version stringclasses 1
value | style stringclasses 2
values | subset stringclasses 12
values | question_id stringlengths 9 23 | question stringlengths 27 8.13k | solution stringlengths 99 5.97k | test stringlengths 105 4.45k | test_info listlengths 0 13 | gpt_pass_sequence listlengths 1 10 | gpt_pass_trial_num int64 1 10 | gpt_difficulty stringclasses 3
values | gpt_pass_percentage float64 0.1 1 | trials dict | chosen_trial stringclasses 10
values | metadata dict | benchmark_similarity float64 0.16 0.93 | benchmark_instruction stringclasses 1
value | benchmark_task_id stringclasses 1
value | filter_reason stringclasses 1
value | base_id stringlengths 7 21 | variant stringclasses 2
values | top_function_names listlengths 2 13 | n_top_functions int64 2 13 | helper_call_edges listlengths 1 16 | n_helper_call_edges int64 1 16 | harness_functions listlengths 0 3 | structural_wrapper bool 1
class | class_names listlengths 0 5 | has_class bool 2
classes | test_kind stringclasses 1
value | test_has_solution_import bool 2
classes | third_party_imports listlengths 0 5 | stdlib_only bool 2
classes | question_norm_sha1 stringlengths 40 40 | solution_ast_sha1 stringlengths 40 40 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
v1.0 | complete | Code_Contests | Code_Contests_11950_C | from typing import List, Tuple
def is_prime(n: int) -> bool:
""" Determine if a number is a prime number. """
pass
def count_primes(arr: List[int]) -> int:
""" Count the number of prime numbers in the list. """
pass
def game_outcome(num_cases: int, cases: List[Tuple[int, List[int]]]) -> List[str]:
... | def is_prime(n):
if n <= 1:
return False
if n <= 3:
return True
if n % 2 == 0 or n % 3 == 0:
return False
i = 5
while i * i <= n:
if n % i == 0 or n % (i + 2) == 0:
return False
i += 6
return True
def count_primes(arr):
return sum(1 for nu... | from solution import game_outcome
def test_single_prime():
assert game_outcome(1, [(1, [2])]) == ["Alice"]
def test_no_primes():
assert game_outcome(1, [(4, [4, 6, 8, 9])]) == ["Bob"]
def test_all_primes():
assert game_outcome(1, [(3, [2, 5, 7])]) == ["Alice"]
def test_even_primes():
assert game_out... | [
{
"docstring": null,
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": null,
"function_declaration": "def count_primes(arr):",
"function_name": "count_primes",
"parameter_list": "(arr)"
},
{
"docstring": nul... | [
0,
0,
0,
1
] | 1 | hard | 0.25 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(num):\n \"\"\"\n Returns True if num is a prime number, otherwise False.\n \"\"\"\n if num < 2:\n return False\n if num ... | trial_gpt4o_4 | {
"original_instruction": "Alice and Bob are two friends who love solving puzzles, and they've come up with an interesting game related to prime numbers.\n\nThe rules of the game are as follows:\n\n1. There are N distinct integers given in a list.\n2. Alice and Bob take turns; Alice always goes first.\n3. During each... | 0.655597 | Code_Contests_11950 | C | [
"is_prime",
"count_primes",
"game_outcome"
] | 3 | [
[
"count_primes",
"is_prime"
],
[
"game_outcome",
"count_primes"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 46f5224db996f428ac0574d7e842463da9684d74 | 6225c6f226e43ffad0db233ab384280c6a360faa | |||
v1.0 | complete | Code_Contests | Code_Contests_11602_C | from typing import List, Tuple
def longest_contiguous_same_parity_sublist(lst: List[int]) -> List[int]:
"""
Given a list of integer numbers, identify and return a sublist that forms the longest
contiguous subsequence where all elements are of the same parity (either all odd or all even).
>>> long... | def longest_contiguous_same_parity_sublist(lst):
"""
Returns a sublist that forms the longest contiguous subsequence where all elements
are of the same parity (either all odd or all even).
"""
max_length = 0
current_length = 0
best_start_index = 0
start_index = 0
is_even = lst[0] % ... | def test_longest_contiguous_same_parity_sublist():
assert longest_contiguous_same_parity_sublist([1, 2, 2, 2, 5, 7, 6, 4]) == [2, 2, 2]
assert longest_contiguous_same_parity_sublist([10, 12, 14, 1, 3]) == [10, 12, 14]
assert longest_contiguous_same_parity_sublist([2, 4, 8, 1, 1, 1, 2, 2]) == [2, 4, 8]
a... | [
{
"docstring": "Returns a sublist that forms the longest contiguous subsequence where all elements \nare of the same parity (either all odd or all even).",
"function_declaration": "def longest_contiguous_same_parity_sublist(lst):",
"function_name": "longest_contiguous_same_parity_sublist",
"paramete... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def longest_same_parity_subsequence(t, test_cases):\n results = []\n for case in test_cases:\n n, nums = case\n max_length = 0\n ... | trial_gpt4o_2 | {
"original_instruction": "Given a list of integer numbers, identify and return a sublist that forms the longest contiguous subsequence where all elements are of the same parity (either all odd or all even).\n\nInput\n\nThe first line contains a single integer t (1 ≤ t ≤ 100) - number of test cases.\n\nFor each test ... | 0.646142 | Code_Contests_11602 | C | [
"longest_contiguous_same_parity_sublist",
"solve",
"parse_input"
] | 3 | [
[
"solve",
"longest_contiguous_same_parity_sublist"
]
] | 1 | [
"parse_input"
] | false | [] | false | pytest | false | [] | true | f693687dbf0c5cfba9dfd731b6e224fdd3cafb8b | fb5beffe4a8a6ee4bad485e365e05542b8fad9a1 | |||
v1.0 | complete | Code_Contests | Code_Contests_11484_C | def hamiltonian_path_exists(n: int, m: int, edges: List[Tuple[int, int]]) -> str:
""" Determine if there exists a Hamiltonian cycle in the given undirected graph.
Args:
n (int): Number of nodes in the graph.
m (int): Number of edges in the graph.
edges (List[Tuple[int, int]]): List of edges represe... | from itertools import permutations
def is_hamiltonian_cycle(n, edges):
graph = {i: set() for i in range(1, n+1)}
for u, v in edges:
graph[u].add(v)
graph[v].add(u)
nodes = list(graph.keys())
for start in nodes:
for perm in permutations(nodes):
if perm[0... | import pytest
from solution import hamiltonian_path_exists
def test_given_example1():
n, m = 4, 6
edges = [(1, 2), (2, 3), (3, 4), (4, 1), (1, 3), (2, 4)]
assert hamiltonian_path_exists(n, m, edges) == "Yes"
def test_given_example2():
n, m = 4, 4
edges = [(1, 2), (2, 3), (3, 4), (1, 3)]
assert... | [
{
"docstring": null,
"function_declaration": "def is_hamiltonian_cycle(n, edges):",
"function_name": "is_hamiltonian_cycle",
"parameter_list": "(n, edges)"
},
{
"docstring": null,
"function_declaration": "def hamiltonian_path_exists(n, m, edges):",
"function_name": "hamiltonian_path_... | [
0,
0,
0,
0,
0,
1,
1,
0,
0,
1
] | 3 | hard | 0.3 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from itertools import permutations\n\ndef has_hamiltonian_cycle(n, edges):\n if n == 1:\n return False\n\n adjacency_list = {i: set() for i in... | trial_gpt4o_9 | {
"original_instruction": "Given an undirected graph with n nodes and m edges, a path in the graph is considered a \"special path\" if it visits every node exactly once and returns to the starting node, forming a cycle known as a Hamiltonian cycle. Your task is to determine whether such a special path exists in the g... | 0.615079 | Code_Contests_11484 | C | [
"is_hamiltonian_cycle",
"hamiltonian_path_exists"
] | 2 | [
[
"hamiltonian_path_exists",
"is_hamiltonian_cycle"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 5cef11c879182562f2a4c8742af1e874c38f314c | 171e5ca8a9d6bcb89682afcc5fa9bf3025bd6f3a | |||
v1.0 | complete | Code_Contests | Code_Contests_10571_C | def dfs(graph, v, visited, rec_stack):
"""
This function performs a Depth First Search (DFS) traversal on a graph
starting from vertex v. It uses visited and rec_stack arrays to keep track
of visited nodes and nodes in the current recursion stack respectively.
"""
visited[v] = True
rec_sta... | def dfs(graph, v, visited, rec_stack):
visited[v] = True
rec_stack[v] = True
# Recur for all neighbors of v
for neighbor in graph[v]:
if not visited[neighbor]:
if dfs(graph, neighbor, visited, rec_stack):
return True
elif rec_stack[neighbor]:
... | import pytest
from solution import detect_cycle
def test_detect_cycle_with_cycle():
n = 4
m = 4
edges = [(1, 2), (2, 3), (3, 4), (4, 2)]
assert detect_cycle(n, m, edges) == "Cycle Detected"
def test_detect_cycle_no_cycle():
n = 3
m = 2
edges = [(1, 2), (2, 3)]
assert detect_cycle(n, m,... | [
{
"docstring": null,
"function_declaration": "def dfs(graph, v, visited, rec_stack):",
"function_name": "dfs",
"parameter_list": "(graph, v, visited, rec_stack)"
},
{
"docstring": null,
"function_declaration": "def has_cycle(graph, n):",
"function_name": "has_cycle",
"parameter_l... | [
1,
0,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def dfs(graph, v, visited, rec_stack):\n visited[v] = True\n rec_stack[v] = True\n \n # Recur for all neighbors of v\n for neighbor in graph... | trial_gpt4o_2 | {
"original_instruction": "Alice is exploring different graph algorithms and has recently learned about Depth First Search (DFS). She decides to write some code to traverse a given directed graph and find out if there are any cycles within it.\n\nAlice knows that a graph contains a cycle if, during the DFS traversal,... | 0.624194 | Code_Contests_10571 | C | [
"dfs",
"has_cycle",
"detect_cycle"
] | 3 | [
[
"detect_cycle",
"has_cycle"
],
[
"has_cycle",
"dfs"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 046266322f7f57c816e9cdfd8d1580855aab7da7 | 02b354de151fc634ca50f9718215bcdb0816ecd1 | |||
v1.0 | complete | Code_Contests | Code_Contests_12411_C | def calculate_revenue(input_str: str) -> int:
""" Calculate the total revenue generated from selling all the paintings at their highest bids.
Args:
input_str: str - Input string containing the number of paintings, minimum starting bids, and bids for each painting.
Returns:
int: Total reven... | def total_revenue(num_paintings, min_bids, bids_list):
total = 0
for i in range(num_paintings):
num_bids = bids_list[i][0]
if num_bids == 0:
continue
highest_bid = max(bids_list[i][1:])
if highest_bid > min_bids[i]:
total += highest_bid
return total
d... | from solution import calculate_revenue
def test_example_case():
input_str = "3\n100 200 150\n2 130 140\n3 210 190 220\n1 160\n"
assert calculate_revenue(input_str) == 520
def test_no_bids():
input_str = "2\n100 200\n0\n0\n"
assert calculate_revenue(input_str) == 0
def test_all_below_minimum():
in... | [
{
"docstring": null,
"function_declaration": "def total_revenue(num_paintings, min_bids, bids_list):",
"function_name": "total_revenue",
"parameter_list": "(num_paintings, min_bids, bids_list)"
},
{
"docstring": null,
"function_declaration": "def parse_input(input_str):",
"function_n... | [
1,
1,
0
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def calculate_total_revenue(n, min_bids, bids):\n \"\"\"\n Calculate the total revenue by summing up the highest bids of each painting \n if the h... | trial_gpt4o_1 | {
"original_instruction": "**Problem:**\n\nA digital art auction house has n paintings available for a silent auction. Each painting has a minimum starting bid and can be bid on by multiple bidders throughout the auction period. At the end of the auction, each painting will be sold to the highest bidder. \n\nYour tas... | 0.583493 | Code_Contests_12411 | C | [
"total_revenue",
"parse_input",
"calculate_revenue"
] | 3 | [
[
"calculate_revenue",
"parse_input"
],
[
"calculate_revenue",
"total_revenue"
]
] | 2 | [
"parse_input"
] | false | [] | false | pytest | true | [] | true | 77e1cb3fab32004e0d1036c330674c4174b5d1ad | d7c921a1d25bf8dc0f0219a3cc78da2be3ae21bf | |||
v1.0 | complete | Code_Contests | Code_Contests_11271_C | class TreeNode:
def __init__(self, value):
self.value = value
self.children = []
def build_tree(edges, root_val):
nodes = {}
for u, v in edges:
if u not in nodes:
nodes[u] = TreeNode(u)
if v not in nodes:
nodes[v] = TreeNode(v)
nodes[u].childr... | class TreeNode:
def __init__(self, value):
self.value = value
self.children = []
def build_tree(edges, root_val):
nodes = {}
for u, v in edges:
if u not in nodes:
nodes[u] = TreeNode(u)
if v not in nodes:
nodes[v] = TreeNode(v)
nodes[u].childr... | import pytest
from solution import TreeNode, build_tree, find_lca, is_ancestor, cyclic_shift
def test_find_lca():
edges = [(1, 2), (2, 3), (3, 4)]
root = build_tree(edges, 1)
assert find_lca(root, 2, 4).value == 2
def test_is_ancestor():
edges = [(1, 2), (2, 3), (3, 4)]
root = build_tree(edges, 1)... | [] | [
0,
0,
0,
1,
0
] | 1 | hard | 0.2 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "class TreeNode:\n def __init__(self, value):\n self.value = value\n self.children = []\n self.parent = None\n\nclass Forest:\n d... | trial_gpt4o_3 | {
"original_instruction": "You are given a forest of rooted trees. Each tree's node has a unique positive integer value, and no two trees have overlapping nodes.\n\nYou need to perform Q queries. There are 3 types of queries:\n\n1. Find the lowest common ancestor (LCA) of two nodes with values X and Y.\n2. Determine ... | 0.57041 | Code_Contests_11271 | C | [
"build_tree",
"find_lca",
"is_ancestor",
"search",
"cyclic_shift",
"main"
] | 6 | [
[
"is_ancestor",
"search"
]
] | 1 | [] | false | [
"TreeNode"
] | true | pytest | true | [] | true | 8ddec0e48feaf7de26d6e2eb56dd018449c63ef0 | d43f4f289c75562d7bd08d389f7efb7d446f4f5a | |||
v1.0 | complete | Code_Contests | Code_Contests_12030_C | from typing import List, Tuple
def min_roads_to_disconnect(n: int, r: int, roads: List[Tuple[int, int]]) -> int:
"""
Determine the minimum number of roads that, if removed, would make the castles disconnected.
Args:
n (int): The number of castles.
r (int): The number of roads.
roads (List[Tupl... | from collections import defaultdict, deque
def find_bridges(n, connections):
def dfs(u, parent):
nonlocal time
visited[u] = True
discovery[u] = low[u] = time
time += 1
for v in graph[u]:
if not visited[v]:
dfs(v, u)
low[u]... | from solution import min_roads_to_disconnect
def test_example():
assert min_roads_to_disconnect(6, 7, [(1, 2), (1, 3), (2, 3), (2, 4), (3, 4), (3, 5), (4, 6)]) == 2
def test_no_roads():
assert min_roads_to_disconnect(5, 0, []) == 0
def test_single_road():
assert min_roads_to_disconnect(2, 1, [(1, 2)]) ==... | [
{
"docstring": null,
"function_declaration": "def find_bridges(n, connections):",
"function_name": "find_bridges",
"parameter_list": "(n, connections)"
},
{
"docstring": null,
"function_declaration": "def min_roads_to_disconnect(n, r, roads):",
"function_name": "min_roads_to_disconne... | [
0,
0,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from collections import defaultdict, deque\n\nclass Graph:\n def __init__(self, n):\n self.graph = defaultdict(list)\n self.ROW = n\n \... | trial_gpt4o_2 | {
"original_instruction": "There is a kingdom with several castles connected by bidirectional roads. The king of the kingdom, Kind King, wants to ensure that in case of an attack, he can close a certain number of roads to minimize the damage by preventing the spread of the enemy troops. To do this, he needs to know t... | 0.638218 | Code_Contests_12030 | C | [
"find_bridges",
"min_roads_to_disconnect"
] | 2 | [
[
"min_roads_to_disconnect",
"find_bridges"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 09ae93c76b2115ea9f6ddc86f343afe06dcd0ce5 | 0d833663aea62516a6add49277cc05a4f52c9847 | |||
v1.0 | complete | Code_Contests | Code_Contests_11779_C | import math
from typing import List, Tuple
def calculate_distance(x1: float, y1: float, x2: float, y2: float) -> float:
""" Calculate the distance between two points in a 2D plane.
>>> calculate_distance(0, 0, 3, 4)
5.0
>>> calculate_distance(1, 1, 4, 5)
5.0
"""
pass
def minimum_range_to_c... | import math
def calculate_distance(x1, y1, x2, y2):
return math.sqrt((x2 - x1)**2 + (y2 - y1)**2)
def minimum_range_to_cover_houses(house_coordinates):
n = len(house_coordinates)
max_distance = 0
for i in range(n):
for j in range(i + 1, n):
distance = calculate_distance(house_coord... | import pytest
from solution import calculate_distance, minimum_range_to_cover_houses, parse_input_data, process_input_dataset
def test_calculate_distance():
assert calculate_distance(0, 0, 3, 4) == 5.0
assert calculate_distance(1, 1, 4, 5) == 5.0
assert calculate_distance(2, 0, 2, 3) == 3.0
def test_minim... | [
{
"docstring": null,
"function_declaration": "def calculate_distance(x1, y1, x2, y2):",
"function_name": "calculate_distance",
"parameter_list": "(x1, y1, x2, y2)"
},
{
"docstring": null,
"function_declaration": "def minimum_range_to_cover_houses(house_coordinates):",
"function_name"... | [
1,
0,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import math\n\ndef calculate_distance(x1, y1, x2, y2):\n return math.sqrt((x2 - x1)**2 + (y2 - y1)**2)\n\ndef minimum_range_to_cover_houses(house_coordi... | trial_gpt4o_0 | {
"original_instruction": "In a remote village, the mayor wants to install a new communication tower to provide internet access to all households in the area. The village can be represented as a 2D plane with each house located at a specific coordinate. The communication tower will have a specific range that determin... | 0.584105 | Code_Contests_11779 | C | [
"calculate_distance",
"minimum_range_to_cover_houses",
"process_input_dataset",
"parse_input_data"
] | 4 | [
[
"minimum_range_to_cover_houses",
"calculate_distance"
],
[
"process_input_dataset",
"minimum_range_to_cover_houses"
]
] | 2 | [
"parse_input_data"
] | false | [] | false | pytest | true | [] | true | fd3fd0b455f1c55dbc5ee6400c8f10ca0d2e29df | 210e05bca7236f0a921144aa577f1bdc3876a083 | |||
v1.0 | complete | Code_Contests | Code_Contests_11638_C | from typing import List, Tuple
def determine_winner(n: int, m: int, edges: List[Tuple[int, int]]) -> str:
"""
Determine the winner of the game if both players play optimally.
Arguments:
n -- number of nodes in the graph
m -- number of edges in the graph
edges -- list of edges represented a... | def determine_winner(n, m, edges):
# The outcome of the game is determined by the parity of the number of edges.
if m % 2 == 0:
return "Alice"
else:
return "Bob"
def find_winners(test_cases):
results = []
for test in test_cases:
n, m, edges = test
results.append(dete... | from solution import find_winners, parse_input
def test_example_cases():
input_str = "3\n3 3\n1 2\n2 3\n3 1\n4 4\n1 2\n2 3\n3 4\n4 1\n4 3\n1 2\n2 3\n3 4"
expected_output = ["Bob", "Alice", "Bob"]
test_cases = parse_input(input_str)
assert find_winners(test_cases) == expected_output
def test_all_edges_... | [
{
"docstring": null,
"function_declaration": "def determine_winner(n, m, edges):",
"function_name": "determine_winner",
"parameter_list": "(n, m, edges)"
},
{
"docstring": null,
"function_declaration": "def find_winners(test_cases):",
"function_name": "find_winners",
"parameter_l... | [
1,
1,
0
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def game_result(n, m, edges):\n \"\"\"\n Determine the winner of the game if both players play optimally.\n \"\"\"\n # Result is determined bas... | trial_gpt4o_1 | {
"original_instruction": "Alice and Bob are playing a game on a graph. The graph is undirected and simple, with no self-loops or multiple edges between any pair of nodes. The graph consists of n nodes and m edges. \n\nThe game is played in turns, starting with Alice. During each turn, a player must select an edge an... | 0.634194 | Code_Contests_11638 | C | [
"determine_winner",
"find_winners",
"parse_input"
] | 3 | [
[
"find_winners",
"determine_winner"
]
] | 1 | [
"parse_input"
] | false | [] | false | pytest | true | [] | true | 35a38196e1715a2ce08fb3cec48093eb90996799 | 4f6267d186503306eae2bac491ab5129965f0ed7 | |||
v1.0 | complete | Code_Contests | Code_Contests_11266_C | def is_possible(books, n, k, max_pages):
"""
Helper function to check if it is possible to allocate books such that the maximum number of pages per student is minimized.
:param books: List of integers representing the number of pages in each book.
:param n: Number of books.
:param k: Number of stud... | def is_possible(books, n, k, max_pages):
student_count = 1
current_pages = 0
for pages in books:
if current_pages + pages > max_pages:
student_count += 1
current_pages = pages
if student_count > k:
return False
else:
curren... | def test_is_possible():
assert is_possible([10, 20, 30, 40], 4, 2, 60) == True
assert is_possible([10, 20, 30, 40], 4, 2, 50) == False
assert is_possible([10, 20, 30, 40], 4, 3, 40) == True
assert is_possible([5, 10, 20, 30, 40], 5, 3, 40) == True
def test_find_minimum_max_pages():
assert find_mini... | [
{
"docstring": null,
"function_declaration": "def is_possible(books, n, k, max_pages):",
"function_name": "is_possible",
"parameter_list": "(books, n, k, max_pages)"
},
{
"docstring": null,
"function_declaration": "def find_minimum_max_pages(books, n, k):",
"function_name": "find_min... | [
1,
0,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_possible_to_allocate(pages, books, students, max_pages):\n cnt_students = 1\n current_sum = 0\n\n for page in pages:\n if current_su... | trial_gpt4o_2 | {
"original_instruction": "You are given a list of N integers which represent the number of pages in N books. Your task is to divide these books into K students such that the maximum number of pages assigned to a student is minimized. Each student must get at least one book, and each book must be assigned to exactly ... | 0.721721 | Code_Contests_11266 | C | [
"is_possible",
"find_minimum_max_pages",
"allocate_books"
] | 3 | [
[
"allocate_books",
"find_minimum_max_pages"
],
[
"find_minimum_max_pages",
"is_possible"
]
] | 2 | [] | false | [] | false | pytest | false | [] | true | 73a5eb0fb08c48f7afefbdea2b6e8cefd95756ba | 71e8944e344d06d6b238450bbdf0ffc9f6b95bbe | |||
v1.0 | complete | Code_Contests | Code_Contests_12590_C | def total_cost_of_mst(n: int, m: int, roads: List[Tuple[int, int, int]]) -> int:
"""
Find the total cost of the Minimum Spanning Tree (MST) of the village's road network.
Arguments:
n -- number of houses
m -- number of roads
roads -- list of tuples representing the roads, where each tuple conta... | def find(parent, i):
if parent[i] == i:
return i
return find(parent, parent[i])
def union(parent, rank, x, y):
root_x = find(parent, x)
root_y = find(parent, y)
if root_x != root_y:
if rank[root_x] > rank[root_y]:
parent[root_y] = root_x
elif rank[root_x] < ... | from solution import total_cost_of_mst
def test_example():
n = 4
m = 5
roads = [
(1, 2, 3),
(1, 3, 1),
(2, 3, 3),
(2, 4, 6),
(3, 4, 2)
]
assert total_cost_of_mst(n, m, roads) == 6
def test_single_road():
n = 2
m = 1
roads = [
(1, 2, 10)
... | [
{
"docstring": null,
"function_declaration": "def find(parent, i):",
"function_name": "find",
"parameter_list": "(parent, i)"
},
{
"docstring": null,
"function_declaration": "def union(parent, rank, x, y):",
"function_name": "union",
"parameter_list": "(parent, rank, x, y)"
},
... | [
0,
1,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "class DisjointSetUnion:\n def __init__(self, n):\n self.parent = list(range(n))\n self.rank = [1] * n\n\n def find(self, u):\n i... | trial_gpt4o_2 | {
"original_instruction": "In a small village, there is a network of N houses connected by M bidirectional roads. Each road connects two houses and has a certain weight representing the cost to travel that road. \n\nThe village head wants to ensure that there is a path to reach any house from any other house, but wit... | 0.683037 | Code_Contests_12590 | C | [
"find",
"union",
"kruskal_mst",
"total_cost_of_mst"
] | 4 | [
[
"kruskal_mst",
"find"
],
[
"kruskal_mst",
"union"
],
[
"total_cost_of_mst",
"kruskal_mst"
],
[
"union",
"find"
]
] | 4 | [] | false | [] | false | pytest | true | [] | true | 53b051cd7489f133797c296c31c3b1429a03e6aa | 406e1d5517d2c4057e4c957342155f2d2c9aa7fd | |||
v1.0 | complete | Code_Contests | Code_Contests_12738_C | from typing import List, Tuple
def solve_maze_problem(input_string: str) -> int:
"""
Given a maze represented by a 2D array of size n x m consisting of '.' and '#' characters,
find the length of the shortest path from the start (0,0) to the end (n-1,m-1).
If no such path exists, return -1.
Example:... | from collections import deque
def shortest_path_in_maze(n, m, maze):
"""
Returns the length of the shortest path from the top-left corner to the bottom-right corner of the maze.
If no such path exists, return -1.
"""
def is_valid(x, y):
return 0 <= x < n and 0 <= y < m and maze[x][y] == '.... | from solution import solve_maze_problem
def test_example_1():
input_data = """5 5
. . . . #
# # . # #
. . . . .
. # # # .
. . . . ."""
result = solve_maze_problem(input_data)
assert result == 9
def test_example_2():
input_data = """4 4
. . # .
# . # .
# . # #
. . . ."""
result = solve_maze_problem... | [
{
"docstring": "Returns the length of the shortest path from the top-left corner to the bottom-right corner of the maze.\nIf no such path exists, return -1.",
"function_declaration": "def shortest_path_in_maze(n, m, maze):",
"function_name": "shortest_path_in_maze",
"parameter_list": "(n, m, maze)"
... | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from collections import deque\n\ndef shortest_path(maze, n, m):\n if maze[0][0] == '#' or maze[n-1][m-1] == '#':\n return -1\n \n direction... | trial_gpt4o_1 | {
"original_instruction": "You are given a maze represented by a 2D array of size n x m consisting of '.' and '#' characters. Here '.' represents an empty cell and '#' represents a wall. You start at the top-left corner of the maze (0,0) and need to reach the bottom-right corner (n-1,m-1). You can move up, down, left... | 0.60449 | Code_Contests_12738 | C | [
"shortest_path_in_maze",
"parse_input",
"solve_maze_problem"
] | 3 | [
[
"solve_maze_problem",
"parse_input"
],
[
"solve_maze_problem",
"shortest_path_in_maze"
]
] | 2 | [
"parse_input"
] | false | [] | false | pytest | true | [] | true | 16209eaa8bf39454c79c4e7a25e522f892ec891b | 5673f2f2898ca0389b7878a339a6dee2d5a79959 | |||
v1.0 | complete | Code_Contests | Code_Contests_12641_C | def minimum_cost_to_connect_islands(n: int, m: int, bridge_data: List[Tuple[int, int, int, int]], max_energy: int) -> Union[int, str]:
""" Determine the minimum cost needed to keep all islands connected without exceeding the wizard's magical energy capacity.
>>> minimum_cost_to_connect_islands(4, 5, [(1, 2, 10,... | def find(parent, i):
if parent[i] == i:
return i
else:
parent[i] = find(parent, parent[i])
return parent[i]
def union(parent, rank, x, y):
xroot = find(parent, x)
yroot = find(parent, y)
if rank[xroot] < rank[yroot]:
parent[xroot] = yroot
elif rank[xroot] > rank... | def test_example_case_1():
n = 4
m = 5
bridge_data = [
(1, 2, 10, 5),
(2, 3, 15, 7),
(3, 4, 10, 6),
(4, 1, 20, 9),
(1, 3, 25, 8)
]
max_energy = 15
assert minimum_cost_to_connect_islands(n, m, bridge_data, max_energy) == 35
def test_example_case_2():
n... | [
{
"docstring": null,
"function_declaration": "def find(parent, i):",
"function_name": "find",
"parameter_list": "(parent, i)"
},
{
"docstring": null,
"function_declaration": "def union(parent, rank, x, y):",
"function_name": "union",
"parameter_list": "(parent, rank, x, y)"
},
... | [
0,
0,
0,
1
] | 1 | hard | 0.25 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def minimum_cost_to_connect_islands(n, m, bridges, max_energy):\n from heapq import heappush, heappop\n \n # Function to find the root of a node i... | trial_gpt4o_3 | {
"original_instruction": "In a magical land, there are n floating islands connected by m magical bridges. Each bridge connects exactly two islands and has a certain fixed cost and fixed magical energy requirement to maintain it. The magical energy is supplied by a wizard, but his energy is limited. The wizard has on... | 0.70625 | Code_Contests_12641 | C | [
"find",
"union",
"kruskal",
"minimum_cost_to_connect_islands"
] | 4 | [
[
"kruskal",
"find"
],
[
"kruskal",
"union"
],
[
"minimum_cost_to_connect_islands",
"kruskal"
],
[
"union",
"find"
]
] | 4 | [] | false | [] | false | pytest | false | [] | true | 98d3528608b6bfd614bfd5f250a1cff0424b9bb2 | a44d494701d40fc95f3ff3fcbdaa339e4b76cd28 | |||
v1.0 | complete | Code_Contests | Code_Contests_13198_C | def check_valid_route(sequence: str) -> str:
"""Check if the binary sequence forms a valid route from HQ to SB.
>>> check_valid_route("0110")
'Yes'
>>> check_valid_route("011011")
'Yes'
>>> check_valid_route("10011")
'Yes'
>>> check_valid_route("1101")
'No'
>>> check_valid_r... | def check_valid_route(sequence):
"""
Function to check if the binary sequence forms a valid route from HQ to SB.
"""
# For simplicity, assume a valid route is one ending with a specific pattern
valid_routes = ["0110", "011011", "10011"] # Dummy example of valid routes
return "Yes" if sequence i... | from solution import check_valid_route, navigate_routes
def test_check_valid_route():
assert check_valid_route("0110") == "Yes"
assert check_valid_route("011011") == "Yes"
assert check_valid_route("10011") == "Yes"
assert check_valid_route("1101") == "No"
assert check_valid_route("1010") == "No"
d... | [
{
"docstring": "Function to check if the binary sequence forms a valid route from HQ to SB.",
"function_declaration": "def check_valid_route(sequence):",
"function_name": "check_valid_route",
"parameter_list": "(sequence)"
},
{
"docstring": null,
"function_declaration": "def navigate_rou... | [
0,
0,
0,
0,
1
] | 1 | hard | 0.2 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_valid_route(binary_sequence):\n \"\"\"\n Determines if the binary sequence is a valid route from HQ to SB.\n A route is valid if it starts ... | trial_gpt4o_4 | {
"original_instruction": "In a distant galaxy, there exists an intricate network of teleportation stations, each connected by one-way teleport routes. A rebel pilot, Zane, is trying to navigate from the Headquarters station (HQ) to the Secret Base (SB). However, the terrorists have intercepted the detailed map of th... | 0.566622 | Code_Contests_13198 | C | [
"check_valid_route",
"navigate_routes"
] | 2 | [
[
"navigate_routes",
"check_valid_route"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 76ac70a5fad74dcc8dbe626f59672af12351eaed | d53c2068149fd5f3ee5bee8f108a56e3fa95f659 | |||
v1.0 | complete | Code_Contests | Code_Contests_12966_C | def is_palindromic_number(num):
""" Check if a number is a palindrome.
>>> is_palindromic_number(121) == True
>>> is_palindromic_number(123) == False
>>> is_palindromic_number(1221) == True
>>> is_palindromic_number(10) == False
"""
def count_palindromic_numbers(L, R):
""" Count palindr... | def is_palindromic_number(num):
return str(num) == str(num)[::-1]
def count_palindromic_numbers(L, R):
count = 0
for num in range(L, R + 1):
if is_palindromic_number(num):
count += 1
return count
def palindromic_range(queries):
results = []
for L, R, P in queries:
i... | from solution import palindromic_range, is_palindromic_number, count_palindromic_numbers
def test_is_palindromic_number():
assert is_palindromic_number(121) == True
assert is_palindromic_number(123) == False
assert is_palindromic_number(1221) == True
assert is_palindromic_number(10) == False
def test_... | [
{
"docstring": null,
"function_declaration": "def is_palindromic_number(num):",
"function_name": "is_palindromic_number",
"parameter_list": "(num)"
},
{
"docstring": null,
"function_declaration": "def count_palindromic_numbers(L, R):",
"function_name": "count_palindromic_numbers",
... | [
1,
0,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_palindromic_number(num):\n return str(num) == str(num)[::-1]\n\ndef count_palindromic_numbers(L, R):\n count = 0\n for num in range(L, R + ... | trial_gpt4o_0 | {
"original_instruction": "Alice loves palindromes and numbers. She defines a \"palindromic range\" to be a range [L, R] of integers such that the number of palindromic numbers in the range is greater than or equal to P. She wants to check if a given range is a palindromic range or not.\n\nA number is said to be pali... | 0.660161 | Code_Contests_12966 | C | [
"is_palindromic_number",
"count_palindromic_numbers",
"palindromic_range"
] | 3 | [
[
"count_palindromic_numbers",
"is_palindromic_number"
],
[
"palindromic_range",
"count_palindromic_numbers"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | e934ebb37b4f50d746e6931d9253668dd443b7fe | 2844e89e0580ffb9530e33c3101dc1780418e112 | |||
v1.0 | complete | Code_Contests | Code_Contests_13013_C | class TreeNode:
def __init__(self, value, left=None, right=None):
self.value = value
self.left = left
self.right = right
def build_tree(node_list):
nodes = [None if val == -1 else TreeNode(val) for val, _, _ in node_list]
for idx, (val, left, right) in enumerate(node_list):
... | class TreeNode:
def __init__(self, value, left=None, right=None):
self.value = value
self.left = left
self.right = right
def build_tree(node_list):
if not node_list:
return None
nodes = [None if val == -1 else TreeNode(val) for val, _, _ in node_list]
for idx, (val, left... | from solution import find_max_sum_path
def test_example_case_1():
node_data = [
(10, 1, 2),
(-2, 3, 4),
(-3, -1, -1),
(7, -1, -1),
(2, -1, -1)
]
assert find_max_sum_path(node_data) == 15
def test_single_node():
node_data = [
(5, -1, -1)
]
assert ... | [] | [
0,
0,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "class TreeNode:\n def __init__(self, val=0, left=None, right=None):\n self.val = val\n self.left = left\n self.right = right\n\ndef... | trial_gpt4o_2 | {
"original_instruction": "This is an algorithm implementation problem where you are given a binary tree and you need to find the maximum sum path from the root node down to any leaf node.\n\n### Problem Statement:\nGiven a binary tree, where each node contains an integer value, find the maximum sum of the numbers al... | 0.632304 | Code_Contests_13013 | C | [
"build_tree",
"max_sum_path_from_root_to_leaf",
"find_max_sum_path"
] | 3 | [
[
"find_max_sum_path",
"build_tree"
],
[
"find_max_sum_path",
"max_sum_path_from_root_to_leaf"
]
] | 2 | [] | false | [
"TreeNode"
] | true | pytest | true | [] | true | 5cb2c332a1e7b6f4093a1b154085e3741ae379fe | 3ff9e17452bccb08de2b7cb1594f1b92ee0c733c | |||
v1.0 | complete | Code_Contests | Code_Contests_13087_C | def is_valid_serial(serial: str) -> bool:
""" Returns True if the serial number contains both letters and digits, False otherwise.
>>> is_valid_serial("A1b2")
True
>>> is_valid_serial("abcd")
False
>>> is_valid_serial("1234")
False
>>> is_valid_serial("a1")
True
>>> is_valid_seri... | def is_valid_serial(serial):
"""
Returns True if the serial number contains both letters and digits, False otherwise.
"""
has_letter = any(char.isalpha() for char in serial)
has_digit = any(char.isdigit() for char in serial)
return has_letter and has_digit
def check_serial_number(N, issued_seri... | from solution import is_valid_serial, check_serial_number
def test_is_valid_serial():
assert is_valid_serial("A1b2") == True
assert is_valid_serial("abcd") == False
assert is_valid_serial("1234") == False
assert is_valid_serial("a1") == True
assert is_valid_serial("A1B2c3") == True
def test_check_... | [
{
"docstring": "Returns True if the serial number contains both letters and digits, False otherwise.",
"function_declaration": "def is_valid_serial(serial):",
"function_name": "is_valid_serial",
"parameter_list": "(serial)"
},
{
"docstring": "Checks if the given serial number is valid and un... | [
0,
0,
0,
1,
1
] | 2 | medium | 0.4 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_valid_serial(serial):\n \"\"\"\n Check if a serial number is valid. A valid serial number must contain both letters and digits.\n \"\"\"\n ... | trial_gpt4o_4 | {
"original_instruction": "A self-driving car company needs to ensure that all its cars use unique serial numbers that can be checked efficiently. Each serial number is a string consisting of both letters and numbers and follows these rules:\n1. The serial number must contain both letters and digits.\n2. The letters ... | 0.584301 | Code_Contests_13087 | C | [
"is_valid_serial",
"check_serial_number"
] | 2 | [
[
"check_serial_number",
"is_valid_serial"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | ec7509e35a8704aaa6759bbfba14f9ceb1ada100 | 670246ce76a70b8e34658bd35b959b5b738033b8 | |||
v1.0 | complete | Code_Contests | Code_Contests_13022_C | from collections import deque
from typing import List, Tuple
def is_valid(cell: Tuple[int, int], grid: List[List[int]], rows: int, cols: int, visited: List[List[bool]]) -> bool:
""" Check if the cell is within bounds, not an obstacle, and not yet visited.
>>> grid = [
... [0, 0, 0],
... [0, 0, 0]... | from collections import deque
def is_valid(cell, grid, rows, cols, visited):
x, y = cell
return 0 <= x < rows and 0 <= y < cols and grid[x][y] == 0 and not visited[x][y]
def bfs_shortest_path(grid, start, end):
rows, cols = len(grid), len(grid[0])
queue = deque([(start, 0)])
visited = [[False]*col... | import pytest
from solution import bfs_shortest_path, is_valid
def test_bfs_shortest_path_no_obstacles():
grid = [
[0, 0, 0],
[0, 0, 0],
[0, 0, 0]
]
assert bfs_shortest_path(grid, (0, 0), (2, 2)) == 4
def test_bfs_shortest_path_with_obstacles():
grid = [
[0, 1, 0],
... | [
{
"docstring": null,
"function_declaration": "def is_valid(cell, grid, rows, cols, visited):",
"function_name": "is_valid",
"parameter_list": "(cell, grid, rows, cols, visited)"
},
{
"docstring": null,
"function_declaration": "def bfs_shortest_path(grid, start, end):",
"function_name... | [
0,
0,
0,
0,
0,
1,
0,
0,
0
] | 1 | hard | 0.111 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from collections import deque\n\ndef shortest_path(m, n, start, end, obstacles):\n \"\"\"\n Returns the shortest path in a grid from start to end, av... | trial_gpt4o_5 | {
"original_instruction": "A warehouse management system needs to optimize the routes of robots picking up inventory. The warehouse is organized in a grid of cells, where each cell may or may not contain obstacles. Each robot can only move up, down, left, or right, and cannot move diagonally or through obstacles. The... | 0.702486 | Code_Contests_13022 | C | [
"is_valid",
"bfs_shortest_path",
"process_test_cases"
] | 3 | [
[
"bfs_shortest_path",
"is_valid"
],
[
"process_test_cases",
"bfs_shortest_path"
]
] | 2 | [
"process_test_cases"
] | false | [] | false | pytest | true | [] | true | 3f4700abca169a55e5b36e2d61a8372c933edd55 | 3b544ed762644ae3934f7cf610a9aab29be43c33 | |||
v1.0 | complete | Code_Contests | Code_Contests_13770_C | def maximalRectangle(matrix: List[List[int]]) -> int:
""" Given a 2D array containing 0's and 1's, return the area of the largest rectangle containing only 1's
>>> maximalRectangle([
... [1, 0, 1, 0, 0],
... [1, 0, 1, 1, 1],
... [1, 1, 1, 1, 1],
... [1, 0, 0, 1, 0]
... ])
6
>>>... | def maximalRectangle(matrix):
if not matrix:
return 0
max_area = 0
dp = [0] * len(matrix[0])
for row in matrix:
for j in range(len(row)):
dp[j] = dp[j] + 1 if row[j] == 1 else 0
max_area = max(max_area, largestRectangleArea(dp))
return max_area
def large... | from solution import maximalRectangle
def test_maximal_rectangle_case_1():
matrix = [
[1, 0, 1, 0, 0],
[1, 0, 1, 1, 1],
[1, 1, 1, 1, 1],
[1, 0, 0, 1, 0]
]
assert maximalRectangle(matrix) == 6
def test_maximal_rectangle_case_2():
matrix = [
[0, 0, 0],
[0,... | [
{
"docstring": null,
"function_declaration": "def maximalRectangle(matrix):",
"function_name": "maximalRectangle",
"parameter_list": "(matrix)"
},
{
"docstring": null,
"function_declaration": "def largestRectangleArea(heights):",
"function_name": "largestRectangleArea",
"paramete... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def maximalRectangle(matrix):\n if not matrix:\n return 0\n\n max_area = 0\n dp = [0] * len(matrix[0])\n \n for row in matrix:\n ... | trial_gpt4o_0 | {
"original_instruction": "Farmer John has a rectangular farmland grid made of cells, where each cell can be plowed or unplowed. He represents the plowed cells with a 1 and unplowed cells with a 0. He wants to effectively prepare the farmland by ensuring that every contiguous block of plowed cells forms a single rect... | 0.749166 | Code_Contests_13770 | C | [
"maximalRectangle",
"largestRectangleArea"
] | 2 | [
[
"maximalRectangle",
"largestRectangleArea"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | d899b723678c79096712290043c2ef3dec59322d | 083f6f63ebed595c17bce7cc41de1e7509783924 | |||
v1.0 | complete | Code_Contests | Code_Contests_13804_C | def is_prime(num: int) -> bool:
""" Check if a number is prime.
>>> is_prime(2)
True
>>> is_prime(4)
False
>>> is_prime(5)
True
"""
def longest_prime_subsequence_length(n: int, sequence: List[int]) -> int:
""" Find the length of the longest contiguous subsequence where all integ... | def is_prime(num):
if num <= 1:
return False
for i in range(2, int(num**0.5) + 1):
if num % i == 0:
return False
return True
def longest_prime_subsequence_length(n, sequence):
max_len = 0
current_len = 0
for num in sequence:
if is_prime(num):
curr... | from solution import is_prime, longest_prime_subsequence_length
def test_is_prime():
assert is_prime(2)
assert is_prime(3)
assert not is_prime(4)
assert is_prime(5)
assert is_prime(7)
assert not is_prime(1)
assert not is_prime(0)
assert not is_prime(-5)
def test_longest_prime_subsequen... | [
{
"docstring": null,
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": null,
"function_declaration": "def longest_prime_subsequence_length(n, sequence):",
"function_name": "longest_prime_subsequence_length",
"pa... | [
1,
0,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(num):\n if num <= 1:\n return False\n for i in range(2, int(num**0.5) + 1):\n if num % i == 0:\n return False\n... | trial_gpt4o_0 | {
"original_instruction": "John recently got interested in studying sequences of prime numbers. He has a sequence of N integers and wants to find the length of the longest contiguous subsequence where all the integers are prime.\n\nA prime number is a positive integer greater than 1 that has no positive integer divis... | 0.729994 | Code_Contests_13804 | C | [
"is_prime",
"longest_prime_subsequence_length"
] | 2 | [
[
"longest_prime_subsequence_length",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | a23c2929dabccb62be870b3fc960b052c0f8dfe9 | 5e296d80c4d3036a675cc5bd62a5b727250b9a96 | |||
v1.0 | complete | Code_Contests | Code_Contests_13136_C | import re
def evaluate_expression(expression, variables):
try:
result = eval(expression, {}, variables)
return int(result)
except NameError:
return 'UNDEFINED'
except ZeroDivisionError:
return 'UNDEFINED'
def parse_and_evaluate(input_lines):
""" Evaluates a sequence of ... | import re
def evaluate_expression(expression, variables):
try:
result = eval(expression, {}, variables)
return int(result)
except NameError:
return 'UNDEFINED'
except ZeroDivisionError:
return 'UNDEFINED'
def parse_and_evaluate(input_lines):
variables = {}
output = ... | import pytest
from solution import parse_and_evaluate
def test_example_case():
input_lines = [
"x 10",
"y 20",
"END OF INITIALIZATION",
"z = x + y",
"a = z * 2",
"a / 5",
"b = a - 30",
"c = (a - (b * 2))",
"w = (d + y)",
"END OF EXPRES... | [
{
"docstring": null,
"function_declaration": "def evaluate_expression(expression, variables):",
"function_name": "evaluate_expression",
"parameter_list": "(expression, variables)"
},
{
"docstring": null,
"function_declaration": "def parse_and_evaluate(input_lines):",
"function_name":... | [
0,
0,
0,
0,
1
] | 1 | hard | 0.2 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import re\n\ndef evaluate_expression(expression, variables):\n tokens = re.findall(r'\\d+|[a-zA-Z_]\\w*|[+*/()-]', expression)\n postfix = to_postfix... | trial_gpt4o_4 | {
"original_instruction": "You are tasked to write a program that helps analyze a simple language. The language consists of variables, basic arithmetic operations (addition, subtraction, multiplication, and division), and assignment statements. Each expression or statement in the language is provided on a single line... | 0.492343 | Code_Contests_13136 | C | [
"evaluate_expression",
"parse_and_evaluate"
] | 2 | [
[
"parse_and_evaluate",
"evaluate_expression"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | d9fe92240e0925b7cc991e1332cac126098384de | 9fbdc7caabbc40fd0818e8a42f9cc4256633db9d | |||
v1.0 | complete | Code_Contests | Code_Contests_13695_C | def second_largest(input_list: List[int]) -> int:
"""
Returns the second largest number in the list.
>>> second_largest([2, 3, 6, 6, 5])
5
>>> second_largest([10, 5, 10])
5
>>> second_largest([1, 1, 1, 1])
None
>>> second_largest([10, 9, 8, 7, 6, 5])
9
>>> second_largest... | def second_largest(input_list):
"""
Returns the second largest number in the list.
"""
unique_numbers = list(set(input_list))
unique_numbers.sort()
if len(unique_numbers) < 2:
return None
return unique_numbers[-2]
# Function to handle the input as per the problem statement... | from solution import find_second_largest
def test_find_second_largest_example1():
assert find_second_largest(5, [2, 3, 6, 6, 5]) == 5
def test_find_second_largest_example2():
assert find_second_largest(3, [10, 5, 10]) == 5
def test_find_second_largest_all_same():
assert find_second_largest(4, [1, 1, 1, 1... | [
{
"docstring": "Returns the second largest number in the list.",
"function_declaration": "def second_largest(input_list):",
"function_name": "second_largest",
"parameter_list": "(input_list)"
},
{
"docstring": null,
"function_declaration": "def find_second_largest(n, numbers):",
"fun... | [
0,
0,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def second_largest(n, numbers):\n \"\"\"\n Returns the second largest number in the list.\n \"\"\"\n first_largest = second_largest = -float('i... | trial_gpt4o_2 | {
"original_instruction": "You are given a list of integers. Find and return the second largest number in the list.\n\nInput\n\nThe first line of input contains an integer n (2 ≤ n ≤ 100) - the number of integers in the list. The second line contains n integers, separated by spaces. Each integer is between -1000 and ... | 0.763146 | Code_Contests_13695 | C | [
"second_largest",
"find_second_largest"
] | 2 | [
[
"find_second_largest",
"second_largest"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 49f9cdbb58e0db266a884cebdabd900dcfc1d042 | 1be29f2377178ba7c689d89a7acf058e144bb5f8 | |||
v1.0 | complete | Code_Contests | Code_Contests_12893_C | def sum_elements_greater_than_k(matrix, k):
"""
Returns the sum of all elements in the matrix that are greater than k.
"""
total_sum = 0
for row in matrix:
for element in row:
if element > k:
total_sum += element
return total_sum
def create_matrix_and_calcula... | def sum_elements_greater_than_k(matrix, k):
"""
Returns the sum of all elements in the matrix that are greater than k.
"""
total_sum = 0
for row in matrix:
for element in row:
if element > k:
total_sum += element
return total_sum
def create_matrix_and_calcula... | from solution import create_matrix_and_calculate_sum
def test_example_case():
m = 3
n = 3
matrix_elements = [1, 2, 3, 4, 5, 6, 7, 8, 9]
k = 5
assert create_matrix_and_calculate_sum(m, n, matrix_elements, k) == 30
def test_all_elements_less_than_k():
m = 2
n = 2
matrix_elements = [1, 2,... | [
{
"docstring": "Returns the sum of all elements in the matrix that are greater than k.",
"function_declaration": "def sum_elements_greater_than_k(matrix, k):",
"function_name": "sum_elements_greater_than_k",
"parameter_list": "(matrix, k)"
},
{
"docstring": "Wrapper function to create a matr... | [
1,
1,
0
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def sum_elements_greater_than_k(matrix, k):\n \"\"\"\n Returns the sum of all elements in the matrix that are greater than k.\n \"\"\"\n total_... | trial_gpt4o_0 | {
"original_instruction": "Lara is very concerned about her Computer Science assignment that requires her to understand the concepts of arrays and matrix manipulation. She needs your help with solving a specific problem in her assignment.\n\nYou are given an MxN matrix and you need to find the sum of all elements in ... | 0.604225 | Code_Contests_12893 | C | [
"sum_elements_greater_than_k",
"create_matrix_and_calculate_sum"
] | 2 | [
[
"create_matrix_and_calculate_sum",
"sum_elements_greater_than_k"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | ad130a05a317b01f0544a41e1b390b305c26d44d | d1e2e0fd5c69e26d8d45445cd54ae31cd0bb6b1b | |||
v1.0 | complete | Code_Contests | Code_Contests_13038_C | def minimum_adjacent_swaps(rows: List[List[int]]) -> List[int]:
"""
Returns the minimum number of adjacent swaps needed to sort each row of plants.
Args:
rows (list of list): A list where each element is a list of integers representing plant heights.
Returns:
list: A list of integers w... | def merge_sort_and_count(arr):
"""
Helper function that uses merge sort and counts inversions.
Args:
arr (list): List of integers representing plant heights.
Returns:
tuple: A sorted list of integers and the count of adjacent swaps (inversions).
"""
if len(arr) <= 1:
re... | def test_minimum_adjacent_swaps():
assert minimum_adjacent_swaps([[3, 1, 2]]) == [2]
assert minimum_adjacent_swaps([[4, 5, 6]]) == [0]
assert minimum_adjacent_swaps([[1, 5, 3, 4]]) == [2]
assert minimum_adjacent_swaps([[1, 2, 3, 4, 5]]) == [0]
assert minimum_adjacent_swaps([[5, 4, 3, 2, 1]]) == [10]... | [
{
"docstring": "Helper function that uses merge sort and counts inversions.\n\nArgs:\narr (list): List of integers representing plant heights.\n\nReturns:\ntuple: A sorted list of integers and the count of adjacent swaps (inversions).",
"function_declaration": "def merge_sort_and_count(arr):",
"function... | [
0,
0,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def count_swaps_to_sort(arr):\n \"\"\"\n Returns the minimum number of adjacent swaps required to sort the array.\n \"\"\"\n n = len(arr)\n ... | trial_gpt4o_2 | {
"original_instruction": "Jon is passionate about gardening and decided to plant some flowers in his garden. He has several rows in his garden bed, and each row can be represented as a list of integers where each integer denotes the height of a plant. Jon wants to arrange the plants in each row such that the heights... | 0.523359 | Code_Contests_13038 | C | [
"merge_sort_and_count",
"merge_and_count",
"minimum_adjacent_swaps"
] | 3 | [
[
"merge_sort_and_count",
"merge_and_count"
],
[
"minimum_adjacent_swaps",
"merge_sort_and_count"
]
] | 2 | [] | false | [] | false | pytest | false | [] | true | f4e221b1c09acadbae5e4a169fdff2d34302e6f3 | 31620f8ac0572a4ab832ef63f1b3041ded049b6b | |||
v1.0 | complete | Code_Contests | Code_Contests_13789_C | def cycle_detector(n: int, matrix: List[List[int]]) -> str:
""" Determine if there is a cycle in the directed graph represented by the adjacency matrix.
Args:
n (int): the number of vertices in the graph
matrix (List[List[int]]): adjacency matrix of size n x n representing the graph
Returns:
st... | def has_cycle(n, graph):
def dfs(v, visited, rec_stack):
visited[v] = True
rec_stack[v] = True
for neighbour in range(n):
if graph[v][neighbour] != 0: # there is an edge
if not visited[neighbour]:
if dfs(neighbour, visited, rec_stack):
... | from solution import cycle_detector
def test_example_1():
n = 3
matrix = [
[0, 1, 0],
[0, 0, 1],
[1, 0, 0]
]
assert cycle_detector(n, matrix) == "YES"
def test_example_2():
n = 3
matrix = [
[0, 1, 0],
[0, 0, 1],
[0, 0, 0]
]
assert cycle_d... | [
{
"docstring": null,
"function_declaration": "def has_cycle(n, graph):",
"function_name": "has_cycle",
"parameter_list": "(n, graph)"
},
{
"docstring": null,
"function_declaration": "def cycle_detector(n, matrix):",
"function_name": "cycle_detector",
"parameter_list": "(n, matrix... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def has_cycle(n, graph):\n def dfs(vertex, visited, rec_stack):\n visited[vertex] = True\n rec_stack[vertex] = True\n\n for neighbo... | trial_gpt4o_2 | {
"original_instruction": "A directed graph is represented using an adjacency matrix of size n x n, where n is the number of vertices. An entry (i, j) in this matrix indicates the weight of the edge from vertex i to vertex j. A weight of 0 means there is no edge between these vertices. Your task is to determine if th... | 0.6084 | Code_Contests_13789 | C | [
"has_cycle",
"cycle_detector"
] | 2 | [
[
"cycle_detector",
"has_cycle"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | ca2070aa1ad26042e3f77073943b17b1da4df97b | 791086aaa6571d4d1f8128b41b507e0775dce9e7 | |||
v1.0 | complete | Code_Contests | Code_Contests_13578_C | class TreeNode:
def __init__(self, value):
""" Initialize a TreeNode with a given value. """
self.value = value
self.left = None
self.right = None
def find_levels(T: int, test_cases: List[Dict[str, Any]]) -> List[int]:
"""
For each test case, find the level of the node with... | class TreeNode:
def __init__(self, value):
self.value = value
self.left = None
self.right = None
def insert(root, value):
if root is None:
return TreeNode(value)
if value < root.value:
root.left = insert(root.left, value)
else:
root.right = insert(root.ri... | from solution import find_levels
def test_find_levels_case1():
T = 2
test_cases = [
{"NQ": (5, 3), "values": [10, 5, 3, 7, 15]},
{"NQ": (3, 10), "values": [5, 15, 20]}
]
assert find_levels(T, test_cases) == [3, -1]
def test_find_levels_case2():
T = 1
test_cases = [
{"NQ... | [] | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "class TreeNode:\n def __init__(self, val):\n self.val = val\n self.left = None\n self.right = None\n\ndef insert(root, key):\n i... | trial_gpt4o_1 | {
"original_instruction": "In Byteland, a magical land of bytes and bits, a new type of tree called a \"BitTree\" is being studied. A BitTree is a binary tree that follows a particular set of rules with respect to the values of its nodes.\n\nThe properties of a BitTree are:\n1. Each node has a distinct integer value.... | 0.537664 | Code_Contests_13578 | C | [
"insert",
"find_level",
"find_levels"
] | 3 | [
[
"find_levels",
"find_level"
],
[
"find_levels",
"insert"
]
] | 2 | [] | false | [
"TreeNode"
] | true | pytest | true | [] | true | c3275693a7aa0231725688227a534a7340e1eb01 | 4edcf9d844268af551f92c6bc866f237a432c2bf | |||
v1.0 | complete | Code_Contests | Code_Contests_14132_C | def is_palindrome(s: str) -> bool:
""" Checks if the given string s is a palindrome, ignoring spaces, punctuation, and capitalization.
>>> is_palindrome("A man, a plan, a canal, Panama") == True
>>> is_palindrome("hello") == False
"""
def check_palindromes(n: int, strings: List[str]) -> List[str]:
... | def is_palindrome(s):
"""
Checks if the given string s is a palindrome, ignoring spaces, punctuation, and capitalization.
"""
cleaned_s = ''.join(char.lower() for char in s if char.isalnum())
return cleaned_s == cleaned_s[::-1]
def check_palindromes(n, strings):
"""
For each string in strin... | from solution import is_palindrome, check_palindromes
def test_is_palindrome_single_word():
assert is_palindrome("racecar") == True
assert is_palindrome("hello") == False
def test_is_palindrome_with_spaces_and_punctuations():
assert is_palindrome("A man, a plan, a canal, Panama") == True
assert is_pal... | [
{
"docstring": "Checks if the given string s is a palindrome, ignoring spaces, punctuation, and capitalization.",
"function_declaration": "def is_palindrome(s):",
"function_name": "is_palindrome",
"parameter_list": "(s)"
},
{
"docstring": "For each string in strings, checks if it is a palind... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import re\n\ndef is_palindrome(s):\n \"\"\"\n Checks if the given string s is a palindrome, ignoring non-alphanumeric characters\n and case sensit... | trial_gpt4o_2 | {
"original_instruction": "A palindrome is a word, number, phrase, or other sequences of characters that reads the same forward and backward (ignoring spaces, punctuation, and capitalization). \n\nIn this problem, you need to write a program that checks if a given string is a palindrome. Your task is to read an integ... | 0.874779 | Code_Contests_14132 | C | [
"is_palindrome",
"check_palindromes"
] | 2 | [
[
"check_palindromes",
"is_palindrome"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | be2625e2cb3ce2bdff1ac3a799cd056ef18e7ebd | 4c81cedaf809e01337460a8439502b0a454ed959 | |||
v1.0 | complete | Code_Contests | Code_Contests_14178_C | MOD = 10**9 + 7
def catalan_number(n):
"""Calculate the nth Catalan number modulo 10^9 + 7."""
pass
def count_balanced_strings(n):
"""Calculate the number of balanced strings of length n.
A balanced string has an equal number of 'A's and 'B's, and for any prefix of the string,
the number of ... | MOD = 10**9 + 7
def catalan_number(n):
if n == 0:
return 1
c = [0]* (n + 1)
c[0] = 1
for i in range(1, n + 1):
c[i] = (2 * (2 * i - 1) * c[i - 1]) // (i + 1)
c[i] %= MOD
return c[n]
def count_balanced_strings(n):
if n % 2 != 0:
return 0
n //= 2
return ca... | from solution import count_balanced_strings
def test_balanced_strings_length_4():
assert count_balanced_strings(4) == 2
def test_balanced_strings_length_6():
assert count_balanced_strings(6) == 5
def test_balanced_strings_length_3():
assert count_balanced_strings(3) == 0
def test_balanced_strings_length... | [
{
"docstring": null,
"function_declaration": "def catalan_number(n):",
"function_name": "catalan_number",
"parameter_list": "(n)"
},
{
"docstring": null,
"function_declaration": "def count_balanced_strings(n):",
"function_name": "count_balanced_strings",
"parameter_list": "(n)"
... | [
0,
0,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "MOD = 10**9 + 7\n\ndef balanced_string_count(n):\n \"\"\"\n Returns the number of balanced strings of length n.\n \"\"\"\n if n % 2 != 0:\n ... | trial_gpt4o_2 | {
"original_instruction": "Ravi is building a special type of string called a \"balanced string\" for his research. A string is considered balanced if it has an equal number of 'A's and 'B's, and for any prefix of the string, the number of 'A's should never be less than the number of 'B's.\n\nFor instance, \"AABB\", ... | 0.627531 | Code_Contests_14178 | C | [
"catalan_number",
"count_balanced_strings"
] | 2 | [
[
"count_balanced_strings",
"catalan_number"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 1db54e41529a219ac384c119d75b99012946bbce | c2c960d2edd7a7708e71c001b915bb2da0fe4f59 | |||
v1.0 | complete | Code_Contests | Code_Contests_14338_C | from typing import List, Tuple
def communication_network_cost(n: int, m: int, connections: List[Tuple[int, int]]) -> int:
""" Determines if the network is robust and returns the cost if it is, otherwise returns -1.
>>> communication_network_cost(5, 6, [(1, 2), (2, 3), (3, 4), (4, 5), (5, 1), (2, 4)]) == 6
... | from collections import defaultdict, deque
def is_robust_network(n, m, cables):
"""
Determines if the network is robust and returns the cost if it is, otherwise returns -1.
:param n: Number of nodes
:param m: Number of cables
:param cables: List of tuples representing undirected cables between... | from solution import communication_network_cost
def test_robust_network():
assert communication_network_cost(5, 6, [(1, 2), (2, 3), (3, 4), (4, 5), (5, 1), (2, 4)]) == 6
def test_non_robust_network():
assert communication_network_cost(4, 2, [(1, 2), (3, 4)]) == -1
def test_minimal_network():
assert commu... | [
{
"docstring": "Determines if the network is robust and returns the cost if it is, otherwise returns -1.\n\n:param n: Number of nodes\n:param m: Number of cables\n:param cables: List of tuples representing undirected cables between nodes\n:return: Cost of the network if robust, otherwise -1",
"function_decl... | [
1,
0,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_robust_and_cost(n, m, cables):\n from collections import defaultdict, deque\n\n # Build the graph\n graph = defaultdict(list)\n for u, v... | trial_gpt4o_2 | {
"original_instruction": "You are developing a new communication system for a space station. The system consists of a network of nodes, each representing a communication device. There are cables connecting the nodes, enabling direct communication between them. Your task is to ensure that the communication network is... | 0.572387 | Code_Contests_14338 | C | [
"is_robust_network",
"communication_network_cost"
] | 2 | [
[
"communication_network_cost",
"is_robust_network"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 7bd27c7ccbd1f1b60deadebcfa75d57e1622e7bc | 7a0e7394a2a3c0c36a9076b4aa0f393129030e41 | |||
v1.0 | complete | Code_Contests | Code_Contests_14037_C | import math
from functools import reduce
def gcd_multiple(numbers):
return reduce(math.gcd, numbers)
def max_students(N: int, A: List[int]) -> int:
""" Calculate the maximum number of students that can receive sweets without having any leftovers.
Args:
N (int): The number of different types o... | import math
from functools import reduce
def gcd_multiple(numbers):
return reduce(math.gcd, numbers)
def max_students(N, A):
return gcd_multiple(A) | from solution import max_students
def test_case_1():
assert max_students(5, [4, 6, 8, 12, 16]) == 2
def test_case_2():
assert max_students(3, [2, 4, 8]) == 2
def test_case_3():
assert max_students(4, [1, 1, 1, 1]) == 1
def test_case_4():
assert max_students(2, [5, 10]) == 5
def test_case_5():
a... | [
{
"docstring": null,
"function_declaration": "def gcd_multiple(numbers):",
"function_name": "gcd_multiple",
"parameter_list": "(numbers)"
},
{
"docstring": null,
"function_declaration": "def max_students(N, A):",
"function_name": "max_students",
"parameter_list": "(N, A)"
}
] | [
0,
1,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import math\nfrom functools import reduce\n\ndef gcd_of_list(numbers):\n \"\"\"\n Function to calculate gcd of a list of numbers\n \"\"\"\n ret... | trial_gpt4o_2 | {
"original_instruction": "F: Sweets Distribution\n\nTamara is organizing a sweets distribution event at her school.\n\nThere are `N` different types of sweet packets, each containing `A_1, A_2, A_3, \\dots, A_N` pieces of sweets respectively.\n\nTamara wants to distribute the sweets such that each student gets an eq... | 0.618034 | Code_Contests_14037 | C | [
"gcd_multiple",
"max_students"
] | 2 | [
[
"max_students",
"gcd_multiple"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | ded0c723d436e2a62aacc1a3f81fc939a92d9937 | 3cea1c44c841648fbf951f0411418d5255640233 | |||
v1.0 | complete | Code_Contests | Code_Contests_14678_C | def is_palindrome(num: int) -> bool:
""" Check if a number is a palindrome.
>>> is_palindrome(121)
True
>>> is_palindrome(12321)
True
>>> is_palindrome(123)
False
"""
def largest_palindromic_product(n: int) -> int:
""" Find the largest palindromic number that can be obtained by ... | def is_palindrome(num):
return str(num) == str(num)[::-1]
def largest_palindromic_product(n):
if n < 1 or n > 6:
return -1
max_num = 10**n - 1
min_num = 10**(n-1)
max_palindrome = -1
for i in range(max_num, min_num - 1, -1):
for j in range(i, min_num - 1, -1):
... | from solution import is_palindrome, largest_palindromic_product
def test_is_palindrome():
assert is_palindrome(121) == True
assert is_palindrome(12321) == True
assert is_palindrome(123) == False
assert is_palindrome(1221) == True
assert is_palindrome(1001) == True
assert is_palindrome(1234) == ... | [
{
"docstring": null,
"function_declaration": "def is_palindrome(num):",
"function_name": "is_palindrome",
"parameter_list": "(num)"
},
{
"docstring": null,
"function_declaration": "def largest_palindromic_product(n):",
"function_name": "largest_palindromic_product",
"parameter_li... | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_palindrome(number):\n \"\"\"\n Check if a number is a palindrome.\n \"\"\"\n return str(number) == str(number)[::-1]\n\ndef largest_pali... | trial_gpt4o_1 | {
"original_instruction": "Chris is fascinated by palindrome numbers. A palindrome is a number that reads the same forwards and backwards, such as 121 or 1331. Chris is interested not only in plain palindromes but also in products of two numbers that result in a palindrome.\n\nHe wonders about the largest palindromic... | 0.706688 | Code_Contests_14678 | C | [
"is_palindrome",
"largest_palindromic_product"
] | 2 | [
[
"largest_palindromic_product",
"is_palindrome"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | ced05b7fc4622a430012ba119fb51c1fd4705366 | 2bc8774dbeba5c2e8cdd6068129f2e6f50bbecc0 | |||
v1.0 | complete | Code_Contests | Code_Contests_14728_C | def prime_factors(n: int) -> List[int]:
"""
Returns a list of prime factors of the given number n.
"""
def convert_list_to_prime_factors(lst: List[int]) -> List[int]:
"""
Converts a list of non-negative integers to a list of their prime factors.
>>> convert_list_to_prime_factors([10, 15, 23, 50... | def prime_factors(n):
"""
Returns a list of prime factors of the given number n.
"""
factors = []
# factor out 2s
while n % 2 == 0:
factors.append(2)
n //= 2
# factor out all odd numbers
for i in range(3, int(n**0.5) + 1, 2):
while n % i == 0:
factors... | from solution import convert_list_to_prime_factors
def test_convert_list_to_prime_factors():
assert convert_list_to_prime_factors([10, 15, 23, 50]) == [2, 5, 3, 5, 23, 2, 5, 5]
assert convert_list_to_prime_factors([4, 17, 8]) == [2, 2, 17, 2, 2, 2]
assert convert_list_to_prime_factors([2, 3, 5, 7]) == [2, ... | [
{
"docstring": "Returns a list of prime factors of the given number n.",
"function_declaration": "def prime_factors(n):",
"function_name": "prime_factors",
"parameter_list": "(n)"
},
{
"docstring": "Converts a list of non-negative integers to a list of their prime factors.",
"function_de... | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def prime_factors(n):\n factors = []\n # Check for number of 2s in n\n while n % 2 == 0:\n factors.append(2)\n n = n // 2\n # n m... | trial_gpt4o_1 | {
"original_instruction": "Your task is to convert a given list of non-negative integers into a new list such that every given integer is replaced by its prime factors (listed in ascending order). If the number is prime, it will be included as-is.\n\nInput\n\nThe first line contains an integer `n` — the number of int... | 0.82115 | Code_Contests_14728 | C | [
"prime_factors",
"convert_list_to_prime_factors"
] | 2 | [
[
"convert_list_to_prime_factors",
"prime_factors"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | d402d24275eaa8ca4d0c5424d2d1e9cbbeb031e5 | 0f4ada5620d7f31770c7734e47bdfd7498d4c982 | |||
v1.0 | complete | Code_Contests | Code_Contests_13882_C | def can_schedule_presentations(test_cases: List[Tuple[int, int, List[int], List[int]]]) -> List[str]:
""" Determine if it is possible to schedule all presentations within the time slots without exceeding the duration limits.
Each test case contains the number of presentations, number of time slots, list of pres... | def can_schedule_presentations(test_cases):
results = []
for case in test_cases:
n, m, durations, limits = case
if n > m:
results.append("NO")
continue
durations.sort()
limits.sort()
possible = True
for duration, limit in zip(durations, ... | def test_can_schedule_presentations():
input_str = '3\n3 3\n2 3 5\n6 5 4\n4 2\n3 1 2 4\n5 3\n5 5\n4 4 4 4 4\n5 5 5 5 1\n'
expected_output = 'YES\nNO\nNO'
assert process_input_output(input_str) == expected_output
def test_single_case_yes():
input_str = '1\n1 2\n3\n5 4\n'
expected_output = 'YES'
... | [
{
"docstring": null,
"function_declaration": "def can_schedule_presentations(test_cases):",
"function_name": "can_schedule_presentations",
"parameter_list": "(test_cases)"
},
{
"docstring": null,
"function_declaration": "def input_parser(input_lines):",
"function_name": "input_parser... | [
1,
0,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def can_schedule_presentations(t, test_cases):\n results = []\n for i in range(t):\n n, m = test_cases[i][0]\n d = test_cases[i][1]\n ... | trial_gpt4o_2 | {
"original_instruction": "Sylvia is organizing a conference, and she has to determine the schedule for n different presentations. Each presentation lasts for a certain amount of time, and there are m time slots available for presentations throughout the day. Sylvia must assign each presentation to one of the availab... | 0.553099 | Code_Contests_13882 | C | [
"can_schedule_presentations",
"input_parser",
"process_input_output"
] | 3 | [
[
"process_input_output",
"can_schedule_presentations"
],
[
"process_input_output",
"input_parser"
]
] | 2 | [
"process_input_output"
] | false | [] | false | pytest | false | [] | true | 3d1dfd17beee91d2a8cc2fe4922fbf16eff71894 | 74222a364c9bad8acd8d45d01fec29928a97f573 | |||
v1.0 | complete | Code_Contests | Code_Contests_14680_C | from typing import List, Tuple
def solve(n: int, values: List[int], edges: List[Tuple[int, int]], queries: List[Tuple[int, int]]) -> List[int]:
"""
You are given a tree with `n` nodes numbered from 1 to `n`. Each node has a value. You have to answer `q` queries. Each query consists of two integers, `u` and `v`... | from collections import defaultdict, deque
import sys
sys.setrecursionlimit(200000)
def preprocess_tree(n, values, edges):
LOG = 17
adj = defaultdict(list)
for a, b in edges:
adj[a].append(b)
adj[b].append(a)
up = [[-1] * (LOG + 1) for _ in range(n + 1)]
max_on_path = [[-1] * (... | from solution import solve
def test_example_case():
n = 5
values = [1, 5, 2, 4, 3]
edges = [(1, 2), (1, 3), (3, 4), (3, 5)]
queries = [(2, 3), (4, 1), (4, 5)]
results = solve(n, values, edges, queries)
expected = [5, 4, 4]
assert results == expected
def test_simple_case():
n = 2
... | [
{
"docstring": null,
"function_declaration": "def preprocess_tree(n, values, edges):",
"function_name": "preprocess_tree",
"parameter_list": "(n, values, edges)"
},
{
"docstring": null,
"function_declaration": "def solve(n, values, edges, queries):",
"function_name": "solve",
"pa... | [
1,
0
] | 1 | medium | 0.5 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from collections import defaultdict, deque\nimport sys\n\nsys.setrecursionlimit(200000)\n\ndef preprocess_tree(n, values, edges):\n LOG = 17 \n\n ad... | trial_gpt4o_0 | {
"original_instruction": "You are given a tree with `n` nodes numbered from 1 to `n`. Each node has a value. You have to answer `q` queries. Each query consists of two integers, `u` and `v` and asks for the maximum value of the nodes in the path from `u` to `v`.\n\nInput\n\nThe first line of the input contains an in... | 0.660096 | Code_Contests_14680 | C | [
"preprocess_tree",
"solve"
] | 2 | [
[
"solve",
"preprocess_tree"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 3082db6a7863658379a3dd2ec872a8c30864e35f | 81405d7f7dde4ce6225851d992b7b848daccb5dc | |||
v1.0 | complete | Code_Contests | Code_Contests_11978_C | def generate_jewel_pairs(test_cases: List[Tuple[int, List[int]]]) -> List[List[Tuple[int, int]]]:
""" Given a list of test cases, each containing an integer N and a list of N jewel indexes,
generate all unique pairs of jewels for each test case.
Parameters:
- test_cases: List of tuples, where each ... | def generate_jewel_pairs(test_cases):
result = []
for case in test_cases:
N, jewels = case
pairs = []
jewels.sort()
for i in range(N):
for j in range(i + 1, N):
pairs.append((jewels[i], jewels[j]))
result.append(pairs)
return result
def pa... | from solution import generate_jewel_pairs, parse_input, format_output, process_jewel_pairs
def test_generate_jewel_pairs_single_test():
test_cases = [(4, [8, 3, 1, 2])]
expected_output = [
[(1, 2), (1, 3), (1, 8), (2, 3), (2, 8), (3, 8)]
]
assert generate_jewel_pairs(test_cases) == expected_out... | [
{
"docstring": null,
"function_declaration": "def generate_jewel_pairs(test_cases):",
"function_name": "generate_jewel_pairs",
"parameter_list": "(test_cases)"
},
{
"docstring": null,
"function_declaration": "def parse_input(input_string):",
"function_name": "parse_input",
"param... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def get_unique_pairs(T, test_cases):\n \"\"\"\n Given the number of test cases and the subsequent test cases,\n this function returns the unique p... | trial_gpt4o_2 | {
"original_instruction": "In a famous kingdom, there were a lot of jewels in the royal treasure. One day, the king decided to distribute the jewels among the citizens in such a way that each citizen gets exactly two jewels and no two citizens get the same pair of jewels. For security reasons, he also decided that ea... | 0.548442 | Code_Contests_11978 | C | [
"generate_jewel_pairs",
"parse_input",
"format_output",
"process_jewel_pairs"
] | 4 | [
[
"process_jewel_pairs",
"format_output"
],
[
"process_jewel_pairs",
"generate_jewel_pairs"
],
[
"process_jewel_pairs",
"parse_input"
]
] | 3 | [
"parse_input",
"format_output"
] | false | [] | false | pytest | true | [] | true | 6db5509f83e02902c9d804f70a7614ab33bd434c | 51b4390070adc17d57fab564eded3ff428c57add | |||
v1.0 | complete | Code_Contests | Code_Contests_14321_C | from collections import deque
from typing import List, Tuple
def minimum_max_distance(n: int, roads: List[Tuple[int, int]]) -> int:
"""
Return the minimum possible maximum distance from an optimally placed headquarters.
n : int : number of villages
roads : List[Tuple[int, int]] : list of roads co... | from collections import deque
def find_furthest_node(n, graph, start):
"""
Perform BFS to find the furthest node from the start node.
Returns the node and its distance from the start.
"""
visited = [False] * (n + 1)
queue = deque([(start, 0)]) # (current_node, current_distance)
visited[sta... | import pytest
from solution import minimum_max_distance
def test_case_1():
n = 4
roads = [(1, 2), (2, 3), (3, 4)]
assert minimum_max_distance(n, roads) == 2
def test_case_2():
n = 6
roads = [(1, 2), (1, 3), (3, 4), (3, 5), (4, 6)]
assert minimum_max_distance(n, roads) == 2
def test_case_3():... | [
{
"docstring": "Perform BFS to find the furthest node from the start node.\nReturns the node and its distance from the start.",
"function_declaration": "def find_furthest_node(n, graph, start):",
"function_name": "find_furthest_node",
"parameter_list": "(n, graph, start)"
},
{
"docstring": "... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from collections import deque\n\ndef find_farthest_node(n, graph, start):\n \"\"\"\n Function to return the farthest node and its distance from the s... | trial_gpt4o_2 | {
"original_instruction": "In a mythical kingdom, there are n villages connected by n-1 roads, making up a tree structure. Each village is labeled from 1 to n. The king wants to set up a courier system to facilitate communication between the villages. The courier system is designed so that every village has exactly o... | 0.683375 | Code_Contests_14321 | C | [
"find_furthest_node",
"minimum_max_distance"
] | 2 | [
[
"minimum_max_distance",
"find_furthest_node"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | e7d1c181dcb522909f8a920ff76bd6a24ad02d48 | 993a78a386c4ce52dae7076dd5c6bd7318b2b891 | |||
v1.0 | complete | Code_Contests | Code_Contests_14064_C | def factorial(n: int) -> int:
""" Calculate the factorial of a given number n.
>>> factorial(0) == 1
>>> factorial(1) => 1
>>> factorial(2) => 2
>>> factorial(3) => 6
>> factorial(4) => 24
>>> factorial(5) => 120
"""
def unique_paths(N: int, M: int) -> int:
""" Calculate the number ... | def factorial(n):
if n == 0 or n == 1:
return 1
result = 1
for i in range(2, n + 1):
result *= i
return result
def unique_paths(N, M):
# The number of unique paths is given by the binomial coefficient (N+M-2) choose (M-1)
return factorial(N + M - 2) // (factorial(N - 1) * factor... | def test_factorial():
assert factorial(0) == 1
assert factorial(1) == 1
assert factorial(2) == 2
assert factorial(3) == 6
assert factorial(4) == 24
assert factorial(5) == 120
def test_unique_paths():
assert unique_paths(2, 2) == 2
assert unique_paths(3, 3) == 6
assert unique_paths(3... | [
{
"docstring": null,
"function_declaration": "def factorial(n):",
"function_name": "factorial",
"parameter_list": "(n)"
},
{
"docstring": null,
"function_declaration": "def unique_paths(N, M):",
"function_name": "unique_paths",
"parameter_list": "(N, M)"
},
{
"docstring":... | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import math\n\ndef number_of_paths(n, m):\n \"\"\"\n Function to calculate the number of unique paths in an NxM grid.\n It uses the binomial coeff... | trial_gpt4o_1 | {
"original_instruction": "Given an NxM grid, you are standing at the top-left corner (1, 1). Your goal is to reach the bottom-right corner (N, M). From any cell (i, j) in the grid, you can move either right to (i, j+1) or down to (i+1, j). You cannot move diagonally or out of the grid's bounds. Your task is to calcu... | 0.597714 | Code_Contests_14064 | C | [
"factorial",
"unique_paths",
"process_test_cases",
"main"
] | 4 | [
[
"process_test_cases",
"unique_paths"
],
[
"unique_paths",
"factorial"
]
] | 2 | [
"process_test_cases"
] | false | [] | false | pytest | false | [] | true | 928d048371b895439cd0489a3f5710f5fd5d0f3f | 974cd6168bccf88e5f34785abf36ed46c6e04579 | |||
v1.0 | complete | Code_Contests | Code_Contests_14845_C | def count_special_pairs(arr):
"""
This function counts the number of special pairs in the array
where a pair (x, y) is special if x + y is even.
"""
even_count = sum(1 for x in arr if x % 2 == 0)
odd_count = len(arr) - even_count
# Special pairs within evens and within odds
return even_... | def count_special_pairs(arr):
"""
This function counts the number of special pairs in the array
where a pair (x, y) is special if x + y is even.
"""
even_count = sum(1 for x in arr if x % 2 == 0)
odd_count = len(arr) - even_count
# Special pairs within evens and within odds
return even_... | from solution import max_special_pairs
def test_no_swaps():
assert max_special_pairs(4, 0, [2, 4, 6, 8]) == 6
assert max_special_pairs(5, 0, [1, 3, 5, 7, 9]) == 10
assert max_special_pairs(3, 0, [2, 3, 4]) == 1
def test_with_swaps():
assert max_special_pairs(6, 1, [1, 3, 5, 7, 2, 8]) == 15
assert ... | [
{
"docstring": "This function counts the number of special pairs in the array \nwhere a pair (x, y) is special if x + y is even.",
"function_declaration": "def count_special_pairs(arr):",
"function_name": "count_special_pairs",
"parameter_list": "(arr)"
},
{
"docstring": "This function retur... | [
0,
0,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def max_special_pairs(n, k, arr):\n # Count the number of even and odd numbers in the array\n num_even = sum(1 for x in arr if x % 2 == 0)\n num_o... | trial_gpt4o_2 | {
"original_instruction": "You are given an array of n integers where there are some pairs of integers that are special. A pair of integers (x, y) is considered special if x + y is even. Your task is to count the number of such special pairs in the array. \n\nYou can swap any two elements of the array k times. Determ... | 0.650411 | Code_Contests_14845 | C | [
"count_special_pairs",
"max_special_pairs"
] | 2 | [
[
"max_special_pairs",
"count_special_pairs"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 034c84deece7e83957c1384052861ad91211c53c | 0b380654a866cb5eb78d37958c32dc60a0efba64 | |||
v1.0 | complete | Code_Contests | Code_Contests_14898_C | def generate_parenthesis(n: int) -> List[str]:
""" Generates all possible balanced parenthesis sequences of length 2n.
>>> generate_parenthesis(1)
["()"]
>>> generate_parenthesis(2)
["(())", "()()"]
>>> generate_parenthesis(3)
["((()))", "(()())", "(())()", "()(())", "()()()"]
"""
def g... | def generate_parenthesis(n):
"""
Generates all possible balanced parenthesis sequences of length 2n.
"""
result = []
def backtrack(s='', left=0, right=0):
if len(s) == 2 * n:
result.append(s)
return
if left < n:
backtrack(s + '(', left + 1, right)
... | from solution import generate_parenthesis, generate_parenthesis_lexicographic
def test_generate_parenthesis():
assert generate_parenthesis(1) == ["()"]
assert generate_parenthesis(2) == ["(())", "()()"]
assert generate_parenthesis(3) == ["((()))", "(()())", "(())()", "()(())", "()()()"]
assert generate... | [
{
"docstring": "Generates all possible balanced parenthesis sequences of length 2n.",
"function_declaration": "def generate_parenthesis(n):",
"function_name": "generate_parenthesis",
"parameter_list": "(n)"
},
{
"docstring": "Generates and prints all possible balanced parenthesis sequences o... | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def generate_parenthesis(n):\n \"\"\"\n Generates all balanced parenthesis sequences of length 2n in lexicographic order.\n n: int, the number of ... | trial_gpt4o_1 | {
"original_instruction": "A balanced parenthesis sequence is a string containing only characters '(' and ')' such that the number of opening brackets '(' is equal to the number of closing brackets ')' and for any prefix of the string, the number of opening brackets is at least the number of closing brackets.\n\nGive... | 0.693162 | Code_Contests_14898 | C | [
"generate_parenthesis",
"generate_parenthesis_lexicographic"
] | 2 | [
[
"generate_parenthesis_lexicographic",
"generate_parenthesis"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | b54d017c0d8aa65354f81345ad7f58f43bb6de64 | 9f041a89b8fc6cfa4adb5e3623024845c15f7603 | |||
v1.0 | complete | Code_Contests | Code_Contests_14009_C | def main(input_string: str) -> str:
""" Given a 9×9 Sudoku puzzle where some of the cells are already filled with digits ranging from 1 to 9,
determine whether it is possible to completely fill the grid following the Sudoku rules:
- Each row must contain all digits from 1 to 9 without repetition.
- Each... | def is_valid_sudoku(board):
rows, cols, squares = {}, {}, {}
for r in range(9):
for c in range(9):
val = board[r][c]
if val != '.':
if r not in rows:
rows[r] = set()
if c not in cols:
cols[c] = set()
... | from solution import main
def test_valid_sudoku():
input_puzzle = """\
53..7....
6..195...
.98....6.
8...6...3
4..8.3..1
7...2...6
.6....28.
...419..5
....8..79
0"""
assert main(input_puzzle) == "Yes"
def test_invalid_sudoku():
input_puzzle = """\
53..7....
65.195...
.98....6.
8...6...3
4..8.3..1
7...2...... | [
{
"docstring": null,
"function_declaration": "def is_valid_sudoku(board):",
"function_name": "is_valid_sudoku",
"parameter_list": "(board)"
},
{
"docstring": null,
"function_declaration": "def solve_sudoku(board):",
"function_name": "solve_sudoku",
"parameter_list": "(board)"
}... | [
0,
0,
0,
1,
0
] | 1 | hard | 0.2 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_valid(board, row, col, num):\n for i in range(9):\n if board[row][i] == num:\n return False\n if board[i][col] == num:\n... | trial_gpt4o_3 | {
"original_instruction": "Given a 9×9 Sudoku puzzle where some of the cells are already filled with digits ranging from 1 to 9, determine whether it is possible to completely fill the grid following the Sudoku rules:\n\n- Each row must contain all digits from 1 to 9 without repetition.\n- Each column must contain al... | 0.671314 | Code_Contests_14009 | C | [
"is_valid_sudoku",
"solve_sudoku",
"find_empty_location",
"is_safe",
"process_input",
"main"
] | 6 | [
[
"process_input",
"solve_sudoku"
],
[
"solve_sudoku",
"find_empty_location"
],
[
"solve_sudoku",
"is_safe"
],
[
"solve_sudoku",
"is_valid_sudoku"
]
] | 4 | [
"process_input"
] | false | [] | false | pytest | true | [] | true | 387a8f30139942ec30fb7292e6cd992d44794976 | a438390be3c1770ddf871ba3bc817e968a2f4888 | |||
v1.0 | complete | Code_Contests | Code_Contests_14585_C | def is_prime(num: int) -> bool:
"""
Helper function to check if a number is prime.
>>> is_prime(1) False
>>> is_prime(2) True
>>> is_prime(4) False
>>> is_prime(3) True
>>> is_prime(5) True
>>> is_prime(9) False
>>> is_prime(23) True
"""
pass
def sum_of_primes(arr: List[int]... | def is_prime(num):
"""
Helper function to check if a number is prime.
"""
if num <= 1:
return False
if num == 2:
return True # 2 is the only even prime number
if num % 2 == 0:
return False # No other even number can be prime
sq_root = int(num**0.5) + 1
for i in ... | from solution import is_prime, sum_of_primes
def test_is_prime():
assert not is_prime(1)
assert is_prime(2)
assert not is_prime(4)
assert is_prime(3)
assert is_prime(5)
assert not is_prime(9)
assert is_prime(23)
def test_sum_of_primes():
assert sum_of_primes([2, 4, 6, 7, 11, 13]) == 33... | [
{
"docstring": "Helper function to check if a number is prime.",
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": "Returns the sum of prime numbers in the array.",
"function_declaration": "def sum_of_primes(arr):",
... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(num):\n \"\"\"\n Check whether a given number is prime.\n \"\"\"\n if num <= 1:\n return False\n if num == 2:\n r... | trial_gpt4o_1 | {
"original_instruction": "Given an integer array `arr` of size `n`, your task is to find and print the sum of the elements that are prime numbers. A number is prime if it is greater than 1 and has no divisors other than 1 and itself. Note that 1 is not a prime number.\n\nINPUT:\nThe first line contains an integer `n... | 0.788419 | Code_Contests_14585 | C | [
"is_prime",
"sum_of_primes",
"main"
] | 3 | [
[
"sum_of_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 45b939af717e908b73e11c2bc204df723827d9d0 | 43bf58ada13224475307e8dcdd60e18cc5811014 | |||
v1.0 | complete | Code_Contests | Code_Contests_15076_C | def process_commands(n: int, command_lines: List[str]) -> str:
""" Process a list of text editor commands and return the final state of the text.
>>> process_commands(5, ["1 a", "1 b", "2", "3", "1 c"]) "abc"
>>> process_commands(7, ["1 x", "1 y", "1 z", "2", "2", "3", "3"]) "xyz"
""" | def text_editor(commands):
current_text = []
undo_stack = []
redo_stack = []
for command in commands:
if command.startswith("1"):
_, char = command.split()
current_text.append(char)
undo_stack.append(char)
redo_stack.clear() # Clear redo stac... | def test_process_commands():
assert process_commands(5, ["1 a", "1 b", "2", "3", "1 c"]) == "abc"
assert process_commands(7, ["1 x", "1 y", "1 z", "2", "2", "3", "3"]) == "xyz"
assert process_commands(4, ["1 d", "1 e", "1 f", "2"]) == "de"
assert process_commands(6, ["1 a", "1 b", "2", "1 c", "3", "3"])... | [
{
"docstring": null,
"function_declaration": "def text_editor(commands):",
"function_name": "text_editor",
"parameter_list": "(commands)"
},
{
"docstring": null,
"function_declaration": "def process_commands(n, command_lines):",
"function_name": "process_commands",
"parameter_lis... | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def process_commands(n, commands):\n text = []\n undo_stack = []\n redo_stack = []\n\n for command in commands:\n if command.startswith(... | trial_gpt4o_1 | {
"original_instruction": "You have been tasked with implementing a text editor with undo and redo functionalities. The editor supports two types of operations:\n1. Insert a character at the end of the current text.\n2. Undo the last operation.\n3. Redo the last undone operation.\n\nThe operations are given as a sequ... | 0.5398 | Code_Contests_15076 | C | [
"text_editor",
"process_commands"
] | 2 | [
[
"process_commands",
"text_editor"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | bfcdfbdb21397bba5099f919ff4c7319282b28c9 | c85729310747e93498d016c55c1c3d47af4b32a7 | |||
v1.0 | complete | Code_Contests | Code_Contests_14927_C | def can_form_word(word: str, letters: List[str]) -> bool:
"""
Check if a word can be formed with the given list of letters exactly once.
>>> can_form_word("dog", ["d", "o", "g"]) == True
>>> can_form_word("cat", ["c", "a", "t"]) == True
>>> can_form_word("bat", ["b", "a", "t", "x"]) == True
>>> ... | def can_form_word(word, letters):
"""
Check if a word can be formed with the given list of letters exactly once.
"""
letter_count = {}
for letter in letters:
if letter in letter_count:
letter_count[letter] += 1
else:
letter_count[letter] = 1
for char ... | from solution import can_form_word, words_from_letters
def test_can_form_word():
assert can_form_word("dog", ["d", "o", "g"]) == True
assert can_form_word("cat", ["c", "a", "t"]) == True
assert can_form_word("mouse", ["m", "o", "u", "s", "e"]) == True
assert can_form_word("bat", ["b", "a", "t", "x"]) =... | [
{
"docstring": "Check if a word can be formed with the given list of letters exactly once.",
"function_declaration": "def can_form_word(word, letters):",
"function_name": "can_form_word",
"parameter_list": "(word, letters)"
},
{
"docstring": "Returns the list of words that can be formed usin... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def can_form_word(word, letter_counts):\n for char in word:\n if char not in letter_counts or letter_counts[char] == 0:\n return False... | trial_gpt4o_2 | {
"original_instruction": "Problem Statement\n\nGiven a list of words and a list of letters, write a function that returns the list of words that can be formed using the given letters exactly once. Each letter can be used only once in a word. The order of words in the output should be the same as in the input.\n\nInp... | 0.709762 | Code_Contests_14927 | C | [
"can_form_word",
"words_from_letters"
] | 2 | [
[
"words_from_letters",
"can_form_word"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 0341b978ece3dac0125f4c73f09ef35f591ac841 | 0e6ad8134b7e5c8c74eecfedb5c4af583637ba5d | |||
v1.0 | complete | Code_Contests | Code_Contests_14955_C | def minimum_hike_time(n: int, m: int, trails: List[str], s: int) -> int:
""" Determine the minimum time Samantha needs to visit all landmarks and return to her starting point.
The function takes in:
- n: number of landmarks
- m: number of undirected trails
- trails: a list of strings representing th... | def tsp(n, m, edges, s):
import itertools
# Initializing adjacency matrix with a large value for non-adjacent nodes
inf = float('inf')
dist = [[inf] * n for _ in range(n)]
for a, b, t in edges:
dist[a-1][b-1] = min(dist[a-1][b-1], t)
dist[b-1][a-1] = min(dist[b-1][a-1], t)
... | def test_minimum_hike_time():
assert minimum_hike_time(4, 5, ["1 2 4", "2 3 3", "3 4 5", "4 1 2", "1 3 6"], 1) == 14
assert minimum_hike_time(3, 3, ["1 2 2", "2 3 2", "3 1 3"], 2) == 7
def test_minimum_hike_time_more_cases():
assert minimum_hike_time(4, 6, ["1 2 10", "1 3 15", "1 4 20", "2 3 35", "2 4 25",... | [
{
"docstring": null,
"function_declaration": "def tsp(n, m, edges, s):",
"function_name": "tsp",
"parameter_list": "(n, m, edges, s)"
},
{
"docstring": null,
"function_declaration": "def minimum_hike_time(n, m, trails, s):",
"function_name": "minimum_hike_time",
"parameter_list":... | [
0,
0,
0,
0,
0,
1,
1,
0,
0
] | 2 | hard | 0.222 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import heapq\n\ndef min_time_to_visit_all_landmarks(n, m, trails, s):\n def prim_mst(adj_list, n):\n visited = [False] * (n + 1)\n min_hea... | trial_gpt4o_7 | {
"original_instruction": "Samantha is hiking in the mountain range and plans to visit several landmark spots there. The mountain range is modeled as a collection of n landmarks connected by m undirected trails, each with a certain length. The length of each trail represents the time (in minutes) it takes to traverse... | 0.633564 | Code_Contests_14955 | C | [
"tsp",
"minimum_hike_time"
] | 2 | [
[
"minimum_hike_time",
"tsp"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | 3adc37230a0c706161708e5f042bfc004dab8872 | 7a4911fb82f8d97d62ca34b086d856c298afdfa8 | |||
v1.0 | complete | Code_Contests | Code_Contests_15203_C | def check_mirror_palindrome(s: str) -> str:
"""
Returns "YES" if the string s is a mirror palindrome, otherwise returns "NO".
>>> check_mirror_palindrome("AHA")
'YES'
>>> check_mirror_palindrome("CAT")
'NO'
>>> check_mirror_palindrome("WOW")
'YES'
>>> check_mirror_palindrome("O... | def is_mirror_palindrome(s):
mirror_letters = {'A', 'H', 'I', 'M', 'O', 'T', 'U', 'V', 'W', 'X', 'Y'}
# Check if all characters in the string are mirror letters
if all(char in mirror_letters for char in s):
return s == s[::-1]
return False
def check_mirror_palindrome(s):
"""
Return... | from solution import check_mirror_palindrome
def test_mirror_palindrome_yes():
assert check_mirror_palindrome("AHA") == "YES"
assert check_mirror_palindrome("WOW") == "YES"
assert check_mirror_palindrome("OTTO") == "YES"
assert check_mirror_palindrome("HIH") == "YES"
def test_mirror_palindrome_no():
... | [
{
"docstring": null,
"function_declaration": "def is_mirror_palindrome(s):",
"function_name": "is_mirror_palindrome",
"parameter_list": "(s)"
},
{
"docstring": "Returns \"YES\" if the string s is a mirror palindrome, otherwise returns \"NO\"",
"function_declaration": "def check_mirror_pa... | [
0,
0,
0,
1,
1
] | 2 | medium | 0.4 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_mirror_palindrome(s):\n \"\"\"\n Returns \"YES\" if the input string is a \"Mirror Palindrome\", otherwise returns \"NO\".\n \"\"\"\n mi... | trial_gpt4o_3 | {
"original_instruction": "A palindrome is a word that reads the same backward as forward, such as \"madam\" or \"level\". Another similar concept is a \"Mirror Palindrome,\" where the word forms the same word when replaced with their mirrored alphabets. For example:\n\n- 'A' ⇔ 'A'\n- 'H' ⇔ 'H'\n- 'I' ⇔ 'I'\n- 'M' ⇔ ... | 0.820088 | Code_Contests_15203 | C | [
"is_mirror_palindrome",
"check_mirror_palindrome"
] | 2 | [
[
"check_mirror_palindrome",
"is_mirror_palindrome"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | ab313fcf97dae666c50a12db778376a5fe8cef79 | 3a34b96289baa99b98a694634afee87841abe85f | |||
v1.0 | complete | Code_Contests | Code_Contests_15136_C | def ninja_mission(N: int, sensors: List[Tuple[int, int, int]], Ax: int, Ay: int, Bx: int, By: int) -> str:
"""
Determine if Sakura can reach from the starting point (Ax, Ay) to the destination point (Bx, By) without entering the detection range of any sensor.
Args:
N : int : The number of sensors.
... | import math
def is_detected(xi, yi, ri, Ax, Ay, Bx, By):
"""
Check if the line segment from (Ax, Ay) to (Bx, By) intersects with the circle centered at (xi, yi) with radius ri.
"""
# Vector AB
ABx = Bx - Ax
ABy = By - Ay
# Vector AP
APx = xi - Ax
APy = yi - Ay
# Project vector A... | from solution import ninja_mission
def test_sample_input_1():
N = 3
sensors = [(0, 0, 5), (10, 10, 3), (-5, -5, 2)]
Ax, Ay, Bx, By = -20, -20, 20, 20
assert ninja_mission(N, sensors, Ax, Ay, Bx, By) == "NO"
def test_sample_input_2():
N = 2
sensors = [(0, 0, 5), (10, 10, 3)]
Ax, Ay, Bx, By ... | [
{
"docstring": "Check if the line segment from (Ax, Ay) to (Bx, By) intersects with the circle centered at (xi, yi) with radius ri.",
"function_declaration": "def is_detected(xi, yi, ri, Ax, Ay, Bx, By):",
"function_name": "is_detected",
"parameter_list": "(xi, yi, ri, Ax, Ay, Bx, By)"
},
{
... | [
1,
1,
0
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import math\n\ndef is_point_in_circle(px, py, cx, cy, cr):\n \"\"\"\n Check if a point (px, py) is inside a circle with center (cx, cy) and radius cr... | trial_gpt4o_1 | {
"original_instruction": "Sakura is a ninja who has to complete her missions stealthily. Each mission requires navigating through fields of sensors that detect her movements. These sensors have circular detection ranges and are placed on a 2D coordinate system.\n\nEach sensor is described by its center coordinates (... | 0.603326 | Code_Contests_15136 | C | [
"is_detected",
"can_reach_destination",
"ninja_mission"
] | 3 | [
[
"can_reach_destination",
"is_detected"
],
[
"ninja_mission",
"can_reach_destination"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 7dde678639880e661500e8e17ecad65001fe8ef9 | 4ff9f23a3ec6034af5612c0590dd294401fa2ffd | |||
v1.0 | complete | Code_Contests | Code_Contests_15156_C | def minimize_max_workload(n:int, k:int, tasks:List[int]) -> int:
"""
Determine the best way to distribute tasks to employees such that the maximum time any single
employee spends on their assigned tasks is minimized.
>>> minimize_max_workload(5, 2, [4, 3, 7, 8, 9])
17
>>> minimize_max_workloa... | def is_possible(tasks, k, max_load):
current_sum = 0
required_workers = 1
for task in tasks:
if current_sum + task > max_load:
required_workers += 1
current_sum = task
if required_workers > k:
return False
else:
current_sum += ... | from solution import minimize_max_workload
def test_minimize_max_workload_example1():
assert minimize_max_workload(5, 2, [4, 3, 7, 8, 9]) == 17
def test_minimize_max_workload_example2():
assert minimize_max_workload(3, 3, [2, 15, 10]) == 15
def test_minimize_max_workload_example3():
assert minimize_max_w... | [
{
"docstring": null,
"function_declaration": "def is_possible(tasks, k, max_load):",
"function_name": "is_possible",
"parameter_list": "(tasks, k, max_load)"
},
{
"docstring": null,
"function_declaration": "def minimize_max_workload(n, k, tasks):",
"function_name": "minimize_max_work... | [
1,
0,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_possible(tasks, k, max_load):\n current_sum = 0\n required_workers = 1\n\n for task in tasks:\n if current_sum + task > max_load:\n ... | trial_gpt4o_0 | {
"original_instruction": "You are tasked with writing a program to help distribute tasks among employees in a way that minimizes the maximum workload any single employee receives.\n\nYou are given n tasks, each of which has a specific time requirement t_i (1 ≤ i ≤ n), and k employees available to undertake the tasks... | 0.658032 | Code_Contests_15156 | C | [
"is_possible",
"minimize_max_workload"
] | 2 | [
[
"minimize_max_workload",
"is_possible"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | c8fe8fe19b5b8f654ddd52f078a9c502b314868a | 46f7edca2e2a64146e53b4913c4962be31f5a763 | |||
v1.0 | complete | Code_Contests | Code_Contests_15017_C | import math
from typing import List
def is_prime(n: int) -> bool:
""" Determine if a number is a prime number.
>>> is_prime(2)
True
>>> is_prime(4)
False
"""
if n <= 1:
return False
if n <= 3:
return True
if n % 2 == 0 or n % 3 == 0:
return False
i = 5
... | import math
def is_prime(n):
if n <= 1:
return False
if n <= 3:
return True
if n % 2 == 0 or n % 3 == 0:
return False
i = 5
while i * i <= n:
if n % i == 0 or n % (i + 2) == 0:
return False
i += 6
return True
def prime_sum(sequence):
retu... | from solution import prime_sum
def test_primes_in_sequence():
assert prime_sum([3, 4, 7, 6, 5, 11]) == 26
def test_only_primes():
assert prime_sum([1, 2, 3, 4, 5]) == 10
def test_no_primes():
assert prime_sum([6, 8, 10]) == 0
def test_large_prime():
assert prime_sum([999983, 1000000]) == 999983
def... | [
{
"docstring": null,
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": null,
"function_declaration": "def prime_sum(sequence):",
"function_name": "prime_sum",
"parameter_list": "(sequence)"
}
] | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import math\n\ndef is_prime(n):\n \"\"\"\n Checks whether a number is prime.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n ... | trial_gpt4o_2 | {
"original_instruction": "Marc loves collecting data. Recently, he started analyzing numerical sequences to determine specific patterns and properties. One property that caught Marc's attention is the \"prime sum\" of a sequence. The prime sum of a sequence is the summation of all prime numbers present in the sequen... | 0.811233 | Code_Contests_15017 | C | [
"is_prime",
"prime_sum"
] | 2 | [
[
"prime_sum",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 749e8a6e27d491f26cccffe84341ea0c517cb8bc | 704e3d52857abe3b138098c11453d9f96b6b945a | |||
v1.0 | complete | Code_Contests | Code_Contests_15493_C | from itertools import permutations
from typing import List
def is_palindrome(s: str) -> bool:
return s == s[::-1]
def palindrome_permutations(s: str) -> List[str]:
"""
Returns all distinct palindromic permutations of the input string.
If no such permutations exist, returns ["None"].
>>> palin... | from itertools import permutations
def is_palindrome(s):
return s == s[::-1]
def palindrome_permutations(s):
"""
Returns all distinct palindromic permutations of the input string.
If no such permutations exist, returns ["None"].
"""
unique_permutations = set(permutations(s))
palindromes = ... | from solution import palindrome_permutations
def test_example1():
assert palindrome_permutations("aabb") == ["abba", "baab"]
def test_example2():
assert palindrome_permutations("abc") == ["None"]
def test_single_character():
assert palindrome_permutations("a") == ["a"]
def test_two_same_characters():
... | [
{
"docstring": null,
"function_declaration": "def is_palindrome(s):",
"function_name": "is_palindrome",
"parameter_list": "(s)"
},
{
"docstring": "Returns all distinct palindromic permutations of the input string.\nIf no such permutations exist, returns [\"None\"].",
"function_declaratio... | [
0,
0,
0,
1,
0
] | 1 | hard | 0.2 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from itertools import permutations\nfrom collections import Counter\n\ndef can_form_palindrome(s):\n \"\"\"\n Helper function to determine if a strin... | trial_gpt4o_3 | {
"original_instruction": "You are given a long string containing various characters. Your task is to find all the distinct permutations of the characters in the string that are palindromes.\n\nA palindrome is a string that reads the same backward as forward.\n\nConstraints:\n\n- The input string will consist of only... | 0.723188 | Code_Contests_15493 | C | [
"is_palindrome",
"palindrome_permutations"
] | 2 | [
[
"palindrome_permutations",
"is_palindrome"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | f6c227f26e9dbe5737bf2b9b7e7f785a91a3d654 | 4b27af4ea46eadfb208c1b14bde4c87734bebe2b | |||
v1.0 | complete | Code_Contests | Code_Contests_13075_C | from typing import List, Tuple
def tsp(adj_matrix: List[List[int]]) -> int:
"""Calculate the minimum delivery cost to cover all points starting from the first node.
:param adj_matrix: A list of lists representing the adjacency matrix of costs.
:return: The minimum cost to visit all nodes starting from... | from itertools import permutations
def tsp(adj_matrix):
n = len(adj_matrix)
nodes = list(range(n))
min_cost = float('inf')
# Create all permutations of nodes except the starting node 0
for perm in permutations(nodes[1:]):
current_cost = adj_matrix[0][perm[0]]
for i in range(len... | from solution import tsp, parse_input, solve_tsp
def test_tsp():
adj_matrix_1 = [
[0, 10, 15, 20],
[10, 0, 35, 25],
[15, 35, 0, 30],
[20, 25, 30, 0]
]
assert tsp(adj_matrix_1) == 80
adj_matrix_2 = [
[0, 29, 20],
[29, 0, 15],
[20, 15, 0]
]... | [
{
"docstring": null,
"function_declaration": "def tsp(adj_matrix):",
"function_name": "tsp",
"parameter_list": "(adj_matrix)"
},
{
"docstring": null,
"function_declaration": "def solve_tsp(problems):",
"function_name": "solve_tsp",
"parameter_list": "(problems)"
},
{
"doc... | [
1,
0
] | 1 | medium | 0.5 | {
"trial_gpt4o_0": null,
"trial_gpt4o_1": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared1_results_combined.jsonl",
"solution_code": "from itertools import permutations\n\ndef tsp(adj_matrix):\n n = len(adj_matrix)\n nodes = list(range(n))\n min_cost = fl... | trial_gpt4o_1 | {
"original_instruction": "Sam is a software engineer working on a drone delivery system. The goal of the system is to ensure that drones take the most efficient path between multiple delivery points. Each delivery point can be represented as a node, and the connections (paths) between them are the edges of a graph. ... | 0.653752 | Code_Contests_13075 | C | [
"tsp",
"solve_tsp",
"parse_input",
"main"
] | 4 | [
[
"solve_tsp",
"tsp"
]
] | 1 | [
"parse_input"
] | false | [] | false | pytest | true | [] | true | b4fbea8c99eb637d001d5cea889563f067d4bda1 | b6425c6187076636316693b81004d3513b60c846 | |||
v1.0 | complete | Code_Contests | Code_Contests_14101_C | from typing import List, Tuple
def solve(n: int, m: int, q: int, grid: List[str], queries: List[Tuple[int, int]]) -> List[int]:
"""
Compute the size of the regions containing specific cells in a grid, where regions are defined as connected cells containing the same character.
Args:
n (int): The n... | def find_region_size(grid, x, y, n, m, visited):
# Directions for moving up, down, left, right
directions = [(-1, 0), (1, 0), (0, -1), (0, 1)]
stack = [(x, y)]
start_char = grid[x][y]
size = 0
while stack:
cx, cy = stack.pop()
if visited[cx][cy]:
continue
... | def test_case_1():
n, m, q = 4, 4, 3
grid = [
"abab",
"baba",
"abab",
"baba"
]
queries = [(1, 1), (2, 2), (4, 2)]
assert solve(n, m, q, grid, queries) == [1, 1, 1]
def test_case_2():
n, m, q = 3, 3, 3
grid = [
"aaa",
"aba",
"aaa"
]... | [
{
"docstring": null,
"function_declaration": "def find_region_size(grid, x, y, n, m, visited):",
"function_name": "find_region_size",
"parameter_list": "(grid, x, y, n, m, visited)"
},
{
"docstring": null,
"function_declaration": "def solve(n, m, q, grid, queries):",
"function_name":... | [
0,
0,
0,
0,
1
] | 1 | hard | 0.2 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def find_region_size(grid, n, m, x, y, visited, char):\n \"\"\"\n Returns the size of the region containing the cell (x, y)\n \"\"\"\n if x < 0... | trial_gpt4o_4 | {
"original_instruction": "You are given a grid with n rows and m columns. Each cell in the grid contains a lowercase alphabet character. Two cells are considered connected if they share a side (top, bottom, left, or right) and contain the same character. A region is defined as a maximal set of connected cells that c... | 0.639083 | Code_Contests_14101 | C | [
"find_region_size",
"solve",
"fill_region_sizes"
] | 3 | [
[
"solve",
"fill_region_sizes"
],
[
"solve",
"find_region_size"
]
] | 2 | [] | false | [] | false | pytest | false | [] | true | 1534f063d2cc4febd8bff97ca9ac740e432f1bf3 | 3af12277ced4221e84dfa0a596f5ab0df85524e5 | |||
v1.0 | complete | Code_Contests | Code_Contests_15459_C | from typing import List, Union
def generate_pin_codes(n: int) -> Union[str, List[str]]:
""" Generate unique 4-digit pin codes for 'n' rooms, ensuring no two digits are the same and the pin code is not a palindrome.
>>> generate_pin_codes(1)
["1032"]
>>> generate_pin_codes(5)
["1032", "2043", "3052"... | from typing import List, Union
def is_valid_pin(pin: str) -> bool:
# Checks if pin is a 4-digit number with all unique digits and not a palindrome
if len(pin) != 4 or len(set(pin)) != 4:
return False
return pin != pin[::-1]
def generate_pin_codes(n: int) -> Union[str, List[str]]:
if n > 5040:
... | def test_generate_pin_codes_min_value():
result = generate_pin_codes(1)
assert isinstance(result, list)
assert len(result) == 1
assert len(result[0]) == 4
assert len(set(result[0])) == 4
assert result[0] != result[0][::-1]
def test_generate_pin_codes_sample_value():
result = generate_pin_co... | [
{
"docstring": null,
"function_declaration": "def is_valid_pin(pin):",
"function_name": "is_valid_pin",
"parameter_list": "(pin)"
},
{
"docstring": null,
"function_declaration": "def generate_pin_codes(n):",
"function_name": "generate_pin_codes",
"parameter_list": "(n)"
}
] | [
1,
0
] | 1 | medium | 0.5 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from typing import List, Union\n\ndef is_valid_pin(pin: str) -> bool:\n # Checks if pin is a 4-digit number with all unique digits and not a palindrome\... | trial_gpt4o_0 | {
"original_instruction": "A company wants to implement a new security system for their office building. The building has several entry points and each room inside requires a pin code to unlock. The pin codes for each room are generated based on specific rules to ensure maximum security.\n\nThe rules to generate a pi... | 0.470588 | Code_Contests_15459 | C | [
"is_valid_pin",
"generate_pin_codes"
] | 2 | [
[
"generate_pin_codes",
"is_valid_pin"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | e426bf4b3f7b75d90cbac8f245d16b4d653fdbc4 | 5e5dc42870dde1b45457a9120a2e533f41ec0494 | |||
v1.0 | complete | Code_Contests | Code_Contests_15135_C | def decode_message(k: int, s: str) -> str:
"""
Decodes the message ID to the original message.
Args:
k: int - number of words in the original message
s: str - encoded message ID
Returns:
str - original message with words separated by spaces
>>> decode_message(2, "hiddenmes... | def decode_message(k, s):
"""
Decodes the message IDs to the original message.
"""
# Initialize variables
words = []
start = 0
length = len(s)
# Iterate through the length of the string and extract words
while start < length:
for i in range(start, length + 1):
if... | import pytest
from solution import process_input, decode_message, prepare_master_word_list
def setup_function():
"""
Setup function to initialize the master word list before each test.
"""
prepare_master_word_list()
def test_process_input():
setup_function()
t = 2
test_cases = [
(2... | [
{
"docstring": "Decodes the message IDs to the original message.",
"function_declaration": "def decode_message(k, s):",
"function_name": "decode_message",
"parameter_list": "(k, s)"
},
{
"docstring": "Processes the input and returns the decoded messages.",
"function_declaration": "def pr... | [
0,
0,
0,
0,
0,
1,
0,
1,
0
] | 2 | hard | 0.222 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def decode_message(t, test_cases):\n results = []\n for testcase in test_cases:\n K, S = testcase\n words = []\n start = 0\n ... | trial_gpt4o_7 | {
"original_instruction": "A Tale of Two Cities\n\nOnce upon a time, in a land of thriving metropolis and rustic towns, communication was key to maintaining harmony between the citizens. Messages were a crucial part of everyday life, and the citizens developed a special method of generating message IDs. However, as t... | 0.572505 | Code_Contests_15135 | C | [
"decode_message",
"process_input",
"prepare_master_word_list"
] | 3 | [
[
"process_input",
"decode_message"
]
] | 1 | [
"process_input"
] | false | [] | false | pytest | true | [] | true | f0c99944318936e8deb9a640e6e40e2f089e75d9 | 92eb03d5e76ee250a3508f0b514465bbcbcd5e6d | |||
v1.0 | complete | Code_Contests | Code_Contests_15362_C | def generate_seating_arrangement(r, c):
""" Generate the seating arrangement in a spiral order for an examination hall.
:param r: number of rows
:param c: number of columns
:return: a 2D list representing the seating arrangement
Example:
>>> generate_seating_arrangement(3, 3)
[[9, 8, 7... | def generate_seating_arrangement(r, c):
mtrx = [[0] * c for _ in range(r)]
num = r * c
left, right, top, bottom = 0, c - 1, 0, r - 1
while left <= right and top <= bottom:
for i in range(left, right + 1): # left to right
mtrx[top][i] = num
num -= 1
top += 1
... | import pytest
from solution import generate_seating_arrangement, print_seating_arrangement
def test_3x3():
result = generate_seating_arrangement(3, 3)
expected = [
[9, 8, 7],
[2, 1, 6],
[3, 4, 5]
]
assert result == expected
def test_4x4():
result = generate_seating_arrangem... | [
{
"docstring": null,
"function_declaration": "def generate_seating_arrangement(r, c):",
"function_name": "generate_seating_arrangement",
"parameter_list": "(r, c)"
},
{
"docstring": null,
"function_declaration": "def print_seating_arrangement(r, c):",
"function_name": "print_seating_... | [
0,
0,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def generate_seating_arrangement(r, c):\n # Initialize the matrix with zeros\n matrix = [[0] * c for _ in range(r)]\n \n num = r * c\n top, ... | trial_gpt4o_2 | {
"original_instruction": "You are an invigilator at a prestigious university and you need to print the seating arrangement for an examination hall. The hall is arranged in a grid of `r` rows and `c` columns, and each student will be given a number `1` to `r*c` (in row-major order). Your task is to generate the seati... | 0.592249 | Code_Contests_15362 | C | [
"generate_seating_arrangement",
"print_seating_arrangement"
] | 2 | [
[
"print_seating_arrangement",
"generate_seating_arrangement"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | e91bca8a74ab0c2ee739f428e6a8ca4f79bafce9 | 2997578bd71709d7e9a4c8997386f19adfca8a83 | |||
v1.0 | complete | Code_Contests | Code_Contests_15559_C | from typing import List
MOD = 1_000_000_007
def update(arr: List[int], index: int, value: int):
"""Update the value at arr[index-1] to value."""
pass
def retrieve(arr: List[int], L: int, R: int) -> int:
"""Retrieve the product of the elements in the subarray from index L to index R, inclusive,
and re... | MOD = 1_000_000_007
def update(arr, index, value):
arr[index - 1] = value
def retrieve(arr, L, R):
result = 1
for i in range(L-1, R):
result = (result * arr[i]) % MOD
return result
def process_operations(N, M, arr, operations):
result = []
for op in operations:
parts = op.spli... | from solution import process_operations
def test_sample_input():
N = 5
M = 3
arr = [2, 3, 7, 5, 6]
operations = ["2 2 4", "1 3 4", "2 2 4"]
expected_output = [105, 60]
assert process_operations(N, M, arr, operations) == expected_output
def test_all_updates():
N = 3
M = 3
arr = [1, ... | [
{
"docstring": null,
"function_declaration": "def update(arr, index, value):",
"function_name": "update",
"parameter_list": "(arr, index, value)"
},
{
"docstring": null,
"function_declaration": "def retrieve(arr, L, R):",
"function_name": "retrieve",
"parameter_list": "(arr, L, R... | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "MOD = 1000000007\n\ndef update(arr, idx, val):\n arr[idx-1] = val\n\ndef retrieve(arr, L, R):\n product = 1\n for i in range(L-1, R):\n pro... | trial_gpt4o_1 | {
"original_instruction": "You are given an array of N integers A[1], A[2], ..., A[N]. You need to perform M update and retrieve operations. Each operation is one of the following types:\n\n1. Update: \"1 x v\" - Update the value of A[x] to v.\n2. Retrieve: \"2 L R\" - Retrieve the product of the elements in the suba... | 0.603271 | Code_Contests_15559 | C | [
"update",
"retrieve",
"process_operations"
] | 3 | [
[
"process_operations",
"retrieve"
],
[
"process_operations",
"update"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 2e2d118716bd868a454f94b5bdd053d6aa5cef52 | c1eaacb7d88571c13039eb3903a6dc821b716236 | |||
v1.0 | complete | Code_Contests | Code_Contests_15209_C | def quickselect(arr, low, high, k):
""" Recursive QuickSelect algorithm to find the k-th smallest element.
>>> quickselect([7, 10, 4, 3, 20, 15], 0, 5, 1)
4
>>> quickselect([7, 10, 4, 3, 20], 0, 4, 4)
20
"""
def partition(arr, low, high):
""" Partition the array for QuickSelect.
>>> par... | def quickselect(arr, low, high, k):
if low == high: # If the list contains only one element
return arr[low]
pivot_index = partition(arr, low, high)
if pivot_index == k:
return arr[pivot_index]
elif pivot_index < k:
return quickselect(arr, pivot_index + 1, high, k)
... | from solution import find_kth_smallest
def test_find_kth_smallest():
data = [
([7, 10, 4, 3, 20, 15], 6, 2, 4),
([7, 10, 4, 3, 20], 5, 5, 20),
([1], 1, 1, 1),
([2, 1], 2, 1, 1),
([3, 2, 1], 3, 3, 3),
([10, 9, 8, 7, 6, 5, 4, 3, 2, 1], 10, 7, 7),
([7, 10, 4, 3,... | [
{
"docstring": null,
"function_declaration": "def quickselect(arr, low, high, k):",
"function_name": "quickselect",
"parameter_list": "(arr, low, high, k)"
},
{
"docstring": null,
"function_declaration": "def partition(arr, low, high):",
"function_name": "partition",
"parameter_l... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def partition(arr, left, right):\n pivot = arr[right]\n i = left - 1\n for j in range(left, right):\n if arr[j] <= pivot:\n i +=... | trial_gpt4o_2 | {
"original_instruction": "You are given an array of n unique integers and an integer k. Your task is to find and return the k-th smallest element in the array using the recursive QuickSelect algorithm.\n\nInputs: \nThe first line contains two integers n and k (1 ≤ k ≤ n ≤ 1000) — the number of elements in the array ... | 0.579744 | Code_Contests_15209 | C | [
"quickselect",
"partition",
"find_kth_smallest"
] | 3 | [
[
"find_kth_smallest",
"quickselect"
],
[
"quickselect",
"partition"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 657cb7af7a6f9339e49d7109d38fb0f1a963f2e9 | 5478065f71ed8e68fea224e2cac6272da88626a2 | |||
v1.0 | complete | Code_Contests | Code_Contests_15536_C | def find_largest_square(n: int, m: int, grid: List[str]) -> int:
""" Find the maximum size of a square subgrid consisting only of 1s.
>>> find_largest_square(5, 6, [
"101001",
"111111",
"111111",
"011111",
"011111"
])
4
>>> find_largest_square(3, 3, [
... | def largest_square_subgrid(grid, n, m):
if n == 0 or m == 0:
return 0
# Create a DP table to store the size of the largest square subgrid ending at (i, j)
dp = [[0] * m for _ in range(n)]
max_side_length = 0
for i in range(n):
for j in range(m):
if grid[i][j] == '1':
... | from solution import find_largest_square
def test_sample_input():
n = 5
m = 6
grid = [
"101001",
"111111",
"111111",
"011111",
"011111"
]
assert find_largest_square(n, m, grid) == 4
def test_no_ones():
n = 3
m = 3
grid = [
"000",
... | [
{
"docstring": null,
"function_declaration": "def largest_square_subgrid(grid, n, m):",
"function_name": "largest_square_subgrid",
"parameter_list": "(grid, n, m)"
},
{
"docstring": null,
"function_declaration": "def find_largest_square(n, m, input_grid):",
"function_name": "find_lar... | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def largest_square_subgrid(grid):\n \"\"\"\n Finds the size of the largest square subgrid consisting only of 1s.\n \n :param grid: List of stri... | trial_gpt4o_1 | {
"original_instruction": "You are given a grid with n rows and m columns filled with binary digits (0s and 1s). Your task is to find the maximum size of a square subgrid consisting only of 1s.\n\nInput\n\nThe first line contains two integers n and m (1 ≤ n, m ≤ 100) — the number of rows and columns in the grid.\nEac... | 0.601296 | Code_Contests_15536 | C | [
"largest_square_subgrid",
"find_largest_square"
] | 2 | [
[
"find_largest_square",
"largest_square_subgrid"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 2fd4f49a01aebaabd5eab216493e06b670d2740f | 79250235d53947994c661241b1407e7b384043da | |||
v1.0 | complete | Code_Contests | Code_Contests_15710_C | def is_prime(num: int) -> bool:
"""
Check if a number is prime.
>>> is_prime(2) True
>>> is_prime(3) True
>>> is_prime(4) False
>>> is_prime(5) True
>>> is_prime(29) True
>>> is_prime(28) False
"""
def smallest_prime_greater_than(n: int) -> int:
"""
Returns the smallest prim... | def is_prime(num):
"""
Check if a number is prime.
"""
if num <= 1:
return False
if num <= 3:
return True
if num % 2 == 0 or num % 3 == 0:
return False
i = 5
while i * i <= num:
if num % i == 0 or num % (i + 2) == 0:
return False
i += 6... | def test_is_prime():
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(4) == False
assert is_prime(5) == True
assert is_prime(29) == True
assert is_prime(28) == False
def test_smallest_prime_greater_than():
assert smallest_prime_greater_than(12) == 13
assert smallest... | [
{
"docstring": "Check if a number is prime.",
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": "Returns the smallest prime number greater than n.",
"function_declaration": "def smallest_prime_greater_than(n):",
"fu... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(num):\n \"\"\"\n Check if a number is prime.\n \"\"\"\n if num <= 1:\n return False\n if num == 2:\n return True\... | trial_gpt4o_1 | {
"original_instruction": "John has always been fascinated by prime numbers. One day, he came across a problem that intrigued him. He wants to find the smallest prime number greater than a given number n. Can you help him solve this problem?\n\nA prime number is a natural number greater than 1 that has no positive di... | 0.80296 | Code_Contests_15710 | C | [
"is_prime",
"smallest_prime_greater_than"
] | 2 | [
[
"smallest_prime_greater_than",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | b20058c8349ebed494e5aa30ffa84649ff814df0 | 9d5ded073cd67a79d2e6aa6af9daba4c81558216 | |||
v1.0 | complete | Code_Contests | Code_Contests_14340_C | import sys
import heapq
from typing import List, Tuple
def find_minimum_distances(T: int, test_cases: List[Tuple[int, int, List[Tuple[int, int, int]], int, List[Tuple[int, int]]]]) -> List[int]:
""" Calculates the minimum distance to travel between pairs of locations in a city.
Args:
- T: int, number ... | import sys
import heapq
def floyd_warshall(n, graph):
dist = [[float('inf')] * n for _ in range(n)]
for u in range(n):
for v in range(n):
dist[u][v] = graph[u][v]
for k in range(n):
for i in range(n):
for j in range(n):
if dist[i][j] > dist[i][k] + ... | from solution import find_minimum_distances
def test_case_1():
T = 1
test_cases = [
(
4, 4,
[
(1, 2, 5),
(2, 3, 6),
(3, 4, 2),
(1, 4, 9)
],
3,
[
(1, 3),
... | [
{
"docstring": null,
"function_declaration": "def floyd_warshall(n, graph):",
"function_name": "floyd_warshall",
"parameter_list": "(n, graph)"
},
{
"docstring": null,
"function_declaration": "def find_minimum_distances(T, test_cases):",
"function_name": "find_minimum_distances",
... | [
0,
0,
0,
1
] | 1 | hard | 0.25 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import heapq\nfrom collections import defaultdict, deque\n\ndef dijkstra(adj_list, start, n):\n \"\"\"\n Computes the shortest paths from start node ... | trial_gpt4o_4 | {
"original_instruction": "A large event is being organized in a city with several locations connected by roads. To ensure efficient transportation of attendees, the organizers want to calculate the minimum distance required to travel between various pairs of locations. Attendees can travel in both directions along a... | 0.695254 | Code_Contests_14340 | C | [
"floyd_warshall",
"find_minimum_distances"
] | 2 | [
[
"find_minimum_distances",
"floyd_warshall"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 1e34094bb3b87b53b197d4215550be7e91b9de5e | afc94453c21813ea136601021e1eb4be8891ed48 | |||
v1.0 | complete | Code_Contests | Code_Contests_15989_C | def max_sum_permutation(arr):
"""
Rearranges the elements of the array to maximize the sum of absolute differences between consecutive elements.
Parameters:
arr (list): A list of integers.
Returns:
list: The rearranged list to achieve the maximum possible sum.
"""
... | def max_sum_permutation(arr):
"""
Rearranges the elements of the array to maximize the sum of absolute differences between consecutive elements.
Parameters:
arr (list): A list of integers.
Returns:
list: The rearranged list to achieve the maximum possible sum.
"""
#... | from solution import max_sum_permutation, max_sum_value
def test_max_sum_permutation():
assert max_sum_permutation([2, 1, 4, 3]) == [4, 1, 3, 2]
def test_max_sum_value():
assert max_sum_value([2, 1, 4, 3]) == 6
def test_max_sum_permutation_with_large_input():
n = 100000
arr = list(range(1, n + 1)... | [
{
"docstring": "Rearranges the elements of the array to maximize the sum of absolute differences between consecutive elements.\n\nParameters:\n arr (list): A list of integers.\n \nReturns:\n list: The rearranged list to achieve the maximum possible sum.",
"function_declaration": "def max_sum_permut... | [
0,
0,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def maximize_sum_of_absolute_differences(arr):\n \"\"\"\n Rearranges the elements of the array into a permutation that maximizes the sum\n of the ... | trial_gpt4o_2 | {
"original_instruction": "You are given an array of n elements consisting of integers ranging from 1 to n inclusive. You are required to rearrange the elements of the array into a permutation that maximizes the product of the following sum:\n\n sum = (absolute difference between 1st element and 2nd element) + \n ... | 0.686653 | Code_Contests_15989 | C | [
"max_sum_permutation",
"max_sum_value"
] | 2 | [
[
"max_sum_value",
"max_sum_permutation"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | bb95ea7f91d9c8e849eb5e803f8078e722dae01b | 28b28350f09f8cda601690c5ad355be0b57a0f28 | |||
v1.0 | complete | Code_Contests | Code_Contests_14027_C | class TreeNode:
def __init__(self, value=0, left=None, right=None):
self.value = value
self.left = left
self.right = right
def construct_tree(nodes):
""" Construct a binary tree from a list of nodes. """
tree_nodes = [TreeNode(value) for value, _, _ in nodes]
for idx, (value, le... | class TreeNode:
def __init__(self, value=0, left=None, right=None):
self.value = value
self.left = left
self.right = right
def construct_tree(nodes):
tree_nodes = [TreeNode(value) for value, _, _ in nodes]
for idx, (value, left, right) in enumerate(nodes):
if left != -1:
... | from solution import TreeNode, construct_tree, find_maximum_sum_path, max_sum_path_for_test_cases
def test_single_node():
nodes = [(3, -1, -1)]
root = construct_tree(nodes)
assert find_maximum_sum_path(root) == ([3], 3)
def test_example_case_1():
nodes = [
(3, 1, 2),
(1, -1, -1),
... | [] | [
0,
0,
0,
0,
1
] | 1 | hard | 0.2 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "class TreeNode:\n def __init__(self, value):\n self.value = value\n self.left = None\n self.right = None\n\ndef build_tree(nodes):\... | trial_gpt4o_4 | {
"original_instruction": "Problem Statement\nYou are given a binary tree composed of N nodes. Each node in the tree has an integer value assigned to it. Your task is to find a path from the root to a leaf such that the sum of the values of the nodes in the path is maximized.\n\nA path is defined as a sequence of nod... | 0.613251 | Code_Contests_14027 | C | [
"construct_tree",
"find_maximum_sum_path",
"max_sum_path_for_test_cases"
] | 3 | [
[
"max_sum_path_for_test_cases",
"construct_tree"
],
[
"max_sum_path_for_test_cases",
"find_maximum_sum_path"
]
] | 2 | [
"max_sum_path_for_test_cases"
] | false | [
"TreeNode"
] | true | pytest | true | [] | true | 8834fb296f5459ba28a1bcb27850c54ba6b6d3cc | 81f58eae1f295ba5790353b1ded296c38635a738 | |||
v1.0 | complete | Code_Contests | Code_Contests_16085_C | from typing import List
def longest_path_from_input(n: int, m: int, grid: List[str]) -> int:
""" Determine the length of the longest path of consecutive empty cells from the top-left to the bottom-right corner.
>>> longest_path_from_input(3, 3, ["..#", ".#.", "..."]) 4
>>> longest_path_from_input(4, 4, [".... | from collections import deque
def longest_path(grid):
n = len(grid)
m = len(grid[0])
if grid[0][0] == '#' or grid[n-1][m-1] == '#':
return -1
queue = deque([(0, 0, 0)])
visited = set((0, 0))
directions = [(0, 1), (1, 0), (0, -1), (-1, 0)]
while queue:
x, ... | from solution import longest_path_from_input
def test_case_1():
n = 3
m = 3
grid = [
"..#",
".#.",
"..."
]
assert longest_path_from_input(n, m, grid) == 4
def test_case_2():
n = 4
m = 4
grid = [
"....",
"##..",
"..#.",
"..##"
... | [
{
"docstring": null,
"function_declaration": "def longest_path(grid):",
"function_name": "longest_path",
"parameter_list": "(grid)"
},
{
"docstring": null,
"function_declaration": "def longest_path_from_input(n, m, matrix):",
"function_name": "longest_path_from_input",
"parameter... | [
0,
1,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from collections import deque\n\ndef longest_path(n, m, grid):\n \"\"\"\n Find the longest path from (0,0) to (n-1,m-1) in an n x m grid filled with ... | trial_gpt4o_2 | {
"original_instruction": "You are given a grid of size n x m filled with '.' and '#' characters, where '.' represents an empty cell and '#' represents an obstacle. The objective is to determine the length of the longest path of consecutive empty cells that the robot can travel on without touching any obstacle, start... | 0.626634 | Code_Contests_16085 | C | [
"longest_path",
"longest_path_from_input"
] | 2 | [
[
"longest_path_from_input",
"longest_path"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 84ef77db4955683bcd9f4591fc37e5121fd7f844 | 31d62e1040d5d5c9d5f14e045802829f63e2daf7 | |||
v1.0 | complete | Code_Contests | Code_Contests_16053_C | def is_prime(n: int) -> bool:
""" Determines if a number is a prime number.
>>> is_prime(2)
True
>>> is_prime(4)
False
"""
pass
def check_prime_sequence(sequence: List[int]) -> List[str]:
""" Given a sequence of integers, determine if each number (except the terminating zero) is prime.
... | def is_prime(n):
"""
Determines if a number is a prime number.
:param n: An integer to check for primality.
:return: True if the number is prime, otherwise False.
"""
if n <= 1:
return False
if n == 2:
return True
if n % 2 == 0:
return False
for i in rang... | from solution import is_prime, check_prime_sequence
def test_is_prime():
# Test known prime numbers
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(5) == True
assert is_prime(7) == True
assert is_prime(11) == True
# Test known non-prime numbers
assert is_prime... | [
{
"docstring": "Determines if a number is a prime number.\n\n:param n: An integer to check for primality.\n:return: True if the number is prime, otherwise False.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Given a sequ... | [
1,
1,
0
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(n):\n \"\"\"\n Checks if a number is a prime number.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return T... | trial_gpt4o_1 | {
"original_instruction": "Write a program that reads a sequence of integers and determines whether each number is a prime number. Each input set will be terminated by a zero, which should not be processed. The program should read input until a zero is encountered and then output \"Prime\" or \"Not Prime\" for each n... | 0.842563 | Code_Contests_16053 | C | [
"is_prime",
"check_prime_sequence"
] | 2 | [
[
"check_prime_sequence",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 40c81ec608586442b4a62b4dfbfd3c7d183bc487 | 9cd7d13b8615b57b5a26de8cb97fc50650c399e7 | |||
v1.0 | complete | Code_Contests | Code_Contests_15937_C | def max_profit(n: int, k: int, prices: List[int]) -> int:
""" Write a function to simulate the stock market trading process with limited trade transactions and given market trends.
n (int): number of days
k (int): maximum number of transactions
prices (List[int]): list of daily stock prices
>>>... | def max_profit(n: int, k: int, prices: list[int]) -> int:
if n == 0:
return 0
# If k is greater than n//2, it's equivalent to an unlimited transaction problem
if k >= n // 2:
return unlimited_transactions(prices)
# Create a 3D DP array
dp = [[0] * (k + 1) for _ in range(n)]... | from solution import max_profit
def test_max_profit_example():
assert max_profit(6, 2, [3, 2, 6, 5, 0, 3]) == 7
def test_max_profit_no_transactions():
assert max_profit(5, 0, [1, 2, 3, 4, 5]) == 0
def test_max_profit_no_profit():
assert max_profit(5, 1, [5, 4, 3, 2, 1]) == 0
def test_max_profit_single_d... | [
{
"docstring": null,
"function_declaration": "def max_profit(n, k, prices):",
"function_name": "max_profit",
"parameter_list": "(n, k, prices)"
},
{
"docstring": null,
"function_declaration": "def unlimited_transactions(prices):",
"function_name": "unlimited_transactions",
"param... | [
0,
0,
0,
1,
0
] | 1 | hard | 0.2 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def max_profit(n, k, prices):\n if not prices or k == 0:\n return 0\n\n # If k is greater than n // 2, it's essentially the same as an infinit... | trial_gpt4o_3 | {
"original_instruction": "Write a function to simulate the stock market trading process with limited trade transactions and given market trends.\n\n### Description\nYou are given a list of daily stock prices for a particular stock over a period of `n` days. Based on these prices, your goal is to maximize profit by p... | 0.720965 | Code_Contests_15937 | C | [
"max_profit",
"unlimited_transactions"
] | 2 | [
[
"max_profit",
"unlimited_transactions"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | bd5646ab81783f8a588aeca86139126f73df2c47 | 1ef1cbdf3fc2f1a765ec0d73eba73ea6039382dd | |||
v1.0 | complete | Code_Contests | Code_Contests_14241_C | def find_cut_vertices(n, adj):
"""
Function to find all cut vertices in a graph using Tarjan's Algorithm.
:param n: number of vertices
:param adj: adjacency list of the graph
:return: a list of cut vertices
"""
def dfs(current, discovery, low, parent, visited, articulation_points, time):
... | def find_cut_vertices(n, adj):
"""
Function to find all cut vertices in a graph using Tarjan's Algorithm.
:param n: number of vertices
:param adj: adjacency list of the graph
:return: a list of cut vertices
"""
def dfs(current, discovery, low, parent, visited, articulation_points, time):
... | import pytest
from solution import main
def test_example():
input_data = "2\n5 5\n1 2\n1 3\n3 4\n4 5\n4 2\n4 4\n1 2\n2 3\n3 4\n4 2"
output_data = "1\n1"
assert main(input_data) == output_data
def test_no_edges():
input_data = "1\n3 0"
output_data = "0"
assert main(input_data) == output_data
d... | [
{
"docstring": "Function to find all cut vertices in a graph using Tarjan's Algorithm.\n:param n: number of vertices\n:param adj: adjacency list of the graph\n:return: a list of cut vertices",
"function_declaration": "def find_cut_vertices(n, adj):",
"function_name": "find_cut_vertices",
"parameter_... | [
0,
0,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def find_cut_vertices(N, M, roads):\n import sys\n sys.setrecursionlimit(2000)\n from collections import defaultdict\n \n def dfs(cur, paren... | trial_gpt4o_2 | {
"original_instruction": "There is a city consisting of N intersections and M roads. Each road connects a pair of intersections. Your task is to find the number of intersections that, if removed along with their incident roads, will divide the city into two or more disconnected parts.\n\nAn intersection is called a ... | 0.55857 | Code_Contests_14241 | C | [
"find_cut_vertices",
"count_cut_vertices",
"process_input",
"main"
] | 4 | [
[
"count_cut_vertices",
"find_cut_vertices"
]
] | 1 | [
"process_input"
] | false | [] | false | pytest | true | [] | true | 15f6d6e7c453c39acc61ac990717ae3b1706386a | 1e2667f2d90838a1ffe9ef34ab9323451cf80172 | |||
v1.0 | complete | Code_Contests | Code_Contests_16060_C | from typing import List, Tuple
def ip_to_int(ip: str) -> int:
"""
Convert a dotted-quad IP address to a 32-bit integer.
"""
octets = map(int, ip.split('.'))
return sum(o << (8 * i) for i, o in enumerate(reversed(list(octets))))
def firewall_rules(n: int, q: int, rules: List[Tuple[str, str]], reque... | def ip_to_int(ip):
"""
Convert a dotted-quad IP address to a 32-bit integer.
"""
octets = map(int, ip.split('.'))
return sum(o << (8 * i) for i, o in enumerate(reversed(list(octets))))
def firewall_rules(n, q, rules, requests):
allowed_ranges = []
for rule in rules:
start, end = map... | from solution import firewall_rules
def test_firewall_rules():
rules = [
("192.168.1.1", "192.168.1.10"),
("10.0.0.1", "10.0.0.255"),
("172.16.4.5", "172.16.4.10")
]
requests = [
"192.168.1.5",
"10.0.0.200",
"172.16.4.11",
"8.8.8.8"
]
... | [
{
"docstring": "Convert a dotted-quad IP address to a 32-bit integer.",
"function_declaration": "def ip_to_int(ip):",
"function_name": "ip_to_int",
"parameter_list": "(ip)"
},
{
"docstring": null,
"function_declaration": "def firewall_rules(n, q, rules, requests):",
"function_name": ... | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def ip_to_int(ip):\n \"\"\"\n Converts a dotted-quad IP address to a 32-bit integer.\n \"\"\"\n parts = list(map(int, ip.split('.')))\n retu... | trial_gpt4o_1 | {
"original_instruction": "You are given a set of firewall rules and a list of access requests. Each firewall rule specifies a range of IP addresses that are allowed, and each access request contains an IP address. You need to determine whether each access request will be allowed based on the given rules.\n\nInput\n\... | 0.633382 | Code_Contests_16060 | C | [
"ip_to_int",
"firewall_rules"
] | 2 | [
[
"firewall_rules",
"ip_to_int"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 43ed85712957262d7200f5f1ad2d7a9efaa5a221 | 60f779df22a6759697bf3d3cdb9acf2e9df163f9 | |||
v1.0 | complete | Code_Contests | Code_Contests_15875_C | class TreeNode:
def __init__(self, val):
self.val = val
self.children = []
def build_tree(n, node_values, parent_indices):
""" Builds the binary tree from the given node values and parent indices.
>>> root = build_tree(7, [5, 3, 6, 8, 7, 2, 4], [0, 1, 1, 3, 3, 2, 2])
"""
def find_max_v... | class TreeNode:
def __init__(self, val):
self.val = val
self.children = []
def build_tree(n, node_values, parent_indices):
nodes = {i: TreeNode(node_values[i]) for i in range(n)}
root = None
for i in range(n):
parent = parent_indices[i]
if parent == 0:
root =... | import pytest
from solution import build_tree, process_queries, TreeNode
def test_example():
n = 7
node_values = [5, 3, 6, 8, 7, 2, 4]
parent_indices = [0, 1, 1, 3, 3, 2, 2]
queries = [(1, 10), (1,), (2,), (3, 20), (1,)]
# Building tree
root = build_tree(n, node_values, parent_indices)
... | [] | [
1,
0,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "class TreeNode:\n def __init__(self, val):\n self.val = val\n self.children = []\n\ndef build_tree(n, node_values, parent_indices):\n n... | trial_gpt4o_0 | {
"original_instruction": "You are given a binary tree with not more than 10^4 nodes. Each node has an integer value associated with it. Your task is to perform the following queries on this binary tree:\n\n1. **u v**: Find the maximum value in the subtree rooted at node `u` and replace it with `v`.\n\n2. **u**: Retu... | 0.588719 | Code_Contests_15875 | C | [
"build_tree",
"find_max_val_rooted_at",
"replace_max_val",
"max_in_subtree",
"process_queries"
] | 5 | [
[
"process_queries",
"max_in_subtree"
],
[
"process_queries",
"replace_max_val"
],
[
"replace_max_val",
"max_in_subtree"
]
] | 3 | [
"process_queries"
] | false | [
"TreeNode"
] | true | pytest | true | [] | true | c8d80c9a095b6a6e8108655393514571d1afe785 | 889124f8b957d9216765213371f850e6c113f22a | |||
v1.0 | complete | Code_Contests | Code_Contests_16134_C | from collections import deque, defaultdict
def is_bipartite(adj_list, n):
"""
Determines if the given graph is bipartite.
adj_list: Adjacency list representation of the graph
n: Number of vertices
"""
pass # To be implemented
def process_input(input_data):
input_lines = input_data.str... | from collections import deque, defaultdict
def is_bipartite(adj_list, n):
"""
Determines if the given graph is bipartite.
adj_list: Adjacency list representation of the graph
n: Number of vertices
"""
colors = [-1] * (n + 1)
for i in range(1, n + 1):
if colors[i] == -1: #... | def test_is_bipartite_empty_graph():
input_data = "1\n0 0"
assert is_bipartite_graph(input_data) == "Yes"
def test_is_bipartite_small_graph():
input_data = "1\n3 2\n1 2\n2 3"
assert is_bipartite_graph(input_data) == "Yes"
def test_is_bipartite_cycle_of_four():
input_data = "1\n4 4\n1 2\n2 3\n3 4\n... | [
{
"docstring": "Determines if the given graph is bipartite.\n\nadj_list: Adjacency list representation of the graph\nn: Number of vertices",
"function_declaration": "def is_bipartite(adj_list, n):",
"function_name": "is_bipartite",
"parameter_list": "(adj_list, n)"
},
{
"docstring": null,
... | [
0,
1,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_bipartite_graph(n, adj):\n color = [-1] * n\n\n def dfs(node, c):\n color[node] = c\n for neighbor in adj[node]:\n if... | trial_gpt4o_2 | {
"original_instruction": "Write a function that takes as input a list of integers which represents the vertices of a graph, and a list of pairs of integers which represents the edges of the graph. The task is to determine if the graph is a bipartite graph.\n\nA graph is bipartite if it is possible to divide its vert... | 0.580647 | Code_Contests_16134 | C | [
"is_bipartite",
"process_input",
"is_bipartite_graph"
] | 3 | [
[
"is_bipartite_graph",
"process_input"
],
[
"process_input",
"is_bipartite"
]
] | 2 | [
"process_input"
] | false | [] | false | pytest | false | [] | true | 2d12aefacedbd44e98bfccf77a726b459ed1ac4b | bd1b7e44128b6eafce774d6b193ca10501c6b377 | |||
v1.0 | complete | Code_Contests | Code_Contests_16417_C | from typing import List, Tuple
def process_input(data: str) -> List[List[Tuple[int, int]]]:
"""
This function processes the input data into a list of datasets where each dataset is a list of tuples.
Each tuple contains two integers: course ID and time slot ID.
"""
pass
def count_course_combination... | def count_course_combinations(datasets):
results = []
for dataset in datasets:
time_slots = {}
for course, slot in dataset:
if slot not in time_slots:
time_slots[slot] = 0
time_slots[slot] += 1
if len(time_slots) < max(time_s... | def test_process_input():
input_data = "2\n4\n101 1\n102 2\n103 1\n104 2\n0 0\n5\n201 1\n202 1\n203 2\n204 2\n205 3\n0 0\n0\n"
expected_output = [
[(101, 1), (102, 2), (103, 1), (104, 2)],
[(201, 1), (202, 1), (203, 2), (204, 2), (205, 3)]
]
assert process_input(input_data) == expected_o... | [
{
"docstring": null,
"function_declaration": "def count_course_combinations(datasets):",
"function_name": "count_course_combinations",
"parameter_list": "(datasets)"
},
{
"docstring": null,
"function_declaration": "def process_input(data):",
"function_name": "process_input",
"par... | [
0,
0,
0,
0,
0,
0,
0,
0,
1,
0
] | 1 | hard | 0.1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def count_course_selections(datasets):\n from collections import defaultdict\n results = []\n \n for dataset in datasets:\n slot_courses... | trial_gpt4o_8 | {
"original_instruction": "problem\n\nIn a certain institute, students are given the opportunity to take additional courses during the summer. Each student can select from a list of available summer courses, with the constraint that they must attend exactly one course in each of the given time slots. Courses are offe... | 0.616513 | Code_Contests_16417 | C | [
"count_course_combinations",
"process_input",
"solution"
] | 3 | [
[
"solution",
"count_course_combinations"
],
[
"solution",
"process_input"
]
] | 2 | [
"process_input"
] | false | [] | false | pytest | false | [] | true | 3fc17fe18f929a18cb4d41664ef9fcc945ff3c16 | 77702af393eb4a7f86609074267711c5879d3b57 | |||
v1.0 | complete | Code_Contests | Code_Contests_15883_C | def count_distinct_prime_factors(n: int) -> int:
"""
Returns the number of distinct prime factors of the integer n.
>>> count_distinct_prime_factors(12) == 2
>>> count_distinct_prime_factors(18) == 2
>>> count_distinct_prime_factors(29) == 1
>>> count_distinct_prime_factors(45) == 2
"""
... | def count_distinct_prime_factors(n):
"""
Returns the number of distinct prime factors of the integer n.
"""
distinct_factors = set()
# Check for number of 2s that divide n
while n % 2 == 0:
distinct_factors.add(2)
n = n // 2
# n must be odd at this point so we can ... | from solution import count_distinct_prime_factors, process_numbers_until_zero
def test_count_distinct_prime_factors():
assert count_distinct_prime_factors(12) == 2 # factors are 2 and 3
assert count_distinct_prime_factors(18) == 2 # factors are 2 and 3
assert count_distinct_prime_factors(29) == 1 # fact... | [
{
"docstring": "Returns the number of distinct prime factors of the integer n.",
"function_declaration": "def count_distinct_prime_factors(n):",
"function_name": "count_distinct_prime_factors",
"parameter_list": "(n)"
},
{
"docstring": "Processes a list of numbers and returns the number of d... | [
0,
0,
0,
0,
1
] | 1 | hard | 0.2 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from math import isqrt\n\ndef count_distinct_prime_factors(n):\n \"\"\"\n Returns the number of distinct prime factors of the integer n.\n \"\"\"\... | trial_gpt4o_4 | {
"original_instruction": "Your task is to find the number of distinct prime factors of each integer in an input list.\n\n**Input:**\n\n- The input consists of multiple data sets, each containing a single integer n (2 ≤ n ≤ 100000).\n- The end of input is indicated by n = 0.\n\n**Output:**\n\n- For each data set, pri... | 0.668621 | Code_Contests_15883 | C | [
"count_distinct_prime_factors",
"process_numbers_until_zero"
] | 2 | [
[
"process_numbers_until_zero",
"count_distinct_prime_factors"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | dc64cc718cb2c755b4822b9138164e1708d7a3d3 | eae004c1ac1904ac8929c47bf64e15811b72c363 | |||
v1.0 | complete | Code_Contests | Code_Contests_16668_C | def check_quasi_prime(n: int) -> str:
""" Determine if a given number is a quasi-prime.
A number is considered quasi-prime if it has exactly three distinct prime factors.
>>> check_quasi_prime(30)
"Yes"
>>> check_quasi_prime(100)
"No"
""" | def is_prime(num):
"""
Helper function to check if a number is prime.
"""
if num <= 1:
return False
if num <= 3:
return True
if num % 2 == 0 or num % 3 == 0:
return False
i = 5
while i * i <= num:
if num % i == 0 or num % (i + 2) == 0:
return F... | from solution import check_quasi_prime
def test_quasi_prime_yes():
assert check_quasi_prime(30) == "Yes" # 2 * 3 * 5
def test_quasi_prime_no_two_primes():
assert check_quasi_prime(100) == "No" # 2 * 2 * 5 * 5
def test_quasi_prime_no_non_prime():
assert check_quasi_prime(1) == "No" # 1 is not quasi-pri... | [
{
"docstring": "Helper function to check if a number is prime.",
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": "Helper function to count distinct prime factors of a number.",
"function_declaration": "def prime_facto... | [
0,
0,
0,
1,
0
] | 1 | hard | 0.2 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_quasi_prime(n):\n \"\"\"\n Determine if a given number `n` is a quasi-prime. A number is quasi-prime if it has exactly three distinct prime fa... | trial_gpt4o_3 | {
"original_instruction": "### Problem Statement\n\nAlex has recently become interested in exploring number theory, specifically in factoring positive integers. He wants to write a program that determines if a given number is a \"quasi-prime.\" A number is considered quasi-prime if it has exactly three distinct prime... | 0.680858 | Code_Contests_16668 | C | [
"is_prime",
"prime_factors_count",
"is_quasi_prime",
"check_quasi_prime"
] | 4 | [
[
"check_quasi_prime",
"is_quasi_prime"
],
[
"is_quasi_prime",
"prime_factors_count"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 1ec5d54e397a84673c98bf4c556563d5819a4665 | fe1f8964d8e471a5ac14201d8885b4c69432d250 | |||
v1.0 | complete | Code_Contests | Code_Contests_16501_C | def zigzag_traversal(matrix):
"""
Returns the elements of the matrix in zigzag order.
"""
pass
def matrix_zigzag(input_str):
"""
Parse the input string, extract the matrix, and return the zigzag traversal.
>>> matrix_zigzag("3 4\\n1 2 3 4\\n5 6 7 8\\n9 10 11 12")
"1 2 3 4 8 7 6 5 9... | def zigzag_traversal(matrix):
"""
Returns the elements of the matrix in zigzag order.
"""
N = len(matrix)
M = len(matrix[0])
result = []
for i in range(N):
if i % 2 == 0:
result.extend(matrix[i])
else:
result.extend(matrix[i][::-1])
retur... | def test_matrix_zigzag_sample():
input_str = "3 4\n1 2 3 4\n5 6 7 8\n9 10 11 12"
expected_output = "1 2 3 4 8 7 6 5 9 10 11 12"
assert matrix_zigzag(input_str) == expected_output
def test_matrix_zigzag_single_row():
input_str = "1 4\n1 2 3 4"
expected_output = "1 2 3 4"
assert matrix_zigzag(inp... | [
{
"docstring": "Returns the elements of the matrix in zigzag order.",
"function_declaration": "def zigzag_traversal(matrix):",
"function_name": "zigzag_traversal",
"parameter_list": "(matrix)"
},
{
"docstring": "Parse the input string, extract the matrix, and return the zigzag traversal.",
... | [
0,
1
] | 1 | medium | 0.5 | {
"trial_gpt4o_0": null,
"trial_gpt4o_1": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared1_results_combined.jsonl",
"solution_code": "def zigzag_traversal(matrix):\n \"\"\"\n This function returns the elements of the matrix\n in a zigzag traversal order.\... | trial_gpt4o_2 | {
"original_instruction": "MatrixZigzag\n\nProblem Statement\n\nYou are given a matrix M of size N x M, where M_i,j denotes the element at i-th row and j-th column of the matrix.\n\nYou need to create a zigzag traversal of the matrix. Starting from the top-left element, the traversal should move right until the end o... | 0.537352 | Code_Contests_16501 | C | [
"zigzag_traversal",
"matrix_zigzag"
] | 2 | [
[
"matrix_zigzag",
"zigzag_traversal"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | e9b434c57a1fd1fc89ac6d3d1b56dd09a73af10e | 4a5b9bd8ced59c6e7fdd2a58f37b6d1a938ffbe8 | |||
v1.0 | complete | Code_Contests | Code_Contests_16470_C | def is_palindrome(n):
"""
Checks if a number is a palindrome.
"""
pass
def count_palindromes(L, R):
"""
Returns the count of palindrome numbers in the range [L, R].
"""
pass
def process_cases(T, cases):
"""
Processes T test cases and returns results for each.
"""
pass
... | def is_palindrome(n):
"""
Checks if a number is a palindrome.
"""
return str(n) == str(n)[::-1]
def count_palindromes(L, R):
"""
Returns the count of palindrome numbers in the range [L, R].
"""
count = 0
for num in range(L, R + 1):
if is_palindrome(num):
count +=... | from solution import is_palindrome, count_palindromes, process_cases
def test_is_palindrome():
assert is_palindrome(121) == True
assert is_palindrome(123) == False
assert is_palindrome(1331) == True
assert is_palindrome(100) == False
def test_count_palindromes():
assert count_palindromes(1, 10) ==... | [
{
"docstring": "Checks if a number is a palindrome.",
"function_declaration": "def is_palindrome(n):",
"function_name": "is_palindrome",
"parameter_list": "(n)"
},
{
"docstring": "Returns the count of palindrome numbers in the range [L, R].",
"function_declaration": "def count_palindrome... | [
1,
0,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_palindrome(n):\n \"\"\"\n Checks if a number is a palindrome.\n \"\"\"\n return str(n) == str(n)[::-1]\n\ndef count_palindromes(L, R):\n... | trial_gpt4o_0 | {
"original_instruction": "Kapil loves palindromes and he wants to count them in different ranges. For a given range [L, R], help Kapil to find how many numbers in this range are palindromes. A number is a palindrome if it reads the same backward as forward. For example, 121 and 1331 are palindromes, whereas 123 and ... | 0.698765 | Code_Contests_16470 | C | [
"is_palindrome",
"count_palindromes",
"process_cases"
] | 3 | [
[
"count_palindromes",
"is_palindrome"
],
[
"process_cases",
"count_palindromes"
]
] | 2 | [
"process_cases"
] | false | [] | false | pytest | true | [] | true | 0204491720f228e411f43d524558e0a23775fbcd | 178098616a6a590bcf5c3c4b2915b990299586d6 | |||
v1.0 | complete | Code_Contests | Code_Contests_16524_C | def get_cgn_cluster_group(number):
"""
Calculate the cluster group number for a given number.
"""
pass
def distinct_cluster_groups(numbers):
"""
Calculate and return the sorted distinct cluster groups for the given numbers.
"""
pass
def process_test_cases(test_cases):
"""
Proce... | def get_cgn_cluster_group(number):
"""
Calculate the cluster group number for a given number.
"""
while number >= 10:
number = sum(int(digit) for digit in str(number))
cluster_groups = "ABCDEFGHIJ"
return cluster_groups[number]
def distinct_cluster_groups(numbers):
"""
Calc... | from solution import get_cgn_cluster_group, distinct_cluster_groups, process_test_cases
def test_get_cgn_cluster_group():
assert get_cgn_cluster_group(128) == 'C'
assert get_cgn_cluster_group(35) == 'I'
assert get_cgn_cluster_group(467) == 'I'
assert get_cgn_cluster_group(50) == 'F'
def test_distinct_... | [
{
"docstring": "Calculate the cluster group number for a given number.",
"function_declaration": "def get_cgn_cluster_group(number):",
"function_name": "get_cgn_cluster_group",
"parameter_list": "(number)"
},
{
"docstring": "Calculate and return the sorted distinct cluster groups for the giv... | [
0,
0,
0,
0,
1
] | 1 | hard | 0.2 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def digital_root(n):\n while n >= 10:\n n = sum(int(digit) for digit in str(n))\n return n\n\ndef cluster_groups(numbers):\n cluster_map = ... | trial_gpt4o_4 | {
"original_instruction": "Cluster Groups\n\nIn a newly discovered dataset, you are given a list of numbers. To perform data simplification, you will create a \"Cluster Group Number\" (CGN) for each number in the list. The CGN is calculated as follows: \n\n1. Split the number into individual digits.\n2. Calculate the... | 0.590869 | Code_Contests_16524 | C | [
"get_cgn_cluster_group",
"distinct_cluster_groups",
"process_test_cases"
] | 3 | [
[
"distinct_cluster_groups",
"get_cgn_cluster_group"
],
[
"process_test_cases",
"distinct_cluster_groups"
]
] | 2 | [
"process_test_cases"
] | false | [] | false | pytest | true | [] | true | 31a811e493656b20d45f6d66d876ce49b0c2b18c | b977a5ce99b4544ae474509156d545e41c368677 | |||
v1.0 | complete | Code_Contests | Code_Contests_16200_C | import re
def validate_password(password):
"""
Validates the given password based on the specified criteria.
Parameters:
password (str): The password to validate.
Returns:
str: "Valid" if the password meets all the criteria, otherwise "Invalid".
"""
pass
def process_passwords... | import re
def validate_password(password):
"""
Validates the given password based on the specified criteria.
Parameters:
password (str): The password to validate.
Returns:
str: "Valid" if the password meets all the criteria, otherwise "Invalid".
"""
if len(password) < 8:
... | from solution import validate_password, process_passwords
def test_validate_password():
assert validate_password("Passw0rd!") == "Valid"
assert validate_password("WeakPass") == "Invalid"
assert validate_password("Str0ngPass!") == "Valid"
assert validate_password("Sh0rt1!") == "Invalid"
assert valid... | [
{
"docstring": "Validates the given password based on the specified criteria.\n\nParameters:\npassword (str): The password to validate.\n\nReturns:\nstr: \"Valid\" if the password meets all the criteria, otherwise \"Invalid\".",
"function_declaration": "def validate_password(password):",
"function_name"... | [
0,
0,
0,
0,
0,
0,
1,
0,
1,
1
] | 3 | hard | 0.3 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import re\n\ndef validate_password(password):\n \"\"\"\n Validate a password based on the given criteria:\n 1. At least 8 characters long.\n 2.... | trial_gpt4o_9 | {
"original_instruction": "Problem D: Password Validator\n\nAlice, an IT security expert, has been tasked with implementing a password validation module for a new application. The program takes multiple user-input passwords and validates them based on the following criteria:\n\n1. The password must be at least 8 char... | 0.591415 | Code_Contests_16200 | C | [
"validate_password",
"process_passwords"
] | 2 | [
[
"process_passwords",
"validate_password"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 61bd4c02cf821170608cf75b8b6ca0deef0c02d6 | d94a2e0c7aefb4ecad69ba198c8390471b5bb4cd | |||
v1.0 | complete | Code_Contests | Code_Contests_16579_C | def is_within_square(x, y, cx, cy, k):
"""
Checks if point (x, y) lies within or on the border of a square with side length k
centered at (cx, cy).
"""
pass
def track_suspect_positions(n, k, positions, queries):
"""
For each query, determines if any position of the suspect was within or on ... | def is_within_square(x, y, cx, cy, k):
"""
Checks if point (x, y) lies within or on the border of a square with side length k
centered at (cx, cy).
"""
half_side = k / 2
return (cx - half_side <= x <= cx + half_side) and (cy - half_side <= y <= cy + half_side)
def track_suspect_positions(n, k, ... | from solution import track_suspect_positions
def test_case_1():
n = 5
k = 2
q = 3
positions = [(1, 2), (2, 2), (3, 3), (4, 4), (5, 5)]
queries = [(2, 2), (5, 5), (0, 0)]
assert track_suspect_positions(n, k, positions, queries) == ["YES", "YES", "NO"]
def test_case_2():
n = 4
k = 4
... | [
{
"docstring": "Checks if point (x, y) lies within or on the border of a square with side length k\ncentered at (cx, cy).",
"function_declaration": "def is_within_square(x, y, cx, cy, k):",
"function_name": "is_within_square",
"parameter_list": "(x, y, cx, cy, k)"
},
{
"docstring": "For each... | [
0,
1,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_inside_square(x, y, cx, cy, k):\n \"\"\"\n Checks if the point (x, y) is within or on the boundary\n of a square centered at (cx, cy) with ... | trial_gpt4o_2 | {
"original_instruction": "A detective is trying to track the location history of a suspect based on GPS data that shows the suspect's position at different times of the day. The data is provided as a sequence of positions on a 2D plane. However, to make it easier to analyze, the detective needs to know if at any poi... | 0.559987 | Code_Contests_16579 | C | [
"is_within_square",
"track_suspect_positions"
] | 2 | [
[
"track_suspect_positions",
"is_within_square"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | e38a62cd0e317f4dda88768d1064d6f960c381c2 | 93487c3d79bc18a7ba8aa17d3d0aa4771ec31653 | |||
v1.0 | complete | Code_Contests | Code_Contests_16450_C | from typing import List
def check_password(password: str) -> str:
""" Check if a password is secure based on given criteria and provide suggestions if not.
>>> check_password("Password123@")
'Secure'
>>> check_password("Pass1@")
'Not Secure\nAt least 8 characters long\nSuggestion: Add more cha... | def check_password(password):
"""
Checks if a password is secure based on given criteria and provides suggestions if not.
"""
criteria = [
("length", lambda x: len(x) >= 8, "At least 8 characters long"),
("uppercase", lambda x: any(c.isupper() for c in x), "At least one uppercase letter"... | from solution import check_password, check_passwords
def test_secure_password():
assert check_password("Password123@") == "Secure"
def test_short_password():
assert check_password("Pass1@") == "Not Secure\nAt least 8 characters long\nSuggestion: Add more characters."
def test_no_uppercase():
assert check... | [
{
"docstring": "Checks if a password is secure based on given criteria and provides suggestions if not.",
"function_declaration": "def check_password(password):",
"function_name": "check_password",
"parameter_list": "(password)"
},
{
"docstring": "Checks a list of passwords and reports if th... | [
0,
0,
0,
0,
0,
0,
1,
0,
0
] | 1 | hard | 0.111 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def check_password(password):\n errors = []\n\n if len(password) < 8:\n errors.append(\"At least 8 characters long\")\n\n if not any(c.isup... | trial_gpt4o_6 | {
"original_instruction": "Background\n\nYou are tasked with developing a program to authenticate passwords based on specific rules devised by a security firm. They have identified that a secure password must meet certain criteria to be considered strong. Additionally, they need the program to provide suggestions for... | 0.64379 | Code_Contests_16450 | C | [
"check_password",
"check_passwords"
] | 2 | [
[
"check_passwords",
"check_password"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 7f62fd9bf9f5b5598605dc9f119cf87d7a7c5d7e | 03ac833bfbd03ecf5a5ee127979a0bb3512e3659 | |||
v1.0 | complete | Code_Contests | Code_Contests_16531_C | def is_prime(n: int) -> bool:
"""Determine if n is a prime number.
>>> is_prime(1)
False
>>> is_prime(2)
True
>>> is_prime(29)
True
>>> is_prime(30)
False
"""
pass
def kth_prime_greater_than_m(m: int, k: int) -> int:
"""Find the k-th prime number greater than a given nu... | def is_prime(n):
if n <= 1:
return False
if n <= 3:
return True
if n % 2 == 0 or n % 3 == 0:
return False
i = 5
while i * i <= n:
if n % i == 0 or n % (i + 2) == 0:
return False
i += 6
return True
def kth_prime_greater_than_m(m, k):
count ... | from solution import is_prime, kth_prime_greater_than_m, find_kth_primes
def test_is_prime():
assert not is_prime(1)
assert is_prime(2)
assert is_prime(3)
assert not is_prime(4)
assert is_prime(5)
assert is_prime(29)
assert not is_prime(30)
def test_kth_prime_greater_than_m():
assert k... | [
{
"docstring": null,
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": null,
"function_declaration": "def kth_prime_greater_than_m(m, k):",
"function_name": "kth_prime_greater_than_m",
"parameter_list": "(m, k)"
}... | [
1,
1,
0
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(n):\n if n <= 1:\n return False\n if n <= 3:\n return True\n if n % 2 == 0 or n % 3 == 0:\n return False\n i ... | trial_gpt4o_1 | {
"original_instruction": "Olivia is fascinated by prime numbers and recently she encountered a new problem. She needs to find the K-th prime number that is greater than a given number M. Help Olivia find this K-th prime number.\n\nInput:\nThe first line contains a number T, the number of test cases.\nThe next T line... | 0.756849 | Code_Contests_16531 | C | [
"is_prime",
"kth_prime_greater_than_m",
"find_kth_primes"
] | 3 | [
[
"find_kth_primes",
"kth_prime_greater_than_m"
],
[
"kth_prime_greater_than_m",
"is_prime"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 3d97449850430678809e22fa018249f230c95085 | 8b8e720d76a96d6ee5ea7ff62184eac57e475450 | |||
v1.0 | complete | Code_Contests | Code_Contests_16597_C | def longest_common_prefix(words: List[str]) -> str:
""" Find the longest common prefix among a list of words.
If there is no common prefix, return an empty string.
Args:
words (list of str): The list of words to analyze.
Returns:
str: The longest common prefix among the words.
... | def longest_common_prefix(words):
"""
Function to find the longest common prefix among a list of words.
Args:
words (list of str): The list of words to analyze.
Returns:
str: The longest common prefix among the words.
"""
if not words:
return ""
# The longest c... | from solution import longest_common_prefix
def test_longest_common_prefix_example1():
words = ["flower", "flow", "flight"]
assert longest_common_prefix(words) == "fl"
def test_longest_common_prefix_example2():
words = ["dog", "racecar", "car", "cat"]
assert longest_common_prefix(words) == ""
def test... | [
{
"docstring": "Function to find the longest common prefix among a list of words.\n\nArgs:\nwords (list of str): The list of words to analyze.\n\nReturns:\nstr: The longest common prefix among the words.",
"function_declaration": "def longest_common_prefix(words):",
"function_name": "longest_common_pref... | [
1,
0,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def longest_common_prefix(words):\n \"\"\"\n Returns the longest common prefix among all the words in the given list.\n If there is no common pref... | trial_gpt4o_2 | {
"original_instruction": "Given a list of words, you need to find the longest common prefix among all the words in the list. If there is no common prefix, return an empty string.\n\nInput:\n\nThe first line contains an integer n (1 ≤ n ≤ 100), the number of words in the list. Each of the next n lines contains a sing... | 0.817184 | Code_Contests_16597 | C | [
"longest_common_prefix",
"is_common_prefix"
] | 2 | [
[
"longest_common_prefix",
"is_common_prefix"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | d713e74b303a543c3eab808d2092a1260a7aa53f | 9735a16d52aa82919dceda24b2b2355d50651489 | |||
v1.0 | complete | Code_Contests | Code_Contests_16596_C | def main(input_str: str) -> List[int]:
"""
Farmer Bob has a rectangular farm represented as an MxN grid,
where each cell is either planted with a crop or is an empty patch.
Farmer Bob is interested in finding out the largest rectangular
area within his farm that is completely made up of crops.
... | def max_histogram_area(heights):
stack = []
max_area = 0
index = 0
while index < len(heights):
if not stack or heights[stack[-1]] <= heights[index]:
stack.append(index)
index += 1
else:
top_of_stack = stack.pop()
area = (heights[top_of... | import pytest
from solution import main
def test_example_case():
input_data = "4 5\n1 0 1 0 0\n1 0 1 1 1\n1 1 1 1 1\n1 0 0 1 0\n" \
"4 4\n0 1 1 1\n1 1 1 1\n1 0 0 1\n0 1 1 0\n" \
"2 2\n1 1\n1 0\n0 0"
expected_result = [6, 6, 2]
assert main(input_data) == expected_result
de... | [
{
"docstring": null,
"function_declaration": "def max_histogram_area(heights):",
"function_name": "max_histogram_area",
"parameter_list": "(heights)"
},
{
"docstring": null,
"function_declaration": "def max_rectangle_area(matrix):",
"function_name": "max_rectangle_area",
"paramet... | [
0,
1,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def maximalRectangle(matrix):\n if not matrix:\n return 0\n\n max_area = 0\n n = len(matrix[0])\n height = [0] * (n + 1)\n \n for ... | trial_gpt4o_2 | {
"original_instruction": "Farmer Bob has a rectangular farm represented as an MxN grid, where each cell is either planted with a crop or is an empty patch. Farmer Bob is interested in finding out the largest rectangular area within his farm that is completely made up of crops.\n\nYour task is to write a program that... | 0.626009 | Code_Contests_16596 | C | [
"max_histogram_area",
"max_rectangle_area",
"largest_rectangle_of_crops",
"parse_input",
"main"
] | 5 | [
[
"largest_rectangle_of_crops",
"max_rectangle_area"
],
[
"max_rectangle_area",
"max_histogram_area"
]
] | 2 | [
"parse_input"
] | false | [] | false | pytest | true | [] | true | 3d84168f2707196501e4ff1a8d1a42e055d8167f | e45d976297da72fb8f1758a364cf24544a5a3be5 | |||
v1.0 | complete | Code_Contests | Code_Contests_16335_C | def final_drone_position(n: int, movements: List[str]) -> Tuple[int, int, int]:
""" Given a number of commands `n` and a list of `movements`,
return the final coordinates of the drone.
>>> final_drone_position(3, ["up", "north", "east"])
(1, 1, 1)
>>> final_drone_position(4, ["up", "up", "down", "we... | def final_drone_position(n, movements):
"""
Given a number of commands `n` and a list of `movements`,
return the final coordinates of the drone.
"""
x, y, z = 0, 0, 0
for movement in movements:
if movement == "up":
z += 1
elif movement == "down":
z -... | def test_final_drone_position():
# Test case 1
n = 3
movements = ["up", "north", "east"]
assert final_drone_position(n, movements) == (1, 1, 1)
# Test case 2
n = 4
movements = ["up", "up", "down", "west"]
assert final_drone_position(n, movements) == (-1, 0, 1)
def test_process_move... | [
{
"docstring": "Given a number of commands `n` and a list of `movements`, \nreturn the final coordinates of the drone.",
"function_declaration": "def final_drone_position(n, movements):",
"function_name": "final_drone_position",
"parameter_list": "(n, movements)"
},
{
"docstring": "Given a l... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def drone_navigation(movements):\n results = []\n idx = 0\n \n while idx < len(movements):\n n = int(movements[idx])\n if n == 0:... | trial_gpt4o_2 | {
"original_instruction": "You are a software engineer working on optimizing the operations for a delivery drone. The drone operates in a 3D grid space where each position can be described by three coordinates (x, y, z). The drone can execute a sequence of movements to navigate through the grid: \"up\" (increase z), ... | 0.522523 | Code_Contests_16335 | C | [
"final_drone_position",
"process_movements"
] | 2 | [
[
"process_movements",
"final_drone_position"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | b5c3487f384fd1dbe0fc00a475f67a1a83681ca9 | ab8c9bb98202bab64363f701aedf9755a4938853 | |||
v1.0 | complete | Code_Contests | Code_Contests_16776_C | def minimum_spanning_tree(n: int, m: int, edges: List[Tuple[int, int, int]]) -> None:
"""
Compute the minimum spanning tree (MST) of an undirected connected graph with n nodes and m edges,
and determine whether the MST is unique.
>>> minimum_spanning_tree(4, 5, [(1, 2, 1), (2, 3, 2), (3, 4, 1), (4, 1,... | import heapq
def find(parent, i):
if parent[i] == i:
return i
else:
return find(parent, parent[i])
def union(parent, rank, x, y):
rootX = find(parent, x)
rootY = find(parent, y)
if rootX != rootY:
if rank[rootX] > rank[rootY]:
parent[rootY] = rootX
... | def test_example_1():
n = 4
m = 5
edges = [(0, 1, 1), (1, 2, 2), (2, 3, 1), (3, 0, 2), (0, 2, 2)]
minimum_spanning_tree(n, m, edges) # should print 5 and UNIQUE
def test_example_2():
n = 3
m = 3
edges = [(0, 1, 1), (1, 2, 1), (2, 0, 2)]
minimum_spanning_tree(n, m, edges) # should prin... | [
{
"docstring": null,
"function_declaration": "def find(parent, i):",
"function_name": "find",
"parameter_list": "(parent, i)"
},
{
"docstring": null,
"function_declaration": "def union(parent, rank, x, y):",
"function_name": "union",
"parameter_list": "(parent, rank, x, y)"
},
... | [
0,
1
] | 1 | medium | 0.5 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import heapq\nfrom collections import defaultdict\n\ndef find(parent, i):\n if parent[i] == i:\n return i\n else:\n parent[i] = find(pa... | trial_gpt4o_1 | {
"original_instruction": "You are given an undirected connected graph with n nodes and m edges. Each edge has a weight associated with it, which is a positive integer. Your task is to compute the minimum spanning tree (MST) of this graph. Additionally, if the MST is unique, you should output \"UNIQUE\", otherwise ou... | 0.700732 | Code_Contests_16776 | C | [
"find",
"union",
"kruskal",
"minimum_spanning_tree"
] | 4 | [
[
"kruskal",
"find"
],
[
"kruskal",
"union"
],
[
"minimum_spanning_tree",
"kruskal"
],
[
"union",
"find"
]
] | 4 | [] | false | [] | false | pytest | false | [] | true | d320df0f3beb03c924c55bbc394c762a6a17500b | 885684489e0d3806ec74e398161bc0917024ebc9 | |||
v1.0 | complete | Code_Contests | Code_Contests_16444_C | import math
from functools import reduce
from typing import List
def gcd_of_array(arr: List[int]) -> int:
"""
Returns the GCD of all elements in the array.
"""
return reduce(math.gcd, arr)
def max_possible_min_element(n: int, arr: List[int]) -> int:
"""
Given an array of positive integers, ret... | import math
from functools import reduce
def gcd_of_array(arr):
"""
Returns the GCD of all elements in the array.
"""
return reduce(math.gcd, arr)
def max_possible_min_element(n, arr):
"""
Given an array of positive integers, returns the maximum possible value
that the smallest element of... | from solution import max_possible_min_element
def test_example_1():
assert max_possible_min_element(5, [2, 10, 6, 14, 8]) == 2
def test_example_2():
assert max_possible_min_element(4, [3, 9, 15, 27]) == 3
def test_example_3():
assert max_possible_min_element(3, [5, 10, 15]) == 5
def test_example_4():
... | [
{
"docstring": "Returns the GCD of all elements in the array.",
"function_declaration": "def gcd_of_array(arr):",
"function_name": "gcd_of_array",
"parameter_list": "(arr)"
},
{
"docstring": "Given an array of positive integers, returns the maximum possible value \nthat the smallest element ... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from math import gcd\nfrom functools import reduce\n\ndef max_possible_minimal_value(n, arr):\n \"\"\"\n Returns the maximum possible value that the ... | trial_gpt4o_2 | {
"original_instruction": "You are given an array of positive integers arr of length n. You can perform the following operation on the array: \n\n- Pick any two elements arr[i] and arr[j] where \\(1 \\leq i, j \\leq n\\) and \\(i \\neq j\\), replace arr[i] and arr[j] with the greatest common divisor (GCD) of these tw... | 0.654445 | Code_Contests_16444 | C | [
"gcd_of_array",
"max_possible_min_element"
] | 2 | [
[
"max_possible_min_element",
"gcd_of_array"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 39c022cb3a57e079ec6ae8646fe9eb535c28df50 | 6d215db5902c151ce344dc84c0a4d2cdf16dddca | |||
v1.0 | complete | Code_Contests | Code_Contests_15690_C | Write a function `tree_info` that takes an integer `n` and a list `node_info` which contains `n` lists, each representing the information of a node in a rooted n-ary tree. The function should calculate and return the details of each node as per the description provided above. The details should include the node ID, par... | class TreeNode:
def __init__(self, node_id, parent_id=-1):
self.node_id = node_id
self.parent_id = parent_id
self.children = []
self.depth = 0
self.height = 0
def calculate_depth(node, depth):
node.depth = depth
for child in node.children:
calculate_depth(chi... | import pytest
from solution import TreeNode, calculate_depth, calculate_height, classify_nodes, create_tree, tree_info
def test_tree_info_basic():
n = 9
node_info = [
[0, 3, 1, 4, 5],
[1, 2, 2, 3],
[2, 0],
[3, 0],
[4, 0],
[5, 2, 6, 7],
[6, 0],
[7... | [] | [
1,
0,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "class Node:\n def __init__(self, id):\n self.id = id\n self.parent = None\n self.children = []\n\ndef calculate_depth(node, depth=0... | trial_gpt4o_2 | {
"original_instruction": "Write a program to read information about a rooted n-ary tree and print the following details for each node u of the tree:\n\n* node ID of u\n* parent of u\n* number of children of u\n* depth of u\n* height of u\n* node type (root, internal node or leaf)\n\nIn an n-ary tree, each node can h... | 0.51972 | Code_Contests_15690 | C | [
"calculate_depth",
"calculate_height",
"classify_nodes",
"create_tree",
"tree_info"
] | 5 | [
[
"tree_info",
"calculate_depth"
],
[
"tree_info",
"calculate_height"
],
[
"tree_info",
"classify_nodes"
],
[
"tree_info",
"create_tree"
]
] | 4 | [] | false | [
"TreeNode"
] | true | pytest | true | [] | true | 4ee31b1e07f2bfc593a887f978f03bde43bae0d9 | 4742414744967432f536041f7034034aeff84327 | |||
v1.0 | complete | Code_Contests | Code_Contests_16724_C | class TreeNode:
def __init__(self, value):
self.value = value
self.left = None
self.right = None
def insert_into_bst(root, value):
""" Insert a value into the BST and return the root of the BST."""
pass
def bst_height(node):
""" Compute the height of the BST."""
pass
def c... | class TreeNode:
def __init__(self, value):
self.value = value
self.left = None
self.right = None
def insert_into_bst(root, value):
if root is None:
return TreeNode(value)
if value < root.value:
root.left = insert_into_bst(root.left, value)
else:
root.righ... | from solution import compute_bst_heights
def test_single_case():
test_cases = [(5, 10, 5, 15, 3, 7)]
assert compute_bst_heights(test_cases) == [2]
def test_multiple_cases():
test_cases = [
(5, 10, 5, 15, 3, 7),
(6, 3, 2, 8, 5, 1, 7, 4),
(4, 6, 10, 4, 8)
]
assert compute_bst... | [] | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "class TreeNode:\n def __init__(self, key):\n self.left = None\n self.right = None\n self.val = key\n \ndef insert(root, key)... | trial_gpt4o_2 | {
"original_instruction": "Henry loves trees, especially binary trees. He has a collection of integers which he wants to insert into an initially empty binary search tree (BST). After building the tree by inserting all integers from his collection (in the given order), he's interested in computing the height of the t... | 0.554352 | Code_Contests_16724 | C | [
"insert_into_bst",
"bst_height",
"compute_bst_heights"
] | 3 | [
[
"compute_bst_heights",
"bst_height"
],
[
"compute_bst_heights",
"insert_into_bst"
]
] | 2 | [] | false | [
"TreeNode"
] | true | pytest | true | [] | true | 028f43477b4ba05a5f277e71053242bf9edffa37 | 95a35c8c0aafb385a968005f45e54da10e9008ef | |||
v1.0 | complete | Code_Contests | Code_Contests_16811_C | from typing import List, Tuple
def update_element(arr: List[int], x: int, y: int) -> None:
"""
Updates the xth element of the array to y.
"""
pass
def find_kth_smallest(arr: List[int], l: int, r: int, k: int) -> int:
"""
Finds the k-th smallest element in the subarray from index l to r (inclus... | def update_element(arr, x, y):
"""
Updates the xth element of the array to y.
"""
arr[x-1] = y
def find_kth_smallest(arr, l, r, k):
"""
Finds the k-th smallest element in the subarray from index l to r (inclusive).
If there is no k-th smallest element, returns -1.
"""
subarray = arr... | from solution import update_element, find_kth_smallest, process_operations
def test_update_element():
arr = [10, 20, 30, 40, 50]
update_element(arr, 3, 35)
assert arr == [10, 20, 35, 40, 50]
update_element(arr, 1, 100)
assert arr == [100, 20, 35, 40, 50]
def test_find_kth_smallest():
arr = [10... | [
{
"docstring": "Updates the xth element of the array to y.",
"function_declaration": "def update_element(arr, x, y):",
"function_name": "update_element",
"parameter_list": "(arr, x, y)"
},
{
"docstring": "Finds the k-th smallest element in the subarray from index l to r (inclusive).\nIf ther... | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def update_element(array, x, y):\n \"\"\"\n Updates the element at index x of the array to y.\n \"\"\"\n array[x - 1] = y\n\ndef kth_smallest_e... | trial_gpt4o_1 | {
"original_instruction": "Given an array of size N consisting of N distinct integers, write a program to handle the following operations:\n\n1. 0 x y: Update the xth element of the array to y.\n2. 1 l r k: Find the k-th smallest element within the subarray from index l to index r (inclusive). If there is no k-th sma... | 0.666435 | Code_Contests_16811 | C | [
"update_element",
"find_kth_smallest",
"process_operations"
] | 3 | [
[
"process_operations",
"find_kth_smallest"
],
[
"process_operations",
"update_element"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | df5e9c812acd8b2ef2207e4353bef6e8015c8e3a | f2a1c2f5ce430c194e6b7942122fea9d3ae4c2b9 | |||
v1.0 | complete | Code_Contests | Code_Contests_16961_C | def generate_sequence(n):
""" Generate the n-th sequence in Bob's study.
>>> generate_sequence(1) "0"
>>> generate_sequence(2) "01"
>>> generate_sequence(3) "0110"
"""
def find_kth_character(n, k):
""" Find the k-th character in the n-th sequence of binary strings.
>>> find_kth_character(1, ... | def generate_sequence(n):
"""
Generate the n-th sequence in Bob's study.
"""
if n == 1:
return "0"
prev_sequence = generate_sequence(n - 1)
flipped_sequence = ''.join('1' if bit == '0' else '0' for bit in prev_sequence)
return prev_sequence + flipped_sequence
def find_kth_character(... | from solution import generate_sequence, find_kth_character, solve_sequence_queries
def test_generate_sequence():
assert generate_sequence(1) == "0"
assert generate_sequence(2) == "01"
assert generate_sequence(3) == "0110"
assert generate_sequence(4) == "01101001"
def test_find_kth_character():
ass... | [
{
"docstring": "Generate the n-th sequence in Bob's study.",
"function_declaration": "def generate_sequence(n):",
"function_name": "generate_sequence",
"parameter_list": "(n)"
},
{
"docstring": "Find the k-th character in the n-th sequence of binary strings.",
"function_declaration": "de... | [
0,
0,
0,
0,
0,
0,
0,
0,
0,
1
] | 1 | hard | 0.1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def kth_character_in_nth_string(n, k):\n def generate_nth_string(n):\n if n == 1:\n return \"0\"\n prev_string = generate_nth_s... | trial_gpt4o_9 | {
"original_instruction": "Bob is studying a new sequence of binary strings. The sequence starts with a single character '0'. Each subsequent string is generated by flipping each bit of the previous string (changing all '0's to '1's and all '1's to '0's) and then appending this flipped string to the original. Thus, t... | 0.563471 | Code_Contests_16961 | C | [
"generate_sequence",
"find_kth_character",
"solve_sequence_queries"
] | 3 | [
[
"find_kth_character",
"generate_sequence"
],
[
"solve_sequence_queries",
"find_kth_character"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | db6c64e8f7c3b5fd5d6dc9c0e3e88c647c1511eb | d126e42acc77ba423b2f4756baf17a0c023ce012 | |||
v1.0 | complete | Code_Contests | Code_Contests_16809_C | import heapq
import sys
from collections import defaultdict
from typing import List, Tuple
def dijkstra(N: int, M: int, S: int, edges: List[Tuple[int, int, int]]) -> List[int]:
""" Finds the shortest paths in a directed weighted graph from a given start node.
Parameters:
N (int): The number of nodes.
... | import heapq
import sys
from collections import defaultdict
def dijkstra(N, M, S, edges):
graph = defaultdict(list)
for u, v, w in edges:
graph[u].append((w, v))
inf = sys.maxsize
distances = [inf] * (N + 1)
distances[S] = 0
priority_queue = [(0, S)]
while priority_queue:
... | from solution import shortest_paths
def test_shortest_paths_example1():
N = 6
M = 9
S = 1
edges = [
(1, 2, 7),
(1, 3, 9),
(1, 6, 14),
(2, 3, 10),
(2, 4, 15),
(3, 4, 11),
(3, 6, 2),
(6, 5, 9),
(4, 5, 6)
]
result = short... | [
{
"docstring": null,
"function_declaration": "def dijkstra(N, M, S, edges):",
"function_name": "dijkstra",
"parameter_list": "(N, M, S, edges)"
},
{
"docstring": null,
"function_declaration": "def shortest_paths(N, M, S, edges):",
"function_name": "shortest_paths",
"parameter_lis... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import heapq\n\ndef dijkstra(N, M, S, edges):\n # Convert to 0-based index\n S -= 1\n graph = [[] for _ in range(N)]\n for u, v, w in edges:\n ... | trial_gpt4o_2 | {
"original_instruction": "Ina, a high school student, is participating in a school coding competition. To prepare, she needs to practice solving problems by computing the shortest paths in weighted graphs.\n\nIna is given a directed weighted graph with $ N $ nodes and $ M $ directed edges. Each edge has a certain we... | 0.678112 | Code_Contests_16809 | C | [
"dijkstra",
"shortest_paths"
] | 2 | [
[
"shortest_paths",
"dijkstra"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 19439d1707f23afc91e8036b3a0ca16c94e634e1 | c4a575badd5b23d98c5a3378a9b11ad22ff7feab | |||
v1.0 | complete | Code_Contests | Code_Contests_16791_C | def growth_pattern_score(n):
"""
Calculates the growth pattern score of a number.
"""
while n >= 10:
product = 1
while n > 0:
product *= n % 10
n //= 10
n = product
return n
def sum_growth_pattern_scores(A, B):
"""
Calculates the sum of growth... | def growth_pattern_score(n):
"""
Calculates the growth pattern score of a number.
"""
while n >= 10:
product = 1
while n > 0:
product *= n % 10
n //= 10
n = product
return n
def sum_growth_pattern_scores(A, B):
"""
Calculates the sum of growth... | from solution import growth_pattern_score, sum_growth_pattern_scores, process_test_cases
def test_growth_pattern_score():
assert growth_pattern_score(345) == 0
assert growth_pattern_score(10) == 0
assert growth_pattern_score(49) == 8
assert growth_pattern_score(81) == 8
assert growth_pattern_score(... | [
{
"docstring": "Calculates the growth pattern score of a number.",
"function_declaration": "def growth_pattern_score(n):",
"function_name": "growth_pattern_score",
"parameter_list": "(n)"
},
{
"docstring": "Calculates the sum of growth pattern scores for corrected growth index numbers [A, B]... | [
0,
0,
0,
0,
0,
0,
0,
1,
0,
0
] | 1 | hard | 0.1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def get_growth_pattern_score(num):\n while num > 9:\n product = 1\n while num > 0:\n product *= num % 10\n num //= 1... | trial_gpt4o_7 | {
"original_instruction": "A group of science students is conducting an experiment on a rare and unique type of plant. Each plant is characterized by its unique growth index number (an integer). The students are interested in observing how the plants grow over several days. For each plant, they compute a \"growth pat... | 0.512209 | Code_Contests_16791 | C | [
"growth_pattern_score",
"sum_growth_pattern_scores",
"process_test_cases"
] | 3 | [
[
"process_test_cases",
"sum_growth_pattern_scores"
],
[
"sum_growth_pattern_scores",
"growth_pattern_score"
]
] | 2 | [
"process_test_cases"
] | false | [] | false | pytest | true | [] | true | 886bedbb7290197233df85d34014574ce2dbbc2d | 50d01f5b9f20561a96a017e96af17f344076ab0c | |||
v1.0 | complete | Code_Contests | Code_Contests_16242_C | def find_smallest_period(sequence):
"""
Determine the smallest period of the sequence if it is periodic.
If the sequence is not periodic, return -1.
:param sequence: List of integers representing daily temperatures
:return: Integer representing the smallest period or -1 if not periodic
"""
... | def find_smallest_period(sequence):
"""
Determine the smallest period of the sequence if it is periodic.
If the sequence is not periodic, return -1.
:param sequence: List of integers representing daily temperatures
:return: Integer representing the smallest period or -1 if not periodic
"""
... | from solution import smallest_periods
def test_periodic_pattern():
n = 3
sequences = [
[1, 2, 3, 1, 2, 3, 1, 2, 3], # Period of 3
[5, 5, 5, 5, 5, 5, 5], # Period of 1
[1, 2, 3, 4, 5, 6, 7] # Not periodic
]
expected_output = [3, 1, -1]
assert smallest_periods(... | [
{
"docstring": "Determine the smallest period of the sequence if it is periodic.\nIf the sequence is not periodic, return -1.\n\n:param sequence: List of integers representing daily temperatures\n:return: Integer representing the smallest period or -1 if not periodic",
"function_declaration": "def find_smal... | [
1,
0,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def find_period(sequence):\n \"\"\"\n Determine the smallest period of the given sequence of daily temperatures.\n If no period exists, return -1.... | trial_gpt4o_2 | {
"original_instruction": "**Task:** Implement a function that determines whether the sequences of daily temperatures for different cities are periodically repeating. Given a number of cities and for each city the sequence of daily temperatures, determine if the sequence follows a periodic pattern and, if so, return ... | 0.557902 | Code_Contests_16242 | C | [
"find_smallest_period",
"smallest_periods"
] | 2 | [
[
"smallest_periods",
"find_smallest_period"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | b57348c9b8b066284ad98f97bc95170a7fea1570 | 1dd527d8ac473c39803913e3f19f8cc3c370f5ef | |||
v1.0 | complete | Code_Contests | Code_Contests_16720_C | def prefix_sums(array):
"""
Returns the prefix sums of the input array.
>>> prefix_sums([10, 20, 30, 40, 50])
[0, 10, 30, 60, 100, 150]
>>> prefix_sums([1, 2, 3, 4, 5, 6, 7, 8, 9, 10])
[0, 1, 3, 6, 10, 15, 21, 28, 36, 45, 55]
"""
def range_sum(prefix, l, r):
"""
Returns the sum ... | def prefix_sums(array):
"""
Returns the prefix sums of the input array.
"""
n = len(array)
prefix = [0] * (n + 1)
for i in range(1, n + 1):
prefix[i] = prefix[i - 1] + array[i - 1]
return prefix
def range_sum(prefix, l, r):
"""
Returns the sum of the elements from index l to... | from solution import prefix_sums, range_sum, process_queries
def test_prefix_sums():
assert prefix_sums([10, 20, 30, 40, 50]) == [0, 10, 30, 60, 100, 150]
assert prefix_sums([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == [0, 1, 3, 6, 10, 15, 21, 28, 36, 45, 55]
def test_range_sum():
prefix = prefix_sums([10, 20, 30,... | [
{
"docstring": "Returns the prefix sums of the input array.",
"function_declaration": "def prefix_sums(array):",
"function_name": "prefix_sums",
"parameter_list": "(array)"
},
{
"docstring": "Returns the sum of the elements from index l to r in the array using the prefix sums.",
"functio... | [
1,
1,
0
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def array_query_sums(n, m, array, queries):\n \"\"\"\n Given an array and a set of queries, returns the sums of elements from index l to r for each q... | trial_gpt4o_1 | {
"original_instruction": "You are given an array of n integers and a series of m queries. Each query consists of two integers l and r, and you need to output the sum of the elements from index l to r in the array.\n\nInput\n\nThe first line contains two integers n and m (1 ≤ n, m ≤ 100000) — the number of elements i... | 0.608546 | Code_Contests_16720 | C | [
"prefix_sums",
"range_sum",
"process_queries"
] | 3 | [
[
"process_queries",
"prefix_sums"
],
[
"process_queries",
"range_sum"
]
] | 2 | [
"process_queries"
] | false | [] | false | pytest | true | [] | true | 081bb6b9ed11e9a36ff1269db83ef16628c98717 | e7ef5975aedf00d5334c990cf92eb987b0b1f7f7 | |||
v1.0 | complete | Code_Contests | Code_Contests_16938_C | from typing import List, Tuple
def is_prime(n: int) -> bool:
""" Check if a given number is prime.
>>> is_prime(2)
True
>>> is_prime(3)
True
>>> is_prime(4)
False
>>> is_prime(17)
True
>>> is_prime(20)
False
>>> is_prime(23)
True
>>> is_prime(25)
False
""... | def is_prime(n):
if n <= 1:
return False
if n <= 3:
return True
if n % 2 == 0 or n % 3 == 0:
return False
i = 5
while i * i <= n:
if n % i == 0 or n % (i + 2) == 0:
return False
i += 6
return True
def sum_of_digits(n):
return sum(int(digit... | from solution import is_prime, sum_of_digits, find_max_digit_sum_prime, solve_intervals
def test_is_prime():
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(4) == False
assert is_prime(17) == True
assert is_prime(20) == False
assert is_prime(23) == True
assert is_prime... | [
{
"docstring": null,
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": null,
"function_declaration": "def sum_of_digits(n):",
"function_name": "sum_of_digits",
"parameter_list": "(n)"
},
{
"docstring": null,... | [
1,
1,
0
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(n):\n if n <= 1:\n return False\n if n <= 3:\n return True\n if n % 2 == 0 or n % 3 == 0:\n return False\n i ... | trial_gpt4o_0 | {
"original_instruction": "Mohan loves prime numbers and has recently learned about prime number intervals. To impress his friend Sohan, he wants to create an interesting puzzle using prime number intervals.\n\nA prime number interval from L to R (inclusive) is a sequence of integers {L, L+1, ..., R}, and we only con... | 0.673747 | Code_Contests_16938 | C | [
"is_prime",
"sum_of_digits",
"find_max_digit_sum_prime",
"solve_intervals",
"main"
] | 5 | [
[
"find_max_digit_sum_prime",
"is_prime"
],
[
"find_max_digit_sum_prime",
"sum_of_digits"
],
[
"solve_intervals",
"find_max_digit_sum_prime"
]
] | 3 | [] | false | [] | false | pytest | true | [] | true | a707db2311ff0366edb8edf14256ace0168b5971 | ed82e5424b6f2bfe64755d16145e95c77a7c1f37 | |||
v1.0 | complete | Code_Contests | Code_Contests_16874_C | import math
from typing import List
def is_perfect_square(x: int) -> bool:
if x < 0:
return False
s = int(math.sqrt(x))
return s * s == x
def contiguous_subarray_has_perfect_square_sum(arr: List[int]) -> str:
"""
Determines if there exists a contiguous subarray whose sum is a perfect squa... | import math
def is_perfect_square(x):
if x < 0:
return False
s = int(math.sqrt(x))
return s * s == x
def contiguous_subarray_has_perfect_square_sum(arr):
n = len(arr)
for start in range(n):
curr_sum = 0
for end in range(start, n):
curr_sum += arr[end]
... | from solution import contiguous_subarray_has_perfect_square_sum
def test_example_case_1():
array = [1, 2, 3, 4, 5]
assert contiguous_subarray_has_perfect_square_sum(array) == "YES"
def test_example_case_2():
array = [-1, -2, -3]
assert contiguous_subarray_has_perfect_square_sum(array) == "NO"
def tes... | [
{
"docstring": null,
"function_declaration": "def is_perfect_square(x):",
"function_name": "is_perfect_square",
"parameter_list": "(x)"
},
{
"docstring": null,
"function_declaration": "def contiguous_subarray_has_perfect_square_sum(arr):",
"function_name": "contiguous_subarray_has_pe... | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import math\n\ndef is_perfect_square(num):\n if num < 0:\n return False\n root = int(math.isqrt(num))\n return root * root == num\n\ndef ex... | trial_gpt4o_1 | {
"original_instruction": "You are given an array of integers. Your task is to determine if there exists a contiguous subarray whose sum is a perfect square. If such a subarray exists, output \"YES\", otherwise output \"NO\".\n\nInput\n\nThe first line contains an integer n (1 ≤ n ≤ 100) — the number of elements in t... | 0.651617 | Code_Contests_16874 | C | [
"is_perfect_square",
"contiguous_subarray_has_perfect_square_sum"
] | 2 | [
[
"contiguous_subarray_has_perfect_square_sum",
"is_perfect_square"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 4d9c067a95063bde2fc7576056157021d0899e03 | 04a6104fc6f25083f57fd2d84521c50cb2a8fc4c | |||
v1.0 | complete | Code_Contests | Code_Contests_17134_C | def number_of_distinct_paths(n: int, m: int, grid: List[List[str]]) -> int:
""" Determine the number of distinct paths from the top-left cell to the bottom-right cell in a grid.
Args:
n (int): number of rows in the grid.
m (int): number of columns in the grid.
grid (List[List[str]]): the grid itsel... | def count_paths(grid):
n = len(grid)
m = len(grid[0])
# If the start or end point is an obstacle, return 0 as no path is possible
if grid[0][0] == '#' or grid[n-1][m-1] == '#':
return 0
# Initialize DP table
dp = [[0] * m for _ in range(n)]
# Starting point
dp[0][0... | from solution import number_of_distinct_paths
def test_paths_simple():
grid = [
['.', '.', '.'],
['.', '#', '.'],
['.', '.', '.']
]
assert number_of_distinct_paths(3, 3, grid) == 2
def test_paths_no_path():
grid = [
['.', '#', '.'],
['#', '.', '#'],
['.'... | [
{
"docstring": null,
"function_declaration": "def count_paths(grid):",
"function_name": "count_paths",
"parameter_list": "(grid)"
},
{
"docstring": null,
"function_declaration": "def number_of_distinct_paths(n, m, grid):",
"function_name": "number_of_distinct_paths",
"parameter_l... | [
1,
0,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def count_paths(grid):\n n = len(grid)\n m = len(grid[0])\n \n # If the start or end point is an obstacle, return 0 as no path is possible\n ... | trial_gpt4o_0 | {
"original_instruction": "You are given a grid with n rows and m columns, where each cell of the grid is either empty, represented by '.', or contains an obstacle, represented by '#'. You can move from one cell to another in the grid if they share an edge and the destination cell is empty. However, you can only move... | 0.672388 | Code_Contests_17134 | C | [
"count_paths",
"number_of_distinct_paths"
] | 2 | [
[
"number_of_distinct_paths",
"count_paths"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | ba1cf8728be10d61d555a55cd9180f23421ee48b | 24eef8f23575078d07cf41d5d8aee9a43c62daa7 | |||
v1.0 | complete | Code_Contests | Code_Contests_16960_C | def analyze_documents(inputs):
"""
Parses the input and processes the document to count word occurrences.
Args:
inputs: A list of strings where the first element specifies the number of documents,
followed by the lines of each document and the last element is the word to count.
Returns... | def count_word_occurrences(docs, word_to_count):
"""
Counts occurrences of a specific word in each document.
Args:
docs: List of documents where each document is represented as list of lines.
word_to_count: The word to count in the documents.
Returns:
A list containing the count of... | from solution import analyze_documents
def test_analyze_documents_case_sensitive():
inputs = [
"2",
"4",
"Hello world",
"The world is beautiful",
"Hello again",
"world",
"3",
"This is a test",
"Test the code",
"test your skills... | [
{
"docstring": "Counts occurrences of a specific word in each document.\n\nArgs:\ndocs: List of documents where each document is represented as list of lines.\nword_to_count: The word to count in the documents.\n\nReturns:\nA list containing the count of occurrences for each document.",
"function_declaratio... | [
0,
1
] | 1 | medium | 0.5 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def count_word_occurrences(documents, word):\n \"\"\"\n Counts the number of occurrences of the specified word in each document.\n\n :param docume... | trial_gpt4o_1 | {
"original_instruction": "Analyze the number of occurrences of a specific word in multiple text documents.\n\nYou are given multiple documents, each containing a series of lines of text. You need to analyze these documents to find out how many times a specific word appears in each document. The word match should be ... | 0.637918 | Code_Contests_16960 | C | [
"count_word_occurrences",
"analyze_documents"
] | 2 | [
[
"analyze_documents",
"count_word_occurrences"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 2979b24327e3eec18328095db7acf0f26a01fe9c | eb790e16e0d755c5128c411cd7e7d82c3606b6c4 | |||
v1.0 | complete | Code_Contests | Code_Contests_17410_C | def evaluate_expression(expression: str) -> float:
"""Evaluates a given arithmetic expression string and returns the result as a floating-point number.
Handles +, -, *, / operators and parentheses.
>>> evaluate_expression("3 + 5") 8.0
>>> evaluate_expression("10 - 2 * 5") 0.0
>>> evaluate_expression... | def evaluate_expression(expression):
"""
Evaluates a given arithmetic expression string and returns the result as a floating-point number.
Handles +, -, *, / operators and parentheses.
"""
try:
result = eval(expression)
return float(result)
except Exception as e:
raise Va... | import pytest
from solution import evaluate_expression, evaluate_expressions
def test_evaluate_expression_simple_addition():
assert evaluate_expression("3 + 5") == 8.0
def test_evaluate_expression_subtraction_and_multiplication():
assert evaluate_expression("10 - 2 * 5") == 0.0
def test_evaluate_expression_d... | [
{
"docstring": "Evaluates a given arithmetic expression string and returns the result as a floating-point number.\nHandles +, -, *, / operators and parentheses.",
"function_declaration": "def evaluate_expression(expression):",
"function_name": "evaluate_expression",
"parameter_list": "(expression)"
... | [
1,
0,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def evaluate_expression(expression):\n \"\"\"\n Evaluates a given arithmetic expression string and returns the result as a floating-point number.\n ... | trial_gpt4o_0 | {
"original_instruction": "You are given a string that contains a series of arithmetic operations involving addition, subtraction, multiplication, and division. The string can also contain parentheses to specify the order of operations. Your task is to evaluate the string and return the result as a floating-point num... | 0.651062 | Code_Contests_17410 | C | [
"evaluate_expression",
"evaluate_expressions"
] | 2 | [
[
"evaluate_expressions",
"evaluate_expression"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | cbab34699bc628be3b3e7ae67937bda7bb9a5b03 | 7bb8ba47d062c9927a0a526604a48ee4ad197a97 | |||
v1.0 | complete | Code_Contests | Code_Contests_16810_C | def smallest_missing_positive_integer(test_cases):
""" Determine the smallest positive integer not present in the sequence of runes. """
results = []
for n, runes in test_cases:
num_set = set(runes)
smallest_missing = 1
while smallest_missing in num_set:
sma... | def smallest_missing_positive_integer(test_cases):
results = []
for n, runes in test_cases:
num_set = set(runes)
smallest_missing = 1
while smallest_missing in num_set:
smallest_missing += 1
results.append(smallest_missing)
return resul... | from solution import alien_runes
def test_case_1():
input_str = "3\n3\n1 2 0\n5\n3 4 -1 1 0\n4\n7 8 9 11"
expected_output = "3\n2\n1"
assert alien_runes(input_str) == expected_output
def test_case_2():
input_str = "1\n6\n2 3 7 6 8 -10"
expected_output = "1"
assert alien_runes(input_str) == exp... | [
{
"docstring": null,
"function_declaration": "def smallest_missing_positive_integer(test_cases):",
"function_name": "smallest_missing_positive_integer",
"parameter_list": "(test_cases)"
},
{
"docstring": null,
"function_declaration": "def parse_input(input_str):",
"function_name": "p... | [
1,
0,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def smallest_missing_positive_integer(T, test_cases):\n results = []\n for n, runes in test_cases:\n # Remove all non-positive numbers from th... | trial_gpt4o_2 | {
"original_instruction": "Anna and Zoe are on a mission to explore alien artifacts. They've stumbled upon a series of ancient alien runes, and each rune is associated with a unique numerical value. Anna and Zoe's goal is to understand the pattern of these runes.\n\nThe runes are arranged in a sequence, and they want... | 0.566221 | Code_Contests_16810 | C | [
"smallest_missing_positive_integer",
"parse_input",
"format_output",
"alien_runes"
] | 4 | [
[
"alien_runes",
"format_output"
],
[
"alien_runes",
"parse_input"
],
[
"alien_runes",
"smallest_missing_positive_integer"
]
] | 3 | [
"parse_input",
"format_output"
] | false | [] | false | pytest | true | [] | true | ce12e194214c07990c682812e171afc17185fad3 | fbb1d8b9cee2aea86d8132b6cf09e8534250956c | |||
v1.0 | complete | Code_Contests | Code_Contests_17252_C | def minimum_paving_cost(num_cases: int, cases: List[Tuple[int, int, List[Tuple[int, int, int]]]]) -> List[int]:
""" Determine the minimum total time to pave roads to keep the kingdom connected.
>>> minimum_paving_cost(2, [(4, 5, [(1, 2, 1), (2, 3, 2), (3, 4, 3), (4, 1, 4), (1, 3, 10)]), (3, 3, [(1, 2, 1), (2, 3... | def find(parent, i):
if parent[i] == i:
return i
else:
parent[i] = find(parent, parent[i])
return parent[i]
def union(parent, rank, x, y):
root_x = find(parent, x)
root_y = find(parent, y)
if root_x != root_y:
if rank[root_x] > rank[root_y]:
parent[r... | from solution import minimum_paving_cost
def test_minimum_paving_cost():
cases = [
(4, 5, [(1, 2, 1), (2, 3, 2), (3, 4, 3), (4, 1, 4), (1, 3, 10)]),
(3, 3, [(1, 2, 1), (2, 3, 3), (1, 3, 2)])
]
assert minimum_paving_cost(2, cases) == [6, 3]
def test_single_case():
cases = [
(2, ... | [
{
"docstring": null,
"function_declaration": "def find(parent, i):",
"function_name": "find",
"parameter_list": "(parent, i)"
},
{
"docstring": null,
"function_declaration": "def union(parent, rank, x, y):",
"function_name": "union",
"parameter_list": "(parent, rank, x, y)"
},
... | [
0,
0,
0,
0,
0,
1,
0,
0,
0,
0
] | 1 | hard | 0.1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def find(parent, i):\n if parent[i] == i:\n return i\n else:\n parent[i] = find(parent, parent[i]) # path compression\n return p... | trial_gpt4o_5 | {
"original_instruction": "In a certain kingdom, there are several towns connected by bidirectional roads. Each road has a specific time taken to travel between towns. The Kingdom's ruler wants to enhance the infrastructure by paving some of the roads while minimizing the cost. However, some roads must remain unpaved... | 0.662937 | Code_Contests_17252 | C | [
"find",
"union",
"minimum_paving_cost"
] | 3 | [
[
"minimum_paving_cost",
"find"
],
[
"minimum_paving_cost",
"union"
],
[
"union",
"find"
]
] | 3 | [] | false | [] | false | pytest | true | [] | true | 5bfe950fb3123d7a1ea7385167186b63b775ab61 | 9392c4d036ce1bf68a3f1d47cc9bc7765c0566dd | |||
v1.0 | complete | Code_Contests | Code_Contests_17271_C | def min_operations_to_equalize(grid: List[List[int]]) -> int:
""" Calculate the minimum number of operations needed to make all cells in the grid equal.
>>> min_operations_to_equalize([[1, 2, 3], [4, 5, 6]])
5
>>> min_operations_to_equalize([[2, 2, 2, 2]])
0
>>> min_operations_to_equalize([[1, 1... | def min_operations_to_equalize(grid):
n = len(grid)
m = len(grid[0])
max_val = max(max(row) for row in grid)
min_val = min(min(row) for row in grid)
operations = max_val - min_val
return operations
def get_grid_and_solve(n, m, values):
grid = []
for i in range(n):
grid.appe... | from solution import get_grid_and_solve
def test_example1():
assert get_grid_and_solve(2, 3, [1, 2, 3, 4, 5, 6]) == 5
def test_example2():
assert get_grid_and_solve(1, 4, [2, 2, 2, 2]) == 0
def test_example3():
assert get_grid_and_solve(3, 3, [1, 1, 1, 2, 2, 2, 4, 4, 4]) == 3
def test_single_cell():
... | [
{
"docstring": null,
"function_declaration": "def min_operations_to_equalize(grid):",
"function_name": "min_operations_to_equalize",
"parameter_list": "(grid)"
},
{
"docstring": null,
"function_declaration": "def get_grid_and_solve(n, m, values):",
"function_name": "get_grid_and_solv... | [
0,
0,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def min_operations_to_equal_cells(n, m, grid):\n \"\"\"\n Returns the minimum number of operations needed to make all cells in the grid equal.\n \... | trial_gpt4o_2 | {
"original_instruction": "You are given a grid with n rows and m columns, where each cell contains a non-negative integer. You are allowed to perform the following operation any number of times: choose a rectangular subgrid and increase every element in that subgrid by 1.\n\nYour task is to make all cells in the gri... | 0.612845 | Code_Contests_17271 | C | [
"min_operations_to_equalize",
"get_grid_and_solve"
] | 2 | [
[
"get_grid_and_solve",
"min_operations_to_equalize"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | e2a7856d67347d990594b4d065626270b758a8f8 | 6ef119495037ab9c45acec4576ad9707f32b7728 | |||
v1.0 | complete | Code_Contests | Code_Contests_17624_C | from typing import List, Tuple
def possible_binary_assignment(n: int, m: int, edges: List[Tuple[int, int]]) -> str:
""" Determine whether it is possible to assign binary values (0 or 1) to the nodes of an undirected graph
such that the difference between the number of edges connecting nodes with the same value... | from collections import deque
def is_bipartite(n, edges):
graph = [[] for _ in range(n + 1)]
# Build the adjacency list
for u, v in edges:
graph[u].append(v)
graph[v].append(u)
# Array to store the color of each node, 0 or 1
color = [-1] * (n + 1)
def bfs(start):
... | def test_bipartite_graph():
assert possible_binary_assignment(5, 4, [(1, 2), (2, 3), (3, 4), (4, 5)]) == "YES"
def test_non_bipartite_graph():
assert possible_binary_assignment(3, 3, [(1, 2), (2, 3), (3, 1)]) == "NO"
def test_single_node_no_edges():
assert possible_binary_assignment(1, 0, []) == "YES"
de... | [
{
"docstring": null,
"function_declaration": "def is_bipartite(n, edges):",
"function_name": "is_bipartite",
"parameter_list": "(n, edges)"
},
{
"docstring": null,
"function_declaration": "def possible_binary_assignment(n, m, edges):",
"function_name": "possible_binary_assignment",
... | [
1,
0,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from collections import deque\n\ndef is_bipartite(n, edges):\n graph = [[] for _ in range(n + 1)]\n \n # Build the adjacency list\n for u, v in... | trial_gpt4o_0 | {
"original_instruction": "You are given an undirected graph with `n` nodes and `m` edges. Each node has a unique integer identifier between `1` and `n`.\n\nYou are required to determine whether it is possible to assign a binary value (0 or 1) to each node such that the difference between the number of edges connecti... | 0.622662 | Code_Contests_17624 | C | [
"is_bipartite",
"possible_binary_assignment"
] | 2 | [
[
"possible_binary_assignment",
"is_bipartite"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | 429057e934be0db84ef9c57057b2171c8db3bb24 | e6c1334f4400de9d3eb111dfd176f8988f267e94 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.