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_72_C
def minimum_cost_to_connect_all(n: int, m: int, roads: List[Tuple[int, int, int]]) -> int: """ Find the minimum total cost required to construct a subset of proposed roads such that all neighborhoods remain connected. If it is not possible to connect all neighborhoods, return -1. Parameters: n (in...
def find(parent, i): if parent[i] == i: return i else: parent[i] = find(parent, parent[i]) return parent[i] def union(parent, rank, x, y): xroot = find(parent, x) yroot = find(parent, y) if rank[xroot] < rank[yroot]: parent[xroot] = yroot elif rank[xroot] > ...
import pytest from solution import minimum_cost_to_connect_all def test_example(): n = 4 m = 5 roads = [ (1, 2, 3), (2, 3, 4), (3, 4, 5), (1, 4, 1), (2, 4, 2) ] assert minimum_cost_to_connect_all(n, m, roads) == 7 def test_not_enough_roads(): n = 4 m...
[ { "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 parent[i] = find(parent, parent[i])\n return parent[i]\n\ndef uni...
trial_gpt4o_0
{ "original_instruction": "In a small town, the local government is planning to construct a series of new roads to improve connectivity among several neighborhoods. The town has n neighborhoods numbered from 1 to n. Currently, there are no roads directly connecting any neighborhoods.\n\nThe government has a list of m...
0.707891
Code_Contests_72
C
[ "find", "union", "minimum_cost_to_connect_all" ]
3
[ [ "minimum_cost_to_connect_all", "find" ], [ "minimum_cost_to_connect_all", "union" ], [ "union", "find" ] ]
3
[]
false
[]
false
pytest
true
[]
true
ebef394093c2bac966eb24dff4aa4c9c34c028ad
17ec35f2a680a789dbce411b69680f9accd4e463
v1.0
complete
Code_Contests
Code_Contests_133_C
def is_valid_passcode(passcodes: List[str]) -> List[str]: """ Determine if each passcode is valid. A passcode is considered valid if it does not contain any two adjacent digits that are the same. >>> is_valid_passcode(["123456"]) ["Valid"] >>> is_valid_passcode(["112345"]) ["Invalid"] ...
def is_valid_passcode(passcodes): results = [] for passcode in passcodes: if all(passcode[i] != passcode[i + 1] for i in range(len(passcode) - 1)): results.append("Valid") else: results.append("Invalid") return results def check_passcodes(T, passcodes): results =...
from solution import is_valid_passcode, check_passcodes def test_is_valid_passcode(): assert is_valid_passcode(["123456"]) == ["Valid"] assert is_valid_passcode(["112345"]) == ["Invalid"] assert is_valid_passcode(["121212"]) == ["Valid"] assert is_valid_passcode(["987654321"]) == ["Valid"] assert i...
[ { "docstring": null, "function_declaration": "def is_valid_passcode(passcodes):", "function_name": "is_valid_passcode", "parameter_list": "(passcodes)" }, { "docstring": null, "function_declaration": "def check_passcodes(T, passcodes):", "function_name": "check_passcodes", "param...
[ 1, 1 ]
2
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_valid_passcode(passcode):\n \"\"\"\n Determines if the given passcode is valid. A passcode is valid if it does not contain \n any two adjac...
trial_gpt4o_2
{ "original_instruction": "A company wants to design a security system that allows employees to enter the building with a special passcode. Each passcode is represented by a string composed solely of digits ('0' to '9'). The passcode is considered valid if it does not contain any two adjacent digits that are the same...
0.593085
Code_Contests_133
C
[ "is_valid_passcode", "check_passcodes" ]
2
[ [ "check_passcodes", "is_valid_passcode" ] ]
1
[]
false
[]
false
pytest
true
[]
true
e195df2156adfba4831d260e9ac5e073c4464762
4a7a5865592745e4bf0bd31a5523908546ae9baa
v1.0
complete
Code_Contests
Code_Contests_85_C
from typing import List, Tuple def is_network_resilient(n: int, m: int, connections: List[Tuple[int, int]]) -> str: """ Determine if the network is resilient by checking the connectivity of each subset of nodes after removing one node. """ pass def evaluate_datasets(datasets: List[Tuple[int, int, List...
def is_network_resilient(n, m, connections): from collections import defaultdict, deque def bfs(start, removed): visited = [False] * n queue = deque([start]) visited[start] = True while queue: node = queue.popleft() for neighbor in graph[node...
def test_is_network_resilient_yes(): n = 4 m = 4 connections = [(0, 1), (1, 2), (2, 3), (3, 0)] assert is_network_resilient(n, m, connections) == "Yes" def test_is_network_resilient_no(): n = 4 m = 3 connections = [(0, 1), (1, 2), (2, 3)] assert is_network_resilient(n, m, connections) =...
[ { "docstring": null, "function_declaration": "def is_network_resilient(n, m, connections):", "function_name": "is_network_resilient", "parameter_list": "(n, m, connections)" }, { "docstring": null, "function_declaration": "def evaluate_datasets(datasets):", "function_name": "evaluate...
[ 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 defaultdict\n\ndef is_resilient(n, connections):\n def dfs(u, visited, parent):\n visited[u] = True\n for v in gra...
trial_gpt4o_1
{ "original_instruction": "A network of computers is represented as an undirected graph where nodes are computers and edges represent a direct connection between two computers. Each computer can send data to any other computer directly if they have a direct connection, or indirectly through other computers.\n\nA netw...
0.510341
Code_Contests_85
C
[ "is_network_resilient", "evaluate_datasets", "parse_input" ]
3
[ [ "evaluate_datasets", "is_network_resilient" ] ]
1
[ "parse_input" ]
false
[]
false
pytest
false
[]
true
067946c77ebfd56d738813cea695f528e29d4c07
69ff302ef25e7fac312e5a8cedd3d2829c87b864
v1.0
complete
Code_Contests
Code_Contests_295_C
def max_sum_of_subarray(arr): """ Given an array of positive integers, find the largest sum of a contiguous subarray using the divide-and-conquer approach. Your function should use recursion to solve the problem. >>> max_sum_of_subarray([1]) 1 >>> max_sum_of_subarray([-1]) -1 >>> max_su...
def max_crossing_sum(arr, left, mid, right): """ Find the maximum sum of a subarray that crosses the midpoint. """ left_sum = float('-inf') sum = 0 for i in range(mid, left - 1, -1): sum += arr[i] if sum > left_sum: left_sum = sum right_sum = float('-...
from solution import max_sum_of_subarray def test_single_element(): assert max_sum_of_subarray([1]) == 1 assert max_sum_of_subarray([-1]) == -1 def test_all_positive(): assert max_sum_of_subarray([1, 2, 3, 4, 5]) == 15 def test_all_negative(): assert max_sum_of_subarray([-1, -2, -3, -4]) == -1 def t...
[ { "docstring": "Find the maximum sum of a subarray that crosses the midpoint.", "function_declaration": "def max_crossing_sum(arr, left, mid, right):", "function_name": "max_crossing_sum", "parameter_list": "(arr, left, mid, right)" }, { "docstring": "Find the maximum sum of a contiguous sub...
[ 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_crossing_sum(arr, left, mid, right):\n \"\"\"\n Helper function to find the maximum crossing sum.\n \"\"\"\n # Include elements on left...
trial_gpt4o_2
{ "original_instruction": "Given an array of positive integers, find the largest sum of a contiguous subarray using the divide-and-conquer approach. Your function should use recursion to solve the problem.\n\nInput\n\nThe input consists of:\n- The first line is an integer n (1 ≤ n ≤ 300000), the number of elements in...
0.787251
Code_Contests_295
C
[ "max_crossing_sum", "max_sub_array_sum", "max_sum_of_subarray" ]
3
[ [ "max_sub_array_sum", "max_crossing_sum" ], [ "max_sum_of_subarray", "max_sub_array_sum" ] ]
2
[]
false
[]
false
pytest
true
[]
true
c3d32939054a2e4d0fd86c82c01cef823d828986
3733b8a1ef240447a03f05af249bfdf84ee409ab
v1.0
complete
Code_Contests
Code_Contests_300_C
from typing import List def spread_forest(N: int, M: int, T: int, forest: List[str]) -> List[str]: """Simulate the spread of the magical aura in the enchanting forest after T hours. Args: N: number of rows in the forest grid. M: number of columns in the forest grid. T: number of hours. for...
def spread_forest(N, M, T, forest): def spread_once(forest): new_forest = [row[:] for row in forest] # Copy the current forest for r in range(N): for c in range(M): if forest[r][c] == '#': # Tree found, spread to adjacent cells if r > 0 and fo...
def test_enchanting_forest_sample_case(): N, M, T = 3, 3, 2 grid = [ ".#.", "...", "#.." ] expected_output = [ "###", "###", "###" ] assert spread_forest(N, M, T, grid) == expected_output def test_enchanting_forest_no_initial_trees(): N, M, T ...
[ { "docstring": null, "function_declaration": "def spread_forest(N, M, T, forest):", "function_name": "spread_forest", "parameter_list": "(N, M, T, forest)" }, { "docstring": null, "function_declaration": "def enchanting_forest_solution(N, M, T, grid):", "function_name": "enchanting_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": "def spread_forest(N, M, T, forest):\n def spread_once(forest):\n new_forest = [row[:] for row in forest] # Copy the current forest\n \n ...
trial_gpt4o_0
{ "original_instruction": "You are given an enchanting forest which is a grid of size NxM. Each cell in the grid either contains a tree (represented by '#') or is empty (represented by '.'). A tree can spread its magical aura if there is an empty cell adjacent to it (in the four possible directions: north, south, eas...
0.481242
Code_Contests_300
C
[ "spread_forest", "enchanting_forest_solution" ]
2
[ [ "enchanting_forest_solution", "spread_forest" ] ]
1
[]
false
[]
false
pytest
false
[]
true
1288833b376befeec83813a4b1a6a20c8ac36c37
50a6c1693ca094ec66191349cf7973b25cb657db
v1.0
complete
Code_Contests
Code_Contests_353_C
from typing import List def is_prime(num: int) -> bool: """ Check if a number is prime. >>> is_prime(2) == True >>> is_prime(3) == True >>> is_prime(4) == False >>> is_prime(5) == True >>> is_prime(29) == True >>> is_prime(1) == False """ def smallest_prime_greater_or_equal(n: int)...
def is_prime(num): """ Check if a number is prime. """ if num <= 1: return False if num <= 3: return True if num % 2 == 0 or num % 3 == 0: return False i = 5 while i * i <= num: if num % i == 0 or num % (i + 2) == 0: return False i += 6...
from solution import is_prime, smallest_prime_greater_or_equal def test_is_prime(): assert is_prime(2) == True assert is_prime(3) == True assert is_prime(4) == False assert is_prime(5) == True assert is_prime(29) == True assert is_prime(1) == False def test_smallest_prime_greater_or_equal(): ...
[ { "docstring": "Check if a number is prime.", "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": "Finds the smallest prime number greater than or equal to n.", "function_declaration": "def smallest_prime_greater_or_equal...
[ 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(number):\n if number <= 1:\n return False\n if number <= 3:\n return True\n if number % 2 == 0 or number % 3 == 0:\n ...
trial_gpt4o_2
{ "original_instruction": "Little bunny Bolo loves prime numbers. Given an integer n, he wants to find the smallest positive integer that is greater than or equal to n and is a prime number.\n\nA prime number is a natural number greater than 1 that is not a product of two smaller natural numbers. For example, the fir...
0.806091
Code_Contests_353
C
[ "is_prime", "smallest_prime_greater_or_equal" ]
2
[ [ "smallest_prime_greater_or_equal", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
14e0a7c8f70d13b7ae5ddae4c9d1dfd41cb4c0a0
d3f2554913d443e95add73494496af78fe6cb17d
v1.0
complete
Code_Contests
Code_Contests_323_C
def min_cost(grid: List[List[int]]) -> int: """ Calculates the minimum total cost for the robot to reach the bottom-right corner of the grid. Parameters: grid (list of list of int): The grid with non-negative integers representing the cost of each cell. Returns: int: The minimum total cost to ...
def min_cost(grid): """ Calculates the minimum total cost for the robot to reach the bottom-right corner of the grid. Parameters: grid (list of list of int): The grid with non-negative integers representing the cost of each cell. Returns: int: The minimum total cost to reach the bottom-right c...
from solution import calculate_min_cost def test_min_cost_example_1(): n = 3 m = 3 grid_values = [1, 3, 1, 1, 5, 1, 4, 2, 1] assert calculate_min_cost(n, m, grid_values) == 7 def test_min_cost_example_2(): n = 2 m = 2 grid_values = [1, 2, 1, 1] assert calculate_min_cost(n, m, grid_valu...
[ { "docstring": "Calculates the minimum total cost for the robot to reach the bottom-right corner of the grid.\n\nParameters:\ngrid (list of list of int): The grid with non-negative integers representing the cost of each cell.\n\nReturns:\nint: The minimum total cost to reach the bottom-right corner of the grid....
[ 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 min_cost(grid):\n \"\"\"\n Calculates the minimum total cost for the robot to reach the bottom-right corner of the grid.\n\n Parameters:\n ...
trial_gpt4o_0
{ "original_instruction": "Sana is a robotics engineer working on a team designing a robot that can traverse a grid. The robot starts at the top-left corner of the grid (at position (1, 1)) and aims to reach the bottom-right corner (at position (n, m)). The grid is composed of cells, and each cell contains a non-nega...
0.598852
Code_Contests_323
C
[ "min_cost", "calculate_min_cost" ]
2
[ [ "calculate_min_cost", "min_cost" ] ]
1
[]
false
[]
false
pytest
true
[]
true
de8073220f2c408f136bb91654fed1d9d7b154cd
30bc78cb2f9a7cd5ec8ce19a5586ed7fd3ffe4c6
v1.0
complete
Code_Contests
Code_Contests_459_C
def find_min_street_lamps(n: int, roads: List[Tuple[int, int, int]], max_time: int) -> int: """ Determine the minimum number of street lamps required so that every intersection in the city is adequately lit. >>> find_min_street_lamps(4, [(1, 2, 2), (2, 3, 4), (3, 4, 1), (4, 1, 3)], 3) == 2 >>> find_min_stre...
import heapq def dijkstra(n, graph, start, max_time): distances = [float('inf')] * n distances[start] = 0 min_heap = [(0, start)] while min_heap: current_distance, u = heapq.heappop(min_heap) if current_distance > distances[u]: continue for v, ...
from solution import find_min_street_lamps def test_basic_case(): n = 4 m = 4 roads = [(1, 2, 2), (2, 3, 4), (3, 4, 1), (4, 1, 3)] max_time = 3 assert find_min_street_lamps(n, roads, max_time) == 2 def test_single_intersection(): n = 1 m = 0 roads = [] max_time = 1 assert find_...
[ { "docstring": null, "function_declaration": "def dijkstra(n, graph, start, max_time):", "function_name": "dijkstra", "parameter_list": "(n, graph, start, max_time)" }, { "docstring": null, "function_declaration": "def find_min_street_lamps(n, roads, max_time):", "function_name": "fi...
[ 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 heapq\n\ndef min_street_lamps(n, m, roads, t):\n # Create an adjacency list representing the graph\n graph = [[] for _ in range(n + 1)]\n f...
trial_gpt4o_2
{ "original_instruction": "In a certain city, there are n intersections and m bidirectional roads connecting them. Each road has a specific travel time associated with it. The city decided to replace the old street lamps with new eco-friendly street lamps. The goal is to ensure each intersection has enough light to b...
0.614343
Code_Contests_459
C
[ "dijkstra", "find_min_street_lamps", "solution" ]
3
[ [ "find_min_street_lamps", "dijkstra" ], [ "solution", "find_min_street_lamps" ] ]
2
[]
false
[]
false
pytest
true
[]
true
bc2b4412816f99075b1e433aff5e85dc647e6671
baf47883e97a32a838a9507885185807ec31e4a4
v1.0
complete
Code_Contests
Code_Contests_356_C
from typing import List, Tuple def preprocess_primes(limit: int): """ Preprocess primes using the Sieve of Eratosthenes up to the given limit. Returns a boolean list indicating prime status and a list of prime counts. """ pass def count_primes_in_range(l: int, r: int, prime_sieve: List[bool], prim...
def count_primes_in_range(l, r, prime_sieve, prime_counts): """ Returns the count of prime numbers between l and r, inclusive. prime_sieve: list of booleans where prime_sieve[i] is True if i is a prime number prime_counts: list where prime_counts[i] is the number of prime numbers <= i """ return...
import pytest from solution import preprocess_primes, process_queries def test_preprocess_primes(): sieve, prime_counts = preprocess_primes(30) assert sieve[2] == True assert sieve[3] == True assert sieve[4] == False assert sieve[29] == True assert prime_counts[10] == 4 assert prime_counts[...
[ { "docstring": "Returns the count of prime numbers between l and r, inclusive.\nprime_sieve: list of booleans where prime_sieve[i] is True if i is a prime number\nprime_counts: list where prime_counts[i] is the number of prime numbers <= i", "function_declaration": "def count_primes_in_range(l, r, prime_sie...
[ 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 sieve_of_eratosthenes(n):\n \"\"\"\n Generates a list of prime numbers up to n using the Sieve of Eratosthenes algorithm.\n \"\"\"\n is_pri...
trial_gpt4o_2
{ "original_instruction": "Alexa is learning about number theory and has come across an interesting problem involving prime numbers. She is trying to find an efficient way to determine whether numbers in a given range are prime.\n\nA prime number is a natural number greater than 1 that has no positive divisors other ...
0.669744
Code_Contests_356
C
[ "count_primes_in_range", "preprocess_primes", "process_queries" ]
3
[ [ "process_queries", "count_primes_in_range" ] ]
1
[ "process_queries" ]
false
[]
false
pytest
true
[]
true
52c310511550eec415c507e9bcf902ddd9ed1020
a72a1ce88ed9be308bae2a0a8456ed57c0e796da
v1.0
complete
Code_Contests
Code_Contests_604_C
def minimum_delivery_cost(n: int, m: int, routes: List[Tuple[int, int, int]]) -> Union[int, str]: """ Calculate the minimum cost required to deliver parcels to various cities using different transportation routes. Args: n (int): Number of cities. m (int): Number of transportation routes. ...
def find(parent, i): if parent[i] == i: return i else: parent[i] = find(parent, parent[i]) return parent[i] def union(parent, rank, x, y): xroot = find(parent, x) yroot = find(parent, y) if rank[xroot] < rank[yroot]: parent[xroot] = yroot elif rank[yroot] < rank...
from solution import minimum_delivery_cost def test_example1(): n = 4 m = 5 routes = [ (1, 2, 2), (1, 3, 3), (2, 3, 1), (2, 4, 4), (3, 4, 5), ] assert minimum_delivery_cost(n, m, routes) == 7 def test_example2(): n = 3 m = 1 routes = [ (1...
[ { "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, 1 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def find_minimum_spanning_tree(n, edges):\n \"\"\"\n Using Kruskal's algorithm to find the Minimum Spanning Tree (MST) cost for a given graph.\n I...
trial_gpt4o_2
{ "original_instruction": "A delivery company needs to calculate the minimum cost required to deliver parcels to various cities using different transportation routes. Each route connects two cities and has a certain cost associated with it. To maximize efficiency, the company wants to ensure that the total delivery c...
0.636799
Code_Contests_604
C
[ "find", "union", "kruskal", "minimum_delivery_cost" ]
4
[ [ "kruskal", "find" ], [ "kruskal", "union" ], [ "minimum_delivery_cost", "kruskal" ], [ "union", "find" ] ]
4
[]
false
[]
false
pytest
true
[]
true
7c89e49be04f555ff886cc9742ed10a9bd7c79c2
f0f9164e5fd8f1f5e5e090e034c3c18fc236a41c
v1.0
complete
Code_Contests
Code_Contests_622_C
def find_positions(n, query_fn): """ Help Alice and Bob find one prime position of '1' and one composite position of '0'. n: The length of the switch sequence (2 <= n <= 1000) query_fn: Function to ask query to the wall, receives a binary string and returns the number of differing positions Exampl...
def is_prime(num): """ Utility function to check if a number is prime. """ if num <= 1: return False if num <= 3: return True if num % 2 == 0 or num % 3 == 0: return False i = 5 while i * i <= num: if num % i == 0 or num % (i + 2) == 0: return ...
def mock_query_fn(target, switch_seq): """ Mock query function that mimics the wall's response given a target sequence. It counts the number of positions that differ between two sequences. """ difference_count = 0 for t, s in zip(target, switch_seq): if t != s: difference_cou...
[ { "docstring": "Utility function to check if a number is prime.", "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": "Function to find one prime position of '1' and one composite position of '0'.\nn: length of the switch seq...
[ 0, 0, 0, 0, 0, 0, 1, 1, 1 ]
3
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "import sys\nimport math\n\ndef is_prime(num):\n \"\"\"This function checks if the given number is prime.\"\"\"\n if num <= 1:\n return False\n...
trial_gpt4o_8
{ "original_instruction": "Alice and Bob are exploring an ancient cave. Suddenly, they come across a magical wall with n switches. Each switch can be either turned on ('1') or off ('0'). Alice claims there is a hidden rule applied to these switches that involves at least one prime position of a '1' and one composite ...
0.51229
Code_Contests_622
C
[ "is_prime", "find_positions" ]
2
[ [ "find_positions", "is_prime" ] ]
1
[]
false
[]
false
pytest
false
[]
true
e78074f63a287757081d5bbfc4891030a9666118
50d846457d7b3c0fd3211d3a64efd7b8e7e433ca
v1.0
complete
Code_Contests
Code_Contests_783_C
def prefix_sum(array): """ Computes the prefix sum of the given array. """ pass def range_sum(prefix, L, R): """ Computes the range sum using the prefix sum array. """ pass def sum_queries(n, q, array, queries): """ Computes the sum for each query in the list of queries. >...
def prefix_sum(array): """ Computes the prefix sum of the given array. """ prefix = [0] * (len(array) + 1) for i in range(1, len(array) + 1): prefix[i] = prefix[i - 1] + array[i - 1] return prefix def range_sum(prefix, L, R): """ Computes the range sum using the prefix sum array...
def test_prefix_sum(): assert prefix_sum([1, 2, 3, 4, 5]) == [0, 1, 3, 6, 10, 15] def test_range_sum(): prefix = [0, 1, 3, 6, 10, 15] assert range_sum(prefix, 1, 3) == 6 assert range_sum(prefix, 2, 4) == 9 assert range_sum(prefix, 1, 5) == 15 def test_sum_queries(): array = [1, 2, 3, 4, 5] ...
[ { "docstring": "Computes the prefix sum of the given array.", "function_declaration": "def prefix_sum(array):", "function_name": "prefix_sum", "parameter_list": "(array)" }, { "docstring": "Computes the range sum using the prefix sum array.", "function_declaration": "def range_sum(prefix...
[ 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 prefix_sums(arr):\n \"\"\"\n Construct prefix sums array from the given array.\n \"\"\"\n n = len(arr)\n prefix = [0] * (n + 1)\n for...
trial_gpt4o_2
{ "original_instruction": "You are given an array of integers and some queries. For each query, you will be given two integers L and R (1 ≤ L ≤ R ≤ n), and you need to find the sum of elements in the array from index L to R (both inclusive). The array is 1-indexed.\n\nInput\n\nThe first line of the input contains two...
0.600662
Code_Contests_783
C
[ "prefix_sum", "range_sum", "sum_queries" ]
3
[ [ "sum_queries", "prefix_sum" ], [ "sum_queries", "range_sum" ] ]
2
[]
false
[]
false
pytest
false
[]
true
fbfa4f1e624c5fa7534b9df6d626a1ddcd908db0
db053cc8e637c0184fc21a2609f8efc8293e980f
v1.0
complete
Code_Contests
Code_Contests_417_C
from typing import List def count_derangements(n: int) -> int: """ Calculate the number of derangements (permutations where no element remains in its original position) for a given n (length of the string). """ # Implementation here def special_permutations(strings: List[str]) -> List[int]: ""...
import math def count_derangements(n): """ Calculate the number of derangements (permutations where no element remains in its original position) for a given n (length of the string). """ if n == 0: return 1 elif n == 1: return 0 elif n == 2: return 1 der = [0] * ...
from solution import compute_special_permutations def test_example_case(): input_lines = [ "3", "AB", "ABC", "ABCD" ] expected_output = [1, 2, 9] assert compute_special_permutations(input_lines) == expected_output def test_single_char(): input_lines = [ "1",...
[ { "docstring": "Calculate the number of derangements (permutations where no element remains in its original position)\nfor a given n (length of the string).", "function_declaration": "def count_derangements(n):", "function_name": "count_derangements", "parameter_list": "(n)" }, { "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": "from math import factorial\n\ndef count_special_permutations(n):\n \"\"\"\n Count the number of derangements (special permutations where no element\n...
trial_gpt4o_2
{ "original_instruction": "Dr. Crypton, a renowned mathematician, is working on a new encryption algorithm that involves manipulating strings. He has discovered that a specific type of permutation of the characters in a string has interesting cryptographic properties. These permutations are called \"special permutati...
0.62995
Code_Contests_417
C
[ "count_derangements", "special_permutations", "process_input", "compute_special_permutations" ]
4
[ [ "compute_special_permutations", "process_input" ], [ "compute_special_permutations", "special_permutations" ], [ "special_permutations", "count_derangements" ] ]
3
[ "process_input" ]
false
[]
false
pytest
true
[]
true
7e0e6a28c6ff0921ef182e06d50de7f8123b6736
b96553472703338e93e93d63d6deb2df49f46361
v1.0
complete
Code_Contests
Code_Contests_845_C
def sum_of_digits(n): """ Returns the sum of the digits of n. """ return sum(int(digit) for digit in str(n)) def find_sequence(n, k, x): """ Determines if there exists a sequence of length n starting with x where each number is the sum of its digits multiplied by k. If it exists, returns the sequ...
def sum_of_digits(n): """ Returns the sum of the digits of n. """ return sum(int(digit) for digit in str(n)) def find_sequence(n, k, x): """ Determines if there exists a sequence of length n starting with x where each number is the sum of its digits multiplied by k. If it exists, returns t...
from solution import sequence_exists, find_sequence def test_case_1(): assert find_sequence(4, 3, 5) == [5, 15, 18, 27] def test_case_2(): assert find_sequence(3, 2, 8) == [8, 16, 14] def test_case_3(): assert find_sequence(2, 5, 1) == [1, 5] def test_case_4(): assert find_sequence(5, 1, 9) == [9, 9...
[ { "docstring": "Returns the sum of the digits of n.", "function_declaration": "def sum_of_digits(n):", "function_name": "sum_of_digits", "parameter_list": "(n)" }, { "docstring": "Determines if there exists a sequence of length n starting with x where each number is the \nsum of its digits m...
[ 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 sum_of_digits(n):\n \"\"\"\n Returns the sum of the digits of n.\n \"\"\"\n return sum(int(digit) for digit in str(n))\n\ndef find_sequence...
trial_gpt4o_0
{ "original_instruction": "Rita enjoys sequences of integers where each number in the sequence is the sum of its digits multiplied by a given integer k. Your task is to determine whether there exists any sequence of length n such that each number in the sequence (except the first one) follows the described rule.\n\nI...
0.66971
Code_Contests_845
C
[ "sum_of_digits", "find_sequence", "sequence_exists" ]
3
[ [ "find_sequence", "sum_of_digits" ], [ "sequence_exists", "find_sequence" ] ]
2
[]
false
[]
false
pytest
true
[]
true
5aa931bb3658e9a95b1613a47678f34b496a1519
03d4f565e1315bfa0eda5cd6b8a9b683d2323df6
v1.0
complete
Code_Contests
Code_Contests_475_C
def is_schedule_valid(lectures): """ Returns True if there are no overlapping lectures in the list of lectures, False otherwise. """ def validate_schedules(test_cases): """ Validates the schedules for multiple test cases. Each test case includes multiple lecturers and each lecturer has a li...
def is_schedule_valid(lectures): """ Returns True if there are no overlapping lectures in the list of lectures, False otherwise. """ lectures.sort(key=lambda x: x[0]) # Sort lectures by start time for i in range(1, len(lectures)): if lectures[i][0] < lectures[i-1][1]: return Fal...
from solution import is_schedule_valid, validate_schedules def test_is_schedule_valid(): assert is_schedule_valid([(10, 20), (20, 30), (30, 40)]) == True assert is_schedule_valid([(5, 10), (15, 20)]) == True assert is_schedule_valid([(5, 10), (8, 12)]) == False assert is_schedule_valid([(10, 15), (15, ...
[ { "docstring": "Returns True if there are no overlapping lectures in the list of lectures, False otherwise.", "function_declaration": "def is_schedule_valid(lectures):", "function_name": "is_schedule_valid", "parameter_list": "(lectures)" }, { "docstring": "Validates the schedules for multip...
[ 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_valid_lecturer_schedule(lectures):\n \"\"\"\n Checks whether the given lectures' schedule of a lecturer is valid (no overlapping).\n \"\"\"...
trial_gpt4o_7
{ "original_instruction": "Grace is working on a schedule management system for a group of lecturers. Each lecturer has a list of lectures they need to give, each associated with a specific start and end time. Grace wants to ensure that each lecturer's schedule does not have any overlapping lectures, meaning a lectur...
0.565134
Code_Contests_475
C
[ "is_schedule_valid", "validate_schedules", "main" ]
3
[ [ "validate_schedules", "is_schedule_valid" ] ]
1
[]
false
[]
false
pytest
true
[]
true
f02ef5559c3e13e5208b4035cd0fe6b35267273a
a3fad66b61e89daa1292be7e27f7f99fb29d488f
v1.0
complete
Code_Contests
Code_Contests_653_C
def count_divisors(n: int) -> int: """ Returns the number of divisors for a given number. >>> count_divisors(1) 1 >>> count_divisors(2) 2 >>> count_divisors(3) 2 >>> count_divisors(6) 4 >>> count_divisors(10) 4 >>> count_divisors(16) 5 """ pass def most_senio...
def count_divisors(n): """Returns the number of divisors of n.""" count = 0 for i in range(1, int(n ** 0.5) + 1): if n % i == 0: count += 1 if i != n // i: count += 1 return count def most_senior_employee(T, test_cases): """Returns the ID of the most ...
def test_count_divisors(): assert count_divisors(1) == 1 assert count_divisors(2) == 2 assert count_divisors(3) == 2 assert count_divisors(6) == 4 assert count_divisors(10) == 4 assert count_divisors(16) == 5 def test_most_senior_employee(): assert most_senior_employee(2, [(3, [10, 6, 8]), ...
[ { "docstring": "Returns the number of divisors of n.", "function_declaration": "def count_divisors(n):", "function_name": "count_divisors", "parameter_list": "(n)" }, { "docstring": "Returns the ID of the most senior employee for each test case.", "function_declaration": "def most_senior...
[ 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 number_of_divisors(n):\n \"\"\"Returns the number of divisors of a given integer n.\"\"\"\n count = 0\n for i in range(1, int(n**0.5) + 1):\n ...
trial_gpt4o_2
{ "original_instruction": "In a company, each employee is represented by an ID, which is a positive integer. The management wants to schedule meetings based on the seniority of employees. The seniority is determined by the number of divisors of the employee ID; the more divisors an employee ID has, the more senior th...
0.627716
Code_Contests_653
C
[ "count_divisors", "most_senior_employee" ]
2
[ [ "most_senior_employee", "count_divisors" ] ]
1
[]
false
[]
false
pytest
false
[]
true
d061f2ae1db25bdbf64229ec6228c12b8e7034b4
f54e61fded72aa101043bf279cfeec7a0eb4a702
v1.0
complete
Code_Contests
Code_Contests_564_C
def reverse_number(n: int) -> int: """ Returns the reverse of integer n. For example, reverse_number(123) returns 321. """ pass def is_palindrome(n: int) -> bool: """ Checks if integer n is a palindrome. For example, is_palindrome(121) returns True, is_palindrome(123) returns False. ...
def reverse_number(n): """ Returns the reverse of integer n. For example, reverse_number(123) returns 321. """ return int(str(n)[::-1]) def is_palindrome(n): """ Checks if integer n is a palindrome. For example, is_palindrome(121) returns True, is_palindrome(123) returns False. """ ...
from solution import reverse_number, is_palindrome, palindrome_chain_length, iterations_to_palindrome def test_reverse_number(): assert reverse_number(123) == 321 assert reverse_number(4000) == 4 assert reverse_number(1) == 1 assert reverse_number(120) == 21 def test_is_palindrome(): assert is_pal...
[ { "docstring": "Returns the reverse of integer n.\nFor example, reverse_number(123) returns 321.", "function_declaration": "def reverse_number(n):", "function_name": "reverse_number", "parameter_list": "(n)" }, { "docstring": "Checks if integer n is a palindrome.\nFor example, is_palindrome(...
[ 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(n):\n \"\"\"\n Check if a given number is a palindrome.\n \"\"\"\n return str(n) == str(n)[::-1]\n\ndef iterations_to_palindr...
trial_gpt4o_2
{ "original_instruction": "Palindrome Chain: A palindrome is a sequence that reads the same backward as forward. Sometimes, by reversing the digits of a number and adding it to the original number, we might get a larger number that is a palindrome. If the resulting sum is not a palindrome, we repeat the process until...
0.712062
Code_Contests_564
C
[ "reverse_number", "is_palindrome", "palindrome_chain_length", "iterations_to_palindrome" ]
4
[ [ "iterations_to_palindrome", "palindrome_chain_length" ], [ "palindrome_chain_length", "is_palindrome" ], [ "palindrome_chain_length", "reverse_number" ] ]
3
[]
false
[]
false
pytest
true
[]
true
1382cc855669b2234dc8f96cb4eba510140a85d0
e39ab6d098bb4658d80bece83b527c1b747661bf
v1.0
complete
Code_Contests
Code_Contests_545_C
def preprocess_grid(grid): """ Preprocesses the grid to compute a prefix_sum array for efficient subgrid sum calculation. >>> preprocess_grid([ ... [1, 2, 3], ... [4, 5, 6], ... [7, 8, 9] ... ]) [ [0, 0, 0, 0], [0, 1, 3, 6], [0, 5, 12, 21], [0, 12,...
def preprocess_grid(grid): n = len(grid) m = len(grid[0]) prefix_sum = [[0] * (m + 1) for _ in range(n + 1)] for i in range(1, n + 1): for j in range(1, m + 1): prefix_sum[i][j] = grid[i-1][j-1] + prefix_sum[i-1][j] + prefix_sum[i][j-1] - prefix_sum[i-1][j-1] return pre...
def test_preprocess_grid(): grid = [ [1, 2, 3], [4, 5, 6], [7, 8, 9] ] expected_prefix_sum = [ [0, 0, 0, 0], [0, 1, 3, 6], [0, 5, 12, 21], [0, 12, 27, 45] ] assert preprocess_grid(grid) == expected_prefix_sum def test_query_weight(): prefi...
[ { "docstring": null, "function_declaration": "def preprocess_grid(grid):", "function_name": "preprocess_grid", "parameter_list": "(grid)" }, { "docstring": null, "function_declaration": "def query_weight(prefix_sum, r1, c1, r2, c2):", "function_name": "query_weight", "parameter_l...
[ 1, 0, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def calculate_weight(grid, queries):\n n = len(grid)\n m = len(grid[0])\n \n # Create a prefix sum matrix to optimize the weight calculation\n ...
trial_gpt4o_2
{ "original_instruction": "In the kingdom of Quadrantland, there is a special grid used for communication. This grid is made up of cells, each containing a non-negative integer. Citizens love to send messages by selecting a subgrid (a rectangular section of the main grid) and calculating its \"weight\".\n\nThe weight...
0.544448
Code_Contests_545
C
[ "preprocess_grid", "query_weight", "solve" ]
3
[ [ "solve", "preprocess_grid" ], [ "solve", "query_weight" ] ]
2
[]
false
[]
false
pytest
false
[]
true
26c3efe5cad8bc0768f94d015589e9b6ce5258db
fe484f0903104c83997fc3620454012178afd8d7
v1.0
complete
Code_Contests
Code_Contests_882_C
def prime_counts_for_ranges(test_cases): """ Given a list of test cases, return the count of prime numbers for each range. >>> prime_counts_for_ranges([(1, 10)]) [4] >>> prime_counts_for_ranges([(11, 20)]) [4] >>> prime_counts_for_ranges([(20, 30)]) [2] >>> prime_counts_for_ranges([(1, 10), (11,...
def sieve_of_eratosthenes(n): """ Generate a boolean array prime[0..n] where prime[i] will be True if i is a prime number """ prime = [True] * (n + 1) p = 2 while (p * p <= n): if prime[p] == True: for i in range(p * p, n + 1, p): prime[i] = False p ...
from solution import prime_counts_for_ranges def test_case_1(): test_cases = [(1, 10)] result = prime_counts_for_ranges(test_cases) assert result == [4] def test_case_2(): test_cases = [(11, 20)] result = prime_counts_for_ranges(test_cases) assert result == [4] def test_case_3(): test_cas...
[ { "docstring": "Generate a boolean array prime[0..n] where prime[i] will be True if i is a prime number ", "function_declaration": "def sieve_of_eratosthenes(n):", "function_name": "sieve_of_eratosthenes", "parameter_list": "(n)" }, { "docstring": "Count the number of primes between l and r ...
[ 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_primes_between(l, r):\n \"\"\"\n Returns the number of prime numbers between l and r, inclusive.\n \"\"\"\n def sieve(n):\n \"...
trial_gpt4o_4
{ "original_instruction": "Lena just started learning math at school and got fascinated by prime numbers. She wants to count how many prime numbers exist between two given numbers, inclusive. However, she doesn't know how to check for prime numbers effectively. Can you help her write a program to solve her problem?\n...
0.732336
Code_Contests_882
C
[ "sieve_of_eratosthenes", "count_primes_between_l_and_r", "prime_counts_for_ranges" ]
3
[ [ "prime_counts_for_ranges", "count_primes_between_l_and_r" ], [ "prime_counts_for_ranges", "sieve_of_eratosthenes" ] ]
2
[]
false
[]
false
pytest
true
[]
true
903da1cffe72245f8c2c335dc16fb6088d232113
898b8f338a25566a20c29eab738fbabddbf45351
v1.0
complete
Code_Contests
Code_Contests_392_C
def preprocess_prefix_sums(arr): """ Preprocesses the array to compute the prefix sums for efficient range-sum queries. """ pass def range_sum(prefix_sums, l, r): """ Computes the sum of elements in the range [l, r] using the prefix sums array. """ pass def process_queries(n, arr, quer...
def preprocess_prefix_sums(arr): """ Preprocesses the array to compute the prefix sums for efficient range-sum queries. """ n = len(arr) prefix_sums = [0] * (n + 1) for i in range(n): prefix_sums[i + 1] = prefix_sums[i] + arr[i] return prefix_sums def range_sum(prefix_sums, l, r): ...
from solution import preprocess_prefix_sums, range_sum, process_queries def test_preprocess_prefix_sums(): assert preprocess_prefix_sums([1, 2, 3, 4, 5]) == [0, 1, 3, 6, 10, 15] def test_range_sum(): prefix_sums = preprocess_prefix_sums([1, 2, 3, 4, 5]) assert range_sum(prefix_sums, 1, 3) == 6 assert ...
[ { "docstring": "Preprocesses the array to compute the prefix sums for efficient range-sum queries.", "function_declaration": "def preprocess_prefix_sums(arr):", "function_name": "preprocess_prefix_sums", "parameter_list": "(arr)" }, { "docstring": "Computes the sum of elements in the range [...
[ 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 range_sum(n, arr, queries):\n \"\"\"\n Computes the sum of elements between given pairs of indices (inclusive) for multiple queries.\n\n Args:...
trial_gpt4o_2
{ "original_instruction": "You are given an array of integers and multiple queries. Each query consists of a pair of indices, and the task is to compute the sum of the elements between these indices (inclusive).\n\nInput\n\nThe first line contains an integer n (1 ≤ n ≤ 100000) — the number of elements in the array. T...
0.602354
Code_Contests_392
C
[ "preprocess_prefix_sums", "range_sum", "process_queries" ]
3
[ [ "process_queries", "preprocess_prefix_sums" ], [ "process_queries", "range_sum" ] ]
2
[ "process_queries" ]
false
[]
false
pytest
true
[]
true
3f265a387c31c70b8cfd9eb2fc7f01b479b62af4
4eb3ba218b76fb41c5e95d94eb3562d510b79c48
v1.0
complete
Code_Contests
Code_Contests_664_C
def is_palindrome(s): """Check if the given string is a palindrome.""" return s == s[::-1] def longest_palindromic_subsequence(s): """Find the length of the longest palindromic subsequence in the given string.""" n = len(s) dp = [[0] * n for _ in range(n)] for i in range(n): dp[i][...
def is_palindrome(s): return s == s[::-1] def longest_palindromic_subsequence(s): n = len(s) dp = [[0] * n for _ in range(n)] for i in range(n): dp[i][i] = 1 for cl in range(2, n+1): for i in range(n-cl+1): j = i + cl - 1 if s[i] == s[j] and cl == 2: ...
from solution import galaxy_coin_value, solve def test_galaxy_coin_value(): assert galaxy_coin_value("abba") == 4 assert galaxy_coin_value("abc") == 2 assert galaxy_coin_value("cbbd") == 4 def test_is_palindrome(): assert is_palindrome("abba") == True assert is_palindrome("abc") == False asser...
[ { "docstring": null, "function_declaration": "def is_palindrome(s):", "function_name": "is_palindrome", "parameter_list": "(s)" }, { "docstring": null, "function_declaration": "def longest_palindromic_subsequence(s):", "function_name": "longest_palindromic_subsequence", "paramete...
[ 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 longest_palindromic_subsequence(val):\n n = len(val)\n dp = [[0] * n for _ in range(n)]\n \n for i in range(n):\n dp[i][i] = 1\n ...
trial_gpt4o_1
{ "original_instruction": "In a distant galaxy, there is a new type of currency called \"GalaxyCoins\". Each GalaxyCoin has a value represented by a string of lowercase English letters. The value of a GalaxyCoin string \"val\" is defined as follows:\n\n1. If \"val\" is a palindrome, then the value is the length of th...
0.651374
Code_Contests_664
C
[ "is_palindrome", "longest_palindromic_subsequence", "galaxy_coin_value", "solve" ]
4
[ [ "galaxy_coin_value", "is_palindrome" ], [ "galaxy_coin_value", "longest_palindromic_subsequence" ], [ "solve", "galaxy_coin_value" ] ]
3
[]
false
[]
false
pytest
true
[]
true
8d578058c3c3af512d86d6426eb778186ddd3511
74a7690de11f9251976ff6a1ef0be3256aa550cf
v1.0
complete
Code_Contests
Code_Contests_823_C
def count_paths(input_string: str) -> int: """ You are developing a game where the player navigates a grid of size n x m. The grid contains barriers and the player's movement is constrained by these obstacles. The player's goal is to move from the top-left corner of the grid (1,1) to the bottom-right corner of ...
def num_paths(grid): n = len(grid) m = len(grid[0]) # Ensure top-left and bottom-right are not barriers if grid[0][0] == '#' or grid[n-1][m-1] == '#': return 0 # Initialize DP table dp = [[0]*m for _ in range(n)] # Start position dp[0][0] = 1 # Fill DP tab...
from solution import count_paths def test_example_case(): input_data = '''3 3 . . . . # . . . .''' assert count_paths(input_data) == 2 def test_no_path_due_to_obstacle(): input_data = '''3 3 . . # . # . # . .''' assert count_paths(input_data) == 0 def test_single_path(): input_data = '''2 2 . . ....
[ { "docstring": null, "function_declaration": "def num_paths(grid):", "function_name": "num_paths", "parameter_list": "(grid)" }, { "docstring": null, "function_declaration": "def parse_input(input_string):", "function_name": "parse_input", "parameter_list": "(input_string)" }, ...
[ 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 num_paths(grid):\n n = len(grid)\n m = len(grid[0])\n \n if grid[0][0] == '#' or grid[n-1][m-1] == '#':\n return 0\n \n dp = [...
trial_gpt4o_3
{ "original_instruction": "You are developing a game where the player navigates a grid of size n x m. The grid contains barriers and the player's movement is constrained by these obstacles. The player's goal is to move from the top-left corner of the grid (1,1) to the bottom-right corner of the grid (n,m). However, t...
0.715703
Code_Contests_823
C
[ "num_paths", "parse_input", "count_paths" ]
3
[ [ "count_paths", "num_paths" ], [ "count_paths", "parse_input" ] ]
2
[ "parse_input" ]
false
[]
false
pytest
true
[]
true
a56c75cf4f58daff6ea99a94525334a6019fcfc2
0af51309c5d86a58db12b34f125ef65eb8a00832
v1.0
complete
Code_Contests
Code_Contests_952_C
def solve_islands_problem(R: int, C: int, K: int, grid_input: List[str]) -> int: """ Determine the maximum number of distinct islands that can be formed by converting K water cells to land cells. Args: R (int): Number of rows. C (int): Number of columns. K (int): Number of water cells to co...
def max_distinct_islands(grid, R, C, K): def dfs(r, c, visited, label): stack = [(r, c)] visited[r][c] = label while stack: x, y = stack.pop() for dx, dy in [(-1, 0), (1, 0), (0, -1), (0, 1)]: nx, ny = x + dx, y + dy if 0 <= nx < R and ...
from solution import solve_islands_problem def test_solve_islands_problem_1(): R, C, K = 4, 4, 2 grid_input = ["1 0 0 1", "0 1 0 0", "0 0 1 0", "1 0 0 1"] assert solve_islands_problem(R, C, K, grid_input) == 6 def test_solve_islands_problem_2(): R, C, K = 3, 3, 1 grid_input = ["1 0 1", "0 1 0", "1...
[ { "docstring": null, "function_declaration": "def max_distinct_islands(grid, R, C, K):", "function_name": "max_distinct_islands", "parameter_list": "(grid, R, C, K)" }, { "docstring": null, "function_declaration": "def solve_islands_problem(R, C, K, grid_input):", "function_name": "s...
[ 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_islands_after_conversion(R, C, K, grid):\n directions = [(-1, 0), (1, 0), (0, -1), (0, 1)]\n\n def dfs(x, y):\n stack = [(x, y)]\n ...
trial_gpt4o_1
{ "original_instruction": "You are given a grid with R rows and C columns. Each cell in the grid either contains a 1 or a 0. A cell containing 1 is considered a land cell, and a cell containing 0 is a water cell. You can traverse from a land cell to another land cell if they are adjacent horizontally or vertically. W...
0.647096
Code_Contests_952
C
[ "max_distinct_islands", "solve_islands_problem" ]
2
[ [ "solve_islands_problem", "max_distinct_islands" ] ]
1
[]
false
[]
false
pytest
true
[]
true
f95b4537bd1afb478467fa06ba3bee4e337d5ea3
03b8aac8856757218c6e89ff924fafd0be3fa168
v1.0
complete
Code_Contests
Code_Contests_1102_C
def matrix_sum_divisible(R: int, C: int, D: int, matrix: List[List[int]]) -> str: """ Check if there exists a row or column such that the sum of its elements is divisible by a given integer D. >>> matrix_sum_divisible(3, 3, 4, [ [1, 2, 3], [4, 5, 6], [7, 8, 9] ]) == "YES" >>> mat...
def check_sum_divisible(matrix, R, C, D): for row in matrix: if sum(row) % D == 0: return "YES" for col in range(C): col_sum = sum(matrix[row][col] for row in range(R)) if col_sum % D == 0: return "YES" return "NO" def matrix_sum_divisible(R, C, D,...
from solution import matrix_sum_divisible def test_matrix_sum_divisible_row(): assert matrix_sum_divisible(3, 3, 4, [ [1, 2, 3], [4, 5, 6], [7, 8, 9] ]) == "YES" def test_matrix_sum_divisible_no(): assert matrix_sum_divisible(2, 3, 10, [ [1, 2, 3], [4, 5, 6] ]) ...
[ { "docstring": null, "function_declaration": "def check_sum_divisible(matrix, R, C, D):", "function_name": "check_sum_divisible", "parameter_list": "(matrix, R, C, D)" }, { "docstring": null, "function_declaration": "def matrix_sum_divisible(R, C, D, matrix):", "function_name": "matr...
[ 0, 0, 0, 0, 0, 1, 0, 0, 1, 1 ]
3
hard
0.3
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_divisible_by_d(arr, R, C, D):\n # Check each row\n for row in arr:\n if sum(row) % D == 0:\n return \"YES\"\n \n # Che...
trial_gpt4o_9
{ "original_instruction": "A rectangular matrix of positive integers is given. Your task is to check if there exists a row or column such that the sum of the elements of that row or column is divisible by a given integer D.\n\nInput\n\nThe first line of input contains three space-separated integers: the number of row...
0.631407
Code_Contests_1102
C
[ "check_sum_divisible", "matrix_sum_divisible" ]
2
[ [ "matrix_sum_divisible", "check_sum_divisible" ] ]
1
[]
false
[]
false
pytest
true
[]
true
325d702c00738a120460347c938ac63235d2d978
4a37f5319e3b7176f17968485286dff94772d346
v1.0
complete
Code_Contests
Code_Contests_1200_C
def solve(N: int, Q: int, A: List[int], queries: List[Tuple[int, int]]) -> List[int]: """ Process a series of queries asking for the sum of elements between two specified indices in the array. Args: N : int : Number of elements in the array Q : int : Number of queries A : List[int] : Array of ...
def preprocess_prefix_sums(array): """ Preprocess the prefix sums for the given array. """ n = len(array) prefix_sums = [0] * (n + 1) for i in range(1, n + 1): prefix_sums[i] = prefix_sums[i-1] + array[i-1] return prefix_sums def range_sum(prefix_sums, L, R): """ Get the sum...
def test_simple_case(): N = 5 Q = 3 A = [1, 2, 3, 4, 5] queries = [(1, 3), (2, 4), (1, 5)] expected_output = [6, 9, 15] assert solve(N, Q, A, queries) == expected_output def test_single_element_arrays(): N = 1 Q = 1 A = [10] queries = [(1, 1)] expected_output = [10] asse...
[ { "docstring": "Preprocess the prefix sums for the given array.", "function_declaration": "def preprocess_prefix_sums(array):", "function_name": "preprocess_prefix_sums", "parameter_list": "(array)" }, { "docstring": "Get the sum of the subarray from index L to R (1-based).", "function_d...
[ 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 preprocess_prefix_sums(array):\n \"\"\"\n Preprocess the prefix sums for the given array.\n \"\"\"\n n = len(array)\n prefix_sums = [0] ...
trial_gpt4o_0
{ "original_instruction": "You are given an array of integers. You need to answer a series of queries on this array. Each query will ask for the sum of the elements between two specified indices, inclusive.\n\nYou must process each query efficiently.\n\nConstraints\n\n* 1≤N≤10^5 - Number of elements in the array.\n* ...
0.656149
Code_Contests_1200
C
[ "preprocess_prefix_sums", "range_sum", "solve" ]
3
[ [ "solve", "preprocess_prefix_sums" ], [ "solve", "range_sum" ] ]
2
[]
false
[]
false
pytest
false
[]
true
1c36f190a309d33fd2a28d972e16ca24dda637c1
c844757115be25293bf1ef391d256f7fd48e9cd7
v1.0
complete
Code_Contests
Code_Contests_1204_C
def is_prime(num): """Returns True if the number is prime, otherwise False.""" if num <= 1: return False for i in range(2, int(num**0.5) + 1): if num % i == 0: return False return True def max_prime_subsequence_sum(n, a): """ Returns the maximum sum of any sub-sequen...
def is_prime(num): """Returns True if the number is prime, otherwise False.""" if num <= 1: return False for i in range(2, int(num**0.5) + 1): if num % i == 0: return False return True def max_prime_subsequence_sum(n, a): """ Returns the maximum sum of any sub-sequen...
from solution import is_prime, max_prime_subsequence_sum 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(11) == True assert is_prime(15) == False assert is_prime(1) == False assert is_prime...
[ { "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 maximum sum of any sub-sequence of prime numbers in the list.\nIf there are no prime num...
[ 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 Checks if a number is a prime number.\n \"\"\"\n if num <= 1:\n return False\n if num == 2:\n re...
trial_gpt4o_2
{ "original_instruction": "Background\n\nAlex is a computer science student who enjoys solving problems using algorithms and data structures. One day, he stumbled upon a new puzzle involving prime numbers and decided to write a program for it.\n\nProblem\n\nYou are given a list of `n` integers. Your task is to find t...
0.75015
Code_Contests_1204
C
[ "is_prime", "max_prime_subsequence_sum" ]
2
[ [ "max_prime_subsequence_sum", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
c9c35629a4e630a72f970be8c49e6d1081caeca5
edf3f173b49b301b375890fa8e2b1dd1fdb5ce65
v1.0
complete
Code_Contests
Code_Contests_976_C
from typing import List, Tuple def sieve(n: int) -> List[int]: """Sieve of Eratosthenes finds all primes up to n.""" def find_primes_in_range(a: int, b: int) -> List[int]: """Finds all prime numbers in the inclusive range [a, b].""" def display_prime_ranges(test_cases: List[Tuple[int, int]]) -> List[str]...
def sieve(n): """ Sieve of Eratosthenes finds all primes up to n """ 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 prime_numbers = [] for p in range(2, n + 1): ...
def test_sieve(): assert sieve(10) == [2, 3, 5, 7] assert sieve(30) == [2, 3, 5, 7, 11, 13, 17, 19, 23, 29] def test_find_primes_in_range(): assert find_primes_in_range(2, 10) == [2, 3, 5, 7] assert find_primes_in_range(11, 20) == [11, 13, 17, 19] assert find_primes_in_range(22, 29) == [23, 29] ...
[ { "docstring": "Sieve of Eratosthenes finds all primes up to n", "function_declaration": "def sieve(n):", "function_name": "sieve", "parameter_list": "(n)" }, { "docstring": "Finds all prime numbers in the inclusive range [a, b]", "function_declaration": "def find_primes_in_range(a, b):"...
[ 0, 0, 1, 1 ]
2
medium
0.5
{ "trial_gpt4o_0": null, "trial_gpt4o_1": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared1_results_combined.jsonl", "solution_code": "def sieve(n):\n \"\"\"Returns a list of prime numbers up to n (inclusive) using the Sieve of Eratosthenes algorithm.\"\"\"\n ...
trial_gpt4o_3
{ "original_instruction": "Petya recently started learning algorithms and he was given a task to identify all prime numbers within a given range. As part of this task, he needs to implement an algorithm that finds all prime numbers from a to b (inclusive). \n\nA number is prime if it is greater than 1 and has no posi...
0.621618
Code_Contests_976
C
[ "sieve", "find_primes_in_range", "display_prime_ranges" ]
3
[ [ "display_prime_ranges", "find_primes_in_range" ], [ "find_primes_in_range", "sieve" ] ]
2
[]
false
[]
false
pytest
false
[]
true
d4148354053d8fdd65123d0163ceb175e8fd2f26
c94f91c309becd5e8d4c45df67a1660a2d64774f
v1.0
complete
Code_Contests
Code_Contests_1166_C
def sum_of_max_elements(matrix: List[List[int]]) -> int: """ Returns the sum of the maximum element in each row of the given matrix. Args: matrix (list of list of int): A 2D list representing the matrix. Returns: int: Sum of the maximum elements in each row. Examples: >>> ...
def sum_of_max_elements(matrix): """ Returns the sum of the maximum element in each row of the given matrix. Args: matrix (list of list of int): A 2D list representing the matrix. Returns: int: Sum of the maximum elements in each row. """ return sum(max(row) for row in matrix) ...
def test_sum_of_max_elements_example(): matrix = [ [1, 2, 3], [4, 5, 6], [7, 8, 9] ] assert sum_of_max_elements(matrix) == 18 def test_sum_of_max_elements_single_row(): matrix = [ [1, 2, 3, 4, 5] ] assert sum_of_max_elements(matrix) == 5 def test_sum_of_max_elem...
[ { "docstring": "Returns the sum of the maximum element in each row of the given matrix.\n\nArgs:\nmatrix (list of list of int): A 2D list representing the matrix.\n\nReturns:\nint: Sum of the maximum elements in each row.", "function_declaration": "def sum_of_max_elements(matrix):", "function_name": "su...
[ 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_in_each_row_sum(matrix):\n \"\"\"\n Given a square matrix, return the sum of the maximum element in each row.\n \"\"\"\n max_elements_s...
trial_gpt4o_1
{ "original_instruction": "You are given a matrix of size n x n, where each cell contains an integer. Your task is to find the sum of the maximum element in each row.\n\nInput format\nThe first line contains one integer n — the size of the matrix.\n\nEach of the next n lines contains n integers describing the element...
0.686225
Code_Contests_1166
C
[ "sum_of_max_elements", "get_matrix_and_sum" ]
2
[ [ "get_matrix_and_sum", "sum_of_max_elements" ] ]
1
[]
false
[]
false
pytest
false
[]
true
8cffaf237411135337fe1e1005256e73bdf6f48b
08354b0bef39a8033cff75a6ed0f015542b52f17
v1.0
complete
Code_Contests
Code_Contests_958_C
def is_sum_of_two_squares(n: int) -> bool: """ Check if a number can be represented as a sum of two perfect squares. """ pass def check_sums(x: int, y: int) -> str: """ Returns "Yes" if both x and y can be represented as the sum of two perfect squares, otherwise returns "No". >>> check_sums(5, 10) ...
import math def is_sum_of_two_squares(n): """ Check if n can be represented as a sum of two perfect squares. """ for a in range(int(math.isqrt(n)) + 1): b = n - a * a if math.isqrt(b) ** 2 == b: return True return False def check_sums(x, y): """ Returns "Yes" if...
from solution import check_sums def test_check_sums_yes(): assert check_sums(5, 10) == "Yes" assert check_sums(0, 0) == "Yes" assert check_sums(1, 4) == "Yes" assert check_sums(2, 50) == "Yes" assert check_sums(9, 25) == "Yes" def test_check_sums_no(): assert check_sums(3, 17) == "No" asse...
[ { "docstring": "Check if n can be represented as a sum of two perfect squares.", "function_declaration": "def is_sum_of_two_squares(n):", "function_name": "is_sum_of_two_squares", "parameter_list": "(n)" }, { "docstring": "Returns \"Yes\" if both x and y can be represented as the sum of two ...
[ 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 check_sum_of_squares(n):\n \"\"\"Helper function to check if an integer can be expressed as the sum of two squares\"\"\"\n for i in range(int(n**...
trial_gpt4o_2
{ "original_instruction": "You are given two integers x and y. You need to determine if they can be represented as the sum of two perfect squares. Specifically, if there exist non-negative integers \\(a\\) and \\(b\\) such that \\(x = a^2 + b^2\\) and \\(y = c^2 + d^2\\) where \\(a, b, c,\\) and \\(d\\) are integers....
0.660038
Code_Contests_958
C
[ "is_sum_of_two_squares", "check_sums" ]
2
[ [ "check_sums", "is_sum_of_two_squares" ] ]
1
[]
false
[]
false
pytest
true
[]
true
06c62beb6e35fad03d4672f1b913dc933b0007d3
3a9443e7c9c461206b7459ca1e883e87a7ee5277
v1.0
complete
Code_Contests
Code_Contests_1319_C
def is_prime(n: int) -> bool: """ Determines if a number n is prime. >>> is_prime(2) True >>> is_prime(3) True >>> is_prime(4) False >>> is_prime(0) False >>> is_prime(1) False >>> is_prime(-5) False >>> is_prime(17) True """ def sum_of_primes(arr: List[int]) -> int: """...
def is_prime(n): """ Determines if a number n is prime. """ if n <= 1: return False for i in range(2, int(n ** 0.5) + 1): if n % i == 0: return False return True def sum_of_primes(arr): """ Returns the sum of all prime numbers in the list. """ return ...
from solution import sum_of_primes, is_prime def test_is_prime(): assert is_prime(2) == True assert is_prime(3) == True assert is_prime(4) == False assert is_prime(0) == False assert is_prime(1) == False assert is_prime(-5) == False assert is_prime(17) == True def test_sum_of_primes_with_m...
[ { "docstring": "Determines if a number n is prime.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Returns the sum of all prime numbers in the list.", "function_declaration": "def sum_of_primes(arr):", "function_na...
[ 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 determine if a number is prime.\n \"\"\"\n if n <= 1:\n return False\n if n == 2:\n ...
trial_gpt4o_2
{ "original_instruction": "Write a function that takes a list of integers and returns the sum of all prime numbers in the list. If there are no prime numbers in the list, the function should return 0.\n\nConstraints\n\n* 1 ≤ len(list) ≤ 100\n* -1000 ≤ list elements ≤ 1000\n\nInput\n\nA list of integers separated by s...
0.783206
Code_Contests_1319
C
[ "is_prime", "sum_of_primes" ]
2
[ [ "sum_of_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
6c2541a69606380164cf4f81778600b0da39cf5c
8465cd022db79679437c0325f7c394ba49e0cc66
v1.0
complete
Code_Contests
Code_Contests_997_C
def maximalRectangle(matrix: List[List[int]]) -> int: """ Determine the area of the largest rectangle containing only 1s in a given binary matrix. >>> maximalRectangle([ ... [1, 0, 1, 0, 0], ... [1, 0, 1, 1, 1], ... [1, 1, 1, 1, 1], ... [1, 0, 0, 1, 0] ... ]) 6 ...
def maximalRectangle(matrix): if not matrix: return 0 m = len(matrix) n = len(matrix[0]) max_area = 0 heights = [0] * n for i in range(m): for j in range(n): if matrix[i][j] == 1: heights[j] += 1 else: heights[j] = 0 ...
def test_maximalRectangle(): matrix1 = [ [1, 0, 1, 0, 0], [1, 0, 1, 1, 1], [1, 1, 1, 1, 1], [1, 0, 0, 1, 0] ] assert maximalRectangle(matrix1) == 6 matrix2 = [ [1], ] assert maximalRectangle(matrix2) == 1 matrix3 = [ [0, 0], [0, 0] ...
[ { "docstring": null, "function_declaration": "def maximalRectangle(matrix):", "function_name": "maximalRectangle", "parameter_list": "(matrix)" }, { "docstring": null, "function_declaration": "def largestRectangleArea(heights):", "function_name": "largestRectangleArea", "paramete...
[ 0, 1 ]
1
medium
0.5
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def maximalRectangle(matrix):\n if not matrix:\n return 0\n \n max_area = 0\n m, n = len(matrix), len(matrix[0])\n heights = [0] * n\...
trial_gpt4o_1
{ "original_instruction": "A large company employs a matrix of binary sensors to monitor various environmental factors in their main server room. The matrix is represented as a 2D grid where each cell contains either a 0 (inactive sensor) or a 1 (active sensor). The company wants to identify the largest rectangular s...
0.7025
Code_Contests_997
C
[ "maximalRectangle", "largestRectangleArea" ]
2
[ [ "maximalRectangle", "largestRectangleArea" ] ]
1
[]
false
[]
false
pytest
false
[]
true
c8641ea46c29b2972bc912ef57f8f46d2e58a47a
6d4b9af81781a8dfeb5099ef1b4eadefec230d39
v1.0
complete
Code_Contests
Code_Contests_1403_C
def find_minimum_capacity(N: int, M: int, preferences: List[List[int]]) -> int: """ Determine the minimum capacity limit L such that all participants can attend at least one workshop. >>> find_minimum_capacity(4, 3, [[1, 2, 3], [2, 3, 1], [3, 1, 2], [1, 3, 2]]) 2 >>> find_minimum_capacity(3, 2, [[1, 2],...
def can_all_attend(preferences, N, M, L): workshop_slots = [0] * M for participant_pref in preferences: for workshop in participant_pref: if workshop_slots[workshop - 1] < L: workshop_slots[workshop - 1] += 1 break return sum(workshop_slots) == N def find...
from solution import find_minimum_capacity def test_example_cases(): # Test case 1 N, M = 4, 3 preferences = [ [1, 2, 3], [2, 3, 1], [3, 1, 2], [1, 3, 2] ] assert find_minimum_capacity(N, M, preferences) == 2 # Test case 2 N, M = 3, 2 preferences = [...
[ { "docstring": null, "function_declaration": "def can_all_attend(preferences, N, M, L):", "function_name": "can_all_attend", "parameter_list": "(preferences, N, M, L)" }, { "docstring": null, "function_declaration": "def find_minimum_capacity(N, M, preferences):", "function_name": "f...
[ 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 workshop_capacity(N, M, preferences):\n def can_all_attend(L):\n filled = [0] * M\n for i in range(N):\n for workshop in pr...
trial_gpt4o_1
{ "original_instruction": "Takahashi is organizing a series of workshops. There are N participants who will join. These participants are conveniently numbered from 1 to N. Takahashi wants to schedule M workshops, numbered from 1 to M. Each participant has a preference list of workshops, ranked from most preferred to ...
0.557033
Code_Contests_1403
C
[ "can_all_attend", "find_minimum_capacity", "main" ]
3
[ [ "find_minimum_capacity", "can_all_attend" ] ]
1
[]
false
[]
false
pytest
true
[]
true
5746a1af5c5ec56d657cc9e9a3cb54476f780d14
a9cd7a50debda92805725bef4ae7dadc414dd1af
v1.0
complete
Code_Contests
Code_Contests_1413_C
def minimum_additional_roads(n: int, m: int, roads: List[Tuple[int, int]]) -> int: """ Compute the minimum number of roads required to ensure that every pair of castles is connected either directly or indirectly. >>> minimum_additional_roads(5, 2, [(1, 2), (3, 4)]) 2 >>> minimum_additional_...
def count_components(n, roads): parent = list(range(n)) def find(x): if parent[x] != x: parent[x] = find(parent[x]) return parent[x] def union(x, y): rootX = find(x) rootY = find(y) if rootX != rootY: parent[rootX] = rootY ...
def test_minimum_additional_roads_basic(): assert minimum_additional_roads(5, 2, [(1, 2), (3, 4)]) == 2 def test_minimum_additional_roads_single_connection(): assert minimum_additional_roads(3, 1, [(1, 2)]) == 1 def test_minimum_additional_roads_all_connected(): assert minimum_additional_roads(4, 4, [(1, ...
[ { "docstring": null, "function_declaration": "def count_components(n, roads):", "function_name": "count_components", "parameter_list": "(n, roads)" }, { "docstring": null, "function_declaration": "def minimum_additional_roads(n, m, roads):", "function_name": "minimum_additional_roads...
[ 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 min_roads_required(N, M, roads):\n \"\"\"\n Determine the minimum number of roads required to make the graph connected.\n \n Parameters:\n ...
trial_gpt4o_1
{ "original_instruction": "In a faraway kingdom, there are numerous castles connected by roads. Each road connects exactly two castles and is bidirectional. The king wants to fortify the kingdom by ensuring that there is at least one direct or indirect road connecting every pair of castles. To achieve this, the king ...
0.684177
Code_Contests_1413
C
[ "count_components", "minimum_additional_roads" ]
2
[ [ "minimum_additional_roads", "count_components" ] ]
1
[]
false
[]
false
pytest
false
[]
true
860a6bea32e0f5820e0244d3164586c9898908ad
83e01b9182c2af60b4b36b36948b60bc1e22720f
v1.0
complete
Code_Contests
Code_Contests_1298_C
def can_form(s: str, word: str) -> bool: """Checks if 'word' can be formed by deleting some characters of 's' without reordering the remaining characters. >>> can_form("abpcplea", "apple") True >>> can_form("abpcplea", "ale") True >>> can_form("abpcplea", "monkey") False >>> can_form("ab...
def can_form(s, word): """ Checks if 'word' can be formed by deleting some characters of 's' without reordering the remaining characters. """ it = iter(s) return all(char in it for char in word) def words_from_string(s, words): """ Finds all words from the list that can be formed by deletin...
from solution import can_form, words_from_string def test_can_form(): assert can_form("abpcplea", "apple") == True assert can_form("abpcplea", "ale") == True assert can_form("abpcplea", "monkey") == False assert can_form("abc", "abc") == True assert can_form("abc", "ac") == True assert can_form...
[ { "docstring": "Checks if 'word' can be formed by deleting some characters of 's' without reordering the remaining characters.", "function_declaration": "def can_form(s, word):", "function_name": "can_form", "parameter_list": "(s, word)" }, { "docstring": "Finds all words from the list that ...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def can_form_from_string(s, word):\n \"\"\"\n Check if `word` can be formed by deleting some characters of the string `s`\n without reordering the...
trial_gpt4o_2
{ "original_instruction": "Given a string s and a list of words, find which words from the list can be formed by deleting some characters of the string s without reordering the remaining characters.\n\nInput\n\nThe first line contains the string s (1 ≤ |s| ≤ 105), consisting of lowercase Latin letters.\n\nThe second ...
0.693031
Code_Contests_1298
C
[ "can_form", "words_from_string", "solution" ]
3
[ [ "solution", "words_from_string" ], [ "words_from_string", "can_form" ] ]
2
[]
false
[]
false
pytest
true
[]
true
0575c74c35690d309507d618d06b84eda2cec8a9
4665a494bffb76b554e265e429973c3a6867ee12
v1.0
complete
Code_Contests
Code_Contests_1611_C
def maximalRectangleArea(grid: List[str]) -> int: """Find the largest rectangular area consisting of only empty cells in a rectangular grid. >>> maximalRectangleArea([ ... ".T...", ... ".TTT.", ... "...TT", ... "....." ... ]) 6 >>> maximalRectangleArea([ ... "T..T", ... ".TT....
def maximalRectangleArea(grid): if not grid: return 0 # Transform the grid into a list of lists with 0s and 1s matrix = [[0 if cell == 'T' else 1 for cell in row] for row in grid] n = len(matrix) m = len(matrix[0]) # Initialize the histogram heights heights = [0] * m m...
def test_maximalRectangleArea(): grid = [ ".T...", ".TTT.", "...TT", "....." ] assert maximalRectangleArea(grid) == 6 def test_maximalRectangleArea_single_row(): grid = [ ".T.T." ] assert maximalRectangleArea(grid) == 1 def test_maximalRectangleArea_...
[ { "docstring": null, "function_declaration": "def maximalRectangleArea(grid):", "function_name": "maximalRectangleArea", "parameter_list": "(grid)" }, { "docstring": null, "function_declaration": "def maxHistogramArea(heights):", "function_name": "maxHistogramArea", "parameter_li...
[ 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_empty_rectangle_area(grid):\n if not grid or not grid[0]:\n return 0\n\n n, m = len(grid), len(grid[0])\n heights = [0] * m\n ma...
trial_gpt4o_2
{ "original_instruction": "You are given a rectangular grid of n rows and m columns. Each cell in the grid either contains a tree or is empty. Your task is to find the largest possible rectangular area consisting of only empty cells.\n\nFor example, if the grid is:\n\n```\n. T . . .\n. T T T .\n. . . T T\n. . . . .\n...
0.618903
Code_Contests_1611
C
[ "maximalRectangleArea", "maxHistogramArea" ]
2
[ [ "maximalRectangleArea", "maxHistogramArea" ] ]
1
[]
false
[]
false
pytest
false
[]
true
426f04a1bb8036a91bc801c47a75630cb1142e9a
8f4bd5f9e8a54ecbf997d0adb7ca541d333bc0b7
v1.0
complete
Code_Contests
Code_Contests_776_C
def generate_employee_id(name: str, number: int) -> str: """Generates a unique employee ID based on the provided full name and unique number. Parameters: name (str): The full name of the employee in the format "FirstName LastName". number (int): The unique number assigned to the employee. ...
def generate_employee_id(name, number): """ Generates a unique employee ID based on the provided full name and unique number. Parameters: name (str): The full name of the employee in the format "FirstName LastName". number (int): The unique number assigned to the employee. Returns: ...
def test_generate_employee_id(): assert generate_employee_id("John Doe", 1) == "JD-1" assert generate_employee_id("Alice Smith", 2) == "AS-2" assert generate_employee_id("Bob Johnson", 3) == "BJ-3" assert generate_employee_id("Chris Evans", 25) == "CE-25" assert generate_employee_id("Tony Stark", 26...
[ { "docstring": "Generates a unique employee ID based on the provided full name and unique number.\n\nParameters:\nname (str): The full name of the employee in the format \"FirstName LastName\".\nnumber (int): The unique number assigned to the employee.\n\nReturns:\nstr: The generated employee ID.", "functio...
[ 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 generate_employee_id(full_name, number):\n \"\"\"\n Generates a unique employee ID from the employee's full name and the unique number.\n \n ...
trial_gpt4o_2
{ "original_instruction": "A company's HR department wants to generate unique employee IDs for each new hire. Each employee ID is generated using the employee’s full name and a unique number assigned to them. The unique number starts from 1 and increments by 1 for each new hire. The ID format follows these rules:\n\n...
0.650048
Code_Contests_776
C
[ "generate_employee_id", "process_new_hires" ]
2
[ [ "process_new_hires", "generate_employee_id" ] ]
1
[]
false
[]
false
pytest
false
[]
true
566115596bb1a65f110723b8f373d71ffe6c8f76
a908e1a7c648289081177b31775c4afe877dad25
v1.0
complete
Code_Contests
Code_Contests_1455_C
def maximum_gap(nums): """ Finds the maximum difference between the successive elements in the sorted form of the given array. >>> maximum_gap([3, 6, 9, 1]) 3 >>> maximum_gap([10, 5, 1, 8]) 4 >>> maximum_gap([1, 2, 3, 4, 5, 6]) 1 >>> maximum_gap([1, 1000000000]) 999999999 >>> max...
def maximum_gap(nums): """ Finds the maximum difference between the successive elements in the sorted form of the given array nums. """ if len(nums) < 2: return 0 nums.sort() max_gap = 0 for i in range(1, len(nums)): max_gap = max(max_gap, nums[i] - nums[i - 1]) ...
from solution import maximum_gap def test_max_gap_simple_case(): assert maximum_gap([3, 6, 9, 1]) == 3 def test_max_gap_another_case(): assert maximum_gap([10, 5, 1, 8]) == 4 def test_max_gap_ordered_array(): assert maximum_gap([1, 2, 3, 4, 5, 6]) == 1 def test_max_gap_single_pair(): assert maximum_...
[ { "docstring": "Finds the maximum difference between the successive elements \nin the sorted form of the given array nums.", "function_declaration": "def maximum_gap(nums):", "function_name": "maximum_gap", "parameter_list": "(nums)" }, { "docstring": null, "function_declaration": "def r...
[ 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 maximum_gap(nums):\n if len(nums) < 2:\n return 0\n \n nums.sort()\n \n max_gap = 0\n \n for i in range(1, len(nums)):\n ...
trial_gpt4o_3
{ "original_instruction": "Given an unsorted array of integers, find the maximum difference between the successive elements in its sorted form. \n\nConstraints\n\n* All values in input are integers.\n* 2 ≤ array length ≤ 10^6\n* -10^9 ≤ array elements ≤ 10^9\n\nInput\n\nInput is given from Standard Input in the follo...
0.767329
Code_Contests_1455
C
[ "maximum_gap", "read_input_and_compute_max_gap" ]
2
[ [ "read_input_and_compute_max_gap", "maximum_gap" ] ]
1
[]
false
[]
false
pytest
true
[]
true
600a465af07414b5f21c79cab7aa0c1423948b17
6938eb9094ea419705838ce1a55080fe9258d114
v1.0
complete
Code_Contests
Code_Contests_999_C
from typing import List, Tuple def can_schedule(day_events: List[Tuple[str, str]], new_event: Tuple[str, str]) -> bool: """Check if a new event can be added to the schedule without time conflicts. >>> can_schedule([("09:00", "10:00"), ("11:30", "12:30"), ("14:00", "15:00")], ("12:30", "13:00")) True >>...
def time_to_minutes(time_str): """ Convert time string in "HH:mm" format to minutes since 00:00. """ hours, minutes = map(int, time_str.split(':')) return hours * 60 + minutes def can_schedule(day_events, new_event): """ Check if the new event can be scheduled without overlapping existing e...
def test_no_overlapping_events(): assert can_schedule([("09:00", "10:00"), ("11:30", "12:30"), ("14:00", "15:00")], ("12:30", "13:00")) == True def test_overlapping_event_start(): assert can_schedule([("09:00", "10:00"), ("10:00", "11:00"), ("11:00", "12:00")], ("10:30", "11:15")) == False def test_event_same...
[ { "docstring": "Convert time string in \"HH:mm\" format to minutes since 00:00.", "function_declaration": "def time_to_minutes(time_str):", "function_name": "time_to_minutes", "parameter_list": "(time_str)" }, { "docstring": "Check if the new event can be scheduled without overlapping existi...
[ 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 typing import List, Tuple\n\ndef time_to_minutes(time: str) -> int:\n \"\"\"\n Converts a time string in \"HH:mm\" format to the number of minut...
trial_gpt4o_2
{ "original_instruction": "You are working on a new software system, and one of your responsibilities is to implement the event scheduler. An event can be scheduled on a specific day and has a start time and end time. Your task is to find out if a new event can be added to the schedule without causing any time confli...
0.632107
Code_Contests_999
C
[ "time_to_minutes", "can_schedule" ]
2
[ [ "can_schedule", "time_to_minutes" ] ]
1
[]
false
[]
false
pytest
false
[]
true
0970230046c4bca9e5877a4656c1944ac72a94e5
b213adcd9594ce30042125c3a4fd9181a28917bc
v1.0
complete
Code_Contests
Code_Contests_1255_C
def count_primes_in_interval(L: int, R: int) -> int: """ Returns the number of prime numbers in the interval [L, R] (both inclusive). >>> count_primes_in_interval(10, 20) 4 >>> count_primes_in_interval(14, 16) 0 >>> count_primes_in_interval(2, 2) 1 >>> count_prim...
def sieve_of_eratosthenes(max_num): """ Helper function to generate a list of primes up to max_num using the Sieve of Eratosthenes. """ is_prime = [True] * (max_num + 1) is_prime[0], is_prime[1] = False, False for start in range(2, int(max_num ** 0.5) + 1): if is_prime[start]: ...
from solution import count_primes_in_interval def test_single_prime(): assert count_primes_in_interval(2, 2) == 1 def test_no_primes(): assert count_primes_in_interval(14, 16) == 0 def test_multiple_primes(): assert count_primes_in_interval(10, 20) == 4 # primes are 11, 13, 17, 19 def test_entirely_pri...
[ { "docstring": "Helper function to generate a list of primes up to max_num using the Sieve of Eratosthenes.", "function_declaration": "def sieve_of_eratosthenes(max_num):", "function_name": "sieve_of_eratosthenes", "parameter_list": "(max_num)" }, { "docstring": "Returns the number of prime ...
[ 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_primes_in_interval(L, R):\n \"\"\"\n Returns the number of prime numbers in the interval [L, R] (both inclusive).\n \"\"\"\n def siev...
trial_gpt4o_1
{ "original_instruction": "Leah has recently become fascinated with prime numbers. She came up with a game involving prime numbers and intervals. Given two integers, L and R, Leah wants to determine the number of prime numbers in the interval [L, R] (both inclusive).\n\nFor example, if L=10 and R=20, the prime number...
0.703798
Code_Contests_1255
C
[ "sieve_of_eratosthenes", "count_primes_in_interval" ]
2
[ [ "count_primes_in_interval", "sieve_of_eratosthenes" ] ]
1
[]
false
[]
false
pytest
true
[]
true
d2a2b350478c3f7842e03a6b6086aa891605b23b
c08ff373f34d48ea177d86bc5b1f5f4dfe633fe8
v1.0
complete
Code_Contests
Code_Contests_1742_C
def roman_to_arabic(roman: str) -> int: """ Convert a Roman numeral to an Arabic numeral. >>> roman_to_arabic("I") 1 >>> roman_to_arabic("IV") 4 >>> roman_to_arabic("IX") 9 """ def arabic_to_roman(arabic: int) -> str: """ Convert an Arabic numeral to a Roman numeral. >>> arabic_...
def roman_to_arabic(roman): roman_values = {'I': 1, 'V': 5, 'X': 10, 'L': 50, 'C': 100, 'D': 500, 'M': 1000} total = 0 prev_value = 0 for char in reversed(roman): value = roman_values[char] if value < prev_value: total -= value else: total += value ...
import pytest from solution import roman_to_arabic, arabic_to_roman, mixed_numeral_calculator def test_roman_to_arabic(): assert roman_to_arabic("I") == 1 assert roman_to_arabic("IV") == 4 assert roman_to_arabic("IX") == 9 assert roman_to_arabic("XL") == 40 assert roman_to_arabic("C") == 100 as...
[ { "docstring": null, "function_declaration": "def roman_to_arabic(roman):", "function_name": "roman_to_arabic", "parameter_list": "(roman)" }, { "docstring": null, "function_declaration": "def arabic_to_roman(arabic):", "function_name": "arabic_to_roman", "parameter_list": "(arab...
[ 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 roman_to_arabic(roman):\n roman_values = {'I': 1, 'V': 5, 'X': 10, 'L': 50, 'C': 100, 'D': 500, 'M': 1000}\n arabic = 0\n previous_value = 0\n...
trial_gpt4o_2
{ "original_instruction": "You are working on an innovative calculator that can not only handle basic arithmetic operations but also support performing operations on mixed numeral systems (e.g., Roman and Arabic numerals). Your task is to develop a program that interprets a series of mixed numeral operations and retu...
0.60064
Code_Contests_1742
C
[ "roman_to_arabic", "arabic_to_roman", "mixed_numeral_calculator" ]
3
[ [ "mixed_numeral_calculator", "arabic_to_roman" ], [ "mixed_numeral_calculator", "roman_to_arabic" ] ]
2
[]
false
[]
false
pytest
true
[]
true
adc5fe4784f21d8c05ef61d5fa5091107be1ecc7
dcfdd7d87a4774eb5cf395cf7ae108e5e7c3c14b
v1.0
complete
Code_Contests
Code_Contests_454_C
def count_training_pairs(test_cases): """Given the badge sets for each member, determine the number of basic training pairs and the number of expert training pairs. Input: - test_cases: List of lists, where each sublist corresponds to a test case and contains lists of badges each member has. O...
def count_training_pairs(test_cases): results = [] for badges_list in test_cases: n = len(badges_list) basic_pairs = 0 expert_pairs = 0 badge_dict = {} for idx, badges in enumerate(badges_list): badg_tuple = tuple(sorted(badges)) if badg_tupl...
def test_solution(): # Sample test case 1 input_data = "2\n2\n2 1 2\n2 2 3\n3\n2 1 2\n2 2 3\n2 1 2\n" expected_output = "1 0\n3 1" assert solution(input_data) == expected_output # Additional test case 1 input_data = "1\n2\n2 1 3\n2 3 4\n" expected_output = "1 0" assert solution(input_da...
[ { "docstring": null, "function_declaration": "def count_training_pairs(test_cases):", "function_name": "count_training_pairs", "parameter_list": "(test_cases)" }, { "docstring": null, "function_declaration": "def parse_input(input_data):", "function_name": "parse_input", "paramet...
[ 0, 0, 1 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def count_training_pairs(T, cases):\n results = []\n for i in range(T):\n N = cases[i][0]\n members_badges = cases[i][1]\n \n ...
trial_gpt4o_2
{ "original_instruction": "You are tasked with organizing a special event for the Emblem Guild. The guild has members who possess different badges indicating their levels of expertise. Each member of the guild has at least one badge which represents their skill in a particular area. The event involves two types of ac...
0.52259
Code_Contests_454
C
[ "count_training_pairs", "parse_input", "solution" ]
3
[ [ "solution", "count_training_pairs" ], [ "solution", "parse_input" ] ]
2
[ "parse_input" ]
false
[]
false
pytest
false
[]
true
bb9fe0f947f2a4d30c8794becd8bdecdbead695c
584e195e6f6efe0067aad2d0066c704d02b9e4ae
v1.0
complete
Code_Contests
Code_Contests_1090_C
def find_pairs(arr, target): """ Returns a list of unique pairs (a, b) such that a + b equals the target value. Pairs are returned in ascending order and each pair (a, b) is unique. >>> find_pairs([1, 9, 8, 2, 4, 6], 10) [(1, 9), (2, 8), (4, 6)] >>> find_pairs([1, 2, 3], 10) [] >>> find_pair...
def find_pairs(arr, target): """ Returns a list of unique pairs (a, b) such that a + b equals target value. Pairs are returned in ascending order and each pair (a, b) is unique. """ pairs = set() seen = set() for num in arr: complement = target - num if complement in see...
from solution import find_pairs, solve, parse_input def test_find_pairs_normal_case(): assert find_pairs([1, 9, 8, 2, 4, 6], 10) == [(1, 9), (2, 8), (4, 6)] def test_find_pairs_no_pairs(): assert find_pairs([1, 2, 3], 10) == [] def test_find_pairs_with_duplicates(): assert find_pairs([1, 2, 4, 4], 8)...
[ { "docstring": "Returns a list of unique pairs (a, b) such that a + b equals target value.\nPairs are returned in ascending order and each pair (a, b) is unique.", "function_declaration": "def find_pairs(arr, target):", "function_name": "find_pairs", "parameter_list": "(arr, target)" }, { "d...
[ 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 find_unique_pairs(arr, x):\n \"\"\"\n Finds and returns unique pairs (a, b) in the array `arr` such that a + b = x and a <= b.\n Returns list ...
trial_gpt4o_1
{ "original_instruction": "Given an array of integers, find and print all the unique pairs of elements (a, b) such that their sum is equal to a given target value x. Each pair should be printed only once, even if there are multiple ways to form the pair from the array elements. The pair (a, b) and (b, a) are consider...
0.645404
Code_Contests_1090
C
[ "find_pairs", "solve", "parse_input" ]
3
[ [ "solve", "find_pairs" ] ]
1
[ "parse_input" ]
false
[]
false
pytest
true
[]
true
c504dbe7cfdc88bcb1d684da066ead072edc71f9
b8d110909e9620397d3125a8fcc9c9b1a4069011
v1.0
complete
Code_Contests
Code_Contests_1486_C
import re from typing import List from collections import defaultdict def check_balanced_equations(equations: List[str]) -> List[str]: """ Given a list of strings representing chemical equations, determine if each of the equations is balanced. A balanced equation is one where the number of atoms of each elemen...
import re from collections import defaultdict def is_balanced(equation): reactants, products = equation.split('=') reactant_compounds = reactants.split('+') product_compounds = products.split('+') reactant_atoms = count_atoms(reactant_compounds) product_atoms = count_atoms(product_compounds) ...
import pytest from solution import check_balanced_equations def test_single_element(): equations = ["H2+O2=H2O2"] assert check_balanced_equations(equations) == ["YES"] def test_balanced_equation(): equations = ["2H2+O2=2H2O"] assert check_balanced_equations(equations) == ["YES"] def test_multiple_ele...
[ { "docstring": null, "function_declaration": "def is_balanced(equation):", "function_name": "is_balanced", "parameter_list": "(equation)" }, { "docstring": null, "function_declaration": "def count_atoms(compounds):", "function_name": "count_atoms", "parameter_list": "(compounds)"...
[ 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": "import re\nfrom collections import defaultdict\n\ndef is_balanced(equation):\n reactants, products = equation.split('=')\n r...
trial_gpt4o_1
{ "original_instruction": "Given a list of strings representing chemical equations, determine if each of the equations is balanced. A balanced equation is one where the number of atoms of each element on the left side (reactants) is equal to the number of atoms of each element on the right side (products).\n\nEach eq...
0.504355
Code_Contests_1486
C
[ "is_balanced", "count_atoms", "parse_compound", "check_balanced_equations" ]
4
[ [ "check_balanced_equations", "is_balanced" ], [ "count_atoms", "parse_compound" ], [ "is_balanced", "count_atoms" ] ]
3
[]
false
[]
false
pytest
true
[]
true
13fe045af5ee88bf9ebc807820573523ee98a333
90e9bbb8433f96487e42286ede39229f13fad1a4
v1.0
complete
Code_Contests
Code_Contests_1840_C
def organize_competition(m: int, n: int, skill_levels: List[int], requirements: List[List[int]]) -> List[int]: """ Determine an assignment of students to challenges such that each challenge is assigned exactly one student, or report that no such assignment exists. Parameters: m (int): The number of...
from collections import defaultdict, deque def find_assignment(m, n, skill_levels, requirements): graph = defaultdict(list) for chall in range(n): for student in range(m): if requirements[chall][student] == 1: graph[student].append(chall + m) graph[chall + m]...
from solution import organize_competition def test_case_1(): m, n = 3, 3 skill_levels = [3, 2, 4] requirements = [ [1, 0, 1], [1, 1, 0], [1, 1, 1] ] result = organize_competition(m, n, skill_levels, requirements) assert sorted(result) == [1, 2, 3] # Valid assignment exi...
[ { "docstring": null, "function_declaration": "def find_assignment(m, n, skill_levels, requirements):", "function_name": "find_assignment", "parameter_list": "(m, n, skill_levels, requirements)" }, { "docstring": null, "function_declaration": "def organize_competition(m, n, skill_levels, ...
[ 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 assign_students_to_challenges(m, n, skill_levels, requirements):\n from scipy.optimize import linear_sum_assignment\n import numpy as np\n \n ...
trial_gpt4o_2
{ "original_instruction": "You are assigned to organize an inter-college coding competition. There are m colleges participating, each represented by one student, and n coding challenges. A student can be assigned to a challenge only if they have the required skill level for that challenge. Additionally, each challeng...
0.627893
Code_Contests_1840
C
[ "find_assignment", "organize_competition" ]
2
[ [ "organize_competition", "find_assignment" ] ]
1
[]
false
[]
false
pytest
true
[]
true
5d8947a4c0c2a4b8a641171cc671d474d501274e
472075194272e5c7bf8a18dd582e48893a9342d7
v1.0
complete
Code_Contests
Code_Contests_2025_C
def is_prime(n: int) -> bool: """ Returns True if n is a prime number, else False. >>> is_prime(2) True >>> is_prime(4) False """ def largest_prime_leq(M: int) -> int: """ Returns the largest prime number less than or equal to M. If no prime number exists, returns -1. >>> largest_pr...
def is_prime(n): """ Returns True if n is a prime number, else False. """ 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...
from solution import is_prime, largest_prime_leq, solve_primes 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 assert is_prime(17) == True assert is_prime(19) == True assert i...
[ { "docstring": "Returns True if n is a prime number, else False.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Returns the largest prime number less than or equal to M.\nIf no prime number exists, returns -1.", "func...
[ 1, 1, 0 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(n):\n \"\"\"\n Helper function to check if a number is prime.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n ...
trial_gpt4o_1
{ "original_instruction": "Martha has just started learning to code, and she is fascinated with prime numbers. A prime number is a natural number greater than 1 that has no positive divisors other than 1 and itself. She came across a puzzle where she needs to find the largest prime number that is smaller than or equa...
0.686373
Code_Contests_2025
C
[ "is_prime", "largest_prime_leq", "solve_primes" ]
3
[ [ "largest_prime_leq", "is_prime" ], [ "solve_primes", "largest_prime_leq" ] ]
2
[]
false
[]
false
pytest
true
[]
true
134cfbbd3ae7c4dd06e89a2141e0e2aac563279f
c2f6c824f23dac146dbe3b42b362d212955b8502
v1.0
complete
Code_Contests
Code_Contests_1247_C
def garden_simulation(m: int, n: int, grid: List[str]) -> List[str]: """ Simulate the spreading of plants in the garden. Args: m (int): Number of rows in the garden. n (int): Number of columns in the garden. grid (List[str]): Initial state of the garden with plants (P) and empty cells (.). ...
def spread_plants(m, n, garden): from collections import deque # Directions for north, south, east, west directions = [(-1, 0), (1, 0), (0, -1), (0, 1)] # Queue to perform BFS queue = deque() # Add initial plants' positions to queue for i in range(m): for j in range(n)...
def test_example_cases(): assert garden_simulation(3, 3, ['.P.', '..P', 'P..']) == [ 'PPP', 'PPP', 'PPP' ] assert garden_simulation(4, 4, ['P..P', '.PP.', '..P.', 'P..P']) == [ 'PPPP', 'PPPP', 'PPPP', 'PPPP' ] def test_empty_garden(): ass...
[ { "docstring": null, "function_declaration": "def spread_plants(m, n, garden):", "function_name": "spread_plants", "parameter_list": "(m, n, garden)" }, { "docstring": null, "function_declaration": "def garden_simulation(m, n, grid):", "function_name": "garden_simulation", "param...
[ 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 spread_plants(m, n, garden):\n from collections import deque\n \n # Directions for north, south, east, west\n directions = [(-1, 0), (1, 0)...
trial_gpt4o_0
{ "original_instruction": "You have a garden represented by a grid of size m x n (1 ≤ m, n ≤ 50). Each cell in the grid can either be empty (denoted by '.') or contain a plant (denoted by 'P'). A plant can spread to adjacent cells in the north, south, east, and west directions if the adjacent cell is empty and was no...
0.531722
Code_Contests_1247
C
[ "spread_plants", "garden_simulation" ]
2
[ [ "garden_simulation", "spread_plants" ] ]
1
[]
false
[]
false
pytest
false
[]
true
c36a8f840c7a360c8109300829f592b5970a7915
e04a46d4eec4e6bbcde3d23485b73ed06531c077
v1.0
complete
Code_Contests
Code_Contests_2308_C
def is_palindromic(number): """ Check if a number is palindromic. """ str_num = str(number) return str_num == str_num[::-1] def count_palindromic_numbers(n, m): """ Returns the count of palindromic numbers between n and m (inclusive). >>> count_palindromic_numbers(10, 20) 1 >>>...
def is_palindromic(number): """ Check if a number is palindromic. """ str_num = str(number) return str_num == str_num[::-1] def count_palindromic_numbers(n, m): """ Returns the count of palindromic numbers between n and m (inclusive). """ count = 0 for num in range(n, m + 1): ...
from solution import is_palindromic, count_palindromic_numbers def test_is_palindromic(): assert is_palindromic(121) == True assert is_palindromic(123) == False assert is_palindromic(1) == True assert is_palindromic(0) == True assert is_palindromic(11) == True assert is_palindromic(1001) == Tru...
[ { "docstring": "Check if a number is palindromic.", "function_declaration": "def is_palindromic(number):", "function_name": "is_palindromic", "parameter_list": "(number)" }, { "docstring": "Returns the count of palindromic numbers between n and m (inclusive).", "function_declaration": "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 is_palindromic(number):\n \"\"\"\n Check if a number is palindromic.\n \"\"\"\n str_num = str(number)\n return str_num == str_num[::-1]\...
trial_gpt4o_0
{ "original_instruction": "Lily is a novice programmer and she is fascinated by palindromic numbers. A palindromic number is a number that remains the same when its digits are reversed. Lily wants to write a program that, given two integers n and m (1 ≤ n ≤ m ≤ 109), can count how many numbers between n and m (inclus...
0.791725
Code_Contests_2308
C
[ "is_palindromic", "count_palindromic_numbers", "main" ]
3
[ [ "count_palindromic_numbers", "is_palindromic" ] ]
1
[]
false
[]
false
pytest
true
[]
true
c66d7f40ed86aaa9ba988ab10dab0786fc16aac0
e72acdd83eb40d7d4938486515fc8cb9572ececc
v1.0
complete
Code_Contests
Code_Contests_1776_C
MOD = 10**9 + 7 def partition_count(n): """ Returns the number of distinct ways to split n into one or more non-negative integers in non-increasing order modulo 10^9 + 7. """ dp = [0] * (n + 1) dp[0] = 1 # There's one way to partition 0 (an empty sum) for i in range(1, n + 1): ...
MOD = 10**9 + 7 def partition_count(n): """ Returns the number of distinct ways to split n into one or more non-negative integers in non-increasing order modulo 10^9 + 7. """ dp = [0] * (n + 1) dp[0] = 1 # There's one way to partition 0 (an empty sum) for i in range(1, n + 1): ...
def test_partition_count_0(): assert distinct_partition_modulo(0) == 1 # Only one way: empty partition def test_partition_count_2(): assert distinct_partition_modulo(2) == 2 # Partitions: [2], [1,1] def test_partition_count_5(): assert distinct_partition_modulo(5) == 7 # Partitions: [5], [4,1], [3,2], ...
[ { "docstring": "Returns the number of distinct ways to split n into one or more non-negative integers \nin non-increasing order modulo 10^9 + 7.", "function_declaration": "def partition_count(n):", "function_name": "partition_count", "parameter_list": "(n)" }, { "docstring": null, "funct...
[ 0, 0, 1 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "MOD = 10**9 + 7\n\ndef ways_to_split(k):\n # DP array to store the number of ways to partition each number up to k\n dp = [0] * (k + 1)\n dp[0] = ...
trial_gpt4o_2
{ "original_instruction": "A company organizes a contest where participants earn points through various activities. Each participant's total points can be represented as a non-negative integer. The company wants to reward the participants by giving out certificates based on the number of distinct ways the total point...
0.706824
Code_Contests_1776
C
[ "partition_count", "distinct_partition_modulo" ]
2
[ [ "distinct_partition_modulo", "partition_count" ] ]
1
[]
false
[]
false
pytest
false
[]
true
80a14bddc3f6a55fc1f4a794b8fdc12c06becd2f
a7021915a4b9fa061f35fce289023b9cb60573cd
v1.0
complete
Code_Contests
Code_Contests_652_C
from typing import List, Tuple def preprocess_tree(n: int, edges: List[Tuple[int, int]]) -> Tuple[List[int], List[int]]: """ Preprocess the tree to prepare for efficient path length queries. :param n: Number of nodes in the tree :param edges: List of tuples representing edges in the tree :retu...
from collections import defaultdict, deque def preprocess_tree(n, edges): """ Preprocess the tree to prepare for efficient path length queries. :param n: Number of nodes in the tree :param edges: List of tuples representing edges in the tree :return: parent, depth arrays used for LCA computati...
from solution import process_queries def test_example_case(): n = 5 edges = [(1, 2), (1, 3), (3, 4), (3, 5)] queries = [(2, 4), (2, 5), (4, 5)] expected_results = [3, 3, 2] assert process_queries(n, edges, queries) == expected_results def test_simple_case(): n = 2 edges = [(1, 2)] quer...
[ { "docstring": "Preprocess the tree to prepare for efficient path length queries.\n\n:param n: Number of nodes in the tree\n:param edges: List of tuples representing edges in the tree\n:return: parent, depth arrays used for LCA computation", "function_declaration": "def preprocess_tree(n, edges):", "fun...
[ 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": "from collections import deque\n\ndef preprocess_tree(n, edges):\n # create adjacency list\n adj_list = [[] for _ in range(n + 1)]\n for u, v in ed...
trial_gpt4o_4
{ "original_instruction": "Valera is studying trees this time. A tree is a connected graph with no cycles. Valera finds trees particularly interesting because there is exactly one unique path between any two nodes.\n\nValera is given a tree with n nodes labeled from 1 to n. He wants to perform some queries on this tr...
0.614064
Code_Contests_652
C
[ "preprocess_tree", "lca", "distance", "process_queries" ]
4
[ [ "distance", "lca" ], [ "process_queries", "distance" ], [ "process_queries", "preprocess_tree" ] ]
3
[ "process_queries" ]
false
[]
false
pytest
true
[]
true
3a800e6a5f3c9e60a2c920bd5890034fa1198b08
2d72c1b5f1162b719707411f7baef30b774441d5
v1.0
complete
Code_Contests
Code_Contests_2167_C
def is_magic_number(n): """ Checks if the number is a magic number. A magic number has a non-zero digit which is repeated consecutively. >>> is_magic_number(233) True >>> is_magic_number(858558) True >>> is_magic_number(123) False >>> is_magic_number(405) False >>> i...
def is_magic_number(n): """ Checks if the number is a magic number. A magic number has a non-zero digit which is repeated consecutively. """ n = abs(n) str_n = str(n) for i in range(1, len(str_n)): if str_n[i] == str_n[i-1] and str_n[i] != '0': return True return Fals...
import pytest from solution import is_magic_number, count_magic_numbers def test_is_magic_number(): assert is_magic_number(233) == True assert is_magic_number(858558) == True assert is_magic_number(123) == False assert is_magic_number(405) == False assert is_magic_number(10011) == True assert i...
[ { "docstring": "Checks if the number is a magic number.\nA magic number has a non-zero digit which is repeated consecutively.", "function_declaration": "def is_magic_number(n):", "function_name": "is_magic_number", "parameter_list": "(n)" }, { "docstring": "Counts the total number of magic n...
[ 0, 0, 0, 0, 1 ]
1
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_magic_number(num):\n \"\"\"\n Check if the number is a magic number.\n A magic number has a non-zero digit which appears consecutively.\n ...
trial_gpt4o_4
{ "original_instruction": "You are given an array of N integers. An integer X is said to be a \"magic number\" if and only if it has a non-zero digit which is repeated consecutively. For example, 233, 858558, and 10011 are magic numbers, while 123, 405, and 8990 are not.\n\nFind the total number of \"magic numbers\" ...
0.629116
Code_Contests_2167
C
[ "is_magic_number", "count_magic_numbers" ]
2
[ [ "count_magic_numbers", "is_magic_number" ] ]
1
[]
false
[]
false
pytest
true
[]
true
0e27e4dde8f8f6402f490b59d9352df057b01e4a
7393c3ebc98042a8031f29b0cd7fa087bc1bc665
v1.0
complete
Code_Contests
Code_Contests_1608_C
def longest_increasing_path(n: int, m: int, grid: List[str]) -> int: """ Eva loves puzzles and has a special one involving a grid of letters. Find the length of the longest contiguous path in the grid where each letter in the path is in increasing alphabetical order, and each step in the path moves one cel...
def longest_increasing_path(n, m, grid): def dfs(x, y): if dp[x][y] != -1: return dp[x][y] max_length = 1 for dx, dy in directions: nx, ny = x + dx, y + dy if 0 <= nx < n and 0 <= ny < m and ord(grid[nx][ny]) == ord(grid[x][y]) + 1: max_le...
import pytest from solution import solve def test_example1(): input_str = "3 4\nabcd\nbcde\ncdef" assert solve(input_str) == 6 def test_example2(): input_str = "4 4\nabcd\naxby\nazcp\nmnop" assert solve(input_str) == 4 def test_min_case(): input_str = "1 1\na" assert solve(input_str) == 1 de...
[ { "docstring": null, "function_declaration": "def longest_increasing_path(n, m, grid):", "function_name": "longest_increasing_path", "parameter_list": "(n, m, grid)" }, { "docstring": null, "function_declaration": "def solve(input_str):", "function_name": "solve", "parameter_list...
[ 0, 0, 0, 0, 0, 0, 0, 0, 1, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def longest_increasing_path(grid):\n n, m = len(grid), len(grid[0])\n dp = [[-1 for _ in range(m)] for _ in range(n)]\n directions = [(-1, 0), (1,...
trial_gpt4o_8
{ "original_instruction": "Eva loves puzzles and has a special one involving a grid of letters. You are given a grid of size n x m filled with lowercase English letters. Eva wants to find the longest contiguous path in the grid where each letter in the path is in increasing alphabetical order, and each step in the pa...
0.627278
Code_Contests_1608
C
[ "longest_increasing_path", "solve" ]
2
[ [ "solve", "longest_increasing_path" ] ]
1
[]
false
[]
false
pytest
true
[]
true
d9ad32aaa76cf57d6a66895e65d25eb3b92bda09
012b8336e9110693e86cc315e0db8ca8d855fcb2
v1.0
complete
Code_Contests
Code_Contests_1877_C
def scheduler(input_string: str) -> List[int]: """ You are tasked with assembling a scheduler for a series of events happening in different rooms. Each event has a specified start and end time. The goal of the scheduler is to ensure that no two events overlap in the same room and to minimize the number of r...
def min_rooms_for_events(datasets): results = [] for events in datasets: if not events: continue times = [] for start, end in events: times.append((start, 'start')) times.append((end, 'end')) times.sort() current_rooms = 0 max_...
from solution import scheduler def test_scheduler(): input_data = """3 0 30 5 10 15 20 4 1 10 2 3 5 7 8 9 0""" expected_output = [2, 2] assert scheduler(input_data) == expected_output def test_scheduler_no_overlap(): input_data = """3 0 10 15 20 25 30 0""" expected_output = [1] a...
[ { "docstring": null, "function_declaration": "def min_rooms_for_events(datasets):", "function_name": "min_rooms_for_events", "parameter_list": "(datasets)" }, { "docstring": null, "function_declaration": "def parse_input(input_string):", "function_name": "parse_input", "parameter...
[ 0, 1, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "import heapq\n\ndef min_meeting_rooms(intervals):\n if not intervals:\n return 0\n \n intervals.sort(key=lambda x: x[0])\n\n heap = []\n...
trial_gpt4o_1
{ "original_instruction": "You are tasked with assembling a scheduler for a series of events happening in different rooms. Each event has a specified start and end time. The goal of the scheduler is to ensure that no two events overlap in the same room and to minimize the number of rooms required.\n\nTo help you deve...
0.548998
Code_Contests_1877
C
[ "min_rooms_for_events", "parse_input", "scheduler" ]
3
[ [ "scheduler", "min_rooms_for_events" ], [ "scheduler", "parse_input" ] ]
2
[ "parse_input" ]
false
[]
false
pytest
true
[]
true
92544e829ea457a958b34b6b4e82da73bd463f92
e92dc3596c68ce49d6738129dcc14d1b86895684
v1.0
complete
Code_Contests
Code_Contests_2372_C
def smallest_permutations(input_string: str) -> str: """ Given an input string with multiple test cases, each containing an array of integers, determine the lexicographically smallest permutation of the array that can be obtained by performing swaps as described. :param input_string: a str contain...
def lexicographically_smallest_permutations(test_cases): results = [] for case in test_cases: array = case['array'] sorted_array = sorted(array) results.append(sorted_array) return results def process_input(input_string): input_lines = input_string.strip().split("\n") ...
from solution import smallest_permutations def test_sample_case(): input_string = "3\n5\n3 1 2 5 4\n4\n9 5 3 7\n3\n10 8 2" expected_output = "1 2 3 4 5\n3 5 7 9\n2 8 10" assert smallest_permutations(input_string) == expected_output def test_single_element(): input_string = "2\n1\n1\n1\n1000000000" ...
[ { "docstring": null, "function_declaration": "def lexicographically_smallest_permutations(test_cases):", "function_name": "lexicographically_smallest_permutations", "parameter_list": "(test_cases)" }, { "docstring": null, "function_declaration": "def process_input(input_string):", "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 smallest_permutation(t, test_cases):\n \"\"\"\n Returns the lexicographically smallest permutation for each test case.\n \n Parameters:\n ...
trial_gpt4o_2
{ "original_instruction": "You are given an array of n integers a_1, a_2, ..., a_n. You can perform the following operation on the array any number of times:\n\n- Choose two integers i and j (1 ≤ i < j ≤ n) such that a_i is less than a_j, and then swap a_i and a_j.\n\nYour task is to determine the lexicographically s...
0.691677
Code_Contests_2372
C
[ "lexicographically_smallest_permutations", "process_input", "format_output", "smallest_permutations" ]
4
[ [ "smallest_permutations", "format_output" ], [ "smallest_permutations", "lexicographically_smallest_permutations" ], [ "smallest_permutations", "process_input" ] ]
3
[ "process_input", "format_output" ]
false
[]
false
pytest
true
[]
true
eaf5dd24d1b9db272f198c2a8bf1abd638a7609c
d8da252a6e53fab8e6d78fca6e4bd1b7e33bb95a
v1.0
complete
Code_Contests
Code_Contests_1916_C
class TreeNode: def __init__(self, x): self.val = x self.left = None self.right = None def find_height(root): """ Recursively finds the height of the binary tree. >>> find_height(TreeNode(1)) == 0 """ pass def lca(root, p, q): """ Finds the lowest common ances...
class TreeNode: def __init__(self, x): self.val = x self.left = None self.right = None def find_height(root): if root is None: return -1 else: left_height = find_height(root.left) right_height = find_height(root.right) return 1 + max(left_height, righ...
def test_find_height(): assert find_height(TreeNode(1)) == 0 # Single node tree height def test_lca_basic(): root = TreeNode(1) node2 = TreeNode(2) node3 = TreeNode(3) root.left = node2 root.right = node3 assert lca(root, node2, node3).val == 1 # LCA of 2 and 3 is 1 def test_lca_deeper(): ...
[]
[ 0, 1, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "class TreeNode:\n def __init__(self, x):\n self.val = x\n self.left = None\n self.right = None\n\n\nclass BinaryTree:\n def __in...
trial_gpt4o_1
{ "original_instruction": "Given a binary tree, you have to either:\n \n * find the height of the tree.\n * or find the lowest common ancestor (LCA) of two given nodes in the tree. \n\nThe height of a binary tree is the number of edges on the longest path from the root to a leaf. The lowest common ancestor of two ...
0.602378
Code_Contests_1916
C
[ "find_height", "lca", "parse_tree", "find_height_or_lca" ]
4
[ [ "find_height_or_lca", "find_height" ], [ "find_height_or_lca", "lca" ], [ "find_height_or_lca", "parse_tree" ] ]
3
[]
false
[ "TreeNode" ]
true
pytest
false
[]
true
f8630300dec14d15013fbe05628bfcffa61dfa17
c410510cdb565f6d70be3bbc4469573c0842bf49
v1.0
complete
Code_Contests
Code_Contests_1869_C
import re from typing import Tuple def compress(text: str) -> str: """ Compresses a text using basic run-length encoding. Parameters: text (str): The input string to be compressed. Returns: str: The compressed string. """ pass def expand(text: str) -> str: """...
import re def compress(text): """ Compresses a text using basic run-length encoding. Parameters: text (str): The input string to be compressed. Returns: str: The compressed string. """ compressed = [] count = 1 for i in range(1, len(text)): if ...
from solution import compress, expand, process_text def test_compress(): assert compress("aaabccccd") == "a3b1c4d1" assert compress("hhhhhhhhhhhh") == "h12" assert compress("abc") == "a1b1c1" assert compress("a") == "a1" def test_expand(): assert expand("a3b1c4d1") == "aaabccccd" assert expand...
[ { "docstring": "Compresses a text using basic run-length encoding.\n\nParameters:\n text (str): The input string to be compressed.\n \nReturns:\n str: The compressed string.", "function_declaration": "def compress(text):", "function_name": "compress", "parameter_list": "(text)" }, { ...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "import re\n\ndef compress_string(s):\n \"\"\"\n Compresses the given string using run-length encoding.\n \n Parameters:\n s (str): The strin...
trial_gpt4o_1
{ "original_instruction": "### Problem: Compress and Expand String\n\nYou are working on a compression algorithm to save space in large text files. To achieve this, you decide to implement a basic run-length encoding (RLE) scheme where sequences of the same character are replaced by a single character followed by the...
0.657408
Code_Contests_1869
C
[ "compress", "expand", "process_text" ]
3
[ [ "process_text", "compress" ], [ "process_text", "expand" ] ]
2
[]
false
[]
false
pytest
true
[]
true
dd34f0c95f38758dd311cff9401b449d8ba8de2a
c4804080b2fab317c346f61b3a23e7919571ed57
v1.0
complete
Code_Contests
Code_Contests_2385_C
def can_register(new_username: str, existing_usernames: List[str]) -> str: """ Determines if the new username can be registered, based on similarity rules. >>> can_register("coder!name", ["Coder1name", "codER&name", "CoderName!"]) 'No' >>> can_register("secure7code", ["secure&code", "SECUre7CoDE"]) ...
def transform_char(c): """ Transform a character based on the explained rules. """ if c == '1': return ['1', '!'] elif c == '!': return ['!', '1'] elif c == '7': return ['7', '&'] elif c == '&': return ['&', '7'] elif c.isalpha(): return [c.lower()...
import pytest from solution import can_register def test_example_1(): new_username = "coder!name" existing_usernames = ["Coder1name", "codER&name", "CoderName!"] assert can_register(new_username, existing_usernames) == "No" def test_example_2(): new_username = "secure7code" existing_usernames = ["...
[ { "docstring": "Transform a character based on the explained rules.", "function_declaration": "def transform_char(c):", "function_name": "transform_char", "parameter_list": "(c)" }, { "docstring": "Generate all possible transformations of a username.", "function_declaration": "def transf...
[ 0, 0, 0, 0, 0, 1, 0, 0, 0, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_similar(new_username, existing_username):\n sim_map = {'1': '!', '!': '1', '7': '&', '&': '7'}\n \n # Helper function to shift character\n ...
trial_gpt4o_5
{ "original_instruction": "You are designing a system to manage usernames for a web application. Each username can only contain lowercase and uppercase Latin letters, digits, and special characters. However, to ensure better user readability, the system prohibits registration of usernames if the new username can be c...
0.483014
Code_Contests_2385
C
[ "transform_char", "transform_username", "can_register" ]
3
[ [ "can_register", "transform_username" ], [ "transform_username", "transform_char" ] ]
2
[]
false
[]
false
pytest
true
[]
true
4557fe3114d6ff6b9c86d3ded773fca0ced2529c
c52064012a19e236c00bd93568469c369a2c08c1
v1.0
complete
Code_Contests
Code_Contests_1825_C
import math from typing import List def lcm(a: int, b: int) -> int: """ Calculate the least common multiple of two integers. """ pass def min_total_check_time(n: int, k: int) -> int: """ Calculate the minimum total time required to check all the robots at least once. Each robot's maintenance check rec...
import math def lcm(a, b): return a * b // math.gcd(a, b) def min_total_check_time(n, k): return lcm(n, k)
from solution import min_total_check_time def test_basic_case(): assert min_total_check_time(5, 3) == 15 def test_equal_n_and_k(): assert min_total_check_time(4, 4) == 4 def test_n_greater_than_k(): assert min_total_check_time(6, 3) == 6 def test_k_greater_than_n(): assert min_total_check_time(3, 7)...
[ { "docstring": null, "function_declaration": "def lcm(a, b):", "function_name": "lcm", "parameter_list": "(a, b)" }, { "docstring": null, "function_declaration": "def min_total_check_time(n, k):", "function_name": "min_total_check_time", "parameter_list": "(n, k)" } ]
[ 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 minimum_check_time(n, k):\n \"\"\"\n Calculates the minimum total time required to check all robots once.\n \n Args:\n n (int): Number o...
trial_gpt4o_9
{ "original_instruction": "The year is 2030, and humanity has established a colony on Mars. To ensure the smooth functioning of the colony, a group of engineers and scientists have developed an advanced robotic system. This robotic system is responsible for maintaining critical infrastructure such as the air supply, ...
0.562733
Code_Contests_1825
C
[ "lcm", "min_total_check_time" ]
2
[ [ "min_total_check_time", "lcm" ] ]
1
[]
false
[]
false
pytest
true
[]
true
f88017a038918c3eb60be609ccd0c1a944110dd9
313bd34d3270315d6bdc67f9b54e194bad3d81da
v1.0
complete
Code_Contests
Code_Contests_2232_C
from typing import List def sum_of_digits(n: int) -> int: """Calculate the sum of the digits of a number. >>> sum_of_digits(123) 6 >>> sum_of_digits(4567) 22 >>> sum_of_digits(0) 0 >>> sum_of_digits(987654321) 45 """ def nth_fibonacci(n: int) -> int: """Calculate the N-th Fibonacci number....
def sum_of_digits(n): return sum(int(digit) for digit in str(n)) def nth_fibonacci(n): if n == 1: return 1 elif n == 2: return 1 a, b = 1, 1 for _ in range(3, n + 1): a, b = b, a + b return b def sum_of_digits_in_nth_fibonacci(n): fib_number = nth_fibonacci(n) r...
def test_sum_of_digits(): assert sum_of_digits(123) == 6 assert sum_of_digits(4567) == 22 assert sum_of_digits(0) == 0 assert sum_of_digits(987654321) == 45 def test_nth_fibonacci(): assert nth_fibonacci(1) == 1 assert nth_fibonacci(2) == 1 assert nth_fibonacci(3) == 2 assert nth_fibona...
[ { "docstring": null, "function_declaration": "def sum_of_digits(n):", "function_name": "sum_of_digits", "parameter_list": "(n)" }, { "docstring": null, "function_declaration": "def nth_fibonacci(n):", "function_name": "nth_fibonacci", "parameter_list": "(n)" }, { "docstri...
[ 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 sum_of_digits_of_fibonacci(n):\n \"\"\"\n Returns the sum of the digits of the N-th Fibonacci number.\n \"\"\"\n if n == 1:\n return...
trial_gpt4o_9
{ "original_instruction": "Ana is interested in number series and their properties. She loves exploring the sum of digits in such series. Currently, she is focused on Fibonacci numbers. The Fibonacci sequence is defined as follows:\n\n- F(0) = 0\n- F(1) = 1\n- F(n) = F(n-1) + F(n-2) for n ≥ 2\n\nAna wants to know the...
0.771523
Code_Contests_2232
C
[ "sum_of_digits", "nth_fibonacci", "sum_of_digits_in_nth_fibonacci", "sum_of_digits_of_nth_fibonacci_for_multiple_cases" ]
4
[ [ "sum_of_digits_in_nth_fibonacci", "nth_fibonacci" ], [ "sum_of_digits_in_nth_fibonacci", "sum_of_digits" ], [ "sum_of_digits_of_nth_fibonacci_for_multiple_cases", "sum_of_digits_in_nth_fibonacci" ] ]
3
[]
false
[]
false
pytest
false
[]
true
28f18c6c550039b42ff7125743d41ab5b157808c
d2d5754b5bccec53f4e1de7d271adde1029b01fc
v1.0
complete
Code_Contests
Code_Contests_2056_C
import math from functools import reduce from typing import List, Tuple def minimum_seconds(T: int, test_cases: List[Tuple[int, List[int]]]) -> List[int]: """ Given a number of test cases, determines the minimum number of seconds after which all runners will be back at their starting checkpoints simultaneo...
import math from functools import reduce def lcm(a, b): """ Helper function to compute the Least Common Multiple (LCM) of two integers. """ return abs(a*b) // math.gcd(a, b) def lcm_multiple(nums): """ Helper function to compute the LCM of a list of integers. """ return reduce(lcm, num...
from solution import minimum_seconds def test_case_1(): T = 2 test_cases = [(3, [2, 3, 2]), (4, [1, 3, 4, 6])] assert minimum_seconds(T, test_cases) == [6, 12] def test_case_2(): T = 1 test_cases = [(5, [1, 2, 3, 4, 5])] assert minimum_seconds(T, test_cases) == [60] def test_case_3(): T =...
[ { "docstring": "Helper function to compute the Least Common Multiple (LCM) of two integers.", "function_declaration": "def lcm(a, b):", "function_name": "lcm", "parameter_list": "(a, b)" }, { "docstring": "Helper function to compute the LCM of a list of integers.", "function_declaration"...
[ 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\ndef lcm(a, b):\n \"\"\"\n Helper function to compute the Least Common Multiple (LCM) of two integers.\n ...
trial_gpt4o_0
{ "original_instruction": "You are given a circular track with N checkpoints numbered from 1 to N. A group of runners is participating in a race and each runner starts from a different checkpoint. Due to a magical spell, every second, each runner moves forward a unique, pre-determined number of steps. The race organi...
0.603119
Code_Contests_2056
C
[ "lcm", "lcm_multiple", "minimum_seconds" ]
3
[ [ "lcm_multiple", "lcm" ], [ "minimum_seconds", "lcm_multiple" ] ]
2
[]
false
[]
false
pytest
true
[]
true
bc8d37c78c99b121bb0ca5e0cf6fce9af40b5a78
8691c87936d91cc77e7decace55c2e56e6bb52d3
v1.0
complete
Code_Contests
Code_Contests_1594_C
def gcd(a: int, b: int) -> int: """ Returns the greatest common divisor (GCD) of a and b. """ pass def lcm(a: int, b: int) -> int: """ Returns the least common multiple (LCM) of a and b. """ pass def find_min_stability(arr: List[int]) -> int: """ Determines the minimum possible difference between ...
import math from functools import reduce def gcd(a, b): """ Returns the greatest common divisor (GCD) of a and b. """ return math.gcd(a, b) def lcm(a, b): """ Returns the least common multiple (LCM) of a and b. """ return a * b // gcd(a, b) def find_min_stability(arr): """ Det...
def test_find_min_stability_single_element(): assert find_min_stability([7]) == 0 def test_find_min_stability_example1(): assert find_min_stability([2, 4, 6, 8]) == 0 def test_find_min_stability_example2(): assert find_min_stability([5, 10, 15, 20, 25]) == 0 def test_find_min_stability_all_same_elements(...
[ { "docstring": "Returns the greatest common divisor (GCD) of a and b.", "function_declaration": "def gcd(a, b):", "function_name": "gcd", "parameter_list": "(a, b)" }, { "docstring": "Returns the least common multiple (LCM) of a and b.", "function_declaration": "def lcm(a, b):", "fun...
[ 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": "import math\nfrom functools import reduce\n\ndef min_difference(arr):\n \"\"\"\n This function takes an array of integers and returns the minimum pos...
trial_gpt4o_8
{ "original_instruction": "Maria loves playing with numbers. She has an array of integers and she likes to perform the following operations:\n\n1. Select any two integers a and b from the array.\n2. Replace one of these integers with their greatest common divisor (GCD).\n3. Replace the other integer with their least ...
0.645474
Code_Contests_1594
C
[ "gcd", "lcm", "find_min_stability" ]
3
[ [ "find_min_stability", "gcd" ], [ "lcm", "gcd" ] ]
2
[]
false
[]
false
pytest
false
[]
true
0980d4941ef7c799e3f7f457d06abd57824447fa
b03e30a8063a669fa074440e79f52992e6486333
v1.0
complete
Code_Contests
Code_Contests_2588_C
from typing import List, Tuple def process_input_and_solve(n: int, m: int, roads: List[Tuple[int, int, int, int]]) -> Tuple[int, int]: """ Determine the shortest possible distance and the longest possible distance between town 1 and town n. Arguments: n -- the number of towns m -- the number of roads ...
import heapq def dijkstra(n, graph, is_min): distances = [float('inf')] * (n + 1) distances[1] = 0 pq = [(0, 1)] # (distance, node) while pq: current_distance, u = heapq.heappop(pq) if current_distance > distances[u]: continue for v, min_d, ma...
import pytest from solution import process_input_and_solve def test_example_1(): n = 4 m = 4 roads = [ (1, 2, 3, 5), (2, 3, 2, 4), (3, 4, 1, 3), (1, 4, 10, 12) ] assert process_input_and_solve(n, m, roads) == (6, 12) def test_example_2(): n = 5 m = 5 roa...
[ { "docstring": null, "function_declaration": "def dijkstra(n, graph, is_min):", "function_name": "dijkstra", "parameter_list": "(n, graph, is_min)" }, { "docstring": null, "function_declaration": "def shortest_and_longest_path(n, m, roads):", "function_name": "shortest_and_longest_pa...
[ 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\nimport sys\n\ndef dijkstra(graph, start, n, is_min):\n # Set initial distances to infinity\n distances = [sys.maxsize] * (n + 1)\n d...
trial_gpt4o_2
{ "original_instruction": "In a magical land, there are n towns connected by m bidirectional roads. Each road has a certain travel distance associated with it. Some of these roads, unfortunately, have been enchanted by a mischievous sorcerer, causing each road's distance to oscillate by a given factor. You have a spe...
0.68692
Code_Contests_2588
C
[ "dijkstra", "shortest_and_longest_path", "process_input_and_solve" ]
3
[ [ "process_input_and_solve", "shortest_and_longest_path" ], [ "shortest_and_longest_path", "dijkstra" ] ]
2
[]
false
[]
false
pytest
true
[]
true
871fe8cbb7bbe2c8daf4d38ebcfdb13edcb61269
c7e8ab33854f9a1af6da2139e7d7d1bb64c2c771
v1.0
complete
Code_Contests
Code_Contests_1337_C
import heapq def dijkstra(n, edges, start): """ Helper function using Dijkstra's algorithm to find the shortest paths from `start` to all other nodes in the graph. """ distances = {node: float('inf') for node in range(1, n + 1)} distances[start] = 0 priority_queue = [(0, start)] while ...
import heapq def dijkstra(n, edges, start): """ Helper function using Dijkstra's algorithm to find the shortest paths from `start` to all other nodes in the graph. """ distances = {node: float('inf') for node in range(1, n + 1)} distances[start] = 0 priority_queue = [(0, start)] while ...
def test_find_optimal_post_office_example_1(): n = 4 m = 4 connections = [(1, 2, 1), (2, 3, 1), (3, 4, 1), (4, 1, 1)] result = find_optimal_post_office(n, m, connections) assert result == 2 def test_find_optimal_post_office_example_2(): n = 5 m = 6 connections = [ (1, 2, 2), ...
[ { "docstring": "Helper function using Dijkstra's algorithm to find the shortest paths from `start` to all other nodes in the graph.", "function_declaration": "def dijkstra(n, edges, start):", "function_name": "dijkstra", "parameter_list": "(n, edges, start)" }, { "docstring": "This function ...
[ 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": "import heapq\nimport sys\nfrom collections import defaultdict\n\ndef dijkstra(graph, start, n):\n dist = [float('inf')] * (n + 1)\n dist[start] = 0\n...
trial_gpt4o_3
{ "original_instruction": "A city in Byteland wants to establish a new postal service. The city has n neighborhoods and m direct connections between them. Each connection is bidirectional and has a specific distance d.\n\nThe postal service aims to establish a central post office in one of the neighborhoods such that...
0.598029
Code_Contests_1337
C
[ "dijkstra", "find_optimal_post_office" ]
2
[ [ "find_optimal_post_office", "dijkstra" ] ]
1
[]
false
[]
false
pytest
false
[]
true
939c5a06fa31e14d351d142c4eddee0da9d4df68
52539f055c703406317cd98504a49913a3fbf18f
v1.0
complete
Code_Contests
Code_Contests_2895_C
def count_solution(m: int) -> int: """ Calculate the number of distinct ways to place magical flowers in an M x M grid such that each row and each column contains exactly one flower. >>> count_solution(1) 1 >>> count_solution(2) 2 >>> count_solution(3) 6 >>> count_solution(4) 24 >>> count_soluti...
import itertools def count_distinct_arrangements(m): def is_valid(permutation): return len(set(permutation)) == len(permutation) count = 0 for perm in itertools.permutations(range(m)): if is_valid(perm): count += 1 return count def count_solution(m): retur...
from solution import count_solution def test_count_solution_m_1(): assert count_solution(1) == 1 def test_count_solution_m_2(): assert count_solution(2) == 2 def test_count_solution_m_3(): assert count_solution(3) == 6 def test_count_solution_m_4(): assert count_solution(4) == 24 def test_count_sol...
[ { "docstring": null, "function_declaration": "def count_distinct_arrangements(m):", "function_name": "count_distinct_arrangements", "parameter_list": "(m)" }, { "docstring": null, "function_declaration": "def count_solution(m):", "function_name": "count_solution", "parameter_list...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "from itertools import permutations\n\ndef count_distinct_flower_arrangements(m):\n \"\"\"\n Counts the number of distinct ways to arrange flowers in ...
trial_gpt4o_2
{ "original_instruction": "In a faraway kingdom, there exists a magical garden divided into an M x M grid. Each cell in the grid represents a plot of land that can grow magical flowers. The king of this kingdom wants to arrange his garden in such a way that the flowers form a symmetrical pattern. Specifically, each r...
0.557604
Code_Contests_2895
C
[ "count_distinct_arrangements", "count_solution" ]
2
[ [ "count_solution", "count_distinct_arrangements" ] ]
1
[]
false
[]
false
pytest
true
[]
true
a0679de4cadf69212aa9057ccdf0b4acb4afa5fc
b11bd11685d8c34c7a5677e7a505178545c00889
v1.0
complete
Code_Contests
Code_Contests_499_C
import heapq import sys from typing import List, Tuple, Dict def dijkstra(n: int, adj_list: List[List[Tuple[int, int]]], start: int, end: int) -> Tuple[int, List[int]]: """ Find the shortest path in a graph using Dijkstra's algorithm. Args: n: Number of vertices adj_list: Adjacency list of...
import heapq import sys def dijkstra(n, adj_list, start, end): dist = [sys.maxsize] * n dist[start] = 0 prev = [-1] * n pq = [(0, start)] while pq: current_dist, u = heapq.heappop(pq) if current_dist > dist[u]: continue for v, weight in adj...
def test_process_input(): input_string = """5 6 0 1 2 1 2 4 2 3 1 3 0 7 3 4 3 1 4 5 0 4 3 3 0 1 1 1 2 1 0 2 5 0 2 #""" expected_output = [ { 'n': 5, 'm': 6, 'edges': [(0, 1, 2), (1, 2, 4), (2, 3, 1), (3, 0, 7), (3, 4, 3), (1, 4, 5)], 's': 0, 't': 4 }, { ...
[ { "docstring": null, "function_declaration": "def dijkstra(n, adj_list, start, end):", "function_name": "dijkstra", "parameter_list": "(n, adj_list, start, end)" }, { "docstring": null, "function_declaration": "def shortest_paths(datasets):", "function_name": "shortest_paths", "p...
[ 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": "import heapq\n\ndef dijkstra(n, edges, start, end):\n graph = {i: [] for i in range(n)}\n for u, v, w in edges:\n graph[u].append((v, w))\n ...
trial_gpt4o_3
{ "original_instruction": "You are given an undirected graph with `n` vertices and `m` edges. Each edge has a weight associated with it. Write a program to find the shortest path from a given start vertex `s` to an end vertex `t`. If there are multiple shortest paths, return any one of them.\n\nInput\n\nThe input con...
0.638914
Code_Contests_499
C
[ "dijkstra", "shortest_paths", "process_input", "generate_output", "main" ]
5
[ [ "shortest_paths", "dijkstra" ] ]
1
[ "process_input", "generate_output" ]
false
[]
false
pytest
false
[]
true
a34ce2a0330e5163a8cd5df79a35827ddb646aa7
aac30eaf9ddf4ce3ac1445ae397824192dd393fe
v1.0
complete
Code_Contests
Code_Contests_939_C
from typing import List, Tuple def minimum_distance_to_travel(N: int, M: int, roads: List[Tuple[int, int, int]]) -> int: """ Find the minimum total distance the mailman has to travel to deliver letters to all houses. Args: N (int): the number of houses M (int): the number of roads roads (List[...
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 rank[rootX] < rank[rootY]: parent[rootX] = rootY elif rank[rootX] > rank[rootY]: parent[rootY] = rootX e...
from solution import minimum_distance_to_travel def test_sample_input(): N, M = 4, 5 roads = [(1, 2, 5), (1, 3, 10), (1, 4, 9), (2, 3, 8), (3, 4, 6)] assert minimum_distance_to_travel(N, M, roads) == 19 def test_single_house(): N, M = 1, 0 roads = [] assert minimum_distance_to_travel(N, M, roa...
[ { "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, 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 heapq\n\ndef minimum_mailman_distance(N, M, roads):\n graph = {i: [] for i in range(1, N+1)}\n \n for u, v, d in roads:\n graph[u].a...
trial_gpt4o_1
{ "original_instruction": "Consider a town with N houses and M roads connecting these houses. Each road connecting two houses has a certain distance. The town council wants to minimize the distance a mailman has to travel in order to deliver letters to all houses. The mailman starts at any house and it should be poss...
0.662467
Code_Contests_939
C
[ "find", "union", "kruskal", "minimum_distance_to_travel" ]
4
[ [ "kruskal", "find" ], [ "kruskal", "union" ], [ "minimum_distance_to_travel", "kruskal" ], [ "union", "find" ] ]
4
[]
false
[]
false
pytest
true
[]
true
bf2cbf21d85cd8505848cd93cf97decb72e6c3f5
2a1ab8b7177d21268fc016e6ec64d0500d4e9d59
v1.0
complete
Code_Contests
Code_Contests_2548_C
from typing import List def partition(s: str) -> List[List[str]]: """ Partition a string into substrings such that each substring is a palindrome. >>> partition("aab") [['a', 'a', 'b'], ['aa', 'b']] >>> partition("a") [['a']] >>> partition("ab") [['a', 'b']] >>> partition("aa") [['a...
def is_palindrome(s): return s == s[::-1] def partition(s): def dfs(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]): dfs(end, path + [s[start:end]]) ...
from solution import partition def test_partition_simple_case(): assert partition("aab") == [["a", "a", "b"], ["aa", "b"]] def test_partition_single_character(): assert partition("a") == [["a"]] def test_partition_two_characters(): assert partition("ab") == [["a", "b"]] assert partition("aa") == [["a...
[ { "docstring": null, "function_declaration": "def is_palindrome(s):", "function_name": "is_palindrome", "parameter_list": "(s)" }, { "docstring": null, "function_declaration": "def partition(s):", "function_name": "partition", "parameter_list": "(s)" }, { "docstring": nul...
[ 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_palindrome(s):\n \"\"\"\n Helper function to check if a given string is a palindrome.\n \"\"\"\n return s == s[::-1]\n\ndef partition(s)...
trial_gpt4o_1
{ "original_instruction": "Palindrome Partitioning\n\nProblem Statement\n\nGiven a string s, partition it into substrings such that each substring is a palindrome. Return all possible palindrome partitioning of s.\n\nFor example, given the string \"aab\", you may return:\n\n[\n [\"a\",\"a\",\"b\"],\n [\"aa\",\"b\"]...
0.702732
Code_Contests_2548
C
[ "is_palindrome", "partition" ]
2
[ [ "partition", "is_palindrome" ] ]
1
[]
false
[]
false
pytest
true
[]
true
b638ce855c8ada13b1d14975b6ae21d5ff8d8143
87b4b70e4522f85c7deab77619b5ac1090702242
v1.0
complete
Code_Contests
Code_Contests_2688_C
def can_fulfill_orders(vehicle_capacities, orders): """ Determine if every shipping order can be satisfied by any of the available vehicles. >>> can_fulfill_orders([100, 200, 150], [90, 110, 130, 160]) "YES" >>> can_fulfill_orders([100, 50], [120, 70, 40]) "NO" """ def transportation_company(input_data...
def can_fulfill_orders(vehicle_capacities, orders): max_capacity = max(vehicle_capacities) for order in orders: if order > max_capacity: return "NO" return "YES" def transportation_company(input_data): lines = input_data.strip().split('\n') V = int(lines[0]) vehicle_capaciti...
def test_transportation_company(): input_data1 = """3 100 200 150 4 90 110 130 160""" output1 = "YES" assert transportation_company(input_da...
[ { "docstring": null, "function_declaration": "def can_fulfill_orders(vehicle_capacities, orders):", "function_name": "can_fulfill_orders", "parameter_list": "(vehicle_capacities, orders)" }, { "docstring": null, "function_declaration": "def transportation_company(input_data):", "func...
[ 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_fulfill_orders(vehicle_capacities, shipping_orders):\n max_capacity = max(vehicle_capacities)\n\n for order in shipping_orders:\n if o...
trial_gpt4o_2
{ "original_instruction": "A transportation company is managing a fleet of vehicles. Each vehicle can transfer goods between two points. Each vehicle has a capacity limit, and cannot carry an amount of goods that exceeds this limit. The company needs to determine if it is possible to fulfill a given list of shipping ...
0.57459
Code_Contests_2688
C
[ "can_fulfill_orders", "transportation_company" ]
2
[ [ "transportation_company", "can_fulfill_orders" ] ]
1
[]
false
[]
false
pytest
false
[]
true
4e7b047b2eb44931913e5533dad177fe439df824
045d7863d3d14ad458027763fdd0c08c7b17ea79
v1.0
complete
Code_Contests
Code_Contests_2095_C
def count_dependencies(n: int, k: int, tasks: List[int], conflicts: List[Tuple[int, int]]) -> List[int]: """ For each employee, find the number of other employees whose tasks can be depended upon by the task assigned to the employee. Args: n : int : total number of employees k : int : number o...
from collections import defaultdict def count_dependencies(n, k, tasks, conflicts): # Convert task IDs to employee indexing starting from 0 conflicts_set = set() for x, y in conflicts: conflicts_set.add((x - 1, y - 1)) conflicts_set.add((y - 1, x - 1)) result = [0] * n for...
from solution import count_dependencies def test_example_1(): n = 4 k = 2 tasks = [10, 4, 10, 15] conflicts = [(1, 2), (4, 3)] expected = [0, 0, 1, 2] assert count_dependencies(n, k, tasks, conflicts) == expected def test_example_2(): n = 10 k = 4 tasks = [5, 4, 1, 5, 4, 3, 7, 1, 2...
[ { "docstring": null, "function_declaration": "def count_dependencies(n, k, tasks, conflicts):", "function_name": "count_dependencies", "parameter_list": "(n, k, tasks, conflicts)" }, { "docstring": null, "function_declaration": "def solve(n, k, task_ids, conflict_pairs):", "function_...
[ 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 count_dependent_tasks(n, k, task_ids, conflicts):\n from collections import defaultdict\n\n conflicts_set = set((min(x, y) - 1, max(x, y) - 1) fo...
trial_gpt4o_9
{ "original_instruction": "A company has a task management system where n employees are assigned tasks to complete. Each employee has a particular assigned task denoted by its id t_i.\n\nA task i can depend on another task j if and only if task i is strictly greater than task j (t_i > t_j) and the two tasks are not i...
0.584736
Code_Contests_2095
C
[ "count_dependencies", "solve" ]
2
[ [ "solve", "count_dependencies" ] ]
1
[]
false
[]
false
pytest
true
[]
true
93df7a4e1f9e1309dd8b5581d561a5408ce88579
78ce1ac9a26819e741006ecd214a0914edace146
v1.0
complete
Code_Contests
Code_Contests_2161_C
def largestRectangleArea(grid: List[List[int]]) -> int: """ Given an NxN grid where 0 represents empty cells and 1 represents treasure, find the area of the largest rectangle filled entirely with 1s. >>> largestRectangleArea([ ... [1, 0, 1, 0], ... [1, 0, 1, 1], ... [1, 1, 1, ...
def maximalRectangle(matrix): if not matrix: return 0 n = len(matrix) m = len(matrix[0]) max_area = 0 # create a dp array to store the height of 1's ending at each cell dp = [0] * m for i in range(n): for j in range(m): # update the dp array ...
from solution import largestRectangleArea def test_example_case(): grid = [ [1, 0, 1, 0], [1, 0, 1, 1], [1, 1, 1, 1], [1, 0, 0, 1] ] assert largestRectangleArea(grid) == 4 def test_single_row(): grid = [ [1, 1, 0, 1] ] assert largestRectangleArea(grid) =...
[ { "docstring": null, "function_declaration": "def maximalRectangle(matrix):", "function_name": "maximalRectangle", "parameter_list": "(matrix)" }, { "docstring": null, "function_declaration": "def calculateHistogramArea(heights):", "function_name": "calculateHistogramArea", "para...
[ 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_histogram_area(heights):\n stack = []\n max_area = 0\n index = 0\n\n while index < len(heights):\n if not stack or heights[stack...
trial_gpt4o_1
{ "original_instruction": "A programming competition involves solving a puzzle game that uses an NxN grid. In this game, two types of pieces, represented by 1s (treasure) and 0s (empty), are placed on the grid. The objective is to find the largest rectangular area that contains only 1s (treasure). \n\nWrite a functio...
0.643888
Code_Contests_2161
C
[ "maximalRectangle", "calculateHistogramArea", "largestRectangleArea" ]
3
[ [ "largestRectangleArea", "maximalRectangle" ], [ "maximalRectangle", "calculateHistogramArea" ] ]
2
[]
false
[]
false
pytest
true
[]
true
a10ca4de885c9a787f022f606fd3d666762fc02a
55ed0ba91ff6af1d838562cb038406bdbc4c04b6
v1.0
complete
Code_Contests
Code_Contests_2354_C
def find_min_excluding_indices(test_cases: List[List[int]]) -> List[List[int]]: """ For each test case, find the minimum value in the array after removing each element in turn. >>> find_min_excluding_indices([[3, 1, 4, 2]]) [[1, 2, 1, 1]] >>> find_min_excluding_indices([[2, 7, 3]]) [[3, 2, 2]] >...
def find_min_excluding_indices(test_cases): results = [] for arr in test_cases: n = len(arr) result = [] min_left = [float('inf')] * n min_right = [float('inf')] * n # Build the min_left array min_left[0] = arr[0] for i in range(1, n): ...
def test_find_min_excluding_indices(): # Test case 1 input_data = [[3, 1, 4, 2]] expected_output = [[1, 2, 1, 1]] assert find_min_excluding_indices(input_data) == expected_output # Test case 2 input_data = [[2, 7, 3]] expected_output = [[3, 2, 2]] assert find_min_excluding_indices(input...
[ { "docstring": null, "function_declaration": "def find_min_excluding_indices(test_cases):", "function_name": "find_min_excluding_indices", "parameter_list": "(test_cases)" }, { "docstring": null, "function_declaration": "def process_input_and_output():", "function_name": "process_inp...
[ 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_min_excluding_indices(test_cases):\n results = []\n \n for arr in test_cases:\n n = len(arr)\n result = []\n min_lef...
trial_gpt4o_0
{ "original_instruction": "You are given an array of integers `arr` of length `n`. Your task is to find another array `result` of length `n` such that for each index `i` in the range [0, n-1], `result[i]` is equal to the minimum value in `arr` after the removal of the element at index `i`.\n\nFor example, if `arr = [...
0.572108
Code_Contests_2354
C
[ "find_min_excluding_indices", "process_input_and_output" ]
2
[ [ "process_input_and_output", "find_min_excluding_indices" ] ]
1
[]
false
[]
false
pytest
false
[]
true
40233e84a3b7da43cb2dc76e4c742410675556e4
72fed5141c3927983d3bbe847b90f540010eb9e0
v1.0
complete
Code_Contests
Code_Contests_1596_C
def longest_path(grid): """ Finds the length of the longest path of consecutive distinct characters in a grid. Args: grid (List[List[str]]): A 2D grid of characters. Returns: int: Length of the longest path. Example usage: >>> longest_path(["abc", "def", "ghi"]) 9 >>> longest_path(...
def longest_path(grid): n = len(grid) m = len(grid[0]) def dfs(x, y, visited): max_length = 1 # The starting point itself is countable. visited.add((x, y)) directions = [(-1, 0), (1, 0), (0, -1), (0, 1)] # up, down, left, right for dx, dy in directions: ...
from solution import get_longest_paths, parse_input def test_longest_path_case_1(): input_data = "3\n3 3\nabc\ndef\nghi\n4 4\naabc\ndefg\nhijk\nlmno\n2 2\nab\nba" expected_output = [9, 16, 4] test_cases = parse_input(input_data) assert get_longest_paths(test_cases) == expected_output def test_longest_...
[ { "docstring": null, "function_declaration": "def longest_path(grid):", "function_name": "longest_path", "parameter_list": "(grid)" }, { "docstring": null, "function_declaration": "def get_longest_paths(test_cases):", "function_name": "get_longest_paths", "parameter_list": "(test...
[ 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 longest_distinct_path(grid):\n def dfs(x, y, visited):\n if not (0 <= x < n and 0 <= y < m) or grid[x][y] in visited:\n return len...
trial_gpt4o_6
{ "original_instruction": "You are given a grid of characters with n rows and m columns. Each cell contains a lowercase English letter. Your task is to find the length of the longest path of consecutive distinct characters, where you can move to adjacent cells in the grid (up, down, left, or right).\n\nA path is a se...
0.618893
Code_Contests_1596
C
[ "longest_path", "get_longest_paths", "parse_input" ]
3
[ [ "get_longest_paths", "longest_path" ] ]
1
[ "parse_input" ]
false
[]
false
pytest
true
[]
true
b0a7117ae7feb2793802bba2ba831181139dfab3
d8793933a668e7a6382d0d66aa9f73a9da44707c
v1.0
complete
Code_Contests
Code_Contests_2181_C
import random from typing import List def generate_maze(n: int, m: int) -> List[List[str]]: """ Generates a random maze of dimensions n x m. The maze is represented using '#' for walls and '.' for open spaces. """ pass def solve_maze(maze: List[List[str]]) -> List[List[str]]: """ Finds a p...
import random def generate_maze(n, m): """ Generates a random maze of dimensions n x m. The maze is represented using '#' for walls and '.' for open spaces. """ # Initialize the maze with walls maze = [['#'] * m for _ in range(n)] # DFS to carve out a random path def carve_passages...
from solution import generate_maze, solve_maze def test_generate_maze_dimensions(): for n in range(2, 6): for m in range(2, 6): maze = generate_maze(n, m) assert len(maze) == n assert all(len(row) == m for row in maze) def test_generate_maze_paths(): maze = generate...
[ { "docstring": "Generates a random maze of dimensions n x m.\nThe maze is represented using '#' for walls and '.' for open spaces.", "function_declaration": "def generate_maze(n, m):", "function_name": "generate_maze", "parameter_list": "(n, m)" }, { "docstring": "Finds a path in the maze fr...
[ 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": "import random\n\ndef generate_maze(n, m):\n maze = [['#' for _ in range(m)] for _ in range(n)]\n\n # Create an entrance and exit\n maze[0][0] = '....
trial_gpt4o_3
{ "original_instruction": "Design a maze generator and solver.\n\n**Task**:\n\nWrite a program that generates a random maze and then solves it using the Depth-First Search (DFS) algorithm. The maze will be represented as a grid. Each cell in the grid can either be a wall or open space.\n\n**Input**:\n\nThe input will...
0.566508
Code_Contests_2181
C
[ "generate_maze", "solve_maze", "print_maze", "generate_and_solve_maze" ]
4
[ [ "generate_and_solve_maze", "generate_maze" ], [ "generate_and_solve_maze", "print_maze" ], [ "generate_and_solve_maze", "solve_maze" ] ]
3
[]
false
[]
false
pytest
true
[]
true
33bb7b6a293f060f98716deb917bc03ff8d64e78
058c94cab7fb7fa8546bd5754a321ce11399f938
v1.0
complete
Code_Contests
Code_Contests_2069_C
from typing import List def compare(x: str, y: str) -> int: """Comparator function for determining order for concatenation.""" return (int(y + x) - int(x + y)) def largest_number(numbers: List[str]) -> str: """ Returns the largest number that can be formed by concatenating the input integers. >>> ...
from functools import cmp_to_key def compare(x, y): return (int(y + x) - int(x + y)) def largest_number(numbers): """ Returns the largest number that can be formed by concatenating the input integers. """ # Convert numbers to string to prepare for concatenation comparisons numbers_str = list(m...
import pytest from solution import largest_number, process_test_cases def test_largest_number(): assert largest_number(['50', '2', '1', '9']) == '95021' assert largest_number(['5', '56', '50']) == '56550' assert largest_number(['1', '34', '3', '98', '9', '76', '45', '4']) == '998764543431' assert large...
[ { "docstring": null, "function_declaration": "def compare(x, y):", "function_name": "compare", "parameter_list": "(x, y)" }, { "docstring": "Returns the largest number that can be formed by concatenating the input integers.", "function_declaration": "def largest_number(numbers):", "f...
[ 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": "from functools import cmp_to_key\n\ndef compare(x, y):\n return (int(y + x) - int(x + y))\n\ndef largest_number(numbers):\n \"\"\"\n Returns the l...
trial_gpt4o_0
{ "original_instruction": "Write a function that takes an input of space-separated integers and returns the largest number that can be formed by concatenating those integers together.\n\nInput:\n\nThe first line contains the number of test cases T. \nThe next T lines each contain space-separated integers.\n\nOutput:\...
0.666791
Code_Contests_2069
C
[ "compare", "largest_number", "process_test_cases" ]
3
[ [ "largest_number", "compare" ], [ "process_test_cases", "largest_number" ] ]
2
[ "process_test_cases" ]
false
[]
false
pytest
true
[]
true
5f232d172c76f8953fc1e3b24ed69594e8359333
2f1000ffb7700006e720743ae609ff74d88aff73
v1.0
complete
Code_Contests
Code_Contests_2569_C
from typing import List, Tuple def find_shortest_path(M: int, N: int, Ex: int, Ey: int, Dx: int, Dy: int, K: int, blocked: List[Tuple[int, int]]) -> int: """ Determine the shortest path from the entrance to the exit in the warehouse grid, avoiding blocked sections. :param M: int - number of rows in the wa...
from collections import deque def shortest_path(warehouse, entrance, exit, blocked_sections): M, N = warehouse (Ex, Ey) = entrance (Dx, Dy) = exit # Initialize grid and mark blocked sections grid = [[0] * N for _ in range(M)] for bx, by in blocked_sections: grid[bx][by] = -1 # Mov...
def test_shortest_path(): # Example test case assert find_shortest_path(5, 7, 0, 0, 4, 6, 3, [(1, 2), (2, 3), (3, 4)]) == 10, "Test case 1 failed" # Test case with no blocked sections assert find_shortest_path(5, 7, 0, 0, 4, 6, 0, []) == 10, "Test case 2 failed" # Test case with entrance =...
[ { "docstring": null, "function_declaration": "def shortest_path(warehouse, entrance, exit, blocked_sections):", "function_name": "shortest_path", "parameter_list": "(warehouse, entrance, exit, blocked_sections)" }, { "docstring": null, "function_declaration": "def find_shortest_path(M, N...
[ 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_size, entrance, exit, blocked_cells):\n M, N = grid_size\n Ex, Ey = entrance\n Dx, Dy = ex...
trial_gpt4o_2
{ "original_instruction": "Our company's warehouse system consists of a grid of cells, with each cell representing a section that can store items. Some sections are blocked and cannot hold any items nor can they be part of a path. The objective is to move items from the entrance of the warehouse to the exit by findin...
0.636653
Code_Contests_2569
C
[ "shortest_path", "find_shortest_path" ]
2
[ [ "find_shortest_path", "shortest_path" ] ]
1
[]
false
[]
false
pytest
false
[]
true
e4a2286ff95ce9b35ef7163e0e50547e8299c2ac
f6bca2201c75609685a185c904929f5bc5b1de6d
v1.0
complete
Code_Contests
Code_Contests_2288_C
def swap_in_a_row(M, N): """ Determine the number of valid ways the people can reorder themselves to their starting positions, modulo 1000000007. Args: M (int): The total number of distinct items placed in a row. N (int): The number of people. Returns: int: The count of valid ways ...
def factorial_mod(n, mod=1000000007): res = 1 for i in range(2, n + 1): res = (res * i) % mod return res def swap_in_a_row(M, N): return factorial_mod(N)
from solution import swap_in_a_row def test_example_1(): assert swap_in_a_row(3, 2) == 2 def test_example_2(): assert swap_in_a_row(5, 3) == 6 def test_example_3(): assert swap_in_a_row(4, 4) == 24 def test_single_person(): assert swap_in_a_row(1, 1) == 1 def test_all_people_to_max(): assert sw...
[ { "docstring": null, "function_declaration": "def factorial_mod(n, mod=1000000007):", "function_name": "factorial_mod", "parameter_list": "(n, mod=1000000007)" }, { "docstring": null, "function_declaration": "def swap_in_a_row(M, N):", "function_name": "swap_in_a_row", "parameter...
[ 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 factorial_mod(n, mod=1000000007):\n res = 1\n for i in range(2, n + 1):\n res = (res * i) % mod\n return res\n\ndef swap_in_a_row(M, N)...
trial_gpt4o_0
{ "original_instruction": "M distinct items are placed in a row, and N people are playing a game called \"Swap-in-a-row\".\n\nInitially, each person starts at a unique position in the line where there is an item designated for them and no two people start at the same position. During the game, they are allowed to swa...
0.588579
Code_Contests_2288
C
[ "factorial_mod", "swap_in_a_row" ]
2
[ [ "swap_in_a_row", "factorial_mod" ] ]
1
[]
false
[]
false
pytest
true
[]
true
b4df5ec09f215b48e57cf5d5341a5fdd1fd15227
090f6e38998c0c5c366b496d24c0a00015647b1f
v1.0
complete
Code_Contests
Code_Contests_2977_C
def find_project_order(N: int, dependencies: List[List[int]]) -> str: """ Produce a valid order for projects such that each project appears after all of its dependencies. If no such order is possible due to a circular dependency, return "IMPOSSIBLE". >>> find_project_order(5, [[], [1], [2], [1, 2], []]) in ...
def find_project_order(N, dependencies): from collections import defaultdict, deque # Build graph and in-degree counter graph = defaultdict(list) in_degree = [0] * (N + 1) for project in range(1, N + 1): deps = dependencies[project - 1] for dep in deps: graph[de...
from solution import solution def test_example_1(): input_str = "5\n0\n1 1\n1 2\n2 1 2\n0\n" output_str = solution(input_str) assert output_str in {"1 2 3 4 5", "1 2 4 3 5", "1 5 2 3 4", "1 5 2 4 3"} # Valid orders def test_example_2(): input_str = "4\n1 2\n1 3\n1 4\n1 2\n" output_str = solution(...
[ { "docstring": null, "function_declaration": "def find_project_order(N, dependencies):", "function_name": "find_project_order", "parameter_list": "(N, dependencies)" }, { "docstring": null, "function_declaration": "def parse_input(input_str):", "function_name": "parse_input", "pa...
[ 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_project_order(N, dependencies):\n from collections import defaultdict, deque\n \n # Build graph and in-degree counter\n graph = defaul...
trial_gpt4o_0
{ "original_instruction": "A company wants to build a system to manage project dependencies. Each project depends on one or more other projects, and to start a project, all its dependencies must be completed first. Every project has a unique identifier, which is an integer from 1 to N.\n\nYou are tasked to write a pr...
0.462148
Code_Contests_2977
C
[ "find_project_order", "parse_input", "solution" ]
3
[ [ "solution", "find_project_order" ], [ "solution", "parse_input" ] ]
2
[ "parse_input" ]
false
[]
false
pytest
true
[]
true
bd10cf7710af15b5738e68d1e3f3b58f72c6321a
4073ca3f6151b3826b145bcd1729b59c9a1a31f0
v1.0
complete
Code_Contests
Code_Contests_2596_C
def swap(S: str, i: int, j: int) -> str: """ Swap characters at indices i and j in the string S. >>> swap("abc", 0, 2) "cba" """ pass def rotate_left(S: str, k: int) -> str: """ Rotate the string S to the left by k positions. >>> rotate_left("abcdef", 2) "cdefab" """ pass def m...
def swap(S, i, j): S = list(S) S[i], S[j] = S[j], S[i] return "".join(S) def rotate_left(S, k): return S[k:] + S[:k] def min_operations_to_transform(S1, S2): if len(S1) != len(S2): return -1 from collections import Counter if Counter(S1) != Counter(S2): return -1 def ...
from solution import min_operations_to_transform def test_min_operations_to_transform_case1(): assert min_operations_to_transform("abcd", "acbd") == 1 def test_min_operations_to_transform_case2(): assert min_operations_to_transform("abcd", "abcd") == 0 def test_min_operations_to_transform_case3(): assert...
[ { "docstring": null, "function_declaration": "def swap(S, i, j):", "function_name": "swap", "parameter_list": "(S, i, j)" }, { "docstring": null, "function_declaration": "def rotate_left(S, k):", "function_name": "rotate_left", "parameter_list": "(S, k)" }, { "docstring":...
[ 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 minimal_operations(S1, S2):\n if len(S1) != len(S2):\n return -1\n \n from collections import Counter\n \n if Counter(S1) != Coun...
trial_gpt4o_2
{ "original_instruction": "You are given two strings S1 and S2. Define the following operations:\n\na. concatenate(S1, S2) denotes the string obtained by concatenating S2 to the end of S1. E.g., concatenate(\"abc\", \"def\") = \"abcdef\"\n\nb. swap(S, i, j) denotes the string obtained by swapping the characters at in...
0.650393
Code_Contests_2596
C
[ "swap", "rotate_left", "min_operations_to_transform" ]
3
[ [ "min_operations_to_transform", "swap" ] ]
1
[]
false
[]
false
pytest
true
[]
true
10c83b421a929694e6dd24667c1785ed85614401
45c0273bbbe5789207a04e1beb22f6b187a6df83
v1.0
complete
Code_Contests
Code_Contests_1900_C
import heapq def shortest_paths_from_capital(N: int, M: int, roads: List[Tuple[int, int, int]]) -> List[int]: """ Calculate the minimum distance required to travel from the capital city (city 1) to all other cities. If a city is not reachable from the capital, the distance should be represented by -1. ...
import heapq def shortest_paths_from_capital(N, M, roads): graph = {i: [] for i in range(1, N+1)} for road in roads: u, v, w = road graph[u].append((w, v)) graph[v].append((w, u)) distances = {i: float('inf') for i in range(1, N+1)} distances[1] = 0 priority_queue ...
import pytest from solution import shortest_paths_from_capital, minimum_distances_from_input def test_shortest_paths_from_capital_basic(): assert shortest_paths_from_capital(5, 6, [(1, 2, 2), (1, 3, 4), (2, 3, 1), (3, 4, 2), (3, 5, 3), (4, 5, 2)]) == [2, 3, 5, 6] def...
[ { "docstring": null, "function_declaration": "def shortest_paths_from_capital(N, M, roads):", "function_name": "shortest_paths_from_capital", "parameter_list": "(N, M, roads)" }, { "docstring": null, "function_declaration": "def minimum_distances_from_input(input_string):", "function...
[ 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\nimport sys\n\ndef dijkstra(N, M, roads):\n graph = {i: [] for i in range(1, N+1)}\n for u, v, w in roads:\n graph[u].append((w, ...
trial_gpt4o_2
{ "original_instruction": "In an ancient kingdom, there are N cities connected by M bidirectional roads. Each road has a certain length associated with it. The King wants to know the minimum distance required to travel from the capital city (city 1) to all other cities. If a city is not reachable from the capital, th...
0.756733
Code_Contests_1900
C
[ "shortest_paths_from_capital", "minimum_distances_from_input" ]
2
[ [ "minimum_distances_from_input", "shortest_paths_from_capital" ] ]
1
[]
false
[]
false
pytest
true
[]
true
0b408e0982da8e35635ddc496f5d1301833ce2f2
b5b29b33d7434ed04de770ec5cc70d03d95c4eae
v1.0
complete
Code_Contests
Code_Contests_1703_C
class TreeNode: def __init__(self, val=0, left=None, right=None): self.val = val self.left = left self.right = right def build_tree(node_list): """ Build a binary tree from a list of tuples where each tuple contains the value of a node and the values of its left and right children. ...
class TreeNode: def __init__(self, val=0, left=None, right=None): self.val = val self.left = left self.right = right def build_tree(node_list): if not node_list: return None nodes = {} for value, left, right in node_list: if value not in nodes: n...
from solution import build_tree, sum_of_left_leaves, left_leaves_sum_multiple_cases def test_build_tree(): node_list = [(3, 9, 20), (9, -1, -1), (20, 15, 7), (15, -1, -1), (7, -1, -1)] root = build_tree(node_list) assert root.val == 3 assert root.left.val == 9 assert root.right.val == 20 assert...
[]
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "class TreeNode:\n def __init__(self, val=0, left=None, right=None):\n self.val = val\n self.left = left\n self.right = right\n\ndef...
trial_gpt4o_0
{ "original_instruction": "Given a binary tree, you need to compute the sum of the values of all left leaves in the tree. A leaf is a node with no children. A left leaf is a leaf that is the left child of its parent node.\n\nInput\n\nThe input consists of multiple test cases. The first line contains an integer `t` (1...
0.609875
Code_Contests_1703
C
[ "build_tree", "sum_of_left_leaves", "left_leaves_sum_multiple_cases" ]
3
[ [ "left_leaves_sum_multiple_cases", "build_tree" ], [ "left_leaves_sum_multiple_cases", "sum_of_left_leaves" ] ]
2
[]
false
[ "TreeNode" ]
true
pytest
true
[]
true
3aef2db97c49abb2582248f47f744ddf8802df89
413d953e693fc3d94ab6b12948699ec744c46a91
v1.0
complete
Code_Contests
Code_Contests_2412_C
class TreeNode: def __init__(self, val=0, left=None, right=None): self.val = val self.left = left self.right = right def build_tree(values): """ Build a binary tree from a list of values. """ if not values: return None nodes = [TreeNode(val) if val is not None else ...
class TreeNode: def __init__(self, val=0, left=None, right=None): self.val = val self.left = left self.right = right def build_tree(values): if not values: return None nodes = [TreeNode(val) if val is not None else None for val in values] kids = nodes[::-1] root...
from solution import find_max_path_sums def test_example_1(): assert find_max_path_sums([[1, 2, 3]]) == [6] def test_example_2(): assert find_max_path_sums([[-10, 9, 20, None, None, 15, 7]]) == [42] def test_example_3(): assert find_max_path_sums([[5, 4, 8, 11, None, 13, 4, 7, 2, None, None, None, 1]]) =...
[]
[ 0, 0, 0, 0, 0, 0, 1, 0, 1 ]
2
hard
0.222
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "import sys\n\nclass TreeNode:\n def __init__(self, key):\n self.left = None\n self.right = None\n self.val = key\n\ndef insertLevel...
trial_gpt4o_9
{ "original_instruction": "Given a binary tree, implement a function to determine the maximum sum of values for any path within the tree, where the path may start and end at any nodes in the tree.\n\nThe binary tree is represented as a list where index `0` is the root, and for any node at index `i`, the left child is...
0.583935
Code_Contests_2412
C
[ "build_tree", "max_path_sum", "find_max_path_sums" ]
3
[ [ "find_max_path_sums", "build_tree" ], [ "find_max_path_sums", "max_path_sum" ] ]
2
[]
false
[ "TreeNode" ]
true
pytest
true
[]
true
ae50ea9ab197ae084902813c574ec3ec5cdf031b
8dfb45f88dde732e1181c26dabcfd546a23efc78
v1.0
complete
Code_Contests
Code_Contests_2469_C
def max_observation_cells(grid, k): """ Given a grid with 'O' and 'X', and the size of the square observation platform k, returns the maximum number of 'O' cells that can be covered by the platform. >>> grid = [ ... "OOOOX", ... "OOOOX", ... "XXOOX", ... "XOXXO" ... ]...
def max_observation_cells(grid, k): """ Given a grid with 'O' and 'X', and size of the square observation platform k, returns the maximum number of 'O' cells that can be covered by the platform. """ N = len(grid) M = len(grid[0]) max_count = 0 for i in range(N - k + 1): for j i...
from solution import max_observation_cells def test_example_case(): grid = [ "OOOOX", "OOOOX", "XXOOX", "XOXXO" ] k = 2 assert max_observation_cells(grid, k) == 4 def test_full_open_grid(): grid = [ "OOOOO", "OOOOO", "OOOOO", "OOOOO" ...
[ { "docstring": "Given a grid with 'O' and 'X', and size of the square observation platform k,\nreturns the maximum number of 'O' cells that can be covered by the platform.", "function_declaration": "def max_observation_cells(grid, k):", "function_name": "max_observation_cells", "parameter_list": "(g...
[ 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 max_observation_cells(grid, k):\n \"\"\"\n Given a grid with 'O' and 'X', and size of the square observation platform k,\n returns the maximum...
trial_gpt4o_0
{ "original_instruction": "A scientist is conducting an experiment in a rectangular lab grid of size N x M. The scientist wants to place a square observation platform of size k x k in the lab such that the platform covers as many 'O' cells as possible, where 'O' represents an open cell suitable for observation. The c...
0.600726
Code_Contests_2469
C
[ "max_observation_cells", "read_and_solve" ]
2
[ [ "read_and_solve", "max_observation_cells" ] ]
1
[]
false
[]
false
pytest
true
[]
true
ea2d4185b5e2e6a15782160bce666a75afe9f22e
ef86ed02a33390926d0fd73737ca8d4a5b931cc7
v1.0
complete
Code_Contests
Code_Contests_2991_C
def peak_heights(n: int, m: int, grid: List[List[int]]) -> List[int]: """ Identify all peak cells in the grid and output their heights in non-increasing order. An off-grid cell is treated as having a height of negative infinity. >>> peak_heights(3, 3, [[3, 4, 5], [2, 6, 1], [1, 2, 3]]) [6, 5, ...
def find_peaks(grid): def is_peak(i, j): current = grid[i][j] for di, dj in [(-1, 0), (1, 0), (0, -1), (0, 1)]: ni, nj = i + di, j + dj if 0 <= ni < len(grid) and 0 <= nj < len(grid[0]): if current <= grid[ni][nj]: return False retu...
import pytest from solution import peak_heights def test_peak_heights_example_case(): grid = [ [3, 4, 5], [2, 6, 1], [1, 2, 3] ] assert peak_heights(3, 3, grid) == [6, 5, 3] def test_peak_heights_single_element(): grid = [ [7] ] assert peak_heights(1, 1, grid) =...
[ { "docstring": null, "function_declaration": "def find_peaks(grid):", "function_name": "find_peaks", "parameter_list": "(grid)" }, { "docstring": null, "function_declaration": "def peak_heights(n, m, grid):", "function_name": "peak_heights", "parameter_list": "(n, m, grid)" }, ...
[ 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": "def find_peak_cells(grid, n, m):\n def is_peak(x, y):\n current_height = grid[x][y]\n adjacents = [\n (-1, 0), (1, 0), # Up an...
trial_gpt4o_9
{ "original_instruction": "You are given a grid of size n × m. The grid contains integers, each integer representing the height of a cell in the grid. A cell is called a peak if it is strictly greater than all of its adjacent cells. The off-grid cells are treated as having a height of negative infinity (i.e., any cel...
0.644959
Code_Contests_2991
C
[ "find_peaks", "peak_heights" ]
2
[ [ "peak_heights", "find_peaks" ] ]
1
[]
false
[]
false
pytest
true
[]
true
8f1fd032c006501bb2a134d06f1077b08417c681
7e836d4be1472177e26a5208392d989560482ac5
v1.0
complete
Code_Contests
Code_Contests_2743_C
def minimum_spanning_tree(n: int, m: int, edge_list: str) -> int: """ Given an undirected weighted graph with n nodes and m edges, determine the weight of the minimum spanning tree of the graph. If the graph is disconnected, return -1. Parameters: n (int): Number of nodes in the graph. m (...
def find(parent, i): if parent[i] == i: return i else: parent[i] = find(parent, parent[i]) return parent[i] def union(parent, rank, x, y): root_x = find(parent, x) root_y = find(parent, y) if root_x != root_y: if rank[root_x] > rank[root_y]: parent[r...
def test_example_1(): n = 4 m = 5 edge_list = '1 2 3\n1 3 1\n2 3 3\n3 4 6\n2 4 5' assert minimum_spanning_tree(n, m, edge_list) == 9 def test_example_2(): n = 3 m = 1 edge_list = '1 2 4' assert minimum_spanning_tree(n, m, edge_list) == -1 def test_single_node(): n = 1 m = 0 ...
[ { "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, 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 DSU:\n def __init__(self, n):\n self.parent = list(range(n))\n self.rank = [0] * n\n\n def find(self, a):\n if self.parent...
trial_gpt4o_2
{ "original_instruction": "Given an undirected weighted graph with `n` nodes and `m` edges, your task is to determine the weight of the minimum spanning tree of the graph.\n\nInput\n\nThe first line contains two integers `n` (1 ≤ n ≤ 10^5) and `m` (1 ≤ m ≤ 2 * 10^5), representing the number of nodes and the number of...
0.794914
Code_Contests_2743
C
[ "find", "union", "kruskal", "minimum_spanning_tree" ]
4
[ [ "kruskal", "find" ], [ "kruskal", "union" ], [ "minimum_spanning_tree", "kruskal" ], [ "union", "find" ] ]
4
[]
false
[]
false
pytest
false
[]
true
baff9366eebb35a01449673edeb0576268ae696c
d731e4ecffbd9b8e09406289a9db2fe5b06cd722
v1.0
complete
Code_Contests
Code_Contests_2048_C
def solve_treasure_hunt(n: int, ranges: List[Tuple[int, int]]) -> List[int]: """ Find the appropriate answers for the treasure hunt clues. >>> solve_treasure_hunt(3, [(5, 10), (7, 15), (6, 12)]) [5, 7, 6] >>> solve_treasure_hunt(4, [(1, 5), (2, 6), (3, 7), (4, 8)]) [1, 2, 3, 4] """ pass # E...
def find_answers(n, ranges): previous_answers = set() answers = [] for l, r in ranges: for number in range(l, r + 1): if number not in previous_answers: previous_answers.add(number) answers.append(number) break return answers # Helpe...
from solution import solve_treasure_hunt def test_example_1(): n = 3 ranges = [ (5, 10), (7, 15), (6, 12) ] result = solve_treasure_hunt(n, ranges) assert result == [5, 7, 6] def test_example_2(): n = 4 ranges = [ (1, 5), (2, 6), (3, 7), ...
[ { "docstring": null, "function_declaration": "def find_answers(n, ranges):", "function_name": "find_answers", "parameter_list": "(n, ranges)" }, { "docstring": null, "function_declaration": "def solve_treasure_hunt(n, ranges):", "function_name": "solve_treasure_hunt", "parameter_...
[ 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_answers(n, ranges):\n previous_answers = set()\n answers = []\n\n for l, r in ranges:\n for number in range(l, r + 1):\n ...
trial_gpt4o_0
{ "original_instruction": "You are organizing a treasure hunt competition at the annual festival. Participants will receive a series of clues which they must solve sequentially. Each clue contains a target number and a range of possible numbers. To get the answer to a clue, participants must find the smallest number ...
0.535043
Code_Contests_2048
C
[ "find_answers", "solve_treasure_hunt" ]
2
[ [ "solve_treasure_hunt", "find_answers" ] ]
1
[]
false
[]
false
pytest
true
[]
true
24d1a82ad7655b254e90aed6e8fb4422bd6c60dc
25473226974dd560ebf1c093b159c3e8e9882751
v1.0
complete
Code_Contests
Code_Contests_3351_C
def derangement_count(s: str) -> int: """ Given a string `s`, compute the number of derangements. A derangement of a string is a permutation where no character appears in its original position. Examples: >>> derangement_count("A") 0 >>> derangement_count("AB") 1 >>> derange...
from math import factorial def count_derangements(n): """ Calculate the number of derangements for a sequence of length n using the formula: !n = (n-1) * (!(n-1) + !(n-2)) """ if n == 0: return 1 elif n == 1: return 0 elif n == 2: return 1 derangements = [0]...
from solution import derangement_count def test_derangement_count_single_letter(): assert derangement_count("A") == 0 def test_derangement_count_two_letters(): assert derangement_count("AB") == 1 def test_derangement_count_five_letters(): assert derangement_count("ABCDE") == 44 def test_derangement_coun...
[ { "docstring": "Calculate the number of derangements for a sequence of length n using the formula:\n!n = (n-1) * (!(n-1) + !(n-2))", "function_declaration": "def count_derangements(n):", "function_name": "count_derangements", "parameter_list": "(n)" }, { "docstring": "Given a string `s`, com...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "from math import factorial\n\ndef derangement(n):\n if n == 0:\n return 1\n if n == 1:\n return 0\n d = [0] * (n + 1)\n d[0] = 1\...
trial_gpt4o_1
{ "original_instruction": "String Permutation Puzzle\n\nAlice loves solving puzzles with strings. Today, she has come across a new type of puzzle which involves permuting substrings. Given a string S, she wants to figure out in how many different ways she can rearrange its characters so that no character ends up in i...
0.653345
Code_Contests_3351
C
[ "count_derangements", "derangement_count" ]
2
[ [ "derangement_count", "count_derangements" ] ]
1
[]
false
[]
false
pytest
true
[]
true
47d3f127bbf57e0121e5e7fe3962b3b5e2e533d1
98609a5d45a91c68bb5f598af2574450c6362fd2
v1.0
complete
Code_Contests
Code_Contests_2594_C
def is_subsequence(s: str, num: str) -> bool: it = iter(s) return all(char in it for char in num) def smallest_missing_integer(input_str: str) -> str: """ Find the smallest positive integer that is not a subsequence of the given input string. :param input_str: The input string consisting of digits...
def is_subsequence(s, num): it = iter(s) return all(char in it for char in num) def smallest_missing_integer(input_str): i = 1 while True: if not is_subsequence(input_str, str(i)): return str(i) i += 1 def process_test_cases(test_cases): return [smallest_missing_integer...
from solution import find_smallest_missing_positive_integer def test_single_case_all_digits(): assert find_smallest_missing_positive_integer(1, ["0123456789"]) == ["10"] def test_single_case_repeated_digits(): assert find_smallest_missing_positive_integer(1, ["111"]) == ["2"] def test_single_case_mixed_digit...
[ { "docstring": null, "function_declaration": "def is_subsequence(s, num):", "function_name": "is_subsequence", "parameter_list": "(s, num)" }, { "docstring": null, "function_declaration": "def smallest_missing_integer(input_str):", "function_name": "smallest_missing_integer", "pa...
[ 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 smallest_missing_subsequence(T, test_cases):\n def is_subsequence(s, subseq):\n it = iter(s)\n return all(char in it for char in subse...
trial_gpt4o_2
{ "original_instruction": "Write a function to find the smallest positive integer that is not a subsequence of a given input string. For instance, for the string \"0123456789\" the output should be \"10\" because all numbers from 0 to 9 are present and \"10\" is the smallest number that is not a subsequence of it. \n...
0.620768
Code_Contests_2594
C
[ "is_subsequence", "smallest_missing_integer", "process_test_cases", "find_smallest_missing_positive_integer" ]
4
[ [ "find_smallest_missing_positive_integer", "process_test_cases" ], [ "process_test_cases", "smallest_missing_integer" ], [ "smallest_missing_integer", "is_subsequence" ] ]
3
[ "process_test_cases" ]
false
[]
false
pytest
true
[]
true
49bfe70600ef76a8dfac2d8da9e84752fdf9ad3f
447d90675246a2283189391eca919dde6d510a6a
v1.0
complete
Code_Contests
Code_Contests_2927_C
from typing import List, Tuple def process_in_game_mechanics(input_str: str) -> str: """ Process player commands and evaluate expressions involving in-game variables according to operator precedence and associativity rules. Args: input_str (str): Input string containing operator definitions an...
import re def evaluate_expression(expression, variables, operators): def apply_operator(op, left, right): try: if op == '+': return left + right elif op == '-': return left - right elif op == '*': return left * right ...
from solution import process_in_game_mechanics def test_dataset1_all_error(): input_data = """1 5 + L 1 - L 1 * L 2 / L 2 ^ R 3 4 a+b*c d-e^f g+h-i*j/k m^n^o""" expected_output = "ERROR\nERROR\nERROR\nERROR" assert process_in_game_mechanics(input_data) == expected_output def test_dataset2_all_error(): ...
[ { "docstring": null, "function_declaration": "def evaluate_expression(expression, variables, operators):", "function_name": "evaluate_expression", "parameter_list": "(expression, variables, operators)" }, { "docstring": null, "function_declaration": "def evaluate_dataset(O, operators, E,...
[ 0, 0, 0, 0, 1 ]
1
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "import operator\nimport re\n\ndef calculate_expression(operators, expressions):\n results = []\n for expr in expressions:\n try:\n ...
trial_gpt4o_4
{ "original_instruction": "Your friend is developing a text-based adventure game, and he needs your help to handle certain in-game mechanics. One important feature he needs is a way to process player commands and evaluate expressions involving in-game variables which represent different attributes such as health (`h`...
0.569861
Code_Contests_2927
C
[ "evaluate_expression", "evaluate_dataset", "parse_input", "process_in_game_mechanics" ]
4
[ [ "evaluate_dataset", "evaluate_expression" ], [ "process_in_game_mechanics", "evaluate_dataset" ], [ "process_in_game_mechanics", "parse_input" ] ]
3
[ "parse_input" ]
false
[]
false
pytest
true
[]
true
48bfb8df3e13486a9746f8120fa420252f9d7041
2f73ed07312e2bc465d9310304d7e035a39fc55f
v1.0
complete
Code_Contests
Code_Contests_2773_C
def process_operations(Q: int, operations: List[str]) -> List[int]: """ Process a series of Q operations on an initially zero-filled 2D grid. Each operation can either update a grid cell or calculate the sum of a sub-matrix. Parameters: Q (int): The number of operations to process. operati...
def update_grid(grid, x, y, v): """ Update the grid at position (x, y) by adding value v. """ grid[x-1][y-1] += v def sum_rectangle(grid, x1, y1, x2, y2): """ Calculate the sum of the rectangle defined by (x1, y1) as top-left and (x2, y2) as bottom-right. """ sum_val = 0 for i in ra...
def test_update_and_sum(): Q = 5 operations = ["1 1 2 5", "1 3 4 -3", "2 1 1 3 4", "1 2 2 2", "2 2 2 3 4"] assert process_operations(Q, operations) == [2, -1] def test_single_update(): Q = 1 operations = ["1 1 1 100"] result = process_operations(Q, operations) assert result == [] def test_...
[ { "docstring": "Update the grid at position (x, y) by adding value v.", "function_declaration": "def update_grid(grid, x, y, v):", "function_name": "update_grid", "parameter_list": "(grid, x, y, v)" }, { "docstring": "Calculate the sum of the rectangle defined by (x1, y1) as top-left and (x2...
[ 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 process_operations(n, m, operations):\n grid = [[0] * m for _ in range(n)]\n results = []\n \n def update(x, y, v):\n grid[x-1][y-1]...
trial_gpt4o_2
{ "original_instruction": "You are provided with a 2D grid of dimension `n * m` where `1 <= n, m <= 1000`. The grid is initially filled with zeros. You need to perform a series of `Q` operations of the following two types:\n\n- `1 x y v`: Update the cell at position `(x, y)` (1-indexed) by adding the value `v` (`1 <=...
0.562944
Code_Contests_2773
C
[ "update_grid", "sum_rectangle", "process_operations" ]
3
[ [ "process_operations", "sum_rectangle" ], [ "process_operations", "update_grid" ] ]
2
[]
false
[]
false
pytest
false
[]
true
742ba03446e1c2bb64f304290ef2515142df4af9
85758dbad3b06246465e05d52368f334876e035b
v1.0
complete
Code_Contests
Code_Contests_3208_C
def solve_game(n: int, m: int, grid: List[str]) -> int: """ Determine the minimum number of moves required for Lina to reach the goal cell from the start cell. If it is impossible, return -1. >>> solve_game(5, 5, ["S...#", ".#..#", "..#.#", "#...#", "#..G."]) 7 >>> solve_game(3, 4, ["S..#", "##...
from collections import deque def min_moves(grid, n, m): # Find start and goal positions start = None goal = None for i in range(n): for j in range(m): if grid[i][j] == 'S': start = (i, j) elif grid[i][j] == 'G': goal = (i, j) if...
from solution import solve_game def test_example_1(): n = 5 m = 5 lines = [ "S...#", ".#..#", "..#.#", "#...#", "#..G." ] assert solve_game(n, m, lines) == 7 def test_example_2(): n = 3 m = 4 lines = [ "S..#", "###.", "......
[ { "docstring": null, "function_declaration": "def min_moves(grid, n, m):", "function_name": "min_moves", "parameter_list": "(grid, n, m)" }, { "docstring": null, "function_declaration": "def solve_game(n, m, lines):", "function_name": "solve_game", "parameter_list": "(n, m, lines...
[ 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 min_moves_to_reach_goal(n, m, grid):\n def is_valid(x, y):\n return 0 <= x < n and 0 <= y < m and grid[x][y]...
trial_gpt4o_1
{ "original_instruction": "Lina is playing a board game on a rectangular grid constituted of cells. Each cell is either passable or blocked. Lina can move from one cell to an adjacent cell if both cells are passable. Two cells are adjacent if they share a side.\n\nLina wants to reach a specific goal cell starting fro...
0.743256
Code_Contests_3208
C
[ "min_moves", "solve_game" ]
2
[ [ "solve_game", "min_moves" ] ]
1
[]
false
[]
false
pytest
true
[]
true
6cfeedcbbe9485adbbc0391580015149a003ce09
c7539f784b81059fb634bc52171d69bf5297283d
v1.0
complete
Code_Contests
Code_Contests_2592_C
from collections import defaultdict from typing import List, Tuple def min_edges_to_connect_graph(N: int, M: int, edges: List[Tuple[int, int, int]]) -> int: """ Calculate the number of ways to add the minimum number of edges to make the graph connected. Parameters: N (int): Number of vertices M (i...
from collections import defaultdict def find_connected_components(adj_list, N): visited = [False] * N components = 0 def dfs(node): stack = [node] while stack: v = stack.pop() for neighbor in adj_list[v]: if not visited[neighbor]: ...
from solution import min_edges_to_connect_graph def test_min_edges_to_connect_graph(): assert min_edges_to_connect_graph(4, 2, [(1, 2, 1), (3, 4, 1)]) == 1 assert min_edges_to_connect_graph(3, 0, []) == 2 assert min_edges_to_connect_graph(6, 2, [(1, 2, 1), (3, 4, 1)]) == 3 assert min_edges_to_connect_g...
[ { "docstring": null, "function_declaration": "def find_connected_components(adj_list, N):", "function_name": "find_connected_components", "parameter_list": "(adj_list, N)" }, { "docstring": null, "function_declaration": "def min_edges_to_connect_graph(N, M, edges):", "function_name":...
[ 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": "from collections import defaultdict\n\ndef find_connected_components(adj_list, N):\n visited = [False] * N\n components = 0\n \n def dfs(node):...
trial_gpt4o_0
{ "original_instruction": "You are given a weighted undirected graph with N vertices and M edges. Each edge has a weight W, and you need to find the number of ways to add a minimum number of edges to make the graph connected. In other words, you need to find how many different sets of edges can be added to make a con...
0.665593
Code_Contests_2592
C
[ "find_connected_components", "min_edges_to_connect_graph", "main" ]
3
[ [ "min_edges_to_connect_graph", "find_connected_components" ] ]
1
[]
false
[]
false
pytest
true
[]
true
5e708fe37905118fc166c8b888642f8ea5a0a191
4f744b39c6856c0ef737153a45434f0e3d875dd4
v1.0
complete
Code_Contests
Code_Contests_3235_C
from typing import List def max_product_subarray(arr: List[int]) -> int: """ Returns the maximum product of any contiguous subarray within `arr`. >>> max_product_subarray([2, 3, -2, 4]) 6 >>> max_product_subarray([-1, -3, -10]) 30 >>> max_product_subarray([0, 2, -3, -4, 0]) 24 """ def solve(te...
def max_product_subarray(arr): """ Returns the maximum product of any contiguous subarray within `arr`. """ if not arr: return 0 max_product = min_product = result = arr[0] for num in arr[1:]: if num < 0: max_product, min_product = min_product, max_product ...
from solution import max_product_subarray, solve, parse_input def test_max_product_subarray(): assert max_product_subarray([2, 3, -2, 4]) == 6 assert max_product_subarray([-1, -3, -10]) == 30 assert max_product_subarray([0, 2, -3, -4, 0]) == 24 assert max_product_subarray([1, -2, -3, 0, 7, -8, -2]) == ...
[ { "docstring": "Returns the maximum product of any contiguous subarray within `arr`.", "function_declaration": "def max_product_subarray(arr):", "function_name": "max_product_subarray", "parameter_list": "(arr)" }, { "docstring": null, "function_declaration": "def solve(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 max_product_subarray(arr):\n \"\"\"\n Returns the maximum product of any contiguous subarray within `arr`.\n \"\"\"\n if not arr:\n ...
trial_gpt4o_0
{ "original_instruction": "You are given an integer array `arr` and you need to find the maximum product of any contiguous subarray within `arr`.\n\nFor example, given the array `arr = [2, 3, -2, 4]`, the contiguous subarray `[2, 3]` has the maximum product of `6`.\n\nInput:\n- The first line contains an integer `T`,...
0.682803
Code_Contests_3235
C
[ "max_product_subarray", "solve", "parse_input" ]
3
[ [ "solve", "max_product_subarray" ] ]
1
[ "parse_input" ]
false
[]
false
pytest
true
[]
true
22a4c1678a3b7de8efb45517a4469925ef1299b2
f13b6926ccad263ea1388033232149f5a539529d
v1.0
complete
Code_Contests
Code_Contests_3363_C
from typing import List def find_longest_word(s: str, d: List[str]) -> str: """ Given a string S and a set of words D, find the longest word in D that is a subsequence of S. >>> find_longest_word("abppplee", ["able", "ale", "apple"]) "apple" >>> find_longest_word("abppplee", ["a", "b", "c"]) "a" ...
def is_subsequence(s, word): it = iter(s) return all(char in it for char in word) def find_longest_word(s, d): d.sort(key=lambda x: (-len(x), x)) for word in d: if is_subsequence(s, word): return word return ''
from solution import find_longest_word def test_case_1(): s = "abppplee" d = ["able", "ale", "apple"] assert find_longest_word(s, d) == "apple" def test_case_2(): s = "abppplee" d = ["a", "b", "c"] assert find_longest_word(s, d) == "a" def test_case_3(): s = "abppplee" d = ["bpp", "bp...
[ { "docstring": null, "function_declaration": "def is_subsequence(s, word):", "function_name": "is_subsequence", "parameter_list": "(s, word)" }, { "docstring": null, "function_declaration": "def find_longest_word(s, d):", "function_name": "find_longest_word", "parameter_list": "(...
[ 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_subsequence(s, word):\n \"\"\"\n Helper function to check if 'word' is a subsequence of 's'.\n \"\"\"\n it = iter(s)\n return all(cha...
trial_gpt4o_2
{ "original_instruction": "Given a string S and a set of words D, find the longest word in D that is a subsequence of S.\n\nA subsequence is defined as a new string generated from the original string with some characters(can be none) deleted without changing the relative order of the remaining characters.\n\n\nInput:...
0.754174
Code_Contests_3363
C
[ "is_subsequence", "find_longest_word" ]
2
[ [ "find_longest_word", "is_subsequence" ] ]
1
[]
false
[]
false
pytest
true
[]
true
693769554acd4024ca033b0005adf8e9de7098a6
c0ee9e4077b76fefec1f6ad253f5b6c0befe952d
v1.0
complete
Code_Contests
Code_Contests_3296_C
def max_submatrix_sum(matrix: List[List[int]]) -> int: """ Finds the submatrix within the given matrix that has the maximum sum and returns that sum. >>> max_submatrix_sum([[1, 2, -1, 4, -5], [-8, 3, 0, 5, 2], [-4, 6, -3, -4, 4], [2, 8, 0, -1, 3]]) 23 >>> max_submatrix_sum([[-1, -2, -3], [-4, -5, -6], [...
def max_submatrix_sum(matrix): """ Finds the submatrix within the given matrix that has the maximum sum and returns that sum. Uses a 2D variant of Kadane's algorithm. """ n = len(matrix) m = len(matrix[0]) max_sum = float('-inf') for left in range(m): temp = [0] * n for ...
from solution import max_submatrix_sum def test_example_1(): matrix = [ [1, 2, -1, 4, -5], [-8, 3, 0, 5, 2], [-4, 6, -3, -4, 4], [2, 8, 0, -1, 3] ] assert max_submatrix_sum(matrix) == 23 def test_example_2(): matrix = [ [-1, -2, -3], [-4, -5, -6], ...
[ { "docstring": "Finds the submatrix within the given matrix that has the maximum sum and returns that sum.\nUses a 2D variant of Kadane's algorithm.", "function_declaration": "def max_submatrix_sum(matrix):", "function_name": "max_submatrix_sum", "parameter_list": "(matrix)" }, { "docstring"...
[ 0, 1, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def max_sum_submatrix(matrix):\n \"\"\"\n Returns the maximum sum of a submatrix within the given matrix.\n \"\"\"\n def kadane(arr):\n ...
trial_gpt4o_1
{ "original_instruction": "You are given a rectangular matrix of dimensions n x m consisting of integers. We define the sum of a submatrix as the sum of all the elements within that submatrix. Your task is to find the submatrix with the maximum sum.\n\nThe rectangle with the maximum sum will give you the desired resu...
0.642732
Code_Contests_3296
C
[ "max_submatrix_sum", "kadane" ]
2
[ [ "max_submatrix_sum", "kadane" ] ]
1
[]
false
[]
false
pytest
true
[]
true
ba95b5297cbbd3729abc1140a5497006cd37034b
6a3f8fb68876b030d6ed4240a8e3d6a7a27339e1
v1.0
complete
Code_Contests
Code_Contests_2982_C
def matrix_max_sum(n: int, m: int, matrix: List[List[int]]) -> int: """ A software company is organizing a competition where each participant is given a matrix of integers. The task is to find the submatrix which has the maximum sum. The participants should write a program that outputs the maximum sum of any submat...
def max_sum_submatrix(matrix, n, m): def kadane(arr): max_ending_here = max_so_far = arr[0] for x in arr[1:]: max_ending_here = max(x, max_ending_here + x) max_so_far = max(max_so_far, max_ending_here) return max_so_far max_sum = float('-inf') for le...
from solution import matrix_max_sum def test_sample_case(): matrix = [ [1, 2, -1, -4, -20], [-8, -3, 4, 2, 1], [3, 8, 10, 1, 3], [-4, -1, 1, 7, -6] ] assert matrix_max_sum(4, 5, matrix) == 29 def test_single_element_matrix(): matrix = [[-5]] assert matrix_max_sum(1,...
[ { "docstring": null, "function_declaration": "def max_sum_submatrix(matrix, n, m):", "function_name": "max_sum_submatrix", "parameter_list": "(matrix, n, m)" }, { "docstring": null, "function_declaration": "def matrix_max_sum(n, m, matrix):", "function_name": "matrix_max_sum", "p...
[ 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 max_sum_submatrix(matrix):\n \"\"\"\n Returns the maximum sum of any submatrix in the given matrix.\n \"\"\"\n if not matrix or not matrix[...
trial_gpt4o_4
{ "original_instruction": "A software company is organizing a competition where each participant is given a matrix of integers. The task is to find the submatrix which has the maximum sum. The participants should write a program that outputs the maximum sum of any submatrix within the given matrix.\n\n Input :\nThe f...
0.628265
Code_Contests_2982
C
[ "max_sum_submatrix", "matrix_max_sum" ]
2
[ [ "matrix_max_sum", "max_sum_submatrix" ] ]
1
[]
false
[]
false
pytest
true
[]
true
5b4d8fbee671e4d8fb45402167e655691b6e667c
364c7526250293231692b7829f3cf93823e044c3
v1.0
complete
Code_Contests
Code_Contests_3084_C
def sieve_of_eratosthenes(max_num): """ Generates a list of booleans indicating the primality of numbers up to max_num. True means the number is prime, False means it is not. """ def count_primes_in_ranges(test_cases): """ Counts the number of prime numbers in given ranges. :param test_cas...
def sieve_of_eratosthenes(max_num): """ Generates a list of booleans indicating the primality of numbers up to max_num. True means the number is prime, False means it is not. """ is_prime = [True] * (max_num + 1) is_prime[0] = is_prime[1] = False # 0 and 1 are not primes p = 2 while p * ...
def test_sieve_of_eratosthenes(): is_prime = sieve_of_eratosthenes(30) expected_primes = [False, False, True, True, False, True, False, True, False, False, False, True, False, True, False, False, False, True, False, True, False, False, False, True, False, False, False, False, False, True, False] assert is_p...
[ { "docstring": "Generates a list of booleans indicating the primality of numbers up to max_num.\nTrue means the number is prime, False means it is not.", "function_declaration": "def sieve_of_eratosthenes(max_num):", "function_name": "sieve_of_eratosthenes", "parameter_list": "(max_num)" }, { ...
[ 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(max_num):\n \"\"\"\n Generates a list of booleans indicating the primality of numbers up to max_num.\n True means the nu...
trial_gpt4o_0
{ "original_instruction": "Mina loves prime numbers and she enjoys counting them. Given two integers l and r, she wants to find how many prime numbers are there in the inclusive range [l, r]. As the prime numbers can be large, the result can be very large as well, so she only needs to know the number of prime numbers...
0.662017
Code_Contests_3084
C
[ "sieve_of_eratosthenes", "count_primes_in_ranges", "process_input", "solve" ]
4
[ [ "count_primes_in_ranges", "sieve_of_eratosthenes" ], [ "solve", "count_primes_in_ranges" ], [ "solve", "process_input" ] ]
3
[ "process_input" ]
false
[]
false
pytest
false
[]
true
7f9516b63deed28afac538ac0b6f64c695fc3876
9dc8e0776a24aa0776669f187cb02ce624226345
v1.0
complete
Code_Contests
Code_Contests_3632_C
def magical_sequence(n: int) -> List[int]: """ Generates the first n elements of the magical sequence. >>> magical_sequence(5) [1, 2, 4, 8, 16] >>> magical_sequence(10) [1, 2, 4, 8, 16, 32, 64, 128, 256, 512] >>> magical_sequence(1) [1] >>> magical_sequence(2) [1, 2] >>> magical_...
def magical_sequence(n): """ Generates the first n elements of the magical sequence. """ seq = [1] for _ in range(1, n): next_element = seq[-1] + 1 while not is_non_summable(next_element, seq): next_element += 1 seq.append(next_element) return seq def is_non_...
from solution import magical_sequence def test_magical_sequence_5(): assert magical_sequence(5) == [1, 2, 4, 8, 16] def test_magical_sequence_10(): assert magical_sequence(10) == [1, 2, 4, 8, 16, 32, 64, 128, 256, 512] def test_magical_sequence_1(): assert magical_sequence(1) == [1] def test_magical_seq...
[ { "docstring": "Generates the first n elements of the magical sequence.", "function_declaration": "def magical_sequence(n):", "function_name": "magical_sequence", "parameter_list": "(n)" }, { "docstring": "Checks if a number cannot be represented as the sum of one or more\nelements in the se...
[ 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 magical_sequence(n):\n \"\"\"\n Generates the first n elements of the magical sequence.\n \"\"\"\n seq = [1]\n for _ in range(1, n):\n ...
trial_gpt4o_0
{ "original_instruction": "A strictly increasing sequence of integers a1, a2, ..., an is called a magical sequence if it satisfies the following conditions:\n1. a1 = 1.\n2. For every integer m ≥ 1, am + 1 is the smallest integer that is greater than am and cannot be represented as the sum of 1 or more (not necessaril...
0.579214
Code_Contests_3632
C
[ "magical_sequence", "is_non_summable" ]
2
[ [ "magical_sequence", "is_non_summable" ] ]
1
[]
false
[]
false
pytest
true
[]
true
c8274f83eada26b55038e2c51824f3bd24b052c3
1aaaec91cfc2d000b15a2c5e241f6fd2e1f63f84
v1.0
complete
Code_Contests
Code_Contests_3648_C
def gemstone_groups(T: int, cases: List[Tuple[int, List[int]]]) -> List[int]: """ Given the number of test cases and for each test case the number of different gemstone types along with the counts of each gemstone type, returns the number of ways to rearrange the collection into groups where each group...
def gcd(a, b): while b: a, b = b, a % b return a def find_max_groups(N, gemstone_counts): if N == 1: return gemstone_counts[0] result_gcd = gemstone_counts[0] for count in gemstone_counts[1:]: result_gcd = gcd(result_gcd, count) return result_gcd def gemstone_...
def test_simple_case(): T = 1 cases = [(3, [2, 4, 6])] assert gemstone_groups(T, cases) == [2] def test_another_case(): T = 1 cases = [(4, [6, 3, 9, 12])] assert gemstone_groups(T, cases) == [3] def test_single_gem_type(): T = 1 cases = [(1, [100])] assert gemstone_groups(T, cases)...
[ { "docstring": null, "function_declaration": "def gcd(a, b):", "function_name": "gcd", "parameter_list": "(a, b)" }, { "docstring": null, "function_declaration": "def find_max_groups(N, gemstone_counts):", "function_name": "find_max_groups", "parameter_list": "(N, gemstone_counts...
[ 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\nfrom functools import reduce\nfrom math import gcd\n\ndef possible_groups(N, counts):\n \"\"\"\n Determines the number of ways Alice can...
trial_gpt4o_1
{ "original_instruction": "**Problem Statement:**\n\nAlice loves collecting gemstones. She has a large collection of gemstones, where each gemstone is represented by a positive integer. Alice wants to distribute her collection of gemstones in such a way that each group of gemstones contains the same gemstones with th...
0.555346
Code_Contests_3648
C
[ "gcd", "find_max_groups", "gemstone_groups" ]
3
[ [ "find_max_groups", "gcd" ], [ "gemstone_groups", "find_max_groups" ] ]
2
[]
false
[]
false
pytest
false
[]
true
dba4893a2534d9d82fcad919e231b236e19a7896
14d2fb616860b0aee11660faaa4f6063f236c095
v1.0
complete
Code_Contests
Code_Contests_3867_C
def longest_palindrome_or_repeating_segment(s: str) -> str: """ Return the longest substring of s that is either a palindrome or has a repeating segment. If there are multiple substrings of the same maximum length, return the lexicographically smallest one. >>> longest_palindrome_or_repeating_segment(...
def is_palindrome(s): """ Check if a string s is a palindrome """ return s == s[::-1] def has_repeating_segment(s): """ Check if a string s has a repeating segment """ n = len(s) for i in range(1, n // 2 + 1): if n % i == 0: if s == s[:i] * (n // i): ...
from solution import longest_palindrome_or_repeating_segment def test_example_1(): assert longest_palindrome_or_repeating_segment("racecarbanana") == "racecar" def test_example_2(): assert longest_palindrome_or_repeating_segment("abcabcabc") == "abcabcabc" def test_example_3(): assert longest_palindrome_...
[ { "docstring": "Check if a string s is a palindrome", "function_declaration": "def is_palindrome(s):", "function_name": "is_palindrome", "parameter_list": "(s)" }, { "docstring": "Check if a string s has a repeating segment", "function_declaration": "def has_repeating_segment(s):", "...
[ 0, 0, 0, 0, 1 ]
1
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_palindrome(s):\n return s == s[::-1]\n\ndef has_repeating_segment(s):\n n = len(s)\n for i in range(1, n // 2 + 1):\n if n % i == 0:...
trial_gpt4o_4
{ "original_instruction": "Ann has another task which she needs to complete to prepare for her upcoming programming exam. She has to solve different questions related to strings. This time she will deal with two specific types of strings: palindromes and repeating segments.\n\nA string is a palindrome if it reads the...
0.737874
Code_Contests_3867
C
[ "is_palindrome", "has_repeating_segment", "longest_palindrome_or_repeating_segment" ]
3
[ [ "longest_palindrome_or_repeating_segment", "has_repeating_segment" ], [ "longest_palindrome_or_repeating_segment", "is_palindrome" ] ]
2
[]
false
[]
false
pytest
true
[]
true
c7e39f88ba4415b4c7019f053d8d108eaddb9622
c93ea905f39a123670f2ad767cc14118f0b0f6fc
v1.0
complete
Code_Contests
Code_Contests_2641_C
def lis_length(sequence): """ Returns the length of the longest increasing subsequence in sequence. """ # Your implementation here def parse_input(input_data): """ Parses the input data and returns the list of sequences to be processed. """ # Your implementation here def longest_increa...
def lis_length(sequence): """ Returns the length of the longest increasing subsequence in sequence. """ if not sequence: return 0 n = len(sequence) lis = [1] * n for i in range(1, n): for j in range(0, i): if sequence[i] > sequence[j]: lis[i]...
from solution import lis_length, parse_input, longest_increasing_subsequence def test_lis_length(): assert lis_length([10, 22, 9, 33, 21, 50]) == 4 assert lis_length([3, 10, 2, 1, 20]) == 3 assert lis_length([]) == 0 assert lis_length([1, 2, 3, 4, 5]) == 5 assert lis_length([9, 8, 7, 6, 5]) == 1 d...
[ { "docstring": "Returns the length of the longest increasing subsequence in sequence.", "function_declaration": "def lis_length(sequence):", "function_name": "lis_length", "parameter_list": "(sequence)" }, { "docstring": "Parses the input data and returns the list of sequences to be processe...
[ 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 longest_increasing_subsequence(arr):\n \"\"\"\n Returns the length of the longest increasing subsequence in the array arr.\n \"\"\"\n if no...
trial_gpt4o_2
{ "original_instruction": "Write a program that calculates the longest increasing subsequence of a given sequence of integers.\n\nInput\n\nThe input consists of several datasets. Each dataset consists of:\n\nThe length of the sequence.\nThe sequence of integers.\n\nThe input ends with a line consisting of a single 0....
0.598924
Code_Contests_2641
C
[ "lis_length", "parse_input", "longest_increasing_subsequence" ]
3
[ [ "longest_increasing_subsequence", "lis_length" ], [ "longest_increasing_subsequence", "parse_input" ] ]
2
[ "parse_input" ]
false
[]
false
pytest
true
[]
true
4745621a244896467c25e75ea0737ea9ed387bcc
80f2c1fce5a6fea36ad070daa8e2567160568b01
v1.0
complete
Code_Contests
Code_Contests_3802_C
def find_prime_chain(d: int, l: int) -> str: """ Find the longest possible chain of primes with D digits and length L. >>> find_prime_chain(2, 3) '11 13 17' >>> find_prime_chain(2, 6) '11 13 17 19 23 29' >>> find_prime_chain(3, 10) '101 103 107 109 113 127 131 137 139 149' >>> find_prime...
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 generate_primes_with_d_digits(d): star...
from solution import find_prime_chain def test_prime_chain_with_two_digits_and_length_three(): assert find_prime_chain(2, 3) == '11 13 17' def test_prime_chain_with_two_digits_and_length_six(): assert find_prime_chain(2, 6) == '11 13 17 19 23 29' def test_prime_chain_with_three_digits_and_length_ten(): a...
[ { "docstring": null, "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": null, "function_declaration": "def generate_primes_with_d_digits(d):", "function_name": "generate_primes_with_d_digits", "parameter_list": "(d)"...
[ 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 sieve_of_eratosthenes(max_num):\n \"\"\"\n Generate a list of prime numbers up to max_num (inclusive) using the Sieve of Eratosthenes.\n \"\"\...
trial_gpt4o_3
{ "original_instruction": "Samuel is an enthusiast for prime numbers and loves constructing prime chains. A prime chain of length n is a sequence of n distinct prime numbers in which each prime number is strictly greater than the previous one. He has a unique rule though: he wants all the prime numbers in the chain t...
0.654899
Code_Contests_3802
C
[ "is_prime", "generate_primes_with_d_digits", "find_prime_chain" ]
3
[ [ "find_prime_chain", "generate_primes_with_d_digits" ], [ "generate_primes_with_d_digits", "is_prime" ] ]
2
[]
false
[]
false
pytest
true
[]
true
0bd7f1e58ec15d883a3c4fcb945e21a8d0f6e14a
fdb5d75ab7cd570cdf4e3bf7687111e5766093f5