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_32616_I | Island Connectivity
You are given an archipelago of islands connected by a network of bridges. Each bridge has a certain travel cost associated with it. There are n islands and m bridges connecting pairs of islands. Find the minimum cost required to make all islands accessible from any other island, effectively creati... | def find(parent, i):
if parent[i] == i:
return i
return find(parent, parent[i])
def union(parent, rank, x, y):
rootX = find(parent, x)
rootY = find(parent, y)
if rootX != rootY:
if rank[rootX] > rank[rootY]:
parent[rootY] = rootX
elif rank[rootX] < rank[root... | def test_minimum_cost_possible():
bridges = [
(1, 2, 5),
(1, 3, 10),
(1, 4, 15),
(2, 3, 9),
(3, 4, 4)
]
assert min_cost_to_connect_islands(4, 5, bridges) == 18
def test_single_island():
bridges = []
assert min_cost_to_connect_islands(1, 0, bridges) == 0
def ... | [
{
"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": "00032616",
"row_id": 32616,
"seed_ids": "[6136]"
} | 0.804455 | Code_Contests_32616 | I | [
"find",
"union",
"min_cost_to_connect_islands"
] | 3 | [
[
"min_cost_to_connect_islands",
"find"
],
[
"min_cost_to_connect_islands",
"union"
],
[
"union",
"find"
]
] | 3 | [] | false | [] | false | pytest | false | [] | true | bbe7dfc6a811e55b64e667bbe1dd12b88507f428 | c549730feca0b72678efbc51f34cb2577693974d | |||
v1.0 | instruct | Code_Contests | Code_Contests_32624_I | Given a directed graph with N nodes and M edges, where each edge has an associated cost, determine the minimum cost to travel from a starting node S to a target node T. If there is no path from S to T, return -1.
Constraints:
* 1 ≤ N, M ≤ 1000
* 1 ≤ edge cost ≤ 10^6
* Input includes S and T, the start and target node... | import heapq
def dijkstra(graph, start, target):
pq = [(0, start)]
dist = {node: float('inf') for node in graph}
dist[start] = 0
visited = set()
while pq:
current_dist, current_node = heapq.heappop(pq)
if current_node in visited:
continue
visited.add(c... | from solution import find_minimum_cost_to_travel
def test_case_1():
N = 4
M = 4
edges = [(1, 2, 10), (1, 3, 5), (2, 3, 2), (3, 4, 1)]
S = 1
T = 4
assert find_minimum_cost_to_travel(N, M, edges, S, T) == 6
def test_case_2():
N = 3
M = 2
edges = [(1, 2, 4), (2, 3, 3)]
S = 1
T... | [
{
"docstring": null,
"function_declaration": "def dijkstra(graph, start, target):",
"function_name": "dijkstra",
"parameter_list": "(graph, start, target)"
},
{
"docstring": null,
"function_declaration": "def find_minimum_cost_to_travel(N, M, edges, S, T):",
"function_name": "find_mi... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import heapq\nfrom collections import defaultdict\n\ndef dijkstra(N, edges, S, T):\n \"\"\"\n Determines the minimum cost to travel from node S to no... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00032624",
"row_id": 32624,
"seed_ids": "[8933]"
} | 0.755543 | Code_Contests_32624 | I | [
"dijkstra",
"find_minimum_cost_to_travel"
] | 2 | [
[
"find_minimum_cost_to_travel",
"dijkstra"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 28dec4f135e7e1f8b6ba0ffb13fd3be882d261ae | 0c47c03a85ac521be3f680bbc72721ff440b74c5 | |||
v1.0 | instruct | Code_Contests | Code_Contests_32650_I | A company is organizing a series of workshops for its employees. Each workshop has an associated benefit score representing how beneficial it is. Employees can attend multiple workshops, but no two workshops can overlap in time.
Each workshop is defined by its start time, end time, and benefit score. The goal is to de... | from bisect import bisect_right
def max_benefit(workshops):
workshops.sort(key=lambda x: x[1]) # Sort by end time
# Prepare for DP
end_times = [w[1] for w in workshops]
dp = [0] * (len(workshops) + 1)
for i in range(1, len(workshops) + 1):
# Current workshop details
s_i, ... | import pytest
from solution import calculate_max_benefit
def test_single_workshop():
assert calculate_max_benefit(1, [(1, 2, 100)]) == 100
def test_non_overlapping_workshops():
assert calculate_max_benefit(3, [(1, 2, 50), (3, 4, 60), (5, 6, 70)]) == 180
def test_all_overlapping_workshops():
assert calcul... | [
{
"docstring": null,
"function_declaration": "def max_benefit(workshops):",
"function_name": "max_benefit",
"parameter_list": "(workshops)"
},
{
"docstring": null,
"function_declaration": "def calculate_max_benefit(n, workshop_list):",
"function_name": "calculate_max_benefit",
"p... | [
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_benefit(workshops):\n workshops.sort(key=lambda x: x[1]) # Sort workshops based on end times\n\n from bisect import bisect_right\n\n n = ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00032650",
"row_id": 32650,
"seed_ids": "[638]"
} | 0.745759 | Code_Contests_32650 | I | [
"max_benefit",
"calculate_max_benefit"
] | 2 | [
[
"calculate_max_benefit",
"max_benefit"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 301cbbc6fdf25c036daa845bcf98472ef9e72df6 | 2a5f075efd8a3577221d0333bb0c993df76423de | |||
v1.0 | instruct | Code_Contests | Code_Contests_32681_I | A road consists of connected segments. Each segment directly connects two intersections except for ramp segments which directly connect an intersection with the skyway or the ground. You need to determine how long a truck can travel on the ground segments without using any ramp segments.
You will be given the list of ... | import math
def calculate_distance(x1, y1, x2, y2):
return math.sqrt((x2 - x1) ** 2 + (y2 - y1) ** 2)
def maximum_ground_distance(segments, start_x, start_y):
graph = {}
ground_segments = []
for (x1, y1, x2, y2, t) in segments:
if t == "ground":
ground_segments.append((x1, y1, x2,... | from solution import maximum_ground_distance, handle_input
def test_maximum_ground_distance():
assert maximum_ground_distance([(0, 0, 1, 1, 'ground'), (1, 1, 2, 2, 'ground'), (2, 2, 3, 3, 'ramp'), (0, 0, 0, 1, 'ramp'), (0, 0, 1, 0, 'ground')], 0, 0) == 2.828
def test_handle_input():
inputs = [
"5",
... | [
{
"docstring": null,
"function_declaration": "def calculate_distance(x1, y1, x2, y2):",
"function_name": "calculate_distance",
"parameter_list": "(x1, y1, x2, y2)"
},
{
"docstring": null,
"function_declaration": "def maximum_ground_distance(segments, start_x, start_y):",
"function_na... | [
1,
1,
0
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import math\n\ndef calculate_distance(x1, y1, x2, y2):\n return math.sqrt((x2 - x1) ** 2 + (y2 - y1) ** 2)\n\ndef maximum_ground_distance(segments, star... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00032681",
"row_id": 32681,
"seed_ids": "[9572]"
} | 0.656442 | Code_Contests_32681 | I | [
"calculate_distance",
"maximum_ground_distance",
"handle_input"
] | 3 | [
[
"handle_input",
"maximum_ground_distance"
],
[
"maximum_ground_distance",
"calculate_distance"
]
] | 2 | [
"handle_input"
] | false | [] | false | pytest | true | [] | true | 61172ab67ec0c5e3a2403ab7209de017367869ce | 1626ccc16b96ca85f977a65587284d62fbdba215 | |||
v1.0 | instruct | Code_Contests | Code_Contests_32692_I | You are given a matrix with n rows and m columns. In each cell, there is either a 0 or a 1.
Your task is to determine the largest possible submatrix which contains only 1s.
Input:
The first line contains two integers n and m (1 ≤ n, m ≤ 500) — the number of rows and columns of the matrix.
Each of the next n lines c... | def maximalRectangle(matrix):
"""
Given a matrix containing only 0s and 1s, find the largest rectangular area containing only 1s.
"""
if not matrix or not matrix[0]:
return 0
n = len(matrix)
m = len(matrix[0])
max_area = 0
heights = [0] * m
for i in range(n):
... | import pytest
def test_maximalRectangle_empty_matrix():
assert maximalRectangle([]) == 0
assert maximalRectangle([[]]) == 0
def test_maximalRectangle_single_element():
assert maximalRectangle([['0']]) == 0
assert maximalRectangle([['1']]) == 1
def test_maximalRectangle_all_zeros():
assert maximal... | [
{
"docstring": "Given a matrix containing only 0s and 1s, find the largest rectangular area containing only 1s.",
"function_declaration": "def maximalRectangle(matrix):",
"function_name": "maximalRectangle",
"parameter_list": "(matrix)"
},
{
"docstring": "Helper function to calculate the lar... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def maximalRectangle(matrix):\n if not matrix:\n return 0\n \n n, m = len(matrix), len(matrix[0])\n \n # Initialize heights matrix\n ... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00032692",
"row_id": 32692,
"seed_ids": "[9708]"
} | 0.587917 | Code_Contests_32692 | I | [
"maximalRectangle",
"largestRectangleArea"
] | 2 | [
[
"maximalRectangle",
"largestRectangleArea"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | 4155310bd76b94173a50c38fe0ac27d2e70f3ae3 | 88e7f71a4354b341a1b8ebfd8d74bd707d727d75 | |||
v1.0 | instruct | Code_Contests | Code_Contests_32697_I | Given the soaring popularity of the online game 'Fruits vs Zombies', the developers have decided to introduce a new feature: farm irrigation. In this feature, players can irrigate their fruit farms by laying pipelines, and these pipelines come with certain capacities that can transport a specified amount of water.
In ... | from collections import defaultdict, deque
def bfs(capacity, neighbors, source, sink, parent):
visited = set()
queue = deque([source])
visited.add(source)
while queue:
current = queue.popleft()
if current == sink:
return True
for adjacent in ne... | def test_solve_farm_irrigation():
assert solve_farm_irrigation(4, 5, [
(0, 1, 100),
(0, 2, 1),
(1, 2, 50),
(1, 3, 100),
(2, 3, 100)
]) == 101
assert solve_farm_irrigation(2, 1, [
(0, 1, 10)
]) == 10
assert solve_farm_irrigation(3, 3, [
(0, 1,... | [
{
"docstring": null,
"function_declaration": "def bfs(capacity, neighbors, source, sink, parent):",
"function_name": "bfs",
"parameter_list": "(capacity, neighbors, source, sink, parent)"
},
{
"docstring": null,
"function_declaration": "def max_flow(N, pipelines):",
"function_name": ... | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from collections import deque, defaultdict\n\ndef max_water_capacity(N, M, pipelines):\n graph = defaultdict(list)\n for u, v, c in pipelines:\n ... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00032697",
"row_id": 32697,
"seed_ids": "[3757]"
} | 0.627725 | Code_Contests_32697 | I | [
"bfs",
"max_flow",
"solve_farm_irrigation"
] | 3 | [
[
"max_flow",
"bfs"
],
[
"solve_farm_irrigation",
"max_flow"
]
] | 2 | [] | false | [] | false | pytest | false | [] | true | 57446e49642cd1ee47c222534182181f0638be1d | 405bc75e9c3b35af4cf91541d71348ef53eeee24 | |||
v1.0 | instruct | Code_Contests | Code_Contests_32700_I | Jack loves prime numbers and he wants to discover prime numbers in an interesting way. He came up with a method where he sums up each digit of a number and checks if the result is a prime number. Therefore, he wants your help to determine, for a given number N, whether the sum of its digits is a prime number.
You are ... | def is_prime(n):
if n <= 1:
return False
if n <= 3:
return True
if n % 2 == 0 or n % 3 == 0:
return False
i = 5
while i * i <= n:
if n % i == 0 or n % (i + 2) == 0:
return False
i += 6
return True
def sum_of_digits(n):
return sum(int(digit... | def test_is_prime():
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(4) == False
assert is_prime(11) == True
assert is_prime(25) == False
def test_sum_of_digits():
assert sum_of_digits(113) == 5
assert sum_of_digits(74) == 11
assert sum_of_digits(123456789) == 45
... | [
{
"docstring": null,
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": null,
"function_declaration": "def sum_of_digits(n):",
"function_name": "sum_of_digits",
"parameter_list": "(n)"
},
{
"docstring": null,... | [
0,
0,
0,
1,
0
] | 1 | hard | 0.2 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(number):\n \"\"\"\n Helper function to check if a given number is prime.\n \"\"\"\n if number <= 1:\n return False\n if ... | trial_gpt4o_3 | {
"original_instruction": "",
"prompt_id": "00032700",
"row_id": 32700,
"seed_ids": "[6216]"
} | 0.664538 | Code_Contests_32700 | I | [
"is_prime",
"sum_of_digits",
"check_prime_digit_sum"
] | 3 | [
[
"check_prime_digit_sum",
"is_prime"
],
[
"check_prime_digit_sum",
"sum_of_digits"
]
] | 2 | [] | false | [] | false | pytest | false | [] | true | 9cb18f7aec327f5e710ecbc123c6bcafb912e1d6 | 86a76a0d9b2790fad1baa9eccd565efbeecdbf65 | |||
v1.0 | instruct | Code_Contests | Code_Contests_32825_I | A scientist is conducting an experiment involving a large number of chemical reactions. For each reaction, a specific amount of a rare chemical ingredient is required. The experiment must re-use as much of the rare chemical as possible to avoid wastage.
The scientist has N random quantities of this rare chemical store... | def max_quantity_under_limit(test_cases):
results = []
for case in test_cases:
N, M, quantities = case
quantities = sorted(quantities, reverse=True)
best_sum = 0
def find_best_sum(index, current_sum):
nonlocal best_sum
if current_sum... | from solution import chemical_max_quantities
def test_case_1():
input_data = """3
5 10
2 3 7 8 10
4 7
1 2 3 4
3 15
5 10 20"""
expected_output = [10, 7, 15]
assert chemical_max_quantities(input_data) == expected_output
def test_case_2():
input_data = """1
3 5
1 1 1"""
expected_output = [3]
asse... | [
{
"docstring": null,
"function_declaration": "def max_quantity_under_limit(test_cases):",
"function_name": "max_quantity_under_limit",
"parameter_list": "(test_cases)"
},
{
"docstring": null,
"function_declaration": "def parse_input(input_data):",
"function_name": "parse_input",
... | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def max_sum_under_target(T, test_cases):\n def knapsack(weights, max_weight):\n n = len(weights)\n dp = [0] * (max_weight + 1)\n \n... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00032825",
"row_id": 32825,
"seed_ids": "[8855]"
} | 0.732233 | Code_Contests_32825 | I | [
"max_quantity_under_limit",
"parse_input",
"chemical_max_quantities"
] | 3 | [
[
"chemical_max_quantities",
"max_quantity_under_limit"
],
[
"chemical_max_quantities",
"parse_input"
]
] | 2 | [
"parse_input"
] | false | [] | false | pytest | true | [] | true | 49064f12e0a0eb229b9812af5d737808f6147d31 | 57d2c5423190dc458457a4b671ed6884896e0177 | |||
v1.0 | instruct | Code_Contests | Code_Contests_32895_I | You are given `n` cities and `m` roads connecting some pairs of the cities. You're required to implement a system that helps determine whether there is a path between two cities.
Each query is a pair of cities and the answer to each query is YES if there is a path connecting the two cities directly or indirectly thro... | def find_parent(parent, i):
if parent[i] == i:
return i
else:
parent[i] = find_parent(parent, parent[i])
return parent[i]
def union(parent, rank, x, y):
xroot = find_parent(parent, x)
yroot = find_parent(parent, y)
if xroot != yroot:
if rank[xroot] < rank[yroot]... | def test_connected_cities_simple_positive_case():
n, m = 5, 4
roads = [(1, 2), (2, 3), (3, 4), (4, 5)]
q = 3
queries = [(1, 5), (2, 5), (5, 1)]
assert connected_cities(n, m, roads, q, queries) == ["YES", "YES", "YES"]
def test_connected_cities_simple_negative_case():
n, m = 4, 2
roads = [(1... | [
{
"docstring": null,
"function_declaration": "def find_parent(parent, i):",
"function_name": "find_parent",
"parameter_list": "(parent, i)"
},
{
"docstring": null,
"function_declaration": "def union(parent, rank, x, y):",
"function_name": "union",
"parameter_list": "(parent, rank... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def find_set(parent, x):\n if parent[x] != x:\n parent[x] = find_set(parent, parent[x])\n return parent[x]\n\ndef union_set(parent, rank, x, y... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00032895",
"row_id": 32895,
"seed_ids": "[220]"
} | 0.759453 | Code_Contests_32895 | I | [
"find_parent",
"union",
"connected_cities"
] | 3 | [
[
"connected_cities",
"find_parent"
],
[
"connected_cities",
"union"
],
[
"union",
"find_parent"
]
] | 3 | [] | false | [] | false | pytest | false | [] | true | 0b26435a8a292862ea7cbede0a5bb53825ec0437 | 1b9fb039df2fe7941f42677ccbf0776918047bfe | |||
v1.0 | instruct | Code_Contests | Code_Contests_32912_I | An aging signal tower is configured to broadcast a vital message at regular intervals to multiple receiver towers in a remote region. The broadcast cycle is determined by the desired frequencies of each receiver tower. However, due to wear and tear, the signal tower now has to be rebooted more frequently, which casters... | import math
from functools import reduce
def lcm(a, b):
"""
Returns the least common multiple of a and b.
"""
return abs(a*b) // math.gcd(a, b)
def find_earliest_broadcast_time(n, frequencies):
"""
Returns the earliest time by which the signal tower can broadcast the next message
that sati... | from solution import find_earliest_broadcast_time
def test_single_frequency():
assert find_earliest_broadcast_time(1, [5]) == 5
def test_multiple_frequencies_example_1():
assert find_earliest_broadcast_time(4, [4, 6, 8, 12]) == 24
def test_multiple_frequencies_example_2():
assert find_earliest_broadcast_... | [
{
"docstring": "Returns the least common multiple of a and b.",
"function_declaration": "def lcm(a, b):",
"function_name": "lcm",
"parameter_list": "(a, b)"
},
{
"docstring": "Returns the earliest time by which the signal tower can broadcast the next message\nthat satisfies as many of the re... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import math\nfrom functools import reduce\n\ndef lcm(a, b):\n \"\"\"Returns the least common multiple of a and b.\"\"\"\n return a * b // math.gcd(a,... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00032912",
"row_id": 32912,
"seed_ids": "[7250]"
} | 0.54174 | Code_Contests_32912 | I | [
"lcm",
"find_earliest_broadcast_time"
] | 2 | [
[
"find_earliest_broadcast_time",
"lcm"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | fa9751cecc1c3e5e4a2504e4d64edc23d160a762 | c56d5c3b1b182a7fbaa0b08018ea5bb95d7b0bfa | |||
v1.0 | instruct | Code_Contests | Code_Contests_32922_I | Phoenix wants to develop a new algorithm for organizing his research papers. Each paper is represented by its importance level, and his goal is to be able to find and access papers of a certain importance level quickly.
To achieve this, he plans to use a binary search tree (BST) where each node represents a paper, an... | class TreeNode:
def __init__(self, val=0, left=None, right=None):
self.val = val
self.left = left
self.right = right
def sorted_array_to_bst(nums):
if not nums:
return None
mid = len(nums) // 2
root = TreeNode(nums[mid])
root.left = sorted_array_to_bst(nums... | import pytest
from solution import balanced_bst_inorder
def test_bst_with_single_element():
assert balanced_bst_inorder([1]) == [1]
def test_bst_already_balanced():
assert balanced_bst_inorder([1, 2, 3, 4, 5]) == [1, 2, 3, 4, 5]
def test_bst_already_sorted():
assert balanced_bst_inorder([10, 20, 30, 40])... | [] | [
1,
0,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "class TreeNode:\n def __init__(self, x):\n self.val = x\n self.left = None\n self.right = None\n\ndef sorted_array_to_bst(nums):\n ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00032922",
"row_id": 32922,
"seed_ids": "[2108]"
} | 0.498215 | Code_Contests_32922 | I | [
"sorted_array_to_bst",
"inorder_traversal",
"balanced_bst_inorder"
] | 3 | [
[
"balanced_bst_inorder",
"inorder_traversal"
],
[
"balanced_bst_inorder",
"sorted_array_to_bst"
]
] | 2 | [] | false | [
"TreeNode"
] | true | pytest | true | [] | true | 6108f301655f9ff69e8177ea8cd87df10b5f1705 | 24fb5020bb053626191a7c4eb9c20aef3590fe87 | |||
v1.0 | instruct | Code_Contests | Code_Contests_32932_I | A secret agent needs to transmit a message securely through an interconnected network of cities. The network is represented as a weighted undirected graph where each city is a node and each road connecting two cities is an edge with a specific weight representing the travel time.
The agent starts in a given city and ... | import heapq
import math
def is_prime(n):
"""Return True if n is a prime number."""
if n <= 1:
return False
if n <= 3:
return True
if n % 2 == 0 or n % 3 == 0:
return False
i = 5
while i * i <= n:
if n % i == 0 or n % (i + 2) == 0:
return False
... | 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(10) == False
assert is_prime(11) == True
def test_find_shortest_prime_path():
# Example case
n = 5
m = 6
t = 10
roads = [(1, 2, 3... | [
{
"docstring": "Return True if n is a prime number.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Find the shortest path from start to destination using Dijkstra's algorithm.",
"function_declaration": "def dijkstra(n... | [
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 math\n\ndef is_prime(n):\n \"\"\"Return True if n is a prime number.\"\"\"\n if n <= 1:\n return False\n if n <= 3:\n ... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00032932",
"row_id": 32932,
"seed_ids": "[4409]"
} | 0.706334 | Code_Contests_32932 | I | [
"is_prime",
"dijkstra",
"find_shortest_prime_path",
"main"
] | 4 | [
[
"find_shortest_prime_path",
"dijkstra"
],
[
"find_shortest_prime_path",
"is_prime"
]
] | 2 | [] | false | [] | false | pytest | false | [] | true | fff07e8de1ec451bcee4f7dd9e7cd148f5944fb9 | 0c6efed9a75e7340f1fe3c565497bcbbd2e9d520 | |||
v1.0 | instruct | Code_Contests | Code_Contests_32972_I | A competitive coder loves writing short scripts to solve math problems on the go. One day, the coder encountered a fascinating problem involving triangular numbers and decided to write a program to solve it.
Triangular numbers are the sequence of numbers that can form an equilateral triangle. The nth triangular number... | import math
def is_triangular(num):
if num <= 0:
return -1
# Calculate n by solving the quadratic equation n^2 + n - 2*num = 0 using the quadratic formula
n = (-1 + math.sqrt(1 + 8 * num)) / 2
if n.is_integer():
return int(n)
else:
return -1
def process_numbers(nu... | from solution import is_triangular, process_numbers
def test_is_triangular():
assert is_triangular(1) == 1
assert is_triangular(3) == 2
assert is_triangular(6) == 3
assert is_triangular(9) == -1
assert is_triangular(10) == 4
assert is_triangular(0) == -1
assert is_triangular(-5) == -1
def ... | [
{
"docstring": null,
"function_declaration": "def is_triangular(num):",
"function_name": "is_triangular",
"parameter_list": "(num)"
},
{
"docstring": null,
"function_declaration": "def process_numbers(numbers):",
"function_name": "process_numbers",
"parameter_list": "(numbers)"
... | [
0,
1,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import math\n\ndef is_triangular_number(number):\n \"\"\"\n Determines if a number is a triangular number and returns the index of the number if it i... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00032972",
"row_id": 32972,
"seed_ids": "[5298]"
} | 0.581626 | Code_Contests_32972 | I | [
"is_triangular",
"process_numbers"
] | 2 | [
[
"process_numbers",
"is_triangular"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 376cfa9f2032e48dc9d351a633ca437d6ddf6b34 | 75f63126cfa612fa28b4163b85e84c6662c8550f | |||
v1.0 | instruct | Code_Contests | Code_Contests_32991_I | You are tasked with managing a railway system. The system comprises multiple stations connected by railway tracks. Each track has a certain travel time associated with it. Passengers can board and deboard trains at each station.
You need to create a program that calculates the minimum travel time required for a train ... | import heapq
from collections import defaultdict
import sys
def dijkstra(n, graph, start, end):
pq = [(0, start)]
dist = {i: float('inf') for i in range(1, n+1)}
dist[start] = 0
while pq:
current_dist, current_station = heapq.heappop(pq)
if current_station == end:
return c... | from solution import minimum_travel_time
def test_case1():
n = 5
m = 6
tracks = [
(1, 2, 10),
(2, 3, 20),
(1, 3, 30),
(3, 4, 10),
(4, 5, 20),
(3, 5, 30)
]
start, end = 1, 5
assert minimum_travel_time(n, m, tracks, start, end) == 60
def test_case2... | [
{
"docstring": null,
"function_declaration": "def dijkstra(n, graph, start, end):",
"function_name": "dijkstra",
"parameter_list": "(n, graph, start, end)"
},
{
"docstring": null,
"function_declaration": "def minimum_travel_time(n, m, tracks, start, end):",
"function_name": "minimum_... | [
1,
1
] | 2 | easy | 1 | {
"trial_gpt4o_0": null,
"trial_gpt4o_1": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared1_results_combined.jsonl",
"solution_code": "import heapq\nfrom collections import defaultdict\nimport sys\n\ndef dijkstra(n, graph, start, end):\n pq = [(0, start)]\n d... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00032991",
"row_id": 32991,
"seed_ids": "[11884]"
} | 0.791862 | Code_Contests_32991 | I | [
"dijkstra",
"minimum_travel_time"
] | 2 | [
[
"minimum_travel_time",
"dijkstra"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 8905dd443d0d4418e10d1b7f8fe3bc36213da3fd | 6ad9b593aecad344f923eb1394adca1f1520c7bc | |||
v1.0 | instruct | Code_Contests | Code_Contests_32993_I | ### Hexagonal Quest
In the world of Hexalon, a group of adventurers is on a quest to retrieve magical artifacts located in various hexagonal cells of a vast grid. Each cell in the grid contains an artifact, and each cell can only be traversed if the player has sufficient energy to overcome the obstacle in that cell.
... | from collections import deque
def can_reach_target(grid, energy, start, target):
n = len(grid)
directions = [(-1, 0), (1, 0), (-1, 1), (-1, -1), (1, 1), (1, -1)]
queue = deque([(start[0], start[1], energy)])
visited = set()
visited.add((start[0], start[1]))
while queue:
x, y, ... | import pytest
from solution import hexagonal_quest
def test_sample_input_1():
n = 5
m = 2
grid = [
[1, 2, 3, 4, -1],
[2, 3, 4, -1, 1],
[3, 4, -1, 1, 2],
[4, -1, 1, 2, 3],
[-1, 1, 2, 3, 4]
]
players = [
(15, (1, 1), (4, 4)),
(10, (0, 0), (3, 3)... | [
{
"docstring": null,
"function_declaration": "def can_reach_target(grid, energy, start, target):",
"function_name": "can_reach_target",
"parameter_list": "(grid, energy, start, target)"
},
{
"docstring": null,
"function_declaration": "def hexagonal_quest(n, m, grid, players):",
"func... | [
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 deque\n\ndef can_reach_target(n, m, grid, players):\n \"\"\"\n Determines if each player can reach the target cell with the g... | trial_gpt4o_4 | {
"original_instruction": "",
"prompt_id": "00032993",
"row_id": 32993,
"seed_ids": "[3120]"
} | 0.692355 | Code_Contests_32993 | I | [
"can_reach_target",
"hexagonal_quest"
] | 2 | [
[
"hexagonal_quest",
"can_reach_target"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 3da68e4b0b06c9f5526aa00ddb662b000337d810 | 7caf682fcd5d2fedf7e6884d684870a143fdedc5 | |||
v1.0 | instruct | Code_Contests | Code_Contests_33015_I | You are a software engineer at a transportation logistics company called FastRoute. Your team is working on a program to optimize delivery routes for drivers by minimizing the total distance traveled while ensuring that every package is delivered efficiently. Each package has a unique delivery address within a city gri... | from itertools import permutations
import math
def calculate_manhattan_distance(x1, y1, x2, y2):
return abs(x1 - x2) + abs(y1 - y2)
def min_total_distance(n, packages, m, drivers):
# Helper function to calculate total distance for a permutation of packages
def total_distance_for_permutation(perm, packages... | from solution import min_total_distance
def test_example_1():
n = 5
packages = [(0, 0), (1, 2), (3, 3), (4, 1), (1, 1)]
m = 2
drivers = [(-1, -1, 3), (2, 2, 2)]
assert min_total_distance(n, packages, m, drivers) == 18
def test_example_2():
n = 3
packages = [(0, 0), (2, 2), (3, 3)]
m = ... | [
{
"docstring": null,
"function_declaration": "def calculate_manhattan_distance(x1, y1, x2, y2):",
"function_name": "calculate_manhattan_distance",
"parameter_list": "(x1, y1, x2, y2)"
},
{
"docstring": null,
"function_declaration": "def min_total_distance(n, packages, m, drivers):",
... | [
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 itertools\n\ndef min_total_distance(n, packages, m, drivers):\n def manhattan_distance(p1, p2):\n x1, y1 = p1\n x2, y2 = p2\n ... | trial_gpt4o_7 | {
"original_instruction": "",
"prompt_id": "00033015",
"row_id": 33015,
"seed_ids": "[466]"
} | 0.723734 | Code_Contests_33015 | I | [
"calculate_manhattan_distance",
"min_total_distance"
] | 2 | [
[
"min_total_distance",
"calculate_manhattan_distance"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 021bd154229c95375a68c7ca19582ea6fbf97e9c | eac735b06b6106542e86601c1910ec8af2b32be1 | |||
v1.0 | instruct | Code_Contests | Code_Contests_33028_I | A logistics company manages a fleet of delivery trucks and needs to optimize the timing of their deliveries. Each truck has a list of deliveries it must make during the day, and each delivery has a specific time window when it must occur. The goal is to determine if all deliveries for each truck can be completed within... | def can_complete_deliveries(deliveries):
"""
Determines if all deliveries for the truck can be completed without overlapping time windows.
:param deliveries: List of tuples where each tuple (start, end) represents the delivery time window.
:return: "Possible" if all deliveries can be made without overla... | from solution import can_complete_deliveries, optimize_delivery_timing
def test_can_complete_deliveries_possible():
assert can_complete_deliveries([(300, 400), (500, 600), (700, 800)]) == "Possible"
def test_can_complete_deliveries_impossible():
assert can_complete_deliveries([(100, 200), (150, 250)]) == "Imp... | [
{
"docstring": "Determines if all deliveries for the truck can be completed without overlapping time windows.\n:param deliveries: List of tuples where each tuple (start, end) represents the delivery time window.\n:return: \"Possible\" if all deliveries can be made without overlap, otherwise \"Impossible\".",
... | [
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_delivery_possible(trucks):\n results = []\n for deliveries in trucks:\n possible = True\n for i in range(1, len(deliveries)):\n ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00033028",
"row_id": 33028,
"seed_ids": "[13312]"
} | 0.655855 | Code_Contests_33028 | I | [
"can_complete_deliveries",
"optimize_delivery_timing"
] | 2 | [
[
"optimize_delivery_timing",
"can_complete_deliveries"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | be1a30617ced0035b097eb56a353e603050ec2d5 | 19c086156c60c7d0171f5630e1c9d8e42b6c7ba4 | |||
v1.0 | instruct | Code_Contests | Code_Contests_33029_I | You are given a binary tree with n nodes, where each node has a unique value between 1 and n. Your task is to determine the height of the tree.
The height of a binary tree is defined as the length of the longest path from the root to a leaf node. The length of a path is the number of edges in the path.
Input
The fir... | from collections import defaultdict, deque
def build_tree(edges, n):
tree = defaultdict(list)
for u, v in edges:
tree[u].append(v)
tree[v].append(u)
return tree
def get_tree_height(n, edges):
if n == 0:
return -1
if n == 1:
return 0
tree = build_tree(edges,... | from solution import get_tree_height
def test_single_node():
assert get_tree_height(1, []) == 0
def test_two_nodes():
assert get_tree_height(2, [(1, 2)]) == 1
def test_five_nodes():
assert get_tree_height(5, [(1, 2), (1, 3), (3, 4), (3, 5)]) == 2
def test_more_complex_tree():
assert get_tree_height(... | [
{
"docstring": null,
"function_declaration": "def build_tree(edges, n):",
"function_name": "build_tree",
"parameter_list": "(edges, n)"
},
{
"docstring": null,
"function_declaration": "def get_tree_height(n, edges):",
"function_name": "get_tree_height",
"parameter_list": "(n, edg... | [
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\n\ndef tree_height(n, edges):\n if n == 1:\n return 0\n\n # Create adjacency list representation of... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00033029",
"row_id": 33029,
"seed_ids": "[7724]"
} | 0.637424 | Code_Contests_33029 | I | [
"build_tree",
"get_tree_height"
] | 2 | [
[
"get_tree_height",
"build_tree"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | e39616321d2dcabc7736296a092610c741937392 | 33c84b5b6c3cfcf38dd684013800b643048f005d | |||
v1.0 | instruct | Code_Contests | Code_Contests_33041_I | You are given a rectangular grid with dimensions n x m, filled with integers. Your task is to answer q independent queries. Each query asks you to calculate the sum of the elements within a sub-rectangle of the grid. The sub-rectangle is defined by its top-left corner (r1, c1) and bottom-right corner (r2, c2).
Input:
... | def compute_prefix_sums(grid):
n = len(grid)
m = len(grid[0])
prefix_sums = [[0] * (m + 1) for _ in range(n + 1)]
for i in range(1, n + 1):
for j in range(1, m + 1):
prefix_sums[i][j] = grid[i - 1][j - 1] + prefix_sums[i - 1][j] + prefix_sums[i][j - 1] - prefix_sums[i - 1][j - 1... | from solution import solve
def test_solve_example_case():
n = 3
m = 4
grid = [
[1, 2, 3, 4],
[5, 6, 7, 8],
[9, 10, 11, 12]
]
queries = [(1, 1, 2, 2), (2, 3, 3, 4)]
expected_output = [14, 38]
assert solve(n, m, grid, queries) == expected_output
def test_solve_single_... | [
{
"docstring": null,
"function_declaration": "def compute_prefix_sums(grid):",
"function_name": "compute_prefix_sums",
"parameter_list": "(grid)"
},
{
"docstring": null,
"function_declaration": "def query_sum(prefix_sums, r1, c1, r2, c2):",
"function_name": "query_sum",
"paramete... | [
1,
1,
0
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def calculate_subrectangle_sums(n, m, grid, queries):\n # Calculate prefix sums\n prefix_sums = [[0] * (m + 1) for _ in range(n + 1)]\n \n for ... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00033041",
"row_id": 33041,
"seed_ids": "[1059]"
} | 0.737741 | Code_Contests_33041 | I | [
"compute_prefix_sums",
"query_sum",
"solve"
] | 3 | [
[
"solve",
"compute_prefix_sums"
],
[
"solve",
"query_sum"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | dac91b5e105cdb15c9fddb2d8f2c185dd38aa4e4 | 05d1b50ccc9c13083d87fce9508a1be1faebb674 | |||
v1.0 | instruct | Code_Contests | Code_Contests_33066_I | John's favorite hobby is building sandcastles. One day, while building a sandcastle with his friends, he decides to make it more challenging and fun. They plan to build a large sandcastle with several towers. Each tower is represented as a stick standing on the ground. John wants to connect some of the towers with rope... | def calculate_catalan_number(n):
"""
Calculates the n-th Catalan number.
"""
if n == 0:
return 1
catalan = [0] * (n + 1)
catalan[0] = 1
for i in range(1, n + 1):
for j in range(i):
catalan[i] += catalan[j] * catalan[i - 1 - j]
return catalan[n]
def count_ways... | import pytest
from solution import count_ways_to_connect_towers
def test_one_tower():
assert count_ways_to_connect_towers(1) == 0
def test_two_towers():
assert count_ways_to_connect_towers(2) == 1
def test_three_towers():
assert count_ways_to_connect_towers(3) == 0
def test_four_towers():
assert cou... | [
{
"docstring": "Calculates the n-th Catalan number.",
"function_declaration": "def calculate_catalan_number(n):",
"function_name": "calculate_catalan_number",
"parameter_list": "(n)"
},
{
"docstring": "Returns the number of ways to connect `n` towers with non-intersecting ropes.",
"funct... | [
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 calculate_catalan_number(n):\n \"\"\"\n Calculates the n-th Catalan number.\n \"\"\"\n if n == 0:\n return 1\n catalan = [0] * (n... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00033066",
"row_id": 33066,
"seed_ids": "[258]"
} | 0.568987 | Code_Contests_33066 | I | [
"calculate_catalan_number",
"count_ways_to_connect_towers"
] | 2 | [
[
"count_ways_to_connect_towers",
"calculate_catalan_number"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | c099dbf7c064308a511cc2839ba17a3209b85b31 | 8512f5bfc5db7c5234a7ee6d68291ac527c903f1 | |||
v1.0 | instruct | Code_Contests | Code_Contests_33076_I | The Agriculture Research Institute is conducting a study to analyze the growth patterns of various crops based on climate data collected over the years. They have developed a software application that uses series of integer sequences to model the growth pattern of crops over time.
However, due to some misconfiguration... | def find_missing_numbers(original_seq, corrupted_seq):
"""
Finds the missing numbers required to restore the corrupted sequence to match the original sequence.
"""
original_set = set(original_seq)
corrupted_set = set(corrupted_seq)
missing_numbers = sorted(original_set - corrupted_set)
retur... | from solution import find_missing_numbers, restore_sequences
def test_find_missing_numbers_example_1():
original_seq = [1, 3, 5, 7, 9]
corrupted_seq = [1, 7, 9]
assert find_missing_numbers(original_seq, corrupted_seq) == [3, 5]
def test_find_missing_numbers_example_2():
original_seq = [2, 4, 6, 8, 10,... | [
{
"docstring": "Finds the missing numbers required to restore the corrupted sequence to match the original sequence.",
"function_declaration": "def find_missing_numbers(original_seq, corrupted_seq):",
"function_name": "find_missing_numbers",
"parameter_list": "(original_seq, corrupted_seq)"
},
{... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def find_missing_numbers(original, corrupted):\n \"\"\"\n Finds the missing numbers from corrupted sequence to match the original sequence.\n \n ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00033076",
"row_id": 33076,
"seed_ids": "[11530]"
} | 0.710981 | Code_Contests_33076 | I | [
"find_missing_numbers",
"restore_sequences",
"process_input"
] | 3 | [
[
"restore_sequences",
"find_missing_numbers"
]
] | 1 | [
"process_input"
] | false | [] | false | pytest | true | [] | true | 75e6372bf4aa9b8031cb7b01bc3a58dce00a67a0 | 8907c99bec6c9ecaccdf6d1a3b6b83acc61bd3d3 | |||
v1.0 | instruct | Code_Contests | Code_Contests_33105_I | Your task is to construct a binary tree given specific traversal orders and then compute the height of the tree. You need to use the given preorder and inorder traversal sequences to reconstruct the original binary tree and then determine its height. The height of the binary tree is the number of edges on the longest p... | class TreeNode:
def __init__(self, value=0, left=None, right=None):
self.value = value
self.left = left
self.right = right
def build_tree(preorder, inorder):
if not preorder or not inorder:
return None
root_value = preorder[0]
root = TreeNode(root_value)
root_index... | from solution import find_height_of_binary_tree
def test_basic_case():
n = 5
preorder = [1, 2, 4, 5, 3]
inorder = [4, 2, 5, 1, 3]
assert find_height_of_binary_tree(n, preorder, inorder) == 3
def test_single_node():
n = 1
preorder = [1]
inorder = [1]
assert find_height_of_binary_tree(n,... | [] | [
0,
1,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "class TreeNode:\n def __init__(self, x):\n self.value = x\n self.left = None\n self.right = None\n\ndef build_tree(preorder, inorde... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00033105",
"row_id": 33105,
"seed_ids": "[5574]"
} | 0.557813 | Code_Contests_33105 | I | [
"build_tree",
"tree_height",
"find_height_of_binary_tree"
] | 3 | [
[
"find_height_of_binary_tree",
"build_tree"
],
[
"find_height_of_binary_tree",
"tree_height"
]
] | 2 | [] | false | [
"TreeNode"
] | true | pytest | true | [] | true | aee097299a8500b83d9203a88d6a65915d5a4341 | 11efba4ac089c948b13a2440801c24f711cab309 | |||
v1.0 | instruct | Code_Contests | Code_Contests_33153_I | You are given an array of integers a = [a_0, a_1, ..., a_{n - 1}] (n ≥ 1). You can perform the following operation any number of times: choose two elements a_i and a_j (i ≠ j) and replace both a_i and a_j with a_i + a_j.
Determine whether it's possible to make all elements of the array equal using the above operation.... | import math
from functools import reduce
def can_make_all_elements_equal(n, arr):
"""
Returns "YES" if it is possible to make all elements equal, otherwise "NO".
"""
gcd_all = reduce(math.gcd, arr)
return "YES" if gcd_all != 1 else "NO"
def process_test_cases(t, test_cases):
results = []
f... | import pytest
from solution import can_make_all_elements_equal, process_test_cases, input_processing
def test_can_make_all_elements_equal():
assert can_make_all_elements_equal(3, [4, 8, 12]) == "YES"
assert can_make_all_elements_equal(4, [2, 3, 6, 9]) == "NO"
assert can_make_all_elements_equal(2, [5, 10]) ... | [
{
"docstring": "Returns \"YES\" if it is possible to make all elements equal, otherwise \"NO\".",
"function_declaration": "def can_make_all_elements_equal(n, arr):",
"function_name": "can_make_all_elements_equal",
"parameter_list": "(n, arr)"
},
{
"docstring": null,
"function_declaration... | [
1,
0,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import math\nfrom functools import reduce\n\ndef gcd_of_array(arr):\n return reduce(math.gcd, arr)\n\ndef can_make_elements_equal(test_cases):\n resu... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00033153",
"row_id": 33153,
"seed_ids": "[8256]"
} | 0.779182 | Code_Contests_33153 | I | [
"can_make_all_elements_equal",
"process_test_cases",
"input_processing"
] | 3 | [
[
"process_test_cases",
"can_make_all_elements_equal"
]
] | 1 | [
"process_test_cases"
] | false | [] | false | pytest | true | [] | true | ed6685f5037b3fbba9e5df25d1069144ca1e4994 | 2d81fd4967e1639f3cf7db24d6810e3766d9b129 | |||
v1.0 | instruct | Code_Contests | Code_Contests_33215_I | In a bustling city, there are several delivery routes, each with a specific length. The city's transport manager wants to establish warehouses such that the maximum route length from any warehouse to its assigned routes is minimized. The manager can choose to place up to K warehouses.
Given the lengths of the delivery... | def canPlaceWarehouses(route_lengths, max_distance, K):
warehouses_used = 1
last_warehouse_position = route_lengths[0]
for i in range(1, len(route_lengths)):
if route_lengths[i] - last_warehouse_position > max_distance:
warehouses_used += 1
last_warehouse_position = route_le... | from solution import minimize_max_distance
def test_minimize_max_distance_case1():
T = 1
test_cases = [
(5, 2, [1, 2, 8, 10, 12])
]
result = minimize_max_distance(T, test_cases)
assert result == [4]
def test_minimize_max_distance_case2():
T = 1
test_cases = [
(5, 1, [1, 2, ... | [
{
"docstring": null,
"function_declaration": "def canPlaceWarehouses(route_lengths, max_distance, K):",
"function_name": "canPlaceWarehouses",
"parameter_list": "(route_lengths, max_distance, K)"
},
{
"docstring": null,
"function_declaration": "def minimize_max_distance(T, test_cases):",... | [
0,
0,
0,
0,
0,
1,
1,
0,
1
] | 3 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def min_max_distance(T, test_cases):\n def is_feasible(max_dist, routes, K):\n warehouses = 1\n last_warehouse = routes[0]\n \n ... | trial_gpt4o_9 | {
"original_instruction": "",
"prompt_id": "00033215",
"row_id": 33215,
"seed_ids": "[8719]"
} | 0.726602 | Code_Contests_33215 | I | [
"canPlaceWarehouses",
"minimize_max_distance"
] | 2 | [
[
"minimize_max_distance",
"canPlaceWarehouses"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | cacdbc1621eeeab49e0f176f896232b078f7c886 | 10473a8b3f02940148e797431cacacc573e6a651 | |||
v1.0 | instruct | Code_Contests | Code_Contests_33248_I | **Problem Statement**
Bob loves playing with numbers, especially finding interesting patterns within them. One day, Bob came across the concept of Happy Numbers. Bob wants to share the joy of Happy Numbers with his friends through a program that can determine whether a given number is happy or not.
A Happy Number is ... | def is_happy_number(n):
"""
Determines if a number n is a Happy Number or not.
Args:
n (int): positive integer to check for happiness.
Returns:
bool: True if n is a Happy Number, False otherwise.
"""
def get_next_number(num):
sum_of_squares = 0
while num:
... | from solution import is_happy_number, happy_number_checker
def test_is_happy_number():
assert is_happy_number(19) == True
assert is_happy_number(2) == False
assert is_happy_number(7) == True
assert is_happy_number(1) == True
assert is_happy_number(0) == False
def test_happy_number_checker():
a... | [
{
"docstring": "Determines if a number n is a Happy Number or not.\n\nArgs:\nn (int): positive integer to check for happiness.\n\nReturns:\nbool: True if n is a Happy Number, False otherwise.",
"function_declaration": "def is_happy_number(n):",
"function_name": "is_happy_number",
"parameter_list": "... | [
1,
0,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_happy_number(n):\n \"\"\"\n Determines if a number n is a Happy Number or not.\n \n Args:\n n (int): positive integer to check for ha... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00033248",
"row_id": 33248,
"seed_ids": "[619]"
} | 0.578661 | Code_Contests_33248 | I | [
"is_happy_number",
"happy_number_checker"
] | 2 | [
[
"happy_number_checker",
"is_happy_number"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 70879e44b3cd3e04b4dc7b90e619751c2c67aa3e | bd98d5286f3a27768e6e773ee163958138abb2e9 | |||
v1.0 | instruct | Code_Contests | Code_Contests_33339_I | You are tasked with helping an urban planner design an efficient bus route system to connect various hubs in a city. Each hub is represented as a node, and each possible bus route between two hubs is represented as a weighted edge, where the weight denotes the distance between the two hubs. The objective is to determin... | def find(parent, i):
if parent[i] == i:
return i
else:
return find(parent, parent[i])
def union(parent, rank, x, y):
xroot = find(parent, x)
yroot = find(parent, y)
if rank[xroot] < rank[yroot]:
parent[xroot] = yroot
elif rank[xroot] > rank[yroot]:
parent[yroot]... | def test_example1():
n, m = 4, 5
edges = [(1, 2, 3), (1, 3, 4), (4, 2, 2), (3, 2, 5), (4, 3, 1)]
assert compute_mst(n, m, edges) == 6
def test_example2():
n, m = 4, 1
edges = [(1, 2, 3)]
assert compute_mst(n, m, edges) == "IMPOSSIBLE"
def test_single_node():
n, m = 1, 0
edges = []
... | [
{
"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,
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 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_1 | {
"original_instruction": "",
"prompt_id": "00033339",
"row_id": 33339,
"seed_ids": "[1718]"
} | 0.725405 | Code_Contests_33339 | I | [
"find",
"union",
"kruskal_mst",
"compute_mst"
] | 4 | [
[
"compute_mst",
"kruskal_mst"
],
[
"kruskal_mst",
"find"
],
[
"kruskal_mst",
"union"
],
[
"union",
"find"
]
] | 4 | [] | false | [] | false | pytest | false | [] | true | 174358e0ceeffe03734899b741864029103e22de | 19d1dbfe8ff2e75000f60d055f3c728ba4774121 | |||
v1.0 | instruct | Code_Contests | Code_Contests_33352_I | ### Problem Statement:
A palindrome is a word, number, phrase, or other sequence of characters that reads the same forward and backward (ignoring spaces, punctuation, and capitalization). However, in this problem, we are interested in numeric palindromes.
Write a program to determine if a given range of numbers conta... | def is_palindrome(num):
"""
Returns True if num is a palindrome, False otherwise.
"""
return str(num) == str(num)[::-1]
def contains_palindrome(A, B):
"""
Returns 'YES' if there is at least one palindrome in the range [A, B], 'NO' otherwise.
"""
for num in range(A, B + 1):
if is... | def test_is_palindrome():
assert is_palindrome(121) == True
assert is_palindrome(123) == False
assert is_palindrome(1) == True
assert is_palindrome(101) == True
def test_contains_palindrome():
assert contains_palindrome(10, 20) == "YES"
assert contains_palindrome(5, 5) == "YES"
assert conta... | [
{
"docstring": "Returns True if num is a palindrome, False otherwise.",
"function_declaration": "def is_palindrome(num):",
"function_name": "is_palindrome",
"parameter_list": "(num)"
},
{
"docstring": "Returns 'YES' if there is at least one palindrome in the range [A, B], 'NO' otherwise.",
... | [
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 Checks if a given number is a palindrome.\n \"\"\"\n s = str(n)\n return s == s[::-1]\n\ndef contains_palin... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00033352",
"row_id": 33352,
"seed_ids": "[4553]"
} | 0.802543 | Code_Contests_33352 | I | [
"is_palindrome",
"contains_palindrome",
"palindromes_in_ranges"
] | 3 | [
[
"contains_palindrome",
"is_palindrome"
],
[
"palindromes_in_ranges",
"contains_palindrome"
]
] | 2 | [] | false | [] | false | pytest | false | [] | true | f41997de4947d054867280dae0784bc13da21d06 | 9f47012fa9a5ef5258df0e8d61242ce85b0e53e2 | |||
v1.0 | instruct | Code_Contests | Code_Contests_33357_I | A magical array is an array of integers where the sum of any two adjacent elements is a perfect square. Given an integer n, write a program to find the first n elements of a magical array starting from the integer 1. If there is no valid array possible, return an empty array.
Input
The input contains one integer n (1... | def is_perfect_square(x):
"""
Checks if a number is a perfect square.
"""
return int(x**0.5) ** 2 == x
def magical_array(n):
"""
Generates a magical array with the first n elements starting from 1.
"""
if n == 1:
return [1]
result = [1]
current = 1
while len(re... | from solution import magical_array
def test_single_element():
assert magical_array(1) == [1]
def test_two_elements():
assert magical_array(2) == [1, 3]
def test_three_elements():
assert magical_array(3) == [1, 3, 6]
def test_four_elements():
assert magical_array(4) == [1, 3, 6, 10]
def test_five_el... | [
{
"docstring": "Checks if a number is a perfect square.",
"function_declaration": "def is_perfect_square(x):",
"function_name": "is_perfect_square",
"parameter_list": "(x)"
},
{
"docstring": "Generates a magical array with the first n elements starting from 1.",
"function_declaration": "... | [
0,
0,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import math\n\ndef is_perfect_square(x):\n \"\"\"Check if x is a perfect square.\"\"\"\n root = int(math.isqrt(x))\n return root * root == x\n\nde... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00033357",
"row_id": 33357,
"seed_ids": "[4432]"
} | 0.621601 | Code_Contests_33357 | I | [
"is_perfect_square",
"magical_array"
] | 2 | [
[
"magical_array",
"is_perfect_square"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | d1adb0a3da91e3315610be11e4e8b17a90fe9e1a | c2b51026bc54ac39176937e571cc82bf0a1b25ea | |||
v1.0 | instruct | Code_Contests | Code_Contests_33364_I | You are given an integer n indicating the number of participants in a singing competition. Each participant sings a number of songs, and the score for each song is given as an integer array. You are required to find out the highest score achieved by any participant.
Input
The first line contains an integer n (1 ≤ n ≤... | def highest_score(n, participants_scores):
"""
Returns the highest score achieved by any participant.
Parameters:
n (int): Number of participants.
participants_scores (list of lists): Each inner list contains the scores of the songs sung by a participant.
Returns:
int: ... | from solution import highest_score, process_input_and_call_highest_score
def test_highest_score_simple():
input_str = "3\n4 34 67 90 100\n2 56 88\n3 23 45 78"
assert process_input_and_call_highest_score(input_str) == 100
def test_highest_score_all_same_scores():
input_str = "3\n1 50\n1 50\n1 50"
asser... | [
{
"docstring": "Returns the highest score achieved by any participant.\n\nParameters:\n n (int): Number of participants.\n participants_scores (list of lists): Each inner list contains the scores of the songs sung by a participant.\n\nReturns:\n int: The highest score achieved by any participant.",
... | [
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 highest_score(n, scores):\n \"\"\"\n Finds the highest score achieved by any participant.\n\n Parameters:\n n (int): Number of participants... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00033364",
"row_id": 33364,
"seed_ids": "[5351]"
} | 0.708997 | Code_Contests_33364 | I | [
"highest_score",
"process_input_and_call_highest_score"
] | 2 | [
[
"process_input_and_call_highest_score",
"highest_score"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 9c695ed3b197e0f76090fc0701bfe7e4e8c69a29 | 7ca22359251a2305465a39d21399b105f5c3721f | |||
v1.0 | instruct | Code_Contests | Code_Contests_33401_I | Lena has a unique interest in prime numbers. She recently discovered an interesting property regarding Twin Primes. Twin Primes are pairs of primes that have a difference of 2. For example, (3, 5) and (11, 13) are twin primes.
Lena wants to develop a program that can find all pairs of twin primes within a given range ... | import math
def is_prime(n):
if n <= 1:
return False
if n <= 3:
return True
if n % 2 == 0 or n % 3 == 0:
return False
i = 5
while i * i <= n:
if n % i == 0 or n % (i + 2) == 0:
return False
i += 6
return True
def find_twin_primes(l, r):
t... | from solution import find_twin_primes
def test_find_twin_primes_case1(capfd):
find_twin_primes(10, 50)
out, err = capfd.readouterr()
assert out == "11 13\n17 19\n29 31\n41 43\n"
assert err == ""
def test_find_twin_primes_case2(capfd):
find_twin_primes(48, 52)
out, err = capfd.readouterr()
... | [
{
"docstring": null,
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": null,
"function_declaration": "def find_twin_primes(l, r):",
"function_name": "find_twin_primes",
"parameter_list": "(l, r)"
}
] | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(n):\n \"\"\" Check if a number is prime. \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return True\n if n % 2 ==... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00033401",
"row_id": 33401,
"seed_ids": "[982]"
} | 0.704218 | Code_Contests_33401 | I | [
"is_prime",
"find_twin_primes"
] | 2 | [
[
"find_twin_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 4e077f52031010265da8d3066d64cd9c8178089e | 72f76efb5935197a72f6580d84dffec448a6f0d3 | |||
v1.0 | instruct | Code_Contests | Code_Contests_33420_I | In an ancient kingdom, a tradition arose where before any two cities can establish a direct road between them, they have to calculate the minimum tax they need to pay. The tax is established by a kingdom-wide directive and varies based on the properties of both cities.
Each city's taxation property is represented as a... | def longest_common_substring_length(property1, property2):
"""
Helper function to find the length of the longest common substring
between two strings.
"""
m, n = len(property1), len(property2)
dp = [[0] * (n + 1) for _ in range(m + 1)]
max_length = 0
for i in range(1, m + 1):
... | def test_longest_common_substring_length():
assert longest_common_substring_length("alpha", "alphabeta") == 5
assert longest_common_substring_length("alphabeta", "gamma") == 1
assert longest_common_substring_length("abcdef", "zbcdf") == 3
assert longest_common_substring_length("abc", "def") == 0
ass... | [
{
"docstring": "Helper function to find the length of the longest common substring\nbetween two strings.",
"function_declaration": "def longest_common_substring_length(property1, property2):",
"function_name": "longest_common_substring_length",
"parameter_list": "(property1, property2)"
},
{
... | [
0,
1,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def longest_common_substring_length(s1, s2):\n \"\"\"\n Returns the length of the longest common substring between s1 and s2.\n \"\"\"\n if not... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00033420",
"row_id": 33420,
"seed_ids": "[3740]"
} | 0.651699 | Code_Contests_33420 | I | [
"longest_common_substring_length",
"tax_queries",
"process_input"
] | 3 | [
[
"process_input",
"tax_queries"
],
[
"tax_queries",
"longest_common_substring_length"
]
] | 2 | [
"process_input"
] | false | [] | false | pytest | false | [] | true | 6d2b0218e282ef653e85a684dc4ac6be345ec695 | 05bf0c65768e08dad77082ab13b876dfcf7ac217 | |||
v1.0 | instruct | Code_Contests | Code_Contests_33460_I | You are given a rectangular grid with integers, where each cell represents the height at that point. You want to find the highest peak in the grid. When traveling from a cell to an adjacent cell (up, down, left, or right), the difference in height between the starting cell and the target cell is added to an elevation g... | def find_elevation_gain(grid):
"""
Returns the elevation gain needed to reach the highest peak from the lowest point in the grid.
"""
R = len(grid)
C = len(grid[0])
min_height = float('inf')
max_height = float('-inf')
for row in grid:
min_height = min(min_height, min(ro... | from solution import process_input_and_find_elevation_gain
def test_case_1():
R, C = 3, 3
grid = [
[1, 2, 3],
[6, 5, 4],
[7, 8, 9]
]
assert process_input_and_find_elevation_gain(R, C, grid) == 8
def test_case_2():
R, C = 4, 4
grid = [
[0, 2, 4, 6],
[1, 3... | [
{
"docstring": "Returns the elevation gain needed to reach the highest peak from the lowest point in the grid.",
"function_declaration": "def find_elevation_gain(grid):",
"function_name": "find_elevation_gain",
"parameter_list": "(grid)"
},
{
"docstring": null,
"function_declaration": "d... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def elevation_gain(grid):\n \"\"\"\n Returns the elevation gain needed to reach the highest peak from the lowest point in the grid.\n \"\"\"\n ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00033460",
"row_id": 33460,
"seed_ids": "[402]"
} | 0.596629 | Code_Contests_33460 | I | [
"find_elevation_gain",
"process_input_and_find_elevation_gain"
] | 2 | [
[
"process_input_and_find_elevation_gain",
"find_elevation_gain"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 475b795b2692efd180a2d7d77da39c996ecf525c | ab82f506552ab909767c2590bfcdfe26f602af9a | |||
v1.0 | instruct | Code_Contests | Code_Contests_33466_I | You are tasked with optimizing a network of N ProcessingUnits in a computing cluster. Each ProcessingUnit is connected with M communication links. The cluster can be represented as a weighted undirected graph where nodes represent ProcessingUnits and edges represent communication links with associated weights represent... | import heapq
import sys
def dijkstra(N, graph, start):
distances = [float('inf')] * N
distances[start] = 0
priority_queue = [(0, start)]
while priority_queue:
current_distance, current_vertex = heapq.heappop(priority_queue)
if current_distance > distances[current_vertex]:
... | def test_given_example():
N = 6
M = 7
edges = [
(0, 1, 3),
(0, 2, 2),
(1, 2, 4),
(1, 3, 6),
(2, 3, 1),
(3, 4, 5),
(4, 5, 2)
]
assert solve(N, M, edges) == 7
def test_small_graph():
N = 3
M = 3
edges = [
(0, 1, 4),
(... | [
{
"docstring": null,
"function_declaration": "def dijkstra(N, graph, start):",
"function_name": "dijkstra",
"parameter_list": "(N, graph, start)"
},
{
"docstring": null,
"function_declaration": "def find_optimal_unit(N, M, edges):",
"function_name": "find_optimal_unit",
"paramete... | [
0,
0,
0,
0,
0,
0,
1,
0
] | 1 | hard | 0.125 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import heapq\nimport sys\nfrom collections import defaultdict\n\ndef dijkstra(graph, start, N):\n dist = [float('inf')] * N\n dist[start] = 0\n pq... | trial_gpt4o_8 | {
"original_instruction": "",
"prompt_id": "00033466",
"row_id": 33466,
"seed_ids": "[10326]"
} | 0.619451 | Code_Contests_33466 | I | [
"dijkstra",
"find_optimal_unit",
"solve"
] | 3 | [
[
"find_optimal_unit",
"dijkstra"
],
[
"solve",
"find_optimal_unit"
]
] | 2 | [] | false | [] | false | pytest | false | [] | true | 72b9748897587f71ea6675e8a714ddb4d1a110a0 | c86a518624e95d2a3a551920149975f5d75d3158 | |||
v1.0 | instruct | Code_Contests | Code_Contests_33509_I | In a remote town, there is a unique clock tower that is known for its peculiar chime pattern. The clock tower chimes following a specific sequence where each chime is either 'Tick' or 'Tock'. People in the town are fascinated by finding patterns in the sequence of chimes, especially the ones that follow a certain rule:... | def follows_chime_rule(pattern):
chimes = pattern.split()
n = len(chimes)
i = 0
while i < n:
tick_count = 0
tock_count = 0
while i < n and chimes[i] == 'Tick':
tick_count += 1
i += 1
while i < n and chimes[i] == 'Tock':
... | from solution import get_count_of_valid_chime_patterns
def test_single_valid_pattern():
assert get_count_of_valid_chime_patterns(1, ["Tick Tick Tock Tick"]) == 1
def test_single_invalid_pattern():
assert get_count_of_valid_chime_patterns(1, ["Tick Tock Tick Tock Tock"]) == 0
def test_multiple_patterns():
... | [
{
"docstring": null,
"function_declaration": "def follows_chime_rule(pattern):",
"function_name": "follows_chime_rule",
"parameter_list": "(pattern)"
},
{
"docstring": null,
"function_declaration": "def count_valid_patterns(n, patterns):",
"function_name": "count_valid_patterns",
... | [
0,
0,
0,
0,
0,
0,
0,
1,
1
] | 2 | hard | 0.222 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def follows_rule(pattern):\n \"\"\"\n Returns True if the pattern follows the rule that the number of consecutive 'Tick'\n chimes is always greate... | trial_gpt4o_9 | {
"original_instruction": "",
"prompt_id": "00033509",
"row_id": 33509,
"seed_ids": "[12397]"
} | 0.619094 | Code_Contests_33509 | I | [
"follows_chime_rule",
"count_valid_patterns",
"get_count_of_valid_chime_patterns"
] | 3 | [
[
"count_valid_patterns",
"follows_chime_rule"
],
[
"get_count_of_valid_chime_patterns",
"count_valid_patterns"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 79ca56b4060f8caf1f7548372dc00253d9c8c0e9 | 66248cc7d3820c4f2af203e4c6d1f0714b5c25db | |||
v1.0 | instruct | Code_Contests | Code_Contests_33548_I | Implement a ticket management system for a movie theater. The theater has a fixed seating arrangement with `n` rows and `m` columns, and each seat can either be available or reserved. You need to create a program that processes a series of booking commands and outputs the final seating arrangement.
The available booki... | def create_theater(n, m):
"""
Initializes a theater with all seats available.
:param n: Number of rows
:param m: Number of columns
:return: 2D list representing the theater seating arrangement
"""
return [['A' for _ in range(m)] for _ in range(n)]
def process_booking_commands(n, m, com... | from solution import process_booking_commands
def test_all_available_seats():
theater = process_booking_commands(3, 3, [])
expected = [
['A', 'A', 'A'],
['A', 'A', 'A'],
['A', 'A', 'A']
]
assert theater == expected
def test_single_booking():
theater = process_booking_comman... | [
{
"docstring": "Initializes a theater with all seats available.\n\n:param n: Number of rows\n:param m: Number of columns\n:return: 2D list representing the theater seating arrangement",
"function_declaration": "def create_theater(n, m):",
"function_name": "create_theater",
"parameter_list": "(n, m)"... | [
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 manage_seats(n, m, commands):\n # Initialize the seating arrangement with all seats available\n seats = [['A' for _ in range(m)] for _ in range(n... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00033548",
"row_id": 33548,
"seed_ids": "[8764]"
} | 0.634381 | Code_Contests_33548 | I | [
"create_theater",
"process_booking_commands",
"print_seating_arrangement"
] | 3 | [
[
"process_booking_commands",
"create_theater"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 50ae147b7994de1325ffc407b79fae14992949ef | fabf7f02d7921f402df800297f9baf41ea531ec7 | |||
v1.0 | instruct | Code_Contests | Code_Contests_33581_I | Arya is a software developer who loves to play with binary numbers. One day, she faced the following problem and needs your help to solve it.
Given two binary strings s1 and s2, Arya wants to maximize the binary sum of two non-overlapping substrings where one is taken from s1 and the other is taken from s2. The sum of... | def binary_to_decimal(binary_str):
"""
Converts a binary string to its decimal value.
"""
return int(binary_str, 2)
def max_non_overlapping_sum(s1, s2):
"""
Finds the maximum possible sum of two non-overlapping substrings where
one is taken from s1 and the other is taken from s2. The sum... | import pytest
from solution import max_non_overlapping_sum
def test_example_1():
assert max_non_overlapping_sum("10110", "1101") == 22 + 13
def test_example_2():
assert max_non_overlapping_sum("11101", "101") == 29 + 5
def test_single_characters():
assert max_non_overlapping_sum("1", "0") == 1
assert... | [
{
"docstring": "Converts a binary string to its decimal value.",
"function_declaration": "def binary_to_decimal(binary_str):",
"function_name": "binary_to_decimal",
"parameter_list": "(binary_str)"
},
{
"docstring": "Finds the maximum possible sum of two non-overlapping substrings where \non... | [
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_possible_sum(s1, s2):\n \"\"\"\n Returns the maximum possible sum of two non-overlapping substrings where\n one is taken from s1 and the o... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00033581",
"row_id": 33581,
"seed_ids": "[882]"
} | 0.640981 | Code_Contests_33581 | I | [
"binary_to_decimal",
"max_non_overlapping_sum"
] | 2 | [
[
"max_non_overlapping_sum",
"binary_to_decimal"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | e41963f64eb2cc62d27fdfc94530101ad8117cb4 | e9ed25ff33987a5b69c96e5bc1dc8b25d5d4325b | |||
v1.0 | instruct | Code_Contests | Code_Contests_33596_I | You are given a binary tree with N nodes, each node having a unique positive integer value. Your task is to determine if there exists a path (from the root to any leaf) such that the sum of the node values along the path is equal to a given target sum S.
If such a path exists, output the nodes along the path as they a... | class TreeNode:
def __init__(self, value):
self.value = value
self.left = None
self.right = None
def build_tree(level_order, edges):
if not level_order:
return None
nodes = {val: TreeNode(val) for val in level_order}
for A, B in edges:
if nodes[A].left ... | import pytest
from solution import find_path_to_sum
def test_example_case():
N = 5
S = 10
level_order = [5, 3, 8, 2, 6]
edges = [(5, 3), (5, 8), (3, 2), (3, 6)]
assert find_path_to_sum(N, S, level_order, edges) == [5, 3, 2]
def test_no_path():
N = 3
S = 15
level_order = [1, 2, 3]
e... | [] | [
1,
0
] | 1 | medium | 0.5 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "class TreeNode:\n def __init__(self, value):\n self.value = value\n self.left = None\n self.right = None\n\ndef build_tree(level_or... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00033596",
"row_id": 33596,
"seed_ids": "[3546]"
} | 0.674997 | Code_Contests_33596 | I | [
"build_tree",
"has_path_sum",
"find_path_to_sum"
] | 3 | [
[
"find_path_to_sum",
"build_tree"
],
[
"find_path_to_sum",
"has_path_sum"
]
] | 2 | [] | false | [
"TreeNode"
] | true | pytest | true | [] | true | be29c134a7389e13a454d8b7260da1a9049b6b55 | 216416cc36dd88fef13cfafaf39bb1516d01810c | |||
v1.0 | instruct | Code_Contests | Code_Contests_33612_I | ### D: Pathfinding in a Grid
story
A group of adventurous friends decided to explore a mysterious forest divided into a rectangular grid of cells. Each cell in the grid can either be empty, a tree, or water. The friends can move up, down, left, or right to an adjacent cell, but they cannot move diagonally. Their goal... | from collections import deque
def is_valid(matrix, x, y, n, m):
return 0 <= x < n and 0 <= y < m and matrix[x][y] == '.'
def update_grid_with_trees(grid, tree_positions, t):
for i in range(t + 1):
if i < len(tree_positions):
x, y = tree_positions[i]
if grid[x][y] == '.':
... | def test_shortest_path_1():
N = 5
M = 5
sx = 0
sy = 0
ex = 4
ey = 4
grid = [
".....",
"..#..",
"..#..",
"..#..",
"....."
]
T = 5
tree_positions = [(0, 4), (4, 0), (1, 1), (1, 3), (3, 3)]
new_grid = [list(row) for row in grid]
assert... | [
{
"docstring": null,
"function_declaration": "def is_valid(matrix, x, y, n, m):",
"function_name": "is_valid",
"parameter_list": "(matrix, x, y, n, m)"
},
{
"docstring": null,
"function_declaration": "def update_grid_with_trees(grid, tree_positions, t):",
"function_name": "update_gri... | [
1,
0,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from collections import deque\n\ndef is_valid(matrix, x, y, n, m):\n return 0 <= x < n and 0 <= y < m and matrix[x][y] == '.'\n\ndef update_grid_with_tr... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00033612",
"row_id": 33612,
"seed_ids": "[9889]"
} | 0.703141 | Code_Contests_33612 | I | [
"is_valid",
"update_grid_with_trees",
"shortest_path_in_forest"
] | 3 | [
[
"shortest_path_in_forest",
"is_valid"
],
[
"shortest_path_in_forest",
"update_grid_with_trees"
]
] | 2 | [] | false | [] | false | pytest | false | [] | true | f9b38f481d22ebc62ef3427f336f7ed97c80eec8 | 7f2e869dc3f7a9b76d54a93f7d6bdccad4a7db03 | |||
v1.0 | instruct | Code_Contests | Code_Contests_33654_I | You are given a 2D matrix of size n x m, where each cell contains an integer. You need to handle q queries, each asking for the sum of elements in a submatrix defined by its top-left and bottom-right corners.
Write a program that first reads the matrix and then processes the queries efficiently.
Input
The first line... | def preprocess_matrix(matrix):
"""
Preprocesses the matrix and returns a prefix sums matrix for efficient query processing.
"""
n = len(matrix)
m = len(matrix[0])
prefix_sums = [[0] * (m + 1) for _ in range(n + 1)]
for i in range(1, n + 1):
for j in range(1, m + 1):
pref... | def test_preprocess_matrix():
matrix = [
[1, 2, 3],
[4, 5, 6],
[7, 8, 9]
]
expected_prefix_sums = [
[0, 0, 0, 0],
[0, 1, 3, 6],
[0, 5, 12, 21],
[0, 12, 27, 45]
]
assert preprocess_matrix(matrix) == expected_prefix_sums
def test_q... | [
{
"docstring": "Preprocesses the matrix and returns a prefix sums matrix for efficient query processing.",
"function_declaration": "def preprocess_matrix(matrix):",
"function_name": "preprocess_matrix",
"parameter_list": "(matrix)"
},
{
"docstring": "Computes the sum of elements in the subma... | [
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 preprocess_matrix(matrix, n, m):\n \"\"\"\n Preprocess the matrix to get cumulative sums for efficient range sum queries.\n \"\"\"\n cumula... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00033654",
"row_id": 33654,
"seed_ids": "[4131]"
} | 0.663667 | Code_Contests_33654 | I | [
"preprocess_matrix",
"query_sum",
"process_queries"
] | 3 | [
[
"process_queries",
"preprocess_matrix"
],
[
"process_queries",
"query_sum"
]
] | 2 | [
"process_queries"
] | false | [] | false | pytest | false | [] | true | d6fc64911a1746b3da47459d212e086c5a0c0a1d | 5040151520148203ee1d475c33f69536ad5bed1b | |||
v1.0 | instruct | Code_Contests | Code_Contests_33700_I | Problem
You are tasked with designing a fitness tracking application. The application tracks the steps walked by users and generates summaries based on the specified range of days. Specifically, you have to implement a function to process a list of daily steps data and answer multiple queries efficiently.
For the giv... | def preprocess_steps(steps):
"""
Preprocess the array of daily steps using prefix sums.
:param steps: List[int], a list of steps taken each day.
:return: List[int], a list of prefix sums.
"""
prefix_sum = [0] * (len(steps) + 1)
for i in range(len(steps)):
prefix_sum[i + 1] = pre... | def test_preprocess_steps():
steps = [1000, 2000, 3000, 4000, 5000]
expected = [0, 1000, 3000, 6000, 10000, 15000]
assert preprocess_steps(steps) == expected
def test_total_steps_in_range():
prefix_sum = [0, 1000, 3000, 6000, 10000, 15000]
assert total_steps_in_range(prefix_sum, 1, 3) == 6000
a... | [
{
"docstring": "Preprocess the array of daily steps using prefix sums.\n\n:param steps: List[int], a list of steps taken each day.\n:return: List[int], a list of prefix sums.",
"function_declaration": "def preprocess_steps(steps):",
"function_name": "preprocess_steps",
"parameter_list": "(steps)"
... | [
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 calculate_prefix_sums(steps):\n \"\"\"\n Calculates the prefix sums for the given steps.\n \n :param steps: List[int] - A list with the num... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00033700",
"row_id": 33700,
"seed_ids": "[12382]"
} | 0.743346 | Code_Contests_33700 | I | [
"preprocess_steps",
"total_steps_in_range",
"process_queries"
] | 3 | [
[
"process_queries",
"preprocess_steps"
],
[
"process_queries",
"total_steps_in_range"
]
] | 2 | [
"process_queries"
] | false | [] | false | pytest | false | [] | true | db827536e4f87670ec7a0b0fed623042594c0bf9 | 47807873907fffaa0e28c34416ac02a2641ce351 | |||
v1.0 | instruct | Code_Contests | Code_Contests_33730_I | There is a complex network of servers within a datacenter. Each server is connected to several others through directed channels that allow data packets to flow between them. The network can be represented as a directed graph where each node represents a server and each directed edge represents a channel with its data c... | from collections import deque, defaultdict
import sys
def bfs(capacity, source, sink, parent):
visited = set()
queue = deque([source])
visited.add(source)
while queue:
current = queue.popleft()
for neighbor in capacity[current]:
if neighbor not in visited and c... | def test_possible_scenario():
n = 4
m = 5
edges = [
(1, 2, 10),
(2, 3, 5),
(3, 4, 10),
(1, 3, 7),
(2, 4, 3)
]
src = 1
sink = 4
f = 8
assert can_send_exact_flow(n, m, edges, src, sink, f) == "Possible"
def test_impossible_scenario():
n = 4
... | [
{
"docstring": null,
"function_declaration": "def bfs(capacity, source, sink, parent):",
"function_name": "bfs",
"parameter_list": "(capacity, source, sink, parent)"
},
{
"docstring": null,
"function_declaration": "def edmonds_karp(n, graph, source, sink):",
"function_name": "edmonds... | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from collections import defaultdict, deque\n\ndef bfs_capacity_check(graph, src, sink, parent):\n visited = [False] * len(graph)\n queue = deque([src... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00033730",
"row_id": 33730,
"seed_ids": "[6940]"
} | 0.636733 | Code_Contests_33730 | I | [
"bfs",
"edmonds_karp",
"can_send_exact_flow"
] | 3 | [
[
"can_send_exact_flow",
"edmonds_karp"
],
[
"edmonds_karp",
"bfs"
]
] | 2 | [] | false | [] | false | pytest | false | [] | true | bcf3b38fb86480603c1905fd900682bebec0bd54 | 5a5afda206e95580e9590c46fe1c7cff915437e9 | |||
v1.0 | instruct | Code_Contests | Code_Contests_33750_I | In a faraway kingdom, there are n castles connected by n-1 bidirectional roads. Each road connects two different castles and has a certain length. The kingdom's ruler wants to hold two events at two different castles. To avoid any possible overcrowding, the ruler requires these two castles to be as far apart as possibl... | from collections import defaultdict, deque
def find_farthest_node(start_node, n, graph):
"""Performs BFS to find the farthest node from the given start_node"""
distances = [-1] * (n + 1)
distances[start_node] = 0
queue = deque([start_node])
farthest_node = start_node
while queue:
curr... | from solution import find_max_distance_castles
def test_case_1():
n = 4
roads = [(1, 2, 3), (2, 3, 5), (3, 4, 2)]
result = find_max_distance_castles(n, roads)
assert result == [1, 4] or result == [4, 1]
def test_case_2():
n = 5
roads = [(1, 2, 1), (1, 3, 1), (1, 4, 1), (1, 5, 1)]
result = ... | [
{
"docstring": "Performs BFS to find the farthest node from the given start_node",
"function_declaration": "def find_farthest_node(start_node, n, graph):",
"function_name": "find_farthest_node",
"parameter_list": "(start_node, n, graph)"
},
{
"docstring": null,
"function_declaration": "d... | [
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 sys\nfrom collections import defaultdict, deque\n\ndef find_furthest_castle(start, tree):\n \"\"\"\n Performs BFS to find the furthest castle ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00033750",
"row_id": 33750,
"seed_ids": "[2948]"
} | 0.627437 | Code_Contests_33750 | I | [
"find_farthest_node",
"find_max_distance_castles"
] | 2 | [
[
"find_max_distance_castles",
"find_farthest_node"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | be45be8c79324af7a904d6b039f4419884223f02 | 3f6a54434b4764d84dc252f083eba404a23aed9d | |||
v1.0 | instruct | Code_Contests | Code_Contests_33764_I | Design a data compression tool that encodes input strings using the Run-Length Encoding (RLE) algorithm. Run-Length Encoding is a basic form of data compression in which consecutive repetitive characters are stored as a single character and a count.
Write a program that will:
1. Compress a given string using RLE.
2. D... | def compress_string(s):
compressed_str = []
i = 0
while i < len(s):
count = 1
while i + 1 < len(s) and s[i] == s[i+1]:
i += 1
count += 1
compressed_str.append(f"{count}{s[i]}")
i += 1
return "".join(compressed_str)
def decompress_string... | def test_run_length_encoding():
test_cases = [
("3", ["AAAABBBCCDAA", "4A3B2C1D2A", "BBBCCCCCCDDDD"], ["4A3B2C1D2A", "AAAABBBCCDAA", "3B6C4D"]),
("2", ["AABBCC", "2A2B2C"], ["2A2B2C", "AABBCC"]),
("1", ["HHHHHHHH"], ["8H"]),
]
for (t, input_strs, expected_output) in test_cases:
... | [
{
"docstring": null,
"function_declaration": "def compress_string(s):",
"function_name": "compress_string",
"parameter_list": "(s)"
},
{
"docstring": null,
"function_declaration": "def decompress_string(s):",
"function_name": "decompress_string",
"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 compress(s):\n \"\"\"\n Compresses the given string using Run-Length Encoding (RLE).\n \"\"\"\n if not s:\n return s\n \n comp... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00033764",
"row_id": 33764,
"seed_ids": "[2367]"
} | 0.71113 | Code_Contests_33764 | I | [
"compress_string",
"decompress_string",
"run_length_encoding"
] | 3 | [
[
"run_length_encoding",
"compress_string"
],
[
"run_length_encoding",
"decompress_string"
]
] | 2 | [] | false | [] | false | pytest | false | [] | true | 9ba6aff1799af1841dc56e3ac0cf45b8064d2a2d | 3e9717b64bc462d61a01ba13b51ead7952855122 | |||
v1.0 | instruct | Code_Contests | Code_Contests_33773_I | A transport company has a network of cities connected by bidirectional roads. Each road has a non-negative integer weight representing the time to travel between the two cities it connects. The company is trying to determine the minimum travel time between various pairs of cities for their new route optimization system... | def floyd_warshall(n, edges):
# Initialize distance matrix
dist = [[float('inf')] * n for _ in range(n)]
# Distance from the node to itself is zero
for i in range(n):
dist[i][i] = 0
for u, v, w in edges:
u -= 1
v -= 1
dist[u][v] = w
dist[v][u] = ... | from solution import floyd_warshall, minimum_travel_times
def test_floyd_warshall_basic():
n = 4
edges = [
(1, 2, 1),
(2, 3, 2),
(1, 3, 4),
(3, 4, 1)
]
expected = [
[0, 1, 3, 4],
[1, 0, 2, 3],
[3, 2, 0, 1],
[4, 3, 1, 0]
]
assert fl... | [
{
"docstring": null,
"function_declaration": "def floyd_warshall(n, edges):",
"function_name": "floyd_warshall",
"parameter_list": "(n, edges)"
},
{
"docstring": null,
"function_declaration": "def minimum_travel_times(n, edges, queries):",
"function_name": "minimum_travel_times",
... | [
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 floyd_warshall(n, roads):\n INF = float('inf')\n dist = [[INF] * n for _ in range(n)]\n \n for i in range(n):\n dist[i][i] = 0\n ... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00033773",
"row_id": 33773,
"seed_ids": "[3577]"
} | 0.835354 | Code_Contests_33773 | I | [
"floyd_warshall",
"minimum_travel_times",
"main"
] | 3 | [
[
"minimum_travel_times",
"floyd_warshall"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | eaceeeb0b77176013911e131b89eb7cdf2fe4103 | 975d35f937a21bd31af346416bf893c1db9c2bbe | |||
v1.0 | instruct | Code_Contests | Code_Contests_33774_I | Alice is working on a network security project where she needs to write a firewall rule to allow or deny access based on IP addresses. The firewall rules are defined by a series of IP ranges, and she needs to check if a given IP falls within those ranges.
An IP address is represented as a string in the form "a.b.c.d",... | def ip_to_int(ip):
"""
Converts an IP address to an integer for easy comparison.
"""
parts = ip.split('.')
return int(parts[0]) * 256**3 + int(parts[1]) * 256**2 + int(parts[2]) * 256 + int(parts[3])
def is_ip_in_range(ip, start_ip, end_ip):
"""
Returns True if the IP is in the provided ran... | from solution import check_ip_in_ranges
def test_ip_in_first_range():
ranges = [("192.168.1.1", "192.168.1.100"), ("10.0.0.0", "10.0.0.255"), ("172.16.0.0", "172.16.255.255")]
ip = "192.168.1.50"
assert check_ip_in_ranges(ranges, ip) == "ALLOW"
def test_ip_not_in_range():
ranges = [("192.168.0.0", "19... | [
{
"docstring": "Converts an IP address to an integer for easy comparison.",
"function_declaration": "def ip_to_int(ip):",
"function_name": "ip_to_int",
"parameter_list": "(ip)"
},
{
"docstring": "Returns True if the IP is in the provided range, otherwise False.",
"function_declaration": ... | [
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 ip_to_int(ip):\n \"\"\"\n Converts an IP address string to an integer.\n \"\"\"\n parts = ip.split('.')\n return int(parts[0]) * 256**3 ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00033774",
"row_id": 33774,
"seed_ids": "[13258]"
} | 0.554567 | Code_Contests_33774 | I | [
"ip_to_int",
"is_ip_in_range",
"check_ip_in_ranges"
] | 3 | [
[
"check_ip_in_ranges",
"is_ip_in_range"
],
[
"is_ip_in_range",
"ip_to_int"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | b7e27ac7fe9a5fc7d7e3c77f89d3b8ddb1370871 | a6b0a7ba8047b37db503e204a476dae580eb7449 | |||
v1.0 | instruct | Code_Contests | Code_Contests_33776_I | You are given a list of weighted edges representing a graph and are tasked with finding the shortest path between two nodes using Dijkstra's algorithm. The graph may be disconnected, meaning there might not be a valid path between some pairs of nodes.
INPUT:
- The first line contains an integer `n`, the number of node... | import heapq
def dijkstra(n, graph, start):
"""
Implements Dijkstra's algorithm to find the shortest paths from start node to all other nodes.
"""
distances = {i: float('inf') for i in range(1, n+1)}
distances[start] = 0
priority_queue = [(0, start)]
while priority_queue:
current_di... | from solution import solve, parse_input
def test_solve_example():
input_str = """5
7
1 2 1
1 3 4
2 3 2
2 4 7
3 5 3
4 5 1
1 5 8
3
1 5
2 5
4 1"""
n, edges, queries = parse_input(input_str)
assert solve(n, edges, queries) == [6, 5, "No Path"]
def test_solve_no_... | [
{
"docstring": "Implements Dijkstra's algorithm to find the shortest paths from start node to all other nodes.",
"function_declaration": "def dijkstra(n, graph, start):",
"function_name": "dijkstra",
"parameter_list": "(n, graph, start)"
},
{
"docstring": "Given the list of edges and queries... | [
0,
0,
0,
1,
0
] | 1 | hard | 0.2 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import heapq\n\ndef dijkstra(graph, n, start):\n distances = {node: float('inf') for node in range(1, n+1)}\n distances[start] = 0\n priority_queu... | trial_gpt4o_3 | {
"original_instruction": "",
"prompt_id": "00033776",
"row_id": 33776,
"seed_ids": "[9232]"
} | 0.726401 | Code_Contests_33776 | I | [
"dijkstra",
"solve",
"parse_input"
] | 3 | [
[
"solve",
"dijkstra"
]
] | 1 | [
"parse_input"
] | false | [] | false | pytest | true | [] | true | 7a99e97e83cf1991804f77732dbeb5cb2cde6409 | 794fc18c007e919f4ce9d52d5bc91f7ee5771a2f | |||
v1.0 | instruct | Code_Contests | Code_Contests_33778_I | In a certain kingdom, there are `n` cities connected by `n-1` roads such that there is exactly one path between any two cities. The king wants to place a palace in one of these cities. However, to ensure his palace is as centralized as possible, he wants to minimize the maximum distance from the palace to any other cit... | from collections import defaultdict, deque
def find_farthest_node(start_node, graph):
"""
Returns the farthest node from start_node and its distance using BFS.
"""
n = len(graph)
visited = [False] * (n + 1)
distance = [0] * (n + 1)
queue = deque([start_node])
visited[start_node] = True
... | from solution import central_city
def test_central_city_example1():
n = 7
roads = [(1, 2), (1, 3), (2, 4), (2, 5), (3, 6), (3, 7)]
assert central_city(n, roads) == 1
def test_central_city_example2():
n = 5
roads = [(1, 2), (1, 3), (2, 4), (3, 5)]
assert central_city(n, roads) == 1
def tes... | [
{
"docstring": "Returns the farthest node from start_node and its distance using BFS.",
"function_declaration": "def find_farthest_node(start_node, graph):",
"function_name": "find_farthest_node",
"parameter_list": "(start_node, graph)"
},
{
"docstring": "Returns the city that minimizes the ... | [
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": "from collections import deque, defaultdict\n\ndef find_optimal_city(n, roads):\n if n == 1:\n return 1\n \n def bfs(start):\n q = de... | trial_gpt4o_8 | {
"original_instruction": "",
"prompt_id": "00033778",
"row_id": 33778,
"seed_ids": "[631]"
} | 0.715089 | Code_Contests_33778 | I | [
"find_farthest_node",
"central_city"
] | 2 | [
[
"central_city",
"find_farthest_node"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 7e305f0e9518d065fe898ea0170b17541806aa61 | 6361ea01532002154c536c9ebbdc4d84f5c2c762 | |||
v1.0 | instruct | Code_Contests | Code_Contests_33817_I | Little Chef has recently learned about prime numbers and wants to apply his newfound knowledge to solve some interesting problems.
He is given a list of integers and needs to find out how many prime numbers are present in this list.
Input
The first line contains an integer N, representing the number of integers in t... | def is_prime(num):
"""
Helper function to check if a number is prime.
"""
if num <= 1:
return False
if num == 2:
return True
if num % 2 == 0:
return False
for i in range(3, int(num**0.5) + 1, 2):
if num % i == 0:
return False
return True
def c... | from solution import count_primes_in_list, is_prime
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(1) == False
assert is_prime(0) == False
assert is_prime(101) == True
assert is_prime(104... | [
{
"docstring": "Helper function to check if a number is prime.",
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": "Returns the count of prime numbers in the list.",
"function_declaration": "def count_primes_in_list(num... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(num):\n \"\"\"\n Helper function to check if a number is prime.\n \"\"\"\n if num <= 1:\n return False\n if num == 2:\n ... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00033817",
"row_id": 33817,
"seed_ids": "[6562]"
} | 0.661439 | Code_Contests_33817 | I | [
"is_prime",
"count_primes_in_list"
] | 2 | [
[
"count_primes_in_list",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | c8676f34f3ea0049046e4e466e056aafb2f05f9e | 069dbea81eb39ede09135ac91f792fbb93c3673b | |||
v1.0 | instruct | Code_Contests | Code_Contests_33820_I | Alice and Bob's Grid Game
Alice and Bob love playing games on a grid. This time, they invented a new game. They have a grid of size N x M consisting of cells. Each cell can either be empty (.) or blocked (#). Alice's goal is to find all the unique paths from the top-left corner of the grid (0, 0) to the bottom-right c... | MOD = 10**9 + 7
def count_unique_paths(grid):
N = len(grid)
M = len(grid[0])
# Create a dp table
dp = [[0] * M for _ in range(N)]
# Starting position
if grid[0][0] == '.':
dp[0][0] = 1
for i in range(N):
for j in range(M):
if grid[i][j] == '#':
... | def test_unique_paths_case_1():
N = 3
M = 3
grid_lines = [
"...",
".#.",
"..."
]
assert unique_paths_from_input(N, M, grid_lines) == 2
def test_unique_paths_case_2():
N = 3
M = 3
grid_lines = [
"...",
"...",
"..."
]
assert unique_p... | [
{
"docstring": null,
"function_declaration": "def count_unique_paths(grid):",
"function_name": "count_unique_paths",
"parameter_list": "(grid)"
},
{
"docstring": null,
"function_declaration": "def unique_paths_from_input(N, M, grid_lines):",
"function_name": "unique_paths_from_input"... | [
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": "MOD = 10**9 + 7\n\ndef count_unique_paths(grid):\n N = len(grid)\n M = len(grid[0])\n \n # Create a dp table\n dp = [[0] * M for _ in range(... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00033820",
"row_id": 33820,
"seed_ids": "[1009]"
} | 0.770547 | Code_Contests_33820 | I | [
"count_unique_paths",
"unique_paths_from_input"
] | 2 | [
[
"unique_paths_from_input",
"count_unique_paths"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | 08e6bcfcfa1000ea945ab735eb43f4fa2b8832ab | f04b40fb9c42266af95b9546ac3014d69e28df89 | |||
v1.0 | instruct | Code_Contests | Code_Contests_33829_I | In a small kingdom, there are n cities and m roads connecting pairs of these cities. Each road has a specific length. To enhance trade and travel efficiency, the king has decided to pave some of these roads, ensuring the total length of the paved roads is the minimum necessary to connect all cities.
Your task is to de... | def kruskal_minimum_spanning_tree(n, roads):
"""
Returns the minimum total length of the paved roads necessary to ensure all cities are connected.
Uses Kruskal's algorithm.
"""
# Sort roads based on their length
roads.sort(key=lambda x: x[2])
# Union-Find data structure to detect cycles... | def test_example_case():
assert minimum_paved_roads(5, 7, [
(1, 2, 1),
(1, 3, 4),
(2, 3, 2),
(2, 4, 7),
(3, 4, 3),
(3, 5, 5),
(4, 5, 6),
]) == 11
def test_single_road():
assert minimum_paved_roads(2, 1, [
(1, 2, 10),
]) == 10
def test_dis... | [
{
"docstring": "Returns the minimum total length of the paved roads necessary to ensure all cities are connected.\nUses Kruskal's algorithm.",
"function_declaration": "def kruskal_minimum_spanning_tree(n, roads):",
"function_name": "kruskal_minimum_spanning_tree",
"parameter_list": "(n, roads)"
},... | [
0,
0,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def find_minimum_spanning_tree(n, m, edges):\n \"\"\"\n Returns the minimum total length of the roads necessary to connect all cities.\n Uses Krus... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00033829",
"row_id": 33829,
"seed_ids": "[7241]"
} | 0.764815 | Code_Contests_33829 | I | [
"kruskal_minimum_spanning_tree",
"minimum_paved_roads"
] | 2 | [
[
"minimum_paved_roads",
"kruskal_minimum_spanning_tree"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | 6efeebf5d10bc97c40aa73a96efcd6640fbad964 | 5c24a40976a3aee8b97f8b9f1bf273dc9319a1f2 | |||
v1.0 | instruct | Code_Contests | Code_Contests_33855_I | A warehouse manager wants to optimize the arrangement of boxes in the warehouse. Each box has a unique integral weight and needs to be grouped into distinct sections on a single floor. He decided to follow these rules for grouping:
1. Each section should consist of consecutive boxes, and there must be exactly m groups... | def is_possible(weights, n, m, max_sum, k):
"""
Helper function to check if it's possible to partition weights into m sections where
each section's sum is at most max_sum and it does not exceed the threshold k.
"""
current_sum = 0
sections_count = 1
for weight in weights:
if weight ... | def test_minimize_max_sum_example1():
assert minimize_max_sum(5, 3, [1, 2, 3, 4, 5], 10) == 6
def test_minimize_max_sum_example2():
assert minimize_max_sum(6, 2, [7, 2, 4, 8, 1, 3], 15) == 13
def test_minimize_max_sum_impossible_case():
assert minimize_max_sum(6, 2, [7, 2, 4, 8, 1, 3], 5) == -1
def test_... | [
{
"docstring": "Helper function to check if it's possible to partition weights into m sections where\neach section's sum is at most max_sum and it does not exceed the threshold k.",
"function_declaration": "def is_possible(weights, n, m, max_sum, k):",
"function_name": "is_possible",
"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": "def can_partition(weights, n, m, max_sum):\n \"\"\"\n Helper function to check if it is possible to partition\n the weights into at most m groups ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00033855",
"row_id": 33855,
"seed_ids": "[13051]"
} | 0.698983 | Code_Contests_33855 | I | [
"is_possible",
"minimize_max_sum"
] | 2 | [
[
"minimize_max_sum",
"is_possible"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | 9982825ad94f4accdee22ad305aa66196081b84e | 2e8de247f19c1f2d083f69323c01c64a4696fa10 | |||
v1.0 | instruct | Code_Contests | Code_Contests_33856_I | The Kingdom of Arithmia consists of n cities interconnected by m directional highways. Each highway has an associated cost representing the toll required to travel from one city to another. However, economic circumstances have necessitated the kingdom to raise tolls more frequently across some highways to generate reve... | import heapq
def dijkstra(n, edges, src):
graph = [[] for _ in range(n + 1)]
for u, v, c in edges:
graph[u].append((v, c))
min_cost = [float('inf')] * (n + 1)
min_cost[src] = 0
pq = [(0, src)]
heapq.heapify(pq)
while pq:
current_cost, u = heapq.heappop(pq)
... | def test_minimal_travel_costs():
assert minimal_travel_costs(4, 5, [(1, 2, 10), (2, 3, 5), (3, 4, 15), (4, 2, 10), (1, 3, 20)]) == [0, 10, 15, 30]
assert minimal_travel_costs(3, 3, [(1, 2, 8), (1, 3, 12), (2, 3, 4)]) == [0, 8, 12]
# Running pytest
if __name__ == "__main__":
import pytest
pytest.main([_... | [
{
"docstring": null,
"function_declaration": "def dijkstra(n, edges, src):",
"function_name": "dijkstra",
"parameter_list": "(n, edges, src)"
},
{
"docstring": null,
"function_declaration": "def minimal_travel_costs(n, m, highways):",
"function_name": "minimal_travel_costs",
"par... | [
1
] | 1 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import heapq\n\ndef dijkstra(n, edges, src):\n graph = [[] for _ in range(n + 1)]\n for u, v, c in edges:\n graph[u].append((v, c))\n \... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00033856",
"row_id": 33856,
"seed_ids": "[3035]"
} | 0.721252 | Code_Contests_33856 | I | [
"dijkstra",
"minimal_travel_costs",
"main"
] | 3 | [
[
"minimal_travel_costs",
"dijkstra"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | 0336d2054a76d8012367e78ab88f07e4f1ea4133 | 20a31fb9f722fd740e0daa652622061467282b35 | |||
v1.0 | instruct | Code_Contests | Code_Contests_33897_I | Create a function that determines if a given pyrotechnic show for an event will be synchronized.
### Problem Description
You are tasked with verifying if the pyrotechnic show for a city festival will be perfectly synchronized.
A pyrotechnic show is perfectly synchronized if all the pyrotechnic intervals align such th... | from math import gcd
from functools import reduce
def lcm(a, b):
"""
Compute the Least Common Multiple of two numbers.
"""
return a * b // gcd(a, b)
def isSynchronized(N, intervals):
"""
Determines if there is a common time T where all pyrotechnic displays
go off simultaneously for the fir... | from solution import isSynchronized
def test_single_interval():
assert isSynchronized(1, [3]) == True
def test_multiple_intervals_example1():
assert isSynchronized(3, [3, 5, 4]) == False
def test_multiple_intervals_example2():
assert isSynchronized(2, [2, 4]) == True
def test_all_prime_intervals():
... | [
{
"docstring": "Compute the Least Common Multiple of two numbers.",
"function_declaration": "def lcm(a, b):",
"function_name": "lcm",
"parameter_list": "(a, b)"
},
{
"docstring": "Determines if there is a common time T where all pyrotechnic displays\ngo off simultaneously for the first time.... | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from math import gcd\nfrom functools import reduce\nfrom typing import List\n\ndef lcm(a, b):\n return abs(a * b) // gcd(a, b)\n\ndef isSynchronized(N: ... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00033897",
"row_id": 33897,
"seed_ids": "[10409]"
} | 0.571672 | Code_Contests_33897 | I | [
"lcm",
"isSynchronized"
] | 2 | [
[
"isSynchronized",
"lcm"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | a3a8c99a389f07df121c96aa44f5417b1d1ea690 | 77d85d7cc1ba4f89a0656e78efb4b3385e91a91c | |||
v1.0 | instruct | Code_Contests | Code_Contests_34033_I | You are given a grid with obstacles represented as walls. You need to find the shortest path from the top-left corner of the grid to the bottom-right corner. You can move up, down, left, or right, but you cannot pass through walls. If no such path exists, return -1.
Input
The first line of the input contains an integ... | from collections import deque
def shortest_path(grid):
n = len(grid)
m = len(grid[0])
directions = [(1, 0), (-1, 0), (0, 1), (0, -1)]
def is_valid(r, c):
return 0 <= r < n and 0 <= c < m and grid[r][c] == '.'
queue = deque([(0, 0, 0)]) # (row, col, distance)
grid[0][0] = '#' # mark ... | from solution import solve_input
def test_shortest_path():
input_str = "2\n4 4\n....\n.##.\n....\n....\n3 3\n.#.\n###\n.#.\n"
expected_output = [6, -1]
assert solve_input(input_str) == expected_output
def test_all_open():
input_str = "1\n3 3\n...\n...\n...\n"
expected_output = [4]
assert solve... | [
{
"docstring": null,
"function_declaration": "def shortest_path(grid):",
"function_name": "shortest_path",
"parameter_list": "(grid)"
},
{
"docstring": null,
"function_declaration": "def solve(test_cases):",
"function_name": "solve",
"parameter_list": "(test_cases)"
},
{
... | [
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 deque\n\ndef shortest_path(grid):\n n = len(grid)\n m = len(grid[0])\n direction_vectors = [(1, 0), (-1, 0), (0, 1), (0, -... | trial_gpt4o_4 | {
"original_instruction": "",
"prompt_id": "00034033",
"row_id": 34033,
"seed_ids": "[1619]"
} | 0.718924 | Code_Contests_34033 | I | [
"shortest_path",
"solve",
"parse_input",
"solve_input"
] | 4 | [
[
"solve",
"shortest_path"
],
[
"solve_input",
"parse_input"
],
[
"solve_input",
"solve"
]
] | 3 | [
"parse_input",
"solve_input"
] | false | [] | false | pytest | true | [] | true | a73021c1676681827b2f0e2c7f7b1f409661d243 | 0eb3dc253fa1ee9c91c01a0cf01219523151ad9a | |||
v1.0 | instruct | Code_Contests | Code_Contests_34062_I | Problem description
In an enchanted forest, there are magical trees that produce fruits only on specific days. Each tree has a unique schedule of days it produces fruit, once per day. You are given the number of trees and for each tree, you are given the days of the week it produces fruits. Determine if there is a day ... | def common_fruit_day(test_cases):
results = []
for case in test_cases:
n = case[0]
tree_days = case[1:]
common_days = set(tree_days[0])
for days in tree_days[1:]:
common_days.intersection_update(days)
if common_days:
results.append("YES")
e... | from solution import common_fruit_day, read_input, find_common_fruit_day
def test_common_fruit_day():
test_cases = [
(3, ["Mon", "Tue", "Wed"], ["Tue", "Thu", "Sat"], ["Tue", "Fri"]),
(2, ["Mon", "Wed", "Fri"], ["Tue", "Thu", "Sat"]),
]
assert common_fruit_day(test_cases) == ["YES", "NO"]
... | [
{
"docstring": null,
"function_declaration": "def common_fruit_day(test_cases):",
"function_name": "common_fruit_day",
"parameter_list": "(test_cases)"
},
{
"docstring": null,
"function_declaration": "def read_input(input_data):",
"function_name": "read_input",
"parameter_list": ... | [
1,
0,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def common_fruit_day(test_cases):\n results = []\n for case in test_cases:\n n = case[0]\n tree_days = case[1:]\n common_days = ... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00034062",
"row_id": 34062,
"seed_ids": "[3441]"
} | 0.699862 | Code_Contests_34062 | I | [
"common_fruit_day",
"read_input",
"find_common_fruit_day"
] | 3 | [
[
"find_common_fruit_day",
"common_fruit_day"
],
[
"find_common_fruit_day",
"read_input"
]
] | 2 | [
"read_input"
] | false | [] | false | pytest | true | [] | true | 4a91272b2b5f508adca4511e2946d4fe6a37b9cc | b20cd21933fc642582ea6bfe73807b6a42c1c90f | |||
v1.0 | instruct | Code_Contests | Code_Contests_34134_I | Given is an undirected tree T with N vertices. The vertices are numbered 1 to N. An undirected tree is a connected graph with N vertices and N-1 edges.
Determine the diameter of the tree. The diameter of a tree is the length of the longest path between any two nodes in the tree.
Constraints:
* 1 ≤ N ≤ 1000
* 1 ≤ u, v... | from collections import deque, defaultdict
def bfs_for_furthest_node(start_node, tree):
visited = set()
max_distance = 0
furthest_node = start_node
queue = deque([(start_node, 0)])
while queue:
node, distance = queue.popleft()
if distance > max_distance:
max_distanc... | from solution import tree_diameter
def test_tree_diameter_example1():
edges = [(1, 2), (1, 3), (3, 4), (3, 5)]
assert tree_diameter(5, edges) == 3
def test_tree_diameter_example2():
edges = [(1, 2), (2, 3)]
assert tree_diameter(3, edges) == 2
def test_tree_diameter_single_node():
assert tree_diam... | [
{
"docstring": null,
"function_declaration": "def bfs_for_furthest_node(start_node, tree):",
"function_name": "bfs_for_furthest_node",
"parameter_list": "(start_node, tree)"
},
{
"docstring": null,
"function_declaration": "def tree_diameter(N, edges):",
"function_name": "tree_diamete... | [
0,
0,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from collections import defaultdict, deque\n\ndef get_tree_diameter(N, edges):\n # Create an adjacency list from the edges\n tree = defaultdict(list)... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00034134",
"row_id": 34134,
"seed_ids": "[6433]"
} | 0.736637 | Code_Contests_34134 | I | [
"bfs_for_furthest_node",
"tree_diameter"
] | 2 | [
[
"tree_diameter",
"bfs_for_furthest_node"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 5cd338a798288fa9abe18697d4a547420b841ca8 | ae93c4f872bc5c4aa4c615c9ea66a3b9d3834b63 | |||
v1.0 | instruct | Code_Contests | Code_Contests_34172_I | You are given a string s consisting of lowercase letters and a set of substrings. Your task is to determine whether the string s can be segmented into a space-separated sequence of one or more of the given substrings.
Input
The first line contains the string s, composed of lowercase letters (1 ≤ |s| ≤ 1000).
The sec... | def can_segment_string(s, substrings):
"""
Determines if the string s can be segmented into a space-separated sequence of one or more substrings.
"""
n = len(s)
dp = [False] * (n + 1)
dp[0] = True
for i in range(1, n + 1):
for substring in substrings:
if dp[i - len(subst... | from solution import can_segment_string, solve
def test_can_segment_string_1():
s = "leetcode"
substrings = ["leet", "code", "lee", "tcode"]
assert can_segment_string(s, substrings) == "Yes"
def test_can_segment_string_2():
s = "applepenapple"
substrings = ["apple", "pen"]
assert can_segment_s... | [
{
"docstring": "Determines if the string s can be segmented into a space-separated sequence of one or more substrings.",
"function_declaration": "def can_segment_string(s, substrings):",
"function_name": "can_segment_string",
"parameter_list": "(s, substrings)"
},
{
"docstring": null,
"f... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def can_segment(s, substrings):\n \"\"\"\n Determines if the string s can be segmented into a sequence of one or more of the given substrings.\n \... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00034172",
"row_id": 34172,
"seed_ids": "[4747]"
} | 0.747938 | Code_Contests_34172 | I | [
"can_segment_string",
"solve"
] | 2 | [
[
"solve",
"can_segment_string"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | ef92e98ed76d01709009f63289caaaf7253acecf | 47882a25097d91abdb61ca9a5dc95eff6cceb4eb | |||
v1.0 | instruct | Code_Contests | Code_Contests_34187_I | You are given a list of employees with their department IDs and their monthly salaries. There are N employees in total (each with a department-ID and salary).
The list is unorganized, and Anna and James decide to sort it.
Anna likes things in alphabetical order and prefers that the department names are sorted alpha... | def sort_employees(employee_list):
"""
Sorts the employee list by department names in alphabetical order
and for each department, sorts employees by salaries in descending order.
"""
# First, we sort the list by department name (alphabetical order)
# and by salary in descending order within the ... | def test_sort_employees():
input_data = [
("IT", 5000),
("HR", 3000),
("Finance", 7000),
("HR", 8000),
("IT", 6000)
]
expected_output = [
("Finance", 7000),
("HR", 8000),
("HR", 3000),
("IT", 6000),
("IT", 5000)
]
... | [
{
"docstring": "Sorts the employee list by department names in alphabetical order\nand for each department, sorts employees by salaries in descending order.",
"function_declaration": "def sort_employees(employee_list):",
"function_name": "sort_employees",
"parameter_list": "(employee_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 sort_employees(N, employee_list):\n \"\"\"\n Sort employees by department names alphabetically and salaries in descending order.\n \n Args:... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00034187",
"row_id": 34187,
"seed_ids": "[3099]"
} | 0.596886 | Code_Contests_34187 | I | [
"sort_employees",
"process_employees_data"
] | 2 | [
[
"process_employees_data",
"sort_employees"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | b3e05f30e06c698f1e19963950d3bd2572286816 | 1ca9dea4c959e22d040c4cf78e648f67a249fc7f | |||
v1.0 | instruct | Code_Contests | Code_Contests_34190_I | Write a function that determines if a string can be transformed into another string through a specific series of operations. You are given a source string and a target string, as well as a list of valid operations. Each operation is defined as replacing one character with another character in the source string.
Your t... | from collections import deque
def min_operations_to_transform(T, test_cases):
results = []
for case in test_cases:
source, target, M, operations = case
if len(source) != len(target):
results.append(-1)
continue
transformation_map = {}
for op... | from solution import min_operations_to_transform, transform_strings
def test_example_cases():
# Example case 1
num_tests = 2
all_cases = [
("abc", "bca", 3, [("a", "b"), ("b", "c"), ("c", "a")]),
("hello", "world", 1, [("h", "f")])
]
assert min_operations_to_transform(num_tests, all... | [
{
"docstring": null,
"function_declaration": "def min_operations_to_transform(T, test_cases):",
"function_name": "min_operations_to_transform",
"parameter_list": "(T, test_cases)"
},
{
"docstring": null,
"function_declaration": "def transform_strings(num_tests, all_cases):",
"functio... | [
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_transformations(T, test_cases):\n def bfs(source, target, operations):\n from collections import deque, defaultdict\n \n if... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00034190",
"row_id": 34190,
"seed_ids": "[10796]"
} | 0.77795 | Code_Contests_34190 | I | [
"min_operations_to_transform",
"transform_strings"
] | 2 | [
[
"transform_strings",
"min_operations_to_transform"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 225ee124b3d72aa6b848151391afe6c02cb8e19e | 63dca82e18db83ca1a1b61f4c2f66a9c0e8055d7 | |||
v1.0 | instruct | Code_Contests | Code_Contests_34231_I | Given a list of words, you are to find the longest subsequence that can be formed by deleting some characters from each word in the list such that the subsequence is the same when read from left to right and right to left.
A subsequence is a sequence derived from another sequence by deleting some or no elements withou... | def longest_palindromic_subsequence_length(word):
"""
Given a word, find the length of the longest palindromic subsequence.
"""
n = len(word)
dp = [[0] * n for _ in range(n)]
for i in range(n):
dp[i][i] = 1
for cl in range(2, n + 1):
for i in range(n - cl + 1):
... | from solution import longest_palindromic_subsequence, longest_palindromic_subsequence_length
def test_longest_palindromic_subsequence_length():
assert longest_palindromic_subsequence_length("abca") == 3
assert longest_palindromic_subsequence_length("bananas") == 5
assert longest_palindromic_subsequence_len... | [
{
"docstring": "Given a word, find the length of the longest palindromic subsequence.",
"function_declaration": "def longest_palindromic_subsequence_length(word):",
"function_name": "longest_palindromic_subsequence_length",
"parameter_list": "(word)"
},
{
"docstring": "Given a list of words,... | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def longest_palindromic_subsequence(s):\n n = len(s)\n if n == 0:\n return 0\n dp = [[0] * n for _ in range(n)]\n for i in range(n):\n ... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00034231",
"row_id": 34231,
"seed_ids": "[8639]"
} | 0.785718 | Code_Contests_34231 | I | [
"longest_palindromic_subsequence_length",
"longest_palindromic_subsequence"
] | 2 | [
[
"longest_palindromic_subsequence",
"longest_palindromic_subsequence_length"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 370e3478ba5176fc9f9610e7a2bdb232b193838f | 5d33b82e8832317cfed3bccec69393fc80a0fd18 | |||
v1.0 | instruct | Code_Contests | Code_Contests_34240_I | Given an undirected graph with `N` nodes and `E` edges, you need to determine whether the graph contains a cycle. If the graph contains a cycle, you also need to find out the minimum length of the cycle. If there are no cycles, output `-1`.
Input:
- The first line contains two integers `N` and `E` — the number of node... | from collections import deque
def shortest_cycle(N, E, edges):
graph = [[] for _ in range(N)]
for u, v in edges:
graph[u - 1].append(v - 1)
graph[v - 1].append(u - 1)
def bfs(start):
dist = [-1] * N
parent = [-1] * N
dist[start] = 0
queue = deque([start... | from solution import find_shortest_cycle
def test_shortest_cycle_sample1():
N = 4
E = 4
edges = [
"1 2",
"2 3",
"3 1",
"3 4"
]
assert find_shortest_cycle(N, E, edges) == 3
def test_shortest_cycle_sample2():
N = 3
E = 2
edges = [
"1 2",
"2... | [
{
"docstring": null,
"function_declaration": "def shortest_cycle(N, E, edges):",
"function_name": "shortest_cycle",
"parameter_list": "(N, E, edges)"
},
{
"docstring": null,
"function_declaration": "def find_shortest_cycle(N, E, edge_list):",
"function_name": "find_shortest_cycle",
... | [
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": "from collections import deque, defaultdict\n\ndef find_shortest_cycle(N, E, edges):\n graph = defaultdict(list)\n for u, v in edges:\n graph[u... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00034240",
"row_id": 34240,
"seed_ids": "[10176]"
} | 0.781049 | Code_Contests_34240 | I | [
"shortest_cycle",
"find_shortest_cycle"
] | 2 | [
[
"find_shortest_cycle",
"shortest_cycle"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | b6ff1e2140c9b8942021d8e7f430f5f8808669c4 | 8eb1ec7c2b2dc1263d87f58b5b6afbee411f0e61 | |||
v1.0 | instruct | Code_Contests | Code_Contests_34253_I | The Galactic Federation has recently incorporated Earth into their alliance, and as part of this integration, Earth has been introduced to their advanced communications protocol. The requirement is that Earthlings should now encode their messages using a specific pattern encryption.
In this encryption method, each cha... | def convert_to_numeric_sequence(s):
numeric_sequence = []
for char in s:
numeric_sequence.append(ord(char) - ord('a') + 1)
return numeric_sequence
def sum_of_digits(num):
total = 0
while num > 0:
total += num % 10
num //= 10
return total
def single_digit_compress(numeri... | def test_convert_to_numeric_sequence():
assert convert_to_numeric_sequence("hello") == [8, 5, 12, 12, 15]
assert convert_to_numeric_sequence("world") == [23, 15, 18, 12, 4]
assert convert_to_numeric_sequence("a") == [1]
assert convert_to_numeric_sequence("zzz") == [26, 26, 26]
def test_sum_of_digits():... | [
{
"docstring": null,
"function_declaration": "def convert_to_numeric_sequence(s):",
"function_name": "convert_to_numeric_sequence",
"parameter_list": "(s)"
},
{
"docstring": null,
"function_declaration": "def sum_of_digits(num):",
"function_name": "sum_of_digits",
"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 compress_message(s):\n def alphabet_position(c):\n return ord(c) - ord('a') + 1\n\n def digit_sum(n):\n while n > 9:\n n... | trial_gpt4o_4 | {
"original_instruction": "",
"prompt_id": "00034253",
"row_id": 34253,
"seed_ids": "[10591]"
} | 0.704896 | Code_Contests_34253 | I | [
"convert_to_numeric_sequence",
"sum_of_digits",
"single_digit_compress",
"compress_message"
] | 4 | [
[
"compress_message",
"convert_to_numeric_sequence"
],
[
"compress_message",
"single_digit_compress"
],
[
"single_digit_compress",
"sum_of_digits"
]
] | 3 | [] | false | [] | false | pytest | false | [] | true | fba79957cc52eb2c8b39bd514c565cf5ea6dde97 | 89a4b69bdcdccb6cfee27c5cead8a25def95c091 | |||
v1.0 | instruct | Code_Contests | Code_Contests_34257_I | You are given two strings, s1 and s2. Your task is to determine whether s2 is a scrambled string of s1.
A scrambled string is defined as follows:
- If a string can be obtained by swapping two non-empty substrings of another string, it is considered a scrambled string.
- For instance, if we take the string "great":
... | def is_scramble(s1, s2):
"""
Determines if s2 is a scrambled string of s1.
"""
if s1 == s2:
return True
if sorted(s1) != sorted(s2):
return False
n = len(s1)
for i in range(1, n):
if (is_scramble(s1[:i], s2[:i]) and is_scramble(s1[i:], s2[i:])) or (is_scramble(s... | from solution import scramble_check
def test_scramble_check_1():
assert scramble_check("great", "rgtae") == "YES"
def test_scramble_check_2():
assert scramble_check("abcde", "caebd") == "NO"
def test_scramble_check_3():
assert scramble_check("a", "a") == "YES"
def test_scramble_check_4():
assert scr... | [
{
"docstring": "Determines if s2 is a scrambled string of s1.",
"function_declaration": "def is_scramble(s1, s2):",
"function_name": "is_scramble",
"parameter_list": "(s1, s2)"
},
{
"docstring": "Outputs \"YES\" if s2 is a scrambled string of s1, otherwise \"NO\".",
"function_declaration... | [
0,
1,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_scramble(s1, s2):\n \"\"\"\n Returns True if s2 is a scrambled string of s1, otherwise False.\n \"\"\"\n if len(s1) != len(s2):\n ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00034257",
"row_id": 34257,
"seed_ids": "[1274]"
} | 0.598778 | Code_Contests_34257 | I | [
"is_scramble",
"scramble_check"
] | 2 | [
[
"scramble_check",
"is_scramble"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | a057e8337c5cffa452e647049cfedd57d13c5172 | d0210ac217351121870e134d037b2196e7207514 | |||
v1.0 | instruct | Code_Contests | Code_Contests_34264_I | Twilight Sparkle is trying to organize books in the Ponyville library. Unfortunately, due to some mischievous acts by Discord, the arrangement of books got completely messed up. Twilight needs your help to sort the books. Each book has a unique identifier, but they are now scattered in arbitrary order.
Twilight wants ... | import bisect
def longest_increasing_subsequence(arr):
"""
Returns the length of the longest increasing subsequence in the array.
"""
if not arr:
return 0
lis = []
for book in arr:
pos = bisect.bisect_left(lis, book)
if pos == len(lis):
lis.append(book)
... | from solution import find_max_sorted_books
def test_example_cases():
assert find_max_sorted_books(5, [3, 10, 2, 1, 20]) == 3
assert find_max_sorted_books(6, [3, 2, 6, 4, 5, 1]) == 3
assert find_max_sorted_books(5, [5, 4, 3, 2, 1]) == 1
def test_single_element():
assert find_max_sorted_books(1, [10]) =... | [
{
"docstring": "Returns the length of the longest increasing subsequence in the array.",
"function_declaration": "def longest_increasing_subsequence(arr):",
"function_name": "longest_increasing_subsequence",
"parameter_list": "(arr)"
},
{
"docstring": null,
"function_declaration": "def f... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import bisect\n\ndef longest_increasing_subsequence(arr):\n \"\"\"\n Returns the length of the longest increasing subsequence in the array.\n \"\"... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00034264",
"row_id": 34264,
"seed_ids": "[2233]"
} | 0.66118 | Code_Contests_34264 | I | [
"longest_increasing_subsequence",
"find_max_sorted_books"
] | 2 | [
[
"find_max_sorted_books",
"longest_increasing_subsequence"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 48920e09ec94441ac9b8b50af970177ba95b3299 | 8b4894c3fb724866a68e0a61db450e0ca477d122 | |||
v1.0 | instruct | Code_Contests | Code_Contests_34332_I | You are given a data set consisting of n distinct points in two-dimensional space. Your task is to find the smallest circle that can contain all the given points.
Input
The first line of input will contain one integer n (1 ≤ n ≤ 10^4), the number of points.
Each of the next n lines will contain two integers xi and y... | import math
from typing import List, Tuple
class Circle:
def __init__(self, x: float = 0.0, y: float = 0.0, r: float = 0.0):
self.x = x
self.y = y
self.r = r
def dist(a: Tuple[float, float], b: Tuple[float, float]) -> float:
return math.sqrt((a[0] - b[0]) ** 2 + (a[1] - b[1]) ** 2)
de... | import pytest
from solution import smallest_enclosing_circle
def test_case_1():
n = 3
points = [(1, 1), (2, 2), (3, 3)]
cx, cy, r = smallest_enclosing_circle(n, points)
assert round(cx, 6) == 2.000000
assert round(cy, 6) == 2.000000
assert round(r, 6) == 1.414214
def test_case_2():
n =... | [] | [
1,
0,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from math import sqrt, inf\n\ndef dist(p1, p2):\n return sqrt((p1[0] - p2[0]) ** 2 + (p1[1] - p2[1]) ** 2)\n \ndef smallest_circle(points):\n # Func... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00034332",
"row_id": 34332,
"seed_ids": "[7762]"
} | 0.671249 | Code_Contests_34332 | I | [
"dist",
"is_in_circle",
"make_circle_two_points",
"make_circle_three_points",
"find_smallest_enclosing_circle",
"smallest_enclosing_circle"
] | 6 | [
[
"find_smallest_enclosing_circle",
"is_in_circle"
],
[
"find_smallest_enclosing_circle",
"make_circle_three_points"
],
[
"find_smallest_enclosing_circle",
"make_circle_two_points"
],
[
"is_in_circle",
"dist"
],
[
"make_circle_three_points",
"dist"
],
[
... | 7 | [] | false | [
"Circle"
] | true | pytest | true | [] | true | e3a981fff783820425e52bfa043e1e86cc955ab9 | 94fad7259597dc59715b26bc9c0b061b2c5a5c8a | |||
v1.0 | instruct | Code_Contests | Code_Contests_34341_I | You are given an array of integers and your task is to determine if it is possible to rearrange the array such that every consecutive pair of elements has a common divisor greater than 1. If such a rearrangement is possible, output one valid rearrangement. Otherwise, output "NO" without quotes.
Input
The first line o... | import math
from itertools import permutations
def gcd(x, y):
while y:
x, y = y, x % y
return x
def can_rearrange(arr):
if len(arr) == 1:
# If there's only one element, we can't have consecutive pairs, hence it could be trivially rearranged
return "YES\n" + str(arr[0])
# C... | from solution import can_rearrange
def test_can_rearrange_example_case():
assert can_rearrange([2, 3, 6, 9]).startswith("YES")
def test_can_rearrange_single_element():
assert can_rearrange([1]) == "YES\n1"
assert can_rearrange([10]) == "YES\n10"
def test_can_rearrange_impossible_case():
assert can_re... | [
{
"docstring": null,
"function_declaration": "def gcd(x, y):",
"function_name": "gcd",
"parameter_list": "(x, y)"
},
{
"docstring": null,
"function_declaration": "def can_rearrange(arr):",
"function_name": "can_rearrange",
"parameter_list": "(arr)"
}
] | [
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 itertools import permutations\n\ndef can_rearrange(arr):\n \"\"\"\n Determines if it is possible to rearrange the array su... | trial_gpt4o_5 | {
"original_instruction": "",
"prompt_id": "00034341",
"row_id": 34341,
"seed_ids": "[3043]"
} | 0.632687 | Code_Contests_34341 | I | [
"gcd",
"can_rearrange"
] | 2 | [
[
"can_rearrange",
"gcd"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 573fa85e6d53d10116ebee6ad3daeb6477e414bd | 53326cf29d02230201c8adf969de9fc5b3605d8c | |||
v1.0 | instruct | Code_Contests | Code_Contests_34342_I | In a land far away, there exists a kingdom where people live in villages connected by roads. The kingdom has N villages numbered from 1 to N and M bidirectional roads. Each road connects two villages and has a certain travel time associated with it.
The king is keen to ensure that his subjects can travel easily throug... | import heapq
from collections import defaultdict, deque
def dijkstra(n, start, graph):
dist = [float('inf')] * (n + 1)
dist[start] = 0
pq = [(0, start)]
while pq:
current_dist, u = heapq.heappop(pq)
if current_dist > dist[u]:
continue
for v, weight in graph[u]:
... | def test_case_1():
input_data = "4 5\n1 2 1\n2 3 1\n3 4 1\n1 3 2\n2 4 2\n"
expected_output = 1
assert can_have_multiple_shortest_paths(4, 5, [(1, 2, 1), (2, 3, 1), (3, 4, 1), (1, 3, 2), (2, 4, 2)]) == expected_output
def test_case_2():
input_data = "3 3\n1 2 2\n2 3 2\n3 1 3\n"
expected_output = 0
... | [
{
"docstring": null,
"function_declaration": "def dijkstra(n, start, graph):",
"function_name": "dijkstra",
"parameter_list": "(n, start, graph)"
},
{
"docstring": null,
"function_declaration": "def can_have_multiple_shortest_paths(n, m, edges):",
"function_name": "can_have_multiple_... | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import heapq\nimport sys\nfrom collections import defaultdict, deque\n\ndef can_ensure_multiple_minimum_paths(N, M, roads):\n # Create adjacency list re... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00034342",
"row_id": 34342,
"seed_ids": "[7379]"
} | 0.797682 | Code_Contests_34342 | I | [
"dijkstra",
"can_have_multiple_shortest_paths",
"main"
] | 3 | [
[
"can_have_multiple_shortest_paths",
"dijkstra"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | 56e5b0efa8baf3e1cc6603a7d84e05d09c2758f8 | a59d75a5ba1ca14fa6ab3a64c7e22f020ff67a8b | |||
v1.0 | instruct | Code_Contests | Code_Contests_34344_I | In a city, there are N water tanks connected by pipes. Each pipe connects two water tanks i and j, and has a certain length d. The goal is to determine the minimum distance needed to repair to ensure all water tanks are connected.
Given an integer N representing the number of water tanks, M representing the number of ... | 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 xroot != yroot:
if rank[xroot] < rank[yroot]:
parent[xroot] = yroot
elif rank[xroo... | import pytest
from solution import solve, minimum_repair_cost
def test_example_1():
assert solve(2, [
(4, 4, [(1, 2, 1), (2, 3, 4), (3, 4, 2), (4, 1, 3)]),
(3, 1, [(1, 2, 1)])
]) == [6, -1]
def test_disconnected_graph():
assert solve(1, [
(5, 3, [(1, 2, 3), (2, 3, 2), (3, 4, 4)])
... | [
{
"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,
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 find(parent, i):\n if parent[i] == i:\n return i\n else:\n return find(parent, parent[i])\n\ndef union(parent, rank, x, y):\n xr... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00034344",
"row_id": 34344,
"seed_ids": "[3307]"
} | 0.664622 | Code_Contests_34344 | I | [
"find",
"union",
"minimum_repair_cost",
"solve"
] | 4 | [
[
"minimum_repair_cost",
"find"
],
[
"minimum_repair_cost",
"union"
],
[
"solve",
"minimum_repair_cost"
],
[
"union",
"find"
]
] | 4 | [] | false | [] | false | pytest | true | [] | true | 61acbb42055fab2b2cabb37501b7689a7ed0cffb | 450ed11d36d6d453578b80e51d88426825ba6556 | |||
v1.0 | instruct | Code_Contests | Code_Contests_34505_I | Two Squares on a Plane
You are given two squares on a 2D plane. Each of the squares is defined by its four vertices, which are given in counterclockwise order. Determine if the two squares overlap, and if so, output the area of their intersection. If the squares do not overlap, output 0.
**Note:** The squares are axi... | def get_square_bounds(coordinates):
"""
Given four coordinates representing the vertices of an axis-aligned square,
return the bounds of the square.
Args:
coordinates: List of tuples [(x1, y1), (x2, y2), (x3, y3), (x4, y4)]
Returns:
(x_min, x_max, y_min, y_max) The bounds of the sq... | from solution import intersection_area
def test_no_overlap():
square1 = [(0, 0), (0, 1), (1, 1), (1, 0)]
square2 = [(2, 2), (2, 3), (3, 3), (3, 2)]
assert intersection_area(square1, square2) == 0
def test_overlap_area_1():
square1 = [(0, 0), (0, 2), (2, 2), (2, 0)]
square2 = [(1, 1), (1, 3), (3, 3... | [
{
"docstring": "Given four coordinates representing the vertices of an axis-aligned square,\nreturn the bounds of the square.\n\nArgs:\ncoordinates: List of tuples [(x1, y1), (x2, y2), (x3, y3), (x4, y4)]\n\nReturns:\n(x_min, x_max, y_min, y_max) The bounds of the square.",
"function_declaration": "def get_... | [
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 area_of_intersection(x1_min, x1_max, y1_min, y1_max, x2_min, x2_max, y2_min, y2_max):\n \"\"\"\n Computes the area of intersection between two ax... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00034505",
"row_id": 34505,
"seed_ids": "[6655]"
} | 0.568107 | Code_Contests_34505 | I | [
"get_square_bounds",
"intersection_area"
] | 2 | [
[
"intersection_area",
"get_square_bounds"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 5d0f0e26b8624721ab405c0cb392d2584b2d361a | eb85fe29e89125ba8265c6fd99a9677ded2d9e4c | |||
v1.0 | instruct | Code_Contests | Code_Contests_34508_I | Develop a program that simulates the behavior of an automatic lamp. The lamp turns on or off based on movements detected by a sensor and the current time of day. The lamp reacts differently during day and night times.
Inputs:
- A series of events that can either be 'movement' or 'no movement'.
- The current time of da... | from datetime import datetime, timedelta
def is_daytime(current_time, start_daytime, end_daytime):
current = datetime.strptime(current_time, "%H:%M").time()
start = datetime.strptime(start_daytime, "%H:%M").time()
end = datetime.strptime(end_daytime, "%H:%M").time()
if start < end:
return start... | def test_simulate_lamp_daytime():
events = ["movement", "no movement", "movement", "no movement"]
assert simulate_lamp(4, events, "12:00", "06:00", "18:00") == "off"
def test_simulate_lamp_night_short_duration():
events = ["movement", "no movement", "no movement", "no movement"]
assert simulate_lamp(4,... | [
{
"docstring": null,
"function_declaration": "def is_daytime(current_time, start_daytime, end_daytime):",
"function_name": "is_daytime",
"parameter_list": "(current_time, start_daytime, end_daytime)"
},
{
"docstring": null,
"function_declaration": "def simulate_lamp(n, events, current_ti... | [
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 datetime import datetime, timedelta\n\ndef is_night(time_str, day_start, day_end):\n time = datetime.strptime(time_str, '%H:%M')\n day_start_tim... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00034508",
"row_id": 34508,
"seed_ids": "[11861]"
} | 0.520216 | Code_Contests_34508 | I | [
"is_daytime",
"simulate_lamp"
] | 2 | [
[
"simulate_lamp",
"is_daytime"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | ddc0e55ed713b58a4ea33e2af734b45f33c75378 | 3d61c342eaaac2fb47ce0d9da62470482b68b92c | |||
v1.0 | instruct | Code_Contests | Code_Contests_34529_I | Write a program to find all the prime numbers between a given range [A, B] (inclusive). A number is said to be prime if it is greater than 1 and has no positive divisors other than 1 and itself.
Input:
The first line contains T, the number of test cases (1 ≤ T ≤ 10).
Each of the next T lines contains two integers, A a... | def is_prime(num):
"""Returns True if num is a prime number, otherwise False."""
if num <= 1:
return False
if num <= 3:
return True
if num % 2 == 0 or num % 3 == 0:
return False
i = 5
while i * i <= num:
if num % i == 0 or num % (i + 2) == 0:
return Fa... | from solution import is_prime, primes_in_range, prime_numbers_in_ranges
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
... | [
{
"docstring": "Returns True if num is a prime number, otherwise False.",
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": "Returns a list of all prime numbers in the range [A, B] inclusive.",
"function_declaration": "... | [
0,
1
] | 1 | medium | 0.5 | {
"trial_gpt4o_0": null,
"trial_gpt4o_1": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared1_results_combined.jsonl",
"solution_code": "def is_prime(num):\n \"\"\"\n Checks if a number is prime.\n \"\"\"\n if num <= 1:\n return False\n if num <... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00034529",
"row_id": 34529,
"seed_ids": "[11143]"
} | 0.634061 | Code_Contests_34529 | I | [
"is_prime",
"primes_in_range",
"prime_numbers_in_ranges"
] | 3 | [
[
"prime_numbers_in_ranges",
"primes_in_range"
],
[
"primes_in_range",
"is_prime"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | f63c664b95212ab74613ac2cf1275006f0b13acf | 47efb1d46a2dddc4fa00e172ca9688c4512814b5 | |||
v1.0 | instruct | Code_Contests | Code_Contests_34537_I | You're given a string `S` consisting of only lowercase Latin letters. Your task is to generate all possible permutations of this string and determine if there exist any valid English words among the generated permutations. If there are multiple valid words, you must return the lexicographically smallest word. If there ... | from itertools import permutations
def is_valid_word(word):
# This is a placeholder for the actual implementation.
# For the purpose of the example, assume a predefined dictionary:
valid_words = {"loop", "pool", "pols", "spools", "loops"}
return word in valid_words
def find_lexicographically_smallest_... | from solution import find_lexicographically_smallest_valid_word
def test_single_permutation_valid_word():
assert find_lexicographically_smallest_valid_word("loop") == "loop"
def test_no_valid_word():
assert find_lexicographically_smallest_valid_word("oloop") == "no valid word"
def test_multiple_valid_words()... | [
{
"docstring": null,
"function_declaration": "def is_valid_word(word):",
"function_name": "is_valid_word",
"parameter_list": "(word)"
},
{
"docstring": null,
"function_declaration": "def find_lexicographically_smallest_valid_word(S):",
"function_name": "find_lexicographically_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": "from itertools import permutations\n\n# This function is assumed to be available for checking valid English words.\ndef is_valid_word(word):\n # For the... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00034537",
"row_id": 34537,
"seed_ids": "[8648]"
} | 0.676922 | Code_Contests_34537 | I | [
"is_valid_word",
"find_lexicographically_smallest_valid_word"
] | 2 | [
[
"find_lexicographically_smallest_valid_word",
"is_valid_word"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | c49db72a26b55627c9da21bf86c58b815960e5d7 | e862c2fee13ed2baee8f019cd58bde29eb464948 | |||
v1.0 | instruct | Code_Contests | Code_Contests_34553_I | In a magical kingdom far away, there exists a peculiar language called "Palindromic Language." Words in this language can be read the same backward as forward. The people of this kingdom are very fond of these words, and they always like to arrange them in a special sequence.
One day, the king of the kingdom asked his... | def is_palindrome(word):
"""
Check if a given word is a palindrome.
"""
return word == word[::-1]
def find_sorted_palindromic_titles(n, titles):
"""
Find and sort all the palindromic titles in lexicographical order.
Args:
n : int : number of titles
titles : list of str : list o... | from solution import is_palindrome, find_sorted_palindromic_titles
def test_is_palindrome():
assert is_palindrome("radar")
assert is_palindrome("level")
assert not is_palindrome("hello")
assert is_palindrome("deified")
assert not is_palindrome("world")
def test_find_sorted_palindromic_titles_with_... | [
{
"docstring": "Check if a given word is a palindrome.",
"function_declaration": "def is_palindrome(word):",
"function_name": "is_palindrome",
"parameter_list": "(word)"
},
{
"docstring": "Find and sort all the palindromic titles in lexicographical order.\n\nArgs:\nn : int : number of titles... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def find_and_sort_palindromic_titles(n, titles):\n \"\"\"\n This function takes the number of titles 'n' and a list of titles 'titles'.\n It retur... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00034553",
"row_id": 34553,
"seed_ids": "[4527]"
} | 0.681415 | Code_Contests_34553 | I | [
"is_palindrome",
"find_sorted_palindromic_titles"
] | 2 | [
[
"find_sorted_palindromic_titles",
"is_palindrome"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 11d0359c02c9f416ab040dd7360a4a0364169578 | 3a131e1e6c687fee4cd911e0fabe09dc8ee647f1 | |||
v1.0 | instruct | Code_Contests | Code_Contests_34634_I | You are given a binary tree with N nodes. Your task is to determine whether the tree is height-balanced.
A binary tree is height-balanced if the absolute difference between the height of the left and right subtrees of every node in the tree is at most 1.
Input:
The first line contains a single integer T - the number ... | class TreeNode:
def __init__(self, val=0, left=None, right=None):
self.val = val
self.left = left
self.right = right
def build_tree(nodes):
if not nodes:
return None
val_to_node = {}
for v, l, r in nodes:
if v not in val_to_node:
val_to_node[v] = Tree... | from solution import solve
def test_example_cases():
T = 2
test_cases = [
[(1, 2, 3), (2, -1, -1), (3, -1, -1)],
[(4, 2, 6), (2, 1, 3), (1, -1, -1), (3, -1, -1), (6, 5, 7), (5, -1, -1), (7, -1, -1)]
]
assert solve(T, test_cases) == ["YES", "YES"]
def test_single_node():
T = 1
... | [] | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "class TreeNode:\n def __init__(self, val=0, left=None, right=None):\n self.val = val\n self.left = left\n self.right = right\n\ndef... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00034634",
"row_id": 34634,
"seed_ids": "[5839]"
} | 0.748586 | Code_Contests_34634 | I | [
"build_tree",
"is_height_balanced",
"solve"
] | 3 | [
[
"solve",
"build_tree"
],
[
"solve",
"is_height_balanced"
]
] | 2 | [] | false | [
"TreeNode"
] | true | pytest | true | [] | true | 055e8824a4161e63be032c1e7d89cf9009d420a4 | f7e5fcbe33b151926f840fb1f7d50ea8d1afec38 | |||
v1.0 | instruct | Code_Contests | Code_Contests_34652_I | Bob is learning about numerical patterns and sequences. He has discovered an interesting sequence of numbers that follow a particular rule. Can you help him determine the rule and generate the sequence?
Given a positive integer n, generate a sequence of length n where the i-th element is defined as the sum of the fact... | import math
def digit_factorial_sum(num):
"""
Returns the sum of the factorials of the digits of num.
"""
return sum(math.factorial(int(d)) for d in str(num))
def generate_sequence(n):
"""
Generates a sequence of length n where the i-th element is defined as the sum of the factorials of its di... | from solution import digit_factorial_sum, generate_sequence, formatted_sequence
def test_digit_factorial_sum():
assert digit_factorial_sum(1) == 1
assert digit_factorial_sum(2) == 2
assert digit_factorial_sum(3) == 6
assert digit_factorial_sum(4) == 24
assert digit_factorial_sum(5) == 120
asser... | [
{
"docstring": "Returns the sum of the factorials of the digits of num.",
"function_declaration": "def digit_factorial_sum(num):",
"function_name": "digit_factorial_sum",
"parameter_list": "(num)"
},
{
"docstring": "Generates a sequence of length n where the i-th element is defined as the su... | [
0,
0,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import math\n\ndef sum_of_digit_factorials(n):\n \"\"\"\n Generates a sequence of length n where the i-th element is the sum of the factorials of its... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00034652",
"row_id": 34652,
"seed_ids": "[5774]"
} | 0.55796 | Code_Contests_34652 | I | [
"digit_factorial_sum",
"generate_sequence",
"formatted_sequence"
] | 3 | [
[
"formatted_sequence",
"generate_sequence"
],
[
"generate_sequence",
"digit_factorial_sum"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | a3216f6d008b745340b6ea007154559765a221f5 | 359ba72686c86e202dc8688a90ee0672384f00c3 | |||
v1.0 | instruct | Code_Contests | Code_Contests_34722_I | A popular graphics editing software wants to introduce a new feature that will allow its users to apply a complex filter to their images. The filter works by rotating sections of the image's pixel matrix. Given an NxN matrix of integers representing pixel values, the filter rotates every KxK block of the matrix 90 degr... | from typing import List
def rotate_90_clockwise(block: List[List[int]]) -> List[List[int]]:
"""
Rotates a KxK block 90 degrees clockwise.
"""
K = len(block)
rotated = [[0] * K for _ in range(K)]
for i in range(K):
for j in range(K):
rotated[j][K - 1 - i] = block[i][j]
re... | def test_apply_filter_case_1():
N = 4
K = 2
A = [
[1, 2, 3, 4],
[5, 6, 7, 8],
[9, 10, 11, 12],
[13, 14, 15, 16]
]
expected = [
[5, 1, 7, 3],
[6, 2, 8, 4],
[13, 9, 15, 11],
[14, 10, 16, 12]
]
assert apply_filter(N, K, A) == expec... | [
{
"docstring": "Rotates a KxK block 90 degrees clockwise.",
"function_declaration": "def rotate_90_clockwise(block):",
"function_name": "rotate_90_clockwise",
"parameter_list": "(block)"
},
{
"docstring": "Applies the filter over NxN matrix with KxK blocks.",
"function_declaration": "def... | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from typing import List\n\ndef rotate_90_clockwise(block: List[List[int]]) -> List[List[int]]:\n \"\"\"\n Rotates a given KxK block 90 degrees clockw... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00034722",
"row_id": 34722,
"seed_ids": "[8312]"
} | 0.554791 | Code_Contests_34722 | I | [
"rotate_90_clockwise",
"apply_filter"
] | 2 | [
[
"apply_filter",
"rotate_90_clockwise"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | 9d58327746dc02fadd8edbdc7a89e64c64519d8f | e1e124f0f1fe1a302950567f231d6ac371aa5fe2 | |||
v1.0 | instruct | Code_Contests | Code_Contests_34730_I | Write an algorithm to generate a sequence of prime numbers such that the nth prime number (starting from 1) is generated at the nth position in the sequence, while also ensuring that the sum of those prime numbers up to the nth position is always less than or equal to 1,000,000. Your task is to answer Q queries, with e... | def generate_primes(limit):
"""
Generate a list of prime numbers up to the specified limit using the Sieve of Eratosthenes.
"""
sieve = [True] * (limit+1)
sieve[0] = sieve[1] = False
for start in range(2, int(limit**0.5) + 1):
if sieve[start]:
for i in range(start*start, limi... | def test_generate_primes():
primes = generate_primes(30)
assert primes == [2, 3, 5, 7, 11, 13, 17, 19, 23, 29]
def test_primes_and_sums_up_to_10th_prime():
result = primes_and_sums_up_to_nth_prime(10)
expected = [
(2, 2),
(3, 5),
(5, 10),
(7, 17),
(11, 28),
... | [
{
"docstring": "Generate a list of prime numbers up to the specified limit using the Sieve of Eratosthenes.",
"function_declaration": "def generate_primes(limit):",
"function_name": "generate_primes",
"parameter_list": "(limit)"
},
{
"docstring": "Generate the nth prime and the sum of those ... | [
1,
0,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def generate_primes(limit):\n \"\"\"\n Generate a list of prime numbers up to the specified limit using the Sieve of Eratosthenes.\n \"\"\"\n s... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00034730",
"row_id": 34730,
"seed_ids": "[12891]"
} | 0.678296 | Code_Contests_34730 | I | [
"generate_primes",
"primes_and_sums_up_to_nth_prime",
"main"
] | 3 | [
[
"primes_and_sums_up_to_nth_prime",
"generate_primes"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | d01466fb879d159b2f11a2641cdff051c0178e99 | d5464603e4b262df3bfcde078aa92bf7f3c675e2 | |||
v1.0 | instruct | Code_Contests | Code_Contests_34782_I | Given a binary tree, your task is to find the largest value in each row of the tree and return these values in an array.
An example of a binary tree is given below:
```
1
/ \
3 2
/ \ \
5 3 9
```
The largest values in each row of the tree are `[1, 3, 9]`.
Write a progr... | class TreeNode:
def __init__(self, value):
self.value = value
self.left = None
self.right = None
def add_node(root, u, v, d):
if root is None:
return
if root.value == u:
if d == 'L':
root.left = TreeNode(v)
else: # d == 'R'
root.right... | from solution import largest_values_per_row
def test_example():
n = 6
nodes = [
(1, 3, 'L'),
(1, 2, 'R'),
(3, 5, 'L'),
(3, 3, 'R'),
(2, 9, 'R')
]
assert largest_values_per_row(n, nodes) == [1, 3, 9]
def test_single_node():
n = 1
nodes = []
assert lar... | [] | [
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\nclass TreeNode:\n def __init__(self, x):\n self.val = x\n self.left = None\n self.rig... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00034782",
"row_id": 34782,
"seed_ids": "[5543]"
} | 0.587849 | Code_Contests_34782 | I | [
"add_node",
"find_largest_values_per_row",
"largest_values_per_row"
] | 3 | [
[
"largest_values_per_row",
"add_node"
],
[
"largest_values_per_row",
"find_largest_values_per_row"
]
] | 2 | [] | false | [
"TreeNode"
] | true | pytest | true | [] | true | e262c485c7b95761e3fbf6e3de0558ba166a84d8 | 75fc4e010cdd271c8ec9b418fea5573215e641e4 | |||
v1.0 | instruct | Code_Contests | Code_Contests_34966_I | def count_trees(grid):
rows = len(grid)
cols = len(grid[0])
tree_count = 0
for i in range(rows):
for j in range(cols):
if grid[i][j] == 1:
tree_count += 1
return tree_count
def max_rect_area(grid):
rows = len(grid)
cols = len(grid[0])
... | def count_trees(grid):
"""
Returns the number of trees (1s) in the grid.
"""
rows = len(grid)
cols = len(grid[0])
tree_count = 0
for i in range(rows):
for j in range(cols):
if grid[i][j] == 1:
tree_count += 1
return tree_count
def ma... | from solution import count_trees, max_rect_area, max_histogram_area
def test_count_trees():
grid1 = [[0, 1, 0], [1, 1, 1], [0, 1, 0]]
assert count_trees(grid1) == 5
grid2 = [[0, 0, 0], [0, 0, 0], [0, 0, 0]]
assert count_trees(grid2) == 0
grid3 = [[1, 1], [1, 1]]
assert count_trees(gri... | [
{
"docstring": "Returns the number of trees (1s) in the grid.",
"function_declaration": "def count_trees(grid):",
"function_name": "count_trees",
"parameter_list": "(grid)"
},
{
"docstring": "Returns the maximum rectangular area of trees (1s) in the grid.",
"function_declaration": "def 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 count_trees(grid):\n \"\"\"\n Returns the number of trees (1s) in the grid.\n \"\"\"\n rows = len(grid)\n cols = len(grid[0])\n tree_... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00034966",
"row_id": 34966,
"seed_ids": "[5800]"
} | 0.502668 | Code_Contests_34966 | I | [
"count_trees",
"max_rect_area",
"max_histogram_area"
] | 3 | [
[
"max_rect_area",
"max_histogram_area"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 8f9e99b652816bece55d72d2fd0ce1dbae1e5c5c | 1ed3ce98666a8cd926c362f29fa7102b415b6ac8 | |||
v1.0 | instruct | Code_Contests | Code_Contests_35005_I | In an ancient kingdom, there was an enchanted garden with a unique irrigation system. The garden is represented as a grid of size MxN (1 ≤ M, N ≤ 100). Each cell in the grid can either be fertile (represented by 'F') or barren (represented by 'B').
The caretaker of the garden wants to ensure that every fertile cell re... | from collections import deque
def min_steps_to_water_all_fertile_cells(grid, M, N):
directions = [(-1, 0), (1, 0), (0, -1), (0, 1)]
queue = deque()
visited = [[False] * N for _ in range(M)]
fertile_count = 0
for i in range(M):
for j in range(N):
if grid[i][j] == 'S... | def test_min_steps_to_water_all_fertile_cells():
input_string = "3 3\nSFF\nFBF\nFFF\n2 2\nSF\nFX\n1 1\nS\n0 0\n"
expected_output = [4, 1, 0]
assert parse_input(input_string) == expected_output
def test_blocked_cells():
input_string = "3 3\nSFF\nXBX\nFFF\n0 0\n"
expected_output = [-1]
assert par... | [
{
"docstring": null,
"function_declaration": "def min_steps_to_water_all_fertile_cells(grid, M, N):",
"function_name": "min_steps_to_water_all_fertile_cells",
"parameter_list": "(grid, M, N)"
},
{
"docstring": null,
"function_declaration": "def process_garden(grids):",
"function_name... | [
0,
0,
0,
1
] | 1 | hard | 0.25 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from collections import deque\n\ndef min_steps_to_water_all_fertile_cells(M, N, grid):\n directions = [(-1, 0), (1, 0), (0, -1), (0, 1)]\n \n def ... | trial_gpt4o_4 | {
"original_instruction": "",
"prompt_id": "00035005",
"row_id": 35005,
"seed_ids": "[3014]"
} | 0.693366 | Code_Contests_35005 | I | [
"min_steps_to_water_all_fertile_cells",
"process_garden",
"parse_input"
] | 3 | [
[
"parse_input",
"process_garden"
],
[
"process_garden",
"min_steps_to_water_all_fertile_cells"
]
] | 2 | [
"parse_input"
] | false | [] | false | pytest | false | [] | true | e4331bccfdce83e988ef4cad072f8c9a2aadb1dd | 403c2c104339c656e634c7404439f987c0c3dec7 | |||
v1.0 | instruct | Code_Contests | Code_Contests_35021_I | You are given a grid with n rows and m columns consisting of cells with binary values (0s and 1s). You need to determine the maximum area of a rectangle containing only 1s within this grid.
Input
The first line contains two integers n and m (1 ≤ n, m ≤ 200) — the number of rows and columns of the grid.
Each of the n... | def max_rectangle_area(grid):
"""
Returns the maximum area of a rectangle containing only 1s in a given binary grid.
"""
if not grid:
return 0
n = len(grid)
m = len(grid[0])
max_area = 0
heights = [0] * m
for i in range(n):
for j in range(m):
if grid[i][... | from solution import find_max_rectangle_area
def test_case_1():
n, m = 4, 5
grid = [
"10100",
"10111",
"11111",
"10010"
]
assert find_max_rectangle_area(n, m, grid) == 6
def test_case_2():
n, m = 3, 3
grid = [
"111",
"111",
"111"
]
... | [
{
"docstring": "Returns the maximum area of a rectangle containing only 1s in a given binary grid.",
"function_declaration": "def max_rectangle_area(grid):",
"function_name": "max_rectangle_area",
"parameter_list": "(grid)"
},
{
"docstring": "Helper function to calculate the maximum rectangu... | [
1,
0,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def max_rectangle_area(grid):\n \"\"\"\n Returns the maximum area of a rectangle containing only 1s in a given binary grid.\n \"\"\"\n if not g... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00035021",
"row_id": 35021,
"seed_ids": "[1106]"
} | 0.785597 | Code_Contests_35021 | I | [
"max_rectangle_area",
"max_histogram_area",
"find_max_rectangle_area"
] | 3 | [
[
"find_max_rectangle_area",
"max_rectangle_area"
],
[
"max_rectangle_area",
"max_histogram_area"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | ed6f152684118d424bdf381dca32eeb4d0a2c1ff | 2ee0b060118a262884b90e1d435579f43bc12eea | |||
v1.0 | instruct | Code_Contests | Code_Contests_35048_I | Problem Statement:
Alice is organizing a large marathon event in her city and needs your help in determining the shortest path for runners between various checkpoints. She will provide you with a list of road segments connecting checkpoints and wants to know the shortest distance between two given checkpoints for a num... | import heapq
import sys
def dijkstra(n, adjacency_list, start):
distances = {node: float('inf') for node in range(1, n + 1)}
distances[start] = 0
priority_queue = [(0, start)]
while priority_queue:
current_distance, current_node = heapq.heappop(priority_queue)
if current_d... | def test_dijkstra():
n = 5
adjacency_list = {
1: [(2, 10), (3, 20)],
2: [(1, 10), (3, 5), (4, 10)],
3: [(1, 20), (2, 5), (4, 20)],
4: [(2, 10), (3, 20), (5, 5)],
5: [(4, 5)]
}
assert dijkstra(n, adjacency_list, 1) == {1: 0, 2: 10, 3: 15, 4: 20, 5: 25}
assert d... | [
{
"docstring": null,
"function_declaration": "def dijkstra(n, adjacency_list, start):",
"function_name": "dijkstra",
"parameter_list": "(n, adjacency_list, start)"
},
{
"docstring": null,
"function_declaration": "def process_queries(n, adjacency_list, queries):",
"function_name": "pr... | [
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, adjacency_list, start):\n distances = {node: float('inf') for node in range(1, n + 1)}\n distances[start]... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00035048",
"row_id": 35048,
"seed_ids": "[4237]"
} | 0.774266 | Code_Contests_35048 | I | [
"dijkstra",
"process_queries",
"solve_marathon_problem"
] | 3 | [
[
"process_queries",
"dijkstra"
],
[
"solve_marathon_problem",
"process_queries"
]
] | 2 | [
"process_queries"
] | false | [] | false | pytest | false | [] | true | 73c35ec7d59388a6f4f1ae87da345af7a9ea5baf | e8dc5d31f441a372edbe1414140387f27ed83564 | |||
v1.0 | instruct | Code_Contests | Code_Contests_35055_I | Jane is fascinated by prime numbers. She defines a sequence of prime numbers as follows:
- The first prime number is 2.
- Every subsequent term in the sequence is the smallest prime number greater than the previous term.
Jane started to challenge her friends to solve the following problem:
Given an integer n, find th... | def sieve_of_eratosthenes(limit):
is_prime = [True] * (limit + 1)
is_prime[0], is_prime[1] = False, False
for start in range(2, int(limit**0.5) + 1):
if is_prime[start]:
for multiples in range(start*start, limit + 1, start):
is_prime[multiples] = False
primes = []
... | def test_nth_prime_numbers():
t = 3
ns = [1, 2, 10]
expected = [2, 3, 29]
assert nth_prime_numbers(t, ns) == expected
def test_nth_prime_numbers_large():
t = 3
ns = [5000, 10000, 100000]
expected = [48611, 104729, 1299709]
assert nth_prime_numbers(t, ns) == expected
def test_nth_prime_... | [
{
"docstring": null,
"function_declaration": "def sieve_of_eratosthenes(limit):",
"function_name": "sieve_of_eratosthenes",
"parameter_list": "(limit)"
},
{
"docstring": null,
"function_declaration": "def nth_prime_numbers(t, ns):",
"function_name": "nth_prime_numbers",
"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 sieve_of_eratosthenes(limit):\n \"\"\"\n Generate all prime numbers up to the limit using the Sieve of Eratosthenes.\n \"\"\"\n sieve = [Tr... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00035055",
"row_id": 35055,
"seed_ids": "[10165]"
} | 0.628948 | Code_Contests_35055 | I | [
"sieve_of_eratosthenes",
"nth_prime_numbers"
] | 2 | [
[
"nth_prime_numbers",
"sieve_of_eratosthenes"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | 236e4538b2cd186d733c13738be5ade45aee9ff1 | 61e4caf3138e74b2e25c827bc27ff5cb8ffed668 | |||
v1.0 | instruct | Code_Contests | Code_Contests_35123_I | Carla loves trees, particularly binary trees. She comes up with an interesting problem:
Given a binary tree, each node has a value. She wants to update some nodes and sum the values in given ranges of the tree.
Any node in the tree has at most two children, commonly called the left child and the right child. Addition... | class TreeNode:
def __init__(self, value):
self.value = value
self.left = None
self.right = None
# Helper function to find the Lowest Common Ancestor (LCA)
def find_lca(root, u, v):
if root is None:
return None
if root.value == u or root.value == v:
return root
... | from solution import TreeNode, find_lca, path_sum_from_ancestor, path_sum, update_value, build_tree
def test_find_lca():
root = TreeNode(1)
root.left = TreeNode(2)
root.right = TreeNode(3)
assert find_lca(root, 2, 3).value == 1
assert find_lca(root, 2, 2).value == 2
def test_path_sum_from_ancestor... | [] | [
0,
0,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "class TreeNode:\n def __init__(self, value=0, left=None, right=None):\n self.value = value\n self.left = left\n self.right = right\... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00035123",
"row_id": 35123,
"seed_ids": "[10873]"
} | 0.625114 | Code_Contests_35123 | I | [
"find_lca",
"path_sum_from_ancestor",
"path_sum",
"update_value",
"build_tree",
"main"
] | 6 | [
[
"path_sum",
"find_lca"
],
[
"path_sum",
"path_sum_from_ancestor"
]
] | 2 | [] | false | [
"TreeNode"
] | true | pytest | true | [] | true | 3141a5be7f3cbb407e29ce004f88516c5d3be66b | 5f3e172332095547d31219d916606ca69cd373e9 | |||
v1.0 | instruct | Code_Contests | Code_Contests_35148_I | David is an avid video game player, and he just started developing his own simple 2D platformer game. He needs help implementing a critical feature: detecting collisions between a player and various obstacles. The game is set on a grid where both the player and obstacles are represented as rectangles aligned with the g... | def does_intersect(x1, y1, w1, h1, x2, y2, w2, h2):
"""
Checks if two rectangles intersect.
Rectangle 1: top-left is (x1, y1), width w1, height h1
Rectangle 2: top-left is (x2, y2), width w2, height h2
"""
return not (x1 + w1 <= x2 or x2 + w2 <= x1 or y1 + h1 <= y2 or y2 + h2 <= y1)
def detect_... | def test_does_intersect():
# Test cases where rectangles intersect
assert does_intersect(1, 1, 3, 3, 2, 2, 3, 3) == True
assert does_intersect(0, 0, 5, 5, 3, 3, 2, 2) == True
# Test case where rectangles don't intersect
assert does_intersect(1, 1, 3, 3, 5, 5, 2, 2) == False
assert does_inte... | [
{
"docstring": "Checks if two rectangles intersect.\nRectangle 1: top-left is (x1, y1), width w1, height h1\nRectangle 2: top-left is (x2, y2), width w2, height h2",
"function_declaration": "def does_intersect(x1, y1, w1, h1, x2, y2, w2, h2):",
"function_name": "does_intersect",
"parameter_list": "(... | [
0,
0,
0,
0,
0,
0,
0,
0,
0,
1
] | 1 | hard | 0.1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_overlapping(x1, y1, w1, h1, x2, y2, w2, h2):\n \"\"\"\n Check if two rectangles overlap.\n Returns True if overlap, otherwise False.\n \... | trial_gpt4o_9 | {
"original_instruction": "",
"prompt_id": "00035148",
"row_id": 35148,
"seed_ids": "[2883]"
} | 0.658456 | Code_Contests_35148 | I | [
"does_intersect",
"detect_collisions"
] | 2 | [
[
"detect_collisions",
"does_intersect"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | 5905850ffc49141366d7252688f07764edb66f2e | 1b6ebc2b6a29e5d4618b0d16f983adbc6849d7cc | |||
v1.0 | instruct | Code_Contests | Code_Contests_35157_I | You are given an integer array `nums` and an integer `k`. Your task is to identify whether the sub-array of length `k` exists whose sum is a prime number.
A prime number is a natural number greater than 1 that is not a product of two smaller natural numbers. For example, 2, 3, 5, and 7 are prime numbers.
Write a func... | from typing import List
def is_prime(n: int) -> bool:
"""
Helper function to determine if a number is prime.
"""
if n <= 1:
return False
if n <= 3:
return True
if n % 2 == 0 or n % 3 == 0:
return False
i = 5
while i * i <= n:
if n % i == 0 or n % (i + 2) ... | from solution import is_prime_subarray
def test_is_prime_subarray_case1():
nums = [2, 3, 4, 7, 1]
k = 3
assert is_prime_subarray(nums, k) == False
def test_is_prime_subarray_case2():
nums = [1, 2, 3, 4, 5]
k = 3
assert is_prime_subarray(nums, k) == False
def test_is_prime_subarray_case3():
... | [
{
"docstring": "Helper function to determine if a number is prime.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Function to check if there is a sub-array of length k in nums whose sum is a prime number.",
"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": "from typing import List\n\ndef is_prime(num: int) -> bool:\n \"\"\"Check if a number is prime.\"\"\"\n if num <= 1:\n return False\n if num... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00035157",
"row_id": 35157,
"seed_ids": "[7926]"
} | 0.632568 | Code_Contests_35157 | I | [
"is_prime",
"is_prime_subarray"
] | 2 | [
[
"is_prime_subarray",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 719ac13f4085cb353254ec37d4d31189ca8cb009 | 6769963015d4d36dbf4f21991a8cdcb8f2734a06 | |||
v1.0 | instruct | Code_Contests | Code_Contests_35159_I | You are tasked with designing a software system that calculates the optimal routes for a delivery company. The company has a fleet of delivery trucks, and each truck has a maximum capacity C. There are N delivery orders, each defined by a tuple (x, y, w), where (x, y) are the coordinates of the delivery location and w ... | import math
from itertools import permutations
def calculate_distance(route):
total_distance = 0
prev_x, prev_y = 0, 0 # start from the depot
for x, y in route:
total_distance += math.sqrt((x - prev_x) ** 2 + (y - prev_y) ** 2)
prev_x, prev_y = x, y
total_distance += math.sqrt(prev_x *... | def test_delivery_routes_example_1():
C = 10
N = 6
deliveries = [(2, 3, 5), (5, 5, 3), (1, 2, 2), (6, 8, 4), (7, 7, 5), (4, 3, 6)]
routes = delivery_routes(C, N, deliveries)
assert len(routes) == 3
def test_delivery_routes_example_2():
C = 15
N = 4
deliveries = [(1, 1, 5), (2, 2, 4), (3... | [
{
"docstring": null,
"function_declaration": "def calculate_distance(route):",
"function_name": "calculate_distance",
"parameter_list": "(route)"
},
{
"docstring": null,
"function_declaration": "def get_routes(capacity, deliveries):",
"function_name": "get_routes",
"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": "import math\nfrom itertools import permutations\n\ndef calculate_distance(route):\n total_distance = 0\n prev_x, prev_y = 0, 0 # start from the depo... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00035159",
"row_id": 35159,
"seed_ids": "[3004]"
} | 0.721855 | Code_Contests_35159 | I | [
"calculate_distance",
"get_routes",
"optimize_routes",
"delivery_routes"
] | 4 | [
[
"delivery_routes",
"get_routes"
],
[
"delivery_routes",
"optimize_routes"
],
[
"optimize_routes",
"calculate_distance"
]
] | 3 | [] | false | [] | false | pytest | false | [] | true | 19ce578729764ffcc98891e85126c6f19e6c7f0b | d28de7a63c9adb77a5a64280ddbaeb432947e5fd | |||
v1.0 | instruct | Code_Contests | Code_Contests_35178_I | You are given a list of integers. Your task is to rearrange the elements to form the largest possible integer. For example, given the numbers [3, 30, 34, 5, 9], the largest formed integer would be 9534330.
Write a function that takes an integer list as input and returns the largest formed integer as a string.
Input f... | from functools import cmp_to_key
def compare(x, y):
if x + y > y + x:
return -1
else:
return 1
def largest_number(nums):
# Convert integers to strings for easier comparison.
nums = list(map(str, nums))
# Sort the numbers based on the custom comparator.
nums.sort(key=cmp_to... | from solution import largest_number
def test_single_digit():
assert largest_number([3, 5, 9, 1]) == "9531"
def test_mixed_numbers():
assert largest_number([3, 30, 34, 5, 9]) == "9534330"
assert largest_number([10, 2]) == "210"
def test_same_digit_numbers():
assert largest_number([1, 11, 111, 1111]) =... | [
{
"docstring": null,
"function_declaration": "def compare(x, y):",
"function_name": "compare",
"parameter_list": "(x, y)"
},
{
"docstring": null,
"function_declaration": "def largest_number(nums):",
"function_name": "largest_number",
"parameter_list": "(nums)"
}
] | [
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 functools import cmp_to_key\n\ndef largest_number(nums):\n \"\"\"\n Given a list of non-negative integers, arrange them such that they form the ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00035178",
"row_id": 35178,
"seed_ids": "[7885]"
} | 0.640721 | Code_Contests_35178 | I | [
"compare",
"largest_number"
] | 2 | [
[
"largest_number",
"compare"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | ce04168dc97b8a8aea3fba13d184cdf374f55f0c | f32635d97fe47da871ffaa00fd9097b56a2f7b9f | |||
v1.0 | instruct | Code_Contests | Code_Contests_35185_I | You are given an undirected graph with `n` nodes, labeled from `1` to `n`, and `m` edges. Each edge has a cost associated with it. Your task is to find the minimum cost required to construct a spanning tree of the graph (i.e., a tree that includes all nodes of the graph). If it is not possible to construct such a spann... | 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]:
paren... | def test_case_1():
n = 4
m = 4
edges = [(1, 2, 1), (2, 3, 2), (3, 4, 3), (4, 1, 4)]
assert minimum_spanning_tree(n, m, edges) == 6
def test_case_2():
n = 4
m = 3
edges = [(1, 2, 1), (2, 3, 2), (3, 4, 3)]
assert minimum_spanning_tree(n, m, edges) == 6
def test_case_3():
n = 4
m ... | [
{
"docstring": null,
"function_declaration": "def find(parent, i):",
"function_name": "find",
"parameter_list": "(parent, i)"
},
{
"docstring": null,
"function_declaration": "def union(parent, rank, x, y):",
"function_name": "union",
"parameter_list": "(parent, rank, x, y)"
},
... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def min_spanning_tree(n, m, edges):\n \"\"\"\n Returns the minimum cost required to construct a spanning tree of the graph using Kruskal's algorithm.... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00035185",
"row_id": 35185,
"seed_ids": "[6126]"
} | 0.825972 | Code_Contests_35185 | 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 | false | [] | true | b9a01b4b91b8bfdd270eaf45d55487eeb14c27f5 | 5346a15f6e3868be8839f843bc2b5b82389109cf | |||
v1.0 | instruct | Code_Contests | Code_Contests_35322_I | In a far-off kingdom, there is a grand celebration held every year which spans multiple days. The celebration includes a series of events each happening on a specific day, and each event requires a certain number of participants for it to be successful. The king wants to ensure that for each day of the celebration, eve... | def minimum_idle_participants(number_of_days, events_per_day, participants_per_day):
idle_participants = 0
for day in range(number_of_days):
total_required = sum(required for event, required in events_per_day[day])
participants_available = participants_per_day[day]
idle_participants += m... | def test_example_1():
input_list = [
"2",
"3",
"1 5",
"2 6",
"3 3",
"15",
"2",
"4 4",
"5 5",
"12"
]
assert find_minimum_idle_participants(input_list) == 4
def test_example_2():
input_list = [
"1",
"2",
... | [
{
"docstring": null,
"function_declaration": "def minimum_idle_participants(number_of_days, events_per_day, participants_per_day):",
"function_name": "minimum_idle_participants",
"parameter_list": "(number_of_days, events_per_day, participants_per_day)"
},
{
"docstring": null,
"function_... | [
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 minimize_idle_participants(days):\n total_idle = 0\n \n for day in days:\n events = day['events']\n participants = day['particip... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00035322",
"row_id": 35322,
"seed_ids": "[3849]"
} | 0.695759 | Code_Contests_35322 | I | [
"minimum_idle_participants",
"parse_input",
"find_minimum_idle_participants"
] | 3 | [
[
"find_minimum_idle_participants",
"minimum_idle_participants"
],
[
"find_minimum_idle_participants",
"parse_input"
]
] | 2 | [
"parse_input"
] | false | [] | false | pytest | false | [] | true | 61f3646f511c11dafabbf3791522c301ec7d39b2 | cd9dd89bad0d7d3333644d8e98ed3bf964bd3fa4 | |||
v1.0 | instruct | Code_Contests | Code_Contests_35378_I | You are given an integer n. You need to generate a sorted list of all the unique factors of the integer n.
Constraints
* 1 \leq n \leq 10^6
Input
Input is given from Standard Input as a single integer n.
Output
Print all the unique factors of n in ascending order, separated by spaces.
Examples
Input
36
Outpu... | def get_factors(n):
"""
Returns a sorted list of all unique factors of the integer n.
"""
factors = set()
for i in range(1, int(n**0.5) + 1):
if n % i == 0:
factors.add(i)
factors.add(n // i)
return sorted(factors)
def format_factors_for_output(n):
"""
Re... | from solution import get_factors, format_factors_for_output
def test_get_factors():
assert get_factors(36) == [1, 2, 3, 4, 6, 9, 12, 18, 36]
assert get_factors(1) == [1]
assert get_factors(100) == [1, 2, 4, 5, 10, 20, 25, 50, 100]
assert get_factors(13) == [1, 13]
assert get_factors(49) == [1, 7, 4... | [
{
"docstring": "Returns a sorted list of all unique factors of the integer n.",
"function_declaration": "def get_factors(n):",
"function_name": "get_factors",
"parameter_list": "(n)"
},
{
"docstring": "Returns the factors of the integer n as a space-separated string.",
"function_declarat... | [
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 factors(n):\n \"\"\"\n Returns a sorted list of all unique factors of the integer n.\n \"\"\"\n result = set()\n for i in range(1, int(n... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00035378",
"row_id": 35378,
"seed_ids": "[394]"
} | 0.660066 | Code_Contests_35378 | I | [
"get_factors",
"format_factors_for_output"
] | 2 | [
[
"format_factors_for_output",
"get_factors"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 4fbd8fa6deb9528b1fd9eea74378c515c2adcc12 | 4399d6fc4725ee6d43937103403ed77011648c96 | |||
v1.0 | instruct | Code_Contests | Code_Contests_35386_I | Sumire has a sequence of N integers and wants to know how many of them are prime numbers.
Write a function to count how many prime numbers are in the given sequence.
Constraints
* The input sequence has N integers.
* 1 \leq N \leq 100
* Each integer in the sequence is between 1 and 1000 inclusive.
Input
Input is g... | 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 count_primes(N, sequence):... | from solution import is_prime, count_primes
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(97) == True
def test_count_primes():
assert count_primes(5, [1, 2, 3, 4, 5]) == 3
assert count_prim... | [
{
"docstring": null,
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": null,
"function_declaration": "def count_primes(N, sequence):",
"function_name": "count_primes",
"parameter_list": "(N, sequence)"
}
] | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(n):\n \"\"\"\n Helper function to check if a number is a prime.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n ... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00035386",
"row_id": 35386,
"seed_ids": "[1226]"
} | 0.764751 | Code_Contests_35386 | I | [
"is_prime",
"count_primes"
] | 2 | [
[
"count_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 8a224767e91401d671f24adb0275a68ef6a3b9a4 | cd9a371d4347f752007699fca48a825836795b8c | |||
v1.0 | instruct | Code_Contests | Code_Contests_35465_I | You are given an array of n positive integers. Your task is to process several range queries on this array. Each query asks for the sum of all the elements in a specified sub-range of the array.
To optimize the process, you should preprocess the array to efficiently answer these range sum queries.
Input
The first li... | def preprocess_array(arr):
"""
Preprocesses the array to compute cumulative sums, which helps in efficiently answering range sum queries.
"""
n = len(arr)
prefix_sum = [0] * (n + 1)
for i in range(n):
prefix_sum[i + 1] = prefix_sum[i] + arr[i]
return prefix_sum
def range_s... | def test_preprocess_array():
arr = [1, 2, 3, 4, 5]
expected_prefix_sum = [0, 1, 3, 6, 10, 15]
assert preprocess_array(arr) == expected_prefix_sum
def test_range_sum():
prefix_sum = [0, 1, 3, 6, 10, 15]
assert range_sum(prefix_sum, 1, 3) == 6
assert range_sum(prefix_sum, 2, 5) == 14
assert r... | [
{
"docstring": "Preprocesses the array to compute cumulative sums, which helps in efficiently answering range sum queries.",
"function_declaration": "def preprocess_array(arr):",
"function_name": "preprocess_array",
"parameter_list": "(arr)"
},
{
"docstring": "Returns the sum of the elements... | [
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 preprocess_array(array):\n \"\"\"\n Preprocesses the array to compute prefix sums for efficient range sum queries.\n \"\"\"\n n = len(array... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00035465",
"row_id": 35465,
"seed_ids": "[8907]"
} | 0.629302 | Code_Contests_35465 | I | [
"preprocess_array",
"range_sum",
"process_queries"
] | 3 | [
[
"process_queries",
"preprocess_array"
],
[
"process_queries",
"range_sum"
]
] | 2 | [
"process_queries"
] | false | [] | false | pytest | false | [] | true | a2077f1b66d6bb2491d156c41f8a7d71faa00efd | b46c168321a0e6b8fee6a3bb10fef7e21f00aacd | |||
v1.0 | instruct | Code_Contests | Code_Contests_35561_I | You are tasked with designing a warehouse robot system that navigates a grid to pick up and deliver packages. The grid is represented as an NxN matrix where each cell can either be empty or contain an obstacle. The robot starts at the top-left corner of the grid and needs to reach the bottom-right corner to complete it... | def num_paths(grid):
N = len(grid)
if grid[0][0] == '#' or grid[N-1][N-1] == '#':
return 0
dp = [[0] * N for _ in range(N)]
dp[0][0] = 1
for i in range(N):
for j in range(N):
if grid[i][j] == '#':
dp[i][j] = 0
else:
... | def test_num_paths_basic():
input_data = "5\n..#..\n.....\n###.#\n.#...\n...#."
assert number_of_paths(input_data) == 2
def test_num_paths_no_obstacle():
input_data = "3\n...\n...\n..."
assert number_of_paths(input_data) == 6
def test_num_paths_all_obstacles():
input_data = "3\n###\n###\n###"
... | [
{
"docstring": null,
"function_declaration": "def num_paths(grid):",
"function_name": "num_paths",
"parameter_list": "(grid)"
},
{
"docstring": null,
"function_declaration": "def number_of_paths(input_data):",
"function_name": "number_of_paths",
"parameter_list": "(input_data)"
... | [
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 find_paths(grid):\n N = len(grid)\n if grid[0][0] == '#' or grid[N-1][N-1] == '#':\n return 0\n \n dp = [[0] * N for _ in range(N)]\... | trial_gpt4o_8 | {
"original_instruction": "",
"prompt_id": "00035561",
"row_id": 35561,
"seed_ids": "[4986]"
} | 0.725937 | Code_Contests_35561 | I | [
"num_paths",
"number_of_paths"
] | 2 | [
[
"number_of_paths",
"num_paths"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | 75c6b48eba3644b750f087fee32a5fe0a83b013a | 2bce002facd43e58a9199aa2990cfaba335b54ca | |||
v1.0 | instruct | Code_Contests | Code_Contests_35584_I | In a country called Wordland, each citizen owns a unique word. The government wants to create a special code for each word such that no two words have the same code. The code for each word is constructed by concatenating the ASCII values of its characters in the same order as they appear.
For example, the code for the... | def word_to_code(word):
"""
Converts a word to its corresponding ASCII code representation.
"""
return ''.join(str(ord(char)) for char in word)
def min_number_of_groups(test_cases):
"""
For each test case, determines the minimum number of groups required
such that no two words within the s... | from solution import word_to_code, min_number_of_groups
def test_word_to_code():
assert word_to_code("abc") == "979899"
assert word_to_code("def") == "100101102"
assert word_to_code("z") == "122"
assert word_to_code("word") == "119111114100"
def test_min_number_of_groups():
test_cases = [
... | [
{
"docstring": "Converts a word to its corresponding ASCII code representation.",
"function_declaration": "def word_to_code(word):",
"function_name": "word_to_code",
"parameter_list": "(word)"
},
{
"docstring": "For each test case, determines the minimum number of groups required \nsuch that... | [
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 ascii_code(word):\n return ''.join(str(ord(c)) for c in word)\n\ndef min_groups(test_cases):\n results = []\n for words in test_cases:\n ... | trial_gpt4o_4 | {
"original_instruction": "",
"prompt_id": "00035584",
"row_id": 35584,
"seed_ids": "[10637]"
} | 0.65558 | Code_Contests_35584 | I | [
"word_to_code",
"min_number_of_groups"
] | 2 | [
[
"min_number_of_groups",
"word_to_code"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 0d855e49ade56a370053b7fdc5f74ed0b4381228 | d9e24f51814b3bec7d0a08527cc4b130c4a2db59 | |||
v1.0 | instruct | Code_Contests | Code_Contests_35647_I | Sam is learning Morse Code, which encodes letters and digits into sequences of dots (.) and dashes (-). He wants to write a function that translates a given string into Morse Code and vice versa. Your task is to help him by writing two functions: one that encodes a string into Morse Code and another that decodes a Mors... | morse_code_dict = {
'A': '.-', 'B': '-...', 'C': '-.-.', 'D': '-..', 'E': '.', 'F': '..-.',
'G': '--.', 'H': '....', 'I': '..', 'J': '.---', 'K': '-.-', 'L': '.-..',
'M': '--', 'N': '-.', 'O': '---', 'P': '.--.', 'Q': '--.-', 'R': '.-.',
'S': '...', 'T': '-', 'U': '..-', 'V': '...-', 'W': '.--', 'X': '-... | from solution import process_input, encode_morse, decode_morse
def test_encode_morse():
assert encode_morse("HELLO 123") == ".... . .-.. .-.. --- .---- ..--- ...--"
assert encode_morse("SOS") == "... --- ..."
assert encode_morse("ABC 123") == ".- -... -.-. .---- ..--- ...--"
def test_decode_morse():
... | [
{
"docstring": "Encodes a regular string into Morse Code.",
"function_declaration": "def encode_morse(text):",
"function_name": "encode_morse",
"parameter_list": "(text)"
},
{
"docstring": "Decodes a Morse Code string into a regular string.",
"function_declaration": "def decode_morse(mor... | [
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": "MORSE_CODE_DICT = {\n 'A': '.-', 'B': '-...', 'C': '-.-.', 'D': '-..', 'E': '.', 'F': '..-.', 'G': '--.', 'H': '....', \n 'I': '..', 'J': '.---', 'K'... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00035647",
"row_id": 35647,
"seed_ids": "[4301]"
} | 0.576643 | Code_Contests_35647 | I | [
"encode_morse",
"decode_morse",
"process_input"
] | 3 | [
[
"process_input",
"decode_morse"
],
[
"process_input",
"encode_morse"
]
] | 2 | [
"process_input"
] | false | [] | false | pytest | true | [] | true | ecb974f6f0e3b665fca58d7db4cc1f64c35ffd19 | ff66b79f490bced00a5fa8437c7743969e0bb0c5 | |||
v1.0 | instruct | Code_Contests | Code_Contests_35651_I | You are given a grid with N rows and M columns. Each cell in the grid contains either a '.' or a '*'. '.' represents an empty cell and '*' represents a mine. Your task is to determine how many mines are adjacent to each cell and replace each empty cell with that number. Cells containing mines should remain unchanged. A... | def count_adjacent_mines(grid, row, col):
directions = [(-1, -1), (-1, 0), (-1, 1), (0, -1), (0, 1), (1, -1), (1, 0), (1, 1)]
count = 0
for dr, dc in directions:
new_row, new_col = row + dr, col + dc
if 0 <= new_row < len(grid) and 0 <= new_col < len(grid[0]):
if grid[new_row][ne... | from solution import modify_grid
def test_example_case():
input_grid = [
".*..",
"....",
"..*.",
"...."
]
expected_output = [
"1*10",
"1221",
"01*1",
"0111"
]
output = modify_grid(4, 4, input_grid)
assert output == expected_output
... | [
{
"docstring": null,
"function_declaration": "def count_adjacent_mines(grid, row, col):",
"function_name": "count_adjacent_mines",
"parameter_list": "(grid, row, col)"
},
{
"docstring": null,
"function_declaration": "def modify_grid(N, M, grid):",
"function_name": "modify_grid",
... | [
0,
0,
0,
0,
0,
0,
0,
0,
1,
0
] | 1 | hard | 0.1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def count_mines(grid, N, M):\n \"\"\"\n Counts the number of adjacent mines for each cell in the grid and returns the modified grid.\n \n :para... | trial_gpt4o_8 | {
"original_instruction": "",
"prompt_id": "00035651",
"row_id": 35651,
"seed_ids": "[4173]"
} | 0.641544 | Code_Contests_35651 | I | [
"count_adjacent_mines",
"modify_grid"
] | 2 | [
[
"modify_grid",
"count_adjacent_mines"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 222f6c8c1d768e0db8d10bb6da14535ec8ef6fe2 | f378c259237df3a0a456f68931849eec3a301a62 | |||
v1.0 | instruct | Code_Contests | Code_Contests_35683_I | Write a program that finds and prints all the prime numbers between two given integers m and n (inclusive).
Constraints
* 0 < m ≤ n < 10^6
Input
Two integers m and n.
Output
Print all the prime numbers between m and n (inclusive) in a line, separated by a single space. If there are no prime numbers in the range, ... | def is_prime(num):
"""
Helper function to determine if a number is prime.
"""
if num < 2:
return False
for i in range(2, int(num ** 0.5) + 1):
if num % i == 0:
return False
return True
def find_primes(m, n):
"""
Finds and returns all prime numbers between m a... | from solution import is_prime, find_primes, format_primes
def test_is_prime_for_prime_numbers():
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(5) == True
assert is_prime(7) == True
assert is_prime(11) == True
def test_is_prime_for_non_prime_numbers():
assert is_prime(1)... | [
{
"docstring": "Helper function to determine if a number is prime.",
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": "Finds and returns all prime numbers between m and n (inclusive).",
"function_declaration": "def fin... | [
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 \"\"\"\n Checks if a given number is a prime number.\n \"\"\"\n if num < 2:\n return False\n if num == 2:\n ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00035683",
"row_id": 35683,
"seed_ids": "[3646]"
} | 0.651155 | Code_Contests_35683 | I | [
"is_prime",
"find_primes",
"format_primes"
] | 3 | [
[
"find_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | c0f5d14f8ecd42f112a671b09e7b7ad747e34058 | 633cdcac482de8934f8e95c419c3553e280dfcec | |||
v1.0 | instruct | Code_Contests | Code_Contests_35685_I | You are given n points in a 2D coordinate system, and an integer k. Your task is to find k points that form the smallest possible perimeter of a convex polygon.
If there are multiple sets of k points that form such a polygon, you should return any one of them.
Input
- The first line contains two integers n and k (3 ≤... | from itertools import combinations
from math import sqrt
def distance(p1, p2):
return sqrt((p1[0] - p2[0]) ** 2 + (p1[1] - p2[1]) ** 2)
def calc_perimeter(points):
n = len(points)
perimeter = 0
for i in range(n):
perimeter += distance(points[i], points[(i+1) % n])
return perimeter
def con... | from solution import smallest_perimeter_polygon
def test_case_1():
n = 5
k = 3
points = [(0, 0), (1, 0), (0, 1), (1, 1), (2, 2)]
expected = [(0, 0), (1, 0), (0, 1)]
assert sorted(smallest_perimeter_polygon(n, k, points)) == sorted(expected)
def test_case_2():
n = 6
k = 4
points = [(4, ... | [
{
"docstring": null,
"function_declaration": "def distance(p1, p2):",
"function_name": "distance",
"parameter_list": "(p1, p2)"
},
{
"docstring": null,
"function_declaration": "def calc_perimeter(points):",
"function_name": "calc_perimeter",
"parameter_list": "(points)"
},
{
... | [
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\nfrom math import sqrt\n\ndef distance(p1, p2):\n return sqrt((p1[0] - p2[0]) ** 2 + (p1[1] - p2[1]) ** 2)\n\ndef cal... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00035685",
"row_id": 35685,
"seed_ids": "[5531]"
} | 0.702471 | Code_Contests_35685 | I | [
"distance",
"calc_perimeter",
"convex_hull",
"smallest_perimeter_polygon"
] | 4 | [
[
"calc_perimeter",
"distance"
],
[
"smallest_perimeter_polygon",
"calc_perimeter"
],
[
"smallest_perimeter_polygon",
"convex_hull"
]
] | 3 | [] | false | [] | false | pytest | true | [] | true | 1a6e980688bf3e0e6e6a5b1a91bed12151ad64ee | 65da9e34609f19b015eb8e17d1b6356a48a523cc | |||
v1.0 | instruct | Code_Contests | Code_Contests_35714_I | problem
Ella is planning a hiking trip and wants to know the maximum height she can reach without running out of energy. She has a certain amount of initial energy and each step she takes either increases or decreases her energy. She can go up, down, left, or right, but she cannot revisit a step. Given the terrain and... | def max_height_reachable(M, N, Sx, Sy, E, terrain):
directions = [(-1, 0), (1, 0), (0, -1), (0, 1)]
visited = set()
max_height = 0
def dfs(x, y, energy, current_height):
nonlocal max_height
if energy < 0 or (x, y) in visited:
return
visited.add((x, y))
curren... | import pytest
from solution import parse_and_solve
def test_example_case():
input_data = """3 3
0 0
20
10 1 15 2 20 3
5 1 30 1 25 2
10 2 35 1 40 1"""
expected_output = 40
assert parse_and_solve(input_data) == expected_output
def test_case_no_energy_to_move():
input_data = """2 2
0 0
1
10 1 15 2
20 1 2... | [
{
"docstring": null,
"function_declaration": "def max_height_reachable(M, N, Sx, Sy, E, terrain):",
"function_name": "max_height_reachable",
"parameter_list": "(M, N, Sx, Sy, E, terrain)"
},
{
"docstring": null,
"function_declaration": "def parse_and_solve(input_str):",
"function_nam... | [
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_height_reachable(M, N, Sx, Sy, E, terrain):\n directions = [(-1, 0), (1, 0), (0, -1), (0, 1)]\n visited = set()\n max_height = 0\n\n de... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00035714",
"row_id": 35714,
"seed_ids": "[298]"
} | 0.69422 | Code_Contests_35714 | I | [
"max_height_reachable",
"parse_and_solve"
] | 2 | [
[
"parse_and_solve",
"max_height_reachable"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 4b0318e008a90977518088960a5472182bcc104d | 13cfc88b37c76abe52a505b90a38ca9a51a5fa20 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.