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_79874_I
A "permuted multiple" of a number is another number that contains the same digits but in a different order. For example, `142857` is a permuted multiple of `285714` since both numbers contain the same digits. Write a function named `find_permuted_multiple` that takes an integer input `n` and finds the smallest positi...
def is_permuted_multiple(x, k): """ Check if k * x is a permuted multiple of x. """ return sorted(str(x)) == sorted(str(k * x)) def find_permuted_multiple(n): """ Finds the smallest integer x such that 2x, 3x, 4x, 5x, and 6x are all permuted multiples of x. The value of x should be greater ...
from solution import is_permuted_multiple, find_permuted_multiple def test_is_permuted_multiple(): assert is_permuted_multiple(142857, 2) assert is_permuted_multiple(142857, 3) assert is_permuted_multiple(142857, 4) assert is_permuted_multiple(142857, 5) assert is_permuted_multiple(142857, 6) a...
[ { "docstring": "Check if k * x is a permuted multiple of x.", "function_declaration": "def is_permuted_multiple(x, k):", "function_name": "is_permuted_multiple", "parameter_list": "(x, k)" }, { "docstring": "Finds the smallest integer x such that 2x, 3x, 4x, 5x, and 6x are all permuted multi...
[ 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 find_permuted_multiple(n):\n \"\"\"\n Finds the smallest positive integer x such that 2x, 3x, 4x, 5x, and 6x are all \n permuted multiples of x and x ...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00079874", "row_id": 79874, "seed_ids": "[6073]" }
0.655041
Taco_79874
I
[ "is_permuted_multiple", "find_permuted_multiple" ]
2
[ [ "find_permuted_multiple", "is_permuted_multiple" ] ]
1
[]
false
[]
false
pytest
true
[]
true
60c33ae5bf5258286f7be8c74e6575637fa0d26f
3632a40b132c2027a9e826f0caaece58c9dc799d
v1.0
instruct
Taco
Taco_80010_I
You are given a list of integers where each integer appears an even number of times, except for one integer which appears an odd number of times. Your task is to find the integer that appears an odd number of times in the list. ------ Input Format ------ - The first line of input contains a single integer T, denotin...
def find_odd_occurrence(numbers): """ Returns the integer that appears an odd number of times in the list. """ result = 0 for number in numbers: result ^= number return result def find_odd_occurrences_in_cases(cases): """ Returns a list of answers for each test case. """ ...
import pytest from solution import find_odd_occurrence, find_odd_occurrences_in_cases, parse_input def test_find_odd_occurrence(): assert find_odd_occurrence([1, 2, 3, 2, 3, 1, 3]) == 3 assert find_odd_occurrence([4, 4, 3, 3, 5]) == 5 assert find_odd_occurrence([9, 9, 7, 7, 7]) == 7 assert find_odd_occ...
[ { "docstring": "Returns the integer that appears an odd number of times in the list.", "function_declaration": "def find_odd_occurrence(numbers):", "function_name": "find_odd_occurrence", "parameter_list": "(numbers)" }, { "docstring": "Returns a list of answers for each test case.", "fu...
[ 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 find_odd_occurrence(test_cases):\n results = []\n for case in test_cases:\n n, arr = case\n result = 0\n for num in arr:\n ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00080010", "row_id": 80010, "seed_ids": "[4668]" }
0.66499
Taco_80010
I
[ "find_odd_occurrence", "find_odd_occurrences_in_cases", "parse_input" ]
3
[ [ "find_odd_occurrences_in_cases", "find_odd_occurrence" ] ]
1
[ "parse_input" ]
false
[]
false
pytest
true
[]
true
6d8bc7c402948588fc8bdbaa517fb1f376bc3ac5
ef65ad469da8bc768a379bbfda3c70f9ddccd99e
v1.0
instruct
Taco
Taco_80110_I
Write a function that takes a list of integers and returns a list of the same integers sorted in ascending order, except that all prime numbers should come first, in the original order they appeared in the input list. Examples: ``` Input: [29, 4, 17, 2, 1, 23, 8] Output: [29, 17, 2, 23, 1, 4, 8] Input: [11, 13, 15, ...
def is_prime(n): """Return True if n is a prime number, otherwise False.""" if n <= 1: return False if n == 2: return True if n % 2 == 0: return False sqrt_n = int(n**0.5) + 1 for i in range(3, sqrt_n, 2): if n % i == 0: return False return True d...
from solution import sort_special, is_prime def test_is_prime(): assert is_prime(2) == True assert is_prime(3) == True assert is_prime(4) == False assert is_prime(5) == True assert is_prime(16) == False assert is_prime(17) == True def test_sort_special(): assert sort_special([29, 4, 17, 2,...
[ { "docstring": "Return True if n is a prime number, otherwise False.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Returns a list of the numbers sorted such that prime numbers come first in their\noriginal order followed...
[ 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(n):\n \"\"\"\n Returns True if n is a prime number, otherwise False.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n ...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00080110", "row_id": 80110, "seed_ids": "[24389]" }
0.642206
Taco_80110
I
[ "is_prime", "sort_special" ]
2
[ [ "sort_special", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
f4f65d2fa3a51f170f9a181a73bdabe708ad755d
ea223c776b264a4766df76bbd5f61b718ed995cf
v1.0
instruct
Taco
Taco_80305_I
In a kingdom, there are n cities connected by m roads. Each road has a toll fee associated with it. The kingdom wants to maximize its revenue by ensuring that anyone traveling between different cities has to pay the toll fee. However, they also want to keep the infrastructure cost low by removing some roads so that the...
def find_minimum_toll(n, m, roads): """ Find the minimal sum of toll fees to keep the cities connected. """ # Kruskal's algorithm to find the Minimum Spanning Tree (MST) parent = list(range(n)) def find(x): if parent[x] != x: parent[x] = find(parent[x]) return parent...
def test_find_minimum_toll_case1(): assert solve("4 6\n1 2 3\n1 3 4\n1 4 2\n2 3 1\n2 4 5\n3 4 7") == 6 def test_find_minimum_toll_case2(): assert solve("5 7\n1 2 1\n2 3 2\n3 4 3\n4 5 4\n1 3 10\n2 4 6\n3 5 8") == 10 def test_find_minimum_toll_case3(): assert solve("3 3\n1 2 2\n1 3 4\n2 3 3") == 5 def test...
[ { "docstring": "Find the minimal sum of toll fees to keep the cities connected.", "function_declaration": "def find_minimum_toll(n, m, roads):", "function_name": "find_minimum_toll", "parameter_list": "(n, m, roads)" }, { "docstring": null, "function_declaration": "def solve(input_data):...
[ 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 minimal_toll_fee(n, m, roads):\n \"\"\"\n Function to calculate the minimum sum of toll fees \n to keep the kingdom connected while minimizing the tot...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00080305", "row_id": 80305, "seed_ids": "[16698]" }
0.716533
Taco_80305
I
[ "find_minimum_toll", "solve" ]
2
[ [ "solve", "find_minimum_toll" ] ]
1
[]
false
[]
false
pytest
false
[]
true
d21f40fe38d92c4712ab546027b1e382a4983904
dccf5bf54473a705a2e6aecdd999024b8c26bee0
v1.0
instruct
Taco
Taco_80343_I
A group of explorers have discovered an ancient artifact which contains a riddle. The artifact asks for the calculation of a special kind of sum involving lists of numbers. To move forward, the explorers need to solve the riddle correctly. Assist them by providing a solution for the following problem. Given an array o...
from itertools import combinations def sum_of_max_elements_in_subsequences(arr, k): MOD = 10**9 + 7 subsequence_sums = (max(subseq) for subseq in combinations(arr, k)) return sum(subsequence_sums) % MOD def solve(test_cases): results = [] for n, k, arr in test_cases: results.append(sum_of_...
def test_sum_of_max_elements_in_subsequences(): assert sum_of_max_elements_in_subsequences([1, 2, 3], 2) == 8 assert sum_of_max_elements_in_subsequences([4, 5, 1, 2], 3) == 19 assert sum_of_max_elements_in_subsequences([1, 1, 1], 1) == 3 assert sum_of_max_elements_in_subsequences([1, 1, 1], 2) == 3 ...
[ { "docstring": null, "function_declaration": "def sum_of_max_elements_in_subsequences(arr, k):", "function_name": "sum_of_max_elements_in_subsequences", "parameter_list": "(arr, k)" }, { "docstring": null, "function_declaration": "def solve(test_cases):", "function_name": "solve", ...
[ 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": "from itertools import combinations\n\nMOD = 10**9 + 7\n\ndef sum_of_max_in_subsequences(arr, N, K):\n subsequences = list(combinations(arr, K))\n max_sum = 0...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00080343", "row_id": 80343, "seed_ids": "[20691]" }
0.740435
Taco_80343
I
[ "sum_of_max_elements_in_subsequences", "solve", "parse_input", "format_output", "main" ]
5
[ [ "solve", "sum_of_max_elements_in_subsequences" ] ]
1
[ "parse_input", "format_output" ]
false
[]
false
pytest
false
[]
true
681894ce0002500230cfe5f94c0440a8d90e361b
2ecc7d9101bddc1b4955bf8b917c92c42bc34439
v1.0
instruct
Taco
Taco_80344_I
In a far-off land, there exists a Kingdom where magical magpies are known for their extraordinary hoarding skills. The magpies are particularly fond of shiny objects, and they have a peculiar way of managing their treasures. Each magpie constructs a binary search tree (BST) where each node represents a shiny object and...
from typing import List class TreeNode: def __init__(self, value): self.value = value self.left = None self.right = None # Function to construct balanced BST def sorted_array_to_bst(arr: List[int]) -> TreeNode: if not arr: return None mid = len(arr) // 2 node = TreeNode...
from solution import find_largest_balanced_bst_size def test_example_1(): assert find_largest_balanced_bst_size(5, [10, 5, 1, 7, 40]) == 5 def test_example_2(): assert find_largest_balanced_bst_size(7, [10, 20, 30, 40, 50, 60, 70]) == 7 def test_single_element(): assert find_largest_balanced_bst_size(1, ...
[]
[ 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_balanced_bst_size(values):\n \"\"\"\n Given a sequence of shininess values, returns the maximum number of nodes in the \n largest balanced bin...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00080344", "row_id": 80344, "seed_ids": "[9773]" }
0.561925
Taco_80344
I
[ "sorted_array_to_bst", "find_largest_balanced_bst_size" ]
2
[ [ "find_largest_balanced_bst_size", "sorted_array_to_bst" ] ]
1
[]
false
[ "TreeNode" ]
true
pytest
true
[]
true
a2f91fa643514c6927964f2f8eda8524ed16202c
3a1995fc5f1aff1cdaf7c597c46dc105b568995b
v1.0
instruct
Taco
Taco_80352_I
You have an array of integers, and you need to form the largest possible number by concatenating the elements of the array. Given an array of non-negative integers, arrange them such that they form the largest possible number. Return the result as a string. ### Example 1: **Input:** ``` N = 3 a = [10, 2, 9] ``` **Out...
from functools import cmp_to_key def compare(x, y): # Custom compare function to determine the order if x + y > y + x: return -1 elif x + y < y + x: return 1 else: return 0 def largestNumber(arr): """ Returns the largest number that can be formed by concatenating the ar...
from solution import largestNumber def test_example1(): assert largestNumber([10, 2, 9]) == "9210" def test_example2(): assert largestNumber([3, 30, 34, 5, 9]) == "9534330" def test_all_zeros(): assert largestNumber([0, 0, 0]) == "0" def test_single_digit_numbers(): assert largestNumber([1, 2, 3, 4,...
[ { "docstring": null, "function_declaration": "def compare(x, y):", "function_name": "compare", "parameter_list": "(x, y)" }, { "docstring": "Returns the largest number that can be formed by concatenating the array elements.", "function_declaration": "def largestNumber(arr):", "functi...
[ 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": "from functools import cmp_to_key\n\ndef compare(a, b):\n \"\"\"\n Custom comparator to decide the order of numbers to form the largest number.\n \"\"\"\n ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00080352", "row_id": 80352, "seed_ids": "[21086]" }
0.675315
Taco_80352
I
[ "compare", "largestNumber" ]
2
[ [ "largestNumber", "compare" ] ]
1
[]
false
[]
false
pytest
true
[]
true
61a39f888f6ef92802ec2d55d9099d65fa23710e
a6e05cdd8cc1e3704cbeacd93d8cb7d8ebab4c2e
v1.0
instruct
Taco
Taco_80371_I
In a certain kingdom, the king wants to build a new road that connects two towns, Town A and Town B. There are n towns in the kingdom and they are connected by m bidirectional roads. Each road has a specific distance. A road that connects towns x and y with distance d can be represented as (x, y, d). Your task is to f...
import heapq def dijkstra(n, roads, A, B): graph = {i: [] for i in range(1, n+1)} for x, y, d in roads: graph[x].append((y, d)) graph[y].append((x, d)) distances = {i: float('inf') for i in range(1, n+1)} distances[A] = 0 priority_queue = [(0, A)] while priority_queue:...
from solution import minimum_distance def test_minimum_distance_example1(): n, m, A, B = 5, 6, 1, 5 roads = [ (1, 2, 3), (2, 3, 4), (3, 1, 1), (1, 4, 5), (4, 5, 2), (2, 5, 7) ] assert minimum_distance(n, m, A, B, roads) == 7 def test_minimum_distance_exa...
[ { "docstring": null, "function_declaration": "def dijkstra(n, roads, A, B):", "function_name": "dijkstra", "parameter_list": "(n, roads, A, B)" }, { "docstring": null, "function_declaration": "def minimum_distance(n, m, A, B, roads):", "function_name": "minimum_distance", "parame...
[ 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 heapq\n\ndef minimum_distance(n, m, A, B, roads):\n \"\"\"\n Finds the minimum distance required to connect Town A to Town B\n \n Parameters:\n ...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00080371", "row_id": 80371, "seed_ids": "[22150]" }
0.7928
Taco_80371
I
[ "dijkstra", "minimum_distance" ]
2
[ [ "minimum_distance", "dijkstra" ] ]
1
[]
false
[]
false
pytest
true
[]
true
d5f1eebc4a574067b1b177c98f8ef439911fd853
bf1a689c4388b197390fa75fd58ece13b539eb74
v1.0
instruct
Taco
Taco_80383_I
You are given a list of integers `nums`. Your task is to return a new list that contains only the prime numbers from the original list `nums`. Example 1: Input: [2, 3, 4, 5, 6, 7, 8, 9, 10] Output: [2, 3, 5, 7] Example 2: Input: [12, 15, 20, 23, 30, 31] Output: [23, 31] Note: - `nums` is a list of integers with 1 <=...
def is_prime(n): """ Helper function to determine if a number is prime. Returns True if n is prime, otherwise False. """ 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...
from solution import filter_primes def test_filter_primes(): assert filter_primes([2, 3, 4, 5, 6, 7, 8, 9, 10]) == [2, 3, 5, 7] assert filter_primes([12, 15, 20, 23, 30, 31]) == [23, 31] assert filter_primes([1, 2, 3]) == [2, 3] assert filter_primes([0, 1, 4, 9, 16, 25, 36]) == [] assert filter_pri...
[ { "docstring": "Helper function to determine if a number is prime.\nReturns True if n is prime, otherwise False.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Filters the prime numbers out of the list `nums`.\n\nArgs:\nn...
[ 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(n):\n \"\"\"\n Helper function to check if a given number is prime.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n r...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00080383", "row_id": 80383, "seed_ids": "[13691]" }
0.654897
Taco_80383
I
[ "is_prime", "filter_primes" ]
2
[ [ "filter_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
a1117dbb4c43beeeaa9b628e51e1103f01c4a2d3
4e89cbb384736d058670ccd3d40d496120e52677
v1.0
instruct
Taco
Taco_80388_I
Given a string representing a mathematical equation which only contains numbers, variables (like `x` or `y`), and the operators `+, -, *, and /`, write a function `simplify_equation` that simplifies fractions in the equation by performing all possible simplifications. The function should maintain the order of operati...
import fractions def simplify_fraction(fraction_str): numerator, denominator = map(int, fraction_str.split('/')) simplified_fraction = fractions.Fraction(numerator, denominator) if simplified_fraction.denominator == 1: return str(simplified_fraction.numerator) return f"{simplified_fraction.nume...
from solution import simplify_equation def test_simplify_equation_basic(): assert simplify_equation("4/2 + 2*3 - 6/3") == "2 + 2*3 - 2" def test_simplify_equation_with_non_fraction(): assert simplify_equation("5 + 3 * 2 - 10/2") == "5 + 3 * 2 - 5" def test_simplify_equation_all_fractions(): assert simpli...
[ { "docstring": null, "function_declaration": "def simplify_fraction(fraction_str):", "function_name": "simplify_fraction", "parameter_list": "(fraction_str)" }, { "docstring": null, "function_declaration": "def simplify_equation(equation):", "function_name": "simplify_equation", ...
[ 0, 1 ]
1
medium
0.5
{ "trial_gpt4o_0": null, "trial_gpt4o_1": { "file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared1_results_combined.jsonl", "solution_code": "from sympy import simplify, Rational\n\ndef simplify_equation(equation):\n \"\"\"\n Simplifies fractions in the given equation by pe...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00080388", "row_id": 80388, "seed_ids": "[22363]" }
0.720973
Taco_80388
I
[ "simplify_fraction", "simplify_equation" ]
2
[ [ "simplify_equation", "simplify_fraction" ] ]
1
[]
false
[]
false
pytest
true
[]
true
c8e31805aed86d7117746bf7757fae294d89c9e2
ced34f0b9603ea77f86327bd8d4ed7ad400700ec
v1.0
instruct
Taco
Taco_80408_I
After his recent exploration into mathematical sequences, Marin encounters another fascinating challenge, which he calls the "Repunit Sum Problem." A repunit is a number consisting entirely of 1s. For example, 1, 11, 111 are all repunits. Marin defines a sequence of repunits where each element $r_i$ is a repunit with ...
def calculate_repunit(n): """ Calculates the n-digit repunit. """ return (10 ** n - 1) // 9 def sum_of_repunits(l, r): """ Calculates the sum of repunits from r_l to r_r. """ return sum(calculate_repunit(i) for i in range(l, r + 1)) def process_queries(queries): """ Process eac...
from solution import calculate_repunit, sum_of_repunits, process_queries def test_calculate_repunit(): assert calculate_repunit(1) == 1 assert calculate_repunit(2) == 11 assert calculate_repunit(3) == 111 def test_sum_of_repunits_single(): assert sum_of_repunits(1, 1) == 1 assert sum_of_repunits(2...
[ { "docstring": "Calculates the n-digit repunit.", "function_declaration": "def calculate_repunit(n):", "function_name": "calculate_repunit", "parameter_list": "(n)" }, { "docstring": "Calculates the sum of repunits from r_l to r_r.", "function_declaration": "def sum_of_repunits(l, r):", ...
[ 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 repunit_sum(l, r):\n \"\"\"\n Calculates the sum of repunits from r_l to r_r inclusive.\n\n :param l: left index of the range\n :param r: right ind...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00080408", "row_id": 80408, "seed_ids": "[25122]" }
0.595367
Taco_80408
I
[ "calculate_repunit", "sum_of_repunits", "process_queries" ]
3
[ [ "process_queries", "sum_of_repunits" ], [ "sum_of_repunits", "calculate_repunit" ] ]
2
[ "process_queries" ]
false
[]
false
pytest
true
[]
true
944ff22f0847bca83c251f53d3a9328ff7f3413f
f1f617c44fd4ea62054a965ed4ef92dbf55b1020
v1.0
instruct
Taco
Taco_80410_I
Tom loves playing with numbers, and he has come up with a fun sequence problem. He wants to generate a special sequence based on a given non-negative integer n. The sequence is generated as follows: 1. Start with the number n. 2. If n is even, the next number in the sequence is n/2. 3. If n is odd, the next number in...
def generate_sequence(n): """ Generates the sequence as described in the problem. Parameters: n (int): A non-negative integer as starting point of the sequence. Returns: List[int]: A list containing the sequence. """ if n == 0: return [0] sequence = [] whil...
from solution import generate_sequence, format_sequence def test_generate_sequence(): assert generate_sequence(6) == [6, 3, 10, 5, 16, 8, 4, 2, 1] assert generate_sequence(0) == [0] assert generate_sequence(1) == [1] assert generate_sequence(7) == [7, 22, 11, 34, 17, 52, 26, 13, 40, 20, 10, 5, 16, 8, 4...
[ { "docstring": "Generates the sequence as described in the problem.\n\nParameters:\nn (int): A non-negative integer as starting point of the sequence.\n\nReturns:\nList[int]: A list containing the sequence.", "function_declaration": "def generate_sequence(n):", "function_name": "generate_sequence", ...
[ 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 generate_sequence(n):\n \"\"\"\n Generates the sequence based on the given rules and returns it as a string.\n The sequence follows these rules:\n ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00080410", "row_id": 80410, "seed_ids": "[11346]" }
0.675738
Taco_80410
I
[ "generate_sequence", "format_sequence", "print_sequence" ]
3
[ [ "print_sequence", "format_sequence" ], [ "print_sequence", "generate_sequence" ] ]
2
[]
false
[]
false
pytest
true
[]
true
58865403cc1770b88420abcde95627d59dc0fcee
e1138d3149fdd6d6a571b8fef880573ca6006629
v1.0
instruct
Taco
Taco_80430_I
Alice loves playing with dominoes. She has a set of dominoes with numbers from 0 to 6 on each half. She wants to use these dominoes to create a chain. A valid chain of dominoes is one in which adjacent halves of neighboring dominoes have matching numbers. More specifically, let d_1, d_2, ..., d_n be the sequence of th...
from itertools import permutations def find_longest_chain(dominoes): def is_chain_valid(chain): for i in range(len(chain) - 1): if chain[i][1] != chain[i+1][0]: return False return True max_length = 0 for perm in permutations(dominoes): for i in rang...
from solution import longest_domino_chain def test_example_1(): assert longest_domino_chain(5, [(1, 2), (2, 3), (3, 4), (1, 3), (4, 5)]) == 4 def test_example_2(): assert longest_domino_chain(3, [(6, 1), (1, 2), (2, 6)]) == 3 def test_single_domino(): assert longest_domino_chain(1, [(0, 0)]) == 1 def te...
[ { "docstring": null, "function_declaration": "def find_longest_chain(dominoes):", "function_name": "find_longest_chain", "parameter_list": "(dominoes)" }, { "docstring": null, "function_declaration": "def longest_domino_chain(n, dominoes):", "function_name": "longest_domino_chain", ...
[ 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 longest_domino_chain(dominoes):\n from collections import defaultdict, deque\n \n def bfs(start):\n queue = deque([(start, [start])])\n ...
trial_gpt4o_3
{ "original_instruction": "", "prompt_id": "00080430", "row_id": 80430, "seed_ids": "[22039]" }
0.607424
Taco_80430
I
[ "find_longest_chain", "longest_domino_chain" ]
2
[ [ "longest_domino_chain", "find_longest_chain" ] ]
1
[]
false
[]
false
pytest
true
[]
true
2da6b4474a1191ff5f1c93a1b9a8b28ce0447152
8106d3ad915e3697dd3bafb97a31f6e3f35d278a
v1.0
instruct
Taco
Taco_80462_I
Heidi has learned about binary trees and their properties. She now needs to perform certain operations on a binary tree, specifically calculating the depth of the tree and finding the maximum value in each level of the tree. Can you help Heidi with these tasks? ----- Input ----- The input consists of two parts: 1. ...
from typing import List, Union from collections import deque class TreeNode: def __init__(self, val=0, left=None, right=None): self.val = val self.left = left self.right = right def build_tree(level_order: List[Union[int, None]]) -> Union[TreeNode, None]: if not level_order or level_or...
def test_depth_of_tree(): level_order = [3, 9, 20, None, None, 15, 7] root_val = 3 root = build_tree(level_order) assert depth_of_tree(root) == 3 def test_max_values_at_each_level(): level_order = [3, 9, 20, None, None, 15, 7] root_val = 3 root = build_tree(level_order) assert max_value...
[]
[ 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, Union\nfrom collections import deque\n\nclass TreeNode:\n def __init__(self, val=0, left=None, right=None):\n self.val = val\n ...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00080462", "row_id": 80462, "seed_ids": "[23706]" }
0.509802
Taco_80462
I
[ "build_tree", "depth_of_tree", "max_values_at_each_level", "process_tree" ]
4
[ [ "process_tree", "build_tree" ], [ "process_tree", "depth_of_tree" ], [ "process_tree", "max_values_at_each_level" ] ]
3
[]
false
[ "TreeNode" ]
true
pytest
false
[]
true
b3d762ef47db0535ab539801a0ee07cb8b3c9577
9180ade002623e3121e45a2cbd55d7c7445f44b6
v1.0
instruct
Taco
Taco_80512_I
Yara wants to build a theme park and realized that she needed to plan the paths that connect the different attractions so that all attractions are connected. She wants the minimum cost to build these paths. You need to find the minimum cost required to connect all attractions. The attractions and paths are represented ...
def find(parent, i): if parent[i] == i: return i else: return find(parent, parent[i]) def union(parent, rank, x, y): xroot = find(parent, x) yroot = find(parent, y) if rank[xroot] < rank[yroot]: parent[xroot] = yroot elif rank[xroot] > rank[yroot]: parent[yr...
def test_minimum_cost(): input_data = """2 4 5 1 2 10 1 3 15 1 4 20 2 3 25 3 4 30 3 1 1 2 10 2 3 15""" expected_output = "45\nImpossible" assert main(input_data) == expected_output def test_single_edge(): input_data = """1 2 1 1 2 5""" expected_output = "5" assert main(input_data) == expected_o...
[ { "docstring": null, "function_declaration": "def find(parent, i):", "function_name": "find", "parameter_list": "(parent, i)" }, { "docstring": null, "function_declaration": "def union(parent, rank, x, y):", "function_name": "union", "parameter_list": "(parent, rank, x, y)" }, ...
[ 0, 0, 1, 0 ]
1
hard
0.25
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl", "solution_code": "class UnionFind:\n def __init__(self, n):\n self.parent = list(range(n))\n self.rank = [1] * n\n\n def find(self, u):\n if self.parent[u...
trial_gpt4o_3
{ "original_instruction": "", "prompt_id": "00080512", "row_id": 80512, "seed_ids": "[13664]" }
0.747298
Taco_80512
I
[ "find", "union", "kruskal", "solve_minimum_cost", "main" ]
5
[ [ "kruskal", "find" ], [ "kruskal", "union" ], [ "solve_minimum_cost", "kruskal" ], [ "union", "find" ] ]
4
[]
false
[]
false
pytest
false
[]
true
7848b9c36bfa3ef4f06c03433272eb4c00ca3071
2ebfeac7ddf53b8058beb5582f3f7b6cd4d93cf9
v1.0
instruct
Taco
Taco_80517_I
In a magical kingdom, there are N wizards standing in a circle. Each wizard possesses a magical power represented by an integer P_i for wizard i (1 ≤ i ≤ N). Wizards have a peculiar way of challenging each other: a wizard i can challenge another wizard j ( j ≠ i) only if the absolute difference between their power leve...
def is_prime(n): if n < 2: return False for i in range(2, int(n**0.5) + 1): if n % i == 0: return False return True def max_standing_wizards(T, test_cases): def can_challenge(p1, p2): return is_prime(abs(p1 - p2)) results = [] for i in range(T): ...
from solution import max_standing_wizards def test_case_1(): T = 2 test_cases = [ (4, [1, 4, 7, 10]), (3, [5, 6, 15]) ] expected_results = [4, 3] assert max_standing_wizards(T, test_cases) == expected_results def test_all_same_power(): T = 1 test_cases = [ (5, [10, ...
[ { "docstring": null, "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": null, "function_declaration": "def max_standing_wizards(T, test_cases):", "function_name": "max_standing_wizards", "parameter_list": "(T, test_c...
[ 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": "import math\n\ndef 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 retu...
trial_gpt4o_3
{ "original_instruction": "", "prompt_id": "00080517", "row_id": 80517, "seed_ids": "[18668]" }
0.662596
Taco_80517
I
[ "is_prime", "max_standing_wizards" ]
2
[ [ "max_standing_wizards", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
09ecedac79b19c88742e876bd841eae47183fd62
89a718e7a3dcc6d19a6c951ebad1bb74f270d06b
v1.0
instruct
Taco
Taco_80550_I
Alice and Bob are playing a game using a sequence of integers. They will take turns counting numbers from the sequence according to specific rules. Alice will always start first. On her turn, she counts one number. On Bob's turn, he counts three numbers. This alternating goes on until the sequence is exhausted. The s...
def play_game(sequence): """ Takes the sequence string as input and returns a tuple with two lists: the first list containing the integers Alice counted, and the second list containing the integers Bob counted. """ numbers = list(map(int, sequence.split(','))) alice_counts = [] bob_counts = ...
from solution import play_game, total_sum def test_play_game(): assert play_game("1,2,3,4,5,6,7,8,9") == ([1, 5, 9], [2, 3, 4, 6, 7, 8]) assert play_game("10,20,30,40,50,60,70") == ([10, 50], [20, 30, 40, 60, 70]) assert play_game("1,2,3,4") == ([1], [2, 3, 4]) assert play_game("7,8,9") == ([7], [8, 9]...
[ { "docstring": "Takes the sequence string as input and returns a tuple with two lists:\nthe first list containing the integers Alice counted, and the second list containing the integers Bob counted.", "function_declaration": "def play_game(sequence):", "function_name": "play_game", "parameter_list":...
[ 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 play_game(sequence):\n \"\"\"\n Distribute the numbers from the sequence to Alice and Bob according to their counting rules.\n \n Args:\n sequen...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00080550", "row_id": 80550, "seed_ids": "[21263]" }
0.70197
Taco_80550
I
[ "play_game", "total_sum" ]
2
[ [ "total_sum", "play_game" ] ]
1
[]
false
[]
false
pytest
true
[]
true
b1097669d93cd9a68aaceb8e5b7c6fc11551511d
8813dd7c635d988ed0f6028cd493901f7e0d8464
v1.0
instruct
Taco
Taco_80585_I
You are given a list of non-negative integers representing the amount of money of each house arranged in a circle. Your task is to determine the maximum amount of money you can rob tonight without alerting the police, given that two adjacent houses cannot be robbed. Important Note: Because the houses are arranged in a...
def rob_linear(nums): """ Helper function to rob houses arranged in a linear fashion """ if not nums: return 0 if len(nums) == 1: return nums[0] dp = [0] * len(nums) dp[0] = nums[0] dp[1] = max(nums[0], nums[1]) for i in range(2, len(nums)): dp[i] = ...
from solution import rob_circle def test_example_1(): assert rob_circle([2, 3, 2]) == 3 def test_example_2(): assert rob_circle([1, 2, 3, 1]) == 4 def test_example_3(): assert rob_circle([0]) == 0 def test_empty_list(): assert rob_circle([]) == 0 def test_single_element(): assert rob_circle([5]...
[ { "docstring": "Helper function to rob houses arranged in a linear fashion", "function_declaration": "def rob_linear(nums):", "function_name": "rob_linear", "parameter_list": "(nums)" }, { "docstring": "Returns the maximum amount of money that can be robbed from houses arranged in a circle",...
[ 0, 0, 0, 0, 0, 0, 0, 1, 1, 0 ]
2
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl", "solution_code": "def rob_linear(nums):\n \"\"\"\n Helper function to solve the problem for a linear arrangement of houses.\n \"\"\"\n prev_max = 0\n curr_max = 0\n ...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00080585", "row_id": 80585, "seed_ids": "[2141]" }
0.601825
Taco_80585
I
[ "rob_linear", "rob_circle" ]
2
[ [ "rob_circle", "rob_linear" ] ]
1
[]
false
[]
false
pytest
true
[]
true
4aaf3a1384a6c2c907122249543ca72795acebc1
3b43fd799612b4ef319bb213ab23c0bc6d1586b1
v1.0
instruct
Taco
Taco_80629_I
You are given a list of cities connected by bidirectional roads. Each road has a weight representing the time it takes to travel from one city to another. You need to find the minimum time required to travel from the starting city to the destination city. You're also given a list of queries where each query asks for th...
def floyd_warshall(n, edges): # Initialize distance matrix with infinity dist = [[float('inf')] * n for _ in range(n)] # Distance from a city to itself is 0 for i in range(n): dist[i][i] = 0 # Populate the distance matrix with the given edges for u, v, t in edges: dist[...
from solution import process_input_output def test_example_1(): n, m, q = 4, 4, 3 roads = [(1, 2, 4), (1, 3, 5), (2, 3, 3), (3, 4, 9)] queries = [(1, 4), (2, 4), (1, 3)] assert process_input_output(n, m, q, roads, queries) == [14, 12, 5] def test_example_2(): n, m, q = 5, 3, 2 roads = [(1, 2, ...
[ { "docstring": null, "function_declaration": "def floyd_warshall(n, edges):", "function_name": "floyd_warshall", "parameter_list": "(n, edges)" }, { "docstring": null, "function_declaration": "def min_travel_time(n, m, q, roads, queries):", "function_name": "min_travel_time", "pa...
[ 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 sys\nimport heapq\n\ndef dijkstra(n, edges, start):\n graph = [[] for _ in range(n+1)]\n for u, v, t in edges:\n graph[u].append((v, t))\n ...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00080629", "row_id": 80629, "seed_ids": "[7110]" }
0.823224
Taco_80629
I
[ "floyd_warshall", "min_travel_time", "process_input_output" ]
3
[ [ "min_travel_time", "floyd_warshall" ], [ "process_input_output", "min_travel_time" ] ]
2
[ "process_input_output" ]
false
[]
false
pytest
true
[]
true
d4ab7e876645ea21c2c1013f3aa3b139e6ed77c5
cea51e7836048d48f744d31395b6cf49631a12c5
v1.0
instruct
Taco
Taco_80683_I
You are given a string `s` consisting of lowercase English letters and a list of words. Your task is to count how many words from the list are subsequences of the string `s`. A subsequence of a string is a new string generated from the original string with some characters (can be none) deleted without changing the rel...
def is_subsequence(s, word): """ Function to check if `word` is a subsequence of `s`. """ it = iter(s) return all(char in it for char in word) def count_subsequences(s, words): """ Function to count how many words from the list are subsequences of the string `s`. """ return sum(is_s...
from solution import count_subsequences def test_sample_input(): s = "abcde" words = ["a", "bb", "ace"] assert count_subsequences(s, words) == 2 def test_no_subsequences(): s = "abc" words = ["d", "e", "f"] assert count_subsequences(s, words) == 0 def test_all_subsequences(): s = "abcdef"...
[ { "docstring": "Function to check if `word` is a subsequence of `s`.", "function_declaration": "def is_subsequence(s, word):", "function_name": "is_subsequence", "parameter_list": "(s, word)" }, { "docstring": "Function to count how many words from the list are subsequences of the string `s`...
[ 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_subsequence(s, word):\n it = iter(s)\n return all(char in it for char in word)\n\ndef count_subsequences(s, number_of_words, words):\n count = 0\n ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00080683", "row_id": 80683, "seed_ids": "[21895]" }
0.842094
Taco_80683
I
[ "is_subsequence", "count_subsequences" ]
2
[ [ "count_subsequences", "is_subsequence" ] ]
1
[]
false
[]
false
pytest
true
[]
true
15bdc240b72de589f32c2b4e1a33819b168c5a0b
8df3d78d903c73fcd5a9c0fbcf241333aea2cd56
v1.0
instruct
Taco
Taco_80702_I
Mike wants to create a list of consecutive integers starting from 1 that includes exactly n prime numbers. However, the list must have its last number p being a prime number. Help Mike find the shortest length of this list. -----Constraints----- - 1 ≦ n ≦ 10^4 -----Input----- The input is given from Standard Input i...
def is_prime(num): """ Check if a given number is a prime number. """ if num <= 1: return False if num <= 3: return True if num % 2 == 0 or num % 3 == 0: return False i = 5 while i * i <= num: if num % i == 0 or num % (i + 2) == 0: return False...
from solution import find_shortest_list_length def test_small_values(): assert find_shortest_list_length(1) == 2 assert find_shortest_list_length(2) == 3 assert find_shortest_list_length(3) == 5 def test_edge_cases(): assert find_shortest_list_length(10) == 29 assert find_shortest_list_length(15) ...
[ { "docstring": "Check if a given number is a prime number.", "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": "Find the shortest length of a list starting from 1 that contains exactly n prime numbers \nwith the last number...
[ 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 shortest_list_with_n_primes(n):\n \"\"\"\n Returns the shortest length of a list of consecutive integers from 1 \n that includes exactly n prime numbe...
trial_gpt4o_3
{ "original_instruction": "", "prompt_id": "00080702", "row_id": 80702, "seed_ids": "[8144]" }
0.582008
Taco_80702
I
[ "is_prime", "find_shortest_list_length" ]
2
[ [ "find_shortest_list_length", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
60b25864c3ae940464b706fa0193afff3b4eccc3
aed43022b78bbfda93deff9506c434858da4c911
v1.0
instruct
Taco
Taco_80733_I
Anna got her hands on two strings `x` and `y` representing chemical formulas, consisting of lowercase Latin letters and digits. She wishes to find out if the formula represented by `x` can be transformed to the formula represented by `y` by rearranging the order of its elements. In a chemical formula, elements are repr...
import re from collections import defaultdict def parse_formula(formula): """ Parse a chemical formula into a dictionary of elements and their counts. """ pattern = re.compile(r'([A-Z][a-z]*)(\d*)') element_count = defaultdict(int) for (element, count) in pattern.findall(formula): ...
from solution import are_formulas_equivalent def test_identical_formulas(): assert are_formulas_equivalent("H2O", "H2O") == True def test_rearranged_formula(): assert are_formulas_equivalent("C6H12O6", "H12C6O6") == True def test_complex_identical_formula(): assert are_formulas_equivalent("K4[ON(SO3)2]2"...
[ { "docstring": "Parse a chemical formula into a dictionary of elements and their counts.", "function_declaration": "def parse_formula(formula):", "function_name": "parse_formula", "parameter_list": "(formula)" }, { "docstring": "Check if two chemical formulas are equivalent by comparing 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": "import re\nfrom collections import defaultdict\n\ndef parse_formula(formula):\n \"\"\"\n Parse a chemical formula into a dictionary of elements and their cou...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00080733", "row_id": 80733, "seed_ids": "[10680]" }
0.665086
Taco_80733
I
[ "parse_formula", "are_formulas_equivalent", "main" ]
3
[ [ "are_formulas_equivalent", "parse_formula" ] ]
1
[]
false
[]
false
pytest
true
[]
true
885bff7224741326f664d900645b7712e1dbde94
b760559f8652b4015737977181c28094a475c61b
v1.0
instruct
Taco
Taco_80749_I
Given an undirected graph with n nodes and m edges, determine if the graph can be colored using exactly 3 colors such that no two adjacent nodes share the same color. If such a coloring is possible, output the colors of the nodes. If not, output "Not possible". The input consists of multiple test cases. Each test case...
def is_bipartite(graph, node, color, colors): queue = [node] colors[node] = color while queue: current = queue.pop(0) for neighbor in graph[current]: if colors[neighbor] == -1: colors[neighbor] = 1 - colors[current] queue.append(neighbor) ...
from solution import process_input, graph_coloring def test_graph_coloring_one(): input_data = "4 4\n1 2\n2 3\n3 4\n4 1\n0 0\n" result = process_input(input_data) assert result == [[1, 2, 1, 2]], f"Unexpected result: {result}" def test_graph_coloring_two(): input_data = "3 3\n1 2\n2 3\n3 1\n0 0\n" ...
[ { "docstring": null, "function_declaration": "def is_bipartite(graph, node, color, colors):", "function_name": "is_bipartite", "parameter_list": "(graph, node, color, colors)" }, { "docstring": null, "function_declaration": "def graph_coloring(n, edges):", "function_name": "graph_col...
[ 0, 0, 0, 0, 0, 1, 0, 0, 0, 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_be_colored_3_colors(n, m, edges):\n from collections import defaultdict, deque\n\n def is_valid_coloring(node, color, graph, colors):\n for ne...
trial_gpt4o_5
{ "original_instruction": "", "prompt_id": "00080749", "row_id": 80749, "seed_ids": "[8465]" }
0.63162
Taco_80749
I
[ "is_bipartite", "graph_coloring", "process_input" ]
3
[ [ "graph_coloring", "is_bipartite" ], [ "process_input", "graph_coloring" ] ]
2
[ "process_input" ]
false
[]
false
pytest
true
[]
true
2be5baa187db94b207029f22b838ad1f93a11960
60476188f08fe1d68889ce33eee3cc001e070642
v1.0
instruct
Taco
Taco_80828_I
Jason has recently learned about binary trees and their various traversals. He is particularly interested in constructing a binary tree from its preorder and inorder traversal arrays. He knows that the unique binary tree can be constructed if both preorder and inorder traversal arrays are given. He wants your help in c...
class TreeNode: def __init__(self, val=0, left=None, right=None): self.val = val self.left = left self.right = right def buildTree(preorder, inorder): if not preorder or not inorder: return None # Root is the first element in preorder traversal root_val = preorder[0...
from solution import construct_postorder_from_pre_in def test_example_case(): assert construct_postorder_from_pre_in([3, 9, 20, 15, 7], [9, 3, 15, 20, 7]) == [9, 15, 7, 20, 3] def test_single_node(): assert construct_postorder_from_pre_in([1], [1]) == [1] def test_left_skewed_tree(): assert construct_pos...
[]
[ 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 build_t...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00080828", "row_id": 80828, "seed_ids": "[5652]" }
0.529692
Taco_80828
I
[ "buildTree", "postOrderTraversal", "construct_postorder_from_pre_in" ]
3
[ [ "construct_postorder_from_pre_in", "buildTree" ], [ "construct_postorder_from_pre_in", "postOrderTraversal" ] ]
2
[]
false
[ "TreeNode" ]
true
pytest
true
[]
true
89686b0511427d30d82e5a7aaabecd73d961e770
541804ded4b443c556013405a516310967adc748
v1.0
instruct
Taco
Taco_80840_I
One of the major banks in Metro City has implemented a new security system. The security system rotates an array of integers (representing the unique IDs of employees) to generate new secret passcodes for secure access. The rotation is defined as shifting a part of the array to the beginning. You are tasked with helpi...
def rotate_array(arr, k): """ Rotates the array 'arr' to the right by 'k' steps. """ n = len(arr) k = k % n # Handle cases where k is larger than the array length # Reverse the first part reverse(arr, 0, n - k - 1) # Reverse the second part reverse(arr, n - k, n - 1) ...
import pytest from solution import rotate_array def test_rotate_array_example1(): assert rotate_array([1, 2, 3, 4, 5], 2) == [4, 5, 1, 2, 3] def test_rotate_array_example2(): assert rotate_array([0, 1, 2, 3, 4, 5, 6], 1) == [6, 0, 1, 2, 3, 4, 5] def test_rotate_array_no_rotation(): assert rotate_array([...
[ { "docstring": "Rotates the array 'arr' to the right by 'k' steps.", "function_declaration": "def rotate_array(arr, k):", "function_name": "rotate_array", "parameter_list": "(arr, k)" }, { "docstring": "Reverses elements in the array 'arr' from index 'start' to 'end'", "function_declarat...
[ 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 rotate_array(arr, k):\n \"\"\"\n Rotates an array to the right by k steps.\n \n :param arr: List of integers to be rotated.\n :param k: Number o...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00080840", "row_id": 80840, "seed_ids": "[23623]" }
0.595288
Taco_80840
I
[ "rotate_array", "reverse" ]
2
[ [ "rotate_array", "reverse" ] ]
1
[]
false
[]
false
pytest
true
[]
true
4e9b0b42661bc0b29de9acca5225157f9831e9fb
bf417fd547b6dfe7ab50a437de95f49fbeaf4ab1
v1.0
instruct
Taco
Taco_80842_I
Alice is a fan of puzzles and recently she found one involving an interesting number sequence. The sequence is derived as follows: - The sequence starts with a single positive integer n. - Each next term is obtained by reversing the digits of the current term and adding it to the current term. The sequence continues u...
def reverse_number(n): return int(str(n)[::-1]) def is_palindrome(n): s = str(n) return s == s[::-1] def steps_to_palindrome(n): steps = 0 while not is_palindrome(n): n = n + reverse_number(n) steps += 1 return steps
def test_reverse_number(): assert reverse_number(56) == 65 assert reverse_number(123) == 321 assert reverse_number(120) == 21 assert reverse_number(1) == 1 def test_is_palindrome(): assert is_palindrome(121) == True assert is_palindrome(123) == False assert is_palindrome(11) == True ass...
[ { "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...
[ 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 is_palindrome(num):\n \"\"\"Check if a number is a palindrome.\"\"\"\n return str(num) == str(num)[::-1]\n\ndef reverse_and_add(num):\n \"\"\"Reverse ...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00080842", "row_id": 80842, "seed_ids": "[8493]" }
0.712909
Taco_80842
I
[ "reverse_number", "is_palindrome", "steps_to_palindrome" ]
3
[ [ "steps_to_palindrome", "is_palindrome" ], [ "steps_to_palindrome", "reverse_number" ] ]
2
[]
false
[]
false
pytest
false
[]
true
15745e6e8557b623af0aebbf7fe41f0d6547f0df
66c214757bd156b515b0be39ecd8eb320b5848e7
v1.0
instruct
Taco
Taco_80957_I
You are given an undirected, unweighted graph with n nodes and m edges. Each node is initially uncolored. You are to determine whether it is possible to color the graph using two colors such that no two adjacent nodes have the same color. -----Input----- The first line contains two integers n and m (1 ≤ n ≤ 2·10^5, 0...
def is_bipartite(n, m, edges): from collections import deque, defaultdict def bfs(start): queue = deque([start]) color[start] = 0 while queue: node = queue.popleft() for neighbor in graph[node]: if color[neighbor] == -1: color[...
from solution import check_graph_coloring def test_example1(): n = 5 m = 4 edges = [(1, 2), (2, 3), (3, 4), (4, 5)] assert check_graph_coloring(n, m, edges) == "YES" def test_example2(): n = 3 m = 3 edges = [(1, 2), (2, 3), (3, 1)] assert check_graph_coloring(n, m, edges) == "NO" def ...
[ { "docstring": null, "function_declaration": "def is_bipartite(n, m, edges):", "function_name": "is_bipartite", "parameter_list": "(n, m, edges)" }, { "docstring": null, "function_declaration": "def check_graph_coloring(n, m, edges):", "function_name": "check_graph_coloring", "pa...
[ 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 collections import deque\n\ndef is_bipartite(n, edges):\n \"\"\"\n Determines if the given graph is bipartite (can be colored with 2 colors).\n\n Par...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00080957", "row_id": 80957, "seed_ids": "[1030]" }
0.675521
Taco_80957
I
[ "is_bipartite", "check_graph_coloring" ]
2
[ [ "check_graph_coloring", "is_bipartite" ] ]
1
[]
false
[]
false
pytest
true
[]
true
5c9482c676e2345cec8aa4453198c79eca5ffd10
5564d9b4587862eb549dcf70b5385900d9480fbe
v1.0
instruct
Taco
Taco_80965_I
Given the in-order and pre-order traversal of a binary tree, construct the binary tree and return its root. Example: Input: 2 3 1 2 3 1 2 3 4 2 1 3 4 1 2 3 4 Output: 3 4 Explanation: Testcase 1: The in-order and pre-order traversal of nodes 1, 2, and 3 reconstructs a binary tree with height 3. Testcase 2: The in-or...
class TreeNode: def __init__(self, x): self.val = x self.left = None self.right = None def buildTree(inorder, preorder): if not inorder or not preorder: return None root_val = preorder.pop(0) root = TreeNode(root_val) inorder_index = inorder.index(root_val) ...
from solution import constructBinaryTree def test_custom_case_1(): assert constructBinaryTree([2, 1, 3], [1, 2, 3]) == 2 def test_custom_case_2(): assert constructBinaryTree([2, 1, 3, 4], [1, 2, 3, 4]) == 3 def test_custom_case_3(): assert constructBinaryTree([3, 2, 4, 1], [1, 2, 3, 4]) == 3 def test_cu...
[]
[ 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": "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 buildTr...
trial_gpt4o_4
{ "original_instruction": "", "prompt_id": "00080965", "row_id": 80965, "seed_ids": "[472]" }
0.630619
Taco_80965
I
[ "buildTree", "treeHeight", "constructBinaryTree" ]
3
[ [ "constructBinaryTree", "buildTree" ], [ "constructBinaryTree", "treeHeight" ] ]
2
[]
false
[ "TreeNode" ]
true
pytest
true
[]
true
0acea6134d58833fb1f5af2337018a47acb7b0f3
ffb7dad5a1b413bef12d35e714f96d28698811e7
v1.0
instruct
Taco
Taco_81096_I
In a distant galaxy, there exists a matrix called the "Galaxy Matrix". The matrix has N rows and M columns. The Galactic Council has decided to introduce a special operation for the Galaxy Matrix: 1. Select any submatrix from the Galaxy Matrix. 2. Reverse the order of elements in every row of this submatrix. Formally...
def are_matrices_equal(mat1, mat2): """ Check if two matrices are equal. """ return mat1 == mat2 def is_transformation_possible(n, m, initial_matrix, target_matrix, k): """ Determine if the target matrix can be obtained from the initial matrix with exactly k row-reversing submatrix operati...
from solution import is_transformation_possible def test_possible_case(): n = 3 m = 3 initial_matrix = [ [1, 2, 3], [4, 5, 6], [7, 8, 9] ] target_matrix = [ [3, 2, 1], [6, 5, 4], [9, 8, 7] ] k = 3 assert is_transformation_possible(n, m, in...
[ { "docstring": "Check if two matrices are equal.", "function_declaration": "def are_matrices_equal(mat1, mat2):", "function_name": "are_matrices_equal", "parameter_list": "(mat1, mat2)" }, { "docstring": "Determine if the target matrix can be obtained from the initial matrix \nwith exactly k...
[ 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 are_matrices_equal(mat1, mat2):\n \"\"\"\n Check if two matrices are equal.\n \"\"\"\n return mat1 == mat2\n\ndef is_transformation_possible(n, m, ...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00081096", "row_id": 81096, "seed_ids": "[24849]" }
0.604046
Taco_81096
I
[ "are_matrices_equal", "is_transformation_possible" ]
2
[ [ "is_transformation_possible", "are_matrices_equal" ] ]
1
[]
false
[]
false
pytest
true
[]
true
10b249adbb67f22f63679c04215e30d4ab66b55c
a5da81faab78ff882db20393430a2609ef3d2313
v1.0
instruct
Taco
Taco_81129_I
There is an undirected graph with N vertices and M edges. Each vertex has a unique ID from 1 to N and each edge connects two different vertices. Some vertices are marked as important. Takahashi needs to find the shortest path that visits all important vertices at least once. Write a program to find the length of this ...
from itertools import permutations from collections import deque, defaultdict def find_shortest_path_length(N, M, k, important_vertices, edges): # Adjacency list representation of graph graph = defaultdict(list) for u, v in edges: graph[u].append(v) graph[v].append(u) # Function to...
def test_simple_cases(): import sys from io import StringIO input_data = "6 7\n3\n2 4 5\n1 2\n1 3\n2 4\n3 4\n4 5\n5 6\n6 3\n" sys.stdin = StringIO(input_data) solve() # Expected output: 8 def test_simple_cases_2(): import sys from io import StringIO input_data = "5 5\...
[ { "docstring": null, "function_declaration": "def find_shortest_path_length(N, M, k, important_vertices, edges):", "function_name": "find_shortest_path_length", "parameter_list": "(N, M, k, important_vertices, edges)" }, { "docstring": null, "function_declaration": "def solve():", "f...
[ 0, 0, 0, 0, 0, 0, 1, 0, 0, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl", "solution_code": "from itertools import permutations\nfrom collections import deque\nimport sys\n\ndef find_shortest_path(N, M, k, important_vertices, edges):\n # Create the adja...
trial_gpt4o_6
{ "original_instruction": "", "prompt_id": "00081129", "row_id": 81129, "seed_ids": "[11116]" }
0.743263
Taco_81129
I
[ "find_shortest_path_length", "solve" ]
2
[ [ "solve", "find_shortest_path_length" ] ]
1
[]
false
[]
false
pytest
false
[]
true
8d7ac56539a4d6a9aeafd32b41daa33c055e1e16
7fdaed61dca6bfa9b26082b8bda4c408742e7723
v1.0
instruct
Taco
Taco_81155_I
A team of engineers is working on a project to optimize a large network of computers. One of their tasks is to analyze the communication patterns between the computers in the network. They represent the network as a grid of characters, where '.' represents an empty space, 'C' represents a computer, and 'W' represents a...
from collections import deque def is_path_exist(grid, n, m): """ Determines if there is a path from the top-left corner to the bottom-right corner of the grid. """ def is_valid_move(x, y): return 0 <= x < n and 0 <= y < m and grid[x][y] == '.' and not visited[x][y] directions = [(1, 0), (-...
from solution import communication_path def test_simple_path(): grid = [ "....", ".W..", "....", "..W." ] assert communication_path(4, 4, grid) == "YES" def test_no_path(): grid = [ ".CW", ".W.", "CW.", "C.W" ] assert communicatio...
[ { "docstring": "Determines if there is a path from the top-left corner to the bottom-right corner of the grid.", "function_declaration": "def is_path_exist(grid, n, m):", "function_name": "is_path_exist", "parameter_list": "(grid, n, m)" }, { "docstring": null, "function_declaration": "d...
[ 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 collections import deque\n\ndef is_path_exist(grid, n, m):\n \"\"\"\n Determines if there is a path from the top-left corner to the bottom-right corner ...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00081155", "row_id": 81155, "seed_ids": "[10232]" }
0.760584
Taco_81155
I
[ "is_path_exist", "communication_path" ]
2
[ [ "communication_path", "is_path_exist" ] ]
1
[]
false
[]
false
pytest
true
[]
true
faa6f525d84fbd31e1a22dcb12e06360b410a5c0
1b376112aeb5207c29c3ee65595d6db0cc8970da
v1.0
instruct
Taco
Taco_81242_I
An online bookstore wishes to organize their book sales data for better analysis. Each sale is represented by the book's unique code and the number of copies sold. The bookstore is interested in knowing which book had the highest number of copies sold for the given input data. If there is a tie, they want to know all s...
def highest_sales(book_sales_data): """ Finds the book(s) with the highest sales for each test case input. Parameters: book_sales_data (list of tuples): A list where each element is a tuple (book_code, copies_sold). Returns: list: A list of book codes with the highest sales for each te...
def test_example_case(): input_data = """\ 2 3 book1 100 book2 250 book3 250 4 codeA 500 codeB 120 codeC 500 codeD 450""" expected_output = "book2 book3\ncodeA codeC" T, data = parse_input(input_data) results = bookstore_sales(T, data) output = format_output(results) assert output ==...
[ { "docstring": "Finds the book(s) with the highest sales for each test case input.\n\nParameters:\nbook_sales_data (list of tuples): A list where each element is a tuple (book_code, copies_sold).\n\nReturns:\nlist: A list of book codes with the highest sales for each test case.", "function_declaration": "de...
[ 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 highest_sales_books(test_cases):\n \"\"\"\n Given test cases containing sales records, return the book code(s)\n with the highest number of copies sol...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00081242", "row_id": 81242, "seed_ids": "[22543]" }
0.688112
Taco_81242
I
[ "highest_sales", "bookstore_sales", "parse_input", "format_output" ]
4
[ [ "bookstore_sales", "highest_sales" ] ]
1
[ "parse_input", "format_output" ]
false
[]
false
pytest
false
[]
true
862665fbd4c26ebe857973e7542ee1d2d8e21acf
a30ca8b56191b552ebdd779f19073e850db93011
v1.0
instruct
Taco
Taco_81252_I
Given a binary tree, you are tasked with finding the longest path from the root to a leaf node where each node in the path satisfies a given condition. The condition is that the value of a node must be greater than the value of its parent. In other words, each step along the path should move from a node to a child with...
class TreeNode: def __init__(self, value): self.value = value self.left = None self.right = None def build_tree(node_list): if not node_list: return None nodes = {node_value: TreeNode(node_value) for node_value, _, _ in node_list} root = nodes[node_list[0][0]] for ...
def test_longest_increasing_path(): from solution import build_tree, longest_increasing_path # Test case 1 node_list_1 = [ (10, 5, 15), (5, -1, -1), (15, 12, 20), (12, -1, -1), (20, -1, -1) ] root_1 = build_tree(node_list_1) assert longest_increasing_path...
[]
[ 0, 0, 0, 0, 0, 0, 0, 1, 0 ]
1
hard
0.111
{ "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(nodes):\n if ...
trial_gpt4o_7
{ "original_instruction": "", "prompt_id": "00081252", "row_id": 81252, "seed_ids": "[20599]" }
0.692915
Taco_81252
I
[ "build_tree", "longest_increasing_path", "process_test_case" ]
3
[ [ "process_test_case", "build_tree" ], [ "process_test_case", "longest_increasing_path" ] ]
2
[ "process_test_case" ]
false
[ "TreeNode" ]
true
pytest
true
[]
true
16b57c51a98205078577343c7feb42fbd2a035e9
01bc229c93535b9a934d7caf5e24fdb1f76975be
v1.0
instruct
Taco
Taco_81335_I
You are designing a string matching algorithm in a DNA sequencing project. Given a target DNA sequence T and a set of N candidate DNA sequences, your task is to find the longest candidate sequence that can be found as a subsequence in the target sequence T. A subsequence of a string is a new string generated from the...
def is_subsequence(target, candidate): it = iter(target) return all(char in it for char in candidate) def find_longest_subsequence(n, T, candidates): longest_match = "" for candidate in candidates: if is_subsequence(T, candidate): if len(candidate) > len(longest_match): ...
def test_example_case(): assert find_longest_subsequence(5, "ACGTACGTGACG", ["ACT", "ACG", "GAT", "TAC", "GACG"]) == "GACG" def test_no_match_case(): assert find_longest_subsequence(3, "ACGT", ["GTA", "CCC", "GGG"]) == "No Match" def test_same_length_different_order_case(): assert find_longest_subsequence...
[ { "docstring": null, "function_declaration": "def is_subsequence(target, candidate):", "function_name": "is_subsequence", "parameter_list": "(target, candidate)" }, { "docstring": null, "function_declaration": "def find_longest_subsequence(n, T, candidates):", "function_name": "find_...
[ 0, 0, 0, 0, 0, 0, 0, 1, 0 ]
1
hard
0.111
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_subsequence(s, t):\n \"\"\"\n Check if s is a subsequence of t.\n \"\"\"\n it = iter(t)\n return all(c in it for c in s)\n\ndef find_longest_...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00081335", "row_id": 81335, "seed_ids": "[5821]" }
0.688536
Taco_81335
I
[ "is_subsequence", "find_longest_subsequence" ]
2
[ [ "find_longest_subsequence", "is_subsequence" ] ]
1
[]
false
[]
false
pytest
false
[]
true
e1157fb9df2b155893ce06bf6538aa8f9aeaebfc
a2a5536fd8c2c3011f130ba6ea9ce7de4a95dc1f
v1.0
instruct
Taco
Taco_81342_I
Given a matrix of size $ N \times N $ consisting of integers. You are allowed to perform a single operation of rotating the matrix by 90 degrees in the clockwise direction any number of times (i.e., 0, 1, 2, 3 times). The goal is to obtain the maximum possible sum of elements in the main diagonal (i.e., the elements in...
def rotate_matrix_90_clockwise(matrix): """ Rotates the given NxN matrix by 90 degrees in the clockwise direction. """ N = len(matrix) rotated_matrix = [[0]*N for _ in range(N)] for i in range(N): for j in range(N): rotated_matrix[j][N-1-i] = matrix[i][j] return rotated_m...
from solution import rotate_matrix_90_clockwise, max_diagonal_sum def test_rotate_matrix_90_clockwise(): matrix = [ [1, 2, 3], [4, 5, 6], [7, 8, 9] ] rotated = rotate_matrix_90_clockwise(matrix) expected = [ [7, 4, 1], [8, 5, 2], [9, 6, 3] ] asser...
[ { "docstring": "Rotates the given NxN matrix by 90 degrees in the clockwise direction.", "function_declaration": "def rotate_matrix_90_clockwise(matrix):", "function_name": "rotate_matrix_90_clockwise", "parameter_list": "(matrix)" }, { "docstring": "Returns the maximum sum of the elements i...
[ 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 rotate_matrix_90_clockwise(matrix):\n \"\"\"\n Rotates the given N x N matrix 90 degrees clockwise.\n \"\"\"\n N = len(matrix)\n rotated = [[0] ...
trial_gpt4o_3
{ "original_instruction": "", "prompt_id": "00081342", "row_id": 81342, "seed_ids": "[13224]" }
0.523346
Taco_81342
I
[ "rotate_matrix_90_clockwise", "max_diagonal_sum", "main" ]
3
[ [ "max_diagonal_sum", "rotate_matrix_90_clockwise" ] ]
1
[]
false
[]
false
pytest
true
[]
true
37b590c934f200c724289e84cd332fb70e289607
2b43a02aaa237bc02b32c35c290f237f2c19b499
v1.0
instruct
Taco
Taco_81388_I
## Each number in the sequence is the product of its digits if the number is greater than 9, and equal to the number itself otherwise. You are required to compute the nth term of this sequence. ### Input Format The first line contains T, the number of test cases. Each of the next T lines contains a single integer n...
def product_of_digits(n): """ Returns the product of the digits of n. """ product = 1 while n > 0: product *= (n % 10) n //= 10 return product def nth_term(n): """ Returns the nth term in the sequence as defined. """ if n < 10: return n else: ...
from solution import product_of_digits, nth_term, compute_sequence def test_product_of_digits(): assert product_of_digits(11) == 1 assert product_of_digits(14) == 4 assert product_of_digits(123) == 6 assert product_of_digits(999) == 729 def test_nth_term(): assert nth_term(1) == 1 assert nth_t...
[ { "docstring": "Returns the product of the digits of n.", "function_declaration": "def product_of_digits(n):", "function_name": "product_of_digits", "parameter_list": "(n)" }, { "docstring": "Returns the nth term in the sequence as defined.", "function_declaration": "def nth_term(n):", ...
[ 0, 0, 1, 0 ]
1
hard
0.25
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl", "solution_code": "def digit_product(num):\n \"\"\"\n Returns the product of the digits of an integer num.\n \"\"\"\n product = 1\n while num > 0:\n digit = num...
trial_gpt4o_3
{ "original_instruction": "", "prompt_id": "00081388", "row_id": 81388, "seed_ids": "[16355]" }
0.662276
Taco_81388
I
[ "product_of_digits", "nth_term", "compute_sequence" ]
3
[ [ "compute_sequence", "nth_term" ], [ "nth_term", "product_of_digits" ] ]
2
[]
false
[]
false
pytest
true
[]
true
91637095912894ecc6f60ce85b813419b99d7ab0
b93edcaea5bf4a872a4a07f0cb10306b8f1e1ab7
v1.0
instruct
Taco
Taco_81408_I
There is a large national park with several scenic spots connected by hiking trails. You are a ranger stationed at this park, and your task is to find the best way to cover the entire park, visiting all scenic spots with the minimum number of distinct trail segments. Each trail segment is a two-way path connecting two...
def find(parent, i): # A utility function to find set of an element i (uses path compression technique) if parent[i] == i: return i else: parent[i] = find(parent, parent[i]) return parent[i] def union(parent, rank, x, y): # A function that does union of two sets of x and y (uses...
def test_hiking_trip(): # Test case 1 n, m = 5, 5 trails = [(1, 2), (1, 3), (3, 4), (2, 4), (4, 5)] result = hiking_trip(n, m, trails) assert result == (4, [1]) # Test case 2 n, m = 2, 1 trails = [(1, 2)] result = hiking_trip(n, m, trails) assert result == (1, [1]) # Test c...
[ { "docstring": null, "function_declaration": "def find(parent, i):", "function_name": "find", "parameter_list": "(parent, i)" }, { "docstring": null, "function_declaration": "def union(parent, rank, x, y):", "function_name": "union", "parameter_list": "(parent, rank, x, y)" }, ...
[ 0, 0, 0, 1, 1 ]
2
medium
0.4
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl", "solution_code": "from collections import defaultdict, deque\n\ndef find_min_trail_coverage(n, m, trails):\n # Build the adjacency list representation of the park's graph\n gr...
trial_gpt4o_4
{ "original_instruction": "", "prompt_id": "00081408", "row_id": 81408, "seed_ids": "[24214]" }
0.675764
Taco_81408
I
[ "find", "union", "kruskal_mst", "hiking_trip" ]
4
[ [ "hiking_trip", "kruskal_mst" ], [ "kruskal_mst", "find" ], [ "kruskal_mst", "union" ], [ "union", "find" ] ]
4
[]
false
[]
false
pytest
false
[]
true
671028aafdf06c99b1ced1b3fd93e89d13366797
77fd6ba55423a988e7a16cf1022b3d133fb751ec
v1.0
instruct
Taco
Taco_81411_I
Given an unsorted array of integers, write a function to sort the array using the quicksort algorithm. Example 1: Input: arr = [10, 7, 8, 9, 1, 5] Output: [1, 5, 7, 8, 9, 10] Example 2: Input: arr = [1, 4, 3, 5, 6, 2] Output: [1, 2, 3, 4, 5, 6] Your Task: You don't need to read input or print anything. Complete the ...
def partition(arr, low, high): i = low - 1 pivot = arr[high] for j in range(low, high): if arr[j] <= pivot: i += 1 arr[i], arr[j] = arr[j], arr[i] arr[i + 1], arr[high] = arr[high], arr[i + 1] return i + 1 def quicksort(arr, low, high): if low < high: ...
from solution import partition, quicksort def test_quicksort(): arr1 = [10, 7, 8, 9, 1, 5] quicksort(arr1, 0, len(arr1) - 1) assert arr1 == [1, 5, 7, 8, 9, 10] arr2 = [1, 4, 3, 5, 6, 2] quicksort(arr2, 0, len(arr2) - 1) assert arr2 == [1, 2, 3, 4, 5, 6] arr3 = [3, 6, 8, 10, 1, 2, 1] q...
[ { "docstring": null, "function_declaration": "def partition(arr, low, high):", "function_name": "partition", "parameter_list": "(arr, low, high)" }, { "docstring": null, "function_declaration": "def quicksort(arr, low, high):", "function_name": "quicksort", "parameter_list": "(ar...
[ 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 partition(arr, low, high):\n pivot = arr[high]\n i = low - 1\n for j in range(low, high):\n if arr[j] <= pivot:\n i += 1\n ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00081411", "row_id": 81411, "seed_ids": "[16332]" }
0.551543
Taco_81411
I
[ "partition", "quicksort" ]
2
[ [ "quicksort", "partition" ] ]
1
[]
false
[]
false
pytest
true
[]
true
9c5a53c210c972cd9ad361fdb51a9d855f252c70
3a54e5b943d37ae3205d027f7bcb0164207a66ae
v1.0
instruct
Taco
Taco_81424_I
You are given a string $s$ and an integer $k$. Your task is to determine if $s$ can be transformed into a valid palindrome by removing at most $k$ characters from it. A palindrome is a string that reads the same forwards and backwards. ------ Input ------ The first line contains an integer $T$ denoting the number of t...
def can_be_palindrome(s, k): def min_deletions_to_palindrome(s): n = len(s) dp = [[0] * n for _ in range(n)] for l in range(2, n + 1): for i in range(n - l + 1): j = i + l - 1 if s[i] == s[j]: dp[i][j] = dp[i + 1][j - 1...
def test_can_be_palindrome(): assert can_be_palindrome("abca", 1) == True assert can_be_palindrome("abcba", 0) == True assert can_be_palindrome("abcda", 3) == True assert can_be_palindrome("aabbcc", 2) == False assert can_be_palindrome("racecar", 0) == True assert can_be_palindrome("racecar", 1)...
[ { "docstring": null, "function_declaration": "def can_be_palindrome(s, k):", "function_name": "can_be_palindrome", "parameter_list": "(s, k)" }, { "docstring": null, "function_declaration": "def process_test_cases(test_cases):", "function_name": "process_test_cases", "parameter_l...
[ 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 can_be_palindrome(s, k):\n def min_deletions_to_palindrome(s):\n n = len(s)\n dp = [[0] * n for _ in range(n)]\n \n for l in ran...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00081424", "row_id": 81424, "seed_ids": "[14473]" }
0.891385
Taco_81424
I
[ "can_be_palindrome", "process_test_cases", "parse_input", "solve" ]
4
[ [ "process_test_cases", "can_be_palindrome" ], [ "solve", "parse_input" ], [ "solve", "process_test_cases" ] ]
3
[ "process_test_cases", "parse_input" ]
false
[]
false
pytest
false
[]
true
1a7ae70e2d344619a208ced38aa7929d7c414d69
8d7f6a8f719670f249252b59d3f9ba1a7cbbb307
v1.0
instruct
Taco
Taco_81431_I
In a game, you are given a grid of size N x M where each cell contains either a 0 or a 1. The goal is to find the largest rectangle containing only 1s and return its area. The rectangle can be of varying sizes. You are required to write a program to find the area of the largest rectangle containing only 1s in the give...
def maximalRectangle(matrix): if not matrix or not matrix[0]: return 0 max_area = 0 heights = [0] * len(matrix[0]) for row in matrix: for i in range(len(row)): heights[i] = heights[i] + 1 if row[i] == '1' else 0 max_area = max(max_area, largestRectangleArea(heights...
def test_maximalRectangle_small_grid(): matrix = [ ['1', '0', '1', '0', '0'], ['1', '0', '1', '1', '1'], ['1', '1', '1', '1', '1'], ['1', '0', '0', '1', '0'] ] assert maximalRectangle(matrix) == 6 def test_maximalRectangle_single_row(): matrix = [ ['1', '1', '1',...
[ { "docstring": null, "function_declaration": "def maximalRectangle(matrix):", "function_name": "maximalRectangle", "parameter_list": "(matrix)" }, { "docstring": null, "function_declaration": "def largestRectangleArea(heights):", "function_name": "largestRectangleArea", "paramete...
[ 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 maximalRectangle(grid):\n if not grid:\n return 0\n\n max_area = 0\n rows, cols = len(grid), len(grid[0])\n heights = [0] * cols\n\n for ...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00081431", "row_id": 81431, "seed_ids": "[6304]" }
0.746755
Taco_81431
I
[ "maximalRectangle", "largestRectangleArea" ]
2
[ [ "maximalRectangle", "largestRectangleArea" ] ]
1
[]
false
[]
false
pytest
false
[]
true
f83944aee4ad4c3b69f066921e6a77c9d18f9250
4e06d0c4de1a4574dd04fd11fcce881120ce34de
v1.0
instruct
Taco
Taco_81441_I
Given an array of integers, return an array where each element is the number of smaller elements to the right of that element. Input Format An array of integers $\boldsymbol{arr}$ of length $\boldsymbol{n}$. Constraints $1\leq n\leq 2\times10^5$ $-10^9\leq arr[i]\leq 10^9$ Output Format Return an array of integ...
def count_smaller_elements(arr): """ Given an array of integers, return an array where each element is the number of smaller elements to the right of that element. :param arr: List[int] - an array of integers :return: List[int] - an array with counts of smaller elements to the right """ n =...
from solution import count_smaller_elements def test_sample_input(): assert count_smaller_elements([5, 2, 6, 1]) == [2, 1, 1, 0] def test_single_element(): assert count_smaller_elements([10]) == [0] def test_all_equal_elements(): assert count_smaller_elements([2, 2, 2, 2]) == [0, 0, 0, 0] def test_decre...
[ { "docstring": "Given an array of integers, return an array where each element is the number of smaller elements to the right of that element.\n\n:param arr: List[int] - an array of integers\n:return: List[int] - an array with counts of smaller elements to the right", "function_declaration": "def count_smal...
[ 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 count_smaller_elements_to_right(arr):\n \"\"\"\n Returns an array where each element is the count of smaller elements to the right of that element in the...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00081441", "row_id": 81441, "seed_ids": "[12696]" }
0.691261
Taco_81441
I
[ "count_smaller_elements", "binary_search" ]
2
[ [ "count_smaller_elements", "binary_search" ] ]
1
[]
false
[]
false
pytest
true
[]
true
e367b08f6dd62a787e6052e792c6367d0d793470
0c140aab144f1efb4f6e9e662919f801760da279
v1.0
instruct
Taco
Taco_81448_I
You are given a positive integer number n. Your task is to add the fewest number of digits to n such that the resulting number is a palindrome and has an even number of digits. A palindrome is a number that reads the same backward as forward. If it's not possible to make such a number by adding up to 3 digits, print ...
def is_palindrome(s): return s == s[::-1] def extend_number_to_palindrome(n): n_str = str(n) for i in range(3, -1, -1): for j in range(10**i): potential_palindrome = n_str + str(j) if is_palindrome(potential_palindrome) and len(potential_palindrome) % 2 == 0: ...
from solution import extend_number_to_palindrome def test_extend_number_to_palindrome(): assert extend_number_to_palindrome(123) == 123321, "Test case 1 failed" assert extend_number_to_palindrome(4567) == -1, "Test case 2 failed" assert extend_number_to_palindrome(12) in (1212, 1221), "Test case 3 failed" ...
[ { "docstring": null, "function_declaration": "def is_palindrome(s):", "function_name": "is_palindrome", "parameter_list": "(s)" }, { "docstring": null, "function_declaration": "def extend_number_to_palindrome(n):", "function_name": "extend_number_to_palindrome", "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 create_palindrome(n):\n n_str = str(n)\n for i in range(1, 4):\n candidate = n_str + n_str[-i:][::-1]\n if len(candidate) % 2 == 0 and cand...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00081448", "row_id": 81448, "seed_ids": "[23117]" }
0.810107
Taco_81448
I
[ "is_palindrome", "extend_number_to_palindrome" ]
2
[ [ "extend_number_to_palindrome", "is_palindrome" ] ]
1
[]
false
[]
false
pytest
true
[]
true
e37838adedc171ec720de2b4ac9fa887916f26ec
5fba7c411d133df7c4b8dbb88476db53a59afcc1
v1.0
instruct
Taco
Taco_81501_I
A top-secret experiment involving genetically modified plants is being conducted on the planet Yavin. The plants exhibit unique growth cycles, with varying times to reach full maturity. Each plant type grows in cycles, repeating its growth pattern infinitely. The research team needs to predict which plant types will ma...
import math from functools import reduce def lcm(a, b): """ Helper function to find the least common multiple (LCM) of two numbers. """ return abs(a * b) // math.gcd(a, b) def earliest_maturity_day(n, cycles): """ Returns the earliest day on which all plant types will mature simultaneously. ...
from solution import earliest_maturity_day def test_single_cycle(): assert earliest_maturity_day(1, [4]) == 4 def test_two_cycles(): assert earliest_maturity_day(2, [6, 8]) == 24 def test_three_cycles(): assert earliest_maturity_day(3, [3, 5, 7]) == 105 def test_prime_cycles(): assert earliest_matur...
[ { "docstring": "Helper function to find the least common multiple (LCM) of two numbers.", "function_declaration": "def lcm(a, b):", "function_name": "lcm", "parameter_list": "(a, b)" }, { "docstring": "Returns the earliest day on which all plant types will mature simultaneously.\n\nParameter...
[ 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": "from math import gcd\nfrom functools import reduce\n\ndef lcm(a, b):\n \"\"\"\n Returns the least common multiple of a and b.\n \"\"\"\n return a * b /...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00081501", "row_id": 81501, "seed_ids": "[25372]" }
0.701267
Taco_81501
I
[ "lcm", "earliest_maturity_day" ]
2
[ [ "earliest_maturity_day", "lcm" ] ]
1
[]
false
[]
false
pytest
true
[]
true
8870749d1e7a3ea04f82ebab9fe79918140f346d
026142990890641eb455bac8e31bc9677891dd47
v1.0
instruct
Taco
Taco_81526_I
Alice and Bob are playing a game where they take turns choosing numbers from a list. The player who makes the final move wins. The game starts with a list of distinct positive integers. In each player's turn, they must choose a number from the list such that the chosen number is a divisor of the current maximum number ...
def has_winning_strategy(numbers): numbers.sort(reverse=True) move_count = 0 while numbers: current_max = numbers[0] move_count += 1 numbers = [num for num in numbers if num % current_max != 0] return move_count % 2 == 1 def alice_or_bob(test_cases): results = [] ...
import pytest from solution import has_winning_strategy, alice_or_bob, parse_input def test_has_winning_strategy(): assert has_winning_strategy([3, 9, 6]) == True assert has_winning_strategy([5, 10, 20, 25]) == False assert has_winning_strategy([1, 2, 4, 8, 16]) == True assert has_winning_strategy([2, ...
[ { "docstring": null, "function_declaration": "def has_winning_strategy(numbers):", "function_name": "has_winning_strategy", "parameter_list": "(numbers)" }, { "docstring": null, "function_declaration": "def alice_or_bob(test_cases):", "function_name": "alice_or_bob", "parameter_l...
[ 0, 0, 0, 0, 0, 0, 1, 0, 1, 0 ]
2
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl", "solution_code": "def determine_winner(test_cases):\n results = []\n for case in test_cases:\n N, numbers = case\n numbers.sort(reverse=True)\n move_count...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00081526", "row_id": 81526, "seed_ids": "[3087]" }
0.831292
Taco_81526
I
[ "has_winning_strategy", "alice_or_bob", "parse_input" ]
3
[ [ "alice_or_bob", "has_winning_strategy" ] ]
1
[ "parse_input" ]
false
[]
false
pytest
true
[]
true
908447df4a45f79676ace1044077ca128054a550
d5ec69040be6e9db0fbec9604e0f8a6db62684c0
v1.0
instruct
Taco
Taco_81551_I
-----General Statement:----- Write a program to determine if a given string is a valid identifier in a programming language. -----Input:----- The first integer indicates the number of strings following it. Each subsequent string represents a potential identifier. -----Output:----- For each string, output "Yes" if it ...
def is_valid_identifier(identifier): """ Returns whether the given string is a valid identifier. An identifier is valid if it starts with a letter (A-Z, a-z) or an underscore (_), followed by letters, digits (0-9), or underscores. """ if not identifier: return False if not (iden...
from solution import is_valid_identifier, validate_identifiers def test_is_valid_identifier(): assert is_valid_identifier("_validIdentifier") == True assert is_valid_identifier("1Invalid") == False assert is_valid_identifier("anotherValid_id3") == True assert is_valid_identifier("_invalid123") == True ...
[ { "docstring": "Returns whether the given string is a valid identifier.\nAn identifier is valid if it starts with a letter (A-Z, a-z) or an underscore (_),\nfollowed by letters, digits (0-9), or underscores.", "function_declaration": "def is_valid_identifier(identifier):", "function_name": "is_valid_ide...
[ 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_valid_identifier(s):\n \"\"\"\n Returns \"Yes\" if s is a valid identifier, \"No\" otherwise.\n \"\"\"\n if not s:\n return \"No\"\n ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00081551", "row_id": 81551, "seed_ids": "[164]" }
0.604055
Taco_81551
I
[ "is_valid_identifier", "validate_identifiers" ]
2
[ [ "validate_identifiers", "is_valid_identifier" ] ]
1
[]
false
[]
false
pytest
true
[]
true
98d8ff400f0deb89c17f3d08bb2db6f1e8ca932b
8899d3f551a8dfd012eb00e3c649cde2a86c8b85
v1.0
instruct
Taco
Taco_81673_I
In a distant land, there is a famous detective named Sherlock who is very fond of puzzles. One day, he encountered a lock which can only be opened by solving a unique problem. The lock has a sequence of `n` numbers, but to open it, Sherlock needs to find the maximum possible sum of any subarray of this sequence. A sub...
def max_subarray_sum(nums): """ Returns the maximum subarray sum using Kadane's algorithm. """ max_sum = current_sum = nums[0] for num in nums[1:]: current_sum = max(num, current_sum + num) max_sum = max(max_sum, current_sum) return max_sum def max_sum_after_one_negation(n, nums...
from solution import max_subarray_sum, max_sum_after_one_negation, solve def test_max_subarray_sum(): assert max_subarray_sum([2, -1, 2, 3]) == 6 assert max_subarray_sum([-1, -2, -3, -4, -5]) == -1 assert max_subarray_sum([1, 2, 3]) == 6 def test_max_sum_after_one_negation(): assert max_sum_after_one_...
[ { "docstring": "Returns the maximum subarray sum using Kadane's algorithm.", "function_declaration": "def max_subarray_sum(nums):", "function_name": "max_subarray_sum", "parameter_list": "(nums)" }, { "docstring": "Returns the maximum subarray sum possible after at most one negation of any s...
[ 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 max_subarray_with_negation(sequence):\n def kadane(arr):\n max_ending_here = max_so_far = arr[0]\n for x in arr[1:]:\n max_ending_h...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00081673", "row_id": 81673, "seed_ids": "[20811]" }
0.694201
Taco_81673
I
[ "max_subarray_sum", "max_sum_after_one_negation", "solve", "main" ]
4
[ [ "max_sum_after_one_negation", "max_subarray_sum" ], [ "solve", "max_sum_after_one_negation" ] ]
2
[]
false
[]
false
pytest
true
[]
true
04d8fdc314a689694b24a9378f1e3e76d02cdb20
4cdc665787660855058f5f1280cd3ce460b2fa0f
v1.0
instruct
Taco
Taco_81722_I
You are given an integer array nums of length n. Determine if there are three distinct elements in the array whose sum is zero. If there are: 1. Print "YES" followed by the three elements in non-decreasing order. 2. If no such triplet exists, print "NO". -----Input----- The first line contains a single integer n (3 ...
def find_triplet(nums): """ This function takes a list of integers and returns a triplet that sums to zero if such a triplet exists, otherwise it returns "NO". """ nums.sort() n = len(nums) for i in range(n-2): if i > 0 and nums[i] == nums[i-1]: continue left...
from solution import find_triplet, print_triplet_result def test_find_triplet_exists(): assert find_triplet([-1, 0, 1, 2, -1, -4]) == ("YES", [-1, -1, 2]) assert find_triplet([-2, -1, 0, 1, 2]) == ("YES", [-2, 0, 2]) assert find_triplet([-1, 0, 1, -1, 1, 1]) == ("YES", [-1, 0, 1]) assert find_triplet([...
[ { "docstring": "This function takes a list of integers and returns a triplet that sums to zero if such a triplet exists,\notherwise it returns \"NO\".", "function_declaration": "def find_triplet(nums):", "function_name": "find_triplet", "parameter_list": "(nums)" }, { "docstring": null, ...
[ 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": "def find_triplet(nums):\n nums.sort()\n n = len(nums)\n \n for i in range(n - 2):\n if i > 0 and nums[i] == nums[i - 1]:\n continue\n...
trial_gpt4o_3
{ "original_instruction": "", "prompt_id": "00081722", "row_id": 81722, "seed_ids": "[19131]" }
0.709274
Taco_81722
I
[ "find_triplet", "print_triplet_result" ]
2
[ [ "print_triplet_result", "find_triplet" ] ]
1
[]
false
[]
false
pytest
true
[]
true
35e35df323c2b8ad5fd4dcf47679f9f2daaa6b5b
3f0c2d46408915eff194b22ddc842f653f3f482d
v1.0
instruct
Taco
Taco_81753_I
Given a set of line segments in a 2D plane, determine if any two line segments intersect each other. Input The first line is an integer $ n $ (2 ≤ $ n $ ≤ 50) representing the number of line segments. The next $ n $ lines each contain four floating point numbers $ x_1 $, $ y_1 $, $ x_2 $, $ y_2 $ representing the en...
def do_lines_intersect(x1, y1, x2, y2, x3, y3, x4, y4): def ccw(ax, ay, bx, by, cx, cy): return (cy - ay) * (bx - ax) > (by - ay) * (cx - ax) def intersect(ax, ay, bx, by, cx, cy, dx, dy): return ccw(ax, ay, cx, cy, dx, dy) != ccw(bx, by, cx, cy, dx, dy) and \ ccw(ax, ay, bx, by,...
from solution import do_lines_intersect, any_intersections, parse_input, check_intersection def test_do_lines_intersect(): assert do_lines_intersect(0.0, 0.0, 1.0, 1.0, 0.0, 1.0, 1.0, 0.0) == True assert do_lines_intersect(0.0, 0.0, 1.0, 1.0, 2.0, 2.0, 3.0, 3.0) == False assert do_lines_intersect(0.0, 0.0,...
[ { "docstring": null, "function_declaration": "def do_lines_intersect(x1, y1, x2, y2, x3, y3, x4, y4):", "function_name": "do_lines_intersect", "parameter_list": "(x1, y1, x2, y2, x3, y3, x4, y4)" }, { "docstring": null, "function_declaration": "def any_intersections(line_segments):", ...
[ 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": "def do_segments_intersect(p1, q1, p2, q2):\n \"\"\"\n Function to determine if two line segments intersect.\n \"\"\"\n def on_segment(p, q, r):\n ...
trial_gpt4o_3
{ "original_instruction": "", "prompt_id": "00081753", "row_id": 81753, "seed_ids": "[8648]" }
0.628319
Taco_81753
I
[ "do_lines_intersect", "any_intersections", "parse_input", "check_intersection" ]
4
[ [ "any_intersections", "do_lines_intersect" ], [ "check_intersection", "any_intersections" ], [ "check_intersection", "parse_input" ] ]
3
[ "parse_input" ]
false
[]
false
pytest
true
[]
true
89e1aa0ba88fabb10ded0746bfb77f623b8673fe
b942d2f8123f2257db771fbee74d5b481adfa85b
v1.0
instruct
Taco
Taco_81786_I
A group of friends are playing a board game that involves rolling two six-sided dice. To add some excitement, they decided to introduce a special rule: If the absolute difference between the two numbers rolled is a prime number, they will perform a special action. Your task is to write a function that takes two number...
def is_prime(n): """ Helper function to check if a number is a prime number. """ if n <= 1: return False if n in (2, 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 Fal...
from solution import special_action def test_special_action_prime_diff(): assert special_action(5, 2) == "YES" assert special_action(6, 1) == "YES" assert special_action(3, 1) == "YES" def test_special_action_non_prime_diff(): assert special_action(4, 4) == "NO" assert special_action(6, 2) == "NO"...
[ { "docstring": "Helper function to check if a number is a prime number.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Determines whether the absolute difference between two dice rolls\nis a prime number.\n\nParameters:\n...
[ 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(n):\n \"\"\"\n Helper function to check if a number is a prime number.\n \"\"\"\n if n <= 1:\n return False\n if n in (2, 3):\n ...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00081786", "row_id": 81786, "seed_ids": "[4921]" }
0.598673
Taco_81786
I
[ "is_prime", "special_action" ]
2
[ [ "special_action", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
6ccb3ea6ae1bd81cf8176d80698745e345f07e58
b0a631060e37b14bdee003eafdd95a099ea55ce7
v1.0
instruct
Taco
Taco_81858_I
You are the network administrator of a large organization. The organization uses a system of servers, each identified by a unique number from 1 to N. The servers are interconnected such that each server can directly communicate with some subset of other servers. The communications between the servers are bidirectional,...
def count_components(n, edges): """ Helper function to count the number of connected components in an undirected graph. """ from collections import defaultdict, deque def bfs(node): queue = deque([node]) visited.add(node) while queue: current = queue.popleft() ...
def test_count_components(): assert count_components(4, [(1, 2), (3, 4)]) == 2 assert count_components(3, [(1, 2)]) == 2 assert count_components(5, []) == 5 assert count_components(4, [(1, 2), (2, 3), (3, 4)]) == 1 def test_minimum_new_connections_needed(): assert minimum_new_connections_needed(4, ...
[ { "docstring": "Helper function to count the number of connected components in an undirected graph.", "function_declaration": "def count_components(n, edges):", "function_name": "count_components", "parameter_list": "(n, edges)" }, { "docstring": "Given the number of servers (n), the number ...
[ 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 find(parent, i):\n if parent[i] == i:\n return i\n else:\n parent[i] = find(parent, parent[i])\n return parent[i]\n\ndef union(paren...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00081858", "row_id": 81858, "seed_ids": "[16807]" }
0.639441
Taco_81858
I
[ "count_components", "minimum_new_connections_needed", "solve", "main" ]
4
[ [ "minimum_new_connections_needed", "count_components" ], [ "solve", "minimum_new_connections_needed" ] ]
2
[]
false
[]
false
pytest
false
[]
true
9b9fd4c0b5a51e56d83a7e0fc74fd8232aeb2cc5
fef0ca76e672da0f3170df3188db0ff5880a918d
v1.0
instruct
Taco
Taco_81861_I
## Task Write a function that takes an array of integers as input and returns a new array composed of only the prime numbers from the input array, sorted in ascending order. Prime numbers are integers greater than 1 that are only divisible by 1 and themselves. ### Examples ```python findPrimes([10, 7, 4, 20, 19, 1...
def is_prime(n): """ Determines if n is a prime number. """ if n <= 1: return False if n <= 3: return True if n % 2 == 0 or n % 3 == 0: return False i = 5 while i * i <= n: if n % i == 0 or n % (i + 2) == 0: return False i += 6 retu...
from solution import findPrimes def test_find_primes_example_cases(): assert findPrimes([10, 7, 4, 20, 19, 13]) == [7, 13, 19] assert findPrimes([0, 1, 4, 9, 15, 21]) == [] assert findPrimes([44, 29, 2, 17, 12, 23]) == [2, 17, 23, 29] def test_find_primes_edge_cases(): assert findPrimes([]) == [] ...
[ { "docstring": "Determines if n is a prime number.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Returns an array of prime numbers from the input array, sorted in ascending order.", "function_declaration": "def findP...
[ 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 is_prime(num):\n \"\"\"\n Check if a number is a prime number.\n \"\"\"\n if num <= 1:\n return False\n if num == 2:\n return True...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00081861", "row_id": 81861, "seed_ids": "[2539]" }
0.700849
Taco_81861
I
[ "is_prime", "findPrimes" ]
2
[ [ "findPrimes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
4b94e14d43cc7caabead20ed62cbf75f2b34c9c7
a095d85174cdabb9ac2127fd507de87ef4cd08ac
v1.0
instruct
Taco
Taco_81911_I
Given a sequence of N integers and Q queries, each requiring a transformation of the sequence. Chef wants to improve efficiency by saving intermediate results to answer queries faster. You are given an array a of N integers. Each of the Q queries provides three integers: L, R, and K. For each query, perform the follo...
def digit_sum(n): """Return the sum of the digits of an integer n.""" return sum(int(d) for d in str(n)) def transform_subarray(a, L, R, K): """ Transform the subarray a[L...R] K times as per the problem statement. """ for _ in range(K): for i in range(L, R + 1): a[i] = digi...
from solution import digit_sum, transform_subarray, process_queries def test_digit_sum(): assert digit_sum(123) == 6 assert digit_sum(456) == 15 assert digit_sum(789) == 24 assert digit_sum(12345) == 15 assert digit_sum(67890) == 30 def test_transform_subarray(): assert transform_subarray([123...
[ { "docstring": "Return the sum of the digits of an integer n.", "function_declaration": "def digit_sum(n):", "function_name": "digit_sum", "parameter_list": "(n)" }, { "docstring": "Transform the subarray a[L...R] K times as per the problem statement.", "function_declaration": "def trans...
[ 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 digit_sum(n):\n \"\"\" Utility function to compute the sum of digits of a number \"\"\"\n return sum(int(digit) for digit in str(n))\n\ndef transform_and...
trial_gpt4o_4
{ "original_instruction": "", "prompt_id": "00081911", "row_id": 81911, "seed_ids": "[10006]" }
0.681513
Taco_81911
I
[ "digit_sum", "transform_subarray", "process_queries" ]
3
[ [ "process_queries", "transform_subarray" ], [ "transform_subarray", "digit_sum" ] ]
2
[ "process_queries" ]
false
[]
false
pytest
true
[]
true
702d3e6f34fbe5499aebf8a91080b38407cac511
6df81138622e730afa075831b09f04dca77ef88d
v1.0
instruct
Taco
Taco_81926_I
For a given integer N, define the function `P(N)` as: - `P(N) = 1` if `N` is a perfect number. - `P(N) = 0` otherwise. A perfect number is a positive integer that is equal to the sum of its positive divisors, excluding itself (e.g., 6, 28, etc.). Given two integers `L` and `R`, compute the sum of `P(i) * P(j)` for a...
def is_perfect(n): """ Check if a number is a perfect number. """ if n <= 1: return False divisors_sum = 1 sqrt_n = int(n**0.5) for i in range(2, sqrt_n + 1): if n % i == 0: divisors_sum += i if i != n // i: divisors_sum += n // i r...
from solution import P, perfect_pairs_sum, main def test_is_perfect(): assert P(6) == 1 assert P(28) == 1 assert P(27) == 0 assert P(1) == 0 def test_perfect_pairs_sum_small_range(): assert perfect_pairs_sum(1, 30) == 1 def test_perfect_pairs_sum_no_perfect_numbers(): assert perfect_pairs_sum...
[ { "docstring": "Check if a number is a perfect number.", "function_declaration": "def is_perfect(n):", "function_name": "is_perfect", "parameter_list": "(n)" }, { "docstring": "Returns 1 if n is a perfect number, 0 otherwise.", "function_declaration": "def P(n):", "function_name": "P...
[ 0, 0, 1, 0 ]
1
hard
0.25
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl", "solution_code": "MOD = 10**9 + 7\n\ndef is_perfect_number(N):\n \"\"\"\n Check if a number N is a perfect number.\n \"\"\"\n if N <= 1:\n return False\n divis...
trial_gpt4o_3
{ "original_instruction": "", "prompt_id": "00081926", "row_id": 81926, "seed_ids": "[17306]" }
0.641329
Taco_81926
I
[ "is_perfect", "P", "perfect_pairs_sum", "main" ]
4
[ [ "P", "is_perfect" ], [ "perfect_pairs_sum", "P" ] ]
2
[]
false
[]
false
pytest
true
[]
true
45b3f100f09c0d39f685bb529d695be8ad6a3408
0240e8da54e646ceb0cbee4d2a5887efe721aa2b
v1.0
instruct
Taco
Taco_81931_I
Your task is to calculate the product (denoted as P) of all the palindromic numbers between [A, B]. An integer is called palindromic if it reads the same forwards and backwards. Input format A B Output format P % 1000000007 Constraints 0 < A <= B < 10^18 Sample Input 10 20 Sample Output 121 Explanation 11 i...
def is_palindrome(n): """ Checks if a given number is a palindrome. """ return str(n) == str(n)[::-1] def product_of_palindromes(A, B): """ Calculates the product of all palindromic numbers between A and B, inclusive, and returns the product modulo 1000000007. """ MOD = 1000000007 ...
from solution import product_of_palindromes, is_palindrome def test_is_palindrome(): assert is_palindrome(121) == True assert is_palindrome(123) == False assert is_palindrome(1) == True assert is_palindrome(22) == True assert is_palindrome(12321) == True def test_product_of_palindromes(): asse...
[ { "docstring": "Checks if a given number is a palindrome.", "function_declaration": "def is_palindrome(n):", "function_name": "is_palindrome", "parameter_list": "(n)" }, { "docstring": "Calculates the product of all palindromic numbers between A and B, inclusive,\nand returns the product mod...
[ 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_palindrome(n):\n \"\"\"\n Checks if a given number is a palindrome.\n \"\"\"\n return str(n) == str(n)[::-1]\n\ndef product_of_palindromes(A, B)...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00081931", "row_id": 81931, "seed_ids": "[22751]" }
0.64944
Taco_81931
I
[ "is_palindrome", "product_of_palindromes" ]
2
[ [ "product_of_palindromes", "is_palindrome" ] ]
1
[]
false
[]
false
pytest
true
[]
true
6d3d6cfa4b06398a7d42dca80ff2eb929885769b
bff7c9d3f80246575ccd6660576fce105d57adc9
v1.0
instruct
Taco
Taco_81936_I
Write a program that simulates a simple calculator supporting addition, subtraction, multiplication, division, and modulo operations. The calculator accepts mathematical expressions in infix notation, computes the result, and outputs the answer. The expressions can include integer numbers, and the five operators: `+`,...
import operator def safe_eval(expression): """ Evaluates a mathematical expression using only allowed operators. """ allowed_operators = { '+': operator.add, '-': operator.sub, '*': operator.mul, '/': operator.floordiv, '%': operator.mod } # Replace ...
from solution import safe_eval, process_expressions def test_addition(): assert safe_eval('3+5') == 8 def test_subtraction(): assert safe_eval('10-3') == 7 def test_multiplication(): assert safe_eval('4*2') == 8 def test_division(): assert safe_eval('10/3') == 3 def test_modulo(): assert safe_e...
[ { "docstring": "Evaluates a mathematical expression using only allowed operators.", "function_declaration": "def safe_eval(expression):", "function_name": "safe_eval", "parameter_list": "(expression)" }, { "docstring": null, "function_declaration": "def process_expressions(expressions):"...
[ 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 compute_expression(expression):\n \"\"\"\n Evaluate a simple mathematical expression provided as a string.\n Supported operators: +, -, *, /, %\n \...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00081936", "row_id": 81936, "seed_ids": "[13848]" }
0.569638
Taco_81936
I
[ "safe_eval", "process_expressions" ]
2
[ [ "process_expressions", "safe_eval" ] ]
1
[]
false
[]
false
pytest
true
[]
true
62ddc5f08c399c11dba4a9501b3864aee3b34385
8cb1f6898794bdbe0622782745038114abbc570b
v1.0
instruct
Taco
Taco_81980_I
A palindrome is a word, phrase, number, or other sequence of characters that reads the same forward and backward (ignoring spaces, punctuation, and capitalization). Write a program that checks whether a given string is a palindrome, and identify the longest palindromic substring within the input. The program should ta...
def is_palindrome(s): """ Returns True if s is a palindrome, ignoring spaces, punctuation, and capitalization. """ stripped = ''.join([c.lower() for c in s if c.isalnum()]) return stripped == stripped[::-1] def longest_palindromic_substring(s): """ Returns the longest palindromic substring ...
from solution import is_palindrome, longest_palindromic_substring, process_input_strings def test_is_palindrome(): assert is_palindrome("madam") == True assert is_palindrome("racecar") == True assert is_palindrome("apple") == False assert is_palindrome("noon") == True assert is_palindrome("A man, a...
[ { "docstring": "Returns True if s is a palindrome, ignoring spaces, punctuation, and capitalization.", "function_declaration": "def is_palindrome(s):", "function_name": "is_palindrome", "parameter_list": "(s)" }, { "docstring": "Returns the longest palindromic substring in s.", "function...
[ 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 is_palindrome(s):\n filtered_s = ''.join([c.lower() for c in s if c.isalnum()])\n return filtered_s == filtered_s[::-1]\n\ndef longest_palindromic_substr...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00081980", "row_id": 81980, "seed_ids": "[22093]" }
0.757018
Taco_81980
I
[ "is_palindrome", "longest_palindromic_substring", "process_input_strings" ]
3
[ [ "process_input_strings", "is_palindrome" ], [ "process_input_strings", "longest_palindromic_substring" ] ]
2
[]
false
[]
false
pytest
true
[]
true
4dbf0c9f57590cb577bd34434f6852f93976352a
d341612013447ded8384067680046bc0b328c8d2
v1.0
instruct
Taco
Taco_81983_I
Julia is planning to make a rectangular flowerbed in her garden, using some wooden planks she found in her garage. Each wooden plank has a given length, and she wants to use these planks to form the perimeter of the rectangle. However, she can only use each plank once. Write a program to determine if she can form a re...
def can_form_rectangle(n, planks): from collections import Counter # Count the frequency of each plank length frequency = Counter(planks) # Count pairs of planks pairs = sum(count // 2 for count in frequency.values()) # To form a rectangle, we need at least 4 planks (2 pairs) ...
from solution import rectangle_possible def test_rectangle_possible(): assert rectangle_possible(6, [2, 2, 2, 2, 4, 4]) == "yes" assert rectangle_possible(5, [1, 2, 3, 4, 5]) == "no" assert rectangle_possible(8, [3, 3, 3, 3, 5, 5, 5, 5]) == "yes" assert rectangle_possible(4, [1, 1, 1, 1]) == "yes" ...
[ { "docstring": null, "function_declaration": "def can_form_rectangle(n, planks):", "function_name": "can_form_rectangle", "parameter_list": "(n, planks)" }, { "docstring": null, "function_declaration": "def rectangle_possible(n, plank_lengths):", "function_name": "rectangle_possible"...
[ 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 could_form_rectangle(n, planks):\n \"\"\"\n Determines if a rectangle can be formed using given planks.\n \n :param n: Number of planks\n :param...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00081983", "row_id": 81983, "seed_ids": "[22913]" }
0.680485
Taco_81983
I
[ "can_form_rectangle", "rectangle_possible" ]
2
[ [ "rectangle_possible", "can_form_rectangle" ] ]
1
[]
false
[]
false
pytest
true
[]
true
7c1bbc07e3cabeb8a23f50a52acedaa6232df718
7cf69b99d2bbe65dbaf5262bf8217343098d0265
v1.0
instruct
Taco
Taco_82067_I
You are given an array `arr` of N integers representing the preorder traversal of a binary search tree. The task is to construct the BST from the given preorder traversal and then find its postorder traversal. Example 1: Input: N = 5 arr = [4, 2, 1, 3, 6] Output: [1, 3, 2, 6, 4] Explanation: The given preorder travers...
class Node: def __init__(self, value): self.value = value self.left = None self.right = None def construct_bst_from_preorder(preorder): if not preorder: return None root = Node(preorder[0]) stack = [root] for value in preorder[1:]: if value < stack[...
from solution import findPostorderFromPreorder def test_example_1(): assert findPostorderFromPreorder(5, [4, 2, 1, 3, 6]) == [1, 3, 2, 6, 4] def test_example_2(): assert findPostorderFromPreorder(3, [8, 5, 7]) == [7, 5, 8] def test_single_node(): assert findPostorderFromPreorder(1, [10]) == [10] def tes...
[]
[ 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, key):\n self.left = None\n self.right = None\n self.value = key\n\ndef constructBSTFromPreorder(preord...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00082067", "row_id": 82067, "seed_ids": "[11445]" }
0.512803
Taco_82067
I
[ "construct_bst_from_preorder", "postorder_traversal", "findPostorderFromPreorder" ]
3
[ [ "findPostorderFromPreorder", "construct_bst_from_preorder" ], [ "findPostorderFromPreorder", "postorder_traversal" ] ]
2
[]
false
[ "Node" ]
true
pytest
true
[]
true
2dd4ee55c8066e0ae1d1850d3cd64921668e8b09
1709dbfb459a85a4284da618fbf576de4bbd367c
v1.0
instruct
Taco
Taco_82190_I
Given an integer n, the task is to determine if it's possible to represent n as a sum of exactly two distinct prime numbers. Return true if possible, otherwise, return false. Example 1: Input: n = 10 Output: True Explanation: 10 can be represented as 3 + 7, where both 3 and 7 are prime numbers. Example 2: Input: n = ...
def is_prime(num): """Return True if num is a prime number, else False.""" if num <= 1: return False if num <= 3: return True if num % 2 == 0 or num % 3 == 0: return False i = 5 while i * i <= num: if num % i == 0 or num % (i + 2) == 0: return False ...
from solution import isSumOfTwoPrimes def test_isSumOfTwoPrimes_10(): assert isSumOfTwoPrimes(10) == True def test_isSumOfTwoPrimes_11(): assert isSumOfTwoPrimes(11) == False def test_isSumOfTwoPrimes_15(): assert isSumOfTwoPrimes(15) == True def test_isSumOfTwoPrimes_34(): assert isSumOfTwoPrimes(3...
[ { "docstring": "Return True if num is a prime number, else False.", "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": "Return True if n can be represented as the sum of two distinct prime numbers, otherwise, return False.",...
[ 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 is_prime(num):\n if num <= 1:\n return False\n if num <= 3:\n return True\n if num % 2 == 0 or num % 3 == 0:\n return False\n ...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00082190", "row_id": 82190, "seed_ids": "[4198]" }
0.666359
Taco_82190
I
[ "is_prime", "isSumOfTwoPrimes" ]
2
[ [ "isSumOfTwoPrimes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
23adc3af23351efe367e96b7ed44413f60eba07b
65418532695a4ec69a1cc369898cad79fb881373
v1.0
instruct
Taco
Taco_82192_I
You are given a string `S` of length `N` consisting of lowercase English letters. Chef wants to create a palindromic string from `S` by rearranging its characters. A string is called palindromic if it reads the same forward and backward. Chef also wants to maximize the number of distinct palindromic substrings present ...
from collections import Counter def can_form_palindrome(s): """ Determines if a given string can be rearranged to form a palindrome. """ counter = Counter(s) odd_count = sum(1 for count in counter.values() if count % 2 != 0) return odd_count <= 1 def rearrange_to_palindrome(s): """ Rea...
from solution import can_form_palindrome, rearrange_to_palindrome, process_test_cases def test_can_form_palindrome(): assert can_form_palindrome("aabb") == True assert can_form_palindrome("abcde") == False assert can_form_palindrome("aaaaaa") == True assert can_form_palindrome("racecar") == True as...
[ { "docstring": "Determines if a given string can be rearranged to form a palindrome.", "function_declaration": "def can_form_palindrome(s):", "function_name": "can_form_palindrome", "parameter_list": "(s)" }, { "docstring": "Rearranges a given string to form a palindrome if possible, otherwi...
[ 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 can_form_palindrome(s):\n \"\"\"\n Determines if a string can be rearranged to form a palindrome. \n If yes, returns one such rearrangement, otherwise...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00082192", "row_id": 82192, "seed_ids": "[9742]" }
0.756007
Taco_82192
I
[ "can_form_palindrome", "rearrange_to_palindrome", "process_test_cases" ]
3
[ [ "process_test_cases", "rearrange_to_palindrome" ], [ "rearrange_to_palindrome", "can_form_palindrome" ] ]
2
[ "process_test_cases" ]
false
[]
false
pytest
true
[]
true
622ad93047c661915017246a5840356e8109b4f4
bcbd2fc529a91c9368ffc4f958a54448ebccc5bb
v1.0
instruct
Taco
Taco_82194_I
A group of explorers are on a quest to recover a lost treasure deep within a magical forest. The forest can be represented as a 2D grid of size MxN, where each cell has a certain amount of gold coins. The starting point for the explorers is the top-left cell (0, 0) and the treasure is at the bottom-right cell (M-1, N-1...
def max_gold_coins(grid): M = len(grid) N = len(grid[0]) # Create a dp table to store the maximum coins up to each cell dp = [[0]*N for _ in range(M)] dp[0][0] = grid[0][0] # Starting point # Fill the first row (can only come from the left) for j in range(1, N): dp[0]...
def test_max_gold_coins(): grid1 = [ [1, 3, 1], [1, 5, 1], [4, 2, 1] ] assert max_gold_coins(grid1) == 12 grid2 = [ [0, 3, 1], [9, 2, 1], [4, 6, 1] ] assert max_gold_coins(grid2) == 20 grid3 = [ [1, 2, 3], [4, 5, 6], ...
[ { "docstring": null, "function_declaration": "def max_gold_coins(grid):", "function_name": "max_gold_coins", "parameter_list": "(grid)" }, { "docstring": null, "function_declaration": "def read_input_and_solve():", "function_name": "read_input_and_solve", "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 max_gold_coins(M, N, grid):\n # Initialize a 2D list with the same dimensions as the grid to store the max coins collected to each cell\n dp = [[0] * N f...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00082194", "row_id": 82194, "seed_ids": "[20455]" }
0.704512
Taco_82194
I
[ "max_gold_coins", "read_input_and_solve" ]
2
[ [ "read_input_and_solve", "max_gold_coins" ] ]
1
[]
false
[]
false
pytest
false
[]
true
21c15eb1977b117017378d3180334c2434f6bed6
7acb946fc8d69880c99381de627048cb00d987ab
v1.0
instruct
Taco
Taco_82262_I
Arpa is participating in a confectionery contest in Arpa’s land to create beautiful and tasty candy chains to impress the judges. A candy chain consists of individual candy pieces, each having a specific sweetness level. The judges have peculiar requirements for the arrangement of candies. To make a valid candy chain: ...
def is_valid_candy_chain(candy_chain): """ Checks if the candy chain meets the requirements: - Each candy piece has a distinct sweetness level. - The total sweetness level is an even number. - Among any three consecutive candy pieces, the total sweetness level is not divisible by 3. """ tota...
def test_case_1(): assert arpas_candy_chain(5, [3, 2, 1, 6, 7]) == None # Prints 1 2 6 7 3 or similar valid configuration def test_case_2(): assert arpas_candy_chain(3, [2, 4, 5]) == None # Prints 2 4 5 def test_case_3(): assert arpas_candy_chain(3, [6, 6, 6]) == None # Prints -1 due to duplicates def te...
[ { "docstring": "Checks if the candy chain meets the requirements:\n- Each candy piece has a distinct sweetness level.\n- The total sweetness level is an even number.\n- Among any three consecutive candy pieces, the total sweetness level is not divisible by 3.", "function_declaration": "def is_valid_candy_ch...
[ 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_valid_chain(chain):\n \"\"\"\n Helper function to check if a given chain is a valid candy chain\n according to the conditions mentioned.\n \"\"\...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00082262", "row_id": 82262, "seed_ids": "[9143]" }
0.664148
Taco_82262
I
[ "is_valid_candy_chain", "arpas_candy_chain" ]
2
[ [ "arpas_candy_chain", "is_valid_candy_chain" ] ]
1
[]
false
[]
false
pytest
false
[]
true
457f85c572a2dc568567bb6c1459e78bc4f9a352
f181d98107f95d3d298bd9c3f04eeccee32f9131
v1.0
instruct
Taco
Taco_82270_I
Farmer John has a barn with `n` stalls, and he wants to place exactly `c` cows in them such that the minimum distance between any two cows is maximized. The stalls are represented by an array of `n` integers, where each integer represents the position of a stall along a straight line. Your task is to write a function ...
def canPlaceCows(stalls, n, c, min_dist): cows_placed = 1 # Place cow in the first stall last_pos = stalls[0] for i in range(1, n): if stalls[i] - last_pos >= min_dist: cows_placed += 1 last_pos = stalls[i] if cows_placed == c: return True ret...
from solution import solve_queries def test_single_query(): queries = [((5, 3), [1, 2, 8, 4, 9])] assert solve_queries(queries) == [3] def test_multiple_queries(): queries = [ ((5, 3), [1, 2, 8, 4, 9]), ((6, 4), [3, 4, 7, 1, 9, 12]) ] assert solve_queries(queries) == [3, 3] def te...
[ { "docstring": null, "function_declaration": "def canPlaceCows(stalls, n, c, min_dist):", "function_name": "canPlaceCows", "parameter_list": "(stalls, n, c, min_dist)" }, { "docstring": null, "function_declaration": "def largestMinDistance(n, c, stalls):", "function_name": "largestMi...
[ 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 can_place_cows(stalls, n, c, min_dist):\n \"\"\"\n Helper function to determine if cows can be placed such that\n the minimum distance between any two...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00082270", "row_id": 82270, "seed_ids": "[5770]" }
0.666244
Taco_82270
I
[ "canPlaceCows", "largestMinDistance", "solve_queries" ]
3
[ [ "largestMinDistance", "canPlaceCows" ], [ "solve_queries", "largestMinDistance" ] ]
2
[ "solve_queries" ]
false
[]
false
pytest
true
[]
true
cd6e00443268eee01c37ed4db7107450891927a1
5f3f03c9af47fb780e49cf43ccec1c1901ba3f8c
v1.0
instruct
Taco
Taco_82280_I
A new bank is revolutionizing financial management with their innovative account balance tracking system. As a software developer, you need to implement a feature to help users monitor their daily transactions and compute their final balance. ------ Input ------ The first line contains an integer T, the number of tes...
def final_balance(test_cases): results = [] for case in test_cases: final_amount = sum(case) results.append(final_amount) return results def parse_input(input_string): data = input_string.strip().split('\n') index = 0 T = int(data[index]) index += 1 test_cases = [] f...
def test_parse_input(): input_string = '2\n3\n-200\n300\n-100\n4\n500\n1000\n-1500\n-500\n' expected_output = [[-200, 300, -100], [500, 1000, -1500, -500]] assert parse_input(input_string) == expected_output def test_final_balance(): test_cases = [[-200, 300, -100], [500, 1000, -1500, -500]] expect...
[ { "docstring": null, "function_declaration": "def final_balance(test_cases):", "function_name": "final_balance", "parameter_list": "(test_cases)" }, { "docstring": null, "function_declaration": "def parse_input(input_string):", "function_name": "parse_input", "parameter_list": "(...
[ 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 compute_balances(test_cases):\n \"\"\"\n Computes the final balance for each test case of daily transactions.\n \n Parameters:\n test_cases (lis...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00082280", "row_id": 82280, "seed_ids": "[3029]" }
0.642472
Taco_82280
I
[ "final_balance", "parse_input", "format_output", "process_transactions" ]
4
[ [ "process_transactions", "final_balance" ], [ "process_transactions", "format_output" ], [ "process_transactions", "parse_input" ] ]
3
[ "parse_input", "format_output" ]
false
[]
false
pytest
false
[]
true
12b84d800eedc733bd226943009ef9e478a07b14
70bfc6ab0bc8686224ddefe1e22dcbdc6feddcea
v1.0
instruct
Taco
Taco_82288_I
Zara, an avid puzzle lover, has recently come across an interesting challenge. The challenge involves a peculiar number game where each number in the sequence has to follow a specific set of rules. Intrigued, she has tasked you with writing a program to help her solve these puzzles more efficiently. You are given a se...
def smallest_enclosing_segment_length(test_cases): results = [] for case in test_cases: N, segments = case total_length = sum(segments) results.append(total_length) return results def parse_input(input_str): lines = input_str.strip().split('\n') test_cases = [] ...
from solution import process def test_sample1(): input_str = "3\n1 2 3\n4\n5 5 5 5\n2\n7 3\n0" expected_output = "6\n20\n10" assert process(input_str) == expected_output def test_single_segment(): input_str = "1\n1000\n0" expected_output = "1000" assert process(input_str) == expected_output d...
[ { "docstring": null, "function_declaration": "def smallest_enclosing_segment_length(test_cases):", "function_name": "smallest_enclosing_segment_length", "parameter_list": "(test_cases)" }, { "docstring": null, "function_declaration": "def parse_input(input_str):", "function_name": "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": "def smallest_enclosing_length(test_cases):\n \"\"\"\n Given multiple test cases, computes the smallest possible enclosing length for each case.\n \"\"\"\n...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00082288", "row_id": 82288, "seed_ids": "[20907]" }
0.593762
Taco_82288
I
[ "smallest_enclosing_segment_length", "parse_input", "process" ]
3
[ [ "process", "parse_input" ], [ "process", "smallest_enclosing_segment_length" ] ]
2
[ "parse_input" ]
false
[]
false
pytest
true
[]
true
092e9eb6691cf5bef5f61162eed8807c7a75906e
194095331ddd974cded4b400dae39b7064b1bc59
v1.0
instruct
Taco
Taco_82340_I
A number N is called a *Wonderful Number* if the sum of its digits is greater than the product of its digits. You are given an array B of size M. You are also given P queries. Each query consists of two integers Y and Z. For each query, find the count of *Wonderful Numbers* in the subarray B[Y:Z]. ------ Input Forma...
def is_wonderful(n): """ Returns True if the number n is a Wonderful Number, otherwise False. A number is Wonderful if the sum of its digits is greater than the product of its digits. """ digits = [int(d) for d in str(n)] digit_sum = sum(digits) digit_product = 1 for d in digits: ...
def test_is_wonderful(): assert is_wonderful(13) == True # 1 + 3 > 1 * 3 assert is_wonderful(24) == False # 2 + 4 <= 2 * 4 assert is_wonderful(36) == False # 3 + 6 <= 3 * 6 assert is_wonderful(45) == False # 4 + 5 <= 4 * 5 assert is_wonderful(56) == False # 5 + 6 <= 5 * 6 assert is_wonderful(10...
[ { "docstring": "Returns True if the number n is a Wonderful Number, otherwise False.\nA number is Wonderful if the sum of its digits is greater than the product of its digits.", "function_declaration": "def is_wonderful(n):", "function_name": "is_wonderful", "parameter_list": "(n)" }, { "doc...
[ 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_wonderful(number):\n \"\"\"\n Check if a given number is a Wonderful Number.\n \"\"\"\n digits = [int(d) for d in str(number)]\n digit_sum = ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00082340", "row_id": 82340, "seed_ids": "[9193]" }
0.684285
Taco_82340
I
[ "is_wonderful", "wonderful_numbers_count", "process_test_cases" ]
3
[ [ "process_test_cases", "wonderful_numbers_count" ], [ "wonderful_numbers_count", "is_wonderful" ] ]
2
[ "process_test_cases" ]
false
[]
false
pytest
false
[]
true
f165ec599f8a359dc8d6a8e636a980da26778368
24585eaae5fc565054b065ccb769c8e1ea450b04
v1.0
instruct
Taco
Taco_82364_I
Aria loves playing with sequences of parentheses. One day, she came up with the idea of generating all possible balanced parenthesis strings. She defined a balanced parenthesis string as follows: - An empty string is considered balanced. - If "A" and "B" are balanced parenthesis strings, then "AB" is also balanced. - ...
def catalan_number(n): """ Function to compute the nth Catalan number, which represents the number of distinct balanced parenthesis strings that can be generated using n pairs of parentheses. """ if n == 0 or n == 1: return 1 # Table to store results of subproblems catalan = [0]...
from solution import count_balanced_parenthesis def test_count_balanced_parenthesis_small_cases(): assert count_balanced_parenthesis(1) == 1 assert count_balanced_parenthesis(2) == 2 assert count_balanced_parenthesis(3) == 5 def test_count_balanced_parenthesis_medium_cases(): assert count_balanced_par...
[ { "docstring": "Function to compute the nth Catalan number, which represents the number of distinct balanced\nparenthesis strings that can be generated using n pairs of parentheses.", "function_declaration": "def catalan_number(n):", "function_name": "catalan_number", "parameter_list": "(n)" }, ...
[ 1, 1 ]
2
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl", "solution_code": "def count_balanced_parentheses(n):\n \"\"\"\n Returns the number of distinct balanced parenthesis strings \n that can be generated with n pairs of parenth...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00082364", "row_id": 82364, "seed_ids": "[3606]" }
0.777846
Taco_82364
I
[ "catalan_number", "count_balanced_parenthesis" ]
2
[ [ "count_balanced_parenthesis", "catalan_number" ] ]
1
[]
false
[]
false
pytest
true
[]
true
e806005a74f16824741539612735a37f5a78d423
ac12fffdbcd61d7f08ef7c0e2931541a1a2eade9
v1.0
instruct
Taco
Taco_82385_I
You are given a 2D grid of dimensions NxM with non-negative integers representing the cost to move through each cell. You start from the top-left cell (1,1) and want to reach the bottom-right cell (N,M). You can only move to the right or down from a cell. Additionally, you are provided with Q queries. Each query consi...
def min_cost_path(grid, N, M): dp = [[0]*M for _ in range(N)] dp[0][0] = grid[0][0] for i in range(1, N): dp[i][0] = dp[i-1][0] + grid[i][0] for j in range(1, M): dp[0][j] = dp[0][j-1] + grid[0][j] for i in range(1, N): for j in range(1, M): dp[i][j] = ...
import pytest from solution import solve def test_example_case(): N, M = 3, 3 grid = [ [1, 2, 3], [4, 5, 6], [7, 8, 9] ] Q = 2 queries = [ [3, 3, 21], [2, 2, 6] ] result = solve(N, M, grid, Q, queries) assert result == ["POSSIBLE", "IMPOSSIBLE"] ...
[ { "docstring": null, "function_declaration": "def min_cost_path(grid, N, M):", "function_name": "min_cost_path", "parameter_list": "(grid, N, M)" }, { "docstring": null, "function_declaration": "def possible_path_to_cost(dp, x, y, C):", "function_name": "possible_path_to_cost", "...
[ 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 check_paths(grid, queries):\n N = len(grid)\n M = len(grid[0])\n \n # Precompute the cost to reach each cell using dynamic programming\n dp = [[...
trial_gpt4o_4
{ "original_instruction": "", "prompt_id": "00082385", "row_id": 82385, "seed_ids": "[11330]" }
0.700638
Taco_82385
I
[ "min_cost_path", "possible_path_to_cost", "solve" ]
3
[ [ "solve", "min_cost_path" ], [ "solve", "possible_path_to_cost" ] ]
2
[]
false
[]
false
pytest
true
[]
true
3dbd6655245b1a4d5d2eeeadeb06ac35ad3a5070
83c834f71b36377759ecdc32083017de2991cc46
v1.0
instruct
Taco
Taco_82389_I
Alex is playing a game with tokens. Each token has a number written on it, and the tokens are arranged in a straight line. The game involves selecting tokens from the line according to the following rules: 1. Alex can pick any number of tokens, but he cannot pick two consecutive tokens. 2. The score Alex gets for a se...
def max_score(tokens): n = len(tokens) if n == 0: return 0 if n == 1: return max(0, tokens[0]) dp = [0] * n dp[0] = max(0, tokens[0]) dp[1] = max(dp[0], tokens[1]) for i in range(2, n): dp[i] = max(dp[i - 1], dp[i - 2] + tokens[i]) return dp[-1] def solve_game...
import pytest from solution import solve_game, max_score def test_case_1(): assert solve_game(4, [1, 2, 9, 4]) == 10 def test_case_2(): assert solve_game(5, [3, 2, 5, 10, 7]) == 15 def test_case_3(): assert solve_game(1, [5]) == 5 def test_case_4(): assert solve_game(2, [5, 5]) == 5 def test_case_...
[ { "docstring": null, "function_declaration": "def max_score(tokens):", "function_name": "max_score", "parameter_list": "(tokens)" }, { "docstring": null, "function_declaration": "def solve_game(n, token_values):", "function_name": "solve_game", "parameter_list": "(n, token_values...
[ 0, 0, 0, 0, 0, 0, 0, 1, 0, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl", "solution_code": "def max_score(tokens):\n n = len(tokens)\n if n == 0:\n return 0\n if n == 1:\n return max(0, tokens[0])\n\n dp = [0] * n\n dp[0] = ma...
trial_gpt4o_7
{ "original_instruction": "", "prompt_id": "00082389", "row_id": 82389, "seed_ids": "[15763]" }
0.715843
Taco_82389
I
[ "max_score", "solve_game" ]
2
[ [ "solve_game", "max_score" ] ]
1
[]
false
[]
false
pytest
true
[]
true
25e09ae2570ca061caf89df32ba5a4af2521fc39
67fa934b7b86ead9c1bb99aeda94b4ed44086c69
v1.0
instruct
Taco
Taco_82459_I
You are given a rectilinear grid where each cell can either be empty or contain an obstacle. You need to find the largest empty square sub-grid within this grid. The empty square sub-grid is a contiguous block of cells, all of which are empty. The grid is represented by a 2D array of integers where 1 represents an obs...
def largest_empty_square(grid): if not grid: return 0 n = len(grid) m = len(grid[0]) # Create a DP table with the same dimensions as the grid dp = [[0]*m for _ in range(n)] max_side = 0 # Fill the DP table for i in range(n): for j in range(m): i...
def test_example_1(): n = 5 m = 5 grid = [ "1 0 1 0 0", "1 0 0 1 0", "1 0 0 0 0", "0 1 0 0 1", "0 0 0 1 0" ] assert find_largest_empty_square(n, m, grid) == 2 def test_example_2(): n = 3 m = 3 grid = [ "1 1 1", "1 0 0", "1 ...
[ { "docstring": null, "function_declaration": "def largest_empty_square(grid):", "function_name": "largest_empty_square", "parameter_list": "(grid)" }, { "docstring": null, "function_declaration": "def find_largest_empty_square(n, m, grid_lines):", "function_name": "find_largest_empty...
[ 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 largest_empty_square(grid):\n if not grid:\n return 0\n n = len(grid)\n m = len(grid[0])\n \n # Create a DP table with the same dimension...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00082459", "row_id": 82459, "seed_ids": "[8131]" }
0.644779
Taco_82459
I
[ "largest_empty_square", "find_largest_empty_square" ]
2
[ [ "find_largest_empty_square", "largest_empty_square" ] ]
1
[]
false
[]
false
pytest
false
[]
true
5c352fa4deaad264fd2eb1b80c8609aed1d64f6c
8f5f10cbbc72e75e09f1851a52e478f50199ad51
v1.0
instruct
Taco
Taco_82463_I
In a fictional kingdom, there are several cities connected by bidirectional roads. The citizens of this kingdom are facing some trouble as the roads are not in good condition and are prone to getting blocked during bad weather. The governor wants to ensure that even if one road gets blocked, it should still be possible...
def find_bridges(n, m, roads): from collections import defaultdict, deque def dfs(v, parent, disc, low, graph, bridges, time): children = 0 disc[v] = low[v] = time[0] time[0] += 1 for to in graph[v]: if disc[to] == -1: children += 1 ...
from solution import road_network def test_example_1(): assert road_network(5, 5, [(1, 2), (2, 3), (3, 4), (4, 5), (5, 1)]) == "YES" def test_example_2(): assert road_network(5, 4, [(1, 2), (2, 3), (3, 4), (4, 5)]) == "NO" def test_single_city(): assert road_network(1, 0, []) == "YES" def test_two_citie...
[ { "docstring": null, "function_declaration": "def find_bridges(n, m, roads):", "function_name": "find_bridges", "parameter_list": "(n, m, roads)" }, { "docstring": null, "function_declaration": "def road_network(n, m, roads):", "function_name": "road_network", "parameter_list": "...
[ 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_2_edge_connected(n, m, roads):\n from collections import defaultdict\n \n def dfs(v, visited, graph, parent, visited_time, low_time, time, bridges)...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00082463", "row_id": 82463, "seed_ids": "[14066]" }
0.783996
Taco_82463
I
[ "find_bridges", "road_network" ]
2
[ [ "road_network", "find_bridges" ] ]
1
[]
false
[]
false
pytest
true
[]
true
6e8d8430a454199e7c717d2b440e07b2a9b298b1
ee82e45e9f7b1eb383f932b39d03c171ec9711ac
v1.0
instruct
Taco
Taco_82493_I
Farmer John's cows have started organizing races in the pastures. Each cow competes by running along a specific path and keeping track of the positions they visit. Farmer John wants to find out which cow visits the maximum number of unique positions. Can you help him determine the winning cow? -----Input----- The firs...
def find_winning_cow(cow_paths): """ Determine which cow visits the maximum number of unique positions. """ max_unique_positions = 0 index_of_winning_cow = 0 for idx, path in enumerate(cow_paths): unique_positions = set(path) if len(unique_positions) > max_unique_positions: ...
import pytest from solution import cow_race def test_sample_input_1(): input_str = "3\n4\n1 1\n2 2\n1 1\n3 4\n3\n5 6\n5 6\n5 6\n5\n7 8\n7 8\n8 9\n9 10\n10 11\n" assert cow_race(input_str) == 3 def test_sample_input_2(): input_str = "2\n5\n1 1\n2 2\n3 3\n4 4\n5 5\n4\n10 10\n10 10\n20 20\n30 30\n" asser...
[ { "docstring": "Determine which cow visits the maximum number of unique positions.", "function_declaration": "def find_winning_cow(cow_paths):", "function_name": "find_winning_cow", "parameter_list": "(cow_paths)" }, { "docstring": "Parse the input string to extract the number of cows and th...
[ 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 find_winning_cow(m, cow_paths):\n max_unique_positions = 0\n winning_cow_index = 0\n \n for i in range(m):\n k, positions = cow_paths[i]\n ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00082493", "row_id": 82493, "seed_ids": "[19247]" }
0.626272
Taco_82493
I
[ "find_winning_cow", "parse_input", "cow_race" ]
3
[ [ "cow_race", "find_winning_cow" ], [ "cow_race", "parse_input" ] ]
2
[ "parse_input" ]
false
[]
false
pytest
true
[]
true
053bf336503d9cb7e7d21726215af005334c8180
e61646de050696057ceebe4fa74b2c74ddd78201
v1.0
instruct
Taco
Taco_82573_I
Problem: You are given a grid with m rows and n columns. Each cell in the grid contains a single lowercase alphabet letter. You are also given a list of k words. Your task is to implement a function that checks if each word in the list can be formed by a sequence of adjacent cells in the grid, where "adjacent" cells a...
def word_exists(grid, word, m, n): def dfs(x, y, pos): if pos == len(word): return True if x < 0 or x >= m or y < 0 or y >= n or word[pos] != grid[x][y]: return False tmp, grid[x][y] = grid[x][y], '#' found = (dfs(x + 1, y, pos + 1) or dfs(x -...
from solution import count_valid_words def test_example_case_1(): m, n = 3, 4 grid = ["a b c e", "s f c s", "a d e e"] k = 2 words = ["abcced", "see"] assert count_valid_words(m, n, grid, k, words) == 2 def test_example_case_2(): m, n = 2, 2 grid = ["a b", "c d"] k = 3 words = ["ab...
[ { "docstring": null, "function_declaration": "def word_exists(grid, word, m, n):", "function_name": "word_exists", "parameter_list": "(grid, word, m, n)" }, { "docstring": null, "function_declaration": "def count_valid_words(m, n, grid, k, words):", "function_name": "count_valid_word...
[ 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 word_exists(grid, word, m, n):\n def dfs(x, y, pos):\n if pos == len(word):\n return True\n if x < 0 or x >= m or y < 0 or y >= n o...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00082573", "row_id": 82573, "seed_ids": "[10591]" }
0.75209
Taco_82573
I
[ "word_exists", "count_valid_words" ]
2
[ [ "count_valid_words", "word_exists" ] ]
1
[]
false
[]
false
pytest
true
[]
true
20df5dd6214792207bdd366874aebab3a87591e5
f849a27d045b2d193c48e8bf5594359176f8bae0
v1.0
instruct
Taco
Taco_82604_I
You are given a log file consisting of multiple entries, each entry detailing an event in a system. Each entry has the format: "YYYY-MM-DD HH:MM:SS <Event_Type> <Event_Description>". Your task is to write a program that outputs a summary report of the events. The summary should contain the number of occurrences of each...
def parse_log(log_lines): from collections import defaultdict from itertools import groupby event_summary = defaultdict(lambda: defaultdict(int)) for line in log_lines: if line.strip() == "END": break date, time, event_type, *event_description = line.split(maxsplit=3) ...
from solution import generate_summary def test_generate_summary(): log_lines = [ "2023-10-01 08:23:45 LOGIN User123 logged in", "2023-10-01 08:47:12 LOGOUT User123 logged out", "2023-10-01 09:00:01 LOGIN User456 logged in", "2023-10-01 10:15:05 LOGIN User789 logged in", "202...
[ { "docstring": null, "function_declaration": "def parse_log(log_lines):", "function_name": "parse_log", "parameter_list": "(log_lines)" }, { "docstring": null, "function_declaration": "def format_summary(event_summary):", "function_name": "format_summary", "parameter_list": "(eve...
[ 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 parse_log(log):\n \"\"\"\n Parses the log file and returns a summary report.\n \"\"\"\n from collections import defaultdict\n\n event_counts = d...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00082604", "row_id": 82604, "seed_ids": "[11189]" }
0.567418
Taco_82604
I
[ "parse_log", "format_summary", "generate_summary" ]
3
[ [ "generate_summary", "format_summary" ], [ "generate_summary", "parse_log" ] ]
2
[]
false
[]
false
pytest
true
[]
true
ec7ec5258af2c02a0daba91cc4c98273de7f5e9d
00084e481405207d189314bbbab3e74ce6c52374
v1.0
instruct
Taco
Taco_82607_I
In a kingdom far away, there existed a dense enchanted forest where magical creatures lived in harmony. The forest was divided into various regions marked by unique trees called "root nodes." These trees served as the central points of magical energy that protected the regions from external threats. However, as time pa...
import sys import math import heapq def calculate_distance(p1, p2): return math.sqrt((p1[0] - p2[0]) ** 2 + (p1[1] - p2[1]) ** 2) def prim_mst(points): N = len(points) if N == 0: return 0.0 in_mst = [False] * N min_edge = [(0, 0)] total_length = 0.0 edges_count = 0 ...
import os import sys from io import StringIO def test_case_1(monkeypatch): input_data = """4 0 0 0 1 1 0 1 1 3 0 0 2 2 3 3 0 """ expected_output = "3.000000\n4.242641\n" monkeypatch.setattr(sys, 'stdin', StringIO(input_data)) monkeypatch.setattr(sys, 'stdout', buffer := StringIO()) from solut...
[ { "docstring": null, "function_declaration": "def calculate_distance(p1, p2):", "function_name": "calculate_distance", "parameter_list": "(p1, p2)" }, { "docstring": null, "function_declaration": "def prim_mst(points):", "function_name": "prim_mst", "parameter_list": "(points)" ...
[ 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\nfrom heapq import heappop, heappush\n\ndef calculate_distance(x1, y1, x2, y2):\n \"\"\"Calculate Euclidean distance between two points.\"\"\"\n ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00082607", "row_id": 82607, "seed_ids": "[15489]" }
0.606565
Taco_82607
I
[ "calculate_distance", "prim_mst", "solve" ]
3
[ [ "prim_mst", "calculate_distance" ], [ "solve", "prim_mst" ] ]
2
[]
false
[]
false
pytest
true
[]
true
a07d20aeffb307290f96b292bc63ded24b21dc99
4b1d10824e61052890084225c83f0020d347bed5
v1.0
instruct
Taco
Taco_82634_I
A company has a network of `n` servers connected by `m` bidirectional cables. Each cable has a bandwidth capacity. The IT team wants to determine the minimum capacity of the cable that should be upgraded to ensure that the data transfer between the server with minimum capacity and maximum capacity is optimized. Only on...
def find(parent, i): if parent[i] == i: return i return find(parent, parent[i]) def union(parent, rank, x, y): xroot = find(parent, x) yroot = find(parent, y) if rank[xroot] < rank[yroot]: parent[xroot] = yroot elif rank[xroot] > rank[yroot]: parent[yroot] = xroot el...
from solution import min_cable_to_upgrade def test_basic_network(): assert min_cable_to_upgrade(5, 6, [ [1, 2, 3], [2, 3, 2], [3, 4, 4], [4, 5, 6], [1, 3, 8], [2, 5, 5], ]) == 2 def test_single_cable(): assert min_cable_to_upgrade(2, 1, [ [1, 2, 10] ...
[ { "docstring": null, "function_declaration": "def find(parent, i):", "function_name": "find", "parameter_list": "(parent, i)" }, { "docstring": null, "function_declaration": "def union(parent, rank, x, y):", "function_name": "union", "parameter_list": "(parent, rank, x, y)" }, ...
[ 0, 0, 0, 1, 0 ]
1
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl", "solution_code": "import heapq\n\ndef min_key_cable_upgrade(n, m, edges):\n def dijkstra(source, target, adj, n):\n heap = [(0, source)]\n dists = [float('inf')] * ...
trial_gpt4o_3
{ "original_instruction": "", "prompt_id": "00082634", "row_id": 82634, "seed_ids": "[8293]" }
0.665951
Taco_82634
I
[ "find", "union", "min_cable_to_upgrade" ]
3
[ [ "min_cable_to_upgrade", "find" ], [ "min_cable_to_upgrade", "union" ], [ "union", "find" ] ]
3
[]
false
[]
false
pytest
true
[]
true
d8719b8b520ec7d787866093be14edbaba3c9602
f082120c4e30f5375560f91649afb22dcb471a4f
v1.0
instruct
Taco
Taco_82678_I
Ibrahim has just started learning about prime numbers and their importance in various algorithms and cryptographic applications. As part of his learning journey, he wants to determine the sum of prime numbers within a given range. However, he is struggling with an efficient way to compute this sum, especially when the ...
import itertools def sieve(n): """ Returns a list of prime numbers up to n using the Sieve of Eratosthenes. """ is_prime = [True] * (n+1) p = 2 while (p * p <= n): if (is_prime[p] == True): for i in range(p * p, n+1, p): is_prime[i] = False p += 1 ...
from solution import sum_of_primes_in_range, solve def test_sum_of_primes_in_range(): assert sum_of_primes_in_range(1, 10) == 17 assert sum_of_primes_in_range(11, 20) == 60 assert sum_of_primes_in_range(21, 30) == 52 assert sum_of_primes_in_range(1, 1) == 0 assert sum_of_primes_in_range(0, 2) == 2 ...
[ { "docstring": "Returns a list of prime numbers up to n using the Sieve of Eratosthenes.", "function_declaration": "def sieve(n):", "function_name": "sieve", "parameter_list": "(n)" }, { "docstring": "Finds the sum of prime numbers in the range [L, R].", "function_declaration": "def sum_...
[ 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 sieve_of_eratosthenes(max_num):\n \"\"\" Helper function to generate a list of primes up to max_num using the Sieve of Eratosthenes \"\"\"\n is_prime = [...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00082678", "row_id": 82678, "seed_ids": "[7084]" }
0.574241
Taco_82678
I
[ "sieve", "sum_of_primes_in_range", "solve" ]
3
[ [ "solve", "sum_of_primes_in_range" ], [ "sum_of_primes_in_range", "sieve" ] ]
2
[]
false
[]
false
pytest
true
[]
true
c02f9a67cffe3e26502da6a418e1776d3ac3d810
40c79b4af93c21d57f44c454f05c51a74f3bcc74
v1.0
instruct
Taco
Taco_82741_I
Alex is fascinated with prime numbers and primes within a range. He likes to find out how many prime numbers can be found within a specified range `[a, b]` (inclusive). Can you help him? Input Format The first line contains an integer $\mathbf{T}$, the number of test cases. The next $\mathbf{2T}$ lines each contain...
def sieve_of_eratosthenes(max_num): is_prime = [True] * (max_num + 1) is_prime[0] = is_prime[1] = False p = 2 while (p * p <= max_num): if (is_prime[p] == True): for i in range(p * p, max_num + 1, p): is_prime[i] = False p += 1 return is_prime def count_p...
from solution import count_primes_in_ranges def test_single_range(): assert count_primes_in_ranges([(1, 10)]) == [4] def test_multiple_ranges(): assert count_primes_in_ranges([(1, 10), (10, 20)]) == [4, 4] def test_large_range(): assert count_primes_in_ranges([(1, 100)]) == [25] # there are 25 primes be...
[ { "docstring": null, "function_declaration": "def sieve_of_eratosthenes(max_num):", "function_name": "sieve_of_eratosthenes", "parameter_list": "(max_num)" }, { "docstring": null, "function_declaration": "def count_primes_in_ranges(ranges):", "function_name": "count_primes_in_ranges"...
[ 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 count_primes_in_range(a, b):\n \"\"\"\n Counts the number of prime numbers within the range [a, b] inclusive.\n \"\"\"\n if a > b:\n a, b = ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00082741", "row_id": 82741, "seed_ids": "[23428]" }
0.628428
Taco_82741
I
[ "sieve_of_eratosthenes", "count_primes_in_ranges" ]
2
[ [ "count_primes_in_ranges", "sieve_of_eratosthenes" ] ]
1
[]
false
[]
false
pytest
true
[]
true
4912af769960bcdb39558aefbb3bf874e022767a
1aed16da5f941dce996d435cb52a39b58bd774cb
v1.0
instruct
Taco
Taco_82778_I
A company is organizing a hackathon event, and they want to distribute participants into teams efficiently. Each participant has a unique skill level, and they want to form teams such that the skill level difference among participants in the same team is minimized. You need to write a program to determine the minimum p...
def minimize_skill_diff(test_cases): results = [] for case in test_cases: N, skills = case skills.sort() min_diff = float('inf') for i in range(1, N): min_diff = min(min_diff, skills[i] - skills[i-1]) results.append(min_diff) return res...
from solution import minimize_skill_diff, process_input, solution def test_minimize_skill_diff_simple_case(): testcase = [(4, [1, 4, 6, 8])] assert minimize_skill_diff(testcase) == [2] def test_minimize_skill_diff_multiple_cases(): testcase = [ (4, [1, 4, 6, 8]), (5, [10, 20, 30, 40, 50]) ...
[ { "docstring": null, "function_declaration": "def minimize_skill_diff(test_cases):", "function_name": "minimize_skill_diff", "parameter_list": "(test_cases)" }, { "docstring": null, "function_declaration": "def process_input(input_text):", "function_name": "process_input", "param...
[ 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": "def min_possible_max_diff(skill_levels):\n \"\"\"\n Determine the minimum possible maximum difference in skill levels within any team.\n \n Parameters:...
trial_gpt4o_4
{ "original_instruction": "", "prompt_id": "00082778", "row_id": 82778, "seed_ids": "[13057]" }
0.766373
Taco_82778
I
[ "minimize_skill_diff", "process_input", "solution" ]
3
[ [ "solution", "minimize_skill_diff" ], [ "solution", "process_input" ] ]
2
[ "process_input" ]
false
[]
false
pytest
true
[]
true
4bf5756915aa23832edc2c89f128ac970f5f2cc9
502f6db664afd9ae83b1b9105d57e12b8aad171c
v1.0
instruct
Taco
Taco_82807_I
A robotics lab has designed several specialized robots to perform tasks on a factory floor. The floor is represented as a 2D grid with R rows and C columns. Each cell in the grid can either be empty or contain an obstacle. Each robot starts at a specific position on the grid and must perform a sequence of movements. T...
def move_robot(R, C, grid, x, y, movements): for move in movements: if move == 'U' and x > 1 and grid[x-2][y-1] != '#': x -= 1 elif move == 'D' and x < R and grid[x][y-1] != '#': x += 1 elif move == 'L' and y > 1 and grid[x-1][y-2] != '#': y -= 1 e...
from solution import move_robot, final_positions def test_move_robot_simple(): # Grid specification R, C = 5, 5 grid = [ ".....", ".....", ".....", ".....", "....." ] # Single robot move assert move_robot(R, C, grid, 1, 1, "RRR") == (1, 4) assert move...
[ { "docstring": null, "function_declaration": "def move_robot(R, C, grid, x, y, movements):", "function_name": "move_robot", "parameter_list": "(R, C, grid, x, y, movements)" }, { "docstring": null, "function_declaration": "def final_positions(R, C, grid, robots):", "function_name": "...
[ 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 simulate_robots(R, C, grid, robots):\n # Convert x and y coordinates from 1-based to 0-based\n def move_robot(start_x, start_y, moves):\n x, y = s...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00082807", "row_id": 82807, "seed_ids": "[15127]" }
0.726892
Taco_82807
I
[ "move_robot", "final_positions" ]
2
[ [ "final_positions", "move_robot" ] ]
1
[]
false
[]
false
pytest
true
[]
true
fcf7ab83bf64fba679d7b923bf2267d95fee4770
13443075211fa34bdc3e27b262b4c69cf5b78439
v1.0
instruct
Taco
Taco_82821_I
A company is developing a software to manage events in a city park. Each event has a start time and an end time, and its schedule cannot overlap with any other event. Given a list of events, find the maximum number of non-overlapping events that can be scheduled in the park. Each event is represented by a tuple of two...
def max_non_overlapping_events(test_cases): results = [] for events in test_cases: events.sort(key=lambda x: x[1]) count = 0 last_end_time = 0 for start, end in events: if start >= last_end_time: count += 1 last_end_time = end ...
def test_max_non_overlapping_events(): input_str = "1\n3\n1 3\n2 5\n4 6\n" expected_output = "2" assert solve(input_str) == expected_output def test_max_non_overlapping_events_multiple_cases(): input_str = "2\n3\n1 3\n2 5\n4 6\n4\n1 2\n2 3\n3 4\n4 5\n" expected_output = "2\n4" assert solve(inpu...
[ { "docstring": null, "function_declaration": "def max_non_overlapping_events(test_cases):", "function_name": "max_non_overlapping_events", "parameter_list": "(test_cases)" }, { "docstring": null, "function_declaration": "def parse_input(input_str):", "function_name": "parse_input", ...
[ 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 max_non_overlapping_events(test_cases):\n \"\"\"\n Given a list of test cases, find the maximum number of non-overlapping events that can be scheduled.\n...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00082821", "row_id": 82821, "seed_ids": "[10549]" }
0.691163
Taco_82821
I
[ "max_non_overlapping_events", "parse_input", "solve" ]
3
[ [ "solve", "max_non_overlapping_events" ], [ "solve", "parse_input" ] ]
2
[ "parse_input" ]
false
[]
false
pytest
false
[]
true
882d999b5dfd7ed0a6854348dc4eda17b447f647
bd1b5a39bbb2b973cf94c8b70383de3c399d3c11
v1.0
instruct
Taco
Taco_82847_I
Given a road network of a city represented as a directed graph with `n` intersections (nodes) and `m` streets (edges), we need to determine the shortest path from a starting intersection to each other intersection. Each street has a non-negative travel time. If there is no path from the starting intersection to another...
import heapq def dijkstra(n, edges, start): """ Returns the shortest path from the start node to all other nodes using Dijkstra's algorithm. If a node is unreachable, the distance is marked as 'INF'. """ graph = [[] for _ in range(n)] for u, v, w in edges: graph[u-1].append((v-1, w)) ...
from solution import shortest_paths def test_example1(): n = 4 m = 4 edge_list = [(1, 2, 2), (1, 3, 4), (2, 3, 1), (3, 4, 1)] s = 1 assert shortest_paths(n, m, edge_list, s) == [0, 2, 3, 4] def test_example2(): n = 5 m = 3 edge_list = [(1, 2, 3), (2, 3, 2), (3, 5, 5)] s = 4 ass...
[ { "docstring": "Returns the shortest path from the start node to all other nodes using Dijkstra's algorithm.\nIf a node is unreachable, the distance is marked as 'INF'.", "function_declaration": "def dijkstra(n, edges, start):", "function_name": "dijkstra", "parameter_list": "(n, edges, start)" },...
[ 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(n, edges, s):\n \"\"\"\n Implements Dijkstra's algorithm to find shortest path from starting \n intersection `s` to all other...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00082847", "row_id": 82847, "seed_ids": "[3826]" }
0.754258
Taco_82847
I
[ "dijkstra", "shortest_paths" ]
2
[ [ "shortest_paths", "dijkstra" ] ]
1
[]
false
[]
false
pytest
true
[]
true
bd00d5df30d5abaac2ab22a51e5b592f81ec62d6
7a94fb8ab3b7fbfabb254e395d242cce8fe4dedb
v1.0
instruct
Taco
Taco_82898_I
John is an avid coder and loves challenges. Today, he stumbled upon an interesting problem while practicing. The problem is as follows: John has a list of N integers. He is given Q queries, and for each query, he needs to find the sum of the integers in a subarray from index L to R (inclusive). However, John finds this...
def preprocess_sums(array): """ Precomputes prefix sums for the given array. Parameters: - array: List of integers Returns: - prefix_sums: List of prefix sums where prefix_sums[i] is the sum of elements from array[0] to array[i-1] """ prefix_sums = [0] * (len(array) + 1) fo...
def test_process_queries(): array = [1, 2, 3, 4, 5] queries = [(1, 3), (2, 4), (1, 5)] result = process_queries(5, 3, array, queries) assert result == [6, 9, 15], f"Expected [6, 9, 15], but got {result}" def test_process_queries_single_element(): array = [100] queries = [(1, 1)] result = pr...
[ { "docstring": "Precomputes prefix sums for the given array.\n\nParameters:\n- array: List of integers\n\nReturns:\n- prefix_sums: List of prefix sums where prefix_sums[i] is the sum of elements from array[0] to array[i-1]", "function_declaration": "def preprocess_sums(array):", "function_name": "prepro...
[ 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_prefix_sums(arr):\n \"\"\"\n Preprocess the given list to create a prefix sums array.\n \n Parameters:\n arr (list): The original lis...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00082898", "row_id": 82898, "seed_ids": "[11410]" }
0.691749
Taco_82898
I
[ "preprocess_sums", "query_sum", "process_queries" ]
3
[ [ "process_queries", "preprocess_sums" ], [ "process_queries", "query_sum" ] ]
2
[ "process_queries" ]
false
[]
false
pytest
false
[]
true
9da8cf19dc983714d73c19cedb2a7d8170987f17
13aa713cacb6b58abf410dd5efe576ecd858bb8a
v1.0
instruct
Taco
Taco_83039_I
There was a fisherman who owned several lakes, and each lake was known for different types of fish he would catch. One day, he decided to design a fishing tournament for his community. The tournament rules were simple: participants had to catch different types of fish from one lake, and each lake has its own set of fis...
def get_largest_connected_component_size(N, edges): from collections import defaultdict, deque graph = defaultdict(list) # Build graph for u, v in edges: graph[u].append(v) graph[v].append(u) visited = set() max_size = 0 def bfs(start): queue = deq...
import pytest from solution import find_largest_component_sizes_in_lakes def test_single_lake_single_component(): T = 1 lake_data = [ (5, 4, [(1, 2), (2, 3), (3, 4), (4, 5)]) ] assert find_largest_component_sizes_in_lakes(T, lake_data) == [5] def test_single_lake_multiple_components(): T =...
[ { "docstring": null, "function_declaration": "def get_largest_connected_component_size(N, edges):", "function_name": "get_largest_connected_component_size", "parameter_list": "(N, edges)" }, { "docstring": null, "function_declaration": "def find_largest_component_sizes_in_lakes(T, lake_d...
[ 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 dfs(graph, node, visited):\n stack = [node]\n size = 0\n while stack:\n current = stack.pop()\n if not visited[current]:\n vi...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00083039", "row_id": 83039, "seed_ids": "[17800]" }
0.615337
Taco_83039
I
[ "get_largest_connected_component_size", "find_largest_component_sizes_in_lakes" ]
2
[ [ "find_largest_component_sizes_in_lakes", "get_largest_connected_component_size" ] ]
1
[]
false
[]
false
pytest
true
[]
true
cc0d2316ff21343cd8dcb8b7114e07ddaca57e14
b4c1517f3c88a7d2d678f2e26ccac642818509b3
v1.0
instruct
Taco
Taco_83041_I
You are given an array containing n positive integers. Your task is to determine if there exists a contiguous subarray whose sum is a perfect square. -----Input----- The first line of the input contains an integer n (1 ≤ n ≤ 100000) — the length of the array. The second line contains n integers (1 ≤ a_{i} ≤ 10000) ...
import math def is_perfect_square(number): """ Checks if a given number is a perfect square """ if number < 0: return False root = math.isqrt(number) return root * root == number def has_contiguous_subarray_sum_as_perfect_square(n, arr): """ Determines if there is a contiguous ...
from solution import is_perfect_square, has_contiguous_subarray_sum_as_perfect_square def test_is_perfect_square(): assert is_perfect_square(0) == True assert is_perfect_square(1) == True assert is_perfect_square(4) == True assert is_perfect_square(9) == True assert is_perfect_square(16) == True ...
[ { "docstring": "Checks if a given number is a perfect square", "function_declaration": "def is_perfect_square(number):", "function_name": "is_perfect_square", "parameter_list": "(number)" }, { "docstring": "Determines if there is a contiguous subarray with a sum that is a perfect square.", ...
[ 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_perfect_square(number):\n \"\"\"\n Checks if a given number is a perfect square\n \"\"\"\n if number < 0:\n return False\n...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00083041", "row_id": 83041, "seed_ids": "[17847]" }
0.63425
Taco_83041
I
[ "is_perfect_square", "has_contiguous_subarray_sum_as_perfect_square" ]
2
[ [ "has_contiguous_subarray_sum_as_perfect_square", "is_perfect_square" ] ]
1
[]
false
[]
false
pytest
true
[]
true
3f24597b9b657ca35c3b737c258972c2b02ee076
23f26dbfe9ea266a7bc9d8a02fe2c2f70f2068e5
v1.0
instruct
Taco
Taco_83046_I
The famous Goldbach Conjecture states that every even number greater than 2 can be expressed as the sum of two prime numbers. There may be multiple valid prime pairs for a given even number. Your task is to write a function that, given an even number, finds one such pair of prime numbers whose sum equals the given numb...
def is_prime(n): if n <= 1: return False if n <= 3: return True if n % 2 == 0 or n % 3 == 0: return False i = 5 while i * i <= n: if n % i == 0 or n % (i + 2) == 0: return False i += 6 return True def goldbach_pair(n): for i in range(2, n)...
from solution import goldbach_conjecture def test_goldbach_conjecture_case_10(): assert goldbach_conjecture(1, [10]) == [(3, 7)] def test_goldbach_conjecture_case_18(): assert goldbach_conjecture(1, [18]) == [(5, 13)] def test_goldbach_conjecture_case_28(): assert goldbach_conjecture(1, [28]) == [(5, 23)...
[ { "docstring": null, "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": null, "function_declaration": "def goldbach_pair(n):", "function_name": "goldbach_pair", "parameter_list": "(n)" }, { "docstring": null,...
[ 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 math\n\ndef sieve_of_eratosthenes(max_num):\n is_prime = [True] * (max_num + 1)\n is_prime[0] = is_prime[1] = False\n for i in range(2, int(math.sq...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00083046", "row_id": 83046, "seed_ids": "[11621]" }
0.686492
Taco_83046
I
[ "is_prime", "goldbach_pair", "goldbach_conjecture" ]
3
[ [ "goldbach_conjecture", "goldbach_pair" ], [ "goldbach_pair", "is_prime" ] ]
2
[]
false
[]
false
pytest
true
[]
true
2f76a0221dfa8b2f98c25a39b6c6631ce2a68273
1a18906914f83a3fad8a6201d9cfe915b4f6d17f
v1.0
instruct
Taco
Taco_83124_I
Emma loves numbers and is very intrigued by prime numbers. She came across a problem where she needs to check if a list of numbers contains any prime numbers. Help Emma by writing a function that takes a list of integers and returns a new list containing only the prime numbers from the original list. Input: The first ...
def is_prime(num): """ Returns True if num is a prime number, otherwise returns False. """ 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 r...
from solution import is_prime, find_primes_in_list def test_is_prime(): assert is_prime(2) == True assert is_prime(3) == True assert is_prime(4) == False assert is_prime(5) == True assert is_prime(1) == False assert is_prime(0) == False assert is_prime(-3) == False assert is_prime(29) =...
[ { "docstring": "Returns True if num is a prime number, otherwise returns False.", "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": "Returns a sorted list of prime numbers from the given list of integers.", "function_de...
[ 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(num):\n \"\"\"\n Checks whether a number is prime or not.\n \"\"\"\n if num <= 1:\n return False\n for i in range(2, int(num**0....
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00083124", "row_id": 83124, "seed_ids": "[6346]" }
0.668579
Taco_83124
I
[ "is_prime", "find_primes_in_list" ]
2
[ [ "find_primes_in_list", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
519becdb62ab48c9719adbd72315b519e94493ae
c89f80b34caa5c11da28bbf43b8bcb7bef34c7d7
v1.0
instruct
Taco
Taco_83148_I
You are given a directed acyclic graph (DAG) with n vertices and m edges. Your task is to find the number of different topological sorts of the graph. A topological sort of a directed acyclic graph is a linear ordering of its vertices such that for every directed edge u -> v, vertex u comes before vertex v in the ord...
MOD = 10**9 + 7 def count_topological_sorts(n, edges): from itertools import permutations # Create the adjacency list and the in-degree list adj_list = [[] for _ in range(n)] in_degree = [0] * n # Populate the adjacency list and in-degree list for u, v in edges: adj_list[u-1]....
from solution import count_topological_sorts def test_example_1(): n = 3 edges = [(1, 2), (2, 3)] assert count_topological_sorts(n, edges) == 1 def test_example_2(): n = 4 edges = [(1, 2), (1, 3), (2, 4), (3, 4)] assert count_topological_sorts(n, edges) == 2 def test_no_edges(): n = 3 ...
[ { "docstring": null, "function_declaration": "def count_topological_sorts(n, edges):", "function_name": "count_topological_sorts", "parameter_list": "(n, edges)" }, { "docstring": null, "function_declaration": "def solve_topo_sort_problem():", "function_name": "solve_topo_sort_proble...
[ 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": "MOD = 10**9 + 7\n\ndef count_topological_sorts(n, edges):\n from functools import lru_cache\n import itertools\n\n # Calculate the adjacency matrix\n a...
trial_gpt4o_3
{ "original_instruction": "", "prompt_id": "00083148", "row_id": 83148, "seed_ids": "[5396]" }
0.58762
Taco_83148
I
[ "count_topological_sorts", "solve_topo_sort_problem" ]
2
[ [ "solve_topo_sort_problem", "count_topological_sorts" ] ]
1
[]
false
[]
false
pytest
true
[]
true
beadca74004166263416e6332484fba087416fa0
e0b4c19de6befe79680bf9f0879183f784b0331f
v1.0
instruct
Taco
Taco_83192_I
In a hypothetical kingdom, there are N cities connected by M bidirectional roads. Each road connects two cities and has a certain travel time associated with it. The cities are numbered from 1 to N. The king wants to visit every city starting from city 1 and follow any path that visits all cities exactly once, ending b...
import itertools def tsp(N, roads): """ Solve the Travelling Salesman Problem (TSP) for the given cities and roads. :param N: Number of cities :param roads: List of tuples (u, v, w) representing roads between cities u and v with travel time w :return: Minimum travel time to visit all cities ex...
from solution import minimum_travel_time def test_case_1(): assert minimum_travel_time(4, 6, [(1, 2, 10), (1, 3, 15), (1, 4, 20), (2, 3, 35), (2, 4, 25), (3, 4, 30)]) == 80 def test_case_no_path(): assert minimum_travel_time(3, 2, [(1, 2, 10), (2, 3, 10)]) == -1 def test_case_single_city(): assert minimu...
[ { "docstring": "Solve the Travelling Salesman Problem (TSP) for the given cities and roads.\n\n:param N: Number of cities\n:param roads: List of tuples (u, v, w) representing roads between cities u and v with travel time w\n:return: Minimum travel time to visit all cities exactly once and return to the start, o...
[ 0, 0, 0, 0, 0, 0, 1, 0, 0, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl", "solution_code": "def tsp(N, M, roads):\n from itertools import permutations\n import sys\n\n # Initialize the adjacency matrix with infinity\n adj = [[float('inf')] * N...
trial_gpt4o_6
{ "original_instruction": "", "prompt_id": "00083192", "row_id": 83192, "seed_ids": "[11158]" }
0.74026
Taco_83192
I
[ "tsp", "minimum_travel_time" ]
2
[ [ "minimum_travel_time", "tsp" ] ]
1
[]
false
[]
false
pytest
true
[]
true
b0e52abee3d823271066c29ac43d68863c4f5d87
f97b8ccdf970875cdd8d147893895c7a1be17b3d
v1.0
instruct
Taco
Taco_83205_I
You are given an initially empty tank, and you need to fill it such that it contains a specific ratio of two different liquids, A and B. The required ratio can be represented as a:b, where `a` and `b` are integers. In each step, you can pour either one unit of liquid A or one unit of liquid B into the tank. What is th...
def min_steps_to_achieve_ratio(a, b): """ Given two integers a and b representing the ratio of two liquids A and B respectively, returns the minimum number of steps required to fill the tank with the desired ratio of a:b. """ gcd_ab = gcd(a, b) return (a // gcd_ab) + (b // gcd_ab) def gcd(x, y)...
def test_gcd(): assert gcd(1, 2) == 1 assert gcd(3, 5) == 1 assert gcd(2, 2) == 2 assert gcd(7, 10) == 1 assert gcd(6, 9) == 3 def test_min_steps_to_achieve_ratio(): assert min_steps_to_achieve_ratio(1, 2) == 3 assert min_steps_to_achieve_ratio(3, 5) == 8 assert min_steps_to_achieve_rat...
[ { "docstring": "Given two integers a and b representing the ratio of two liquids A and B respectively,\nreturns the minimum number of steps required to fill the tank with the desired ratio of a:b.", "function_declaration": "def min_steps_to_achieve_ratio(a, b):", "function_name": "min_steps_to_achieve_r...
[ 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 min_steps_to_fill_ratio(t, test_cases):\n \"\"\"\n Returns the minimum number of steps required to achieve the desired ratio a:b for all test cases.\n ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00083205", "row_id": 83205, "seed_ids": "[5665]" }
0.665664
Taco_83205
I
[ "min_steps_to_achieve_ratio", "gcd", "min_steps_test_cases" ]
3
[ [ "min_steps_test_cases", "min_steps_to_achieve_ratio" ], [ "min_steps_to_achieve_ratio", "gcd" ] ]
2
[ "min_steps_test_cases" ]
false
[]
false
pytest
false
[]
true
e49a9b7d8e044d6aabaca01e2b1fc4e868aa08a7
28f8638c48dd471514d1dfd6f9a5d4d863e7c464
v1.0
instruct
Taco
Taco_83244_I
Given a binary tree consisting of N vertices. Each vertex of the binary tree is numbered from 1 to N, and each edge has a weight associated with it. Your task is to find the length of the longest path of the tree that is characterized by consecutive primes, in other words, a path where every consecutive edge weight is ...
def is_prime(x): if x < 2: return False for i in range(2, int(x**0.5) + 1): if x % i == 0: return False return True from collections import defaultdict, deque def longest_prime_path(N, edges): # Create adjacency list adj = defaultdict(list) for (u, v, w) in edges: ...
def test_longest_prime_path_example(): N = 5 edges = [ (1, 2, 3), (2, 3, 5), (3, 4, 7), (4, 5, 4), ] assert longest_prime_path(N, edges) == 3 def test_longest_prime_path_no_primes(): N = 4 edges = [ (1, 2, 6), (2, 3, 8), (3, 4, 10), ] ...
[ { "docstring": null, "function_declaration": "def is_prime(x):", "function_name": "is_prime", "parameter_list": "(x)" }, { "docstring": null, "function_declaration": "def longest_prime_path(N, edges):", "function_name": "longest_prime_path", "parameter_list": "(N, edges)" }, ...
[ 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 sys\nfrom collections import defaultdict\nfrom itertools import combinations\n\nsys.setrecursionlimit(200000)\n\ndef is_prime(x):\n \"\"\"\n Returns T...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00083244", "row_id": 83244, "seed_ids": "[22846]" }
0.529924
Taco_83244
I
[ "is_prime", "longest_prime_path" ]
2
[ [ "longest_prime_path", "is_prime" ] ]
1
[]
false
[]
false
pytest
false
[]
true
eef71d0ba885e2818bbbbd07643a2f48e768cb95
01126fc2bfd476c347763e608e958d90360a8277
v1.0
instruct
Taco
Taco_83327_I
You are given an array consisting of $n$ integers. Your task is to process $q$ queries, each of which asks for the count of even numbers in a given subarray. ------ Input Format ------ - The first line contains a single integer $n$ — the number of elements in the array. - The second line contains $n$ space-separated ...
def preprocess_evens(arr): """ Preprocess the array to create an auxiliary array that holds the prefix sum of even numbers. """ n = len(arr) prefix_evens = [0] * n prefix_evens[0] = 1 if arr[0] % 2 == 0 else 0 for i in range(1, n): prefix_evens[i] = prefix_evens[i-1] if ...
def test_preprocess_evens(): arr = [1, 2, 3, 4, 5] assert preprocess_evens(arr) == [0, 1, 1, 2, 2] def test_count_even_numbers(): arr = [1, 2, 3, 4, 5] queries = [(1, 3), (2, 5), (1, 5)] assert count_even_numbers(arr, queries) == [1, 2, 2] def test_all_odds(): arr = [1, 3, 5, 7, 9] queries...
[ { "docstring": "Preprocess the array to create an auxiliary array that holds the prefix sum of even numbers.", "function_declaration": "def preprocess_evens(arr):", "function_name": "preprocess_evens", "parameter_list": "(arr)" }, { "docstring": "Process the given queries to count the even n...
[ 0, 1 ]
1
medium
0.5
{ "trial_gpt4o_0": null, "trial_gpt4o_1": { "file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared1_results_combined.jsonl", "solution_code": "def count_even_numbers(n, arr, queries):\n # Create a prefix sum array for counting even numbers\n prefix_even_count = [0] * (n + 1)...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00083327", "row_id": 83327, "seed_ids": "[17691]" }
0.677374
Taco_83327
I
[ "preprocess_evens", "count_even_numbers" ]
2
[ [ "count_even_numbers", "preprocess_evens" ] ]
1
[]
false
[]
false
pytest
false
[]
true
bd839c30c8fdb49da7dbf30de2286d232005499d
5c1186ec27e40c61d4f36040e17177b822cfebd7
v1.0
instruct
Taco
Taco_83344_I
In a distant land, there are multiple kingdoms. Each kingdom is represented by a letter from 'A' to 'Z'. The kingdoms decide to form some alliances. Each alliance is defined as a group of kingdoms that are directly or indirectly connected. For example, if Kingdom A is allied with Kingdom B, and Kingdom B is allied wit...
def floyd_warshall(n, rates): from collections import defaultdict import math dist = defaultdict(lambda: defaultdict(lambda: math.inf)) for u in range(n): dist[chr(ord('A') + u)][chr(ord('A') + u)] = 1.0 for u, v, r in rates: dist[u][v] = r for k in range(n): ...
from solution import find_exchange_rates def test_example_case(): n = 5 m = 6 rates = [ ('A', 'B', 1.2), ('B', 'C', 1.3), ('C', 'D', 0.9), ('D', 'E', 1.4), ('E', 'A', 0.8), ('B', 'D', 1.1) ] queries = [('A', 'D'), ('C', 'E'), ('A', 'F')] expected_...
[ { "docstring": null, "function_declaration": "def floyd_warshall(n, rates):", "function_name": "floyd_warshall", "parameter_list": "(n, rates)" }, { "docstring": null, "function_declaration": "def find_exchange_rates(n, m, rates, queries):", "function_name": "find_exchange_rates", ...
[ 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_exchange_rate(n, m, edges, queries):\n from collections import defaultdict\n from math import isclose, inf\n\n graph = defaultdict(list)\n for...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00083344", "row_id": 83344, "seed_ids": "[23690]" }
0.639773
Taco_83344
I
[ "floyd_warshall", "find_exchange_rates" ]
2
[ [ "find_exchange_rates", "floyd_warshall" ] ]
1
[]
false
[]
false
pytest
true
[]
true
4fe359e6c6da12b8ebd381af43357396e1ce0fb2
06b59cbb015cf44cd255b4bb01d57bb9e27a7c02
v1.0
instruct
Taco
Taco_83353_I
In a faraway land, there exists a peculiar form of currency: magical coins. Each coin has a positive integer value, and the value is equal to the sum of its two closest lower valued coins. For instance, if there are coins with values 3 and 5, the next higher value coin will be 8, followed by 13 (since 5+8=13), and so o...
def generate_fibonacci_up_to(limit): fibonacci = [1, 2] while fibonacci[-1] + fibonacci[-2] <= limit: fibonacci.append(fibonacci[-1] + fibonacci[-2]) return fibonacci def min_coins_needed(N): fibonacci = generate_fibonacci_up_to(N) total, count = 0, 0 for coin in reversed(fibonacci): ...
from solution import solve_cases, min_coins_needed def test_min_coins_needed(): assert min_coins_needed(10) == 2 assert min_coins_needed(15) == 2 assert min_coins_needed(50) == 3 def test_solve_cases(): assert solve_cases([10, 15, 50]) == [2, 2, 3] assert solve_cases([1]) == [1] assert solve_c...
[ { "docstring": null, "function_declaration": "def generate_fibonacci_up_to(limit):", "function_name": "generate_fibonacci_up_to", "parameter_list": "(limit)" }, { "docstring": null, "function_declaration": "def min_coins_needed(N):", "function_name": "min_coins_needed", "paramete...
[ 0, 0, 0, 0, 0, 1, 0, 0, 0, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl", "solution_code": "def generate_coins():\n coins = [1, 2]\n while coins[-1] <= 10**9:\n new_coin = coins[-1] + coins[-2]\n coins.append(new_coin)\n return coin...
trial_gpt4o_5
{ "original_instruction": "", "prompt_id": "00083353", "row_id": 83353, "seed_ids": "[14473]" }
0.775402
Taco_83353
I
[ "generate_fibonacci_up_to", "min_coins_needed", "solve_cases" ]
3
[ [ "min_coins_needed", "generate_fibonacci_up_to" ], [ "solve_cases", "min_coins_needed" ] ]
2
[ "solve_cases" ]
false
[]
false
pytest
true
[]
true
c24ed48c93b7caa2e8da398d197c9223c2edd796
7772bda639ac2df2d6540310c250b9a984ad9147
v1.0
instruct
Taco
Taco_83363_I
Strings can be represented as characters and spaces combined to form words. A palindrome is a string that reads the same forwards and backwards, ignoring spaces and capitalization. For example, "A man a plan a canal Panama" is a palindrome because it reads the same regardless of spaces and capitalization. Write a prog...
import re def is_palindrome(s): """ Checks if the given string s is a palindrome, ignoring spaces, punctuation, and capitalization. """ # Remove non-alphanumeric characters and convert to lowercase cleaned_string = re.sub(r'[^a-zA-Z0-9]', '', s).lower() # Check if the string reads the same forw...
from solution import is_palindrome, check_palindromes def test_is_palindrome(): assert is_palindrome("A man a plan a canal Panama") == True assert is_palindrome("Hello, World!") == False assert is_palindrome("Madam, in Eden, I'm Adam") == True assert is_palindrome("racecar") == True assert is_palin...
[ { "docstring": "Checks if the given string s is a palindrome, ignoring spaces, punctuation, and capitalization.", "function_declaration": "def is_palindrome(s):", "function_name": "is_palindrome", "parameter_list": "(s)" }, { "docstring": "Takes a list of strings and returns a list of \"YES\...
[ 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 re\n\ndef is_palindrome(s):\n \"\"\"\n Checks if the provided string is a palindrome, ignoring spaces, punctuation, and capitalization.\n \"\"\"\n ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00083363", "row_id": 83363, "seed_ids": "[21370]" }
0.801861
Taco_83363
I
[ "is_palindrome", "check_palindromes" ]
2
[ [ "check_palindromes", "is_palindrome" ] ]
1
[]
false
[]
false
pytest
true
[]
true
d83eeaa083315396c63fb472d2ea877103170633
240f620f04a87a1872f32cd9013ed7469d9e9a69
v1.0
instruct
Taco
Taco_83502_I
You are given a grid of size n x n, filled with non-negative integers. You need to process q queries on this grid. Each query is defined by four integers x1, y1, x2, y2 and asks for the sum of all elements within the subgrid determined by the corners (x1, y1) and (x2, y2) (inclusive). ----- Input ----- The first line...
def compute_prefix_sums(grid): n = len(grid) prefix_sums = [[0] * (n + 1) for _ in range(n + 1)] for i in range(1, n + 1): for j in range(1, n + 1): prefix_sums[i][j] = grid[i - 1][j - 1] + \ prefix_sums[i - 1][j] + \ p...
def test_compute_prefix_sums(): 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 compute_prefix_sums(grid) == expected def test_query_subgrid_sum(): prefix_sums = ...
[ { "docstring": null, "function_declaration": "def compute_prefix_sums(grid):", "function_name": "compute_prefix_sums", "parameter_list": "(grid)" }, { "docstring": null, "function_declaration": "def query_subgrid_sum(prefix_sums, x1, y1, x2, y2):", "function_name": "query_subgrid_sum...
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 ]
1
hard
0.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 = len(grid)\n prefix_sum = [[0] * (n + 1) for _ in range(n + 1)]\n\n for i in range(1, n + 1):\n for j in range(1, n...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00083502", "row_id": 83502, "seed_ids": "[7514]" }
0.722508
Taco_83502
I
[ "compute_prefix_sums", "query_subgrid_sum", "process_queries" ]
3
[ [ "process_queries", "compute_prefix_sums" ], [ "process_queries", "query_subgrid_sum" ] ]
2
[ "process_queries" ]
false
[]
false
pytest
false
[]
true
d6bed80c1181cecde401fa9ad02e12d7b9998d3f
003594a968d65bc19d22e11a45dd6be78992f726
v1.0
instruct
Taco
Taco_83532_I
Given a binary tree, write a function `findLCA()` to find the lowest common ancestor (LCA) of two given nodes in the tree. Input: The input consists of multiple test cases. Each test case contains the following: 1. The first line contains the number of nodes in the binary tree. 2. The second line contains the values ...
class TreeNode: def __init__(self, x): self.val = x self.left = None self.right = None def findLCA(root, n1, n2): def findLCAHelper(root, n1, n2): if root is None: return None if root.val == n1 or root.val == n2: return root left_lca = f...
from solution import findLCA, build_tree def test_findLCA_case_1(): nodes = [3, 5, 1, 6, 2, 0, 8, -1, -1, 7, 4] root = build_tree(nodes) assert findLCA(root, 5, 1) == 3 def test_findLCA_case_2(): nodes = [3, 5, 1, 6, 2, 0, 8, -1, -1, 7, 4] root = build_tree(nodes) assert findLCA(root, 6, 4) ==...
[]
[ 0, 0, 0, 0, 0, 0, 0, 1, 0, 0 ]
1
hard
0.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, x):\n self.val = x\n self.left = None\n self.right = None\n\ndef build_tree(nodes):\n if not nodes ...
trial_gpt4o_7
{ "original_instruction": "", "prompt_id": "00083532", "row_id": 83532, "seed_ids": "[7855]" }
0.577342
Taco_83532
I
[ "findLCA", "existsInTree", "build_tree" ]
3
[ [ "findLCA", "existsInTree" ] ]
1
[]
false
[ "TreeNode" ]
true
pytest
true
[]
true
ddc8eb1d1d02c37d34da880a0a236d83acb5de5a
abd9e2b2738b95f85f67e1f53390ada7ff779479
v1.0
instruct
Taco
Taco_83621_I
Professor Claire loves rectangles. Every time she finds a rectangular area filled with positive integers, she calculates their sum and stores it. Given a 2D matrix of dimensions N x M filled with positive integers, she wants to find the subrectangle with the highest possible sum. Can you help Professor Claire to deter...
def max_sum_subrectangle(matrix): """ Function to find the maximum sum of any subrectangle in a given matrix. :param matrix: A 2D list of integers representing the matrix. :return: The maximum sum of any subrectangle in the matrix. """ if not matrix or not matrix[0]: return 0 n...
from solution import max_sum_subrectangle def test_example_1(): matrix = [ [1, 2, 3], [4, 5, 6], [7, 8, 9] ] assert max_sum_subrectangle(matrix) == 45 def test_example_2(): matrix = [ [1, 2, 3, 4, 5], [6, 7, 8, 9, 10], [11, 12, 13, 14, 15], [16, ...
[ { "docstring": "Function to find the maximum sum of any subrectangle in a given matrix.\n\n:param matrix: A 2D list of integers representing the matrix.\n:return: The maximum sum of any subrectangle in the matrix.", "function_declaration": "def max_sum_subrectangle(matrix):", "function_name": "max_sum_s...
[ 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": "def maximum_sum_subrectangle(matrix):\n def max_subarray(array):\n max_sum = float('-inf')\n current_sum = 0\n for value in array:\n ...
trial_gpt4o_4
{ "original_instruction": "", "prompt_id": "00083621", "row_id": 83621, "seed_ids": "[8345]" }
0.689068
Taco_83621
I
[ "max_sum_subrectangle", "max_subarray_sum" ]
2
[ [ "max_sum_subrectangle", "max_subarray_sum" ] ]
1
[]
false
[]
false
pytest
true
[]
true
a630e19c6a391a4ef3899243b4f5c5ab583b61bf
74dac5a6a28b81950defc3c9c8becabfd931ee79
v1.0
instruct
Taco
Taco_83635_I
------ Problem Statement ------ You are given an integer array $A$ of length $N$. You are allowed to perform the following type of operation on $A$ any number of times: - Pick any subarray of size $M$ (where $M$ is a positive integer less than or equal to $N$) and reverse it. Determine the minimum possible number of i...
def count_inversions(arr): """ Helper function to count inversions in an array using a modified merge sort algorithm. """ if len(arr) < 2: return 0 mid = len(arr) // 2 left = arr[:mid] right = arr[mid:] inv_count = count_inversions(left) + count_inversions(right) i = j =...
from solution import process_test_cases def test_sample_cases(): test_cases = [ (5, [3, 1, 2, 5, 4]), (4, [4, 3, 2, 1]) ] results = process_test_cases(test_cases) assert results == [0, 0] def test_edge_case_single_element(): test_cases = [ (1, [1]), ] results = proc...
[ { "docstring": "Helper function to count inversions in an array\nusing a modified merge sort algorithm.", "function_declaration": "def count_inversions(arr):", "function_name": "count_inversions", "parameter_list": "(arr)" }, { "docstring": "The goal of the problem is to determine the minimu...
[ 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 count_inversions(arr):\n inv_count = 0\n arr_sorted = sorted(arr)\n inv_map = {v: i for i, v in enumerate(arr_sorted)}\n\n BIT = [0] * (len(arr) + ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00083635", "row_id": 83635, "seed_ids": "[17183]" }
0.760776
Taco_83635
I
[ "count_inversions", "min_inversions_after_sorting", "process_test_cases" ]
3
[ [ "process_test_cases", "min_inversions_after_sorting" ] ]
1
[ "process_test_cases" ]
false
[]
false
pytest
true
[]
true
2385daf7fda9383241d2fc6573ad856d7ec2f132
4553fb14b1544b052bd4d49dda35a93e0b57679b
v1.0
instruct
Taco
Taco_83643_I
Problem Statement Given an array `A` of `n` integers, you are required to respond to `q` queries. Each query consists of two integers `L` and `R`, and requires you to return the sum of all prime numbers in the subarray `A[L...R]` inclusive. Write a function to process these queries efficiently. To keep the solution e...
def sieve_of_eratosthenes(max_num): """ Generates a list of booleans that indicates whether numbers are prime. Returns an array is_prime where is_prime[i] is True if i is a prime number. """ is_prime = [True] * (max_num + 1) is_prime[0] = is_prime[1] = False # 0 and 1 are not prime numbers ...
from solution import process_queries def test_process_queries_sample_case(): A = [2, 3, 4, 5, 6] queries = [(1, 3), (2, 5), (1, 5)] assert process_queries(A, queries) == [5, 8, 10] def test_process_queries_all_primes(): A = [2, 3, 5, 7, 11] queries = [(1, 5), (2, 4), (3, 3)] assert process_que...
[ { "docstring": "Generates a list of booleans that indicates whether numbers are prime.\nReturns an array is_prime where is_prime[i] is True if i is a prime number.", "function_declaration": "def sieve_of_eratosthenes(max_num):", "function_name": "sieve_of_eratosthenes", "parameter_list": "(max_num)"...
[ 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 < 2:\n return False\n if num in (2, 3):\n return True\n if num % 2 == 0 or num % 3 == 0:\n return False\n...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00083643", "row_id": 83643, "seed_ids": "[1170]" }
0.631881
Taco_83643
I
[ "sieve_of_eratosthenes", "preprocess_prime_sums", "sum_of_primes_in_range", "process_queries" ]
4
[ [ "process_queries", "preprocess_prime_sums" ], [ "process_queries", "sieve_of_eratosthenes" ], [ "process_queries", "sum_of_primes_in_range" ] ]
3
[ "process_queries" ]
false
[]
false
pytest
true
[]
true
86207e23caec711f493e50a47afb5f380766ec94
634a8aef102a5bace19547d7ead34033871a6bc9