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_21955_I
Maxim the Engineer is working on an old project that involves managing a series of robots placed on a 2D grid. Each robot can only move in the four cardinal directions (up, down, left, right) and must navigate around obstacles placed on the grid. Each robot starts at a specific position and has a target position it mus...
from collections import deque def min_moves(grid, start, target): n, m = len(grid), len(grid[0]) directions = [(-1, 0), (1, 0), (0, -1), (0, 1)] queue = deque([(start[0], start[1], 0)]) # (x, y, distance) visited = set() visited.add((start[0], start[1])) while queue: x, y, dist = queu...
def test_min_moves(): grid = [ ['.', '.', '.', '.'], ['.', '#', '.', '.'], ['.', '#', '.', '.'], ['.', '.', '.', '.'] ] assert min_moves(grid, (0, 0), (3, 3)) == 6 assert min_moves(grid, (0, 0), (1, 1)) == -1 def test_process_robot_paths(): grid = [ ['.', '.'...
[ { "docstring": null, "function_declaration": "def min_moves(grid, start, target):", "function_name": "min_moves", "parameter_list": "(grid, start, target)" }, { "docstring": null, "function_declaration": "def process_robot_paths(n, m, grid, robots):", "function_name": "process_robot_...
[ 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 minimum_moves(n, m, grid, start, target):\n moves = [(-1, 0), (1, 0), (0, -1), (0, 1)]\n sx, sy = start\n tx, ty...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00021955", "row_id": 21955, "seed_ids": "[4118, 7217, 8273]" }
0.73953
Codeforces_21955
I
[ "min_moves", "process_robot_paths" ]
2
[ [ "process_robot_paths", "min_moves" ] ]
1
[]
false
[]
false
pytest
false
[]
true
48a9b41d8044af8b9f716bb5c1d99d20e2d3d4e9
dd219a0ed95f72cadfbf080b7133c0ffbb8296ce
v1.0
instruct
Codeforces
Codeforces_21960_I
You are given an array of integers $$$a$$$ of length $$$n$$$. Any two adjacent elements of the array that are different can be swapped in one move. Your task is to calculate the minimum number of moves required to make the entire array non-decreasing. For example, consider the array $$$a = [4, 3, 2, 1]$$$. You can swa...
def merge_count_split_inv(arr, temp_arr, left, mid, right): i = left # Starting index for left subarray j = mid + 1 # Starting index for right subarray k = left # Starting index to be sorted inv_count = 0 # Conditions are checked to ensure that i doesn't exceed mid and j doesn't exceed righ...
def test_example_case(): arr = [4, 3, 2, 1] assert minimum_swaps_to_sort(arr) == 6 def test_already_sorted(): arr = [1, 2, 3, 4, 5] assert minimum_swaps_to_sort(arr) == 0 def test_random_case(): arr = [1, 3, 5, 2, 4, 6] assert minimum_swaps_to_sort(arr) == 3 def test_reverse_sorted(): arr...
[ { "docstring": null, "function_declaration": "def merge_count_split_inv(arr, temp_arr, left, mid, right):", "function_name": "merge_count_split_inv", "parameter_list": "(arr, temp_arr, left, mid, right)" }, { "docstring": null, "function_declaration": "def merge_sort_and_count(arr, temp_...
[ 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 count_inversions(arr):\n \"\"\"\n Use a modified merge sort to count the inversions in the array.\n \"\"\"\n if len(arr) < 2:\n return ...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00021960", "row_id": 21960, "seed_ids": "[1128, 4561, 1446]" }
0.719742
Codeforces_21960
I
[ "merge_count_split_inv", "merge_sort_and_count", "minimum_swaps_to_sort" ]
3
[ [ "merge_sort_and_count", "merge_count_split_inv" ], [ "minimum_swaps_to_sort", "merge_sort_and_count" ] ]
2
[]
false
[]
false
pytest
false
[]
true
ebdb2dafe216d9f76f9ede5a6e0ea57adb2f6b17
fb0bcac314ad01c2e626d73f91a58bd726cc8214
v1.0
instruct
Codeforces
Codeforces_22008_I
In the bustling city of Technopolis, a new communication network is being set up. The city is divided into distinct districts, each represented by a node, and they need to be connected by the shortest possible network of optical fibers. However, the installation company can only lay fiber along predefined potential pat...
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] = roo...
def test_basic_example(): D = 4 C = 5 connection_data = [ (1, 2, 5), (1, 3, 10), (2, 3, 4), (2, 4, 8), (3, 4, 12) ] assert min_network_length(D, C, connection_data) == 17 def test_no_possible_connection(): D = 4 C = 2 connection_data = [ (...
[ { "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_minimum_spanning_tree(dist, connections):\n parent = [-1] * (dist + 1)\n\n def find(x):\n if parent[x] == -1:\n return x\n ...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00022008", "row_id": 22008, "seed_ids": "[1987, 1997, 2059]" }
0.728879
Codeforces_22008
I
[ "find", "union", "kruskal_mst", "min_network_length" ]
4
[ [ "kruskal_mst", "find" ], [ "kruskal_mst", "union" ], [ "min_network_length", "kruskal_mst" ], [ "union", "find" ] ]
4
[]
false
[]
false
pytest
false
[]
true
979762c97742d017d3b0029730eb8840a0dccde1
126be5d3e10716130a3e7d928d22cd9739e18be0
v1.0
instruct
Codeforces
Codeforces_22020_I
You are given an undirected graph represented by an adjacency matrix. The graph has n vertices and m edges. You need to determine if there's a Hamiltonian path in the graph. A Hamiltonian path is a path that visits each vertex exactly once. Input Format: - The first line contains two integers, n (2 ≤ n ≤ 17) and m (0 ...
def is_hamiltonian_path(graph, n): def dp(mask, pos, memo): if mask == (1 << n) - 1: return True if (mask, pos) in memo: return memo[(mask, pos)] for next_pos in range(n): if graph[pos][next_pos] and not (mask & (1 << next_pos)): i...
from solution import hamiltonian_path def test_example_case(): n = 4 m = 4 adjacency_matrix = [ [0, 1, 1, 0], [1, 0, 1, 1], [1, 1, 0, 1], [0, 1, 1, 0] ] assert hamiltonian_path(n, m, adjacency_matrix) == "YES" def test_no_edges(): n = 3 m = 0 adjacency_m...
[ { "docstring": null, "function_declaration": "def is_hamiltonian_path(graph, n):", "function_name": "is_hamiltonian_path", "parameter_list": "(graph, n)" }, { "docstring": null, "function_declaration": "def hamiltonian_path(n, m, adjacency_matrix):", "function_name": "hamiltonian_pat...
[ 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_hamiltonian_path(graph, n):\n def dp(mask, pos, memo):\n if mask == (1 << n) - 1:\n return True\n if (mask, pos) in memo:\n...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00022020", "row_id": 22020, "seed_ids": "[4109, 6850, 122]" }
0.598997
Codeforces_22020
I
[ "is_hamiltonian_path", "hamiltonian_path" ]
2
[ [ "hamiltonian_path", "is_hamiltonian_path" ] ]
1
[]
false
[]
false
pytest
true
[]
true
174547c4b5f295a062c272c77856ebe3d9285e97
7deff17b608edacdce2bfe1a580b1e8e87ef6754
v1.0
instruct
Codeforces
Codeforces_22060_I
You are given an array of non-negative integers and a positive integer $$$k$$$. You need to determine whether it is possible to partition the array into $$$k$$$ non-empty subsets such that the sum of elements in each subset is the same. Your task is to write a function to determine if the array can be partitioned in s...
def canPartitionKSubsets(nums, k): """ Determine if the array can be partitioned into k subsets with equal sum. """ total_sum = sum(nums) if total_sum % k != 0: return False target = total_sum // k def backtrack(index, target, k, subset_sum, used): if k == 1: ret...
from solution import partition_array def test_example_1(): assert partition_array(5, 3, [2, 1, 4, 5, 6]) == True def test_example_2(): assert partition_array(4, 3, [4, 3, 2, 3]) == False def test_single_element(): assert partition_array(1, 1, [1]) == True def test_all_same_elements(): assert partiti...
[ { "docstring": "Determine if the array can be partitioned into k subsets with equal sum.", "function_declaration": "def canPartitionKSubsets(nums, k):", "function_name": "canPartitionKSubsets", "parameter_list": "(nums, k)" }, { "docstring": null, "function_declaration": "def partition_a...
[ 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 can_partition_k_subsets(nums, k):\n if k == 1:\n return True\n total_sum = sum(nums)\n if total_sum % k != 0:\n return False\n t...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00022060", "row_id": 22060, "seed_ids": "[1165, 3094, 7085]" }
0.681041
Codeforces_22060
I
[ "canPartitionKSubsets", "partition_array" ]
2
[ [ "partition_array", "canPartitionKSubsets" ] ]
1
[]
false
[]
false
pytest
true
[]
true
d825abc855ce59a2fd8c7ad471977204e7a2b139
db31c15b3932e6b0caec88d2f306595cece19ae9
v1.0
instruct
Codeforces
Codeforces_22217_I
Polycarp loves playing with sequences of integers. He has a sequence of n positive integers and he wants to perform several operations on this sequence. The operations are of two types: 1. Update the value at a specific position in the sequence. 2. Query the maximum sum of any contiguous subarray of the sequence. You...
def update_value(arr, x, y): arr[x-1] = y def max_subarray_sum(arr, l, r): max_sum = float('-inf') current_sum = 0 for i in range(l-1, r): current_sum += arr[i] max_sum = max(max_sum, current_sum) if current_sum < 0: current_sum = 0 return max_sum def process_op...
def test_update_value(): arr = [3, 2, 1, -4, 5] update_value(arr, 3, 10) assert arr == [3, 2, 10, -4, 5] def test_max_subarray_sum(): arr = [3, 2, 10, -4, 5] assert max_subarray_sum(arr, 1, 5) == 16 assert max_subarray_sum(arr, 1, 3) == 15 assert max_subarray_sum(arr, 2, 4) == 12 def test_...
[ { "docstring": null, "function_declaration": "def update_value(arr, x, y):", "function_name": "update_value", "parameter_list": "(arr, x, y)" }, { "docstring": null, "function_declaration": "def max_subarray_sum(arr, l, r):", "function_name": "max_subarray_sum", "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": "class SegmentTree:\n def __init__(self, data):\n self.n = len(data)\n self.tree = [0] * (4 * self.n)\n self.data = data\n self....
trial_gpt4o_3
{ "original_instruction": "", "prompt_id": "00022217", "row_id": 22217, "seed_ids": "[6630, 6154, 7180]" }
0.659903
Codeforces_22217
I
[ "update_value", "max_subarray_sum", "process_operations" ]
3
[ [ "process_operations", "max_subarray_sum" ], [ "process_operations", "update_value" ] ]
2
[]
false
[]
false
pytest
false
[]
true
e72d88dbe7bdb77e5a0377e5822e0824b3dee2c8
e60545a4e16143ee2b15b616a0fef4ec5353023c
v1.0
instruct
Codeforces
Codeforces_22225_I
Vasya has a directed graph with $$$n$$$ vertices and $$$m$$$ edges. Vasya wants to check if it's possible to start from any vertex and reach any other vertex using the edges. Help Vasya with determining it. The first line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n \le 1000, 1 \le m \le 10000$$$) — the numbe...
def is_strongly_connected(n, m, edges): from collections import defaultdict, deque def bfs(start, graph): visited = [False] * (n + 1) queue = deque([start]) visited[start] = True while queue: node = queue.popleft() for neighbor in graph[node]: ...
def test_is_strongly_connected_yes(): assert can_reach_any_vertex(4, 5, [1, 2, 2, 3, 3, 4, 4, 1, 2, 4]) == "YES" def test_is_strongly_connected_no(): assert can_reach_any_vertex(4, 3, [1, 2, 2, 3, 3, 4]) == "NO" def test_single_vertex(): assert can_reach_any_vertex(1, 0, []) == "YES" def test_two_vertice...
[ { "docstring": null, "function_declaration": "def is_strongly_connected(n, m, edges):", "function_name": "is_strongly_connected", "parameter_list": "(n, m, edges)" }, { "docstring": null, "function_declaration": "def can_reach_any_vertex(n, m, edge_list):", "function_name": "can_reac...
[ 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 is_strongly_connected(n, m, edges):\n from collections import defaultdict, deque\n \n def bfs(start, graph):\n visited = [False] * (n + 1)...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00022225", "row_id": 22225, "seed_ids": "[3068, 7302, 7730]" }
0.641168
Codeforces_22225
I
[ "is_strongly_connected", "can_reach_any_vertex" ]
2
[ [ "can_reach_any_vertex", "is_strongly_connected" ] ]
1
[]
false
[]
false
pytest
false
[]
true
4cd926aeca9ed0ca8f466fc45593ebfcb820ce43
111c3f07e4c2c705b2801fc0f9dc9aa8eaded840
v1.0
instruct
Codeforces
Codeforces_22285_I
Superhero Central Intelligence (SCI) is in need of a highly efficient way to encrypt their communication channels. They've designed an encryption scheme based on a mathematical transformation process. Here’s how it works: Given an integer matrix of size `n x n` (1 ≤ n ≤ 20), we apply a specific rotation transformation...
def rotate_layer(matrix, layer, n): temp = [] # Extract the layer elements in clockwise order for i in range(layer, n-layer): temp.append(matrix[layer][i]) for i in range(layer+1, n-layer): temp.append(matrix[i][n-layer-1]) for i in range(n-layer-2, layer-1, -1): temp.append(...
from solution import diagonal_sum_after_rotation def test_case_1(): matrix = [ [1, 2, 3], [4, 5, 6], [7, 8, 9] ] assert diagonal_sum_after_rotation(matrix, 1) == 15 def test_case_2(): matrix = [ [1, 2], [3, 4] ] assert diagonal_sum_after_rotation(matrix,...
[ { "docstring": null, "function_declaration": "def rotate_layer(matrix, layer, n):", "function_name": "rotate_layer", "parameter_list": "(matrix, layer, n)" }, { "docstring": null, "function_declaration": "def rotate_matrix(matrix, steps):", "function_name": "rotate_matrix", "para...
[ 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 rotate_layer(matrix, layer, n):\n # Get the indices for the top-left and bottom-right corners of the current layer\n top_left = layer\n bottom_ri...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00022285", "row_id": 22285, "seed_ids": "[1914, 4669, 5536]" }
0.543425
Codeforces_22285
I
[ "rotate_layer", "rotate_matrix", "diagonal_sum_after_rotation" ]
3
[ [ "diagonal_sum_after_rotation", "rotate_matrix" ], [ "rotate_matrix", "rotate_layer" ] ]
2
[]
false
[]
false
pytest
true
[]
true
fba519c247a3241948e9e3983c1f3006acac25f2
38455d26ce90a8fd0e7a2ac9f63a60820fb5f472
v1.0
instruct
Codeforces
Codeforces_22299_I
In a city, there are n traffic signals numbered from 0 to n-1 connected by m roads. Each road allows traveling from one traffic signal to another and has a certain travel time. You need to determine the shortest time required to travel from a given starting traffic signal s to a given destination traffic signal t. The...
import heapq def dijkstra(n, roads, start, end): graph = [[] for _ in range(n)] for u, v, w in roads: graph[u].append((v, w)) graph[v].append((u, w)) # Assuming bidirectional roads pq = [(0, start)] # Priority queue of (travel time, node) min_time = {i: float('inf') for i in rang...
from solution import shortest_travel_time def test_shortest_travel_time_case1(): n = 5 m = 6 roads_list = [ (0, 1, 2), (1, 2, 4), (0, 2, 1), (2, 3, 7), (3, 4, 3), (2, 4, 5) ] s = 0 t = 4 assert shortest_travel_time(n, m, roads_list, s, t) == 6...
[ { "docstring": null, "function_declaration": "def dijkstra(n, roads, start, end):", "function_name": "dijkstra", "parameter_list": "(n, roads, start, end)" }, { "docstring": null, "function_declaration": "def shortest_travel_time(n, m, roads_list, s, t):", "function_name": "shortest_...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "import heapq\n\ndef shortest_time(n, m, roads, s, t):\n graph = {i: [] for i in range(n)}\n for u, v, w in roads:\n graph[u].append((v, w))\n ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00022299", "row_id": 22299, "seed_ids": "[3970, 2284, 4325]" }
0.782124
Codeforces_22299
I
[ "dijkstra", "shortest_travel_time" ]
2
[ [ "shortest_travel_time", "dijkstra" ] ]
1
[]
false
[]
false
pytest
true
[]
true
88a63ddf9e5fe60030df3eed25fc987e112f0df1
363e5cf8017fd1df6c5a25ca0758e7dcb76d8f62
v1.0
instruct
Codeforces
Codeforces_22305_I
The President of the National Aeronautics Institute wants to design a new satellite transmission scheduling system. Each satellite can communicate with Earth during non-overlapping time intervals. You have to develop an algorithm to maximize the total number of non-overlapping time intervals where at least one satellit...
def max_non_overlapping_intervals(intervals): """ Returns the maximum number of non-overlapping intervals. """ if not intervals: return 0 # Sort intervals based on the end time intervals.sort(key=lambda x: x[1]) count = 0 end_time = float('-inf') for start, end in inte...
from solution import solve def test_single_interval(): assert solve(1, [[1, 2]]) == 1 def test_non_overlapping_intervals(): assert solve(3, [[1, 3], [4, 6], [7, 9]]) == 3 def test_overlapping_intervals(): assert solve(3, [[1, 3], [2, 5], [4, 8]]) == 2 def test_all_intervals_overlapping(): assert sol...
[ { "docstring": "Returns the maximum number of non-overlapping intervals.", "function_declaration": "def max_non_overlapping_intervals(intervals):", "function_name": "max_non_overlapping_intervals", "parameter_list": "(intervals)" }, { "docstring": null, "function_declaration": "def solve...
[ 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 max_non_overlapping_intervals(n, intervals):\n \"\"\"\n Returns the max number of non-overlapping intervals where at least one satellite\n is tra...
trial_gpt4o_6
{ "original_instruction": "", "prompt_id": "00022305", "row_id": 22305, "seed_ids": "[106, 2024, 4806]" }
0.636497
Codeforces_22305
I
[ "max_non_overlapping_intervals", "solve" ]
2
[ [ "solve", "max_non_overlapping_intervals" ] ]
1
[]
false
[]
false
pytest
true
[]
true
1a39a441f75788b445a1cc659a763cb8a46742d2
cc84385c5d3d3d8057181fde90b9926c5f53c492
v1.0
instruct
Codeforces
Codeforces_22317_I
The town of Graphlandia consists of n buildings connected by m bidirectional roads, forming a simple undirected graph. Each road connects two different buildings. The residents of Graphlandia have a peculiar way of choosing where to set up security checkpoints. They will only set up a checkpoint on a road if removing t...
def find_bridges(n, roads): from collections import defaultdict graph = defaultdict(list) # Create the adjacency list representation of the graph for i, (u, v) in enumerate(roads): graph[u].append((v, i + 1)) graph[v].append((u, i + 1)) bridges = [] visited = [Fals...
from solution import security_checkpoints def test_example_case(): n, m = 5, 5 roads = [(1, 2), (1, 3), (2, 3), (3, 4), (4, 5)] assert security_checkpoints(n, m, roads) == (2, [4, 5]) def test_no_bridges(): n, m = 4, 4 roads = [(1, 2), (2, 3), (3, 4), (4, 1)] assert security_checkpoints(n, m, ...
[ { "docstring": null, "function_declaration": "def find_bridges(n, roads):", "function_name": "find_bridges", "parameter_list": "(n, roads)" }, { "docstring": null, "function_declaration": "def security_checkpoints(n, m, roads):", "function_name": "security_checkpoints", "paramete...
[ 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_bridges(n, edges):\n from collections import defaultdict\n\n graph = defaultdict(list)\n for i, (u, v) in enumerate(edges):\n graph[u...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00022317", "row_id": 22317, "seed_ids": "[264, 2409, 5738]" }
0.700632
Codeforces_22317
I
[ "find_bridges", "security_checkpoints" ]
2
[ [ "security_checkpoints", "find_bridges" ] ]
1
[]
false
[]
false
pytest
true
[]
true
b835b0ea08f222022015534b0df3a6c4e13168e6
27fc287047270c835dcb8ef8b40fd6fd222087bc
v1.0
instruct
Codeforces
Codeforces_22333_I
You are given an undirected graph with `n` nodes and `m` edges. The graph may contain cycles. You need to find the maximum possible size of a subset `S` of nodes such that no two nodes in `S` are connected directly by an edge. This is known as finding the maximum independent set of the graph. Additionally, for each qu...
from collections import deque, defaultdict def is_path_exist(graph, u, v): visited = set() queue = deque([u]) while queue: node = queue.popleft() if node == v: return "YES" if node not in visited: visited.add(node) queue.extend(graph[node]) ...
from solution import process_graph def test_process_graph(): n = 4 m = 4 edges = [(1, 2), (2, 3), (3, 4), (1, 4)] q = 3 queries = [(1, 3), (2, 4), (1, 5)] expected_output = [2, "YES", "YES", "NO"] assert process_graph(n, m, edges, q, queries) == expected_output def test_no_edges(): n =...
[ { "docstring": null, "function_declaration": "def is_path_exist(graph, u, v):", "function_name": "is_path_exist", "parameter_list": "(graph, u, v)" }, { "docstring": null, "function_declaration": "def max_independent_set_size(graph, n):", "function_name": "max_independent_set_size", ...
[ 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_maximum_independent_set_size(n, m, edges, q, queries):\n def is_bipartite(adj_list, start, color):\n queue = [start]\n color[start] ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00022333", "row_id": 22333, "seed_ids": "[842, 2095, 3178]" }
0.679029
Codeforces_22333
I
[ "is_path_exist", "max_independent_set_size", "process_graph", "main" ]
4
[ [ "process_graph", "is_path_exist" ], [ "process_graph", "max_independent_set_size" ] ]
2
[]
false
[]
false
pytest
true
[]
true
f8884a58122c6c04adf57e76bb73293b0e661901
4c03ba85725968e4cdd0fe67a9c5a6e2682d765b
v1.0
instruct
Codeforces
Codeforces_22361_I
Chess Master has recently devised a new variant of chess called "Diagonal Chess." In this variant, pieces can only move diagonally across the board. This means each piece can move to a square that shares the same color as the starting square because chessboards are colored in a checkerboard pattern. You are given the ...
def get_position(coord): col, row = coord return (ord(col) - ord('a'), int(row) - 1) def same_color(start, end): start_col, start_row = get_position(start) end_col, end_row = get_position(end) return (start_col + start_row) % 2 == (end_col + end_row) % 2 def min_diagonal_moves(start, end): if ...
def test_get_position(): assert get_position("a1") == (0, 0) assert get_position("h8") == (7, 7) assert get_position("c3") == (2, 2) def test_same_color(): assert same_color("a1", "h8") == True assert same_color("a1", "h7") == False assert same_color("c3", "f6") == True assert same_color("a...
[ { "docstring": null, "function_declaration": "def get_position(coord):", "function_name": "get_position", "parameter_list": "(coord)" }, { "docstring": null, "function_declaration": "def same_color(start, end):", "function_name": "same_color", "parameter_list": "(start, end)" }...
[ 0, 0, 0, 0, 1, 0, 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 min_diagonal_moves(start, end):\n \"\"\"\n Calculate the minimum number of diagonal moves to reach 'end' position from 'start' position on a chessbo...
trial_gpt4o_5
{ "original_instruction": "", "prompt_id": "00022361", "row_id": 22361, "seed_ids": "[7077, 4266, 1289]" }
0.671964
Codeforces_22361
I
[ "get_position", "same_color", "min_diagonal_moves", "main" ]
4
[ [ "min_diagonal_moves", "get_position" ], [ "min_diagonal_moves", "same_color" ], [ "same_color", "get_position" ] ]
3
[]
false
[]
false
pytest
false
[]
true
c905621549fe2de8217e5dff183293457d6d5dc1
cbfe03cf9a46026d54d0ff45b41a3634363c477e
v1.0
instruct
Codeforces
Codeforces_22375_I
A wildlife sanctuary is home to n distinct species of birds. The sanctuary has m viewing spots. Each spot can be visited by the public and allows observation of specific bird species. Depending on the species, some spots are more suitable for seeing certain birds than others. Your task is to determine if it is possible...
from itertools import permutations def can_place_birds(n, m, suitability): spots = list(range(m)) # Generate all permutations of the spots for perm in permutations(spots, n): valid = True for i in range(n): # Check if each species can be placed at the corresponding spot in the p...
from solution import solve_bird_placement def test_simple_case_yes(): n = 3 m = 3 suitability = [ [1, 1, 0], [0, 1, 1], [1, 0, 1], ] assert solve_bird_placement(n, m, suitability) == "Yes" def test_simple_case_no(): n = 3 m = 2 suitability = [ [1, 0], ...
[ { "docstring": null, "function_declaration": "def can_place_birds(n, m, suitability):", "function_name": "can_place_birds", "parameter_list": "(n, m, suitability)" }, { "docstring": null, "function_declaration": "def solve_bird_placement(n, m, suitability):", "function_name": "solve_...
[ 0, 0, 0, 0, 0, 1, 1, 0, 0, 1 ]
3
hard
0.3
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def can_place_species(n, m, suitability_matrix):\n from scipy.optimize import linear_sum_assignment\n \n cost_matrix = [[0 if suitability_matrix[i][j...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00022375", "row_id": 22375, "seed_ids": "[3459, 2234, 5080]" }
0.620628
Codeforces_22375
I
[ "can_place_birds", "solve_bird_placement" ]
2
[ [ "solve_bird_placement", "can_place_birds" ] ]
1
[]
false
[]
false
pytest
true
[]
true
9f6114e5d964d6581d06b9b77e7f4de4bd58918b
833bd8dc9b2bb9a9aba73bcc98d0535f9c8331bb
v1.0
instruct
Codeforces
Codeforces_22381_I
An online bookstore keeps track of its inventory using a tree-like structure where each book is a node. Each book can have zero or more child books, representing related suggestions. Each book in the inventory is given a unique integer ID from 1 to n inclusive. The bookstore allows search operations that retrieve all b...
def build_tree(n, edges): from collections import defaultdict tree = defaultdict(list) for parent, child in edges: tree[parent].append(child) return tree def count_subtree_size(tree, node, subtree_size): size = 1 # count the node itself for child in tree[node]: size += count_su...
from solution import bookstore_inventory def test_bookstore_inventory_case1(): n = 5 edges = [(1, 2), (1, 3), (3, 4), (3, 5)] queries = [1, 2, 3] assert bookstore_inventory(n, edges, queries) == [5, 1, 3] def test_bookstore_inventory_case2(): n = 4 edges = [(1, 2), (1, 3), (2, 4)] queries ...
[ { "docstring": null, "function_declaration": "def build_tree(n, edges):", "function_name": "build_tree", "parameter_list": "(n, edges)" }, { "docstring": null, "function_declaration": "def count_subtree_size(tree, node, subtree_size):", "function_name": "count_subtree_size", "par...
[ 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 collections import defaultdict, deque\n\ndef count_descendants(n, edges, queries):\n tree = defaultdict(list)\n for u, v in edges:\n tree[u]...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00022381", "row_id": 22381, "seed_ids": "[4914, 4498, 4607]" }
0.635596
Codeforces_22381
I
[ "build_tree", "count_subtree_size", "process_queries", "bookstore_inventory" ]
4
[ [ "bookstore_inventory", "build_tree" ], [ "bookstore_inventory", "count_subtree_size" ], [ "bookstore_inventory", "process_queries" ] ]
3
[ "process_queries" ]
false
[]
false
pytest
true
[]
true
ddbf7d58897f0be29fef04e91d92a7173dd9389c
e52dd5986400428ae488220f44f561a1e0c8f816
v1.0
instruct
Codeforces
Codeforces_22425_I
You are given an $$$n \times m$$$ grid filled with non-negative integers. You need to find the maximum sum of a subrectangle within this grid. A subrectangle is defined by choosing two rows and two columns, and summing all the elements in the rectangular area formed between these rows and columns. The first line of i...
def maximum_sum_subrectangle(grid): n = len(grid) if n == 0: return 0 m = len(grid[0]) if m == 0: return 0 max_sum = float('-inf') for left in range(m): temp = [0] * n for right in range(left, m): for i in range(n): temp[i] += grid...
import pytest from solution import maximum_sum_subrectangle def test_small_grid(): grid = [ [1, 2, -1], [-2, 3, 4], [2, -1, 1] ] assert maximum_sum_subrectangle(grid) == 9 def test_single_row(): grid = [ [1, -2, 3, 4] ] assert maximum_sum_subrectangle(grid) == 7...
[ { "docstring": null, "function_declaration": "def maximum_sum_subrectangle(grid):", "function_name": "maximum_sum_subrectangle", "parameter_list": "(grid)" }, { "docstring": null, "function_declaration": "def kadane(arr):", "function_name": "kadane", "parameter_list": "(arr)" }...
[ 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 maximum_sum_subrectangle(n, m, grid):\n \"\"\"\n Returns the maximum sum of a subrectangle within the grid.\n \"\"\"\n max_sum = -float('inf')...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00022425", "row_id": 22425, "seed_ids": "[5830, 6881, 8277]" }
0.639579
Codeforces_22425
I
[ "maximum_sum_subrectangle", "kadane" ]
2
[ [ "maximum_sum_subrectangle", "kadane" ] ]
1
[]
false
[]
false
pytest
true
[]
true
c43b9280cf2417ab4b6efb828835d2a8dec50eea
5293e3b107ce1cc83b49ec01edfb0c64e470ead2
v1.0
instruct
Codeforces
Codeforces_22564_I
You are given a tree with $$$n$$$ nodes (1 ≤ $$$n$$$ ≤ 100,000). Each node has a unique integer from 1 to $$$n$$$. Your task is to perform $$$q$$$ queries on this tree. There are two types of queries: 1. Add a value $$$v$$$ to the value at all nodes in the subtree of node $$$u$$$. 2. Output the value at node $$$u$$$ ...
from collections import defaultdict, deque def build_tree(n, edges): tree = defaultdict(list) for a, b in edges: tree[a].append(b) tree[b].append(a) return tree def dfs(tree, node, parent, start_time, end_time, timer, start_times, end_times): start_time[node] = timer[0] start_times...
from solution import solve_tree_queries def test_basic_case(): n = 5 edges = [(1, 2), (1, 3), (3, 4), (3, 5)] q = 5 queries = [ (1, 3, 10), (2, 4), (2, 3), (1, 3, 5), (2, 4) ] assert solve_tree_queries(n, edges, q, queries) == [10, 10, 15] def test_singl...
[ { "docstring": null, "function_declaration": "def build_tree(n, edges):", "function_name": "build_tree", "parameter_list": "(n, edges)" }, { "docstring": null, "function_declaration": "def dfs(tree, node, parent, start_time, end_time, timer, start_times, end_times):", "function_name"...
[ 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": "class Tree:\n def __init__(self, n):\n self.n = n\n self.edges = [[] for _ in range(n + 1)]\n self.values = [0] * (n + 1)\n sel...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00022564", "row_id": 22564, "seed_ids": "[2985, 7917, 399]" }
0.70384
Codeforces_22564
I
[ "build_tree", "dfs", "process_queries", "solve_tree_queries" ]
4
[ [ "process_queries", "build_tree" ], [ "process_queries", "dfs" ], [ "solve_tree_queries", "process_queries" ] ]
3
[ "process_queries" ]
false
[]
false
pytest
true
[]
true
655fb04df003d4f54047fa908cda94ebb68a4c83
bf59bfc6573b153fce1bdbe605644f546eccd869
v1.0
instruct
Codeforces
Codeforces_22569_I
Given an integer array $$$arr$$$ of size $$$n$$$, you need to perform $$$q$$$ queries on it. Each query consists of two integers $$$l$$$ and $$$r$$$, and you need to return the sum of elements between the indices $$$l$$$ and $$$r$$$ (inclusive). Note that the indices are 0-based. Input Format: - The first line contain...
def prefix_sum_array(arr): """ Create a prefix sum array for the given array. """ prefix_sum = [0] * len(arr) prefix_sum[0] = arr[0] for i in range(1, len(arr)): prefix_sum[i] = prefix_sum[i - 1] + arr[i] return prefix_sum def query_sum(prefix_sum, l, r): """ Return the sum ...
from solution import process_queries def test_sample_input(): n = 5 arr = [1, 2, 3, 4, 5] queries = [(0, 2), (1, 3), (2, 4)] expected = [6, 9, 12] assert process_queries(n, arr, queries) == expected def test_single_element_array(): n = 1 arr = [10] queries = [(0, 0)] expected = [10...
[ { "docstring": "Create a prefix sum array for the given array.", "function_declaration": "def prefix_sum_array(arr):", "function_name": "prefix_sum_array", "parameter_list": "(arr)" }, { "docstring": "Return the sum of elements between indices l and r.", "function_declaration": "def quer...
[ 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_prefix_sum(arr):\n \"\"\" \n Preprocess the prefix sum array for efficient range sum queries.\n \n Args:\n arr: List[int] - The ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00022569", "row_id": 22569, "seed_ids": "[1515, 8036, 7430]" }
0.709186
Codeforces_22569
I
[ "prefix_sum_array", "query_sum", "process_queries" ]
3
[ [ "process_queries", "prefix_sum_array" ], [ "process_queries", "query_sum" ] ]
2
[ "process_queries" ]
false
[]
false
pytest
true
[]
true
9ce69c2782bf3b4ddeb1335b4a1339278c1ab31e
9756613967e8187685401a966666612aab207fcb
v1.0
instruct
Codeforces
Codeforces_22574_I
You are given an integer array $$$a$$$ of length $$$n$$$. Your task is to process a list of queries, where each query contains four integers $$$l$$$, $$$r$$$, $$$x$$$, $$$y$$$. For each query, you need to count how many integers in the subarray $$$a[l:r]$$$ are divisible by all integers in the range $$$[x, y]$$$. The ...
def gcd(a, b): while b: a, b = b, a % b return a def lcm(a, b): return a * b // gcd(a, b) def lcm_in_range(x, y): result = x for i in range(x + 1, y + 1): result = lcm(result, i) return result def process_queries(a, queries): results = [] for l, r, x, y in queries: ...
from solution import process_queries def test_example(): a = [6, 12, 15, 20, 25] queries = [(1, 3, 2, 3), (2, 5, 2, 5), (1, 5, 1, 1)] result = process_queries(a, queries) assert result == [2, 0, 5] def test_no_divisibles(): a = [2, 3, 5, 7, 11] queries = [(1, 5, 2, 3), (1, 3, 2, 5)] result...
[ { "docstring": null, "function_declaration": "def gcd(a, b):", "function_name": "gcd", "parameter_list": "(a, b)" }, { "docstring": null, "function_declaration": "def lcm(a, b):", "function_name": "lcm", "parameter_list": "(a, b)" }, { "docstring": null, "function_dec...
[ 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 gcd(a, b):\n while b:\n a, b = b, a % b\n return a\n\ndef lcm(a, b):\n return a * b // gcd(a, b)\n\ndef lcm_in_range(x, y):\n result = ...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00022574", "row_id": 22574, "seed_ids": "[7704, 1715, 490]" }
0.668528
Codeforces_22574
I
[ "gcd", "lcm", "lcm_in_range", "process_queries" ]
4
[ [ "lcm", "gcd" ], [ "lcm_in_range", "lcm" ], [ "process_queries", "lcm_in_range" ] ]
3
[ "process_queries" ]
false
[]
false
pytest
true
[]
true
7fabb1e689578950fb294b88001a7f540b0d6cbc
44bbdcc5e8516432015bd0552e0948117834feae
v1.0
instruct
Codeforces
Codeforces_22583_I
In the kingdom of Zorland, there are n towns connected by a series of bidirectional highways. Each highway has a unique identification and a positive integer distance associated with it. Two towns can have no more than one direct highway between them, but there may be many indirect routes connecting them. Each town des...
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 rootX != rootY: if rank[rootX] > rank[rootY]: parent[rootY] = rootX elif rank[rootX] <...
from solution import minimum_total_distance def test_example1(): n = 4 m = 5 highways = [ (1, 2, 1), (2, 3, 4), (3, 4, 6), (1, 4, 5), (2, 4, 3) ] assert minimum_total_distance(n, m, highways) == 8 def test_example2(): n = 4 m = 2 highways = [ ...
[ { "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_minimum_distance(n, m, highways):\n \"\"\"\n Returns the minimum total distance required to ensure all towns are connected.\n If it is not p...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00022583", "row_id": 22583, "seed_ids": "[7050, 3276, 1628]" }
0.791955
Codeforces_22583
I
[ "find", "union", "kruskal", "minimum_total_distance" ]
4
[ [ "kruskal", "find" ], [ "kruskal", "union" ], [ "minimum_total_distance", "kruskal" ], [ "union", "find" ] ]
4
[]
false
[]
false
pytest
true
[]
true
caf7803e8d8ed5e481d8c2a798d4be444431a356
bd1338bd027e6d7c8530bd896ccabda338f49d1c
v1.0
instruct
Codeforces
Codeforces_22594_I
The mayor of Codetown is planning to improve the city's transportation system by constructing bridges over several rivers that run through the city. The city can be represented as an undirected graph where nodes represent city blocks and edges represent roads between them, some of which may already have bridges. The m...
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 rootX != rootY: if rank[rootX] > rank[rootY]: parent[rootY] = rootX elif rank[rootX] < ...
from solution import min_cost_to_connect def test_example1(): n = 4 m = 5 bridges = [(1, 2, 1), (2, 3, 2), (3, 4, 3), (1, 4, 4), (2, 4, 5)] assert min_cost_to_connect(n, m, bridges) == 6 def test_example2(): n = 4 m = 2 bridges = [(1, 2, 1), (3, 4, 1)] assert min_cost_to_connect(n, m, ...
[ { "docstring": null, "function_declaration": "def find(parent, i):", "function_name": "find", "parameter_list": "(parent, i)" }, { "docstring": null, "function_declaration": "def union(parent, rank, x, y):", "function_name": "union", "parameter_list": "(parent, rank, x, y)" }, ...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_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 rootX...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00022594", "row_id": 22594, "seed_ids": "[4520, 7099, 6614]" }
0.758492
Codeforces_22594
I
[ "find", "union", "min_cost_to_connect" ]
3
[ [ "min_cost_to_connect", "find" ], [ "min_cost_to_connect", "union" ], [ "union", "find" ] ]
3
[]
false
[]
false
pytest
true
[]
true
4574201ca0fbe1e8e32247efbb82e138080e8482
a0e01f7bebe457c5e7a191a05d477f37ab8c3b98
v1.0
instruct
Codeforces
Codeforces_22613_I
Chris is planning a trip across several cities. Each city is connected by a certain number of roads, each with a specific length. Since Chris values efficiency, he wants to travel the shortest possible path which connects all the cities he plans to visit at least once. This is a classic problem known as the "Traveling ...
def find(parent, i): if parent[i] == i: return i return find(parent, parent[i]) def union(parent, rank, x, y): root_x = find(parent, x) root_y = find(parent, y) if rank[root_x] < rank[root_y]: parent[root_x] = root_y elif rank[root_x] > rank[root_y]: parent[root_y] ...
from solution import minimum_spanning_tree def test_mst_simple(): n = 4 roads = [ (1, 2, 1), (2, 3, 2), (3, 4, 3), (1, 4, 4), (1, 3, 5) ] assert minimum_spanning_tree(n, roads) == 6 def test_mst_disconnected(): n = 3 roads = [ (1, 2, 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, 0, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "class UnionFind:\n def __init__(self, size):\n self.parent = list(range(size))\n self.rank = [0] * size\n\n def find(self, node):\n ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00022613", "row_id": 22613, "seed_ids": "[6230, 5512, 4323]" }
0.716646
Codeforces_22613
I
[ "find", "union", "minimum_spanning_tree" ]
3
[ [ "minimum_spanning_tree", "find" ], [ "minimum_spanning_tree", "union" ], [ "union", "find" ] ]
3
[]
false
[]
false
pytest
true
[]
true
6fda8d2554d952542bd68d01ca30e32f17c2dfce
c08ef40b6bf741bd816a2c117534e09bf9ab6be9
v1.0
instruct
Codeforces
Codeforces_22619_I
Eva has a workshop where she produces custom-made rectangular tiles that have designs printed on them. Each tile is characterized by its width, height, and a specific design. She has n tiles and she wants to organize them into groups where all tiles in a group must be identical in both dimensions and design. Two tiles ...
def count_unique_tile_groups(n, tiles): """ Returns the number of unique groups of tiles after considering possible rotations. Parameters: n (int): Number of tiles tiles (list of tuples): Each tuple contains width, height, and design of a tile Returns: int: Number of unique groups ...
from solution import count_unique_tile_groups_from_input def test_unique_groups_case_1(): input_str = "5\n4 6 star\n6 4 star\n5 7 flower\n7 5 flower\n4 6 moon\n" assert count_unique_tile_groups_from_input(input_str) == 3 def test_unique_groups_case_2(): input_str = "1\n10 20 tree\n" assert count_uniqu...
[ { "docstring": "Returns the number of unique groups of tiles after considering possible rotations.\n\nParameters:\nn (int): Number of tiles\ntiles (list of tuples): Each tuple contains width, height, and design of a tile\n\nReturns:\nint: Number of unique groups of tiles", "function_declaration": "def count...
[ 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 count_unique_tile_groups(n, tiles):\n \"\"\"\n Returns the number of unique groups of tiles after considering possible rotations.\n \n :param ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00022619", "row_id": 22619, "seed_ids": "[2007, 6859, 4698]" }
0.659732
Codeforces_22619
I
[ "count_unique_tile_groups", "count_unique_tile_groups_from_input" ]
2
[ [ "count_unique_tile_groups_from_input", "count_unique_tile_groups" ] ]
1
[]
false
[]
false
pytest
true
[]
true
37f5436c8ab73a7b5a0639e1c30884ad109e1bc8
cdd483752af947c2bc214af2731484f1fe3d5d53
v1.0
instruct
Codeforces
Codeforces_22671_I
You are given an undirected graph consisting of `n` nodes and `m` edges, and the graph represents a network of cities and roads. Each node represents a city, and each edge represents a road connecting two cities. Your task is to find the minimum number of roads that need to be added so that the graph becomes fully conn...
def find_connected_components(n, edges): """ Returns a list of connected components in an undirected graph represented by `n` nodes and given edges. """ from collections import defaultdict, deque def bfs(start, visited, adj_list): queue = deque([start]) component = [] ...
from solution import min_roads_to_connect def test_example_case(): n = 6 m = 3 edges = [(1, 2), (1, 3), (4, 5)] assert min_roads_to_connect(n, edges) == 2 def test_no_edges(): n = 4 m = 0 edges = [] assert min_roads_to_connect(n, edges) == 3 def test_already_connected(): n = 4...
[ { "docstring": "Returns a list of connected components in an undirected graph\nrepresented by `n` nodes and given edges.", "function_declaration": "def find_connected_components(n, edges):", "function_name": "find_connected_components", "parameter_list": "(n, edges)" }, { "docstring": "Retur...
[ 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(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_2
{ "original_instruction": "", "prompt_id": "00022671", "row_id": 22671, "seed_ids": "[6566, 269, 4620]" }
0.754329
Codeforces_22671
I
[ "find_connected_components", "min_roads_to_connect" ]
2
[ [ "min_roads_to_connect", "find_connected_components" ] ]
1
[]
false
[]
false
pytest
true
[]
true
8b077cfe9633b825e125197a0ff3b56f74c6c0e5
8adfdecf033b485c7425ce734b1af84669eb9b11
v1.0
instruct
Codeforces
Codeforces_22687_I
A kingdom has n castles and m roads between them. Each road has a unique length. An enemy plans to capture the kingdom by taking control of a set of castles including at least one castle at each end of some road. To defend the kingdom, you must construct a defense wall that minimizes the sum of the lengths of the roads...
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_min_defense_wall(): n, m = 4, 5 roads = [ (1, 2, 3), (1, 3, 1), (2, 3, 5), (3, 4, 4), (2, 4, 2) ] assert min_defense_wall(n, m, roads) == 6 def test_min_defense_wall_small(): n, m = 2, 1 roads = [(1, 2, 1)] assert min_defense_wall(n, m, 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, 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 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 root_x = find(parent...
trial_gpt4o_3
{ "original_instruction": "", "prompt_id": "00022687", "row_id": 22687, "seed_ids": "[4226, 7898, 3]" }
0.667558
Codeforces_22687
I
[ "find", "union", "kruskal", "min_defense_wall" ]
4
[ [ "kruskal", "find" ], [ "kruskal", "union" ], [ "min_defense_wall", "kruskal" ], [ "union", "find" ] ]
4
[]
false
[]
false
pytest
false
[]
true
d80d70215e31d51d42d03fb8ce7c9e06c82436c2
deea7c062283ef0bc38617623dc4ac75b5a392cb
v1.0
instruct
Codeforces
Codeforces_22749_I
Peter is a security manager at a popular tech company. He is responsible for monitoring the company's system logs and identifying potential unauthorized access attempts. The company's security system logs all login attempts in a specific format and Peter needs to analyze these logs to detect any suspicious activities. ...
from collections import defaultdict from datetime import datetime, timedelta def parse_time(time_str): return datetime.strptime(time_str, '%H:%M') def find_suspicious_users(log_entries): user_attempts = defaultdict(list) suspicious_users = set() # Fill the user_attempts dictionary for entry i...
from solution import process_logs def test_example_case(): n = 10 logs = [ "09:00 1234 failure", "09:10 1234 failure", "09:20 1234 failure", "10:00 5678 failure", "10:15 5678 failure", "10:30 5678 success", "11:00 5678 failure", "11:05 5678 failur...
[ { "docstring": null, "function_declaration": "def parse_time(time_str):", "function_name": "parse_time", "parameter_list": "(time_str)" }, { "docstring": null, "function_declaration": "def find_suspicious_users(log_entries):", "function_name": "find_suspicious_users", "parameter_...
[ 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\nfrom datetime import datetime, timedelta\n\ndef parse_time(time_str):\n return datetime.strptime(time_str, '%H:%M')\n\...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00022749", "row_id": 22749, "seed_ids": "[196, 3410, 3147]" }
0.578198
Codeforces_22749
I
[ "parse_time", "find_suspicious_users", "process_logs" ]
3
[ [ "find_suspicious_users", "parse_time" ], [ "process_logs", "find_suspicious_users" ] ]
2
[]
false
[]
false
pytest
true
[]
true
b612733dfc0815b2d3dadd5dad60a1d6c96e729b
6c35ecede5a9d247b13165ec5d64963eff7ee3be
v1.0
instruct
Codeforces
Codeforces_22759_I
In the land of Algoria, there is a peculiar type of forest consisting of trees that can communicate with each other. Each tree is an intelligent node in a network, and they are connected by unique bidirectional communication channels. The trees communicate by passing signals, and they need your help to determine the sh...
import heapq from collections import defaultdict, deque def count_shortest_paths(n, m, edges): graph = defaultdict(list) for x, y, w in edges: graph[x].append((y, w)) graph[y].append((x, w)) # Dijkstra's algorithm to find shortest path distances def dijkstra(source): distan...
from solution import count_shortest_paths def test_sample_input(): edges = [(1, 2, 1), (2, 3, 2), (1, 3, 3), (3, 4, 2)] assert count_shortest_paths(4, 4, edges) == 2 def test_single_path(): edges = [(1, 2, 1), (2, 3, 1)] assert count_shortest_paths(3, 2, edges) == 1 def test_multiple_same_length_path...
[ { "docstring": null, "function_declaration": "def count_shortest_paths(n, m, edges):", "function_name": "count_shortest_paths", "parameter_list": "(n, m, edges)" }, { "docstring": null, "function_declaration": "def solve():", "function_name": "solve", "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\nfrom collections import defaultdict, deque\n\ndef count_shortest_paths(n, m, edges):\n graph = defaultdict(list)\n for x, y, w in edges:\n...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00022759", "row_id": 22759, "seed_ids": "[7903, 6954, 7749]" }
0.640697
Codeforces_22759
I
[ "count_shortest_paths", "solve" ]
2
[ [ "solve", "count_shortest_paths" ] ]
1
[]
false
[]
false
pytest
true
[]
true
ef0aab3f949fe1ae30891d023db65cea728745fe
b6f31a82fe78faf5cd245a53f2d51a7c02d21965
v1.0
instruct
Codeforces
Codeforces_22781_I
A monotonic array is an array where the elements are either entirely non-increasing or non-decreasing. Given an integer array, determine whether this array is monotonic or not. The first line of input contains an integer n (1 ≤ n ≤ 1000) — the number of elements in the array. The second line contains n integers separa...
def is_monotonic(arr): """ Returns "YES" if the array is monotonic, otherwise returns "NO". """ if len(arr) <= 1: # An array with 0 or 1 element is trivially monotonic return "YES" increasing = decreasing = True # Assume array is both for i in range(1, len(arr)): if arr[i...
from solution import monotonic_array def test_monotonic_increasing(): assert monotonic_array(5, [1, 2, 2, 3, 4]) == "YES" assert monotonic_array(4, [1, 2, 3, 4]) == "YES" def test_monotonic_decreasing(): assert monotonic_array(5, [5, 4, 3, 2, 1]) == "YES" assert monotonic_array(4, [3, 2, 1, 1]) == "YE...
[ { "docstring": "Returns \"YES\" if the array is monotonic, otherwise returns \"NO\".", "function_declaration": "def is_monotonic(arr):", "function_name": "is_monotonic", "parameter_list": "(arr)" }, { "docstring": null, "function_declaration": "def monotonic_array(n, arr):", "functio...
[ 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 is_monotonic(arr):\n \"\"\"\n Returns 'YES' if the array is monotonic (either entirely non-increasing or non-decreasing),\n otherwise returns 'NO...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00022781", "row_id": 22781, "seed_ids": "[6093, 5436, 1134]" }
0.78225
Codeforces_22781
I
[ "is_monotonic", "monotonic_array" ]
2
[ [ "monotonic_array", "is_monotonic" ] ]
1
[]
false
[]
false
pytest
true
[]
true
3d01c7cc733e7b3f6cf27bbf60a998ada4747351
fe880d6f3e5d53f97cf540c09e71cc55abbfef7c
v1.0
instruct
Codeforces
Codeforces_22837_I
You are given an undirected, connected graph with n vertices and m edges. Each edge has a positive integer weight. Your task is to find the minimum spanning tree (MST) of this graph, and then determine the second smallest spanning tree. The second smallest spanning tree is defined as the spanning tree with the smallest...
import heapq def find(parent, i): if parent[i] == i: return i return find(parent, parent[i]) def union(parent, rank, x, y): rootx = find(parent, x) rooty = find(parent, y) if rank[rootx] < rank[rooty]: parent[rootx] = rooty elif rank[rootx] > rank[rooty]: parent[rooty] ...
def test_simple_case(): n, edges = 4, [(0, 1, 3), (0, 2, 1), (0, 3, 4), (1, 2, 2), (2, 3, 5)] assert second_best_mst(n, edges) == 8 def test_no_second_mst(): n, edges = 3, [(0, 1, 1), (0, 2, 1), (1, 2, 1)] assert second_best_mst(n, edges) == -1 def test_large_case(): n, edges = 4, [(0, 1, 1), (0, ...
[ { "docstring": null, "function_declaration": "def find(parent, i):", "function_name": "find", "parameter_list": "(parent, i)" }, { "docstring": null, "function_declaration": "def union(parent, rank, x, y):", "function_name": "union", "parameter_list": "(parent, rank, x, y)" }, ...
[ 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": "class UnionFind:\n def __init__(self, size):\n self.parent = list(range(size))\n self.rank = [0] * size\n \n def find(self, node):\n ...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00022837", "row_id": 22837, "seed_ids": "[3107, 4648, 3709]" }
0.819201
Codeforces_22837
I
[ "find", "union", "kruskal", "second_best_mst", "parse_input" ]
5
[ [ "kruskal", "find" ], [ "kruskal", "union" ], [ "second_best_mst", "kruskal" ], [ "union", "find" ] ]
4
[ "parse_input" ]
false
[]
false
pytest
false
[]
true
014d74bf8c0135c1f9f70a10c19afed57a0bfbec
0d32dbf8d601adbce2d9d8b614256ffd9e7a5f69
v1.0
instruct
Codeforces
Codeforces_22858_I
Given a sequence of integers, you are allowed to perform a certain operation multiple times to transform the sequence. The operation consists of choosing any two adjacent elements of the sequence and swapping them. You are required to sort the sequence in a non-decreasing order using the minimum number of these operati...
def count_inversions(arr): """ Function to count number of inversions in the array using merge sort. """ if len(arr) < 2: return 0 mid = len(arr) // 2 left = arr[:mid] right = arr[mid:] inversions = count_inversions(left) + count_inversions(right) i = j = k = 0 while i...
def test_count_inversions(): assert count_inversions([4, 3, 2, 1, 5, 6]) == 6 assert count_inversions([1, 2, 4, 3]) == 1 assert count_inversions([5, 4, 3, 2, 1]) == 10 assert count_inversions([1, 3, 2, 4, 5, 6]) == 1 assert count_inversions([1, 2, 3, 4, 5]) == 0 def test_minimum_swaps_to_sort(): ...
[ { "docstring": "Function to count number of inversions in the array using merge sort.", "function_declaration": "def count_inversions(arr):", "function_name": "count_inversions", "parameter_list": "(arr)" }, { "docstring": null, "function_declaration": "def minimum_swaps_to_sort(arr):", ...
[ 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 count_inversions(arr):\n \"\"\"\n Function to count number of inversions in the array using merge sort.\n \"\"\"\n if len(arr) < 2:\n r...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00022858", "row_id": 22858, "seed_ids": "[5185, 3907, 3339]" }
0.78318
Codeforces_22858
I
[ "count_inversions", "minimum_swaps_to_sort" ]
2
[ [ "minimum_swaps_to_sort", "count_inversions" ] ]
1
[]
false
[]
false
pytest
false
[]
true
dd51959f3449b7ee07ed716cd151eea874f72a5b
a7510fd8298cbc615e19c5372d66ab8c17957c6c
v1.0
instruct
Codeforces
Codeforces_22892_I
Simon has a list of pet names with `n` names. He wants to determine if there is any pair of names that when concatenated (first concatenated with second or second concatenated with first) forms a palindrome. Two names form a palindrome if the concatenation of these two names reads the same forwards and backwards, e.g....
def is_palindrome(s): """ Returns True if the string s is a palindrome, False otherwise. """ return s == s[::-1] def find_palindrome_pair(pet_names): """ Returns "Yes" if there exists a pair of names that when concatenated forms a palindrome, otherwise "No". """ n = len(pet_names) f...
from solution import find_palindrome_pair def test_basic_cases(): assert find_palindrome_pair(["cat", "tac", "dog"]) == "Yes" assert find_palindrome_pair(["cat", "dog", "mouse"]) == "No" def test_single_pair(): assert find_palindrome_pair(["race", "car"]) == "Yes" assert find_palindrome_pair(["car", "...
[ { "docstring": "Returns True if the string s is a palindrome, False otherwise.", "function_declaration": "def is_palindrome(s):", "function_name": "is_palindrome", "parameter_list": "(s)" }, { "docstring": "Returns \"Yes\" if there exists a pair of names that when concatenated forms a palind...
[ 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 has_palindrome_pair(names):\n \"\"\"\n Determines if there exists any pair of names in the list that when \n concatenated forms a palindrome.\n ...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00022892", "row_id": 22892, "seed_ids": "[120, 7659, 1908]" }
0.821827
Codeforces_22892
I
[ "is_palindrome", "find_palindrome_pair" ]
2
[ [ "find_palindrome_pair", "is_palindrome" ] ]
1
[]
false
[]
false
pytest
true
[]
true
abfab8c5ab2e05c5fce6be5e365277aa2d93312e
f4188b5de974df8237590e8a49296c77fb4712c7
v1.0
instruct
Codeforces
Codeforces_22927_I
Alice is a big fan of palindromes. A palindrome is a string that reads the same forward and backward. She loves to create palindromes from other strings. She has a string s consisting of lowercase English letters. Alice wants to split the string into the minimal number of substrings such that each substring is a pali...
def min_palindromic_substrings(s): """ This method calculates the minimum number of palindromic substrings needed to split the string s. """ n = len(s) dp = [float('inf')] * n palindrome = [[False] * n for _ in range(n)] for i in range(n): palindrome[i][i] = True for le...
from solution import string_to_min_palindromic_substrings def test_example_case(): assert string_to_min_palindromic_substrings(7, "aabacaa") == 4 def test_single_character(): assert string_to_min_palindromic_substrings(1, "a") == 1 def test_all_unique_characters(): assert string_to_min_palindromic_substr...
[ { "docstring": "This method calculates the minimum number of palindromic substrings needed to split the string s.", "function_declaration": "def min_palindromic_substrings(s):", "function_name": "min_palindromic_substrings", "parameter_list": "(s)" }, { "docstring": null, "function_decla...
[ 0, 0, 0, 0, 1, 1, 0, 0, 1 ]
3
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def min_palindromic_substrings(n, s):\n def is_palindrome(x):\n return x == x[::-1]\n \n dp = [float('inf')] * n\n for i in range(n):\n ...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00022927", "row_id": 22927, "seed_ids": "[2757, 1142, 7609]" }
0.826293
Codeforces_22927
I
[ "min_palindromic_substrings", "string_to_min_palindromic_substrings" ]
2
[ [ "string_to_min_palindromic_substrings", "min_palindromic_substrings" ] ]
1
[]
false
[]
false
pytest
true
[]
true
40d87c6495326c1cff99bb0fcf9907d542d4087c
95ce436c0ccd884232de0f3ac3c314df99b22aeb
v1.0
instruct
Codeforces
Codeforces_22952_I
During a cultural festival, a city has decided to lay out a network of footpaths connecting various points of interest such as parks, museums, and squares. Each footpath has a certain length, and the objective is to make sure that people can walk between any two points of interest without retracing their steps over a p...
def find(parent, i): if parent[i] == i: return i return find(parent, parent[i]) def union(parent, rank, x, y): rootX = find(parent, x) rootY = find(parent, y) if rootX != rootY: if rank[rootX] > rank[rootY]: parent[rootY] = rootX elif rank[rootX] < rank[root...
def test_minimum_spanning_tree(): n = 4 edges = [ (0, 1, 1), (0, 2, 4), (1, 2, 2), (2, 3, 3), (0, 3, 5) ] assert minimum_spanning_tree(n, edges) == 6 def test_minimum_spanning_tree_disconnected(): n = 4 edges = [ (0, 1, 1), (2, 3, 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)" }, ...
[ 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": "00022952", "row_id": 22952, "seed_ids": "[2939, 336, 344]" }
0.706264
Codeforces_22952
I
[ "find", "union", "minimum_spanning_tree", "read_input", "main" ]
5
[ [ "minimum_spanning_tree", "find" ], [ "minimum_spanning_tree", "union" ], [ "union", "find" ] ]
3
[ "read_input" ]
false
[]
false
pytest
false
[]
true
0073c3373efe9b20ce1d2bce84943f2b35172679
2e90bbc071f458cc082e5771d87713d97d1d0e2e
v1.0
instruct
Codeforces
Codeforces_23012_I
A kingdom is divided into several cities connected by roads. Each road has a specific time cost associated with it. The king of the kingdom wants to ensure that there are multiple routes available between his capital city and every other city to avoid any situation where a single road failure would cut off some cities ...
from collections import defaultdict, deque def bfs(graph, start): queue = deque([start]) visited = {start} parent = {start: None} while queue: node = queue.popleft() for neighbor in graph[node]: if neighbor not in visited: visited.add(neighbor) ...
def test_example1(): n = 5 m = 6 roads = [ (1, 2, 4), (1, 3, 2), (2, 3, 1), (2, 4, 5), (3, 5, 3), (4, 5, 2) ] result = multiple_paths_possible(n, m, roads) assert result == "YES" def test_example2(): n = 4 m = 3 roads = [ (1, 2...
[ { "docstring": null, "function_declaration": "def bfs(graph, start):", "function_name": "bfs", "parameter_list": "(graph, start)" }, { "docstring": null, "function_declaration": "def second_bfs(graph, start, exclude_edge):", "function_name": "second_bfs", "parameter_list": "(grap...
[ 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": "from collections import defaultdict, deque\n\ndef is_two_disjoint_paths_possible(n, m, roads):\n graph = defaultdict(list)\n \n for u, v, t in roads:...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00023012", "row_id": 23012, "seed_ids": "[7237, 5270, 3251]" }
0.781198
Codeforces_23012
I
[ "bfs", "second_bfs", "multiple_paths_possible" ]
3
[ [ "multiple_paths_possible", "bfs" ], [ "multiple_paths_possible", "second_bfs" ] ]
2
[]
false
[]
false
pytest
false
[]
true
f6e5d51c226678758920bbfc1cc272c0f2d5741c
7e4e8d9ef2cb771d0e47960cb920525a1a93055c
v1.0
instruct
Codeforces
Codeforces_23023_I
Vladik loves graphs and he came up with an interesting problem involving bipartite graphs. Given a bipartite graph represented by two sets of vertices $$$U$$$ and $$$V$$$ with edges only between vertices in $$$U$$$ and vertices in $$$V$$$, Vladik wants to find a perfect matching, if one exists. A perfect matching is a ...
def bpm(u, match_result, visited, adj): for v in adj[u]: if not visited[v]: visited[v] = True if match_result[v] == -1 or bpm(match_result[v], match_result, visited, adj): match_result[v] = u return True return False def is_perfect_matching(n, m, ...
def test_is_perfect_matching_case1(): adj = [[], [1, 2], [1, 3], [2, 3]] n = 3 m = 3 assert solve(n, m, adj) == "YES" def test_is_perfect_matching_case2(): adj = [[], [1], [2], [2]] n = 3 m = 3 assert solve(n, m, adj) == "NO" def test_is_perfect_matching_case3(): adj = [[], [1], [2...
[ { "docstring": null, "function_declaration": "def bpm(u, match_result, visited, adj):", "function_name": "bpm", "parameter_list": "(u, match_result, visited, adj)" }, { "docstring": null, "function_declaration": "def is_perfect_matching(n, m, adj):", "function_name": "is_perfect_matc...
[ 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 find_perfect_matching(n, m, adjacency_list):\n # Helper function to perform DFS and find augmenting paths\n def dfs(u):\n for v in adjacency_...
trial_gpt4o_6
{ "original_instruction": "", "prompt_id": "00023023", "row_id": 23023, "seed_ids": "[3571, 7934, 2945]" }
0.535116
Codeforces_23023
I
[ "bpm", "is_perfect_matching", "solve" ]
3
[ [ "is_perfect_matching", "bpm" ], [ "solve", "is_perfect_matching" ] ]
2
[]
false
[]
false
pytest
false
[]
true
6ab6b107c82cf25909b98b011725979cf8e08d78
ae86b330ff9f79110298b1efe2aae5f89a9ef0ee
v1.0
instruct
Codeforces
Codeforces_23028_I
You are given an undirected graph with $$$n$$$ nodes labeled from $$$1$$$ to $$$n$$$ and $$$m$$$ edges. Each edge connects two distinct nodes. Additionally, there are $$$q$$$ queries, each asking whether there is a path between two specified nodes in the graph. The input consists of multiple test cases. The first line...
def find_components(n, edges): """ Uses DFS to find components in an undirected graph. """ graph = {i: [] for i in range(1, n + 1)} for u, v in edges: graph[u].append(v) graph[v].append(u) visited = [False] * (n + 1) component = [-1] * (n + 1) def dfs(node, comp...
def test_solution_case1(): input_str = "1\n5 3\n1 2\n2 3\n4 5\n3\n1 3\n1 4\n4 5" expected_output = "YES\nNO\nYES" assert main(input_str.strip()) == expected_output def test_solution_case2(): input_str = "1\n4 2\n1 2\n3 4\n2\n1 4\n2 3" expected_output = "NO\nNO" assert main(input_str.strip()) ==...
[ { "docstring": "Uses DFS to find components in an undirected graph.", "function_declaration": "def find_components(n, edges):", "function_name": "find_components", "parameter_list": "(n, edges)" }, { "docstring": null, "function_declaration": "def solve(test_cases):", "function_name"...
[ 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 else:\n parent[i] = find(parent, parent[i])\n return parent[i]\n\ndef union(...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00023028", "row_id": 23028, "seed_ids": "[5473, 5547, 5608]" }
0.775583
Codeforces_23028
I
[ "find_components", "solve", "main" ]
3
[ [ "solve", "find_components" ] ]
1
[]
false
[]
false
pytest
false
[]
true
6e512f8c1cb1307a2ecd2757c8728ba4e1ff49cf
ae39ddf450f580333a8f10df8576631f6ef0ce61
v1.0
instruct
Codeforces
Codeforces_23029_I
You are given an undirected graph with n vertices and m edges. Each edge has an associated weight. You need to find the maximum spanning tree of the given graph. A spanning tree is a subgraph that connects all the vertices together without creating any cycles and uses all n vertices. The maximum spanning tree is the sp...
def find(parent, i): if parent[i] == i: return i else: return find(parent, parent[i]) def union(parent, rank, x, y): xroot = find(parent, x) yroot = find(parent, y) if rank[xroot] < rank[yroot]: parent[xroot] = yroot elif rank[xroot] > rank[yroot]: parent[yr...
from solution import solution def test_example_case(): input_data = "4 5\n1 2 4\n2 3 2\n3 4 7\n4 1 3\n1 3 6" assert solution(input_data) == 17 def test_single_edge(): input_data = "2 1\n1 2 10" assert solution(input_data) == 10 def test_small_graph_multiple_edges(): input_data = "3 3\n1 2 5\n2 3 ...
[ { "docstring": null, "function_declaration": "def find(parent, i):", "function_name": "find", "parameter_list": "(parent, i)" }, { "docstring": null, "function_declaration": "def union(parent, rank, x, y):", "function_name": "union", "parameter_list": "(parent, rank, x, y)" }, ...
[ 1, 1, 1 ]
3
easy
1
{ "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 = [0] * n\n \n def find(self, u):\n ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00023029", "row_id": 23029, "seed_ids": "[3086, 4804, 5043]" }
0.707014
Codeforces_23029
I
[ "find", "union", "maximum_spanning_tree", "solution" ]
4
[ [ "maximum_spanning_tree", "find" ], [ "maximum_spanning_tree", "union" ], [ "solution", "maximum_spanning_tree" ], [ "union", "find" ] ]
4
[]
false
[]
false
pytest
true
[]
true
0240ae3c9177436c6de48d01834d6167a9fd01a9
ef7241c97a1a999a816bea1a538a7540b29b76cf
v1.0
instruct
Codeforces
Codeforces_23058_I
Consider a grid of size n x m where each cell contains an integer value. You are given q queries, and each query consists of four integers x1, y1, x2, and y2 representing the coordinates of two diagonally opposite corners of a rectangular sub-grid. For each query, your task is to find the sum of all integers in that su...
def preprocess_grid(grid, n, m): # Create an auxiliary sum matrix sum_matrix = [[0] * (m + 1) for _ in range(n + 1)] # Precomputing the sum of sub-grids using prefix sum method for i in range(1, n + 1): for j in range(1, m + 1): sum_matrix[i][j] = grid[i - 1][j - 1] + \ ...
def test_given_example(): grid = [ [1, 2, 3], [4, 5, 6], [7, 8, 9] ] queries = [ (1, 1, 2, 2), (2, 2, 3, 3) ] expected_result = [12, 28] results = process_queries(grid, queries) assert results == expected_result def test_single_element_query(): gr...
[ { "docstring": null, "function_declaration": "def preprocess_grid(grid, n, m):", "function_name": "preprocess_grid", "parameter_list": "(grid, n, m)" }, { "docstring": null, "function_declaration": "def subgrid_sum(sum_matrix, x1, y1, x2, y2):", "function_name": "subgrid_sum", "p...
[ 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 calculate_prefix_sum(grid, n, m):\n prefix_sum = [[0] * (m + 1) for _ in range(n + 1)]\n \n for i in range(1, n + 1):\n for j in range(1, ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00023058", "row_id": 23058, "seed_ids": "[293, 5688, 2746]" }
0.713787
Codeforces_23058
I
[ "preprocess_grid", "subgrid_sum", "process_queries" ]
3
[ [ "process_queries", "preprocess_grid" ], [ "process_queries", "subgrid_sum" ] ]
2
[ "process_queries" ]
false
[]
false
pytest
false
[]
true
75b867d6907b81fb031e307e445bf173f2011850
5874afcd33219374000b73f086158790ca2f6d17
v1.0
instruct
Codeforces
Codeforces_23064_I
There is a country with n cities and m bidirectional roads connecting some pairs of cities. Each road has a certain length and the country forms a connected graph. The president wants to build a binary communication network that connects all the cities directly or indirectly. The communication network must only use co...
def find_parent(parent, i): if parent[i] == i: return i 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 root_x != root_y: if rank[root_x] > rank[root_y]: parent[root_y] = root_x ...
def test_communication_network(): from solution import build_communication_network import sys from io import StringIO test_input = "4 5\n1 2 1\n1 3 4\n2 3 2\n3 4 5\n2 4 3\n" expected_output = "6\n1 2\n2 3\n2 4\n" sys.stdin = StringIO(test_input) sys.stdout = StringIO() ...
[ { "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, 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(parent, i):\n if parent[i] == i:\n return i\n return find_parent(parent, parent[i])\n\ndef union(parent, rank, x, y):\n root_x...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00023064", "row_id": 23064, "seed_ids": "[4470, 5192, 1355]" }
0.715248
Codeforces_23064
I
[ "find_parent", "union", "kruskal", "build_communication_network" ]
4
[ [ "build_communication_network", "kruskal" ], [ "kruskal", "find_parent" ], [ "kruskal", "union" ], [ "union", "find_parent" ] ]
4
[]
false
[]
false
pytest
true
[]
true
8d33c629d69871ec04480613711709923c02f20f
122525f0bd4415b429b991e85a7cc08e7a3142ad
v1.0
instruct
Codeforces
Codeforces_23099_I
Petra loves driving through the city and often needs to find the shortest path between two points. She’s using a navigation app that displays a directed graph where intersections are represented as nodes and roads as directed edges with specific travel times. However, the app doesn’t always point out the quickest ways ...
import heapq def dijkstra(n, graph, start): dist = [float('inf')] * (n + 1) dist[start] = 0 pq = [(0, start)] # (distance, node) while pq: current_distance, current_node = heapq.heappop(pq) if current_distance > dist[current_node]: continue fo...
from solution import shortest_paths def test_shortest_paths_example(): n = 4 m = 4 edges = [(1, 2, 3), (2, 3, 4), (3, 4, 5), (1, 4, 10)] q = 2 queries = [(1, 4), (3, 2)] result = shortest_paths(n, edges, queries) assert result == [10, -1] def test_shortest_paths_no_edges(): n = 4 m...
[ { "docstring": null, "function_declaration": "def dijkstra(n, graph, start):", "function_name": "dijkstra", "parameter_list": "(n, graph, start)" }, { "docstring": null, "function_declaration": "def shortest_paths(n, edges, queries):", "function_name": "shortest_paths", "paramete...
[ 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(n, graph, start):\n dist = [float('inf')] * (n + 1)\n dist[start] = 0\n pq = [(0, start)] # (distance, node)\n \n ...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00023099", "row_id": 23099, "seed_ids": "[4334, 469, 2323]" }
0.767393
Codeforces_23099
I
[ "dijkstra", "shortest_paths" ]
2
[ [ "shortest_paths", "dijkstra" ] ]
1
[]
false
[]
false
pytest
true
[]
true
0ab006bd2a9cb025a3970c3c3a7217883c429457
7824c3a0561c59fcabc2d7f1504f7b8c4d3f83e3
v1.0
instruct
Codeforces
Codeforces_23106_I
You're given a grid of size `n x m` where each cell can either be passable or impassable. A passable cell is represented by a '.' and an impassable cell is represented by a '#'. You need to help a robot navigate from the top-left corner of the grid to the bottom-right corner. The robot can move one cell up, down, left,...
from collections import deque def can_reach_with_k_turns(n, m, k, grid): directions = [(0, 1), (1, 0), (0, -1), (-1, 0)] # right, down, left, up def is_valid(x, y): return 0 <= x < n and 0 <= y < m and grid[x][y] == '.' queue = deque([(0, 0, 0, -1)]) # (x, y, turns, direction_index) visited...
def test_can_reach_with_k_turns_1(): n = 4 m = 4 k = 2 grid = [ "....", ".#..", "..#.", "...." ] assert solve(n, m, k, grid) == "YES" def test_can_reach_with_k_turns_2(): n = 4 m = 4 k = 1 grid = [ "....", ".#..", "..#.", ...
[ { "docstring": null, "function_declaration": "def can_reach_with_k_turns(n, m, k, grid):", "function_name": "can_reach_with_k_turns", "parameter_list": "(n, m, k, grid)" }, { "docstring": null, "function_declaration": "def solve(n, m, k, grid):", "function_name": "solve", "parame...
[ 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 can_robot_reach_with_k_turns(n, m, k, grid):\n from collections import deque\n \n # Direction vectors for moving in four possible directions\n ...
trial_gpt4o_4
{ "original_instruction": "", "prompt_id": "00023106", "row_id": 23106, "seed_ids": "[5142, 2622, 2238]" }
0.715277
Codeforces_23106
I
[ "can_reach_with_k_turns", "solve" ]
2
[ [ "solve", "can_reach_with_k_turns" ] ]
1
[]
false
[]
false
pytest
false
[]
true
76a73fcbba8487d7949374b63782635a774347e3
4cb84398acb0f2da1f2221c3fad42f750442527d
v1.0
instruct
Codeforces
Codeforces_23215_I
You are given an undirected graph with n vertices and m edges. Each edge has an associated cost. You are required to find the Minimum Spanning Tree (MST) of the graph and determine the total cost of this MST. Additionally, you must answer several queries regarding the graph. Each query consists of three integers u, v, ...
import heapq def find(parent, i): if parent[i] == i: return i else: parent[i] = find(parent, parent[i]) return parent[i] def union(parent, rank, x, y): root_x = find(parent, x) root_y = find(parent, y) if root_x != root_y: if rank[root_x] > rank[root_y]: ...
from solution import minimum_spanning_tree def test_given_example(): n = 5 m = 7 edges = [ (1, 2, 2), (2, 3, 3), (3, 4, 1), (4, 5, 4), (5, 1, 6), (1, 3, 5), (2, 4, 7) ] queries = [ (1, 5, 2), (2, 4, 1), (3, 5, 8) ] ...
[ { "docstring": null, "function_declaration": "def find(parent, i):", "function_name": "find", "parameter_list": "(parent, i)" }, { "docstring": null, "function_declaration": "def union(parent, rank, x, y):", "function_name": "union", "parameter_list": "(parent, rank, x, y)" }, ...
[ 0, 0, 0, 0, 0, 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": "import heapq\n\ndef prims_algorithm(n, edges):\n \"\"\"\n Function to calculate the MST total cost using Prim's Algorithm\n \"\"\"\n adj = [[] for...
trial_gpt4o_5
{ "original_instruction": "", "prompt_id": "00023215", "row_id": 23215, "seed_ids": "[6323, 6859, 2342]" }
0.849531
Codeforces_23215
I
[ "find", "union", "kruskal", "minimum_spanning_tree" ]
4
[ [ "kruskal", "find" ], [ "kruskal", "union" ], [ "minimum_spanning_tree", "kruskal" ], [ "union", "find" ] ]
4
[]
false
[]
false
pytest
true
[]
true
294c32171fc77b7db1f721aee540d2e401e74f05
7554a655120067a9424d3cefe4340b3615440696
v1.0
instruct
Codeforces
Codeforces_23260_I
Alice is organizing a series of games with her friends. Each game has multiple rounds, and each round can be won by one of the participants, earning them a certain number of points. The participant with the highest total score at the end of all rounds wins the game. Alice realizes that sometimes a simple win-loss tal...
def calculate_winner(scores): n = len(scores) m = len(scores[0]) total_scores = [(i + 1, sum(participant_scores)) for i, participant_scores in enumerate(scores)] total_scores.sort(key=lambda x: x[1], reverse=True) top_two = total_scores[:2] winner = max(top_two, key=lambda x: x[1]) return...
from solution import find_winner def test_find_winner_example(): assert find_winner(3, 4, [ [10, 20, 30, 40], [5, 15, 25, 35], [8, 18, 28, 38] ]) == 1 def test_find_winner_close_scores(): assert find_winner(4, 3, [ [10, 20, 30], [13, 22, 25], [12, 21, 29...
[ { "docstring": null, "function_declaration": "def calculate_winner(scores):", "function_name": "calculate_winner", "parameter_list": "(scores)" }, { "docstring": "Determines the winner based on total scores of the top two participants.\n\nn: int - number of participants\nm: int - number of r...
[ 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_winner(n, m, scores):\n \"\"\"\n Determines the winner based on the sum of scores among the top two participants.\n \n Args:\n n : int...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00023260", "row_id": 23260, "seed_ids": "[4932, 5507, 1745]" }
0.7432
Codeforces_23260
I
[ "calculate_winner", "find_winner" ]
2
[ [ "find_winner", "calculate_winner" ] ]
1
[]
false
[]
false
pytest
true
[]
true
8868f5a7942f8543521404d515c353503c07cb3b
c1bc44f4e17ba0be61da2f207754cfad352e086c
v1.0
instruct
Codeforces
Codeforces_23291_I
You have been given a sequence of N distinct integers. Your task is to determine the length of the longest subsequence where the elements of the subsequence are prime numbers that can be arranged in increasing order. A subsequence is derived by deleting some or no elements from the original sequence without rearrangin...
def is_prime(num): if num <= 1: return False for i in range(2, int(num**0.5) + 1): if num % i == 0: return False return True def longest_prime_subsequence(sequence): prime_sequence = [num for num in sequence if is_prime(num)] if not prime_sequence: return 0 ...
from solution import process_input def test_example1(): n = 10 sequence = [3, 10, 7, 9, 11, 4, 5, 2, 8, 13] assert process_input(n, sequence) == 4 def test_example2(): n = 6 sequence = [16, 36, 12, 18, 19, 37] assert process_input(n, sequence) == 2 def test_no_primes(): n = 5 sequence...
[ { "docstring": null, "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": null, "function_declaration": "def longest_prime_subsequence(sequence):", "function_name": "longest_prime_subsequence", "parameter_list": "(...
[ 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 is_prime(n):\n \"\"\"\n Check if a number is prime.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return True\n if n...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00023291", "row_id": 23291, "seed_ids": "[4284, 1192, 5964]" }
0.769746
Codeforces_23291
I
[ "is_prime", "longest_prime_subsequence", "process_input" ]
3
[ [ "longest_prime_subsequence", "is_prime" ], [ "process_input", "longest_prime_subsequence" ] ]
2
[ "process_input" ]
false
[]
false
pytest
true
[]
true
ee7d19591952b7d4f4c38adc91b1db44cdcb9044
62be633a9bf07fa67cdaedc6519c2385fb1167ff
v1.0
instruct
Codeforces
Codeforces_23306_I
There is an island kingdom with several interconnected cities. The king wants to construct roads such that every city in the kingdom is accessible from any other city. He also wants to minimize the total cost of road construction. You are provided with a map of the kingdom. The map consists of $$$n$$$ cities and $$$m$...
def find(parent, i): if parent[i] == i: return i return find(parent, parent[i]) def union(parent, rank, x, y): rootx = find(parent, x) rooty = find(parent, y) if rootx != rooty: if rank[rootx] > rank[rooty]: parent[rooty] = rootx elif rank[rootx] < rank[rooty]: ...
from solution import minimum_cost_to_connect def test_minimum_cost_to_connect_basic(): assert minimum_cost_to_connect(3, 3, [(1, 2, 1), (2, 3, 1), (1, 3, 2)]) == 2 assert minimum_cost_to_connect(4, 5, [(1, 2, 1), (2, 3, 1), (3, 4, 1), (4, 1, 1), (1, 3, 3)]) == 3 def test_minimum_cost_to_connect_impossible(): ...
[ { "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 rootx = find(parent,...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00023306", "row_id": 23306, "seed_ids": "[4932, 784, 7784]" }
0.749249
Codeforces_23306
I
[ "find", "union", "minimum_cost_to_connect" ]
3
[ [ "minimum_cost_to_connect", "find" ], [ "minimum_cost_to_connect", "union" ], [ "union", "find" ] ]
3
[]
false
[]
false
pytest
true
[]
true
45cb09f44f90bbc20f5ef7c822774cf04266aa48
b46148ad6c5d00b024909b7aeb925e37849ae64e
v1.0
instruct
Codeforces
Codeforces_23309_I
In Chef's kitchen, there are n types of dishes. Each dish can be prepared using a specific recipe, which requires certain ingredients in particular quantities. Chef has m different ingredients in his pantry. Given the maximum quantity of each ingredient available, determine if Chef can prepare exactly k different types...
from itertools import combinations def can_prepare_k_dishes(n, m, k, pantry, dishes): """ Determines if exactly k distinct dishes can be prepared with the given ingredients in the pantry. Args: n (int): The number of different types of dishes. m (int): The number of different ingredients. ...
from solution import can_prepare_k_dishes def test_example(): n, m, k = 5, 4, 3 pantry = [10, 10, 10, 10] dishes = [ [2, 0, 1, 1], [3, 4, 0, 0], [0, 2, 2, 3], [1, 0, 0, 1], [4, 1, 4, 0] ] assert can_prepare_k_dishes(n, m, k, pantry, dishes) == "YES" def test...
[ { "docstring": "Determines if exactly k distinct dishes can be prepared with the given ingredients in the pantry.\n\nArgs:\nn (int): The number of different types of dishes.\nm (int): The number of different ingredients.\nk (int): The number of different dishes to prepare.\npantry (list[int]): List of available...
[ 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 itertools import combinations\n\ndef can_prepare_dishes(n, m, k, max_quantities, recipes):\n \"\"\"\n Determine if it is possible to prepare exactl...
trial_gpt4o_4
{ "original_instruction": "", "prompt_id": "00023309", "row_id": 23309, "seed_ids": "[4151, 6362, 2708]" }
0.779365
Codeforces_23309
I
[ "can_prepare_k_dishes", "feasible_combination" ]
2
[ [ "can_prepare_k_dishes", "feasible_combination" ] ]
1
[]
false
[]
false
pytest
true
[]
true
7638ff5ce9e2c0f874105bd7cb0c0e29aac71499
0646fc6e01889718ef9f3d3d4805954e300479f4
v1.0
instruct
Codeforces
Codeforces_23382_I
You are given a sequence of integers. Your task is to find the length of the longest subsequence which is both strictly increasing, and contains only prime numbers. A subsequence is derived by deleting zero or more elements from the sequence without changing the order of the remaining elements. For example, if you ar...
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 length_of_longest_increasing_prime_subsequ...
from solution import longest_increasing_prime_subsequence_length def test_example_1(): assert longest_increasing_prime_subsequence_length((6, [2, 3, 4, 6, 7, 11])) == 4 def test_example_2(): assert longest_increasing_prime_subsequence_length((5, [1, 4, 6, 8, 9])) == 0 def test_only_primes(): assert longe...
[ { "docstring": null, "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": null, "function_declaration": "def length_of_longest_increasing_prime_subsequence(nums):", "function_name": "length_of_longest_increasing_prime_subs...
[ 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 is_prime(n):\n if n <= 1:\n return False\n if n <= 3:\n return True\n if n % 2 == 0 or n % 3 == 0:\n return False\n i = 5...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00023382", "row_id": 23382, "seed_ids": "[6101, 835, 3218]" }
0.774488
Codeforces_23382
I
[ "is_prime", "length_of_longest_increasing_prime_subsequence", "longest_increasing_prime_subsequence_length" ]
3
[ [ "length_of_longest_increasing_prime_subsequence", "is_prime" ], [ "longest_increasing_prime_subsequence_length", "length_of_longest_increasing_prime_subsequence" ] ]
2
[]
false
[]
false
pytest
true
[]
true
d017d2fafbf053a63faf0767260fe9d916c88821
c6d674db3e3726638908b64f65b2bf20966814c4
v1.0
instruct
Codeforces
Codeforces_23383_I
You are given a 2D grid of dimensions \( n \times m \) filled with integers. Your task is to find the maximum sum of integers on any rectangular sub-grid of the grid. A rectangular sub-grid is defined by choosing two rows \( r_1 \) and \( r_2 \) and two columns \( c_1 \) and \( c_2 \) such that \( 1 \leq r_1 \leq r_2 \...
def max_subgrid_sum(grid): """ Finds the maximum sum of any rectangular sub-grid in a given 2D grid. """ n = len(grid) m = len(grid[0]) max_sum = float('-inf') for left in range(m): temp = [0] * n for right in range(left, m): for i in range(n): te...
from solution import max_subgrid_sum def test_case_1(): grid = [ [1, 2, -1, -4, -20], [-8, -3, 4, 2, 1], [3, 8, 10, 1, 3], [-4, -1, 1, 7, -6] ] assert max_subgrid_sum(grid) == 29 def test_case_2(): grid = [ [-1, -2, -3, -4], [-1, -2, -3, -4], [-1...
[ { "docstring": "Finds the maximum sum of any rectangular sub-grid in a given 2D grid.", "function_declaration": "def max_subgrid_sum(grid):", "function_name": "max_subgrid_sum", "parameter_list": "(grid)" }, { "docstring": "Helper function to find the maximum sum subarray using Kadane's algo...
[ 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 max_sum_subgrid(grid):\n \"\"\"\n Returns the maximum sum of integers on any rectangular sub-grid of the grid.\n \"\"\"\n n, m = len(grid), le...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00023383", "row_id": 23383, "seed_ids": "[5141, 3599, 968]" }
0.714999
Codeforces_23383
I
[ "max_subgrid_sum", "kadane" ]
2
[ [ "max_subgrid_sum", "kadane" ] ]
1
[]
false
[]
false
pytest
true
[]
true
958b7cd1db3f812e7def703dbd653fa853961208
f5cc8fe6756a395a620d7271d2f6371885caf98e
v1.0
instruct
Codeforces
Codeforces_23402_I
A culinary competition requires a specific type of sandwich for entry: a palindromic sandwich. A palindromic sandwich consists of a palindrome in the middle, surrounded by two slices of equal length on either side that are also palindromes. Given an integer n (1 ≤ n ≤ 50), and a string s of length 2n, determine if it ...
def is_palindrome(s): return s == s[::-1] def is_palindromic_sandwich(n, s): for i in range(1, n+1): a = s[:i] b = s[i:-i] c = s[-i:] if a == c and is_palindrome(b): return "YES" return "NO" def check_palindromic_sandwich(): import sys input = sys.stdin....
from solution import is_palindromic_sandwich def test_is_palindromic_sandwich(): assert is_palindromic_sandwich(3, "abccba") == "YES" assert is_palindromic_sandwich(3, "abcdcb") == "NO" assert is_palindromic_sandwich(2, "abba") == "YES" assert is_palindromic_sandwich(2, "abca") == "NO" assert is_pa...
[ { "docstring": null, "function_declaration": "def is_palindrome(s):", "function_name": "is_palindrome", "parameter_list": "(s)" }, { "docstring": null, "function_declaration": "def is_palindromic_sandwich(n, s):", "function_name": "is_palindromic_sandwich", "parameter_list": "(n,...
[ 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 is_palindrome(s):\n \"\"\"\n Helper function to check if a string s is a palindrome.\n \"\"\"\n return s == s[::-1]\n\ndef is_palindromic_sand...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00023402", "row_id": 23402, "seed_ids": "[5902, 3619, 882]" }
0.736679
Codeforces_23402
I
[ "is_palindrome", "is_palindromic_sandwich", "check_palindromic_sandwich" ]
3
[ [ "check_palindromic_sandwich", "is_palindromic_sandwich" ], [ "is_palindromic_sandwich", "is_palindrome" ] ]
2
[]
false
[]
false
pytest
true
[]
true
879167d9217e02f16855d60450e76e83c47b7a30
69b7f11075b64a880fea59c012b9b6358a07f91f
v1.0
instruct
Codeforces
Codeforces_23463_I
A new land has been discovered, and the government wants to construct roads connecting every town. The land consists of n towns, numbered from 1 to n. Each town is connected to every other town with a bidirectional road having a certain length. The government has already built some roads, but they want to ensure that ...
def prims_algorithm(n, graph): """ Function to calculate the minimum total length of roads required to connect all towns using Prim's Algorithm. :param n: Number of towns :param graph: Adjacency matrix representing lengths of the roads :return: Total length of the roads in the MST """ # Ini...
def test_example(): graph = [ [0, 1, 3], [1, 0, 2], [3, 2, 0] ] assert min_total_road_length(3, graph) == 3 def test_symmetric_graph(): graph = [ [0, 10, 20], [10, 0, 30], [20, 30, 0] ] assert min_total_road_length(3, graph) == 30 def test_four_t...
[ { "docstring": "Function to calculate the minimum total length of roads required to connect all towns using Prim's Algorithm.\n:param n: Number of towns\n:param graph: Adjacency matrix representing lengths of the roads\n:return: Total length of the roads in the MST", "function_declaration": "def prims_algor...
[ 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 prim_mst(n, roads):\n \"\"\"\n Finds the total length of the roads in the Minimum Spanning Tree (MST) for the given towns.\n \n Parameters:\n ...
trial_gpt4o_6
{ "original_instruction": "", "prompt_id": "00023463", "row_id": 23463, "seed_ids": "[6520, 227, 1256]" }
0.708341
Codeforces_23463
I
[ "prims_algorithm", "min_total_road_length" ]
2
[ [ "min_total_road_length", "prims_algorithm" ] ]
1
[]
false
[]
false
pytest
false
[]
true
e6c165a9b7e3acffaa993d178d9b9431ff7c62d3
9ca8f0fbaad5eb812cd7d88e85fa480d1faf4368
v1.0
instruct
Codeforces
Codeforces_23486_I
Given an integer `n`, find all prime numbers up to `n` (inclusive) that also remain prime if their digits are reversed. For example, for `n = 31`, the prime numbers up to `31` are: [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]. From these, the primes that remain primes when their digits are reversed are: [2, 3, 5, 7, 11, 13...
def is_prime(num): if num <= 1: return False if num <= 3: return True if num % 2 == 0 or num % 3 == 0: return False i = 5 while i * i <= num: if num % i == 0 or num % (i + 2) == 0: return False i += 6 return True def find_reversible_primes(n):...
from solution import find_reversible_primes def test_find_reversible_primes_example1(): assert find_reversible_primes(31) == [2, 3, 5, 7, 11, 13, 17, 31] def test_find_reversible_primes_example2(): assert find_reversible_primes(20) == [2, 3, 5, 7, 11, 13, 17] def test_find_reversible_primes_example3(): a...
[ { "docstring": null, "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": null, "function_declaration": "def find_reversible_primes(n):", "function_name": "find_reversible_primes", "parameter_list": "(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_prime(n):\n \"\"\"\n Check if a number is prime.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return True\n if n...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00023486", "row_id": 23486, "seed_ids": "[5920, 824, 6276]" }
0.602156
Codeforces_23486
I
[ "is_prime", "find_reversible_primes" ]
2
[ [ "find_reversible_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
6816fd799d4cc81eebe786db9a3812aa3d20eb81
6ce8b4ae764abf89ae75f90f7c697dcac72a005b
v1.0
instruct
Codeforces
Codeforces_23534_I
The company aims to organize a coding competition where participants will provide solutions to a problem involving numbers. They want each participant to submit a sequence of n integers such that no two consecutive integers have the same number of divisors. The first line contains one integer n (1 ≤ n ≤ 1000) — the le...
def number_of_divisors(x): """ Helper function to count the number of divisors of a given integer x. """ count = 0 for i in range(1, int(x ** 0.5) + 1): if x % i == 0: if i * i == x: count += 1 else: count += 2 return count def gen...
from solution import generate_sequence, number_of_divisors def test_generate_sequence_length(): assert len(generate_sequence(1)) == 1 assert len(generate_sequence(5)) == 5 assert len(generate_sequence(10)) == 10 def test_generate_sequence_unique_divisors(): sequence = generate_sequence(5) for i in...
[ { "docstring": "Helper function to count the number of divisors of a given integer x.", "function_declaration": "def number_of_divisors(x):", "function_name": "number_of_divisors", "parameter_list": "(x)" }, { "docstring": "Generates a sequence of n integers where no two consecutive integers...
[ 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 number_of_divisors(x):\n \"\"\"Returns the number of divisors of x.\"\"\"\n if x == 1:\n return 1\n divisors = 2 # 1 and x\n for i in ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00023534", "row_id": 23534, "seed_ids": "[4752, 3348, 4736]" }
0.654224
Codeforces_23534
I
[ "number_of_divisors", "generate_sequence" ]
2
[ [ "generate_sequence", "number_of_divisors" ] ]
1
[]
false
[]
false
pytest
true
[]
true
32ad6b6910a7252386922facb521a7c7a84ede46
f39da53ab9bd43ac8b02a5ab4b35d50a8a090132
v1.0
instruct
Codeforces
Codeforces_23555_I
Vasya is organizing a tree planting project in a park represented by an undirected graph with n vertices and m edges. Each vertex represents a location where he can plant a tree, and each edge represents a pathway between locations. Vasya plans to plant exactly k trees, and he wants to maximize the minimum distance bet...
from collections import deque, defaultdict def bfs(graph, start, n): distances = [-1] * n distances[start] = 0 queue = deque([start]) while queue: node = queue.popleft() for neighbor in graph[node]: if distances[neighbor] == -1: # Not visited distances[...
from solution import get_optimal_trees def test_example_case(): n, m, k = 5, 4, 2 edges = [(1, 2), (2, 3), (3, 4), (4, 5)] result = get_optimal_trees(n, m, k, edges) assert sorted(result) == [1, 5] def test_case_all_vertices(): n, m, k = 4, 4, 4 edges = [(1, 2), (2, 3), (3, 4), (4, 1)] res...
[ { "docstring": null, "function_declaration": "def bfs(graph, start, n):", "function_name": "bfs", "parameter_list": "(graph, start, n)" }, { "docstring": null, "function_declaration": "def get_optimal_trees(n, m, k, edges):", "function_name": "get_optimal_trees", "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 floyd_warshall(n, graph):\n dist = [[float('inf')] * n for _ in range(n)]\n \n for i in range(n):\n dist[i][i] = 0\n for u in range(n):...
trial_gpt4o_3
{ "original_instruction": "", "prompt_id": "00023555", "row_id": 23555, "seed_ids": "[957, 7086, 2460]" }
0.715411
Codeforces_23555
I
[ "bfs", "get_optimal_trees" ]
2
[ [ "get_optimal_trees", "bfs" ] ]
1
[]
false
[]
false
pytest
true
[]
true
96599d8e056fe18f3120a1ababf7ebc2bcf19d53
5ddcccbd2a8fcaaf7420870d00952421839e614c
v1.0
instruct
Codeforces
Codeforces_23559_I
You are given a binary tree. Your task is to find all the root-to-leaf paths such that the sum of the node values in the path equals a given target sum. Each path should be returned as a list of the node values. The first line contains an integer n (1 ≤ n ≤ 10^5) — the number of nodes in the binary tree. The second li...
class TreeNode: def __init__(self, val=0, left=None, right=None): self.val = val self.left = left self.right = right def path_sum_helper(node, target_sum): if not node: return [] if not node.left and not node.right: # if it's a leaf node if node.val == target_sum: ...
from solution import TreeNode, path_sum def test_single_node_path(): root = TreeNode(5) assert path_sum(root, 5) == [[5]] def test_two_level_tree(): root = TreeNode(1, TreeNode(2), TreeNode(3)) assert path_sum(root, 3) == [[1, 2]] # only one valid path def test_multiple_paths(): root = TreeNode(...
[]
[ 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": "class TreeNode:\n def __init__(self, val=0, left=None, right=None):\n self.val = val\n self.left = left\n self.right = right\n\ndef pa...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00023559", "row_id": 23559, "seed_ids": "[4849, 3434, 1827]" }
0.632721
Codeforces_23559
I
[ "path_sum_helper", "path_sum" ]
2
[ [ "path_sum", "path_sum_helper" ] ]
1
[]
false
[ "TreeNode" ]
true
pytest
true
[]
true
5a318f43c115015086391a4eb2a62206270ba89d
744faa879f156f83aa649f8b5e3dbaadd1c0c344
v1.0
instruct
Codeforces
Codeforces_23576_I
You are given a grid consisting of n rows and m columns. Each cell of the grid is either empty (represented by '.') or contains an obstacle (represented by '#'). You are also given q queries. Each query consists of two pairs of coordinates representing the starting and ending points of a particular path. For each query...
from collections import deque def is_valid_move(x, y, n, m, grid, visited): return 0 <= x < n and 0 <= y < m and grid[x][y] == '.' and not visited[x][y] def bfs(grid, start, end, n, m): queue = deque([start]) visited = [[False] * m for _ in range(n)] visited[start[0]][start[1]] = True directi...
def test_path_exists(): grid = [ ".....", ".###.", ".###.", ".###.", "....." ] n, m = 5, 5 queries = [ (1, 1, 5, 5), (2, 2, 3, 3), (1, 5, 5, 1) ] assert path_exists(grid, n, m, queries) == ["YES", "NO", "YES"] def test_path_ex...
[ { "docstring": null, "function_declaration": "def is_valid_move(x, y, n, m, grid, visited):", "function_name": "is_valid_move", "parameter_list": "(x, y, n, m, grid, visited)" }, { "docstring": null, "function_declaration": "def bfs(grid, start, end, n, m):", "function_name": "bfs", ...
[ 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 collections import deque\n\ndef is_valid_move(x, y, n, m, grid, visited):\n return 0 <= x < n and 0 <= y < m and grid[x][y] == '.' and not visited[x][...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00023576", "row_id": 23576, "seed_ids": "[137, 1630, 6918]" }
0.723964
Codeforces_23576
I
[ "is_valid_move", "bfs", "path_exists" ]
3
[ [ "bfs", "is_valid_move" ], [ "path_exists", "bfs" ] ]
2
[]
false
[]
false
pytest
false
[]
true
6fc8d815af52957d10ce9107adf4a5b0ef5a2829
795d13f3f4bce6316413a68ea57e839a6fed374c
v1.0
instruct
Codeforces
Codeforces_23595_I
Peter has recently learned about the concept of pseudorandom number generators and how they can be used to generate sequences that appear random but are actually deterministic. He decides to experiment with a simple linear congruential generator (LCG). The formula for generating the next number in the sequence using ...
def generate_lcg_sequence(a, c, m, X0, k): """ Generates the first k numbers in the sequence using a Linear Congruential Generator (LCG). Parameters: a (int): Multiplier c (int): Increment m (int): Modulus X0 (int): Initial seed k (int): Number of terms to generate Returns:...
from solution import generate_lcg_sequence, format_lcg_sequence def test_generate_lcg_sequence(): assert generate_lcg_sequence(2, 3, 5, 1, 10) == [1, 0, 3, 4, 1, 0, 3, 4, 1, 0] assert generate_lcg_sequence(1, 1, 10, 0, 5) == [0, 1, 2, 3, 4] assert generate_lcg_sequence(4, 1, 8, 2, 6) == [2, 1, 5, 5, 5, 5] ...
[ { "docstring": "Generates the first k numbers in the sequence using a Linear Congruential Generator (LCG).\n\nParameters:\na (int): Multiplier\nc (int): Increment\nm (int): Modulus\nX0 (int): Initial seed\nk (int): Number of terms to generate\n\nReturns:\nlist: The first k numbers in the LCG sequence", "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 generate_lcg_sequence(a, c, m, X_0, k):\n \"\"\"\n Generates the first k numbers of a sequence using a Linear Congruential Generator (LCG).\n \n ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00023595", "row_id": 23595, "seed_ids": "[1776, 2655, 4146]" }
0.54654
Codeforces_23595
I
[ "generate_lcg_sequence", "format_lcg_sequence" ]
2
[ [ "format_lcg_sequence", "generate_lcg_sequence" ] ]
1
[]
false
[]
false
pytest
true
[]
true
54adf7c41eb8fd47e11d96e4fad862f9b7a05ea8
001e2a6482621870ac9908af9c34728a132dca96
v1.0
instruct
Codeforces
Codeforces_23624_I
Given an undirected graph with n nodes and m edges, where each edge has an associated weight, determine the smallest sum of edge weights needed to connect all nodes in the graph. This ensures that you create a minimum spanning tree (MST). Your task is to calculate the weight of the MST of the graph. The first line ...
def find(parent, i): if parent[i] == i: return i else: return find(parent, parent[i]) def union(parent, rank, x, y): xroot = find(parent, x) yroot = find(parent, y) if rank[xroot] < rank[yroot]: parent[xroot] = yroot elif rank[xroot] > rank[yroot]: parent[yroot]...
from solution import minimum_spanning_tree def test_mst_example(): n = 4 m = 5 edges = [(1, 2, 1), (1, 3, 4), (2, 3, 2), (2, 4, 6), (3, 4, 3)] assert minimum_spanning_tree(n, m, edges) == 6 def test_mst_disconnected(): n = 4 m = 2 edges = [(1, 2, 1), (3, 4, 2)] assert minimum_spanning_...
[ { "docstring": null, "function_declaration": "def find(parent, i):", "function_name": "find", "parameter_list": "(parent, i)" }, { "docstring": null, "function_declaration": "def union(parent, rank, x, y):", "function_name": "union", "parameter_list": "(parent, rank, x, y)" }, ...
[ 1, 0, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_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_0
{ "original_instruction": "", "prompt_id": "00023624", "row_id": 23624, "seed_ids": "[2850, 6192, 6982]" }
0.833777
Codeforces_23624
I
[ "find", "union", "kruskal_mst", "minimum_spanning_tree" ]
4
[ [ "kruskal_mst", "find" ], [ "kruskal_mst", "union" ], [ "minimum_spanning_tree", "kruskal_mst" ], [ "union", "find" ] ]
4
[]
false
[]
false
pytest
true
[]
true
bfe0f08459c3446d9945dfaa7dc3084626435e12
2770ab65d7f35c7a898054f217fbb6b6f1e50b9c
v1.0
instruct
Codeforces
Codeforces_23632_I
You are hosting a coding challenge event, and the final round challenges participants with solving an interesting puzzle involving a binary tree. The puzzle presents an intriguing blend of tree traversal, dynamic programming, and recursive algorithms. You are given a binary tree with \( n \) nodes. Each node has a uni...
class TreeNode: def __init__(self, weight): self.weight = weight self.children = [] def max_sum_path_in_tree(n, weights, edges): def dfs(node, parent): max_1, max_2, node_max_sum = 0, 0, 0 for child in tree[node].children: if child == parent: ...
import pytest from solution import max_sum_path_in_tree def test_example_1(): n = 5 weights = [1, 2, 3, 4, 5] edges = [(1, 2), (1, 3), (2, 4), (3, 5)] assert max_sum_path_in_tree(n, weights, edges) == 15 def test_single_path(): n = 3 weights = [1, 2, 3] edges = [(1, 2), (2, 3)] assert ...
[]
[ 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": "class TreeNode:\n def __init__(self, weight):\n self.weight = weight\n self.children = []\n\ndef find_max_path_sum(weights, edges):\n from...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00023632", "row_id": 23632, "seed_ids": "[1156, 3812, 1732]" }
0.724014
Codeforces_23632
I
[ "max_sum_path_in_tree", "solve" ]
2
[ [ "solve", "max_sum_path_in_tree" ] ]
1
[]
false
[ "TreeNode" ]
true
pytest
true
[]
true
e50969466305e542a4942b5398bc2b5322842b79
1b2b257534a3d050354f66c7b42eeb8b157d4e30
v1.0
instruct
Codeforces
Codeforces_23685_I
Leonardo is organizing a treasure hunt for his friends. The treasure is hidden in a grid of dimensions n x m. Each cell in the grid either contains a clue or is empty. The clues are represented by integers from 1 to k, each type of clue can only appear once in the grid, while empty cells are denoted by 0. To solve the...
from collections import deque def find_clue_positions(grid, n, m): positions = {} for i in range(n): for j in range(m): if grid[i][j] > 0: positions[grid[i][j]] = (i, j) return positions def bfs(start, end, grid, n, m): queue = deque([(start[0], start[1], 0)]) v...
from solution import minimum_time_to_collect_all_clues def test_example_case(): n = 3 m = 3 k = 3 grid = [ [1, 0, 2], [0, 3, 0], [0, 0, 0] ] assert minimum_time_to_collect_all_clues(n, m, k, grid) == 4 def test_single_row(): n = 1 m = 5 k = 5 grid = [ ...
[ { "docstring": null, "function_declaration": "def find_clue_positions(grid, n, m):", "function_name": "find_clue_positions", "parameter_list": "(grid, n, m)" }, { "docstring": null, "function_declaration": "def bfs(start, end, grid, n, m):", "function_name": "bfs", "parameter_lis...
[ 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\n\ndef bfs(start, goal, grid, n, m):\n \"\"\"\n Performs a breadth-first search to find the shortest path from start to go...
trial_gpt4o_4
{ "original_instruction": "", "prompt_id": "00023685", "row_id": 23685, "seed_ids": "[3320, 7784, 644]" }
0.657445
Codeforces_23685
I
[ "find_clue_positions", "bfs", "minimum_time_to_collect_all_clues" ]
3
[ [ "minimum_time_to_collect_all_clues", "bfs" ], [ "minimum_time_to_collect_all_clues", "find_clue_positions" ] ]
2
[]
false
[]
false
pytest
true
[]
true
c069c37799363baaaa9545011a1cf17ae33a3efc
4099bba9c328cf78511c402f1ee7dcca6779b747
v1.0
instruct
Codeforces
Codeforces_23708_I
You are given a binary tree with `n` nodes. Each node has a value and the tree may not be balanced. Your task is to find the longest path (from any node to any other node) in the tree where the absolute difference between the values of adjacent nodes in the path is exactly 1. The input contains multiple test cases. Th...
class TreeNode: def __init__(self, value): self.value = value self.left = None self.right = None def build_tree(node_data): nodes = [TreeNode(data[0]) for data in node_data] for idx, (value, left, right) in enumerate(node_data): if left != -1: nodes[idx].left = n...
from solution import longest_path_in_trees def test_example_1(): t = 1 test_cases = [ (5, [(1, 1, 2), (2, -1, -1), (3, -1, -1), (4, -1, -1), (5, -1, -1)]) ] assert longest_path_in_trees(t, test_cases) == [2] def test_example_2(): t = 1 test_cases = [ (4, [(1, 1, -1), (2, 2, -1)...
[]
[ 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": "class TreeNode:\n def __init__(self, value=0, left=None, right=None):\n self.value = value\n self.left = left\n self.right = right\n\n...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00023708", "row_id": 23708, "seed_ids": "[3452, 6222, 52]" }
0.659004
Codeforces_23708
I
[ "build_tree", "longest_path", "longest_path_in_trees" ]
3
[ [ "longest_path_in_trees", "build_tree" ], [ "longest_path_in_trees", "longest_path" ] ]
2
[]
false
[ "TreeNode" ]
true
pytest
true
[]
true
e1a8e18c342e93d53ed531e287998102925ef633
c25e8f0f96e24aec60d98ba87eeb04978f44fb6e
v1.0
instruct
Codeforces
Codeforces_23798_I
After exploring the forest near her home, Alice stumbled upon a labyrinth filled with magical creatures. To navigate through the labyrinth, she needs to solve the following puzzle: Given an undirected graph representing the labyrinth, where nodes represent rooms and edges represent the paths between them, Alice needs ...
import heapq def dijkstra(n, edges): # Create an adjacency list graph = [[] for _ in range(n + 1)] for u, v, w in edges: graph[u].append((v, w)) graph[v].append((u, w)) # Min-heap to store (distance, node) min_heap = [(0, 1)] # Start from node 1 with distance 0 distances =...
def test_find_shortest_path_resistance_example1(): n = 4 m = 4 edges = [ (1, 2, 1), (2, 3, 2), (1, 3, 4), (2, 4, 3), ] assert find_shortest_path_resistance(n, m, edges) == 4 def test_find_shortest_path_resistance_example2(): n = 4 m = 2 edges = [ ...
[ { "docstring": null, "function_declaration": "def dijkstra(n, edges):", "function_name": "dijkstra", "parameter_list": "(n, edges)" }, { "docstring": null, "function_declaration": "def find_shortest_path_resistance(n, m, edges):", "function_name": "find_shortest_path_resistance", ...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "import heapq\nimport sys\n\ndef shortest_path(n, m, edges):\n # adjacency list representation of the graph\n graph = [[] for _ in range(n + 1)]\n\n f...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00023798", "row_id": 23798, "seed_ids": "[4351, 4925, 2710]" }
0.654878
Codeforces_23798
I
[ "dijkstra", "find_shortest_path_resistance" ]
2
[ [ "find_shortest_path_resistance", "dijkstra" ] ]
1
[]
false
[]
false
pytest
false
[]
true
8360978566606493fbd60cf083fe31747f13611d
40b7413d4b1055ac6dea0d1bb126919888ea28c1
v1.0
instruct
Codeforces
Codeforces_23821_I
Artem has a drone and he loves exploring the city. The city is represented as a grid of size $$$n \times n$$$. Some cells on the grid are blocked due to buildings or other obstacles, and cannot be traversed by the drone. Artem can control the drone and make it fly up, down, left, or right to an adjacent cell. He wants ...
from collections import deque def shortest_path(grid, n, start_x, start_y, target_x, target_y): directions = [(-1, 0), (1, 0), (0, -1), (0, 1)] queue = deque([(start_x, start_y, 0)]) # (x, y, distance) visited = set() visited.add((start_x, start_y)) while queue: x, y, dist = queue.pop...
def test_shortest_path(): grid1 = [ ".....", ".###.", "...#.", ".#...", "....." ] assert solve(5, grid1, 1, 1, 5, 5) == 8 grid2 = [ "#####", "#####", "#####", "#####", "#####" ] assert solve(5, grid2, 1, 1, 5, 5) ==...
[ { "docstring": null, "function_declaration": "def shortest_path(grid, n, start_x, start_y, target_x, target_y):", "function_name": "shortest_path", "parameter_list": "(grid, n, start_x, start_y, target_x, target_y)" }, { "docstring": null, "function_declaration": "def solve(n, grid, x1, ...
[ 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 deque\n\ndef shortest_path_in_grid(n, grid, x1, y1, x2, y2):\n directions = [(-1, 0), (1, 0), (0, -1), (0, 1)]\n queue = deque([...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00023821", "row_id": 23821, "seed_ids": "[3241, 6680, 3699]" }
0.747799
Codeforces_23821
I
[ "shortest_path", "solve" ]
2
[ [ "solve", "shortest_path" ] ]
1
[]
false
[]
false
pytest
false
[]
true
fe437f7279edce0205e1f803e9eb0065b7bf1989
d2891c5e915198e8c4caeb9c065bfaad0e1bd5cb
v1.0
instruct
Codeforces
Codeforces_23844_I
In a distant land called Algorithmia, there are n bi-directional roads and m intersections. The city planning committee has decided to partition the city into regions for better management. The goal is to divide the city in such a way that each region forms a connected component with no more than k intersections in it....
def find_connected_components(m, roads): from collections import defaultdict, deque graph = defaultdict(list) for u, v in roads: graph[u].append(v) graph[v].append(u) def bfs(start): queue = deque([start]) visited.add(start) component = [] while ...
def test_min_new_roads_case1(): input_str = "6 4 2\n1 2\n2 3\n3 4\n4 5\n" assert algorithmia(input_str) == 2 def test_min_new_roads_case2(): input_str = "3 3 1\n1 2\n2 3\n3 1\n" assert algorithmia(input_str) == 2 def test_min_new_roads_case3(): input_str = "6 5 1\n1 2\n2 3\n3 4\n4 5\n5 6\n" as...
[ { "docstring": null, "function_declaration": "def find_connected_components(m, roads):", "function_name": "find_connected_components", "parameter_list": "(m, roads)" }, { "docstring": null, "function_declaration": "def analyze_subcomponents(components, k):", "function_name": "analyze...
[ 0, 1 ]
1
medium
0.5
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def partition_city(m, n, k, roads):\n from collections import defaultdict, deque\n \n def bfs(start, visited):\n component = []\n queue...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00023844", "row_id": 23844, "seed_ids": "[156, 1337, 1681]" }
0.72064
Codeforces_23844
I
[ "find_connected_components", "analyze_subcomponents", "min_new_roads", "process_input", "algorithmia" ]
5
[ [ "algorithmia", "process_input" ], [ "min_new_roads", "analyze_subcomponents" ], [ "min_new_roads", "find_connected_components" ], [ "process_input", "min_new_roads" ] ]
4
[ "process_input" ]
false
[]
false
pytest
false
[]
true
185f4f6e5dbccb3172a210ede2dfc1d1fd41f0b9
ec7a4ada6f6a07ce3383860748ddea6c5413b6d6
v1.0
instruct
Codeforces
Codeforces_23853_I
You are given a grid of dimensions n by m filled with numbers between 1 and 9. You need to find the maximum sum of numbers you can collect if you move according to the following rules: 1. You start at the top-left cell (1,1). 2. You can only move to the right (to cell (i,j+1)) or downwards (to cell (i+1,j)). Write a f...
def max_sum_path(grid): n, m = len(grid), len(grid[0]) # Create a dp array with the same dimensions as the grid dp = [[0]*m for _ in range(n)] # Initialize the dp array with the max sums dp[0][0] = grid[0][0] # Fill the first row for j in range(1, m): dp[0][j] = dp[0][j-1] + grid[0...
from solution import max_sum_path_from_input def test_example_case(): n, m = 3, 3 grid_lines = ["1 3 1", "1 5 1", "4 2 1"] assert max_sum_path_from_input(n, m, grid_lines) == 12 def test_single_cell(): n, m = 1, 1 grid_lines = ["5"] assert max_sum_path_from_input(n, m, grid_lines) == 5 def te...
[ { "docstring": null, "function_declaration": "def max_sum_path(grid):", "function_name": "max_sum_path", "parameter_list": "(grid)" }, { "docstring": null, "function_declaration": "def max_sum_path_from_input(n, m, grid_lines):", "function_name": "max_sum_path_from_input", "param...
[ 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 max_path_sum(n, m, grid):\n \"\"\"\n Given a grid of dimensions n by m filled with numbers between 1 and 9,\n returns the maximum sum of numbers ...
trial_gpt4o_4
{ "original_instruction": "", "prompt_id": "00023853", "row_id": 23853, "seed_ids": "[4346, 2195, 2811]" }
0.72163
Codeforces_23853
I
[ "max_sum_path", "max_sum_path_from_input" ]
2
[ [ "max_sum_path_from_input", "max_sum_path" ] ]
1
[]
false
[]
false
pytest
true
[]
true
6637b109fd0d510723e78d53a62629887ba76dbd
4184b624c4447a073102d9c60130800e913d9c3c
v1.0
instruct
Codeforces
Codeforces_23863_I
You are given an array of integers where each integer represents the temperature recorded on a particular day. The temperature recordings for 'n' days are stored in the array `temperatures`. Your task is to find the number of pairs of days (i, j) such that i < j and temperatures[i] > temperatures[j]. Input: - The firs...
def count_inversion_pairs(temperatures): """ Returns the number of pairs (i, j) such that i < j and temperatures[i] > temperatures[j]. """ n = len(temperatures) return merge_sort_and_count(temperatures, 0, n-1) def merge_sort_and_count(arr, left, right): if left >= right: return 0 m...
from solution import count_inversion_pairs def test_case_1(): temperatures = [30, 20, 25, 35, 10] assert count_inversion_pairs(temperatures) == 6 def test_case_2(): temperatures = [10, 20, 30, 40, 50] assert count_inversion_pairs(temperatures) == 0 def test_case_3(): temperatures = [50, 40, 30, 2...
[ { "docstring": "Returns the number of pairs (i, j) such that i < j and temperatures[i] > temperatures[j].", "function_declaration": "def count_inversion_pairs(temperatures):", "function_name": "count_inversion_pairs", "parameter_list": "(temperatures)" }, { "docstring": null, "function_d...
[ 0, 0, 0, 0, 0, 0, 0, 1, 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 count_temperature_pairs(n, temperatures):\n \"\"\"\n Counts the number of pairs (i, j) such that i < j and temperatures[i] > temperatures[j].\n \...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00023863", "row_id": 23863, "seed_ids": "[743, 510, 1119]" }
0.698584
Codeforces_23863
I
[ "count_inversion_pairs", "merge_sort_and_count", "merge_and_count" ]
3
[ [ "count_inversion_pairs", "merge_sort_and_count" ], [ "merge_sort_and_count", "merge_and_count" ] ]
2
[]
false
[]
false
pytest
true
[]
true
67152699c2bcf801e292465105b40712d32c7223
27fde7815d4a6fbfd036ebfc49aaf306f509adb5
v1.0
instruct
Codeforces
Codeforces_23915_I
Imagine you are part of the development team for a popular online multiplayer game. Your task is to implement a feature that matches players into teams based on their skill levels. The game categorizes players into skill levels represented by integers from 1 to 100, inclusive. The skill level of each player is stored...
def form_teams(player_count, skill_levels): """ Returns the number of teams that can be formed and the indices of players in each team. Parameters: player_count: int - The total number of players. skill_levels: List[int] - The skill levels of the players. Returns: result: List - A ...
from solution import form_teams def test_form_teams(): assert form_teams(6, [10, 20, 30, 40, 50, 60]) == [2, [1, 2, 3], [4, 5, 6]] assert form_teams(6, [60, 20, 10, 30, 40, 50]) == [2, [3, 2, 4], [5, 6, 1]] assert form_teams(5, [10, 20, 30, 40, 50]) == -1 assert form_teams(9, [1, 2, 3, 4, 5, 6, 7, 8, 9...
[ { "docstring": "Returns the number of teams that can be formed and the indices of players in each team.\n\nParameters:\nplayer_count: int - The total number of players.\nskill_levels: List[int] - The skill levels of the players.\n\nReturns:\nresult: List - A list containing the number of teams and their respect...
[ 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 form_teams(player_count, skill_levels):\n \"\"\"\n Returns the number of teams that can be formed and the indices of players in each team.\n \n ...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00023915", "row_id": 23915, "seed_ids": "[7034, 5259, 8079]" }
0.751534
Codeforces_23915
I
[ "form_teams", "solve" ]
2
[ [ "solve", "form_teams" ] ]
1
[]
false
[]
false
pytest
true
[]
true
a39b2ed3652140318a7cd2b905d1c36be7438473
3f4a451ab5d3ee1eac5820f3dc87ac56d0443662
v1.0
instruct
Codeforces
Codeforces_23925_I
Prime Number Permutations: Given a string containing only digits, determine if it is possible to re-arrange the digits in such a way that the resulting number is a prime number. The input string will not contain any leading zeros. For this task, you will be given multiple test cases. For each test case, you need to id...
from itertools import permutations def is_prime(num): """ This function checks if a given number is a prime. """ if num < 2: return False for i in range(2, int(num ** 0.5) + 1): if num % i == 0: return False return True def can_form_prime(digit_string): """ ...
from solution import is_prime, can_form_prime, solve def test_is_prime(): assert is_prime(2) assert is_prime(3) assert not is_prime(4) assert is_prime(5) assert is_prime(11) assert not is_prime(1) assert not is_prime(0) assert not is_prime(-7) def test_can_form_prime(): assert can_...
[ { "docstring": "This function checks if a given number is a prime.", "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": "This function checks if any permutation of the digit string can form a prime number.", "function_de...
[ 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 itertools import permutations\n\ndef is_prime(num):\n \"\"\"\n This function checks if a given number is a prime.\n \"\"\"\n if num < 2:\n ...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00023925", "row_id": 23925, "seed_ids": "[5000, 7615, 2402]" }
0.598152
Codeforces_23925
I
[ "is_prime", "can_form_prime", "solve", "process_input_output" ]
4
[ [ "can_form_prime", "is_prime" ], [ "process_input_output", "solve" ], [ "solve", "can_form_prime" ] ]
3
[ "process_input_output" ]
false
[]
false
pytest
true
[]
true
7c2c116680a836dcc4181c336345609b26aeaa8a
75d6a4cff109b3f287a6443581f7337d496aef9c
v1.0
instruct
Codeforces
Codeforces_23943_I
Given a binary tree where each node contains an integer value, write a program that calculates the sum of all nodes with even-valued grandparents. A node's grandparent is the parent of its parent - if the parent or grandparent does not exist, their values are not considered. The input consists of a description of the ...
class TreeNode: def __init__(self, value): self.value = value self.left = None self.right = None def build_tree(n, nodes_info): nodes = [None] * (n + 1) for i in range(1, n + 1): if nodes[i] is None: nodes[i] = TreeNode(nodes_info[i - 1][0]) value, left_i...
def test_example_case(): input_str = "5\n2 2 3\n6 4 5\n8 0 0\n1 0 0\n7 0 0" expected_output = 8 assert process_input(input_str) == expected_output def test_single_node(): input_str = "1\n1 0 0" expected_output = 0 assert process_input(input_str) == expected_output def test_no_even_valued_grand...
[]
[ 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": "class TreeNode:\n def __init__(self, value=0, left=None, right=None):\n self.value = value\n self.left = left\n self.right = right\n\n...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00023943", "row_id": 23943, "seed_ids": "[1718, 4384, 6987]" }
0.598796
Codeforces_23943
I
[ "build_tree", "sum_even_grandparent", "process_input" ]
3
[ [ "process_input", "build_tree" ], [ "process_input", "sum_even_grandparent" ] ]
2
[ "process_input" ]
false
[ "TreeNode" ]
true
pytest
false
[]
true
4158ee4a1732d0ce03102c98e63a9fbf815e6607
2e4da2d56b7cd2fab6b25c17ce2700d690276f3f
v1.0
instruct
Codeforces
Codeforces_23965_I
You are given a rectangular grid of size n x m, where each cell contains a number. Serval is given the task to find the sum of all numbers in a specific subgrid multiple times. The grid is defined by n rows and m columns, and the subgrid is defined by its top-left corner (r1, c1) and its bottom-right corner (r2, c2). ...
def preprocess_grid(grid, n, m): """ Preprocess the grid to create a prefix sum array. """ prefix_sum = [[0] * (m + 1) for _ in range(n + 1)] for i in range(1, n + 1): for j in range(1, m + 1): prefix_sum[i][j] = (grid[i - 1][j - 1] + prefix_sum[i...
from solution import preprocess_grid, query_sum, solve_queries def test_preprocess_grid(): grid = [ [1, 2, 3], [4, 5, 6], [7, 8, 9] ] n, m = 3, 3 expected_prefix_sum = [ [0, 0, 0, 0], [0, 1, 3, 6], [0, 5, 12, 21], [0, 12, 27, 45] ] assert ...
[ { "docstring": "Preprocess the grid to create a prefix sum array.", "function_declaration": "def preprocess_grid(grid, n, m):", "function_name": "preprocess_grid", "parameter_list": "(grid, n, m)" }, { "docstring": "Calculate the sum of the subgrid using the prefix sum array.", "function...
[ 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_grid(grid, n, m):\n prefix_sum = [[0] * (m + 1) for _ in range(n + 1)]\n \n for i in range(1, n + 1):\n for j in range(1, m + 1...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00023965", "row_id": 23965, "seed_ids": "[425, 4535, 926]" }
0.637712
Codeforces_23965
I
[ "preprocess_grid", "query_sum", "solve_queries" ]
3
[ [ "solve_queries", "preprocess_grid" ], [ "solve_queries", "query_sum" ] ]
2
[ "solve_queries" ]
false
[]
false
pytest
true
[]
true
e93bc2c1cc8849dde7566a81163c54714127c50e
043edff5a6d55319f924301a9306247136c8aa73
v1.0
instruct
Codeforces
Codeforces_24014_I
You are tasked with creating a software module that filters an array of integers, ensuring that all elements in the resulting array are prime numbers. The module should receive an array of integers as input and return a new array containing only the prime numbers from the original array. For the purpose of this task,...
def is_prime(n): """ Helper function to check if a number is prime. """ if n <= 1: return False if n <= 3: return True if n % 2 == 0 or n % 3 == 0: return False i = 5 while i * i <= n: if n % i == 0 or n % (i + 2) == 0: return False i +...
from solution import filter_primes def test_filter_primes(): assert filter_primes([2, 4, 6, 7, 11, 15, 19]) == [2, 7, 11, 19] assert filter_primes([3, 5, 8, 14, 17, 21]) == [3, 5, 17] assert filter_primes([1, 22, 25, 31, 37]) == [31, 37] assert filter_primes([2, 3, 5, 7, 11]) == [2, 3, 5, 7, 11] as...
[ { "docstring": "Helper function to check if a number is prime.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Filters the input array to include only prime numbers.", "function_declaration": "def filter_primes(arr):",...
[ 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 is_prime(n):\n \"\"\"\n Helper function to check if a number n is prime.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00024014", "row_id": 24014, "seed_ids": "[2969, 448, 5749]" }
0.66205
Codeforces_24014
I
[ "is_prime", "filter_primes" ]
2
[ [ "filter_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
ba4fbd28756e75927a45f163939e19f0c74e6294
def5f45cb02e4806c2d972b9a94ad1945416bf57
v1.0
instruct
Codeforces
Codeforces_24021_I
You are given an undirected graph with $$$n$$$ nodes and $$$m$$$ edges. Each node in the graph represents a city, and each edge represents a bidirectional road connecting two cities. Each road has a weight, which represents the time it takes to travel that road. There is a specific path two people want to take: startin...
import heapq from collections import defaultdict def dijkstra(graph, start, n): """ Returns the shortest distance from start to all other nodes using Dijkstra's algorithm. """ distances = [float('inf')] * (n + 1) distances[start] = 0 priority_queue = [(0, start)] while priority_queue: ...
from solution import minimum_round_trip_time def test_minimum_round_trip_time_simple(): n, m = 4, 5 edges = [ (1, 2, 4), (1, 3, 2), (2, 3, 5), (2, 4, 10), (3, 4, 3) ] u, v = 1, 4 assert minimum_round_trip_time(n, m, edges, u, v) == 10 def test_minimum_round_...
[ { "docstring": "Returns the shortest distance from start to all other nodes using Dijkstra's algorithm.", "function_declaration": "def dijkstra(graph, start, n):", "function_name": "dijkstra", "parameter_list": "(graph, start, n)" }, { "docstring": "Returns the minimum round trip time from u...
[ 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": "import heapq\nimport sys\nfrom collections import defaultdict\n\ndef dijkstra(n, graph, start):\n \"\"\"\n Perform Dijkstra's algorithm to find the shor...
trial_gpt4o_5
{ "original_instruction": "", "prompt_id": "00024021", "row_id": 24021, "seed_ids": "[3609, 3560, 5428]" }
0.783732
Codeforces_24021
I
[ "dijkstra", "minimum_round_trip_time" ]
2
[ [ "minimum_round_trip_time", "dijkstra" ] ]
1
[]
false
[]
false
pytest
true
[]
true
17cabf1fbc8d1e16f41ea34848c7e23858d3d4d0
8aa023177eab3b562da05f75bc456424f11c350e
v1.0
instruct
Codeforces
Codeforces_24024_I
You are given an undirected graph with n nodes and m edges. Each edge has a weight associated with it, representing the cost to traverse that edge. Your task is to find the maximum cost of any path between any two nodes in the graph. Input Format: - The first line contains two integers n and m (1 ≤ n ≤ 10^5, 1 ≤ m ≤ 2...
from collections import defaultdict import sys def dfs(node, graph, visited, dist): visited[node] = True max_cost = 0 for neighbor, weight in graph[node]: if not visited[neighbor]: dist[neighbor] = dist[node] + weight max_cost = max(max_cost, dist[neighbor]) max_...
import pytest from solution import find_max_cost_path def test_example1(): n = 4 m = 4 edges = [(1, 2, 3), (2, 3, 4), (3, 4, 5), (4, 1, 6)] assert find_max_cost_path(n, m, edges) == 12 def test_single_edge(): n = 2 m = 1 edges = [(1, 2, 200)] assert find_max_cost_path(n, m, edges) == 2...
[ { "docstring": null, "function_declaration": "def dfs(node, graph, visited, dist):", "function_name": "dfs", "parameter_list": "(node, graph, visited, dist)" }, { "docstring": null, "function_declaration": "def find_max_cost_path(n, m, edges):", "function_name": "find_max_cost_path",...
[ 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": "import heapq\nfrom collections import defaultdict\n\ndef max_cost_path(n, m, edges):\n def prim_mst():\n visited = [False] * n\n max_cost = 0...
trial_gpt4o_5
{ "original_instruction": "", "prompt_id": "00024024", "row_id": 24024, "seed_ids": "[7775, 2749, 4448]" }
0.807407
Codeforces_24024
I
[ "dfs", "find_max_cost_path" ]
2
[ [ "find_max_cost_path", "dfs" ] ]
1
[]
false
[]
false
pytest
true
[]
true
851bd53e5362c501d5c5b2c33614843c20fa42e6
fa38accd58e6ed08a80b277afcc04e4fd65d2f34
v1.0
instruct
Codeforces
Codeforces_24025_I
Determine a minimum spanning tree in an undirected, weighted graph. You are given an undirected, weighted graph with $$$n$$$ vertices and $$$m$$$ edges. Your task is to determine the sum of the weights of the edges included in the minimum spanning tree (MST) of the graph. If the graph is already disconnected and canno...
def find(parent, i): if parent[i] == i: return i return find(parent, parent[i]) def union(parent, rank, x, y): xroot = find(parent, x) yroot = find(parent, y) if rank[xroot] < rank[yroot]: parent[xroot] = yroot elif rank[xroot] > rank[yroot]: parent[yroot] = xroot ...
from solution import minimum_spanning_tree def test_minimum_spanning_tree_1(): n = 4 m = 5 edges = [(1, 2, 3), (2, 3, 1), (3, 4, 4), (4, 1, 2), (3, 1, 5)] assert minimum_spanning_tree(n, m, edges) == 6 def test_minimum_spanning_tree_2(): n = 2 m = 1 edges = [(1, 2, 10)] assert minimum_...
[ { "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 return find(parent, parent[i])\n\ndef union(parent, rank, x, y):\n xroot = find(parent,...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00024025", "row_id": 24025, "seed_ids": "[5067, 6351, 6813]" }
0.797039
Codeforces_24025
I
[ "find", "union", "kruskal", "minimum_spanning_tree" ]
4
[ [ "kruskal", "find" ], [ "kruskal", "union" ], [ "minimum_spanning_tree", "kruskal" ], [ "union", "find" ] ]
4
[]
false
[]
false
pytest
true
[]
true
14858628649611914e4e66011b4fbb2124810cac
62ebe207cb335063c439692291b7d04cda1af99a
v1.0
instruct
Codeforces
Codeforces_24027_I
In an ancient kingdom, there are several cities connected by bidirectional roads. Each road has a length, which is an integer. The kingdom wants to construct a new capital city that minimizes the maximum travel distance from this capital to any other city. Your task is to help the kingdom find the optimal location for...
import heapq def dijkstra(adj, start, n): distances = [float('inf')] * n distances[start] = 0 pq = [(0, start)] while pq: current_dist, u = heapq.heappop(pq) if current_dist > distances[u]: continue for v, weight in adj[u]: distance = curren...
import pytest from solution import minimize_max_distance def test_example_case(): n = 5 m = 6 roads = [ (1, 2, 3), (1, 3, 4), (1, 4, 5), (2, 4, 2), (3, 4, 1), (3, 5, 1) ] assert minimize_max_distance(n, m, roads) == 4 def test_single_city(): n = ...
[ { "docstring": null, "function_declaration": "def dijkstra(adj, start, n):", "function_name": "dijkstra", "parameter_list": "(adj, start, n)" }, { "docstring": null, "function_declaration": "def minimize_max_distance(n, m, roads):", "function_name": "minimize_max_distance", "para...
[ 0, 0, 1, 0 ]
1
hard
0.25
{ "trial_gpt4o_0": null, "trial_gpt4o_1": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared1_results_combined.jsonl", "solution_code": "def minimal_maximum_distance(n, m, roads):\n import heapq\n \n def dijkstra(source):\n dist = [float('inf')] * (n + 1...
trial_gpt4o_3
{ "original_instruction": "", "prompt_id": "00024027", "row_id": 24027, "seed_ids": "[2142, 7207, 8145]" }
0.770089
Codeforces_24027
I
[ "dijkstra", "minimize_max_distance" ]
2
[ [ "minimize_max_distance", "dijkstra" ] ]
1
[]
false
[]
false
pytest
true
[]
true
293119b6a1208d0e0e031223648ed627d3f471a8
2ffa253b508cb7daf8f129e329ab1833bd306349
v1.0
instruct
Codeforces
Codeforces_24032_I
A small town consists of several houses connected by a network of roads. Each road connects two houses, and each pair of houses is directly connected by at most one road. The town wants to ensure that if any single road is closed for repairs, it is still possible to travel between any two houses using the remaining roa...
def find_min_roads_to_add(n, m, roads): from collections import defaultdict graph = defaultdict(list) for u, v in roads: graph[u].append(v) graph[v].append(u) def dfs(node, visited): stack = [node] while stack: current = stack.pop() for neighbor ...
from solution import find_min_roads def test_sample_input(): assert find_min_roads(5, 4, [(1, 2), (2, 3), (3, 4), (4, 5)]) == ("NO", 1) def test_already_biconnected(): assert find_min_roads(5, 6, [(1, 2), (2, 3), (3, 4), (4, 5), (5, 1), (3, 5)]) == ("YES", None) def test_disconnected_components(): assert...
[ { "docstring": null, "function_declaration": "def find_min_roads_to_add(n, m, roads):", "function_name": "find_min_roads_to_add", "parameter_list": "(n, m, roads)" }, { "docstring": null, "function_declaration": "def find_min_roads(n, m, roads):", "function_name": "find_min_roads", ...
[ 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 check_road_network(n, m, roads):\n from collections import defaultdict, deque\n\n # Create an adjacency list for the graph\n adj = defaultdict(li...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00024032", "row_id": 24032, "seed_ids": "[1684, 440, 552]" }
0.723665
Codeforces_24032
I
[ "find_min_roads_to_add", "find_min_roads" ]
2
[ [ "find_min_roads", "find_min_roads_to_add" ] ]
1
[]
false
[]
false
pytest
true
[]
true
7d0807a3b9cdf51287c1924ce49cb05d4e70612e
bee322525d0e26fc7f004346e715f92a77db570b
v1.0
instruct
Codeforces
Codeforces_24038_I
Given a directed graph with $$n$$ nodes (numbered from 1 to n) and $$m$$ edges, determine if it contains a cycle. If there is a cycle, output "YES"; otherwise, output "NO". The first line of the input contains two integers $$n$$ and $$m$$ ($$1 \leq n, m \leq 10^5$$) — the number of nodes and the number of edges in the...
from collections import defaultdict def is_cyclic_util(v, visited, rec_stack, graph): visited[v] = True rec_stack[v] = True for neighbour in graph[v]: if not visited[neighbour]: if is_cyclic_util(neighbour, visited, rec_stack, graph): return True elif rec_st...
def test_contains_cycle(): assert contains_cycle(4, 4, [(1, 2), (2, 3), (3, 4), (4, 2)]) == "YES" assert contains_cycle(4, 3, [(1, 2), (2, 3), (3, 4)]) == "NO" assert contains_cycle(1, 0, []) == "NO" assert contains_cycle(2, 2, [(1, 2), (2, 1)]) == "YES" assert contains_cycle(3, 3, [(1, 2), (2, 3), ...
[ { "docstring": null, "function_declaration": "def is_cyclic_util(v, visited, rec_stack, graph):", "function_name": "is_cyclic_util", "parameter_list": "(v, visited, rec_stack, graph)" }, { "docstring": null, "function_declaration": "def contains_cycle(n, m, edges):", "function_name":...
[ 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 has_cycle(n, m, edges):\n from collections import defaultdict, deque\n\n def dfs(node, visited, rec_stack):\n visited[node] = True\n r...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00024038", "row_id": 24038, "seed_ids": "[4525, 3590, 2710]" }
0.785548
Codeforces_24038
I
[ "is_cyclic_util", "contains_cycle" ]
2
[ [ "contains_cycle", "is_cyclic_util" ] ]
1
[]
false
[]
false
pytest
false
[]
true
5481a9e4316a63df4cd3e5723d173232f93ddcd1
953d5b82439f4e8528adaaf1785dfc59191440a1
v1.0
instruct
Codeforces
Codeforces_24070_I
Professor Smith is conducting research on DNA sequences. He often needs to find and compare patterns within DNA strings. Recently, he encountered a task where he needs to identify possible mutations between two DNA sequences. You are given two non-empty DNA sequences, represented as strings s1 and s2, which consist on...
def min_mutations(s1, s2): """ Determine the minimum number of mutations needed to transform s1 to s2. If it's not possible, return -1. """ if len(s1) != len(s2): return -1 mutations = 0 for i in range(len(s1)): if s1[i] != s2[i]: mutations += 1 retu...
from solution import can_transform def test_basic_mutation(): assert can_transform("AGCT", "TCGA") == 4 def test_same_sequences(): assert can_transform("ATCG", "ATCG") == 0 def test_single_mutation(): assert can_transform("A", "T") == 1 def test_two_different_sequences(): assert can_transform("AAA",...
[ { "docstring": "Determine the minimum number of mutations needed to transform s1 to s2.\nIf it's not possible, return -1.", "function_declaration": "def min_mutations(s1, s2):", "function_name": "min_mutations", "parameter_list": "(s1, s2)" }, { "docstring": "Check if it is possible to trans...
[ 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 min_mutations(s1, s2):\n \"\"\"\n Calculates the minimum number of mutations required to transform DNA sequence s1 into s2.\n If such transformat...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00024070", "row_id": 24070, "seed_ids": "[1789, 4345, 801]" }
0.653379
Codeforces_24070
I
[ "min_mutations", "can_transform" ]
2
[ [ "can_transform", "min_mutations" ] ]
1
[]
false
[]
false
pytest
true
[]
true
69d63927503eb3892211990e76a6373ded3fcee5
22469a72ec3e9cf210eac86984e0e4e9f7f731f0
v1.0
instruct
Codeforces
Codeforces_24073_I
You are given a binary tree with n nodes (1 ≤ n ≤ 1000), where each node has a unique value between 1 and n. The task is to find the most frequent subtree sum. A subtree sum is defined as the sum of all node values in a subtree, including the root of the subtree. The input begins with a single integer n, the number of...
from collections import defaultdict, Counter class TreeNode: def __init__(self, value=0): self.value = value self.left = None self.right = None def find_frequent_tree_sum(root): subtree_sum_count = Counter() def dfs(node): if not node: return 0 left_sum...
from solution import most_frequent_subtree_sum def test_most_frequent_subtree_sum_example(): n = 5 nodes_info = [ (1, 2, 3), (2, -1, -1), (3, 4, 5), (4, -1, -1), (5, -1, -1) ] assert most_frequent_subtree_sum(n, nodes_info) == 2 def test_most_frequent_subtree_su...
[]
[ 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 defaultdict\n\nclass TreeNode:\n def __init__(self, x):\n self.val = x\n self.left = None\n self.right = None\...
trial_gpt4o_3
{ "original_instruction": "", "prompt_id": "00024073", "row_id": 24073, "seed_ids": "[3283, 1314, 3031]" }
0.594532
Codeforces_24073
I
[ "find_frequent_tree_sum", "build_tree", "most_frequent_subtree_sum" ]
3
[ [ "most_frequent_subtree_sum", "build_tree" ], [ "most_frequent_subtree_sum", "find_frequent_tree_sum" ] ]
2
[]
false
[ "TreeNode" ]
true
pytest
true
[]
true
1fa21e0ba5d96513cc507d378c585f97e90d10cb
561c8e33c00b0d4f9855297be8efc9daea71cf95
v1.0
instruct
Codeforces
Codeforces_24154_I
The kingdom of Flatland is represented by a grid with n rows and m columns. The grid cells are numbered from 1 to n from top to bottom and from 1 to m from left to right. Each cell contains an elevation, which is an integer value. Flatland recently experienced heavy rainfall, causing water to accumulate in various are...
import heapq def trapRainWater(elevation_map): if not elevation_map or not elevation_map[0]: return 0 n, m = len(elevation_map), len(elevation_map[0]) visited = [[False for _ in range(m)] for _ in range(n)] heap = [] for i in range(n): for j in range(m): if i == 0 or i...
from solution import total_water_acummulation def test_example_case(): grid = [ [1, 2, 1], [2, 1, 2], [1, 2, 1] ] assert total_water_acummulation(3, 3, grid) == 1 def test_no_water(): grid = [ [1, 1, 1], [1, 1, 1], [1, 1, 1] ] assert total_water_...
[ { "docstring": null, "function_declaration": "def trapRainWater(elevation_map):", "function_name": "trapRainWater", "parameter_list": "(elevation_map)" }, { "docstring": null, "function_declaration": "def total_water_acummulation(n, m, grid):", "function_name": "total_water_acummulat...
[ 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 total_water_volume(n, m, grid):\n if not grid or not grid[0]:\n return 0\n\n heap = []\n visited = [[False] * m for _ in r...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00024154", "row_id": 24154, "seed_ids": "[2970, 1785, 7471]" }
0.654328
Codeforces_24154
I
[ "trapRainWater", "total_water_acummulation" ]
2
[ [ "total_water_acummulation", "trapRainWater" ] ]
1
[]
false
[]
false
pytest
true
[]
true
f168c714def12c57c3f7f160873c80180e00ae44
c9df988cb2200ab938f7d5c08d6299debd1b01a8
v1.0
instruct
Codeforces
Codeforces_24189_I
You are the organizer of a marathon event. The marathon route includes several checkpoints where runners must pass and log their times. Each checkpoint records the time when a runner crosses that checkpoint. However, due to a malfunction in one or more checkpoints, some log times might be missing. Your task is to recon...
def parse_time(time_str): """ Convert time string in hh:mm:ss format to seconds. """ h, m, s = map(int, time_str.split(':')) return h * 3600 + m * 60 + s def format_time(seconds): """ Convert seconds to time string in hh:mm:ss format. """ h = seconds // 3600 m = (seconds % 3600) // 60 s = s...
from solution import reconstruct_checkpoint_times def test_reconstruct_single_runner(): result = reconstruct_checkpoint_times(1, 4, ["12:00:00 - 12:30:00 13:00:00"]) assert result == ["12:00:00 12:15:00 12:30:00 13:00:00"] def test_reconstruct_multiple_runners(): result = reconstruct_checkpoint_times(2, 4...
[ { "docstring": "Convert time string in hh:mm:ss format to seconds. ", "function_declaration": "def parse_time(time_str):", "function_name": "parse_time", "parameter_list": "(time_str)" }, { "docstring": "Convert seconds to time string in hh:mm:ss format. ", "function_declaration": "def f...
[ 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 hhmmss_to_seconds(hhmmss):\n \"\"\"\n Convert hh:mm:ss to total seconds.\n \"\"\"\n hh, mm, ss = map(int, hhmmss.split(':'))\n return hh * ...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00024189", "row_id": 24189, "seed_ids": "[4894, 935, 8028]" }
0.611204
Codeforces_24189
I
[ "parse_time", "format_time", "reconstruct_checkpoint_times" ]
3
[ [ "reconstruct_checkpoint_times", "format_time" ], [ "reconstruct_checkpoint_times", "parse_time" ] ]
2
[]
false
[]
false
pytest
true
[]
true
2ff3602e1f0dc697f626ba5ef45a0b6cd488e271
383046acf807170e253ff1b6f125a63c030bd30c
v1.0
instruct
Codeforces
Codeforces_24217_I
In the land of Arithmania, people love playing with arrays and numbers. Shem, the town's mathematician, recently came up with a fascinating problem. Given an array of n integers, Shem wants to divide it into exactly k non-empty contiguous subarrays such that the sum of elements in each subarray is maximized. Shem needs...
def can_divide(nums, k, min_sum): current_sum = 0 subarrays = 1 for num in nums: if current_sum + num > min_sum: subarrays += 1 current_sum = num if subarrays > k: return False else: current_sum += num return True def maxim...
from solution import maximum_minimum_sum def test_example_case(): assert maximum_minimum_sum(5, 2, [1, 2, 3, 4, 5]) == 9 def test_single_element_array(): assert maximum_minimum_sum(1, 1, [10]) == 10 def test_equal_elements(): assert maximum_minimum_sum(4, 2, [1, 1, 1, 1]) == 2 def test_larger_array(): ...
[ { "docstring": null, "function_declaration": "def can_divide(nums, k, min_sum):", "function_name": "can_divide", "parameter_list": "(nums, k, min_sum)" }, { "docstring": null, "function_declaration": "def maximum_minimum_sum(n, k, nums):", "function_name": "maximum_minimum_sum", ...
[ 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 max_minimum_sum_subarrays(n, k, arr):\n def can_divide(x):\n subarray_count = 1\n current_sum = 0\n \n for num in arr:\n ...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00024217", "row_id": 24217, "seed_ids": "[3100, 2427, 268]" }
0.800938
Codeforces_24217
I
[ "can_divide", "maximum_minimum_sum" ]
2
[ [ "maximum_minimum_sum", "can_divide" ] ]
1
[]
false
[]
false
pytest
true
[]
true
0486a540c4e52a6c8f7a444b79ce636e3e93ab01
db6fe3ee218289c6ba28391a2fcef409dccefe52
v1.0
instruct
Codeforces
Codeforces_24276_I
You are given a tree (a connected undirected graph with no cycles) with n vertices. Each vertex has a value associated with it. Your task is to find the maximum sum of values along any path in the tree. A path is defined as a sequence of vertices where each adjacent pair of vertices in the sequence is connected by an e...
from collections import defaultdict import sys sys.setrecursionlimit(200000) def build_tree(edges, n): tree = defaultdict(list) for u, v in edges: tree[u].append(v) tree[v].append(u) return tree def max_path_sum(n, values, edges): tree = build_tree(edges, n) visited = [False] * (n...
from solution import max_path_sum def test_case_1(): assert max_path_sum(5, [1, 2, 3, 4, 5], [(1, 2), (2, 3), (3, 4), (4, 5)]) == 15 def test_case_2(): assert max_path_sum(3, [10, 20, 30], [(1, 2), (1, 3)]) == 60 def test_case_3(): assert max_path_sum(4, [5, 5, 5, 5], [(1, 2), (1, 3), (1, 4)]) == 20 def...
[ { "docstring": null, "function_declaration": "def build_tree(edges, n):", "function_name": "build_tree", "parameter_list": "(edges, n)" }, { "docstring": null, "function_declaration": "def max_path_sum(n, values, edges):", "function_name": "max_path_sum", "parameter_list": "(n, v...
[ 0, 0, 1, 0 ]
1
hard
0.25
{ "trial_gpt4o_0": null, "trial_gpt4o_1": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared1_results_combined.jsonl", "solution_code": "def max_path_sum(n, values, edges):\n from collections import defaultdict\n \n def dfs(node, parent):\n max1, max2 = ...
trial_gpt4o_3
{ "original_instruction": "", "prompt_id": "00024276", "row_id": 24276, "seed_ids": "[4436, 8077, 4362]" }
0.704649
Codeforces_24276
I
[ "build_tree", "max_path_sum" ]
2
[ [ "max_path_sum", "build_tree" ] ]
1
[]
false
[]
false
pytest
true
[]
true
d72071e446e0ede712d53de1b00c6138f1263216
0d8f4f98c72b08f7f1e134eb5df07dc960450bd8
v1.0
instruct
Codeforces
Codeforces_24337_I
You are given a grid with n rows and m columns filled with integers. Your task is to find the largest sum of any rectangle subgrid. A rectangle subgrid is defined by choosing two rows and two columns. The sum of the rectangle subgrid is the sum of all integers inside the rectangle defined by these rows and columns. W...
def max_sum_subgrid(grid): """ Returns the largest sum of any rectangle subgrid in the given grid. """ n = len(grid) m = len(grid[0]) # Initialize max_sum to be the smallest possible value max_sum = float('-inf') # Temporary array used to store sums temp = [0] * n # Us...
import pytest from solution import find_largest_sum def test_example_case(): n = 4 m = 5 elements = [ [1, 2, -1, -4, -20], [-8, -3, 4, 2, 1], [3, 8, 10, 1, 3], [-4, -1, 1, 7, -6] ] assert find_largest_sum(n, m, elements) == 29 def test_single_element_grid():...
[ { "docstring": "Returns the largest sum of any rectangle subgrid in the given grid.", "function_declaration": "def max_sum_subgrid(grid):", "function_name": "max_sum_subgrid", "parameter_list": "(grid)" }, { "docstring": null, "function_declaration": "def find_largest_sum(n, m, elements)...
[ 0, 0, 0, 0, 0, 0, 1, 0, 0, 1 ]
2
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def max_sum_subgrid(grid):\n \"\"\"\n Returns the largest sum of any rectangle subgrid in the given 2D grid.\n \"\"\"\n n = len(grid)\n m = len...
trial_gpt4o_6
{ "original_instruction": "", "prompt_id": "00024337", "row_id": 24337, "seed_ids": "[3391, 6794, 3025]" }
0.687359
Codeforces_24337
I
[ "max_sum_subgrid", "find_largest_sum" ]
2
[ [ "find_largest_sum", "max_sum_subgrid" ] ]
1
[]
false
[]
false
pytest
true
[]
true
76549a501ebfdf90622b534b70e4b1b7aaf6e0e4
e65ca29d04154ea19a38aca974565ca9447c684f
v1.0
instruct
Codeforces
Codeforces_24388_I
The city of ByteLand is known for its intricate network of bidirectional roads connecting various districts. Each district is represented by an integer (1 to n). The road network is designed such that from any district, you can reach any other district through one or more roads. ByteLand also runs a unique subway line ...
def find_parent(parent, x): if parent[x] != x: parent[x] = find_parent(parent, parent[x]) return parent[x] def union(parent, rank, x, y): rootX = find_parent(parent, x) rootY = find_parent(parent, y) if rootX != rootY: if rank[rootX] > rank[rootY]: parent[rootY] = r...
from solution import solve_connectivity def test_example_case(): n, m = 5, 2 subway_lines = [ [1, 2, 3], [3, 4] ] queries = [ (1, 3), (1, 4), (2, 5), (3, 4) ] result = solve_connectivity(n, m, subway_lines, queries) assert result == ["YES", "Y...
[ { "docstring": null, "function_declaration": "def find_parent(parent, x):", "function_name": "find_parent", "parameter_list": "(parent, x)" }, { "docstring": null, "function_declaration": "def union(parent, rank, x, y):", "function_name": "union", "parameter_list": "(parent, rank...
[ 0, 0, 1, 0 ]
1
hard
0.25
{ "trial_gpt4o_0": null, "trial_gpt4o_1": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared1_results_combined.jsonl", "solution_code": "def are_districts_connected(n, m, subway_lines, queries):\n from collections import defaultdict\n\n # Create a map to store dis...
trial_gpt4o_3
{ "original_instruction": "", "prompt_id": "00024388", "row_id": 24388, "seed_ids": "[909, 6014, 6934]" }
0.75441
Codeforces_24388
I
[ "find_parent", "union", "solve_connectivity" ]
3
[ [ "solve_connectivity", "find_parent" ], [ "solve_connectivity", "union" ], [ "union", "find_parent" ] ]
3
[]
false
[]
false
pytest
true
[]
true
50b93e81f8ffdcb6fe21d3731c47607d6f38cc20
3a4dd9a20bcf84dcd6d262f2e0915cad05dde5e4
v1.0
instruct
Codeforces
Codeforces_24393_I
In a kingdom, there are n cities connected by m bidirectional roads. The cities are numbered from 1 to n. Each road connects two different cities and has a certain travel cost associated with it. The king wants to construct a new road network such that every city is accessible from every other city using the new roads....
def find(parent, i): if parent[i] == i: return i else: return find(parent, parent[i]) def union(parent, rank, x, y): xroot = find(parent, x) yroot = find(parent, y) if rank[xroot] < rank[yroot]: parent[xroot] = yroot elif rank[xroot] > rank[yroot]: paren...
from solution import minimum_travel_cost def test_case_1(): n = 4 roads = [(1, 2, 1), (2, 3, 2), (3, 4, 3), (4, 1, 4), (1, 3, 5)] assert minimum_travel_cost(n, roads) == 6 def test_case_2(): n = 3 roads = [(1, 2, 1), (2, 3, 2), (1, 3, 3)] assert minimum_travel_cost(n, roads) == 3 def test_cas...
[ { "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 kruskal(n, m, edges):\n \"\"\"\n Utilizes Kruskal's algorithm to find the minimum spanning tree of a graph.\n\n :param n: Number of cities (nodes...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00024393", "row_id": 24393, "seed_ids": "[4378, 5861, 7144]" }
0.751534
Codeforces_24393
I
[ "find", "union", "kruskal", "minimum_travel_cost" ]
4
[ [ "kruskal", "find" ], [ "kruskal", "union" ], [ "minimum_travel_cost", "kruskal" ], [ "union", "find" ] ]
4
[]
false
[]
false
pytest
true
[]
true
d20f220a9b08faa795286ac9c1ab46cbab708bb9
77e242a9a48e36129467f1b0cd30b4747bc7d362
v1.0
instruct
Codeforces
Codeforces_24413_I
Peter loves solving puzzles and stumbled upon an interesting sequence problem. He names it a "Zigzag Sequence." A sequence of numbers \(a_1, a_2, \ldots, a_n\) is a Zigzag Sequence if it contains at least two elements, and it satisfies one of the two following properties throughout the entire sequence: 1. \(a_1 < a_2 ...
def longest_zigzag_sequence(arr): if not arr: return 0 n = len(arr) if n == 1: return 1 up = [1] * n down = [1] * n for i in range(1, n): if arr[i] > arr[i - 1]: up[i] = down[i - 1] + 1 down[i] = down[i - 1] elif arr[i] < arr[i - 1]: ...
from solution import zig_zag def test_example1(): assert zig_zag(6, [1, 7, 4, 9, 2, 5]) == 6 def test_example2(): assert zig_zag(5, [1, 4, 7, 2, 5]) == 4 def test_example3(): assert zig_zag(3, [1, 2, 3]) == 2 def test_all_increasing(): assert zig_zag(4, [1, 2, 3, 4]) == 2 def test_all_decreasing():...
[ { "docstring": null, "function_declaration": "def longest_zigzag_sequence(arr):", "function_name": "longest_zigzag_sequence", "parameter_list": "(arr)" }, { "docstring": null, "function_declaration": "def zig_zag(n, arr):", "function_name": "zig_zag", "parameter_list": "(n, arr)"...
[ 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 longest_zigzag_sequence(arr):\n if not arr:\n return 0\n\n n = len(arr)\n if n == 1:\n return 1\n\n up = [1] * n\n down = [1]...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00024413", "row_id": 24413, "seed_ids": "[3327, 7915, 855]" }
0.691727
Codeforces_24413
I
[ "longest_zigzag_sequence", "zig_zag" ]
2
[ [ "zig_zag", "longest_zigzag_sequence" ] ]
1
[]
false
[]
false
pytest
true
[]
true
1dd5330dfd9caed75c0da37cae885ca8629264e4
ebdf27cc53565edb6529d6955af44a742a62df8c
v1.0
instruct
Codeforces
Codeforces_24460_I
John has recently learned about prime palindromes and is fascinated by them. A prime palindrome is a number that is both prime and a palindrome. In other words, it should read the same forwards and backwards and should only have 1 and itself as divisors. John wants to find the smallest prime palindrome greater than or ...
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 is_palindrome(n): return str(n) == str...
from solution import is_prime, is_palindrome, smallest_prime_palindrome def test_is_prime(): assert is_prime(2) == True assert is_prime(3) == True assert is_prime(4) == False assert is_prime(5) == True def test_is_palindrome(): assert is_palindrome(101) == True assert is_palindrome(12321) == T...
[ { "docstring": null, "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": null, "function_declaration": "def is_palindrome(n):", "function_name": "is_palindrome", "parameter_list": "(n)" }, { "docstring": null,...
[ 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 is_prime(n):\n \"\"\"\n Check if a number is a prime number.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return True\...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00024460", "row_id": 24460, "seed_ids": "[6250, 2777, 6429]" }
0.77561
Codeforces_24460
I
[ "is_prime", "is_palindrome", "smallest_prime_palindrome" ]
3
[ [ "smallest_prime_palindrome", "is_palindrome" ], [ "smallest_prime_palindrome", "is_prime" ] ]
2
[]
false
[]
false
pytest
true
[]
true
7348cc887277fc8bdf1d7caa60bc5c631329e7ec
b095eb12b7821b02ecbf6a56fbefa7c84a6d898c
v1.0
instruct
Codeforces
Codeforces_24476_I
A company wants to optimize its supply chain by minimizing the transportation costs associated with delivering goods from its central warehouse to multiple distribution centers. The company has a list of delivery routes connecting these centers, with each route having a specific transportation cost. The problem can be ...
import heapq def find(parent, i): """ A utility function to find set of an element i (uses path compression technique). """ if parent[i] == i: return i else: parent[i] = find(parent, parent[i]) return parent[i] def union(parent, rank, x, y): """ A function that ...
from solution import minimum_transportation_cost def test_example(): assert minimum_transportation_cost(4, 5, [ (1, 2, 4), (1, 3, 3), (2, 3, 2), (2, 4, 5), (3, 4, 7), ]) == 10 def test_impossible_case(): assert minimum_transportation_cost(3, 1, [ (1, 2, 4) ...
[ { "docstring": "A utility function to find set of an element i\n(uses path compression technique).", "function_declaration": "def find(parent, i):", "function_name": "find", "parameter_list": "(parent, i)" }, { "docstring": "A function that does union of two sets of x and y\n(uses union by r...
[ 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_transportation_cost(n, m, routes):\n import heapq\n from collections import defaultdict\n\n if n == 1:\n return 0\n\n graph = d...
trial_gpt4o_4
{ "original_instruction": "", "prompt_id": "00024476", "row_id": 24476, "seed_ids": "[1156, 133, 1642]" }
0.763237
Codeforces_24476
I
[ "find", "union", "minimum_spanning_tree", "minimum_transportation_cost" ]
4
[ [ "minimum_spanning_tree", "find" ], [ "minimum_spanning_tree", "union" ], [ "minimum_transportation_cost", "minimum_spanning_tree" ], [ "union", "find" ] ]
4
[]
false
[]
false
pytest
true
[]
true
96c1efdfd335ec6a4f83e74da482189504b1f325
918a80e8c0c28e63adb6cb0b808e3ba68ea50cfa
v1.0
instruct
Codeforces
Codeforces_24535_I
Given a matrix of integers with dimensions $$$n \times m$$$, your task is to find the largest submatrix (consecutive subarray) that can be rearranged to form a magic square. A magic square is a grid of distinct numbers in which the sums of the numbers in each row, each column, and both main diagonals are the same. The ...
def is_magic_square(grid, size): s = sum(grid[0]) # Check rows and columns for i in range(size): if sum(grid[i]) != s or sum(grid[j][i] for j in range(size)) != s: return False # Check diagonals if sum(grid[i][i] for i in range(size)) != s or sum(grid[i][size-i-1] for i...
import pytest from solution import find_largest_magic_square def test_magic_square_example(): matrix = [ [16, 3, 2, 13], [5, 10, 11, 8], [9, 6, 7, 12], [4, 15, 14, 1] ] assert find_largest_magic_square(matrix) == 4 def test_no_magic_square(): matrix = [ [1, 2], ...
[ { "docstring": null, "function_declaration": "def is_magic_square(grid, size):", "function_name": "is_magic_square", "parameter_list": "(grid, size)" }, { "docstring": null, "function_declaration": "def largest_magic_square(matrix, n, m):", "function_name": "largest_magic_square", ...
[ 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_magic_square(matrix, n):\n magic_sum = n * (n * n + 1) // 2\n unique_numbers = set()\n\n # Check uniqueness and range of numbers\n for row ...
trial_gpt4o_4
{ "original_instruction": "", "prompt_id": "00024535", "row_id": 24535, "seed_ids": "[2196, 1674, 3845]" }
0.606657
Codeforces_24535
I
[ "is_magic_square", "largest_magic_square", "find_largest_magic_square" ]
3
[ [ "find_largest_magic_square", "largest_magic_square" ], [ "largest_magic_square", "is_magic_square" ] ]
2
[]
false
[]
false
pytest
true
[]
true
58f937c2f4364af566546b83b2508381916f409c
1c12caf06d86f398227a47719fda947fc8ea403b
v1.0
instruct
Codeforces
Codeforces_24545_I
You are given a grid of size $$$n \times m$$$ ($$$1 \le n, m \le 50$$$) containing non-negative integers. The grid contains some blocked cells with a value of -1, which cannot be traversed. You need to find the number of distinct paths from the top-left cell (1,1) to the bottom-right cell ($$$n$$$, $$$m$$$) such that y...
def unique_paths(grid): n = len(grid) m = len(grid[0]) # If the starting or ending cell is blocked, there is no valid path if grid[0][0] == -1 or grid[n-1][m-1] == -1: return 0 # Initialize dp table dp = [[0] * m for _ in range(n)] dp[0][0] = 1 # Fill the dp table for i in...
def test_unique_paths_example1(): grid = [ [0, 0, 0], [0, -1, 0], [0, 0, 0] ] assert unique_paths(grid) == 2 def test_unique_paths_example2(): grid = [ [0, 0, 0], [-1, -1, 0], [0, 0, 0] ] assert unique_paths(grid) == 1 def test_unique_paths_examp...
[ { "docstring": null, "function_declaration": "def unique_paths(grid):", "function_name": "unique_paths", "parameter_list": "(grid)" }, { "docstring": null, "function_declaration": "def get_input_and_solve():", "function_name": "get_input_and_solve", "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": "def count_paths(grid):\n n = len(grid)\n m = len(grid[0])\n if grid[0][0] == -1 or grid[n-1][m-1] == -1:\n return 0\n\n dp = [[0] * m for _...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00024545", "row_id": 24545, "seed_ids": "[1021, 3326, 1177]" }
0.811097
Codeforces_24545
I
[ "unique_paths", "get_input_and_solve" ]
2
[ [ "get_input_and_solve", "unique_paths" ] ]
1
[]
false
[]
false
pytest
false
[]
true
5f1a4d4f332e16c55cd35f0097b34bcbdb1e9029
677b79501a4b58d4d6288e06358d4843c16527a6
v1.0
instruct
Codeforces
Codeforces_24589_I
John is a computer science student and loves working with trees. He recently came across a problem that involves binary trees and path sums, and he needs your help to solve it. The problem is as follows: Given a binary tree where each node contains an integer value, find all root-to-leaf paths where each path's sum eq...
from typing import List, Optional class TreeNode: def __init__(self, x): self.val = x self.left = None self.right = None def build_tree(nodes: List[Optional[int]]) -> Optional[TreeNode]: if not nodes: return None root = TreeNode(nodes[0]) queue = [root] i = 1 wh...
from solution import find_paths def test_no_path_sum(): tree = [1, 2, 3] S = 5 assert find_paths(tree, S) == [] def test_single_path_sum(): tree = [1, 2, 3] S = 4 assert find_paths(tree, S) == [[1, 3]] def test_multiple_path_sum(): tree = [5, 4, 8, 11, None, 13, 4, 7, 2, None, None, 5, 1]...
[]
[ 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 typing import List, Optional\n\nclass TreeNode:\n def __init__(self, val=0, left=None, right=None):\n self.val = val\n self.left = left\...
trial_gpt4o_6
{ "original_instruction": "", "prompt_id": "00024589", "row_id": 24589, "seed_ids": "[1678, 3000, 6737]" }
0.562653
Codeforces_24589
I
[ "build_tree", "find_paths" ]
2
[ [ "find_paths", "build_tree" ] ]
1
[]
false
[ "TreeNode" ]
true
pytest
true
[]
true
086809a93849409dc7c777730a89220a5640f330
34416e2ef570d187626f425338197d75e7aeba27
v1.0
instruct
Codeforces
Codeforces_24613_I
Alice and Bob are playing a game with a sequence of positive integers a1, a2, ..., an. They take turns, starting with Alice. On each turn, the player picks a number from the sequence, removes it, and replaces it with two numbers whose sum is equal to the removed number. The game continues until all numbers in the seque...
def is_prime(number): """ Returns True if the number is prime, otherwise False """ if number <= 1: return False if number <= 3: return True if number % 2 == 0 or number % 3 == 0: return False i = 5 while i * i <= number: if number % i == 0 or number % (i + 2) == 0...
from solution import is_prime, determine_winner 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(1) == False def test_determine_winner_all_primes(): assert determi...
[ { "docstring": "Returns True if the number is prime, otherwise False ", "function_declaration": "def is_prime(number):", "function_name": "is_prime", "parameter_list": "(number)" }, { "docstring": "Determines the winner of the game given the initial sequence of numbers\nwith optimal play.", ...
[ 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_prime(number):\n \"\"\" Returns True if the number is prime, otherwise False \"\"\"\n if number <= 1:\n return False\n if number <= 3:\...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00024613", "row_id": 24613, "seed_ids": "[3050, 4709, 1374]" }
0.799898
Codeforces_24613
I
[ "is_prime", "determine_winner" ]
2
[ [ "determine_winner", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
58a077c85ef87087819a2fe8ecdb392e4d930e06
f1521e9849740b281de9b27c4008d0e63697eb95
v1.0
instruct
Codeforces
Codeforces_24633_I
Michael is a big fan of coding challenges. He has recently been working on a unique type of problem involving sequences of numbers. The sequence that Michael is dealing with has an interesting property: the difference between consecutive numbers is not fixed but follows a pattern based on prime numbers. Given a sequen...
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_prime_index_differences(n, sequence): ...
from solution import sum_prime_index_differences def test_example1(): assert sum_prime_index_differences(6, [1, 3, 10, 4, 20, 7]) == 17 def test_example2(): assert sum_prime_index_differences(4, [10, 25, 30, 40]) == 5 def test_no_primes(): assert sum_prime_index_differences(1, [1]) == 0 def test_single_...
[ { "docstring": null, "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": null, "function_declaration": "def sum_prime_index_differences(n, sequence):", "function_name": "sum_prime_index_differences", "parameter_list":...
[ 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_prime(n):\n if n <= 1:\n return False\n if n <= 3:\n return True\n if n % 2 == 0 or n % 3 == 0:\n return False\n i = 5...
trial_gpt4o_4
{ "original_instruction": "", "prompt_id": "00024633", "row_id": 24633, "seed_ids": "[398, 3328, 24]" }
0.697122
Codeforces_24633
I
[ "is_prime", "sum_prime_index_differences" ]
2
[ [ "sum_prime_index_differences", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
3c3533540a7ba2708106ed474b8c213cf7b52e80
ee51c83db353e2574ca98fb64c21b79c138935e9
v1.0
instruct
Codeforces
Codeforces_24657_I
Petya is learning math and particularly enjoys solving math puzzles. His current task is to find all pairs of integers $\$(a, b)\$ that satisfy the equation \$a^2 + b^2 = n\$ for a given integer \(\$n\$). He finds this task challenging and has asked for your help. Write a program that takes a positive integer \(\$n\$ ...
def find_pairs(n): """ Returns all pairs (a, b) such that a^2 + b^2 = n. Order of pairs doesn't matter, i.e., (a, b) is the same as (b, a). """ pairs = [] for a in range(int(n**0.5) + 1): b_squared = n - a**2 b = int(b_squared**0.5) if b**2 == b_squared and a <= b: ...
from solution import find_pairs, display_pairs def test_find_pairs_no_pairs(): assert find_pairs(3) == [] def test_find_pairs_single_pair(): assert find_pairs(5) == [(1, 2)] def test_find_pairs_multiple_pairs(): assert find_pairs(50) == [(1, 7), (5, 5)] def test_find_pairs_large_input(): assert find...
[ { "docstring": "Returns all pairs (a, b) such that a^2 + b^2 = n. Order of pairs doesn't matter, i.e., (a, b) is the same as (b, a).", "function_declaration": "def find_pairs(n):", "function_name": "find_pairs", "parameter_list": "(n)" }, { "docstring": null, "function_declaration": "def...
[ 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": "import math\n\ndef find_pairs(n):\n \"\"\"\n Finds all unique pairs (a, b) such that a^2 + b^2 = n.\n Each pair is printed on a separate line.\n I...
trial_gpt4o_3
{ "original_instruction": "", "prompt_id": "00024657", "row_id": 24657, "seed_ids": "[6497, 5344, 5804]" }
0.592727
Codeforces_24657
I
[ "find_pairs", "display_pairs" ]
2
[ [ "display_pairs", "find_pairs" ] ]
1
[]
false
[]
false
pytest
true
[]
true
24592b2b997db8df64f8bb5b8a8bdd147935beef
724002c8125b020328f4cde4c52996e0e8b87311
v1.0
instruct
Codeforces
Codeforces_24673_I
You are given a grid of size `n x m` consisting of empty cells ('.') and blocks ('#'). Your task is to determine if there exists a path from the top-left corner of the grid (cell at (1, 1)) to the bottom-right corner of the grid (cell at (n, m)) that passes through each cell exactly once. If such a path exists, print "...
def is_valid(x, y, n, m, grid, visited): return 0 <= x < n and 0 <= y < m and grid[x][y] == '.' and not visited[x][y] def find_hamiltonian_path(n, m, grid): def dfs(x, y, step): if step == n * m: return True visited[x][y] = True for dx, dy in directions: ...
def test_find_hamiltonian_path(): assert find_hamiltonian_path(4, 4, ["....", ".##.", "....", "...."]) == "No" assert find_hamiltonian_path(1, 1, ["."]) == "Yes" assert find_hamiltonian_path(2, 2, ["..", ".."]) == "Yes" assert find_hamiltonian_path(2, 2, [".#", "#."]) == "No" assert find_hamiltonian...
[ { "docstring": null, "function_declaration": "def is_valid(x, y, n, m, grid, visited):", "function_name": "is_valid", "parameter_list": "(x, y, n, m, grid, visited)" }, { "docstring": null, "function_declaration": "def find_hamiltonian_path(n, m, grid):", "function_name": "find_hamil...
[ 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 is_path_possible(n, m, grid):\n \"\"\"\n Determines if there is a Hamiltonian path from the top-left to the bottom-right corner\n of the grid tha...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00024673", "row_id": 24673, "seed_ids": "[7245, 5538, 1173]" }
0.749783
Codeforces_24673
I
[ "is_valid", "find_hamiltonian_path" ]
2
[ [ "find_hamiltonian_path", "is_valid" ] ]
1
[]
false
[]
false
pytest
false
[]
true
9751f01fb082556b597ad85873e49b3e65e2fe6b
304bf06284b5d1b98da2fa848c3679b02d3ce5ee
v1.0
instruct
Codeforces
Codeforces_24680_I
Consider a grid-based maze composed of obstacles and one character. Each cell in the grid is represented by a character, where 'X' denotes an obstacle, '.' denotes a free cell, and 'C' denotes the initial position of the character. The character can move up, down, left, or right, but cannot move into cells marked as 'X...
def find_initial_position(maze, n, m): for i in range(n): for j in range(m): if maze[i][j] == 'C': return (i, j) return None def is_valid_position(x, y, n, m, maze, visited): return 0 <= x < n and 0 <= y < m and maze[x][y] != 'X' and not visited[x][y] def dfs(maze, x, y...
def test_find_initial_position(): maze = [ [".", "X", ".", "."], [".", ".", "X", "."], [".", "C", ".", "."], [".", ".", ".", "."] ] assert find_initial_position(maze, 4, 4) == (2, 1) def test_is_valid_position(): maze = [ [".", "X", ".", "."], [".", ".", ...
[ { "docstring": null, "function_declaration": "def find_initial_position(maze, n, m):", "function_name": "find_initial_position", "parameter_list": "(maze, n, m)" }, { "docstring": null, "function_declaration": "def is_valid_position(x, y, n, m, maze, visited):", "function_name": "is_...
[ 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_initial_position(maze, n, m):\n for i in range(n):\n for j in range(m):\n if maze[i][j] == 'C':\n return (i, j)\n...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00024680", "row_id": 24680, "seed_ids": "[3015, 1262, 4155]" }
0.726296
Codeforces_24680
I
[ "find_initial_position", "is_valid_position", "dfs", "can_reach_end" ]
4
[ [ "can_reach_end", "dfs" ], [ "can_reach_end", "find_initial_position" ], [ "dfs", "is_valid_position" ] ]
3
[]
false
[]
false
pytest
false
[]
true
18a44304f0e52777cbd1480839c5cc46c7bcb3a0
cac769ffff3d4c471bb5876b24c01103d9db4fc8
v1.0
instruct
Codeforces
Codeforces_24697_I
Sophie has been fascinated by prime numbers and decided to conduct an experiment involving arrays of integers. She wants to modify an array of integers in such a way that each element is increased to the nearest prime number that is greater than or equal to the element itself. To help Sophie with her experiment, you n...
def is_prime(n): """Check if a number is prime.""" if n <= 1: return False if n <= 3: return True if n % 2 == 0 or n % 3 == 0: return False i = 5 while i * i <= n: if n % i == 0 or n % (i + 2) == 0: return False i += 6 return True def near...
def test_is_prime(): assert not is_prime(1) assert is_prime(2) assert is_prime(3) assert not is_prime(4) assert is_prime(5) assert not is_prime(6) assert is_prime(29) assert not is_prime(30) def test_nearest_prime(): assert nearest_prime(7) == 7 assert nearest_prime(10) == 1...
[ { "docstring": "Check if a number is prime.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Find the nearest prime number greater than or equal to n.", "function_declaration": "def nearest_prime(n):", "function_nam...
[ 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 math\n\ndef is_prime(n):\n if n <= 1:\n return False\n if n == 2:\n return True\n if n % 2 == 0:\n return False\n max_...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00024697", "row_id": 24697, "seed_ids": "[3688, 3174, 3897]" }
0.680115
Codeforces_24697
I
[ "is_prime", "nearest_prime", "nearest_primes_array" ]
3
[ [ "nearest_prime", "is_prime" ], [ "nearest_primes_array", "nearest_prime" ] ]
2
[]
false
[]
false
pytest
false
[]
true
ee1749e15b00fb9b153dfe7a7652a6896760e261
cdb2580aa7f544a189723a124f8a2119281431b6
v1.0
instruct
Codeforces
Codeforces_24713_I
Consider a connected undirected graph with n nodes and m edges. Each node is assigned a color from 1 to k. You need to answer q questions, each asking for the number of distinct colors in the shortest path between two given nodes, u and v. For each query, find the shortest path (in terms of number of edges) between u ...
from collections import deque, defaultdict def bfs_shortest_path(graph, start_node, end_node): """ Perform BFS to find the shortest path from start_node to end_node. Return the nodes in the shortest path. """ queue = deque([(start_node, [start_node])]) visited = set() while queue: ...
from solution import answer_queries def test_example(): n, m, k = 5, 6, 3 node_colors = [1, 2, 3, 2, 1] edges = [(1, 2), (1, 3), (2, 4), (3, 4), (2, 5), (4, 5)] queries = [(1, 5), (2, 3), (3, 5)] results = answer_queries(n, m, k, node_colors, edges, queries) assert results == [2, 3, 3] def tes...
[ { "docstring": "Perform BFS to find the shortest path from start_node to end_node.\nReturn the nodes in the shortest path.", "function_declaration": "def bfs_shortest_path(graph, start_node, end_node):", "function_name": "bfs_shortest_path", "parameter_list": "(graph, start_node, end_node)" }, {...
[ 0, 0, 0, 0, 0, 1, 0, 1, 0, 1 ]
3
hard
0.3
{ "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 distinct_colors_on_shortest_path(n, m, k, colors, edges, queries):\n # Create adjacency list for the grap...
trial_gpt4o_7
{ "original_instruction": "", "prompt_id": "00024713", "row_id": 24713, "seed_ids": "[6393, 7893, 5582]" }
0.73792
Codeforces_24713
I
[ "bfs_shortest_path", "distinct_colors_in_path", "answer_queries" ]
3
[ [ "answer_queries", "bfs_shortest_path" ], [ "answer_queries", "distinct_colors_in_path" ] ]
2
[]
false
[]
false
pytest
true
[]
true
7f601909af6259ed1d5af4e9783c30af79ee3258
779d055d15d5eb1a75fd3d81648dbb8c2b552d22
v1.0
instruct
Codeforces
Codeforces_24779_I
In a faraway kingdom, there is a tree with $$$n$$$ nodes and $$$n-1$$$ edges. Each node represents a city and each edge represents a direct road between two cities. The king wants to set up a postal service such that for any two cities, the distance measured in number of edges (or roads) shall never exceed a given thre...
from collections import deque def find_farthest_node(tree, start): """ Performs BFS from the start node and returns the farthest node and its distance. """ n = len(tree) visited = [-1] * n queue = deque([(start, 0)]) visited[start] = 0 farthest_node = start max_distance = 0 whi...
def test_example_case(): edges = [(1, 2), (1, 3), (2, 4), (2, 5)] assert minimum_possible_max_distance(5, edges) == 2 def test_small_case(): edges = [(1, 2)] assert minimum_possible_max_distance(2, edges) == 1 def test_linear_tree(): edges = [(1, 2), (2, 3), (3, 4), (4, 5)] assert minimum_poss...
[ { "docstring": "Performs BFS from the start node and returns the farthest node and its distance.", "function_declaration": "def find_farthest_node(tree, start):", "function_name": "find_farthest_node", "parameter_list": "(tree, start)" }, { "docstring": "Computes the minimum possible value o...
[ 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\n\ndef find_farthest_node(tree, start):\n \"\"\"\n Performs BFS from the start node and returns the farthest node and its ...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00024779", "row_id": 24779, "seed_ids": "[1867, 793, 8176]" }
0.738168
Codeforces_24779
I
[ "find_farthest_node", "minimum_possible_max_distance" ]
2
[ [ "minimum_possible_max_distance", "find_farthest_node" ] ]
1
[]
false
[]
false
pytest
false
[]
true
3125571d7c8024d342fde68189c4d1e110d06d11
abff95bd394a2bdfd59306cba395a8992316e074
v1.0
instruct
Codeforces
Codeforces_24800_I
Four friends, Alex, Bonnie, Charlie, and Dana, decided to go on a hiking trip in the mountains. They need to leave their house as soon as possible to make the most of daylight. Each of them has a different readiness time, and they can't leave until everyone is ready. Moreover, they need to carry some hiking equipment, ...
from itertools import permutations def can_distribute(weights, capacities): """ Check if weights can be distributed among given capacities. """ n = len(capacities) perm = permutations(weights) for comb in perm: caps_copy = sorted(capacities, reverse=True) possible = True ...
from solution import hiking_trip_time def test_hiking_trip_time_possible_distribution_1(): assert hiking_trip_time(4, [10, 5, 8, 6], [200, 300, 150, 400], 3, [500, 200, 400]) == 10 def test_hiking_trip_time_possible_distribution_2(): assert hiking_trip_time(4, [10, 15, 8, 20], [500, 200, 300, 400], 4, [500, 5...
[ { "docstring": "Check if weights can be distributed among given capacities.", "function_declaration": "def can_distribute(weights, capacities):", "function_name": "can_distribute", "parameter_list": "(weights, capacities)" }, { "docstring": "Determine the minimum time to depart for the hikin...
[ 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 itertools import permutations\n\ndef min_departure_time(n, r, w, m, c):\n # Minimum readiness time is the maximum readiness time of the friends\n m...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00024800", "row_id": 24800, "seed_ids": "[1701, 4139, 4645]" }
0.651199
Codeforces_24800
I
[ "can_distribute", "hiking_trip_time" ]
2
[ [ "hiking_trip_time", "can_distribute" ] ]
1
[]
false
[]
false
pytest
true
[]
true
a4c88a1d9473e09902c19719cd80d8aa65a42a43
8f3c59b54c6ab627bdf6450605ba4d9e7b1ea4e1