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_5268_I
A string is considered beautiful if it can be made a palindrome by removing at most one character. A palindrome is a string that reads the same forward and backward. Your task is to determine whether a given string is beautiful or not. - Input: A single line containing a string $$$s$$$ ($$$1 \le |s| \le 10^5$$$) cons...
def is_beautiful(s): """ Determine if the string can be made a palindrome by removing at most one character. """ def is_palindrome_range(start, end): while start < end: if s[start] != s[end]: return False start += 1 end -= 1 return True...
from solution import beautiful_string def test_beautiful_string_yes_cases(): assert beautiful_string("abca") == "YES" # removing 'c' assert beautiful_string("radar") == "YES" # already palindrome assert beautiful_string("racecar") == "YES" # already palindrome assert beautiful_string("abccbaa") == "...
[ { "docstring": "Determine if the string can be made a palindrome by removing at most one character.", "function_declaration": "def is_beautiful(s):", "function_name": "is_beautiful", "parameter_list": "(s)" }, { "docstring": "Returns \"YES\" if the string is beautiful, otherwise \"NO\".", ...
[ 0, 0, 1, 0, 0, 0, 0, 0 ]
1
hard
0.125
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_beautiful(s):\n \"\"\"\n Returns \"YES\" if the string can be made a palindrome by removing at most one character, otherwise \"NO\".\n \"\"\"\...
trial_gpt4o_3
{ "original_instruction": "", "prompt_id": "00005268", "row_id": 5268, "seed_ids": "[7465]" }
0.700627
Codeforces_5268
I
[ "is_beautiful", "beautiful_string" ]
2
[ [ "beautiful_string", "is_beautiful" ] ]
1
[]
false
[]
false
pytest
true
[]
true
9433bc64e737ceebfdd7c917d9ed6a9de50629ec
7b28b9ae15495ca1f93327b5e9e506b569606595
v1.0
instruct
Codeforces
Codeforces_5271_I
A company is hosting a competition where participants are required to solve a unique puzzle. The puzzle involves a grid of size $$$N \times N$$$, filled with non-negative integers. Participants need to determine the highest value that can be obtained by summing a contiguous subgrid within the original grid. You are gi...
def find_max_subgrid_sum(grid, N): def max_sum_subarray(arr): max_sum = arr[0] curr_sum = arr[0] for i in range(1, len(arr)): curr_sum = max(arr[i], curr_sum + arr[i]) max_sum = max(max_sum, curr_sum) return max_sum max_sum = float('-inf') for le...
from solution import max_contiguous_subgrid_sum def test_example_case(): N = 4 grid = [ [1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12], [13, 14, 15, 16] ] assert max_contiguous_subgrid_sum(N, grid) == 136 def test_single_element_grid(): N = 1 grid = [[42]] asse...
[ { "docstring": null, "function_declaration": "def find_max_subgrid_sum(grid, N):", "function_name": "find_max_subgrid_sum", "parameter_list": "(grid, N)" }, { "docstring": null, "function_declaration": "def max_contiguous_subgrid_sum(N, grid):", "function_name": "max_contiguous_subgr...
[ 0, 0, 1, 0, 0, 0, 1, 1, 0, 0 ]
3
hard
0.3
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def max_sum_subgrid(N, grid):\n \"\"\"\n Returns the maximum sum of any contiguous subgrid in the given N x N grid.\n \"\"\"\n max_sum = float('-i...
trial_gpt4o_6
{ "original_instruction": "", "prompt_id": "00005271", "row_id": 5271, "seed_ids": "[7207]" }
0.665808
Codeforces_5271
I
[ "find_max_subgrid_sum", "max_contiguous_subgrid_sum" ]
2
[ [ "max_contiguous_subgrid_sum", "find_max_subgrid_sum" ] ]
1
[]
false
[]
false
pytest
true
[]
true
b7558ca056cad459b5391144eed5f49a901f9606
7f5b600695f639362d3fd9f6825c589458ae5cd0
v1.0
instruct
Codeforces
Codeforces_5287_I
In a distant galaxy, there exists a planet called Numera where the inhabitants have a peculiar way of managing work assignments. They believe in minimizing the maximum workload any individual has to bear. Here's the scenario on Numera: There are `n` workers and `m` tasks. Each task `j` (1 ≤ j ≤ m) has a certain diffic...
def is_valid_distribution(difficulties, n, max_workload): """ Check if it is possible to distribute tasks such that no worker has a workload exceeding max_workload """ current_sum = 0 workers_needed = 1 for task in difficulties: if current_sum + task > max_workload: work...
def test_minimize_maximum_workload_example(): assert minimize_maximum_workload(3, 5, [10, 20, 30, 40, 50]) == 60 def test_minimize_maximum_workload_single_worker(): assert minimize_maximum_workload(1, 4, [10, 20, 30, 40]) == 100 def test_minimize_maximum_workload_equal_tasks(): assert minimize_maximum_wor...
[ { "docstring": "Check if it is possible to distribute tasks such that no worker has a workload exceeding max_workload", "function_declaration": "def is_valid_distribution(difficulties, n, max_workload):", "function_name": "is_valid_distribution", "parameter_list": "(difficulties, n, max_workload)" ...
[ 1, 1, 1, 0, 1, 0, 1, 0, 0, 1 ]
6
medium
0.6
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def minimize_max_workload(n, m, difficulties):\n def can_distribute(max_workload):\n # Helper function to determine if we can distribute tasks \n ...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00005287", "row_id": 5287, "seed_ids": "[6130]" }
0.655792
Codeforces_5287
I
[ "is_valid_distribution", "minimize_maximum_workload" ]
2
[ [ "minimize_maximum_workload", "is_valid_distribution" ] ]
1
[]
false
[]
false
pytest
false
[]
true
0a8f1a6208846641f77c77c37c15bfb310008e15
e037bea7ce2d28879b398dfbf0491c5b32054d50
v1.0
instruct
Codeforces
Codeforces_5297_I
In the bustling city of Kanto, there's a dedicated team of researchers studying the behavior of Squirtles when they are arranged in a connected sequence of water tanks. To understand the dynamics, the team has built a series of operations to determine the water flow through these tanks. Initially, there are exactly $$...
def max_subarray_sum(w): max_current = max_global = w[0] for i in range(1, len(w)): max_current = max(w[i], max_current + w[i]) if max_current > max_global: max_global = max_current return max_global def max_powers(w, queries): result = [max_subarray_sum(w[:])] for ...
from solution import max_subarray_sum, max_powers, kanto_water_flow def test_max_subarray_sum(): assert max_subarray_sum([5, 3, 8, 6, 1]) == 23 assert max_subarray_sum([2, 5, 1, 7]) == 15 assert max_subarray_sum([1, 3, 2, 5, 4, 6]) == 21 def test_max_powers(): assert max_powers([5, 3, 8, 6, 1], [(2, 3...
[ { "docstring": null, "function_declaration": "def max_subarray_sum(w):", "function_name": "max_subarray_sum", "parameter_list": "(w)" }, { "docstring": null, "function_declaration": "def max_powers(w, queries):", "function_name": "max_powers", "parameter_list": "(w, queries)" }...
[ 0, 0, 0, 0, 0, 0, 0, 0, 1, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def max_subarray_sum(arr):\n max_ending_here = max_so_far = arr[0]\n for x in arr[1:]:\n max_ending_here = max(x, max_ending_here + x)\n m...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00005297", "row_id": 5297, "seed_ids": "[3408]" }
0.616577
Codeforces_5297
I
[ "max_subarray_sum", "max_powers", "kanto_water_flow" ]
3
[ [ "kanto_water_flow", "max_powers" ], [ "max_powers", "max_subarray_sum" ] ]
2
[]
false
[]
false
pytest
true
[]
true
42a7b6a1f269c391f164a72f63a613e54d8ff5b9
29c2651153401dc7a5e0c1bd1b9b7b7b0de43f86
v1.0
instruct
Codeforces
Codeforces_5311_I
You are given a list of integers. Write a function `find_subarray_with_max_sum` that finds a contiguous subarray with the largest sum, and returns this sum. Consider the case where the list can contain both positive and negative integers. For example, given the array: [-2, -3, 4, -1, -2, 1, 5, -3], the contiguous sub...
def find_subarray_with_max_sum(arr): """ Finds and returns the sum of the contiguous subarray with the largest sum. Parameters: arr (list): A list of integers. Returns: int: The maximum sum of the contiguous subarray. """ max_end_here = max_so_far = arr[0] for num in arr[1:]: ...
from solution import find_subarray_with_max_sum, process_input_and_find_max_sum def test_single_element(): assert find_subarray_with_max_sum([1]) == 1 assert find_subarray_with_max_sum([-1]) == -1 def test_all_negative(): assert find_subarray_with_max_sum([-2, -3, -4, -1]) == -1 def test_mixed_elements()...
[ { "docstring": "Finds and returns the sum of the contiguous subarray with the largest sum.\n\nParameters:\narr (list): A list of integers.\n\nReturns:\nint: The maximum sum of the contiguous subarray.", "function_declaration": "def find_subarray_with_max_sum(arr):", "function_name": "find_subarray_with_...
[ 0, 1, 0, 1, 0, 0, 1, 1, 0, 1 ]
5
medium
0.5
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def find_subarray_with_max_sum(array):\n \"\"\"\n Finds the sum of the contiguous subarray within a one-dimensional numeric list\n which has the larg...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00005311", "row_id": 5311, "seed_ids": "[832]" }
0.821098
Codeforces_5311
I
[ "find_subarray_with_max_sum", "process_input_and_find_max_sum" ]
2
[ [ "process_input_and_find_max_sum", "find_subarray_with_max_sum" ] ]
1
[]
false
[]
false
pytest
true
[]
true
f8ab31e597e5e91ed5e92caefdcde65e2413f12f
14fbc269bd262e86eb3c560b419791744b61edd0
v1.0
instruct
Codeforces
Codeforces_5323_I
There is a river that runs through a city, connecting various neighborhoods. The city administration wants to build new bridges across the river to improve connectivity between neighborhoods. Each bridge connects two different neighborhoods and has a cost associated with it. The goal is to determine the minimum total c...
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...
def test_min_cost_to_connect_neighborhoods(): N = 4 M = 5 bridges = [ (1, 2, 1), (1, 3, 2), (1, 4, 3), (2, 3, 1), (3, 4, 4) ] total_cost, result = min_cost_to_connect_neighborhoods(N, M, bridges) assert total_cost == 4 assert sorted(result) == sorted([...
[ { "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, 1, 0, 0, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def find(parent, i):\n if parent[i] == i:\n return i\n else:\n parent[i] = find(parent, parent[i])\n return parent[i]\n\ndef union(...
trial_gpt4o_6
{ "original_instruction": "", "prompt_id": "00005323", "row_id": 5323, "seed_ids": "[5361]" }
0.723439
Codeforces_5323
I
[ "find", "union", "min_cost_to_connect_neighborhoods", "main" ]
4
[ [ "min_cost_to_connect_neighborhoods", "find" ], [ "min_cost_to_connect_neighborhoods", "union" ], [ "union", "find" ] ]
3
[]
false
[]
false
pytest
false
[]
true
09cee642cd1e37e1602233fffc73f22132558dc4
4ab0565957a28c15a0e107b6ff7a5d4340e411ec
v1.0
instruct
Codeforces
Codeforces_5327_I
In a rectangular grid of size $$$n \times m$$$, you are given a robot starting at the top-left corner (1, 1). The robot is tasked to reach the bottom-right corner (n, m). The robot can only move either to the right or down at any point in time. Along the way, there are certain cells in the grid that are blocked and the...
MOD = 10**9 + 7 def num_paths(grid, n, m): if grid[0][0] == '#': return 0 dp = [[0] * m for _ in range(n)] dp[0][0] = 1 for i in range(n): for j in range(m): if grid[i][j] == '#': dp[i][j] = 0 else: if i > 0: ...
from solution import read_input_and_solve def test_example_1(): input_string = '''3 3 ... .#. ...''' assert read_input_and_solve(input_string) == 2 def test_no_path(): input_string = '''3 3 ### ### ###''' assert read_input_and_solve(input_string) == 0 def test_single_row(): input_string = '''1 3 ...
[ { "docstring": null, "function_declaration": "def num_paths(grid, n, m):", "function_name": "num_paths", "parameter_list": "(grid, n, m)" }, { "docstring": null, "function_declaration": "def read_input_and_solve(input_string):", "function_name": "read_input_and_solve", "parameter...
[ 1, 1, 1, 0, 0, 0, 1, 0, 1, 0 ]
5
medium
0.5
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "MOD = 10**9 + 7\n\ndef count_paths(n, m, grid):\n dp = [[0] * m for _ in range(n)]\n \n if grid[0][0] == '#':\n return 0\n\n dp[0][0] = 1\n...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00005327", "row_id": 5327, "seed_ids": "[4567]" }
0.780238
Codeforces_5327
I
[ "num_paths", "read_input_and_solve" ]
2
[ [ "read_input_and_solve", "num_paths" ] ]
1
[]
false
[]
false
pytest
true
[]
true
1114b3ae6a4668bc632267a17198d5d7f7ee460e
ded2c4791025daf58259c296dd0eadbcb6f56025
v1.0
instruct
Codeforces
Codeforces_5344_I
You are given an n x m grid representing a map of the town. Each cell in the grid is either land ('L') or water ('W'). You need to find the largest rectangle containing only land cells ('L') in the grid and return its area. The first line contains two integers n and m (1 ≤ n, m ≤ 1000). The next n lines each contain ...
def max_histogram_area(heights): """ Calculate maximum rectangle area in a histogram with these heights. """ stack = [] max_area = 0 index = 0 while index < len(heights): if not stack or heights[index] >= heights[stack[-1]]: stack.append(index) index += 1...
from solution import maximal_rectangle def test_single_land_cell(): grid = ['L'] assert maximal_rectangle(grid) == 1 def test_single_water_cell(): grid = ['W'] assert maximal_rectangle(grid) == 0 def test_mixed_small_grid(): grid = [ 'LLW', 'LLW', 'WWW' ] assert ma...
[ { "docstring": "Calculate maximum rectangle area in a histogram with these heights.", "function_declaration": "def max_histogram_area(heights):", "function_name": "max_histogram_area", "parameter_list": "(heights)" }, { "docstring": "Calculate the maximal rectangle of land in the given grid....
[ 0, 1, 0, 1, 1, 1, 1, 0, 1, 0 ]
6
medium
0.6
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def max_histogram_area(heights):\n stack = []\n max_area = 0\n index = 0\n \n while index < len(heights):\n if not stack or heights[inde...
trial_gpt4o_6
{ "original_instruction": "", "prompt_id": "00005344", "row_id": 5344, "seed_ids": "[3743]" }
0.665105
Codeforces_5344
I
[ "max_histogram_area", "maximal_rectangle" ]
2
[ [ "maximal_rectangle", "max_histogram_area" ] ]
1
[]
false
[]
false
pytest
true
[]
true
d1b16ae75858127fc9244c4b03ca00378e60e6ca
c0257b98f8bc0c831c64e1526551a3907d072c35
v1.0
instruct
Codeforces
Codeforces_5349_I
Aria and Ben play a new game with a string of lowercase English letters. They move in turns, with Aria starting first. In each move, a player must choose a non-empty substring such that the number of distinct characters in this substring is a prime number, and remove it from the string. The remaining parts of the strin...
def is_prime(num): """ Helper function to check if a given number is prime. """ if num <= 1: return False if num == 2: return True if num % 2 == 0: return False for i in range(3, int(num**0.5) + 1, 2): if num % i == 0: return False return True ...
from solution import aria_vs_ben def test_aria_wins_immediately(): assert aria_vs_ben(5, "abaca") == "Aria" assert aria_vs_ben(6, "abcdef") == "Aria" def test_aria_no_prime_move(): assert aria_vs_ben(3, "aaa") == "Ben" assert aria_vs_ben(5, "aaaaa") == "Ben" def test_ben_has_a_chance(): # Assumes...
[ { "docstring": "Helper function to check if a given number is prime.", "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": "Helper function to count the number of distinct characters in a string.", "function_declaration":...
[ 0, 0, 0, 0, 0, 0, 0, 0, 1, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(num):\n \"\"\"\n Helper function to check if a number is prime.\n \"\"\"\n if num <= 1:\n return False\n if num <= 3:\n ...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00005349", "row_id": 5349, "seed_ids": "[856]" }
0.779975
Codeforces_5349
I
[ "is_prime", "get_distinct_counts", "can_make_move", "aria_vs_ben" ]
4
[ [ "aria_vs_ben", "can_make_move" ], [ "can_make_move", "get_distinct_counts" ], [ "can_make_move", "is_prime" ] ]
3
[]
false
[]
false
pytest
true
[]
true
213c241ffecb74715ad22f524619667b266c276c
6132c3a00b63c8e7b52997b8d8aec1f08ef219e8
v1.0
instruct
Codeforces
Codeforces_5368_I
You are given a string S of length n and an integer k. The string consists of lowercase alphabets only. You need to perform q operations on the string, which can be of two types: 1. Replace the substring starting from position l and ending at position r with its k-th lexicographic permutation. 2. Query the number of d...
from itertools import permutations def kth_lexicographic_permutation(string, k): """ Returns the k-th lexicographic permutation of given string. """ perm = sorted(''.join(p) for p in permutations(string)) return perm[k-1] def distinct_substrings_of_length_k(s, k): """ Returns the number of...
def test_kth_lexicographic_permutation(): assert kth_lexicographic_permutation('abc', 2) == 'acb' assert kth_lexicographic_permutation('abcd', 1) == 'abcd' assert kth_lexicographic_permutation('abcd', 24) == 'dcba' def test_distinct_substrings_of_length_k(): assert distinct_substrings_of_length_k('abca...
[ { "docstring": "Returns the k-th lexicographic permutation of given string.", "function_declaration": "def kth_lexicographic_permutation(string, k):", "function_name": "kth_lexicographic_permutation", "parameter_list": "(string, k)" }, { "docstring": "Returns the number of distinct substring...
[ 1, 0, 0, 0, 0, 0, 0, 0, 0 ]
1
hard
0.111
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "from itertools import permutations\n\ndef kth_lexicographic_permutation(string, k):\n \"\"\"\n Returns the k-th lexicographic permutation of given strin...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00005368", "row_id": 5368, "seed_ids": "[835]" }
0.838889
Codeforces_5368
I
[ "kth_lexicographic_permutation", "distinct_substrings_of_length_k", "process_operations" ]
3
[ [ "process_operations", "distinct_substrings_of_length_k" ], [ "process_operations", "kth_lexicographic_permutation" ] ]
2
[]
false
[]
false
pytest
false
[]
true
41f3c0e943d16da478870c02409459af9d6f2c33
d68eca9b61f771788344d6169c45b672d54705ca
v1.0
instruct
Codeforces
Codeforces_5372_I
To help a mechanical arm navigate a grid, you need to write a program that determines the minimum number of moves required to traverse from the top-left corner to the bottom-right corner of the grid. The arm can only move right or down, and certain cells are blocked and cannot be traversed. The first line of input con...
from collections import deque def min_moves(grid): """ Returns the minimum number of moves required to traverse from the top-left corner to the bottom-right corner of the grid. If it is impossible, return "impossible". """ m, n = len(grid), len(grid[0]) if grid[0][0] == 'X' or grid[m-1][n-1] ==...
from solution import min_moves_from_input def test_min_moves_sample_1(): input_str = "3 3\n...\n.X.\n..." assert min_moves_from_input(input_str) == 4 def test_min_moves_sample_2(): input_str = "2 2\n.X\nX." assert min_moves_from_input(input_str) == "impossible" def test_min_moves_single_cell(): i...
[ { "docstring": "Returns the minimum number of moves required to traverse from the top-left corner to the bottom-right corner of the grid.\nIf it is impossible, return \"impossible\".", "function_declaration": "def min_moves(grid):", "function_name": "min_moves", "parameter_list": "(grid)" }, { ...
[ 0, 0, 0, 0, 1, 1, 0, 0, 1, 0 ]
3
hard
0.3
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "from collections import deque\n\ndef minimum_moves(m, n, grid):\n \"\"\"\n Returns the minimum number of moves required to traverse from the\n top-le...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00005372", "row_id": 5372, "seed_ids": "[2890]" }
0.729598
Codeforces_5372
I
[ "min_moves", "parse_input", "min_moves_from_input" ]
3
[ [ "min_moves_from_input", "min_moves" ], [ "min_moves_from_input", "parse_input" ] ]
2
[ "parse_input" ]
false
[]
false
pytest
true
[]
true
ff1e2732a20f98060da2cbd744158bcdc17164b2
064b7486169bfa390e802053c236dced3fcfea4b
v1.0
instruct
Codeforces
Codeforces_5394_I
Let $$$N=\{1,2,3,4,5\}$$$ be a set with $$$5$$$ elements. Determine the number of bijective functions $$$g: N \to N$$$ such that there are no elements $$$a \in N$$$ for which $$$g(a) = a$$$ and $$$g(g(a)) = a$$$. Note: A function $$$g: A \to B$$$ is called bijective if it is both injective (one-to-one) and surjective ...
from math import factorial def subfactorial(n): """ Compute the subfactorial (derangement) of a number n. !n = n! * sum((-1)^i / i! for i in range(n+1)) """ return round(factorial(n) * sum((-1)**i / factorial(i) for i in range(n + 1))) # Specific function to return the number of derangements for n...
from solution import subfactorial, derangements_without_2cycles def test_subfactorial(): # Verify subfactorial values as known from combinatorial math assert subfactorial(0) == 1 assert subfactorial(1) == 0 assert subfactorial(2) == 1 assert subfactorial(3) == 2 assert subfactorial(4) == 9 ...
[ { "docstring": "Compute the subfactorial (derangement) of a number n.\n!n = n! * sum((-1)^i / i! for i in range(n+1))", "function_declaration": "def subfactorial(n):", "function_name": "subfactorial", "parameter_list": "(n)" }, { "docstring": null, "function_declaration": "def derangemen...
[ 0, 0, 0, 0, 0, 0, 1, 0, 0, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "from itertools import permutations\n\ndef is_derangement(p):\n \"\"\"\n Check if the permutation p is a derangement.\n \"\"\"\n for i in range(len...
trial_gpt4o_6
{ "original_instruction": "", "prompt_id": "00005394", "row_id": 5394, "seed_ids": "[4621]" }
0.398312
Codeforces_5394
I
[ "subfactorial", "derangements_without_2cycles" ]
2
[ [ "derangements_without_2cycles", "subfactorial" ] ]
1
[]
false
[]
false
pytest
true
[]
true
f83e71f467d60988d5b564589a23b8dfd9295e63
1e03cc70cae8196e15223397601672a0636109e5
v1.0
instruct
Codeforces
Codeforces_5403_I
You are given an array of integers $$$A$$$ of size $$$N$$$. Your task is to find out if there is a pair of integers in the array whose product is a perfect square. A perfect square is an integer that is the square of some other integer. For example, $$$1, 4, 9, 16, \ldots$$$ are perfect squares. Input consists of: - ...
import math from collections import Counter def has_perfect_square_pair(A): """ Returns "YES" if there is a pair of integers in the array whose product is a perfect square, otherwise "NO". """ # Count the frequency of each number freq = Counter(A) # Check for conditions where the same numb...
from solution import has_perfect_square_pair def test_sample_case(): assert has_perfect_square_pair([4, 7, 6, 25, 1]) == "YES" def test_no_pairs(): assert has_perfect_square_pair([2, 3, 5]) == "NO" def test_single_element(): assert has_perfect_square_pair([1]) == "NO" def test_multiple_duplicates(): ...
[ { "docstring": "Returns \"YES\" if there is a pair of integers in the array whose product is a perfect square, otherwise \"NO\".", "function_declaration": "def has_perfect_square_pair(A):", "function_name": "has_perfect_square_pair", "parameter_list": "(A)" }, { "docstring": "Returns True if...
[ 1, 1, 0, 0, 1, 0, 1, 0 ]
4
medium
0.5
{ "trial_gpt4o_0": null, "trial_gpt4o_1": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared1_results_combined.jsonl", "solution_code": "import math\nfrom collections import defaultdict\n\ndef is_perfect_square(x):\n \"\"\" Helper function to check if a number is a p...
trial_gpt4o_5
{ "original_instruction": "", "prompt_id": "00005403", "row_id": 5403, "seed_ids": "[8211]" }
0.687675
Codeforces_5403
I
[ "has_perfect_square_pair", "is_perfect_square" ]
2
[ [ "has_perfect_square_pair", "is_perfect_square" ] ]
1
[]
false
[]
false
pytest
true
[]
true
2d0b1fa8b93be40808a4d122e02ebc9347e1ce08
473862f549052d7f8a85cfd9f04b6f4fa05bf0a2
v1.0
instruct
Codeforces
Codeforces_5413_I
You are given a sequence of n integers a1, a2, ..., an and m queries. Each query is of one of the following two types: 1. Update the value at position ai to a new value x. 2. Determine the number of distinct integers present in the subsequence between indices l and r inclusive. Write a program that processes these qu...
def update(array, index, value): """ Updates the element at `index` to the new `value`. """ array[index] = value def distinct_count(array, l, r): """ Returns the number of distinct elements in the subarray from index `l` to `r` (0-based). """ return len(set(array[l:r+1])) def process_q...
def test_update(): array = [1, 2, 1, 3, 2] update(array, 2, 5) assert array == [1, 2, 5, 3, 2] def test_distinct_count(): array = [1, 2, 1, 3, 2] assert distinct_count(array, 0, 2) == 2 assert distinct_count(array, 0, 4) == 3 assert distinct_count(array, 1, 3) == 3 def test_process_queries...
[ { "docstring": "Updates the element at `index` to the new `value`.", "function_declaration": "def update(array, index, value):", "function_name": "update", "parameter_list": "(array, index, value)" }, { "docstring": "Returns the number of distinct elements in the subarray from index `l` to `...
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "class SegmentTree:\n def __init__(self, data):\n self.n = len(data)\n self.data = data[:]\n self.tree = [set() for _ in range(4 * self...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00005413", "row_id": 5413, "seed_ids": "[7075]" }
0.757341
Codeforces_5413
I
[ "update", "distinct_count", "process_queries" ]
3
[ [ "process_queries", "distinct_count" ], [ "process_queries", "update" ] ]
2
[ "process_queries" ]
false
[]
false
pytest
false
[]
true
489c93e772439468398ddf463b4aa6742939bad3
605bcc63df2ecbad29f8773740b903d2d33144bf
v1.0
instruct
Codeforces
Codeforces_5452_I
Samuel is designing a water distribution system for his small town. The town has n water tanks and m pipes connecting various pairs of water tanks. Each water tank needs to be connected directly or indirectly to the main water source for effective distribution. Samuel wants to ensure that the water distribution system ...
from collections import defaultdict def find_bridges(n, graph): timer = 0 disc = [-1] * n low = [-1] * n visited = [False] * n parent = [-1] * n bridges = [] def dfs(u): nonlocal timer visited[u] = True disc[u] = low[u] = timer timer += 1 for v in g...
from solution import can_build_reliable_system def test_single_tank(): assert can_build_reliable_system(1, 0, []) == "YES" def test_reliable_small_graph(): assert can_build_reliable_system(4, 5, [(1, 2), (1, 3), (2, 3), (2, 4), (3, 4)]) == "YES" def test_unreliable_small_graph(): assert can_build_reliabl...
[ { "docstring": null, "function_declaration": "def find_bridges(n, graph):", "function_name": "find_bridges", "parameter_list": "(n, graph)" }, { "docstring": null, "function_declaration": "def can_build_reliable_system(n, m, pipes):", "function_name": "can_build_reliable_system", ...
[ 0, 0, 1, 1, 0, 0, 0, 0, 0, 0 ]
2
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_reliable_water_distribution(n, m, pipes):\n from collections import defaultdict\n \n if n == 1:\n return \"YES\" if m == 0 else \"NO\"\...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00005452", "row_id": 5452, "seed_ids": "[1]" }
0.615901
Codeforces_5452
I
[ "find_bridges", "can_build_reliable_system" ]
2
[ [ "can_build_reliable_system", "find_bridges" ] ]
1
[]
false
[]
false
pytest
true
[]
true
b95ea54ce0329cbaa20206eea637fb64a55b4dec
109fa98f0939235097556ed4655e9affd420554a
v1.0
instruct
Codeforces
Codeforces_5459_I
The city council of a town with $$$N$$$ intersections and $$$M$$$ roads is planning to improve the infrastructure. Each road has a certain length and can be traveled in both directions. They want to ensure that every pair of intersections remains connected, but at the same time they want to minimize the total length of...
def find(parent, i): if parent[i] == i: return i else: return find(parent, parent[i]) def union(parent, rank, x, y): root_x = find(parent, x) root_y = find(parent, y) if rank[root_x] > rank[root_y]: parent[root_y] = root_x elif rank[root_x] < rank[root_y]: p...
import pytest from solution import minimum_total_road_length def test_example(): roads = [ (1, 2, 3), (1, 3, 4), (4, 2, 2), (3, 4, 5), (1, 4, 6) ] assert minimum_total_road_length(4, 5, roads) == 9 def test_no_connection(): roads = [ (1, 2, 1), (...
[ { "docstring": null, "function_declaration": "def find(parent, i):", "function_name": "find", "parameter_list": "(parent, i)" }, { "docstring": null, "function_declaration": "def union(parent, rank, x, y):", "function_name": "union", "parameter_list": "(parent, rank, x, y)" }, ...
[ 0, 0, 1, 1, 0, 0, 1, 0, 0, 1 ]
4
medium
0.4
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def kruskal_minimum_spanning_tree(N, roads):\n parent = list(range(N))\n rank = [0] * N\n\n def find(x):\n if parent[x] != x:\n par...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00005459", "row_id": 5459, "seed_ids": "[8214]" }
0.72129
Codeforces_5459
I
[ "find", "union", "minimum_total_road_length" ]
3
[ [ "minimum_total_road_length", "find" ], [ "minimum_total_road_length", "union" ], [ "union", "find" ] ]
3
[]
false
[]
false
pytest
true
[]
true
659d5037afb0ba199f553c8c32bff075af0c06a7
ba4bc7fba5301903e8fbd478fbae7588787ed875
v1.0
instruct
Codeforces
Codeforces_5461_I
Alyssa P. enjoys solving puzzles and recently came across an intriguing number problem. She learned about Palindromic Numbers; numbers that read the same backward as forward, like 121 or 909. One day, she decided to challenge herself by finding the largest palindromic number that can be obtained by the product of two ...
def is_palindrome(num): """ Returns True if num is a palindrome, otherwise False. """ return str(num) == str(num)[::-1] def largest_palindrome_product(n): """ Returns the largest palindromic number made from the product of two n-digit numbers. """ if n < 1 or n > 3: raise ValueE...
from solution import is_palindrome, largest_palindrome_product def test_is_palindrome(): assert is_palindrome(121) is True assert is_palindrome(123) is False assert is_palindrome(12321) is True assert is_palindrome(123456) is False def test_largest_palindrome_product_1_digit(): assert largest_pali...
[ { "docstring": "Returns True if num is a palindrome, otherwise False.", "function_declaration": "def is_palindrome(num):", "function_name": "is_palindrome", "parameter_list": "(num)" }, { "docstring": "Returns the largest palindromic number made from the product of two n-digit numbers.", ...
[ 1, 1, 1, 1, 1, 1, 1, 1, 0, 1 ]
9
easy
0.9
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_palindrome(number):\n \"\"\"\n Checks if a given number is a palindrome.\n \"\"\"\n return str(number) == str(number)[::-1]\n\ndef largest_...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00005461", "row_id": 5461, "seed_ids": "[7292]" }
0.747844
Codeforces_5461
I
[ "is_palindrome", "largest_palindrome_product" ]
2
[ [ "largest_palindrome_product", "is_palindrome" ] ]
1
[]
false
[]
false
pytest
true
[]
true
4e5c7d45581b836b00c5dc23aebd4e920aca43fa
29604dc79fea9e76dcbfedffaa49a8e7d2a915a8
v1.0
instruct
Codeforces
Codeforces_5495_I
A company has designed a special kind of list called a "wiggle list". A wiggle list is defined as a sequence of numbers such that the differences between successive numbers strictly alternate between positive and negative. Your task is to determine if a given list is a wiggle list. A wiggle list meets the following cr...
def is_wiggle_list(nums): """ Determines if a list of integers is a wiggle list. Args: nums (list of int): A list of integers Returns: str: "YES" if the list is a wiggle list, otherwise "NO" """ if len(nums) < 2: return "YES" for i in range(1, len(nums) - 1): ...
from solution import is_wiggle_list, process_wiggle_lists def test_is_wiggle_list(): assert is_wiggle_list([1, 3, 2]) == "YES" assert is_wiggle_list([4, 5, 6, 3]) == "NO" assert is_wiggle_list([1, 4, 2, 5, 3]) == "YES" assert is_wiggle_list([1]) == "YES" assert is_wiggle_list([1, 1, 1, 1]) == "NO" ...
[ { "docstring": "Determines if a list of integers is a wiggle list.\n\nArgs:\nnums (list of int): A list of integers\n\nReturns:\nstr: \"YES\" if the list is a wiggle list, otherwise \"NO\"", "function_declaration": "def is_wiggle_list(nums):", "function_name": "is_wiggle_list", "parameter_list": "(n...
[ 1, 1, 0, 1, 1, 0, 0, 1, 0, 0 ]
5
medium
0.5
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_wiggle_list(lst):\n \"\"\"\n Returns 'YES' if the given list lst is a wiggle list, otherwise returns 'NO'.\n \"\"\"\n m = len(lst)\n if ...
trial_gpt4o_7
{ "original_instruction": "", "prompt_id": "00005495", "row_id": 5495, "seed_ids": "[7880]" }
0.562086
Codeforces_5495
I
[ "is_wiggle_list", "process_wiggle_lists" ]
2
[ [ "process_wiggle_lists", "is_wiggle_list" ] ]
1
[]
false
[]
false
pytest
true
[]
true
3319e54597cab4a98e30d2a86c765ca4764a163a
5996999615e7097bddf22e136c3f5a2b1bac2070
v1.0
instruct
Codeforces
Codeforces_5564_I
You have a binary string s of length n consisting of characters '0' and '1'. You are allowed to perform the following operations on this string: 1. Flip a bit: Change a '0' to '1' or a '1' to '0' at a specific index. 2. Count subarrays: Count the number of subarrays which consist entirely of '1's. You will be given m...
def count_subarrays_of_ones(s): """ Counts the number of subarrays consisting entirely of '1's in the given binary string s. """ count = 0 in_subarray = False for char in s: if char == '1': if not in_subarray: count += 1 in_subarray = True...
from solution import process_operations, count_subarrays_of_ones def test_count_subarrays_of_ones(): assert count_subarrays_of_ones("11001") == 2 assert count_subarrays_of_ones("11101") == 2 assert count_subarrays_of_ones("00000") == 0 assert count_subarrays_of_ones("11111") == 1 assert count_subar...
[ { "docstring": "Counts the number of subarrays consisting entirely of '1's in the given binary string s.", "function_declaration": "def count_subarrays_of_ones(s):", "function_name": "count_subarrays_of_ones", "parameter_list": "(s)" }, { "docstring": "Processes a list of operations on the g...
[ 1, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def count_subarrays_of_ones(s):\n \"\"\"\n Counts the number of subarrays consisting entirely of '1's in the given binary string s.\n \"\"\"\n cou...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00005564", "row_id": 5564, "seed_ids": "[3094]" }
0.737467
Codeforces_5564
I
[ "count_subarrays_of_ones", "process_operations" ]
2
[ [ "process_operations", "count_subarrays_of_ones" ] ]
1
[]
false
[]
false
pytest
true
[]
true
3c66e1a8f950fe7c16856d93071a1c0bc62924ac
11bb4a93b5ed89fbdc32c8b9730021ce68f8b03e
v1.0
instruct
Codeforces
Codeforces_5570_I
You are given a list of integers where each integer represents the height of a vertical line on a Cartesian plane. The consecutive lines together form a histogram. Your objective is to find the largest rectangle that can be formed within the bounds of this histogram. The rectangle must be completely contained within th...
def largest_rectangle_area(heights): """ Given a list of integers representing the height of vertical lines in a histogram, return the area of the largest rectangle that can be formed within the histogram. """ stack = [] max_area = 0 for i, h in enumerate(heights): while stack and he...
from solution import largest_rectangle_area, get_input_and_solve def test_largest_rectangle_area_basic(): assert largest_rectangle_area([2, 1, 5, 6, 2, 3]) == 10 def test_largest_rectangle_area_single_height(): assert largest_rectangle_area([2]) == 2 def test_largest_rectangle_area_multiple_same_heights(): ...
[ { "docstring": "Given a list of integers representing the height of vertical lines in a histogram,\nreturn the area of the largest rectangle that can be formed within the histogram.", "function_declaration": "def largest_rectangle_area(heights):", "function_name": "largest_rectangle_area", "paramete...
[ 1, 1, 0, 0, 0, 1, 1, 0, 1, 0 ]
5
medium
0.5
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def largest_rectangle_area(heights):\n \"\"\"\n Calculate the area of the largest rectangle that can be formed within a histogram.\n \n :param hei...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00005570", "row_id": 5570, "seed_ids": "[4128]" }
0.654701
Codeforces_5570
I
[ "largest_rectangle_area", "get_input_and_solve" ]
2
[ [ "get_input_and_solve", "largest_rectangle_area" ] ]
1
[]
false
[]
false
pytest
true
[]
true
4fa58f79a0062b18630bc3a4bc65adfa249372b9
c46ae62ed8990de221da6a48022a13d1d8b8e003
v1.0
instruct
Codeforces
Codeforces_5622_I
You're given a grid of size n × m filled with characters '.' (representing empty space) and '#' (representing walls). Your task is to determine the size of the largest rectangle that can be formed by empty spaces ('.') within the grid. The first line of the input contains two integers n and m (1 ≤ n, m ≤ 100) — the d...
def largest_rectangle_area(grid): """ Given a grid of '.' and '#', find the area of the largest rectangle filled with only '.'. """ n = len(grid) m = len(grid[0]) # Create an array to store the height of histogram columns heights = [0] * m max_area = 0 for i in range(n...
def test_largest_rectangle_area(): assert parse_and_find_largest_rectangle_area("4 4\n....\n..#.\n...#\n##..") == 6, "Test case 1 failed" assert parse_and_find_largest_rectangle_area("1 1\n.") == 1, "Test case 2 failed" assert parse_and_find_largest_rectangle_area("1 1\n#") == 0, "Test case 3 failed" as...
[ { "docstring": "Given a grid of '.' and '#', find the area of the largest rectangle \nfilled with only '.'.", "function_declaration": "def largest_rectangle_area(grid):", "function_name": "largest_rectangle_area", "parameter_list": "(grid)" }, { "docstring": "Given an array of heights, deter...
[ 0, 0, 0, 0, 1, 1, 0, 1, 0, 1 ]
4
medium
0.4
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def max_histogram_area(histogram):\n stack = []\n max_area = 0\n index = 0\n while index < len(histogram):\n if not stack or histogram[stac...
trial_gpt4o_5
{ "original_instruction": "", "prompt_id": "00005622", "row_id": 5622, "seed_ids": "[4832]" }
0.656149
Codeforces_5622
I
[ "largest_rectangle_area", "max_histogram_area", "parse_and_find_largest_rectangle_area" ]
3
[ [ "largest_rectangle_area", "max_histogram_area" ], [ "parse_and_find_largest_rectangle_area", "largest_rectangle_area" ] ]
2
[]
false
[]
false
pytest
false
[]
true
026646620b232172ac3a525acf11b3627d440cdd
4cf6ec2e41cbc3e22e3ec53213e179fa9c4218be
v1.0
instruct
Codeforces
Codeforces_5623_I
You are managing a database of users, each represented by a unique integer ID. You need to provide a function that checks if a given list of user IDs is valid based on the following criteria: 1. All IDs must be positive integers. 2. No ID should appear more than once in the list. 3. The sum of all IDs should be a prim...
def is_prime(n): if n <= 1: return False if n == 2: return True if n % 2 == 0: return False p = 3 while p * p <= n: if n % p == 0: return False p += 2 return True def is_valid_user_list(user_ids): """ Check if the list of user IDs is v...
from solution import is_valid_user_list def test_valid_list_with_prime_sum(): assert is_valid_user_list([2, 3, 5, 7]) == True def test_list_with_negative_ids(): assert is_valid_user_list([2, -3, 5, 7]) == False def test_list_with_non_integer_ids(): assert is_valid_user_list([2, 3.5, 5, 7]) == False def ...
[ { "docstring": null, "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Check if the list of user IDs is valid based on the given criteria.", "function_declaration": "def is_valid_user_list(user_ids):", "function_name":...
[ 0, 1, 0, 0, 1, 0, 0, 0, 0 ]
2
hard
0.222
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(n):\n if n <= 1:\n return False\n if n == 2:\n return True\n if n % 2 == 0:\n return False\n p = 3\n while p ...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00005623", "row_id": 5623, "seed_ids": "[2619]" }
0.65321
Codeforces_5623
I
[ "is_prime", "is_valid_user_list" ]
2
[ [ "is_valid_user_list", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
99fbaa9ac285f2baa08b3dcf0b01ad790ee4a050
20d2258371af415b31e1d902c4d583f36bf3003e
v1.0
instruct
Codeforces
Codeforces_5631_I
You are given an undirected graph with `n` nodes and `m` edges. Each node has a unique integer value assigned to it, and each edge has a non-negative weight. Your task is to answer `q` queries. Each query provides two nodes, `u` and `v`, and asks for the minimum cost to visit all nodes' values on the shortest path bet...
import heapq def calculate_minimum_costs(n, m, q, node_values, edges, queries): # Build the graph graph = {i: [] for i in range(1, n+1)} for u, v, w in edges: graph[u].append((v, w)) graph[v].append((u, w)) def dijkstra(source): dist = {i: float('inf') for i in range(1,...
from solution import solve_graph_queries def test_example(): n, m, q = 5, 6, 3 node_values = [5, 1, 3, 2, 4] edges = [ (1, 2, 2), (1, 3, 3), (2, 4, 4), (3, 5, 1), (4, 5, 5), (2, 5, 7) ] queries = [ (1, 4), (3, 4), (1, 5) ] ...
[ { "docstring": null, "function_declaration": "def calculate_minimum_costs(n, m, q, node_values, edges, queries):", "function_name": "calculate_minimum_costs", "parameter_list": "(n, m, q, node_values, edges, queries)" }, { "docstring": null, "function_declaration": "def solve_graph_queri...
[ 0, 0, 0, 0, 0, 1, 0, 0, 0, 1 ]
2
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "import heapq\nimport sys\nfrom collections import defaultdict\n\ndef min_cost_on_shortest_path(n, m, q, values, edges, queries):\n graph = defaultdict(list...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00005631", "row_id": 5631, "seed_ids": "[2717]" }
0.801283
Codeforces_5631
I
[ "calculate_minimum_costs", "solve_graph_queries" ]
2
[ [ "solve_graph_queries", "calculate_minimum_costs" ] ]
1
[]
false
[]
false
pytest
true
[]
true
6bba661d3709d027932320d5e5a761ef5608af73
b78e2dd9e026d252b4c4dcc6e9d06641c56143ed
v1.0
instruct
Codeforces
Codeforces_5651_I
You are given a tall rectangular grid of cells with dimensions $$$h$$$ by $$$w$$$ ($$$h$$$ rows and $$$w$$$ columns). Some of these cells are blocked and some are empty. An empty cell is represented by a '.' character, while a blocked cell is represented by a '#' character. Your task is to construct a path through the ...
def is_path_possible(h, w, grid): def is_in_bounds(x, y): return 0 <= x < h and 0 <= y < w def dfs(x, y): if x == h - 1 and y == w - 1: return True for dx, dy in [(1, 0), (-1, 0), (0, 1), (0, -1)]: nx, ny = x + dx, y + dy if is_in_bounds(nx, ny) a...
from solution import grid_path def test_no_path(): h, w = 5, 5 grid = [ "..#..", "#####", "..#..", ".#...", "#...." ] assert grid_path(h, w, grid) == "NO" def test_yes_path(): h, w = 5, 5 grid = [ "..#..", "#...#", "..#..", ...
[ { "docstring": null, "function_declaration": "def is_path_possible(h, w, grid):", "function_name": "is_path_possible", "parameter_list": "(h, w, grid)" }, { "docstring": null, "function_declaration": "def grid_path(h, w, grid):", "function_name": "grid_path", "parameter_list": "(...
[ 0, 1, 1, 0, 0, 0, 0, 0, 0 ]
2
hard
0.222
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_path_exist(h, w, grid):\n \"\"\"\n Determine if there exists a valid path from the top-left corner (1, 1) to the bottom right corner (h, w).\n ...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00005651", "row_id": 5651, "seed_ids": "[4518]" }
0.749753
Codeforces_5651
I
[ "is_path_possible", "grid_path" ]
2
[ [ "grid_path", "is_path_possible" ] ]
1
[]
false
[]
false
pytest
true
[]
true
e751090e2698db4410a52d281a8d39a3ad3f9832
7188b33ed337b468446d04c12552b1942e2c9030
v1.0
instruct
Codeforces
Codeforces_5692_I
You are given a square n × n board. Some cells are already filled with distinct positive integers. Your task is to fill each empty cell with any positive integer such that the resulting configuration satisfies the following property: For any 2 × 2 sub-board, the sum of its four cells must be a perfect square. Print t...
MOD = 1000000007 def is_perfect_square(x): return int(x**0.5)**2 == x def count_ways_to_fill_board(n, board): # This is a highly non-trivial task, a simple direct approach won't work due to constraints # Instead we focus on constraints and perfect squares checking for 2x2 sub-matrix if n == 1: ...
from solution import count_ways_to_fill_board def test_single_filled_cell(): n = 1 board = [ [0] ] assert count_ways_to_fill_board(n, board) == 1 def test_single_fixed_filled_cell(): n = 1 board = [ [5] ] assert count_ways_to_fill_board(n, board) == 1 def test_4x4_boa...
[ { "docstring": null, "function_declaration": "def is_perfect_square(x):", "function_name": "is_perfect_square", "parameter_list": "(x)" }, { "docstring": null, "function_declaration": "def count_ways_to_fill_board(n, board):", "function_name": "count_ways_to_fill_board", "paramet...
[ 0, 1, 0, 1, 0, 0, 0 ]
2
hard
0.286
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_perfect_square(x):\n from math import isqrt\n s = isqrt(x)\n return s * s == x\n\ndef count_ways_to_fill_board(n, board):\n MOD = 100000000...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00005692", "row_id": 5692, "seed_ids": "[6212]" }
0.659817
Codeforces_5692
I
[ "is_perfect_square", "count_ways_to_fill_board" ]
2
[ [ "count_ways_to_fill_board", "is_perfect_square" ] ]
1
[]
false
[]
false
pytest
true
[]
true
7fad42bae93d5cf5674cb3ab2a1e2d8e1f2024fb
d11920f0237efb9bf0b979c784f26529e7848aa9
v1.0
instruct
Codeforces
Codeforces_5722_I
Alice is planning a road trip and wants to visit a number of cities. She wants to know the shortest route that allows her to visit each city exactly once and return to her starting city. This is a well-known problem in computer science known as the Traveling Salesperson Problem (TSP). Alice needs your help to implement...
from itertools import permutations from math import sqrt from functools import lru_cache def calculate_distance(x1, y1, x2, y2): """ Calculate the Euclidean distance between two points (x1, y1) and (x2, y2) """ return sqrt((x1 - x2) ** 2 + (y1 - y2) ** 2) def calculate_total_distance(tour, cities): ...
from solution import calculate_distance, calculate_total_distance, tsp def test_calculate_distance(): # Tests for distance calculation assert round(calculate_distance(0, 0, 3, 4)) == 5 assert round(calculate_distance(0, 0, 0, 0)) == 0 assert round(calculate_distance(1, 1, 4, 5)) == 5 def test_calculat...
[ { "docstring": "Calculate the Euclidean distance between two points (x1, y1) and (x2, y2)", "function_declaration": "def calculate_distance(x1, y1, x2, y2):", "function_name": "calculate_distance", "parameter_list": "(x1, y1, x2, y2)" }, { "docstring": "Calculate the total distance of a give...
[ 0, 1, 0, 0, 0, 0, 0, 0, 0, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "from itertools import permutations\nimport math\n\ndef calculate_distance(city1, city2):\n \"\"\"\n Returns the Euclidean distance between two cities.\n...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00005722", "row_id": 5722, "seed_ids": "[6189]" }
0.72677
Codeforces_5722
I
[ "calculate_distance", "calculate_total_distance", "tsp" ]
3
[ [ "calculate_total_distance", "calculate_distance" ], [ "tsp", "calculate_total_distance" ] ]
2
[]
false
[]
false
pytest
true
[]
true
c194990ecec2cb38b1d8c0585352d3895b7c798d
0aa9057c0d47a2f88a42b44e24d8774fdc1f5e6e
v1.0
instruct
Codeforces
Codeforces_5755_I
A group of friends decided to create a game called "Maze Runner". The game is played on an n × m grid. Each cell in the grid may contain either a wall or be passable. The player starts from a given initial position (sx, sy) and needs to reach the destination (dx, dy). The player can move up, down, left, or right, but ...
from collections import deque def within_bounds(x, y, n, m): return 0 <= x < n and 0 <= y < m def bfs_minimum_time(grid, n, m, sx, sy, dx, dy): if grid[sx][sy] == '#' or grid[dx][dy] == '#': return -1 directions = [(-1, 0), (1, 0), (0, -1), (0, 1)] visited = [[False] * m for _ in range(n)...
import pytest from solution import maze_runner def test_maze_runner_basic(): grid = [ "......", ".####.", "......", ".####.", "......" ] queries = [ (0, 0, 4, 5), (0, 0, 3, 1), (1, 1, 2, 2), (0, 0, 1, 5) ] expected = [9, -1...
[ { "docstring": null, "function_declaration": "def within_bounds(x, y, n, m):", "function_name": "within_bounds", "parameter_list": "(x, y, n, m)" }, { "docstring": null, "function_declaration": "def bfs_minimum_time(grid, n, m, sx, sy, dx, dy):", "function_name": "bfs_minimum_time", ...
[ 1, 0, 0, 0, 1, 0, 0, 0, 0 ]
2
hard
0.222
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "from collections import deque\n\ndef within_bounds(x, y, n, m):\n return 0 <= x < n and 0 <= y < m\n\ndef bfs_minimum_time(grid, n, m, sx, sy, dx, dy):\n ...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00005755", "row_id": 5755, "seed_ids": "[3946]" }
0.741252
Codeforces_5755
I
[ "within_bounds", "bfs_minimum_time", "maze_runner" ]
3
[ [ "bfs_minimum_time", "within_bounds" ], [ "maze_runner", "bfs_minimum_time" ] ]
2
[]
false
[]
false
pytest
true
[]
true
865133ef6302cfd084f3cc0b2b5f680a11f16b1b
ea626197eb467c13603aa811a5ded77108c89cc6
v1.0
instruct
Codeforces
Codeforces_5756_I
You are given a list of wanted criminal records. Each record includes the name of a criminal and the name of the city where the crime was committed. Multiple crimes might have been committed by the same criminal in the same or different cities. Your objective is to analyze the criminal records and generate a summary t...
def summarize_criminal_records(n, records): from collections import defaultdict criminal_dict = defaultdict(set) for name, city in records: criminal_dict[name].add(city) result = [] for criminal, cities in sorted(criminal_dict.items()): result.append(f"{criminal} {','.join...
from solution import summarize_criminal_records_from_input def test_single_record(): input_data = ["1", "John NewYork"] expected_output = [1, "John NewYork"] assert summarize_criminal_records_from_input(input_data) == expected_output def test_multiple_records_single_criminal(): input_data = ["3", "Joh...
[ { "docstring": null, "function_declaration": "def summarize_criminal_records(n, records):", "function_name": "summarize_criminal_records", "parameter_list": "(n, records)" }, { "docstring": null, "function_declaration": "def parse_input(input_list):", "function_name": "parse_input", ...
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
10
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def summarize_crimes(n, records):\n from collections import defaultdict\n \n criminals = defaultdict(set)\n \n # Collecting the data into a dic...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00005756", "row_id": 5756, "seed_ids": "[1972]" }
0.557102
Codeforces_5756
I
[ "summarize_criminal_records", "parse_input", "summarize_criminal_records_from_input" ]
3
[ [ "summarize_criminal_records_from_input", "parse_input" ], [ "summarize_criminal_records_from_input", "summarize_criminal_records" ] ]
2
[ "parse_input" ]
false
[]
false
pytest
true
[]
true
617e9eaf20b433446ec15ef12479f18e51bf458a
be159059b38e2f378c86bf25c8110efaf792443b
v1.0
instruct
Codeforces
Codeforces_5769_I
A delivery company operates in a town with n intersections numbered from 1 to n. The town has m directional roads, each connecting a pair of intersections. Every road has a particular delivery time in minutes. The company currently has k distribution centers located at specified intersections. The company wants to min...
import heapq def dijkstra(n, graph, distribution_centers): """ Performs Dijkstra's algorithm from multiple sources (distribution centers). Returns the minimum delivery times from any distribution center to each intersection. """ dist = {i: float('inf') for i in range(1, n + 1)} pq = [] ...
from solution import minimum_delivery_time def test_example_case(): n = 5 m = 6 k = 2 roads = [ (1, 2, 5), (1, 3, 10), (2, 3, 2), (3, 4, 1), (2, 4, 8), (4, 5, 3) ] distribution_centers = [1, 4] assert minimum_delivery_time(n, m, k, roads, dist...
[ { "docstring": "Performs Dijkstra's algorithm from multiple sources (distribution centers).\nReturns the minimum delivery times from any distribution center to each intersection.", "function_declaration": "def dijkstra(n, graph, distribution_centers):", "function_name": "dijkstra", "parameter_list":...
[ 0, 0, 1, 0, 0, 0, 0, 0, 0, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "import heapq\n\ndef minimum_delivery_time(n, m, k, roads, centers):\n if k == 0:\n return -1\n\n # Create adjacency list\n adj_list = [[] for ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00005769", "row_id": 5769, "seed_ids": "[4731]" }
0.729549
Codeforces_5769
I
[ "dijkstra", "minimum_delivery_time" ]
2
[ [ "minimum_delivery_time", "dijkstra" ] ]
1
[]
false
[]
false
pytest
true
[]
true
67be915a89615e692055fdc7d8f4455604a1a60c
bc3cc85a4da8ed1435ffaa7645af2b2c9fd1c681
v1.0
instruct
Codeforces
Codeforces_5788_I
Gina is organizing a conference where she will be the keynote speaker. During the conference, Gina plans to address $$$m$$$ different topics in $$$m$$$ different sessions. Each topic is to be covered in exactly one session. Gina needs to decide the order in which she will address the topics — formally, she needs to cho...
from collections import deque, defaultdict def find_topic_order(m, l, s, constraints): # Create graph and in-degree list graph = defaultdict(list) in_degree = [0] * (m + 1) # Add edges for preparation topics for j in range(1, m + 1): if s[j - 1] != 0: # there's a preparation topic ...
from solution import conference_order def test_simple_case(): assert conference_order(3, 1, [0, 1, 2], [(1, 2)]) == [1, 2, 3] def test_complex_case(): result = conference_order(4, 2, [0, 1, 2, 2], [(1, 2), (3, 4)]) assert result in ([1, 2, 3, 4], [1, 3, 2, 4], [1, 3, 4, 2]) def test_no_valid_case(): ...
[ { "docstring": null, "function_declaration": "def find_topic_order(m, l, s, constraints):", "function_name": "find_topic_order", "parameter_list": "(m, l, s, constraints)" }, { "docstring": null, "function_declaration": "def conference_order(m, l, s, constraints):", "function_name": ...
[ 0, 0, 1, 1, 0, 0, 0, 0, 1, 0 ]
3
hard
0.3
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "from collections import defaultdict, deque\n\ndef find_ordering(m, l, s, constraints):\n # Create the graph and the in-degree count\n graph = defaultdic...
trial_gpt4o_3
{ "original_instruction": "", "prompt_id": "00005788", "row_id": 5788, "seed_ids": "[1442]" }
0.613636
Codeforces_5788
I
[ "find_topic_order", "conference_order" ]
2
[ [ "conference_order", "find_topic_order" ] ]
1
[]
false
[]
false
pytest
true
[]
true
9cd2e87a77849a8f9ff28260cc606a2d7a588984
e537ffa731e34b46f181df952159a5222603b993
v1.0
instruct
Codeforces
Codeforces_5792_I
## New Coding Assessment Question В первой строке дано два целых числа $$$n$$$ и $$$q$$$ ($$$1 \le n \le 1\,000\,000$$$) — размер массива и количество запросов соответственно. Во второй строке даны $$$n$$$ целых чисел $$$arr_i$$$ ($$$0 \le arr_i \le 10^9$$$) — количество операций, зарегистрированных каждым сервером...
def prefix_sums(arr): """ Returns the prefix sum array of the given array `arr`. """ n = len(arr) prefix = [0] * (n + 1) for i in range(1, n + 1): prefix[i] = prefix[i - 1] + arr[i - 1] return prefix def query_sum(prefix, l, r): """ Returns the sum of elements from index l t...
from solution import prefix_sums, query_sum, process_queries def test_prefix_sums(): assert prefix_sums([1, 2, 3, 4, 5]) == [0, 1, 3, 6, 10, 15] assert prefix_sums([0, 0, 0]) == [0, 0, 0, 0] assert prefix_sums([10, 20, 30]) == [0, 10, 30, 60] def test_query_sum(): prefix = prefix_sums([1, 2, 3, 4, 5])...
[ { "docstring": "Returns the prefix sum array of the given array `arr`.", "function_declaration": "def prefix_sums(arr):", "function_name": "prefix_sums", "parameter_list": "(arr)" }, { "docstring": "Returns the sum of elements from index l to r using the prefix sum array.", "function_dec...
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
10
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def process_queries(n, q, array, queries):\n # Precompute prefix sums\n prefix_sums = [0] * (n + 1)\n for i in range(n):\n prefix_sums[i + 1] ...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00005792", "row_id": 5792, "seed_ids": "[2059]" }
0.572239
Codeforces_5792
I
[ "prefix_sums", "query_sum", "process_queries" ]
3
[ [ "process_queries", "prefix_sums" ], [ "process_queries", "query_sum" ] ]
2
[ "process_queries" ]
false
[]
false
pytest
true
[]
true
30b26ca4fe11e11451bbed87eed4b23caec480fa
6cb10009447d02e1f6cadc236c47083fb745b980
v1.0
instruct
Codeforces
Codeforces_5802_I
A mysterious map has been discovered, and it appears to be encrypted. The map is a grid of cells, where each cell contains a non-negative integer representing altitude levels. The task is to determine if there is a path from the top-left corner of the grid to the bottom-right corner such that the maximum altitude encou...
def find_min_max_altitude(n, m, grid): from heapq import heappush, heappop def is_valid(x, y): return 0 <= x < n and 0 <= y < m directions = [(0, 1), (1, 0)] min_heap = [(grid[0][0], 0, 0)] visited = [[False] * m for _ in range(n)] visited[0][0] = True while min_heap: curr...
from solution import solve def test_example_case(): grid = [ [0, 2, 3], [1, 5, 4], [2, 1, 0] ] assert solve(3, 3, grid) == 2 def test_all_same(): grid = [ [1, 1, 1], [1, 1, 1], [1, 1, 1] ] assert solve(3, 3, grid) == 1 def test_increasing_path()...
[ { "docstring": null, "function_declaration": "def find_min_max_altitude(n, m, grid):", "function_name": "find_min_max_altitude", "parameter_list": "(n, m, grid)" }, { "docstring": null, "function_declaration": "def solve(n, m, grid):", "function_name": "solve", "parameter_list": ...
[ 0, 0, 0, 0, 0, 0, 0, 1, 0 ]
1
hard
0.111
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "from heapq import heappush, heappop\n\ndef minimum_maximum_path(grid):\n n, m = len(grid), len(grid[0])\n visited = [[False] * m for _ in range(n)]\n ...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00005802", "row_id": 5802, "seed_ids": "[3165]" }
0.613678
Codeforces_5802
I
[ "find_min_max_altitude", "solve" ]
2
[ [ "solve", "find_min_max_altitude" ] ]
1
[]
false
[]
false
pytest
true
[]
true
9ab86efa7ceddfed0118bdd5ebebabe662778cb6
36c44d41e5d7d0ba5052ae1b43215ca0af702d95
v1.0
instruct
Codeforces
Codeforces_5812_I
You are given an array of integers, and you need to find the length of the longest subsequence such that every element in the subsequence is a power of two. More formally, a subsequence is a sequence that can be derived from the array by deleting some or no elements without changing the order of the remaining elements...
def is_power_of_two(x): return (x & (x - 1)) == 0 and x != 0 def longest_power_of_two_subsequence_length(arr): power_of_two_elements = [x for x in arr if is_power_of_two(x)] return len(power_of_two_elements)
from solution import is_power_of_two, longest_power_of_two_subsequence_length def test_is_power_of_two(): assert is_power_of_two(1) == True assert is_power_of_two(2) == True assert is_power_of_two(3) == False assert is_power_of_two(4) == True assert is_power_of_two(5) == False assert is_power_o...
[ { "docstring": null, "function_declaration": "def is_power_of_two(x):", "function_name": "is_power_of_two", "parameter_list": "(x)" }, { "docstring": null, "function_declaration": "def longest_power_of_two_subsequence_length(arr):", "function_name": "longest_power_of_two_subsequence_...
[ 1, 1, 1, 1, 1, 1, 1, 1, 0, 1 ]
9
easy
0.9
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_power_of_two(x):\n \"\"\"\n Function to check if a given number is a power of two.\n \"\"\"\n return (x & (x - 1)) == 0 and x > 0\n\ndef lo...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00005812", "row_id": 5812, "seed_ids": "[5556]" }
0.756208
Codeforces_5812
I
[ "is_power_of_two", "longest_power_of_two_subsequence_length" ]
2
[ [ "longest_power_of_two_subsequence_length", "is_power_of_two" ] ]
1
[]
false
[]
false
pytest
true
[]
true
68676e825200b4d596428ec4c9d886b861888b4f
0a10ff98a2798a424c511461e971c28346df80ed
v1.0
instruct
Codeforces
Codeforces_5880_I
A prime number is a natural number greater than 1 that has no positive divisors other than 1 and itself. Write a program to find the smallest prime number that is greater than a given integer X. The input consists of a single integer X (1 ≤ X ≤ 100). Output the smallest prime number greater than X.
def is_prime(n): """ Check if a number is prime. :param n: Integer to check. :return: True if the number is prime, False otherwise. """ 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: ...
from solution import next_prime def test_next_prime_1(): assert next_prime(1) == 2 def test_next_prime_2(): assert next_prime(2) == 3 def test_next_prime_10(): assert next_prime(10) == 11 def test_next_prime_17(): assert next_prime(17) == 19 def test_next_prime_99(): assert next_prime(99) == 10...
[ { "docstring": "Check if a number is prime.\n\n:param n: Integer to check.\n:return: True if the number is prime, False otherwise.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Find the smallest prime number greater than...
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
10
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(n):\n \"\"\"\n Determines if a number n is prime.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return True\n ...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00005880", "row_id": 5880, "seed_ids": "[247]" }
0.569139
Codeforces_5880
I
[ "is_prime", "next_prime" ]
2
[ [ "next_prime", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
fcf587b2f060a4b03d819e324a02028e081cdbb6
f1ab6bac86c1f85f48de3f8798a54ccee5aa85a4
v1.0
instruct
Codeforces
Codeforces_5883_I
A logistics company utilizes a network of warehouses connected by roads. Each warehouse is represented by a node, and each road has a specific capacity, denoting the maximum number of goods that can be transported between two warehouses. The goal of the company is to find the maximum flow of goods from a starting wareh...
from collections import deque, defaultdict def bfs(C, F, source, sink, parent): """ Perform a breadth-first search to find an augmenting path in the residual graph. """ visited = set() queue = deque([source]) visited.add(source) while queue: u = queue.popleft() ...
def test_max_flow_example(): n = 4 m = 5 edges = [ (1, 2, 100), (1, 3, 100), (2, 3, 1), (2, 4, 100), (3, 4, 100) ] assert max_flow(n, m, edges) == 200 def test_max_flow_single_path(): n = 2 m = 1 edges = [ (1, 2, 50) ] assert max_f...
[ { "docstring": "Perform a breadth-first search to find an augmenting path in the residual graph.", "function_declaration": "def bfs(C, F, source, sink, parent):", "function_name": "bfs", "parameter_list": "(C, F, source, sink, parent)" }, { "docstring": "Implementation of the Edmonds-Karp al...
[ 0, 0, 0, 0, 1, 0, 0, 1, 1, 0 ]
3
hard
0.3
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "from collections import deque\n\ndef bfs(capacity, source, sink, parent):\n visited = set()\n queue = deque([source])\n visited.add(source)\n\n wh...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00005883", "row_id": 5883, "seed_ids": "[5595]" }
0.692148
Codeforces_5883
I
[ "bfs", "edmonds_karp", "max_flow" ]
3
[ [ "edmonds_karp", "bfs" ], [ "max_flow", "edmonds_karp" ] ]
2
[]
false
[]
false
pytest
false
[]
true
b8ba375a6555284313229c00286a37be62d00788
a6ec3daa0c41cbd69a4ad7dfb5084b6efe625e17
v1.0
instruct
Codeforces
Codeforces_5916_I
A small village is organizing a tournament of string games. Each game involves rearranging strings according to specific rules. The tournament committee decided to create a challenge for the participants: for each given string, they must determine whether it can be rearranged to become a palindrome. A string is a pali...
def can_form_palindrome(s): """ Determine if the given string can be rearranged to form a palindrome. Args: s (str): Input string consisting of lowercase English letters. Returns: str: "Yes" if the string can be rearranged to form a palindrome, otherwise "No". """ from collecti...
from solution import can_form_palindrome, process_strings def test_can_form_palindrome_yes(): assert can_form_palindrome("aabb") == "Yes" assert can_form_palindrome("carerac") == "Yes" assert can_form_palindrome("aaabbbb") == "Yes" assert can_form_palindrome("racecar") == "Yes" assert can_form_pali...
[ { "docstring": "Determine if the given string can be rearranged to form a palindrome.\n\nArgs:\ns (str): Input string consisting of lowercase English letters.\n\nReturns:\nstr: \"Yes\" if the string can be rearranged to form a palindrome, otherwise \"No\".", "function_declaration": "def can_form_palindrome(...
[ 0, 1, 0, 0, 0, 0, 1, 1, 1 ]
4
medium
0.444
{ "trial_gpt4o_0": null, "trial_gpt4o_1": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared1_results_combined.jsonl", "solution_code": "def can_form_palindrome(s):\n \"\"\"\n Check if the given string can be rearranged to form a palindrome.\n \n A string ca...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00005916", "row_id": 5916, "seed_ids": "[3768]" }
0.803003
Codeforces_5916
I
[ "can_form_palindrome", "process_strings" ]
2
[ [ "process_strings", "can_form_palindrome" ] ]
1
[]
false
[]
false
pytest
true
[]
true
fc9baa7d51af8b73e016aee2fb049b8e71094b2e
917fa12ded372c2d25a1a309764df312a754301d
v1.0
instruct
Codeforces
Codeforces_6030_I
Given a list of distinct positive integers, find the largest subset of the list such that the greatest common divisor (GCD) of all the integers in the subset is greater than one. If no such subset exists, return an empty list. The first line of the input contains a single integer n (1 ≤ n ≤ 100) — the number of intege...
from math import gcd from itertools import combinations from functools import reduce def find_gcd_of_list(lst): if not lst: return 0 return reduce(gcd, lst) def largest_gcd_subset(n, numbers): max_subset = [] for r in range(2, n + 1): for subset in combinations(numbers, r): ...
from solution import largest_gcd_subset def test_example_1(): result = largest_gcd_subset(3, [10, 20, 30]) assert sorted(result) == [10, 20, 30] def test_example_2(): result = largest_gcd_subset(3, [7, 11, 13]) assert result == [] def test_mixed_numbers(): result = largest_gcd_subset(4, [6, 10, 1...
[ { "docstring": null, "function_declaration": "def find_gcd_of_list(lst):", "function_name": "find_gcd_of_list", "parameter_list": "(lst)" }, { "docstring": null, "function_declaration": "def largest_gcd_subset(n, numbers):", "function_name": "largest_gcd_subset", "parameter_list"...
[ 0, 0, 0, 0, 0, 1, 0, 0, 0, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "import math\nfrom collections import defaultdict\n\ndef find_largest_subset_with_gcd_greater_than_one(n, arr):\n \"\"\"\n Find the largest subset of the...
trial_gpt4o_5
{ "original_instruction": "", "prompt_id": "00006030", "row_id": 6030, "seed_ids": "[280]" }
0.652939
Codeforces_6030
I
[ "find_gcd_of_list", "largest_gcd_subset" ]
2
[ [ "largest_gcd_subset", "find_gcd_of_list" ] ]
1
[]
false
[]
false
pytest
true
[]
true
9364767d083c3d9af94a4fdcf61f4b4a4ef67a6a
c7037994e677bb95959ef333e086cbdd6c9f100e
v1.0
instruct
Codeforces
Codeforces_6041_I
You are given two points on a 2D plane and several rectangles. Your task is to draw the shortest possible line segment connecting the two points such that the segment does not intersect any of the given rectangles, but it can touch the edges of the rectangles. Each rectangle is axis-aligned, meaning its sides are para...
import math def euclidean_distance(x1, y1, x2, y2): """ Returns the Euclidean distance between two points (x1, y1) and (x2, y2). """ return math.sqrt((x2 - x1) ** 2 + (y2 - y1) ** 2) def shortest_path(x1, y1, x2, y2, rectangles): """ Returns the shortest path from (x1, y1) to (x2, y2) without ...
from solution import euclidean_distance, shortest_path def test_euclidean_distance(): assert math.isclose(euclidean_distance(0, 0, 3, 4), 5.0, rel_tol=1e-4) assert math.isclose(euclidean_distance(-1, -1, 1, 1), 2.8284, rel_tol=1e-4) assert math.isclose(euclidean_distance(2, 2, 5, 5), 4.2426, rel_tol=1e-4) ...
[ { "docstring": "Returns the Euclidean distance between two points (x1, y1) and (x2, y2).", "function_declaration": "def euclidean_distance(x1, y1, x2, y2):", "function_name": "euclidean_distance", "parameter_list": "(x1, y1, x2, y2)" }, { "docstring": "Returns the shortest path from (x1, y1)...
[ 1, 0, 0, 0, 0, 0, 1, 0, 0, 1 ]
3
hard
0.3
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "import math\n\ndef is_inside_rectangle(px, py, rect):\n \"\"\"\n Returns True if the point (px, py) is inside the rectangle\n defined by rect (xi1, y...
trial_gpt4o_6
{ "original_instruction": "", "prompt_id": "00006041", "row_id": 6041, "seed_ids": "[4444]" }
0.680507
Codeforces_6041
I
[ "euclidean_distance", "shortest_path" ]
2
[ [ "shortest_path", "euclidean_distance" ] ]
1
[]
false
[]
false
pytest
true
[]
true
a52e6978bd69a2a64d3f05e29e2b314bbc73026b
c556098db79430ec03e14562ec6be792164d167f
v1.0
instruct
Codeforces
Codeforces_6070_I
Write a program to find the smallest number that is evenly divisible by all of the numbers from 1 to a given number N. The number N will be provided as input. The program should output one line with the smallest number that is evenly divisible by all numbers in the range from 1 to N. **Input:** - An integer N, such ...
from math import gcd def lcm(a, b): return abs(a * b) // gcd(a, b) def smallest_multiple(N): multiple = 1 for i in range(1, N + 1): multiple = lcm(multiple, i) return multiple
from solution import smallest_multiple def test_smallest_multiple_1(): assert smallest_multiple(1) == 1 def test_smallest_multiple_2(): assert smallest_multiple(2) == 2 def test_smallest_multiple_3(): assert smallest_multiple(3) == 6 def test_smallest_multiple_5(): assert smallest_multiple(5) == 60 ...
[ { "docstring": null, "function_declaration": "def lcm(a, b):", "function_name": "lcm", "parameter_list": "(a, b)" }, { "docstring": null, "function_declaration": "def smallest_multiple(N):", "function_name": "smallest_multiple", "parameter_list": "(N)" } ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
10
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "import math\n\ndef smallest_multiple(N):\n \"\"\"\n Returns the smallest number that is evenly divisible by all of the numbers from 1 to N.\n \"\"\"\...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00006070", "row_id": 6070, "seed_ids": "[4180]" }
0.664111
Codeforces_6070
I
[ "lcm", "smallest_multiple" ]
2
[ [ "smallest_multiple", "lcm" ] ]
1
[]
false
[]
false
pytest
true
[]
true
14a8b2a1b325f123a194d69d721df2ff240fa2ae
2d3e3d48c58aa60e629d772fa7a32c7318b562f8
v1.0
instruct
Codeforces
Codeforces_6073_I
You are given a list of strings representing IP addresses, some of which are potentially valid IPv4 addresses and others are not. A valid IPv4 address is formatted as `a.b.c.d`, where `a`, `b`, `c`, and `d` are integers in the inclusive range from 0 to 255. Your task is to implement a function `filter_valid_ips(ip_lis...
from typing import List def is_valid_ipv4(ip: str) -> bool: parts = ip.split('.') if len(parts) != 4: return False for part in parts: if not part.isdigit(): return False if len(part) > 1 and part[0] == '0': return False if int(part) < 0 or int(part) >...
import pytest from solution import filter_valid_ips def test_mixed_ips(): assert filter_valid_ips([ "192.168.0.1", "255.255.255.255", "256.100.100.100", "123.45.67.89", "1.1.1", "01.02.03.04" ]) == ["123.45.67.89", "192.168.0.1", "255.255.255.255"] def test_all_valid_ips(): assert filter_...
[ { "docstring": null, "function_declaration": "def is_valid_ipv4(ip):", "function_name": "is_valid_ipv4", "parameter_list": "(ip)" }, { "docstring": null, "function_declaration": "def filter_valid_ips(ip_list):", "function_name": "filter_valid_ips", "parameter_list": "(ip_list)" ...
[ 1, 1, 1, 1, 0, 1, 1, 1, 1, 1 ]
9
easy
0.9
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "from typing import List\n\ndef filter_valid_ips(ip_list: List[str]) -> List[str]:\n def is_valid_ip(ip: str) -> bool:\n parts = ip.split('.')\n ...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00006073", "row_id": 6073, "seed_ids": "[7672]" }
0.588674
Codeforces_6073
I
[ "is_valid_ipv4", "filter_valid_ips" ]
2
[ [ "filter_valid_ips", "is_valid_ipv4" ] ]
1
[]
false
[]
false
pytest
true
[]
true
883cc822ec360993fd99b24a2b11777f9e9a0a58
595f6e0bd441ddf6ae238192c49e0d49a75bbb71
v1.0
instruct
Codeforces
Codeforces_6091_I
A city has n intersections connected by m one-way streets. Each street allows travel from one intersection to another in one specific direction. Since this city is famous for its nightly parades, some intersections have been set up with colorful lights, while others remain unlit. The city mayor wants to ensure that ev...
def dfs(graph, node, target_lights, lit, visited, lit_visited, result): if lit_visited == target_lights: result[0] = True return visited[node] = True for neighbor in graph[node]: if not visited[neighbor]: dfs(graph, neighbor, target_lights, lit, visited, lit_visited + (1...
def test_case_1(): n, m, k = 6, 7, 3 lit = [3, 5, 6] edges = [(1, 2), (2, 3), (3, 4), (4, 5), (5, 6), (6, 1), (1, 3)] assert is_route_with_exactly_k_lit_intersections(n, m, k, lit, edges) == "YES" def test_case_2(): n, m, k = 6, 7, 2 lit = [3, 5] edges = [(1, 2), (2, 3), (3, 4), (4, 5), (5,...
[ { "docstring": null, "function_declaration": "def dfs(graph, node, target_lights, lit, visited, lit_visited, result):", "function_name": "dfs", "parameter_list": "(graph, node, target_lights, lit, visited, lit_visited, result)" }, { "docstring": null, "function_declaration": "def is_rout...
[ 0, 0, 0, 0, 0, 0, 0, 0, 1, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def parade_route_exists(n, m, k, lit_intersections, streets):\n from collections import defaultdict, deque\n \n lit_intersections_set = set(lit_inter...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00006091", "row_id": 6091, "seed_ids": "[5330]" }
0.711267
Codeforces_6091
I
[ "dfs", "is_route_with_exactly_k_lit_intersections" ]
2
[ [ "is_route_with_exactly_k_lit_intersections", "dfs" ] ]
1
[]
false
[]
false
pytest
false
[]
true
24e79c7a7399329f1e1aec1abba4f4e562d651a9
1a65531a6c6233139e6861ba012fa7b13e167f5d
v1.0
instruct
Codeforces
Codeforces_6122_I
The International Space Station (ISS) needs a new scheduling system for experiments. The ISS operates on an Earth-standard 24-hour day (00:00 to 23:59). The astronauts have a list of experiment start and end times they need to fit into a day’s schedule. Given the list of experiments and their durations, it is necessary...
from typing import List, Tuple def to_minutes(time_str: str) -> int: """ Convert a time string in format "HH:MM" to minutes since midnight. """ hours, minutes = map(int, time_str.split(':')) return hours * 60 + minutes def experiments_conflict(experiments: List[Tuple[str, str]]) -> str: times ...
def test_no_conflict(): experiments = [("09:00", "10:00"), ("10:00", "11:00"), ("11:30", "12:30")] assert experiments_conflict(experiments) == "NO CONFLICT" def test_conflict(): experiments = [("09:00", "10:00"), ("09:30", "10:30"), ("11:00", "12:00")] assert experiments_conflict(experiments) == "CONFL...
[ { "docstring": "Convert a time string in format \"HH:MM\" to minutes since midnight.", "function_declaration": "def to_minutes(time_str):", "function_name": "to_minutes", "parameter_list": "(time_str)" }, { "docstring": null, "function_declaration": "def experiments_conflict(experiments)...
[ 1, 1, 0, 1, 1, 1, 1, 1, 1, 0 ]
8
easy
0.8
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "from typing import List, Tuple\n\ndef time_to_minutes(time: str) -> int:\n \"\"\"\n Convert time in \"HH:MM\" format to minutes since midnight.\n \"\...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00006122", "row_id": 6122, "seed_ids": "[6219]" }
0.58617
Codeforces_6122
I
[ "to_minutes", "experiments_conflict" ]
2
[ [ "experiments_conflict", "to_minutes" ] ]
1
[]
false
[]
false
pytest
false
[]
true
74fcbcf90602f78b62fbeb7d2dcac6f8a3f71bd7
edb7032181d4450c1669683783c133c661f1cb16
v1.0
instruct
Codeforces
Codeforces_6125_I
You are given a list of integers. Your task is to determine whether the list contains any duplicate elements. Input The input consists of a single line containing a space-separated list of integers, where each integer \(n\) (-10^6 <= \(n\) <= 10^6). Output Output "YES" if any integer appears more than once in the lis...
def contains_duplicates(numbers): """ Returns 'YES' if there are duplicate numbers in the list, otherwise 'NO'. """ # Create a set to store unique numbers seen = set() for number in numbers: if number in seen: return "YES" seen.add(number) return "NO" d...
from solution import contains_duplicates, check_duplicate_numbers def test_no_duplicates(): assert check_duplicate_numbers("1 2 3 4 5") == "NO" def test_with_duplicates(): assert check_duplicate_numbers("1 2 3 4 4") == "YES" def test_empty_list(): assert check_duplicate_numbers("") == "NO" def test_sing...
[ { "docstring": "Returns 'YES' if there are duplicate numbers in the list, otherwise 'NO'.", "function_declaration": "def contains_duplicates(numbers):", "function_name": "contains_duplicates", "parameter_list": "(numbers)" }, { "docstring": "Parses the input string and invokes the contains_d...
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
10
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def contains_duplicates(integers):\n \"\"\"\n Returns \"YES\" if the input list contains any duplicate elements, otherwise \"NO\".\n \"\"\"\n inte...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00006125", "row_id": 6125, "seed_ids": "[5221]" }
0.719404
Codeforces_6125
I
[ "contains_duplicates", "check_duplicate_numbers" ]
2
[ [ "check_duplicate_numbers", "contains_duplicates" ] ]
1
[]
false
[]
false
pytest
true
[]
true
9ef3427a0a2ecc178df44e52d4c83f02fc6a5849
0ed69e81e5078bfbf62cce32717bb706791112dd
v1.0
instruct
Codeforces
Codeforces_6126_I
You are organizing a programming competition and need to randomly pair up contestants for each round. You have a list of contestant names and need to ensure that every contestant is paired with exactly one other contestant. If the list has an odd number of contestants, one contestant will be left without a pair. Additi...
import random def generate_pairs(contestants): """ Generate unique pairs of contestants for a round. """ # Randomly shuffle the contestants' names for pairing random.shuffle(contestants) pairs = [] i = 0 while i < len(contestants) - 1: pairs.append((contestants[i], contesta...
from solution import generate_pairs, avoid_repeated_pairs def test_generate_pairs_even(): contestants = ["Alice", "Bob", "Charlie", "Dave"] pairs = generate_pairs(contestants) assert len(pairs) == 2 # Two pairs [("Alice", "Bob"), ("Charlie", "Dave")] def test_generate_pairs_odd(): contestants = ["Ali...
[ { "docstring": "Generate unique pairs of contestants for a round.", "function_declaration": "def generate_pairs(contestants):", "function_name": "generate_pairs", "parameter_list": "(contestants)" }, { "docstring": "For multiple rounds of contests, avoid repeated pairs, including reversed pa...
[ 1, 1, 0, 1, 0, 0, 0, 0 ]
3
medium
0.375
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "import random\n\ndef generate_pairs(rounds):\n \"\"\"\n Generate unique pairs of contestants for each round.\n\n :param rounds: List of tuples, where...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00006126", "row_id": 6126, "seed_ids": "[932]" }
0.629476
Codeforces_6126
I
[ "generate_pairs", "avoid_repeated_pairs" ]
2
[ [ "avoid_repeated_pairs", "generate_pairs" ] ]
1
[]
false
[]
false
pytest
true
[]
true
86b7651595a2861b437dd6b7a961c3d00e50638c
8354d7dc8d400f12b341abe0486582694009e84d
v1.0
instruct
Codeforces
Codeforces_6140_I
Alice and Bob are playing a game with numbers. The game starts with a non-negative integer $$$n$$$. Alice wants to test Bob's abilities by giving him the reverse of this number, $$$m$$$, but with a twist. She will remove any leading zeroes from the reversed number. Bob's task is to determine if $$$m$$$ is a prime numb...
def reverse_and_remove_leading_zeros(n): """ Reverses the digits of n and removes any leading zeros from the reversed number. """ reversed_n = str(n)[::-1].lstrip('0') return int(reversed_n) def is_prime(m): """ Determines if a number m is a prime number. """ if m <= 1: retu...
from solution import reverse_prime, reverse_and_remove_leading_zeros, is_prime def test_reverse_and_remove_leading_zeros(): assert reverse_and_remove_leading_zeros(104) == 401 assert reverse_and_remove_leading_zeros(100) == 1 assert reverse_and_remove_leading_zeros(1200) == 21 assert reverse_and_remove...
[ { "docstring": "Reverses the digits of n and removes any leading zeros from the reversed number.", "function_declaration": "def reverse_and_remove_leading_zeros(n):", "function_name": "reverse_and_remove_leading_zeros", "parameter_list": "(n)" }, { "docstring": "Determines if a number m is a...
[ 1, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def reverse_and_remove_leading_zeros(n):\n \"\"\"\n Reverses the digits of n and removes any leading zeros from the reversed number.\n \"\"\"\n re...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00006140", "row_id": 6140, "seed_ids": "[8305]" }
0.617676
Codeforces_6140
I
[ "reverse_and_remove_leading_zeros", "is_prime", "reverse_prime" ]
3
[ [ "reverse_prime", "is_prime" ], [ "reverse_prime", "reverse_and_remove_leading_zeros" ] ]
2
[]
false
[]
false
pytest
true
[]
true
89c9b7a23a4ac2b906254975627ebea5f3012e60
dac04e00c26f78208ced371215a802242a9240ee
v1.0
instruct
Codeforces
Codeforces_6161_I
In a country, there are $$$n$$$ cities and $$$m$$$ bidirectional roads connecting them. The cities are numbered from $$$1$$$ to $$$n$$$. Each road has a certain weight, representing the time it takes to travel that road. The government wants to improve the transportation system by ensuring that there's at least one pa...
def find(parent, i): if parent[i] == i: return i else: parent[i] = find(parent, parent[i]) return parent[i] def union(parent, rank, x, y): rootX = find(parent, x) rootY = find(parent, y) if rootX != rootY: if rank[rootX] > rank[rootY]: parent[rootY] = roo...
from solution import minimum_new_roads def test_all_connected(): assert minimum_new_roads(4, [(1, 2, 1), (2, 3, 1), (3, 4, 1)]) == 0 def test_disjoint_sets(): assert minimum_new_roads(6, [(1, 2, 3), (2, 3, 2), (4, 5, 4), (5, 6, 6)]) == 1 def test_single_city(): assert minimum_new_roads(1, []) == 0 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, 0, 0, 0, 1, 1, 0 ]
2
hard
0.222
{ "trial_gpt4o_0": null, "trial_gpt4o_1": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared1_results_combined.jsonl", "solution_code": "def find(parent, i):\n if parent[i] == i:\n return i\n return find(parent, parent[i])\n\ndef union(parent, rank, x, y):\...
trial_gpt4o_7
{ "original_instruction": "", "prompt_id": "00006161", "row_id": 6161, "seed_ids": "[8224]" }
0.775663
Codeforces_6161
I
[ "find", "union", "minimum_new_roads" ]
3
[ [ "minimum_new_roads", "find" ], [ "minimum_new_roads", "union" ], [ "union", "find" ] ]
3
[]
false
[]
false
pytest
true
[]
true
5025c573106a6bfce1f8b723bed6495b1c6c1128
3d8ac1afe5ed55d8b02fffb4ee2d82dcfeed472e
v1.0
instruct
Codeforces
Codeforces_6165_I
You are given a grid containing only the characters '0' and '1'. Each '0' represents an empty cell, and each '1' represents an obstacle. You are initially positioned at the top-left corner of the grid (0, 0) and you want to reach the bottom-right corner of the grid (n-1, m-1). You can move up, down, left, or right, and...
from collections import deque def min_time_to_reach_end(grid): """ Returns the minimum time required to reach the bottom-right corner of the grid from the top-left corner, or -1 if it's impossible. """ n = len(grid) m = len(grid[0]) if grid[0][0] == '1' or grid[n-1][m-1] == '1': re...
from solution import min_time_required def test_basic_case(): n, m = 3, 3 grid = ["001", "010", "000"] assert min_time_required(n, m, grid) == 4 def test_no_path(): n, m = 3, 3 grid = ["011", "111", "111"] assert min_time_required(n, m, grid) == -1 def test_all_zeros(): n, m = 5, 5 gr...
[ { "docstring": "Returns the minimum time required to reach the bottom-right corner \nof the grid from the top-left corner, or -1 if it's impossible.", "function_declaration": "def min_time_to_reach_end(grid):", "function_name": "min_time_to_reach_end", "parameter_list": "(grid)" }, { "docstr...
[ 0, 0, 0, 1, 0, 1, 0, 1, 1, 0 ]
4
medium
0.4
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "from collections import deque\n\ndef min_time_to_reach_bottom_right(n, m, grid):\n if not grid or grid[0][0] == '1' or grid[-1][-1] == '1':\n return...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00006165", "row_id": 6165, "seed_ids": "[6059]" }
0.766797
Codeforces_6165
I
[ "min_time_to_reach_end", "min_time_required" ]
2
[ [ "min_time_required", "min_time_to_reach_end" ] ]
1
[]
false
[]
false
pytest
true
[]
true
def068b7d4762ce779b8969a614ab454d7f5706c
1ad9c2772fc597e92486c316601bdaad176e28d5
v1.0
instruct
Codeforces
Codeforces_6167_I
In a certain kingdom, there are multiple cities connected through a network of roads. The cities can be represented as nodes in a graph, and the roads as edges connecting these nodes. Over the years, some roads have been destroyed by natural calamities, which disrupted the connectivity between cities. The kingdom want...
def find(parent, i): if parent[i] == i: return i else: parent[i] = find(parent, parent[i]) return parent[i] def union(parent, rank, x, y): rootX = find(parent, x) rootY = find(parent, y) if rootX != rootY: if rank[rootX] > rank[rootY]: parent[rootY] ...
def test_minimum_cost(): input_data = """4 5 1 2 5 1 3 10 2 3 6 2 4 2 3 4 1""" assert minimum_cost_to_connect_all_cities(input_data) == 8 def test_no_roads(): input_data = """3 0""" # Impossible to connect all cities without any roads assert minimum_cost_to_connect_all_cities(input_data) == 0 def ...
[ { "docstring": null, "function_declaration": "def find(parent, i):", "function_name": "find", "parameter_list": "(parent, i)" }, { "docstring": null, "function_declaration": "def union(parent, rank, x, y):", "function_name": "union", "parameter_list": "(parent, rank, x, y)" }, ...
[ 0, 0, 1, 0, 1, 0, 0, 1, 1, 1 ]
5
medium
0.5
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def find(parent, i):\n if parent[i] == i:\n return i\n return find(parent, parent[i])\n\ndef union(parent, rank, x, y):\n xroot = find(parent,...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00006167", "row_id": 6167, "seed_ids": "[8122]" }
0.695522
Codeforces_6167
I
[ "find", "union", "minimum_reconstruction_cost", "process_input", "minimum_cost_to_connect_all_cities" ]
5
[ [ "minimum_cost_to_connect_all_cities", "minimum_reconstruction_cost" ], [ "minimum_cost_to_connect_all_cities", "process_input" ], [ "minimum_reconstruction_cost", "find" ], [ "minimum_reconstruction_cost", "union" ], [ "union", "find" ] ]
5
[ "process_input" ]
false
[]
false
pytest
false
[]
true
d8ec0edf9666e176e5d3a7baa6aab50f1a159458
bcfb3b5de1f89b1da0d4aec44e6483a74af0c752
v1.0
instruct
Codeforces
Codeforces_6172_I
You are given a rectangular grid with rows and columns. Some cells of the grid contain traps, represented by '#', and the remaining cells are either free cells represented by '.', or starting point 'S', or target point 'T'. Your task is to determine if there is a path from the starting point 'S' to the target point '...
def is_path_possible(grid): """ Determines if there is a path from 'S' to 'T' in the given grid without passing through '#'. """ rows = len(grid) cols = len(grid[0]) def find_start_end(): for i in range(rows): for j in range(cols): if grid[i][j] == 'S': ...
def test_path_possible(): grid = [ "S....", ".#...", "...T.", "....." ] assert solve(4, 5, grid) == "YES" def test_path_impossible(): grid = [ "S..#.", ".#.#.", "###..", "..T.." ] assert solve(4, 5, grid) == "NO" def test_no_traps...
[ { "docstring": "Determines if there is a path from 'S' to 'T' in the given grid without passing through '#'.", "function_declaration": "def is_path_possible(grid):", "function_name": "is_path_possible", "parameter_list": "(grid)" }, { "docstring": null, "function_declaration": "def solve...
[ 0, 1, 0, 0, 1, 0, 0, 1, 1, 0 ]
4
medium
0.4
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_path_exist(grid):\n from collections import deque\n\n # Helper function to find the position of 'S' and 'T'\n def find_positions(grid):\n ...
trial_gpt4o_7
{ "original_instruction": "", "prompt_id": "00006172", "row_id": 6172, "seed_ids": "[1810]" }
0.715853
Codeforces_6172
I
[ "is_path_possible", "solve" ]
2
[ [ "solve", "is_path_possible" ] ]
1
[]
false
[]
false
pytest
false
[]
true
ae3da99298f4ca5a9a85a5fc1155938c23a59085
594f32a2890b936475b086c1d5906f808e92c05b
v1.0
instruct
Codeforces
Codeforces_6190_I
You are given a rectangular farm represented as a grid with `m x n` cells. Each cell can either be empty (represented by '.') or have a tree (represented by 'T'). Two friends are standing on two distinct empty cells, and they want to meet each other by the shortest path. They can move up, down, left, or right and canno...
from collections import deque def bfs_shortest_path(grid, start, end, m, n): queue = deque([(start[0], start[1], 0)]) # (x, y, distance) visited = set() visited.add((start[0], start[1])) directions = [(-1, 0), (1, 0), (0, -1), (0, 1)] while queue: x, y, dist = queue.popleft() ...
from solution import minimum_steps_to_meet def test_example_case(): m, n = 5, 5 grid = [ ['.', '.', '.', '.', '.'], ['.', 'T', '.', '.', 'T'], ['.', '.', '.', '.', '.'], ['T', '.', '.', '.', '.'], ['.', '.', '.', '.', '.'], ] friend1 = (1, 1) friend2 = (4, 4)...
[ { "docstring": null, "function_declaration": "def bfs_shortest_path(grid, start, end, m, n):", "function_name": "bfs_shortest_path", "parameter_list": "(grid, start, end, m, n)" }, { "docstring": null, "function_declaration": "def minimum_steps_to_meet(m, n, grid, friend1, friend2):", ...
[ 0, 0, 0, 0, 1, 0, 0, 0, 0, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "from collections import deque\n\ndef min_steps_to_meet(m, n, t, grid, empty_cells, friend1, friend2):\n \"\"\"\n Returns the minimum number of steps req...
trial_gpt4o_4
{ "original_instruction": "", "prompt_id": "00006190", "row_id": 6190, "seed_ids": "[1390]" }
0.737182
Codeforces_6190
I
[ "bfs_shortest_path", "minimum_steps_to_meet" ]
2
[ [ "minimum_steps_to_meet", "bfs_shortest_path" ] ]
1
[]
false
[]
false
pytest
true
[]
true
91df91c2db424716091b77c6e57be5ca0c7e2b92
89aa0be97f9345a131820784201c6e167244f2b1
v1.0
instruct
Codeforces
Codeforces_6377_I
Create a program that sorts an array of positive integers such that prime numbers in the array appear at the beginning of the array in increasing order, followed by composite numbers in increasing order. The relative order of prime and composite numbers should be maintained from the original array. Input: - The first ...
def sieve_of_eratosthenes(max_num): is_prime = [True] * (max_num + 1) is_prime[0] = is_prime[1] = False p = 2 while (p * p <= max_num): if is_prime[p] == True: for i in range(p * p, max_num + 1, p): is_prime[i] = False p += 1 return is_prime def sort_prim...
from solution import process_array def test_simple_case(): assert process_array(6, [10, 3, 7, 15, 14, 2]) == [2, 3, 7, 10, 14, 15] def test_all_primes(): assert process_array(5, [23, 19, 2, 3, 29]) == [2, 3, 19, 23, 29] def test_all_composites(): assert process_array(5, [4, 6, 8, 10, 12]) == [4, 6, 8, 10...
[ { "docstring": null, "function_declaration": "def sieve_of_eratosthenes(max_num):", "function_name": "sieve_of_eratosthenes", "parameter_list": "(max_num)" }, { "docstring": null, "function_declaration": "def sort_prime_composite(arr):", "function_name": "sort_prime_composite", "...
[ 1, 1, 0, 1, 0, 1, 0, 1, 1, 1 ]
7
easy
0.7
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(num):\n if num <= 1:\n return False\n if num <= 3:\n return True\n if num % 2 == 0 or num % 3 == 0:\n return False\...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00006377", "row_id": 6377, "seed_ids": "[92]" }
0.595221
Codeforces_6377
I
[ "sieve_of_eratosthenes", "sort_prime_composite", "process_array" ]
3
[ [ "process_array", "sort_prime_composite" ], [ "sort_prime_composite", "sieve_of_eratosthenes" ] ]
2
[]
false
[]
false
pytest
true
[]
true
f7e75133603716d79d2b9abe944318c0031db887
bf695c2b75e3242f514437cad158df89d1b0e64c
v1.0
instruct
Codeforces
Codeforces_6417_I
A mega department store uses a unique pricing system for its products. The store labels each product with a base price and a discount percentage that continually rotates in cycles. Each product has a price markdown schedule that goes through k cycles of varying discount percentages. For example, a product may go throu...
def calculate_effective_price(base_price, discount_phases, d, t): phases_count = len(discount_phases) phase_index = (t // d) % phases_count discount_percentage = discount_phases[phase_index] effective_price = base_price * (1 - discount_percentage / 100) return round(effective_price) def calculate_p...
def test_calculate_effective_price(): assert calculate_effective_price(100, [10, 20, 15, 5], 10, 0) == 90 assert calculate_effective_price(100, [10, 20, 15, 5], 10, 15) == 80 assert calculate_effective_price(100, [10, 20, 15, 5], 10, 35) == 95 assert calculate_effective_price(250, [5, 10, 20], 5, 3) == ...
[ { "docstring": null, "function_declaration": "def calculate_effective_price(base_price, discount_phases, d, t):", "function_name": "calculate_effective_price", "parameter_list": "(base_price, discount_phases, d, t)" }, { "docstring": null, "function_declaration": "def calculate_prices_fo...
[ 0, 0, 0, 0, 0, 0, 1, 0, 1, 0 ]
2
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "from math import ceil\n\ndef calculate_effective_price(base_price, k, d, discounts, purchases):\n \"\"\"\n Calculate the effective price of a product fo...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00006417", "row_id": 6417, "seed_ids": "[245]" }
0.684764
Codeforces_6417
I
[ "calculate_effective_price", "calculate_prices_for_customers", "mega_department_store" ]
3
[ [ "calculate_prices_for_customers", "calculate_effective_price" ], [ "mega_department_store", "calculate_prices_for_customers" ] ]
2
[]
false
[]
false
pytest
false
[]
true
20c7893fe220b53f97e9da95936ba69a77736aea
d316a9bf0a379c61b8455118d0e996083ccedb13
v1.0
instruct
Codeforces
Codeforces_6426_I
The Martian rover mission discovered an ancient game board on the surface of Mars, presumed to be used by an extinct civilization. The game board is a grid of size n x m, where each cell can either be passable ('.') or blocked ('#'). The objective of the game is to traverse from the top-left cell (1,1) to the bottom-ri...
def is_valid_move(board, visited, x, y, n, m): return 0 <= x < n and 0 <= y < m and board[x][y] == '.' and not visited[x][y] def dfs(board, visited, x, y, n, m): stack = [(x, y)] while stack: cx, cy = stack.pop() if cx == n-1 and cy == m-1: return True for nx, ny in [(c...
def test_check_path_possible(): n, m = 3, 3 board_str = [ "...", ".#.", "..." ] assert solve(n, m, board_str) == "YES" def test_check_path_not_possible(): n, m = 4, 4 board_str = [ "..#.", "..#.", "##..", "...." ] assert solve(n, m...
[ { "docstring": null, "function_declaration": "def is_valid_move(board, visited, x, y, n, m):", "function_name": "is_valid_move", "parameter_list": "(board, visited, x, y, n, m)" }, { "docstring": null, "function_declaration": "def dfs(board, visited, x, y, n, m):", "function_name": "...
[ 0, 0, 0, 0, 1, 0, 0, 0, 0, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_path_possible(n, m, grid):\n from collections import deque\n\n def neighbors(x, y):\n for dx, dy in [(-1, 0), (1, 0), (0, -1), (0, 1)]:\n ...
trial_gpt4o_4
{ "original_instruction": "", "prompt_id": "00006426", "row_id": 6426, "seed_ids": "[1389]" }
0.656957
Codeforces_6426
I
[ "is_valid_move", "dfs", "check_path", "solve" ]
4
[ [ "check_path", "dfs" ], [ "dfs", "is_valid_move" ], [ "solve", "check_path" ] ]
3
[]
false
[]
false
pytest
false
[]
true
bf43c6eccaf5a9aa408abbdac330effd6e262e97
5e1538e8a07f0669282950d5f65bcd4381817dd5
v1.0
instruct
Codeforces
Codeforces_6475_I
You are given a 2D grid representing a map of a city. Each cell in the grid can either be a building (denoted by 1) or an empty lot (denoted by 0). The roads in this city are aligned with the boundaries of the cells, meaning that you can move from one cell to an adjacent cell if this cell is an empty lot. Cars can tra...
from collections import deque def min_steps_to_destination(grid, start, destination): n = len(grid) m = len(grid[0]) directions = [(1, 0), (-1, 0), (0, 1), (0, -1)] start = (start[0] - 1, start[1] - 1) destination = (destination[0] - 1, destination[1] - 1) if start == destination: ...
from solution import solve def test_min_steps_basic(): city_grid_input = "5 5\n0 0 1 0 0\n0 1 0 1 0\n0 0 0 0 0\n0 1 0 1 0\n0 0 0 0 0\n1 1 5 5" assert solve(city_grid_input) == 8 def test_min_steps_direct_path(): city_grid_input = "3 3\n0 0 0\n0 1 0\n0 0 0\n1 1 3 3" assert solve(city_grid_input) == 4 ...
[ { "docstring": null, "function_declaration": "def min_steps_to_destination(grid, start, destination):", "function_name": "min_steps_to_destination", "parameter_list": "(grid, start, destination)" }, { "docstring": null, "function_declaration": "def parse_input(input_string):", "funct...
[ 0, 1, 0, 1, 1, 1, 1, 0, 0, 1 ]
6
medium
0.6
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "from collections import deque\n\ndef min_steps(grid, start, end):\n \"\"\"\n Finds the minimum number of steps to travel from start to end in a grid.\n ...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00006475", "row_id": 6475, "seed_ids": "[4769]" }
0.760304
Codeforces_6475
I
[ "min_steps_to_destination", "parse_input", "solve" ]
3
[ [ "solve", "min_steps_to_destination" ], [ "solve", "parse_input" ] ]
2
[ "parse_input" ]
false
[]
false
pytest
true
[]
true
388c262bd7f1940c7c815c0143c2f63867ae2d17
fd7ae495372d6e2d9af8342c4d3b714567bb79ab
v1.0
instruct
Codeforces
Codeforces_6528_I
A logistics company uses a transportation network represented as a directed weighted graph where nodes represent warehouses and edges represent roads with known distances. The company wants to find the shortest delivery route from one warehouse to another, possibly passing through other warehouses. Your task is to help...
import heapq def dijkstra(n, edges, start, end): graph = {i: [] for i in range(1, n + 1)} for u, v, w in edges: graph[u].append((v, w)) dist = {i: float('inf') for i in range(1, n + 1)} dist[start] = 0 pq = [(0, start)] while pq: current_dist, node = heapq.heappop(pq) ...
from solution import shortest_path def test_direct_path(): n, m = 4, 4 edges = [(1, 2, 3), (2, 3, 4), (3, 4, 5), (1, 4, 10)] s, t = 1, 4 assert shortest_path(n, m, edges, s, t) == 10 def test_shortest_via_other(): n, m = 4, 4 edges = [(1, 2, 3), (2, 3, 4), (3, 4, 1), (1, 4, 10)] s, t = 1, ...
[ { "docstring": null, "function_declaration": "def dijkstra(n, edges, start, end):", "function_name": "dijkstra", "parameter_list": "(n, edges, start, end)" }, { "docstring": null, "function_declaration": "def shortest_path(n, m, edge_list, s, t):", "function_name": "shortest_path", ...
[ 1, 0, 1, 1, 1, 0, 1, 1, 0, 0 ]
6
medium
0.6
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "import heapq\n\ndef shortest_path(n, m, edges, s, t):\n graph = {i: [] for i in range(1, n+1)}\n for u, v, w in edges:\n graph[u].append((v, w))\...
trial_gpt4o_7
{ "original_instruction": "", "prompt_id": "00006528", "row_id": 6528, "seed_ids": "[181]" }
0.791437
Codeforces_6528
I
[ "dijkstra", "shortest_path" ]
2
[ [ "shortest_path", "dijkstra" ] ]
1
[]
false
[]
false
pytest
true
[]
true
09f2636d3315326dff2bdec786eac4f746a15ac6
2ddab236d423702c22a9139f346044c1bad438c6
v1.0
instruct
Codeforces
Codeforces_6687_I
Alex loves sequences of numbers. Specifically, Alex is fascinated by sequences where the sum of any two adjacent elements is prime. You are given an integer array and need to determine if it's possible to rearrange the array such that it meets Alex's condition. Given an array of integers, determine if the array can be...
from itertools import permutations 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 can_re...
from solution import sequence_prime_sum def test_sequence_prime_sum_example1(): n = 3 array = [1, 2, 3] assert sequence_prime_sum(n, array).startswith("YES") def test_sequence_prime_sum_example2(): n = 4 array = [4, 6, 8, 10] assert sequence_prime_sum(n, array) == "NO" def test_sequence_prime...
[ { "docstring": null, "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": null, "function_declaration": "def can_rearrange_with_prime_sums(arr):", "function_name": "can_rearrange_with_prime_sums", "parameter_list": "(a...
[ 0, 0, 1, 0, 0, 0, 0, 0, 0 ]
1
hard
0.111
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(n):\n \"\"\" Helper function to check if a number is prime \"\"\"\n if n <= 1:\n return False\n if n == 2:\n return True\n...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00006687", "row_id": 6687, "seed_ids": "[1207]" }
0.660862
Codeforces_6687
I
[ "is_prime", "can_rearrange_with_prime_sums", "sequence_prime_sum" ]
3
[ [ "can_rearrange_with_prime_sums", "is_prime" ], [ "sequence_prime_sum", "can_rearrange_with_prime_sums" ] ]
2
[]
false
[]
false
pytest
true
[]
true
f65e8dc39877708b56da5169a720d325b80ea5ef
8f560a8a3a7f30de94d7954af98741db45a15f84
v1.0
instruct
Codeforces
Codeforces_6713_I
Alice loves playing with strings. She has two strings, s1 and s2, of lengths n and m respectively. She wants to find out the minimum number of operations required to transform s1 into s2. The operations allowed are: 1. Insert a character at any position in s1. 2. Delete a character from s1. 3. Replace a character in s...
def min_distance(s1, s2): """ Calculate the minimum number of operations required to transform s1 into s2 using insertion, deletion, and replacement operations. """ n = len(s1) m = len(s2) # Initialize a matrix to store the minimum edit distances. dp = [[0] * (m + 1) for _ in range(...
from solution import run_transformations def test_example_case_1(): test_input = [2, 5, 3, 'abcde', 'bcd', 3, 4, 'abc', 'adc'] expected_output = [2, 1] assert run_transformations(test_input) == expected_output def test_example_case_2(): test_input = [1, 4, 5, 'abcd', 'abcde'] expected_output = [1]...
[ { "docstring": "Calculate the minimum number of operations required to transform s1 into s2 using\ninsertion, deletion, and replacement operations.", "function_declaration": "def min_distance(s1, s2):", "function_name": "min_distance", "parameter_list": "(s1, s2)" }, { "docstring": null, ...
[ 1, 1, 1, 1, 1, 1, 0, 0, 0 ]
6
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def min_operations_string(s1, s2):\n \"\"\"\n Returns the minimum number of operations required to transform s1 into s2.\n Operations allowed are ins...
trial_gpt4o_6
{ "original_instruction": "", "prompt_id": "00006713", "row_id": 6713, "seed_ids": "[5519]" }
0.738718
Codeforces_6713
I
[ "min_distance", "transform_strings_transformations", "run_transformations" ]
3
[ [ "run_transformations", "transform_strings_transformations" ], [ "transform_strings_transformations", "min_distance" ] ]
2
[]
false
[]
false
pytest
true
[]
true
44efa6f48ea0a9a5d0c8f1581dc4c83310217bd8
25326c02490962ac644d3051a2924135e9ade837
v1.0
instruct
Codeforces
Codeforces_6762_I
### Allocate Tasks to Workers You have a work schedule to assign tasks to workers. Each task requires a specific time to complete, and each worker has a maximum number of hours they can work per day. The goal is to determine the minimum number of workers needed to complete all tasks within one day. The first line of ...
def min_workers_to_complete_tasks(task_times, max_hours_per_worker): task_times.sort(reverse=True) workers = [] for task_time in task_times: placed = False for i in range(len(workers)): if workers[i] + task_time <= max_hours_per_worker: workers[i] += task_time ...
from solution import allocate_tasks_to_workers def test_example_case(): n = 5 task_times = [4, 3, 2, 5, 6] max_hours_per_worker = 8 assert allocate_tasks_to_workers(n, task_times, max_hours_per_worker) == 3 def test_single_task_fits(): n = 1 task_times = [4] max_hours_per_worker = 8 as...
[ { "docstring": null, "function_declaration": "def min_workers_to_complete_tasks(task_times, max_hours_per_worker):", "function_name": "min_workers_to_complete_tasks", "parameter_list": "(task_times, max_hours_per_worker)" }, { "docstring": null, "function_declaration": "def allocate_task...
[ 0, 0, 1, 0, 0, 1, 0, 0, 0 ]
2
hard
0.222
{ "trial_gpt4o_0": null, "trial_gpt4o_1": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared1_results_combined.jsonl", "solution_code": "def min_workers(tasks, max_hours):\n \"\"\"\n Returns the minimum number of workers required to complete all tasks within a sin...
trial_gpt4o_6
{ "original_instruction": "", "prompt_id": "00006762", "row_id": 6762, "seed_ids": "[4059]" }
0.707951
Codeforces_6762
I
[ "min_workers_to_complete_tasks", "allocate_tasks_to_workers" ]
2
[ [ "allocate_tasks_to_workers", "min_workers_to_complete_tasks" ] ]
1
[]
false
[]
false
pytest
true
[]
true
a1c2d5106e4bf2132190605487483538db859e4d
7ba115510d2af38d0429d39d5c3aec41b74dd224
v1.0
instruct
Codeforces
Codeforces_6783_I
You are given a binary tree with `n` nodes. Each node contains a positive integer data value. The binary tree follows the property that for any given node, its left child has a value less than the node's value, and its right child has a value greater than the node's value. Your task is to find the maximum sum of value...
class TreeNode: def __init__(self, value): self.value = value self.left = None self.right = None def build_tree(node_values): nodes = {} for value, left, right in node_values: if value not in nodes: nodes[value] = TreeNode(value) if left != -1: ...
def test_max_sum_from_root_to_leaf(): t = 1 test_cases = [ (5, (10, 7, 15), (7, -1, 9), (15, 13, 20), (13, -1, -1), (9, -1, -1), (20, -1, -1)) ] assert max_sum_from_root_to_leaf(t, test_cases) == [45] def test_max_sum_from_root_to_leaf...
[]
[ 1, 0, 1, 0, 0, 0, 1, 0, 0 ]
3
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "class TreeNode:\n def __init__(self, value):\n self.value = value\n self.left = None\n self.right = None\n\ndef build_tree(node_values...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00006783", "row_id": 6783, "seed_ids": "[4922]" }
0.669831
Codeforces_6783
I
[ "build_tree", "max_sum_path", "max_sum_from_root_to_leaf" ]
3
[ [ "max_sum_from_root_to_leaf", "build_tree" ], [ "max_sum_from_root_to_leaf", "max_sum_path" ] ]
2
[]
false
[ "TreeNode" ]
true
pytest
false
[]
true
c68605db5b71da2e8d30975bc98f32709b27aae4
73a5017f813a00637771f0af706e42c25d29c299
v1.0
instruct
Codeforces
Codeforces_6803_I
You are provided with two stacks of coins. The first stack contains `a` coins and the second stack contains `b` coins. Two players alternate turns, with Player 1 acting first. On a player's turn, they can choose to either remove 1 coin or a prime number of coins from one of the stacks. The player who cannot make any mo...
def is_prime(n): """Helper function to check if a number is prime""" if n <= 1: return False if n <= 3: return True if n % 2 == 0 or n % 3 == 0: return False i = 5 while i * i <= n: if n % i == 0 or n % (i + 2) == 0: return False i += 6 ret...
from solution import determine_winner def test_case_1(): assert determine_winner(5, 7) == "Player 1" def test_case_2(): assert determine_winner(1, 1) == "Player 2" def test_case_3(): assert determine_winner(4, 4) == "Player 2" def test_case_4(): assert determine_winner(10, 15) == "Player 1" def tes...
[ { "docstring": "Helper function to check if a number is prime", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Compute the Grundy number for a given pile size", "function_declaration": "def find_grundy_number(n):", ...
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def sieve(n):\n \"\"\"\n Returns a list of prime numbers up to n (inclusive).\n \"\"\"\n is_prime = [True] * (n + 1)\n p = 2\n while (p * p ...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00006803", "row_id": 6803, "seed_ids": "[2023]" }
0.769895
Codeforces_6803
I
[ "is_prime", "find_grundy_number", "determine_winner" ]
3
[ [ "determine_winner", "find_grundy_number" ], [ "find_grundy_number", "is_prime" ] ]
2
[]
false
[]
false
pytest
true
[]
true
86a74423dc8389b89e11b46d9a782f8c4aa9f3ea
06b920d5f0962b4980462e6899a5d613365db342
v1.0
instruct
Codeforces
Codeforces_6809_I
You are given a binary tree with integer values on each node. Your task is to compute the sum of all values of nodes that are at the same level as the target node. ### Input - The first line contains an integer $$$n$$$ ($$$1 \leq n \leq 10^4$$$), the number of nodes in the binary tree. - The next $$$n$$$ lines each co...
from collections import deque, defaultdict class TreeNode: def __init__(self, value): self.value = value self.left = None self.right = None def build_tree(tree_data): nodes = {} for v, l, r in tree_data: if v not in nodes: nodes[v] = TreeNode(v) if l != ...
from solution import sum_of_values_at_same_level def test_example_case(): n = 7 tree_data = [ (1, 2, 3), (2, 4, 5), (3, 6, 7), (4, -1, -1), (5, -1, -1), (6, -1, -1), (7, -1, -1) ] target = 5 assert sum_of_values_at_same_level(tree_data, target...
[]
[ 0, 1, 0, 0, 0, 0, 0, 0, 0, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_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 su...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00006809", "row_id": 6809, "seed_ids": "[3146]" }
0.664534
Codeforces_6809
I
[ "build_tree", "find_level_sums_and_target_level", "sum_of_values_at_same_level" ]
3
[ [ "sum_of_values_at_same_level", "build_tree" ], [ "sum_of_values_at_same_level", "find_level_sums_and_target_level" ] ]
2
[]
false
[ "TreeNode" ]
true
pytest
true
[]
true
489a57e3e34816f40884d97cfec92252e165b48c
dff26c84f9ffedfce2d6e903b36a90b091093099
v1.0
instruct
Codeforces
Codeforces_6871_I
Given an array of `k` lists of sorted integers, merge them into one sorted list. The input begins with an integer `k` ($$$1 \leq k \leq 10^3$$$), the number of lists. Each of the next `k` lines contains the elements of a list, prefixed by an integer `n_i` ($$$1 \leq n_i \leq 10^3$$$), the number of elements in the resp...
import heapq def merge_k_sorted_lists(lists): """ Merges k sorted lists into one sorted list. Parameters: lists: List of lists, where each list is sorted. Returns: A single sorted list containing all elements of the k lists. """ min_heap = [] for l in lists: ...
from solution import merge_k_sorted_lists, parse_input, solve def test_merge_k_sorted_lists(): lists = [ [-10, -5, 0, 5], [2, 4, 8], [-7, -3, 1, 9, 10] ] assert merge_k_sorted_lists(lists) == [-10, -7, -5, -3, 0, 1, 2, 4, 5, 8, 9, 10] def test_parse_input(): input_data = "3\n4 ...
[ { "docstring": "Merges k sorted lists into one sorted list.\n\nParameters:\n lists: List of lists, where each list is sorted.\n \nReturns:\n A single sorted list containing all elements of the k lists.", "function_declaration": "def merge_k_sorted_lists(lists):", "function_name": "merge_k_sorte...
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
10
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "import heapq\n\ndef merge_k_sorted_lists(input_lists):\n \"\"\"\n Merge k sorted lists into one sorted list.\n \"\"\"\n min_heap = []\n for lst...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00006871", "row_id": 6871, "seed_ids": "[5384]" }
0.611595
Codeforces_6871
I
[ "merge_k_sorted_lists", "parse_input", "solve" ]
3
[ [ "solve", "merge_k_sorted_lists" ], [ "solve", "parse_input" ] ]
2
[ "parse_input" ]
false
[]
false
pytest
true
[]
true
7e2ca99c7f8767f5599783499fd4dfea7809f219
f17ee4f399b705b47296b255123e2d508959115b
v1.0
instruct
Codeforces
Codeforces_6908_I
There is an undirected graph with $$$n$$$ nodes and $$$m$$$ edges. Each edge connects two nodes $$$u$$$ and $$$v$$$, and is assigned a weight $$$w$$$. Your task is to determine if there exists a path between any two given nodes $$$a$$$ and $$$b$$$ such that the maximum weight of the edges in this path is minimized. Th...
import heapq from collections import defaultdict, deque def can_reach_with_max_weight(graph, start, end, max_weight, n): visited = [False] * n queue = deque([start]) while queue: node = queue.popleft() if node == end: return True for neighbor, weight in gra...
def test_minimize_max_edge_weight(): assert minimize_max_edge_weight(4, 4, [(1, 2, 2), (2, 3, 2), (2, 4, 5), (3, 4, 6)], 1, 4) == 5 def test_no_path(): assert minimize_max_edge_weight(4, 2, [(1, 2, 10), (2, 3, 10)], 1, 4) == -1 def test_single_node(): assert minimize_max_edge_weight(1, 0, [], 1, 1) == 0 ...
[ { "docstring": null, "function_declaration": "def can_reach_with_max_weight(graph, start, end, max_weight, n):", "function_name": "can_reach_with_max_weight", "parameter_list": "(graph, start, end, max_weight, n)" }, { "docstring": null, "function_declaration": "def minimize_max_edge_wei...
[ 0, 0, 0, 0, 0, 0, 0, 0, 1, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "import heapq\n\ndef minimize_max_edge_weight(n, m, edges, a, b):\n graph = [[] for _ in range(n + 1)]\n for u, v, w in edges:\n graph[u].append((...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00006908", "row_id": 6908, "seed_ids": "[85]" }
0.876399
Codeforces_6908
I
[ "can_reach_with_max_weight", "minimize_max_edge_weight" ]
2
[ [ "minimize_max_edge_weight", "can_reach_with_max_weight" ] ]
1
[]
false
[]
false
pytest
false
[]
true
c8da851591d96948413a1fc6bd4cc746272e773a
33c105cb21844a8c034a0fad94478746912149be
v1.0
instruct
Codeforces
Codeforces_6967_I
You are given a matrix of size n x m where each cell contains an integer representing the height of that cell's terrain. Your task is to find the minimum effort required for an ant to travel from the top-left cell (0,0) to the bottom-right cell (n-1,m-1). The ant can travel to a neighboring cell (left, right, up, or ...
import heapq def minimum_effort_path(heights): def can_travel(k): rows, cols = len(heights), len(heights[0]) visited = [[False for _ in range(cols)] for _ in range(rows)] pq = [(0, 0, 0)] # (effort, row, col) directions = [(1, 0), (-1, 0), (0, 1), (0, -1)] while pq...
from solution import ant_travel_min_effort def test_example_case(): matrix = [ [1, 2, 2], [3, 8, 2], [5, 3, 5] ] assert ant_travel_min_effort(matrix) == 2 def test_single_row(): matrix = [ [1, 2, 3, 4] ] assert ant_travel_min_effort(matrix) == 1 def test_single...
[ { "docstring": null, "function_declaration": "def minimum_effort_path(heights):", "function_name": "minimum_effort_path", "parameter_list": "(heights)" }, { "docstring": null, "function_declaration": "def ant_travel_min_effort(matrix):", "function_name": "ant_travel_min_effort", ...
[ 0, 0, 0, 0, 0, 1, 0, 0, 0, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "from heapq import heappush, heappop\n\ndef minimumEffortPath(heights):\n def canCross(threshold):\n n, m = len(heights), len(heights[0])\n vi...
trial_gpt4o_5
{ "original_instruction": "", "prompt_id": "00006967", "row_id": 6967, "seed_ids": "[6846]" }
0.651548
Codeforces_6967
I
[ "minimum_effort_path", "ant_travel_min_effort" ]
2
[ [ "ant_travel_min_effort", "minimum_effort_path" ] ]
1
[]
false
[]
false
pytest
true
[]
true
a51a36b235d105565d5b3f7d352cb7c414a3c8fc
313d9e6bbf00223b4c5c357bdfe91de18bb96aee
v1.0
instruct
Codeforces
Codeforces_7046_I
Tom is working on a binary tree and needs to determine certain properties about it. Each node in the tree contains a unique integer value. Here is the problem: Given the root of a binary tree, a target value, and an integer k, find the number of nodes that are at an exact distance of k from the node that contains the ...
from collections import deque class TreeNode: def __init__(self, value=0, left=None, right=None): self.value = value self.left = left self.right = right def countNodesAtDistanceK(root, target, k): if not root: return 0 # Find the target node target_node = findTargetNod...
def test_countNodesAtDistanceK_example(): root = TreeNode(3) root.left = TreeNode(5) root.right = TreeNode(1) root.left.left = TreeNode(6) root.left.right = TreeNode(2) root.right.left = TreeNode(0) root.right.right = TreeNode(8) root.left.right.left = TreeNode(7) root.left.right.rig...
[]
[ 1, 0, 1, 0, 1, 0, 1, 1, 0, 1 ]
6
medium
0.6
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "from collections import deque\n\nclass TreeNode:\n def __init__(self, value=0, left=None, right=None):\n self.value = value\n self.left = lef...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00007046", "row_id": 7046, "seed_ids": "[5036]" }
0.716561
Codeforces_7046
I
[ "countNodesAtDistanceK", "findTargetNode", "mapParents", "bfs_from_target" ]
4
[ [ "countNodesAtDistanceK", "bfs_from_target" ], [ "countNodesAtDistanceK", "findTargetNode" ], [ "countNodesAtDistanceK", "mapParents" ] ]
3
[]
false
[ "TreeNode" ]
true
pytest
false
[]
true
67ac5263b4e072ad9da48e42945a213fbace91c8
e8d3305780b265d32e8884091b2a94c541dbb073
v1.0
instruct
Codeforces
Codeforces_7047_I
Cinderella loves flowers and wants to grow a beautiful garden. She has n flower pots, each of which can grow a certain type of flower. However, she wants to ensure that her garden looks aesthetically pleasing by having at most two consecutive pots with the same type of flower. Each flower type is represented by an int...
def arrange_flowers(n, k): if k == 1: if n > 2: return -1 else: return [1] * n arrangement = [] for i in range(n): arrangement.append((i % k) + 1) return arrangement def cinderella_flowers(n, k): arrangement = arrange_flowers(n, k) if arrang...
from solution import cinderella_flowers def test_case_1(): assert cinderella_flowers(5, 2) == "1 2 1 2 1" def test_case_2(): assert cinderella_flowers(3, 1) == -1 def test_case_3(): assert cinderella_flowers(3, 3) == "1 2 3" def test_case_4(): assert cinderella_flowers(2, 1) == "1 1" def test_case_...
[ { "docstring": null, "function_declaration": "def arrange_flowers(n, k):", "function_name": "arrange_flowers", "parameter_list": "(n, k)" }, { "docstring": null, "function_declaration": "def cinderella_flowers(n, k):", "function_name": "cinderella_flowers", "parameter_list": "(n,...
[ 1, 0, 1, 0, 1, 1, 1, 1, 1, 1 ]
8
easy
0.8
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def arrange_flowers(n, k):\n if k == 1 and n > 2:\n return -1\n result = []\n for i in range(n):\n result.append((i % k) + 1)\n retu...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00007047", "row_id": 7047, "seed_ids": "[6613]" }
0.588485
Codeforces_7047
I
[ "arrange_flowers", "cinderella_flowers" ]
2
[ [ "cinderella_flowers", "arrange_flowers" ] ]
1
[]
false
[]
false
pytest
true
[]
true
dc9d05579508f492d5d1c1883a006f24c78798ba
097516849501ac0dc4aa9bd50ccc90769ee561a5
v1.0
instruct
Codeforces
Codeforces_7051_I
You are given an array of integers where each integer can be positive, negative, or zero. We define an "inversion" in the array such that if we have two indices \(i\) and \(j\) with \(i < j\), then an inversion occurs if \(arr[i] > arr[j]\). Your task is to find the total number of inversions in the array. For example...
def merge_and_count(arr, temp_arr, left, mid, right): i = left # Starting index for left subarray j = mid + 1 # Starting index for right subarray k = left # Starting index to be sorted inv_count = 0 while i <= mid and j <= right: if arr[i] <= arr[j]: temp_arr[k] = arr[i] ...
import pytest from solution import process_test_cases def test_single_inversion(): assert process_test_cases([[1, 2, 3, 4, 5]]) == [0] assert process_test_cases([[5, 4, 3, 2, 1]]) == [10] def test_multiple_inversions(): assert process_test_cases([[2, 3, 8, 6, 1]]) == [5] assert process_test_cases([[5,...
[ { "docstring": null, "function_declaration": "def merge_and_count(arr, temp_arr, left, mid, right):", "function_name": "merge_and_count", "parameter_list": "(arr, temp_arr, left, mid, right)" }, { "docstring": null, "function_declaration": "def merge_sort_and_count(arr, temp_arr, left, r...
[ 0, 1, 1, 1, 1, 1, 0, 1, 1, 0 ]
7
easy
0.7
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def count_inversions(arr):\n \"\"\"\n Counts the number of inversions in the array using a modified merge sort algorithm.\n \"\"\"\n def merge_cou...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00007051", "row_id": 7051, "seed_ids": "[2065]" }
0.778654
Codeforces_7051
I
[ "merge_and_count", "merge_sort_and_count", "count_inversions", "process_test_cases" ]
4
[ [ "count_inversions", "merge_sort_and_count" ], [ "merge_sort_and_count", "merge_and_count" ], [ "process_test_cases", "count_inversions" ] ]
3
[ "process_test_cases" ]
false
[]
false
pytest
true
[]
true
8adf33ba68875e9253e3291eda1e2aa0dfe6fc98
0005268d85dde3fd923e7ecc274b1d874995a687
v1.0
instruct
Codeforces
Codeforces_7130_I
Polycarp is learning about binary search trees (BST) and their properties. He has recently come across the concept of the in-order traversal of a BST, which returns the elements of the tree in sorted order. However, Polycarp is more interested in the properties of nodes in the BST relative to their position in this tra...
class TreeNode: def __init__(self, key): self.left = None self.right = None self.val = key def insert(root, key): """Function to insert a new node with the given key in the BST.""" if root is None: return TreeNode(key) if key < root.val: root.left = insert(root.l...
from solution import bst_predecessor_successor_repr def test_example_case(): n = 5 values = [20, 10, 30, 5, 15] assert bst_predecessor_successor_repr(n, values) == [ "-1 -1", "-1 20", "20 -1", "-1 10", "10 20" ] def test_all_increasing(): n = 4 values = ...
[]
[ 1, 1, 0, 0, 0, 0, 0, 0, 1, 0 ]
3
hard
0.3
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "class TreeNode:\n def __init__(self, key):\n self.left = None\n self.right = None\n self.val = key\n\ndef insert(root, key):\n \"\"...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00007130", "row_id": 7130, "seed_ids": "[2149]" }
0.585935
Codeforces_7130
I
[ "insert", "find_predecessor_successor", "bst_insertion_with_predecessor_successor", "bst_predecessor_successor_repr" ]
4
[ [ "bst_insertion_with_predecessor_successor", "find_predecessor_successor" ], [ "bst_insertion_with_predecessor_successor", "insert" ], [ "bst_predecessor_successor_repr", "bst_insertion_with_predecessor_successor" ] ]
3
[]
false
[ "TreeNode" ]
true
pytest
true
[]
true
e19c454d5d8f71e60bd205808303fe00f465d0a7
d4dfa33335f18e53815caaf58dce06e827abe1a8
v1.0
instruct
Codeforces
Codeforces_7141_I
The hiking organizers have come up with a unique problem for participants. Given the trail system map of a national park, you need to determine if it is possible to start at a specific trailhead and visit all other trailheads exactly once before returning to the starting point (a Hamiltonian Cycle) using the provided t...
def find_hamiltonian_cycle(n, edges): # Create an adjacency matrix from the edges graph = [[0] * n for _ in range(n)] for u, v in edges: graph[u][v] = 1 graph[v][u] = 1 def is_valid(v, pos, path): # Check if this vertex is an adjacency to the previous vertex if graph[pat...
def test_hamiltonian_cycle(): # First Example assert hamiltonian_cycle(4, 5, [(0, 1), (1, 2), (2, 3), (3, 0), (1, 3)]) == "YES" # Second Example: No Hamiltonian cycle present assert hamiltonian_cycle(5, 6, [(0, 1), (1, 2), (2, 3), (3, 4), (4, 1), (1, 3)]) == "NO" # Third Example: Simple triangle, ...
[ { "docstring": null, "function_declaration": "def find_hamiltonian_cycle(n, edges):", "function_name": "find_hamiltonian_cycle", "parameter_list": "(n, edges)" }, { "docstring": null, "function_declaration": "def hamiltonian_cycle(n, m, connections):", "function_name": "hamiltonian_c...
[ 0, 0, 1, 0, 1, 1, 1, 1, 0, 0 ]
5
medium
0.5
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def find_hamiltonian_cycle(graph, path, visited, position, n):\n if position == n:\n if graph[path[-1]][path[0]] == 1:\n return True\n ...
trial_gpt4o_7
{ "original_instruction": "", "prompt_id": "00007141", "row_id": 7141, "seed_ids": "[6147]" }
0.644264
Codeforces_7141
I
[ "find_hamiltonian_cycle", "hamiltonian_cycle" ]
2
[ [ "hamiltonian_cycle", "find_hamiltonian_cycle" ] ]
1
[]
false
[]
false
pytest
false
[]
true
028ed8b9b41e05265b03bace4647b6eb09f34bc6
286540fe21f2e14fba19a0587a2c8527eee99326
v1.0
instruct
Codeforces
Codeforces_7208_I
You are given a rectangular grid consisting of cells with a specific color: red, green, or blue. The grid is represented as an array of strings, where each string corresponds to a row of the grid, and each character in the string represents the color of a cell. The possible characters are 'R' for red, 'G' for green, an...
def can_reach_bottom_right(m, n, grid): def dfs(x, y): if x == m - 1 and y == n - 1: return True visited[x][y] = True directions = [(0, 1), (1, 0)] for dx, dy in directions: nx, ny = x + dx, y + dy if 0 <= nx < m and 0 <= ny < n and grid[nx][ny] ==...
from solution import solve def test_grid_with_possible_path(): assert solve(2, 2, ["RR", "RR"]) == "YES" def test_grid_without_possible_path(): assert solve(3, 3, ["RGB", "GRG", "BBG"]) == "NO" def test_single_cell(): assert solve(1, 1, ["R"]) == "YES" assert solve(1, 1, ["G"]) == "YES" assert so...
[ { "docstring": null, "function_declaration": "def can_reach_bottom_right(m, n, grid):", "function_name": "can_reach_bottom_right", "parameter_list": "(m, n, grid)" }, { "docstring": null, "function_declaration": "def solve(m, n, grid):", "function_name": "solve", "parameter_list"...
[ 1, 0, 0, 0, 0, 0, 0, 1, 1, 1 ]
4
medium
0.4
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def can_reach_bottom_right(m, n, grid):\n def dfs(x, y, color):\n if x == m - 1 and y == n - 1:\n return True\n visited.add((x, y)...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00007208", "row_id": 7208, "seed_ids": "[5767]" }
0.720787
Codeforces_7208
I
[ "can_reach_bottom_right", "solve" ]
2
[ [ "solve", "can_reach_bottom_right" ] ]
1
[]
false
[]
false
pytest
true
[]
true
b50cb06f7a4a4314b21d55fd3179df38d3725aab
7540e1353fcd5889c8893a2d1440d2b34e299be2
v1.0
instruct
Codeforces
Codeforces_7209_I
Alex has a passion for collecting coins of various denominations. He recently obtained a collection of coins and wants to organize them in a special way. Alex has m different types of coins, where each type i is characterized by its denomination di and the count of coins ci. Alex desires to keep x coins in a single ro...
def max_sum_denominations(m, x, coin_info): """ Returns the maximum sum of denominations and the indices of coins that produce this sum given m types of coins and a row length of x. Parameters: m (int): The number of different types of coins x (int): The number of coins Alex wants ...
from solution import parse_and_solve def test_basic_case(): m = 5 x = 3 coins = [(5, 3), (2, 1), (7, 2), (4, 5), (6, 2)] max_sum, indices = parse_and_solve(m, x, coins) assert max_sum == 18 assert sorted(indices) == sorted([3, 5, 1]) def test_all_same_denomination(): m = 5 x = 3 c...
[ { "docstring": "Returns the maximum sum of denominations and the indices of coins \nthat produce this sum given m types of coins and a row length of x.\n\nParameters:\n m (int): The number of different types of coins\n x (int): The number of coins Alex wants to place in a single row\n coin_info (list o...
[ 1, 0, 0, 0, 0, 0, 0, 0, 0, 1 ]
2
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def max_sum_of_denominations(m, x, denominations_counts):\n # sort the denominations and their indices in descending order based on the denomination values...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00007209", "row_id": 7209, "seed_ids": "[1800]" }
0.720899
Codeforces_7209
I
[ "max_sum_denominations", "parse_and_solve" ]
2
[ [ "parse_and_solve", "max_sum_denominations" ] ]
1
[]
false
[]
false
pytest
true
[]
true
4331052da4a2ba8cffa87c0d895b7c7bcb987b99
1ea9160004aa169d9d872b9f7e09b6abbd82702b
v1.0
instruct
Codeforces
Codeforces_7222_I
In a fictional kingdom called Forestland, there lives a clever squirrel called Nutty. Nutty loves gathering nuts and storing them in different locations throughout the forest. As winter approaches, Nutty wants to find the best place to hide her nuts, ensuring that they are safe from other animals and easy for her to ac...
import heapq def dijkstra(n, graph, start): """ Use Dijkstra's algorithm to find the shortest paths from start to all other nodes. Parameters: n (int): Number of nodes in the graph. graph (dict): Adjacency list representation of the graph. start (int): The start node. Returns: ...
def test_single_tree(): assert find_optimal_storage_tree(1, 0, []) == 0 def test_two_trees_one_branch(): assert find_optimal_storage_tree(2, 1, [(1, 2, 10)]) == 10 def test_three_trees_linear(): assert find_optimal_storage_tree(3, 2, [(1, 2, 5), (2, 3, 5)]) == 5 def test_three_trees_triangle(): asser...
[ { "docstring": "Use Dijkstra's algorithm to find the shortest paths from start to all other nodes.\n\nParameters:\nn (int): Number of nodes in the graph.\ngraph (dict): Adjacency list representation of the graph.\nstart (int): The start node.\n\nReturns:\nlist: List of shortest distance from start to each node....
[ 0, 0, 1, 0, 1, 0, 1, 0, 0 ]
3
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def floyd_warshall(n, edges):\n # Initialize distance matrix with infinity\n INF = float('inf')\n dist = [[INF] * n for _ in range(n)]\n \n # D...
trial_gpt4o_3
{ "original_instruction": "", "prompt_id": "00007222", "row_id": 7222, "seed_ids": "[3927]" }
0.656109
Codeforces_7222
I
[ "dijkstra", "find_optimal_storage_tree" ]
2
[ [ "find_optimal_storage_tree", "dijkstra" ] ]
1
[]
false
[]
false
pytest
false
[]
true
8fc3e72f5929590714e2e459ba8292757e9701b9
1be4c5c3285a630a07cfad6e3f676c175270e764
v1.0
instruct
Codeforces
Codeforces_7383_I
A city has a network of roads connecting various locations. Each road has a specific traffic capacity representing the maximum number of vehicles that can pass through it per unit time. Your task is to determine the maximum number of vehicles that can travel from a starting location (source) to a destination location (...
from collections import deque def bfs(capacity, source, sink, parent): """ Returns true if there is a path from source to sink in residual graph. Also fills parent to store the path. """ visited = [False] * len(capacity) queue = deque([source]) visited[source] = True while queue: ...
def test_small_graph(): n = 4 m = 5 edges = [ (1, 2, 40), (1, 3, 20), (2, 3, 10), (2, 4, 30), (3, 4, 20) ] assert edmonds_karp(n, edges) == 50 def test_single_path(): n = 4 m = 3 edges = [ (1, 2, 10), (2, 3, 5), (3, 4, 10) ...
[ { "docstring": "Returns true if there is a path from source to sink in residual graph.\nAlso fills parent to store the path.", "function_declaration": "def bfs(capacity, source, sink, parent):", "function_name": "bfs", "parameter_list": "(capacity, source, sink, parent)" }, { "docstring": "R...
[ 0, 0, 0, 0, 0, 1, 0, 0, 0, 1 ]
2
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "from collections import deque, defaultdict\n\ndef bfs_capacity(graph, source, sink, parent):\n visited = set()\n queue = deque([source])\n visited.ad...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00007383", "row_id": 7383, "seed_ids": "[4845]" }
0.738821
Codeforces_7383
I
[ "bfs", "edmonds_karp" ]
2
[ [ "edmonds_karp", "bfs" ] ]
1
[]
false
[]
false
pytest
false
[]
true
6e974f9a835f69c099b5ee806f75d8f37c15465c
91ea385210164cdac16a22a6f0d52a9aeb87b0ae
v1.0
instruct
Codeforces
Codeforces_7385_I
Marie wants to organize a workshop for children where they will learn about constructing networks. She has a set of nodes and wants to connect them using edges. Each edge has a certain weight and each node can only be connected to at most two other nodes, forming a tree-like structure. Given a set of nodes and a list ...
def find(parent, i): if parent[i] == i: return i else: parent[i] = find(parent, parent[i]) return parent[i] def union(parent, rank, x, y): xroot = find(parent, x) yroot = find(parent, y) if rank[xroot] < rank[yroot]: parent[xroot] = yroot elif rank[xroot] > rank...
def test_example(): n = 4 edges = [ (1, 2, 3), (1, 3, 2), (2, 3, 4), (3, 4, 1), (2, 4, 5) ] assert maximum_spanning_tree(n, edges) == 12 def test_single_node(): n = 1 edges = [] assert maximum_spanning_tree(n, edges) == 0 def test_no_edges(): n =...
[ { "docstring": null, "function_declaration": "def find(parent, i):", "function_name": "find", "parameter_list": "(parent, i)" }, { "docstring": null, "function_declaration": "def union(parent, rank, x, y):", "function_name": "union", "parameter_list": "(parent, rank, x, y)" }, ...
[ 1, 0, 0, 0, 0, 0, 0, 1, 1, 0 ]
3
hard
0.3
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def maximum_weighted_tree_sum(n, m, edges):\n \"\"\"\n Finds the maximum possible sum of edge weights in a valid tree that includes every node exactly o...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00007385", "row_id": 7385, "seed_ids": "[573]" }
0.777052
Codeforces_7385
I
[ "find", "union", "maximum_spanning_tree" ]
3
[ [ "maximum_spanning_tree", "find" ], [ "maximum_spanning_tree", "union" ], [ "union", "find" ] ]
3
[]
false
[]
false
pytest
false
[]
true
f8a2136a1a842aef4278898ef83a7f726fdeb00e
18507ffa45279325e980187f2df2b2e6ca55e6f6
v1.0
instruct
Codeforces
Codeforces_7413_I
You are given an array of integers and a series of queries. Each query specifies a range within the array, and you need to find the sum of the elements within that range. Write a program that handles multiple queries efficiently. ### Input - The first line contains two integers, `n` and `q`. (`1 ≤ n ≤ 100000`, `1 ≤ ...
def preprocess(arr): """ Preprocess the given array to create a prefix sum array. """ prefix_sums = [0] * (len(arr) + 1) for i in range(1, len(arr) + 1): prefix_sums[i] = prefix_sums[i - 1] + arr[i - 1] return prefix_sums def query_sum(prefix_sums, l, r): """ Returns the sum of ...
def test_preprocess(): assert preprocess([1, 2, 3, 4, 5]) == [0, 1, 3, 6, 10, 15] def test_query_sum(): prefix_sums = [0, 1, 3, 6, 10, 15] assert query_sum(prefix_sums, 0, 2) == 6 # Sum from index 1 to 3 in original array assert query_sum(prefix_sums, 1, 3) == 9 # Sum from index 2 to 4 in original ar...
[ { "docstring": "Preprocess the given array to create a prefix sum array.", "function_declaration": "def preprocess(arr):", "function_name": "preprocess", "parameter_list": "(arr)" }, { "docstring": "Returns the sum of the elements from index l to r (inclusive) using the prefix sum array.", ...
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 0 ]
9
easy
0.9
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def preprocess(array):\n \"\"\"\n Preprocess the array to create a prefix sum array.\n \"\"\"\n n = len(array)\n prefix_sum = [0] * (n + 1)\n ...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00007413", "row_id": 7413, "seed_ids": "[5480]" }
0.63854
Codeforces_7413
I
[ "preprocess", "query_sum", "find_range_sums" ]
3
[ [ "find_range_sums", "preprocess" ], [ "find_range_sums", "query_sum" ] ]
2
[]
false
[]
false
pytest
false
[]
true
eb60d54ea52c6a55df0caabe6908b3d5894eea26
9aabb913c320d429e9b39149eea9d3fad3feac06
v1.0
instruct
Codeforces
Codeforces_7414_I
A courier company needs to schedule deliveries for a new set of packages. Each package has a specific delivery window [si, ei] indicating the earliest and latest time the package can be delivered. There are k delivery slots available during which a courier can be assigned to deliver a package. Each delivery slot j is d...
import heapq def max_deliveries(package_windows, delivery_slots): package_windows.sort(key=lambda x: x[1]) # Sort by end time of delivery window delivery_slots.sort() # Sort by start time of delivery slot max_delivered = 0 available_slots = [] for start, end in package_windows: ...
def test_case1(): n, k = 5, 3 package_data = [(1, 5), (2, 7), (3, 6), (5, 10), (6, 8)] slot_data = [(2, 3), (4, 2), (7, 3)] assert max_packages_delivered(n, k, package_data, slot_data) == 3 def test_case2(): n, k = 3, 3 package_data = [(1, 5), (6, 10), (11, 15)] slot_data = [(2, 3), (7, 3),...
[ { "docstring": null, "function_declaration": "def max_deliveries(package_windows, delivery_slots):", "function_name": "max_deliveries", "parameter_list": "(package_windows, delivery_slots)" }, { "docstring": null, "function_declaration": "def max_packages_delivered(n, k, package_data, sl...
[ 0, 0, 0, 0, 0, 0, 0, 1, 1, 0 ]
2
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def max_delivered_packages(n, k, packages, slots):\n packages.sort(key=lambda x: x[1])\n slots.sort(key=lambda x: x[0] + x[1])\n \n delivered_coun...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00007414", "row_id": 7414, "seed_ids": "[7119]" }
0.775853
Codeforces_7414
I
[ "max_deliveries", "max_packages_delivered" ]
2
[ [ "max_packages_delivered", "max_deliveries" ] ]
1
[]
false
[]
false
pytest
false
[]
true
7fe7386aa797adae5ee50cc5c49399d39f19be0c
c4fe218fbc5f8f0f507ad53ae2f411961ce51249
v1.0
instruct
Codeforces
Codeforces_7447_I
You are given a city grid and it's represented as a 2D array. Each cell in the 2D array represents a city block. The value of the cell can either be `0` (representing an obstacle) or `1` (representing an accessible path). A person can move from one block to any of the four side-adjacent blocks (up, down, left, or right...
from collections import deque def shortest_path_in_grid(grid): n = len(grid) m = len(grid[0]) directions = [(0, 1), (1, 0), (0, -1), (-1, 0)] def in_bounds(x, y): return 0 <= x < n and 0 <= y < m queue = deque([(0, 0, 1)]) # (x, y, distance) visited = set((0, 0)) while queue...
def test_shortest_path_no_obstacles(): grid = [ [1, 1, 1], [1, 1, 1], [1, 1, 1] ] assert find_shortest_path(3, 3, grid) == 5 def test_shortest_path_with_obstacles(): grid = [ [1, 0, 1, 1], [1, 1, 0, 1], [0, 1, 0, 1], [1, 1, 1, 1] ] assert ...
[ { "docstring": null, "function_declaration": "def shortest_path_in_grid(grid):", "function_name": "shortest_path_in_grid", "parameter_list": "(grid)" }, { "docstring": null, "function_declaration": "def find_shortest_path(n, m, grid):", "function_name": "find_shortest_path", "par...
[ 0, 1, 0, 0, 1, 0, 0, 0, 0, 0 ]
2
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "from collections import deque\n\ndef shortest_path(grid):\n def bfs(start, end):\n n, m = len(grid), len(grid[0])\n queue = deque([start])\n ...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00007447", "row_id": 7447, "seed_ids": "[6605]" }
0.768991
Codeforces_7447
I
[ "shortest_path_in_grid", "find_shortest_path" ]
2
[ [ "find_shortest_path", "shortest_path_in_grid" ] ]
1
[]
false
[]
false
pytest
false
[]
true
d1ac6dbf61274efdfd2470713c967f267ae99c0f
8a82e7e035387a9ce94bfacb06cc975ce07af197
v1.0
instruct
Codeforces
Codeforces_7467_I
Given a sequence of integers, arrange them into a binary search tree (BST). A BST is a binary tree in which for each node, the values in its left subtree are less than the node's value, and the values in its right subtree are greater than the node's value. Write a function to build and print the BST. If there are dupl...
class TreeNode: def __init__(self, value): self.value = value self.left = None self.right = None def insert_into_bst(root, value): if root is None: return TreeNode(value) if value < root.value: root.left = insert_into_bst(root.left, value) elif value > root.value...
from solution import bst_from_sequence def test_bst_valid_sequence(): assert bst_from_sequence("5 3 7 2 4 6 8") == [5, 3, 7, 2, 4, 6, 8] def test_bst_with_duplicates(): assert bst_from_sequence("5 3 3 2 4 6 8") == -1 def test_bst_single_element(): assert bst_from_sequence("10") == [10] def test_bst_empt...
[]
[ 0, 1, 1, 1, 1, 1, 1, 1, 0, 0 ]
7
easy
0.7
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "class TreeNode:\n def __init__(self, value):\n self.value = value\n self.left = None\n self.right = None\n\ndef insert_into_bst(root, ...
trial_gpt4o_7
{ "original_instruction": "", "prompt_id": "00007467", "row_id": 7467, "seed_ids": "[3924]" }
0.596734
Codeforces_7467
I
[ "insert_into_bst", "build_bst", "level_order_traversal", "bst_from_sequence" ]
4
[ [ "bst_from_sequence", "build_bst" ], [ "bst_from_sequence", "level_order_traversal" ], [ "build_bst", "insert_into_bst" ] ]
3
[]
false
[ "TreeNode" ]
true
pytest
true
[]
true
ce6d020be1e2cdd064c1cefaf876d09f5d350291
21967d7ebfa4825c3757d6a403c89fd7a98020d3
v1.0
instruct
Codeforces
Codeforces_7488_I
Alice is fascinated by palindromes and wants to find them in different number systems. In particular, she is interested in finding the smallest palindrome greater than a given number n in a number system with base b. A number is considered a palindrome if it reads the same backward as forward. For example, in a decima...
def int_to_base(n, b): """ Converts an integer n to a given base b and returns the string representation. """ if n == 0: return '0' digits = [] while n: digits.append(int(n % b)) n //= b return ''.join('0123456789abcdefghijklmnopqrstuvwxyz'[d] for d in digits[::-1]) ...
from solution import next_palindrome def test_next_palindrome_base_10(): assert next_palindrome('123', 10) == '131' assert next_palindrome('99', 10) == '101' assert next_palindrome('101', 10) == '111' def test_next_palindrome_base_16(): assert next_palindrome('1f', 16) == '22' assert next_palindro...
[ { "docstring": "Converts an integer n to a given base b and returns the string representation.", "function_declaration": "def int_to_base(n, b):", "function_name": "int_to_base", "parameter_list": "(n, b)" }, { "docstring": "Converts a string s in base b to an integer.", "function_declar...
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_palindrome(s):\n return s == s[::-1]\n\ndef increment_in_base(s, base):\n num = int(s, base)\n num += 1\n result = ''\n while num > 0:\n...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00007488", "row_id": 7488, "seed_ids": "[6043]" }
0.788658
Codeforces_7488
I
[ "int_to_base", "base_to_int", "is_palindrome", "next_palindrome" ]
4
[ [ "next_palindrome", "base_to_int" ], [ "next_palindrome", "int_to_base" ], [ "next_palindrome", "is_palindrome" ] ]
3
[]
false
[]
false
pytest
true
[]
true
ab759360362a3d0c783939b9af63e266e9d06d3b
4d74815031c9dc081c447c5bf5849c2c6bd76a12
v1.0
instruct
Codeforces
Codeforces_7562_I
You are given a rectangular grid filled with unique positive integers. Your task is to find the minimum value in each row of the grid and then the maximum value among those minimums. The input consists of: - The first line contains two integers n and m (1 ≤ n, m ≤ 100), which represent the number of rows and columns o...
def max_of_mins(grid): """ Find the maximum value among the minimum values of each row in the grid. Parameters: grid (list of lists of int): The input grid Returns: int: The maximum value among the minimum values of each row """ # Finding the minimum value in each row min_valu...
from solution import read_grid_and_find_max_of_mins def test_example_case(): n, m = 3, 3 lines = [ "3 7 5", "1 8 2", "9 4 6" ] assert read_grid_and_find_max_of_mins(n, m, lines) == 4 def test_single_row_case(): n, m = 1, 5 lines = ["7 3 5 1 6"] assert read_grid_and_...
[ { "docstring": "Find the maximum value among the minimum values of each row in the grid.\n\nParameters:\ngrid (list of lists of int): The input grid\n\nReturns:\nint: The maximum value among the minimum values of each row ", "function_declaration": "def max_of_mins(grid):", "function_name": "max_of_mins...
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def max_of_row_minima(grid):\n \"\"\"\n Returns the maximum value among the minimum values of each row of the grid.\n \"\"\"\n min_values = [min(r...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00007562", "row_id": 7562, "seed_ids": "[4310]" }
0.683039
Codeforces_7562
I
[ "max_of_mins", "read_grid_and_find_max_of_mins" ]
2
[ [ "read_grid_and_find_max_of_mins", "max_of_mins" ] ]
1
[]
false
[]
false
pytest
true
[]
true
7a8051cd8aa797dd3d6a17ab98603a06854ea131
733c377d993f1b837e1cb88f50f5e0a49dd4ec3d
v1.0
instruct
Codeforces
Codeforces_7602_I
You are given a series of events represented by tuples `(timestamp, event_type)`, where `timestamp` is in the format "YYYY-MM-DD HH:MM:SS", and `event_type` is a string representing the type of event. Your task is to group the events by their `event_type` and then sort each group of events by their `timestamp` in ascen...
def group_and_sort_events(n, events): from collections import defaultdict import datetime event_dict = defaultdict(list) for event in events: timestamp, event_type = event.rsplit(' ', 1) event_dict[event_type].append(timestamp) result = [] for event_type, timestamps in event_d...
def test_group_and_sort_events(): n = 5 events = [ "2023-01-01 12:00:00 A", "2023-01-01 13:00:00 B", "2023-01-01 11:00:00 A", "2023-01-02 12:00:00 B", "2023-01-01 14:00:00 A" ] output = process_events(n, events) expected_output = ( 'A\n' '...
[ { "docstring": null, "function_declaration": "def group_and_sort_events(n, events):", "function_name": "group_and_sort_events", "parameter_list": "(n, events)" }, { "docstring": null, "function_declaration": "def format_output(events):", "function_name": "format_output", "paramet...
[ 1, 0, 0, 1, 0, 1, 1, 1, 0, 0 ]
5
medium
0.5
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "from collections import defaultdict\nfrom datetime import datetime\n\ndef group_and_sort_events(events):\n \"\"\"\n Groups events by their type and sort...
trial_gpt4o_7
{ "original_instruction": "", "prompt_id": "00007602", "row_id": 7602, "seed_ids": "[5219]" }
0.545646
Codeforces_7602
I
[ "group_and_sort_events", "format_output", "process_events" ]
3
[ [ "process_events", "format_output" ], [ "process_events", "group_and_sort_events" ] ]
2
[ "format_output" ]
false
[]
false
pytest
false
[]
true
045ad8bda9feffcf23f174b57ba55902c4156a3c
ce9ad581af68ab0e7ba7a293530db94fa0d2dc79
v1.0
instruct
Codeforces
Codeforces_7622_I
You are given an array of n integers. You have to handle q queries of the following types: 1. Update the value of a specified element in the array. 2. Calculate the product of elements in a specified range of the array. For the update query, you will be given an index and a new value, and you need to update the array...
MOD = 1_000_000_007 def update(index, value, arr, product): n = len(arr) old_value = arr[index] arr[index] = value # Efficiently update the product product = (product * pow(old_value, MOD-2, MOD) % MOD) * value % MOD return product def range_product(l, r, arr): result = 1 for i in...
import pytest from solution import process_queries def test_process_queries(): n = 5 q = 3 arr = [2, 3, 4, 5, 6] queries = ["2 1 3", "1 2 10", "2 1 3"] expected_output = [24, 80] assert process_queries(n, q, arr, queries) == expected_output def test_process_queries_single_element(): n = 1 ...
[ { "docstring": null, "function_declaration": "def update(index, value, arr, product):", "function_name": "update", "parameter_list": "(index, value, arr, product)" }, { "docstring": null, "function_declaration": "def range_product(l, r, arr):", "function_name": "range_product", "...
[ 0, 0, 1, 0, 0, 1, 0, 0, 0, 0 ]
2
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "MOD = 1000000007\n\ndef build_segment_tree(arr, seg_tree, start, end, node):\n if start == end:\n seg_tree[node] = arr[start]\n else:\n mi...
trial_gpt4o_5
{ "original_instruction": "", "prompt_id": "00007622", "row_id": 7622, "seed_ids": "[7229]" }
0.701776
Codeforces_7622
I
[ "update", "range_product", "process_queries" ]
3
[ [ "process_queries", "range_product" ], [ "process_queries", "update" ] ]
2
[ "process_queries" ]
false
[]
false
pytest
true
[]
true
29f63acda0335d7053e20841d8eb7ecb8029a6f9
1cc82f632b58b19a8e3cf3de4ff308b749e0067f
v1.0
instruct
Codeforces
Codeforces_7629_I
Frank needs to deliver packages to different locations in his city using his delivery van. The city is represented as a grid of size \( N \times N \), with Frank starting at the top-left corner of the grid (position (0,0)). Frank wants to minimize the total distance traveled while ensuring that each package is deliver...
import itertools def calculate_distance(p1, p2): """ Calculates Manhattan distance between two points p1 and p2. """ return abs(p1[0] - p2[0]) + abs(p1[1] - p2[1]) def minimum_total_distance(N, M, package_coords): """ Computes the minimum total distance to deliver all packages and return to th...
def test_minimum_total_distance_1(): assert minimum_total_distance(4, 3, [(1, 2), (2, 2), (3, 3)]) == 12 def test_minimum_total_distance_2(): assert minimum_total_distance(3, 2, [(1, 1), (2, 2)]) == 8 def test_minimum_total_distance_3(): assert minimum_total_distance(2, 1, [(1, 1)]) == 4 def test_minimum...
[ { "docstring": "Calculates Manhattan distance between two points p1 and p2.", "function_declaration": "def calculate_distance(p1, p2):", "function_name": "calculate_distance", "parameter_list": "(p1, p2)" }, { "docstring": "Computes the minimum total distance to deliver all packages and retu...
[ 0, 0, 0, 0, 0, 0, 0, 1, 0 ]
1
hard
0.111
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "from itertools import permutations\n\ndef compute_min_distance(N, M, delivery_locations):\n def manhattan_distance(coord1, coord2):\n return abs(coo...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00007629", "row_id": 7629, "seed_ids": "[5039]" }
0.708786
Codeforces_7629
I
[ "calculate_distance", "minimum_total_distance" ]
2
[ [ "minimum_total_distance", "calculate_distance" ] ]
1
[]
false
[]
false
pytest
false
[]
true
78dac5a15107cf03613ae19fa274f988e74a8038
3f9baff324d7f2808a6d2195f42b7a4d8b18f9c6
v1.0
instruct
Codeforces
Codeforces_7632_I
In a certain country, there is a new subway system. The subway map can be thought of as a tree with $$$n$$$ stations, where each station is represented as a node, and each corridor between stations (bidirectional) is represented as an edge. Stations are numbered from $$$1$$$ to $$$n$$$. A person wants to travel from s...
from collections import deque def build_tree(n, edges): tree = [[] for _ in range(n + 1)] for u, v in edges: tree[u].append(v) tree[v].append(u) return tree def bfs(tree, start): n = len(tree) dist = [-1] * n dist[start] = 0 queue = deque([start]) while queue: u...
from solution import subway_distances def test_example_case(): n = 6 q = 3 edges = [(1, 2), (2, 3), (2, 4), (4, 5), (4, 6)] queries = [(1, 4), (5, 3), (2, 6)] assert subway_distances(n, edges, queries) == [2, 3, 2] def test_single_node(): n = 1 q = 1 edges = [] queries = [(1, 1)] ...
[ { "docstring": null, "function_declaration": "def build_tree(n, edges):", "function_name": "build_tree", "parameter_list": "(n, edges)" }, { "docstring": null, "function_declaration": "def bfs(tree, start):", "function_name": "bfs", "parameter_list": "(tree, start)" }, { ...
[ 0, 1, 0, 0, 0, 0, 0, 0, 1 ]
2
hard
0.222
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "from collections import defaultdict, deque\n\ndef find_distances(n, q, edges, queries):\n tree = defaultdict(list)\n \n for u, v in edges:\n t...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00007632", "row_id": 7632, "seed_ids": "[3446]" }
0.746815
Codeforces_7632
I
[ "build_tree", "bfs", "subway_distances" ]
3
[ [ "subway_distances", "bfs" ], [ "subway_distances", "build_tree" ] ]
2
[]
false
[]
false
pytest
true
[]
true
b9d0630789704861e7e6fc6da6d04977f6809446
29c7f391c5defd6a3e1f31d511af7617d563d0d1
v1.0
instruct
Codeforces
Codeforces_7633_I
Given an undirected graph with `n` nodes labeled from `1` to `n`, and `m` bidirectional edges, your task is to determine the maximum size of an independent set in the graph. An independent set is a subset of vertices in a graph, no two of which are adjacent. The graph may contain self-loops and multiple edges between t...
def is_independent(graph, subset): """ Checks if subset of vertices is an independent set in the given graph. """ for i in range(len(subset)): for j in range(i + 1, len(subset)): if subset[j] in graph[subset[i]]: return False return True def maximum_independent_s...
from solution import find_max_independent_set def test_case_1(): input_data = "5 6\n1 2\n1 3\n2 3\n3 4\n4 5\n2 5\n" assert find_max_independent_set(input_data) == 2 def test_case_2(): input_data = "4 4\n1 2\n2 3\n3 4\n4 1\n" assert find_max_independent_set(input_data) == 2 def test_case_3(): inpu...
[ { "docstring": "Checks if subset of vertices is an independent set in the given graph.", "function_declaration": "def is_independent(graph, subset):", "function_name": "is_independent", "parameter_list": "(graph, subset)" }, { "docstring": "Find the maximum size of an independent set in the ...
[ 1, 1, 1, 0, 0, 0, 1, 1, 1 ]
6
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def max_independent_set(n, m, edges):\n from itertools import combinations\n \n # Create an adjacency list\n adj = {i: set() for i in range(1, n+1...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00007633", "row_id": 7633, "seed_ids": "[3244]" }
0.603232
Codeforces_7633
I
[ "is_independent", "maximum_independent_set", "find_max_independent_set" ]
3
[ [ "find_max_independent_set", "maximum_independent_set" ], [ "maximum_independent_set", "is_independent" ] ]
2
[]
false
[]
false
pytest
true
[]
true
351be43c5b05244f75af6ff579a5899c50125836
50f43ec8436eabee1a6ad1608d4b15390871b20c
v1.0
instruct
Codeforces
Codeforces_7653_I
The city of Riverland is undergoing a renovation restructuring its road network. The city comprises $$$n$$$ intersections and $$$m$$$ bidirectional roads connecting pairs of intersections, where each road has a certain length. To redesign the road network, the city officials have decided the following: 1. There needs ...
import heapq def find_shortest_path(n, graph): dist = {i: float('inf') for i in range(1, n + 1)} dist[1] = 0 prev = {i: None for i in range(1, n + 1)} pq = [(0, 1)] # (cost, node) while pq: current_dist, u = heapq.heappop(pq) if current_dist > dist[u]: continue ...
def test_find_shortest_path(): n = 5 graph = { 1: [(2, 1), (3, 2)], 2: [(1, 1), (3, 3), (4, 5)], 3: [(1, 2), (2, 3), (5, 4)], 4: [(2, 5), (5, 1)], 5: [(3, 4), (4, 1)] } path = find_shortest_path(n, graph) assert path == [(1, 3), (3, 5)] def test_rearrang...
[ { "docstring": null, "function_declaration": "def find_shortest_path(n, graph):", "function_name": "find_shortest_path", "parameter_list": "(n, graph)" }, { "docstring": null, "function_declaration": "def create_maximum_tree(n, graph, main_route):", "function_name": "create_maximum_t...
[ 0, 0, 1, 0, 0, 0, 0, 0, 0 ]
1
hard
0.111
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "import heapq\n\ndef find_shortest_path(n, edges):\n graph = [[] for _ in range(n+1)]\n for u, v, w in edges:\n graph[u].append((w, v))\n g...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00007653", "row_id": 7653, "seed_ids": "[7882]" }
0.699849
Codeforces_7653
I
[ "find_shortest_path", "create_maximum_tree", "redesign_road_network", "format_solution" ]
4
[ [ "redesign_road_network", "create_maximum_tree" ], [ "redesign_road_network", "find_shortest_path" ] ]
2
[]
false
[]
false
pytest
false
[]
true
267993fdb17f7856458607b65bbdb8c30d873406
8af68e91ac3c91a48b756f228a84b890e327ff03
v1.0
instruct
Codeforces
Codeforces_7676_I
You are given a binary matrix of size $$$n \times m$$$. The goal is to make all elements of the matrix equal using the minimum number of operations. In one operation, you can select a rectangular submatrix and flip all of its elements (change 0 to 1 and 1 to 0). Determine the minimum number of operations required to m...
def flip_submatrix(matrix, r1, c1, r2, c2): for i in range(r1, r2 + 1): for j in range(c1, c2 + 1): matrix[i][j] = '1' if matrix[i][j] == '0' else '0' def is_uniform(matrix): first_value = matrix[0][0] for row in matrix: for value in row: if value != first_value: ...
from solution import min_operations_to_uniform, read_matrix_input def test_uniform_matrix(): input_str = """2 2 00 00""" matrix = read_matrix_input(input_str) num_operations, operations = min_operations_to_uniform(matrix) assert num_operations == 0 assert operations == [] def test_non_unif...
[ { "docstring": null, "function_declaration": "def flip_submatrix(matrix, r1, c1, r2, c2):", "function_name": "flip_submatrix", "parameter_list": "(matrix, r1, c1, r2, c2)" }, { "docstring": null, "function_declaration": "def is_uniform(matrix):", "function_name": "is_uniform", "p...
[ 0, 0, 0, 1, 0, 0, 0, 0, 0, 1 ]
2
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def min_operations_to_uniform_matrix(matrix):\n n = len(matrix)\n m = len(matrix[0])\n \n # Helper function to flip the submatrix\n def flip_su...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00007676", "row_id": 7676, "seed_ids": "[3860]" }
0.673303
Codeforces_7676
I
[ "flip_submatrix", "is_uniform", "min_operations_to_uniform", "read_matrix_input" ]
4
[ [ "min_operations_to_uniform", "flip_submatrix" ], [ "min_operations_to_uniform", "is_uniform" ] ]
2
[]
false
[]
false
pytest
true
[]
true
f8eaf78be39865157489560ab43010b8311477a3
b3327e950fcb5208cc5d5d11dba0fb24f9cb917b
v1.0
instruct
Codeforces
Codeforces_7786_I
Kathryn is planning a treasure hunt game for her friends. The participants need to collect keys to unlock chests, and each key can open one or more specific chests. The objective is to determine the minimum number of keys required to open all the chests. There are n chests and m keys. Each key can open one or more che...
def min_keys_to_open_all_chests(n, m, keys): from itertools import combinations all_chests = set(range(1, n+1)) key_sets = [set(key[1:]) for key in keys] # Try all combinations of keys, starting from the smallest set size for r in range(1, m+1): for combo in combinations(range(m), r): ...
def test_treasure_hunt(): input_data = "5 3\n2 1 2\n2 2 3\n3 3 4 5" result = treasure_hunt(input_data) assert result == (2, [1, 3]) or result == (2, [2, 3]) input_data = "3 3\n1 1\n1 2\n1 3" result = treasure_hunt(input_data) assert result == (3, [1, 2, 3]) input_data = "4 3\n1 1\n2 2 3\n1...
[ { "docstring": null, "function_declaration": "def min_keys_to_open_all_chests(n, m, keys):", "function_name": "min_keys_to_open_all_chests", "parameter_list": "(n, m, keys)" }, { "docstring": null, "function_declaration": "def parse_input(input_lines):", "function_name": "parse_input...
[ 0, 0, 1, 1, 0, 0, 0, 1, 1, 0 ]
4
medium
0.4
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "from itertools import combinations\n\ndef min_keys_to_open_chests(n, m, keys_info):\n # List of sets indicating which chests each key can open\n keys = ...
trial_gpt4o_3
{ "original_instruction": "", "prompt_id": "00007786", "row_id": 7786, "seed_ids": "[1603]" }
0.643046
Codeforces_7786
I
[ "min_keys_to_open_all_chests", "parse_input", "treasure_hunt" ]
3
[ [ "treasure_hunt", "min_keys_to_open_all_chests" ], [ "treasure_hunt", "parse_input" ] ]
2
[ "parse_input" ]
false
[]
false
pytest
false
[]
true
c16fcfa3d763129e32cd9522b9f6f8c1a90458a0
0f86b8bdb1a3b43654d219b68b6d3b858ef12796
v1.0
instruct
Codeforces
Codeforces_7791_I
A large amusement park consists of several attractions connected by walkways. Your task is to determine if there's a route from the entrance to various attractions and to find the shortest route if one exists. You will represent the park as an undirected graph with n nodes and m edges. Nodes represent attractions, and ...
from collections import deque, defaultdict def build_graph(n, edges): graph = defaultdict(list) for u, v in edges: graph[u].append(v) graph[v].append(u) return graph def bfs_shortest_path(graph, start, end): if start == end: return 0 visited = set() queue = deque([(star...
def test_build_graph(): n = 5 edges = [(1, 2), (1, 3), (2, 4), (3, 4), (4, 5)] graph = build_graph(n, edges) assert graph == { 1: [2, 3], 2: [1, 4], 3: [1, 4], 4: [2, 3, 5], 5: [4] } def test_bfs_shortest_path(): n = 5 edges = [(1, 2), (1, 3), (2, 4),...
[ { "docstring": null, "function_declaration": "def build_graph(n, edges):", "function_name": "build_graph", "parameter_list": "(n, edges)" }, { "docstring": null, "function_declaration": "def bfs_shortest_path(graph, start, end):", "function_name": "bfs_shortest_path", "parameter_...
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 0 ]
9
easy
0.9
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "import heapq\nfrom collections import defaultdict, deque\n\ndef build_graph(n, edges):\n graph = defaultdict(list)\n for u, v in edges:\n graph[u...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00007791", "row_id": 7791, "seed_ids": "[3351]" }
0.719909
Codeforces_7791
I
[ "build_graph", "bfs_shortest_path", "process_queries" ]
3
[ [ "process_queries", "bfs_shortest_path" ], [ "process_queries", "build_graph" ] ]
2
[ "process_queries" ]
false
[]
false
pytest
false
[]
true
c1ff3cd3a6534b943efa5017b2facdba9ba07d17
8d33b3c27b0aa040c2f3721487404f1a1dcc38f6
v1.0
instruct
Codeforces
Codeforces_7797_I
Master Li is a master tactician in Cyberland! Li needs to safely transfer a package from one end of a dangerous alley to the other. The alley is represented as a grid with dimensions N x M, where each cell may contain obstacles. The grid cells are either empty ('.') or contain obstacles ('#'). Li can move up, down, le...
from collections import deque def min_steps(grid, N, M, sr, sc, dr, dc): # Convert from 1-based to 0-based indexes sr -= 1 sc -= 1 dr -= 1 dc -= 1 directions = [(-1, 0), (1, 0), (0, -1), (0, 1)] # Up, Down, Left, Right queue = deque([(sr, sc, 0)]) # (row, col, steps) visited = set...
def test_min_steps_basic_case(): input_str = "5 5\n.....\n.###.\n.....\n.###.\n.....\n1 1 5 5" assert min_steps_from_input(input_str) == 8 def test_min_steps_no_obstacle_case(): input_str = "4 4\n....\n....\n....\n....\n1 1 4 4" assert min_steps_from_input(input_str) == 6 def test_min_steps_single_row...
[ { "docstring": null, "function_declaration": "def min_steps(grid, N, M, sr, sc, dr, dc):", "function_name": "min_steps", "parameter_list": "(grid, N, M, sr, sc, dr, dc)" }, { "docstring": null, "function_declaration": "def min_steps_from_input(input_str):", "function_name": "min_step...
[ 0, 0, 0, 0, 0, 1, 0, 1, 1, 0 ]
3
hard
0.3
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "from collections import deque\n\ndef min_steps_to_reach_destination(grid, n, m, sr, sc, dr, dc):\n \"\"\"\n Determines the minimum number of steps requi...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00007797", "row_id": 7797, "seed_ids": "[5631]" }
0.749989
Codeforces_7797
I
[ "min_steps", "min_steps_from_input" ]
2
[ [ "min_steps_from_input", "min_steps" ] ]
1
[]
false
[]
false
pytest
false
[]
true
5ce77cd26cb6afc9c50188078d614e674f9ce5db
a3f277062624a7d9a8390da1c899d3a10b7a5b96
v1.0
instruct
Codeforces
Codeforces_7840_I
A traveler wants to explore a certain country. The country has n cities and m one-way roads connecting them. The traveler wants to visit exactly three distinct cities in such a way that the total distance traveled is minimized. The traveler can start from any city and end in any city but must visit exactly three differ...
import sys import heapq from collections import defaultdict def floyd_warshall(n, graph): dist = [[sys.maxsize] * n for _ in range(n)] for i in range(n): dist[i][i] = 0 for u in range(n): for v in graph[u]: dist[u][v] = 1 for k in range(n): for i in ra...
from solution import find_minimal_path def test_example_scenario_1(): n = 5 m = 6 roads = [ (1, 2), (2, 3), (3, 4), (4, 5), (1, 3), (2, 4) ] result = find_minimal_path(n, m, roads) assert result == [1, 2, 3] or result == [2, 3, 4] def test_minima...
[ { "docstring": null, "function_declaration": "def floyd_warshall(n, graph):", "function_name": "floyd_warshall", "parameter_list": "(n, graph)" }, { "docstring": null, "function_declaration": "def minimize_travel_distance(n, m, roads):", "function_name": "minimize_travel_distance", ...
[ 1, 1, 1, 0, 1, 1, 1, 0, 1, 1 ]
8
easy
0.8
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "import heapq\n\ndef find_shortest_paths(n, roads):\n # Initialize graph\n graph = [[] for _ in range(n + 1)]\n \n for u, v in roads:\n grap...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00007840", "row_id": 7840, "seed_ids": "[2597]" }
0.8019
Codeforces_7840
I
[ "floyd_warshall", "minimize_travel_distance", "find_minimal_path" ]
3
[ [ "find_minimal_path", "minimize_travel_distance" ], [ "minimize_travel_distance", "floyd_warshall" ] ]
2
[]
false
[]
false
pytest
true
[]
true
7179a60fe1f59f7ca760906c94733d37f5a1d7bf
be468d0d41e7e637aa217143f4145545ef35a03c
v1.0
instruct
Codeforces
Codeforces_7869_I
You are given a list of integers, and you need to find the length of the longest subsequence which meets the property that the sum of its elements is a prime number. A subsequence is obtained by deleting some or none of the elements from the list without changing the order of the remaining elements. The first line of ...
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 Tr...
from solution import longest_prime_sum_subsequence_length def test_single_case_with_prime(): t = 1 test_cases = [(5, [3, 7, 10, 2, 5])] assert longest_prime_sum_subsequence_length(t, test_cases) == [4] def test_single_case_without_prime(): t = 1 test_cases = [(4, [4, 6, 8, 12])] assert longest...
[ { "docstring": "Check if a number is prime.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": null, "function_declaration": "def longest_prime_sum_subsequence_length(t, test_cases):", "function_name": "longest_prime_s...
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "import math\n\ndef is_prime(x):\n if x < 2:\n return False\n for i in range(2, int(math.sqrt(x)) + 1):\n if x % i == 0:\n retur...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00007869", "row_id": 7869, "seed_ids": "[5354]" }
0.716704
Codeforces_7869
I
[ "is_prime", "longest_prime_sum_subsequence_length" ]
2
[ [ "longest_prime_sum_subsequence_length", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
1420b1d1768080af4a2244fc9b70731e658cb068
ecdf8b04bb7cfbc2fee7aaa746568f00a9f2973f
v1.0
instruct
Codeforces
Codeforces_7915_I
Given an integer array `nums` of length `n` containing distinct integers, your task is to return all possible permutations of the array in any order. A permutation of the array is a rearrangement of its elements. Your function should handle arrays with lengths up to 8. You may assume that all integers in the input arr...
from itertools import permutations def get_permutations(nums): """ Returns all possible permutations of the list nums. """ return list(permutations(nums)) def format_permutations(perms): """ Formats the permutations into a string representation, each permutation on a new line. """ ...
from solution import get_permutations, format_permutations, process_input def test_get_permutations(): assert get_permutations([1, 2]) == [(1, 2), (2, 1)] assert get_permutations([1, 2, 3]) == [ (1, 2, 3), (1, 3, 2), (2, 1, 3), (2, 3, 1), (3, 1, 2), (3, 2, 1) ...
[ { "docstring": "Returns all possible permutations of the list nums.", "function_declaration": "def get_permutations(nums):", "function_name": "get_permutations", "parameter_list": "(nums)" }, { "docstring": "Formats the permutations into a string representation, each permutation on a new lin...
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 0 ]
9
easy
0.9
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "from itertools import permutations\n\ndef generate_permutations(nums):\n \"\"\"\n Generate all possible permutations of the given list of distinct integ...
trial_gpt4o_7
{ "original_instruction": "", "prompt_id": "00007915", "row_id": 7915, "seed_ids": "[3344]" }
0.74944
Codeforces_7915
I
[ "get_permutations", "format_permutations", "process_input" ]
3
[ [ "process_input", "format_permutations" ], [ "process_input", "get_permutations" ] ]
2
[ "process_input" ]
false
[]
false
pytest
true
[]
true
bc8c6a4c89105122ddbed618828ea721534a726e
e1f422ff59a51a5d28a7a897d3dd43980e6bc6e7
v1.0
instruct
Codeforces
Codeforces_7933_I
Given an integer `n` (1 ≤ n ≤ 10^6), determine the smallest number of prime numbers whose sum is equal to `n`. If `n` is itself a prime number, then the answer is 1. Otherwise, test different sums composed of two or three primes, as necessary. Summarize the minimum count under given constraints. Example: Input: 27 ...
def is_prime(num): """ Determines if a number is a prime number. """ 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 ...
from solution import is_prime, smallest_prime_sum_count 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(16) == False assert is_prime(17) == True assert is_prime(1) == False assert is_prime(...
[ { "docstring": "Determines if a number is a prime number.", "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": "Determines the smallest number of prime numbers whose sum is equal to n.", "function_declaration": "def smal...
[ 0, 1, 0, 0, 0, 1, 0, 0, 0, 1 ]
3
hard
0.3
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(num):\n \"\"\"\n Helper function to check if a number is prime.\n \"\"\"\n if num <= 1:\n return False\n if num == 2:\n ...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00007933", "row_id": 7933, "seed_ids": "[1693]" }
0.597616
Codeforces_7933
I
[ "is_prime", "smallest_prime_sum_count" ]
2
[ [ "smallest_prime_sum_count", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
b40ab3fd31470a94e041a18e6c9277557a80ac6e
81215d4e7aa3e33d6dd4242fc2ffbb63f39b6332
v1.0
instruct
Codeforces
Codeforces_7972_I
You are given an undirected graph with `n` nodes and `m` edges. Each node has an integer value associated with it. Your task is to process multiple queries where each query asks you to calculate the sum of values of nodes that are connected to a given starting node, either directly or indirectly. Two nodes are consider...
def find_connected_components(n, edges): from collections import defaultdict, deque graph = defaultdict(list) for u, v in edges: graph[u].append(v) graph[v].append(u) visited = [False] * (n + 1) components = [] def bfs(node): queue = deque([node]) component...
from solution import process_queries def test_single_node(): assert process_queries(1, [], [10], [1]) == [10] def test_no_edges(): assert process_queries(3, [], [1, 2, 3], [1, 2, 3]) == [1, 2, 3] def test_all_connected(): assert process_queries(5, [(1, 2), (2, 3), (3, 4), (4, 5)], [1, 2, 3, 4, 5], [1, 3,...
[ { "docstring": null, "function_declaration": "def find_connected_components(n, edges):", "function_name": "find_connected_components", "parameter_list": "(n, edges)" }, { "docstring": null, "function_declaration": "def preprocess_values(n, values, components):", "function_name": "pre...
[ 0, 1, 1, 1, 1, 1, 0, 1, 1 ]
7
easy
0.778
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def calculate_connected_components_sum(n, m, node_values, edges, queries):\n from collections import defaultdict, deque\n \n # Represent the graph as...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00007972", "row_id": 7972, "seed_ids": "[4641]" }
0.741736
Codeforces_7972
I
[ "find_connected_components", "preprocess_values", "process_queries" ]
3
[ [ "process_queries", "find_connected_components" ], [ "process_queries", "preprocess_values" ] ]
2
[ "process_queries" ]
false
[]
false
pytest
true
[]
true
6eeec71fb0a4e983a1e18dd42d0d28367ed3d430
5d63f6febb073f65cc7a45feacea6ae6cf23aedb
v1.0
instruct
Codeforces
Codeforces_8038_I
There is a kingdom made up of $$$n$$$ cities connected by two-way roads. The cities are numbered from $$$1$$$ to $$$n$$$. The kingdom is planning to construct a new capital city, $$$c$$$ ($$$1 \le c \le n$$$). For the project, a specific task is to determine the minimum time required to send an invitation from any ci...
import heapq import sys input = sys.stdin.read def dijkstra(n, c, roads): graph = [[] for _ in range(n + 1)] for u, v, w in roads: graph[u].append((v, w)) graph[v].append((u, w)) dist = [sys.maxsize] * (n + 1) dist[c] = 0 pq = [(0, c)] while pq: current_dist, u = h...
from solution import dijkstra, solve import io import sys def test_dijkstras_simple_graph(): n = 3 c = 1 roads = [ (1, 2, 1), (2, 3, 1), (3, 1, 4) ] assert dijkstra(n, c, roads) == [0, 1, 2] def test_dijkstra_larger_graph(): n = 5 c = 3 roads = [ (1, 2, ...
[ { "docstring": null, "function_declaration": "def dijkstra(n, c, roads):", "function_name": "dijkstra", "parameter_list": "(n, c, roads)" }, { "docstring": null, "function_declaration": "def solve():", "function_name": "solve", "parameter_list": "()" } ]
[ 0, 0, 0, 0, 1, 1, 1, 0, 1, 0 ]
4
medium
0.4
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "import heapq\nimport sys\n\ndef minimum_invitation_time(t, test_cases):\n results = []\n for case in test_cases:\n n, c, roads = case\n gr...
trial_gpt4o_5
{ "original_instruction": "", "prompt_id": "00008038", "row_id": 8038, "seed_ids": "[2066]" }
0.822222
Codeforces_8038
I
[ "dijkstra", "solve" ]
2
[ [ "solve", "dijkstra" ] ]
1
[]
false
[]
false
pytest
true
[]
true
2a18b32076b92ec7239cd79e5b738a5adefd634d
5b4126c2822ba65a1ce26973febbb9f6e2b7f28b
v1.0
instruct
Codeforces
Codeforces_8158_I
**You are tasked with developing a new navigation system for a quantum computing research facility. The facility's network can be represented as a directed graph with n nodes and m edges, where each node corresponds to a specific location within the facility, and each edge represents a permissible direct path between t...
import sys import heapq def dijkstra(n, adj, start): dist = [sys.maxsize] * (n + 1) dist[start] = 0 priority_queue = [(0, start)] while priority_queue: current_distance, current_node = heapq.heappop(priority_queue) if current_distance > dist[current_node]: continue ...
def test_shortest_path(): n = 4 m = 4 edges = [ (1, 2, 5), (2, 3, 10), (3, 4, 1), (1, 3, 20) ] queries = [(1, 3), (2, 4), (1, 4)] expected_output = [15, 11, 16] assert shortest_path(n, edges, queries) == expected_output def test_no_path(): n = 3...
[ { "docstring": null, "function_declaration": "def dijkstra(n, adj, start):", "function_name": "dijkstra", "parameter_list": "(n, adj, start)" }, { "docstring": null, "function_declaration": "def shortest_path(n, edges, queries):", "function_name": "shortest_path", "parameter_list...
[ 0, 0, 0, 0, 1, 0, 0, 1, 0, 1 ]
3
hard
0.3
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "import sys\nimport heapq\n\ndef dijkstra(graph, start, n):\n distances = [float('inf')] * (n + 1)\n distances[start] = 0\n min_heap = [(0, start)]\n ...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00008158", "row_id": 8158, "seed_ids": "[5446]" }
0.683188
Codeforces_8158
I
[ "dijkstra", "shortest_path" ]
2
[ [ "shortest_path", "dijkstra" ] ]
1
[]
false
[]
false
pytest
false
[]
true
762b711e327931e8c58db9653d1d7f890feb7856
889fac0b79022d911f88c8816e1fc65ef01e6e9d
v1.0
instruct
Codeforces
Codeforces_8224_I
You are working on a project to optimize network usage for a company. The company's network consists of $$$n$$$ servers and $$$m$$$ two-way communication links between the servers. Each link has a certain amount of data $$$d$$$ that it can transfer per unit time. The company wants to maximize the flow of data from a ...
from collections import deque, defaultdict def bfs(C, F, source, sink, parent): visited = set() queue = deque([source]) visited.add(source) while queue: u = queue.popleft() for v in C[u]: if v not in visited and C[u][v] - F[u][v] > 0: queue.appe...
from solution import max_data_flow def test_max_data_flow_basic(): n = 4 m = 5 links = [(1, 2, 100), (1, 3, 100), (2, 3, 1), (2, 4, 100), (3, 4, 100)] s = 1 t = 4 assert max_data_flow(n, m, links, s, t) == 200 def test_max_data_flow_single_path(): n = 3 m = 2 links = [(1, 2, 5), (2...
[ { "docstring": null, "function_declaration": "def bfs(C, F, source, sink, parent):", "function_name": "bfs", "parameter_list": "(C, F, source, sink, parent)" }, { "docstring": "Using Edmonds-Karp algorithm to find the maximum flow ", "function_declaration": "def edmonds_karp(C, source, s...
[ 0, 1, 0, 0, 1, 0, 1, 0, 1, 0 ]
4
medium
0.4
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "from collections import defaultdict, deque\n\ndef bfs(C, F, source, sink, parent):\n visited = set()\n queue = deque([source])\n visited.add(source)\...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00008224", "row_id": 8224, "seed_ids": "[27]" }
0.622476
Codeforces_8224
I
[ "bfs", "edmonds_karp", "max_data_flow" ]
3
[ [ "edmonds_karp", "bfs" ], [ "max_data_flow", "edmonds_karp" ] ]
2
[]
false
[]
false
pytest
true
[]
true
30c5a44fa14a28ebd8f1370aa30b881f2887090a
f76611a15020b21a70586f48c40a97ec24527f3c
v1.0
instruct
Codeforces
Codeforces_8229_I
Mishra loves coding and has just started learning about sorting algorithms. However, he finds the concept of inversion count in an array fascinating. An inversion in an array is a pair of elements (arr[i], arr[j]) such that arr[i] > arr[j] and i < j. Mishra wants to determine how "unsorted" the array is by finding the ...
def merge_and_count(arr, temp_arr, left, mid, right): i = left # Starting index for left subarray j = mid + 1 # Starting index for right subarray k = left # Starting index to be sorted inv_count = 0 # Conditions are checked to ensure that i doesn't exceed mid and j doesn't exceed right ...
from solution import count_inversions def test_count_inversions_example(): assert count_inversions([1, 20, 6, 4, 5]) == 5 def test_count_inversions_sorted_array(): assert count_inversions([1, 2, 3, 4, 5]) == 0 def test_count_inversions_reverse_sorted_array(): assert count_inversions([5, 4, 3, 2, 1]) == 1...
[ { "docstring": null, "function_declaration": "def merge_and_count(arr, temp_arr, left, mid, right):", "function_name": "merge_and_count", "parameter_list": "(arr, temp_arr, left, mid, right)" }, { "docstring": null, "function_declaration": "def merge_sort_and_count(arr, temp_arr, left, r...
[ 1, 1, 1, 1, 1, 1, 0, 1, 0, 1 ]
8
easy
0.8
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def count_inversions(arr):\n \"\"\"\n Counts the number of inversions in the array using a modified merge sort algorithm.\n \"\"\"\n if len(arr) <...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00008229", "row_id": 8229, "seed_ids": "[1399]" }
0.737069
Codeforces_8229
I
[ "merge_and_count", "merge_sort_and_count", "count_inversions" ]
3
[ [ "count_inversions", "merge_sort_and_count" ], [ "merge_sort_and_count", "merge_and_count" ] ]
2
[]
false
[]
false
pytest
true
[]
true
d6d4c334476e53120ca5de54beff2d35b7697c49
a26c9b6a718c4902636c0e23856d3e4613edfe7d
v1.0
instruct
Codeforces
Codeforces_8241_I
You are an engineer working on a network of computers that need to communicate with each other. The network is represented as a graph where each computer is a node and the communication paths between them are edges with weights representing the time it takes to send a message between those computers. Your task is to d...
def find(parent, i): if parent[i] == i: return i parent[i] = find(parent, parent[i]) return parent[i] def union(parent, rank, x, y): rootX = find(parent, x) rootY = find(parent, y) if rootX != rootY: if rank[rootX] > rank[rootY]: parent[rootY] = rootX el...
from solution import min_spanning_tree def test_sample_input_1(): assert min_spanning_tree(4, [ (1, 2, 3), (1, 3, 2), (1, 4, 4), (2, 3, 1), (3, 4, 5) ]) == 7 def test_sample_input_2(): assert min_spanning_tree(3, [ (1, 2, 2) ]) == "IMPOSSIBLE" def test_single_node_no_edges(): ...
[ { "docstring": null, "function_declaration": "def find(parent, i):", "function_name": "find", "parameter_list": "(parent, i)" }, { "docstring": null, "function_declaration": "def union(parent, rank, x, y):", "function_name": "union", "parameter_list": "(parent, rank, x, y)" }, ...
[ 0, 0, 0, 0, 0, 0, 1, 0, 0, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def find_minimum_spanning_tree(n, edges):\n \"\"\"\n Finds the minimum spanning tree of a graph using Kruskal's algorithm.\n \n :param n: Number o...
trial_gpt4o_6
{ "original_instruction": "", "prompt_id": "00008241", "row_id": 8241, "seed_ids": "[6133]" }
0.756252
Codeforces_8241
I
[ "find", "union", "min_spanning_tree" ]
3
[ [ "min_spanning_tree", "find" ], [ "min_spanning_tree", "union" ], [ "union", "find" ] ]
3
[]
false
[]
false
pytest
true
[]
true
e59f98fdce4ea6a7d48eaa6b62c85623745663dd
3e80995947c929548de882cf829c3867f0a4cd9d