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
instruct
Code_Contests
Code_Contests_22196_I
In a faraway land, there is a kingdom with n cities connected by m bidirectional roads. Each road connects two distinct cities, and no two cities are directly connected by more than one road. Additionally, it is guaranteed that the road network forms a tree (i.e., there are no cycles, and all cities are reachable from ...
from collections import deque, defaultdict import sys def bfs(farthest_node, graph, n): dist = [-1] * (n + 1) queue = deque([farthest_node]) dist[farthest_node] = 0 max_dist = 0 furthest_node = farthest_node while queue: node = queue.popleft() for neighbor in graph[node]: ...
from solution import best_city_to_host_festival def test_single_test_case(): assert best_city_to_host_festival(1, [(6, [(1, 2), (1, 3), (3, 4), (3, 5), (4, 6)])]) == [3] def test_multiple_possible_answers(): assert best_city_to_host_festival(1, [(3, [(1, 2), (1, 3)])]) == [1] def test_large_tree(): n = 1...
[ { "docstring": null, "function_declaration": "def bfs(farthest_node, graph, n):", "function_name": "bfs", "parameter_list": "(farthest_node, graph, n)" }, { "docstring": null, "function_declaration": "def find_best_city(n, roads):", "function_name": "find_best_city", "parameter_l...
[ 1, 1, 0 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "from collections import deque, defaultdict\nimport sys\n\ndef bfs(farthest_node, graph, n):\n dist = [-1] * (n + 1)\n queue = deque([farthest_node])\...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00022196", "row_id": 22196, "seed_ids": "[6929]" }
0.757543
Code_Contests_22196
I
[ "bfs", "find_best_city", "best_city_to_host_festival" ]
3
[ [ "best_city_to_host_festival", "find_best_city" ], [ "find_best_city", "bfs" ] ]
2
[]
false
[]
false
pytest
true
[]
true
c01e4c5601432d85e8595531e1b8f89a8e44a7f3
9dc91631e7cf644ba0c0b7324594a6039bbe6191
v1.0
instruct
Code_Contests
Code_Contests_22224_I
In a network security company, analyst Emily is in charge of monitoring the network for any unusual behavior. She needs to identify and report on the number of unique IP addresses accessing the network over a certain period. You're tasked to create a program that helps Emily with her job. The program will ingest a seq...
def process_logs_and_queries(log_entries, queries): from collections import defaultdict import bisect # Parse log entries into a list of (timestamp, IP_address) tuples logs = [] for entry in log_entries: timestamp, ip = entry.split() logs.append((int(timestamp), ip)) # Dictiona...
def test_process_logs_and_queries_simple_case(): log_entries = [ "10 192.168.1.1", "20 192.168.1.2", "30 192.168.1.3", "40 192.168.1.1", "50 192.168.1.4" ] queries = [ "10 30", "20 50", "0 60" ] expected = [3, 3, 4] result = p...
[ { "docstring": null, "function_declaration": "def process_logs_and_queries(log_entries, queries):", "function_name": "process_logs_and_queries", "parameter_list": "(log_entries, queries)" }, { "docstring": null, "function_declaration": "def collect_input_and_process():", "function_na...
[ 0, 0, 0, 0, 0, 0, 1, 0, 0 ]
1
hard
0.111
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def count_unique_ips(logs, queries):\n \"\"\"\n Returns a list of the number of unique IP addresses for each query interval.\n \"\"\"\n from co...
trial_gpt4o_7
{ "original_instruction": "", "prompt_id": "00022224", "row_id": 22224, "seed_ids": "[6239]" }
0.670849
Code_Contests_22224
I
[ "process_logs_and_queries", "collect_input_and_process" ]
2
[ [ "collect_input_and_process", "process_logs_and_queries" ] ]
1
[]
false
[]
false
pytest
false
[]
true
4f1c7f3fe048e1495deed4434db7263863041ba9
994cf8b8809754383febf94efd18e49a35e75d3d
v1.0
instruct
Code_Contests
Code_Contests_22248_I
Arjun loves to play with numbers and is particularly fascinated by prime numbers. He recently learned about twin primes (pairs of prime numbers that differ by 2). He now wants to identify all the twin primes within a given range and needs your help. Input: The first line contains two integers, L and R, denoting the lo...
def is_prime(n): """ Checks if n is a prime number. """ if n <= 1: return False if n == 2: return True # as 2 is the only even prime number if n % 2 == 0: return False for i in range(3, int(n ** 0.5) + 1, 2): if n % i == 0: return False return...
from solution import is_prime, find_twin_primes, format_twin_primes def test_is_prime(): assert is_prime(2) == True assert is_prime(3) == True assert is_prime(4) == False assert is_prime(17) == True assert is_prime(18) == False assert is_prime(19) == True assert is_prime(1) == False def te...
[ { "docstring": "Checks if n is a prime number.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Finds and returns all twin primes within the range [L, R].", "function_declaration": "def find_twin_primes(L, R):", "fu...
[ 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 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 == 2:\n ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00022248", "row_id": 22248, "seed_ids": "[7357]" }
0.654412
Code_Contests_22248
I
[ "is_prime", "find_twin_primes", "format_twin_primes" ]
3
[ [ "find_twin_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
432b9960745f0b9686c2af7bbb5add3d7ccf65c7
ae010c6cf3b2e71184dc5864546e6dcc71fcd39a
v1.0
instruct
Code_Contests
Code_Contests_22260_I
During a treasure hunt, you discover an ancient map that leads to a treasure. The map contains a secret code which can be deciphered using a simple algorithm based on characters' positions in the English alphabet. The map is represented as a string containing only lowercase English alphabetic characters. Each characte...
def alphabet_position(char): return ord(char) - ord('a') + 1 def preprocess_sum(s): sums = [0] * (len(s) + 1) for i in range(1, len(s) + 1): sums[i] = sums[i - 1] + alphabet_position(s[i - 1]) return sums def query_sum(sums, l, r): return sums[r] - sums[l - 1] def treasure_hunt(s, queries...
from solution import treasure_hunt def test_example_1(): s = "abc" queries = [(1, 1), (1, 2), (1, 3)] result = treasure_hunt(s, queries) assert result == [1, 3, 6] def test_example_2(): s = "xyz" queries = [(1, 2), (2, 3)] result = treasure_hunt(s, queries) assert result == [49, 51] d...
[ { "docstring": null, "function_declaration": "def alphabet_position(char):", "function_name": "alphabet_position", "parameter_list": "(char)" }, { "docstring": null, "function_declaration": "def preprocess_sum(s):", "function_name": "preprocess_sum", "parameter_list": "(s)" }, ...
[ 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 alphabetic_value_sum(s, queries):\n \"\"\"\n This function calculates the sum of numeric values for queried segments of the string.\n \n Pa...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00022260", "row_id": 22260, "seed_ids": "[220]" }
0.628772
Code_Contests_22260
I
[ "alphabet_position", "preprocess_sum", "query_sum", "treasure_hunt" ]
4
[ [ "preprocess_sum", "alphabet_position" ], [ "treasure_hunt", "preprocess_sum" ], [ "treasure_hunt", "query_sum" ] ]
3
[]
false
[]
false
pytest
true
[]
true
47cea2ca092c7403eb86f1ea960aacf2e273ffb0
95ca1f79b319d0013b47687331493ebf23bf6747
v1.0
instruct
Code_Contests
Code_Contests_22290_I
Write a program that reads a list of integers and determines if each number is a perfect square. A perfect square is an integer that is the square of some integer. For example, 1, 4, 9, and 16 are perfect squares. Input Input consists of several datasets. Each dataset is a single integer n (1 ≤ n ≤ 10^12) in a line. ...
import math def is_perfect_square(n): """ Determines if n is a perfect square. """ root = int(math.sqrt(n)) return root * root == n def process_numbers(numbers): """ Takes a list of numbers and returns a list of 'YES' or 'NO' indicating whether each number is a perfect square. """...
from solution import is_perfect_square, process_numbers def test_is_perfect_square(): assert is_perfect_square(1) == True assert is_perfect_square(4) == True assert is_perfect_square(9) == True assert is_perfect_square(16) == True assert is_perfect_square(10) == False assert is_perfect_square(2...
[ { "docstring": "Determines if n is a perfect square.", "function_declaration": "def is_perfect_square(n):", "function_name": "is_perfect_square", "parameter_list": "(n)" }, { "docstring": "Takes a list of numbers and returns a list of 'YES' or 'NO' indicating \nwhether each number is a perfe...
[ 1, 0, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "import math\n\ndef is_perfect_square(n):\n \"\"\"\n Determines if n is a perfect square.\n \"\"\"\n root = int(math.sqrt(n))\n return root *...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00022290", "row_id": 22290, "seed_ids": "[1965]" }
0.593608
Code_Contests_22290
I
[ "is_perfect_square", "process_numbers" ]
2
[ [ "process_numbers", "is_perfect_square" ] ]
1
[]
false
[]
false
pytest
true
[]
true
8a554e760f52ad1fa0badefd152e9569c68d13a8
3cb10b661f280a431df6c713e30a2049062bc3a5
v1.0
instruct
Code_Contests
Code_Contests_22327_I
Alex recently started experimenting with different sorting algorithms for fun. To challenge himself, he wants to modify the traditional quicksort algorithm. Specifically, he wants to add a twist: for each subarray that gets partitioned, he will pick the median of the first, middle, and last elements as the pivot. Help ...
def median_of_three(arr, low, high): mid = (low + high) // 2 a = arr[low] b = arr[mid] c = arr[high] if a > b: if a < c: return low elif b > c: return mid else: return high else: if a > c: return low elif b <...
from solution import sort_array def test_sort_array_example1(): assert sort_array(5, [3, 1, 4, 1, 5]) == [1, 1, 3, 4, 5] def test_sort_array_example2(): assert sort_array(6, [10, 9, 8, 7, 6, 5]) == [5, 6, 7, 8, 9, 10] def test_sort_array_single_element(): assert sort_array(1, [42]) == [42] def test_sort...
[ { "docstring": null, "function_declaration": "def median_of_three(arr, low, high):", "function_name": "median_of_three", "parameter_list": "(arr, low, high)" }, { "docstring": null, "function_declaration": "def partition(arr, low, high):", "function_name": "partition", "parameter...
[ 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 median_of_three(arr, low, high):\n mid = (low + high) // 2\n a = arr[low]\n b = arr[mid]\n c = arr[high]\n if a > b:\n if a < c:\...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00022327", "row_id": 22327, "seed_ids": "[4843]" }
0.587819
Code_Contests_22327
I
[ "median_of_three", "partition", "quicksort", "modified_quicksort", "sort_array" ]
5
[ [ "modified_quicksort", "quicksort" ], [ "partition", "median_of_three" ], [ "quicksort", "partition" ], [ "sort_array", "modified_quicksort" ] ]
4
[]
false
[]
false
pytest
true
[]
true
c8dcae19ed6a8c09065dcee44d10b55a41876221
950e7cd8467bc2dbba619c5d7180dc4fd4ca931f
v1.0
instruct
Code_Contests
Code_Contests_22363_I
Write a program to implement the Merge Sort algorithm which sorts a sequence A in ascending order. The algorithm should be based on the following pseudocode: merge_sort(A, left, right): if left < right: mid = (left + right) // 2 merge_sort(A, left, mid) merge_sort(A, mid + 1, right) merge(A, left, mid,...
def merge(A, left, mid, right): n1 = mid - left + 1 n2 = right - mid L = [0] * n1 R = [0] * n2 for i in range(n1): L[i] = A[left + i] for j in range(n2): R[j] = A[mid + 1 + j] i = 0 j = 0 k = left while i < n1 and j < n2: if L[i] <= R[j]: A...
from solution import merge_sort def test_merge_sort(): A = [5, 2, 4, 6, 1, 3] merge_sort(A, 0, 5) assert A == [1, 2, 3, 4, 5, 6] A = [4, 3, 2, 1] merge_sort(A, 0, 3) assert A == [1, 2, 3, 4] A = [1] merge_sort(A, 0, 0) assert A == [1] A = [1, 2, 3, 4, 5] merge_sort(A, 0, ...
[ { "docstring": null, "function_declaration": "def merge(A, left, mid, right):", "function_name": "merge", "parameter_list": "(A, left, mid, right)" }, { "docstring": null, "function_declaration": "def merge_sort(A, left, right):", "function_name": "merge_sort", "parameter_list": ...
[ 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 merge_sort(A, left, right, result_sequences):\n if left < right:\n mid = (left + right) // 2\n merge_sort(A, left, mid, result_sequenc...
trial_gpt4o_4
{ "original_instruction": "", "prompt_id": "00022363", "row_id": 22363, "seed_ids": "[10204]" }
0.651209
Code_Contests_22363
I
[ "merge", "merge_sort", "main" ]
3
[ [ "merge_sort", "merge" ] ]
1
[]
false
[]
false
pytest
true
[]
true
5695ae85cc3a3e30b8838fd155d057a2b0264d00
e7dbac695c52c0849e60a71fad21646a13e41647
v1.0
instruct
Code_Contests
Code_Contests_22450_I
A software development company is designing a new traffic management system for a small town. The town has a number of parking lots and streets connecting them. Each street has a certain traversal time, and each parking lot has a maximum number of available spaces. The town planners want to ensure that vehicles can mov...
def floyd_warshall(n, edges): inf = float('inf') dist = [[inf] * n for _ in range(n)] for i in range(n): dist[i][i] = 0 for u, v, w in edges: dist[u][v] = w dist[v][u] = w for k in range(n): for i in range(n): for j in range(n): ...
import pytest from solution import traffic_management_system def test_single_case_sufficient(): test_cases = [ (4, 5, [3, 2, 4, 1], [(0, 1, 4), (0, 2, 9), (1, 2, 2), (1, 3, 5), (2, 3, 1)], [2, 1, 2, 1]) ] expected_output = """Case #1: 0 4 6 7 4 0 2 3 6 2 0 1 7 3 1 0 Sufficient""" assert traffic...
[ { "docstring": null, "function_declaration": "def floyd_warshall(n, edges):", "function_name": "floyd_warshall", "parameter_list": "(n, edges)" }, { "docstring": null, "function_declaration": "def check_sufficiency(capacities, demands):", "function_name": "check_sufficiency", "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": "def floyd_warshall(n, edges):\n # Initialize distance matrix with infinity\n inf = float('inf')\n dist = [[inf] * n for _ in range(n)]\n \n ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00022450", "row_id": 22450, "seed_ids": "[720]" }
0.741168
Code_Contests_22450
I
[ "floyd_warshall", "check_sufficiency", "traffic_management_system" ]
3
[ [ "traffic_management_system", "check_sufficiency" ], [ "traffic_management_system", "floyd_warshall" ] ]
2
[]
false
[]
false
pytest
true
[]
true
967e9d94c2ec17bba478698efad8978bb253966e
05445200de3ac8c8a3710f0f6f8f34835998cb48
v1.0
instruct
Code_Contests
Code_Contests_22543_I
City Zoo is creating a new exhibit for a rare species of animals. To keep track of the total lifespan of the animals in the new exhibit, the zookeepers decided to implement a new tracking system. The system needs a special mechanism to calculate the sum of the lifespans of animals within a certain range. Each animal's ...
def is_prime(num): """ Helper function to determine if a number is prime. """ if num <= 1: return False if num == 2: return True if num % 2 == 0: return False for i in range(3, int(num**0.5) + 1, 2): if num % i == 0: return False return True d...
def test_is_prime(): assert is_prime(2) assert is_prime(3) assert not is_prime(4) assert is_prime(5) assert not is_prime(10) def test_get_lifespan_status(): assert get_lifespan_status(2, [ (5, 1, 3, [2, 3, 5, 7, 11]), (6, 2, 5, [3, 5, 7, 11, 13, 17]) ]) == ["INVALID", "INVAL...
[ { "docstring": "Helper function to determine if a number is prime.", "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": null, "function_declaration": "def get_lifespan_status(T, test_cases):", "function_name": "get_l...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(n):\n if n <= 1:\n return False\n if n <= 3:\n return True\n if n % 2 == 0 or n % 3 == 0:\n return False\n i ...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00022543", "row_id": 22543, "seed_ids": "[10275]" }
0.589681
Code_Contests_22543
I
[ "is_prime", "get_lifespan_status", "parse_input", "main" ]
4
[ [ "get_lifespan_status", "is_prime" ] ]
1
[ "parse_input" ]
false
[]
false
pytest
false
[]
true
668179c98213a24daa3ad3b89ddccce1055f12ea
57a3ac8d4b00beed8149226e9807509d6ff73ede
v1.0
instruct
Code_Contests
Code_Contests_22560_I
Alex works as a network administrator at a company that maintains a dedicated network of servers. Each server connects to a certain number of other servers through direct one-way communication links. The network is represented as a directed graph where each node corresponds to a server and each directed edge correspond...
from collections import defaultdict def find_scc(graph, n): """Find Strongly Connected Components (SCC) using Kosaraju's Algorithm.""" def dfs(v, graph, visited, stack): visited[v] = True for u in graph[v]: if not visited[u]: dfs(u, graph, visited, stack) ...
from solution import min_new_links_to_strongly_connect def test_example_case(): assert min_new_links_to_strongly_connect(4, 2, [(0, 1), (2, 3)]) == 2 def test_single_server(): assert min_new_links_to_strongly_connect(1, 0, []) == 0 def test_already_strongly_connected(): assert min_new_links_to_strongly_c...
[ { "docstring": "Find Strongly Connected Components (SCC) using Kosaraju's Algorithm.", "function_declaration": "def find_scc(graph, n):", "function_name": "find_scc", "parameter_list": "(graph, n)" }, { "docstring": null, "function_declaration": "def min_new_links_to_strongly_connect(n, ...
[ 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 min_new_links(n, m, edges):\n from collections import defaultdict, deque\n \n def strongly_connected_components(n, adjacency_list):\n i...
trial_gpt4o_3
{ "original_instruction": "", "prompt_id": "00022560", "row_id": 22560, "seed_ids": "[1243]" }
0.688425
Code_Contests_22560
I
[ "find_scc", "min_new_links_to_strongly_connect", "reverse_graph" ]
3
[ [ "min_new_links_to_strongly_connect", "find_scc" ], [ "min_new_links_to_strongly_connect", "reverse_graph" ] ]
2
[]
false
[]
false
pytest
true
[]
true
bd278a5c00344f10af2b4f5feb7783289dd928f4
af6e500e0151e3d1c1c3d818eddfe6991cf35f51
v1.0
instruct
Code_Contests
Code_Contests_22569_I
You are given a list of n integers. Your task is to answer q queries. Each query will contain two integers l and r (1 ≤ l ≤ r ≤ n), and you need to determine the maximum GCD (Greatest Common Divisor) of any subarray that includes all elements from the l-th to the r-th element in the list. Input The first line of inpu...
import math from functools import reduce def gcd(a, b): while b: a, b = b, a % b return a def compute_max_gcd_in_subarray(arr, l, r): """ Function to compute the max GCD of any subarray that includes all elements from index l to r in the given list. """ subarray = arr[l-1:r] return...
def test_gcd(): assert gcd(10, 15) == 5 assert gcd(14, 21) == 7 assert gcd(13, 17) == 1 assert gcd(0, 5) == 5 assert gcd(5, 0) == 5 def test_compute_max_gcd_in_subarray(): assert compute_max_gcd_in_subarray([5, 10, 15, 20, 25, 30], 1, 3) == 5 assert compute_max_gcd_in_subarray([5, 10, 15, 2...
[ { "docstring": null, "function_declaration": "def gcd(a, b):", "function_name": "gcd", "parameter_list": "(a, b)" }, { "docstring": "Function to compute the max GCD of any subarray that includes all elements from index l to r in the given list.", "function_declaration": "def compute_max_...
[ 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": "import math\nfrom functools import reduce\n\ndef gcd(a, b):\n \"\"\"\n Function to return the greatest common divisor (GCD) of two numbers.\n \"\"...
trial_gpt4o_7
{ "original_instruction": "", "prompt_id": "00022569", "row_id": 22569, "seed_ids": "[7299]" }
0.775039
Code_Contests_22569
I
[ "gcd", "compute_max_gcd_in_subarray", "solve" ]
3
[ [ "compute_max_gcd_in_subarray", "gcd" ], [ "solve", "compute_max_gcd_in_subarray" ] ]
2
[]
false
[]
false
pytest
false
[]
true
31ae037c4d5bdc70700feabc61fece6a55a18702
ac1ad12771a0efa671569debe8dc49b20e87b21f
v1.0
instruct
Code_Contests
Code_Contests_22580_I
You are given a rooted tree with n nodes. The tree is rooted at node 1. Each node has a value assigned to it, and the value of node i is denoted by a_i. Your task is to answer q queries of the following type: For each query, given a node u and an integer k, find the k-th ancestor of node u. The k-th ancestor of node u...
from collections import defaultdict, deque def build_tree(n, edges): tree = defaultdict(list) for u, v in edges: tree[u].append(v) tree[v].append(u) return tree def preprocess_ancestors(n, tree): parent = [-1] * (n + 1) depth = [0] * (n + 1) log = 1 while (1 << log) <= n: ...
def test_find_ancestors(): n = 7 q = 6 values = [1, 2, 3, 4, 5, 6, 7] edges = [ (1, 2), (1, 3), (2, 4), (2, 5), (3, 6), (3, 7), ] queries = [ (4, 1), (4, 2), (4, 3), (7, 2), (6, 1), (1, 0), ] ...
[ { "docstring": null, "function_declaration": "def build_tree(n, edges):", "function_name": "build_tree", "parameter_list": "(n, edges)" }, { "docstring": null, "function_declaration": "def preprocess_ancestors(n, tree):", "function_name": "preprocess_ancestors", "parameter_list":...
[ 1, 0, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "from collections import deque, defaultdict\nimport sys\n\nsys.setrecursionlimit(200000)\n\ndef find_kth_ancestor(tree, values, u, k, parent, depth):\n i...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00022580", "row_id": 22580, "seed_ids": "[6690]" }
0.676148
Code_Contests_22580
I
[ "build_tree", "preprocess_ancestors", "find_kth_ancestor", "solve" ]
4
[ [ "solve", "build_tree" ], [ "solve", "find_kth_ancestor" ], [ "solve", "preprocess_ancestors" ] ]
3
[]
false
[]
false
pytest
false
[]
true
c663b493c915009a923fcdf5a304b7a33159e166
e16b49718f07c4377b19f59d9ddba857e2abd48d
v1.0
instruct
Code_Contests
Code_Contests_22586_I
Alice and Bob love playing games that involve numbers. Recently, they have come up with a new game that involves prime factors. The rules are simple: given two numbers `A` and `B`, they need to find the sum of all distinct prime factors of `A^B`. For example, if `A` is 12 and `B` is 2, then `A^B = 12^2 = 144`. The pri...
def prime_factors(n): """ Return the set of distinct prime factors of n. """ i = 2 factors = set() while i * i <= n: while (n % i) == 0: factors.add(i) n //= i i += 1 if n > 1: factors.add(n) return factors def sum_of_distinct_prime_factor...
def test_prime_factors(): assert prime_factors(12) == {2, 3} assert prime_factors(15) == {3, 5} assert prime_factors(7) == {7} assert prime_factors(1) == set() def test_sum_of_distinct_prime_factors(): assert sum_of_distinct_prime_factors(12, 2) == 5 assert sum_of_distinct_prime_factors(15, 3) ...
[ { "docstring": "Return the set of distinct prime factors of n.", "function_declaration": "def prime_factors(n):", "function_name": "prime_factors", "parameter_list": "(n)" }, { "docstring": "Return the sum of all distinct prime factors of A^B.", "function_declaration": "def sum_of_distin...
[ 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 math\n\ndef distinct_prime_factors(n):\n primes = set()\n if n % 2 == 0:\n primes.add(2)\n while n % 2 == 0:\n n //= ...
trial_gpt4o_4
{ "original_instruction": "", "prompt_id": "00022586", "row_id": 22586, "seed_ids": "[6950]" }
0.604083
Code_Contests_22586
I
[ "prime_factors", "sum_of_distinct_prime_factors", "games_sum_prime_factors" ]
3
[ [ "games_sum_prime_factors", "sum_of_distinct_prime_factors" ], [ "sum_of_distinct_prime_factors", "prime_factors" ] ]
2
[]
false
[]
false
pytest
false
[]
true
e086c010c565f4f958ca5bd6659454ef00d87913
540f4fb9491926aa25fabad95db3601a36956e00
v1.0
instruct
Code_Contests
Code_Contests_22589_I
You are given a compressed string where occurrences of the same character are represented in the format "character count". For example, "a2b1c5a3" is the compressed form of the string "aabcccccaaa". Your task is to decompress such strings. However, there are a few constraints: 1. The compressed string might not always...
import re def decompress_string(compressed_str): """ Decompresses a string where characters are followed by their counts. Returns the decompressed string if valid, otherwise returns "INVALID". """ pattern = re.compile(r'([a-z])(\d+)') decompressed_str = "" position = 0 while p...
import pytest from solution import decompress_string, decompress_multiple_strings def test_decompress_string(): assert decompress_string("a2b1c5a3") == "aabcccccaaa" assert decompress_string("a10bc3") == "INVALID" assert decompress_string("x1y2") == "xyy" assert decompress_string("z0") == "" # Edge ca...
[ { "docstring": "Decompresses a string where characters are followed by their counts.\n\nReturns the decompressed string if valid, otherwise returns \"INVALID\".", "function_declaration": "def decompress_string(compressed_str):", "function_name": "decompress_string", "parameter_list": "(compressed_st...
[ 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 re\n\ndef decompress_string(compressed):\n # Define a pattern to match the format of a character followed by a number\n pattern = re.compile(r...
trial_gpt4o_3
{ "original_instruction": "", "prompt_id": "00022589", "row_id": 22589, "seed_ids": "[12571]" }
0.712425
Code_Contests_22589
I
[ "decompress_string", "decompress_multiple_strings" ]
2
[ [ "decompress_multiple_strings", "decompress_string" ] ]
1
[]
false
[]
false
pytest
true
[]
true
41bad048278d942dc5462bfcfbdbb7532a92c93a
2164693c8158e8247ae9cb8116fddc183c6b8555
v1.0
instruct
Code_Contests
Code_Contests_22763_I
You are given a binary tree with `N` nodes, each with a value. The value of each node is unique and ranges from 1 to N. Your task is to find the maximum distance between any two nodes in the tree. The distance between two nodes is defined as the number of edges on the shortest path between them. ### Input Input is g...
from collections import deque, defaultdict def max_distance(N, edges, values): if N == 1: return 0 # Construct the tree as an adjacency list tree = defaultdict(list) for u, v in edges: tree[u].append(v) tree[v].append(u) # Function to perform BFS and return the far...
def test_max_distance_simple(): edges = [(1, 2), (1, 3)] values = [3, 1, 2] assert max_distance(3, edges, values) == 2 def test_max_distance_complex(): edges = [(1, 2), (1, 3), (2, 4), (2, 5)] values = [5, 1, 4, 2, 3] assert max_distance(5, edges, values) == 3 def test_max_distance_single_node...
[ { "docstring": null, "function_declaration": "def max_distance(N, edges, values):", "function_name": "max_distance", "parameter_list": "(N, edges, values)" }, { "docstring": null, "function_declaration": "def parse_and_solve():", "function_name": "parse_and_solve", "parameter_lis...
[ 1, 0, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "from collections import deque, defaultdict\n\ndef max_distance(N, edges, values):\n if N == 1:\n return 0\n \n # Construct the tree as an a...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00022763", "row_id": 22763, "seed_ids": "[186]" }
0.698753
Code_Contests_22763
I
[ "max_distance", "parse_and_solve" ]
2
[ [ "parse_and_solve", "max_distance" ] ]
1
[]
false
[]
false
pytest
false
[]
true
590740cd2c5da30faa74e93d3f977a2f49075afc
dc6b8d3a46db1558f8486045dc3ff81b2e97ed76
v1.0
instruct
Code_Contests
Code_Contests_22774_I
Given a list of integers, sort the list such that all prime numbers come before non-prime numbers, and within each group (prime and non-prime), the numbers are sorted in ascending order. Input The first line contains integer n (1 ≤ n ≤ 100) — the number of elements in the list. The second line contains n integers (1...
def is_prime(num): """ Check if a number is a prime number. """ if num <= 1: return False for i in range(2, int(num**0.5) + 1): if num % i == 0: return False return True def sort_numbers_with_primes_first(n, numbers): """ Sorts the list of numbers such that p...
from solution import is_prime, sort_numbers_with_primes_first def test_is_prime(): assert is_prime(2) assert is_prime(3) assert not is_prime(4) assert is_prime(5) assert not is_prime(1) assert not is_prime(0) def test_sort_numbers_with_primes_first(): assert sort_numbers_with_primes_fi...
[ { "docstring": "Check if a number is a prime number.", "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": "Sorts the list of numbers such that primes come before non-primes, both sorted in ascending order.", "function_de...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(n):\n \"\"\"\n Helper function to check if a number is prime.\n \n Args:\n n (int): The number to check.\n\n Returns:\n b...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00022774", "row_id": 22774, "seed_ids": "[48]" }
0.683575
Code_Contests_22774
I
[ "is_prime", "sort_numbers_with_primes_first" ]
2
[ [ "sort_numbers_with_primes_first", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
0b41d138eba0d74a5e8a5bf668985e248b5211c0
dc44f042d622cb4660e42138343d0e426afe3af4
v1.0
instruct
Code_Contests
Code_Contests_22776_I
Given a list of n distinct integers in any random order, you need to sort them into a special order. The special order is defined as follows: - All the prime numbers in the list should appear first and they should be sorted in ascending order. - All the composite numbers in the list should appear next and they should b...
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 retur...
def test_is_prime(): assert is_prime(2) == True assert is_prime(3) == True assert is_prime(4) == False assert is_prime(7) == True assert is_prime(10) == False assert is_prime(11) == True assert is_prime(1) == False def test_special_sort(): assert special_sort(7, [3, 15, 2, 1, 9, 4, 7]) ...
[ { "docstring": "Check if a number is prime.", "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": "Return the array sorted in special order.", "function_declaration": "def special_sort(n, arr):", "function_name": "spe...
[ 1, 0, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(num):\n \"\"\" Helper function to determine if a number is prime \"\"\"\n if num <= 1:\n return False\n if num <= 3:\n ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00022776", "row_id": 22776, "seed_ids": "[9912]" }
0.596961
Code_Contests_22776
I
[ "is_prime", "special_sort", "process_test_cases" ]
3
[ [ "process_test_cases", "special_sort" ], [ "special_sort", "is_prime" ] ]
2
[ "process_test_cases" ]
false
[]
false
pytest
false
[]
true
5497537bfe43e4c16f2be83d354bff0b08c121ee
b2979204f7bcf42e72736cdb1de33d344f5da593
v1.0
instruct
Code_Contests
Code_Contests_22791_I
Liam is fascinated with symmetric properties of strings. He finds a string beautiful if it can be rearranged to form a palindrome. Recall that a palindrome is a string that reads the same forward and backward. Liam wonders how many of the strings in a given list are beautiful. Input The first line contains a single ...
def can_form_palindrome(s): """ Determine if a string can be rearranged to form a palindrome. """ from collections import Counter char_count = Counter(s) odd_count = sum(1 for count in char_count.values() if count % 2 == 1) return odd_count <= 1 def check_beautiful_strings(strings): """...
import pytest from solution import can_form_palindrome, check_beautiful_strings def test_can_form_palindrome(): assert can_form_palindrome("civic") == True assert can_form_palindrome("ivicc") == True assert can_form_palindrome("random") == False assert can_form_palindrome("madam") == True assert ca...
[ { "docstring": "Determine if a string can be rearranged to form a palindrome.", "function_declaration": "def can_form_palindrome(s):", "function_name": "can_form_palindrome", "parameter_list": "(s)" }, { "docstring": "For each string in the input list, return 'YES' if it is beautiful (can be...
[ 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_beautiful(s):\n \"\"\"\n Checks if a string s can be rearranged to form a palindrome.\n \n Args:\n s (str): The input string.\n \n...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00022791", "row_id": 22791, "seed_ids": "[6169]" }
0.74489
Code_Contests_22791
I
[ "can_form_palindrome", "check_beautiful_strings" ]
2
[ [ "check_beautiful_strings", "can_form_palindrome" ] ]
1
[]
false
[]
false
pytest
true
[]
true
1aa3573a2b76ea3ad756c4ac40fae84987459bc2
3c672f406639f9a3cd5318d502c1466c30c5af7c
v1.0
instruct
Code_Contests
Code_Contests_22792_I
You have been hired by an amusement park to develop a simulation for one of their new attractions: a robotic boat ride. The ride consists of a rectangular grid of cells, where each cell represents a distinct position in the water. At the start of the ride, the boat is positioned at the top-left cell of the grid (cell (...
def mod_comb(n, k, mod=10**9 + 7): """ Calculate n choose k (nCk) modulo mod. """ if k > n - k: k = n - k num = 1 den = 1 for i in range(k): num = num * (n - i) % mod den = den * (i + 1) % mod return num * pow(den, mod - 2, mod) % mod def number_of_paths(N, M): ...
from solution import process_test_cases def test_case_1(): assert process_test_cases([(2, 2)]) == [2] def test_case_2(): assert process_test_cases([(3, 2)]) == [3] def test_multiple_cases(): assert process_test_cases([(2, 2), (3, 2), (4, 3)]) == [2, 3, 10] def test_case_large(): assert process_test_...
[ { "docstring": "Calculate n choose k (nCk) modulo mod.", "function_declaration": "def mod_comb(n, k, mod=10 ** 9 + 7):", "function_name": "mod_comb", "parameter_list": "(n, k, mod=10 ** 9 + 7)" }, { "docstring": "Calculate the number of distinct paths from (1, 1) to (N, M) on a N x M grid.",...
[ 0, 0, 0, 1, 1 ]
2
medium
0.4
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def number_of_paths(N, M):\n MOD = 10**9 + 7\n \n # Calculate factorials and factorial inverses modulo MOD\n fact = [1] * (N + M)\n inv_fact...
trial_gpt4o_4
{ "original_instruction": "", "prompt_id": "00022792", "row_id": 22792, "seed_ids": "[5800]" }
0.700181
Code_Contests_22792
I
[ "mod_comb", "number_of_paths", "process_test_cases" ]
3
[ [ "number_of_paths", "mod_comb" ], [ "process_test_cases", "number_of_paths" ] ]
2
[ "process_test_cases" ]
false
[]
false
pytest
true
[]
true
6c032c9778f5258c6927dc4ea5e368392bbd0816
1ca642058fa134374a67d17a9c2b114250a5e72c
v1.0
instruct
Code_Contests
Code_Contests_22938_I
A forest ranger is responsible for maintaining the hiking trails in a large forest. The forest is represented by an undirected graph, where nodes represent trail intersections and edges represent the trails between them. Each trail has a difficulty level that can be positive or zero. The ranger wants to ensure that al...
# Kruskal's algorithm to find the Minimum Spanning Tree (MST) def find(parent, i): if parent[i] == i: return i else: return find(parent, parent[i]) def union(parent, rank, x, y): root_x = find(parent, x) root_y = find(parent, y) if root_x != root_y: if rank[root_x] < rank[ro...
def test_min_total_difficulty(): # Test case 1 n, m = 4, 5 trails = [(1, 2, 1), (1, 3, 4), (1, 4, 3), (2, 3, 2), (3, 4, 5)] assert min_total_difficulty(n, m, trails) == 6 # Test case 2 n, m = 5, 4 trails = [(1, 2, 0), (2, 3, 1), (3, 4, 2), (4, 5, 3)] assert min_total_difficulty(n, 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, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "# Kruskal's algorithm to find the Minimum Spanning Tree (MST)\ndef find(parent, i):\n if parent[i] == i:\n return i\n else:\n return fi...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00022938", "row_id": 22938, "seed_ids": "[6192]" }
0.713364
Code_Contests_22938
I
[ "find", "union", "min_total_difficulty" ]
3
[ [ "min_total_difficulty", "find" ], [ "min_total_difficulty", "union" ], [ "union", "find" ] ]
3
[]
false
[]
false
pytest
false
[]
true
77431e00a7a35a917eedbe6ad407bd1e13692136
dc437ed1c058c56f9a7181016b8255f43f5ae99d
v1.0
instruct
Code_Contests
Code_Contests_22953_I
A scientist is conducting an experiment using bacteria cultures in a laboratory. Each culture is represented as a string consisting of characters 'A', 'B', 'C', and 'D'. The scientist has a hypothesis that the cultures follow a specific pattern to mutate over time. Specifically, she suspects that each string is derived...
def find_core_string(cycle): n = len(cycle) m = len(cycle[0]) for i in range(n): candidate = list(cycle[i]) valid = True for j in range(m): original_char = candidate[j] mismatch_count = 0 for k in range(n): ...
from solution import solve def test_single_experiment_positive(): t = 1 experiments = [ ["ABCD", "ABCE", "ABCF"] ] assert solve(t, experiments) == ["ABCD"] def test_single_experiment_negative(): t = 1 experiments = [ ["ABCD", "ABDC"] ] assert solve(t, experiments) == [-...
[ { "docstring": null, "function_declaration": "def find_core_string(cycle):", "function_name": "find_core_string", "parameter_list": "(cycle)" }, { "docstring": null, "function_declaration": "def solve(t, experiments):", "function_name": "solve", "parameter_list": "(t, experiments...
[ 0, 0, 0, 0, 0, 1, 1, 1, 0, 0 ]
3
hard
0.3
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def find_core_string(t, cycles):\n results = []\n for cycle in cycles:\n n, strings = cycle\n \n m = len(strings[0])\n \n...
trial_gpt4o_7
{ "original_instruction": "", "prompt_id": "00022953", "row_id": 22953, "seed_ids": "[1106]" }
0.651818
Code_Contests_22953
I
[ "find_core_string", "solve" ]
2
[ [ "solve", "find_core_string" ] ]
1
[]
false
[]
false
pytest
true
[]
true
868933f7f601f31a9325134e38ae265dfab2c5aa
f04f66fa671fb87571316578a6d7144fc155aeb9
v1.0
instruct
Code_Contests
Code_Contests_23010_I
You are given a string s composed of lowercase alphabetic characters and a digit x. Your task is to shift each character in the string s forward in the alphabet by a number of positions equal to the digit x. If the shift exceeds 'z', it should wrap around to 'a'. Input The input consists of a single line containing t...
def shift_string(s, x): """ Shifts each character in the string s forward in the alphabet by a number of positions equal to the digit x. If the shift exceeds 'z', it wraps around to 'a'. """ x = int(x) shifted_string = [] for char in s: shifted_char = chr((ord(char) - ord('a') + x) ...
from solution import transform_input def test_shift_string_example_1(): assert transform_input("abc 2") == "cde" def test_shift_string_example_2(): assert transform_input("xyz 3") == "abc" def test_shift_string_full_cycle(): assert transform_input("abc 26") == "abc" def test_shift_string_no_shift(): ...
[ { "docstring": "Shifts each character in the string s forward in the alphabet by a number of positions equal to the digit x.\nIf the shift exceeds 'z', it wraps around to 'a'.", "function_declaration": "def shift_string(s, x):", "function_name": "shift_string", "parameter_list": "(s, x)" }, { ...
[ 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 shift_string(s, x):\n \"\"\"\n Shifts each character in the string s forward in the alphabet by a number of positions equal to the digit x.\n ...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00023010", "row_id": 23010, "seed_ids": "[5573]" }
0.737408
Code_Contests_23010
I
[ "shift_string", "transform_input" ]
2
[ [ "transform_input", "shift_string" ] ]
1
[]
false
[]
false
pytest
true
[]
true
270181298c6f763e797c642a29e6368bf8b3ef1c
cb8d1add18187082f6c24e79db6b6ef0b201d272
v1.0
instruct
Code_Contests
Code_Contests_23091_I
Imagine you are writing an algorithm for an online marketplace to manage the pricing of products over time to maximize revenue. The marketplace has a set of products, each with a specific price elasticity of demand. The price elasticity of demand (e) is a measure of how the quantity demanded of a product changes in res...
def calculate_max_revenue(initial_price, elasticity): """ Calculate the maximum possible revenue for a product given its initial price and price elasticity of demand. """ if elasticity > 0: # Elastic demand return round(max(2 * initial_price, initial_price), 2) else: # Inelastic deman...
from solution import maximize_revenues def test_maximize_revenues_case_1(): n = 2 product_info = [(100, 1.5), (200, -0.5)] result = maximize_revenues(n, product_info) assert result == [200.0, 400.0] def test_maximize_revenues_case_2(): n = 3 product_info = [(50, 0.8), (150, 1.2), (300, -0....
[ { "docstring": "Calculate the maximum possible revenue for a product given its \ninitial price and price elasticity of demand.", "function_declaration": "def calculate_max_revenue(initial_price, elasticity):", "function_name": "calculate_max_revenue", "parameter_list": "(initial_price, elasticity)" ...
[ 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 calculate_max_revenue(prices, elasticities):\n \"\"\"\n Calculate the maximum possible revenue for each product\n\n :param prices: List of ini...
trial_gpt4o_3
{ "original_instruction": "", "prompt_id": "00023091", "row_id": 23091, "seed_ids": "[7124]" }
0.603515
Code_Contests_23091
I
[ "calculate_max_revenue", "maximize_revenues" ]
2
[ [ "maximize_revenues", "calculate_max_revenue" ] ]
1
[]
false
[]
false
pytest
true
[]
true
5eeb688636f6c6fda7d153f96a1ada99bb55a3ac
860785f4ee3c26bbadc9a96aeb5e8db2309662f0
v1.0
instruct
Code_Contests
Code_Contests_23150_I
A company has several departments, each having a certain number of employees, as well as a designated manager. Each employee has a unique ID number ranging from 0 to n-1. The higher the level of the employee, the lower their ID number, i.e., managers will always have lower ID numbers than their subordinates within the ...
def check_departments(n, d, departments): for dep in departments: manager_id, employee_ids = dep[0], dep[1:] if manager_id != min(employee_ids): return "NO" return "YES" def validate_departments(n, d, departments): """ Validates if the given departments data follows the cons...
def test_validate_departments_example_1(): n, d = 6, 2 departments = [(0, 0, 1, 2), (3, 3, 4, 5)] assert validate_departments(n, d, departments) == "YES" def test_validate_departments_example_2(): n, d = 5, 2 departments = [(1, 1, 2, 3), (4, 4, 0)] assert validate_departments(n, d, departments)...
[ { "docstring": null, "function_declaration": "def check_departments(n, d, departments):", "function_name": "check_departments", "parameter_list": "(n, d, departments)" }, { "docstring": "Validates if the given departments data follows the constraints mentioned:\n- The manager's ID is the sma...
[ 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_valid_structure(n, d, departments):\n \"\"\"\n Verifies if the data structure follows the constraints:\n - The manager's ID is the smallest...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00023150", "row_id": 23150, "seed_ids": "[5046]" }
0.635406
Code_Contests_23150
I
[ "check_departments", "validate_departments" ]
2
[ [ "validate_departments", "check_departments" ] ]
1
[]
false
[]
false
pytest
false
[]
true
4ff6d591afffb2fa48b10064c923cad5226b100f
e19b0f95efc895d8f611a0caa99aa05c05e1c847
v1.0
instruct
Code_Contests
Code_Contests_23194_I
**Lazy Bartender's Challenge** Bartender, a fan of efficient serving, has an interesting dilemma. There exist `n` different drinks at his bar and `m` regulars at his bar, each having a distinct drink preference. Each regular requests only a single drink, but the bartender sometimes must compromise due to limited resou...
from itertools import combinations def minimize_drinks(n, preferences): all_drinks = set() for pref in preferences: all_drinks.update(pref) # Check each combination of drink sets starting from size 1 to size n for size in range(1, n + 1): for combo in combinations(all_drinks, size): ...
from solution import lazy_bartender def test_example_1(): n = 4 m = 3 preferences = [(1, 2), (2, 3), (3, 4)] assert lazy_bartender(n, m, preferences) == 2 def test_example_2(): n = 5 m = 5 preferences = [(1, 2), (2, 3), (3, 4), (4, 5), (5, 1)] assert lazy_bartender(n, m, preferences) =...
[ { "docstring": null, "function_declaration": "def minimize_drinks(n, preferences):", "function_name": "minimize_drinks", "parameter_list": "(n, preferences)" }, { "docstring": null, "function_declaration": "def lazy_bartender(n, m, preferences):", "function_name": "lazy_bartender", ...
[ 1, 0, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "from itertools import combinations\n\ndef minimize_drinks(n, preferences):\n all_drinks = set()\n for pref in preferences:\n all_drinks.update...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00023194", "row_id": 23194, "seed_ids": "[1485]" }
0.643839
Code_Contests_23194
I
[ "minimize_drinks", "lazy_bartender" ]
2
[ [ "lazy_bartender", "minimize_drinks" ] ]
1
[]
false
[]
false
pytest
true
[]
true
c0d0cd26366b0ad978661215bb19efe945235d49
f04d02ecb2267ac609982efca5d0fc2445117ad6
v1.0
instruct
Code_Contests
Code_Contests_23283_I
Given a directed, weighted graph G. Each node represents a city, and each edge represents a direct road connecting two cities with a certain travel cost. Your task is to determine the shortest path from a starting city s to a destination city d. You need to return the minimum travel cost if there is a valid path, or -1...
import heapq def dijkstra(n, graph, start, end): """ Uses Dijkstra's algorithm to find the shortest path in a directed, weighted graph. """ # Initialize distances and priority queue dist = [float('inf')] * (n + 1) dist[start] = 0 pq = [(0, start)] # (cost, node) while pq: ...
import pytest from solution import find_shortest_path def test_example_case(): n = 5 m = 6 edges = [ (1, 2, 2), (1, 3, 4), (2, 3, 1), (3, 4, 7), (2, 4, 5), (4, 5, 1) ] s = 1 d = 5 assert find_shortest_path(n, m, edges, s, d) == 8 def test_no_...
[ { "docstring": "Uses Dijkstra's algorithm to find the shortest path in a directed, weighted graph.", "function_declaration": "def dijkstra(n, graph, start, end):", "function_name": "dijkstra", "parameter_list": "(n, graph, start, end)" }, { "docstring": "Constructs the graph and finds the sh...
[ 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 heapq\n\ndef dijkstra(n, edges, s, d):\n # Creating the adjacency list for the graph\n graph = {i: [] for i in range(1, n+1)}\n for u, v, w...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00023283", "row_id": 23283, "seed_ids": "[636]" }
0.798419
Code_Contests_23283
I
[ "dijkstra", "find_shortest_path" ]
2
[ [ "find_shortest_path", "dijkstra" ] ]
1
[]
false
[]
false
pytest
true
[]
true
0076a43862e4a4731a0c821be0903e78e66fa11f
c7d1d0cf77af96ef372036b573981561fdf74867
v1.0
instruct
Code_Contests
Code_Contests_23335_I
Hermione Granger and Ron Weasley are in a competition to solve a special type of sequence problem. Professor McGonagall has given them a task to test their understanding of number sequences and prime numbers. The task is as follows: You need to define a sequence P as follows: P(0) = 2 P(1) = 3 For each n > 1, P(n) ...
import itertools def generate_primes(): """Generate an infinite sequence of prime numbers.""" # Sieve of Eratosthenes implementation D = {} q = 2 while True: if q not in D: yield q D[q * q] = [q] else: for p in D[q]: D.setdefault(p...
from solution import process_queries def test_example_cases(): assert process_queries([1, 2, 3, 4, 5]) == [2, 5, 10, 17, 28] def test_single_case(): assert process_queries([1]) == [2] def test_multiple_cases(): assert process_queries([1, 10, 3, 5]) == [2, 129, 10, 28] def test_large_input(): # Not p...
[ { "docstring": "Generate an infinite sequence of prime numbers.", "function_declaration": "def generate_primes():", "function_name": "generate_primes", "parameter_list": "()" }, { "docstring": "Return the sum of the first x elements of the prime sequence P.", "function_declaration": "def...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(num):\n if num <= 1:\n return False\n if num <= 3:\n return True\n if num % 2 == 0 or num % 3 == 0:\n return Fal...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00023335", "row_id": 23335, "seed_ids": "[174]" }
0.589954
Code_Contests_23335
I
[ "generate_primes", "Q", "process_queries" ]
3
[ [ "process_queries", "Q" ] ]
1
[ "process_queries" ]
false
[]
false
pytest
true
[]
true
f9dc97332aa177b2a60e57bcdb1e0c4b30c7755f
779d0248d9713bd3095a001b5df7bfe2c7c43868
v1.0
instruct
Code_Contests
Code_Contests_23340_I
You are given a string of characters that represent an encoded message. The encoding mechanism works by shifting each character in the message a certain number of places down the Unicode table. We call this the "shift value." For example, if the shift value is 2, 'a' becomes 'c', 'b' becomes 'd', and 'z' would wrap aro...
def shift_char(c, shift): if c.isalpha(): base = ord('a') if c.islower() else ord('A') return chr((ord(c) - base + shift) % 26 + base) return c def process_message(directive, shift_value, message): if directive == "DECODE": shift_value = -shift_value return ''.join(shift_char(c,...
from solution import process_input, process_message def test_process_message(): assert process_message("ENCODE", 2, "Hello, World!") == "Jgnnq, Yqtnf!" assert process_message("DECODE", 2, "Jgnnq, Yqtnf!") == "Hello, World!" assert process_message("ENCODE", -2, "Jgnnq, Yqtnf!") == "Hello, World!" assert...
[ { "docstring": null, "function_declaration": "def shift_char(c, shift):", "function_name": "shift_char", "parameter_list": "(c, shift)" }, { "docstring": null, "function_declaration": "def process_message(directive, shift_value, message):", "function_name": "process_message", "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": "def shift_character(c, shift):\n if 'a' <= c <= 'z':\n return chr((ord(c) - ord('a') + shift) % 26 + ord('a'))\n elif 'A' <= c <= 'Z':\n ...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00023340", "row_id": 23340, "seed_ids": "[6761]" }
0.69585
Code_Contests_23340
I
[ "shift_char", "process_message", "process_input" ]
3
[ [ "process_input", "process_message" ], [ "process_message", "shift_char" ] ]
2
[ "process_input" ]
false
[]
false
pytest
true
[]
true
1c09c72894d631fdfb6d26e44426f234ef6a76ab
155edc0e1bf35d8c16fdddc5c410021697c8d6f2
v1.0
instruct
Code_Contests
Code_Contests_23343_I
You are given a matrix with n rows and m columns containing only 0s and 1s. A subrectangle of this matrix is any contiguous subgrid with all values being 1. The task is to find the area of the largest subrectangle in the matrix containing only 1s. Input The first line contains two integers, n and m (1 ≤ n, m ≤ 100), ...
def max_rectangle_area(matrix): if not matrix: return 0 n = len(matrix) m = len(matrix[0]) heights = [0] * (m + 1) max_area = 0 for row in matrix: for i in range(m): if row[i] == 1: heights[i] += 1 else: heights[i...
from solution import largest_subrectangle_area def test_example_1(): n, m = 4, 5 matrix = [ [1, 0, 1, 0, 0], [1, 0, 1, 1, 1], [1, 1, 1, 1, 1], [1, 0, 0, 1, 0] ] assert largest_subrectangle_area(n, m, matrix) == 6 def test_example_2(): n, m = 3, 3 matrix = [ ...
[ { "docstring": null, "function_declaration": "def max_rectangle_area(matrix):", "function_name": "max_rectangle_area", "parameter_list": "(matrix)" }, { "docstring": null, "function_declaration": "def largest_subrectangle_area(n, m, matrix):", "function_name": "largest_subrectangle_a...
[ 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 maximalRectangle(matrix):\n \"\"\"\n Given a 2D binary matrix filled with 0's and 1's, find the area of the largest rectangle containing only 1's...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00023343", "row_id": 23343, "seed_ids": "[873]" }
0.618094
Code_Contests_23343
I
[ "max_rectangle_area", "largest_subrectangle_area" ]
2
[ [ "largest_subrectangle_area", "max_rectangle_area" ] ]
1
[]
false
[]
false
pytest
true
[]
true
abe763ae2b93b51770b926759a70cba35d0fca4d
ac7695550d1c50458dccd2408e0c2dd25292e687
v1.0
instruct
Code_Contests
Code_Contests_23392_I
Emily is learning about tree structures and their properties. She came across the concept of node distances and wants to write a program to calculate the longest distance between any two nodes in a tree. A tree is an undirected, connected, acyclic graph with n nodes and n-1 edges. The distance between any two nodes in...
def find_farthest_node(adj_list, start): from collections import deque n = len(adj_list) visited = [False] * n distance = [0] * n queue = deque([start]) visited[start] = True farthest_node = start while queue: node = queue.popleft() for neighbor in adj_list[node]: ...
def test_tree_diameter(): assert tree_diameter(5, [(1, 2), (1, 3), (2, 4), (2, 5)]) == 3 assert tree_diameter(3, [(1, 2), (2, 3)]) == 2 assert tree_diameter(1, []) == 0 assert tree_diameter(2, [(1, 2)]) == 1 def test_tree_diameter_large(): assert tree_diameter(6, [(1, 2), (2, 3), (3, 4), (4, 5), (5...
[ { "docstring": null, "function_declaration": "def find_farthest_node(adj_list, start):", "function_name": "find_farthest_node", "parameter_list": "(adj_list, start)" }, { "docstring": null, "function_declaration": "def tree_diameter(n, edges):", "function_name": "tree_diameter", ...
[ 0, 0, 1 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "from collections import deque, defaultdict\n\ndef find_furthest_node(start_node, graph):\n visited = set()\n queue = deque([(start_node, 0)])\n fu...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00023392", "row_id": 23392, "seed_ids": "[145]" }
0.678061
Code_Contests_23392
I
[ "find_farthest_node", "tree_diameter" ]
2
[ [ "tree_diameter", "find_farthest_node" ] ]
1
[]
false
[]
false
pytest
false
[]
true
2842b6365a38be95c1c6537af21def90d81d4c3f
d1b30f683251d89455ed53e96fb3c9a76b33b042
v1.0
instruct
Code_Contests
Code_Contests_23465_I
You are given a directed weighted graph with n vertices and m edges. The weights of the edges can be any positive integer. You are also given two integers s and t representing the starting and ending vertices respectively. Your task is to find the shortest path from vertex s to vertex t. Input The first line of the i...
import heapq def dijkstra(graph, start, end): """ Finds the shortest path in a weighted directed graph using Dijkstra's algorithm. """ pq = [(0, start)] distances = {start: 0} while pq: current_distance, current_vertex = heapq.heappop(pq) if current_vertex == end: ...
def test_no_mandatory_stops(): n, m, k = 5, 5, 0 edges = [ (1, 2, 2), (2, 3, 2), (3, 4, 2), (4, 5, 2), (1, 5, 10) ] mandatory_stops = [] s, t = 1, 5 assert shortest_path(n, m, k, edges, mandatory_stops, s, t) == 8 def test_with_mandatory_stops(): n, m...
[ { "docstring": "Finds the shortest path in a weighted directed graph using Dijkstra's algorithm.", "function_declaration": "def dijkstra(graph, start, end):", "function_name": "dijkstra", "parameter_list": "(graph, start, end)" }, { "docstring": "Builds a graph from a list of edges.", "f...
[ 0, 0, 0, 0, 0, 1, 0, 1, 0, 1 ]
3
hard
0.3
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "import heapq\nfrom collections import defaultdict\n\ndef dijkstra(graph, start):\n distances = {vertex: float('infinity') for vertex in graph}\n dist...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00023465", "row_id": 23465, "seed_ids": "[7860]" }
0.849423
Code_Contests_23465
I
[ "dijkstra", "build_graph", "shortest_path" ]
3
[ [ "shortest_path", "build_graph" ], [ "shortest_path", "dijkstra" ] ]
2
[]
false
[]
false
pytest
false
[]
true
f597f18e87de1e49ea2db3c1a17de6210dc37ccf
ed6d1eaac91ae8c60e2c29b98dff78aab0fec13f
v1.0
instruct
Code_Contests
Code_Contests_23481_I
Alyssa is fascinated by palindromes and wants to find out how many different ways she can split a given string `s` into palindromic substrings. A palindrome is a string that reads the same forward and backward. Alyssa wants to split the string in such a way that every substring in the split is a palindrome. Two split...
def is_palindrome(s): return s == s[::-1] def palindromic_splits_helper(s, memo): if s in memo: return memo[s] if not s: return 1 total_splits = 0 for i in range(1, len(s) + 1): if is_palindrome(s[:i]): total_splits += palindromic_splits_helper(s[i:], memo) ...
from solution import palindromic_splits def test_single_case_aab(): assert palindromic_splits(1, ["aab"]) == [2] def test_single_case_aaa(): assert palindromic_splits(1, ["aaa"]) == [4] def test_single_case_abc(): assert palindromic_splits(1, ["abc"]) == [1] def test_multiple_cases(): assert palindr...
[ { "docstring": null, "function_declaration": "def is_palindrome(s):", "function_name": "is_palindrome", "parameter_list": "(s)" }, { "docstring": null, "function_declaration": "def palindromic_splits_helper(s, memo):", "function_name": "palindromic_splits_helper", "parameter_list...
[ 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 count_palindrome_splits(s):\n \"\"\"\n Returns the number of ways to split string s into distinct palindromic substrings.\n \"\"\"\n n = le...
trial_gpt4o_3
{ "original_instruction": "", "prompt_id": "00023481", "row_id": 23481, "seed_ids": "[2646]" }
0.758824
Code_Contests_23481
I
[ "is_palindrome", "palindromic_splits_helper", "palindromic_splits" ]
3
[ [ "palindromic_splits", "palindromic_splits_helper" ], [ "palindromic_splits_helper", "is_palindrome" ] ]
2
[]
false
[]
false
pytest
true
[]
true
7c75bc7a3af4aef5d84e7e5a0d52b9a161ce2c79
b1f41f66ee7ef6af08b1a7cf4479309f367e5722
v1.0
instruct
Code_Contests
Code_Contests_23495_I
Write a program that reads a single integer N (1 ≤ N ≤ 10000) and prints all the prime numbers from 1 to N (inclusive). Constraints * 1 ≤ N ≤ 10000 Input The input consists of a single integer N. Output For each prime number from 1 to N, print the prime number on a new line. Example Input 10 Output 2 3 5 7
def is_prime(num): """ Check if a number is a 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 ...
from solution import is_prime, find_primes_up_to_n def test_is_prime(): assert is_prime(1) == False assert is_prime(2) == True assert is_prime(3) == True assert is_prime(4) == False assert is_prime(5) == True def test_find_primes_up_to_10(): assert find_primes_up_to_n(10) == [2, 3, 5, 7] def ...
[ { "docstring": "Check if a number is a prime.", "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": "Returns a list of all prime numbers from 1 to N (inclusive).", "function_declaration": "def find_primes_up_to_n(N):", ...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(n):\n \"\"\"\n Check if a number is prime.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return True\n i...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00023495", "row_id": 23495, "seed_ids": "[12391]" }
0.640592
Code_Contests_23495
I
[ "is_prime", "find_primes_up_to_n" ]
2
[ [ "find_primes_up_to_n", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
9185873aaece78309f357122ec22879d46464ccd
fc5aa4989e8d55fb1a3ce4f9b12a31a5e5c35144
v1.0
instruct
Code_Contests
Code_Contests_23608_I
In a rectangular garden, there are m rows and n columns of plants. Each plant can either grow flowers or vegetables. The gardener wants to arrange the garden such that each row contains only one type of plant (all flowers or all vegetables) and each column contains only one type of plant. Additionally, the gardener pre...
def garden_arrangement(m, n, constraints): garden = [[-1 for _ in range(n)] for _ in range(m)] # Fill in the constraints for (i, j, t) in constraints: garden[i-1][j-1] = t # Check if the constraints lead to a contradiction for i in range(m): for j in range(n): i...
from solution import garden_arrangement, solve, parse_input, format_output def test_garden_arrangement_no(): assert garden_arrangement(3, 3, [(1, 1, 0), (1, 2, 0)]) == "NO" def test_garden_arrangement_yes(): assert garden_arrangement(3, 3, [(1, 1, 0), (3, 3, 1)])[0] == "YES" assert garden_arrangement(4, 4...
[ { "docstring": null, "function_declaration": "def garden_arrangement(m, n, constraints):", "function_name": "garden_arrangement", "parameter_list": "(m, n, constraints)" }, { "docstring": null, "function_declaration": "def solve(k, cases):", "function_name": "solve", "parameter_l...
[ 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 garden_arrangement(m, n, requirements):\n # Create an initial garden with -1 (undecided)\n garden = [[-1 for _ in range(n)] for _ in range(m)]\n ...
trial_gpt4o_4
{ "original_instruction": "", "prompt_id": "00023608", "row_id": 23608, "seed_ids": "[4717]" }
0.721229
Code_Contests_23608
I
[ "garden_arrangement", "solve", "parse_input", "format_output" ]
4
[ [ "solve", "garden_arrangement" ] ]
1
[ "parse_input", "format_output" ]
false
[]
false
pytest
true
[]
true
b8588ecdfb5a6715e0644ac7dc59fd234d11c875
b530e59e869ae72cbfdd4cbc75154c64714d4b0b
v1.0
instruct
Code_Contests
Code_Contests_23617_I
You are given an N x N grid with non-negative integers in each cell. Your objective is to find a path from the top-left corner (0, 0) to the bottom-right corner (N-1, N-1) such that the sum of the values of the cells on the path is minimized. You can only move right or down at each step. Each test case consists of a s...
def min_path_sum(grid): """ Function to compute the minimum path sum in a given grid. Parameters: grid (list of list): NxN grid of non-negative integers. Returns: int: The minimum path sum from the top-left corner to the bottom-right corner. """ N = len(grid) # Initialize a...
def test_min_path_sum(): grid1 = [ [1, 3, 1], [1, 5, 1], [4, 2, 1] ] assert min_path_sum(grid1) == 7 grid2 = [ [1, 2], [1, 1] ] assert min_path_sum(grid2) == 3 grid3 = [ [0, 0, 0], [0, 0, 0], [0, 0, 0] ] assert min...
[ { "docstring": "Function to compute the minimum path sum in a given grid.\n\nParameters:\ngrid (list of list): NxN grid of non-negative integers.\n\nReturns:\nint: The minimum path sum from the top-left corner to the bottom-right corner.", "function_declaration": "def min_path_sum(grid):", "function_nam...
[ 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 min_path_sum(grid):\n n = len(grid)\n dp = [[0] * n for _ in range(n)]\n \n dp[0][0] = grid[0][0]\n \n # Initialize the first row of ...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00023617", "row_id": 23617, "seed_ids": "[5399]" }
0.725245
Code_Contests_23617
I
[ "min_path_sum", "read_input_and_find_min_path" ]
2
[ [ "read_input_and_find_min_path", "min_path_sum" ] ]
1
[]
false
[]
false
pytest
false
[]
true
a97a80defdc0f65d1e706d928004607c59573a21
79b542ab8d0e627917b71083a2851a0c432be16c
v1.0
instruct
Code_Contests
Code_Contests_23623_I
Emma is a renowned mathematician who is fascinated by sequences and prime numbers. She stumbled upon a sequence problem and needs your help to solve it. You need to develop an algorithm that finds a special sum of a sequence based on a specific condition. Given a sequence of integers and a positive integer m, you are ...
def is_prime(num): if num <= 1: return False if num <= 3: return True if num % 2 == 0 or num % 3 == 0: return False i = 5 while i * i <= num: if num % i == 0 or num % (i + 2) == 0: return False i += 6 return True def sum_of_m_largest_primes(se...
from solution import is_prime, sum_of_m_largest_primes 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 assert is_prime(0) == False assert is_prime(18...
[ { "docstring": null, "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": null, "function_declaration": "def sum_of_m_largest_primes(sequence, m):", "function_name": "sum_of_m_largest_primes", "parameter_list": "(s...
[ 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 is_prime(n):\n \"\"\"\n Check if a number is prime.\n \"\"\"\n if n <= 1:\n return False\n if n == 2:\n return True\n i...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00023623", "row_id": 23623, "seed_ids": "[12145]" }
0.627498
Code_Contests_23623
I
[ "is_prime", "sum_of_m_largest_primes" ]
2
[ [ "sum_of_m_largest_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
544b26765df0a6687f7370febe87b8e83e79e130
77a55e8715206d15daca961351e45b1a304f7b8f
v1.0
instruct
Code_Contests
Code_Contests_23632_I
Two friends, Charlie and Dana, are playing a card game using a deck of N cards numbered from 1 to N. They take turns drawing cards from the top of the deck. Charlie always goes first, and after that, they alternate turns. On their turn, a player can draw either one card or two consecutive cards from the top of the de...
def who_wins_game(n): """ Determine the winner of the card game with n cards. Charlie wins if n % 3 != 0. Dana wins if n % 3 == 0. """ if n % 3 == 0: return "Dana" else: return "Charlie" def determine_winners(test_cases): results = [] for n in test_cases: ...
from solution import who_wins_game, determine_winners, process_input_output def test_who_wins_game(): assert who_wins_game(1) == "Charlie" assert who_wins_game(2) == "Charlie" assert who_wins_game(3) == "Dana" assert who_wins_game(4) == "Charlie" assert who_wins_game(5) == "Charlie" assert who_...
[ { "docstring": "Determine the winner of the card game with n cards.\n\nCharlie wins if n % 3 != 0.\nDana wins if n % 3 == 0.", "function_declaration": "def who_wins_game(n):", "function_name": "who_wins_game", "parameter_list": "(n)" }, { "docstring": null, "function_declaration": "def d...
[ 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 find_winner(n):\n \"\"\"\n Determines the winner of the game given N cards.\n Charlie wins if N % 3 != 0, otherwise Dana wins.\n \"\"\"\n ...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00023632", "row_id": 23632, "seed_ids": "[5175]" }
0.78394
Code_Contests_23632
I
[ "who_wins_game", "determine_winners", "process_input_output" ]
3
[ [ "determine_winners", "who_wins_game" ], [ "process_input_output", "determine_winners" ] ]
2
[ "process_input_output" ]
false
[]
false
pytest
true
[]
true
34f9eb105cabd237ce5c9c44bb772f672af29bac
8c9744f8ca5d19898468c81842a934d6606fab1f
v1.0
instruct
Code_Contests
Code_Contests_23659_I
Alice loves playing with arrays. She has an array of integers and she likes to modify it using multiple operations. The operations can be of three types: 1. "1 x y" — add y to the element at index x of the array. 2. "2 x y" — multiply the element at index x of the array by y. 3. "3 l r k" — find the k-th smallest elem...
def update_add(array, x, y): """ Add y to the element at index x-1 of the array. """ array[x-1] += y def update_multiply(array, x, y): """ Multiply the element at index x-1 of the array by y. """ array[x-1] *= y def find_kth_smallest(array, l, r, k): """ Find the k-th smallest ...
import pytest from solution import update_add, update_multiply, find_kth_smallest, process_operations def test_update_add(): arr = [5, 3, 8, 6, 2, 1] update_add(arr, 2, 2) assert arr == [5, 5, 8, 6, 2, 1] def test_update_multiply(): arr = [5, 3, 8, 6, 2, 1] update_add(arr, 2, 2) update_multipl...
[ { "docstring": "Add y to the element at index x-1 of the array.", "function_declaration": "def update_add(array, x, y):", "function_name": "update_add", "parameter_list": "(array, x, y)" }, { "docstring": "Multiply the element at index x-1 of the array by y.", "function_declaration": "de...
[ 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 update_add(array, x, y):\n \"\"\"\n Add y to the element at index x-1 of the array.\n \"\"\"\n array[x-1] += y\n\ndef update_multiply(array...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00023659", "row_id": 23659, "seed_ids": "[5741]" }
0.713333
Code_Contests_23659
I
[ "update_add", "update_multiply", "find_kth_smallest", "process_operations" ]
4
[ [ "process_operations", "find_kth_smallest" ], [ "process_operations", "update_add" ], [ "process_operations", "update_multiply" ] ]
3
[]
false
[]
false
pytest
true
[]
true
d9219efd338fa9f891ef29a14d79fd2ca884a089
0e062649187c08afa008e0b7f27d9687aa64baf0
v1.0
instruct
Code_Contests
Code_Contests_23724_I
Given an integer n, construct a balanced binary search tree with n nodes where each node has a unique value between 1 and n (inclusive). The tree should be printed in level-order traversal. Input The input contains a single integer n (1 ≤ n ≤ 100) — the number of nodes in the binary search tree. Output Print n line...
from collections import deque class TreeNode: def __init__(self, val=0, left=None, right=None): self.val = val self.left = left self.right = right def sortedArrayToBST(nums): if not nums: return None mid = len(nums) // 2 root = TreeNode(nums[mid]) root.left = s...
from solution import createBalancedBST def test_bst_with_3_nodes(): result = createBalancedBST(3) assert result == [2, 1, 3] def test_bst_with_5_nodes(): result = createBalancedBST(5) assert result == [3, 2, 5, 1, 4] def test_bst_with_1_node(): result = createBalancedBST(1) assert result == [...
[]
[ 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 deque\n\nclass TreeNode:\n def __init__(self, val=0, left=None, right=None):\n self.val = val\n self.left = left\n...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00023724", "row_id": 23724, "seed_ids": "[4830]" }
0.598182
Code_Contests_23724
I
[ "sortedArrayToBST", "levelOrderTraversal", "createBalancedBST" ]
3
[ [ "createBalancedBST", "levelOrderTraversal" ], [ "createBalancedBST", "sortedArrayToBST" ] ]
2
[]
false
[ "TreeNode" ]
true
pytest
true
[]
true
9c0ca254984dc2285e7cab9af18b5785d6bd7fc1
b623c99147a899027d55b22042c0284a6bcc36b3
v1.0
instruct
Code_Contests
Code_Contests_23766_I
Create a function that takes a single list of integers as input and returns a new list containing only the prime numbers from the original list. The function should also return the count of prime numbers found. ## Input format A single list containing integers, which may include negative numbers, zero, and positive nu...
def is_prime(n): if n <= 1: return False if n == 2: return True if n % 2 == 0: return False for i in range(3, int(n ** 0.5) + 1, 2): if n % i == 0: return False return True def find_primes(numbers): """ Returns a tuple containing a list of prime n...
from solution import find_primes def test_find_primes_example_case(): assert find_primes([-5, 0, 2, 3, 4, 5, 10, 11, 13, 16, 17]) == ([2, 3, 5, 11, 13, 17], 6) def test_find_primes_no_primes(): assert find_primes([-5, 0, 1, 4, 6, 8, 10]) == ([], 0) def test_find_primes_all_primes(): assert find_primes([2...
[ { "docstring": null, "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Returns a tuple containing a list of prime numbers found in the input list\nand the count of prime numbers.", "function_declaration": "def find_primes(...
[ 0, 1, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(n):\n \"\"\"\n Helper function to determine if a number is prime.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00023766", "row_id": 23766, "seed_ids": "[7807]" }
0.733982
Code_Contests_23766
I
[ "is_prime", "find_primes" ]
2
[ [ "find_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
239f10c6c8aade7eeacec12038a2afeaa5be3f4e
e445e1db9a468ea6c240f30c132e21855e724c4e
v1.0
instruct
Code_Contests
Code_Contests_23770_I
You are given a collection of cities connected by roads. Each road has an associated travel time. Your task is to determine the shortest time required to travel from a given starting city to a destination city. Input The first line contains two integers n (1 ≤ n ≤ 100) and m (0 ≤ m ≤ 10,000), where n is the number of...
import heapq def dijkstra(n, roads, s, d): # Build the graph graph = {i: [] for i in range(1, n + 1)} for u, v, t in roads: graph[u].append((v, t)) graph[v].append((u, t)) # Priority queue for Dijkstra's algorithm pq = [(0, s)] dist = {i: float('inf') for i in range(1, n + 1)} ...
from solution import shortest_travel_time def test_shortest_travel_time_example_1(): n = 5 m = 6 roads = [ (1, 2, 4), (2, 3, 1), (3, 4, 2), (4, 5, 5), (1, 3, 5), (3, 5, 3) ] s = 1 d = 5 assert shortest_travel_time(n, m, roads, s, d) == 8 def ...
[ { "docstring": null, "function_declaration": "def dijkstra(n, roads, s, d):", "function_name": "dijkstra", "parameter_list": "(n, roads, s, d)" }, { "docstring": null, "function_declaration": "def shortest_travel_time(n, m, roads, s, d):", "function_name": "shortest_travel_time", ...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "import heapq\n\ndef shortest_path_time(n, m, roads, s, d):\n graph = {i: [] for i in range(1, n+1)}\n \n for u, v, t in roads:\n graph[u].a...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00023770", "row_id": 23770, "seed_ids": "[2455]" }
0.826155
Code_Contests_23770
I
[ "dijkstra", "shortest_travel_time" ]
2
[ [ "shortest_travel_time", "dijkstra" ] ]
1
[]
false
[]
false
pytest
true
[]
true
8f64acadf6fbe3105b276bbc1431d9b18269ac7b
85be6c2befe97d4227b8df81b2131332e691537e
v1.0
instruct
Code_Contests
Code_Contests_23852_I
Anna is interested in palindrome numbers. A palindrome number is a number that reads the same backward as forward, like 121 or 1331. One day, she was given a task to check if a number is a palindrome and, if not, find the minimum number of digits she needs to add to the end of the number to make it a palindrome. Given...
def is_palindrome(s): """ Returns True if the given string s is a palindrome, False otherwise. """ return s == s[::-1] def min_digits_to_palindrome(n): """ Check if the number n is a palindrome. If not, find the minimum number of digits required to be added to the end of n to make it a ...
from solution import min_digits_to_palindrome def test_min_digits_to_palindrome_positive_palindrome(): assert min_digits_to_palindrome(121) == "YES" def test_min_digits_to_palindrome_non_palindrome(): assert min_digits_to_palindrome(123) == 2 def test_min_digits_to_palindrome_single_digit(): assert min_d...
[ { "docstring": "Returns True if the given string s is a palindrome, False otherwise.", "function_declaration": "def is_palindrome(s):", "function_name": "is_palindrome", "parameter_list": "(s)" }, { "docstring": "Check if the number n is a palindrome.\nIf not, find the minimum number of digi...
[ 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 the number n is a palindrome.\n \"\"\"\n str_n = str(n)\n return str_n == str_n[::-1]\n\ndef min_a...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00023852", "row_id": 23852, "seed_ids": "[11049]" }
0.819804
Code_Contests_23852
I
[ "is_palindrome", "min_digits_to_palindrome" ]
2
[ [ "min_digits_to_palindrome", "is_palindrome" ] ]
1
[]
false
[]
false
pytest
true
[]
true
0b6347f40d92aa657127bc3f354583b2c5b8c1f8
ad7091c33f6aac7af210d0e7e0d4e5ca8624cc78
v1.0
instruct
Code_Contests
Code_Contests_23878_I
Write a function to find the maximum subarray sum for a given array using the divide and conquer approach. The problem is to find the maximum sum of a contiguous subarray in an unbounded array (i.e., an array that can have both positive and negative integers). You need to implement the solution using the divide and co...
def max_crossing_sum(arr, low, mid, high): """ Find the maximum sum of the subarray that crosses the midpoint. """ left_sum = float('-inf') total = 0 for i in range(mid, low-1, -1): total += arr[i] if total > left_sum: left_sum = total right_sum = float('-inf') ...
from solution import find_maximum_subarray_sum def test_single_element(): assert find_maximum_subarray_sum([1]) == 1 assert find_maximum_subarray_sum([-1]) == -1 def test_all_negative(): assert find_maximum_subarray_sum([-2, -3, -1, -4]) == -1 def test_mixed_elements(): assert find_maximum_subarray_s...
[ { "docstring": "Find the maximum sum of the subarray that crosses the midpoint.", "function_declaration": "def max_crossing_sum(arr, low, mid, high):", "function_name": "max_crossing_sum", "parameter_list": "(arr, low, mid, high)" }, { "docstring": "Find the maximum sum of a contiguous subar...
[ 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_crossing_sum(arr, left, mid, right):\n \"\"\"\n Find the maximum possible sum in `arr` such that the sum includes\n elements on either sid...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00023878", "row_id": 23878, "seed_ids": "[6888]" }
0.781227
Code_Contests_23878
I
[ "max_crossing_sum", "max_subarray_sum", "find_maximum_subarray_sum" ]
3
[ [ "find_maximum_subarray_sum", "max_subarray_sum" ], [ "max_subarray_sum", "max_crossing_sum" ] ]
2
[]
false
[]
false
pytest
true
[]
true
65b3e99d01120fef42f2ea9a1750736ae6c4a5c5
1126a3f435e69c573b25e59f0386647bea718ec1
v1.0
instruct
Code_Contests
Code_Contests_23943_I
Create a program to find the longest common subsequence (LCS) of two given strings. The longest common subsequence is defined as the longest sequence that can be derived from both original strings by removing some characters (or none) without changing the order of the remaining characters. ### Input Format: - The firs...
def lcs_length(str1, str2): m = len(str1) n = len(str2) dp = [[0] * (n + 1) for _ in range(m + 1)] for i in range(1, m + 1): for j in range(1, n + 1): if str1[i - 1] == str2[j - 1]: dp[i][j] = dp[i - 1][j - 1] + 1 else: dp[i][j] = max(...
def test_lcs_length(): assert lcs_length("abcde", "ace") == 3 assert lcs_length("abc", "efgh") == 0 assert lcs_length("abcdef", "abcdef") == 6 assert lcs_length("aaaa", "aa") == 2 assert lcs_length("", "") == 0 def test_process_test_cases(): test_cases = [("abcde", "ace"), ("abc", "efgh")] ...
[ { "docstring": null, "function_declaration": "def lcs_length(str1, str2):", "function_name": "lcs_length", "parameter_list": "(str1, str2)" }, { "docstring": null, "function_declaration": "def process_test_cases(test_cases):", "function_name": "process_test_cases", "parameter_lis...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def lcs_length(str1, str2):\n \"\"\"\n Computes the length of the longest common subsequence (LCS) between two strings str1 and str2.\n \"\"\"\n ...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00023943", "row_id": 23943, "seed_ids": "[2782]" }
0.659321
Code_Contests_23943
I
[ "lcs_length", "process_test_cases", "longest_common_subsequence" ]
3
[ [ "longest_common_subsequence", "process_test_cases" ], [ "process_test_cases", "lcs_length" ] ]
2
[ "process_test_cases" ]
false
[]
false
pytest
false
[]
true
d67b2436efe82756a46b9b6640e351ce593bb877
5d6c4097bfba1cd376163d96e9e3de63aa5733fe
v1.0
instruct
Code_Contests
Code_Contests_23957_I
John is creating unique IDs for his new application. Each ID consists of lowercase Latin letters (a-z) and possibly special characters like underscores ('_') and digits (0-9). John wants to ensure that all IDs are valid and follow specific rules to maintain uniformity across his application. The rules for a valid ID a...
def is_valid_id(candidate): """ Check if the candidate ID meets all the rules: 1. Contains at least one lowercase Latin letter. 2. Does not contain consecutive underscores. 3. Does not start or end with an underscore. 4. Has length between 1 and 100 characters (inclusive). """ # Che...
from solution import is_valid_id, validate_ids def test_is_valid_id(): # Test valid cases assert is_valid_id("john_doe") == "YES" assert is_valid_id("valid_id123") == "YES" assert is_valid_id("a") == "YES" assert is_valid_id("a_b_c_d") == "YES" # Test invalid cases assert is_valid_id("...
[ { "docstring": "Check if the candidate ID meets all the rules:\n1. Contains at least one lowercase Latin letter.\n2. Does not contain consecutive underscores.\n3. Does not start or end with an underscore.\n4. Has length between 1 and 100 characters (inclusive).", "function_declaration": "def is_valid_id(can...
[ 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_valid_id(id_str):\n \"\"\"\n Checks if the given id_str is a valid ID based on the following rules:\n 1. It must have at least one lowercas...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00023957", "row_id": 23957, "seed_ids": "[4213]" }
0.666819
Code_Contests_23957
I
[ "is_valid_id", "validate_ids" ]
2
[ [ "validate_ids", "is_valid_id" ] ]
1
[]
false
[]
false
pytest
true
[]
true
99b0bfdadd0000567e816583b00b240bc9838b9d
bf546a3cfd83be796fbbc6b5a9da75bd002526c7
v1.0
instruct
Code_Contests
Code_Contests_24022_I
Arkady wants to monitor the water supply system in his garden. The water supply system can be represented as a weighted directed graph with n junctions (numbered from 1 to n) and m pipes connecting them. Each pipe from junction u to junction v has a capacity w, which is the maximum amount of water that can flow through...
import collections def bfs(C, F, source, sink, parent): visited = [False] * len(C) queue = collections.deque([source]) visited[source] = True while queue: u = queue.popleft() for v in range(len(C)): if not visited[v] and C[u][v] - F[u][v] > 0: queue.append(v)...
from solution import max_water_flow def test_example_case1(): num_junctions = 4 pipes = [ (1, 2, 10), (1, 3, 5), (2, 3, 15), (2, 4, 10), (3, 4, 10) ] queries = [ (1, 4), (2, 3), (3, 1) ] result = max_water_flow(num_junctions, pipes...
[ { "docstring": null, "function_declaration": "def bfs(C, F, source, sink, parent):", "function_name": "bfs", "parameter_list": "(C, F, source, sink, parent)" }, { "docstring": null, "function_declaration": "def edmonds_karp(C, source, sink):", "function_name": "edmonds_karp", "pa...
[ 0, 0, 0, 0, 1 ]
1
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "from collections import defaultdict, deque\n\ndef bfs(C, F, source, sink, parent):\n visited = set()\n queue = deque([source])\n visited.add(sourc...
trial_gpt4o_4
{ "original_instruction": "", "prompt_id": "00024022", "row_id": 24022, "seed_ids": "[1782]" }
0.683487
Code_Contests_24022
I
[ "bfs", "edmonds_karp", "max_water_flow" ]
3
[ [ "edmonds_karp", "bfs" ], [ "max_water_flow", "edmonds_karp" ] ]
2
[]
false
[]
false
pytest
true
[]
true
39716776c1535b8f0c232ebdbec440e3f1eaef33
75745f254632847a6814ac4ee29f7c9c126d3047
v1.0
instruct
Code_Contests
Code_Contests_24050_I
You are part of a team responsible for designing road networks. You need to select certain roads in such a way that the road network does not contain any cycles and has the maximum possible total length. You are given a list of roads, where each road connects two cities and has a certain length. Your task is to deter...
def find(parent, i): if parent[i] == i: return i else: return find(parent, parent[i]) def union(parent, rank, x, y): root_x = find(parent, x) root_y = find(parent, y) if rank[root_x] < rank[root_y]: parent[root_x] = root_y elif rank[root_x] > rank[root_y]: p...
def test_maximum_spanning_tree(): assert maximum_spanning_tree(4, [(0, 1, 3), (1, 2, 5), (2, 3, 6), (3, 0, 7), (1, 3, 4)]) == 18 assert maximum_spanning_tree(4, [(0, 1, 1), (1, 2, 1), (2, 3, 1)]) == 3 assert maximum_spanning_tree(2, [(0, 1, 10)]) == 10 assert maximum_spanning_tree(3, [(0, 1, 10), (1, 2,...
[ { "docstring": null, "function_declaration": "def find(parent, i):", "function_name": "find", "parameter_list": "(parent, i)" }, { "docstring": null, "function_declaration": "def union(parent, rank, x, y):", "function_name": "union", "parameter_list": "(parent, rank, x, y)" }, ...
[ 1, 0, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def find(parent, i):\n if parent[i] == i:\n return i\n else:\n return find(parent, parent[i])\n\ndef union(parent, rank, x, y):\n ro...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00024050", "row_id": 24050, "seed_ids": "[5366]" }
0.686003
Code_Contests_24050
I
[ "find", "union", "maximum_spanning_tree", "process_input" ]
4
[ [ "maximum_spanning_tree", "find" ], [ "maximum_spanning_tree", "union" ], [ "process_input", "maximum_spanning_tree" ], [ "union", "find" ] ]
4
[ "process_input" ]
false
[]
false
pytest
false
[]
true
748a8d87c9a01d7411566db7d20eda9c2ca5ae8a
ed505874bdb082a00e4065ca35dac7a42cf51e8b
v1.0
instruct
Code_Contests
Code_Contests_24076_I
**Question: Price Fluctuation Analysis** Alice is an analyst working for a stock trading company. Her task is to monitor the daily price changes of a particular stock for the past N days. Alice records a positive integer each day, representing the price change. A positive change indicates a price increase, while a neg...
def max_increase_and_decrease(prices): """ Returns the maximum increase and maximum decrease in stock prices within a contiguous subarray. """ max_increase = max_subarray_sum(prices) max_decrease = min_subarray_sum(prices) return max_increase, max_decrease def max_subarray_sum(arr): max...
from solution import max_increase_and_decrease, solve def test_case_1(): prices = [1, -2, 3, -4, 5] assert max_increase_and_decrease(prices) == (5, -4) def test_case_2(): prices = [-1, -1, -1, -1] assert max_increase_and_decrease(prices) == (-1, -4) def test_case_3(): prices = [2, -1, 2, 3, -1, 2...
[ { "docstring": "Returns the maximum increase and maximum decrease in stock prices\nwithin a contiguous subarray.", "function_declaration": "def max_increase_and_decrease(prices):", "function_name": "max_increase_and_decrease", "parameter_list": "(prices)" }, { "docstring": null, "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 max_increase_and_decrease(arr):\n def max_subarray_sum(nums):\n max_ending_here, max_so_far = float('-inf'), float('-inf')\n for x in ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00024076", "row_id": 24076, "seed_ids": "[11561]" }
0.613621
Code_Contests_24076
I
[ "max_increase_and_decrease", "max_subarray_sum", "min_subarray_sum", "solve" ]
4
[ [ "max_increase_and_decrease", "max_subarray_sum" ], [ "max_increase_and_decrease", "min_subarray_sum" ], [ "solve", "max_increase_and_decrease" ] ]
3
[]
false
[]
false
pytest
true
[]
true
bc982479aa2bfab6354bc16b3764872e590f14e4
3a6a1b03f00c3499cd27d2a226b9d4bcc2d474ad
v1.0
instruct
Code_Contests
Code_Contests_24080_I
Alice is an avid gardener and is particularly fond of growing flowerbeds. However, maintaining the flowerbeds in certain patterns is quite a task! Alice decides to automate the process using some programming magic. You are assigned to help Alice in the following problem: Alice has a rectangular garden of size m x n (...
def can_plant_flowers(m, n, garden): row_counts = [0] * m col_counts = [0] * n for i in range(m): for j in range(n): if garden[i][j] == '#': row_counts[i] += 1 col_counts[j] += 1 return sorted(row_counts) == sorted(col_counts) def garden_setup(m, n,...
from solution import garden_setup def test_example1(): m = 3 n = 3 garden = [ "#.#", ".#.", "#.#" ] assert garden_setup(m, n, garden) == "YES" def test_example2(): m = 4 n = 4 garden = [ "####", ".#..", "###.", "####" ] as...
[ { "docstring": null, "function_declaration": "def can_plant_flowers(m, n, garden):", "function_name": "can_plant_flowers", "parameter_list": "(m, n, garden)" }, { "docstring": null, "function_declaration": "def garden_setup(m, n, garden):", "function_name": "garden_setup", "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 can_plant_flowers(m, n, garden):\n row_counts = [0] * m\n col_counts = [0] * n\n\n for i in range(m):\n for j in range(n):\n ...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00024080", "row_id": 24080, "seed_ids": "[9011]" }
0.736452
Code_Contests_24080
I
[ "can_plant_flowers", "garden_setup" ]
2
[ [ "garden_setup", "can_plant_flowers" ] ]
1
[]
false
[]
false
pytest
true
[]
true
8de61ac9aa94eaaf81fd86c769967610303051d3
ccd2ea0f6e2b27457140591788223357452400d4
v1.0
instruct
Code_Contests
Code_Contests_24129_I
In a forest there are n different types of trees, labeled from 1 to n. Each tree type has a fixed height, and exactly one tree of each type exists in the forest. You want to trim the forest such that only trees of certain heights remain in a contiguous segment from any given range [L, R] (1 ≤ L < R ≤ n). For a given q...
def preprocess_tree_heights(heights): """ Preprocess the tree heights to allow for efficient range maximum queries. """ n = len(heights) log_n = n.bit_length() dp = [[0] * log_n for _ in range(n)] for i in range(n): dp[i][0] = heights[i] j = 1 while (1 << j) <= n: ...
from solution import preprocess_tree_heights, query_max_in_range, solve def test_single_query(): heights = [2, 8, 3, 7, 4] dp = preprocess_tree_heights(heights) assert query_max_in_range(dp, 1, 3) == 8 assert query_max_in_range(dp, 2, 4) == 8 assert query_max_in_range(dp, 1, 5) == 8 def test_multi...
[ { "docstring": "Preprocess the tree heights to allow for efficient range maximum queries.", "function_declaration": "def preprocess_tree_heights(heights):", "function_name": "preprocess_tree_heights", "parameter_list": "(heights)" }, { "docstring": "Answer the range maximum query using the p...
[ 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 SegmentTree:\n def __init__(self, data):\n n = len(data)\n self.n = n\n self.tree = [0] * (2 * n)\n self.build(data)\n...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00024129", "row_id": 24129, "seed_ids": "[6103]" }
0.594078
Code_Contests_24129
I
[ "preprocess_tree_heights", "query_max_in_range", "solve" ]
3
[ [ "solve", "preprocess_tree_heights" ], [ "solve", "query_max_in_range" ] ]
2
[]
false
[]
false
pytest
true
[]
true
8583896a9ae2a1ddd994b4dafba53c0813d0c42b
4935eb25b72ca34b54c00272c66e42d62ae15558
v1.0
instruct
Code_Contests
Code_Contests_24188_I
Write a program that assists a librarian in sorting a collection of books. Each book in the collection has a title, an author, and a year of publication. You are required to sort the books primarily by the year of publication in ascending order. If two or more books are published in the same year, they should be sorte...
def sort_books(test_cases): result = [] for books in test_cases: sorted_books = sorted(books, key=lambda x: (x[2], x[1], x[0])) result.append(sorted_books) return result def process_input(input_data): lines = input_data.strip().split("\n") index = 0 T = int(lines[index]) ind...
from solution import librarian_program def test_case_1(): input_data = "2\n3\nWarAndPeace Tolstoy 1869\nPrideAndPrejudice Austen 1813\nAnnaKarenina Tolstoy 1877\n4\nTheGreatGatsby Fitzgerald 1925\nMobyDick Melville 1851\nTheCatchInTheRye Salinger 1951\nToKillAMockingbird Lee 1960" expected_output = "PrideAndPr...
[ { "docstring": null, "function_declaration": "def sort_books(test_cases):", "function_name": "sort_books", "parameter_list": "(test_cases)" }, { "docstring": null, "function_declaration": "def process_input(input_data):", "function_name": "process_input", "parameter_list": "(inpu...
[ 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 sort_books(T, cases):\n \"\"\"\n Sort the books according to the specified rules and return the sorted list for each test case.\n \"\"\"\n ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00024188", "row_id": 24188, "seed_ids": "[4068]" }
0.663822
Code_Contests_24188
I
[ "sort_books", "process_input", "format_output", "librarian_program" ]
4
[ [ "librarian_program", "format_output" ], [ "librarian_program", "process_input" ], [ "librarian_program", "sort_books" ] ]
3
[ "process_input", "format_output" ]
false
[]
false
pytest
true
[]
true
79c372604c7fd956a7e95a3a1dc28af8cdd991ff
c0ca2dfb1a30269c93efdf933bc33daae32858e5
v1.0
instruct
Code_Contests
Code_Contests_24205_I
Given an array of integers, determine if there exists a subset of the array whose sum is exactly equal to a given integer $S$. Constraints * $ 1 \leq n \leq 1000$ * $ 1 \leq a_i \leq 1000$ Input The input is given in the following format: $n$ $S$ $a_1$ $a_2$ $a_3$ $...$ $a_n$ Where * $n$ is the number of element...
def is_subset_sum_exists(n, S, array): """ Determines if there exists a subset of the array whose sum is exactly equal to S using dynamic programming. :param n: int, number of elements in the array :param S: int, target sum :param array: list of integers, elements of the array :return: str,...
def test_subset_sum_exists(): assert subset_sum_exists("5 9\n3 34 4 12 5 2") == "YES" assert subset_sum_exists("5 30\n3 34 4 12 5 2") == "NO" assert subset_sum_exists("6 10\n1 2 3 4 5 6") == "YES" assert subset_sum_exists("4 10\n10 10 10 10") == "YES" assert subset_sum_exists("4 25\n1 3 5 7") == "NO...
[ { "docstring": "Determines if there exists a subset of the array whose sum is exactly equal to S using dynamic programming.\n\n:param n: int, number of elements in the array\n:param S: int, target sum\n:param array: list of integers, elements of the array\n:return: str, \"YES\" if such a subset exists, \"NO\" o...
[ 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 subset_sum_exists(arr, target):\n \"\"\"\n Determine if there is a subset of 'arr' such that the sum of its elements is equal to 'target'.\n \...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00024205", "row_id": 24205, "seed_ids": "[2501]" }
0.686661
Code_Contests_24205
I
[ "is_subset_sum_exists", "subset_sum_exists" ]
2
[ [ "subset_sum_exists", "is_subset_sum_exists" ] ]
1
[]
false
[]
false
pytest
false
[]
true
d4fce5d1a14aa0394af3b105b681dd7f00976d9c
e41f838d29d3a28d9aa44ba323896813fa7b430d
v1.0
instruct
Code_Contests
Code_Contests_24225_I
In a distant galaxy, there is a highly secure vault protected by a series of magical locks. Each lock is controlled by a distinct key matrix. The key matrices are square matrices of integers, and two matrices \(A\) and \(B\) are deemed equivalent if one can be transformed into the other by rotating it 0, 90, 180, or 27...
def rotate_90_deg(matrix): """ Rotate the given NxN matrix by 90 degrees clockwise. """ n = len(matrix) return [[matrix[n - j - 1][i] for j in range(n)] for i in range(n)] def are_matrices_equivalent(n, A, B): """ Check if matrix B is equivalent to matrix A by rotating it 0, 90, 180, or 270...
from solution import are_matrices_equivalent def test_matrices_equivalent_example_1(): n = 2 A = [[1, 2], [3, 4]] B = [[4, 3], [2, 1]] assert are_matrices_equivalent(n, A, B) == "YES" def test_matrices_equivalent_example_2(): n = 3 A = [[1, 2, 3], [4, 5, 6], [7, 8, 9]] B = [[1, 2, 3], [6, ...
[ { "docstring": "Rotate the given NxN matrix by 90 degrees clockwise.", "function_declaration": "def rotate_90_deg(matrix):", "function_name": "rotate_90_deg", "parameter_list": "(matrix)" }, { "docstring": "Check if matrix B is equivalent to matrix A by rotating it 0, 90, 180, or 270 degrees...
[ 1, 1, 0 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def rotate_90(matrix):\n \"\"\"\n Rotates the given square matrix by 90 degrees clockwise.\n \"\"\"\n n = len(matrix)\n return [[matrix[n - ...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00024225", "row_id": 24225, "seed_ids": "[11714]" }
0.689393
Code_Contests_24225
I
[ "rotate_90_deg", "are_matrices_equivalent" ]
2
[ [ "are_matrices_equivalent", "rotate_90_deg" ] ]
1
[]
false
[]
false
pytest
true
[]
true
991a5bbd5205deb14c4f254bf73d992696dcb74f
d98f0e5006e3b64ff33a817204b92c7bdf750fb9
v1.0
instruct
Code_Contests
Code_Contests_24297_I
Professor Quantum is building a new encryption system based on a sequence of prime numbers. He defines an encoded message as the sum of the k-th powers of distinct prime numbers, where k is a given integer. Given an integer n, find the longest possible sequence of distinct prime numbers such that the sum of the k-th p...
def sieve_of_eratosthenes(limit): is_prime = [True] * (limit + 1) p = 2 while (p * p <= limit): if is_prime[p]: for i in range(p * p, limit + 1, p): is_prime[i] = False p += 1 prime_numbers = [] for p in range(2, limit + 1): if is_prime[p]: ...
from solution import find_longest_sequence def test_find_longest_sequence_case1(): result = find_longest_sequence(100, 2) assert set(result) == set([2, 3, 5, 7]) def test_find_longest_sequence_case2(): result = find_longest_sequence(500, 3) # Either [2, 3, 5] or [2, 11] are acceptable answers asse...
[ { "docstring": null, "function_declaration": "def sieve_of_eratosthenes(limit):", "function_name": "sieve_of_eratosthenes", "parameter_list": "(limit)" }, { "docstring": null, "function_declaration": "def find_longest_sequence(n, k):", "function_name": "find_longest_sequence", "p...
[ 0, 0, 0, 0, 0, 0, 0, 1, 1, 0 ]
2
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def sieve_of_eratosthenes(max_num):\n \"\"\"\n Implements the Sieve of Eratosthenes to find all prime numbers up to max_num.\n \"\"\"\n sieve =...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00024297", "row_id": 24297, "seed_ids": "[6140]" }
0.564014
Code_Contests_24297
I
[ "sieve_of_eratosthenes", "find_longest_sequence" ]
2
[ [ "find_longest_sequence", "sieve_of_eratosthenes" ] ]
1
[]
false
[]
false
pytest
true
[]
true
a9ee2fc4c8184ce13d10b4d7ab662bb35502dd1c
4633557a35fc076aa0a6209df411129b1bfff2d3
v1.0
instruct
Code_Contests
Code_Contests_24307_I
There is a city with n intersections and m bi-directional roads connecting these intersections. The city planning committee needs to ensure that it's still possible to travel between any two intersections even if one road needs to be closed for maintenance. To help them, you need to find out if there exists at least on...
import sys sys.setrecursionlimit(200000) def find_bridges(n, m, edges): from collections import defaultdict def dfs(node, parent, discovery, low, graph, visited, disc_time, bridges): visited[node] = True discovery[node] = low[node] = disc_time[0] disc_time[0] += 1 for neighbor...
def test_example_1(): n, m = 4, 5 roads = [ (1, 2), (2, 3), (2, 4), (3, 4), (4, 1) ] assert is_there_a_bridge(n, m, roads) == "NO" def test_example_2(): n, m = 4, 3 roads = [ (1, 2), (2, 3), (3, 4) ] assert is_there_a_bridg...
[ { "docstring": null, "function_declaration": "def find_bridges(n, m, edges):", "function_name": "find_bridges", "parameter_list": "(n, m, edges)" }, { "docstring": null, "function_declaration": "def is_there_a_bridge(n, m, roads):", "function_name": "is_there_a_bridge", "paramete...
[ 1, 0, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def find_bridges(n, m, edges):\n from collections import defaultdict\n \n graph = defaultdict(list)\n for u, v in edges:\n graph[u].appe...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00024307", "row_id": 24307, "seed_ids": "[9124]" }
0.688846
Code_Contests_24307
I
[ "find_bridges", "is_there_a_bridge" ]
2
[ [ "is_there_a_bridge", "find_bridges" ] ]
1
[]
false
[]
false
pytest
false
[]
true
1f3eb7f8f7333e7c96abe3714851ca19f5da4c8d
5d395e2fb640d66c3d431e9b19f0c7af945ba895
v1.0
instruct
Code_Contests
Code_Contests_24383_I
Alice likes to collect and arrange strings of the same length but wants them to look nice. A string looks "nice" if it is a palindrome or can be rearranged to form a palindrome. A palindrome is a string that reads the same forwards and backwards. Alice can swap any two characters in the string any number of times. G...
def can_form_palindrome(s): """ Check if a string can be rearranged to form a palindrome. """ from collections import Counter char_count = Counter(s) odd_count = sum(1 for count in char_count.values() if count % 2 != 0) return odd_count <= 1 def process_strings(t, strings): """ For ...
from solution import can_form_palindrome, process_strings def test_can_form_palindrome(): assert can_form_palindrome("aabb") == True assert can_form_palindrome("racecar") == True assert can_form_palindrome("abcd") == False assert can_form_palindrome("a") == True assert can_form_palindrome("abcdef")...
[ { "docstring": "Check if a string can be rearranged to form a palindrome.", "function_declaration": "def can_form_palindrome(s):", "function_name": "can_form_palindrome", "parameter_list": "(s)" }, { "docstring": "For multiple strings, determine if each can be rearranged to form a palindrome...
[ 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 can_be_rearranged_to_palindrome(s):\n \"\"\"\n Determine if a string can be rearranged to form a palindrome.\n \n A string can be rearrange...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00024383", "row_id": 24383, "seed_ids": "[1485]" }
0.802497
Code_Contests_24383
I
[ "can_form_palindrome", "process_strings" ]
2
[ [ "process_strings", "can_form_palindrome" ] ]
1
[]
false
[]
false
pytest
true
[]
true
424ab1c037301967e0a710839b0df2aeadb8456d
3769272f42518e5e2a9af4c382afb9145eb474b4
v1.0
instruct
Code_Contests
Code_Contests_24407_I
A simplified fraction is a fraction that is reduced to its simplest form. Given two positive integers, a numerator and a denominator of a fraction, return the simplified fraction. You can assume that the initial numerator and denominator are positive integers that do not exceed 1000. Input The input consists of multi...
def gcd(x, y): while y: x, y = y, x % y return x def simplify_fraction(numerator, denominator): gcd_value = gcd(numerator, denominator) return f"{numerator // gcd_value}/{denominator // gcd_value}" def process_fractions(input_data): results = [] for data in input_data.strip().split("\n...
import pytest from solution import simplify_fraction, process_fractions def test_gcd(): assert gcd(48, 18) == 6 assert gcd(8, 24) == 8 assert gcd(25, 100) == 25 def test_simplify_fraction(): assert simplify_fraction(8, 24) == "1/3" assert simplify_fraction(25, 100) == "1/4" assert simplify_fra...
[ { "docstring": null, "function_declaration": "def gcd(x, y):", "function_name": "gcd", "parameter_list": "(x, y)" }, { "docstring": null, "function_declaration": "def simplify_fraction(numerator, denominator):", "function_name": "simplify_fraction", "parameter_list": "(numerator,...
[ 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 sys\nfrom math import gcd\n\ndef simplify_fraction(numerator, denominator):\n \"\"\"\n Returns the simplified form of a fraction given the num...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00024407", "row_id": 24407, "seed_ids": "[7486]" }
0.593452
Code_Contests_24407
I
[ "gcd", "simplify_fraction", "process_fractions" ]
3
[ [ "process_fractions", "simplify_fraction" ], [ "simplify_fraction", "gcd" ] ]
2
[]
false
[]
false
pytest
true
[]
true
4a2d29d2860aaf93be0ce2e5cf37bc738647c90e
ec65de5fcf244388711b7df1d1f08e2c78a15c93
v1.0
instruct
Code_Contests
Code_Contests_24415_I
Given a set of $N$ axis-aligned rectangular plots, find the area of the largest rectangle that can be formed using one or multiple overlapping or touching plots. Constraints * $ 1 \leq N \leq 100000 $ * $ 0 \leq x1_i < x2_i \leq 1000 $ * $ 0 \leq y1_i < y2_i \leq 1000 $ * $ x1_i, y1_i, x2_i, y2_i$ are given in intege...
def largest_rectangle_area(rectangles): """ Calculate the area of the largest rectangle that can be formed using one or multiple overlapping or touching plots. :param rectangles: List of tuples (x1, y1, x2, y2) :return: The area of the largest rectangle """ if not rectangles: return ...
from solution import largest_rectangle_area def test_single_small_rectangle(): assert largest_rectangle_area([(0, 0, 2, 2)]) == 4 def test_multiple_overlapping_rectangles(): assert largest_rectangle_area([(0, 0, 3, 2), (2, 1, 4, 3)]) == 6 def test_multiple_adjacent_rectangles_horizontal(): assert largest...
[ { "docstring": "Calculate the area of the largest rectangle that can be formed\nusing one or multiple overlapping or touching plots.\n:param rectangles: List of tuples (x1, y1, x2, y2)\n:return: The area of the largest rectangle", "function_declaration": "def largest_rectangle_area(rectangles):", "funct...
[ 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 largest_rectangle_area(N, plots):\n # Create an empty grid of size 1001x1001\n grid = [[0] * 1001 for _ in range(1001)]\n \n # Fill the gri...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00024415", "row_id": 24415, "seed_ids": "[2501]" }
0.629549
Code_Contests_24415
I
[ "largest_rectangle_area", "largest_rectangle_in_histogram" ]
2
[ [ "largest_rectangle_area", "largest_rectangle_in_histogram" ] ]
1
[]
false
[]
false
pytest
true
[]
true
ad1477bd8c73e4ba1aa44009aa06c4dd25f4cf62
6046a267e705e90b80c84e7d6d0a0fb8d34fe6d5
v1.0
instruct
Code_Contests
Code_Contests_24424_I
Mihai loves prime numbers and recently came across an interesting problem. He wishes to find out the number of prime numbers that are less than or equal to a given number X. Being a Computer Science student, Mihai decided to write a program to solve this. The problem is defined as follows: Given an integer X, determi...
def sieve(n): """ Uses the Sieve of Eratosthenes to find all prime numbers less than or equal 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_count = [...
from solution import count_primes def test_with_small_numbers(): assert count_primes([10, 14, 18]) == [4, 6, 7] def test_with_edge_case_1(): assert count_primes([1]) == [0] def test_with_prime_edge_cases(): assert count_primes([2, 3, 5, 7]) == [1, 2, 3, 4] def test_with_large_numbers(): assert count...
[ { "docstring": "Uses the Sieve of Eratosthenes to find all prime numbers less than or equal to n ", "function_declaration": "def sieve(n):", "function_name": "sieve", "parameter_list": "(n)" }, { "docstring": "For each test case, count the number of prime numbers less than or equal to X", ...
[ 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 sieve_of_eratosthenes(max_num):\n is_prime = [True] * (max_num + 1)\n is_prime[0] = is_prime[1] = False\n p = 2\n while (p * p <= max_num):...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00024424", "row_id": 24424, "seed_ids": "[9445]" }
0.66532
Code_Contests_24424
I
[ "sieve", "count_primes" ]
2
[ [ "count_primes", "sieve" ] ]
1
[]
false
[]
false
pytest
true
[]
true
a55787d0315eca14ccb2c95aa6c9b05cdff90d7c
03972fa36027700406fd70c78be672e294a909d2
v1.0
instruct
Code_Contests
Code_Contests_24567_I
Xenny now wants to explore factors and multiples. His latest homework assignment involves working with a list of integers. Given a list, he needs to find the Greatest Common Divisor (GCD) of all elements in a particular range specified by two indices in the list. This time, Xenny is busy with a school project and hasn'...
import math from functools import reduce def gcd(a, b): return math.gcd(a, b) def gcd_of_list(lst): return reduce(gcd, lst) def gcd_of_subarray(arr, l, r): subarray = arr[l-1:r] return gcd_of_list(subarray)
from solution import gcd_of_subarray def test_gcd_of_subarray_case1(): arr = [2, 3, 6, 9, 5] assert gcd_of_subarray(arr, 1, 3) == 1 def test_gcd_of_subarray_case2(): arr = [2, 3, 6, 9, 5] assert gcd_of_subarray(arr, 2, 5) == 1 def test_gcd_of_subarray_case3(): arr = [2, 3, 6, 9, 5] assert gcd...
[ { "docstring": null, "function_declaration": "def gcd(a, b):", "function_name": "gcd", "parameter_list": "(a, b)" }, { "docstring": null, "function_declaration": "def gcd_of_list(lst):", "function_name": "gcd_of_list", "parameter_list": "(lst)" }, { "docstring": null, ...
[ 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 typing import List, Tuple\n\ndef find_gcd_subarray(n: int, arr: List[int], queries: List[Tuple[int, int]]) -> List[int]:\n def gcd(a, ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00024567", "row_id": 24567, "seed_ids": "[3828]" }
0.776601
Code_Contests_24567
I
[ "gcd", "gcd_of_list", "gcd_of_subarray" ]
3
[ [ "gcd_of_list", "gcd" ], [ "gcd_of_subarray", "gcd_of_list" ] ]
2
[]
false
[]
false
pytest
true
[]
true
f56272f222b63d9c555589e1f92cd1bcfc284dd1
d90c2e33ec3b6e16443a8971648204d6b7d6895f
v1.0
instruct
Code_Contests
Code_Contests_24616_I
You are given a matrix of N rows and M columns filled with integers. Your task is to find the largest possible sum of integers of a rectangle within the matrix. A rectangle is defined by choosing any two distinct pairs of row indices and any two distinct pairs of column indices. Input The first line of the input conta...
def kadane(arr): """ A helper function to implement the Kadane's algorithm. It returns the maximum sum of a contiguous subarray. """ max_sum = arr[0] current_sum = arr[0] for num in arr[1:]: current_sum = max(num, current_sum + num) max_sum = max(max_sum, current_sum) ret...
def test_largest_sum_submatrix(): assert largest_sum_submatrix([ [1, 2, -1, -4, -20], [-8, -3, 4, 2, 1], [3, 8, 10, 1, 3], [-4, -1, 1, 7, -6] ]) == 29 assert largest_sum_submatrix([ [1, 2, 3], [4, 5, 6], [7, 8, 9] ]) == 45 def test_max_sum_rectan...
[ { "docstring": "A helper function to implement the Kadane's algorithm.\nIt returns the maximum sum of a contiguous subarray.", "function_declaration": "def kadane(arr):", "function_name": "kadane", "parameter_list": "(arr)" }, { "docstring": "Finds the largest possible sum of integers of a r...
[ 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_sum_submatrix(matrix):\n \"\"\"\n Finds the maximum sum submatrix in a given matrix.\n \"\"\"\n def max_subarray(arr):\n max_end...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00024616", "row_id": 24616, "seed_ids": "[4377]" }
0.739017
Code_Contests_24616
I
[ "kadane", "largest_sum_submatrix", "max_sum_rectangles" ]
3
[ [ "largest_sum_submatrix", "kadane" ], [ "max_sum_rectangles", "largest_sum_submatrix" ] ]
2
[]
false
[]
false
pytest
false
[]
true
b9c06bf1a2b3ec59e49dc59ff0d18946c8afea48
295aa67e7e61f1a8ce67f4dce4ac2471185dc377
v1.0
instruct
Code_Contests
Code_Contests_24617_I
You have been assigned the role of a developer in a company responsible for traffic management systems. Your task involves monitoring and managing traffic flows at various intersections. At a particular intersection, there are N traffic lights. Each traffic light operates on a fixed cycle: green for Gi seconds and red...
from math import gcd from functools import reduce def lcm(a, b): return a * b // gcd(a, b) def total_lcm(cycles): return reduce(lcm, cycles) def main(): import sys input = sys.stdin.read data = input().strip().split('\n') N = int(data[0]) cycles = [] for i in range(1, N+1): ...
from solution import lcm, total_lcm def test_lcm(): assert lcm(3, 5) == 15 assert lcm(4, 6) == 12 assert lcm(2, 3) == 6 assert lcm(7, 3) == 21 assert lcm(1, 1) == 1 def test_total_lcm(): assert total_lcm([3, 4, 2, 5, 6]) == 60 assert total_lcm([2, 3, 5]) == 30 assert total_lcm([4, 6]) ...
[ { "docstring": null, "function_declaration": "def lcm(a, b):", "function_name": "lcm", "parameter_list": "(a, b)" }, { "docstring": null, "function_declaration": "def total_lcm(cycles):", "function_name": "total_lcm", "parameter_list": "(cycles)" }, { "docstring": null, ...
[ 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": "from math import gcd\nfrom functools import reduce\n\ndef lcm(a, b):\n return a * b // gcd(a, b)\n\ndef traffic_lights_sync(n, cycles):\n # Calculate...
trial_gpt4o_5
{ "original_instruction": "", "prompt_id": "00024617", "row_id": 24617, "seed_ids": "[9671]" }
0.573866
Code_Contests_24617
I
[ "lcm", "total_lcm", "main" ]
3
[ [ "total_lcm", "lcm" ] ]
1
[]
false
[]
false
pytest
true
[]
true
984a8654a69a0e5b93e35a7aa40c9d4bb7c0a38b
3e739292defc5aa1570829b5b92dd0c139925ba5
v1.0
instruct
Code_Contests
Code_Contests_24629_I
### Problem Alice is a computer science student who loves algorithms. She has recently learned about binary search and wants to practice it. She decides to create an array of integers and repetitively search for multiple target values in the array using the binary search algorithm. Your task is to help Alice by writin...
def binary_search(arr, target): """ Perform binary search on a sorted array to find the target. Returns the index of the target if found, otherwise -1. """ left, right = 0, len(arr) - 1 while left <= right: mid = left + (right - left) // 2 if arr[mid] == target: retur...
from solution import binary_search, find_targets_in_array def test_binary_search_present_in_middle(): assert binary_search([1, 2, 3, 4, 5], 3) == 2 def test_binary_search_not_present(): assert binary_search([1, 2, 3, 4, 5], 6) == -1 def test_binary_search_present_at_start(): assert binary_search([1, 2, 3...
[ { "docstring": "Perform binary search on a sorted array to find the target.\nReturns the index of the target if found, otherwise -1.", "function_declaration": "def binary_search(arr, target):", "function_name": "binary_search", "parameter_list": "(arr, target)" }, { "docstring": "Takes an ar...
[ 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 binary_search(arr, target):\n left, right = 0, len(arr) - 1\n while left <= right:\n mid = (left + right) // 2\n if arr[mid] == tar...
trial_gpt4o_5
{ "original_instruction": "", "prompt_id": "00024629", "row_id": 24629, "seed_ids": "[8597]" }
0.733922
Code_Contests_24629
I
[ "binary_search", "find_targets_in_array", "process_input_output" ]
3
[ [ "find_targets_in_array", "binary_search" ], [ "process_input_output", "find_targets_in_array" ] ]
2
[ "process_input_output" ]
false
[]
false
pytest
true
[]
true
cd202784c8b3131e27f1adfcf434c1427c005e45
7a88fb3c2c2f13158e53da50504dbf0dbf199fa5
v1.0
instruct
Code_Contests
Code_Contests_24641_I
A valid email address is composed of a local part, an "@" symbol, and a domain part: - The local part may contain uppercase and lowercase letters, digits, and the characters: `.`, `-`, `_`. - The domain part is a sequence of characters divided into two or more segments by dots (`.`). Each segment must contain only upp...
import re def validate_email(email): """ Validates a single email address based on the criteria provided. """ email_regex = re.compile( r"^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,6}$" ) return bool(email_regex.match(email)) def validate_emails(emails): """ Takes a list of ...
import pytest from solution import validate_email, validate_emails def test_validate_email(): assert validate_email("john.doe@example.com") == True assert validate_email("jane_doe@sub.domain.co.uk") == True assert validate_email("user@domain") == False assert validate_email("user@domain.toolongtld") ==...
[ { "docstring": "Validates a single email address based on the criteria provided.", "function_declaration": "def validate_email(email):", "function_name": "validate_email", "parameter_list": "(email)" }, { "docstring": "Takes a list of email addresses and returns a list of 'Valid' or 'Invalid...
[ 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 re\n\ndef is_valid_email(email):\n \"\"\"\n Validates an email address based on specific criteria.\n \"\"\"\n # Define the regular expre...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00024641", "row_id": 24641, "seed_ids": "[7278]" }
0.527802
Code_Contests_24641
I
[ "validate_email", "validate_emails" ]
2
[ [ "validate_emails", "validate_email" ] ]
1
[]
false
[]
false
pytest
true
[]
true
71f84ac132773b55147c61c541fea905acf86958
120bb66c6add41f2c236b95d81eaf271c6821540
v1.0
instruct
Code_Contests
Code_Contests_24658_I
Sophia is a budding mathematician and she enjoys playing with numbers. One day, she came up with an interesting problem involving numbers and their digits. She defines the "shadow" of a number as the sum of all the digits of the number raised to the power of their respective positions (1-based index) in the number when...
def digit_shadow(n): """ Calculate the shadow of a number. """ return sum(int(digit)**(pos+1) for pos, digit in enumerate(str(n))) def count_shadow_perfect(L, R): """ Count the number of shadow-perfect numbers in the range [L, R]. """ count = 0 for number in range(L, R+1): i...
from solution import digit_shadow, count_shadow_perfect def test_digit_shadow(): assert digit_shadow(123) == 1**1 + 2**2 + 3**3 == 1 + 4 + 27 == 32 assert digit_shadow(89) == 8**1 + 9**2 == 8 + 81 == 89 assert digit_shadow(1) == 1**1 == 1 assert digit_shadow(10) == 1**1 + 0**2 == 1 def test_count_...
[ { "docstring": "Calculate the shadow of a number.", "function_declaration": "def digit_shadow(n):", "function_name": "digit_shadow", "parameter_list": "(n)" }, { "docstring": "Count the number of shadow-perfect numbers in the range [L, R].", "function_declaration": "def count_shadow_perf...
[ 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 digit_power_sum(n):\n \"\"\"\n Calculate the sum of digits powered by their respective positions for n.\n \"\"\"\n return sum(int(digit) **...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00024658", "row_id": 24658, "seed_ids": "[4842]" }
0.594766
Code_Contests_24658
I
[ "digit_shadow", "count_shadow_perfect" ]
2
[ [ "count_shadow_perfect", "digit_shadow" ] ]
1
[]
false
[]
false
pytest
true
[]
true
996eb706d32e0882f149de532c04d51e4a694002
291e6b7d8d54d050cec0270a7f130fe55bd237fe
v1.0
instruct
Code_Contests
Code_Contests_24675_I
A transport company wants to optimize the travel route between its warehouses. Given a map with N warehouses and M direct lanes between them, determine the minimum distance required to connect all warehouses into a single connected network (spanning tree), ensuring that the company minimizes the total travel distance. ...
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] > ...
def test_minimum_distance_case_1(): N = 4 M = 5 lanes = [ [0, 1, 1], [1, 2, 2], [2, 3, 1], [0, 3, 4], [0, 2, 3] ] assert minimum_distance(N, M, lanes) == 4 def test_minimum_distance_case_2(): N = 3 M = 1 lanes = [ [0, 1, 2] ] asser...
[ { "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": "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_1
{ "original_instruction": "", "prompt_id": "00024675", "row_id": 24675, "seed_ids": "[3421]" }
0.699101
Code_Contests_24675
I
[ "find", "union", "kruskal", "minimum_distance" ]
4
[ [ "kruskal", "find" ], [ "kruskal", "union" ], [ "minimum_distance", "kruskal" ], [ "union", "find" ] ]
4
[]
false
[]
false
pytest
false
[]
true
28238ca2c2990f8d35c733f395490bd54e1c60de
66246d09241f9dfa6098d4a9a61964847b2de059
v1.0
instruct
Code_Contests
Code_Contests_24790_I
You are given a tree with n nodes and n-1 edges. Each node has an initial value assigned to it. In one operation, you can choose any node and increase its value by 1. The cost of this operation is equal to the sum of the current values of its direct children. If the node has no children, the cost is zero. Your task i...
def min_cost_to_leaf_values(n, k, values, edges): from collections import defaultdict, deque tree = defaultdict(list) for u, v in edges: tree[u].append(v) tree[v].append(u) degrees = {i: len(adj) for i, adj in tree.items()} leaf_nodes = [i for i, d in degrees.items() if...
from solution import process_tree_cost def test_example_case(): n, k = 5, 5 values = [1, 2, 3, 4, 5] edges = [(1, 2), (1, 3), (3, 4), (3, 5)] assert process_tree_cost(n, k, values, edges) == 5 def test_all_leaves_have_enough_value(): n, k = 4, 2 values = [2, 2, 2, 2] edges = [(1, 2), (1, 3...
[ { "docstring": null, "function_declaration": "def min_cost_to_leaf_values(n, k, values, edges):", "function_name": "min_cost_to_leaf_values", "parameter_list": "(n, k, values, edges)" }, { "docstring": null, "function_declaration": "def process_tree_cost(n, k, values, edges):", "func...
[ 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 min_cost_to_reach_k(n, k, values, edges):\n from collections import defaultdict, deque\n \n # Create adjacency list\n tree = defaultdict(li...
trial_gpt4o_3
{ "original_instruction": "", "prompt_id": "00024790", "row_id": 24790, "seed_ids": "[3562]" }
0.75158
Code_Contests_24790
I
[ "min_cost_to_leaf_values", "process_tree_cost" ]
2
[ [ "process_tree_cost", "min_cost_to_leaf_values" ] ]
1
[]
false
[]
false
pytest
true
[]
true
6c7d393f75bf651a9ccd7a512fb2e9a1c723456f
ddb8e252fdeb925036b180b3f3c5a21c2b6ee487
v1.0
instruct
Code_Contests
Code_Contests_24804_I
You are given a list of M intercity flights, where each flight is represented by a triplet (source city, destination city, travel time in hours). You want to develop a program to determine the minimum travel time required to go from a specific starting city to all other cities in the network by catching a series of the...
import heapq import sys def dijkstra(N, flights, starting_city): adj = {i: [] for i in range(N)} for src, dst, time in flights: adj[src].append((dst, time)) min_time = [sys.maxsize] * N min_time[starting_city] = 0 pq = [(0, starting_city)] while pq: current_time, city...
from solution import find_min_travel_times def test_case_1(): data = [ "5 7", "0", "0 1 10", "0 2 3", "1 2 1", "2 1 4", "1 3 2", "2 3 8", "3 4 7" ] assert find_min_travel_times(data) == [0, 7, 3, 9, 16] def test_case_2(): data = [...
[ { "docstring": null, "function_declaration": "def dijkstra(N, flights, starting_city):", "function_name": "dijkstra", "parameter_list": "(N, flights, starting_city)" }, { "docstring": null, "function_declaration": "def find_min_travel_times(data):", "function_name": "find_min_travel_...
[ 1, 0, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "import heapq\nimport sys\n\ndef dijkstra(N, flights, starting_city):\n adj = {i: [] for i in range(N)}\n for src, dst, time in flights:\n adj[...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00024804", "row_id": 24804, "seed_ids": "[1231]" }
0.767585
Code_Contests_24804
I
[ "dijkstra", "find_min_travel_times" ]
2
[ [ "find_min_travel_times", "dijkstra" ] ]
1
[]
false
[]
false
pytest
true
[]
true
b7e39e74fe1fed320a093aaeba7f02eeae3be709
fb9d3371fd9230addf567f4d1e76bbc33f0927f8
v1.0
instruct
Code_Contests
Code_Contests_24876_I
Matt loves the Fibonacci sequence and he is trying to create a game based on the Fibonacci numbers. He needs your help to compute the n-th Fibonacci number, but there's a twist: since the numbers can get very large, he wants to know the n-th Fibonacci number modulo 1000000007. Input The first line contains an integer ...
MOD = 1000000007 def matrix_mult(A, B, mod=MOD): return [ [(A[0][0] * B[0][0] + A[0][1] * B[1][0]) % mod, (A[0][0] * B[0][1] + A[0][1] * B[1][1]) % mod], [(A[1][0] * B[0][0] + A[1][1] * B[1][0]) % mod, (A[1][0] * B[0][1] + A[1][1] * B[1][1]) % mod] ] def matrix_pow(mat, exp, ...
def test_fibonacci_cases(): assert solve_fibonacci([1]) == [1] assert solve_fibonacci([2]) == [1] assert solve_fibonacci([10]) == [55] assert solve_fibonacci([50]) == [12586269025 % 1000000007] assert solve_fibonacci([100]) == [354224848179261915075 % 1000000007] def test_multiple_fibonacci_cases()...
[ { "docstring": null, "function_declaration": "def matrix_mult(A, B, mod=MOD):", "function_name": "matrix_mult", "parameter_list": "(A, B, mod=MOD)" }, { "docstring": null, "function_declaration": "def matrix_pow(mat, exp, mod=MOD):", "function_name": "matrix_pow", "parameter_list...
[ 0, 0, 1 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "MODULO = 1000000007\n\ndef fibonacci_modulo(n):\n \"\"\"\n Returns the n-th Fibonacci number modulo 1000000007.\n \"\"\"\n if n == 1 or n == 2:...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00024876", "row_id": 24876, "seed_ids": "[6562]" }
0.691779
Code_Contests_24876
I
[ "matrix_mult", "matrix_pow", "fibonacci_mod", "solve_fibonacci" ]
4
[ [ "fibonacci_mod", "matrix_pow" ], [ "matrix_pow", "matrix_mult" ], [ "solve_fibonacci", "fibonacci_mod" ] ]
3
[]
false
[]
false
pytest
false
[]
true
ed32cab30d290d186316cd00e6ad79ade3237a63
cac255301bea06182b9e614698a4e910360b95db
v1.0
instruct
Code_Contests
Code_Contests_24889_I
In the Kingdom of Alpha, there are several towns connected by bidirectional roads that create a network. Each road has a weight representing its length. The King's advisor wants to ensure that the towns are connected in the most efficient way possible, specifically building the minimum spanning tree (MST) of the road n...
import heapq def find(parent, i): """ A function to find the set of an element i (uses path compression technique) """ if parent[i] == i: return i else: parent[i] = find(parent, parent[i]) return parent[i] def union(parent, rank, x, y): """ A function that does ...
from solution import minimum_spanning_tree def test_mst_example_1(): towns = 5 roads = [ [1, 2, 4], [1, 3, 2], [2, 3, 1], [2, 4, 7], [3, 4, 3], [3, 5, 5], [4, 5, 6] ] assert minimum_spanning_tree(towns, roads) == 11 def test_mst_example_2(): ...
[ { "docstring": "A function to find the set of an element i\n(uses path compression technique)", "function_declaration": "def find(parent, i):", "function_name": "find", "parameter_list": "(parent, i)" }, { "docstring": "A function that does union of two sets of x and y\n(uses union by rank)"...
[ 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 heapq\n\ndef find(parent, i):\n \"\"\"\n A function to find the set of an element i\n (uses path compression technique)\n \"\"\"\n if...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00024889", "row_id": 24889, "seed_ids": "[6482]" }
0.734984
Code_Contests_24889
I
[ "find", "union", "kruskal_mst", "minimum_spanning_tree" ]
4
[ [ "kruskal_mst", "find" ], [ "kruskal_mst", "union" ], [ "minimum_spanning_tree", "kruskal_mst" ], [ "union", "find" ] ]
4
[]
false
[]
false
pytest
true
[]
true
b3c72d6e63bb4d7c68891cc1d580bae071c56528
2f7fc49b7e62340ec164ab6b5a1a6a79918720b9
v1.0
instruct
Code_Contests
Code_Contests_24895_I
You are given a directed graph with $N$ nodes and $M$ edges. Find the number of strongly connected components (SCCs) in the graph. ### Constraints * $1 \leq N \leq 10^5$ * $1 \leq M \leq 10^5$ ### Input The input is given in the following format: $N$ $M$ Next $M$ lines, each containing two integers $u$ and $v$ indi...
from collections import defaultdict, deque def kosaraju_scc_count(n, edges): def dfs(v, graph, visited, stack=None, component=None): visited[v] = True if component is not None: component.append(v) for neighbour in graph[v]: if not visited[neighbour]: ...
def test_find_scc_count_example(): n = 5 m = 5 edges = [ (1, 2), (2, 3), (3, 1), (4, 5), (5, 4) ] assert find_scc_count(n, m, edges) == 2 def test_find_scc_count_no_edges(): n = 5 m = 0 edges = [] assert find_scc_count(n, m, edges) == 5 # Ea...
[ { "docstring": null, "function_declaration": "def kosaraju_scc_count(n, edges):", "function_name": "kosaraju_scc_count", "parameter_list": "(n, edges)" }, { "docstring": null, "function_declaration": "def find_scc_count(n, m, edges):", "function_name": "find_scc_count", "paramete...
[ 1, 0, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "from collections import defaultdict, deque\n\ndef kosaraju_scc_count(n, edges):\n def dfs(v, graph, visited, stack=None, component=None):\n visit...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00024895", "row_id": 24895, "seed_ids": "[13015]" }
0.600956
Code_Contests_24895
I
[ "kosaraju_scc_count", "find_scc_count" ]
2
[ [ "find_scc_count", "kosaraju_scc_count" ] ]
1
[]
false
[]
false
pytest
false
[]
true
d366c21b94b3787b7bd14e710e9b732a7ccfe96b
665759191d1a5341d8f9e875d94a8c3c261196ba
v1.0
instruct
Code_Contests
Code_Contests_24913_I
You are given an array of N integers and Q queries. Each query consists of two indices L and R. For each query, you need to return the sum of all the unique prime numbers in the subarray from L to R (inclusive). Implement a function to handle the queries efficiently. Input: - The first line of input contains two integ...
def sieve_primes_upto(limit): is_prime = [True] * (limit + 1) p = 2 while (p * p <= limit): if (is_prime[p] == True): for i in range(p * p, limit + 1, p): is_prime[i] = False p += 1 is_prime[0], is_prime[1] = False, False # 0 and 1 are not prime numbers p...
from solution import sum_of_unique_primes def test_case_1(): arr = [2, 3, 4, 5, 6] queries = [(1, 3), (2, 4), (1, 5)] result = sum_of_unique_primes(arr, queries) assert result == [5, 8, 10] def test_case_2(): arr = [10, 15, 21, 25, 30] queries = [(1, 3), (3, 5), (1, 5)] result = sum_of_uni...
[ { "docstring": null, "function_declaration": "def sieve_primes_upto(limit):", "function_name": "sieve_primes_upto", "parameter_list": "(limit)" }, { "docstring": null, "function_declaration": "def sum_of_unique_primes(arr, queries):", "function_name": "sum_of_unique_primes", "par...
[ 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 sieve_of_eratosthenes(max_num):\n \"\"\" Returns a list of all primes <= max_num \"\"\"\n is_prime = [True] * (max_num + 1)\n is_prime[0] = is...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00024913", "row_id": 24913, "seed_ids": "[1215]" }
0.618154
Code_Contests_24913
I
[ "sieve_primes_upto", "sum_of_unique_primes" ]
2
[ [ "sum_of_unique_primes", "sieve_primes_upto" ] ]
1
[]
false
[]
false
pytest
true
[]
true
e95c3c2a8675a5d82fb10d781cda9d3c6b46ec44
ef47ff2d4a734b6f73b8ad7fc5a2a40f15a98bf8
v1.0
instruct
Code_Contests
Code_Contests_24924_I
You are given a 2D grid representing a maze, where each cell can either be open or blocked. The objective is to modify the maze to make it solvable if it's not already. Specifically, you can transform some blocked cells into open cells. Your task is to find the minimum number of blocked cells that need to be made open ...
from collections import deque import heapq def minCellsToOpenForPath(grid): n = len(grid) m = len(grid[0]) if n == 0 or m == 0: return -1 def is_valid(x, y): return 0 <= x < n and 0 <= y < m directions = [(1, 0), (0, 1), (-1, 0), (0, -1)] # Early exit if initial or final ...
from solution import minimum_modifications def test_example_case(): grid = [ [0, 1, 0], [1, 1, 0], [0, 0, 0] ] assert minimum_modifications(3, 3, grid) == 1 def test_no_modifications_needed(): grid = [ [0, 0, 0], [0, 1, 0], [0, 0, 0] ] assert min...
[ { "docstring": null, "function_declaration": "def minCellsToOpenForPath(grid):", "function_name": "minCellsToOpenForPath", "parameter_list": "(grid)" }, { "docstring": null, "function_declaration": "def minimum_modifications(n, m, grid):", "function_name": "minimum_modifications", ...
[ 1, 0, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "from collections import deque\nimport heapq\n\ndef minCellsToOpenForPath(grid):\n n = len(grid)\n m = len(grid[0])\n if n == 0 or m == 0:\n ...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00024924", "row_id": 24924, "seed_ids": "[9923]" }
0.700879
Code_Contests_24924
I
[ "minCellsToOpenForPath", "minimum_modifications" ]
2
[ [ "minimum_modifications", "minCellsToOpenForPath" ] ]
1
[]
false
[]
false
pytest
true
[]
true
22e780fe7d7ea64dcd535cbe286abd1824520c80
a69ece5e00501a8a04b721051f256e60014a3d89
v1.0
instruct
Code_Contests
Code_Contests_24926_I
Write a function that will reverse the digits of an integer and determine if the result is a prime number or not. The function should take as input the integer and return True if the reversed integer is a prime, and False otherwise. A prime number is a natural number greater than 1 that has no positive divisors other...
def is_prime(n): """ Helper function to check if a number is prime. """ if n <= 1: return False if n == 2: return True if n % 2 == 0: return False max_divisor = int(n**0.5) + 1 for i in range(3, max_divisor, 2): if n % i == 0: return False ...
def test_reverse_and_check_prime(): # Test case 1: Reversing 13 gives 31, which is prime assert reverse_and_check_prime(13) == True # Test case 2: Reversing 37 gives 73, which is prime assert reverse_and_check_prime(37) == True # Test case 3: Reversing 123 gives 321, which is not prime ass...
[ { "docstring": "Helper function to check if a number is prime.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Reverses the digits of an integer and checks if the result is a prime number.", "function_declaration": "de...
[ 1, 0, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(n):\n \"\"\"Helper function to check if a number is prime.\"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return True...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00024926", "row_id": 24926, "seed_ids": "[12184]" }
0.719346
Code_Contests_24926
I
[ "is_prime", "reverse_and_check_prime" ]
2
[ [ "reverse_and_check_prime", "is_prime" ] ]
1
[]
false
[]
false
pytest
false
[]
true
89b635f8699e1391b4cb9a5e15890a178a8f5099
b486490552b577c9ad716d9a6ec10070bfe46131
v1.0
instruct
Code_Contests
Code_Contests_24967_I
Alice has recently learned about binary search trees (BST) and is fascinated by their properties. She decides to test her knowledge by solving a problem where she needs to transform one BST into another by performing rotations. A single rotation in a BST involves changing the parent-child relationship between two node...
class TreeNode: def __init__(self, key): self.left = None self.right = None self.val = key def build_tree_from_inorder(inorder): if not inorder: return None def build_tree(in_index_map, start, end): if start > end: return None root_val = next(it...
from solution import rotations_from_inorder def test_rotations_simple_case(): n, A, B = 3, [1, 2, 3], [3, 1, 2] result = rotations_from_inorder(n, A, B) assert result == -1 def test_rotations_complex_case(): n, A, B = 5, [4, 2, 5, 1, 3], [1, 2, 3, 4, 5] result = rotations_from_inorder(n, A, B) ...
[]
[ 0, 0, 1, 0 ]
1
hard
0.25
{ "trial_gpt4o_0": null, "trial_gpt4o_1": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared1_results_combined.jsonl", "solution_code": "class TreeNode:\n def __init__(self, key):\n self.left = None\n self.right = None\n self.val = key\n\ndef ...
trial_gpt4o_3
{ "original_instruction": "", "prompt_id": "00024967", "row_id": 24967, "seed_ids": "[1895]" }
0.512173
Code_Contests_24967
I
[ "build_tree_from_inorder", "convert_tree_to_inorder", "find_rotation_sequence", "rotations_from_inorder", "calculate_rotations" ]
5
[ [ "calculate_rotations", "rotations_from_inorder" ], [ "find_rotation_sequence", "build_tree_from_inorder" ], [ "find_rotation_sequence", "convert_tree_to_inorder" ], [ "rotations_from_inorder", "find_rotation_sequence" ] ]
4
[]
false
[ "TreeNode" ]
true
pytest
true
[]
true
30eb2e9c6835f9d1ddb9ac57b34ef73c40d79680
674a07925a1f51d2f95a559816667739f4ff3b18
v1.0
instruct
Code_Contests
Code_Contests_25010_I
A city is represented as a grid of size N x M. Some cells are blocked and cannot be walked on. The city has exactly one fire station and some number of hospitals and residential houses. A person can move up, down, left, or right, but cannot move into or through a blocked cell. The mayor wants to ensure that in case of...
from collections import deque def bfs(grid, start, N, M): directions = [(0, 1), (1, 0), (0, -1), (-1, 0)] visited = [[False for _ in range(M)] for _ in range(N)] queue = deque([start]) visited[start[0]][start[1]] = True distances = [[float('inf') for _ in range(M)] for _ in range(N)] distances[...
from solution import is_layout_valid def test_case_1(): grid = [ "F....", ".#H#.", "H..R.", "R...." ] assert is_layout_valid(4, 5, 2, grid) == "YES" def test_case_2(): grid = [ "F.#..", "##H#.", "H..R.", "R...." ] assert is_layout...
[ { "docstring": null, "function_declaration": "def bfs(grid, start, N, M):", "function_name": "bfs", "parameter_list": "(grid, start, N, M)" }, { "docstring": null, "function_declaration": "def is_layout_valid(N, M, D, grid):", "function_name": "is_layout_valid", "parameter_list":...
[ 0, 0, 1 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "from collections import deque\n\ndef bfs(start, grid, n, m):\n \"\"\"\n Perform BFS from the start position to find shortest distance to all reachabl...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00025010", "row_id": 25010, "seed_ids": "[7363]" }
0.723891
Code_Contests_25010
I
[ "bfs", "is_layout_valid" ]
2
[ [ "is_layout_valid", "bfs" ] ]
1
[]
false
[]
false
pytest
true
[]
true
850d7120da0366311cf61c0fc19ed6af13b7ac32
6b82221b5f9c937694a5cd345cfd2b78a464c15a
v1.0
instruct
Code_Contests
Code_Contests_25012_I
There is a complex system of waterways and dams called the Vethian River Network (VRN) on planet Vetha. VRN is represented as a directed graph where nodes represent dams, and edges represent waterways with given capacities. The water flows along these waterways from one dam to another. The VRN has one special dam known...
from collections import deque def bfs_capacity(graph, source, sink, parent): """ A BFS for finding the augmenting path in the residual graph. """ visited = [False] * len(graph) queue = deque([source]) visited[source] = True while queue: u = queue.popleft() for v, capacity i...
def test_simple_case(): n = 4 m = 5 waterways = [ (1, 2, 100), (1, 3, 100), (2, 4, 50), (3, 4, 50), (2, 3, 50) ] assert max_flow(n, m, waterways) == 100 def test_disconnected_case(): n = 4 m = 3 waterways = [ (1, 2, 10), (2, 3, 5) ...
[ { "docstring": "A BFS for finding the augmenting path in the residual graph.", "function_declaration": "def bfs_capacity(graph, source, sink, parent):", "function_name": "bfs_capacity", "parameter_list": "(graph, source, sink, parent)" }, { "docstring": "Calculates the maximum flow from sour...
[ 1, 0, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "from collections import deque\n\ndef bfs_capacity(graph, source, sink, parent):\n \"\"\"\n A BFS for finding the augmenting path in the residual grap...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00025012", "row_id": 25012, "seed_ids": "[3531]" }
0.604658
Code_Contests_25012
I
[ "bfs_capacity", "max_flow" ]
2
[ [ "max_flow", "bfs_capacity" ] ]
1
[]
false
[]
false
pytest
false
[]
true
af863daee704730419511c1aa63c2baedafa46e5
4e161376572be197fa9555d7129095266c308e1a
v1.0
instruct
Code_Contests
Code_Contests_25027_I
Iroha loves palindrome numbers. A palindrome number reads the same backward as forward, for example, 121 or 12321. She has a number N and would like to find the smallest palindrome number greater than or equal to N. Constraints * 1 ≦ N < 100000 Input The input is given from Standard Input in the following format:...
def is_palindrome(num): """ Check if a number is palindrome. """ s = str(num) return s == s[::-1] def find_smallest_palindrome_greater_or_equal(N): """ Find the smallest palindrome number greater than or equal to N. """ current_num = N while True: if is_palindrome(curren...
from solution import is_palindrome, find_smallest_palindrome_greater_or_equal def test_is_palindrome(): assert is_palindrome(121) == True assert is_palindrome(12321) == True assert is_palindrome(123) == False assert is_palindrome(1) == True assert is_palindrome(1221) == True def test_find_smallest...
[ { "docstring": "Check if a number is palindrome.", "function_declaration": "def is_palindrome(num):", "function_name": "is_palindrome", "parameter_list": "(num)" }, { "docstring": "Find the smallest palindrome number greater than or equal to N.", "function_declaration": "def find_smalles...
[ 1, 0, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_palindrome(n):\n \"\"\"\n Utility function to check if a number is a palindrome.\n \"\"\"\n s = str(n)\n return s == s[::-1]\n\ndef s...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00025027", "row_id": 25027, "seed_ids": "[10397]" }
0.823517
Code_Contests_25027
I
[ "is_palindrome", "find_smallest_palindrome_greater_or_equal" ]
2
[ [ "find_smallest_palindrome_greater_or_equal", "is_palindrome" ] ]
1
[]
false
[]
false
pytest
true
[]
true
8b17471c1a976b2d94898d83cb60f2ab353482af
72572620503c0718dd27b5d9fde18a96980655d6
v1.0
instruct
Code_Contests
Code_Contests_25035_I
A robotics company is designing a new robotic arm that can move in a 2D grid. The robotic arm starts at the origin point (0,0) and can move in four directions: up, down, left, and right. Each move is represented by a command in a string, where 'U' means up, 'D' means down, 'L' means left, and 'R' means right. The robot...
def final_position(commands): """ Takes a string of commands and returns the final position of the robotic arm. Parameters: commands (str): A string containing the commands executed by the robotic arm Returns: tuple: A tuple of two integers representing the final coordinates """ ...
from solution import final_position def test_final_position_uurrddllr(): assert final_position("UURDDLLR") == (0, 0) def test_final_position_uuddlrlr(): assert final_position("UUDDLRLR") == (0, 0) def test_final_position_llll(): assert final_position("LLLL") == (-4, 0) def test_final_position_uuuuu(): ...
[ { "docstring": "Takes a string of commands and returns the final position of the robotic arm.\n\nParameters:\ncommands (str): A string containing the commands executed by the robotic arm\n\nReturns:\ntuple: A tuple of two integers representing the final coordinates", "function_declaration": "def final_posit...
[ 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 final_position(commands):\n \"\"\"\n Takes a string of commands and returns the final position of the robotic arm.\n \n Parameters:\n co...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00025035", "row_id": 25035, "seed_ids": "[2554]" }
0.656194
Code_Contests_25035
I
[ "final_position", "print_final_position" ]
2
[ [ "print_final_position", "final_position" ] ]
1
[]
false
[]
false
pytest
true
[]
true
8a646ccbbe191b083f3d4a76de33cc1a13971016
6a77a55efe8d1259795a51cc8ebe5785ccc5d49f
v1.0
instruct
Code_Contests
Code_Contests_25037_I
Bob is organizing a programming contest where each participant can solve multiple problems. Each problem has a difficulty level d and an associated score s. A participant can solve a problem if their skill level, l, is greater than or equal to the difficulty level d of the problem. The participant will then earn the s...
def max_total_score(test_cases): results = [] for test_case in test_cases: n, l = test_case[0] problems = test_case[1] total_score = 0 for (d, s) in problems: if l >= d: total_score += s results.append(total_score) return results # Functio...
def test_max_total_score(): test_cases = [ [(3, 10), [(5, 80), (10, 100), (3, 50)]], [(4, 5), [(10, 100), (5, 50), (20, 30)]] ] expected_output = [230, 50] assert calculate_max_scores(2, test_cases) == expected_output def test_max_total_score_with_zero_problems(): test_cases = [ ...
[ { "docstring": null, "function_declaration": "def max_total_score(test_cases):", "function_name": "max_total_score", "parameter_list": "(test_cases)" }, { "docstring": null, "function_declaration": "def calculate_max_scores(t, test_cases):", "function_name": "calculate_max_scores", ...
[ 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_total_score(t, test_cases):\n \"\"\"\n Calculates the maximum total score a participant can achieve.\n \n Parameters:\n t (int): num...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00025037", "row_id": 25037, "seed_ids": "[11893]" }
0.770957
Code_Contests_25037
I
[ "max_total_score", "calculate_max_scores" ]
2
[ [ "calculate_max_scores", "max_total_score" ] ]
1
[]
false
[]
false
pytest
false
[]
true
29d9ff0c4d2e774cadd1306bf2e54d2eda058991
9e8e5838cce111b6702d041276b665e2e529626a
v1.0
instruct
Code_Contests
Code_Contests_25055_I
Title: Weight of the Words In a universe where words have weights, each word's weight is calculated as the sum of the weights of its characters. The weight of a character is defined by its position in the alphabet (i.e., 'a' = 1, 'b' = 2, ..., 'z' = 26). Given a phrase, you need to determine the weight of each word in...
def word_weight(word): """ Calculate the weight of a word based on the sum of the positions of its characters in the alphabet. """ return sum(ord(char) - ord('a') + 1 for char in word) def sort_words_by_weight(phrase): """ Sort the words in the phrase based on their weight in ascending order. ...
from solution import word_weight, sort_words_by_weight, process_phrases def test_word_weight(): assert word_weight('a') == 1 assert word_weight('z') == 26 assert word_weight('abc') == 6 assert word_weight('test') == 64 def test_sort_words_by_weight(): assert sort_words_by_weight('this is a test') ...
[ { "docstring": "Calculate the weight of a word based on the sum of the positions of its characters in the alphabet.", "function_declaration": "def word_weight(word):", "function_name": "word_weight", "parameter_list": "(word)" }, { "docstring": "Sort the words in the phrase based on their we...
[ 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 word_weight(word):\n \"\"\"\n Given a word, return its weight, which is the sum of its characters' positions \n in the alphabet.\n \"\"\"\n...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00025055", "row_id": 25055, "seed_ids": "[419]" }
0.611759
Code_Contests_25055
I
[ "word_weight", "sort_words_by_weight", "process_phrases" ]
3
[ [ "process_phrases", "sort_words_by_weight" ], [ "sort_words_by_weight", "word_weight" ] ]
2
[]
false
[]
false
pytest
true
[]
true
13f9f8cef67a21a18f8f04067633889a4e9e251c
b05da0edad9d3bb7d65ef79a14f25ba9d8df1e54
v1.0
instruct
Code_Contests
Code_Contests_25065_I
Admiral Grace Hopper Naval Academy is planning a midterm programming assessment for its cadets. The task is to determine the efficiency of their navigation algorithms by assessing their ability to calculate the shortest path in a grid that's partially subject to current flows that either accelerate or decelerate their ...
import sys import heapq def dijkstra(grid, n, m): # Initialize time array with infinity time = [[sys.maxsize] * m for _ in range(n)] time[0][0] = max(1, 1 - grid[0][0]) # Priority queue for dijkstra's algorithm pq = [(time[0][0], 0, 0)] # Dijkstra's algorithm while pq: cur...
def test_parse_input(): input_str = "2\n3 3\n0 1 2\n-1 0 1\n2 -1 0\n2 2\n0 1\n-1 0\n" expected_output = [ [[0, 1, 2], [-1, 0, 1], [2, -1, 0]], [[0, 1], [-1, 0]] ] assert parse_input(input_str) == expected_output def test_dijkstra(): grid1 = [[0, 1, 2], [-1, 0, 1], [2, -1, 0]] as...
[ { "docstring": null, "function_declaration": "def dijkstra(grid, n, m):", "function_name": "dijkstra", "parameter_list": "(grid, n, m)" }, { "docstring": null, "function_declaration": "def min_travel_time(test_cases):", "function_name": "min_travel_time", "parameter_list": "(test...
[ 1, 0, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "import sys\nimport heapq\n\ndef dijkstra(grid, n, m):\n # Initialize time array with infinity\n time = [[sys.maxsize] * m for _ in range(n)]\n tim...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00025065", "row_id": 25065, "seed_ids": "[416]" }
0.61673
Code_Contests_25065
I
[ "dijkstra", "min_travel_time", "parse_input", "main" ]
4
[ [ "min_travel_time", "dijkstra" ] ]
1
[ "parse_input" ]
false
[]
false
pytest
false
[]
true
855685158cae1d9f87dc9e49281fb909369f5b75
1b529651a8477eea4a802c431b721e459bc302a9
v1.0
instruct
Code_Contests
Code_Contests_25070_I
**Archie loves trees and math. One day he found an interesting problem involving binary search trees (BST). He decided to solve it and needs your help to succeed.** Given an array of integer values, you need to construct the BST from the given array elements and find the sum of all nodes which are greater than or equa...
class TreeNode: def __init__(self, value): self.value = value self.left = None self.right = None def insert_into_bst(root, value): if root is None: return TreeNode(value) if value < root.value: root.left = insert_into_bst(root.left, value) else: root.righ...
def test_solve_example(): assert solve(5, [10, 5, 15, 3, 7], 7) == 32 def test_all_elements_greater_or_equal(): assert solve(3, [5, 10, 15], 5) == 30 def test_all_elements_less_than_k(): assert solve(3, [1, 2, 3], 10) == 0 def test_mixed_elements(): assert solve(6, [20, 15, 25, 10, 30, 5], 17) == 75 ...
[]
[ 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, key):\n self.left = None\n self.right = None\n self.val = key\n\ndef insert(node, key):\n i...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00025070", "row_id": 25070, "seed_ids": "[9827]" }
0.569133
Code_Contests_25070
I
[ "insert_into_bst", "build_bst", "sum_of_nodes_greater_or_equal_to_k", "solve" ]
4
[ [ "build_bst", "insert_into_bst" ], [ "solve", "build_bst" ], [ "solve", "sum_of_nodes_greater_or_equal_to_k" ] ]
3
[]
false
[ "TreeNode" ]
true
pytest
false
[]
true
460822c3ae6afb2066c1cf7b44efe8943ad0c55b
5f24d71974b3efb937b8bcf2c0a503268f8904f8
v1.0
instruct
Code_Contests
Code_Contests_25082_I
Grace loves playing with numbers. One day, she came across a sequence of operations involving the properties of prime numbers. She defined a transformation on an integer N, which involves the following steps: 1. Find all the prime numbers less than or equal to N. 2. Multiply these prime numbers together to get a new n...
def sieve_of_eratosthenes(max_num): """ Helper function that uses the Sieve of Eratosthenes to find all primes <= max_num """ is_prime = [True] * (max_num + 1) p = 2 while (p * p <= max_num): if (is_prime[p] == True): for i in range(p * p, max_num + 1, p): is_prime[i]...
from solution import single_digit_prime_product, sieve_of_eratosthenes, multiply_digits, process_input def test_sieve_of_eratosthenes(): assert sieve_of_eratosthenes(10) == [2, 3, 5, 7] assert sieve_of_eratosthenes(15) == [2, 3, 5, 7, 11, 13] assert sieve_of_eratosthenes(7) == [2, 3, 5, 7] def test_multip...
[ { "docstring": "Helper function that uses the Sieve of Eratosthenes to find all primes <= max_num ", "function_declaration": "def sieve_of_eratosthenes(max_num):", "function_name": "sieve_of_eratosthenes", "parameter_list": "(max_num)" }, { "docstring": "Helper function that multiplies all d...
[ 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 sieve_of_eratosthenes(n):\n \"\"\" Returns a list of prime numbers up to n using the Sieve of Eratosthenes. \"\"\"\n is_prime = [True] * (n + 1)\...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00025082", "row_id": 25082, "seed_ids": "[3196]" }
0.668036
Code_Contests_25082
I
[ "sieve_of_eratosthenes", "multiply_digits", "single_digit_prime_product", "process_input" ]
4
[ [ "process_input", "single_digit_prime_product" ], [ "single_digit_prime_product", "multiply_digits" ], [ "single_digit_prime_product", "sieve_of_eratosthenes" ] ]
3
[ "process_input" ]
false
[]
false
pytest
true
[]
true
473dae450024d0b70da408248d89b7a0c4eac02f
5495fa5346632e4e79a340fd781bf4c2cfe234d2
v1.0
instruct
Code_Contests
Code_Contests_25084_I
A large university is planning the layout for its new campus, which is going to have several buildings connected by a series of roads. Each building and road is represented in the form of a graph where buildings are nodes and roads are edges. The university wants to ensure that the campus remains connected (i.e., there...
def minimum_total_road_length(N, M, roads): """ This function takes the number of buildings N, number of roads M, and a list of roads. Each road is represented by a tuple (u, v, w) where u and v are the buildings connected by the road and w is the length of the road. The function returns the minimum tot...
def test_minimum_total_road_length(): input_data = "4 5\n1 2 10\n1 3 6\n1 4 5\n2 3 15\n3 4 4" assert parse_and_solve(input_data) == 19 def test_single_road(): input_data = "2 1\n1 2 5" assert parse_and_solve(input_data) == 5 def test_no_road(): input_data = "1 0" assert parse_and_solve(input_d...
[ { "docstring": "This function takes the number of buildings N, number of roads M, and a list of roads.\nEach road is represented by a tuple (u, v, w) where u and v are the buildings connected\nby the road and w is the length of the road. The function returns the minimum total length\nof roads required to keep t...
[ 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 minimum_spanning_tree(N, M, edges):\n \"\"\"\n Returns the minimum total length of roads required to keep the campus connected.\n \n Parame...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00025084", "row_id": 25084, "seed_ids": "[12706]" }
0.70875
Code_Contests_25084
I
[ "minimum_total_road_length", "parse_and_solve" ]
2
[ [ "parse_and_solve", "minimum_total_road_length" ] ]
1
[]
false
[]
false
pytest
true
[]
true
4c54be5b7e29277143772c8631397681003281a1
5f5f7c05e7ed37ba9749ddfa7e3caaa2453cf00c
v1.0
instruct
Code_Contests
Code_Contests_25133_I
A company has a network of N servers connected by M bidirectional links. Each link has an associated latency which represents the time taken to travel between two servers. The company's goal is to ensure that data can be transferred between any pair of servers in the minimum possible time. Provide a plan to calculate t...
def find(parent, node): if parent[node] == node: return node parent[node] = find(parent, parent[node]) return parent[node] def union(parent, rank, node1, node2): root1 = find(parent, node1) root2 = find(parent, node2) if root1 != root2: if rank[root1] > rank[root2]: ...
def test_minimum_latency_to_connect_servers_minimum_spanning_tree(): assert minimum_latency_to_connect_servers(4, 5, [(1, 2, 3), (2, 3, 4), (3, 4, 5), (1, 4, 10), (1, 3, 6)]) == 12 def test_minimum_latency_to_connect_servers_disconnected(): assert minimum_latency_to_connect_servers(4, 2, [(1, 2, 3), (3, 4, 5)]...
[ { "docstring": null, "function_declaration": "def find(parent, node):", "function_name": "find", "parameter_list": "(parent, node)" }, { "docstring": null, "function_declaration": "def union(parent, rank, node1, node2):", "function_name": "union", "parameter_list": "(parent, rank...
[ 0, 0, 1 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "class UnionFind:\n def __init__(self, size):\n self.parent = list(range(size))\n self.rank = [0] * size\n\n def find(self, u):\n ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00025133", "row_id": 25133, "seed_ids": "[7884]" }
0.606605
Code_Contests_25133
I
[ "find", "union", "minimum_latency_to_connect_servers", "solve" ]
4
[ [ "minimum_latency_to_connect_servers", "find" ], [ "minimum_latency_to_connect_servers", "union" ], [ "solve", "minimum_latency_to_connect_servers" ], [ "union", "find" ] ]
4
[]
false
[]
false
pytest
false
[]
true
d75caec4e30e5b2e804b5c3fbcae78856726590a
4709b9b16bcb15f1b0fc7f8c08610685d16f4fb0
v1.0
instruct
Code_Contests
Code_Contests_25149_I
You are reading an ancient manuscript which contains numeric code sequences. The codes are represented as strings of digits, separated by spaces. You suspect that each sequence contains an embedded message, based on the frequency of digits in the sequence. Your task is to determine the most frequently occurring digit ...
def most_frequent_digit(sequences): """ For each sequence in the list, returns the most frequently occurring digit. If there is a tie, returns the smallest digit among them. """ results = [] for sequence in sequences: digit_counts = [0] * 10 for char in sequence: if c...
from solution import most_frequent_digit def test_most_frequent_digit(): sequences = [ "122333444455555", "9876543210 122333", "000111222 333444 555666" ] expected_output = ["5", "3", "0"] assert most_frequent_digit(sequences) == expected_output def test_tied_frequencies(): ...
[ { "docstring": "For each sequence in the list, returns the most frequently occurring digit.\nIf there is a tie, returns the smallest digit among them.", "function_declaration": "def most_frequent_digit(sequences):", "function_name": "most_frequent_digit", "parameter_list": "(sequences)" }, { ...
[ 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 most_frequent_digit(sequences):\n \"\"\"\n Given a list of numeric code sequences, return the most frequently occurring digit in each sequence.\n...
trial_gpt4o_3
{ "original_instruction": "", "prompt_id": "00025149", "row_id": 25149, "seed_ids": "[11031]" }
0.648593
Code_Contests_25149
I
[ "most_frequent_digit", "process_input_and_find_most_frequent" ]
2
[ [ "process_input_and_find_most_frequent", "most_frequent_digit" ] ]
1
[]
false
[]
false
pytest
true
[]
true
75988b3cf3e82a9af169144fb5926d12353fbcf3
d9d9b582604e226bb1d9b151c123f05ca68ed7f4
v1.0
instruct
Code_Contests
Code_Contests_25159_I
Space Mining Robotics A space mining company has developed advanced mining robots to autonomously extract valuable minerals from asteroids. Each mining robot operates by moving through a grid-like path on the surface of an asteroid. The grid is represented by a 2D matrix where each cell contains an integer value indic...
def max_minerals(matrix): """ Given a 2D list representing the mineral quantities in a grid, computes the maximum quantity of minerals the robot can collect from the top-left to the bottom-right corner. """ if not matrix: return 0 n = len(matrix) m = len(matrix[0]) # Create...
def test_max_minerals(): matrix1 = [ [1, 3, 1, 2], [1, 5, 1, 3], [4, 2, 1, 4], ] matrix2 = [ [2, 4], [0, 3], ] assert max_minerals(matrix1) == 17 assert max_minerals(matrix2) == 9 def test_process_input(): input_data = "3 4\n1 3 1 2\n1 5 1 3\n4 2 1 4\...
[ { "docstring": "Given a 2D list representing the mineral quantities in a grid,\ncomputes the maximum quantity of minerals the robot can collect\nfrom the top-left to the bottom-right corner.", "function_declaration": "def max_minerals(matrix):", "function_name": "max_minerals", "parameter_list": "(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 max_minerals(matrix):\n \"\"\"\n Given a 2D list representing the mineral quantities in a grid,\n computes the maximum quantity of minerals th...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00025159", "row_id": 25159, "seed_ids": "[2596]" }
0.602187
Code_Contests_25159
I
[ "max_minerals", "process_input", "space_mining_robots" ]
3
[ [ "space_mining_robots", "max_minerals" ], [ "space_mining_robots", "process_input" ] ]
2
[ "process_input" ]
false
[]
false
pytest
false
[]
true
98631d2664b58f0ffc45f64a1b71cfb5fe5ca845
d654c4a281835933cfc560544474ff64d5d02470
v1.0
instruct
Code_Contests
Code_Contests_25253_I
**Problem Description:** You are given a matrix with `n` rows and `m` columns, containing only 0s and 1s. Your task is to find the maximum area of a rectangle composed entirely of 1s in the matrix. ### Input: - First line contains two integers `n` and `m`, the number of rows and columns respectively. - Each of the nex...
def maximal_rectangle(matrix): if not matrix: return 0 n = len(matrix) m = len(matrix[0]) max_area = 0 heights = [0] * m for i in range(n): for j in range(m): heights[j] = heights[j] + 1 if matrix[i][j] == 1 else 0 max_area = max(max_area, largest_r...
from solution import maximal_rectangle def test_maximal_rectangle_example(): matrix = [ [1, 0, 1, 0, 0], [1, 0, 1, 1, 1], [1, 1, 1, 1, 1], [1, 0, 0, 1, 0] ] assert maximal_rectangle(matrix) == 6 def test_maximal_rectangle_single_column(): matrix = [ [1], ...
[ { "docstring": null, "function_declaration": "def maximal_rectangle(matrix):", "function_name": "maximal_rectangle", "parameter_list": "(matrix)" }, { "docstring": null, "function_declaration": "def largest_rectangle_area(heights):", "function_name": "largest_rectangle_area", "pa...
[ 1, 1, 0 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def maximal_rectangle(matrix):\n if not matrix:\n return 0\n\n n = len(matrix)\n m = len(matrix[0])\n max_area = 0\n heights = [0] * ...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00025253", "row_id": 25253, "seed_ids": "[628]" }
0.741232
Code_Contests_25253
I
[ "maximal_rectangle", "largest_rectangle_area" ]
2
[ [ "maximal_rectangle", "largest_rectangle_area" ] ]
1
[]
false
[]
false
pytest
true
[]
true
6f061ac6f34f2787048849a587a0132511f41750
31c07d6c0a5991ebc72d0e5e14799c301694f090
v1.0
instruct
Code_Contests
Code_Contests_25311_I
The kingdom of Astoria has a network of N towns connected by M bidirectional roads. Each road connects exactly two towns and different roads can connect the same pair of towns. Schedules for travelling on each road are precisely maintained. The king wants to arrange messengers who can disseminate royal decrees to every...
def find(parent, i): if parent[i] == i: return i else: return find(parent, parent[i]) def union(parent, rank, x, y): xroot = find(parent, x) yroot = find(parent, y) if rank[xroot] < rank[yroot]: parent[xroot] = yroot elif rank[xroot] > rank[yroot]: p...
import pytest from solution import minimum_travel_time def test_minimum_travel_time_example(): n = 4 m = 5 roads = [ (1, 2, 1), (2, 3, 2), (3, 4, 2), (1, 3, 2), (1, 4, 3) ] assert minimum_travel_time(n, m, roads) == 5 def test_minimum_travel_time_single_road...
[ { "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": "def find(parent, i):\n if parent[i] == i:\n return i\n else:\n return find(parent, parent[i])\n \ndef union(parent, rank, x, y):...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00025311", "row_id": 25311, "seed_ids": "[4226]" }
0.726913
Code_Contests_25311
I
[ "find", "union", "kruskal", "minimum_travel_time" ]
4
[ [ "kruskal", "find" ], [ "kruskal", "union" ], [ "minimum_travel_time", "kruskal" ], [ "union", "find" ] ]
4
[]
false
[]
false
pytest
true
[]
true
15c643bd278e205bd442f6f890918cab2034a67b
de09c1de14eb068b5e3e12957293db63fd3cab5d
v1.0
instruct
Code_Contests
Code_Contests_25325_I
Joan is a math enthusiast who loves working with prime numbers. She recently learned about twin primes, which are pairs of prime numbers that have a difference of 2. For example, (3, 5), (11, 13), and (17, 19) are twin primes. Joan wants to find out how many twin prime pairs exist in a given range [L, R]. She is askin...
def sieve_of_eratosthenes(n): """ Generate a list of booleans representing whether numbers are prime up to n. """ is_prime = [True] * (n+1) p = 2 while (p * p <= n): if (is_prime[p] == True): for i in range(p * p, n+1, p): is_prime[i] = False p += 1 ...
from solution import twin_prime_pairs def test_example_case(): assert twin_prime_pairs(3, [(1, 10), (11, 20), (1, 100)]) == [2, 2, 8] def test_no_twin_primes(): assert twin_prime_pairs(1, [(14, 16)]) == [0] def test_single_digit_range(): assert twin_prime_pairs(1, [(1, 10)]) == [2] def test_large_range(...
[ { "docstring": "Generate a list of booleans representing whether numbers are prime up to n.", "function_declaration": "def sieve_of_eratosthenes(n):", "function_name": "sieve_of_eratosthenes", "parameter_list": "(n)" }, { "docstring": null, "function_declaration": "def count_twin_primes(...
[ 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 sieve(n):\n \"\"\"\n Implements the Sieve of Eratosthenes to generate a list of primes up to n.\n \"\"\"\n is_prime = [True] * (n + 1)\n ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00025325", "row_id": 25325, "seed_ids": "[3249]" }
0.685227
Code_Contests_25325
I
[ "sieve_of_eratosthenes", "count_twin_primes", "twin_prime_pairs" ]
3
[ [ "twin_prime_pairs", "count_twin_primes" ], [ "twin_prime_pairs", "sieve_of_eratosthenes" ] ]
2
[]
false
[]
false
pytest
true
[]
true
5f3a90e6e2eee81de3b2a04c926e872b58359a28
16380f695c8424019d9d8eaf878afba67046c7d7
v1.0
instruct
Code_Contests
Code_Contests_25327_I
You are given a series of integers. Your task is to identify the first and last positions of a given target integers in this series and return them as a tuple. The given series of integers is guaranteed to be sorted in non-decreasing order. Write a function `find_positions` that takes in two arguments - a list of inte...
from typing import List, Tuple def find_first_position(nums: List[int], target: int) -> int: left, right = 0, len(nums) - 1 first_pos = -1 while left <= right: mid = (left + right) // 2 if nums[mid] < target: left = mid + 1 elif nums[mid] > target: right...
def test_find_positions(): nums = [5, 7, 7, 8, 8, 10] target = 8 assert find_positions(nums, target) == (3, 4) def test_find_positions_not_found(): nums = [5, 7, 7, 8, 8, 10] target = 6 assert find_positions(nums, target) == (-1, -1) def test_find_positions_all_elements_match(): nu...
[ { "docstring": null, "function_declaration": "def find_first_position(nums, target):", "function_name": "find_first_position", "parameter_list": "(nums, target)" }, { "docstring": null, "function_declaration": "def find_last_position(nums, target):", "function_name": "find_last_posit...
[ 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 typing import List, Tuple\n\ndef find_positions(nums: List[int], target: int) -> Tuple[int, int]:\n \"\"\"\n Finds the first and last positions ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00025327", "row_id": 25327, "seed_ids": "[8446]" }
0.647646
Code_Contests_25327
I
[ "find_first_position", "find_last_position", "find_positions" ]
3
[ [ "find_positions", "find_first_position" ], [ "find_positions", "find_last_position" ] ]
2
[]
false
[]
false
pytest
false
[]
true
8211cfa968e207427bba3227923187e67f7e735d
49f5242f2e16fd6993df6ce0158b9bf947b1a497
v1.0
instruct
Code_Contests
Code_Contests_25378_I
You are given a string that represents a chemical formula containing various elements, where the occurrence of each element is denoted by an integer immediately following the element's symbol (if the integer is omitted, the count is assumed to be 1). The elements inside parentheses indicate groupings where the number f...
import re from collections import defaultdict def parse_formula(formula): def parse(): stack = [defaultdict(int)] i = 0 while i < len(formula): if formula[i] == '(': stack.append(defaultdict(int)) i += 1 elif formula[i] == ')': ...
from solution import chemical_formula def test_simple_formula(): result = chemical_formula("H2O") assert result == ["H 2", "O 1"] def test_complex_formula(): result = chemical_formula("K4(ON(SO3)2)2") assert result == ["K 4", "N 2", "O 14", "S 4"] def test_single_element(): result = chemical_form...
[ { "docstring": null, "function_declaration": "def parse_formula(formula):", "function_name": "parse_formula", "parameter_list": "(formula)" }, { "docstring": null, "function_declaration": "def chemical_formula(formula):", "function_name": "chemical_formula", "parameter_list": "(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": "import re\nfrom collections import defaultdict\n\ndef parse_formula(formula):\n def parse():\n stack = [defaultdict(int)]\n i = 0\n ...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00025378", "row_id": 25378, "seed_ids": "[7118]" }
0.568944
Code_Contests_25378
I
[ "parse_formula", "chemical_formula" ]
2
[ [ "chemical_formula", "parse_formula" ] ]
1
[]
false
[]
false
pytest
true
[]
true
c1cd34966fad17af15b06ffc318f661a77485579
3722450e079a985ea6049ba25c0b5e50016d58cd
v1.0
instruct
Code_Contests
Code_Contests_25397_I
You are given two binary trees, T1 and T2. Write a function to check if T2 is a subtree of T1. A subtree of T1 is a tree consisting of a node in T1 and all of this node's descendants. The tree T1 could also be considered as a subtree of itself. Input - `T1` and `T2` are binary trees, represented as linked structures w...
class TreeNode: def __init__(self, val=0, left=None, right=None): self.val = val self.left = left self.right = right def isSubtree(T1, T2): if not T2: return True # An empty tree is always a subtree if not T1: return False # Non-empty T2 can't be a subtree of an em...
from solution import TreeNode, isSubtree def test_isSubtree_T2_is_subtree(): T1 = TreeNode(3) T1.left = TreeNode(4) T1.right = TreeNode(5) T1.left.left = TreeNode(1) T1.left.right = TreeNode(2) T2 = TreeNode(4) T2.left = TreeNode(1) T2.right = TreeNode(2) assert isSubtree(...
[]
[ 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_2
{ "original_instruction": "", "prompt_id": "00025397", "row_id": 25397, "seed_ids": "[9127]" }
0.577267
Code_Contests_25397
I
[ "isSubtree", "isSameTree" ]
2
[ [ "isSubtree", "isSameTree" ] ]
1
[]
false
[ "TreeNode" ]
true
pytest
true
[]
true
382353bc680543787df9300ee30b9d90414e734c
dc4213b2e2a57a56dbb00303af7a27074540c129
v1.0
instruct
Code_Contests
Code_Contests_25402_I
A famous online puzzle game consists of a grid of characters representing a river with logs, rocks, and empty spaces. The grid is made up of `N` rows and `M` columns. Each cell on the grid can be one of the following: - `L`: Represents a log. - `R`: Represents a rock. - `.`: Represents an empty space. The goal is to ...
def is_path_possible(grid, N, M): from collections import deque directions = [(-1, 0), (1, 0), (0, -1), (0, 1)] queue = deque([(0, 0)]) visited = set((0, 0)) while queue: r, c = queue.popleft() if (r, c) == (N-1, M-1): return "YES" for dr, dc in dir...
def test_is_path_possible(): input1 = "5 5\nL..R.\nRL..R\nR.RLL\nLL.RL\n....L" input2 = "4 4\nL.R.\n.RL.\nRLR.\n.LRR" input3 = "1 1\nL" input4 = "2 2\nLR\nRR" assert navigate_river(input1) == "YES" assert navigate_river(input2) == "NO" assert navigate_river(input3) == "YES" assert naviga...
[ { "docstring": null, "function_declaration": "def is_path_possible(grid, N, M):", "function_name": "is_path_possible", "parameter_list": "(grid, N, M)" }, { "docstring": null, "function_declaration": "def navigate_river(grid_input):", "function_name": "navigate_river", "parameter...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_path_possible(grid, N, M):\n from collections import deque\n\n directions = [(-1, 0), (1, 0), (0, -1), (0, 1)]\n queue = deque([(0, 0)])\n ...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00025402", "row_id": 25402, "seed_ids": "[5718]" }
0.752135
Code_Contests_25402
I
[ "is_path_possible", "navigate_river" ]
2
[ [ "navigate_river", "is_path_possible" ] ]
1
[]
false
[]
false
pytest
false
[]
true
cd8f787433d0a806b7070732f30942eb1fbf63c4
d3cf097e834be5d61e93e1347b851af30f151d84
v1.0
instruct
Code_Contests
Code_Contests_25526_I
Graph Shortest Path Delivery In a city, there are N buildings connected by M one-way roads. The roads potentially have different lengths, and they form a directed graph. One of these buildings, labeled as the "Start Building," is where delivery starts. The goal is to deliver a package to the "Target Building" as quick...
import heapq def dijkstra(graph, start, end, n): """ Dijkstra's algorithm to find the shortest path from start to end. """ INF = float('inf') dist = [INF] * (n + 1) dist[start] = 0 priority_queue = [(0, start)] while priority_queue: current_dist, current_node = heapq.heappo...
from solution import process_input_and_find_paths def test_case_1(): input_data = "4 4 3\n1 2 4\n1 3 2\n2 3 5\n3 4 1\n1 4\n2 3\n3 2\n0 0 0" expected_output = [3, 5, "NO PATH"] assert process_input_and_find_paths(input_data) == expected_output def test_case_no_path(): input_data = "3 2 1\n1 2 1\n2 3 1\...
[ { "docstring": "Dijkstra's algorithm to find the shortest path from start to end.", "function_declaration": "def dijkstra(graph, start, end, n):", "function_name": "dijkstra", "parameter_list": "(graph, start, end, n)" }, { "docstring": "Returns shortest paths for each query.", "function...
[ 0, 0, 1 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "import heapq\n\ndef shortest_path_delivery(N, M, edges, queries):\n def dijkstra(start, end):\n if start == end:\n return 0\n d...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00025526", "row_id": 25526, "seed_ids": "[11555]" }
0.735222
Code_Contests_25526
I
[ "dijkstra", "find_shortest_paths", "process_input_and_find_paths" ]
3
[ [ "find_shortest_paths", "dijkstra" ], [ "process_input_and_find_paths", "find_shortest_paths" ] ]
2
[]
false
[]
false
pytest
true
[]
true
2cd7e5e34bbd809d6f872a13fc084732a1e1e1ae
d92e9b92012971d7368c80d08bf89a4595af05a7
v1.0
instruct
Code_Contests
Code_Contests_25527_I
Petya and Gena are playing a survival game on a grid. The grid is an n x m matrix, where each cell either contains an obstacle or is empty. Petya starts at the top-left cell of the grid and needs to reach the bottom-right cell. Petya can only move right or down. If Petya moves onto an obstacle cell, she loses the game....
def unique_paths_with_obstacles(grid): """ Returns the number of unique paths from the top-left to the bottom-right corner of the grid, avoiding obstacles. """ n = len(grid) m = len(grid[0]) # Special case for a 1x1 grid with no obstacle. if n == 1 and m == 1: return 1 if grid[...
from solution import count_paths def test_simple_case(): assert count_paths(3, 3, [ "000", "010", "000" ]) == 2 def test_no_paths_due_to_obstacles(): assert count_paths(3, 3, [ "011", "110", "000" ]) == 0 def test_single_path(): assert count_pat...
[ { "docstring": "Returns the number of unique paths from the top-left to the bottom-right corner \nof the grid, avoiding obstacles.", "function_declaration": "def unique_paths_with_obstacles(grid):", "function_name": "unique_paths_with_obstacles", "parameter_list": "(grid)" }, { "docstring": ...
[ 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 unique_paths(n, m, grid):\n # Create a 2D dp array initialized with 0\n dp = [[0]*m for _ in range(n)]\n \n # Starting position\n dp[0][...
trial_gpt4o_7
{ "original_instruction": "", "prompt_id": "00025527", "row_id": 25527, "seed_ids": "[12645]" }
0.752197
Code_Contests_25527
I
[ "unique_paths_with_obstacles", "count_paths" ]
2
[ [ "count_paths", "unique_paths_with_obstacles" ] ]
1
[]
false
[]
false
pytest
true
[]
true
d6c56529656c587cdfd395617f02addcaf681015
38ed162116154238960fb1b28172a8c6b5e35e74
v1.0
instruct
Code_Contests
Code_Contests_25533_I
Given an undirected graph G = (V, E) representing a network of computers and connections between them, find the largest Bipartite Subgraph. A Bipartite Graph is a graph whose vertices can be divided into two disjoint sets U and V such that no two vertices within the same set are adjacent. Constraints * 1 ≤ |V| ≤ 100 ...
from collections import defaultdict, deque def is_bipartite(graph, src, color): """ Helper function to check if the graph is bipartite starting from the source vertex. """ q = deque([src]) color[src] = 1 # Start coloring with 1 while q: node = q.popleft() for neig...
def test_bipartite_subgraph(): vertices = 4 edges_list = [ (0, 1), (0, 2), (1, 2), (1, 3), (2, 3), (3, 0) ] assert bipartite_subgraph(vertices, edges_list) == 5 vertices = 5 edges_list = [ (0, 1), (0, 2), (0, 3), ...
[ { "docstring": "Helper function to check if the graph is bipartite starting from the source vertex.", "function_declaration": "def is_bipartite(graph, src, color):", "function_name": "is_bipartite", "parameter_list": "(graph, src, color)" }, { "docstring": "Function to find the largest bipar...
[ 0, 0, 0, 0, 0, 1, 0, 0, 1, 0 ]
2
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def largest_bipartite_subgraph(V, E, edges):\n from collections import defaultdict, deque\n\n def bfs_check(start):\n color = {}\n queu...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00025533", "row_id": 25533, "seed_ids": "[415]" }
0.539331
Code_Contests_25533
I
[ "is_bipartite", "bipartite_subgraph" ]
2
[ [ "bipartite_subgraph", "is_bipartite" ] ]
1
[]
false
[]
false
pytest
false
[]
true
32412e35f3bdab711a3bf8a39ea430a14adf0644
147479b36ea50016d329de64342ba98b2f1ca4e8
v1.0
instruct
Code_Contests
Code_Contests_25619_I
F: Sequence Transformation Problem Statement You are given an array A of N integers. Your task is to transform this array into another array B of length N such that the following conditions are satisfied: 1. For every 1 <= i <= N, B[i] = A[i] + max(0, B[i-1] - (i-1)), where B[0] is considered 0. 2. The final array B...
MOD = 10**9 + 7 def count_distinct_arrays(N, A): """ Determines the number of distinct arrays B that can be generated following the rules. B[i] = A[i] + max(0, B[i-1] - (i-1)) for 1 <= i <= N where B[0] is considered 0. """ B = [] prev_B = 0 for i in range(1, N+1): current_B = A[i-...
from solution import sequence_transformation def test_sample1(): assert sequence_transformation(3, [1, 2, 3]) == 1 def test_sample2(): assert sequence_transformation(2, [1000000000, 1000000000]) == 1 def test_sample3(): assert sequence_transformation(4, [1, 2, 2, 3]) == 0 def test_sample4(): assert ...
[ { "docstring": "Determines the number of distinct arrays B that can be generated following the rules.\nB[i] = A[i] + max(0, B[i-1] - (i-1)) for 1 <= i <= N where B[0] is considered 0.", "function_declaration": "def count_distinct_arrays(N, A):", "function_name": "count_distinct_arrays", "parameter_l...
[ 0, 1 ]
1
medium
0.5
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def count_distinct_arrays(N, A):\n MOD = 10**9 + 7\n \n # Initialize set for calculated B. We start with one empty state\n dp = set([0])\n \...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00025619", "row_id": 25619, "seed_ids": "[13325]" }
0.681719
Code_Contests_25619
I
[ "count_distinct_arrays", "sequence_transformation" ]
2
[ [ "sequence_transformation", "count_distinct_arrays" ] ]
1
[]
false
[]
false
pytest
true
[]
true
0e633ef1599846e3a5cb091e148bd841fc1335ad
e1293f4a5340c0f40443e29b4e7502bb2e098fe3
v1.0
instruct
Code_Contests
Code_Contests_25655_I
A well-known software company has developed a new encryption algorithm known as the Circular Caesar Cipher (CCC). This encryption method shifts the characters in the plaintext by a fixed number of positions down the alphabet while wrapping around to the beginning. For instance, with a shift of 3, 'A' would transform in...
def encrypt(plaintext, shift): encrypted_text = [] for char in plaintext: if char == ' ': encrypted_text.append(' ') else: new_pos = (ord(char) - ord('a') + shift) % 26 new_char = chr(new_pos + ord('a')) encrypted_text.append(new_char) return '...
import pytest from solution import encrypt, decrypt, process_test_cases def test_encrypt(): assert encrypt("hello world", 3) == "khoor zruog" assert encrypt("abc xyz", 5) == "fgh cde" assert encrypt("a", 1) == "b" assert encrypt("z", 1) == "a" assert encrypt(" ", 1) == " " assert encrypt("abcde...
[ { "docstring": null, "function_declaration": "def encrypt(plaintext, shift):", "function_name": "encrypt", "parameter_list": "(plaintext, shift)" }, { "docstring": null, "function_declaration": "def decrypt(encrypted_text, shift):", "function_name": "decrypt", "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 circular_caesar_cipher_encrypt(shift, plaintext):\n encrypted_text = []\n for char in plaintext:\n if char == ' ':\n encrypted_...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00025655", "row_id": 25655, "seed_ids": "[134]" }
0.666183
Code_Contests_25655
I
[ "encrypt", "decrypt", "process_test_cases" ]
3
[ [ "process_test_cases", "decrypt" ], [ "process_test_cases", "encrypt" ] ]
2
[ "process_test_cases" ]
false
[]
false
pytest
true
[]
true
06540bc3f2984d66a78911ed712770673060c40a
bba91955528f3bad036427fc9996759b027e5b60