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_18829_I
In a faraway land, an ancient kingdom maintains a unique and strict financial system. Every citizen receives exactly one integer amount of gold coins. As a part of a fair taxation system, the king has mandated a new rule: A citizen must pay tax such that the total number of gold coins paid is either a prime number or ...
def is_prime(num): if num < 2: return False if num in (2, 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 max_prime_tax(gold): ...
def test_is_prime(): assert is_prime(2) == True assert is_prime(3) == True assert is_prime(4) == False assert is_prime(17) == True assert is_prime(18) == False assert is_prime(1) == False def test_max_prime_tax(): assert max_prime_tax(11) == 11 assert max_prime_tax(13) == 13 assert ...
[ { "docstring": null, "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": null, "function_declaration": "def max_prime_tax(gold):", "function_name": "max_prime_tax", "parameter_list": "(gold)" }, { "docstri...
[ 0, 1, 1, 1, 1, 1, 0, 1, 1 ]
7
easy
0.778
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def sieve_of_eratosthenes(max_num):\n \"\"\"\n Returns a list of prime numbers up to max_num using the Sieve of Eratosthenes algorithm.\n \"\"\"\n ...
trial_gpt4o_3
{ "original_instruction": "", "prompt_id": "00018829", "row_id": 18829, "seed_ids": "[4517]" }
0.587525
Codeforces_18829
I
[ "is_prime", "max_prime_tax", "compute_taxes" ]
3
[ [ "compute_taxes", "max_prime_tax" ], [ "max_prime_tax", "is_prime" ] ]
2
[]
false
[]
false
pytest
false
[]
true
033a7c7f147365b91e8d002e5e480845a387b9cf
487b80b253bb747177f63336ff3e82a5c11da2e0
v1.0
instruct
Codeforces
Codeforces_18882_I
Alex is a food enthusiast who recently started experimenting with recipes to create unique dishes. He has `n` recipes, each recipe having a unique ID ranging from `1` to `n`. Alex wants to prepare a gourmet meal by selecting a subset of these recipes. However, due to various dietary restrictions and preferences, he can...
def max_recipes(n, m, recipes): def can_add_recipe(selected_recipes, new_recipe): for ingredient in new_recipe: if ingredient in selected_recipes: return False return True def backtrack(index, selected_recipes): if index == len(recipes): return le...
from solution import gourmet_meal def test_example_case(): n = 5 m = 7 recipes = [ "3 1 2 3", "2 3 4", "3 5 6 7", "2 2 5", "1 4" ] assert gourmet_meal(n, m, recipes) == 3 def test_single_recipe(): n = 1 m = 5 recipes = ["3 1 2 3"] assert gour...
[ { "docstring": null, "function_declaration": "def max_recipes(n, m, recipes):", "function_name": "max_recipes", "parameter_list": "(n, m, recipes)" }, { "docstring": null, "function_declaration": "def gourmet_meal(n, m, raw_recipes):", "function_name": "gourmet_meal", "parameter_...
[ 1, 1, 1, 1, 1, 1, 0, 1, 0, 1 ]
8
easy
0.8
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def max_recipes(n, m, recipes):\n from itertools import combinations\n \n def has_common_ingredients(recipe1, recipe2):\n return not set(recip...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00018882", "row_id": 18882, "seed_ids": "[4111]" }
0.717194
Codeforces_18882
I
[ "max_recipes", "gourmet_meal" ]
2
[ [ "gourmet_meal", "max_recipes" ] ]
1
[]
false
[]
false
pytest
true
[]
true
f768d57af8daa7bfac2d6e3e38049883a443a5b6
e2bb7fe4c10e377cf0eaccf102ede0fa0250fa91
v1.0
instruct
Codeforces
Codeforces_18934_I
Given a string array words, you need to find all the pairs of distinct indices (i, j) in the array such that the concatenation of words[i] and words[j] is a palindrome. A palindrome is a word, phrase, number, or other sequences of characters that reads the same backward as forward (ignoring spaces, punctuation, and ca...
def is_palindrome(s): return s == s[::-1] def palindrome_pairs(words): result = [] word_dict = {word: i for i, word in enumerate(words)} for i, word in enumerate(words): for j in range(len(word) + 1): prefix = word[:j] suffix = word[j:] if i...
from solution import palindrome_pairs def test_example_1(): words = ["bat", "tab", "cat"] expected = [(0, 1), (1, 0)] result = palindrome_pairs(words) assert set(result) == set(expected) def test_example_2(): words = ["abcd", "dcba", "lls", "s", "sssll"] expected = [(0, 1), (1, 0), (3, 2), (2,...
[ { "docstring": null, "function_declaration": "def is_palindrome(s):", "function_name": "is_palindrome", "parameter_list": "(s)" }, { "docstring": null, "function_declaration": "def palindrome_pairs(words):", "function_name": "palindrome_pairs", "parameter_list": "(words)" } ]
[ 0, 0, 0, 0, 0, 0, 1, 0, 0 ]
1
hard
0.111
{ "trial_gpt4o_0": null, "trial_gpt4o_1": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared1_results_combined.jsonl", "solution_code": "def palindrome_pairs(words):\n def is_palindrome(s):\n return s == s[::-1]\n\n pairs = []\n word_dict = {word: i for ...
trial_gpt4o_7
{ "original_instruction": "", "prompt_id": "00018934", "row_id": 18934, "seed_ids": "[3515]" }
0.786084
Codeforces_18934
I
[ "is_palindrome", "palindrome_pairs" ]
2
[ [ "palindrome_pairs", "is_palindrome" ] ]
1
[]
false
[]
false
pytest
true
[]
true
1740a5e8f3134b7630a0b6a0b3d6f89e3779b220
38b231b92d69be55e23e6d0fb70ea987a148ba9a
v1.0
instruct
Codeforces
Codeforces_18948_I
You are given a list of sets of integers. Each set contains different, unique integers and no set is empty. Your task is to merge sets following a specific algorithm: 1. Find two sets, A and B, such that they have the largest intersection (i.e., the maximum number of common elements). If there are multiple such pairs,...
def merge_sets(sets): """ Given a list of sets, merges the sets following a specific algorithm until only one set remains. """ while len(sets) > 1: max_intersection_size = 0 sets_to_merge = (0, 1) # Find pair with largest intersection for i in range(len(sets)): ...
from solution import find_final_set def test_example_case(): data = [ "3 1 2 3", "3 2 3 4", "3 4 5 6" ] result = find_final_set(3, data) assert result == [1, 2, 3, 4, 5, 6] def test_single_set(): data = [ "3 1 2 3" ] result = find_final_set(1, data) asse...
[ { "docstring": "Given a list of sets, merges the sets following a specific algorithm\nuntil only one set remains.", "function_declaration": "def merge_sets(sets):", "function_name": "merge_sets", "parameter_list": "(sets)" }, { "docstring": null, "function_declaration": "def convert_inpu...
[ 0, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
9
easy
0.9
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def merge_sets(sets):\n while len(sets) > 1:\n max_intersection_size = -1\n merge_indices = (0, 1)\n \n for i in range(len(sets...
trial_gpt4o_7
{ "original_instruction": "", "prompt_id": "00018948", "row_id": 18948, "seed_ids": "[7616]" }
0.609864
Codeforces_18948
I
[ "merge_sets", "convert_input_to_sets", "find_final_set" ]
3
[ [ "find_final_set", "convert_input_to_sets" ], [ "find_final_set", "merge_sets" ] ]
2
[]
false
[]
false
pytest
true
[]
true
1b307b766134d526e0d9f773f15c61a318f53e3b
2952e22ad323cd9c910fb0bf0d0749c46f23ea6d
v1.0
instruct
Codeforces
Codeforces_18978_I
After a sudden rise in technological advancements, the citizens of Techland want to establish a new communication network by connecting various nodes spread across their country. The nodes are positioned at various (x, y) coordinates on a 2D plane, and they can only connect directly if their connection distance does no...
import math def find_parent(parent, i): if parent[i] == i: return i else: parent[i] = find_parent(parent, parent[i]) return parent[i] def union(parent, rank, x, y): root_x = find_parent(parent, x) root_y = find_parent(parent, y) if root_x != root_y: if rank[root_...
from solution import min_max_distance_to_connect_all_nodes def test_example_case(): coordinates = [(0, 0), (3, 4), (6, 8), (10, 10)] assert abs(min_max_distance_to_connect_all_nodes(coordinates) - 5.000000) < 10**-6 def test_two_nodes(): coordinates = [(0, 0), (0, 3)] assert abs(min_max_distance_to_co...
[ { "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, 1, 1, 1, 0, 0, 1, 1 ]
5
medium
0.556
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "import math\nimport heapq\n\n\ndef minimum_maximum_distance(n, coordinates):\n def euclidean_distance(p1, p2):\n return math.sqrt((p1[0] - p2[0]) **...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00018978", "row_id": 18978, "seed_ids": "[5301]" }
0.618355
Codeforces_18978
I
[ "find_parent", "union", "compute_distance", "minimum_spanning_tree_kruskal", "min_max_distance_to_connect_all_nodes" ]
5
[ [ "min_max_distance_to_connect_all_nodes", "minimum_spanning_tree_kruskal" ], [ "minimum_spanning_tree_kruskal", "compute_distance" ], [ "minimum_spanning_tree_kruskal", "find_parent" ], [ "minimum_spanning_tree_kruskal", "union" ], [ "union", "find_parent" ...
5
[]
false
[]
false
pytest
true
[]
true
e89eb46f728020345a9744a50bc9f140bdcf3328
e6fd4598ba320adc6b1e5ea7115991677fe549f2
v1.0
instruct
Codeforces
Codeforces_19031_I
A game company has developed a simple game involving a grid of size nxn. Each cell on the grid can either contain a '1' (indicating a barrier) or a '0' (indicating a free path). The goal of the game is to navigate from the top-left corner of the grid (0,0) to the bottom-right corner (n-1,n-1) by moving only right or do...
def is_path_possible(grid): """ Determines if there is a path from the top-left corner to the bottom-right corner of the grid avoiding barriers (1's). The function returns 'YES' if there is a path and 'NO' otherwise. :param grid: List of strings where each string is a row of the grid. :ret...
from solution import is_path_possible, is_path_possible_from_input def test_is_path_possible_single_path(): grid = ["0100", "0000", "0110", "0000"] assert is_path_possible(grid) == 'YES' def test_is_path_possible_no_path(): grid = ["010", "010", "011"] assert is_path_possible(grid) == 'NO' def test_i...
[ { "docstring": "Determines if there is a path from the top-left corner to the bottom-right corner\nof the grid avoiding barriers (1's). The function returns 'YES' if there is a \npath and 'NO' otherwise.\n\n:param grid: List of strings where each string is a row of the grid.\n:return: 'YES' if there is a path, ...
[ 0, 0, 0, 1, 0, 1, 1, 0, 0, 0 ]
3
hard
0.3
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_path_possible(n, grid):\n \"\"\"\n Determines if there is a path from the top-left to the bottom-right of the grid.\n \n :param n: int, siz...
trial_gpt4o_6
{ "original_instruction": "", "prompt_id": "00019031", "row_id": 19031, "seed_ids": "[1383]" }
0.797113
Codeforces_19031
I
[ "is_path_possible", "is_path_possible_from_input" ]
2
[ [ "is_path_possible_from_input", "is_path_possible" ] ]
1
[]
false
[]
false
pytest
true
[]
true
064df5fa197949418e9030f5512edd8ebc7ae7d6
d5b7547b5a5bdc2565e05797ca7e98124a2fe5bb
v1.0
instruct
Codeforces
Codeforces_19037_I
You are given a list of integers, and your task is to identify the largest subset of integers such that no two integers in the subset have a common prime factor. In other words, any pair of numbers in the subset should be coprime. The input consists of two lines: The first line contains an integer n (1 ≤ n ≤ 1000), th...
def gcd(a, b): while b: a, b = b, a % b return a def has_common_prime_factor(a, b): return gcd(a, b) != 1 def largest_coprime_subset_size(n, nums): subsets = [] # Store all subsets that are pairwise coprime for num in nums: appended = False for subset in subsets: ...
from solution import largest_coprime_subset_size def test_largest_coprime_subset_size_example(): assert largest_coprime_subset_size(6, [30, 1, 3, 15, 7, 11]) == 4 def test_single_element(): assert largest_coprime_subset_size(1, [5]) == 1 def test_all_prime_numbers(): assert largest_coprime_subset_size(4,...
[ { "docstring": null, "function_declaration": "def gcd(a, b):", "function_name": "gcd", "parameter_list": "(a, b)" }, { "docstring": null, "function_declaration": "def has_common_prime_factor(a, b):", "function_name": "has_common_prime_factor", "parameter_list": "(a, b)" }, { ...
[ 0, 1, 0, 0, 0, 0, 1, 1, 0, 0 ]
3
hard
0.3
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "from math import gcd\nfrom functools import reduce\n\ndef largest_coprime_subset(n, numbers):\n \"\"\"\n Finds the size of the largest subset of coprime...
trial_gpt4o_7
{ "original_instruction": "", "prompt_id": "00019037", "row_id": 19037, "seed_ids": "[284]" }
0.601193
Codeforces_19037
I
[ "gcd", "has_common_prime_factor", "largest_coprime_subset_size" ]
3
[ [ "has_common_prime_factor", "gcd" ], [ "largest_coprime_subset_size", "gcd" ] ]
2
[]
false
[]
false
pytest
true
[]
true
becb98da15409841c3fde669f79ee71c1d0cf2be
4ead2de39afaa221055136a23ae4a2d6410c8789
v1.0
instruct
Codeforces
Codeforces_19039_I
You are given a sequence of n integers. Your task is to answer m queries, where each query asks for the greatest common divisor (GCD) of a subarray of the original sequence. The GCD of a subset of numbers is the largest positive integer that divides each of the numbers. For example, the GCD of the sequence [12, 15, 2...
import math from functools import reduce def gcd(a, b): """ Returns the greatest common divisor of a and b. """ while b: a, b = b, a % b return a def get_subarray_gcd(arr, l, r): """ Returns the gcd of the subarray from index l to r (inclusive) """ subarray = arr[l-1:r] ...
from solution import solve_gcd_queries def test_solve_gcd_queries_example(): n = 6 array = [12, 15, 21, 24, 18, 30] queries = [(1, 3), (2, 5), (1, 6)] expected = [3, 3, 3] assert solve_gcd_queries(n, array, queries) == expected def test_single_element_array(): n = 1 array = [5] queries...
[ { "docstring": "Returns the greatest common divisor of a and b.", "function_declaration": "def gcd(a, b):", "function_name": "gcd", "parameter_list": "(a, b)" }, { "docstring": "Returns the gcd of the subarray from index l to r (inclusive)", "function_declaration": "def get_subarray_gcd(...
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
10
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "import math\nfrom functools import reduce\n\ndef gcd(a, b):\n while b:\n a, b = b, a % b\n return a\n\ndef gcd_of_subarray(arr, l, r):\n retur...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00019039", "row_id": 19039, "seed_ids": "[5560]" }
0.778522
Codeforces_19039
I
[ "gcd", "get_subarray_gcd", "solve_gcd_queries" ]
3
[ [ "get_subarray_gcd", "gcd" ], [ "solve_gcd_queries", "get_subarray_gcd" ] ]
2
[]
false
[]
false
pytest
true
[]
true
182637423b5c6201c0db6c7cd61618883152086b
8893bebe6b8ac0d0bc5f2fafb33393944671346d
v1.0
instruct
Codeforces
Codeforces_19065_I
**Problem Statement:** Mario loves solving puzzles and has recently taken up solving Sudoku puzzles. In the traditional Sudoku puzzle, there is a 9x9 grid that needs to be filled with digits from 1 to 9. Each row, each column, and each of the 3x3 smaller grids must contain all the digits from 1 to 9 without repetition...
def is_valid(board, row, col, num): """ Checks whether a given number can be placed at board[row][col] according to the Sudoku rules. """ # Check row for i in range(9): if board[row][i] == num: return False # Check column for i in range(9): if board[i][col] =...
from solution import solve_sudoku def test_solve_sudoku_no_constraints(): sudoku = [ [5, 3, 0, 0, 7, 0, 0, 0, 0], [6, 0, 0, 1, 9, 5, 0, 0, 0], [0, 9, 8, 0, 0, 0, 0, 6, 0], [8, 0, 0, 0, 6, 0, 0, 0, 3], [4, 0, 0, 8, 0, 3, 0, 0, 1], [7, 0, 0, 0, 2, 0, 0, 0, 6], ...
[ { "docstring": "Checks whether a given number can be placed at board[row][col]\naccording to the Sudoku rules.", "function_declaration": "def is_valid(board, row, col, num):", "function_name": "is_valid", "parameter_list": "(board, row, col, num)" }, { "docstring": "Backtracking helper funct...
[ 1, 1, 0, 0, 0, 0, 0, 0, 0, 0 ]
2
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_valid(board, row, col, num):\n \"\"\"\n Checks whether a given number can be placed at board[row][col]\n according to the Sudoku rules.\n \...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00019065", "row_id": 19065, "seed_ids": "[1806]" }
0.660796
Codeforces_19065
I
[ "is_valid", "solve_sudoku_helper", "validate_constraints", "solve_sudoku" ]
4
[ [ "solve_sudoku", "solve_sudoku_helper" ], [ "solve_sudoku", "validate_constraints" ], [ "solve_sudoku_helper", "is_valid" ] ]
3
[]
false
[]
false
pytest
true
[]
true
5b8575e98e072eba9c89001351bb54b0bd6e9943
eade40ba414edad598246756100beaa000312bc9
v1.0
instruct
Codeforces
Codeforces_19082_I
You are given an array of n integers where each integer represents the carbon emission level recorded over n days. An environmental organization wants to determine the longest strictly decreasing sequence of days to show the effectiveness of their programs in reducing carbon emissions. The organization wants to identif...
def longest_decreasing_subsequence(days, emissions): n = len(emissions) dp = [1] * n previous = [-1] * n for i in range(1, n): for j in range(i): if emissions[i] < emissions[j] and dp[i] < dp[j] + 1: dp[i] = dp[j] + 1 previous[i] = j ...
from solution import process_emissions def test_example_case(): emissions = [5, 3, 4, 8, 6, 7, 2] n = len(emissions) max_length, seq = process_emissions(n, emissions) assert max_length == 3 assert seq == [1, 2, 7] def test_single_element_case(): emissions = [5] n = len(emissions) max_l...
[ { "docstring": null, "function_declaration": "def longest_decreasing_subsequence(days, emissions):", "function_name": "longest_decreasing_subsequence", "parameter_list": "(days, emissions)" }, { "docstring": null, "function_declaration": "def process_emissions(n, emissions):", "funct...
[ 0, 0, 0, 0, 0, 1, 0, 0, 0, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def longest_decreasing_subsequence(n, emissions):\n \"\"\"\n Finds the longest strictly decreasing subsequence in the given emission levels array.\n ...
trial_gpt4o_5
{ "original_instruction": "", "prompt_id": "00019082", "row_id": 19082, "seed_ids": "[1388]" }
0.746047
Codeforces_19082
I
[ "longest_decreasing_subsequence", "process_emissions" ]
2
[ [ "process_emissions", "longest_decreasing_subsequence" ] ]
1
[]
false
[]
false
pytest
true
[]
true
a7a037896f3b4e62b8a1d3168b1d1558a7f35eb8
6a8ad0f90bcac2fd468da5542b233131c0c5957e
v1.0
instruct
Codeforces
Codeforces_19121_I
### Bob's Binary Tree Adventure Bob is exploring binary trees and wants to check if a sequence of operations will maintain a tree-like structure. A sequence of operations contains nodes being added to create a tree or nodes being removed from the tree. The nodes are represented by unique positive integers, and the ope...
class TreeNode: def __init__(self, key): self.left = None self.right = None self.val = key def insert(root, key): if root is None: return TreeNode(key) else: if root.val < key: root.right = insert(root.right, key) else: root.left = ins...
from solution import process_input def test_example_cases(): assert process_input(2, [[4, "INSERT 5", "INSERT 2", "INSERT 8", "DELETE 5"], [3, "INSERT 1", "DELETE 1", "DELETE 1"]]) == [1, -1] def test_single_insert(): assert process_input(1, [[1, "INSERT 10"]]) == [0] def test_mu...
[]
[ 1, 1, 0, 0, 0, 0, 0, 0 ]
2
hard
0.25
{ "trial_gpt4o_0": null, "trial_gpt4o_1": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared1_results_combined.jsonl", "solution_code": "class TreeNode:\n def __init__(self, key):\n self.left = None\n self.right = None\n self.val = key\n\ndef ins...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00019121", "row_id": 19121, "seed_ids": "[5948]" }
0.645263
Codeforces_19121
I
[ "insert", "delete_node", "find_min", "height", "verify_sequence_of_operations", "contains", "process_input" ]
7
[ [ "delete_node", "find_min" ], [ "process_input", "verify_sequence_of_operations" ], [ "verify_sequence_of_operations", "contains" ], [ "verify_sequence_of_operations", "delete_node" ], [ "verify_sequence_of_operations", "height" ], [ "verify_sequence_...
6
[ "process_input" ]
false
[ "TreeNode" ]
true
pytest
true
[]
true
1374b416f1e2888abf28e1b87bce79265e2f54c0
58dd19c8a79426088e22e437765872049fc52b7f
v1.0
instruct
Codeforces
Codeforces_19141_I
You have been tasked with designing a system to track and manage the seating arrangements in a large lecture hall. The hall is represented as an `R x C` grid, where `R` is the number of rows and `C` is the number of columns. Each cell in the grid can either be empty (denoted by '.'), occupied by a student (denoted by '...
def find_seat_block(grid, group_size): R = len(grid) C = len(grid[0]) # Check horizontally for r in range(R): count = 0 for c in range(C): if grid[r][c] == '.': count += 1 if count == group_size: # Mark seats as occupie...
from solution import seating_arrangement def test_example_case(): R = 5 C = 5 G = 3 initial_state = [ ".....", ".....", "..X..", ".....", "....." ] groups = [3, 5, 10] expected = ["YES", "YES", "NO"] assert seating_arrangement(R, C, G, initial_sta...
[ { "docstring": null, "function_declaration": "def find_seat_block(grid, group_size):", "function_name": "find_seat_block", "parameter_list": "(grid, group_size)" }, { "docstring": null, "function_declaration": "def seating_arrangement(R, C, G, initial_state, groups):", "function_name...
[ 0, 0, 1, 0, 1, 1, 1, 0, 0, 1 ]
5
medium
0.5
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def find_seats(hall, n):\n R, C = len(hall), len(hall[0])\n # Check for horizontal blocks\n for row in range(R):\n count = 0\n for col ...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00019141", "row_id": 19141, "seed_ids": "[1785]" }
0.680492
Codeforces_19141
I
[ "find_seat_block", "seating_arrangement" ]
2
[ [ "seating_arrangement", "find_seat_block" ] ]
1
[]
false
[]
false
pytest
true
[]
true
c6ef1f07f82d87b9b666c6de0dee14cfe4936796
c39e260bd611a2e5d050281629566439afb1f1dd
v1.0
instruct
Codeforces
Codeforces_19162_I
In a distant city, there is a beautiful rectangular garden with n rows and m columns. Each cell of the garden is filled either with a flower or with grass. The garden is represented as a 2D matrix of characters 'F' for flowers and 'G' for grass. The city council wants to preserve rectangular subgardens that only cont...
def max_rectangle_of_flowers(n, m, garden): """ Returns the maximum area of a rectangular subgarden containing only 'F'. """ if n == 0 or m == 0: return 0 max_area = 0 heights = [0] * m for row in garden: for j in range(m): if row[j] == 'F': heig...
from solution import max_rectangle_of_flowers def test_example_case(): garden = [ "FGFFF", "FFFFF", "FFFGG", "FFFFG" ] assert max_rectangle_of_flowers(4, 5, garden) == 9 def test_all_flowers(): garden = [ "FFF", "FFF", "FFF" ] assert max_...
[ { "docstring": "Returns the maximum area of a rectangular subgarden containing only 'F'.", "function_declaration": "def max_rectangle_of_flowers(n, m, garden):", "function_name": "max_rectangle_of_flowers", "parameter_list": "(n, m, garden)" }, { "docstring": "Helper function to calculate th...
[ 1, 0, 1, 0, 0, 0, 1, 1, 1, 0 ]
5
medium
0.5
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def max_rectangle_of_flowers(n, m, garden):\n \"\"\"\n Returns the maximum area of a rectangular subgarden containing only 'F'.\n \"\"\"\n if n ==...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00019162", "row_id": 19162, "seed_ids": "[6858]" }
0.6621
Codeforces_19162
I
[ "max_rectangle_of_flowers", "largest_rectangle_area" ]
2
[ [ "max_rectangle_of_flowers", "largest_rectangle_area" ] ]
1
[]
false
[]
false
pytest
true
[]
true
7e27bf612820b85cc01007b3e8f9f12437c90ef0
f4a424fafa8ca14bcb178dc1d75943d6519311a3
v1.0
instruct
Codeforces
Codeforces_19180_I
In a town called Nara, there is a unique way to manage the water supply for its residents. The town has a large water tank, and water from this tank is supplied to its residents through a series of connected pipes. Each pipe has a specific capacity, which represents the maximum amount of water it can transport per hour...
from collections import defaultdict, deque def bfs(capacity, source, sink, parent): visited = set() queue = deque([source]) visited.add(source) while queue: u = queue.popleft() for v in capacity[u]: if v not in visited and capacity[u][v] > 0: queue....
from solution import max_water_flow def test_max_water_flow_example(): n = 5 m = 7 edges = [ (1, 2, 10), (1, 3, 10), (2, 4, 25), (3, 4, 15), (2, 3, 10), (4, 5, 10), (3, 5, 10) ] assert max_water_flow(n, m, edges) == 20 def test_max_water_flow...
[ { "docstring": null, "function_declaration": "def bfs(capacity, source, sink, parent):", "function_name": "bfs", "parameter_list": "(capacity, source, sink, parent)" }, { "docstring": null, "function_declaration": "def edmonds_karp(capacity, source, sink):", "function_name": "edmonds...
[ 1, 1, 0, 1, 0, 1, 0, 1, 0, 1 ]
6
medium
0.6
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "from collections import deque, defaultdict\n\ndef bfs_capacity(graph, s, t, parent):\n visited = set()\n queue = deque([s])\n visited.add(s)\n \n ...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00019180", "row_id": 19180, "seed_ids": "[3501]" }
0.69304
Codeforces_19180
I
[ "bfs", "edmonds_karp", "max_water_flow" ]
3
[ [ "edmonds_karp", "bfs" ], [ "max_water_flow", "edmonds_karp" ] ]
2
[]
false
[]
false
pytest
true
[]
true
1e27a609069cf7017668c6bd9788b464b8930b39
5e72ce5181ba0c7282b312e90a9d8f23f88da60a
v1.0
instruct
Codeforces
Codeforces_19184_I
The Union of Social Coders (USC) decided to create a social network for programmers. Each programmer can be identified by a unique integer ID starting from 1. The programmers form a hierarchical structure based on direct mentorship where one programmer can mentor multiple others, but each programmer can have only one d...
from collections import defaultdict, deque def preprocess_lca(n, edges): # Initialize adjacency list, parents and depth adj_list = defaultdict(list) parent = [0] * (n + 1) depth = [0] * (n + 1) # Building adjacency list from edges for u, v in edges: adj_list[u].append(v) ad...
from solution import usc_least_common_mentor def test_case_1(): n = 5 edges = [(1, 2), (1, 3), (3, 4), (3, 5)] queries = [(2, 4), (4, 5), (2, 3)] assert usc_least_common_mentor(n, edges, queries) == [1, 3, 1] def test_case_2(): n = 6 edges = [(1, 2), (1, 3), (2, 4), (2, 5), (3, 6)] queries...
[ { "docstring": null, "function_declaration": "def preprocess_lca(n, edges):", "function_name": "preprocess_lca", "parameter_list": "(n, edges)" }, { "docstring": null, "function_declaration": "def find_lca(u, v, parent, depth):", "function_name": "find_lca", "parameter_list": "(u...
[ 1, 1, 1, 1, 1, 1, 1, 0, 1, 0 ]
8
easy
0.8
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "from collections import defaultdict, deque\n\ndef lca_preprocessing(n, edges):\n \"\"\"\n Preprocesses the tree to build up necessary data to answer LCA...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00019184", "row_id": 19184, "seed_ids": "[7766]" }
0.620144
Codeforces_19184
I
[ "preprocess_lca", "find_lca", "usc_least_common_mentor" ]
3
[ [ "usc_least_common_mentor", "find_lca" ], [ "usc_least_common_mentor", "preprocess_lca" ] ]
2
[]
false
[]
false
pytest
true
[]
true
90e1dc1b6b0e244e98a15ae8cf8c3c654f098c6d
0f43efd016c9edb5be48b7d9bfd4f54f8a3c4490
v1.0
instruct
Codeforces
Codeforces_19187_I
You work for a logistics company that needs to optimize the delivery route of a truck that has to visit a set of delivery points scattered around a city. The truck starts at the company's central depot, and the goal is to visit each delivery point exactly once and return to the central depot while minimizing the total ...
import json import itertools import math def calculate_distance(point1, point2): """Calculate Euclidean distance between two points.""" return math.sqrt((point1[0] - point2[0]) ** 2 + (point1[1] - point2[1]) ** 2) def calculate_route_distance(route, points): """Calculate the total distance of the given ro...
from solution import find_optimal_route def test_find_optimal_route_simple_example(tmp_path): input_json = { "Depot": [0, 0], "DeliveryPoints": [[1, 2], [3, 4], [5, 1]] } file_path = tmp_path / "input.json" with open(file_path, 'w') as file: json.dump(input_json, file) resu...
[ { "docstring": "Calculate Euclidean distance between two points.", "function_declaration": "def calculate_distance(point1, point2):", "function_name": "calculate_distance", "parameter_list": "(point1, point2)" }, { "docstring": "Calculate the total distance of the given route.", "functio...
[ 0, 0, 0, 0, 1, 1, 1, 0, 0 ]
3
medium
0.333
{ "trial_gpt4o_0": null, "trial_gpt4o_1": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared1_results_combined.jsonl", "solution_code": "import json\nimport math\nfrom itertools import permutations\n\ndef distance(point1, point2):\n return math.sqrt((point1[0] - poin...
trial_gpt4o_7
{ "original_instruction": "", "prompt_id": "00019187", "row_id": 19187, "seed_ids": "[530]" }
0.619262
Codeforces_19187
I
[ "calculate_distance", "calculate_route_distance", "find_optimal_route" ]
3
[ [ "calculate_route_distance", "calculate_distance" ], [ "find_optimal_route", "calculate_route_distance" ] ]
2
[]
false
[]
false
pytest
true
[]
true
7770c5315f4639e3d810723d12136a537e4fa8d4
c796a5c40cbf8f03cbb30f4e5f9dd020ee567b67
v1.0
instruct
Codeforces
Codeforces_19192_I
Arthur loves managing his warehouse inventory and is always keen on finding ways to optimize it. He has a new shipment of items arriving, and he wants to distribute these items as evenly as possible across his warehouse shelves. Architecturally, his warehouse has several sections, each with a fixed number of shelves, a...
from math import gcd from functools import reduce def lcm(a, b): return a * b // gcd(a, b) def min_additional_items(m, shelves): if m == 1: return 0 overall_lcm = reduce(lcm, shelves) return overall_lcm # Example usage: #m = 3 #shelves = [4, 5, 6] #print(min_additional_items(m, shel...
import pytest from solution import min_additional_items def test_single_section(): assert min_additional_items(1, [10]) == 0 def test_multiple_sections(): assert min_additional_items(3, [4, 5, 6]) == 60 def test_two_sections(): assert min_additional_items(2, [3, 4]) == 12 def test_varied_shelves(): ...
[ { "docstring": null, "function_declaration": "def lcm(a, b):", "function_name": "lcm", "parameter_list": "(a, b)" }, { "docstring": null, "function_declaration": "def min_additional_items(m, shelves):", "function_name": "min_additional_items", "parameter_list": "(m, shelves)" }...
[ 0, 1, 0, 1, 0, 0, 0, 0, 0 ]
2
hard
0.222
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "import math\nfrom functools import reduce\n\ndef lcm(x, y):\n # Function to calculate the least common multiple (LCM) of two integers\n return x * y // ...
trial_gpt4o_4
{ "original_instruction": "", "prompt_id": "00019192", "row_id": 19192, "seed_ids": "[7926]" }
0.686781
Codeforces_19192
I
[ "lcm", "min_additional_items" ]
2
[ [ "min_additional_items", "lcm" ] ]
1
[]
false
[]
false
pytest
true
[]
true
61826359b6b5e4141a312e4f500e1d47d1fea6c1
aaa4a19ad0e7cc9a886240eaed5d14aa712a79d4
v1.0
instruct
Codeforces
Codeforces_19202_I
A company is developing a delivery service and wants to create an optimal route for their delivery vehicle. They have a list of delivery locations, each characterized by its coordinates (xi, yi) on a 2D plane and the urgency of the delivery (ui). The vehicle starts at the origin point (0, 0) and must plan a route that ...
import math def calculate_distance(x1, y1, x2, y2): """ Calculates the Euclidean distance between two points (x1, y1) and (x2, y2). """ return math.sqrt((x1 - x2) ** 2 + (y1 - y2) ** 2) def optimal_route(delivery_locations): """ Determines the optimal route for the delivery vehicle. """ ...
import math from solution import calculate_distance, optimal_route def test_calculate_distance(): assert math.isclose(calculate_distance(0, 0, 3, 4), 5.0, rel_tol=1e-9) assert math.isclose(calculate_distance(0, 0, 0, 0), 0.0, rel_tol=1e-9) assert math.isclose(calculate_distance(1, 1, 4, 5), 5.0, rel_tol=1e...
[ { "docstring": "Calculates the Euclidean distance between two points (x1, y1) and (x2, y2).", "function_declaration": "def calculate_distance(x1, y1, x2, y2):", "function_name": "calculate_distance", "parameter_list": "(x1, y1, x2, y2)" }, { "docstring": "Determines the optimal route for the...
[ 1, 1, 0, 1, 0, 0, 0, 0, 1 ]
4
medium
0.444
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "import math\n\ndef optimal_delivery_route(n, points):\n \"\"\"\n Find the optimal delivery route given the delivery points and their urgencies.\n \n ...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00019202", "row_id": 19202, "seed_ids": "[5645]" }
0.779081
Codeforces_19202
I
[ "calculate_distance", "optimal_route" ]
2
[ [ "optimal_route", "calculate_distance" ] ]
1
[]
false
[]
false
pytest
true
[]
true
d40d7efaa4cada14a3e97a59ca81fde2e47f75c5
74f77848c914fa2197f21746332c3bc1be56dcce
v1.0
instruct
Codeforces
Codeforces_19209_I
Given an array of integers `nums`, you need to find the number of unique triplets `(i, j, k)` such that `i < j < k` and the sum of the elements at these indices is zero. The array may contain both positive and negative numbers, and values may repeat. ### Input: - The first line contains an integer `n` (0 ≤ n ≤ 1000), ...
from itertools import combinations def count_unique_triplets(nums): """ Returns the number of unique triplets (i, j, k) such that i < j < k and nums[i] + nums[j] + nums[k] == 0. """ triplets = set() nums.sort() n = len(nums) for i in range(n): left, right = i + 1, n - 1 ...
from solution import unique_triplets def test_unique_triplets_example1(): assert unique_triplets(6, [-1, 0, 1, 2, -1, -4]) == 2 def test_unique_triplets_example2(): assert unique_triplets(5, [0, 0, 0, 0, 0]) == 1 def test_unique_triplets_no_triplets(): assert unique_triplets(4, [1, 2, 3, 4]) == 0 def te...
[ { "docstring": "Returns the number of unique triplets (i, j, k) such that i < j < k and nums[i] + nums[j] + nums[k] == 0.", "function_declaration": "def count_unique_triplets(nums):", "function_name": "count_unique_triplets", "parameter_list": "(nums)" }, { "docstring": "Entry point to the s...
[ 0, 0, 0, 1, 1, 0, 0, 1, 0, 1 ]
4
medium
0.4
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def count_unique_zero_sum_triplets(nums):\n nums.sort()\n n = len(nums)\n unique_triplets = set()\n\n for i in range(n):\n if i > 0 and num...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00019209", "row_id": 19209, "seed_ids": "[4112]" }
0.729052
Codeforces_19209
I
[ "count_unique_triplets", "unique_triplets" ]
2
[ [ "unique_triplets", "count_unique_triplets" ] ]
1
[]
false
[]
false
pytest
true
[]
true
e2a6cbf07286fcf502e647aab0327bd39b36ff4f
18032ab45e78825d4a3b7d4efb04fe26b1abd20d
v1.0
instruct
Codeforces
Codeforces_19262_I
You are given a tree with $$$n$$$ nodes. Each node has an integer value $$$a_i$$$ associated with it. You will perform several queries on this tree. Each query asks you to find the maximum value of the integers in the subtree of a given node. The tree is rooted at node 1. The subtree of a node $$$v$$$ consists of $$$v...
class SegmentTree: def __init__(self, data): self.n = len(data) self.tree = [0] * (2 * self.n) self.build(data) def build(self, data): # Insert leaf nodes in tree for i in range(self.n): self.tree[self.n + i] = data[i] # Build the tree by calculating ...
def test_solve(): tree_info = { 'n': 5, 'values': [1, 2, 3, 4, 5], 'edges': [(1, 2), (1, 3), (3, 4), (3, 5)] } queries = [(2, 3), (1, 3, 10), (2, 3)] expected_output = [5, 10] assert solve(tree_info, queries) == expected_output tree_info = { 'n': 3, ...
[]
[ 0, 1, 0, 0, 0, 1, 1, 1, 1, 0 ]
5
medium
0.5
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "class TreeNode:\n def __init__(self, value):\n self.value = value\n self.children = []\n self.max_subtree_value = value\n\ndef dfs_max...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00019262", "row_id": 19262, "seed_ids": "[1032]" }
0.589892
Codeforces_19262
I
[ "dfs", "solve" ]
2
[ [ "solve", "dfs" ] ]
1
[]
false
[ "SegmentTree" ]
true
pytest
false
[]
true
3ad8652aa1135e5fd6a70333a4adade3d8f9e799
82fcd77a83024f5b815b8107ba67390ce1d0344e
v1.0
instruct
Codeforces
Codeforces_19306_I
You are given an array of integers representing the heights of students standing in a row. The school needs to rearrange the students such that the row of students becomes non-decreasing in height. To achieve this, you are allowed to perform the following operation as many times as necessary: choose any two adjacent st...
def count_inversions(arr): temp_arr = [0]*len(arr) return merge_sort(arr, temp_arr, 0, len(arr)-1) def merge_sort(arr, temp_arr, left, right): inv_count = 0 if left < right: mid = (left + right)//2 inv_count += merge_sort(arr, temp_arr, left, mid) inv_count += merge_sort(arr, te...
from solution import minimum_swaps_to_sort def test_example1(): arr = [3, 1, 2] assert minimum_swaps_to_sort(arr) == 2 def test_example2(): arr = [5, 4, 3, 2, 1] assert minimum_swaps_to_sort(arr) == 10 def test_example3(): arr = [1, 3, 5, 2] assert minimum_swaps_to_sort(arr) == 2 def test_so...
[ { "docstring": null, "function_declaration": "def count_inversions(arr):", "function_name": "count_inversions", "parameter_list": "(arr)" }, { "docstring": null, "function_declaration": "def merge_sort(arr, temp_arr, left, right):", "function_name": "merge_sort", "parameter_list"...
[ 0, 0, 0, 1, 0, 0, 0, 0, 0, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def minimum_swaps(arr):\n \"\"\"\n Returns the minimum number of adjacent swaps required to sort the given list in non-decreasing order.\n \"\"\"\n ...
trial_gpt4o_3
{ "original_instruction": "", "prompt_id": "00019306", "row_id": 19306, "seed_ids": "[3656]" }
0.683109
Codeforces_19306
I
[ "count_inversions", "merge_sort", "merge", "minimum_swaps_to_sort" ]
4
[ [ "count_inversions", "merge_sort" ], [ "merge_sort", "merge" ], [ "minimum_swaps_to_sort", "count_inversions" ] ]
3
[]
false
[]
false
pytest
true
[]
true
8f50a76853a6079264515bb3164e2f00bf9ac07a
a1786d6199762600ef69b47e3be8fd35283e7baf
v1.0
instruct
Codeforces
Codeforces_19313_I
You are given a list of strings, where each string is derived from an identifier used in a programming context. Each identifier follows a specific format and naming convention. Your task is to determine whether each identifier in the list follows a valid camel case naming convention. Camel case format requires: 1. The...
import re def is_camel_case(identifier): """ Determine if the given identifier is in camel case format. """ pattern = '^[a-z]+(?:[A-Z][a-z]*)*$' return re.match(pattern, identifier) is not None def check_identifiers(identifiers): """ Given a list of identifiers, determine if each is in cam...
from solution import is_camel_case, check_identifiers def test_is_camel_case(): assert is_camel_case("camelCase") == True assert is_camel_case("CamelCase") == False assert is_camel_case("camelcase") == True assert is_camel_case("Camelcase") == False assert is_camel_case("camelCaseExample") == True ...
[ { "docstring": "Determine if the given identifier is in camel case format.", "function_declaration": "def is_camel_case(identifier):", "function_name": "is_camel_case", "parameter_list": "(identifier)" }, { "docstring": "Given a list of identifiers, determine if each is in camel case format ...
[ 1, 0, 0, 0, 0, 0, 1, 1, 0, 0 ]
3
hard
0.3
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "import re\n\ndef is_camel_case(identifier):\n \"\"\"\n Returns 'YES' if the identifier follows the camel case naming convention, otherwise 'NO'.\n \"...
trial_gpt4o_7
{ "original_instruction": "", "prompt_id": "00019313", "row_id": 19313, "seed_ids": "[1193]" }
0.632496
Codeforces_19313
I
[ "is_camel_case", "check_identifiers" ]
2
[ [ "check_identifiers", "is_camel_case" ] ]
1
[]
false
[]
false
pytest
true
[]
true
f1d2f3bfef57a475e997588d24c90e97a9c1cee4
e9c03cb80c38fb110b414b12c0efe4b5bf35f4bb
v1.0
instruct
Codeforces
Codeforces_19485_I
Write a program that helps in processing unique coupon codes for a marketing campaign. Each coupon code is a string containing alphanumeric characters, and it should be validated according to a specific set of rules: 1. The coupon code must contain exactly 10 characters. 2. It must include at least one uppercase letter...
def validate_coupon(coupon): """ Validates a given coupon code based on specific rules. Rules: - It must contain exactly 10 characters. - It must include at least one uppercase letter. - It must include at least one digit. - It must include at least one special character from the set: {'#', ...
from solution import validate_coupon, process_coupons def test_validate_coupon_valid(): assert validate_coupon("A1b2C3d4E!") == "VALID" assert validate_coupon("A2b3D4c5E#") == "VALID" assert validate_coupon("M7n6O5p4*!") == "VALID" def test_validate_coupon_invalid_length(): assert validate_coupon("A1b...
[ { "docstring": "Validates a given coupon code based on specific rules.\nRules:\n- It must contain exactly 10 characters.\n- It must include at least one uppercase letter.\n- It must include at least one digit.\n- It must include at least one special character from the set: {'#', '@', '!', '*'}.\n\n:param coupon...
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "import re\n\ndef is_valid_coupon(coupon: str) -> bool:\n \"\"\"\n Returns True if the coupon is valid according to the specified rules, False otherwise....
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00019485", "row_id": 19485, "seed_ids": "[6641]" }
0.595789
Codeforces_19485
I
[ "validate_coupon", "process_coupons" ]
2
[ [ "process_coupons", "validate_coupon" ] ]
1
[]
false
[]
false
pytest
true
[]
true
95fccc481e321f78323d544400be983ece02ae38
5e9ec35831ccfae2713fbcc4eb9537e096d5ce17
v1.0
instruct
Codeforces
Codeforces_19490_I
You are given a grid with $$$n$$$ rows and $$$m$$$ columns. Each cell in the grid is initially either empty or occupied by an obstacle. You can move from one cell to another if they are adjacent (vertically or horizontally) and both are empty. Given two cells in the grid, determine if there exists a path between them...
def is_path_exists(n, m, grid, start, end): from collections import deque def is_valid(x, y): return 0 <= x < n and 0 <= y < m and grid[x][y] == '.' directions = [(-1, 0), (1, 0), (0, -1), (0, 1)] queue = deque([start]) visited = set([start]) while queue: x, y = queue.popleft(...
def test_find_path_in_grid_empty_grid(): n, m = 4, 4 grid = [ "....", "....", "....", "...." ] r1, c1, r2, c2 = 1, 1, 4, 4 assert find_path_in_grid(n, m, grid, r1, c1, r2, c2) == "YES" def test_find_path_in_grid_obstacle_blocking_path(): n, m = 4, 4 grid = [ ...
[ { "docstring": null, "function_declaration": "def is_path_exists(n, m, grid, start, end):", "function_name": "is_path_exists", "parameter_list": "(n, m, grid, start, end)" }, { "docstring": null, "function_declaration": "def find_path_in_grid(n, m, grid, r1, c1, r2, c2):", "function_...
[ 0, 0, 0, 0, 0, 0, 0, 0, 1, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "from collections import deque\n\ndef is_path_exist(n, m, grid, r1, c1, r2, c2):\n directions = [(0, 1), (1, 0), (0, -1), (-1, 0)]\n \n def is_valid(x...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00019490", "row_id": 19490, "seed_ids": "[7590]" }
0.740353
Codeforces_19490
I
[ "is_path_exists", "find_path_in_grid" ]
2
[ [ "find_path_in_grid", "is_path_exists" ] ]
1
[]
false
[]
false
pytest
false
[]
true
368da6230faf0d86f7535777ea437d8a21ea97aa
979f8f5b3e09f9b13ef2abe1fb37c7c498923dfe
v1.0
instruct
Codeforces
Codeforces_19519_I
Alex is exploring different sorting algorithms and wants to implement a function to sort an array of unique integers. However, he is particularly interested in understanding how merge sort works and would like to test his understanding by writing a version of it. Given an array of unique integers, implement the merge ...
from typing import List def merge_sort(arr: List[int]) -> List[int]: """ Sorts an array of unique integers using merge sort algorithm. :param arr: List of unique integers :return: Sorted list of integers """ if len(arr) <= 1: return arr # Split the array into two halves mi...
from solution import merge_sort def test_merge_sort_basic_input(): assert merge_sort([3, 1, 2]) == [1, 2, 3] def test_merge_sort_large_input(): assert merge_sort([10, 5, 3, 2, 8, 6, 7, 4, 1, 9]) == [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] def test_merge_sort_empty_array(): assert merge_sort([]) == [] def test_me...
[ { "docstring": "Sorts an array of unique integers using merge sort algorithm.\n\n:param arr: List of unique integers\n:return: Sorted list of integers", "function_declaration": "def merge_sort(arr):", "function_name": "merge_sort", "parameter_list": "(arr)" }, { "docstring": null, "funct...
[ 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
9
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "from typing import List\n\ndef merge_sort(arr: List[int]) -> List[int]:\n \"\"\"\n Sorts an array of unique integers using merge sort algorithm.\n \n...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00019519", "row_id": 19519, "seed_ids": "[6797]" }
0.662275
Codeforces_19519
I
[ "merge_sort", "merge" ]
2
[ [ "merge_sort", "merge" ] ]
1
[]
false
[]
false
pytest
true
[]
true
f7400fd6ceeefc8b0f79f7d55105a00738ce4638
afe322550c01ed701d31c8c883a92204b4ddaf3c
v1.0
instruct
Codeforces
Codeforces_19625_I
You are given two integers n and m representing the number of nodes and the number of directed edges in a graph, respectively. Each node is labeled with a unique integer from 1 to n. Each of the next m lines contains three integers u, v, and c (1 ≤ u, v ≤ n, u ≠ v, 1 ≤ c ≤ 109) representing a directed edge from node u ...
import heapq def dijkstra(graph, start, n): """ Implements Dijkstra's algorithm to compute shortest paths from start node to all other nodes in the graph. graph: adjacency list where graph[u] is a list of tuples (v, c) meaning there is an edge from node u to node v with cost c. start: the start node fo...
from solution import main def test_example(): input_data = [ "4 4", "1 2 1", "2 3 1", "3 4 1", "1 4 4", "2", "1 4", "2 1" ] expected_output = [3, -1] assert main(input_data) == expected_output def test_no_path(): input_data = [ ...
[ { "docstring": "Implements Dijkstra's algorithm to compute shortest paths from start node to all other nodes in the graph.\ngraph: adjacency list where graph[u] is a list of tuples (v, c) meaning there is an edge from node u to node v with cost c.\nstart: the start node for shortest path calculation.\nn: the nu...
[ 0, 1, 0, 0, 0, 0, 1, 1, 0, 1 ]
4
medium
0.4
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "import heapq\n\ndef dijkstra(graph, n, start):\n \"\"\"\n Implements Dijkstra's algorithm to find the shortest path from start node\n to all other no...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00019625", "row_id": 19625, "seed_ids": "[789]" }
0.763718
Codeforces_19625
I
[ "dijkstra", "find_shortest_paths", "process_input", "main" ]
4
[ [ "find_shortest_paths", "dijkstra" ] ]
1
[ "process_input" ]
false
[]
false
pytest
true
[]
true
9fb829a185ee5c9156762723665c869139a8f961
f3df2a01f045beb3b8214c27cb33e94720a735a3
v1.0
instruct
Codeforces
Codeforces_19630_I
A new kitchen management system is being developed for a restaurant. Each chef is responsible for a specific number of dishes each day. The head chef assigns dishes to each chef based on their workload capacity. Your task is to create a program that helps to uniformly distribute dishes among chefs such that the differe...
def canDistribute(dishes, m, n, max_workload): chefs = 1 current_workload = 0 for time in dishes: if current_workload + time <= max_workload: current_workload += time else: chefs += 1 current_workload = time if chefs > n: r...
def test_minMaxWorkload_single_chef(): assert minMaxWorkload(5, 1, [2, 4, 6, 8, 10]) == 30 def test_minMaxWorkload_equal_dishes_chefs(): assert minMaxWorkload(4, 4, [1, 2, 3, 4]) == 4 def test_minMaxWorkload_more_dishes_than_chefs(): assert minMaxWorkload(10, 4, [11, 6, 5, 4, 7, 3, 10, 8, 3, 1]) == 17 de...
[ { "docstring": null, "function_declaration": "def canDistribute(dishes, m, n, max_workload):", "function_name": "canDistribute", "parameter_list": "(dishes, m, n, max_workload)" }, { "docstring": null, "function_declaration": "def minMaxWorkload(m, n, dishes):", "function_name": "min...
[ 1, 0, 0, 1, 1, 0, 0, 0, 0, 1 ]
4
medium
0.4
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def minimize_max_workload(m, n, dish_times):\n def canDistribute(target_max_workload):\n current_sum = 0\n chefs_needed = 1\n \n ...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00019630", "row_id": 19630, "seed_ids": "[3546]" }
0.738072
Codeforces_19630
I
[ "canDistribute", "minMaxWorkload" ]
2
[ [ "minMaxWorkload", "canDistribute" ] ]
1
[]
false
[]
false
pytest
false
[]
true
abe0a71972004e91a44fe2ab84631017be9856fa
fde8fb1669aebadc1aac1fadd9abaaa62b579676
v1.0
instruct
Codeforces
Codeforces_19729_I
Given an array of integers, your task is to find the longest contiguous subsequence such that every element in this subsequence is a power of 2. If there are multiple subsequences with the same maximum length, return the one that appears first. ### Input The first line of the input contains an integer $$$t$$$ ($$$1 \l...
def is_power_of_2(x): """ Check if a number is a power of 2. """ return x > 0 and (x & (x - 1)) == 0 def longest_power_of_2_subsequence(test_cases): results = [] for case in test_cases: n, array = case max_length = 0 current_length = 0 for num in array: ...
import pytest from solution import longest_power_of_2_subsequence def test_example_cases(): test_cases = [ (8, [1, 2, 3, 4, 8, 16, 32, 2]), (5, [5, 3, 6, 7, 9]), (6, [4, 8, 2, 4, 16, 2]) ] expected = [5, 0, 6] assert longest_power_of_2_subsequence(test_cases) == expected def te...
[ { "docstring": "Check if a number is a power of 2.", "function_declaration": "def is_power_of_2(x):", "function_name": "is_power_of_2", "parameter_list": "(x)" }, { "docstring": null, "function_declaration": "def longest_power_of_2_subsequence(test_cases):", "function_name": "longest...
[ 1, 0, 1, 0, 1, 0, 0, 1, 1, 1 ]
6
medium
0.6
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_power_of_two(x):\n \"\"\"\n Checks if a number x is a power of two.\n \"\"\"\n return x > 0 and (x & (x - 1)) == 0\n\ndef longest_power_of_...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00019729", "row_id": 19729, "seed_ids": "[5088]" }
0.761948
Codeforces_19729
I
[ "is_power_of_2", "longest_power_of_2_subsequence" ]
2
[ [ "longest_power_of_2_subsequence", "is_power_of_2" ] ]
1
[]
false
[]
false
pytest
true
[]
true
884de66cbcaa2993a4631ef759a259b8015240d2
30a0bde4562f3704a0a84154a23f96eba9223dfa
v1.0
instruct
Codeforces
Codeforces_19730_I
In a faraway land, there is a magical forest with n distinct trees. Each tree holds a unique integer value in its bark, known as the tree's magic number. The trees are connected by n-1 bidirectional roads, forming a single connected forest with exactly one path between any pair of trees. All the inhabitants of the lan...
def dfs(tree, node, parent, magic_numbers, subtree_sum): """ Perform DFS to compute subtree sum for each node. """ subtree_sum[node] = magic_numbers[node] for neighbor in tree[node]: if neighbor != parent: dfs(tree, neighbor, node, magic_numbers, subtree_sum) subtree_...
def test_solve_magic_forest(): n = 5 magic_numbers = [1, 2, 3, 4, 5] roads = [(0, 1), (1, 2), (1, 3), (3, 4)] queries = [(0, 4), (2, 3), (1, 1)] expected = [15, 9, 2] assert solve_magic_forest(n, magic_numbers, roads, queries) == expected n = 3 magic_numbers = [10, 20, 30] roads = [...
[ { "docstring": "Perform DFS to compute subtree sum for each node.", "function_declaration": "def dfs(tree, node, parent, magic_numbers, subtree_sum):", "function_name": "dfs", "parameter_list": "(tree, node, parent, magic_numbers, subtree_sum)" }, { "docstring": null, "function_declarati...
[ 0, 0, 1, 0, 0, 0, 0, 0, 0 ]
1
hard
0.111
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "from collections import defaultdict\n\n# Function to perform DFS and compute necessary information\ndef dfs(node, parent, adjacency_list, magic_numbers, depth...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00019730", "row_id": 19730, "seed_ids": "[4251]" }
0.60339
Codeforces_19730
I
[ "dfs", "solve_magic_forest" ]
2
[ [ "solve_magic_forest", "dfs" ] ]
1
[]
false
[]
false
pytest
false
[]
true
9f79238ded7ed95f7d21309eeffe76151487b2ae
26712773a1bf1cb58080291eec535781cd398716
v1.0
instruct
Codeforces
Codeforces_19756_I
Sara has a peculiar grid. The grid is a rectangle consisting of n rows and m columns. Each cell in the grid can contain one of two possible values: 0 or 1. Adjacent cells can have the same or different values. Sara wants to know the largest "plus" shape she can find in the grid. A "plus" shape is defined by a center ce...
def max_plus_length(grid): n = len(grid) m = len(grid[0]) up = [[0] * m for _ in range(n)] down = [[0] * m for _ in range(n)] left = [[0] * m for _ in range(n)] right = [[0] * m for _ in range(n)] for i in range(n): for j in range(m): if grid[i][j] == 1: ...
import pytest from solution import find_max_plus_length def test_example_1(): grid = [ [1, 0, 0, 1, 0], [1, 1, 1, 1, 1], [0, 1, 0, 1, 0], [1, 1, 1, 1, 0] ] assert find_max_plus_length(4, 5, grid) == 1 def test_example_2(): grid = [ [1, 0, 1], [0, 1, 0], ...
[ { "docstring": null, "function_declaration": "def max_plus_length(grid):", "function_name": "max_plus_length", "parameter_list": "(grid)" }, { "docstring": null, "function_declaration": "def find_max_plus_length(n, m, grid):", "function_name": "find_max_plus_length", "parameter_l...
[ 1, 1, 1, 1, 0, 0, 1, 0, 1, 1 ]
7
easy
0.7
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def largest_plus_arm_length(grid):\n n = len(grid)\n m = len(grid[0])\n\n def get_dp():\n left = [[0] * m for _ in range(n)]\n right = ...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00019756", "row_id": 19756, "seed_ids": "[3333]" }
0.637074
Codeforces_19756
I
[ "max_plus_length", "find_max_plus_length" ]
2
[ [ "find_max_plus_length", "max_plus_length" ] ]
1
[]
false
[]
false
pytest
true
[]
true
7b027325f892301531a4a41743f69270bbc3ab8f
bf706fe6e624e20e0503713c63244adeec97e789
v1.0
instruct
Codeforces
Codeforces_19867_I
You are given a balanced binary search tree (BST) and an integer k. The BST contains unique integers. Your task is to find the k-th largest element in the BST. A balanced Binary Search Tree is defined as a binary tree in which for every node, the difference in height between the left and right subtrees is at most 1. T...
class TreeNode: def __init__(self, val=0, left=None, right=None): self.val = val self.left = left self.right = right def insert_into_bst(root, val): if not root: return TreeNode(val) if val < root.val: root.left = insert_into_bst(root.left, val) else: ...
from solution import find_kth_largest_element def test_example_1(): test_cases = [(7, 3, [20, 8, 22, 4, 12, 10, 14])] assert find_kth_largest_element(test_cases) == [14] def test_example_2(): test_cases = [(5, 1, [3, 1, 4, 2, 5])] assert find_kth_largest_element(test_cases) == [5] def test_single_nod...
[]
[ 1, 1, 1, 1, 1, 0, 1, 1, 1, 1 ]
9
easy
0.9
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "class TreeNode:\n def __init__(self, key):\n self.key = key\n self.left = None\n self.right = None\n\ndef insert(root, key):\n if r...
trial_gpt4o_7
{ "original_instruction": "", "prompt_id": "00019867", "row_id": 19867, "seed_ids": "[199]" }
0.567283
Codeforces_19867
I
[ "insert_into_bst", "kth_largest_in_bst", "find_kth_largest_element" ]
3
[ [ "find_kth_largest_element", "insert_into_bst" ], [ "find_kth_largest_element", "kth_largest_in_bst" ] ]
2
[]
false
[ "TreeNode" ]
true
pytest
true
[]
true
242e955298cdeb58893270f1b966289693876676
b5ba829b94f8362adc61a2c1be02f8145983e65e
v1.0
instruct
Codeforces
Codeforces_19873_I
Berland's subway system consists of n stations and m routes. Each route connects a pair of stations and has an associated travel time ti, which represents the time it takes for a train to travel from one station to the other along that route. Each route is bidirectional, meaning that trains can travel in both direction...
import heapq def find_shortest_path(n, m, routes): graph = {i: [] for i in range(1, n+1)} for ai, bi, ti in routes: graph[ai].append((bi, ti)) graph[bi].append((ai, ti)) # Dijkstra's algorithm pq = [(0, 1, [])] # (accumulated cost, current station, path) shortest_paths = {i: f...
from solution import shortest_travel_time_and_path def test_shortest_travel_time_and_path(): n = 4 m = 5 routes = [ (1, 2, 3), (1, 3, 6), (2, 3, 1), (3, 4, 2), (2, 4, 5), ] shortest_time, path = shortest_travel_time_and_path(n, m, routes) assert shortest_...
[ { "docstring": null, "function_declaration": "def find_shortest_path(n, m, routes):", "function_name": "find_shortest_path", "parameter_list": "(n, m, routes)" }, { "docstring": null, "function_declaration": "def shortest_travel_time_and_path(n, m, routes):", "function_name": "shorte...
[ 1, 1, 1, 0, 0, 1, 0, 1, 0 ]
5
medium
0.556
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "import heapq\n\ndef find_shortest_path(n, m, routes):\n # Create adjacency list\n graph = {i: [] for i in range(1, n + 1)}\n for a, b, t in routes:\n...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00019873", "row_id": 19873, "seed_ids": "[5779]" }
0.696354
Codeforces_19873
I
[ "find_shortest_path", "shortest_travel_time_and_path" ]
2
[ [ "shortest_travel_time_and_path", "find_shortest_path" ] ]
1
[]
false
[]
false
pytest
true
[]
true
a84c326306064819119b30f0383717a695a0cd58
f3063ce01fed21f813c0aebfb03d2648520cd0ec
v1.0
instruct
Codeforces
Codeforces_19889_I
You are given an array b[1], b[2], ..., b[m] containing m integers. Your task is to transform this array into a non-decreasing array using the following operation (you may need to apply it multiple times): - Select two indices i and j (1 ≤ i < j ≤ m) such that the sum of the subarray b[i], b[i+1], ..., b[j] is even, t...
def is_non_decreasing(arr): """ Checks if the given array is non-decreasing. """ return all(arr[i] <= arr[i + 1] for i in range(len(arr) - 1)) def reverse_subarray(arr, i, j): """ Returns a new array with the subarray from index i to j reversed. """ return arr[:i] + arr[i:j + 1][::-1] +...
from solution import transform_array def test_transform_array_case_1(): m = 5 b = [4, 3, 2, 1, 5] result = transform_array(m, b) assert result[0] > 0 # At least one operation must be performed final_array = b[:] for op in result[1:]: i, j = op final_array[i-1:j] = reversed(fina...
[ { "docstring": "Checks if the given array is non-decreasing.", "function_declaration": "def is_non_decreasing(arr):", "function_name": "is_non_decreasing", "parameter_list": "(arr)" }, { "docstring": "Returns a new array with the subarray from index i to j reversed.", "function_declarati...
[ 0, 0, 0, 0, 0, 0, 0, 0, 1 ]
1
hard
0.111
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def make_non_decreasing(m, b):\n operations = []\n for i in range(1, m):\n if b[i-1] > b[i]:\n j = i\n while j < m and (sum...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00019889", "row_id": 19889, "seed_ids": "[2776]" }
0.708156
Codeforces_19889
I
[ "is_non_decreasing", "reverse_subarray", "sum_is_even", "make_non_decreasing", "transform_array" ]
5
[ [ "make_non_decreasing", "is_non_decreasing" ], [ "make_non_decreasing", "reverse_subarray" ], [ "make_non_decreasing", "sum_is_even" ], [ "transform_array", "make_non_decreasing" ] ]
4
[]
false
[]
false
pytest
true
[]
true
27bb6a684d97924c6751b14a336e3487da659eb5
a560d8a7d6d9ae3da87b3f2a63eb2377a0fd306a
v1.0
instruct
Codeforces
Codeforces_19898_I
Peter is designing a new routing protocol for a network consisting of $$$n$$$ nodes labeled from $$$1$$$ to $$$n$$$. The network is represented as a tree. Each node can communicate directly with its adjacent nodes. We will denote this tree as $$$\mathcal{T}$$$. To improve the efficiency of routing messages, Peter want...
from collections import deque def find_farthest_node(tree, start_node): """ Performs a BFS to find the farthest node from the start_node. Returns the farthest node and its distance. """ n = len(tree) visited = [False] * n dist = [-1] * n queue = deque([start_node]) visited[start_nod...
from solution import add_extra_edge_to_minimize_diameter def test_case_1(): n = 4 edges = [(1, 2), (1, 3), (3, 4)] assert add_extra_edge_to_minimize_diameter(n, edges) in [(2, 4), (4, 2)] def test_case_2(): n = 5 edges = [(1, 2), (1, 3), (2, 4), (3, 5)] assert add_extra_edge_to_minimize_diamet...
[ { "docstring": "Performs a BFS to find the farthest node from the start_node.\nReturns the farthest node and its distance.", "function_declaration": "def find_farthest_node(tree, start_node):", "function_name": "find_farthest_node", "parameter_list": "(tree, start_node)" }, { "docstring": "F...
[ 0, 1, 0, 0, 0, 0, 0, 0, 0, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "from collections import deque, defaultdict\n\ndef find_best_edge(n, edges):\n def bfs(start):\n dist = [-1] * (n + 1)\n dist[start] = 0\n ...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00019898", "row_id": 19898, "seed_ids": "[2123]" }
0.693902
Codeforces_19898
I
[ "find_farthest_node", "find_diameter", "add_extra_edge_to_minimize_diameter" ]
3
[ [ "add_extra_edge_to_minimize_diameter", "find_diameter" ], [ "find_diameter", "find_farthest_node" ] ]
2
[]
false
[]
false
pytest
true
[]
true
40d0d5dbfa5700441d58a4e812eb89ce65010d72
f9cc17f697f6fdea526eebd7bcba013abb234b74
v1.0
instruct
Codeforces
Codeforces_19919_I
A park contains several paths, each connecting a pair of landmarks within the park. Each path has a certain distance associated with it. The park administration wants to install lights on the paths to ensure that every landmark is directly or indirectly lit by at least one light. However, due to budget constraints, the...
def find(parent, i): if parent[i] == i: return i return find(parent, parent[i]) def union(parent, rank, x, y): xroot = find(parent, x) yroot = find(parent, y) if rank[xroot] < rank[yroot]: parent[xroot] = yroot elif rank[xroot] > rank[yroot]: parent[yroot] = xroot el...
from solution import minimum_lights def test_example(): n = 4 m = 4 edges = [(1, 2, 1), (2, 3, 2), (3, 4, 1), (4, 1, 2)] assert minimum_lights(n, m, edges) == 3 def test_disconnected_graph(): n = 3 m = 1 edges = [(1, 2, 5)] assert minimum_lights(n, m, edges) == 1 def test_single_node(...
[ { "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, 1, 0, 0, 1, 1, 1, 0 ]
6
medium
0.6
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def minimum_lights_needed(n, m, paths):\n if n == 1:\n return 0 # Only one landmark, no light is needed.\n \n # A MATLAB-based approach to fi...
trial_gpt4o_6
{ "original_instruction": "", "prompt_id": "00019919", "row_id": 19919, "seed_ids": "[3416]" }
0.71193
Codeforces_19919
I
[ "find", "union", "minimum_lights" ]
3
[ [ "minimum_lights", "find" ], [ "minimum_lights", "union" ], [ "union", "find" ] ]
3
[]
false
[]
false
pytest
true
[]
true
3eaaae7fd512b0a6822feed6f52e3d3e37208ecb
7c63dcb2c907a9565b59b0637ad4a4ad6c2b64a4
v1.0
instruct
Codeforces
Codeforces_19926_I
In a distant land, there exists a kingdom with n cities, connected by m bidirectional roads. Each road has a positive integer weight representing the time it takes to travel between the two cities it connects. However, there is a powerful sorcerer in the kingdom who can teleport between certain pairs of cities instantl...
import heapq def dijkstra(n, roads, teleports, source=1): # Initialization graph = {i: [] for i in range(1, n + 1)} # Adding roads to graph for u, v, w in roads: graph[u].append((w, v)) graph[v].append((w, u)) # Adding teleportation pairs to graph with weight 0 for x, ...
def test_minimum_travel_time(): n = 5 m = 6 road_data = [ (1, 2, 2), (1, 3, 3), (2, 4, 4), (3, 4, 1), (4, 5, 5), (3, 5, 8) ] k = 1 teleport_data = [ (1, 5) ] result = minimum_travel_time(n, m, road_data, k, teleport_data) assert...
[ { "docstring": null, "function_declaration": "def dijkstra(n, roads, teleports, source=1):", "function_name": "dijkstra", "parameter_list": "(n, roads, teleports, source=1)" }, { "docstring": null, "function_declaration": "def minimum_travel_time(n, m, road_data, k, teleport_data):", ...
[ 1, 0, 0, 0, 1, 1, 0, 0, 0, 0 ]
3
hard
0.3
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "import heapq\n\ndef dijkstra(n, adj, start=1):\n dist = [float('inf')] * (n + 1)\n dist[start] = 0\n pq = [(0, start)] # (distance, node)\n while...
trial_gpt4o_5
{ "original_instruction": "", "prompt_id": "00019926", "row_id": 19926, "seed_ids": "[7157]" }
0.770795
Codeforces_19926
I
[ "dijkstra", "minimum_travel_time" ]
2
[ [ "minimum_travel_time", "dijkstra" ] ]
1
[]
false
[]
false
pytest
false
[]
true
12c207c6a5ce187941e170fda3264a5bb1ac09a2
46fc3fd8e245320e6eccd14356276f75200e5af7
v1.0
instruct
Codeforces
Codeforces_19956_I
You are given a simple undirected graph with "n" vertices and "m" edges. Each vertex of the graph has a unique integer identifier from 1 to n. Your task is to determine if there is a simple path in the graph that visits each vertex exactly once. The input to the program will be two integers n and m, representing the n...
def hamiltonian_path_exists(n, m, edges): from itertools import permutations # Generate adjacency matrix adj = [[0] * n for _ in range(n)] for u, v in edges: adj[u-1][v-1] = 1 adj[v-1][u-1] = 1 # Check all permutations of vertices to see if any is a hamiltonian path for...
def test_hamiltonian_path_exists(): # Test case 1 assert hamiltonian_path_exists(4, 4, [(1, 2), (2, 3), (3, 4), (4, 1)]) == True # Test case 2 assert hamiltonian_path_exists(4, 3, [(1, 2), (2, 3), (3, 4)]) == True # Test case 3 assert hamiltonian_path_exists(4, 3, [(1, 2), (2, 3), (3, 1)]) == Fa...
[ { "docstring": null, "function_declaration": "def hamiltonian_path_exists(n, m, edges):", "function_name": "hamiltonian_path_exists", "parameter_list": "(n, m, edges)" }, { "docstring": null, "function_declaration": "def solve(n, m, edges):", "function_name": "solve", "parameter_...
[ 0, 0, 0, 0, 1, 0, 0, 1, 0, 0 ]
2
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def has_hamiltonian_path(n, m, edges):\n from itertools import permutations\n \n if n == 1:\n return \"YES\"\n\n graph = {i: set() for i in...
trial_gpt4o_7
{ "original_instruction": "", "prompt_id": "00019956", "row_id": 19956, "seed_ids": "[5649]" }
0.707898
Codeforces_19956
I
[ "hamiltonian_path_exists", "solve" ]
2
[ [ "solve", "hamiltonian_path_exists" ] ]
1
[]
false
[]
false
pytest
false
[]
true
0740ef5018072ab2cafa3018d319daa8582f225f
ee659889361d6d6662bdb3f1374486fcd570a0c3
v1.0
instruct
Codeforces
Codeforces_19986_I
### Automated Garbage Collection Optimization The city council has decided to implement a new automated system for managing garbage collection routes. Each day, smart garbage trucks will follow a specific route that maximizes efficiency, such as minimizing the total distance traveled while ensuring all garbage bins al...
import itertools import math def euclidean_distance(point1, point2): return math.sqrt((point1[0] - point2[0]) ** 2 + (point1[1] - point2[1]) ** 2) def optimal_garbage_collection(n, coordinates): all_permutations = itertools.permutations(coordinates) min_distance = float('inf') for perm in all_permuta...
from solution import optimal_garbage_collection def test_optimal_garbage_collection_example(): coordinates = [(0, 0), (2, 0), (2, 2), (0, 2)] assert optimal_garbage_collection(4, coordinates) == 8.0000 def test_optimal_garbage_collection_case1(): coordinates = [(0, 0), (1, 0), (1, 1), (0, 1)] assert o...
[ { "docstring": null, "function_declaration": "def euclidean_distance(point1, point2):", "function_name": "euclidean_distance", "parameter_list": "(point1, point2)" }, { "docstring": null, "function_declaration": "def optimal_garbage_collection(n, coordinates):", "function_name": "opt...
[ 0, 0, 0, 0, 0, 1, 0, 0, 0, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "import itertools\nimport math\n\ndef calculate_distance(point1, point2):\n return math.sqrt((point2[0] - point1[0]) ** 2 + (point2[1] - point1[1]) ** 2)\n\...
trial_gpt4o_5
{ "original_instruction": "", "prompt_id": "00019986", "row_id": 19986, "seed_ids": "[102]" }
0.716232
Codeforces_19986
I
[ "euclidean_distance", "optimal_garbage_collection" ]
2
[ [ "optimal_garbage_collection", "euclidean_distance" ] ]
1
[]
false
[]
false
pytest
true
[]
true
54cf480d182a0cf214bcce500a62062623b2011d
53f99c35fbef5bb68308fac369cbcfec7ab7041e
v1.0
instruct
Codeforces
Codeforces_20047_I
You are given a string `s` consisting of lowercase English letters and a set of `words` consisting of non-empty strings made of lowercase English letters. The task is to count how many of the words from the `words` list are subsequences of the string `s`. A subsequence is a sequence that can be derived from another se...
def is_subsequence(s, word): it = iter(s) return all(char in it for char in word) def count_subsequences(s, words): """ Counts how many words in the list are subsequences of the string `s`. """ return sum(is_subsequence(s, word) for word in words)
from solution import count_subsequences def test_example_case(): s = "abcdefg" words = ["abc", "abg", "bdf", "acb", "bgf"] assert count_subsequences(s, words) == 3 def test_single_char_words(): s = "abc" words = ["a", "b", "c", "d"] assert count_subsequences(s, words) == 3 def test_identical_...
[ { "docstring": null, "function_declaration": "def is_subsequence(s, word):", "function_name": "is_subsequence", "parameter_list": "(s, word)" }, { "docstring": "Counts how many words in the list are subsequences of the string `s`.", "function_declaration": "def count_subsequences(s, word...
[ 1, 0, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "from collections import defaultdict\n\ndef num_matching_subseq(s, words):\n \"\"\"\n Given a string s and a list of words, returns the number of words t...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00020047", "row_id": 20047, "seed_ids": "[2016, 1192, 7869]" }
0.827164
Codeforces_20047
I
[ "is_subsequence", "count_subsequences" ]
2
[ [ "count_subsequences", "is_subsequence" ] ]
1
[]
false
[]
false
pytest
true
[]
true
f5bee4276660463fd176214c60fa2986df0a0030
e0f8dd22199935e2ccb3a23f227208976e4802ea
v1.0
instruct
Codeforces
Codeforces_20087_I
You are given a matrix of size \( n \times m \) filled with non-negative integers. Your task is to find the sum of elements in the submatrix defined by its top-left and bottom-right corners. The top-left corner is at \((i_1, j_1)\) and the bottom-right corner is at \((i_2, j_2)\). The matrix is \( A \), where \( A[i][...
def preprocess_matrix(matrix): """ Preprocess the matrix using prefix sums for efficient submatrix sum queries. """ 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] ...
from solution import preprocess_matrix, submatrix_sum, handle_queries def test_preprocess_matrix(): matrix = [ [1, 2, 3], [4, 5, 6], [7, 8, 9] ] expected_prefix_sum = [ [0, 0, 0, 0], [0, 1, 3, 6], [0, 5, 12, 21], [0, 12, 27, 45] ] assert prepr...
[ { "docstring": "Preprocess the matrix using prefix sums for efficient submatrix sum queries.", "function_declaration": "def preprocess_matrix(matrix):", "function_name": "preprocess_matrix", "parameter_list": "(matrix)" }, { "docstring": "Calculate the sum of the submatrix using the precompu...
[ 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 build_prefix_sum_matrix(matrix):\n n = len(matrix)\n m = len(matrix[0]) if n > 0 else 0\n prefix_sum = [[0] * (m + 1) for _ in range(n + 1)]\n ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00020087", "row_id": 20087, "seed_ids": "[7617, 6065, 6191]" }
0.626426
Codeforces_20087
I
[ "preprocess_matrix", "submatrix_sum", "handle_queries" ]
3
[ [ "handle_queries", "preprocess_matrix" ], [ "handle_queries", "submatrix_sum" ] ]
2
[ "handle_queries" ]
false
[]
false
pytest
true
[]
true
cf1ac31b665bf2d3156a6ddbc767718b6bd770c6
4d33e18a9a1fc2df9d9f52b914380ae23c9d9823
v1.0
instruct
Codeforces
Codeforces_20108_I
A small city is planning to build a new road network. There are n intersections in the city, numbered from 1 to n. Some pairs of intersections are already connected directly by bi-directional roads. Each road has a specific travel time associated with it. The city planner needs to ensure that any intersection can be re...
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_basic_scenario(): n = 4 roads = [ (1, 2, 3), (2, 3, 4), (3, 4, 5), (1, 4, 10) ] assert minimum_travel_time(n, roads) == 12 def test_no_roads(): n = 4 roads = [] assert minimum_travel_time(n, roads) == -1 def test_single_road(): n = 2 roads =...
[ { "docstring": null, "function_declaration": "def find(parent, i):", "function_name": "find", "parameter_list": "(parent, i)" }, { "docstring": null, "function_declaration": "def union(parent, rank, x, y):", "function_name": "union", "parameter_list": "(parent, rank, x, y)" }, ...
[ 0, 1 ]
1
medium
0.5
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def minimum_total_travel_time(n, m, roads):\n \"\"\"\n Determines the minimum total travel time required to ensure that every intersection\n is reach...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00020108", "row_id": 20108, "seed_ids": "[1957, 7344, 1075]" }
0.751924
Codeforces_20108
I
[ "find", "union", "kruskal", "minimum_travel_time" ]
4
[ [ "kruskal", "find" ], [ "kruskal", "union" ], [ "minimum_travel_time", "kruskal" ], [ "union", "find" ] ]
4
[]
false
[]
false
pytest
false
[]
true
fad6a28ccde74f618d3c71570f4bc11aededeb06
c0bf7dbfec2853c0cbe0d39bc2f164b5584c5f6a
v1.0
instruct
Codeforces
Codeforces_20113_I
Frank has an unusual prime number obsession. He collects prime numbers in a special sequence called "alternating prime sum". The alternating prime sum sequence is defined as follows: The first prime number in the sequence is 2. The second prime is subtracted from the first, the third is added to the sequence, the fou...
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 nth_alternating_prime_sum(...
from solution import nth_alternating_prime_sum def test_nth_alternating_prime_sum_1(): assert nth_alternating_prime_sum(1) == 2 def test_nth_alternating_prime_sum_2(): assert nth_alternating_prime_sum(2) == -1 def test_nth_alternating_prime_sum_3(): assert nth_alternating_prime_sum(3) == 4 def test_nth_...
[ { "docstring": null, "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": "Calculates the n-th term of Frank's \"alternating prime sum\" sequence.\n\nArgs:\nn (int): The term number to compute (1 ≤ n ≤ 1000).\n\nReturns:\nint:...
[ 1, 0, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(num):\n if num <= 1:\n return False\n if num <= 3:\n return True\n if num % 2 == 0 or num % 3 == 0:\n return False\...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00020113", "row_id": 20113, "seed_ids": "[2229, 7327, 4197]" }
0.563576
Codeforces_20113
I
[ "is_prime", "nth_alternating_prime_sum" ]
2
[ [ "nth_alternating_prime_sum", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
e7a7223c56b491997696e5f752a985a02ed7ce0a
2b974e13d005c2e3a4584a740db0ccac3f9eaf92
v1.0
instruct
Codeforces
Codeforces_20118_I
A local government wants to improve its road infrastructure to minimize travel costs between towns. There are `n` towns and `m` bidirectional roads connecting some pairs of towns, with each road having an associated cost. The government plans to construct new roads to ensure that every town can be reached from every ot...
def find(parent, i): if parent[i] == i: return i else: parent[i] = find(parent, parent[i]) return parent[i] def union(parent, rank, x, y): rootX = find(parent, x) rootY = find(parent, y) if rootX != rootY: if rank[rootX] > rank[rootY]: parent[rootY] = roo...
from solution import minimum_cost_to_connect_towns def test_example1(): n = 4 roads = [(1, 2, 3), (2, 3, 4), (3, 4, 5)] assert minimum_cost_to_connect_towns(n, roads) == 12 def test_example2(): n = 2 roads = [(1, 2, 1)] assert minimum_cost_to_connect_towns(n, roads) == 1 def test_example3(): ...
[ { "docstring": null, "function_declaration": "def find(parent, i):", "function_name": "find", "parameter_list": "(parent, i)" }, { "docstring": null, "function_declaration": "def union(parent, rank, x, y):", "function_name": "union", "parameter_list": "(parent, rank, x, y)" }, ...
[ 0, 0, 0, 1, 1 ]
2
medium
0.4
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def minimum_road_construction_cost(n, m, roads):\n \"\"\"\n Returns the minimum total cost to make the road network connected.\n If it is impossible ...
trial_gpt4o_3
{ "original_instruction": "", "prompt_id": "00020118", "row_id": 20118, "seed_ids": "[4197, 1936, 4951]" }
0.785401
Codeforces_20118
I
[ "find", "union", "minimum_cost_to_connect_towns" ]
3
[ [ "minimum_cost_to_connect_towns", "find" ], [ "minimum_cost_to_connect_towns", "union" ], [ "union", "find" ] ]
3
[]
false
[]
false
pytest
true
[]
true
d08bd25cf5b14e5b1cd0ae3ef812c43a3cce04bd
822729be85ecb0294343b6cf515629acada33969
v1.0
instruct
Codeforces
Codeforces_20161_I
Alice has a collection of unique prime numbers and she loves to create different subsets of these primes. Given a list of prime numbers, she wants to know how many subsets of these primes have a product that is also a prime number. She needs your help to find out. A prime number is a natural number greater than 1 that...
def is_prime(num): """Helper function to 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 ...
from solution import count_prime_product_subsets, is_prime def test_is_prime_function(): 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_example_case(): primes = [2, 3, 5, 7, 11] assert coun...
[ { "docstring": "Helper function to check if a number is prime.", "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": "Function to count subsets whose product is also a prime number.", "function_declaration": "def count_pr...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(num):\n \"\"\"Helper function to check if a number is prime.\"\"\"\n if num <= 1:\n return False\n if num <= 3:\n return T...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00020161", "row_id": 20161, "seed_ids": "[1908, 7953, 7000]" }
0.546368
Codeforces_20161
I
[ "is_prime", "count_prime_product_subsets" ]
2
[ [ "count_prime_product_subsets", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
0afc2ef7b79f770fd316ad9f16e34e11dcda2e44
673489b7b5941662459638ecde016e9f69306b9b
v1.0
instruct
Codeforces
Codeforces_20177_I
Alice loves designing patterns with numbers. She especially likes working with matrices where specific values are placed according to her unique rules. Recently, she created a new type of pattern where for any given integer, the matrices must follow these rules: 1. The matrix is always square with a size of $$$n \time...
def construct_matrix(n, k): """ Constructs an n x n matrix where the sum of each row and each column equals k. If such a matrix is possible, returns "YES" followed by the matrix. Otherwise, returns "NO". """ # If k cannot be evenly divided into n cells, return NO if k % n != 0: retur...
import pytest from solution import construct_matrix, format_matrix_output def test_construct_matrix_possible_case(): assert construct_matrix(3, 6) == ("YES", [[2, 2, 2], [2, 2, 2], [2, 2, 2]]) def test_construct_matrix_possible_case_all_zeros(): assert construct_matrix(4, 0) == ("YES", [[0, 0, 0, 0], [0, 0, 0...
[ { "docstring": "Constructs an n x n matrix where the sum of each row and each column equals k.\nIf such a matrix is possible, returns \"YES\" followed by the matrix.\nOtherwise, returns \"NO\".", "function_declaration": "def construct_matrix(n, k):", "function_name": "construct_matrix", "parameter_l...
[ 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 construct_matrix(n, k):\n \"\"\"\n Constructs an n x n matrix where the sum of each row and column is k.\n Returns \"YES\" followed by the matrix...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00020177", "row_id": 20177, "seed_ids": "[7472, 2783, 7650]" }
0.643913
Codeforces_20177
I
[ "construct_matrix", "format_matrix_output" ]
2
[ [ "format_matrix_output", "construct_matrix" ] ]
1
[]
false
[]
false
pytest
true
[]
true
a5ab1e015e698b6d7da470ae33f683c9173376af
ebde254c2030f12d5d3170ec93eab4cb493f8f67
v1.0
instruct
Codeforces
Codeforces_20186_I
You are given a city grid of size n x m where each cell in the grid represents a building which has a certain height. Your task is to identify the largest rectangular area in the grid where every cell within the rectangle has the same height. The input consists of: - The first line contains two integers n and m (1 ≤ n...
def largest_rectangle_area(grid): """ This function takes a 2D list of integers representing building heights and returns the largest rectangular area where every building within the rectangle has the same height. """ if not grid: return 0 n, m = len(grid), len(grid[0]) max_area = 0...
from solution import largest_rectangle_area def test_largest_rectangle_area(): grid = [ [1, 1, 1, 0, 0], [1, 1, 1, 0, 0], [1, 1, 1, 0, 0], [0, 0, 0, 0, 0] ] assert largest_rectangle_area(grid) == 9 def test_single_cell_grid(): grid = [ [1] ] assert l...
[ { "docstring": "This function takes a 2D list of integers representing building heights and returns\nthe largest rectangular area where every building within the rectangle has the same height.", "function_declaration": "def largest_rectangle_area(grid):", "function_name": "largest_rectangle_area", "...
[ 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 maximalRectangle(matrix):\n if not matrix:\n return 0\n n, m = len(matrix), len(matrix[0])\n max_area = 0\n heights = [0] * m\n \n ...
trial_gpt4o_7
{ "original_instruction": "", "prompt_id": "00020186", "row_id": 20186, "seed_ids": "[184, 7258, 7213]" }
0.720749
Codeforces_20186
I
[ "largest_rectangle_area", "max_histogram_area" ]
2
[ [ "largest_rectangle_area", "max_histogram_area" ] ]
1
[]
false
[]
false
pytest
true
[]
true
70b9f9dac25e32b03dcd0dadc3fd3c37040d0bfa
8ca9e9dfdf6103513e9f58ff692ffbcb4efab199
v1.0
instruct
Codeforces
Codeforces_20188_I
You are given a binary tree rooted at node containing the integer value $$$1$$$. Each node in the binary tree contains a unique integer value. Your task is to determine the shortest path between any two given nodes in the tree. The path length between two nodes is defined as the number of edges on the path between th...
from collections import defaultdict, deque def build_tree(n, edges): tree = defaultdict(list) for u, v in edges: tree[u].append(v) tree[v].append(u) return tree def bfs_distance(tree, start): distances = {start: 0} queue = deque([start]) while queue: node = queue.poplef...
from solution import shortest_path_length def test_example_case(): n = 5 edges = [(1, 2), (1, 3), (2, 4), (2, 5)] queries = [(4, 5), (4, 3), (3, 5)] assert shortest_path_length(n, edges, queries) == [2, 3, 3] def test_chain_tree(): n = 4 edges = [(1, 2), (2, 3), (3, 4)] queries = [(1, 4), ...
[ { "docstring": null, "function_declaration": "def build_tree(n, edges):", "function_name": "build_tree", "parameter_list": "(n, edges)" }, { "docstring": null, "function_declaration": "def bfs_distance(tree, start):", "function_name": "bfs_distance", "parameter_list": "(tree, sta...
[ 0, 0, 0, 0, 0, 1, 0, 1, 0, 0 ]
2
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "from collections import defaultdict, deque\n\ndef shortest_path(n, edges, queries):\n # Build the tree as an adjacency list\n tree = defaultdict(list)\n...
trial_gpt4o_7
{ "original_instruction": "", "prompt_id": "00020188", "row_id": 20188, "seed_ids": "[7848, 127, 3150]" }
0.72378
Codeforces_20188
I
[ "build_tree", "bfs_distance", "shortest_path_length" ]
3
[ [ "shortest_path_length", "bfs_distance" ], [ "shortest_path_length", "build_tree" ] ]
2
[]
false
[]
false
pytest
true
[]
true
36983e227dcef2fec7adcedfecce52b44a5cac26
020e51ba5aeb443944e16b239086f85218d4c372
v1.0
instruct
Codeforces
Codeforces_20193_I
You are given an array of integers that represents the number of pages in different books. You have k students, and you want to allocate all the books to these students such that each student gets at least one book and the maximum number of pages assigned to a student is minimized. The task is to find the minimum poss...
def is_possible(books, n, k, max_pages): students_required = 1 current_pages = 0 for pages in books: if current_pages + pages > max_pages: students_required += 1 current_pages = pages if students_required > k: return False else: ...
def test_find_min_max_pages_case_1(): books = [12, 34, 67, 90] k = 2 assert find_min_max_pages(books, len(books), k) == 113 def test_find_min_max_pages_case_2(): books = [10, 20, 30, 40] k = 2 assert find_min_max_pages(books, len(books), k) == 60 def test_find_min_max_pages_case_3(): books...
[ { "docstring": null, "function_declaration": "def is_possible(books, n, k, max_pages):", "function_name": "is_possible", "parameter_list": "(books, n, k, max_pages)" }, { "docstring": null, "function_declaration": "def find_min_max_pages(books, n, k):", "function_name": "find_min_max...
[ 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_possible(books, n, k, curr_min):\n students_required = 1\n current_sum = 0\n\n for i in range(n):\n if books[i] > curr_min:\n ...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00020193", "row_id": 20193, "seed_ids": "[1303, 806, 7518]" }
0.667949
Codeforces_20193
I
[ "is_possible", "find_min_max_pages" ]
2
[ [ "find_min_max_pages", "is_possible" ] ]
1
[]
false
[]
false
pytest
false
[]
true
5c3417eb64228c172098e9474b7ba37e635bd113
87a4df3d92408938ab324635edb80a8da83d42a3
v1.0
instruct
Codeforces
Codeforces_20194_I
You are given a grid with n rows and n columns, and each cell contains an integer value. The task is to answer multiple queries, each asking for the sum of elements in a subgrid defined by a given set of boundaries. Specifically, each query specifies a rectangular subgrid by the top-left cell (r1, c1) and the bottom-r...
def preprocess_grid(grid): """ Preprocess the grid to create a prefix sum matrix for quick area sum lookup. """ n = len(grid) prefix_sum = [[0] * (n + 1) for _ in range(n + 1)] for i in range(1, n + 1): for j in range(1, n + 1): prefix_sum[i][j] = grid[i-1][j-1] + prefix...
from solution import solve def test_example_case(): n = 3 q = 2 grid = [ [1, 2, 3], [4, 5, 6], [7, 8, 9] ] queries = [ (1, 1, 2, 2), (2, 2, 3, 3) ] expected = [12, 28] assert solve(n, q, grid, queries) == expected def test_single_element_subgrid(...
[ { "docstring": "Preprocess the grid to create a prefix sum matrix for quick area sum lookup.", "function_declaration": "def preprocess_grid(grid):", "function_name": "preprocess_grid", "parameter_list": "(grid)" }, { "docstring": "Calculate the sum of the subgrid using the prefix sum matrix....
[ 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_grid(grid):\n n = len(grid)\n prefix_sum = [[0] * (n + 1) for _ in range(n + 1)]\n for i in range(1, n + 1):\n for j in range(1...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00020194", "row_id": 20194, "seed_ids": "[5610, 1068, 6068]" }
0.674014
Codeforces_20194
I
[ "preprocess_grid", "subgrid_sum", "solve" ]
3
[ [ "solve", "preprocess_grid" ], [ "solve", "subgrid_sum" ] ]
2
[]
false
[]
false
pytest
true
[]
true
28b67766393b28847ae4106c4140700c9f3e898a
d858897ce3e60014e7f8900bf4d9f2a5abbf6943
v1.0
instruct
Codeforces
Codeforces_20208_I
Nicole is a graphic designer who frequently works with grids of pixels. She wants to create a mosaic, which is an m x n grid, where each cell contains an integer representing a color. Given the grid and a sequence of swap operations, where each operation consists of swapping the content of two specified cells, help Ni...
def perform_swaps(grid, operations): """ Perform the given swap operations on the grid and return the final state of the grid. :param grid: List of lists representing the initial state of the grid. :param operations: List of tuples representing swap operations. :return: List of lists representing t...
def test_sample_case(): m, n, k = 3, 3, 2 grid = [ [1, 2, 3], [4, 5, 6], [7, 8, 9] ] operations = [ (1, 1, 3, 3), (2, 2, 3, 1) ] expected_output = [ [9, 2, 3], [4, 7, 6], [5, 8, 1] ] assert read_input_and_process_operations(...
[ { "docstring": "Perform the given swap operations on the grid and return the final state of the grid.\n\n:param grid: List of lists representing the initial state of the grid.\n:param operations: List of tuples representing swap operations.\n:return: List of lists representing the final state of the grid after ...
[ 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 perform_swaps(grid, operations):\n \"\"\"\n Perform the given swap operations on the grid and return the final state of the grid.\n\n :param grid...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00020208", "row_id": 20208, "seed_ids": "[5632, 2088, 99]" }
0.727562
Codeforces_20208
I
[ "perform_swaps", "read_input_and_process_operations" ]
2
[ [ "read_input_and_process_operations", "perform_swaps" ] ]
1
[]
false
[]
false
pytest
false
[]
true
62cb924174b4bae93984feedc3620d3bd06bee31
e28968ba015f9f1b33bf3b583bae1f1148134eb6
v1.0
instruct
Codeforces
Codeforces_20244_I
Alex is preparing for a mission to Mars and needs to efficiently pack his backpack with supplies. The backpack has a maximum weight capacity of W. Alex has n types of items, each with a specific weight and value. He wants to maximize the total value of the items in his backpack without exceeding the weight capacity. G...
def knapsack(n, W, items): """ Returns the maximum total value of items that can be put in a knapsack of capacity W. :param n: Number of items :param W: Maximum weight capacity of the knapsack :param items: List of (weight, value) tuples :return: Maximum value that can be achieved """ ...
from solution import solve_knapsack def test_example_case(): input_data = "3 50\n10 60\n20 100\n30 120" assert solve_knapsack(input_data) == 220 def test_case_with_zero_values(): input_data = "3 50\n10 0\n20 0\n30 0" assert solve_knapsack(input_data) == 0 def test_case_with_high_value_low_weight(): ...
[ { "docstring": "Returns the maximum total value of items that can be put in a knapsack of capacity W.\n\n:param n: Number of items\n:param W: Maximum weight capacity of the knapsack\n:param items: List of (weight, value) tuples\n:return: Maximum value that can be achieved", "function_declaration": "def knap...
[ 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 knapsack(n, W, items):\n \"\"\"\n Returns the maximum value that can be achieved with a given weight capacity.\n :param n: int - Number of items\...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00020244", "row_id": 20244, "seed_ids": "[2901, 2883, 1139]" }
0.749733
Codeforces_20244
I
[ "knapsack", "parse_input", "solve_knapsack" ]
3
[ [ "solve_knapsack", "knapsack" ], [ "solve_knapsack", "parse_input" ] ]
2
[ "parse_input" ]
false
[]
false
pytest
true
[]
true
d2b269531c8dcb0a7355959974761c81021d61da
11b365e4c297d3460f717ac41ea9d2ed0b4576fc
v1.0
instruct
Codeforces
Codeforces_20277_I
Colony of Bacteria A colony of bacteria grows in a rectangular grid with dimensions m × n. Each cell in the grid can either be empty (denoted by 0) or contain a bacterium (denoted by 1). Over time, the bacteria spread to adjacent cells according to the following rules: 1. A bacterium in a cell will die if it has fewer...
def get_next_state(grid): """ Given the current state of the grid, compute the state for the next generation. """ m, n = len(grid), len(grid[0]) next_grid = [[0] * n for _ in range(m)] def count_adjacent_bacteria(x, y): directions = [(-1, -1), (-1, 0), (-1, 1), (0, -1), (0, 1), (1, ...
from solution import bacteria_colony def test_bacteria_colony_case1(): initial_state = [ [0, 1, 0, 0, 0], [0, 0, 1, 0, 0], [1, 1, 1, 0, 0], [0, 0, 0, 0, 0] ] m, n, k = 4, 5, 1 expected_state = [ [0, 0, 0, 0, 0], [1, 0, 1, 0, 0], [0, 1, 1, 0, 0], ...
[ { "docstring": "Given the current state of the grid, compute the state for the next generation.", "function_declaration": "def get_next_state(grid):", "function_name": "get_next_state", "parameter_list": "(grid)" }, { "docstring": null, "function_declaration": "def bacteria_colony(m, n, ...
[ 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 update_grid(grid, m, n):\n def count_adjacent_bacteria(x, y):\n directions = [(-1, -1), (-1, 0), (-1, 1), (0, -1), (0, 1), (1, -1), (1, 0), (1, ...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00020277", "row_id": 20277, "seed_ids": "[1983, 3751, 611]" }
0.611939
Codeforces_20277
I
[ "get_next_state", "bacteria_colony", "print_grid" ]
3
[ [ "bacteria_colony", "get_next_state" ] ]
1
[]
false
[]
false
pytest
true
[]
true
d4c01568cb3d061a1a7db12d76f274ade528e485
e141539c4b1056ad8410ea4a78e757037c237b46
v1.0
instruct
Codeforces
Codeforces_20281_I
John loves playing with strings. Recently, he came across a string consisting of lowercase Latin letters and decided to perform some operations on it. He has devised two types of operations that he can perform on this string: 1. Replace a sub-string with another string of equal length. 2. Query a sub-string and check ...
def is_palindrome(s): """ Helper function to check if a given string s is a palindrome. """ return s == s[::-1] def process_operations(n, s, operations): """ Processes a list of operations on the string s. Parameters: n (int): The length of the string. s (str): The init...
from solution import process_operations def test_example_case(): n = 5 s = "abcba" operations = ["query 0 4", "replace 1 3 xyz", "query 0 4"] result = process_operations(n, s, operations) assert result == ["YES", "NO"] def test_replace_only(): n = 3 s = "abc" operations = ["replace 0 2...
[ { "docstring": "Helper function to check if a given string s is a palindrome.", "function_declaration": "def is_palindrome(s):", "function_name": "is_palindrome", "parameter_list": "(s)" }, { "docstring": "Processes a list of operations on the string s.\n\nParameters:\n n (int): The lengt...
[ 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 perform_operations(n, s, q, operations):\n result = []\n s = list(s) # Convert string to list for mutable operations\n\n for operation in operat...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00020281", "row_id": 20281, "seed_ids": "[5315, 551, 1774]" }
0.812392
Codeforces_20281
I
[ "is_palindrome", "process_operations" ]
2
[ [ "process_operations", "is_palindrome" ] ]
1
[]
false
[]
false
pytest
true
[]
true
44510e18f0702c45732d871b17d9e40c086a83ca
ef5980193442304f41612342c97be2bc8764332e
v1.0
instruct
Codeforces
Codeforces_20284_I
Given an array of integers, you must determine whether you can make the array sorted in non-decreasing order by removing exactly one or zero elements. In other words, you need to check if it's possible to achieve a sorted array after removing at most one element from the array. The input consists of multiple test case...
def can_be_sorted_by_removing_one_element(t, test_cases): results = [] for case in test_cases: n, arr = case if is_sorted(arr): results.append("YES") continue found_solution = False for i in range(n): new_arr = arr[:i] + arr[i+1:] ...
def test_can_be_sorted_by_removing_one_element(): test_cases = [ (5, [1, 2, 10, 5, 7]), (4, [1, 2, 3, 4]), (6, [10, 5, 1, 3, 4, 6]) ] t = len(test_cases) result = can_be_sorted_by_removing_one_element(t, test_cases) assert result == ["YES", "YES", "NO"] def test_can_be_sorte...
[ { "docstring": null, "function_declaration": "def can_be_sorted_by_removing_one_element(t, test_cases):", "function_name": "can_be_sorted_by_removing_one_element", "parameter_list": "(t, test_cases)" }, { "docstring": null, "function_declaration": "def is_sorted(arr):", "function_nam...
[ 1, 1, 0 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def can_be_sorted_by_removing_one_element(arr):\n n = len(arr)\n\n def is_sorted(array):\n return all(array[i] <= array[i + 1] for i in range(len...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00020284", "row_id": 20284, "seed_ids": "[4800, 5353, 5422]" }
0.722496
Codeforces_20284
I
[ "can_be_sorted_by_removing_one_element", "is_sorted" ]
2
[ [ "can_be_sorted_by_removing_one_element", "is_sorted" ] ]
1
[]
false
[]
false
pytest
false
[]
true
3d525c5da00b8b41738569b2f3e46c0ad9509129
31816b3b5de9c4953f32d26b513e96e91a1ceafd
v1.0
instruct
Codeforces
Codeforces_20313_I
You are given an array of integers and you need to answer multiple queries about it. Each query consists of two integers l and r, and you need to find the sum of all the even numbers in the segment of the array from index l to index r, inclusive (1-based indexing). The array and queries have the following constraints:...
def precompute_even_prefix_sums(arr): n = len(arr) even_prefix_sums = [0] * (n + 1) # initialize prefix sum array with an extra zero at the beginning for i in range(1, n + 1): even_prefix_sums[i] = even_prefix_sums[i - 1] + (arr[i - 1] if arr[i - 1] % 2 == 0 else 0) return even_prefix_sums def...
from solution import precompute_even_prefix_sums, query_even_sum, process_queries def test_precompute_even_prefix_sums(): arr = [1, 2, 3, 4, 5, 6] expected = [0, 0, 2, 2, 6, 6, 12] assert precompute_even_prefix_sums(arr) == expected def test_query_even_sum(): arr = [1, 2, 3, 4, 5, 6] even_prefix_s...
[ { "docstring": null, "function_declaration": "def precompute_even_prefix_sums(arr):", "function_name": "precompute_even_prefix_sums", "parameter_list": "(arr)" }, { "docstring": null, "function_declaration": "def query_even_sum(even_prefix_sums, l, r):", "function_name": "query_even_...
[ 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_even_sum(arr):\n \"\"\"\n Preprocess the given array to create a prefix sum array for even numbers.\n \n Parameters:\n arr (list...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00020313", "row_id": 20313, "seed_ids": "[3635, 8315, 680]" }
0.680731
Codeforces_20313
I
[ "precompute_even_prefix_sums", "query_even_sum", "process_queries" ]
3
[ [ "process_queries", "precompute_even_prefix_sums" ], [ "process_queries", "query_even_sum" ] ]
2
[ "process_queries" ]
false
[]
false
pytest
true
[]
true
f451be448ab462798599dc6170c59918fe6a4a68
034a043cdf6b0a1606f7d56a122e3c3b99193225
v1.0
instruct
Codeforces
Codeforces_20354_I
A medieval kingdom has a number of castles connected by bidirectional roads. Each road has a certain toll fee associated with it. The king wants to maintain control over all the castles while minimizing the total toll fees collected. You are given an integer n, the number of castles, and an integer e, the number of ro...
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_toll def test_example_case(): n = 4 e = 5 roads = [ (1, 2, 3), (2, 3, 4), (3, 4, 2), (1, 3, 5), (1, 4, 8) ] assert minimum_toll(n, e, roads) == 9 def test_single_castle(): assert minimum_toll(1, 0, []) == 0 def test_disconne...
[ { "docstring": null, "function_declaration": "def find(parent, i):", "function_name": "find", "parameter_list": "(parent, i)" }, { "docstring": null, "function_declaration": "def union(parent, rank, x, y):", "function_name": "union", "parameter_list": "(parent, rank, x, y)" }, ...
[ 1, 0, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def find(parent, i):\n if parent[i] == i:\n return i\n else:\n parent[i] = find(parent, parent[i])\n return parent[i]\n\ndef union(...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00020354", "row_id": 20354, "seed_ids": "[3122, 510, 6439]" }
0.689732
Codeforces_20354
I
[ "find", "union", "kruskal_mst", "minimum_toll" ]
4
[ [ "kruskal_mst", "find" ], [ "kruskal_mst", "union" ], [ "minimum_toll", "kruskal_mst" ], [ "union", "find" ] ]
4
[]
false
[]
false
pytest
true
[]
true
677bd0454f87f7aeb3b200ba3b7801576eb002f0
f60e6277bea36b5e54c42b42a2cf5d39b16549d9
v1.0
instruct
Codeforces
Codeforces_20402_I
The kingdom of Lexocrypt is known for its large collection of ancient encrypted texts. Given a set of encrypted messages, each represented by a string of lowercase letters, the king's cryptanalysts have identified that certain messages share common prefix patterns. To further their research, they need to determine the ...
def longest_common_prefix_length(str1, str2): """ Returns the length of the longest common prefix between str1 and str2. """ common_length = 0 for a, b in zip(str1, str2): if a == b: common_length += 1 else: break return common_length def max_common_prefi...
from solution import longest_common_prefix_length, max_common_prefix_length def test_longest_common_prefix_length(): assert longest_common_prefix_length("apple", "ape") == 2 assert longest_common_prefix_length("apple", "apricot") == 2 assert longest_common_prefix_length("banana", "band") == 3 assert lo...
[ { "docstring": "Returns the length of the longest common prefix between str1 and str2.", "function_declaration": "def longest_common_prefix_length(str1, str2):", "function_name": "longest_common_prefix_length", "parameter_list": "(str1, str2)" }, { "docstring": "Returns the maximum length of...
[ 0, 0, 1 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def longest_common_prefix_length(messages):\n \"\"\"\n Given a list of messages, determines the maximum length of a common prefix shared\n by any two...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00020402", "row_id": 20402, "seed_ids": "[2134, 7807, 198]" }
0.663862
Codeforces_20402
I
[ "longest_common_prefix_length", "max_common_prefix_length" ]
2
[ [ "max_common_prefix_length", "longest_common_prefix_length" ] ]
1
[]
false
[]
false
pytest
true
[]
true
32a3ff82635f9617e5bb36f7b1f0d3eb9b45f585
ebb314ee83d65dd58097e5e6b6e18dbdf1db43b3
v1.0
instruct
Codeforces
Codeforces_20450_I
You are given n chisels and a block of wood. The task is to carve out k slots on the block using the given chisels. Each chisel has a specific width and can create a slot of that width on the block. You are allowed to use each chisel at most once. You need to determine if it is possible to create exactly k slots on th...
from itertools import combinations def find_slots(n, k, T, chisels): """ Determine if it's possible to select k chisels such that the sum of their widths equals T. :param n: Number of chisels :param k: Required number of slots :param T: Target width :param chisels: List of chisels' widths :...
from solution import chisels_solution def test_chisels_solution_example(): input_str = "5 3 100\n30 20 25 50 70" output_str = chisels_solution(input_str) assert output_str.startswith("YES") indices = list(map(int, output_str.split('\n')[1].split())) chisels = [30, 20, 25, 50, 70] assert len(ind...
[ { "docstring": "Determine if it's possible to select k chisels such that the sum of their widths equals T.\n:param n: Number of chisels\n:param k: Required number of slots\n:param T: Target width\n:param chisels: List of chisels' widths\n:return: Tuple containing \"YES\" or \"NO\" and the indices of selected ch...
[ 0, 0, 0, 0, 0, 0, 1, 0, 0, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "from itertools import combinations\n\ndef carve_slots(n, k, T, chisels):\n for indices in combinations(range(n), k):\n if sum(chisels[i] for i in in...
trial_gpt4o_6
{ "original_instruction": "", "prompt_id": "00020450", "row_id": 20450, "seed_ids": "[6064, 552, 206]" }
0.569896
Codeforces_20450
I
[ "find_slots", "chisels_solution" ]
2
[ [ "chisels_solution", "find_slots" ] ]
1
[]
false
[]
false
pytest
true
[]
true
bad48307e2772b8f6d196637504ca36c0605e1dd
d11e63efd1dae8bb0a0233402e73566a2edcb462
v1.0
instruct
Codeforces
Codeforces_20478_I
Consider a tree (an acyclic, connected graph) with \( n \) vertices labeled from \( 1 \) to \( n \). You are given the tree as an adjacency list in which each vertex contains a list of its directly connected vertices. Your task is to determine the diameter of the tree. The diameter is defined as the number of edges in ...
from collections import deque def get_farthest_node(start, adjacency_list): """ Perform BFS and return the farthest node and its distance from the start node. """ n = len(adjacency_list) visited = [False] * (n + 1) queue = deque([(start, 0)]) visited[start] = True farthest_node = start ...
def test_tree_diameter(): edges = [ (1, 2), (1, 3), (2, 4), (2, 5), (3, 6) ] assert tree_diameter(6, edges) == 4 def test_small_tree(): edges = [ (1, 2) ] assert tree_diameter(2, edges) == 1 def test_balanced_tree(): edges = [ (1, 2),...
[ { "docstring": "Perform BFS and return the farthest node and its distance from the start node.", "function_declaration": "def get_farthest_node(start, adjacency_list):", "function_name": "get_farthest_node", "parameter_list": "(start, adjacency_list)" }, { "docstring": "Given the number of n...
[ 1, 0, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "from collections import deque\n\ndef get_farthest_node(start, adjacency_list):\n \"\"\"\n Perform BFS and return the farthest node and its distance from...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00020478", "row_id": 20478, "seed_ids": "[508, 7078, 5223]" }
0.721383
Codeforces_20478
I
[ "get_farthest_node", "tree_diameter" ]
2
[ [ "tree_diameter", "get_farthest_node" ] ]
1
[]
false
[]
false
pytest
false
[]
true
09b61a0150807744719e69f0eaa3212deff8572d
a91614be612b5428728ec8e4369ff5f7b8cb7c49
v1.0
instruct
Codeforces
Codeforces_20485_I
You are given a matrix of integers with dimensions n x m. Your task is to rotate the matrix 90 degrees clockwise. The first line of the input contains two integers, n and m (1 ≤ n, m ≤ 100), which represent the number of rows and columns in the matrix, respectively. The next n lines each contain m integers, represent...
def rotate_matrix_90_degrees_clockwise(matrix): """ Rotates the given matrix 90 degrees clockwise. """ n = len(matrix) m = len(matrix[0]) rotated_matrix = [[0]*n for _ in range(m)] for i in range(n): for j in range(m): rotated_matrix[j][n - 1 - i] = matrix[i][j] ...
from solution import rotate_matrix def test_rotate_matrix_3x4(): input_str = "3 4\n1 2 3 4\n5 6 7 8\n9 10 11 12" expected_output = "9 5 1\n10 6 2\n11 7 3\n12 8 4" assert rotate_matrix(input_str) == expected_output def test_rotate_matrix_2x2(): input_str = "2 2\n1 2\n3 4" expected_output = "3 1\n4 ...
[ { "docstring": "Rotates the given matrix 90 degrees clockwise.", "function_declaration": "def rotate_matrix_90_degrees_clockwise(matrix):", "function_name": "rotate_matrix_90_degrees_clockwise", "parameter_list": "(matrix)" }, { "docstring": null, "function_declaration": "def convert_inp...
[ 1, 1 ]
2
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def rotate_matrix_90_degrees_clockwise(matrix):\n \"\"\"\n Rotates the given n x m matrix 90 degrees clockwise.\n \n :param matrix: List[List[int]...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00020485", "row_id": 20485, "seed_ids": "[6709, 3529, 288]" }
0.605546
Codeforces_20485
I
[ "rotate_matrix_90_degrees_clockwise", "convert_input_to_matrix", "convert_matrix_to_output", "rotate_matrix" ]
4
[ [ "rotate_matrix", "convert_input_to_matrix" ], [ "rotate_matrix", "convert_matrix_to_output" ], [ "rotate_matrix", "rotate_matrix_90_degrees_clockwise" ] ]
3
[]
false
[]
false
pytest
true
[]
true
a4494cfa030d399e3733fbe953dbff1f835aac54
96125c1ceb456beb95665fdf7a03af7182e188c9
v1.0
instruct
Codeforces
Codeforces_20529_I
Petya is organizing a hiking event and wants to create a unique hiking path for the participants. The hiking trail is represented as a grid of size `n x m`. Each cell of the grid can be either land or water. The trail can only be built on land, and hikers can move between adjacent cells (left, right, up, down). Petya...
def find_continuous_trail(grid, n, m, k): def is_valid(x, y): return 0 <= x < n and 0 <= y < m and grid[x][y] == '.' and (x, y) not in visited def dfs(x, y): if len(path) == k: return True visited.add((x, y)) path.append((x, y)) for dx, dy in [(-1, 0), (1, 0)...
def test_hiking_trail_easy(): n = 5 m = 5 k = 8 grid_lines = [ ".#...", "...#.", "..##.", ".#..#", "....." ] result = hiking_trail(n, m, k, grid_lines) assert result != -1 assert len(result) == k def test_hiking_trail_no_continuous_path(): n =...
[ { "docstring": null, "function_declaration": "def find_continuous_trail(grid, n, m, k):", "function_name": "find_continuous_trail", "parameter_list": "(grid, n, m, k)" }, { "docstring": null, "function_declaration": "def hiking_trail(n, m, k, grid_lines):", "function_name": "hiking_t...
[ 0, 0, 1 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def find_hiking_trail(n, m, k, grid):\n directions = [(-1, 0), (1, 0), (0, -1), (0, 1)]\n\n def is_valid(x, y):\n return 0 <= x < n and 0 <= y < ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00020529", "row_id": 20529, "seed_ids": "[6094, 8342, 3629]" }
0.667546
Codeforces_20529
I
[ "find_continuous_trail", "hiking_trail" ]
2
[ [ "hiking_trail", "find_continuous_trail" ] ]
1
[]
false
[]
false
pytest
false
[]
true
629d13f3726787d7ce46510d62ee025cedb3c9d9
66e603423f0e4e73717a1877a29bedf283b6b0ea
v1.0
instruct
Codeforces
Codeforces_20555_I
Alex has just started learning about trees and binary tree traversal algorithms. A binary tree is a tree data structure in which each node has at most two children, referred to as the left child and the right child. He is studying pre-order traversal, in which the nodes are recursively visited in this order: visit the ...
class TreeNode: def __init__(self, val=0, left=None, right=None): self.val = val self.left = left self.right = right def build_tree(level_order_values): if not level_order_values or level_order_values[0] == -1: return None iterator = iter(level_order_values) root = ...
from solution import pre_order_from_level_order def test_basic_tree(): level_order = [1, 2, 3, 4, 5, -1, -1, -1, -1, 6, 7] assert pre_order_from_level_order(level_order) == [1, 2, 4, 5, 6, 7, 3] def test_single_node(): level_order = [1] assert pre_order_from_level_order(level_order) == [1] def test_n...
[]
[ 1, 1 ]
2
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "class TreeNode:\n def __init__(self, x):\n self.val = x\n self.left = None\n self.right = None\n\ndef build_tree_level_order(arr):\n ...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00020555", "row_id": 20555, "seed_ids": "[7779, 7172, 5229]" }
0.524684
Codeforces_20555
I
[ "build_tree", "pre_order_traversal", "pre_order_from_level_order" ]
3
[ [ "pre_order_from_level_order", "build_tree" ], [ "pre_order_from_level_order", "pre_order_traversal" ] ]
2
[]
false
[ "TreeNode" ]
true
pytest
true
[]
true
f4099adfd44ed0e9b506857640ceeade7882bfa2
6913d7c9595363a06b4481f494085d8b1d2ccfa0
v1.0
instruct
Codeforces
Codeforces_20691_I
The Code Eaters Software company recently started a project to analyze user data. They have a dataset consisting of n records, each record containing an integer denoting user activity level for a particular day. The company's goal is to identify the longest subsequence of records where any two consecutive activity leve...
def gcd(a, b): """Helper function to compute the greatest common divisor of a and b.""" while b: a, b = b, a % b return a def longest_subsequence_with_common_divisor(n, activity_levels): """Returns the length of the longest subsequence where any two consecutive activity levels have a common div...
def test_gcd_basic(): assert gcd(10, 20) == 10 assert gcd(14, 25) == 1 assert gcd(49, 30) == 1 assert gcd(25, 30) == 5 def test_single_record(): assert longest_subsequence_with_common_divisor(1, [10]) == 1 assert longest_subsequence_with_common_divisor(1, [25]) == 1 def test_example_case(): ...
[ { "docstring": "Helper function to compute the greatest common divisor of a and b.", "function_declaration": "def gcd(a, b):", "function_name": "gcd", "parameter_list": "(a, b)" }, { "docstring": "Returns the length of the longest subsequence where any two consecutive activity levels have a ...
[ 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 gcd(a, b):\n \"\"\"Helper function to compute the greatest common divisor of a and b.\"\"\"\n while b:\n a, b = b, a % b\n return a\n\ndef...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00020691", "row_id": 20691, "seed_ids": "[6542, 346, 3025]" }
0.75467
Codeforces_20691
I
[ "gcd", "longest_subsequence_with_common_divisor" ]
2
[ [ "longest_subsequence_with_common_divisor", "gcd" ] ]
1
[]
false
[]
false
pytest
false
[]
true
8af08f333890341e83a9ce6216a2a37142a38de4
7652e7c8dd6b2e768034ef24ecd9fb75dfa7d0b8
v1.0
instruct
Codeforces
Codeforces_20705_I
You are given an array of integers representing the costs of different items in a shop. You have a certain budget and you want to buy a combination of these items such that the total cost is exactly equal to your budget. You can only buy each item once. Write a function that returns all the distinct combinations of it...
from itertools import combinations def find_combinations(costs, budget): """ Finds all distinct combinations of items that sum up to the given budget. """ costs.sort() result = [] n = len(costs) def backtrack(start, current_combo, current_sum): if current_sum == budget: ...
from solution import get_combinations_string def test_with_example_1(): assert get_combinations_string(4, 7, [2, 3, 6, 7]) == ["7"] def test_with_example_2(): assert get_combinations_string(5, 8, [2, 4, 1, 7, 6]) == ["1 7", "2 6"] def test_no_solution(): assert get_combinations_string(3, 15, [2, 3, 4]) =...
[ { "docstring": "Finds all distinct combinations of items that sum up to the given budget.", "function_declaration": "def find_combinations(costs, budget):", "function_name": "find_combinations", "parameter_list": "(costs, budget)" }, { "docstring": null, "function_declaration": "def get_...
[ 0, 0, 0, 0, 1 ]
1
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "from typing import List\n\ndef find_combinations(items: List[int], budget: int) -> List[List[int]]:\n \"\"\"\n Finds all distinct combinations of items ...
trial_gpt4o_4
{ "original_instruction": "", "prompt_id": "00020705", "row_id": 20705, "seed_ids": "[1868, 8104, 236]" }
0.674233
Codeforces_20705
I
[ "find_combinations", "get_combinations_string" ]
2
[ [ "get_combinations_string", "find_combinations" ] ]
1
[]
false
[]
false
pytest
true
[]
true
374f17ce7e2234e71bc7736e3df3574ed29c19f2
e6d1cffd1f87f04eab6587588d81b6686e42c4dc
v1.0
instruct
Codeforces
Codeforces_20756_I
Daria has a bookshelf with n compartments, and each compartment contains a certain number of books. She likes keeping her bookshelf organized, so she wants to ensure that the number of books in each compartment doesn't exceed a certain threshold k. To achieve this, Daria can perform a sequence of operations. In one op...
def can_redistribute_books(n, k, books): """ Determines if it's possible to redistribute books so that no compartment exceeds the threshold k """ total_books = sum(books) max_possible_books_in_compartment = (total_books + n - 1) // n return max_possible_books_in_compartment <= k def solution():...
def test_can_redistribute_books_yes(): assert can_redistribute_books(5, 5, [3, 8, 6, 2, 4]) == True assert can_redistribute_books(4, 4, [4, 4, 4, 4]) == True assert can_redistribute_books(3, 10, [3, 3, 3]) == True def test_can_redistribute_books_no(): assert can_redistribute_books(3, 2, [3, 1, 5]) == F...
[ { "docstring": "Determines if it's possible to redistribute books so that no compartment exceeds the threshold k", "function_declaration": "def can_redistribute_books(n, k, books):", "function_name": "can_redistribute_books", "parameter_list": "(n, k, books)" }, { "docstring": null, "fun...
[ 1, 0, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def can_redistribute_books(n, k, book_counts):\n \"\"\"\n Determines if it's possible to redistribute the books so that no compartment has more than k b...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00020756", "row_id": 20756, "seed_ids": "[2728, 2773, 476]" }
0.686511
Codeforces_20756
I
[ "can_redistribute_books", "solution" ]
2
[ [ "solution", "can_redistribute_books" ] ]
1
[]
false
[]
false
pytest
false
[]
true
e601638e694a9e23a6fa70fb3825c632c9e69394
a0501bc3fdafd010886c43ead31e51d56a101140
v1.0
instruct
Codeforces
Codeforces_20788_I
You are given a maze represented by an $n \times m$ grid. Some of the cells are blocked and some are open. You start at the top-left corner of the maze and need to reach the bottom-right corner. You can move to an adjacent cell if it's open, in one of the four directions: up, down, left, or right. To complicate things...
from collections import deque def is_valid(x, y, n, m, grid, visited): return 0 <= x < n and 0 <= y < m and grid[x][y] != '#' and visited[x][y] != 1 def bfs(n, m, grid, start, end): directions = [(0, 1), (1, 0), (0, -1), (-1, 0)] queue = deque([(start, 0)]) visited = [[0] * m for _ in range(n)] vi...
def test_simple_no_traps(): n = 3 m = 3 grid = [ [".", ".", "."], [".", "#", "."], [".", ".", "."] ] assert can_reach_and_return(n, m, grid) == "YES" def test_no_possible_path(): n = 3 m = 3 grid = [ [".", ".", "."], ["#", "#", "#"], [".",...
[ { "docstring": null, "function_declaration": "def is_valid(x, y, n, m, grid, visited):", "function_name": "is_valid", "parameter_list": "(x, y, n, m, grid, visited)" }, { "docstring": null, "function_declaration": "def bfs(n, m, grid, start, end):", "function_name": "bfs", "param...
[ 0, 0, 0, 0, 1 ]
1
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "from collections import deque\n\ndef is_within_bounds(x, y, n, m):\n return 0 <= x < n and 0 <= y < m\n\ndef bfs(grid, n, m, start, end):\n directions =...
trial_gpt4o_4
{ "original_instruction": "", "prompt_id": "00020788", "row_id": 20788, "seed_ids": "[3879, 5595, 115]" }
0.711593
Codeforces_20788
I
[ "is_valid", "bfs", "can_reach_and_return", "main" ]
4
[ [ "bfs", "is_valid" ], [ "can_reach_and_return", "bfs" ] ]
2
[]
false
[]
false
pytest
false
[]
true
24fa074dbb8be3ba9551b3d795f413b03ae89d17
6c6c37d7604449f4026100c6437e9bfd9b0e0b74
v1.0
instruct
Codeforces
Codeforces_20871_I
Ingrid loves the game of Array Rotation. Given an array of integers, she is required to perform multiple operations on it. Each operation can be of two types: 1. Rotate the entire array to the right by k positions. 2. Reverse the subarray from index L to R (inclusive). These operations can be performed multiple times ...
def rotate_right(arr, k): n = len(arr) k %= n return arr[-k:] + arr[:-k] def reverse_subarray(arr, L, R): arr[L:R+1] = arr[L:R+1][::-1] def process_operations(arr, operations): for operation in operations: op = operation.split() if op[0] == 'R': k = int(op[1]) ...
def test_rotate_right(): assert rotate_right([1, 2, 3, 4, 5], 2) == [4, 5, 1, 2, 3] assert rotate_right([1, 2, 3], 4) == [3, 1, 2] assert rotate_right([1, 2, 3], 0) == [1, 2, 3] def test_reverse_subarray(): arr = [1, 2, 3, 4, 5] reverse_subarray(arr, 1, 3) assert arr == [1, 4, 3, 2, 5] arr ...
[ { "docstring": null, "function_declaration": "def rotate_right(arr, k):", "function_name": "rotate_right", "parameter_list": "(arr, k)" }, { "docstring": null, "function_declaration": "def reverse_subarray(arr, L, R):", "function_name": "reverse_subarray", "parameter_list": "(arr...
[ 1, 0, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def apply_operations(n, m, array, operations):\n for operation in operations:\n if operation[0] == 'R':\n k = int(operation[1])\n ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00020871", "row_id": 20871, "seed_ids": "[773, 5286, 3894]" }
0.642846
Codeforces_20871
I
[ "rotate_right", "reverse_subarray", "process_operations" ]
3
[ [ "process_operations", "reverse_subarray" ], [ "process_operations", "rotate_right" ] ]
2
[]
false
[]
false
pytest
false
[]
true
87bcc8f214b2db5beb6788311f8ed36917e77f30
b493804b9e80251ae45e420069bfa6de8937df17
v1.0
instruct
Codeforces
Codeforces_20893_I
In a fictional city, there is a unique system of roads connecting several districts. The roads form a tree structure, meaning that there is exactly one path between any two districts. Each road has a certain length. The mayor decided to launch a new public transportation service called "District Connect." People can u...
from collections import defaultdict, deque import sys input = sys.stdin.read sys.setrecursionlimit(200000) def find_LCA_and_minimum_edge(parent, lca_matrix, min_edge_matrix, depth, u, v): if depth[u] < depth[v]: u, v = v, u diff = depth[u] - depth[v] min_edge = float('inf') for i in range(17)...
def test_minimum_transport_fee(): result = minimum_transport_fee( 5, [(1, 2, 3), (1, 3, 2), (3, 4, 4), (3, 5, 1)], [(4, 5), (1, 4), (2, 5)] ) assert result == [1, 2, 1] def test_minimum_transport_fee_single_query(): result = minimum_transport_fee( 5, [(1, 2, 3), ...
[ { "docstring": null, "function_declaration": "def find_LCA_and_minimum_edge(parent, lca_matrix, min_edge_matrix, depth, u, v):", "function_name": "find_LCA_and_minimum_edge", "parameter_list": "(parent, lca_matrix, min_edge_matrix, depth, u, v)" }, { "docstring": null, "function_declarat...
[ 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_lca_and_min_edge(u, v, n, parent, depth, min_edge):\n if depth[u] < depth[v]:\n u, v = v, u\n diff = depth[u] - depth[v]\n min_cost =...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00020893", "row_id": 20893, "seed_ids": "[147, 4355, 933]" }
0.775933
Codeforces_20893
I
[ "find_LCA_and_minimum_edge", "preprocess_lca", "minimum_transport_fee" ]
3
[ [ "minimum_transport_fee", "find_LCA_and_minimum_edge" ], [ "minimum_transport_fee", "preprocess_lca" ] ]
2
[]
false
[]
false
pytest
false
[]
true
5c733e78f438c3ad23cb5d31720edf08ca31e19c
600d4054b3a650f5d288047555436a55216920f4
v1.0
instruct
Codeforces
Codeforces_20933_I
Alice loves playing with numbers. She is given an array of integers, and she can perform the following operation any number of times (including zero): - Pick any two adjacent elements of the array and swap them. Alice wants to know the minimum number of swaps required to sort the array in non-decreasing order. You a...
def count_inversions(arr): """ Counts the number of inversions in the array using a modified merge sort. Args: arr (list): The list of integers to count inversions in. Returns: int: The number of inversions needed to sort the array. """ def merge_count_split_inv(arr, temp_arr, ...
from solution import min_swaps_to_sort def test_min_swaps_to_sort_example_1(): assert min_swaps_to_sort([4, 3, 2, 1]) == 6 def test_min_swaps_to_sort_sorted_array(): assert min_swaps_to_sort([1, 2, 3, 4]) == 0 def test_min_swaps_to_sort_reverse_sorted_array(): assert min_swaps_to_sort([4, 3, 2, 1]) == 6 ...
[ { "docstring": "Counts the number of inversions in the array using a modified merge sort.\n\nArgs:\narr (list): The list of integers to count inversions in.\n\nReturns:\nint: The number of inversions needed to sort the array.", "function_declaration": "def count_inversions(arr):", "function_name": "coun...
[ 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 minimum_swaps_to_sort(arr):\n \"\"\"\n Counts the minimum number of swaps required to sort the array using adjacent swaps only.\n \"\"\"\n # C...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00020933", "row_id": 20933, "seed_ids": "[7935, 2028, 8001]" }
0.710367
Codeforces_20933
I
[ "count_inversions", "min_swaps_to_sort" ]
2
[ [ "min_swaps_to_sort", "count_inversions" ] ]
1
[]
false
[]
false
pytest
true
[]
true
2cd820953270015c53967f0412220d5759a22008
4f61c299aacef9ff62314f36ff15c2f1b05288a1
v1.0
instruct
Codeforces
Codeforces_20980_I
In the fictional country of Algovia, there is a robotics factory that needs your help optimizing the travel routes for their delivery robots. The factory floor is a grid with dimensions n x m. Each cell in the grid can either be empty or contain an obstacle that the robot cannot pass through. The robots can move up, do...
from collections import deque def min_moves(n, m, grid, sx, sy, tx, ty): """ Determines the minimum number of moves required for a robot to travel from the start to the target while avoiding obstacles. Returns -1 if it is impossible for the robot to reach the target. """ # Adjust to zero based ind...
def test_min_moves(): input_str1 = "5 5\n.....\n.###.\n.....\n.###.\n.....\n1 1 5 5" assert read_input_and_find_min_moves(input_str1) == 8 input_str2 = "3 3\n###\n#..\n###\n1 2 3 2" assert read_input_and_find_min_moves(input_str2) == -1 input_str3 = "3 3\n...\n...\n...\n1 1 3 3" assert read_in...
[ { "docstring": "Determines the minimum number of moves required for a robot to travel from the start to the target\nwhile avoiding obstacles. Returns -1 if it is impossible for the robot to reach the target.", "function_declaration": "def min_moves(n, m, grid, sx, sy, tx, ty):", "function_name": "min_mo...
[ 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 min_moves_to_target(n, m, grid, sx, sy, tx, ty):\n \"\"\"\n Returns the minimum number of moves required for a robo...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00020980", "row_id": 20980, "seed_ids": "[1392, 4654, 6520]" }
0.744627
Codeforces_20980
I
[ "min_moves", "read_input_and_find_min_moves" ]
2
[ [ "read_input_and_find_min_moves", "min_moves" ] ]
1
[]
false
[]
false
pytest
false
[]
true
b4d04e8e4cd5003b015268cf922a26601ef93327
177b71ddf5cf5cda905454b84dd427bdb1815c23
v1.0
instruct
Codeforces
Codeforces_21055_I
Samuel enjoys creating unique passwords. He recently read about a method where a password should be considered "valid" if it meets certain criteria based on its length and the type of characters it contains. Samuel decides to follow these rules: 1. The password must be of length n (1 ≤ n ≤ 100). 2. The password must c...
def is_valid_password(password): """ Check if a password is valid based on predefined criteria. """ if len(password) < 1 or len(password) > 100: return "Invalid" has_upper = False has_lower = False has_digit = False for char in password: if char.isupper(): ...
from solution import is_valid_password, validate_passwords def test_is_valid_password(): assert is_valid_password("aB1") == "Valid" assert is_valid_password("abcdefgh") == "Invalid" assert is_valid_password("ABCDEFGH") == "Invalid" assert is_valid_password("12345678") == "Invalid" assert is_valid_p...
[ { "docstring": "Check if a password is valid based on predefined criteria.", "function_declaration": "def is_valid_password(password):", "function_name": "is_valid_password", "parameter_list": "(password)" }, { "docstring": "Given a list of passwords, determine which are valid.", "functi...
[ 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 re\n\ndef is_valid_password(password):\n \"\"\"\n Checks if the given password meets all the criteria:\n 1. The password must be of length 1 t...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00021055", "row_id": 21055, "seed_ids": "[7498, 3330, 6395]" }
0.647861
Codeforces_21055
I
[ "is_valid_password", "validate_passwords" ]
2
[ [ "validate_passwords", "is_valid_password" ] ]
1
[]
false
[]
false
pytest
true
[]
true
974b7254c38117d19272a61a2791aad1fd71e245
3efe5fb39f586145cbc3be7404d790d9f711254b
v1.0
instruct
Codeforces
Codeforces_21058_I
A new online shopping website uses a rating system for product reviews. Customers rate products on a scale of 1 to 5 stars. To make the ratings fairer, the website wants to implement a feature called "Critical Average Rating" (CAR). The CAR of a product is defined as the average rating after removing the highest and lo...
def calculate_car(ratings): """ Calculate the Critical Average Rating (CAR) for a list of ratings. Args: ratings (list): List of integers representing the ratings. Returns: float: The CAR value rounded to two decimal places. """ # Sort the ratings to find the highest and lowest...
from solution import calculate_car, process_products def test_calculate_car_with_various_ratings(): assert calculate_car([1, 2, 3, 4, 5]) == 3.00 assert calculate_car([2, 3, 3, 3, 4, 5]) == 3.25 def test_calculate_car_with_same_ratings(): assert calculate_car([4, 4, 4, 4, 4]) == 4.00 def test_calculate_c...
[ { "docstring": "Calculate the Critical Average Rating (CAR) for a list of ratings.\n\nArgs:\nratings (list): List of integers representing the ratings.\n\nReturns:\nfloat: The CAR value rounded to two decimal places.", "function_declaration": "def calculate_car(ratings):", "function_name": "calculate_ca...
[ 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 calculate_car(ratings):\n \"\"\"\n Calculate the Critical Average Rating (CAR) for a list of ratings.\n \n Args:\n ratings (list): List of ...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00021058", "row_id": 21058, "seed_ids": "[765, 795, 2474]" }
0.606308
Codeforces_21058
I
[ "calculate_car", "process_products" ]
2
[ [ "process_products", "calculate_car" ] ]
1
[]
false
[]
false
pytest
true
[]
true
2bfd5267eb0c0033c5f53b85169a489ca700f10b
15a4a9bee7725545c0fa3af483f28462a9d74f42
v1.0
instruct
Codeforces
Codeforces_21063_I
In a binary tree, each node contains a value, and each node has zero, one, or two children. You need to write a function that finds the lowest common ancestor (LCA) of two given nodes in the tree. The lowest common ancestor is defined between two nodes `p` and `q` as the lowest node in the tree that has both `p` and `q...
class TreeNode: def __init__(self, x): self.val = x self.left = None self.right = None def build_tree(n, links): nodes = {i: TreeNode(i) for i in range(1, n+1)} for parent, child, is_left in links: if is_left: nodes[parent].left = nodes[child] else: ...
from solution import TreeNode, build_tree, find_LCA, get_lca def test_example_case(): n = 6 links = [(1, 2, 1), (1, 3, 0), (2, 4, 1), (2, 5, 0), (3, 6, 0)] p, q = 4, 6 assert get_lca(n, links, p, q) == 1 def test_lca_2_and_3(): n = 6 links = [(1, 2, 1), (1, 3, 0), (2, 4, 1), (2, 5, 0), (3, 6, ...
[]
[ 0, 1, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "class TreeNode:\n def __init__(self, x):\n self.val = x\n self.left = None\n self.right = None\n\ndef build_tree(edges):\n nodes = ...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00021063", "row_id": 21063, "seed_ids": "[6090, 5904, 5760]" }
0.587291
Codeforces_21063
I
[ "build_tree", "find_LCA", "get_lca" ]
3
[ [ "get_lca", "build_tree" ], [ "get_lca", "find_LCA" ] ]
2
[]
false
[ "TreeNode" ]
true
pytest
true
[]
true
1b9df699fae682c3dae5b920f23b4abed0f1243a
18dd9f4172d942bd82c770c3ba4b65bbe49a6403
v1.0
instruct
Codeforces
Codeforces_21082_I
Alice and Bob are playing a game of numbers on a n x m grid. The game begins with two players placing their tokens independently on any cell of the first row. They take turns to move their tokens. On each turn, a player can move their token downwards to any cell in the row directly below, but only if the gcd (greatest ...
from math import gcd from collections import deque def is_winning_path(grid, n, m, start_col): dp = [[False] * m for _ in range(n)] dp[0][start_col] = True queue = deque([(0, start_col)]) while queue: row, col = queue.popleft() if row == n - 1: return True...
from solution import determine_winner def test_case1(): n = 3 m = 3 grid = [ [2, 3, 4], [6, 10, 12], [15, 18, 20] ] s1 = 1 s2 = 3 assert determine_winner(n, m, grid, s1, s2) == "Alice" def test_case2(): n = 3 m = 3 grid = [ [2, 3, 4], [5,...
[ { "docstring": null, "function_declaration": "def is_winning_path(grid, n, m, start_col):", "function_name": "is_winning_path", "parameter_list": "(grid, n, m, start_col)" }, { "docstring": null, "function_declaration": "def determine_winner(n, m, grid, s1, s2):", "function_name": "d...
[ 0, 0, 0, 0, 0, 0, 0, 1, 0, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "import math\nfrom collections import defaultdict\n\ndef gcd(a, b):\n while b:\n a, b = b, a % b\n return a\n\ndef can_win(grid, n, m, s1, s2):\n ...
trial_gpt4o_7
{ "original_instruction": "", "prompt_id": "00021082", "row_id": 21082, "seed_ids": "[4826, 7516, 4881]" }
0.746066
Codeforces_21082
I
[ "is_winning_path", "determine_winner" ]
2
[ [ "determine_winner", "is_winning_path" ] ]
1
[]
false
[]
false
pytest
true
[]
true
9d606f824ac20653a23827bb11718f281e22b4a0
245c846e421296a496de7213db369b8dd7e9dde3
v1.0
instruct
Codeforces
Codeforces_21093_I
Sudoku is a popular number puzzle where the objective is to fill a 9x9 grid with digits from 1 to 9. Each row, each column, and each of the nine 3x3 sub-grids that compose the grid (also called "boxes") must contain all of the digits from 1 to 9, without repetition. Given an incomplete Sudoku board, your task is to d...
def is_valid(board, row, col, num): # Check the row for c in range(9): if board[row][c] == num: return False # Check the column for r in range(9): if board[r][col] == num: return False # Check the 3x3 sub-grid start_row, start_col = 3 * (row // 3), 3 * (co...
def test_is_valid(): board = [ [5, 3, 0, 0, 7, 0, 0, 0, 0], [6, 0, 0, 1, 9, 5, 0, 0, 0], [0, 9, 8, 0, 0, 0, 0, 6, 0], [8, 0, 0, 0, 6, 0, 0, 0, 3], [4, 0, 0, 8, 0, 3, 0, 0, 1], [7, 0, 0, 0, 2, 0, 0, 0, 6], [0, 6, 0, 0, 0, 0, 2, 8, 0], [0, 0, 0, 4, 1, 9,...
[ { "docstring": null, "function_declaration": "def is_valid(board, row, col, num):", "function_name": "is_valid", "parameter_list": "(board, row, col, num)" }, { "docstring": null, "function_declaration": "def solve(board):", "function_name": "solve", "parameter_list": "(board)" ...
[ 0, 0, 1 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_valid(board, row, col, num):\n # Check if num is not in the current row\n if num in board[row]:\n return False\n \n # Check if num i...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00021093", "row_id": 21093, "seed_ids": "[6671, 1357, 6653]" }
0.704491
Codeforces_21093
I
[ "is_valid", "solve", "can_solve_sudoku", "check_sudoku_cases" ]
4
[ [ "can_solve_sudoku", "solve" ], [ "check_sudoku_cases", "can_solve_sudoku" ], [ "solve", "is_valid" ] ]
3
[]
false
[]
false
pytest
false
[]
true
beac25ec33d2ff3e34dc50f83cffd5184a48e8c9
4008b54366b0b5498237dd3f3f1f590016d85806
v1.0
instruct
Codeforces
Codeforces_21141_I
Thom is fascinated by prime numbers and recently stumbled upon an interesting concept: the Sum of Distinct Prime Factors (SDPF) of a number. The SDPF of a number is calculated by summing all its distinct prime factors. For example, the SDPF of 18 is 2 + 3 = 5, because 2 and 3 are the distinct prime factors of 18. Thom...
def sieve_of_eratosthenes(limit): primes = [] is_prime = [True] * (limit + 1) is_prime[0] = is_prime[1] = False for num in range(2, limit + 1): if is_prime[num]: primes.append(num) for multiple in range(num * num, limit + 1, num): is_prime[multiple] =...
def test_sieve_of_eratosthenes(): assert sieve_of_eratosthenes(10) == [2, 3, 5, 7] assert sieve_of_eratosthenes(20) == [2, 3, 5, 7, 11, 13, 17, 19] def test_distinct_prime_factors_sum(): primes = sieve_of_eratosthenes(100) assert distinct_prime_factors_sum(18, primes) == 5 # Factors: 2, 3 assert d...
[ { "docstring": null, "function_declaration": "def sieve_of_eratosthenes(limit):", "function_name": "sieve_of_eratosthenes", "parameter_list": "(limit)" }, { "docstring": null, "function_declaration": "def distinct_prime_factors_sum(number, primes):", "function_name": "distinct_prime_...
[ 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 sympy import primefactors\n\ndef smallest_integer_with_smallest_sdp_fast(n, numbers):\n \"\"\"\n Returns the smallest integer with the smallest Sum...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00021141", "row_id": 21141, "seed_ids": "[10, 4281, 5668]" }
0.589284
Codeforces_21141
I
[ "sieve_of_eratosthenes", "distinct_prime_factors_sum", "smallest_integer_with_smallest_sdpfs" ]
3
[ [ "smallest_integer_with_smallest_sdpfs", "distinct_prime_factors_sum" ], [ "smallest_integer_with_smallest_sdpfs", "sieve_of_eratosthenes" ] ]
2
[]
false
[]
false
pytest
false
[]
true
09010335f0b332bf0e967b9bf38ce1c0cf7f4ef5
75852ba6c7cd576af1a72645c6699e1c21ba5530
v1.0
instruct
Codeforces
Codeforces_21216_I
Mary loves collecting rare stamps. She has a collection of `n` stamps, each uniquely identified by an integer from 1 to `n`. Stamps can be traded through a special stamp trading platform which allows Mary to offer her collection as a package and receive a completely different package of the same size, containing distin...
def can_return_to_initial(n, initial_collection, trade_offers): from collections import deque initial_collection_set = set(initial_collection) # If there is a trade that exactly swaps initial_collection elements for out_trade, in_trade in trade_offers: if set(out_trade) == initial_coll...
from solution import solve def test_case_1(): trades_info = [ (5, [1, 2, 3, 4, 5], [ ([1, 2, 3, 4, 5], [6, 7, 8, 9, 10]), ([6, 7, 8, 9, 10], [1, 2, 3, 4, 5]) ]), (5, [1, 2, 3, 4, 5], [ ([1, 2, 3, 4, 5], [6, 7, 8, 9, 10]), ([6, 7, 8, 9, 10], [1...
[ { "docstring": null, "function_declaration": "def can_return_to_initial(n, initial_collection, trade_offers):", "function_name": "can_return_to_initial", "parameter_list": "(n, initial_collection, trade_offers)" }, { "docstring": null, "function_declaration": "def solve(trades_info):", ...
[ 0, 0, 0, 0, 0, 0, 0, 1, 0, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def can_return_to_initial_collection(t, test_cases):\n results = []\n for test_case in test_cases:\n n, initial_collection, m, trades = test_case...
trial_gpt4o_7
{ "original_instruction": "", "prompt_id": "00021216", "row_id": 21216, "seed_ids": "[1550, 5522, 3021]" }
0.637396
Codeforces_21216
I
[ "can_return_to_initial", "solve" ]
2
[ [ "solve", "can_return_to_initial" ] ]
1
[]
false
[]
false
pytest
true
[]
true
571628d5810100e0aadd7688900f718a10e14696
44f46bbc55584d0e356a545f3dc30e44ebc61ceb
v1.0
instruct
Codeforces
Codeforces_21370_I
The country of Bumblingland is known for its convoluted paths and long journeys. There are $$$n$$$ cities in Bumblingland connected by $$$m$$$ bidirectional roads. Each road has an associated travel time. The citizens of Bumblingland always prefer to use the shortest path between any two cities. Recently, the Bumbling...
import heapq from sys import maxsize def dijkstra(n, graph, start): """ Computes shortest paths from start to all other nodes in a graph using Dijkstra's algorithm. :param n: Number of nodes in the graph. :param graph: Adjacency list of the graph. :param start: The starting node. :return: List ...
def test_find_fastest_travel_times_example(): n = 5 m = 6 edges = [ (1, 2, 3), (2, 3, 4), (3, 4, 5), (4, 5, 6), (1, 5, 15), (2, 5, 7) ] k = 2 car_routes = [ (1, 5), (2, 5) ] expected_output = [10, 7] assert find_fastest_...
[ { "docstring": "Computes shortest paths from start to all other nodes in a graph using Dijkstra's algorithm.\n:param n: Number of nodes in the graph.\n:param graph: Adjacency list of the graph.\n:param start: The starting node.\n:return: List of shortest path distances from start to every other node.", "fun...
[ 1, 0, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "import heapq\nfrom collections import defaultdict\n\ndef dijkstra(graph, start, n):\n \"\"\"\n Function to perform Dijkstra's algorithm for finding the ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00021370", "row_id": 21370, "seed_ids": "[7807, 192, 442]" }
0.756466
Codeforces_21370
I
[ "dijkstra", "find_fastest_travel_times" ]
2
[ [ "find_fastest_travel_times", "dijkstra" ] ]
1
[]
false
[]
false
pytest
true
[]
true
f240f95b06d8d270d7cc60aca1acc9eb21663b8d
9e5dc295bb7b116912d6354b16ff7d1844f181b1
v1.0
instruct
Codeforces
Codeforces_21445_I
Dima enjoys solving problems related to binary matrices. A binary matrix is a matrix where each cell contains either 0 or 1. He came up with an interesting task involving binary matrices and wants to test your skills on it. Given a binary matrix of size $$$n \times m$$$ ($$$1 \le n, m \le 2000$$$), perform the followi...
def flip(matrix, i, j): """ Flip the submatrix with top-left corner at (i, j). """ flip_count = sum(matrix[i][j:j+2] + matrix[i+1][j:j+2]) if flip_count == 3: for x in range(2): for y in range(2): matrix[i + x][j + y] ^= 1 def can_be_uniform(matrix, n, m): ...
from solution import is_uniform_possible def test_example_case(): test_cases = [ (2, 2, ["1100", "0011"]), (3, 4, ["1111", "1001", "1111"]), (3, 3, ["000", "011", "000"]), ] expected = ["YES", "NO", "NO"] assert is_uniform_possible(test_cases) == expected def test_single_row():...
[ { "docstring": "Flip the submatrix with top-left corner at (i, j).", "function_declaration": "def flip(matrix, i, j):", "function_name": "flip", "parameter_list": "(matrix, i, j)" }, { "docstring": "Check if the matrix can be made all 1s or all 0s.", "function_declaration": "def can_be_u...
[ 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 flip(matrix, i, j):\n \"\"\"\n Flip the submatrix with top-left corner at (i, j).\n \"\"\"\n flip_count = sum(matrix[i][j:j+2] + matrix[i+1][j...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00021445", "row_id": 21445, "seed_ids": "[8137, 6982, 8083]" }
0.598911
Codeforces_21445
I
[ "flip", "can_be_uniform", "is_uniform_possible" ]
3
[ [ "can_be_uniform", "flip" ], [ "is_uniform_possible", "can_be_uniform" ] ]
2
[]
false
[]
false
pytest
true
[]
true
43c101ac76d09afbaa2a9f702be970e9b48d8683
b8536b2d23209f9283a09f1e6320252991d0d5de
v1.0
instruct
Codeforces
Codeforces_21456_I
You are given a list of integers. You have to determine if there exists a subset of these integers which sums to a given value. More formally, you are given an integer array $$$a$$$ of length $$$n$$$ and an integer $$$k$$$. Determine if there exists a subset of the array $$$a$$$ such that the sum of its elements is eq...
from itertools import combinations def subset_sum_exists(n, k, arr): """ Returns "YES" if there exists a subset of the array arr with length n that sums to k, otherwise returns "NO" """ for i in range(n + 1): for subset in combinations(arr, i): if sum(subset) == k: ...
from solution import subset_sum_exists def test_subset_sum_exists(): assert subset_sum_exists(6, 9, [3, 34, 4, 12, 5, 2]) == "YES" assert subset_sum_exists(3, 7, [1, 2, 3]) == "NO" assert subset_sum_exists(4, 0, [1, 2, 3, 4]) == "YES" assert subset_sum_exists(5, 5, [1, 2, 5, 3, 7]) == "YES" assert ...
[ { "docstring": "Returns \"YES\" if there exists a subset of the array arr with length n\nthat sums to k, otherwise returns \"NO\"", "function_declaration": "def subset_sum_exists(n, k, arr):", "function_name": "subset_sum_exists", "parameter_list": "(n, k, arr)" }, { "docstring": null, "...
[ 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 subset_sum_exists(n, k, array):\n \"\"\"\n Returns \"YES\" if there exists a subset of array that sums to k, otherwise \"NO\".\n \"\"\"\n # Us...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00021456", "row_id": 21456, "seed_ids": "[2525, 559, 5199]" }
0.690615
Codeforces_21456
I
[ "subset_sum_exists", "process_test_cases", "solve" ]
3
[ [ "process_test_cases", "subset_sum_exists" ], [ "solve", "process_test_cases" ] ]
2
[ "process_test_cases" ]
false
[]
false
pytest
true
[]
true
e96662db988e2560ef82a0fe10bb055b832d27b0
b6fb49f435748331c5a9c6af427ec921f60ffdc1
v1.0
instruct
Codeforces
Codeforces_21487_I
You are writing a program to manage a company's employee hierarchy. Each employee has a unique ID, a manager, and a list of subordinates. The hierarchy is represented as a rooted tree, with the CEO at the root. Given a query about two employees, find the lowest common manager. The lowest common manager of two employees...
from collections import defaultdict, deque def create_hierarchy_tree(n, hierarchy_info): tree = defaultdict(list) parent = [-1] * (n + 1) for u, p in hierarchy_info: if p != -1: tree[p].append(u) parent[u] = p return tree, parent def bfs_depth(tree, n): depth = [-1] * (...
import pytest from solution import lowest_common_manager def test_lowest_common_manager_case1(): n = 6 hierarchy_info = [ (1, -1), (2, 1), (3, 1), (4, 2), (5, 2), (6, 3) ] a, b = 4, 5 assert lowest_common_manager(n, hierarchy_info, a, b) == 2 def...
[ { "docstring": null, "function_declaration": "def create_hierarchy_tree(n, hierarchy_info):", "function_name": "create_hierarchy_tree", "parameter_list": "(n, hierarchy_info)" }, { "docstring": null, "function_declaration": "def bfs_depth(tree, n):", "function_name": "bfs_depth", ...
[ 1, 1 ]
2
easy
1
{ "trial_gpt4o_0": null, "trial_gpt4o_1": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared1_results_combined.jsonl", "solution_code": "class CompanyHierarchy:\n def __init__(self, n):\n self.n = n\n self.manager = [-1] * (n + 1)\n self.depth = ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00021487", "row_id": 21487, "seed_ids": "[4332, 1668, 2924]" }
0.583254
Codeforces_21487
I
[ "create_hierarchy_tree", "bfs_depth", "preprocess_lca", "lca", "lowest_common_manager" ]
5
[ [ "lowest_common_manager", "bfs_depth" ], [ "lowest_common_manager", "create_hierarchy_tree" ], [ "lowest_common_manager", "lca" ], [ "lowest_common_manager", "preprocess_lca" ] ]
4
[]
false
[]
false
pytest
true
[]
true
773fd0f3410ac8ffe822d3d22dff9c285fca6234
2cc63ea7180c73eb8ef8c96bfff2295ec807f2bf
v1.0
instruct
Codeforces
Codeforces_21530_I
I hope you are ready for a challenging task! Here is your question: Alex has detected that some links are causing congestion. To alleviate this, he needs to determine the fewest number of links to remove to make the network operate in an efficient manner where no cycles exist, turning it into a "tree"-like structure...
def find_parent(parent, i): if parent[i] == i: return i else: return find_parent(parent, parent[i]) def union_parent(parent, rank, x, y): rootX = find_parent(parent, x) rootY = find_parent(parent, y) if rootX != rootY: if rank[rootX] > rank[rootY]: parent[ro...
from solution import min_links_to_remove def test_sample_case(): n = 6 m = 6 edges = [(1, 2), (1, 3), (2, 4), (3, 4), (4, 5), (4, 6)] assert min_links_to_remove(n, m, edges) == 1 def test_no_edges(): n = 5 m = 0 edges = [] assert min_links_to_remove(n, m, edges) == 0 def test_no_cycle...
[ { "docstring": null, "function_declaration": "def find_parent(parent, i):", "function_name": "find_parent", "parameter_list": "(parent, i)" }, { "docstring": null, "function_declaration": "def union_parent(parent, rank, x, y):", "function_name": "union_parent", "parameter_list": ...
[ 0, 1, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def min_links_to_remove(n, m, edges):\n \"\"\"\n Returns the fewest number of links to remove to make the network tree-like.\n For a connected graph,...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00021530", "row_id": 21530, "seed_ids": "[5744, 3308, 7509]" }
0.675459
Codeforces_21530
I
[ "find_parent", "union_parent", "min_links_to_remove" ]
3
[ [ "min_links_to_remove", "find_parent" ], [ "min_links_to_remove", "union_parent" ], [ "union_parent", "find_parent" ] ]
3
[]
false
[]
false
pytest
true
[]
true
ba6781b88ffd023af2bf2bf050fc04614953543c
1f8c8476c6642234cc900e0d47411b886320bcdd
v1.0
instruct
Codeforces
Codeforces_21531_I
To further examine students' understanding of programming concepts such as number theory, we present the following problem: Maksim loves playing with numbers. Recently, he has been fascinated by prime numbers and how they multiply together to form what is called the 'Product of Primes'. Help him find the largest prime...
def sieve_of_eratosthenes(n): is_prime = [True] * (n + 1) p = 2 while (p * p <= n): if is_prime[p] == True: for i in range(p * p, n + 1, p): is_prime[i] = False p += 1 prime_numbers = [p for p in range(2, n + 1) if is_prime[p]] return is_prime, prime_numbe...
def test_sieve_of_eratosthenes(): _, primes = sieve_of_eratosthenes(30) assert primes == [2, 3, 5, 7, 11, 13, 17, 19, 23, 29] def test_largest_prime_in_range(): _, primes = sieve_of_eratosthenes(30) assert largest_prime_in_range(10, 20, primes) == 19 assert largest_prime_in_range(25, 30, prime...
[ { "docstring": null, "function_declaration": "def sieve_of_eratosthenes(n):", "function_name": "sieve_of_eratosthenes", "parameter_list": "(n)" }, { "docstring": null, "function_declaration": "def largest_prime_in_range(L, R, primes):", "function_name": "largest_prime_in_range", ...
[ 0, 0, 0, 0, 0, 0, 1, 1, 0, 0 ]
2
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def sieve_of_eratosthenes(max_num):\n \"\"\" Generates a list of booleans determining if numbers are prime \n up to max_num inclusive using Sieve of...
trial_gpt4o_6
{ "original_instruction": "", "prompt_id": "00021531", "row_id": 21531, "seed_ids": "[5262, 235, 480]" }
0.639983
Codeforces_21531
I
[ "sieve_of_eratosthenes", "largest_prime_in_range", "analyze_ranges", "main" ]
4
[ [ "analyze_ranges", "largest_prime_in_range" ], [ "analyze_ranges", "sieve_of_eratosthenes" ] ]
2
[]
false
[]
false
pytest
false
[]
true
412110a37f10b90c4cba0507782ad504eb2f609d
a651091f8f6d5beb0ab8bf9c7efe86b31b5fef42
v1.0
instruct
Codeforces
Codeforces_21565_I
Alice is a delivery agent who delivers packages across a city laid out in a grid. The grid is composed of `n` by `m` cells, and each cell can either be navigable or blocked. Alice starts at the top-left cell `(1, 1)` with coordinates and needs to deliver a package to the bottom-right cell `(n, m)`. She wants to find th...
from collections import deque def min_time_to_deliver_package(num_cases, cases): """ Returns the minimum time required to deliver the package for each test case. :param num_cases: Number of test cases :param cases: List of tuples, each containing grid dimensions and the grid itself :return: List of...
def test_min_time_to_deliver_package(): input_str = """2 5 5 ..... .###. ...#. .#.#. ..... 3 3 #.# .#. #.# """ num_cases, cases = create_test_cases(input_str) results = min_time_to_deliver_package(num_cases, cases) assert results == [8, -1] def test_single_case_possible_path(): input_str = """1 3 3...
[ { "docstring": "Returns the minimum time required to deliver the package for each test case.\n:param num_cases: Number of test cases\n:param cases: List of tuples, each containing grid dimensions and the grid itself\n:return: List of minimum times or -1 if not possible for each test case", "function_declara...
[ 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 min_time_to_deliver_package(num_cases, cases):\n \"\"\"\n Returns the minimum time required to deliver the package ...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00021565", "row_id": 21565, "seed_ids": "[7688, 3163, 2471]" }
0.727889
Codeforces_21565
I
[ "min_time_to_deliver_package", "bfs", "create_test_cases" ]
3
[ [ "min_time_to_deliver_package", "bfs" ] ]
1
[ "create_test_cases" ]
false
[]
false
pytest
false
[]
true
4f395358289312de575b0f1d5d1725386554f537
bb021a5ce428d5ce81025d72fa20d1276c2229c0
v1.0
instruct
Codeforces
Codeforces_21574_I
Given an integer array nums of size n, where n is a positive integer, and a target integer target, you need to determine if there exist three integers a, b, and c in nums such that a + b + c = target. Return true if such triples exist, and false otherwise. The first line contains one integer n (1 ≤ n ≤ 100) — the numb...
def three_sum_exists(nums, target): """ Determines if there exist three integers in nums that sum to target. Args: nums: List of integers. target: The target sum. Returns: Boolean: True if such a triplet exists, False otherwise. """ nums.sort() n = len(nums) fo...
def test_three_sum_exists(): assert check_triplet_exists(4, [1, 2, 3, 4], 6) == "YES" assert check_triplet_exists(3, [-1, 0, 1], 2) == "NO" assert check_triplet_exists(5, [1, 2, 4, 5, -1], 10) == "YES" assert check_triplet_exists(7, [-1, -2, -3, -4, -5, -6, -7], -10) == "YES" assert check_triplet_ex...
[ { "docstring": "Determines if there exist three integers in nums that sum to target.\n\nArgs:\nnums: List of integers.\ntarget: The target sum.\n\nReturns:\nBoolean: True if such a triplet exists, False otherwise.", "function_declaration": "def three_sum_exists(nums, target):", "function_name": "three_s...
[ 0, 0, 0, 0, 0, 1, 1, 0, 0, 0 ]
2
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def three_sum_exists(nums, target):\n nums.sort()\n n = len(nums)\n \n for i in range(n - 2):\n left = i + 1\n right = n - 1\n ...
trial_gpt4o_6
{ "original_instruction": "", "prompt_id": "00021574", "row_id": 21574, "seed_ids": "[1092, 1292, 97]" }
0.727035
Codeforces_21574
I
[ "three_sum_exists", "check_triplet_exists" ]
2
[ [ "check_triplet_exists", "three_sum_exists" ] ]
1
[]
false
[]
false
pytest
false
[]
true
1304992bf467fb3fbf8b993f6eccc59282dc2ab7
dcc5b9057e3d59a48618bf68cb52e47e566517ab
v1.0
instruct
Codeforces
Codeforces_21585_I
Garrett is the owner of a booming online book store. He has a system that records the number of books sold each day, and he wants to identify the days with interesting sales patterns. In particular, Garrett defines an interesting day as one where the number of books sold is a prime number. You are given the sales data...
def is_prime(num): """ Check if a number is prime. """ if num <= 1: return False if num == 2: return True if num % 2 == 0: return False p = 3 while p * p <= num: if num % p == 0: return False p += 2 return True def find_interesting...
from solution import is_prime, find_interesting_days 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_find_interesting_days(): assert find_interesting_days(6, [5, 8, 13, 4, 6...
[ { "docstring": "Check if a number is prime.", "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": "Returns the 1-based indices of days with prime number of books sold.", "function_declaration": "def find_interesting_days(...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(num):\n \"\"\"\n Checks if a number is prime.\n \"\"\"\n if num <= 1:\n return False\n if num <= 3:\n return True\n ...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00021585", "row_id": 21585, "seed_ids": "[4178, 3673, 3428]" }
0.594707
Codeforces_21585
I
[ "is_prime", "find_interesting_days" ]
2
[ [ "find_interesting_days", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
b9a9b04e4d6ab96648401b693814d218620b21bf
5b048d75db20d5d5ca7b56361a92b90feae3efe9
v1.0
instruct
Codeforces
Codeforces_21586_I
You are given an integer matrix of size $$$N \times M$$$ where each entry can be either 0 or 1. A rectangle within this matrix is defined by four integers $$$r1, c1, r2, c2$$$ (1 ≤ r1 ≤ r2 ≤ N and 1 ≤ c1 ≤ c2 ≤ M), which represent the top-left and bottom-right coordinates of the rectangle, respectively. Your task is t...
def largest_rectangle_of_1s(matrix): """ Given a matrix with 0s and 1s, finds the largest rectangle containing only 1s. """ if not matrix or not matrix[0]: return 0 n = len(matrix) m = len(matrix[0]) max_area = 0 heights = [0] * m def largest_histogram_area(heights): ...
from solution import largest_rectangle_area def test_example_case(): matrix = [ [1, 0, 1, 0, 0], [1, 0, 1, 1, 1], [1, 1, 1, 1, 1], [1, 0, 0, 1, 0], ] assert largest_rectangle_area(4, 5, matrix) == 6 def test_single_row(): matrix = [ [1, 1, 1, 1, 1], ] as...
[ { "docstring": "Given a matrix with 0s and 1s, finds the largest rectangle containing only 1s.", "function_declaration": "def largest_rectangle_of_1s(matrix):", "function_name": "largest_rectangle_of_1s", "parameter_list": "(matrix)" }, { "docstring": null, "function_declaration": "def l...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def maximalRectangle(matrix):\n if not matrix:\n return 0\n \n n = len(matrix)\n m = len(matrix[0])\n max_area = 0\n heights = [0] * ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00021586", "row_id": 21586, "seed_ids": "[7651, 2673, 550]" }
0.779535
Codeforces_21586
I
[ "largest_rectangle_of_1s", "largest_rectangle_area" ]
2
[ [ "largest_rectangle_area", "largest_rectangle_of_1s" ] ]
1
[]
false
[]
false
pytest
true
[]
true
dcc0c03c0081559f241360ce40014d4df50a9791
d6e97d2f9d6333ede9aca99b624286ec66efe328
v1.0
instruct
Codeforces
Codeforces_21610_I
Given an array of integers, an inversion is defined as a pair of indices (i, j) such that i < j and a[i] > a[j]. Your task is to count the number of inversions in the array. The first line contains a single integer n (1 ≤ n ≤ 10^5), representing the number of elements in the array. The second line contains n integers ...
def count_inversions(arr): """ Function to count the number of inversions in the array. """ if not arr: return 0 n = len(arr) temp_arr = [0]*n return _merge_sort(arr, temp_arr, 0, n-1) def _merge_sort(arr, temp_arr, left, right): """ Utility function to perform mergesor...
from solution import count_inversions def test_no_inversions(): assert count_inversions([1, 2, 3, 4, 5]) == 0 def test_all_reversed(): assert count_inversions([5, 4, 3, 2, 1]) == 10 def test_some_inversions(): assert count_inversions([2, 3, 8, 6, 1]) == 5 def test_single_element(): assert count_inve...
[ { "docstring": "Function to count the number of inversions in the array.", "function_declaration": "def count_inversions(arr):", "function_name": "count_inversions", "parameter_list": "(arr)" }, { "docstring": "Utility function to perform mergesort and count inversions.", "function_decla...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def count_inversions(arr):\n \"\"\"\n Counts the number of inversions in the array.\n \n Parameters:\n arr (list of int): The input array o...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00021610", "row_id": 21610, "seed_ids": "[5828, 5702, 5172]" }
0.820502
Codeforces_21610
I
[ "count_inversions", "_merge_sort", "_merge" ]
3
[ [ "_merge_sort", "_merge" ], [ "count_inversions", "_merge_sort" ] ]
2
[]
false
[]
false
pytest
true
[]
true
ec7eb4997787187f16845934c10abab043e30df1
c1201de369050a1c3bb9c0272f967d26e1d87a74
v1.0
instruct
Codeforces
Codeforces_21631_I
There is a magical forest that can be represented as an undirected, weighted graph with `n` nodes and `m` edges. Each node represents a magical tree and each edge represents a path that connects two magical trees with a magical energy cost. The forest guardian wants to ensure that each pair of magical trees is in comm...
def find(parent, i): if parent[i] == i: return i else: return find(parent, parent[i]) def union(parent, rank, x, y): root_x = find(parent, x) root_y = find(parent, y) if rank[root_x] < rank[root_y]: parent[root_x] = root_y elif rank[root_x] > rank[root_y]: paren...
def test_minimum_energy(): assert minimum_energy(4, 5, [(1, 2, 1), (1, 3, 2), (1, 4, 3), (2, 3, 4), (3, 4, 5)]) == 6 def test_minimum_energy_single_edge(): assert minimum_energy(2, 1, [(1, 2, 10)]) == 10 def test_minimum_energy_all_equal_weights(): assert minimum_energy(3, 3, [(1, 2, 5), (2, 3, 5), (1...
[ { "docstring": null, "function_declaration": "def find(parent, i):", "function_name": "find", "parameter_list": "(parent, i)" }, { "docstring": null, "function_declaration": "def union(parent, rank, x, y):", "function_name": "union", "parameter_list": "(parent, rank, x, y)" }, ...
[ 0, 0, 0, 0, 0, 0, 1, 1, 0, 0 ]
2
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def find(parent, i):\n if parent[i] == i:\n return i\n return find(parent, parent[i])\n\ndef union(parent, rank, x, y):\n root_x = find(parent...
trial_gpt4o_6
{ "original_instruction": "", "prompt_id": "00021631", "row_id": 21631, "seed_ids": "[4462, 1075, 7916]" }
0.718932
Codeforces_21631
I
[ "find", "union", "kruskal", "minimum_energy" ]
4
[ [ "kruskal", "find" ], [ "kruskal", "union" ], [ "minimum_energy", "kruskal" ], [ "union", "find" ] ]
4
[]
false
[]
false
pytest
false
[]
true
6369dc8e809a99ada63f4e3fcf96a811cf03e9ed
e659cd4e0cd144869ed4e18fd293ed4e99961d93
v1.0
instruct
Codeforces
Codeforces_21666_I
Yak has recently developed a keen interest in prime numbers. He is fascinated by the uniqueness of prime numbers and the fact that they have only two distinct positive divisors: 1 and themselves. One day, Yak came across an interesting problem and needs your help to solve it. Given an integer N, determine if there exi...
from sympy import isprime def find_prime_subset(n): # Use the sum of the first n natural numbers formula total_sum = n * (n + 1) // 2 # Check if the sum is prime if isprime(total_sum): return ("YES", list(range(1, n + 1))) # Try to find subsets by excluding one number for i in...
from solution import prime_subset def test_prime_subset_case_1(): result = prime_subset(5) assert result.startswith("YES") def test_prime_subset_case_2(): result = prime_subset(10) assert result.startswith("YES") def test_prime_subset_small_number(): result = prime_subset(1) assert result == ...
[ { "docstring": null, "function_declaration": "def find_prime_subset(n):", "function_name": "find_prime_subset", "parameter_list": "(n)" }, { "docstring": null, "function_declaration": "def prime_subset(n):", "function_name": "prime_subset", "parameter_list": "(n)" } ]
[ 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": "import math\n\ndef is_prime(num):\n if num <= 1:\n return False\n if num <= 3:\n return True\n if num % 2 == 0 or num % 3 == 0:\n ...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00021666", "row_id": 21666, "seed_ids": "[6771, 3531, 1784]" }
0.613298
Codeforces_21666
I
[ "find_prime_subset", "prime_subset" ]
2
[ [ "prime_subset", "find_prime_subset" ] ]
1
[]
false
[]
false
pytest
true
[ "sympy" ]
false
ee93508567f514463319fe826a173c75564b3e2d
5758141ba23e2c29c15d57c870ce27a1576cbbb7
v1.0
instruct
Codeforces
Codeforces_21776_I
In a galaxy far, far away, there are $$$n$$$ planets connected by $$$m$$$ bidirectional space tunnels. Each tunnel has a certain travel time, and it's possible to reach any planet from any other planet by these tunnels. The Galactic Federation wants to build an emergency travel system that allows for the quickest possi...
import heapq def dijkstra(graph, start, n): dist = [float('inf')] * n dist[start] = 0 pq = [(0, start)] # (distance, node) while pq: d, u = heapq.heappop(pq) if d > dist[u]: continue for v, w in graph[u]: if dist[u] + w < dist[v]: di...
import pytest from solution import find_capital_planet def test_example_case(): n = 4 m = 4 tunnels = [(1, 2, 1), (2, 3, 2), (3, 4, 3), (4, 1, 4)] assert find_capital_planet(n, m, tunnels) == 3 def test_single_tunnel(): n = 2 m = 1 tunnels = [(1, 2, 7)] assert find_capital_planet(n, m,...
[ { "docstring": null, "function_declaration": "def dijkstra(graph, start, n):", "function_name": "dijkstra", "parameter_list": "(graph, start, n)" }, { "docstring": null, "function_declaration": "def find_capital_planet(n, m, tunnels):", "function_name": "find_capital_planet", "pa...
[ 0, 0, 0, 1, 1 ]
2
medium
0.4
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "import heapq\n\ndef minimize_max_travel_time(n, m, tunnels):\n def dijkstra(graph, start):\n distances = {node: float('inf') for node in range(1, n ...
trial_gpt4o_3
{ "original_instruction": "", "prompt_id": "00021776", "row_id": 21776, "seed_ids": "[62, 3072, 3064]" }
0.601464
Codeforces_21776
I
[ "dijkstra", "find_capital_planet" ]
2
[ [ "find_capital_planet", "dijkstra" ] ]
1
[]
false
[]
false
pytest
true
[]
true
d70b07b07e1a81f4bc2d4292e10f779d33f8cebe
551e8daa93d1c9ae59ed0c85274d410bea125e85
v1.0
instruct
Codeforces
Codeforces_21798_I
You are given an undirected, weighted graph with $$$n$$$ vertices and $$$m$$$ edges. The graph may contain loops and multiple edges. Each edge has a non-negative weight associated with it. Alice wants to know the weight of the minimum spanning tree (MST) of the graph for several different configurations. For each que...
def find(parent, i): if parent[i] == i: return i return find(parent, parent[i]) def union(parent, rank, x, y): root_x = find(parent, x) root_y = find(parent, y) if root_x != root_y: if rank[root_x] > rank[root_y]: parent[root_y] = root_x elif rank[root_x] < rank[...
from solution import solve_mst_with_exclusions def test_example(): n = 4 m = 4 q = 1 edges = [(1, 2, 1), (2, 3, 1), (3, 4, 1), (4, 1, 2)] queries = [(1, 2)] assert solve_mst_with_exclusions(n, m, q, edges, queries) == [-1] def test_no_exclusions(): n = 4 m = 5 q = 1 edges =...
[ { "docstring": null, "function_declaration": "def find(parent, i):", "function_name": "find", "parameter_list": "(parent, i)" }, { "docstring": null, "function_declaration": "def union(parent, rank, x, y):", "function_name": "union", "parameter_list": "(parent, rank, x, y)" }, ...
[ 0, 0, 0, 0, 0, 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": "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...
trial_gpt4o_5
{ "original_instruction": "", "prompt_id": "00021798", "row_id": 21798, "seed_ids": "[463, 382, 922]" }
0.763035
Codeforces_21798
I
[ "find", "union", "kruskal", "solve_mst_with_exclusions" ]
4
[ [ "kruskal", "union" ], [ "solve_mst_with_exclusions", "kruskal" ], [ "union", "find" ] ]
3
[]
false
[]
false
pytest
true
[]
true
652b49c0d5d3886d9ff4dd66f185cc63e3b754b2
e75a90bf9c40f822d697946cd6051c78ad36895d
v1.0
instruct
Codeforces
Codeforces_21820_I
Four robots, named Alice, Bob, Charlie, and Dave are placed on a grid of size $$$n \times m$$$. Each robot can move up, down, left, or right, but each robot can move only in the sequence of their turns: Alice first, then Bob, then Charlie, and lastly Dave. Each robot can only place one obstacle in an empty cell during ...
# Let's model the problem as a grid traversal with BFS, alongside checking obstacles. from collections import deque def can_reach(start, destination, grid, n, m): if start == destination: return True queue = deque([start]) visited = set([start]) while queue: x, y = queue.pople...
from solution import robots_sequence def test_case_1(): n, m = 5, 5 robots_info = [(1, 1), (5, 5), (4, 4), (2, 2), (3, 3), (1, 4)] obstacles_info = [(2, 3), (4, 1)] assert robots_sequence(n, m, robots_info, obstacles_info) == "YES" def test_case_no_existing_path(): n, m = 3, 3 robots_info = [(...
[ { "docstring": null, "function_declaration": "def can_reach(start, destination, grid, n, m):", "function_name": "can_reach", "parameter_list": "(start, destination, grid, n, m)" }, { "docstring": null, "function_declaration": "def solver(n, m, robots, obstacles):", "function_name": "...
[ 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 is_valid(x, y, n, m, obstacles):\n return 1 <= x <= n and 1 <= y <= m and (x, y) not in obstacles\n\ndef bfs(start, en...
trial_gpt4o_3
{ "original_instruction": "", "prompt_id": "00021820", "row_id": 21820, "seed_ids": "[5856, 185, 3989]" }
0.732884
Codeforces_21820
I
[ "can_reach", "solver", "robots_sequence" ]
3
[ [ "robots_sequence", "solver" ], [ "solver", "can_reach" ] ]
2
[]
false
[]
false
pytest
true
[]
true
14a777b69325f2601a21a99f6743376dca6aebd1
b9fdf28f18ad8c63100513a113bf21067a415d0c
v1.0
instruct
Codeforces
Codeforces_21822_I
To celebrate her birthday, Alice has planned a treasure hunt for her friends. She has hidden the treasure in one of the rooms in her house. The house can be represented as a grid of size \( n \times m \), with each cell representing a different room. Each room can have one of the three possible statuses: open ('.'), bl...
from collections import deque def is_within_bounds(x, y, n, m): return 0 <= x < n and 0 <= y < m def bfs_to_treasure(grid, n, m): directions = [(-1, 0), (1, 0), (0, -1), (0, 1)] start = (0, 0) if grid[0][0] == '#' or grid[0][0] == 'T': # Start is blocked or start is the treasure return -...
from solution import min_steps_to_treasure def test_example(): n, m, k = 4, 4, 1 grid = [ "....", "...#", "..T.", "#..." ] assert min_steps_to_treasure(n, m, k, grid) == 4 def test_unreachable_treasure(): n, m, k = 4, 4, 1 grid = [ "....", "####"...
[ { "docstring": null, "function_declaration": "def is_within_bounds(x, y, n, m):", "function_name": "is_within_bounds", "parameter_list": "(x, y, n, m)" }, { "docstring": null, "function_declaration": "def bfs_to_treasure(grid, n, m):", "function_name": "bfs_to_treasure", "paramet...
[ 0, 0, 0, 0, 1 ]
1
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "from collections import deque\n\ndef min_steps_to_treasure(n, m, k, grid):\n def in_bounds(x, y):\n return 0 <= x < n and 0 <= y < m\n \n dire...
trial_gpt4o_4
{ "original_instruction": "", "prompt_id": "00021822", "row_id": 21822, "seed_ids": "[5660, 4602, 4112]" }
0.742103
Codeforces_21822
I
[ "is_within_bounds", "bfs_to_treasure", "min_steps_to_treasure" ]
3
[ [ "bfs_to_treasure", "is_within_bounds" ], [ "min_steps_to_treasure", "bfs_to_treasure" ] ]
2
[]
false
[]
false
pytest
true
[]
true
6d859403c76cac80a84bfdce1126621c5e831bdf
fd3c2083ad844923f289ca74cdc11e10c2f67bb1
v1.0
instruct
Codeforces
Codeforces_21838_I
Alice has a collection of strings and wants to find a special kind of subset from this collection. A subset of strings S is considered special if, for any two different strings in the subset, one string is not a substring of the other. You are given n strings. Your task is to find the size of the largest special subs...
def is_special_subset(subset): """ Check if a given subset is special. """ for i in range(len(subset)): for j in range(len(subset)): if i != j and (subset[i] in subset[j] or subset[j] in subset[i]): return False return True def largest_special_subset_size(strings...
from solution import largest_special_subset_size def test_example_case(): assert largest_special_subset_size(["abc", "ab", "bca", "d"]) == 3 def test_single_string(): assert largest_special_subset_size(["a"]) == 1 def test_no_special_subset(): assert largest_special_subset_size(["a", "aa", "aaa"]) == 1 ...
[ { "docstring": "Check if a given subset is special.", "function_declaration": "def is_special_subset(subset):", "function_name": "is_special_subset", "parameter_list": "(subset)" }, { "docstring": "Returns the size of the largest special subset from the given strings.", "function_declara...
[ 1, 0, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_special_subset(subset):\n \"\"\"\n Check if a given subset is special.\n \"\"\"\n for i in range(len(subset)):\n for j in range(len(...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00021838", "row_id": 21838, "seed_ids": "[6563, 6399, 3662]" }
0.698627
Codeforces_21838
I
[ "is_special_subset", "largest_special_subset_size" ]
2
[ [ "largest_special_subset_size", "is_special_subset" ] ]
1
[]
false
[]
false
pytest
true
[]
true
51666ccbc9b2ee9fcf33613763715c56829da359
0bc11a73abcdbe9707fb4d85038b8c24ced0c007
v1.0
instruct
Codeforces
Codeforces_21867_I
You are working on a project that involves processing strings of text. One of the tasks you need to perform is to find the longest palindromic substring within a given string. A palindrome is a word, phrase, or sequence of characters that reads the same backward as forward. Write a function that takes a single string ...
def expand_around_center(s, left, right): while left >= 0 and right < len(s) and s[left] == s[right]: left -= 1 right += 1 return s[left + 1:right] def longest_palindromic_substring(s): if len(s) == 0: return "" longest = s[0] for i in range(len(s)): # Odd ...
from solution import longest_palindromic_substring, process_test_cases def test_single_case(): assert longest_palindromic_substring("babad") in ["bab", "aba"] assert longest_palindromic_substring("cbbd") == "bb" assert longest_palindromic_substring("abcde") == "a" def test_edge_cases(): assert longest...
[ { "docstring": null, "function_declaration": "def expand_around_center(s, left, right):", "function_name": "expand_around_center", "parameter_list": "(s, left, right)" }, { "docstring": null, "function_declaration": "def longest_palindromic_substring(s):", "function_name": "longest_p...
[ 0, 0, 1 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def longest_palindromic_substring(s):\n \"\"\"\n Returns the longest palindromic substring in the given string s.\n \"\"\"\n n = len(s)\n if n ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00021867", "row_id": 21867, "seed_ids": "[4483, 5162, 6659]" }
0.84807
Codeforces_21867
I
[ "expand_around_center", "longest_palindromic_substring", "process_test_cases" ]
3
[ [ "longest_palindromic_substring", "expand_around_center" ], [ "process_test_cases", "longest_palindromic_substring" ] ]
2
[ "process_test_cases" ]
false
[]
false
pytest
true
[]
true
d6b71b8f319469c1bcdae3c87fb8639f3dc87deb
38d8c8f55d741b98a65f7aa864516d795936bb30
v1.0
instruct
Codeforces
Codeforces_21891_I
Calixta is planning her next photo expedition to capture some rare species of birds. She plans to visit each bird habitat only once to minimize the disturbance to the birds. Each habitat is connected by footpaths, and she wants to make sure that she takes the shortest possible route that visits every habitat exactly on...
from itertools import permutations def calculate_tsp(n, distances): # generate all permutations of habitats to be visited (excluding the return to start point) habitats = range(n) min_route_length = float('inf') # iterate through all possible tours for perm in permutations(habitats): c...
from solution import min_tsp_route_length def test_case_1(): n = 4 distance_matrix = [ [0, 10, 15, 20], [10, 0, 35, 25], [15, 35, 0, 30], [20, 25, 30, 0] ] assert min_tsp_route_length(n, distance_matrix) == 80 def test_case_2(): n = 3 distance_matrix = [ ...
[ { "docstring": null, "function_declaration": "def calculate_tsp(n, distances):", "function_name": "calculate_tsp", "parameter_list": "(n, distances)" }, { "docstring": null, "function_declaration": "def min_tsp_route_length(n, distance_matrix):", "function_name": "min_tsp_route_lengt...
[ 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 itertools import permutations\n\ndef calculate_tsp(n, distances):\n # generate all permutations of habitats to be visited (excluding the return to sta...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00021891", "row_id": 21891, "seed_ids": "[1894, 8191, 2313]" }
0.663739
Codeforces_21891
I
[ "calculate_tsp", "min_tsp_route_length" ]
2
[ [ "min_tsp_route_length", "calculate_tsp" ] ]
1
[]
false
[]
false
pytest
true
[]
true
cc9004eb9c620964c9c10cf3df1c78458d1e259d
a5d988f57e4ea81e5215320aea13c3fccb8f5262
v1.0
instruct
Codeforces
Codeforces_21893_I
Anna likes playing with arrays. She has an array of integers and wants to perform a specific operation to make the array more interesting. The operation is defined as follows: 1. Anna can pick any two elements in the array. 2. Suppose these elements are $$$a_i$$$ and $$$a_j$$$ (with $$$i \neq j$$$). 3. Anna can replac...
import math from functools import reduce def gcd(a, b): """ Returns the greatest common divisor of a and b using Euclidean algorithm. """ while b: a, b = b, a % b return a def gcd_of_array(arr): """ Returns the greatest common divisor of all elements in the array arr. """ r...
from solution import max_possible_minimal_element def test_cases(): t = 2 test_cases = [ (3, [6, 9, 15]), (4, [4, 6, 8, 10]) ] assert max_possible_minimal_element(t, test_cases) == [3, 2] def test_single_case(): t = 1 test_cases = [ (5, [9, 27, 30, 18, 12]) ] as...
[ { "docstring": "Returns the greatest common divisor of a and b using Euclidean algorithm.", "function_declaration": "def gcd(a, b):", "function_name": "gcd", "parameter_list": "(a, b)" }, { "docstring": "Returns the greatest common divisor of all elements in the array arr.", "function_de...
[ 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 math\n\ndef max_min_gcd(t, test_cases):\n \"\"\"\n This function computes the maximum possible value of the minimum element \n of the array af...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00021893", "row_id": 21893, "seed_ids": "[5810, 1451, 1883]" }
0.722367
Codeforces_21893
I
[ "gcd", "gcd_of_array", "max_possible_minimal_element" ]
3
[ [ "gcd_of_array", "gcd" ], [ "max_possible_minimal_element", "gcd_of_array" ] ]
2
[]
false
[]
false
pytest
true
[]
true
9459fde3be44aa8f283cfdfdd36d686821f8a693
7850948dd0af60b83982042d02abefb4369161d0
v1.0
instruct
Codeforces
Codeforces_21910_I
You are given an array of integers a1, a2, ..., an. You need to perform q operations on this array. Each operation is of one of the three types: 1. Add a value x to all elements in the range [l, r]. 2. Multiply all elements in the range [l, r] by a value x. 3. Find the sum of elements in the range [l, r]. The array e...
MOD = 1000000007 def execute_operations(n, q, array, operations): """ Executes the given operations on the array and returns the results of type-3 operations. :param n: number of elements in the array :param q: number of operations :param array: list of integers representing the array :param op...
from solution import array_operations def test_add_and_sum_operations(): n, q = 5, 5 array = [1, 2, 3, 4, 5] operations = [ (1, 1, 3, 10), # Add 10 to elements from 1 to 3 -> [11, 12, 13, 4, 5] (2, 2, 5, 2), # Multiply elements from 2 to 5 by 2 -> [11, 24, 26, 8, 10] (3, 1, 5), ...
[ { "docstring": "Executes the given operations on the array and returns the results of type-3 operations.\n:param n: number of elements in the array\n:param q: number of operations\n:param array: list of integers representing the array\n:param operations: list of tuples representing the operations\n:return: list...
[ 0, 0, 0, 0, 0, 1, 0, 0, 0 ]
1
hard
0.111
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "MOD = 1000000007\n\nclass SegmentTree:\n def __init__(self, array):\n self.n = len(array)\n self.tree = [0] * (2 * self.n)\n self.lazy...
trial_gpt4o_6
{ "original_instruction": "", "prompt_id": "00021910", "row_id": 21910, "seed_ids": "[5510, 4495, 2855]" }
0.639148
Codeforces_21910
I
[ "execute_operations", "array_operations" ]
2
[ [ "array_operations", "execute_operations" ] ]
1
[]
false
[]
false
pytest
true
[]
true
9abd33c7206f2f9934534be02b038ff73cf56bf4
81026a1de886b83aa2698698a20c21be3f7cb30b
v1.0
instruct
Codeforces
Codeforces_21913_I
Alexis has recently discovered a strange kind of number which she calls "prime factors squared" numbers. A number is considered a "prime factors squared" number if it can be expressed as the product of distinct primes squared. For example: - 36 = 2^2 * 3^2 - 49 = 7^2 - 100 = 2^2 * 5^2 Given an integer `m`, Alexi...
def is_prime(n): """ Helper function to check if 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...
# To invoke the function from the solution code from solution import prime_factors_squared def test_prime_factors_squared_example1(): assert prime_factors_squared(49) == [7] def test_prime_factors_squared_example2(): assert prime_factors_squared(20) == -1 def test_prime_factors_squared_single_prime_squared()...
[ { "docstring": "Helper function to check if n is a prime number.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Returns the prime factors of m if m can be expressed as a product of distinct primes squared.\nOtherwise, ret...
[ 0, 1, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "import math\n\ndef is_prime(n):\n if n <= 1:\n return False\n if n <= 3:\n return True\n if n % 2 == 0 or n % 3 == 0:\n return F...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00021913", "row_id": 21913, "seed_ids": "[4480, 4338, 5191]" }
0.6213
Codeforces_21913
I
[ "is_prime", "prime_factors_squared" ]
2
[ [ "prime_factors_squared", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
9b66e92e84259fa6d4ecfdad4f8f9405f3badee4
aac067839872ea966fb6268436c691002300295d