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_44593_C
from typing import List, Tuple def min_cost(n: int, edges: List[Tuple[int, int, int]], s: int, t: int) -> int: """ Finds the minimum cost to send a message from creature s to creature t through the forest. :param n: Number of creatures and trees :param edges: List of edges in the form (u, v, w) w...
import heapq from collections import defaultdict def dijkstra(n, edges, s, t): """ Finds the minimum cost to send a message from node s to node t using Dijkstra's algorithm. :param n: Number of nodes :param edges: List of edges in the form (u, v, w) :param s: Starting node :param t: Target...
from solution import min_cost def test_case_1(): n = 5 edges = [(1, 2, 3), (1, 3, 4), (3, 4, 5), (2, 5, 6)] s, t = 1, 5 assert min_cost(n, edges, s, t) == 9 def test_case_2(): n = 3 edges = [(1, 2, 2), (2, 3, 4)] s, t = 1, 3 assert min_cost(n, edges, s, t) == 6 def test_case_3(): ...
[ { "docstring": "Finds the minimum cost to send a message from node s to node t using Dijkstra's algorithm.\n\n:param n: Number of nodes\n:param edges: List of edges in the form (u, v, w)\n:param s: Starting node\n:param t: Target node\n:return: Minimum cost to send the message from s to t", "function_declar...
[ 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\nfrom collections import defaultdict\n\ndef dijkstra(n, edges, s, t):\n \"\"\"\n Finds the minimum cost to send a message from node s to...
trial_gpt4o_0
{ "original_instruction": "In an enchanted forest, there are n magical creatures, each residing in its own unique tree. The trees are connected by n-1 gracious vines such that the entire forest forms a tree structure (connected and acyclic). The creatures communicate through these vines, and each vine has a magical s...
0.633402
Code_Contests_44593
C
[ "dijkstra", "min_cost" ]
2
[ [ "min_cost", "dijkstra" ] ]
1
[]
false
[]
false
pytest
true
[]
true
ad1b224a11171e05bc522c8d0a98e2717e34328a
a99e49b9c73d5712eb1655c79a62d9510aadf358
v1.0
complete
Code_Contests
Code_Contests_45117_C
from functools import cmp_to_key from typing import List def max_number_from_list(numbers: List[int]) -> str: """ You are provided with a list of integers. Your task is to rearrange the integers so that they form the maximum possible integer. The output should be the largest integer that can be forme...
from functools import cmp_to_key def compare(x, y): # Custom comparator that decides the order based on concatenated result if x + y > y + x: return -1 elif x + y < y + x: return 1 else: return 0 def max_number_from_list(numbers): # Convert all numbers to strings since we'l...
from solution import max_number_from_list def test_all_single_digits(): assert max_number_from_list([1, 2, 3, 4, 5]) == "54321" def test_different_length_numbers(): assert max_number_from_list([54, 546, 548]) == "54854654" def test_adjacent_different_ordering(): assert max_number_from_list([98, 9, 97]) =...
[ { "docstring": null, "function_declaration": "def compare(x, y):", "function_name": "compare", "parameter_list": "(x, y)" }, { "docstring": null, "function_declaration": "def max_number_from_list(numbers):", "function_name": "max_number_from_list", "parameter_list": "(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": "from functools import cmp_to_key\n\ndef compare(x, y):\n # Custom comparator that decides the order based on concatenated result\n if x + y > y + x:\...
trial_gpt4o_0
{ "original_instruction": "You are provided with a list of integers. Your task is to rearrange the integers so that they form the maximum possible integer.\n\nThe output should be the largest integer that can be formed by concatenating the list of integers.\n\nInput\n- The first line contains an integer n (1 ≤ n ≤ 10...
0.68011
Code_Contests_45117
C
[ "compare", "max_number_from_list", "main" ]
3
[ [ "max_number_from_list", "compare" ] ]
1
[]
false
[]
false
pytest
true
[]
true
796ebd3826cc61529f244664c1099c270aec35de
7dc3058dcc84115281c63eb145c1aa594884ad0b
v1.0
complete
Code_Contests
Code_Contests_45141_C
from typing import List def largest_concatenated_number(nums: List[int]) -> str: """ Given a list of integers, rearrange the integers to form the largest possible concatenated number. Args: nums (List[int]): A list of non-negative integers. Returns: str: The largest concatenated n...
from typing import List from functools import cmp_to_key def compare(x, y): if x + y > y + x: return -1 elif x + y < y + x: return 1 else: return 0 def largest_concatenated_number(nums: List[int]) -> str: if not nums: return "" # Convert numbers to strings ...
from solution import largest_concatenated_number def test_example_case_1(): assert largest_concatenated_number([10, 2]) == "210" def test_example_case_2(): assert largest_concatenated_number([3, 30, 34, 5, 9]) == "9534330" def test_all_zeros(): assert largest_concatenated_number([0, 0, 0]) == "0" def te...
[ { "docstring": null, "function_declaration": "def compare(x, y):", "function_name": "compare", "parameter_list": "(x, y)" }, { "docstring": null, "function_declaration": "def largest_concatenated_number(nums):", "function_name": "largest_concatenated_number", "parameter_list": "(...
[ 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 typing import List\nfrom functools import cmp_to_key\n\ndef compare(x, y):\n if x + y > y + x:\n return -1\n elif x + y < y + x:\n ...
trial_gpt4o_0
{ "original_instruction": "Given a list of integers, rearrange the integers to form the largest possible concatenated number. \n\nYou should implement this function:\n```python\ndef largest_concatenated_number(nums: List[int]) -> str:\n```\n\n### Input:\n- An array of integers `nums` (1 ≤ len(nums) ≤ 10^5, 0 ≤ nums[i...
0.608276
Code_Contests_45141
C
[ "compare", "largest_concatenated_number" ]
2
[ [ "largest_concatenated_number", "compare" ] ]
1
[]
false
[]
false
pytest
true
[]
true
b06c4a4facfe9f17dda4314253d1f3448f6fc20f
6fd1eda3ece7630833fae692adc94043233d3be2
v1.0
complete
Code_Contests
Code_Contests_45242_C
def matrix_chain_order(p: List[int]) -> int: """ Given a sequence of matrices, find the minimum number of scalar multiplications required to multiply them. Parameters: p (List[int]): A list where the i-th element represents the dimension p[i] of the i-th matrix. Returns: int: The minim...
def matrix_chain_order(p): """ Function to find the minimum number of scalar multiplications needed to compute the matrix chain product. Parameters: p (list): A list of integers where p[i] is the dimension of the matrix. Returns: int: The minimum number of scalar multiplications ne...
def test_matrix_chain_order(): assert min_matrix_mult(4, [1, 2, 3, 4, 5]) == 38 assert min_matrix_mult(3, [10, 20, 30, 40]) == 18000 assert min_matrix_mult(2, [10, 100, 5]) == 5000 assert min_matrix_mult(5, [4, 10, 3, 12, 20, 7]) == 1344 assert min_matrix_mult(4, [2, 3, 6, 4, 5]) == 124 def test_ma...
[ { "docstring": "Function to find the minimum number of scalar multiplications needed\nto compute the matrix chain product.\n\nParameters:\np (list): A list of integers where p[i] is the dimension of the matrix.\n\nReturns:\nint: The minimum number of scalar multiplications needed.", "function_declaration": ...
[ 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 matrix_chain_order(p):\n \"\"\"\n Returns the minimum number of scalar multiplications needed to multiply\n a sequence of matrices.\n \n ...
trial_gpt4o_2
{ "original_instruction": "Matrix Chain Multiplication is a classic problem of dynamic programming. Given a sequence of matrices, the task is to find the most efficient way to multiply these matrices together.\n\nA matrix A[i] has dimensions p[i-1] x p[i]. You want to know in which order to multiply the matrices so t...
0.489482
Code_Contests_45242
C
[ "matrix_chain_order", "min_matrix_mult" ]
2
[ [ "min_matrix_mult", "matrix_chain_order" ] ]
1
[]
false
[]
false
pytest
false
[]
true
8073390f264b7e1c6100b6c00317ae362c7af565
74b4951b60b4fd9b0d8d4d8209753fbdf42cd1fd
v1.0
complete
Code_Contests
Code_Contests_44888_C
class Node: def __init__(self, value, left=None, right=None): self.value = value self.left = left self.right = right def build_tree(nodes): if not nodes: return None node_dict = {} for value, left, right in nodes: if value not in node_dict: node_dict...
class Node: def __init__(self, value, left=None, right=None): self.value = value self.left = left self.right = right def build_tree(nodes): if not nodes: return None node_dict = {} for value, left, right in nodes: if value not in node_dict: node_dict...
import pytest from solution import calculate_tree_depth def test_example_case(): assert calculate_tree_depth(5, [ (1, 2, 3), (2, 4, 5), (3, 'null', 'null'), (4, 'null', 'null'), (5, 'null', 'null') ]) == 3 def test_single_node(): assert calculate_tree_depth(1, [ ...
[]
[ 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, value, left=None, right=None):\n self.value = value\n self.left = left\n self.right = right\n\ndef...
trial_gpt4o_0
{ "original_instruction": "Tree Depth Calculation\n\nYou are provided with a binary tree, and your task is to calculate its maximum depth. The depth of a node is defined as the number of edges on the path from the root node to the node. The depth of the tree is the maximum depth among all nodes in the tree.\n\nA bina...
0.578414
Code_Contests_44888
C
[ "build_tree", "max_depth", "calculate_tree_depth" ]
3
[ [ "calculate_tree_depth", "build_tree" ], [ "calculate_tree_depth", "max_depth" ] ]
2
[]
false
[ "Node" ]
true
pytest
true
[]
true
b489a895bcb69b7c6e2f77d3f4c52b28dabbd4db
cc1c8cdabec3cda1155665270a9cc9b1dc8336bd
v1.0
complete
Code_Contests
Code_Contests_45159_C
def reverse_subarray(array: List[int], l: int, r: int) -> List[int]: """ Given an array and indices l and r, reverse the subarray from index l to r. """ return array[:l-1] + array[l-1:r][::-1] + array[r:] def reconstruct_permutation(n: int, p: List[int]) -> List[int]: """ Given a permutation of...
def reverse_subarray(array, l, r): """ Given an array and indices l and r, reverse the subarray from index l to r. """ return array[:l-1] + array[l-1:r][::-1] + array[r:] def reconstruct_permutation(n, p): """ Given the length n and a permutation p, this function reconstructs the original permu...
# Assuming the solution is in a file named `solution.py` from solution import reverse_subarray, reconstruct_permutation def test_reverse_subarray(): assert reverse_subarray([1, 2, 3, 4, 5], 1, 5) == [5, 4, 3, 2, 1] assert reverse_subarray([1, 2, 3, 4, 5], 2, 4) == [1, 4, 3, 2, 5] assert reverse_subarray([1...
[ { "docstring": "Given an array and indices l and r, reverse the subarray from index l to r.", "function_declaration": "def reverse_subarray(array, l, r):", "function_name": "reverse_subarray", "parameter_list": "(array, l, r)" }, { "docstring": "Given the length n and a permutation p, this f...
[ 0, 0, 0, 0, 1, 0, 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": "def reconstruct_permutation(p):\n n = len(p)\n \n # Initial Check if the array is already sorted\n if p == sorted(p):\n return \"!\" + ...
trial_gpt4o_5
{ "original_instruction": "You are given a permutation of the first n positive integers, 1 through n, represented as an array p. Your task is to reconstruct the original permutation from which this array was derived after performing a series of m operations. Each operation consists of choosing a subarray and reversin...
0.639388
Code_Contests_45159
C
[ "reverse_subarray", "reconstruct_permutation" ]
2
[ [ "reconstruct_permutation", "reverse_subarray" ] ]
1
[]
false
[]
false
pytest
true
[]
true
5002455e5be94be978f67ee19253c7dcd43fa26c
0c4fd760fda94db275952a39d05a28fb15d78fed
v1.0
complete
Code_Contests
Code_Contests_45081_C
def marathon_info(input_data: List[str]) -> Tuple[int, str, int]: """Processes marathon race data to determine the fastest runner, the time difference between the fastest and second fastest runner, and the bib number of the slowest runner. Parameters: input_data (List[str]): List of lines whe...
from datetime import timedelta def process_race_data(runners): """ Processes race data to determine the fastest, the time difference between the fastest and second fastest, and the bib number of the slowest runner. Parameters: runners (list of tuples): List of tuples where each tuple contains ...
from solution import marathon_info def test_example_1(): input_data = [ "3", "45 2:15:38", "106 2:12:45", "374 2:20:01" ] assert marathon_info(input_data) == (106, '0:2:53', 374) def test_example_2(): input_data = [ "4", "12 1:05:20", "34 1:04:50...
[ { "docstring": "Processes race data to determine the fastest, the time difference between the fastest and second fastest,\nand the bib number of the slowest runner.\n\nParameters:\nrunners (list of tuples): List of tuples where each tuple contains the runner's bib number and their recorded time.\n\nReturns:\ntu...
[ 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 datetime import timedelta\n\ndef process_marathon_times(n, runner_times):\n def time_to_seconds(time_str):\n hours, minutes, seconds = map(i...
trial_gpt4o_2
{ "original_instruction": "The town of Algorville is arranging an annual marathon, and the organizers want to track the race progress at different checkpoints. Each runner has a unique bib number and their checkpoint times are recorded in hours, minutes, and seconds format. Your task is to create a system that proces...
0.529328
Code_Contests_45081
C
[ "process_race_data", "marathon_info" ]
2
[ [ "marathon_info", "process_race_data" ] ]
1
[]
false
[]
false
pytest
true
[]
true
a0508a6dd4ab9014a886dfbf13484a1108df2a92
a1fdab34ed3add2ee421f1f4e65d26525f300330
v1.0
complete
Code_Contests
Code_Contests_45288_C
def is_prime(num: int) -> bool: """Check if a number is a prime number. >>> is_prime(1) False >>> is_prime(2) True >>> is_prime(3) True >>> is_prime(4) False """ pass def find_kth_prime_in_n_primes(n: int, k: int) -> int: """Find the k-th prime number in an array of the ...
def is_prime(num): 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 return True def find_kth_prime_in_n_primes...
from solution import is_prime, find_kth_prime_in_n_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 not is_prime(9) assert is_prime(11) def test_find_kth_prime_in_n_primes(): assert find_kth_prime_...
[ { "docstring": null, "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": null, "function_declaration": "def find_kth_prime_in_n_primes(n, k):", "function_name": "find_kth_prime_in_n_primes", "parameter_list": "(n,...
[ 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 if num <= 3:\n return True\n if num % 2 == 0 or num % 3 == 0:\n return Fal...
trial_gpt4o_0
{ "original_instruction": "Petya loves prime numbers. He finds prime numbers fascinating and enjoys the challenge of discovering them. A prime number is a natural number greater than 1 that has no positive divisors other than 1 and itself.\n\nPetya wants to create an array of length n, where the value at each index i...
0.79082
Code_Contests_45288
C
[ "is_prime", "find_kth_prime_in_n_primes" ]
2
[ [ "find_kth_prime_in_n_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
4e4a2aa3744d4cbccbf93f909926ad1d61a91396
77a5571017c30d8e411c5a1ed728c9c4c2286488
v1.0
complete
Code_Contests
Code_Contests_45274_C
def calculate_max_gold(x, y, grid): """ Returns the maximum gold that can be collected starting from (x, y). >>> grid = {(0, 1): 5, (1, 0): 10, (1, 1): 15} >>> calculate_max_gold(0, 0, grid) 15 >>> grid = {(0, 1): 5, (1, 0): 20, (1, 1): 5} >>> calculate_max_gold(0, 0, grid) 20 ...
def calculate_max_gold(x, y, grid): """ Returns the maximum gold that can be collected starting from (x, y). """ max_gold = 0 for (a, b), g in grid.items(): if a >= x and b >= y: max_gold = max(max_gold, g) return max_gold def process_updates(x, y, initial_gold, updates): ...
def test_calculate_max_gold(): grid = { (0, 1): 5, (1, 0): 10, (1, 1): 15 } assert calculate_max_gold(0, 0, grid) == 15 assert calculate_max_gold(0, 1, grid) == 15 assert calculate_max_gold(1, 0, grid) == 15 assert calculate_max_gold(1, 1, grid) == 15 assert calculate...
[ { "docstring": "Returns the maximum gold that can be collected starting from (x, y).", "function_declaration": "def calculate_max_gold(x, y, grid):", "function_name": "calculate_max_gold", "parameter_list": "(x, y, grid)" }, { "docstring": "Process each update and return a list of maximum go...
[ 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_gold_collectable(x, y, gold_cells, updates):\n \"\"\"\n Calculate the maximum gold collectable on a 2D grid from a starting position (x, y).\...
trial_gpt4o_2
{ "original_instruction": "You are given an infinite 2D grid. In each cell, there can be some gold coins. Given an initial position (x, y) on the grid, you need to find the maximum amount of gold you can collect if you're only allowed to move right or down from any cell.\n\nInitially, you are given n coordinates, eac...
0.602712
Code_Contests_45274
C
[ "calculate_max_gold", "process_updates" ]
2
[ [ "process_updates", "calculate_max_gold" ] ]
1
[]
false
[]
false
pytest
false
[]
true
3b09c2e6c9dee5a8e0520d99621af49eb735b058
7f7bb7697c0f68155e31fc32533d3fbb3f1af0fd
v1.0
complete
Code_Contests
Code_Contests_45203_C
from typing import List def manage_farm(n: int, m: int, q: int, operations: List[str]) -> List[int]: """ Manages Farmer John's farm by performing operations on the grid and resolving queries about the largest contiguous fertile region. Parameters: n (int): Number of rows in the grid. m (in...
def find_largest_region(grid, n, m): def dfs(x, y): stack = [(x, y)] size = 0 while stack: cx, cy = stack.pop() if 0 <= cx < n and 0 <= cy < m and grid[cx][cy] == 1 and not visited[cx][cy]: visited[cx][cy] = True size += 1 ...
from solution import manage_farm def test_manage_farm_example_1(): n, m, q = 3, 3, 6 operations = ["1 0 0", "1 0 1", "2", "1 1 0", "1 2 0", "2"] assert manage_farm(n, m, q, operations) == [2, 4] def test_manage_farm_single_cell(): n, m, q = 1, 1, 2 operations = ["1 0 0", "2"] assert manage_far...
[ { "docstring": null, "function_declaration": "def find_largest_region(grid, n, m):", "function_name": "find_largest_region", "parameter_list": "(grid, n, m)" }, { "docstring": null, "function_declaration": "def manage_farm(n, m, q, operations):", "function_name": "manage_farm", "...
[ 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 largest_fertile_region(grid, n, m):\n def dfs(x, y):\n if x < 0 or x >= n or y < 0 or y >= m or grid[x][y] == 0:\n return 0\n ...
trial_gpt4o_2
{ "original_instruction": "Farmer John owns a rectangular farm that can be represented as a grid with n rows and m columns. Each cell in the grid can either be fertile (represented by `1`) or barren (represented by `0`). Farmer John can perform two types of operations:\n\n 1. Turn a specific barren cell into a ferti...
0.556996
Code_Contests_45203
C
[ "find_largest_region", "manage_farm" ]
2
[ [ "manage_farm", "find_largest_region" ] ]
1
[]
false
[]
false
pytest
true
[]
true
edd747aef688f813fa81edd8f4ac4a8189f68874
638ba0789bc3ca5760d5e188aceff21c8ab0532d
v1.0
complete
Code_Contests
Code_Contests_45521_C
def matrix_transformation_possible(n: int, matrix: List[List[int]]) -> str: """ Determine if it is possible to transform the given n x n matrix into an identity matrix by rotating its rows and columns. Args: n (int): The size of the matrix. matrix (List[List[int]]): The n x n matrix element...
def can_transform_to_identity(n, matrix): # Check if every row contains exactly one 1 for row in matrix: if row.count(1) != 1: return "NO" # Check if every column contains exactly one 1 for col in range(n): col_count = 0 for row in range(n): if matrix...
from solution import matrix_transformation_possible def test_example1(): n = 2 matrix = [ [0, 1], [1, 0] ] assert matrix_transformation_possible(n, matrix) == "YES" def test_example2(): n = 3 matrix = [ [1, 2, 3], [4, 5, 6], [7, 8, 9] ] assert ma...
[ { "docstring": null, "function_declaration": "def can_transform_to_identity(n, matrix):", "function_name": "can_transform_to_identity", "parameter_list": "(n, matrix)" }, { "docstring": null, "function_declaration": "def matrix_transformation_possible(n, matrix):", "function_name": "...
[ 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_transform_to_identity(n, matrix):\n # Check if every row contains exactly one 1\n for row in matrix:\n if row.count(1) != 1:\n ...
trial_gpt4o_0
{ "original_instruction": "**Question: Matrix Transformation**\n\nGiven an `n x n` matrix, determine if it is possible to transform it into an identity matrix by rotating its rows and columns. You can rotate any row or column such that the last element becomes the first one and all other elements shift one position t...
0.51351
Code_Contests_45521
C
[ "can_transform_to_identity", "matrix_transformation_possible" ]
2
[ [ "matrix_transformation_possible", "can_transform_to_identity" ] ]
1
[]
false
[]
false
pytest
true
[]
true
b8f0d79b636435357c5fc85dd5ee6a9d4c8d814b
ebca7190546bede30f1ec21f77dc2ec08584884c
v1.0
complete
Code_Contests
Code_Contests_45106_C
from typing import List from collections import Counter import heapq def can_rearrange_string(n: int, s: str) -> str: """ Determine if the string can be rearranged such that no two adjacent letters are the same. Args: n: The length of the string. s: The string consisting of exactly n lowercase Latin l...
from collections import Counter import heapq def rearrange_string(s): """ Rearranges the string such that no two adjacent letters are the same. If not possible, returns -1. """ # Count the frequency of each character freq = Counter(s) # Create a max heap based on frequency max_heap = [(...
from solution import can_rearrange_string def test_example_1(): assert can_rearrange_string(7, "aabbccc") != -1 def test_example_2(): assert can_rearrange_string(6, "aaabbb") == "ababab" def test_example_3(): assert can_rearrange_string(3, "aaa") == -1 def test_single_char(): assert can_...
[ { "docstring": "Rearranges the string such that no two adjacent letters are the same.\nIf not possible, returns -1.", "function_declaration": "def rearrange_string(s):", "function_name": "rearrange_string", "parameter_list": "(s)" }, { "docstring": null, "function_declaration": "def can_...
[ 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 Counter\nfrom heapq import heappush, heappop\n\ndef rearrange_string(s):\n \"\"\"\n Returns a rearrangement of the string suc...
trial_gpt4o_2
{ "original_instruction": "You are given a string s consisting of n lowercase Latin letters.\n\nYour task is to determine if it is possible to rearrange the letters of the string such that no two adjacent letters are the same. If it is possible, you should return one such rearrangement; otherwise, return -1.\n\nInput...
0.739761
Code_Contests_45106
C
[ "rearrange_string", "can_rearrange_string" ]
2
[ [ "can_rearrange_string", "rearrange_string" ] ]
1
[]
false
[]
false
pytest
true
[]
true
7832b570fdcd8f2af59e8a1e8e0c27baf4d17382
35932866f17342dd0c7a8679c95b36a6eb82a62a
v1.0
complete
Code_Contests
Code_Contests_45505_C
from typing import List import math def is_ana_number(num: int) -> bool: """ Check if a number is an Ana Number. An Ana Number is a positive integer where the sum of the factorial of its digits equals the number itself. >>> is_ana_number(1) True >>> is_ana_number(2) True >>> is_ana_numb...
import math def is_ana_number(num): """ Check if a number is an Ana Number. An Ana Number is a positive integer where the sum of the factorial of its digits equals the number itself. """ return num == sum(math.factorial(int(digit)) for digit in str(num)) def find_ana_numbers(n): """ Find a...
from solution import is_ana_number, find_ana_numbers def test_is_ana_number(): assert is_ana_number(1) == True assert is_ana_number(2) == True assert is_ana_number(145) == True assert is_ana_number(123) == False def test_find_ana_numbers(): assert find_ana_numbers(150) == [1, 2, 145] assert fi...
[ { "docstring": "Check if a number is an Ana Number.\nAn Ana Number is a positive integer where the sum of the factorial of its digits equals the number itself.", "function_declaration": "def is_ana_number(num):", "function_name": "is_ana_number", "parameter_list": "(num)" }, { "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": "import math\n\ndef is_ana_number(num):\n \"\"\"\n Check if the given number is an Ana Number.\n \"\"\"\n return num == sum(math.factorial(int(d...
trial_gpt4o_2
{ "original_instruction": "Professor Ana is working on a special sequence of integers. She defines an Ana Number as a positive integer where the sum of the factorials of its digits equals the number itself. For example, 145 is an Ana Number, because 1! + 4! + 5! = 1 + 24 + 120 = 145.\n\nYour task is to write a progra...
0.613391
Code_Contests_45505
C
[ "is_ana_number", "find_ana_numbers" ]
2
[ [ "find_ana_numbers", "is_ana_number" ] ]
1
[]
false
[]
false
pytest
true
[]
true
f8afc4ee51693d41942fdadf90c8e6f28bb3c481
beb9153db2d5fa96636d1a246f789e39dbece9e6
v1.0
complete
Code_Contests
Code_Contests_45482_C
from typing import List def partition(s: str) -> List[List[str]]: """ Return all possible palindrome partitioning of a given string s. >>> partition("aab") [["a", "a", "b"], ["aa", "b"]] >>> partition("a") [["a"]] >>> partition("racecar") [["r", "a", "c", "e", "c", "a", "r"], ["r", "a", "ce...
def is_palindrome(sub): return sub == sub[::-1] def partition(s): result = [] def backtrack(start, path): if start == len(s): result.append(path[:]) return for end in range(start + 1, len(s) + 1): if is_palindrome(s[start:end]): ...
from solution import partition def test_partition_single_char(): result = partition("a") assert result == [["a"]], f"Unexpected result: {result}" def test_partition_two_chars(): result = partition("aa") assert result == [["a", "a"], ["aa"]], f"Unexpected result: {result}" def test_partition_diffe...
[ { "docstring": null, "function_declaration": "def is_palindrome(sub):", "function_name": "is_palindrome", "parameter_list": "(sub)" }, { "docstring": null, "function_declaration": "def partition(s):", "function_name": "partition", "parameter_list": "(s)" }, { "docstring":...
[ 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_palindrome(s):\n return s == s[::-1]\n\ndef partition(s):\n def backtrack(start, path):\n if start == len(s):\n result.appen...
trial_gpt4o_2
{ "original_instruction": "Palindrome Partitioning\n\nConstraints\n\n* 1 ≤ s.length ≤ 20\n* s consists only of lowercase English letters.\n\nInput\n\nA single string s.\n\nOutput\n\nReturn all possible palindrome partitioning of s as a list of lists.\n\nExample\n\nInput\n\n\"aab\"\n\nOutput\n\n[\n [\"a\",\"a\",\"b\"...
0.664902
Code_Contests_45482
C
[ "is_palindrome", "partition" ]
2
[ [ "partition", "is_palindrome" ] ]
1
[]
false
[]
false
pytest
true
[]
true
910fd6f8cc05de7cc88455f65b73441f82d50bb0
d87c77788f0cadc16638ab811646863ff7e9d6c7
v1.0
complete
Code_Contests
Code_Contests_45411_C
def sieve_of_eratosthenes(n): """ Returns a list of all primes less than or equal to n using the Sieve of Eratosthenes algorithm. """ prime = [True for _ in range(n+1)] p = 2 while (p * p <= n): if prime[p] == True: for i in range(p * p, n + 1, p): prime[i] = ...
def sieve_of_eratosthenes(n): """ Returns a list of all primes less than or equal to n using the Sieve of Eratosthenes algorithm. """ prime = [True for _ in range(n+1)] p = 2 while (p * p <= n): if prime[p] == True: for i in range(p * p, n + 1, p): prime[i] = ...
from solution import sieve_of_eratosthenes, primes_with_digit_7, solve_queries def test_sieve_of_eratosthenes(): assert sieve_of_eratosthenes(10) == [2, 3, 5, 7] assert sieve_of_eratosthenes(30) == [2, 3, 5, 7, 11, 13, 17, 19, 23, 29] assert sieve_of_eratosthenes(100) == [2, 3, 5, 7, 11, 13, 17, 19, 23, 29...
[ { "docstring": "Returns a list of all primes less than or equal to n using the Sieve of Eratosthenes algorithm.", "function_declaration": "def sieve_of_eratosthenes(n):", "function_name": "sieve_of_eratosthenes", "parameter_list": "(n)" }, { "docstring": null, "function_declaration": "de...
[ 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 sieve(n):\n \"\"\"\n Returns a list of boolean values representing whether numbers up to n are prime.\n \"\"\"\n is_prime = [True] * (n + 1...
trial_gpt4o_4
{ "original_instruction": "Problem Statement:\n\nAlice loves to play with numbers, and she's particularly fascinated by prime numbers. One day she came up with a problem for herself: Given an integer 'x', she wants to find all the prime numbers less than or equal to 'x' that contain the digit '7'.\n\nBeing new to pro...
0.675578
Code_Contests_45411
C
[ "sieve_of_eratosthenes", "primes_with_digit_7", "solve_queries", "main" ]
4
[ [ "primes_with_digit_7", "sieve_of_eratosthenes" ], [ "solve_queries", "primes_with_digit_7" ] ]
2
[ "solve_queries" ]
false
[]
false
pytest
true
[]
true
c8b6816ffeb0d2f5cd38e7a8d4d912ee19fffcc9
0cb791660d237b282f22692e4a9115e69250a12b
v1.0
complete
Code_Contests
Code_Contests_45264_C
def count_components_after_edge_removal(n: int, m: int, edges: List[Tuple[int, int]], k: int, to_remove: List[Tuple[int, int]]) -> int: """ Determine the number of connected components in a graph after removing specified edges. Args: n : int : number of vertices m : int : number of initial edges ed...
def find_connected_components(n, edges, to_remove): from collections import defaultdict, deque # Create the adjacency list for the graph adj_list = defaultdict(list) for u, v in edges: adj_list[u].append(v) adj_list[v].append(u) # Remove the specified edges for u, v in to_r...
def test_find_connected_components(): # Test case 1 n = 7 m = 6 edges = [(1, 2), (2, 3), (3, 4), (4, 5), (5, 6), (6, 7)] k = 2 to_remove = [(2, 3), (4, 5)] assert count_components_after_edge_removal(n, m, edges, k, to_remove) == 3 # Test case 2 n = 5 m = 4 edges = [(1, 2), (...
[ { "docstring": null, "function_declaration": "def find_connected_components(n, edges, to_remove):", "function_name": "find_connected_components", "parameter_list": "(n, edges, to_remove)" }, { "docstring": null, "function_declaration": "def count_components_after_edge_removal(n, m, edges...
[ 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 count_connected_components(n, edges, to_remove):\n from collections import defaultdict, deque\n\n # Initialize adjacency list\n graph = defaul...
trial_gpt4o_1
{ "original_instruction": "In a certain magical land, there is a series of bridges connecting different islands. These islands and bridges can be represented as an undirected graph where islands are vertices and bridges are edges. Unfortunately, some of the bridges are fragile and will collapse if used.\n\nYou have t...
0.639125
Code_Contests_45264
C
[ "find_connected_components", "count_components_after_edge_removal" ]
2
[ [ "count_components_after_edge_removal", "find_connected_components" ] ]
1
[]
false
[]
false
pytest
false
[]
true
3a10ee45c7f63d5316e3c5c3f3dc5d6502b5e4b9
331cb879e1fb7ae9ee8fd9258a66546155d34339
v1.0
complete
Code_Contests
Code_Contests_45773_C
def find_maximum_sub_segment_sum(N: int, values: List[int]) -> int: """ Function to find the sum of the most valuable sub-segment of coins. Args: N (int): The number of coins. values (List[int]): The list of coin values. Returns: int: The sum of the most valuable sub-segment. >>> find_...
def maxSubArraySum(values): """ Function to find the sum of the most valuable sub-segment Args: values : List[int] : List containing values of coins Returns: int : Maximum sub-segment sum """ max_sum = values[0] current_sum = values[0] for i in range(1, len(values)): cu...
from solution import find_maximum_sub_segment_sum def test_single_value(): assert find_maximum_sub_segment_sum(1, [5]) == 5 def test_all_positive(): assert find_maximum_sub_segment_sum(5, [1, 2, 3, 4, 5]) == 15 def test_all_negative(): assert find_maximum_sub_segment_sum(3, [-1, -2, -3]) == -1 def test_...
[ { "docstring": "Function to find the sum of the most valuable sub-segment\nArgs:\nvalues : List[int] : List containing values of coins\n\nReturns:\nint : Maximum sub-segment sum", "function_declaration": "def maxSubArraySum(values):", "function_name": "maxSubArraySum", "parameter_list": "(values)" ...
[ 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 max_subsegment_sum(N, coins):\n \"\"\"\n Returns the sum of the most valuable sub-segment.\n \"\"\"\n max_sum = current_sum = coins[0]\n ...
trial_gpt4o_1
{ "original_instruction": "Shiro is an avid collector of antique coins. He arranges his coins in a straight line on a shelf. Each coin has a unique value assigned to it, and he wants to know the most valuable sub-segment of his collection. A sub-segment is defined as a continuous portion of the line of coins.\n\nGive...
0.660114
Code_Contests_45773
C
[ "maxSubArraySum", "find_maximum_sub_segment_sum" ]
2
[ [ "find_maximum_sub_segment_sum", "maxSubArraySum" ] ]
1
[]
false
[]
false
pytest
true
[]
true
349e0c2e5a7e7d55683e44558dd748c5cdb42b11
ba15bf1ff308ec3adf7b25982e7d0001aac9fe97
v1.0
complete
Code_Contests
Code_Contests_45038_C
from typing import List, Tuple def gcd(a: int, b: int) -> int: """Calculate the greatest common divisor (GCD) of two numbers.""" pass def max_boxes(t: int, test_cases: List[Tuple[int, List[int]]]) -> List[int]: """Determine the maximum number of boxes in which you can pack the books. Each box mus...
def gcd(a, b): while b: a, b = b, a % b return a def max_boxes(t, test_cases): result = [] for i in range(t): n = test_cases[i][0] pages = test_cases[i][1] if n == 1: result.append(1) continue overall_gcd = pages[0] ...
from solution import gcd, max_boxes def test_gcd(): assert gcd(6, 8) == 2 assert gcd(12, 15) == 3 assert gcd(7, 3) == 1 assert gcd(10, 5) == 5 assert gcd(1, 1) == 1 def test_max_boxes_single_case(): assert max_boxes(1, [(4, [6, 4, 8, 12])]) == [2] assert max_boxes(1, [(3, [3, 5, 7])]) == [...
[ { "docstring": null, "function_declaration": "def gcd(a, b):", "function_name": "gcd", "parameter_list": "(a, b)" }, { "docstring": null, "function_declaration": "def max_boxes(t, test_cases):", "function_name": "max_boxes", "parameter_list": "(t, test_cases)" } ]
[ 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 gcd(a, b):\n while b:\n a, b = b, a % b\n return a\n\ndef max_boxes(t, test_cases):\n result = []\n for i in range(t):\n n = ...
trial_gpt4o_0
{ "original_instruction": "You have a collection of n distinct books and you want to pack them into boxes such that the books in each box meet a specific condition. The condition is that the number of books in the box should be equal to the greatest common divisor (GCD) of the page counts of all books in that box. Th...
0.565661
Code_Contests_45038
C
[ "gcd", "max_boxes" ]
2
[ [ "max_boxes", "gcd" ] ]
1
[]
false
[]
false
pytest
true
[]
true
b4f3d502868a3e0c6e43d2395da4727ac476b689
2a070327c97a246236a7f80891e0af8f81c7926e
v1.0
complete
Code_Contests
Code_Contests_44989_C
import math from functools import reduce def lcm(a, b): """Compute the least common multiple of two numbers """ return abs(a * b) // math.gcd(a, b) def find_days_until_bloom(intervals): """Find the number of days until all plants bloom together again. Args: intervals (List[int]): List of bloo...
import math from functools import reduce MODULO = 1000000007 def lcm(a, b): return abs(a * b) // math.gcd(a, b) def find_days_until_bloom(intervals): return reduce(lcm, intervals) % MODULO def solve(test_cases): results = [] for n, intervals in test_cases: days = find_days_until_bloom(interv...
from solution import main def test_sample_cases(): input_data = """2 3 3 7 9 4 2 3 5 7""" expected_output = [63, 210] assert main(input_data) == expected_output def test_single_plant(): input_data = """1 1 7""" expected_output = [7] assert main(input_data) == expected_output def test_large_nu...
[ { "docstring": null, "function_declaration": "def lcm(a, b):", "function_name": "lcm", "parameter_list": "(a, b)" }, { "docstring": null, "function_declaration": "def find_days_until_bloom(intervals):", "function_name": "find_days_until_bloom", "parameter_list": "(intervals)" }...
[ 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": "import math\nfrom functools import reduce\n\nMODULO = 1000000007\n\ndef lcm(a, b):\n return abs(a * b) // math.gcd(a, b)\n\ndef find_days_until_bloom(in...
trial_gpt4o_0
{ "original_instruction": "Given a scenic garden with several plants, each plant blooms at a regular interval of days. All the plants in the garden bloomed together on day 0. You need to determine how many days it will be until all the plants bloom together again.\n\nFor example, if there are 3 plants with blooming i...
0.563692
Code_Contests_44989
C
[ "lcm", "find_days_until_bloom", "solve", "parse_input", "main" ]
5
[ [ "find_days_until_bloom", "lcm" ], [ "solve", "find_days_until_bloom" ] ]
2
[ "parse_input" ]
false
[]
false
pytest
true
[]
true
c0a23ff753123b18f99c9821ee77357beb477683
5512174aec7e0c8baae2fc669fab8da5a61a4e17
v1.0
complete
Code_Contests
Code_Contests_45665_C
from typing import List def preprocess_expiration_dates(expiration_dates: List[int]) -> None: """ Preprocess the list of expiration dates by sorting them. """ pass def count_expired_items_by_day(expiration_dates: List[int], day: int) -> int: """ Count the number of food items that will expire ...
from bisect import bisect_right def preprocess_expiration_dates(expiration_dates): """ Preprocess the list of expiration dates by sorting them. """ expiration_dates.sort() def count_expired_items_by_day(expiration_dates, day): """ Count the number of food items that will expire on or before a ...
from solution import handle_queries def test_example_case(): expiration_dates = [2, 3, 1, 4, 0] queries = [0, 3, 10] expected_output = [1, 4, 5] assert handle_queries(expiration_dates, queries) == expected_output def test_all_never_expire(): expiration_dates = [0, 0, 0, 0, 0] queries = [0, 1, ...
[ { "docstring": "Preprocess the list of expiration dates by sorting them.", "function_declaration": "def preprocess_expiration_dates(expiration_dates):", "function_name": "preprocess_expiration_dates", "parameter_list": "(expiration_dates)" }, { "docstring": "Count the number of food items th...
[ 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 preprocess_expiration_dates(expiration_dates):\n \"\"\"\n Preprocess the list of expiration dates to facilitate quick querying.\n \"\"\"\n ...
trial_gpt4o_2
{ "original_instruction": "Your task is to help Takahashi manage his food inventory. He has a list of \\(N\\) food items, each identified by a unique integer ID from \\(1\\) to \\(N\\). Each food item has an associated expiration date, represented as a non-negative integer \\(e_i\\), where \\(0\\) means the food item...
0.520891
Code_Contests_45665
C
[ "preprocess_expiration_dates", "count_expired_items_by_day", "handle_queries" ]
3
[ [ "handle_queries", "count_expired_items_by_day" ], [ "handle_queries", "preprocess_expiration_dates" ] ]
2
[ "handle_queries" ]
false
[]
false
pytest
true
[]
true
adc11f6e68bf0bd1eb58fd474a55673c26c937e3
875f3b083e8abbb70222c3de76e2f14ffd06120c
v1.0
complete
Code_Contests
Code_Contests_45595_C
def travel_route_optimization(datasets: List[List[List[int]]]) -> List[int]: """ Optimize the travel route to visit all attractions with the minimum possible distance. >>> travel_route_optimization([ ... [[0, 10], [10, 0]], ... [[0, 29, 20], [29, 0, 15], [20, 15, 0]] ... ]) [20, 64] ...
from itertools import permutations def tsp_minimum_distance(d): N = len(d) min_distance = float('inf') # Generate all possible routes (permutations) for perm in permutations(range(N)): # Calculate the distance of this route distance = 0 for i in range(N): distan...
from solution import travel_route_optimization, parse_input def test_travel_route_optimization(): input_text = "2\n0 10\n10 0\n3\n0 29 20\n29 0 15\n20 15 0\n0" expected_output = [20, 64] datasets = parse_input(input_text) assert travel_route_optimization(datasets) == expected_output def test_travel_r...
[ { "docstring": null, "function_declaration": "def tsp_minimum_distance(d):", "function_name": "tsp_minimum_distance", "parameter_list": "(d)" }, { "docstring": null, "function_declaration": "def travel_route_optimization(datasets):", "function_name": "travel_route_optimization", ...
[ 1, 1 ]
2
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "import itertools\n\ndef tsp_brute_force(dist_matrix):\n \"\"\"\n Solve the Traveling Salesman Problem using brute force method.\n Parameters:\n ...
trial_gpt4o_1
{ "original_instruction": "### Travel Route Optimization\n\nYou are a tour guide planning to organize trips for tourists in a city. The city has numerous attractions, and there are multiple possible routes connecting different attractions. Your goal is to plan the shortest possible route that visits each attraction e...
0.62258
Code_Contests_45595
C
[ "tsp_minimum_distance", "travel_route_optimization", "parse_input" ]
3
[ [ "travel_route_optimization", "tsp_minimum_distance" ] ]
1
[ "parse_input" ]
false
[]
false
pytest
true
[]
true
3934d2798c777f9427aad544ba8d8ffe45558efb
b5deca1e835a2a797b8cf672aa459d0fb61e4cc5
v1.0
complete
Code_Contests
Code_Contests_46210_C
def next_n_primes(start: int, n: int) -> List[int]: """ Generates the next n prime numbers greater than a given start. >>> next_n_primes(10, 5) [11, 13, 17, 19, 23] >>> next_n_primes(20, 3) [23, 29, 31] """
def is_prime(num): """ Helper function to check if a number is a prime number. """ if num <= 1: return False if num == 2: return True if num % 2 == 0: return False for i in range(3, int(num**0.5) + 1, 2): if num % i == 0: return False return Tr...
from solution import next_n_primes def test_next_n_primes_example_1(): assert next_n_primes(10, 5) == [11, 13, 17, 19, 23] def test_next_n_primes_example_2(): assert next_n_primes(20, 3) == [23, 29, 31] def test_next_n_primes_start_0(): assert next_n_primes(0, 4) == [2, 3, 5, 7] def test_next_n_primes_s...
[ { "docstring": "Helper function to check if a number is a prime number.", "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": "Returns the next n prime numbers greater than a given start.", "function_declaration": "def ne...
[ 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 Returns whether a number is a prime number.\n \"\"\"\n if num <= 1:\n return False\n if num <= 3:\n ...
trial_gpt4o_2
{ "original_instruction": "Given an integer `n`, generate the next `n` prime numbers in the sequence after a specified starting number `start`. A prime number is a natural number greater than 1 that cannot be formed by multiplying two smaller natural numbers. The sequence of prime numbers begins as 2, 3, 5, 7, 11, 13...
0.736898
Code_Contests_46210
C
[ "is_prime", "next_n_primes" ]
2
[ [ "next_n_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
f1d33f5c34017edd43d14fd255aeafd1847955ee
528ebf7c83ed781c02d533cdf8ca491c47e3f936
v1.0
complete
Code_Contests
Code_Contests_45927_C
from typing import List, Tuple def is_subsequence(small: str, large: str) -> bool: """ Check if 'small' is a subsequence of 'large'. >>> is_subsequence("ab", "abc") True >>> is_subsequence("abc", "ab") False """ pass def find_special_strings(t: int, test_cases: List[Tuple[int, List[str]]])...
def is_subsequence(small, large): it = iter(large) return all(char in it for char in small) def find_special_strings(t, test_cases): results = [] for i in range(t): n = test_cases[i][0] strings = test_cases[i][1] special_strings = [] for s in strings: ...
from solution import is_subsequence, find_special_strings def test_is_subsequence(): assert is_subsequence("ab", "abc") assert not is_subsequence("abc", "ab") assert is_subsequence("abc", "aabbcc") assert not is_subsequence("acb", "abc") def test_find_special_strings(): assert find_special_strings...
[ { "docstring": null, "function_declaration": "def is_subsequence(small, large):", "function_name": "is_subsequence", "parameter_list": "(small, large)" }, { "docstring": null, "function_declaration": "def find_special_strings(t, test_cases):", "function_name": "find_special_strings",...
[ 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 is_subsequence(small, large):\n it = iter(large)\n return all(char in it for char in small)\n \ndef find_special_strings(test_cases):\n res...
trial_gpt4o_7
{ "original_instruction": "Sam is working on a data-driven project that involves analyzing a collection of strings. Each string is composed exclusively of lower case alphabets. After pre-processing, he generates a list where each element is a string. The final task is to identify special strings in this list. A strin...
0.656643
Code_Contests_45927
C
[ "is_subsequence", "find_special_strings" ]
2
[ [ "find_special_strings", "is_subsequence" ] ]
1
[]
false
[]
false
pytest
true
[]
true
1922b0ed1b2b0adac13d7321ba75a76e9347c53f
8a651f1f839c336eab99e7c6ed76321b514ab174
v1.0
complete
Code_Contests
Code_Contests_45336_C
from typing import List def min_steps_to_and_return(n: int, m: int, grid: List[str]) -> int: """ Determine the minimum number of steps required for the robot to reach the bottom-right corner of the grid and then return to the starting position. If it is impossible, return -1. >>> min_steps_to_and_re...
from collections import deque def is_valid(x, y, n, m, grid, visited): return 0 <= x < n and 0 <= y < m and grid[x][y] == '.' and not visited[x][y] def bfs(grid, start, end, n, m): directions = [(-1,0), (1,0), (0,-1), (0,1)] queue = deque([(start[0], start[1], 0)]) # (x, y, distance) visited = [[False...
import pytest from solution import min_steps_to_and_return def test_min_steps_example_1(): grid = [ ".....", "....#", "##...", "...#.", "....." ] assert min_steps_to_and_return(5, 5, grid) == 16 def test_min_steps_example_2(): grid = [ ".#.", "##...
[ { "docstring": null, "function_declaration": "def is_valid(x, y, n, m, grid, visited):", "function_name": "is_valid", "parameter_list": "(x, y, n, m, grid, visited)" }, { "docstring": null, "function_declaration": "def bfs(grid, start, end, n, m):", "function_name": "bfs", "param...
[ 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 bfs(grid, start, end):\n n, m = len(grid), len(grid[0])\n visited = [[False for _ in range(m)] for _ in range(n)...
trial_gpt4o_1
{ "original_instruction": "Consider a robot that is placed on a 2D grid. The grid has n rows and m columns. Each cell in the grid can either be empty or contain an obstacle. The robot can move one step at a time to any of its four neighboring cells - up, down, left, or right, but it cannot move into a cell that conta...
0.573814
Code_Contests_45336
C
[ "is_valid", "bfs", "min_steps_to_and_return" ]
3
[ [ "bfs", "is_valid" ], [ "min_steps_to_and_return", "bfs" ] ]
2
[]
false
[]
false
pytest
true
[]
true
0ebfa1490de88ca195e7a844cd255a1d52ee6a2a
82c7ca93cb6f04a54b43cd3e7fd72c515e14efb6
v1.0
complete
Code_Contests
Code_Contests_45816_C
import math from typing import List, Tuple def is_regular_polygon(n: int, points: List[Tuple[int, int]]) -> str: """ Checks if the points form a polygon that resembles a regular polygon. >>> is_regular_polygon(4, [(0, 0), (2, 0), (2, 2), (0, 2)]) "YES" >>> is_regular_polygon(3, [(0, 0), (1, 1), (2, 0)]...
import math def is_regular_polygon(n, points): # Helper to calculate distance between two points def distance(p1, p2): return math.sqrt((p1[0] - p2[0])**2 + (p1[1] - p2[1])**2) # Calculate the distances between consecutive points sides = [distance(points[i], points[(i + 1) % n]) for i in range...
from solution import is_regular_polygon def test_square(): points = [(0, 0), (2, 0), (2, 2), (0, 2)] assert is_regular_polygon(4, points) == "YES" def test_triangle(): points = [(0, 0), (1, 1), (2, 0)] assert is_regular_polygon(3, points) == "NO" def test_regular_hexagon(): points = [(1, 0), (0.5...
[ { "docstring": null, "function_declaration": "def is_regular_polygon(n, points):", "function_name": "is_regular_polygon", "parameter_list": "(n, points)" }, { "docstring": null, "function_declaration": "def solve():", "function_name": "solve", "parameter_list": "()" }, { ...
[ 0, 0, 0, 0, 0, 0, 0, 1, 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 is_regular_polygon(points):\n import math\n \n def distance(p1, p2):\n return math.sqrt((p2[0] - p1[0])**2 + (p2[1] - p1[1])**2)\n \...
trial_gpt4o_7
{ "original_instruction": "Late at night, you were stargazing on a rooftop when you saw a peculiar constellation. The constellation is formed by `n` stars placed on a 2D coordinate plane. Each star is represented as a point `(xi, yi)`.\n\nYour task is to determine if the stars form a polygon that resembles a regular ...
0.550934
Code_Contests_45816
C
[ "is_regular_polygon", "solve" ]
2
[ [ "solve", "is_regular_polygon" ] ]
1
[]
false
[]
false
pytest
true
[]
true
d46ac1cf2738c3b0f84695ffc8103c231860ec78
c6fe658b0e65fb10202db3c5e057dc3af5b7f15a
v1.0
complete
Code_Contests
Code_Contests_46042_C
import itertools def calculate_distance(x1, y1, x2, y2): return abs(x1 - x2) + abs(y1 - y2) def minimal_total_distance(n: int, trees: List[Tuple[int, int]]) -> int: """ Calculate the minimal total distance traveled by the ranger to mark all the trees and return to the starting tree. >>> minimal_t...
import itertools def calculate_distance(x1, y1, x2, y2): return abs(x1 - x2) + abs(y1 - y2) def minimal_total_distance(n, trees): if n == 1: return 0 # If there's only one tree, no travel is needed. min_distance = float('inf') for perm in itertools.permutations(range(n)): cu...
from solution import minimal_total_distance def test_minimal_total_distance(): assert minimal_total_distance(4, [(0, 0), (10, 10), (10, 0), (0, 10)]) == 40 assert minimal_total_distance(3, [(1, 1), (2, 2), (3, 3)]) == 8 assert minimal_total_distance(1, [(5, 5)]) == 0 assert minimal_total_distance(2, [(...
[ { "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 minimal_total_distance(n, trees):", "function_name": "minimal_total...
[ 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": "import itertools\n\ndef calculate_manhattan_distance(point1, point2):\n \"\"\"Calculate the Manhattan distance between two points.\"\"\"\n return abs...
trial_gpt4o_2
{ "original_instruction": "You are given a dense forest with n trees. Each tree is located at a distinct point in a 2D plane. There is a ranger who needs to travel from one tree to another to mark all trees with a special mark for research purposes. The ranger can travel only vertically or horizontally from one tree ...
0.607238
Code_Contests_46042
C
[ "calculate_distance", "minimal_total_distance" ]
2
[ [ "minimal_total_distance", "calculate_distance" ] ]
1
[]
false
[]
false
pytest
true
[]
true
0e3c7e4b13b8732907d5eb076a5b6e3b777f3fc2
543a52182560a46343475fd5af3856bd3049a2e3
v1.0
complete
Code_Contests
Code_Contests_46450_C
import math from typing import List, Tuple def process_test_cases(T: int, test_cases: List[Tuple[int, List[int]]]) -> List[int]: """ Determine the final equal height of all pillars after performing the necessary operations. >>> process_test_cases(2, [(4, [3, 9, 12, 15]), (3, [6, 6, 9])]) [3, 3] >>...
import math def gcd(a, b): while b: a, b = b, a % b return a def find_final_height(pillars): current_gcd = pillars[0] for height in pillars[1:]: current_gcd = gcd(current_gcd, height) if current_gcd == 1: # early exit, as the smallest possible gcd is 1 break re...
from solution import process_test_cases def test_example_1(): T = 2 test_cases = [ (4, [3, 9, 12, 15]), (3, [6, 6, 9]) ] assert process_test_cases(T, test_cases) == [3, 3] def test_all_identical_heights(): T = 1 test_cases = [ (5, [7, 7, 7, 7, 7]) ] assert proce...
[ { "docstring": null, "function_declaration": "def gcd(a, b):", "function_name": "gcd", "parameter_list": "(a, b)" }, { "docstring": null, "function_declaration": "def find_final_height(pillars):", "function_name": "find_final_height", "parameter_list": "(pillars)" }, { "d...
[ 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 gcd(a, b):\n while b:\n a, b = b, a % b\n return a\n\ndef find_final_height(heights):\n \"\"\"\n Returns the final equal height afte...
trial_gpt4o_1
{ "original_instruction": "A group of explorers have discovered a mysterious island with a set of N stone pillars arranged in a circle. Each pillar has an inscription that indicates a number, representing the height of the pillar. The heights of these pillars are given in a list where each integer denotes the height ...
0.567302
Code_Contests_46450
C
[ "gcd", "find_final_height", "process_test_cases" ]
3
[ [ "find_final_height", "gcd" ], [ "process_test_cases", "find_final_height" ] ]
2
[ "process_test_cases" ]
false
[]
false
pytest
true
[]
true
ccb04b5fedb959a2d1c1db13f3b5ea47db994190
70da98da1540e355d7d8831220c8e1955851e2d8
v1.0
complete
Code_Contests
Code_Contests_46239_C
def smallest_enclosing_rectangle(rectangles): """ Given a list of rectangles represented by their width and height, this function returns the dimensions of the smallest possible enclosing rectangle. """ # Your code here # Function to help parse input and pass to the function def parse_input_rectang...
def smallest_enclosing_rectangle(rectangles): """ Given a list of rectangles represented by their width and height, this function returns the dimensions of the smallest possible enclosing rectangle. """ max_width, max_height = 0, 0 for w, h in rectangles: if (w > max_width): ...
import pytest from solution import parse_input_rectangle, smallest_enclosing_rectangle def test_example1(): input_string = "3\n4 6\n7 2\n5 5" assert parse_input_rectangle(input_string) == (7, 6) def test_example2(): input_string = "2\n1 8\n8 1" assert parse_input_rectangle(input_string) == (8, 8) def...
[ { "docstring": "Given a list of rectangles represented by their width and height,\nthis function returns the dimensions of the smallest possible enclosing rectangle.", "function_declaration": "def smallest_enclosing_rectangle(rectangles):", "function_name": "smallest_enclosing_rectangle", "parameter...
[ 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 smallest_enclosing_rectangle(rectangles):\n \"\"\"\n Given a list of rectangles' dimensions, find the dimensions of the smallest possible enclosi...
trial_gpt4o_2
{ "original_instruction": "Evelyn loves solving puzzles involving geometric figures. One day, she came across an interesting problem about rectangles and decided to share it with her friends.\n\nA rectangle is defined by its width and height. For each rectangle, we define its area as the product of its width and heig...
0.598161
Code_Contests_46239
C
[ "smallest_enclosing_rectangle", "parse_input_rectangle" ]
2
[ [ "parse_input_rectangle", "smallest_enclosing_rectangle" ] ]
1
[]
false
[]
false
pytest
true
[]
true
21ec83cf72f1a739c9648f950d75760683c6f4c1
c3ffce392ed360cfa0ff753995217aa5686171fd
v1.0
complete
Code_Contests
Code_Contests_46522_C
def heaviest_path(n: int, values: List[int], edges: List[Tuple[int, int]]) -> int: """ Charlotte is a renowned botanist conducting research on a unique species of tree. Each tree consists of nodes connected by branches, forming an acyclic connected graph (or simply a tree). Each node has a value assigned to it....
import sys sys.setrecursionlimit(200000) def get_heaviest_path_sum(node, parent, adj_list, values): max_path_1, max_path_2 = 0, 0 for neighbor in adj_list[node]: if neighbor == parent: continue path_sum = get_heaviest_path_sum(neighbor, node, adj_list, values) if path_sum > ...
def test_heaviest_path_example_1(): assert heaviest_path(3, [1, 2, 3], [(0, 1), (0, 2)]) == 6 def test_heaviest_path_example_2(): assert heaviest_path(5, [1, -2, 3, 4, -1], [(0, 1), (0, 2), (1, 3), (1, 4)]) == 6 def test_heaviest_path_single_node(): assert heaviest_path(1, [1], []) == 1 def test_heaviest...
[ { "docstring": null, "function_declaration": "def get_heaviest_path_sum(node, parent, adj_list, values):", "function_name": "get_heaviest_path_sum", "parameter_list": "(node, parent, adj_list, values)" }, { "docstring": null, "function_declaration": "def heaviest_path(n, values, edges):"...
[ 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 read_input():\n import sys\n input = sys.stdin.read\n data = input().split()\n idx = 0\n \n T = int(data[idx])\n idx += 1\n tes...
trial_gpt4o_4
{ "original_instruction": "Charlotte is a renowned botanist conducting research on a unique species of tree. Each tree consists of nodes connected by branches, forming an acyclic connected graph (or simply a tree). Each node has a value assigned to it. Charlotte is particularly interested in finding the sum of the no...
0.637411
Code_Contests_46522
C
[ "get_heaviest_path_sum", "heaviest_path", "process_test_cases" ]
3
[ [ "heaviest_path", "get_heaviest_path_sum" ], [ "process_test_cases", "heaviest_path" ] ]
2
[ "process_test_cases" ]
false
[]
false
pytest
false
[]
true
b9db01711e549d37acb4e82da290fa858c16bb45
9f4d794fbb64731e3f3592fb9b51031ebb4b1580
v1.0
complete
Code_Contests
Code_Contests_46324_C
def determine_topic(title: str, content: str) -> int: """ Determine the topic of a given article based on its content. There are 5 topics: 1. World 2. Technology 3. Health 4. Sports 5. Entertainment >>> determine_topic("Latest Technology Trends", "With the advancement in AI, the world o...
import os # Dummy function to simulate reading training data def load_training_data(): training_data = { 1: ["world", "global", "international", "country"], 2: ["technology", "tech", "innovation", "AI", "software", "hardware"], 3: ["health", "medicine", "disease", "wellness", "healthcare"],...
from solution import determine_topic def test_technology_article(): title = "Latest Technology Trends" content = "With the advancement in AI, the world of technology is rapidly evolving..." assert determine_topic(title, content) == 2 def test_world_article(): title = "Global News Update" content =...
[ { "docstring": null, "function_declaration": "def load_training_data():", "function_name": "load_training_data", "parameter_list": "()" }, { "docstring": null, "function_declaration": "def determine_topic(title, content):", "function_name": "determine_topic", "parameter_list": "(...
[ 0, 0, 0, 0, 0, 0, 0, 0, 1 ]
1
hard
0.111
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "import os\nimport zipfile\nimport requests\nfrom collections import defaultdict\nfrom sklearn.feature_extraction.text import TfidfVectorizer\nfrom sklearn....
trial_gpt4o_9
{ "original_instruction": "A news website has articles categorized under different topics – World, Technology, Health, Sports, and Entertainment. Each article has a unique identifier, a title, and the content of the article. The topics of the articles are identified by integers from 1 to 5:\n\n1. World\n2. Technology...
0.715893
Code_Contests_46324
C
[ "load_training_data", "determine_topic" ]
2
[ [ "determine_topic", "load_training_data" ] ]
1
[]
false
[]
false
pytest
true
[]
true
e34fdf9b835f309faf357687d807c4d60272d1ed
ff8fd5273da1a7033d799f68037020e0d25074c1
v1.0
complete
Code_Contests
Code_Contests_45436_C
def minimum_cost_to_construct_network(n: int, m: int, pipelines: List[Tuple[int, int, int]]) -> int: """ Determine the minimum cost required to construct a water distribution network. Args: n (int): The number of neighborhoods. m (int): The number of possible pipelines. pipelines (List[Tupl...
def find(parent, i): if parent[i] == i: return i 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[rootX] = rootY elif rank[rootX] > rank[root...
def test_minimum_cost_to_construct_network_case1(): n = 4 m = 5 pipelines = [ (1, 2, 3), (2, 3, 4), (3, 4, 5), (1, 3, 1), (1, 4, 10) ] assert minimum_cost_to_construct_network(n, m, pipelines) == 9 def test_minimum_cost_to_construct_network_case2(): n = 3...
[ { "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": "def find_minimum_cost(n, m, pipelines):\n \"\"\"\n Finds the minimum cost required to construct a water distribution network linking all neighborhood...
trial_gpt4o_2
{ "original_instruction": "A city is planning to develop a new water distribution system to supply water to all its neighborhoods. The system will include pipes connecting the neighborhoods to ensure water from the central water source can reach every neighborhood.\n\nThe city consists of n neighborhoods, numbered fr...
0.580054
Code_Contests_45436
C
[ "find", "union", "kruskal_mst", "minimum_cost_to_construct_network" ]
4
[ [ "kruskal_mst", "find" ], [ "kruskal_mst", "union" ], [ "minimum_cost_to_construct_network", "kruskal_mst" ], [ "union", "find" ] ]
4
[]
false
[]
false
pytest
false
[]
true
decf978ebbcaef34f8bf166758b3765f8c3c022b
4dda262e2fcd3fd15575f6f3ca816ff413963487
v1.0
complete
Code_Contests
Code_Contests_46099_C
def number_of_ways(N: int, K: int, P: int) -> int: """ Determine the number of ways to divide N distinct colors of paint into K groups such that each group contains at least one color. The result is returned modulo a prime number P. >>> number_of_ways(4, 2, 1000000007) 7 >>> number_of_ways(5, 3, 998...
def stirling_second_kind(n, k, p): """ Calculate the Stirling number of the second kind modulo p. """ dp = [[0] * (k + 1) for _ in range(n + 1)] dp[0][0] = 1 for i in range(1, n + 1): for j in range(1, k + 1): dp[i][j] = (dp[i-1][j-1] + j * dp[i-1][j]) % p r...
from solution import number_of_ways def test_number_of_ways_example1(): assert number_of_ways(4, 2, 1000000007) == 7 def test_number_of_ways_example2(): assert number_of_ways(5, 3, 998244353) == 25 def test_number_of_ways_example3(): assert number_of_ways(10, 5, 1000000009) == 42525 def test_number_of_w...
[ { "docstring": "Calculate the Stirling number of the second kind modulo p.", "function_declaration": "def stirling_second_kind(n, k, p):", "function_name": "stirling_second_kind", "parameter_list": "(n, k, p)" }, { "docstring": null, "function_declaration": "def number_of_ways(N, K, P):"...
[ 0, 0, 0, 0, 0, 0, 0, 1, 1 ]
2
hard
0.222
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def count_ways_to_divide_colors(n, k, p):\n \"\"\"\n Returns the number of ways to divide n distinct colors into k groups such that each group contai...
trial_gpt4o_8
{ "original_instruction": "Given two positive integers N and K, determine the number of ways to divide N distinct colors of paint into K groups such that each group contains at least one color. The answer can be very large, so return the result modulo a prime number P.\n\nConstraints:\n- 1 <= N <= 1000\n- 1 <= K <= N...
0.525123
Code_Contests_46099
C
[ "stirling_second_kind", "number_of_ways" ]
2
[ [ "number_of_ways", "stirling_second_kind" ] ]
1
[]
false
[]
false
pytest
true
[]
true
8173086b835fd61724b5a35b4cf27e3a24db5190
e05c40f978f5a5b81db30fc70b66613b38c3ad2a
v1.0
complete
Code_Contests
Code_Contests_45794_C
def validate_sudoku(sudoku_board: List[List[str]]) -> str: """ Check if a given 9x9 Sudoku board is valid. >>> validate_sudoku([ ... ['5', '3', '.', '.', '7', '.', '.', '.', '.'], ... ['6', '.', '.', '1', '9', '5', '.', '.', '.'], ... ['.', '9', '8', '.', '.', '.', '.', '6', '.'], .....
def is_valid_sudoku(board): """ Check if a given 9x9 Sudoku board is valid. :param board: List[List[str]] - A 2D list representing the Sudoku board :return: bool - True if the current state of the board is valid, otherwise False """ # Use sets to keep track of seen numbers in rows, columns ...
from solution import validate_sudoku def test_valid_sudoku(): board = [ ['5', '3', '.', '.', '7', '.', '.', '.', '.'], ['6', '.', '.', '1', '9', '5', '.', '.', '.'], ['.', '9', '8', '.', '.', '.', '.', '6', '.'], ['8', '.', '.', '.', '6', '.', '.', '.', '3'], ['4', '.', '.',...
[ { "docstring": "Check if a given 9x9 Sudoku board is valid.\n\n:param board: List[List[str]] - A 2D list representing the Sudoku board\n:return: bool - True if the current state of the board is valid, otherwise False", "function_declaration": "def is_valid_sudoku(board):", "function_name": "is_valid_sud...
[ 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_valid_sudoku(board):\n \"\"\"\n Validates the current state of the Sudoku board.\n \n Parameters:\n board (List[List[str]]): 9x9 grid...
trial_gpt4o_3
{ "original_instruction": "B: Sudoku Validator\n\nproblem\n\nSudoku is a popular number puzzle consisting of a 9x9 grid divided into nine 3x3 subgrids, where the objective is to fill the grid with digits from 1 to 9. Each digit must appear exactly once in each row, column, and 3x3 subgrid.\n\nGiven a partially filled...
0.540722
Code_Contests_45794
C
[ "is_valid_sudoku", "validate_sudoku" ]
2
[ [ "validate_sudoku", "is_valid_sudoku" ] ]
1
[]
false
[]
false
pytest
true
[]
true
37d1dbd8dabc388f0df0d800dceb063e4ef75329
9d6502f173887c21a5699f03be15efebe5e5afc9
v1.0
complete
Code_Contests
Code_Contests_47026_C
def is_power_of_two(n: int) -> bool: """ Checks if n is a power of two. >>> is_power_of_two(1) True >>> is_power_of_two(16) True >>> is_power_of_two(10) False >>> is_power_of_two(0) False """ pass def check_powers_of_two(nums: List[int]) -> List[str]: """ Takes a...
def is_power_of_two(n): """ Checks if n is a power of two. """ if n <= 0: return False return (n & (n - 1)) == 0 def check_powers_of_two(nums): """ Takes a list of integers and returns a list of results, where each result is "Yes" if the corresponding integer is a power of...
from solution import is_power_of_two, check_powers_of_two def test_is_power_of_two(): assert is_power_of_two(1) == True assert is_power_of_two(16) == True assert is_power_of_two(10) == False assert is_power_of_two(0) == False assert is_power_of_two(-2) == False assert is_power_of_two(1024) == T...
[ { "docstring": "Checks if n is a power of two.", "function_declaration": "def is_power_of_two(n):", "function_name": "is_power_of_two", "parameter_list": "(n)" }, { "docstring": "Takes a list of integers and returns a list of results, \nwhere each result is \"Yes\" if the corresponding integ...
[ 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_power_of_two(n):\n \"\"\"\n Checks if the given integer n is a power of two.\n \"\"\"\n if n <= 0:\n return False\n return (n ...
trial_gpt4o_2
{ "original_instruction": "Given an integer, determine if it is a power of two. Write a program that takes multiple test cases and checks for each case if the number is a power of two.\n\nInput Format\n\nThe first line contains the number of test cases T.\nEach of the next T lines contains one integer N to be checked...
0.749742
Code_Contests_47026
C
[ "is_power_of_two", "check_powers_of_two" ]
2
[ [ "check_powers_of_two", "is_power_of_two" ] ]
1
[]
false
[]
false
pytest
true
[]
true
3c6ff3e3c1ea53982bee71fd8cf43507bdbad974
8f71dd7a67a084c89d8b72bd1494259dedf14404
v1.0
complete
Code_Contests
Code_Contests_46161_C
from typing import List, Tuple from collections import defaultdict, deque def max_path_sum_in_forest(n: int, edges: List[Tuple[int, int, int]]) -> int: """ You are given a forest (an acyclic undirected graph) consisting of n nodes and n - 1 edges. Each edge has a certain weight. Find two such nodes in the for...
from collections import defaultdict, deque def find_farthest_node(start, graph): n = len(graph) distances = [-1] * n distances[start] = 0 max_distance = 0 farthest_node = start queue = deque([start]) while queue: current = queue.popleft() for neighbor, weight in graph[curre...
from solution import max_path_sum_in_forest def test_example_1(): n = 5 edges = [ (1, 2, 3), (2, 3, 4), (3, 4, 2), (3, 5, 1) ] assert max_path_sum_in_forest(n, edges) == 9 def test_example_2(): n = 4 edges = [ (1, 2, 5), (2, 3, 6), (3, 4,...
[ { "docstring": null, "function_declaration": "def find_farthest_node(start, graph):", "function_name": "find_farthest_node", "parameter_list": "(start, graph)" }, { "docstring": null, "function_declaration": "def max_path_sum_in_forest(n, edges):", "function_name": "max_path_sum_in_f...
[ 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 defaultdict, deque\n\ndef find_farthest_node(start, graph):\n n = len(graph)\n distances = [-1] * n\n distances[start] = 0...
trial_gpt4o_0
{ "original_instruction": "You are given a forest (an acyclic undirected graph) consisting of n nodes and n - 1 edges. Each edge has a certain weight. Find two such nodes in the forest that the sum of the weights of the edges in the path between them is maximized. Note that the path between any two nodes in the graph...
0.694207
Code_Contests_46161
C
[ "find_farthest_node", "max_path_sum_in_forest" ]
2
[ [ "max_path_sum_in_forest", "find_farthest_node" ] ]
1
[]
false
[]
false
pytest
true
[]
true
55d8ea18760140da93efa5ae8d9cc599437529d8
afd15bf9ec03b9fbd7b86baa988e3a9f56d66e51
v1.0
complete
Code_Contests
Code_Contests_46952_C
from typing import List def is_palindromic_email(email: str) -> bool: """Check if the local part of the given email address is palindromic. Args: email (str): The email address to check. Returns: bool: True if the local part is palindromic, otherwise False. Examples: >>> is_p...
def is_palindromic_email(email): """ Checks if the local part of the given email address is palindromic. """ local_part = email.split('@')[0] return local_part == local_part[::-1] def check_palindromic_emails(n, emails): """ For each email in emails, prints "YES" if the local part is palind...
from solution import is_palindromic_email, check_palindromic_emails def test_is_palindromic_email(): assert is_palindromic_email("madam@company.com") == True assert is_palindromic_email("racecar@fastmail.com") == True assert is_palindromic_email("hello@world.com") == False assert is_palindromic_email("...
[ { "docstring": "Checks if the local part of the given email address is palindromic.", "function_declaration": "def is_palindromic_email(email):", "function_name": "is_palindromic_email", "parameter_list": "(email)" }, { "docstring": "For each email in emails, prints \"YES\" if the local part...
[ 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_palindromic_email(email):\n \"\"\"\n Checks if the local part of an email address is palindromic.\n \"\"\"\n local_part = email.split('@...
trial_gpt4o_2
{ "original_instruction": "Palindromic Email Addresses\n\nAlice works in the IT department and is responsible for managing email addresses for a large organization. She has recently noticed that some users prefer more \"unique\" email addresses, ones that are palindromic.\n\nA palindromic string reads the same backwa...
0.725985
Code_Contests_46952
C
[ "is_palindromic_email", "check_palindromic_emails" ]
2
[ [ "check_palindromic_emails", "is_palindromic_email" ] ]
1
[]
false
[]
false
pytest
true
[]
true
d2de9d256556945581b5c5c4fc58b539f8d0f0cc
93f6e235020038061e32c6a6e9e2c5e9767d6495
v1.0
complete
Code_Contests
Code_Contests_47194_C
def min_cost_to_connect_sectors(n: int, k: int, paths: List[Tuple[int, int, int]]) -> int: """ Find the optimal way to connect all sectors in a kingdom to minimize the total time cost. >>> min_cost_to_connect_sectors(4, 5, [(1, 2, 1), (2, 3, 2), (3, 4, 3), (1, 4, 6), (2, 4, 5)]) == 6 >>> min_cost_to_connect...
def find(parent, i): if parent[i] == i: return i else: return find(parent, 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[yroot]: parent[yr...
from solution import min_cost_to_connect_sectors def test_case_1(): n = 4 k = 5 paths = [ (1, 2, 1), (2, 3, 2), (3, 4, 3), (1, 4, 6), (2, 4, 5) ] assert min_cost_to_connect_sectors(n, k, paths) == 6 def test_case_2(): n = 5 k = 6 paths = [ ...
[ { "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)" }, ...
[ 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 find(parent, i):\n if parent[i] == i:\n return i\n else:\n return find(parent, parent[i])\n\ndef union(parent, rank, x, y):\n xr...
trial_gpt4o_0
{ "original_instruction": "In a kingdom far away, there lies a magical forest divided into n sectors, each connected with some of k paths. Each path connects two different sectors and has a certain time cost associated with it. The king wants to connect all sectors in a way that the total time cost is minimized and e...
0.590605
Code_Contests_47194
C
[ "find", "union", "min_cost_to_connect_sectors" ]
3
[ [ "min_cost_to_connect_sectors", "find" ], [ "min_cost_to_connect_sectors", "union" ], [ "union", "find" ] ]
3
[]
false
[]
false
pytest
true
[]
true
e6ccdae2bbc07b531da043bd9e0daf3fe58b6008
2f4badd5a607ab3a81e07590e585c7b98d60579d
v1.0
complete
Code_Contests
Code_Contests_47018_C
from typing import List, Tuple def find_tree_positions(t: int, test_cases: List[Tuple[int, int]]) -> List[Tuple[int, int]]: """ For each test case, find valid positions (d1, d2) for the two trees such that they are aligned along the length of the garden with a prime number distance between them. >>> find_...
def is_prime(n): """ Helper function to check if a number is a prime number. """ 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 ...
from solution import find_tree_positions def test_find_tree_positions_single_case(): results = find_tree_positions(1, [(10, 5)]) assert len(results) == 1 d1, d2 = results[0] assert d1 < d2 assert d2 - d1 in {2, 3, 5, 7, 11, 13, 17, 19, 23, 29} def test_find_tree_positions_multiple_cases(): res...
[ { "docstring": "Helper function to check if a number is a prime number.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "For each test case, find valid positions (d1, d2) for the two trees such that they are aligned\nalong ...
[ 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": "import sympy\n\ndef find_tree_positions(l, w):\n \"\"\"\n Finds the positions d1 and d2 for placing two trees such that they are aligned \n along ...
trial_gpt4o_2
{ "original_instruction": "Nina is planning to design a rectangular garden and needs to determine the placement of two trees along one of its sides. She knows the length l and width w of the garden. She wants to place the two trees such that they are aligned along the length of the rectangle, at integer distances d1 ...
0.598309
Code_Contests_47018
C
[ "is_prime", "find_tree_positions" ]
2
[ [ "find_tree_positions", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
ae54408c72a33e898ac339e71a8847036e043937
c311362237aeca5d2b8296d1fc8469d80c572ec2
v1.0
complete
Code_Contests
Code_Contests_46946_C
class TreeNode: def __init__(self, val=0, left=None, right=None): self.val = val self.left = left self.right = right def print_unique_bsts_pre_order(n: int) -> List[List[int]]: """ Given a positive integer n, generate all structurally unique Binary Search Trees (BST) that store values 1...
class TreeNode: def __init__(self, val=0, left=None, right=None): self.val = val self.left = left self.right = right def generate_trees(n): if n == 0: return [] return generate_trees_rec(1, n) def generate_trees_rec(start, end): if start > end: return [None] ...
from solution import print_unique_bsts_pre_order def test_unique_bsts_pre_order(): result = print_unique_bsts_pre_order(3) expected = [ [1, 2, 3], [1, 3, 2], [2, 1, 3], [3, 1, 2], [3, 2, 1] ] assert sorted(result) == sorted(expected) def test_empty_bsts_pre_orde...
[]
[ 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": "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_1
{ "original_instruction": "Given a positive integer n, generate all structurally unique Binary Search Trees (BST) that store values 1 ... n and print the pre-order traversal of each unique BST.\n\nINPUT\nThe first and only line of the input contains a single integer, n.\n\nOUTPUT\nEach line of the output should conta...
0.519792
Code_Contests_46946
C
[ "generate_trees", "generate_trees_rec", "pre_order_traversal", "print_unique_bsts_pre_order" ]
4
[ [ "generate_trees", "generate_trees_rec" ], [ "print_unique_bsts_pre_order", "generate_trees" ], [ "print_unique_bsts_pre_order", "pre_order_traversal" ] ]
3
[]
false
[ "TreeNode" ]
true
pytest
true
[]
true
5449f75317f20410b97b73aac7e0f324037a1e08
0d1a47e791463e014458df40fac4e03b4fb88c99
v1.0
complete
Code_Contests
Code_Contests_47400_C
def is_binary_palindrome(n: int) -> bool: """ Check if a number is a binary palindrome. >>> is_binary_palindrome(0) True >>> is_binary_palindrome(1) True >>> is_binary_palindrome(3) True >>> is_binary_palindrome(5) True >>> is_binary_palindrome(6) False """ def next_binary_palindrome(n:...
def is_binary_palindrome(n): binary_representation = bin(n)[2:] return binary_representation == binary_representation[::-1] def next_binary_palindrome(n): n += 1 while not is_binary_palindrome(n): n += 1 return n
from solution import is_binary_palindrome, next_binary_palindrome def test_is_binary_palindrome(): assert is_binary_palindrome(0) == True assert is_binary_palindrome(1) == True assert is_binary_palindrome(3) == True # binary: 11 assert is_binary_palindrome(5) == True # binary: 101 assert is_binar...
[ { "docstring": null, "function_declaration": "def is_binary_palindrome(n):", "function_name": "is_binary_palindrome", "parameter_list": "(n)" }, { "docstring": null, "function_declaration": "def next_binary_palindrome(n):", "function_name": "next_binary_palindrome", "parameter_li...
[ 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_binary_palindrome(n):\n \"\"\"\n Checks if the given number n is a binary palindrome.\n \"\"\"\n binary_str = bin(n)[2:]\n return bin...
trial_gpt4o_2
{ "original_instruction": "Vasya is fond of binary palindromes. A binary palindrome is a number that reads the same forwards as backwards when written in binary form. For example, 5 (which is 101 in binary) and 9 (which is 1001 in binary) are binary palindromes.\n\nGiven an integer `n`, find the smallest integer grea...
0.675785
Code_Contests_47400
C
[ "is_binary_palindrome", "next_binary_palindrome" ]
2
[ [ "next_binary_palindrome", "is_binary_palindrome" ] ]
1
[]
false
[]
false
pytest
true
[]
true
de57fdc5a739cf0ca785d8ad3c2f02b62108ca48
cc77a01eb843b935adfd1c388b5a10d1966f5ad7
v1.0
complete
Code_Contests
Code_Contests_47333_C
def three_sum(nums, target): """ Returns True if there are three distinct integers in nums that add up to the target. >>> three_sum([1, 2, 3, 4, 5], 9) True >>> three_sum([1, 2, 3, 4, 5], 15) False >>> three_sum([-1, 0, 1, 2, -1, -4], 0) True >>> three_sum([1], 1) False """ def ...
def three_sum(nums, target): """ Returns True if there are three distinct integers in nums that add up to the target. """ nums.sort() n = len(nums) for i in range(n - 2): left, right = i + 1, n - 1 while left < right: s = nums[i] + nums[left] + nums[right] ...
from solution import three_sum, solve def test_three_sum_exists(): assert three_sum([1, 2, 3, 4, 5], 9) == True assert three_sum([-1, 0, 1, 2, -1, -4], 0) == True assert three_sum([0, 0, 0], 0) == True def test_three_sum_not_exists(): assert three_sum([1, 2, 3, 4, 5], 15) == False assert three_sum...
[ { "docstring": "Returns True if there are three distinct integers in nums that add up to the target.", "function_declaration": "def three_sum(nums, target):", "function_name": "three_sum", "parameter_list": "(nums, target)" }, { "docstring": null, "function_declaration": "def solve(input...
[ 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 has_triplet_sum(nums, target):\n \"\"\"\n Returns True if there exist three distinct integers in nums that add up to the target.\n \"\"\"\n ...
trial_gpt4o_2
{ "original_instruction": "You are given a list of integers and a target integer. Your task is to determine if there are three distinct integers in the list that add up to the target integer. Write a function that returns True if such a triplet exists, and False otherwise. \n\nInput\n\nThe input consists of two lines...
0.773275
Code_Contests_47333
C
[ "three_sum", "solve" ]
2
[ [ "solve", "three_sum" ] ]
1
[]
false
[]
false
pytest
true
[]
true
f3aa6808b6b8709dd58cf32e1b51dde7f1ac854d
9ad3e227b6d4643fd2bf449c449ed5ddb5502748
v1.0
complete
Code_Contests
Code_Contests_46686_C
import math def check_valid_triangle(a, b, c): """ Check whether the sides can form a valid triangle. """ return a + b > c and a + c > b and b + c > a def calculate_perimeter(a, b, c): """ Returns the perimeter of the triangle. """ return a + b + c def calculate_area(a, b, c): """...
import math def check_valid_triangle(a, b, c): """ Check whether the sides can form a valid triangle. """ return a + b > c and a + c > b and b + c > a def calculate_perimeter(a, b, c): """ Returns the perimeter of the triangle. """ return a + b + c def calculate_area(a, b, c): """...
from solution import triangle def test_valid_triangle_345(): assert triangle(3, 4, 5) == "12 6" def test_invalid_triangle_11012(): assert triangle(1, 10, 12) == "Invalid" def test_valid_triangle_equilateral(): assert triangle(6, 6, 6) == "18 15.5885" def test_valid_triangle_isosceles(): assert trian...
[ { "docstring": "Check whether the sides can form a valid triangle.", "function_declaration": "def check_valid_triangle(a, b, c):", "function_name": "check_valid_triangle", "parameter_list": "(a, b, c)" }, { "docstring": "Returns the perimeter of the triangle.", "function_declaration": "d...
[ 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": "import math\n\ndef triangle_properties(a, b, c):\n \"\"\"\n Determine whether the sides a, b, and c form a valid triangle.\n If they do, return it...
trial_gpt4o_2
{ "original_instruction": "Write a program that determines whether three given sides can form a valid triangle and if so, calculates its perimeter and area.\n\nConstraints\n\n* 1 ≤ a, b, c ≤ 100\n\nInput\n\nThe lengths a, b, and c of the three sides of the triangle are given in a line separated by single spaces.\n\nO...
0.858574
Code_Contests_46686
C
[ "check_valid_triangle", "calculate_perimeter", "calculate_area", "triangle" ]
4
[ [ "triangle", "calculate_area" ], [ "triangle", "calculate_perimeter" ], [ "triangle", "check_valid_triangle" ] ]
3
[]
false
[]
false
pytest
true
[]
true
46585929d97a3dde4a8afaf0eade142d4f86affc
289b0d37eaa5857672f075b6aade10076b573da8
v1.0
complete
Code_Contests
Code_Contests_47533_C
def encrypt(message: str, shift: int) -> str: """ Encrypt the message by shifting each alphabetical character by a fixed number of positions. >>> encrypt("Hello World", 3) 'Khoor Zruog' >>> encrypt("Python", 7) 'Wavvym' """ pass def decrypt(encrypted_message: str, shift: int) -> str: ""...
def encrypt(message, shift): encrypted_message = [] for char in message: if char.isalpha(): if char.islower(): encrypted_message.append(chr((ord(char) - ord('a') + shift) % 26 + ord('a'))) elif char.isupper(): encrypted_message.append(chr((ord(char...
from solution import encrypt, decrypt def test_encrypt_simple_case(): assert encrypt("Hello World", 3) == "Khoor Zruog" def test_decrypt_simple_case(): assert decrypt("Khoor Zruog", 3) == "Hello World" def test_encrypt_with_wrap_around(): assert encrypt("xyz", 3) == "abc" def test_decrypt_with_wrap_arou...
[ { "docstring": null, "function_declaration": "def encrypt(message, shift):", "function_name": "encrypt", "parameter_list": "(message, shift)" }, { "docstring": null, "function_declaration": "def decrypt(encrypted_message, shift):", "function_name": "decrypt", "parameter_list": "(...
[ 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 encrypt(message, key):\n encrypted_message = []\n for char in message:\n if char.islower():\n encrypted_message.append(chr((ord...
trial_gpt4o_9
{ "original_instruction": "A software company is developing a new messaging application. As a part of the different features, they want to incorporate an encryption mechanism to secure the messages. The encryption algorithm they intend to use involves shifting each character in the message alphabetically by a fixed n...
0.789585
Code_Contests_47533
C
[ "encrypt", "decrypt" ]
2
[ [ "decrypt", "encrypt" ] ]
1
[]
false
[]
false
pytest
true
[]
true
1058dad9a28f8701d6fdff6b9307d374373b1c72
e49418f1bb7e819ff7538542c18cc02823315066
v1.0
complete
Code_Contests
Code_Contests_47550_C
def is_prime(n: int) -> bool: """ Check if a given number is a prime number. >>> is_prime(2) True >>> is_prime(4) False >>> is_prime(5) True >>> is_prime(25) False """ def longest_prime_subarray_length(N: int, houses: List[int]) -> int: """ Find the length of the longest contiguous subarray...
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 longest_prime_subarray_length(N, houses): ...
from solution import is_prime, longest_prime_subarray_length 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(25) == False assert is_prime(1) == False def test_longest_prime_subarray_length(): ...
[ { "docstring": null, "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": null, "function_declaration": "def longest_prime_subarray_length(N, houses):", "function_name": "longest_prime_subarray_length", "parameter_list...
[ 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_prime(n):\n \"\"\"\n Check if a number is prime.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n ret...
trial_gpt4o_1
{ "original_instruction": "In the land of Arithma, there are N houses arranged in a straight line, each owned by a wizard. Each wizard has a certain amount of magical power associated with their house. The wizards want to form the most powerful alliance by combining the magical power of contiguous houses. However, th...
0.620502
Code_Contests_47550
C
[ "is_prime", "longest_prime_subarray_length" ]
2
[ [ "longest_prime_subarray_length", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
24df1d86431ce27fc6e513a36b8851226500bf22
b1f2311dea481cff6b9d851c14e9cc93017f0ca6
v1.0
complete
Code_Contests
Code_Contests_47372_C
def garden_pathways(inputs): """ Calculate the minimum possible sum of the pathway lengths that can be constructed to connect all plots. >>> garden_pathways([(3, 3), (1, 2, 1), (2, 3, 2), (1, 3, 3), (0, 0)]) [3] >>> garden_pathways([(4, 2), (1, 2, 5), (3, 4, 7), (0, 0)]) [-1] >>> ...
def find(parent, i): if parent[i] == i: return i else: return find(parent, 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[yroot]: parent[yr...
from solution import garden_pathways def test_single_dataset_connected(): inputs = [ (3, 3), (1, 2, 1), (2, 3, 2), (1, 3, 3), (0, 0) ] result = garden_pathways(inputs) assert result == [3] def test_single_dataset_not_connected(): inputs = [ (4, 2), (1, 2, 5), (3, 4, 7), ...
[ { "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)" }, ...
[ 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 find(parent, i):\n if parent[i] == i:\n return i\n else:\n return find(parent, parent[i])\n\ndef union(parent, rank, x, y):\n xr...
trial_gpt4o_0
{ "original_instruction": "<!--\n\nProblem D\n\n-->\n\nGarden Pathways\n\nYou are working on a project to design an efficient network of pathways to connect a series of garden plots in a public park. Each plot can be seen as a node in a graph, and the pathways connecting them are the edges. To make the paths easily n...
0.618023
Code_Contests_47372
C
[ "find", "union", "kruskal_mst", "garden_pathways" ]
4
[ [ "garden_pathways", "kruskal_mst" ], [ "kruskal_mst", "find" ], [ "kruskal_mst", "union" ], [ "union", "find" ] ]
4
[]
false
[]
false
pytest
true
[]
true
6fc9982cac86dd75b1c47b016409f77143ef1719
8e5c609c16dcf3ccbc77f9db0099b9f49890d590
v1.0
complete
Code_Contests
Code_Contests_46142_C
def minimum_bipartite_spanning_tree(n: int, m: int, edges: List[Tuple[int, int, int]]) -> int: """Given an undirected graph with `n` vertices and `m` edges, where each edge has a positive weight, find the minimum possible weight of a spanning tree that can be formed using some (or all) of the edges of the...
class UnionFind: def __init__(self, n): self.parent = list(range(n)) self.rank = [0] * n def find(self, u): if self.parent[u] != u: self.parent[u] = self.find(self.parent[u]) return self.parent[u] def union(self, u, v): root_u = self.find(u) root...
def test_minimum_bipartite_spanning_tree(): assert minimum_bipartite_spanning_tree(5, 6, [(1-1, 2-1, 3), (1-1, 3-1, 4), (2-1, 3-1, 2), (2-1, 4-1, 5), (3-1, 5-1, 1), (4-1, 5-1, 6)]) == 11 assert minimum_bipartite_spanning_tree(3, 2, [(1-1, 2-1, 1), (2-1, 3-1, 2)]) == 3 assert minimum_bipartite_span...
[]
[ 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 UnionFind:\n def __init__(self, n):\n self.parent = list(range(n))\n self.rank = [1] * n\n\n def find(self, u):\n if u != ...
trial_gpt4o_4
{ "original_instruction": "Given an undirected graph with `n` vertices and `m` edges, where each edge has a positive weight, find the minimum possible weight of a spanning tree that can be formed using some (or all) of the edges of the initial graph, under the constraint that this spanning tree must be bipartite.\n\n...
0.674938
Code_Contests_46142
C
[ "is_bipartite_dfs", "kruskal_min_bipartite_spanning_tree", "minimum_bipartite_spanning_tree" ]
3
[ [ "kruskal_min_bipartite_spanning_tree", "is_bipartite_dfs" ], [ "minimum_bipartite_spanning_tree", "kruskal_min_bipartite_spanning_tree" ] ]
2
[]
false
[ "UnionFind" ]
true
pytest
false
[]
true
a7223f223a2b27c71a464527ed5972a526ce5475
a9ebb95474fffb84313153a079d60d1752e92a47
v1.0
complete
Code_Contests
Code_Contests_47075_C
class TreeNode: def __init__(self, key): self.left = None self.right = None self.val = key def insert(root, key): """Inserts a new node with the given key into the BST.""" pass def find_height(root): """Finds the height of the BST. >>> find_height(TreeNode(10)) 0 >>...
class TreeNode: def __init__(self, key): self.left = None self.right = None self.val = key def insert(root, key): if root is None: return TreeNode(key) else: if root.val < key: root.right = insert(root.right, key) else: root.left = ins...
from solution import TreeNode, insert, find_height, process_input def test_insert_and_height(): root = None for val in [5, 3, 8, 1, 4, 7]: root = insert(root, val) assert find_height(root) == 2 root = None for val in [2, 1, 3]: root = insert(root, val) assert find_height(ro...
[]
[ 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, key):\n self.left = None\n self.right = None\n self.val = key\n\ndef insert(root, key):\n \...
trial_gpt4o_2
{ "original_instruction": "Sara is learning about trees in data structures. She came across the concept of Binary Search Trees (BST) and is fascinated by their properties, such as how they allow for efficient searching, insertion, and deletion. She decides to write a program that can help her visualize the process of...
0.52321
Code_Contests_47075
C
[ "insert", "find_height", "process_input" ]
3
[ [ "process_input", "find_height" ], [ "process_input", "insert" ] ]
2
[ "process_input" ]
false
[ "TreeNode" ]
true
pytest
true
[]
true
66028e3a68910ceebb375185e7492c72212c86ad
3a16c865244fce37631a6800a1981d201ea72ddf
v1.0
complete
Code_Contests
Code_Contests_47381_C
import math from typing import List, Tuple def is_prime(num: int) -> bool: """ Check if a number is a prime. >>> is_prime(2) == True >>> is_prime(3) == True >>> is_prime(4) == False >>> is_prime(11) == True """ pass def is_perfect_square(num: int) -> bool: """ Check if a number...
import math def is_prime(num): """ Check if a number is a prime. """ if num <= 1: return False if num == 2: return True if num % 2 == 0: return False for i in range(3, int(math.sqrt(num)) + 1, 2): if num % i == 0: return False return True def...
from solution import is_prime, is_perfect_square, count_prime_and_squares def test_is_prime(): assert is_prime(2) == True assert is_prime(3) == True assert is_prime(4) == False assert is_prime(11) == True assert is_prime(21) == False assert is_prime(47) == True def test_is_perfect_square(): ...
[ { "docstring": "Check if a number is a prime.", "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": "Check if a number is a perfect square.", "function_declaration": "def is_perfect_square(num):", "function_name": "is...
[ 0, 0, 0, 0, 0, 0, 0, 1, 0, 1 ]
2
hard
0.2
{ "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(num):\n if num <= 1:\n return False\n if num == 2:\n return True\n if num % 2 == 0:\n return Fals...
trial_gpt4o_9
{ "original_instruction": "Tara loves number theory, and she particularly enjoys working with special sequences of numbers. Today, she came across a sequence where each element is either a prime number or a perfect square. She wants to know how many prime numbers are in the sequence and how many perfect squares are i...
0.70405
Code_Contests_47381
C
[ "is_prime", "is_perfect_square", "count_prime_and_squares" ]
3
[ [ "count_prime_and_squares", "is_perfect_square" ], [ "count_prime_and_squares", "is_prime" ] ]
2
[]
false
[]
false
pytest
true
[]
true
112f4207a78dc5f2322d495105f4822fe3669ccd
3f111e81481c0949b50a91216e8105a45a18ca74
v1.0
complete
Code_Contests
Code_Contests_47334_C
from collections import deque from typing import List def is_one_letter_diff(word1: str, word2: str) -> bool: """ Check if two words differ by exactly one letter. """ # Your code here def transform_word(initial: str, target: str, word_list: List[str]) -> int: """ Returns the minimum number of ...
from collections import deque def is_one_letter_diff(word1, word2): """ Check if two words differ by exactly one letter. """ if len(word1) != len(word2): return False count_diff = 0 for a, b in zip(word1, word2): if a != b: count_diff += 1 if count_diff >...
from solution import is_one_letter_diff, transform_word def test_is_one_letter_diff(): assert is_one_letter_diff("hit", "hot") == True assert is_one_letter_diff("hot", "dot") == True assert is_one_letter_diff("hit", "dot") == False assert is_one_letter_diff("hit", "hits") == False def test_transform_w...
[ { "docstring": "Check if two words differ by exactly one letter.", "function_declaration": "def is_one_letter_diff(word1, word2):", "function_name": "is_one_letter_diff", "parameter_list": "(word1, word2)" }, { "docstring": "Returns the minimum number of transformations required to change th...
[ 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 get_neighbors(word, word_set):\n neighbors = []\n for i in range(len(word)):\n for c in 'abcdefghijklmnop...
trial_gpt4o_2
{ "original_instruction": "In a mystical forest, there are N magical creatures living in harmony. These creatures communicate using a special language where words are linked if they differ by exactly one letter. For example, \"hat\" and \"hot\" can communicate with each other, but \"hat\" and \"hit\" cannot because t...
0.645249
Code_Contests_47334
C
[ "is_one_letter_diff", "transform_word" ]
2
[ [ "transform_word", "is_one_letter_diff" ] ]
1
[]
false
[]
false
pytest
true
[]
true
0948e9abac17553ea47f88296ac84e4c01602390
8486c5fa99d6de19974e0cda588d0ee37e48d032
v1.0
complete
Code_Contests
Code_Contests_47698_C
from typing import List def max_score_stones(stones: List[int]) -> int: """ Determine the maximum possible score Alex can achieve if both players play optimally. >>> max_score_stones([4, 7, 2, 3]) 10 >>> max_score_stones([2, 2, 10]) 12 """ def maximum_scores_for_cases(test_cases: List[List...
def max_score_stones(stones): n = len(stones) if n == 0: return 0 # dp[i][j] will be the maximum score the player can achieve from stones[i] to stones[j] dp = [[0] * n for _ in range(n)] for size in range(1, n + 1): # size is the length of the subproblem we are solving for...
from solution import parse_input_and_get_results def test_single_case(): input_str = "1\n4\n4 7 2 3\n" expected_output = "10" assert parse_input_and_get_results(input_str) == expected_output def test_multiple_cases(): input_str = "2\n4\n4 7 2 3\n3\n2 2 10\n" expected_output = "10\n12" assert p...
[ { "docstring": null, "function_declaration": "def max_score_stones(stones):", "function_name": "max_score_stones", "parameter_list": "(stones)" }, { "docstring": null, "function_declaration": "def maximum_scores_for_cases(test_cases):", "function_name": "maximum_scores_for_cases", ...
[ 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_score(stones):\n def helper(i, j):\n if i > j:\n return 0\n if memo[i][j] != -1:\n return memo[i][j]\n ...
trial_gpt4o_3
{ "original_instruction": "Alex and Bob are playing a game involving a row of stones. Each stone has a positive integer value written on it. Alex and Bob take turns picking up a stone from either end of the row. Alex goes first, and both players aim to maximize the sum of the stones they pick up.\n\nDesign an algorit...
0.653449
Code_Contests_47698
C
[ "max_score_stones", "maximum_scores_for_cases", "parse_input_and_get_results" ]
3
[ [ "maximum_scores_for_cases", "max_score_stones" ], [ "parse_input_and_get_results", "maximum_scores_for_cases" ] ]
2
[ "parse_input_and_get_results" ]
false
[]
false
pytest
true
[]
true
3ed34abdd579c86c8079884a876dafd40f60ef87
165cc5f1b5b2c6ded9ecb118b8ca173c1adb8875
v1.0
complete
Code_Contests
Code_Contests_47679_C
def conference_room_booker(input_data: str) -> List[str]: """ Given the number of participants and required facilities, provide a list of available conference rooms that can accommodate the meeting. Args: input_data: str : Multiline input containing room information and booking requests. Retur...
def find_available_rooms(rooms, booking_requests): result = [] for request in booking_requests: num_participants, required_facilities = request available_rooms = [] for room in rooms: room_id, capacity, facilities = room if capacity >= num_participants and all(f...
from solution import conference_room_booker def test_sample_input(): input_data = """4 101 10 projector whiteboard; 102 20 projector teleconference whiteboard video; 103 15 teleconference projector; 104 25 video; 3 8 projector; 12 projector teleconference; 30 video projector; """ expected_output = ["101 102 10...
[ { "docstring": null, "function_declaration": "def find_available_rooms(rooms, booking_requests):", "function_name": "find_available_rooms", "parameter_list": "(rooms, booking_requests)" }, { "docstring": null, "function_declaration": "def process_input(input_data):", "function_name":...
[ 0, 0, 0, 0, 0, 0, 1, 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_suitable_rooms(n, room_data, m, booking_requests):\n rooms = []\n for i in range(n):\n room = room_data[i].split()\n room_id =...
trial_gpt4o_6
{ "original_instruction": "A large company has a number of conference rooms in different buildings. Each conference room has a unique identifier, a capacity, and a list of facilities it offers, such as a projector, whiteboard, or video conferencing. Employees can book these conference rooms for meetings.\n\nYou are a...
0.54205
Code_Contests_47679
C
[ "find_available_rooms", "process_input", "conference_room_booker" ]
3
[ [ "conference_room_booker", "find_available_rooms" ], [ "conference_room_booker", "process_input" ] ]
2
[ "process_input" ]
false
[]
false
pytest
true
[]
true
3a3ace7672e4fbf5f72c3b68135b6683afaa4a73
b8fbd844d15e048f6debd3c4781d46d9c26d2f30
v1.0
complete
Code_Contests
Code_Contests_47911_C
def gcd_and_lcm(a: int, b: int) -> Tuple[int, int]: """ Compute the GCD and LCM of two numbers. >>> gcd_and_lcm(15, 20) (5, 60) >>> gcd_and_lcm(27, 36) (9, 108) """
def gcd(a, b): """ Compute the Greatest Common Divisor of a and b. """ while b: a, b = b, a % b return a def lcm(a, b, gcd_val): """ Compute the Least Common Multiple of a and b using their GCD. """ return a * b // gcd_val def gcd_and_lcm(a, b): """ Compute both the...
from solution import gcd_and_lcm def test_gcd_lcm_case_1(): assert gcd_and_lcm(15, 20) == (5, 60) def test_gcd_lcm_case_2(): assert gcd_and_lcm(27, 36) == (9, 108) def test_gcd_lcm_case_3(): assert gcd_and_lcm(1, 1) == (1, 1) def test_gcd_lcm_case_4(): assert gcd_and_lcm(2, 3) == (1, 6) def test_gc...
[ { "docstring": "Compute the Greatest Common Divisor of a and b.", "function_declaration": "def gcd(a, b):", "function_name": "gcd", "parameter_list": "(a, b)" }, { "docstring": "Compute the Least Common Multiple of a and b using their GCD.", "function_declaration": "def lcm(a, b, gcd_val...
[ 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 gcd(a, b):\n \"\"\"\n Returns the greatest common divisor of a and b.\n Uses the Euclidean algorithm.\n \"\"\"\n while b:\n a, b ...
trial_gpt4o_2
{ "original_instruction": "The GCD (Greatest Common Divisor) and LCM (Least Common Multiple) are fundamental concepts in number theory. Given two numbers, find both their GCD and LCM.\n\nInput\n\nThe input consists of a single line containing two integers a and b (1 ≤ a, b ≤ 10^9).\n\nOutput\n\nPrint two integers, th...
0.812644
Code_Contests_47911
C
[ "gcd", "lcm", "gcd_and_lcm" ]
3
[ [ "gcd_and_lcm", "gcd" ], [ "gcd_and_lcm", "lcm" ] ]
2
[]
false
[]
false
pytest
true
[]
true
606149432233d3c5580c6c8631aa3ca16f0c8baa
de57d4eb63ff1afc29d77c59f6d89c5bafafdeb8
v1.0
complete
Code_Contests
Code_Contests_47806_C
def read_pyramid(input_lines): """ Reads a list of strings representing the rows of a pyramid, where each string contains comma-separated integers. Returns a 2D list representing the pyramid. """ pass def maximum_path_sum(pyramid): """ Takes a 2D list representing a pyramid of integers and...
def read_pyramid(input_lines): """ Reads a list of strings representing the rows of a pyramid, where each string contains comma-separated integers. Returns a 2D list representing the pyramid. """ pyramid = [list(map(int, line.split(','))) for line in input_lines] return pyramid def maximum_pat...
import pytest from solution import read_pyramid, maximum_path_sum, max_path_sum_from_top_to_bottom def test_read_pyramid(): input_lines = ["3", "7,4", "2,4,6", "8,5,9,3"] expected_output = [[3], [7, 4], [2, 4, 6], [8, 5, 9, 3]] assert read_pyramid(input_lines) == expected_output def test_maximum_path_sum(...
[ { "docstring": "Reads a list of strings representing the rows of a pyramid, where each string \ncontains comma-separated integers. Returns a 2D list representing the pyramid.", "function_declaration": "def read_pyramid(input_lines):", "function_name": "read_pyramid", "parameter_list": "(input_lines)...
[ 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 read_pyramid(input_lines):\n \"\"\"\n Reads a list of strings representing the rows of a pyramid, where each string \n contains comma-separate...
trial_gpt4o_0
{ "original_instruction": "Design a function to read a sequence of comma-separated integers representing a pyramid (triangle) structure, where each row of the pyramid has one more integer than the previous row. Then, calculate the maximum path sum from the top to the bottom of the pyramid, where at each step, you can...
0.616257
Code_Contests_47806
C
[ "read_pyramid", "maximum_path_sum", "max_path_sum_from_top_to_bottom" ]
3
[ [ "max_path_sum_from_top_to_bottom", "maximum_path_sum" ], [ "max_path_sum_from_top_to_bottom", "read_pyramid" ] ]
2
[]
false
[]
false
pytest
true
[]
true
ced01a1970e0fbc1abffd16ff88f94c58cbd54a7
a2a8d373a621ecb61b1ed9b2e4a2b316433e23cb
v1.0
complete
Code_Contests
Code_Contests_47486_C
def is_subgrid_palindromic(grid: List[str], start_row: int, start_col: int, size: int) -> bool: """ Check if a subgrid of a given size is palindromic. :param grid: The grid of lowercase letters. :param start_row: The starting row index of the subgrid. :param start_col: The starting column index of the s...
def is_subgrid_palindromic(grid, start_row, start_col, size): subgrid = [grid[i][start_col:start_col + size] for i in range(start_row, start_row + size)] for i in range(size): # Check row-wise palindrome if subgrid[i] != subgrid[i][::-1]: return False # Check column-wise pali...
def test_is_subgrid_palindromic(): grid1 = ["aba", "bab", "aba"] assert is_subgrid_palindromic(grid1, 0, 0, 3) grid2 = ["abcd", "efgh", "ijkl", "mnop"] assert not is_subgrid_palindromic(grid2, 0, 0, 2) grid3 = ["ababa", "bacab", "ababa", "bacab", "ababa"] assert is_subgrid_palindromic(...
[ { "docstring": null, "function_declaration": "def is_subgrid_palindromic(grid, start_row, start_col, size):", "function_name": "is_subgrid_palindromic", "parameter_list": "(grid, start_row, start_col, size)" }, { "docstring": null, "function_declaration": "def largest_palindromic_subgrid...
[ 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_subgrid_palindromic(grid, start_row, start_col, size):\n subgrid = [grid[i][start_col:start_col + size] for i in range(start_row, start_row + siz...
trial_gpt4o_0
{ "original_instruction": "You are given a grid of size n x n, where each cell contains a single lowercase letter. You need to find the largest possible palindromic subgrid contained within this grid. A subgrid is a contiguous block of cells within the grid, and a palindrome reads the same forwards and backwards both...
0.683452
Code_Contests_47486
C
[ "is_subgrid_palindromic", "largest_palindromic_subgrid", "process_input" ]
3
[ [ "largest_palindromic_subgrid", "is_subgrid_palindromic" ] ]
1
[ "process_input" ]
false
[]
false
pytest
false
[]
true
3736f3b6466fd04960d0cc21910bcdb3a95506e3
75e79465109f5ea0f1b169aa9a3af3de6ea7a1cc
v1.0
complete
Code_Contests
Code_Contests_47687_C
def is_prime(num): """ Returns True if the number is prime, otherwise False. """ pass def count_prime_fibonacci(N): """ Returns the number of prime fibonacci numbers up to and including the N-th fibonacci number. """ pass if __name__ == "__main__": import pytest def test_is_pr...
def is_prime(num): """ Returns True if the number is prime, otherwise False. """ 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: r...
import pytest from solution import is_prime, count_prime_fibonacci 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(18) == False assert is_prime(19) == True assert is_prime(0) == False asse...
[ { "docstring": "Returns True if the number is prime, otherwise False.", "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": "Returns the number of prime fibonacci numbers up to and including the N-th fibonacci number.", "...
[ 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 is_prime(num):\n \"\"\"\n Check if a number is a prime number.\n \"\"\"\n if num < 2:\n return False\n for i in range(2, int(num ...
trial_gpt4o_7
{ "original_instruction": "Vasya is fond of playing with numbers, and one day he came across an interesting sequence known as a \"fibonacci\". The sequence starts with two 1s, and each subsequent number in the sequence is the sum of the two preceding ones.\n\nThe first ten elements of the fibonacci sequence are:\n1, ...
0.823503
Code_Contests_47687
C
[ "is_prime", "count_prime_fibonacci" ]
2
[ [ "count_prime_fibonacci", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
bd131f6c568bc3311a05b5957c24ffa2074d0021
29fc81e74c82d592a383f14ceffa419050d7363c
v1.0
complete
Code_Contests
Code_Contests_47668_C
def max_rectangle_area(grid): """ Given a grid of size N x M filled with zeros and ones, this function returns the area of the largest rectangular subgrid consisting entirely of ones. """ pass def test_max_rectangle_area_1(): grid = [ "11001", "11011", "11111", "...
def max_rectangle_area(grid): """ Given a grid of size N x M filled with zeros and ones, this function returns the area of the largest rectangular subgrid consisting entirely of ones. """ if not grid or not grid[0]: return 0 n, m = len(grid), len(grid[0]) max_area = 0 height...
def test_max_rectangle_area_1(): grid = [ "11001", "11011", "11111", "00011" ] assert max_rectangle_area(grid) == 6 def test_max_rectangle_area_2(): grid = [ "000", "000", "000" ] assert max_rectangle_area(grid) == 0 def test_max_rectangl...
[ { "docstring": "Given a grid of size N x M filled with zeros and ones, this function returns the area of the largest\nrectangular subgrid consisting entirely of ones.", "function_declaration": "def max_rectangle_area(grid):", "function_name": "max_rectangle_area", "parameter_list": "(grid)" }, {...
[ 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 max_rectangle_area(grid):\n \"\"\"\n Given a grid of size N x M filled with zeros and ones, this function returns the area of the largest\n re...
trial_gpt4o_0
{ "original_instruction": "You are given a grid of size N x M filled with zeros and ones. Your task is to find the largest rectangular subgrid consisting entirely of ones.\n\nInput\n- The first line contains two integers, N (1 ≤ N ≤ 500) and M (1 ≤ M ≤ 500), representing the grid dimensions.\n- The next N lines each ...
0.672939
Code_Contests_47668
C
[ "max_rectangle_area", "largest_rectangle_histogram" ]
2
[ [ "max_rectangle_area", "largest_rectangle_histogram" ] ]
1
[]
false
[]
false
pytest
false
[]
true
335b09931e9a9ff4680cd4409b5b01860a1c423e
3304d9fd8fa0e29e0a6937bfb317f7b98f85f449
v1.0
complete
Code_Contests
Code_Contests_46938_C
def shortest_reliable_path(n: int, m: int, k: int, roads: List[Tuple[int, int, int, int]], s: int, e: int) -> int: """ Calculate the shortest travel time of a reliable path from s to e in a city. Args: n (int): Number of intersections. m (int): Number of roads. k (int): Reliability threshold. ...
import heapq def dijkstra(n, roads, k, start, end): graph = {i: [] for i in range(1, n + 1)} for u, v, t, r in roads: if r >= k: graph[u].append((v, t)) graph[v].append((u, t)) queue = [(0, start)] distances = {i: float('inf') for i in range(1, n + 1)} distances[sta...
def test_shortest_reliable_path(): # Test Case 1 n = 4 m = 4 k = 50 roads = [ (1, 2, 10, 60), (2, 3, 20, 70), (3, 4, 30, 80), (1, 3, 40, 30), ] s = 1 e = 4 assert shortest_reliable_path(n, m, k, roads, s, e) == 60 # Test Case 2 n = 3 m = 3...
[ { "docstring": null, "function_declaration": "def dijkstra(n, roads, k, start, end):", "function_name": "dijkstra", "parameter_list": "(n, roads, k, start, end)" }, { "docstring": null, "function_declaration": "def shortest_reliable_path(n, m, k, roads, s, e):", "function_name": "sho...
[ 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 heapq\n\ndef shortest_reliable_path(n, m, k, roads, s, e):\n graph = {i: [] for i in range(1, n + 1)}\n for u, v, t, r in roads:\n if r...
trial_gpt4o_1
{ "original_instruction": "You have been tasked to design a new navigation system for a city. The city has several intersections connected by roads, where each road has a specified travel time. However, due to recent construction, some roads have become unreliable, and you need to determine the most reliable path bet...
0.685431
Code_Contests_46938
C
[ "dijkstra", "shortest_reliable_path" ]
2
[ [ "shortest_reliable_path", "dijkstra" ] ]
1
[]
false
[]
false
pytest
false
[]
true
3efefc586e5e20f1d5b01c536da5dcbc09f58f39
670f08400f8035e8ba80c39a95cd8984b8ca7f93
v1.0
complete
Code_Contests
Code_Contests_47598_C
import math from typing import List, Tuple def is_perfect_square(x: int) -> bool: """Check if a given number is a perfect square""" ... def hasPerfectSquareTriplet(arr: List[int]) -> bool: """Determine if there exists a triplet (i, j, k) with 0 ≤ i < j < k < n such that arr[i] * arr[j] * arr[k] is a p...
import math def is_perfect_square(x): if x < 0: return False root = int(math.isqrt(x)) return root * root == x def hasPerfectSquareTriplet(arr): n = len(arr) for i in range(n): for j in range(i + 1, n): for k in range(j + 1, n): product = arr[i] * arr[j]...
from solution import is_perfect_square, hasPerfectSquareTriplet, process_test_cases def test_is_perfect_square(): assert is_perfect_square(4) == True assert is_perfect_square(16) == True assert is_perfect_square(25) == True assert is_perfect_square(-1) == False assert is_perfect_square(10) == False...
[ { "docstring": null, "function_declaration": "def is_perfect_square(x):", "function_name": "is_perfect_square", "parameter_list": "(x)" }, { "docstring": null, "function_declaration": "def hasPerfectSquareTriplet(arr):", "function_name": "hasPerfectSquareTriplet", "parameter_list...
[ 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": "import math\n\ndef hasPerfectSquareTriplet(arr):\n n = len(arr)\n for i in range(n):\n for j in range(i+1, n):\n for k in range(j+1...
trial_gpt4o_2
{ "original_instruction": "Given an array of integers, you are to determine whether there exists a triplet (i, j, k) with 0 ≤ i < j < k < n such that arr[i] * arr[j] * arr[k] is a perfect square.\n\nA perfect square is an integer that is the square of another integer. For example, 1, 4, 9, 16, and 25 are perfect squa...
0.602839
Code_Contests_47598
C
[ "is_perfect_square", "hasPerfectSquareTriplet", "process_test_cases" ]
3
[ [ "hasPerfectSquareTriplet", "is_perfect_square" ], [ "process_test_cases", "hasPerfectSquareTriplet" ] ]
2
[ "process_test_cases" ]
false
[]
false
pytest
true
[]
true
2efcda538b435c5f6cc0c989ea2a853fd9c05664
9cb44e231a7d3040e3a3feceaf11d68f0dfb7458
v1.0
complete
Code_Contests
Code_Contests_48062_C
def shortest_path(maze, n, m, sx, sy, dx, dy): """ Determine the length of the shortest path from a starting cell to a destination cell in a maze. >>> maze = [ ... ".....", ... ".###.", ... "..#..", ... ".###.", ... "....." ... ] >>> n, m = 5, 5 >>> sx, sy, dx, dy = 0, 0, 4, 4 ...
from collections import deque def shortest_path(maze, n, m, sx, sy, dx, dy): # Directions for movement: right, down, left, up directions = [(0, 1), (1, 0), (0, -1), (-1, 0)] # BFS initialization queue = deque([(sx, sy, 0)]) # queue holds tuples of (current_x, current_y, steps_taken) visited = ...
import pytest from solution import solve, parse_input def test_shortest_path(): input_list = [ "2", "5 5", ".....", ".###.", "..#..", ".###.", ".....", "0 0 4 4", "3 3", "..#", "#.#", "..#", "0 0 2 2" ] ...
[ { "docstring": null, "function_declaration": "def shortest_path(maze, n, m, sx, sy, dx, dy):", "function_name": "shortest_path", "parameter_list": "(maze, n, m, sx, sy, dx, dy)" }, { "docstring": null, "function_declaration": "def solve(mazes):", "function_name": "solve", "parame...
[ 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 shortest_path(grid, start, end):\n n = len(grid)\n m = len(grid[0])\n sx, sy = start\n dx, dy = end\n \...
trial_gpt4o_2
{ "original_instruction": "Sophia enjoys playing a computer game in which she must navigate a character through a maze. The maze is represented by a grid, where some cells contain obstacles and others are free paths. Sophia can move her character up, down, left, or right, but can't move diagonally or through obstacle...
0.585751
Code_Contests_48062
C
[ "shortest_path", "solve", "parse_input" ]
3
[ [ "solve", "shortest_path" ] ]
1
[ "parse_input" ]
false
[]
false
pytest
true
[]
true
8fc4d95978370ad8d177c78b75ec5baf6ea54ded
67d83c8ec55ec09000047f07cc2e29768807a51a
v1.0
complete
Code_Contests
Code_Contests_47635_C
def is_magic_square(subgrid): """ Check if the 3x3 subgrid is a magic square. >>> is_magic_square([[8, 1, 6], [3, 5, 7], [4, 9, 2]]) True >>> is_magic_square([[1, 2, 3], [4, 5, 6], [7, 8, 9]]) False """ pass def contains_magic_square(grid): """ Check if there is any 3x3 magic ...
def is_magic_square(subgrid): """ Check if the 3x3 subgrid is a magic square. """ target_sum = sum(subgrid[0]) # Check rows and columns for i in range(3): if sum(subgrid[i]) != target_sum or sum(row[i] for row in subgrid) != target_sum: return False # Check diagonal...
from solution import contains_magic_square, parse_grid def test_contains_magic_square_1(): input_string = "1 2 3 4 5\n5 6 7 8 9\n9 10 11 12 13\n13 14 15 16 17\n17 18 19 20 21" grid = parse_grid(input_string) assert contains_magic_square(grid) == "NO" def test_contains_magic_square_2(): input_string = ...
[ { "docstring": "Check if the 3x3 subgrid is a magic square.", "function_declaration": "def is_magic_square(subgrid):", "function_name": "is_magic_square", "parameter_list": "(subgrid)" }, { "docstring": "Check if there is any 3x3 magic square in the 5x5 grid.", "function_declaration": "d...
[ 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_magic_square_3x3(grid, x, y):\n # Extract the 3x3 subgrid starting at (x, y)\n subgrid = [grid[x+i][y:y+3] for i in range(3)]\n \n # Cal...
trial_gpt4o_1
{ "original_instruction": "In the land of Dracovania, there is a game of magic squares that many inhabitants enjoy. The game involves a 5x5 grid where each cell contains a different integer from 1 to 25. A player can select any subgrid of size 3x3 and must check if it forms a \"magic square.\" A 3x3 magic square is d...
0.56619
Code_Contests_47635
C
[ "is_magic_square", "contains_magic_square", "parse_grid" ]
3
[ [ "contains_magic_square", "is_magic_square" ] ]
1
[]
false
[]
false
pytest
true
[]
true
f48712fd45baa14c3d079e04815e89fc214d31ed
36bd83c292b2696a2f848b54ab64788f3d5b2b70
v1.0
complete
Code_Contests
Code_Contests_48050_C
def process_input_and_find_shortest_good_substring_length(t: int, sequences: List[str]) -> List[int]: """ Determine the length of the shortest good substring for each DNA sequence. Args: t (int): The number of test cases. sequences (List[str]): The list of DNA sequences. Returns: List[int]: Th...
def find_shortest_good_substring_length(dna_sequences): results = [] for dna in dna_sequences: n = len(dna) min_length = n + 1 # Initialize with a large value (larger than any possible substring) for start in range(n): count = {'A': 0, 'C': 0, 'G': 0, 'T': 0} ...
from solution import process_input_and_find_shortest_good_substring_length def test_single_case(): sequences = ["AGCT"] result = process_input_and_find_shortest_good_substring_length(1, sequences) assert result == [4] def test_multiple_cases(): sequences = ["AGCT", "AAGGCCTT", "ACGTACGTACGT"] resu...
[ { "docstring": null, "function_declaration": "def find_shortest_good_substring_length(dna_sequences):", "function_name": "find_shortest_good_substring_length", "parameter_list": "(dna_sequences)" }, { "docstring": null, "function_declaration": "def process_input_and_find_shortest_good_su...
[ 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 find_shortest_good_substring_length(dna_sequences):\n results = []\n for dna in dna_sequences:\n n = len(dna)\n min_length = n + 1 ...
trial_gpt4o_0
{ "original_instruction": "A scientist in a lab is studying DNA sequences. Each sequence is represented as a string consisting of characters 'A', 'C', 'G', and 'T'. The scientist defines a good substring as one that has an equal number of 'A's, 'C's, 'G's, and 'T's. Given a DNA sequence, help the scientist determine ...
0.624207
Code_Contests_48050
C
[ "find_shortest_good_substring_length", "process_input_and_find_shortest_good_substring_length" ]
2
[ [ "process_input_and_find_shortest_good_substring_length", "find_shortest_good_substring_length" ] ]
1
[]
false
[]
false
pytest
true
[]
true
0caaec16c9f5ce916b899ade3e146034f044cd62
7f2cd9803caaae1c3619e089a9cac42c8919884c
v1.0
complete
Code_Contests
Code_Contests_47585_C
def marathon_route(n: int, m: int, streets: List[Tuple[int, int, int]]) -> int: """ Find the minimal total length of the marathon route that forms a single closed loop using every street exactly once. Args: n : int : number of intersections m : int : number of streets streets : List of Tuples :...
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 rank[root_x] < rank[root_y]: parent[root_x] = root_y elif rank[root_x] > rank[root_y]: parent[root_y] = ...
from solution import marathon_route def test_marathon_route_simple_loop(): n = 5 m = 7 streets = [ (1, 2, 10), (2, 3, 15), (3, 4, 20), (4, 5, 25), (5, 1, 30), (2, 5, 35), (3, 1, 40) ] assert marathon_route(n, m, streets) == 100 def test_marat...
[ { "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, 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": "from collections import defaultdict\nimport heapq\n\ndef minimal_marathon_route(N, M, streets):\n def find(parent, i):\n \"\"\" Helper function t...
trial_gpt4o_9
{ "original_instruction": "The city of Algorithmia is organizing an annual marathon event. The marathon route must be designed in such a way that it forms a single closed loop (i.e., the starting point is the same as the endpoint) and every street is a part of the loop exactly once. Given the streets in the city and ...
0.687653
Code_Contests_47585
C
[ "find", "union", "kruskal_mst", "min_marathon_route", "marathon_route" ]
5
[ [ "kruskal_mst", "find" ], [ "kruskal_mst", "union" ], [ "marathon_route", "min_marathon_route" ], [ "min_marathon_route", "kruskal_mst" ], [ "union", "find" ] ]
5
[]
false
[]
false
pytest
true
[]
true
02c2c98f73960820a4ab3c6d362fe8909d7005f4
687c4d00577518ca744a31551c5999ca66dd07d4
v1.0
complete
Code_Contests
Code_Contests_47231_C
def can_form_palindrome(arr): """ Determine if the array can form a palindrome after at most one modification. Parameters: arr (list): List of integers representing the array. Returns: str: "YES" if the array can be modified to form a palindrome, "NO" otherwise. """ pass def s...
def can_form_palindrome(arr): """ Determine if the array can form a palindrome after at most one modification. Parameters: arr (list): List of integers representing the array. Returns: str: "YES" if the array can be modified to form a palindrome, "NO" otherwise. """ def is_almo...
from solution import can_form_palindrome, solve def test_can_form_palindrome(): assert can_form_palindrome([1, 2, 3, 2, 1]) == "YES" assert can_form_palindrome([1, 2, 3, 4, 1]) == "NO" assert can_form_palindrome([1, 2, 2, 1]) == "YES" assert can_form_palindrome([1, 2, 2, 2, 1]) == "YES" assert can_...
[ { "docstring": "Determine if the array can form a palindrome after at most one modification.\n\nParameters:\narr (list): List of integers representing the array.\n\nReturns:\nstr: \"YES\" if the array can be modified to form a palindrome, \"NO\" otherwise.", "function_declaration": "def can_form_palindrome(...
[ 0, 0, 0, 0, 0, 0, 1, 0, 0, 1 ]
2
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def can_form_palindrome_after_one_modification(arr):\n \"\"\"\n Determine if the array can be modified to form a palindrome\n after at most one mo...
trial_gpt4o_9
{ "original_instruction": "Given an array of integers, determine whether the array can form a palindrome after at most one modification (i.e., changing at most one integer). A palindrome is a sequence that reads the same backward as forward.\n\nInput\n\nThe first line contains an integer n (1 ≤ n ≤ 10^5) — the number...
0.719557
Code_Contests_47231
C
[ "can_form_palindrome", "solve" ]
2
[ [ "solve", "can_form_palindrome" ] ]
1
[]
false
[]
false
pytest
true
[]
true
39d81ff2576693b3fd47d6633913774da2e59b88
83d8afd24837cd1a9c287e1f471390020dc5e720
v1.0
complete
Code_Contests
Code_Contests_47995_C
def reverse_number(n): """Returns the reverse of the given number. """ pass def is_palindromic(n): """Checks if the given number is palindromic. """ pass def find_palindromic_number(n): """Finds the smallest palindromic number starting from n and the steps taken to reach it. """ pa...
def reverse_number(n): """ Returns the reverse of the given number. """ return int(str(n)[::-1]) def is_palindromic(n): """ Checks if the given number is palindromic. """ return str(n) == str(n)[::-1] def find_palindromic_number(n): """ Finds the smallest palindromic number sta...
from solution import reverse_number, is_palindromic, find_palindromic_number, process_test_cases def test_reverse_number(): assert reverse_number(123) == 321 assert reverse_number(87) == 78 assert reverse_number(1) == 1 assert reverse_number(4321) == 1234 def test_is_palindromic(): assert is_palin...
[ { "docstring": "Returns the reverse of the given number.", "function_declaration": "def reverse_number(n):", "function_name": "reverse_number", "parameter_list": "(n)" }, { "docstring": "Checks if the given number is palindromic.", "function_declaration": "def is_palindromic(n):", "f...
[ 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 reverse_number(n):\n \"\"\"\n Reverses the digits of the given number.\n \"\"\"\n return int(str(n)[::-1])\n\ndef is_palindrome(n):\n \"...
trial_gpt4o_2
{ "original_instruction": "Tom is a fan of unique sequences and has recently come across a fascinating sequence that he wants to explore further. The sequence is defined by the following rules:\n\n1. The sequence starts with an integer `n`.\n2. The next number in the sequence is obtained by reversing the digits of th...
0.697671
Code_Contests_47995
C
[ "reverse_number", "is_palindromic", "find_palindromic_number", "process_test_cases" ]
4
[ [ "find_palindromic_number", "is_palindromic" ], [ "find_palindromic_number", "reverse_number" ], [ "process_test_cases", "find_palindromic_number" ] ]
3
[ "process_test_cases" ]
false
[]
false
pytest
true
[]
true
14532fff81bc142b50eefd3b77de344de99fa66d
0c6c022dde631d13126fc0e4de0aa618bca0f1ce
v1.0
complete
Code_Contests
Code_Contests_47686_C
def is_palindrome(number: int) -> bool: """ Checks if a number is a palindrome. >>> is_palindrome(121) True >>> is_palindrome(1331) True >>> is_palindrome(123) False """ def smallest_palindrome_greater_than_or_equal_to(n: int) -> int: """ Returns the smallest palindrome number greater ...
def is_palindrome(number): """ Checks if a number is a palindrome. """ return str(number) == str(number)[::-1] def smallest_palindrome_greater_than_or_equal_to(n): """ Returns the smallest palindrome number greater than or equal to n. """ while not is_palindrome(n): n += 1 r...
from solution import is_palindrome, smallest_palindrome_greater_than_or_equal_to def test_is_palindrome(): assert is_palindrome(121) assert is_palindrome(1331) assert is_palindrome(1) assert not is_palindrome(123) def test_smallest_palindrome_greater_than_or_equal_to(): assert smallest_palindrome_...
[ { "docstring": "Checks if a number is a palindrome.", "function_declaration": "def is_palindrome(number):", "function_name": "is_palindrome", "parameter_list": "(number)" }, { "docstring": "Returns the smallest palindrome number greater than or equal to n.", "function_declaration": "def ...
[ 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_palindrome(num):\n \"\"\"\n Check if a given number is a palindrome.\n \"\"\"\n return str(num) == str(num)[::-1]\n\ndef smallest_palind...
trial_gpt4o_2
{ "original_instruction": "Tanya is passionate about palindrome numbers. A number is considered a palindrome if it reads the same forward and backward. For instance, 121 and 1331 are palindromes, whereas 123 is not. Tanya is particularly interested in the smallest palindrome number that meets certain criteria. \n\nGi...
0.693504
Code_Contests_47686
C
[ "is_palindrome", "smallest_palindrome_greater_than_or_equal_to" ]
2
[ [ "smallest_palindrome_greater_than_or_equal_to", "is_palindrome" ] ]
1
[]
false
[]
false
pytest
true
[]
true
862101d6238a1062b315d7487356ae47dbf3347f
cc4369a8f3bd55b524f7dddd1e8e11d53265f49b
v1.0
complete
Code_Contests
Code_Contests_46767_C
MOD = 10**9 + 7 class FenwickTree: def __init__(self, size): self.size = size self.tree = [0] * (size + 1) def update(self, index, delta): while index <= self.size: self.tree[index] = (self.tree[index] + delta) % MOD index += index & -index def query(self, ...
MOD = 10**9 + 7 class FenwickTree: def __init__(self, size): self.size = size self.tree = [0] * (size + 1) def update(self, index, delta): while index <= self.size: self.tree[index] = (self.tree[index] + delta) % MOD index += index & -index def query(self, ...
def test_example_case(): n = 5 queries = [ [1, 1, 3, 10], [1, 2, 5, 5], [2, 1, 5], [1, 4, 5, 5], [2, 3, 5] ] assert process_queries(n, queries) == [50, 35] def test_single_tree(): n = 1 queries = [ [1, 1, 1, 10], [2, 1, 1], [1, 1, ...
[]
[ 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": "MOD = 10**9 + 7\n\nclass Garden:\n def __init__(self, n):\n self.n = n\n self.tree = [0] * (n + 1)\n self.lazy = [0] * (n + 1)\n\n ...
trial_gpt4o_8
{ "original_instruction": "In a large garden, there are n trees planted in a single line, numbered from 1 to n. Each tree can bear a certain quantity of fruits. Initially, each tree has no fruits. You will be given q operations which are either increasing the number of fruits on the trees or querying the total number...
0.542053
Code_Contests_46767
C
[ "range_update", "prefix_sum", "range_query", "process_queries" ]
4
[ [ "process_queries", "range_query" ], [ "process_queries", "range_update" ], [ "range_query", "prefix_sum" ] ]
3
[ "process_queries" ]
false
[ "FenwickTree" ]
true
pytest
false
[]
true
4be9101c5e5ccfee602a65537899456762df81bd
cc6cb0b14fa39088cb09d54ae19d7801a1bd3c55
v1.0
complete
Code_Contests
Code_Contests_48010_C
def sieve_of_eratosthenes(n): """Use the Sieve of Eratosthenes to find all primes up to n.""" # Implementation def largest_twin_prime_pair(n): """Find the largest twin prime pair (p, p+2) where p+2 ≤ n. Args: n (int): The upper limit for p+2. Returns: str: The largest twin prime pair (p, p...
def sieve_of_eratosthenes(n): """Use the Sieve of Eratosthenes to find all primes up to n.""" is_prime = [True] * (n + 1) is_prime[0] = is_prime[1] = False for start in range(2, int(n**0.5) + 1): if is_prime[start]: for multiple in range(start*start, n + 1, start): ...
from solution import largest_twin_prime_pair def test_example_1(): assert largest_twin_prime_pair(10) == "5 7" def test_example_2(): assert largest_twin_prime_pair(15) == "11 13" def test_example_3(): assert largest_twin_prime_pair(2) == "-1" def test_no_twin_primes(): assert largest_twin_prime_pair...
[ { "docstring": "Use the Sieve of Eratosthenes to find all primes up to n.", "function_declaration": "def sieve_of_eratosthenes(n):", "function_name": "sieve_of_eratosthenes", "parameter_list": "(n)" }, { "docstring": "Find the largest twin prime pair (p, p+2) where p+2 ≤ n.", "function_d...
[ 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 sieve_of_eratosthenes(n):\n \"\"\"Use the Sieve of Eratosthenes to find all primes up to n.\"\"\"\n is_prime = [True] * (n + 1)\n is_prime[0] ...
trial_gpt4o_0
{ "original_instruction": "Alex loves exploring prime numbers. A prime number is a natural number greater than 1 that has no positive divisors other than 1 and itself. Alex is particularly fascinated by pairs of prime numbers that differ by exactly 2. Such pairs of primes are called \"twin primes\". For example, (3, ...
0.62613
Code_Contests_48010
C
[ "sieve_of_eratosthenes", "largest_twin_prime_pair" ]
2
[ [ "largest_twin_prime_pair", "sieve_of_eratosthenes" ] ]
1
[]
false
[]
false
pytest
true
[]
true
b1151d87c18a44826f7a8542d05d1d22c6df496b
99c049564f8b542c33c3216b9e7c532dbe5d3056
v1.0
complete
Code_Contests
Code_Contests_48382_C
from typing import List def can_partition(nums: List[int]) -> str: """ Determines if it is possible to partition the nums list into two subsets such that the sum of the subsets is equal. >>> can_partition([1, 5, 11, 5]) "YES" >>> can_partition([1, 2, 3, 5]) "NO" >>> can_partition...
def can_partition(nums): """ Determines if it is possible to partition the nums list into two subsets such that the sum of the subsets is equal. """ total_sum = sum(nums) if total_sum % 2 != 0: return "NO" target = total_sum // 2 n = len(nums) dp = [False] * (t...
from solution import can_partition, process_input_lines def test_can_partition(): assert can_partition([1, 5, 11, 5]) == "YES" assert can_partition([1, 2, 3, 5]) == "NO" assert can_partition([3, 3, 3, 3]) == "YES" assert can_partition([1, 1, 1]) == "NO" assert can_partition([]) == "YES" # Edge cas...
[ { "docstring": "Determines if it is possible to partition the nums list into two subsets\nsuch that the sum of the subsets is equal.", "function_declaration": "def can_partition(nums):", "function_name": "can_partition", "parameter_list": "(nums)" }, { "docstring": "Processes the given list ...
[ 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 can_partition(nums):\n \"\"\"\n Determines if a list of numbers can be partitioned into two subsets with equal sum.\n \n Parameters:\n n...
trial_gpt4o_2
{ "original_instruction": "Given a sequence of n numbers, your task is to determine if it is possible to split the sequence into two partitions such that the sum of the numbers in each partition is the same. If it is possible, print \"YES\", otherwise print \"NO\".\n\nEach input line contains a sequence of space-sepa...
0.618023
Code_Contests_48382
C
[ "can_partition", "process_input_lines" ]
2
[ [ "process_input_lines", "can_partition" ] ]
1
[]
false
[]
false
pytest
true
[]
true
fdca24230a5493510adce9bcce27112e108fea03
9f551c3a9f7e35ffd24027bde7ebbeab74d4339d
v1.0
complete
Code_Contests
Code_Contests_46795_C
def levenshtein_distance(a, b): """ Calculates the Levenshtein distance between two strings a and b. """ def closest_matching_title(product_titles, search_phrases): """ Finds the closest matching product title from the product titles for each search phrase. Args: product_titles: List o...
def levenshtein_distance(a, b): """ Calculates the Levenshtein distance between two strings a and b. """ n, m = len(a), len(b) if n > m: a, b = b, a n, m = m, n current_row = range(n+1) for i in range(1, m+1): previous_row, current_row = current_row, [i...
def test_levenshtein_distance(): assert levenshtein_distance('kitten', 'sitting') == 3 assert levenshtein_distance('flaw', 'lawn') == 2 assert levenshtein_distance('intention', 'execution') == 5 assert levenshtein_distance('', 'abc') == 3 assert levenshtein_distance('abc', '') == 3 def test_closest...
[ { "docstring": "Calculates the Levenshtein distance between two strings a and b.", "function_declaration": "def levenshtein_distance(a, b):", "function_name": "levenshtein_distance", "parameter_list": "(a, b)" }, { "docstring": "Finds the closest matching product title from the product title...
[ 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 levenshtein_distance(a, b):\n \"\"\"\n Calculates the Levenshtein distance between two strings a and b.\n \"\"\"\n n, m = len(a), len(b)\n ...
trial_gpt4o_0
{ "original_instruction": "James and his team are working on a new e-commerce platform. To improve the search functionality, they want to implement an algorithm that can find the closest match for a set of search phrases in a database of product titles. Help them by writing a program to determine the closest matching...
0.639209
Code_Contests_46795
C
[ "levenshtein_distance", "closest_matching_title", "process_datasets", "format_output", "main" ]
5
[ [ "closest_matching_title", "levenshtein_distance" ], [ "process_datasets", "closest_matching_title" ] ]
2
[ "process_datasets", "format_output" ]
false
[]
false
pytest
false
[]
true
71999c3ffd697cebde6780275dda6f5b9dff58b0
0623e4e440660b30ea7041898a52e1a7b71c3107
v1.0
complete
Code_Contests
Code_Contests_47862_C
def is_prime(n): """Check if a number is prime. >>> is_prime(2) True >>> is_prime(3) True >>> is_prime(4) False >>> is_prime(17) True >>> is_prime(18) False """ def path_exists(N, A, B, D, waypoints): """Check if there is a path to destination with the prime sum cond...
def is_prime(n): """Check if a number is prime.""" 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 path...
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(18) == False def test_single_test_case_yes(): N, A, B, D = 4, 10, 50, 4 waypoints = [11, 15, 29, 4] assert path_exists(N, A, B, D-1, waypoin...
[ { "docstring": "Check if a number is prime.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Check if there is a path to destination with the prime sum condition.", "function_declaration": "def path_exists(N, A, B, D, w...
[ 0, 0, 0, 0, 0, 0, 0, 1, 1, 0 ]
2
hard
0.2
{ "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 < 2:\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_8
{ "original_instruction": "Michael is planning a treasure hunt for his friends. He designed a map with several waypoints, each labeled with a unique number. To add an extra level of challenge, Michael introduced a rule: Starting from the first waypoint, participants must find a path to the destination waypoint such t...
0.622061
Code_Contests_47862
C
[ "is_prime", "path_exists", "treasure_hunt" ]
3
[ [ "path_exists", "is_prime" ], [ "treasure_hunt", "path_exists" ] ]
2
[]
false
[]
false
pytest
false
[]
true
70604a89ea759bf35e03b0a94698b089b6273dbb
4a08ab873aef76e6e39d211bbffa6eb0e3d9ea35
v1.0
complete
Code_Contests
Code_Contests_48253_C
def max_even_consecutive_flowers(n: int, flower_ids: List[int]) -> int: """ Returns the maximum number of flowers in the largest arrangement that John can create while following the rule of consecutive IDs and even total number of flowers. Parameters: - n: int, number of flower IDs available. ...
def max_even_consecutive_flowers(n, flower_ids): """ Returns the maximum number of flowers in the largest arrangement that John can create while following the rule of consecutive IDs and even total number of flowers. Parameters: - n: int, number of flower IDs available. - flower_ids: list o...
from solution import max_even_consecutive_flowers def test_example_1(): assert max_even_consecutive_flowers(5, [1, 3, 5, 6, 7]) == 2 def test_example_2(): assert max_even_consecutive_flowers(7, [2, 3, 5, 6, 7, 8, 10]) == 4 def test_single_flower(): assert max_even_consecutive_flowers(1, [1]) == 0 def te...
[ { "docstring": "Returns the maximum number of flowers in the largest arrangement that John\ncan create while following the rule of consecutive IDs and even total number of flowers.\n\nParameters:\n- n: int, number of flower IDs available.\n- flower_ids: list of int, distinct flower IDs.\n\nReturns:\n- int, the ...
[ 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 max_even_consecutive_flowers(n, flower_ids):\n \"\"\"\n Determine the maximum number of flowers John can choose \n while satisfying his rule o...
trial_gpt4o_9
{ "original_instruction": "John has a garden with a variety of flowers each identified by a unique integer ID. He wants to create a beautiful flower arrangement for a special event. However, he has a peculiar rule for choosing the flowers for the arrangement: he wants the arrangement to consist of flowers in consecut...
0.549622
Code_Contests_48253
C
[ "max_even_consecutive_flowers", "is_consecutive" ]
2
[ [ "max_even_consecutive_flowers", "is_consecutive" ] ]
1
[]
false
[]
false
pytest
true
[]
true
faa646619eaf14a44f17978c24d15004b47afb10
9776271f9d404f0f7d0e62539307ae40febd614c
v1.0
complete
Code_Contests
Code_Contests_47815_C
def max_length_of_word(grid: List[str]) -> int: """ Returns the length of the longest possible word that can be formed by moving right or down from the top-left corner to the bottom-right corner in a grid. :param grid: List of strings representing the grid :return: Integer representing the leng...
def max_length_of_word(grid): """ Returns the length of the longest possible word that can be formed by moving right or down from the top-left corner to the bottom-right corner in a grid. :param grid: List of strings representing the grid :return: Integer representing the length of the longest ...
from solution import max_length_of_word, find_max_length def test_max_length_of_word_example1(): grid = [ "abc", "def", "ghi" ] assert max_length_of_word(grid) == 5 def test_max_length_of_word_example2(): grid = [ "aa", "bb" ] assert max_length_of_word(g...
[ { "docstring": "Returns the length of the longest possible word that can be formed by moving right or down from the top-left corner\nto the bottom-right corner in a grid.\n\n:param grid: List of strings representing the grid\n:return: Integer representing the length of the longest word", "function_declarati...
[ 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 max_word_length_in_grid(n, m, grid):\n \"\"\"\n Function that finds the maximum length of a word formed by concatenating characters from a \n ...
trial_gpt4o_1
{ "original_instruction": "Sam loves solving puzzles and his latest fascination is with finding specific strings in a grid. Help Sam by writing a function that can find the maximum length of a word formed by concatenating characters from a non-overlapping path in the grid. Sam can only move either right or down from ...
0.707752
Code_Contests_47815
C
[ "max_length_of_word", "find_max_length" ]
2
[ [ "find_max_length", "max_length_of_word" ] ]
1
[]
false
[]
false
pytest
true
[]
true
aaf9edf6cf2c188658c74edae066ec3403f8cb38
9a398fa8ddccd21f3edb825e9c822da768235990
v1.0
complete
Code_Contests
Code_Contests_48791_C
def is_prime(n: int) -> bool: """ Check if a number is prime >>> is_prime(1) False >>> is_prime(2) True >>> is_prime(3) True >>> is_prime(4) False """ def is_tree_beautiful(h: int) -> str: """ Determines if a perfect binary tree of height h is beautiful. A tree is beautiful if the nu...
def is_prime(n): """Check if a number is prime""" 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 is_tr...
from solution import is_tree_beautiful def test_height_1(): # For height 1, perfect binary tree has 1 non-leaf node, which is not prime. assert is_tree_beautiful(1) == "NO" def test_height_2(): # For height 2, perfect binary tree has 3 non-leaf nodes, which is prime. assert is_tree_beautiful(2) == "YE...
[ { "docstring": "Check if a number is prime", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Determines if a perfect binary tree of height h is beautiful.\nA tree is beautiful if the number of non-leaf nodes is a prime numbe...
[ 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_prime(n):\n \"\"\"\n Returns True if n is a prime number, otherwise False.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n...
trial_gpt4o_1
{ "original_instruction": "Alice loves trees, particularly binary trees. She has a special type of binary tree called a \"perfect binary tree\". A perfect binary tree is one in which all interior nodes have two children and all leaves are at the same level.\n\nAlice also enjoys prime numbers. She thinks that a binary...
0.658182
Code_Contests_48791
C
[ "is_prime", "is_tree_beautiful" ]
2
[ [ "is_tree_beautiful", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
4e8629e4d2de1c8b8d2eb358e452926081225e2c
a78b12d21cf260d23ca1eb8fa854bb6163283cb9
v1.0
complete
Code_Contests
Code_Contests_48243_C
import itertools from typing import List, Tuple def minimum_travel_time(n: int, m: int, roads: List[Tuple[int, int, int]]) -> int: """ Determine the minimum total travel time for a round trip that visits all delivery points exactly once and returns to the warehouse. Args: n (int): number of delive...
import itertools def calculate_min_travel_time(n, roads): # Create a 2D array (matrix) to store the travel times between points travel_times = [[float('inf')] * n for _ in range(n)] # Fill in the travel times from the roads data for u, v, t in roads: travel_times[u-1][v-1] = t trav...
from solution import minimum_travel_time def test_example_case(): n, m = 4, 6 roads = [ (1, 2, 10), (1, 3, 15), (1, 4, 20), (2, 3, 35), (2, 4, 25), (3, 4, 30) ] assert minimum_travel_time(n, m, roads) == 80 def test_two_points_case(): n, m = 2, 1 ...
[ { "docstring": null, "function_declaration": "def calculate_min_travel_time(n, roads):", "function_name": "calculate_min_travel_time", "parameter_list": "(n, roads)" }, { "docstring": null, "function_declaration": "def minimum_travel_time(n, m, roads):", "function_name": "minimum_tra...
[ 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": "from itertools import permutations\n\ndef min_travel_time(n, m, roads):\n # Initialize adjacency matrix with infinite travel times\n inf = float('inf...
trial_gpt4o_4
{ "original_instruction": "A local delivery company wants to optimize its delivery routes. The company has one central warehouse and several delivery points distributed in a city. A delivery truck will start from the warehouse, deliver packages to all the points, and return to the warehouse. The company uses a bidire...
0.666007
Code_Contests_48243
C
[ "calculate_min_travel_time", "minimum_travel_time" ]
2
[ [ "minimum_travel_time", "calculate_min_travel_time" ] ]
1
[]
false
[]
false
pytest
true
[]
true
311f5109e8bbeecf4ce37b8c990712725aaa073c
3f3d29cdb00f361b93b533365846b5a1f09bde86
v1.0
complete
Code_Contests
Code_Contests_47782_C
def cyclic_shift(matrix, r, k): """ Perform a right cyclic shift on the given row of the matrix by k positions. >>> cyclic_shift([[1, 2, 3], [4, 5, 6], [7, 8, 9]], 0, 1) [3, 1, 2] >>> cyclic_shift([[1, 2, 3], [4, 5, 6], [7, 8, 9]], 2, 2) [8, 9, 7] """ n = len(matrix[r]) k = k % n # ...
def cyclic_shift(matrix, r, k): """ Perform a right cyclic shift on the given row of the matrix by k positions. """ n = len(matrix[r]) k = k % n # To handle cases where k is larger than the number of columns return matrix[r][-k:] + matrix[r][:-k] def sum_after_operations(n, m, matrix, operatio...
def test_cyclic_shift_basic(): matrix = [ [1, 2, 3], [4, 5, 6], [7, 8, 9] ] assert cyclic_shift(matrix, 0, 1) == [3, 1, 2] assert cyclic_shift(matrix, 2, 2) == [8, 9, 7] def test_sum_after_operations_case1(): n = 3 m = 3 matrix = [ [1, 2, 3], [4, 5, 6...
[ { "docstring": "Perform a right cyclic shift on the given row of the matrix by k positions.", "function_declaration": "def cyclic_shift(matrix, r, k):", "function_name": "cyclic_shift", "parameter_list": "(matrix, r, k)" }, { "docstring": "Perform a series of cyclic shift operations on the m...
[ 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 matrix_cyclic_shift_and_sum(matrix, operations):\n \"\"\"\n Perform cyclic shifts on specified rows of the matrix and return the sum of all eleme...
trial_gpt4o_2
{ "original_instruction": "There is a matrix of size N x M consisting of non-negative integers. You need to perform a series of operations. In each operation, you will be given a row index `r_i` and a cyclic shift amount `k_i`. You will perform a right cyclic shift of the elements in the row `r_i` by `k_i` positions....
0.560637
Code_Contests_47782
C
[ "cyclic_shift", "sum_after_operations" ]
2
[ [ "sum_after_operations", "cyclic_shift" ] ]
1
[]
false
[]
false
pytest
false
[]
true
970694d17b5f3fac8b598cda6f7795d3fe3749d2
8e1c493934d7b2e7506a1406627f3222a0f9aafd
v1.0
complete
Code_Contests
Code_Contests_47228_C
from typing import List, Tuple def organize_hackathon(n: int, T: int, a: List[int]) -> Tuple[int, List[List[int]]]: """ Organize a Hackathon event to form teams that maximize network engagement and collaboration. Args: n (int): the number of participants. T (int): the maximum total skill rati...
def form_teams(n, T, skill_ratings): participants = list(enumerate(skill_ratings, start=1)) participants.sort(key=lambda x: x[1], reverse=True) teams = [] visited = [False] * n for i in range(n): if visited[i]: continue for j in range(i + 1, n): if v...
from solution import organize_hackathon def test_organize_hackathon_example_case(): n, T = 6, 10 a = [2, 3, 7, 5, 4, 1] num_teams, teams = organize_hackathon(n, T, a) assert num_teams == 3 assert len(teams) == 3 for team in teams: assert len(team[1:]) == 2 # Ensure each team has exactl...
[ { "docstring": null, "function_declaration": "def form_teams(n, T, skill_ratings):", "function_name": "form_teams", "parameter_list": "(n, T, skill_ratings)" }, { "docstring": null, "function_declaration": "def organize_hackathon(n, T, a):", "function_name": "organize_hackathon", ...
[ 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 form_teams(n, T, skill_ratings):\n skill_ratings = [(skill, i + 1) for i, skill in enumerate(skill_ratings)]\n skill_ratings.sort(reverse=True) ...
trial_gpt4o_7
{ "original_instruction": "A technology startup is planning to organize a Hackathon event. For the successful operation of the event, they need to arrange the participants in a manner that maximizes network engagement and collaboration.\n\nIn this Hackathon, n participants are competing, each having a unique skill ra...
0.661794
Code_Contests_47228
C
[ "form_teams", "organize_hackathon" ]
2
[ [ "organize_hackathon", "form_teams" ] ]
1
[]
false
[]
false
pytest
true
[]
true
e828fae54df2ab52c2a022629acdcc4af0de68e0
a9916f9b3415f9bc01367b42e4ba279080dc3768
v1.0
complete
Code_Contests
Code_Contests_48119_C
def orientation(p, q, r): """ Return the orientation of the ordered triplet (p, q, r). 0 -> p, q and r are collinear 1 -> Clockwise 2 -> Counterclockwise """ pass def on_segment(p, q, r): """ Given three collinear points p, q, r, check if point q lies on segment pr. """ pass...
def orientation(p, q, r): """ Return the orientation of the ordered triplet (p, q, r). 0 -> p, q and r are collinear 1 -> Clockwise 2 -> Counterclockwise """ val = (q[1] - p[1]) * (r[0] - q[0]) - (q[0] - p[0]) * (r[1] - q[1]) if val == 0: return 0 elif val > 0: return...
from solution import do_segments_intersect def test_case_1(): assert do_segments_intersect(1, 1, 4, 4, 1, 8, 2, 4) == "NO" def test_case_2(): assert do_segments_intersect(1, 1, 4, 4, 2, 2, 3, 3) == "YES" def test_case_3(): assert do_segments_intersect(1, 1, 4, 4, 4, 4, 5, 5) == "YES" def test_collinear_...
[ { "docstring": "Return the orientation of the ordered triplet (p, q, r).\n0 -> p, q and r are collinear\n1 -> Clockwise\n2 -> Counterclockwise", "function_declaration": "def orientation(p, q, r):", "function_name": "orientation", "parameter_list": "(p, q, r)" }, { "docstring": "Given three c...
[ 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 intersect(x1, y1, x2, y2, x3, y3, x4, y4):\n def orientation(px, py, qx, qy, rx, ry):\n # To find the orientation of the ordered triplet (p, ...
trial_gpt4o_1
{ "original_instruction": "You are given two segments in a 2D plane. Each segment is defined by its endpoints. Determine if these two segments intersect.\n\nHere is a simplified description of the segments and the intersection:\n\nSegments are defined by their endpoints (x1, y1), (x2, y2) and (x3, y3), (x4, y4).\n\nT...
0.590134
Code_Contests_48119
C
[ "orientation", "on_segment", "segments_intersect", "do_segments_intersect" ]
4
[ [ "do_segments_intersect", "segments_intersect" ], [ "segments_intersect", "on_segment" ], [ "segments_intersect", "orientation" ] ]
3
[]
false
[]
false
pytest
true
[]
true
0f84d1fab01a7d6924f421ab8a7db2c3151be41b
960ec6e38bdfab9d3818030d1efca91b755df948
v1.0
complete
Code_Contests
Code_Contests_48909_C
from typing import List, Tuple def is_creation_possible(N: int, blocks_data: List[Tuple[str, int]], M: int, required_data: List[Tuple[str, int]]) -> str: """ Determine whether it is possible to create a specific composite shape given the set of available building blocks. Args: N: int - Number of avail...
def can_create_composite_shapes(blocks, required_shapes): from collections import defaultdict # Parse block sizes by shape block_sizes = defaultdict(list) for shape, size in blocks: block_sizes[shape].append(size) # Sort each shape's block sizes for efficient comparison for sha...
def test_possible_creation_case_1(): blocks_data = [('circle', 10), ('circle', 20), ('square', 5), ('square', 10)] required_data = [('circle', 25), ('square', 10)] assert is_creation_possible(4, blocks_data, 2, required_data) == 'Possible' def test_impossible_creation_case_2(): blocks_data = [('circle'...
[ { "docstring": null, "function_declaration": "def can_create_composite_shapes(blocks, required_shapes):", "function_name": "can_create_composite_shapes", "parameter_list": "(blocks, required_shapes)" }, { "docstring": null, "function_declaration": "def is_creation_possible(N, blocks_data...
[ 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_possible_to_create_composite_shape(n, blocks, m, requirements):\n # Organize blocks by shape\n block_dict = {}\n for shape, size in blocks:...
trial_gpt4o_4
{ "original_instruction": "In a distant land, there is a unique factory called ShapeMaker which specializes in creating a variety of different shapes from a given set of building blocks. Each building block is defined by its size and shape. The factory can create a new composite shape by combining a specified number ...
0.519912
Code_Contests_48909
C
[ "can_create_composite_shapes", "is_creation_possible" ]
2
[ [ "is_creation_possible", "can_create_composite_shapes" ] ]
1
[]
false
[]
false
pytest
false
[]
true
abe3adb05be68a701a757fc74427c675d0f7fb55
0f6387cdece70c5ac81dd92784d1e7ab18fdbbbc
v1.0
complete
Code_Contests
Code_Contests_48859_C
def palindromic_transformation(input_data: str) -> List[int]: """ Palindromic Subsequence Transformation Determine whether it is possible to transform the sequence A into a palindromic sequence using the given transformation rules. If possible, compute the minimum number of transformations required t...
from collections import defaultdict, deque def is_palindromic(seq): return seq == seq[::-1] def min_transformations_to_palindrome(n, r, A, transformations): if is_palindromic(A): return 0 transform_dict = defaultdict(list) for x, y in transformations: transform_dict[x].append(...
import pytest from solution import palindromic_transformation def test_case_1(): input_data = "3 3\n1 2 3\n1 3\n2 2\n3 1\n0 0\n" assert palindromic_transformation(input_data) == [1] def test_case_2(): input_data = "4 2\n4 4 2 1\n4 1\n2 3\n0 0\n" assert palindromic_transformation(input_data) == [-1] d...
[ { "docstring": null, "function_declaration": "def is_palindromic(seq):", "function_name": "is_palindromic", "parameter_list": "(seq)" }, { "docstring": null, "function_declaration": "def min_transformations_to_palindrome(n, r, A, transformations):", "function_name": "min_transformati...
[ 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": "from collections import defaultdict, deque\n\ndef is_palindromic(seq):\n return seq == seq[::-1]\n \ndef min_transformations_to_palindrome(n, r, A, t...
trial_gpt4o_0
{ "original_instruction": "Palindromic Subsequence Transformation\n\nYou are given a sequence of integers A: A1 A2 ... An and a set of transformation rules of the form \"x -> y\". The following transformation on the sequence is allowed an arbitrary number of times:\n\n* Transformation: With a transformation rule \"x ...
0.77388
Code_Contests_48859
C
[ "is_palindromic", "min_transformations_to_palindrome", "palindromic_transformation" ]
3
[ [ "min_transformations_to_palindrome", "is_palindromic" ], [ "palindromic_transformation", "min_transformations_to_palindrome" ] ]
2
[]
false
[]
false
pytest
true
[]
true
ac0280c117bfbc74786cbd829670ad4dcbdbdda4
0f9058a75501a4f4b6fab6b6652562bd4eac3a2b
v1.0
complete
Code_Contests
Code_Contests_47413_C
def max_water_flow(n, e, edges, s, t): """ Calculates the maximum amount of water that can be transported from city S to city T in the network. >>> simulate_game('''4 5 1 2 100 1 3 100 2 3 1 2 4 100 3 4 100 1 4''') 200 >>> simulate_game('''4 2 1 2 100 3 4 100 1 4...
from collections import deque, defaultdict class MaxFlow: def __init__(self, n): self.n = n self.capacity = defaultdict(lambda: defaultdict(int)) self.flow = defaultdict(lambda: defaultdict(int)) def add_edge(self, u, v, c): self.capacity[u][v] += c def bfs(self, source, s...
def test_sample_input(): input_str = '''4 5 1 2 100 1 3 100 2 3 1 2 4 100 3 4 100 1 4''' assert simulate_game(input_str) == 200 def test_no_flow(): input_str = '''4 2 1 2 100 3 4 100 1 4''' assert simulate_game(input_str) == 0 def test_single_path(): input_str = '''3 2 1 2 10 2 3 5 1 3''' asse...
[]
[ 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, defaultdict\n\nclass MaxFlow:\n def __init__(self, n):\n self.n = n\n self.capacity = defaultdict(lambda: d...
trial_gpt4o_0
{ "original_instruction": "In a computer simulation game, players construct networks of pipelines to transport water between different cities. Each city has a water requirement, and water flows through the network to meet these requirements. You need to write a program that calculates the maximum flow from a source c...
0.584587
Code_Contests_47413
C
[ "max_water_flow", "simulate_game" ]
2
[ [ "simulate_game", "max_water_flow" ] ]
1
[]
false
[ "MaxFlow" ]
true
pytest
false
[]
true
d0d6fdeefe3a1dd5f812fd1e2de96267ddbda8e2
6080d60a398aa4f473d917ebe8255022669f12cb
v1.0
complete
Code_Contests
Code_Contests_47933_C
def grid_path(n: int, m: int, grid_lines: List[str]) -> str: """ There is a rectangular grid with n rows and m columns. Some cells in this grid contain obstacles, while others are free. You want to find a path from the top-left corner (1,1) to the bottom-right corner (n,m) such that the path avoids obstacles and on...
def find_path(n, m, grid): def is_valid(x, y): return 0 <= x < n and 0 <= y < m and grid[x][y] == '.' def dfs(x, y): if x == n - 1 and y == m - 1: return True if not is_valid(x, y): return False grid[x][y] = '#' # mark the cell as visited ...
from solution import grid_path def test_grid_path_example1(): n, m = 3, 3 grid_lines = [ '...', '.#.', '...' ] result = grid_path(n, m, grid_lines) assert result == "YES\nRRDD" or result == "YES\nDDRR" def test_grid_path_example2(): n, m = 3, 3 grid_lines = [ ...
[ { "docstring": null, "function_declaration": "def find_path(n, m, grid):", "function_name": "find_path", "parameter_list": "(n, m, grid)" }, { "docstring": null, "function_declaration": "def grid_path(n, m, grid_lines):", "function_name": "grid_path", "parameter_list": "(n, m, gr...
[ 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_path(n, m, grid):\n def is_valid(x, y):\n return 0 <= x < n and 0 <= y < m and grid[x][y] == '.'\n \n def dfs(x, y):\n if x...
trial_gpt4o_0
{ "original_instruction": "There is a rectangular grid with n rows and m columns. Some cells in this grid contain obstacles, while others are free. You want to find a path from the top-left corner (1,1) to the bottom-right corner (n,m) such that the path avoids obstacles and only moves right or down.\n\nWrite a progr...
0.690802
Code_Contests_47933
C
[ "find_path", "grid_path" ]
2
[ [ "grid_path", "find_path" ] ]
1
[]
false
[]
false
pytest
true
[]
true
67cd6c49205ff90bcf463b507278426d436a0e68
33fb48a92e8a147850e69e38678f61ee7db2a610
v1.0
complete
Code_Contests
Code_Contests_49488_C
def determine_winner(M, N, grid): """ Determine who wins the game between Tom and Jerry. Both Tom and Jerry play optimally. Tom starts at (0, 0) and Jerry starts at (M-1, N-1). Tom can move right or down, and Jerry can move left or up. The grid may contain obstacles represented by '#' and empty cells by...
from collections import deque def can_tom_win(grid, M, N): directions_tom = [(0, 1), (1, 0)] # right, down for Tom directions_jerry = [(0, -1), (-1, 0)] # left, up for Jerry start_tom = (0, 0) start_jerry = (M-1, N-1) # BFS to find shortest path distance for Tom and Jerry from their starts d...
def test_case_1(): grid = [ "...", ".#.", ".#." ] assert determine_winner(3, 3, grid) == "Tom wins" def test_case_2(): grid = [ "..#", ".#.", ".#." ] assert determine_winner(3, 3, grid) == "Jerry wins" def test_case_3(): grid = [ "......
[ { "docstring": null, "function_declaration": "def can_tom_win(grid, M, N):", "function_name": "can_tom_win", "parameter_list": "(grid, M, N)" }, { "docstring": null, "function_declaration": "def determine_winner(M, N, grid):", "function_name": "determine_winner", "parameter_list"...
[ 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 collections import deque\n\ndef can_tom_win(grid, M, N):\n directions_tom = [(0, 1), (1, 0)] # right, down for Tom\n d...
trial_gpt4o_1
{ "original_instruction": "Tom and Jerry are playing a game on a 2D grid of size M x N. Initially, Tom starts at the top left corner of the grid (0, 0) and Jerry starts at the bottom right corner (M-1, N-1). The game progresses in turns, with each player moving alternately. In each turn, Tom can move one step either ...
0.67237
Code_Contests_49488
C
[ "can_tom_win", "determine_winner" ]
2
[ [ "determine_winner", "can_tom_win" ] ]
1
[]
false
[]
false
pytest
false
[]
true
29678d8f98a85b942c3861f865d333a841ee83a7
b5787e212bfbce60ed069c92d7e9c90d20f25a6a
v1.0
complete
Code_Contests
Code_Contests_49279_C
from typing import List def is_prime(n: int) -> bool: """ Check if a given number is a prime number. >>> is_prime(2) == True >>> is_prime(3) == True >>> is_prime(4) == False >>> is_prime(29) == True """ # Implement the function here def is_palindrome(n: int) -> bool: """ C...
def is_prime(n): """Check if n is a prime number.""" 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 is...
from solution import is_prime, is_palindrome, smallest_prime_palindrome def test_is_prime(): assert is_prime(2) == True assert is_prime(3) == True assert is_prime(4) == False assert is_prime(29) == True assert is_prime(31) == True assert is_prime(32) == False def test_is_palindrome(): asse...
[ { "docstring": "Check if n is a prime number.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Check if n is a palindrome.", "function_declaration": "def is_palindrome(n):", "function_name": "is_palindrome", "pa...
[ 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_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 retur...
trial_gpt4o_1
{ "original_instruction": "Alice loves prime numbers and palindromes. She is especially fascinated by numbers that are both prime and palindrome. She refers to such numbers as **prime palindromes**. Your task is to find the smallest prime palindrome greater than or equal to a given number `X`.\n\nA **prime number** i...
0.70374
Code_Contests_49279
C
[ "is_prime", "is_palindrome", "smallest_prime_palindrome" ]
3
[ [ "smallest_prime_palindrome", "is_palindrome" ], [ "smallest_prime_palindrome", "is_prime" ] ]
2
[]
false
[]
false
pytest
true
[]
true
5237a35aae5a63da482256d7561dc8488099e42f
ec47482e136f90a9e2bf00eeac97fe60c6c9ef81
v1.0
complete
Code_Contests
Code_Contests_49264_C
def good_string(s: str) -> str: """ Determine if the given string can become a good string by removing exactly one character. A string is defined as a "good string" if all its characters are distinct and the alphabetical order of characters in the string does not change. Args: s (str): The input strin...
def good_string(s): n = len(s) # Early return if the string is already a good string if is_good_string(s): return s for i in range(n): modified_string = s[:i] + s[i+1:] if is_good_string(modified_string): return modified_string return "IMPOSSIBLE" ...
from solution import good_string def test_good_string_already_good(): assert good_string("abcd") == "abcd" def test_good_string_remove_one(): assert good_string("abacd") == "abcd" def test_good_string_impossible(): assert good_string("ddca") == "IMPOSSIBLE" def test_good_string_all_same(): assert go...
[ { "docstring": null, "function_declaration": "def good_string(s):", "function_name": "good_string", "parameter_list": "(s)" }, { "docstring": null, "function_declaration": "def is_good_string(s):", "function_name": "is_good_string", "parameter_list": "(s)" } ]
[ 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 good_string(s):\n n = len(s)\n \n # Early return if the string is already a good string\n if is_good_string(s):\n return s\n \n ...
trial_gpt4o_0
{ "original_instruction": "A string is defined as a “good string” if all its characters are distinct and the alphabetical order of characters in the string does not change. Given a string `str`, your task is to determine if it can become a good string by removing exactly one character. If it's possible, return the mo...
0.660116
Code_Contests_49264
C
[ "good_string", "is_good_string" ]
2
[ [ "good_string", "is_good_string" ] ]
1
[]
false
[]
false
pytest
true
[]
true
e932271a12341a2b41e6daeaaade7a8c7d5377c4
ae2912acc0f9ee390aa89c5c10c9e40b12c7d616
v1.0
complete
Code_Contests
Code_Contests_48808_C
from typing import List, Tuple def is_path_possible(grid: List[List[str]], N: int) -> str: """ Determine if there exists a path from 'S' to 'E' in a grid. >>> is_path_possible([ ['S', '.', '.'], ['.', '#', '.'], ['.', '.', 'E'] ], 3) == "POSSIBLE" >>> is_path_possible([ ...
def is_path_possible(grid, N): from collections import deque def bfs(sx, sy, ex, ey): directions = [(-1, 0), (1, 0), (0, -1), (0, 1)] queue = deque([(sx, sy)]) visited = set([(sx, sy)]) while queue: x, y = queue.popleft() if (x, ...
def test_is_path_possible(): assert is_path_possible([ ['S', '.', '.'], ['.', '#', '.'], ['.', '.', 'E'] ], 3) == "POSSIBLE" assert is_path_possible([ ['S', '.', '.'], ['#', '#', '#'], ['.', '.', 'E'] ], 3) == "IMPOSSIBLE" assert is_path_possible...
[ { "docstring": null, "function_declaration": "def is_path_possible(grid, N):", "function_name": "is_path_possible", "parameter_list": "(grid, N)" }, { "docstring": null, "function_declaration": "def evaluate_grids(grids):", "function_name": "evaluate_grids", "parameter_list": "(g...
[ 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_path_possible(grid, N):\n from collections import deque\n \n def bfs(sx, sy, ex, ey):\n directions = [(-1, 0), (1, 0), (0, -1), (0, ...
trial_gpt4o_0
{ "original_instruction": "You are given a grid representing a battlefield, where:\n- '.' denotes an empty cell.\n- '#' denotes a blocked cell that cannot be passed through.\n- 'S' denotes the starting point.\n- 'E' denotes the endpoint.\n\nYour task is to determine if there exists a path from the starting point to t...
0.52647
Code_Contests_48808
C
[ "is_path_possible", "evaluate_grids", "bfs_solve_battlefield" ]
3
[ [ "bfs_solve_battlefield", "is_path_possible" ], [ "evaluate_grids", "is_path_possible" ] ]
2
[]
false
[]
false
pytest
false
[]
true
0b5dbb80cc3b5cf36d47d0667d86e1c917898453
aad55d1e148d2163eca4e9f0e17b21096ac8dc85
v1.0
complete
Code_Contests
Code_Contests_49161_C
def is_leap_year(year: int) -> str: """ Returns 'YES' if the given year is a leap year, 'NO' otherwise. >>> is_leap_year(2000) 'YES' >>> is_leap_year(1900) 'NO' >>> is_leap_year(2004) 'YES' >>> is_leap_year(1999) 'NO' >>> is_leap_year(1600) 'YES' >>> is_leap_year(2020...
def is_leap_year(year): """ Returns 'YES' if the given year is a leap year, 'NO' otherwise. """ if (year % 400 == 0) or (year % 4 == 0 and year % 100 != 0): return "YES" else: return "NO" def leap_years(years): """ Given a list of years, returns a list indicating whether eac...
from solution import is_leap_year, leap_years def test_is_leap_year(): assert is_leap_year(2000) == "YES" assert is_leap_year(1900) == "NO" assert is_leap_year(2004) == "YES" assert is_leap_year(1999) == "NO" assert is_leap_year(1600) == "YES" assert is_leap_year(2020) == "YES" assert is_le...
[ { "docstring": "Returns 'YES' if the given year is a leap year, 'NO' otherwise.", "function_declaration": "def is_leap_year(year):", "function_name": "is_leap_year", "parameter_list": "(year)" }, { "docstring": "Given a list of years, returns a list indicating whether each year is a leap yea...
[ 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_leap_year(year):\n \"\"\"\n Determines if a given year is a leap year.\n\n :param year: int, the year to check\n :return: str, \"YES\" i...
trial_gpt4o_2
{ "original_instruction": "Kevin is building his skills in competitive programming and stumbled upon a problem involving leap years. He decided to write a program that checks if a given year is a leap year or not. However, Kevin later found out that the rules he had were not correct, and he needs your help to verify ...
0.629739
Code_Contests_49161
C
[ "is_leap_year", "leap_years" ]
2
[ [ "leap_years", "is_leap_year" ] ]
1
[]
false
[]
false
pytest
true
[]
true
e5bdc6a5019b63928d5fd223ff340249775662e7
0b591c43d5ccee630932d1e6cae8d4fa5b1b7ce6
v1.0
complete
Code_Contests
Code_Contests_47281_C
def check_subarray_square(t: int, cases: List[Tuple[int, List[int]]]) -> List[str]: """ Determines whether there exists a subarray with length greater than 1 such that the product of its elements is a perfect square. Args: t (int): Number of test cases. cases (List[Tuple[int, List[int]]]): List...
def is_perfect_square(x): """ Checks if a number x is a perfect square. """ if x < 0: return False root = int(x**0.5) return root * root == x def has_subarray_with_square_product(arr): """ Determines if there exists a subarray with length greater than 1 such that the produc...
from solution import check_subarray_square def test_case_1(): t = 3 cases = [ (4, [1, 2, 2, 1]), (3, [3, 4, 2]), (5, [2, 3, 4, 6, 5]) ] expected = ["YES", "NO", "YES"] assert check_subarray_square(t, cases) == expected def test_case_2(): t = 1 cases = [ (2, ...
[ { "docstring": "Checks if a number x is a perfect square.", "function_declaration": "def is_perfect_square(x):", "function_name": "is_perfect_square", "parameter_list": "(x)" }, { "docstring": "Determines if there exists a subarray with length greater than 1 such \nthat the product of its el...
[ 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 \"\"\"\n Returns True if the num is a perfect square, False otherwise.\n \"\"\"\n if num < 0:\n ...
trial_gpt4o_1
{ "original_instruction": "You are given an array of integers. Your task is to determine whether there exists a subarray with length greater than 1 such that the product of its elements is a perfect square.\n\nInput\nThe first line of the input contains an integer T denoting the number of test cases. Each of the next...
0.630984
Code_Contests_47281
C
[ "is_perfect_square", "has_subarray_with_square_product", "main", "check_subarray_square" ]
4
[ [ "check_subarray_square", "main" ], [ "has_subarray_with_square_product", "is_perfect_square" ] ]
2
[]
false
[]
false
pytest
true
[]
true
4e2626b637dd806cfa591d8c4ce762c205f0f4ec
9093dfe7ec0c19de958f2752d4b6de9bed1c28e4
v1.0
complete
Code_Contests
Code_Contests_48654_C
def generate_primes_upto(n): """ Generates all prime numbers up to n using the Sieve of Eratosthenes. """ pass def product_of_primes(k): """ Returns the product of the first k prime numbers modulo 10^9 + 7. >>> product_of_primes(3) 30 >>> product_of_primes(4) 210 """ pas...
def generate_primes_upto(n): """ Generates all prime numbers up to n using the Sieve of Eratosthenes. """ is_prime = [True] * (n + 1) p = 2 while p * p <= n: if is_prime[p]: for i in range(p * p, n + 1, p): is_prime[i] = False p += 1 primes = [p fo...
def test_generate_primes_upto(): assert generate_primes_upto(10) == [2, 3, 5, 7] assert generate_primes_upto(20) == [2, 3, 5, 7, 11, 13, 17, 19] def test_product_of_primes(): assert product_of_primes(3) == 30 assert product_of_primes(4) == 210 assert product_of_primes(5) == 2310 def test_primes_pr...
[ { "docstring": "Generates all prime numbers up to n using the Sieve of Eratosthenes.", "function_declaration": "def generate_primes_upto(n):", "function_name": "generate_primes_upto", "parameter_list": "(n)" }, { "docstring": "Returns the product of the first k prime numbers modulo 10^9 + 7....
[ 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 generate_primes_upto(n):\n \"\"\"\n Generates all prime numbers up to n using the Sieve of Eratosthenes.\n \"\"\"\n is_prime = [True] * (n ...
trial_gpt4o_0
{ "original_instruction": "Two scientists, Dr. Xavier and Dr. Yara, are collaborating on a special experiment. They are using a computer simulation that involves prime numbers and dynamic arrays. The experiment starts with an empty list, and the scientists take turns adding elements to this list. \n\nDr. Xavier alway...
0.60444
Code_Contests_48654
C
[ "generate_primes_upto", "product_of_primes", "primes_product_for_turns", "main" ]
4
[ [ "primes_product_for_turns", "product_of_primes" ], [ "product_of_primes", "generate_primes_upto" ] ]
2
[]
false
[]
false
pytest
false
[]
true
04e5bd92f343f9e84115fd42b5a3306be83422b0
f44f7491262a4c2b25bf7c7a94e8f1c2274ffd75
v1.0
complete
Code_Contests
Code_Contests_49383_C
from typing import List def rotate_90(mat: List[List[int]]) -> List[List[int]]: """ Rotate the matrix 90 degrees clockwise. >>> rotate_90([[1,2,3], [4,5,6], [7,8,9]]) [[7,4,1], [8,5,2], [9,6,3]] """ pass def is_rotation(a: List[List[int]], b: List[List[int]]) -> bool: """Check if matrix b is a...
def rotate_90(mat): return [list(row) for row in zip(*mat[::-1])] def is_rotation(a, b): if a == b: return True rotated_90 = rotate_90(a) if rotated_90 == b: return True rotated_180 = rotate_90(rotated_90) if rotated_180 == b: return True rotated_270 = rotate_90(rota...
from solution import check_matrix_rotation, rotate_90 def test_rotate_90(): assert rotate_90([[1,2,3], [4,5,6], [7,8,9]]) == [[7,4,1], [8,5,2], [9,6,3]] def test_is_rotation_0(): assert check_matrix_rotation(3, 3, [[1,2,3], [4,5,6], [7,8,9]], [[1,2,3], [4,5,6], [7,8,9]]) == "Yes" def test_is_rotation_90(): ...
[ { "docstring": null, "function_declaration": "def rotate_90(mat):", "function_name": "rotate_90", "parameter_list": "(mat)" }, { "docstring": null, "function_declaration": "def is_rotation(a, b):", "function_name": "is_rotation", "parameter_list": "(a, b)" }, { "docstring...
[ 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 rotate_90(mat):\n return [list(row) for row in zip(*mat[::-1])]\n\ndef is_rotation(a, b):\n if a == b:\n return True\n rotated_90 = rot...
trial_gpt4o_0
{ "original_instruction": "You are given two matrices `A` and `B` of size `m x n`. Write a function to check if matrix `B` can be obtained by rotating matrix `A` 0, 90, 180, or 270 degrees in a clockwise direction.\n\nConstraints:\n\n* $1 \\leq m, n \\leq 10$\n\nInput:\n\nThe input is given as two matrices in the fol...
0.54844
Code_Contests_49383
C
[ "rotate_90", "is_rotation", "check_matrix_rotation" ]
3
[ [ "check_matrix_rotation", "is_rotation" ], [ "is_rotation", "rotate_90" ] ]
2
[]
false
[]
false
pytest
true
[]
true
9aaf85cc1a8a9e3f2c4c0b9084d1c6a623a40b82
31a78e5108ac6213ec4a76b5404b50e2f5c7ce4d
v1.0
complete
Code_Contests
Code_Contests_49412_C
class TreeNode: def __init__(self, value): self.value = value self.left = None self.right = None def build_tree(nodes_info): nodes = {} for value, left, right in nodes_info: if value not in nodes: nodes[value] = TreeNode(value) node = nodes[value] ...
class TreeNode: def __init__(self, value): self.value = value self.left = None self.right = None def build_tree(nodes_info): nodes = {} for value, left, right in nodes_info: if value not in nodes: nodes[value] = TreeNode(value) node = nodes[value] ...
def test_calculate_tree_depths(): test_cases = [ ([ (1, 2, 3), (2, -1, -1), (3, -1, -1) ], 1), ([ (1, 2, 3), (2, -1, -1), (3, 4, 5), (4, -1, -1), (5, -1, -1) ], 2) ] for nodes...
[]
[ 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, value):\n self.value = value\n self.left = None\n self.right = None\n\ndef build_tree(nodes_in...
trial_gpt4o_0
{ "original_instruction": "Three young friends, Alex, Charlie, and Jordan, are interested in a game involving binary trees. They define a binary tree as a data structure in which each node can have at most two children referred to as the left child and the right child. As part of their game, they want to calculate th...
0.555787
Code_Contests_49412
C
[ "build_tree", "max_depth", "calculate_tree_depths", "main" ]
4
[ [ "calculate_tree_depths", "build_tree" ], [ "calculate_tree_depths", "max_depth" ] ]
2
[]
false
[ "TreeNode" ]
true
pytest
false
[]
true
79cab24f16ae421064cb5100f2b27aee94e9ede6
de24a58cf929d37f291b352c5499c4080c26a920
v1.0
complete
Code_Contests
Code_Contests_49204_C
def preprocess_tracks(n, tracks): """ Preprocess the tracks to create data structures for track counts and direct connections. """ pass def process_queries(q, queries, track_count, direct_connections): """ Processes the queries using the preprocessed track count and direct connections. """ pass...
def preprocess_tracks(n, tracks): from collections import defaultdict # Dictionary to store counts of tracks connected to each station track_count = defaultdict(int) # Sets to store unique connections direct_connections = defaultdict(set) for a, b in tracks: track_count[a] += 1 ...
from solution import preprocess_tracks, process_queries, railway_system def test_preprocess_tracks(): tracks = [ (1, 2), (2, 3), (3, 4), (4, 5) ] track_count, direct_connections = preprocess_tracks(4, tracks) assert track_count == {1: 1, 2: 2, 3: 2, 4: 2, 5: 1} asser...
[ { "docstring": null, "function_declaration": "def preprocess_tracks(n, tracks):", "function_name": "preprocess_tracks", "parameter_list": "(n, tracks)" }, { "docstring": null, "function_declaration": "def process_queries(q, queries, track_count, direct_connections):", "function_name"...
[ 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 collections import defaultdict\n\nclass RailwaySystem:\n def __init__(self, n_tracks):\n # Initialize adjacency list to represent the railwa...
trial_gpt4o_3
{ "original_instruction": "A railway system consists of several tracks, each connecting two different stations. Each station is assigned a unique positive integer as its identifier. In any track, a train can travel in both directions.\n\nA query can be made to find out:\n1. How many railway tracks are directly connec...
0.584873
Code_Contests_49204
C
[ "preprocess_tracks", "process_queries", "railway_system" ]
3
[ [ "railway_system", "preprocess_tracks" ], [ "railway_system", "process_queries" ] ]
2
[ "process_queries" ]
false
[]
false
pytest
true
[]
true
99c5b6dbd1114a5c22898ada6d38443699315a3b
0ae96be4507ca368c1ab4292c6a28b6ac86d30cf
v1.0
complete
Code_Contests
Code_Contests_48289_C
def is_prime(n: int) -> bool: """ Helper function to check if a number is a prime. >>> is_prime(1) False >>> is_prime(2) True >>> is_prime(3) True >>> is_prime(4) False >>> is_prime(29) True >>> is_prime(10) False >>> is_prime(11) True """ def filter_primes(lst: List[int]) -> List[i...
def is_prime(n): """ Helper function to check if a number is a prime. """ if n <= 1: return False if n == 2: return True # 2 is the only even prime number if n % 2 == 0: return False max_divisor = int(n**0.5) + 1 for d in range(3, max_divisor, 2): if n % ...
from solution import is_prime, filter_primes def test_is_prime(): assert not is_prime(1) # 1 is not prime assert is_prime(2) # 2 is prime assert is_prime(3) # 3 is prime assert not is_prime(4) # 4 is not prime assert is_prime(29) # 29 is prime assert not is_prime(10) #...
[ { "docstring": "Helper function to check if a number is a prime.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Returns a list containing only the prime numbers from the input list.", "function_declaration": "def filt...
[ 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(n):\n \"\"\"\n Helper function to check if a number is a prime.\n \"\"\"\n if n <= 1:\n return False\n if n == 2:\n ...
trial_gpt4o_0
{ "original_instruction": "Write a function that takes a list of integers and returns a new list containing only the prime numbers from the original list.\n\nInput\n\nA list of integers.\n\nOutput\n\nA list containing only the prime numbers from the input list. The order of the elements in the output list should be t...
0.768634
Code_Contests_48289
C
[ "is_prime", "filter_primes" ]
2
[ [ "filter_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
5a8ee8b46718dacedd76d772a22c1a2247c30532
3dd8043b7e024d1b06599129e9ac0f7c44e1b4c7
v1.0
complete
Code_Contests
Code_Contests_49472_C
def count_triplets(arr: List[int]) -> int: """ Count the number of triplets (a[i], a[j], a[k]) in the array such that a[i] < a[j] < a[k] and i < j < k. >>> count_triplets([4, 7, 1, 9, 3, 10, 5]) 7 >>> count_triplets([4, 3, 2, 1]) 0 >>> count_triplets([1, 2, 3]) 1 """ from typing import ...
def count_triplets(arr): n = len(arr) if n < 3: return 0 count = 0 for i in range(n): for j in range(i+1, n): for k in range(j+1, n): if arr[i] < arr[j] < arr[k]: count += 1 return count def count_triplets_from_input(n, ...
from solution import count_triplets_from_input def test_sample_input(): assert count_triplets_from_input(7, "4 7 1 9 3 10 5") == 7 def test_no_triplets(): assert count_triplets_from_input(4, "4 3 2 1") == 0 def test_single_triplet(): assert count_triplets_from_input(3, "1 2 3") == 1 def test_multiple_tr...
[ { "docstring": null, "function_declaration": "def count_triplets(arr):", "function_name": "count_triplets", "parameter_list": "(arr)" }, { "docstring": null, "function_declaration": "def count_triplets_from_input(n, elements):", "function_name": "count_triplets_from_input", "para...
[ 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 count_triplets(n, arr):\n \"\"\"\n Count the number of triplets (a[i], a[j], a[k]) such that a[i] < a[j] < a[k] \n and i < j < k in the array ...
trial_gpt4o_4
{ "original_instruction": "A triplet in an array is defined as a sequence of three elements (a[i], a[j], a[k]) such that a[i] < a[j] < a[k] and i < j < k. Given an array of distinct integers, your task is to determine the number of such triplets in the array.\n\nINPUT\nThe first line contains a single integer n, the ...
0.646729
Code_Contests_49472
C
[ "count_triplets", "count_triplets_from_input" ]
2
[ [ "count_triplets_from_input", "count_triplets" ] ]
1
[]
false
[]
false
pytest
true
[]
true
05d441fc8581878b512e02f42b89c46f7c90a77f
466521b6a36c0d86c0d4d79cc8a70ff6757cfa03
v1.0
complete
Code_Contests
Code_Contests_48210_C
from typing import List, Tuple def edmonds_karp(n: int, m: int, edges: List[Tuple[int, int, int]]) -> int: """ Calculate the maximum flow from the source node (0) to sink node (n-1) using the Edmonds-Karp algorithm. Args: n (int): The number of reservoirs (nodes). m (int): The number of pipes...
from collections import deque def bfs(capacity, source, sink, parent): visited = [False] * len(capacity) queue = deque([source]) visited[source] = True while queue: current = queue.popleft() for adj, cap in enumerate(capacity[current]): if not visited[adj] and cap > 0: ...
def test_small_case(): n = 6 m = 9 edges = [ (0, 1, 16), (0, 2, 13), (1, 2, 10), (1, 3, 12), (2, 1, 4), (2, 4, 14), (3, 2, 9), (3, 5, 20), (4, 3, 7), (4, 5, 4) ] assert edmonds_karp(n, m, edges) == 23 def test_single_pi...
[ { "docstring": null, "function_declaration": "def bfs(capacity, source, sink, parent):", "function_name": "bfs", "parameter_list": "(capacity, source, sink, parent)" }, { "docstring": null, "function_declaration": "def edmonds_karp(n, m, edges):", "function_name": "edmonds_karp", ...
[ 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 deque\n\ndef bfs_capacity(graph, source, sink, parent):\n visited = set()\n queue = deque([source])\n visited.add(source)\...
trial_gpt4o_2
{ "original_instruction": "You are tasked with maintaining a water distribution network. The network consists of N reservoirs connected by M unidirectional pipes. Each reservoir is represented by a node, and each pipe is represented by a directed edge with a specific flow capacity. The goal is to maximize the water f...
0.587273
Code_Contests_48210
C
[ "bfs", "edmonds_karp" ]
2
[ [ "edmonds_karp", "bfs" ] ]
1
[]
false
[]
false
pytest
false
[]
true
b5ae6f6ec9482c70f590560c0317ff3dbd9359a8
10e19a8a5e11be76c8ffabad3e62fe255a6c0ff3
v1.0
complete
Code_Contests
Code_Contests_49752_C
def pascal_row(n: int) -> list: """ Generate the n-th row of Pascal's triangle. >>> pascal_row(0) [1] >>> pascal_row(1) [1, 1] >>> pascal_row(2) [1, 2, 1] >>> pascal_row(3) [1, 3, 3, 1] >>> pascal_row(4) [1, 4, 6, 4, 1] >>> pascal_row(5) [1, 5, 10, 10, 5, 1] """
def factorial(num): if num == 0 or num == 1: return 1 fact = 1 for i in range(2, num + 1): fact *= i return fact def pascal_row(n): row = [] for k in range(n + 1): row.append(factorial(n) // (factorial(k) * factorial(n - k))) return row
from solution import pascal_row def test_pascal_row_zero(): assert pascal_row(0) == [1] def test_pascal_row_one(): assert pascal_row(1) == [1, 1] def test_pascal_row_two(): assert pascal_row(2) == [1, 2, 1] def test_pascal_row_three(): assert pascal_row(3) == [1, 3, 3, 1] def test_pascal_row_four()...
[ { "docstring": null, "function_declaration": "def factorial(num):", "function_name": "factorial", "parameter_list": "(num)" }, { "docstring": null, "function_declaration": "def pascal_row(n):", "function_name": "pascal_row", "parameter_list": "(n)" } ]
[ 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 factorial(num):\n if num == 0 or num == 1:\n return 1\n fact = 1\n for i in range(2, num + 1):\n fact *= i\n return fact\n\nd...
trial_gpt4o_0
{ "original_instruction": "You are given a positive integer `n`. Your task is to generate an n-th row of Pascal's triangle.\n\nPascal's triangle is a triangular array of the binomial coefficients. The elements of the n-th row of Pascal's triangle are given by where `C(n, k) = n! / (k! * (n - k)!)`, `0 <= k <= n`, an...
0.582358
Code_Contests_49752
C
[ "factorial", "pascal_row" ]
2
[ [ "pascal_row", "factorial" ] ]
1
[]
false
[]
false
pytest
true
[]
true
5e2c643596670a19b4b45348695f7ca724be6c79
0c6d02d1040070ccb46c21dde25c0b09ab1c1411
v1.0
complete
Code_Contests
Code_Contests_49743_C
def is_prime(num): """ Helper function to check if a number is prime. >>> is_prime(2) True >>> is_prime(4) False """ pass def longest_prime_subsequence_length(n, a): """ Returns the length of the longest subsequence that consists of prime numbers only. >>> longest_...
def is_prime(num): """ Helper function to check if a number is prime. """ if num <= 1: return False if num == 2: return True if num % 2 == 0: return False sq = int(num**0.5) + 1 for i in range(3, sq, 2): if num % i == 0: return False return...
from solution import is_prime, longest_prime_subsequence_length def test_is_prime(): assert is_prime(2) == True assert is_prime(3) == True assert is_prime(4) == False assert is_prime(7) == True assert is_prime(9) == False assert is_prime(11) == True assert is_prime(1) == False assert is...
[ { "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 length of the longest subsequence that consists of prime numbers only.", "function_declarat...
[ 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 Determines if a number is prime.\n A prime number is a number greater than 1 that has no positive divisors \n oth...
trial_gpt4o_1
{ "original_instruction": "You are given an array of n integers. Find the length of the longest subsequence that consists of prime numbers only.\n\nA subsequence is obtained by deleting zero or more elements from the array without changing the order of the remaining elements. A prime number is a number greater than 1...
0.788992
Code_Contests_49743
C
[ "is_prime", "longest_prime_subsequence_length" ]
2
[ [ "longest_prime_subsequence_length", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
26a844ef1175bc13030ee5d54197b1d952405d75
b6341feb1f2ade9d4c4d66145c3bad5b11935f19
v1.0
complete
Code_Contests
Code_Contests_47844_C
class TreeNode: def __init__(self, value=0): self.value = value self.left = None self.right = None def longest_path_length(root): """Find the length of the longest path between any two nodes in the binary tree. >>> longest_path_length([1, 2, 3, 4, 5], [(1, 2), (1, 3), (2, 4), (2, 5)...
class TreeNode: def __init__(self, value=0): self.value = value self.left = None self.right = None def longest_path_length(root): def dfs(node): nonlocal diameter if not node: return 0 left_length = dfs(node.left) right_length = dfs(node.right...
def test_find_longest_path(): assert find_longest_path(5, [1, 2, 3, 4, 5], [(1, 2), (1, 3), (2, 4), (2, 5)]) == 3 assert find_longest_path(3, [1, 2, 3], [(1, 2), (1, 3)]) == 2 assert find_longest_path(6, [1, 2, 3, 4, 5, 6], [(1, 2), (1, 3), (2, 4), (2, 5), (5, 6)]) == 4 def test_single_path_tree(): ass...
[]
[ 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": "class TreeNode:\n def __init__(self, value):\n self.value = value\n self.left = None\n self.right = None\n\ndef find_longest_path_l...
trial_gpt4o_7
{ "original_instruction": "You are given a binary tree with N nodes, where each node has a unique integer value. The task is to find the length of the longest path between any two nodes in the tree. The path may or may not pass through the root of the tree.\n\nA binary tree is defined as:\n\n- A tree in which each no...
0.57424
Code_Contests_47844
C
[ "longest_path_length", "build_tree", "find_longest_path" ]
3
[ [ "find_longest_path", "build_tree" ], [ "find_longest_path", "longest_path_length" ] ]
2
[]
false
[ "TreeNode" ]
true
pytest
false
[]
true
cc0cffc67cf28887d6d6a92edf8f9d216e047bbc
1da249d463e9b6b07db803a2270aa361a47701ca
v1.0
complete
Code_Contests
Code_Contests_49223_C
class TreeNode: def __init__(self, val=0, left=None, right=None): self.val = val self.left = left self.right = right def sumOfLeftLeaves(root: TreeNode) -> int: """ Calculate the sum of all left leaves in a binary tree. >>> Tree = TreeNode(3, TreeNode(9), TreeNode(20, TreeNode(15), ...
class TreeNode: def __init__(self, val=0, left=None, right=None): self.val = val self.left = left self.right = right def is_leaf(node: TreeNode) -> bool: return node is not None and node.left is None and node.right is None def sumOfLeftLeaves(root: TreeNode) -> int: if root is None...
from solution import TreeNode, sumOfLeftLeaves def test_example_tree(): # Tree: # 3 # / \ # 9 20 # / \ # 15 7 root = TreeNode(3) root.left = TreeNode(9) root.right = TreeNode(20) root.right.left = TreeNode(15) root.right.right = TreeNode(7) asser...
[]
[ 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": "Ariana is learning about binary trees in her computer science class. Given a binary tree, she needs to find the sum of all left leaves.\n\nA leaf is a node with no children. A left leaf is a leaf node that is the left child of its parent.\n\nPlease help Ariana by writing a function `sumOfLe...
0.556411
Code_Contests_49223
C
[ "is_leaf", "sumOfLeftLeaves" ]
2
[ [ "sumOfLeftLeaves", "is_leaf" ] ]
1
[]
false
[ "TreeNode" ]
true
pytest
true
[]
true
24bb111010e37c6fe60400d2723b7f38b5e3b2fd
0f4b5453af401b306efb4decee2cf794f7046b7d
v1.0
complete
Code_Contests
Code_Contests_49082_C
import re from typing import List def predict_category(book_content: str) -> int: """ Predicts the category of the book based on the content using simplified keyword matching. >>> predict_category("In the future, humanity may encounter alien spaceships and robots.") 1 >>> predict_category("The...
import re from collections import Counter import random # Predefined categories and related sample words for simplification. CATEGORY_WORDS = { 1: ["space", "robot", "time", "future", "alien"], 2: ["love", "romance", "heart", "kiss", "wedding"], 3: ["murder", "detective", "mystery", "crime", "clue"], 4...
def test_predict_category_scifi(): content = "In the future, humanity may encounter alien spaceships and robots." assert predict_category(content) == 1 def test_predict_category_romance(): content = "Their love story began with a romantic wedding by the beach." assert predict_category(content) == 2 de...
[ { "docstring": "Predicts the category of the book based on the content using\nsimplified keyword matching.", "function_declaration": "def predict_category(book_content):", "function_name": "predict_category", "parameter_list": "(book_content)" }, { "docstring": "Classifies the book into a ca...
[ 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": "import zipfile\nimport os\nimport requests\nfrom sklearn.feature_extraction.text import TfidfVectorizer\nfrom sklearn.naive_bayes import MultinomialNB\nimp...
trial_gpt4o_2
{ "original_instruction": "A company is creating a system to manage the books in their library. Each book has a unique identifier and falls into one of the following categories represented by integers from 1 to 5:\n\n- 1: Science Fiction\n- 2: Romance\n- 3: Mystery\n- 4: Biography\n- 5: Philosophy\n\nThey have provid...
0.524236
Code_Contests_49082
C
[ "predict_category", "classify_book" ]
2
[ [ "classify_book", "predict_category" ] ]
1
[]
false
[]
false
pytest
false
[]
true
ae0e8e111fe9e886eb067fc593e76bf53c97035f
0bb4c1b9a650f6638394b386aab099ac629f02c2
v1.0
complete
Code_Contests
Code_Contests_49799_C
from typing import List def is_prime(num: int) -> bool: """ Determines if a number is prime. >>> is_prime(2) True >>> is_prime(3) True >>> is_prime(4) False """ def sum_of_primes_up_to_n(n: int) -> int: """ Evaluates the sum of prime numbers up to integer n. >>> sum_of_primes_u...
def is_prime(num): if num <= 1: return False if num == 2: return True if num % 2 == 0: return False max_divisor = int(num ** 0.5) + 1 for divisor in range(3, max_divisor, 2): if num % divisor == 0: return False return True def sum_of_primes_up_to_n(n)...
from solution import is_prime, sum_of_primes_up_to_n, process_input def test_is_prime(): assert is_prime(2) == True assert is_prime(3) == True assert is_prime(4) == False assert is_prime(11) == True assert is_prime(15) == False def test_sum_of_primes_up_to_n(): assert sum_of_primes_up_to_n(10)...
[ { "docstring": null, "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": null, "function_declaration": "def sum_of_primes_up_to_n(n):", "function_name": "sum_of_primes_up_to_n", "parameter_list": "(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 is_prime(num):\n if num <= 1:\n return False\n if num == 2:\n return True\n if num % 2 == 0:\n return False\n max_divi...
trial_gpt4o_0
{ "original_instruction": "You are tasked with evaluating the sum of the series of prime numbers up to a provided integer n.\n\nInput\n\nAn integer t, 1 ≤ t ≤ 100, denoting the number of test cases, followed by t lines, each containing a single integer n, 1 ≤ n ≤ 10^3.\n\nOutput\n\nFor each integer n given in the inp...
0.734702
Code_Contests_49799
C
[ "is_prime", "sum_of_primes_up_to_n", "process_input" ]
3
[ [ "process_input", "sum_of_primes_up_to_n" ], [ "sum_of_primes_up_to_n", "is_prime" ] ]
2
[ "process_input" ]
false
[]
false
pytest
true
[]
true
ecbc1e85ff1f2a8fe9a47a19a73da0291d4cf6ee
d3ac8b0ccbb0f592b6064d195218ea92f65bac55