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_33953_I
Given an array of integers, determine the maximum product that can be obtained by multiplying any three distinct elements of the array. The array can contain both positive and negative integers. The first line of the input contains an integer n (3 ≤ n ≤ 105) — the number of elements in the array. The second line cont...
def max_product_of_three(nums): nums.sort() return max(nums[-1] * nums[-2] * nums[-3], nums[0] * nums[1] * nums[-1]) def max_product_from_input_string(input_string): # Parse input input_lines = input_string.strip().split("\n") n = int(input_lines[0]) nums = list(map(int, input_lines[1].split())...
from solution import max_product_from_input_string def test_example_case(): input_str = "5\n-10 -10 5 2 1" assert max_product_from_input_string(input_str) == 500 def test_all_positive_numbers(): input_str = "4\n1 2 3 4" assert max_product_from_input_string(input_str) == 24 def test_all_negative_numbe...
[ { "docstring": null, "function_declaration": "def max_product_of_three(nums):", "function_name": "max_product_of_three", "parameter_list": "(nums)" }, { "docstring": null, "function_declaration": "def max_product_from_input_string(input_string):", "function_name": "max_product_from_i...
[ 1, 0, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def max_product_of_three(nums):\n nums.sort()\n return max(nums[-1] * nums[-2] * nums[-3], nums[0] * nums[1] * nums[-1])\n\ndef max_product_from_input_s...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00033953", "row_id": 33953, "seed_ids": "[6541, 7126, 2675]" }
0.74205
Codeforces_33953
I
[ "max_product_of_three", "max_product_from_input_string" ]
2
[ [ "max_product_from_input_string", "max_product_of_three" ] ]
1
[]
false
[]
false
pytest
true
[]
true
71aacb4f05eae27a7b6ac4547c893b63defc82bd
fb5601e90793940d6e99ecf351aa29dd50259836
v1.0
instruct
Codeforces
Codeforces_34010_I
Given an integer n, you are asked to transform it into a palindrome by reversing its digits and adding the result to the original number. If the sum is not a palindrome, repeat the process until the sum is a palindrome. The task is to find the resulting palindrome and the number of iterations required to reach it. Not...
def is_palindrome(number): """ Check if the given integer is a palindrome. """ str_num = str(number) return str_num == str_num[::-1] def reverse_number(number): """ Return the reverse of the given integer. """ return int(str(number)[::-1]) def palindrome_transform(n): """ T...
from solution import palindrome_transform def test_single_digit_palindrome(): assert palindrome_transform(5) == (5, 0) def test_example_case(): assert palindrome_transform(96) == (4884, 4) def test_no_iteration_needed(): assert palindrome_transform(121) == (121, 0) def test_small_number(): assert pa...
[ { "docstring": "Check if the given integer is a palindrome.", "function_declaration": "def is_palindrome(number):", "function_name": "is_palindrome", "parameter_list": "(number)" }, { "docstring": "Return the reverse of the given integer.", "function_declaration": "def reverse_number(num...
[ 0, 0, 0, 0, 0, 0, 0, 0, 1, 1 ]
2
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_palindrome(n):\n \"\"\"\n Checks if a given integer n is a palindrome.\n \"\"\"\n s = str(n)\n return s == s[::-1]\n\ndef reverse_number...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00034010", "row_id": 34010, "seed_ids": "[2349, 3738, 2456]" }
0.794468
Codeforces_34010
I
[ "is_palindrome", "reverse_number", "palindrome_transform" ]
3
[ [ "palindrome_transform", "is_palindrome" ], [ "palindrome_transform", "reverse_number" ] ]
2
[]
false
[]
false
pytest
true
[]
true
0c9784f0257605cc6f89d64ff7df9db7fde2df92
419298b1c2efce44d555382d3ea7a687fd85648d
v1.0
instruct
Codeforces
Codeforces_34078_I
Anna is a software engineer who likes to analyze the performance of different sorting algorithms. She has been given n arrays and asked to determine if each array is already sorted in non-decreasing order. Your task is to help Anna by writing a program that checks if each given array is sorted in non-decreasing order....
def is_sorted_array(array): """ Checks if the given array is sorted in non-decreasing order. """ for i in range(1, len(array)): if array[i] < array[i - 1]: return "NO" return "YES" def check_sorted_arrays(input_list): """ Processes multiple arrays and checks if each arra...
import pytest from solution import check_sorted_arrays def test_single_sorted_array(): input_list = [[5, 1, 2, 3, 4, 5]] expected_output = ["YES"] assert check_sorted_arrays(input_list) == expected_output def test_single_unsorted_array(): input_list = [[4, 1, 3, 2, 4]] expected_output = ["NO"] ...
[ { "docstring": "Checks if the given array is sorted in non-decreasing order.", "function_declaration": "def is_sorted_array(array):", "function_name": "is_sorted_array", "parameter_list": "(array)" }, { "docstring": "Processes multiple arrays and checks if each array is sorted\nin non-decrea...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_sorted_in_non_decreasing_order(arr):\n \"\"\"\n Checks if the given list is sorted in non-decreasing order.\n \"\"\"\n return all(arr[i] <=...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00034078", "row_id": 34078, "seed_ids": "[1592, 8, 4507]" }
0.622003
Codeforces_34078
I
[ "is_sorted_array", "check_sorted_arrays" ]
2
[ [ "check_sorted_arrays", "is_sorted_array" ] ]
1
[]
false
[]
false
pytest
true
[]
true
329d8bc516fdfa186b5718d45ba0b87d043e869a
6550aced69963c019908f7297fc3aed62ab62af9
v1.0
instruct
Codeforces
Codeforces_34079_I
A kingdom consists of n cities connected by n-1 bidirectional roads in such a way that there is exactly one path between any two cities (forming a tree). Each road between cities i and j has a specific length d[i][j]. The king lives in city 1 and wants to establish a communication network where every other city will ...
import heapq def max_communication_time(n, roads): def dijkstra(graph, start): distances = [float('inf')] * (n + 1) distances[start] = 0 pq = [(0, start)] while pq: (current_distance, current_node) = heapq.heappop(pq) if current_distance > distances[...
from solution import max_time_to_farthest_city def test_max_time_to_farthest_city_1(): n = 5 roads = [ (1, 2, 3), (1, 3, 2), (3, 4, 4), (3, 5, 5) ] assert max_time_to_farthest_city(n, roads) == 7 def test_max_time_to_farthest_city_2(): n = 3 roads = [ (1...
[ { "docstring": null, "function_declaration": "def max_communication_time(n, roads):", "function_name": "max_communication_time", "parameter_list": "(n, roads)" }, { "docstring": null, "function_declaration": "def max_time_to_farthest_city(n, edges):", "function_name": "max_time_to_fa...
[ 1, 0, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "import heapq\n\ndef max_communication_time(n, roads):\n def dijkstra(graph, start):\n distances = [float('inf')] * (n + 1)\n distances[start]...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00034079", "row_id": 34079, "seed_ids": "[5719, 1662, 512]" }
0.731262
Codeforces_34079
I
[ "max_communication_time", "max_time_to_farthest_city" ]
2
[ [ "max_time_to_farthest_city", "max_communication_time" ] ]
1
[]
false
[]
false
pytest
true
[]
true
c0bd5af930f91f4c18f865547d7e88a4920118e3
5211d26653c7f77ecbfe99195db1af6dee77d6c3
v1.0
instruct
Codeforces
Codeforces_34171_I
A local construction company undertakes a project to build water supply pipelines for a new housing complex. The project involves connecting the houses with each other. There are n houses, and the company has an initial supply of various pipes, each with a defined length and diameter. The goal is to design a pipeline ...
def find(parent, i): if parent[i] == i: return i else: return find(parent, parent[i]) def union(parent, rank, x, y): xroot = find(parent, x) yroot = find(parent, y) if rank[xroot] < rank[yroot]: parent[xroot] = yroot elif rank[xroot] > rank[yroot]: paren...
from solution import maximize_minimum_diameter def test_example_case(): assert maximize_minimum_diameter(4, 5, [(1, 2, 4), (1, 3, 2), (2, 3, 3), (2, 4, 5), (3, 4, 1)]) == 3 def test_no_connection(): assert maximize_minimum_diameter(2, 1, [(1, 2, 1)]) == 1 assert maximize_minimum_diameter(2, 0, []) == -1 ...
[ { "docstring": null, "function_declaration": "def find(parent, i):", "function_name": "find", "parameter_list": "(parent, i)" }, { "docstring": null, "function_declaration": "def union(parent, rank, x, y):", "function_name": "union", "parameter_list": "(parent, rank, x, y)" }, ...
[ 0, 1, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def find(parent, i):\n if parent[i] == i:\n return i\n else:\n parent[i] = find(parent, parent[i])\n return parent[i]\n\ndef union(...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00034171", "row_id": 34171, "seed_ids": "[1332, 8166, 4765]" }
0.597518
Codeforces_34171
I
[ "find", "union", "maximize_minimum_diameter" ]
3
[ [ "maximize_minimum_diameter", "find" ], [ "maximize_minimum_diameter", "union" ], [ "union", "find" ] ]
3
[]
false
[]
false
pytest
true
[]
true
39324371c408e61363d2e63a95ea0d032ed59828
e68fa26310d0990313a57e8fafbf34106b5d1617
v1.0
instruct
Codeforces
Codeforces_34207_I
You are given an array of n positive integers. Your task is to transform this array into another array where each number is replaced by the sum of its digits. You need to determine the minimum number of operations required to make all elements in the transformed array equal. In each operation, you can pick any number ...
def digit_sum(n): """Calculate the sum of the digits of a number.""" return sum(int(d) for d in str(n)) def transform_to_equal(arr): """ Transforms the array into another array where each number is replaced by the sum of its digits. Returns the minimum number of operations required to make all elem...
from solution import digit_sum, transform_to_equal def test_digit_sum(): assert digit_sum(123) == 6 assert digit_sum(10) == 1 assert digit_sum(999) == 27 assert digit_sum(0) == 0 def test_transform_to_equal_single_element(): assert transform_to_equal([123]) == 1 # 123 -> 6 def test_transform...
[ { "docstring": "Calculate the sum of the digits of a number.", "function_declaration": "def digit_sum(n):", "function_name": "digit_sum", "parameter_list": "(n)" }, { "docstring": "Transforms the array into another array where each number is replaced by the sum of its digits.\nReturns the mi...
[ 0, 0, 0, 0, 0, 0, 0, 0, 1, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def digit_sum(n):\n \"\"\"\n Helper function to calculate the sum of the digits of a number.\n \"\"\"\n return sum(int(digit) for digit in str(n))...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00034207", "row_id": 34207, "seed_ids": "[242, 4211, 1455]" }
0.739791
Codeforces_34207
I
[ "digit_sum", "transform_to_equal" ]
2
[ [ "transform_to_equal", "digit_sum" ] ]
1
[]
false
[]
false
pytest
true
[]
true
cfbfbdcd9a89a769ff66865168a4a2c548c7ba50
ed22d53adf582d3bd2159c6e985b4d9f296c4f68
v1.0
instruct
Codeforces
Codeforces_34208_I
You are given an undirected graph containing `n` nodes and `m` edges. Each edge has an associated weight, which can be positive, negative, or zero. Your task is to compute the sum of the weights of the Minimum Spanning Tree (MST) of the graph. If there are multiple MSTs with the same weight, their weight sums will obvi...
class DisjointSet: def __init__(self, n): self.parent = list(range(n)) self.rank = [0] * n def find(self, u): if self.parent[u] != u: self.parent[u] = self.find(self.parent[u]) return self.parent[u] def union(self, u, v): root_u = self.find(u) ...
def test_mst_weight_sum_example_1(): n, m = 4, 5 edges = [(1, 2, 1), (1, 3, 2), (2, 3, 2), (2, 4, 3), (3, 4, 3)] assert mst_weight_sum(n, m, edges) == 6 def test_mst_weight_sum_example_2(): n, m = 4, 2 edges = [(1, 2, -1), (3, 4, -2)] assert mst_weight_sum(n, m, edges) == "IMPOSSIBLE" def test...
[]
[ 0, 1, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def find(parent, i):\n if parent[i] == i:\n return i\n return find(parent, parent[i])\n\ndef union(parent, rank, x, y):\n root_x = find(parent...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00034208", "row_id": 34208, "seed_ids": "[2343, 3118, 6759]" }
0.836261
Codeforces_34208
I
[ "kruskal_mst", "mst_weight_sum" ]
2
[ [ "mst_weight_sum", "kruskal_mst" ] ]
1
[]
false
[ "DisjointSet" ]
true
pytest
false
[]
true
06de071ee8e5b695e896a4b0bc1c6bb172299e0e
1e03aaaf3acc1de1b716876164fac57d2b71c598
v1.0
instruct
Codeforces
Codeforces_34212_I
You have been given an array of integers $$$a$$$ of length $$$n$$$. You are to perform a sequence of operations to transform the array such that all its elements become zeros. An operation consists of choosing three distinct indices $$$i$$$, $$$j$$$, and $$$k$$$ (1 ≤ $$$i, j, k$$$ ≤ $$$n$$$ and $$$i ≠ j ≠ k$$$) such th...
def can_transform_to_zero(t, test_cases): results = [] for case in test_cases: n = case['n'] array = case['array'] # Check if total number of elements in array is divisible by 3 if sum(array) % 3 != 0: results.append("NO") continue ...
def test_can_transform_to_zero_single_case(): assert can_transform_to_zero(1, [{'n': 3, 'array': [1, 1, 1]}]) == ["YES\n0"] def test_can_transform_to_zero_single_case_no(): assert can_transform_to_zero(1, [{'n': 4, 'array': [1, 2, 3, 4]}]) == ["NO"] def test_can_transform_to_zero_multiple_cases(): ass...
[ { "docstring": null, "function_declaration": "def can_transform_to_zero(t, test_cases):", "function_name": "can_transform_to_zero", "parameter_list": "(t, test_cases)" }, { "docstring": null, "function_declaration": "def array_transformation(t, test_cases_raw):", "function_name": "ar...
[ 0, 0, 0, 1, 1 ]
2
medium
0.4
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def can_transform_to_zero(n, a):\n sum_a = sum(a)\n if (sum_a % 2) != 0:\n return (\"NO\", [])\n \n operations = []\n while any(a):\n ...
trial_gpt4o_4
{ "original_instruction": "", "prompt_id": "00034212", "row_id": 34212, "seed_ids": "[3492, 7589, 2947]" }
0.714317
Codeforces_34212
I
[ "can_transform_to_zero", "array_transformation" ]
2
[ [ "array_transformation", "can_transform_to_zero" ] ]
1
[]
false
[]
false
pytest
false
[]
true
ab844fcd2db9e98b4d7ee7ba1909036f3135564a
89990de54fb0ad63f28fc1f7b622e6d797b99621
v1.0
instruct
Codeforces
Codeforces_34256_I
Alice loves playing with strings. She defines the "beauty" of a string as the number of distinct substrings it contains. Given a string $$$s$$$, Alice wants to know how "beautiful" it is according to her definition. Can you help her? The first line contains an integer $$$t$$$ ($$$1 \le t \le 10^5$$$) — the number of t...
class SuffixAutomaton: def __init__(self, s): self.s = s self.states = [{}] self.link = [-1] self.length = [0] self.last = 0 self.pad = [] for a in list(s): self.extend(a) def extend(self, c): current = len(self.states) sel...
from solution import process_input def test_beauty_of_string_1(): assert process_input(2, ["ab", "aaa"]) == [3, 3] def test_beauty_of_string_2(): assert process_input(1, ["abc"]) == [6] def test_beauty_of_string_3(): assert process_input(1, ["aaaa"]) == [4] def test_beauty_of_string_4(): assert proc...
[]
[ 1, 1, 0 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def beauty_of_string(s):\n \"\"\"\n Returns the beauty of the string s, defined as the number of distinct substrings.\n \"\"\"\n # Set to store al...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00034256", "row_id": 34256, "seed_ids": "[2086, 3824, 2594]" }
0.764968
Codeforces_34256
I
[ "beauty_of_string", "beauty_of_strings", "process_input" ]
3
[ [ "beauty_of_strings", "beauty_of_string" ], [ "process_input", "beauty_of_strings" ] ]
2
[ "process_input" ]
false
[ "SuffixAutomaton" ]
true
pytest
true
[]
true
b8b91bfac71c3282b3e07bf2ed51f1bb4044bae8
65b288ebdd2717de42bb0a4a78cece5bcdbc9028
v1.0
instruct
Codeforces
Codeforces_34292_I
You are given a string $$$s$$$ consisting of lowercase English letters. Your task is to modify the string such that it becomes a palindrome by removing at most one character. A palindrome is a string that reads the same backward as forward. For example, "abca" can be modified to "aba" by removing the character 'c', wh...
def is_palindrome(s: str) -> bool: return s == s[::-1] def can_be_palindrome_by_removing_one_char(s: str) -> str: left, right = 0, len(s) - 1 while left < right: if s[left] != s[right]: # Check by removing one character either from left or right if is_palindrome(s[left:right...
from solution import process_test_cases def test_can_be_palindrome_by_removing_one_char(): assert process_test_cases(3, ["abca", "racecar", "abc"]) == ["YES", "YES", "NO"] assert process_test_cases(2, ["madam", "aabaa"]) == ["YES", "YES"] assert process_test_cases(1, ["abcdefg"]) == ["NO"] assert proce...
[ { "docstring": null, "function_declaration": "def is_palindrome(s):", "function_name": "is_palindrome", "parameter_list": "(s)" }, { "docstring": null, "function_declaration": "def can_be_palindrome_by_removing_one_char(s):", "function_name": "can_be_palindrome_by_removing_one_char",...
[ 1, 0, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def can_be_palindrome_by_removing_one_char(s):\n \"\"\"\n Checks if a string can be transformed into a palindrome by removing at most one character.\n ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00034292", "row_id": 34292, "seed_ids": "[561, 655, 7067]" }
0.88349
Codeforces_34292
I
[ "is_palindrome", "can_be_palindrome_by_removing_one_char", "process_test_cases" ]
3
[ [ "can_be_palindrome_by_removing_one_char", "is_palindrome" ], [ "process_test_cases", "can_be_palindrome_by_removing_one_char" ] ]
2
[ "process_test_cases" ]
false
[]
false
pytest
true
[]
true
f34bcb8aded50d01a5efbc87e1325ffddc7fde9b
d6a93f27a340ac8bc656901c772f0f62813a8693
v1.0
instruct
Codeforces
Codeforces_34298_I
A certain kingdom consists of $$$n$$$ towns connected by $$$m$$$ bidirectional roads. Each road has a travel time. The king wants to establish a center of the kingdom such that the maximum travel time from this center to any other town is minimized. The travel times between towns can be large, so it's important to find...
import heapq def dijkstra(graph, start, n): distances = [float('inf')] * (n + 1) distances[start] = 0 priority_queue = [(0, start)] while priority_queue: current_distance, current_node = heapq.heappop(priority_queue) if current_distance > distances[current_node]: ...
def test_example(): n, m = 4, 4 roads = [ (1, 2, 4), (1, 3, 3), (2, 3, 1), (3, 4, 2) ] assert find_optimal_center(n, roads) == 3 def test_small_case(): n, m = 2, 1 roads = [ (1, 2, 5) ] assert find_optimal_center(n, roads) == 5 def test_complete_...
[ { "docstring": null, "function_declaration": "def dijkstra(graph, start, n):", "function_name": "dijkstra", "parameter_list": "(graph, start, n)" }, { "docstring": null, "function_declaration": "def find_optimal_center(n, roads):", "function_name": "find_optimal_center", "paramet...
[ 0, 0, 1 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "import heapq\n\ndef dijkstra(n, graph, start):\n max_time = [float('inf')] * (n + 1)\n max_time[start] = 0\n pq = [(0, start)]\n while pq:\n ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00034298", "row_id": 34298, "seed_ids": "[4989, 6691, 3178]" }
0.72527
Codeforces_34298
I
[ "dijkstra", "find_optimal_center" ]
2
[ [ "find_optimal_center", "dijkstra" ] ]
1
[]
false
[]
false
pytest
false
[]
true
e9d0da25f56f76aaf923ed45871a99bbd2abba4e
0a7517de36e9308b4bd46d7982a8d8f3cda4a2b8
v1.0
instruct
Codeforces
Codeforces_34333_I
In a land where communication through codes is essential, a secret society has developed a unique way of encrypting their numeric messages. The encryption process involves taking a number and transforming it by repeatedly replacing each digit by the sum of the digits of the original number until a single digit is obtai...
def digital_root(num): """ Returns the single digit result of repeatedly summing the digits of num until a single digit is obtained. """ while num >= 10: num = sum(int(digit) for digit in str(num)) return num def process_numbers(numbers): """ Takes a list of numbers and returns a li...
from solution import digital_root, process_numbers def test_digital_root_single_digit(): assert digital_root(5) == 5 def test_digital_root_multiple_iterations(): assert digital_root(9875) == 2 assert digital_root(123) == 6 def test_digital_root_two_digits(): assert digital_root(67) == 4 def test_pro...
[ { "docstring": "Returns the single digit result of repeatedly summing the digits of num until a single digit is obtained.", "function_declaration": "def digital_root(num):", "function_name": "digital_root", "parameter_list": "(num)" }, { "docstring": "Takes a list of numbers and returns a li...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def digital_root(n):\n \"\"\"\n Returns the digital root of an integer n.\n \"\"\"\n while n >= 10:\n n = sum(map(int, str(n)))\n return...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00034333", "row_id": 34333, "seed_ids": "[5634, 2250, 1981]" }
0.683939
Codeforces_34333
I
[ "digital_root", "process_numbers" ]
2
[ [ "process_numbers", "digital_root" ] ]
1
[]
false
[]
false
pytest
true
[]
true
89ee7e75b677fb06f88cad44e95fcdddfac0b12d
ee0e588c0683e684625c9d8f813550c5b41f3bb8
v1.0
instruct
Codeforces
Codeforces_34338_I
The citizens of Blueland have developed a unique numerical system based on letters from the alphabet. Each letter in the alphabet corresponds to a unique digit from 0 to 9. You are given a string t consisting of lowercase English letters, representing a number in this unusual system. You are also given several substitu...
def max_numeric_value(t, rules): from collections import defaultdict # Create a dict to store the most valuable replacement for each character replacement_map = defaultdict(str) for rule in rules: a, b = rule.split() if replacement_map[a] == '' or replacement_map[a] < b: ...
from solution import utilize_substitution def test_single_replacement(): t = "abc" q = 3 rules = ["a d", "b e", "c f"] assert utilize_substitution(t, q, rules) == "def" def test_multiple_replacement(): t = "aaa" q = 3 rules = ["a b", "b c", "c d"] assert utilize_substitution(t, q, rule...
[ { "docstring": null, "function_declaration": "def max_numeric_value(t, rules):", "function_name": "max_numeric_value", "parameter_list": "(t, rules)" }, { "docstring": null, "function_declaration": "def utilize_substitution(t, q, rules):", "function_name": "utilize_substitution", ...
[ 0, 0, 0, 1, 0 ]
1
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def maximize_value(t, q, rules):\n # Create a dictionary to hold the best possible substitution for each letter\n best_substitution = {chr(i): chr(i) fo...
trial_gpt4o_3
{ "original_instruction": "", "prompt_id": "00034338", "row_id": 34338, "seed_ids": "[6036, 4194, 3698]" }
0.674835
Codeforces_34338
I
[ "max_numeric_value", "utilize_substitution" ]
2
[ [ "utilize_substitution", "max_numeric_value" ] ]
1
[]
false
[]
false
pytest
true
[]
true
b9b3ee2ae567bfc872f9d96f9d93bf7a709fb88c
445e6a5a303ded505f77764716262b189fa5b337
v1.0
instruct
Codeforces
Codeforces_34344_I
A city's road network can be represented as a graph consisting of $$$n$$$ intersections and $$$m$$$ bidirectional roads. Each road connects two intersections and has a certain length associated with it. The government has decided to build new roads. However, due to cost constraints, they want to minimize the total leng...
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): xroot = find(parent, x) yroot = find(parent, y) if rank[xroot] < rank[yroot]: parent[xroot] = yroot elif rank[xroot] > rank[yroot]: ...
from solution import min_additional_roads_to_connect def test_no_road_needed(): n = 3 m = 3 edges = [(1, 2, 1), (2, 3, 1), (3, 1, 1)] assert min_additional_roads_to_connect(n, m, edges) == 0 def test_one_road_needed(): n = 4 m = 2 edges = [(1, 2, 5), (3, 4, 7)] assert min_additional_ro...
[ { "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, 1 ]
1
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def find(parent, i):\n if parent[i] == i:\n return i\n else:\n parent[i] = find(parent, parent[i])\n return parent[i]\n\ndef union(...
trial_gpt4o_4
{ "original_instruction": "", "prompt_id": "00034344", "row_id": 34344, "seed_ids": "[5109, 3658, 4581]" }
0.7381
Codeforces_34344
I
[ "find", "union", "min_additional_roads_to_connect" ]
3
[ [ "min_additional_roads_to_connect", "find" ], [ "min_additional_roads_to_connect", "union" ], [ "union", "find" ] ]
3
[]
false
[]
false
pytest
true
[]
true
d0426078884788a4b96bd02514345c9a6fa073fc
49c449194cd489bb6fc0d7b015246e64c196c0cc
v1.0
instruct
Codeforces
Codeforces_34351_I
Sebastian loves sequences, especially ones with interesting properties. He is currently fascinated by sequences where the sum of any two adjacent elements is a prime number. Given an integer $$$n$$$ ($$$2 \le n \le 10^5$$$), construct a sequence of length $$$n$$$ such that the sum of any two adjacent elements is a pri...
def is_prime(num): if num <= 1: return False if num <= 3: return True if num % 2 == 0 or num % 3 == 0: return False i = 5 while (i * i) <= num: if num % i == 0 or num % (i + 2) == 0: return False i += 6 return True def prime_pairs_prefix_seque...
from solution import solve, is_prime, prime_pairs_prefix_sequence def test_is_prime(): assert is_prime(2) assert is_prime(3) assert not is_prime(4) assert is_prime(5) assert not is_prime(6) assert is_prime(7) def test_prime_pairs_prefix_sequence(): assert prime_pairs_prefix_sequence(2) == ...
[ { "docstring": null, "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": null, "function_declaration": "def prime_pairs_prefix_sequence(n):", "function_name": "prime_pairs_prefix_sequence", "parameter_list": "(n)"...
[ 1 ]
1
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(num):\n 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_0
{ "original_instruction": "", "prompt_id": "00034351", "row_id": 34351, "seed_ids": "[8273, 2200, 1457]" }
0.660812
Codeforces_34351
I
[ "is_prime", "prime_pairs_prefix_sequence", "solve", "output_results" ]
4
[ [ "solve", "prime_pairs_prefix_sequence" ] ]
1
[]
false
[]
false
pytest
true
[]
true
26a7775b99ee3fccebce61125002a437a3d3c607
4eb83a62f55a04c30dd7038f038b035caa73eb21
v1.0
instruct
Codeforces
Codeforces_34361_I
You have a grid of size m × n representing a map where '1's represent land and '0's represent water. A cell is defined to be connected to another cell if they share edges (no diagonals). An island on this grid is a group of connected '1's (land cells) surrounded by '0's (water). A single connected group of '1's forms o...
def numIslands(grid): if not grid: return 0 m, n = len(grid), len(grid[0]) visited = [[False] * n for _ in range(m)] def dfs(i, j): stack = [(i, j)] while stack: x, y = stack.pop() for dx, dy in [(-1, 0), (1, 0), (0, -1), (0, 1)]: nx, ...
from solution import numIslands, find_num_of_islands_from_input def test_single_island(): m = 4 n = 5 grid_lines = [ "11110", "11010", "11000", "00000" ] assert find_num_of_islands_from_input(m, n, grid_lines) == 1 def test_multiple_islands(): m = 4 n = 5 ...
[ { "docstring": null, "function_declaration": "def numIslands(grid):", "function_name": "numIslands", "parameter_list": "(grid)" }, { "docstring": null, "function_declaration": "def find_num_of_islands_from_input(m, n, grid_lines):", "function_name": "find_num_of_islands_from_input", ...
[ 0, 0, 1 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def numIslands(grid):\n if not grid:\n return 0\n m, n = len(grid), len(grid[0])\n visited = [[False] * n for _ in range(m)]\n\n def dfs(i,...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00034361", "row_id": 34361, "seed_ids": "[7494, 1444, 3053]" }
0.617837
Codeforces_34361
I
[ "numIslands", "find_num_of_islands_from_input" ]
2
[ [ "find_num_of_islands_from_input", "numIslands" ] ]
1
[]
false
[]
false
pytest
true
[]
true
96265d5e754c15f738dbd4f252a10d4fcb5a1159
84a483e8a012db41836a99fba2fe44c1cb350658
v1.0
instruct
Codeforces
Codeforces_34382_I
You are given a string composed of lowercase English letters. Your task is to find the length of the shortest substring that contains all the unique characters present in the given string. The first line of input contains a single integer n (1 ≤ n ≤ 100000), representing the length of the string. The second line of in...
def shortest_substring_with_all_chars(string): unique_chars = set(string) num_unique_chars = len(unique_chars) start = 0 min_len = len(string) + 1 char_count = {} for end in range(len(string)): char_count[string[end]] = char_count.get(string[end], 0) + 1 while ...
from solution import find_shortest_substring_length def test_short_string(): assert find_shortest_substring_length(2, "ab") == 2 def test_no_repeats(): assert find_shortest_substring_length(5, "abcde") == 5 def test_same_char(): assert find_shortest_substring_length(4, "aaaa") == 1 def test_example_case...
[ { "docstring": null, "function_declaration": "def shortest_substring_with_all_chars(string):", "function_name": "shortest_substring_with_all_chars", "parameter_list": "(string)" }, { "docstring": null, "function_declaration": "def find_shortest_substring_length(n, s):", "function_nam...
[ 0, 0, 0, 0, 0, 0, 0, 1 ]
1
hard
0.125
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def length_of_shortest_substring_with_all_unique_chars(s):\n from collections import defaultdict\n \n n = len(s)\n if n == 0:\n return 0\n ...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00034382", "row_id": 34382, "seed_ids": "[3001, 3058, 2700]" }
0.771744
Codeforces_34382
I
[ "shortest_substring_with_all_chars", "find_shortest_substring_length" ]
2
[ [ "find_shortest_substring_length", "shortest_substring_with_all_chars" ] ]
1
[]
false
[]
false
pytest
true
[]
true
d3a0f029a700a7a899665e1b490c7195dd87d3b8
b1f5dfe061526d40dbc467659144c9a0ac3ea51b
v1.0
instruct
Codeforces
Codeforces_34384_I
Sandra is fascinated by prime numbers and decided to create a game where she challenges others to solve a specific prime-related problem. Given an integer \( n \) and a set of queries, each query consists of a pair of integers \( (a, b) \). For each query, determine how many prime numbers are there between \( a \) an...
def sieve(n): """ Implements the Sieve of Eratosthenes to find all prime numbers up to n. """ is_prime = [True] * (n + 1) is_prime[0] = is_prime[1] = False p = 2 while p * p <= n: if is_prime[p]: for i in range(p * p, n + 1, p): is_prime[i] = False ...
from solution import sieve, precompute_prime_count, count_primes_in_range, process_queries def test_sieve(): assert sieve(10) == [False, False, True, True, False, True, False, True, False, False, False] assert sieve(1) == [False, False] def test_precompute_prime_count(): assert precompute_prime_count(10,...
[ { "docstring": "Implements the Sieve of Eratosthenes to find all prime numbers up to n.", "function_declaration": "def sieve(n):", "function_name": "sieve", "parameter_list": "(n)" }, { "docstring": "Precompute the prime count up to each number from 1 to n.", "function_declaration": "def...
[ 0, 0, 0, 1, 0 ]
1
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def sieve_of_eratosthenes(max_num):\n sieve = [True] * (max_num + 1)\n sieve[0] = sieve[1] = False # 0 and 1 are not primes\n for start in range(2, ...
trial_gpt4o_3
{ "original_instruction": "", "prompt_id": "00034384", "row_id": 34384, "seed_ids": "[7800, 7692, 567]" }
0.618676
Codeforces_34384
I
[ "sieve", "precompute_prime_count", "count_primes_in_range", "process_queries" ]
4
[ [ "process_queries", "count_primes_in_range" ], [ "process_queries", "precompute_prime_count" ], [ "process_queries", "sieve" ] ]
3
[ "process_queries" ]
false
[]
false
pytest
true
[]
true
1d468228ebe61fdf444c109cced8a4b77bd23563
8865b5a97f1b050b55a778cb9ba37157ca254e2a
v1.0
instruct
Codeforces
Codeforces_34386_I
You are given an integer matrix $$$M$$$ with dimensions $$$n \times m$$$. Your task is to determine if there exists a submatrix of $$$M$$$ which contains at least one of every number from 1 to $$$k$$$. The first line contains three integers $$$n$$$, $$$m$$$, and $$$k$$$ ($$$1 \le n, m \le 500$$$; $$$1 \le k \le n \cdo...
def contains_all_numbers(M, n, m, k): """ Returns "YES" if there exists a submatrix in M which contains all integers from 1 to k, otherwise returns "NO". """ num_set = set(range(1, k + 1)) numbers_found = set() for i in range(n): for j in range(m): if M[i][j] in num_set:...
def test_case_1(): matrix = [ [3, 4, 5], [1, 2, 3, 4], [2, 5, 6, 1], [3, 4, 2, 1] ] assert solve(matrix) == "YES" def test_case_2(): matrix = [ [3, 4, 6], [1, 2, 3, 4], [2, 5, 6, 1], [3, 4, 2, 1] ] assert solve(matrix) == "YES" de...
[ { "docstring": "Returns \"YES\" if there exists a submatrix in M which contains all integers\nfrom 1 to k, otherwise returns \"NO\".", "function_declaration": "def contains_all_numbers(M, n, m, k):", "function_name": "contains_all_numbers", "parameter_list": "(M, n, m, k)" }, { "docstring": ...
[ 0, 1, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def contains_all_numbers_with_square(nums_set, total_numbers):\n return len(nums_set) == total_numbers\n\ndef check_submatrix(matrix, n, m, k):\n # coll...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00034386", "row_id": 34386, "seed_ids": "[666, 4446, 1490]" }
0.646495
Codeforces_34386
I
[ "contains_all_numbers", "solve" ]
2
[ [ "solve", "contains_all_numbers" ] ]
1
[]
false
[]
false
pytest
false
[]
true
72ff7178eb47dbbcadb1d825373c50a059b1c58c
424f4b3b4720e8a7a3532a15dff5b0cbd979f0ae
v1.0
instruct
Codeforces
Codeforces_34396_I
In a village, each house is connected by a series of roads, and there's exactly one road between any two houses, forming a tree structure. However, recently some roads broke down, and now some of the houses can no longer be reached from others. The villagers need to repair the least number of roads to make the whole vi...
def find_set(parent, u): if parent[u] != u: parent[u] = find_set(parent, parent[u]) return parent[u] def union_sets(parent, rank, u, v): root_u = find_set(parent, u) root_v = find_set(parent, v) if root_u != root_v: if rank[root_u] > rank[root_v]: parent[root_v] = root_...
import pytest from solution import min_roads_to_repair def test_example_case(): assert min_roads_to_repair(5, 2, [(1, 2), (2, 3)]) == 2 def test_no_working_roads(): assert min_roads_to_repair(5, 0, []) == 4 def test_fully_connected(): assert min_roads_to_repair(4, 3, [(1, 2), (2, 3), (3, 4)]) == 0 def t...
[ { "docstring": null, "function_declaration": "def find_set(parent, u):", "function_name": "find_set", "parameter_list": "(parent, u)" }, { "docstring": null, "function_declaration": "def union_sets(parent, rank, u, v):", "function_name": "union_sets", "parameter_list": "(parent, ...
[ 1, 1, 0 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def find_set(parent, u):\n if parent[u] != u:\n parent[u] = find_set(parent, parent[u])\n return parent[u]\n\ndef union_sets(parent, rank, u, v):...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00034396", "row_id": 34396, "seed_ids": "[5360, 4070, 1690]" }
0.688963
Codeforces_34396
I
[ "find_set", "union_sets", "min_roads_to_repair" ]
3
[ [ "min_roads_to_repair", "find_set" ], [ "min_roads_to_repair", "union_sets" ], [ "union_sets", "find_set" ] ]
3
[]
false
[]
false
pytest
true
[]
true
883385e95d2d40d4b32ff21d77576f3e886dcb1d
e39a3bd2479a291e084b0d8d9abd735d49e56aab
v1.0
instruct
Codeforces
Codeforces_34430_I
In a certain fictional city, there are **n** islands connected by **m** bridges. Each bridge connects exactly two different islands and has a certain length. An island **i** is connected to another island **j** if there's a bridge between them. No island is isolated, meaning every island can reach any other island thro...
def dfs(node, visited, adjacency_list): stack = [node] while stack: current = stack.pop() if not visited[current]: visited[current] = True for neighbor in adjacency_list[current]: if not visited[neighbor]: stack.append(neighbor) def mi...
from solution import min_lamps def test_single_bridge(): assert min_lamps(2, 1, [(1, 2)]) == 1 def test_simple_case(): assert min_lamps(5, 5, [(1, 2), (2, 3), (3, 4), (4, 5), (1, 5)]) == 1 def test_cycle_case(): assert min_lamps(4, 4, [(1, 2), (2, 3), (3, 4), (4, 1)]) == 1 def test_two_components(): ...
[ { "docstring": null, "function_declaration": "def dfs(node, visited, adjacency_list):", "function_name": "dfs", "parameter_list": "(node, visited, adjacency_list)" }, { "docstring": null, "function_declaration": "def min_lamps(n, m, bridges):", "function_name": "min_lamps", "para...
[ 0, 0, 0, 0, 0, 0, 0, 1, 0 ]
1
hard
0.111
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def find_minimum_lamps(n, m, bridges):\n from collections import defaultdict\n \n # Create an adjacency list for the graph\n graph = defaultdict(l...
trial_gpt4o_7
{ "original_instruction": "", "prompt_id": "00034430", "row_id": 34430, "seed_ids": "[1549, 3993, 76]" }
0.76299
Codeforces_34430
I
[ "dfs", "min_lamps" ]
2
[ [ "min_lamps", "dfs" ] ]
1
[]
false
[]
false
pytest
true
[]
true
cf64933aef1c09d9a12d3ec167d420d624b50548
4e627f5990c46e1d1b2c681077158be3f11565cd
v1.0
instruct
Codeforces
Codeforces_34442_I
You are given an underground system of interconnected stations represented as a graph. Each station is represented by a unique integer, and each bi-directional connection between the stations is represented by a pair of integers indicating a direct path. A traveler starts their journey at one station and brings with t...
from collections import deque, defaultdict import itertools def bfs_shortest_path(graph, start): """ Find the shortest path from start to all other nodes using BFS. """ distances = {start: 0} queue = deque([start]) while queue: node = queue.popleft() current_distance = dist...
from solution import find_minimum_distance def test_find_minimum_distance(): assert find_minimum_distance(5, 6, 3, [(1, 2), (2, 3), (3, 4), (4, 5), (5, 1), (3, 5)], [1, 5, 4], 1) == 2 assert find_minimum_distance(5, 6, 3, [(1, 2), (2, 3), (3, 4), (4, 5), (5, 1), (3, 5)], [2, 3, 4], 1) == 3 assert find_mini...
[ { "docstring": "Find the shortest path from start to all other nodes using BFS.", "function_declaration": "def bfs_shortest_path(graph, start):", "function_name": "bfs_shortest_path", "parameter_list": "(graph, start)" }, { "docstring": null, "function_declaration": "def find_minimum_dis...
[ 0, 0, 0, 0, 0, 0, 0, 0, 1, 1 ]
2
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "import heapq\n\ndef min_distance_to_visit_stations(n, m, k, connections, desired_stations, start_station):\n # Create adjacency list for the graph\n gra...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00034442", "row_id": 34442, "seed_ids": "[7075, 1422, 5967]" }
0.721698
Codeforces_34442
I
[ "bfs_shortest_path", "find_minimum_distance" ]
2
[ [ "find_minimum_distance", "bfs_shortest_path" ] ]
1
[]
false
[]
false
pytest
true
[]
true
76754f24a50fe7f74fcfa0234d0461e5b2e726bd
b777d063140c4c2f1e9e60116128e8f0f6625be5
v1.0
instruct
Codeforces
Codeforces_34473_I
Alice has recently taken a keen interest in sorting algorithms and their efficiencies. One day, while playing with her deck of uniquely numbered cards, she decided to sort them using a custom algorithm. Unfortunately, she got distracted and ended up with a shuffled deck again. Now, she has a shuffled sequence of cards ...
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 minimum_adjacent_swaps_to_sort def test_case_1(): assert minimum_adjacent_swaps_to_sort(5, [5, 4, 3, 2, 1]) == 10 def test_case_2(): assert minimum_adjacent_swaps_to_sort(5, [2, 3, 4, 5, 1]) == 4 def test_case_3(): assert minimum_adjacent_swaps_to_sort(5, [1, 2, 3, 4, 5]) == 0 d...
[ { "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, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def merge_and_count(arr, temp_arr, left, mid, right):\n i = left # Starting index for left subarray\n j = mid + 1 # Starting index for right subarray...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00034473", "row_id": 34473, "seed_ids": "[408, 6848, 2566]" }
0.692909
Codeforces_34473
I
[ "merge_and_count", "merge_sort_and_count", "minimum_adjacent_swaps_to_sort" ]
3
[ [ "merge_sort_and_count", "merge_and_count" ], [ "minimum_adjacent_swaps_to_sort", "merge_sort_and_count" ] ]
2
[]
false
[]
false
pytest
true
[]
true
374e36ea95bc593d5bc48f858d52c068d24e5e82
4dae2f7de2fb5ad32056331a910051c97141be26
v1.0
instruct
Codeforces
Codeforces_34502_I
Alex has recently become interested in number theory, particularly in the concept of prime numbers. He came up with a new problem: for a given integer $$$n$$$, he wants to determine if it can be expressed as the sum of exactly three distinct prime numbers. He decides to write a program to help him figure this out. The...
def is_prime(n): if n <= 1: return False if n <= 3: return True if n % 2 == 0 or n % 3 == 0: return False i = 5 while i * i <= n: if n % i == 0 or n % (i + 2) == 0: return False i += 6 return True def find_three_primes_sum(n): primes = [i ...
def test_primes_sum_three(): # Testing with a known case that cannot be expressed as the sum of three distinct primes assert primes_sum_three(11) == "NO" # Testing with a known case that can be expressed as the sum of three distinct primes result = primes_sum_three(30) assert result.startswith(...
[ { "docstring": null, "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": null, "function_declaration": "def find_three_primes_sum(n):", "function_name": "find_three_primes_sum", "parameter_list": "(n)" }, { "d...
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(num):\n if num < 2:\n return False\n if num in (2, 3):\n return True\n if num % 2 == 0 or num % 3 == 0:\n return Fa...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00034502", "row_id": 34502, "seed_ids": "[4603, 7958, 7527]" }
0.629941
Codeforces_34502
I
[ "is_prime", "find_three_primes_sum", "primes_sum_three" ]
3
[ [ "find_three_primes_sum", "is_prime" ], [ "primes_sum_three", "find_three_primes_sum" ] ]
2
[]
false
[]
false
pytest
false
[]
true
fd3651da3213814be02402bb3e42d649ebff37c8
2d4a5c37803437be5c6a02e5cef19b40329a8329
v1.0
instruct
Codeforces
Codeforces_34513_I
You've been hired to help a software development team optimize their data storage system. The storage system has a specific limitation: it can only store data blocks if the block size is a prime number. Given an integer `n`, you are tasked with determining the smallest number of prime-sized blocks that can be used to s...
def sieve_of_eratosthenes(max_num): """ Returns a list of primes up to max_num (inclusive) using the Sieve of Eratosthenes algorithm. """ is_prime = [True] * (max_num + 1) is_prime[0] = is_prime[1] = False for start in range(2, int(max_num**0.5) + 1): if is_prime[start]: for i in ra...
from solution import min_prime_blocks def test_min_prime_blocks(): assert min_prime_blocks(1) == 1 assert min_prime_blocks(2) == 1 assert min_prime_blocks(3) == 1 assert min_prime_blocks(4) == 2 assert min_prime_blocks(5) == 1 assert min_prime_blocks(6) == 2 assert min_prime_blocks(10) == 2...
[ { "docstring": "Returns a list of primes up to max_num (inclusive) using the Sieve of Eratosthenes algorithm. ", "function_declaration": "def sieve_of_eratosthenes(max_num):", "function_name": "sieve_of_eratosthenes", "parameter_list": "(max_num)" }, { "docstring": "Returns the minimum numbe...
[ 0, 0, 1 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(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_2
{ "original_instruction": "", "prompt_id": "00034513", "row_id": 34513, "seed_ids": "[1880, 2588, 2312]" }
0.654497
Codeforces_34513
I
[ "sieve_of_eratosthenes", "min_prime_blocks" ]
2
[ [ "min_prime_blocks", "sieve_of_eratosthenes" ] ]
1
[]
false
[]
false
pytest
true
[]
true
505015c1b754723ea77ce6fc35209474fc7f7d09
f3cef69a4d2ffca9b568e772761abc8a93ea00f2
v1.0
instruct
Codeforces
Codeforces_34535_I
You are working in a factory that produces metal rods. Each rod is characterized by its length in meters, and you need to group the rods into bundles. To ensure stability during transportation, each bundle must contain rods with the same length. Your task is to calculate the minimum number of bundles needed to group a...
def min_bundles(test_cases): results = [] for lengths in test_cases: unique_lengths = set(lengths) results.append(len(unique_lengths)) return results # Helper function to parse input def parse_input(input_str): lines = input_str.strip().split("\n") t = int(lines[0]) test_cases ...
import pytest from solution import solve, parse_input, min_bundles def test_parse_input(): input_str = "2\n5\n1 2 2 3 1\n4\n4 4 4 4" expected_output = [ [1, 2, 2, 3, 1], [4, 4, 4, 4] ] assert parse_input(input_str) == expected_output def test_min_bundles(): test_cases = [ [...
[ { "docstring": null, "function_declaration": "def min_bundles(test_cases):", "function_name": "min_bundles", "parameter_list": "(test_cases)" }, { "docstring": null, "function_declaration": "def parse_input(input_str):", "function_name": "parse_input", "parameter_list": "(input_s...
[ 0, 1, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def min_bundles(t, test_cases):\n \"\"\"\n Returns the minimum number of bundles needed to group rods with the same length for each test case.\n \n ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00034535", "row_id": 34535, "seed_ids": "[3836, 5003, 122]" }
0.632655
Codeforces_34535
I
[ "min_bundles", "parse_input", "solve" ]
3
[ [ "solve", "min_bundles" ], [ "solve", "parse_input" ] ]
2
[ "parse_input" ]
false
[]
false
pytest
true
[]
true
77c6a7e30ee19f7aa5e6d1a1104c7d57c7cffaf7
20724766ff4589aa0be24c8ed073fdc9985b1271
v1.0
instruct
Codeforces
Codeforces_34568_I
You are working on a letter sorting system for a post office. The system receives a list of letter addresses, each represented by a string. Your task is to sort these addresses in lexicographical order, but with a twist: the address strings might contain numeric characters which should be sorted based on their numeric ...
import re def sort_addresses(test_cases): def extract_number(s): match = re.search(r'\d+', s) return int(match.group()) if match else float('inf') results = [] for n, addresses in test_cases: sorted_addresses = sorted(addresses, key=lambda addr: (extract_number(addr), addr)) ...
from solution import get_sorted_addresses, format_result def test_single_case(): input_text = "1\n3\napple123\nbanana45\ncherry78" expected_output = "banana45\ncherry78\napple123" results = get_sorted_addresses(input_text) assert format_result(results) == expected_output def test_multiple_cases(): ...
[ { "docstring": null, "function_declaration": "def sort_addresses(test_cases):", "function_name": "sort_addresses", "parameter_list": "(test_cases)" }, { "docstring": null, "function_declaration": "def get_sorted_addresses(input_text):", "function_name": "get_sorted_addresses", "p...
[ 1, 1, 0 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "import re\n\ndef extract_number(s):\n \"\"\"\n Extract the first number found in the string s. If no number is found, return None.\n \"\"\"\n matc...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00034568", "row_id": 34568, "seed_ids": "[7666, 15, 2221]" }
0.6715
Codeforces_34568
I
[ "sort_addresses", "get_sorted_addresses", "format_result" ]
3
[ [ "get_sorted_addresses", "sort_addresses" ] ]
1
[ "format_result" ]
false
[]
false
pytest
true
[]
true
7a685a80859a61d2fbd97985c389f8a1d36efa78
695ead011f1ecb52f0bd2beda528d9a14c176330
v1.0
instruct
Codeforces
Codeforces_34573_I
In a certain land, there is a kingdom ruled by King Geoffrey. The kingdom is divided into n territories connected by m bidirectional roads. Each road connects exactly two different territories. Unfortunately, due to the rise of bandits, each road has a certain risk factor associated with traveling through it. King Ge...
def kruskal_minimum_risk(n, roads): """ Kruskal's algorithm to find the minimum spanning tree's total risk factor. """ # Sort the roads by their risk factor (weight) roads.sort(key=lambda x: x[2]) # Helper function to find the parent of a node with path compression def find(parent, i): ...
def test_kruskal_minimum_risk(): # Example test case from the problem statement n = 4 m = 5 roads = [ [1, 2, 3], [1, 3, 1], [2, 3, 3], [2, 4, 6], [3, 4, 5] ] assert minimum_total_risk(n, m, roads) == 9 # Test case with only two territories and one roa...
[ { "docstring": "Kruskal's algorithm to find the minimum spanning tree's total risk factor.", "function_declaration": "def kruskal_minimum_risk(n, roads):", "function_name": "kruskal_minimum_risk", "parameter_list": "(n, roads)" }, { "docstring": null, "function_declaration": "def minimum...
[ 0, 0, 1 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def find(parent, i):\n if parent[i] == i:\n return i\n return find(parent, parent[i])\n\ndef union(parent, rank, x, y):\n root_x = find(parent...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00034573", "row_id": 34573, "seed_ids": "[5225, 880, 4131]" }
0.647917
Codeforces_34573
I
[ "kruskal_minimum_risk", "minimum_total_risk" ]
2
[ [ "minimum_total_risk", "kruskal_minimum_risk" ] ]
1
[]
false
[]
false
pytest
false
[]
true
b245673ceb7d7f8b0114790b780d53e16e6ad36e
f173ae79d90e11ca8807e8defc1dff4b457a940c
v1.0
instruct
Codeforces
Codeforces_34588_I
Given a grid of size \( n \times n \), you have to perform \( q \) queries. Each query is described as two integers \( rc \) and \( c \), where \( rc \) can be either 1 or 2, and \( c \) is an integer from 1 to \( n \). - If \( rc \) is 1, it indicates a row \( c \). You have to reverse the elements of this row. - If...
def reverse_row(grid, row_idx): grid[row_idx] = grid[row_idx][::-1] def reverse_column(grid, col_idx): n = len(grid) for i in range(n // 2): grid[i][col_idx], grid[n-i-1][col_idx] = grid[n-i-1][col_idx], grid[i][col_idx] def perform_operations(n, queries): # Initialize the grid with all zeros ...
from solution import perform_operations def test_example_case(): n = 3 q = 4 queries = [(1, 2), (2, 3), (1, 2), (2, 3)] result = perform_operations(n, queries) expected = [ [0, 0, 0], [0, 0, 0], [0, 0, 0] ] assert result == expected def test_single_row_reverse(): ...
[ { "docstring": null, "function_declaration": "def reverse_row(grid, row_idx):", "function_name": "reverse_row", "parameter_list": "(grid, row_idx)" }, { "docstring": null, "function_declaration": "def reverse_column(grid, col_idx):", "function_name": "reverse_column", "parameter_...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def process_grid(n, q, queries):\n grid = [[0 for _ in range(n)] for _ in range(n)]\n \n for rc, c in queries:\n c -= 1 # Convert to 0-based ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00034588", "row_id": 34588, "seed_ids": "[1704, 7814, 2734]" }
0.702607
Codeforces_34588
I
[ "reverse_row", "reverse_column", "perform_operations" ]
3
[ [ "perform_operations", "reverse_column" ], [ "perform_operations", "reverse_row" ] ]
2
[]
false
[]
false
pytest
true
[]
true
4327f0f7fe43d8c29ecdda3e7baf7974f8369bf8
00f33689c042cd34d8a36d59d0a0bfa84c19a9d7
v1.0
instruct
Codeforces
Codeforces_34604_I
In a distant kingdom, there's a peculiar road network connecting its many cities. Each city has a bidirectional road to every other city. However, the cost to build and maintain these roads varies depending on the pair of cities. The kingdom's ruler has decided to construct a minimal-cost network that still allows trav...
def find_mst_cost(n, cost_matrix): def find(parent, i): if parent[i] == i: return i else: return find(parent, parent[i]) def union(parent, rank, x, y): root_x = find(parent, x) root_y = find(parent, y) if root_x != root_y: if rank[root...
def test_minimal_total_cost_example(): n = 3 cost_matrix = [ [0, 1, 3], [1, 0, 2], [3, 2, 0] ] assert minimal_total_cost(n, cost_matrix) == 3 def test_minimal_total_cost_all_equal(): n = 4 cost_matrix = [ [0, 1, 1, 1], [1, 0, 1, 1], [1, 1, 0, 1], ...
[ { "docstring": null, "function_declaration": "def find_mst_cost(n, cost_matrix):", "function_name": "find_mst_cost", "parameter_list": "(n, cost_matrix)" }, { "docstring": null, "function_declaration": "def minimal_total_cost(n, cost_matrix):", "function_name": "minimal_total_cost", ...
[ 1, 0, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def find_mst_cost(n, cost_matrix):\n def find(parent, i):\n if parent[i] == i:\n return i\n else:\n return find(parent,...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00034604", "row_id": 34604, "seed_ids": "[6144, 3431, 5518]" }
0.775759
Codeforces_34604
I
[ "find_mst_cost", "minimal_total_cost" ]
2
[ [ "minimal_total_cost", "find_mst_cost" ] ]
1
[]
false
[]
false
pytest
false
[]
true
1a7ea1eb74deea346d21e587397d95c7af835e1b
40d0991ffd243ff54c958756b9005b4bb0b79924
v1.0
instruct
Codeforces
Codeforces_34613_I
Petra is fascinated by geometric patterns and has been playing around with various grid-based games. Recently, she came up with a new game on a grid and would like to challenge you with the following problem: You are given a 2D grid of size $$$N \times M$$$, initially filled with zeros. Petra will provide you with a l...
def update_grid(N, M, commands): """ Updates the grid of size N x M according to the given commands and returns the final grid. Parameters: N (int): number of rows in the grid M (int): number of columns in the grid commands (list of tuples): list of commands, each represented as (r1, c1, r2...
from solution import process_input_and_update_grid def test_single_command(): N, M, K = 3, 4, 1 commands = [(1, 1, 2, 2)] expected_output = [ [1, 1, 0, 0], [1, 1, 0, 0], [0, 0, 0, 0] ] assert process_input_and_update_grid(N, M, K, commands) == expected_output def test_multi...
[ { "docstring": "Updates the grid of size N x M according to the given commands and returns the final grid.\n\nParameters:\nN (int): number of rows in the grid\nM (int): number of columns in the grid\ncommands (list of tuples): list of commands, each represented as (r1, c1, r2, c2)\n\nReturns:\nList[List[int]]: ...
[ 1, 1, 0 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def apply_commands_to_grid(N, M, K, commands):\n \"\"\"\n Apply a list of increment commands to a grid of size N x M.\n\n Parameters:\n N (int): N...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00034613", "row_id": 34613, "seed_ids": "[7836, 6398, 4534]" }
0.628785
Codeforces_34613
I
[ "update_grid", "process_input_and_update_grid" ]
2
[ [ "process_input_and_update_grid", "update_grid" ] ]
1
[]
false
[]
false
pytest
true
[]
true
1c571bca36403f060c9009db20ddf1399cf43798
e4a9099e93f2bc97220d5b7a76cd1e95e51abc89
v1.0
instruct
Codeforces
Codeforces_34667_I
You are given a string of parentheses. A string of parentheses is valid if: 1) Open brackets are closed by the same type of brackets. 2) Open brackets are closed in the correct order. In this problem, we only have the types of brackets '(' and ')'. You are given a string s containing only characters '(' and ')'. You n...
def validate_parentheses(t, test_cases): results = [] for s in test_cases: if is_valid(s): results.append("YES") elif can_be_made_valid_by_removing_one(s): results.append("YES") else: results.append("NO") return results def is_valid(s): balanc...
from solution import validate_parentheses, run_validate_parentheses def test_validate_parentheses(): t = 5 test_cases = ["()", "(())", "())", "))((", "(()(("] expected = ["YES", "YES", "YES", "NO", "NO"] result = validate_parentheses(t, test_cases) assert result == expected def test_validate_paren...
[ { "docstring": null, "function_declaration": "def validate_parentheses(t, test_cases):", "function_name": "validate_parentheses", "parameter_list": "(t, test_cases)" }, { "docstring": null, "function_declaration": "def is_valid(s):", "function_name": "is_valid", "parameter_list":...
[ 0, 0, 0, 0, 0, 1, 0, 0, 1, 0 ]
2
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def validate_parentheses(s):\n \"\"\"\n Returns \"YES\" if the string s can be made valid by removing at most one character,\n otherwise returns \"NO...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00034667", "row_id": 34667, "seed_ids": "[5466, 6889, 4750]" }
0.838207
Codeforces_34667
I
[ "validate_parentheses", "is_valid", "can_be_made_valid_by_removing_one", "run_validate_parentheses" ]
4
[ [ "can_be_made_valid_by_removing_one", "is_valid" ], [ "run_validate_parentheses", "validate_parentheses" ], [ "validate_parentheses", "can_be_made_valid_by_removing_one" ], [ "validate_parentheses", "is_valid" ] ]
4
[]
false
[]
false
pytest
true
[]
true
663ee9a5497e1caa0b3ed016cd0a8cf73e72cf36
62bd828003e6cdacdad1689d047dd07b7c62307e
v1.0
instruct
Codeforces
Codeforces_34721_I
Andrei loves playing with graphs. He has an undirected weighted graph with n vertices and m edges. Each edge has a positive integer weight. He wants to find the length of the shortest path between two given nodes a and b. Each line contains four integers: n (2 ≤ n ≤ 1000) — the number of vertices, m (1 ≤ m ≤ 10000) — ...
import heapq def dijkstra(n, edges, a, b): graph = [[] for _ in range(n + 1)] for u, v, w in edges: graph[u].append((v, w)) graph[v].append((u, w)) pq = [(0, a)] distances = {i: float('inf') for i in range(1, n + 1)} distances[a] = 0 while pq: current_dist...
from solution import find_shortest_path def test_example_case(): n = 5 m = 6 a, b = 1, 5 edges = [(1, 2, 2), (2, 3, 3), (3, 4, 1), (4, 5, 2), (2, 5, 6), (1, 5, 10)] assert find_shortest_path(n, m, a, b, edges) == 8 def test_disconnected_graph(): n = 4 m = 2 a, b = 1, 4 edges = [(1,...
[ { "docstring": null, "function_declaration": "def dijkstra(n, edges, a, b):", "function_name": "dijkstra", "parameter_list": "(n, edges, a, b)" }, { "docstring": null, "function_declaration": "def find_shortest_path(n, m, a, b, edges):", "function_name": "find_shortest_path", "pa...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "import heapq\nimport sys\n\ndef shortest_path(n, m, a, b, edges):\n graph = {i: [] for i in range(1, n+1)}\n for u, v, w in edges:\n graph[u].app...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00034721", "row_id": 34721, "seed_ids": "[3996, 3126, 6211]" }
0.795127
Codeforces_34721
I
[ "dijkstra", "find_shortest_path" ]
2
[ [ "find_shortest_path", "dijkstra" ] ]
1
[]
false
[]
false
pytest
true
[]
true
c4da48467fed0fee7d4b68fd9416339fcd6d5dd8
6911a0b104b6360d3852c5a1f0328416fd951f55
v1.0
instruct
Codeforces
Codeforces_34729_I
You are given a connected, undirected graph with `n` vertices and `m` edges. Each edge has an integer weight associated with it. Your task is to remove some of the edges to form a Minimum Spanning Tree (MST) of the graph. However, there is a special requirement: the weight of an edge you remove can change depending on ...
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): root_x = find(parent, x) root_y = find(parent, y) if root_x != root_y: if rank[root_x] > rank[root_y]: parent[root_y] = root_x ...
def test_minimum_spanning_tree(): edges_1 = [ (0, 1, 5), (0, 2, 10), (0, 3, 3), (1, 2, 6), (2, 3, 7) ] assert minimum_spanning_tree(4, edges_1, 2) == 14 # Using initial weights for MST edges edges_2 = [ (0, 1, 4), (0, 2, 9), (0, 3, 15), ...
[ { "docstring": null, "function_declaration": "def find(parent, i):", "function_name": "find", "parameter_list": "(parent, i)" }, { "docstring": null, "function_declaration": "def union(parent, rank, x, y):", "function_name": "union", "parameter_list": "(parent, rank, x, y)" }, ...
[ 0, 0, 0, 0, 0, 0, 0, 0, 1 ]
1
hard
0.111
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def find(parent, i):\n if parent[i] == i:\n return i\n return find(parent, parent[i])\n\ndef union(parent, rank, x, y):\n xroot = find(parent,...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00034729", "row_id": 34729, "seed_ids": "[2627, 3838, 2784]" }
0.817804
Codeforces_34729
I
[ "find", "union", "minimum_spanning_tree" ]
3
[ [ "minimum_spanning_tree", "find" ], [ "minimum_spanning_tree", "union" ], [ "union", "find" ] ]
3
[]
false
[]
false
pytest
false
[]
true
f2d94e901f8c8833f202c7106731e4445499f074
5ca7fc8fa31d5f289d6567ddd69ba50dd7effd72
v1.0
instruct
Codeforces
Codeforces_34776_I
Eve works as a delivery robot in a huge warehouse with an enormous grid of cells having `n` rows and `m` columns, where each cell can either be open or contain an obstacle. Each cell can be represented by a pair of coordinates `(i, j)`. Eve can move up, down, left, or right to an adjacent open cell in unit time. It is...
from collections import deque def bfs_shortest_path(grid, start, end): n, m = len(grid), len(grid[0]) directions = [(-1, 0), (1, 0), (0, -1), (0, 1)] start = (start[0] - 1, start[1] - 1) end = (end[0] - 1, end[1] - 1) if grid[start[0]][start[1]] == 1 or grid[end[0]][end[1]] == 1: retur...
import pytest from solution import bfs_shortest_path, delivery_requests def test_shortest_path(): grid = [ [0, 0, 0, 1], [1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 0, 0] ] assert bfs_shortest_path(grid, (1, 1), (4, 4)) == 6 assert bfs_shortest_path(grid, (1, 1), (4, 3)) == 5 ...
[ { "docstring": null, "function_declaration": "def bfs_shortest_path(grid, start, end):", "function_name": "bfs_shortest_path", "parameter_list": "(grid, start, end)" }, { "docstring": null, "function_declaration": "def delivery_requests(grid, requests):", "function_name": "delivery_r...
[ 0, 1, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "from collections import deque\n\ndef bfs(grid, start, end, n, m):\n if start == end:\n return 0\n \n q = deque([start])\n visited = set()\n...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00034776", "row_id": 34776, "seed_ids": "[6771, 2245, 2990]" }
0.674138
Codeforces_34776
I
[ "bfs_shortest_path", "delivery_requests" ]
2
[ [ "delivery_requests", "bfs_shortest_path" ] ]
1
[]
false
[]
false
pytest
true
[]
true
06f2af55fb0e843fa3614dfa397b672d1a005aef
26df8ac1a3fa7b30403a33e29fbad96517be8fe8
v1.0
instruct
Codeforces
Codeforces_34839_I
You are developing a flight scheduling program for an airline company. There are n direct flights available, each connecting two different cities. The company wants to schedule additional direct flights such that there are no cities left isolated. A city is considered isolated if it cannot be reached, directly or indir...
from collections import defaultdict def dfs(node, visited, adj_list): stack = [node] while stack: current = stack.pop() for neighbor in adj_list[current]: if neighbor not in visited: visited.add(neighbor) stack.append(neighbor) def count_isolated_gro...
from solution import minimum_additional_flights def test_minimum_with_isolated(): assert minimum_additional_flights([ (6, 4, [(1, 2), (2, 3), (4, 5), (5, 6)]) ]) == [1] def test_minimum_with_connected(): assert minimum_additional_flights([ (5, 5, [(1, 2), (2, 3), (3, 4), (4, 5), (5, 1)]) ...
[ { "docstring": null, "function_declaration": "def dfs(node, visited, adj_list):", "function_name": "dfs", "parameter_list": "(node, visited, adj_list)" }, { "docstring": null, "function_declaration": "def count_isolated_groups(n, edges):", "function_name": "count_isolated_groups", ...
[ 0, 1, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def min_additional_flights(test_cases):\n \"\"\"\n Returns the minimum number of additional flights required to ensure no city is left isolated.\n \"...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00034839", "row_id": 34839, "seed_ids": "[7348, 1447, 789]" }
0.709942
Codeforces_34839
I
[ "dfs", "count_isolated_groups", "minimum_additional_flights" ]
3
[ [ "count_isolated_groups", "dfs" ], [ "minimum_additional_flights", "count_isolated_groups" ] ]
2
[]
false
[]
false
pytest
true
[]
true
e47d20c222659530f58c2e64f10b766c176c88c6
d99d059ab3cb92705115a3716f785be1ed516fbf
v1.0
instruct
Codeforces
Codeforces_34887_I
You are given a list of integers and a maximum allowable total sum. Your task is to split the list into the minimum number of sublists such that the sum of the integers in each sublist does not exceed the given maximum allowable total sum. The input consists of: - The first line contains two integers n and S (1 ≤ n ≤ ...
def split_into_sublists(n, S, integers): result = [] current_sublist = [] current_sum = 0 for num in integers: if current_sum + num > S: result.append(current_sublist) current_sublist = [num] current_sum = num else: current_sublist.app...
from solution import split_into_sublists, number_of_sublists def test_split_into_sublists(): assert split_into_sublists(6, 10, [2, 7, 1, 4, 3, 8]) == [[2, 7, 1], [4, 3], [8]] assert split_into_sublists(6, 5, [2, 7, 1, 4, 3, 8]) == [[2], [7], [1, 4], [3], [8]] assert split_into_sublists(1, 1, [1]) == [[1]] ...
[ { "docstring": null, "function_declaration": "def split_into_sublists(n, S, integers):", "function_name": "split_into_sublists", "parameter_list": "(n, S, integers)" }, { "docstring": null, "function_declaration": "def number_of_sublists(n, S, integers):", "function_name": "number_of...
[ 1, 1, 0 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def split_list(n, S, nums):\n \"\"\"\n Splits the list into the minimum number of sublists such that the sum of the \n integers in each sublist does ...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00034887", "row_id": 34887, "seed_ids": "[5242, 5432, 7188]" }
0.696832
Codeforces_34887
I
[ "split_into_sublists", "number_of_sublists" ]
2
[ [ "number_of_sublists", "split_into_sublists" ] ]
1
[]
false
[]
false
pytest
true
[]
true
24e78550be540aa80ca84a1465b24b184d1c1f7c
205097cdd1727ce8e6c18707c8e2705f99200f6d
v1.0
instruct
Codeforces
Codeforces_34966_I
Alex is planning a road trip between several cities and wants to minimize the total travel time. The travel time between any two cities is known, and Alex can choose any city as the starting point for the trip and must visit each city exactly once before returning to the starting city. This problem can be approached a...
def tsp(mask, pos, n, dist, dp): if mask == (1 << n) - 1: return dist[pos][0] if dp[mask][pos] != -1: return dp[mask][pos] ans = float('inf') for city in range(n): if (mask & (1 << city)) == 0: new_ans = dist[pos][city] + tsp(mask | (1 << city), city,...
from solution import min_travel_time def test_example_case(): n = 4 matrix = [ [0, 10, 15, 20], [10, 0, 35, 25], [15, 35, 0, 30], [20, 25, 30, 0] ] assert min_travel_time(n, matrix) == 80 def test_small_case(): n = 2 matrix = [ [0, 1], [1, 0] ...
[ { "docstring": null, "function_declaration": "def tsp(mask, pos, n, dist, dp):", "function_name": "tsp", "parameter_list": "(mask, pos, n, dist, dp)" }, { "docstring": null, "function_declaration": "def min_travel_time(n, matrix):", "function_name": "min_travel_time", "parameter_...
[ 0, 0, 0, 0, 1 ]
1
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "from itertools import permutations\n\ndef tsp(n, graph):\n \"\"\"\n Solves the Traveling Salesman Problem.\n \n Parameters:\n n (int): Number o...
trial_gpt4o_4
{ "original_instruction": "", "prompt_id": "00034966", "row_id": 34966, "seed_ids": "[6600, 3900, 4683]" }
0.764797
Codeforces_34966
I
[ "tsp", "min_travel_time", "main" ]
3
[ [ "min_travel_time", "tsp" ] ]
1
[]
false
[]
false
pytest
true
[]
true
6cbbc584f6dfbefaa1e4a3fd54b3ffc378bf5f62
51a3e0135e63c587eb81814fbeb61073d5dcf49b
v1.0
instruct
Codeforces
Codeforces_34972_I
You are given a string consisting of lowercase Latin letters. You can remove any one character from it. Your task is to determine if it is possible to make the string a palindrome by removing exactly one character. A palindrome is a string that reads the same forward and backward. The first line contains a single in...
def can_be_palindrome_by_removing_one_char(s): def is_palindrome(x): return x == x[::-1] l, r = 0, len(s) - 1 while l < r: if s[l] != s[r]: return is_palindrome(s[l+1:r+1]) or is_palindrome(s[l:r]) l += 1 r -= 1 return True def check_palindromes(t, strings):...
from solution import check_palindromes def test_example_cases(): assert check_palindromes(3, ["abca", "abc", "a"]) == ["YES", "NO", "YES"] def test_single_character(): assert check_palindromes(2, ["a", "b"]) == ["YES", "YES"] def test_complete_palindrome(): assert check_palindromes(1, ["racecar"]) == ["Y...
[ { "docstring": null, "function_declaration": "def can_be_palindrome_by_removing_one_char(s):", "function_name": "can_be_palindrome_by_removing_one_char", "parameter_list": "(s)" }, { "docstring": null, "function_declaration": "def check_palindromes(t, strings):", "function_name": "ch...
[ 0, 0, 0, 1, 0 ]
1
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def can_form_palindrome_by_removing_one_char(s):\n def is_palindrome_range(i, j):\n while i < j:\n if s[i] != s[j]:\n retu...
trial_gpt4o_3
{ "original_instruction": "", "prompt_id": "00034972", "row_id": 34972, "seed_ids": "[419, 552, 2861]" }
0.851543
Codeforces_34972
I
[ "can_be_palindrome_by_removing_one_char", "check_palindromes", "main" ]
3
[ [ "check_palindromes", "can_be_palindrome_by_removing_one_char" ] ]
1
[]
false
[]
false
pytest
true
[]
true
73f251ebd88d757f5fbd943ce6395e3c40408be3
23ff4f25e8930e7df69b81057c1cb606d9765c35
v1.0
instruct
Codeforces
Codeforces_34985_I
You are given an undirected tree of n nodes and n-1 edges, where each node is numbered from 1 to n. Each edge has a weight. You are also given q queries. In each query, you are given two nodes u and v, and you need to determine the maximum weighted edge on the unique path between u and v in the tree. The first line co...
from collections import defaultdict, deque def preprocess_tree(n, edges): """ Preprocess the tree to find the parent, and the maximum weight edge to reach each node """ tree = defaultdict(list) for u, v, w in edges: tree[u].append((v, w)) tree[v].append((u, w)) parent =...
def test_example(): n = 5 q = 3 edges = [ (1, 2, 3), (2, 3, 4), (2, 4, 5), (4, 5, 1) ] queries = [ (2, 5), (1, 3), (3, 4) ] expected_output = [5, 4, 5] assert solve(n, q, edges, queries) == expected_output def test_chain_tree(): ...
[ { "docstring": "Preprocess the tree to find the parent, and the maximum weight edge to reach each node", "function_declaration": "def preprocess_tree(n, edges):", "function_name": "preprocess_tree", "parameter_list": "(n, edges)" }, { "docstring": null, "function_declaration": "def find_...
[ 0, 0, 0, 1, 1 ]
2
medium
0.4
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "from collections import defaultdict, deque\n\ndef preprocess_tree(edges, n):\n \"\"\"\n Constructs the adjacency list of the tree and preprocesses the r...
trial_gpt4o_4
{ "original_instruction": "", "prompt_id": "00034985", "row_id": 34985, "seed_ids": "[789, 1088, 547]" }
0.738971
Codeforces_34985
I
[ "preprocess_tree", "find_max_edge_endpoint", "solve" ]
3
[ [ "solve", "find_max_edge_endpoint" ], [ "solve", "preprocess_tree" ] ]
2
[]
false
[]
false
pytest
false
[]
true
a3444d12a1c4036db6361e4e8fe38bdafc29bb66
c803e117192339e26d30356a9a257e68b69bd31d
v1.0
instruct
Codeforces
Codeforces_35119_I
In a faraway kingdom, there exist p castles connected by q roads. Each road connects two different castles, allowing travel in both directions. However, the kingdom's transportation system is unique. Each road has a toll associated with it – some roads are free (toll of zero) while others cost a certain number of gold ...
def floyd_warshall(p, q, roads): INF = float('inf') dist = [[INF] * p for _ in range(p)] for i in range(p): dist[i][i] = 0 for a, b, c in roads: dist[a-1][b-1] = c dist[b-1][a-1] = c for k in range(p): for i in range(p): for j in range(p): ...
from solution import find_minimum_travel_expenses def test_example_case(): input_data = "4 5\n1 2 1\n2 3 2\n3 4 1\n4 1 2\n1 3 1\n" expected_output = [ [0, 1, 1, 2], [1, 0, 2, 3], [1, 2, 0, 1], [2, 3, 1, 0], ] assert find_minimum_travel_expenses(input_data) == expected_ou...
[ { "docstring": null, "function_declaration": "def floyd_warshall(p, q, roads):", "function_name": "floyd_warshall", "parameter_list": "(p, q, roads)" }, { "docstring": null, "function_declaration": "def parse_input(input_data):", "function_name": "parse_input", "parameter_list": ...
[ 0, 0, 1 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def floyd_warshall(p, q, roads):\n # Initialize distances\n dist = [[float('inf')] * p for _ in range(p)]\n \n for i in range(p):\n dist[i]...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00035119", "row_id": 35119, "seed_ids": "[4709, 7709, 1688]" }
0.672827
Codeforces_35119
I
[ "floyd_warshall", "parse_input", "find_minimum_travel_expenses" ]
3
[ [ "find_minimum_travel_expenses", "floyd_warshall" ], [ "find_minimum_travel_expenses", "parse_input" ] ]
2
[ "parse_input" ]
false
[]
false
pytest
true
[]
true
0c127a0bdcc75f30a946d763c3a2ed0b01cf6152
7c781e7948795c48e62d617a02174c3930842148
v1.0
instruct
Codeforces
Codeforces_35147_I
In a small town, there is an advanced surveillance system installed to monitor all residents. The system performs two main tasks: adding a new camera and processing requests to detect the number of cameras currently covering a given location. Each camera has a fixed range that it covers along the main street, which ca...
def add_camera(cameras, a, b): cameras.append((a, b)) def count_cameras(cameras, x): count = 0 for a, b in cameras: if a <= x <= b: count += 1 return count def process_camera_queries(n, q, cameras_data, queries): cameras = [] for a, b in cameras_data: add_camera(cam...
def test_process_camera_queries(): n = 4 q = 3 cameras_data = [(1, 5), (2, 6), (8, 10), (3, 4)] queries = [4, 7, 9] expected_output = [3, 0, 1] assert process_camera_queries(n, q, cameras_data, queries) == expected_output def test_process_camera_queries_single_camera(): n = 1 q = 2 ...
[ { "docstring": null, "function_declaration": "def add_camera(cameras, a, b):", "function_name": "add_camera", "parameter_list": "(cameras, a, b)" }, { "docstring": null, "function_declaration": "def count_cameras(cameras, x):", "function_name": "count_cameras", "parameter_list": ...
[ 1, 1, 0 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "from bisect import bisect_left, bisect_right\n\ndef process_queries(n, q, camera_ranges, queries):\n starts = sorted([start for start, end in camera_ranges...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00035147", "row_id": 35147, "seed_ids": "[3450, 1509, 5566]" }
0.653868
Codeforces_35147
I
[ "add_camera", "count_cameras", "process_camera_queries" ]
3
[ [ "process_camera_queries", "add_camera" ], [ "process_camera_queries", "count_cameras" ] ]
2
[]
false
[]
false
pytest
false
[]
true
aa008c49d2e2a1fdf83ff82a037ec8d0f548cc00
553f2ef346ea9d224c8630c6a6eec8a764f18d14
v1.0
instruct
Codeforces
Codeforces_35162_I
You are given a set of n points in a 2D plane, each point represented by its coordinates (xi, yi). Your task is to determine the closest pair of points among the given set. The distance between two points (xi, yi) and (xj, yj) is defined as the Euclidean distance: \[d((xi, yi), (xj, yj)) = \sqrt{(xi - xj)^2 + (yi - yj...
import math def euclidean_distance(p1, p2): return math.sqrt((p1[0] - p2[0]) ** 2 + (p1[1] - p2[1]) ** 2) def closest_pair_of_points(points): points = sorted(points, key=lambda x: x[0]) def closest_pair_rec(start, end): if end - start <= 3: min_dist = float('inf') for i in...
from solution import closest_pair_of_points def test_small_number_of_points(): points = [(0, 0), (3, 4), (7, 7), (3, 0)] assert abs(closest_pair_of_points(points) - 3.0) < 1e-6 def test_minimum_possible_distance(): points = [(0, 0), (0, 0)] assert abs(closest_pair_of_points(points) - 0.0) < 1e-6 def ...
[ { "docstring": null, "function_declaration": "def euclidean_distance(p1, p2):", "function_name": "euclidean_distance", "parameter_list": "(p1, p2)" }, { "docstring": null, "function_declaration": "def closest_pair_of_points(points):", "function_name": "closest_pair_of_points", "p...
[ 0, 0, 1 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "from math import sqrt\nfrom itertools import combinations\n\ndef closest_pair(points):\n def distance(point1, point2):\n x1, y1 = point1\n x2...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00035162", "row_id": 35162, "seed_ids": "[6074, 5127, 1422]" }
0.770646
Codeforces_35162
I
[ "euclidean_distance", "closest_pair_of_points" ]
2
[ [ "closest_pair_of_points", "euclidean_distance" ] ]
1
[]
false
[]
false
pytest
true
[]
true
e7885bd19f8cb83ee31f798b173e52e8bb6c9d1c
58fca8bb4d622e3863d8ac8326897aa9fc69d5a9
v1.0
instruct
Codeforces
Codeforces_35201_I
In a distant galaxy, there are n planets that form a galactic network connected by m bidirectional paths. Each path directly connects two planets and has a certain travel cost associated with it. The Galactic Federation has decided to establish a central command on one of these planets, from which they will be able to ...
import heapq import sys def dijkstra(graph, n, start): # Initial distances are set to infinity distances = [sys.maxsize] * (n + 1) distances[start] = 0 # Priority queue to process nodes priority_queue = [(0, start)] while priority_queue: current_distance, u = heapq.heappop(priority...
def test_optimal_planet_simple_case(): n = 5 edges = [ (1, 2, 3), (1, 3, 4), (2, 4, 2), (2, 5, 3), (3, 4, 1), (4, 5, 5) ] assert find_optimal_planet(n, edges) == 2 def test_optimal_planet_tie_case(): n = 4 edges = [ (1, 2, 1), (2, ...
[ { "docstring": null, "function_declaration": "def dijkstra(graph, n, start):", "function_name": "dijkstra", "parameter_list": "(graph, n, start)" }, { "docstring": null, "function_declaration": "def find_optimal_planet(n, edges):", "function_name": "find_optimal_planet", "paramet...
[ 1, 0, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "import heapq\nfrom collections import defaultdict\n\ndef dijkstra(n, graph, start):\n \"\"\"\n Performs Dijkstra's algorithm to find the shortest path f...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00035201", "row_id": 35201, "seed_ids": "[2850, 4794, 6538]" }
0.631899
Codeforces_35201
I
[ "dijkstra", "find_optimal_planet" ]
2
[ [ "find_optimal_planet", "dijkstra" ] ]
1
[]
false
[]
false
pytest
false
[]
true
a8f49ddcc673bec9ccfa0b3ec638125e965c2a0e
5a5acab3d13403aa5eff6f75abe6c6a7c2d85cec
v1.0
instruct
Codeforces
Codeforces_35227_I
You are given a weighted graph with $$$v$$$ vertices and $$$e$$$ edges. The vertices are numbered from $$$0$$$ to $$$v-1$$$. Each edge has a positive weight. Your task is to find the weight of the minimum spanning tree (MST) of the graph. A spanning tree of a connected graph is a subgraph that includes all vertices an...
def find(parent, i): if parent[i] == i: return i return find(parent, parent[i]) def union(parent, rank, x, y): root_x = find(parent, x) root_y = find(parent, y) if rank[root_x] < rank[root_y]: parent[root_x] = root_y elif rank[root_x] > rank[root_y]: parent[root_y] = roo...
from solution import minimum_spanning_tree def test_example_1(): vertices = 4 edges_count = 5 edges = [ (0, 1, 10), (0, 2, 6), (0, 3, 5), (1, 3, 15), (2, 3, 4) ] assert minimum_spanning_tree(vertices, edges_count, edges) == 19 def test_example_2(): verti...
[ { "docstring": null, "function_declaration": "def find(parent, i):", "function_name": "find", "parameter_list": "(parent, i)" }, { "docstring": null, "function_declaration": "def union(parent, rank, x, y):", "function_name": "union", "parameter_list": "(parent, rank, x, y)" }, ...
[ 0, 1, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def find(parent, i):\n if parent[i] == i:\n return i\n else:\n return find(parent, parent[i])\n\ndef union(parent, rank, x, y):\n rootX...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00035227", "row_id": 35227, "seed_ids": "[3153, 7432, 8307]" }
0.822957
Codeforces_35227
I
[ "find", "union", "kruskal_mst", "minimum_spanning_tree" ]
4
[ [ "kruskal_mst", "find" ], [ "kruskal_mst", "union" ], [ "minimum_spanning_tree", "kruskal_mst" ], [ "union", "find" ] ]
4
[]
false
[]
false
pytest
true
[]
true
8c135f835f24d3501fa18a285e6e09cdc4132b7b
257b44b64a1be2b10e2641033c5ff98e776b72ea
v1.0
instruct
Codeforces
Codeforces_35241_I
You are given a matrix of dimensions $$$n \times m$$$. The matrix is initially filled with zeros. You need to perform a series of operations on this matrix. Each operation specifies a submatrix (a continuous block within the matrix) and a value $$$v$$$ to add to each element of this submatrix. After performing all the...
def update_matrix(n, m, operations): # Initialize matrix with zeros matrix = [[0 for _ in range(m)] for _ in range(n)] # Apply each operation for x1, y1, x2, y2, v in operations: for i in range(x1 - 1, x2): for j in range(y1 - 1, y2): matrix[i][j] += v return ma...
def test_update_matrix(): result = process_operations(3, 3, 3, [(1, 1, 2, 2, 1), (2, 2, 3, 3, 2), (1, 3, 3, 3, 3)]) expected = [ [1, 1, 3], [1, 3, 5], [0, 2, 5] ] assert result == expected def test_single_operation(): result = process_operations(2, 2, 1, [(1, 1, 2, 2, 5)]) ...
[ { "docstring": null, "function_declaration": "def update_matrix(n, m, operations):", "function_name": "update_matrix", "parameter_list": "(n, m, operations)" }, { "docstring": null, "function_declaration": "def process_operations(n, m, k, operations):", "function_name": "process_oper...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def apply_operations(n, m, operations):\n matrix = [[0] * m for _ in range(n)]\n\n for x1, y1, x2, y2, v in operations:\n for i in range(x1 - 1, ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00035241", "row_id": 35241, "seed_ids": "[8058, 3461, 2230]" }
0.631492
Codeforces_35241
I
[ "update_matrix", "process_operations" ]
2
[ [ "process_operations", "update_matrix" ] ]
1
[]
false
[]
false
pytest
false
[]
true
92848d80cc291f58cceae902a1d7e9b872218e82
0a6a8f703b94bb0946d61b554d3ea509f3a6a398
v1.0
instruct
Codeforces
Codeforces_35250_I
Given an array of integers, you are required to answer few queries where each query contains two integers left and right. For each query, you need to find subarray sum and the minimum element in the range from left to right (inclusive). The array does not change over multiple queries. You should preprocess the array...
def preprocess_array(arr): n = len(arr) # Preprocess prefix sums prefix_sum = [0] * (n + 1) for i in range(n): prefix_sum[i + 1] = prefix_sum[i] + arr[i] # Preprocess segment tree for range minima queries import math st = [[0] * (math.ceil(math.log2(n))+1) for _ in range(n)] ...
import pytest from solution import preprocess_array, range_sum, range_minimum, answer_queries def test_preprocess_array(): arr = [1, 2, 7, 4, 5, 3, 6, 8] prefix_sum, st = preprocess_array(arr) assert prefix_sum == [0, 1, 3, 10, 14, 19, 22, 28, 36] # The segment tree can't be easily validated because o...
[ { "docstring": null, "function_declaration": "def preprocess_array(arr):", "function_name": "preprocess_array", "parameter_list": "(arr)" }, { "docstring": null, "function_declaration": "def range_sum(prefix_sum, left, right):", "function_name": "range_sum", "parameter_list": "(p...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def preprocess(arr):\n \"\"\"\n Preprocess the array to generate prefix sums and minimum elements for each subarray.\n \"\"\"\n n = len(arr)\n ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00035250", "row_id": 35250, "seed_ids": "[8109, 5663, 6716]" }
0.737629
Codeforces_35250
I
[ "preprocess_array", "range_sum", "range_minimum", "answer_queries" ]
4
[ [ "answer_queries", "preprocess_array" ], [ "answer_queries", "range_minimum" ], [ "answer_queries", "range_sum" ] ]
3
[]
false
[]
false
pytest
true
[]
true
92ba548f76db0bdab791846bbb93a402fa9aa17b
bcd926e2d72b6342a772201386827058231a2434
v1.0
instruct
Codeforces
Codeforces_35329_I
Alice and Bob are playing a game with strings. They have two strings, `s1` and `s2`, each consisting of lowercase English letters. The game involves finding the longest common subsequence (LCS) of `s1` and `s2` — a sequence that appears in both strings in the same order but not necessarily contiguously. Alice proposes ...
def lcs(s1, s2): """ Returns the longest common subsequence of s1 and s2. """ m = len(s1) n = len(s2) # Create a 2D array to store the lengths of longest common subsequence dp = [[0] * (n+1) for _ in range(m+1)] # Fill dp array for i in range(m): for j in range(n): ...
def test_lcs(): assert lcs("abcbdab", "bdcaba") == "bdab" assert lcs("XMJYAUZ", "MZJAWXU") == "MJAU" assert lcs("abc", "abc") == "abc" assert lcs("abc", "def") == "" assert lcs("a", "a") == "a" def test_lexicographically_smallest_permutation(): assert lexicographically_smallest_permutation("bda...
[ { "docstring": "Returns the longest common subsequence of s1 and s2.", "function_declaration": "def lcs(s1, s2):", "function_name": "lcs", "parameter_list": "(s1, s2)" }, { "docstring": "Returns the lexicographically smallest permutation of the string lcs_str.", "function_declaration": "...
[ 0, 0, 0, 0, 0, 0, 0, 1, 0, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def longest_common_subsequence(s1, s2):\n \"\"\"\n Finds the Longest Common Subsequence (LCS) of s1 and s2.\n Returns the LCS as a string.\n \"\"\...
trial_gpt4o_7
{ "original_instruction": "", "prompt_id": "00035329", "row_id": 35329, "seed_ids": "[4086, 8208, 2878]" }
0.734767
Codeforces_35329
I
[ "lcs", "lexicographically_smallest_permutation", "smallest_lcs_permutation" ]
3
[ [ "smallest_lcs_permutation", "lcs" ], [ "smallest_lcs_permutation", "lexicographically_smallest_permutation" ] ]
2
[]
false
[]
false
pytest
false
[]
true
ff5d303105a49f37b430d78e67543362e155be6f
e94912b83c620ebcd42ddfca663c081bc0076136
v1.0
instruct
Codeforces
Codeforces_35342_I
Iahub likes playing with strings and puzzles. He came up with an interesting problem for you. You are given a string $$$s$$$ of length $$$n$$$ consisting of lowercase English letters. Iahub wants to rearrange the letters of the string in such a way that there are no two adjacent characters that are the same. If such ...
from collections import Counter import heapq def rearrange_string(s): n = len(s) freq_counter = Counter(s) # max heap by frequency max_heap = [(-freq, char) for char, freq in freq_counter.items()] heapq.heapify(max_heap) prev_char = None prev_freq = 0 result = [] whil...
def test_3_characters_no_adjacent(): assert iahub_string_rearrangement(3, "aab") in ["aba"] def test_2_same_characters_not_possible(): assert iahub_string_rearrangement(2, "aa") == -1 def test_single_character(): assert iahub_string_rearrangement(1, "a") == "a" def test_no_possible_rearrangement(): a...
[ { "docstring": null, "function_declaration": "def rearrange_string(s):", "function_name": "rearrange_string", "parameter_list": "(s)" }, { "docstring": null, "function_declaration": "def iahub_string_rearrangement(n, s):", "function_name": "iahub_string_rearrangement", "parameter...
[ 0, 1, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "from collections import Counter\nimport heapq\n\ndef rearrange_string(s: str) -> str:\n count = Counter(s)\n max_heap = [(-freq, char) for char, freq in...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00035342", "row_id": 35342, "seed_ids": "[7892, 1713, 4003]" }
0.737437
Codeforces_35342
I
[ "rearrange_string", "iahub_string_rearrangement" ]
2
[ [ "iahub_string_rearrangement", "rearrange_string" ] ]
1
[]
false
[]
false
pytest
false
[]
true
acfe202cd9d496da938e03b1967bf026c255381b
e09b147a8a531652ac8146e975a8b29621ddbf68
v1.0
instruct
Codeforces
Codeforces_35370_I
Given an undirected graph with $$$n$$$ vertices and $$$m$$$ edges, determine the minimum number of edges to be removed to make the graph bipartite. A graph is bipartite if its vertices can be divided into two disjoint sets such that no two graph vertices within the same set are adjacent. Each test contains multiple t...
from collections import deque, defaultdict def bfs_is_bipartite(graph, start, colors): queue = deque([start]) colors[start] = 0 while queue: current = queue.popleft() for neighbor in graph[current]: if colors[neighbor] == -1: colors[neighbor] = 1 - colors[current...
def test_min_edges_to_remove_to_make_bipartite(): test_cases = [ (4, 4, [(1, 2), (2, 3), (3, 4), (4, 1)]), (3, 2, [(1, 2), (2, 3)]) ] expected_results = [0, 0] results = process_test_cases(test_cases) assert results == expected_results def test_more_complex_case(): test_cases = ...
[ { "docstring": null, "function_declaration": "def bfs_is_bipartite(graph, start, colors):", "function_name": "bfs_is_bipartite", "parameter_list": "(graph, start, colors)" }, { "docstring": null, "function_declaration": "def min_edges_to_remove_to_make_bipartite(n, edges):", "functio...
[ 0, 1, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def min_edges_to_remove_for_bipartite(t, test_cases):\n from collections import deque \n\n def is_bipartite(n, adj):\n color = [-1] * (n + 1)\n ...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00035370", "row_id": 35370, "seed_ids": "[5932, 1965, 4261]" }
0.665511
Codeforces_35370
I
[ "bfs_is_bipartite", "min_edges_to_remove_to_make_bipartite", "process_test_cases", "read_input" ]
4
[ [ "min_edges_to_remove_to_make_bipartite", "bfs_is_bipartite" ], [ "process_test_cases", "min_edges_to_remove_to_make_bipartite" ] ]
2
[ "process_test_cases", "read_input" ]
false
[]
false
pytest
false
[]
true
996b55f0627108ff19b783e3e91c7892a3b77fb2
1dd6b94fb06983f00a9cbd0826e22f09ad0d3bd9
v1.0
instruct
Codeforces
Codeforces_35380_I
You are given an undirected, connected graph with \( n \) vertices and \( m \) edges. Each edge \( (u, v) \) has a non-negative weight \( w \). You need to determine the minimum spanning tree (MST) of the graph and then find the heaviest edge in the MST. The MST of a graph is a spanning tree whose sum of edge weights ...
import heapq def find(parent, i): if parent[i] == i: return i else: parent[i] = find(parent, parent[i]) return parent[i] def union(parent, rank, x, y): root_x = find(parent, x) root_y = find(parent, y) if rank[root_x] < rank[root_y]: parent[root_x] = root_y ...
def test_example(): n = 4 m = 5 edges = [ (1, 2, 1), (2, 3, 2), (3, 4, 3), (1, 3, 4), (1, 4, 5) ] assert heaviest_edge_in_mst(n, m, edges) == 3 def test_single_edge(): n = 2 m = 1 edges = [(1, 2, 10)] assert heaviest_edge_in_mst(n, m, edges) =...
[ { "docstring": null, "function_declaration": "def find(parent, i):", "function_name": "find", "parameter_list": "(parent, i)" }, { "docstring": null, "function_declaration": "def union(parent, rank, x, y):", "function_name": "union", "parameter_list": "(parent, rank, x, y)" }, ...
[ 1, 0, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "import heapq\n\ndef find(parent, i):\n if parent[i] == i:\n return i\n else:\n parent[i] = find(parent, parent[i])\n return parent[...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00035380", "row_id": 35380, "seed_ids": "[1475, 7982, 3599]" }
0.833348
Codeforces_35380
I
[ "find", "union", "kruskal_mst", "heaviest_edge_in_mst" ]
4
[ [ "heaviest_edge_in_mst", "kruskal_mst" ], [ "kruskal_mst", "find" ], [ "kruskal_mst", "union" ], [ "union", "find" ] ]
4
[]
false
[]
false
pytest
false
[]
true
355ba2d5d9eed84b047b6382c03370faaa43d150
e90dc7377220f42ce37ffc5d4e7fce88943edf2d
v1.0
instruct
Codeforces
Codeforces_35403_I
You are given a city with `n` intersections and `m` bidirectional roads. Each road has a length associated with it. Bob wants to find out the minimum travel distance he would need to go from intersection `1` to intersection `n`. Write a program that computes this minimum distance using the given roads. The first line ...
import heapq import sys def dijkstra(n, adj): # Distance to each node, initialized as infinity dist = [sys.maxsize] * (n + 1) dist[1] = 0 # Min heap to get the node with the smallest distance heap = [(0, 1)] while heap: current_dist, u = heapq.heappop(heap) if...
def test_min_travel_distance(): assert min_travel_distance(5, 6, [(1, 2, 2), (1, 3, 4), (2, 3, 1), (2, 4, 7), (3, 5, 3), (4, 5, 1)]) == 6 assert min_travel_distance(3, 2, [(1, 2, 2), (2, 3, 3)]) == 5 assert min_travel_distance(4, 4, [(1, 2, 1), (1, 3, 4), (2, 3, 2), (3, 4, 1)]) == 4 assert min_travel_di...
[ { "docstring": null, "function_declaration": "def dijkstra(n, adj):", "function_name": "dijkstra", "parameter_list": "(n, adj)" }, { "docstring": null, "function_declaration": "def min_travel_distance(n, m, roads):", "function_name": "min_travel_distance", "parameter_list": "(n, ...
[ 0, 0, 0, 1, 0 ]
1
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "import heapq\nfrom collections import defaultdict\nimport sys\n\ndef find_min_distance(n, m, roads):\n \"\"\"\n Returns the minimum distance from inters...
trial_gpt4o_3
{ "original_instruction": "", "prompt_id": "00035403", "row_id": 35403, "seed_ids": "[2879, 1852, 7340]" }
0.792197
Codeforces_35403
I
[ "dijkstra", "min_travel_distance" ]
2
[ [ "min_travel_distance", "dijkstra" ] ]
1
[]
false
[]
false
pytest
false
[]
true
89c98205381f18c608f4da8c122f8b26498210b0
65534d0334760ca39bce4b17148625268d57ce41
v1.0
instruct
Codeforces
Codeforces_35409_I
Inverted Index is a fundamental methodology that many search engines use to perform efficient textual searches. In this task, you are required to create an inverted index from a set of documents, and then perform queries on that index to find documents that contain specific words. ### Explanation: An inverted index i...
def build_inverted_index(documents): """ Returns an inverted index from the given documents. """ from collections import defaultdict inverted_index = defaultdict(list) for doc_id, doc in enumerate(documents, 1): words = doc.split() for word in words: if doc_id no...
def test_build_inverted_index(): documents = [ "hello world", "this is a test", "hello again", "test the inverted index" ] result = build_inverted_index(documents) expected = { 'hello': [1, 3], 'world': [1], 'this': [2], 'is': [2], ...
[ { "docstring": "Returns an inverted index from the given documents.", "function_declaration": "def build_inverted_index(documents):", "function_name": "build_inverted_index", "parameter_list": "(documents)" }, { "docstring": "Returns the list of document indices for each query word.", "f...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def create_inverted_index(documents):\n \"\"\"\n Create an inverted index from the given list of documents.\n \"\"\"\n inverted_index = {}\n fo...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00035409", "row_id": 35409, "seed_ids": "[1524, 2847, 3437]" }
0.537224
Codeforces_35409
I
[ "build_inverted_index", "query_inverted_index", "process_documents_and_queries" ]
3
[ [ "process_documents_and_queries", "build_inverted_index" ], [ "process_documents_and_queries", "query_inverted_index" ] ]
2
[]
false
[]
false
pytest
false
[]
true
aef831102860d17744dfc0b260748adc160ec253
40b569ceaf16ebe54ce1cdb13bfd8b72e5e53072
v1.0
instruct
Codeforces
Codeforces_35432_I
A network of n computers is connected by m bidirectional cables. Each computer in the network is assigned a unique ID from 1 to n. Each cable directly connects exactly two different computers and has a specific latency associated with it. Your task is to determine the minimum latency required to send data from compute...
import heapq def network_latency(n, m, cables): graph = {i: [] for i in range(1, n + 1)} for u, v, l in cables: graph[u].append((v, l)) graph[v].append((u, l)) # Dijkstra's algorithm to find the minimum latency from node 1 to node n pq = [(0, 1)] # (latency, node) latencies = {i: ...
from solution import solve_network_latency_problem def test_case_1(): input_data = "4 4\n1 2 1\n2 3 2\n3 4 1\n1 4 5" assert solve_network_latency_problem(input_data) == 4 def test_case_2(): input_data = "4 3\n1 2 1\n2 3 2\n3 4 1" assert solve_network_latency_problem(input_data) == 4 def test_case_3()...
[ { "docstring": null, "function_declaration": "def network_latency(n, m, cables):", "function_name": "network_latency", "parameter_list": "(n, m, cables)" }, { "docstring": null, "function_declaration": "def solve_network_latency_problem(input_data):", "function_name": "solve_network_...
[ 0, 1, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "import heapq\n\ndef minimum_latency(n, m, edges):\n graph = [[] for _ in range(n + 1)]\n for u, v, l in edges:\n graph[u].append((v, l))\n ...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00035432", "row_id": 35432, "seed_ids": "[287, 1518, 1379]" }
0.610835
Codeforces_35432
I
[ "network_latency", "solve_network_latency_problem" ]
2
[ [ "solve_network_latency_problem", "network_latency" ] ]
1
[]
false
[]
false
pytest
true
[]
true
61a507abaaece7ff93b43935bd66a9981d1aed0c
0678916b63d783eeac6cd89775bc365bf8b381f9
v1.0
instruct
Codeforces
Codeforces_35467_I
Given a string $$$s$$$ consisting of lowercase English letters, determine the minimum number of operations required to make all characters in the string distinct. In one operation, you can choose any character in the string and replace it with any other lowercase English letter. ### Input - The input consists of multi...
def min_operations_to_make_unique(s): """ Calculate the minimum number of operations required to make all characters in the string distinct. """ # Frequency count of each character freq = {} for char in s: if char in freq: freq[char] += 1 else: freq[char] ...
def test_example_cases(): input_data = """3 abc abca aaaa""" expected_output = """0 1 3""" assert solution_function(input_data) == expected_output def test_single_character_strings(): input_data = """3 a b c""" expected_output = """0 0 0""" assert solution_function(input_data) == expected_outpu...
[ { "docstring": "Calculate the minimum number of operations required to make all characters in the string distinct.", "function_declaration": "def min_operations_to_make_unique(s):", "function_name": "min_operations_to_make_unique", "parameter_list": "(s)" }, { "docstring": null, "functio...
[ 0, 0, 0, 1, 0 ]
1
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def min_operations_to_make_distinct(t, test_cases):\n \"\"\"\n For each test case, determine the minimum number of operations required\n to make all ...
trial_gpt4o_3
{ "original_instruction": "", "prompt_id": "00035467", "row_id": 35467, "seed_ids": "[8116, 4625, 2529]" }
0.796956
Codeforces_35467
I
[ "min_operations_to_make_unique", "min_ops_for_multiple_cases", "solution_function" ]
3
[ [ "min_ops_for_multiple_cases", "min_operations_to_make_unique" ], [ "solution_function", "min_ops_for_multiple_cases" ] ]
2
[]
false
[]
false
pytest
false
[]
true
b14929533b2378b4ce4b59d3e1d228fd76b70ef2
dd9175994764037db0a7cb93d6e5f9cdc86f7f7f
v1.0
instruct
Codeforces
Codeforces_35470_I
Captain Ahab is planning his next whaling expedition and needs to chart the shortest possible route to visit a specific set of islands in the Pacific Ocean. The islands are represented as nodes in a graph, and the routes between them are the edges with weights representing the distance. Given a graph with n nodes and ...
import heapq def dijkstra(graph, start, n): distances = [float('inf')] * (n + 1) distances[start] = 0 queue = [(0, start)] while queue: current_distance, current_node = heapq.heappop(queue) if current_distance > distances[current_node]: continue for neighbor, weight ...
from solution import shortest_path_to_visit_islands def test_example_case(): n = 6 m = 7 edges = [ (1, 2, 10), (1, 3, 15), (2, 4, 12), (3, 5, 10), (4, 5, 2), (5, 6, 5), (2, 6, 20) ] k = 4 islands = [1, 3, 4, 6] assert shortest_path_to_...
[ { "docstring": null, "function_declaration": "def dijkstra(graph, start, n):", "function_name": "dijkstra", "parameter_list": "(graph, start, n)" }, { "docstring": null, "function_declaration": "def shortest_path_to_visit_islands(n, m, edges, k, islands):", "function_name": "shortest...
[ 0, 1, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "import heapq\nimport sys\n\ndef dijkstra(graph, start):\n n = len(graph)\n dist = [sys.maxsize] * n\n dist[start] = 0\n pq = [(0, start)]\n \n ...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00035470", "row_id": 35470, "seed_ids": "[2902, 281, 2036]" }
0.741727
Codeforces_35470
I
[ "dijkstra", "shortest_path_to_visit_islands" ]
2
[ [ "shortest_path_to_visit_islands", "dijkstra" ] ]
1
[]
false
[]
false
pytest
true
[]
true
18c0291b7438a99228973433b87976702a16333c
4caca57df6de09cf0e65b6318253de9f07272c5d
v1.0
instruct
Codeforces
Codeforces_35487_I
Stanley loves puzzles and has discovered a new type of number which he calls 'circular primes'. A circular prime is a prime number that remains prime under all rotations of its digits. For example, 197 is a circular prime because all of its rotations (197, 971, and 719) are prime. Stanley wonders how many circular prim...
def is_prime(num): """ Check if the given number is a prime. """ if num < 2: return False if num == 2 or num == 3: return True if num % 2 == 0 or num % 3 == 0: return False i = 5 while i * i <= num: if num % i == 0 or num % (i + 2) == 0: return...
from solution import count_circular_primes, is_prime, get_rotations, is_circular_prime def test_is_prime(): assert is_prime(2) == True assert is_prime(3) == True assert is_prime(4) == False assert is_prime(29) == True assert is_prime(25) == False def test_get_rotations(): assert get_rotations(...
[ { "docstring": "Check if the given number is a prime.", "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": "Generate all rotations of a given number.", "function_declaration": "def get_rotations(num):", "function_nam...
[ 0, 0, 1 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(num):\n if num <= 1:\n return False\n if num == 2:\n return True\n if num % 2 == 0:\n return False\n for i in ra...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00035487", "row_id": 35487, "seed_ids": "[2003, 3101, 6367]" }
0.554825
Codeforces_35487
I
[ "is_prime", "get_rotations", "is_circular_prime", "count_circular_primes" ]
4
[ [ "count_circular_primes", "is_circular_prime" ], [ "is_circular_prime", "get_rotations" ], [ "is_circular_prime", "is_prime" ] ]
3
[]
false
[]
false
pytest
true
[]
true
579c80e4f3cca88461ba228bb93e3851f5b3c3ef
2e325718a663321ebe429f383e0f008a7894173a
v1.0
instruct
Codeforces
Codeforces_35492_I
A group of archeologists is exploring an ancient cave system. The cave has n chambers connected by m paths. Their goal is to map out the system by ensuring every chamber is reachable from any other chamber directly or indirectly. It's crucial that the group can efficiently travel between any two chambers. The cave sys...
def find_parent(parent, i): if parent[i] == i: return i else: return find_parent(parent, parent[i]) def union(parent, rank, x, y): xroot = find_parent(parent, x) yroot = find_parent(parent, y) if rank[xroot] < rank[yroot]: parent[xroot] = yroot elif rank[xroot] > ra...
from solution import minimum_additional_paths_needed def test_example_case(): n = 5 m = 3 paths = [(1, 2), (1, 3), (4, 5)] assert minimum_additional_paths_needed(n, m, paths) == 1 def test_fully_connected(): n = 4 m = 3 paths = [(1, 2), (2, 3), (3, 4)] assert minimum_additional_paths_n...
[ { "docstring": null, "function_declaration": "def find_parent(parent, i):", "function_name": "find_parent", "parameter_list": "(parent, i)" }, { "docstring": null, "function_declaration": "def union(parent, rank, x, y):", "function_name": "union", "parameter_list": "(parent, rank...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def find_parent(parent, i):\n if parent[i] == i:\n return i\n else:\n return find_parent(parent, parent[i])\n\ndef union(parent, rank, x, ...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00035492", "row_id": 35492, "seed_ids": "[7053, 3380, 6866]" }
0.641344
Codeforces_35492
I
[ "find_parent", "union", "minimum_additional_paths_needed" ]
3
[ [ "minimum_additional_paths_needed", "find_parent" ], [ "minimum_additional_paths_needed", "union" ], [ "union", "find_parent" ] ]
3
[]
false
[]
false
pytest
true
[]
true
1f4edf8770dead1e549ed0d2c9afeb7665501a17
1505ed79d51b993db3e53020c26314a1bd28e12f
v1.0
instruct
Codeforces
Codeforces_35518_I
You are given an undirected graph with n nodes and m edges. Each node is labeled with a unique integer from 1 to n. The graph may contain multiple edges between the same pair of nodes and self-loops. Your task is to determine whether the graph is connected or not. A graph is connected if there is a path between any pa...
def is_connected(n, m, edges): from collections import defaultdict, deque if n == 1: return True # Create adjacency list adj_list = defaultdict(list) for u, v in edges: adj_list[u].append(v) adj_list[v].append(u) # BFS to check connectivity visited = se...
def test_check_graph_connected(): assert check_graph_connected(4, 3, [(1, 2), (2, 3), (3, 4)]) == "YES" def test_check_graph_not_connected(): assert check_graph_connected(4, 2, [(1, 2), (3, 4)]) == "NO" def test_single_node_graph(): assert check_graph_connected(1, 0, []) == "YES" def test_two_nodes_conne...
[ { "docstring": null, "function_declaration": "def is_connected(n, m, edges):", "function_name": "is_connected", "parameter_list": "(n, m, edges)" }, { "docstring": null, "function_declaration": "def check_graph_connected(n, m, edges):", "function_name": "check_graph_connected", "...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_connected_graph(n, m, edges):\n from collections import defaultdict, deque\n\n # Create adjacency list\n adj_list = defaultdict(list)\n for...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00035518", "row_id": 35518, "seed_ids": "[1994, 6647, 6076]" }
0.722481
Codeforces_35518
I
[ "is_connected", "check_graph_connected" ]
2
[ [ "check_graph_connected", "is_connected" ] ]
1
[]
false
[]
false
pytest
false
[]
true
0f4be2eb4fe9a677c49080bad09a8014dbcc5ff6
01cb36df161b6712ad00353d41d6ac1e3d0009f8
v1.0
instruct
Codeforces
Codeforces_35520_I
You are given a grid of size $$n \times m$$ filled with characters. Each cell in the grid contains either '0' or '1'. You can only walk from a cell to its neighboring cell in one of the four directions: up, down, left, and right. The walk is considered valid if the absolute difference between the number of '0's and '1'...
from collections import deque def is_valid_path(grid, n, m): directions = [(-1, 0), (1, 0), (0, -1), (0, 1)] def bfs(): queue = deque([(0, 0, 0, 0)]) # (row, col, count_0, count_1) visited = set([(0, 0, 0, 0)]) while queue: r, c, count_0, count_1 = queue.pople...
def test_min_steps(): grid = [ '010', '001', '100' ] assert min_steps(grid) == 4 def test_no_path(): grid = [ '111', '111', '111' ] assert min_steps(grid) == -1 def test_simple_path(): grid = [ '00', '10' ] assert min_...
[ { "docstring": null, "function_declaration": "def is_valid_path(grid, n, m):", "function_name": "is_valid_path", "parameter_list": "(grid, n, m)" }, { "docstring": null, "function_declaration": "def min_steps(grid):", "function_name": "min_steps", "parameter_list": "(grid)" }, ...
[ 0, 0, 1 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "from collections import deque\n\ndef min_steps(grid, n, m):\n \"\"\"\n Returns the minimum number of steps required to reach from top-left to bottom-rig...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00035520", "row_id": 35520, "seed_ids": "[5788, 6191, 3575]" }
0.746649
Codeforces_35520
I
[ "is_valid_path", "min_steps" ]
2
[ [ "min_steps", "is_valid_path" ] ]
1
[]
false
[]
false
pytest
false
[]
true
a2896e0ccbc12435a51861b046b29f2d6b51f6de
5be70cbeaea66a85cafae0c759ceb7e1bf4893a0
v1.0
instruct
Codeforces
Codeforces_35521_I
Alex has a deep interest in the Fibonacci sequence and prime numbers. Recently, Alex came across an interesting problem and needs your help to solve it. The Fibonacci sequence is defined as follows: - \( F(0) = 0 \) - \( F(1) = 1 \) - \( F(n) = F(n-1) + F(n-2) \) for \( n \geq 2 \) A number is called a "Fibonacci Pr...
def fibonacci(n): """ Function to calculate the nth Fibonacci number. """ if n <= 0: return 0 elif n == 1: return 1 a, b = 0, 1 for _ in range(2, n + 1): a, b = b, a + b return b def is_prime(n): """ Function to determine if a number n is prime. """ ...
from solution import fibonacci, is_prime, is_fibonacci_prime def test_fibonacci(): assert fibonacci(0) == 0 assert fibonacci(1) == 1 assert fibonacci(2) == 1 assert fibonacci(3) == 2 assert fibonacci(4) == 3 assert fibonacci(5) == 5 assert fibonacci(10) == 55 def test_is_prime(): asser...
[ { "docstring": "Function to calculate the nth Fibonacci number.", "function_declaration": "def fibonacci(n):", "function_name": "fibonacci", "parameter_list": "(n)" }, { "docstring": "Function to determine if a number n is prime.", "function_declaration": "def is_prime(n):", "functio...
[ 0, 0, 1 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def fibonacci(n):\n \"\"\"\n Returns the n-th Fibonacci number.\n \"\"\"\n if n == 0:\n return 0\n elif n == 1:\n return 1\n a...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00035521", "row_id": 35521, "seed_ids": "[6340, 1835, 6554]" }
0.757817
Codeforces_35521
I
[ "fibonacci", "is_prime", "is_fibonacci_prime" ]
3
[ [ "is_fibonacci_prime", "fibonacci" ], [ "is_fibonacci_prime", "is_prime" ] ]
2
[]
false
[]
false
pytest
true
[]
true
ab10606dd91557c49fb8ec3a3649e5f8b637a8b4
4332bc060c19dddeaf724a98c8a3ae0e5cb20cb5
v1.0
instruct
Codeforces
Codeforces_35537_I
You have been hired as a detective by ACME Corporation to investigate a series of data breaches. In your investigation, you found that the company uses a secret encryption algorithm that involves two numbers, `x` and `y`. The algorithm generates the secret key by finding the Least Common Multiple (LCM) of these two num...
import math def lcm(a, b): """ Returns the Least Common Multiple (LCM) of a and b. """ return abs(a * b) // math.gcd(a, b) def secret_key(x, y): """ Calculate the secret key using the given algorithm. """ lcm1 = lcm(x, y) swapped_lcm = lcm(y, x) return lcm1 + swapped_lcm
from solution import lcm, secret_key def test_lcm(): assert lcm(12, 15) == 60 assert lcm(15, 12) == 60 assert lcm(1, 1) == 1 assert lcm(1, 2) == 2 assert lcm(8, 12) == 24 assert lcm(21, 6) == 42 def test_secret_key(): assert secret_key(12, 15) == 120 assert secret_key(1, 1) == 2 as...
[ { "docstring": "Returns the Least Common Multiple (LCM) of a and b.", "function_declaration": "def lcm(a, b):", "function_name": "lcm", "parameter_list": "(a, b)" }, { "docstring": "Calculate the secret key using the given algorithm.", "function_declaration": "def secret_key(x, y):", ...
[ 1, 0, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "import math\n\ndef lcm(a, b):\n \"\"\"\n Calculate the Least Common Multiple (LCM) of two integers a and b.\n \"\"\"\n return abs(a*b) // math.gcd...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00035537", "row_id": 35537, "seed_ids": "[6359, 7102, 7517]" }
0.601869
Codeforces_35537
I
[ "lcm", "secret_key" ]
2
[ [ "secret_key", "lcm" ] ]
1
[]
false
[]
false
pytest
true
[]
true
68d42c387ea2a05048739af329ee45f3b0a71c47
3e03fc948465708d34da726852972e1c8a9c6664
v1.0
instruct
Codeforces
Codeforces_35581_I
Paolo is a manager who needs to distribute a set of tasks among his employees. Each task takes a certain amount of time to complete. Paolo wants to minimize the maximum time taken by any employee to complete all their assigned tasks. To achieve this, he can distribute the tasks in any way he likes, but each task must b...
def canDistribute(tasks, n, m, maxTime): """ This function checks if it is possible to distribute all tasks among 'm' employees such that no employee spends more than 'maxTime' on their tasks. """ employeesUsed = 1 currentTime = 0 for task in tasks: if currentTime + task > maxTi...
from solution import findMinMaxTaskTime def test_distribute_tasks_case_1(): assert findMinMaxTaskTime(5, 2, [4, 7, 8, 3, 1]) == 12 def test_distribute_tasks_case_2(): assert findMinMaxTaskTime(3, 3, [1, 2, 3]) == 3 def test_distribute_tasks_case_3(): assert findMinMaxTaskTime(4, 2, [10, 10, 10, 10]) == 2...
[ { "docstring": "This function checks if it is possible to distribute all tasks among 'm' employees\nsuch that no employee spends more than 'maxTime' on their tasks.", "function_declaration": "def canDistribute(tasks, n, m, maxTime):", "function_name": "canDistribute", "parameter_list": "(tasks, n, m...
[ 1, 0, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def check(mid, tasks, m):\n current_sum = 0\n count = 1 # At least one employee is necessary\n for task in tasks:\n if current_sum + task > m...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00035581", "row_id": 35581, "seed_ids": "[6173, 2495, 5929]" }
0.698905
Codeforces_35581
I
[ "canDistribute", "findMinMaxTaskTime" ]
2
[ [ "findMinMaxTaskTime", "canDistribute" ] ]
1
[]
false
[]
false
pytest
true
[]
true
ea77c3aa4d1cf28ce395276b01aded55f30d0ded
b1ba510ee75645e181366dc1a932d0d4e8a23d56
v1.0
instruct
Codeforces
Codeforces_35585_I
Given a binary tree, your task is to find the sum of the values of the nodes on the longest path from the root to a leaf. If there are multiple paths with the same maximum length, consider the path which has the greatest sum of node values. The binary tree is represented in level order, where 'null' represents a missi...
class TreeNode: def __init__(self, val=0, left=None, right=None): self.val = val self.left = left self.right = right def construct_tree(level_order): if not level_order or level_order[0] == 'null': return None root = TreeNode(int(level_order[0])) queue = [root] i = ...
from solution import sum_longest_path_from_input def test_case_1(): input_str = "1 2 3 4 5 null 6 7 null null null null null 8" assert sum_longest_path_from_input(input_str) == 22 def test_case_2(): input_str = "1 2 3" assert sum_longest_path_from_input(input_str) == 4 def test_case_3(): input_st...
[]
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "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 bu...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00035585", "row_id": 35585, "seed_ids": "[1947, 464, 5227]" }
0.634288
Codeforces_35585
I
[ "construct_tree", "find_sum_of_longest_path", "sum_longest_path_from_input" ]
3
[ [ "sum_longest_path_from_input", "construct_tree" ], [ "sum_longest_path_from_input", "find_sum_of_longest_path" ] ]
2
[]
false
[ "TreeNode" ]
true
pytest
true
[]
true
742d8193bde26331c1f1f5f1426fa7e2c68b823a
7204740192e186685987f151b188548bdbb71ba2
v1.0
instruct
Codeforces
Codeforces_35605_I
You are given a binary tree with `n` nodes. Each node contains a unique integer identifier `NodeID` from `1` to `n`. Your task is to compute the following: 1. The longest path in the tree (also known as the tree diameter). 2. The minimum height of the binary tree when restructured by selecting any node as the new root...
from collections import deque, defaultdict def longestPathAndMinHeight(n, edges): if n == 1: return (0, 0) graph = defaultdict(list) for u, v in edges: graph[u].append(v) graph[v].append(u) def bfs(start): visited = [-1] * (n + 1) q = deque([start]) vi...
def test_example(): assert longestPathAndMinHeight(5, [(1, 2), (1, 3), (3, 4), (3, 5)]) == (3, 2) def test_single_node(): assert longestPathAndMinHeight(1, []) == (0, 0) def test_chain(): assert longestPathAndMinHeight(4, [(1, 2), (2, 3), (3, 4)]) == (3, 2) def test_star(): assert longestPathAndMinHe...
[ { "docstring": null, "function_declaration": "def longestPathAndMinHeight(n, edges):", "function_name": "longestPathAndMinHeight", "parameter_list": "(n, edges)" }, { "docstring": null, "function_declaration": "def solve():", "function_name": "solve", "parameter_list": "()" }, ...
[ 0, 1, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "from collections import deque, defaultdict\n\ndef find_longest_path_and_min_height(n, edges):\n # Build the graph from node edges\n graph = defaultdict(...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00035605", "row_id": 35605, "seed_ids": "[1037, 4829, 5456]" }
0.691919
Codeforces_35605
I
[ "longestPathAndMinHeight", "solve" ]
2
[ [ "solve", "longestPathAndMinHeight" ] ]
1
[]
false
[]
false
pytest
false
[]
true
78941bcfcb2106333201ee2505dee35688d71f86
8d32705aca72187f3ed3988fe458edee504f5699
v1.0
instruct
Codeforces
Codeforces_35638_I
You are given a program that controls a complex signaling system in a factory. The system consists of multiple signals that need to turn on and off following a specific pattern. Each signal operates in its own unique cycle, specified in seconds. For example, a signal with a cycle of 5 seconds will turn on at the 1st se...
from math import gcd from functools import reduce def lcm(a, b): """ Calculate the Least Common Multiple of two integers. """ return a * b // gcd(a, b) def first_common_on_time(cycles): """ Given a list of cycle durations of signals, find the first time in seconds when all the signals are...
from solution import first_common_on_time def test_common_case(): assert first_common_on_time([3, 4]) == 12 assert first_common_on_time([5, 7, 9]) == 315 def test_single_signal(): assert first_common_on_time([10]) == 10 def test_large_cycles(): assert first_common_on_time([10**9, 10**9 + 1]) == (10**...
[ { "docstring": "Calculate the Least Common Multiple of two integers.", "function_declaration": "def lcm(a, b):", "function_name": "lcm", "parameter_list": "(a, b)" }, { "docstring": "Given a list of cycle durations of signals, find the first time in seconds \nwhen all the signals are on simu...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "from functools import reduce\nimport math\n\ndef lcm(a, b):\n \"\"\"\n Calculate the Least Common Multiple of two numbers.\n \"\"\"\n return a * b...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00035638", "row_id": 35638, "seed_ids": "[5880, 4402, 2647]" }
0.578574
Codeforces_35638
I
[ "lcm", "first_common_on_time" ]
2
[ [ "first_common_on_time", "lcm" ] ]
1
[]
false
[]
false
pytest
true
[]
true
3467f6bf71e32f9db30b86aadd9173056963edef
aa5b302c5c1cac149117d7df497d1353e05ddbb8
v1.0
instruct
Codeforces
Codeforces_35687_I
You are working on a logistics and distribution project for a large manufacturing company. The company operates numerous warehouses spread across different cities. The goal is to improve delivery efficiency by optimizing the routes taken to deliver goods between warehouses. The company has a network of roads connecting...
import sys from collections import defaultdict, deque sys.setrecursionlimit(200000) def add_edge(graph, u, v, d): graph[u].append((v, d)) graph[v].append((u, d)) def lca_preprocess(graph, n, root=1): # To store the parent and depth of each node parent = [-1] * (n + 1) depth = [0] * (n + 1) ma...
from solution import warehouse_distances def test_case_1(): n = 5 edges = [ (1, 2, 3), (1, 3, 2), (3, 4, 4), (3, 5, 5) ] queries = [ (2, 4), (4, 5), (1, 5) ] assert warehouse_distances(n, edges, queries) == [9, 9, 7] def test_case_2(): ...
[ { "docstring": null, "function_declaration": "def add_edge(graph, u, v, d):", "function_name": "add_edge", "parameter_list": "(graph, u, v, d)" }, { "docstring": null, "function_declaration": "def lca_preprocess(graph, n, root=1):", "function_name": "lca_preprocess", "parameter_l...
[ 1, 0, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "import sys\nfrom collections import defaultdict, deque\n\nsys.setrecursionlimit(200000)\n\ndef add_edge(graph, u, v, d):\n graph[u].append((v, d))\n gra...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00035687", "row_id": 35687, "seed_ids": "[2011, 4230, 3114]" }
0.778374
Codeforces_35687
I
[ "add_edge", "lca_preprocess", "lca", "calculate_distance", "preprocess_distances", "warehouse_distances" ]
6
[ [ "calculate_distance", "lca" ], [ "warehouse_distances", "add_edge" ], [ "warehouse_distances", "calculate_distance" ], [ "warehouse_distances", "lca_preprocess" ], [ "warehouse_distances", "preprocess_distances" ] ]
5
[]
false
[]
false
pytest
true
[]
true
37f1555ef5d1a5c23345688ff28d78534b30a5a3
8eaf8cf2fd58a0eabd9460c3d5dc35df6da21f6e
v1.0
instruct
Codeforces
Codeforces_35726_I
Given two arrays, `in_order` and `pre_order`, representing the in-order and pre-order traversal of a binary tree, respectively, construct the binary tree. The in-order traversal of a binary tree is the sequence in which the nodes are visited in the order: Left subtree, Root, Right subtree. The pre-order traversal of a...
class TreeNode: def __init__(self, val=0, left=None, right=None): self.val = val self.left = left self.right = right def build_tree(in_order, pre_order): if not in_order or not pre_order: return None root_val = pre_order.pop(0) root = TreeNode(root_val) root_index ...
from solution import TreeNode, build_tree, postorder_traversal, reconstruct_post_order def test_simple_case(): in_order = [4, 2, 5, 1, 3] pre_order = [1, 2, 4, 5, 3] expected_post_order = [4, 5, 2, 3, 1] assert reconstruct_post_order(5, in_order, pre_order) == expected_post_order def test_single_node(...
[]
[ 0, 1, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "class TreeNode:\n def __init__(self, x):\n self.val = x\n self.left = None\n self.right = None\n\ndef build_tree(in_order, pre_order):...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00035726", "row_id": 35726, "seed_ids": "[5429, 6325, 6897]" }
0.596775
Codeforces_35726
I
[ "build_tree", "postorder_traversal", "reconstruct_post_order" ]
3
[ [ "reconstruct_post_order", "build_tree" ], [ "reconstruct_post_order", "postorder_traversal" ] ]
2
[]
false
[ "TreeNode" ]
true
pytest
true
[]
true
52ebe39416d4c9b2c742a5a4f84aeae1c3daeefb
447e595aeedf30a5e630354ab854095e640e5a80
v1.0
instruct
Codeforces
Codeforces_35757_I
Jenny is organizing her bookshelf and realizes she wants to group her books by genre such that the total weight of the books in each genre group is balanced as much as possible. She has n books, each with their weight wi, and k genres to classify them into. She needs to find a way to distribute the books into k genres...
def canDistribute(weights, n, k, maxWeight): current_sum = 0 required_genres = 1 for weight in weights: if current_sum + weight > maxWeight: required_genres += 1 current_sum = weight if required_genres > k: return False el...
def test_scenario1(): assert minMaxGenreWeight(5, 3, [10, 20, 30, 40, 50]) == 60 def test_scenario2(): assert minMaxGenreWeight(6, 2, [10, 10, 10, 10, 10, 10]) == 30 def test_scenario3(): assert minMaxGenreWeight(4, 2, [20, 10, 30, 10]) == 40 def test_scenario4(): assert minMaxGenreWeight(1, 1, [100]...
[ { "docstring": null, "function_declaration": "def canDistribute(weights, n, k, maxWeight):", "function_name": "canDistribute", "parameter_list": "(weights, n, k, maxWeight)" }, { "docstring": null, "function_declaration": "def minMaxGenreWeight(n, k, weights):", "function_name": "min...
[ 0, 0, 0, 1, 1 ]
2
medium
0.4
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def minimize_max_genre_weight(n, k, weights):\n def can_distribute(mid):\n genre_count, current_sum = 1, 0\n for weight in weights:\n ...
trial_gpt4o_3
{ "original_instruction": "", "prompt_id": "00035757", "row_id": 35757, "seed_ids": "[706, 2728, 1966]" }
0.658391
Codeforces_35757
I
[ "canDistribute", "minMaxGenreWeight" ]
2
[ [ "minMaxGenreWeight", "canDistribute" ] ]
1
[]
false
[]
false
pytest
false
[]
true
c66a1f7a6b681fe75037e1e0c8064be5d70656fa
f3c5d0cbd0c8da8339e88dee5f8384215f7d61d5
v1.0
instruct
Codeforces
Codeforces_35788_I
Cryptographer Alice is working on a new type of cipher to encode messages. She decided to use prime numbers as the main tool for encoding. Given a positive integer n, she wants to decompose it into the sum of the maximum number of prime numbers. If there are multiple ways to achieve this, she wants to find the decompos...
def sieve_of_eratosthenes(limit): primes = [] is_prime = [True] * (limit + 1) is_prime[0] = is_prime[1] = False for number in range(2, limit + 1): if is_prime[number]: primes.append(number) for multiple in range(number * number, limit + 1, number): is...
from solution import prime_decomposition def test_prime_decomposition_6(): assert prime_decomposition(6) == [2, 2, 2] def test_prime_decomposition_10(): assert prime_decomposition(10) == [2, 2, 2, 2, 2] def test_prime_decomposition_13(): assert prime_decomposition(13) == [13] def test_prime_decompositio...
[ { "docstring": null, "function_declaration": "def sieve_of_eratosthenes(limit):", "function_name": "sieve_of_eratosthenes", "parameter_list": "(limit)" }, { "docstring": null, "function_declaration": "def prime_decomposition(n):", "function_name": "prime_decomposition", "paramete...
[ 0, 1, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def decompose_to_primes(n):\n \"\"\"\n Decompose the given integer into the sum of the maximum number of prime numbers with the smallest lexicographical...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00035788", "row_id": 35788, "seed_ids": "[3921, 3984, 5575]" }
0.638701
Codeforces_35788
I
[ "sieve_of_eratosthenes", "prime_decomposition" ]
2
[ [ "prime_decomposition", "sieve_of_eratosthenes" ] ]
1
[]
false
[]
false
pytest
true
[]
true
7f919b2736900d3e936a88cbe3a11883c4f0122d
7164accc3b7dabf5a771f12c95511004efdd1019
v1.0
instruct
Codeforces
Codeforces_35833_I
Byte the Factorial loves factorials but hates trailing zeroes! Byte recently found a peculiar interest in the concept of factorials – the product of all positive integers up to a given number n. However, Byte despises trailing zeroes in numbers because they look unattractive. A trailing zero is a zero at the end of a n...
def count_trailing_zeroes(n): """ Returns the number of trailing zeroes in the factorial of n. """ count = 0 while n >= 5: n //= 5 count += n return count def min_trailing_zeroes(l, r): """ Returns the minimum number of trailing zeroes in n! for any integer n between l a...
from solution import count_trailing_zeroes, min_trailing_zeroes def test_count_trailing_zeroes(): assert count_trailing_zeroes(5) == 1 assert count_trailing_zeroes(10) == 2 assert count_trailing_zeroes(25) == 6 assert count_trailing_zeroes(3) == 0 def test_min_trailing_zeroes(): assert min_trailin...
[ { "docstring": "Returns the number of trailing zeroes in the factorial of n.", "function_declaration": "def count_trailing_zeroes(n):", "function_name": "count_trailing_zeroes", "parameter_list": "(n)" }, { "docstring": "Returns the minimum number of trailing zeroes in n! for any integer n b...
[ 0, 0, 1 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def count_trailing_zeroes(n):\n \"\"\"\n This function returns the number of trailing zeroes in n!.\n \"\"\"\n count = 0\n while n >= 5:\n ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00035833", "row_id": 35833, "seed_ids": "[6441, 7313, 3593]" }
0.609005
Codeforces_35833
I
[ "count_trailing_zeroes", "min_trailing_zeroes" ]
2
[ [ "min_trailing_zeroes", "count_trailing_zeroes" ] ]
1
[]
false
[]
false
pytest
true
[]
true
92ab767863e45f67fcdc3ae6d9af519e763d2daf
fcfca8b1e5897b78d69831a5f6f7385a705d06b2
v1.0
instruct
Codeforces
Codeforces_35844_I
Vrohacs recently became interested in a type of sequence they call "beautiful arrays." An array of integers is called beautiful if it contains an arithmetic progression of three elements. Your task is to help Vrohacs determine whether a given array is beautiful or not. An array of integers is given as input. The array...
def is_beautiful_array(arr): """ Determines if the array contains an arithmetic progression of three elements. """ arr_set = set(arr) n = len(arr) for i in range(n): for j in range(i+1, n): num1, num2 = arr[i], arr[j] diff = num2 - num1 next_num =...
def test_is_beautiful_array(): assert check_beautiful_array(5, [3, 6, 9, 12, 15]) == "YES" assert check_beautiful_array(4, [1, 2, 3, 5]) == "YES" assert check_beautiful_array(3, [1, 2, 4]) == "NO" assert check_beautiful_array(7, [10, 20, 30, 40, 50, 60, 25]) == "YES" assert check_beautiful_array(8, ...
[ { "docstring": "Determines if the array contains an arithmetic progression of three elements.", "function_declaration": "def is_beautiful_array(arr):", "function_name": "is_beautiful_array", "parameter_list": "(arr)" }, { "docstring": null, "function_declaration": "def check_beautiful_ar...
[ 0, 0, 1 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_beautiful_array(arr):\n \"\"\"\n Determine whether the given array contains an arithmetic progression of three elements.\n \n :param arr: L...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00035844", "row_id": 35844, "seed_ids": "[237, 6883, 2920]" }
0.646111
Codeforces_35844
I
[ "is_beautiful_array", "check_beautiful_array" ]
2
[ [ "check_beautiful_array", "is_beautiful_array" ] ]
1
[]
false
[]
false
pytest
false
[]
true
804e88065a710c1d7ab9b466444f557309dab903
20170fdda885da47dc2c76c777737746160f8992
v1.0
instruct
Codeforces
Codeforces_35900_I
You are given a binary tree where each node has a value. Your task is to transform the binary tree so that the value of each node is replaced by the sum of values of all the nodes in its subtree, including the node itself. The subtree of a node is the tree consisting of the node and all its descendants. The binary tre...
class TreeNode: def __init__(self, value, left=None, right=None): self.value = value self.left = left self.right = right def build_tree(tree_list): nodes = {} for value, left, right in tree_list: if value not in nodes: nodes[value] = TreeNode(value) node ...
from solution import transform_tree def test_simple_tree(): tree = [(1, 2, 3), (2, None, None), (3, None, None)] expected_output = [(6, 2, 3), (2, None, None), (3, None, None)] assert transform_tree(tree) == expected_output def test_extended_tree(): tree = [(1, 2, 3), (2, None, None), (3, 4, 5), (4, N...
[]
[ 0, 0, 1 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "class TreeNode:\n def __init__(self, value):\n self.value = value\n self.left = None\n self.right = None\n\ndef build_tree(nodes):\n ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00035900", "row_id": 35900, "seed_ids": "[7381, 7588, 30]" }
0.554101
Codeforces_35900
I
[ "build_tree", "sum_subtree", "build_tuple_list", "transform_tree" ]
4
[ [ "transform_tree", "build_tree" ], [ "transform_tree", "build_tuple_list" ], [ "transform_tree", "sum_subtree" ] ]
3
[]
false
[ "TreeNode" ]
true
pytest
true
[]
true
c1ceb16228bd805de9c7ea336659f63280031427
4515507f7b83583935d2281a5c196bd19a28bc9d
v1.0
instruct
Codeforces
Codeforces_35931_I
In Ancient Grolen, there is a peculiar game involving a rectangular grid of dimensions m x n. Each cell in the grid contains a positive integer value. The player starts at the top-left corner of the grid and aims to reach the bottom-right corner. The player can only move in two possible ways: - Right: Move to the cel...
def max_path_sum(grid): """ Returns the maximum sum of values along a path from the top-left to the bottom-right corner of the grid. :param grid: List[List[int]] :return: int """ m = len(grid) n = len(grid[0]) # Initialize a dp array with the same dimensions as grid dp = [[0] * ...
from solution import find_max_path_sum def test_find_max_path_sum_example(): m = 3 n = 3 matrix = [ [1, 3, 1], [1, 5, 1], [4, 2, 1], ] assert find_max_path_sum(m, n, matrix) == 12 def test_find_max_path_sum_single_row(): m = 1 n = 5 matrix = [[1, 2, 3, 4, 5]] ...
[ { "docstring": "Returns the maximum sum of values along a path from the top-left to the bottom-right corner of the grid.\n:param grid: List[List[int]]\n:return: int", "function_declaration": "def max_path_sum(grid):", "function_name": "max_path_sum", "parameter_list": "(grid)" }, { "docstrin...
[ 0, 0, 1, 1 ]
2
medium
0.5
{ "trial_gpt4o_0": null, "trial_gpt4o_1": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared1_results_combined.jsonl", "solution_code": "def max_path_sum(m, n, grid):\n \"\"\"\n Returns the maximum sum of values along the path from the top-left \n to the bottom...
trial_gpt4o_4
{ "original_instruction": "", "prompt_id": "00035931", "row_id": 35931, "seed_ids": "[1951, 6192, 7221]" }
0.627744
Codeforces_35931
I
[ "max_path_sum", "find_max_path_sum" ]
2
[ [ "find_max_path_sum", "max_path_sum" ] ]
1
[]
false
[]
false
pytest
true
[]
true
cb321066947b6d5bc1e3af1ef84c7d3483067dc7
19baf14eb0c07e2b9f9f5fcba4679c8ff8ada013
v1.0
instruct
Codeforces
Codeforces_35959_I
Henry is the head guard of a large bank and he's in charge of security. The bank has n security checkpoints and these checkpoints are connected by m bidirectional corridors. Each corridor has a certain length. The bank's corridors form a connected graph. Henry needs to ensure that it is possible to get from any checkpo...
import heapq def dijkstra(adj_list, start, n): """ Runs Dijkstra's algorithm and returns the shortest distances from start to all nodes. """ dist = [float('inf')] * (n + 1) dist[start] = 0 min_heap = [(0, start)] while min_heap: current_dist, u = heapq.heappop(min_heap) ...
from solution import shortest_path_after_adjustment def test_example_case(): n = 5 m = 5 edges = [ (1, 2, 3), (2, 3, 4), (3, 4, 5), (4, 5, 2), (1, 5, 10) ] assert shortest_path_after_adjustment(n, m, edges) == 9 def test_single_edge(): n = 2 m = 1 ...
[ { "docstring": "Runs Dijkstra's algorithm and returns the shortest distances from start to all nodes.", "function_declaration": "def dijkstra(adj_list, start, n):", "function_name": "dijkstra", "parameter_list": "(adj_list, start, n)" }, { "docstring": null, "function_declaration": "def ...
[ 0, 0, 0, 0, 0, 0, 0, 1, 0, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "import heapq\n\ndef dijkstra(n, graph, start):\n distances = [float('inf')] * (n + 1)\n distances[start] = 0\n priority_queue = [(0, start)]\n \n ...
trial_gpt4o_7
{ "original_instruction": "", "prompt_id": "00035959", "row_id": 35959, "seed_ids": "[2439, 7782, 473]" }
0.665512
Codeforces_35959
I
[ "dijkstra", "shortest_path_after_adjustment" ]
2
[ [ "shortest_path_after_adjustment", "dijkstra" ] ]
1
[]
false
[]
false
pytest
true
[]
true
bbca0b7a508a20399513d1ed58bf33237662c963
4282fcbd2bacbd968812535f79f8b729fbbf4b6a
v1.0
instruct
Codeforces
Codeforces_35969_I
You are given an undirected, weighted graph with $$$n$$$ nodes and $$$m$$$ edges. Each edge has a positive integer weight. Your task is to find the shortest path from node $$$1$$$ to node $$$n$$$ using at most $$$k$$$ edges. If there is no such path, output -1. The first line contains three integers $$$n$$$, $$$m$$$, ...
import heapq def shortest_path_with_k_edges(n, m, k, edges): # Initialize adjacency list graph = [[] for _ in range(n + 1)] for u, v, w in edges: graph[u].append((v, w)) graph[v].append((u, w)) # (dist, node, edges_used) pq = [(0, 1, 0)] # Start from node 1 with distance 0 and 0 ed...
from solution import find_shortest_path def test_case_1(): n = 6 m = 7 k = 3 edges = [ (1, 2, 5), (2, 3, 10), (1, 4, 2), (4, 5, 3), (5, 6, 8), (3, 6, 1), (2, 6, 4) ] assert find_shortest_path(n, m, k, edges) == 9 def test_case_2(): n ...
[ { "docstring": null, "function_declaration": "def shortest_path_with_k_edges(n, m, k, edges):", "function_name": "shortest_path_with_k_edges", "parameter_list": "(n, m, k, edges)" }, { "docstring": null, "function_declaration": "def find_shortest_path(n, m, k, edge_list):", "function...
[ 0, 1, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def shortest_path(n, m, k, edges):\n INF = float('inf')\n dp = [[INF] * (k + 1) for _ in range(n + 1)]\n dp[1][0] = 0 # Starting point\n \n fo...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00035969", "row_id": 35969, "seed_ids": "[4495, 5854, 7915]" }
0.849698
Codeforces_35969
I
[ "shortest_path_with_k_edges", "find_shortest_path" ]
2
[ [ "find_shortest_path", "shortest_path_with_k_edges" ] ]
1
[]
false
[]
false
pytest
true
[]
true
a640558957679a680cf0833c62e151eb15aa9866
89ec5a2e8ba885997e922b7b3a8aa38c762b4fc2
v1.0
instruct
Codeforces
Codeforces_35974_I
Alpha loves prime numbers and regularly checks if numbers are prime. He has recently been intrigued by numbers that can be expressed as the sum of prime numbers in consecutive order. For example, the number 41 can be expressed as 2 + 3 + 5 + 7 + 11 + 13. Given a number n, Alpha wants to know if it can be represented a...
def is_prime(num): if num < 2: return False elif num == 2: return True elif num % 2 == 0: return False sqrt_n = int(num**0.5) + 1 for i in range(3, sqrt_n, 2): if num % i == 0: return False return True def consecutive_prime_sum(n): primes = [] ...
from solution import consecutive_prime_sum def test_consecutive_prime_sum_yes(): assert consecutive_prime_sum(41) == "YES" def test_consecutive_prime_sum_no(): assert consecutive_prime_sum(20) == "NO" def test_consecutive_prime_sum_edge_case(): assert consecutive_prime_sum(2) == "YES" def test_consecuti...
[ { "docstring": null, "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": null, "function_declaration": "def consecutive_prime_sum(n):", "function_name": "consecutive_prime_sum", "parameter_list": "(n)" } ]
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def sieve_of_eratosthenes(max_num):\n is_prime = [True] * (max_num + 1)\n is_prime[0] = is_prime[1] = False\n for start in range(2, int(max_num**0.5)...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00035974", "row_id": 35974, "seed_ids": "[6190, 6852, 1047]" }
0.615457
Codeforces_35974
I
[ "is_prime", "consecutive_prime_sum" ]
2
[ [ "consecutive_prime_sum", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
ba4206dcc77ea4fd7d8c1c0d773f704b19dbf294
bdf1d42a12f024281d76e3da99c92a6bf6a56e5b
v1.0
instruct
Codeforces
Codeforces_35987_I
In a kingdom far away, there are n castles connected by m bidirectional roads. Each road connects two castles (u, v) and has a certain length (d). The kingdom needs to maintain an efficient and safe route system to ensure that all castles can communicate with one another directly or indirectly. The king wants to know ...
def find(parent, i): if parent[i] == i: return i return find(parent, parent[i]) def union(parent, rank, x, y): xroot = find(parent, x) yroot = find(parent, y) if rank[xroot] < rank[yroot]: parent[xroot] = yroot elif rank[xroot] > rank[yroot]: parent[yroot] = xroot el...
from solution import minimum_total_length def test_example_1(): n = 4 m = 5 edges = [ (1, 2, 4), (1, 3, 3), (1, 4, 2), (2, 3, 5), (3, 4, 1) ] assert minimum_total_length(n, m, edges) == 7 def test_example_2(): n = 3 m = 0 edges = [] assert mi...
[ { "docstring": null, "function_declaration": "def find(parent, i):", "function_name": "find", "parameter_list": "(parent, i)" }, { "docstring": null, "function_declaration": "def union(parent, rank, x, y):", "function_name": "union", "parameter_list": "(parent, rank, x, y)" }, ...
[ 0, 1, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def find(parent, i):\n while parent[i] != i:\n i = parent[i]\n return i\n\ndef union(parent, rank, x, y):\n root_x = find(parent, x)\n root...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00035987", "row_id": 35987, "seed_ids": "[3940, 5536, 1479]" }
0.687877
Codeforces_35987
I
[ "find", "union", "kruskal_mst", "minimum_total_length" ]
4
[ [ "kruskal_mst", "find" ], [ "kruskal_mst", "union" ], [ "minimum_total_length", "kruskal_mst" ], [ "union", "find" ] ]
4
[]
false
[]
false
pytest
true
[]
true
1a6cc9f031f8e912189efe30cea504ae3705ecc5
ad129ac2104a282d144a00ff48cbc31a01ca189d
v1.0
instruct
Codeforces
Codeforces_36021_I
The kingdom of Silvergrove is known for its intricate cobblestone roads connecting several towns in the kingdom. There are `n` towns labeled from 1 to `n` and `m` roads connecting these towns bidirectionally. Each road has a certain distance associated with it. The kingdom's wise ruler wants to improve the trade routes...
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...
import pytest from solution import minimal_max_distance def test_example(): n = 4 m = 5 roads = [ (1, 2, 5), (2, 3, 6), (3, 4, 2), (1, 3, 10), (1, 4, 8) ] assert minimal_max_distance(n, m, roads) == 6 def test_small_case(): n = 2 m = 1 roads = [ ...
[ { "docstring": null, "function_declaration": "def find(parent, i):", "function_name": "find", "parameter_list": "(parent, i)" }, { "docstring": null, "function_declaration": "def union(parent, rank, x, y):", "function_name": "union", "parameter_list": "(parent, rank, x, y)" }, ...
[ 1, 0, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def find(parent, i):\n if parent[i] == i:\n return i\n else:\n parent[i] = find(parent, parent[i])\n return parent[i]\n\ndef union(...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00036021", "row_id": 36021, "seed_ids": "[4160, 2876, 703]" }
0.770673
Codeforces_36021
I
[ "find", "union", "is_possible", "minimal_max_distance" ]
4
[ [ "is_possible", "find" ], [ "is_possible", "union" ], [ "minimal_max_distance", "is_possible" ], [ "union", "find" ] ]
4
[]
false
[]
false
pytest
true
[]
true
3b0ad06f662d7b73efde3897e5357ee57c6eee66
747367753deaae4c4eed24dc7a999f3c68b20fc6
v1.0
instruct
Codeforces
Codeforces_36035_I
Vivek loves to play with numbers. Given an integer array $$$a$$$ of length $$$n$$$. He wants to find the longest subsequence, such that for any two elements $$$a_i$$$ and $$$a_j$$$ ($$$i < j$$$) in the subsequence the following conditions hold: 1. $$$a_j - a_i$$$ is a prime number. Given the array $$$a$$$, help Vivek...
import math from collections import defaultdict def is_prime(num): if num <= 1: return False if num <= 3: return True if num % 2 == 0 or num % 3 == 0: return False i = 5 while i * i <= num: if num % i == 0 or num % (i + 2) == 0: return False i += ...
from solution import longest_subsequence_with_prime_diff def test_example_case(): assert longest_subsequence_with_prime_diff(5, [3, 7, 12, 8, 15]) == 3 def test_single_element(): assert longest_subsequence_with_prime_diff(1, [10]) == 1 def test_no_prime_diff(): assert longest_subsequence_with_prime_diff(...
[ { "docstring": null, "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": null, "function_declaration": "def generate_prime_set(max_diff):", "function_name": "generate_prime_set", "parameter_list": "(max_diff)" }...
[ 0, 1, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "import math\n\ndef is_prime(n):\n \"\"\"Helper function to determine if n is a prime number.\"\"\"\n if n <= 1:\n return False\n if n <= 3:\n ...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00036035", "row_id": 36035, "seed_ids": "[4954, 1081, 5404]" }
0.751485
Codeforces_36035
I
[ "is_prime", "generate_prime_set", "longest_subsequence_with_prime_diff" ]
3
[ [ "generate_prime_set", "is_prime" ], [ "longest_subsequence_with_prime_diff", "generate_prime_set" ] ]
2
[]
false
[]
false
pytest
true
[]
true
820dd5c9cd6c99c5317a4184e9207ccff523110c
26c3f13281f762c6fbcf3e4bb52516127e645eb4
v1.0
instruct
Codeforces
Codeforces_36066_I
You are given a grid with n rows and m columns consisting of characters '*' and '.'. A rectangle in the grid is defined by four corners (r1, c1), (r1, c2), (r2, c1), and (r2, c2) such that r1 ≤ r2 and c1 ≤ c2. A rectangle is called filled if every cell inside it contains a '*'. Your task is to find the rectangle with t...
def max_filled_rectangle_area(n, m, grid): max_area = 0 # Convert grid to list of lists of ints for easier manipulation ('*' -> 1, '.' -> 0) matrix = [[1 if grid[r][c] == '*' else 0 for c in range(m)] for r in range(n)] # Prepare storage for heights heights = [0] * m for row in ma...
from solution import find_max_filled_rectangle def test_max_filled_rectangle_area(): n = 4 m = 5 grid = [ "*****", "*..**", "*****", "*****" ] assert find_max_filled_rectangle(n, m, grid) == 10 def test_single_cell_filled(): n = 1 m = 1 grid = ["*"] ...
[ { "docstring": null, "function_declaration": "def max_filled_rectangle_area(n, m, grid):", "function_name": "max_filled_rectangle_area", "parameter_list": "(n, m, grid)" }, { "docstring": null, "function_declaration": "def largest_rectangle_area_in_histogram(heights):", "function_nam...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def maximal_filled_rectangle(grid):\n \"\"\"\n Find the area of the largest filled rectangle in the grid.\n \n :param grid: A 2D list of character...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00036066", "row_id": 36066, "seed_ids": "[5754, 6158, 4372]" }
0.724074
Codeforces_36066
I
[ "max_filled_rectangle_area", "largest_rectangle_area_in_histogram", "find_max_filled_rectangle" ]
3
[ [ "find_max_filled_rectangle", "max_filled_rectangle_area" ], [ "max_filled_rectangle_area", "largest_rectangle_area_in_histogram" ] ]
2
[]
false
[]
false
pytest
true
[]
true
a1465b4f82e013a1bef894029112da3a4f055489
58a95036019f64c95c14f038171b1c49d3c3d867
v1.0
instruct
Codeforces
Codeforces_36079_I
You're managing a network of n servers connected by m transmission lines. Each transmission line connects exactly two servers and data can be transmitted in both directions. Additionally, each line has an associated transmission cost. Unfortunately, not all servers are directly connected, and some server pairs may be 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_single_server(): assert minimum_transmission_cost(1, 0, []) == 0 def test_no_edges(): assert minimum_transmission_cost(4, 0, []) == -1 def test_general_case(): edge_list = [ (1, 2, 3), (2, 3, 4), (3, 4, 2), (4, 1, 1) ] assert minimum_transmission_cost(4, 4,...
[ { "docstring": null, "function_declaration": "def find(parent, i):", "function_name": "find", "parameter_list": "(parent, i)" }, { "docstring": null, "function_declaration": "def union(parent, rank, x, y):", "function_name": "union", "parameter_list": "(parent, rank, x, y)" }, ...
[ 1, 0, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def find(parent, i):\n if parent[i] == i:\n return i\n else:\n return find(parent, parent[i])\n\ndef union(parent, rank, x, y):\n xroot...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00036079", "row_id": 36079, "seed_ids": "[5806, 6620, 3063]" }
0.602163
Codeforces_36079
I
[ "find", "union", "kruskal_mst", "minimum_transmission_cost" ]
4
[ [ "kruskal_mst", "find" ], [ "kruskal_mst", "union" ], [ "minimum_transmission_cost", "kruskal_mst" ], [ "union", "find" ] ]
4
[]
false
[]
false
pytest
false
[]
true
47d1596e55f919d2ca815bf41cc5e44b71f0db30
6bb0aa3aa5d7e5910b151a26e17b912bd66adbd7
v1.0
instruct
Codeforces
Codeforces_36150_I
Bob's friend Alice has a peculiar interest in words and numbers. She recently encountered a challenge involving words composed of certain sets of letters. Alice describes a word as "perfect" if it solely consists of alternating vowels and consonants and starts with a vowel. For example, the word "abecid" is perfect, wh...
def is_perfect_word(word): vowels = "aeiou" consonants = "bcdfghjklmnpqrstvwxyz" if word[0] not in vowels: return "IMPERFECT" for i in range(1, len(word)): if (word[i-1] in vowels and word[i] not in consonants) or (word[i-1] in consonants and word[i] not in vowels): ...
import pytest from solution import check_words, is_perfect_word def test_is_perfect_word(): assert is_perfect_word("abecid") == "PERFECT" assert is_perfect_word("bacde") == "IMPERFECT" assert is_perfect_word("aioue") == "IMPERFECT" assert is_perfect_word("a") == "PERFECT" assert is_perfect_word("ab...
[ { "docstring": null, "function_declaration": "def is_perfect_word(word):", "function_name": "is_perfect_word", "parameter_list": "(word)" }, { "docstring": null, "function_declaration": "def check_words(words):", "function_name": "check_words", "parameter_list": "(words)" } ]
[ 1, 0, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_perfect_word(word):\n vowels = set('aeiou')\n consonants = set('bcdfghjklmnpqrstvwxyz')\n \n if len(word) == 0 or word[0] not in vowels:\n ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00036150", "row_id": 36150, "seed_ids": "[145, 6298, 2959]" }
0.674873
Codeforces_36150
I
[ "is_perfect_word", "check_words" ]
2
[ [ "check_words", "is_perfect_word" ] ]
1
[]
false
[]
false
pytest
true
[]
true
ac65faf9300350c4ac3722eed118af56ce31fb1d
0a4a334f8e1e2bb98aee45a32ae0393945e73c3f
v1.0
instruct
Codeforces
Codeforces_36304_I
You are given a rectangular grid of size $$$N \times M$$$ (1 ≤ N, M ≤ 1000) consisting of lowercase letters. A word search algorithm scans this grid to find words from a given dictionary. The algorithm can move horizontally, vertically, or diagonally to adjacent cells in eight possible directions. However, it cannot wr...
def find_word_in_grid(grid, rows, cols, word): directions = [(-1, -1), (-1, 0), (-1, 1), (0, -1), (0, 1), (1, -1), (1, 0), (1, 1)] def dfs(x, y, index): if index == len(word): return True if not (0 <= x < rows and 0 <= y < cols) or grid[x][y] != word[index] or visited[x][y]: ...
from solution import solve_word_search def test_case_1(): N = 4 M = 5 grid = [ "abces", "sfcsf", "adees", "sster" ] Q = 3 words = ["abc", "see", "ssss"] assert solve_word_search(N, M, grid, Q, words) == ["YES", "YES", "NO"] def test_case_2(): N = 3 M...
[ { "docstring": null, "function_declaration": "def find_word_in_grid(grid, rows, cols, word):", "function_name": "find_word_in_grid", "parameter_list": "(grid, rows, cols, word)" }, { "docstring": null, "function_declaration": "def solve_word_search(N, M, grid, Q, words):", "function_...
[ 0, 0, 0, 0, 0, 0, 0, 0, 1 ]
1
hard
0.111
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def word_search(grid, words):\n def search_from(x, y, word):\n if not word:\n return True\n if not (0 <= x < n and 0 <= y < m):\n ...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00036304", "row_id": 36304, "seed_ids": "[3114, 5999, 7947]" }
0.681656
Codeforces_36304
I
[ "find_word_in_grid", "solve_word_search" ]
2
[ [ "solve_word_search", "find_word_in_grid" ] ]
1
[]
false
[]
false
pytest
true
[]
true
13746c5a58d2d9205c55e8af7b81f7c4eb46a05c
61443564717f71390ac18d67cbb3167a150d7028
v1.0
instruct
Codeforces
Codeforces_36320_I
Eve and Adam are learning about binary trees. They are particularly interested in identifying the "kth smallest element" in a binary search tree (BST). They came up with a challenge: given a BST, find the kth smallest element within it. In a binary search tree, the "kth smallest element" is defined as the kth element ...
class TreeNode: def __init__(self, val=0, id=0, left=None, right=None): self.val = val self.id = id self.left = left self.right = right def insert_into_BST(root, val, id): if not root: return TreeNode(val, id) if val < root.val or (val == root.val and id < root....
from solution import find_kth_smallest def test_example_case(): n = 5 k = 3 nodes = [(4, 1), (2, 2), (6, 3), (1, 4), (3, 5)] assert find_kth_smallest(n, k, nodes) == 3 def test_single_node(): n = 1 k = 1 nodes = [(1, 1)] assert find_kth_smallest(n, k, nodes) == 1 def test_all_left_chi...
[]
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "class TreeNode:\n def __init__(self, x):\n self.val = x\n self.left = None\n self.right = None\n\ndef insert_node(root, node):\n if...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00036320", "row_id": 36320, "seed_ids": "[6578, 5395, 4306]" }
0.539497
Codeforces_36320
I
[ "insert_into_BST", "kth_smallest_element", "find_kth_smallest" ]
3
[ [ "find_kth_smallest", "insert_into_BST" ], [ "find_kth_smallest", "kth_smallest_element" ] ]
2
[]
false
[ "TreeNode" ]
true
pytest
true
[]
true
89740cd0e522a61d13be16cc239e702ac5dc1df4
18cf43e20384ae0809615d39b798e1875fe3e2aa
v1.0
instruct
Codeforces
Codeforces_36330_I
You are given an array of integers `arr` of length `n` and an integer `m`. Your task is to partition the array into exactly `m` non-overlapping subarrays such that the maximum sum of the values in any of the `m` subarrays is minimized. Formally, you need to select `m-1` partition points, divide the array into `m` sect...
def can_partition(arr, n, m, mid): count, current_sum = 1, 0 for num in arr: if current_sum + num > mid: count += 1 current_sum = num if count > m: return False else: current_sum += num return True def minimize_maximum_sum(arr,...
def test_minimize_maximum_sum_basic(): assert minimize_maximum_sum([7, 2, 5, 10, 8], 5, 2) == 18 def test_minimize_maximum_sum_single_element(): assert minimize_maximum_sum([5], 1, 1) == 5 def test_minimize_maximum_sum_single_partition(): assert minimize_maximum_sum([1, 2, 3, 4, 5], 5, 1) == 15 def test_...
[ { "docstring": null, "function_declaration": "def can_partition(arr, n, m, mid):", "function_name": "can_partition", "parameter_list": "(arr, n, m, mid)" }, { "docstring": null, "function_declaration": "def minimize_maximum_sum(arr, n, m):", "function_name": "minimize_maximum_sum", ...
[ 1, 0, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def can_partition(arr, m, max_sum):\n current_sum = 0\n count = 1\n \n for num in arr:\n if current_sum + num > max_sum:\n count...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00036330", "row_id": 36330, "seed_ids": "[7756, 5928, 6628]" }
0.74931
Codeforces_36330
I
[ "can_partition", "minimize_maximum_sum" ]
2
[ [ "minimize_maximum_sum", "can_partition" ] ]
1
[]
false
[]
false
pytest
false
[]
true
afa5cb9844195fabfcecef330547b3d9e3ba341a
3437311ca1eda6814310f860f0a3be758add43a9
v1.0
instruct
Codeforces
Codeforces_36380_I
Given a grid of size N x M consisting of '0's (empty cells) and '1's (walls), you need to determine the shortest path from the top-left corner (0, 0) to the bottom-right corner (N-1, M-1). You can move up, down, left, or right, but cannot pass through walls ('1's). In addition, you have a special ability that can tran...
from collections import deque def shortest_path_with_ability(grid, n, m): def is_valid(x, y): return 0 <= x < n and 0 <= y < m directions = [(0, 1), (1, 0), (0, -1), (-1, 0)] queue = deque([(0, 0, 0, False)]) # x, y, steps, used_ability visited = set((0, 0, False)) while queue: ...
def test_example_case_1(): grid = [ "01100", "00010", "00010", "11110", "00000" ] assert min_steps_to_reach_bottom_right(5, 5, grid) == 8 def test_example_case_2(): grid = [ "111", "111", "111" ] assert min_steps_to_reach_bottom_ri...
[ { "docstring": null, "function_declaration": "def shortest_path_with_ability(grid, n, m):", "function_name": "shortest_path_with_ability", "parameter_list": "(grid, n, m)" }, { "docstring": null, "function_declaration": "def min_steps_to_reach_bottom_right(n, m, grid):", "function_na...
[ 0, 0, 0, 0, 0, 0, 1, 0, 1 ]
2
hard
0.222
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "from collections import deque\n\ndef shortest_path_with_transform(grid):\n N, M = len(grid), len(grid[0])\n directions = [(-1, 0), (1, 0), (0, -1), (0, ...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00036380", "row_id": 36380, "seed_ids": "[2709, 4332, 4417]" }
0.746333
Codeforces_36380
I
[ "shortest_path_with_ability", "min_steps_to_reach_bottom_right" ]
2
[ [ "min_steps_to_reach_bottom_right", "shortest_path_with_ability" ] ]
1
[]
false
[]
false
pytest
false
[]
true
6003b6c4f1686213f0ef4d492fdf8bf1ed1ca91e
047e52e3e2f638cee989afb96dd26b1eb57508d0
v1.0
instruct
Codeforces
Codeforces_36414_I
A mysterious old cathedral in the city has a lot of stained glass windows, which are especially beautiful during daylight. Each window can be described as a grid of cells, where each cell can either let the light pass through or block it. The monks at the cathedral are interested in knowing the largest rectangle of cel...
def max_histogram_area(histogram): stack = [] max_area = 0 index = 0 while index < len(histogram): if not stack or histogram[stack[-1]] <= histogram[index]: stack.append(index) index += 1 else: top_of_stack = stack.pop() area = (histogram[...
def test_max_histogram_area(): assert max_histogram_area([6, 2, 5, 4, 5, 1, 6]) == 12 assert max_histogram_area([2, 1, 2]) == 3 def test_max_rectangle_area(): assert max_rectangle_area([["1", "0", "1", "0", "0"], ["1", "0", "1", "1", "1"], ["1...
[ { "docstring": null, "function_declaration": "def max_histogram_area(histogram):", "function_name": "max_histogram_area", "parameter_list": "(histogram)" }, { "docstring": null, "function_declaration": "def max_rectangle_area(grid):", "function_name": "max_rectangle_area", "param...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def maximalRectangle(matrix):\n if not matrix:\n return 0\n \n n = len(matrix)\n m = len(matrix[0])\n max_area = 0\n heights = [0...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00036414", "row_id": 36414, "seed_ids": "[5734, 2174, 6182]" }
0.637732
Codeforces_36414
I
[ "max_histogram_area", "max_rectangle_area" ]
2
[ [ "max_rectangle_area", "max_histogram_area" ] ]
1
[]
false
[]
false
pytest
false
[]
true
667803b7a01856ae13a18463bd2e8677854a5f9f
6c346e8b864314a80aae86463cdb26e14835d2bb
v1.0
instruct
Codeforces
Codeforces_36452_I
Aman loves solving problems related to prime numbers. He recently learned about twin primes and got curious. A twin prime is a prime number that has either a difference of 2 lower and/or 2 higher prime numbers. For example, (3, 5) and (11, 13) are twin primes. Aman wants to find all twin primes in a given range. Help ...
def sieve_of_eratosthenes(max_num): """Generates a list of booleans representing primality of numbers from 0 to max_num""" is_prime = [True] * (max_num + 1) is_prime[0] = is_prime[1] = False # 0 and 1 are not primes for start in range(2, int(max_num**0.5) + 1): if is_prime[start]: ...
import pytest from solution import solve, format_results def test_sieve_of_eratosthenes(): sieve = sieve_of_eratosthenes(30) assert sieve[2] assert sieve[3] assert not sieve[4] assert sieve[5] assert sieve[29] assert not sieve[30] def test_find_twin_primes(): is_prime = sieve_of_erato...
[ { "docstring": "Generates a list of booleans representing primality of numbers from 0 to max_num", "function_declaration": "def sieve_of_eratosthenes(max_num):", "function_name": "sieve_of_eratosthenes", "parameter_list": "(max_num)" }, { "docstring": null, "function_declaration": "def f...
[ 1, 0, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def sieve_of_eratosthenes(max_num):\n \"\"\"Generates a list of booleans representing primality of numbers from 0 to max_num\"\"\"\n is_prime = [True] *...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00036452", "row_id": 36452, "seed_ids": "[2266, 7800, 971]" }
0.66999
Codeforces_36452
I
[ "sieve_of_eratosthenes", "find_twin_primes", "solve", "format_results" ]
4
[ [ "solve", "find_twin_primes" ], [ "solve", "sieve_of_eratosthenes" ] ]
2
[ "format_results" ]
false
[]
false
pytest
true
[]
true
2c113b2a59f157df240cedb1c4132ec702836c5c
31a33272c87b506a1574d5300abca3229d0e681a
v1.0
instruct
Codeforces
Codeforces_36520_I
Peter loves working with numbers and is fascinated by special number sequences. Recently, he came across a unique type of sequence called a "Factorial Sum Sequence." In this sequence, each number is the sum of the factorials of its digits. He started experimenting with these sequences and observed interesting behaviors...
import math def factorial_sum(n): """ Calculates the sum of factorials of the digits of the given number n. """ return sum(math.factorial(int(digit)) for digit in str(n)) def steps_to_repeating_number(n): """ Generates the Factorial Sum Sequence starting from n and returns the number of steps ...
from solution import steps_to_repeating_number def test_example_1(): assert steps_to_repeating_number(145) == 1 def test_example_2(): assert steps_to_repeating_number(69) == 5 def test_example_3(): assert steps_to_repeating_number(1) == 1 def test_example_4(): assert steps_to_repeating_number(40585)...
[ { "docstring": "Calculates the sum of factorials of the digits of the given number n.", "function_declaration": "def factorial_sum(n):", "function_name": "factorial_sum", "parameter_list": "(n)" }, { "docstring": "Generates the Factorial Sum Sequence starting from n and returns the number of...
[ 0, 0, 1 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "import math\n\ndef factorial_sum_sequence_steps(n):\n def factorial_sum(num):\n return sum(math.factorial(int(digit)) for digit in str(num))\n\n ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00036520", "row_id": 36520, "seed_ids": "[6089, 7874, 1420]" }
0.586422
Codeforces_36520
I
[ "factorial_sum", "steps_to_repeating_number" ]
2
[ [ "steps_to_repeating_number", "factorial_sum" ] ]
1
[]
false
[]
false
pytest
true
[]
true
a00b17cb9294662a4fd57fcfddb1c32acd85f34f
90cc17a6dbed4fdd49ef4cc60a9161f0a932e19b
v1.0
instruct
Codeforces
Codeforces_36526_I
In a distant world, there are n ancient temples located in a vast desert. Each temple is a point in a 2D coordinate plane, and no two temples share the same location. The rulers of the land want to establish a new path that connects all the temples exactly once and forms a simple polygon (a non-intersecting closed path...
import math from itertools import permutations def calculate_distance(p1, p2): return math.sqrt((p1[0] - p2[0]) ** 2 + (p1[1] - p2[1]) ** 2) def calculate_path_length(path): total_length = 0 for i in range(len(path)): total_length += calculate_distance(path[i], path[(i + 1) % len(path)]) retur...
from solution import calculate_distance, shortest_polygon_path def test_calculate_distance(): assert calculate_distance((0, 0), (3, 4)) == 5.0 def test_shortest_polygon_path_square(): points = [(0, 0), (0, 1), (1, 1), (1, 0)] result = shortest_polygon_path(points) assert math.isclose(result, 4.0, abs_...
[ { "docstring": null, "function_declaration": "def calculate_distance(p1, p2):", "function_name": "calculate_distance", "parameter_list": "(p1, p2)" }, { "docstring": null, "function_declaration": "def calculate_path_length(path):", "function_name": "calculate_path_length", "param...
[ 0, 1, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "import math\nfrom functools import cmp_to_key\n\ndef compute_distance(p1, p2):\n \"\"\"\n Computes the Euclidean distance between two points p1 and p2.\...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00036526", "row_id": 36526, "seed_ids": "[6158, 2818, 364]" }
0.611277
Codeforces_36526
I
[ "calculate_distance", "calculate_path_length", "shortest_polygon_path", "main" ]
4
[ [ "calculate_path_length", "calculate_distance" ], [ "shortest_polygon_path", "calculate_path_length" ] ]
2
[]
false
[]
false
pytest
true
[]
true
75c58706f5153b3ad5942455256d3cdc7a68279e
829c774022c3aab0eb82d4cb661d45d4f2aa5742
v1.0
instruct
Codeforces
Codeforces_36535_I
Ian is an anthropologist studying the social networks of a community. He models the community as a graph with $$$n$$$ members (numbered from $$$1$$$ to $$$n$$$) and $$$m$$$ friendships (undirected edges) between them. Ian is particularly interested in clique structures within this community. A clique is defined as a s...
from itertools import combinations def is_clique(graph, nodes): """ Check if a given set of nodes forms a clique. """ for u, v in combinations(nodes, 2): if v not in graph[u]: return False return True def largest_clique_size(n, m, friendships): """ Finds the size of the...
from solution import largest_clique_size def test_example_case(): assert largest_clique_size(5, 6, [(1, 2), (1, 3), (1, 4), (2, 3), (2, 4), (3, 4)]) == 4 def test_single_member(): assert largest_clique_size(1, 0, []) == 1 def test_no_friendships(): assert largest_clique_size(4, 0, []) == 1 def test_two_...
[ { "docstring": "Check if a given set of nodes forms a clique.", "function_declaration": "def is_clique(graph, nodes):", "function_name": "is_clique", "parameter_list": "(graph, nodes)" }, { "docstring": "Finds the size of the largest clique in the friendship graph.\nn: number of members\nm: ...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def largest_clique(n, m, friendships):\n from itertools import combinations\n\n def is_clique(subset):\n for u, v in combinations(subset, 2):\n ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00036535", "row_id": 36535, "seed_ids": "[1147, 3193, 7999]" }
0.671829
Codeforces_36535
I
[ "is_clique", "largest_clique_size" ]
2
[ [ "largest_clique_size", "is_clique" ] ]
1
[]
false
[]
false
pytest
true
[]
true
9a08e5958d69fbc8fba8cfd7f5dfbfd517ff9740
5e51e8243f53919831fb0b140c8adf58a2f09144
v1.0
instruct
Codeforces
Codeforces_36584_I
You are the manager of a logistics company. You have a network of warehouses connected by roads, each with a certain length. There are n warehouses and m bidirectional roads. Each road connects two warehouses and has a length associated with it. Your task is to ensure that every warehouse can communicate with every oth...
def find(parent, i): """ A utility function to find the set of an element i using path compression. """ if parent[i] == i: return i else: parent[i] = find(parent, parent[i]) return parent[i] def union(parent, rank, x, y): """ A function that does union of two subsets...
from solution import min_roads_to_construct def test_example_case(): roads = [(1, 2, 4), (3, 4, 3)] assert min_roads_to_construct(4, 2, roads) == 1 def test_already_connected(): roads = [(1, 2, 1), (2, 3, 1), (3, 4, 1)] assert min_roads_to_construct(4, 3, roads) == 0 def test_no_roads(): assert m...
[ { "docstring": "A utility function to find the set of an element i using path compression.", "function_declaration": "def find(parent, i):", "function_name": "find", "parameter_list": "(parent, i)" }, { "docstring": "A function that does union of two subsets x and y based on the rank.", ...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def find(parent, i):\n \"\"\"\n A utility function to find the set of an element i using path compression.\n \"\"\"\n if parent[i] == i:\n ...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00036584", "row_id": 36584, "seed_ids": "[2525, 3073, 298]" }
0.699435
Codeforces_36584
I
[ "find", "union", "min_roads_to_construct" ]
3
[ [ "min_roads_to_construct", "find" ], [ "min_roads_to_construct", "union" ], [ "union", "find" ] ]
3
[]
false
[]
false
pytest
true
[]
true
6c917895a544fe3064e5372a12bd858e17567db6
39b28fa076393da5fee9c524ec03a8c8901b0154
v1.0
instruct
Codeforces
Codeforces_36613_I
The kingdom of Farland is a prosperous region known for its powerful knights and magical beings. Recently, their king has called upon a special architect to plan the largest rectangular castle that can be built using specific sections of land within the kingdom. The kingdom is represented as a 2D grid of size n × m, w...
def maximalRectangle(matrix): if not matrix or not matrix[0]: return 0 n = len(matrix) m = len(matrix[0]) # Initialize variables max_area = 0 # Heights array heights = [0] * m for row in range(n): for col in range(m): # Update the heights hi...
from solution import maximalRectangle def test_example_case(): matrix = [ [1, 0, 1, 0, 0], [1, 0, 1, 1, 1], [1, 1, 1, 1, 1], [1, 0, 0, 1, 0] ] assert maximalRectangle(matrix) == 6 def test_single_row(): matrix = [[1, 0, 1, 1, 1]] assert maximalRectangle(matrix) == 3...
[ { "docstring": null, "function_declaration": "def maximalRectangle(matrix):", "function_name": "maximalRectangle", "parameter_list": "(matrix)" }, { "docstring": null, "function_declaration": "def largestRectangleArea(heights):", "function_name": "largestRectangleArea", "paramete...
[ 0, 1, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def maximal_rectangle(matrix):\n if not matrix or not matrix[0]:\n return 0\n \n def max_histogram_area(heights):\n stack = []\n ...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00036613", "row_id": 36613, "seed_ids": "[5418, 6429, 6272]" }
0.639999
Codeforces_36613
I
[ "maximalRectangle", "largestRectangleArea" ]
2
[ [ "maximalRectangle", "largestRectangleArea" ] ]
1
[]
false
[]
false
pytest
true
[]
true
f9236fc92ce1d50b6fe34a9973f5a3ef4f2b20c2
a8989c7bd4745d22bd8faa95946289f92a9e80a6
v1.0
instruct
Codeforces
Codeforces_36679_I
A local library is hosting a word game challenge. Participants are given a string of lowercase English letters and a dictionary of valid words. The objective is to determine the longest valid word in the dictionary that can be formed using the letters of the given string. Each letter in the given string can only be use...
def can_form(word, char_count): """ Checks whether the given word can be formed from the characters in char_count with sufficient number of each character. """ word_count = {} for char in word: if char in word_count: word_count[char] += 1 else: word_count[...
def test_no_valid_word(): assert longest_valid_word('xyz', ['apple', 'banana', 'cherry', 'date']) == '' def test_single_char_word(): assert longest_valid_word('a', ['a']) == 'a' def test_exact_match(): assert longest_valid_word('hello', ['hello', 'he', 'ohell']) == 'hello' def test_longest_and_lexicograp...
[ { "docstring": "Checks whether the given word can be formed from the characters\nin char_count with sufficient number of each character.", "function_declaration": "def can_form(word, char_count):", "function_name": "can_form", "parameter_list": "(word, char_count)" }, { "docstring": null, ...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def longest_valid_word(S, dictionary):\n from collections import Counter\n \n def can_form(word, letter_count):\n word_count = Counter(word)\n...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00036679", "row_id": 36679, "seed_ids": "[7944, 2634, 5335]" }
0.754331
Codeforces_36679
I
[ "can_form", "longest_valid_word" ]
2
[ [ "longest_valid_word", "can_form" ] ]
1
[]
false
[]
false
pytest
false
[]
true
7a3aef2cc311b43d4b65603683c70687c19880f0
d097a2921d6dac76d8b0ec13748a651588b3155b
v1.0
instruct
Codeforces
Codeforces_36795_I
In a land far away, there are multi-colored gemstones scattered across a magical grid of size `n x n`. Each gemstone has a unique color, and each stone occupies a distinct cell. These gemstones hold significant power which can only be unlocked when all stones of the same color are arranged in a horizontal or vertical l...
def find_moves(n, initial, target): moves = [] if initial == target: return moves def swap(x1, y1, x2, y2): nonlocal initial initial[x1][y1], initial[x2][y2] = initial[x2][y2], initial[x1][y1] moves.append(f"S {x1+1} {y1+1} {x2+1} {y2+1}") def rotate(x, y): ...
from solution import transform_grid def test_simple_swap(): n = 3 initial = [ "AAB", "BBC", "CCD" ] target = [ "ABB", "ABC", "BBC" ] transform_grid(n, initial, target) def test_no_change_needed(): n = 2 initial = [ "AB", "...
[ { "docstring": null, "function_declaration": "def find_moves(n, initial, target):", "function_name": "find_moves", "parameter_list": "(n, initial, target)" }, { "docstring": null, "function_declaration": "def transform_grid(n, initial, target):", "function_name": "transform_grid", ...
[ 0, 1, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def find_moves_to_transform(n, initial_grid, target_grid):\n moves = []\n \n # Find positions of all gemstones in initial and target grids\n initi...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00036795", "row_id": 36795, "seed_ids": "[7549, 8197, 6034]" }
0.715237
Codeforces_36795
I
[ "find_moves", "transform_grid" ]
2
[ [ "transform_grid", "find_moves" ] ]
1
[]
false
[]
false
pytest
true
[]
true
79ac0a14fc773ede209954bdb8b1355209aa46cc
e4f14d701bb2012e3a413713b98066e6f33f5843
v1.0
instruct
Codeforces
Codeforces_36802_I
Vlad loves graphs very much. One day, he decided to play a game with his computer. He will give the computer a connected undirected graph with $$$n$$$ vertices and $$$m$$$ edges, and a sequence of queries. Each query will provide two vertices $$$u$$$ and $$$v$$$ in the graph. For each query, the computer will have to d...
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 xroot != yroot: if rank[xroot] < rank[yroot]: parent[xroot] ...
from solution import vlad_loves_graphs def test_graph_all_connected(): n = 5 m = 5 edges = [(1, 2), (2, 3), (3, 4), (4, 5), (5, 1)] q = 3 queries = [(1, 3), (2, 5), (4, 2)] expected = ["YES", "YES", "YES"] assert vlad_loves_graphs(n, m, edges, q, queries) == expected def test_graph_disconn...
[ { "docstring": null, "function_declaration": "def find(parent, i):", "function_name": "find", "parameter_list": "(parent, i)" }, { "docstring": null, "function_declaration": "def union(parent, rank, x, y):", "function_name": "union", "parameter_list": "(parent, rank, x, y)" }, ...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def find(parent, i):\n if parent[i] == i:\n return i\n else:\n parent[i] = find(parent, parent[i])\n return parent[i]\n\ndef union(...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00036802", "row_id": 36802, "seed_ids": "[3163, 3030, 2885]" }
0.718678
Codeforces_36802
I
[ "find", "union", "vlad_loves_graphs" ]
3
[ [ "union", "find" ], [ "vlad_loves_graphs", "find" ], [ "vlad_loves_graphs", "union" ] ]
3
[]
false
[]
false
pytest
true
[]
true
0a6b97a0be57d840da6134fcf258ac667935399f
24e09765ccc5305d7021a87e164983335d9ad7c2
v1.0
instruct
Codeforces
Codeforces_36807_I
An online store has a loyalty program. Each new customer who registers on the site gets a unique customer ID and, upon making their first purchase, can receive a discount. The store has a buggy system: if a customer ID contains consecutive identical digits, e.g., 112 or 202, they are ineligible for any discounts. You ...
def is_eligible_for_discount(customer_id): """ Checks if the given customer ID is eligible for a discount. A customer ID is eligible if it does not contain consecutive identical digits. """ for i in range(1, len(customer_id)): if customer_id[i] == customer_id[i-1]: return False ...
from solution import is_eligible_for_discount, count_eligible_customers def test_is_eligible_for_discount(): assert is_eligible_for_discount("123456") == True assert is_eligible_for_discount("112345") == False assert is_eligible_for_discount("234567") == True assert is_eligible_for_discount("678910") =...
[ { "docstring": "Checks if the given customer ID is eligible for a discount.\n\nA customer ID is eligible if it does not contain consecutive identical digits.", "function_declaration": "def is_eligible_for_discount(customer_id):", "function_name": "is_eligible_for_discount", "parameter_list": "(custo...
[ 1, 0, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def count_discount_eligible_customers(n, customer_ids):\n \"\"\"\n Returns the count of unique customer IDs eligible for discounts.\n \n :param n:...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00036807", "row_id": 36807, "seed_ids": "[5152, 7823, 3762]" }
0.660082
Codeforces_36807
I
[ "is_eligible_for_discount", "count_eligible_customers" ]
2
[ [ "count_eligible_customers", "is_eligible_for_discount" ] ]
1
[]
false
[]
false
pytest
true
[]
true
e7485f778cc3987e4d836d413cca047670729082
c4d7b93901b82fc494199a61eb1f1cd99efe03fe
v1.0
instruct
Codeforces
Codeforces_36837_I
Sid loves prime numbers and has a collection of them. His collection is organized in a unique way. He picks the primes sequentially starting from the smallest prime number and arranges them in a table with n columns. Consequently, the number of rows in the table is determined by the number of primes in the collection a...
import itertools def nth_prime(n): def is_prime(num): if num <= 1: return False if num <= 3: return True if num % 2 == 0 or num % 3 == 0: return False i = 5 while i * i <= num: if num % i == 0 or num % (i + 2) == 0: ...
from solution import find_prime_in_table def test_find_prime_in_table_example1(): assert find_prime_in_table(15, 5, 3, 2) == 37 def test_find_prime_in_table_example2(): assert find_prime_in_table(10, 4, 3, 3) == -1 def test_find_prime_in_table_out_of_bounds(): assert find_prime_in_table(20, 5, 5, 3) == -...
[ { "docstring": null, "function_declaration": "def nth_prime(n):", "function_name": "nth_prime", "parameter_list": "(n)" }, { "docstring": null, "function_declaration": "def find_prime_in_table(p, n, r, c):", "function_name": "find_prime_in_table", "parameter_list": "(p, n, r, c)"...
[ 0, 0, 0, 0, 1 ]
1
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def sieve_of_eratosthenes(max_num):\n \"\"\"\n Generate a list of prime numbers up to max_num.\n \"\"\"\n is_prime = [True] * (max_num + 1)\n p...
trial_gpt4o_4
{ "original_instruction": "", "prompt_id": "00036837", "row_id": 36837, "seed_ids": "[6830, 6196, 4955]" }
0.597573
Codeforces_36837
I
[ "nth_prime", "find_prime_in_table" ]
2
[ [ "find_prime_in_table", "nth_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
6a365be212a4dc6f9a4ed66c430201225599d7d9
6e7a80f5ca0df95b74d260b137ea0b60c95d7da8
v1.0
instruct
Codeforces
Codeforces_36850_I
The Kingdom of Magicland consists of a number of towns connected by bidirectional roads. Each town has a certain magical power associated with it. Two towns can either be directly connected by a road or connected through some intermediate towns. You are given the magical power of each town and the information about th...
def find_parent(parent, i): if parent[i] == i: return i else: parent[i] = find_parent(parent, parent[i]) return parent[i] def union(parent, rank, x, y): xroot = find_parent(parent, x) yroot = find_parent(parent, y) if rank[xroot] < rank[yroot]: parent[xroot] = y...
def test_max_magical_power_towns(): n, m = 5, 4 magical_powers = [1, 2, 3, 4, 5] roads = [(1, 2), (1, 3), (3, 4), (4, 5)] queries = [1, 3, 5] assert max_magical_power_towns(n, m, magical_powers, roads, queries) == [5, 5, 5] def test_max_magical_power_towns_single_node(): n, m = 1, 0 magical...
[ { "docstring": null, "function_declaration": "def find_parent(parent, i):", "function_name": "find_parent", "parameter_list": "(parent, i)" }, { "docstring": null, "function_declaration": "def union(parent, rank, x, y):", "function_name": "union", "parameter_list": "(parent, rank...
[ 1, 0 ]
1
medium
0.5
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def find_parent(parent, i):\n if parent[i] == i:\n return i\n else:\n parent[i] = find_parent(parent, parent[i])\n return parent[i]...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00036850", "row_id": 36850, "seed_ids": "[4122, 8073, 8072]" }
0.64857
Codeforces_36850
I
[ "find_parent", "union", "max_magical_power_towns" ]
3
[ [ "max_magical_power_towns", "find_parent" ], [ "max_magical_power_towns", "union" ], [ "union", "find_parent" ] ]
3
[]
false
[]
false
pytest
false
[]
true
468485b8a8db72f5acdad55a600d1fc1aa068d52
084fe8de6e39827bfa0f96cf26f6c6c87cac2916