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_36889_I | Tim's favorite hobby is playing with number sequences. Recently, he came across an interesting problem. He discovered that for any given positive integer $$$n$$$, if you keep adding the digits of $$$n$$$ until the number is reduced to a single digit, the result is always the same regardless of the initial value of $$$n... | def digital_root(n):
if n == 0:
return 0
else:
return 1 + (n - 1) % 9
def sum_of_digital_roots(test_cases):
results = []
for case in test_cases:
k, array = case
sum_dr = sum(digital_root(num) for num in array)
results.append(sum_dr)
return results
# Helper f... | def test_digital_root():
assert digital_root(16) == 7
assert digital_root(7) == 7
assert digital_root(28) == 1
assert digital_root(123) == 6
assert digital_root(45) == 9
assert digital_root(0) == 0
assert digital_root(9) == 9
assert digital_root(81) == 9
assert digital_root(100) == 1... | [
{
"docstring": null,
"function_declaration": "def digital_root(n):",
"function_name": "digital_root",
"parameter_list": "(n)"
},
{
"docstring": null,
"function_declaration": "def sum_of_digital_roots(test_cases):",
"function_name": "sum_of_digital_roots",
"parameter_list": "(test... | [
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 digital_root(n):\n \"\"\"\n Returns the digital root of a non-negative integer n.\n \"\"\"\n if n == 0:\n return 0\n else:\n ... | trial_gpt4o_4 | {
"original_instruction": "",
"prompt_id": "00036889",
"row_id": 36889,
"seed_ids": "[5062, 6221, 5357]"
} | 0.620217 | Codeforces_36889 | I | [
"digital_root",
"sum_of_digital_roots",
"process_input_output"
] | 3 | [
[
"process_input_output",
"sum_of_digital_roots"
],
[
"sum_of_digital_roots",
"digital_root"
]
] | 2 | [
"process_input_output"
] | false | [] | false | pytest | false | [] | true | cea7426ee2eb8ef8820203131b69413c4762e843 | 2624b2934608f793a33655a6fbdd2eb621ad0f49 | |||
v1.0 | instruct | Codeforces | Codeforces_36903_I | In the kingdom of ByteLand, there are **n** cities. These cities are connected by **n-1** two-way roads such that there is exactly one path between any pair of cities. The inhabitants of ByteLand are friendly and often like to visit each other.
You are tasked with building an efficient transportation system that minim... | import sys
from collections import defaultdict, deque
def find_farthest_city_and_distance(n, graph, start_city):
"""
Find the farthest city and its distance from the start_city using BFS.
"""
visited = [False] * (n + 1)
queue = deque([(start_city, 0)])
visited[start_city] = True
farthest_ci... | from solution import max_travel_time, process_input
def test_basic_case():
input_data = "2\n4\n1 2 4\n1 3 2\n3 4 3\n3\n1 2 5\n2 3 7\n"
t, test_cases = process_input(input_data)
results = max_travel_time(t, test_cases)
assert results == [9, 12]
def test_single_case_minimum_values():
input_data = "1... | [
{
"docstring": "Find the farthest city and its distance from the start_city using BFS.",
"function_declaration": "def find_farthest_city_and_distance(n, graph, start_city):",
"function_name": "find_farthest_city_and_distance",
"parameter_list": "(n, graph, start_city)"
},
{
"docstring": null... | [
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 sys\nfrom collections import defaultdict, deque\n\ndef find_farthest_city_and_distance(n, graph, start_city):\n \"\"\"\n Find the farthest city a... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00036903",
"row_id": 36903,
"seed_ids": "[2096, 2976, 3083]"
} | 0.777464 | Codeforces_36903 | I | [
"find_farthest_city_and_distance",
"max_travel_time",
"process_input",
"main"
] | 4 | [
[
"max_travel_time",
"find_farthest_city_and_distance"
]
] | 1 | [
"process_input"
] | false | [] | false | pytest | true | [] | true | 337059903fbcd67cc02bafc81c93b81d00368a47 | 859a15b713f810d8520d7da190386d4ed748e1c4 | |||
v1.0 | instruct | Codeforces | Codeforces_36928_I | Yuki loves palindromes. She especially adores numbers that are palindromes. One day, she came up with the idea of finding the smallest palindrome larger than a given number.
A number is said to be a palindrome if it reads the same forward and backward. For example, 121 and 1331 are palindromes, but 123 and 1321 are n... | def is_palindrome(num):
"""
Check if a number is a palindrome.
"""
return str(num) == str(num)[::-1]
def next_palindrome(n):
"""
Find the smallest palindrome greater than n.
"""
n += 1 # Start checking from the next number
while not is_palindrome(n):
n += 1
return n
de... | from solution import is_palindrome, next_palindrome, find_next_palindromes
def test_is_palindrome():
assert is_palindrome(121) == True
assert is_palindrome(12321) == True
assert is_palindrome(123) == False
assert is_palindrome(10) == False
def test_next_palindrome():
assert next_palindrome(123) ==... | [
{
"docstring": "Check if a number is a palindrome.",
"function_declaration": "def is_palindrome(num):",
"function_name": "is_palindrome",
"parameter_list": "(num)"
},
{
"docstring": "Find the smallest palindrome greater than n.",
"function_declaration": "def next_palindrome(n):",
"fu... | [
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 next_palindrome(n):\n \"\"\"\n Given a number n, find the smallest palindrome larger than n.\n \"\"\"\n def is_palindrome(num):\n s = s... | trial_gpt4o_4 | {
"original_instruction": "",
"prompt_id": "00036928",
"row_id": 36928,
"seed_ids": "[4015, 5905, 740]"
} | 0.769279 | Codeforces_36928 | I | [
"is_palindrome",
"next_palindrome",
"find_next_palindromes"
] | 3 | [
[
"find_next_palindromes",
"next_palindrome"
],
[
"next_palindrome",
"is_palindrome"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | e7868755ed41692f2037a2afe4051057a6299b4e | 023f4c666b05a84c494ece0ea32030d4aafbd025 | |||
v1.0 | instruct | Codeforces | Codeforces_36968_I | John is a computer science student who loves solving puzzles. He recently came across a puzzle that involved finding a special sequence of numbers. The sequence must be a permutation of numbers from 1 to n, such that the sum of any two adjacent numbers in the sequence is a prime number.
John decided to write a program... | def is_prime(num):
if num <= 1:
return False
if num <= 3:
return True
if num % 2 == 0 or num % 3 == 0:
return False
i = 5
while i * i <= num:
if num % i == 0 or num % (i + 2) == 0:
return False
i += 6
return True
def find_special_sequence(n):
... | def test_is_prime():
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(4) == False
assert is_prime(17) == True
assert is_prime(18) == False
def test_sum_pairs():
assert sum_pairs(4) == [2, 1, 4, 3]
assert sum_pairs(8) == [2, 1, 4, 3, 6, 5, 8, 7]
def test_find_special_se... | [
{
"docstring": null,
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": null,
"function_declaration": "def find_special_sequence(n):",
"function_name": "find_special_sequence",
"parameter_list": "(n)"
},
{
... | [
1,
1,
0
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(n):\n if n <= 1:\n return False\n if n <= 3:\n return True\n if n % 2 == 0 or n % 3 == 0:\n return False\n i = 5... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00036968",
"row_id": 36968,
"seed_ids": "[3761, 2871, 3221]"
} | 0.653126 | Codeforces_36968 | I | [
"is_prime",
"find_special_sequence",
"sum_pairs",
"solve"
] | 4 | [
[
"find_special_sequence",
"sum_pairs"
],
[
"solve",
"find_special_sequence"
]
] | 2 | [] | false | [] | false | pytest | false | [] | true | cdd711916f46077913e31582e18c1d44ea12e942 | febf2b8626f83611e27d9392c3e7028784645a09 | |||
v1.0 | instruct | Codeforces | Codeforces_37035_I | You are given an integer array and an integer k. You need to determine if you can partition the array into k non-empty subsets such that each subset's sum is equal.
The first line contains two integers n (1 ≤ n ≤ 16) — the number of elements in the array, and k (1 ≤ k ≤ 16) — the number of subsets.
The second line c... | from typing import List
def can_partition_k_subsets(nums: List[int], k: int) -> bool:
total_sum = sum(nums)
if total_sum % k != 0:
return False
target = total_sum // k
n = len(nums)
nums.sort(reverse=True)
buckets = [0] * k
def backtrack(index):
if index == n:
... | from solution import partition_possible
def test_partition_possible_yes():
assert partition_possible(4, 2, [4, 3, 2, 3]) == "YES"
def test_partition_possible_no():
assert partition_possible(4, 3, [4, 3, 2, 3]) == "NO"
def test_partition_possible_trivial_case():
assert partition_possible(1, 1, [1]) == "YE... | [
{
"docstring": null,
"function_declaration": "def can_partition_k_subsets(nums, k):",
"function_name": "can_partition_k_subsets",
"parameter_list": "(nums, k)"
},
{
"docstring": null,
"function_declaration": "def partition_possible(n, k, array):",
"function_name": "partition_possible... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def can_partition_k_subsets(nums, k):\n def can_partition(start, k, subset_sum, target, visited):\n if k == 0:\n return True\n if ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00037035",
"row_id": 37035,
"seed_ids": "[7716, 6521, 686]"
} | 0.644787 | Codeforces_37035 | I | [
"can_partition_k_subsets",
"partition_possible"
] | 2 | [
[
"partition_possible",
"can_partition_k_subsets"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 7ddf6d3678f162f516a329a7767d8fdc393a55be | 28347d476619df84352d9d856a767cca518be797 | |||
v1.0 | instruct | Codeforces | Codeforces_37056_I | The city of Graphland consists of $$$n$$$ cities and $$$m$$$ two-way roads. The mayor wants to evaluate the connectivity of the city under the assumption that some roads may be closed for maintenance. For this purpose, you are to determine how many connected components the city will be divided into if certain roads are... | from collections import defaultdict
def find_parent(parent, i):
if parent[i] == i:
return i
else:
return find_parent(parent, parent[i])
def union(parent, rank, x, y):
x_root = find_parent(parent, x)
y_root = find_parent(parent, y)
if x_root != y_root:
if rank[x_root] <... | def test_case_1():
n = 5
m = 4
roads = [(1, 2), (2, 3), (4, 5), (3, 5)]
q = 2
queries = [(2, [1, 2]), (1, [4])]
assert number_of_components(n, m, roads, q, queries) == [3, 2]
def test_case_2():
n = 6
m = 5
roads = [(1, 2), (2, 3), (3, 4), (4, 5), (5, 6)]
q = 1
queries = [(3,... | [
{
"docstring": null,
"function_declaration": "def find_parent(parent, i):",
"function_name": "find_parent",
"parameter_list": "(parent, i)"
},
{
"docstring": null,
"function_declaration": "def union(parent, rank, x, y):",
"function_name": "union",
"parameter_list": "(parent, rank... | [
0,
1,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from collections import defaultdict\n\nclass UnionFind:\n def __init__(self, size):\n self.parent = list(range(size))\n self.rank = [1] * siz... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00037056",
"row_id": 37056,
"seed_ids": "[3161, 2203, 499]"
} | 0.747727 | Codeforces_37056 | I | [
"find_parent",
"union",
"number_of_components"
] | 3 | [
[
"number_of_components",
"find_parent"
],
[
"number_of_components",
"union"
],
[
"union",
"find_parent"
]
] | 3 | [] | false | [] | false | pytest | false | [] | true | 88f8f0b8b6718693292efe0f7b1a5bda1bda31e3 | 7cd98e3a9c07aeae98f6f4c5608b354cc238889b | |||
v1.0 | instruct | Codeforces | Codeforces_37124_I | You are given a string $$$s$$$ consisting of lowercase letters and a number $$$k$$$.
Your task is to transform the string into a k-palindrome. A string is called k-palindrome if it can be divided into exactly $$$k$$$ contiguous non-empty parts where each part is a palindrome.
Determine if it's possible to transform ... | def is_palindrome(s):
"""
Check if a given string s is a palindrome.
"""
return s == s[::-1]
def can_form_k_palindrome(k, s):
"""
Check if the string s can be divided into k palindromic parts.
"""
n = len(s)
if k > n:
return "NO"
# dp[i][j] is True if s[i:j+1] is a ... | from solution import process
def test_simple_case():
assert process(3, [(2, 'aab'), (3, 'abcba'), (1, 'racecar')]) == ["YES", "YES", "YES"]
def test_single_character_string():
assert process(1, [(2, 'a')]) == ["NO"]
assert process(1, [(1, 'a')]) == ["YES"]
def test_all_same_characters():
assert proce... | [
{
"docstring": "Check if a given string s is a palindrome.",
"function_declaration": "def is_palindrome(s):",
"function_name": "is_palindrome",
"parameter_list": "(s)"
},
{
"docstring": "Check if the string s can be divided into k palindromic parts.",
"function_declaration": "def can_for... | [
0,
0,
0,
0,
1
] | 1 | hard | 0.2 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_palindrome(s):\n return s == s[::-1]\n\ndef k_palindrome_possible(t, test_cases):\n results = []\n for case in test_cases:\n k, s = cas... | trial_gpt4o_4 | {
"original_instruction": "",
"prompt_id": "00037124",
"row_id": 37124,
"seed_ids": "[1439, 3726, 736]"
} | 0.835042 | Codeforces_37124 | I | [
"is_palindrome",
"can_form_k_palindrome",
"process"
] | 3 | [
[
"process",
"can_form_k_palindrome"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | fe3b847beda0f589a6c089bcd7a07f78ff2b850b | e0015f65e300e884e62637487a28b976a2158c8e | |||
v1.0 | instruct | Codeforces | Codeforces_37133_I | You are given an n × n matrix filled with integers. Let's define a "magic square" as a subgrid of this matrix where the numbers in each row, each column, and both main diagonals all add up to the same constant, called the "magic constant."
Your task is to find the largest magic square subgrid in the given matrix. If t... | def is_magic_square(grid, row, col, size):
magic_sum = sum(grid[row][col:col+size])
# Check rows and columns
for i in range(size):
if sum(grid[row+i][col:col+size]) != magic_sum:
return False
if sum(grid[row+j][col+i] for j in range(size)) != magic_sum:
return Fa... | def test_magic_square_4x4():
matrix = [
[8, 1, 6, 3],
[3, 5, 7, 10],
[4, 9, 2, 8],
[11, 3, 6, 7]
]
assert get_largest_magic_square(4, matrix) == 3
def test_no_magic_square():
matrix = [
[5, 6, 1],
[2, 7, 8],
[3, 4, 9]
]
assert get_largest_... | [
{
"docstring": null,
"function_declaration": "def is_magic_square(grid, row, col, size):",
"function_name": "is_magic_square",
"parameter_list": "(grid, row, col, size)"
},
{
"docstring": null,
"function_declaration": "def largest_magic_square(matrix, n):",
"function_name": "largest_... | [
0,
0,
0,
0,
1
] | 1 | hard | 0.2 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_magic_square(grid, row, col, size):\n magic_sum = sum(grid[row][col:col+size])\n for i in range(size):\n if sum(grid[row + i][col:col + si... | trial_gpt4o_4 | {
"original_instruction": "",
"prompt_id": "00037133",
"row_id": 37133,
"seed_ids": "[2740, 5085, 6371]"
} | 0.604962 | Codeforces_37133 | I | [
"is_magic_square",
"largest_magic_square",
"get_largest_magic_square"
] | 3 | [
[
"get_largest_magic_square",
"largest_magic_square"
],
[
"largest_magic_square",
"is_magic_square"
]
] | 2 | [] | false | [] | false | pytest | false | [] | true | e2e98a1d4885c6bf67607c5d9834c0705e8261e1 | 0c2e672572bb4a2bf9a4fc6b8868c240c48e9565 | |||
v1.0 | instruct | Codeforces | Codeforces_37163_I | Given an array of integers, we define its beauty as the maximum possible sum of its contiguous subarray which has a length of at least one less than the length of the original array. You are to find the beauty of the array.
The first line contains a single integer n (2 ≤ n ≤ 5000), the length of the array.
The second ... | def max_subarray_sum(arr):
"""
Finds the maximum sum of any contiguous subarray of the given array
"""
max_ending_here = max_so_far = arr[0]
for x in arr[1:]:
max_ending_here = max(x, max_ending_here + x)
max_so_far = max(max_so_far, max_ending_here)
return max_so_far
def find_b... | def test_max_subarray_sum():
assert max_subarray_sum([1, -2, 3, 4, -5]) == 7
assert max_subarray_sum([-1, -2, -3, -4]) == -1
assert max_subarray_sum([5, 4, -1, 7, 8]) == 23
assert max_subarray_sum([1]) == 1
assert max_subarray_sum([1, 2, 3, 4]) == 10
def test_find_beauty():
assert find_beauty(5... | [
{
"docstring": "Finds the maximum sum of any contiguous subarray of the given array",
"function_declaration": "def max_subarray_sum(arr):",
"function_name": "max_subarray_sum",
"parameter_list": "(arr)"
},
{
"docstring": "Finds the beauty of the array, which is the maximum sum of any contigu... | [
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_beauty_of_array(arr):\n \"\"\"\n Finds the beauty of the array, defined as the maximum possible \n sum of its contiguous subarray which has ... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00037163",
"row_id": 37163,
"seed_ids": "[6269, 7062, 3025]"
} | 0.759408 | Codeforces_37163 | I | [
"max_subarray_sum",
"find_beauty"
] | 2 | [
[
"find_beauty",
"max_subarray_sum"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | 494f0b74e1982e10bcc2cb7d159ed8327a77bfff | c4d128f833b9580fe13df40ce3f556fa28cc6ff3 | |||
v1.0 | instruct | Codeforces | Codeforces_37195_I | In a city, there are n intersections and m roads connecting them. Each road is bi-directional and has a certain length. The city council wants to monitor the traffic and reduce congestion by imposing a toll on certain roads. Your task is to determine the total length of roads on which tolls can be imposed for a series ... | def total_road_lengths(n, m, roads, q, toll_schemes):
"""
Calculate the total length of roads for each toll scheme.
Parameters:
n (int): Number of intersections
m (int): Number of roads
roads (list of tuples): List containing tuples with road informations (u, v, l)
q (in... | import pytest
from solution import total_road_lengths, solve
def test_total_road_lengths():
n = 5
m = 5
roads = [(1, 2, 10), (2, 3, 20), (4, 5, 40), (3, 5, 30), (1, 4, 50)]
q = 3
toll_schemes = [(1, 3), (2, 5), (1, 5)]
expected = [70, 140, 150]
assert total_road_lengths(n, m, roads, q,... | [
{
"docstring": "Calculate the total length of roads for each toll scheme.\n\nParameters:\n n (int): Number of intersections\n m (int): Number of roads\n roads (list of tuples): List containing tuples with road informations (u, v, l)\n q (int): Number of toll schemes\n toll_schemes (list of tuples... | [
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 calculate_length_of_roads(n, m, roads, q, schemes):\n \"\"\"\n Calculates the total length of roads included in each toll scheme.\n \n Paramet... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00037195",
"row_id": 37195,
"seed_ids": "[3946, 2428, 7936]"
} | 0.748878 | Codeforces_37195 | I | [
"total_road_lengths",
"solve"
] | 2 | [
[
"solve",
"total_road_lengths"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | e9692f51bf0ede2b1f6072ab0127e8e9af3934ad | 76da242a116f194e3d4c46a781b14772622eb144 | |||
v1.0 | instruct | Codeforces | Codeforces_37205_I | The kingdom of Arithmania is famous for its elaborate encryption methods. The king has devised a particularly intriguing encryption algorithm based on the properties of prime numbers.
Given an integer `n`, the encryption algorithm involves the following steps:
1. Find all prime numbers less than or equal to `n`.
2. Fo... | def is_prime(num):
"""
Return True if `num` is a prime number, otherwise False.
"""
if num < 2:
return False
for i in range(2, int(num**0.5) + 1):
if num % i == 0:
return False
return True
def generate_prime_sequences(n):
"""
Generate sequences for all prime ... | def test_is_prime():
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(4) == False
assert is_prime(5) == True
assert is_prime(10) == False
assert is_prime(11) == True
def test_generate_prime_sequences():
assert generate_prime_sequences(10) == [[2, 4, 6, 8, 10], [3, 6, 9]... | [
{
"docstring": "Return True if `num` is a prime number, otherwise False.",
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": "Generate sequences for all prime numbers up to and including `n`.",
"function_declaration": "... | [
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 generate_prime_sequences(n):\n def is_prime(num):\n if num < 2:\n return False\n for i in range(2, int(num**0.5) + 1):\n ... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00037205",
"row_id": 37205,
"seed_ids": "[6920, 5932, 2339]"
} | 0.569875 | Codeforces_37205 | I | [
"is_prime",
"generate_prime_sequences",
"format_prime_sequences"
] | 3 | [
[
"format_prime_sequences",
"generate_prime_sequences"
],
[
"generate_prime_sequences",
"is_prime"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | a43f503c037b160184e64294fcdfbdc89b11599e | e13bf2b6bc13e0832a46f4de8864ad5985aef889 | |||
v1.0 | instruct | Codeforces | Codeforces_37282_I | In a kingdom, there are n cities connected by m roads. Each road has a toll. The king wants to upgrade the kingdom's road network by minimizing the toll cost to travel between the cities. If you are given the layout of the cities and the roads between them, determine the minimum cost required to connect all the cities.... | 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... | import pytest
from solution import min_cost_to_connect_cities
def test_example_1():
n = 4
m = 5
roads = [
(1, 2, 1),
(1, 3, 3),
(4, 1, 4),
(2, 3, 2),
(3, 4, 5)
]
assert min_cost_to_connect_cities(n, m, roads) == 7
def test_example_2():
n = 3
m = 1
... | [
{
"docstring": null,
"function_declaration": "def find(parent, i):",
"function_name": "find",
"parameter_list": "(parent, i)"
},
{
"docstring": null,
"function_declaration": "def union(parent, rank, x, y):",
"function_name": "union",
"parameter_list": "(parent, rank, x, y)"
},
... | [
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 UnionFind:\n def __init__(self, n):\n self.parent = list(range(n))\n self.rank = [0] * n\n\n def find(self, u):\n if self.par... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00037282",
"row_id": 37282,
"seed_ids": "[421, 3255, 4578]"
} | 0.658694 | Codeforces_37282 | I | [
"find",
"union",
"kruskal",
"min_cost_to_connect_cities"
] | 4 | [
[
"kruskal",
"find"
],
[
"kruskal",
"union"
],
[
"min_cost_to_connect_cities",
"kruskal"
],
[
"union",
"find"
]
] | 4 | [] | false | [] | false | pytest | true | [] | true | 749f0cd666e80db8bc858a28d55f3db053c954db | 9fa8db74497e055e2ade6fa60e4af287e58129df | |||
v1.0 | instruct | Codeforces | Codeforces_37366_I | Tarun is learning about matrix operations and has come across the concept of matrix exponentiation. He is particularly interested in computing the power of a square matrix. Given a square matrix A of size n and a positive integer k, the k-th power of the matrix A is defined as multiplying the matrix A by itself k times... | MOD = 10**9 + 7
def matrix_mult(A, B, n):
result = [[0] * n for _ in range(n)]
for i in range(n):
for j in range(n):
for k in range(n):
result[i][j] = (result[i][j] + A[i][k] * B[k][j]) % MOD
return result
def matrix_pow(A, k, n):
result = [[1 if i == j else 0 for j... | from solution import matrix_mult, matrix_pow, compute_matrix_power
def test_matrix_mult():
A = [[1, 1], [1, 0]]
B = [[1, 1], [1, 0]]
expected = [[2, 1], [1, 1]]
assert matrix_mult(A, B, 2) == expected
def test_matrix_pow():
A = [[1, 1], [1, 0]]
expected = [[2, 1], [1, 1]]
assert matrix_pow... | [
{
"docstring": null,
"function_declaration": "def matrix_mult(A, B, n):",
"function_name": "matrix_mult",
"parameter_list": "(A, B, n)"
},
{
"docstring": null,
"function_declaration": "def matrix_pow(A, k, n):",
"function_name": "matrix_pow",
"parameter_list": "(A, k, 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": "MOD = 10**9 + 7\n\ndef matrix_mult(A, B, n):\n \"\"\"Multiplies two matrices A and B of size n and returns the resulting matrix modulo 10^9 + 7.\"\"\"\n ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00037366",
"row_id": 37366,
"seed_ids": "[6793, 4008, 1365]"
} | 0.497724 | Codeforces_37366 | I | [
"matrix_mult",
"matrix_pow",
"compute_matrix_power",
"main"
] | 4 | [
[
"compute_matrix_power",
"matrix_pow"
],
[
"matrix_pow",
"matrix_mult"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 0fa59210cbe1e71fb35f612fca787259db20dd9b | 49325c58b0f939382522fa36077dbd6721faccc8 | |||
v1.0 | instruct | Codeforces | Codeforces_37367_I | You are given a rectangular grid of dimensions n x m. Each cell in the grid is either a land cell or a water cell. The grid can be represented as a matrix of characters where 'L' indicates a land cell and 'W' indicates a water cell.
You need to determine the largest rectangular area composed entirely of land cells ('L... | def maximalRectangle(grid):
if not grid:
return 0
n, m = len(grid), len(grid[0])
height = [0] * m
max_area = 0
for i in range(n):
for j in range(m):
# Update the height array; reset to 0 if the cell is 'W'
if grid[i][j] == 'L':
height... | from solution import maximalRectangle
def test_single_cell_land():
assert maximalRectangle([['L']]) == 1
def test_single_cell_water():
assert maximalRectangle([['W']]) == 0
def test_rectangular_grid_all_land():
grid = [
['L', 'L', 'L'],
['L', 'L', 'L'],
['L', 'L', 'L']
]
a... | [
{
"docstring": null,
"function_declaration": "def maximalRectangle(grid):",
"function_name": "maximalRectangle",
"parameter_list": "(grid)"
},
{
"docstring": null,
"function_declaration": "def largestRectangleArea(heights):",
"function_name": "largestRectangleArea",
"parameter_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 maximalRectangle(grid):\n if not grid:\n return 0\n \n n, m = len(grid), len(grid[0])\n height = [0] * m\n max_area = 0\n \n f... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00037367",
"row_id": 37367,
"seed_ids": "[4484, 3613, 6065]"
} | 0.722204 | Codeforces_37367 | I | [
"maximalRectangle",
"largestRectangleArea"
] | 2 | [
[
"maximalRectangle",
"largestRectangleArea"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 163c3faa422cf3f3d561ff1dc9a8bd23a684164c | 9286c76bc04b64a8f0c3763a95c895c5237893dc | |||
v1.0 | instruct | Codeforces | Codeforces_37396_I | Mary is building a new home and she decided to decorate the walls with some colorful tiling. She has a row of wall segments of length m which she wants to cover using color tiles. She has multiple types of color tiles available, each of a certain length and color.
Her goal is to use exactly n tiles to cover the entire... | def can_cover_wall(m, n, t, c):
"""
Determines if it's possible to cover a wall of length m using exactly n tiles
such that no two adjacent tiles have the same color.
"""
def backtrack(index, current_length, last_color, arrangement):
if current_length == m and index == n:
return ... | from solution import solve
def test_solve_possible_case():
assert solve(12, 4, [3, 3, 4, 5], ["RED", "BLUE", "BLUE", "GREEN"]).startswith("YES")
def test_solve_not_possible_case():
assert solve(10, 2, [5, 5], ["RED", "RED"]) == "NO"
def test_solve_single_tile_exact_fit():
assert solve(5, 1, [5], ["RED"])... | [
{
"docstring": "Determines if it's possible to cover a wall of length m using exactly n tiles\nsuch that no two adjacent tiles have the same color.",
"function_declaration": "def can_cover_wall(m, n, t, c):",
"function_name": "can_cover_wall",
"parameter_list": "(m, n, t, c)"
},
{
"docstring... | [
0,
0,
0,
0,
0,
1,
0,
0,
0,
0
] | 1 | hard | 0.1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def colorful_tiling(m, n, t, c):\n \"\"\"\n Determines if it's possible to cover a wall of length m with n tiles such that no two adjacent tiles are of ... | trial_gpt4o_5 | {
"original_instruction": "",
"prompt_id": "00037396",
"row_id": 37396,
"seed_ids": "[16, 7281, 1797]"
} | 0.73098 | Codeforces_37396 | I | [
"can_cover_wall",
"solve"
] | 2 | [
[
"solve",
"can_cover_wall"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 519a02260a79abf07490dae445797f38615603d0 | efa87a021d388892ca403e2c1e1e28f5d878b8dc | |||
v1.0 | instruct | Codeforces | Codeforces_37416_I | In the bustling city of Graphonia, Mayor Edgefield has launched a new public transportation system. The city consists of an undirected graph with n nodes and m edges. Each edge represents a bidirectional road between two intersections (nodes). Every edge has a weight (ti), representing the travel time across that road.... | import heapq
def dijkstra(n, m, s, edges):
graph = [[] for _ in range(n + 1)]
for u, v, t in edges:
graph[u].append((v, t))
graph[v].append((u, t))
distances = [float('inf')] * (n + 1)
distances[s] = 0
priority_queue = [(0, s)]
while priority_queue:
current_dis... | def test_shortest_travel_time():
n, m, s = 6, 9, 1
edges = [
(1, 2, 7), (1, 3, 9), (1, 6, 14),
(2, 3, 10), (2, 4, 15), (3, 4, 11),
(3, 6, 2), (4, 5, 6), (5, 6, 9)
]
expected_output = [0, 7, 9, 20, 20, 11]
assert shortest_travel_time(n, m, s, edges) == expected_output
def tes... | [
{
"docstring": null,
"function_declaration": "def dijkstra(n, m, s, edges):",
"function_name": "dijkstra",
"parameter_list": "(n, m, s, edges)"
},
{
"docstring": null,
"function_declaration": "def shortest_travel_time(n, m, s, edges):",
"function_name": "shortest_travel_time",
"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 heapq\n\ndef dijkstra(n, m, s, edges):\n graph = [[] for _ in range(n + 1)]\n for u, v, t in edges:\n graph[u].append((v, t))\n gra... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00037416",
"row_id": 37416,
"seed_ids": "[4385, 2081, 4725]"
} | 0.754741 | Codeforces_37416 | I | [
"dijkstra",
"shortest_travel_time"
] | 2 | [
[
"shortest_travel_time",
"dijkstra"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | 45f580e57ae6bcc402da7878a6f5999bdf6baca6 | 2da81f7342a78e09c10a701d5396f35dfe72e188 | |||
v1.0 | instruct | Codeforces | Codeforces_37484_I | A company wants to assign desks to the employees in their new office space. The office is represented as an M x N grid. Some of the cells in the grid contain obstacles (like pillars or other furniture), and employees cannot be assigned to these cells. The company wants to place employees in such a way that no two adjac... | def assign_desks(grid, M, N):
result = [list(row) for row in grid]
def can_place(i, j):
if result[i][j] != '.': # Can't place on obstacles or other employees
return False
if i > 0 and result[i-1][j] == 'E': # Check above
return False
if j > 0 and result[i][j-1]... | import pytest
from solution import assign_desks
def test_case1():
M, N = 4, 5
layout = [
".....",
".#.#.",
".....",
"..#.."
]
result = assign_desks(layout, M, N)
assert 'E' in result and result != "Not Possible"
def test_case2():
M, N = 3, 3
layout = [
... | [
{
"docstring": null,
"function_declaration": "def assign_desks(grid, M, N):",
"function_name": "assign_desks",
"parameter_list": "(grid, M, N)"
},
{
"docstring": null,
"function_declaration": "def test_assign_desks():",
"function_name": "test_assign_desks",
"parameter_list": "()"... | [
0,
0,
0,
0,
0,
0,
0,
0,
1,
0
] | 1 | hard | 0.1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def assign_desks(M, N, grid):\n def can_place_employee(r, c):\n # Check if we can place an employee at the given cell\n if grid[r][c] != '.':... | trial_gpt4o_8 | {
"original_instruction": "",
"prompt_id": "00037484",
"row_id": 37484,
"seed_ids": "[2940, 7208, 2230]"
} | 0.736439 | Codeforces_37484 | I | [
"assign_desks",
"test_assign_desks"
] | 2 | [
[
"test_assign_desks",
"assign_desks"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 4cc7b1728a0ecf44394f7741f57518b3b084a696 | 56c9cb1d0d616153f6c4f5939c0369d8e8b437ba | |||
v1.0 | instruct | Codeforces | Codeforces_37535_I | You are given a list of programming contest problems and their difficulty levels. Each problem has a unique identifier, a difficulty rating, and a list of tags that describe the topics it covers (e.g., "dp", "graphs", "math").
Your task is to generate a balanced contest set, consisting of 5 problems, with the followi... | from itertools import combinations
def can_select_problems(problems):
difficulties = [(1,3), (4,6), (7,9), (10,12)]
for comb in combinations(problems, 5):
if all(any(low <= prob['difficulty'] <= high for prob in comb) for (low, high) in difficulties):
tags = set()
for prob in co... | def test_generate_contest_example_case():
input_str = """6
p1 4 dp,graphs
p2 6 math,geometry
p3 7 strings
p4 2 sorting,search
p5 10 bitmasks
p6 11 trees,graphs"""
result = generate_contest(input_str)
expected_result = ['p1', 'p2', 'p3', 'p4', 'p5']
assert sorted(result) == sorted(expected_result) or res... | [
{
"docstring": null,
"function_declaration": "def can_select_problems(problems):",
"function_name": "can_select_problems",
"parameter_list": "(problems)"
},
{
"docstring": null,
"function_declaration": "def find_optimal_contest(problems):",
"function_name": "find_optimal_contest",
... | [
0,
1
] | 1 | medium | 0.5 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from itertools import combinations\n\ndef is_valid_set(problems):\n difficulties = [p[1] for p in problems]\n tags = set()\n \n ranges = [False, F... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00037535",
"row_id": 37535,
"seed_ids": "[4942, 2115, 2699]"
} | 0.683009 | Codeforces_37535 | I | [
"can_select_problems",
"find_optimal_contest",
"process_input",
"generate_contest"
] | 4 | [
[
"find_optimal_contest",
"can_select_problems"
],
[
"generate_contest",
"find_optimal_contest"
],
[
"generate_contest",
"process_input"
]
] | 3 | [
"process_input"
] | false | [] | false | pytest | false | [] | true | e0749ce03be5d90e45d67bd214f9be98c344fc57 | 20772b8658c460a923b03208125580183abb606f | |||
v1.0 | instruct | Codeforces | Codeforces_37551_I | A rising star athlete downloaded an app that records her training and competition results over the year. For each of her training sessions or competitions, the app records the date (in `YYYY-MM-DD` format) and her performance, quantified as an integer representing points scored.
The athlete wants to analyze her progre... | def parse_input(input_string):
lines = input_string.strip().split('\n')
n = int(lines[0])
performance_data = {}
for i in range(1, n + 1):
date, points = lines[i].split()
performance_data[date] = int(points)
m = int(lines[n + 1])
queries = []
for i in range(n + 2, n + 2 +... | def test_analyze_performance():
input_string = '''5
2023-01-01 10
2023-01-05 20
2023-02-01 15
2023-02-10 10
2023-02-15 5
3
2023-01-01 2023-01-31
2023-02-01 2023-02-28
2023-01-01 2023-02-28'''
expected_output = [30, 30, 60]
assert analyze_performance(input_string) == expected_output
def test_analyze_perform... | [
{
"docstring": null,
"function_declaration": "def parse_input(input_string):",
"function_name": "parse_input",
"parameter_list": "(input_string)"
},
{
"docstring": null,
"function_declaration": "def calculate_points(performance_data, queries):",
"function_name": "calculate_points",
... | [
1,
1,
0
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def parse_input(input_string):\n lines = input_string.strip().split('\\n')\n n = int(lines[0])\n performance_data = {}\n for i in range(1, n + 1):... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00037551",
"row_id": 37551,
"seed_ids": "[8022, 1623, 7545]"
} | 0.594864 | Codeforces_37551 | I | [
"parse_input",
"calculate_points",
"analyze_performance"
] | 3 | [
[
"analyze_performance",
"calculate_points"
],
[
"analyze_performance",
"parse_input"
]
] | 2 | [
"parse_input"
] | false | [] | false | pytest | false | [] | true | 3580a9dcf4cfe39b8cc601042a786d8a30083d8c | b0268ed026b5a9438875b8e8b7f9e549d601ddb1 | |||
v1.0 | instruct | Codeforces | Codeforces_37594_I | Fran loves to play with numbers, and his favorite pastime is finding interesting sequences. One day, he discovered a new type of sequence which he calls the "self-dividing sequence". A number is considered self-dividing if it is divisible by all its digits.
For example, the number 128 is self-dividing because 128 % 1... | def is_self_dividing(num):
original_num = num
while num > 0:
digit = num % 10
if digit == 0 or original_num % digit != 0:
return False
num //= 10
return True
def self_dividing_numbers(left, right):
result = []
for num in range(left, right + 1):
if is_self... | from solution import is_self_dividing, self_dividing_numbers
def test_is_self_dividing():
assert is_self_dividing(128) == True
assert is_self_dividing(12) == True
assert is_self_dividing(15) == True
assert is_self_dividing(120) == False # contains 0
assert is_self_dividing(130) == False # contain... | [
{
"docstring": null,
"function_declaration": "def is_self_dividing(num):",
"function_name": "is_self_dividing",
"parameter_list": "(num)"
},
{
"docstring": null,
"function_declaration": "def self_dividing_numbers(left, right):",
"function_name": "self_dividing_numbers",
"paramete... | [
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_self_dividing(num):\n original_num = num\n while num > 0:\n digit = num % 10\n if digit == 0 or original_num % digit != 0:\n ... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00037594",
"row_id": 37594,
"seed_ids": "[1284, 2047, 7535]"
} | 0.635432 | Codeforces_37594 | I | [
"is_self_dividing",
"self_dividing_numbers"
] | 2 | [
[
"self_dividing_numbers",
"is_self_dividing"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 84862affc3adbb220e69eeaac50317e9605bcccd | 28db74c6e74404d3008c9cd91cdb70d97be6150e | |||
v1.0 | instruct | Codeforces | Codeforces_37597_I | You are tasked with creating a new variant of a popular puzzle game called "Block Shift". In this game, a 2D grid of cells is given, each containing a single integer. The goal of the game is to shift the rows and columns of the grid such that all integers in each row and each column are unique.
You have to implement a... | def is_unique_collection(collection):
"""
Helper function to check if all elements in the collection are unique.
"""
return len(collection) == len(set(collection))
def can_rearrange_to_unique(n, grid):
"""
Function to determine if the grid can be rearranged such that each row and column has uni... | from solution import solve_block_shift
def test_solve_block_shift_possible():
grid = [
[1, 2, 3],
[3, 1, 2],
[2, 3, 1]
]
# Redirect output
import io
import sys
captured_output = io.StringIO()
sys.stdout = captured_output
solve_block_shift(3, grid)
sys.stdout ... | [
{
"docstring": "Helper function to check if all elements in the collection are unique.",
"function_declaration": "def is_unique_collection(collection):",
"function_name": "is_unique_collection",
"parameter_list": "(collection)"
},
{
"docstring": "Function to determine if the grid can be rear... | [
1,
1,
0
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_possible_to_rearrange(grid):\n n = len(grid)\n \n # Check unique values in each row\n for row in grid:\n if len(set(row)) != n:\n ... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00037597",
"row_id": 37597,
"seed_ids": "[6523, 3104, 4552]"
} | 0.707217 | Codeforces_37597 | I | [
"is_unique_collection",
"can_rearrange_to_unique",
"solve_block_shift"
] | 3 | [
[
"can_rearrange_to_unique",
"is_unique_collection"
],
[
"solve_block_shift",
"can_rearrange_to_unique"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | bbcadf446756f2c0a339829f1c917853f887dcf7 | 5174b6ca290f9b571641c93b234d9fa4e51724b5 | |||
v1.0 | instruct | Codeforces | Codeforces_37628_I | Vasya is a student in a university that has a peculiar configuration of rooms. The university has 'n' rooms and there are several corridors connecting pairs of rooms. Vasya is in room '1' and he wants to reach room 'n'. The problem is that the university has specific rules for moving from one room to another.
Each cor... | import heapq
def find_min_cost(n, m, corridors):
graph = {i: [] for i in range(1, n + 1)}
for a, b, c, d in corridors:
graph[a].append((b, c))
graph[b].append((a, d))
# Dijkstra's Algorithm
pq = [(0, 1)] # (cost, node)
dist = {i: float('inf') for i in range(1, n + 1)}
dist... | from solution import find_min_cost
def test_basic_case():
n = 5
m = 6
corridors = [
(1, 2, 5, 10),
(1, 3, 10, 5),
(2, 4, 2, 3),
(3, 4, 3, 2),
(4, 5, 1, 1),
(3, 5, 8, 8)
]
assert find_min_cost(n, m, corridors) == 8
def test_no_path():
n = 3
m ... | [
{
"docstring": null,
"function_declaration": "def find_min_cost(n, m, corridors):",
"function_name": "find_min_cost",
"parameter_list": "(n, m, corridors)"
},
{
"docstring": null,
"function_declaration": "def example_usage():",
"function_name": "example_usage",
"parameter_list": ... | [
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_min_cost(n, m, corridors):\n graph = {i: [] for i in range(1, n + 1)}\n for a, b, c, d in corridors:\n graph[a].append((... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00037628",
"row_id": 37628,
"seed_ids": "[5504, 5857, 2107]"
} | 0.710855 | Codeforces_37628 | I | [
"find_min_cost",
"example_usage"
] | 2 | [
[
"example_usage",
"find_min_cost"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 24258e861a39bf338533f9cbba4b2aaf11a034d2 | a3c2e84af338fcdef077f05b9ba78f4d09c3c0d3 | |||
v1.0 | instruct | Codeforces | Codeforces_37676_I | You are given an undirected graph with n nodes and m edges. Each edge has a weight associated with it. The weight of a path in the graph is the sum of the weights of the edges in the path. Your task is to find and print the maximum possible weight of any path in this graph.
You are guaranteed that the graph is connect... | from heapq import heappush, heappop
def prims_maximum_spanning_tree(n, edges):
# Convert the graph to adjacency list
graph = {i: [] for i in range(1, n+1)}
for u, v, w in edges:
graph[u].append((v, w))
graph[v].append((u, w))
vis = [False] * (n + 1)
max_weight = 0
max_heap = [(... | from solution import maximum_path_weight
def test_example():
n, m = 4, 5
edges = [
(1, 2, 3),
(2, 3, 4),
(3, 4, 5),
(1, 4, 1),
(2, 4, 2)
]
assert maximum_path_weight(n, m, edges) == 12
def test_single_edge():
n, m = 2, 1
edges = [
(1, 2, 5)
]... | [
{
"docstring": null,
"function_declaration": "def prims_maximum_spanning_tree(n, edges):",
"function_name": "prims_maximum_spanning_tree",
"parameter_list": "(n, edges)"
},
{
"docstring": null,
"function_declaration": "def maximum_path_weight(n, m, edge_list):",
"function_name": "max... | [
0,
0,
0,
0,
0,
0,
1,
0,
0,
0
] | 1 | hard | 0.1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def maximum_path_weight(n, m, edges):\n from collections import defaultdict, deque\n\n graph = defaultdict(list)\n for u, v, w in edges:\n gra... | trial_gpt4o_6 | {
"original_instruction": "",
"prompt_id": "00037676",
"row_id": 37676,
"seed_ids": "[6626, 1856, 2694]"
} | 0.794741 | Codeforces_37676 | I | [
"prims_maximum_spanning_tree",
"maximum_path_weight"
] | 2 | [
[
"maximum_path_weight",
"prims_maximum_spanning_tree"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 6cb5f9d634cc29030497ebd616f6304a9b0cfb5a | ee0ed2bef5b98f75db8c01781280d8512cff3d77 | |||
v1.0 | instruct | Codeforces | Codeforces_37679_I | Alyssa loves to play the game "Word Morph". In this game, she is given a starting word and a target word, both of which have the same length. The only allowed move in the game is to change exactly one letter from the current word to transform it into another valid word, where a valid word is one that can be found in a ... | from collections import deque
def is_one_letter_difference(word1, word2):
"""
Helper function to check if two words differ by exactly one letter.
"""
count = 0
for a, b in zip(word1, word2):
if a != b:
count += 1
if count > 1:
return False
return count ==... | import pytest
from solution import min_word_morph
def test_example_case():
start_word = "hit"
target_word = "cog"
dict_words = ["hot", "dot", "dog", "lot", "log", "cog"]
assert min_word_morph(start_word, target_word, dict_words) == 4
def test_no_possible_transformation():
start_word = "hit"
ta... | [
{
"docstring": "Helper function to check if two words differ by exactly one letter.",
"function_declaration": "def is_one_letter_difference(word1, word2):",
"function_name": "is_one_letter_difference",
"parameter_list": "(word1, word2)"
},
{
"docstring": "Returns the minimum number of moves ... | [
0,
0,
0,
1,
0
] | 1 | hard | 0.2 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from collections import deque\n\ndef word_ladder(start, target, dictionary):\n if start == target:\n return 0\n \n word_set = set(dictiona... | trial_gpt4o_3 | {
"original_instruction": "",
"prompt_id": "00037679",
"row_id": 37679,
"seed_ids": "[3450, 3090, 1843]"
} | 0.640221 | Codeforces_37679 | I | [
"is_one_letter_difference",
"min_word_morph"
] | 2 | [
[
"min_word_morph",
"is_one_letter_difference"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | f220336cd783b96aabd05d1b51e80cc1fb9ea706 | ebc375a6aa89504013bb5ee94e9a1e75f13e71d4 | |||
v1.0 | instruct | Codeforces | Codeforces_37720_I | Sophia is passionate about creating perfect balanced binary search trees (BST) for her data structure project. Given an array of distinct integers, she wants to convert it into a balanced BST. A balanced BST is defined as a binary tree in which the height of the two subtrees of every node never differs by more than one... | class TreeNode:
"""
Node of a binary search tree.
"""
def __init__(self, key):
self.left = None
self.right = None
self.val = key
def sorted_array_to_bst(arr):
"""
Function to convert sorted array to a balanced BST and return the root node.
"""
if not arr:
... | def test_bst_height_from_sorted_array():
assert bst_height_from_sorted_array(7, [1, 2, 3, 4, 5, 6, 7]) == 2
assert bst_height_from_sorted_array(3, [10, 20, 30]) == 1
assert bst_height_from_sorted_array(1, [42]) == 0
assert bst_height_from_sorted_array(0, []) == -1
assert bst_height_from_sorted_array... | [] | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl",
"solution_code": "class TreeNode:\n def __init__(self, val=0, left=None, right=None):\n self.val = val\n self.left = left\n self.right = right\n\ndef so... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00037720",
"row_id": 37720,
"seed_ids": "[4861, 3432, 7611]"
} | 0.632561 | Codeforces_37720 | I | [
"sorted_array_to_bst",
"height_of_bst",
"bst_height_from_sorted_array"
] | 3 | [
[
"bst_height_from_sorted_array",
"height_of_bst"
],
[
"bst_height_from_sorted_array",
"sorted_array_to_bst"
]
] | 2 | [] | false | [
"TreeNode"
] | true | pytest | false | [] | true | bb596162da893dd33da15c430d7813c8e636b6e4 | d67f8c6948cdfdd3d92c3ae3572892afbb0ed369 | |||
v1.0 | instruct | Codeforces | Codeforces_37754_I | A group of neighbors are planning a community garden with n plots arranged in a straight line, where each plot can either contain a flower or be empty. They want to grow flowers in such a way that the beauty score of the garden is maximized. The beauty score is calculated as the total number of flowers multiplied by th... | def calculate_beauty(plan):
"""
Calculate the beauty score of a garden plan.
:param plan: A string representing the garden plan.
:return: An integer representing the beauty score.
"""
num_flowers = plan.count('F')
if num_flowers == 0:
return 0
max_consecutive = 0
curren... | from solution import best_garden_plan
def test_best_garden_plan_example():
assert best_garden_plan(5, 3, ["EFFFE", "FFFFE", "EEFEE"]) == "FFFFE"
def test_best_garden_plan_single_plan():
assert best_garden_plan(5, 1, ["EFFFE"]) == "EFFFE"
def test_best_garden_plan_identical_scores():
assert best_garden_pl... | [
{
"docstring": "Calculate the beauty score of a garden plan.\n\n:param plan: A string representing the garden plan.\n:return: An integer representing the beauty score.",
"function_declaration": "def calculate_beauty(plan):",
"function_name": "calculate_beauty",
"parameter_list": "(plan)"
},
{
... | [
0,
0,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def calculate_beauty_score(garden_plan):\n flowers_count = garden_plan.count('F')\n max_consecutive_flowers = max(map(len, garden_plan.split('E')))\n ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00037754",
"row_id": 37754,
"seed_ids": "[837, 7891, 5956]"
} | 0.590242 | Codeforces_37754 | I | [
"calculate_beauty",
"best_garden_plan"
] | 2 | [
[
"best_garden_plan",
"calculate_beauty"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 93fb79354de38c668702aa771b8d9f1aeab50952 | 9f111a756ed32674bba8ca5b8637dbdd8b192603 | |||
v1.0 | instruct | Codeforces | Codeforces_37837_I | In Ancient Byteland, there exist several mystical trees. Each mystical tree has exactly \( n \) nodes and \( n-1 \) edges and is undirected. The nodes are numbered from \( 1 \) to \( n \).
A tree is special if and only if for every pair of nodes \( u \) and \( v \) the distance between them (the number of edges in the... | def is_special_tree(n):
"""
Determine if a tree with n nodes is special and return its edges if it is.
A tree is special if and only if for every pair of nodes u and v the distance
between them is even.
Args:
n (int): The number of nodes in the tree.
Returns:
tuple: ("YES", edges)... | from solution import is_special_tree, solve
def test_is_special_tree():
assert is_special_tree(1) == ("NO", [])
assert is_special_tree(2) == ("YES", [(1, 2)])
assert is_special_tree(3) == ("NO", [])
assert is_special_tree(4) == ("YES", [(1, 2), (2, 3), (3, 4)])
assert is_special_tree(5) == ("NO", [... | [
{
"docstring": "Determine if a tree with n nodes is special and return its edges if it is.\n\nA tree is special if and only if for every pair of nodes u and v the distance\nbetween them is even.\n\nArgs:\nn (int): The number of nodes in the tree.\n\nReturns:\ntuple: (\"YES\", edges) if the tree is special, othe... | [
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_special_tree_possible(n):\n \"\"\"\n Determines if a special tree with n nodes is possible.\n A tree is special if the distance between every ... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00037837",
"row_id": 37837,
"seed_ids": "[7682, 7632, 984]"
} | 0.730123 | Codeforces_37837 | I | [
"is_special_tree",
"solve"
] | 2 | [
[
"solve",
"is_special_tree"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 54eb4bc2d49f449c166c03e1699c7914d7a27ba8 | 2dca2b45d1fc64dfa4447c53bfb79d2d542d224c | |||
v1.0 | instruct | Codeforces | Codeforces_37882_I | You are given an array of integers. Each element in the array represents the number of minutes a student takes to complete a specific task. The task times are not sorted and may vary significantly. Your goal is to divide the students into two groups such that the difference between the total task time for each group is... | def find_min_difference(task_times):
total_sum = sum(task_times)
n = len(task_times)
half_sum = total_sum // 2
dp = [[False] * (half_sum + 1) for _ in range(n + 1)]
for i in range(n + 1):
dp[i][0] = True
for i in range(1, n + 1):
for j in range(1, half_sum + 1):
if ... | def test_min_difference_case1():
assert minimum_possible_difference(5, [1, 3, 4, 3, 2]) == 1
def test_min_difference_case2():
assert minimum_possible_difference(4, [10, 20, 30, 40]) == 0
def test_min_difference_case3():
assert minimum_possible_difference(3, [1, 2, 5]) == 2
def test_min_difference_case4()... | [
{
"docstring": null,
"function_declaration": "def find_min_difference(task_times):",
"function_name": "find_min_difference",
"parameter_list": "(task_times)"
},
{
"docstring": null,
"function_declaration": "def minimum_possible_difference(n, task_times):",
"function_name": "minimum_p... | [
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_time_difference(n, task_times):\n \"\"\"\n Minimize the absolute difference between the total task times of two groups.\n \n :param n... | trial_gpt4o_4 | {
"original_instruction": "",
"prompt_id": "00037882",
"row_id": 37882,
"seed_ids": "[7613, 5334, 4386]"
} | 0.711156 | Codeforces_37882 | I | [
"find_min_difference",
"minimum_possible_difference"
] | 2 | [
[
"minimum_possible_difference",
"find_min_difference"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | a69dc8d0457bf0d8078a70fe3a2e52de5d6562c4 | 961c21a2e42b5271d6a1e39e2f5c9e3070f0e0fd | |||
v1.0 | instruct | Codeforces | Codeforces_38085_I | Given an arithmetic expression as a string, you are to determine whether the expression is valid. The rules for a valid arithmetic expression are as follows:
1. The expression must only contain integers, addition (+), subtraction (-), multiplication (*), division (/) operators, and parentheses (() and )).
2. Operators ... | import re
def is_valid_expression(expression):
# Check if the expression contains invalid characters
if re.search(r"[^0-9+\-*/()]", expression):
return False
# Check for balanced parentheses
balance = 0
for char in expression:
if char == '(':
balance += 1
el... | import pytest
from solution import check_expression
def test_valid_expression():
assert check_expression("3*(1+2)-4/2") == "Valid"
assert check_expression("2+3*5/7-2") == "Valid"
assert check_expression("(5+5)/(2*2)-3") == "Valid"
def test_invalid_unbalanced_parentheses():
assert check_expression("3*(... | [
{
"docstring": null,
"function_declaration": "def is_valid_expression(expression):",
"function_name": "is_valid_expression",
"parameter_list": "(expression)"
},
{
"docstring": null,
"function_declaration": "def check_expression(expression):",
"function_name": "check_expression",
... | [
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 re\n\ndef is_valid_expression(expression):\n \"\"\"\n Determines if the given arithmetic expression is valid based on the specified rules.\n \... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00038085",
"row_id": 38085,
"seed_ids": "[309, 7152, 5178]"
} | 0.6507 | Codeforces_38085 | I | [
"is_valid_expression",
"check_expression"
] | 2 | [
[
"check_expression",
"is_valid_expression"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 85d5c2907b435b7c6cd689c0b814ba34e24573c0 | 25fb42cbeb925727b79349a0fcef5f9290cc8b01 | |||
v1.0 | instruct | Codeforces | Codeforces_38114_I | In a futuristic city, there are several power stations providing electricity and storage units storing the power. The power stations and the storage units are connected by a complex network of pipes. Each pipe connects exactly two power stations or storage units and has a certain capacity indicating how much power it c... | from collections import deque
def bfs(C, F, source, sink, parent):
n = len(C)
visited = [False] * n
queue = deque([source])
visited[source] = True
while queue:
u = queue.popleft()
for v in range(n):
if not visited[v] and F[u][v] < C[u][v]: # there is remai... | def test_example_1():
input_str = "4 5 1 4\n1 2 1000\n2 4 1000\n1 3 1000\n3 4 1000\n2 3 1\n"
assert from_io_string(input_str) == 2000
def test_min_input():
input_str = "2 1 1 2\n1 2 100\n"
assert from_io_string(input_str) == 100
def test_no_capacity():
input_str = "3 3 1 3\n1 2 0\n2 3 0\n1 3 0\n"
... | [
{
"docstring": null,
"function_declaration": "def bfs(C, F, source, sink, parent):",
"function_name": "bfs",
"parameter_list": "(C, F, source, sink, parent)"
},
{
"docstring": null,
"function_declaration": "def edmonds_karp(n, source, sink, capacity):",
"function_name": "edmonds_karp... | [
0,
0,
0,
0,
0,
1,
0,
0,
1,
1
] | 3 | hard | 0.3 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from collections import deque, defaultdict\n\ndef bfs_level_graph(capacity, source, sink, parent):\n visited = {source}\n queue = deque([source])\n w... | trial_gpt4o_9 | {
"original_instruction": "",
"prompt_id": "00038114",
"row_id": 38114,
"seed_ids": "[3481, 4916, 7376]"
} | 0.628806 | Codeforces_38114 | I | [
"bfs",
"edmonds_karp",
"max_flow_from_input",
"from_io_string"
] | 4 | [
[
"edmonds_karp",
"bfs"
],
[
"from_io_string",
"max_flow_from_input"
],
[
"max_flow_from_input",
"edmonds_karp"
]
] | 3 | [] | false | [] | false | pytest | false | [] | true | 117cb6a1c497bf2709be382cedbd96f1f0a48912 | 37bcdbc0049220af7abd2dd56cdb7b73944df38c | |||
v1.0 | instruct | Codeforces | Codeforces_38137_I | A company has assigned a daily task to its employees to compress a list of logs. Each log is a string consisting of lowercase letters and digits. The compression task involves replacing consecutive groups of the same character with the character followed by the number of repetitions, if the character repeats two or mor... | def compress_log(log):
"""
Compress a single log string by replacing consecutive groups of
the same character with the character followed by the number
of repetitions if the character repeats two or more times.
:param log: str - The log string to compress.
:return: str - The compressed lo... | def test_compress_log():
assert compress_log("aaabbcccd") == "a3b2c3d"
assert compress_log("a") == "a"
assert compress_log("bbbbb") == "b5"
assert compress_log("ab") == "ab"
assert compress_log("") == ""
assert compress_log("abcd") == "abcd"
assert compress_log("aabbcc") == "a2b2c2"
def tes... | [
{
"docstring": "Compress a single log string by replacing consecutive groups of \nthe same character with the character followed by the number \nof repetitions if the character repeats two or more times.\n\n:param log: str - The log string to compress.\n:return: str - The compressed log string.",
"function_... | [
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 compress_logs(logs):\n def compress(log):\n if not log:\n return \"\"\n\n compressed = []\n count = 1\n prev_cha... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00038137",
"row_id": 38137,
"seed_ids": "[989, 698, 7582]"
} | 0.72317 | Codeforces_38137 | I | [
"compress_log",
"compress_logs"
] | 2 | [
[
"compress_logs",
"compress_log"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | b08abed725994401a18ad04bd971d106ae10de91 | 507fade10a8c57e2dd97bac230cbddb565cf515c | |||
v1.0 | instruct | Codeforces | Codeforces_38158_I | A spaceship is stuck within a rectangular space grid in outer space. The grid is represented by its dimensions $$$n \times m$$$. Each cell in the grid either contains empty space denoted by '.', or an obstacle denoted by '#'. The spaceship is currently at position $$$(r_s, c_s)$$$ and wants to reach a destination at po... | from collections import deque
def shortest_path(n, m, grid, r_s, c_s, r_d, c_d):
# Directions (up, down, left, right)
directions = [(-1, 0, 'U'), (1, 0, 'D'), (0, -1, 'L'), (0, 1, 'R')]
# BFS setup
queue = deque([(r_s - 1, c_s - 1, "")]) # (row, col, path)
visited = set([(r_s - 1, c_s - 1)]) ... | from solution import spaceship_path
def test_spacship_path_simple_case():
n = 5
m = 5
grid = [
".....",
".###.",
".....",
".###.",
"....."
]
r_s, c_s, r_d, c_d = 1, 1, 5, 5
assert spaceship_path(n, m, grid, r_s, c_s, r_d, c_d).startswith("YES")
assert... | [
{
"docstring": null,
"function_declaration": "def shortest_path(n, m, grid, r_s, c_s, r_d, c_d):",
"function_name": "shortest_path",
"parameter_list": "(n, m, grid, r_s, c_s, r_d, c_d)"
},
{
"docstring": null,
"function_declaration": "def spaceship_path(n, m, grid, r_s, c_s, r_d, c_d):",... | [
1,
1,
0
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from collections import deque\n\ndef shortest_path_space(grid, n, m, r_s, c_s, r_d, c_d):\n # Directions for moving up, down, left, right\n directions =... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00038158",
"row_id": 38158,
"seed_ids": "[4952, 3100, 3801]"
} | 0.720418 | Codeforces_38158 | I | [
"shortest_path",
"spaceship_path"
] | 2 | [
[
"spaceship_path",
"shortest_path"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 44280abe389ef67821fb1b2e8fc9f242d8c9d8ff | 2cb3d75ee43c04650ba800cf5c13eaec2114c277 | |||
v1.0 | instruct | Codeforces | Codeforces_38163_I | You are given a permutation of integers from $$$1$$$ to $$$n$$$. A permutation is called good if no element in the sequence is at its original position (i.e., the position it would be in if the permutation were sorted in ascending order). This type of permutation is also known as a derangement.
For example, permutatio... | MOD = 10**9 + 7
def precompute_derangements(max_n):
"""
Precompute the derangements for all numbers from 0 to max_n.
"""
derangements = [0] * (max_n + 1)
if max_n >= 2:
derangements[1] = 0
derangements[2] = 1
for i in range(3, max_n + 1):
derangements[i] = (i - 1... | from solution import number_of_good_permutations
def test_single_case():
assert number_of_good_permutations(1, [1]) == [0]
def test_multiple_cases():
assert number_of_good_permutations(3, [1, 2, 3]) == [0, 1, 2]
def test_large_case():
n_max = 10**5
result = number_of_good_permutations(1, [n_max])... | [
{
"docstring": "Precompute the derangements for all numbers from 0 to max_n.",
"function_declaration": "def precompute_derangements(max_n):",
"function_name": "precompute_derangements",
"parameter_list": "(max_n)"
},
{
"docstring": null,
"function_declaration": "def number_of_good_permut... | [
0,
0,
0,
0,
0,
1,
0,
0,
1
] | 2 | hard | 0.222 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl",
"solution_code": "MOD = 10**9 + 7\n\ndef preprocess(limit):\n dp = [0] * (limit + 1)\n dp[0], dp[1] = 1, 0\n\n for i in range(2, limit + 1):\n dp[i] = (i - 1) *... | trial_gpt4o_9 | {
"original_instruction": "",
"prompt_id": "00038163",
"row_id": 38163,
"seed_ids": "[1459, 8222, 7261]"
} | 0.736573 | Codeforces_38163 | I | [
"precompute_derangements",
"number_of_good_permutations"
] | 2 | [
[
"number_of_good_permutations",
"precompute_derangements"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 74e0bb7e9481b9bd1a055ad22b40478cecd6eb1c | 3be8c6515c5fc14dc5fe49d02e18526a08aaa549 | |||
v1.0 | instruct | Codeforces | Codeforces_38188_I | You are given a matrix of size $$$n \times m$$$ filled with integers, and numerous queries to find the sum of elements in a submatrix. Efficiently compute the sum for each given submatrix.
The first line of the input contains two integers $$$n$$$ and $$$m$$$ ($$$1 \leq n, m \leq 10^3$$$), the number of rows and column... | def compute_prefix_sum(matrix):
n = len(matrix)
m = len(matrix[0])
prefix_sum = [[0] * (m + 1) for _ in range(n + 1)]
for i in range(1, n + 1):
for j in range(1, m + 1):
prefix_sum[i][j] = matrix[i-1][j-1] + prefix_sum[i-1][j] + prefix_sum[i][j-1] - prefix_sum[i-1][j-1]
return ... | import pytest
from solution import submatrix_sum
def test_submatrix_sum_example():
matrix = [
[1, 2, 3],
[4, 5, 6],
[7, 8, 9]
]
queries = [(1, 1, 2, 2), (2, 2, 3, 3)]
result = submatrix_sum(matrix, queries)
assert result == [12, 28]
def test_submatrix_sum_single_element():
... | [
{
"docstring": null,
"function_declaration": "def compute_prefix_sum(matrix):",
"function_name": "compute_prefix_sum",
"parameter_list": "(matrix)"
},
{
"docstring": null,
"function_declaration": "def submatrix_sum(matrix, queries):",
"function_name": "submatrix_sum",
"parameter_... | [
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 prepare_prefix_sum_matrix(matrix):\n n = len(matrix)\n m = len(matrix[0])\n prefix_sum = [[0] * (m + 1) for _ in range(n... | trial_gpt4o_4 | {
"original_instruction": "",
"prompt_id": "00038188",
"row_id": 38188,
"seed_ids": "[5003, 1986, 1708]"
} | 0.620905 | Codeforces_38188 | I | [
"compute_prefix_sum",
"submatrix_sum"
] | 2 | [
[
"submatrix_sum",
"compute_prefix_sum"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 8e6d46c039df1ab8cfaae45e3b03630a5b722477 | 67127bc058cae25d1242f95d48dae2614dba326a | |||
v1.0 | instruct | Codeforces | Codeforces_38241_I | You are given a list of $$$k$$$ strings. Each string contains lowercase Latin letters and has length exactly $$$n$$$. Your task is to determine if there exists a permutation of the columns such that all strings in the list are lexicographically sorted.
A permutation of the columns means the columns of all strings can ... | from itertools import permutations
def is_lexicographically_sorted(strings):
return all(strings[i] <= strings[i + 1] for i in range(len(strings) - 1))
def can_be_sorted(n, k, strings):
for perm in permutations(range(n)):
permuted_strings = ["".join(s[j] for j in perm) for s in strings]
if is_l... | from solution import can_be_sorted
def test_example_case1():
n = 3
k = 3
strings = ["abc", "cba", "bca"]
assert can_be_sorted(n, k, strings) == "YES"
def test_example_case2():
n = 3
k = 3
strings = ["aac", "caa", "bac"]
assert can_be_sorted(n, k, strings) == "NO"
def test_edge_cas... | [
{
"docstring": null,
"function_declaration": "def is_lexicographically_sorted(strings):",
"function_name": "is_lexicographically_sorted",
"parameter_list": "(strings)"
},
{
"docstring": null,
"function_declaration": "def can_be_sorted(n, k, strings):",
"function_name": "can_be_sorted... | [
0,
1,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from itertools import permutations\n\ndef is_lexicographically_sorted(lst):\n \"\"\" Check if the list of strings is lexicographically sorted \"\"\"\n r... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00038241",
"row_id": 38241,
"seed_ids": "[1191, 255, 6714]"
} | 0.696887 | Codeforces_38241 | I | [
"is_lexicographically_sorted",
"can_be_sorted"
] | 2 | [
[
"can_be_sorted",
"is_lexicographically_sorted"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 5699ad8dbe0e5afa9696ca955d3dbb04e0d6633d | db007ac48209484b74d7970d7b3f95cc508f1550 | |||
v1.0 | instruct | Codeforces | Codeforces_38328_I | Farmer Bob has a rectangular field represented as a grid of size n x m. Each cell in the grid can either be fertile land (represented by 1) or infertile land (represented by 0). Farmer Bob wants to grow his crops in a single rectangular subgrid within his field. However, he will only plant crops in subgrids where all c... | def max_rectangle_area(grid):
if not grid:
return 0
n = len(grid)
m = len(grid[0])
max_area = 0
heights = [0] * m
for row in grid:
for j in range(m):
if row[j] == 0:
heights[j] = 0
else:
heights[j] += 1
max_area =... | import pytest
from solution import max_rectangle_area
def test_max_rectangle_area_example1():
grid = [
[1, 0, 1, 1, 1],
[1, 1, 1, 1, 0],
[0, 1, 1, 0, 0],
[1, 1, 1, 0, 1]
]
assert max_rectangle_area(grid) == 6
def test_max_rectangle_area_all_fertile():
grid = [
[... | [
{
"docstring": null,
"function_declaration": "def max_rectangle_area(grid):",
"function_name": "max_rectangle_area",
"parameter_list": "(grid)"
},
{
"docstring": null,
"function_declaration": "def largest_rectangle_area_histogram(heights):",
"function_name": "largest_rectangle_area_h... | [
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 largest_fertile_subgrid_area(n, m, grid):\n \"\"\"\n Given a 2D grid, determines the area of the largest rectangular subgrid composed entirely of fe... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00038328",
"row_id": 38328,
"seed_ids": "[918, 3463, 7116]"
} | 0.616323 | Codeforces_38328 | I | [
"max_rectangle_area",
"largest_rectangle_area_histogram"
] | 2 | [
[
"max_rectangle_area",
"largest_rectangle_area_histogram"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | b0909bb472557fdb906e81612756386be200fa00 | 61bca4f3fe45d2b80532b21a2e0874ff3cad20b5 | |||
v1.0 | instruct | Codeforces | Codeforces_38332_I | Given an n x m grid where each cell is either land or water, represented respectively by the characters 'L' and 'W', a land mass is formed by connecting adjacent lands horizontally or vertically. A player can change any land cell to water in order to minimize the number of distinct land masses.
Your task is to determi... | def find_land_masses(grid, n, m):
def dfs(x, y):
if x < 0 or y < 0 or x >= n or y >= m or grid[x][y] != 'L':
return
grid[x][y] = 'V' # Mark as visited
for dx, dy in [(-1, 0), (1, 0), (0, -1), (0, 1)]:
dfs(x + dx, y + dy)
land_masses = 0
for i in range(n):
... | from solution import min_land_masses_after_change
def test_min_land_masses_after_change():
n, m = 3, 3
grid = [
['L', 'W', 'L'],
['L', 'L', 'L'],
['W', 'L', 'W']
]
assert min_land_masses_after_change(n, m, grid) == 1
def test_single_land():
n, m = 1, 1
grid = [
... | [
{
"docstring": null,
"function_declaration": "def find_land_masses(grid, n, m):",
"function_name": "find_land_masses",
"parameter_list": "(grid, n, m)"
},
{
"docstring": null,
"function_declaration": "def min_land_masses_after_change(n, m, grid):",
"function_name": "min_land_masses_a... | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def min_land_masses(grid):\n from collections import deque\n \n def num_land_masses(grid):\n n, m = len(grid), len(grid[0])\n visited =... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00038332",
"row_id": 38332,
"seed_ids": "[2341, 7751, 6832]"
} | 0.64042 | Codeforces_38332 | I | [
"find_land_masses",
"min_land_masses_after_change",
"main"
] | 3 | [
[
"min_land_masses_after_change",
"find_land_masses"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | bfc656b7c9465420284621455e48682fc1b8a088 | e04c953bb9239c2e4c5272c0ffd6659c29dcb4e0 | |||
v1.0 | instruct | Codeforces | Codeforces_38337_I | Bob the builder needs to construct a series of new roads to connect all the villages in the town of Slumberville. The town has n villages and r already existing bidirectional roads. Bob wants to ensure that after his new roads are built, there is a way to travel between any two villages. Since building roads is expensi... | def find(parent, i):
if parent[i] == i:
return i
else:
return find(parent, parent[i])
def union(parent, rank, x, y):
root_x = find(parent, x)
root_y = find(parent, y)
if root_x != root_y:
if rank[root_x] > rank[root_y]:
parent[root_y] = root_x
elif rank[... | def test_minimum_new_roads():
assert minimum_new_roads(4, [(1, 2), (2, 3)]) == 1
assert minimum_new_roads(4, [(1, 2), (2, 3), (3, 4)]) == 0
assert minimum_new_roads(6, [(1, 2), (2, 3), (4, 5)]) == 2
assert minimum_new_roads(1, []) == 0
assert minimum_new_roads(5, [(1, 2), (2, 3), (3, 4), (4, 5)]) ==... | [
{
"docstring": null,
"function_declaration": "def find(parent, i):",
"function_name": "find",
"parameter_list": "(parent, i)"
},
{
"docstring": null,
"function_declaration": "def union(parent, rank, x, y):",
"function_name": "union",
"parameter_list": "(parent, rank, x, y)"
},
... | [
1,
1,
0
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def find(parent, i):\n if parent[i] == i:\n return i\n else:\n return find(parent, parent[i])\n\ndef union(parent, rank, x, y):\n root_... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00038337",
"row_id": 38337,
"seed_ids": "[5323, 4266, 885]"
} | 0.672974 | Codeforces_38337 | I | [
"find",
"union",
"minimum_new_roads"
] | 3 | [
[
"minimum_new_roads",
"find"
],
[
"minimum_new_roads",
"union"
],
[
"union",
"find"
]
] | 3 | [] | false | [] | false | pytest | false | [] | true | 5f9291284c4b41f9073a01072472a9f2b3f99868 | f8c1475fdf444ab3f8773463fcd11350d7b95284 | |||
v1.0 | instruct | Codeforces | Codeforces_38401_I | You are given an array of n integers, and you need to perform the following tasks on it:
1. Find the length of the longest subarray such that the sum of the elements in this subarray is at most k.
2. Find the length of the shortest subarray such that the sum of the elements in this subarray is at least k.
The first l... | def longest_subarray_with_at_most_sum(arr, k):
n = len(arr)
max_length = 0
current_sum = 0
start = 0
for end in range(n):
current_sum += arr[end]
while current_sum > k:
current_sum -= arr[start]
start += 1
max_length = max(max_le... | from solution import find_subarray_lengths
def test_example_case():
n = 10
k = 15
arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
result = find_subarray_lengths(n, k, arr)
assert result == (5, 2)
def test_no_valid_longest():
n = 5
k = 2
arr = [5, 5, 5, 5, 5]
result = find_subarray_lengths(n,... | [
{
"docstring": null,
"function_declaration": "def longest_subarray_with_at_most_sum(arr, k):",
"function_name": "longest_subarray_with_at_most_sum",
"parameter_list": "(arr, k)"
},
{
"docstring": null,
"function_declaration": "def shortest_subarray_with_at_least_sum(arr, k):",
"funct... | [
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 find_subarray_lengths(n, k, arr):\n def longest_subarray_with_sum_at_most_k(n, k, arr):\n start = 0\n sum = 0\n max_length = 0\n ... | trial_gpt4o_7 | {
"original_instruction": "",
"prompt_id": "00038401",
"row_id": 38401,
"seed_ids": "[8231, 5791, 3814]"
} | 0.792402 | Codeforces_38401 | I | [
"longest_subarray_with_at_most_sum",
"shortest_subarray_with_at_least_sum",
"find_subarray_lengths"
] | 3 | [
[
"find_subarray_lengths",
"longest_subarray_with_at_most_sum"
],
[
"find_subarray_lengths",
"shortest_subarray_with_at_least_sum"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | f30bfa0cd92f2035da5ee7ef45954d20f64ce71e | 13e8e917bdc0f212656527daa27ec91b4b06dbb0 | |||
v1.0 | instruct | Codeforces | Codeforces_38411_I | You are given a playground represented as a 2D grid of size n x m. The playground can contain mountains ('^'), water ('~'), or empty fields ('.'). You are tasked with finding the largest rectangular region of empty fields ('.') in the playground. Note that the rectangular region must be contiguous and be aligned with t... | def max_histogram_area(heights):
stack = []
max_area = 0
index = 0
while index < len(heights):
if not stack or heights[stack[-1]] <= heights[index]:
stack.append(index)
index += 1
else:
top_of_stack = stack.pop()
area = (heights[top_of... | def test_max_histogram_area():
assert max_histogram_area([6, 2, 5, 4, 5, 1, 6]) == 12
assert max_histogram_area([2, 4]) == 4
assert max_histogram_area([0, 0, 0, 0]) == 0
assert max_histogram_area([1, 1, 1, 1]) == 4
def test_largest_rectangle_area():
grid1 = [
['.', '.', '^', '.'],
[... | [
{
"docstring": null,
"function_declaration": "def max_histogram_area(heights):",
"function_name": "max_histogram_area",
"parameter_list": "(heights)"
},
{
"docstring": null,
"function_declaration": "def largest_rectangle_area(grid):",
"function_name": "largest_rectangle_area",
"p... | [
1,
0,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def max_histogram_area(heights):\n stack = []\n max_area = 0\n index = 0\n \n while index < len(heights):\n if not stack or heights[stac... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00038411",
"row_id": 38411,
"seed_ids": "[4022, 1219, 3684]"
} | 0.599258 | Codeforces_38411 | I | [
"max_histogram_area",
"largest_rectangle_area",
"largest_empty_fields"
] | 3 | [
[
"largest_empty_fields",
"largest_rectangle_area"
],
[
"largest_rectangle_area",
"max_histogram_area"
]
] | 2 | [] | false | [] | false | pytest | false | [] | true | fb2ea6326762d3aca0b2e294b9b55209737e69f1 | aa6957da12a39bdc3cf1c54ca66f62e26f4f4949 | |||
v1.0 | instruct | Codeforces | Codeforces_38417_I | A company has a hierarchical organization structure, where each employee (except for the CEO) has exactly one direct manager. The CEO does not have any manager. You are given this organizational structure as a tree with `n` nodes. Node `1` represents the CEO, and each node numbered from `2` to `n` represents an employe... | class TreeNode:
def __init__(self, id):
self.id = id
self.children = []
def build_tree(edges, n):
nodes = {i: TreeNode(i) for i in range(1, n + 1)}
for u, v in edges:
nodes[u].children.append(nodes[v])
return nodes
def dfs(node, depth, parent, depths, parents):
depths[node.... | def test_lowest_common_manager_sample():
n = 9
edges = [
(1, 2), (1, 3), (2, 4), (2, 5), (3, 6), (3, 7), (5, 8), (5, 9)
]
m = 4
project_employees = [8, 9, 6, 7]
assert lowest_common_manager(n, edges, m, project_employees) == 1
def test_lowest_common_manager_direct_subordinates():
... | [] | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from collections import defaultdict\n\n# Function to find LCA of u and v. Assumes lca_method is already executed\ndef lca(u, v, parent, depth):\n if depth[... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00038417",
"row_id": 38417,
"seed_ids": "[1423, 3582, 1916]"
} | 0.591398 | Codeforces_38417 | I | [
"build_tree",
"dfs",
"preprocess_lca_tree",
"find_lca",
"lowest_common_manager"
] | 5 | [
[
"lowest_common_manager",
"build_tree"
],
[
"lowest_common_manager",
"find_lca"
],
[
"lowest_common_manager",
"preprocess_lca_tree"
],
[
"preprocess_lca_tree",
"dfs"
]
] | 4 | [] | false | [
"TreeNode"
] | true | pytest | false | [] | true | 6c21bc2325dfc23968e23babbff6da9111c99341 | 2e6500d1ad1580ebf576a54fb6091ca89fe86c59 | |||
v1.0 | instruct | Codeforces | Codeforces_38435_I | You are given an undirected graph with n vertices and m edges, where each vertex has a weight. Your task is to find the weight sum of the vertices that form the minimum spanning tree (MST) of the graph.
The first line of the input contains two integers, n and m (1 ≤ n ≤ 1000, 0 ≤ m ≤ 10^4), representing the number of ... | import heapq
def prims_min_vertex_weight_sum(n, m, weights, edges):
if n == 1:
return weights[0]
adj_list = {i: [] for i in range(n)}
for u, v, c in edges:
adj_list[u-1].append((c, v-1))
adj_list[v-1].append((c, u-1))
visited = [False] * n
min_heap = [(0, ... | from solution import find_mst_vertex_weight_sum
def test_basic():
n, m = 4, 5
weights = [1, 2, 3, 4]
edges = [
(1, 2, 1),
(2, 3, 2),
(3, 4, 3),
(4, 1, 4),
(1, 3, 5)
]
assert find_mst_vertex_weight_sum(n, m, weights, edges) == 10
def test_no_mst():
n, m =... | [
{
"docstring": null,
"function_declaration": "def prims_min_vertex_weight_sum(n, m, weights, edges):",
"function_name": "prims_min_vertex_weight_sum",
"parameter_list": "(n, m, weights, edges)"
},
{
"docstring": null,
"function_declaration": "def find_mst_vertex_weight_sum(n, m, weights,... | [
0,
1
] | 1 | medium | 0.5 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import heapq\n\nclass UnionFind:\n def __init__(self, n):\n self.parent = list(range(n))\n self.rank = [0] * n\n\n def find(self, u):\n ... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00038435",
"row_id": 38435,
"seed_ids": "[4896, 7382, 5223]"
} | 0.843123 | Codeforces_38435 | I | [
"prims_min_vertex_weight_sum",
"find_mst_vertex_weight_sum"
] | 2 | [
[
"find_mst_vertex_weight_sum",
"prims_min_vertex_weight_sum"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 4b1250393492f6d9532817e4342773adfbf9ddd9 | 2d2b197b1fc825e0581cba6686232d4a2e058e7d | |||
v1.0 | instruct | Codeforces | Codeforces_38436_I | The Kingdom of Graphland consists of several cities connected by directed roads. Each road has a specific travel time associated with it. The king of Graphland, King Graffius, has recently developed an interest in understanding the shortest travel times between cities in his kingdom.
Given the map of Graphland, help K... | import heapq
def dijkstra(n, roads, s):
# Prepare graph using adjacency list
graph = [[] for _ in range(n)]
for u, v, t in roads:
graph[u - 1].append((v - 1, t))
# Initialize distances and priority queue
INF = float('inf')
distances = [INF] * n
distances[s - 1] = 0
pq = [(0, s ... | from solution import calculate_shortest_paths
def test_example_case():
n = 5
m = 6
roads = [
(1, 2, 2),
(1, 3, 4),
(2, 3, 1),
(2, 4, 7),
(3, 5, 3),
(4, 5, 1)
]
s = 1
expected = [0, 2, 3, 9, 6]
assert calculate_shortest_paths(n, m, roads, s) ==... | [
{
"docstring": null,
"function_declaration": "def dijkstra(n, roads, s):",
"function_name": "dijkstra",
"parameter_list": "(n, roads, s)"
},
{
"docstring": null,
"function_declaration": "def calculate_shortest_paths(n, m, roads, s):",
"function_name": "calculate_shortest_paths",
... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import sys\nimport heapq\n\ndef shortest_paths(n, m, edges, s):\n \"\"\"\n Determines the shortest travel times from a city `s` to all other cities in a... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00038436",
"row_id": 38436,
"seed_ids": "[191, 7387, 5326]"
} | 0.790856 | Codeforces_38436 | I | [
"dijkstra",
"calculate_shortest_paths"
] | 2 | [
[
"calculate_shortest_paths",
"dijkstra"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | c2b6f48e09678052a7eff7fae742add993062efe | 8e38551ce67f47c54ff2a03807892936c9ad999c | |||
v1.0 | instruct | Codeforces | Codeforces_38453_I | You work for a company that provides internet services to several cities. To improve the infrastructure, they want to optimize their deployment of the internet cable lines between cities. Each cable line connects two distinct cities and has an associated cost.
Given the existing network connections and their costs, yo... | def find(parent, i):
if parent[i] == i:
return i
else:
return find(parent, parent[i])
def union(parent, rank, x, y):
xroot = find(parent, x)
yroot = find(parent, y)
if rank[xroot] < rank[yroot]:
parent[xroot] = yroot
elif rank[xroot] > rank[yroot]:
parent[yr... | def test_min_cost_example():
connections = [(1, 2, 3), (2, 3, 1), (3, 4, 4), (4, 1, 2), (1, 3, 5)]
assert minCostToConnectCities(4, 5, connections) == 6
def test_min_cost_single_city():
connections = []
assert minCostToConnectCities(1, 0, connections) == 0
def test_min_cost_no_connections():
conne... | [
{
"docstring": null,
"function_declaration": "def find(parent, i):",
"function_name": "find",
"parameter_list": "(parent, i)"
},
{
"docstring": null,
"function_declaration": "def union(parent, rank, x, y):",
"function_name": "union",
"parameter_list": "(parent, rank, x, y)"
},
... | [
0,
0,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def find_parent(parent, x):\n if parent[x] != x:\n parent[x] = find_parent(parent, parent[x]) # Path compression\n return parent[x]\n\ndef union... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00038453",
"row_id": 38453,
"seed_ids": "[7879, 5428, 2720]"
} | 0.730964 | Codeforces_38453 | I | [
"find",
"union",
"minCostToConnectCities"
] | 3 | [
[
"minCostToConnectCities",
"find"
],
[
"minCostToConnectCities",
"union"
],
[
"union",
"find"
]
] | 3 | [] | false | [] | false | pytest | false | [] | true | 67985fa1db1423082eedd55002878fd0034097e9 | 0df1d84373f7a40b8f68f2813f0fe5c0dba715ba | |||
v1.0 | instruct | Codeforces | Codeforces_38471_I | You are given a grid of size $$n \times m$$ consisting of binary values. The grid represents a maze where 0s denote open paths and 1s denote walls. Your task is to find the shortest path from the top-left corner (1,1) to the bottom-right corner ($$n$$,$$m$$) moving only up, down, left, or right. If there is no valid pa... | from collections import deque
def shortest_path(maze, n, m):
if maze[0][0] == 1 or maze[n-1][m-1] == 1:
return -1
moves = [(-1, 0), (1, 0), (0, -1), (0, 1)]
visited = [[False] * m for _ in range(n)]
queue = deque([(0, 0, 1)]) # (row, col, distance)
visited[0][0] = True
while queue:
... | import pytest
from solution import solve_maze
def test_solve_maze_case1():
n, m = 3, 3
maze_data = [
"0 1 0",
"0 0 0",
"1 1 0"
]
assert solve_maze(n, m, maze_data) == 5
def test_solve_maze_case2():
n, m = 3, 3
maze_data = [
"0 1 0",
"0 1 0",
"1 1... | [
{
"docstring": null,
"function_declaration": "def shortest_path(maze, n, m):",
"function_name": "shortest_path",
"parameter_list": "(maze, n, m)"
},
{
"docstring": null,
"function_declaration": "def solve_maze(n, m, maze_data):",
"function_name": "solve_maze",
"parameter_list": "... | [
1,
0,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from collections import deque\n\ndef shortest_path(maze, n, m):\n if maze[0][0] == 1 or maze[n-1][m-1] == 1:\n return -1\n\n moves = [(-1, 0), (1... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00038471",
"row_id": 38471,
"seed_ids": "[2244, 141, 987]"
} | 0.734009 | Codeforces_38471 | I | [
"shortest_path",
"solve_maze"
] | 2 | [
[
"solve_maze",
"shortest_path"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 1f9e3c24675df59182e10f6497128ea35eba13b8 | 01b3b9d1fd58506548bf48365c43e3de94cbabae | |||
v1.0 | instruct | Codeforces | Codeforces_38472_I | A magical forest has a peculiar structure where there are N magical trees connected by N-1 magical paths. Each path has a specific "magic level" associated with it. The trees are numbered from 1 to N.
Q queries will be asked about the forest. Each query consists of two integers u and v and you are to determine the max... | from collections import defaultdict
import heapq
def build_adjacency_list(N, paths):
adjacency_list = defaultdict(list)
for u, v, l in paths:
adjacency_list[u].append((v, l))
adjacency_list[v].append((u, l))
return adjacency_list
def get_max_magic_level(u, v, adjacency_list):
visited =... | from solution import solve
def test_example_case():
N = 5
Q = 2
paths = [
(1, 2, 3),
(2, 3, 4),
(2, 4, 6),
(4, 5, 9)
]
queries = [
(1, 5),
(3, 5)
]
assert solve(N, Q, paths, queries) == [9, 9]
def test_small_case():
N = 2
Q = 1
pa... | [
{
"docstring": null,
"function_declaration": "def build_adjacency_list(N, paths):",
"function_name": "build_adjacency_list",
"parameter_list": "(N, paths)"
},
{
"docstring": null,
"function_declaration": "def get_max_magic_level(u, v, adjacency_list):",
"function_name": "get_max_magi... | [
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 MagicalForest:\n def __init__(self, N):\n self.N = N\n self.adjacency_list = [[] for _ in range(N + 1)]\n\n def add_path(self, u, v,... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00038472",
"row_id": 38472,
"seed_ids": "[3571, 4706, 5159]"
} | 0.573725 | Codeforces_38472 | I | [
"build_adjacency_list",
"get_max_magic_level",
"solve"
] | 3 | [
[
"solve",
"build_adjacency_list"
],
[
"solve",
"get_max_magic_level"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 39dacaa98b1501fde0ebd994008d0538dc79ab4f | 99425ae5be8bcd6755d7c3acb9351008a511f309 | |||
v1.0 | instruct | Codeforces | Codeforces_38528_I | In Farland, each city is represented as a node in a graph. Roads connect the cities, and each road has a time cost associated with it. The roads allow travel between any two cities in both directions. The ruler of Farland has a peculiar interest in finding the shortest round-trip path for a courier starting from a spec... | import heapq
def dijkstra(graph, start, n):
"""
Executes the Dijkstra algorithm to find the shortest paths from the start node.
Returns the distances array.
"""
distances = [float("inf")] * (n + 1)
distances[start] = 0
priority_queue = [(0, start)]
while priority_queue:
current_... | from solution import shortest_round_trip
def test_example_case():
roads = [
(1, 2, 10),
(2, 3, 10),
(3, 4, 10),
(4, 5, 10),
(5, 1, 10),
(1, 3, 15)
]
assert shortest_round_trip(5, 6, roads, 1, 4) == 40
def test_single_direct_road():
roads = [
(1, ... | [
{
"docstring": "Executes the Dijkstra algorithm to find the shortest paths from the start node.\nReturns the distances array.",
"function_declaration": "def dijkstra(graph, start, n):",
"function_name": "dijkstra",
"parameter_list": "(graph, start, n)"
},
{
"docstring": null,
"function_d... | [
0,
0,
0,
0,
0,
0,
0,
1,
1,
0
] | 2 | hard | 0.2 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import heapq\n\ndef dijkstra(graph, start, n):\n queue = [(0, start)]\n distances = {i: float('inf') for i in range(1, n + 1)}\n distances[start] = 0... | trial_gpt4o_8 | {
"original_instruction": "",
"prompt_id": "00038528",
"row_id": 38528,
"seed_ids": "[2998, 3655, 7165]"
} | 0.762209 | Codeforces_38528 | I | [
"dijkstra",
"shortest_round_trip"
] | 2 | [
[
"shortest_round_trip",
"dijkstra"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 5e9a6c56ddd980ce999eb7e0462d38ab5300a86c | b849d810f0d79aa0de4f3e93f0c6d46d060357b5 | |||
v1.0 | instruct | Codeforces | Codeforces_38644_I | The kingdom of Flatland is a perfectly flat plane filled with intricate road networks connecting various towns. The king of Flatland has a peculiar fondness for squares, and he wants to identify all the possible squares that can be formed by towns connected through the road networks.
You are given n towns labeled from... | import math
from itertools import combinations
def is_square(p1, p2, p3, p4):
"""
Check if the given four points form a square
"""
points = [p1, p2, p3, p4]
distances = sorted([distance(points[i], points[j]) for i in range(4) for j in range(i + 1, 4)])
return distances[0] > 0 and distances[0] ... | import pytest
from solution import process_flatland_kingdom, four_towns_form_square
def test_example_case():
data = """5
0 0
0 1
1 0
1 1
2 2"""
assert process_flatland_kingdom(data) == "YES"
def test_no_square():
data = """4
0 0
0 1
1 1
2 2"""
assert process_flatland_kingdom(data) == "NO"
def test_la... | [
{
"docstring": "Check if the given four points form a square",
"function_declaration": "def is_square(p1, p2, p3, p4):",
"function_name": "is_square",
"parameter_list": "(p1, p2, p3, p4)"
},
{
"docstring": "Calculate the squared distance between two points to avoid floating point precision i... | [
0,
1,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_square(x1, y1, x2, y2, x3, y3, x4, y4):\n \"\"\"\n Check if four points form a square.\n \"\"\"\n from collections import Counter\n impo... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00038644",
"row_id": 38644,
"seed_ids": "[2943, 5185, 2024]"
} | 0.577059 | Codeforces_38644 | I | [
"is_square",
"distance",
"four_towns_form_square",
"process_flatland_kingdom"
] | 4 | [
[
"four_towns_form_square",
"is_square"
],
[
"is_square",
"distance"
],
[
"process_flatland_kingdom",
"four_towns_form_square"
]
] | 3 | [] | false | [] | false | pytest | true | [] | true | 974b52ab64039fe542449fcb23faab865f45b943 | 717aacc6de221e7a8bca466ea0221532a232510c | |||
v1.0 | instruct | Codeforces | Codeforces_38645_I | You are given a matrix of size `n x m` filled with integers. You need to perform multiple queries on this matrix. Each query is described by two pairs of coordinates `(x1, y1)` and `(x2, y2)` which represent the top-left and bottom-right corners of a submatrix. For each query, you need to find the sum of all integers w... | def preprocess_matrix(matrix, n, m):
prefix_sum = [[0] * (m + 1) for _ in range(n + 1)]
for i in range(1, n + 1):
for j in range(1, m + 1):
prefix_sum[i][j] = matrix[i-1][j-1] + prefix_sum[i][j-1] + prefix_sum[i-1][j] - prefix_sum[i-1][j-1]
return prefix_sum
def query_sum(prefix_sum, x1... | def test_preprocess_matrix():
matrix = [
[1, 2, 3],
[4, 5, 6],
[7, 8, 9]
]
expected = [
[0, 0, 0, 0],
[0, 1, 3, 6],
[0, 5, 12, 21],
[0, 12, 27, 45]
]
assert preprocess_matrix(matrix, 3, 3) == expected
def test_query_sum():
prefix_sum = [
... | [
{
"docstring": null,
"function_declaration": "def preprocess_matrix(matrix, n, m):",
"function_name": "preprocess_matrix",
"parameter_list": "(matrix, n, m)"
},
{
"docstring": null,
"function_declaration": "def query_sum(prefix_sum, x1, y1, x2, y2):",
"function_name": "query_sum",
... | [
0,
1,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def preprocess_matrix(matrix):\n n = len(matrix)\n m = len(matrix[0])\n \n prefix_sum = [[0] * (m + 1) for _ in range(n + 1)]\n \n for i in ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00038645",
"row_id": 38645,
"seed_ids": "[2262, 3759, 1942]"
} | 0.666867 | Codeforces_38645 | I | [
"preprocess_matrix",
"query_sum",
"matrix_queries"
] | 3 | [
[
"matrix_queries",
"preprocess_matrix"
],
[
"matrix_queries",
"query_sum"
]
] | 2 | [] | false | [] | false | pytest | false | [] | true | ff079482585e846c4ed7a83516526e941561bc65 | 92227924a3ee4530f8a9f92cba9746a15f2c054b | |||
v1.0 | instruct | Codeforces | Codeforces_38656_I | In a large university, there is a popular social networking app called UniConnect. In this app, each student is uniquely represented by an ID number, and friendships between students can be represented as undirected edges in a graph. Unfortunately, the university's network team has observed a potential security issue: ... | def find_parent(parent, i):
if parent[i] == i:
return i
return find_parent(parent, parent[i])
def union(parent, rank, x, y):
xroot = find_parent(parent, x)
yroot = find_parent(parent, y)
if xroot != yroot:
if rank[xroot] < rank[yroot]:
parent[xroot] = yroot
... | from solution import min_additional_edges_to_reduce_components
def test_example_case():
assert min_additional_edges_to_reduce_components(6, 3, 2, [(1, 2), (2, 3), (4, 5)]) == 1
def test_no_edges_needed():
assert min_additional_edges_to_reduce_components(5, 3, 2, [(1, 2), (2, 3), (4, 5)]) == 0
def test_alread... | [
{
"docstring": null,
"function_declaration": "def find_parent(parent, i):",
"function_name": "find_parent",
"parameter_list": "(parent, i)"
},
{
"docstring": null,
"function_declaration": "def union(parent, rank, x, y):",
"function_name": "union",
"parameter_list": "(parent, rank... | [
0,
0,
0,
0,
0,
0,
0,
1,
0,
1
] | 2 | hard | 0.2 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl",
"solution_code": "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_7 | {
"original_instruction": "",
"prompt_id": "00038656",
"row_id": 38656,
"seed_ids": "[7099, 2623, 3910]"
} | 0.667115 | Codeforces_38656 | I | [
"find_parent",
"union",
"min_additional_edges_to_reduce_components"
] | 3 | [
[
"min_additional_edges_to_reduce_components",
"find_parent"
],
[
"min_additional_edges_to_reduce_components",
"union"
],
[
"union",
"find_parent"
]
] | 3 | [] | false | [] | false | pytest | true | [] | true | 2dc9c161b976e9866f0e259d375d3eb1c66d9afe | 65c3beffff8cbb98804a0f0a6089fc14b3c3f1d6 | |||
v1.0 | instruct | Codeforces | Codeforces_38720_I | You are given a string consisting of lowercase Latin letters. Your task is to find the number of distinct substrings of this string using a suffix array and longest common prefix (LCP) array.
A suffix array of a string is an array of integers giving the starting positions of suffixes of the string in lexicographical o... | def suffix_array_construction(s):
"""
Constructs the suffix array of a given string s.
Args:
s (str): The input string.
Returns:
List[int]: The suffix array of s.
"""
n = len(s)
suffixes = sorted(range(n), key=lambda i: s[i:])
return suffixes
def lcp_array_construction(s, suffi... | def test_suffix_array_construction():
assert suffix_array_construction('banana') == [5, 3, 1, 0, 4, 2]
assert suffix_array_construction('abc') == [0, 1, 2]
assert suffix_array_construction('a') == [0]
assert suffix_array_construction('aaaa') == [3, 2, 1, 0]
def test_lcp_array_construction():
assert... | [
{
"docstring": "Constructs the suffix array of a given string s.\nArgs:\ns (str): The input string.\n\nReturns:\nList[int]: The suffix array of s.",
"function_declaration": "def suffix_array_construction(s):",
"function_name": "suffix_array_construction",
"parameter_list": "(s)"
},
{
"docstr... | [
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 build_suffix_array(s):\n n = len(s)\n suffixes = sorted((s[i:], i) for i in range(n))\n suffix_arr = [suffix[1] for suffix in suffixes]\n retu... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00038720",
"row_id": 38720,
"seed_ids": "[3311, 4810, 7381]"
} | 0.70045 | Codeforces_38720 | I | [
"suffix_array_construction",
"lcp_array_construction",
"count_distinct_substrings"
] | 3 | [
[
"count_distinct_substrings",
"lcp_array_construction"
],
[
"count_distinct_substrings",
"suffix_array_construction"
]
] | 2 | [] | false | [] | false | pytest | false | [] | true | 9a0813ccd15f991403bca625c09d72c39bbca7b4 | 8a7e34fd3b5399d3439ea271d44436af3e52c1a1 | |||
v1.0 | instruct | Codeforces | Codeforces_38726_I | You are a software developer in a city where autonomous drones are used to carry packages between various warehouses. Given that your company maintains a network of warehouses connected by direct routes with distinct travel times, they want to ensure efficient delivery of packages by selecting the shortest routes.
Eac... | import heapq
def dijkstra(n, edges, s):
adjacency_list = [[] for _ in range(n + 1)]
for u, v, w in edges:
adjacency_list[u].append((v, w))
adjacency_list[v].append((u, w))
dist = [float('inf')] * (n + 1)
dist[s] = 0
priority_queue = [(0, s)]
while priority_queue:
c... | from solution import shortest_travel_times
def test_shortest_travel_times():
n = 5
m = 6
routes = [
(1, 2, 2),
(1, 3, 4),
(2, 3, 1),
(3, 4, 1),
(2, 5, 5),
(4, 5, 3)
]
s = 1
expected_output = [0, 2, 3, 4, 7]
assert shortest_travel_times(n, m, r... | [
{
"docstring": null,
"function_declaration": "def dijkstra(n, edges, s):",
"function_name": "dijkstra",
"parameter_list": "(n, edges, s)"
},
{
"docstring": null,
"function_declaration": "def shortest_travel_times(n, m, routes, s):",
"function_name": "shortest_travel_times",
"para... | [
1,
1,
0
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import heapq\nfrom collections import defaultdict\nimport sys\n\ndef dijkstra(n, edges, s):\n graph = defaultdict(list)\n for u, v, w in edges:\n ... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00038726",
"row_id": 38726,
"seed_ids": "[4515, 1606, 2680]"
} | 0.72997 | Codeforces_38726 | I | [
"dijkstra",
"shortest_travel_times"
] | 2 | [
[
"shortest_travel_times",
"dijkstra"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 15c1f0ed42ba9401413ee6ad9568d3b0e58620a6 | 79e17e66d88cd47d54a7307c0fc0730fa7d576ad | |||
v1.0 | instruct | Codeforces | Codeforces_38774_I | You are given a directed graph with **n** vertices and **m** edges. Each edge has a cost associated with it. You need to answer **q** queries, each query asking for the cost of the shortest path between two given vertices **u** and **v**.
The following constraints are guaranteed:
- There are no negative-weight cycles... | def floyd_warshall(n, edges):
"""
Uses the Floyd-Warshall algorithm to compute shortest paths between all pairs of vertices.
"""
inf = float('inf')
dist = [[inf] * n for _ in range(n)]
for i in range(n):
dist[i][i] = 0
for a, b, w in edges:
dist[a-1][b-1] = min(dist[a-1... | def test_shortest_paths():
n = 4
m = 4
edges = [
(1, 2, 1),
(2, 3, 3),
(3, 4, 1),
(1, 4, 5)
]
q = 3
queries = [
(1, 4),
(1, 3),
(3, 1)
]
expected = [5, 4, -1]
assert shortest_paths(n, m, edges, q, queries) == expected
def test_... | [
{
"docstring": "Uses the Floyd-Warshall algorithm to compute shortest paths between all pairs of vertices.",
"function_declaration": "def floyd_warshall(n, edges):",
"function_name": "floyd_warshall",
"parameter_list": "(n, edges)"
},
{
"docstring": null,
"function_declaration": "def sho... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import heapq\n\ndef dijkstra(graph, start, n):\n \"\"\"\n Implements Dijkstra algorithm to find shortest paths from start node to all other nodes\n \... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00038774",
"row_id": 38774,
"seed_ids": "[3740, 7690, 7541]"
} | 0.811226 | Codeforces_38774 | I | [
"floyd_warshall",
"shortest_paths"
] | 2 | [
[
"shortest_paths",
"floyd_warshall"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | 2d069c27bd88eacb96da81277cd40ca020600455 | 6f3a44cdbbc14c9ee2b84b189b39ac9def36e30d | |||
v1.0 | instruct | Codeforces | Codeforces_38845_I | Gabriella is working on a grid with n rows and m columns. Each cell in the grid has an initial value. She can perform a set of operations to modify the grid. Each operation consists of selecting a subgrid and incrementing the value of each cell in this subgrid by 1. Gabriella wants to determine the state of the grid af... | def apply_operations(grid, operations):
n = len(grid)
m = len(grid[0])
# Applying each operation
for r1, c1, r2, c2 in operations:
for i in range(r1 - 1, r2):
for j in range(c1 - 1, c2):
grid[i][j] += 1
return grid
def grid_state_after_opera... | def test_basic():
n, m = 3, 3
initial_grid = [
[1, 2, 3],
[4, 5, 6],
[7, 8, 9]
]
k = 2
operations = [
(1, 1, 2, 2),
(2, 2, 3, 3)
]
expected_grid = [
[2, 3, 3],
[5, 7, 7],
[7, 9, 10]
]
assert grid_state_after_operations(n... | [
{
"docstring": null,
"function_declaration": "def apply_operations(grid, operations):",
"function_name": "apply_operations",
"parameter_list": "(grid, operations)"
},
{
"docstring": null,
"function_declaration": "def grid_state_after_operations(n, m, initial_grid, k, operations):",
"... | [
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 apply_operations(n, m, grid, operations):\n # Initialize a difference matrix with zeros\n diff = [[0] * (m + 1) for _ in range(n + 1)]\n \n # ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00038845",
"row_id": 38845,
"seed_ids": "[6962, 4208, 143]"
} | 0.727943 | Codeforces_38845 | I | [
"apply_operations",
"grid_state_after_operations"
] | 2 | [
[
"grid_state_after_operations",
"apply_operations"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | dc4cc52392e3572912c3d39c4f5b4c76b0e5dfea | f43833fdb455d7ff7fa66f58239560c9bd490661 | |||
v1.0 | instruct | Codeforces | Codeforces_38879_I | A researcher is studying the growth patterns of a peculiar species of fungus. They observe that the fungus grows in a pattern resembling a rectangular grid and takes special interest in the number of unique clusters of fungus over time. Each grid cell can either be empty ('.') or occupied by fungus ('X'). Two neighbori... | def find_clusters(grid, n, m):
def dfs(r, c):
stack = [(r, c)]
while stack:
cr, cc = stack.pop()
for dr, dc in [(-1, 0), (1, 0), (0, -1), (0, 1)]:
nr, nc = cr + dr, cc + dc
if 0 <= nr < n and 0 <= nc < m and grid[nr][nc] == 'X':
... | from solution import get_fungus_clusters
def test_single_day_growth():
initial_grid = [
".....",
".....",
".....",
"....."
]
changes = [(1, 1, 1)]
result = get_fungus_clusters(4, 5, initial_grid, changes)
assert result == [1]
def test_multiple_days_single_cluster():... | [
{
"docstring": null,
"function_declaration": "def find_clusters(grid, n, m):",
"function_name": "find_clusters",
"parameter_list": "(grid, n, m)"
},
{
"docstring": null,
"function_declaration": "def get_fungus_clusters(n, m, initial_grid, changes):",
"function_name": "get_fungus_clus... | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def count_clusters(grid):\n \"\"\"\n Count the number of unique clusters of fungus in the grid.\n \"\"\"\n n = len(grid)\n m = len(grid[0])\n ... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00038879",
"row_id": 38879,
"seed_ids": "[7223, 6175, 217]"
} | 0.620782 | Codeforces_38879 | I | [
"find_clusters",
"get_fungus_clusters"
] | 2 | [
[
"get_fungus_clusters",
"find_clusters"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 574c5229d8e1a8b0f8cc59d804c039897363ee87 | 26049a7c0b321e549f25ccaa9a5a30b49593f288 | |||
v1.0 | instruct | Codeforces | Codeforces_38891_I | Peterson is a curious explorer who loves traveling to new and exciting places. He plans his journeys with the help of a special map called the "interestingness map". The interestingness map is a directed graph with weighted edges. Each node represents a place, and each edge a route with a specific degree of interesting... | from itertools import permutations
def max_interestingness_tour(n, m, w, k, edges):
# Create adjacency matrix for interestingness values
interestingness = [[-1 for _ in range(n)] for _ in range(n)]
for u, v, c in edges:
if c >= w:
interestingness[u - 1][v - 1] = c
def compute_total... | from solution import solve_tsp
def test_example():
n = 4
m = 5
w = 3
k = 2
edges = [
(1, 2, 3),
(2, 3, 4),
(3, 4, 5),
(4, 1, 3),
(1, 3, 2)
]
assert solve_tsp(n, m, w, k, edges) == 15
def test_no_valid_start():
n = 4
m = 5
w = 8
k = 2
... | [
{
"docstring": null,
"function_declaration": "def max_interestingness_tour(n, m, w, k, edges):",
"function_name": "max_interestingness_tour",
"parameter_list": "(n, m, w, k, edges)"
},
{
"docstring": null,
"function_declaration": "def solve_tsp(n, m, w, k, edges):",
"function_name": ... | [
0,
0,
0,
1
] | 1 | hard | 0.25 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import itertools\n\ndef max_interestingness_tour(n, m, w, k, edges):\n graph = [[-1 for _ in range(n)] for _ in range(n)]\n for u, v, c in edges:\n ... | trial_gpt4o_4 | {
"original_instruction": "",
"prompt_id": "00038891",
"row_id": 38891,
"seed_ids": "[7184, 4512, 2943]"
} | 0.651411 | Codeforces_38891 | I | [
"max_interestingness_tour",
"solve_tsp"
] | 2 | [
[
"solve_tsp",
"max_interestingness_tour"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | c3cf3787b0d0d793d371b29762e48625f343519e | 3149d6c267ddfc7c1a38698a1efcabeedd3eb232 | |||
v1.0 | instruct | Codeforces | Codeforces_38931_I | Jason, a budding computer scientist, is fascinated by binary search trees (BSTs) and their properties. He recently learned about a unique property of BSTs - the sum of the distances from the root to all other nodes. He wants to write a program that, given a sequence of integers, constructs a BST and calculates this sum... | class BSTNode:
def __init__(self, key):
self.key = key
self.left = None
self.right = None
def insert_bst_node(root, key):
if root is None:
return BSTNode(key)
if key < root.key:
root.left = insert_bst_node(root.left, key)
else:
root.right = insert_bst_nod... | from solution import sum_of_distances
def test_sum_of_distances_example():
assert sum_of_distances(5, [10, 5, 1, 7, 40]) == 6
def test_sum_of_distances_single_node():
assert sum_of_distances(1, [10]) == 0
def test_sum_of_distances_two_nodes():
assert sum_of_distances(2, [10, 5]) == 1
def test_sum_of_dis... | [] | [
1,
0,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl",
"solution_code": "class BSTNode:\n def __init__(self, key):\n self.key = key\n self.left = None\n self.right = None\n\ndef insert_bst_node(root, key):\n... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00038931",
"row_id": 38931,
"seed_ids": "[6916, 5066, 21]"
} | 0.599827 | Codeforces_38931 | I | [
"insert_bst_node",
"calculate_distances_sum",
"sum_of_distances"
] | 3 | [
[
"sum_of_distances",
"calculate_distances_sum"
],
[
"sum_of_distances",
"insert_bst_node"
]
] | 2 | [] | false | [
"BSTNode"
] | true | pytest | true | [] | true | b5c27b18beb4ee263c235a86e2a436d8e2d4cf88 | 5679a72b8e3f0492c5ceba4a3b098f01a7120a57 | |||
v1.0 | instruct | Codeforces | Codeforces_38987_I | David is working on a data analysis task and has a matrix of integers. He wants to determine the largest contiguous submatrix (a submatrix formed by selecting a contiguous range of rows and columns) that contains only positive numbers. The goal is to calculate the area of this submatrix, defined as the number of elemen... | def largest_contiguous_positive_submatrix(matrix):
n = len(matrix)
m = len(matrix[0])
# Helper function to find maximum rectangle area in a histogram
def max_histogram_area(histogram):
stack = []
max_area = 0
index = 0
while index < len(histogram):
... | def test_largest_contiguous_positive_submatrix():
matrix1 = [
[1, 2, 3, -1, 5],
[-2, 3, 4, -5, 6],
[7, 8, 9, 1, -4],
[5, 4, -2, 3, -6]
]
assert solve(matrix1) == 6
matrix2 = [
[1, 2, -3, 4],
[5, 6, 7, 8],
[9, 10, 11, 12]
]
assert solve(mat... | [
{
"docstring": null,
"function_declaration": "def largest_contiguous_positive_submatrix(matrix):",
"function_name": "largest_contiguous_positive_submatrix",
"parameter_list": "(matrix)"
},
{
"docstring": null,
"function_declaration": "def solve(matrix):",
"function_name": "solve",
... | [
1,
0,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def largest_contiguous_positive_submatrix(matrix):\n n = len(matrix)\n m = len(matrix[0])\n \n # Helper function to find maximum rectangle area in... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00038987",
"row_id": 38987,
"seed_ids": "[6999, 737, 5259]"
} | 0.642998 | Codeforces_38987 | I | [
"largest_contiguous_positive_submatrix",
"solve"
] | 2 | [
[
"solve",
"largest_contiguous_positive_submatrix"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | 9139be96f7863b9e3d712cefe0815c8786837be4 | e071c258ac9da21d5a32b9a1291235f4f8f36b44 | |||
v1.0 | instruct | Codeforces | Codeforces_39093_I | In a distant land called Yendoria, there are $$$n$$$ villages connected by $$$m$$$ bidirectional roads forming a connected graph. Each road has a certain length. There is a major festival happening, and the king wants to ensure that each village has the least possible travel cost to any other village. To achieve this, ... | def floyd_warshall(n, m, roads):
# Initialize the distance matrix
dist = [[float('inf')] * n for _ in range(n)]
# Distance from each village to itself is 0
for i in range(n):
dist[i][i] = 0
# Initialize distances according to the roads given
for u, v, w in roads:
dist[u... | from solution import shortest_paths
def test_example_case():
n, m = 4, 4
roads = [
(1, 2, 3),
(2, 3, 4),
(3, 4, 2),
(4, 1, 5)
]
result = shortest_paths(n, m, roads)
expected = [
[0, 3, 7, 5],
[3, 0, 4, 6],
[7, 4, 0, 2],
[5, 6, 2, 0]
... | [
{
"docstring": null,
"function_declaration": "def floyd_warshall(n, m, roads):",
"function_name": "floyd_warshall",
"parameter_list": "(n, m, roads)"
},
{
"docstring": null,
"function_declaration": "def shortest_paths(n, m, roads):",
"function_name": "shortest_paths",
"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": "def floyd_warshall(n, m, roads):\n # Initialize the distance matrix with infinity\n dist = [[float('inf')] * n for _ in range(n)]\n \n # Distance ... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00039093",
"row_id": 39093,
"seed_ids": "[2075, 1994, 1449]"
} | 0.738278 | Codeforces_39093 | I | [
"floyd_warshall",
"shortest_paths"
] | 2 | [
[
"shortest_paths",
"floyd_warshall"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 6e4532ed2a93ace5c9d5265394c4f671835d85ee | feaeedcb91a35ebffdc41e7e784eef5783466b36 | |||
v1.0 | instruct | Codeforces | Codeforces_39095_I | Misha is a huge fan of mathematics and puzzles. One day, he came across a challenging problem involving prime numbers and he needs your help to solve it.
Given an integer n, determine the smallest prime number that is greater than n.
Your task is to write a program that finds and prints this prime number.
The first ... | def is_prime(n):
"""
Checks if a number is prime.
"""
if n <= 1:
return False
if n <= 3:
return True
if n % 2 == 0 or n % 3 == 0:
return False
i = 5
while i * i <= n:
if n % i == 0 or n % (i + 2) == 0:
return False
i += 6
return Tru... | from solution import next_prime, is_prime
def test_is_prime():
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(4) == False
assert is_prime(5) == True
assert is_prime(9) == False
assert is_prime(11) == True
assert is_prime(13) == True
assert is_prime(25) == False
d... | [
{
"docstring": "Checks if a number is prime.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Returns the smallest prime number greater than a given number n.",
"function_declaration": "def next_prime(n):",
"functio... | [
1,
0,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(n):\n \"\"\"\n Checks if a number is prime.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return True\n if ... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00039095",
"row_id": 39095,
"seed_ids": "[3258, 4425, 6980]"
} | 0.577491 | Codeforces_39095 | I | [
"is_prime",
"next_prime"
] | 2 | [
[
"next_prime",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 0afce2b024a6283ea04915571c15e72d26a7b2dc | 871d46a2c200accbb7ec437ddf2842f836a605f5 | |||
v1.0 | instruct | Codeforces | Codeforces_39097_I | A construction company is working on planning a road network within a new urban area. The area can be represented as a grid of streets, where some streets are already blocked due to ongoing construction work.
Given a grid of size n x m, where 0 represents an open street and 1 represents a blocked street, the company a... | def has_path(grid):
from collections import deque
n = len(grid)
m = len(grid[0])
if grid[0][0] == 1 or grid[n-1][m-1] == 1:
return "NO"
directions = [(0, 1), (1, 0), (0, -1), (-1, 0)]
visited = [[False] * m for _ in range(n)]
queue = deque([(0, 0)])
while queue:
... | def test_get_path_result():
assert get_path_result(4, 4, [[0, 0, 0, 0], [1, 1, 0, 1], [0, 0, 0, 0], [0, 1, 1, 0]]) == "YES"
assert get_path_result(3, 3, [[0, 1, 0], [1, 1, 0], [0, 0, 0]]) == "NO"
assert get_path_result(1, 1, [[0]]) == "YES"
assert get_path_result(2, 2, [[0, 1], [1, 0]]) == "NO"
asse... | [
{
"docstring": null,
"function_declaration": "def has_path(grid):",
"function_name": "has_path",
"parameter_list": "(grid)"
},
{
"docstring": null,
"function_declaration": "def get_path_result(n, m, grid):",
"function_name": "get_path_result",
"parameter_list": "(n, m, 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 is_path_exists(grid):\n \"\"\"\n Determine if there is a path from the top-left corner\n to the bottom-right corner of the grid.\n \"\"\"\n ... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00039097",
"row_id": 39097,
"seed_ids": "[6569, 6238, 2269]"
} | 0.712457 | Codeforces_39097 | I | [
"has_path",
"get_path_result"
] | 2 | [
[
"get_path_result",
"has_path"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | 6cf43c79d5ded104aae0fe14f385911e94c18c43 | 1b0e5f33db7f375b7dcc80d14036fc7946454834 | |||
v1.0 | instruct | Codeforces | Codeforces_39116_I | You have been hired by a transportation company to design a scheduling algorithm for their bus routes. The company operates buses on a large number of routes, each connecting two different cities. Every bus route needs to be scheduled exactly once per day. Some bus routes are more profitable than others, and the compan... | def find(parent, i):
if parent[i] == i:
return i
else:
parent[i] = find(parent, parent[i])
return parent[i]
def union(parent, rank, x, y):
rootX = find(parent, x)
rootY = find(parent, y)
if rootX != rootY:
if rank[rootX] > rank[rootY]:
parent[rootY] ... | def test_maximum_profit():
assert maximum_profit(4, 5, 3, [(1, 2, 10), (2, 3, 20), (3, 4, 30), (4, 1, 40), (2, 4, -50)]) == 90
assert maximum_profit(4, 5, 4, [(1, 2, 10), (2, 3, 20), (3, 4, 30), (4, 1, 40), (2, 4, -50)]) == 100
assert maximum_profit(3, 3, 3, [(1, 2, 10), (2, 3, 20), (1, 3, 5)]) == 35
as... | [
{
"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": "import heapq\n\ndef find_max_profit(n, m, min_routes, routes):\n parent = list(range(n))\n rank = [0] * n\n def find(u):\n if u != parent[u]:\... | trial_gpt4o_9 | {
"original_instruction": "",
"prompt_id": "00039116",
"row_id": 39116,
"seed_ids": "[5556, 8186, 548]"
} | 0.734113 | Codeforces_39116 | I | [
"find",
"union",
"maximum_profit",
"read_input"
] | 4 | [
[
"maximum_profit",
"find"
],
[
"maximum_profit",
"union"
],
[
"union",
"find"
]
] | 3 | [
"read_input"
] | false | [] | false | pytest | true | [] | true | 5e2c84af02dafc3c5c118c636d0b47e6a6fee72f | 3657154ff9937ae85a30dcd01692849f63242929 | |||
v1.0 | instruct | Codeforces | Codeforces_39118_I | Farmer Bob has a rectangular farm represented as a 2D grid. Each cell in the grid contains either a crop or a weed. Bob wants to protect his crops by enclosing the largest rectangular area consisting of only crops with a wooden fence. The fence must be rectangular and aligned to the grid's rows and columns.
You need t... | def maximalRectangle(matrix):
"""
Returns the area of the largest rectangular region that contains only '1s'.
"""
if not matrix:
return 0
m = len(matrix)
n = len(matrix[0])
max_area = 0
dp = [0] * n
for i in range(m):
for j in range(n):
if matrix... | from solution import maximalRectangle
def test_maximalRectangle():
assert maximalRectangle([
['1', '0', '1', '0', '0'],
['1', '0', '1', '1', '1'],
['1', '1', '1', '1', '1'],
['1', '0', '0', '1', '0']
]) == 6
assert maximalRectangle([
['0', '1'],
['1', '0... | [
{
"docstring": "Returns the area of the largest rectangular region that contains only '1s'.",
"function_declaration": "def maximalRectangle(matrix):",
"function_name": "maximalRectangle",
"parameter_list": "(matrix)"
},
{
"docstring": "Returns the largest rectangular area in a histogram.",
... | [
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 maximalRectangle(grid):\n if not grid:\n return 0\n\n m, n = len(grid), len(grid[0])\n heights = [0] * (n + 1)\n max_area = 0\n\n fo... | trial_gpt4o_7 | {
"original_instruction": "",
"prompt_id": "00039118",
"row_id": 39118,
"seed_ids": "[2937, 4993, 2544]"
} | 0.635142 | Codeforces_39118 | I | [
"maximalRectangle",
"largestAreaInHistogram"
] | 2 | [
[
"maximalRectangle",
"largestAreaInHistogram"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 876981c8f22e30ab220e0a9a7f95f2c54b42be3c | 2a31e8bd2c21d806f4ed96bb27b8b68041f813cc | |||
v1.0 | instruct | Codeforces | Codeforces_39126_I | You have a field of crops represented as a grid of n rows and m columns. Each cell in this grid can either be a crop (represented by 1) or barren land (represented by 0). Your task is to find the largest rectangle of crops in this grid. A rectangle of crops is defined as a contiguous sub-grid where all cells contain 1.... | 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[t... | from solution import largest_rectangle_of_crops
def test_single_test_case():
t = 1
test_cases = [
(4, 4, [
[1, 1, 0, 1],
[1, 1, 1, 1],
[0, 1, 1, 0],
[1, 1, 1, 0]
])
]
assert largest_rectangle_of_crops(t, test_cases) == [6]
def test_multip... | [
{
"docstring": null,
"function_declaration": "def max_histogram_area(histogram):",
"function_name": "max_histogram_area",
"parameter_list": "(histogram)"
},
{
"docstring": null,
"function_declaration": "def max_rectangle(grid):",
"function_name": "max_rectangle",
"parameter_list"... | [
1,
0,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def maximalRectangle(matrix):\n if not matrix:\n return 0\n\n max_area = 0\n dp = [0] * len(matrix[0])\n for row in matrix:\n for i ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00039126",
"row_id": 39126,
"seed_ids": "[6246, 2873, 1360]"
} | 0.681962 | Codeforces_39126 | I | [
"max_histogram_area",
"max_rectangle",
"largest_rectangle_of_crops"
] | 3 | [
[
"largest_rectangle_of_crops",
"max_rectangle"
],
[
"max_rectangle",
"max_histogram_area"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 89acac902e53026d4bd949a893b1ae5dda03f82f | b8eb6cf2af0ce2408c8695043ea4158dada4f91d | |||
v1.0 | instruct | Codeforces | Codeforces_39148_I | In a distant galaxy, there is a kingdom consisting of several cities connected by teleportation portals. Each portal has a transportation cost associated with it. The monarch of the kingdom wants to ensure that his subjects can travel between any two cities with minimum cost, so he has decided to hire an engineer to co... | def find(parent, i):
if parent[i] == i:
return i
else:
parent[i] = find(parent, parent[i])
return parent[i]
def union(parent, rank, x, y):
root_x = find(parent, x)
root_y = find(parent, y)
if root_x != root_y:
if rank[root_x] > rank[root_y]:
parent[r... | from solution import minimum_cost_to_connect_cities
def test_minimum_cost_to_connect_cities():
# Test case 1
assert minimum_cost_to_connect_cities(4, 4, [(1, 2, 3), (2, 3, 1), (3, 4, 4), (1, 4, 5)]) == 8
# Test case 2
assert minimum_cost_to_connect_cities(4, 2, [(1, 2, 3), (3, 4, 4)]) == -1
... | [
{
"docstring": null,
"function_declaration": "def find(parent, i):",
"function_name": "find",
"parameter_list": "(parent, i)"
},
{
"docstring": null,
"function_declaration": "def union(parent, rank, x, y):",
"function_name": "union",
"parameter_list": "(parent, rank, x, y)"
},
... | [
0,
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 xroot... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00039148",
"row_id": 39148,
"seed_ids": "[397, 299, 8003]"
} | 0.736319 | Codeforces_39148 | I | [
"find",
"union",
"kruskal",
"minimum_cost_to_connect_cities"
] | 4 | [
[
"kruskal",
"find"
],
[
"kruskal",
"union"
],
[
"minimum_cost_to_connect_cities",
"kruskal"
],
[
"union",
"find"
]
] | 4 | [] | false | [] | false | pytest | true | [] | true | eb0cf98e9c98aa4dbb1d9a7dbff5ba2ef88f6ee9 | 2cee371a80866a23845909563d628f5733fedf92 | |||
v1.0 | instruct | Codeforces | Codeforces_39179_I | You are given an array of n integer numbers. You need to perform q queries of a specific type on the array. Each query asks you to calculate the sum of the numbers in a given subarray.
The first line of the input contains two integers n and q (1 ≤ n, q ≤ 2·10^5). The second line contains n integers a1, a2, ..., an (1 ... | def prefix_sum_array(arr):
"""
Create a prefix sum array for the given array.
"""
prefix_sum = [0] * (len(arr) + 1)
for i in range(1, len(arr) + 1):
prefix_sum[i] = prefix_sum[i - 1] + arr[i - 1]
return prefix_sum
def sum_of_subarray(prefix_sum, l, r):
"""
Returns the sum of the... | from solution import process_queries
def test_process_queries():
assert process_queries(5, 3, [1, 2, 3, 4, 5], [(1, 3), (2, 4), (1, 5)]) == [6, 9, 15]
assert process_queries(4, 2, [1, 1, 1, 1], [(1, 2), (2, 4)]) == [2, 3]
assert process_queries(3, 1, [5, 8, 6], [(1, 3)]) == [19]
assert process_queries(... | [
{
"docstring": "Create a prefix sum array for the given array.",
"function_declaration": "def prefix_sum_array(arr):",
"function_name": "prefix_sum_array",
"parameter_list": "(arr)"
},
{
"docstring": "Returns the sum of the subarray from index l to r (1-based index).",
"function_declarat... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def preprocess_prefix_sums(arr):\n \"\"\"\n Given an array, preprocess it to get the prefix sums.\n \"\"\"\n prefix_sums = [0] * (len(arr) + 1)\n ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00039179",
"row_id": 39179,
"seed_ids": "[4313, 7419, 5804]"
} | 0.724988 | Codeforces_39179 | I | [
"prefix_sum_array",
"sum_of_subarray",
"process_queries"
] | 3 | [
[
"process_queries",
"prefix_sum_array"
],
[
"process_queries",
"sum_of_subarray"
]
] | 2 | [
"process_queries"
] | false | [] | false | pytest | true | [] | true | c7c317bbf6f98435df05c5e151d36d9a1bf3b15b | 88a60c04214d58d12b0fe70615ab2a2a2a642a95 | |||
v1.0 | instruct | Codeforces | Codeforces_39181_I | You are given a rectangular grid with R rows and C columns where each cell of the grid initially contains a value 0. Your task is to process a series of Q operations on this grid. Each operation can be one of the following types:
1. **Add Value**: Add a given value V to all elements in a specific rectangular subgrid.
... | def create_grid(R, C):
"""Creates a grid with specified rows and columns filled with zero."""
return [[0] * C for _ in range(R)]
def add_value(grid, r1, c1, r2, c2, V):
"""Adds a given value V to all elements in a specific rectangular subgrid."""
for r in range(r1 - 1, r2):
for c in range(c1 - ... | from solution import create_grid, add_value, set_value, get_value, process_queries
def test_create_grid():
assert create_grid(3, 3) == [[0, 0, 0], [0, 0, 0], [0, 0, 0]]
def test_add_value():
grid = create_grid(3, 3)
add_value(grid, 1, 1, 2, 2, 5)
assert grid == [[5, 5, 0], [5, 5, 0], [0, 0, 0]]
def t... | [
{
"docstring": "Creates a grid with specified rows and columns filled with zero.",
"function_declaration": "def create_grid(R, C):",
"function_name": "create_grid",
"parameter_list": "(R, C)"
},
{
"docstring": "Adds a given value V to all elements in a specific rectangular subgrid.",
"fu... | [
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 create_grid(R, C):\n \"\"\"Creates a grid with specified rows and columns filled with zero.\"\"\"\n return [[0] * C for _ in range(R)]\n\ndef add_va... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00039181",
"row_id": 39181,
"seed_ids": "[2975, 8197, 4744]"
} | 0.652412 | Codeforces_39181 | I | [
"create_grid",
"add_value",
"set_value",
"get_value",
"process_queries"
] | 5 | [
[
"process_queries",
"add_value"
],
[
"process_queries",
"create_grid"
],
[
"process_queries",
"get_value"
],
[
"process_queries",
"set_value"
]
] | 4 | [
"process_queries"
] | false | [] | false | pytest | true | [] | true | 8d79028217098f1895d0dd97c3323908de10cfbc | 36b33b871a032f8c586e6b0e5baac3d18e5a35a7 | |||
v1.0 | instruct | Codeforces | Codeforces_39230_I | You are given an array $$$a$$$ consisting of $$$n$$$ integers. In one operation, you can select any two adjacent elements and swap them. Your goal is to sort the array in non-decreasing order. Calculate the minimum number of swaps required to sort the array.
The first line of the input contains one integer $$$n$$$ ($$... | 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
wh... | def test_single_element():
assert minimum_swaps_to_sort([1]) == 0
def test_sorted_array():
assert minimum_swaps_to_sort([1, 2, 3, 4, 5]) == 0
def test_reverse_sorted_array():
assert minimum_swaps_to_sort([5, 4, 3, 2, 1]) == 10
def test_random_array():
assert minimum_swaps_to_sort([2, 3, 8, 6, 1]) == ... | [
{
"docstring": null,
"function_declaration": "def merge_and_count(arr, temp_arr, left, mid, right):",
"function_name": "merge_and_count",
"parameter_list": "(arr, temp_arr, left, mid, right)"
},
{
"docstring": null,
"function_declaration": "def merge_sort_and_count(arr, temp_arr, left, r... | [
1,
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 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_0 | {
"original_instruction": "",
"prompt_id": "00039230",
"row_id": 39230,
"seed_ids": "[3386, 987, 1680]"
} | 0.721872 | Codeforces_39230 | I | [
"merge_and_count",
"merge_sort_and_count",
"minimum_swaps_to_sort"
] | 3 | [
[
"merge_sort_and_count",
"merge_and_count"
],
[
"minimum_swaps_to_sort",
"merge_sort_and_count"
]
] | 2 | [] | false | [] | false | pytest | false | [] | true | a888976929a761d14cbd74c2ddd14c2ef66f42ac | f06f2766f981ff2a098b2b3e8fbc2a1669e8aea8 | |||
v1.0 | instruct | Codeforces | Codeforces_39281_I | The roads in the kingdom of Casteland are quite peculiar. Casteland has n cities labeled from 1 to n, and certain bidirectional roads connect specific pairs of cities. Each city can be described as having a certain altitude. The kingdom is planning to build a new road system to connect all the cities. The plan is to en... | from collections import defaultdict, deque
def find_root(city, parent):
if parent[city] != city:
parent[city] = find_root(parent[city], parent)
return parent[city]
def union(city1, city2, parent, rank):
root1 = find_root(city1, parent)
root2 = find_root(city2, parent)
if root1 != root... | import pytest
from solution import minimum_new_roads
def test_example_1():
n = 4
m = 2
altitudes = [1, 2, 3, 4]
roads = [(1, 2), (3, 4)]
assert minimum_new_roads(n, m, altitudes, roads) == 1
def test_example_2():
n = 3
m = 0
altitudes = [5, 5, 5]
roads = []
assert minimum_new_r... | [
{
"docstring": null,
"function_declaration": "def find_root(city, parent):",
"function_name": "find_root",
"parameter_list": "(city, parent)"
},
{
"docstring": null,
"function_declaration": "def union(city1, city2, parent, rank):",
"function_name": "union",
"parameter_list": "(ci... | [
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 min_new_roads_needed(n, m, altitudes, roads):\n from collections import defaultdict, deque\n\n def bfs_components():\n visited = [False] * n\... | trial_gpt4o_7 | {
"original_instruction": "",
"prompt_id": "00039281",
"row_id": 39281,
"seed_ids": "[2632, 6560, 6821]"
} | 0.787543 | Codeforces_39281 | I | [
"find_root",
"union",
"minimum_new_roads"
] | 3 | [
[
"minimum_new_roads",
"find_root"
],
[
"minimum_new_roads",
"union"
],
[
"union",
"find_root"
]
] | 3 | [] | false | [] | false | pytest | true | [] | true | 2382eb73c885bcf869e39563d46f0bdb6b53ee26 | 60972a6535858550788eaf3fdc15c43bcd62dd26 | |||
v1.0 | instruct | Codeforces | Codeforces_39283_I | Alice and Bob are playing a friendly game on a binary tree. The tree has `n` nodes, numbered from 1 to `n`, rooted at node 1. Alice randomly selects a node `a`, and Bob randomly selects a different node `b`. They start from their respective nodes and try to meet at a common node by only moving towards the root.
You ar... | import sys
import collections
def preprocess_lca(n, edges):
LOG = 17 # As n <= 10^5, log2(10^5) is less than 17
# Create adjacency list for the tree
tree = collections.defaultdict(list)
for u, v in edges:
tree[u].append(v)
tree[v].append(u)
# Initialize parent and depth array... | def test_example_case():
input_data = '''7
1 2
1 3
2 4
2 5
3 6
3 7
4
4 5
4 6
3 4
2 7'''
expected_output = [2, 1, 1, 1]
assert lca_queries(input_data) == expected_output
def test_single_edge():
input_data = '''2
1 2
1
1 2'''
expected_output = [1]
assert lca_queries(input_data) == expected_output... | [
{
"docstring": null,
"function_declaration": "def preprocess_lca(n, edges):",
"function_name": "preprocess_lca",
"parameter_list": "(n, edges)"
},
{
"docstring": null,
"function_declaration": "def lca(u, v, parent, depth, LOG):",
"function_name": "lca",
"parameter_list": "(u, v, ... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from collections import defaultdict, deque\n\nclass BinaryTreeLCA:\n def __init__(self, n, edges):\n self.n = n\n self.edges = edges\n ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00039283",
"row_id": 39283,
"seed_ids": "[1680, 6387, 5681]"
} | 0.606602 | Codeforces_39283 | I | [
"preprocess_lca",
"lca",
"solve_lca",
"parse_input",
"lca_queries"
] | 5 | [
[
"lca_queries",
"parse_input"
],
[
"lca_queries",
"solve_lca"
],
[
"solve_lca",
"lca"
],
[
"solve_lca",
"preprocess_lca"
]
] | 4 | [
"parse_input"
] | false | [] | false | pytest | false | [] | true | deaf1d251618095e356b02f9ff234efdaf438a41 | e2ceec80a09f473e6a1fb072020c5d87ccc924b5 | |||
v1.0 | instruct | Codeforces | Codeforces_39300_I | With the recent advancement in the AI industry, you decided to showcase your knowledge of prime numbers by developing a new algorithm to generate prime numbers in a given range. To help visualize the capability of your algorithm, you've decided to create a simple program to find all prime numbers between two given inte... | def is_prime(n):
"""
Checks if a number n is a prime number.
"""
if n <= 1:
return False
if n <= 3:
return True
if n % 2 == 0 or n % 3 == 0:
return False
i = 5
while i * i <= n:
if n % i == 0 or n % (i + 2) == 0:
return False
i += 6
... | from solution import is_prime, primes_in_range, display_primes
import io
import sys
def test_is_prime():
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(5) == True
assert is_prime(4) == False
assert is_prime(1) == False
assert is_prime(0) == False
def test_primes_in_r... | [
{
"docstring": "Checks if a number n is a prime number.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Returns a list of all prime numbers between low and high (inclusive).",
"function_declaration": "def primes_in_ran... | [
0,
1,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(num):\n \"\"\"\n Determines if a given number is a prime number.\n \"\"\"\n if num <= 1:\n return False\n if num <= 3:\n ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00039300",
"row_id": 39300,
"seed_ids": "[7001, 7688, 7636]"
} | 0.663881 | Codeforces_39300 | I | [
"is_prime",
"primes_in_range",
"display_primes"
] | 3 | [
[
"display_primes",
"primes_in_range"
],
[
"primes_in_range",
"is_prime"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 48b68090e6879b746a82b1e542b9e6b01667a693 | 4b36ffa717faf52dd65adfb0e2d767b6427cb4d9 | |||
v1.0 | instruct | Codeforces | Codeforces_39307_I | Provided below is a similar coding assessment question. The format, style, complexity, and scope are aligned with the preceding questions.
Design a new coding assessment question within the following parameters:
- Ensure new question style is in accordance with the original ones.
- Compare length, tone, language, diff... | from collections import deque
import heapq
def is_valid(x, y, m, n):
return 0 <= x < m and 0 <= y < n
def find_minimum_time(m, n, start, destination, grid, weather_intervals):
directions = [(0, 1), (1, 0), (0, -1), (-1, 0)]
weather_map = {}
for t_start, t_end, x, y in weather_intervals:
i... | def test_example():
m, n = 5, 4
start = (0, 0)
destination = (4, 3)
grid = [
[0, 0, 0, 0],
[0, 1, 0, 1],
[0, 0, 0, 0],
[1, 1, 0, 1],
[0, 0, 0, 0]
]
weather_intervals = [
(2, 5, 1, 1),
(4, 6, 2, 3)
]
result = find_minimum_time(m, n, ... | [
{
"docstring": null,
"function_declaration": "def is_valid(x, y, m, n):",
"function_name": "is_valid",
"parameter_list": "(x, y, m, n)"
},
{
"docstring": null,
"function_declaration": "def find_minimum_time(m, n, start, destination, grid, weather_intervals):",
"function_name": "find_... | [
0,
0,
0,
0,
0,
0,
0,
1,
1,
0
] | 2 | hard | 0.2 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import heapq\n\ndef min_time_to_destination(m, n, sx, sy, dx, dy, forest, weather_patterns):\n def is_valid(x, y):\n return 0 <= x < m and 0 <= y < ... | trial_gpt4o_8 | {
"original_instruction": "",
"prompt_id": "00039307",
"row_id": 39307,
"seed_ids": "[50, 2811, 770]"
} | 0.558586 | Codeforces_39307 | I | [
"is_valid",
"find_minimum_time"
] | 2 | [
[
"find_minimum_time",
"is_valid"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | b9b9086a92ba59d057c79ae77ed3cf40466cc4c9 | 2e3a418448c027d0f2d5e638fde981d9405d9f6c | |||
v1.0 | instruct | Codeforces | Codeforces_39384_I | You are given a matrix A of size n x m, where each cell contains a single lowercase English letter. You need to find the largest square sub-matrix (including its length) within A where all four borders of the square are palindromes. A palindrome is a sequence that reads the same backward as forward.
Input:
- The first... | def is_palindrome(seq):
return seq == seq[::-1]
def largest_palindromic_border(n, m, matrix):
max_size = 0
top_left_coordinates = (0, 0)
for size in range(min(n, m), 0, -1):
for i in range(n - size + 1):
for j in range(m - size + 1):
top_row = matrix[i][j:j+size]
... | from solution import largest_palindromic_square_submatrix
def test_example_1():
n, m = 5, 5
matrix = [
"abcba",
"babab",
"cbabc",
"babab",
"abcba"
]
assert largest_palindromic_square_submatrix(n, m, matrix) == (5, 1, 1)
def test_example_2():
n, m = 3, 3
... | [
{
"docstring": null,
"function_declaration": "def is_palindrome(seq):",
"function_name": "is_palindrome",
"parameter_list": "(seq)"
},
{
"docstring": null,
"function_declaration": "def largest_palindromic_border(n, m, matrix):",
"function_name": "largest_palindromic_border",
"par... | [
1,
1,
0
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_palindrome(s):\n return s == s[::-1]\n\ndef largest_palindromic_square(matrix, n, m):\n max_len = 0\n top_left = (0, 0)\n\n for size in ran... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00039384",
"row_id": 39384,
"seed_ids": "[4028, 4589, 6587]"
} | 0.67808 | Codeforces_39384 | I | [
"is_palindrome",
"largest_palindromic_border",
"largest_palindromic_square_submatrix"
] | 3 | [
[
"largest_palindromic_border",
"is_palindrome"
],
[
"largest_palindromic_square_submatrix",
"largest_palindromic_border"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | bef5dc67044d8f1591a331d07318e4dac4976568 | e29a35881c40f6716445b3cd669d2551fa5d57e1 | |||
v1.0 | instruct | Codeforces | Codeforces_39455_I | You are given a grid with `n` rows and `m` columns, where each cell either contains a `.` (representing an open cell) or a `#` (representing an obstacle). Your task is to determine the maximum area of a rectangular sub-grid that contains only open cells (`.`).
The input data consists of multiple test cases. The first ... | def max_rectangle_area(grid):
n = len(grid)
m = len(grid[0])
heights = [0] * m
max_area = 0
for row in grid:
for col in range(m):
if row[col] == '.':
heights[col] += 1
else:
heights[col] = 0
stack = []
for i in range(m... | from solution import main
def test_case_1():
input_string = "2\n3 4\n.##.\n..#.\n....\n5 5\n.....\n.....\n..#..\n.....\n....."
expected_output = "4\n10"
assert main(input_string) == expected_output
def test_case_empty_grid():
input_string = "1\n3 3\n###\n###\n###"
expected_output = "0"
assert ... | [
{
"docstring": null,
"function_declaration": "def max_rectangle_area(grid):",
"function_name": "max_rectangle_area",
"parameter_list": "(grid)"
},
{
"docstring": null,
"function_declaration": "def solve(test_cases):",
"function_name": "solve",
"parameter_list": "(test_cases)"
}... | [
0,
0,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def max_rect_area(grid, n, m):\n \"\"\"\n Helper function to calculate the maximum area of a rectangle of open cells in a grid.\n \"\"\"\n # Creat... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00039455",
"row_id": 39455,
"seed_ids": "[5488, 8183, 1955]"
} | 0.648307 | Codeforces_39455 | I | [
"max_rectangle_area",
"solve",
"parse_input",
"main"
] | 4 | [
[
"solve",
"max_rectangle_area"
]
] | 1 | [
"parse_input"
] | false | [] | false | pytest | true | [] | true | bdfb6ce9cbcc7da8e41250b5cf5f6e2ced40f877 | 23b9f85a2500afc9ac485cdf3ba72413f031e8eb | |||
v1.0 | instruct | Codeforces | Codeforces_39465_I | There is a kingdom with N cities connected by M bidirectional roads. Each road has a certain travel cost associated with it. The kingdom has a peculiar rule: each city must be connected to every other city directly or indirectly. You are the royal cartographer tasked with ensuring the kingdom remains connected after an... | import heapq
# Prim's Algorithm to find Minimum Spanning Tree Cost and Edges
def prim_mst(graph, n):
visited = [False] * (n + 1)
min_heap = [(0, 1, -1)] # (cost, to_node, from_node)
mst_cost = 0
mst_edges = []
while min_heap:
cost, to_node, from_node = heapq.heappop(min_heap)
... | from solution import find_max_cost_removal
def test_case_1():
input_str = "5 6\n1 2 3\n1 3 4\n2 3 1\n2 4 2\n3 5 5\n4 5 3\n"
assert find_max_cost_removal(input_str) == 3
def test_case_2():
input_str = "4 5\n1 2 2\n1 3 3\n1 4 10\n2 3 1\n3 4 4\n"
assert find_max_cost_removal(input_str) == 4
def test_cas... | [
{
"docstring": null,
"function_declaration": "def prim_mst(graph, n):",
"function_name": "prim_mst",
"parameter_list": "(graph, n)"
},
{
"docstring": null,
"function_declaration": "def max_cost_removal(N, M, roads):",
"function_name": "max_cost_removal",
"parameter_list": "(N, M,... | [
0,
0,
0,
0,
0,
0,
1,
0,
0,
0
] | 1 | hard | 0.1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def find_max_cost_road_to_remove(N, M, roads):\n \"\"\"\n Returns the maximum travel cost of a single road that can be removed while keeping the kingdom... | trial_gpt4o_6 | {
"original_instruction": "",
"prompt_id": "00039465",
"row_id": 39465,
"seed_ids": "[7150, 4283, 5479]"
} | 0.690025 | Codeforces_39465 | I | [
"prim_mst",
"max_cost_removal",
"parse_input",
"find_max_cost_removal"
] | 4 | [
[
"find_max_cost_removal",
"max_cost_removal"
],
[
"find_max_cost_removal",
"parse_input"
],
[
"max_cost_removal",
"prim_mst"
]
] | 3 | [
"parse_input"
] | false | [] | false | pytest | true | [] | true | bc9e7d19f70e855ce382ad22e3954a3db213e0a1 | 74c7186b65347c36533296b0d84f2f8f8d582bee | |||
v1.0 | instruct | Codeforces | Codeforces_39487_I | Dominic has recently taken up the hobby of hedge maze design. He has decided to create mazes that have a unique feature: exactly one path exists between any two points in the maze. Essentially, each maze is a tree. Dominic wants to ensure that his mazes are well-designed and have certain properties to make them both ch... | from collections import deque
def find_tree_diameter(n, edges):
if n == 1:
return [1]
adj = [[] for _ in range(n+1)]
for u, v in edges:
adj[u].append(v)
adj[v].append(u)
def bfs(start):
dist = [-1] * (n + 1)
dist[start] = 0
queue = deque([start]... | def test_find_tree_center():
# Test on provided examples
assert find_tree_center(4, [(1, 2), (1, 3), (2, 4)]) in {1}
assert find_tree_center(5, [(1, 2), (1, 3), (3, 4), (4, 5)]) in {3}
# Additional tests
assert find_tree_center(1, []) == 1
assert find_tree_center(2, [(1, 2)]) in {1, 2}
... | [
{
"docstring": null,
"function_declaration": "def find_tree_diameter(n, edges):",
"function_name": "find_tree_diameter",
"parameter_list": "(n, edges)"
},
{
"docstring": null,
"function_declaration": "def find_tree_center(n, edges):",
"function_name": "find_tree_center",
"paramet... | [
1,
0,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from collections import deque\n\ndef find_tree_diameter(n, edges):\n if n == 1:\n return [1]\n \n adj = [[] for _ in range(n+1)]\n for u, v... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00039487",
"row_id": 39487,
"seed_ids": "[5084, 6060, 8199]"
} | 0.575928 | Codeforces_39487 | I | [
"find_tree_diameter",
"find_tree_center"
] | 2 | [
[
"find_tree_center",
"find_tree_diameter"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | 2f3c92bd290d3a3c1f0dd3a223b04151acf82ee3 | fb8a79d6413465e09869e4a8a852e8ab7775f5fb | |||
v1.0 | instruct | Codeforces | Codeforces_39501_I | Ravi is a big fan of prime numbers. He loves to play with them and has come up with an interesting problem. A prime number is a natural number greater than 1 that is not a product of two smaller natural numbers.
Given an integer $$$n$$$, Ravi wants to find the smallest prime number that is greater than or equal to $$$... | import math
def is_prime(num):
"""
Determines if a number is prime.
"""
if num <= 1:
return False
if num == 2:
return True
if num % 2 == 0:
return False
for i in range(3, int(math.sqrt(num)) + 1, 2):
if num % i == 0:
return False
return True
... | from solution import is_prime, smallest_prime_gte, process_test_cases
def test_is_prime():
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(4) == False
assert is_prime(17) == True
assert is_prime(18) == False
assert is_prime(19) == True
assert is_prime(1) == False
a... | [
{
"docstring": "Determines if a number is prime.",
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": "Finds the smallest prime number greater than or equal to n.",
"function_declaration": "def smallest_prime_gte(n):",
... | [
1,
1
] | 2 | 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 \"\"\"Return True if num is a prime number, else False.\"\"\"\n if num <= 1:\n return False\n if num <= 3:\n retur... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00039501",
"row_id": 39501,
"seed_ids": "[107, 2561, 4983]"
} | 0.620814 | Codeforces_39501 | I | [
"is_prime",
"smallest_prime_gte",
"process_test_cases"
] | 3 | [
[
"process_test_cases",
"smallest_prime_gte"
],
[
"smallest_prime_gte",
"is_prime"
]
] | 2 | [
"process_test_cases"
] | false | [] | false | pytest | true | [] | true | b60df258f7c665e7d84209d57c72eb06b05ad08a | e0e1871d88794c638903be9aea7e4e9f944e8ee4 | |||
v1.0 | instruct | Codeforces | Codeforces_39540_I | Jane is organizing a charity event and she has several booths offering different activities. The event lasts for n minutes and each activity takes a certain duration to complete and provides a certain amount of fun. Jane wants to maximize the total amount of fun that visitors can have by participating in different acti... | def max_fun(n, m, activities, k, incompatibles):
def can_schedule(activity, schedule):
for sch in schedule:
if incompatibles.get((min(activity, sch), max(activity, sch)), False):
return False
return True
def dfs(idx, current_fun, schedule):
nonlocal max_f... | from solution import solution
def test_example_case():
n = 10
m = 3
activities = [
(1, 3, 5),
(4, 6, 7),
(7, 10, 4)
]
k = 1
incompatibilities = [(1, 3)]
assert solution(n, m, activities, k, incompatibilities) == 12
def test_no_incompatibilities():
n = 10
m =... | [
{
"docstring": null,
"function_declaration": "def max_fun(n, m, activities, k, incompatibles):",
"function_name": "max_fun",
"parameter_list": "(n, m, activities, k, incompatibles)"
},
{
"docstring": null,
"function_declaration": "def solution(n, m, activities, k, incompatibilities):",
... | [
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_fun(n, m, activities, k, incompatibles):\n def can_schedule(activity, schedule):\n for sch in schedule:\n if incompatibles.get((m... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00039540",
"row_id": 39540,
"seed_ids": "[6864, 3233, 4543]"
} | 0.677907 | Codeforces_39540 | I | [
"max_fun",
"solution"
] | 2 | [
[
"solution",
"max_fun"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | b0bd8d774afee191c47d23b885c57ea62a44bc02 | e4a23a23947d6a8c10049d1ad19f2a9bcf876a17 | |||
v1.0 | instruct | Codeforces | Codeforces_39557_I | You are given a set of $$$n$$$ intervals on a number line, where each interval is represented by a pair of integers $$$[l_i, r_i]$$$ (1 ≤ $$$i$$$ ≤ n). Two intervals $$$[l_i, r_i]$$$ and $$$[l_j, r_j]$$$ are considered overlapping if they share at least one common point, i.e., there exists some integer $$$x$$$ such tha... | def max_overlap(intervals):
"""
This function takes a list of intervals and returns the maximum number of overlapping intervals.
"""
events = []
for interval in intervals:
l, r = interval
events.append((l, 1)) # start of interval
events.append((r + 1, -1)) # end of interval... | from solution import process_intervals
def test_max_overlap_example():
n = 5
interval_list = [(1, 3), (2, 5), (4, 6), (7, 9), (8, 10)]
assert process_intervals(n, interval_list) == 2
def test_max_overlap_no_overlap():
n = 3
interval_list = [(1, 2), (3, 4), (5, 6)]
assert process_intervals(n, i... | [
{
"docstring": "This function takes a list of intervals and returns the maximum number of overlapping intervals.",
"function_declaration": "def max_overlap(intervals):",
"function_name": "max_overlap",
"parameter_list": "(intervals)"
},
{
"docstring": "This function processes the input for 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_overlap(intervals):\n \"\"\"\n This function takes a list of intervals and returns the maximum number of overlapping intervals.\n \"\"\"\n ... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00039557",
"row_id": 39557,
"seed_ids": "[7878, 1094, 5737]"
} | 0.804008 | Codeforces_39557 | I | [
"max_overlap",
"process_intervals"
] | 2 | [
[
"process_intervals",
"max_overlap"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 67901c99a432edabefa86d718e53e09c15c5ee05 | ddf8a7398d15e25217cfc003cda893abb5e88037 | |||
v1.0 | instruct | Codeforces | Codeforces_39604_I | Liza loves collecting prime numbers. Recently she has started wondering about prime sums. She came up with a problem and is eager to know the answer.
Given an array of positive integers, can you determine if it is possible to split the array into two non-empty subsets such that the sum of the prime numbers in each sub... | def is_prime(num):
"""
Helper function to check if a number is prime.
"""
if num <= 1:
return False
for i in range(2, int(num**0.5) + 1):
if num % i == 0:
return False
return True
def can_split_prime_sum(nums):
"""
Determines if it's possible to split the arr... | from solution import can_split_prime_sum
def test_no_primes():
assert can_split_prime_sum([1, 4, 6, 8, 10]) == "NO"
def test_primes_equal_split():
assert can_split_prime_sum([1, 2, 3, 4, 5, 6]) == "YES"
assert can_split_prime_sum([2, 2, 3, 3]) == "YES"
def test_primes_non_equal_split():
assert ca... | [
{
"docstring": "Helper function to check if a number is prime.",
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": "Determines if it's possible to split the array into two non-empty subsets\nsuch that their prime sums are e... | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(num):\n \"\"\"\n Returns True if num is a prime number, else False.\n \"\"\"\n if num <= 1:\n return False\n if num == 2:\n... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00039604",
"row_id": 39604,
"seed_ids": "[2971, 4074, 4355]"
} | 0.627017 | Codeforces_39604 | I | [
"is_prime",
"can_split_prime_sum"
] | 2 | [
[
"can_split_prime_sum",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 02b099987139e3f4441c8a3d20b7685ba64cf08a | d507dc9317ad402713bf212ed6e1fc36e68560d9 | |||
v1.0 | instruct | Codeforces | Codeforces_39622_I | In the land of Algorithmia, there exists a magical tree consisting of `n` nodes and `n-1` edges (1 ≤ n ≤ 100000). A tree is a connected acyclic graph. Each node in the tree has a unique number from 1 to `n`. Algorithmia's king wants to find the "dominant path" in the tree between any two nodes `u` and `v`.
The "domina... | import sys
from collections import deque
def dfs(node, parent, depth, values, adj, path_sum, parent_table):
parent_table[node] = parent
path_sum[node] = values[node]
if parent != -1:
path_sum[node] += path_sum[parent]
depth[node] = 0 if parent == -1 else depth[parent] + 1
for neighbor in a... | from solution import find_dominant_path_sum
def test_example_case():
n = 5
values = [0, 1, 3, 2, 4, 5] # Pad with a 0 at index 0 for 1-based indexing
edges = [(1, 2), (1, 3), (2, 4), (2, 5)]
queries = [(1, 4), (1, 5), (3, 4)]
assert find_dominant_path_sum(n, values, edges, queries) == [8, 9, 10]
... | [
{
"docstring": null,
"function_declaration": "def dfs(node, parent, depth, values, adj, path_sum, parent_table):",
"function_name": "dfs",
"parameter_list": "(node, parent, depth, values, adj, path_sum, parent_table)"
},
{
"docstring": null,
"function_declaration": "def lca(u, v, parent,... | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl",
"solution_code": "class DominantPathTree:\n def __init__(self, node_values, edges):\n self.n = len(node_values)\n self.node_values = node_values\n self.... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00039622",
"row_id": 39622,
"seed_ids": "[4520, 1172, 7151]"
} | 0.663312 | Codeforces_39622 | I | [
"dfs",
"lca",
"find_dominant_path_sum"
] | 3 | [
[
"find_dominant_path_sum",
"dfs"
],
[
"find_dominant_path_sum",
"lca"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 0223ef1520f5ed9efc6173f78f1a4a4569910f65 | 5d4c0d5bba3502d514f871c3bc4f141ff70aa718 | |||
v1.0 | instruct | Codeforces | Codeforces_39819_I | In a distant galaxy, there is a complex system of space tunnels connecting various planets. The transportation authority wants to ensure that each planet can communicate directly or indirectly with all other planets using the least number of tunnels. The system can be represented as an undirected graph where planets ar... | def find(parent, i):
if parent[i] == i:
return i
return find(parent, parent[i])
def union(parent, rank, x, y):
xroot = find(parent, x)
yroot = find(parent, y)
if rank[xroot] < rank[yroot]:
parent[xroot] = yroot
elif rank[xroot] > rank[yroot]:
parent[yroot] = xroot
... | from solution import minimum_tunnels_to_connect_all_planets
def test_no_tunnels():
assert minimum_tunnels_to_connect_all_planets(4, 0, []) == 3
def test_some_tunnels():
assert minimum_tunnels_to_connect_all_planets(4, 1, [(1, 2)]) == 2
def test_fully_connected():
assert minimum_tunnels_to_connect_all_pla... | [
{
"docstring": null,
"function_declaration": "def find(parent, i):",
"function_name": "find",
"parameter_list": "(parent, i)"
},
{
"docstring": null,
"function_declaration": "def union(parent, rank, x, y):",
"function_name": "union",
"parameter_list": "(parent, rank, x, y)"
},
... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def find(parent, i):\n if parent[i] == i:\n return i\n return find(parent, parent[i])\n\ndef union(parent, rank, x, y):\n xroot = find(parent,... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00039819",
"row_id": 39819,
"seed_ids": "[3165, 1820, 5608]"
} | 0.644055 | Codeforces_39819 | I | [
"find",
"union",
"minimum_tunnels_to_connect_all_planets"
] | 3 | [
[
"minimum_tunnels_to_connect_all_planets",
"find"
],
[
"minimum_tunnels_to_connect_all_planets",
"union"
],
[
"union",
"find"
]
] | 3 | [] | false | [] | false | pytest | true | [] | true | 3fc6acfb3e4ec92422700e3218a375555ce597f2 | 61d7746c85c7b146b0dc59c9513097c14ae9ff8b | |||
v1.0 | instruct | Codeforces | Codeforces_39831_I | A large company has multiple departments and each department has a different number of employees. The company wants to organize a team-building event and plans to set up teams such that each team contains exactly the same number of employees. The goal is to form the largest possible teams with an equal number of employ... | import math
from functools import reduce
def find_gcd(a, b):
while b:
a, b = b, a % b
return a
def maximum_team_size_and_count(n, departments):
# Finding the GCD of all elements in the list
gcd_all = reduce(find_gcd, departments)
# Sum of all employees
total_employees = sum(depart... | from solution import maximum_team_size_and_count
def test_case_1():
assert maximum_team_size_and_count(4, [12, 15, 18, 9]) == (3, 18)
def test_case_2():
assert maximum_team_size_and_count(3, [10, 20, 30]) == (10, 6)
def test_case_3():
assert maximum_team_size_and_count(5, [7, 14, 21, 28, 35]) == ... | [
{
"docstring": null,
"function_declaration": "def find_gcd(a, b):",
"function_name": "find_gcd",
"parameter_list": "(a, b)"
},
{
"docstring": null,
"function_declaration": "def maximum_team_size_and_count(n, departments):",
"function_name": "maximum_team_size_and_count",
"paramet... | [
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 math\nfrom functools import reduce\n\ndef max_team_size_and_count(n, employees):\n \"\"\"\n Returns the maximum team size and the number of such ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00039831",
"row_id": 39831,
"seed_ids": "[4979, 4752, 6353]"
} | 0.668597 | Codeforces_39831 | I | [
"find_gcd",
"maximum_team_size_and_count"
] | 2 | [
[
"maximum_team_size_and_count",
"find_gcd"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 8c89577de651217698ba71982764ea8b857b328e | 7a8410142090b9bcad7538db1a5ee477d77ec739 | |||
v1.0 | instruct | Codeforces | Codeforces_39912_I | Tom works at a warehouse and is in charge of monitoring the stock of different items. He needs a way to efficiently check the quantity of items available within a range of storage units. Each storage unit has a certain item quantity, and Tom often needs to sum up the quantities across a range of contiguous storage unit... | def preprocess_stock(stock):
"""
Preprocess the stock list to create a prefix sum array.
"""
prefix_sum = [0] * (len(stock) + 1)
for i in range(1, len(stock) + 1):
prefix_sum[i] = prefix_sum[i - 1] + stock[i - 1]
return prefix_sum
def query_sum(l, r, prefix_sum):
"""
Given the p... | from solution import preprocess_stock, query_sum, process_queries
def test_preprocess_stock():
stock = [2, 3, 5, 7, 11]
expected_prefix_sum = [0, 2, 5, 10, 17, 28]
assert preprocess_stock(stock) == expected_prefix_sum
def test_query_sum():
stock = [2, 3, 5, 7, 11]
prefix_sum = preprocess_stock(sto... | [
{
"docstring": "Preprocess the stock list to create a prefix sum array.",
"function_declaration": "def preprocess_stock(stock):",
"function_name": "preprocess_stock",
"parameter_list": "(stock)"
},
{
"docstring": "Given the prefix sum array, calculate the sum from index l to r (1-based).",
... | [
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_stock(stock):\n \"\"\"\n Preprocess stock list to create prefix sums array.\n \"\"\"\n prefix_sums = [0] * (len(stock) + 1)\n fo... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00039912",
"row_id": 39912,
"seed_ids": "[1844, 772, 470]"
} | 0.668997 | Codeforces_39912 | I | [
"preprocess_stock",
"query_sum",
"process_queries"
] | 3 | [
[
"process_queries",
"preprocess_stock"
],
[
"process_queries",
"query_sum"
]
] | 2 | [
"process_queries"
] | false | [] | false | pytest | true | [] | true | d3c709c0b6859189513611a4b187b2297e921950 | 55ac1a4af506a13d62ae07072a7a3b6191922d54 | |||
v1.0 | instruct | Codeforces | Codeforces_39936_I | You are given an array of integers of length n, and you need to handle q queries. Each query consists of two integers, `l` and `r` (1 ≤ l ≤ r ≤ n) and asks for the sum of the elements in the subarray from index l to index r (both inclusive).
The first line of the input contains two integers n and q (1 ≤ n, q ≤ 100,000... | def preprocess_prefix_sum(array):
"""
Preprocess the array to create a prefix sum array.
"""
n = len(array)
prefix_sum = [0] * (n + 1)
for i in range(n):
prefix_sum[i + 1] = prefix_sum[i] + array[i]
return prefix_sum
def sum_query(prefix_sum, l, r):
"""
Returns the sum of th... | def test_preprocess_prefix_sum():
assert preprocess_prefix_sum([1, 2, 3, 4, 5]) == [0, 1, 3, 6, 10, 15]
def test_sum_query():
prefix_sum = preprocess_prefix_sum([1, 2, 3, 4, 5])
assert sum_query(prefix_sum, 1, 3) == 6
assert sum_query(prefix_sum, 2, 4) == 9
assert sum_query(prefix_sum, 1, 5) == 15
... | [
{
"docstring": "Preprocess the array to create a prefix sum array.",
"function_declaration": "def preprocess_prefix_sum(array):",
"function_name": "preprocess_prefix_sum",
"parameter_list": "(array)"
},
{
"docstring": "Returns the sum of the subarray from index l to index r inclusive.",
... | [
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 calculate_prefix_sums(arr):\n \"\"\"\n Calculates prefix sums for the given array.\n \"\"\"\n prefix_sums = [0] * (len(arr) + 1)\n for i in... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00039936",
"row_id": 39936,
"seed_ids": "[4518, 5826, 2659]"
} | 0.740912 | Codeforces_39936 | I | [
"preprocess_prefix_sum",
"sum_query",
"handle_queries"
] | 3 | [
[
"handle_queries",
"preprocess_prefix_sum"
],
[
"handle_queries",
"sum_query"
]
] | 2 | [
"handle_queries"
] | false | [] | false | pytest | false | [] | true | 925f05119813df01b11722f846b86ebac5ba078d | 60754f2cb8d70967610949daa0b235c99c4a8efd | |||
v1.0 | instruct | Code_Contests | Code_Contests_0_I | In the town of Techville, there are n bus stops connected by m bus routes. The bus system is designed in such a way that it is always possible to travel from any bus stop to any other bus stop through a series of bus routes. Each bus stop can represent an intersection, and each bus route can be considered a one-way roa... | from collections import deque, defaultdict
def bfs(graph, start):
distances = {node: float('inf') for node in graph}
distances[start] = 0
queue = deque([start])
while queue:
current = queue.popleft()
for neighbor in graph[current]:
if distances[neighbor] == flo... | def test_route_recomputations_case_1():
n, m = 6, 9
routes = [
(1, 5), (5, 4), (1, 2), (2, 3), (3, 4),
(4, 1), (2, 6), (6, 4), (4, 2)
]
k = 4
commute = [1, 2, 3, 4]
assert route_recomputations(n, m, routes, k, commute) == (1, 2)
def test_route_recomputations_case_2():
n, m =... | [
{
"docstring": null,
"function_declaration": "def bfs(graph, start):",
"function_name": "bfs",
"parameter_list": "(graph, start)"
},
{
"docstring": null,
"function_declaration": "def route_recomputations(n, m, routes, k, commute):",
"function_name": "route_recomputations",
"param... | [
0,
0,
0,
0,
0,
0,
1,
1,
0,
1
] | 3 | hard | 0.3 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from collections import deque, defaultdict\n\ndef min_max_recalculations(n, m, edges, k, commute):\n graph = defaultdict(list)\n for u, v in edges:\n... | trial_gpt4o_9 | {
"original_instruction": "",
"prompt_id": "00000000",
"row_id": 0,
"seed_ids": "[8975]"
} | 0.701895 | Code_Contests_0 | I | [
"bfs",
"route_recomputations"
] | 2 | [
[
"route_recomputations",
"bfs"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | c2815cf3cf1df27ed79325b3318d59cec95de036 | 418d00094b7208576993d4ea9f5f881d40846a71 | |||
v1.0 | instruct | Code_Contests | Code_Contests_18_I | You are given a sequence of n integers. Your task is to answer q queries, where each query involves finding the sum of a specific subarray in the sequence.
More formally, you are given an array of integers a_1, a_2, ..., a_n. Each query is described by two integers l and r (1 ≤ l ≤ r ≤ n), and you need to find the sum... | def prefix_sums(arr):
# Create a prefix sums array
n = len(arr)
ps = [0] * (n + 1)
for i in range(1, n + 1):
ps[i] = ps[i - 1] + arr[i - 1]
return ps
def sum_subarray(prefix_sum, l, r):
# Calculate the sum of subarray using prefix sums
return prefix_sum[r] - prefix_sum[l - 1]
def s... | from solution import prefix_sums, sum_subarray, solve
def test_prefix_sums():
assert prefix_sums([3, -2, 5, 1, -6, 3]) == [0, 3, 1, 6, 7, 1, 4]
assert prefix_sums([1, 2, 3, 4, 5]) == [0, 1, 3, 6, 10, 15]
def test_sum_subarray():
ps = [0, 3, 1, 6, 7, 1, 4]
assert sum_subarray(ps, 1, 3) == 6
assert ... | [
{
"docstring": null,
"function_declaration": "def prefix_sums(arr):",
"function_name": "prefix_sums",
"parameter_list": "(arr)"
},
{
"docstring": null,
"function_declaration": "def sum_subarray(prefix_sum, l, r):",
"function_name": "sum_subarray",
"parameter_list": "(prefix_sum, ... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def prefix_sum(arr):\n \"\"\"\n Generates a prefix sum array.\n \"\"\"\n n = len(arr)\n prefix = [0] * (n + 1)\n for i in range(1, n + 1)... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00000018",
"row_id": 18,
"seed_ids": "[5171]"
} | 0.756211 | Code_Contests_18 | I | [
"prefix_sums",
"sum_subarray",
"solve"
] | 3 | [
[
"solve",
"prefix_sums"
],
[
"solve",
"sum_subarray"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 09c3b4b9d763dc8df38a090ea013dccbb11ac772 | 6fc300b390fa60a9547a50026fc151e0532c8ec5 | |||
v1.0 | instruct | Code_Contests | Code_Contests_57_I | A local council organizes various musical events in the city every summer. Due to the popularity of these events, they need a system to manage the schedule and avoid conflicts.
There are n events scheduled, each identified by two numbers: si and ei — the start time and end time of the event, respectively (both inclusi... | def schedule_events(events, num_venues):
n = len(events)
events = sorted(enumerate(events, 1), key=lambda x: x[1][1])
venue_end_time = [0] * num_venues
scheduled_events = []
for event_id, (s, e) in events:
for v in range(num_venues):
if s >= venue_end_time[v]:
ve... | from solution import maximum_events
def test_simple_case():
n = 5
events = [(1, 5), (2, 6), (4, 7), (7, 9), (8, 10)]
m = 2
num_scheduled, scheduled_events = maximum_events(n, events, m)
assert num_scheduled == 4
assert len(scheduled_events) == 4
def test_all_overlap():
n = 4
events = [... | [
{
"docstring": null,
"function_declaration": "def schedule_events(events, num_venues):",
"function_name": "schedule_events",
"parameter_list": "(events, num_venues)"
},
{
"docstring": null,
"function_declaration": "def maximum_events(n, events, m):",
"function_name": "maximum_events"... | [
0,
1
] | 1 | medium | 0.5 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def schedule_events(events, m):\n \"\"\"\n Returns the maximum number of events that can be scheduled without conflicts\n and the number of venues... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00000057",
"row_id": 57,
"seed_ids": "[4419]"
} | 0.70938 | Code_Contests_57 | I | [
"schedule_events",
"maximum_events"
] | 2 | [
[
"maximum_events",
"schedule_events"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | c13416ceabb88558e64cb07f254ab83df2baa2e0 | 937996cc3d782d86f685d97011f4f19652dc6c85 | |||
v1.0 | instruct | Code_Contests | Code_Contests_72_I | In a small town, the local government is planning to construct a series of new roads to improve connectivity among several neighborhoods. The town has n neighborhoods numbered from 1 to n. Currently, there are no roads directly connecting any neighborhoods.
The government has a list of m proposed roads, where each roa... | 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] > ... | import pytest
from solution import minimum_cost_to_connect_all
def test_example():
n = 4
m = 5
roads = [
(1, 2, 3),
(2, 3, 4),
(3, 4, 5),
(1, 4, 1),
(2, 4, 2)
]
assert minimum_cost_to_connect_all(n, m, roads) == 7
def test_not_enough_roads():
n = 4
m... | [
{
"docstring": null,
"function_declaration": "def find(parent, i):",
"function_name": "find",
"parameter_list": "(parent, i)"
},
{
"docstring": null,
"function_declaration": "def union(parent, rank, x, y):",
"function_name": "union",
"parameter_list": "(parent, rank, x, y)"
},
... | [
1,
0,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_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 uni... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00000072",
"row_id": 72,
"seed_ids": "[12516]"
} | 0.727781 | Code_Contests_72 | I | [
"find",
"union",
"minimum_cost_to_connect_all"
] | 3 | [
[
"minimum_cost_to_connect_all",
"find"
],
[
"minimum_cost_to_connect_all",
"union"
],
[
"union",
"find"
]
] | 3 | [] | false | [] | false | pytest | true | [] | true | 43503b188d9dfdeca1ecf15f6cbcb217da5df25e | 17ec35f2a680a789dbce411b69680f9accd4e463 | |||
v1.0 | instruct | Code_Contests | Code_Contests_85_I | A network of computers is represented as an undirected graph where nodes are computers and edges represent a direct connection between two computers. Each computer can send data to any other computer directly if they have a direct connection, or indirectly through other computers.
A network is resilient if removing an... | def is_network_resilient(n, m, connections):
from collections import defaultdict, deque
def bfs(start, removed):
visited = [False] * n
queue = deque([start])
visited[start] = True
while queue:
node = queue.popleft()
for neighbor in graph[node... | def test_is_network_resilient_yes():
n = 4
m = 4
connections = [(0, 1), (1, 2), (2, 3), (3, 0)]
assert is_network_resilient(n, m, connections) == "Yes"
def test_is_network_resilient_no():
n = 4
m = 3
connections = [(0, 1), (1, 2), (2, 3)]
assert is_network_resilient(n, m, connections) =... | [
{
"docstring": null,
"function_declaration": "def is_network_resilient(n, m, connections):",
"function_name": "is_network_resilient",
"parameter_list": "(n, m, connections)"
},
{
"docstring": null,
"function_declaration": "def evaluate_datasets(datasets):",
"function_name": "evaluate... | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from collections import defaultdict\n\ndef is_resilient(n, connections):\n def dfs(u, visited, parent):\n visited[u] = True\n for v in gra... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00000085",
"row_id": 85,
"seed_ids": "[11134]"
} | 0.592397 | Code_Contests_85 | I | [
"is_network_resilient",
"evaluate_datasets",
"parse_input"
] | 3 | [
[
"evaluate_datasets",
"is_network_resilient"
]
] | 1 | [
"parse_input"
] | false | [] | false | pytest | false | [] | true | 943823a3dcdcd9a465658aee49576b5c7c61e831 | 69ff302ef25e7fac312e5a8cedd3d2829c87b864 | |||
v1.0 | instruct | Code_Contests | Code_Contests_133_I | A company wants to design a security system that allows employees to enter the building with a special passcode. Each passcode is represented by a string composed solely of digits ('0' to '9'). The passcode is considered valid if it does not contain any two adjacent digits that are the same.
You need to write a functi... | def is_valid_passcode(passcodes):
results = []
for passcode in passcodes:
if all(passcode[i] != passcode[i + 1] for i in range(len(passcode) - 1)):
results.append("Valid")
else:
results.append("Invalid")
return results
def check_passcodes(T, passcodes):
results =... | from solution import is_valid_passcode, check_passcodes
def test_is_valid_passcode():
assert is_valid_passcode(["123456"]) == ["Valid"]
assert is_valid_passcode(["112345"]) == ["Invalid"]
assert is_valid_passcode(["121212"]) == ["Valid"]
assert is_valid_passcode(["987654321"]) == ["Valid"]
assert i... | [
{
"docstring": null,
"function_declaration": "def is_valid_passcode(passcodes):",
"function_name": "is_valid_passcode",
"parameter_list": "(passcodes)"
},
{
"docstring": null,
"function_declaration": "def check_passcodes(T, passcodes):",
"function_name": "check_passcodes",
"param... | [
1,
1
] | 2 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_valid_passcode(passcode):\n \"\"\"\n Determines if the given passcode is valid. A passcode is valid if it does not contain \n any two adjac... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00000133",
"row_id": 133,
"seed_ids": "[8865]"
} | 0.588186 | Code_Contests_133 | I | [
"is_valid_passcode",
"check_passcodes"
] | 2 | [
[
"check_passcodes",
"is_valid_passcode"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 4da1a67047b0aa5ecbca5f5507125e5bcbb8df12 | 4a7a5865592745e4bf0bd31a5523908546ae9baa | |||
v1.0 | instruct | Code_Contests | Code_Contests_295_I | Given an array of positive integers, find the largest sum of a contiguous subarray using the divide-and-conquer approach. Your function should use recursion to solve the problem.
Input
The input consists of:
- The first line is an integer n (1 ≤ n ≤ 300000), the number of elements in the array.
- The second line is n... | def max_crossing_sum(arr, left, mid, right):
"""
Find the maximum sum of a subarray that crosses the midpoint.
"""
left_sum = float('-inf')
sum = 0
for i in range(mid, left - 1, -1):
sum += arr[i]
if sum > left_sum:
left_sum = sum
right_sum = float('-... | from solution import max_sum_of_subarray
def test_single_element():
assert max_sum_of_subarray([1]) == 1
assert max_sum_of_subarray([-1]) == -1
def test_all_positive():
assert max_sum_of_subarray([1, 2, 3, 4, 5]) == 15
def test_all_negative():
assert max_sum_of_subarray([-1, -2, -3, -4]) == -1
def t... | [
{
"docstring": "Find the maximum sum of a subarray that crosses the midpoint.",
"function_declaration": "def max_crossing_sum(arr, left, mid, right):",
"function_name": "max_crossing_sum",
"parameter_list": "(arr, left, mid, right)"
},
{
"docstring": "Find the maximum sum of a contiguous sub... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def max_crossing_sum(arr, left, mid, right):\n \"\"\"\n Helper function to find the maximum crossing sum.\n \"\"\"\n # Include elements on left... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00000295",
"row_id": 295,
"seed_ids": "[12531]"
} | 0.760449 | Code_Contests_295 | I | [
"max_crossing_sum",
"max_sub_array_sum",
"max_sum_of_subarray"
] | 3 | [
[
"max_sub_array_sum",
"max_crossing_sum"
],
[
"max_sum_of_subarray",
"max_sub_array_sum"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 04ba754783592a86b31bb509f99c0ee09ee07b22 | 3733b8a1ef240447a03f05af249bfdf84ee409ab | |||
v1.0 | instruct | Code_Contests | Code_Contests_300_I | You are given an enchanting forest which is a grid of size NxM. Each cell in the grid either contains a tree (represented by '#') or is empty (represented by '.'). A tree can spread its magical aura if there is an empty cell adjacent to it (in the four possible directions: north, south, east, and west). The magical aur... | def spread_forest(N, M, T, forest):
def spread_once(forest):
new_forest = [row[:] for row in forest] # Copy the current forest
for r in range(N):
for c in range(M):
if forest[r][c] == '#': # Tree found, spread to adjacent cells
if r > 0 and fo... | def test_enchanting_forest_sample_case():
N, M, T = 3, 3, 2
grid = [
".#.",
"...",
"#.."
]
expected_output = [
"###",
"###",
"###"
]
assert spread_forest(N, M, T, grid) == expected_output
def test_enchanting_forest_no_initial_trees():
N, M, T ... | [
{
"docstring": null,
"function_declaration": "def spread_forest(N, M, T, forest):",
"function_name": "spread_forest",
"parameter_list": "(N, M, T, forest)"
},
{
"docstring": null,
"function_declaration": "def enchanting_forest_solution(N, M, T, grid):",
"function_name": "enchanting_f... | [
1,
0,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def spread_forest(N, M, T, forest):\n def spread_once(forest):\n new_forest = [row[:] for row in forest] # Copy the current forest\n \n ... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00000300",
"row_id": 300,
"seed_ids": "[13089]"
} | 0.578196 | Code_Contests_300 | I | [
"spread_forest",
"enchanting_forest_solution"
] | 2 | [
[
"enchanting_forest_solution",
"spread_forest"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | d5de419cd8784b94ba91984a93a308786795281b | 50a6c1693ca094ec66191349cf7973b25cb657db | |||
v1.0 | instruct | Code_Contests | Code_Contests_323_I | Sana is a robotics engineer working on a team designing a robot that can traverse a grid. The robot starts at the top-left corner of the grid (at position (1, 1)) and aims to reach the bottom-right corner (at position (n, m)). The grid is composed of cells, and each cell contains a non-negative integer representing the... | def min_cost(grid):
"""
Calculates the minimum total cost for the robot to reach the bottom-right corner of the grid.
Parameters:
grid (list of list of int): The grid with non-negative integers representing the cost of each cell.
Returns:
int: The minimum total cost to reach the bottom-right c... | from solution import calculate_min_cost
def test_min_cost_example_1():
n = 3
m = 3
grid_values = [1, 3, 1, 1, 5, 1, 4, 2, 1]
assert calculate_min_cost(n, m, grid_values) == 7
def test_min_cost_example_2():
n = 2
m = 2
grid_values = [1, 2, 1, 1]
assert calculate_min_cost(n, m, grid_valu... | [
{
"docstring": "Calculates the minimum total cost for the robot to reach the bottom-right corner of the grid.\n\nParameters:\ngrid (list of list of int): The grid with non-negative integers representing the cost of each cell.\n\nReturns:\nint: The minimum total cost to reach the bottom-right corner of the grid.... | [
1,
0,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def min_cost(grid):\n \"\"\"\n Calculates the minimum total cost for the robot to reach the bottom-right corner of the grid.\n\n Parameters:\n ... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00000323",
"row_id": 323,
"seed_ids": "[1728]"
} | 0.724064 | Code_Contests_323 | I | [
"min_cost",
"calculate_min_cost"
] | 2 | [
[
"calculate_min_cost",
"min_cost"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | c3560ff917f7a0de10837d25bcde3922b748394a | 30bc78cb2f9a7cd5ec8ce19a5586ed7fd3ffe4c6 | |||
v1.0 | instruct | Code_Contests | Code_Contests_353_I | Little bunny Bolo loves prime numbers. Given an integer n, he wants to find the smallest positive integer that is greater than or equal to n and is a prime number.
A prime number is a natural number greater than 1 that is not a product of two smaller natural numbers. For example, the first 5 prime numbers are 2, 3, 5,... | def is_prime(num):
"""
Check if a number is prime.
"""
if num <= 1:
return False
if num <= 3:
return True
if num % 2 == 0 or num % 3 == 0:
return False
i = 5
while i * i <= num:
if num % i == 0 or num % (i + 2) == 0:
return False
i += 6... | from solution import is_prime, smallest_prime_greater_or_equal
def test_is_prime():
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(4) == False
assert is_prime(5) == True
assert is_prime(29) == True
assert is_prime(1) == False
def test_smallest_prime_greater_or_equal():
... | [
{
"docstring": "Check if a number is prime.",
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": "Finds the smallest prime number greater than or equal to n.",
"function_declaration": "def smallest_prime_greater_or_equal... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(number):\n if number <= 1:\n return False\n if number <= 3:\n return True\n if number % 2 == 0 or number % 3 == 0:\n ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00000353",
"row_id": 353,
"seed_ids": "[9826]"
} | 0.568184 | Code_Contests_353 | I | [
"is_prime",
"smallest_prime_greater_or_equal"
] | 2 | [
[
"smallest_prime_greater_or_equal",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 081193d17795f7bde4250c3c9d0cd9446eb470b3 | d3f2554913d443e95add73494496af78fe6cb17d | |||
v1.0 | instruct | Code_Contests | Code_Contests_356_I | Alexa is learning about number theory and has come across an interesting problem involving prime numbers. She is trying to find an efficient way to determine whether numbers in a given range are prime.
A prime number is a natural number greater than 1 that has no positive divisors other than 1 and itself.
Alexa decid... | def count_primes_in_range(l, r, prime_sieve, prime_counts):
"""
Returns the count of prime numbers between l and r, inclusive.
prime_sieve: list of booleans where prime_sieve[i] is True if i is a prime number
prime_counts: list where prime_counts[i] is the number of prime numbers <= i
"""
return... | import pytest
from solution import preprocess_primes, process_queries
def test_preprocess_primes():
sieve, prime_counts = preprocess_primes(30)
assert sieve[2] == True
assert sieve[3] == True
assert sieve[4] == False
assert sieve[29] == True
assert prime_counts[10] == 4
assert prime_counts[... | [
{
"docstring": "Returns the count of prime numbers between l and r, inclusive.\nprime_sieve: list of booleans where prime_sieve[i] is True if i is a prime number\nprime_counts: list where prime_counts[i] is the number of prime numbers <= i",
"function_declaration": "def count_primes_in_range(l, r, prime_sie... | [
0,
0,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def sieve_of_eratosthenes(n):\n \"\"\"\n Generates a list of prime numbers up to n using the Sieve of Eratosthenes algorithm.\n \"\"\"\n is_pri... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00000356",
"row_id": 356,
"seed_ids": "[2108]"
} | 0.609848 | Code_Contests_356 | I | [
"count_primes_in_range",
"preprocess_primes",
"process_queries"
] | 3 | [
[
"process_queries",
"count_primes_in_range"
]
] | 1 | [
"process_queries"
] | false | [] | false | pytest | true | [] | true | 065313555551c0a89b9c4913be2190268236de8c | a72a1ce88ed9be308bae2a0a8456ed57c0e796da | |||
v1.0 | instruct | Code_Contests | Code_Contests_392_I | You are given an array of integers and multiple queries. Each query consists of a pair of indices, and the task is to compute the sum of the elements between these indices (inclusive).
Input
The first line contains an integer n (1 ≤ n ≤ 100000) — the number of elements in the array. The second line contains n space-s... | def preprocess_prefix_sums(arr):
"""
Preprocesses the array to compute the prefix sums for efficient range-sum queries.
"""
n = len(arr)
prefix_sums = [0] * (n + 1)
for i in range(n):
prefix_sums[i + 1] = prefix_sums[i] + arr[i]
return prefix_sums
def range_sum(prefix_sums, l, r):
... | from solution import preprocess_prefix_sums, range_sum, process_queries
def test_preprocess_prefix_sums():
assert preprocess_prefix_sums([1, 2, 3, 4, 5]) == [0, 1, 3, 6, 10, 15]
def test_range_sum():
prefix_sums = preprocess_prefix_sums([1, 2, 3, 4, 5])
assert range_sum(prefix_sums, 1, 3) == 6
assert ... | [
{
"docstring": "Preprocesses the array to compute the prefix sums for efficient range-sum queries.",
"function_declaration": "def preprocess_prefix_sums(arr):",
"function_name": "preprocess_prefix_sums",
"parameter_list": "(arr)"
},
{
"docstring": "Computes the sum of elements in the range [... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def range_sum(n, arr, queries):\n \"\"\"\n Computes the sum of elements between given pairs of indices (inclusive) for multiple queries.\n\n Args:... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00000392",
"row_id": 392,
"seed_ids": "[8469]"
} | 0.692192 | Code_Contests_392 | I | [
"preprocess_prefix_sums",
"range_sum",
"process_queries"
] | 3 | [
[
"process_queries",
"preprocess_prefix_sums"
],
[
"process_queries",
"range_sum"
]
] | 2 | [
"process_queries"
] | false | [] | false | pytest | true | [] | true | b6b1df4c31af22c2482f25e2f0a1f4b55c042888 | 4eb3ba218b76fb41c5e95d94eb3562d510b79c48 | |||
v1.0 | instruct | Code_Contests | Code_Contests_417_I | Dr. Crypton, a renowned mathematician, is working on a new encryption algorithm that involves manipulating strings. He has discovered that a specific type of permutation of the characters in a string has interesting cryptographic properties. These permutations are called "special permutations" and are defined as follow... | import math
def count_derangements(n):
"""
Calculate the number of derangements (permutations where no element remains in its original position)
for a given n (length of the string).
"""
if n == 0:
return 1
elif n == 1:
return 0
elif n == 2:
return 1
der = [0] * ... | from solution import compute_special_permutations
def test_example_case():
input_lines = [
"3",
"AB",
"ABC",
"ABCD"
]
expected_output = [1, 2, 9]
assert compute_special_permutations(input_lines) == expected_output
def test_single_char():
input_lines = [
"1",... | [
{
"docstring": "Calculate the number of derangements (permutations where no element remains in its original position)\nfor a given n (length of the string).",
"function_declaration": "def count_derangements(n):",
"function_name": "count_derangements",
"parameter_list": "(n)"
},
{
"docstring"... | [
0,
1,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from math import factorial\n\ndef count_special_permutations(n):\n \"\"\"\n Count the number of derangements (special permutations where no element\n... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00000417",
"row_id": 417,
"seed_ids": "[4275]"
} | 0.662073 | Code_Contests_417 | I | [
"count_derangements",
"special_permutations",
"process_input",
"compute_special_permutations"
] | 4 | [
[
"compute_special_permutations",
"process_input"
],
[
"compute_special_permutations",
"special_permutations"
],
[
"special_permutations",
"count_derangements"
]
] | 3 | [
"process_input"
] | false | [] | false | pytest | true | [] | true | e7c16de3a117748e473a88dd1360b5b84ea8fece | b96553472703338e93e93d63d6deb2df49f46361 | |||
v1.0 | instruct | Code_Contests | Code_Contests_454_I | You are tasked with organizing a special event for the Emblem Guild. The guild has members who possess different badges indicating their levels of expertise. Each member of the guild has at least one badge which represents their skill in a particular area. The event involves two types of activities: basic training sess... | def count_training_pairs(test_cases):
results = []
for badges_list in test_cases:
n = len(badges_list)
basic_pairs = 0
expert_pairs = 0
badge_dict = {}
for idx, badges in enumerate(badges_list):
badg_tuple = tuple(sorted(badges))
if badg_tupl... | def test_solution():
# Sample test case 1
input_data = "2\n2\n2 1 2\n2 2 3\n3\n2 1 2\n2 2 3\n2 1 2\n"
expected_output = "1 0\n3 1"
assert solution(input_data) == expected_output
# Additional test case 1
input_data = "1\n2\n2 1 3\n2 3 4\n"
expected_output = "1 0"
assert solution(input_da... | [
{
"docstring": null,
"function_declaration": "def count_training_pairs(test_cases):",
"function_name": "count_training_pairs",
"parameter_list": "(test_cases)"
},
{
"docstring": null,
"function_declaration": "def parse_input(input_data):",
"function_name": "parse_input",
"paramet... | [
0,
0,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def count_training_pairs(T, cases):\n results = []\n for i in range(T):\n N = cases[i][0]\n members_badges = cases[i][1]\n \n ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00000454",
"row_id": 454,
"seed_ids": "[12459]"
} | 0.674466 | Code_Contests_454 | I | [
"count_training_pairs",
"parse_input",
"solution"
] | 3 | [
[
"solution",
"count_training_pairs"
],
[
"solution",
"parse_input"
]
] | 2 | [
"parse_input"
] | false | [] | false | pytest | false | [] | true | 534dc77b0b2b1ed7cf2ad3c96acecde52bb8fd64 | 584e195e6f6efe0067aad2d0066c704d02b9e4ae | |||
v1.0 | instruct | Code_Contests | Code_Contests_459_I | In a certain city, there are n intersections and m bidirectional roads connecting them. Each road has a specific travel time associated with it. The city decided to replace the old street lamps with new eco-friendly street lamps. The goal is to ensure each intersection has enough light to be adequately visible, both di... | import heapq
def dijkstra(n, graph, start, max_time):
distances = [float('inf')] * n
distances[start] = 0
min_heap = [(0, start)]
while min_heap:
current_distance, u = heapq.heappop(min_heap)
if current_distance > distances[u]:
continue
for v, ... | from solution import find_min_street_lamps
def test_basic_case():
n = 4
m = 4
roads = [(1, 2, 2), (2, 3, 4), (3, 4, 1), (4, 1, 3)]
max_time = 3
assert find_min_street_lamps(n, roads, max_time) == 2
def test_single_intersection():
n = 1
m = 0
roads = []
max_time = 1
assert find_... | [
{
"docstring": null,
"function_declaration": "def dijkstra(n, graph, start, max_time):",
"function_name": "dijkstra",
"parameter_list": "(n, graph, start, max_time)"
},
{
"docstring": null,
"function_declaration": "def find_min_street_lamps(n, roads, max_time):",
"function_name": "fi... | [
0,
0,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import heapq\n\ndef min_street_lamps(n, m, roads, t):\n # Create an adjacency list representing the graph\n graph = [[] for _ in range(n + 1)]\n f... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00000459",
"row_id": 459,
"seed_ids": "[5752]"
} | 0.688697 | Code_Contests_459 | I | [
"dijkstra",
"find_min_street_lamps",
"solution"
] | 3 | [
[
"find_min_street_lamps",
"dijkstra"
],
[
"solution",
"find_min_street_lamps"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | ef658d7a611af59da4fa5f61cc218707dbe47a44 | baf47883e97a32a838a9507885185807ec31e4a4 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.