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_24804_I
You are a software developer who has just joined a new company. One of your first tasks is to help manage the company's network. The network consists of computers that are connected by cables. Each computer is assigned a unique integer identifier and the connections between them are bidirectional. The network is config...
from collections import deque, defaultdict def bfs(node, graph): visited = set() queue = deque([(node, 0)]) visited.add(node) farthest_node = node max_distance = 0 while queue: current_node, distance = queue.popleft() if distance > max_distance: max_dis...
def test_find_tree_diameter(): connections = [ (1, 2), (1, 3), (3, 4), (3, 5) ] n = 5 assert find_tree_diameter(n, connections) == 3 def test_smallest_tree(): connections = [ (1, 2) ] n = 2 assert find_tree_diameter(n, connections) == 1 def test_...
[ { "docstring": null, "function_declaration": "def bfs(node, graph):", "function_name": "bfs", "parameter_list": "(node, graph)" }, { "docstring": null, "function_declaration": "def find_tree_diameter(n, connections):", "function_name": "find_tree_diameter", "parameter_list": "(n,...
[ 1, 0, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "from collections import deque, defaultdict\n\ndef bfs(node, graph):\n visited = set()\n queue = deque([(node, 0)])\n visited.add(node)\n farthest_...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00024804", "row_id": 24804, "seed_ids": "[330, 3476, 5084]" }
0.656758
Codeforces_24804
I
[ "bfs", "find_tree_diameter" ]
2
[ [ "find_tree_diameter", "bfs" ] ]
1
[]
false
[]
false
pytest
false
[]
true
1cfaae23d03e867f327f49ee0f4d8f277cdf5fdf
30c8b3527128a64d02cf13431fb7a0efcefb1b3e
v1.0
instruct
Codeforces
Codeforces_24819_I
Bob is a big fan of binary trees. Recently, he has been working on finding a special property in binary trees. A binary tree is defined as a tree where each node has at most two children, referred to as the left child and the right child. Bob is particularly interested in balanced binary trees. A balanced binary tree ...
class TreeNode: def __init__(self, value=0, left=None, right=None): self.value = value self.left = left self.right = right def sorted_array_to_bst(nums): if not nums: return None mid = len(nums) // 2 root = TreeNode(nums[mid]) root.left = sorted_array_to_bst(num...
from solution import construct_balanced_bst_and_inorder_traversal, process_input def test_example_case(): assert process_input(7, [4, 2, 7, 1, 3, 6, 9]) == [1, 2, 3, 4, 6, 7, 9] def test_single_element(): assert process_input(1, [5]) == [5] def test_two_elements(): assert process_input(2, [5, 3]) == [3, ...
[]
[ 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 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 so...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00024819", "row_id": 24819, "seed_ids": "[3855, 5028, 850]" }
0.691107
Codeforces_24819
I
[ "sorted_array_to_bst", "inorder_traversal", "construct_balanced_bst_and_inorder_traversal", "process_input" ]
4
[ [ "construct_balanced_bst_and_inorder_traversal", "inorder_traversal" ], [ "construct_balanced_bst_and_inorder_traversal", "sorted_array_to_bst" ], [ "process_input", "construct_balanced_bst_and_inorder_traversal" ] ]
3
[ "process_input" ]
false
[ "TreeNode" ]
true
pytest
true
[]
true
2d549ed4ba4329685146fc82709deb9b7b349539
0900a5e27608fcbb5a0a5a82e288670b78462bd3
v1.0
instruct
Codeforces
Codeforces_24891_I
A square matrix of integers is called "beautiful" if all rows and all columns are palindromes. A palindrome is a sequence of characters which reads the same backward as forward. You are given a square matrix of integers. Your task is to determine whether the given matrix is beautiful or not. The first line contains...
def is_palindrome(seq): return seq == seq[::-1] def is_beautiful(m): n = len(m) for i in range(n): if not is_palindrome(m[i]): return "NO" for j in range(n): col = [m[i][j] for i in range(n)] if not is_palindrome(col): return "NO" return "YES" def ma...
from solution import matrix_beautiful def test_beautiful_matrix_3x3(): matrix = [ [1, 2, 1], [2, 3, 2], [1, 2, 1] ] assert matrix_beautiful(3, matrix) == "YES" def test_non_beautiful_matrix_3x3(): matrix = [ [1, 2, 3], [4, 5, 6], [7, 8, 9] ] asse...
[ { "docstring": null, "function_declaration": "def is_palindrome(seq):", "function_name": "is_palindrome", "parameter_list": "(seq)" }, { "docstring": null, "function_declaration": "def is_beautiful(m):", "function_name": "is_beautiful", "parameter_list": "(m)" }, { "docst...
[ 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 is_beautiful_matrix(matrix):\n \"\"\"\n This function checks if a given square matrix is 'beautiful'.\n A matrix is considered beautiful if all r...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00024891", "row_id": 24891, "seed_ids": "[2361, 2057, 6654]" }
0.623786
Codeforces_24891
I
[ "is_palindrome", "is_beautiful", "matrix_beautiful" ]
3
[ [ "is_beautiful", "is_palindrome" ], [ "matrix_beautiful", "is_beautiful" ] ]
2
[]
false
[]
false
pytest
true
[]
true
c100ee8802671fff876df0269cd8f96714fa56f0
5f4a3f5983d2d9f50eecec976554a4bf41b31fe3
v1.0
instruct
Codeforces
Codeforces_24899_I
You are given a list of strings, each string contains a series of characters. Your task is to determine if any string in the list can be transformed into a palindrome by rearranging its characters. If at least one such string exists, print "YES" and the string, otherwise print "NO". A string can be rearranged into a...
def can_form_palindrome(s): from collections import Counter count = Counter(s) odd_count = sum(1 for freq in count.values() if freq % 2 != 0) return odd_count <= 1 def palindrome_check(n, strings): for s in strings: if can_form_palindrome(s): return f"YES\n{s}" return "NO"
from solution import can_form_palindrome, palindrome_check def test_can_form_palindrome_single_letter(): assert can_form_palindrome("a") == True def test_can_form_palindrome_even_frequency(): assert can_form_palindrome("aabbcc") == True def test_can_form_palindrome_odd_frequency(): assert can_form_palind...
[ { "docstring": null, "function_declaration": "def can_form_palindrome(s):", "function_name": "can_form_palindrome", "parameter_list": "(s)" }, { "docstring": null, "function_declaration": "def palindrome_check(n, strings):", "function_name": "palindrome_check", "parameter_list": ...
[ 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 can_form_palindrome(strings):\n def is_palindrome_permutation(s):\n # Count frequency of each character\n frequency = {}\n for cha...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00024899", "row_id": 24899, "seed_ids": "[1802, 5244, 4358]" }
0.846764
Codeforces_24899
I
[ "can_form_palindrome", "palindrome_check" ]
2
[ [ "palindrome_check", "can_form_palindrome" ] ]
1
[]
false
[]
false
pytest
true
[]
true
3555d9fb9cd1ab7251ccdef6ab7883679b1cf631
ebbcb7b718c2eeb9995389b940a45fa6f80db83f
v1.0
instruct
Codeforces
Codeforces_24917_I
A programming contest is taking place, and the participants are given a special type of problem involving trees. They are presented with a tree (a connected acyclic graph) with weighted edges. Each node of the tree can have at most one special property: being either "active" or "inactive." A transformation from the in...
def dfs(node, parent, tree, active, costs): """ Depth First Search to calculate the minimum cost to transform all active nodes to inactive. Parameters: - node (int): The current node - parent (int): The parent node of the current node - tree (list): Adjacency list of the tree [(destination, wei...
from solution import minimum_transformation_cost def test_simple_case(): n = 5 active = [0, 1, 0, 1, 1, 0] # Including a dummy 0 at index 0 for 1-based indexing edges = [(1, 2, 3), (1, 3, 2), (3, 4, 4), (3, 5, 1)] assert minimum_transformation_cost(n, active, edges) == 6 def test_all_active(): n =...
[ { "docstring": "Depth First Search to calculate the minimum cost to transform all active nodes to inactive.\n\nParameters:\n- node (int): The current node\n- parent (int): The parent node of the current node\n- tree (list): Adjacency list of the tree [(destination, weight)]\n- active (list): List indicating if ...
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "from collections import defaultdict\nimport heapq\n\ndef min_transformation_cost(n, activations, edges):\n def dfs(node, parent):\n min_cost = 0\n ...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00024917", "row_id": 24917, "seed_ids": "[4712, 4687, 7672]" }
0.700989
Codeforces_24917
I
[ "dfs", "minimum_transformation_cost" ]
2
[ [ "minimum_transformation_cost", "dfs" ] ]
1
[]
false
[]
false
pytest
true
[]
true
f2ec895d3668de30a12bf6d52caf89b1db9e187f
76a8d5e804a4086bcc978d5a1673de4b32be1904
v1.0
instruct
Codeforces
Codeforces_24930_I
A farmer has a rectangular field represented by an n x m grid. Each cell in the grid contains either a 0 or a 1, where 0 represents an empty cell, and 1 represents a cell with a crop. To make the field more efficient, the farmer wants to count the number of connected components of crops (i.e., clusters of adjacent 1's)...
def count_clusters(field, n, m): def dfs(x, y): if x < 0 or x >= n or y < 0 or y >= m or field[x][y] == '0': return field[x][y] = '0' dfs(x + 1, y) dfs(x - 1, y) dfs(x, y + 1) dfs(x, y - 1) cluster_count = 0 for i in range(n): for j i...
from solution import solve def test_solve_example_case(): input_str = "4 5\n11000\n11011\n00101\n00001" assert solve(input_str) == 3 def test_solve_single_cell_crop(): input_str = "1 1\n1" assert solve(input_str) == 1 def test_solve_single_cell_no_crop(): input_str = "1 1\n0" assert solve(inp...
[ { "docstring": null, "function_declaration": "def count_clusters(field, n, m):", "function_name": "count_clusters", "parameter_list": "(field, n, m)" }, { "docstring": null, "function_declaration": "def parse_input(input_str):", "function_name": "parse_input", "parameter_list": "...
[ 0, 0, 0, 0, 0, 0, 0, 0, 1, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def count_crops_clusters(n, m, field):\n \"\"\"\n Returns the number of connected clusters of crops in the field.\n \"\"\"\n def dfs(i, j):\n ...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00024930", "row_id": 24930, "seed_ids": "[2342, 3937, 1934]" }
0.612585
Codeforces_24930
I
[ "count_clusters", "parse_input", "solve" ]
3
[ [ "solve", "count_clusters" ], [ "solve", "parse_input" ] ]
2
[ "parse_input" ]
false
[]
false
pytest
true
[]
true
c6aae75ddba410e1b4fc4ebacb1b95514f794a4b
35dfc8b2694b071cb0553cf8c189e5e82ee888ed
v1.0
instruct
Codeforces
Codeforces_24934_I
There is an island with n cities and m roads connecting them. Each road has a certain travel time associated with it. The government wants to build a new telecommunication network such that every city can communicate with each other. They aim to minimize the total cost of building this network. However, the government ...
def find(parent, i): if parent[i] == i: return i else: return find(parent, parent[i]) def union(parent, rank, x, y): root_x = find(parent, x) root_y = find(parent, y) if root_x != root_y: if rank[root_x] < rank[root_y]: parent[root_x] = root_y elif r...
def test_kruskal_example_case(): n = 4 edges = [ (1, 2, 1), (1, 3, 4), (1, 4, 3), (2, 3, 3), (3, 4, 2) ] assert kruskal(n, edges) == 6 def test_kruskal_disconnected_graph(): n = 4 edges = [ (1, 2, 1), (3, 4, 2) ] assert krus...
[ { "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": "# We'll use Kruskal's Algorithm to find the minimum spanning tree (MST)\n# It ensures the minimum cost to connect all nodes in a graph\n\ndef find(parent, i):...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00024934", "row_id": 24934, "seed_ids": "[1213, 2644, 1735]" }
0.758607
Codeforces_24934
I
[ "find", "union", "kruskal" ]
3
[ [ "kruskal", "find" ], [ "kruskal", "union" ], [ "union", "find" ] ]
3
[]
false
[]
false
pytest
false
[]
true
7aeb0d4c93ad237cdc15bfe7ab5853a24a2ab16f
a71dbb2be4021612eb52f5fd8996a4018b0bf27a
v1.0
instruct
Codeforces
Codeforces_24947_I
Given an integer array nums containing n distinct numbers, you need to determine if there exists a subset of nums such that the sum of the elements in the subset is equal to a given target sum t. If such a subset exists, output the subset; otherwise, output "No solution". The first line of the input contains two integ...
def subset_sum(nums, t): """ Determine if there exists a subset of nums that sums to t. If such a subset exists, return it as a list. Otherwise, return "No solution". """ n = len(nums) dp = {0: []} # Initial state with zero sum having an empty subset for num in nums: current_dp = l...
def test_subset_sum(): assert subset_sum([2, 4, 6, 8, 10], 10) in [[2, 8], [4, 6], [10]] assert subset_sum([1, 2, 3, 4, 5], 9) in [[4, 5], [1, 3, 5], [2, 3, 4]] assert subset_sum([1, 2, 3, 4], 15) == "No solution" assert subset_sum([3, 34, 4, 12, 5, 2], 9) in [[4, 5], [2, 3, 4]] assert subset_sum([-...
[ { "docstring": "Determine if there exists a subset of nums that sums to t.\nIf such a subset exists, return it as a list. Otherwise, return \"No solution\".", "function_declaration": "def subset_sum(nums, t):", "function_name": "subset_sum", "parameter_list": "(nums, t)" }, { "docstring": nu...
[ 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_subset_with_sum(n, t, nums):\n \"\"\"\n Finds a subset of nums that sums up to t.\n \n Args:\n n (int): The number of elements in the ...
trial_gpt4o_3
{ "original_instruction": "", "prompt_id": "00024947", "row_id": 24947, "seed_ids": "[1424, 6565, 3087]" }
0.677869
Codeforces_24947
I
[ "subset_sum", "parse_and_run" ]
2
[ [ "parse_and_run", "subset_sum" ] ]
1
[]
false
[]
false
pytest
false
[]
true
720f8c90be4c5142e1ab87d3be17fae7eb3cfca8
a049b70cdc83e169bc1caec0f97ff337cfcd83cc
v1.0
instruct
Codeforces
Codeforces_24969_I
Farmer John has a rectangular barn with dimensions n by m. He wants to place his cows in the barn such that no two cows can see each other. The barn consists of rows and columns of cells, where each cell can either be empty (.) or contain an obstacle (x) that blocks the line of sight. A cow placed in cell (i, j) can se...
def max_cows_placement(n, m, barn): from itertools import product def can_place(barn, placed, i, j): for k in range(i): if barn[k][j] == '.' and placed[k][j] == 'C': return False for l in range(j): if barn[i][l] == '.' and placed[i][l] == 'C': ...
from solution import max_cows_placement def test_case_1(): n = 5 m = 5 barn = [ ".....", "..x..", ".....", ".x...", "....x" ] assert max_cows_placement(n, m, barn) == 5 def test_case_2(): n = 3 m = 3 barn = [ "...", ".x.", ...
[ { "docstring": null, "function_declaration": "def max_cows_placement(n, m, barn):", "function_name": "max_cows_placement", "parameter_list": "(n, m, barn)" }, { "docstring": null, "function_declaration": "def solve():", "function_name": "solve", "parameter_list": "()" }, { ...
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def max_cows_in_barn(n, m, barn):\n \"\"\"\n Given the dimensions of the barn and its layout, returns the maximum\n number of cows that can be placed...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00024969", "row_id": 24969, "seed_ids": "[6545, 4774, 5394]" }
0.616691
Codeforces_24969
I
[ "max_cows_placement", "solve" ]
2
[ [ "solve", "max_cows_placement" ] ]
1
[]
false
[]
false
pytest
true
[]
true
6b75cf6dfcabc11291d07971a482321eec07ab63
fed4691d98f13176ae93d48f9fb3c2606b8e8853
v1.0
instruct
Codeforces
Codeforces_24996_I
Given a tree with `n` vertices, each vertex has a certain value associated with it. A path in the tree is called a "special path" if the greatest common divisor (GCD) of all the values of the vertices on the path is greater than 1. You are required to find the longest "special path" in the tree. The first line conta...
from math import gcd from collections import defaultdict, deque def longest_special_path(n, vertex_values, edges): def bfs(start): queue = deque([(start, vertex_values[start - 1])]) visited = {start} parent = [-1] * (n + 1) distance = [0] * (n + 1) while queue: ...
from solution import find_longest_special_path def test_example_case(): n = 6 vertex_values = [2, 4, 6, 3, 9, 15] edges = [(1, 2), (1, 3), (2, 4), (3, 5), (3, 6)] assert find_longest_special_path(n, vertex_values, edges) == 2 def test_single_node(): n = 1 vertex_values = [2] edges = [] ...
[ { "docstring": null, "function_declaration": "def longest_special_path(n, vertex_values, edges):", "function_name": "longest_special_path", "parameter_list": "(n, vertex_values, edges)" }, { "docstring": "Given a tree with n vertices and their associated values, \nreturns the length of the l...
[ 0, 0, 0, 1, 1 ]
2
medium
0.4
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "import math\nfrom collections import defaultdict\n\ndef longest_special_path(n, values, edges):\n \"\"\"\n Given the number of vertices `n`, associated ...
trial_gpt4o_4
{ "original_instruction": "", "prompt_id": "00024996", "row_id": 24996, "seed_ids": "[4952, 8206, 2713]" }
0.648109
Codeforces_24996
I
[ "longest_special_path", "find_longest_special_path" ]
2
[ [ "find_longest_special_path", "longest_special_path" ] ]
1
[]
false
[]
false
pytest
true
[]
true
182f0754e20cd29ef04b3be1e0b23e63fb5ccfe0
b7d686a70b7a7206acaf64909c0cbb56ff743e81
v1.0
instruct
Codeforces
Codeforces_25039_I
A group of robotic vehicles are navigating a grid to perform certain tasks. Each robot moves within an n × m grid and can navigate using the following moves: - 'U' (move up) - 'D' (move down) - 'L' (move left) - 'R' (move right) Due to power consumption constraints, each robot has a limited range d, which defines the ...
def can_reach_target(grid, n, m, tx, ty, sx, sy, d): from collections import deque # Directions for 'U', 'D', 'L', 'R' directions = [(-1, 0), (1, 0), (0, -1), (0, 1)] # BFS initialization queue = deque([(sx, sy, 0)]) # (row, col, distance) visited = set((sx, sy)) while queue: x, ...
def test_num_robots_to_target_example(): grid = [ ".....", ".#...", ".#...", ".#...", "....." ] tx, ty = 5, 5 robots = [(1, 1, 10), (2, 2, 3), (3, 5, 2)] assert num_robots_to_target(5, 5, grid, tx, ty, robots) == 2 def test_num_robots_to_target_single_robot_r...
[ { "docstring": null, "function_declaration": "def can_reach_target(grid, n, m, tx, ty, sx, sy, d):", "function_name": "can_reach_target", "parameter_list": "(grid, n, m, tx, ty, sx, sy, d)" }, { "docstring": null, "function_declaration": "def num_robots_to_target(n, m, grid, tx, ty, robo...
[ 0, 0, 1 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "from collections import deque\n\ndef can_reach_target(grid, start_x, start_y, target_x, target_y, max_steps):\n n = len(grid)\n m = len(grid[0])\n di...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00025039", "row_id": 25039, "seed_ids": "[2335, 1892, 217]" }
0.715512
Codeforces_25039
I
[ "can_reach_target", "num_robots_to_target" ]
2
[ [ "num_robots_to_target", "can_reach_target" ] ]
1
[]
false
[]
false
pytest
false
[]
true
5468da896147c3a113bf0adc4c0d52b98bca6985
b293b40da942e6097550167c7f7882748f339208
v1.0
instruct
Codeforces
Codeforces_25072_I
Nina is fascinated with numbers and their properties. One day, she discovered an interesting function f(x) that is defined for a positive integer x in the following manner: 1. If x is a prime number, then f(x) = 1. 2. If x is a composite number, then f(x) is the smallest prime number that divides x. Nina wants to app...
def is_prime(x): if x <= 1: return False if x <= 3: return True if x % 2 == 0 or x % 3 == 0: return False i = 5 while i * i <= x: if x % i == 0 or x % (i + 2) == 0: return False i += 6 return True def smallest_prime_divisor(x): if is_prime...
from solution import nina_numbers def test_single_prime_number(): assert nina_numbers(1, [7]) == 1 def test_single_composite_number(): assert nina_numbers(1, [6]) == 2 def test_mixed_numbers(): assert nina_numbers(3, [6, 7, 15]) == 6 # f(6)=2, f(7)=1, f(15)=3 -> 2*1*3=6 def test_multiple_primes(): ...
[ { "docstring": null, "function_declaration": "def is_prime(x):", "function_name": "is_prime", "parameter_list": "(x)" }, { "docstring": null, "function_declaration": "def smallest_prime_divisor(x):", "function_name": "smallest_prime_divisor", "parameter_list": "(x)" }, { ...
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def smallest_prime_factor(x):\n \"\"\"\n Returns the smallest prime factor of x. If x is prime, returns 1.\n \"\"\"\n if x <= 1:\n return 1...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00025072", "row_id": 25072, "seed_ids": "[2173, 4714, 7174]" }
0.661569
Codeforces_25072
I
[ "is_prime", "smallest_prime_divisor", "compute_product_modulo", "nina_numbers" ]
4
[ [ "compute_product_modulo", "smallest_prime_divisor" ], [ "nina_numbers", "compute_product_modulo" ], [ "smallest_prime_divisor", "is_prime" ] ]
3
[]
false
[]
false
pytest
true
[]
true
a526ad33ae613514915c33637cfdfe3e70fe2d19
054602e1219e83d296a6b07f453c45a908c14ff4
v1.0
instruct
Codeforces
Codeforces_25118_I
Maria loves art and she wants to fill a grid of size n × m with colors. She uses k different colors for this purpose. Each cell of the grid should contain exactly one color. Maria’s artistic sense tells her that she should fill the grid in such a way that no two adjacent cells (horizontally, vertically, or diagonally) ...
def is_fill_possible(n, m, k): """ Determines whether it is possible to fill a grid of size n x m with k colors such that no two adjacent cells (horizontally, vertically, or diagonally) have the same color. Returns a tuple (is_possible, grid) where is_possible is a boolean indicating if it's po...
from solution import fill_grid def test_fill_grid_possible(): result = fill_grid(3, 3, 3) assert result[0] == "YES" def test_fill_grid_impossible(): result = fill_grid(2, 2, 1) assert result == ["NO"] def test_fill_grid_size_1x1(): result = fill_grid(1, 1, 1) assert result == ["YES", "A"] de...
[ { "docstring": "Determines whether it is possible to fill a grid of size n x m with k colors\nsuch that no two adjacent cells (horizontally, vertically, or diagonally)\nhave the same color.\n\nReturns a tuple (is_possible, grid) where is_possible is a boolean indicating\nif it's possible to fill the grid and gr...
[ 0, 0, 0, 0, 0, 1, 1, 0, 0, 0 ]
2
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def fill_grid(n, m, k):\n \"\"\"\n Function to determine if the grid can be filled according to the rules\n and provide one such arrangement if possi...
trial_gpt4o_6
{ "original_instruction": "", "prompt_id": "00025118", "row_id": 25118, "seed_ids": "[1573, 1901, 3865]" }
0.766831
Codeforces_25118
I
[ "is_fill_possible", "fill_grid" ]
2
[ [ "fill_grid", "is_fill_possible" ] ]
1
[]
false
[]
false
pytest
true
[]
true
e2ec01fb57d25de552b781b6b9e4420e0dcbe3e0
74c99a04d34d4ef34f1e3b9f94ebc02c8bb054f8
v1.0
instruct
Codeforces
Codeforces_25149_I
Lara loves binary numbers and has a special interest in finding patterns in them. She is currently fascinated with binary palindromes. A binary palindrome is a number that reads the same backward as forward when written in binary. She wants to find the smallest binary palindrome that is greater than or equal to a give...
def is_binary_palindrome(num): binary_rep = bin(num)[2:] return binary_rep == binary_rep[::-1] def smallest_binary_palindrome(n): while True: if is_binary_palindrome(n): return n n += 1
from solution import is_binary_palindrome, smallest_binary_palindrome def test_is_binary_palindrome(): assert is_binary_palindrome(1) == True assert is_binary_palindrome(9) == True assert is_binary_palindrome(21) == True assert is_binary_palindrome(22) == False assert is_binary_palindrome(33) == Tr...
[ { "docstring": null, "function_declaration": "def is_binary_palindrome(num):", "function_name": "is_binary_palindrome", "parameter_list": "(num)" }, { "docstring": null, "function_declaration": "def smallest_binary_palindrome(n):", "function_name": "smallest_binary_palindrome", "...
[ 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_binary_palindrome(n):\n \"\"\"\n Check if the binary representation of n is a palindrome.\n \"\"\"\n binary_n = bin(n)[2:] # Get binary re...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00025149", "row_id": 25149, "seed_ids": "[886, 5102, 4507]" }
0.71531
Codeforces_25149
I
[ "is_binary_palindrome", "smallest_binary_palindrome" ]
2
[ [ "smallest_binary_palindrome", "is_binary_palindrome" ] ]
1
[]
false
[]
false
pytest
true
[]
true
b505e2f188ae628056415b5712bc1828c2a8d6dd
f8610cd9a300d40288cb07407670dae6d45736fc
v1.0
instruct
Codeforces
Codeforces_25151_I
In a kingdom, there are $$n$$ cities connected by $$n - 1$$ roads. The kingdom is structured in such a way that there is exactly one path between any pair of cities, making the structure a tree. The king has decided to establish a new capital for the kingdom. To minimize the travel time for all his subjects, he wants ...
from collections import deque def bfs(farthest_node, graph, n): """ Perform BFS and find the farthest node with its distance from a given node. """ dist = [-1] * (n + 1) queue = deque([farthest_node]) dist[farthest_node] = 0 max_dist = 0 node = farthest_node while queue: ...
def read_sample_input(): return "2\n4\n1 2\n1 3\n3 4\n4\n1 2\n1 3\n2 4\n" def test_case_1(): assert solve([(4, [(1, 2), (1, 3), (3, 4)])]) == [3] def test_case_2(): assert solve([(4, [(1, 2), (1, 3), (2, 4)])]) == [2] def test_case_3(): assert solve([(1, [])]) == [1] # Single city case def test_cas...
[ { "docstring": "Perform BFS and find the farthest node with its distance from a given node.", "function_declaration": "def bfs(farthest_node, graph, n):", "function_name": "bfs", "parameter_list": "(farthest_node, graph, n)" }, { "docstring": "Find the optimal city to be the capital by minim...
[ 0, 1, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "from collections import deque, defaultdict\nimport sys\n\ndef find_furthest_city(start, n, graph):\n \"\"\"Finds the furthest city and its distance from th...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00025151", "row_id": 25151, "seed_ids": "[3604, 3838, 3460]" }
0.738382
Codeforces_25151
I
[ "bfs", "find_optimal_city", "solve", "main" ]
4
[ [ "find_optimal_city", "bfs" ], [ "solve", "find_optimal_city" ] ]
2
[]
false
[]
false
pytest
false
[]
true
221ec81d6c90f8a5cad83351802aa1fbbb3062e2
59ccdbae88b91cae0ea1251aecb9a76e5e3dee64
v1.0
instruct
Codeforces
Codeforces_25158_I
Masha is organizing a marathon event, and she has received registration from n participants. Each participant has a unique registration number and an estimated running time (in minutes) to complete the marathon. Masha wants to distribute the participants into groups such that the total estimated running time of partici...
def can_divide_in_k_groups_with_max_sum(max_sum, times, k): current_sum = 0 group_count = 1 for time in times: if current_sum + time > max_sum: group_count += 1 current_sum = time if group_count > k: return False else: current_s...
from solution import minimum_maximum_running_time def test_case_1(): n, k = 5, 3 times = [10, 20, 30, 40, 50] assert minimum_maximum_running_time(n, k, times) == 60 def test_case_2(): n, k = 5, 2 times = [10, 20, 30, 40, 50] assert minimum_maximum_running_time(n, k, times) == 90 def test_case...
[ { "docstring": null, "function_declaration": "def can_divide_in_k_groups_with_max_sum(max_sum, times, k):", "function_name": "can_divide_in_k_groups_with_max_sum", "parameter_list": "(max_sum, times, k)" }, { "docstring": null, "function_declaration": "def minimum_maximum_running_time(n,...
[ 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 minimize_maximum_total_time(n, k, times):\n def can_distribute_with_max_time(max_time):\n groups = 1\n current_sum = 0\n \n ...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00025158", "row_id": 25158, "seed_ids": "[6142, 1373, 5783]" }
0.648269
Codeforces_25158
I
[ "can_divide_in_k_groups_with_max_sum", "minimum_maximum_running_time" ]
2
[ [ "minimum_maximum_running_time", "can_divide_in_k_groups_with_max_sum" ] ]
1
[]
false
[]
false
pytest
true
[]
true
d1982d95741077f09d4bf9da5f7f5efea9f3dc0b
2be1323523aa7659787d328262c5c59e18c0702b
v1.0
instruct
Codeforces
Codeforces_25168_I
Suppose there are n cities connected by m bidirectional roads. Each road has a certain importance specified by an integer, and a specific road can be used only once while calculating the importance. The importance of path refers to the sum of importances of the roads in that path. Your task is to find the length of th...
import heapq def dijkstra(graph, source, n): """ Performs the Dijkstra algorithm to find the shortest path from the source to all other nodes. Returns the distances dictionary. """ distances = {node: float('inf') for node in range(1, n + 1)} distances[source] = 0 priority_queue = [(0, sourc...
def test_shortest_and_highest_importance(): n = 5 m = 6 roads = [ (1, 2, 2), (1, 3, 3), (2, 4, 2), (2, 3, 1), (3, 4, 4), (4, 5, 3) ] A = 1 B = 5 assert find_path_stats(n, m, roads, A, B) == (7, 10) def test_no_path(): n = 4 m = 2 r...
[ { "docstring": "Performs the Dijkstra algorithm to find the shortest path from the source to all other nodes.\nReturns the distances dictionary.", "function_declaration": "def dijkstra(graph, source, n):", "function_name": "dijkstra", "parameter_list": "(graph, source, n)" }, { "docstring": ...
[ 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\nfrom collections import defaultdict, deque\n\ndef shortest_and_highest_paths(n, m, roads, A, B):\n def dijkstra(graph, start, end):\n ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00025168", "row_id": 25168, "seed_ids": "[7350, 3545, 5317]" }
0.746831
Codeforces_25168
I
[ "dijkstra", "find_highest_importance", "dfs", "find_path_stats", "main" ]
5
[ [ "find_highest_importance", "dfs" ], [ "find_path_stats", "dijkstra" ], [ "find_path_stats", "find_highest_importance" ] ]
3
[]
false
[]
false
pytest
false
[]
true
3ae3b95eec9c0c0af05b5b18e7b7058a77d01569
b9ef826ed9b6247e587b8a3b9cc0f307b8a6b1d3
v1.0
instruct
Codeforces
Codeforces_25193_I
A technique called "Sort and Merge" helps in merging overlapping intervals in a list. Given a list of intervals where each interval is represented by a pair of integers [start, end], your task is to merge all overlapping intervals and return the list of merged intervals in ascending order of their start times. Two int...
def merge_intervals(intervals): """ Merges overlapping intervals and returns the merged list of intervals. :param intervals: List of tuples/lists where each tuple/list has two integers [start, end] :return: List of merged intervals as lists """ if not intervals: return [] #...
import pytest from solution import merge_intervals, merge_intervals_from_input def test_merge_intervals(): assert merge_intervals([[1, 3], [2, 6], [8, 10], [15, 18]]) == [[1, 6], [8, 10], [15, 18]] assert merge_intervals([[1, 4], [4, 5]]) == [[1, 5]] assert merge_intervals([[1, 4], [0, 2], [3, 5]]) == [[0,...
[ { "docstring": "Merges overlapping intervals and returns the merged list of intervals.\n\n:param intervals: List of tuples/lists where each tuple/list has two integers [start, end]\n:return: List of merged intervals as lists", "function_declaration": "def merge_intervals(intervals):", "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 merge_intervals(intervals):\n \"\"\"\n Merges overlapping intervals and returns the list of merged intervals in ascending order of their start times...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00025193", "row_id": 25193, "seed_ids": "[3605, 4891, 8064]" }
0.682019
Codeforces_25193
I
[ "merge_intervals", "merge_intervals_from_input" ]
2
[ [ "merge_intervals_from_input", "merge_intervals" ] ]
1
[]
false
[]
false
pytest
true
[]
true
583359b9ad9df2fae285ee03477e47d6f86282cd
d01eac7d31dce6b3b443ee5ee3095041f969980b
v1.0
instruct
Codeforces
Codeforces_25202_I
In a binary tree, each node contains an integer value, and each node has at most two children. You need to determine the size of the maximum independent set (MIS). An independent set is a set of nodes such that no two nodes in the set are direct parent-child. The input consists of multiple test cases. The first line o...
class TreeNode: def __init__(self, value): self.value = value self.children = [] def build_tree(edges, n): nodes = {i: TreeNode(i) for i in range(1, n + 1)} for u, v in edges: nodes[u].children.append(nodes[v]) nodes[v].children.append(nodes[u]) return nodes[1] ...
from solution import solve def test_case_1(): test_cases = [(5, [(1, 2), (1, 3), (2, 4), (2, 5)])] assert solve(test_cases) == [3] def test_case_2(): test_cases = [(6, [(1, 2), (1, 3), (3, 4), (3, 5), (4, 6)])] assert solve(test_cases) == [3] def test_case_3(): test_cases = [(7, [(1, 2), (2, 3), ...
[]
[ 0, 1 ]
1
medium
0.5
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "class Node:\n def __init__(self, value):\n self.value = value\n self.children = []\n\ndef mis(node, parent, dp):\n if node is None:\n ...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00025202", "row_id": 25202, "seed_ids": "[1119, 8173, 711]" }
0.595175
Codeforces_25202
I
[ "build_tree", "mis", "find_mis", "solve" ]
4
[ [ "find_mis", "mis" ], [ "solve", "build_tree" ], [ "solve", "find_mis" ] ]
3
[]
false
[ "TreeNode" ]
true
pytest
true
[]
true
850dd48445181fdd75d1fcc83eee7f66920160ed
e54cebf07d01f42232a70bd793ec5953daa35548
v1.0
instruct
Codeforces
Codeforces_25203_I
You are given an integer array representing the heights of buildings in a row. You are also given the number of rain units that fall on these buildings. When it rains on consecutive buildings with varying heights, the rainwater gets trapped between the buildings. Your task is to compute the total amount of trapped rain...
def compute_trapped_rainwater(building_heights): """ Computes the total amount of trapped rainwater between buildings. Parameters: - building_heights (list): A list of integers representing the heights of the buildings. Returns: - int: The total units of rainwater that can be trapped. ...
from solution import compute_trapped_rainwater, trapped_rainwater def test_compute_trapped_rainwater_basic(): assert compute_trapped_rainwater([0, 1, 0, 2, 1, 0, 1, 3, 2, 1, 2, 1]) == 6 def test_compute_trapped_rainwater_no_buildings(): assert compute_trapped_rainwater([]) == 0 def test_compute_trapped_rainw...
[ { "docstring": "Computes the total amount of trapped rainwater between buildings.\n\nParameters:\n- building_heights (list): A list of integers representing the heights of the buildings.\n\nReturns:\n- int: The total units of rainwater that can be trapped.", "function_declaration": "def compute_trapped_rain...
[ 0, 0, 0, 0, 0, 1, 1, 0, 0, 0 ]
2
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def trap_rainwater(n, r, heights):\n if n == 0:\n return 0\n \n total_water = 0\n left, right = 0, n - 1\n left_max, right_max = heights...
trial_gpt4o_6
{ "original_instruction": "", "prompt_id": "00025203", "row_id": 25203, "seed_ids": "[7601, 228, 6694]" }
0.65037
Codeforces_25203
I
[ "compute_trapped_rainwater", "trapped_rainwater" ]
2
[ [ "trapped_rainwater", "compute_trapped_rainwater" ] ]
1
[]
false
[]
false
pytest
true
[]
true
24ae3378db2d1232537750026252e838f55f1752
a0d63df08d0acd12ca7b924bad0f4722b9d81a7a
v1.0
instruct
Codeforces
Codeforces_25306_I
In a hypothetical kingdom, there are "n" towns (numbered 1 through n) and "m" direct roads connecting some pairs of different towns. Each road is bidirectional and has an associated travel time. The kingdom's king wants to build a high-speed railway system that connects all towns with the minimum total travel time with...
def find(parent, i): if parent[i] == i: return i else: parent[i] = find(parent, parent[i]) # path compression return 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 ...
from solution import minimum_travel_time def test_example1(): n = 4 m = 4 roads = [ (1, 2, 1), (2, 3, 2), (3, 4, 3), (4, 1, 4) ] assert minimum_travel_time(n, m, roads) == 6 def test_example2(): n = 4 m = 2 roads = [ (1, 2, 1), (3, 4, 1) ...
[ { "docstring": null, "function_declaration": "def find(parent, i):", "function_name": "find", "parameter_list": "(parent, i)" }, { "docstring": null, "function_declaration": "def union(parent, rank, x, y):", "function_name": "union", "parameter_list": "(parent, rank, x, y)" }, ...
[ 0, 0, 0, 1 ]
1
hard
0.25
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "class DisjointSet:\n def __init__(self, n):\n self.parent = list(range(n))\n self.rank = [0] * n\n \n def find(self, u):\n if se...
trial_gpt4o_4
{ "original_instruction": "", "prompt_id": "00025306", "row_id": 25306, "seed_ids": "[7693, 315, 1139]" }
0.715227
Codeforces_25306
I
[ "find", "union", "kruskal", "minimum_travel_time" ]
4
[ [ "kruskal", "find" ], [ "kruskal", "union" ], [ "minimum_travel_time", "kruskal" ], [ "union", "find" ] ]
4
[]
false
[]
false
pytest
true
[]
true
2e34d1cd3a06f9c4262b6acdcd2c9218d97e323c
ff5d436a9fe972a9eb07ad03bd0abc6d27ffdbd7
v1.0
instruct
Codeforces
Codeforces_25318_I
Imagine you are playing a game where you need to collect stars. The game is played on a 2D grid with dimensions n x m. Each cell in the grid represents either a blocked cell (designated by '#') or an open cell (designated by '.'). You can move from an open cell to any of the 4 adjacent cells that are also open (up, dow...
from queue import Queue def min_cells_to_collect_stars(grid, n, m): directions = [(0, 1), (1, 0), (0, -1), (-1, 0)] # Create a 3D visited array to mark cells as visited visited = [[[False, False] for _ in range(m)] for _ in range(n)] q = Queue() # Start from the top-left corner with step ...
from solution import game_grid def test_game_grid_possible_path(): input_str = "4 4\n....\n.#..\n..#.\n...." assert game_grid(input_str) == 7 def test_game_grid_no_path(): input_str = "2 2\n.#\n#." assert game_grid(input_str) == -1 def test_game_grid_single_column(): input_str = "3 1\n.\n.\n." ...
[ { "docstring": null, "function_declaration": "def min_cells_to_collect_stars(grid, n, m):", "function_name": "min_cells_to_collect_stars", "parameter_list": "(grid, n, m)" }, { "docstring": null, "function_declaration": "def game_grid(input_str):", "function_name": "game_grid", "...
[ 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": "from collections import deque\n\ndef min_path_stars(grid):\n def is_valid(x, y):\n return 0 <= x < n and 0 <= y < m and grid[x][y] == '.'\n\n n =...
trial_gpt4o_5
{ "original_instruction": "", "prompt_id": "00025318", "row_id": 25318, "seed_ids": "[322, 4163, 5887]" }
0.776801
Codeforces_25318
I
[ "min_cells_to_collect_stars", "game_grid" ]
2
[ [ "game_grid", "min_cells_to_collect_stars" ] ]
1
[]
false
[]
false
pytest
true
[]
true
0d8493774c2b9d993974e20e1fd3b0f3a8e16a82
c242e37a7df3817445f172d420f4ba36f4ca1808
v1.0
instruct
Codeforces
Codeforces_25344_I
You are given a social network consisting of n users and m friendship relations. Each friendship relation is bi-directional. The users can communicate with each other directly if they are friends, otherwise, they need a mediator who can relay messages between them through a series of friendships. Initially, each user ...
class UnionFind: def __init__(self, n): self.parent = list(range(n)) self.rank = [1] * n def find(self, u): if self.parent[u] != u: self.parent[u] = self.find(self.parent[u]) return self.parent[u] def union(self, u, v): root_u = self.find(u) root...
from solution import parse_and_execute def test_communication_simple(): n = 4 m = 2 friendships = [(1, 2), (2, 3)] q = 2 queries = [(1, 3), (1, 4)] assert parse_and_execute(n, m, friendships, q, queries) == ["YES", "NO"] def test_communication_disconnected(): n = 5 m = 3 frien...
[]
[ 1, 1 ]
2
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "class DSU:\n def __init__(self, n):\n self.parent = list(range(n))\n self.rank = [1] * n\n\n def find(self, u):\n if self.parent[u]...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00025344", "row_id": 25344, "seed_ids": "[2913, 3669, 1379]" }
0.708315
Codeforces_25344
I
[ "can_communicate", "parse_and_execute" ]
2
[ [ "parse_and_execute", "can_communicate" ] ]
1
[]
false
[ "UnionFind" ]
true
pytest
true
[]
true
09c9171543f62a0aa2831e2491222f1a8ace4dee
317a89115361090e15d5711574e77fc987ab3e6a
v1.0
instruct
Codeforces
Codeforces_25345_I
You are given an array of integers $$$a$$$ of length $$$n$$$. Your task is to answer $$$q$$$ queries. Each query gives you two integers $$$l$$$ and $$$r$$$ and asks for the sum of the elements in the array between indices $$$l$$$ and $$$r$$$ (inclusive). The first line of the input contains an integer $$$n$$$ ($$$1 \l...
def prefix_sum_array(arr): """ Creates a prefix sum array. """ prefix_sum = [0] * (len(arr) + 1) for i in range(1, len(arr) + 1): prefix_sum[i] = prefix_sum[i-1] + arr[i-1] return prefix_sum def sum_range(prefix_sum, l, r): """ Computes the sum of elements between indices l and ...
def test_prefix_sum_array(): arr = [1, 2, 3, 4, 5] expected = [0, 1, 3, 6, 10, 15] assert prefix_sum_array(arr) == expected def test_sum_range(): prefix_sum = [0, 1, 3, 6, 10, 15] assert sum_range(prefix_sum, 1, 3) == 6 assert sum_range(prefix_sum, 2, 4) == 9 assert sum_range(prefix_sum, 1,...
[ { "docstring": "Creates a prefix sum array.", "function_declaration": "def prefix_sum_array(arr):", "function_name": "prefix_sum_array", "parameter_list": "(arr)" }, { "docstring": "Computes the sum of elements between indices l and r using prefix sums.", "function_declaration": "def sum...
[ 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 range_sum(arr, queries):\n \"\"\"\n For each query (l, r), returns the sum of the elements between indices l and r (inclusive).\n \"\"\"\n # C...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00025345", "row_id": 25345, "seed_ids": "[1662, 3732, 5076]" }
0.689928
Codeforces_25345
I
[ "prefix_sum_array", "sum_range", "process_queries" ]
3
[ [ "process_queries", "prefix_sum_array" ], [ "process_queries", "sum_range" ] ]
2
[ "process_queries" ]
false
[]
false
pytest
true
[]
true
a814c28cc2090636e46440c6434b92f3ed46a96b
4bcbdd4f48ac4620fc753c0274de7c213127d67b
v1.0
instruct
Codeforces
Codeforces_25375_I
Given an undirected graph with unweighted edges, your task is to determine the minimum number of edges to remove in order to make the graph acyclic (i.e., a forest). Input: The first line of the input contains two integers $$$n$$$ and $$$m$$$ ($$$1 \leq n \leq 1000$$$, $$$0 \leq m \leq 2000$$$), where $$$n$$$ is the ...
def find_parent(parent, i): if parent[i] == i: return i else: return find_parent(parent, parent[i]) def union(parent, rank, x, y): x_root = find_parent(parent, x) y_root = find_parent(parent, y) if rank[x_root] < rank[y_root]: parent[x_root] = y_root elif rank[x...
from solution import min_edges_to_remove def test_single_cycle(): assert min_edges_to_remove(4, 4, [(1, 2), (2, 3), (3, 4), (4, 2)]) == 1 def test_no_edges(): assert min_edges_to_remove(5, 0, []) == 0 def test_no_cycles(): assert min_edges_to_remove(4, 3, [(1, 2), (2, 3), (3, 4)]) == 0 def test_multiple...
[ { "docstring": null, "function_declaration": "def find_parent(parent, i):", "function_name": "find_parent", "parameter_list": "(parent, i)" }, { "docstring": null, "function_declaration": "def union(parent, rank, x, y):", "function_name": "union", "parameter_list": "(parent, rank...
[ 0, 0, 0, 1, 1 ]
2
medium
0.4
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def find(parent, i):\n if parent[i] == -1:\n return i\n if parent[i] != -1:\n return find(parent, parent[i])\n\ndef union(parent, x, y):\n...
trial_gpt4o_3
{ "original_instruction": "", "prompt_id": "00025375", "row_id": 25375, "seed_ids": "[7204, 1210, 1235]" }
0.628584
Codeforces_25375
I
[ "find_parent", "union", "min_edges_to_remove" ]
3
[ [ "min_edges_to_remove", "find_parent" ], [ "min_edges_to_remove", "union" ], [ "union", "find_parent" ] ]
3
[]
false
[]
false
pytest
true
[]
true
00e016ebbbe1add5f0ef9d1b35666fe53e8564fe
11eee0b43e54c356be7e2f29ca6715e0bc7fd535
v1.0
instruct
Codeforces
Codeforces_25400_I
Alice is a puzzle enthusiast who loves solving problems involving sequences and patterns. She recently came across a unique number sequence challenge. The sequence follows a simple rule: starting with a number `x`, each subsequent number is the smallest integer that is greater than the previous number and has a digit s...
def digit_sum(n): """ Returns the sum of the digits of n. """ return sum(int(digit) for digit in str(n)) def next_number_with_same_digit_sum(n): """ Returns the smallest integer greater than n that has the same digit sum as n. """ target_digit_sum = digit_sum(n) current_number = n +...
import pytest from solution import get_sequence, digit_sum, next_number_with_same_digit_sum def test_digit_sum(): assert digit_sum(23) == 5 assert digit_sum(123) == 6 assert digit_sum(9999) == 36 assert digit_sum(0) == 0 def test_next_number_with_same_digit_sum(): assert next_number_with_same_digi...
[ { "docstring": "Returns the sum of the digits of n.", "function_declaration": "def digit_sum(n):", "function_name": "digit_sum", "parameter_list": "(n)" }, { "docstring": "Returns the smallest integer greater than n that has the same digit sum as n.", "function_declaration": "def next_nu...
[ 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 digit_sum(number):\n \"\"\"\n Returns the sum of the digits of the number.\n \"\"\"\n return sum(int(digit) for digit in str(number))\n\ndef g...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00025400", "row_id": 25400, "seed_ids": "[4130, 7307, 5268]" }
0.679974
Codeforces_25400
I
[ "digit_sum", "next_number_with_same_digit_sum", "generate_sequence", "get_sequence" ]
4
[ [ "generate_sequence", "next_number_with_same_digit_sum" ], [ "get_sequence", "generate_sequence" ], [ "next_number_with_same_digit_sum", "digit_sum" ] ]
3
[]
false
[]
false
pytest
true
[]
true
1dbd863d109aaa7b29a83bad297d42e9b8442768
9f6a7ea55144d8f86ba79c9d5aae4fc40f4e1939
v1.0
instruct
Codeforces
Codeforces_25421_I
Eva is organizing a charity auction and wants to manage the inventory of donated items. She has a list of item categories, and each item belongs to a specific category. When a donor donates an item, Eva needs to check if the item category already exists in her inventory database. If the category does not exist, she add...
class Inventory: def __init__(self): self.categories = {} def donate(self, category, count): if category in self.categories: self.categories[category] += count else: self.categories[category] = count def query(self, category): return self.categories....
from solution import execute_inventory_operations def test_inventory_operations(): operations = [ "donate books 10", "donate clothes 5", "query books", "donate toys 2", "query clothes", "donate clothes 3", "query clothes" ] assert execute_inventory_op...
[]
[ 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 Inventory:\n def __init__(self):\n self.categories = {}\n\n def donate(self, category, count):\n if category in self.categories:\n ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00025421", "row_id": 25421, "seed_ids": "[6219, 7095, 5587]" }
0.561036
Codeforces_25421
I
[ "manage_inventory", "execute_inventory_operations" ]
2
[ [ "execute_inventory_operations", "manage_inventory" ] ]
1
[]
false
[ "Inventory" ]
true
pytest
true
[]
true
51cb3cb3a2c43f01fdf04ec3ac8f5fa8ceb918ea
218cef31b1fc591ddc12ec8e61d846ac6e552eb5
v1.0
instruct
Codeforces
Codeforces_25434_I
Polycarp participated in a programming competition and received a strange problem. He was given a directed graph and needed to find whether it contains any cycles. A directed graph is a graph in which the edges have a direction, going from one vertex to another. Polycarp has written down all the vertices and edges of ...
def contains_cycle(n, m, edges): from collections import defaultdict graph = defaultdict(list) for u, v in edges: graph[u].append(v) visited = [False] * (n + 1) rec_stack = [False] * (n + 1) def dfs(v): visited[v] = True rec_stack[v] = True for neighbour in gr...
from solution import detect_cycle_in_graph def test_cycle_exists(): n, m = 3, 3 edges = [(1, 2), (2, 3), (3, 1)] assert detect_cycle_in_graph(n, m, edges) == "YES" def test_no_cycle(): n, m = 4, 4 edges = [(1, 2), (2, 3), (3, 4), (4, 1)] assert detect_cycle_in_graph(n, m, edges) == "YES" def ...
[ { "docstring": null, "function_declaration": "def contains_cycle(n, m, edges):", "function_name": "contains_cycle", "parameter_list": "(n, m, edges)" }, { "docstring": null, "function_declaration": "def detect_cycle_in_graph(n, m, edges):", "function_name": "detect_cycle_in_graph", ...
[ 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, edges):\n from collections import defaultdict, deque\n\n def is_cyclic(v):\n stack = deque([(v, set())])\n visited[v] = T...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00025434", "row_id": 25434, "seed_ids": "[7174, 4278, 5436]" }
0.736724
Codeforces_25434
I
[ "contains_cycle", "detect_cycle_in_graph" ]
2
[ [ "detect_cycle_in_graph", "contains_cycle" ] ]
1
[]
false
[]
false
pytest
true
[]
true
3ae6e0f3cfe121128ea685aec0e4afac12bb88e7
2668de22eaaa6d59dab56539137d52bf03b1cf0c
v1.0
instruct
Codeforces
Codeforces_25442_I
A prestigious coding competition is about to start, and you are one of the participants. Each participant will be given a sequence of positive integers representing their scores in previous contests. The competition organizers want to ensure a fair initial ranking and therefore will give special privileges to participa...
def is_prime(num): """ Checks if a number is prime. """ if num < 2: return False for i in range(2, int(num ** 0.5) + 1): if num % i == 0: return False return True def is_strictly_increasing(seq): """ Checks if a sequence of numbers is strictly increasing. ...
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 def test_is_strictly_increasing(): assert is_strictly_increasing([1, 2, 3]) == True assert is_strictly_increasing([1, 2, 2]) == Fal...
[ { "docstring": "Checks if a number is prime.", "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": "Checks if a sequence of numbers is strictly increasing.", "function_declaration": "def is_strictly_increasing(seq):", ...
[ 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 sympy import isprime\n\ndef is_strictly_increasing(seq):\n \"\"\"\n Check if the sequence is strictly increasing.\n \"\"\"\n for i in range(1...
trial_gpt4o_6
{ "original_instruction": "", "prompt_id": "00025442", "row_id": 25442, "seed_ids": "[2398, 7952, 8123]" }
0.693199
Codeforces_25442
I
[ "is_prime", "is_strictly_increasing", "count_privileged_participants" ]
3
[ [ "count_privileged_participants", "is_prime" ], [ "count_privileged_participants", "is_strictly_increasing" ] ]
2
[]
false
[]
false
pytest
false
[]
true
ce7b024a753a40ec84018e4c2d062003cfc862a6
051be2990506fccd7121d839f8234111757b4ebd
v1.0
instruct
Codeforces
Codeforces_25505_I
Given a binary tree, return all paths from the root to each leaf node, each path in the form of a list. A leaf node is a node with no children. The first line contains an integer n (1 ≤ n ≤ 2500), the number of nodes in the tree. Each of the following n lines contains three integers x, y, z. x denotes the value of the...
class TreeNode: def __init__(self, x): self.val = x self.left = None self.right = None def build_tree(n, nodes_info): if n == 0: return None nodes = {} for info in nodes_info: x, y, z = info if x not in nodes: nodes[x] = TreeNode(x) i...
from solution import get_all_paths def test_example_case(): n = 5 nodes_info = [ (1, 2, 3), (2, -1, -1), (3, 4, 5), (4, -1, -1), (5, -1, -1) ] expected_output = [ [1, 2], [1, 3, 4], [1, 3, 5] ] assert get_all_paths(n, nodes_info) =...
[]
[ 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 TreeNode:\n def __init__(self, x):\n self.val = x\n self.left = None\n self.right = None\n\ndef build_tree(n, nodes_info):\n ...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00025505", "row_id": 25505, "seed_ids": "[3764, 6845, 2475]" }
0.59768
Codeforces_25505
I
[ "build_tree", "all_paths_from_root_to_leaf", "get_all_paths" ]
3
[ [ "get_all_paths", "all_paths_from_root_to_leaf" ], [ "get_all_paths", "build_tree" ] ]
2
[]
false
[ "TreeNode" ]
true
pytest
true
[]
true
7ad6e66f01b77107ee1889210d34d9d4883b1fe0
58658bcf9887eb0587786200c2986743de92e7c3
v1.0
instruct
Codeforces
Codeforces_25573_I
In a certain kingdom, there are n castles numbered from 1 to n. Each castle is connected to at most two other castles by roads. Each road has a length, and it takes time proportional to the road's length to travel it. The roads can be represented as edges of a tree, where each castle corresponds to a node. The queen wa...
import sys import heapq from collections import defaultdict def dijkstra(graph, start, end): # Min-heap priority queue for Dijkstra's algorithm heap = [(0, start)] # Dictionary to store the shortest distance to each node distances = {i: float('inf') for i in graph} distances[start] = 0 while h...
def test_shortest_travel_time_simple(): n = 5 roads = [ (1, 2, 3), (1, 3, 1), (2, 4, 4), (2, 5, 2) ] u = 4 v = 5 assert shortest_travel_time(n, roads, u, v) == 6 def test_shortest_travel_time_single_road(): n = 2 roads = [ (1, 2, 5) ] u = ...
[ { "docstring": null, "function_declaration": "def dijkstra(graph, start, end):", "function_name": "dijkstra", "parameter_list": "(graph, start, end)" }, { "docstring": null, "function_declaration": "def shortest_travel_time(n, roads, u, v):", "function_name": "shortest_travel_time", ...
[ 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": "import heapq\nfrom collections import defaultdict, deque\n\ndef shortest_path_in_tree(n, edges, u, v):\n def dijkstra(graph, start):\n distances = {...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00025573", "row_id": 25573, "seed_ids": "[201, 5708, 2392]" }
0.735291
Codeforces_25573
I
[ "dijkstra", "shortest_travel_time" ]
2
[ [ "shortest_travel_time", "dijkstra" ] ]
1
[]
false
[]
false
pytest
false
[]
true
4ff9a680a9435d850b58e8bf2bdface6ffcc9b7f
7e62c06c43407576ea2ffd12deb1a70bc1de5d78
v1.0
instruct
Codeforces
Codeforces_25614_I
The following question is designed to align with the style, complexity, and scope of the provided questions: You are given a sequence of N natural numbers (positive integers) and an integer M. Your task is to find two subsequences of the given sequence such that the sum of the first subsequence is as close to M as pos...
def find_subsequences(n, m, sequence): from itertools import combinations closest_sum = float('-inf') best_subseq = None # generate all possible subsequences for length in range(1, n + 1): for subseq in combinations(sequence, length): sub_sum = sum(subseq) ...
from solution import solve def test_example_case(): assert solve(5, 10, [1, 2, 3, 4, 8]) == ("1 2 3 4", "8") def test_case_no_solution(): assert solve(3, 1, [2, 3, 4]) == "No solution" def test_case_multiple_solutions(): # 10 can be formed by either (4, 6) or (5, 5) but (4, 6) is lexicographically smalle...
[ { "docstring": null, "function_declaration": "def find_subsequences(n, m, sequence):", "function_name": "find_subsequences", "parameter_list": "(n, m, sequence)" }, { "docstring": null, "function_declaration": "def solve(n, m, sequence):", "function_name": "solve", "parameter_lis...
[ 0, 0, 0, 0, 0, 0, 0, 0, 1, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def find_subsequences(n, M, sequence):\n \"\"\"\n Finds two subsequences such that the sum of the first subsequence is as close to M as possible (but no...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00025614", "row_id": 25614, "seed_ids": "[6772, 1759, 2291]" }
0.76804
Codeforces_25614
I
[ "find_subsequences", "solve" ]
2
[ [ "solve", "find_subsequences" ] ]
1
[]
false
[]
false
pytest
true
[]
true
52456ca85b50dba5e7211737bc2da940b766dd1b
de044100b5cdc479717f3f89a412a0b7923ccda1
v1.0
instruct
Codeforces
Codeforces_25628_I
You are given an undirected graph with n nodes and m edges. Each edge has a weight associated with it. Your task is to find the Minimum Spanning Tree (MST) of the graph. A Minimum Spanning Tree is a subset of the edges which connects all vertices in the graph without any cycles and with the minimum possible total edg...
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] = ro...
from solution import kruskal_mst def test_kruskal_mst_basic(): assert kruskal_mst(4, [(1, 2, 1), (1, 3, 4), (2, 3, 2), (2, 4, 3), (3, 4, 5)]) == 6 def test_kruskal_mst_single_node(): assert kruskal_mst(1, []) == 0 def test_kruskal_mst_two_nodes_one_edge(): assert kruskal_mst(2, [(1, 2, 10)]) == 10 def t...
[ { "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": "class UnionFind:\n def __init__(self, size):\n self.parent = list(range(size))\n self.rank = [1] * size\n\n def find(self, node):\n ...
trial_gpt4o_3
{ "original_instruction": "", "prompt_id": "00025628", "row_id": 25628, "seed_ids": "[4724, 3932, 7101]" }
0.807606
Codeforces_25628
I
[ "find", "union", "kruskal_mst" ]
3
[ [ "kruskal_mst", "find" ], [ "kruskal_mst", "union" ], [ "union", "find" ] ]
3
[]
false
[]
false
pytest
true
[]
true
de7fbf741448be33565bdc2b4d6ed88e44705957
9519579fe70645558302b756b21c05b928c2cb74
v1.0
instruct
Codeforces
Codeforces_25635_I
A company is planning to digitize their library and they need to scan books. Each book is represented by a string of lowercase letters. To ensure accuracy in the database, the company implements a verification step that counts the number of anagrams each book title can form. Your task is to determine the number of dis...
import math from collections import Counter def count_anagrams(book_titles): results = [] for title in book_titles: freq = Counter(title) denominator = 1 for count in freq.values(): denominator *= math.factorial(count) total_anagrams = math.factorial(len(title)) // d...
from solution import number_of_anagrams def test_single_length_titles(): assert number_of_anagrams(3, ['a', 'b', 'c']) == [1, 1, 1] def test_multiple_length_titles(): assert number_of_anagrams(2, ['aabb', 'abc']) == [6, 6] assert number_of_anagrams(2, ['aaa', 'abcd']) == [1, 24] def test_large_input(): ...
[ { "docstring": null, "function_declaration": "def count_anagrams(book_titles):", "function_name": "count_anagrams", "parameter_list": "(book_titles)" }, { "docstring": null, "function_declaration": "def number_of_anagrams(n, book_titles):", "function_name": "number_of_anagrams", ...
[ 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 math import factorial\nfrom collections import Counter\n\ndef count_distinct_anagrams(book_titles):\n \"\"\"\n Given a list of book titles, return ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00025635", "row_id": 25635, "seed_ids": "[8104, 1756, 8039]" }
0.63948
Codeforces_25635
I
[ "count_anagrams", "number_of_anagrams" ]
2
[ [ "number_of_anagrams", "count_anagrams" ] ]
1
[]
false
[]
false
pytest
true
[]
true
9764936913e1abf5b3bb407b0563e92400e0475a
9614da9f2c0adf9cdb25f5aed1b187480b02cb90
v1.0
instruct
Codeforces
Codeforces_25725_I
Given an array of positive integers, you are asked to partition the array into several contiguous subarrays, such that for each subarray, the sum of its elements is a prime number. If there is more than one valid partition, you can output any of them. If no such partitioning is possible, print -1. A prime number is a ...
def is_prime(n): """ Determines if a number n is a prime number. """ if n <= 1: return False if n <= 3: return True if n % 2 == 0 or n % 3 == 0: return False i = 5 while i * i <= n: if n % i == 0 or n % (i + 2) == 0: return False i += 6...
from solution import is_prime, prime_partition 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(29) == True def test_prime_partition_case1(): arr = [2, 3, 5, 7, 11...
[ { "docstring": "Determines if a number n is a prime number.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Partitions the array into contiguous subarrays where each subarray sum is a prime number.\nIf such a partition is ...
[ 0, 0, 0, 0, 0, 0, 0, 1, 0, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(num):\n \"\"\"\n Checks if a number is prime.\n \"\"\"\n if num <= 1:\n return False\n if num == 2:\n return True\n ...
trial_gpt4o_7
{ "original_instruction": "", "prompt_id": "00025725", "row_id": 25725, "seed_ids": "[1736, 275, 7668]" }
0.648267
Codeforces_25725
I
[ "is_prime", "prime_partition" ]
2
[ [ "prime_partition", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
a841faeb5e1cd7be2f861978c8b88ae9160aa04f
30ab383a046dd603fab0280d45cdc229a346ada0
v1.0
instruct
Codeforces
Codeforces_25793_I
You are given an array of integers. Your task is to find an integer that appears an odd number of times in the array. If there are multiple such integers, return any one of them. If no such integer exists, return -1. The first line of the input contains an integer n (1 ≤ n ≤ 10^5) — the number of elements in the array...
def find_odd_occurrence(arr): """ Finds an integer that appears an odd number of times in the array. Parameters: arr (list): List of integers. Returns: int: An integer that appears an odd number of times, or -1 if there is none. """ count_map = {} # Count the occurrenc...
from solution import find_odd_occurrence, find_odd_occurrence_from_input def test_example_case(): assert find_odd_occurrence_from_input(7, [1, 2, 3, 2, 3, 1, 1]) == 1 def test_no_odd_occurrence(): assert find_odd_occurrence_from_input(4, [2, 2, 3, 3]) == -1 def test_single_element(): assert find_odd_occu...
[ { "docstring": "Finds an integer that appears an odd number of times in the array.\n\nParameters:\narr (list): List of integers.\n\nReturns:\nint: An integer that appears an odd number of times, or -1 if there is none.", "function_declaration": "def find_odd_occurrence(arr):", "function_name": "find_odd...
[ 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_odd_occurrence(arr):\n \"\"\"\n Given an array, returns an integer that appears an odd number of times.\n If no such integer exists, returns...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00025793", "row_id": 25793, "seed_ids": "[6001, 5354, 2772]" }
0.699293
Codeforces_25793
I
[ "find_odd_occurrence", "find_odd_occurrence_from_input" ]
2
[ [ "find_odd_occurrence_from_input", "find_odd_occurrence" ] ]
1
[]
false
[]
false
pytest
true
[]
true
12e3317c45c0c5a06a07f85a0016c6153cbffdb2
184808056c86797ac18fd4968e249f50b8c04e78
v1.0
instruct
Codeforces
Codeforces_25815_I
You are given an ancient library with old books. Due to the age of the books, some pages have been torn apart, leading to missing paragraphs or full pages. Each book is represented as a sequence of paragraphs, and each paragraph contains unique words. You have received a specific sequence of words that belongs to some...
def find_paragraph_with_sequence(k, books, m, search_sequence): search_sequence = " ".join(search_sequence) for book_index in range(k): paragraphs = books[book_index] for paragraph_index in range(len(paragraphs)): if search_sequence in paragraphs[paragraph_index]: ...
from solution import find_paragraph def test_simple_case(): input_text = "2\n3\nthe quick brown fox\njumps over the lazy dog\nin a galaxy far away\n2\na long time ago\non planet earth\n4\nover the lazy dog\n" assert find_paragraph(input_text) == (1, 2) def test_case_no_sequence(): input_text = "2\n3\nthe ...
[ { "docstring": null, "function_declaration": "def find_paragraph_with_sequence(k, books, m, search_sequence):", "function_name": "find_paragraph_with_sequence", "parameter_list": "(k, books, m, search_sequence)" }, { "docstring": null, "function_declaration": "def transform_input(input_t...
[ 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_sequence_of_words(k, books, m, sequence):\n \"\"\"\n Finds the book and paragraph indexes that contain the exact sequence of words.\n \n ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00025815", "row_id": 25815, "seed_ids": "[548, 7448, 5740]" }
0.611117
Codeforces_25815
I
[ "find_paragraph_with_sequence", "transform_input", "find_paragraph" ]
3
[ [ "find_paragraph", "find_paragraph_with_sequence" ], [ "find_paragraph", "transform_input" ] ]
2
[]
false
[]
false
pytest
true
[]
true
42354d3491bec92053f9b8fbd25ca5de0de9f7c7
811b6e258cb60088f1914e20fb73f2a9810b935f
v1.0
instruct
Codeforces
Codeforces_25866_I
You are given a matrix with $$$n$$$ rows and $$$m$$$ columns, filled with integers. Your task is to find the submatrix that has the maximum possible sum and return the sum of its elements. The submatrix should be contiguous, meaning it must contain elements only from consecutive rows and columns. The matrix is represe...
def max_sum_submatrix(matrix, n, m): def max_subarray(arr): max_sum = float('-inf') current_sum = 0 for x in arr: current_sum = max(x, current_sum + x) max_sum = max(max_sum, current_sum) return max_sum max_sum = float('-inf') for left in range(m...
def test_case_1(): input_str = """ 2 3 3 1 2 -1 -3 -4 5 2 3 -8 2 2 -1 -2 -3 -4 """ expected_output = [5, -1] assert max_sum_submatrices_from_input(input_str) == expected_output def test_case_2(): input_str = """ 1 1 1 7 """ expected_output = [7] ...
[ { "docstring": null, "function_declaration": "def max_sum_submatrix(matrix, n, m):", "function_name": "max_sum_submatrix", "parameter_list": "(matrix, n, m)" }, { "docstring": null, "function_declaration": "def get_max_sum_all_matrices(test_cases):", "function_name": "get_max_sum_all...
[ 1, 0 ]
1
medium
0.5
{ "trial_gpt4o_0": null, "trial_gpt4o_1": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared1_results_combined.jsonl", "solution_code": "def max_sum_submatrix(matrix, n, m):\n def max_subarray(arr):\n max_sum = float('-inf')\n current_sum = 0\n f...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00025866", "row_id": 25866, "seed_ids": "[604, 3448, 6732]" }
0.686335
Codeforces_25866
I
[ "max_sum_submatrix", "get_max_sum_all_matrices", "parse_input", "max_sum_submatrices_from_input" ]
4
[ [ "get_max_sum_all_matrices", "max_sum_submatrix" ], [ "max_sum_submatrices_from_input", "get_max_sum_all_matrices" ], [ "max_sum_submatrices_from_input", "parse_input" ] ]
3
[ "parse_input" ]
false
[]
false
pytest
false
[]
true
41e27e1d2cca5950e865676d90b5911a457986cb
b57e52bee7d2f001e7f846bcc21cf2af4288cc9a
v1.0
instruct
Codeforces
Codeforces_25889_I
Alice is trying to learn about prime numbers. A prime number is a natural number greater than 1 that has no positive divisors other than 1 and itself. You need to write a program that, given an integer n, returns the closest prime number to n. If there are two prime numbers equally close, return the smaller one. The ...
def is_prime(num): """ Check if a number is prime. """ if num <= 1: return False if num <= 3: return True if num % 2 == 0 or num % 3 == 0: return False i = 5 while i * i <= num: if num % i == 0 or num % (i + 2) == 0: return False i += 6...
from solution import is_prime, closest_prime def test_is_prime(): assert is_prime(2) == True assert is_prime(3) == True assert is_prime(4) == False assert is_prime(13) == True assert is_prime(25) == False def test_closest_prime(): assert closest_prime(10) == 11 assert closest_prime(15) == ...
[ { "docstring": "Check if a number is prime.", "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": "Returns the closest prime number to n. If there are two prime numbers equally close, returns the smaller one.", "function_...
[ 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_prime(num):\n if num <= 1:\n return False\n for i in range(2, int(num**0.5) + 1):\n if num % i == 0:\n return False\n ...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00025889", "row_id": 25889, "seed_ids": "[8331, 6153, 6841]" }
0.650565
Codeforces_25889
I
[ "is_prime", "closest_prime" ]
2
[ [ "closest_prime", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
aa17e49a9622c5c8e7ae43b59b4b314e2f9b9b7b
b5d2e230f87789537a84e64fcffd32166b0648d4
v1.0
instruct
Codeforces
Codeforces_25969_I
Petya has a favorite number which he considers very special. He calls a number "beautiful" if it consists only of digits 3 and 6. For example, numbers 333, 3663, and 666 are "beautiful" while 123, 345, and 789 are not. One day, Petya received a number `n` as a present. He wants to determine the largest "beautiful" num...
def largest_beautiful_number(n): """ Finds the largest "beautiful" number smaller than or equal to n. A "beautiful" number consists only of the digits 3 and 6. """ str_n = str(n) length = len(str_n) # Generate the largest beautiful numbers of the same length or shorter for length in ran...
from solution import largest_beautiful_number def test_example_cases(): assert largest_beautiful_number(573) == 366 assert largest_beautiful_number(3) == 3 assert largest_beautiful_number(1) == -1 def test_edge_cases(): assert largest_beautiful_number(333) == 333 assert largest_beautiful_number(66...
[ { "docstring": "Finds the largest \"beautiful\" number smaller than or equal to n.\nA \"beautiful\" number consists only of the digits 3 and 6.", "function_declaration": "def largest_beautiful_number(n):", "function_name": "largest_beautiful_number", "parameter_list": "(n)" }, { "docstring":...
[ 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 is_beautiful(number):\n \"\"\"\n Returns True if the number is \"beautiful\", i.e., consists only of digits 3 and 6.\n \"\"\"\n digits = set(s...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00025969", "row_id": 25969, "seed_ids": "[2916, 3711, 3466]" }
0.600693
Codeforces_25969
I
[ "largest_beautiful_number", "generate_beautiful_numbers" ]
2
[ [ "largest_beautiful_number", "generate_beautiful_numbers" ] ]
1
[]
false
[]
false
pytest
true
[]
true
995f185714f1be0f6a6e8aeee9f74700bcd67386
d57c42480e7be7ea0ddada05a37c4afb1882d240
v1.0
instruct
Codeforces
Codeforces_25971_I
You are given a collection of words composed of lowercase English letters. Each word is unique in this collection. Your task is to determine, for each word, the least number of characters you need to append to the end of it to make it a palindrome. A palindrome is a word that reads the same forwards and backwards. Th...
def min_append_to_palindrome(word): """ Returns the minimum number of characters that need to be appended to the end of the word to make it a palindrome. """ for i in range(len(word)): if word[i:] == word[i:][::-1]: return i return len(word) def process_words(n, words): ...
import pytest from solution import min_append_to_palindrome, process_words def test_min_append_to_palindrome(): assert min_append_to_palindrome("abc") == 2 assert min_append_to_palindrome("race") == 3 assert min_append_to_palindrome("madam") == 0 assert min_append_to_palindrome("ab") == 1 assert mi...
[ { "docstring": "Returns the minimum number of characters that need to be appended to the end\nof the word to make it a palindrome.", "function_declaration": "def min_append_to_palindrome(word):", "function_name": "min_append_to_palindrome", "parameter_list": "(word)" }, { "docstring": "Takes...
[ 0, 0, 0, 0, 0, 1, 0, 0, 0, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def min_chars_to_make_palindrome(word):\n \"\"\"\n Returns the minimum number of characters that need to be appended to the end of the word to make it a...
trial_gpt4o_5
{ "original_instruction": "", "prompt_id": "00025971", "row_id": 25971, "seed_ids": "[862, 5757, 1655]" }
0.841542
Codeforces_25971
I
[ "min_append_to_palindrome", "process_words" ]
2
[ [ "process_words", "min_append_to_palindrome" ] ]
1
[]
false
[]
false
pytest
true
[]
true
ee246156ee1e57f5bc9d986e15d57bb29b533a9b
aa0e32a0440a450fbaa528b0169fdf93b9a8e36c
v1.0
instruct
Codeforces
Codeforces_25990_I
Given a binary tree, write a program to find the longest path from the root node to a leaf node. A path is defined as a sequence of nodes from the root to any leaf node, where each node in the sequence is connected by an edge. A root is a node with no parent, and a leaf is a node with no children. The length of a path...
class TreeNode: def __init__(self, val): self.val = val self.children = [] def build_tree(n, edges): """ Build an adjacency list representation of the tree. """ nodes = {i: TreeNode(i) for i in range(1, n + 1)} for u, v in edges: nodes[u].children.append(nodes[v]) ...
import pytest from solution import find_longest_path def test_example(): n = 5 edges = [(1, 2), (1, 3), (3, 4), (3, 5)] assert find_longest_path(n, edges) == 2 def test_single_node(): n = 1 edges = [] assert find_longest_path(n, edges) == 0 def test_line_tree(): n = 4 edges = [(1, 2)...
[]
[ 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 defaultdict, deque\n\ndef longest_path_in_binary_tree(n, edges):\n if n == 1:\n return 0\n \n graph = defaultdict(list...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00025990", "row_id": 25990, "seed_ids": "[986, 915, 547]" }
0.66315
Codeforces_25990
I
[ "build_tree", "longest_path", "find_longest_path" ]
3
[ [ "find_longest_path", "build_tree" ], [ "find_longest_path", "longest_path" ] ]
2
[]
false
[ "TreeNode" ]
true
pytest
true
[]
true
45a750f4f2eb59f9859521f82df930e363922e02
1979dfb57269178db17c0b7f1bec11b0f6de7f1c
v1.0
instruct
Codeforces
Codeforces_25995_I
Given an integer array `arr` of length `n`, arrange the array elements into the minimum number of groups such that each group contains two or more contiguous elements with each pair of elements having the same greatest common divisor (GCD). The array elements are between 1 and 1000 (inclusive). Your task is to write ...
import math from typing import List def min_gcd_groups(arr: List[int]) -> int: """ Function to determine the minimum number of groups such that each group contains two or more contiguous elements with each pair of elements having the same greatest common divisor (GCD). """ n = len(arr) group_c...
from solution import min_gcd_groups_from_input def test_example_case(): assert min_gcd_groups_from_input(5, [4, 8, 6, 3, 9]) == 2 def test_single_group_case(): assert min_gcd_groups_from_input(4, [2, 4, 8, 16]) == 1 def test_multiple_groups_case(): assert min_gcd_groups_from_input(6, [2, 4, 6, 8, 3, 9]) ...
[ { "docstring": "Function to determine the minimum number of groups such that each group contains \ntwo or more contiguous elements with each pair of elements having the same greatest common divisor (GCD).", "function_declaration": "def min_gcd_groups(arr):", "function_name": "min_gcd_groups", "param...
[ 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 math import gcd\nfrom typing import List\n\ndef minimum_groups(arr: List[int]) -> int:\n def find_gcd_of_subarray(start: int, end: int) -> int:\n ...
trial_gpt4o_3
{ "original_instruction": "", "prompt_id": "00025995", "row_id": 25995, "seed_ids": "[5714, 2384, 3889]" }
0.683902
Codeforces_25995
I
[ "min_gcd_groups", "min_gcd_groups_from_input" ]
2
[ [ "min_gcd_groups_from_input", "min_gcd_groups" ] ]
1
[]
false
[]
false
pytest
true
[]
true
d525f7e45f58d725793cd17b4623e3a5704aa534
6682836b0375a7d2868b0b2e0231488c7e37ba02
v1.0
instruct
Codeforces
Codeforces_26035_I
A network of computers is hit by a virus that exploits a bug in the system. The virus can spread from one computer to another if there is a direct connection between them. You are given the network's topology as a list of direct connections, but unfortunately, some connections have been destroyed and need to be repaire...
def find_min_repairs(n, m, connections): parent = list(range(n + 1)) def find(x): if parent[x] != x: parent[x] = find(parent[x]) return parent[x] def union(x, y): rootX = find(x) rootY = find(y) if rootX != rootY: parent[rootY] = rootX f...
def test_example_case(): input_string = "4 2\n1 2\n3 4\n" assert min_repairs_from_input(input_string) == 1 def test_single_node(): input_string = "1 0\n" assert min_repairs_from_input(input_string) == 0 def test_fully_connected(): input_string = "3 3\n1 2\n2 3\n1 3\n" assert min_repairs_from_i...
[ { "docstring": null, "function_declaration": "def find_min_repairs(n, m, connections):", "function_name": "find_min_repairs", "parameter_list": "(n, m, connections)" }, { "docstring": null, "function_declaration": "def min_repairs_from_input(input_string):", "function_name": "min_rep...
[ 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_min_repairs(n, connections):\n # Helper function to perform DFS and find connected components\n def dfs(node, visited, adj):\n visited[n...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00026035", "row_id": 26035, "seed_ids": "[4331, 281, 6645]" }
0.645653
Codeforces_26035
I
[ "find_min_repairs", "min_repairs_from_input" ]
2
[ [ "min_repairs_from_input", "find_min_repairs" ] ]
1
[]
false
[]
false
pytest
false
[]
true
0e888ae6eae6c3298661bb04acd74202c36406fb
a96110c4fce812703954cee693f19b2aa931d546
v1.0
instruct
Codeforces
Codeforces_26049_I
You are given a set of n points in a 2D plane, each with distinct coordinates. Determine the smallest circle that can enclose all these points. The circle's radius should be minimized, and both the center and radius of the circle should be calculated with precision. First, input the integer n (1 ≤ n ≤ 100) — the numbe...
import math from itertools import combinations def dist_squared(p1, p2): return (p1[0] - p2[0]) ** 2 + (p1[1] - p2[1]) ** 2 def circle_from_two_points(p1, p2): cx = (p1[0] + p2[0]) / 2.0 cy = (p1[1] + p2[1]) / 2.0 radius = math.sqrt(dist_squared(p1, p2)) / 2.0 return (cx, cy), radius def circumce...
def test_min_enclosing_circle(): points = [(0, 0), (0, 1), (1, 0)] center, radius = min_enclosing_circle(3, points) assert abs(center[0] - 0.5) < 1e-6 assert abs(center[1] - 0.5) < 1e-6 assert abs(radius - 0.707107) < 1e-6 def test_min_enclosing_circle_one_point(): points = [(7, 8)] center,...
[ { "docstring": null, "function_declaration": "def dist_squared(p1, p2):", "function_name": "dist_squared", "parameter_list": "(p1, p2)" }, { "docstring": null, "function_declaration": "def circle_from_two_points(p1, p2):", "function_name": "circle_from_two_points", "parameter_lis...
[ 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 math\nfrom typing import List, Tuple\n\ndef dist(p1: Tuple[int, int], p2: Tuple[int, int]) -> float:\n return math.sqrt((p1[0] - p2[0]) ** 2 + (p1[1...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00026049", "row_id": 26049, "seed_ids": "[6345, 7849, 2186]" }
0.614149
Codeforces_26049
I
[ "dist_squared", "circle_from_two_points", "circumcenter", "min_enclosing_circle", "main" ]
5
[ [ "circle_from_two_points", "dist_squared" ], [ "circumcenter", "dist_squared" ], [ "min_enclosing_circle", "circle_from_two_points" ], [ "min_enclosing_circle", "circumcenter" ], [ "min_enclosing_circle", "dist_squared" ] ]
5
[]
false
[]
false
pytest
false
[]
true
22b91b413d1850fe7222ef0ef5675efb9388183b
5de215d4c0f8ab9f35d638b65b60ea2e7f693ad1
v1.0
instruct
Codeforces
Codeforces_26065_I
Hiroshi, an avid coder, has devised a game involving an NxM grid filled with numbers. Each cell of the grid contains a positive integer. The objective is to find a path from the top-left corner (cell (1,1)) to the bottom-right corner (cell (N,M)) such that the sum of the values on the path is maximized. Hiroshi can onl...
def max_path_sum(grid): N = len(grid) M = len(grid[0]) # Create a 2D dp array to store the maximum sum up to each position dp = [[0]*M for _ in range(N)] # Initialize the top-left cell dp[0][0] = grid[0][0] # Initialize the first column for i in range(1, N): dp[i][...
from solution import max_path_sum, solve_max_path_sum def test_max_path_sum(): grid = [ [1, 2, 3], [4, 5, 6], [7, 8, 9] ] assert max_path_sum(grid) == 29 def test_solve_max_path_sum_example(): N = 3 M = 3 grid = [ [1, 2, 3], [4, 5, 6], [7, 8, 9] ...
[ { "docstring": null, "function_declaration": "def max_path_sum(grid):", "function_name": "max_path_sum", "parameter_list": "(grid)" }, { "docstring": null, "function_declaration": "def solve_max_path_sum(N, M, grid):", "function_name": "solve_max_path_sum", "parameter_list": "(N,...
[ 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": "def max_path_sum(grid):\n \"\"\"\n Returns the maximum sum of values on a path from the top-left corner to the bottom-right corner\n where one can on...
trial_gpt4o_6
{ "original_instruction": "", "prompt_id": "00026065", "row_id": 26065, "seed_ids": "[4203, 2785, 7923]" }
0.647425
Codeforces_26065
I
[ "max_path_sum", "solve_max_path_sum" ]
2
[ [ "solve_max_path_sum", "max_path_sum" ] ]
1
[]
false
[]
false
pytest
true
[]
true
3324367f5f2fc6cf6b9f50771c60ad635fe949fc
92da9348a44255b3c7e1fe64d8f563595bf7f36b
v1.0
instruct
Codeforces
Codeforces_26113_I
The kingdom of CodeLand consists of n cities and m bidirectional roads linking the cities. Every road connects two distinct cities and no two roads connect the same pair of cities. CodeLand government wants to make sure that residents can travel easily between cities, so they have tasked you with ensuring that the king...
def find(parent, i): """ A utility function to find the subset of an element i """ if parent[i] == i: return i else: return find(parent, parent[i]) def union(parent, rank, x, y): """ A function that does union of two subsets x and y """ xroot = find(parent, x) yroot = find(paren...
from solution import minimum_new_roads def test_minimum_new_roads_case1(): n = 5 m = 2 roads = [(1, 2), (3, 4)] count, new_roads = minimum_new_roads(n, m, roads) assert count == 2 assert new_roads == [(1, 3), (3, 5)] or new_roads == [(2, 3), (3, 5)] def test_minimum_new_roads_case2(): n = ...
[ { "docstring": "A utility function to find the subset of an element i ", "function_declaration": "def find(parent, i):", "function_name": "find", "parameter_list": "(parent, i)" }, { "docstring": "A function that does union of two subsets x and y ", "function_declaration": "def union(par...
[ 0, 0, 0, 0, 1 ]
1
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def find(parent, i):\n if parent[i] == i:\n return i\n else:\n root_i = find(parent, parent[i])\n parent[i] = root_i # Path compre...
trial_gpt4o_4
{ "original_instruction": "", "prompt_id": "00026113", "row_id": 26113, "seed_ids": "[4048, 1093, 8165]" }
0.756659
Codeforces_26113
I
[ "find", "union", "minimum_new_roads" ]
3
[ [ "minimum_new_roads", "find" ], [ "minimum_new_roads", "union" ], [ "union", "find" ] ]
3
[]
false
[]
false
pytest
true
[]
true
31823ef1e1a12f142229ad593fbf3fe43d0d1c9e
6b93feaad542705c108715c3b5c44d208009ffb0
v1.0
instruct
Codeforces
Codeforces_26146_I
In a city, there are n zones (numbered from 1 to n) and m one-way roads connecting them. Each road has a travel time associated with it. You need to find the shortest travel times from a designated start zone to all other zones. Write a program that takes as input the number of zones n, the number of roads m, the star...
import heapq def dijkstra(n, m, start, roads): graph = [[] for _ in range(n + 1)] for u, v, t in roads: graph[u].append((v, t)) distances = [float('inf')] * (n + 1) distances[start] = 0 priority_queue = [(0, start)] while priority_queue: current_distance, current_...
from solution import solve def test_example_case(): input_lines = [ "5 6 1", "1 2 1", "1 3 3", "2 3 1", "2 4 6", "3 4 2", "4 5 1" ] result = solve(input_lines) assert result == [0, 1, 2, 4, 5] def test_no_roads(): input_lines = [ "4 0...
[ { "docstring": null, "function_declaration": "def dijkstra(n, m, start, roads):", "function_name": "dijkstra", "parameter_list": "(n, m, start, roads)" }, { "docstring": null, "function_declaration": "def solve(input_lines):", "function_name": "solve", "parameter_list": "(input_l...
[ 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 dijkstra(n, m, start, roads):\n \"\"\"\n Compute shortest paths from start to all other zones.\n :param n: Number of zones\n :...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00026146", "row_id": 26146, "seed_ids": "[5583, 294, 6012]" }
0.757557
Codeforces_26146
I
[ "dijkstra", "solve" ]
2
[ [ "solve", "dijkstra" ] ]
1
[]
false
[]
false
pytest
true
[]
true
27c87a9893e6fde6c244e8c9f6091ba1ec48227d
e99d029c07be1ced5adcfc0b3395e0d21527de0b
v1.0
instruct
Codeforces
Codeforces_26148_I
You are given a binary search tree (BST) with n nodes, each node having a unique value between 1 and n. You are also given a list of queries. Each query represents a value, and your task is to find the node in the BST that is closest to that value. The closest node is defined based on the absolute difference between th...
class TreeNode: def __init__(self, x): self.val = x self.left = None self.right = None def insert_into_bst(root, val): if not root: return TreeNode(val) if val < root.val: root.left = insert_into_bst(root.left, val) else: root.right = insert_into_bst(root...
from solution import TreeNode, insert_into_bst, closest_value_in_bst, solve_bst_closest_value def test_closest_value_simple_case(): root = None for val in [4, 2, 6, 1, 3]: root = insert_into_bst(root, val) assert closest_value_in_bst(root, 5) == 4 assert closest_value_in_bst(root, 2) == 2 a...
[]
[ 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": "class TreeNode:\n def __init__(self, x):\n self.val = x\n self.left = None\n self.right = None\n\ndef insert_bst(root, val):\n if r...
trial_gpt4o_5
{ "original_instruction": "", "prompt_id": "00026148", "row_id": 26148, "seed_ids": "[6927, 2948, 3998]" }
0.587507
Codeforces_26148
I
[ "insert_into_bst", "closest_value_in_bst", "solve_bst_closest_value" ]
3
[ [ "solve_bst_closest_value", "closest_value_in_bst" ], [ "solve_bst_closest_value", "insert_into_bst" ] ]
2
[]
false
[ "TreeNode" ]
true
pytest
true
[]
true
d20de5664ac49f1a48af91911942d5350211d4cd
1356f5b85e98e7bc2934391fa36315b47fc939e9
v1.0
instruct
Codeforces
Codeforces_26173_I
A corporation is planning to distribute company T-shirts to its employees. The corporation has arranged for a local printing shop to produce the T-shirts. However, due to a certain constraint, the printing shop can only produce T-shirts in two sizes: small (S) and large (L). Each order must consist of a number of T-shi...
def lcm(a, b): """ Returns the least common multiple (LCM) of two numbers a and b. """ def gcd(x, y): while y: x, y = y, x % y return x return abs(a * b) // gcd(a, b) def min_tshirts_order(S, L): """ Returns the minimum number of T-shirts that is divisible b...
def test_min_tshirts_order(): assert min_tshirts_order(3, 5) == 15, "Test case 1 failed" assert min_tshirts_order(4, 6) == 12, "Test case 2 failed" assert min_tshirts_order(1, 1) == 1, "Test case 3 failed" assert min_tshirts_order(6, 8) == 24, "Test case 4 failed" assert min_tshirts_order(7, 7) == 7...
[ { "docstring": "Returns the least common multiple (LCM) of two numbers a and b.", "function_declaration": "def lcm(a, b):", "function_name": "lcm", "parameter_list": "(a, b)" }, { "docstring": "Returns the minimum number of T-shirts that is divisible by both S and L.", "function_declarat...
[ 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 lcm(a, b):\n \"\"\"\n Returns the least common multiple of a and b.\n \"\"\"\n def gcd(x, y):\n while y:\n x, y = y, x % y\n...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00026173", "row_id": 26173, "seed_ids": "[657, 7919, 6076]" }
0.733605
Codeforces_26173
I
[ "lcm", "min_tshirts_order" ]
2
[ [ "min_tshirts_order", "lcm" ] ]
1
[]
false
[]
false
pytest
false
[]
true
e1cfc405f07d3236f9475e6424c60b989c94656d
67d8f98b2a106d6df73cecb490283b8bef6ce843
v1.0
instruct
Codeforces
Codeforces_26178_I
A farmer wants to arrange his crops in a rectangular field with dimensions n × m. Each cell of the field can grow a certain type of crop and the farmer wants to maximize the variety of crops in the field. However, there is a restriction: No two adjacent cells (horizontally or vertically) should have the same type of cr...
def max_crops(n, m): """ Returns the maximum number of different crops that can be planted in the field, and an arrangement of crops in the field. """ crops = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" crop_arrangement = [] for i in range(n): row = [] for j in range(m): # The...
from solution import max_crops def test_max_crops_2x3(): max_crop_count, arrangement = max_crops(2, 3) assert max_crop_count == 2 assert len(arrangement) == 2 assert len(arrangement[0]) == 3 assert len(arrangement[1]) == 3 assert arrangement[0][0] != arrangement[0][1] assert arrangement[0][...
[ { "docstring": "Returns the maximum number of different crops that can be planted in the field,\nand an arrangement of crops in the field.", "function_declaration": "def max_crops(n, m):", "function_name": "max_crops", "parameter_list": "(n, m)" }, { "docstring": null, "function_declarat...
[ 0, 0, 0, 0, 0, 0, 0, 0, 1, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def max_crop_types(n, m):\n \"\"\"\n Returns the maximum number of different crop types that can be planted\n and the arrangement corresponding to th...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00026178", "row_id": 26178, "seed_ids": "[6176, 507, 6949]" }
0.62843
Codeforces_26178
I
[ "max_crops", "print_max_crops" ]
2
[ [ "print_max_crops", "max_crops" ] ]
1
[]
false
[]
false
pytest
true
[]
true
e0334f4173948269cb207387303cdddd66899e20
32c048e6e68fb0c507f0bf50d1ddeb4744efaf9d
v1.0
instruct
Codeforces
Codeforces_26207_I
Alex has recently started learning about palindrome numbers. A palindrome number is a number that remains the same when its digits are reversed. He is very curious to know how many palindrome numbers exist within a given range [L, R]. Given two integers L and R (1 ≤ L ≤ R ≤ 10^9), write a program to help Alex determin...
def is_palindrome(n): """ Check if the given number n is a palindrome. """ return str(n) == str(n)[::-1] def count_palindromes(L, R): """ Count the number of palindrome numbers between L and R, inclusive. """ count = 0 for i in range(L, R + 1): if is_palindrome(i): ...
from solution import is_palindrome, count_palindromes def test_is_palindrome(): assert is_palindrome(121) == True assert is_palindrome(123) == False assert is_palindrome(1) == True assert is_palindrome(0) == True assert is_palindrome(12321) == True def test_count_palindromes_small_range(): ass...
[ { "docstring": "Check if the given number n is a palindrome.", "function_declaration": "def is_palindrome(n):", "function_name": "is_palindrome", "parameter_list": "(n)" }, { "docstring": "Count the number of palindrome numbers between L and R, inclusive.", "function_declaration": "def c...
[ 0, 0, 0, 0, 0, 0, 0, 1, 0, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_palindrome(n):\n \"\"\"\n Checks if a number is a palindrome.\n \"\"\"\n return str(n) == str(n)[::-1]\n\ndef count_palindromes(L, R):\n ...
trial_gpt4o_7
{ "original_instruction": "", "prompt_id": "00026207", "row_id": 26207, "seed_ids": "[4894, 4139, 2665]" }
0.721435
Codeforces_26207
I
[ "is_palindrome", "count_palindromes" ]
2
[ [ "count_palindromes", "is_palindrome" ] ]
1
[]
false
[]
false
pytest
true
[]
true
5d6c1f8793b6e1b4cedc7ba9fd9624f91029336b
9bd375b6f569ac32696a0ed49eb4cfc899bab09a
v1.0
instruct
Codeforces
Codeforces_26219_I
Maria is learning about binary trees and has come across the concept of a "height-balanced" binary tree. A binary tree is height-balanced if the difference in height between the left and right subtrees of every node is at most 1. She wants to write a function to determine if a given binary tree is height-balanced. The...
from typing import List, Tuple class TreeNode: def __init__(self, val=0, left=None, right=None): self.val = val self.left = left self.right = right def build_tree_from_list(tree: List[int], index: int) -> TreeNode: if index >= len(tree) or tree[index] == -1: return None roo...
from solution import is_balanced_tree def test_balanced_tree(): # Balanced tree example tree = [1, 2, 3, 4, 5, 6, 7] assert is_balanced_tree(tree) == True def test_unbalanced_tree(): # Unbalanced tree example tree = [1, 2, 3, 4, 5, -1, -1, 6, -1, -1] assert is_balanced_tree(tree) == False def...
[]
[ 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 typing import List, Tuple\n\nclass TreeNode:\n def __init__(self, x):\n self.val = x\n self.left = None\n self.right = None\n\nde...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00026219", "row_id": 26219, "seed_ids": "[465, 5506, 53]" }
0.782984
Codeforces_26219
I
[ "build_tree_from_list", "check_balance_and_height", "is_balanced_tree" ]
3
[ [ "is_balanced_tree", "build_tree_from_list" ], [ "is_balanced_tree", "check_balance_and_height" ] ]
2
[]
false
[ "TreeNode" ]
true
pytest
true
[]
true
33959b4e103e950282cebed84cea2b58e2555ce7
30ce4156aded1d1b44c5a6222f7cb9053f1b57f5
v1.0
instruct
Codeforces
Codeforces_26231_I
In a land far away, there is a game played with an array of integers. The array can be split into subarrays and you perform specified operations to calculate the subarray sums. Let's define the problem more formally: You are given an array of integers of length n. You are required to handle multiple queries. Each quer...
def preprocess_prefix_sums(arr): """ Preprocess the array into a prefix sum array. """ n = len(arr) prefix_sums = [0] * (n + 1) for i in range(1, n + 1): prefix_sums[i] = prefix_sums[i - 1] + arr[i - 1] return prefix_sums def sum_subarray(prefix_sums, l, r): """ Calculate th...
def test_preprocess_prefix_sums(): arr = [1, 2, 3, 4, 5] expected_prefix_sums = [0, 1, 3, 6, 10, 15] assert preprocess_prefix_sums(arr) == expected_prefix_sums def test_sum_subarray(): prefix_sums = [0, 1, 3, 6, 10, 15] assert sum_subarray(prefix_sums, 1, 3) == 6 assert sum_subarray(prefix_sums...
[ { "docstring": "Preprocess the array into a prefix sum array.", "function_declaration": "def preprocess_prefix_sums(arr):", "function_name": "preprocess_prefix_sums", "parameter_list": "(arr)" }, { "docstring": "Calculate the sum of the subarray using the prefix sums array.\nThe indices l an...
[ 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_array(arr):\n \"\"\"\n Preprocess the array to create a prefix sum array.\n \"\"\"\n prefix_sum = [0] * (len(arr) + 1)\n for i i...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00026231", "row_id": 26231, "seed_ids": "[6503, 5351, 7636]" }
0.716216
Codeforces_26231
I
[ "preprocess_prefix_sums", "sum_subarray", "process_queries" ]
3
[ [ "process_queries", "preprocess_prefix_sums" ], [ "process_queries", "sum_subarray" ] ]
2
[ "process_queries" ]
false
[]
false
pytest
false
[]
true
b9d79f15afedb1ce74dc7e0420504dfa3df05972
fb7f77efdafb8540c09381391ccb52e84f1beda3
v1.0
instruct
Codeforces
Codeforces_26232_I
A company wants to conduct a small survey by sending out personalized invitation emails to participants. Each email contains a special code that is unique to the participant. The email format should follow specific rules to prevent spam blockers from marking it as spam. Given a list of participants' information, gener...
import random import string def generate_survey_code(existing_codes): while True: code = random.choice(string.ascii_letters) + ''.join(random.choices(string.ascii_letters + string.digits, k=7)) if code not in existing_codes: existing_codes.add(code) return code def generate...
from solution import generate_emails, generate_survey_code def test_generate_unique_survey_code(): existing_codes = set() codes = [generate_survey_code(existing_codes) for _ in range(10)] assert len(codes) == len(set(codes)) # check for uniqueness assert all(code[0].isalpha() for code in codes) # che...
[ { "docstring": null, "function_declaration": "def generate_survey_code(existing_codes):", "function_name": "generate_survey_code", "parameter_list": "(existing_codes)" }, { "docstring": null, "function_declaration": "def generate_emails(participants):", "function_name": "generate_ema...
[ 0, 1 ]
1
medium
0.5
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "import random\nimport string\n\ndef generate_unique_code(existing_codes):\n \"\"\"Generates a unique 8 character code starting with a letter.\"\"\"\n wh...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00026232", "row_id": 26232, "seed_ids": "[3050, 5101, 1425]" }
0.481786
Codeforces_26232
I
[ "generate_survey_code", "generate_emails" ]
2
[ [ "generate_emails", "generate_survey_code" ] ]
1
[]
false
[]
false
pytest
true
[]
true
cc3614d23c708c6bbe87c0fe14d1a0b292e869f5
1c2b9ed064710bdb41a6a92ccafa76b6e30e3a26
v1.0
instruct
Codeforces
Codeforces_26298_I
Alicia is organizing a charity auction and she needs to determine the minimum cost of achieving her target fund. She has a list of items, each with a given price and a value. Alicia can sell any subset of these items, and she wants to choose the subset that achieves at least her target fund with the minimum possible to...
def minimum_cost_achieving_target(n, T, items): # Create a dp array where dp[i] represents the minimum cost to achieve at least value i dp = [float('inf')] * (T + 1) dp[0] = 0 for price, value in items: for i in range(T, value - 1, -1): dp[i] = min(dp[i], dp[i - value] + price) ...
from solution import charity_auction def test_example_case(): assert charity_auction(4, 10, [(4, 6), (2, 4), (7, 8), (5, 3)]) == 6 def test_single_item_exact(): assert charity_auction(1, 10, [(10, 10)]) == 10 def test_single_item_not_enough(): assert charity_auction(1, 11, [(10, 10)]) == -1 def test_mul...
[ { "docstring": null, "function_declaration": "def minimum_cost_achieving_target(n, T, items):", "function_name": "minimum_cost_achieving_target", "parameter_list": "(n, T, items)" }, { "docstring": null, "function_declaration": "def charity_auction(n, T, items):", "function_name": "c...
[ 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 min_cost_to_achieve_target(n, T, items):\n \"\"\"\n Returns the minimum total price required to achieve at least the target fund or -1 if not possib...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00026298", "row_id": 26298, "seed_ids": "[4492, 7993, 1132]" }
0.70172
Codeforces_26298
I
[ "minimum_cost_achieving_target", "charity_auction" ]
2
[ [ "charity_auction", "minimum_cost_achieving_target" ] ]
1
[]
false
[]
false
pytest
true
[]
true
67502394ff3ccaa499a6048bd6eaf3e5b315d2f3
6a778802881eb9550aff723df4a71e5ae94da58b
v1.0
instruct
Codeforces
Codeforces_26358_I
Vasya is a curious boy and loves math puzzles. He recently learned about prime numbers and challenges you with the following task. Given an integer \( N \), your task is to find the smallest prime number greater than \( N \). A prime number is a positive integer greater than 1 that has no positive integer divisors oth...
def is_prime(num): """ Checks if a number is prime. """ if num <= 1: return False if num == 2 or 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 ...
from solution import is_prime, next_prime def test_is_prime(): assert is_prime(2) == True assert is_prime(3) == True assert is_prime(4) == False assert is_prime(5) == True assert is_prime(29) == True assert is_prime(25) == False assert is_prime(1) == False assert is_prime(0) == False ...
[ { "docstring": "Checks if a number is prime.", "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": "Returns the smallest prime number greater than N.", "function_declaration": "def next_prime(N):", "function_name": "n...
[ 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(num):\n \"\"\"\n Checks if a number is prime.\n \"\"\"\n if num <= 1:\n return False\n if num == 2 or num == 3:\n re...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00026358", "row_id": 26358, "seed_ids": "[2656, 6022, 8283]" }
0.579785
Codeforces_26358
I
[ "is_prime", "next_prime" ]
2
[ [ "next_prime", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
58a0c7d7eb9fc3393b583bd5610fc4fc39c28464
89f373bcde63220e423be8722e0f1143b503c2f5
v1.0
instruct
Codeforces
Codeforces_26360_I
Albert is playing with trees. A tree is a connected undirected graph with no cycles. He is particularly interested in certain properties of "special paths" in these trees. A special path between nodes u and v in a tree is defined as a path where the sum of the node values on the path is minimized. Albert has a tree wi...
from collections import defaultdict, deque def build_tree(edges, n): tree = defaultdict(list) for u, v in edges: tree[u].append(v) tree[v].append(u) return tree def calc_subtree_sums(tree, node_values, root): n = len(node_values) subtree_sums = [0] * (n + 1) visited = [False] *...
from solution import special_paths_sum def test_example(): n = 5 node_values = [1, 2, 3, 4, 5] edges = [(1, 2), (1, 3), (2, 4), (2, 5)] queries = [(1, 4), (1, 5), (3, 4)] expected = [7, 8, 10] result = special_paths_sum(n, node_values, edges, queries) assert result == expected def test_sin...
[ { "docstring": null, "function_declaration": "def build_tree(edges, n):", "function_name": "build_tree", "parameter_list": "(edges, n)" }, { "docstring": null, "function_declaration": "def calc_subtree_sums(tree, node_values, root):", "function_name": "calc_subtree_sums", "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": "class TreeNode:\n def __init__(self, value):\n self.value = value\n self.children = []\n\ndef dfs(node, parent, values, subtree_sums, tree_no...
trial_gpt4o_4
{ "original_instruction": "", "prompt_id": "00026360", "row_id": 26360, "seed_ids": "[4919, 2836, 7894]" }
0.73585
Codeforces_26360
I
[ "build_tree", "calc_subtree_sums", "find_special_path_sum", "special_paths_sum" ]
4
[ [ "special_paths_sum", "build_tree" ], [ "special_paths_sum", "calc_subtree_sums" ], [ "special_paths_sum", "find_special_path_sum" ] ]
3
[]
false
[]
false
pytest
true
[]
true
9e919a56af0df0390f7c16b917dcd3eae93e2433
3d931cce0b5b799e4f5291b99b8855b68627f424
v1.0
instruct
Codeforces
Codeforces_26374_I
Tom recently got a job at a renowned software company, and one of his tasks is to optimize memory usage of programs. He is working on a program that deals with an integer array, `arr`, of length `n`. He needs to answer `q` queries, each querying the smallest value in a subarray of `arr`. Each query is described by two...
import sys import math def preprocess(arr, n): # Initialize sparse table for range minimum query log = math.ceil(math.log2(n)) sparse_table = [[0] * (log + 1) for _ in range(n)] # Initialize all minimum values for the intervals of length 1 for i in range(n): sparse_table[i][0] = arr[i]...
import pytest from solution import solve def test_example(): n, q = 5, 3 arr = [1, 2, 3, 4, 5] queries = [(1, 3), (2, 4), (1, 5)] expected_output = [1, 2, 1] assert solve(n, q, arr, queries) == expected_output def test_single_element(): n, q = 1, 1 arr = [42] queries = [(1, 1)] ex...
[ { "docstring": null, "function_declaration": "def preprocess(arr, n):", "function_name": "preprocess", "parameter_list": "(arr, n)" }, { "docstring": null, "function_declaration": "def query(sparse_table, l, r):", "function_name": "query", "parameter_list": "(sparse_table, l, r)"...
[ 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 sys\nimport math\n\ndef preprocess(arr, n):\n # Initialize sparse table for range minimum query\n log = math.ceil(math.log2(n))\n sparse_table...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00026374", "row_id": 26374, "seed_ids": "[1762, 1347, 4949]" }
0.682952
Codeforces_26374
I
[ "preprocess", "query", "solve" ]
3
[ [ "solve", "preprocess" ], [ "solve", "query" ] ]
2
[]
false
[]
false
pytest
true
[]
true
0d81cb5e723b1226440ce91ad3c18f242a218219
45315886de694cf21e4917c24e5d912658d136e0
v1.0
instruct
Codeforces
Codeforces_26420_I
Aria is a successful gardener with a large flower garden. She has a large section of the garden where she wants to plant flowers in a long straight line. To make the garden look beautiful, she decided to plant exactly k flowers and wants to maximize the minimum distance between any two adjacent flowers. You are given ...
def can_place_flowers(positions, k, min_distance): count = 1 # Place the first flower at the first position last_position = positions[0] for position in positions[1:]: if position - last_position >= min_distance: count += 1 last_position = position if c...
import pytest from solution import max_min_distance def test_example_case(): assert max_min_distance(5, 3, [1, 2, 8, 4, 9]) == 3 def test_small_case(): assert max_min_distance(2, 2, [1, 10]) == 9 def test_consecutive_positions(): assert max_min_distance(5, 3, [1, 2, 3, 4, 5]) == 2 def test_large_gap(): ...
[ { "docstring": null, "function_declaration": "def can_place_flowers(positions, k, min_distance):", "function_name": "can_place_flowers", "parameter_list": "(positions, k, min_distance)" }, { "docstring": null, "function_declaration": "def max_min_distance(n, k, positions):", "functio...
[ 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 max_min_distance(n, k, positions):\n \"\"\"\n Returns the maximum minimum distance between any two flowers\n that can be planted at exactly k pos...
trial_gpt4o_3
{ "original_instruction": "", "prompt_id": "00026420", "row_id": 26420, "seed_ids": "[4875, 413, 1826]" }
0.645765
Codeforces_26420
I
[ "can_place_flowers", "max_min_distance" ]
2
[ [ "max_min_distance", "can_place_flowers" ] ]
1
[]
false
[]
false
pytest
true
[]
true
0a3234e795089731ca9e828f3f419c8ce2cde0b1
b94e46cbdec050dd7793a9b5364da4831e447e99
v1.0
instruct
Codeforces
Codeforces_26433_I
You are given an array $$$a$$$ consisting of $$$n$$$ integers and an integer $$$k$$$. Your task is to determine whether it is possible to partition the array into exactly $$$k$$$ non-empty subsets such that the sum of each subset is a prime number. An integer $$$p$$$ is considered a prime if it is greater than 1 and c...
from itertools import combinations def is_prime(num): """ Check if a number is a prime. """ if num <= 1: return False for i in range(2, int(num ** 0.5) + 1): if num % i == 0: return False return True def can_partition_into_prime_sums(n, k, arr): """ Determin...
def test_can_partition_into_prime_sums(): assert can_partition_into_prime_sums(5, 3, [6, 5, 8, 12, 1]) == "NO" assert can_partition_into_prime_sums(3, 2, [5, 7, 6]) == "YES" assert can_partition_into_prime_sums(4, 2, [3, 11, 7, 2]) == "YES" assert can_partition_into_prime_sums(4, 2, [4, 6, 8, 9]) == "NO...
[ { "docstring": "Check if a number is a prime.", "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": "Determine if array can be partitioned into `k` non-empty subsets such that each subset sum is a prime number.", "functio...
[ 0, 0, 0, 0, 0, 1, 0, 0, 0, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(num):\n \"\"\" Returns True if num is a prime number, otherwise False. \"\"\"\n if num <= 1:\n return False\n if num == 2:\n ...
trial_gpt4o_5
{ "original_instruction": "", "prompt_id": "00026433", "row_id": 26433, "seed_ids": "[7714, 5766, 7711]" }
0.620371
Codeforces_26433
I
[ "is_prime", "can_partition_into_prime_sums" ]
2
[ [ "can_partition_into_prime_sums", "is_prime" ] ]
1
[]
false
[]
false
pytest
false
[]
true
74add88b1f29fea82debbbdf33fc0f0b3804c11d
53cc4e1528605ee3df378b9cbecfecbce7df5dda
v1.0
instruct
Codeforces
Codeforces_26460_I
Alice loves to play with numbers. Today she came across an interesting challenge about palindrome numbers and decided to test you with it. A palindrome number is a number that remains the same when its digits are reversed. For example, 121 and 1331 are palindromes while 123 and 1223 are not. Alice gives you a number ...
def is_palindrome(num): return str(num) == str(num)[::-1] def next_palindrome(N): N += 1 while not is_palindrome(N): N += 1 return N
from solution import next_palindrome def test_next_palindrome(): assert next_palindrome(123) == 131 assert next_palindrome(1234) == 1331 assert next_palindrome(999) == 1001 assert next_palindrome(1) == 2 assert next_palindrome(11) == 22 def test_next_palindrome_edge_cases(): assert next_palind...
[ { "docstring": null, "function_declaration": "def is_palindrome(num):", "function_name": "is_palindrome", "parameter_list": "(num)" }, { "docstring": null, "function_declaration": "def next_palindrome(N):", "function_name": "next_palindrome", "parameter_list": "(N)" } ]
[ 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_palindrome(num):\n \"\"\"\n Check if the given number is a palindrome.\n \"\"\"\n return str(num) == str(num)[::-1]\n\ndef next_palindrome(...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00026460", "row_id": 26460, "seed_ids": "[2768, 619, 20]" }
0.813127
Codeforces_26460
I
[ "is_palindrome", "next_palindrome" ]
2
[ [ "next_palindrome", "is_palindrome" ] ]
1
[]
false
[]
false
pytest
true
[]
true
a59760962c7adcce9e8c8836ab10d30e12fb95ac
515a9f37992d5048262b230a728afbef7b873d5f
v1.0
instruct
Codeforces
Codeforces_26526_I
In a magical kingdom, there are n cities connected by m bidirectional roads. Each road has a certain length. The roads are arranged such that there is at least one way to travel between any two cities. A powerful wizard has decided to make travel faster by providing portals. A portal can directly connect any two cities...
def floyd_warshall(n, graph): # Initialize distance matrix with infinity dist = [[float('inf')] * n for _ in range(n)] # Initialize distances to themselves as zero for i in range(n): dist[i][i] = 0 # Initialize distances based on the graph edges for u in range(n): for v...
from solution import minimize_max_travel_distance def test_example_case(): n = 4 m = 4 roads = [(1, 2, 1), (2, 3, 2), (3, 4, 3), (4, 1, 4)] assert minimize_max_travel_distance(n, m, roads) == 3 def test_case_no_portal_needed(): n = 3 m = 3 roads = [(1, 2, 1), (2, 3, 1), (3, 1, 1)] asse...
[ { "docstring": null, "function_declaration": "def floyd_warshall(n, graph):", "function_name": "floyd_warshall", "parameter_list": "(n, graph)" }, { "docstring": null, "function_declaration": "def minimize_max_travel_distance(n, m, roads):", "function_name": "minimize_max_travel_dist...
[ 0, 0, 0, 0, 0, 0, 0, 1, 0, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def minimize_max_travel_distance(n, m, roads):\n import math\n INF = math.inf\n\n # Initializing distance array\n dist = [[INF] * n for _ in range...
trial_gpt4o_7
{ "original_instruction": "", "prompt_id": "00026526", "row_id": 26526, "seed_ids": "[6424, 3071, 1400]" }
0.750155
Codeforces_26526
I
[ "floyd_warshall", "minimize_max_travel_distance", "main" ]
3
[ [ "minimize_max_travel_distance", "floyd_warshall" ] ]
1
[]
false
[]
false
pytest
true
[]
true
b8399283259d1f17003e1eebb6c0d02945eb6a4b
34a642a0d53881760bfc29f73f225d6ee0211224
v1.0
instruct
Codeforces
Codeforces_26539_I
In a post-apocalyptic world, communication between groups of survivors is crucial for their survival. They communicate via a network of old servers connected in a specific way. The network can be represented as a directed graph where nodes represent servers and edges represent one-way communication channels between the...
from collections import defaultdict, deque def kosaraju_scc(n, edges): def dfs(v): visited[v] = True for neighbour in graph[v]: if not visited[neighbour]: dfs(neighbour) order.append(v) def reverse_dfs(v, component): visited[v] = True compone...
from solution import largest_scc def test_case_1(): n = 6 m = 7 edges = [(1, 2), (2, 3), (3, 1), (3, 4), (4, 5), (5, 6), (6, 4)] size, scc = largest_scc(n, m, edges) assert size == 3 assert sorted(scc) in [sorted([1, 2, 3]), sorted([4, 5, 6])] def test_case_2(): n = 5 m = 5 edges =...
[ { "docstring": null, "function_declaration": "def kosaraju_scc(n, edges):", "function_name": "kosaraju_scc", "parameter_list": "(n, edges)" }, { "docstring": null, "function_declaration": "def largest_scc(n, m, edges):", "function_name": "largest_scc", "parameter_list": "(n, m, e...
[ 1, 0, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "from collections import defaultdict, deque\n\ndef kosaraju_scc(n, edges):\n def dfs(v):\n visited[v] = True\n for neighbour in graph[v]:\n ...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00026539", "row_id": 26539, "seed_ids": "[210, 2755, 1746]" }
0.573681
Codeforces_26539
I
[ "kosaraju_scc", "largest_scc" ]
2
[ [ "largest_scc", "kosaraju_scc" ] ]
1
[]
false
[]
false
pytest
true
[]
true
6b8efd5d1ab12147f36b6d8e1fa2f0f2d08bf811
dcc919fef10e0f01ec31d6cdd4e51473b246d977
v1.0
instruct
Codeforces
Codeforces_26546_I
You are given a weighted, connected, undirected graph with `n` vertices and `m` edges (1 ≤ n ≤ 50, 1 ≤ m ≤ 1250). Each vertex represents a city, and each edge represents a road with a certain toll. During the annual festival, the government wants to ensure that the maximum road toll between any two cities in the same g...
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 root_x != root_y: if rank[root_x] > rank[root_y]: parent[root_y] = root_x elif rank[root_x] < ...
from solution import maximum_possible_minimal_road_toll def test_case_1(): n = 4 m = 5 edges = [ (0, 1, 4), (0, 2, 2), (1, 2, 1), (1, 3, 6), (2, 3, 3) ] assert maximum_possible_minimal_road_toll(n, m, edges) == 3 def test_case_2(): n = 3 m = 3 ed...
[ { "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_maximal_minimal_road_toll(n, m, edges):\n import heapq\n\n parent = list(range(n + 1))\n \n def find(x):\n if parent[x] != x:\n ...
trial_gpt4o_3
{ "original_instruction": "", "prompt_id": "00026546", "row_id": 26546, "seed_ids": "[5755, 4600, 5727]" }
0.687982
Codeforces_26546
I
[ "find", "union", "kruskal", "maximum_possible_minimal_road_toll", "main" ]
5
[ [ "kruskal", "find" ], [ "kruskal", "union" ], [ "maximum_possible_minimal_road_toll", "kruskal" ], [ "union", "find" ] ]
4
[]
false
[]
false
pytest
true
[]
true
1c206c7b003226247f62ffb4c0cc8379a838c033
d73e56bf305f9896242193ebc60faae698648d52
v1.0
instruct
Codeforces
Codeforces_26587_I
You are given a 2D grid with n rows and m columns, where each cell in the grid contains an integer representing either: - The cost of walking through that cell if the integer is positive. - An obstacle (impassable cell) if the integer is -1. You start at the top-left cell (0,0) and want to reach the bottom-right cell ...
import heapq def min_cost_to_reach_bottom_right(grid): n = len(grid) m = len(grid[0]) if grid[0][0] == -1 or grid[n-1][m-1] == -1: return -1 directions = [(1, 0), (0, 1)] # Only right or down directions min_heap = [(grid[0][0], 0, 0)] # (cost, row, col) costs = {(0, 0): grid...
import pytest from solution import process_grids def test_example_case(): num_tests = 2 test_cases = [ (3, 3, [[0, 1, 1], [-1, 1, 1], [1, 1, 1]]), (3, 3, [[0, 1, 1], [1, -1, 1], [1, 1, -1]]) ] assert process_grids(num_tests, test_cases) == [4, -1] def test_all_obstacles(): num_test...
[ { "docstring": null, "function_declaration": "def min_cost_to_reach_bottom_right(grid):", "function_name": "min_cost_to_reach_bottom_right", "parameter_list": "(grid)" }, { "docstring": null, "function_declaration": "def process_grids(num_tests, test_cases):", "function_name": "proce...
[ 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 sys\nimport heapq\n\ndef min_cost_to_reach_end(t, test_sets):\n results = []\n \n for i in range(t):\n n, m = test_sets[i][0]\n ...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00026587", "row_id": 26587, "seed_ids": "[6671, 2863, 649]" }
0.774214
Codeforces_26587
I
[ "min_cost_to_reach_bottom_right", "process_grids" ]
2
[ [ "process_grids", "min_cost_to_reach_bottom_right" ] ]
1
[]
false
[]
false
pytest
true
[]
true
faffb16bbf12cc075c931fb265780bb518065d63
ff76c3efd5f21378149040ec752ee0ca006b0b92
v1.0
instruct
Codeforces
Codeforces_26613_I
King George has recently acquired a new kingdom, and he plans to conduct a census to collect some data. The kingdom is divided into m cities, each city has a uniquely assigned number from 1 to m. There are n one-way roads connecting these cities in such a way that you can reach any city from any other city through some...
from collections import defaultdict, deque def find_scc(m, edges): """ Function to find Strongly Connected Components (SCCs) using Tarjan's algorithm """ index = [0] # Shared counter to assign indices to each node stack = [] indices = [-1] * m lowlinks = [-1] * m on_stack = [False] * ...
from solution import find_min_reachable_city def test_case_1(): m = 6 n = 7 roads = [ (1, 2), (2, 3), (3, 4), (4, 5), (5, 6), (6, 1), (1, 5) ] assert find_min_reachable_city(m, n, roads) == [1, 1, 1, 1, 1, 1] def test_case_2(): m = 3 ...
[ { "docstring": "Function to find Strongly Connected Components (SCCs) using Tarjan's algorithm", "function_declaration": "def find_scc(m, edges):", "function_name": "find_scc", "parameter_list": "(m, edges)" }, { "docstring": null, "function_declaration": "def find_min_reachable_city(m, ...
[ 0, 0, 0, 0, 0, 0, 1, 0, 0, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "from collections import defaultdict, deque\n\ndef find_min_reachable_cities(m, n, roads):\n def dfs(node, id):\n stack = [node]\n while stack...
trial_gpt4o_6
{ "original_instruction": "", "prompt_id": "00026613", "row_id": 26613, "seed_ids": "[2629, 6475, 2740]" }
0.782084
Codeforces_26613
I
[ "find_scc", "find_min_reachable_city" ]
2
[ [ "find_min_reachable_city", "find_scc" ] ]
1
[]
false
[]
false
pytest
true
[]
true
6cc8a939b34160065892068e65656628b05e591d
8f1a88dfc77114f466c4b65537fe7caab572f426
v1.0
instruct
Codeforces
Codeforces_26629_I
A dance competition is taking place and the judges need your help to determine the winners. There are `n` dance pairs competing, and each pair is evaluated by `m` judges. Each judge awards a score between 0 and 100 to each dance pair. To determine the overall score of a pair, the highest and lowest scores given to the ...
def calculate_highest_score(n, m, scores): """ Calculate the highest overall score of dance pairs and their indices. Args: n (int): Number of dance pairs. m (int): Number of judges. scores (list of list of int): Scores given to each pair by each judge. Returns: tuple: Highest o...
from solution import calculate_highest_score, find_winners def test_single_pair(): n = 1 m = 5 scores = [ [78, 82, 85, 88, 90] ] assert calculate_highest_score(n, m, scores) == (85.0, [1]) def test_multiple_pairs(): n = 3 m = 5 scores = [ [78, 82, 85, 88, 90], [...
[ { "docstring": "Calculate the highest overall score of dance pairs and their indices.\n\nArgs:\nn (int): Number of dance pairs.\nm (int): Number of judges.\nscores (list of list of int): Scores given to each pair by each judge.\n\nReturns:\ntuple: Highest overall score and a list of indices of pairs with the hi...
[ 0, 0, 0, 0, 0, 1, 0, 0, 0, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def find_winning_pairs(n, m, scores):\n \"\"\"\n Determine the highest overall score after removing the highest and lowest scores for each pair\n and...
trial_gpt4o_5
{ "original_instruction": "", "prompt_id": "00026629", "row_id": 26629, "seed_ids": "[847, 7642, 7712]" }
0.734809
Codeforces_26629
I
[ "calculate_highest_score", "find_winners" ]
2
[ [ "find_winners", "calculate_highest_score" ] ]
1
[]
false
[]
false
pytest
true
[]
true
774e91f428afe9024116bd7b0176578b9d3d3a83
f6d1bcb42b7e8967facc8ba9cfb12e53a37c16aa
v1.0
instruct
Codeforces
Codeforces_26768_I
In a certain kingdom, there are multiple villages connected by a network of roads. Villages are numbered from 1 to n. Each road connects exactly two villages and has a certain length associated with it. The king wants to build a single central warehouse in one of the villages such that the sum of distances from this wa...
from collections import defaultdict import sys def find_centroid(n, edges): def dfs(node, parent): subtree_size[node] = 1 is_centroid = True for neighbor, weight in graph[node]: if neighbor != parent: dfs(neighbor, node) subtree_size[node] += sub...
from solution import find_optimal_village def test_example(): roads = [(1, 2, 3), (2, 3, 4), (3, 4, 2), (3, 5, 1)] assert find_optimal_village(5, roads) == 3 def test_single_edge(): roads = [(1, 2, 1)] assert find_optimal_village(2, roads) in [1, 2] def test_balanced_tree(): roads = [(1, 2, 1), (...
[ { "docstring": null, "function_declaration": "def find_centroid(n, edges):", "function_name": "find_centroid", "parameter_list": "(n, edges)" }, { "docstring": null, "function_declaration": "def find_optimal_village(n, road_list):", "function_name": "find_optimal_village", "param...
[ 0, 0, 1, 1 ]
2
medium
0.5
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "from collections import deque, defaultdict\n\ndef bfs(start, n, graph):\n distances = [-1] * (n + 1)\n queue = deque([start])\n distances[start] = 0\...
trial_gpt4o_4
{ "original_instruction": "", "prompt_id": "00026768", "row_id": 26768, "seed_ids": "[2990, 981, 2818]" }
0.653293
Codeforces_26768
I
[ "find_centroid", "find_optimal_village" ]
2
[ [ "find_optimal_village", "find_centroid" ] ]
1
[]
false
[]
false
pytest
true
[]
true
5d9d60b8436ae887cb6142f33d7990123e820210
829159708e33972ddb5a00b9fde0acb5b1cc2c5a
v1.0
instruct
Codeforces
Codeforces_26779_I
Tom is organizing a marathon event in his city. He has a certain number of checkpoints in a straight-line track. Each checkpoint has a flag that needs to be colored. Tom has a set of colors and he wants to assign these colors to the flags in such a way that no two adjacent checkpoint flags have the same color. Tom kno...
def color_checkpoints(n, c, positions): if c == 1 and n > 1: return "NO" colors = [0] * n for i in range(n): colors[i] = (i % c) + 1 return f"YES\n{' '.join(map(str, colors))}" def solve_marathon_color_checkpoints(n, c, positions): result = color_checkpoints(n, c, position...
from solution import solve_marathon_color_checkpoints def test_example1(): assert solve_marathon_color_checkpoints(5, 3, [1, 3, 7, 12, 18]) == "YES\n1 2 3 1 2" def test_example2(): assert solve_marathon_color_checkpoints(4, 2, [1, 2, 4, 8]) == "YES\n1 2 1 2" def test_not_possible_with_one_color(): assert...
[ { "docstring": null, "function_declaration": "def color_checkpoints(n, c, positions):", "function_name": "color_checkpoints", "parameter_list": "(n, c, positions)" }, { "docstring": null, "function_declaration": "def solve_marathon_color_checkpoints(n, c, positions):", "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": "def can_color_checkpoints(n, c, positions):\n \"\"\"\n Determines if it is possible to color the checkpoints such that no two\n adjacent checkpoints ...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00026779", "row_id": 26779, "seed_ids": "[3265, 6002, 3130]" }
0.691686
Codeforces_26779
I
[ "color_checkpoints", "solve_marathon_color_checkpoints" ]
2
[ [ "solve_marathon_color_checkpoints", "color_checkpoints" ] ]
1
[]
false
[]
false
pytest
true
[]
true
1f32997fa92bc619adbbe0208e6df8b3350c1407
daaa9077514fa72b1130494957e4bdba84f2946b
v1.0
instruct
Codeforces
Codeforces_26791_I
A secret agency has intercepted some communication between two spies. The communication is in the form of a sequence of characters from 'A' to 'Z' which can be considered as an encrypted message. The agency knows that the message can be decoded using a special method called the "Shift Cipher". In a Shift Cipher, each l...
from typing import List def is_meaningful(seq: str) -> bool: """ Determines if the sequence of characters can be shifted to from 'A' to 'Z' in order one. """ def is_contiguous(word): for i in range(1, len(word)): if ord(word[i]) != ord(word[i-1]) + 1: return False ...
from solution import decode_messages def test_multiple_cases(): assert decode_messages(2, ["DEF", "XYZABC"]) == ["YES", "YES"] def test_single_case_yes(): assert decode_messages(1, ["GHI"]) == ["YES"] def test_single_case_no(): assert decode_messages(1, ["ACD"]) == ["NO"] def test_edge_case_single_chara...
[ { "docstring": "Determines if the sequence of characters can be shifted to from 'A' to 'Z' in order one.", "function_declaration": "def is_meaningful(seq):", "function_name": "is_meaningful", "parameter_list": "(seq)" }, { "docstring": null, "function_declaration": "def decode_messages(t...
[ 0, 0, 0, 0, 0, 1, 0, 0, 1 ]
2
hard
0.222
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_continuous_sequence(word):\n \"\"\"\n Checks if a sequence of characters forms a continuous sequence\n in the alphabet without any repetition....
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00026791", "row_id": 26791, "seed_ids": "[5938, 7681, 8164]" }
0.655935
Codeforces_26791
I
[ "is_meaningful", "decode_messages" ]
2
[ [ "decode_messages", "is_meaningful" ] ]
1
[]
false
[]
false
pytest
true
[]
true
5fff832524fff080d0d058ddf8a582afc6007aa7
2069cd5612f2fa17871057360d3b7fae2b291453
v1.0
instruct
Codeforces
Codeforces_26793_I
Nina likes solving puzzles, and one of her favorite puzzles involves working with arrays. She has an array of integers and she likes rearranging its elements in specific ways to form new arrays. One of her preferences is to create arrays in which the difference between adjacent elements is as large as possible. Task: ...
def max_min_difference(t, cases): results = [] for case in cases: _, array = case array.sort() reordered = [] left = 0 right = len(array) - 1 while left <= right: if left == right: reordered.append(array[left]) ...
def test_max_min_difference(): cases = [ (4, [1, 2, 3, 4]), # Expected output: 1 (5, [10, 20, 30, 40, 50]), # Expected output: 10 (3, [5, 10, 5]), # Expected output: 5 ] expected_results = [1, 10, 5] assert max_min_difference(len(cases), cases) == expected_results def test_ma...
[ { "docstring": null, "function_declaration": "def max_min_difference(t, cases):", "function_name": "max_min_difference", "parameter_list": "(t, cases)" }, { "docstring": null, "function_declaration": "def solve():", "function_name": "solve", "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 maximize_min_difference(t, cases):\n \"\"\"\n This function processes multiple test cases to reorder arrays such that the \n maximum possible val...
trial_gpt4o_4
{ "original_instruction": "", "prompt_id": "00026793", "row_id": 26793, "seed_ids": "[1017, 4447, 5315]" }
0.786146
Codeforces_26793
I
[ "max_min_difference", "solve" ]
2
[ [ "solve", "max_min_difference" ] ]
1
[]
false
[]
false
pytest
false
[]
true
cd3ffcde470710ad234f10f240d03ba3c4be91e0
4c1dc60c5e5286cddf0a73cd9bb02bf017c712bc
v1.0
instruct
Codeforces
Codeforces_26861_I
You are given a grid with m rows and n columns. Each cell in the grid is either empty or contains a barrier. You start from the top-left corner of the grid and want to reach the bottom-right corner. You can move up, down, left, or right, but you cannot move through the barriers. Write a program to find the length of t...
from collections import deque def shortest_path(m, n, grid): """ Returns the length of the shortest path from the top-left corner to the bottom-right corner of the grid. If there is no such path, returns -1. grid is a list of strings representing the grid. """ # Helper function to check if a c...
def test_shortest_path(): m, n = 5, 5 grid = [ ". . # . .", ". # . # .", ". # . # .", ". . . # #", ". # . . ." ] assert solve(m, n, grid) == 8 def test_no_path(): m, n = 3, 3 grid = [ ". # .", "# # #", ". # ." ] assert solv...
[ { "docstring": "Returns the length of the shortest path from the top-left corner to \nthe bottom-right corner of the grid. If there is no such path, returns -1.\ngrid is a list of strings representing the grid.", "function_declaration": "def shortest_path(m, n, grid):", "function_name": "shortest_path",...
[ 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": "from collections import deque\n\ndef shortest_path_length(m, n, grid):\n \"\"\"\n Returns the length of the shortest path from the top-left corner to th...
trial_gpt4o_6
{ "original_instruction": "", "prompt_id": "00026861", "row_id": 26861, "seed_ids": "[7287, 5233, 3775]" }
0.740566
Codeforces_26861
I
[ "shortest_path", "solve" ]
2
[ [ "solve", "shortest_path" ] ]
1
[]
false
[]
false
pytest
false
[]
true
03c10400bb6c44b4d39770cb9d5e271080229bad
9e8351e19ca2e55149f6487f62d72fdf6c1fcf72
v1.0
instruct
Codeforces
Codeforces_26878_I
You are a city planner tasked with designing a new public park. The park consists of a number of flower beds arranged in a grid pattern. Each flower bed can either be empty or contain flowers. The city has specific aesthetic rules for designing these parks. 1. The park should have a rectangular area with flowers. 2....
def max_area_of_flowers(grid): n, m = len(grid), len(grid[0]) max_area = 0 # Initialize a histogram based on the grid histogram = [0] * m for i in range(n): for j in range(m): if grid[i][j] == 'F': histogram[j] += 1 else: histogra...
def test_max_area_of_flowers_example1(): grid = [ list("FFFEE"), list("FFFFE"), list("FFEFF"), list("EEFFF") ] assert max_area_of_flowers(grid) == 6 def test_max_area_of_flowers_example2(): grid = [ list("EEE"), list("EFF"), list("EFF") ] ...
[ { "docstring": null, "function_declaration": "def max_area_of_flowers(grid):", "function_name": "max_area_of_flowers", "parameter_list": "(grid)" }, { "docstring": null, "function_declaration": "def largest_rectangle(hist):", "function_name": "largest_rectangle", "parameter_list"...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def max_flower_bed_area(n, m, grid):\n \"\"\"Find the area of the largest rectangle containing only 'F' cells.\"\"\"\n if n == 0 or m == 0:\n ret...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00026878", "row_id": 26878, "seed_ids": "[3537, 4964, 2691]" }
0.658885
Codeforces_26878
I
[ "max_area_of_flowers", "largest_rectangle" ]
2
[ [ "max_area_of_flowers", "largest_rectangle" ] ]
1
[]
false
[]
false
pytest
false
[]
true
27a1b6d458f84e0372781183af7712a548314adc
f40afc13501d46c4c2ebfc5ed51e7e0afe668fd3
v1.0
instruct
Codeforces
Codeforces_26909_I
Given a binary tree, you need to find the maximum sum of values of any path from the root node to a leaf node. A leaf node is a node that has no children. For example, in the binary tree shown below: ``` 10 / \ 20 30 / \ / \ 40 50 60 70 / 75 ``` The maximum sum path fr...
from typing import List, Optional class TreeNode: def __init__(self, val: Optional[int]): self.val = val self.left = None self.right = None def construct_tree(tree: List[Optional[int]], index: int = 0) -> Optional[TreeNode]: if index < len(tree) and tree[index] is not None: nod...
from solution import max_root_to_leaf_sum def test_example_case(): tree = [10, 20, 30, 40, 50, 60, 70, None, None, 75, None, None, None, None, None] assert max_root_to_leaf_sum(tree) == 155 def test_single_node(): tree = [10] assert max_root_to_leaf_sum(tree) == 10 def test_no_child_nodes(): tree...
[]
[ 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 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_2
{ "original_instruction": "", "prompt_id": "00026909", "row_id": 26909, "seed_ids": "[824, 6690, 3347]" }
0.64909
Codeforces_26909
I
[ "construct_tree", "max_root_to_leaf_sum" ]
2
[ [ "max_root_to_leaf_sum", "construct_tree" ] ]
1
[]
false
[ "TreeNode" ]
true
pytest
true
[]
true
86d61af937a538d23c6745f25c06d45bb8c380db
412b09f5fa7bc0dd67c617d1334dcee7b5bb6d99
v1.0
instruct
Codeforces
Codeforces_27041_I
Given a grid of size n x m filled with integers, you are required to perform a series of operations to make all the integers in the grid the same. In each operation, you can select any subrectangle of the grid and increment each of its elements by 1. You need to determine the minimum number of operations required to ac...
def min_operations_to_make_uniform(grid): """ Returns the minimum number of operations required to make all the integers in the grid the same. """ max_val = max(max(row) for row in grid) min_val = min(min(row) for row in grid) if max_val == min_val: return 0 return max_val ...
from solution import process_grid def test_all_elements_same(): assert process_grid(3, 3, [[3, 3, 3], [3, 3, 3], [3, 3, 3]]) == 0 def test_simple_case(): assert process_grid(2, 3, [[1, 2, 3], [4, 3, 2]]) == 3 def test_single_row(): assert process_grid(1, 5, [[1, 2, 3, 4, 5]]) == 4 def test_single_column...
[ { "docstring": "Returns the minimum number of operations required to make all the integers in the grid the same.", "function_declaration": "def min_operations_to_make_uniform(grid):", "function_name": "min_operations_to_make_uniform", "parameter_list": "(grid)" }, { "docstring": null, "f...
[ 0, 0, 0, 0, 0, 1, 0, 0, 0, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def min_operations_to_equalize_grid(grid):\n \"\"\"\n Determines the minimum number of operations to make all integers in\n the grid the same. You ca...
trial_gpt4o_5
{ "original_instruction": "", "prompt_id": "00027041", "row_id": 27041, "seed_ids": "[1643, 6241, 5042]" }
0.768753
Codeforces_27041
I
[ "min_operations_to_make_uniform", "process_grid" ]
2
[ [ "process_grid", "min_operations_to_make_uniform" ] ]
1
[]
false
[]
false
pytest
true
[]
true
2dc7d64faa7be87190cdbdca34399283bba7e874
6c21e5a35083b4cca11582de49d5fbdcece37c30
v1.0
instruct
Codeforces
Codeforces_27076_I
Maria is interested in prime numbers and their properties. She recently learned about the Sieve of Eratosthenes algorithm to find all prime numbers up to a given integer n. However, she is particularly interested in the k-th prime number within this range. Additionally, she wants to determine the sum of all prime numbe...
def sieve_of_eratosthenes(n): """ Use the Sieve of Eratosthenes to find all prime numbers up to n. """ is_prime = [True] * (n + 1) p = 2 while (p * p <= n): if is_prime[p]: for i in range(p * p, n + 1, p): is_prime[i] = False p += 1 primes = [p fo...
def test_sieve_of_eratosthenes(): assert sieve_of_eratosthenes(10) == [2, 3, 5, 7] assert sieve_of_eratosthenes(20) == [2, 3, 5, 7, 11, 13, 17, 19] assert sieve_of_eratosthenes(30) == [2, 3, 5, 7, 11, 13, 17, 19, 23, 29] def test_kth_prime_and_sum(): assert kth_prime_and_sum(10, 3) == "5 10" assert...
[ { "docstring": "Use the Sieve of Eratosthenes to find all prime numbers up to n.", "function_declaration": "def sieve_of_eratosthenes(n):", "function_name": "sieve_of_eratosthenes", "parameter_list": "(n)" }, { "docstring": "Returns the k-th prime number within the range up to n and the sum ...
[ 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 sieve_of_eratosthenes(limit):\n \"\"\" Perform the Sieve of Eratosthenes algorithm to find all primes up to the given limit. \"\"\"\n is_prime = [Tr...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00027076", "row_id": 27076, "seed_ids": "[3036, 1181, 8083]" }
0.614394
Codeforces_27076
I
[ "sieve_of_eratosthenes", "kth_prime_and_sum", "process_queries" ]
3
[ [ "kth_prime_and_sum", "sieve_of_eratosthenes" ], [ "process_queries", "kth_prime_and_sum" ] ]
2
[ "process_queries" ]
false
[]
false
pytest
false
[]
true
9edf056e0a8db8e2aeba4203c9c446745b4159bd
3bb3a0ced952e39fc90f25beb7833fef25664a8e
v1.0
instruct
Codeforces
Codeforces_27096_I
Ariel is fascinated by palindromes, especially those that can be found in strings. Let's help Ariel with a problem involving checking palindromic properties of substrings. You are given a string `s` consisting of lowercase English letters and a list of `m` queries. Each query is composed of two integers `l` and `r` (1...
def is_palindrome(s, l, r): """ Returns whether the substring s[l:r+1] is a palindrome. """ sub_str = s[l:r+1] return sub_str == sub_str[::-1] def process_queries(n, m, s, queries): results = [] for l, r in queries: if is_palindrome(s, l, r): results.append("YES") ...
from solution import ariel_palindrome def test_ariel_palindrome(): n = 7 m = 3 s = "abacaba" queries = [(0, 6), (2, 4), (1, 2)] assert ariel_palindrome(n, m, s, queries) == ["YES", "YES", "NO"] n = 5 m = 2 s = "abcba" queries = [(0, 4), (1, 3)] assert ariel_palindrome(n, m, s, ...
[ { "docstring": "Returns whether the substring s[l:r+1] is a palindrome.", "function_declaration": "def is_palindrome(s, l, r):", "function_name": "is_palindrome", "parameter_list": "(s, l, r)" }, { "docstring": null, "function_declaration": "def process_queries(n, m, s, queries):", "...
[ 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_palindrome(s, l, r):\n \"\"\"\n Check if the substring s[l:r+1] is a palindrome.\n \n :param s: The original string.\n :param l: The sta...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00027096", "row_id": 27096, "seed_ids": "[5725, 2100, 6460]" }
0.812477
Codeforces_27096
I
[ "is_palindrome", "process_queries", "ariel_palindrome" ]
3
[ [ "ariel_palindrome", "process_queries" ], [ "process_queries", "is_palindrome" ] ]
2
[ "process_queries" ]
false
[]
false
pytest
true
[]
true
94a78a605288fc20fabb55c63795c3828439fbab
9a0464b26bf78e492b42b5db50a3f2f0db339ae6
v1.0
instruct
Codeforces
Codeforces_27188_I
You are given a tree (i.e., a connected, undirected graph with no cycles) with `n` nodes and `n-1` edges. Each edge has an associated positive integer weight. Your task is to find the largest weighted path in the tree, where the weight of a path is defined as the sum of the weights of the edges in that path. The input...
from collections import defaultdict, deque def bfs_farthest_node(tree, start_node): visited = set() queue = deque([(start_node, 0)]) farthest_node, max_distance = start_node, 0 while queue: current_node, current_distance = queue.popleft() visited.add(current_node) ...
from solution import solution def test_single_case(): input_data = "1\n3\n1 2 3\n2 3 4\n" expected_output = "7" assert solution(input_data) == expected_output def test_multiple_cases(): input_data = "2\n3\n1 2 3\n2 3 4\n4\n1 2 1\n2 3 2\n3 4 3\n" expected_output = "7\n6" assert solution(input_d...
[ { "docstring": null, "function_declaration": "def bfs_farthest_node(tree, start_node):", "function_name": "bfs_farthest_node", "parameter_list": "(tree, start_node)" }, { "docstring": null, "function_declaration": "def largest_weighted_path(test_cases):", "function_name": "largest_we...
[ 0, 0, 0, 0, 1, 0, 0, 0, 0 ]
1
hard
0.111
{ "trial_gpt4o_0": null, "trial_gpt4o_1": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared1_results_combined.jsonl", "solution_code": "from collections import defaultdict, deque\n\ndef find_farthest_node(start_node, graph, n):\n # BFS to find the farthest node from...
trial_gpt4o_5
{ "original_instruction": "", "prompt_id": "00027188", "row_id": 27188, "seed_ids": "[5079, 6719, 3521]" }
0.757957
Codeforces_27188
I
[ "bfs_farthest_node", "largest_weighted_path", "parse_input", "solution" ]
4
[ [ "largest_weighted_path", "bfs_farthest_node" ], [ "solution", "largest_weighted_path" ], [ "solution", "parse_input" ] ]
3
[ "parse_input" ]
false
[]
false
pytest
true
[]
true
2542c18c68b02ab2111192f0f7b9840223529c62
7501d05fdd47d2e1624385eae01080ce4af4dd88
v1.0
instruct
Codeforces
Codeforces_27267_I
In a certain country, there is a unique way of determining the capital city every year. The country consists of $$n$$ cities, and the cities are connected by $$n-1$$ bidirectional roads in such a way that each city can be reached from any other city (i.e., they form a tree). Each year, the capital city is chosen based...
from collections import deque def bfs_max_distance(n, graph, start): dist = [-1] * (n + 1) queue = deque([start]) dist[start] = 0 max_dist = 0 while queue: node = queue.popleft() for neighbor in graph[node]: if dist[neighbor] == -1: dist[neighbor] = ...
from solution import find_capital_city def test_example_case(): assert find_capital_city(5, [(1, 2), (1, 3), (2, 4), (2, 5)]) == 1 def test_single_city(): assert find_capital_city(1, []) == 1 def test_chain_structure_1(): assert find_capital_city(4, [(1, 2), (2, 3), (3, 4)]) == 2 def test_chain_structur...
[ { "docstring": null, "function_declaration": "def bfs_max_distance(n, graph, start):", "function_name": "bfs_max_distance", "parameter_list": "(n, graph, start)" }, { "docstring": null, "function_declaration": "def find_capital_city(n, roads):", "function_name": "find_capital_city", ...
[ 0, 0, 0, 1, 1 ]
2
medium
0.4
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "from collections import deque\n\ndef find_capital(n, roads):\n if n == 1:\n return 1\n \n graph = [[] for _ in range(n + 1)]\n for a, b in ...
trial_gpt4o_3
{ "original_instruction": "", "prompt_id": "00027267", "row_id": 27267, "seed_ids": "[3591, 3828, 1727]" }
0.742309
Codeforces_27267
I
[ "bfs_max_distance", "find_capital_city" ]
2
[ [ "find_capital_city", "bfs_max_distance" ] ]
1
[]
false
[]
false
pytest
true
[]
true
4130ec54e47533b0d88d0ccfe08f714acdad4b03
7183c9b5e434854b932f0fc2d39433ff3d605130
v1.0
instruct
Codeforces
Codeforces_27427_I
Alice loves playing board games, and she recently invented a new game called "Maze Escape". The game is played on a rectangular grid with n rows and m columns. Each cell in the grid can either be empty or contain an obstacle. Alice needs to navigate from the top-left corner of the grid to the bottom-right corner. She c...
from collections import deque def min_moves_to_escape(maze, n, m): """ Returns the minimum number of moves required to escape the maze, or -1 if it's not possible. """ if maze[0][0] == '#' or maze[n-1][m-1] == '#': return -1 directions = [(-1, 0), (1, 0), (0, -1), (0, 1)] queue...
def test_min_moves_possible(): input_str = "3 3\n..#\n.#.\n..." assert solve_maze_escape(input_str) == 4 def test_min_moves_impossible(): input_str = "3 3\n###\n###\n###" assert solve_maze_escape(input_str) == -1 def test_min_moves_single_cell(): input_str = "1 1\n." assert solve_maze_escape(i...
[ { "docstring": "Returns the minimum number of moves required to escape the maze,\nor -1 if it's not possible.", "function_declaration": "def min_moves_to_escape(maze, n, m):", "function_name": "min_moves_to_escape", "parameter_list": "(maze, n, m)" }, { "docstring": null, "function_decla...
[ 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 min_moves_to_escape_maze(n, m, grid):\n \"\"\"\n Returns the minimum number of moves required to escape the maze, o...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00027427", "row_id": 27427, "seed_ids": "[5683, 2782, 3893]" }
0.742976
Codeforces_27427
I
[ "min_moves_to_escape", "solve_maze_escape" ]
2
[ [ "solve_maze_escape", "min_moves_to_escape" ] ]
1
[]
false
[]
false
pytest
false
[]
true
239c02737797967ef4584b3596dd5334209aacc7
4d9d0b35eb85fe748a2c97cd8f21e3671d058c2c
v1.0
instruct
Codeforces
Codeforces_27436_I
In a kingdom, there are n cities connected by m bidirectional roads. Each road has a certain length in kilometers. The kingdom has just established a new policy to promote travel between cities more effectively. The policy states that every two cities should have at most one direct road connecting them and all the citi...
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 root_x != root_y: if rank[root_x] > rank[root_y]: parent[root_y] = root_x elif rank[root_x] < ...
def test_road_policy(): # Test case 1 - Already connected and meets policy n = 4 m = 3 roads = [(1, 2, 3), (2, 3, 4), (3, 4, 5)] assert road_policy(n, m, roads) == "YES" # Test case 2 - Not all cities connected, minimal roads needed n = 4 m = 2 roads = [(1, 2, 3), (3, 4, 4)] ...
[ { "docstring": null, "function_declaration": "def find(parent, i):", "function_name": "find", "parameter_list": "(parent, i)" }, { "docstring": null, "function_declaration": "def union(parent, rank, x, y):", "function_name": "union", "parameter_list": "(parent, rank, x, y)" }, ...
[ 0, 0, 0, 0, 0, 0, 0, 0, 1, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def can_travel_all_cities(n, m, roads):\n from collections import defaultdict\n import sys\n sys.setrecursionlimit(10000)\n \n # Create an adja...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00027436", "row_id": 27436, "seed_ids": "[7609, 6263, 2485]" }
0.820684
Codeforces_27436
I
[ "find", "union", "road_policy" ]
3
[ [ "road_policy", "find" ], [ "road_policy", "union" ], [ "union", "find" ] ]
3
[]
false
[]
false
pytest
false
[]
true
d96c9df0f9a75e6a640d950552fb3692d7ab40b1
f00b0b8f74fc535129e2c99a6ca10c92a967e26e
v1.0
instruct
Codeforces
Codeforces_27438_I
In the land of Treeland, there are $$$n$$$ trees forming a connected acyclic graph. Each tree is unique and labeled with an integer from 1 to n. Each tree is directly connected to one or more other trees by an undirected path. The tradition in Treeland is to celebrate in the town square, which must be equidistant from...
from collections import defaultdict, deque def find_farthest_node(n, edges, start): # Perform BFS to find farthest node from the start node queue = deque([(start, 0)]) visited = [False] * (n + 1) visited[start] = True farthest_node = start max_distance = 0 while queue: current,...
from solution import minimum_colors_needed def test_example_case(): n = 6 paths = [(1, 2), (1, 3), (3, 4), (3, 5), (4, 6)] assert minimum_colors_needed(n, paths) == 2 def test_small_case(): n = 2 paths = [(1, 2)] assert minimum_colors_needed(n, paths) == 1 def test_line_graph(): n = 5 ...
[ { "docstring": null, "function_declaration": "def find_farthest_node(n, edges, start):", "function_name": "find_farthest_node", "parameter_list": "(n, edges, start)" }, { "docstring": null, "function_declaration": "def minimum_colors_needed(n, paths):", "function_name": "minimum_colo...
[ 1, 1, 0 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "from collections import defaultdict, deque\n\ndef find_farthest_node(n, edges, start):\n # Perform BFS to find farthest node from the start node\n queue...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00027438", "row_id": 27438, "seed_ids": "[5832, 266, 173]" }
0.618528
Codeforces_27438
I
[ "find_farthest_node", "minimum_colors_needed" ]
2
[ [ "minimum_colors_needed", "find_farthest_node" ] ]
1
[]
false
[]
false
pytest
true
[]
true
a46932d84b9e4280b881b018229870cd58b11ba7
dfe87eecf138e846261c3824128a7a5cf1bc06e8
v1.0
instruct
Codeforces
Codeforces_27445_I
In the kingdom of Logica, there are n cities connected by m bidirectional roads. Each road connects two different cities and has a certain length. The king wants to establish a postal service to ensure that all cities are connected and the total length of the roads used is minimized. In other words, the king needs to b...
def find(parent, i): if parent[i] == i: return i else: parent[i] = find(parent, parent[i]) # path compression 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]: ...
def test_minimum_cost_1(): n = 4 m = 5 roads = [ (1, 2, 5), (2, 3, 10), (3, 4, 3), (4, 1, 2), (1, 3, 12) ] assert minimum_cost_to_connect_all_cities(n, m, roads) == 10 def test_minimum_cost_2(): n = 4 m = 2 roads = [ (1, 2, 5), (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)" }, ...
[ 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": "00027445", "row_id": 27445, "seed_ids": "[7180, 3531, 4734]" }
0.738211
Codeforces_27445
I
[ "find", "union", "kruskal", "minimum_cost_to_connect_all_cities" ]
4
[ [ "kruskal", "find" ], [ "kruskal", "union" ], [ "minimum_cost_to_connect_all_cities", "kruskal" ], [ "union", "find" ] ]
4
[]
false
[]
false
pytest
false
[]
true
bd499b5f1fd5b5f7d8f099e179134b61326698eb
4e8dd80c20b488e4878ed791c0e1f2b62d9998e8
v1.0
instruct
Codeforces
Codeforces_27578_I
Felicity has a grid with n rows and m columns. Each cell in the grid is either walkable (represented by '.') or blocked (represented by '#'). Felicity can move from a walkable cell to any adjacent walkable cell. Two cells are adjacent if they share a side. Felicity starts at position (r1, c1) and wants to reach positi...
def can_reach_destination(grid, n, m, start, end): from collections import deque def is_valid(x, y): return 0 <= x < n and 0 <= y < m and grid[x][y] == '.' directions = [(-1, 0), (1, 0), (0, -1), (0, 1)] r1, c1 = start r2, c2 = end r1 -= 1 c1 -= 1 r2 -= 1 c2 -= 1 queue...
from solution import felicity_reach_destination def test_felicity_reach_destination_example(): n, m = 5, 5 grid = [ ".....", ".###.", ".###.", ".###.", "....." ] r1, c1 = 1, 1 r2, c2 = 5, 5 assert felicity_reach_destination(n, m, grid, r1, c1, r2, c2) == ...
[ { "docstring": null, "function_declaration": "def can_reach_destination(grid, n, m, start, end):", "function_name": "can_reach_destination", "parameter_list": "(grid, n, m, start, end)" }, { "docstring": null, "function_declaration": "def felicity_reach_destination(n, m, grid, r1, c1, r2...
[ 0, 0, 0, 0, 0, 0, 0, 1, 0, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def can_felicity_reach_destination(n, m, grid, start, end):\n from collections import deque\n \n # Directions for possible moves: right, left, down, ...
trial_gpt4o_7
{ "original_instruction": "", "prompt_id": "00027578", "row_id": 27578, "seed_ids": "[98, 5973, 894]" }
0.713246
Codeforces_27578
I
[ "can_reach_destination", "felicity_reach_destination" ]
2
[ [ "felicity_reach_destination", "can_reach_destination" ] ]
1
[]
false
[]
false
pytest
true
[]
true
1d16ce0d278cc30125c9cebc9147bf797bb78b66
d7c18e26644e535dd22f2517c59662d4cee4e870
v1.0
instruct
Codeforces
Codeforces_27593_I
Implement a function that sorts an array of integers in non-increasing order using the merge sort algorithm. Merge sort is a divide-and-conquer algorithm that works as follows: 1. Divide the unsorted array into n subarrays, each containing one element. 2. Repeatedly merge subarrays to produce new sorted subarrays unti...
from typing import List def merge_sort(arr: List[int]) -> List[int]: if len(arr) <= 1: return arr mid = len(arr) // 2 left_half = merge_sort(arr[:mid]) right_half = merge_sort(arr[mid:]) return merge(left_half, right_half) def merge(left: List[int], right: List[int]) -> List[int]: so...
def test_merge_sort_example1(): assert merge_sort([3, 6, 2, 8, 4, 5]) == [8, 6, 5, 4, 3, 2] def test_merge_sort_example2(): assert merge_sort([1, 1, 1, 1, 1]) == [1, 1, 1, 1, 1] def test_merge_sort_example3(): assert merge_sort([9, -3, 5, 0, -1, 2]) == [9, 5, 2, 0, -1, -3] def test_merge_sort_empty(): ...
[ { "docstring": null, "function_declaration": "def merge_sort(arr):", "function_name": "merge_sort", "parameter_list": "(arr)" }, { "docstring": null, "function_declaration": "def merge(left, right):", "function_name": "merge", "parameter_list": "(left, right)" } ]
[ 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 typing import List\n\ndef merge_sort(arr: List[int]) -> List[int]:\n if len(arr) <= 1:\n return arr\n \n mid = len(arr) // 2\n left_ha...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00027593", "row_id": 27593, "seed_ids": "[7838, 3127, 1104]" }
0.674537
Codeforces_27593
I
[ "merge_sort", "merge" ]
2
[ [ "merge_sort", "merge" ] ]
1
[]
false
[]
false
pytest
false
[]
true
545b0cea7c644a201fb8053f6408cfc138ef8a88
07af20e149cd31bae6b39f53708107be41264351
v1.0
instruct
Codeforces
Codeforces_27618_I
You are given an undirected graph with $$$n$$$ nodes and $$$m$$$ edges. Each edge has a weight associated with it. Your task is to determine the minimum spanning tree (MST) of this graph. More specifically, you need to perform multiple queries on this graph where each query asks whether a given edge is part of the MST ...
class UnionFind: def __init__(self, n): self.parent = list(range(n)) self.rank = [0] * n def find(self, u): if self.parent[u] != u: self.parent[u] = self.find(self.parent[u]) return self.parent[u] def union(self, u, v): root_u = self.find(u) root...
from solution import mst_queries def test_example_case(): n = 4 m = 5 edges = [ (1, 2, 1), (1, 3, 4), (2, 3, 2), (2, 4, 5), (3, 4, 3) ] queries = [1, 2, 3, 4] expected_output = ["YES", "NO", "YES", "NO"] assert mst_queries(n, edges, queries) == expect...
[]
[ 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 UnionFind:\n def __init__(self, n):\n self.parent = list(range(n))\n self.rank = [1] * n\n\n def find(self, u):\n if u != sel...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00027618", "row_id": 27618, "seed_ids": "[1103, 3406, 823]" }
0.762615
Codeforces_27618
I
[ "kruskal", "mst_queries" ]
2
[ [ "mst_queries", "kruskal" ] ]
1
[]
false
[ "UnionFind" ]
true
pytest
true
[]
true
3308fda8a2e20bbeabb7a7e9895a71093e3abd56
bd11fa6d8ab9dcff7d27cb6e7e36570cfcf21a22
v1.0
instruct
Codeforces
Codeforces_27667_I
In a faraway kingdom, there is a rectangular farm divided into a grid of M rows and N columns. Each cell in the grid either contains a crop or is empty. Farmers want to build the largest possible rectangular structure on the farm without disturbing any crops. You are appointed to determine the maximum area of such a st...
def maximal_rectangle(matrix): if not matrix: return 0 m, n = len(matrix), len(matrix[0]) # Transform the input matrix to a heights matrix heights = [0] * n max_area = 0 for i in range(m): for j in range(n): if matrix[i][j] == 0: heights[j] += 1 ...
from solution import maximal_rectangle def test_maximal_rectangle_basic(): matrix = [ [1, 0, 0, 0, 0], [0, 0, 1, 0, 0], [0, 0, 0, 0, 0], [1, 0, 0, 0, 1] ] assert maximal_rectangle(matrix) == 6 def test_maximal_rectangle_no_zeros(): matrix = [ [1, 1], [1,...
[ { "docstring": null, "function_declaration": "def maximal_rectangle(matrix):", "function_name": "maximal_rectangle", "parameter_list": "(matrix)" }, { "docstring": null, "function_declaration": "def largest_rectangle_area(heights):", "function_name": "largest_rectangle_area", "pa...
[ 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 maximalRectangle(matrix):\n if not matrix:\n return 0\n\n max_area = 0\n height = [0] * (len(matrix[0]) + 1)\n\n for row in matrix:\n ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00027667", "row_id": 27667, "seed_ids": "[3016, 5844, 8336]" }
0.708406
Codeforces_27667
I
[ "maximal_rectangle", "largest_rectangle_area" ]
2
[ [ "maximal_rectangle", "largest_rectangle_area" ] ]
1
[]
false
[]
false
pytest
true
[]
true
06b5ecbefa68491bccbc57d228bc1c4892f55e6b
05dee0aa84ecb603fd96b862158ccc17f3c3ac35
v1.0
instruct
Codeforces
Codeforces_27680_I
Sherlock Holmes is working on a new case involving a secret message that is hidden within a grid. The message is encoded using a grid of characters, where each cell contains a single lowercase letter ('a' to 'z') and some cells are empty ('.'). To decode the message, Sherlock needs to identify the longest contiguous pa...
def find_longest_word_path(grid, dictionary): n = len(grid) m = len(grid[0]) # Set of words for quick lookup word_set = set(dictionary) # Set of all prefix to quickly check if a prefix exists in dictionary prefix_set = {word[:i] for word in dictionary for i in range(1, len(word) + 1)} ...
from solution import longest_word_in_grid def test_find_longest_word_single_word(): n = 3 m = 4 grid = [ ['a', '.', 't', '.'], ['h', 'e', 'l', 'p'], ['.', 'e', '.', 'r'] ] d = 4 dictionary = ["help", "ale", "her", "tap"] assert longest_word_in_grid(n, m, grid, d, dic...
[ { "docstring": null, "function_declaration": "def find_longest_word_path(grid, dictionary):", "function_name": "find_longest_word_path", "parameter_list": "(grid, dictionary)" }, { "docstring": null, "function_declaration": "def longest_word_in_grid(n, m, grid, d, dictionary):", "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 longest_path_in_grid(n, m, grid, d, dictionary):\n from collections import defaultdict\n \n def dfs(x, y, node, visited, path_length):\n i...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00027680", "row_id": 27680, "seed_ids": "[2237, 7880, 4264]" }
0.659314
Codeforces_27680
I
[ "find_longest_word_path", "longest_word_in_grid" ]
2
[ [ "longest_word_in_grid", "find_longest_word_path" ] ]
1
[]
false
[]
false
pytest
true
[]
true
71fc0de1da1623948273d17d52d5825612c401de
7c6c1af2feac5ac998245f93c8f714656173ef59
v1.0
instruct
Codeforces
Codeforces_27706_I
Given an undirected graph with `n` nodes and initially no edges, you need to perform `q` operations. The operations can be of two types: 1. Add an edge between node `u` and node `v` with weight `w`. 2. Find the shortest path from node `x` to node `y`. The input format is as follows: - The first line contains two int...
import heapq def dijkstra(graph, start): """ Implements Dijkstra's algorithm to find the shortest paths from start node to all other nodes. :param graph: A dictionary where keys are node numbers and values are lists of tuples (neighbor, weight) :param start: The starting node for Dijkstra's algori...
def test_process_operations(): n = 5 operations = [ (1, 1, 2, 4), (1, 2, 3, 1), (1, 4, 5, 3), (2, 1, 3), (1, 1, 3, 2), (2, 1, 3) ] expected_output = [5, 2] assert process_operations(n, operations) == expected_output def test_no_path(): n = 3 o...
[ { "docstring": "Implements Dijkstra's algorithm to find the shortest paths from start node to all other nodes.\n\n:param graph: A dictionary where keys are node numbers and values are lists of tuples (neighbor, weight)\n:param start: The starting node for Dijkstra's algorithm.\n\n:return: A dictionary of shorte...
[ 1, 1, 0 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "import heapq\n\ndef dijkstra(graph, start):\n \"\"\"\n Implements Dijkstra's algorithm to find the shortest paths from start node to all other nodes.\n ...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00027706", "row_id": 27706, "seed_ids": "[4659, 7328, 853]" }
0.702194
Codeforces_27706
I
[ "dijkstra", "process_operations" ]
2
[ [ "process_operations", "dijkstra" ] ]
1
[]
false
[]
false
pytest
false
[]
true
7699dc4ed631efad66c54ba5b6d4ae4ff064342e
6c4e368c7f170b738962bdae8970e8e6ae7a336c
v1.0
instruct
Codeforces
Codeforces_27717_I
You are given an array of n integers a1, a2, ..., an. A pair of indices (i, j) (1 ≤ i < j ≤ n) is called special if it satisfies all of the following conditions: 1. a[i] < a[j] 2. a[i] is a prime number You need to find the number of such special pairs in the array. The first line contains a single integer n (1 ≤ n ...
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 count_special_pairs(arr): count = 0 ...
from solution import is_prime, count_special_pairs def test_is_prime(): assert is_prime(2) == True assert is_prime(3) == True assert is_prime(4) == False assert is_prime(5) == True assert is_prime(1) == False assert is_prime(0) == False def test_count_special_pairs_example1(): arr = [2, 3,...
[ { "docstring": null, "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": null, "function_declaration": "def count_special_pairs(arr):", "function_name": "count_special_pairs", "parameter_list": "(arr)" } ]
[ 0, 1, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def 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_1
{ "original_instruction": "", "prompt_id": "00027717", "row_id": 27717, "seed_ids": "[4826, 3167, 1364]" }
0.684467
Codeforces_27717
I
[ "is_prime", "count_special_pairs" ]
2
[ [ "count_special_pairs", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
a7f16f601bc0fb19d189963cd6a957a24c632a73
e0915b098549397d3a66fda52b62899c7317d31b
v1.0
instruct
Codeforces
Codeforces_27741_I
You're given an undirected graph with $$$n$$$ nodes and $$$m$$$ edges. Your task is to determine the cost of the minimum spanning tree (MST) of this graph. If it's impossible to form an MST (i.e., the graph isn't connected), return -1. The MST is a subset of the edges that connects all the nodes in the graph without a...
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 minimum_spanning_tree def test_example_1(): n = 4 m = 5 edges = [ (1, 2, 1), (1, 3, 1), (1, 4, 1), (2, 3, 1), (3, 4, 1) ] assert minimum_spanning_tree(n, m, edges) == 3 def test_example_2(): n = 4 m = 2 edges = [ (1, ...
[ { "docstring": null, "function_declaration": "def find(parent, i):", "function_name": "find", "parameter_list": "(parent, i)" }, { "docstring": null, "function_declaration": "def union(parent, rank, x, y):", "function_name": "union", "parameter_list": "(parent, rank, x, y)" }, ...
[ 0, 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 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 root_...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00027741", "row_id": 27741, "seed_ids": "[631, 8112, 5914]" }
0.846166
Codeforces_27741
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
840198b3c316a9704a900a764bd3fad13698dfbd
ccf1caa57848a67535b1adeef00c1c06072de2ba
v1.0
instruct
Codeforces
Codeforces_27745_I
A famous artist is creating a new type of artwork using a rectangular grid of colored cells. Each cell can be either black or white. The grid is represented by a matrix of 0s and 1s, where 0 denotes a white cell and 1 denotes a black cell. The artist wants to find the largest rectangular sub-grid that contains only bla...
def largest_black_rect(grid): if not grid: return 0 n = len(grid) m = len(grid[0]) # Initialize a histogram array based on the same number of columns hist = [0] * m max_area = 0 # Update histogram for each row and calculate the maximal rectangle for i in range(n): ...
from solution import largest_black_rect def test_single_cell_black(): grid = [[1]] assert largest_black_rect(grid) == 1 def test_single_cell_white(): grid = [[0]] assert largest_black_rect(grid) == 0 def test_all_black(): grid = [ [1, 1], [1, 1] ] assert largest_black_rect...
[ { "docstring": null, "function_declaration": "def largest_black_rect(grid):", "function_name": "largest_black_rect", "parameter_list": "(grid)" }, { "docstring": null, "function_declaration": "def max_histogram_area(hist):", "function_name": "max_histogram_area", "parameter_list"...
[ 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 largest_rectangle_area(heights):\n \"\"\"\n Helper function to calculate the largest rectangle area in a histogram.\n :param heights: List[int]\n...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00027745", "row_id": 27745, "seed_ids": "[4710, 3921, 5866]" }
0.717646
Codeforces_27745
I
[ "largest_black_rect", "max_histogram_area" ]
2
[ [ "largest_black_rect", "max_histogram_area" ] ]
1
[]
false
[]
false
pytest
true
[]
true
210312225ed73147a3eaee34dfcad19864c499c0
96f0f9f774239618e6b8f3b4f5a541bc9a5d14b9
v1.0
instruct
Codeforces
Codeforces_27778_I
You are given a matrix with `n` rows and `m` columns. Each cell in the matrix contains either a '1' or a '0'. You need to process the matrix to locate the largest submatrix that consists entirely of '1's, then output the area of this largest submatrix. It is guaranteed that the matrix contains at least one '1'. **Inp...
def largest_rectangle_area(heights): stack = [] max_area = 0 index = 0 while index < len(heights): if not stack or heights[stack[-1]] <= heights[index]: stack.append(index) index += 1 else: top_of_stack = stack.pop() area = (heights[to...
from solution import main def test_example_case(): input_data = "4 5\n1 0 1 0 0\n1 0 1 1 1\n1 1 1 1 1\n1 0 0 1 0\n" assert main(input_data) == 6 def test_single_element_1(): input_data = "1 1\n1\n" assert main(input_data) == 1 def test_single_element_0(): input_data = "1 1\n0\n" # The questio...
[ { "docstring": null, "function_declaration": "def largest_rectangle_area(heights):", "function_name": "largest_rectangle_area", "parameter_list": "(heights)" }, { "docstring": null, "function_declaration": "def maximal_rectangle(matrix):", "function_name": "maximal_rectangle", "p...
[ 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 maximalRectangle(matrix):\n if not matrix:\n return 0\n\n n = len(matrix)\n m = len(matrix[0])\n height = [0] * (m + 1)\n max_area =...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00027778", "row_id": 27778, "seed_ids": "[6674, 3818, 4482]" }
0.608914
Codeforces_27778
I
[ "largest_rectangle_area", "maximal_rectangle", "main" ]
3
[ [ "maximal_rectangle", "largest_rectangle_area" ] ]
1
[]
false
[]
false
pytest
true
[]
true
81500b811210db8239ed3a5f0abb216c3bd5b8d8
8fb6c71afa19360e6cf058c4d7bf8d85d2da5404
v1.0
instruct
Codeforces
Codeforces_27796_I
Given an infinite binary string consisting of '0's and '1's, you need to find the length of the longest contiguous subsequence of '1's. The section of the string to analyze is defined by an interval `[l, r]`, where `l` and `r` are non-negative integers representing the positions in the binary string. The binary string ...
import math def generate_binary_string_segment(P, l, r): segment = [] for i in range(l, r + 1): value = math.floor(((i**2) % P) / P) segment.append(value) return segment def longest_contiguous_ones(P, l, r): binary_segment = generate_binary_string_segment(P, l, r) max_count = 0 ...
from solution import generate_binary_string_segment, longest_contiguous_ones def test_generate_binary_string_segment(): assert generate_binary_string_segment(5, 0, 10) == [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] assert generate_binary_string_segment(7, 0, 10) == [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] def test_longest_con...
[ { "docstring": null, "function_declaration": "def generate_binary_string_segment(P, l, r):", "function_name": "generate_binary_string_segment", "parameter_list": "(P, l, r)" }, { "docstring": null, "function_declaration": "def longest_contiguous_ones(P, l, r):", "function_name": "lon...
[ 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 math\n\ndef generate_binary_string_segment(P, l, r):\n segment = []\n for i in range(l, r + 1):\n value = math.floor(((i**2) % P) / P)\n ...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00027796", "row_id": 27796, "seed_ids": "[1936, 6099, 2783]" }
0.63982
Codeforces_27796
I
[ "generate_binary_string_segment", "longest_contiguous_ones" ]
2
[ [ "longest_contiguous_ones", "generate_binary_string_segment" ] ]
1
[]
false
[]
false
pytest
true
[]
true
dfa6c0bad4a692591a89714cbb126e439c6e6132
62204b76ceae0af5c433f2be7631e0904a20cd51
v1.0
instruct
Codeforces
Codeforces_27899_I
You are working on a task to optimize energy distribution in a rising smart city. The city has m power stations connected by n bi-directional transmission lines, each with a specific capacity. Each power station may supply or consume energy, resulting in a net demand (positive for consumption and negative for supply). ...
from collections import defaultdict, deque def bfs_capacity(graph, capacity, source, sink, parent): visited = set() queue = deque([source]) visited.add(source) while queue: u = queue.popleft() for v in graph[u]: if v not in visited and capacity[u][v] > 0: ...
from solution import max_energy_transport def test_case_1(): m, n = 4, 4 demands = [-5, 5, -5, 5] edges = [(0, 1, 5), (1, 2, 5), (2, 3, 5), (0, 3, 5)] assert max_energy_transport(m, n, demands, edges) == 10 def test_case_2(): m, n = 4, 5 demands = [-10, 10, -10, 10] edges = [(0, 1, 15), (...
[ { "docstring": null, "function_declaration": "def bfs_capacity(graph, capacity, source, sink, parent):", "function_name": "bfs_capacity", "parameter_list": "(graph, capacity, source, sink, parent)" }, { "docstring": null, "function_declaration": "def edmonds_karp(graph, capacity, source,...
[ 0, 0, 0, 0, 1 ]
1
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "import networkx as nx\n\ndef max_energy_transport(m, n, demands, transmission_lines):\n \"\"\"\n Determines the maximum amount of energy that can be tra...
trial_gpt4o_4
{ "original_instruction": "", "prompt_id": "00027899", "row_id": 27899, "seed_ids": "[4074, 3779, 6789]" }
0.600829
Codeforces_27899
I
[ "bfs_capacity", "edmonds_karp", "max_energy_transport" ]
3
[ [ "edmonds_karp", "bfs_capacity" ], [ "max_energy_transport", "edmonds_karp" ] ]
2
[]
false
[]
false
pytest
true
[]
true
d9326b200ab6b5284ee6c577c75d6abf684873b4
37046f951febc87d35f54a2637519c6676ae5d28
v1.0
instruct
Codeforces
Codeforces_27937_I
Alyona loves playing with numbers. She has recently learned about prime numbers and now she is very keen on them. For her, a positive integer x is prime if it has no positive integer divisors other than 1 and itself. She starts to wonder about the sums of these prime numbers. Given two integers l and r, she wants to kn...
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 sum_...
from solution import is_prime, sum_of_primes def test_is_prime(): assert is_prime(2) == True assert is_prime(3) == True assert is_prime(4) == False assert is_prime(17) == True assert is_prime(18) == False assert is_prime(19) == True assert is_prime(20) == False def test_sum_of_primes(): ...
[ { "docstring": "Check if a number is prime.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Return the sum of all prime numbers in the range [l, r].", "function_declaration": "def sum_of_primes(l, r):", "function_n...
[ 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(n):\n \"\"\"Check if a number is prime.\"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return True\n if n % 2 == 0 or...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00027937", "row_id": 27937, "seed_ids": "[5588, 6510, 3677]" }
0.62797
Codeforces_27937
I
[ "is_prime", "sum_of_primes" ]
2
[ [ "sum_of_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
b586106cdc4f1bbfaf2762b9fb39b38447997030
0a623bd4fd2161fd0acd7096d1bc4089caf51ef4
v1.0
instruct
Codeforces
Codeforces_27942_I
In an ancient kingdom, there are n towns connected by m bidirectional roads. Each road has a certain time delay to travel between the two towns it connects. The king wants to establish a new capital in one of the towns. He wants to choose a town such that the maximum travel time from this capital to any other town is m...
import heapq def dijkstra(n, graph, start): dist = [float('inf')] * (n + 1) dist[start] = 0 heap = [(0, start)] while heap: current_dist, u = heapq.heappop(heap) if current_dist > dist[u]: continue for v, length in graph[u]: distance = current_dist + leng...
from solution import min_max_travel_time def test_example(): n, m = 4, 4 roads = [(1, 2, 5), (2, 3, 10), (3, 4, 5), (1, 4, 20)] assert min_max_travel_time(n, roads) == 15 def test_two_towns(): n, m = 2, 1 roads = [(1, 2, 1)] assert min_max_travel_time(n, roads) == 1 def test_disconnected_grap...
[ { "docstring": null, "function_declaration": "def dijkstra(n, graph, start):", "function_name": "dijkstra", "parameter_list": "(n, graph, start)" }, { "docstring": null, "function_declaration": "def min_max_travel_time(n, roads):", "function_name": "min_max_travel_time", "paramet...
[ 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_new_capital(n, m, roads):\n inf = float('inf')\n distance = [[inf] * n for _ in range(n)]\n \n for i in range(n):\n distance[i][i]...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00027942", "row_id": 27942, "seed_ids": "[2018, 2773, 6342]" }
0.704654
Codeforces_27942
I
[ "dijkstra", "min_max_travel_time" ]
2
[ [ "min_max_travel_time", "dijkstra" ] ]
1
[]
false
[]
false
pytest
true
[]
true
216a21b84037f462721268021de3aabfa2d92eb6
3953b5ee93cfd78230100b17c4bbcd882729b789
v1.0
instruct
Codeforces
Codeforces_27950_I
Sophia loves gardening and has a beautiful garden with paths laid out in a grid. Each cell in the grid can either contain a plant or be empty. The grid is represented as an `n x m` matrix where each cell contains either a 0 (empty) or a 1 (plant). Sophia wants to water her plants, but she can only water them in rectang...
def max_area_of_plant_section(n, m, grid): if not grid: return 0 max_area = 0 heights = [0] * m for row in grid: for i in range(m): if row[i] == 0: heights[i] = 0 else: heights[i] += 1 max_area = max(max_area, lar...
from solution import max_area_of_plant_section def test_max_area_small_grid(): assert max_area_of_plant_section(4, 5, [ [1, 0, 1, 0, 0], [1, 0, 1, 1, 1], [1, 1, 1, 1, 1], [1, 0, 0, 1, 0] ]) == 6 def test_max_area_entire_grid(): assert max_area_of_plant_section(3, 3, [ ...
[ { "docstring": null, "function_declaration": "def max_area_of_plant_section(n, m, grid):", "function_name": "max_area_of_plant_section", "parameter_list": "(n, m, grid)" }, { "docstring": null, "function_declaration": "def largest_rectangle_area(heights):", "function_name": "largest_...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def max_rect_area(matrix):\n if not matrix or not matrix[0]:\n return 0\n\n max_area = 0\n n, m = len(matrix), len(matrix[0])\n heights = [...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00027950", "row_id": 27950, "seed_ids": "[5443, 6176, 292]" }
0.666996
Codeforces_27950
I
[ "max_area_of_plant_section", "largest_rectangle_area" ]
2
[ [ "max_area_of_plant_section", "largest_rectangle_area" ] ]
1
[]
false
[]
false
pytest
true
[]
true
89424878886f232929380212f322d35546f0e9d1
7b83ec577129f20444dc740c1b44bfba75d8df72
v1.0
instruct
Codeforces
Codeforces_28003_I
Monica loves prime numbers and has recently learned about the Goldbach Conjecture. According to the conjecture, every even number greater than 2 can be expressed as the sum of two prime numbers. As practice, Monica wants to write a program that, given an even number, finds two prime numbers that sum up to the given nu...
def sieve_of_eratosthenes(max_num): """ Generates a list of prime numbers up to max_num using the Sieve of Eratosthenes algorithm. """ is_prime = [True] * (max_num + 1) is_prime[0] = is_prime[1] = False # 0 and 1 are not prime numbers for start in range(2, int(max_num**0.5) + 1): i...
from solution import main def test_example_case(): pair = main(10) assert pair in [(3, 7), (7, 3)] def test_small_even_number(): pair = main(4) assert pair == (2, 2) def test_medium_even_number(): pair = main(28) assert pair in [(5, 23), (23, 5), (11, 17), (17, 11)] def test_large_even_numbe...
[ { "docstring": "Generates a list of prime numbers up to max_num using the Sieve of Eratosthenes algorithm.", "function_declaration": "def sieve_of_eratosthenes(max_num):", "function_name": "sieve_of_eratosthenes", "parameter_list": "(max_num)" }, { "docstring": "Finds and returns a pair of p...
[ 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 sieve_of_eratosthenes(max_num):\n \"\"\"\n Generates a list of prime numbers up to max_num using the Sieve of Eratosthenes algorithm.\n \"\"\"\n ...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00028003", "row_id": 28003, "seed_ids": "[5737, 1080, 222]" }
0.691711
Codeforces_28003
I
[ "sieve_of_eratosthenes", "find_prime_pair", "main" ]
3
[ [ "find_prime_pair", "sieve_of_eratosthenes" ] ]
1
[]
false
[]
false
pytest
true
[]
true
71d6a624db60bcbcf573dc1505307e8f6fe3b9d3
d50676651afc64a4d0c01e2b793e20b222e7a340