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
Codeforces
Codeforces_30999_I
You are given an undirected graph with `N` nodes and `M` edges. Each edge has a weight associated with it. The goal is to find the weight of the minimum spanning tree (MST) of the graph. If the graph is disconnected, output -1. A minimum spanning tree of a graph is a subgraph that is a tree and connects all the vertic...
def find(parent, i): # Finds the root of the set in which element i is if parent[i] == i: return i else: return find(parent, parent[i]) def union(parent, rank, x, y): # Does union of two sets of x and y using rank xroot = find(parent, x) yroot = find(parent, y) if rank[...
from solution import minimum_spanning_trees def test_single_test_case(): assert minimum_spanning_trees(1, [(4, 5, [(1, 2, 1), (1, 3, 2), (2, 3, 2), (3, 4, 3), (1, 4, 4)])]) == [6] def test_disconnected_graph(): assert minimum_spanning_trees(1, [(4, 2, [(1, 3, 3), (2, 4, 5)])]) == [-1] def test_multiple_test_...
[ { "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_codeforces-i2i_20000_1739005484_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 xroot...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00030999", "row_id": 30999, "seed_ids": "[2938, 2236, 1450]" }
0.821667
Codeforces_30999
I
[ "find", "union", "kruskal_mst", "minimum_spanning_trees" ]
4
[ [ "kruskal_mst", "find" ], [ "kruskal_mst", "union" ], [ "minimum_spanning_trees", "kruskal_mst" ], [ "union", "find" ] ]
4
[]
false
[]
false
pytest
true
[]
true
1820ab8770096eefaca83cdc46241c4526d46582
2c776583ecb6d3661c0b5ddcc3670bb66c5822a9
v1.0
instruct
Codeforces
Codeforces_31009_I
Sarah is organizing a party and wants to arrange the guests in a circular arrangement, such that certain guests have preferences on who should not be seated next to each other. Each guest is represented by a unique integer from 1 to n. Given the number of guests and their seating preferences, determine if it is possib...
from itertools import permutations def can_be_seated_next_to(seating, pref_dict): """ Returns True if in the given seating arrangement no one is seated next to someone they don't want to be seated next to. """ for i in range(len(seating)): a = seating[i] b = seating[(i + 1) % len(seatin...
from solution import arrange_party def test_example_case(): n = 5 m = 3 restrictions = [(1, 2), (2, 3), (4, 5)] result = arrange_party(n, m, restrictions) assert result != -1 assert len(result) == n assert result[0] != result[-1] # Ensure a valid seating arrangement in a circle def test_n...
[ { "docstring": "Returns True if in the given seating arrangement no one is seated next to someone they don't want to be seated next to.", "function_declaration": "def can_be_seated_next_to(seating, pref_dict):", "function_name": "can_be_seated_next_to", "parameter_list": "(seating, pref_dict)" }, ...
[ 0, 1, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "from itertools import permutations\n\ndef can_arrange(n, m, preferences):\n # Generate all permutations of guests\n for perm in permutations(range(1, n ...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00031009", "row_id": 31009, "seed_ids": "[4779, 7054, 1012]" }
0.730192
Codeforces_31009
I
[ "can_be_seated_next_to", "arrange_party" ]
2
[ [ "arrange_party", "can_be_seated_next_to" ] ]
1
[]
false
[]
false
pytest
true
[]
true
637d4fc775ad2b95f04dfa59ece2e9d9ffff777e
9211ef4b19421c571984ee76dec6d9cbed73953e
v1.0
instruct
Codeforces
Codeforces_31014_I
Alex is a software developer at a company that has several projects. Each project consists of different tasks, which have certain dependencies. Alex needs to complete all tasks of a project in such a way that no task is started before all its dependencies are completed. You are given multiple projects, and for each p...
from collections import defaultdict, deque def find_task_order(projects): def get_task_order(tasks, dependencies): incoming_edges = {i: 0 for i in range(1, tasks+1)} graph = defaultdict(list) for task, deps in dependencies.items(): for dep in deps: graph[dep].ap...
from solution import solve def test_example_1(): input_str = "2\n3\n1: \n2: 1\n3: 2\n4\n1: \n2: \n3: 1 2\n4: 2 3\n" output = solve(input_str) assert output == ["1 2 3", "1 2 3 4"] or output == ["1 2 3", "2 1 3 4"] def test_example_2(): input_str = "1\n4\n1: 2\n2: 3\n3: 4\n4: 1\n" output = solve(in...
[ { "docstring": null, "function_declaration": "def find_task_order(projects):", "function_name": "find_task_order", "parameter_list": "(projects)" }, { "docstring": null, "function_declaration": "def parse_input(input_str):", "function_name": "parse_input", "parameter_list": "(inp...
[ 1, 0, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "from collections import defaultdict, deque\n\ndef find_task_order(projects):\n def get_task_order(tasks, dependencies):\n incoming_edges = {i: 0 for...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00031014", "row_id": 31014, "seed_ids": "[5832, 3946, 1304]" }
0.577201
Codeforces_31014
I
[ "find_task_order", "parse_input", "solve" ]
3
[ [ "solve", "find_task_order" ], [ "solve", "parse_input" ] ]
2
[ "parse_input" ]
false
[]
false
pytest
true
[]
true
db65a26787c85b0af5e25bf1bfd100f9ee972916
bb2b1ee531555366233fd9561aa372d94f6de0d1
v1.0
instruct
Codeforces
Codeforces_31096_I
You are given a tree (connected acyclic undirected graph) with n vertices labeled 1 through n. Each vertex has a positive integer value associated with it. Your task is to perform q queries of the following type: find the maximum value among all vertices within a given distance d from a specified vertex v. The first l...
from collections import deque def find_max_within_distance(n, values, edges, queries): # Build the adjacency list for the graph graph = {i: [] for i in range(1, n + 1)} for a, b in edges: graph[a].append(b) graph[b].append(a) def bfs_max_value(start, distance): visited = {s...
def test_example(): n = 5 values = [5, 3, 6, 2, 9] edges = [(1, 2), (1, 3), (3, 4), (3, 5)] q = 3 queries = [(1, 2), (4, 1), (5, 0)] expected_result = [9, 6, 9] assert solve(n, values, edges, q, queries) == expected_result def test_single_node(): n = 1 values = [10] edges =...
[ { "docstring": null, "function_declaration": "def find_max_within_distance(n, values, edges, queries):", "function_name": "find_max_within_distance", "parameter_list": "(n, values, edges, queries)" }, { "docstring": null, "function_declaration": "def solve(n, values, edges, q, queries):"...
[ 1, 1, 0 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "from collections import deque, defaultdict\n\ndef bfs_max_value(tree, values, start, distance):\n n = len(values)\n visited = [False] * (n + 1)\n que...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00031096", "row_id": 31096, "seed_ids": "[7959, 1946, 5901]" }
0.797805
Codeforces_31096
I
[ "find_max_within_distance", "solve" ]
2
[ [ "solve", "find_max_within_distance" ] ]
1
[]
false
[]
false
pytest
false
[]
true
5dd890e7ac49c11615ffa6934b76f1a5b4a74007
8018b30a6b50f1844dd9420dc5c7173f50565791
v1.0
instruct
Codeforces
Codeforces_31141_I
Miko enjoys exploring and photographing beautiful gardens. He often travels around to different gardens in the city, and he likes to take the shortest possible route to visit a specific set of gardens. Given the set of gardens he wants to visit and the distances between some pairs of gardens, Miko wants to know the sho...
def tsp(gardens): from itertools import permutations n = len(gardens) min_path_len = float('inf') # Generate all permutations of garden indices excluding the starting garden for perm in permutations(range(1, n)): # Initialize current path length and starting position current_pa...
from solution import min_route_length def test_example_case(): n = 4 distance_matrix = [ [0, 10, 15, 20], [10, 0, 35, 25], [15, 35, 0, 30], [20, 25, 30, 0] ] assert min_route_length(n, distance_matrix) == 80 def test_case_two_gardens(): n = 2 distance_matrix = [...
[ { "docstring": null, "function_declaration": "def tsp(gardens):", "function_name": "tsp", "parameter_list": "(gardens)" }, { "docstring": null, "function_declaration": "def min_route_length(n, distance_matrix):", "function_name": "min_route_length", "parameter_list": "(n, distanc...
[ 0, 0, 1 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "from itertools import permutations\n\ndef tsp_distance(n, distances):\n \"\"\"\n Solves the Traveling Salesman Problem using brute-force approach for a ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00031141", "row_id": 31141, "seed_ids": "[7032, 1958, 2305]" }
0.6895
Codeforces_31141
I
[ "tsp", "min_route_length" ]
2
[ [ "min_route_length", "tsp" ] ]
1
[]
false
[]
false
pytest
true
[]
true
e7887513f63d11e100364583db7f0fa9073cffaa
a19d02f0fe2a82a8b9ecebe08ef03438640e6880
v1.0
instruct
Codeforces
Codeforces_31156_I
You are given a weighted tree with `n` vertices. The tree is rooted at vertex 1, and each vertex i has a weight `wi`. The weight of a subtree rooted at vertex `u` is the sum of weights of all vertices in that subtree. Your task is to handle `q` queries. In each query, you are given a vertex `u`, and you need to find t...
from collections import defaultdict def calculate_subtree_weights(n, weights, edges): tree = defaultdict(list) for u, v in edges: tree[u].append(v) tree[v].append(u) subtree_weights = [0] * (n + 1) visited = [False] * (n + 1) def dfs(node): visited[node] = True ...
from solution import solve def test_subtree_weights_case_1(): n = 5 q = 3 weights = [1, 2, 3, 4, 5] edges = [(1, 2), (1, 3), (3, 4), (3, 5)] queries = [1, 3, 4] expected = [15, 12, 4] assert solve(n, q, weights, edges, queries) == expected def test_subtree_weights_case_2(): n = 3 q...
[ { "docstring": null, "function_declaration": "def calculate_subtree_weights(n, weights, edges):", "function_name": "calculate_subtree_weights", "parameter_list": "(n, weights, edges)" }, { "docstring": null, "function_declaration": "def subtree_query(subtree_weights, queries):", "fun...
[ 0, 0, 1 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def calculate_subtree_weights(n, weights, edges, queries):\n from collections import defaultdict, deque\n \n tree = defaultdict(list)\n subtree_we...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00031156", "row_id": 31156, "seed_ids": "[5616, 3919, 3642]" }
0.68398
Codeforces_31156
I
[ "calculate_subtree_weights", "subtree_query", "solve" ]
3
[ [ "solve", "calculate_subtree_weights" ], [ "solve", "subtree_query" ] ]
2
[]
false
[]
false
pytest
true
[]
true
5c33fb6917e11f3ea715012c39d875890f9c2563
0b58dd46f52c140d4a6e2193a95385c45f4f74a0
v1.0
instruct
Codeforces
Codeforces_31192_I
Alice and Bob are playing a card game with a deck containing `n` cards numbered from 1 to n. The game proceeds in turns, with Alice starting first. In each turn, a player can either: 1. Draw a card from the top of the deck. 2. Skip the turn. Both players can see all the cards in the deck and know which cards their op...
def find_gcd(x, y): """ Returns the greatest common divisor (GCD) of two numbers. """ while y: x, y = y, x % y return x def determine_winner(n, cards): """ Determines the winner of the card game. Alice wins if she can immediately draw a card such that there is no subset in t...
def test_case_1(): assert determine_winner(6, [2, 3, 5, 7, 11, 13]) == "Alice" def test_case_2(): assert determine_winner(1, [1]) == "Alice" def test_case_3(): assert determine_winner(3, [6, 10, 15]) == "Alice" def test_case_4(): assert determine_winner(4, [2, 4, 8, 16]) == "Alice" def test_case_5()...
[ { "docstring": "Returns the greatest common divisor (GCD) of two numbers.", "function_declaration": "def find_gcd(x, y):", "function_name": "find_gcd", "parameter_list": "(x, y)" }, { "docstring": "Determines the winner of the card game.\nAlice wins if she can immediately draw a card such th...
[ 0, 1 ]
1
medium
0.5
{ "trial_gpt4o_0": null, "trial_gpt4o_1": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared1_results_combined.jsonl", "solution_code": "import math\nfrom functools import reduce\nfrom typing import List\n\ndef gcd(a: int, b: int) -> int:\n while b:\n a, b = b...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00031192", "row_id": 31192, "seed_ids": "[2856, 6740, 1885]" }
0.727782
Codeforces_31192
I
[ "find_gcd", "determine_winner", "main" ]
3
[ [ "determine_winner", "find_gcd" ] ]
1
[]
false
[]
false
pytest
false
[]
true
c48ff7cc9d1c4df1d01a155803a029db101a1ba9
c9744f77ca5b902556b6f080f72ba6f1305ca5ea
v1.0
instruct
Codeforces
Codeforces_31204_I
In a certain country, there are n cities connected by m bidirectional roads. Each road has a positive length given in kilometers. The cities want to establish a network of highways such that every city is accessible from any other city directly or indirectly through these highways. Additionally, the total length of the...
class UnionFind: """Union-Find data structure (Disjoint Set Union) with path compression and union by rank.""" def __init__(self, n): self.parent = list(range(n)) self.rank = [0] * n def find(self, u): if self.parent[u] != u: self.parent[u] = self.find(self.parent[u]) #...
from solution import find_min_highway_length_and_roads def test_example(): n, m = 4, 5 roads = [ (1, 2, 1), (2, 3, 2), (1, 3, 2), (1, 4, 3), (3, 4, 4) ] expected_length = 6 expected_roads = [(1, 2), (2, 3), (1, 4)] total_length, mst_edges = find_min_high...
[]
[ 1, 0 ]
1
medium
0.5
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "class UnionFind:\n \"\"\"Union-Find data structure (Disjoint Set Union) with path compression and union by rank.\"\"\"\n def __init__(self, n):\n ...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00031204", "row_id": 31204, "seed_ids": "[5529, 4134, 2498]" }
0.755773
Codeforces_31204
I
[ "kruskal", "find_min_highway_length_and_roads" ]
2
[ [ "find_min_highway_length_and_roads", "kruskal" ] ]
1
[]
false
[ "UnionFind" ]
true
pytest
true
[]
true
49ba74ee597a10746cea23f8d1ebe1985806f179
86192d34b7ec5f6bd587ec07973bae1b810edfae
v1.0
instruct
Codeforces
Codeforces_31209_I
Masha loves combinatorial problems. She recently came across the concept of Catalan numbers, which are a sequence of natural numbers that appear in various counting problems. The nth Catalan number C(n) can be expressed directly in terms of binomial coefficients: C(n) = (1 / (n + 1)) * (2n choose n) Given an integer ...
MOD = 10**9 + 7 def binomial_coefficient(n, k): if k > n - k: k = n - k res = 1 for i in range(k): res = res * (n - i) // (i + 1) return res def catalan_number(n): return binomial_coefficient(2 * n, n) // (n + 1) def sum_of_catalan_numbers(n): catalan_sum = 0 for i in rang...
from solution import binomial_coefficient, catalan_number, sum_of_catalan_numbers def test_binomial_coefficient(): assert binomial_coefficient(5, 2) == 10 assert binomial_coefficient(10, 5) == 252 assert binomial_coefficient(4, 2) == 6 def test_catalan_number(): assert catalan_number(0) == 1 asser...
[ { "docstring": null, "function_declaration": "def binomial_coefficient(n, k):", "function_name": "binomial_coefficient", "parameter_list": "(n, k)" }, { "docstring": null, "function_declaration": "def catalan_number(n):", "function_name": "catalan_number", "parameter_list": "(n)"...
[ 0, 0, 0, 0, 0, 0, 1, 0, 0 ]
1
hard
0.111
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "MOD = 10**9 + 7\n\ndef catalan_number(n):\n if n == 0 or n == 1:\n return 1\n cat = [0] * (n + 1)\n cat[0], cat[1] = 1, 1\n \n for i in ...
trial_gpt4o_7
{ "original_instruction": "", "prompt_id": "00031209", "row_id": 31209, "seed_ids": "[4501, 1794, 444]" }
0.512579
Codeforces_31209
I
[ "binomial_coefficient", "catalan_number", "sum_of_catalan_numbers" ]
3
[ [ "catalan_number", "binomial_coefficient" ], [ "sum_of_catalan_numbers", "catalan_number" ] ]
2
[]
false
[]
false
pytest
true
[]
true
7f0d56f9018802280c5e1ae259b8a379910924f6
21359f5feed816c01d86140cac72e406b81b261b
v1.0
instruct
Codeforces
Codeforces_31236_I
You are given a string of characters that can contain letters, digits, and special symbols. A valid password is defined as a string that meets the following criteria: 1. The length of the string is at least 8 characters. 2. It contains at least one uppercase letter. 3. It contains at least one lowercase letter. 4. It c...
def is_valid_password(password): """ Validates if the given password meets the required criteria. 1. The length of the string is at least 8 characters. 2. It contains at least one uppercase letter. 3. It contains at least one lowercase letter. 4. It contains at least one digit. 5. It contain...
import pytest from solution import is_valid_password, validate_passwords def test_is_valid_password(): assert is_valid_password("Hello#123") is True assert is_valid_password("pass1234") is False assert is_valid_password("Secure@Pass1") is True assert is_valid_password("Password!2") is True assert i...
[ { "docstring": "Validates if the given password meets the required criteria.\n1. The length of the string is at least 8 characters.\n2. It contains at least one uppercase letter.\n3. It contains at least one lowercase letter.\n4. It contains at least one digit.\n5. It contains at least one special symbol from t...
[ 0, 0, 0, 1, 1 ]
2
medium
0.4
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_valid_password(password):\n if len(password) < 8:\n return \"NO\"\n \n has_upper = has_lower = has_digit = has_special = False\n spe...
trial_gpt4o_4
{ "original_instruction": "", "prompt_id": "00031236", "row_id": 31236, "seed_ids": "[2199, 4034, 2349]" }
0.669347
Codeforces_31236
I
[ "is_valid_password", "validate_passwords" ]
2
[ [ "validate_passwords", "is_valid_password" ] ]
1
[]
false
[]
false
pytest
true
[]
true
3b17bd3095c3c9ab9a2380be214262c61cb66015
261b339ab121cf8084eadeb17aef0359bebe0c1b
v1.0
instruct
Codeforces
Codeforces_31237_I
Raymond is involved in a construction project where he needs to build an optimal road network connecting various cities. The cities are represented as points in a 2D plane, and Raymond wants to minimize the total length of the roads while ensuring that every city is connected to the network. To do this, Raymond plans ...
import heapq import math def compute_euclidean_distance(x1, y1, x2, y2): return math.sqrt((x1 - x2)**2 + (y1 - y2)**2) def minimum_spanning_tree(n, coordinates): if n == 2: return compute_euclidean_distance(coordinates[0][0], coordinates[0][1], coordinates[1][...
from solution import compute_euclidean_distance, minimum_spanning_tree def test_euclidean_distance(): assert math.isclose(compute_euclidean_distance(0, 0, 1, 1), 1.414213, rel_tol=1e-6) assert math.isclose(compute_euclidean_distance(0, 0, 0, 1), 1.0, rel_tol=1e-6) assert math.isclose(compute_euclidean_dist...
[ { "docstring": null, "function_declaration": "def compute_euclidean_distance(x1, y1, x2, y2):", "function_name": "compute_euclidean_distance", "parameter_list": "(x1, y1, x2, y2)" }, { "docstring": null, "function_declaration": "def minimum_spanning_tree(n, coordinates):", "function_...
[ 0, 0, 0, 0, 0, 0, 0, 1, 0 ]
1
hard
0.111
{ "trial_gpt4o_0": null, "trial_gpt4o_1": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared1_results_combined.jsonl", "solution_code": "import math\nimport heapq\n\ndef compute_mst(n, cities):\n def euclidean_distance(city1, city2):\n return math.sqrt((city1[...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00031237", "row_id": 31237, "seed_ids": "[7408, 2663, 3314]" }
0.67793
Codeforces_31237
I
[ "compute_euclidean_distance", "minimum_spanning_tree", "main" ]
3
[ [ "minimum_spanning_tree", "compute_euclidean_distance" ] ]
1
[]
false
[]
false
pytest
true
[]
true
7eb9ef4d449efc4c6d2bec7f6de188301f497476
c0c8570012edc7e38decccd8e976c70f4da54886
v1.0
instruct
Codeforces
Codeforces_31246_I
Programming contests often require participants to flex their algorithm and logic muscles in solving unique and challenging problems. Below is a new problem that aligns with the given examples in terms of style, complexity, and scope: A popular transportation company is planning a new bus route for their city that min...
# Implementation of Kruskal's Algorithm to find Minimum Spanning Tree (MST) def find_parent(parent, i): if parent[i] == i: return i else: return find_parent(parent, parent[i]) def union(parent, rank, x, y): root_x = find_parent(parent, x) root_y = find_parent(parent, y) if rank...
import pytest from solution import minimum_travel_time def test_minimum_travel_time_sample1(): assert minimum_travel_time(4, 3, [[1, 2, 1], [2, 3, 1], [3, 4, 1]]) == 3 def test_minimum_travel_time_sample2(): assert minimum_travel_time(4, 2, [[1, 2, 1], [2, 3, 1]]) == "Impossible" def test_minimum_travel_time...
[ { "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...
[ 0, 1, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def minimum_total_travel_time(n, m, roads):\n \"\"\"\n Determines the minimum total travel time required to connect all bus stops using Kruskal's algori...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00031246", "row_id": 31246, "seed_ids": "[3434, 5754, 1224]" }
0.674393
Codeforces_31246
I
[ "find_parent", "union", "minimum_travel_time" ]
3
[ [ "minimum_travel_time", "find_parent" ], [ "minimum_travel_time", "union" ], [ "union", "find_parent" ] ]
3
[]
false
[]
false
pytest
true
[]
true
9364ba9852f8c6a34cca0455e2d8c4259a4c8b98
a068a2f070a5c051448e3377c9990adc5ca137a2
v1.0
instruct
Codeforces
Codeforces_31284_I
A farmer has a rectangular farm divided into $$$n \times m$$$ grid cells. Some of these cells have trees planted in them, while others are empty. The farmer wants to build a rectangular barn on his farm such that none of the cells where the barn is built have trees. The task is to determine the area of the largest pos...
def max_histogram_area(histogram): stack = [] max_area = 0 index = 0 while index < len(histogram): if not stack or histogram[stack[-1]] <= histogram[index]: stack.append(index) index += 1 else: top_of_stack = stack.pop() current_area = (hi...
def test_largest_rectangle_possible_barn(): assert largest_rectangle_possible_barn(4, 5, [ ".....", ".T..T", ".....", "...T." ]) == 6 assert largest_rectangle_possible_barn(3, 3, [ "...", "T.T", "..." ]) == 3 assert largest_rectangle_possible...
[ { "docstring": null, "function_declaration": "def max_histogram_area(histogram):", "function_name": "max_histogram_area", "parameter_list": "(histogram)" }, { "docstring": null, "function_declaration": "def largest_rectangle_area(grid):", "function_name": "largest_rectangle_area", ...
[ 0, 0, 1 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def largest_rectangle_in_farm(n, m, farm):\n def max_histogram_area(histogram):\n stack = []\n max_area = 0\n index = 0\n\n whi...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00031284", "row_id": 31284, "seed_ids": "[3814, 504, 5070]" }
0.593426
Codeforces_31284
I
[ "max_histogram_area", "largest_rectangle_area", "largest_rectangle_possible_barn" ]
3
[ [ "largest_rectangle_area", "max_histogram_area" ], [ "largest_rectangle_possible_barn", "largest_rectangle_area" ] ]
2
[]
false
[]
false
pytest
false
[]
true
c40707424b36f7ef2603b7b85bf7f6f4d3aa4e08
bcedcd2aeec61a69621022a91d2989642e709c62
v1.0
instruct
Codeforces
Codeforces_31302_I
A company wants to plan an office layout based on employees' preferences. Each employee can sit in a specific row and a column they prefer in an office grid. There are m rows and n columns in the office. If an employee cannot sit at their preferred location because it's already occupied, they will sit at the nearest av...
def find_nearest_seat(m, n, preferences): # A matrix to track occupied seats occupied = [[False for _ in range(n)] for _ in range(m)] result = [] def manhattan_distance(r1, c1, r2, c2): return abs(r1 - r2) + abs(c1 - c2) for r, c in preferences: r -= 1 # Converting to 0-based inde...
from solution import office_layout def test_office_layout_example_case(): assert office_layout(3, 3, 4, [(1, 1), (2, 2), (1, 1), (3, 3)]) == [(1, 1), (2, 2), (1, 2), (3, 3)] def test_office_layout_single_employee(): assert office_layout(1, 1, 1, [(1, 1)]) == [(1, 1)] assert office_layout(2, 2, 1, [(1, 2)]...
[ { "docstring": null, "function_declaration": "def find_nearest_seat(m, n, preferences):", "function_name": "find_nearest_seat", "parameter_list": "(m, n, preferences)" }, { "docstring": null, "function_declaration": "def office_layout(m, n, q, preferences):", "function_name": "office...
[ 0, 0, 0, 0, 0, 1, 0, 0, 0 ]
1
hard
0.111
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def plan_office_layout(m, n, q, preferences):\n office = [[False] * n for _ in range(m)]\n \n def find_nearest_available_seat(r, c):\n queue =...
trial_gpt4o_6
{ "original_instruction": "", "prompt_id": "00031302", "row_id": 31302, "seed_ids": "[4098, 3946, 5222]" }
0.67559
Codeforces_31302
I
[ "find_nearest_seat", "office_layout" ]
2
[ [ "office_layout", "find_nearest_seat" ] ]
1
[]
false
[]
false
pytest
true
[]
true
e2849d895761a3901b3b5b3121d2de8878a1d215
f024b09078501f7e35db761cbd01ba8021b6b1f0
v1.0
instruct
Codeforces
Codeforces_31321_I
Alice has recently built a network of computers in her office. The network consists of `n` computers connected by `m` cables. Each cable has a certain length associated with it. Alice wants to ensure that a message can be sent from any computer to any other computer in the network. Due to budget constraints, she needs ...
def find(parent, i): if parent[i] == i: return i else: return find(parent, parent[i]) def union(parent, rank, x, y): root_x = find(parent, x) root_y = find(parent, y) if rank[root_x] < rank[root_y]: parent[root_x] = root_y elif rank[root_x] > rank[root_y]: ...
from solution import min_total_length_of_cables def test_example_case(): n = 4 m = 4 cables = [ (1, 2, 3), (2, 3, 1), (3, 4, 4), (4, 1, 2) ] assert min_total_length_of_cables(n, m, cables) == 6 def test_disconnected_case(): n = 4 m = 1 cables = [ ...
[ { "docstring": null, "function_declaration": "def find(parent, i):", "function_name": "find", "parameter_list": "(parent, i)" }, { "docstring": null, "function_declaration": "def union(parent, rank, x, y):", "function_name": "union", "parameter_list": "(parent, rank, x, y)" }, ...
[ 0, 1, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "class DisjointSetUnion:\n def __init__(self, n):\n self.parent = list(range(n))\n self.rank = [1] * n\n\n def find(self, u):\n if s...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00031321", "row_id": 31321, "seed_ids": "[3399, 5696, 7233]" }
0.685364
Codeforces_31321
I
[ "find", "union", "kruskal", "min_total_length_of_cables" ]
4
[ [ "kruskal", "find" ], [ "kruskal", "union" ], [ "min_total_length_of_cables", "kruskal" ], [ "union", "find" ] ]
4
[]
false
[]
false
pytest
true
[]
true
b57b46707f4124a892a30051cc9b5474c4a3cb1f
75d6d5b3a8f5873936763ae3b59399dc2e5457ee
v1.0
instruct
Codeforces
Codeforces_31324_I
Masha and Strong Passwords Masha wants to help teachers at her school create strong passwords for their accounts. She knows that for a password to be considered strong, it must meet the following criteria: 1. It must be at least 8 characters long. 2. It must contain at least one uppercase letter. 3. It must contain at...
def is_strong_password(password): special_characters = {'!', '@', '#', '$', '%', '^', '&', '*', '(', ')', '-', '+'} has_upper = any(c.isupper() for c in password) has_lower = any(c.islower() for c in password) has_digit = any(c.isdigit() for c in password) has_special = any(c in special_charact...
from solution import is_strong_password, check_passwords def test_is_strong_password(): assert is_strong_password("Pass1!") == "NO 2" def test_is_strong_password_all_missing(): assert is_strong_password("passwrd") == "NO 3" assert is_strong_password("PASSWORD") == "NO 3" assert is_strong_password("123...
[ { "docstring": null, "function_declaration": "def is_strong_password(password):", "function_name": "is_strong_password", "parameter_list": "(password)" }, { "docstring": null, "function_declaration": "def check_passwords(n, passwords):", "function_name": "check_passwords", "param...
[ 0, 0, 0, 0, 0, 0, 0, 0, 1 ]
1
hard
0.111
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "import string\n\ndef is_strong_password(password):\n special_characters = {'!', '@', '#', '$', '%', '^', '&', '*', '(', ')', '-', '+'}\n \n has_upper...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00031324", "row_id": 31324, "seed_ids": "[8042, 6731, 6887]" }
0.614219
Codeforces_31324
I
[ "is_strong_password", "check_passwords" ]
2
[ [ "check_passwords", "is_strong_password" ] ]
1
[]
false
[]
false
pytest
true
[]
true
e7c8cab47fabc5f19c1ecae2996ecced0458d9ac
60ffd8e92046b33e716ded55076e9282b1fa0302
v1.0
instruct
Codeforces
Codeforces_31332_I
Vova loves prime numbers and prime factorization. One day, he was playing with arrays and prime numbers and came up with an interesting problem. Vova is given a sequence of n integers, and he wants to create a new sequence by replacing each integer with its largest prime factor. Your task is to help him with this. Th...
def max_prime_factor(n): """ Returns the largest prime factor of a given number n. """ def is_prime(x): if x <= 1: return False if x <= 3: return True if x % 2 == 0 or x % 3 == 0: return False i = 5 while i * i <= x: ...
from solution import largest_prime_factors def test_single_element(): assert largest_prime_factors([10]) == [5] def test_multiple_elements(): assert largest_prime_factors([10, 15, 21, 33, 35, 49]) == [5, 5, 7, 11, 7, 7] def test_prime_numbers(): assert largest_prime_factors([2, 3, 5, 7, 11]) == [2, 3, 5,...
[ { "docstring": "Returns the largest prime factor of a given number n.", "function_declaration": "def max_prime_factor(n):", "function_name": "max_prime_factor", "parameter_list": "(n)" }, { "docstring": "Given a sequence of integers, replace each integer with its largest prime factor.", ...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def max_prime_factor(n):\n \"\"\"\n Returns the largest prime factor of a given number n.\n \"\"\"\n def is_prime(x):\n if x <= 1:\n ...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00031332", "row_id": 31332, "seed_ids": "[223, 6366, 1337]" }
0.58194
Codeforces_31332
I
[ "max_prime_factor", "largest_prime_factors" ]
2
[ [ "largest_prime_factors", "max_prime_factor" ] ]
1
[]
false
[]
false
pytest
true
[]
true
dd27ce268e818a39c5e74f59033402bca60954bf
dd1f8490b11671458ed0e2cd0bc2d369cabf9ffc
v1.0
instruct
Codeforces
Codeforces_31405_I
Farmer John owns a piece of land that can be represented as an n x m grid. Each cell in the grid is either fertile or infertile. Farmer John wants to plant a single rectangular crop field on the land, and he wants the field to be as large as possible while only containing fertile cells. You are given the grid in the f...
def max_histogram_area(heights): stack = [] max_area = 0 index = 0 while index < len(heights): if not stack or heights[stack[-1]] <= heights[index]: stack.append(index) index += 1 else: top_of_stack = stack.pop() area = (heights[top_of_stac...
def test_single_row(): matrix = [[1, 0, 1, 1, 1]] assert max_rectangle_area(matrix) == 3 def test_single_column(): matrix = [[1], [1], [0], [1]] assert max_rectangle_area(matrix) == 2 def test_mixed_grid(): matrix = [ [1, 0, 1, 0, 0], [1, 0, 1, 1, 1], [1, 1, 1, 1, 1], ...
[ { "docstring": null, "function_declaration": "def max_histogram_area(heights):", "function_name": "max_histogram_area", "parameter_list": "(heights)" }, { "docstring": null, "function_declaration": "def max_rectangle_area(matrix):", "function_name": "max_rectangle_area", "paramet...
[ 1, 1, 0 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_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 max_area = 0\n heights = [0] * m\n ...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00031405", "row_id": 31405, "seed_ids": "[1070, 7018, 8011]" }
0.635282
Codeforces_31405
I
[ "max_histogram_area", "max_rectangle_area" ]
2
[ [ "max_rectangle_area", "max_histogram_area" ] ]
1
[]
false
[]
false
pytest
false
[]
true
3e36ee00ec7dac28e1749c862b921639e61022fb
b9054d04f0befe2181393dcedaaf70d5fb53d26f
v1.0
instruct
Codeforces
Codeforces_31426_I
John is an avid cyclist and often records his routes using GPS. Unfortunately, sometimes the GPS data gets corrupted and his recorded routes contain errors. Each route is described as a series of points on a 2D grid, where each point is represented by its x and y coordinates. To find the correct route, John uses a spec...
def min_modifications(n, original_route, m, must_visit): # Building a dynamic programming table where dp[i][j] represents the minimum cost # to make the first i elements of the original route match the first j elements # of the must visit list. dp = [[0] * (m + 1) for _ in range(n + 1)] # If the m...
import pytest from solution import correct_route def test_example_case(): input_data = "6\n1 2\n3 4\n5 6\n3 4\n7 8\n9 10\n4\n3 4\n6 8\n7 8\n9 10" assert correct_route(input_data) == 3 def test_no_modifications_needed(): input_data = "4\n1 2\n3 4\n5 6\n7 8\n4\n1 2\n3 4\n5 6\n7 8" assert correct_route(i...
[ { "docstring": null, "function_declaration": "def min_modifications(n, original_route, m, must_visit):", "function_name": "min_modifications", "parameter_list": "(n, original_route, m, must_visit)" }, { "docstring": null, "function_declaration": "def correct_route(input_data):", "fun...
[ 0, 0, 0, 0, 0, 1, 1, 0, 0 ]
2
hard
0.222
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def min_modifications_to_correct_route(original_route, must_visit_points):\n n = len(original_route)\n m = len(must_visit_points)\n\n # dp[i][j] will...
trial_gpt4o_7
{ "original_instruction": "", "prompt_id": "00031426", "row_id": 31426, "seed_ids": "[1748, 195, 7039]" }
0.681719
Codeforces_31426
I
[ "min_modifications", "correct_route" ]
2
[ [ "correct_route", "min_modifications" ] ]
1
[]
false
[]
false
pytest
true
[]
true
291c358cdeba25729b688cb03865ebe0cde94276
b3f88461a1c0ab393202824081e6e8d22d12247a
v1.0
instruct
Codeforces
Codeforces_31518_I
You are given a sequence of integers a1, a2, ..., an. We define an operation as follows: for a given odd-length subsequence of length k, replace the subsequence with its median. The median of a subsequence is the element that would be in the middle if the subsequence were sorted. If multiple elements qualify as the med...
def perform_operation(sequence): """ Repeatedly performs the described operation until the sequence becomes a single integer. """ while len(sequence) > 1: # Find the median of the entire sequence sorted_sequence = sorted(sequence) median_index = len(sorted_sequence) // 2 ...
from solution import final_integer def test_example_case(): assert final_integer(5, [3, 1, 2, 4, 6]) == 3 def test_single_element(): assert final_integer(1, [5]) == 5 def test_two_median_choices(): assert final_integer(7, [3, 1, 2, 4, 6, 7, 8]) == 4 def test_negative_numbers(): assert final_integer(...
[ { "docstring": "Repeatedly performs the described operation until the sequence becomes a single integer.", "function_declaration": "def perform_operation(sequence):", "function_name": "perform_operation", "parameter_list": "(sequence)" }, { "docstring": null, "function_declaration": "def...
[ 0, 0, 0, 0, 0, 0, 1, 1, 0, 0 ]
2
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def find_final_integer(n, sequence):\n from heapq import heappush, heappop\n import heapq\n \n def compute_median(seq):\n min_heap, max_hea...
trial_gpt4o_7
{ "original_instruction": "", "prompt_id": "00031518", "row_id": 31518, "seed_ids": "[4114, 6379, 5241]" }
0.740331
Codeforces_31518
I
[ "perform_operation", "final_integer" ]
2
[ [ "final_integer", "perform_operation" ] ]
1
[]
false
[]
false
pytest
true
[]
true
6d884510393f8c7976a734e683062e4a8b50de7c
c4d82c4f5b46d6475424bf0c216c807538a8043a
v1.0
instruct
Codeforces
Codeforces_31603_I
Given n distinct points on a coordinate plane, find the maximum number of points that lie on the same straight line. The input consists of: - An integer n (1 ≤ n ≤ 300), the number of points. - n lines, each containing two integers x and y (-10^4 ≤ x, y ≤ 10^4), representing the coordinates of each point. Output a si...
from collections import defaultdict from typing import List, Tuple def gcd(a: int, b: int) -> int: while b: a, b = b, a % b return a def max_points_on_line(n: int, points: List[Tuple[int, int]]) -> int: if n <= 2: return n def slope(p1: Tuple[int, int], p2: Tuple[int, int]) -> Tuple[i...
from solution import max_points_on_line def test_example_1(): n = 4 points = [(1, 1), (2, 2), (3, 3), (4, 5)] assert max_points_on_line(n, points) == 3 def test_example_2(): n = 6 points = [(1, 1), (2, 2), (3, 3), (5, 5), (4, 6), (6, 1)] assert max_points_on_line(n, points) == 4 def test_sing...
[ { "docstring": null, "function_declaration": "def gcd(a, b):", "function_name": "gcd", "parameter_list": "(a, b)" }, { "docstring": null, "function_declaration": "def max_points_on_line(n, points):", "function_name": "max_points_on_line", "parameter_list": "(n, points)" }, { ...
[ 1, 1, 0 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "from collections import defaultdict\nfrom typing import List, Tuple\n\ndef gcd(a: int, b: int) -> int:\n while b:\n a, b = b, a % b\n return a\n\...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00031603", "row_id": 31603, "seed_ids": "[1561, 7099, 2744]" }
0.732962
Codeforces_31603
I
[ "gcd", "max_points_on_line" ]
2
[ [ "max_points_on_line", "gcd" ] ]
1
[]
false
[]
false
pytest
true
[]
true
8318e2d4e17e52e2a4cd77d4815c5612145badc6
beff42b12973f49bd660256506b89a741d47f2c7
v1.0
instruct
Codeforces
Codeforces_31614_I
You are given a 2D grid of size $$$n \times m$$$ filled with integers. Your goal is to answer $$$q$$$ queries. Each query contains two coordinates, $$$(x_1, y_1)$$$ and $$$(x_2, y_2)$$$, which represent a submatrix of the grid with top-left corner $$$(x_1, y_1)$$$ and bottom-right corner $$$(x_2, y_2)$$$. For each quer...
def compute_prefix_sum(grid, n, m): """ Computes the prefix sum matrix for a given grid. """ prefix_sum = [[0] * (m + 1) for _ in range(n + 1)] for i in range(1, n + 1): for j in range(1, m + 1): prefix_sum[i][j] = (grid[i-1][j-1] + prefix_sum...
from solution import compute_prefix_sum, submatrix_sum, process_queries def test_compute_prefix_sum(): grid = [ [1, 2, 3], [4, 5, 6], [7, 8, 9] ] expected_prefix_sum = [ [0, 0, 0, 0], [0, 1, 3, 6], [0, 5, 12, 21], [0, 12, 27, 45] ] assert comp...
[ { "docstring": "Computes the prefix sum matrix for a given grid.", "function_declaration": "def compute_prefix_sum(grid, n, m):", "function_name": "compute_prefix_sum", "parameter_list": "(grid, n, m)" }, { "docstring": "Calculates the sum of the submatrix from (x1, y1) to (x2, y2) using the...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def preprocess_matrix(matrix, n, m):\n \"\"\"\n Preprocess the given matrix to create a prefix sum matrix.\n \"\"\"\n prefix_sum = [[0] * (m + 1) ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00031614", "row_id": 31614, "seed_ids": "[4941, 3506, 8031]" }
0.715426
Codeforces_31614
I
[ "compute_prefix_sum", "submatrix_sum", "process_queries" ]
3
[ [ "process_queries", "compute_prefix_sum" ], [ "process_queries", "submatrix_sum" ] ]
2
[ "process_queries" ]
false
[]
false
pytest
true
[]
true
ccf955735471937c1c4e2a50c20f81468307ae08
59d0c4e53d903522845c4ba6c99ce7f0f843cbc1
v1.0
instruct
Codeforces
Codeforces_31620_I
In a magical land, there are n numbered cities connected by m bidirectional roads. Each road has a certain positive magic intensity associated with it. The King wants to ensure that every city is connected, either directly or indirectly. However, he wants to minimize the maximum magic intensity of the roads used in con...
def find(parent, i): if parent[i] == i: return i else: return find(parent, parent[i]) def union(parent, rank, x, y): rootX = find(parent, x) rootY = find(parent, y) if rank[rootX] < rank[rootY]: parent[rootX] = rootY elif rank[rootX] > rank[rootY]: parent[ro...
from solution import min_max_intensity def test_example_case(): assert min_max_intensity(4, 5, [(1, 2, 5), (1, 3, 3), (2, 3, 2), (2, 4, 4), (3, 4, 1)]) == 3 def test_all_equal_intensity(): assert min_max_intensity(3, 3, [(1, 2, 2), (2, 3, 2), (1, 3, 2)]) == 2 def test_successive_intensity(): assert min_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)" }, ...
[ 0, 0, 1 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def find_minimum_maximum_intensity(n, m, roads):\n \"\"\"\n Function to find the minimum possible maximum magic intensity of the roads used to connect a...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00031620", "row_id": 31620, "seed_ids": "[4697, 6913, 3698]" }
0.65813
Codeforces_31620
I
[ "find", "union", "kruskal", "min_max_intensity" ]
4
[ [ "kruskal", "find" ], [ "kruskal", "union" ], [ "min_max_intensity", "kruskal" ], [ "union", "find" ] ]
4
[]
false
[]
false
pytest
true
[]
true
d2c84f8a80159c69e6f1095de956ef858276e56a
f8a6e595c4ebc1e8433da41c4010fb70dde80f33
v1.0
instruct
Codeforces
Codeforces_31639_I
You are given a number of cities connected by bidirectional roads. Each road has a certain length. You need to determine the minimum cost to connect all the cities such that there is at least one path between any two cities. This is known as finding the Minimum Spanning Tree (MST) of the graph. The first line of input...
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[y...
import pytest from solution import min_cost_to_connect_cities def test_sample_1(): n = 4 m = 5 edges = [ (1, 2, 1), (1, 3, 3), (1, 4, 4), (2, 3, 2), (3, 4, 5), ] assert min_cost_to_connect_cities(n, m, edges) == 7 def test_sample_2(): n = 2 m = 1 ...
[ { "docstring": null, "function_declaration": "def find(parent, i):", "function_name": "find", "parameter_list": "(parent, i)" }, { "docstring": null, "function_declaration": "def union(parent, rank, x, y):", "function_name": "union", "parameter_list": "(parent, rank, x, y)" }, ...
[ 1, 1, 0 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_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 xroot...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00031639", "row_id": 31639, "seed_ids": "[7665, 2807, 254]" }
0.736042
Codeforces_31639
I
[ "find", "union", "min_cost_to_connect_cities" ]
3
[ [ "min_cost_to_connect_cities", "find" ], [ "min_cost_to_connect_cities", "union" ], [ "union", "find" ] ]
3
[]
false
[]
false
pytest
true
[]
true
2a4d0e165fccf17233e072a4967e999cfe2ebdc8
08dc7e07b6975ed973ab87ab3b2c91e7eb05174c
v1.0
instruct
Codeforces
Codeforces_31670_I
You are given an infinite sequence defined as follows: $$a_1 = 1,$$ $$a_2 = 2,$$ $$a_{n} = 2a_{n-1} + a_{n-2},$$ for all n ≥ 3. Your task is to determine the k-th term of the sequence modulo 10^9 + 7. **Input:** The first line contains an integer T (1 ≤ T ≤ 1000) - the number of test cases. Each of the next T lin...
MOD = 10**9 + 7 def matrix_mult(A, B, mod): return [ [ (A[0][0] * B[0][0] + A[0][1] * B[1][0]) % mod, (A[0][0] * B[0][1] + A[0][1] * B[1][1]) % mod ], [ (A[1][0] * B[0][0] + A[1][1] * B[1][0]) % mod, (A[1][0] * B[0][1] + A[1][1] * B[1][1]) % m...
from solution import sequence_terms def test_example_cases(): assert sequence_terms(3, [1, 2, 5]) == [1, 2, 29] def test_single_cases(): assert sequence_terms(1, [1]) == [1] assert sequence_terms(1, [2]) == [2] assert sequence_terms(1, [3]) == [5] assert sequence_terms(1, [4]) == [12] assert s...
[ { "docstring": null, "function_declaration": "def matrix_mult(A, B, mod):", "function_name": "matrix_mult", "parameter_list": "(A, B, mod)" }, { "docstring": null, "function_declaration": "def matrix_power(matrix, power, mod):", "function_name": "matrix_power", "parameter_list": ...
[ 0, 1, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "MOD = 10**9 + 7\n\ndef matrix_mult(A, B):\n # Multiplies two 2x2 matrices A and B\n return [\n [(A[0][0] * B[0][0] + A[0][1] * B[1][0]) % MOD,\n ...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00031670", "row_id": 31670, "seed_ids": "[4349, 822, 8102]" }
0.652093
Codeforces_31670
I
[ "matrix_mult", "matrix_power", "sequence_kth_term", "sequence_terms" ]
4
[ [ "matrix_power", "matrix_mult" ], [ "sequence_kth_term", "matrix_power" ], [ "sequence_terms", "sequence_kth_term" ] ]
3
[]
false
[]
false
pytest
true
[]
true
68c6d9034cec16bdfdc2763c557ee737a0be0a30
55ccf9a2740fea15df38f703411335fa8b86eae4
v1.0
instruct
Codeforces
Codeforces_31676_I
Alice has a collection of balloons, each with a certain number of candies inside. Alice wants to distribute the candies among her friends in such a way that each friend gets the same number of candies and each balloon is used completely. She can choose any number of friends (at least one). Your task is to find the maxi...
import math from functools import reduce def gcd_multiple(numbers): """ Returns the GCD of a list of numbers. """ return reduce(math.gcd, numbers) def max_friends(n, candies): """ Returns the maximum number of friends Alice can distribute the candies to. """ return gcd_multiple(candies...
from solution import max_friends def test_single_balloon(): assert max_friends(1, [10]) == 10 def test_two_balloons(): assert max_friends(2, [10, 20]) == 10 def test_multiple_balloons(): assert max_friends(3, [12, 15, 18]) == 3 assert max_friends(5, [20, 50, 30, 40, 70]) == 10 def test_no_common_div...
[ { "docstring": "Returns the GCD of a list of numbers.", "function_declaration": "def gcd_multiple(numbers):", "function_name": "gcd_multiple", "parameter_list": "(numbers)" }, { "docstring": "Returns the maximum number of friends Alice can distribute the candies to.", "function_declarati...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "from math import gcd\nfrom functools import reduce\n\ndef max_friends_from_candies(numbers):\n \"\"\"\n Returns the maximum number of friends such that ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00031676", "row_id": 31676, "seed_ids": "[3167, 4447, 6764]" }
0.60156
Codeforces_31676
I
[ "gcd_multiple", "max_friends" ]
2
[ [ "max_friends", "gcd_multiple" ] ]
1
[]
false
[]
false
pytest
true
[]
true
531851cc209524a2bb39cfc25fad7777a77e7d50
41d65bf4889413f5b43ac5ef8e44b69b1589963d
v1.0
instruct
Codeforces
Codeforces_31680_I
Masha loves playing with arrays. She has an array of integers of length \( n \). She can perform the following operation as many times as she wants (including zero): Select two indices \( i \) and \( j \) (1 ≤ i, j ≤ n, i \ne j), and set \( a_i = a_i \cdot a_j \) and \( a_j = a_i - a_j \). Given an array, Masha want...
def can_make_elements_equal(n, arr): """ Determines if all elements of an array can be made equal using the given operations. """ gcd = arr[0] # Find the GCD of all elements for num in arr[1:]: gcd = gcd_of_two_numbers(gcd, num) if gcd == 1: return "No" return "Ye...
from solution import can_make_elements_equal def test_example1(): assert can_make_elements_equal(3, [2, 4, 8]) == "Yes" def test_example2(): assert can_make_elements_equal(4, [1, 5, 9, 10]) == "No" def test_example3(): assert can_make_elements_equal(1, [7]) == "Yes" def test_identical_elements(): as...
[ { "docstring": "Determines if all elements of an array can be made equal using the given operations.", "function_declaration": "def can_make_elements_equal(n, arr):", "function_name": "can_make_elements_equal", "parameter_list": "(n, arr)" }, { "docstring": "Helper function to return GCD of ...
[ 1, 0, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def can_make_elements_equal(n, arr):\n \"\"\"\n Determines if all elements of an array can be made equal using the given operations.\n \"\"\"\n gc...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00031680", "row_id": 31680, "seed_ids": "[1805, 6993, 8037]" }
0.632443
Codeforces_31680
I
[ "can_make_elements_equal", "gcd_of_two_numbers" ]
2
[ [ "can_make_elements_equal", "gcd_of_two_numbers" ] ]
1
[]
false
[]
false
pytest
true
[]
true
a9c2ec672e3af7dee286aa1eca91e8067adcd70e
9cec92ba44b8680425d0dea46728b1c2a986ef53
v1.0
instruct
Codeforces
Codeforces_31684_I
Sophia loves playing with numbers and recently she got interested in palindromic numbers. A palindromic number is one that reads the same backward as forward, such as 121 or 3443. Given a number n, she wants to know what the smallest palindromic number greater than or equal to n is. Help Sophia by writing a function th...
def is_palindrome(num): """ Helper function to check if a number is a palindrome. """ return str(num) == str(num)[::-1] def next_palindrome(n): """ Returns the smallest palindromic number greater than or equal to n. """ while not is_palindrome(n): n += 1 return n def find_s...
from solution import is_palindrome, next_palindrome, find_smallest_palindromes def test_is_palindrome(): assert is_palindrome(121) == True assert is_palindrome(123) == False assert is_palindrome(1) == True assert is_palindrome(44) == True def test_next_palindrome(): assert next_palindrome(123) == ...
[ { "docstring": "Helper function to check if a number is a palindrome.", "function_declaration": "def is_palindrome(num):", "function_name": "is_palindrome", "parameter_list": "(num)" }, { "docstring": "Returns the smallest palindromic number greater than or equal to n.", "function_declar...
[ 0, 0, 0, 0, 1 ]
1
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_palindrome(x):\n \"\"\"\n Returns True if x is a palindrome number, False otherwise.\n \"\"\"\n return str(x) == str(x)[::-1]\n\ndef find_n...
trial_gpt4o_4
{ "original_instruction": "", "prompt_id": "00031684", "row_id": 31684, "seed_ids": "[8306, 1646, 2916]" }
0.817316
Codeforces_31684
I
[ "is_palindrome", "next_palindrome", "find_smallest_palindromes" ]
3
[ [ "find_smallest_palindromes", "next_palindrome" ], [ "next_palindrome", "is_palindrome" ] ]
2
[]
false
[]
false
pytest
true
[]
true
5b0671092f4c87d9099a38a8252f733eeaa2506d
755f84a5b6fd6d642191b0478e482baebf8aca7a
v1.0
instruct
Codeforces
Codeforces_31712_I
In a town called Graphville, there are n intersections connected by m bidirectional roads. The intersections are labeled from 1 to n. The roads are arranged such that there is a unique path between any two intersections. The mayor of Graphville, Ms. Euler, wants to identify if she can rearrange the roads to form a Eule...
from collections import defaultdict, deque def is_connected(graph, n): visited = [False] * (n + 1) def dfs(v): stack = [v] while stack: node = stack.pop() if not visited[node]: visited[node] = True for neighbor in graph[node]: ...
def test_eulerian_trail_case_1(): n = 5 m = 5 edges = [(1, 2), (2, 3), (3, 4), (4, 5), (3, 5)] find_eulerian_trail(n, edges) # Expected output: YES followed by a valid Eulerian trail def test_eulerian_trail_case_2(): n = 3 m = 2 edges = [(1, 2), (2, 3)] find_eulerian_trail(n, edges) ...
[ { "docstring": null, "function_declaration": "def is_connected(graph, n):", "function_name": "is_connected", "parameter_list": "(graph, n)" }, { "docstring": null, "function_declaration": "def find_eulerian_trail(n, edges):", "function_name": "find_eulerian_trail", "parameter_lis...
[ 0, 0, 0, 0, 0, 0, 0, 1, 0 ]
1
hard
0.111
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "from collections import defaultdict, deque\n\ndef find_eulerian_trail(n, m, roads):\n # Step 1: Construct the graph\n graph = defaultdict(list)\n deg...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00031712", "row_id": 31712, "seed_ids": "[4082, 4948, 6013]" }
0.663867
Codeforces_31712
I
[ "is_connected", "find_eulerian_trail" ]
2
[ [ "find_eulerian_trail", "is_connected" ] ]
1
[]
false
[]
false
pytest
false
[]
true
a15a52eff08659f01f85c1f1e248f372a0742405
8ad5f6530c23f79fa4ad303153e73488e8ae8981
v1.0
instruct
Codeforces
Codeforces_31742_I
Alice and Bob are playing a game on a tree. The tree consists of `n` nodes and `n-1` edges. Each edge has an initial weight of `1`. The tree has a unique root, node `1`. Alice starts at the root (node `1`), while Bob starts at the leaf node that is farthest from the root, breaking ties by choosing the smallest indexed ...
from collections import deque, defaultdict def tree_max_distance(n, edges): def bfs(start): dist = [-1] * (n + 1) q = deque([start]) dist[start] = 0 max_dist = 0 max_node = start while q: node = q.popleft() for neighbor in graph[node]...
from solution import min_moves_to_capture def test_example(): assert min_moves_to_capture(6, [(1, 2), (2, 3), (2, 4), (1, 5), (5, 6)]) == 2 def test_single_edge(): assert min_moves_to_capture(2, [(1, 2)]) == 1 def test_linear_tree(): assert min_moves_to_capture(5, [(1, 2), (2, 3), (3, 4), (4, 5)]) == 2 ...
[ { "docstring": null, "function_declaration": "def tree_max_distance(n, edges):", "function_name": "tree_max_distance", "parameter_list": "(n, edges)" }, { "docstring": null, "function_declaration": "def min_moves_to_capture(n, edges):", "function_name": "min_moves_to_capture", "p...
[ 0, 1, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "from collections import deque\n\ndef find_farthest_leaf(n, edges):\n adj = [[] for _ in range(n + 1)]\n for u, v in edges:\n adj[u].append(v)\n ...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00031742", "row_id": 31742, "seed_ids": "[2712, 7690, 3412]" }
0.755805
Codeforces_31742
I
[ "tree_max_distance", "min_moves_to_capture" ]
2
[ [ "min_moves_to_capture", "tree_max_distance" ] ]
1
[]
false
[]
false
pytest
true
[]
true
e4ac50219da5c34ae3a7256b59e26c1a31c8d99b
87898e2873d2f3af89c93584ea84f3e1298d4971
v1.0
instruct
Codeforces
Codeforces_31782_I
You have been given a matrix of size n x m and a list of q queries. Each query contains four integers x1, y1, x2, and y2. The task is to find the sum of all elements within the submatrix whose corners are defined by (x1, y1) and (x2, y2). The first line contains two integers n and m (1 ≤ n, m ≤ 1000) - the number of r...
def compute_prefix_sum(matrix): n = len(matrix) m = len(matrix[0]) prefix_sum = [[0] * (m + 1) for _ in range(n + 1)] for i in range(1, n + 1): for j in range(1, m + 1): prefix_sum[i][j] = matrix[i-1][j-1] + prefix_sum[i-1][j] + prefix_sum[i][j-1] - prefix_sum[i-1][j-1] ret...
from solution import process_queries def test_single_element_matrix(): n, m = 1, 1 matrix = [[5]] queries = [(1, 1, 1, 1)] assert process_queries(n, m, matrix, queries) == [5] def test_all_elements_query(): n, m = 2, 2 matrix = [[1, 2], [3, 4]] queries = [(1, 1, 2, 2)] assert process_q...
[ { "docstring": null, "function_declaration": "def compute_prefix_sum(matrix):", "function_name": "compute_prefix_sum", "parameter_list": "(matrix)" }, { "docstring": null, "function_declaration": "def sum_submatrix(prefix_sum, x1, y1, x2, y2):", "function_name": "sum_submatrix", ...
[ 1, 0, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def compute_prefix_sum(matrix):\n n = len(matrix)\n m = len(matrix[0])\n prefix_sum = [[0] * (m + 1) for _ in range(n + 1)]\n \n for i in range...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00031782", "row_id": 31782, "seed_ids": "[7240, 378, 5850]" }
0.667054
Codeforces_31782
I
[ "compute_prefix_sum", "sum_submatrix", "process_queries" ]
3
[ [ "process_queries", "compute_prefix_sum" ], [ "process_queries", "sum_submatrix" ] ]
2
[ "process_queries" ]
false
[]
false
pytest
true
[]
true
3bbb8c697ce8727deb935881c2e8fbe9ecaafc44
a56cd47bca2fdb24482c9afcc715251bc0a458d5
v1.0
instruct
Codeforces
Codeforces_31825_I
You are a developer for a logistics company that wants to optimize the allocation of shipping containers on various routes. Each route connects two cities and has a capacity that indicates the maximum number of containers it can handle per day. Your task is to find the maximum number of containers that can be shipped ...
from collections import defaultdict, deque def bfs_capacity(graph, source, sink, parent): visited = set() queue = deque([(source, float('Inf'))]) while queue: current_node, flow = queue.popleft() if current_node not in visited: visited.add(current_node) ...
from solution import find_maximum_containers def test_example_case(): n, m, k = 4, 5, 10 routes = [(1, 2, 5), (1, 3, 5), (2, 4, 3), (3, 4, 2), (2, 3, 2)] s, t = 1, 4 assert find_maximum_containers(n, m, k, routes, s, t) == 5 def test_case_with_insufficient_capacity(): n, m, k = 4, 5, 15 routes...
[ { "docstring": null, "function_declaration": "def bfs_capacity(graph, source, sink, parent):", "function_name": "bfs_capacity", "parameter_list": "(graph, source, sink, parent)" }, { "docstring": null, "function_declaration": "def max_flow(graph, source, sink):", "function_name": "ma...
[ 0, 0, 0, 0, 0, 0, 0, 1, 0, 1 ]
2
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "import collections \nimport heapq\n\ndef max_flow(n, m, k, edges, s, t):\n def dikjstra(source, sink, parent):\n dist = [float('inf')] * (n + 1)\n ...
trial_gpt4o_7
{ "original_instruction": "", "prompt_id": "00031825", "row_id": 31825, "seed_ids": "[6398, 12, 8199]" }
0.716625
Codeforces_31825
I
[ "bfs_capacity", "max_flow", "find_maximum_containers" ]
3
[ [ "find_maximum_containers", "max_flow" ], [ "max_flow", "bfs_capacity" ] ]
2
[]
false
[]
false
pytest
true
[]
true
5ccd21414dbeacf9a7b33c6ec3ef9b2447c0d1c2
b9deae3ffb15b88e14d9bb2a5a11e850f362130d
v1.0
instruct
Codeforces
Codeforces_31833_I
You have been gifted with a magical rectangular grid of size $$$n$$$ x $$$m$$$. The grid contains only the characters '.' (dot) and '#' (hash). Your task is to determine the minimum number of hash cells ('#') that must be turned into dot cells ('.') such that there is at least one clear path from the top-left corner o...
from collections import deque def min_hash_to_dot(grid, n, m): def is_valid(x, y): return 0 <= x < n and 0 <= y < m and grid[x][y] == '.' def bfs(): queue = deque([(0, 0)]) visited = [[False] * m for _ in range(n)] visited[0][0] = True steps = 0 while queue: ...
from solution import solve def test_example_case(): grid = ["..#", "#..", "###"] assert solve(3, 3, grid) == 1 def test_no_changes_needed(): grid = ["...", "...", "..."] assert solve(3, 3, grid) == 0 def test_full_block(): grid = ["###", "###", "###"] assert solve(3, 3, grid) == float('in...
[ { "docstring": null, "function_declaration": "def min_hash_to_dot(grid, n, m):", "function_name": "min_hash_to_dot", "parameter_list": "(grid, n, m)" }, { "docstring": null, "function_declaration": "def solve(n, m, grid):", "function_name": "solve", "parameter_list": "(n, m, grid...
[ 0, 0, 1 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def min_hashes_to_clear_path(grid):\n n = len(grid)\n m = len(grid[0])\n \n # Initialize a DP table with infinity\n dp = [[float('inf')] * m fo...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00031833", "row_id": 31833, "seed_ids": "[599, 2390, 2804]" }
0.674894
Codeforces_31833
I
[ "min_hash_to_dot", "solve" ]
2
[ [ "solve", "min_hash_to_dot" ] ]
1
[]
false
[]
false
pytest
true
[]
true
5e9c19d265bdb74c19d7650655527d748ea99d65
a6926398cf47b34bef16ca402b3a8f0b230e8fd0
v1.0
instruct
Codeforces
Codeforces_31868_I
You are given a directed graph with n nodes (numbered from 1 to n) and m arcs. Each arc (i, j) has a weight w associated with it, representing the cost to travel from node i to node j. You need to find the minimum possible cost to travel from the first node to the last node (from node 1 to node n). However, travel is ...
import heapq import sys def find_min_cost(n, m, k, edges): INF = sys.maxsize graph = [[] for _ in range(n + 1)] for u, v, w in edges: graph[u].append((v, w)) # Using Dijkstra's algorithm with a priority queue pq = [(0, 1, 0)] # (current cost, current node, number of arcs used) min_di...
from solution import solve def test_example_case(): input_str = "5 7 3\n1 2 2\n1 3 4\n2 3 1\n2 4 7\n3 4 3\n4 5 1\n3 5 5\n" assert solve(input_str) == "8" def test_case_unreachable(): input_str = "4 3 1\n1 2 2\n2 3 3\n3 4 1\n" assert solve(input_str) == "-1" def test_minimum_arcs_needed(): input_s...
[ { "docstring": null, "function_declaration": "def find_min_cost(n, m, k, edges):", "function_name": "find_min_cost", "parameter_list": "(n, m, k, edges)" }, { "docstring": null, "function_declaration": "def solve(input_str):", "function_name": "solve", "parameter_list": "(input_s...
[ 0, 0, 0, 0, 1 ]
1
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "import heapq\n\ndef find_min_cost(n, m, k, edges):\n # We'll use a min heap for Dijkstra's algorithm\n heap = []\n # distances[node][j] will represen...
trial_gpt4o_4
{ "original_instruction": "", "prompt_id": "00031868", "row_id": 31868, "seed_ids": "[7129, 8205, 7531]" }
0.762103
Codeforces_31868
I
[ "find_min_cost", "solve" ]
2
[ [ "solve", "find_min_cost" ] ]
1
[]
false
[]
false
pytest
true
[]
true
a4cdcfc478e2582e911dd0bf17680e5f91daef90
ac34d6ed46aa5d7ac258dd14b50a5e7c172b37fe
v1.0
instruct
Codeforces
Codeforces_31910_I
In this task, you need to create a parallel algorithm to merge multiple sorted arrays into one sorted array efficiently. The goal is to leverage multiple processors in order to speed up the merging process. ### Background Merging sorted arrays is a common problem in computer science with applications in various domain...
from heapq import merge import multiprocessing as mp def merge_sorted_arrays(arrays, p): """ Merges multiple sorted arrays into a single sorted array using p processors. Parameters: arrays (list of lists of int): The k sorted arrays to merge. p (int): Number of available processors. R...
import pytest from solution import merge_sorted_arrays def test_merge_sorted_arrays_small(): arrays = [ [1, 4, 7, 10], [2, 5, 8, 11], [3, 6, 9, 12] ] p = 2 result = merge_sorted_arrays(arrays, p) expected = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12] assert result == expecte...
[ { "docstring": "Merges multiple sorted arrays into a single sorted array using p processors.\n\nParameters:\narrays (list of lists of int): The k sorted arrays to merge.\np (int): Number of available processors.\n\nReturns:\nlist of int: The merged sorted array.", "function_declaration": "def merge_sorted_a...
[ 0, 1, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "import heapq\nimport multiprocessing\n\ndef merge_sorted_arrays(arrays, processors):\n \"\"\"\n Merges multiple sorted arrays into a single sorted array...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00031910", "row_id": 31910, "seed_ids": "[5235, 6794, 2340]" }
0.612993
Codeforces_31910
I
[ "merge_sorted_arrays", "merge_worker", "main" ]
3
[ [ "merge_sorted_arrays", "merge_worker" ] ]
1
[]
false
[]
false
pytest
true
[]
true
94da6ccb9998f681b35a0299bdf8427c24b12529
817156b5d7fbfc76af07abfcfd1471ecb933698c
v1.0
instruct
Codeforces
Codeforces_31994_I
Sam is playing a digital card game where each card has a power level represented by an integer. He wants to maximize his score by arranging the cards in a specific order. Sam can make two moves to rearrange the cards: 1. Swap the positions of any two cards. 2. Reverse the sub-sequence of cards between two chosen positi...
def maximum_subsequence_sum(cards): """ Returns the maximum subsequence sum after performing at most one swap and/or one subsequence reversal. """ # Optimal sub-sequence sum in the original array max_sum = max_subsequence_sum(cards) n = len(cards) # Trying all possible single swaps...
from solution import maximum_subsequence_sum def test_single_positive_number(): assert maximum_subsequence_sum([10]) == 10 def test_single_negative_number(): assert maximum_subsequence_sum([-10]) == 0 def test_multiple_mixed_numbers(): assert maximum_subsequence_sum([3, -1, 4, -2, 5]) == 12 def test_all...
[ { "docstring": "Returns the maximum subsequence sum after performing at most one swap and/or one subsequence reversal.", "function_declaration": "def maximum_subsequence_sum(cards):", "function_name": "maximum_subsequence_sum", "parameter_list": "(cards)" }, { "docstring": "Helper function t...
[ 0, 0, 0, 0, 0, 0, 0, 1, 0, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def max_subsequence_sum(cards):\n \"\"\"\n Given the list of card power levels, this function returns the maximum sum\n of any subsequence after perf...
trial_gpt4o_7
{ "original_instruction": "", "prompt_id": "00031994", "row_id": 31994, "seed_ids": "[797, 6853, 5636]" }
0.656537
Codeforces_31994
I
[ "maximum_subsequence_sum", "max_subsequence_sum" ]
2
[ [ "maximum_subsequence_sum", "max_subsequence_sum" ] ]
1
[]
false
[]
false
pytest
true
[]
true
6c9b6562d2167c02b6c74fc821ff730d72190e7b
591d5625230b584654f0ff303a2b6d0ea30e0c69
v1.0
instruct
Codeforces
Codeforces_31996_I
You're given a grid with N rows and M columns. Each cell contains either a '.', representing an open space, or a '#', representing an obstacle. You can move from any open space to any adjacent open space (up, down, left, or right). You're also given coordinates of the starting point (Sx, Sy) and the ending point (Ex, E...
from collections import deque def min_moves(grid, n, m, start, end): directions = [(1, 0), (-1, 0), (0, 1), (0, -1)] # Down, Up, Right, Left sx, sy = start ex, ey = end sx -= 1 # Convert to 0-based indexing sy -= 1 ex -= 1 ey -= 1 if grid[sx][sy] == '#' or grid[ex][ey] ...
def test_min_moves(): grid = [ '.....', '.###.', '.#.#.', '.#...', '.....' ] n, m = 5, 5 start = (1, 1) end = (5, 5) assert min_moves(grid, n, m, start, end) == 8 def test_min_moves_no_path(): grid = [ '.....', '.###.', '#####'...
[ { "docstring": null, "function_declaration": "def min_moves(grid, n, m, start, end):", "function_name": "min_moves", "parameter_list": "(grid, n, m, start, end)" }, { "docstring": null, "function_declaration": "def solve():", "function_name": "solve", "parameter_list": "()" } ]
[ 0, 0, 0, 1, 0 ]
1
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "from collections import deque\n\ndef min_moves_to_reach_end(N, M, grid, Sx, Sy, Ex, Ey):\n directions = [(0, 1), (1, 0), (0, -1), (-1, 0)]\n \n Sx -=...
trial_gpt4o_3
{ "original_instruction": "", "prompt_id": "00031996", "row_id": 31996, "seed_ids": "[4332, 7560, 5749]" }
0.818994
Codeforces_31996
I
[ "min_moves", "solve" ]
2
[ [ "solve", "min_moves" ] ]
1
[]
false
[]
false
pytest
false
[]
true
d2ec6bbc8b56701298e45e7904515365491e77af
38fb9035da23fe45e068b236b01e1f9d055a5f82
v1.0
instruct
Codeforces
Codeforces_31997_I
Vanya has recently started learning about graphs. A graph consists of vertices connected by edges. He learned that a tree is a special type of graph that is connected and acyclic, meaning there is exactly one path between any two vertices. Vanya is given an undirected tree with `n` vertices, and each edge has a positiv...
from collections import defaultdict, deque def find_farthest_node(start, graph, n): visited = [False] * (n + 1) distances = [-1] * (n + 1) distances[start] = 0 queue = deque([start]) farthest_node = start max_distance = 0 while queue: current = queue.popleft() visited[...
def test_example_case(): edges = [(1, 2, 3), (1, 3, 2), (3, 4, 4), (3, 5, 2)] assert tree_diameter(5, edges) == 9 def test_single_path(): edges = [(1, 2, 1)] assert tree_diameter(2, edges) == 1 def test_all_nodes_connected_in_line(): edges = [(1, 2, 1), (2, 3, 1), (3, 4, 1)] assert tree_diamet...
[ { "docstring": null, "function_declaration": "def find_farthest_node(start, graph, n):", "function_name": "find_farthest_node", "parameter_list": "(start, graph, n)" }, { "docstring": null, "function_declaration": "def tree_diameter(n, edges):", "function_name": "tree_diameter", ...
[ 0, 0, 1 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "import collections\n\ndef find_tree_diameter(n, edges):\n if n == 1:\n return 0\n\n def bfs(start_node):\n distances = [-1] * (n + 1)\n ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00031997", "row_id": 31997, "seed_ids": "[149, 3215, 7782]" }
0.651391
Codeforces_31997
I
[ "find_farthest_node", "tree_diameter" ]
2
[ [ "tree_diameter", "find_farthest_node" ] ]
1
[]
false
[]
false
pytest
false
[]
true
b09e95843ad2f2f47d1c1919710fa93243181f85
2ad821dbdbd9185c43eb0fd86e7dae4ba0ae1adc
v1.0
instruct
Codeforces
Codeforces_32003_I
You are given a list of n integers representing the pages of a book that need to be read before an upcoming exam. Each page has a difficulty level associated with it. You want to distribute these pages among m students such that the maximum sum of difficulties a student has to read is minimized. Each student should ge...
def find_min_difficulty(pages, n, m): """ Function to find the minimized maximum sum of difficulties a student has to read. """ def is_possible(threshold): """ Helper function to check if a given threshold can be maintained. """ student_count = 1 current_sum = 0 ...
from solution import minimized_maximum_difficulty def test_minimized_maximum_difficulty_case1(): assert minimized_maximum_difficulty(6, 3, [10, 20, 30, 40, 50, 60]) == 90 def test_minimized_maximum_difficulty_case2(): assert minimized_maximum_difficulty(4, 2, [10, 20, 10, 30]) == 40 def test_minimized_maximu...
[ { "docstring": "Function to find the minimized maximum sum of difficulties a student has to read.", "function_declaration": "def find_min_difficulty(pages, n, m):", "function_name": "find_min_difficulty", "parameter_list": "(pages, n, m)" }, { "docstring": null, "function_declaration": "...
[ 0, 1, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def find_min_max_page_difficulty(pages, students):\n def can_divide(max_sum):\n current_sum = 0\n required_students = 1\n\n for page i...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00032003", "row_id": 32003, "seed_ids": "[5250, 4348, 5235]" }
0.689282
Codeforces_32003
I
[ "find_min_difficulty", "minimized_maximum_difficulty" ]
2
[ [ "minimized_maximum_difficulty", "find_min_difficulty" ] ]
1
[]
false
[]
false
pytest
true
[]
true
fcf95c7493816b6ec79f97d1c0b2075bbb22fe65
f562b31e027601fb3ddfb2a1c471fbbba01c2e0a
v1.0
instruct
Codeforces
Codeforces_32006_I
In a fantasy kingdom, there are n cities connected by n-1 bidirectional roads, forming a tree. Each city has a unique integer identifier from 1 to n. The King of this kingdom wants to establish a new capital in one of the cities. However, the city chosen as the capital must minimize the maximum distance to any other ci...
from collections import defaultdict, deque def find_tree_diameter(n, edges): # Build adjacency list graph = defaultdict(list) for u, v in edges: graph[u].append(v) graph[v].append(u) # Helper function to perform BFS and return the farthest node and its distance def bfs(start): ...
from solution import find_optimal_capital def test_find_optimal_capital(): assert find_optimal_capital(6, [(1, 2), (1, 3), (2, 4), (2, 5), (3, 6)]) == [1] assert find_optimal_capital(4, [(1, 2), (2, 3), (3, 4)]) == [2, 3] assert find_optimal_capital(7, [(1, 2), (1, 3), (2, 4), (2, 5), (4, 6), (4, 7)]) == [...
[ { "docstring": null, "function_declaration": "def find_tree_diameter(n, edges):", "function_name": "find_tree_diameter", "parameter_list": "(n, edges)" }, { "docstring": null, "function_declaration": "def find_optimal_capital(n, edges):", "function_name": "find_optimal_capital", ...
[ 0, 1, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "from collections import deque, defaultdict\n\ndef find_best_capital(n, roads):\n def bfs(start):\n distances = [-1] * (n + 1)\n queue = deque...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00032006", "row_id": 32006, "seed_ids": "[4009, 6357, 1520]" }
0.753945
Codeforces_32006
I
[ "find_tree_diameter", "find_optimal_capital" ]
2
[ [ "find_optimal_capital", "find_tree_diameter" ] ]
1
[]
false
[]
false
pytest
true
[]
true
532a4a792fa1dc554a2f37491d95f1902b45d779
f359e55094adca57fe35e723eb291c9290437a4e
v1.0
instruct
Codeforces
Codeforces_32011_I
You are given an undirected graph with `n` nodes and `m` edges. Each node is initially uncolored. Your task is to color the nodes such that no two adjacent nodes share the same color using the minimum number of colors possible. You need to determine the minimum number of colors required to color the graph. The input ...
def is_bipartite(graph, n, start): """ Utility function to check if the graph is bipartite starting from a given node. """ color = [-1] * n queue = [start] color[start] = 1 while queue: node = queue.pop(0) for neighbor in graph[node]: if color[neighbor] == -1: # ...
import pytest from solution import solve def test_example_case_1(): t = 2 test_cases = [ (3, 3, [(1, 2), (2, 3), (3, 1)]), (4, 4, [(1, 2), (2, 3), (3, 4), (4, 1)]) ] result = solve(t, test_cases) assert result == [3, 2] def test_no_edges_case(): t = 1 test_cases = [ ...
[ { "docstring": "Utility function to check if the graph is bipartite starting from a given node.", "function_declaration": "def is_bipartite(graph, n, start):", "function_name": "is_bipartite", "parameter_list": "(graph, n, start)" }, { "docstring": "Determines the minimum number of colors re...
[ 0, 0, 0, 0, 1 ]
1
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def minimum_colors(t, test_cases):\n from collections import deque\n \n def bfs(node, graph, colors):\n queue = deque([node])\n colors[...
trial_gpt4o_4
{ "original_instruction": "", "prompt_id": "00032011", "row_id": 32011, "seed_ids": "[5477, 4008, 8237]" }
0.656448
Codeforces_32011
I
[ "is_bipartite", "minimum_colors_required", "solve" ]
3
[ [ "minimum_colors_required", "is_bipartite" ], [ "solve", "minimum_colors_required" ] ]
2
[]
false
[]
false
pytest
true
[]
true
0a2bfdf5b9bbb76f9f4f28d5e3023b950b5995d9
38b8c4f42c152665afc0d002372c345beaed32a4
v1.0
instruct
Codeforces
Codeforces_32042_I
In a parallel universe, spatial coordinates in a 2D grid can contain portals that teleport entities from one position to another. The grid can be visualized as an infinite plane where each cell is represented by its x and y coordinates. Each portal connects exactly two different cells on the grid. Entities can travel t...
from collections import deque, defaultdict def build_graph(portals): """ Build the graph of portals using adjacency list representation. """ graph = defaultdict(list) for (x1, y1, x2, y2) in portals: graph[(x1, y1)].append((x2, y2)) graph[(x2, y2)].append((x1, y1)) return graph def bfs...
from solution import min_portals_required def test_min_portals_case_1(): portals = [(0, 0, 1, 1), (1, 1, 2, 2), (2, 2, 3, 3), (3, 3, 4, 4)] queries = [(0, 0, 4, 4), (0, 0, 5, 5)] assert min_portals_required(portals, queries) == [4, -1] def test_min_portals_case_2(): portals = [(0, 0, 1, 1), (1, 1, 2, ...
[ { "docstring": "Build the graph of portals using adjacency list representation. ", "function_declaration": "def build_graph(portals):", "function_name": "build_graph", "parameter_list": "(portals)" }, { "docstring": "Perform BFS to find the minimum number of portals required to reach the tar...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "from collections import defaultdict, deque\n\ndef min_portals(portals, queries):\n # Create a graph where each node represents a cell and each edge represe...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00032042", "row_id": 32042, "seed_ids": "[94, 4671, 4180]" }
0.64065
Codeforces_32042
I
[ "build_graph", "bfs_min_portals", "min_portals_required" ]
3
[ [ "min_portals_required", "bfs_min_portals" ], [ "min_portals_required", "build_graph" ] ]
2
[]
false
[]
false
pytest
true
[]
true
722f27fe5ea939d8bb8d456245713f1dc9daa98d
30b3f485d08477d9c161c6666103b42f2d044b88
v1.0
instruct
Codeforces
Codeforces_32056_I
Alex is a big fan of number sequences. He recently encountered an interesting sequence-related problem and needs your help to solve it. The problem revolves around finding the longest subsequence with strictly increasing values from a given list of integers. Formally, given a list of integers, determine the longest su...
def length_of_lis(arr): """ Returns the length of the longest increasing subsequence in arr. """ if not arr: return 0 n = len(arr) lis = [1] * n for i in range(1, n): for j in range(0, i): if arr[i] > arr[j] and lis[i] < lis[j] + 1: lis[i...
from solution import length_of_lis, longest_increasing_subsequence, solve def test_length_of_lis(): assert length_of_lis([2, 5, 3, 7, 11]) == 4 assert length_of_lis([10, 22, 9, 33, 21, 50]) == 4 assert length_of_lis([3, 10, 2, 1, 20]) == 3 assert length_of_lis([3, 2]) == 1 assert length_of_lis([50,...
[ { "docstring": "Returns the length of the longest increasing subsequence in arr.", "function_declaration": "def length_of_lis(arr):", "function_name": "length_of_lis", "parameter_list": "(arr)" }, { "docstring": "Returns the list of lengths of longest increasing subsequences for each test ca...
[ 0, 1, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def longest_increasing_subsequence_length(n, lst):\n if n == 0:\n return 0\n\n lis = [1] * n\n\n for i in range(1, n):\n for j in range...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00032056", "row_id": 32056, "seed_ids": "[3336, 2553, 5415]" }
0.811052
Codeforces_32056
I
[ "length_of_lis", "longest_increasing_subsequence", "solve" ]
3
[ [ "longest_increasing_subsequence", "length_of_lis" ], [ "solve", "longest_increasing_subsequence" ] ]
2
[]
false
[]
false
pytest
true
[]
true
f0f368d27ae9ee2058221314822606bfcee0648f
be2ed87cc0fa54580745a426011ab614a491bf62
v1.0
instruct
Codeforces
Codeforces_32059_I
Your friend Jack is planning a long trip and he needs to pack his backpack with essential items but he wants to minimize the weight he carries. Jack has a selection of items, each with a certain weight and value. He wants to maximize the total value of items in his backpack without exceeding the maximum weight his back...
def knapsack(max_weight, weights, values, n): # Initialize DP table with zeros dp = [[0 for x in range(max_weight + 1)] for y in range(n + 1)] # Build table dp[][] in bottom up manner for i in range(n + 1): for w in range(max_weight + 1): if i == 0 or w == 0: dp[i][w...
from solution import maximize_value def test_sample_case(): n = 4 W = 10 items = [(5, 10), (4, 40), (6, 30), (3, 50)] assert maximize_value(n, W, items) == 90 def test_single_item_fits(): n = 1 W = 10 items = [(10, 100)] assert maximize_value(n, W, items) == 100 def test_single_item_d...
[ { "docstring": null, "function_declaration": "def knapsack(max_weight, weights, values, n):", "function_name": "knapsack", "parameter_list": "(max_weight, weights, values, n)" }, { "docstring": null, "function_declaration": "def maximize_value(n, W, items):", "function_name": "maximi...
[ 0, 0, 0, 0, 0, 1, 0, 0, 0, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def knapsack(N, W, items):\n dp = [[0 for _ in range(W + 1)] for _ in range(N + 1)]\n \n for i in range(1, N + 1):\n for w in range(W + 1):\n ...
trial_gpt4o_5
{ "original_instruction": "", "prompt_id": "00032059", "row_id": 32059, "seed_ids": "[4030, 1744, 1500]" }
0.749308
Codeforces_32059
I
[ "knapsack", "maximize_value" ]
2
[ [ "maximize_value", "knapsack" ] ]
1
[]
false
[]
false
pytest
true
[]
true
c51a8022cf4135a06ba06dbb396b9e875896f3ed
97ce630be69246266d8c6e64471e675cbec6f528
v1.0
instruct
Codeforces
Codeforces_32071_I
Alice is a botanist who loves growing plants. She has a garden with n types of plants, each with a specific growth rate. The growth rate of the i-th plant is given as gi. Alice wants to plant these in a peculiar way to maximize the biodiversity of her garden. For biodiversity, Alice defines two consecutive plants as h...
def is_prime(x): """Returns True if x is a prime number, else False.""" if x <= 1: return False if x <= 3: return True if x % 2 == 0 or x % 3 == 0: return False i = 5 while i * i <= x: if x % i == 0 or x % (i + 2) == 0: return False i += 6 ...
from solution import is_prime, max_biodiversity_pairs def test_is_prime(): assert is_prime(2) assert is_prime(3) assert not is_prime(1) assert not is_prime(4) assert is_prime(5) assert not is_prime(6) assert is_prime(7) assert not is_prime(9) assert is_prime(17) def test_max_biodiv...
[ { "docstring": "Returns True if x is a prime number, else False.", "function_declaration": "def is_prime(x):", "function_name": "is_prime", "parameter_list": "(x)" }, { "docstring": "Returns the maximum number of consecutive good biodiversity pairs.", "function_declaration": "def max_bio...
[ 0, 0, 0, 1, 1 ]
2
medium
0.4
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(num):\n \"\"\"\n Determine if a number is prime.\n \"\"\"\n if num <= 1:\n return False\n if num <= 3:\n return True...
trial_gpt4o_4
{ "original_instruction": "", "prompt_id": "00032071", "row_id": 32071, "seed_ids": "[7068, 732, 3354]" }
0.55957
Codeforces_32071
I
[ "is_prime", "max_biodiversity_pairs" ]
2
[ [ "max_biodiversity_pairs", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
653589e6db4d87cf4d6b15c84a466b1161e70c33
16014afceb5ca1c4071e3f155067db8cf1d6a08e
v1.0
instruct
Codeforces
Codeforces_32078_I
In a city, there are `N` intersections connected by `M` bidirectional roads. Each road has a length `L`. Two people, Alice and Bob, live at different intersections and want to meet at the same place. They want to find the shortest distance they each must travel to meet at a common intersection. Write a program that, g...
from collections import deque def bfs(start, N, adj): dist = [-1] * (N + 1) dist[start] = 0 queue = deque([start]) while queue: u = queue.popleft() for v in adj[u]: if dist[v] == -1: dist[v] = dist[u] + 1 queue.append(v) return dist def m...
from solution import minimum_meeting_distance def test_example_case(): N = 5 M = 5 L = 2 A = 1 B = 3 roads = [(1, 2), (2, 3), (3, 4), (4, 5), (5, 1)] assert minimum_meeting_distance(N, M, L, A, B, roads) == 4 def test_no_meeting_point(): N = 5 M = 3 L = 2 A = 1 B = 5 ...
[ { "docstring": null, "function_declaration": "def bfs(start, N, adj):", "function_name": "bfs", "parameter_list": "(start, N, adj)" }, { "docstring": null, "function_declaration": "def minimum_meeting_distance(N, M, L, A, B, roads):", "function_name": "minimum_meeting_distance", ...
[ 0, 0, 0, 0, 1 ]
1
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "from collections import deque, defaultdict\n\ndef bfs(start, n, adj_list):\n \"\"\"\n Perform Breadth-First Search (BFS) from the start node to compute ...
trial_gpt4o_4
{ "original_instruction": "", "prompt_id": "00032078", "row_id": 32078, "seed_ids": "[5313, 2970, 2134]" }
0.731763
Codeforces_32078
I
[ "bfs", "minimum_meeting_distance" ]
2
[ [ "minimum_meeting_distance", "bfs" ] ]
1
[]
false
[]
false
pytest
true
[]
true
459a3286039d7e92fbda38e89efa5833ebe62f95
171a0edb50b24a67e6fef2e78317785c065691cb
v1.0
instruct
Codeforces
Codeforces_32083_I
Alex is planning a treasure hunt and wants to place clues at various coordinates on a 2D plane. He has a list of coordinates where each coordinate $(x_i, y_i)$ specifies a point on the plane. Alex wants to ensure the hunt will be challenging by hiding each clue at the convex hull of the given coordinates. Your task is...
def convex_hull(points): """ Computes the vertices of the convex hull of the given set of 2D points. :param points: List of tuples representing the coordinates (x, y). :return: List of tuples representing the vertices of the convex hull in counter-clockwise order. """ # Sort the points lexicogra...
from solution import convex_hull def test_given_example(): points = [(0, 0), (1, 1), (2, 2), (2, 0), (1, 3)] expected = [(0, 0), (2, 0), (2, 2), (1, 3)] result = convex_hull(points) assert result == expected, f"Expected {expected}, but got {result}" def test_square(): points = [(0, 0), (0, 1), (1,...
[ { "docstring": "Computes the vertices of the convex hull of the given set of 2D points.\n:param points: List of tuples representing the coordinates (x, y).\n:return: List of tuples representing the vertices of the convex hull in counter-clockwise order.", "function_declaration": "def convex_hull(points):", ...
[ 0, 0, 0, 1, 1 ]
2
medium
0.4
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def convex_hull(points):\n \"\"\"\n Computes the vertices of the convex hull of the set of points using Graham's scan algorithm.\n Args:\n points:...
trial_gpt4o_4
{ "original_instruction": "", "prompt_id": "00032083", "row_id": 32083, "seed_ids": "[7828, 5556, 7427]" }
0.625963
Codeforces_32083
I
[ "convex_hull", "cross" ]
2
[ [ "convex_hull", "cross" ] ]
1
[]
false
[]
false
pytest
true
[]
true
d6a1db582b6063d1083a11da1a11b1ab84e5df84
1363a3e2da372e2650e82c886ac9b07169e1222a
v1.0
instruct
Codeforces
Codeforces_32117_I
Bob is fascinated by numbers, particularly by palindromic numbers. A palindromic number is a number that remains the same when its digits are reversed. Bob defines a palindromic range as a range of numbers [l, r] (inclusive) where both l and r are palindromic numbers. Bob has a list of queries, each giving a range [l,...
def is_palindromic(n): """ Check if a number n is palindromic. """ return str(n) == str(n)[::-1] def count_palindromic_numbers(l, r): """ Count palindromic numbers in the range [l, r] (inclusive). """ count = 0 for number in range(l, r + 1): if is_palindromic(number): ...
from solution import is_palindromic, count_palindromic_numbers, palindromic_queries def test_is_palindromic(): assert is_palindromic(121) == True assert is_palindromic(123) == False assert is_palindromic(0) == True assert is_palindromic(1) == True assert is_palindromic(12321) == True def test_coun...
[ { "docstring": "Check if a number n is palindromic.", "function_declaration": "def is_palindromic(n):", "function_name": "is_palindromic", "parameter_list": "(n)" }, { "docstring": "Count palindromic numbers in the range [l, r] (inclusive).", "function_declaration": "def count_palindromi...
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_palindromic(n):\n \"\"\"\n Check if a number is palindromic.\n \"\"\"\n return str(n) == str(n)[::-1]\n\ndef count_palindromic_numbers(l, r...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00032117", "row_id": 32117, "seed_ids": "[4508, 1053, 7647]" }
0.619471
Codeforces_32117
I
[ "is_palindromic", "count_palindromic_numbers", "palindromic_queries" ]
3
[ [ "count_palindromic_numbers", "is_palindromic" ], [ "palindromic_queries", "count_palindromic_numbers" ] ]
2
[]
false
[]
false
pytest
true
[]
true
1290374a58931d9976a2c30b580205a23aa631b2
046f10430022b8bedc45317bb57dcf105a038907
v1.0
instruct
Codeforces
Codeforces_32146_I
In a distant land, there exists a kingdom named Graphonia. The kingdom consists of N cities connected by a network of M bidirectional roads. Each road connects two cities and has a certain travel time associated with it. The king of Graphonia wishes to make communication as efficient as possible between any two cities ...
import heapq def dijkstra(graph, start, n): distances = {node: float('infinity') for node in range(1, n + 1)} distances[start] = 0 pq = [(0, start)] while pq: current_distance, current_node = heapq.heappop(pq) if current_distance > distances[current_node]: cont...
import pytest def test_shortest_path_with_new_road(): assert shortest_path_with_new_road(5, 7, 1, 5, [(1, 2, 2), (2, 3, 3), (3, 4, 4), (4, 5, 5), (1, 3, 6), (1, 4, 10), (3, 5, 1)], (2, 5, 2)) == 4 assert shortest_path_with_new_road(...
[ { "docstring": null, "function_declaration": "def dijkstra(graph, start, n):", "function_name": "dijkstra", "parameter_list": "(graph, start, n)" }, { "docstring": null, "function_declaration": "def shortest_path_with_new_road(n, m, s, d, roads, new_road):", "function_name": "shortes...
[ 1, 0 ]
1
medium
0.5
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "import heapq\n\ndef dijkstra(graph, start, n):\n distances = {node: float('infinity') for node in range(1, n + 1)}\n distances[start] = 0\n pq = [(0,...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00032146", "row_id": 32146, "seed_ids": "[1664, 7651, 6801]" }
0.771375
Codeforces_32146
I
[ "dijkstra", "shortest_path_with_new_road" ]
2
[ [ "shortest_path_with_new_road", "dijkstra" ] ]
1
[]
false
[]
false
pytest
false
[]
true
65c27e61d9b65c5389f5e421c6cdba33a6d8080e
5e8484ac4fcd4bcaefe3635f28539abb5530aea2
v1.0
instruct
Codeforces
Codeforces_32153_I
You are given a rectangular grid with n rows and m columns. Each cell in the grid contains a positive integer indicating the height of that cell. You can move the hero from a cell only to one of its four adjacent cells (up, down, left, right) if the height of the destination cell is not lower than the height of the cur...
from heapq import heappop, heappush def dijkstra_min_moves(grid): n, m = len(grid), len(grid[0]) moves = [[float('inf')] * m for _ in range(n)] moves[0][0] = 0 heap = [(0, 0, 0)] # (moves_count, x, y) directions = [(0, 1), (1, 0), (0, -1), (-1, 0)] while heap: move_count, x, y = heap...
from solution import minimum_moves def test_minimum_moves_possible(): assert minimum_moves(3, 3, [ [1, 2, 3], [4, 5, 6], [7, 8, 9] ]) == 4 def test_minimum_moves_not_possible(): assert minimum_moves(3, 3, [ [1, 2, 3], [2, 1, 3], [3, 2, 1] ]) == -1 def t...
[ { "docstring": null, "function_declaration": "def dijkstra_min_moves(grid):", "function_name": "dijkstra_min_moves", "parameter_list": "(grid)" }, { "docstring": null, "function_declaration": "def minimum_moves(n, m, heights):", "function_name": "minimum_moves", "parameter_list":...
[ 0, 1, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "import heapq\n\ndef min_moves_to_reach_end(grid):\n n = len(grid)\n m = len(grid[0])\n directions = [(0, 1), (1, 0), (0, -1), (-1, 0)] # right, down...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00032153", "row_id": 32153, "seed_ids": "[6095, 7836, 1031]" }
0.746108
Codeforces_32153
I
[ "dijkstra_min_moves", "minimum_moves" ]
2
[ [ "minimum_moves", "dijkstra_min_moves" ] ]
1
[]
false
[]
false
pytest
true
[]
true
15b96223e14693b975b2a57472be3ea3a8617a74
bd0f3b60b2ef39e3a9897939005d9f434b04c697
v1.0
instruct
Codeforces
Codeforces_32220_I
Nikita has a tree with $$$n$$$ vertices. Each edge in the tree has a weight. A path in the tree is a sequence of vertices such that there is an edge between every pair of consecutive vertices in the sequence. The weight of a path is the sum of the weights of its edges. Nikita wants to find the two vertices u and v suc...
from collections import defaultdict, deque def find_farthest_node(start, tree): """ Uses BFS to find the farthest node and its distance from the start node. """ visited = {} queue = deque([(start, 0)]) max_distance = 0 farthest_node = start while queue: node, curr_distance ...
from solution import maximum_path_weight def test_example_case(): n = 5 edges = [ (1, 2, 3), (2, 3, 4), (3, 4, 5), (4, 5, 6) ] assert maximum_path_weight(n, edges) == 18 def test_simple_case(): n = 3 edges = [ (1, 2, 1), (2, 3, 2) ] asser...
[ { "docstring": "Uses BFS to find the farthest node and its distance from the start node.", "function_declaration": "def find_farthest_node(start, tree):", "function_name": "find_farthest_node", "parameter_list": "(start, tree)" }, { "docstring": "Finds the two vertices in the tree such that ...
[ 0, 1, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def find_max_weight_path(n, edges):\n from collections import defaultdict, deque\n \n def bfs(start):\n distance = [-1] * (n + 1)\n que...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00032220", "row_id": 32220, "seed_ids": "[3142, 5779, 7232]" }
0.74407
Codeforces_32220
I
[ "find_farthest_node", "maximum_path_weight" ]
2
[ [ "maximum_path_weight", "find_farthest_node" ] ]
1
[]
false
[]
false
pytest
true
[]
true
d4a8f255f3a9f0ca12fd30eaadaf055bd803007f
c4979d718b6088872b3bf2a7cb0694c58e50bef0
v1.0
instruct
Codeforces
Codeforces_32223_I
You are given a 2D grid of size $$$n \times m$$$ where each cell contains a single lower-case letter. A subgrid is a rectangular section of the grid that includes some rows and some columns. A subgrid is considered beautiful if each row in the subgrid contains all unique characters. Your task is to find the largest be...
def is_beautiful_subgrid(grid, top_row, bottom_row, left_col, right_col): for i in range(top_row, bottom_row + 1): if len(set(grid[i][left_col:right_col + 1])) < (right_col - left_col + 1): return False return True def find_largest_beautiful_subgrid(n, m, grid): max_area = 0 best_to...
from solution import is_beautiful_subgrid, find_largest_beautiful_subgrid def test_is_beautiful_subgrid(): grid1 = [ "abc", "def", "ghi" ] assert is_beautiful_subgrid(grid1, 0, 0, 0, 2) == True # Single row, all unique assert is_beautiful_subgrid(grid1, 0, 1, 0, 2) == True...
[ { "docstring": null, "function_declaration": "def is_beautiful_subgrid(grid, top_row, bottom_row, left_col, right_col):", "function_name": "is_beautiful_subgrid", "parameter_list": "(grid, top_row, bottom_row, left_col, right_col)" }, { "docstring": null, "function_declaration": "def fin...
[ 1, 0, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_beautiful_subgrid(grid, top_row, bottom_row, left_col, right_col):\n for i in range(top_row, bottom_row + 1):\n if len(set(grid[i][left_col:r...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00032223", "row_id": 32223, "seed_ids": "[8106, 2810, 2067]" }
0.665036
Codeforces_32223
I
[ "is_beautiful_subgrid", "find_largest_beautiful_subgrid" ]
2
[ [ "find_largest_beautiful_subgrid", "is_beautiful_subgrid" ] ]
1
[]
false
[]
false
pytest
true
[]
true
a20618b453ad610119cff644a469a372c90285e8
f946a231598375690cb440313181cc7656beeee0
v1.0
instruct
Codeforces
Codeforces_32242_I
Tanya is organizing an online coding contest. She has n participants and each participant has a unique id from 1 to n. The contest consists of m problems, and each problem is scored differently. Each participant submits a solution to each problem and gets a score based on its correctness and efficiency. If a participa...
def find_winners(n, m, scores): total_scores = [sum(scores[i]) for i in range(n)] max_score = max(total_scores) winners = [i + 1 for i, score in enumerate(total_scores) if score == max_score] return winners # Function to parse the input and find the winners def determine_winners(n, m, score_matrix): ...
from solution import determine_winners def test_single_winner(): n, m = 3, 4 scores = [ [50, 30, 20, 10], [80, 60, 40, 0], [50, 30, 0, 60] ] assert determine_winners(n, m, scores) == [2] def test_multiple_winners(): n, m = 3, 4 scores = [ [50, 30, 20, 10], ...
[ { "docstring": null, "function_declaration": "def find_winners(n, m, scores):", "function_name": "find_winners", "parameter_list": "(n, m, scores)" }, { "docstring": null, "function_declaration": "def determine_winners(n, m, score_matrix):", "function_name": "determine_winners", ...
[ 1, 0, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def find_winners(n, m, scores):\n total_scores = [sum(scores[i]) for i in range(n)]\n max_score = max(total_scores)\n winners = [i + 1 for i, score i...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00032242", "row_id": 32242, "seed_ids": "[2758, 8052, 3170]" }
0.794469
Codeforces_32242
I
[ "find_winners", "determine_winners" ]
2
[ [ "determine_winners", "find_winners" ] ]
1
[]
false
[]
false
pytest
true
[]
true
de6385a7dee07b484b5c12c61d901e0db60bdc9d
d1d7518a8058d966d70ba7df90856a07d03ec537
v1.0
instruct
Codeforces
Codeforces_32307_I
In Berland, a special type of employee hierarchy is being used in their futuristic corporations. The corporations are organized as a tree, where each worker except the CEO (highest authority) has exactly one immediate supervisor. Given this hierarchy, workers tend to form different committee groups among themselves for...
def find_lca_and_depths(n, edges): from collections import defaultdict, deque tree = defaultdict(list) for a, b in edges: tree[a].append(b) tree[b].append(a) depth = [-1] * (n + 1) parent = [-1] * (n + 1) def bfs(): queue = deque([1]) depth[1] =...
def test_committee_group_size(): edges = [ (1, 2), (1, 3), (3, 4), (3, 5) ] queries = [ (2, 4), (2, 5), (4, 5) ] expected_result = [4, 4, 3] result = committee_group_size(5, edges, queries) assert result == expected_result, f"Expec...
[ { "docstring": null, "function_declaration": "def find_lca_and_depths(n, edges):", "function_name": "find_lca_and_depths", "parameter_list": "(n, edges)" }, { "docstring": null, "function_declaration": "def committee_group_size(n, edges, queries):", "function_name": "committee_group_...
[ 1, 0, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def find_lca_and_depths(n, edges):\n from collections import defaultdict, deque\n \n tree = defaultdict(list)\n for a, b in edges:\n tree[a...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00032307", "row_id": 32307, "seed_ids": "[260, 4416, 820]" }
0.592854
Codeforces_32307
I
[ "find_lca_and_depths", "committee_group_size" ]
2
[ [ "committee_group_size", "find_lca_and_depths" ] ]
1
[]
false
[]
false
pytest
false
[]
true
f5178e019e10af06ec9d454fb2cd414ded2fa13e
9c1203789e693830cc299506694d2938731f4224
v1.0
instruct
Codeforces
Codeforces_32334_I
A town has n intersections and m bidirectional roads between them. Each road has a length and a maximum travel speed allowed. The townspeople want to know the minimum time required to get from one intersection to another. Some intersections and roads are available or unavailable with respect to a particular time of the...
import heapq from collections import defaultdict, deque def min_travel_time(n, m, s, t, roads, c): # Graph representation graph = defaultdict(list) for u, v, l, z in roads: if z == c: # only consider roads available at the given time c graph[u].append((v, l)) graph[v].appen...
def test_min_travel_time_basic_case(): n = 5 m = 6 s = 1 t = 5 roads = [ (1, 2, 5, 3), (1, 3, 10, 14), (2, 4, 3, 3), (3, 5, 7, 14), (4, 5, 1, 3), (2, 3, 4, 3) ] c = 3 assert calculate_min_travel_time(n, m, s, t, roads, c) == 9 def test_min...
[ { "docstring": null, "function_declaration": "def min_travel_time(n, m, s, t, roads, c):", "function_name": "min_travel_time", "parameter_list": "(n, m, s, t, roads, c)" }, { "docstring": null, "function_declaration": "def calculate_min_travel_time(n, m, s, t, roads, c):", "function_...
[ 1, 1, 0 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "import heapq\n\ndef min_travel_time(n, m, s, t, roads, current_hour):\n graph = {i: [] for i in range(1, n + 1)}\n for u, v, l, z in roads:\n if ...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00032334", "row_id": 32334, "seed_ids": "[3251, 1985, 995]" }
0.725105
Codeforces_32334
I
[ "min_travel_time", "calculate_min_travel_time" ]
2
[ [ "calculate_min_travel_time", "min_travel_time" ] ]
1
[]
false
[]
false
pytest
false
[]
true
d7c6c202f4ec15c87181e443de3ade5a72c1fa8c
8413ccd5060ddcb96eb62b6da9811be2390242e2
v1.0
instruct
Codeforces
Codeforces_32383_I
A magical creature named Floop the wizard possesses an array of integers that has some mysterious properties. Floop noticed that the array can be split into contiguous subarrays, each with a prime sum. He wants your help to find at least one such way to split the array. Write a program to determine how the array can b...
def is_prime(number): if number < 2: return False for i in range(2, int(number ** 0.5) + 1): if number % i == 0: return False return True def find_min_prime_subarrays(n, arr): # Create a prefix sum array prefix_sum = [0] * (n + 1) for i in range(n): prefix_su...
from solution import find_min_prime_subarrays def test_example_cases(): assert find_min_prime_subarrays(5, [2, 3, 4, 6, 5]) == 3 def test_single_element_prime(): assert find_min_prime_subarrays(1, [2]) == 1 def test_single_element_non_prime(): assert find_min_prime_subarrays(1, [4]) == -1 def test_multi...
[ { "docstring": null, "function_declaration": "def is_prime(number):", "function_name": "is_prime", "parameter_list": "(number)" }, { "docstring": null, "function_declaration": "def find_min_prime_subarrays(n, arr):", "function_name": "find_min_prime_subarrays", "parameter_list": ...
[ 0, 0, 0, 0, 0, 1, 0, 0, 0, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(num):\n if num <= 1:\n return False\n if num <= 3:\n return True\n if num % 2 == 0 or num % 3 == 0:\n return False\...
trial_gpt4o_5
{ "original_instruction": "", "prompt_id": "00032383", "row_id": 32383, "seed_ids": "[7201, 7973, 6865]" }
0.602763
Codeforces_32383
I
[ "is_prime", "find_min_prime_subarrays" ]
2
[ [ "find_min_prime_subarrays", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
9e2318bf47d7ded96a69ba760fb9f0c185ba2e2f
b67366b53a6dc7cf488f5d896060ebeb0e50a4da
v1.0
instruct
Codeforces
Codeforces_32509_I
In a town where network connectivity is crucial, there are n computer nodes connected through a series of bi-directional wires. The network administrator wants to ensure the network is robust against failures. The network can be seen as an undirected graph where nodes represent computers and edges represent the wires. ...
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): rootX = find_parent(parent, x) rootY = find_parent(parent, y) if rootX != rootY: if rank[rootX] > rank[rootY]...
import pytest from solution import solve def test_example_case(): assert solve(6, 5, [(1, 2), (2, 3), (3, 4), (4, 5), (5, 6)], 3) == 2 def test_single_node(): assert solve(1, 0, [], 1) == 0 assert solve(1, 0, [], 2) == -1 def test_no_edges(): assert solve(4, 0, [], 4) == 0 assert solve(4, 0, [], ...
[ { "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...
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def find_minimum_wires_to_remove(n, m, edges, k):\n from collections import defaultdict\n \n graph = defaultdict(list)\n for u, v in edges:\n ...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00032509", "row_id": 32509, "seed_ids": "[1231, 4629, 119]" }
0.685692
Codeforces_32509
I
[ "find_parent", "union", "minimum_wires_to_remove", "solve" ]
4
[ [ "minimum_wires_to_remove", "find_parent" ], [ "minimum_wires_to_remove", "union" ], [ "solve", "minimum_wires_to_remove" ], [ "union", "find_parent" ] ]
4
[]
false
[]
false
pytest
true
[]
true
01c47c19b158faea989368d07bf13cdd09a7b3eb
2279a6df8467e8ecac1af6175a9742473bc297e6
v1.0
instruct
Codeforces
Codeforces_32590_I
You are given a binary tree of n nodes. Each node has a unique value from 1 to n. The target is to perform the following operations: 1. Rotate any subtree rooted at a node. 2. Retrieve the order of nodes in the tree when the nodes are traversed in pre-order. You need to determine the minimum number of rotations requi...
def build_tree(node_list, n): nodes = {i: [None, None] for i in range(1, n+1)} for node, left, right in node_list: if left != -1: nodes[node][0] = left if right != -1: nodes[node][1] = right return nodes def pre_order_traversal(tree, root): if root is None: ...
from solution import main def test_two_identical_trees(): t = 1 test_cases = [ (3, [(1, 2, 3), (2, -1, -1), (3, -1, -1)], [(1, 2, 3), (2, -1, -1), (3, -1, -1)]) ] result = main(t, test_cases) assert result == [0] def test_case_with_already_same_structure(): t = 1 test_...
[ { "docstring": null, "function_declaration": "def build_tree(node_list, n):", "function_name": "build_tree", "parameter_list": "(node_list, n)" }, { "docstring": null, "function_declaration": "def pre_order_traversal(tree, root):", "function_name": "pre_order_traversal", "paramet...
[ 0, 0, 0, 1, 0, 1, 0, 0 ]
2
hard
0.25
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "class TreeNode:\n def __init__(self, val):\n self.val = val\n self.left = None\n self.right = None\n\ndef build_tree(nodes):\n node...
trial_gpt4o_7
{ "original_instruction": "", "prompt_id": "00032590", "row_id": 32590, "seed_ids": "[3227, 7436, 1487]" }
0.600955
Codeforces_32590
I
[ "build_tree", "pre_order_traversal", "min_rotations_to_convert", "main" ]
4
[ [ "min_rotations_to_convert", "build_tree" ], [ "min_rotations_to_convert", "pre_order_traversal" ] ]
2
[]
false
[]
false
pytest
true
[]
true
387fb2adefc95a43480ab7c8631898eb30f8acea
e9e2a9b3640eb2b04531fae9b0441a0f7c22f045
v1.0
instruct
Codeforces
Codeforces_32629_I
In a small town, there is a park with n straight walking paths that intersect at different points. We can represent each path as a line segment on a 2D plane with endpoints (x1, y1) and (x2, y2). A path is considered "intersected" if there is at least one point on the path that intersects with any part of another path...
from itertools import combinations def ccw(A, B, C): return (C[1] - A[1]) * (B[0] - A[0]) > (B[1] - A[1]) * (C[0] - A[0]) def intersect(path1, path2): A, B = path1[:2], path1[2:] C, D = path2[:2], path2[2:] return ccw(A, C, D) != ccw(B, C, D) and ccw(A, B, C) != ccw(A, B, D) def count_intersected_pat...
def test_count_intersected_paths(): paths1 = [ [0, 0, 4, 4], [1, 4, 4, 1], [0, 4, 4, 0] ] assert count_intersected_paths(paths1) == 3 paths2 = [ [0, 0, 1, 1], [2, 2, 3, 3], [1, 0, 2, 3] ] assert count_intersected_paths(paths2) == 0 pa...
[ { "docstring": null, "function_declaration": "def ccw(A, B, C):", "function_name": "ccw", "parameter_list": "(A, B, C)" }, { "docstring": null, "function_declaration": "def intersect(path1, path2):", "function_name": "intersect", "parameter_list": "(path1, path2)" }, { "d...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def number_of_intersected_paths(n, paths):\n def direction(a, b, c):\n return (b[0] - a[0]) * (c[1] - a[1]) - (b[1] - a[1]) * (c[0] - a[0])\n\n d...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00032629", "row_id": 32629, "seed_ids": "[3660, 123, 6525]" }
0.664825
Codeforces_32629
I
[ "ccw", "intersect", "count_intersected_paths" ]
3
[ [ "count_intersected_paths", "intersect" ], [ "intersect", "ccw" ] ]
2
[]
false
[]
false
pytest
false
[]
true
d1090370ac2e5cabae309839b97e0739d08ac3bb
fec9bc65e98e743aa6100ef899595d6e07c065f5
v1.0
instruct
Codeforces
Codeforces_32700_I
Phoenix has made a bet with his friend Echo about the minimum cost required to connect cities with roads. There are $$$m$$$ cities and $$$n$$$ possible roads between certain pairs of cities, each road having a specific construction cost. The goal is to ensure that all cities are connected directly or indirectly to each...
def find(parent, i): if parent[i] == i: return i else: parent[i] = find(parent, parent[i]) return parent[i] def union(parent, rank, x, y): rootX = find(parent, x) rootY = find(parent, y) if rootX != rootY: if rank[rootX] > rank[rootY]: parent[rootY] ...
from solution import minimum_cost_to_connect_cities def test_case_1(): m = 4 n = 5 roads = [ [1, 2, 2], [2, 3, 3], [3, 4, 2], [4, 1, 4], [1, 3, 1] ] assert minimum_cost_to_connect_cities(m, n, roads) == 5 def test_case_2(): m = 4 n = 4 roads = [ ...
[ { "docstring": null, "function_declaration": "def find(parent, i):", "function_name": "find", "parameter_list": "(parent, i)" }, { "docstring": null, "function_declaration": "def union(parent, rank, x, y):", "function_name": "union", "parameter_list": "(parent, rank, x, y)" }, ...
[ 0, 1, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def minimum_cost_to_connect_cities(m, n, roads):\n from collections import defaultdict\n from heapq import heappop, heappush\n \n if n < m - 1:\n ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00032700", "row_id": 32700, "seed_ids": "[3951, 460, 3124]" }
0.727409
Codeforces_32700
I
[ "find", "union", "minimum_cost_to_connect_cities" ]
3
[ [ "minimum_cost_to_connect_cities", "find" ], [ "minimum_cost_to_connect_cities", "union" ], [ "union", "find" ] ]
3
[]
false
[]
false
pytest
true
[]
true
5a614e4d41f883b1a2728c42d45225c0303292ba
ec005396ace720c2e2fefa581a17cf86277d00ef
v1.0
instruct
Codeforces
Codeforces_32706_I
Alice is an avid gardener with a rectangular garden of size n x m. She has planted different types of flowers in each cell of her garden. Each type of flower is represented by a unique lowercase English letter. Due to the diversity of flowers, Alice's garden is visually striking, but she wants to create a flower bed th...
def is_palindrome(s): return s == s[::-1] def check_subgrid(garden, n, m, k): for i in range(n - k + 1): for j in range(m - k + 1): rows_palindrome = all(is_palindrome(garden[i + row][j:j + k]) for row in range(k)) cols_palindrome = all(is_palindrome(''.join(garden[i + col][j + ...
def test_example_case(): n, m, k = 5, 6, 3 garden = [ "abcdefgh", "ijklmnop", "qrstuvwx", "yzabcdef", "ghijklmn" ] assert find_palindrome_subgrid(n, m, k, garden) is None def test_single_cell_palindrome(): n, m, k = 1, 1, 1 garden = [ "a" ] ...
[ { "docstring": null, "function_declaration": "def is_palindrome(s):", "function_name": "is_palindrome", "parameter_list": "(s)" }, { "docstring": null, "function_declaration": "def check_subgrid(garden, n, m, k):", "function_name": "check_subgrid", "parameter_list": "(garden, n, ...
[ 0, 0, 1 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_palindrome(s):\n return s == s[::-1]\n\ndef check_k_palindrome_subgrid(garden, n, m, k):\n for i in range(n - k + 1):\n for j in range(m -...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00032706", "row_id": 32706, "seed_ids": "[3764, 6558, 5242]" }
0.717581
Codeforces_32706
I
[ "is_palindrome", "check_subgrid", "find_palindrome_subgrid" ]
3
[ [ "check_subgrid", "is_palindrome" ], [ "find_palindrome_subgrid", "check_subgrid" ] ]
2
[]
false
[]
false
pytest
false
[]
true
9c43443663de23f54777b3aed6bb4cf477a5e0b6
dd7fac430352a4608c83a69268b2dc369b77cabc
v1.0
instruct
Codeforces
Codeforces_32719_I
You are given a sequence of n integers. For an integer x in the sequence, its beauty is defined as the greatest common divisor (GCD) of all numbers in the sequence except x. You need to find and print the beauty of each number in the sequence. The first line of input contains an integer n (2 ≤ n ≤ 200000). The second ...
import math from functools import reduce def gcd(a, b): return math.gcd(a, b) def gcd_list(nums): return reduce(gcd, nums) def beauty_of_sequence(nums): n = len(nums) # If there are only two numbers, the beauty of each is the other number if n == 2: return [nums[1], nums[0]] ...
def test_beauty_of_sequence_case1(): assert beauty_of_sequence([12, 15, 18]) == [3, 6, 3] def test_beauty_of_sequence_case2(): assert beauty_of_sequence([2, 3, 4, 5]) == [1, 1, 1, 1] def test_beauty_of_sequence_case3(): assert beauty_of_sequence([10, 20, 30, 40]) == [10, 10, 10, 10] def test_beauty_of_se...
[ { "docstring": null, "function_declaration": "def gcd(a, b):", "function_name": "gcd", "parameter_list": "(a, b)" }, { "docstring": null, "function_declaration": "def gcd_list(nums):", "function_name": "gcd_list", "parameter_list": "(nums)" }, { "docstring": null, "fu...
[ 1, 0, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "from math import gcd\nfrom functools import reduce\n\ndef calculate_beauties(arr):\n n = len(arr)\n \n # Create prefix and suffix GCD arrays\n pre...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00032719", "row_id": 32719, "seed_ids": "[1404, 628, 5284]" }
0.659977
Codeforces_32719
I
[ "gcd", "gcd_list", "beauty_of_sequence" ]
3
[ [ "beauty_of_sequence", "gcd" ], [ "gcd_list", "gcd" ] ]
2
[]
false
[]
false
pytest
false
[]
true
8e87be9fcc1f0cd335421ee77351c968f5b8032a
ff248cf34d91f07bb5254d2a6364e29f4a2aefd3
v1.0
instruct
Codeforces
Codeforces_32728_I
Reza is a software engineer who has developed a passion for working with trees. He came across an interesting problem involving tree structures. Given a tree with `n` nodes, each node has a value assigned to it. Reza wants to know the maximum sum of values in any subtree of this tree. Can you help him solve this proble...
import sys sys.setrecursionlimit(200000) def dfs(u, parent, adj, values, max_sum): current_sum = values[u-1] for v in adj[u]: if v != parent: child_sum = dfs(v, u, adj, values, max_sum) current_sum += child_sum max_sum[0] = max(max_sum[0], current_sum) return current_sum...
from solution import maximum_subtree_sum def test_example_case(): assert maximum_subtree_sum(5, [1, 2, 3, -2, 5], [(1, 2), (1, 3), (2, 4), (2, 5)]) == 9 def test_all_negative_values(): assert maximum_subtree_sum(5, [-1, -2, -3, -2, -1], [(1, 2), (1, 3), (2, 4), (2, 5)]) == -1 def test_single_node(): asse...
[ { "docstring": null, "function_declaration": "def dfs(u, parent, adj, values, max_sum):", "function_name": "dfs", "parameter_list": "(u, parent, adj, values, max_sum)" }, { "docstring": null, "function_declaration": "def maximum_subtree_sum(n, values, edges):", "function_name": "maxi...
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def max_subtree_sum(n, node_values, edges):\n from collections import defaultdict\n \n # Build the adjacency list for the tree\n tree = defaultdic...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00032728", "row_id": 32728, "seed_ids": "[7750, 4065, 2610]" }
0.702979
Codeforces_32728
I
[ "dfs", "maximum_subtree_sum" ]
2
[ [ "maximum_subtree_sum", "dfs" ] ]
1
[]
false
[]
false
pytest
true
[]
true
8d44aa881211324b215dc3f5207ebdf229bb7cc2
766ca5386c679ae71c09af0ab7a16b79c74ef864
v1.0
instruct
Codeforces
Codeforces_32762_I
You are given an array `arr` of `n` integers and `q` queries. Each query consists of two integers `l` and `r`, and requires you to calculate the sum of the subarray from index `l` to index `r` (inclusive). You need to answer each query efficiently. The first line contains two integers `n` and `q` (1 ≤ n, q ≤ 200,000) ...
def prefix_sums(arr): """ Computes and returns the prefix sums for the given array. """ prefix = [0] * (len(arr) + 1) for i in range(len(arr)): prefix[i + 1] = prefix[i] + arr[i] return prefix def query_sum(prefix, l, r): """ Computes the sum of the subarray from index l to inde...
from solution import prefix_sums, query_sum, solve def test_prefix_sums(): arr = [1, 2, 3, 4, 5] prefix = prefix_sums(arr) assert prefix == [0, 1, 3, 6, 10, 15] def test_query_sum(): arr = [1, 2, 3, 4, 5] prefix = prefix_sums(arr) assert query_sum(prefix, 1, 3) == 6 assert query_sum(prefix...
[ { "docstring": "Computes and returns the prefix sums for the given array.", "function_declaration": "def prefix_sums(arr):", "function_name": "prefix_sums", "parameter_list": "(arr)" }, { "docstring": "Computes the sum of the subarray from index l to index r using the prefix sums.", "fun...
[ 0, 1, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def compute_prefix_sums(arr):\n \"\"\"\n Computes prefix sums for the input array.\n \"\"\"\n prefix_sums = [0] * (len(arr) + 1)\n for i in ran...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00032762", "row_id": 32762, "seed_ids": "[124, 1807, 3682]" }
0.680634
Codeforces_32762
I
[ "prefix_sums", "query_sum", "solve" ]
3
[ [ "solve", "prefix_sums" ], [ "solve", "query_sum" ] ]
2
[]
false
[]
false
pytest
true
[]
true
0df3d6a3ec6c53bdfd0069fc14d958fc469865c1
7a4ea5d1370aa56461800c6a23762121d7f557ee
v1.0
instruct
Codeforces
Codeforces_32786_I
You are given a weighted undirected graph with n nodes and m edges. Each node represents a city and each edge represents a road with a certain travel time between two cities. Each road has a specific positive integer weight representing the travel time. Your task is to split the cities into two groups such that the max...
import heapq def find_max_edge_in_mst(n, edges): """ Function to find the maximum weight of an edge that can be kept to achieve a minimum of maximum weight of edge in the group's Minimum Spanning Tree after splitting the cities. :param n: Number of cities (nodes) :param edges: List of edges ...
from solution import minimized_max_edge_weight def test_example_case(): n = 4 m = 5 edges = [ (1, 2, 3), (2, 3, 2), (3, 4, 4), (4, 1, 1), (2, 4, 5) ] result = minimized_max_edge_weight(n, m, edges) assert result == 3 def test_another_case(): n = 5 ...
[ { "docstring": "Function to find the maximum weight of an edge that can be kept \nto achieve a minimum of maximum weight of edge in the group's \nMinimum Spanning Tree after splitting the cities.\n\n:param n: Number of cities (nodes)\n:param edges: List of edges where each edge is represented as (u, v, w)\n:ret...
[ 0, 0, 0, 0, 0, 0, 1, 0, 0 ]
1
hard
0.111
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def find_min_max_edge_in_partition(n, m, edges):\n \"\"\"\n Finds the minimum possible value of the maximum edge within the same group after partitionin...
trial_gpt4o_7
{ "original_instruction": "", "prompt_id": "00032786", "row_id": 32786, "seed_ids": "[4742, 6847, 3087]" }
0.698195
Codeforces_32786
I
[ "find_max_edge_in_mst", "minimized_max_edge_weight" ]
2
[ [ "minimized_max_edge_weight", "find_max_edge_in_mst" ] ]
1
[]
false
[]
false
pytest
true
[]
true
c70f5a8067b52fe39c56a7d03c3a075fbafe79c8
2f1c59cd5ffd7573513b4fe3e67dcbe41af310ff
v1.0
instruct
Codeforces
Codeforces_32895_I
Santa's elves are busy organizing the workshop for the annual gift wrapping event. The workshop consists of a series of connected rooms, and each room has a certain number of presents stored in it. Santa wants to maximize efficiency by ensuring that all presents are easily accessible. Each room is represented as a nod...
import heapq def dijkstra(graph, start_nodes, n): distances = [float('inf')] * (n + 1) pq = [] for node in start_nodes: heapq.heappush(pq, (0, node)) distances[node] = 0 while pq: current_distance, current_node = heapq.heappop(pq) if current_distance >...
from solution import shortest_path_to_storage def test_example_case(): n = 5 q = 3 edges = [ (1, 2, 3), (1, 3, 2), (3, 4, 4), (2, 5, 6), (4, 5, 1) ] storage_rooms = [3, 5] wrapping_rooms = [2, 4] queries = [2, 4, 5] expected = [5, 1, 0] assert...
[ { "docstring": null, "function_declaration": "def dijkstra(graph, start_nodes, n):", "function_name": "dijkstra", "parameter_list": "(graph, start_nodes, n)" }, { "docstring": null, "function_declaration": "def shortest_path_to_storage(n, q, edges, storage_rooms, wrapping_rooms, queries)...
[ 1, 0, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "import heapq\n\ndef dijkstra(graph, start_nodes, n):\n distances = [float('inf')] * (n + 1)\n pq = []\n \n for node in start_nodes:\n heapq...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00032895", "row_id": 32895, "seed_ids": "[1966, 6387, 5977]" }
0.685389
Codeforces_32895
I
[ "dijkstra", "shortest_path_to_storage" ]
2
[ [ "shortest_path_to_storage", "dijkstra" ] ]
1
[]
false
[]
false
pytest
true
[]
true
35b1021edb9a2b7f622e18a0dc68fca97196a61e
191724bcda602fb2808ffa0fb61f5eb8b2652929
v1.0
instruct
Codeforces
Codeforces_32899_I
David is a computer science student and he is working on a project involving binary search trees (BST). For his project, he needs to frequently calculate the depth of a given node in a BST. The depth of a node in a BST is defined as the number of edges from the root to the node. Help David by writing a program that, g...
class TreeNode: def __init__(self, value): self.value = value self.left = None self.right = None def build_bst(data): nodes = {} for value, left, right in data: if value not in nodes: nodes[value] = TreeNode(value) if left != -1: if left not i...
def test_calc_bst_depth_basic(): input_data = [ "5", "10 5 15", "5 2 -1", "15 -1 20", "2 -1 -1", "20 -1 -1", "15" ] expected_output = 1 assert calc_bst_depth(input_data) == expected_output def test_calc_bst_depth_root(): input_data = [ ...
[]
[ 1, 1, 0 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_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_bst(data):\n ...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00032899", "row_id": 32899, "seed_ids": "[4111, 5317, 2152]" }
0.575655
Codeforces_32899
I
[ "build_bst", "find_depth", "bst_node_depth", "calc_bst_depth" ]
4
[ [ "bst_node_depth", "build_bst" ], [ "bst_node_depth", "find_depth" ], [ "calc_bst_depth", "bst_node_depth" ] ]
3
[]
false
[ "TreeNode" ]
true
pytest
false
[]
true
b99352fb735e57cdaa84be4a2cc51f467cdd774f
f62bc026015d7b353bc0c724c0206fbf296c9c4e
v1.0
instruct
Codeforces
Codeforces_32924_I
You are given an n-sided polygon in a 2D plane. The vertices of the polygon are provided in order, either clockwise or counterclockwise. A point is considered inside the polygon if it lies strictly inside, or on one of the edges. Given a list of m points, determine for each point if it is inside the polygon or not. Th...
def is_point_in_polygon(polygon, point): # Helper function for checking if a point is on a segment def on_segment(p, q, r): return (min(p[0], r[0]) <= q[0] <= max(p[0], r[0]) and min(p[1], r[1]) <= q[1] <= max(p[1], r[1])) # Helper function to find the orientation of the ordered tri...
from solution import is_point_in_polygon, process_polygon_and_points def test_is_point_in_polygon(): polygon = [(0, 0), (4, 0), (4, 4), (0, 4), (-1, 2)] point1 = (-1, 1) point2 = (2, 2) point3 = (4, 0) assert is_point_in_polygon(polygon, point1) == "OUTSIDE" assert is_point_in_polygon(polygon, ...
[ { "docstring": null, "function_declaration": "def is_point_in_polygon(polygon, point):", "function_name": "is_point_in_polygon", "parameter_list": "(polygon, point)" }, { "docstring": null, "function_declaration": "def process_polygon_and_points(n, m, vertices, points):", "function_n...
[ 0, 0, 1 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_point_on_segment(px, py, ax, ay, bx, by):\n \"\"\"\n Check if point (px, py) is on the segment from (ax, ay) to (bx, by).\n \"\"\"\n if min...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00032924", "row_id": 32924, "seed_ids": "[5696, 1758, 3143]" }
0.577241
Codeforces_32924
I
[ "is_point_in_polygon", "process_polygon_and_points" ]
2
[ [ "process_polygon_and_points", "is_point_in_polygon" ] ]
1
[]
false
[]
false
pytest
true
[]
true
5af9eaf78cb6f99987dfcf2f1a351b1c6c70e3a8
40009ffaf534e141e5aea442a570ad3474c93b0c
v1.0
instruct
Codeforces
Codeforces_33070_I
In an ancient kingdom, there is a highly advanced tree known for its exotic fruits. In this kingdom, they have a tradition of representing data in binary trees. Each node of the tree contains a non-negative integer value, and each tree has exactly one root node. For this particular tree, a unique ceremony is performed...
from collections import defaultdict def dfs(node, parent, tree, values, cache): # We initialize the two largest distances from current node to any leaf max1, max2 = 0, 0 # Iterate over all connected nodes for neighbor in tree[node]: if neighbor != parent: neighbor_max = dfs(neighbor...
import pytest from solution import max_path_strength def test_example_case(): n = 5 edges = [(1, 2), (1, 3), (3, 4), (3, 5)] node_values = [5, 8, 3, 7, 1] assert max_path_strength(n, edges, node_values) == 23 def test_small_tree(): n = 2 edges = [(1, 2)] node_values = [1, 2] assert max...
[ { "docstring": null, "function_declaration": "def dfs(node, parent, tree, values, cache):", "function_name": "dfs", "parameter_list": "(node, parent, tree, values, cache)" }, { "docstring": null, "function_declaration": "def max_path_strength(n, edges, node_values):", "function_name"...
[ 0, 0, 1 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "from collections import defaultdict, deque\n\ndef max_path_strength(n, edges, values):\n tree = defaultdict(list)\n for u, v in edges:\n tree[u]....
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00033070", "row_id": 33070, "seed_ids": "[3623, 2822, 2948]" }
0.666395
Codeforces_33070
I
[ "dfs", "max_path_strength" ]
2
[ [ "max_path_strength", "dfs" ] ]
1
[]
false
[]
false
pytest
true
[]
true
cac111eb700ba49a7534591238bcea6d9222916f
95740dd4d9877bb27252788907d4be80e7324e9c
v1.0
instruct
Codeforces
Codeforces_33094_I
Little Ada likes to play with strings and numbers. She came up with a sophisticated game that involves converting numbers into their Roman numeral representations and vice-versa. Roman numerals follow a special system and are composed of the following symbols with corresponding values: - `I` (1) - `V` (5) - `X` (10) -...
def int_to_roman(n): """Converts an integer to a Roman numeral.""" val = [ 1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1 ] syms = [ "M", "CM", "D", "CD", "C", "XC", "L", "XL", "X", "IX", "V", "IV", "I" ] roman_num = '...
from solution import convert def test_int_to_roman(): assert convert("INT_TO_ROMAN", 1) == "I" assert convert("INT_TO_ROMAN", 3999) == "MMMCMXCIX" assert convert("INT_TO_ROMAN", 58) == "LVIII" assert convert("INT_TO_ROMAN", 1994) == "MCMXCIV" assert convert("INT_TO_ROMAN", 944) == "CMXLIV" def tes...
[ { "docstring": "Converts an integer to a Roman numeral.", "function_declaration": "def int_to_roman(n):", "function_name": "int_to_roman", "parameter_list": "(n)" }, { "docstring": "Converts a Roman numeral to an integer.", "function_declaration": "def roman_to_int(s):", "function_na...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def int_to_roman(n):\n \"\"\"\n Converts an integer to a Roman numeral.\n \"\"\"\n val = [\n 1000, 900, 500, 400,\n 100, 90, 50, 40,...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00033094", "row_id": 33094, "seed_ids": "[7112, 1816, 2220]" }
0.639377
Codeforces_33094
I
[ "int_to_roman", "roman_to_int", "convert" ]
3
[ [ "convert", "int_to_roman" ], [ "convert", "roman_to_int" ] ]
2
[]
false
[]
false
pytest
true
[]
true
e8e7c151c8ec1f3a0f36f07f534f69a1ca50e7d4
75d6c77593d606c12f96da7ca0bd5931c052ab95
v1.0
instruct
Codeforces
Codeforces_33139_I
There are several places on the map linked by bidirectional roads in such a way that each place is reachable from every other place. You are given the description of the roads in the form of a weighted graph, where each road has a certain distance. You are a delivery person and need to deliver packages along a specifi...
import heapq def dijkstra(graph, start_node, n): """ Dijkstra's algorithm to find the shortest path from a start node to all other nodes. """ distances = [float('inf')] * (n + 1) distances[start_node] = 0 pq = [(0, start_node)] while pq: current_distance, current_node = heapq.heapp...
from solution import minimum_travel_distance def test_case_1(): n = 5 m = 6 k = 4 roads = [ (1, 2, 3), (1, 3, 5), (2, 3, 4), (2, 5, 6), (3, 4, 2), (4, 5, 1) ] sequence = [1, 3, 4, 5] assert minimum_travel_distance(n, m, k, roads, sequence) == ...
[ { "docstring": "Dijkstra's algorithm to find the shortest path from a start node to all other nodes.", "function_declaration": "def dijkstra(graph, start_node, n):", "function_name": "dijkstra", "parameter_list": "(graph, start_node, n)" }, { "docstring": null, "function_declaration": "d...
[ 0, 0, 1 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "import heapq\n\ndef dijkstra(graph, start, n):\n \"\"\"\n Computes the shortest path from the start node to all other nodes using Dijkstra's algorithm.\...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00033139", "row_id": 33139, "seed_ids": "[7978, 2493, 8121]" }
0.746528
Codeforces_33139
I
[ "dijkstra", "minimum_travel_distance" ]
2
[ [ "minimum_travel_distance", "dijkstra" ] ]
1
[]
false
[]
false
pytest
true
[]
true
05020e17a20c368a423e83a02957adf85e9db91e
e94a9c4b0aa2d0632c6e4e2ee3b8d190d1f9c983
v1.0
instruct
Codeforces
Codeforces_33146_I
You have an array of n integers and Q queries. For each query, you will be given two integers l and r, representing the 1-based indices of the array. You need to find the sum of the elements in the subarray from index l to index r (inclusive). The first line contains an integer n (1 ≤ n ≤ 100,000) — the number of elem...
def preprocess_array(array): """ Preprocess the array to create a prefix sum array. Parameters: array (list of int): The input array. Returns: list of int: The prefix sum array. """ prefix_sum = [0] * (len(array) + 1) for i in range(1, len(array) + 1): prefix_sum[i]...
from solution import preprocess_array, query_sum, process_queries def test_preprocess_array(): assert preprocess_array([1, 2, 3, 4, 5]) == [0, 1, 3, 6, 10, 15] def test_query_sum(): prefix_sum = [0, 1, 3, 6, 10, 15] assert query_sum(prefix_sum, 1, 3) == 6 assert query_sum(prefix_sum, 2, 4) == 9 as...
[ { "docstring": "Preprocess the array to create a prefix sum array.\n\nParameters:\narray (list of int): The input array.\n\nReturns:\nlist of int: The prefix sum array.", "function_declaration": "def preprocess_array(array):", "function_name": "preprocess_array", "parameter_list": "(array)" }, {...
[ 1, 1, 0 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def preprocess_array(arr):\n \"\"\"\n Preprocessing array to create prefix sums\n \"\"\"\n n = len(arr)\n prefix_sums = [0] * (n + 1)\n for ...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00033146", "row_id": 33146, "seed_ids": "[1980, 7218, 5023]" }
0.667784
Codeforces_33146
I
[ "preprocess_array", "query_sum", "process_queries" ]
3
[ [ "process_queries", "preprocess_array" ], [ "process_queries", "query_sum" ] ]
2
[ "process_queries" ]
false
[]
false
pytest
true
[]
true
af893c2e6ccc845fd2bde5ac33fa528dd33e51ef
38ce17bc2bd6c78025f98dda06e33dcfd65d2969
v1.0
instruct
Codeforces
Codeforces_33158_I
Farmer John has a rectangular field of N rows and M columns of cells. Each cell is either empty or has a fence. John wants to construct a chicken coop in the field. The coop must be a rectangular section of cells such that there are no fences within this section. Your task is to help John find the largest possible area...
def largest_coop_area(n, m, grid): # Initialize histogram height array heights = [0] * m max_area = 0 for row in grid: for col in range(m): heights[col] = heights[col] + 1 if row[col] == '.' else 0 max_area = max(max_area, max_histogram_area(heights)) return max_ar...
from solution import largest_coop_area def test_largest_coop_area_1(): n = 5 m = 6 grid = [ "....#.", "..##..", "......", ".#..#.", "##...." ] assert largest_coop_area(n, m, grid) == 6 def test_largest_coop_area_2(): n = 1 m = 1 grid = [ ...
[ { "docstring": null, "function_declaration": "def largest_coop_area(n, m, grid):", "function_name": "largest_coop_area", "parameter_list": "(n, m, grid)" }, { "docstring": null, "function_declaration": "def max_histogram_area(heights):", "function_name": "max_histogram_area", "pa...
[ 0, 0, 1 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def max_rectangle_area(N, M, field):\n def max_histogram_area(heights):\n stack = []\n max_area = 0\n index = 0\n \n whi...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00033158", "row_id": 33158, "seed_ids": "[3699, 5231, 3607]" }
0.575014
Codeforces_33158
I
[ "largest_coop_area", "max_histogram_area" ]
2
[ [ "largest_coop_area", "max_histogram_area" ] ]
1
[]
false
[]
false
pytest
true
[]
true
28bfbbd0c473d0c5fd1430b6e4f959ca5f8f24f2
10383eeb8b71f6ea6d5ca30273c373876a5ce027
v1.0
instruct
Codeforces
Codeforces_33162_I
Tracy has a rectangular grid of size $$$n \times m$$$. Each cell in the grid is either blocked or empty. Tracy can move from an empty cell to another empty cell horizontally or vertically. Due to an upcoming school project, Tracy has to place a set of computers in the grid. The requirement is that all computers must be...
def is_connected(grid, n, m): from collections import deque def bfs(start): visited = [[False] * m for _ in range(n)] queue = deque([start]) directions = [(-1, 0), (1, 0), (0, -1), (0, 1)] while queue: x, y = queue.popleft() for dx, dy in dir...
from solution import handle_input_output def test_example_1(): result = handle_input_output(4, 4, [ "....", ".#..", "..#.", "...." ]) assert result[0] == "YES" # Check the proper format of coordinates for i in range(1, len(result)): assert isinstance(result[i...
[ { "docstring": null, "function_declaration": "def is_connected(grid, n, m):", "function_name": "is_connected", "parameter_list": "(grid, n, m)" }, { "docstring": null, "function_declaration": "def place_computers(n, m, grid):", "function_name": "place_computers", "parameter_list"...
[ 0, 0, 1 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_valid_cell(x, y, n, m):\n return 0 <= x < n and 0 <= y < m\n\ndef dfs(grid, visited, x, y, n, m):\n direction_vectors = [(-1, 0), (1, 0), (0, -1)...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00033162", "row_id": 33162, "seed_ids": "[696, 947, 725]" }
0.759879
Codeforces_33162
I
[ "is_connected", "place_computers", "handle_input_output" ]
3
[ [ "handle_input_output", "place_computers" ], [ "place_computers", "is_connected" ] ]
2
[ "handle_input_output" ]
false
[]
false
pytest
true
[]
true
a0437ddb8c51fdef56c17c80b2b565c468bb1125
0762b5b3a9439ab55b7c82997bee431a8c5b5423
v1.0
instruct
Codeforces
Codeforces_33180_I
You are given an array of integers containing n (1 ≤ n ≤ 200,000) elements. You need to perform several queries on this array. Each query consists of two integers l and r (1 ≤ l ≤ r ≤ n), and you have to calculate the sum of the elements in the array from index l to index r, inclusive. To handle these queries efficien...
def preprocess_array(arr): """ Preprocess the array to create prefix sums. """ n = len(arr) prefix_sums = [0] * (n + 1) for i in range(1, n + 1): prefix_sums[i] = prefix_sums[i-1] + arr[i-1] return prefix_sums def range_sum(prefix_sums, l, r): """ Calculate the sum of elemen...
def test_preprocess_array(): arr = [1, 2, 3, 4, 5] expected = [0, 1, 3, 6, 10, 15] assert preprocess_array(arr) == expected def test_range_sum(): prefix_sums = preprocess_array([1, 2, 3, 4, 5]) assert range_sum(prefix_sums, 1, 3) == 6 assert range_sum(prefix_sums, 2, 4) == 9 assert range_su...
[ { "docstring": "Preprocess the array to create prefix sums.", "function_declaration": "def preprocess_array(arr):", "function_name": "preprocess_array", "parameter_list": "(arr)" }, { "docstring": "Calculate the sum of elements in the range [l, r] using prefix sums.", "function_declarati...
[ 1, 1 ]
2
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def preprocess(arr):\n \"\"\"\n Preprocess the array to create a prefix sum array.\n \n Parameters:\n arr (list): List of integers.\n \n ...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00033180", "row_id": 33180, "seed_ids": "[3348, 2112, 4996]" }
0.672078
Codeforces_33180
I
[ "preprocess_array", "range_sum", "process_queries" ]
3
[ [ "process_queries", "preprocess_array" ], [ "process_queries", "range_sum" ] ]
2
[ "process_queries" ]
false
[]
false
pytest
false
[]
true
fec5ecc65289b0e7be202d1eb072d8d1309bd684
392d76138508df9268a418c8a37d4d23f20558d1
v1.0
instruct
Codeforces
Codeforces_33190_I
A new gallery has recently opened in Metropolis. The gallery consists of a series of rooms connected by passageways, represented as a weighted undirected graph. Each room is a node, and each passageway is an edge with a weight corresponding to the time required to traverse it. There are h-hallways in the gallery, and e...
import heapq def find(parent, x): if parent[x] != x: parent[x] = find(parent, parent[x]) return parent[x] 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 r...
from solution import minimum_cost_to_unblock def test_all_passageways_open(): n = 4 h = 3 hallways = [(1, 2, 1), (2, 3, 2), (3, 4, 1)] m = 0 unblockable_hallways = [] assert minimum_cost_to_unblock(n, h, hallways, m, unblockable_hallways) == 4 def test_some_blocked_passageways(): n = 4 ...
[ { "docstring": null, "function_declaration": "def find(parent, x):", "function_name": "find", "parameter_list": "(parent, x)" }, { "docstring": null, "function_declaration": "def union(parent, rank, x, y):", "function_name": "union", "parameter_list": "(parent, rank, x, y)" }, ...
[ 1, 0, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "import heapq\n\ndef find(parent, x):\n if parent[x] != x:\n parent[x] = find(parent, parent[x])\n return parent[x]\n\ndef union(parent, rank, x, ...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00033190", "row_id": 33190, "seed_ids": "[860, 4260, 2665]" }
0.691749
Codeforces_33190
I
[ "find", "union", "minimum_cost_to_unblock" ]
3
[ [ "minimum_cost_to_unblock", "find" ], [ "minimum_cost_to_unblock", "union" ], [ "union", "find" ] ]
3
[]
false
[]
false
pytest
true
[]
true
4d5cf1ba0442631728df2b40ef299ca98d02e92d
372580d70cc404fe20dd29e34ae59ec19c7e2844
v1.0
instruct
Codeforces
Codeforces_33200_I
A company has a distributed system with numerous servers interconnected in a network. Each server can communicate with any other server directly or indirectly through other servers. A common issue faced in the system is determining whether any two servers are connected directly or indirectly, i.e., they belong to the s...
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]...
from solution import same_component def test_same_component_1(): n, m = 6, 5 edges = [(1, 2), (2, 3), (4, 5), (5, 6), (3, 4)] queries = [(1, 3), (2, 4), (5, 6)] assert same_component(n, m, edges, queries) == ["YES", "YES", "YES"] def test_same_component_2(): n, m = 5, 4 edges = [(1, 2), (2, 3)...
[ { "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 ]
2
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_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 union(...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00033200", "row_id": 33200, "seed_ids": "[2128, 445, 3446]" }
0.675981
Codeforces_33200
I
[ "find_parent", "union", "same_component" ]
3
[ [ "same_component", "find_parent" ], [ "same_component", "union" ], [ "union", "find_parent" ] ]
3
[]
false
[]
false
pytest
true
[]
true
6a77ff514be36d3ee29f3794278dd2390b45a210
ae02e30b526832327d9165d8daf300fa28951471
v1.0
instruct
Codeforces
Codeforces_33205_I
ByteLandian scientists have recently discovered a new numeric representation system they call "Bit Fraction System". In this system, each number is represented as a sequence of bits, but instead of each bit representing an integral power of 2 (like in regular binary), they represent fractional powers of 2. For example...
def float_to_int_binary(n): """ Converts the integer part of the float to binary. """ if n == 0: return "0" result = "" while n > 0: result = str(n % 2) + result n = n // 2 return result def fraction_to_binary(fraction): """ Converts the fraction part of the ...
from solution import float_to_bit_fraction def test_float_to_bit_fraction(): assert float_to_bit_fraction(10.25) == "1010.01" assert float_to_bit_fraction(5.5) == "101.1" assert float_to_bit_fraction(0.75) == "0.11" assert float_to_bit_fraction(0.5) == "0.1" assert float_to_bit_fraction(3.75) == "1...
[ { "docstring": "Converts the integer part of the float to binary.", "function_declaration": "def float_to_int_binary(n):", "function_name": "float_to_int_binary", "parameter_list": "(n)" }, { "docstring": "Converts the fraction part of the float to binary.", "function_declaration": "def ...
[ 0, 1, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def float_to_bit_fraction(x):\n \"\"\"\n Converts a floating-point number to its representation in the Bit Fraction System.\n \n Args:\n x (flo...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00033205", "row_id": 33205, "seed_ids": "[5934, 1945, 6177]" }
0.593595
Codeforces_33205
I
[ "float_to_int_binary", "fraction_to_binary", "float_to_bit_fraction" ]
3
[ [ "float_to_bit_fraction", "float_to_int_binary" ], [ "float_to_bit_fraction", "fraction_to_binary" ] ]
2
[]
false
[]
false
pytest
true
[]
true
52158556bc2f34d746c0151d1f19743503b51f36
26f099cef220c221903c765f2dde691dc658907c
v1.0
instruct
Codeforces
Codeforces_33219_I
Given an undirected graph with n nodes and m edges, determine if it is possible to color the graph using exactly three colors such that no two adjacent nodes share the same color. If it is possible, output one such coloring; otherwise, output "No." The first line of input contains two integers n and m (1 ≤ n ≤ 1000, 0...
def is_bipartite(graph, n): color = [-1] * n for start in range(n): if color[start] == -1: queue = [start] color[start] = 0 while queue: node = queue.pop(0) for neighbor in graph[node]: if color[nei...
from solution import three_color_graph def test_example_case(): n = 4 edges = [(1, 2), (1, 3), (1, 4), (2, 3), (3, 4)] result = three_color_graph(n, edges) assert result == "No" def test_bipartite_graph(): n = 4 edges = [(1, 2), (2, 3), (3, 4), (4, 1)] result = three_color_graph(n, edges) ...
[ { "docstring": null, "function_declaration": "def is_bipartite(graph, n):", "function_name": "is_bipartite", "parameter_list": "(graph, n)" }, { "docstring": null, "function_declaration": "def three_color_graph(n, edges):", "function_name": "three_color_graph", "parameter_list": ...
[ 0, 0, 0, 1, 0 ]
1
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_three_colorable(n, m, edges):\n from collections import deque\n\n graph = [[] for _ in range(n + 1)]\n\n for u, v in edges:\n graph[u]....
trial_gpt4o_3
{ "original_instruction": "", "prompt_id": "00033219", "row_id": 33219, "seed_ids": "[6914, 4621, 6045]" }
0.595926
Codeforces_33219
I
[ "is_bipartite", "three_color_graph", "process_input" ]
3
[ [ "process_input", "three_color_graph" ], [ "three_color_graph", "is_bipartite" ] ]
2
[ "process_input" ]
false
[]
false
pytest
true
[]
true
bd9d5a82dc15daf61f9577b1472239a845696173
4f742642eecfc26b62cf9d760b195c412315b10a
v1.0
instruct
Codeforces
Codeforces_33315_I
The city of Graphland has a unique railway system where each road connecting two cities is bidirectional and has an associated cost. The residents of Graphland are interested in making the railway system more efficient. The mayor has proposed a new project where he plans to connect all cities with the minimal possible...
def find(parent, i): if parent[i] == i: return i return find(parent, parent[i]) def union(parent, rank, x, y): root_x = find(parent, x) root_y = find(parent, y) if rank[root_x] < rank[root_y]: parent[root_x] = root_y elif rank[root_x] > rank[root_y]: parent[root_y] ...
def test_solution(): # Test case 1 n = 4 m = 5 roads = [ (1, 2, 1), (2, 3, 2), (3, 4, 3), (4, 1, 4), (1, 3, 5) ] assert minimal_cost_to_connect_cities(n, m, roads) == 6 # Test case 2: Minimum edge case n = 2 m = 1 roads = [ (1, 2, ...
[ { "docstring": null, "function_declaration": "def find(parent, i):", "function_name": "find", "parameter_list": "(parent, i)" }, { "docstring": null, "function_declaration": "def union(parent, rank, x, y):", "function_name": "union", "parameter_list": "(parent, rank, x, y)" }, ...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def find(parent, i):\n if parent[i] == i:\n return i\n return find(parent, parent[i])\n\ndef union(parent, rank, x, y):\n xroot = find(parent,...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00033315", "row_id": 33315, "seed_ids": "[6115, 7482, 6967]" }
0.791881
Codeforces_33315
I
[ "find", "union", "kruskal", "minimal_cost_to_connect_cities" ]
4
[ [ "kruskal", "find" ], [ "kruskal", "union" ], [ "minimal_cost_to_connect_cities", "kruskal" ], [ "union", "find" ] ]
4
[]
false
[]
false
pytest
false
[]
true
7e864174b4b4695be49c6fcad8b437a33637db52
db2d1b19e7b93defba1efe66b5e1113c2e6167ca
v1.0
instruct
Codeforces
Codeforces_33336_I
Dylan loves to collect gemstones. Each gemstone is characterized by a unique color and size. A gemstone's color is represented by an integer and its size by a floating-point number. Dylan wants to display his gemstones in a special order in his display case: he wants to group gemstones of the same color together and s...
def sort_gemstones(gemstones): """ Sorts the gemstones by color in ascending order and by size in descending order within each color. """ gemstones.sort(key=lambda x: (x[0], -x[1])) return gemstones def read_and_process_input(input_list): """ Reads the gemstone data from input_list, sorts t...
def test_sort_gemstones(): input_list = [ "4", "1 1.0", "2 2.5", "1 0.5", "2 3.0" ] expected_output = [ "1 1.00", "1 0.50", "2 3.00", "2 2.50", ] sorted_gemstones = read_and_process_input(input_list) formatted_...
[ { "docstring": "Sorts the gemstones by color in ascending order and by size in descending order within each color.", "function_declaration": "def sort_gemstones(gemstones):", "function_name": "sort_gemstones", "parameter_list": "(gemstones)" }, { "docstring": "Reads the gemstone data from in...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def sort_gemstones(gemstones):\n \"\"\"\n Sorts the gemstones first by color (ascending) and then by size within each color (descending).\n \n Arg...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00033336", "row_id": 33336, "seed_ids": "[5706, 4048, 7499]" }
0.565663
Codeforces_33336
I
[ "sort_gemstones", "read_and_process_input", "format_output" ]
3
[ [ "read_and_process_input", "sort_gemstones" ] ]
1
[ "format_output" ]
false
[]
false
pytest
false
[]
true
6fbcc8a4ab6b6d2fe5b287ff1daf6b18d906afb9
a605d59b9b61aaf3d69d1001a080dc57be0bfec8
v1.0
instruct
Codeforces
Codeforces_33358_I
Consider a grid with $$$n$$$ rows and $$$m$$$ columns. Each cell in the grid can be either empty ('.') or occupied by an obstacle ('#'). You are given the starting position of a robot in the grid and the goal position it needs to reach. The robot can move up, down, left, or right, but it can't move through obstacles. Y...
from collections import deque def is_valid_position(x, y, n, m, grid, visited): return 0 <= x < n and 0 <= y < m and grid[x][y] == '.' and not visited[x][y] def minimum_moves(grid, n, m, start, goal): start = (start[0] - 1, start[1] - 1) goal = (goal[0] - 1, goal[1] - 1) if grid[start[0]][start[1...
def test_minimum_moves(): test_cases = [ (1, [( 3, 3, ["...", ".#.", "..."], (1, 1), (3, 3) )]), (1, [( 3, 3, ["...", "###", "..."], (1, 1), (3, 3) )]), (1, [( 4, 4, ...
[ { "docstring": null, "function_declaration": "def is_valid_position(x, y, n, m, grid, visited):", "function_name": "is_valid_position", "parameter_list": "(x, y, n, m, grid, visited)" }, { "docstring": null, "function_declaration": "def minimum_moves(grid, n, m, start, goal):", "func...
[ 0, 0, 1 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "from collections import deque\n\ndef minimum_moves(grid, n, m, start, goal):\n def is_valid(x, y):\n return 0 <= x < n and 0 <= y < m and grid[x][y]...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00033358", "row_id": 33358, "seed_ids": "[2556, 7048, 763]" }
0.794403
Codeforces_33358
I
[ "is_valid_position", "minimum_moves", "process_test_cases" ]
3
[ [ "minimum_moves", "is_valid_position" ], [ "process_test_cases", "minimum_moves" ] ]
2
[ "process_test_cases" ]
false
[]
false
pytest
false
[]
true
048d1ea514ab86ddf3d07c2feed4133500c61702
5d3dc866bf03a401382d1566e4f243dc4a867703
v1.0
instruct
Codeforces
Codeforces_33385_I
You are given an array of n integers, and you need to perform q queries on the array. Each query contains two integers l and r (1-indexed), and you need to find the sum of all prime numbers in the subarray from index l to index r. Input: - The first line of input contains two integers n and q (1 ≤ n, q ≤ 100000). - Th...
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_primes_in_subarray(arr, l, r): ...
from solution import is_prime, sum_of_primes_in_subarray, process_queries def test_is_prime(): assert is_prime(2) assert is_prime(3) assert not is_prime(4) assert is_prime(5) assert not is_prime(1) assert is_prime(97) assert not is_prime(99) def test_sum_of_primes_in_subarray(): arr = ...
[ { "docstring": null, "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": null, "function_declaration": "def sum_of_primes_in_subarray(arr, l, r):", "function_name": "sum_of_primes_in_subarray", "parameter_list": "(arr...
[ 0, 1, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def sieve_of_eratosthenes(limit):\n \"\"\"\n Generates a list of prime numbers up to the given limit using the Sieve of Eratosthenes.\n \"\"\"\n i...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00033385", "row_id": 33385, "seed_ids": "[7374, 8176, 6239]" }
0.645411
Codeforces_33385
I
[ "is_prime", "sum_of_primes_in_subarray", "process_queries" ]
3
[ [ "process_queries", "sum_of_primes_in_subarray" ], [ "sum_of_primes_in_subarray", "is_prime" ] ]
2
[ "process_queries" ]
false
[]
false
pytest
true
[]
true
27274ca03d1adcee04cf4c1ae91bada3bd120f8e
50acb04a44eda64bff7461bcdfc40a0faaeb980f
v1.0
instruct
Codeforces
Codeforces_33472_I
A farmer has a rectangular field divided into an n x m grid of unit squares. Each unit square can either be fertile or infertile, and the farmer wants to find the largest rectangular subgrid that is fully fertile so that he can plant his crops effectively. You are given a binary matrix of size n x m, where a 0 represe...
def largest_rectangle_area(matrix): if not matrix: return 0 n = len(matrix) m = len(matrix[0]) heights = [0] * m max_area = 0 for i in range(n): for j in range(m): if matrix[i][j] == '1': heights[j] += 1 else: heights...
def test_largest_rectangle_area(): matrix = [ ['1', '0', '1', '0', '0'], ['1', '0', '1', '1', '1'], ['1', '1', '1', '1', '1'], ['1', '0', '0', '1', '0'] ] assert largest_rectangle_area(matrix) == 6 def test_largest_rectangle_area_single_row(): matrix = [['1', '1', '1', '...
[ { "docstring": null, "function_declaration": "def largest_rectangle_area(matrix):", "function_name": "largest_rectangle_area", "parameter_list": "(matrix)" }, { "docstring": null, "function_declaration": "def largest_histogram_area(heights):", "function_name": "largest_histogram_area...
[ 1, 0, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def largest_rectangle_area(matrix):\n if not matrix:\n return 0\n\n n = len(matrix)\n m = len(matrix[0])\n \n heights = [0] * m\n max...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00033472", "row_id": 33472, "seed_ids": "[7077, 5625, 1396]" }
0.684771
Codeforces_33472
I
[ "largest_rectangle_area", "largest_histogram_area" ]
2
[ [ "largest_rectangle_area", "largest_histogram_area" ] ]
1
[]
false
[]
false
pytest
false
[]
true
4ddd54be4fc8fb544c453af7f0542d9bba934b3a
5ba4f7558491a6b97e1a3c29491071695583a437
v1.0
instruct
Codeforces
Codeforces_33528_I
Alyssa loves solving problems with arrays. Recently, she came across a new challenge involving the maximum subsequence sum in circular arrays. A circular array is an array where the end of the array wraps around to the beginning of the array. Alyssa's goal is to find the maximum sum of any subsequence in a circular arr...
def max_subsequence_sum_circular(n, a): """ Determines the maximum possible sum of any subsequence in the circular array. Parameters: n (int): Length of the array. a (list): List of n integers representing the circular array. Returns: int: The maximum sum of any subsequence in the circ...
def test_max_subsequence_sum_circular_basic(): assert max_subsequence_sum_circular(5, [5, -3, 5]) == 10 def test_max_subsequence_sum_circular_single_element(): assert max_subsequence_sum_circular(1, [7]) == 7 assert max_subsequence_sum_circular(1, [-5]) == -5 def test_max_subsequence_sum_circular_all_nega...
[ { "docstring": "Determines the maximum possible sum of any subsequence in the circular array.\n\nParameters:\nn (int): Length of the array.\na (list): List of n integers representing the circular array.\n\nReturns:\nint: The maximum sum of any subsequence in the circular array.", "function_declaration": "de...
[ 0, 0, 0, 0, 0, 0, 1, 0, 1, 0 ]
2
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def max_subsequence_sum_circular(array):\n def kadane(arr):\n max_current = max_global = arr[0]\n for num in arr[1:]:\n max_curren...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00033528", "row_id": 33528, "seed_ids": "[1125, 452, 1897]" }
0.660551
Codeforces_33528
I
[ "max_subsequence_sum_circular", "max_subsequence_sum" ]
2
[ [ "max_subsequence_sum_circular", "max_subsequence_sum" ] ]
1
[]
false
[]
false
pytest
false
[]
true
5902e71e4b7641be3605d8091d8f6fdd88d64d88
e3b6b1a0af187ddc94d96b4c4cc032ddca91035f
v1.0
instruct
Codeforces
Codeforces_33559_I
Mina is working on a project that involves square matrices of integers. She needs to find the largest sum of elements in any contiguous submatrix within a given matrix. A submatrix is defined by selecting a rectangular section from the matrix, and its sum is the sum of all the elements within that rectangle. The first...
def max_sum_submatrix(matrix): """ Returns the maximum sum of any contiguous submatrix in the given 2D matrix. """ n = len(matrix) m = len(matrix[0]) max_sum = float('-inf') # Iterate over every possible combination of top and bottom row for top in range(n): temp = [0] * m ...
from solution import max_sum_submatrix, kadane def test_single_element_matrix(): assert max_sum_submatrix([[5]]) == 5 assert max_sum_submatrix([[-5]]) == -5 def test_all_negative_matrix(): matrix = [ [-1, -2, -3], [-4, -5, -6], [-7, -8, -9] ] assert max_sum_submatrix(matrix...
[ { "docstring": "Returns the maximum sum of any contiguous submatrix in the given 2D matrix.", "function_declaration": "def max_sum_submatrix(matrix):", "function_name": "max_sum_submatrix", "parameter_list": "(matrix)" }, { "docstring": "Helper function to find the maximum sum subarray using...
[ 1, 0, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def max_sum_submatrix(matrix):\n \"\"\"\n Finds the maximum sum of any contiguous submatrix within the given matrix.\n \"\"\"\n def kadane(arr):\n...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00033559", "row_id": 33559, "seed_ids": "[1975, 691, 5363]" }
0.615465
Codeforces_33559
I
[ "max_sum_submatrix", "kadane" ]
2
[ [ "max_sum_submatrix", "kadane" ] ]
1
[]
false
[]
false
pytest
true
[]
true
9f41468ca49b91f39694b26698df2b7d7d6b0f80
453b01ad06e3ff644196721f33f355008845bb9c
v1.0
instruct
Codeforces
Codeforces_33565_I
You are given a grid with `n` rows and `m` columns. Each cell in the grid is either empty ('.') or blocked by an obstacle ('#'). You are initially situated at the top-left cell (1, 1) and you need to reach the bottom-right cell (n, m). You can move up, down, left, or right, but you cannot move through obstacles. Howev...
def is_reachable(grid): from collections import deque n = len(grid) m = len(grid[0]) if grid[0][0] == '#' or grid[n-1][m-1] == '#': return "NO" def in_bound(x, y): return 0 <= x < n and 0 <= y < m and grid[x][y] == '.' def bfs(): queue = deque([(0, 0)]) ...
def test_is_reachable(): assert solve("4 4\n....\n..#.\n.#..\n....") == "YES" assert solve("3 3\n.#.\n###\n.#.") == "NO" assert solve("1 1\n.") == "YES" assert solve("2 2\n..\n.#") == "NO" assert solve("3 3\n...\n.#.\n...") == "YES" assert solve("3 4\n....\n####\n....") == "NO" if __name__ == '...
[ { "docstring": null, "function_declaration": "def is_reachable(grid):", "function_name": "is_reachable", "parameter_list": "(grid)" }, { "docstring": null, "function_declaration": "def solve(input_data):", "function_name": "solve", "parameter_list": "(input_data)" }, { "d...
[ 0, 0, 0, 0, 0, 0, 0, 1, 1 ]
2
hard
0.222
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_path_possible(n, m, grid):\n from collections import deque\n\n def in_bounds(x, y):\n return 0 <= x < n and 0 <= y < m\n\n def bfs():\n...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00033565", "row_id": 33565, "seed_ids": "[4466, 7232, 5657]" }
0.802906
Codeforces_33565
I
[ "is_reachable", "solve" ]
2
[ [ "solve", "is_reachable" ] ]
1
[]
false
[]
false
pytest
false
[]
true
d12bb804430ffa4b169d0ec308e5be35ebb00fdf
877db31690c5f0da4f32ad4271662ce13223e2a3
v1.0
instruct
Codeforces
Codeforces_33569_I
Given a set of points in a 2D plane, determine the number of points that are on the convex hull. The convex hull of a set of points is the smallest convex polygon that can enclose all the points. The first line of input contains an integer `n` (3 ≤ n ≤ 10^4) — the number of points. Each of the next `n` lines contains ...
def cross_product(o, a, b): """ Returns the cross product of vector OA and OB A positive cross product indicates a counter-clockwise turn A negative cross product indicates a clockwise turn A zero cross product indicates collinearity """ return (a[0] - o[0]) * (b[1] - o[1]) - (a[1] - o[1]) *...
from solution import number_of_points_on_convex_hull def test_convex_hull_example(): assert number_of_points_on_convex_hull(5, [(0, 0), (2, 2), (2, 0), (0, 2), (1, 1)]) == 4 def test_convex_hull_triangle(): assert number_of_points_on_convex_hull(3, [(0, 0), (1, 1), (2, 0)]) == 3 def test_convex_hull_square()...
[ { "docstring": "Returns the cross product of vector OA and OB\nA positive cross product indicates a counter-clockwise turn\nA negative cross product indicates a clockwise turn\nA zero cross product indicates collinearity", "function_declaration": "def cross_product(o, a, b):", "function_name": "cross_pr...
[ 0, 1, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def convex_hull(points):\n def orientation(p, q, r):\n return (q[1] - p[1]) * (r[0] - q[0]) - (q[0] - p[0]) * (r[1] - q[1])\n\n points = sorted(p...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00033569", "row_id": 33569, "seed_ids": "[7267, 3370, 1222]" }
0.563272
Codeforces_33569
I
[ "cross_product", "convex_hull", "number_of_points_on_convex_hull" ]
3
[ [ "convex_hull", "cross_product" ], [ "number_of_points_on_convex_hull", "convex_hull" ] ]
2
[]
false
[]
false
pytest
true
[]
true
a848d6d5a9970d0d686543d20d7dbe788367810c
ab72c0542c10d63abffeca6b12023d02e2912aca
v1.0
instruct
Codeforces
Codeforces_33590_I
Alina is a math enthusiast who loves working with prime numbers and Fibonacci sequences. One day, she became curious about an interesting problem involving both concepts. The problem is as follows: Given an integer n (1 ≤ n ≤ 10^6), find the smallest prime number p such that the nth Fibonacci number is divisible by p....
import math # Helper function to check if a number is prime def is_prime(n): if n <= 1: return False if n <= 3: return True if n % 2 == 0 or n % 3 == 0: return False i = 5 while i * i <= n: if n % i == 0 or n % (i + 2) == 0: return False i += 6 ...
from solution import is_prime, fibonacci, smallest_prime_divisor_of_fibonacci def test_is_prime(): assert is_prime(2) == True assert is_prime(3) == True assert is_prime(4) == False assert is_prime(5) == True assert is_prime(11) == True assert is_prime(12) == False def test_fibonacci(): ass...
[ { "docstring": null, "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": null, "function_declaration": "def fibonacci(n):", "function_name": "fibonacci", "parameter_list": "(n)" }, { "docstring": null, "fu...
[ 0, 0, 0, 0, 0, 0, 0, 1, 0, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(num):\n if num <= 1:\n return False\n if num <= 3:\n return True\n if num % 2 == 0 or num % 3 == 0:\n return False\...
trial_gpt4o_7
{ "original_instruction": "", "prompt_id": "00033590", "row_id": 33590, "seed_ids": "[5763, 5685, 5446]" }
0.679575
Codeforces_33590
I
[ "is_prime", "fibonacci", "smallest_prime_divisor_of_fibonacci" ]
3
[ [ "smallest_prime_divisor_of_fibonacci", "fibonacci" ], [ "smallest_prime_divisor_of_fibonacci", "is_prime" ] ]
2
[]
false
[]
false
pytest
true
[]
true
170ae0a392e9aef19d24f3c759c19b5bdc07ff7e
386bc0b9cdbb533d6979ca4f57d5a7f4051744df
v1.0
instruct
Codeforces
Codeforces_33613_I
In a certain kingdom, there are $$$n$$$ cities connected by exactly $$$n - 1$$$ roads. Each road connects two cities and can be traversed in both directions. All cities are connected directly or indirectly. The kingdom is planning to build some additional roads such that any two cities are directly connected by at most...
from collections import deque def bfs_farthest_node(start_node, n, graph): visited = [-1] * n visited[start_node] = 0 queue = deque([start_node]) farthest_node = start_node max_distance = 0 while queue: current = queue.popleft() current_distance = visited[current] for ...
from solution import minimum_maximum_distance def test_case_1(): n = 5 roads = [(1, 2), (1, 3), (2, 4), (3, 5)] assert minimum_maximum_distance(n, roads) == 2 def test_case_2(): n = 4 roads = [(1, 2), (1, 3), (3, 4)] assert minimum_maximum_distance(n, roads) == 2 def test_case_3(): n = 6 ...
[ { "docstring": null, "function_declaration": "def bfs_farthest_node(start_node, n, graph):", "function_name": "bfs_farthest_node", "parameter_list": "(start_node, n, graph)" }, { "docstring": null, "function_declaration": "def find_tree_diameter(n, graph):", "function_name": "find_tr...
[ 0, 1, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "from collections import deque, defaultdict\n\ndef bfs_diameter(start, adj):\n \"\"\"\n Perform BFS to find the furthest node from start and its distance...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00033613", "row_id": 33613, "seed_ids": "[2170, 7382, 790]" }
0.79789
Codeforces_33613
I
[ "bfs_farthest_node", "find_tree_diameter", "minimum_maximum_distance" ]
3
[ [ "find_tree_diameter", "bfs_farthest_node" ], [ "minimum_maximum_distance", "find_tree_diameter" ] ]
2
[]
false
[]
false
pytest
true
[]
true
0a3ab3c4bb07b017caf07fa85ba0eded171c1922
e894f465629906c8da816aff5351e24534766854
v1.0
instruct
Codeforces
Codeforces_33629_I
You are given a tree with $$$n$$$ nodes and $$$n-1$$$ edges. Each edge has a weight of 1. The nodes are numbered from 1 to $$$n$$$. Your task is to determine the length of the shortest path between two nodes in the tree. Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ (...
from collections import defaultdict, deque def lca_depth(tree, root, n): """ This function returns an array of depths and a parent array using BFS. """ depth = [-1] * (n + 1) parent = [-1] * (n + 1) depth[root] = 0 queue = deque([root]) while queue: node = queue.popleft() ...
from solution import process def test_single_case(): test_cases = [ { "n": 6, "edges": [ (1, 2), (2, 3), (2, 4), (4, 5), (4, 6) ], "queries": [ (1, 6), ...
[ { "docstring": "This function returns an array of depths and a parent array using BFS.", "function_declaration": "def lca_depth(tree, root, n):", "function_name": "lca_depth", "parameter_list": "(tree, root, n)" }, { "docstring": "Function to find Lowest Common Ancestor using parent array an...
[ 0, 0, 0, 0, 1, 1, 0, 0 ]
2
hard
0.25
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "import sys\nimport collections\n\ninput = sys.stdin.read\n\ndef preprocess_lca(n, tree):\n LOG = 20 # log2(10^5) is approximately 17, we take a higher pow...
trial_gpt4o_6
{ "original_instruction": "", "prompt_id": "00033629", "row_id": 33629, "seed_ids": "[8334, 4582, 4498]" }
0.74306
Codeforces_33629
I
[ "lca_depth", "find_lca", "shortest_path_length", "handle_queries", "process" ]
5
[ [ "handle_queries", "lca_depth" ], [ "handle_queries", "shortest_path_length" ], [ "process", "handle_queries" ], [ "shortest_path_length", "find_lca" ] ]
4
[ "handle_queries" ]
false
[]
false
pytest
true
[]
true
bbe0cf9e1f473b1d6376d30ee699125852929f7c
0de89aeb92148f4392c820f68a21624256c3bfe7
v1.0
instruct
Codeforces
Codeforces_33702_I
The kingdom of Aluket has a network of roads in the shape of a tree. There are n cities and n-1 roads, each connecting a pair of cities. Each road has a toll fee associated with it. King Halph wants to travel from city 1 to city n, but he wants to minimize the total toll he has to pay. Help King Halph find the minimum ...
import heapq def find_minimum_toll(n, roads): """ Finds the minimum toll King Halph needs to pay to travel from city 1 to city n. """ # Create an adjacency list for the graph graph = {i: [] for i in range(1, n + 1)} for u, v, w in roads: graph[u].append((v, w)) graph[v].append((...
from solution import minimum_toll def test_sample_input_1(): n = 4 roads_input = [1, 2, 1, 2, 3, 2, 2, 4, 3] assert minimum_toll(n, roads_input) == 4 def test_sample_input_2(): n = 6 roads_input = [1, 2, 2, 1, 3, 1, 2, 4, 1, 2, 5, 2, 3, 6, 2] assert minimum_toll(n, roads_input) == 3 def test_...
[ { "docstring": "Finds the minimum toll King Halph needs to pay to travel from city 1 to city n.", "function_declaration": "def find_minimum_toll(n, roads):", "function_name": "find_minimum_toll", "parameter_list": "(n, roads)" }, { "docstring": null, "function_declaration": "def minimum_...
[ 0, 1, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "import heapq\nfrom collections import defaultdict\nimport sys\n\ndef minimum_toll(n, roads):\n graph = defaultdict(list)\n for u, v, w in roads:\n ...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00033702", "row_id": 33702, "seed_ids": "[6066, 7972, 3434]" }
0.747344
Codeforces_33702
I
[ "find_minimum_toll", "minimum_toll" ]
2
[ [ "minimum_toll", "find_minimum_toll" ] ]
1
[]
false
[]
false
pytest
true
[]
true
18ee64114967745adb4b7a59959a0964e41d489e
df0f868c992bd631c31cd12a58d2b5fe5831c7ac
v1.0
instruct
Codeforces
Codeforces_33708_I
John is learning about prime numbers and is particularly interested in `twin primes`. Twin primes are pairs of prime numbers that have a difference of 2. For example, (3, 5) and (11, 13) are twin primes. John's teacher gave him an assignment where he needs to find the number of twin primes in a given range [L, R]. Joh...
def sieve_of_eratosthenes(n): """ Returns a list of boolean values. The index represents the number and the value at each index is True if the number is prime, otherwise False. """ is_prime = [True] * (n + 1) is_prime[0] = is_prime[1] = False for p in range(2, int(n**0.5) + 1): ...
from solution import find_twin_primes def test_find_twin_primes_example_cases(): assert find_twin_primes(1, 20) == 4 # (3,5), (5,7), (11,13), (17,19) assert find_twin_primes(10, 30) == 2 # (11,13), (17,19) assert find_twin_primes(1, 10) == 2 # (3,5), (5,7) def test_find_twin_primes_no_twins(): asser...
[ { "docstring": "Returns a list of boolean values. The index represents the number and the value at each index\nis True if the number is prime, otherwise False.", "function_declaration": "def sieve_of_eratosthenes(n):", "function_name": "sieve_of_eratosthenes", "parameter_list": "(n)" }, { "d...
[ 0, 0, 0, 0, 1 ]
1
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def find_twin_primes(L, R):\n def sieve(n):\n is_prime = [True] * (n + 1)\n p = 2\n while (p * p <= n):\n if (is_prime[p] =...
trial_gpt4o_4
{ "original_instruction": "", "prompt_id": "00033708", "row_id": 33708, "seed_ids": "[3504, 6562, 2648]" }
0.654167
Codeforces_33708
I
[ "sieve_of_eratosthenes", "find_twin_primes" ]
2
[ [ "find_twin_primes", "sieve_of_eratosthenes" ] ]
1
[]
false
[]
false
pytest
true
[]
true
e1a6ddc751366c594d77d3d7317225e5d4ee88f0
841da4517fe39ee4861d800d06b3f401ca7d4fde
v1.0
instruct
Codeforces
Codeforces_33777_I
Given a list of strings, create a function that finds the longest palindromic subsequence in each string. A palindromic subsequence is a sequence that reads the same forward and backward, and it need not be contiguous. ### Input The input consists of an integer `n` (1 ≤ n ≤ 1000) representing the number of strings, fo...
def longest_palindromic_subsequence_length(s): """ Given a string s, find the length of the longest palindromic subsequence. """ n = len(s) if n == 0: return 0 # Create a 2D array to store lengths of palindromic subsequences dp = [[0] * n for _ in range(n)] # All substrings of ...
from solution import find_longest_palindromic_subsequence_lengths def test_longest_palindromic_subsequence_length(): inputs = ["character", "racecar", "level", "abcba"] expected = [5, 7, 5, 5] assert find_longest_palindromic_subsequence_lengths(inputs) == expected def test_single_character_strings(): ...
[ { "docstring": "Given a string s, find the length of the longest palindromic subsequence.", "function_declaration": "def longest_palindromic_subsequence_length(s):", "function_name": "longest_palindromic_subsequence_length", "parameter_list": "(s)" }, { "docstring": "Given a list of strings,...
[ 1, 0, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def longest_palindromic_subsequence_length(s):\n \"\"\"\n Given a string s, find the length of the longest palindromic subsequence.\n \"\"\"\n n =...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00033777", "row_id": 33777, "seed_ids": "[4154, 670, 7817]" }
0.857003
Codeforces_33777
I
[ "longest_palindromic_subsequence_length", "find_longest_palindromic_subsequence_lengths" ]
2
[ [ "find_longest_palindromic_subsequence_lengths", "longest_palindromic_subsequence_length" ] ]
1
[]
false
[]
false
pytest
true
[]
true
690f94ca0f76d389337861b18ea81e4a5a521820
a8e99aac94644173f82da1cf63625f56013658fe
v1.0
instruct
Codeforces
Codeforces_33796_I
Lena loves archery and regularly practices at the training ground. The training ground has multiple targets positioned in a line, and each target has a certain score associated with hitting it. However, Lena has a unique way of practicing: she can only hit targets in a contiguous segment of the line during one practice...
def max_subarray_sum(nums): """ Returns the maximum score (sum) of any contiguous subarray. """ max_sum = current_sum = nums[0] for num in nums[1:]: current_sum = max(num, current_sum + num) max_sum = max(max_sum, current_sum) return max_sum def archery_sessions(t, ses...
from solution import archery_sessions, max_subarray_sum def test_max_subarray_sum(): assert max_subarray_sum([1, -2, 3, 4, -1]) == 7 assert max_subarray_sum([-1, -2, -3]) == -1 assert max_subarray_sum([5, -1, 2, -3, 4]) == 7 assert max_subarray_sum([1, 2, 3, 4]) == 10 assert max_subarray_sum([-2, -...
[ { "docstring": "Returns the maximum score (sum) of any contiguous subarray.", "function_declaration": "def max_subarray_sum(nums):", "function_name": "max_subarray_sum", "parameter_list": "(nums)" }, { "docstring": null, "function_declaration": "def archery_sessions(t, sessions):", "...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def max_contiguous_segment_score(t, sessions):\n \"\"\"\n Returns the maximum score achievable from any contiguous segment of targets.\n \n Args:\...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00033796", "row_id": 33796, "seed_ids": "[3591, 6897, 344]" }
0.689386
Codeforces_33796
I
[ "max_subarray_sum", "archery_sessions" ]
2
[ [ "archery_sessions", "max_subarray_sum" ] ]
1
[]
false
[]
false
pytest
true
[]
true
28f25defa28b270809f2f43d49179536357b9199
b9c68a5b7e4b27ab951d062424bd322e6452dbdd
v1.0
instruct
Codeforces
Codeforces_33800_I
Daisy loves prime numbers and is fascinated by sequences. She recently encountered Prime Sequences and wants your help to solve a problem. She gives you a sequence of integers and wants you to check if it's possible to delete some elements (possibly none) from the sequence so that the sum of the remaining elements is ...
import itertools def is_prime(num): """ Check if a number is prime. """ if num <= 1: return False if num <= 3: return True if num % 2 == 0 or num % 3 == 0: return False i = 5 while i * i <= num: if num % i == 0 or num % (i + 2) == 0: return Fa...
from solution import is_prime, prime_sequence_exists def test_is_prime(): assert is_prime(2) == True assert is_prime(3) == True assert is_prime(4) == False assert is_prime(17) == True assert is_prime(18) == False assert is_prime(19) == True assert is_prime(1) == False def test_prime_sequen...
[ { "docstring": "Check if a number is prime.", "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": "Returns \"YES\" if there exists a non-empty subset of the sequence whose sum is a prime number.\nReturns \"NO\" otherwise.", ...
[ 0, 1, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "from itertools import combinations\n\ndef is_prime(num):\n \"\"\"\n Helper function to check if a number is prime.\n \"\"\"\n if num <= 1:\n ...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00033800", "row_id": 33800, "seed_ids": "[7882, 6772, 6250]" }
0.618998
Codeforces_33800
I
[ "is_prime", "prime_sequence_exists" ]
2
[ [ "prime_sequence_exists", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
d93520c7db420ca0d6629a13e3c7a7d0801a1884
053f36b22ddb2d52e5684351a63dacd78a9bc281
v1.0
instruct
Codeforces
Codeforces_33827_I
You are given an undirected, connected graph with `n` nodes and `m` edges. The nodes are numbered from `1` to `n`. Each edge has a weight, which is a positive integer. Your task is to determine the minimum number of edges to remove from the graph so that the remaining graph has no cycles (i.e., it becomes a tree). If...
def find(parent, i): """ A utility function to find the subset of an element i """ if parent[i] == i: return i else: return find(parent, parent[i]) def union(parent, rank, x, y): """ A utility function to do union of two subsets """ xroot = find(parent, x) yroot ...
import pytest from solution import solve def test_example_case_1(): n = 6 m = 9 edge_list = [ (1, 2, 4), (1, 3, 3), (2, 3, 2), (2, 4, 5), (3, 4, 7), (3, 5, 9), (4, 5, 6), (4, 6, 8), (5, 6, 1) ] assert solve(n, m, edge_list) == ...
[ { "docstring": "A utility function to find the subset of an element i", "function_declaration": "def find(parent, i):", "function_name": "find", "parameter_list": "(parent, i)" }, { "docstring": "A utility function to do union of two subsets", "function_declaration": "def union(parent, r...
[ 1, 0, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def find(parent, i):\n \"\"\"\n A utility function to find the subset of an element i\n \"\"\"\n if parent[i] == i:\n return i\n else:\n...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00033827", "row_id": 33827, "seed_ids": "[1157, 2534, 2579]" }
0.79471
Codeforces_33827
I
[ "find", "union", "max_spanning_tree", "solve" ]
4
[ [ "max_spanning_tree", "find" ], [ "max_spanning_tree", "union" ], [ "solve", "max_spanning_tree" ], [ "union", "find" ] ]
4
[]
false
[]
false
pytest
true
[]
true
0be7d6005c164d1c12317a2a98cdb0e74f171c2b
27bc56a5f34299179ca9ce92d69e71d7f705071e
v1.0
instruct
Codeforces
Codeforces_33838_I
Priya and Rohan are playing a game with prime numbers. The game involves finding certain prime numbers within specific ranges. A prime number is a natural number greater than 1 that cannot be formed by multiplying two smaller natural numbers. Priya wants to find prime numbers between two given numbers frequently, and R...
def sieve(max_num): """ Create a list to determine prime numbers up to max_num using the Sieve of Eratosthenes. """ is_prime = [True] * (max_num + 1) is_prime[0] = is_prime[1] = False for start in range(2, int(max_num**0.5) + 1): if is_prime[start]: for multiple in range...
from solution import find_prime_counts def test_find_prime_counts(): queries = [(2, 10), (11, 20), (30, 50)] result = find_prime_counts(queries) assert result == [4, 4, 5] def test_find_prime_counts_edge_case(): queries = [(1, 2), (1, 1), (10**6, 10**6)] result = find_prime_counts(queries) ass...
[ { "docstring": "Create a list to determine prime numbers up to max_num using the Sieve of Eratosthenes.", "function_declaration": "def sieve(max_num):", "function_name": "sieve", "parameter_list": "(max_num)" }, { "docstring": "Given a range [l, r] and a list of primes, count how many primes...
[ 0, 0, 1 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def sieve_of_eratosthenes(max_num):\n is_prime = [True] * (max_num + 1)\n p = 2\n while (p * p <= max_num):\n if (is_prime[p] == True):\n ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00033838", "row_id": 33838, "seed_ids": "[3016, 1614, 4059]" }
0.671385
Codeforces_33838
I
[ "sieve", "count_primes_in_range", "find_prime_counts" ]
3
[ [ "find_prime_counts", "count_primes_in_range" ], [ "find_prime_counts", "sieve" ] ]
2
[]
false
[]
false
pytest
true
[]
true
d3881ba83ce05a78513b8f35bbceb69b06d9d51c
d81d01db14fbe359a9ab5a405fcac5c6b6fc916b
v1.0
instruct
Codeforces
Codeforces_33841_I
You are given a binary tree with n nodes, rooted at node 1. Each node has a unique integer value assigned to it. Your task is to determine the sum of all root-to-leaf paths where each node in the path sums to a prime number. A leaf is defined as a node with no children. A root-to-leaf path is the sequence of nodes sta...
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 build_tree(n): from collections import...
from solution import is_prime, sum_prime_paths, find_leaf_paths def test_is_prime(): assert is_prime(2) == True assert is_prime(3) == True assert is_prime(4) == False assert is_prime(13) == True assert is_prime(20) == False def test_find_leaf_paths(): tree = {1: [2, 3], 2: [1], 3: [1, 4, 5], 4...
[ { "docstring": null, "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": null, "function_declaration": "def build_tree(n):", "function_name": "build_tree", "parameter_list": "(n)" }, { "docstring": null, "...
[ 0, 0, 0, 0, 0, 0, 1, 0, 0, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "from collections import defaultdict, deque\n\ndef is_prime(n):\n if n <= 1:\n return False\n if n <= 3:\n return True\n if n % 2 == 0 o...
trial_gpt4o_6
{ "original_instruction": "", "prompt_id": "00033841", "row_id": 33841, "seed_ids": "[6547, 6110, 1574]" }
0.542275
Codeforces_33841
I
[ "is_prime", "build_tree", "find_leaf_paths", "sum_prime_paths", "main" ]
5
[ [ "find_leaf_paths", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
8605a812e006eabb9488c9c510da1a5dc77316fe
a1b3320ae259baa7b8c49206bbcad94a788cb4dd
v1.0
instruct
Codeforces
Codeforces_33948_I
Heidi is studying the structure of a large archaeological site that can be modeled as a simple undirected graph. Each area of the site is represented as a vertex, and a direct connection between two areas is represented as an edge. Heidi wants to place guiding signs in such a way that from any given area, one can event...
import heapq from collections import defaultdict def min_spanning_tree_prims(n, edges, exclude_edge=None): if exclude_edge: edges.remove(exclude_edge) # Priority queue to select the smallest weight edge pq = [] for u, v, d in edges: heapq.heappush(pq, (d, u, v)) # To track...
from solution import minimum_guiding_signs, min_spanning_tree_prims def test_min_spanning_tree_prims(): edges = [(1, 2, 1), (1, 3, 2), (2, 3, 4), (2, 4, 3), (3, 4, 5)] min_edges, total_weight = min_spanning_tree_prims(4, edges.copy(), exclude_edge=(3, 4, 5)) assert total_weight == 6 assert len(min_edge...
[ { "docstring": null, "function_declaration": "def min_spanning_tree_prims(n, edges, exclude_edge=None):", "function_name": "min_spanning_tree_prims", "parameter_list": "(n, edges, exclude_edge=None)" }, { "docstring": null, "function_declaration": "def minimum_guiding_signs(n, edges):", ...
[ 0, 0, 1 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "import heapq\n\ndef find_min_guiding_signs(n, m, edges):\n \"\"\"\n Determines the minimal number of guiding signs needed if the longest edge is closed....
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00033948", "row_id": 33948, "seed_ids": "[8016, 4834, 7164]" }
0.621103
Codeforces_33948
I
[ "min_spanning_tree_prims", "minimum_guiding_signs", "process_input" ]
3
[ [ "minimum_guiding_signs", "min_spanning_tree_prims" ], [ "process_input", "minimum_guiding_signs" ] ]
2
[ "process_input" ]
false
[]
false
pytest
true
[]
true
b959e63fd6bcf0d5615b2180edf28af49c2e1584
b50bf3fe0d0703666f3717bf856c36a03b5da170