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
Taco
Taco_98274_I
Alice is participating in a coding competition and encounters a grid-based puzzle. The puzzle consists of a rectangular grid of cells with R rows and C columns. Initially, the grid contains only zeros (0). Alice is required to fill the grid with integers according to the following rules: 1. Every integer in row i (1 ≤...
def solve_grid_puzzle(T, test_cases): results = [] for R, C in test_cases: if R > 100 or C > 100: results.append("Impossible") continue grid = [[0] * C for _ in range(R)] if R == 1 and C == 1: grid[0][0] = 1 else: num = 1 ...
from solution import solve_grid_puzzle, format_results def test_single_cell(): T = 1 test_cases = [(1, 1)] results = solve_grid_puzzle(T, test_cases) assert results == [[[1]]] def test_3x3_grid(): T = 1 test_cases = [(3, 3)] results = solve_grid_puzzle(T, test_cases) assert results == ...
[ { "docstring": null, "function_declaration": "def solve_grid_puzzle(T, test_cases):", "function_name": "solve_grid_puzzle", "parameter_list": "(T, test_cases)" }, { "docstring": null, "function_declaration": "def format_results(results):", "function_name": "format_results", "para...
[ 1, 1, 0 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl", "solution_code": "def solve_grid_puzzle(T, test_cases):\n results = []\n for R, C in test_cases:\n if R > 100 or C > 100:\n results.append(\"Impossible\")\n ...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00098274", "row_id": 98274, "seed_ids": "[23203]" }
0.767317
Taco_98274
I
[ "solve_grid_puzzle", "format_results", "grid_puzzle_main" ]
3
[ [ "grid_puzzle_main", "format_results" ], [ "grid_puzzle_main", "solve_grid_puzzle" ] ]
2
[ "format_results" ]
false
[]
false
pytest
true
[]
true
87a8f627599fb660028c360b384f564ae3c93dde
377ade29bc9d3aa8b556e6d588940e09cdbd1e97
v1.0
instruct
Taco
Taco_98293_I
You are given a string of words separated by spaces. Each word in the string is encoded by shifting each letter by a fixed number of positions in the alphabet. This fixed number is different for each word in the string. Your task is to decode the message by determining the correct shift value for each word. You realiz...
from collections import Counter # Assuming a pre-defined set of valid English words ENGLISH_WORDS = set([ 'the', 'quick', 'brown', 'fox', 'jumps', 'over', 'lazy', 'dog', 'hello', 'world', 'this', 'is', 'an', 'example' # A comprehensive list would include all English words ]) def shift_char(c, shift): ...
from solution import decode_message def test_decode_message_example(): encoded_message = "ymj vznhp gwtbs ktc ozrux tajw ymj qfed itl" expected_decoded_message = "the quick brown fox jumps over the lazy dog" assert decode_message(encoded_message) == expected_decoded_message def test_decode_message_hello_w...
[ { "docstring": "Shift a character by given shift", "function_declaration": "def shift_char(c, shift):", "function_name": "shift_char", "parameter_list": "(c, shift)" }, { "docstring": null, "function_declaration": "def is_valid_word(word):", "function_name": "is_valid_word", "par...
[ 0, 1, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl", "solution_code": "def decode_word(encoded_word: str, shift: int) -> str:\n \"\"\"\n Decodes a single word by shifting its letters backward by the given shift amount.\n \"\"...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00098293", "row_id": 98293, "seed_ids": "[19502]" }
0.748727
Taco_98293
I
[ "shift_char", "is_valid_word", "decode_word", "decode_message" ]
4
[ [ "decode_message", "decode_word" ], [ "decode_word", "is_valid_word" ], [ "decode_word", "shift_char" ] ]
3
[]
false
[]
false
pytest
true
[]
true
a7da35461b364fe6baa1a8a4c8b6c2e6383051eb
4de11d6303eb57bc161d813b7ca5cc69fc21cf55
v1.0
instruct
Taco
Taco_98335_I
Mary is at position 0 on an infinite road with two types of jumps: a long jump, which covers `L` meters, and a short jump, which covers `S` meters. Mary wants to reach exactly position `D` using a sequence of these jumps. Determine if Mary can reach exactly position `D` using a combination of the long and short jumps...
def gcd(a, b): while b: a, b = b, a % b return a def can_reach(L, S, D): # Find the greatest common divisor (GCD) of L and S g = gcd(L, S) # Check if D is divisible by the GCD of L and S return D % g == 0 def mary_jumps(T, test_cases): results = [] for L, S, D in test_cases: ...
from solution import mary_jumps def test_can_reach_cases(): T = 3 test_cases = [ (3, 5, 13), (4, 6, 11), (7, 2, 14) ] assert mary_jumps(T, test_cases) == ["YES", "NO", "YES"] def test_gcd_function(): from solution import gcd assert gcd(12, 15) == 3 assert gcd(10...
[ { "docstring": null, "function_declaration": "def gcd(a, b):", "function_name": "gcd", "parameter_list": "(a, b)" }, { "docstring": null, "function_declaration": "def can_reach(L, S, D):", "function_name": "can_reach", "parameter_list": "(L, S, D)" }, { "docstring": null,...
[ 0, 0, 0, 0, 0, 0, 0, 0, 1, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl", "solution_code": "def can_reach_position(L, S, D):\n from math import gcd\n \n # The solution is possible if and only if D is a multiple of the greatest common divisor of L...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00098335", "row_id": 98335, "seed_ids": "[8403]" }
0.643089
Taco_98335
I
[ "gcd", "can_reach", "mary_jumps" ]
3
[ [ "can_reach", "gcd" ], [ "mary_jumps", "can_reach" ] ]
2
[]
false
[]
false
pytest
true
[]
true
950d37463f05ff09953191877d360e6bd61dc3ee
dc6753936504423fd913b9e48f3a85cdad8677c7
v1.0
instruct
Taco
Taco_98342_I
------ Input ------ Ali loves experimenting with numerical series. One day, he came across a problem and found it interesting. He has an array of $N$ integers and wants to create a new series of products. Each item in the new series is the product of all the numbers in the original array except for the one at the curr...
def product_except_self(nums): """ Returns a list such that each element at index i is the product of all numbers in nums except nums[i]. """ length = len(nums) left_products = [1] * length right_products = [1] * length result = [1] * length for i in range(1, length): l...
def test_product_except_self(): assert product_except_self([1, 2, 3]) == [6, 3, 2] assert product_except_self([4, 5, 6, 7]) == [210, 168, 140, 120] assert product_except_self([1, 1, 1, 1]) == [1, 1, 1, 1] assert product_except_self([-1, 1, 0, -3, 3]) == [0, 0, 9, 0, 0] assert product_except_self([2,...
[ { "docstring": "Returns a list such that each element at index i is the product of all numbers in nums except nums[i].", "function_declaration": "def product_except_self(nums):", "function_name": "product_except_self", "parameter_list": "(nums)" }, { "docstring": null, "function_declarat...
[ 1, 0, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl", "solution_code": "def product_except_self(arr):\n \"\"\"\n Given an array of integers, returns a new array such that each element at index `i` \n is the product of all the ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00098342", "row_id": 98342, "seed_ids": "[10600]" }
0.684107
Taco_98342
I
[ "product_except_self", "solve", "parse_input", "format_output", "main" ]
5
[ [ "solve", "product_except_self" ] ]
1
[ "parse_input", "format_output" ]
false
[]
false
pytest
false
[]
true
087e2a03348e44288ca5fadc2da08e8750837e59
bb42306c92b9d15a5f2aa5d1dd82767a492f017f
v1.0
instruct
Taco
Taco_98343_I
You are given a rectangular matrix of dimensions N x M. Each cell of the matrix contains an integer. There are Q queries, each query gives the coordinates of the top-left and bottom-right corners of a subrectangle. For each query, you need to calculate the sum of all the elements contained within the subrectangle. ---...
def preprocess_matrix(matrix, N, M): """ Preprocess the matrix to create a prefix sum matrix. """ prefix_sum = [[0] * (M + 1) for _ in range(N + 1)] for i in range(1, N + 1): for j in range(1, M + 1): prefix_sum[i][j] = ( matrix[i-1][j-1] + pr...
from solution import preprocess_matrix, subrectangle_sum, matrix_query def test_preprocess_matrix(): matrix = [ [1, 2, 3], [4, 5, 6], [7, 8, 9] ] N, M = 3, 3 prefix_sum = preprocess_matrix(matrix, N, M) expected_prefix_sum = [ [0, 0, 0, 0], [0, 1, 3, 6], ...
[ { "docstring": "Preprocess the matrix to create a prefix sum matrix.", "function_declaration": "def preprocess_matrix(matrix, N, M):", "function_name": "preprocess_matrix", "parameter_list": "(matrix, N, M)" }, { "docstring": "Calculate the sum of elements in a subrectangle using the prefix ...
[ 1, 1, 0 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl", "solution_code": "def precompute_prefix_sum(matrix, N, M):\n \"\"\"\n Computes the prefix sum matrix for the given matrix.\n \"\"\"\n prefix_sum = [[0] * (M + 1) for _ i...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00098343", "row_id": 98343, "seed_ids": "[15507]" }
0.644255
Taco_98343
I
[ "preprocess_matrix", "subrectangle_sum", "matrix_query" ]
3
[ [ "matrix_query", "preprocess_matrix" ], [ "matrix_query", "subrectangle_sum" ] ]
2
[]
false
[]
false
pytest
true
[]
true
98775415b9f7b4bc57f867d90bab5cd502598721
b6672ebb14c333e87b69d44581ab9d32ccdae5d3
v1.0
instruct
Taco
Taco_98361_I
Given a grid of size MxN consisting of '.' (walkable cell) and '#' (non-walkable cell), find the number of unique paths from the top-left corner to the bottom-right corner. You can only move down or right at any point in time. You must ensure that paths do not pass through cells marked as '#'. Each cell can be visite...
def num_ways(grid): M = len(grid) N = len(grid[0]) if grid[0][0] == '#' or grid[M-1][N-1] == '#': return 0 dp = [[0] * N for _ in range(M)] dp[0][0] = 1 for i in range(M): for j in range(N): if grid[i][j] == '#': dp[i][j] = 0 ...
from solution import unique_paths def test_case_1(): m, n = 3, 3 grid = [ "...", ".#.", "..." ] assert unique_paths(m, n, grid) == 2 def test_case_2(): m, n = 2, 2 grid = [ "..", ".." ] assert unique_paths(m, n, grid) == 2 def test_case_3(): ...
[ { "docstring": null, "function_declaration": "def num_ways(grid):", "function_name": "num_ways", "parameter_list": "(grid)" }, { "docstring": null, "function_declaration": "def unique_paths(m, n, grid):", "function_name": "unique_paths", "parameter_list": "(m, n, grid)" } ]
[ 1, 0, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl", "solution_code": "def unique_paths_in_grid(grid):\n \"\"\"\n Returns the number of unique paths from the top-left corner to the bottom-right corner\n in a grid marked with ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00098361", "row_id": 98361, "seed_ids": "[21160]" }
0.774531
Taco_98361
I
[ "num_ways", "unique_paths" ]
2
[ [ "unique_paths", "num_ways" ] ]
1
[]
false
[]
false
pytest
true
[]
true
05d2c7994c6fc9e1697b0b82b6a420a55c1ac8e3
28431b6b960074fabe4d46bca0530aa91eb61151
v1.0
instruct
Taco
Taco_98423_I
Problem King Arthur is organizing his yearly round table meeting with the $ N $ knights, each represented by a point in a 2D plane. The knights need to be divided into $ K $ distinct groups for discussion, and each group should have at least one knight. Arthur wants to position a round table at the optimal point so t...
def k_means(knights, K): import numpy as np from scipy.spatial import distance def initialize_centroids(knights, K): np.random.seed(42) initial_indices = np.random.choice(len(knights), K, replace=False) return knights[initial_indices] def assign_knights_to_centroids(knights, ce...
from solution import find_optimal_tables def test_example_1(): knight_coordinates = [(1, 3), (2, 2), (3, 1), (8, 8), (9, 9), (10, 10)] N = 6 K = 2 tables = find_optimal_tables(N, K, knight_coordinates) assert round(tables[0][0]) == 2 assert round(tables[0][1]) == 2 assert round(tables[1][0]...
[ { "docstring": null, "function_declaration": "def k_means(knights, K):", "function_name": "k_means", "parameter_list": "(knights, K)" }, { "docstring": null, "function_declaration": "def find_optimal_tables(N, K, knight_coordinates):", "function_name": "find_optimal_tables", "par...
[ 0, 0, 0, 1 ]
1
hard
0.25
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl", "solution_code": "from sklearn.cluster import KMeans\nimport numpy as np\n\ndef get_optimal_table_positions(N, K, coordinates):\n \"\"\"\n Returns the optimal positions of K t...
trial_gpt4o_4
{ "original_instruction": "", "prompt_id": "00098423", "row_id": 98423, "seed_ids": "[4619]" }
0.553788
Taco_98423
I
[ "k_means", "find_optimal_tables", "main" ]
3
[ [ "find_optimal_tables", "k_means" ] ]
1
[]
false
[]
false
pytest
true
[ "numpy", "scipy" ]
false
89b0c5db0e1acec8e03e5768150a4230737fbe2d
3d07a5bc11f4a228524011254f95dff377981a7f
v1.0
instruct
Taco
Taco_98426_I
You are given a list of non-negative integers, with each integer representing the height of a vertical line on a graph. Your task is to write a program that finds two lines that, together with the x-axis, form a container such that the container holds the most amount of water. Return the maximum amount of water a conta...
def max_area(heights): """ Return the maximum area of water that can be contained by two vertical lines. """ left, right = 0, len(heights) - 1 max_area = 0 while left < right: height = min(heights[left], heights[right]) width = right - left current_area = height * wi...
from solution import max_area, find_max_areas, parse_input def test_max_area(): assert max_area([1, 8, 6, 2, 5, 4, 8, 3, 7]) == 49 assert max_area([1, 1, 1, 1]) == 3 assert max_area([5, 2, 6]) == 10 def test_find_max_areas(): datasets = [ [1, 8, 6, 2, 5, 4, 8, 3, 7], [1, 1, 1, 1], ...
[ { "docstring": "Return the maximum area of water that can be contained by two vertical lines.", "function_declaration": "def max_area(heights):", "function_name": "max_area", "parameter_list": "(heights)" }, { "docstring": "For each dataset, find the max area of water the container can store...
[ 0, 0, 1 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl", "solution_code": "def max_water_container(heights):\n \"\"\"\n This function returns the maximum amount of water that can be stored between two lines represented by the height...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00098426", "row_id": 98426, "seed_ids": "[11820]" }
0.614897
Taco_98426
I
[ "max_area", "find_max_areas", "parse_input" ]
3
[ [ "find_max_areas", "max_area" ] ]
1
[ "parse_input" ]
false
[]
false
pytest
true
[]
true
6da19ba2e92ae150feda641c281b6e0968e45a56
17c841220c4638432c16c23cc573bd08f2d019b3
v1.0
instruct
Taco
Taco_98442_I
Sam is working on a project where he needs to manipulate arrays frequently. One of the tasks requires him to rotate an array. Given an array of integers and a number k, rotate the array to the right by k steps. ### Rotation Description To rotate the array to the right by k steps means to move every element of the arr...
def rotate_array(arr, k): """ Rotates the array to the right by k steps. Parameters: arr (list): List of integers to rotate. k (int): Number of steps to rotate the array. Returns: list: The rotated array. """ n = len(arr) # In case k is greater than n k = k % n ...
from solution import rotate_array def test_rotate_array_example1(): assert rotate_array([1, 2, 3, 4, 5, 6], 2) == [5, 6, 1, 2, 3, 4] def test_rotate_array_example2(): assert rotate_array([-1, -100, 3, 99, 0], 3) == [3, 99, 0, -1, -100] def test_rotate_array_k_greater_than_n(): assert rotate_array([1, 2, ...
[ { "docstring": "Rotates the array to the right by k steps.\n\nParameters:\narr (list): List of integers to rotate.\nk (int): Number of steps to rotate the array.\n\nReturns:\nlist: The rotated array.", "function_declaration": "def rotate_array(arr, k):", "function_name": "rotate_array", "parameter_l...
[ 1, 0, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl", "solution_code": "def rotate_array(arr, k):\n \"\"\"\n Rotates the array to the right by k steps.\n \n Parameters:\n arr (list): List of integers to rotate.\n k (i...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00098442", "row_id": 98442, "seed_ids": "[4327]" }
0.681597
Taco_98442
I
[ "rotate_array", "reverse" ]
2
[ [ "rotate_array", "reverse" ] ]
1
[]
false
[]
false
pytest
true
[]
true
e0e33f9fba48e3ea577eb367826ba12a79de45fb
7c871772bf8ae9350373720c2f5e07984c0b009a
v1.0
instruct
Taco
Taco_98453_I
Minimize Path Sum in Triangle Problem You are given a triangle of integers where the first row has one element, the second row has two elements, and so on. Your task is to find the minimum path sum from the top to the bottom row, where each movement can go to either the adjacent number on the row directly below. The...
def minimize_path_sum(triangle): """ Returns the minimum path sum from top to bottom in a given triangle. :param triangle: List of lists of integers representing the triangle :return: Integer representing the minimum path sum """ # Start from the second last row and propagate the minimum pa...
from solution import minimize_path_sum_from_input def test_minimize_path_sum1(): n = 4 triangle_list = [2, 3, 4, 6, 5, 7, 4, 1, 8, 3] assert minimize_path_sum_from_input(n, triangle_list) == 11 def test_minimize_path_sum2(): n = 3 triangle_list = [1, 2, 3, 4, 5, 6] assert minimize_path_sum_fro...
[ { "docstring": "Returns the minimum path sum from top to bottom in a given triangle.\n\n:param triangle: List of lists of integers representing the triangle\n:return: Integer representing the minimum path sum", "function_declaration": "def minimize_path_sum(triangle):", "function_name": "minimize_path_s...
[ 1, 0, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl", "solution_code": "def minimize_path_sum(triangle):\n \"\"\"\n Returns the minimum path sum from top to bottom in a given triangle.\n \n :param triangle: List of lists of...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00098453", "row_id": 98453, "seed_ids": "[23965]" }
0.632266
Taco_98453
I
[ "minimize_path_sum", "minimize_path_sum_from_input" ]
2
[ [ "minimize_path_sum_from_input", "minimize_path_sum" ] ]
1
[]
false
[]
false
pytest
true
[]
true
23654d8cfdcf305a81dc5d499140f3287cb15359
2e5ecffd399f40d062be86bc2578c2b831a004e5
v1.0
instruct
Taco
Taco_98508_I
A programming competition requires participants to write a function that calculates the factorial of a given non-negative integer n. However, instead of calculating the result directly, participants must implement a memoization technique to store intermediate results for efficiency. Memoization is a technique used to ...
def memoized_factorial(): """ Returns a function to compute the factorial using memoization. """ memo = {} def factorial(n): if n in memo: return memo[n] if n <= 1: memo[n] = 1 else: memo[n] = n * factorial(n-1) return memo[n] ...
from solution import solve_factorial def test_sample_input(): test_cases = [0, 1, 5, 10] expected = [1, 1, 120, 3628800] assert solve_factorial(test_cases) == expected def test_zero_and_one(): test_cases = [0, 1] expected = [1, 1] assert solve_factorial(test_cases) == expected def test_small_...
[ { "docstring": "Returns a function to compute the factorial using memoization.", "function_declaration": "def memoized_factorial():", "function_name": "memoized_factorial", "parameter_list": "()" }, { "docstring": null, "function_declaration": "def solve_factorial(test_cases):", "fun...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl", "solution_code": "def memoized_factorial():\n \"\"\"\n Returns a memoized factorial function that caches intermediate results for efficiency.\n \"\"\"\n cache = {}\n ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00098508", "row_id": 98508, "seed_ids": "[15997]" }
0.622469
Taco_98508
I
[ "memoized_factorial", "solve_factorial" ]
2
[ [ "solve_factorial", "memoized_factorial" ] ]
1
[]
false
[]
false
pytest
true
[]
true
1aadc715b346ac76e45cd28a094f0b6bde1fded2
081e731908e411d957f4850ea458e6afae26e231
v1.0
instruct
Taco
Taco_98513_I
You are working on a text-based game involving a series of quests. Each quest has specified prerequisites that need to be completed before it can be started. Given a list of quests and their prerequisites, you need to determine the order in which the quests can be completed, if such an order is possible. -----Input---...
from collections import defaultdict, deque def find_quest_order(n, prerequisites): # Dictionary to store the prerequisites prereq_map = defaultdict(list) # Dictionary to maintain the in-degree of nodes in_degree = defaultdict(int) all_quests = set() for x, y in prerequisites: prere...
from solution import find_quest_order def test_possible_order(): n = 4 prerequisites = [ ("clean_house", "cook_meal"), ("buy_groceries", "cook_meal"), ("buy_groceries", "clean_house"), ("cook_meal", "play_game") ] result = find_quest_order(n, prerequisites) expected ...
[ { "docstring": null, "function_declaration": "def find_quest_order(n, prerequisites):", "function_name": "find_quest_order", "parameter_list": "(n, prerequisites)" }, { "docstring": null, "function_declaration": "def solve():", "function_name": "solve", "parameter_list": "()" }...
[ 0, 0, 0, 1, 1 ]
2
medium
0.4
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl", "solution_code": "from collections import defaultdict, deque\n\ndef find_quest_order(n, quest_prerequisites):\n graph = defaultdict(list)\n in_degree = defaultdict(int)\n \...
trial_gpt4o_4
{ "original_instruction": "", "prompt_id": "00098513", "row_id": 98513, "seed_ids": "[11663]" }
0.652441
Taco_98513
I
[ "find_quest_order", "solve" ]
2
[ [ "solve", "find_quest_order" ] ]
1
[]
false
[]
false
pytest
true
[]
true
c256050de5bb1ae731c5d60d10b9bc6db2446214
c5e669ca782cc0a3acd7ea53dcd9e1ac65ca1809
v1.0
instruct
Taco
Taco_98560_I
A well-known game requires players to form words from a given set of characters. Each character may be used only once per word, and the length of the word must be at least 1. The scoring mechanism of the game provides points based on the length of the word formed: a word of length `l` earns `l * l` points. Given a list...
def get_word_score(word): """ Return the score of the word based on its length. Score is calculated as the square of the word's length. """ return len(word) ** 2 def can_form_word(word, chars): """ Check if 'word' can be formed from the characters in 'chars'. """ from collections im...
import pytest from solution import can_form_word, get_word_score, max_score, process_input def test_get_word_score(): assert get_word_score("a") == 1 assert get_word_score("apple") == 25 assert get_word_score("banana") == 36 def test_can_form_word(): assert not can_form_word("apple", "appl") asser...
[ { "docstring": "Return the score of the word based on its length.\nScore is calculated as the square of the word's length.", "function_declaration": "def get_word_score(word):", "function_name": "get_word_score", "parameter_list": "(word)" }, { "docstring": "Check if 'word' can be formed fro...
[ 0, 0, 1 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl", "solution_code": "from collections import Counter\n\ndef max_score(words, chars):\n \"\"\"\n This function computes the maximum score that can be achieved by forming words fro...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00098560", "row_id": 98560, "seed_ids": "[1122]" }
0.708355
Taco_98560
I
[ "get_word_score", "can_form_word", "max_score", "process_input" ]
4
[ [ "max_score", "can_form_word" ], [ "max_score", "get_word_score" ], [ "process_input", "max_score" ] ]
3
[ "process_input" ]
false
[]
false
pytest
true
[]
true
bd697beeaeefe0dae531bcc1c1e40e5348176ff8
b7f4f2420b6ac5997c0dca106c8715dfa89dc46c
v1.0
instruct
Taco
Taco_98600_I
A: Trip Route Planning problem You are given a list of trip stops represented by their respective coordinates on a 2D plane. Each stop has an (x, y) coordinate. Your task is to find the shortest route that visits all the trip stops exactly once and returns to the starting point. Input format n x_1 y_1 x_2 y_2 ... x...
import itertools import math def calculate_distance(p1, p2): """ Calculates the Euclidean distance between two points p1 and p2. """ return math.sqrt((p1[0] - p2[0]) ** 2 + (p1[1] - p2[1]) ** 2) def shortest_route_distance(stops): """ Finds the shortest route that visits all trip stops exactly...
from solution import shortest_route_distance def test_shortest_route_distance_example1(): stops = [(0, 0), (1, 0), (1, 1), (0, 1)] assert shortest_route_distance(stops) == 4.0000 def test_shortest_route_distance_example2(): stops = [(-1, 2), (2, 2), (2, 3), (-1, 3), (0, 0)] assert shortest_route_dista...
[ { "docstring": "Calculates the Euclidean distance between two points p1 and p2.", "function_declaration": "def calculate_distance(p1, p2):", "function_name": "calculate_distance", "parameter_list": "(p1, p2)" }, { "docstring": "Finds the shortest route that visits all trip stops exactly once...
[ 1, 0, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl", "solution_code": "import itertools\nimport math\n\ndef calculate_distance(p1, p2):\n \"\"\"\n Calculates the Euclidean distance between two points p1 and p2.\n \"\"\"\n ...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00098600", "row_id": 98600, "seed_ids": "[19884]" }
0.767362
Taco_98600
I
[ "calculate_distance", "shortest_route_distance" ]
2
[ [ "shortest_route_distance", "calculate_distance" ] ]
1
[]
false
[]
false
pytest
true
[]
true
f24b365606c9171edf357326cda382961ac463b7
42de30f2b2ab32b88d19cbf0e5149e2b8b88bb0f
v1.0
instruct
Taco
Taco_98644_I
Design a function `find_palindrome_pairs` that takes a list of words and returns a list of all unique pairs of indices (i, j) such that the concatenation of the words `words[i] + words[j]` is a palindrome. ### Function Signature `find_palindrome_pairs(words: List[str]) -> List[Tuple[int, int]]` ### Input - `words` (L...
from typing import List, Tuple def is_palindrome(s: str) -> bool: """ Helper function to check if a given string is a palindrome. """ return s == s[::-1] def find_palindrome_pairs(words: List[str]) -> List[Tuple[int, int]]: """ Given a list of words, returns a list of all unique pairs of indic...
from solution import find_palindrome_pairs def test_find_palindrome_pairs_example1(): assert set(find_palindrome_pairs(["bat", "tab", "cat"])) == set([(0, 1), (1, 0)]) def test_find_palindrome_pairs_example2(): assert set(find_palindrome_pairs(["abcd", "dcba", "lls", "s", "sssll"])) == set([(0, 1), (1, 0), (3...
[ { "docstring": "Helper function to check if a given string is a palindrome.", "function_declaration": "def is_palindrome(s):", "function_name": "is_palindrome", "parameter_list": "(s)" }, { "docstring": "Given a list of words, returns a list of all unique pairs of indices \n(i, j) such that ...
[ 1, 0, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl", "solution_code": "from typing import List, Tuple\n\ndef is_palindrome(s: str) -> bool:\n \"\"\"\n Helper function to check if a given string is a palindrome.\n \"\"\"\n ...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00098644", "row_id": 98644, "seed_ids": "[22300]" }
0.756071
Taco_98644
I
[ "is_palindrome", "find_palindrome_pairs" ]
2
[ [ "find_palindrome_pairs", "is_palindrome" ] ]
1
[]
false
[]
false
pytest
true
[]
true
73f912b6e04c09f25eded4b9a83e7902390097b3
ac69e6c2f0367feaa32f0f02240e74c1a9b1ca76
v1.0
instruct
Taco
Taco_98692_I
Raman is an astronomy enthusiast and loves observing the night sky. He has a telescope that can track multiple stars simultaneously. One night, he tracked the positions of $n$ stars in the sky. Each star $i$ has coordinates $(x_i, y_i)$ in a 2D plane. Raman is interested in knowing the maximum area of the triangle th...
from itertools import combinations from typing import List, Tuple def area_of_triangle(x1, y1, x2, y2, x3, y3): """Calculate the area of triangle using the determinant method.""" return abs((x1*(y2 - y3) + x2*(y3 - y1) + x3*(y1 - y2)) / 2) def max_triangle_area(t: int, cases: List[Tuple[int, List[Tuple[int, i...
def test_area_of_triangle(): assert area_of_triangle(0, 0, 0, 1, 1, 0) == 0.5 assert area_of_triangle(0, 0, 1, 0, 0, 1) == 0.5 assert area_of_triangle(0, 0, 1, 1, 2, 2) == 0.0 # collinear points def test_max_triangle_area(): input_data = ( "2\n" "3\n0 0\n0 1\n1 0\n" "4\n0 0\n0 ...
[ { "docstring": "Calculate the area of triangle using the determinant method.", "function_declaration": "def area_of_triangle(x1, y1, x2, y2, x3, y3):", "function_name": "area_of_triangle", "parameter_list": "(x1, y1, x2, y2, x3, y3)" }, { "docstring": null, "function_declaration": "def m...
[ 0, 0, 0, 0, 0, 1, 0, 1, 1, 1 ]
4
medium
0.4
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl", "solution_code": "import itertools\n\ndef max_triangle_area(n, stars):\n def triangle_area(p1, p2, p3):\n return abs(p1[0] * (p2[1] - p3[1]) + p2[0] * (p3[1] - p1[1]) + p3...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00098692", "row_id": 98692, "seed_ids": "[17687]" }
0.630592
Taco_98692
I
[ "area_of_triangle", "max_triangle_area", "process_input", "process_output" ]
4
[ [ "max_triangle_area", "area_of_triangle" ] ]
1
[ "process_input" ]
false
[]
false
pytest
false
[]
true
aaa161d2fcf3ffdbd4fad70109d8c492693646a1
2edb5dd75c7868d69c45013565d6d8981e95624b
v1.0
instruct
Taco
Taco_98750_I
John is a security analyst who is developing a password strength checker for an application. Each password must satisfy certain conditions to be considered strong. The conditions are as follows: 1. The password must be at least `n` characters long. 2. The password must contain at least one uppercase letter, one lowerc...
def is_strong_password(n, password): """ Determines if the given password is strong based on specified criteria. Parameters: n (int): The minimum length required for the password. password (str): The password string to be evaluated. Returns: str: 'YES' if the password is strong, ot...
def test_is_strong_password(): assert is_strong_password(7, 'A1b#def') == "YES" assert is_strong_password(7, 'A1bdefgH') == "NO" assert is_strong_password(7, 'a1bdefg!H') == "YES" assert is_strong_password(7, 'A1b') == "NO" # Less than 7 characters assert is_strong_password(7, 'abcdefg1!') == "NO" ...
[ { "docstring": "Determines if the given password is strong based on specified criteria.\n\nParameters:\nn (int): The minimum length required for the password.\npassword (str): The password string to be evaluated.\n\nReturns:\nstr: 'YES' if the password is strong, otherwise 'NO'.", "function_declaration": "d...
[ 0, 1, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl", "solution_code": "import re\n\ndef is_strong_password(password, n=8):\n \"\"\"\n Checks if a password is strong based on the given criteria:\n 1. At least n characters long...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00098750", "row_id": 98750, "seed_ids": "[19905]" }
0.636258
Taco_98750
I
[ "is_strong_password", "check_passwords" ]
2
[ [ "check_passwords", "is_strong_password" ] ]
1
[]
false
[]
false
pytest
false
[]
true
a8261f814b173758cbee99a3707c5977c953b930
2d24542ad90f01fcdcfab9bbc150ecac75f52e51
v1.0
instruct
Taco
Taco_98783_I
You are tasked with developing a pairing mechanism for a matchmaking service. The service aims to match individuals based on their preferences and certain constraints. The service stores data about individuals, including their unique IDs, ages, preferences (each person can list up to three desired characteristics in a...
import math def count_valid_pairs(datasets): def calculate_distance(x1, y1, x2, y2): return math.sqrt((x1 - x2)**2 + (y1 - y2)**2) results = [] for dataset in datasets: n = dataset[0] individuals = dataset[1] valid_pairs = 0 for i in range(n): ...
from solution import matchmaking def test_matchmaking_single_dataset(): input_data = """4 101 25 hiking photography reading 10.0 20.0 102 27 hiking cooking music 15.0 24.0 103 30 fitness music drawing 14.0 13.0 104 35 reading traveling hiking 40.0 50.0 0""" assert matchmaking(input_data) == [2] def test_match...
[ { "docstring": null, "function_declaration": "def count_valid_pairs(datasets):", "function_name": "count_valid_pairs", "parameter_list": "(datasets)" }, { "docstring": null, "function_declaration": "def parse_input(input_data):", "function_name": "parse_input", "parameter_list": ...
[ 0, 1, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl", "solution_code": "from math import sqrt\n\ndef calculate_distance(x1, y1, x2, y2):\n return sqrt((x1 - x2) ** 2 + (y1 - y2) ** 2)\n\ndef find_valid_pairs(dataset):\n n = len(d...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00098783", "row_id": 98783, "seed_ids": "[22167]" }
0.585218
Taco_98783
I
[ "count_valid_pairs", "parse_input", "matchmaking" ]
3
[ [ "matchmaking", "count_valid_pairs" ], [ "matchmaking", "parse_input" ] ]
2
[ "parse_input" ]
false
[]
false
pytest
true
[]
true
0cced2bcefd46057e2af7379c776549c4101acfe
18c0dfebf25b5b7507812aa59f919ac585ccc467
v1.0
instruct
Taco
Taco_98789_I
Little Shino loves binary trees. She recently learned how to traverse a binary tree in different ways. To test her understanding, she wants to create a binary tree and calculate the sum of all node values for each type of traversal. You are given the structure of a binary tree and the node values. Your task is to calc...
class TreeNode: def __init__(self, value): self.value = value self.left = None self.right = None def build_tree(node_values, edges): nodes = {i + 1: TreeNode(val) for i, val in enumerate(node_values)} for u, v in edges: if nodes[u].left is None: nodes[u].lef...
def test_inorder_sum(): N = 5 node_values = [1, 2, 3, 4, 5] edges = [(1, 2), (1, 3), (2, 4), (2, 5)] root = build_tree(node_values, edges) assert inorder_sum(root) == 15 def test_preorder_sum(): N = 5 node_values = [1, 2, 3, 4, 5] edges = [(1, 2), (1, 3), (2, 4), (2, 5)] root = buil...
[]
[ 1, 1, 0 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl", "solution_code": "class TreeNode:\n def __init__(self, value):\n self.value = value\n self.left = None\n self.right = None\n\ndef build_tree(node_values, edg...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00098789", "row_id": 98789, "seed_ids": "[25010]" }
0.646435
Taco_98789
I
[ "build_tree", "inorder_sum", "preorder_sum", "postorder_sum", "calculate_sums" ]
5
[ [ "calculate_sums", "build_tree" ], [ "calculate_sums", "inorder_sum" ], [ "calculate_sums", "postorder_sum" ], [ "calculate_sums", "preorder_sum" ] ]
4
[]
false
[ "TreeNode" ]
true
pytest
false
[]
true
363d41817c3e103341a45f22b34256be71f45681
238cd345c35cb1d45f990da5d221983ccd7ebd70
v1.0
instruct
Taco
Taco_98804_I
In a mystical land, there exists a peculiar type of tree known as the "Palindrome Tree." The defining characteristic of this tree is that the sequence of node values from the root to any leaf forms a palindrome. In other words, the sequence reads the same forward and backward. You are given a binary tree, where each n...
class TreeNode: def __init__(self, value): self.value = value self.left = None self.right = None def is_palindrome(s): return s == s[::-1] def is_palindrome_tree(root): if not root: return True paths = [] def dfs(node, path): if node: p...
import pytest from solution import TreeNode, is_palindrome, is_palindrome_tree, build_tree_from_level_order, check_palindrome_trees def test_is_palindrome(): assert is_palindrome("aba") == True assert is_palindrome("abc") == False def test_is_palindrome_tree(): # Tree 1: a b b a c # c (YES) tree1_data...
[]
[ 0, 1 ]
1
medium
0.5
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl", "solution_code": "class TreeNode:\n def __init__(self, val):\n self.val = val\n self.left = None\n self.right = None\n\ndef build_tree(nodes):\n if not no...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00098804", "row_id": 98804, "seed_ids": "[8344]" }
0.825309
Taco_98804
I
[ "is_palindrome", "is_palindrome_tree", "build_tree_from_level_order", "check_palindrome_trees" ]
4
[ [ "check_palindrome_trees", "build_tree_from_level_order" ], [ "check_palindrome_trees", "is_palindrome_tree" ], [ "is_palindrome_tree", "is_palindrome" ] ]
3
[]
false
[ "TreeNode" ]
true
pytest
true
[]
true
646b26f330aa29af5bef73c9008ce5184a550922
77913e10fcab7c41944b3ff180852a9cf000fdb5
v1.0
instruct
Taco
Taco_98816_I
Given a list of n points on a 2D plane, your task is to determine the pair of points that are the closest to each other and compute the Euclidean distance between them. ### Input: - The first line contains an integer n (2 ≤ n ≤ 10^5), the number of points. - The next n lines each contain two integers x and y (-10^9 ≤ ...
import math import itertools def euclidean_distance(p1, p2): return math.sqrt((p1[0] - p2[0]) ** 2 + (p1[1] - p2[1]) ** 2) def closest_pair_of_points(points): min_distance = float('inf') closest_pair = None # Sort points by x coordinate points.sort() for i, p1 in enumerate(points): ...
import pytest from solution import closest_distance def test_example1(): assert closest_distance(2, [(0, 0), (3, 4)]) == "5.000000" def test_example2(): assert closest_distance(3, [(1, 1), (2, 2), (4, 4)]) == "1.414214" def test_same_point(): assert closest_distance(2, [(0, 0), (0, 0)]) == "0.000000" de...
[ { "docstring": null, "function_declaration": "def euclidean_distance(p1, p2):", "function_name": "euclidean_distance", "parameter_list": "(p1, p2)" }, { "docstring": null, "function_declaration": "def closest_pair_of_points(points):", "function_name": "closest_pair_of_points", "p...
[ 1, 1, 0 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl", "solution_code": "import math\n\ndef closest_pair_distance(points):\n \"\"\"\n Returns the Euclidean distance between the closest pair of points in the given list.\n points...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00098816", "row_id": 98816, "seed_ids": "[7264]" }
0.761124
Taco_98816
I
[ "euclidean_distance", "closest_pair_of_points", "closest_distance" ]
3
[ [ "closest_distance", "closest_pair_of_points" ], [ "closest_pair_of_points", "euclidean_distance" ] ]
2
[]
false
[]
false
pytest
true
[]
true
9f4951a29e2e06a15f2073f60b5663c7764e9674
c57c2bb26a9ad16f9d5a955ebd0bb9d1f631a6d6
v1.0
instruct
Taco
Taco_98884_I
Given an array of integers of size N, your task is to shift the elements of the array to the right by K positions. This should be done in-place without using extra space for another array. If an element is shifted beyond the end of the array, it should wrap around to the beginning. Example 1: Input: N = 7, K = 3 arr[]...
def shiftRight(arr, N, K): """ Shift elements of the array to the right by K positions in place. :param arr: List[int] - The array to be shifted. :param N: int - The number of elements in the array. :param K: int - The number of positions to shift. """ # Effective number of shifts K...
from solution import shiftRight def test_shiftBy3_positions(): arr = [1, 2, 3, 4, 5, 6, 7] shiftRight(arr, 7, 3) assert arr == [5, 6, 7, 1, 2, 3, 4] def test_shiftBy2_positions(): arr = [10, 20, 30, 40, 50] shiftRight(arr, 5, 2) assert arr == [40, 50, 10, 20, 30] def test_shiftByMoreThanLengt...
[ { "docstring": "Shift elements of the array to the right by K positions in place.\n\n:param arr: List[int] - The array to be shifted.\n:param N: int - The number of elements in the array.\n:param K: int - The number of positions to shift.", "function_declaration": "def shiftRight(arr, N, K):", "function...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl", "solution_code": "def shiftRight(arr, N, K):\n \"\"\"\n Shifts the elements of the array to the right by K positions in-place.\n \n :param arr: List[int], the input arra...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00098884", "row_id": 98884, "seed_ids": "[2936]" }
0.722504
Taco_98884
I
[ "shiftRight", "reverse" ]
2
[ [ "shiftRight", "reverse" ] ]
1
[]
false
[]
false
pytest
true
[]
true
5f5af8efdd28d0072a4b0f21e6060efa52f185f5
94a64a186682d65e354f0552ca8e78559a170801
v1.0
instruct
Taco
Taco_98918_I
Jason's company is conducting a security audit of their password storage system. One of the tasks involves determining the strength of stored passwords. A password is considered strong if it meets the following conditions: 1. It has at least 8 characters. 2. It contains at least one uppercase letter. 3. It contains at...
def is_strong_password(password): """ Check if the password is strong based on provided criteria. """ if len(password) < 8: return "NO" has_upper = any(c.isupper() for c in password) has_lower = any(c.islower() for c in password) has_digit = any(c.isdigit() for c in password) ...
from solution import is_strong_password, check_passwords def test_is_strong_password(): assert is_strong_password("Password1!") == "YES" assert is_strong_password("abcd1234") == "NO" assert is_strong_password("A!c1") == "NO" assert is_strong_password("StrongPass1$") == "YES" assert is_strong_passwo...
[ { "docstring": "Check if the password is strong based on provided criteria.", "function_declaration": "def is_strong_password(password):", "function_name": "is_strong_password", "parameter_list": "(password)" }, { "docstring": null, "function_declaration": "def check_passwords(passwords)...
[ 1, 0, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_strong_password(password):\n \"\"\"\n Check if the password is strong based on provided criteria.\n \"\"\"\n if len(password) < 8:\n retu...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00098918", "row_id": 98918, "seed_ids": "[15345]" }
0.633213
Taco_98918
I
[ "is_strong_password", "check_passwords" ]
2
[ [ "check_passwords", "is_strong_password" ] ]
1
[]
false
[]
false
pytest
true
[]
true
91fd736535d5d96d86b876a85f1d475a744f5c9e
755097dba474231127c64eb9565603002a1a2c46
v1.0
instruct
Taco
Taco_98963_I
A new company wants to establish a communication network between its employees. The company has N employees and they want to set up a messenger service that ensures optimal communication time between employees. Each employee has a unique ID between 1 and N. Some pairs of employees are known to have direct communication...
import heapq import sys def floyd_warshall(n, edges): dist = [[sys.maxsize] * (n + 1) for _ in range(n + 1)] for i in range(1, n + 1): dist[i][i] = 0 for u, v, w in edges: dist[u][v] = w dist[v][u] = w for k in range(1, n + 1): for i in range(1, n + 1): ...
import pytest from solution import find_worst_case_latency_and_count, solve def test_find_worst_case_latency_and_count(): assert find_worst_case_latency_and_count(4, [(1, 2, 3), (2, 3, 4), (3, 4, 5), (1, 4, 9), (1, 3, 2)]) == (9, 1) assert find_worst_case_latency_and_count(3, [(1, 2, 3), (2, 3, 4), (1, 3, 5)])...
[ { "docstring": null, "function_declaration": "def floyd_warshall(n, edges):", "function_name": "floyd_warshall", "parameter_list": "(n, edges)" }, { "docstring": null, "function_declaration": "def find_worst_case_latency_and_count(n, edges):", "function_name": "find_worst_case_latenc...
[ 0, 0, 0, 1, 0 ]
1
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl", "solution_code": "def max_latency_and_count(T, cases):\n import heapq\n \n def dijkstra(graph, start, n):\n INF = float('inf')\n dist = [INF] * (n + 1)\n ...
trial_gpt4o_3
{ "original_instruction": "", "prompt_id": "00098963", "row_id": 98963, "seed_ids": "[14237]" }
0.64357
Taco_98963
I
[ "floyd_warshall", "find_worst_case_latency_and_count", "solve", "main" ]
4
[ [ "find_worst_case_latency_and_count", "floyd_warshall" ], [ "solve", "find_worst_case_latency_and_count" ] ]
2
[]
false
[]
false
pytest
true
[]
true
05e5ca76773f093725ec55f4859e61452194f4c5
9520b69cb13b9faafa930c5c14e6af88e85ac260
v1.0
instruct
Taco
Taco_98964_I
Alex is planning a road trip and wants to maintain a log of his journey. As part of this, he needs to calculate the distance between each pair of consecutive stops and the total distance traveled by the end of the trip. You need to help him write a program to calculate these distances. For simplicity, the map can be r...
import math def calculate_distances(stops): """ Calculates the distances between consecutive stops and the total distance. Parameters: stops (list of tuples): List of coordinate tuples (x, y) for each stop. Returns: list of floats: List of distances between consecutive stops, followed by ...
import pytest from solution import road_trip_log def test_single_segment(): assert road_trip_log(2, ["0 0", "3 4"]) == [5.00, 5.00] def test_multiple_segments(): assert road_trip_log(3, ["0 0", "3 4", "6 0"]) == [5.00, 5.00, 10.00] def test_negative_coordinates(): assert road_trip_log(2, ["-1 -1", "2 3"]...
[ { "docstring": "Calculates the distances between consecutive stops and the total distance.\n\nParameters:\nstops (list of tuples): List of coordinate tuples (x, y) for each stop.\n\nReturns:\nlist of floats: List of distances between consecutive stops, followed by the total distance.", "function_declaration...
[ 0, 0, 1 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl", "solution_code": "import math\n\ndef calculate_distances(n, stops):\n \"\"\"\n Given the number of stops and a list of (x, y) coordinates of each stop,\n calculates the dis...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00098964", "row_id": 98964, "seed_ids": "[4914]" }
0.683719
Taco_98964
I
[ "calculate_distances", "road_trip_log" ]
2
[ [ "road_trip_log", "calculate_distances" ] ]
1
[]
false
[]
false
pytest
true
[]
true
99831335cf50858b6b4be079b69237cf1ece4156
41160a70ecad5ab15a12ab02ae4b6351d2ff5b8f
v1.0
instruct
Taco
Taco_98971_I
Alice and Bob are playing a game with sequences of positive integers. Alice gives Bob a sequence of integers and asks him to perform a series of operations to transform it. Bob needs your help writing a program to automate these operations. Here is how the game works: 1. Start with an initial sequence of integers. 2...
from math import gcd from functools import reduce from collections import deque def lcm(a, b): """ Returns the Least Common Multiple of a and b. """ return a * b // gcd(a, b) def can_transform(initial_sequence, target_sequence): """ Given the initial and target sequence, determine whether it i...
import pytest from solution import can_transform def test_sample_case(): initial = [12, 15, 10, 20, 25] target = [3, 60, 10, 20, 25] assert can_transform(initial, target) == "YES" def test_same_sequence(): initial = [1, 2, 3] target = [1, 2, 3] assert can_transform(initial, target) == "YES" d...
[ { "docstring": "Returns the Least Common Multiple of a and b.", "function_declaration": "def lcm(a, b):", "function_name": "lcm", "parameter_list": "(a, b)" }, { "docstring": "Given the initial and target sequence, determine whether it is possible to\ntransform the initial sequence into the ...
[ 1, 0, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl", "solution_code": "from math import gcd\nfrom functools import reduce\nfrom collections import deque\n\ndef lcm(a, b):\n \"\"\"\n Returns the Least Common Multiple of a and b.\...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00098971", "row_id": 98971, "seed_ids": "[4876]" }
0.681443
Taco_98971
I
[ "lcm", "can_transform" ]
2
[ [ "can_transform", "lcm" ] ]
1
[]
false
[]
false
pytest
true
[]
true
5235340510576c4831a16c6a8bd4d57967d657df
ee4bc40f46f7538971091cbe3cf9c3aea6499600
v1.0
instruct
Taco
Taco_98974_I
You are the captain of a spaceship and have to navigate your ship through a complex asteroid field. The field is represented as a two-dimensional grid consisting of `r` rows and `c` columns. Each cell in the grid may contain an empty space, an asteroid, or the spaceship (your position). The grid is represented using t...
from collections import deque def transform_grid(current_grid, r, c, transformations): new_grid = [['.'] * c for _ in range(r)] for i in range(r): for j in range(c): if current_grid[i][j] == '#': if transformations[i][j] == 'U': new_grid[(i - 1 + r) % r][...
import pytest from solution import minimum_time_to_exit, transform_grid def test_example_1(): r, c, m = 4, 4, 2 grid = [ "S..#", "....", ".#..", "..E#" ] transformations = [ "DUDU", "RLUD", "LRLU", "UDUD" ] assert minimum_time_to_e...
[ { "docstring": null, "function_declaration": "def transform_grid(current_grid, r, c, transformations):", "function_name": "transform_grid", "parameter_list": "(current_grid, r, c, transformations)" }, { "docstring": null, "function_declaration": "def minimum_time_to_exit(r, c, m, grid, t...
[ 0, 0, 0, 0, 0, 0, 0, 0, 1, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl", "solution_code": "from collections import deque\n\ndef min_time_to_exit(r, c, m, grid, transform):\n \"\"\"\n Returns the minimum time required for the spaceship to reach the ...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00098974", "row_id": 98974, "seed_ids": "[21875]" }
0.59252
Taco_98974
I
[ "transform_grid", "minimum_time_to_exit" ]
2
[ [ "minimum_time_to_exit", "transform_grid" ] ]
1
[]
false
[]
false
pytest
true
[]
true
1dce2d92bc1686b57c2a3183d639904f44a098a1
61ede2a35cf497ef9c0c7c7c66c42af7aae5961c
v1.0
instruct
Taco
Taco_99001_I
Michael is a fan of prime numbers and subsequences. He defines a prime-subsequence as a subsequence of a given array that consists entirely of prime numbers. However, he finds it difficult to count all such prime-subsequences in a given array. Given an array of integers, can you help Michael count the number of prime-...
def is_prime(num): """Helper function to determine if a number is prime.""" if num <= 1: return False if num == 2: return True # 2 is the smallest prime number if num % 2 == 0: return False for i in range(3, int(num**0.5) + 1, 2): if num % i == 0: return ...
from solution import is_prime, count_prime_subsequences 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(19) == True assert is_prime(20) == False assert is_prime(1) == False assert is_prime...
[ { "docstring": "Helper function to determine if a number is prime.", "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": "Count the number of non-empty prime-subsequences in the array.", "function_declaration": "def count...
[ 1, 0, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(num):\n \"\"\"Helper function to determine if a number is prime.\"\"\"\n if num <= 1:\n return False\n if num == 2:\n return Tr...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00099001", "row_id": 99001, "seed_ids": "[360]" }
0.660618
Taco_99001
I
[ "is_prime", "count_prime_subsequences" ]
2
[ [ "count_prime_subsequences", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
6feea796f82aea2d9bd832ce7c8972bb070e029e
9623b863789d8b92d81fd4eacb33e791700bd7a3
v1.0
instruct
Taco
Taco_99013_I
**Problem Statement** You are given a grid consisting of `N` rows and `M` columns. Each cell in the grid can have either a value of 0 or 1. Your task is to find the largest square that can be formed entirely of 1s, and return its area. ### Input Format: - The first line contains two integers `N` and `M` representing ...
def largest_square_area(grid): """ Returns the area of the largest square of 1s in the given grid. """ if not grid or not grid[0]: return 0 N = len(grid) M = len(grid[0]) dp = [[0] * M for _ in range(N)] max_side = 0 for i in range(N): for j in range(M): ...
from solution import largest_square_area_from_input def test_largest_square_1(): input_str = '''4 5 1 0 1 0 0 1 0 1 1 1 1 1 1 1 1 1 0 0 1 0''' assert largest_square_area_from_input(input_str) == 4 def test_largest_square_2(): input_str = '''3 3 1 1 1 1 1 1 0 1 1''' assert largest_square_area_from_inpu...
[ { "docstring": "Returns the area of the largest square of 1s in the given grid.", "function_declaration": "def largest_square_area(grid):", "function_name": "largest_square_area", "parameter_list": "(grid)" }, { "docstring": null, "function_declaration": "def parse_input(input_str):", ...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl", "solution_code": "def largest_square_area(grid):\n \"\"\"\n Finds the largest square that can be formed entirely of 1s in the given grid\n and returns its area.\n \"\"\"...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00099013", "row_id": 99013, "seed_ids": "[10952]" }
0.706394
Taco_99013
I
[ "largest_square_area", "parse_input", "largest_square_area_from_input" ]
3
[ [ "largest_square_area_from_input", "largest_square_area" ], [ "largest_square_area_from_input", "parse_input" ] ]
2
[ "parse_input" ]
false
[]
false
pytest
true
[]
true
e8209f1d00dd152bf6ff9d7800a621f29bb4fb51
cd0a0028d004564a9e948f47ba96235df98acf16
v1.0
instruct
Taco
Taco_99027_I
In the realm of mystical forests, there are enchanted trees that form a magical boundary known as the "Mysterious Belt." Your mission is to calculate the energy required to traverse this belt. The forest can be represented as a 2D grid, where each cell has an energy value associated with crossing it. You start at the ...
def find_min_energy(t, test_cases): results = [] for case in test_cases: n, matrix = case dp = [[0] * n for _ in range(n)] dp[0][0] = matrix[0][0] for i in range(1, n): dp[i][0] = dp[i-1][0] + matrix[i][0] dp[0][i] = dp[0][i-1] + mat...
from solution import find_min_energy, parse_input def test_single_case(): t = 1 test_cases = [(3, [ [1, 2, 3], [4, 5, 6], [7, 8, 9] ])] assert find_min_energy(t, test_cases) == [21] def test_multiple_cases(): t = 2 test_cases = [ (3, [ [1, 2, 3], ...
[ { "docstring": null, "function_declaration": "def find_min_energy(t, test_cases):", "function_name": "find_min_energy", "parameter_list": "(t, test_cases)" }, { "docstring": null, "function_declaration": "def parse_input(input_data):", "function_name": "parse_input", "parameter_l...
[ 0, 0, 0, 1, 0 ]
1
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl", "solution_code": "def min_energy(grid):\n \"\"\"\n Given a grid of non-negative integers, calculate the minimum energy required\n to traverse from the top-left corner to th...
trial_gpt4o_3
{ "original_instruction": "", "prompt_id": "00099027", "row_id": 99027, "seed_ids": "[9357]" }
0.657942
Taco_99027
I
[ "find_min_energy", "parse_input", "mysterious_belt" ]
3
[ [ "mysterious_belt", "find_min_energy" ], [ "mysterious_belt", "parse_input" ] ]
2
[ "parse_input" ]
false
[]
false
pytest
true
[]
true
69ae51d636904390bd2574be3be8f2d33c0c019d
f637fd49148d991e2f692ce846b07d6b5bc63a2e
v1.0
instruct
Taco
Taco_99143_I
The National Treasure Hunt is an annual event where N teams participate in a series of treasure hunting challenges. Each team must find and submit treasures in different locations spread across a vast area. The objective of each challenge is to find the most valuable treasure in a given location. Each treasure has a un...
def calculate_points(matrix): """ Calculates the total points earned by each team over all challenges. Args: matrix (list of list of int): 2D list where each row represents the values of treasures submitted by each team in each challenge. Returns: lis...
from solution import treasure_hunt_points def test_example_case(): n = 4 m = 3 treasures = [ [100, 200, 300], [150, 200, 250], [300, 150, 100], [200, 300, 250] ] assert treasure_hunt_points(n, m, treasures) == [300, 0, 300, 300] def test_all_teams_get_points(): ...
[ { "docstring": "Calculates the total points earned by each team over all challenges.\n\nArgs:\nmatrix (list of list of int): 2D list where each row represents the values of \n treasures submitted by each team in each challenge.\n\nReturns:\nlist of int: List where each element repre...
[ 1, 0, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl", "solution_code": "def calculate_points(matrix):\n \"\"\"\n Calculates the total points earned by each team over all challenges.\n \n Args:\n matrix (list of list of i...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00099143", "row_id": 99143, "seed_ids": "[6637]" }
0.718499
Taco_99143
I
[ "calculate_points", "treasure_hunt_points" ]
2
[ [ "treasure_hunt_points", "calculate_points" ] ]
1
[]
false
[]
false
pytest
true
[]
true
f9f03394efd40abc12df583d5ea3df9d623045ee
df6711d4478852e03615b5b743ac7f897339fa0c
v1.0
instruct
Taco
Taco_99176_I
Alex is working on a project where he needs to optimize the storage space of a warehouse. The warehouse can be represented as a 2D grid of size $n \times m$, where each cell contains a certain number of items. Alex wants to be able to quickly retrieve the maximum number of items in any rectangular sub-grid of the wareh...
def preprocess_grid(grid, n, m): """ Preprocess the grid to allow quick retrieval of maximum in any sub-grid. This will build a 2D prefix max matrix. """ max_grid = [[0] * m for _ in range(n)] # Initialize the first cell max_grid[0][0] = grid[0][0] # Fill the first row for ...
def test_preprocess_grid(): grid = [ [1, 3, 2], [4, 6, 5], [7, 3, 9] ] expected = [ [1, 3, 3], [4, 6, 6], [7, 7, 9] ] n, m = 3, 3 assert preprocess_grid(grid, n, m) == expected def test_query_max(): grid = [ [1, 3, 2], [4, 6, 5...
[ { "docstring": "Preprocess the grid to allow quick retrieval of maximum in any sub-grid.\nThis will build a 2D prefix max matrix.", "function_declaration": "def preprocess_grid(grid, n, m):", "function_name": "preprocess_grid", "parameter_list": "(grid, n, m)" }, { "docstring": "Retrieve the...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl", "solution_code": "def preprocess_grid(grid):\n \"\"\"\n Preprocesses the grid to prepare for efficient sub-grid maximum queries.\n \"\"\"\n n = len(grid)\n m = len(gr...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00099176", "row_id": 99176, "seed_ids": "[2534]" }
0.670573
Taco_99176
I
[ "preprocess_grid", "query_max", "warehouse_queries" ]
3
[ [ "warehouse_queries", "preprocess_grid" ], [ "warehouse_queries", "query_max" ] ]
2
[]
false
[]
false
pytest
false
[]
true
9a322ee7d26ccb8224244a6c967011de2dd1db4c
73e17b17809b3d5e09dfcb828f9c9927713af311
v1.0
instruct
Taco
Taco_99180_I
Given a binary tree, you need to perform the following tasks: - Collect all the leaf nodes. - Sort the collected leaf nodes in non-decreasing order. - Replace the original leaf nodes in the tree with the sorted values. Example 1: Input: 5 / \ 3 8 /| |\ 1 4 7 9 Output: 5 / \ 3...
class TreeNode: def __init__(self, val=0, left=None, right=None): self.val = val self.left = left self.right = right def collect_leaves(root): if root is None: return [] if root.left is None and root.right is None: return [root.val] leaves = collect_leaves(root....
from solution import TreeNode, reorderLeaves def get_inorder(root): if not root: return [] return get_inorder(root.left) + [root.val] + get_inorder(root.right) def test_reorder_leaves_case_1(): root = TreeNode(5) root.left = TreeNode(3) root.right = TreeNode(8) root.left.left = Tr...
[]
[ 1, 0, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl", "solution_code": "class TreeNode:\n def __init__(self, val=0, left=None, right=None):\n self.val = val\n self.left = left\n self.right = right\n\n\ndef colle...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00099180", "row_id": 99180, "seed_ids": "[15928]" }
0.594432
Taco_99180
I
[ "collect_leaves", "replace_leaves", "reorderLeaves" ]
3
[ [ "reorderLeaves", "collect_leaves" ], [ "reorderLeaves", "replace_leaves" ] ]
2
[]
false
[ "TreeNode" ]
true
pytest
true
[]
true
949f53912c654a222cda22980c3a212ff09f7eb2
68405c30241144bc2f0d25d25ab2b4db72d8ccc5
v1.0
instruct
Taco
Taco_99228_I
Given a sequence of integers, we call a "prime pair" any two adjacent numbers that are both prime. A "good number" is a number in the sequence that is part of at least one prime pair. Your task is to determine the count of good numbers in a given sequence. A prime number is a number greater than 1 with no divisors oth...
def is_prime(n): if n <= 1: return False if n == 2: return True if n % 2 == 0: return False for i in range(3, int(n**0.5) + 1, 2): if n % i == 0: return False return True def count_good_numbers(sequences): results = [] for sequence in sequences: ...
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(20) == False assert is_prime(1) == False def test_count_good_numbers(): assert count_good_numbers(["2 3 5 7 11 13"]) == [6] assert count_goo...
[ { "docstring": null, "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": null, "function_declaration": "def count_good_numbers(sequences):", "function_name": "count_good_numbers", "parameter_list": "(sequences)" }, ...
[ 0, 1, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(n):\n if n <= 1:\n return False\n if n <= 3:\n return True\n if n % 2 == 0 or n % 3 == 0:\n return False\n i = 5\n ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00099228", "row_id": 99228, "seed_ids": "[7527]" }
0.641033
Taco_99228
I
[ "is_prime", "count_good_numbers", "process_input" ]
3
[ [ "count_good_numbers", "is_prime" ], [ "process_input", "count_good_numbers" ] ]
2
[ "process_input" ]
false
[]
false
pytest
false
[]
true
b96cbbd20db3131557548e5725d162940f01752d
5a0c9632bf62f82f8da62f4d92cdebbbabf51849
v1.0
instruct
Taco
Taco_99292_I
Consider a grid of size N x M filled with integers. You are given Q queries each specifying a rectangular sub-grid within the main grid. For each query, calculate the sum of all integers within the specified sub-grid. -----Input----- - The first line contains three integers, N, M, and Q, representing the number of row...
def calculate_prefix_sum(grid, n, m): prefix_sum = [[0] * (m + 1) for _ in range(n + 1)] for i in range(1, n + 1): for j in range(1, m + 1): prefix_sum[i][j] = grid[i - 1][j - 1] + prefix_sum[i - 1][j] + prefix_sum[i][j - 1] - prefix_sum[i - 1][j - 1] return prefix_sum def que...
def test_calculate_prefix_sum(): grid = [ [1, 2, 3], [4, 5, 6], [7, 8, 9] ] expected = [ [0, 0, 0, 0], [0, 1, 3, 6], [0, 5, 12, 21], [0, 12, 27, 45] ] assert calculate_prefix_sum(grid, 3, 3) == expected def test_query_subgrid_sum(): prefix...
[ { "docstring": null, "function_declaration": "def calculate_prefix_sum(grid, n, m):", "function_name": "calculate_prefix_sum", "parameter_list": "(grid, n, m)" }, { "docstring": null, "function_declaration": "def query_subgrid_sum(prefix_sum, x1, y1, x2, y2):", "function_name": "quer...
[ 0, 0, 0, 0, 1 ]
1
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl", "solution_code": "def preprocess_grid(grid, n, m):\n # Create a prefix sum matrix\n prefix_sum = [[0] * (m + 1) for _ in range(n + 1)]\n \n # Fill the prefix sum matrix\...
trial_gpt4o_4
{ "original_instruction": "", "prompt_id": "00099292", "row_id": 99292, "seed_ids": "[13858]" }
0.682868
Taco_99292
I
[ "calculate_prefix_sum", "query_subgrid_sum", "process_queries" ]
3
[ [ "process_queries", "calculate_prefix_sum" ], [ "process_queries", "query_subgrid_sum" ] ]
2
[ "process_queries" ]
false
[]
false
pytest
false
[]
true
b2829be7f0f9ff53ad497c766034778f2cf6221b
5ffa2100d803b6a3cc10179a0586185ff1744553
v1.0
instruct
Taco
Taco_99298_I
### Chessboard Knight's Move A knight in chess moves in an L-shape: it can move two squares in one direction (either vertically or horizontally) and then one square in a perpendicular direction, or one square in one direction and then two squares in a perpendicular direction. Given the starting and ending positions o...
from collections import deque def is_valid_position(x, y): return 0 <= x < 8 and 0 <= y < 8 def minKnightMoves(start, end): if not is_valid_position(*start) or not is_valid_position(*end): return "Invalid input" if start == end: return 0 moves = [(2, 1), (2, -1), (-2, 1), (-2...
import pytest from solution import minKnightMoves def test_knight_same_position(): assert minKnightMoves((4, 4), (4, 4)) == 0 def test_knight_one_move(): assert minKnightMoves((0, 0), (2, 1)) == 1 assert minKnightMoves((0, 0), (1, 2)) == 1 def test_knight_minimal_moves(): assert minKnightMoves((0, 0)...
[ { "docstring": null, "function_declaration": "def is_valid_position(x, y):", "function_name": "is_valid_position", "parameter_list": "(x, y)" }, { "docstring": null, "function_declaration": "def minKnightMoves(start, end):", "function_name": "minKnightMoves", "parameter_list": "(...
[ 1, 0 ]
1
medium
0.5
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl", "solution_code": "from collections import deque\n\ndef is_valid_position(x, y):\n return 0 <= x < 8 and 0 <= y < 8\n\ndef minKnightMoves(start, end):\n if not is_valid_positio...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00099298", "row_id": 99298, "seed_ids": "[22861]" }
0.698969
Taco_99298
I
[ "is_valid_position", "minKnightMoves" ]
2
[ [ "minKnightMoves", "is_valid_position" ] ]
1
[]
false
[]
false
pytest
true
[]
true
cc0b1b43809130f9887ce214df079a7061c81d1c
ffe1d65763a8bc8820f636ab6e9f4d154b6228a4
v1.0
instruct
Taco
Taco_99333_I
Write a program that helps the post office efficiently deliver packages. Each package has a weight, and the post office van has a weight limit for each delivery trip. You are given a list of package weights and the total weight limit of the van. The goal is to determine the minimum number of trips required to deliver ...
def min_trips(test_cases): results = [] for case in test_cases: N, W, weights = case weights.sort(reverse=True) trips = 0 while weights: remaining_capacity = W i = 0 while i < len(weights): if weights[...
def test_min_trips(): # Test case 1: Provided in the question test_cases = [ (4, 10, [2, 3, 5, 7]), (5, 15, [1, 2, 3, 4, 5]) ] assert process_min_trips(len(test_cases), test_cases) == [2, 1] # Test case 2: Multiple packages that perfectly fit into trips test_cases = [ ...
[ { "docstring": null, "function_declaration": "def min_trips(test_cases):", "function_name": "min_trips", "parameter_list": "(test_cases)" }, { "docstring": null, "function_declaration": "def process_min_trips(T, cases):", "function_name": "process_min_trips", "parameter_list": "(...
[ 0, 0, 1 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl", "solution_code": "def minimum_trips(T, test_cases):\n \"\"\"\n Determine the minimum number of trips required to deliver all packages for each test case.\n \n Parameters...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00099333", "row_id": 99333, "seed_ids": "[19310]" }
0.743405
Taco_99333
I
[ "min_trips", "process_min_trips" ]
2
[ [ "process_min_trips", "min_trips" ] ]
1
[]
false
[]
false
pytest
false
[]
true
f5e143572607de4a51fe2cf384721ea0f600269c
5a26065978a081dfaa5c47ed2a831c26b074983f
v1.0
instruct
Taco
Taco_99353_I
A teacher wants to grade homework assignments using a specific set of rules. The homework consists of Q problems, each with a score that can range from 0 to 100. The teacher has decided to use the following rules to determine the final grade for each assignment: 1. If a score is a perfect square, it will be multiplied...
import math def is_prime(n): """ Check if a number is prime. """ if n <= 1: return False if n <= 3: return True if n % 2 == 0 or n % 3 == 0: return False i = 5 while i * i <= n: if n % i == 0 or n % (i + 2) == 0: return False i += 6 ...
from solution import is_prime, apply_grading_rules def test_is_prime(): assert is_prime(0) == False assert is_prime(1) == False assert is_prime(2) == True assert is_prime(3) == True assert is_prime(4) == False assert is_prime(5) == True assert is_prime(10) == False assert is_prime(17) =...
[ { "docstring": "Check if a number is prime.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Apply grading rules to a list of scores.", "function_declaration": "def apply_grading_rules(scores):", "function_name": "a...
[ 1, 0, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl", "solution_code": "import math\n\ndef is_prime(n):\n \"\"\"\n Check if a number is prime.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return True...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00099353", "row_id": 99353, "seed_ids": "[10629]" }
0.672241
Taco_99353
I
[ "is_prime", "apply_grading_rules", "main" ]
3
[ [ "apply_grading_rules", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
6347f54c2b1180f1e1b1f7fcdfa58b451331ebea
afabe00313ed18f6fbe372a47f6008478d43b125
v1.0
instruct
Taco
Taco_99374_I
Given a binary tree, your task is to complete the function `isSymmetric()`, that returns true if the binary tree is a mirror of itself (i.e., symmetric around its center) and false otherwise. Example 1: Input: 1 / \ 2 2 / \ / \ 3 4 4 3 Output: True Explanation: The given binary tree is symmetric. Exampl...
# Definition for a binary tree node. class TreeNode: def __init__(self, x): self.val = x self.left = None self.right = None def isSymmetric(root): """ Determines if a binary tree is symmetric. Args: root (TreeNode): The root node of the binary tree. Ret...
import pytest from solution import TreeNode, isSymmetric def test_is_symmetric_example1(): # Creating the tree for example 1 root = TreeNode(1) root.left = TreeNode(2) root.right = TreeNode(2) root.left.left = TreeNode(3) root.left.right = TreeNode(4) root.right.left = TreeNode(4) root....
[]
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl", "solution_code": "class TreeNode:\n def __init__(self, val=0, left=None, right=None):\n self.val = val\n self.left = left\n self.right = right\n\ndef isSymme...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00099374", "row_id": 99374, "seed_ids": "[2879]" }
0.621379
Taco_99374
I
[ "isSymmetric", "isMirror" ]
2
[ [ "isSymmetric", "isMirror" ] ]
1
[]
false
[ "TreeNode" ]
true
pytest
true
[]
true
b8fd5bdf66ed18f380a95743301f909baea0929d
9a959839e898119c3ca3efeb4070235d86da71cc
v1.0
instruct
Taco
Taco_99396_I
Alice loves playing with arrays and performing operations on them. One day, she came across a unique operation and decided to turn it into a challenge. The challenge is as follows: Given an array of positive integers, Alice performs the following operation until no more operations can be performed: 1. Select any two e...
import math from functools import reduce def gcd(x, y): """ Returns the greatest common divisor of x and y. """ while y: x, y = y, x % y return x def find_final_element(arr): """ Returns the final remaining element in the array after performing the operations. """ return re...
from solution import process_test_cases def test_sample_cases(): assert process_test_cases(2, [(3, [10, 7, 12]), (4, [2, 4, 6, 8])]) == [1, 2] def test_all_elements_same(): assert process_test_cases(1, [(5, [5, 5, 5, 5, 5])]) == [5] def test_mixed_elements(): assert process_test_cases(1, [(4, [4, 8, 12, ...
[ { "docstring": "Returns the greatest common divisor of x and y.", "function_declaration": "def gcd(x, y):", "function_name": "gcd", "parameter_list": "(x, y)" }, { "docstring": "Returns the final remaining element in the array after performing the operations.", "function_declaration": "d...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl", "solution_code": "from math import gcd\nfrom functools import reduce\n\ndef find_final_remaining_element(arr):\n \"\"\"\n Given an array, returns the final remaining element a...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00099396", "row_id": 99396, "seed_ids": "[11544]" }
0.707989
Taco_99396
I
[ "gcd", "find_final_element", "process_test_cases" ]
3
[ [ "find_final_element", "gcd" ], [ "process_test_cases", "find_final_element" ] ]
2
[ "process_test_cases" ]
false
[]
false
pytest
true
[]
true
55d8e8b37068f085f6c8f75324916d0351060a67
63ae49218430e510d1a3dfe35d237ae102ca6519
v1.0
instruct
Taco
Taco_99466_I
You are given a string of parentheses, and you are required to determine if the parentheses are balanced. A string is balanced if every opening parenthesis '(' has a corresponding closing parenthesis ')', and the pairs of parentheses are properly nested. Input Format The input begins with an integer M > 0, followed b...
def is_balanced_parentheses(s): """ Returns 'YES' if the string s of parentheses is balanced, otherwise 'NO'. """ stack = [] for char in s: if char == '(': stack.append(char) elif char == ')': if not stack: return "NO" stack.pop() ...
from solution import is_balanced_parentheses, check_parentheses_balance def test_is_balanced_parentheses(): assert is_balanced_parentheses("()") == "YES" assert is_balanced_parentheses("(()())") == "YES" assert is_balanced_parentheses("(()") == "NO" assert is_balanced_parentheses(")(") == "NO" asse...
[ { "docstring": "Returns 'YES' if the string s of parentheses is balanced, otherwise 'NO'.", "function_declaration": "def is_balanced_parentheses(s):", "function_name": "is_balanced_parentheses", "parameter_list": "(s)" }, { "docstring": "Processes a list of parentheses strings and returns a ...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_balanced_parentheses(strings):\n \"\"\"\n Given a list of strings of parentheses, determine if each string is balanced.\n A string is balanced if e...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00099466", "row_id": 99466, "seed_ids": "[23294]" }
0.73955
Taco_99466
I
[ "is_balanced_parentheses", "check_parentheses_balance" ]
2
[ [ "check_parentheses_balance", "is_balanced_parentheses" ] ]
1
[]
false
[]
false
pytest
true
[]
true
c7a866422f7394b67a727aee80c51a1e26d21844
f5f30100a8234d963b59be97ff7792327548e8c5
v1.0
instruct
Taco
Taco_99472_I
Given an integer array nums, return the product of the integers in that array that are prime numbers. If there is no such integer in the array, return 1. Example 1: Input: nums = [2, 3, 4, 7, 8] Output: 42 Explanation: 2, 3, and 7 are prime numbers. The product of these primes is 2 * 3 * 7 = 42. Example 2: Input: num...
def is_prime(n): """Helper function to check if a number is prime.""" if n <= 1: return False if n <= 3: return True if n % 2 == 0 or n % 3 == 0: return False i = 5 while i * i <= n: if n % i == 0 or n % (i + 2) == 0: return False i += 6 re...
from solution import product_of_primes, is_prime def test_is_prime(): assert is_prime(2) == True assert is_prime(3) == True assert is_prime(4) == False assert is_prime(7) == True assert is_prime(9) == False assert is_prime(13) == True assert is_prime(25) == False def test_no_prime_numbers(...
[ { "docstring": "Helper function to check if a number is prime.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Returns the product of prime numbers in the given list of integers.\nIf there are no primes, returns 1.", "...
[ 1, 0, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(n):\n \"\"\"Helper function to check if a number is prime.\"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return True\n if...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00099472", "row_id": 99472, "seed_ids": "[388]" }
0.751372
Taco_99472
I
[ "is_prime", "product_of_primes" ]
2
[ [ "product_of_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
8a39be4d6468390514ba4eec84ff6976090af7c4
b55e65fee2db83d28f0465118c5d4cf8f7c629f6
v1.0
instruct
Taco
Taco_99514_I
In a country called Algorithmia, traffic control is a crucial matter. The government conducts a traffic survey every year to understand and alleviate traffic congestion in its capital city. One major intersection in the city has several road segments leading towards and away from it. Each road segment can be described ...
import math def calculate_segment_length(x1, y1, x2, y2): """ Calculates the Euclidean distance between two points (x1, y1) and (x2, y2). """ return math.sqrt((x2 - x1)**2 + (y2 - y1)**2) def total_road_segments_length(n, segments): """ Calculates the total length of all road segments. ...
from solution import calculate_segment_length, total_road_segments_length def test_calculate_segment_length(): assert calculate_segment_length(0, 0, 3, 4) == 5.0 assert calculate_segment_length(1, 2, 4, 6) == 5.0 assert calculate_segment_length(3, 3, 6, 7) == 5.0 def test_total_road_segments_length(): ...
[ { "docstring": "Calculates the Euclidean distance between two points (x1, y1) and (x2, y2).", "function_declaration": "def calculate_segment_length(x1, y1, x2, y2):", "function_name": "calculate_segment_length", "parameter_list": "(x1, y1, x2, y2)" }, { "docstring": "Calculates the total len...
[ 0, 0, 0, 0, 0, 0, 0, 1, 0 ]
1
hard
0.111
{ "trial_gpt4o_0": null, "trial_gpt4o_1": { "file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared1_results_combined.jsonl", "solution_code": "import math\n\ndef total_road_length(segments):\n \"\"\"\n This function calculates the total length of all road segments.\n\n Pa...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00099514", "row_id": 99514, "seed_ids": "[15773]" }
0.621382
Taco_99514
I
[ "calculate_segment_length", "total_road_segments_length" ]
2
[ [ "total_road_segments_length", "calculate_segment_length" ] ]
1
[]
false
[]
false
pytest
true
[]
true
0ed1d9e59a19c09bc432c06b87c5d0dff9017866
0e4fbb812ec42ca6d38615e0450e496304b33e58
v1.0
instruct
Taco
Taco_99625_I
Create a program that reads a series of words and determines if each word can be rearranged to form a palindrome. A string is a palindrome if it reads the same from the front and back, such as "abba" or "racecar". For the string to be rearranged into a palindrome, at most one character can have an odd number of occurr...
def can_form_palindrome(word): """ Determines if a word can be rearranged to form a palindrome. """ # Count occurrences of each character char_count = {} for char in word: if char in char_count: char_count[char] += 1 else: char_count[char] = 1 # C...
def test_can_form_palindrome(): assert can_form_palindrome("civic") == True assert can_form_palindrome("ivicc") == True assert can_form_palindrome("hello") == False assert can_form_palindrome("racecar") == True assert can_form_palindrome("aabbcc") == True assert can_form_palindrome("aabbccd") ==...
[ { "docstring": "Determines if a word can be rearranged to form a palindrome.", "function_declaration": "def can_form_palindrome(word):", "function_name": "can_form_palindrome", "parameter_list": "(word)" }, { "docstring": "Processes a series of words to determine if each can be rearranged to...
[ 1, 0, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl", "solution_code": "def can_form_palindrome(word):\n \"\"\"\n Determines if a word can be rearranged to form a palindrome.\n \"\"\"\n # Count occurrences of each character...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00099625", "row_id": 99625, "seed_ids": "[11543]" }
0.778559
Taco_99625
I
[ "can_form_palindrome", "process_words" ]
2
[ [ "process_words", "can_form_palindrome" ] ]
1
[]
false
[]
false
pytest
false
[]
true
bd8c07c08fbe5455cfc4e307e86215185f150caa
3b3acf4a4642160ef72832a07e80abfe9d02f45b
v1.0
instruct
Taco
Taco_99631_I
Sarah is a coding enthusiast who loves solving problems. One day she encounters a coding challenge that involves prime number manipulation. The problem statement goes as follows: You are given a list of $n$ integers. For each integer in the list, determine whether it is prime or not. If the number is prime, Sarah shou...
def is_prime(number): """ Check if a number is prime. """ if number <= 1: return False if number <= 3: return True if number % 2 == 0 or number % 3 == 0: return False i = 5 while i * i <= number: if number % i == 0 or number % (i + 2) == 0: ret...
from solution import is_prime, next_prime, replace_primes_with_next, process_numbers 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(25) == False def test_next_prime(): assert next_prime(2) == 3 ...
[ { "docstring": "Check if a number is prime.", "function_declaration": "def is_prime(number):", "function_name": "is_prime", "parameter_list": "(number)" }, { "docstring": "Find the next prime number greater than the given number n.", "function_declaration": "def next_prime(n):", "fun...
[ 1, 0, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(num):\n \"\"\"\n Determines if a number is a prime number.\n \"\"\"\n if num <= 1:\n return False\n if num <= 3:\n return...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00099631", "row_id": 99631, "seed_ids": "[6368]" }
0.599372
Taco_99631
I
[ "is_prime", "next_prime", "replace_primes_with_next", "process_numbers" ]
4
[ [ "next_prime", "is_prime" ], [ "process_numbers", "replace_primes_with_next" ], [ "replace_primes_with_next", "is_prime" ], [ "replace_primes_with_next", "next_prime" ] ]
4
[]
false
[]
false
pytest
true
[]
true
20d935feabe40f988cdc3ac37fcf3f7e99559a0b
4574ed7fb1bc78c793a6c655efd06d710d169c12
v1.0
instruct
Taco
Taco_99650_I
Harry and Sally love playing with numbers. Their favorite game is to transform numbers in a unique way. The rule of the game is simple: For any given number N, they check whether it is possible to split the number into two prime numbers whose sum is equal to N. If possible, they print the two prime numbers, otherwise, ...
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 for i in range(3, int(num**0.5) + 1, 2): if num % i == 0: return False return True def find_prime_pair(N): ...
from solution import is_prime, find_prime_pair, prime_pairs 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_prime_pair(): assert find_prime_pair(10) == (3, 7) asser...
[ { "docstring": "Check if a number is prime.", "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": "Find two prime numbers whose sum is N.", "function_declaration": "def find_prime_pair(N):", "function_name": "find_pri...
[ 0, 1, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(n):\n if n <= 1:\n return False\n for i in range(2, int(n**0.5) + 1):\n if n % i == 0:\n return False\n return True\...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00099650", "row_id": 99650, "seed_ids": "[7099]" }
0.700175
Taco_99650
I
[ "is_prime", "find_prime_pair", "prime_pairs" ]
3
[ [ "find_prime_pair", "is_prime" ], [ "prime_pairs", "find_prime_pair" ] ]
2
[]
false
[]
false
pytest
true
[]
true
a993e41d09e62d503a42318790324616f426c732
167552a43d9a9f3f6019e58630f4822521b42019
v1.0
instruct
Taco
Taco_99680_I
Given two integers a and b, you are required to find the LCM (Least Common Multiple) of all the integers from a to b (inclusive). The LCM of two integers x and y is the smallest positive integer that is divisible by both x and y. To make the problem slightly easier, you can directly use the GCD (Greatest Common Diviso...
from math import gcd from functools import reduce MOD = 1000000007 def lcm(a, b): return a * b // gcd(a, b) def lcm_range(a, b): if a == b: return a % MOD return reduce(lambda x, y: lcm(x, y) % MOD, range(a, b + 1)) # Example test cases print(lcm_range(1, 3)) # Output: 6 print(lcm_range(4, 6)) ...
from solution import lcm_range def test_example_cases(): assert lcm_range(1, 3) == 6 assert lcm_range(4, 6) == 60 assert lcm_range(2, 5) == 60 assert lcm_range(7, 7) == 7 def test_single_element(): assert lcm_range(1, 1) == 1 assert lcm_range(13, 13) == 13 def test_same_multiple(): assert...
[ { "docstring": null, "function_declaration": "def lcm(a, b):", "function_name": "lcm", "parameter_list": "(a, b)" }, { "docstring": null, "function_declaration": "def lcm_range(a, b):", "function_name": "lcm_range", "parameter_list": "(a, b)" } ]
[ 0, 0, 1 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl", "solution_code": "from math import gcd\n\nMOD = 1000000007\n\ndef lcm(x, y):\n return (x * y) // gcd(x, y)\n\ndef lcm_range(a, b):\n lcm_result = 1\n for num in range(a, b ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00099680", "row_id": 99680, "seed_ids": "[17112]" }
0.65707
Taco_99680
I
[ "lcm", "lcm_range" ]
2
[ [ "lcm_range", "lcm" ] ]
1
[]
false
[]
false
pytest
true
[]
true
0d733187a44bddef12e44343b12b83f700ad11dc
60cb9fceee37a8f55948c29005ea231dfebc3bdb
v1.0
instruct
Taco
Taco_99691_I
function sumPrimes() is provided to return the sum of all prime numbers that are less than a given non-negative integer n. Code def is_prime(num): if num <= 1: return False for i in range(2, int(num ** 0.5) + 1): if num % i == 0: return False return True def sumPrimes(n): ...
def is_prime(num): if num <= 1: return False for i in range(2, int(num ** 0.5) + 1): if num % i == 0: return False return True def sumPrimes(n): total = 0 for i in range(2, n): if is_prime(i): total += i return total
from solution import is_prime, sumPrimes def test_is_prime(): assert is_prime(2) is True assert is_prime(3) is True assert is_prime(4) is False assert is_prime(17) is True assert is_prime(18) is False assert is_prime(19) is True assert is_prime(1) is False assert is_prime(0) is False ...
[ { "docstring": null, "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": null, "function_declaration": "def sumPrimes(n):", "function_name": "sumPrimes", "parameter_list": "(n)" } ]
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(num):\n if num <= 1:\n return False\n for i in range(2, int(num ** 0.5) + 1):\n if num % i == 0:\n return False\n re...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00099691", "row_id": 99691, "seed_ids": "[16091]" }
0.686104
Taco_99691
I
[ "is_prime", "sumPrimes" ]
2
[ [ "sumPrimes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
ec43723556f8cdab33f9ecc05bf28f224ebe7da6
0caf855bbc3b3d3c167865bf53f54f114a45465e
v1.0
instruct
Taco
Taco_99721_I
Given an integer n, your task is to determine if it is possible to express the number n as the sum of two prime numbers. If possible, return any such pair of prime numbers, otherwise return -1. ------ Input Format ------ - The first line contains a single integer T - the number of test cases. Then the test cases foll...
import math def is_prime(num): """ Checks if a number is a 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 Fals...
from solution import solve def test_case_1(): assert solve([10]) == ["3 7"] def test_case_2(): assert solve([27]) == [-1] def test_case_3(): assert solve([4]) == ["2 2"] def test_case_4(): assert solve([20]) == ["3 17"] def test_multiple_cases(): assert solve([10, 27, 4, 20]) == ["3 7", -1, "2 ...
[ { "docstring": "Checks if a number is a prime.", "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": "Finds a pair of prime numbers that sum up to n.", "function_declaration": "def find_prime_pair(n):", "function_name...
[ 1, 0, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl", "solution_code": "import math\n\ndef is_prime(num):\n \"\"\"\n Checks if a number is a prime.\n \"\"\"\n if num <= 1:\n return False\n if num <= 3:\n re...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00099721", "row_id": 99721, "seed_ids": "[5869]" }
0.765771
Taco_99721
I
[ "is_prime", "find_prime_pair", "solve" ]
3
[ [ "find_prime_pair", "is_prime" ], [ "solve", "find_prime_pair" ] ]
2
[]
false
[]
false
pytest
true
[]
true
3e80efc627cca4c21d5c5a34f40c853117727f77
a8b4e4ecb398d79ded94c465a3bc2e93ca6397f1
v1.0
instruct
Taco
Taco_99764_I
Alice wants to compare the performance of two sorting algorithms: Quick Sort and Merge Sort. Given a list of integers, her goal is to determine which sorting algorithm will perform fewer comparisons for a particular configuration. Implement a function that simulates the number of comparisons made by Quick Sort and Mer...
def quick_sort_comparisons(arr, lo, hi): """ Helper function to count comparisons in Quick Sort """ if lo >= hi: return 0 pivot = arr[hi] i = lo - 1 comparisons = 0 for j in range(lo, hi): comparisons += 1 if arr[j] <= pivot: i += 1 arr[i], arr[j] ...
def test_compare_sorts_quick_sort_fewer(): import io import sys input_str = "5\n3 5 1 9 6\n" sys.stdin = io.StringIO(input_str) from solution import compare_sorts compare_sorts(5, [3, 5, 1, 9, 6]) def test_compare_sorts_merge_sort_fewer(): import io import sys input_str = "3\n2 3 1\...
[ { "docstring": "Helper function to count comparisons in Quick Sort ", "function_declaration": "def quick_sort_comparisons(arr, lo, hi):", "function_name": "quick_sort_comparisons", "parameter_list": "(arr, lo, hi)" }, { "docstring": "Helper function to count comparisons in Merge Sort ", ...
[ 0, 1, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl", "solution_code": "def quick_sort_comparisons(arr):\n def quick_sort(arr, low, high):\n if low < high:\n pi, comparisons = partition(arr, low, high)\n ...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00099764", "row_id": 99764, "seed_ids": "[7547]" }
0.54895
Taco_99764
I
[ "quick_sort_comparisons", "merge_sort_comparisons", "merge_and_count", "compare_sorts" ]
4
[ [ "compare_sorts", "merge_sort_comparisons" ], [ "compare_sorts", "quick_sort_comparisons" ], [ "merge_sort_comparisons", "merge_and_count" ] ]
3
[]
false
[]
false
pytest
true
[]
true
b0ea192c5e134eb82481ebe23941be767a881173
92a0c3977e70fa335f3c93531093fcfd195ad614
v1.0
instruct
Taco
Taco_99812_I
The manager of a multi-user system wants to analyze user logins and statistics for each user. Your task is to implement a system that processes a list of log entries which contain information about user logins and logouts during a single day and computes the amount of time each user spent logged in. A login event does...
def parse_time(time_str): """ Parses a time string in HH:MM format and returns the total minutes since midnight. """ hours, minutes = map(int, time_str.split(':')) return hours * 60 + minutes def format_time(total_minutes): """ Formats total minutes as a string in HH:MM format. """ ...
from solution import compute_login_times def test_example_1(): log_entries = [ "09:00 login alice", "12:00 logout alice", "13:00 login bob", "13:45 logout bob" ] result = compute_login_times(4, log_entries) assert result == ["alice 03:00", "bob 00:45"] def test_example_...
[ { "docstring": "Parses a time string in HH:MM format and returns the total minutes since midnight.", "function_declaration": "def parse_time(time_str):", "function_name": "parse_time", "parameter_list": "(time_str)" }, { "docstring": "Formats total minutes as a string in HH:MM format.", ...
[ 0, 1, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl", "solution_code": "def compute_user_login_times(n, log_entries):\n from collections import defaultdict\n from datetime import datetime\n\n user_login_times = defaultdict(int...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00099812", "row_id": 99812, "seed_ids": "[3821]" }
0.592788
Taco_99812
I
[ "parse_time", "format_time", "compute_login_times" ]
3
[ [ "compute_login_times", "format_time" ], [ "compute_login_times", "parse_time" ] ]
2
[]
false
[]
false
pytest
true
[]
true
70a979c7cfae3e986b008e821898a059254e6fa7
e92b8a8179338386db139769ece881fa1262f853
v1.0
instruct
Taco
Taco_99859_I
Adam is an avid gardener who loves arranging his plants in a specific pattern. He recently came up with a new type of arrangement he calls the "Beautiful Cluster". In this task, you are required to help Adam by calculating the number of possible Beautiful Clusters. A Beautiful Cluster has the following properties: - I...
def factorial(n): """ Calculates the factorial of n modulo 10^9+7 """ MOD = 10**9 + 7 result = 1 for i in range(2, n+1): result = (result * i) % MOD return result def combinations(n, k): """ Calculates n choose k modulo 10^9+7 """ if k > n: return 0 MOD =...
import pytest from solution import beautiful_clusters, factorial, combinations def test_factorial(): assert factorial(0) == 1 assert factorial(5) == 120 assert factorial(10) == 3628800 def test_combinations(): assert combinations(5, 2) == 10 assert combinations(4, 4) == 1 assert combinations(6...
[ { "docstring": "Calculates the factorial of n modulo 10^9+7", "function_declaration": "def factorial(n):", "function_name": "factorial", "parameter_list": "(n)" }, { "docstring": "Calculates n choose k modulo 10^9+7", "function_declaration": "def combinations(n, k):", "function_name"...
[ 0, 0, 0, 1, 0 ]
1
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl", "solution_code": "from math import comb, factorial\n\nMOD = 10**9 + 7\n\ndef count_beautiful_clusters(N, M):\n \"\"\"\n This function returns the number of possible Beautiful ...
trial_gpt4o_3
{ "original_instruction": "", "prompt_id": "00099859", "row_id": 99859, "seed_ids": "[24000]" }
0.647511
Taco_99859
I
[ "factorial", "combinations", "beautiful_clusters", "process_input_and_output" ]
4
[ [ "beautiful_clusters", "combinations" ], [ "beautiful_clusters", "factorial" ], [ "combinations", "factorial" ], [ "process_input_and_output", "beautiful_clusters" ] ]
4
[]
false
[]
false
pytest
true
[]
true
70b1b9aec5cebbc8473e5e3b39b4aaac775acb89
15e2ea5ca8950847cf18bee697ea48d546d317ff
v1.0
instruct
Taco
Taco_99873_I
### Task Sam is learning about prime numbers and he also wants to understand how digits of prime numbers distribute themselves. He needs a program that converts an integer to a list of its digits, then determines if the sum of the digits is a prime number. Given an integer `n`, write a function that will accomplish th...
def is_prime(num): """ Determines if a number is prime. """ if num <= 1: return False if num == 2: return True if num % 2 == 0: return False for i in range(3, int(num**0.5) + 1, 2): if num % i == 0: return False return True def sum_of_digits_i...
from solution import sum_of_digits_is_prime def test_sum_of_digits_is_prime(): assert sum_of_digits_is_prime(123) == False, "Test case 123 failed" assert sum_of_digits_is_prime(113) == True, "Test case 113 failed" assert sum_of_digits_is_prime(29) == True, "Test case 29 failed" assert sum_of_digits_is_...
[ { "docstring": "Determines if a number is prime.", "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": "Determines if the sum of the digits of n is a prime number.", "function_declaration": "def sum_of_digits_is_prime(n):...
[ 0, 0, 1 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(num):\n \"\"\"\n Checks if the given number is a prime number.\n \"\"\"\n if num <= 1:\n return False\n if num <= 3:\n re...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00099873", "row_id": 99873, "seed_ids": "[11231]" }
0.678049
Taco_99873
I
[ "is_prime", "sum_of_digits_is_prime" ]
2
[ [ "sum_of_digits_is_prime", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
bfce95be7f78505088dc7cecc45319ac59bea729
a23e2690dbd814f4fef7f5e25e024661571c2dd8
v1.0
instruct
Taco
Taco_99974_I
The city of Codeville has a peculiar street numbering system. Each street is represented by an integer, and the city planners have devised several routes between different streets. Each route connects two different streets bidirectionally and has an associated length. The Mayor wants to redesign the city's utility ser...
def find(parent, u): if parent[u] != u: parent[u] = find(parent, parent[u]) return parent[u] def union(parent, rank, u, v): root_u = find(parent, u) root_v = find(parent, v) if root_u != root_v: if rank[root_u] > rank[root_v]: parent[root_v] = root_u elif ra...
def test_example_one(): assert minimum_cost_to_connect_streets(4, 5, [(1, 2, 10), (1, 3, 6), (2, 3, 5), (3, 4, 7), (1, 4, 12)]) == 18 def test_example_two(): assert minimum_cost_to_connect_streets(3, 1, [(1, 2, 15)]) == -1 def test_single_street(): assert minimum_cost_to_connect_streets(1, 0, []) == 0 de...
[ { "docstring": null, "function_declaration": "def find(parent, u):", "function_name": "find", "parameter_list": "(parent, u)" }, { "docstring": null, "function_declaration": "def union(parent, rank, u, v):", "function_name": "union", "parameter_list": "(parent, rank, u, v)" }, ...
[ 0, 0, 1 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_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, x)\...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00099974", "row_id": 99974, "seed_ids": "[20522]" }
0.741432
Taco_99974
I
[ "find", "union", "minimum_cost_to_connect_streets" ]
3
[ [ "minimum_cost_to_connect_streets", "find" ], [ "minimum_cost_to_connect_streets", "union" ], [ "union", "find" ] ]
3
[]
false
[]
false
pytest
false
[]
true
1bb0551b81ba49eec72428ef2ecfcf9cb049692c
2f015b5576362db5ad97a279230efb4ce3dd51a7
v1.0
instruct
Taco
Taco_99977_I
Consider an undirected graph with `N` nodes numbered from `1` to `N` and `M` bidirectional edges. Each edge has an associated weight. You need to answer `Q` queries. Each query consists of two integers `U` and `V`. You need to find the shortest path from node `U` to node `V` in terms of the sum of weights of the edges...
import heapq import sys from collections import defaultdict def dijkstra(graph, start, n): """Function to execute Dijkstra's algorithm on the graph from a starting node.""" distances = {node: float('infinity') for node in range(1, n + 1)} distances[start] = 0 priority_queue = [(0, start)] whil...
def test_solve_shortest_paths_example(): n = 4 m = 4 edges = [ (1, 2, 3), (2, 3, 4), (3, 4, 2), (1, 4, 10), ] q = 3 queries = [ (1, 4), (1, 3), (2, 4), ] expected = [9, 7, 6] assert solve_shortest_paths(n, m, edges, q, queries) ...
[ { "docstring": "Function to execute Dijkstra's algorithm on the graph from a starting node.", "function_declaration": "def dijkstra(graph, start, n):", "function_name": "dijkstra", "parameter_list": "(graph, start, n)" }, { "docstring": null, "function_declaration": "def solve_shortest_p...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl", "solution_code": "import heapq\n\ndef dijkstra(graph, start, n):\n \"\"\"\n Implements Dijkstra's algorithm to find the shortest path from the starting node to all other nodes...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00099977", "row_id": 99977, "seed_ids": "[20936]" }
0.888198
Taco_99977
I
[ "dijkstra", "solve_shortest_paths" ]
2
[ [ "solve_shortest_paths", "dijkstra" ] ]
1
[]
false
[]
false
pytest
false
[]
true
cc8c30fbc74dca962b2d7d12eb85ac932bf4a604
6964f316c185a27849d93f4e484e4b80f840a165
v1.0
instruct
Taco
Taco_99981_I
Sarah is fascinated by palindromic numbers and decides to create new palindromic numbers by summing numbers and their reversals. She starts with any positive integer and adds it to its reverse. If the sum is a palindrome, she stops; otherwise, she repeats the process with the new sum until a palindrome is obtained. Som...
def reverse_number(n): return int(str(n)[::-1]) def is_palindrome(n): return str(n) == str(n)[::-1] def num_additions_for_palindrome(T, cases): results = [] for P in cases: count = 0 while count < 1000: if is_palindrome(P): break P = P + rev...
from solution import num_additions_for_palindrome def test_basics(): assert num_additions_for_palindrome(1, [56]) == [1] assert num_additions_for_palindrome(1, [89]) == [24] assert num_additions_for_palindrome(2, [56, 89]) == [1, 24] def test_small_palindromes(): assert num_additions_for_palindrome(1,...
[ { "docstring": null, "function_declaration": "def reverse_number(n):", "function_name": "reverse_number", "parameter_list": "(n)" }, { "docstring": null, "function_declaration": "def is_palindrome(n):", "function_name": "is_palindrome", "parameter_list": "(n)" }, { "docst...
[ 1, 0, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_palindrome(n):\n return str(n) == str(n)[::-1]\n\ndef num_additions_for_palindrome(T, cases):\n results = []\n \n for P in cases:\n steps...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00099981", "row_id": 99981, "seed_ids": "[3567]" }
0.705446
Taco_99981
I
[ "reverse_number", "is_palindrome", "num_additions_for_palindrome" ]
3
[ [ "num_additions_for_palindrome", "is_palindrome" ], [ "num_additions_for_palindrome", "reverse_number" ] ]
2
[]
false
[]
false
pytest
true
[]
true
1d0ec0f3473c679ecf152bf709306bd19cddc4d1
5e89deb111b8a2be42082fb2c33d173f9ac70737
v1.0
instruct
Codeforces
Codeforces_20_I
You are given a binary tree with `n` nodes. Each node has a value v_i associated with it. The value of the root node is v_1, its left child (if it exists) is v_2, its right child (if it exists) is v_3, and so on in a level-order traversal. Your task is to perform `q` queries on this binary tree. Each query asks you to...
def calculate_subtree_sums(n, values): """ Precompute the subtree sums using a DFS approach. Args: n: number of nodes values: list of values of the nodes Returns: subtree_sum: list where subtree_sum[i] is the sum of values in the subtree rooted at node i+1 """ subtree_sum = valu...
import pytest from solution import subtree_query_sum def test_example_case(): n = 5 q = 3 values = [1, 2, 3, 4, 5] queries = [1, 2, 3] expected_output = [15, 11, 3] assert subtree_query_sum(n, q, values, queries) == expected_output def test_single_node(): n = 1 q = 1 values = [10] ...
[ { "docstring": "Precompute the subtree sums using a DFS approach.\nArgs:\nn: number of nodes\nvalues: list of values of the nodes\n\nReturns:\nsubtree_sum: list where subtree_sum[i] is the sum of values in the subtree rooted at node i+1", "function_declaration": "def calculate_subtree_sums(n, values):", ...
[ 1, 0, 0, 1, 0, 0, 0, 1, 0, 0 ]
3
hard
0.3
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def calculate_subtree_sums(n, values, queries):\n from collections import defaultdict, deque\n \n # Construct tree from level order values\n child...
trial_gpt4o_7
{ "original_instruction": "", "prompt_id": "00000020", "row_id": 20, "seed_ids": "[5764]" }
0.619057
Codeforces_20
I
[ "calculate_subtree_sums", "subtree_query_sum" ]
2
[ [ "subtree_query_sum", "calculate_subtree_sums" ] ]
1
[]
false
[]
false
pytest
true
[]
true
7de38addfc26be2d39eb2fb7769f716da33f0e60
395527ae6f123820d52c1060b85a382d73fd8a14
v1.0
instruct
Codeforces
Codeforces_50_I
Steve is learning graph theory and wants to explore the shortest paths in an undirected weighted graph. The graph has cities connected by roads, and weights represent the travel time between each pair of cities. He is particularly interested in whether there is a unique shortest path between two specific cities, A and ...
import heapq def dijkstra(graph, start, n): """ Returns the shortest distance from start to all other nodes and number of ways to reach each node. """ dist = {i: float('inf') for i in range(1, n + 1)} dist[start] = 0 ways = {i: 0 for i in range(1, n + 1)} ways[start] = 1 pq = [(0, start)] ...
def test_shortest_path_unique(): n = 4 m = 4 a = 1 b = 4 edges = [(1, 2, 1), (2, 3, 2), (3, 4, 1), (1, 3, 4)] assert shortest_path(n, m, a, b, edges) == 4 def test_shortest_path_ambiguous(): n = 4 m = 4 a = 1 b = 4 edges = [(1, 2, 1), (2, 3, 2), (3, 4, 1), (1, 4, 4)] ass...
[ { "docstring": "Returns the shortest distance from start to all other nodes and number of ways to reach each node. ", "function_declaration": "def dijkstra(graph, start, n):", "function_name": "dijkstra", "parameter_list": "(graph, start, n)" }, { "docstring": null, "function_declaration...
[ 0, 0, 1, 0, 0, 0, 1, 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": "import heapq\n\ndef shortest_path_unique(n, m, A, B, edges):\n graph = [[] for _ in range(n + 1)]\n for u, v, w in edges:\n graph[u].append((v, w...
trial_gpt4o_6
{ "original_instruction": "", "prompt_id": "00000050", "row_id": 50, "seed_ids": "[6452]" }
0.785623
Codeforces_50
I
[ "dijkstra", "shortest_path" ]
2
[ [ "shortest_path", "dijkstra" ] ]
1
[]
false
[]
false
pytest
false
[]
true
8292011813ff85aca7f914a1aaa54a64c28e49c6
0c32104a17a4ddaff2f4941807568d5cf4182a30
v1.0
instruct
Codeforces
Codeforces_70_I
You are given an array of integers representing the number of pages in several books arranged in a linear order on a bookshelf. You want to allocate these books to students such that each student gets at least one book, and the maximum number of pages allocated to a student is minimized. You need to find the minimum po...
def is_valid_distribution(pages, k, max_pages): students_required = 1 current_pages_sum = 0 for page in pages: if current_pages_sum + page > max_pages: students_required += 1 current_pages_sum = page if students_required > k: return False ...
from solution import find_min_max_pages def test_example_case(): assert find_min_max_pages(2, [12, 34, 67, 90]) == 113 def test_single_student(): assert find_min_max_pages(1, [12, 34, 67, 90]) == 203 # Sum of all pages def test_equal_number_of_students_and_books(): assert find_min_max_pages(4, [12, 34, ...
[ { "docstring": null, "function_declaration": "def is_valid_distribution(pages, k, max_pages):", "function_name": "is_valid_distribution", "parameter_list": "(pages, k, max_pages)" }, { "docstring": null, "function_declaration": "def find_min_max_pages(k, pages):", "function_name": "f...
[ 0, 0, 1, 0, 0, 1, 0, 0, 0, 0 ]
2
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def find_min_maximum_pages(k, pages):\n def is_possible(mid):\n students_required = 1\n current_sum = 0\n\n for page in pages:\n ...
trial_gpt4o_5
{ "original_instruction": "", "prompt_id": "00000070", "row_id": 70, "seed_ids": "[1396]" }
0.70476
Codeforces_70
I
[ "is_valid_distribution", "find_min_max_pages" ]
2
[ [ "find_min_max_pages", "is_valid_distribution" ] ]
1
[]
false
[]
false
pytest
true
[]
true
bec2c37b1ad4cdad9f29459d4a71aeb34e0b932a
26b73ca0ef7d55b8ef871a98143d607d365a0cb4
v1.0
instruct
Codeforces
Codeforces_110_I
Marcus is organizing a robot race event. Each robot participates in a race on a different day. Robot races are held over $$$k$$$ consecutive days. Marcus wants to ensure there's enough charging time for all the robots and minimize the maximum fatigue any robot can experience. The fatigue of a robot performing on day $...
def minimize_max_fatigue(n, k, r): """ This function assigns each robot a day such that the maximum fatigue is minimized. The assignment minimizes |d_i - r_i| for given n robots and k days. Args: - n (int): The number of robots. - k (int): The number of consecutive days. - r (list): Lis...
from solution import minimize_max_fatigue def test_simple_case(): assert minimize_max_fatigue(5, 5, [1, 2, 3, 4, 5]) == 0 def test_no_optimal_match(): assert minimize_max_fatigue(3, 3, [1, 1, 3]) == 1 def test_equal_optimal_days(): assert minimize_max_fatigue(3, 3, [2, 2, 2]) == 1 def test_large_case():...
[ { "docstring": "This function assigns each robot a day such that the maximum fatigue is minimized.\nThe assignment minimizes |d_i - r_i| for given n robots and k days.\n\nArgs:\n- n (int): The number of robots.\n- k (int): The number of consecutive days.\n- r (list): List of integers where r[i] is the optimal 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_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def minimize_maximum_fatigue(n, k, r):\n \"\"\"\n Returns minimum possible maximum fatigue experienced by any robot.\n \"\"\"\n \n # Step 1: So...
trial_gpt4o_7
{ "original_instruction": "", "prompt_id": "00000110", "row_id": 110, "seed_ids": "[3736]" }
0.711055
Codeforces_110
I
[ "minimize_max_fatigue", "can_assign_days" ]
2
[ [ "minimize_max_fatigue", "can_assign_days" ] ]
1
[]
false
[]
false
pytest
true
[]
true
cb5ae04c86b5aeb77691097067f231a6de9328e9
6975dc06bc6bdbd8ded35e544497751fb0c65b92
v1.0
instruct
Codeforces
Codeforces_122_I
You are given n pairs of integers representing the coordinates of points in 2D space. Your task is to find the two closest points and calculate the Euclidean distance between them. The first line contains an integer n (2 ≤ n ≤ 5000), the number of points. Each of the next n lines contains two integers xi and yi (|xi|,...
import math def euclidean_distance(p1, p2): """ Compute the Euclidean distance between two points p1 and p2. Each point is represented as a tuple (x, y). """ return math.sqrt((p2[0] - p1[0])**2 + (p2[1] - p1[1])**2) def closest_pair(points): """ Find the closest pair of points in a list of...
from solution import find_closest_distance def test_find_closest_distance_1(): n = 4 coordinates = ["0 0", "0 3", "4 0", "3 4"] result = find_closest_distance(n, coordinates) assert math.isclose(result, 3.000000, rel_tol=1e-6) def test_find_closest_distance_2(): n = 2 coordinates = ["1 1", "4 ...
[ { "docstring": "Compute the Euclidean distance between two points p1 and p2.\nEach point is represented as a tuple (x, y).", "function_declaration": "def euclidean_distance(p1, p2):", "function_name": "euclidean_distance", "parameter_list": "(p1, p2)" }, { "docstring": "Find the closest pair...
[ 1, 1, 1, 0, 1, 0, 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 math\n\ndef euclidean_distance(p1, p2):\n \"\"\"\n Returns the Euclidean distance between points p1 and p2.\n \"\"\"\n return math.sqrt((p1...
trial_gpt4o_7
{ "original_instruction": "", "prompt_id": "00000122", "row_id": 122, "seed_ids": "[4681]" }
0.700541
Codeforces_122
I
[ "euclidean_distance", "closest_pair", "find_closest_distance" ]
3
[ [ "closest_pair", "euclidean_distance" ], [ "find_closest_distance", "closest_pair" ] ]
2
[]
false
[]
false
pytest
true
[]
true
cd0758abeb9a17be3802e58a751c6374d196a9b8
5f5d375ff8b707806d8cdd6dcafdffd588e5d573
v1.0
instruct
Codeforces
Codeforces_137_I
An increasingly popular challenge in the programming world nowadays is to detect palindromes within strings. A **palindrome** is a word, phrase, or sequence of characters that reads the same backward as forward, ignoring spaces, punctuation, and capitalization. You are tasked with writing a function to detect all uni...
def find_unique_palindromic_substrings(s): """ Finds all unique palindromic substrings in a given string `s`. Parameters: s (str): The input string. Returns: list: Sorted list of unique palindromic substrings. """ def is_palindrome(sub): return sub == sub[::-1] n = len...
from solution import find_unique_palindromic_substrings def test_single_character_string(): assert find_unique_palindromic_substrings("a") == [] def test_no_palindromes(): assert find_unique_palindromic_substrings("abc") == [] def test_two_character_palindromes(): assert find_unique_palindromic_substring...
[ { "docstring": "Finds all unique palindromic substrings in a given string `s`.\n\nParameters:\ns (str): The input string.\n\nReturns:\nlist: Sorted list of unique palindromic substrings.", "function_declaration": "def find_unique_palindromic_substrings(s):", "function_name": "find_unique_palindromic_sub...
[ 0, 0, 0, 0, 1, 0, 0, 0, 0, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def find_unique_palindromic_substrings(s):\n \"\"\"\n Returns unique palindromic substrings and their count from the given string s.\n \"\"\"\n de...
trial_gpt4o_4
{ "original_instruction": "", "prompt_id": "00000137", "row_id": 137, "seed_ids": "[2817]" }
0.74359
Codeforces_137
I
[ "find_unique_palindromic_substrings", "print_palindromic_substrings" ]
2
[ [ "print_palindromic_substrings", "find_unique_palindromic_substrings" ] ]
1
[]
false
[]
false
pytest
true
[]
true
ba78529766c254859e7569a0c39e9a81adef2e13
4673c58246bbfab24d3a7d2aeebac04aebf1aef9
v1.0
instruct
Codeforces
Codeforces_170_I
A treasure hunter is exploring a haunted mansion where each room is connected by corridors. The mansion consists of $$$n$$$ rooms, and each pair of rooms is connected by a corridor that can either be open or closed. The entrance to the mansion is at room $$$1$$$, and the treasure is located in room $$$n$$$. Whenever t...
from collections import deque def bfs_minimum_corridors(n, adj_list): """ Apply BFS to find the minimum path from room 1 to room n. """ # This will store the minimum number of corridors from room 1 to room i. distances = [-1] * (n + 1) distances[1] = 0 # This will store the path to ...
from solution import find_treasure_path def test_no_corridors(): assert find_treasure_path(3, []) == -1 def test_simple_case(): n = 6 corridors = [(1, 2), (2, 3), (3, 6)] assert find_treasure_path(n, corridors) == (3, [1, 2, 3, 6]) def test_more_complex_case(): n = 6 corridors = [(1, 2), (1, ...
[ { "docstring": "Apply BFS to find the minimum path from room 1 to room n.", "function_declaration": "def bfs_minimum_corridors(n, adj_list):", "function_name": "bfs_minimum_corridors", "parameter_list": "(n, adj_list)" }, { "docstring": "Find the shortest path from room 1 to room n in the ha...
[ 0, 1, 0, 1, 0, 1, 1, 0, 1, 0 ]
5
medium
0.5
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "from collections import deque, defaultdict\n\ndef find_treasure_path(n, m, corridors):\n if n == 2 and not corridors:\n print(\"-1\")\n retur...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00000170", "row_id": 170, "seed_ids": "[7266]" }
0.701988
Codeforces_170
I
[ "bfs_minimum_corridors", "find_treasure_path" ]
2
[ [ "find_treasure_path", "bfs_minimum_corridors" ] ]
1
[]
false
[]
false
pytest
true
[]
true
4950c36aa01c8175a36082668642bc77fc61095f
f92556f152cdba408accf89dc26f8d23e71358f3
v1.0
instruct
Codeforces
Codeforces_318_I
You are given a grid of size $$$n \times m$$$, filled with non-negative integers. Your task is to find the shortest path from the top-left corner (0, 0) to the bottom-right corner (n-1, m-1) such that the sum of the integers along the path is minimized. You can only move right or down at each step. Print the sum of th...
def min_path_sum(grid): n = len(grid) m = len(grid[0]) # Initialize DP table and path tracker dp = [[float('inf')] * m for _ in range(n)] dp[0][0] = grid[0][0] path = [[[] for _ in range(m)] for _ in range(n)] path[0][0] = [(0, 0)] for i in range(n): for j in range(m): ...
from solution import solve def test_case_1(): grid = [ [1, 3, 1], [1, 5, 1], [4, 2, 1] ] result = solve(grid) expected = "7\n(0, 0), (0, 1), (0, 2), (1, 2), (2, 2)" assert result == expected def test_case_2(): grid = [ [1, 2], [1, 1] ] result = s...
[ { "docstring": null, "function_declaration": "def min_path_sum(grid):", "function_name": "min_path_sum", "parameter_list": "(grid)" }, { "docstring": null, "function_declaration": "def solve(grid):", "function_name": "solve", "parameter_list": "(grid)" } ]
[ 0, 0, 0, 1, 0, 1, 0, 0, 0, 0 ]
2
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def min_path_sum(grid):\n n = len(grid)\n m = len(grid[0])\n \n dp = [[0] * m for _ in range(n)]\n dp[0][0] = grid[0][0]\n \n for i in ra...
trial_gpt4o_5
{ "original_instruction": "", "prompt_id": "00000318", "row_id": 318, "seed_ids": "[1911]" }
0.719536
Codeforces_318
I
[ "min_path_sum", "solve" ]
2
[ [ "solve", "min_path_sum" ] ]
1
[]
false
[]
false
pytest
true
[]
true
8e856dfdca2bfa33ee0f08eb4fb06a4878b50468
c952f09ecfc7fadedf46708c1d2f5e53a3a6b9c3
v1.0
instruct
Codeforces
Codeforces_393_I
Your task involves calculating some properties on a sequence of numbers. A sequence of integers is given, and you need to handle several queries, each asking you to determine the minimum value in a specific subarray of the sequence. ### Input - The first line contains two integers `n` and `q` ($$1 \leq n, q \leq 200,0...
def preprocess_min_values(arr): """ Preprocess the input array to allow efficient querying for the minimum value in any subarray. Using a Sparse Table for Range Minimum Query (RMQ). """ import math n = len(arr) log = int(math.log2(n)) + 1 st = [[0] * log for _ in range(n)] for i in ...
import math def test_preprocess_min_values(): arr = [1, 3, 4, 2, 5] st = preprocess_min_values(arr) assert st[0][0] == 1 assert st[1][0] == 3 assert st[2][0] == 4 assert st[3][0] == 2 assert st[4][0] == 5 assert st[0][1] == 1 assert st[1][1] == 3 assert st[2][1] == 2 assert...
[ { "docstring": "Preprocess the input array to allow efficient querying for the minimum value in any subarray.\nUsing a Sparse Table for Range Minimum Query (RMQ).", "function_declaration": "def preprocess_min_values(arr):", "function_name": "preprocess_min_values", "parameter_list": "(arr)" }, {...
[ 1, 0, 1, 1, 0, 1, 1, 1, 1, 1 ]
8
easy
0.8
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "class RangeMinimumQuery:\n def __init__(self, arr):\n self.n = len(arr)\n self.arr = arr\n self.sparse_table = []\n self.log = ...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00000393", "row_id": 393, "seed_ids": "[2253]" }
0.756305
Codeforces_393
I
[ "preprocess_min_values", "query_min", "min_in_subarrays" ]
3
[ [ "min_in_subarrays", "preprocess_min_values" ], [ "min_in_subarrays", "query_min" ] ]
2
[]
false
[]
false
pytest
false
[]
true
b8f1c910024413a7ddf5918aba03e5379bfaa5a7
4c9b1beb55a4efd5c5adc12c8c22ad7b2f3ad85c
v1.0
instruct
Codeforces
Codeforces_411_I
Company XYZ has a popular online multiplayer game and they are planning to introduce a new feature called "Guild War Challenges". In this feature, guilds of players compete against each other in various challenges. Each guild can have varying numbers of members, and each member has a certain skill level. To determine...
from collections import defaultdict import bisect class Guild: def __init__(self): self.members = [] def add_member(guilds, g, s): if g not in guilds: guilds[g] = Guild() bisect.insort(guilds[g].members, -s) def remove_member(guilds, g, s): if g in guilds: idx = bisect.bisect_...
def test_guild_war_challenges(): queries = [ "add 1 5000", "add 1 3000", "add 1 7000", "rank 1 2", "remove 1 5000", "rank 1 2", "add 2 4000", "rank 2 1" ] expected_output = [ 5000, 3000, 4000 ] assert p...
[]
[ 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": "from sortedcontainers import SortedList\nfrom collections import defaultdict, Counter\n\nclass GuildWarChallenge:\n def __init__(self):\n self.guild...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00000411", "row_id": 411, "seed_ids": "[734]" }
0.597292
Codeforces_411
I
[ "add_member", "remove_member", "get_ranked_member", "process_queries" ]
4
[ [ "process_queries", "add_member" ], [ "process_queries", "get_ranked_member" ], [ "process_queries", "remove_member" ] ]
3
[ "process_queries" ]
false
[ "Guild" ]
true
pytest
false
[]
true
71003dd31af8e3d711fd23e16d51ff5f8d91e846
3df7bba193ee1fa310d928e0ae62a380ebe299f9
v1.0
instruct
Codeforces
Codeforces_420_I
You are given a sequence of integers, and you are tasked with creating a new sequence where each element is derived from the sum of the digits of the corresponding element in the original sequence. The goal is to determine if the resulting sequence eventually reaches a point where all elements are equal. Write a funct...
from typing import List def sum_of_digits(n: int) -> int: """ Calculates the sum of the digits of an integer n. """ return sum(int(digit) for digit in str(n)) def all_elements_equal(lst: List[int]) -> bool: """ Checks if all elements in the list are equal. """ return all(x == lst[0] fo...
from solution import is_harmonious_sequence def test_harmonious_sequence_example(): sequence = [123, 456, 789] assert is_harmonious_sequence(sequence) == True def test_single_element_sequence(): sequence = [555] assert is_harmonious_sequence(sequence) == True def test_unequal_initially_becomes_equal(...
[ { "docstring": "Calculates the sum of the digits of an integer n.", "function_declaration": "def sum_of_digits(n):", "function_name": "sum_of_digits", "parameter_list": "(n)" }, { "docstring": "Checks if all elements in the list are equal.", "function_declaration": "def all_elements_equa...
[ 0, 0, 0, 0, 1, 0, 0, 0, 0, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "from typing import List\n\ndef sum_of_digits(n: int) -> int:\n return sum(int(digit) for digit in str(n))\n\ndef is_harmonious_sequence(sequence: List[int]...
trial_gpt4o_4
{ "original_instruction": "", "prompt_id": "00000420", "row_id": 420, "seed_ids": "[4920]" }
0.633536
Codeforces_420
I
[ "sum_of_digits", "all_elements_equal", "is_harmonious_sequence" ]
3
[ [ "is_harmonious_sequence", "all_elements_equal" ], [ "is_harmonious_sequence", "sum_of_digits" ] ]
2
[]
false
[]
false
pytest
true
[]
true
998d7199ed1efb8bd748f8aa5860950c6bab4e10
da9e83c0e9018b6467b7136601e8505869f53859
v1.0
instruct
Codeforces
Codeforces_455_I
You are given a string consisting of lowercase letters and a dictionary containing several words. Your task is to determine the minimum number of characters you need to insert into the given string so that it contains all the words from the dictionary as subsequences. A subsequence of a string is a new string generate...
def is_subsequence(s, word): it = iter(s) return all(char in it for char in word) def min_inserts_to_form_subsequences(s, dictionary): def min_insertions(s, word): m, n = len(s), len(word) dp = [[0] * (n + 1) for _ in range(m + 1)] for i in range(m + 1): for j in range(...
def test_example_1(): s = "abc" dictionary = ["ab", "bc", "ac"] assert min_inserts_to_form_subsequences(s, dictionary) == 0 def test_example_2(): s = "abc" dictionary = ["abcd", "aef"] assert min_inserts_to_form_subsequences(s, dictionary) == 4 def test_single_insertion(): s = "a" ...
[ { "docstring": null, "function_declaration": "def is_subsequence(s, word):", "function_name": "is_subsequence", "parameter_list": "(s, word)" }, { "docstring": null, "function_declaration": "def min_inserts_to_form_subsequences(s, dictionary):", "function_name": "min_inserts_to_form_...
[ 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 typing import List\n\ndef min_inserts_to_form_subsequences(s: str, dictionary: List[str]) -> int:\n def min_insertions_for_subsequence(s: str, word: s...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00000455", "row_id": 455, "seed_ids": "[2761]" }
0.774122
Codeforces_455
I
[ "is_subsequence", "min_inserts_to_form_subsequences" ]
2
[ [ "min_inserts_to_form_subsequences", "is_subsequence" ] ]
1
[]
false
[]
false
pytest
false
[]
true
63e56ae12de079a25fda1f26e0dfbbd1a7791f77
d0fb87e822616a03c2bc16689728d45e05bb062e
v1.0
instruct
Codeforces
Codeforces_460_I
You are given a list of integers, and you want to form the maximum possible number by concatenating them. Write a function that takes a list of non-negative integers and returns the largest integer that can be formed by concatenating their string representations. The input integers can range from 0 to 10^9. The first ...
from functools import cmp_to_key def compare(x, y): """ Custom comparator function to determine the order of two strings x and y by comparing their concatenated results in both possible orders. """ if x + y > y + x: return -1 elif x + y < y + x: return 1 else: retur...
from solution import largest_concatenated_number def test_example(): assert largest_concatenated_number([3, 30, 34, 5, 9]) == '9534330' def test_single_element(): assert largest_concatenated_number([1]) == '1' def test_multiple_zeros(): assert largest_concatenated_number([0, 0, 0]) == '0' def test_l...
[ { "docstring": "Custom comparator function to determine the order of two strings \nx and y by comparing their concatenated results in both possible orders.", "function_declaration": "def compare(x, y):", "function_name": "compare", "parameter_list": "(x, y)" }, { "docstring": "Takes a list o...
[ 0, 0, 0, 1, 0, 0, 0, 1, 1, 1 ]
4
medium
0.4
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "from functools import cmp_to_key\n\ndef largest_concatenated_number(nums):\n \"\"\"\n Returns the largest concatenated number that can be formed by the ...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00000460", "row_id": 460, "seed_ids": "[1335]" }
0.713016
Codeforces_460
I
[ "compare", "largest_concatenated_number" ]
2
[ [ "largest_concatenated_number", "compare" ] ]
1
[]
false
[]
false
pytest
true
[]
true
f26aa0ddb5175bd13310d90aea5d3230acf42cd1
3b22a29d9439d8abdc82a0e4254fd3fdd258f60b
v1.0
instruct
Codeforces
Codeforces_531_I
ZooKeeper at the Wonderland Zoo is tasked with organizing the feeding schedule for different animals. The zoo has different species of animals, and each species has a name that must be sorted in a specific lexicographical order. However, some species names can conflict with the traditional alphabetical order. The ZooK...
from collections import defaultdict, deque def find_order_of_alphabet(species_names): """ Determine a valid permutation of the alphabet letters such that the given species names are sorted in lexicographical order based on this permutation. If such an order does not exist, return "Impossible". """ ...
from solution import solve def test_possible_order(): input_text = """4 bunny bear banana cat""" output = solve(input_text) assert output != "Impossible" def test_no_possible_order(): input_text = """3 abc ab""" output = solve(input_text) assert output == "Impossible" def test_single_species_...
[ { "docstring": "Determine a valid permutation of the alphabet letters such that the given species names\nare sorted in lexicographical order based on this permutation. If such an order does not\nexist, return \"Impossible\".", "function_declaration": "def find_order_of_alphabet(species_names):", "functi...
[ 0, 0, 0, 1, 0, 0, 0, 0, 1 ]
2
hard
0.222
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "from collections import deque, defaultdict\n\ndef find_order(words):\n \"\"\"\n Determines a valid custom order of the alphabet given a list of words so...
trial_gpt4o_3
{ "original_instruction": "", "prompt_id": "00000531", "row_id": 531, "seed_ids": "[2018]" }
0.745483
Codeforces_531
I
[ "find_order_of_alphabet", "solve" ]
2
[ [ "solve", "find_order_of_alphabet" ] ]
1
[]
false
[]
false
pytest
true
[]
true
917bb5120376e62284f93bcca2f9ef55ab2472f5
5069d352d3c34d18c508fc31103ef0292dd370a6
v1.0
instruct
Codeforces
Codeforces_585_I
You are given a series of events in a calendar, where each event is represented by a start time and an end time. The times are given in 24-hour format (e.g., 13:00 for 1 PM). Your task is to find the maximum number of events you can attend if you can only attend one event at a time. Two events overlap if the end time o...
from typing import List, Tuple def parse_time(time: str) -> int: """Converts time from HH:MM format to minutes since the start of the day.""" hours, minutes = map(int, time.split(':')) return hours * 60 + minutes def parse_event(event: str) -> Tuple[int, int]: """Parses an event string in the format '...
from solution import max_events def test_max_events_example(): assert max_events(["09:00-10:30", "10:15-11:30", "11:00-12:00"]) == 2 def test_max_events_no_overlap(): assert max_events(["09:00-10:00", "10:00-11:00", "11:00-12:00"]) == 3 def test_max_events_all_overlap(): assert max_events(["09:00-11:00",...
[ { "docstring": "Converts time from HH:MM format to minutes since the start of the day.", "function_declaration": "def parse_time(time):", "function_name": "parse_time", "parameter_list": "(time)" }, { "docstring": "Parses an event string in the format 'HH:MM-HH:MM' to a tuple of start and en...
[ 0, 0, 0, 1, 0, 1, 1, 1, 0, 0 ]
4
medium
0.4
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def to_minutes(time_str):\n hours, minutes = map(int, time_str.split(':'))\n return hours * 60 + minutes\n\ndef can_attend_all(events):\n events.sort...
trial_gpt4o_7
{ "original_instruction": "", "prompt_id": "00000585", "row_id": 585, "seed_ids": "[3932]" }
0.632691
Codeforces_585
I
[ "parse_time", "parse_event", "max_events" ]
3
[ [ "max_events", "parse_event" ], [ "parse_event", "parse_time" ] ]
2
[]
false
[]
false
pytest
true
[]
true
33d749191401700d8b24c4255754536abf700a53
e0990e5d65914ab8f811550a4c587bac1febc551
v1.0
instruct
Codeforces
Codeforces_594_I
You are given an integer array `nums` containing `n` distinct elements. Your task is to reorder the array such that each `nums[i]` is less than `nums[i+2]` (for every valid `i`). If there are multiple solutions, you can output any of them. If it is not possible to achieve the required ordering, return an empty array. ...
def reorder_array(nums): n = len(nums) if n == 0: return [] nums.sort() mid = (n + 1) // 2 left = nums[:mid] right = nums[mid:] result = [] for i in range(len(left)): result.append(left[i]) if i < len(right): result.append(right[i]) ...
def test_reorder_array(): assert reorder(5, [4, 1, 3, 2, 5]) == [1, 4, 2, 5, 3] or reorder(5, [4, 1, 3, 2, 5]) == [1, 3, 2, 5, 4] assert reorder(4, [4, 1, 3, 2]) == [1, 3, 2, 4] or reorder(4, [4, 1, 3, 2]) == [1, 4, 2, 3] assert reorder(3, [3, 1, 2]) == [1, 3, 2] assert reorder(2, [2, 1]) == [1, 2] or r...
[ { "docstring": null, "function_declaration": "def reorder_array(nums):", "function_name": "reorder_array", "parameter_list": "(nums)" }, { "docstring": null, "function_declaration": "def reorder(n, nums):", "function_name": "reorder", "parameter_list": "(n, nums)" } ]
[ 1, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def reorder_array(nums):\n n = len(nums)\n \n if n == 0:\n return []\n\n nums.sort()\n \n mid = (n + 1) // 2\n left = nums[:mid]\n...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00000594", "row_id": 594, "seed_ids": "[4422]" }
0.707541
Codeforces_594
I
[ "reorder_array", "reorder" ]
2
[ [ "reorder", "reorder_array" ] ]
1
[]
false
[]
false
pytest
false
[]
true
9634fe5a712163018fccb57a5885aef64027b424
ecfcb5e7a05db528415e617433745dc86714f163
v1.0
instruct
Codeforces
Codeforces_611_I
You've got a list of n integers. You need to find a pair of numbers such that the absolute difference between these two numbers is minimized. Furthermore, both these numbers need to be distinct and located at different indices in the original list. The first line of the input is an integer n (2 ≤ n ≤ 10^5), representi...
def find_min_abs_difference(nums): """ Given a list of integers, returns the smallest possible absolute difference between any pair of distinct numbers located at different indices. """ nums_sorted = sorted(nums) min_diff = float('inf') for i in range(len(nums_sorted) - 1): min_...
from solution import smallest_abs_difference def test_smallest_abs_difference(): assert smallest_abs_difference(4, [1, 5, 3, 19]) == 2 assert smallest_abs_difference(5, [10, 10, 10, 10, 10]) == 0 assert smallest_abs_difference(6, [8, 1, 9, 4, 6, 19]) == 1 assert smallest_abs_difference(2, [1, 2]) == 1 ...
[ { "docstring": "Given a list of integers, returns the smallest possible absolute difference\nbetween any pair of distinct numbers located at different indices.", "function_declaration": "def find_min_abs_difference(nums):", "function_name": "find_min_abs_difference", "parameter_list": "(nums)" }, ...
[ 1, 1, 1, 0, 1, 1, 0, 0, 1 ]
6
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def minimum_absolute_difference(arr):\n \"\"\"\n Returns the minimum absolute difference between any two distinct elements in the list.\n \"\"\"\n ...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00000611", "row_id": 611, "seed_ids": "[2312]" }
0.826842
Codeforces_611
I
[ "find_min_abs_difference", "smallest_abs_difference" ]
2
[ [ "smallest_abs_difference", "find_min_abs_difference" ] ]
1
[]
false
[]
false
pytest
true
[]
true
42144683c6a92e9251a7c26a94b04c666ba00f9a
3217fc9848cad63cb718068b93140c2e54e814a5
v1.0
instruct
Codeforces
Codeforces_619_I
Konatsu is designing a new social media app that allows users to tag their friends in posts. Every post can have multiple friends tagged, and tagging can only be done if the friend accepts the tag request. The tagging system can be represented as a directed graph where each vertex represents a friend, and a directed ...
def find_connected_components(n, edges): from collections import defaultdict, deque graph = defaultdict(list) for u, v in edges: graph[u].append(v) graph[v].append(u) visited = [-1] * (n + 1) component_id = 0 def bfs(start): queue = deque([start]) v...
def test_connected_queries(): n = 5 edges = [ (1, 2), (2, 3), (3, 4), (4, 5) ] queries = [ (1, 5), (2, 4), (1, 3) ] expected_output = ["YES", "YES", "YES"] assert connected_queries(n, edges, queries) == expected_output def test_disconn...
[ { "docstring": null, "function_declaration": "def find_connected_components(n, edges):", "function_name": "find_connected_components", "parameter_list": "(n, edges)" }, { "docstring": null, "function_declaration": "def connected_queries(n, edges, queries):", "function_name": "connect...
[ 0, 1, 1, 1, 1, 1, 1, 1, 0 ]
7
easy
0.778
{ "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 solve_connectedness(n, m, connections, q, queries):\n def bfs(start, graph, reached):\n queue = de...
trial_gpt4o_7
{ "original_instruction": "", "prompt_id": "00000619", "row_id": 619, "seed_ids": "[5421]" }
0.722362
Codeforces_619
I
[ "find_connected_components", "connected_queries" ]
2
[ [ "connected_queries", "find_connected_components" ] ]
1
[]
false
[]
false
pytest
false
[]
true
566b5b8940c454c1d8b00eba10e59554d5a480e5
dd8ef0a655d81a6559cb2fb8dd0a1c0a15451100
v1.0
instruct
Codeforces
Codeforces_875_I
In a fictional kingdom, there are k castles connected by n bidirectional roads. Each road connects two distinct castles and can be traversed in both directions. The king wants to ensure that his troops can defend the entire kingdom efficiently by installing communication lines. However, there can only be one direct com...
def find(parent, i): if parent[i] == i: return i return find(parent, parent[i]) def union(parent, rank, x, y): root_x = find(parent, x) root_y = find(parent, y) if rank[root_x] > rank[root_y]: parent[root_y] = root_x elif rank[root_x] < rank[root_y]: parent[root_x] ...
def test_minimum_travel_time(): k = 4 n = 5 road_list = [ "1 2 3", "2 3 4", "3 4 5", "4 1 6", "2 4 2", ] assert minimum_travel_time(k, n, road_list) == 9 def test_only_one_road(): k = 2 n = 1 road_list = [ "1 2 1000", ] assert mini...
[ { "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, 0, 0, 0 ]
4
medium
0.4
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def kruskal_minimum_spanning_tree(k, n, roads):\n # Helper function to find the root of a set using path compression\n def find(parent, i):\n if ...
trial_gpt4o_6
{ "original_instruction": "", "prompt_id": "00000875", "row_id": 875, "seed_ids": "[5568]" }
0.713595
Codeforces_875
I
[ "find", "union", "kruskal_minimum_spanning_tree", "minimum_travel_time" ]
4
[ [ "kruskal_minimum_spanning_tree", "find" ], [ "kruskal_minimum_spanning_tree", "union" ], [ "minimum_travel_time", "kruskal_minimum_spanning_tree" ], [ "union", "find" ] ]
4
[]
false
[]
false
pytest
false
[]
true
27e841925538602060050510f7fdeb078519093f
7978210cba088e034017ed29d1edfbce034dc6bf
v1.0
instruct
Codeforces
Codeforces_890_I
Given an array of integers, your task is to rearrange the elements in such a way that they form the lexicographically smallest possible array. If the input array is already the smallest possible lexicographical order, then the next lexicographical permutation should be used instead. For example, if the input array is ...
def next_permutation(arr): """ Generate the next lexicographical permutation for the list `arr`. Args: arr (list): The list of integers. Returns: list: The next lexicographical permutation of the list. """ # 1. Find the largest index k such that arr[k] < arr[k + 1]. If no such ...
def test_smallest_order(): assert smallest_or_next_lexicographical_order([3, 1, 4, 2]) == [1, 2, 3, 4] assert smallest_or_next_lexicographical_order([2, 2, 1]) == [1, 2, 2] def test_next_permutation(): assert smallest_or_next_lexicographical_order([1, 2, 3, 4, 5]) == [1, 2, 3, 5, 4] assert smallest_or_...
[ { "docstring": "Generate the next lexicographical permutation for the list `arr`.\n\nArgs:\narr (list): The list of integers.\n\nReturns:\nlist: The next lexicographical permutation of the list.", "function_declaration": "def next_permutation(arr):", "function_name": "next_permutation", "parameter_l...
[ 1, 1, 1, 1, 1, 0, 0, 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 next_permutation(nums):\n \"\"\"\n Modifies list 'nums' to its next lexicographical permutation in-place.\n Returns True if the permutation is th...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00000890", "row_id": 890, "seed_ids": "[3457]" }
0.792558
Codeforces_890
I
[ "next_permutation", "smallest_or_next_lexicographical_order" ]
2
[ [ "smallest_or_next_lexicographical_order", "next_permutation" ] ]
1
[]
false
[]
false
pytest
false
[]
true
0f77aa3dedd5ea64afb1621e8bbd4b4e6dd2aa57
fa9f43bc823f10ea46e8acff1ad3e7c008825822
v1.0
instruct
Codeforces
Codeforces_908_I
In an ancient city, the local historian has discovered a fragmented set of inscriptions on stone tablets. Each tablet contains a sequence of lowercase English letters, but some characters are missing and replaced with the "_" symbol. The historian believes that by inserting letters in place of "_" in each tablet's sequ...
def count_matching_words(dictionary, fragment): """ Counts how many words from the dictionary can match the fragmented sequence by replacing underscores. """ def matches(word, fragment): if len(word) != len(fragment): return False for w_char, f_char in zip(word, fragment): ...
def test_single_word_match(): dictionary = ["alpha", "beta", "gamma"] fragment = "a__ha" result = count_matching_words(dictionary, fragment) assert result == 1 def test_multiple_word_match(): dictionary = ["alpha", "beta", "gamma"] fragment = "____a" result = count_matching_words(dictionary...
[ { "docstring": "Counts how many words from the dictionary can match the fragmented sequence by replacing underscores.", "function_declaration": "def count_matching_words(dictionary, fragment):", "function_name": "count_matching_words", "parameter_list": "(dictionary, fragment)" }, { "docstri...
[ 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 count_possible_words(dictionary, sequences):\n def match(sequence, word):\n if len(sequence) != len(word):\n return False\n fo...
trial_gpt4o_3
{ "original_instruction": "", "prompt_id": "00000908", "row_id": 908, "seed_ids": "[3085]" }
0.643764
Codeforces_908
I
[ "count_matching_words", "solve" ]
2
[ [ "solve", "count_matching_words" ] ]
1
[]
false
[]
false
pytest
false
[]
true
e1daf95907d8005bb4184638c0af99b922845f21
6410457a885e3a6626d2b2bf99a805f0e280a791
v1.0
instruct
Codeforces
Codeforces_919_I
You are given a convex polygon with n vertices. A convex polygon is defined as a polygon where all interior angles are less than 180 degrees, and each line segment between two vertices is inside or on the boundary of the polygon. The vertices are given in clockwise order. Your task is to determine if a given point P li...
def is_point_in_polygon(vertices, point): def on_segment(p, q, r): """Check if point q lies on segment pr""" if (q[0] <= max(p[0], r[0]) and q[0] >= min(p[0], r[0]) and q[1] <= max(p[1], r[1]) and q[1] >= min(p[1], r[1])): return True return False def orientation...
from solution import determine_point_status def test_inside(): assert determine_point_status(5, [(0,0),(4,0),(4,4),(0,4),(-1,2)], (2,2)) == "INSIDE" def test_outside(): assert determine_point_status(4, [(1,1),(3,1),(3,3),(1,3)], (4,4)) == "OUTSIDE" def test_boundary(): assert determine_point_status(4, [(...
[ { "docstring": null, "function_declaration": "def is_point_in_polygon(vertices, point):", "function_name": "is_point_in_polygon", "parameter_list": "(vertices, point)" }, { "docstring": null, "function_declaration": "def determine_point_status(n, vertices, point):", "function_name": ...
[ 1, 0, 0, 1, 1, 1, 1, 1, 1, 1 ]
8
easy
0.8
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_point_in_polygon(n, vertices, px, py):\n def is_on_segment(p, q, r):\n # Check if point r is on segment pq\n return (q[0] <= max(p[0],...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00000919", "row_id": 919, "seed_ids": "[4865]" }
0.637669
Codeforces_919
I
[ "is_point_in_polygon", "determine_point_status" ]
2
[ [ "determine_point_status", "is_point_in_polygon" ] ]
1
[]
false
[]
false
pytest
true
[]
true
02af6571bcbb9ec81b50eaf362e1ea31f18ad4e7
cfc408b2b7866c2477133c7eef3c7195f7c40506
v1.0
instruct
Codeforces
Codeforces_1002_I
Lea is organizing a charity marathon event. She wants to assign a set of runners to each checkpoint. Each checkpoint must have at least one runner and each runner must participate in exactly one checkpoint. However, the total number of runners at every checkpoint must either be a prime number or a power of two. Given ...
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 is_power_of_two(num): ...
from solution import max_checkpoints def test_one_runner(): assert max_checkpoints(1) == (1, [1]) def test_two_runners(): assert max_checkpoints(2) == (1, [2]) def test_three_runners(): assert max_checkpoints(3) == (1, [3]) def test_four_runners(): assert max_checkpoints(4) == (1, [4]) def test_mul...
[ { "docstring": null, "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": null, "function_declaration": "def is_power_of_two(num):", "function_name": "is_power_of_two", "parameter_list": "(num)" }, { "docst...
[ 0, 1, 0, 0, 0, 0, 0, 0, 0 ]
1
hard
0.111
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(num):\n \"\"\"Check if a number is prime.\"\"\"\n if num <= 1:\n return False\n if num <= 3:\n return True\n if num % 2...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00001002", "row_id": 1002, "seed_ids": "[2871]" }
0.599941
Codeforces_1002
I
[ "is_prime", "is_power_of_two", "max_checkpoints" ]
3
[ [ "max_checkpoints", "is_power_of_two" ], [ "max_checkpoints", "is_prime" ] ]
2
[]
false
[]
false
pytest
true
[]
true
5d32613e288e265a67ca4ef39d3362532cfdf6fe
51ce00ea396efeea0f6afd50b6e724786b8d6f76
v1.0
instruct
Codeforces
Codeforces_1007_I
Alice has recently learned about hash tables. She has a hash table that uses open addressing with linear probing to resolve collisions. This hash table supports the following operations: 1. `insert x`: Inserts integer `x` into the hash table. If `x` is already in the hash table, it ignores the insert. 2. `delete x`: ...
def make_consistent_log(n, operations): table = set() result = [] for operation in operations: op = operation.split() if op[0] == "insert": x = int(op[1]) if x not in table: table.add(x) result.append(operation) elif op[0] ...
from solution import make_consistent_log def test_sample_input_1(): operations = ["delete 3", "insert 4", "contains 4"] expected_output = ["insert 3", "delete 3", "insert 4", "contains 4"] assert make_consistent_log(3, operations) == expected_output def test_sample_input_2(): operations = ["contains 1...
[ { "docstring": null, "function_declaration": "def make_consistent_log(n, operations):", "function_name": "make_consistent_log", "parameter_list": "(n, operations)" }, { "docstring": null, "function_declaration": "def solve(n, operations):", "function_name": "solve", "parameter_li...
[ 1, 1, 0, 0, 0, 0, 1, 0, 0 ]
3
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "class HashTable:\n def __init__(self, size=100000):\n self.size = size\n self.table = [None] * size\n self.deleted = set()\n \n...
trial_gpt4o_6
{ "original_instruction": "", "prompt_id": "00001007", "row_id": 1007, "seed_ids": "[2690]" }
0.557449
Codeforces_1007
I
[ "make_consistent_log", "solve" ]
2
[ [ "solve", "make_consistent_log" ] ]
1
[]
false
[]
false
pytest
true
[]
true
f72c3f6e59dc617d90456455f1221c1ae7c9b8c3
a848c5ba8e745b8f7e6c8011f307c14d0f522367
v1.0
instruct
Codeforces
Codeforces_1038_I
You are given a series of shelves, each of which can hold a certain number of books. Each shelf can hold at most a[ind] books. You have several books to place into the shelves, and your goal is to fit all the books into the shelves while balancing the total weight evenly across the shelves to minimize the maximum weigh...
def canPlaceBooks(maxWeight, shelves, books): """ Helper function to check if all books can be placed such that no shelf exceeds maxWeight.""" shelf_capacities = shelves[:] current_shelf = 0 current_weight = 0 for book in books: if current_weight + book <= maxWeight: current...
from solution import minimumHeaviestLoad def test_case_1(): assert minimumHeaviestLoad(3, 5, [3, 2, 1], [4, 3, 2, 7, 1]) == 7 def test_case_2(): assert minimumHeaviestLoad(1, 3, [1], [1, 1, 1]) == 3 def test_case_3(): assert minimumHeaviestLoad(4, 5, [2, 2, 2, 2], [2, 2, 2, 2, 2]) == 4 def test_case...
[ { "docstring": "Helper function to check if all books can be placed such that no shelf exceeds maxWeight.", "function_declaration": "def canPlaceBooks(maxWeight, shelves, books):", "function_name": "canPlaceBooks", "parameter_list": "(maxWeight, shelves, books)" }, { "docstring": "Return the...
[ 0, 0, 0, 0, 0, 1, 0, 0, 0 ]
1
hard
0.111
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def canDistribute(books, shelves, mid):\n # List to capture the current weights on each shelf.\n current_shelves = [0] * len(shelves)\n\n for book in...
trial_gpt4o_5
{ "original_instruction": "", "prompt_id": "00001038", "row_id": 1038, "seed_ids": "[706]" }
0.684326
Codeforces_1038
I
[ "canPlaceBooks", "minimumHeaviestLoad" ]
2
[ [ "minimumHeaviestLoad", "canPlaceBooks" ] ]
1
[]
false
[]
false
pytest
true
[]
true
2dedaa25d16b99beae45bb7903be116375a17960
d7abf9f01b24a45884b17cebea077a99b9626c7f
v1.0
instruct
Codeforces
Codeforces_1224_I
An online bookstore keeps track of the books its customers read. Each time a customer reads a book, the bookstore logs the reading activity. The system stores all customers' reading activities in a logbook, which is a list of entries. Each entry contains a customer id and book id. Based on the logbook, the bookstore w...
def count_unique_books(logbook): """ Returns a dictionary where keys are customer ids and values are the number of unique books read by that customer. :param logbook: List of tuples, each tuple contains a customer id and a book id. :return: Dictionary with customer id as keys and number of uniq...
from solution import process_logbook def test_single_customer_multiple_books(): entries = [ "5", "1 10", "1 20", "1 30", "1 40", "1 10" ] assert process_logbook(entries) == {1: 4} def test_multiple_customers(): entries = [ "6", "1 10", ...
[ { "docstring": "Returns a dictionary where keys are customer ids and values are\nthe number of unique books read by that customer.\n\n:param logbook: List of tuples, each tuple contains a customer id and a book id.\n:return: Dictionary with customer id as keys and number of unique books as values.", "functi...
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
10
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def count_unique_books(logbook):\n from collections import defaultdict\n\n customer_books = defaultdict(set)\n\n for customer_id, book_id in logbook:...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00001224", "row_id": 1224, "seed_ids": "[4436]" }
0.620489
Codeforces_1224
I
[ "count_unique_books", "process_logbook" ]
2
[ [ "process_logbook", "count_unique_books" ] ]
1
[]
false
[]
false
pytest
true
[]
true
baee299c0c12941195f54ae94b3f028c223a24d3
b0acf08f79cec2d13a2c76bc2f7d79868eeac342
v1.0
instruct
Codeforces
Codeforces_1360_I
Given a list of words, find all anagram groups within the list. An anagram is a word formed by rearranging the letters of another, such as "listen" and "silent". The first line contains a single integer n (1 ≤ n ≤ 10000) — the total number of words in the list. The next n lines each contain a single word consisting o...
def find_anagram_groups(words): """ Given a list of words, find all anagram groups within the list. """ from collections import defaultdict anagrams = defaultdict(list) for word in words: sorted_word = ''.join(sorted(word)) anagrams[sorted_word].append(word) ...
from solution import find_anagram_groups, solve def test_find_anagram_groups_with_anagrams(): words = ["listen", "silent", "enlist", "inlets", "google"] result = find_anagram_groups(words) assert result == ["listen silent enlist inlets"] def test_find_anagram_groups_without_anagrams(): words = ["apple...
[ { "docstring": "Given a list of words, find all anagram groups within the list.", "function_declaration": "def find_anagram_groups(words):", "function_name": "find_anagram_groups", "parameter_list": "(words)" }, { "docstring": null, "function_declaration": "def solve(n, word_list):", ...
[ 1, 1, 1, 1, 0, 0, 0, 1, 1, 1 ]
7
easy
0.7
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def find_anagram_groups(words):\n from collections import defaultdict\n \n anagram_dict = defaultdict(list)\n \n # Group words by sorted tuple ...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00001360", "row_id": 1360, "seed_ids": "[4301]" }
0.59971
Codeforces_1360
I
[ "find_anagram_groups", "solve" ]
2
[ [ "solve", "find_anagram_groups" ] ]
1
[]
false
[]
false
pytest
true
[]
true
3a04056e9b73b7393fb33da737b8565b64da8c25
fd547f7b89de3e83d8f22cbe8dc8b24bcc8f5cfa
v1.0
instruct
Codeforces
Codeforces_1376_I
Create a function that calculates the 'beauty' of a string. The beauty of a character is defined as its position in the English alphabet (A is 1, B is 2, ..., Z is 26). The beauty of a string is the sum of the beauties of its characters. The function should also be able to take a list of strings and return the string ...
def char_beauty(c): """ Returns the beauty of a single character. """ return ord(c) - ord('A') + 1 def string_beauty(s): """ Returns the beauty of a string. """ return sum(char_beauty(c) for c in s) def max_beauty(input_data): """ If input_data is a single string, returns its b...
from solution import max_beauty def test_single_string(): assert max_beauty("ZEBRA") == 52 assert max_beauty("ABCDE") == 15 assert max_beauty("XYZ") == 75 def test_list_of_strings(): assert max_beauty(["APPLE", "ORANGE", "BANANA"]) == "ORANGE" assert max_beauty(["ABC", "XYZ", "MNO"]) == "XYZ" ...
[ { "docstring": "Returns the beauty of a single character.", "function_declaration": "def char_beauty(c):", "function_name": "char_beauty", "parameter_list": "(c)" }, { "docstring": "Returns the beauty of a string.", "function_declaration": "def string_beauty(s):", "function_name": "s...
[ 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 calculate_beauty(char):\n \"\"\"\n Calculate the beauty of a single character.\n \"\"\"\n return ord(char) - ord('A') + 1\n\ndef beauty_of_str...
trial_gpt4o_3
{ "original_instruction": "", "prompt_id": "00001376", "row_id": 1376, "seed_ids": "[2005]" }
0.705034
Codeforces_1376
I
[ "char_beauty", "string_beauty", "max_beauty" ]
3
[ [ "max_beauty", "string_beauty" ], [ "string_beauty", "char_beauty" ] ]
2
[]
false
[]
false
pytest
true
[]
true
bd4af36c8681ea9f418f680255a0383abe7efedb
9011d08fa75469a21bc4235378e7ae7ddd06d6b7
v1.0
instruct
Codeforces
Codeforces_1415_I
A software company MicronTech keeps track of important events happening within the day. However, due to an error, the timestamps of some of the events got corrupted. What remains is a list of events with partial information about the times. From the data, it's known that each event happened between specific hours (a ra...
def parse_time_range(time_range): start_time, end_time = time_range.split('-') start_hour, start_minute = map(int, start_time.split(':')) end_hour, end_minute = map(int, end_time.split(':')) return (start_hour, start_minute), (end_hour, end_minute) def min_hours_to_cover_events(n, events): time_slo...
from solution import min_hours_to_cover_events def test_single_event(): assert min_hours_to_cover_events(1, ["08:00-09:00: Meeting with team"]) == 1 def test_multiple_events_non_overlapping(): assert min_hours_to_cover_events(3, ["08:00-09:00: Meeting with team", "10:...
[ { "docstring": null, "function_declaration": "def parse_time_range(time_range):", "function_name": "parse_time_range", "parameter_list": "(time_range)" }, { "docstring": null, "function_declaration": "def min_hours_to_cover_events(n, events):", "function_name": "min_hours_to_cover_ev...
[ 0, 0, 0, 0, 1, 0, 0, 0, 0, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def min_hours_to_cover_events(n, events):\n \"\"\"\n Determines the minimum number of hours required to cover all the events recorded.\n\n :param n: ...
trial_gpt4o_4
{ "original_instruction": "", "prompt_id": "00001415", "row_id": 1415, "seed_ids": "[5983]" }
0.635729
Codeforces_1415
I
[ "parse_time_range", "min_hours_to_cover_events", "main" ]
3
[ [ "min_hours_to_cover_events", "parse_time_range" ] ]
1
[]
false
[]
false
pytest
true
[]
true
32ac5165ad9df143b874c299efd00d98c4e35e0e
dbff8e7ca07f8eca2bf97797271d153ac844856d
v1.0
instruct
Codeforces
Codeforces_1433_I
Write a function that takes a list of tuples as input, each containing start and end times of meetings (in the format (start_time, end_time)), and determines whether a person can attend all the meetings without overlap. The times are given as 24-hour format strings (e.g., "09:00"). The function should return `True` if...
from typing import List, Tuple def time_to_minutes(t: str) -> int: """ Convert a time string in the format 'HH:MM' to the number of minutes since 00:00. """ hours, minutes = map(int, t.split(':')) return hours * 60 + minutes def can_attend_meetings(meetings: List[Tuple[str, str]]) -> bool: """...
from solution import can_attend_meetings def test_no_overlap(): meetings = [("09:00", "10:30"), ("11:00", "12:00"), ("12:30", "14:00")] assert can_attend_meetings(meetings) == True def test_with_overlap(): meetings = [("09:00", "10:30"), ("10:15", "11:00"), ("11:00", "12:00")] assert can_attend_meetin...
[ { "docstring": "Convert a time string in the format 'HH:MM' to the number of minutes since 00:00.", "function_declaration": "def time_to_minutes(t):", "function_name": "time_to_minutes", "parameter_list": "(t)" }, { "docstring": "Determines if a person can attend all meetings without overlap...
[ 1, 1, 1, 1, 1, 1, 0, 1, 1, 0 ]
8
easy
0.8
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "from typing import List, Tuple\n\ndef can_attend_meetings(meetings: List[Tuple[str, str]]) -> bool:\n # Convert time from \"HH:MM\" string format to intege...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00001433", "row_id": 1433, "seed_ids": "[7916]" }
0.649738
Codeforces_1433
I
[ "time_to_minutes", "can_attend_meetings" ]
2
[ [ "can_attend_meetings", "time_to_minutes" ] ]
1
[]
false
[]
false
pytest
true
[]
true
d28720601116f04a0e220ee9fb6657d3dd101c55
6775a621e5627221c0b98e23a7140eb944bda28a
v1.0
instruct
Codeforces
Codeforces_1438_I
Katrina is managing a new software system which consists of n modules numbered from 1 to n. Module 1 is the central module. Additionally, there are m directed connections between the modules. One can go from module ui to module vi using the i-th connection, with a latency of xi milliseconds. Additionally, there are k s...
from heapq import heappop, heappush from collections import defaultdict import sys def min_latencies(n, adj): dist = [float('inf')] * (n + 1) dist[1] = 0 pq = [(0, 1)] while pq: d, u = heappop(pq) if d > dist[u]: continue for v, w in adj[u]: if dist[...
from solution import max_decommissioned_paths def test_max_decommissioned_paths(): n, m, k = 5, 6, 3 connections = [ (1, 2, 1), (1, 3, 3), (2, 4, 4), (3, 4, 2), (4, 5, 2), (3, 5, 8) ] secure_paths = [ (2, 1), (4, 3), (5, 10) ] ...
[ { "docstring": null, "function_declaration": "def min_latencies(n, adj):", "function_name": "min_latencies", "parameter_list": "(n, adj)" }, { "docstring": null, "function_declaration": "def max_decommissioned_paths(n, m, k, connections, secure_paths):", "function_name": "max_decommi...
[ 0, 0, 0, 0, 0, 0, 1, 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": "import heapq\n\ndef maximum_decommissioned_paths(n, m, k, connections, secure_paths):\n # Step 1: Build the adjacency list for general connections\n adj...
trial_gpt4o_6
{ "original_instruction": "", "prompt_id": "00001438", "row_id": 1438, "seed_ids": "[2887]" }
0.612387
Codeforces_1438
I
[ "min_latencies", "max_decommissioned_paths" ]
2
[ [ "max_decommissioned_paths", "min_latencies" ] ]
1
[]
false
[]
false
pytest
true
[]
true
4bd703ac59670076d091de9c329b8e970a2daa0f
ef042cc272de2363967b0bb761e17710ed7fee05
v1.0
instruct
Codeforces
Codeforces_1458_I
A forest has several clearings, connected by surprisingly straight paths. Adventurers traveling from one point to another often encounter multiple possible routes between the same pair of clearings. However, thick forest growth and active wildlife make travel between clearings difficult, so adventurers prefer to travel...
def floyd_warshall(n, graph): """ Uses Floyd-Warshall algorithm to find the shortest paths between all pairs of clearings. :param n: Number of clearings. :param graph: Adjacency matrix representing path lengths. :return: Matrix of shortest paths between all pairs of clearings. """ # Ini...
from solution import shortest_path_matrix def test_shortest_path_example(): input_matrix = [ [0, 3, -1, 7], [3, 0, 2, 8], [-1, 2, 0, 1], [7, 8, 1, 0] ] expected_output = [ [0, 3, 5, 6], [3, 0, 2, 3], [5, 2, 0, 1], [6, 3, 1, 0] ] assert...
[ { "docstring": "Uses Floyd-Warshall algorithm to find the shortest paths between all pairs of clearings.\n\n:param n: Number of clearings.\n:param graph: Adjacency matrix representing path lengths.\n:return: Matrix of shortest paths between all pairs of clearings.", "function_declaration": "def floyd_warsha...
[ 1, 0, 1, 0, 1, 0, 1, 0, 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 floyd_warshall(n, graph):\n # Prepare the distance matrix, using float('inf') for non-existent paths\n dist = [[float('inf')] * n for _ in range(n)]...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00001458", "row_id": 1458, "seed_ids": "[7398]" }
0.696181
Codeforces_1458
I
[ "floyd_warshall", "shortest_path_matrix" ]
2
[ [ "shortest_path_matrix", "floyd_warshall" ] ]
1
[]
false
[]
false
pytest
true
[]
true
19fb6a3524861cf54746a8a2ab548b467f10ad0f
a1054df49ce6ad08342a9b69ee95e022d91960d2
v1.0
instruct
Codeforces
Codeforces_1480_I
A professor is studying the migratory patterns of birds. The researcher has observed that birds migrate in a specific manner that can be represented as a grid. The grid consists of N rows and M columns of cells, and each cell can either be traversable (.) or an obstacle (#). The birds can move to an adjacent traversabl...
from collections import deque def min_steps_to_goal(grid, start, goal): N, M = len(grid), len(grid[0]) r1, c1 = start r2, c2 = goal 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([(r1, c1, 0)]) ...
from solution import migratory_patterns def test_simple_case(): grid = [ ['.', '.', '.', '.', '.'], ['.', '#', '.', '.', '.'], ['.', '.', '#', '.', '.'], ['.', '.', '.', '#', '.'], ['.', '.', '.', '.', '.'] ] assert migratory_patterns(5, 5, grid, 1, 1, 5, 5) == 8 de...
[ { "docstring": null, "function_declaration": "def min_steps_to_goal(grid, start, goal):", "function_name": "min_steps_to_goal", "parameter_list": "(grid, start, goal)" }, { "docstring": null, "function_declaration": "def migratory_patterns(N, M, grid, r1, c1, r2, c2):", "function_nam...
[ 0, 1, 1, 0, 0, 1, 0, 0, 1, 1 ]
5
medium
0.5
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "from collections import deque\n\ndef min_steps_to_goal(N, M, grid, start_r, start_c, goal_r, goal_c):\n def is_valid(x, y):\n return 0 <= x < N and ...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00001480", "row_id": 1480, "seed_ids": "[3075]" }
0.7415
Codeforces_1480
I
[ "min_steps_to_goal", "migratory_patterns" ]
2
[ [ "migratory_patterns", "min_steps_to_goal" ] ]
1
[]
false
[]
false
pytest
true
[]
true
3339adc6f14f12fe72b8630ef252dc188f3dacda
6ffa4a25f0ba2332ddac2c97eb29e9e396ce5023
v1.0
instruct
Codeforces
Codeforces_1481_I
In an ancient forest, there are several magical creatures each with unique abilities. Abilities can be either physical (strength, agility) or elemental (fire, water). Every day, two creatures engage in a duel in a particular ability chosen by the forest's elder. The creature with the higher value in the chosen ability ...
def find_ruler(n, m, creatures, abilities): current_creatures = list(range(n)) # index of creatures still in the forest for ability in abilities: ability -= 1 # converting to 0-based index # Perform duels for the current ability new_creatures = [] while len(current_creatures...
def test_ruler_example(): n = 4 m = 2 creatures = [ [10, 15], [20, 5], [25, 30], [10, 40] ] abilities = [1, 2, 2, 1] assert ruler_of_forest(n, m, creatures, abilities) == 3 def test_ruler_different_abilities(): n = 3 m = 3 creatures = [ [5, 15...
[ { "docstring": null, "function_declaration": "def find_ruler(n, m, creatures, abilities):", "function_name": "find_ruler", "parameter_list": "(n, m, creatures, abilities)" }, { "docstring": null, "function_declaration": "def ruler_of_forest(n, m, creatures, abilities):", "function_na...
[ 1, 1, 0, 0, 0, 0, 0, 0, 0, 1 ]
3
hard
0.3
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def find_ruler(num_creatures, num_abilities, creatures, order_of_duels):\n remaining_creatures = list(range(num_creatures))\n \n for ability in order...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00001481", "row_id": 1481, "seed_ids": "[4409]" }
0.634698
Codeforces_1481
I
[ "find_ruler", "ruler_of_forest" ]
2
[ [ "ruler_of_forest", "find_ruler" ] ]
1
[]
false
[]
false
pytest
false
[]
true
d66018604c3d08243a296b4d16e650aed1d4f3ed
19e6918f84b032ca32aa2dd3a52da3d695aeadc9
v1.0
instruct
Codeforces
Codeforces_1484_I
You are given an undirected graph with $$$n$$$ vertices and $$$m$$$ edges. Each edge has a weight associated with it. Your task is to determine if there exists a path between any two vertices such that the sum of weights along the path equals $$$k$$$. Input: - The first line contains three integers $$$n$$$ ($$$2 \le n...
import collections from itertools import product def does_path_exist(n, m, k, edges): """ Returns "YES" if there exists any path between any two vertices such that the sum of weights along the path equals k. Otherwise, returns "NO". """ graph = collections.defaultdict(list) for u, v, w in ...
from solution import graph_path_exists def test_case_1(): n = 5 m = 6 k = 7 edges = [(1, 2, 3), (2, 3, 4), (1, 3, 5), (3, 4, 2), (2, 5, 1), (4, 5, -1)] assert graph_path_exists(n, m, k, edges) == "YES" def test_case_2(): n = 3 ...
[ { "docstring": "Returns \"YES\" if there exists any path between any two vertices such that the sum of weights\nalong the path equals k. Otherwise, returns \"NO\".", "function_declaration": "def does_path_exist(n, m, k, edges):", "function_name": "does_path_exist", "parameter_list": "(n, m, k, edges...
[ 0, 1, 0, 0, 0, 0, 0, 0, 0, 1 ]
2
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "from collections import defaultdict, deque\n\ndef has_path_with_sum(n, m, k, edges):\n \"\"\"\n Determine if there exists any path between any two verti...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00001484", "row_id": 1484, "seed_ids": "[7451]" }
0.812949
Codeforces_1484
I
[ "does_path_exist", "graph_path_exists" ]
2
[ [ "graph_path_exists", "does_path_exist" ] ]
1
[]
false
[]
false
pytest
true
[]
true
ad54b297ceb24a9ac1f9b3a2f9decf7cfec7a21e
0143d633bc998d5e8e93135e62b76f7219b04fa9
v1.0
instruct
Codeforces
Codeforces_1494_I
Given a grid with N rows and M columns, you need to find the largest rectangle (sub-grid) containing only 1s. You are given N x M grid of 0s and 1s. Your task is to write a program that calculates the area of the largest rectangle (sub-grid) in the grid that contains only 1s. **Input:** - The first line contains two...
def largestRectangleArea(heights): """ Helper function to find the largest rectangle in a histogram. """ stack = [] max_area = 0 index = 0 while index < len(heights): if not stack or heights[index] >= heights[stack[-1]]: stack.append(index) index += 1 ...
from solution import maximalRectangle def test_example_case(): input_grid = [ [1, 0, 1, 0, 0], [1, 0, 1, 1, 1], [1, 1, 1, 1, 1], [1, 0, 0, 1, 0] ] assert maximalRectangle(input_grid) == 6 def test_all_ones(): input_grid = [ [1, 1, 1], [1, 1, 1], ...
[ { "docstring": "Helper function to find the largest rectangle in a histogram.", "function_declaration": "def largestRectangleArea(heights):", "function_name": "largestRectangleArea", "parameter_list": "(heights)" }, { "docstring": "Given a grid of 0s and 1s, finds the largest rectangle conta...
[ 0, 1, 1, 0, 1, 0, 1, 0, 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 largest_rectangle_area(matrix):\n \"\"\"\n Returns the area of the largest rectangle containing only 1s in the given grid.\n \"\"\"\n if not m...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00001494", "row_id": 1494, "seed_ids": "[6998]" }
0.744481
Codeforces_1494
I
[ "largestRectangleArea", "maximalRectangle" ]
2
[ [ "maximalRectangle", "largestRectangleArea" ] ]
1
[]
false
[]
false
pytest
true
[]
true
7213cb32e57f1dc8ee4f617fa12ca2810dae6dea
5c4adf140e8104f0242fbce952d17fb7f6072d50
v1.0
instruct
Codeforces
Codeforces_1509_I
Given a non-negative integer `x`, determine whether it is possible to rearrange its digits such that they form a power of 2. The first line contains an integer `x` (0 ≤ x ≤ 10^9). In a single line, print "YES" if it is possible to rearrange the digits of `x` to form a power of 2, otherwise print "NO". **Examples:**...
from itertools import permutations def is_power_of_two(n): # n is a single number return n > 0 and (n & (n - 1)) == 0 def can_form_power_of_two(x): x_str = str(x) perm = set(permutations(x_str)) # get all permutations of x_str for p in perm: num = int(''.join(p)) if is_power_of_tw...
from solution import check_power_of_two_rearrangement, can_form_power_of_two def test_example_1(capsys): check_power_of_two_rearrangement(128) captured = capsys.readouterr() assert captured.out.strip() == "YES" def test_example_2(capsys): check_power_of_two_rearrangement(123) captured = capsys.rea...
[ { "docstring": null, "function_declaration": "def is_power_of_two(n):", "function_name": "is_power_of_two", "parameter_list": "(n)" }, { "docstring": null, "function_declaration": "def can_form_power_of_two(x):", "function_name": "can_form_power_of_two", "parameter_list": "(x)" ...
[ 1, 1, 0, 0, 0, 0, 1, 0, 1, 1 ]
5
medium
0.5
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "from itertools import permutations\n\ndef is_power_of_two(n):\n \"\"\"\n Check if the given number n is a power of two.\n \"\"\"\n return (n > 0) ...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00001509", "row_id": 1509, "seed_ids": "[1975]" }
0.536923
Codeforces_1509
I
[ "is_power_of_two", "can_form_power_of_two", "check_power_of_two_rearrangement" ]
3
[ [ "can_form_power_of_two", "is_power_of_two" ], [ "check_power_of_two_rearrangement", "can_form_power_of_two" ] ]
2
[]
false
[]
false
pytest
true
[]
true
56e96a589014e7fdbbc58e69788c5a6e58f16dcc
ed509be53a2d38145e2a399a870b9a4bb00f7c11
v1.0
instruct
Codeforces
Codeforces_1510_I
Kiran has been learning about different sorting algorithms, and he is particularly interested in the Merge Sort algorithm. He understands how Merge Sort works, but he wants to see its specific application on an array of strings. Kiran has an array of n strings, and he needs to sort the array using the Merge Sort algor...
def merge_sort(arr): if len(arr) <= 1: return arr mid = len(arr) // 2 left = merge_sort(arr[:mid]) right = merge_sort(arr[mid:]) return merge(left, right) def merge(left, right): merged = [] i = j = 0 while i < len(left) and j < len(right): if left[i] < right[j]: ...
from solution import sort_strings def test_sort_strings(): assert sort_strings(5, ["apple", "banana", "orange", "grape", "mango"]) == ["apple", "banana", "grape", "mango", "orange"] assert sort_strings(3, ["zebra", "apple", "yellow"]) == ["apple", "yellow", "zebra"] assert sort_strings(4, ["mango", "banana...
[ { "docstring": null, "function_declaration": "def merge_sort(arr):", "function_name": "merge_sort", "parameter_list": "(arr)" }, { "docstring": null, "function_declaration": "def merge(left, right):", "function_name": "merge", "parameter_list": "(left, right)" }, { "docst...
[ 1, 1, 1, 1, 1, 1, 0, 0, 1, 1 ]
8
easy
0.8
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def merge_sort(arr):\n if len(arr) > 1:\n mid = len(arr) // 2\n left_half = arr[:mid]\n right_half = arr[mid:]\n\n merge_sort(l...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00001510", "row_id": 1510, "seed_ids": "[3963]" }
0.677041
Codeforces_1510
I
[ "merge_sort", "merge", "sort_strings" ]
3
[ [ "merge_sort", "merge" ], [ "sort_strings", "merge_sort" ] ]
2
[]
false
[]
false
pytest
true
[]
true
651cd3aaeed9d53f4ef2629c2022e3af0eee7ced
0573fca7c12e3f49f288e6e0c05a3c9d058d2656
v1.0
instruct
Codeforces
Codeforces_1518_I
Ella has recently become interested in prime numbers and their properties. To challenge herself, she came up with a new game involving prime sums. The game is defined as follows: Given an integer n, find two distinct positive prime numbers p and q such that their sum equals n (i.e., p + q = n). If there are multiple p...
def sieve(n): """ Implement Sieve of Eratosthenes to generate all prime numbers up to n. """ is_prime = [True] * (n + 1) p = 2 while p * p <= n: if is_prime[p]: for i in range(p * p, n + 1, p): is_prime[i] = False p += 1 primes = [p for p in range(2, n + 1...
from solution import find_prime_pair def test_smallest_valid_prime_pair(): assert find_prime_pair(4) == (2, 2) def test_example_case(): assert find_prime_pair(26) == (3, 23) def test_no_possible_pair(): # This case assumes the input will always guarantee at least one valid pair pass def test_lar...
[ { "docstring": "Implement Sieve of Eratosthenes to generate all prime numbers up to n. ", "function_declaration": "def sieve(n):", "function_name": "sieve", "parameter_list": "(n)" }, { "docstring": null, "function_declaration": "def find_prime_pair(n):", "function_name": "find_prime...
[ 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 is_prime(num):\n if num <= 1:\n return False\n if num == 2:\n return True\n if num % 2 == 0:\n return False\n for i in ra...
trial_gpt4o_3
{ "original_instruction": "", "prompt_id": "00001518", "row_id": 1518, "seed_ids": "[766]" }
0.650251
Codeforces_1518
I
[ "sieve", "find_prime_pair" ]
2
[ [ "find_prime_pair", "sieve" ] ]
1
[]
false
[]
false
pytest
true
[]
true
2f67ca124e771ba8d45fa87c8c2243d3eddcbc73
be012d64b5c23b17d3764b08e91467980a6c19bf
v1.0
instruct
Codeforces
Codeforces_1527_I
Write a function `find_subsets` that takes a list of n integers and returns all possible non-empty subsets of the list. Each subset should be presented in non-descending order of their elements. In addition, create a function `unique_subsets` that ensures subsets with the same elements, regardless of order, are consi...
import itertools def find_subsets(nums): """ Returns all possible non-empty subsets of nums. """ subsets = [] for i in range(1, len(nums) + 1): subsets.extend(itertools.combinations(nums, i)) return subsets def unique_subsets(nums): """ Returns all non-empty unique subsets of n...
from solution import find_subsets, unique_subsets def test_find_subsets(): assert sorted(find_subsets([1, 2, 2])) == sorted([ (1,), (2,), (2,), (1, 2), (1, 2), (2, 2), (1, 2, 2) ]) def test_unique_subsets(): assert unique_subsets([1, 2, 2]) == [[1], [1, 2], [1, 2, 2], [2...
[ { "docstring": "Returns all possible non-empty subsets of nums.", "function_declaration": "def find_subsets(nums):", "function_name": "find_subsets", "parameter_list": "(nums)" }, { "docstring": "Returns all non-empty unique subsets of nums, sorted in lexicographical order.", "function_d...
[ 1, 0, 0, 0, 1, 1, 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": "from itertools import combinations\n\ndef find_subsets(nums):\n \"\"\"\n Returns all non-empty subsets of the input list in non-descending order.\n \...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00001527", "row_id": 1527, "seed_ids": "[4228]" }
0.601797
Codeforces_1527
I
[ "find_subsets", "unique_subsets" ]
2
[ [ "unique_subsets", "find_subsets" ] ]
1
[]
false
[]
false
pytest
true
[]
true
5c5cdab3e2f1bc8eda81303e939b7304eb0779cc
c25ce5d21382621384d07310ca972b32bcac3140
v1.0
instruct
Codeforces
Codeforces_1585_I
A rectangular matrix is given with $$$n$$$ rows and $$$m$$$ columns. The matrix contains only binary values (0 or 1). Your task is to find the largest rectangle containing only 1's and return its area. ### Input format - The first line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 2000$$$), the dimens...
def maximal_rectangle(matrix): if not matrix: return 0 n = len(matrix) m = len(matrix[0]) heights = [0] * m max_area = 0 for row in matrix: for i in range(m): if row[i] == '1': heights[i] += 1 else: heights[i] = 0 ...
import pytest from solution import maximal_rectangle 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 maximal_rectangle(matrix) == 6 def test_empty_matrix(): matrix = ...
[ { "docstring": null, "function_declaration": "def maximal_rectangle(matrix):", "function_name": "maximal_rectangle", "parameter_list": "(matrix)" }, { "docstring": null, "function_declaration": "def largest_rectangle_area(heights):", "function_name": "largest_rectangle_area", "pa...
[ 1, 1, 1, 0, 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 maximalRectangle(matrix):\n if not matrix:\n return 0\n\n max_area = 0\n n = len(matrix)\n m = len(matrix[0])\n heights = [0] * m\n\...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00001585", "row_id": 1585, "seed_ids": "[1108]" }
0.715344
Codeforces_1585
I
[ "maximal_rectangle", "largest_rectangle_area" ]
2
[ [ "maximal_rectangle", "largest_rectangle_area" ] ]
1
[]
false
[]
false
pytest
true
[]
true
2c543f2ef2834624a912e7eef77e9c2fd81c2a71
40be436b6ef406bdbae9a0fa5cdae33b9e5ea63a
v1.0
instruct
Codeforces
Codeforces_1656_I
A group of friends are planning a trip. They want to visit exactly k islands out of n available islands. Each friend can have only one visit per island, but multiple friends can visit an island simultaneously. They can start from any island and move to any other island. They want to minimize the largest distance any on...
import math from itertools import combinations def calculate_distance(p1, p2): """ Computes the Euclidean distance between two points p1 and p2. """ return math.sqrt((p1[0] - p2[0]) ** 2 + (p1[1] - p2[1]) ** 2) def min_largest_distance(n, k, coordinates): """ Returns the minimum possible value...
from solution import min_largest_distance def test_min_largest_distance_case1(): n = 4 k = 2 coordinates = [(0, 0), (3, 4), (6, 8), (9, 12)] assert min_largest_distance(n, k, coordinates) == 5.0 def test_min_largest_distance_case2(): n = 3 k = 2 coordinates = [(1, 1), (4, 5), (7, 9)] a...
[ { "docstring": "Computes the Euclidean distance between two points p1 and p2.", "function_declaration": "def calculate_distance(p1, p2):", "function_name": "calculate_distance", "parameter_list": "(p1, p2)" }, { "docstring": "Returns the minimum possible value of the largest distance any fri...
[ 0, 0, 1, 0, 0, 0, 0, 0, 0, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "import math\nfrom itertools import combinations\n\ndef distance(p1, p2):\n \"\"\"\n Calculates the Euclidean distance between two points p1 and p2.\n ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00001656", "row_id": 1656, "seed_ids": "[4682]" }
0.703726
Codeforces_1656
I
[ "calculate_distance", "min_largest_distance" ]
2
[ [ "min_largest_distance", "calculate_distance" ] ]
1
[]
false
[]
false
pytest
true
[]
true
c06936f8b4ec8b19cd55211ed8ce5ee6155fc8c2
04733948ef98eedf3479f5c226dbc0c716c072ce
v1.0
instruct
Codeforces
Codeforces_1676_I
You are organizing a coding competition and you have received the registration forms from n participants, numbered from 1 to n. Each participant has provided a schedule of coding problems they will solve, which needs to be followed in a strict sequential order. Each problem provided by a participant is characterized ...
def generate_difficulties(l, b1, v, w, m): difficulties = [b1] for j in range(1, l): next_difficulty = (difficulties[-1] + v * w) % m difficulties.append(next_difficulty) return difficulties def minimize_difficult_transitions(n, participants): all_problems = [] for i, (l, b1, v, w, ...
from solution import generate_difficulties, minimize_difficult_transitions, solve def test_generate_difficulties(): assert generate_difficulties(2, 5, 3, 2, 100) == [5, 11] assert generate_difficulties(2, 4, 1, 5, 50) == [4, 9] assert generate_difficulties(3, 1, 2, 2, 10) == [1, 5, 9] def test_minimize_di...
[ { "docstring": null, "function_declaration": "def generate_difficulties(l, b1, v, w, m):", "function_name": "generate_difficulties", "parameter_list": "(l, b1, v, w, m)" }, { "docstring": null, "function_declaration": "def minimize_difficult_transitions(n, participants):", "function_...
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def generate_difficulties(n, participants):\n difficulties = []\n \n for i in range(n):\n li, b1, vi, wj, mi = participants[i]\n b = [b...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00001676", "row_id": 1676, "seed_ids": "[6131]" }
0.673069
Codeforces_1676
I
[ "generate_difficulties", "minimize_difficult_transitions", "solve" ]
3
[ [ "minimize_difficult_transitions", "generate_difficulties" ], [ "solve", "minimize_difficult_transitions" ] ]
2
[]
false
[]
false
pytest
true
[]
true
355be977d36fa50eac3171b88e3fa2eebb063020
4ef40c229cd7dd7fa3b6fe1d578cf52298674d68
v1.0
instruct
Codeforces
Codeforces_1781_I
### Puzzle Vault Manager Vera is the curator of a mysterious puzzle vault. The vault is electronic and can only be opened by solving a specific puzzle. The vault gives a puzzle in the form of a sequence of numbers, and you need to find the minimum number of operations to rearrange the sequence such that it becomes non...
def min_operations_to_non_decreasing(sequence): """ Given a sequence of integers, find the minimum number of operations required to make the sequence non-decreasing. Parameters: sequence (list of int): The list of integers to be processed. Returns: int: The minimum number of opera...
from solution import min_operations_to_non_decreasing, solve_puzzles, read_input, format_output def test_min_operations_to_non_decreasing(): assert min_operations_to_non_decreasing([5, 3, 6, 1, 7]) == 2 assert min_operations_to_non_decreasing([8, 5, 9, 4, 3, 2]) == 4 assert min_operations_to_non_decreasing...
[ { "docstring": "Given a sequence of integers, find the minimum number of operations required \nto make the sequence non-decreasing.\n\nParameters:\nsequence (list of int): The list of integers to be processed.\n\nReturns:\nint: The minimum number of operations required.", "function_declaration": "def min_op...
[ 1, 1, 1, 0, 0, 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 min_operations_to_non_decreasing(sequence):\n \"\"\"\n Given a sequence of integers, find the minimum number of operations required \n to make th...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00001781", "row_id": 1781, "seed_ids": "[1540]" }
0.76538
Codeforces_1781
I
[ "min_operations_to_non_decreasing", "solve_puzzles", "read_input", "format_output" ]
4
[ [ "solve_puzzles", "min_operations_to_non_decreasing" ] ]
1
[ "read_input", "format_output" ]
false
[]
false
pytest
true
[]
true
71fae98babee7ac8212a8c4fd7a8cbe1c005069e
a424447654f61fbdc1c7eec05db839801332ef40