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_70224_I | A popular city has been divided into several zones and the transport authority wants to plan an efficient transportation route for their new bus service. The main objective is to connect every zone with the minimum total length of roads. You have to help the authorities find a way to achieve this.
Your task is to writ... | def find(parent, i):
if parent[i] == i:
return i
return find(parent, parent[i])
def union(parent, rank, x, y):
root_x = find(parent, x)
root_y = find(parent, y)
if rank[root_x] < rank[root_y]:
parent[root_x] = root_y
elif rank[root_x] > rank[root_y]:
parent[root_y] ... | def test_sample_input():
z = 4
r = 5
roads = [
(0, 1, 1),
(0, 2, 2),
(0, 3, 1),
(1, 3, 3),
(2, 3, 4)
]
expected_output = [
[0, 1, 1],
[0, 3, 1],
[0, 2, 2]
] # The order of roads might be different, so we check all possible correct ... | [
{
"docstring": null,
"function_declaration": "def find(parent, i):",
"function_name": "find",
"parameter_list": "(parent, i)"
},
{
"docstring": null,
"function_declaration": "def union(parent, rank, x, y):",
"function_name": "union",
"parameter_list": "(parent, rank, x, y)"
},
... | [
1,
1,
0
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def find(parent, i):\n if parent[i] == i:\n return i\n return find(parent, parent[i])\n\ndef union(parent, rank, x, y):\n root_x = find(parent, x)\... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00070224",
"row_id": 70224,
"seed_ids": "[15964]"
} | 0.743162 | Taco_70224 | I | [
"find",
"union",
"kruskal_mst",
"main"
] | 4 | [
[
"kruskal_mst",
"find"
],
[
"kruskal_mst",
"union"
],
[
"union",
"find"
]
] | 3 | [] | false | [] | false | pytest | false | [] | true | 29fb1253837a85173cd308e6fa8f07e5e1135ba5 | 9eae3ad8287a987f0bc46c60a4360e1924a597e8 | |||
v1.0 | instruct | Taco | Taco_70225_I | In a distant kingdom, there is a legendary Phoenix Tree. The branches of this tree grow in a unique way, such that every branch splits into two new branches every year. The people of the kingdom are fascinated by the growth patterns, and they've kept records of the tree's branches.
You have been given the task of anal... | def number_of_branches(initial_branches, year):
"""
Given the initial number of branches and a specific year, returns the number of branches in that year.
"""
return initial_branches * (2 ** (year - 1))
def total_branches_between_years(initial_branches, start_year, end_year):
"""
Given the init... | import pytest
from solution import number_of_branches, total_branches_between_years, process_queries
def test_number_of_branches():
assert number_of_branches(5, 3) == 20
assert number_of_branches(5, 5) == 80
assert number_of_branches(1, 1) == 1
assert number_of_branches(1, 2) == 2
assert number_of_... | [
{
"docstring": "Given the initial number of branches and a specific year, returns the number of branches in that year.",
"function_declaration": "def number_of_branches(initial_branches, year):",
"function_name": "number_of_branches",
"parameter_list": "(initial_branches, year)"
},
{
"docstr... | [
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 phoenix_tree_growth(B, queries):\n \"\"\"\n Analyzes the Phoenix Tree's branches growth based on the given queries.\n \n :param B: Initial number o... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00070225",
"row_id": 70225,
"seed_ids": "[22867]"
} | 0.641942 | Taco_70225 | I | [
"number_of_branches",
"total_branches_between_years",
"process_queries"
] | 3 | [
[
"process_queries",
"number_of_branches"
],
[
"process_queries",
"total_branches_between_years"
],
[
"total_branches_between_years",
"number_of_branches"
]
] | 3 | [
"process_queries"
] | false | [] | false | pytest | true | [] | true | e3b07bdd663008bf5015ad95e6872e105d80796a | 7ce4db87b2bcae67a6e03dc2185ad24a7cfccda3 | |||
v1.0 | instruct | Taco | Taco_70282_I | You are given a binary tree with n nodes. Each node is uniquely numbered with integers from 1 to n. Additionally, each node contains a value, which is a non-negative integer.
You need to perform q update and query operations on this tree:
1. Update the value of a specific node.
2. Query the maximum value in the subtr... | class TreeNode:
def __init__(self, id):
self.id = id
self.value = 0
self.children = []
def update_value(node, x):
node.value = x
def find_max_in_subtree(node):
max_value = node.value
for child in node.children:
max_value = max(max_value, find_max_in_subtree(child))
... | def test_tree_operations():
n = 5
q = 6
edges = [1, 1, 2, 2]
operations = ["1 1 5", "1 3 3", "1 4 7", "2 1", "2 2", "2 5"]
expected_outputs = [7, 7, 0]
assert process_operations(n, edges, operations) == expected_outputs
def test_single_node_tree():
n = 1
q = 2
edges = []
op... | [] | [
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": "class TreeNode:\n def __init__(self, value=0):\n self.value = value\n self.children = []\n\nclass Tree:\n def __init__(self, n):\n self.... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00070282",
"row_id": 70282,
"seed_ids": "[22336]"
} | 0.596235 | Taco_70282 | I | [
"update_value",
"find_max_in_subtree",
"process_operations"
] | 3 | [
[
"process_operations",
"find_max_in_subtree"
],
[
"process_operations",
"update_value"
]
] | 2 | [] | false | [
"TreeNode"
] | true | pytest | false | [] | true | c6b2914af2923f53fda6839547b14c2521b5758b | f965d56a633e49bb186e0afe1e7ec348372c46b9 | |||
v1.0 | instruct | Taco | Taco_70290_I | Karl is working on a project to analyze sequences of integers. He has a sequence of integers of length n. He wants to determine if the sequence can be sorted in non-decreasing order by changing at most one integer in the sequence. If possible, return the list of integers after the change. If it is not possible, return ... | def can_be_sorted_by_one_change(sequence):
n = len(sequence)
# Helper function to check if a sequence is sorted in non-decreasing order
def is_sorted(seq):
return all(seq[i] <= seq[i + 1] for i in range(len(seq) - 1))
if is_sorted(sequence):
return sequence # Already sorted
... | from solution import sequence_sort_check
def test_case_1():
assert sequence_sort_check(5, [1, 2, 10, 5, 6]) == [1, 2, 5, 5, 6]
def test_case_2():
assert sequence_sort_check(3, [4, 1, 3]) == [1, 1, 3]
def test_case_3():
assert sequence_sort_check(4, [5, 4, 3, 2]) == -1
def test_already_sorted():
asse... | [
{
"docstring": null,
"function_declaration": "def can_be_sorted_by_one_change(sequence):",
"function_name": "can_be_sorted_by_one_change",
"parameter_list": "(sequence)"
},
{
"docstring": null,
"function_declaration": "def sequence_sort_check(n, seq):",
"function_name": "sequence_sor... | [
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_be_sorted_by_one_change(n, arr):\n \"\"\"\n Determines if the sequence can be sorted in non-decreasing order by changing\n at most one integer in ... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00070290",
"row_id": 70290,
"seed_ids": "[7694]"
} | 0.749159 | Taco_70290 | I | [
"can_be_sorted_by_one_change",
"sequence_sort_check"
] | 2 | [
[
"sequence_sort_check",
"can_be_sorted_by_one_change"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 09b0c51694e97eb3a11d6e5ccf922e9b418a2b02 | 676bed394a15dbbf755ad495b7ecc8629629df2f | |||
v1.0 | instruct | Taco | Taco_70306_I | Our protagonist, Lek, is a budding chef who loves experimenting with new recipes. Today, he wants to determine the unique ways he can prepare a dish using specific ingredients. Can you help him find this out?
You are given a list of N distinct ingredients and an integer M representing the number of ingredients require... | MOD = 10**9 + 7
def factorial(n):
result = 1
for i in range(2, n + 1):
result = (result * i) % MOD
return result
def mod_inverse(n, mod):
return pow(n, mod-2, mod)
def combination(n, k):
if k == 0 or k == n:
return 1
numerator = factorial(n)
denominator = (factorial(k) * f... | from solution import number_of_ways_to_prepare_dish
def test_case_1():
N = 5
M = 3
ingredients = [1, 2, 3, 4, 5]
assert number_of_ways_to_prepare_dish(N, M, ingredients) == 10
def test_case_2():
N = 6
M = 2
ingredients = [1, 2, 3, 4, 5, 6]
assert number_of_ways_to_prepare_dish(N, M, in... | [
{
"docstring": null,
"function_declaration": "def factorial(n):",
"function_name": "factorial",
"parameter_list": "(n)"
},
{
"docstring": null,
"function_declaration": "def mod_inverse(n, mod):",
"function_name": "mod_inverse",
"parameter_list": "(n, mod)"
},
{
"docstring... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from math import comb\n\nMOD = 10**9 + 7\n\ndef unique_ways(N, M, ingredients):\n \"\"\"\n Returns the number of unique ways to choose M ingredients from a l... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00070306",
"row_id": 70306,
"seed_ids": "[18403]"
} | 0.664972 | Taco_70306 | I | [
"factorial",
"mod_inverse",
"combination",
"number_of_ways_to_prepare_dish"
] | 4 | [
[
"combination",
"factorial"
],
[
"combination",
"mod_inverse"
],
[
"number_of_ways_to_prepare_dish",
"combination"
]
] | 3 | [] | false | [] | false | pytest | true | [] | true | 7d9a317d469bc0d3809b30e6cd2cc408fda8ce3a | dfecb9de983ede72c53162860e7beebac319285f | |||
v1.0 | instruct | Taco | Taco_70310_I | Given a string, you need to determine if it is a valid palindrome, considering only alphanumeric characters and ignoring cases and spaces.
A palindrome is a word, phrase, number, or other sequence of characters which reads the same backward as forward (ignoring spaces, punctuation, and capitalization).
For example, "... | def is_valid_palindrome(s):
"""
Determines if the given string is a valid palindrome, considering only alphanumeric characters and ignoring case.
"""
# Normalize the string: remove non-alphanumeric characters and convert to lower case
normalized_s = ''.join(char.lower() for char in s if char.isalnum... | from solution import check_palindrome
def test_example_1():
assert check_palindrome("A man, a plan, a canal: Panama") == "YES"
def test_example_2():
assert check_palindrome("racecar") == "YES"
def test_example_3():
assert check_palindrome("hello") == "NO"
def test_example_4():
assert check_palindrom... | [
{
"docstring": "Determines if the given string is a valid palindrome, considering only alphanumeric characters and ignoring case.",
"function_declaration": "def is_valid_palindrome(s):",
"function_name": "is_valid_palindrome",
"parameter_list": "(s)"
},
{
"docstring": "Outputs 'YES' if the g... | [
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_palindrome(s: str) -> str:\n \"\"\"\n Check if the given string is a valid palindrome, considering only alphanumeric characters and ignoring cas... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00070310",
"row_id": 70310,
"seed_ids": "[9473]"
} | 0.763182 | Taco_70310 | I | [
"is_valid_palindrome",
"check_palindrome"
] | 2 | [
[
"check_palindrome",
"is_valid_palindrome"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | e1ce35de3e3c6117eaf6c0890e546a3fe87faaa6 | b91d61bbfc9575643c977df616b709fbe96594f3 | |||
v1.0 | instruct | Taco | Taco_70356_I | A gardener wants to build a pyramid-shaped flower bed in his garden. The flower bed will be composed of layers of flowers, where each layer forms an upside-down triangle. The gardener will plant the flowers in a specific order. Each layer i (0-indexed) contains flowers numbered from `1` to `2^i`. The top layer is layer... | def generate_flower_bed(n):
flower_bed = []
for i in range(1, n + 1):
layer = []
for j in range(1, i + 1):
layer.append(j)
for j in range(i - 1, 0, -1):
layer.append(j)
flower_bed.append(layer)
return flower_bed
def print_flower_bed(n):
flower_bed... | from solution import generate_flower_bed, print_flower_bed
def test_generate_flower_bed_single_layer():
result = generate_flower_bed(1)
assert result == [[1]]
def test_generate_flower_bed_two_layers():
result = generate_flower_bed(2)
assert result == [[1], [1, 2, 1]]
def test_generate_flower_bed_thre... | [
{
"docstring": null,
"function_declaration": "def generate_flower_bed(n):",
"function_name": "generate_flower_bed",
"parameter_list": "(n)"
},
{
"docstring": null,
"function_declaration": "def print_flower_bed(n):",
"function_name": "print_flower_bed",
"parameter_list": "(n)"
}... | [
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 flower_bed(n):\n \"\"\"\n Prints a pyramid-shaped flower bed for a given n.\n \"\"\"\n for i in range(n):\n # Calculate the leading spaces\n... | trial_gpt4o_6 | {
"original_instruction": "",
"prompt_id": "00070356",
"row_id": 70356,
"seed_ids": "[5349]"
} | 0.584224 | Taco_70356 | I | [
"generate_flower_bed",
"print_flower_bed"
] | 2 | [
[
"print_flower_bed",
"generate_flower_bed"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 7c15f33dcd16ad1e4e5b64456ec4ea7711321ee2 | 0a0d9957a7e9d123c223ffce08a3e8c4ece5fcec | |||
v1.0 | instruct | Taco | Taco_70430_I | $Aarav$ is an esteemed mathematician in the kingdom of $Mathland$. To protect the kingdom from invaders, he proposed a safeguard mechanism that uses prime numbers. As a result, the king has charged him with a special task to encrypt messages using prime numbers. Aarav has to arrange $N$ integer numbers in such a way th... | def is_prime(num):
if num < 2:
return False
if num == 2:
return True
if num % 2 == 0:
return False
p = 3
while p * p <= num:
if num % p == 0:
return False
p += 2
return True
def prime_nonprime_sort(numbers):
primes = [num for num in number... | def test_is_prime():
assert is_prime(2) == True
assert is_prime(17) == True
assert is_prime(19) == True
assert is_prime(1) == False
assert is_prime(0) == False
assert is_prime(15) == False
def test_prime_nonprime_sort():
assert prime_nonprime_sort([10, 29, 3, 20, 17, 5, 18, 2, 11, 19]) ... | [
{
"docstring": null,
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": null,
"function_declaration": "def prime_nonprime_sort(numbers):",
"function_name": "prime_nonprime_sort",
"parameter_list": "(numbers)"
}... | [
1,
0,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(n):\n \"\"\"\n Helper function to check if a number is prime.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00070430",
"row_id": 70430,
"seed_ids": "[8573]"
} | 0.613551 | Taco_70430 | I | [
"is_prime",
"prime_nonprime_sort"
] | 2 | [
[
"prime_nonprime_sort",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | 589e142d683bd2b70cebc5637b9ecdfa1cfc6d5d | 3c0ba54d1a09b9690078575cd5189c9c3699f9f5 | |||
v1.0 | instruct | Taco | Taco_70478_I | You are given a list of natural numbers. Your task is to determine which of the given numbers are prime.
Input
An integer T, denoting the number of testcases, followed by T lines, each containing a single natural number N.
Output
For each integer N given at input, output a single line containing "Yes" if N is a prim... | def is_prime(n):
"""
Determines if a given number n is prime.
:param n: The integer to check for primality.
:return: True if n is a prime number, else False.
"""
if n <= 1:
return False
if n <= 3:
return True
if n % 2 == 0 or n % 3 == 0:
return False
i = ... | from solution import is_prime, check_primes
def test_is_prime():
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(4) == False
assert is_prime(5) == True
assert is_prime(10) == False
assert is_prime(1) == False
assert is_prime(29) == True
assert is_prime(30) == False... | [
{
"docstring": "Determines if a given number n is prime.\n\n:param n: The integer to check for primality.\n:return: True if n is a prime number, else False.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Determines prime ... | [
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_2 | {
"original_instruction": "",
"prompt_id": "00070478",
"row_id": 70478,
"seed_ids": "[9772]"
} | 0.709101 | Taco_70478 | I | [
"is_prime",
"check_primes"
] | 2 | [
[
"check_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | a2602b114c57886f6031ba4e79986592fc85bd15 | ceb1e5a022a43e23d11275de3e1a67d29ffd5fc8 | |||
v1.0 | instruct | Taco | Taco_70507_I | You are given an array b consisting of n integers. Your task is to find out if there exists a subarray (a contiguous subsequence) of the given array whose sum is a prime number.
If such a subarray exists, print "YES". Otherwise, print "NO".
Input
The first line of the input contains one integer n (1 ≤ n ≤ 2000) — th... | 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 subarray_with_prime_sum(arr):
n = len(... | from solution import subarray_with_prime_sum
def test_positive_case_1():
assert subarray_with_prime_sum([1, 2, 3, 4, 5]) == "YES"
def test_positive_case_2():
assert subarray_with_prime_sum([7, 1, 12]) == "YES"
def test_negative_case_1():
assert subarray_with_prime_sum([4, 6, 8, 10]) == "NO"
def test_sin... | [
{
"docstring": null,
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": null,
"function_declaration": "def subarray_with_prime_sum(arr):",
"function_name": "subarray_with_prime_sum",
"parameter_list": "(arr)"
}
] | [
0,
0,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(n):\n \"\"\"\n Helper function to check if a number is prime.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00070507",
"row_id": 70507,
"seed_ids": "[1803]"
} | 0.654728 | Taco_70507 | I | [
"is_prime",
"subarray_with_prime_sum"
] | 2 | [
[
"subarray_with_prime_sum",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 90efb96fbbc7cefbe00e077dddf2b935889f5a43 | 2b1d236dbee4a5f3e0e0e2e61210e582ec350aa6 | |||
v1.0 | instruct | Taco | Taco_70559_I | Alex loves puzzles, especially those that involve numbers. Recently, he came across a challenge where he needs to find the smallest positive integer that is evenly divisible by all of the numbers from 1 to a given integer N.
Given a number N, write a program to determine the smallest positive integer that is evenly di... | from math import gcd
def lcm(a, b):
"""
Returns the least common multiple of a and b.
"""
return a * b // gcd(a, b)
def smallest_multiple(N):
"""
Returns the smallest positive integer that is evenly divisible by all the numbers from 1 to N.
"""
smallest_mul = 1
for i in range(1, N ... | from solution import smallest_multiple, solve
def test_smallest_multiple():
assert smallest_multiple(1) == 1
assert smallest_multiple(5) == 60
assert smallest_multiple(10) == 2520
assert smallest_multiple(4) == 12
assert smallest_multiple(6) == 60
def test_solve():
inputs = ["3", "1", "5", "10... | [
{
"docstring": "Returns the least common multiple of a and b.",
"function_declaration": "def lcm(a, b):",
"function_name": "lcm",
"parameter_list": "(a, b)"
},
{
"docstring": "Returns the smallest positive integer that is evenly divisible by all the numbers from 1 to N.",
"function_decla... | [
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 lcm(a, b):\n return a * b // math.gcd(a, b)\n\ndef smallest_multiple(n):\n smallest_mult = 1\n for i in range(1, n + 1):\n small... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00070559",
"row_id": 70559,
"seed_ids": "[1887]"
} | 0.704403 | Taco_70559 | I | [
"lcm",
"smallest_multiple",
"solve"
] | 3 | [
[
"smallest_multiple",
"lcm"
],
[
"solve",
"smallest_multiple"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 73c320129b3b2fef3313f9feec307769657a588d | a8584d7dfe2fa131a7b025adddd0633b5a73bf03 | |||
v1.0 | instruct | Taco | Taco_70595_I | Chef is trying to cut a large rectangular cake which is represented by a grid of cells of size M x N. Each cell can be either plain (represented by '.') or contain a strawberry (represented by 'S'). Chef can only make vertical or horizontal cuts between the cells, and once a cut is made, it continues across the entire ... | def can_cut_into_k_pieces(M, N, K, cake):
# Count the number of strawberries in the cake
strawberry_count = sum(row.count('S') for row in cake)
# If the number of strawberries is greater than K, it's impossible to achieve the goal.
if strawberry_count > K:
return "NO"
# If there ar... | from solution import solve, parse_input
def test_case_1():
input_string = """3
3 3 4
...
.S.
...
5 5 5
.....
...S.
.....
.S...
.....
4 4 2
.S..
..S.
....
...."""
test_cases = parse_input(input_string)
assert solve(test_cases) == ["YES", "NO", "NO"]
def test_case_2():
input_string = """1
5 5 10
..S..
.... | [
{
"docstring": null,
"function_declaration": "def can_cut_into_k_pieces(M, N, K, cake):",
"function_name": "can_cut_into_k_pieces",
"parameter_list": "(M, N, K, cake)"
},
{
"docstring": null,
"function_declaration": "def solve(test_cases):",
"function_name": "solve",
"parameter_l... | [
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 can_cut_cake(M, N, K, cake_grid):\n # Count the number of strawberries\n strawberry_count = sum(row.count('S') for row in cake_grid)\n\n # To cut into... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00070595",
"row_id": 70595,
"seed_ids": "[8116]"
} | 0.80055 | Taco_70595 | I | [
"can_cut_into_k_pieces",
"solve",
"parse_input"
] | 3 | [
[
"solve",
"can_cut_into_k_pieces"
]
] | 1 | [
"parse_input"
] | false | [] | false | pytest | true | [] | true | d3bd8c5412f07ef9c1460082b648ce2c913d3593 | d00ff01da0b574d3e4ae16ace5881fc21dfdbb7a | |||
v1.0 | instruct | Taco | Taco_70619_I | You are tasked with designing a city road network for a new smart city project. The city will consist of n buildings connected by roads. The goal is to ensure that there is no cycle in the road network while minimizing the total length of the roads. Thus, the network should form a Minimum Spanning Tree (MST).
Each bu... | import math
import heapq
def calculate_distance(x1, y1, x2, y2):
return math.sqrt((x2 - x1) ** 2 + (y2 - y1) ** 2)
def minimum_spanning_tree(n, coordinates):
edges = []
for i in range(n):
for j in range(i + 1, n):
x1, y1 = coordinates[i]
x2, y2 = coordinates[j]
... | from solution import minimum_spanning_tree
def test_example_1():
n = 4
coordinates = [(0, 0), (0, 1), (1, 0), (1, 1)]
result = minimum_spanning_tree(n, coordinates)
assert math.isclose(result, 3.0000000000, abs_tol=1e-6)
def test_example_2():
n = 3
coordinates = [(0, 0), (4, 0), (0, 3)]
re... | [
{
"docstring": null,
"function_declaration": "def calculate_distance(x1, y1, x2, y2):",
"function_name": "calculate_distance",
"parameter_list": "(x1, y1, x2, y2)"
},
{
"docstring": null,
"function_declaration": "def minimum_spanning_tree(n, coordinates):",
"function_name": "minimum_... | [
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": "import math\nimport heapq\n\ndef euclidean_distance(point1, point2):\n return math.sqrt((point1[0] - point2[0]) ** 2 + (point1[1] - point2[1]) ** 2)\n\ndef mini... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00070619",
"row_id": 70619,
"seed_ids": "[4414]"
} | 0.650578 | Taco_70619 | I | [
"calculate_distance",
"minimum_spanning_tree"
] | 2 | [
[
"minimum_spanning_tree",
"calculate_distance"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 23a0efe89e8af17d40a0cde92990057507d533f5 | 80183ca1d5b456ccaa4c7bce06e52c3700e4940e | |||
v1.0 | instruct | Taco | Taco_70625_I | In a sports event, athletes competed in multiple events, and their scores for each event have been recorded. The athlete with the highest total score wins. If there is a tie, the athlete with the lowest participant number is declared the winner.
Create a program that reads the list of participant numbers, the number o... | def find_winner(participants_scores):
"""
Finds the winner based on the highest total score.
In case of a tie, the participant with the lower number wins.
:param participants_scores: List of tuples where each tuple contains participant number and their scores in all events.
:return: Tuple cont... | from solution import sports_event_winner
def test_single_participant():
input_data = "1 3\n1 10 20 30"
assert sports_event_winner(input_data) == "1 60"
def test_multiple_participants():
input_data = "3 2\n1 50 60\n2 60 50\n3 30 40"
assert sports_event_winner(input_data) == "1 110"
def test_tie_with_l... | [
{
"docstring": "Finds the winner based on the highest total score. \nIn case of a tie, the participant with the lower number wins.\n\n:param participants_scores: List of tuples where each tuple contains participant number and their scores in all events.\n:return: Tuple containing the winner's participant number... | [
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 find_winner(n, m, scores):\n max_score = -1\n winner_number = -1\n \n for participant in scores:\n total_score = sum(participant[1])\n ... | trial_gpt4o_6 | {
"original_instruction": "",
"prompt_id": "00070625",
"row_id": 70625,
"seed_ids": "[25258]"
} | 0.763737 | Taco_70625 | I | [
"find_winner",
"sports_event_winner"
] | 2 | [
[
"sports_event_winner",
"find_winner"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 3627edb4a98c4f3a7d30655909525a8eaebd2d31 | 1c174b54ca6a6af60f6b13c112b537f7d260927d | |||
v1.0 | instruct | Taco | Taco_70651_I | You are given an array of n integers and a series of q queries. Each query consists of a single integer value and requires you to find the number of distinct integers in the array that are less than or equal to that query value.
Input
The first line contains two integers n and q (1 ≤ n, q ≤ 100000) - the size of the ... | def preprocess_array(arr):
"""
Preprocess the given array to get only distinct elements and then sort them.
This will be used to quickly answer the queries.
"""
return sorted(set(arr))
def count_distinct_leq(preprocessed_arr, x):
"""
Count the number of distinct elements in the preprocessed... | import pytest
from solution import distinct_elements_count
def test_example_1():
assert distinct_elements_count(6, 3, [1, 5, 2, 2, 3, 5], [2, 4, 5]) == [2, 3, 4]
def test_example_2():
assert distinct_elements_count(5, 2, [8, 8, 8, 8, 8], [7, 9]) == [0, 1]
def test_single_element_array():
assert distinct_... | [
{
"docstring": "Preprocess the given array to get only distinct elements and then sort them.\nThis will be used to quickly answer the queries.",
"function_declaration": "def preprocess_array(arr):",
"function_name": "preprocess_array",
"parameter_list": "(arr)"
},
{
"docstring": "Count the n... | [
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 count_distinct_less_equal(arr, queries):\n \"\"\"\n Returns a list where each element is the number of distinct integers in the array \n that are less... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00070651",
"row_id": 70651,
"seed_ids": "[7110]"
} | 0.73007 | Taco_70651 | I | [
"preprocess_array",
"count_distinct_leq",
"distinct_elements_count"
] | 3 | [
[
"distinct_elements_count",
"count_distinct_leq"
],
[
"distinct_elements_count",
"preprocess_array"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 2307ed4384be13f57b025e48d091cd8608e4ba9f | c1735f15449368931784c21036cda2cdff969d54 | |||
v1.0 | instruct | Taco | Taco_70660_I | You are given a set of integers. You need to answer a series of queries, each asking for the smallest prime number greater than or equal to a given integer in the set.
To simplify, each query specifies an integer x, and you need to find the smallest prime number in the set which is greater than or equal to x.
Constra... | from bisect import bisect_left
import sys
input = sys.stdin.read
def sieve(limit):
is_prime = [True] * (limit + 1)
is_prime[0] = is_prime[1] = False
for i in range(2, int(limit**0.5) + 1):
if is_prime[i]:
for j in range(i * i, limit + 1, i):
is_prime[j] = False
retur... | from solution import smallest_prime_geq
def test_example_1():
arr = [2, 3, 5, 7, 11, 13]
queries = [4, 6, 12]
assert smallest_prime_geq(arr, queries) == [5, 7, 13]
def test_example_2():
arr = [1, 4, 6, 8, 9]
queries = [5, 10]
assert smallest_prime_geq(arr, queries) == [-1, -1]
def test_only_p... | [
{
"docstring": null,
"function_declaration": "def sieve(limit):",
"function_name": "sieve",
"parameter_list": "(limit)"
},
{
"docstring": null,
"function_declaration": "def smallest_prime_geq(arr, queries):",
"function_name": "smallest_prime_geq",
"parameter_list": "(arr, queries... | [
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 bisect import bisect_left\nimport sys\ninput = sys.stdin.read\n\ndef sieve(limit):\n is_prime = [True] * (limit + 1)\n is_prime[0] = is_prime[1] = False... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00070660",
"row_id": 70660,
"seed_ids": "[8111]"
} | 0.654391 | Taco_70660 | I | [
"sieve",
"smallest_prime_geq",
"main"
] | 3 | [
[
"smallest_prime_geq",
"sieve"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 5f389256ab445f8d633413ee7b60124b91173a33 | 9e1747f542425e28247f24abd41f8ed36090d189 | |||
v1.0 | instruct | Taco | Taco_70663_I | An n x n matrix is defined as a "quasi-symmetric" matrix if, for every pair of indices (i, j), the sum of matrix elements satisfies the following condition:
```
A[i][j] + A[j][i] = A[n-1-i][n-1-j] + A[n-1-j][n-1-i]
```
You are given a matrix of size n x n (1 ≤ n ≤ 500) filled with integers. Determine whether the given... | def is_quasi_symmetric(matrix):
n = len(matrix)
for i in range(n):
for j in range(n):
if matrix[i][j] + matrix[j][i] != matrix[n-1-i][n-1-j] + matrix[n-1-j][n-1-i]:
return False
return True
def check_quasi_symmetric(string_input):
lines = string_input.strip().split('... | import pytest
from solution import check_quasi_symmetric
def test_example_case():
input_data = "3\n1 2 3\n4 5 6\n7 8 9"
assert check_quasi_symmetric(input_data) == "NO"
def test_symmetric_case():
input_data = "2\n1 2\n2 1"
assert check_quasi_symmetric(input_data) == "YES"
def test_another_case():
... | [
{
"docstring": null,
"function_declaration": "def is_quasi_symmetric(matrix):",
"function_name": "is_quasi_symmetric",
"parameter_list": "(matrix)"
},
{
"docstring": null,
"function_declaration": "def check_quasi_symmetric(string_input):",
"function_name": "check_quasi_symmetric",
... | [
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 is_quasi_symmetric(matrix):\n \"\"\"\n Determines if a given n x n matrix is quasi-symmetric.\n \n Args:\n matrix (list of list of int): The inp... | trial_gpt4o_7 | {
"original_instruction": "",
"prompt_id": "00070663",
"row_id": 70663,
"seed_ids": "[8731]"
} | 0.564995 | Taco_70663 | I | [
"is_quasi_symmetric",
"check_quasi_symmetric"
] | 2 | [
[
"check_quasi_symmetric",
"is_quasi_symmetric"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | e14f55394e9e6e2c5a83eb6b9e76ffb057bb5870 | d4545060e7a1210a88f3d51aa459a86eacd78657 | |||
v1.0 | instruct | Taco | Taco_70669_I | You are given a string `S` consisting of lowercase English letters. Your task is to process the string to create a new string `T` based on the following operations, which you can perform any number of times:
1. If there are two adjacent same letters `aa` in the string, you can replace them with a single letter `a`.
2.... | def can_be_single_character_string(S):
"""
Function to determine if it is possible to transform the string S into a
single-character string.
"""
for i in range(1, len(S)):
# Check if there is any adjacent pair of different characters
if S[i] != S[i-1]:
return "IMPOSSIBLE"... | from solution import can_be_single_character_string, process_test_cases
def test_can_be_single_character_string():
assert can_be_single_character_string("aaab") == "IMPOSSIBLE"
assert can_be_single_character_string("bbbaa") == "IMPOSSIBLE"
assert can_be_single_character_string("a") == "a"
assert can_be... | [
{
"docstring": "Function to determine if it is possible to transform the string S into a\nsingle-character string.",
"function_declaration": "def can_be_single_character_string(S):",
"function_name": "can_be_single_character_string",
"parameter_list": "(S)"
},
{
"docstring": "Function to pro... | [
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 can_transform_to_single_char(S):\n \"\"\"\n Determines if the string S can be transformed into a single-character\n string using the given operations.... | trial_gpt4o_3 | {
"original_instruction": "",
"prompt_id": "00070669",
"row_id": 70669,
"seed_ids": "[19990]"
} | 0.80728 | Taco_70669 | I | [
"can_be_single_character_string",
"process_test_cases",
"solution"
] | 3 | [
[
"process_test_cases",
"can_be_single_character_string"
],
[
"solution",
"process_test_cases"
]
] | 2 | [
"process_test_cases"
] | false | [] | false | pytest | true | [] | true | 44059889125edc600e3860b86cfb9b77d4f0fe55 | 2b5c5c2517baba2faee13eb33c8cb1eb9b72c09a | |||
v1.0 | instruct | Taco | Taco_70716_I | Alice and Bob love playing a game involving prime numbers. Together, they came up with a new challenge: finding the product of all prime numbers between two given numbers inclusive.
Given two positive integers, l and r, Alice wants to know the product of all prime numbers in this range modulo 10^9 + 7. Bob, being impa... | def sieve(max_num):
"""
Generate a list of booleans representing primality of numbers from 0 to max_num.
"""
is_prime = [True] * (max_num + 1)
is_prime[0] = is_prime[1] = False
for p in range(2, int(max_num**0.5) + 1):
if is_prime[p]:
for i in range(p * p, max_num + 1, p... | import pytest
from solution import sieve, prime_product, process_test_cases
def test_sieve():
is_prime, primes = sieve(30)
expected_primes_up_to_30 = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29]
assert primes == expected_primes_up_to_30
assert is_prime[0] == False
assert is_prime[1] == False
assert is_... | [
{
"docstring": "Generate a list of booleans representing primality of numbers from 0 to max_num.",
"function_declaration": "def sieve(max_num):",
"function_name": "sieve",
"parameter_list": "(max_num)"
},
{
"docstring": "Calculate the product of all prime numbers between l and r inclusive.\n... | [
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 sieve_of_eratosthenes(n):\n \"\"\"\n Generate a list of prime numbers up to n (inclusive) using the Sieve of Eratosthenes algorithm.\n \"\"\"\n is_... | trial_gpt4o_8 | {
"original_instruction": "",
"prompt_id": "00070716",
"row_id": 70716,
"seed_ids": "[11586]"
} | 0.586183 | Taco_70716 | I | [
"sieve",
"prime_product",
"process_test_cases"
] | 3 | [
[
"process_test_cases",
"prime_product"
],
[
"process_test_cases",
"sieve"
]
] | 2 | [
"process_test_cases"
] | false | [] | false | pytest | true | [] | true | 8ff025de7f6cd7e6c5bc02ac37542b36d9883502 | b62eb6cedb16ac4f14b34328583795aa2f42ea54 | |||
v1.0 | instruct | Taco | Taco_70719_I | Given a 2D grid of characters representing a map of islands (*'L'*) and water (*'W'*), you need to determine the size of the largest island. An island is defined as a group of adjacent cells containing 'L' connected in horizontal or vertical directions.
**Input:**
- First line contains two integers $M$ and $N$ ($1 \le... | def largest_island_size(grid):
"""
Returns the size of the largest island in the given 2D grid of 'L' and 'W'.
An island is defined as a group of adjacent 'L's connected horizontally or vertically.
"""
def is_valid(x, y, visited):
return 0 <= x < len(grid) and 0 <= y < len(grid[0]) and ... | def test_largest_island_size_example1():
data = """4 5
LWLWL
WWWLL
LLLWW
LWLWL"""
assert process_largest_island_size_input(data) == 5
def test_largest_island_size_example2():
data = """3 3
WLW
LLL
WLW"""
assert process_largest_island_size_input(data) == 5
def test_no_islands():
data = """2 2
WW
WW... | [
{
"docstring": "Returns the size of the largest island in the given 2D grid of 'L' and 'W'.\nAn island is defined as a group of adjacent 'L's connected horizontally or vertically.",
"function_declaration": "def largest_island_size(grid):",
"function_name": "largest_island_size",
"parameter_list": "(... | [
0,
1,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def largest_island_size(grid):\n def dfs(x, y):\n if x < 0 or x >= M or y < 0 or y >= N or grid[x][y] != 'L':\n return 0\n grid[x][y] =... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00070719",
"row_id": 70719,
"seed_ids": "[2567]"
} | 0.633023 | Taco_70719 | I | [
"largest_island_size",
"process_largest_island_size_input"
] | 2 | [
[
"process_largest_island_size_input",
"largest_island_size"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | 26bccf1a8ad79d81ae5a5616204205d87fa78673 | 45d27544ec322f3a1e9f0fc6812c1d95fdd8a3f1 | |||
v1.0 | instruct | Taco | Taco_70729_I | A delivery company has a large fleet of delivery trucks that often visit multiple destinations. Each truck has a delivery capacity, which is the maximum number of locations it can visit in one trip. Due to recent traffic issues, the company wants to minimize the total travel distance of its trucks while still completin... | import heapq
import sys
from collections import defaultdict, deque
def dijkstra(graph, start, n):
distances = [float('inf')] * (n + 1)
distances[start] = 0
priority_queue = [(0, start)]
while priority_queue:
current_distance, current_node = heapq.heappop(priority_queue)
if... | def test_example_1():
n = 5
m = 6
roads = [
(1, 2, 3),
(1, 3, 4),
(1, 4, 2),
(2, 4, 5),
(3, 4, 1),
(4, 5, 6)
]
k = 3
capacities = [2, 2, 4]
l = 3
deliveries = [
(1, 5),
(3, 3),
(5, 1)
]
assert can_complete_de... | [
{
"docstring": null,
"function_declaration": "def dijkstra(graph, start, n):",
"function_name": "dijkstra",
"parameter_list": "(graph, start, n)"
},
{
"docstring": null,
"function_declaration": "def can_complete_deliveries(n, m, roads, k, capacities, l, deliveries):",
"function_name"... | [
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": "import heapq\n\ndef dijkstra(adj, start, n):\n # Initialize distances and priority queue\n dist = [float('inf')] * (n + 1)\n dist[start] = 0\n pq = [(0... | trial_gpt4o_4 | {
"original_instruction": "",
"prompt_id": "00070729",
"row_id": 70729,
"seed_ids": "[11780]"
} | 0.749865 | Taco_70729 | I | [
"dijkstra",
"can_complete_deliveries"
] | 2 | [
[
"can_complete_deliveries",
"dijkstra"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | bca58f7b8167dacad476369cc2f99e134f79dc3e | 5c737ce42b6105f53457224b7f875d8fa6087964 | |||
v1.0 | instruct | Taco | Taco_70767_I | Given an array of integers, determine whether a subset of the array exists whose sum is prime. If such a subset exists, return the smallest prime number that can be obtained, otherwise return -1.
Input Format
The first line of the input contains an integer ${n}$, which is the number of elements in the array.
The sec... | import itertools
def is_prime(n):
"""
Check if a number n is prime.
"""
if n <= 1:
return False
if n == 2:
return True
if n % 2 == 0:
return False
for i in range(3, int(n**0.5) + 1, 2):
if n % i == 0:
return False
return True
def smallest_pri... | from solution import smallest_prime_subset_sum
def test_smallest_prime_subset_sum_example():
assert smallest_prime_subset_sum(5, [3, 5, 7, -2, 8]) == 3
def test_smallest_prime_subset_sum_no_primes():
assert smallest_prime_subset_sum(5, [4, 6, 8, 10, 12]) == -1
def test_smallest_prime_subset_sum_single_elemen... | [
{
"docstring": "Check if a number n is prime.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Determine the smallest prime sum from any subset of the array.",
"function_declaration": "def smallest_prime_subset_sum(n, a... | [
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 itertools\nimport math\n\ndef is_prime(num):\n \"\"\"\n Function to check if a given number is prime.\n \"\"\"\n if num <= 1:\n return Fa... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00070767",
"row_id": 70767,
"seed_ids": "[1389]"
} | 0.708626 | Taco_70767 | I | [
"is_prime",
"smallest_prime_subset_sum"
] | 2 | [
[
"smallest_prime_subset_sum",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 061053be09d943e8fa465e395876bfa29a56a692 | 7914ecabfc5468e2dadca3303eeff661cc31866c | |||
v1.0 | instruct | Taco | Taco_70786_I | Problem :
You are given an array A comprising of N non-negative integers A[1], A[2]...A[N]. You need to perform a series of operations that include updating the array and calculating the sum of elements within a given range. The two types of queries you will receive are:
1. Update operation: 1 x y - Update the value ... | def update_value(array, index, value):
"""
Updates the value at the given index of the array.
"""
array[index - 1] = value
def range_sum(array, left, right):
"""
Returns the sum of elements in the array from index left to right, inclusive.
"""
return sum(array[left - 1:right])
def proc... | import pytest
from solution import update_value, range_sum, process_queries
def test_update_value():
array = [1, 2, 3, 4, 5]
update_value(array, 2, 10)
assert array == [1, 10, 3, 4, 5]
def test_range_sum():
array = [1, 2, 3, 4, 5]
assert range_sum(array, 1, 3) == 6
assert range_sum(array, 2, 4... | [
{
"docstring": "Updates the value at the given index of the array.",
"function_declaration": "def update_value(array, index, value):",
"function_name": "update_value",
"parameter_list": "(array, index, value)"
},
{
"docstring": "Returns the sum of elements in the array from index left to rig... | [
1,
0,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "class NumArray:\n def __init__(self, nums):\n self.nums = nums\n self.n = len(nums)\n self.tree = [0] * (self.n + 1)\n for i in rang... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00070786",
"row_id": 70786,
"seed_ids": "[10517]"
} | 0.679077 | Taco_70786 | I | [
"update_value",
"range_sum",
"process_queries"
] | 3 | [
[
"process_queries",
"range_sum"
],
[
"process_queries",
"update_value"
]
] | 2 | [
"process_queries"
] | false | [] | false | pytest | true | [] | true | 2fb13f9b66f1237be63b8d9d92ddeab2a6cdc08c | 826c7b242489d8296e8a77fe4afac5b9198a2fab | |||
v1.0 | instruct | Taco | Taco_70865_I | Function checkPalindrome() is an ideal interview question testing for understanding of recursion and string manipulation.
Given a string s, check if it can be transformed into a palindrome by removing at most one character from it. A string is considered a palindrome if it reads the same forward and backward.
Example ... | def is_palindrome(s: str) -> bool:
"""
Helper function to check if a string is a palindrome.
"""
return s == s[::-1]
def isAlmostPalindrome(s: str) -> bool:
"""
Returns True if the string s can be transformed into a palindrome by
removing at most one character, otherwise, returns False.
... | def test_isAlmostPalindrome():
assert isAlmostPalindrome("abca") == True
assert isAlmostPalindrome("abc") == False
assert isAlmostPalindrome("a") == True
assert isAlmostPalindrome("aa") == True
assert isAlmostPalindrome("racecar") == True
assert isAlmostPalindrome("raceecar") == True
assert ... | [
{
"docstring": "Helper function to check if a string is a palindrome.",
"function_declaration": "def is_palindrome(s):",
"function_name": "is_palindrome",
"parameter_list": "(s)"
},
{
"docstring": "Returns True if the string s can be transformed into a palindrome by \nremoving at most one ch... | [
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_palindrome(s):\n \"\"\"\n Helper function to check if a given string is a palindrome.\n \"\"\"\n return s == s[::-1]\n\ndef isAlmostPalindrome(s... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00070865",
"row_id": 70865,
"seed_ids": "[12790]"
} | 0.758065 | Taco_70865 | I | [
"is_palindrome",
"isAlmostPalindrome"
] | 2 | [
[
"isAlmostPalindrome",
"is_palindrome"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | 7bfd2d4c20c72b4dc0d6b17ef69fcd488eca2430 | 0688efe78c66f8e647e70d4df286bf44afa761d8 | |||
v1.0 | instruct | Taco | Taco_70912_I | For a given array of distinct integers, write a program to find all possible subsets (the power set) and output them in lexicographic order.
Constraints
* The array will have no more than 10 distinct elements.
* Each subset should be listed on a new line, with elements separated by a space.
* The subsets should appea... | from itertools import combinations
def find_subsets(numbers):
"""
Finds all possible subsets of the array and returns them in a lexicographic order.
"""
numbers.sort()
subsets = []
n = len(numbers)
for i in range(n + 1):
for comb in combinations(numbers, i):
subsets... | from solution import find_subsets, print_subsets
from io import StringIO
import sys
def test_find_subsets_with_3_elements():
numbers = [1, 2, 3]
result = find_subsets(numbers)
expected = [
(),
(1,),
(2,),
(3,),
(1, 2,),
(1, 3,),
(2, 3,),
(1, 2... | [
{
"docstring": "Finds all possible subsets of the array and returns them in a lexicographic order.",
"function_declaration": "def find_subsets(numbers):",
"function_name": "find_subsets",
"parameter_list": "(numbers)"
},
{
"docstring": null,
"function_declaration": "def print_subsets(n, ... | [
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": "from itertools import combinations\n\ndef power_set_lexicographic(arr):\n \"\"\"\n Returns the power set of the array sorted in lexicographic order.\n \"\... | trial_gpt4o_4 | {
"original_instruction": "",
"prompt_id": "00070912",
"row_id": 70912,
"seed_ids": "[6064]"
} | 0.538853 | Taco_70912 | I | [
"find_subsets",
"print_subsets"
] | 2 | [
[
"print_subsets",
"find_subsets"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 8c35791d23f2b5efad4ac0f872864b7eeb21e112 | e73a5e07b32617c88570d96a241b2c2fdd9cea20 | |||
v1.0 | instruct | Taco | Taco_70946_I | You are managing a warehouse and need to move packages between different locations. The warehouse consists of $N$ locations, represented as nodes in a graph, and there are $M$ bidirectional paths between these locations, represented as edges. Each edge has a weight associated with it, representing the time it takes to ... | import heapq
def dijkstra(N, M, S, T, edges):
graph = [[] for _ in range(N + 1)]
for u, v, w in edges:
graph[u].append((v, w))
graph[v].append((u, w))
pq = [(0, S)]
distances = {i: float('inf') for i in range(1, N + 1)}
distances[S] = 0
while pq:
current_distance, curr... | from solution import find_shortest_path
def test_shortest_path_sample_1():
N, M = 5, 6
S, T = 1, 5
edges = [
(1, 2, 4),
(1, 3, 2),
(2, 3, 5),
(2, 4, 10),
(3, 4, 3),
(4, 5, 7),
]
assert find_shortest_path(N, M, S, T, edges) == 12
def test_no_path(... | [
{
"docstring": null,
"function_declaration": "def dijkstra(N, M, S, T, edges):",
"function_name": "dijkstra",
"parameter_list": "(N, M, S, T, edges)"
},
{
"docstring": null,
"function_declaration": "def find_shortest_path(N, M, S, T, edges):",
"function_name": "find_shortest_path",
... | [
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 heapq\n\ndef shortest_path(N, M, S, T, edges):\n \"\"\"\n Calculate the shortest path from location S to location T using Dijkstra's algorithm.\n \... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00070946",
"row_id": 70946,
"seed_ids": "[5195]"
} | 0.807111 | Taco_70946 | I | [
"dijkstra",
"find_shortest_path"
] | 2 | [
[
"find_shortest_path",
"dijkstra"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 3ad776d6cae7910b78ab943ad6f01801a735628c | fd662b0d634c720085ede9835c388b07bad74d01 | |||
v1.0 | instruct | Taco | Taco_71002_I | A digital competition requires participants to unlock a secure vault by solving a sequence of challenges. Each participant needs to crack a custom sequence of lock codes that follow specific constraints. Your task is to write a program to determine whether a given sequence can be unlocked.
### Problem Description
A l... | def is_unlockable_sequence(N, sequence):
"""
Returns whether the given sequence of strings is unlockable.
A sequence is unlockable if all strings are permutations of
each other.
:param N: Number of strings in the sequence
:param sequence: List of strings representing the lock sequence
... | import pytest
from solution import is_unlockable_sequence, unlock_sequences
def test_is_unlockable_sequence_all_permutations():
assert is_unlockable_sequence(3, ['123', '321', '312']) == "Unlockable"
def test_is_unlockable_sequence_not_permutations():
assert is_unlockable_sequence(2, ['111', '121']) == "Not U... | [
{
"docstring": "Returns whether the given sequence of strings is unlockable.\nA sequence is unlockable if all strings are permutations of \neach other.\n\n:param N: Number of strings in the sequence\n:param sequence: List of strings representing the lock sequence\n:return: \"Unlockable\" if the sequence can be ... | [
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_unlockable(sequence):\n \"\"\"\n Determines if a sequence of strings can unlock the vault by\n verifying if all strings are permutations of each ot... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00071002",
"row_id": 71002,
"seed_ids": "[17887]"
} | 0.59965 | Taco_71002 | I | [
"is_unlockable_sequence",
"process_input",
"unlock_sequences"
] | 3 | [
[
"unlock_sequences",
"is_unlockable_sequence"
],
[
"unlock_sequences",
"process_input"
]
] | 2 | [
"process_input"
] | false | [] | false | pytest | true | [] | true | 6c0015854bb3ede3bd488aa36a2e6d10c05e3b44 | 3fdaea3a800df42ad56aeae2d0b7b2091943788c | |||
v1.0 | instruct | Taco | Taco_71008_I | Given a binary tree, the task is to find the left view of the binary tree. The left view of a binary tree is the set of nodes visible when the tree is viewed from the left side.
Example 1:
Input:
```
1
/ \
2 3
/ \ / \
4 5 6 7
\
8
```
Output: [1, 2, 4... | class Node:
def __init__(self, key):
self.data = key
self.left = None
self.right = None
def leftViewUtil(current_node, current_level, max_level, view):
"""Utility function to find the left view of the binary tree."""
if current_node is None:
return
# If this is the ... | from solution import Node, leftView
def test_left_view_example_1():
root = Node(1)
root.left = Node(2)
root.right = Node(3)
root.left.left = Node(4)
root.left.right = Node(5)
root.right.left = Node(6)
root.right.right = Node(7)
root.left.right.right = Node(8)
assert leftView(ro... | [] | [
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, value=0, left=None, right=None):\n self.value = value\n self.left = left\n self.right = right\n\ndef l... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00071008",
"row_id": 71008,
"seed_ids": "[1741]"
} | 0.511388 | Taco_71008 | I | [
"leftViewUtil",
"leftView"
] | 2 | [
[
"leftView",
"leftViewUtil"
]
] | 1 | [] | false | [
"Node"
] | true | pytest | true | [] | true | 61772c53138064c346913f3c8f3adfa98c2a1fa8 | a7795cadd783d65b26d9f7514950e15f943a977b | |||
v1.0 | instruct | Taco | Taco_71114_I | Alice is a big fan of number theory and enjoys playing with numbers. She has recently discovered an interesting property of numbers. She calls a number 'special' if the sum of its digits is divisible by 3. For example, 123 is special because 1 + 2 + 3 = 6, which is divisible by 3.
Given a number N, Alice wants to kno... | def is_special(num):
"""
Check if a number is 'special', i.e., if the sum of its digits is divisible by 3.
"""
digit_sum = sum(int(digit) for digit in str(num))
return digit_sum % 3 == 0
def find_smallest_special_number(N):
"""
Find the smallest 'special' number greater than or equal to N.
... | def test_is_special():
assert is_special(123) == True
assert is_special(38) == False
assert is_special(39) == True
assert is_special(57) == True
def test_find_smallest_special_number():
assert find_smallest_special_number(57) == 57
assert find_smallest_special_number(38) == 39
assert find_s... | [
{
"docstring": "Check if a number is 'special', i.e., if the sum of its digits is divisible by 3.",
"function_declaration": "def is_special(num):",
"function_name": "is_special",
"parameter_list": "(num)"
},
{
"docstring": "Find the smallest 'special' number greater than or equal to N.",
... | [
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 is_special_number(n):\n \"\"\"\n Checks whether the sum of digits of `n` is divisible by 3.\n \"\"\"\n return sum(int(digit) for digit in str(n)) %... | trial_gpt4o_4 | {
"original_instruction": "",
"prompt_id": "00071114",
"row_id": 71114,
"seed_ids": "[19727]"
} | 0.701955 | Taco_71114 | I | [
"is_special",
"find_smallest_special_number"
] | 2 | [
[
"find_smallest_special_number",
"is_special"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | 29a53d79b3a6d7045514356e393e813a1148bf50 | a91a921b1f63be9efd25ddec0bc2b4174f1bef07 | |||
v1.0 | instruct | Taco | Taco_71176_I | A company is organizing a team-building event where employees will participate in a series of tasks. Each task can be performed by one or more employees, and some tasks depend on the completion of others. In order to ensure the event runs smoothly, the organizers need to determine the order in which the tasks should be... | from collections import deque
def find_task_order(T, D, dependencies):
graph = {i: [] for i in range(1, T + 1)}
in_degrees = {i: 0 for i in range(1, T + 1)}
for a, b in dependencies:
graph[a].append(b)
in_degrees[b] += 1
queue = deque([node for node in in_degrees if in_degrees[node] =... | from solution import valid_task_sequence
def test_case_1():
assert valid_task_sequence(4, 3, [(1, 2), (1, 3), (3, 4)]) in {"1 3 4 2", "1 3 2 4", "1 2 3 4"}
def test_case_2():
assert valid_task_sequence(3, 3, [(1, 2), (2, 3), (3, 1)]) == "IMPOSSIBLE"
def test_case_3():
assert valid_task_sequence(2, 0, [])... | [
{
"docstring": null,
"function_declaration": "def find_task_order(T, D, dependencies):",
"function_name": "find_task_order",
"parameter_list": "(T, D, dependencies)"
},
{
"docstring": null,
"function_declaration": "def valid_task_sequence(T, D, dependencies):",
"function_name": "vali... | [
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": "from collections import defaultdict, deque\n\ndef find_task_order(T, D, dependencies):\n def kahn_topological_sort():\n in_degree = [0] * (T + 1)\n ... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00071176",
"row_id": 71176,
"seed_ids": "[5964]"
} | 0.587724 | Taco_71176 | I | [
"find_task_order",
"valid_task_sequence"
] | 2 | [
[
"valid_task_sequence",
"find_task_order"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 06a4c5baf5e5dfa10abdfc403b5d65f4ca48eedb | 5972f0b8e257fdf37abbeb8073ffabc240cb3de0 | |||
v1.0 | instruct | Taco | Taco_71179_I | Your friend is working on a virtual farming simulation game. The game world consists of a rectangular grid of size `n x m`. Each cell in the grid either contains fertile land or an obstacle (like a rock or a tree).
The objective of the game is to find the largest possible rectangular plot of fertile land where crops c... | def largest_rectangle_area_in_histogram(heights):
stack = []
max_area = 0
index = 0
while index < len(heights):
if not stack or heights[stack[-1]] <= heights[index]:
stack.append(index)
index += 1
else:
top_of_stack = stack.pop()
area ... | def test_largest_rectangle_in_grid_1():
n, m = 3, 4
grid = [
'1011',
'1101',
'1110'
]
assert largest_rectangle_in_grid(n, m, grid) == 4
def test_largest_rectangle_in_grid_2():
n, m = 2, 2
grid = [
'11',
'01'
]
assert largest_rectangle_in_grid(n, m... | [
{
"docstring": null,
"function_declaration": "def largest_rectangle_area_in_histogram(heights):",
"function_name": "largest_rectangle_area_in_histogram",
"parameter_list": "(heights)"
},
{
"docstring": null,
"function_declaration": "def largest_rectangle_in_grid(n, m, grid):",
"funct... | [
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_rectangle_area_in_histogram(heights):\n stack = []\n max_area = 0\n index = 0\n \n while index < len(heights):\n if not stack or ... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00071179",
"row_id": 71179,
"seed_ids": "[3071]"
} | 0.598253 | Taco_71179 | I | [
"largest_rectangle_area_in_histogram",
"largest_rectangle_in_grid"
] | 2 | [
[
"largest_rectangle_in_grid",
"largest_rectangle_area_in_histogram"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | 8d808026515c0cbf3ee6e14d928b2daef61af470 | c7d312ebc68fd2aab9d51c0e875f0179d07921d6 | |||
v1.0 | instruct | Taco | Taco_71188_I | Write a function that takes a list of integers and returns a new list containing only the prime numbers from the original list, arranged in descending order.
A prime number is a natural number greater than 1 that is not a product of two smaller natural numbers.
For example:
```python
get_primes([2, 3, 4, 5, 6, 7, 8,... | def is_prime(n):
"""
Helper function to check if a number is prime.
"""
if n <= 1:
return False
if n == 2:
return True
if n % 2 == 0:
return False
for i in range(3, int(n**0.5) + 1, 2):
if n % i == 0:
return False
return True
def get_primes(nu... | from solution import get_primes
def test_no_primes():
assert get_primes([1, 4, 6, 8, 10, 12]) == []
def test_some_primes():
assert get_primes([2, 3, 4, 5, 6, 7, 8, 9, 10]) == [7, 5, 3, 2]
def test_all_primes():
assert get_primes([2, 3, 5, 7, 11]) == [11, 7, 5, 3, 2]
def test_mixed_numbers():
ass... | [
{
"docstring": "Helper function to check if a number is prime.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Returns a list of prime numbers from the input list, sorted in descending order.",
"function_declaration": ... | [
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 number n is prime.\n \"\"\"\n if n <= 1:\n return False\n for i in range(2, int(n**... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00071188",
"row_id": 71188,
"seed_ids": "[20441]"
} | 0.734275 | Taco_71188 | I | [
"is_prime",
"get_primes"
] | 2 | [
[
"get_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 54c6e04897397e91bc852b24552a64d1bd9503cf | 983d019a4912f514b30b60597dae2962f0f49b46 | |||
v1.0 | instruct | Taco | Taco_71237_I | There is a large square grid of size N x N. Each cell in the grid can either be 'empty' or contain an 'obstacle'. You are given the grid and need to determine if there exists a path from the top-left corner of the grid (0, 0) to the bottom-right corner of the grid (N-1, N-1). You can only move right or down from any ce... | def path_exists(grid):
"""
Determines if there exists a path from the top-left corner to the bottom-right corner of the grid.
:param grid: List[List[str]] -- the grid of size N x N
:return: str -- "YES" if a path exists, otherwise "NO"
"""
N = len(grid)
if grid[0][0] == 'O' or grid[N-1]... | import pytest
from solution import exists_path_in_grids
def test_single_tests():
assert exists_path_in_grids(2, [
[['E', 'E'], ['E', 'O']],
[['E', 'O', 'E'], ['E', 'E', 'E'], ['O', 'E', 'E']]
]) == ["NO", "YES"]
def test_edge_case_smallest_grid():
assert exists_path_in_grids(1, [
[... | [
{
"docstring": "Determines if there exists a path from the top-left corner to the bottom-right corner of the grid.\n\n:param grid: List[List[str]] -- the grid of size N x N\n:return: str -- \"YES\" if a path exists, otherwise \"NO\"",
"function_declaration": "def path_exists(grid):",
"function_name": "p... | [
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 can_reach_end(grid):\n \"\"\"\n Determines if there exists a path from the top-left corner to the bottom-right corner in the grid.\n Only right and do... | trial_gpt4o_4 | {
"original_instruction": "",
"prompt_id": "00071237",
"row_id": 71237,
"seed_ids": "[16632]"
} | 0.731581 | Taco_71237 | I | [
"path_exists",
"exists_path_in_grids",
"formatted_result"
] | 3 | [
[
"exists_path_in_grids",
"path_exists"
],
[
"formatted_result",
"exists_path_in_grids"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | b11f64df0d4d1255b488c60e462eb3662948a1d1 | 3999c460570d00ef3cfa1ba12a60846857c543b5 | |||
v1.0 | instruct | Taco | Taco_71329_I | Given a string of digits, find and return all possible valid IP addresses that can be obtained by inserting dots into the string. A valid IP address must follow these rules:
1. It consists of exactly four integers, each integer is between 0 and 255, inclusive.
2. Integers cannot have leading zeros unless they are zero... | def is_valid(segment):
"""
Check if a segment is a valid IP address part.
"""
if not segment or (segment[0] == '0' and len(segment) > 1) or int(segment) > 255:
return False
return True
def restore_ip_addresses(s):
"""
Given a string of digits, return all possible valid IP addresses ... | from solution import restore_ip_addresses
def test_restore_ip_addresses_1():
assert restore_ip_addresses("25525511135") == ["255.255.11.135", "255.255.111.35"]
def test_restore_ip_addresses_2():
assert restore_ip_addresses("0000") == ["0.0.0.0"]
def test_restore_ip_addresses_3():
assert restore_ip_addres... | [
{
"docstring": "Check if a segment is a valid IP address part.",
"function_declaration": "def is_valid(segment):",
"function_name": "is_valid",
"parameter_list": "(segment)"
},
{
"docstring": "Given a string of digits, return all possible valid IP addresses by inserting dots.",
"function... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def valid_ip(s):\n \"\"\"\n Given a string containing only digits, return all possible valid IP addresses\n that can be obtained by inserting dots into th... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00071329",
"row_id": 71329,
"seed_ids": "[2141]"
} | 0.60006 | Taco_71329 | I | [
"is_valid",
"restore_ip_addresses"
] | 2 | [
[
"restore_ip_addresses",
"is_valid"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 22208119ad520e2fbb980272dff61f7e930a5bbc | e18e9c7547f4a0abc7c2ac7f50ae54607b7de166 | |||
v1.0 | instruct | Taco | Taco_71367_I | Given a positive integer `n`, return the smallest prime number that is greater than `n`. If `n` is a prime number itself, return the next prime number.
**Note**: Efficient solutions are required because large inputs will be tested.
## Examples:
For `n = 7`, the next prime number is `11`.
For `n = 14`, the next prim... | def is_prime(num):
"""
Helper function to check if a number is prime.
"""
if num <= 1:
return False
if num <= 3:
return True
if num % 2 == 0 or num % 3 == 0:
return False
i = 5
while i * i <= num:
if num % i == 0 or num % (i + 2) == 0:
return F... | from solution import next_prime
def test_next_prime_of_7():
assert next_prime(7) == 11
def test_next_prime_of_14():
assert next_prime(14) == 17
def test_next_prime_of_29():
assert next_prime(29) == 31
def test_next_prime_of_prime_number_23():
assert next_prime(23) == 29
def test_next_prime_of_large... | [
{
"docstring": "Helper function to check if a number is prime.",
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": "Returns the smallest prime number that is greater than n.\nIf n is a prime number itself, returns the next ... | [
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(x):\n \"\"\"\n Checks whether a given number x is prime.\n \"\"\"\n if x <= 1:\n return False\n if x <= 3:\n return True\... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00071367",
"row_id": 71367,
"seed_ids": "[6940]"
} | 0.5914 | Taco_71367 | I | [
"is_prime",
"next_prime"
] | 2 | [
[
"next_prime",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | f42759b28db78ce31f0e09d0984976ea68f8ddc7 | bd3bff960f79b506e503a8128956ce4400505099 | |||
v1.0 | instruct | Taco | Taco_71427_I | A common problem in software engineering is managing file paths. Operating systems provide various APIs to handle file operations such as reading and writing data to files, navigating directories, and managing paths.
# Path Manager Contract
## normalize(path)
`normalize` accepts a string `path` representing a file p... | import os
def normalize(path):
"""
Normalize the given file path by removing redundant cwd (.) and parent (..) references and unnecessary slashes.
"""
if not isinstance(path, str) or not path:
raise ValueError("Invalid path")
normalized_path = os.path.normpath(path)
if normalized_path =... | import pytest
from solution import normalize, is_absolute, join, basename
def test_normalize():
assert normalize("a/b/../c/./d") == "a/c/d"
assert normalize("/a//b////c/d//") == "/a/b/c/d"
assert normalize("/a/b/../../c/./d") == "/c/d"
assert normalize("/a/b/../../..") == "/"
assert normalize(".") ... | [
{
"docstring": "Normalize the given file path by removing redundant cwd (.) and parent (..) references and unnecessary slashes.",
"function_declaration": "def normalize(path):",
"function_name": "normalize",
"parameter_list": "(path)"
},
{
"docstring": "Check if the given path is an absolute... | [
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": "import os\n\ndef normalize(path):\n if not isinstance(path, str):\n raise ValueError(\"Invalid path\")\n normalized_path = os.path.normpath(path)\n ... | trial_gpt4o_3 | {
"original_instruction": "",
"prompt_id": "00071427",
"row_id": 71427,
"seed_ids": "[19348]"
} | 0.608972 | Taco_71427 | I | [
"normalize",
"is_absolute",
"join",
"basename"
] | 4 | [
[
"join",
"normalize"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 7a3c3d65364465dc8b8c79f60f34ef96f1620ae6 | 8477e33f59490e8d9711c2832e789a129b92d83c | |||
v1.0 | instruct | Taco | Taco_71450_I | A kingdom is divided into N cities connected by M bidirectional roads. Each road has a certain travel time associated with it. The ruler of the kingdom wants to ensure that it takes as little time as possible for a messenger to travel from the capital city to any other city.
You are given the number of cities N and th... | import heapq
def dijkstra(graph, N, src):
"""
Performs Dijkstra's algorithm to find the shortest path from the source node to all other nodes.
:param graph: The adjacency list of the graph.
:param N: The total number of nodes.
:param src: The source node.
:return: The shortest path distanc... | def test_messenger_travel_time():
assert messenger_travel_time(6, 7, [(1, 2, 4), (1, 3, 2), (2, 3, 1), (2, 4, 7), (3, 5, 3), (5, 4, 2), (4, 6, 1)]) == 8
assert messenger_travel_time(5, 4, [(1, 2, 2), (2, 3, 4), (3, 4, 1), (4, 5, 3)]) == 10
assert messenger_travel_time(2, 1, [(1, 2, 5)]) == 5
assert mess... | [
{
"docstring": "Performs Dijkstra's algorithm to find the shortest path from the source node to all other nodes.\n\n:param graph: The adjacency list of the graph.\n:param N: The total number of nodes.\n:param src: The source node.\n:return: The shortest path distances from the source node to all other nodes.",
... | [
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 dijkstra(graph, N, src):\n \"\"\"\n Performs Dijkstra's algorithm to find the shortest path from the source node to all other nodes.\n ... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00071450",
"row_id": 71450,
"seed_ids": "[20952]"
} | 0.792909 | Taco_71450 | I | [
"dijkstra",
"messenger_travel_time"
] | 2 | [
[
"messenger_travel_time",
"dijkstra"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | 996ec97e6caef0fcc8a500c35ece8f0a16792b93 | 33d28d146f3a33e2df64fdf8341f1668d65b92d9 | |||
v1.0 | instruct | Taco | Taco_71455_I | In a parallel world, there exists a unique numbering system for houses in a neighborhood. Each house number is a combination of a 3-letter string followed by a 4-digit number (e.g., ABC1234). The mayor of the neighborhood decided to introduce a new house numbering rule and wants to number only those houses where:
1. T... | def is_prime(num):
if num <= 1:
return False
for i in range(2, int(num**0.5) + 1):
if num % i == 0:
return False
return True
def is_valid_house_number(house_number):
letters = house_number[:3]
number = int(house_number[3:])
ascii_sum = sum(ord(char) for char in ... | def test_is_prime():
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(4) == False
assert is_prime(17) == True
assert is_prime(1000) == False
assert is_prime(9999) == False
def test_is_valid_house_number():
assert is_valid_house_number("ABC1237") == True
assert is_va... | [
{
"docstring": null,
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": null,
"function_declaration": "def is_valid_house_number(house_number):",
"function_name": "is_valid_house_number",
"parameter_list": "(hous... | [
0,
0,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(num):\n \"\"\"\n Helper function to check if a number is prime.\n \"\"\"\n if num <= 1:\n return False\n if num == 2:\n r... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00071455",
"row_id": 71455,
"seed_ids": "[952]"
} | 0.615591 | Taco_71455 | I | [
"is_prime",
"is_valid_house_number",
"check_house_numbers"
] | 3 | [
[
"check_house_numbers",
"is_valid_house_number"
],
[
"is_valid_house_number",
"is_prime"
]
] | 2 | [] | false | [] | false | pytest | false | [] | true | d6714545ec0b97528ad6a62709c818b9b6668276 | 254c72db723c1435333ac4abd1710297938b519a | |||
v1.0 | instruct | Taco | Taco_71610_I | You are given a grid of size `n x m` consisting of non-negative integers. Your task is to find the sum of integers in the sub-grid for multiple queries. Specifically, for each query, you will be given the top left and bottom right coordinates of a sub-grid, and you need to compute the sum of all integers within that su... | def compute_prefix_sum(matrix):
n = len(matrix)
m = len(matrix[0])
prefix_sum = [[0] * (m + 1) for _ in range(n + 1)]
for i in range(1, n + 1):
for j in range(1, m + 1):
prefix_sum[i][j] = matrix[i-1][j-1] + \
prefix_sum[i-1][j] + \
... | def test_process_queries():
n, m = 3, 3
grid = [
[1, 2, 3],
[4, 5, 6],
[7, 8, 9]
]
queries = [
(1, 1, 2, 2), # sub-grid: [[1, 2], [4, 5]] -> sum = 12
(2, 2, 3, 3) # sub-grid: [[5, 6], [8, 9]] -> sum = 28
]
expected = [12, 28]
assert process_queries(... | [
{
"docstring": null,
"function_declaration": "def compute_prefix_sum(matrix):",
"function_name": "compute_prefix_sum",
"parameter_list": "(matrix)"
},
{
"docstring": null,
"function_declaration": "def sum_subgrid(prefix_sum, x1, y1, x2, y2):",
"function_name": "sum_subgrid",
"par... | [
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 compute_subgrid_sums(n, m, grid, queries):\n \"\"\"\n Computes the sum of integers in the sub-grid for multiple queries.\n \n Parameters:\n n (i... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00071610",
"row_id": 71610,
"seed_ids": "[10998]"
} | 0.688544 | Taco_71610 | I | [
"compute_prefix_sum",
"sum_subgrid",
"process_queries"
] | 3 | [
[
"process_queries",
"compute_prefix_sum"
],
[
"process_queries",
"sum_subgrid"
]
] | 2 | [
"process_queries"
] | false | [] | false | pytest | false | [] | true | 9a72623157ec90cc903a803a2ce8470dca51dd35 | 41357b34d27a74eecceed4cd453d4f4ab26d52d0 | |||
v1.0 | instruct | Taco | Taco_71628_I | Given a list of strings, determine the length of the longest subsequence of characters that is common to all strings. A subsequence is defined as a sequence that can be derived from another sequence by deleting some or no elements without changing the order of the remaining elements.
Input:
- An integer N, the number ... | def longest_common_subsequence(strings):
def lcs(str1, str2):
len1 = len(str1)
len2 = len(str2)
dp = [[0] * (len2 + 1) for _ in range(len1 + 1)]
for i in range(1, len1 + 1):
for j in range(1, len2 + 1):
if str1[i - 1] == str2[j - 1]:
dp... | from solution import longest_common_subsequence
def test_longest_common_subsequence_example_1():
strings = ["abcdef", "acdf", "ade"]
assert longest_common_subsequence(strings) == 2
def test_longest_common_subsequence_all_same():
strings = ["abc", "abc", "abc"]
assert longest_common_subsequence(strings... | [
{
"docstring": null,
"function_declaration": "def longest_common_subsequence(strings):",
"function_name": "longest_common_subsequence",
"parameter_list": "(strings)"
},
{
"docstring": null,
"function_declaration": "def lcs_string(str1, str2, lcs_length):",
"function_name": "lcs_strin... | [
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 longest_common_subsequence_length(strings):\n \"\"\"\n Finds the length of the longest subsequence that is common to all given strings.\n \n :param... | trial_gpt4o_4 | {
"original_instruction": "",
"prompt_id": "00071628",
"row_id": 71628,
"seed_ids": "[9558]"
} | 0.725228 | Taco_71628 | I | [
"longest_common_subsequence",
"lcs_string"
] | 2 | [
[
"longest_common_subsequence",
"lcs_string"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 68b57a2194ef363ce7e2670123205e84fb4cbac9 | d3eadd841f080ae83d024679797a2e328d154622 | |||
v1.0 | instruct | Taco | Taco_71652_I | Given a string s consisting of lowercase alphabets, the task is to check if the string is a palindrome or can be made palindrome by removing at most one character. A string is considered a palindrome if it reads the same forward and backward.
Example:
Input: s = "abca"
Output: True
Explanation: By removing the characte... | def is_palindrome(s, left, right):
"""
Helper function to check if the substring s[left:right+1] is a palindrome.
"""
while left < right:
if s[left] != s[right]:
return False
left += 1
right -= 1
return True
def validPalindrome(s):
"""
Returns True if the... | from solution import validPalindrome
def test_palindrome():
# Perfect palindrome
assert validPalindrome("racecar") == True
def test_single_removal_make_palindrome():
# Single character removal to make palindrome
assert validPalindrome("abca") == True # Removing 'c' makes it "aba"
assert validPali... | [
{
"docstring": "Helper function to check if the substring s[left:right+1] is a palindrome.",
"function_declaration": "def is_palindrome(s, left, right):",
"function_name": "is_palindrome",
"parameter_list": "(s, left, right)"
},
{
"docstring": "Returns True if the string can be made a palind... | [
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 validPalindrome(s):\n \"\"\"\n Returns True if the string can be a palindrome after removing at most one character.\n \"\"\"\n def is_palindrome(su... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00071652",
"row_id": 71652,
"seed_ids": "[20926]"
} | 0.802345 | Taco_71652 | I | [
"is_palindrome",
"validPalindrome"
] | 2 | [
[
"validPalindrome",
"is_palindrome"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 139b6272cf2ee5e252f272bfb05a8fecdb0379a9 | 0a27f52a583bb7d2d2b94231b5e3b73e08512df3 | |||
v1.0 | instruct | Taco | Taco_71658_I | A young programmer enjoys creating mini-games. One day, he designed a simple game involving an array of integers and a special operation. The operation allows the player to choose any contiguous subarray and replace each element in that subarray with the sum of its digits. For example, given the array `[123, 405, 120]`... | def digit_sum(n):
"""
Returns the sum of digits of the given integer n.
"""
return sum(int(digit) for digit in str(n))
def min_operations_to_single_digit_array(arr):
"""
Returns the minimum number of operations required to turn all elements
in the array into single-digit numbers.
"""
... | from solution import digit_sum, min_operations_to_single_digit_array
def test_digit_sum():
assert digit_sum(123) == 6
assert digit_sum(405) == 9
assert digit_sum(120) == 3
assert digit_sum(99999) == 45
assert digit_sum(12345) == 15
assert digit_sum(1000000000) == 1
def test_min_operations_to_s... | [
{
"docstring": "Returns the sum of digits of the given integer n.",
"function_declaration": "def digit_sum(n):",
"function_name": "digit_sum",
"parameter_list": "(n)"
},
{
"docstring": "Returns the minimum number of operations required to turn all elements\nin the array into single-digit num... | [
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 sum_of_digits(num):\n \"\"\"\n Returns the sum of the digits of num.\n \"\"\"\n return sum(int(ch) for ch in str(num))\n\ndef minimum_operations_to... | trial_gpt4o_9 | {
"original_instruction": "",
"prompt_id": "00071658",
"row_id": 71658,
"seed_ids": "[13275]"
} | 0.693531 | Taco_71658 | I | [
"digit_sum",
"min_operations_to_single_digit_array"
] | 2 | [
[
"min_operations_to_single_digit_array",
"digit_sum"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | c782fec4794970a9d70453cd239f837a8f9ea60e | b3fc64acf53e04a4d058d00a55899d3efbb6b8e4 | |||
v1.0 | instruct | Taco | Taco_71686_I | You are given a sequence whose $n^{\text{th}}$ term is
$T_{n}=F_{m}$
where $F_{m}$ is the $m^{\text{th}}$ Fibonacci number.
You have to evaluate the series
$S_p=T_{1}+T_{2}+T_{3}+\cdots+T_{p}$
Find $S_p\:\text{mod}\:(10^9+7)$.
Input Format
The first line of input contains $\mathbf{T}$, the number of test cases. ... | def fibonacci_mod(n, mod=10**9 + 7):
if n == 0: return 0
if n == 1: return 1
a, b = 0, 1
for _ in range(2, n+1):
a, b = b, (a + b) % mod
return b
def sum_fibonacci_series(p, mod=10**9 + 7):
sum_fib = 0
for i in range(1, p + 1):
sum_fib = (sum_fib + fibonacci_mod(i, mod)) % m... | from solution import solve
def test_case_1():
test_input = [5]
expected_output = [12]
assert solve(test_input) == expected_output
def test_case_2():
test_input = [4]
expected_output = [7]
assert solve(test_input) == expected_output
def test_case_3():
test_input = [6]
expected_output =... | [
{
"docstring": null,
"function_declaration": "def fibonacci_mod(n, mod=10 ** 9 + 7):",
"function_name": "fibonacci_mod",
"parameter_list": "(n, mod=10 ** 9 + 7)"
},
{
"docstring": null,
"function_declaration": "def sum_fibonacci_series(p, mod=10 ** 9 + 7):",
"function_name": "sum_fib... | [
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 fibonacci_sum_modulo(p, mod=10**9 + 7):\n if p < 1:\n return 0\n\n if p == 1:\n return 1\n\n # Initialize the first two Fibonacci number... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00071686",
"row_id": 71686,
"seed_ids": "[18145]"
} | 0.720203 | Taco_71686 | I | [
"fibonacci_mod",
"sum_fibonacci_series",
"solve"
] | 3 | [
[
"solve",
"sum_fibonacci_series"
],
[
"sum_fibonacci_series",
"fibonacci_mod"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | c957ed2cef2383126be2c65fcfb056240faed7b4 | 6ada32337473506c74aaaf4bd57cb25193c03512 | |||
v1.0 | instruct | Taco | Taco_71741_I | In a mystical land, there lived a group of sorcerers who had the ability to create magical potions. To enhance the potency of their potions, they utilized a rare herb called "Mana Blossom". The potency of a potion is maximized by combining the right amounts of two different types of Mana Blossoms. Each type of Mana Blo... | def max_combined_potency(T, cases):
results = []
for i in range(T):
N = cases[i][0]
first_list = cases[i][1]
M = cases[i][2]
second_list = cases[i][3]
# Calculate the maximum possible potency
max_potency = max(first_list) + max(second_list)
result... | from solution import solve
def test_case_1():
T = 2
cases = [
(3, [4, 7, 2], 4, [5, 10, 6, 3]),
(2, [1, 9], 3, [8, 5, 9])
]
assert solve(T, cases) == [17, 18]
def test_case_2():
T = 1
cases = [
(5, [1, 2, 3, 4, 5], 5, [5, 4, 3, 2, 1])
]
assert solve(T, cases) ==... | [
{
"docstring": null,
"function_declaration": "def max_combined_potency(T, cases):",
"function_name": "max_combined_potency",
"parameter_list": "(T, cases)"
},
{
"docstring": null,
"function_declaration": "def solve(T, cases):",
"function_name": "solve",
"parameter_list": "(T, cas... | [
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 max_combined_potency(T, test_cases):\n results = []\n for i in range(T):\n N = test_cases[i]['N']\n A = test_cases[i]['A']\n M = tes... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00071741",
"row_id": 71741,
"seed_ids": "[21418]"
} | 0.655271 | Taco_71741 | I | [
"max_combined_potency",
"solve"
] | 2 | [
[
"solve",
"max_combined_potency"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | efa32d3ef1aa8119dc7e77301de050cef3bc6a1e | f4ddbc5ea6ea086fcdd10bf3830492cab4ad5b16 | |||
v1.0 | instruct | Taco | Taco_71758_I | Write a program that analyzes arithmetic expressions to determine if they are valid within the constraints of a specific calculator. This calculator supports only addition and multiplication of positive integers with specific limits on the number of operations performed.
The constraints for a valid expression on the c... | def is_valid_expression(expression):
"""
Checks if the arithmetic expression is valid based on specific constraints.
"""
if not expression or expression[0] in '+*' or expression[-1] in '+*':
return False
num_additions = 0
num_multiplications = 0
prev_char = None
for char in exp... | from solution import is_valid_expression, validate_expressions
def test_is_valid_expression():
assert is_valid_expression("12+7*3") == True
assert is_valid_expression("15+35+21") == True
assert is_valid_expression("3*5*7*") == False
assert is_valid_expression("123*456+789") == True
assert is_valid_... | [
{
"docstring": "Checks if the arithmetic expression is valid based on specific constraints.",
"function_declaration": "def is_valid_expression(expression):",
"function_name": "is_valid_expression",
"parameter_list": "(expression)"
},
{
"docstring": "Validates a list of arithmetic expressions... | [
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_expression(expression):\n if not expression or expression[0] in \"+*\" or expression[-1] in \"+*\":\n return \"Invalid\"\n \n add_coun... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00071758",
"row_id": 71758,
"seed_ids": "[11103]"
} | 0.601994 | Taco_71758 | I | [
"is_valid_expression",
"validate_expressions"
] | 2 | [
[
"validate_expressions",
"is_valid_expression"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 224d5216380208806ff8a8a315e7e28ee4d207e2 | 5fabf555fbba054e70a4b446f9c2f4d11183dfa2 | |||
v1.0 | instruct | Taco | Taco_71760_I | In the realm of competitive programming, prime numbers often play a significant role. Take this challenge for instance:
You are tasked with finding the smallest positive integer that is not only a prime number but also greater than or equal to a given number $X$. Your job is to write an efficient algorithm to identify... | def is_prime(n):
"""
Checks if a number n is prime.
"""
if n <= 1:
return False
if n <= 3:
return True
if n % 2 == 0 or n % 3 == 0:
return False
i = 5
while i * i <= n:
if n % i == 0 or n % (i + 2) == 0:
return False
i += 6
return T... | from solution import process_queries
def test_single_query_with_prime():
assert process_queries([5]) == [5]
def test_single_query_with_non_prime():
assert process_queries([10]) == [11]
def test_multiple_queries():
assert process_queries([5, 10]) == [5, 11]
def test_edge_case_one():
assert process_qu... | [
{
"docstring": "Checks if a number n is prime.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Finds the smallest prime number that is greater than or equal to x.",
"function_declaration": "def smallest_prime_ge(x):",
... | [
1,
0,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(n):\n \"\"\"\n Helper function to check if a number is prime.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00071760",
"row_id": 71760,
"seed_ids": "[14139]"
} | 0.569193 | Taco_71760 | I | [
"is_prime",
"smallest_prime_ge",
"process_queries"
] | 3 | [
[
"process_queries",
"smallest_prime_ge"
],
[
"smallest_prime_ge",
"is_prime"
]
] | 2 | [
"process_queries"
] | false | [] | false | pytest | true | [] | true | cee6c8572c4df98bcbb694ac85179abdd12a9ec0 | bdeb2096c412f1a3adf330c6ade3aa2315c9db9d | |||
v1.0 | instruct | Taco | Taco_71769_I | Given an array B[ ] of M integers, your task is to find the number of distinct prime factors of the product of all elements in the array.
Example 1:
Input:
M = 3
B = {2, 3, 5}
Output:
3
Explanation:
The product of the given array is 2 * 3 * 5 = 30.
The distinct prime factors are 2, 3, and 5, giving a count of 3.
Exam... | import math
def get_prime_factors(n):
prime_factors = set()
# Check if 2 is a prime factor
while n % 2 == 0:
prime_factors.add(2)
n //= 2
# Check for odd prime factors
for i in range(3, int(math.sqrt(n)) + 1, 2):
while n % i == 0:
prime_factors.add(i)
... | from solution import countPrimeFactors
def test_example_1():
assert countPrimeFactors(3, [2, 3, 5]) == 3
def test_example_2():
assert countPrimeFactors(5, [4, 9, 25, 16, 7]) == 4
def test_single_element():
assert countPrimeFactors(1, [10]) == 2
def test_multiple_same_elements():
assert countPrimeFac... | [
{
"docstring": null,
"function_declaration": "def get_prime_factors(n):",
"function_name": "get_prime_factors",
"parameter_list": "(n)"
},
{
"docstring": null,
"function_declaration": "def countPrimeFactors(M, B):",
"function_name": "countPrimeFactors",
"parameter_list": "(M, B)"... | [
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": "from math import isqrt\nfrom functools import reduce\nfrom typing import List\n\ndef countPrimeFactors(M: int, B: List[int]) -> int:\n def sieve(n):\n pr... | trial_gpt4o_4 | {
"original_instruction": "",
"prompt_id": "00071769",
"row_id": 71769,
"seed_ids": "[6524]"
} | 0.593338 | Taco_71769 | I | [
"get_prime_factors",
"countPrimeFactors"
] | 2 | [
[
"countPrimeFactors",
"get_prime_factors"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 832fbe373ab8f137015b5967f8864107e2afbf02 | c15dc9421220236cc6ee359a8db45ae5d3c5392e | |||
v1.0 | instruct | Taco | Taco_71778_I | You are given a matrix with n rows and m columns filled with integers. You can perform the following operation any number of times: select any row and add 1 to each element of that row or select any column and add 1 to each element of that column. Determine if it is possible to make all the elements of the matrix equal... | def can_make_elements_equal(matrix):
# Calculate the difference between first row and all other rows
row_diffs = []
reference_first_row = matrix[0]
for i in range(1, len(matrix)):
diff = [matrix[i][j] - reference_first_row[j] for j in range(len(matrix[0]))]
row_diffs.append(diff)
... | from solution import is_transformable
def test_sample_input_1():
n = 2
m = 2
matrix = [
[1, 2],
[3, 4]
]
assert is_transformable(n, m, matrix) == "YES"
def test_sample_input_2():
n = 2
m = 3
matrix = [
[1, 2, 3],
[4, 5, 6]
]
assert is_transformab... | [
{
"docstring": null,
"function_declaration": "def can_make_elements_equal(matrix):",
"function_name": "can_make_elements_equal",
"parameter_list": "(matrix)"
},
{
"docstring": null,
"function_declaration": "def is_transformable(n, m, matrix):",
"function_name": "is_transformable",
... | [
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 can_make_elements_equal(matrix, n, m):\n \"\"\"\n Determines if it is possible to make all elements of the matrix equal by \n ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00071778",
"row_id": 71778,
"seed_ids": "[20566]"
} | 0.677886 | Taco_71778 | I | [
"can_make_elements_equal",
"is_transformable"
] | 2 | [
[
"is_transformable",
"can_make_elements_equal"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | fa19bcc3b967b216ec57d5ac844552492667f066 | 703e7c8a359524a0335e5cb946106a087f90bec9 | |||
v1.0 | instruct | Taco | Taco_71812_I | In a development company, there is a system that tracks which developer reviews whose code. Each developer can have multiple reviewers, and a developer can review multiple developers' code. You need to determine if there is a path of code reviews from one developer to another.
You will be given the review relationship... | from collections import defaultdict, deque
def create_graph(edges):
graph = defaultdict(list)
for u, v in edges:
graph[u].append(v)
return graph
def bfs(graph, start, goal):
queue = deque([start])
visited = set()
while queue:
node = queue.popleft()
if node == goal:
... | from solution import code_review_paths
def test_single_path_exists():
n = 5
r = 4
edges = [(1, 2), (2, 3), (3, 4), (4, 5)]
q = 3
queries = [(1, 3), (1, 4), (2, 5)]
assert code_review_paths(n, r, edges, q, queries) == ['YES', 'YES', 'YES']
def test_no_path_exists():
n = 3
r = 2
edge... | [
{
"docstring": null,
"function_declaration": "def create_graph(edges):",
"function_name": "create_graph",
"parameter_list": "(edges)"
},
{
"docstring": null,
"function_declaration": "def bfs(graph, start, goal):",
"function_name": "bfs",
"parameter_list": "(graph, start, goal)"
... | [
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 defaultdict, deque\n\ndef create_graph(edges):\n graph = defaultdict(list)\n for u, v in edges:\n graph[u].append(v)\n retu... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00071812",
"row_id": 71812,
"seed_ids": "[1112]"
} | 0.627665 | Taco_71812 | I | [
"create_graph",
"bfs",
"code_review_paths"
] | 3 | [
[
"code_review_paths",
"bfs"
],
[
"code_review_paths",
"create_graph"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | d21428a9f725a15f4147dbc368268f3cef098f1c | 9c9e68f2d9fcd601cb0efc097ffaf2de9b60ef27 | |||
v1.0 | instruct | Taco | Taco_71831_I | Mia is learning about prime numbers and Fibonacci sequences in her mathematics class. Her teacher gave her an interesting problem to solve:
Given an integer $N$, Mia must find the $N$-th number in the sequence that consists only of prime numbers appearing in the Fibonacci sequence.
Help Mia by writing a function that... | def is_prime(num):
""" Returns True if num is a prime number, False otherwise. """
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 ... | import pytest
from solution import is_prime, nth_prime_fibonacci
def test_is_prime():
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(4) == False
assert is_prime(17) == True
assert is_prime(18) == False
def test_nth_prime_fibonacci():
assert nth_prime_fibonacci(1) == 2
... | [
{
"docstring": "Returns True if num is a prime number, False otherwise. ",
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": "Returns the n-th prime Fibonacci number. ",
"function_declaration": "def nth_prime_fibonacci(... | [
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 is_prime(num):\n \"\"\"\n Check if a number is prime.\n \"\"\"\n if num <= 1:\n return False\n if num == 2:\n return True\n if ... | trial_gpt4o_3 | {
"original_instruction": "",
"prompt_id": "00071831",
"row_id": 71831,
"seed_ids": "[21236]"
} | 0.764514 | Taco_71831 | I | [
"is_prime",
"nth_prime_fibonacci"
] | 2 | [
[
"nth_prime_fibonacci",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | ef1893026dafe6e758d30e0709ad88fe1fc90bd2 | 7c5cbb72bd89bfb218cdd4f57a7b0eabb292a37e | |||
v1.0 | instruct | Taco | Taco_71832_I | Two cities, Atlantis and Elantia, are connected by a series of straight roads. Each road either connects Atlantis to Elantia directly or passes through several smaller towns in between. Both cities are engaged in trading, and each road has a certain toll fee. Your task is to determine the minimum total toll fee require... | import heapq
def minimum_toll(N, M, roads):
graph = [[] for _ in range(N + 1)]
for u, v, w in roads:
graph[u].append((v, w))
graph[v].append((u, w))
return dijkstra(1, N, graph)
def dijkstra(start, end, graph):
min_heap = [(0, start)] # (toll cost, current node)
costs = [float('i... | from solution import minimum_toll
def test_minimum_toll_sample1():
N, M = 5, 6
roads = [
(1, 2, 2),
(1, 3, 4),
(2, 3, 1),
(2, 4, 7),
(3, 5, 3),
(4, 5, 1)
]
assert minimum_toll(N, M, roads) == 6
def test_minimum_toll_sample2():
N, M = 3, 2
roads =... | [
{
"docstring": null,
"function_declaration": "def minimum_toll(N, M, roads):",
"function_name": "minimum_toll",
"parameter_list": "(N, M, roads)"
},
{
"docstring": null,
"function_declaration": "def dijkstra(start, end, graph):",
"function_name": "dijkstra",
"parameter_list": "(s... | [
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 heapq\n\ndef minimum_toll_fee(n, m, roads):\n \"\"\"\n Finds the minimum toll fee from Atlantis (node 1) to Elantia (node n).\n \n Parameters:\n... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00071832",
"row_id": 71832,
"seed_ids": "[23476]"
} | 0.767894 | Taco_71832 | I | [
"minimum_toll",
"dijkstra"
] | 2 | [
[
"minimum_toll",
"dijkstra"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | f9870bfd2ec8ed0c44112dbe1b0aaea2ee45fc5e | 224ca0e6d8004d6f683bff61b7d88ada14323bbe | |||
v1.0 | instruct | Taco | Taco_71956_I | A company operates a network of machines connected by a series of cables. The network is represented as a graph with N nodes (machines) and M edges (cables). The machines have unique IDs ranging from 1 to N.
The company wants to determine the minimum cost to ensure that all machines are connected directly or indirectl... | 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
... | def test_minimum_activation_cost():
test_cases = [
(4, 5, [(1, 2, 3), (2, 3, 4), (3, 4, 5), (1, 4, 6), (2, 4, 7)]),
(3, 3, [(1, 2, 1), (2, 3, 2), (1, 3, 4)]),
(4, 3, [(1, 2, 1), (2, 3, 2), (3, 4, 3)]),
(4, 2, [(1, 2, 1), (2, 3, 2)])
]
expected_results = [12, 3, 6, -1]
ass... | [
{
"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 | hard | 0.25 | {
"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 return find(parent, parent[i])\n\ndef union(parent, rank, x, y):\n xroot = fi... | trial_gpt4o_4 | {
"original_instruction": "",
"prompt_id": "00071956",
"row_id": 71956,
"seed_ids": "[19222]"
} | 0.723894 | Taco_71956 | I | [
"find",
"union",
"kruskal_minimum_cost",
"minimum_activation_cost"
] | 4 | [
[
"kruskal_minimum_cost",
"find"
],
[
"kruskal_minimum_cost",
"union"
],
[
"minimum_activation_cost",
"kruskal_minimum_cost"
],
[
"union",
"find"
]
] | 4 | [] | false | [] | false | pytest | false | [] | true | a4b8937cbe7a86eb6eb3110cdf0483c46879a856 | 90b1fbc46dcc4a41181f88c12066d66dbb00da2f | |||
v1.0 | instruct | Taco | Taco_71972_I | You have a rectangular grid consisting of W columns and H rows. Each cell in the grid has either a 1 indicating it has a tree or a 0 indicating it is empty. You want to place exactly one house anywhere in the grid such that the sum of Manhattan distances from the house to all trees is minimized. The Manhattan distance ... | def min_manhattan_distance_sum(grid, W, H):
trees = [(i, j) for i in range(H) for j in range(W) if grid[i][j] == 1]
def manhattan_distance(x1, y1, x2, y2):
return abs(x1 - x2) + abs(y1 - y2)
min_distance_sum = float('inf')
for x in range(H):
for y in range(W):
... | from solution import minimal_tree_distance
def test_minimal_tree_distance_sample_input():
grid = [
[1, 0, 0],
[0, 1, 0],
[0, 0, 1]
]
assert minimal_tree_distance(3, 3, grid) == 4
def test_minimal_tree_distance_all_zeros():
grid = [
[0, 0, 0],
[0, 0, 0],
... | [
{
"docstring": null,
"function_declaration": "def min_manhattan_distance_sum(grid, W, H):",
"function_name": "min_manhattan_distance_sum",
"parameter_list": "(grid, W, H)"
},
{
"docstring": null,
"function_declaration": "def minimal_tree_distance(W, H, grid):",
"function_name": "mini... | [
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 get_minimum_distance(W, H, grid):\n trees = [(i, j) for i in range(H) for j in range(W) if grid[i][j] == 1]\n \n def manhattan_distance(x1, y1, x2, y2... | trial_gpt4o_4 | {
"original_instruction": "",
"prompt_id": "00071972",
"row_id": 71972,
"seed_ids": "[9306]"
} | 0.696826 | Taco_71972 | I | [
"min_manhattan_distance_sum",
"minimal_tree_distance"
] | 2 | [
[
"minimal_tree_distance",
"min_manhattan_distance_sum"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 2c8d1d13d770726ac9f31b26340373f102724074 | e338929ae99162e8fa7186cb8c4fbe1dce410ab6 | |||
v1.0 | instruct | Taco | Taco_71978_I | You have been given a list of rectangles, each defined by its vertices in a 2D plane with integer coordinates. Your task is to determine if they overlap at any point. If they do, output "Overlapping", otherwise output "Not Overlapping".
A rectangle is represented by its top-left and bottom-right corners. For example, ... | def is_overlapping(x1, y1, x2, y2, xx1, yy1, xx2, yy2):
"""
Check if two rectangles (x1, y1, x2, y2) and (xx1, yy1, xx2, yy2) overlap.
"""
return not (x2 < xx1 or xx2 < x1 or y2 > yy1 or yy2 > y1)
def check_overlap(n, rectangles):
"""
Check if any rectangles in the given list overlap.
"""
... | def test_is_overlapping():
assert not is_overlapping(1, 4, 3, 2, 6, 4, 8, 2)
assert is_overlapping(1, 4, 3, 2, 2, 3, 5, 1)
assert not is_overlapping(1, 4, 3, 2, 4, 5, 6, 3)
assert is_overlapping(1, 4, 4, 1, 2, 5, 6, 2)
def test_check_overlap():
assert check_overlap(3, [[1, 4, 3, 2], [2, 3, 5, 1], [... | [
{
"docstring": "Check if two rectangles (x1, y1, x2, y2) and (xx1, yy1, xx2, yy2) overlap.",
"function_declaration": "def is_overlapping(x1, y1, x2, y2, xx1, yy1, xx2, yy2):",
"function_name": "is_overlapping",
"parameter_list": "(x1, y1, x2, y2, xx1, yy1, xx2, yy2)"
},
{
"docstring": "Check... | [
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_overlapping(rect1, rect2):\n \"\"\"\n Checks if two rectangles overlap.\n Each rectangle is defined by two points (x1, y1) for top-left and (x2, y2... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00071978",
"row_id": 71978,
"seed_ids": "[2586]"
} | 0.669702 | Taco_71978 | I | [
"is_overlapping",
"check_overlap",
"main"
] | 3 | [
[
"check_overlap",
"is_overlapping"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | 14c794c297e4820d7bc04911ff7c140ca9b44c9a | 0b7d6ed0dd576501c18dfd82c2975366b763252b | |||
v1.0 | instruct | Taco | Taco_71992_I | Problem
You are given a grid consisting only of characters '0' and '1'. You need to find the largest rectangular sub-grid that contains only the character '1' and output its area.
Constraints
* 1 ≤ R, C ≤ 1000
Input
The input is given in the following format:
```
R C
grid_row_1
grid_row_2
...
grid_row_R
```
The ... | def maximalRectangle(grid):
"""
Given a grid of '0's and '1's, this function returns the area of the largest rectangle containing only '1's.
"""
if not grid:
return 0
max_area = 0
heights = [0] * len(grid[0])
for row in grid:
for i in range(len(row)):
# ... | from solution import maximalRectangle
def test_maximal_rectangle_example_1():
grid = [
"10100",
"10111",
"11111",
"10010",
]
assert maximalRectangle(grid) == 6
def test_maximal_rectangle_example_2():
grid = [
"00",
"00",
]
assert maximalRectangle... | [
{
"docstring": "Given a grid of '0's and '1's, this function returns the area of the largest rectangle containing only '1's.",
"function_declaration": "def maximalRectangle(grid):",
"function_name": "maximalRectangle",
"parameter_list": "(grid)"
},
{
"docstring": "Given an array of heights c... | [
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 \"\"\"\n Given a grid of '0's and '1's, this function returns the area of the largest rectangle containing only '1's.\n \"\"... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00071992",
"row_id": 71992,
"seed_ids": "[4354]"
} | 0.683688 | Taco_71992 | I | [
"maximalRectangle",
"largestRectangleArea"
] | 2 | [
[
"maximalRectangle",
"largestRectangleArea"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 97ea43396b77c4b9c1246fd4edcfce77eac777f8 | 969bd5a676702177529dd8b0e22369b6883480ab | |||
v1.0 | instruct | Taco | Taco_72008_I | You are given a network of cities represented as a weighted undirected graph. Each city is connected by roads, and each road has an associated distance. Your task is to determine if it is possible to travel between all pairs of cities considering the following potential disruptions:
1. Any one road can be blocked due ... | def find_union_parent(parent, i):
if parent[i] == i:
return i
else:
return find_union_parent(parent, parent[i])
def union(parent, rank, x, y):
xroot = find_union_parent(parent, x)
yroot = find_union_parent(parent, y)
if rank[xroot] < rank[yroot]:
parent[xroot] = yroot
... | def test_simple_case():
input_str = "4 5\n1 2 3\n1 3 4\n2 3 5\n2 4 6\n3 4 2\n0 0\n"
assert check_road_network(input_str) == ["Safe"]
def test_safe_case():
input_str = "5 5\n1 2 3\n2 3 4\n3 4 5\n4 5 6\n5 1 7\n0 0\n"
assert check_road_network(input_str) == ["Safe"]
def test_disconnected_case():
inpu... | [
{
"docstring": null,
"function_declaration": "def find_union_parent(parent, i):",
"function_name": "find_union_parent",
"parameter_list": "(parent, i)"
},
{
"docstring": null,
"function_declaration": "def union(parent, rank, x, y):",
"function_name": "union",
"parameter_list": "(... | [
1
] | 1 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def find_union_parent(parent, i):\n if parent[i] == i:\n return i\n else:\n return find_union_parent(parent, parent[i])\n\ndef union(parent, ra... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00072008",
"row_id": 72008,
"seed_ids": "[1843]"
} | 0.716943 | Taco_72008 | I | [
"find_union_parent",
"union",
"is_connected",
"check_road_network"
] | 4 | [
[
"check_road_network",
"is_connected"
],
[
"is_connected",
"find_union_parent"
],
[
"is_connected",
"union"
],
[
"union",
"find_union_parent"
]
] | 4 | [] | false | [] | false | pytest | false | [] | true | e1ac0e3c8cd7a5cb4052a6057c747cef2ba143db | 7f7b6081b1dae4367cb182165183c9b8cd69ec1f | |||
v1.0 | instruct | Taco | Taco_72026_I | A group of students decided to form a study group for their upcoming coding exam. They have a list of topics they need to cover, and they want to create a timetable to plan their studies. However, they don't want to study the same topic on consecutive days.
Each topic is represented by a different integer. They need y... | MOD = 10**9 + 7
def factorial(n):
"""
Calculate the factorial of n modulo MOD.
"""
result = 1
for i in range(1, n + 1):
result = (result * i) % MOD
return result
def valid_timtables_count(n):
"""
Return the number of valid timetables for n topics modulo MOD.
"""
return ... | from solution import solve
def test_single_case():
assert solve("1\n1") == "1"
assert solve("1\n2") == "2"
assert solve("1\n3") == "6"
def test_multiple_cases():
assert solve("3\n1\n2\n3") == "1\n2\n6"
def test_large_case():
assert solve("1\n10") == "3628800"
assert solve("1\n20") == "1463260... | [
{
"docstring": "Calculate the factorial of n modulo MOD.",
"function_declaration": "def factorial(n):",
"function_name": "factorial",
"parameter_list": "(n)"
},
{
"docstring": "Return the number of valid timetables for n topics modulo MOD.",
"function_declaration": "def valid_timtables_c... | [
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 factorial(n):\n if n == 0 or n == 1:\n return 1\n result = 1\n for i in range(2, n+1):\n result *= i\n return result\n\ndef count_val... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00072026",
"row_id": 72026,
"seed_ids": "[13946]"
} | 0.668446 | Taco_72026 | I | [
"factorial",
"valid_timtables_count",
"solve"
] | 3 | [
[
"solve",
"valid_timtables_count"
],
[
"valid_timtables_count",
"factorial"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 3f93325af41709d288d47ddab5307efeb5944d69 | 7378cfa3e727d1bed8b487505e156f8272ea21fe | |||
v1.0 | instruct | Taco | Taco_72059_I | Heidi has been tasked with securing a series of historic sites connected via ancient pathways. Each pathway has a certain width, and Heidi wants to ensure the pathways can support the traffic of tourists while keeping the scenic beauty intact. To decide which pathways to reinforce, Heidi must find the maximum width a p... | import heapq
def prim_mst(graph, n):
"""
Uses Prim's algorithm to find the MST of a graph.
Returns the total weight of the MST and the edges in the MST.
"""
# Min heap to select the edge with minimum weight in cut
min_heap = [(0, 1, -1)] # (weight, vertex, parent)
visited = [False] * (n + ... | from solution import compute_max_width
def test_example_case():
n = 4
m = 5
paths = [
(1, 2, 5),
(2, 3, 7),
(3, 4, 6),
(1, 3, 4),
(2, 4, 8),
]
assert compute_max_width(n, m, paths) == [7, 8]
def test_case_with_all_paths_mst():
n = 3
m = 2
paths =... | [
{
"docstring": "Uses Prim's algorithm to find the MST of a graph.\nReturns the total weight of the MST and the edges in the MST.",
"function_declaration": "def prim_mst(graph, n):",
"function_name": "prim_mst",
"parameter_list": "(graph, n)"
},
{
"docstring": "Given the number of sites n, nu... | [
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 find_W_max(n, m, edges):\n from heapq import heappop, heappush\n import sys\n\n def prim_mst():\n mst = []\n used = [False] * n\n ... | trial_gpt4o_5 | {
"original_instruction": "",
"prompt_id": "00072059",
"row_id": 72059,
"seed_ids": "[7204]"
} | 0.668905 | Taco_72059 | I | [
"prim_mst",
"compute_max_width"
] | 2 | [
[
"compute_max_width",
"prim_mst"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 7e4df4b3892121542d16b908447ceb51b74f4528 | db017ed2243a9ffd39dde6dfc5ed990c7d1aa1a7 | |||
v1.0 | instruct | Taco | Taco_72100_I | You are given an array of integers `arr` with a length of `|arr| = n (1 ≤ n ≤ 500)`. You need to make a series of operations on the array such that after each operation, each element in the array is incremented by a value divisible by the difference between its index and a given integer `k (0 ≤ k ≤ n - 1)`.
You need t... | import math
from functools import reduce
from math import gcd
def gcd_array(arr):
return reduce(gcd, arr)
def number_of_ways(n, arr, k):
if n == 1:
return -1 # Problem specification does not allow n=1 to have significant variety.
differences = []
for i in range(n):
differences.ap... | from solution import number_of_ways
def test_case_1():
assert number_of_ways(3, [1, 5, 3], 1) == 2
def test_case_2():
assert number_of_ways(4, [7, 9, 12, 18], 2) == 1
def test_case_3():
assert number_of_ways(2, [10, 20], 0) == 10
def test_case_4():
assert number_of_ways(5, [1, 5, 5, 5, 5], 0) == 4
... | [
{
"docstring": null,
"function_declaration": "def gcd_array(arr):",
"function_name": "gcd_array",
"parameter_list": "(arr)"
},
{
"docstring": null,
"function_declaration": "def number_of_ways(n, arr, k):",
"function_name": "number_of_ways",
"parameter_list": "(n, arr, k)"
}
] | [
0,
0,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import math\n\ndef count_ways_to_equal_array_elements(n, arr, k):\n \"\"\"\n Calculate the number of different ways to make all elements of the array equal\n... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00072100",
"row_id": 72100,
"seed_ids": "[5228]"
} | 0.701544 | Taco_72100 | I | [
"gcd_array",
"number_of_ways"
] | 2 | [
[
"number_of_ways",
"gcd_array"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 46cb29aa255f2ecac3e74751cd444b826e4f5ee4 | ed5dd295d0fdda8d37945b4885220ea99bcd4788 | |||
v1.0 | instruct | Taco | Taco_72114_I | Given a string S and an array of words W, determine the count of words from the array that can be formed using the letters of the string S without reusing any letters. Each letter in the string S can be used only once per word.
Input:
The first line contains the integer T, the number of test cases. Each test case sta... | def can_form_word(s, word):
"""
Helper function to check if a word can be formed from the letters of string s without reusing any letters.
"""
from collections import Counter
s_counter = Counter(s)
word_counter = Counter(word)
for char, count in word_counter.items():
if s_counte... | import pytest
from solution import can_form_word, count_formable_words, process_test_cases
def test_can_form_word():
assert can_form_word("aabbcc", "abc") == True
assert can_form_word("aabbcc", "aaa") == False
assert can_form_word("aabbcc", "bbb") == False
assert can_form_word("aabbcc", "cca") == True
... | [
{
"docstring": "Helper function to check if a word can be formed from the letters of string s without reusing any letters.",
"function_declaration": "def can_form_word(s, word):",
"function_name": "can_form_word",
"parameter_list": "(s, word)"
},
{
"docstring": "Returns the count of words th... | [
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_formable_words(S, words):\n \"\"\"\n Returns the count of words from the list that can be formed using the letters of the string S \n without re... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00072114",
"row_id": 72114,
"seed_ids": "[11885]"
} | 0.723645 | Taco_72114 | I | [
"can_form_word",
"count_formable_words",
"process_test_cases"
] | 3 | [
[
"count_formable_words",
"can_form_word"
],
[
"process_test_cases",
"count_formable_words"
]
] | 2 | [
"process_test_cases"
] | false | [] | false | pytest | true | [] | true | 2c7f7f08d18907a1ca62f75f0f2971ab56e7f839 | d7d35370bb5ade16cd195d9738b312e8f559ca4b | |||
v1.0 | instruct | Taco | Taco_72130_I | You are given an undirected graph with $n$ vertices and $m$ edges. Each edge has a weight associated with it. Your task is to find the minimum cost to connect all the vertices (i.e., the cost of a Minimum Spanning Tree).
If the graph is disconnected, output -1, indicating that not all vertices can be connected.
-----... | def find(parent, u):
if parent[u] != u:
parent[u] = find(parent, parent[u])
return parent[u]
def union(parent, rank, u, v):
root_u = find(parent, u)
root_v = find(parent, v)
if root_u != root_v:
if rank[root_u] > rank[root_v]:
parent[root_v] = root_u
elif rank[ro... | from solution import minimum_spanning_tree
def test_mst_example1():
assert minimum_spanning_tree(4, [(1, 2, 2), (1, 3, 3), (2, 3, 4), (3, 4, 1), (4, 2, 5)]) == 6
def test_mst_example2():
assert minimum_spanning_tree(3, [(1, 2, 4)]) == -1
def test_mst_single_node():
assert minimum_spanning_tree(1, []) == ... | [
{
"docstring": null,
"function_declaration": "def find(parent, u):",
"function_name": "find",
"parameter_list": "(parent, u)"
},
{
"docstring": null,
"function_declaration": "def union(parent, rank, u, v):",
"function_name": "union",
"parameter_list": "(parent, rank, u, v)"
},
... | [
0,
1,
0
] | 1 | medium | 0.333 | {
"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 = [0] * n\n \n def find(self, u):\n if self.pare... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00072130",
"row_id": 72130,
"seed_ids": "[181]"
} | 0.853832 | Taco_72130 | I | [
"find",
"union",
"minimum_spanning_tree"
] | 3 | [
[
"minimum_spanning_tree",
"find"
],
[
"minimum_spanning_tree",
"union"
],
[
"union",
"find"
]
] | 3 | [] | false | [] | false | pytest | true | [] | true | a57a991a057f0da210e813221b0b6e567c3c780a | 95f31d78fb70b3ce28feab773ec732c51ed58a50 | |||
v1.0 | instruct | Taco | Taco_72131_I | Alex loves solving problems involving binary trees. One day, he came across an interesting problem and needs your help to solve it. Given a binary tree, find the length of the longest path which contains the same value.
A path in a binary tree is a sequence of nodes where each pair of adjacent nodes in the sequence ha... | from collections import defaultdict
def longest_same_value_path(n, edges, values):
tree = defaultdict(list)
for u, v in edges:
tree[u].append(v)
tree[v].append(u)
max_path = [0]
def dfs(node, parent):
current_val = values[node - 1]
max_length = 0
f... | from solution import longest_same_value_path
def test_example_1():
assert longest_same_value_path(5, [(1, 2), (1, 3), (3, 4), (3, 5)], [1, 1, 2, 2, 2]) == 2
def test_example_2():
assert longest_same_value_path(3, [(1, 2), (1, 3)], [1, 1, 1]) == 2
def test_example_3():
assert longest_same_value_pa... | [
{
"docstring": null,
"function_declaration": "def longest_same_value_path(n, edges, values):",
"function_name": "longest_same_value_path",
"parameter_list": "(n, edges, values)"
},
{
"docstring": null,
"function_declaration": "def example_implementation():",
"function_name": "example... | [
0,
1,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from collections import defaultdict, deque\n\ndef longest_path_with_same_value(n, edges, values):\n # Construct the adjacency list\n tree = defaultdict(list)... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00072131",
"row_id": 72131,
"seed_ids": "[17786]"
} | 0.634665 | Taco_72131 | I | [
"longest_same_value_path",
"example_implementation"
] | 2 | [
[
"example_implementation",
"longest_same_value_path"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 7701a251a92e3e5254f569f7a7d93d7caf3ca29c | ad383d34108fa566abc42286ac4f7dcdc1e29334 | |||
v1.0 | instruct | Taco | Taco_72143_I | The Social Media Analytics Corp. (SMACorp) operates a robust system to analyze user engagement across various platforms. To ensure fast and efficient analysis, SMACorp divides the user's activity log into segments. Each segment contains the activity data for a certain duration (e.g., one hour). SMACorp needs to aggrega... | def preprocess_prefix_sum(impacts):
"""
Precompute the prefix sums for the given impact values.
Params:
impacts: List of integers representing the impact values of segments.
Returns:
A list of prefix sums.
"""
n = len(impacts)
prefix_sum = [0] * (n + 1)
for i in range(1... | def test_example_1():
n = 5
queries = [(1, 3), (2, 5), (1, 5)]
impacts = [1, -2, 3, 10, -5]
expected_output = [2, 6, 7]
assert process_queries(n, queries, impacts) == expected_output
def test_example_2():
n = 6
queries = [(3, 4), (1, 6)]
impacts = [-1, 3, 4, 0, -3, 2]
expected_outpu... | [
{
"docstring": "Precompute the prefix sums for the given impact values.\n\nParams:\nimpacts: List of integers representing the impact values of segments.\n\nReturns:\nA list of prefix sums.",
"function_declaration": "def preprocess_prefix_sum(impacts):",
"function_name": "preprocess_prefix_sum",
"pa... | [
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 preprocess_prefix_sum(impacts):\n \"\"\"\n Precompute the prefix sums for the given impact values.\n \n Params:\n impacts: List of integers repr... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00072143",
"row_id": 72143,
"seed_ids": "[12587]"
} | 0.525636 | Taco_72143 | I | [
"preprocess_prefix_sum",
"query_sum",
"process_queries"
] | 3 | [
[
"process_queries",
"preprocess_prefix_sum"
],
[
"process_queries",
"query_sum"
]
] | 2 | [
"process_queries"
] | false | [] | false | pytest | false | [] | true | 347e4aaf5077a47f927e4fd1f6556035a704f30a | 88377de9ffcef6c4f33cdba02fa0e8c1e980d064 | |||
v1.0 | instruct | Taco | Taco_72182_I | You are given an array of integers $A$ of length $n$ and a sequence of $q$ queries. For each query, you are given two integers $l$ and $r$ (1-based index), and you need to find the sum of the elements in the subarray $A[l-1, r-1]$.
Constraints
* $1 \leq n \leq 100,000$
* $1 \leq q \leq 100,000$
* $1 \leq A[i] \leq 1,... | def preprocess(arr):
"""
Preprocess the array to create prefix sums which will help in answering range sum queries efficiently.
"""
prefix_sums = [0] * (len(arr) + 1)
for i in range(len(arr)):
prefix_sums[i + 1] = prefix_sums[i] + arr[i]
return prefix_sums
def range_sum(l, r, prefix_sum... | from solution import preprocess, range_sum, process_queries
def test_preprocess():
assert preprocess([1, 2, 3, 4, 5]) == [0, 1, 3, 6, 10, 15]
assert preprocess([5, 1, 2, 3, 4]) == [0, 5, 6, 8, 11, 15]
def test_range_sum():
prefix_sums = preprocess([1, 2, 3, 4, 5])
assert range_sum(1, 3, prefix_sums) =... | [
{
"docstring": "Preprocess the array to create prefix sums which will help in answering range sum queries efficiently.",
"function_declaration": "def preprocess(arr):",
"function_name": "preprocess",
"parameter_list": "(arr)"
},
{
"docstring": "Returns the sum of array elements from index l ... | [
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 range_sum_queries(n, A, queries):\n \"\"\"\n Calculates the sum of the elements in the subarray A[l-1:r-1] for each query.\n \n Parameters:\n n ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00072182",
"row_id": 72182,
"seed_ids": "[16000]"
} | 0.670674 | Taco_72182 | I | [
"preprocess",
"range_sum",
"process_queries"
] | 3 | [
[
"process_queries",
"preprocess"
],
[
"process_queries",
"range_sum"
]
] | 2 | [
"process_queries"
] | false | [] | false | pytest | true | [] | true | 954f44d91cc5cfe99009964b2ad1fbfda3cae296 | 8da2d0e73ab572f98c74d9410661659514549bbb | |||
v1.0 | instruct | Taco | Taco_72288_I | Given a string composed of parenthesis '(', ')', square brackets '[', ']', and curly braces '{', '}', determine if the input string is valid. An input string is valid if:
1. Open brackets are closed by the same type of brackets.
2. Open brackets are closed in the correct order.
Return "YES" if the input string is val... | def is_valid_parentheses(s):
"""
Determines if the input string with parentheses, square brackets, and curly braces is valid.
Parameters:
s (str): The input string to be validated.
Returns:
str: "YES" if the input string is valid, otherwise "NO".
"""
stack = []
mapping = {'... | from solution import validate_multiple_cases, is_valid_parentheses
def test_is_valid_parentheses():
assert is_valid_parentheses("()[]{}") == "YES"
assert is_valid_parentheses("([{}])") == "YES"
assert is_valid_parentheses("[[") == "NO"
assert is_valid_parentheses("{[()]}") == "YES"
assert is_valid_... | [
{
"docstring": "Determines if the input string with parentheses, square brackets, and curly braces is valid.\n\nParameters:\ns (str): The input string to be validated.\n\nReturns:\nstr: \"YES\" if the input string is valid, otherwise \"NO\".",
"function_declaration": "def is_valid_parentheses(s):",
"fun... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_valid_bracket_sequence(s):\n stack = []\n bracket_map = {')': '(', ']': '[', '}': '{'}\n \n for char in s:\n if char in bracket_map.value... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00072288",
"row_id": 72288,
"seed_ids": "[8664]"
} | 0.787762 | Taco_72288 | I | [
"is_valid_parentheses",
"validate_multiple_cases"
] | 2 | [
[
"validate_multiple_cases",
"is_valid_parentheses"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | ffb5fc663d8b0fd77166b921228c8b6e3627875e | 2bf75bc50e5b15263b182b470fd335ef29601dc5 | |||
v1.0 | instruct | Taco | Taco_72302_I | In a city, there are N intersections connected by M roads. Each road has a certain length. A delivery truck starts from a particular intersection and wants to return to the starting point after delivering all packages. However, the truck must not take the same road twice along its route. Additionally, the truck prefers... | import itertools
def tsp(graph, start):
"""
Solves the Traveling Salesman Problem using brute force.
"""
n = len(graph)
vertices = list(range(n))
vertices.remove(start)
min_path = float('inf')
for permutation in itertools.permutations(vertices):
current_pathweight = 0
... | import pytest
from solution import min_route_length
def test_min_route_length_simple():
assert min_route_length(4, 6, [
(1, 2, 10),
(1, 3, 15),
(1, 4, 20),
(2, 3, 35),
(2, 4, 25),
(3, 4, 30)
]) == 80
def test_min_route_length_no_path():
assert min_route_leng... | [
{
"docstring": "Solves the Traveling Salesman Problem using brute force.",
"function_declaration": "def tsp(graph, start):",
"function_name": "tsp",
"parameter_list": "(graph, start)"
},
{
"docstring": null,
"function_declaration": "def min_route_length(N, M, roads):",
"function_name... | [
0,
0,
0,
0,
1,
0,
1,
0
] | 2 | hard | 0.25 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def min_route_length(N, M, roads):\n from itertools import combinations, product\n import sys\n \n # Create adjacency matrix\n inf = sys.maxsize\n ... | trial_gpt4o_7 | {
"original_instruction": "",
"prompt_id": "00072302",
"row_id": 72302,
"seed_ids": "[730]"
} | 0.731597 | Taco_72302 | I | [
"tsp",
"min_route_length"
] | 2 | [
[
"min_route_length",
"tsp"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 8b9fac5f8c528d1201810aba66634242ee6cd8aa | 5fee020fbe8d74a9e0606f4d718ff719b11cb13d | |||
v1.0 | instruct | Taco | Taco_72320_I | For a series of expressions containing parentheses, check if each expression is balanced. A balanced expression has every opening parenthesis matched with a proper closing parenthesis.
Constraints
* 1 ≤ n ≤ 10000
* Length of each expression ≤ 10000
Input
n
expression1
expression2
:
expressionn
The first line of th... | def is_balanced(expression):
"""
Returns "YES" if the expression is balanced, otherwise "NO".
"""
stack = []
for char in expression:
if char == '(':
stack.append(char)
elif char == ')':
if not stack:
return "NO"
stack.pop()
... | def test_is_balanced():
assert is_balanced('()') == 'YES'
assert is_balanced('((()))') == 'YES'
assert is_balanced('(()))') == 'NO'
assert is_balanced('((()()') == 'NO'
assert is_balanced('') == 'YES'
assert is_balanced(')(') == 'NO'
def test_check_expressions():
expressions = ['()', '((())... | [
{
"docstring": "Returns \"YES\" if the expression is balanced, otherwise \"NO\".",
"function_declaration": "def is_balanced(expression):",
"function_name": "is_balanced",
"parameter_list": "(expression)"
},
{
"docstring": "Check a list of expressions for balanced parentheses.\n\nParameters:\... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_balanced(expression):\n \"\"\"\n Checks if the given expression containing only parentheses is balanced.\n \"\"\"\n stack = []\n for char in ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00072320",
"row_id": 72320,
"seed_ids": "[9319]"
} | 0.709777 | Taco_72320 | I | [
"is_balanced",
"check_expressions"
] | 2 | [
[
"check_expressions",
"is_balanced"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | c0352b8ae3dcda5d190082c3d842a46cca2602a4 | cd9f7e586b97e59fcff2526e4370b5b1ba1831e9 | |||
v1.0 | instruct | Taco | Taco_72326_I | Given a 2D grid of integers, you are tasked with finding the largest rectangular submatrix that only contains the number `1`. You should return the area of this largest rectangular submatrix.
For example, consider the 2D grid [[1, 0, 1, 0, 0], [1, 0, 1, 1, 1], [1, 1, 1, 1, 1], [1, 0, 0, 1, 0]]. The largest rectangular... | def maximalRectangle(matrix):
if not matrix or not matrix[0]:
return 0
max_area = 0
n, m = len(matrix), len(matrix[0])
heights = [0] * m
for row in range(n):
for col in range(m):
if matrix[row][col] == 1:
heights[col] += 1
else:
... | def test_maximalRectangle():
grid1 = [
[1, 0, 1, 0, 0],
[1, 0, 1, 1, 1],
[1, 1, 1, 1, 1],
[1, 0, 0, 1, 0]
]
assert maximalRectangle(grid1) == 6
grid2 = [
[0, 1],
[1, 0]
]
assert maximalRectangle(grid2) == 1
grid3 = [
[1, 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(matrix):\n if not matrix or not matrix[0]:\n return 0\n\n max_area = 0\n n, m = len(matrix), len(matrix[0])\n \n heights... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00072326",
"row_id": 72326,
"seed_ids": "[3461]"
} | 0.713952 | Taco_72326 | I | [
"maximalRectangle",
"largestRectangleArea"
] | 2 | [
[
"maximalRectangle",
"largestRectangleArea"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | b9d7ff7ae621883ba8e6774d18a350a07c3a5d82 | 19f5dd89fa264a6369895f4cad83a33d070c1755 | |||
v1.0 | instruct | Taco | Taco_72386_I | You are given a matrix `grid` consisting of `m` rows and `n` columns filled with integers. A cell at (i, j) in `grid` represents the height of the particular cell. You can only move up, down, left, or right if and only if the new cell's value is less than or equal to the current cell's value plus a given maximum effort... | import heapq
def minimum_effort_path(grid):
m, n = len(grid), len(grid[0])
heap = [(0, 0, 0)] # (effort, row, col)
efforts = [[float('inf')] * n for _ in range(m)]
efforts[0][0] = 0
directions = [(0, 1), (1, 0), (0, -1), (-1, 0)]
while heap:
effort, x, y = heapq.heappop(heap)
... | from solution import read_input_and_solve
def test_minimum_effort_path_case_1():
input_str = "3 3\n1 2 2\n3 8 2\n5 3 5"
assert read_input_and_solve(input_str) == 2
def test_minimum_effort_path_case_2():
input_str = "2 2\n1 2\n2 3"
assert read_input_and_solve(input_str) == 1
def test_minimum_effort_pa... | [
{
"docstring": null,
"function_declaration": "def minimum_effort_path(grid):",
"function_name": "minimum_effort_path",
"parameter_list": "(grid)"
},
{
"docstring": null,
"function_declaration": "def read_input_and_solve(input_str):",
"function_name": "read_input_and_solve",
"para... | [
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 heapq\n\ndef minimum_effort_path(grid):\n m, n = len(grid), len(grid[0])\n heap = [(0, 0, 0)] # (effort, row, col)\n efforts = [[float('inf')] * n... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00072386",
"row_id": 72386,
"seed_ids": "[7501]"
} | 0.723237 | Taco_72386 | I | [
"minimum_effort_path",
"read_input_and_solve"
] | 2 | [
[
"read_input_and_solve",
"minimum_effort_path"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 46d96b29d3ec7f3a5b1d82e2801e13464efba276 | df151e08d9b5f02f85973308b9045a35e3e158c5 | |||
v1.0 | instruct | Taco | Taco_72426_I | Bob is a digital sentient AI who recently obtained access to universally stored data of countless human societies. He is intrigued by a specific problem in graph theory and asks for your help to solve it.
Bob is interested in finding out if it's possible to design an algorithm that can detect the shortest path in a we... | import heapq
def dijkstra(n, edges, start, end):
graph = {i: [] for i in range(1, n + 1)}
for u, v, w in edges:
graph[u].append((w, v))
graph[v].append((w, u))
heap = [(0, start)]
distances = {i: float('inf') for i in range(1, n + 1)}
distances[start] = 0
while heap:
... | from solution import solve
def test_case_1():
input_data = "2\n4 4\n1 2 4\n1 3 2\n2 3 5\n3 4 1\n1 4\n3 2\n1 2 5\n2 3 7\n1 3"
expected_output = "3\n12"
assert solve(input_data) == expected_output
def test_case_2():
input_data = "1\n2 1\n1 2 1\n1 2"
expected_output = "1"
assert solve(input_data)... | [
{
"docstring": null,
"function_declaration": "def dijkstra(n, edges, start, end):",
"function_name": "dijkstra",
"parameter_list": "(n, edges, start, end)"
},
{
"docstring": null,
"function_declaration": "def find_shortest_paths(test_cases):",
"function_name": "find_shortest_paths",
... | [
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": "import heapq\n\ndef dijkstra_shortest_path(n, edges, start, target):\n graph = [[] for _ in range(n + 1)]\n \n for u, v, w in edges:\n graph[u].app... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00072426",
"row_id": 72426,
"seed_ids": "[8738]"
} | 0.779383 | Taco_72426 | I | [
"dijkstra",
"find_shortest_paths",
"parse_input",
"solve"
] | 4 | [
[
"find_shortest_paths",
"dijkstra"
],
[
"solve",
"find_shortest_paths"
],
[
"solve",
"parse_input"
]
] | 3 | [
"parse_input"
] | false | [] | false | pytest | true | [] | true | 76991d3030a304f08dad1b7dd191b0107ea9eeb0 | 326140b908ba4985b5c0579f8706ff1ce7c02b38 | |||
v1.0 | instruct | Taco | Taco_72484_I | A kingdom has n villages connected by m bidirectional roads. The roads vary in length, and the king wants to strengthen the roads in such a way that the maximum length of the shortest path between any two villages is minimized. In other words, the king wants to ensure that the farthest shortest path between any two vil... | import heapq
def dijkstra(graph, start, n):
distances = [float('inf')] * (n + 1)
distances[start] = 0
pq = [(0, start)]
while pq:
current_distance, current_node = heapq.heappop(pq)
if current_distance > distances[current_node]:
continue
for neighbor, weight in gra... | def test_kingdom_problems_case_1():
input_data = [
(4, 5, [(1, 2, 3), (1, 3, 1), (2, 3, 1), (2, 4, 5), (3, 4, 2)])
]
expected_output = [2]
assert solve_kingdom_problems(input_data) == expected_output
def test_kingdom_problems_case_2():
input_data = [
(3, 3, [(1, 2, 4), (2, 3, 2), (1... | [
{
"docstring": null,
"function_declaration": "def dijkstra(graph, start, n):",
"function_name": "dijkstra",
"parameter_list": "(graph, start, n)"
},
{
"docstring": null,
"function_declaration": "def solve_kingdom_problems(test_cases):",
"function_name": "solve_kingdom_problems",
... | [
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 min_max_shortest_path(T, test_cases):\n from heapq import heappop, heappush\n import math\n \n def dijkstra(graph, start):\n distances = {no... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00072484",
"row_id": 72484,
"seed_ids": "[22068]"
} | 0.719239 | Taco_72484 | I | [
"dijkstra",
"solve_kingdom_problems"
] | 2 | [
[
"solve_kingdom_problems",
"dijkstra"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | e09ad0581bd20c34d0e54edb156a3209d9b7d64e | e56c0dfac340dc580cbe536f6fcc5d843e973a3e | |||
v1.0 | instruct | Taco | Taco_72520_I | In a bustling city, the taxi companies maintain records of their taxi fares for different rides. Each taxi company has a unique company ID and records the distance of the ride along with the fare charged for that distance. The city council wants to analyze this data to identify pricing patterns amongst different compan... | def analyze_taxi_data(M, rides):
from collections import defaultdict
# Dictionary to hold the rides grouped by company_id
company_data = defaultdict(list)
# Parsing the input rides
for ride in rides:
company_id, distance, fare = ride
company_data[company_id].append((distanc... | from solution import analyze_taxi_data, taxi_fare_analysis
def test_analyze_taxi_data():
input_data = [
(1, 10, 15.75),
(2, 15, 19.50),
(1, 5, 12.00),
(2, 15, 20.00),
(1, 5, 15.00),
(2, 20, 25.00),
]
expected_output = [
(1, 5, 15.00),
(1,... | [
{
"docstring": null,
"function_declaration": "def analyze_taxi_data(M, rides):",
"function_name": "analyze_taxi_data",
"parameter_list": "(M, rides)"
},
{
"docstring": null,
"function_declaration": "def taxi_fare_analysis(input_str):",
"function_name": "taxi_fare_analysis",
"para... | [
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 sort_taxi_rides(records):\n from collections import defaultdict\n \n rides = defaultdict(list)\n \n for record in records:\n company_id, ... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00072520",
"row_id": 72520,
"seed_ids": "[15670]"
} | 0.558793 | Taco_72520 | I | [
"analyze_taxi_data",
"taxi_fare_analysis"
] | 2 | [
[
"taxi_fare_analysis",
"analyze_taxi_data"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 5cf046f78f7c2b4dcdeda36cf6aedafc29bb1ded | 7afa5019d8a341e2f82d69ab577d100e12bc1ef5 | |||
v1.0 | instruct | Taco | Taco_72542_I | ## Task
You are given a vending machine that only accepts coins of certain denominations.
Denominations are represented using binary representation:
```
0001 - penny (1 cent)
0010 - nickel (5 cents)
0100 - dime (10 cents)
1000 - quarter (25 cents)
```
For example, if the vending machine accepts pennies, nickels, and d... | def get_denominations(denominations):
"""
Convert the binary representation of denominations into a list of coin values.
"""
coin_values = [1, 5, 10, 25]
available_coins = []
for i in range(4):
if (denominations >> i) & 1:
available_coins.append(coin_values[i])
... | from solution import min_coins
def test_min_coins_example():
assert min_coins(12, 0b0111) == 3 # 1 dime + 2 pennies
def test_min_coins_no_pennies():
assert min_coins(3, 0b0110) == -1 # 3 cannot be made with nickels and dimes
def test_min_coins_only_pennies():
assert min_coins(4, 0b0001) == 4 # 4 p... | [
{
"docstring": "Convert the binary representation of denominations into a list of coin values.",
"function_declaration": "def get_denominations(denominations):",
"function_name": "get_denominations",
"parameter_list": "(denominations)"
},
{
"docstring": "Calculate the minimum number of coins... | [
0,
0,
0,
0,
0,
1,
0,
0,
1,
1
] | 3 | hard | 0.3 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def min_coins_needed(amount, denominations):\n \"\"\"\n Returns the minimum number of coins needed to make the payment or -1 if it's not possible.\n \n ... | trial_gpt4o_8 | {
"original_instruction": "",
"prompt_id": "00072542",
"row_id": 72542,
"seed_ids": "[16669]"
} | 0.668795 | Taco_72542 | I | [
"get_denominations",
"min_coins"
] | 2 | [
[
"min_coins",
"get_denominations"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 26b125fda0dd2b164a57044e68635fb44be21e77 | 693526df5cd8024ac9d961bdcc65521444cde575 | |||
v1.0 | instruct | Taco | Taco_72566_I | You are participating in a treasure hunt game where you need to find the shortest path through a grid filled with obstacles and treasures. The grid is represented as an `n x m` matrix, where each cell can contain:
- '0' (empty cell): You can walk through it.
- '1' (obstacle): You cannot walk through it.
- 'T' (treasur... | from itertools import permutations
from collections import deque
def bfs(grid, start, goals):
n, m = len(grid), len(grid[0])
q = deque([(start, 0)])
visited = set([start])
distances = {}
while q:
(x, y), dist = q.popleft()
if (x, y) in goals:
distances[(x, y)] = dist
... | from solution import treasure_hunt
def test_example_1():
t = 2
cases = [
((5, 5), [
'S0000',
'010T0',
'01000',
'T0000',
'0000E'
]),
((3, 3), [
'S1T',
'111',
'TE0'
])
]
assert ... | [
{
"docstring": null,
"function_declaration": "def bfs(grid, start, goals):",
"function_name": "bfs",
"parameter_list": "(grid, start, goals)"
},
{
"docstring": null,
"function_declaration": "def find_shortest_path(grid):",
"function_name": "find_shortest_path",
"parameter_list": ... | [
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": "from collections import deque\nfrom itertools import combinations\n\ndef min_steps_to_collect_treasures(grid):\n n, m = len(grid), len(grid[0])\n \n def f... | trial_gpt4o_9 | {
"original_instruction": "",
"prompt_id": "00072566",
"row_id": 72566,
"seed_ids": "[24876]"
} | 0.736329 | Taco_72566 | I | [
"bfs",
"find_shortest_path",
"treasure_hunt"
] | 3 | [
[
"find_shortest_path",
"bfs"
],
[
"treasure_hunt",
"find_shortest_path"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | d0ca5ccc061c2c040b277ad52d4c46acbae136cd | 035804117b000254b8b48fb60ebc69ada999c171 | |||
v1.0 | instruct | Taco | Taco_72576_I | Write a program that processes a series of dates and determines which day of the week each date falls on.
Constraints:
- The date will be given in the format YYYY-MM-DD.
- The input will consist of multiple dates, one per line.
- The input ends with an empty line.
- The years given will be between 1900 and 2100, incl... | import datetime
def get_day_of_week(date):
"""
Takes a date string in 'YYYY-MM-DD' format and returns the day of the week.
"""
date_object = datetime.datetime.strptime(date, '%Y-%m-%d')
return date_object.strftime('%A')
def process_dates(dates):
"""
Process multiple date strings and print ... | from solution import get_day_of_week, process_dates
def test_get_day_of_week():
assert get_day_of_week("2023-10-05") == "Thursday"
assert get_day_of_week("1999-12-31") == "Friday"
assert get_day_of_week("2000-01-01") == "Saturday"
assert get_day_of_week("2023-01-01") == "Sunday"
assert get_day_of_w... | [
{
"docstring": "Takes a date string in 'YYYY-MM-DD' format and returns the day of the week.",
"function_declaration": "def get_day_of_week(date):",
"function_name": "get_day_of_week",
"parameter_list": "(date)"
},
{
"docstring": "Process multiple date strings and print the corresponding day ... | [
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 datetime\n\ndef process_dates(dates):\n \"\"\"\n Process a list of date strings and print the day of the week for each date.\n Each date should be ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00072576",
"row_id": 72576,
"seed_ids": "[19241]"
} | 0.621368 | Taco_72576 | I | [
"get_day_of_week",
"process_dates"
] | 2 | [
[
"process_dates",
"get_day_of_week"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 3c5730d288660256ea17b1117dd3f723bf3756ee | 4d9a43a96df556924a57bdeb9390b3c7b51ab8e9 | |||
v1.0 | instruct | Taco | Taco_72590_I | You are given a list of N integers. Your task is to categorize them into two lists: one containing all prime numbers and the other containing non-prime numbers. Write a function to accomplish this and return both lists.
### Input
- The first line contains a single integer N (1 ≤ N ≤ 10^5) - the number of integers in t... | def is_prime(n):
"""
Helper function to check if a number is prime.
"""
if n <= 1:
return False
if n == 2:
return True
if n % 2 == 0:
return False
for i in range(3, int(n**0.5) + 1, 2):
if n % i == 0:
return False
return True
def categorize_nu... | from solution import categorize_numbers
def test_case_1():
numbers = [1, 2, 3, 4, 5, 6]
primes, non_primes = categorize_numbers(numbers)
assert primes == [2, 3, 5]
assert non_primes == [1, 4, 6]
def test_case_2():
numbers = [7, 8, 9, 10, 11, 12]
primes, non_primes = categorize_numbers(numbers)... | [
{
"docstring": "Helper function to check if a number is prime.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Categorize the given list of numbers into a list of primes and non-primes.",
"function_declaration": "def c... | [
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 math\n\ndef is_prime(num):\n \"\"\"\n Check if a number is prime.\n \"\"\"\n if num <= 1:\n return False\n if num <= 3:\n retur... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00072590",
"row_id": 72590,
"seed_ids": "[621]"
} | 0.641406 | Taco_72590 | I | [
"is_prime",
"categorize_numbers"
] | 2 | [
[
"categorize_numbers",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 87ca258a61308d30fd8ad0f32aba5a43fc747536 | 132b4bb6ccf24557f90fcfe7ca36980aba495c1c | |||
v1.0 | instruct | Taco | Taco_72609_I | In a fictional world, a group of magical wizards use a special form of communication called "spell encryption" to send secret messages. The messages are encrypted using a combination of magical gestures, represented by unique sequences of letters and symbols.
Each wizard has a personal dictionary of sequences, where e... | def are_dictionaries_equivalent(d1, d2):
"""
Checks if two dictionaries are equivalent by comparing their sequences.
:param d1: Dictionary 1, a dict of words to sequences
:param d2: Dictionary 2, a dict of words to sequences
:return: True if dictionaries are equivalent, False otherwise
"""
... | import pytest
from solution import are_dictionaries_equivalent, parse_input, compare_dictionaries
def test_are_dictionaries_equivalent():
d1 = {'hello': 'h1^', 'world': 'w1@'}
d2 = {'hello': 'h1^', 'world': 'w1@'}
assert are_dictionaries_equivalent(d1, d2) == True
d3 = {'hello': 'h1^'}
d4 = {'hel... | [
{
"docstring": "Checks if two dictionaries are equivalent by comparing their sequences.\n\n:param d1: Dictionary 1, a dict of words to sequences\n:param d2: Dictionary 2, a dict of words to sequences\n:return: True if dictionaries are equivalent, False otherwise",
"function_declaration": "def are_dictionari... | [
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 are_dictionaries_equivalent(dict1, dict2):\n \"\"\"\n Function to check if two given dictionaries are equivalent.\n \"\"\"\n return dict1 == dict2\... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00072609",
"row_id": 72609,
"seed_ids": "[13881]"
} | 0.629869 | Taco_72609 | I | [
"are_dictionaries_equivalent",
"parse_input",
"compare_dictionaries"
] | 3 | [
[
"compare_dictionaries",
"are_dictionaries_equivalent"
],
[
"compare_dictionaries",
"parse_input"
]
] | 2 | [
"parse_input"
] | false | [] | false | pytest | true | [] | true | 94e955903f6ee7cc02a869d9b5f61a5d0ba38aeb | 3b8600f1200b6541e15b1d96665beccf5097aa5b | |||
v1.0 | instruct | Taco | Taco_72621_I | You are given a sequence of N integers, each in the range 1 to 10^6. For each integer in the sequence, determine whether it is a perfect square and print 'YES' if it is, and 'NO' otherwise.
A perfect square is an integer that is the square of an integer.
Constraints
* All integers in the input are within the range 1... | import math
def is_perfect_square(n):
"""
Determines if a given number n is a perfect square.
"""
root = int(math.sqrt(n))
return root * root == n
def check_perfect_squares(sequence):
"""
For each integer in the sequence, determines whether it is a perfect square.
Returns a list of 'YE... | from solution import is_perfect_square, check_perfect_squares, main
def test_is_perfect_square():
assert is_perfect_square(1) == True
assert is_perfect_square(2) == False
assert is_perfect_square(4) == True
assert is_perfect_square(10) == False
assert is_perfect_square(16) == True
def test_check_p... | [
{
"docstring": "Determines if a given number n is a perfect square.",
"function_declaration": "def is_perfect_square(n):",
"function_name": "is_perfect_square",
"parameter_list": "(n)"
},
{
"docstring": "For each integer in the sequence, determines whether it is a perfect square.\nReturns a ... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import math\n\ndef perfect_squares(N, arr):\n \"\"\"\n Given a list of N integers, this function returns a list of 'YES' or 'NO'\n indicating whether each... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00072621",
"row_id": 72621,
"seed_ids": "[13336]"
} | 0.708534 | Taco_72621 | I | [
"is_perfect_square",
"check_perfect_squares",
"main"
] | 3 | [
[
"check_perfect_squares",
"is_perfect_square"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | c66d63d166dc45b89f96b59a88f559ab37c04043 | 88d3b78c845f21785a366e99e526443eab82ddd8 | |||
v1.0 | instruct | Taco | Taco_72652_I | Sarah recently learned about linked lists in her programming class and decided to test her skills with an interesting problem. She wants to create a linked list from a list of integers. After creating the linked list, she needs to reverse it.
Your task is to help Sarah by writing a program that will take a list of int... | class ListNode:
def __init__(self, x):
self.val = x
self.next = None
def create_linked_list(lst):
if not lst:
return None
head = ListNode(lst[0])
current = head
for value in lst[1:]:
current.next = ListNode(value)
current = current.next
return head
def r... | from solution import reverse_list_of_integers
def test_reverse_list_of_integers():
assert reverse_list_of_integers(5, [1, 2, 3, 4, 5]) == [5, 4, 3, 2, 1]
assert reverse_list_of_integers(3, [10, 20, 30]) == [30, 20, 10]
assert reverse_list_of_integers(1, [100]) == [100]
assert reverse_list_of_integers(4... | [] | [
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 ListNode:\n def __init__(self, val=0, next=None):\n self.val = val\n self.next = next\n\ndef create_linked_list(nums):\n if not nums:\n ... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00072652",
"row_id": 72652,
"seed_ids": "[25412]"
} | 0.666214 | Taco_72652 | I | [
"create_linked_list",
"reverse_linked_list",
"linked_list_to_list",
"reverse_list_of_integers"
] | 4 | [
[
"reverse_list_of_integers",
"create_linked_list"
],
[
"reverse_list_of_integers",
"linked_list_to_list"
],
[
"reverse_list_of_integers",
"reverse_linked_list"
]
] | 3 | [] | false | [
"ListNode"
] | true | pytest | true | [] | true | 6a03698e18f665aa4854c0ecf63a31e57826b3f2 | de25e7e235e48e473afbeafa25bca72a3ce9f224 | |||
v1.0 | instruct | Taco | Taco_72680_I | During a rescue operation, Alex needs to navigate several buildings connected by roads in a disaster-stricken city. The city can be represented as a graph where nodes are buildings and edges are roads connecting them. Each road either allows traffic in one direction or both directions, and has an associated time for tr... | import heapq
def dijkstra(n, adj, start):
"""
Implementation of Dijkstra's algorithm to find the shortest path from a single source to all other nodes.
"""
dist = {i: float('inf') for i in range(1, n + 1)}
dist[start] = 0
pq = [(0, start)]
while pq:
current_dist, u = heapq.heap... | def test_shortest_travel_time():
# Define the test case
n = 5
m = 5
q = 3
roads = [
(1, 2, 10),
(2, 3, 20),
(3, 4, 30),
(4, 5, 40),
(1, 3, 100)
]
queries = [
(1, 5),
(3, 1),
(3, 4)
]
expected_output = [
100,... | [
{
"docstring": "Implementation of Dijkstra's algorithm to find the shortest path from a single source to all other nodes.",
"function_declaration": "def dijkstra(n, adj, start):",
"function_name": "dijkstra",
"parameter_list": "(n, adj, start)"
},
{
"docstring": "Determines the shortest time... | [
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 heapq\n\ndef dijkstra(n, graph, start, end):\n distance = {i: float('inf') for i in range(1, n+1)}\n distance[start] = 0\n priority_queue = [(0, st... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00072680",
"row_id": 72680,
"seed_ids": "[15092]"
} | 0.795241 | Taco_72680 | I | [
"dijkstra",
"shortest_travel_time"
] | 2 | [
[
"shortest_travel_time",
"dijkstra"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | 32b9ad823a7cf3851a352be25dcb25f37dcbcc63 | c6fccdcb954db5cd651de3aff891db962b1ff59c | |||
v1.0 | instruct | Taco | Taco_72718_I | Bob likes playing with prime numbers. He recently learned about a new concept called "Prime Cycles". A Prime Cycle is a sequence of prime numbers where each prime number is shifted to create a cyclic permutation. Bob wants to find out how many unique Prime Cycles can be formed from a given list of prime numbers.
A pri... | def generate_cyclic_permutations(primes):
"""
Generate all cyclic permutations of the given list of prime numbers.
"""
N = len(primes)
cycles = []
for i in range(N):
cycle = primes[i:] + primes[:i]
cycles.append(tuple(cycle))
return cycles
def count_unique_prime_cycles(N, pr... | from solution import count_unique_prime_cycles
def test_small_case():
assert count_unique_prime_cycles(3, [11, 13, 17]) == 3
def test_single_prime():
assert count_unique_prime_cycles(1, [7]) == 1
def test_multiple_unique_cycles():
assert count_unique_prime_cycles(4, [2, 3, 5, 7]) == 4
def test_larger_ca... | [
{
"docstring": "Generate all cyclic permutations of the given list of prime numbers.",
"function_declaration": "def generate_cyclic_permutations(primes):",
"function_name": "generate_cyclic_permutations",
"parameter_list": "(primes)"
},
{
"docstring": "Counts the number of unique Prime Cycle... | [
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 count_unique_prime_cycles(primes):\n \"\"\"\n Function to count unique prime cycles formed from a given list of prime numbers.\n \n Parameters:\n ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00072718",
"row_id": 72718,
"seed_ids": "[12768]"
} | 0.566242 | Taco_72718 | I | [
"generate_cyclic_permutations",
"count_unique_prime_cycles"
] | 2 | [
[
"count_unique_prime_cycles",
"generate_cyclic_permutations"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 7eea441a54bd2db7b69148624f89d828f584e3c4 | 88eb8bf153e3f110bedf46e0b4ae50043772337b | |||
v1.0 | instruct | Taco | Taco_72724_I | You are given a grid with rows and columns, filled with positive integers. You need to find the maximum sum of a contiguous sub-grid in the given grid. A contiguous sub-grid is defined as the rectangular section of the grid that can be obtained by selecting a subarray of contiguous rows and within those rows, selecting... | def max_sub_grid_sum(grid):
"""
Finds the maximum sum of a contiguous sub-grid in the given grid.
"""
R, C = len(grid), len(grid[0])
max_sum = float('-inf')
for left in range(C):
temp = [0] * R
for right in range(left, C):
for i in range(R):
temp[i] +... | import pytest
from solution import max_sub_grid_sum
def test_case_1():
grid = [
[1, 2, -1],
[-3, 4, 2],
[1, -1, 3]
]
assert max_sub_grid_sum(grid) == 9
def test_case_2():
grid = [
[1, 2, 3, 4],
[5, 6, 7, 8],
[9, 10, 11, 12],
[13, 14, 15, 16]
... | [
{
"docstring": "Finds the maximum sum of a contiguous sub-grid in the given grid.",
"function_declaration": "def max_sub_grid_sum(grid):",
"function_name": "max_sub_grid_sum",
"parameter_list": "(grid)"
},
{
"docstring": "Helper function to perform Kadane's algorithm on 1D array to find 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": "def max_sub_grid_sum(grid):\n \"\"\"\n Finds the maximum sum of a contiguous sub-grid in the given grid.\n \"\"\"\n R, C = len(grid), len(grid[0])\n ... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00072724",
"row_id": 72724,
"seed_ids": "[7163]"
} | 0.689251 | Taco_72724 | I | [
"max_sub_grid_sum",
"kadane_1d",
"read_grid_input"
] | 3 | [
[
"max_sub_grid_sum",
"kadane_1d"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 853e77c240dfb939d8548d3b9c94f07684a481b1 | d962dbfe61b0ab26edf3e8d10d6592489aea6df3 | |||
v1.0 | instruct | Taco | Taco_72784_I | In a kingdom, there are several cities connected by various roads. The roads are bidirectional and each road has a certain travel cost. The king wants to build a new palace in one of the cities such that the maximum travel cost from this city to any other city is minimized.
You are given the number of cities and a lis... | import heapq
def dijkstra(n, graph, start):
"""
Function to perform Dijkstra's algorithm from the start node.
Returns a list of minimum distances from start to all other nodes.
"""
distances = [float('inf')] * n
distances[start] = 0
priority_queue = [(0, start)]
while priority_queu... | def test_optimal_palace_location():
assert optimal_palace_location(
4,
[
[1, 2, 3],
[2, 3, 4],
[3, 4, 5],
[4, 1, 6]
]
) == 7
assert optimal_palace_location(
3,
[
[1, 2, 1],
[2, 3, 1],
... | [
{
"docstring": "Function to perform Dijkstra's algorithm from the start node.\nReturns a list of minimum distances from start to all other nodes.",
"function_declaration": "def dijkstra(n, graph, start):",
"function_name": "dijkstra",
"parameter_list": "(n, graph, start)"
},
{
"docstring": "... | [
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": "import heapq\n\ndef dijkstra(graph, start, n):\n \"\"\"\n Implements Dijkstra's algorithm to find the shortest path from start node to all other nodes in the... | trial_gpt4o_8 | {
"original_instruction": "",
"prompt_id": "00072784",
"row_id": 72784,
"seed_ids": "[6176]"
} | 0.747724 | Taco_72784 | I | [
"dijkstra",
"optimal_palace_location"
] | 2 | [
[
"optimal_palace_location",
"dijkstra"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | 05d93c73977cdff966cd8c9f012e7f17257e5b18 | 3af2cf0286984551f5a855a51c159f86cc85af43 | |||
v1.0 | instruct | Taco | Taco_72835_I | # Task
Given an integer `n`, return a list where the `i`-th element (0-indexed) is the square of the `i`-th prime number, for the first `n` prime numbers.
# Example
For `n = 0`, the output should be `[]`.
For `n = 1`, the output should be `[4]`. (The first prime number is 2, and its square is 4).
For `n = 3`, the ... | def is_prime(num):
"""Helper function to determine if a number is prime."""
if num <= 1:
return False
if num <= 3:
return True
if num % 2 == 0 or num % 3 == 0:
return False
i = 5
while (i * i) <= num:
if num % i == 0 or num % (i + 2) == 0:
return False... | from solution import prime_squares
def test_prime_squares_zero():
assert prime_squares(0) == []
def test_prime_squares_one():
assert prime_squares(1) == [4]
def test_prime_squares_two():
assert prime_squares(2) == [4, 9]
def test_prime_squares_three():
assert prime_squares(3) == [4, 9, 25]
def test... | [
{
"docstring": "Helper function to determine if a number is prime.",
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": "Return a list where the i-th element is the square of the i-th prime number, for the first n prime numb... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(num):\n if num <= 1:\n return False\n for i in range(2, int(num ** 0.5) + 1):\n if num % i == 0:\n return False\n re... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00072835",
"row_id": 72835,
"seed_ids": "[7238]"
} | 0.642422 | Taco_72835 | I | [
"is_prime",
"prime_squares"
] | 2 | [
[
"prime_squares",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 7559e1387158cbbe4acc12f66c559966c1bcd5b1 | 9d9099693b7391ddc9e5546620c17bfed91e4290 | |||
v1.0 | instruct | Taco | Taco_72867_I | Write a function that takes an array of integers and returns the length of the longest contiguous subarray that forms a palindrome. A subarray is a contiguous part of an array that can be obtained by deleting zero or more elements from either end of the array.
```
longestPalindromicSubarrayLength([1,2,3,4,3,2,1]) == 7... | def is_palindrome(subarray):
"""
Helper function to check if a given subarray is a palindrome.
"""
return subarray == subarray[::-1]
def longestPalindromicSubarrayLength(nums):
"""
Returns the length of the longest contiguous subarray that forms a palindrome.
"""
max_length = 0
n = ... | from solution import longestPalindromicSubarrayLength
def test_empty_array():
assert longestPalindromicSubarrayLength([]) == 0
def test_single_element():
assert longestPalindromicSubarrayLength([1]) == 1
def test_all_elements_same():
assert longestPalindromicSubarrayLength([2, 2, 2, 2, 2]) == 5
def test... | [
{
"docstring": "Helper function to check if a given subarray is a palindrome.",
"function_declaration": "def is_palindrome(subarray):",
"function_name": "is_palindrome",
"parameter_list": "(subarray)"
},
{
"docstring": "Returns the length of the longest contiguous subarray that forms a palin... | [
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 longestPalindromicSubarrayLength(arr):\n \"\"\"\n Return the length of the longest contiguous subarray that forms a palindrome.\n \"\"\"\n n = len(... | trial_gpt4o_5 | {
"original_instruction": "",
"prompt_id": "00072867",
"row_id": 72867,
"seed_ids": "[9564]"
} | 0.752228 | Taco_72867 | I | [
"is_palindrome",
"longestPalindromicSubarrayLength"
] | 2 | [
[
"longestPalindromicSubarrayLength",
"is_palindrome"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | f16e4aeef913b4ada7bcff1fb529705a120a492b | 97439386eec8a6f1b7863d024117416e79100169 | |||
v1.0 | instruct | Taco | Taco_72925_I | Given a grid of size $n \times m$ consisting of lowercase English letters, you need to find the largest square subgrid such that all the characters in the subgrid are the same.
### Input
The first line contains two integers $t$ ($1 \le t \le 10$) — the number of test cases.
For each test case, the first line contai... | def largest_uniform_square(grid, n, m):
dp = [[0]*m for _ in range(n)]
max_side_len = 1
# Initialize the DP table
for i in range(n):
for j in range(m):
if i == 0 or j == 0:
dp[i][j] = 1
else:
if grid[i][j] == grid[i-1][j] == grid[i][j-1] =... | def test_largest_uniform_square():
grid1 = [
['a', 'a', 'a', 'a'],
['a', 'b', 'a', 'a'],
['a', 'b', 'b', 'b']
]
assert largest_uniform_square(grid1, 3, 4) == 2
grid2 = [
['a', 'b', 'c', 'd'],
['a', 'b', 'c', 'd'],
['a', 'b', 'c', 'd'],
['a', '... | [
{
"docstring": null,
"function_declaration": "def largest_uniform_square(grid, n, m):",
"function_name": "largest_uniform_square",
"parameter_list": "(grid, n, m)"
},
{
"docstring": null,
"function_declaration": "def solve_problem(test_cases):",
"function_name": "solve_problem",
... | [
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 largest_same_char_square(n, m, grid):\n max_side = min(n, m)\n largest_square_side = 1\n \n for side in range(2, max_side + 1):\n found = Fa... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00072925",
"row_id": 72925,
"seed_ids": "[5406]"
} | 0.655268 | Taco_72925 | I | [
"largest_uniform_square",
"solve_problem",
"read_input",
"output_result"
] | 4 | [
[
"solve_problem",
"largest_uniform_square"
]
] | 1 | [
"read_input"
] | false | [] | false | pytest | true | [] | true | 29e2f17398956188db531eda355ea7fea4da3cb9 | 8e630445c98c86c8bc9ba14a6eaac8f5718ba1a5 | |||
v1.0 | instruct | Taco | Taco_72968_I | A game developer is designing a new strategy game where players need to manage a fleet of robots to mine resources on a grid. Each robot has a sequence of instructions encoded as a string, where 'L' indicates a move left, 'R' indicates a move right, 'U' indicates a move up, and 'D' indicates a move down. The game devel... | def is_within_bounds(m, n, x, y, instructions):
"""
Determines if the robot's sequence of instructions keeps it within the grid.
:param m: Number of rows in the grid.
:param n: Number of columns in the grid.
:param x: Starting x-coordinate (row) of the robot.
:param y: Starting y-coordinate... | from solution import is_within_bounds, process_robots_and_instructions
def test_is_within_bounds():
assert is_within_bounds(5, 5, 1, 1, 'RDU') == 'YES'
assert is_within_bounds(5, 5, 2, 2, 'LLR') == 'NO'
assert is_within_bounds(5, 5, 3, 3, 'DDDUU') == 'NO'
assert is_within_bounds(3, 3, 3, 3, 'UUUUUU') =... | [
{
"docstring": "Determines if the robot's sequence of instructions keeps it within the grid.\n\n:param m: Number of rows in the grid.\n:param n: Number of columns in the grid.\n:param x: Starting x-coordinate (row) of the robot.\n:param y: Starting y-coordinate (column) of the robot.\n:param instructions: Seque... | [
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 is_within_grid(m, n, x, y, s):\n \"\"\"\n Check if the robot remains within the grid boundaries.\n \n :param m: Number of rows in the grid\n :pa... | trial_gpt4o_7 | {
"original_instruction": "",
"prompt_id": "00072968",
"row_id": 72968,
"seed_ids": "[25170]"
} | 0.681956 | Taco_72968 | I | [
"is_within_bounds",
"process_robots_and_instructions"
] | 2 | [
[
"process_robots_and_instructions",
"is_within_bounds"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 65e94ccf2e7b63a7b62bcdbf0b942d1035889fde | af353828d8a273bf1a52ed41c2fd5927f5c36a6a | |||
v1.0 | instruct | Taco | Taco_72977_I | Your friend Jeff Zebos is trying to enhance his product catalog by giving each product a catchy name. However, due to certain restrictions, he's only able to use alphabetic characters and wants to generate new names based on predefined sets of valid names.
Unfortunately, Jeff learned that customers prefer names with s... | from collections import Counter
def can_form_palindrome(name):
"""
Determines if the given product name can be rearranged into a palindrome.
Returns a tuple of (result, palindrome) where result is "YES" or "NO"
and palindrome is any one possible palindromic permutation or None if it's not possible.
... | def test_can_form_palindrome_yes():
result, palindrome = can_form_palindrome("AABB")
assert result == "YES"
assert palindrome == "ABBA" or palindrome == "BAAB"
def test_can_form_palindrome_no():
result, palindrome = can_form_palindrome("CAR")
assert result == "NO"
assert palindrome is None
def... | [
{
"docstring": "Determines if the given product name can be rearranged into a palindrome.\nReturns a tuple of (result, palindrome) where result is \"YES\" or \"NO\" \nand palindrome is any one possible palindromic permutation or None if it's not possible.",
"function_declaration": "def can_form_palindrome(n... | [
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 can_form_palindrome(name):\n \"\"\"\n Checks if the given product name can be rearranged to form a palindrome.\n Returns \"YES\" with any one of the p... | trial_gpt4o_3 | {
"original_instruction": "",
"prompt_id": "00072977",
"row_id": 72977,
"seed_ids": "[19079]"
} | 0.749376 | Taco_72977 | I | [
"can_form_palindrome",
"process_names"
] | 2 | [
[
"process_names",
"can_form_palindrome"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | 95195545f190f56919fd85765702353176dc1330 | 4da3fd12773c56fbda316a75394ca4ab98115a06 | |||
v1.0 | instruct | Taco | Taco_73024_I | In a particular town, there is a grid of streets with M rows and N columns, represented as a matrix with cells. Each cell represents an intersection of streets. Each intersection can have a traffic light with two states: green (G) or red (R). The traffic light switches states according to the following rules:
- A green... | def get_next_state(grid, M, N):
next_grid = [['R'] * N for _ in range(M)]
directions = [(-1, 0), (1, 0), (0, -1), (0, 1)]
for i in range(M):
for j in range(N):
green_count = 0
red_count = 0
for di, dj in directions:
ni, nj = i + d... | def test_get_next_state():
grid = [
['G', 'G', 'G'],
['G', 'R', 'G'],
['G', 'G', 'G']
]
expected = [
['G', 'R', 'G'],
['R', 'G', 'R'],
['G', 'R', 'G']
]
assert get_next_state(grid, 3, 3) == expected
def test_traffic_lights_after_k_steps_1_step():
... | [
{
"docstring": null,
"function_declaration": "def get_next_state(grid, M, N):",
"function_name": "get_next_state",
"parameter_list": "(grid, M, N)"
},
{
"docstring": null,
"function_declaration": "def traffic_lights_after_k_steps(M, N, K, grid):",
"function_name": "traffic_lights_aft... | [
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 next_state(M, N, K, grid):\n def adjacent_same(state, row, col):\n return (row > 0 and grid[row - 1][col] == state) or \\\n (row < M - ... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00073024",
"row_id": 73024,
"seed_ids": "[3461]"
} | 0.631355 | Taco_73024 | I | [
"get_next_state",
"traffic_lights_after_k_steps"
] | 2 | [
[
"traffic_lights_after_k_steps",
"get_next_state"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | 9114edc8511372934fae39be906145ad7f65925b | ef37b2f1a0d8fbe5d9d8dbf04e89c826da506645 | |||
v1.0 | instruct | Taco | Taco_73037_I | John loves gardening and has a beautiful garden with N different plants. He waters these plants with a unique watering system that has multiple watering schedules. Each plant has its own watering frequency in days. When plants are watered on the same day, they grow together and bloom beautifully. John's challenge is to... | import math
from functools import reduce
MOD = 1000000007
def lcm(a, b):
return abs(a * b) // math.gcd(a, b)
def lcm_multiple(*args):
return reduce(lcm, args)
def next_simultaneous_watering_day(test_cases):
results = []
for case in test_cases:
n, frequencies = case
next_day = lcm_mul... | from solution import next_simultaneous_watering_day
def test_single_case():
assert next_simultaneous_watering_day([(3, [2, 3, 5])]) == [30]
def test_multiple_cases():
assert next_simultaneous_watering_day([(3, [2, 3, 5]), (2, [4, 6])]) == [30, 12]
def test_large_numbers():
assert next_simultaneous_wateri... | [
{
"docstring": null,
"function_declaration": "def lcm(a, b):",
"function_name": "lcm",
"parameter_list": "(a, b)"
},
{
"docstring": null,
"function_declaration": "def lcm_multiple(*args):",
"function_name": "lcm_multiple",
"parameter_list": "(*args)"
},
{
"docstring": nul... | [
0,
1,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from math import gcd\nfrom functools import reduce\n\nMOD = 1000000007\n\ndef lcm(a, b):\n return (a * b) // gcd(a, b)\n\ndef lcm_of_list(frequencies):\n ret... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00073037",
"row_id": 73037,
"seed_ids": "[21405]"
} | 0.626705 | Taco_73037 | I | [
"lcm",
"lcm_multiple",
"next_simultaneous_watering_day"
] | 3 | [
[
"lcm_multiple",
"lcm"
],
[
"next_simultaneous_watering_day",
"lcm_multiple"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 061c2af0c5c4eb1243a0e8cc23c086723c9fb35d | 376ce6a0fbc80674a6c8fe459b03fcd1c2caa24e | |||
v1.0 | instruct | Taco | Taco_73047_I | Kalyani has a sequence of integers and she wants to know some interesting properties about the sequence. For each given integer, she wants to calculate the sum of the digits raised to the power of 3. The task is to compute this sum for every element in the sequence and check if the result is a prime number or not. If i... | from math import isqrt
def sum_of_cubed_digits(n):
"""
Returns the sum of the digits of `n` each raised to the power of 3.
"""
return sum(int(digit) ** 3 for digit in str(n))
def is_prime(num):
"""
Returns True if `num` is a prime number, else False.
"""
if num <= 1:
return Fal... | from solution import interesting_properties
def test_sample_input():
assert interesting_properties([123, 9474, 372]) == ["NO", "NO", "NO"]
def test_single_small_number():
assert interesting_properties([5]) == ["NO"]
assert interesting_properties([7]) == ["NO"]
def test_single_large_number():
assert i... | [
{
"docstring": "Returns the sum of the digits of `n` each raised to the power of 3.",
"function_declaration": "def sum_of_cubed_digits(n):",
"function_name": "sum_of_cubed_digits",
"parameter_list": "(n)"
},
{
"docstring": "Returns True if `num` is a prime number, else False.",
"function... | [
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 is_prime(n):\n \"\"\"\n Helper function to check if a number is prime.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return ... | trial_gpt4o_3 | {
"original_instruction": "",
"prompt_id": "00073047",
"row_id": 73047,
"seed_ids": "[11513]"
} | 0.61525 | Taco_73047 | I | [
"sum_of_cubed_digits",
"is_prime",
"interesting_properties"
] | 3 | [
[
"interesting_properties",
"is_prime"
],
[
"interesting_properties",
"sum_of_cubed_digits"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 38d17169cc6c7edfa27b459569141816cc70b1db | 8416c1a435f87228495e3816bb9364125d4c439b | |||
v1.0 | instruct | Taco | Taco_73056_I | You are given an integer array $arr$ and an integer $k$. Find the number of distinct pairs of numbers in the array that add up to the integer $k$. A pair $(x, y)$ is considered unique if there are no previously counted pairs with both $x$ and $y$ the same.
-----Input:-----
- First line contains an integer $T$, the num... | def find_distinct_pairs_count(arr, k):
"""
Finds the number of unique pairs that add up to k in the given array.
"""
seen = set()
pairs = set()
for num in arr:
target = k - num
if target in seen:
ordered_pair = tuple(sorted((num, target)))
pairs.add(o... | from solution import find_distinct_pairs_count, solve, parse_input
def test_find_distinct_pairs_count():
assert find_distinct_pairs_count([4, 3, 5, 7, 8], 10) == 1
assert find_distinct_pairs_count([1, 5, 7, -1], 6) == 2
assert find_distinct_pairs_count([1, 2, 3, 4, 5], 5) == 2
assert find_distinct_pair... | [
{
"docstring": "Finds the number of unique pairs that add up to k in the given array.",
"function_declaration": "def find_distinct_pairs_count(arr, k):",
"function_name": "find_distinct_pairs_count",
"parameter_list": "(arr, k)"
},
{
"docstring": null,
"function_declaration": "def solve(... | [
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 count_distinct_pairs_with_sum(arr, k):\n \"\"\"\n Returns the number of distinct pairs in the arr that add up to k.\n \"\"\"\n seen = set()\n pa... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00073056",
"row_id": 73056,
"seed_ids": "[25095]"
} | 0.733381 | Taco_73056 | I | [
"find_distinct_pairs_count",
"solve",
"parse_input"
] | 3 | [
[
"solve",
"find_distinct_pairs_count"
]
] | 1 | [
"parse_input"
] | false | [] | false | pytest | true | [] | true | 13187659d3fb0c71e4973b95d975cbefd8c03096 | 742a83a814c6da133ed49d7887e3fa22398aa73e | |||
v1.0 | instruct | Taco | Taco_73066_I | Jane needs to organize a series of events, each with different start and end times, but she cannot attend more than one event at a time. Given a list of events, each described by a start time and end time, determine the maximum number of events Jane can attend without overlapping.
-----Input-----
Input contains an int... | def max_events(events):
"""
Returns the maximum number of events that can be attended without overlapping.
"""
# Sort events by their end times to prioritize finishing earliest.
events.sort(key=lambda x: x[1])
count = 0
last_end_time = 0
for start, end in events:
if sta... | from solution import parse_and_solve
def test_max_events_sample_1():
n = 3
events = [(1, 2), (2, 3), (3, 4)]
assert parse_and_solve(n, events) == 3
def test_max_events_sample_2():
n = 3
events = [(1, 2), (1, 2), (1, 2)]
assert parse_and_solve(n, events) == 1
def test_max_events_no_overlap():
... | [
{
"docstring": "Returns the maximum number of events that can be attended without overlapping.",
"function_declaration": "def max_events(events):",
"function_name": "max_events",
"parameter_list": "(events)"
},
{
"docstring": "Given the number of events and a list of their start and end time... | [
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 max_events(events):\n \"\"\"\n Given a list of events with start and end times, determine the maximum number\n of events that can be attended without ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00073066",
"row_id": 73066,
"seed_ids": "[21282]"
} | 0.688314 | Taco_73066 | I | [
"max_events",
"parse_and_solve"
] | 2 | [
[
"parse_and_solve",
"max_events"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 51cc2030365296db7b53d84930f22fcef9f9eaf2 | c23fc61b58d063aaeadae8858d49c778932367d5 | |||
v1.0 | instruct | Taco | Taco_73073_I | Given two binary search trees, BST1 and BST2, your task is to merge these trees into a single binary search tree with all the elements from both input trees. The resulting tree must also satisfy the properties of a binary search tree:
1. The left subtree of a node contains only nodes with keys less than the node's key.... | class TreeNode:
def __init__(self, value=0, left=None, right=None):
self.value = value
self.left = left
self.right = right
def insertIntoBST(root, value):
if not root:
return TreeNode(value)
if value < root.value:
root.left = insertIntoBST(root.left, value)
else:... | def test_merge_bsts():
cases = [
("3,1,4", "2,5", "1 2 3 4 5"),
("10,5,1", "8,3,7", "1 3 5 7 8 10"),
("", "1,2,3", "1 2 3"),
("4,2,6", "", "2 4 6"),
("", "", "")
]
for bst1, bst2, expected in cases:
assert " ".join(map(str, mergeBSTs(bst1, bst2))) == expected... | [] | [
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": "class TreeNode:\n def __init__(self, value=0, left=None, right=None):\n self.value = value\n self.left = left\n self.right = right\n\ndef i... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00073073",
"row_id": 73073,
"seed_ids": "[11191]"
} | 0.533608 | Taco_73073 | I | [
"insertIntoBST",
"mergeBSTs",
"process_merge",
"main"
] | 4 | [
[
"mergeBSTs",
"insertIntoBST"
],
[
"process_merge",
"mergeBSTs"
]
] | 2 | [] | false | [
"TreeNode"
] | true | pytest | false | [] | true | e146be769de96b456955ed8363063d5f42d6fae1 | 95e3da2fe4e25ea9d7054f2905cd97595a4e2073 | |||
v1.0 | instruct | Taco | Taco_73136_I | A scrabble helper
Design a function that helps determine the longest word you can form from a given set of letters. You have a dictionary of valid words and a rack of letters. Write a function that takes the rack of letters and returns the longest valid word(s) that can be formed from it. If there are multiple words w... | from collections import Counter
def can_form_word(rack_counter, word):
word_counter = Counter(word)
for letter, count in word_counter.items():
if count > rack_counter[letter]:
return False
return True
def find_longest_words(rack, dictionary):
rack_counter = Counter(rack)
valid_... | from solution import find_longest_words
def test_single_longest_word():
dictionary = ["pale", "leap", "plea", "apple"]
rack = ["a", "e", "l", "p", "p"]
assert find_longest_words(rack, dictionary) == ["apple"]
def test_multiple_longest_words():
dictionary = ["pale", "leap", "plea", "pep"]
rack = ["... | [
{
"docstring": null,
"function_declaration": "def can_form_word(rack_counter, word):",
"function_name": "can_form_word",
"parameter_list": "(rack_counter, word)"
},
{
"docstring": null,
"function_declaration": "def find_longest_words(rack, dictionary):",
"function_name": "find_longes... | [
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": "from collections import Counter\n\ndef find_longest_words(rack, dictionary):\n \"\"\"\n Find the longest words that can be formed from the given rack of lett... | trial_gpt4o_4 | {
"original_instruction": "",
"prompt_id": "00073136",
"row_id": 73136,
"seed_ids": "[12013]"
} | 0.654912 | Taco_73136 | I | [
"can_form_word",
"find_longest_words"
] | 2 | [
[
"find_longest_words",
"can_form_word"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | d4bc04e93bc3082abda93e921fb684de78c7f71d | 9bbb58a63f3cc98434b6b7ac8b2db41b8634431c | |||
v1.0 | instruct | Taco | Taco_73138_I | You are given a list of n integers, and you need to sort this list in such a way that all the prime numbers in the list are sorted in ascending order, while the non-prime numbers remain in their original positions.
Input
The single line contains an integer n (1 ≤ n ≤ 1000), followed by n integers.
Output
Print the ... | def is_prime(num):
"""
Check if a number is a prime number.
"""
if num <= 1:
return False
if num == 2:
return True
if num % 2 == 0:
return False
for i in range(3, int(num**0.5) + 1, 2):
if num % i == 0:
return False
return True
def sort_primes... | from solution import is_prime, sort_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(10) == False
assert is_prime(13) == True
def test_sort_primes_in_list():
assert sort_primes_i... | [
{
"docstring": "Check if a number is a prime number.",
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": "Sorts the prime numbers in the list in ascending order while keeping non-prime numbers in their original positions.",... | [
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 \"\"\"\n Determine whether a number is prime.\n \"\"\"\n if num <= 1:\n return False\n if num <= 3:\n return True... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00073138",
"row_id": 73138,
"seed_ids": "[24906]"
} | 0.638577 | Taco_73138 | I | [
"is_prime",
"sort_primes_in_list"
] | 2 | [
[
"sort_primes_in_list",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | c77471e8aff807d017cd7eb14dcad68ffd64ada9 | b476416b1bf19b4b5f67b0433f77d4f696cc3e45 | |||
v1.0 | instruct | Taco | Taco_73139_I | You are tasked to determine the final standings for a marathon race. There are several competitors, and their progress needs to be evaluated based on specific checkpoints they pass during the marathon. A runner's final position is determined by how quickly they pass through the checkpoints and finish the race.
Here's ... | from typing import List, Dict, Any
from datetime import datetime
def race_results(runners: List[Dict[str, Any]]) -> Dict[str, str]:
def parse_time(time_str):
return datetime.strptime(time_str, "%H:%M:%S")
def tie_breaker(runner1, runner2):
times1 = runner1["times"]
times2 = runner2... | from solution import race_results
def test_no_ties():
runners = [
{"name": "Alice", "times": ["00:15:30", "00:30:25", "00:45:10", "01:10:05"]},
{"name": "Bob", "times": ["00:14:25", "00:28:20", "00:42:30", "01:05:25"]},
{"name": "Charlie", "times": ["00:17:10", "00:34:05", "00:50:00", "01:1... | [
{
"docstring": null,
"function_declaration": "def race_results(runners):",
"function_name": "race_results",
"parameter_list": "(runners)"
},
{
"docstring": null,
"function_declaration": "def ordinal(n):",
"function_name": "ordinal",
"parameter_list": "(n)"
},
{
"docstring... | [
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 convert_time_to_seconds(time_str):\n \"\"\"\n Convert a time string in the format HH:MM:SS to seconds.\n \"\"\"\n h, m, s = map(int, time_str.split... | trial_gpt4o_6 | {
"original_instruction": "",
"prompt_id": "00073139",
"row_id": 73139,
"seed_ids": "[19211]"
} | 0.6256 | Taco_73139 | I | [
"race_results",
"ordinal"
] | 2 | [
[
"race_results",
"ordinal"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | beeba9a22fb177cb225cf45d78fbdd5312aef996 | a68e87153a2f46cc8f86140861360ae1bb6ce5b9 | |||
v1.0 | instruct | Taco | Taco_73162_I | Gene Corporation is working on a new robotic turtle that navigates inside a 2D grid factory. The turtle has a unique property: it can execute a fixed sequence of operations repeatedly. Specifically, the turtle can move in four directions (N, E, S, W) within the grid. For each direction, the turtle moves exactly one uni... | def calculate_final_position(x_start, y_start, command_sequence):
x, y = x_start, y_start
for cmd in command_sequence:
if cmd == 'N':
y += 1
elif cmd == 'E':
x += 1
elif cmd == 'S':
y -= 1
elif cmd == 'W':
x -= 1
return (x, y)
... | def test_turtle_visits_targets_success():
n = 3
k = 4
targets = [(1, 1), (2, 2), (3, 3)]
command_sequence = "NESW"
assert turtle_visits_targets(n, k, targets, command_sequence) == (1, 1)
def test_turtle_visits_targets_fail():
n = 3
k = 4
targets = [(1, 1), (2, 2), (4, 5)]
command_se... | [
{
"docstring": null,
"function_declaration": "def calculate_final_position(x_start, y_start, command_sequence):",
"function_name": "calculate_final_position",
"parameter_list": "(x_start, y_start, command_sequence)"
},
{
"docstring": null,
"function_declaration": "def turtle_visits_targe... | [
0,
0,
0,
0,
0,
0,
1,
0,
0
] | 1 | hard | 0.111 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def can_visit_all_targets(N, K, targets, command_sequence):\n \"\"\"\n Determine if it's possible for the turtle to visit all the target points\n exactly ... | trial_gpt4o_7 | {
"original_instruction": "",
"prompt_id": "00073162",
"row_id": 73162,
"seed_ids": "[21865]"
} | 0.700266 | Taco_73162 | I | [
"calculate_final_position",
"turtle_visits_targets"
] | 2 | [
[
"turtle_visits_targets",
"calculate_final_position"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | ffccf66c49330149b9c9cec2acb1f0bf665fafac | 70c69acb157f4a953a0b97ccf04801e6edb2e5c6 | |||
v1.0 | instruct | Taco | Taco_73171_I | You are given an $N \times M$ grid consisting of characters `.` and `*`. The `.` character represents an empty cell and the `*` character represents an obstacle. You are also provided with the starting position of a robot that needs to be navigated to a target position. The robot can move up, down, left, or right, but ... | from collections import deque
def shortest_path(grid, start, target):
N = len(grid)
M = len(grid[0])
# Converting to 0-indexed
start_row, start_col = start[0] - 1, start[1] - 1
target_row, target_col = target[0] - 1, target[1] - 1
# Directions for moving up, down, left, right
dire... | import pytest
from solution import resolve_shortest_path
def test_example1():
N = 5
M = 7
grid = [
".......",
".*.*.*.",
".......",
".*.*.*.",
"......."
]
start = (1, 1)
target = (5, 7)
assert resolve_shortest_path(N, M, grid, start, target) == 10
de... | [
{
"docstring": null,
"function_declaration": "def shortest_path(grid, start, target):",
"function_name": "shortest_path",
"parameter_list": "(grid, start, target)"
},
{
"docstring": null,
"function_declaration": "def resolve_shortest_path(N, M, grid, start, target):",
"function_name"... | [
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": "from collections import deque\n\ndef shortest_path(grid, start, target):\n N = len(grid)\n M = len(grid[0])\n start = (start[0] - 1, start[1] - 1) # conve... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00073171",
"row_id": 73171,
"seed_ids": "[11478]"
} | 0.773982 | Taco_73171 | I | [
"shortest_path",
"resolve_shortest_path"
] | 2 | [
[
"resolve_shortest_path",
"shortest_path"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 1f5f1a87ffa198b9b44373c64964689778f80c7c | 81cd543d38c7a287c8659acd81c97eb564ae5f2b | |||
v1.0 | instruct | Taco | Taco_73186_I | **Problem**
You are given a binary tree where each node contains an integer value. You need to determine if there exists a path in this tree whose sum of values equals a given target sum. The path must start from the root node and end at any leaf node.
A leaf node is a node with no children. Consider the following d... | class BinaryTree:
def __init__(self, x):
self.val = x
self.left = None
self.right = None
def add_left(self, left):
self.left = left
def add_right(self, right):
self.right = right
def has_path_sum(root, target_sum):
if not root:
return False
... | from solution import BinaryTree, has_path_sum, create_binary_tree_from_breadth_first, check_path_sum_from_input
def test_check_path_sum_from_input():
assert check_path_sum_from_input(5, [5, 4, 8, 11, 13], 22) == "YES"
assert check_path_sum_from_input(3, [1, 2, 3], 5) == "NO"
assert check_path_sum_from_inpu... | [] | [
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": "class BinaryTreeNode:\n def __init__(self, x):\n self.val = x\n self.left = None\n self.right = None\n\ndef has_path_sum(root, target_sum):... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00073186",
"row_id": 73186,
"seed_ids": "[20434]"
} | 0.635004 | Taco_73186 | I | [
"has_path_sum",
"create_binary_tree_from_breadth_first",
"check_path_sum_from_input"
] | 3 | [
[
"check_path_sum_from_input",
"create_binary_tree_from_breadth_first"
],
[
"check_path_sum_from_input",
"has_path_sum"
]
] | 2 | [] | false | [
"BinaryTree"
] | true | pytest | true | [] | true | ac7bba4d8a3b92dab5fd7ddd22f4311324351e50 | 0fda693e60a04e246d2004ba7b41137d25477f5f |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.