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_16669_I | Given an integer n, print the first n prime numbers in ascending order.
Constraints
* 1 ≤ n ≤ 1000
Input
The input contains a single integer n.
Output
Output the first n prime numbers in ascending order, each on a new line.
Example
Input
10
Output
2
3
5
7
11
13
17
19
23
29 | def is_prime(num):
if num <= 1:
return False
if num <= 3:
return True
if num % 2 == 0 or num % 3 == 0:
return False
i = 5
while i * i <= num:
if num % i == 0 or num % (i + 2) == 0:
return False
i += 6
return True
def first_n_primes(n):
pri... | from solution import is_prime, first_n_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(29) == True
def test_first_n_primes():
assert first_n_primes(1) == [2... | [
{
"docstring": null,
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": null,
"function_declaration": "def first_n_primes(n):",
"function_name": "first_n_primes",
"parameter_list": "(n)"
}
] | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(num):\n \"\"\"\n Helper function to determine if a number is prime.\n \"\"\"\n if num <= 1:\n return False\n if num <= 3:\n ... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00016669",
"row_id": 16669,
"seed_ids": "[12443]"
} | 0.655872 | Taco_16669 | I | [
"is_prime",
"first_n_primes"
] | 2 | [
[
"first_n_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 4eb4508cb69ecb46e71e4cc79a1200f64abf6ab8 | f8c4d4b6f4735a7380fcd7f7965e88dc640f41fd | |||
v1.0 | instruct | Taco | Taco_16760_I | In a kingdom, there are N cities connected by M bidirectional roads. Each road connects two cities, and it is guaranteed that there is a unique path between any pair of cities (i.e., the cities and roads form a tree). The kingdom's ruler wants to monitor the traffic between cities to ensure the safety of his people. He... | import sys
import collections
sys.setrecursionlimit(200000)
def preprocess_tree(n, graph):
# BFS to find out the depth and the immediate parent (2^0) parent
depth = [-1] * (n + 1)
parent = [-1] * (n + 1)
root = 1
depth[root] = 0
queue = collections.deque([root])
while queue:
n... | def test_solution():
N, M = 5, 4
roads = [(1, 2), (1, 3), (3, 4), (3, 5)]
Q = 3
queries = [(2, 4), (5, 4), (1, 5)]
expected_output = [1, 3, 1]
assert solution(N, M, roads, Q, queries) == expected_output
def test_solution_large_case():
N, M = 6, 5
roads = [(1, 2), (1, 3), (2, 4), (2, 5),... | [
{
"docstring": null,
"function_declaration": "def preprocess_tree(n, graph):",
"function_name": "preprocess_tree",
"parameter_list": "(n, graph)"
},
{
"docstring": null,
"function_declaration": "def lca(a, b, depth, parent):",
"function_name": "lca",
"parameter_list": "(a, b, dep... | [
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 sys\nfrom collections import defaultdict, deque\n\ninput = sys.stdin.read\n\ndef preprocess_lca(n, adj):\n LOG = 17 # As 2^17 > 100000\n\n depth = [0... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00016760",
"row_id": 16760,
"seed_ids": "[9343]"
} | 0.808402 | Taco_16760 | I | [
"preprocess_tree",
"lca",
"solution"
] | 3 | [
[
"solution",
"lca"
],
[
"solution",
"preprocess_tree"
]
] | 2 | [] | false | [] | false | pytest | false | [] | true | 053021c77ca1c7a8fcde32c206a3e69b1dce47da | 109f6b166562a6c5f500865aaee1a199e6e1554d | |||
v1.0 | instruct | Taco | Taco_16769_I | You are given a sequence of integers representing the heights of students in a line. All the students are required to rearrange themselves in non-decreasing order of their heights. However, the rearrangement must be done using the minimum number of adjacent swaps.
Write a function that takes the list of student height... | def count_inversions(arr):
# Helper function to merge two halves and count inversions
def merge_and_count(arr, temp_arr, left, mid, right):
i = left # Starting index for left subarray
j = mid + 1 # Starting index for right subarray
k = left # Starting index to be sorted
inv... | from solution import minimum_adjacent_swaps
def test_example():
assert minimum_adjacent_swaps([4, 3, 2, 1, 5, 6]) == 6
def test_sorted_list():
assert minimum_adjacent_swaps([1, 2, 3, 4, 5, 6]) == 0
def test_reversed_list():
assert minimum_adjacent_swaps([6, 5, 4, 3, 2, 1]) == 15
def test_mixed_list_1():... | [
{
"docstring": null,
"function_declaration": "def count_inversions(arr):",
"function_name": "count_inversions",
"parameter_list": "(arr)"
},
{
"docstring": null,
"function_declaration": "def minimum_adjacent_swaps(heights):",
"function_name": "minimum_adjacent_swaps",
"parameter_... | [
0,
0,
0,
0,
0,
1,
0,
1,
1,
1
] | 4 | medium | 0.4 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def count_inversions(arr):\n \"\"\"\n Uses the merge sort algorithm to count inversions in the array.\n \"\"\"\n def merge_count_split_inv(arr, temp_ar... | trial_gpt4o_9 | {
"original_instruction": "",
"prompt_id": "00016769",
"row_id": 16769,
"seed_ids": "[6991]"
} | 0.704661 | Taco_16769 | I | [
"count_inversions",
"minimum_adjacent_swaps"
] | 2 | [
[
"minimum_adjacent_swaps",
"count_inversions"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 0d9f75e2a6509d17887fd5a56cfbbb1cef6c00b2 | feb485716aaafd44ec9464b126d2ada119e3917e | |||
v1.0 | instruct | Taco | Taco_16773_I | Violet loves solving complex puzzles using her favorite data structure, the binary tree. One day, while analyzing a specific binary tree, she stumbled upon an interesting challenge. Given a binary tree, determine the sum of all node values that are at even levels in the tree. The root of the tree is considered to be at... | class TreeNode:
def __init__(self, val=0, left=None, right=None):
self.val = val
self.left = left
self.right = right
def build_tree(nodes):
if not nodes or nodes[0] == 'null':
return None
root = TreeNode(int(nodes[0]))
queue = [root]
i = 1
while queue and i < len... | from solution import build_tree, sum_even_levels, process_test_cases
def test_sum_even_levels():
tree_nodes = "1 2 3 null null 4 5".split()
root = build_tree(tree_nodes)
assert sum_even_levels(root) == 10
tree_nodes = "10 20 30 40 50 null null 60".split()
root = build_tree(tree_nodes)
assert s... | [] | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from collections import deque\n\n# Definition for a binary tree node.\nclass TreeNode:\n def __init__(self, x):\n self.val = x\n self.left = None\... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00016773",
"row_id": 16773,
"seed_ids": "[17336]"
} | 0.602783 | Taco_16773 | I | [
"build_tree",
"sum_even_levels",
"process_test_cases",
"main"
] | 4 | [
[
"process_test_cases",
"build_tree"
],
[
"process_test_cases",
"sum_even_levels"
]
] | 2 | [
"process_test_cases"
] | false | [
"TreeNode"
] | true | pytest | true | [] | true | 9d791773db1adb1a550d7949b4f479c744cf2dbf | 9c131fe59926caf727b6947a96ea3a7bbd461993 | |||
v1.0 | instruct | Taco | Taco_16799_I | Write a program that reads a series of queries. Each query consists of two positive integers, n and m, where n < m. The task is to compute the number of prime numbers in the range [n, m] (both inclusive).
For example, given the input values 10 and 20, there are 4 prime numbers in that range: 11, 13, 17, and 19. Thus, ... | def is_prime(num):
if num <= 1:
return False
if num <= 3:
return True
if num % 2 == 0 or num % 3 == 0:
return False
i = 5
while i * i <= num:
if num % i == 0 or num % (i + 2) == 0:
return False
i += 6
return True
def count_primes_in_range(n, m... | from solution import is_prime, count_primes_in_range, process_queries
def test_is_prime():
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(4) == False
assert is_prime(5) == True
assert is_prime(29) == True
assert is_prime(30) == False
assert is_prime(1) == False
as... | [
{
"docstring": null,
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": null,
"function_declaration": "def count_primes_in_range(n, m):",
"function_name": "count_primes_in_range",
"parameter_list": "(n, m)"
},
... | [
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 sieve_of_eratosthenes(max_num):\n prime = [True] * (max_num + 1)\n p = 2\n while p * p <= max_num:\n if prime[p] == True:\n for i in... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00016799",
"row_id": 16799,
"seed_ids": "[16599]"
} | 0.656838 | Taco_16799 | I | [
"is_prime",
"count_primes_in_range",
"process_queries",
"main"
] | 4 | [
[
"count_primes_in_range",
"is_prime"
],
[
"process_queries",
"count_primes_in_range"
]
] | 2 | [
"process_queries"
] | false | [] | false | pytest | true | [] | true | 15b3512938e8a5c9e126ef835c4a58aeeae9a1d2 | 2d64bac56ffa084b1c3be8b55616855545bc39f7 | |||
v1.0 | instruct | Taco | Taco_16801_I | Problem
At Tech Express, there is a need to optimize the delivery routes for its delivery vans. Each city is represented as a node in a graph, and the direct roads between the cities are represented as edges with associated travel time. The goal is to find the shortest travel time required for a delivery van to travel... | import heapq
import sys
def dijkstra(n, edges, start):
graph = {i: [] for i in range(1, n + 1)}
for u, v, w in edges:
graph[u].append((v, w))
graph[v].append((u, w))
distances = {i: sys.maxsize for i in range(1, n + 1)}
distances[start] = 0
priority_queue = [(0, start)]
wh... | def test_shortest_travel_times():
number_of_cities = 6
number_of_roads = 7
central_hub_city = 1
roads = [
(1, 2, 4),
(1, 3, 2),
(2, 3, 5),
(2, 4, 10),
(3, 5, 3),
(5, 4, 4),
(4, 6, 11)
]
target_cities = [4, 5, 6]
assert shortest_travel_t... | [
{
"docstring": null,
"function_declaration": "def dijkstra(n, edges, start):",
"function_name": "dijkstra",
"parameter_list": "(n, edges, start)"
},
{
"docstring": null,
"function_declaration": "def shortest_travel_times(number_of_cities, number_of_roads, central_hub_city, roads, target_... | [
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 shortest_travel_times(num_cities, num_roads, central_hub, roads, targets):\n graph = {i: [] for i in range(1, num_cities + 1)}\n \n fo... | trial_gpt4o_8 | {
"original_instruction": "",
"prompt_id": "00016801",
"row_id": 16801,
"seed_ids": "[1650]"
} | 0.793294 | Taco_16801 | I | [
"dijkstra",
"shortest_travel_times"
] | 2 | [
[
"shortest_travel_times",
"dijkstra"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | f866e53f3b527a74a4d1b2b294e13f479f942a84 | f9f116cc78df3434ee0d236524cce9464d2eec5b | |||
v1.0 | instruct | Taco | Taco_16820_I | In a small city, the traffic lights are controlled by a smart system. There are $n$ intersections in the city, each with its own traffic light. Each traffic light has a cycle time of $c_i$ seconds, which means it takes $c_i$ seconds for the light at the $i$-th intersection to return to green after turning red.
The ci... | import math
def lcm(a, b):
"""
Returns the least common multiple of a and b.
"""
return abs(a * b) // math.gcd(a, b)
def earliest_time_for_lights(n, cycle_times, queries):
results = []
for query in queries:
m = query[0]
intersections = query[1:]
if m == 0:
r... | import pytest
from solution import earliest_time_for_lights
def test_example_case():
n = 5
cycle_times = [4, 6, 8, 12, 15]
queries = [
(2, 1, 2),
(3, 1, 3, 5),
(2, 2, 4)
]
expected = [12, 120, 12]
assert earliest_time_for_lights(n, cycle_times, queries) == expected
def ... | [
{
"docstring": "Returns the least common multiple of a and b.",
"function_declaration": "def lcm(a, b):",
"function_name": "lcm",
"parameter_list": "(a, b)"
},
{
"docstring": null,
"function_declaration": "def earliest_time_for_lights(n, cycle_times, queries):",
"function_name": "ear... | [
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 math import gcd\nfrom functools import reduce\n\ndef lcm(x, y):\n \"\"\"\n Compute the Least Common Multiple of x and y\n \"\"\"\n return (x * y) ... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00016820",
"row_id": 16820,
"seed_ids": "[5333]"
} | 0.697635 | Taco_16820 | I | [
"lcm",
"earliest_time_for_lights"
] | 2 | [
[
"earliest_time_for_lights",
"lcm"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 3dd937ecb9274ed38e999e47782cb5c511a92cb5 | 075d9e47bde39215f397392c9854db7a6b669dea | |||
v1.0 | instruct | Taco | Taco_16853_I | Calculate the Nth Fibonacci number using matrix exponentiation.
Example 1:
Input:
N = 5
Output:
5
Explanation:
The Fibonacci sequence is 0, 1, 1, 2, 3, 5...
So, the 5th Fibonacci number is 5.
Example 2:
Input:
N = 10
Output:
55
Explanation:
The Fibonacci sequence is 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55...
So, the 10th... | def multiply_matrices(mat1, mat2):
"""Multiplies two 2x2 matrices."""
return [
[
mat1[0][0] * mat2[0][0] + mat1[0][1] * mat2[1][0],
mat1[0][0] * mat2[0][1] + mat1[0][1] * mat2[1][1]
],
[
mat1[1][0] * mat2[0][0] + mat1[1][1] * mat2[1][0],
ma... | def test_findNthFibonacci():
assert findNthFibonacci(5) == 5
assert findNthFibonacci(10) == 55
assert findNthFibonacci(1) == 1
assert findNthFibonacci(2) == 1
assert findNthFibonacci(20) == 6765
assert findNthFibonacci(50) == 12586269025
assert findNthFibonacci(0) == 0
def test_large_N():
... | [
{
"docstring": "Multiplies two 2x2 matrices.",
"function_declaration": "def multiply_matrices(mat1, mat2):",
"function_name": "multiply_matrices",
"parameter_list": "(mat1, mat2)"
},
{
"docstring": "Raises the matrix to the power using efficient matrix exponentiation.",
"function_declara... | [
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 matrix_mult(A, B):\n \"\"\"\n Multiplies two 2x2 matrices A and B.\n \"\"\"\n return [\n [A[0][0]*B[0][0] + A[0][1]*B[1][0], A[0][0]*B[0][1]... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00016853",
"row_id": 16853,
"seed_ids": "[24951]"
} | 0.641884 | Taco_16853 | I | [
"multiply_matrices",
"matrix_exponentiation",
"findNthFibonacci"
] | 3 | [
[
"findNthFibonacci",
"matrix_exponentiation"
],
[
"matrix_exponentiation",
"multiply_matrices"
]
] | 2 | [] | false | [] | false | pytest | false | [] | true | a6b4f3e5bafe6fa6cdb999df11e05ae9e5d3776e | 13933e8adba0b2bc28be01aab4acccba99953907 | |||
v1.0 | instruct | Taco | Taco_16896_I | You are given a list of integers. Your task is to transform the list according to the following rules and return the resulting list:
1. If a number is divisible by 3, replace it with "Fizz".
2. If a number is divisible by 5, replace it with "Buzz".
3. If a number is divisible by both 3 and 5, replace it with "FizzBuzz... | 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 transform_list(numbers)... | from solution import transform_list
def test_empty_list():
assert transform_list([]) == []
def test_only_primes():
assert transform_list([2, 3, 5, 7, 11]) == ["Prime", "Fizz", "Buzz", "Prime", "Prime"]
def test_fizz_buzz_fizzbuzz():
assert transform_list([3, 5, 15]) == ["Fizz", "Buzz", "FizzBuzz"]
def t... | [
{
"docstring": "Helper function to check if a number is prime.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Transforms the list according to the given rules.",
"function_declaration": "def transform_list(numbers):",... | [
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 \"\"\"Helper function to check if a number is prime.\"\"\"\n if n <= 1:\n return False\n if n == 2:\n return True\n if... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00016896",
"row_id": 16896,
"seed_ids": "[14990]"
} | 0.599742 | Taco_16896 | I | [
"is_prime",
"transform_list"
] | 2 | [
[
"transform_list",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 159eadd84a20ba2ab797cb2f05780434c79e2bad | 856f7f9ad481de1c3c31f424b498d02242714b66 | |||
v1.0 | instruct | Taco | Taco_16916_I | Sarah has recently started learning about prime numbers. She is given an array of integers and she wants to find the smallest prime number which is bigger than the maximum number in the array. If all elements in the array are negative or the array is empty, return -1.
-----Input-----
The first line of the input conta... | 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 next_prime(n):
candidate = n + 1
w... | from solution import is_prime, next_prime, smallest_prime_bigger_than_max, process_test_cases
def test_is_prime():
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(4) == False
assert is_prime(11) == True
assert is_prime(15) == False
def test_next_prime():
assert next_prime... | [
{
"docstring": null,
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": null,
"function_declaration": "def next_prime(n):",
"function_name": "next_prime",
"parameter_list": "(n)"
},
{
"docstring": null,
"... | [
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 \"\"\" Returns True if n is a prime number, else False \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return True\n ... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00016916",
"row_id": 16916,
"seed_ids": "[9155]"
} | 0.745189 | Taco_16916 | I | [
"is_prime",
"next_prime",
"smallest_prime_bigger_than_max",
"process_test_cases"
] | 4 | [
[
"next_prime",
"is_prime"
],
[
"process_test_cases",
"smallest_prime_bigger_than_max"
],
[
"smallest_prime_bigger_than_max",
"next_prime"
]
] | 3 | [
"process_test_cases"
] | false | [] | false | pytest | true | [] | true | 0b680cbc963e2d887eb76ecef50a33c47200c3ba | 486cd08e18b18aaf7853b16acfbe0f7cd5aaa455 | |||
v1.0 | instruct | Taco | Taco_16933_I | You are given an array of integers. Your task is to find the maximum length of a contiguous subarray, such that the sum of its elements is even.
Input
The first line contains an integer n (1 ≤ n ≤ 300,000) – the number of elements in the array.
The second line contains n integers a1, a2, ..., an (-10^9 ≤ ai ≤ 10^9) –... | def max_length_even_sum_subarray(arr):
"""
This function returns the maximum length of a contiguous subarray
such that the sum of its elements is even.
"""
current_sum = 0
max_length = 0
first_odd_index = -1
for i, num in enumerate(arr):
current_sum += num
if current_su... | import pytest
from solution import max_length_even_sum_subarray, solve
def test_max_length_even_sum_subarray():
assert max_length_even_sum_subarray([1, 2, 3, 4, 5]) == 4
assert max_length_even_sum_subarray([1, 3, 5]) == 2
assert max_length_even_sum_subarray([2, 4, 6, 8]) == 4
assert max_length_even_sum... | [
{
"docstring": "This function returns the maximum length of a contiguous subarray\nsuch that the sum of its elements is even.",
"function_declaration": "def max_length_even_sum_subarray(arr):",
"function_name": "max_length_even_sum_subarray",
"parameter_list": "(arr)"
},
{
"docstring": null,... | [
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 max_even_sum_subarray_length(n, arr):\n \"\"\"\n Returns the maximum length of a contiguous subarray with an even sum.\n \"\"\"\n max_length = 0\n ... | trial_gpt4o_4 | {
"original_instruction": "",
"prompt_id": "00016933",
"row_id": 16933,
"seed_ids": "[16229]"
} | 0.82576 | Taco_16933 | I | [
"max_length_even_sum_subarray",
"solve"
] | 2 | [
[
"solve",
"max_length_even_sum_subarray"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 398205a9265f6df9525493924bce408028ed2ca0 | 590b2347b435476cb5b1c42592c2da5de48c04ba | |||
v1.0 | instruct | Taco | Taco_16951_I | Your task is to generate all possible valid IP addresses from a given string S of digits. The function should output each possible IP address in the standard dot-decimal form. An IP address consists of four octets, and each octet is a number between 0 and 255, inclusive. The octets are separated by periods ('.').
----... | def is_valid_octet(s):
"""
Checks if the provided string is a valid IP address octet.
"""
if s == "" or (len(s) > 1 and s[0] == '0') or int(s) > 255:
return False
return True
def generate_ip_addresses(S):
"""
Generates all possible valid IP addresses from the given string S.
"""... | from solution import is_valid_octet, generate_ip_addresses
def test_is_valid_octet():
assert is_valid_octet("255") == True
assert is_valid_octet("0") == True
assert is_valid_octet("00") == False
assert is_valid_octet("256") == False
assert is_valid_octet("1") == True
assert is_valid_octet("") =... | [
{
"docstring": "Checks if the provided string is a valid IP address octet.",
"function_declaration": "def is_valid_octet(s):",
"function_name": "is_valid_octet",
"parameter_list": "(s)"
},
{
"docstring": "Generates all possible valid IP addresses from the given string S.",
"function_decl... | [
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 valid_ip_addresses(s):\n \"\"\"\n Given a string of digits, returns all valid IP addresses.\n \"\"\"\n def is_valid(segment):\n # Check if t... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00016951",
"row_id": 16951,
"seed_ids": "[168]"
} | 0.569984 | Taco_16951 | I | [
"is_valid_octet",
"generate_ip_addresses",
"print_ip_addresses"
] | 3 | [
[
"generate_ip_addresses",
"is_valid_octet"
],
[
"print_ip_addresses",
"generate_ip_addresses"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 261fdf05d53685659fb1398701b7adf1d84c03c6 | 44ba5b012438a29ab56efa019c773fbf798590c1 | |||
v1.0 | instruct | Taco | Taco_16961_I | Alex works for a company that delivers packages and he's responsible for routing the packages to their destinations. The packages are packed in rectangular boxes with integer dimensions. Each box must fit exactly into another box or itself. A box A can fit into box B if both the length and width of box A are smaller th... | def can_organize_boxes(n, boxes):
"""
Determines if it is possible to organize the boxes in such a way that each box
(except the outermost one) fits into exactly one other box.
Args:
n: int, the number of boxes.
boxes: List of tuples, each containing two integers (length, width) of the boxe... | def test_organize_boxes():
assert organize_boxes("5\n1 2\n2 3\n3 4\n4 5\n5 6") == "YES"
assert organize_boxes("3\n1 5\n2 4\n3 3") == "NO"
assert organize_boxes("1\n10 10") == "YES"
assert organize_boxes("2\n1 1\n1 2") == "YES"
assert organize_boxes("2\n2 3\n1 4") == "NO"
assert organize_boxes("4... | [
{
"docstring": "Determines if it is possible to organize the boxes in such a way that each box\n(except the outermost one) fits into exactly one other box.\n\nArgs:\nn: int, the number of boxes.\nboxes: List of tuples, each containing two integers (length, width) of the boxes.\n\nReturns:\nstr: \"YES\" if it is... | [
1,
0,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def can_organize_boxes(n, boxes):\n \"\"\"\n Determines if it is possible to organize the boxes in such a way that each box\n (except the outermost one) f... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00016961",
"row_id": 16961,
"seed_ids": "[22283]"
} | 0.688459 | Taco_16961 | I | [
"can_organize_boxes",
"organize_boxes"
] | 2 | [
[
"organize_boxes",
"can_organize_boxes"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | d077019acc0992291300da0fd3fcf20b51c67732 | 9e653fd330bc5f53671315f42b1d4640e69df030 | |||
v1.0 | instruct | Taco | Taco_16963_I | A city is developing a new traffic system to manage congestion at its busiest intersections. The plan involves using a system of traffic lights that operate on cycles, and each intersection has a predetermined cycle time. An intersection's cycle time is the total time it takes for the traffic light to complete one full... | from math import gcd
from functools import reduce
def lcm(a, b):
"""
Helper function to return the least common multiple of two integers
"""
return a * b // gcd(a, b)
def find_lcm_of_intersections(cycle_times):
"""
Returns the least amount of time after which all traffic lights will
simul... | from solution import find_lcm_of_intersections
def test_example1():
assert find_lcm_of_intersections([4, 6, 8]) == 24
def test_example2():
assert find_lcm_of_intersections([5, 10]) == 10
def test_single_intersection():
assert find_lcm_of_intersections([7]) == 7
def test_multiple_prime_cycles():
asse... | [
{
"docstring": "Helper function to return the least common multiple of two integers",
"function_declaration": "def lcm(a, b):",
"function_name": "lcm",
"parameter_list": "(a, b)"
},
{
"docstring": "Returns the least amount of time after which all traffic lights will \nsimultaneously show gre... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from math import gcd\nfrom functools import reduce\n\ndef lcm(a, b):\n return a * b // gcd(a, b)\n\ndef find_time_for_green_lights(num_intersections, cycle_time... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00016963",
"row_id": 16963,
"seed_ids": "[12664]"
} | 0.653275 | Taco_16963 | I | [
"lcm",
"find_lcm_of_intersections"
] | 2 | [
[
"find_lcm_of_intersections",
"lcm"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 616546533160501b3dc8a9dc4a9dd3994391a1a1 | 1a2ddc57918d8eb4d7998b335305c898f86c44cf | |||
v1.0 | instruct | Taco | Taco_16974_I | Write a function that takes a list of integers and returns the product of all the prime numbers in the list. If the list contains no prime numbers, return 1.
Rules:
- A prime number is a natural number greater than 1 that has no positive divisors other than 1 and itself.
- Your function should handle a variety of list... | from typing import List
def is_prime(n: int) -> bool:
if n <= 1:
return False
if n == 2:
return True
if n % 2 == 0:
return False
max_divisor = int(n ** 0.5) + 1
for d in range(3, max_divisor, 2):
if n % d == 0:
return False
return True
def prime_prod... | from solution import prime_product
def test_prime_product_with_primes():
assert prime_product([2, 3, 5, 7]) == 210
assert prime_product([11, 13, 17]) == 2431
def test_prime_product_with_no_primes():
assert prime_product([1, 4, 6, 8, 9]) == 1
assert prime_product([0, 1, 15, 16, 18]) == 1
def test_prim... | [
{
"docstring": null,
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": null,
"function_declaration": "def prime_product(lst):",
"function_name": "prime_product",
"parameter_list": "(lst)"
}
] | [
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 typing import List\n\ndef is_prime(n: int) -> bool:\n if n <= 1:\n return False\n if n == 2:\n return True\n if n % 2 == 0:\n re... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00016974",
"row_id": 16974,
"seed_ids": "[14218]"
} | 0.70603 | Taco_16974 | I | [
"is_prime",
"prime_product"
] | 2 | [
[
"prime_product",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 7988e18bbf91e66ecebe7d151becbe89050a1d22 | 98b1dd096acc3a4704243168d719b47c56fdf401 | |||
v1.0 | instruct | Taco | Taco_17039_I | A well-known university is organizing a programming competition, and the organizers have decided they need a method to determine if the contestants' paths through campus meet certain requirements. Each path consists of a series of vertical and horizontal movements specified as up (U), down (D), left (L), or right (R) m... | def is_valid_path(path):
"""
Determines if a path is valid, i.e., it returns to the starting point.
"""
vertical = 0
horizontal = 0
for move in path:
if move == 'U':
vertical += 1
elif move == 'D':
vertical -= 1
elif move == 'L':
horiz... | from solution import is_valid_path, check_paths
def test_is_valid_path():
assert is_valid_path('UDLR') == True
assert is_valid_path('UUDDLLRR') == True
assert is_valid_path('UUDLRR') == False
assert is_valid_path('UU') == False
assert is_valid_path('') == True
def test_check_paths():
paths = [... | [
{
"docstring": "Determines if a path is valid, i.e., it returns to the starting point.",
"function_declaration": "def is_valid_path(path):",
"function_name": "is_valid_path",
"parameter_list": "(path)"
},
{
"docstring": "Checks multiple paths to determine their validity.",
"function_decl... | [
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_path_valid(path):\n \"\"\"\n Determines if the given path returns to the starting point.\n \n A path is valid if the number of 'U's equals the n... | trial_gpt4o_3 | {
"original_instruction": "",
"prompt_id": "00017039",
"row_id": 17039,
"seed_ids": "[23620]"
} | 0.676093 | Taco_17039 | I | [
"is_valid_path",
"check_paths"
] | 2 | [
[
"check_paths",
"is_valid_path"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | bc000aacfb8de1e029b51d7d9ea34932296bf48c | de65f3eeae769184cccaef25cc46fff8708673c9 | |||
v1.0 | instruct | Taco | Taco_17064_I | The task requires you to implement a function to merge two sorted linked lists and return it as a new sorted list. The new list should be made by splicing together the nodes of the first two lists.
Input
The first line contains a single integer T, the number of test cases. The following T sections each contain two li... | class ListNode:
def __init__(self, val=0, next=None):
self.val = val
self.next = next
def mergeTwoLists(l1, l2):
"""
Merges two sorted linked lists l1 and l2 into a single sorted linked list.
Returns the head of the merged linked list.
"""
dummy = ListNode()
current = dummy
... | from solution import merge_sorted_linked_lists
def test_merge_sorted_linked_lists():
assert merge_sorted_linked_lists([([], [0, 1])]) == [[0, 1]]
assert merge_sorted_linked_lists([([1, 3, 5], [2, 4, 6])]) == [[1, 2, 3, 4, 5, 6]]
assert merge_sorted_linked_lists([([0, 5, 9, 11], [2, 3, 7])]) == [[0, 2, 3, 5... | [] | [
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": "class ListNode:\n def __init__(self, val=0, next=None):\n self.val = val\n self.next = next\n\ndef merge_two_sorted_lists(l1, l2):\n dummy = Li... | trial_gpt4o_4 | {
"original_instruction": "",
"prompt_id": "00017064",
"row_id": 17064,
"seed_ids": "[10384]"
} | 0.524893 | Taco_17064 | I | [
"mergeTwoLists",
"list_to_linked_list",
"linked_list_to_list",
"merge_sorted_linked_lists",
"main"
] | 5 | [
[
"merge_sorted_linked_lists",
"linked_list_to_list"
],
[
"merge_sorted_linked_lists",
"list_to_linked_list"
],
[
"merge_sorted_linked_lists",
"mergeTwoLists"
]
] | 3 | [] | false | [
"ListNode"
] | true | pytest | true | [] | true | f13e4201409af349aed6ea9692a1a8f78a888a3f | d57973279cb3802916b28dbeb0b82b0fa9a3d3ca | |||
v1.0 | instruct | Taco | Taco_17101_I | Write a function to identify the next prime number.
Input
The input consists of a single line containing an integer N.
Output
Your function should output the smallest prime number that is greater than N.
Constraints
1 ≤ N ≤ 10^6
SAMPLE INPUT
14
SAMPLE OUTPUT
17 | def is_prime(num):
"""
Helper function to check if num is a prime number.
"""
if num <= 1:
return False
if num <= 3:
return True
if num % 2 == 0 or num % 3 == 0:
return False
i = 5
while (i * i) <= num:
if num % i == 0 or num % (i + 2) == 0:
re... | from solution import next_prime
def test_next_prime_after_14():
assert next_prime(14) == 17
def test_next_prime_after_1():
assert next_prime(1) == 2
def test_next_prime_after_17():
assert next_prime(17) == 19
def test_next_prime_after_10():
assert next_prime(10) == 11
def test_next_prime_large_inpu... | [
{
"docstring": "Helper function to check if num is a prime number.",
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": "Returns the smallest prime number that is greater than N.",
"function_declaration": "def next_prime... | [
1,
0,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(num):\n \"\"\"\n Helper function to check if num is a prime number.\n \"\"\"\n if num <= 1:\n return False\n if num <= 3:\n ... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00017101",
"row_id": 17101,
"seed_ids": "[8612]"
} | 0.66033 | Taco_17101 | I | [
"is_prime",
"next_prime"
] | 2 | [
[
"next_prime",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 9724cfdb8b14432e34692db59d21f120017698c4 | d36926208de24f9b53b1779d29cf3a5fc7dd58ef | |||
v1.0 | instruct | Taco | Taco_17129_I | You are given an MxN matrix where each cell contains a positive integer. Your task is to find the maximum sum of a path from the top left corner to the bottom right corner of the matrix. You can only move either down or right at any point in time.
Input:
- The first line contains an integer T, the number of test cases... | def max_path_sum(matrix):
"""
Calculates the maximum path sum in a given matrix from the top left corner to the bottom right corner moving only right or down.
"""
M = len(matrix)
N = len(matrix[0])
# Initialize dp array with the same dimensions as the matrix
dp = [[0] * N for _ in range(M)]... | import pytest
from solution import max_path_sum, solve, parse_input
def test_max_path_sum():
matrix = [
[1, 2, 3],
[4, 5, 6],
[7, 8, 9]
]
assert max_path_sum(matrix) == 29
matrix = [
[3, 8],
[5, 7]
]
assert max_path_sum(matrix) == 18
def test_solve():
... | [
{
"docstring": "Calculates the maximum path sum in a given matrix from the top left corner to the bottom right corner moving only right or down.",
"function_declaration": "def max_path_sum(matrix):",
"function_name": "max_path_sum",
"parameter_list": "(matrix)"
},
{
"docstring": null,
"f... | [
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_path_sum(matrix):\n \"\"\"\n Calculates the maximum path sum in a given matrix from the top left corner to the bottom right corner moving only right ... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00017129",
"row_id": 17129,
"seed_ids": "[463]"
} | 0.635343 | Taco_17129 | I | [
"max_path_sum",
"solve",
"parse_input"
] | 3 | [
[
"solve",
"max_path_sum"
]
] | 1 | [
"parse_input"
] | false | [] | false | pytest | true | [] | true | 07a722453e3ca6053321e27836f2209729210070 | e6e2fe9d6ee36ac3479bad38a780bd5c732170f7 | |||
v1.0 | instruct | Taco | Taco_17182_I | You are given a binary tree and a target integer value. Write a function to determine if there exists a path from the root to any leaf such that the sum of the values along the path equals the target integer. A leaf is a node with no children.
----- Input -----
The first line of input contains an integer T, denoting ... | from collections import deque, namedtuple
class TreeNode:
def __init__(self, val=0, left=None, right=None):
self.val = val
self.left = left
self.right = right
def build_tree(values):
if not values or values[0] == 'null':
return None
root = TreeNode(int(values[0]))
queue... | def test_case_1():
test_cases = [
(['5', '4', '8', '11', 'null', '13', '4', '7', '2', 'null', 'null', 'null', '1'], 22),
(['1', '2', '3'], 5)
]
expected = [1, 0]
assert path_exists_in_binary_tree(test_cases) == expected
def test_case_all_null():
test_cases = [
(['null'], 0)
... | [] | [
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 has_path_sum_from_root_to_leaf(root, target_sum):\n if not root:\n return False\n\n # If it's a leaf node\n if not root.left and not root.right... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00017182",
"row_id": 17182,
"seed_ids": "[22723]"
} | 0.684168 | Taco_17182 | I | [
"build_tree",
"has_path_sum",
"path_exists_in_binary_tree"
] | 3 | [
[
"path_exists_in_binary_tree",
"build_tree"
],
[
"path_exists_in_binary_tree",
"has_path_sum"
]
] | 2 | [] | false | [
"TreeNode"
] | true | pytest | false | [] | true | 8342f05297564727eba65f1f3d073937cacb5dc1 | a98e83c6ad749c4ff67864db13fb78772e6aaf66 | |||
v1.0 | instruct | Taco | Taco_17187_I | On the xy-plane, Rika is going to navigate through a polygonal maze. The maze has N vertices, defined by their Cartesian coordinates. To get out of the maze, Rika must start from the entrance vertex and travel to the exit vertex. She can move in straight lines from one vertex to any other vertex, but the path must not ... | import math
from heapq import heappop, heappush
def euclidean_distance(p1, p2):
return math.sqrt((p1[0] - p2[0]) ** 2 + (p1[1] - p2[1]) ** 2)
def is_interior(polygon, point):
x, y = point
n = len(polygon)
inside = False
px, py = polygon[0]
for i in range(n + 1):
p_next_x, p_next_y = po... | def test_sample_case():
import sys
from io import StringIO
sys.stdin = StringIO("4\n0 0\n4 0\n4 4\n0 4\n0 0 4 4\n")
solve()
def test_no_route():
import sys
from io import StringIO
sys.stdin = StringIO("4\n0 0\n4 0\n4 4\n0 4\n-1 -1 5 5\n")
solve()
def test_small_polygon():
impor... | [
{
"docstring": null,
"function_declaration": "def euclidean_distance(p1, p2):",
"function_name": "euclidean_distance",
"parameter_list": "(p1, p2)"
},
{
"docstring": null,
"function_declaration": "def is_interior(polygon, point):",
"function_name": "is_interior",
"parameter_list"... | [
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": "import heapq\nimport math\n\ndef distance(p1, p2):\n return math.sqrt((p1[0] - p2[0]) ** 2 + (p1[1] - p2[1]) ** 2)\n\ndef is_inside_polygon(polygon, x, y):\n ... | trial_gpt4o_5 | {
"original_instruction": "",
"prompt_id": "00017187",
"row_id": 17187,
"seed_ids": "[1964]"
} | 0.619185 | Taco_17187 | I | [
"euclidean_distance",
"is_interior",
"dijkstra",
"shortest_route",
"solve"
] | 5 | [
[
"dijkstra",
"euclidean_distance"
],
[
"dijkstra",
"is_interior"
],
[
"shortest_route",
"dijkstra"
],
[
"shortest_route",
"is_interior"
],
[
"solve",
"shortest_route"
]
] | 5 | [] | false | [] | false | pytest | false | [] | true | 6d16a88438a457ac3d14c52837c273501828b098 | a004e0ba9c52a2ba858f635b68a7a8d5ae628858 | |||
v1.0 | instruct | Taco | Taco_17237_I | Clara is organizing a team-building event for her company and she has come up with a unique idea called "Chain Reaction". In this game, each participant is assigned a task to accomplish. Each task will have a list of dependencies, meaning the participant can only perform their task after the participants assigned to th... | def find_order(tasks):
from collections import defaultdict, deque
# Initialize graph and in-degree count
graph = defaultdict(list)
in_degree = defaultdict(int)
for task, dep in tasks.items():
for d in dep:
graph[d].append(task)
in_degree[task] += 1
# Initia... | from solution import task_order
def test_case_1():
input_str = "3\na: b c.\nb: c.\nc: ."
assert task_order(input_str) == "c b a"
def test_case_2():
input_str = "3\na: b.\nb: a.\nc: ."
assert task_order(input_str) == "Cyclic dependency detected."
def test_case_3():
input_str = "1\na: ."
assert... | [
{
"docstring": null,
"function_declaration": "def find_order(tasks):",
"function_name": "find_order",
"parameter_list": "(tasks)"
},
{
"docstring": null,
"function_declaration": "def parse_input(input_str):",
"function_name": "parse_input",
"parameter_list": "(input_str)"
},
... | [
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 find_order(tasks):\n from collections import defaultdict, deque\n\n # Initialize graph and in-degree count\n graph = defaultdict(list)\n in_degree ... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00017237",
"row_id": 17237,
"seed_ids": "[19603]"
} | 0.527253 | Taco_17237 | I | [
"find_order",
"parse_input",
"task_order"
] | 3 | [
[
"task_order",
"find_order"
],
[
"task_order",
"parse_input"
]
] | 2 | [
"parse_input"
] | false | [] | false | pytest | true | [] | true | 75864a427ad0a86d9ecd0fe1b97b550eceebaf7b | f396f5831b11c6350f45ccf5456954d2643bbe61 | |||
v1.0 | instruct | Taco | Taco_17273_I | Given a tree with n nodes and weighted edges, you need to answer several queries. Each query asks you to find the length of the path between two given nodes.
Input:
- The first line contains an integer n (1 ≤ n ≤ 10^5) — the number of nodes in the tree.
- Each of the next n-1 lines contains three integers u, v, and w ... | import sys
import collections
sys.setrecursionlimit(10000000)
def preprocess(tree, n):
"""
Perform BFS to calculate the distance from the root to every other node
and construct parent array for each node to facilitate LCA calculation.
"""
dist = [-1] * (n + 1)
parent = [-1] * (n + 1)
lev... | from solution import solve
def test_case_1():
n = 5
edges = [(1, 2, 3), (1, 3, 2), (3, 4, 4), (3, 5, 1)]
queries = [(1, 4), (2, 5), (4, 5)]
expected = [6, 6, 5]
assert solve(n, edges, queries) == expected
def test_case_2():
n = 3
edges = [(1, 2, 1), (2, 3, 2)]
queries = [(1, 2), (1, 3)... | [
{
"docstring": "Perform BFS to calculate the distance from the root to every other node \nand construct parent array for each node to facilitate LCA calculation.",
"function_declaration": "def preprocess(tree, n):",
"function_name": "preprocess",
"parameter_list": "(tree, n)"
},
{
"docstring... | [
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 sys\nfrom collections import defaultdict, deque\n\nsys.setrecursionlimit(200000)\n\ndef preprocess_tree(n, edges):\n # Create adjacency list for the tree... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00017273",
"row_id": 17273,
"seed_ids": "[3506]"
} | 0.698886 | Taco_17273 | I | [
"preprocess",
"lca",
"find_path_length",
"solve"
] | 4 | [
[
"find_path_length",
"lca"
],
[
"solve",
"find_path_length"
],
[
"solve",
"preprocess"
]
] | 3 | [] | false | [] | false | pytest | true | [] | true | 57e76c9e29289917345f7125011f878a46305b1b | 49fd8cf108735417a4aba9cdc4d2f58ede4fd751 | |||
v1.0 | instruct | Taco | Taco_17287_I | ## Problem Description
Given a binary tree, traverse it level-by-level from left to right and print the nodes of each level in a new line.
A binary tree is represented by a sequence of values where the value `-1` indicates a null child.
### Constraints
* The number of nodes in the binary tree will not exceed 1000.
* ... | from collections import deque
class TreeNode:
def __init__(self, value=0, left=None, right=None):
self.value = value
self.left = left
self.right = right
def build_tree(levels):
"""
Builds a binary tree from a given level-order list.
"""
if not levels or levels[0] == -1:
... | def test_convert_input_to_list():
input_str = "3\n1\n2 3\n4 5 -1 7"
expected_output = [1, 2, 3, 4, 5, -1, 7]
assert convert_input_to_list(input_str) == expected_output
def test_build_tree():
levels = [1, 2, 3, 4, 5, -1, 7]
root = build_tree(levels)
assert root.value == 1
assert root.left.va... | [] | [
0,
0,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from collections import deque\n\nclass TreeNode:\n def __init__(self, value):\n self.val = value\n self.left = None\n self.right = None\n\n... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00017287",
"row_id": 17287,
"seed_ids": "[11050]"
} | 0.654792 | Taco_17287 | I | [
"build_tree",
"level_order_traversal",
"convert_input_to_list",
"print_level_order"
] | 4 | [
[
"print_level_order",
"build_tree"
],
[
"print_level_order",
"convert_input_to_list"
],
[
"print_level_order",
"level_order_traversal"
]
] | 3 | [] | false | [
"TreeNode"
] | true | pytest | false | [] | true | cf6e542ab6c693be83eac74766654a94d7dfaef7 | 6b8161f1dc7378011e95bc8acf00e16bb3041f1f | |||
v1.0 | instruct | Taco | Taco_17307_I | Given an undirected graph with n (1 ≤ n ≤ 200,000) nodes and m (0 ≤ m ≤ 200,000) edges, and q (1 ≤ q ≤ 100,000) queries, answer each query efficiently. The graph is initially empty (contains no edges).
Each query consists of a number ti (ti = 1, 2), which indicates the type of the query, and possibly two numbers ai an... | def find(parent, i):
if parent[i] == i:
return i
else:
parent[i] = find(parent, parent[i])
return parent[i]
def union(parent, rank, x, y):
rootx = find(parent, x)
rooty = find(parent, y)
if rootx != rooty:
if rank[rootx] > rank[rooty]:
parent[rooty] = ro... | def test_process_queries():
assert process_queries(5, [[1, 1, 2], [1, 2, 3], [1, 3, 4], [2, 1, 4], [2, 1, 5], [1, 4, 5], [2, 1, 5]]) == ["YES", "NO", "YES"]
assert process_queries(4, [[2, 1, 2], [1, 1, 2], [2, 1, 2], [1, 2, 3], [2, 1, 3]]) == ["NO", "YES", "YES"]
def test_no_edges():
assert process_queries... | [
{
"docstring": null,
"function_declaration": "def find(parent, i):",
"function_name": "find",
"parameter_list": "(parent, i)"
},
{
"docstring": null,
"function_declaration": "def union(parent, rank, x, y):",
"function_name": "union",
"parameter_list": "(parent, rank, x, y)"
},
... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def find(parent, i):\n if parent[i] == i:\n return i\n else:\n parent[i] = find(parent, parent[i])\n return parent[i]\n\ndef union(paren... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00017307",
"row_id": 17307,
"seed_ids": "[13264]"
} | 0.782949 | Taco_17307 | I | [
"find",
"union",
"process_queries"
] | 3 | [
[
"process_queries",
"find"
],
[
"process_queries",
"union"
],
[
"union",
"find"
]
] | 3 | [
"process_queries"
] | false | [] | false | pytest | false | [] | true | d24c5f9bf879ae6f90eb48e6cc631ff511da7e34 | 1e192952012a8e6b5d1652633df6f7ceb45bd707 | |||
v1.0 | instruct | Taco | Taco_17315_I | Enchanted Forest
In an enchanted forest, there is a special path consisting of several nodes connected with directional edges. Each node contains a unique item, and collecting these items provides magical energy. The forest has a unique property where some nodes have a one-way portal to another node. You can enter and... | def maximum_magical_energy(nodes, energies, edges):
from collections import defaultdict, deque
# Construct the graph
graph = defaultdict(list)
indegree = [0] * nodes
for u, v in edges:
graph[u].append(v)
indegree[v] += 1
# Find all the starting nodes (nodes with indegre... | from solution import enchanted_forest_solution
def test_example_1():
input_str = "4\n10 20 30 40\n4\n0 1\n1 2\n2 3\n0 3"
assert enchanted_forest_solution(input_str) == 100
def test_example_2():
input_str = "5\n2 4 6 8 10\n6\n0 1\n1 2\n2 3\n3 4\n0 3\n1 4"
assert enchanted_forest_solution(input_str) == ... | [
{
"docstring": null,
"function_declaration": "def maximum_magical_energy(nodes, energies, edges):",
"function_name": "maximum_magical_energy",
"parameter_list": "(nodes, energies, edges)"
},
{
"docstring": null,
"function_declaration": "def enchanted_forest_solution(input_str):",
"fu... | [
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 maximum_magical_energy(nodes, energies, edges):\n from collections import defaultdict, deque\n \n # Construct the graph\n graph = defaultdict(list)... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00017315",
"row_id": 17315,
"seed_ids": "[17805]"
} | 0.65786 | Taco_17315 | I | [
"maximum_magical_energy",
"enchanted_forest_solution"
] | 2 | [
[
"enchanted_forest_solution",
"maximum_magical_energy"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | acac65c55992c2e355b9ee2f510495848cfffd14 | 5ae29ca24f123ed9ef885f20adc65731fa59b54b | |||
v1.0 | instruct | Taco | Taco_17370_I | In a kingdom far away, there existed n cities numbered from 1 to n. These cities are connected by m bidirectional roads. The roads are represented as a list of triples (a, b, c), where a and b are the cities connected by the road and c is the cost to travel that road. The kingdom’s king wants to build a new capital cit... | import heapq
import sys
INF = sys.maxsize
def dijkstra(graph, start):
n = len(graph)
dist = [INF] * n
dist[start] = 0
pq = [(0, start)]
while pq:
current_dist, u = heapq.heappop(pq)
if current_dist > dist[u]:
continue
for v, weight in grap... | from solution import find_best_capitals
def test_case_1():
test_cases = [
(3, 3, [(1, 2, 1), (2, 3, 3), (1, 3, 4)])
]
assert find_best_capitals(test_cases) == [2]
def test_case_2():
test_cases = [
(4, 5, [(1, 2, 2), (1, 3, 3), (1, 4, 1), (2, 3, 4), (3, 4, 5)])
]
assert find_bes... | [
{
"docstring": null,
"function_declaration": "def dijkstra(graph, start):",
"function_name": "dijkstra",
"parameter_list": "(graph, start)"
},
{
"docstring": null,
"function_declaration": "def find_minimal_city(n, roads):",
"function_name": "find_minimal_city",
"parameter_list": ... | [
1,
0,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import heapq\nimport sys\n\nINF = sys.maxsize\n\ndef dijkstra(graph, start):\n n = len(graph)\n dist = [INF] * n\n dist[start] = 0\n pq = [(0, start)]\... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00017370",
"row_id": 17370,
"seed_ids": "[4348]"
} | 0.757561 | Taco_17370 | I | [
"dijkstra",
"find_minimal_city",
"find_best_capitals"
] | 3 | [
[
"find_best_capitals",
"find_minimal_city"
],
[
"find_minimal_city",
"dijkstra"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 02751c008460d6640b1362f0fffcfa0b4ed192a2 | 2af5e3c0a040b8c0c5620d990c25148664093d14 | |||
v1.0 | instruct | Taco | Taco_17458_I | Alex is building a complex password validation system for his company's internal applications. A password is considered strong if it meets the following criteria:
1. It has at least 8 characters.
2. It contains both lowercase and uppercase alphabet characters.
3. It has at least one numerical digit.
4. It contains at ... | import re
def check_password_strength(passwords):
results = []
for password in passwords:
if len(password) < 8:
results.append("WEAK")
continue
if not re.search(r'[a-z]', password):
results.append("WEAK")
continue
if not re.search(r'[A-Z]'... | from solution import validate_passwords
def test_all_strong_passwords():
passwords = ["Passw0rd!", "Str0ng#Pass1", "VeryStr0ng!@#"]
assert validate_passwords(3, passwords) == ["STRONG", "STRONG", "STRONG"]
def test_all_weak_passwords():
passwords = ["weak", "password", "12345678"]
assert validate_pass... | [
{
"docstring": null,
"function_declaration": "def check_password_strength(passwords):",
"function_name": "check_password_strength",
"parameter_list": "(passwords)"
},
{
"docstring": null,
"function_declaration": "def validate_passwords(N, passwords):",
"function_name": "validate_pass... | [
0,
1,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import re\n\ndef is_strong_password(password):\n \"\"\"\n Determine if a password is strong based on given criteria.\n \"\"\"\n if len(password) < 8:\n... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00017458",
"row_id": 17458,
"seed_ids": "[8521]"
} | 0.654002 | Taco_17458 | I | [
"check_password_strength",
"validate_passwords"
] | 2 | [
[
"validate_passwords",
"check_password_strength"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | d580a4463c1b2a56b1d5e7f1125935e0999431ae | d876e741ef1b194b6aa76275b20506a2f5af5ff8 | |||
v1.0 | instruct | Taco | Taco_17472_I | A company needs to schedule a set of tasks, some of which must be completed before others start. Each task is labeled with a unique identifier, and there can be dependencies between the tasks. Given a list of task identifiers and a set of dependencies, determine the order in which the tasks should be executed so that a... | from collections import defaultdict, deque
def schedule_tasks(T, D, tasks, dependencies):
# Create graph and indegree dict
graph = defaultdict(list)
indegree = {task: 0 for task in tasks}
# Populate the graph and indegree based on dependencies
for dep in dependencies:
u, v = dep
gr... | from solution import generate_schedule
def test_sample_case():
tasks = ["a", "b", "c", "d", "e", "f"]
dependencies = [("a", "b"), ("a", "c"), ("b", "d"), ("c", "e"), ("d", "f"), ("e", "f")]
assert generate_schedule(6, 6, tasks, dependencies) == "a b c d e f" or generate_schedule(6, 6, tasks, dependencies) ... | [
{
"docstring": null,
"function_declaration": "def schedule_tasks(T, D, tasks, dependencies):",
"function_name": "schedule_tasks",
"parameter_list": "(T, D, tasks, dependencies)"
},
{
"docstring": null,
"function_declaration": "def generate_schedule(T, D, tasks, dependencies):",
"func... | [
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 schedule_tasks(T, D, tasks, dependencies):\n # Create graph and indegree dict\n graph = defaultdict(list)\n... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00017472",
"row_id": 17472,
"seed_ids": "[8487]"
} | 0.542635 | Taco_17472 | I | [
"schedule_tasks",
"generate_schedule"
] | 2 | [
[
"generate_schedule",
"schedule_tasks"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 7ccec7a0ca134d908f6e0068302b21ad01091b3c | ae6b60a16a0b8c2823df2bdd9a619d32a1ca30e5 | |||
v1.0 | instruct | Taco | Taco_17513_I | Sarah is an enthusiastic collector of rare stamps. She has recently acquired a new set and wants to catalog them in a unique way. Instead of sorting them by their year of issue, Sarah decides to organize them by the prime factors of their unique serial number.
Each stamp in Sarah's collection has a unique serial numbe... | def prime_factors(n):
"""
Returns the prime factors of a given number n in ascending order.
"""
if n <= 1:
return []
factors = []
# Check for number of 2s in n
while n % 2 == 0:
factors.append(2)
n //= 2
# Check for odd factors from 3 upwards
factor = 3
... | import pytest
from solution import prime_factors, process_serial_numbers
def test_prime_factors():
assert prime_factors(18) == [2, 3, 3]
assert prime_factors(29) == [29]
assert prime_factors(60) == [2, 2, 3, 5]
assert prime_factors(2) == [2]
assert prime_factors(1) == []
assert prime_factors(15... | [
{
"docstring": "Returns the prime factors of a given number n in ascending order.",
"function_declaration": "def prime_factors(n):",
"function_name": "prime_factors",
"parameter_list": "(n)"
},
{
"docstring": "Processes a list of serial numbers to produce the desired output format.",
"fu... | [
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 prime_factors(n):\n \"\"\"\n Returns the list of prime factors of n in ascending order.\n \"\"\"\n i = 2\n factors = []\n while i * i <= n:\n... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00017513",
"row_id": 17513,
"seed_ids": "[11995]"
} | 0.631507 | Taco_17513 | I | [
"prime_factors",
"process_serial_numbers"
] | 2 | [
[
"process_serial_numbers",
"prime_factors"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 3d7c2e8e813e613644acfc2ab4bf65437a938583 | 8d84d797a0d65597668b491f159d028fdec6b4c1 | |||
v1.0 | instruct | Taco | Taco_17593_I | Given a binary tree, find the sum of all nodes at the K-th level of the tree. Levels are numbered from 0 for the root.
Input:
The first line contains an integer N, the number of nodes in the tree.
The following N lines each contain three values: the value of the node, the value of the left child, and the value of th... | class TreeNode:
def __init__(self, value=0, left=None, right=None):
self.value = value
self.left = left
self.right = right
def build_tree(node_data):
if not node_data:
return None
nodes = {}
for value, left, right in node_data:
if value not in nodes... | from solution import get_sum_of_kth_level
def test_sample_input():
node_data = [
(1, 2, 3),
(2, 4, -1),
(3, -1, 5),
(4, -1, -1),
(5, -1, -1)
]
k = 2
assert get_sum_of_kth_level(node_data, k) == 9
def test_no_nodes():
node_data = []
k = 0
assert get_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": "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 b... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00017593",
"row_id": 17593,
"seed_ids": "[16450]"
} | 0.587124 | Taco_17593 | I | [
"build_tree",
"sum_at_kth_level",
"get_sum_of_kth_level"
] | 3 | [
[
"get_sum_of_kth_level",
"build_tree"
],
[
"get_sum_of_kth_level",
"sum_at_kth_level"
]
] | 2 | [] | false | [
"TreeNode"
] | true | pytest | true | [] | true | 5a3f611f68551b8b8718dd795d819553141e75c7 | e161dba0690c76b471af644c1466a91d5d3ad19c | |||
v1.0 | instruct | Taco | Taco_17597_I | Smith is a software developer working on a new project that requires efficient storage and retrieval of user data. He is considering using various data structures to optimize these operations. To analyze the system performance, Smith needs to calculate the time complexity for different operations on a dynamic array.
A... | def process_operations(operations):
array = []
result = []
for op in operations:
if op.startswith('Insert'):
_, x = op.split()
array.append(int(x))
elif op.startswith('Sum'):
_, k = op.split()
k = int(k)
result.append(sum(array... | from solution import execute_operations
def test_insert_and_sum_operations():
operations = [
"Insert 3",
"Insert 1",
"Sum 1",
"Insert 4",
"Sum 3"
]
result = execute_operations(5, operations)
assert result == [3, 8]
def test_multiple_sums():
operations = [
... | [
{
"docstring": null,
"function_declaration": "def process_operations(operations):",
"function_name": "process_operations",
"parameter_list": "(operations)"
},
{
"docstring": null,
"function_declaration": "def execute_operations(Q, operations):",
"function_name": "execute_operations",... | [
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 dynamic_array_operations(operations):\n \"\"\"\n Processes a list of operations on a dynamic array and returns the results of 'Sum' operations.\n \"\"... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00017597",
"row_id": 17597,
"seed_ids": "[15180]"
} | 0.561141 | Taco_17597 | I | [
"process_operations",
"execute_operations"
] | 2 | [
[
"execute_operations",
"process_operations"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 2787c8fad1b5ace1b8c27f3925941e6f8d0429a1 | 2316dbabc2ab6ab6ea0ab75f936944ac41bddf08 | |||
v1.0 | instruct | Taco | Taco_17604_I | The next prime number
---------------------
Write a function that takes an integer as input and returns the smallest prime number greater than or equal to the input value. The function should handle both positive and negative integers. For negative integers, return the smallest prime number, which is 2.
A prime numbe... | 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 next_prime(n):
if n < 2:
retur... | from solution import next_prime
def test_next_prime_with_positive_numbers():
assert next_prime(12) == 13
assert next_prime(24) == 29
assert next_prime(2) == 2
assert next_prime(17) == 17
assert next_prime(18) == 19
def test_next_prime_with_negative_numbers():
assert next_prime(-5) == 2
ass... | [
{
"docstring": null,
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": null,
"function_declaration": "def next_prime(n):",
"function_name": "next_prime",
"parameter_list": "(n)"
}
] | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(n):\n if n <= 1:\n return False\n if n <= 3:\n return True\n if n % 2 == 0 or n % 3 == 0:\n return False\n i = 5\n ... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00017604",
"row_id": 17604,
"seed_ids": "[17992]"
} | 0.65503 | Taco_17604 | I | [
"is_prime",
"next_prime"
] | 2 | [
[
"next_prime",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 941748084bea97624171c785dacb9f7d0cede400 | baf9b4fd42f4131eda15e484ef7a924d12e04e44 | |||
v1.0 | instruct | Taco | Taco_17624_I | A game development company is working on creating a navigation system for characters in a 2D grid-based environment. The grid consists of cells that can either be walkable or blocked. Each cell in the grid is represented by a value: 1 for walkable and 0 for blocked.
Given the starting coordinates and the target coord... | from collections import deque
def min_steps(grid, start, target):
n, m = len(grid), len(grid[0])
xs, ys = start
xt, yt = target
if grid[xs][ys] == 0 or grid[xt][yt] == 0:
return -1
directions = [(0, 1), (1, 0), (0, -1), (-1, 0)]
queue = deque([(xs, ys, 0)])
visited = set()
visi... | from solution import min_steps_wrapper
def test_basic_case():
input_str = ("5 5\n"
"1 1 1 0 1\n"
"1 0 1 1 1\n"
"1 1 1 0 1\n"
"0 1 0 1 1\n"
"1 1 1 1 1\n"
"0 0\n"
"4 4\n")
assert min_steps_wrapp... | [
{
"docstring": null,
"function_declaration": "def min_steps(grid, start, target):",
"function_name": "min_steps",
"parameter_list": "(grid, start, target)"
},
{
"docstring": null,
"function_declaration": "def parse_input(input_str):",
"function_name": "parse_input",
"parameter_li... | [
1,
0,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from collections import deque\n\ndef min_steps(grid, start, target):\n n, m = len(grid), len(grid[0])\n xs, ys = start\n xt, yt = target\n if grid[xs][... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00017624",
"row_id": 17624,
"seed_ids": "[9344]"
} | 0.78374 | Taco_17624 | I | [
"min_steps",
"parse_input",
"min_steps_wrapper"
] | 3 | [
[
"min_steps_wrapper",
"min_steps"
],
[
"min_steps_wrapper",
"parse_input"
]
] | 2 | [
"parse_input"
] | false | [] | false | pytest | true | [] | true | 2ee7472b02e018e075b8dd798b630266380f59fc | 1dfb59aac344c6ec004915443cdf8d06ceeb59e1 | |||
v1.0 | instruct | Taco | Taco_17637_I | Tree Depth Calculation
You are given a tree with $n$ nodes, numbered from 1 to $n$, and $n-1$ edges, such that the tree is connected. The tree's root is node 1, and you need to find the depth of each node in the tree. In this problem, the depth of a node is the number of edges in the path from the root node to that no... | def find_depths(n, edges):
from collections import deque, defaultdict
# Create an adjacency list
tree = defaultdict(list)
for u, v in edges:
tree[u].append(v)
tree[v].append(u)
# Array to store depth of each node
depth = [-1] * (n + 1)
# Use BFS to find depth o... | from solution import convert_input_and_run
def test_sample_input_1():
n = 5
edges_list = ["1 2", "1 3", "3 4", "3 5"]
expected_output = [0, 1, 1, 2, 2]
assert convert_input_and_run(n, edges_list) == expected_output
def test_sample_input_2():
n = 6
edges_list = ["1 3", "3 2", "1 4", "4 5", "4 6... | [
{
"docstring": null,
"function_declaration": "def find_depths(n, edges):",
"function_name": "find_depths",
"parameter_list": "(n, edges)"
},
{
"docstring": null,
"function_declaration": "def convert_input_and_run(n, edges_list):",
"function_name": "convert_input_and_run",
"parame... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def find_depths(n, edges):\n from collections import deque, defaultdict\n \n # Create an adjacency list\n tree = defaultdict(list)\n for u, v in edg... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00017637",
"row_id": 17637,
"seed_ids": "[19197]"
} | 0.667786 | Taco_17637 | I | [
"find_depths",
"convert_input_and_run"
] | 2 | [
[
"convert_input_and_run",
"find_depths"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 4634f1d8e5676bdbe9485d7a8ecd6174b5f2f26b | a3ade54a5364dfb5afc81903680930a317b45684 | |||
v1.0 | instruct | Taco | Taco_17645_I | Marcus needs to create a safe password for his new portal account. He wants to follow a specific set of rules to ensure the password is both strong and easy to remember. According to the rules, a valid password must meet the following criteria:
- It must be at least 8 characters long.
- It must contain at least one upp... | import re
def is_valid_password(password):
if len(password) < 8:
return "INVALID"
if not re.search(r'[A-Z]', password):
return "INVALID"
if not re.search(r'[a-z]', password):
return "INVALID"
if not re.search(r'[0-9]', password):
return "INVALID"
if re.search(r'[^A-Z... | from solution import is_valid_password, validate_passwords
def test_is_valid_password():
assert is_valid_password("StrongPassw0rd") == "VALID"
assert is_valid_password("weakpass") == "INVALID"
assert is_valid_password("Strong1") == "INVALID"
assert is_valid_password("WayTooLongPasswordWithoutDigit") ==... | [
{
"docstring": null,
"function_declaration": "def is_valid_password(password):",
"function_name": "is_valid_password",
"parameter_list": "(password)"
},
{
"docstring": null,
"function_declaration": "def validate_passwords(passwords):",
"function_name": "validate_passwords",
"para... | [
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 validate_passwords(passwords):\n results = []\n for pwd in passwords:\n if (len(pwd) < 8 or \n not any(char.isupper() for char in pwd) ... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00017645",
"row_id": 17645,
"seed_ids": "[11203]"
} | 0.586275 | Taco_17645 | I | [
"is_valid_password",
"validate_passwords"
] | 2 | [
[
"validate_passwords",
"is_valid_password"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | fa7b6a67d4d580703d8caaa707ac34a015b1f356 | 633189b8e00ff2f2c5a3e18ff8d51d8d7409fa0a | |||
v1.0 | instruct | Taco | Taco_17720_I | In a zoo, every animal has been given an integer ID number. The zookeeper wants to create groups of animals with IDs that are prime numbers. Prime numbers are numbers greater than 1 that have no divisors other than 1 and themselves. Given a list of animal IDs, determine how many unique prime number groups can be formed... | 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 countPrimeGro... | from solution import countPrimeGroups
def test_countPrimeGroups_example1():
assert countPrimeGroups(6, [2, 3, 5, 10, 15, 7]) == 4
def test_countPrimeGroups_example2():
assert countPrimeGroups(5, [4, 6, 8, 10, 12]) == 0
def test_countPrimeGroups_edgecase1():
assert countPrimeGroups(1, [2]) == 1
def test_... | [
{
"docstring": "Helper function to check if a number is prime.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Given a list of animal IDs, return the count of unique prime number groups.",
"function_declaration": "def ... | [
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 if num <= 1:\n return False\n if num == 2:\n return True\n if num % 2 == 0:\n return False\n f... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00017720",
"row_id": 17720,
"seed_ids": "[9167]"
} | 0.580928 | Taco_17720 | I | [
"is_prime",
"countPrimeGroups"
] | 2 | [
[
"countPrimeGroups",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | ca1277393e12440d5c0a2b2988a5fcdeb12a1cdd | b3a4582f0cb5c9ddfd7151e4ebcedcbb73311c50 | |||
v1.0 | instruct | Taco | Taco_17742_I | You are given a positive integer `n`. Your task is to determine the smallest positive integer `x` such that the product of the digits of `x` is equal to `n`.
Example 1:
`
smallest_product_number(12) returns 26`
Explanation:
The product of the digits of 26 is 2 * 6 = 12, and there is no smaller number than 26 whose ... | def smallest_product_number(n):
"""
Finds the smallest positive integer x such that the product of the digits of x is equal to n.
"""
if n == 1:
return 1
# Handle the cases where n is a single digit
if 1 <= n <= 9:
return n
# Start checking from 10 upwards
x = 10
wh... | from solution import smallest_product_number
def test_smallest_product_number_12():
assert smallest_product_number(12) == 26
def test_smallest_product_number_36():
assert smallest_product_number(36) == 49
def test_smallest_product_number_1():
assert smallest_product_number(1) == 1
def test_smallest_prod... | [
{
"docstring": "Finds the smallest positive integer x such that the product of the digits of x is equal to n.",
"function_declaration": "def smallest_product_number(n):",
"function_name": "smallest_product_number",
"parameter_list": "(n)"
},
{
"docstring": "Calculates the product of the digi... | [
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 smallest_product_number(n):\n \"\"\"\n Given a positive integer n, determine the smallest positive integer x \n such that the product of the digits of... | trial_gpt4o_4 | {
"original_instruction": "",
"prompt_id": "00017742",
"row_id": 17742,
"seed_ids": "[13860]"
} | 0.804972 | Taco_17742 | I | [
"smallest_product_number",
"product_of_digits"
] | 2 | [
[
"smallest_product_number",
"product_of_digits"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | ab949276695dc199d7afe4813a59c3a848d4c91c | cbfaaba07a79e0f80371f1fc89d72318dfe66155 | |||
v1.0 | instruct | Taco | Taco_17816_I | Aditya loves numbers and has recently come across an interesting sequence. The sequence starts with a single digit number and the next number is formed by summing the square of the digits of the current number. The sequence continues until it reaches 1 or forms a loop. Aditya wants to know if the sequence for a given n... | def sum_of_squares_of_digits(n):
"""
This function calculates the sum of the squares of the digits of a number.
"""
return sum(int(digit) ** 2 for digit in str(n))
def will_terminate_at_1(n):
"""
This function determines if the sequence starting from n will terminate at 1 or enter a loop.
"... | from solution import sum_of_squares_of_digits, will_terminate_at_1, process_test_cases
def test_sum_of_squares_of_digits():
assert sum_of_squares_of_digits(19) == 82
assert sum_of_squares_of_digits(82) == 68
assert sum_of_squares_of_digits(100) == 1
assert sum_of_squares_of_digits(2) == 4
def test_wil... | [
{
"docstring": "This function calculates the sum of the squares of the digits of a number.",
"function_declaration": "def sum_of_squares_of_digits(n):",
"function_name": "sum_of_squares_of_digits",
"parameter_list": "(n)"
},
{
"docstring": "This function determines if the sequence starting f... | [
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 will_end_at_1(n):\n def get_next_number(num):\n return sum(int(digit) ** 2 for digit in str(num))\n \n seen_numbers = set()\n \n while n ... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00017816",
"row_id": 17816,
"seed_ids": "[11545]"
} | 0.641779 | Taco_17816 | I | [
"sum_of_squares_of_digits",
"will_terminate_at_1",
"process_test_cases"
] | 3 | [
[
"process_test_cases",
"will_terminate_at_1"
],
[
"will_terminate_at_1",
"sum_of_squares_of_digits"
]
] | 2 | [
"process_test_cases"
] | false | [] | false | pytest | true | [] | true | 5ba70e3d6ed402203097512b97898274e5de99c4 | d9d28a7dcdb6d15c5670b7a0bcc33d0d8e010413 | |||
v1.0 | instruct | Taco | Taco_17821_I | Stan and Ollie love playing with numbers. Stan has discovered a way to have fun with numbers by creating a sequence. He starts with an integer $n$ and repeatedly applies a transformation on it. The transformation consists of reversing the digits of $n$, converting it back to an integer, and then adding this reversed nu... | def is_palindrome(number):
"""
Checks if a given number is a palindrome.
"""
return str(number) == str(number)[::-1]
def reverse_number(number):
"""
Reverses the digits of a given number.
"""
return int(str(number)[::-1])
def transformations_to_palindrome(n):
"""
Determines the... | from solution import is_palindrome, reverse_number, transformations_to_palindrome, process_test_cases
def test_is_palindrome():
assert is_palindrome(121) == True
assert is_palindrome(123) == False
assert is_palindrome(1) == True
assert is_palindrome(22) == True
def test_reverse_number():
assert re... | [
{
"docstring": "Checks if a given number is a palindrome.",
"function_declaration": "def is_palindrome(number):",
"function_name": "is_palindrome",
"parameter_list": "(number)"
},
{
"docstring": "Reverses the digits of a given number.",
"function_declaration": "def reverse_number(number)... | [
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(n):\n \"\"\"\n Check if a given number is a palindrome.\n \"\"\"\n return str(n) == str(n)[::-1]\n\ndef reverse_number(n):\n \"\"\... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00017821",
"row_id": 17821,
"seed_ids": "[4393]"
} | 0.685701 | Taco_17821 | I | [
"is_palindrome",
"reverse_number",
"transformations_to_palindrome",
"process_test_cases"
] | 4 | [
[
"process_test_cases",
"transformations_to_palindrome"
],
[
"transformations_to_palindrome",
"is_palindrome"
],
[
"transformations_to_palindrome",
"reverse_number"
]
] | 3 | [
"process_test_cases"
] | false | [] | false | pytest | true | [] | true | 0bb9a9500717f22af695d7c61bfb94fd8a16593d | 3970f14894a52b8c822c6fa8a0683c488e051328 | |||
v1.0 | instruct | Taco | Taco_17831_I | Example
Input
3 2
0 0 1 2
2 3 3 3
1 2
2 3
0 0 0 0
5 5 5 5
Output
Non-intersecting
Intersecting | def orientation(p, q, r):
"""
To find the orientation of the ordered triplet (p, q, r).
The function returns following values
0 --> p, q and r are collinear
1 --> Clockwise
2 --> Counterclockwise
"""
val = (q[1] - p[1]) * (r[0] - q[0]) - (q[0] - p[0]) * (r[1] - q[1])
if val == 0:
... | from solution import check_intersection
def test_non_intersecting():
assert check_intersection([0, 0, 1, 2], [2, 3, 3, 3]) == "Non-intersecting"
def test_intersecting():
assert check_intersection([1, 2, 2, 3], [0, 0, 0, 0]) == "Non-intersecting"
def test_collinear_and_non_intersecting():
assert check_int... | [
{
"docstring": "To find the orientation of the ordered triplet (p, q, r).\nThe function returns following values\n0 --> p, q and r are collinear\n1 --> Clockwise\n2 --> Counterclockwise",
"function_declaration": "def orientation(p, q, r):",
"function_name": "orientation",
"parameter_list": "(p, q, r... | [
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_intersecting(rect1, rect2):\n \"\"\"\n Determine if two rectangles intersect.\n \n rect1 and rect2 are provided as lists [x1, y1, x2, y2]\n w... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00017831",
"row_id": 17831,
"seed_ids": "[8208]"
} | 0.488358 | Taco_17831 | I | [
"orientation",
"on_segment",
"do_intersect",
"check_intersection"
] | 4 | [
[
"check_intersection",
"do_intersect"
],
[
"do_intersect",
"on_segment"
],
[
"do_intersect",
"orientation"
]
] | 3 | [] | false | [] | false | pytest | true | [] | true | 1b0eacf17227c27bfd7aa6d0294db0b2b0e297c9 | 99749b3158df8ad880942d5de4a1a8c3b766b07c | |||
v1.0 | instruct | Taco | Taco_17849_I | Given an array of integers, your task is to rearrange the array such that all the prime numbers appear before all non-prime numbers, while maintaining the relative order among prime and non-prime numbers.
Example 1:
Input:
N = 6
Arr = {4, 7, 6, 5, 8, 3}
Output:
7 5 3 4 6 8
Explanation:
The primes 7 5 3 appear before t... | def is_prime(num):
"""
Helper function to check if a number is prime.
"""
if num <= 1:
return False
if num == 2:
return True
if num % 2 == 0:
return False
p = 3
while p * p <= num:
if num % p == 0:
return False
p += 2
return True
d... | from solution import segregatePrime
def test_example_case_1():
arr = [4, 7, 6, 5, 8, 3]
segregatePrime(len(arr), arr)
assert arr == [7, 5, 3, 4, 6, 8]
def test_example_case_2():
arr = [10, 11, 13, 15, 17]
segregatePrime(len(arr), arr)
assert arr == [11, 13, 17, 10, 15]
def test_single_element... | [
{
"docstring": "Helper function to check if a number is prime.",
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": "Function to segregate prime numbers to the front of the array while maintaining\nthe relative order of prim... | [
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 isqrt\n\ndef is_prime(n):\n if n <= 1:\n return False\n if n <= 3:\n return True\n if n % 2 == 0 or n % 3 == 0:\n re... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00017849",
"row_id": 17849,
"seed_ids": "[25182]"
} | 0.56784 | Taco_17849 | I | [
"is_prime",
"segregatePrime"
] | 2 | [
[
"segregatePrime",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | d745dd10148833980c3a66458235dd869775cd42 | 72d5136b267013107fe3ce4781b2d4b93b731fb7 | |||
v1.0 | instruct | Taco | Taco_17878_I | Kaito is creating a game where you need to invert a binary tree. In a binary tree, each node has at most two children referred to as the left child and the right child. Inverting a binary tree means swapping every left node with its corresponding right node.
Given a binary tree in the form of connected nodes, write a ... | class TreeNode:
def __init__(self, value=0, left=None, right=None):
self.value = value
self.left = left
self.right = right
def build_tree(nodes):
node_dict = {}
for node in nodes:
value = node[0]
if value not in node_dict:
node_dict[value] = TreeNode(valu... | def test_invert_binary_tree():
t = 1
test_cases = [
(7, [
(1, 2, 3),
(2, 4, 5),
(3, 6, 7),
(4, -1, -1),
(5, -1, -1),
(6, -1, -1),
(7, -1, -1)
])
]
expected_output = [
[(1, 3, 2),
(3, 7, 6)... | [] | [
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": "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_2 | {
"original_instruction": "",
"prompt_id": "00017878",
"row_id": 17878,
"seed_ids": "[15373]"
} | 0.5808 | Taco_17878 | I | [
"build_tree",
"invert_tree",
"tree_to_list",
"invert_binary_tree"
] | 4 | [
[
"invert_binary_tree",
"build_tree"
],
[
"invert_binary_tree",
"invert_tree"
],
[
"invert_binary_tree",
"tree_to_list"
]
] | 3 | [] | false | [
"TreeNode"
] | true | pytest | false | [] | true | e251abb670803bb61860bf9c1682ed299452c07d | b9d3a072e906fcb35a141371340a03a2af0592a3 | |||
v1.0 | instruct | Taco | Taco_17926_I | To determine if a point lies inside or outside a given polygon, we can use ray-casting algorithm. A ray is drawn from the point in question to the positive x-direction. If this ray intersects the edges of the polygon an odd number of times, the point is inside the polygon. Otherwise, the point is outside the polygon.
... | def is_point_in_polygon(x, y, vertices):
"""
Determines if the point (x, y) lies inside the given polygon defined by vertices.
Returns True if the point is inside, False otherwise.
"""
n = len(vertices)
inside = False
px, py = vertices[0]
for i in range(n + 1):
sx, sy = vert... | def test_is_point_in_polygon_inside():
vertices = [(0, 0), (0, 4), (4, 4), (4, 0)]
point = (2, 2)
assert is_point_in_polygon(point[0], point[1], vertices) == True
def test_is_point_in_polygon_outside():
vertices = [(0, 0), (0, 4), (4, 4), (4, 0)]
point = (5, 5)
assert is_point_in_polygon(point[... | [
{
"docstring": "Determines if the point (x, y) lies inside the given polygon defined by vertices.\nReturns True if the point is inside, False otherwise.",
"function_declaration": "def is_point_in_polygon(x, y, vertices):",
"function_name": "is_point_in_polygon",
"parameter_list": "(x, y, vertices)"
... | [
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_point_in_polygon(n, vertices, k, points):\n def is_inside(px, py):\n count = 0\n x1, y1 = vertices[0]\n for i in range(1, n + 1):\n ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00017926",
"row_id": 17926,
"seed_ids": "[18213]"
} | 0.541148 | Taco_17926 | I | [
"is_point_in_polygon",
"check_points_in_polygon",
"read_input"
] | 3 | [
[
"check_points_in_polygon",
"is_point_in_polygon"
],
[
"read_input",
"check_points_in_polygon"
]
] | 2 | [
"read_input"
] | false | [] | false | pytest | false | [] | true | 0c510622208dba81477005b1e412273403a58f37 | 0705b56072d6b0afffe8c86013f9bd319205231f | |||
v1.0 | instruct | Taco | Taco_17959_I | Alice loves playing with integers and sequences. She is particularly interested in finding a special type of sub-sequence within a sequence of integers. The special sub-sequence is defined as follows:
1. It must be a contiguous sub-sequence.
2. The sum of the numbers in the sub-sequence must be a prime number.
Alice h... | def is_prime(num):
"""
Checks 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 has_prim... | def test_is_prime():
assert is_prime(2) == True
assert is_prime(5) == True
assert is_prime(11) == True
assert is_prime(10) == False
assert is_prime(21) == False
def test_has_prime_subsequence():
assert has_prime_subsequence([1, 2, 3, 4, 5]) == "YES"
assert has_prime_subsequence([4, 6, 8, 10... | [
{
"docstring": "Checks if a number is a prime number.",
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": "Returns 'YES' if there exists a contiguous sub-sequence with a prime sum, otherwise returns 'NO'",
"function_dec... | [
1,
0,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(num):\n \"\"\"\n Checks if a number is a prime number.\n \"\"\"\n if num <= 1:\n return False\n if num == 2:\n return Tru... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00017959",
"row_id": 17959,
"seed_ids": "[435]"
} | 0.702414 | Taco_17959 | I | [
"is_prime",
"has_prime_subsequence",
"prime_subsequence_tests"
] | 3 | [
[
"has_prime_subsequence",
"is_prime"
],
[
"prime_subsequence_tests",
"has_prime_subsequence"
]
] | 2 | [] | false | [] | false | pytest | false | [] | true | 34037fc381c00e5a31d139b728546a6b02ff6956 | d92d343c07abe1be1905e932c4157bec0dda64ba | |||
v1.0 | instruct | Taco | Taco_18005_I | You are given a list of strings where each string consists of various alphanumeric characters. Your task is to find the number of strings that can be rearranged to form a palindrome.
A palindrome is a string that reads the same forward and backward.
------ Input ------
The first line of input contains an integer N -... | def can_form_palindrome(s):
"""
This function checks if the given string can be rearranged to form a palindrome.
:param s: A string containing alphanumeric characters
:return: Boolean indicating if the string can be rearranged to form a palindrome
"""
from collections import Counter
counts ... | from solution import can_form_palindrome, num_strings_can_form_palindrome
def test_can_form_palindrome():
assert can_form_palindrome("carrace") == True
assert can_form_palindrome("daily") == False
assert can_form_palindrome("aabbaa") == True
assert can_form_palindrome("a") == True
assert can_form_p... | [
{
"docstring": "This function checks if the given string can be rearranged to form a palindrome.\n\n:param s: A string containing alphanumeric characters\n:return: Boolean indicating if the string can be rearranged to form a palindrome",
"function_declaration": "def can_form_palindrome(s):",
"function_n... | [
1,
0,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def can_form_palindrome(s):\n \"\"\"\n This function checks if the given string can be rearranged to form a palindrome.\n\n :param s: A string containing ... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00018005",
"row_id": 18005,
"seed_ids": "[5454]"
} | 0.789744 | Taco_18005 | I | [
"can_form_palindrome",
"num_strings_can_form_palindrome"
] | 2 | [
[
"num_strings_can_form_palindrome",
"can_form_palindrome"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 9fab44ed97965541cb7d3957b816daccc6fd6816 | 488e800e21fd16a45ecc9cde6887e0170cf0fee0 | |||
v1.0 | instruct | Taco | Taco_18013_I | Nephren and the little leprechauns are playing a new game with palindromes.
A string is called a palindrome if it reads the same backward as forward, ignoring spaces. For example, "aba", "a man a plan a canal panama", and "racecar" are palindromes.
Given a string s, determine whether it is a palindrome or not. Additi... | def is_palindrome(s: str) -> bool:
s = ''.join(s.split()) # remove spaces
return s == s[::-1]
def min_remove_to_palindrome(s: str) -> int:
s = ''.join(s.split()) # remove spaces
n = len(s)
dp = [[0] * n for _ in range(n)]
for length in range(2, n + 1):
for i in range(n - length +... | from solution import check_strings
def test_check_strings():
assert check_strings(3, ["racecar", "a man a plan a canal panama", "abca"]) == ["YES 0", "YES 0", "NO 1"]
assert check_strings(1, ["aabba"]) == ["NO 1"]
assert check_strings(2, ["abc", "abba"]) == ["NO 2", "YES 0"]
assert check_strings(1, ["a... | [
{
"docstring": null,
"function_declaration": "def is_palindrome(s):",
"function_name": "is_palindrome",
"parameter_list": "(s)"
},
{
"docstring": null,
"function_declaration": "def min_remove_to_palindrome(s):",
"function_name": "min_remove_to_palindrome",
"parameter_list": "(s)"... | [
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_palindrome(s):\n \"\"\"\n Determines if the given string s is a palindrome ignoring spaces.\n \"\"\"\n s_filtered = \"\".join(s.split())\n re... | trial_gpt4o_7 | {
"original_instruction": "",
"prompt_id": "00018013",
"row_id": 18013,
"seed_ids": "[25037]"
} | 0.747927 | Taco_18013 | I | [
"is_palindrome",
"min_remove_to_palindrome",
"check_strings"
] | 3 | [
[
"check_strings",
"is_palindrome"
],
[
"check_strings",
"min_remove_to_palindrome"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | efdf533a40015180d1b6850102c09a4b4d33f75b | 5ba4234c4ed54403bad19c572626cccf29e150f2 | |||
v1.0 | instruct | Taco | Taco_18020_I | You are tasked with developing a system to help a logistics company optimize their delivery routes. The company delivers parcels between various locations, and you need to determine the shortest possible route that a delivery person can take to cover all locations exactly once and return to the starting point. This pro... | import itertools
import math
def calculate_distance(p1, p2):
return math.sqrt((p1[0] - p2[0])**2 + (p1[1] - p2[1])**2)
def tsp_shortest_path(n, coordinates):
all_permutations = itertools.permutations(range(1, n))
min_distance = float('inf')
for perm in all_permutations:
current_distance = 0
... | from solution import tsp_shortest_path
def test_tsp_example():
n = 4
coordinates = [(0, 0), (0, 1), (1, 0), (1, 1)]
assert tsp_shortest_path(n, coordinates) == 4
def test_tsp_two_points():
n = 2
coordinates = [(0, 0), (3, 4)]
assert tsp_shortest_path(n, coordinates) == 10 # As round trip 5+5 ... | [
{
"docstring": null,
"function_declaration": "def calculate_distance(p1, p2):",
"function_name": "calculate_distance",
"parameter_list": "(p1, p2)"
},
{
"docstring": null,
"function_declaration": "def tsp_shortest_path(n, coordinates):",
"function_name": "tsp_shortest_path",
"par... | [
0,
0,
0,
0,
0,
1,
0,
0,
0,
1
] | 2 | hard | 0.2 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import itertools\nimport math\n\ndef tsp_shortest_route(num_locations, locations):\n def distance(p1, p2):\n return math.sqrt((p1[0] - p2[0]) ** 2 + (p1[... | trial_gpt4o_5 | {
"original_instruction": "",
"prompt_id": "00018020",
"row_id": 18020,
"seed_ids": "[10492]"
} | 0.68307 | Taco_18020 | I | [
"calculate_distance",
"tsp_shortest_path"
] | 2 | [
[
"tsp_shortest_path",
"calculate_distance"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 04f908d6c4d68618267aac4735d25dc67e4cd606 | 2f76b2aad0d463cd378169133470e15af8af9b2a | |||
v1.0 | instruct | Taco | Taco_18024_I | You are given a tree which is an acyclic connected graph. The vertices are enumerated from 1 to n. Your task is to find the diameter of the tree, which is defined as the longest shortest path between any two vertices in the tree.
Input
The first line contains an integer n (2 ≤ n ≤ 100000), where n is the number of ve... | from collections import deque
def bfs_farthest_node(start, n, adj_list):
distances = [-1] * (n + 1)
queue = deque([start])
distances[start] = 0
farthest_node = start
while queue:
current = queue.popleft()
for neighbor in adj_list[current]:
if distances[neighbor] == ... | import pytest
from solution import tree_diameter
def test_tree_diameter_case1():
n = 5
edges = [(1, 2), (2, 3), (3, 4), (4, 5)]
assert tree_diameter(n, edges) == 4
def test_tree_diameter_case2():
n = 7
edges = [(1, 2), (1, 3), (2, 4), (2, 5), (3, 6), (3, 7)]
assert tree_diameter(n, edges) == 4... | [
{
"docstring": null,
"function_declaration": "def bfs_farthest_node(start, n, adj_list):",
"function_name": "bfs_farthest_node",
"parameter_list": "(start, n, adj_list)"
},
{
"docstring": null,
"function_declaration": "def tree_diameter(n, edges):",
"function_name": "tree_diameter",
... | [
1,
0,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from collections import deque\n\ndef bfs_farthest_node(start, n, adj_list):\n distances = [-1] * (n + 1)\n queue = deque([start])\n distances[start] = 0\n... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00018024",
"row_id": 18024,
"seed_ids": "[10430]"
} | 0.681054 | Taco_18024 | I | [
"bfs_farthest_node",
"tree_diameter"
] | 2 | [
[
"tree_diameter",
"bfs_farthest_node"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 40a034721863efd7aa8c00a5590e6175007534fc | 107e3675155a6a9dc268001de7fc5135c56d63f3 | |||
v1.0 | instruct | Taco | Taco_18036_I | A company is organizing a conference, and each session of the conference must be assigned to one of the several available rooms. The sessions have specific starting and ending times, and a session cannot overlap with any other session assigned to the same room. Your task is to determine the minimum number of rooms requ... | def parse_time(t):
"""
Parse a time string in HH:MM format into minutes since midnight.
"""
hours, minutes = map(int, t.split(':'))
return hours * 60 + minutes
def min_rooms_required(sessions):
"""
Given a list of sessions with start and end times, determine the minimum number of rooms requ... | from solution import conference_room_scheduler
def test_conference_room_scheduler():
# Test case 1: All sessions can be fit into 2 rooms
test_cases = [
[
("09:00", "10:00"),
("09:30", "10:30"),
("10:00", "11:00"),
("10:30", "11:30")
],
[
... | [
{
"docstring": "Parse a time string in HH:MM format into minutes since midnight.",
"function_declaration": "def parse_time(t):",
"function_name": "parse_time",
"parameter_list": "(t)"
},
{
"docstring": "Given a list of sessions with start and end times, determine the minimum number of rooms ... | [
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 heapq import heappush, heappop\nfrom datetime import datetime\n\ndef min_rooms_required(test_cases):\n def time_to_minutes(t):\n return int(t[:2]) *... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00018036",
"row_id": 18036,
"seed_ids": "[2674]"
} | 0.697085 | Taco_18036 | I | [
"parse_time",
"min_rooms_required",
"conference_room_scheduler"
] | 3 | [
[
"conference_room_scheduler",
"min_rooms_required"
],
[
"min_rooms_required",
"parse_time"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | bd38d258c96f86a3dc37135f4ab84d3dd208fbe2 | 69f89e5ce9329ee0c237660be1b252e02fcb96e4 | |||
v1.0 | instruct | Taco | Taco_18064_I | A famous problem is to find the largest rectangle that can be formed within a histogram. A histogram is a representation of data where each bar denotes the frequency (or count) of data points corresponding to that bar. Given the heights of the bars, the task is to determine the area of the largest rectangle that can be... | def largest_rectangle_area(heights):
"""
Calculate the largest rectangle area in a histogram given by heights.
"""
stack = []
max_area = 0
index = 0
while index < len(heights):
if not stack or heights[stack[-1]] <= heights[index]:
stack.append(index)
inde... | from solution import largest_rectangle_histogram
def test_case_1():
test_input = [
(5, [2, 1, 5, 6, 2, 3]),
]
assert largest_rectangle_histogram(1, test_input) == [10]
def test_case_2():
test_input = [
(7, [6, 2, 5, 4, 5, 1, 6]),
]
assert largest_rectangle_histogram(1, test_inp... | [
{
"docstring": "Calculate the largest rectangle area in a histogram given by heights.",
"function_declaration": "def largest_rectangle_area(heights):",
"function_name": "largest_rectangle_area",
"parameter_list": "(heights)"
},
{
"docstring": null,
"function_declaration": "def process_hi... | [
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_rectangle_area(heights):\n \"\"\"\n Function to calculate the largest rectangle area in a histogram.\n \"\"\"\n stack = []\n max_area = ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00018064",
"row_id": 18064,
"seed_ids": "[9427]"
} | 0.636818 | Taco_18064 | I | [
"largest_rectangle_area",
"process_histograms",
"largest_rectangle_histogram"
] | 3 | [
[
"largest_rectangle_histogram",
"process_histograms"
],
[
"process_histograms",
"largest_rectangle_area"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 3820a7cf52b4820942dfc8a3ed56dfd667eab62a | b1f1c11f517b82659addb4cc6f8816702ffd4c72 | |||
v1.0 | instruct | Taco | Taco_18068_I | Alice is intrigued by triangular numbers and their interesting properties. A number T is called triangular if it can be expressed as T = n * (n + 1) / 2 for some positive integer n. For instance, 1, 3, 6, 10 are the first few triangular numbers.
Alice wants to find out how many triangular numbers exist in a given rang... | import math
def is_triangular_number(t):
"""
Check if a number t is a triangular number.
"""
if t < 1:
return False
n = (-1 + math.sqrt(1 + 8 * t)) / 2
return n.is_integer()
def find_triangular_count(X, Y):
"""
Returns the count of triangular numbers within the range [X, Y].
... | from solution import is_triangular_number, find_triangular_count, process_test_cases
def test_is_triangular_number():
assert is_triangular_number(1) == True
assert is_triangular_number(3) == True
assert is_triangular_number(6) == True
assert is_triangular_number(10) == True
assert is_triangular_num... | [
{
"docstring": "Check if a number t is a triangular number.",
"function_declaration": "def is_triangular_number(t):",
"function_name": "is_triangular_number",
"parameter_list": "(t)"
},
{
"docstring": "Returns the count of triangular numbers within the range [X, Y].",
"function_declarati... | [
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_triangular_numbers_in_range(X, Y):\n def is_triangular(num):\n if num < 1:\n return False\n # We solve the qua... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00018068",
"row_id": 18068,
"seed_ids": "[7224]"
} | 0.615433 | Taco_18068 | I | [
"is_triangular_number",
"find_triangular_count",
"process_test_cases",
"main"
] | 4 | [
[
"find_triangular_count",
"is_triangular_number"
],
[
"process_test_cases",
"find_triangular_count"
]
] | 2 | [
"process_test_cases"
] | false | [] | false | pytest | true | [] | true | a91b1db49e0f8c60eec25ea9851c12e6819e4fad | 6ddfdd6f5224d1cf205ce00d14df8653067384d0 | |||
v1.0 | instruct | Taco | Taco_18111_I | A group of researchers is investigating a rectangular field divided into M x N plots. Each plot has a specific fertility value — a non-negative integer. The researchers want to plant certain crops that require a high and balanced fertility value across specific regions of the field. To do this, they need to calculate t... | def average_fertility(field, queries):
M, N = len(field), len(field[0])
results = []
for query in queries:
x1, y1, x2, y2 = query
total_sum = 0
count = 0
# Iterate through the sub-rectangle from (x1, y1) to (x2, y2)
for i in range(x1 - 1, x2):
... | def test_average_fertility_case1():
input_str = """3 3
1 2 3
4 5 6
7 8 9
2
1 1 2 2
2 2 3 3"""
expected_output = [3, 7]
assert analyze_field(input_str) == expected_output
def test_average_fertility_single_cell():
input_str = """2 2
5 5
5 5
1
1 1 1 1"""
expected_output = [5]
assert analyze_field(... | [
{
"docstring": null,
"function_declaration": "def average_fertility(field, queries):",
"function_name": "average_fertility",
"parameter_list": "(field, queries)"
},
{
"docstring": null,
"function_declaration": "def parse_input(input_str):",
"function_name": "parse_input",
"parame... | [
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 calculate_average_fertility(M, N, field, queries):\n results = []\n \n for x1, y1, x2, y2 in queries:\n total_fertility = 0\n num_plots ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00018111",
"row_id": 18111,
"seed_ids": "[8633]"
} | 0.561735 | Taco_18111 | I | [
"average_fertility",
"parse_input",
"analyze_field"
] | 3 | [
[
"analyze_field",
"average_fertility"
],
[
"analyze_field",
"parse_input"
]
] | 2 | [
"parse_input"
] | false | [] | false | pytest | false | [] | true | 7e153dc2512895fc902f4fc661f859808873d74a | 64593a1c87953991dce63c9b35915617ce3c7d9f | |||
v1.0 | instruct | Taco | Taco_18113_I | You are given a sequence of integers and are required to find a subsequence such that the sum of the subsequence is a prime number. A subsequence is derived by deleting some or none of the elements from the sequence without changing the order of the remaining elements.
Input:
The input consists of multiple test cases.... | def is_prime(num):
"""
Determine if a number is prime.
"""
if num <= 1:
return False
if num == 2:
return True
if num % 2 == 0:
return False
for i in range(3, int(num**0.5) + 1, 2):
if num % i == 0:
return False
return True
def find_prime_subse... | def test_is_prime():
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(4) == False
assert is_prime(5) == True
assert is_prime(1) == False
assert is_prime(0) == False
assert is_prime(-3) == False
assert is_prime(11) == True
def test_find_prime_subsequence():
t = 3... | [
{
"docstring": "Determine if a number is prime.",
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": "Returns the result for each test case whether a subsequence with a prime sum exists,\nand the indices of one such subseque... | [
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": "from itertools import combinations\n\ndef is_prime(num):\n \"\"\"Helper function to check if a number is prime.\"\"\"\n if num <= 1:\n return False\n ... | trial_gpt4o_5 | {
"original_instruction": "",
"prompt_id": "00018113",
"row_id": 18113,
"seed_ids": "[7837]"
} | 0.698442 | Taco_18113 | I | [
"is_prime",
"find_prime_subsequence"
] | 2 | [
[
"find_prime_subsequence",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | d3270182f161d374d8209255fc2debb3fb9cdc1b | 359122b2b3d4c9a68fcaa5baf6a229283682e941 | |||
v1.0 | instruct | Taco | Taco_18118_I | Write a function that takes in a list of integers and returns a new list which contains only the primes from the original list. If there are no prime numbers in the input list, return an empty list.
A prime number is a number greater than 1 that has no divisors other than 1 and itself.
For example:
extract_prime... | def is_prime(n):
"""
Returns True if n is a prime number, otherwise False.
"""
if n <= 1:
return False
if n == 2:
return True
if n % 2 == 0:
return False
for i in range(3, int(n**0.5) + 1, 2):
if n % i == 0:
return False
return True
def extrac... | from solution import extract_primes, is_prime
def test_is_prime():
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(4) == False
assert is_prime(5) == True
assert is_prime(10) == False
assert is_prime(17) == True
def test_extract_primes():
assert extract_primes([10, 15,... | [
{
"docstring": "Returns True if n is a prime number, otherwise False.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Takes in a list of integers and returns a new list which contains only the primes from the original list... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(n):\n \"\"\"\n Helper function to check if a number is prime.\n \"\"\"\n if n <= 1:\n return False\n if n == 2:\n return ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00018118",
"row_id": 18118,
"seed_ids": "[21439]"
} | 0.664412 | Taco_18118 | I | [
"is_prime",
"extract_primes"
] | 2 | [
[
"extract_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 5aeec6d2226b5f4afd6b2854c77511e84556052f | 03b3340b72002c0c7d728b16880dd9daa88b5a9e | |||
v1.0 | instruct | Taco | Taco_18166_I | A famous programming competition consists of several rounds, each requiring solving a unique problem. One of the challenges is to redesign a given matrix according to a specific pattern. The goal of this task is to rearrange a given NxN matrix according to the following rules:
1. Rotate the matrix 90 degrees clockwise... | def rotate_and_reflect_matrix(T, matrices):
def rotate_90_clockwise(matrix):
N = len(matrix)
return [[matrix[N - j - 1][i] for j in range(N)] for i in range(N)]
results = []
for matrix in matrices:
rotated_matrix = rotate_90_clockwise(matrix)
results.append(rotated_matri... | def test_rotate_3x3_matrix():
input_matrix = [
[1, 2, 3],
[4, 5, 6],
[7, 8, 9]
]
expected_output = [
[7, 4, 1],
[8, 5, 2],
[9, 6, 3]
]
assert rotate_and_reflect_matrix(1, [input_matrix]) == [expected_output]
def test_rotate_4x4_matrix():
input_mat... | [
{
"docstring": null,
"function_declaration": "def rotate_and_reflect_matrix(T, matrices):",
"function_name": "rotate_and_reflect_matrix",
"parameter_list": "(T, matrices)"
},
{
"docstring": null,
"function_declaration": "def restructured_matrix(T, matrices):",
"function_name": "restr... | [
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 transform(matrix):\n \"\"\"\n Transforms the given NxN matrix by rotating it 90 degrees clockwise\n and then reflecting it along its main diagonal.\n ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00018166",
"row_id": 18166,
"seed_ids": "[3317]"
} | 0.617603 | Taco_18166 | I | [
"rotate_and_reflect_matrix",
"restructured_matrix"
] | 2 | [
[
"restructured_matrix",
"rotate_and_reflect_matrix"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | 5c4f818f771240b0691aabc2d6899774c8ca6840 | 52590a554015f1b97c4d47fcde87c8d1423cca12 | |||
v1.0 | instruct | Taco | Taco_18196_I | You are given an empty grid of size n x n and a list of k operations. Each operation is represented as a tuple (i, j, c) where i and j are the row and column indices (1-indexed) and c is a character. For each operation, you need to place the character c in the cell located at the i-th row and j-th column of the grid. I... | def apply_operations(n, k, operations):
"""
This function applies a list of k operations to an n x n grid and returns the final state of the grid.
Args:
n (int): The size of the grid (n x n).
k (int): The number of operations.
operations (list of tuples): Each tuple contains (i, j, c) which... | from solution import apply_operations, grid_after_operations
def test_apply_operations_example_1():
n, k = 3, 4
operations = [(1, 1, 'a'), (2, 2, 'b'), (3, 3, 'c'), (3, 1, 'd')]
assert apply_operations(n, k, operations) == ["a..", ".b.", "d.c"]
def test_apply_operations_example_2():
n, k = 2, 3
op... | [
{
"docstring": "This function applies a list of k operations to an n x n grid and returns the final state of the grid.\n\nArgs:\nn (int): The size of the grid (n x n).\nk (int): The number of operations.\noperations (list of tuples): Each tuple contains (i, j, c) which indicates\n pl... | [
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 update_grid(n, k, operations):\n grid = [['.' for _ in range(n)] for _ in range(n)]\n \n for i, j, c in operations:\n grid[i-1][j-1] = c\n\n ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00018196",
"row_id": 18196,
"seed_ids": "[23528]"
} | 0.755147 | Taco_18196 | I | [
"apply_operations",
"grid_after_operations"
] | 2 | [
[
"grid_after_operations",
"apply_operations"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 40c8ccecb4875c887ed2d74da06c4303ddb777e5 | 3543104c33ba61c365e22925aa6b60d3f3cfc0cb | |||
v1.0 | instruct | Taco | Taco_18228_I | Given a binary tree, you need to find the second smallest element in the tree. The tree contains unique values in its nodes.
### Input Format
- The first line of input contains a single integer T, the number of test cases.
- The following lines contain the description of each test case. For each test case:
- The fi... | class TreeNode:
def __init__(self, val=0, left=None, right=None):
self.val = val
self.left = left
self.right = right
def find_second_minimum_value(root: TreeNode) -> int:
def in_order_traversal(node):
if not node:
return []
return in_order_traversal(node.left... | from solution import second_smallest_in_binary_tree
def test_case_1():
T = 1
test_cases = [
(5, [5, 3, 1, 7, 2], [(5, 3), (5, 7), (3, 1), (3, 2)])
]
output = second_smallest_in_binary_tree(T, test_cases)
assert output == [2]
def test_case_2():
T = 1
test_cases = [
(2, [10, ... | [] | [
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):\n self.value = value\n self.children = []\n\ndef find_second_minimum(tree_nodes):\n if len(tree_no... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00018228",
"row_id": 18228,
"seed_ids": "[13750]"
} | 0.685267 | Taco_18228 | I | [
"find_second_minimum_value",
"build_tree_from_edges",
"second_smallest_in_binary_tree"
] | 3 | [
[
"second_smallest_in_binary_tree",
"build_tree_from_edges"
],
[
"second_smallest_in_binary_tree",
"find_second_minimum_value"
]
] | 2 | [] | false | [
"TreeNode"
] | true | pytest | true | [] | true | 06a76393f189379a7038a0d10b72e0dd3a1d90cd | 5dd18212f484b82ffa0028c8bd7307ba1f15b641 | |||
v1.0 | instruct | Taco | Taco_18284_I | A busy architect, Polygono, is planning the layout of a new city called Geoville. Geoville will have n buildings, all of which are at integer coordinates in a 2D plane. Polygono wants to design the layout in such a way that the distance between the furthest pair of buildings is minimized. The distance between two build... | import math
def calculate_distance(x1, y1, x2, y2):
return math.sqrt((x2 - x1) ** 2 + (y2 - y1) ** 2)
def minimize_max_distance_buildings(buildings):
n = len(buildings)
if n == 2:
# If there are only 2 buildings, they must be kept as is
return buildings
# Sort coordinates by eithe... | from solution import main
def test_case_1():
input_data = "3\n1 2\n3 4\n-1 -1"
output_data = main(input_data).strip().split('\n')
assert len(output_data) == 3
assert output_data[0] == "2"
def test_case_2():
input_data = "4\n0 0\n1 1\n2 2\n3 3"
output_data = main(input_data).strip().split('\n')... | [
{
"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 minimize_max_distance_buildings(buildings):",
"function_name": "min... | [
1,
1,
0
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import math\n\ndef distance(p1, p2):\n return math.sqrt((p1[0] - p2[0]) ** 2 + (p1[1] - p2[1]) ** 2)\n\ndef find_max_buildings(n, buildings):\n max_possible_... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00018284",
"row_id": 18284,
"seed_ids": "[1422]"
} | 0.684727 | Taco_18284 | I | [
"calculate_distance",
"minimize_max_distance_buildings",
"main"
] | 3 | [
[
"minimize_max_distance_buildings",
"calculate_distance"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 3c99fc61843914199afeaae61bcf4fbb815aab1d | 68be4f4c7bbe84a0723c9071d2b753dc2efc0e2c | |||
v1.0 | instruct | Taco | Taco_18349_I | ### Problem
You are given a grid with `R` rows and `C` columns. Each cell in the grid has a value which can be either 1 or 0. The objective is to perform the following operation for exactly `N` times:
- Choose a cell with value 1.
- The chosen cell and all cells connected directly or indirectly to it (orthogonally) ch... | def count_connected_groups(grid, r, c):
visited = [[False] * c for _ in range(r)]
def dfs(x, y):
stack = [(x, y)]
while stack:
i, j = stack.pop()
for ni, nj in [(i-1, j), (i+1, j), (i, j-1), (i, j+1)]:
if 0 <= ni < r and 0 <= nj < c and not visited[ni... | def test_count_connected_groups():
grid1 = [
[0, 1, 0, 0],
[0, 1, 1, 0],
[0, 0, 0, 0]
]
assert count_connected_groups(grid1, 3, 4) == 1
grid2 = [
[1, 1, 0],
[0, 1, 1],
[0, 0, 1]
]
assert count_connected_groups(grid2, 3, 3) == 1
grid3 ... | [
{
"docstring": null,
"function_declaration": "def count_connected_groups(grid, r, c):",
"function_name": "count_connected_groups",
"parameter_list": "(grid, r, c)"
},
{
"docstring": null,
"function_declaration": "def remaining_ones_after_operations(grid, r, c, n):",
"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": "def number_of_1s_after_operations(T, test_cases):\n def dfs(grid, visited, i, j, R, C):\n # Stack based DFS for finding all connected 1s\n stack =... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00018349",
"row_id": 18349,
"seed_ids": "[23047]"
} | 0.740729 | Taco_18349 | I | [
"count_connected_groups",
"remaining_ones_after_operations",
"solve"
] | 3 | [
[
"remaining_ones_after_operations",
"count_connected_groups"
],
[
"solve",
"remaining_ones_after_operations"
]
] | 2 | [] | false | [] | false | pytest | false | [] | true | cf630eb619bf3bb515447c6990619fa68e3864ad | c17f52fda8b7a73f1143104b8a06b019202f5754 | |||
v1.0 | instruct | Taco | Taco_18352_I | A company specializing in event management has decided to improve its tracking of participant registration for their numerous events. They keep a record of unique event IDs (event_id) and the number of participants (num_participants) registered for each event.
To facilitate their planning, they want to identify 'speci... | def is_prime(num):
"""
Determine if a number is prime.
"""
if num < 2:
return False
if num == 2:
return True
if num % 2 == 0:
return False
for i in range(3, int(num**0.5) + 1, 2):
if num % i == 0:
return False
return True
def find_special_even... | from solution import find_special_events
def test_no_special_events():
events = [(1001, 10), (1002, 15), (1003, 20)]
assert find_special_events(3, events) == ["None"]
def test_some_special_events():
events = [(1001, 20), (1002, 31), (1003, 12), (1004, 17), (1005, 18)]
assert find_special_events(5, eve... | [
{
"docstring": "Determine if a number is prime.",
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": "Find special events whose number of participants is a prime number.\n\nArgs:\n- n (int): Number of events.\n- events (list... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(num):\n if num <= 1:\n return False\n if num <= 3:\n return True\n if num % 2 == 0 or num % 3 == 0:\n return False\n ... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00018352",
"row_id": 18352,
"seed_ids": "[8888]"
} | 0.622759 | Taco_18352 | I | [
"is_prime",
"find_special_events"
] | 2 | [
[
"find_special_events",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 6e744edf98de8c04c3987dece2ac0e54f4eaba86 | 5f43d77e7304059db33b170369db1d7729a9c06f | |||
v1.0 | instruct | Taco | Taco_18377_I | Write a program to read two numbers $A$ and $B$ and print the number of common prime factors between them.
-----Input:-----
- First line will contain a number $A$ and $B$ separated by space.
-----Output:-----
Output a single line, the number of common prime factors.
-----Constraints-----
- $1 \leq A, B \leq 1000$
-... | def get_prime_factors(n):
factors = set()
d = 2
while n > 1:
while (n % d) == 0:
factors.add(d)
n //= d
d += 1
return factors
def common_prime_factors(A, B):
primes_a = get_prime_factors(A)
primes_b = get_prime_factors(B)
common_primes = primes_a.inte... | from solution import get_prime_factors, common_prime_factors
def test_get_prime_factors():
assert get_prime_factors(12) == {2, 3}
assert get_prime_factors(18) == {2, 3}
assert get_prime_factors(17) == {17}
assert get_prime_factors(100) == {2, 5}
def test_common_prime_factors():
assert common_prime... | [
{
"docstring": null,
"function_declaration": "def get_prime_factors(n):",
"function_name": "get_prime_factors",
"parameter_list": "(n)"
},
{
"docstring": null,
"function_declaration": "def common_prime_factors(A, B):",
"function_name": "common_prime_factors",
"parameter_list": "(... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from math import gcd\n\ndef prime_factors(n):\n \"\"\"\n Returns a set of prime factors of the given number n.\n \"\"\"\n factors = set()\n \n # ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00018377",
"row_id": 18377,
"seed_ids": "[2701]"
} | 0.563928 | Taco_18377 | I | [
"get_prime_factors",
"common_prime_factors"
] | 2 | [
[
"common_prime_factors",
"get_prime_factors"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 27910dee790f44c97e53bcdb7460574d15caff58 | 7971637f66cc6579130b1b40b7e7e837096243ec | |||
v1.0 | instruct | Taco | Taco_18390_I | You are given a binary tree where each node contains an integer value. Write a program to determine whether there exists a root-to-leaf path that sums up to a given number.
A root-to-leaf path is a sequence of nodes in a tree starting from the root node and ending at any leaf node. The sum of a path is the sum of the ... | class TreeNode:
def __init__(self, val=0, left=None, right=None):
self.val = val
self.left = left
self.right = right
def hasPathSum(root, targetSum):
if not root:
return False
if not root.left and not root.right and root.val == targetSum:
return True
targetSum -=... | def test_checkRootToLeafPath_no_nodes():
assert checkRootToLeafPath(22, 0, []) == "No"
def test_checkRootToLeafPath_single_node_true():
assert checkRootToLeafPath(5, 1, [(5, -1, -1)]) == "Yes"
def test_checkRootToLeafPath_single_node_false():
assert checkRootToLeafPath(10, 1, [(5, -1, -1)]) == "No"
def t... | [] | [
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": "class TreeNode:\n def __init__(self, val=0, left=None, right=None):\n self.val = val\n self.left = left\n self.right = right\n\ndef build_t... | trial_gpt4o_3 | {
"original_instruction": "",
"prompt_id": "00018390",
"row_id": 18390,
"seed_ids": "[3711]"
} | 0.657871 | Taco_18390 | I | [
"hasPathSum",
"buildTree",
"checkRootToLeafPath"
] | 3 | [
[
"checkRootToLeafPath",
"buildTree"
],
[
"checkRootToLeafPath",
"hasPathSum"
]
] | 2 | [] | false | [
"TreeNode"
] | true | pytest | false | [] | true | ffca1d82ebd795fb8a7088f043fa18298424fc1c | 3a4320f9a54e6fb76ff34bf4cafed4b2e7bef621 | |||
v1.0 | instruct | Taco | Taco_18419_I | A company has multiple departments, each with a unique project. Every employee in the company is part of exactly one department, and each department's project has a specific priority and deadline. Your task is to process a series of commands to update the project information and answer queries about the earliest projec... | import sys
from bisect import bisect_left, bisect_right
def create_segment_tree(arr, n):
seg_tree = [sys.maxsize] * 4 * n
build(seg_tree, arr, 0, n - 1, 0)
return seg_tree
def build(seg_tree, arr, start, end, node):
if start == end:
seg_tree[node] = arr[start]
else:
mid = (start + ... | def test_process_commands():
n, q = 5, 4
deadlines = [10, 20, 5, 15, 25]
commands = [(1, 1, 3), (0, 2, 6), (1, 1, 3), (1, 1, 5)]
assert process_commands(n, commands, deadlines) == [5, 5, 5]
def test_process_commands_with_updates():
n, q = 5, 6
deadlines = [10, 20, 5, 15, 25]
commands = [(1,... | [
{
"docstring": null,
"function_declaration": "def create_segment_tree(arr, n):",
"function_name": "create_segment_tree",
"parameter_list": "(arr, n)"
},
{
"docstring": null,
"function_declaration": "def build(seg_tree, arr, start, end, node):",
"function_name": "build",
"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": "import bisect\n\nclass ProjectManager:\n def __init__(self, deadlines):\n self.deadlines = deadlines\n self.sorted_deadlines = sorted(deadlines)\n... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00018419",
"row_id": 18419,
"seed_ids": "[21010]"
} | 0.61644 | Taco_18419 | I | [
"create_segment_tree",
"build",
"update",
"query",
"process_commands"
] | 5 | [
[
"create_segment_tree",
"build"
],
[
"process_commands",
"create_segment_tree"
],
[
"process_commands",
"query"
],
[
"process_commands",
"update"
]
] | 4 | [] | false | [] | false | pytest | false | [] | true | 478185861a3e0fdf7742e8c84e7010f756ef7622 | bd258129c29ece6644303dee7b79a06fc22c63b4 | |||
v1.0 | instruct | Taco | Taco_18428_I | Given a matrix, find the number of distinct paths from the top-left to the bottom-right corner of the matrix, such that you can only move either down or right at any point in time. Additionally, certain cells are blocked, and you cannot pass through those cells.
### Input Format
- The first line contains two integers ... | def unique_paths_with_obstacles(matrix):
m = len(matrix)
n = len(matrix[0])
# Create a 2D dp array initializing zeros everywhere
dp = [[0]*n for _ in range(m)]
# Initialize the starting point
dp[0][0] = 1 if matrix[0][0] == '.' else 0
# Fill the dp array
for i in range(m):... | import pytest
from solution import find_unique_paths
def test_find_unique_paths_no_obstacles():
grid = [
". . .",
". . .",
". . ."
]
m, n = 3, 3
grid = [row.split() for row in grid]
assert find_unique_paths(m, n, grid) == 6
def test_find_unique_paths_with_obstacles():
g... | [
{
"docstring": null,
"function_declaration": "def unique_paths_with_obstacles(matrix):",
"function_name": "unique_paths_with_obstacles",
"parameter_list": "(matrix)"
},
{
"docstring": null,
"function_declaration": "def find_unique_paths(m, n, grid):",
"function_name": "find_unique_pa... | [
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 num_paths(matrix):\n \"\"\"\n Returns the number of distinct paths from the top-left to the bottom-right of the matrix.\n You can only move either dow... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00018428",
"row_id": 18428,
"seed_ids": "[3411]"
} | 0.77235 | Taco_18428 | I | [
"unique_paths_with_obstacles",
"find_unique_paths"
] | 2 | [
[
"find_unique_paths",
"unique_paths_with_obstacles"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 381d5a48ca2d8fc31387eeceae3f5f8f674b84fc | 077512dc0a170fe7ad563c0e4dafa4e748029c1a | |||
v1.0 | instruct | Taco | Taco_18434_I | In a given kingdom, there is a famous magician who can create magical pathways between different cities. The king has asked the magician to connect cities in such a way that the path should be the shortest possible to travel between two specific cities. However, the magician can't directly connect the cities; instead, ... | def floyd_warshall(n, distance):
INF = float('inf')
dist = [[INF] * (n + 1) for _ in range(n + 1)]
for i in range(1, n + 1):
dist[i][i] = 0
for u in range(1, n + 1):
for v in range(1, n + 1):
if distance[u][v] != -1:
dist[u][v] = distance[u][v]
... | def test_shortest_path_between_cities():
T = 2
test_cases = [
(4, 4, [(1, 2, 5), (2, 3, 3), (3, 4, 1), (4, 1, 7)], 2, [(1, 3), (2, 4)]),
(3, 3, [(1, 2, 1), (2, 3, 1)], 1, [(1, 3)])
]
expected_results = [8, 4, 2]
assert shortest_path_between_cities(T, test_cases) == expected_resu... | [
{
"docstring": null,
"function_declaration": "def floyd_warshall(n, distance):",
"function_name": "floyd_warshall",
"parameter_list": "(n, distance)"
},
{
"docstring": null,
"function_declaration": "def shortest_path_between_cities(T, test_cases):",
"function_name": "shortest_path_be... | [
0,
0,
0,
0,
0,
0,
0,
1,
1,
1
] | 3 | hard | 0.3 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import sys\nimport heapq\n\ndef shortest_path(T, test_cases):\n results = []\n \n for test_case in test_cases:\n C, P, pathways, Q, queries = test_... | trial_gpt4o_7 | {
"original_instruction": "",
"prompt_id": "00018434",
"row_id": 18434,
"seed_ids": "[3108]"
} | 0.78923 | Taco_18434 | I | [
"floyd_warshall",
"shortest_path_between_cities"
] | 2 | [
[
"shortest_path_between_cities",
"floyd_warshall"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | a1a7bc85958ac39f997fcf98ff1ab94aed2259d2 | 89fd2cf4cacc882c7d818d749ea249799d14a66e | |||
v1.0 | instruct | Taco | Taco_18473_I | Given an integer array arr[] of size N, find the length of the longest subsequence such that every element in the subsequence is a perfect square.
Example 1:
Input:
N = 6, arr = [1, 2, 3, 4, 5, 16]
Output:
3
Explanation:
The longest subsequence where every element is a perfect square is [1, 4, 16]. Therefore, the outp... | import math
def is_perfect_square(num):
"""
Helper function to check if a number is a perfect square.
"""
if num < 0:
return False
root = int(math.isqrt(num))
return root * root == num
def longestPerfectSquareSubseq(N, arr):
"""
Function to find the length of the longest subseq... | from solution import longestPerfectSquareSubseq
def test_example1():
assert longestPerfectSquareSubseq(6, [1, 2, 3, 4, 5, 16]) == 3
def test_example2():
assert longestPerfectSquareSubseq(4, [10, 15, 14, 7]) == 0
def test_all_perfect_squares():
assert longestPerfectSquareSubseq(5, [1, 4, 9, 16, 25]) == 5
... | [
{
"docstring": "Helper function to check if a number is a perfect square.",
"function_declaration": "def is_perfect_square(num):",
"function_name": "is_perfect_square",
"parameter_list": "(num)"
},
{
"docstring": "Function to find the length of the longest subsequence such that every element... | [
1,
0,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import math\n\ndef is_perfect_square(num):\n \"\"\"\n Helper function to check if a number is a perfect square.\n \"\"\"\n if num < 0:\n return ... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00018473",
"row_id": 18473,
"seed_ids": "[18246]"
} | 0.721543 | Taco_18473 | I | [
"is_perfect_square",
"longestPerfectSquareSubseq"
] | 2 | [
[
"longestPerfectSquareSubseq",
"is_perfect_square"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 18ccf46de6cec01f34ce66a7de6607fab1a633f1 | dd83977f0420ecd8669b40e7fa7d3e25e60cfb74 | |||
v1.0 | instruct | Taco | Taco_18545_I | You are given an array of N integers. You are allowed to perform at most one operation of the following kind: Choose any element in the array, remove it from its position, and insert it back into any other position of the array.
Input
The first line of the input contains an integer T denoting the number of test cases... | def lexicographically_smallest_array(arr):
n = len(arr)
if n <= 1:
return arr
min_elem = min(arr)
min_index = arr.index(min_elem)
smallest_array = arr[:min_index] + arr[min_index+1:]
smallest_array.sort()
smallest_array.insert(0, min_elem)
return smallest_array
d... | from solution import lexicographically_smallest_array, solve
def test_lexicographically_smallest_array():
assert lexicographically_smallest_array([4, 8, 2, 7, 5]) == [2, 4, 5, 7, 8]
assert lexicographically_smallest_array([3, 1, 4, 1, 5, 9]) == [1, 1, 3, 4, 5, 9]
assert lexicographically_smallest_array([1,... | [
{
"docstring": null,
"function_declaration": "def lexicographically_smallest_array(arr):",
"function_name": "lexicographically_smallest_array",
"parameter_list": "(arr)"
},
{
"docstring": null,
"function_declaration": "def solve(arrays):",
"function_name": "solve",
"parameter_lis... | [
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 lexicographically_smallest_array(T, test_cases):\n results = []\n for case in test_cases:\n N, arr = case\n smallest_arr = sorted(arr[:]) ... | trial_gpt4o_4 | {
"original_instruction": "",
"prompt_id": "00018545",
"row_id": 18545,
"seed_ids": "[5404]"
} | 0.737743 | Taco_18545 | I | [
"lexicographically_smallest_array",
"solve",
"array_to_string",
"main"
] | 4 | [
[
"solve",
"lexicographically_smallest_array"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | f1440bff953d3e539c63950c3a82e4d347102556 | bc0c3bc9ae09e7a9c4c0d96734d15ac0bf34e27c | |||
v1.0 | instruct | Taco | Taco_18591_I | You are a software developer tasked with developing a new scheduling algorithm for hospital shifts. Hospitals have different numbers of doctors available each day, and each doctor has different start and end times for their shifts. Your goal is to find the maximum number of overlapping shifts on any given day.
A shift... | def convert_to_minutes(time_str):
hours, minutes = map(int, time_str.split(':'))
return hours * 60 + minutes
def max_overlapping_shifts(shifts):
events = []
for start, end in shifts:
events.append((convert_to_minutes(start), 'start'))
events.append((convert_to_minutes(end), 'end'))
... | def test_max_overlapping_shifts_example1():
shifts = [("09:00", "17:00"), ("12:00", "20:00"), ("11:00", "15:00")]
assert max_overlapping_shifts(shifts) == 3
def test_max_overlapping_shifts_example2():
shifts = [("08:00", "12:00"), ("12:00", "16:00"), ("10:00", "14:00"), ("11:00", "15:00")]
assert max_o... | [
{
"docstring": null,
"function_declaration": "def convert_to_minutes(time_str):",
"function_name": "convert_to_minutes",
"parameter_list": "(time_str)"
},
{
"docstring": null,
"function_declaration": "def max_overlapping_shifts(shifts):",
"function_name": "max_overlapping_shifts",
... | [
1,
1,
0
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def max_overlapping_shifts(n, shifts):\n \"\"\"\n Returns the maximum number of overlapping shifts.\n \"\"\"\n events = []\n \n # Collect all sta... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00018591",
"row_id": 18591,
"seed_ids": "[1994]"
} | 0.677446 | Taco_18591 | I | [
"convert_to_minutes",
"max_overlapping_shifts"
] | 2 | [
[
"max_overlapping_shifts",
"convert_to_minutes"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | 20f122201b3551b9245d3d2afa0ecaf38ddaf621 | 317ee9635283ed964ae02eb4bfb632f18baaf5ea | |||
v1.0 | instruct | Taco | Taco_18610_I | Consider an infinite sequence defined as follows: The first term is 3, the second term is 5, and each subsequent term is the sum of the previous two terms. Hence, the sequence begins as 3, 5, 8, 13, 21, 34, ...
You are given an integer M and a list of integers Q of length K. For each query in Q, find the smallest term... | def generate_sequence_up_to(max_value):
sequence = [3, 5]
while sequence[-1] < max_value:
sequence.append(sequence[-1] + sequence[-2])
return sequence
def smallest_term(sequence, query):
for term in sequence:
if term >= query:
return term
return None
def process_queries... | from solution import generate_sequence_up_to, smallest_term, process_queries
def test_generate_sequence():
assert generate_sequence_up_to(50) == [3, 5, 8, 13, 21, 34, 55]
def test_smallest_term():
sequence = [3, 5, 8, 13, 21, 34, 55]
assert smallest_term(sequence, 50) == 55
assert smallest_term(sequen... | [
{
"docstring": null,
"function_declaration": "def generate_sequence_up_to(max_value):",
"function_name": "generate_sequence_up_to",
"parameter_list": "(max_value)"
},
{
"docstring": null,
"function_declaration": "def smallest_term(sequence, query):",
"function_name": "smallest_term",... | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def find_smallest_term_greater_or_equal(seq, queries):\n \"\"\"\n For each query in queries, find the smallest term in the sequence that is greater than or e... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00018610",
"row_id": 18610,
"seed_ids": "[14637]"
} | 0.820714 | Taco_18610 | I | [
"generate_sequence_up_to",
"smallest_term",
"process_queries"
] | 3 | [
[
"process_queries",
"generate_sequence_up_to"
],
[
"process_queries",
"smallest_term"
]
] | 2 | [
"process_queries"
] | false | [] | false | pytest | true | [] | true | a6688ed187344536721706265aa2a2467b738a61 | c546759f14c53a8e5b948431584c12f9e448d533 | |||
v1.0 | instruct | Taco | Taco_18640_I | You are an urban planner tasked with creating the optimal route plan for bus lines in a city. The city is represented as a graph with n intersections and m bidirectional roads between those intersections. Each road has a certain bus route associated with it and a travel time. The goal is to determine the shortest trave... | from collections import defaultdict
import heapq
def dijkstra(n, edges, start, route):
graph = defaultdict(list)
for u, v, t in edges:
graph[u].append((v, t))
graph[v].append((u, t))
dist = {i: float('inf') for i in range(1, n+1)}
dist[start] = 0
min_heap = [(0, start)]
... | def test_shortest_travel_times():
n, m = 5, 6
s = 1
routes= [
(1, 2, 2, "A"),
(2, 3, 3, "A"),
(3, 4, 1, "A"),
(1, 3, 8, "B"),
(3, 5, 2, "B"),
(4, 5, 3, "C")
]
result = shortest_travel_times(n, m, s, routes)
assert result["A"] == [0, 2, 5, 6, -... | [
{
"docstring": null,
"function_declaration": "def dijkstra(n, edges, start, route):",
"function_name": "dijkstra",
"parameter_list": "(n, edges, start, route)"
},
{
"docstring": null,
"function_declaration": "def shortest_travel_times(n, m, s, routes):",
"function_name": "shortest_tr... | [
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\nimport heapq\n\ndef dijkstra(n, edges, start, route):\n graph = defaultdict(list)\n for u, v, t in edges:\n graph... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00018640",
"row_id": 18640,
"seed_ids": "[3100]"
} | 0.747569 | Taco_18640 | I | [
"dijkstra",
"shortest_travel_times"
] | 2 | [
[
"shortest_travel_times",
"dijkstra"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | dd6c2a6bfd75b7f807e032e830fb88f1015f0f8b | fc1ee3566e100f5d62a156b1669791fe841c38de | |||
v1.0 | instruct | Taco | Taco_18654_I | John is practicing for a coding competition and is working on understanding the concept of prime numbers. He reads about twin primes, which are pairs of prime numbers that have a difference of two. John wants to write a program to check if two given numbers are twin primes.
-----Input:-----
- The first line contains t... | def is_prime(n):
if n <= 1:
return False
for i in range(2, int(n ** 0.5) + 1):
if n % i == 0:
return False
return True
def are_twin_primes(A, B):
"""
Checks if A and B are twin primes.
"""
if abs(A - B) == 2 and is_prime(A) and is_prime(B):
return "YES"
... | from solution import is_prime, are_twin_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
def test_are_twin_primes():
assert are_twin_primes(3, 5) == "YES"
assert are_twin_pr... | [
{
"docstring": null,
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Checks if A and B are twin primes.",
"function_declaration": "def are_twin_primes(A, B):",
"function_name": "are_twin_primes",
"parameter_list"... | [
1,
0,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(n):\n if n <= 1:\n return False\n for i in range(2, int(n ** 0.5) + 1):\n if n % i == 0:\n return False\n return Tru... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00018654",
"row_id": 18654,
"seed_ids": "[9512]"
} | 0.693752 | Taco_18654 | I | [
"is_prime",
"are_twin_primes"
] | 2 | [
[
"are_twin_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 6d75e4f7f29d3c6f3bb7866cbb8d5ec00956cbc5 | ba7661feca4fa1fabce99c7b3af34e03626aaeda | |||
v1.0 | instruct | Taco | Taco_18693_I | You are given an array of positive integers. Your task is to determine the maximum product of two distinct elements of this array.
If the array has less than two elements, return -1.
-----Input-----
The input consists of two lines:
The first line contains a single integer $t$ ($1 \le t \le 1000$) — the number of te... | def max_product_of_two(arr):
"""
Returns the maximum product of two distinct elements of the array.
If the array has less than two elements, returns -1.
"""
if len(arr) < 2:
return -1
arr = sorted(arr, reverse=True)
return arr[0] * arr[1]
def process_test_cases(t, test_cases):
... | from solution import max_product_of_two, process_test_cases, parse_input, max_product_main
def test_max_product_of_two():
assert max_product_of_two([1, 2, 3, 4, 5]) == 20
assert max_product_of_two([7, 1, 9]) == 63
assert max_product_of_two([10]) == -1
assert max_product_of_two([5, 5]) == 25
assert ... | [
{
"docstring": "Returns the maximum product of two distinct elements of the array.\nIf the array has less than two elements, returns -1.",
"function_declaration": "def max_product_of_two(arr):",
"function_name": "max_product_of_two",
"parameter_list": "(arr)"
},
{
"docstring": null,
"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 max_product(test_cases):\n results = []\n for n, arr in test_cases:\n if n < 2:\n results.append(-1)\n else:\n arr.so... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00018693",
"row_id": 18693,
"seed_ids": "[8887]"
} | 0.798225 | Taco_18693 | I | [
"max_product_of_two",
"process_test_cases",
"parse_input",
"max_product_main"
] | 4 | [
[
"max_product_main",
"parse_input"
],
[
"max_product_main",
"process_test_cases"
],
[
"process_test_cases",
"max_product_of_two"
]
] | 3 | [
"process_test_cases",
"parse_input"
] | false | [] | false | pytest | true | [] | true | 73aa181fc58be377a48aa1920e6bd76004ec3cfe | 165f782ca889a72a24585d163ea0680d83250c00 | |||
v1.0 | instruct | Taco | Taco_18720_I | Deepak is fascinated by palindromic sequences and wants to explore them in the context of strings. A string is called a palindrome if it reads the same forwards and backwards. For example, "radar" is a palindrome, but "hello" is not. Deepak would like to determine if it's possible to rearrange the characters of a given... | def can_form_palindrome(s):
"""
Determines if the characters of the string s can be rearranged to form a palindrome.
"""
from collections import Counter
# Count the frequency of each character in the string
char_count = Counter(s)
# Count how many characters have an odd frequency
o... | from solution import can_form_palindrome, batch_check_palindromic_rearrangement
def test_can_form_palindrome():
assert can_form_palindrome("aabbcc") == True
assert can_form_palindrome("abcdef") == False
assert can_form_palindrome("aaabb") == True
assert can_form_palindrome("racecar") == True
assert... | [
{
"docstring": "Determines if the characters of the string s can be rearranged to form a palindrome.",
"function_declaration": "def can_form_palindrome(s):",
"function_name": "can_form_palindrome",
"parameter_list": "(s)"
},
{
"docstring": null,
"function_declaration": "def batch_check_p... | [
1,
1,
0
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def can_form_palindrome(s):\n \"\"\"\n Determines if the characters of the string s can be rearranged to form a palindrome.\n \"\"\"\n from collections... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00018720",
"row_id": 18720,
"seed_ids": "[369]"
} | 0.826829 | Taco_18720 | I | [
"can_form_palindrome",
"batch_check_palindromic_rearrangement"
] | 2 | [
[
"batch_check_palindromic_rearrangement",
"can_form_palindrome"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 091729a9ab0399b2ed8cd7a5b61ea1cf9aec6bc3 | 673705dc382a198dde0b259c58ba660a808d7ea4 | |||
v1.0 | instruct | Taco | Taco_18725_I | The city is planning to erect a series of signposts along a straight road. Each signpost has a specified height. To ensure uniformity in design, the height of each signpost in any given subsegment of the road must not differ by more than a fixed number, k.
You are given the heights of n signposts and an integer k. You... | def is_uniform(subsegment_heights, k):
"""
Checks if height difference within the subsegment does not exceed k.
"""
return max(subsegment_heights) - min(subsegment_heights) <= k
def check_subsegments(n, h, k, queries):
"""
Checks each subsegment query for the uniformity condition.
"""
r... | from solution import process_input
def test_example_case():
n = 6
q = 3
h = [1, 5, 3, 9, 2, 6]
k = 4
queries = [(1, 3), (2, 5), (1, 6)]
assert process_input(n, q, h, k, queries) == ["Yes", "No", "No"]
def test_single_signpost():
n = 1
q = 1
h = [5]
k = 10
queries = [(1, 1)]... | [
{
"docstring": "Checks if height difference within the subsegment does not exceed k.",
"function_declaration": "def is_uniform(subsegment_heights, k):",
"function_name": "is_uniform",
"parameter_list": "(subsegment_heights, k)"
},
{
"docstring": "Checks each subsegment query for the uniformi... | [
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 check_subsegments_heights(n, q, heights, k, queries):\n \"\"\"\n Checks if the height difference within each subsegment does not exceed k.\n \n Par... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00018725",
"row_id": 18725,
"seed_ids": "[13675]"
} | 0.687206 | Taco_18725 | I | [
"is_uniform",
"check_subsegments",
"process_input"
] | 3 | [
[
"check_subsegments",
"is_uniform"
],
[
"process_input",
"check_subsegments"
]
] | 2 | [
"process_input"
] | false | [] | false | pytest | true | [] | true | 4b1b1ce599584ed1cc8b6cffaf2bec2b3fa44d67 | 5488f416ebdff67c7c39092e2d2e88e267f33703 | |||
v1.0 | instruct | Taco | Taco_18730_I | Given a binary tree, the task is to write a function diagonalSum() that computes the sum of the nodes present at each diagonal of the tree. The diagonals of a binary tree begin from the root and extend rightwards and downwards, forming a cascading pattern.
Input:
- The function takes a single argument as input, which ... | class Node:
def __init__(self, key):
self.data = key
self.left = None
self.right = None
def diagonalSum(root):
if root is None:
return []
diagonal_map = {}
_diagonalSumUtil(root, 0, diagonal_map)
# Extract sums from the map and return as a list
result =... | from solution import Node, diagonalSum
def test_diagonalSum_simple():
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.right.right.left = Node(8)
assert diagonalS... | [] | [
0,
0,
0,
1,
0
] | 1 | hard | 0.2 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from collections import defaultdict\n\nclass Node:\n def __init__(self, data):\n self.data = data\n self.left = None\n self.right = None\n\... | trial_gpt4o_3 | {
"original_instruction": "",
"prompt_id": "00018730",
"row_id": 18730,
"seed_ids": "[18196]"
} | 0.585233 | Taco_18730 | I | [
"diagonalSum",
"_diagonalSumUtil"
] | 2 | [
[
"diagonalSum",
"_diagonalSumUtil"
]
] | 1 | [] | false | [
"Node"
] | true | pytest | true | [] | true | 60b708c11edef620dda1eb648c776ea82e9a03a5 | 0d6c9c13478681fe605c7e6c03ce56a496737fc3 | |||
v1.0 | instruct | Taco | Taco_18742_I | Given an $n \times m$ grid, each cell of the grid contains a value which represents the altitude at that position. Alice and Bob are going for a hike, and they want to find a path from the top-left corner (1, 1) to the bottom-right corner ($n$, $m$) of the grid such that the maximum difference in altitude between any t... | from collections import deque
def can_reach_with_diff(grid, n, m, max_diff):
directions = [(1, 0), (-1, 0), (0, 1), (0, -1)]
visited = [[False] * m for _ in range(n)]
queue = deque([(0, 0)])
visited[0][0] = True
while queue:
x, y = queue.popleft()
if x == n - 1 and y == m - 1:
... | def test_minimum_max_diff():
assert minimum_max_diff([
[1, 2, 2],
[3, 8, 2],
[5, 3, 5]
]) == 2
assert minimum_max_diff([
[1, 1000000],
[1000000, 1]
]) == 999999
assert minimum_max_diff([
[1, 2],
[2, 1]
]) == 1
assert minimum_max_diff([
... | [
{
"docstring": null,
"function_declaration": "def can_reach_with_diff(grid, n, m, max_diff):",
"function_name": "can_reach_with_diff",
"parameter_list": "(grid, n, m, max_diff)"
},
{
"docstring": null,
"function_declaration": "def minimum_max_diff(grid):",
"function_name": "minimum_m... | [
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 min_max_path_diff(grid):\n n = len(grid)\n m = len(grid[0])\n directions = [(0, 1), (1, 0), (0, -1), (-1, 0)]\n \n def is_valid(... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00018742",
"row_id": 18742,
"seed_ids": "[15827]"
} | 0.696691 | Taco_18742 | I | [
"can_reach_with_diff",
"minimum_max_diff"
] | 2 | [
[
"minimum_max_diff",
"can_reach_with_diff"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | 7ddb04447ab719f2d3c693deb0b7e28617b079f5 | 639f0c4a6d84746dab9680e716432f7e13bedd2b | |||
v1.0 | instruct | Taco | Taco_18764_I | You are given an undirected graph with $n$ nodes and $m$ edges. Each edge has an associated cost. Your task is to find the minimum cost to visit every node at least once, starting and ending at the same node.
You can perform the following operations on the graph:
- Traverse each edge exactly once.
- Repeat some nodes ... | import itertools
def travel_cost(graph, path):
cost = 0
for i in range(len(path) - 1):
u, v = path[i], path[i+1]
if v in graph[u]:
cost += graph[u][v]
else:
return float('inf')
return cost
def find_min_cost_to_visit_all_nodes(n, m, edges):
if m < n - 1:
... | import pytest
from solution import find_min_cost_to_visit_all_nodes
def test_example_1():
n, m = 4, 6
edges = [
(1, 2, 10),
(1, 3, 15),
(1, 4, 20),
(2, 3, 35),
(2, 4, 25),
(3, 4, 30)
]
assert find_min_cost_to_visit_all_nodes(n, m, edges) == 80
def test_e... | [
{
"docstring": null,
"function_declaration": "def travel_cost(graph, path):",
"function_name": "travel_cost",
"parameter_list": "(graph, path)"
},
{
"docstring": null,
"function_declaration": "def find_min_cost_to_visit_all_nodes(n, m, edges):",
"function_name": "find_min_cost_to_vis... | [
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 sys\n\ndef tsp(graph, n):\n # Initialize dp array to store the results\n dp = [[sys.maxsize] * (1 << n) for _ in range(n)]\n # Starting point initi... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00018764",
"row_id": 18764,
"seed_ids": "[3463]"
} | 0.762175 | Taco_18764 | I | [
"travel_cost",
"find_min_cost_to_visit_all_nodes"
] | 2 | [
[
"find_min_cost_to_visit_all_nodes",
"travel_cost"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 8e73f23d77f69df48b38e885ae0d15c3f8b8ef33 | b002c26d2ee8b8a216a0a17a5279b96eff8a8660 | |||
v1.0 | instruct | Taco | Taco_18793_I | A friend of yours is a world-class mathematician who loves solving complex mathematical challenges. Recently, he encountered a problem in converting an array of integers into a magic square. A magic square is a square matrix in which the sum of the numbers in each row, each column, and both main diagonals are the same.... | def is_magic_square(square, n):
# Calculate the magic constant
magic_constant = n * (n * n + 1) // 2
# Check rows
for row in square:
if sum(row) != magic_constant:
return False
# Check columns
for col in range(n):
if sum(square[row][col] for row in range(n)) != ... | import pytest
from solution import solve_magic_square_problem
def test_magic_square_3x3_possible():
n = 3
arr = [8, 1, 6, 3, 5, 7, 4, 9, 2]
expected_output = '''8 1 6
3 5 7
4 9 2'''
assert solve_magic_square_problem(n, arr) == expected_output
def test_magic_square_3x3_impossible():
n = 3
arr =... | [
{
"docstring": null,
"function_declaration": "def is_magic_square(square, n):",
"function_name": "is_magic_square",
"parameter_list": "(square, n)"
},
{
"docstring": null,
"function_declaration": "def to_magic_square(arr, n):",
"function_name": "to_magic_square",
"parameter_list"... | [
0,
0,
0,
1,
1
] | 2 | medium | 0.4 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def can_form_magic_square(n, arr):\n from itertools import permutations\n\n # Function to check if a matrix is a magic square\n def is_magic_square(matrix... | trial_gpt4o_4 | {
"original_instruction": "",
"prompt_id": "00018793",
"row_id": 18793,
"seed_ids": "[5484]"
} | 0.704089 | Taco_18793 | I | [
"is_magic_square",
"to_magic_square",
"format_output",
"solve_magic_square_problem"
] | 4 | [
[
"solve_magic_square_problem",
"format_output"
],
[
"solve_magic_square_problem",
"to_magic_square"
],
[
"to_magic_square",
"is_magic_square"
]
] | 3 | [
"format_output"
] | false | [] | false | pytest | true | [] | true | 02840230d409aa60a2e26316f2487366aa5482bd | ad40e9e40f5f03a9f45af0960cee0e895446a4e5 | |||
v1.0 | instruct | Taco | Taco_18942_I | In a distant city called Numerica, every year, the city holds a grand number-guessing festival. In this festival, contestants are given a number and they must guess the numbers that, when combined using multiplication, equal the given number. Specifically, the festival has a unique twist. Contestants need to find two s... | import math
def is_prime(num):
if num <= 1:
return False
if num <= 3:
return True
if num % 2 == 0 or num % 3 == 0:
return False
i = 5
while i * i <= num:
if num % i == 0 or num % (i + 2) == 0:
return False
i += 6
return True
def prime_factors... | def test_is_prime():
assert is_prime(2)
assert is_prime(3)
assert not is_prime(4)
assert is_prime(5)
assert not is_prime(9)
def test_prime_factors():
assert prime_factors(10) == [2, 5]
assert prime_factors(18) == [2, 3, 3]
assert prime_factors(30) == [2, 3, 5]
def test_find_two_sets():... | [
{
"docstring": null,
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": null,
"function_declaration": "def prime_factors(n):",
"function_name": "prime_factors",
"parameter_list": "(n)"
},
{
"docstring": n... | [
1,
0
] | 1 | medium | 0.5 | {
"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 if num <= 1:\n return False\n if num <= 3:\n return True\n if num % 2 == 0 or num % 3 == 0:\n ret... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00018942",
"row_id": 18942,
"seed_ids": "[10548]"
} | 0.616678 | Taco_18942 | I | [
"is_prime",
"prime_factors",
"find_two_sets",
"solve",
"number_guessing_festival"
] | 5 | [
[
"find_two_sets",
"prime_factors"
],
[
"number_guessing_festival",
"solve"
],
[
"solve",
"find_two_sets"
]
] | 3 | [] | false | [] | false | pytest | false | [] | true | 33486eec6b62ecb681d3158d629b37b718ec285c | 82de33c0270371c4fea3ea292a42b405cd4f2cc9 | |||
v1.0 | instruct | Taco | Taco_18954_I | In a busy workshop, there are a number of different types of tools lying around. Each tool can be identified by a string of lowercase Latin letters. A tool is considered "useful" if its identifier can be turned into a palindrome by reordering its characters. The workshop owner, Gina, wants to identify which tools are u... | def is_useful_tool(identifier):
"""
Determines if the tool identifier can be rearranged to form a palindrome.
"""
from collections import Counter
# Count the frequency of each character in the identifier
char_counts = Counter(identifier)
# Count how many characters have an odd frequency
... | from solution import is_useful_tool, determine_useful_tools
def test_is_useful_tool():
assert is_useful_tool("radar") == True
assert is_useful_tool("abc") == False
assert is_useful_tool("abb") == True
assert is_useful_tool("car") == False
assert is_useful_tool("a") == True # Single character is a ... | [
{
"docstring": "Determines if the tool identifier can be rearranged to form a palindrome.",
"function_declaration": "def is_useful_tool(identifier):",
"function_name": "is_useful_tool",
"parameter_list": "(identifier)"
},
{
"docstring": "Determines which of the given tool identifiers are use... | [
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_useful_tool(identifier):\n \"\"\"\n Determines if the given tool identifier can be rearranged to form a palindrome.\n \"\"\"\n from collections ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00018954",
"row_id": 18954,
"seed_ids": "[20674]"
} | 0.783131 | Taco_18954 | I | [
"is_useful_tool",
"determine_useful_tools"
] | 2 | [
[
"determine_useful_tools",
"is_useful_tool"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 9cc561395989d270474258e2c92a8b25daf5880a | 201d57e3a931e3c58268f4ff60dacc5bffe0c41d | |||
v1.0 | instruct | Taco | Taco_18994_I | Problem
You are tasked with writing a program that can simulate the behavior of a simple graphics editor. The editor can manipulate a 2D canvas of pixels (represented as a matrix) with the following operations:
1. Fill a subrectangle with a specific color.
2. Flip the contents of the canvas horizontally.
3. Flip the ... | def fill_subrectangle(canvas, r1, c1, r2, c2, color):
for i in range(r1, r2 + 1):
for j in range(c1, c2 + 1):
canvas[i][j] = color
def horizontal_flip(canvas):
for row in canvas:
row.reverse()
def vertical_flip(canvas):
n = len(canvas)
for j in range(n):
for i in ra... | from solution import fill_subrectangle, horizontal_flip, vertical_flip, rotate_90_clockwise, rotate_90_counterclockwise, manipulate_canvas
def test_fill_operation():
canvas = [
[0, 0, 0, 0],
[0, 0, 0, 0],
[0, 0, 0, 0],
[0, 0, 0, 0]
]
fill_subrectangle(canvas, 1, 1, 2, 2, 128... | [
{
"docstring": null,
"function_declaration": "def fill_subrectangle(canvas, r1, c1, r2, c2, color):",
"function_name": "fill_subrectangle",
"parameter_list": "(canvas, r1, c1, r2, c2, color)"
},
{
"docstring": null,
"function_declaration": "def horizontal_flip(canvas):",
"function_na... | [
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 fill_subrectangle(canvas, r1, c1, r2, c2, color):\n for i in range(r1, r2 + 1):\n for j in range(c1, c2 + 1):\n canvas[i][j] = color\n ... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00018994",
"row_id": 18994,
"seed_ids": "[25161]"
} | 0.707855 | Taco_18994 | I | [
"fill_subrectangle",
"horizontal_flip",
"vertical_flip",
"rotate_90_clockwise",
"rotate_90_counterclockwise",
"manipulate_canvas"
] | 6 | [
[
"manipulate_canvas",
"fill_subrectangle"
],
[
"manipulate_canvas",
"horizontal_flip"
],
[
"manipulate_canvas",
"rotate_90_clockwise"
],
[
"manipulate_canvas",
"rotate_90_counterclockwise"
],
[
"manipulate_canvas",
"vertical_flip"
]
] | 5 | [] | false | [] | false | pytest | true | [] | true | 2f6ec158ec1acf11bd3bd5e25878930acc8a6316 | 9943b94f23405c6815c32b174dcaca7ea7575528 | |||
v1.0 | instruct | Taco | Taco_19024_I | Jack and Jill are learning about graphs in their computer science class. Their teacher has given them an interesting challenge involving trees. A tree is a connected, undirected graph with no cycles. The challenge is to find the longest path in the tree, also known as the diameter of the tree. The diameter of a tree is... | from collections import deque, defaultdict
def longest_path_length(tree: dict, start: int) -> (int, int):
"""
BFS to find the longest path from the start node in the tree.
Returns the farthest node found and the distance to that node.
"""
visited = set()
queue = deque([(start, 0)])
farthest... | def test_sample_input():
n = 5
edges = [(1, 2), (1, 3), (2, 4), (2, 5)]
assert tree_diameter(n, edges) == 3
def test_single_node():
n = 1
edges = []
assert tree_diameter(n, edges) == 0
def test_line_graph():
n = 4
edges = [(1, 2), (2, 3), (3, 4)]
assert tree_diameter(n, edges) == 3... | [
{
"docstring": "BFS to find the longest path from the start node in the tree.\nReturns the farthest node found and the distance to that node.",
"function_declaration": "def longest_path_length(tree, start):",
"function_name": "longest_path_length",
"parameter_list": "(tree, start)"
},
{
"doc... | [
1,
0
] | 1 | medium | 0.5 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from collections import deque, defaultdict\n\ndef longest_path_length(tree: dict, start: int) -> (int, int):\n \"\"\"\n BFS to find the longest path from the... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00019024",
"row_id": 19024,
"seed_ids": "[25146]"
} | 0.68685 | Taco_19024 | I | [
"longest_path_length",
"tree_diameter"
] | 2 | [
[
"tree_diameter",
"longest_path_length"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | c2623e506f9d4f1c6a78765fd557742e537a5cc6 | ee218b4a288cfad6ad3f9c20849f4bab0f8325ae | |||
v1.0 | instruct | Taco | Taco_19049_I | Emma is fascinated by numbers and patterns, and she recently discovered prime numbers. She loves manipulating numbers to derive new sequences and combinations. Now, Emma is curious about prime sums.
She defines a prime sum operation which takes a number $n$ and finds two prime numbers $p_1$ and $p_2$ such that $p_1 + ... | def prime_sieve(limit):
"""
Generate a list of prime numbers up to the limit using the Sieve of Eratosthenes.
"""
sieve = [True] * (limit + 1)
sieve[0] = sieve[1] = False
for start in range(2, int(limit**0.5) + 1):
if sieve[start]:
for multiple in range(start * start, limit +... | from solution import find_prime_sum
def test_find_prime_sum_10():
assert find_prime_sum(10) in [(3, 7), (7, 3)]
def test_find_prime_sum_12():
assert find_prime_sum(12) in [(5, 7), (7, 5)]
def test_find_prime_sum_17():
assert find_prime_sum(17) == -1
def test_find_prime_sum_2():
assert find_prime_sum... | [
{
"docstring": "Generate a list of prime numbers up to the limit using the Sieve of Eratosthenes.",
"function_declaration": "def prime_sieve(limit):",
"function_name": "prime_sieve",
"parameter_list": "(limit)"
},
{
"docstring": "Find two prime numbers that sum up to n. If such a pair exists... | [
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 sieve_of_eratosthenes(max_num):\n \"\"\"\n Use the sieve of Eratosthenes to find all prime numbers up to max_num.\n \"\"\"\n is_prime = [True] * (m... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00019049",
"row_id": 19049,
"seed_ids": "[4374]"
} | 0.71321 | Taco_19049 | I | [
"prime_sieve",
"find_prime_sum"
] | 2 | [
[
"find_prime_sum",
"prime_sieve"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 18cbebfc1571b08495d143ea7b43f808ad5dd2ea | 7b51431b29605e2f4819c19d551622efdf5d8d10 | |||
v1.0 | instruct | Taco | Taco_19064_I | A famous botanist is cataloging a series of unique plants found in a remote region. Each plant can be described using three traits: height, width, and number of leaves. Two plants are identical if and only if all three traits are exactly the same.
Given a list of plants, write a program to determine the number of uniq... | def count_unique_plants(T, plant_lists):
"""
Returns the number of unique plants for each list of plants.
Args:
T (int): The number of lists of plants to analyze.
plant_lists (list of list of tuples): Each list contains tuples representing each plant with (height, width, leaves).
Retur... | from solution import botanical_analysis
def test_case_1():
input_data = "2\n3\n3 2 5\n3 2 5\n1 4 10\n2\n0 0 0\n0 0 0"
assert botanical_analysis(input_data) == [2, 1]
def test_case_2():
input_data = "1\n4\n1 1 1\n2 2 2\n3 3 3\n4 4 4"
assert botanical_analysis(input_data) == [4]
def test_case_3():
... | [
{
"docstring": "Returns the number of unique plants for each list of plants.\n\nArgs:\nT (int): The number of lists of plants to analyze.\nplant_lists (list of list of tuples): Each list contains tuples representing each plant with (height, width, leaves).\n\nReturns:\nlist of int: Number of unique plants for e... | [
0,
1
] | 1 | medium | 0.5 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def count_unique_plants(T, plant_lists):\n \"\"\"\n Given a number of lists of plants, each with height, width, and number of leaves, \n determine the num... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00019064",
"row_id": 19064,
"seed_ids": "[11240]"
} | 0.62395 | Taco_19064 | I | [
"count_unique_plants",
"botanical_analysis"
] | 2 | [
[
"botanical_analysis",
"count_unique_plants"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 47c88c4c90f1c53175b9caa88e6437636d7ec313 | 8960f484be9f3f7a294f2b5c0a3c48768bfb40cd | |||
v1.0 | instruct | Taco | Taco_19065_I | You are a software developer at a logistics company. Your team is working on optimizing delivery routes by keeping track of the locations of delivery vehicles throughout the day.
Each vehicle records its location at various times during the day, and the goal is to determine the total distance covered by each vehicle b... | import math
def calculate_distance(x1, y1, x2, y2):
"""
Calculate the Euclidean distance between two points (x1, y1) and (x2, y2).
"""
return math.sqrt((x2 - x1) ** 2 + (y2 - y1) ** 2)
def total_distance_covered(vehicle_locations):
"""
Calculate the total distance covered by a vehicle given a ... | from solution import calculate_distance, total_distance_covered, process_input
def test_calculate_distance():
assert math.isclose(calculate_distance(0, 0, 3, 4), 5.0)
assert math.isclose(calculate_distance(-1, -1, -4, -5), 5.0)
assert math.isclose(calculate_distance(0, 0, 0, 0), 0.0)
def test_total_distan... | [
{
"docstring": "Calculate the Euclidean distance between two points (x1, y1) and (x2, y2).",
"function_declaration": "def calculate_distance(x1, y1, x2, y2):",
"function_name": "calculate_distance",
"parameter_list": "(x1, y1, x2, y2)"
},
{
"docstring": "Calculate the total distance covered ... | [
0,
0,
0,
0,
0,
1,
1,
0,
0,
1
] | 3 | hard | 0.3 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import math\n\ndef calculate_distance(x1, y1, x2, y2):\n return math.sqrt((x2 - x1) ** 2 + (y2 - y1) ** 2)\n\ndef calculate_total_distance(vehicle_data):\n t... | trial_gpt4o_9 | {
"original_instruction": "",
"prompt_id": "00019065",
"row_id": 19065,
"seed_ids": "[7950]"
} | 0.709185 | Taco_19065 | I | [
"calculate_distance",
"total_distance_covered",
"process_input"
] | 3 | [
[
"process_input",
"total_distance_covered"
],
[
"total_distance_covered",
"calculate_distance"
]
] | 2 | [
"process_input"
] | false | [] | false | pytest | true | [] | true | 0dfc957afc6ffe13277633b7861ddb15f939ba64 | baf86b7e6a24fedc5d0cc3b63d9f60ee03415d2f | |||
v1.0 | instruct | Taco | Taco_19101_I | Mr. LD, an eccentric AI researcher, designed a binary communication system between his AI agents. Each agent sends a binary message that consists of a series of `0`s and `1`s. The receiver agent must reconstruct the original message correctly, but the communication system is so simple that it occasionally corrupts the ... | def is_palindrome(s):
return s == s[::-1]
def min_subsequences(s):
if is_palindrome(s):
return 1
return 2
def process_cases(cases):
results = []
for s in cases:
results.append(min_subsequences(s))
return results | from solution import is_palindrome, min_subsequences, process_cases
def test_is_palindrome():
assert is_palindrome("101")
assert not is_palindrome("1100")
assert is_palindrome("0110")
assert is_palindrome("1")
assert is_palindrome("11")
assert not is_palindrome("10")
def test_min_subsequences(... | [
{
"docstring": null,
"function_declaration": "def is_palindrome(s):",
"function_name": "is_palindrome",
"parameter_list": "(s)"
},
{
"docstring": null,
"function_declaration": "def min_subsequences(s):",
"function_name": "min_subsequences",
"parameter_list": "(s)"
},
{
"d... | [
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 min_reversal_subsequences(S):\n \"\"\"\n Returns the minimum number of contiguous subsequences the binary string \n must be divided into, such that re... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00019101",
"row_id": 19101,
"seed_ids": "[23974]"
} | 0.647996 | Taco_19101 | I | [
"is_palindrome",
"min_subsequences",
"process_cases"
] | 3 | [
[
"min_subsequences",
"is_palindrome"
],
[
"process_cases",
"min_subsequences"
]
] | 2 | [
"process_cases"
] | false | [] | false | pytest | true | [] | true | 256adc5b90375cc6e7e645d2333ba59091053919 | 1d479fc1c5470d170b40aa9dcc2324e53cdd490a | |||
v1.0 | instruct | Taco | Taco_19134_I | You are given a binary tree, where each node contains an integer value. The goal is to determine the maximum sum of values obtained by visiting nodes in any downward path in the tree. A downward path is defined as starting from any node and moving downward to any node without revisiting any nodes.
Input
The first lin... | class TreeNode:
def __init__(self, value=0):
self.value = value
self.children = []
def build_tree(edges, values):
nodes = [TreeNode(val) for val in values]
for u, v in edges:
nodes[u-1].children.append(nodes[v-1])
nodes[v-1].children.append(nodes[u-1])
return nodes[0]
d... | def test_solves_example():
n = 5
edges = [(1, 2), (1, 3), (3, 4), (3, 5)]
values = [10, 2, 10, -1, 3]
assert solve(n, edges, values) == 23
def test_single_node():
n = 1
edges = []
values = [1]
assert solve(n, edges, values) == 1
def test_linear_tree():
n = 5
edges = [(1, 2), (2... | [] | [
0,
0,
0,
0,
0,
0,
0,
0,
1,
0
] | 1 | hard | 0.1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from collections import defaultdict\n\ndef dfs(node, parent, node_values, adj_list):\n max_sum = node_values[node - 1]\n max_single_path = 0\n for neighbo... | trial_gpt4o_8 | {
"original_instruction": "",
"prompt_id": "00019134",
"row_id": 19134,
"seed_ids": "[6568]"
} | 0.681897 | Taco_19134 | I | [
"build_tree",
"max_path_sum",
"solve"
] | 3 | [
[
"solve",
"build_tree"
],
[
"solve",
"max_path_sum"
]
] | 2 | [] | false | [
"TreeNode"
] | true | pytest | false | [] | true | 63cb096ee92d7f71c8b1e565811342df410bbc3a | a1dd4b48981438f9e9ff17348c02e6c0c29f53c3 | |||
v1.0 | instruct | Taco | Taco_19201_I | Write a function that takes a list of integers and returns a new list where each integer is replaced by the number of integers smaller than it on its right side in the original list.
-----Constraints-----
- The list will contain between 1 and 100,000 integers.
- Each integer in the list will be between -1,000,000 and ... | def count_smaller_elements(nums):
"""
Returns a list where each element is replaced by the number of integers smaller than it on its right side.
"""
if not nums:
return []
result = [0] * len(nums)
sorted_nums = []
for i in range(len(nums) - 1, -1, -1):
pos = binary_search_i... | from solution import count_smaller_elements
def test_count_smaller_elements_example():
assert count_smaller_elements([3, 4, 9, 6, 1]) == [1, 1, 2, 1, 0]
def test_count_smaller_elements_all_ascending():
assert count_smaller_elements([1, 2, 3, 4, 5]) == [0, 0, 0, 0, 0]
def test_count_smaller_elements_all_desce... | [
{
"docstring": "Returns a list where each element is replaced by the number of integers smaller than it on its right side.",
"function_declaration": "def count_smaller_elements(nums):",
"function_name": "count_smaller_elements",
"parameter_list": "(nums)"
},
{
"docstring": "Uses binary searc... | [
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 count_smaller(nums):\n \"\"\"\n Returns a new list where each integer is replaced by the number of integers smaller \n than it on its right side in th... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00019201",
"row_id": 19201,
"seed_ids": "[22048]"
} | 0.674665 | Taco_19201 | I | [
"count_smaller_elements",
"binary_search_insert_position"
] | 2 | [
[
"count_smaller_elements",
"binary_search_insert_position"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 0b966df52e79ac309e3d050eb825812184446a35 | 0bacc1e485c0eaabd2ec07d7115467931846fd56 | |||
v1.0 | instruct | Taco | Taco_19210_I | You are given a binary tree with N nodes, numbered 1 through N.
The i-th of the N-1 edges connects the vertices u_i and v_i.
For each query, you are given two vertices x and y. You need to determine the length of the shortest path between these two vertices.
Write a program that reads the tree and handles Q queries.... | import sys
from collections import deque
def preprocess_tree(N, edges):
"""
Preprocess the tree to create adjacency list and depth/parent info for LCA.
N: int, number of nodes in the tree
edges: list of tuples, each tuple representing an edge between two nodes (u, v)
"""
adjacency_list = [... | import pytest
from solution import preprocess_tree, shortest_path_length
def test_preprocess_tree():
N = 5
edges = [(1, 2), (1, 3), (3, 4), (3, 5)]
parent, depth = preprocess_tree(N, edges)
assert parent == [-1, -1, 1, 1, 3, 3]
assert depth == [-1, 0, 1, 1, 2, 2]
def test_shortest_path_length():
... | [
{
"docstring": "Preprocess the tree to create adjacency list and depth/parent info for LCA.\n\nN: int, number of nodes in the tree\nedges: list of tuples, each tuple representing an edge between two nodes (u, v)",
"function_declaration": "def preprocess_tree(N, edges):",
"function_name": "preprocess_tre... | [
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 sys\nfrom collections import deque\n\n\nclass Tree:\n def __init__(self, n):\n self.adj = [[] for _ in range(n + 1)]\n self.depth = [-1] * ... | trial_gpt4o_4 | {
"original_instruction": "",
"prompt_id": "00019210",
"row_id": 19210,
"seed_ids": "[17251]"
} | 0.684138 | Taco_19210 | I | [
"preprocess_tree",
"lca",
"shortest_path_length",
"main"
] | 4 | [
[
"shortest_path_length",
"lca"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 4ac51306ef28918b5b1ba5f486efda240a4b8f9f | 33659dec4aa6c21730df7436fe980b4f99c78e9d | |||
v1.0 | instruct | Taco | Taco_19312_I | You are given a square grid of size $n \times n$, where $n$ is an odd integer. Each cell in the grid contains a unique integer from $1$ to $n^2$.
Your task is to create a magic square using the given grid. In a magic square, the sum of the integers in each row, each column, and the two main diagonals are equal.
Using... | def is_magic_square(grid, n):
magic_sum = n * (n**2 + 1) // 2
row_sums = [sum(row) for row in grid]
col_sums = [sum(grid[i][j] for i in range(n)) for j in range(n)]
diag1_sum = sum(grid[i][i] for i in range(n))
diag2_sum = sum(grid[i][n-i-1] for i in range(n))
all_sums = row_sums + col_sums... | from solution import main
def test_case_1():
input_str = "2\n3\n8 1 6\n3 5 7\n4 9 2\n5\n17 24 1 8 15\n23 5 7 14 16\n4 6 13 20 22\n10 12 19 21 3\n11 18 25 2 9"
expected_output = "YES\nYES"
assert main(input_str) == expected_output
def test_case_2():
input_str = "1\n3\n1 2 3\n4 5 6\n7 8 9"
expected_... | [
{
"docstring": null,
"function_declaration": "def is_magic_square(grid, n):",
"function_name": "is_magic_square",
"parameter_list": "(grid, n)"
},
{
"docstring": null,
"function_declaration": "def can_form_magic_square(grids):",
"function_name": "can_form_magic_square",
"paramete... | [
0,
0,
0,
0,
0,
0,
0,
0,
1,
0
] | 1 | hard | 0.1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_magic_square(matrix):\n \"\"\"\n Check if the given matrix is a magic square.\n \"\"\"\n n = len(matrix)\n magic_sum = sum(matrix[0])\n \n... | trial_gpt4o_8 | {
"original_instruction": "",
"prompt_id": "00019312",
"row_id": 19312,
"seed_ids": "[25428]"
} | 0.673503 | Taco_19312 | I | [
"is_magic_square",
"can_form_magic_square",
"process_input",
"main"
] | 4 | [
[
"can_form_magic_square",
"is_magic_square"
]
] | 1 | [
"process_input"
] | false | [] | false | pytest | true | [] | true | fbae825c1a5a12ba7fb43e6534972eef8a2b813c | d0d4c4a6331fa7253decc25846e41816037208ed | |||
v1.0 | instruct | Taco | Taco_19418_I | You are given an integer array A of size N. Your task is to process Q queries on this array. Each query consists of two integers L and R, and asks for the sum of the Fibonacci numbers from the subarray A[L:R].
The Fibonacci number for an integer X is defined as follows:
- F(0) = 0
- F(1) = 1
- F(X) = F(X-1) + F(X-2) f... | def fibonacci(n):
"""
Calculate the Fibonacci number F(n).
Uses iterative approach for efficiency.
"""
fib = [0, 1]
for i in range(2, n + 1):
fib.append(fib[-1] + fib[-2])
return fib[n]
def process_queries(arr, queries):
fib_cache = {i: fibonacci(i) for i in range(... | def test_fibonacci():
assert fibonacci(0) == 0
assert fibonacci(1) == 1
assert fibonacci(2) == 1
assert fibonacci(3) == 2
assert fibonacci(10) == 55
assert fibonacci(30) == 832040
def test_process_queries():
arr = [1, 2, 3, 4, 5]
queries = [(1, 3), (2, 5)]
assert process_queries(arr... | [
{
"docstring": "Calculate the Fibonacci number F(n).\nUses iterative approach for efficiency.",
"function_declaration": "def fibonacci(n):",
"function_name": "fibonacci",
"parameter_list": "(n)"
},
{
"docstring": null,
"function_declaration": "def process_queries(arr, queries):",
"fu... | [
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(n):\n \"\"\"\n Calculate the Fibonacci number F(n).\n Uses iterative approach for efficiency.\n \"\"\"\n fib = [0, 1]\n \n for i... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00019418",
"row_id": 19418,
"seed_ids": "[9193]"
} | 0.713402 | Taco_19418 | I | [
"fibonacci",
"process_queries",
"fibonacci_queries"
] | 3 | [
[
"fibonacci_queries",
"process_queries"
],
[
"process_queries",
"fibonacci"
]
] | 2 | [
"process_queries"
] | false | [] | false | pytest | false | [] | true | f943444f2c37e42aa7dde4867662817230e0e520 | 91ccfc7764ee01c1aeb2b296db13956f17d236a6 | |||
v1.0 | instruct | Taco | Taco_19448_I | In the world of competitive programming, you often have to deal with numerical constraints and optimization problems. One such problem presented to you is to achieve precise control over robotic arms in a factory setting. The robotic arms need to reach specific coordinates in a 2D plane to pick up or place items, and e... | def process_robot_commands(commands):
"""
Processes a list of robot commands and returns the final position of the robotic arm.
:param commands: List of command strings
:return: Tuple (x, y) representing the final coordinates on the cartesian plane.
"""
x, y = 0, 0 # Starting at the origin... | from solution import process_robot_commands, read_input_to_process
def test_process_robot_commands():
assert process_robot_commands(["MOVE_X 10", "MOVE_Y 5", "POSITION 3 7", "MOVE_X -4"]) == (-1, 7)
assert process_robot_commands(["MOVE_X 12", "MOVE_Y 8", "POSITION 1 -3"]) == (1, -3)
assert process_robot_co... | [
{
"docstring": "Processes a list of robot commands and returns the final position of the robotic arm.\n\n:param commands: List of command strings\n:return: Tuple (x, y) representing the final coordinates on the cartesian plane.",
"function_declaration": "def process_robot_commands(commands):",
"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 control_robotic_arm(commands):\n \"\"\"\n Computes the final position of the robotic arm after processing a series of commands.\n \n :param command... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00019448",
"row_id": 19448,
"seed_ids": "[24449]"
} | 0.572118 | Taco_19448 | I | [
"process_robot_commands",
"read_input_to_process"
] | 2 | [
[
"read_input_to_process",
"process_robot_commands"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 559af2d06d2afa9ca0c9954691e038b6a85b2a0c | 2cb00cdfdf009d09a45743830ac414ecf7bd0af2 | |||
v1.0 | instruct | Taco | Taco_19453_I | A palindrome is a word that reads the same backward as forward. Write a function that accepts a string and returns True if the string is a palindrome, ignoring spaces, punctuation, and capitalization, and False otherwise.
## Example
For example, if the input string is: `"A man, a plan, a canal, Panama!"`, the function... | def clean_string(s: str) -> str:
"""
Removes all non-alphanumeric characters from a string and converts it to lowercase.
"""
return ''.join(c.lower() for c in s if c.isalnum())
def is_palindrome(s: str) -> bool:
"""
Returns True if the cleaned string is a palindrome, ignoring spaces, punctuatio... | from solution import is_palindrome, clean_string
def test_clean_string():
assert clean_string("A man, a plan, a canal, Panama!") == "amanaplanacanalpanama"
assert clean_string("Hello, World!") == "helloworld"
assert clean_string("No 'x' in Nixon") =="noxinnixon"
assert clean_string("Palindrome!") == "p... | [
{
"docstring": "Removes all non-alphanumeric characters from a string and converts it to lowercase.",
"function_declaration": "def clean_string(s):",
"function_name": "clean_string",
"parameter_list": "(s)"
},
{
"docstring": "Returns True if the cleaned string is a palindrome, ignoring space... | [
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 clean_string(s: str) -> str:\n \"\"\"\n Removes all non-alphanumeric characters from a string and converts it to lowercase.\n \"\"\"\n return ''.jo... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00019453",
"row_id": 19453,
"seed_ids": "[25092]"
} | 0.805333 | Taco_19453 | I | [
"clean_string",
"is_palindrome"
] | 2 | [
[
"is_palindrome",
"clean_string"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | ea809bb46a214627d9b9fe140b9d296fe8b10742 | aff17a5620501c4882ebfad39d18869f2e0b1688 | |||
v1.0 | instruct | Taco | Taco_19467_I | You are given a rectangular grid with cells arranged in r rows and c columns. Each cell has a specific energy value. You need to find a path from the top-left cell (1, 1) to the bottom-right cell (r, c) such that the sum of the energy values of the cells in the path is minimized. You can only move to the right or down ... | def min_energy_path(grid):
"""
Finds the minimum energy path in a grid from top-left to bottom-right.
"""
r = len(grid)
c = len(grid[0])
# Create a 2D dp array to store the minimum path sum up to each cell
dp = [[0] * c for _ in range(r)]
# Initialize the starting point
dp[... | from solution import min_energy_path_from_input
def test_easy_case():
input_str = """\
3 4
5 9 1 3
4 7 2 6
8 5 3 2"""
assert min_energy_path_from_input(input_str) == 22
def test_single_row():
input_str = """\
1 4
1 2 3 4"""
assert min_energy_path_from_input(input_str) == 10
def test_single_column():
... | [
{
"docstring": "Finds the minimum energy path in a grid from top-left to bottom-right.",
"function_declaration": "def min_energy_path(grid):",
"function_name": "min_energy_path",
"parameter_list": "(grid)"
},
{
"docstring": null,
"function_declaration": "def min_energy_path_from_input(in... | [
0,
0,
0,
1,
0
] | 1 | hard | 0.2 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def min_energy_path(r, c, grid):\n \"\"\"\n Returns the minimum energy sum required to move from the top-left \n to the bottom-right cell of the grid.\n ... | trial_gpt4o_3 | {
"original_instruction": "",
"prompt_id": "00019467",
"row_id": 19467,
"seed_ids": "[17146]"
} | 0.690021 | Taco_19467 | I | [
"min_energy_path",
"min_energy_path_from_input"
] | 2 | [
[
"min_energy_path_from_input",
"min_energy_path"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 829c28a6ce4305ecaac5822c54156b2c4f1565f7 | 0d212fe1f3e101e59921c15394a61a94e2655487 | |||
v1.0 | instruct | Taco | Taco_19474_I | Given an unsorted array of integers, write a function named "find_kth_largest" that takes two arguments: an array of integers and an integer k, and returns the k-th largest element in the array.
For example, given the array [3, 2, 1, 5, 6, 4] and k = 2, your function should return 5. Note that k is guaranteed to be a ... | def partition(arr, low, high):
pivot = arr[high]
i = low - 1
for j in range(low, high):
if arr[j] > pivot:
i += 1
arr[i], arr[j] = arr[j], arr[i]
arr[i + 1], arr[high] = arr[high], arr[i + 1]
return i + 1
def quickselect(arr, low, high, k):
if low < high:
... | from solution import find_kth_largest
def test_single_element():
assert find_kth_largest([1], 1) == 1
def test_two_elements():
assert find_kth_largest([1, 2], 1) == 2
assert find_kth_largest([1, 2], 2) == 1
def test_general_case():
assert find_kth_largest([3, 2, 1, 5, 6, 4], 1) == 6
assert find_k... | [
{
"docstring": null,
"function_declaration": "def partition(arr, low, high):",
"function_name": "partition",
"parameter_list": "(arr, low, high)"
},
{
"docstring": null,
"function_declaration": "def quickselect(arr, low, high, k):",
"function_name": "quickselect",
"parameter_list... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def find_kth_largest(nums, k):\n \"\"\"\n Finds the k-th largest element in the array.\n \n :param nums: List[int], an unsorted array of integers\n ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00019474",
"row_id": 19474,
"seed_ids": "[22946]"
} | 0.75907 | Taco_19474 | I | [
"partition",
"quickselect",
"find_kth_largest"
] | 3 | [
[
"find_kth_largest",
"quickselect"
],
[
"quickselect",
"partition"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | d571838d04afe81b3d4ff2708a004b99bef41866 | 8f6f60d82a9190f1f291bcbd6f35dc3e964093a9 | |||
v1.0 | instruct | Taco | Taco_19481_I | A group of hikers is exploring a mountain trail. The trail is a circle, meaning it starts and ends at the same point. Each hiker starts from the beginning of the trail at the same time and walks at a constant speed. The trail has markers at regular intervals, and we want to know when all the hikers will next meet at th... | import math
from functools import reduce
# Function to find the Least Common Multiple (LCM) of two numbers
def lcm(a, b):
return abs(a * b) // math.gcd(a, b)
# Function to find the LCM of a list of numbers using reduce
def find_lcm_for_list(lst):
return reduce(lcm, lst)
def find_hikers_meeting_time(test_case... | from solution import find_hikers_meeting_time
def test_case_1():
assert find_hikers_meeting_time([[3, 4]]) == [12]
def test_case_2():
assert find_hikers_meeting_time([[1, 2, 3]]) == [6]
def test_case_3():
assert find_hikers_meeting_time([[2, 3, 6, 9]]) == [18]
def test_multiple_cases():
test_cases =... | [
{
"docstring": null,
"function_declaration": "def lcm(a, b):",
"function_name": "lcm",
"parameter_list": "(a, b)"
},
{
"docstring": null,
"function_declaration": "def find_lcm_for_list(lst):",
"function_name": "find_lcm_for_list",
"parameter_list": "(lst)"
},
{
"docstring... | [
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\ndef lcm(a, b):\n \"\"\"Return least common multiple.\"\"\"\n return a * b // gcd(a, b)\n\ndef lcm_multi... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00019481",
"row_id": 19481,
"seed_ids": "[16918]"
} | 0.683761 | Taco_19481 | I | [
"lcm",
"find_lcm_for_list",
"find_hikers_meeting_time"
] | 3 | [
[
"find_hikers_meeting_time",
"find_lcm_for_list"
],
[
"find_lcm_for_list",
"lcm"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 8ec5c2a32bf5ba07b1ba49e4230b27526e425f59 | f6fbf3d527a743321163b4f17977cae888570114 | |||
v1.0 | instruct | Taco | Taco_19483_I | A charity organization is hosting an auction where bidders can place bids on items. Each bid consists of the bidder's name, the item name, and the bid amount. At the end of the auction, the organization wants to announce the highest bid for each item along with the bidder's name.
Write a program that reads the bids an... | def find_highest_bids(n, bids):
"""
Finds the highest bid for each item along with the bidder's name.
Parameters:
n : int : Number of bids
bids : list of tuple : List of tuples where each tuple contains:
(bidder's name, item name, bid amount)
Returns:
lis... | from solution import auction_results
def test_auction_results_example():
input_data = """5
John painting 300
Alice sculpture 500
John sculpture 700
Alice painting 250
Tom vase 400"""
expected_output = """painting 300 John
sculpture 700 John
vase 400 Tom"""
assert auction_results(input_data) == ex... | [
{
"docstring": "Finds the highest bid for each item along with the bidder's name.\n\nParameters:\nn : int : Number of bids\nbids : list of tuple : List of tuples where each tuple contains:\n (bidder's name, item name, bid amount)\n\nReturns:\nlist of tuple : List of tuples where each tuple... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def find_highest_bids(bids):\n \"\"\"\n Returns the highest bid for each item along with the bidder's name.\n \"\"\"\n highest_bids = {}\n \n for... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00019483",
"row_id": 19483,
"seed_ids": "[1533]"
} | 0.566597 | Taco_19483 | I | [
"find_highest_bids",
"auction_results"
] | 2 | [
[
"auction_results",
"find_highest_bids"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | f98e9c38fc591155e5c7248ffaa3bab8d3c77b92 | df19716788abd303d85823e1fedc69bcebb54b9b | |||
v1.0 | instruct | Taco | Taco_19490_I | Given a string `s` that consists of only digits, return all possible valid IP addresses that can be obtained by placing three dots (`.`) in the string.
A valid IP address consists of exactly four integers, each integer is between `0` and `255`, separated by single dots, and cannot have leading zeros.
For example:
- `... | from typing import List
def is_valid_segment(segment: str) -> bool:
"""
Check if a segment is a valid IP segment.
"""
if len(segment) > 1 and segment[0] == '0':
return False
if not 0 <= int(segment) <= 255:
return False
return True
def restore_ip_addresses(s: str) -> List[str]:... | from solution import restore_ip_addresses
def test_restore_ip_addresses():
assert restore_ip_addresses("010010") == ["0.10.0.10", "0.100.1.0"]
def test_restore_ip_addresses_no_leading_zero():
assert restore_ip_addresses("25525511135") == ["255.255.11.135", "255.255.111.35"]
def test_restore_ip_addres... | [
{
"docstring": "Check if a segment is a valid IP segment.",
"function_declaration": "def is_valid_segment(segment):",
"function_name": "is_valid_segment",
"parameter_list": "(segment)"
},
{
"docstring": "Given a string `s` that consists of only digits, return all possible valid IP addresses.... | [
1,
0,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from typing import List\n\ndef is_valid_segment(segment: str) -> bool:\n \"\"\"\n Check if a segment is a valid IP segment.\n \"\"\"\n if len(segment) ... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00019490",
"row_id": 19490,
"seed_ids": "[17694]"
} | 0.662147 | Taco_19490 | I | [
"is_valid_segment",
"restore_ip_addresses"
] | 2 | [
[
"restore_ip_addresses",
"is_valid_segment"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 41911d87dce4d3c4b8413b6bb34d9e3a16a83041 | 44eb4487239422807974c0e8ed24c2762e4deaf0 | |||
v1.0 | instruct | Taco | Taco_19572_I | Given an undirected graph G with N nodes and M edges, find the size of the largest clique in this graph.
A clique is a subset of nodes such that there is an edge between any two distinct nodes in this subset.
-----Constraints-----
- 1 <= N <= 100
- 0 <= M <= N*(N-1)/2
- 1 <= u_i, v_i <= N
- All given values in inp... | from itertools import combinations
def is_clique(graph, nodes):
"""Helper function to verify if a given set of nodes forms a clique."""
for u, v in combinations(nodes, 2):
if v not in graph[u]:
return False
return True
def largest_clique_size(N, edges):
"""Returns the size of the l... | from solution import largest_clique_size
def test_sample_input():
N = 5
edges = [(1, 2), (1, 3), (1, 4), (2, 3), (2, 4), (3, 4)]
assert largest_clique_size(N, edges) == 4
def test_no_edges():
N = 4
edges = []
assert largest_clique_size(N, edges) == 1
def test_disjoint_cliques():
N = 6
... | [
{
"docstring": "Helper function to verify if a given set of nodes forms a clique.",
"function_declaration": "def is_clique(graph, nodes):",
"function_name": "is_clique",
"parameter_list": "(graph, nodes)"
},
{
"docstring": "Returns the size of the largest clique in the graph with N nodes and... | [
0,
0,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from itertools import combinations\n\ndef largest_clique_size(n, edges):\n \"\"\"\n Returns the size of the largest clique in an undirected graph with n node... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00019572",
"row_id": 19572,
"seed_ids": "[560]"
} | 0.603542 | Taco_19572 | I | [
"is_clique",
"largest_clique_size",
"read_input"
] | 3 | [
[
"largest_clique_size",
"is_clique"
]
] | 1 | [
"read_input"
] | false | [] | false | pytest | true | [] | true | 655b09ac6d057b47ef4ca9f8858f89a66c9552f8 | 2f708c7c847683241ddc0b2b1f4abd84a26fe9d5 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.