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_44367_I
Anna is a university student who wants to create a study group. She has a number of friends, each friend is represented by a unique student ID, and the friendship between them can be represented as an undirected graph where each node is a student, and an edge between two nodes indicates that they are friends. Anna want...
from itertools import combinations def is_clique(graph, nodes): for i in range(len(nodes)): for j in range(i + 1, len(nodes)): if nodes[j] not in graph[nodes[i]]: return False return True def largest_clique(n, m, friendships): graph = {i: set() for i in range(1, n + 1)}...
from solution import largest_clique def test_example_case1(): n, m = 5, 6 friendships = [(1, 2), (2, 3), (3, 4), (4, 1), (1, 3), (2, 4)] assert largest_clique(n, m, friendships) == 4 def test_example_case2(): n, m = 4, 2 friendships = [(1, 2), (3, 4)] assert largest_clique(n, m, friendships) =...
[ { "docstring": null, "function_declaration": "def is_clique(graph, nodes):", "function_name": "is_clique", "parameter_list": "(graph, nodes)" }, { "docstring": null, "function_declaration": "def largest_clique(n, m, friendships):", "function_name": "largest_clique", "parameter_li...
[ 1, 1 ]
2
easy
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 largest_clique(n, m, edges):\n \"\"\"\n Given the number of students n and the list of edges representing friendshi...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00044367", "row_id": 44367, "seed_ids": "[22627]" }
0.691528
Taco_44367
I
[ "is_clique", "largest_clique" ]
2
[ [ "largest_clique", "is_clique" ] ]
1
[]
false
[]
false
pytest
true
[]
true
4d4b1cc750ecb787951009c3073932530afbf2d7
3b15f8c93d8216cf15a569f2418ab5de8bdad4f5
v1.0
instruct
Taco
Taco_44369_I
You are tasked with the development of a sophisticated program that can analyze and manage network traffic in a simulated environment. The network consists of several nodes interconnected by bidirectional links. Each link between two nodes has an associated bandwidth representing the maximum amount of data it can handl...
from collections import defaultdict, deque def bfs(capacity, parent, source, sink): visited = set() queue = deque([source]) visited.add(source) while queue: u = queue.popleft() for v in capacity[u]: if v not in visited and capacity[u][v] > 0: # If there's avai...
from solution import simulate_datasets def test_single_small_case(): datasets = [{ 'meta': (4, 5, 3), 'links': [ (0, 1, 10), (0, 2, 5), (1, 2, 15), (1, 3, 10), (2, 3, 5) ], 'requests': [ (0, 3, 10), ...
[ { "docstring": null, "function_declaration": "def bfs(capacity, parent, source, sink):", "function_name": "bfs", "parameter_list": "(capacity, parent, source, sink)" }, { "docstring": null, "function_declaration": "def edmonds_karp(capacity, source, sink):", "function_name": "edmonds...
[ 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, deque\n\ndef bfs_capacity_path(flow, source, sink, path):\n visited = set()\n queue = deque([source])\n visited.add(s...
trial_gpt4o_3
{ "original_instruction": "", "prompt_id": "00044369", "row_id": 44369, "seed_ids": "[19967]" }
0.521151
Taco_44369
I
[ "bfs", "edmonds_karp", "analyze_network", "simulate_datasets", "main" ]
5
[ [ "analyze_network", "edmonds_karp" ], [ "edmonds_karp", "bfs" ], [ "simulate_datasets", "analyze_network" ] ]
3
[]
false
[]
false
pytest
true
[]
true
6d64e36426266906ff6de7dbd4579862b8e1da29
900d3b16c43ea8d36938c85f99f35868792d0655
v1.0
instruct
Taco
Taco_44390_I
Crypto messaging service "SecuMessage" is designed to allow secure communication between users by encrypting messages. Given an encryption mechanism, your task is to implement this encryption and decryption algorithms. The encryption mechanism works as follows: 1. Each letter in the message is shifted by a fixed numb...
def encrypt_message(shift, message): """ Encrypts the message by shifting its letters by the given shift value. """ encrypted_message = [] for char in message: new_char = chr(((ord(char) - ord('a') + shift) % 26) + ord('a')) encrypted_message.append(new_char) return ''.join(encry...
from solution import encrypt_message, decrypt_message, process_message def test_encrypt_message_with_positive_shift(): assert encrypt_message(3, "secure") == "vhfxuh" def test_decrypt_message_with_positive_shift(): assert decrypt_message(3, "vhfxuh") == "secure" def test_encrypt_message_with_negative_shift()...
[ { "docstring": "Encrypts the message by shifting its letters by the given shift value.", "function_declaration": "def encrypt_message(shift, message):", "function_name": "encrypt_message", "parameter_list": "(shift, message)" }, { "docstring": "Decrypts the message by reversing the shift its...
[ 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 encrypt_message(message, shift):\n \"\"\"\n Encrypts the message by shifting each letter by the shift value.\n Wraps around the alphabet if necessary....
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00044390", "row_id": 44390, "seed_ids": "[20595]" }
0.612239
Taco_44390
I
[ "encrypt_message", "decrypt_message", "process_message" ]
3
[ [ "process_message", "decrypt_message" ], [ "process_message", "encrypt_message" ] ]
2
[]
false
[]
false
pytest
true
[]
true
cac081e9920521c0e2d19d3c9ad5863a37037d46
94d541ec52bd7e2fc9aff19500701ce22e3f4c74
v1.0
instruct
Taco
Taco_44427_I
You are given a grid of digits representing a city map where each digit indicates the height of the building at that position. Your task is to find the number of "peaks" in the grid. A peak is defined as a building whose height is greater than or equal to the heights of all its adjacent buildings (consider the building...
def count_peaks(grid): def is_peak(grid, i, j): directions = [(-1, -1), (-1, 0), (-1, 1), (0, -1), (0, 1), (1, -1), (1, 0), (1, 1)] for di, dj in directions: ni, nj = i + di, j + dj if 0 <= ni < len(grid) and 0 <= nj < len(g...
from solution import count_peaks_in_city_map def test_example_1(): input_str = '3 3\n1 2 1\n2 3 2\n1 2 1' assert count_peaks_in_city_map(input_str) == 1 def test_example_2(): input_str = '4 4\n3 3 3 3\n3 4 4 3\n3 4 4 3\n3 3 3 3' assert count_peaks_in_city_map(input_str) == 4 def test_single_peak(): ...
[ { "docstring": null, "function_declaration": "def count_peaks(grid):", "function_name": "count_peaks", "parameter_list": "(grid)" }, { "docstring": null, "function_declaration": "def parse_input(input_str):", "function_name": "parse_input", "parameter_list": "(input_str)" }, ...
[ 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 count_peaks(grid):\n \"\"\"\n Counts the number of peak buildings in the grid.\n \n A peak is defined as a building whose height is greater than or...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00044427", "row_id": 44427, "seed_ids": "[23547]" }
0.673653
Taco_44427
I
[ "count_peaks", "parse_input", "count_peaks_in_city_map" ]
3
[ [ "count_peaks_in_city_map", "count_peaks" ], [ "count_peaks_in_city_map", "parse_input" ] ]
2
[ "parse_input" ]
false
[]
false
pytest
true
[]
true
78294be61526868b0d1da85e80f59e1e3c18f47e
a905aeb2a4f01062f35ee8992cdb54af337268d4
v1.0
instruct
Taco
Taco_44439_I
You are given two strings, `s` and `t`. The string `s` consists of alphabetic characters and special characters '#'. The character '#' acts as a backspace, i.e., it removes the last non-special character of `s`. Your task is to determine whether the final processed string `s` is equal to string `t`. Write a function t...
def apply_backspace(s): """ Applies the backspace operation on the string s. """ result = [] for char in s: if char == '#': if result: result.pop() else: result.append(char) return ''.join(result) def is_backspace_equal(s, t): """ ...
from solution import apply_backspace, is_backspace_equal, process_test_cases def test_apply_backspace(): assert apply_backspace("ab#c") == "ac" assert apply_backspace("ab##") == "" assert apply_backspace("a##c") == "c" assert apply_backspace("a#b#c#") == "" def test_is_backspace_equal(): assert is...
[ { "docstring": "Applies the backspace operation on the string s.", "function_declaration": "def apply_backspace(s):", "function_name": "apply_backspace", "parameter_list": "(s)" }, { "docstring": "Determines if the processed string s is equal to string t.", "function_declaration": "def i...
[ 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 process_string(s):\n result = []\n for char in s:\n if char == '#':\n if result:\n result.pop()\n else:\n ...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00044439", "row_id": 44439, "seed_ids": "[9882]" }
0.719727
Taco_44439
I
[ "apply_backspace", "is_backspace_equal", "process_test_cases" ]
3
[ [ "is_backspace_equal", "apply_backspace" ], [ "process_test_cases", "is_backspace_equal" ] ]
2
[ "process_test_cases" ]
false
[]
false
pytest
true
[]
true
08f789cf0fa784520c22b525b68ecda60b5ac326
66320cedcd435b60bffd13512072a9f816bc249f
v1.0
instruct
Taco
Taco_44492_I
The city of Gridland is built on an n x m grid. Some cells have buildings blocking the view, and you need to find the largest possible rectangle of vacant cells in order to build a new park. Vacant cells are denoted by 0, while cells with buildings are denoted by 1. Write a program to determine the area of the largest...
def max_histogram_area(histogram): stack = [] max_area = 0 index = 0 while index < len(histogram): if not stack or histogram[stack[-1]] <= histogram[index]: stack.append(index) index += 1 else: top_of_stack = stack.pop() area = (histogram[...
from solution import max_rectangle def test_max_rectangle_1(): grid = [ [1, 0, 1, 0], [0, 0, 1, 0], [0, 0, 0, 0], [1, 0, 1, 1] ] assert max_rectangle(grid) == 4 def test_max_rectangle_2(): grid = [ [0, 1, 0, 0, 1], [1, 1, 0, 0, 0], [0, 0, 0, 1, 0...
[ { "docstring": null, "function_declaration": "def max_histogram_area(histogram):", "function_name": "max_histogram_area", "parameter_list": "(histogram)" }, { "docstring": null, "function_declaration": "def max_rectangle(grid):", "function_name": "max_rectangle", "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 max_histogram_area(histogram):\n \"\"\"Helper function to calculate max area in a histogram\"\"\"\n stack = []\n max_area = 0\n index = 0\n\n wh...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00044492", "row_id": 44492, "seed_ids": "[12729]" }
0.642079
Taco_44492
I
[ "max_histogram_area", "max_rectangle" ]
2
[ [ "max_rectangle", "max_histogram_area" ] ]
1
[]
false
[]
false
pytest
true
[]
true
bff1604cca570575fb9794a2712034d3fc8177d7
fbd6e01a8c2b2b592a6e1b7158b2885f2021dea1
v1.0
instruct
Taco
Taco_44507_I
A company wants to optimize their bus routes. They have a set of bus stops and routes between them. Each route has a specific travel time. They want to find out the minimum travel time required to reach each bus stop from a given starting bus stop. The company provides you with an undirected graph where vertices repre...
import heapq def dijkstra(n, graph, start): """ Compute the shortest travel times from the starting bus stop to all other bus stops. Parameters: n: int - Number of bus stops. graph: List[Tuple[int, int, int]] - List of bus routes (u, v, w). start: int - Starting bus stop. Returns:...
from solution import minimum_travel_times def test_minimum_travel_times_case_1(): n = 4 m = 4 edges = [(1, 2, 4), (1, 3, 2), (2, 3, 1), (3, 4, 5)] start = 1 assert minimum_travel_times(n, m, edges, start) == [0, 3, 2, 7] def test_minimum_travel_times_case_2(): n = 6 m = 7 edges = [(1, ...
[ { "docstring": "Compute the shortest travel times from the starting bus stop to all other bus stops.\n\nParameters:\nn: int - Number of bus stops.\ngraph: List[Tuple[int, int, int]] - List of bus routes (u, v, w).\nstart: int - Starting bus stop.\n\nReturns:\nList[Union[int, str]] - List of shortest travel time...
[ 0, 1, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl", "solution_code": "import heapq\n\ndef dijkstra(n, m, edges, start):\n INF = float('inf')\n adj = [[] for _ in range(n)]\n for u, v, w in edges:\n adj[u-1].append((w,...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00044507", "row_id": 44507, "seed_ids": "[3962]" }
0.776274
Taco_44507
I
[ "dijkstra", "minimum_travel_times" ]
2
[ [ "minimum_travel_times", "dijkstra" ] ]
1
[]
false
[]
false
pytest
true
[]
true
f7795952eec203a13518aee5b56bf0cea926da42
525b1a86d955b154fd4d9a6177b24093229b688a
v1.0
instruct
Taco
Taco_44522_I
Eleanor is managing a network of computers for a scientific research organization. The network consists of n computers (numbered from 1 to n) and m bidirectional cables (numbered from 1 to m) connecting pairs of computers. Each cable has a bandwidth capacity and a cost associated with its usage. Eleanor needs to selec...
import heapq def find(parent, i): if parent[i] == i: return i else: parent[i] = find(parent, parent[i]) return parent[i] def union(parent, rank, x, y): root_x = find(parent, x) root_y = find(parent, y) if root_x != root_y: if rank[root_x] > rank[root_y]: ...
import pytest from solution import maximum_bandwidth_within_budget def test_case1(): assert maximum_bandwidth_within_budget(4, 5, 20, [(1, 2, 5, 4), (2, 3, 6, 5), (3, 4, 4, 3), (1, 3, 2, 6), (1, 4, 3, 8)]) == 15 def test_case2(): assert maximum_bandwidth_within_budget(3, 3, 7, [(1, 2, 3, 8), (2, 3, 2, 5), (1...
[ { "docstring": null, "function_declaration": "def find(parent, i):", "function_name": "find", "parameter_list": "(parent, i)" }, { "docstring": null, "function_declaration": "def union(parent, rank, x, y):", "function_name": "union", "parameter_list": "(parent, rank, x, y)" }, ...
[ 0, 0, 0, 0, 0, 0, 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": "import heapq\nfrom collections import defaultdict\n\ndef maximum_bandwidth(n, m, B, cables):\n def kruskal(n, edges):\n parent = list(range(n))\n ...
trial_gpt4o_7
{ "original_instruction": "", "prompt_id": "00044522", "row_id": 44522, "seed_ids": "[10461]" }
0.599457
Taco_44522
I
[ "find", "union", "maximum_bandwidth_within_budget" ]
3
[ [ "maximum_bandwidth_within_budget", "find" ], [ "maximum_bandwidth_within_budget", "union" ], [ "union", "find" ] ]
3
[]
false
[]
false
pytest
true
[]
true
3efe0dc895257f6cf32d09a2be7935f7664a3a0c
f8e76c5adfadf79eb8580bc2c5900bb43fe75792
v1.0
instruct
Taco
Taco_44616_I
We have an array of N elements where each element represents the age of a person in a community. Write a function to determine the number of people whose age is both greater than a given X and a prime number. Constraints * All values in input are integers. * 1 \leq N \leq 100 * 1 \leq age_i \leq 100 * 1 \leq X \leq 1...
import math def is_prime(n): """ Helper function to check if a number is prime. """ if n <= 1: return False if n == 2: return True # 2 is the only even prime number if n % 2 == 0: return False for i in range(3, int(math.sqrt(n)) + 1, 2): if n % i == 0: ...
from solution import count_prime_ages_greater_than_x def test_example_1(): assert count_prime_ages_greater_than_x(6, 10, [11, 14, 17, 18, 19, 21]) == 3 def test_example_2(): assert count_prime_ages_greater_than_x(5, 20, [22, 23, 24, 29, 30]) == 2 def test_all_ages_non_prime(): assert count_prime_ages_gre...
[ { "docstring": "Helper function to check if a number is prime.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Counts the number of ages that are both greater than X and prime numbers.", "function_declaration": "def co...
[ 1, 0, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl", "solution_code": "import math\n\ndef is_prime(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...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00044616", "row_id": 44616, "seed_ids": "[10687]" }
0.60408
Taco_44616
I
[ "is_prime", "count_prime_ages_greater_than_x" ]
2
[ [ "count_prime_ages_greater_than_x", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
1d0a9f9a7a9ecc6aa9d84967a34182548c13f27f
c8ef190373ad1687e5f16b28cedbe592ced07898
v1.0
instruct
Taco
Taco_44659_I
Write a function that takes an integer `n` and returns the largest palindrome number less than `n`. ### Examples ```python largest_palindrome(123) => 121 # 121 is the largest palindrome number less than 123 largest_palindrome(1000) => 999 # 999 is a palindrome and less than 1000 largest_palindrome(10) => 9 # 9 is...
def is_palindrome(number): """ Checks if a given number is a palindrome. """ str_num = str(number) return str_num == str_num[::-1] def largest_palindrome(n): """ Returns the largest palindrome number less than n. """ for num in range(n-1, -1, -1): if is_palindrome(num): ...
from solution import largest_palindrome def test_palindrome_below_123(): assert largest_palindrome(123) == 121 def test_palindrome_below_1000(): assert largest_palindrome(1000) == 999 def test_palindrome_below_10(): assert largest_palindrome(10) == 9 def test_palindrome_below_1(): assert largest_pal...
[ { "docstring": "Checks if a given number is a palindrome.", "function_declaration": "def is_palindrome(number):", "function_name": "is_palindrome", "parameter_list": "(number)" }, { "docstring": "Returns the largest palindrome number less than n.", "function_declaration": "def largest_pa...
[ 0, 0, 0, 1 ]
1
hard
0.25
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl", "solution_code": "def largest_palindrome(n):\n \"\"\"\n Returns the largest palindrome number less than n.\n \"\"\"\n # Iterate from n-1 to 1 to find the largest palindr...
trial_gpt4o_4
{ "original_instruction": "", "prompt_id": "00044659", "row_id": 44659, "seed_ids": "[14047]" }
0.783569
Taco_44659
I
[ "is_palindrome", "largest_palindrome" ]
2
[ [ "largest_palindrome", "is_palindrome" ] ]
1
[]
false
[]
false
pytest
true
[]
true
0d7b914d9bc7bd5dbe05c75834342c45fb611d45
b54821dafe7b297be7056ab9c306996797ba9e95
v1.0
instruct
Taco
Taco_44675_I
Given n cities and m direct flights between them, find if it’s possible to travel between any two cities by only using these flights. If it is possible, determine the minimum number of flights required to visit all cities starting from any city. Each of the cities is numbered from 1 to n. -----Input----- The first l...
def bfs(start, adj_list, visited): """ Perform BFS on the graph to mark all reachable nodes from the start node. """ queue = [start] while queue: node = queue.pop(0) for neighbor in adj_list[node]: if not visited[neighbor]: visited[neighbor] = True ...
from solution import can_travel_and_min_flights def test_case_1(): n = 4 m = 4 flights = [(1, 2), (2, 3), (3, 4), (4, 1)] assert can_travel_and_min_flights(n, m, flights) == 3 def test_case_2(): n = 4 m = 2 flights = [(1, 2), (2, 3)] assert can_travel_and_min_flights(n, m, flights) == ...
[ { "docstring": "Perform BFS on the graph to mark all reachable nodes from the start node.", "function_declaration": "def bfs(start, adj_list, visited):", "function_name": "bfs", "parameter_list": "(start, adj_list, visited)" }, { "docstring": null, "function_declaration": "def can_travel...
[ 0, 1, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl", "solution_code": "def find_min_flights(n, m, flights):\n from collections import defaultdict, deque\n \n if n == 1:\n return 0\n \n graph = defaultdict(list)\n...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00044675", "row_id": 44675, "seed_ids": "[11217]" }
0.761871
Taco_44675
I
[ "bfs", "can_travel_and_min_flights" ]
2
[ [ "can_travel_and_min_flights", "bfs" ] ]
1
[]
false
[]
false
pytest
true
[]
true
fb246535d41323e6203acce2dda15821251b65af
49cafe3b84551e8b5f829f988e6d430655630000
v1.0
instruct
Taco
Taco_44682_I
A string is called a cyclic permutation of another string if it can be obtained by shifting its characters circularly any number of times. Write a program that, given two strings, determines if one is a cyclic permutation of the other. For example, the strings "abcd" and "dabc" are cyclic permutations of each other b...
def is_cyclic_permutation(s1, s2): """ Determines if s1 is a cyclic permutation of s2. """ if len(s1) != len(s2): return False return s2 in (s1 + s1) def check_cyclic_permutations(pairs): """ Given a list of string pairs, return a list of "yes" or "no" indicating if one string ...
from solution import is_cyclic_permutation, check_cyclic_permutations def test_is_cyclic_permutation(): assert is_cyclic_permutation("abcd", "dabc") == True assert is_cyclic_permutation("abcd", "abdc") == False assert is_cyclic_permutation("abc", "cab") == True assert is_cyclic_permutation("aa", "aa") ...
[ { "docstring": "Determines if s1 is a cyclic permutation of s2.", "function_declaration": "def is_cyclic_permutation(s1, s2):", "function_name": "is_cyclic_permutation", "parameter_list": "(s1, s2)" }, { "docstring": "Given a list of string pairs, return a list of \"yes\" or \"no\" indicatin...
[ 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_cyclic_permutation(str1, str2):\n \"\"\"\n Determines if str1 is a cyclic permutation of str2.\n \"\"\"\n if len(str1) != len(str2):\n re...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00044682", "row_id": 44682, "seed_ids": "[18986]" }
0.654086
Taco_44682
I
[ "is_cyclic_permutation", "check_cyclic_permutations" ]
2
[ [ "check_cyclic_permutations", "is_cyclic_permutation" ] ]
1
[]
false
[]
false
pytest
true
[]
true
3918bebc357f871ef0c0470ba8e673c03ee54294
90d01ebaef1fa3bef670f9c1882f8d49e68efcca
v1.0
instruct
Taco
Taco_44685_I
Given a grid of letters and a word, your task is to determine if the word exists in the grid. The word can be constructed from letters of sequentially adjacent cells, where "adjacent" cells are those horizontally or vertically neighboring. The same cell may not be used twice in the construction of the word. ### Input ...
def exists_in_grid(grid, word): rows = len(grid) cols = len(grid[0]) word_len = len(word) def dfs(x, y, index): if index == word_len: return True if x < 0 or x >= rows or y < 0 or y >= cols or grid[x][y] != word[index]: return False temp = grid[x][y] ...
def test_exists_in_grid(): grid1 = [['a', 'b', 'c', 'e'], ['s', 'f', 'c', 's'], ['a', 'd', 'e', 'e']] word1 = "abcced" assert exists_in_grid(grid1, word1) == True grid2 = [['a', 'b', 'c', 'e'], ['s', 'f', 'c', 's'], ['a', 'd', 'e', 'e']] word2 = "see" assert exists_in_grid(grid2, word2) == True...
[ { "docstring": null, "function_declaration": "def exists_in_grid(grid, word):", "function_name": "exists_in_grid", "parameter_list": "(grid, word)" }, { "docstring": null, "function_declaration": "def word_exists_in_grids(grids):", "function_name": "word_exists_in_grids", "parame...
[ 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 word_exists_in_grid(grid, word):\n m, n = len(grid), len(grid[0])\n \n def dfs(x, y, word):\n if not word:\n return True\n if...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00044685", "row_id": 44685, "seed_ids": "[14992]" }
0.775462
Taco_44685
I
[ "exists_in_grid", "word_exists_in_grids", "parse_input", "main" ]
4
[ [ "word_exists_in_grids", "exists_in_grid" ] ]
1
[ "parse_input" ]
false
[]
false
pytest
false
[]
true
6220369322907a3db914b695bf7d362f151145f1
c28fd007ba9eb46a0927d662b5e2d343b25f8090
v1.0
instruct
Taco
Taco_44726_I
In a forest, there are N trees positioned on a 2D grid. Each tree is represented by its coordinates (x_i, y_i). Lumberjacks need to cut down all trees, but they can only move between adjacent trees. The adjacent tree to a tree at (x_i, y_i) is a tree located at any of (x_i+1, y_i), (x_i-1, y_i), (x_i, y_i+1), or (x_i, ...
import itertools def calculate_distance(point1, point2): """ Calculate the Manhattan distance between two points. """ return abs(point1[0] - point2[0]) + abs(point1[1] - point2[1]) def find_min_energy(trees): """ Find the minimum energy required to cut down all trees and return to the starting...
from solution import minimum_energy_required def test_minimum_energy_basic(): assert minimum_energy_required(3, [(0, 0), (1, 0), (0, 1)]) == 4 def test_single_tree(): assert minimum_energy_required(1, [(0, 0)]) == 0 def test_two_trees(): assert minimum_energy_required(2, [(0, 0), (1, 1)]) == 4 def t...
[ { "docstring": "Calculate the Manhattan distance between two points.", "function_declaration": "def calculate_distance(point1, point2):", "function_name": "calculate_distance", "parameter_list": "(point1, point2)" }, { "docstring": "Find the minimum energy required to cut down all trees and ...
[ 0, 0, 0, 1, 1 ]
2
medium
0.4
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl", "solution_code": "from itertools import permutations\n\ndef minimum_energy(N, trees):\n def manhattan_distance(tree1, tree2):\n return abs(tree1[0] - tree2[0]) + abs(tree1...
trial_gpt4o_3
{ "original_instruction": "", "prompt_id": "00044726", "row_id": 44726, "seed_ids": "[23888]" }
0.678734
Taco_44726
I
[ "calculate_distance", "find_min_energy", "minimum_energy_required" ]
3
[ [ "find_min_energy", "calculate_distance" ], [ "minimum_energy_required", "find_min_energy" ] ]
2
[]
false
[]
false
pytest
true
[]
true
6b66c1c8a810f72f78f1d0a42bc9f0503b0dcd11
029794b7d8f42bae2e58de72a9c8a0ce40b993af
v1.0
instruct
Taco
Taco_44748_I
You are given a grid of size n x m where each cell contains a number representing the height of a building at that position. A water reservoir is placed over the grid that collects rainwater in the gaps between buildings. Determine the maximum amount of water that can be trapped between the buildings after a rain. Th...
def max_trapped_water(grid, n, m): if n < 3 or m < 3: return 0 left_max = [[0]*m for _ in range(n)] right_max = [[0]*m for _ in range(n)] top_max = [[0]*m for _ in range(n)] bottom_max = [[0]*m for _ in range(n)] for i in range(n): left_max[i][0] = grid[i][0] for j in r...
from solution import max_trapped_water, solve_trapped_water def test_example1(): grid = [ [1, 2, 1], [2, 1, 2], [1, 1, 1] ] n, m = 3, 3 assert max_trapped_water(grid, n, m) == 0 def test_example2(): grid = [ [3, 3, 3], [3, 0, 3], [3, 3, 3] ] ...
[ { "docstring": null, "function_declaration": "def max_trapped_water(grid, n, m):", "function_name": "max_trapped_water", "parameter_list": "(grid, n, m)" }, { "docstring": null, "function_declaration": "def solve_trapped_water(test_cases):", "function_name": "solve_trapped_water", ...
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl", "solution_code": "def calculate_trapped_water(n, m, grid):\n if n < 3 or m < 3:\n return 0\n\n left_max = [[0] * m for _ in range(n)]\n right_max = [[0] * m for _ in...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00044748", "row_id": 44748, "seed_ids": "[17999]" }
0.689621
Taco_44748
I
[ "max_trapped_water", "solve_trapped_water", "parse_input", "main" ]
4
[ [ "solve_trapped_water", "max_trapped_water" ] ]
1
[ "parse_input" ]
false
[]
false
pytest
true
[]
true
6530c57a34d23b42623adb34f1bfd155efdabbd8
5967fd295cf5d2177aec0c76beeb5ce872336dc8
v1.0
instruct
Taco
Taco_44763_I
The planet of Zog has a unique network of inter-connected cities, each city represented as a node and each route between them as an edge with a certain distance. Aliens on Zog want to establish a central logistics center that minimizes the total travel distance from this center to all other cities, for their efficient ...
import heapq def dijkstra(graph, start, n): """ Perform Dijkstra's algorithm to find the shortest paths from start node to all other nodes in a weighted graph. """ distances = {i: float('inf') for i in range(1, n + 1)} distances[start] = 0 priority_queue = [(0, start)] while priority_q...
def test_solution(): from solution import find_central_logistics_center # Test case 1 n = 4 edges = [(1, 2, 4), (1, 3, 2), (2, 3, 1), (3, 4, 7)] assert find_central_logistics_center(n, edges) == 3 # Test case 2 n = 3 edges = [(1, 2, 1), (2, 3, 1), (1, 3, 2)] assert find_central_log...
[ { "docstring": "Perform Dijkstra's algorithm to find the shortest paths from start node to all other nodes in a weighted graph.", "function_declaration": "def dijkstra(graph, start, n):", "function_name": "dijkstra", "parameter_list": "(graph, start, n)" }, { "docstring": null, "function...
[ 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 optimal_city(N, M, routes):\n def dijkstra(source):\n dist = [float('inf')] * (N + 1)\n dist[source] = 0\n pq = [(0, so...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00044763", "row_id": 44763, "seed_ids": "[2655]" }
0.698479
Taco_44763
I
[ "dijkstra", "find_central_logistics_center", "solve" ]
3
[ [ "find_central_logistics_center", "dijkstra" ], [ "solve", "find_central_logistics_center" ] ]
2
[]
false
[]
false
pytest
true
[]
true
fdcfc226d056d84f735c2bf30f580b696751d4ed
1795bd7e1587dfde6b642999bfc762cdce24277f
v1.0
instruct
Taco
Taco_44806_I
A company has a transportation system that moves goods between different locations. Each location is represented as a node, and each direct route between two locations is represented as an edge with a given weight corresponding to the cost of transportation. Due to cost constraints, the company wants to ensure that the...
def find(parent, i): if parent[i] == i: return i else: return find(parent, parent[i]) def union(parent, rank, x, y): xroot = find(parent, x) yroot = find(parent, y) if rank[xroot] < rank[yroot]: parent[xroot] = yroot elif rank[xroot] > rank[yroot]: parent[yr...
from solution import get_mst_cost def test_mst_basic(): assert get_mst_cost(4, [(1, 2, 1), (2, 3, 4), (3, 4, 2), (4, 1, 3)]) == 6 def test_mst_disconnected(): assert get_mst_cost(4, [(1, 2, 1), (2, 3, 4)]) == -1 # Node 4 is disconnected def test_mst_single_node(): assert get_mst_cost(1, []) == 0 def te...
[ { "docstring": null, "function_declaration": "def find(parent, i):", "function_name": "find", "parameter_list": "(parent, i)" }, { "docstring": null, "function_declaration": "def union(parent, rank, x, y):", "function_name": "union", "parameter_list": "(parent, rank, x, y)" }, ...
[ 0, 1, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl", "solution_code": "def find(parent, i):\n if parent[i] == i:\n return i\n else:\n parent[i] = find(parent, parent[i])\n return parent[i]\n\ndef union(paren...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00044806", "row_id": 44806, "seed_ids": "[23979]" }
0.751512
Taco_44806
I
[ "find", "union", "get_mst_cost" ]
3
[ [ "get_mst_cost", "find" ], [ "get_mst_cost", "union" ], [ "union", "find" ] ]
3
[]
false
[]
false
pytest
true
[]
true
361951993ec0f3e44fa764ad49897fcad9b67892
6c7cca42859fa6b54222425974ce4bba515151f6
v1.0
instruct
Taco
Taco_44895_I
You are given a patch of rectangular tiles arranged in a grid with $R$ rows and $C$ columns. Each tile can either be plain (represented by 0) or have an obstacle (represented by 1). You need to start in the top-left corner of the grid and reach the bottom-right corner while navigating around the obstacles. You can move...
def unique_paths_with_obstacles(grid): if not grid or grid[0][0] == 1 or grid[-1][-1] == 1: return 0 R, C = len(grid), len(grid[0]) dp = [[0] * C for _ in range(R)] dp[0][0] = 1 for r in range(R): for c in range(C): if grid[r][c] == 1: dp[r][c] = 0 ...
import pytest from solution import process_input def test_example_1(): raw_input = "2\n3 3\n0 0 0\n0 1 0\n0 0 0\n2 2\n0 1\n1 0\n" result = process_input(raw_input) assert result == [2, 0] def test_no_obstacles(): raw_input = "1\n3 3\n0 0 0\n0 0 0\n0 0 0\n" result = process_input(raw_input) ass...
[ { "docstring": null, "function_declaration": "def unique_paths_with_obstacles(grid):", "function_name": "unique_paths_with_obstacles", "parameter_list": "(grid)" }, { "docstring": null, "function_declaration": "def solve_number_of_unique_paths(test_cases):", "function_name": "solve_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 unique_paths_with_obstacles(grid):\n if not grid or grid[0][0] == 1 or grid[-1][-1] == 1:\n return 0\n\n R, C = len(grid), len(grid[0])\n dp = ...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00044895", "row_id": 44895, "seed_ids": "[4568]" }
0.716566
Taco_44895
I
[ "unique_paths_with_obstacles", "solve_number_of_unique_paths", "parse_input", "process_input" ]
4
[ [ "process_input", "parse_input" ], [ "process_input", "solve_number_of_unique_paths" ], [ "solve_number_of_unique_paths", "unique_paths_with_obstacles" ] ]
3
[ "parse_input", "process_input" ]
false
[]
false
pytest
true
[]
true
1f1c85af3f2d2dffd60e0757f01bf4cd108fe194
49f4c29c679609d4b3a6a211bb1384a850a51dc5
v1.0
instruct
Taco
Taco_44905_I
**Problem Statement:** Alice is teaching a class of young students the concept of prime numbers. She comes up with a fun exercise for the class. She provides each student with a list of numbers and asks them to replace each non-prime number in the list with the nearest smaller prime number. For example, if the number i...
def is_prime(num): """ Check if a number is prime. """ if num <= 1: return False if num == 2: return True if num % 2 == 0: return False for i in range(3, int(num**0.5) + 1, 2): if num % i == 0: return False return True def nearest_smaller_prime(num): ...
from solution import is_prime, nearest_smaller_prime, transform_list def test_is_prime(): assert is_prime(2) == True assert is_prime(3) == True assert is_prime(4) == False assert is_prime(17) == True assert is_prime(18) == False def test_nearest_smaller_prime(): assert nearest_smaller_prime(10...
[ { "docstring": "Check if a number is prime. ", "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": "Find the nearest smaller prime number less than the given number. ", "function_declaration": "def nearest_smaller_prime(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 Check if a number is prime.\n \"\"\"\n if num <= 1:\n return False\n if num <= 3:\n return True\n if ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00044905", "row_id": 44905, "seed_ids": "[19597]" }
0.607557
Taco_44905
I
[ "is_prime", "nearest_smaller_prime", "transform_list" ]
3
[ [ "nearest_smaller_prime", "is_prime" ], [ "transform_list", "is_prime" ], [ "transform_list", "nearest_smaller_prime" ] ]
3
[]
false
[]
false
pytest
true
[]
true
330349e6424e9b91520b12ab2d5dbbd7b21e83a6
f11338127b88a1eea5be48badfe69dc4d5bbd2e3
v1.0
instruct
Taco
Taco_44923_I
Given an undirected graph represented by a set of nodes and edges, determine the minimum number of edges needed to add so that the graph becomes connected. A graph is connected if there is a path between any pair of nodes. Input The input consists of multiple test cases. The first line contains an integer t (1 ≤ t ≤ ...
def find_parent(parent, node): if parent[node] != node: parent[node] = find_parent(parent, parent[node]) return parent[node] def union(parent, rank, node1, node2): root1 = find_parent(parent, node1) root2 = find_parent(parent, node2) if root1 != root2: if rank[root1] > rank...
from solution import min_edges_to_connect_graph def test_example_cases(): assert min_edges_to_connect_graph([ (4, 2, [(1, 2), (3, 4)]), (5, 3, [(1, 2), (2, 3), (4, 5)]), (3, 0, []) ]) == [1, 1, 2] def test_single_node_cases(): assert min_edges_to_connect_graph([ (1, 0, []),...
[ { "docstring": null, "function_declaration": "def find_parent(parent, node):", "function_name": "find_parent", "parameter_list": "(parent, node)" }, { "docstring": null, "function_declaration": "def union(parent, rank, node1, node2):", "function_name": "union", "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(parent, x):\n if parent[x] != x:\n parent[x] = find(parent, parent[x])\n return parent[x]\n\ndef union(parent, rank, x, y):\n rootX = find...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00044923", "row_id": 44923, "seed_ids": "[8847]" }
0.762061
Taco_44923
I
[ "find_parent", "union", "min_edges_to_connect_graph" ]
3
[ [ "min_edges_to_connect_graph", "find_parent" ], [ "min_edges_to_connect_graph", "union" ], [ "union", "find_parent" ] ]
3
[]
false
[]
false
pytest
true
[]
true
1cca738dbd59cb963b63d3535b5e00b1b23c6dff
c7b0ff108684065d11b092145753970fb491e508
v1.0
instruct
Taco
Taco_44956_I
Given an array B of M non-negative integers, find the maximum possible sum of elements you can obtain by modifying the array such that each element can only be either kept the same or replaced with any one of its prime factors. ----- Input Format ----- - The first line contains a single integer P, the number of test...
def sieve(n): primes = [] is_prime = [True] * (n + 1) for p in range(2, n + 1): if is_prime[p]: primes.append(p) for multiple in range(p * p, n + 1, p): is_prime[multiple] = False return primes def generate_factors(n): factors = [[] for _ in range(n +...
from solution import max_possible_sum def test_sample_input_1(): assert max_possible_sum([12, 15, 7]) == 34 assert max_possible_sum([23, 10]) == 33 assert max_possible_sum([4, 6, 8, 9]) == 27 def test_large_number(): assert max_possible_sum([1000000]) == 1000000 # Since 1000000 has multiple factors, ...
[ { "docstring": null, "function_declaration": "def sieve(n):", "function_name": "sieve", "parameter_list": "(n)" }, { "docstring": null, "function_declaration": "def generate_factors(n):", "function_name": "generate_factors", "parameter_list": "(n)" }, { "docstring": null,...
[ 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 typing import List, Tuple\n\ndef sieve(n):\n \"\"\"\n Sieve of Eratosthenes to generate prime factors for every number up to n.\n \"\"\"\n smalles...
trial_gpt4o_5
{ "original_instruction": "", "prompt_id": "00044956", "row_id": 44956, "seed_ids": "[19146]" }
0.662512
Taco_44956
I
[ "sieve", "generate_factors", "max_possible_sum", "process_test_cases", "main" ]
5
[ [ "max_possible_sum", "generate_factors" ], [ "process_test_cases", "max_possible_sum" ] ]
2
[ "process_test_cases" ]
false
[]
false
pytest
true
[]
true
a96192a2f0b2cc180568cadeac6a14828c37ed07
9e4ad6cd1c710e7d0447d96986209963ee570281
v1.0
instruct
Taco
Taco_45018_I
A bakery likes to deliver fresh bread to its customers. The bakery delivery system operates on predefined delivery routes. Each delivery person has a specific route that they follow, and each route is marked by delivery points. A delivery person can only deliver bread to points on their route without skipping any point...
def common_delivery_point(routes): """ Determines if all delivery routes have at least one common delivery point. :param routes: List of lists, where each list contains delivery points for a specific route. :return: 'yes' if there is at least one common delivery point, otherwise 'no'. """ # Usin...
import pytest from solution import common_delivery_point, solve, parse_input, format_output def test_common_delivery_point(): assert common_delivery_point([[1, 2, 3], [2, 3, 4], [3, 4, 5]]) == "yes" assert common_delivery_point([[1, 2, 3], [4, 5, 6]]) == "no" assert common_delivery_point([[7, 8, 9, 10], [7...
[ { "docstring": "Determines if all delivery routes have at least one common delivery point.\n:param routes: List of lists, where each list contains delivery points for a specific route.\n:return: 'yes' if there is at least one common delivery point, otherwise 'no'.", "function_declaration": "def common_deliv...
[ 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 common_delivery_point(test_cases):\n results = []\n \n for case in test_cases:\n n = case[0]\n routes = case[1:]\n \n # Ge...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00045018", "row_id": 45018, "seed_ids": "[4536]" }
0.687257
Taco_45018
I
[ "common_delivery_point", "solve", "parse_input", "format_output" ]
4
[ [ "solve", "common_delivery_point" ] ]
1
[ "parse_input", "format_output" ]
false
[]
false
pytest
true
[]
true
7d4eefe1f2d2c555a73d0cf65ac012a8b63b3223
2e9d4ffb28e63cdf8c8c26bed82bce0c7832e4f6
v1.0
instruct
Taco
Taco_45123_I
Sophie is a wildlife photographer, and she wants to capture images of a rare species of bird that nest in a particular type of tree. She has discovered that these trees are always part of a unique type of forest spread known as teardrop forests. A teardrop forest can be represented as a binary tree where each node cont...
class TreeNode: def __init__(self, val=0, left=None, right=None): self.val = val self.left = left self.right = right def build_tree(level_order): if not level_order or level_order[0] == -1: return None root = TreeNode(level_order[0]) queue = [(root, 0)] front = 0 ...
def test_teardrop_forest_height(): input_str = "2\n9\n1 2 3 -1 -1 4 5 -1 -1 -1 -1 6 7\n7\n1 2 3 -1 4 -1 5" expected_output = [4, 3] assert main(input_str) == expected_output def test_single_node(): input_str = "1\n1\n5" expected_output = [1] assert main(input_str) == expected_output def test_a...
[]
[ 0, 0, 0, 0, 0, 0, 1, 0, 0, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl", "solution_code": "class TreeNode:\n def __init__(self, value):\n self.value = value\n self.left = None\n self.right = None\n\ndef build_tree(level_order):\n ...
trial_gpt4o_6
{ "original_instruction": "", "prompt_id": "00045123", "row_id": 45123, "seed_ids": "[5696]" }
0.675664
Taco_45123
I
[ "build_tree", "tree_height", "teardrop_forest_height", "main" ]
4
[ [ "teardrop_forest_height", "build_tree" ], [ "teardrop_forest_height", "tree_height" ] ]
2
[]
false
[ "TreeNode" ]
true
pytest
false
[]
true
ed551d2b85c2d31db7a45fbe2b218b51d2eacb15
c044fa9e0a9131d5519c3378f58dc8d04062c95d
v1.0
instruct
Taco
Taco_45183_I
Given a string s and a list of words words[], return the number of words that are a subsequence of s. A subsequence of a string is a new string generated from the original string with some characters(can be none) deleted without changing the relative order of the remaining characters. Example: Input: s = "abcde" words...
def is_subsequence(s, word): """ Helper function to determine if 'word' is a subsequence of 's'. """ it = iter(s) return all(char in it for char in word) def numMatchingSubseq(s, words): """ Returns the number of words that are a subsequence of s. """ count = 0 for word in words...
from solution import numMatchingSubseq def test_num_matching_subseq_example(): assert numMatchingSubseq("abcde", ["a", "bb", "acd", "ace"]) == 3 def test_num_matching_subseq_empty_string(): assert numMatchingSubseq("", ["a", "bb", "acd", "ace"]) == 0 def test_num_matching_subseq_no_subsequences(): assert...
[ { "docstring": "Helper function to determine if 'word' is a subsequence of 's'.", "function_declaration": "def is_subsequence(s, word):", "function_name": "is_subsequence", "parameter_list": "(s, word)" }, { "docstring": "Returns the number of words that are a subsequence of s.", "functi...
[ 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 numMatchingSubseq(s, words):\n \"\"\"\n Returns the number of words that are a subsequence of s.\n \"\"\"\n from collections import defaultdict\n ...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00045183", "row_id": 45183, "seed_ids": "[2302]" }
0.748908
Taco_45183
I
[ "is_subsequence", "numMatchingSubseq" ]
2
[ [ "numMatchingSubseq", "is_subsequence" ] ]
1
[]
false
[]
false
pytest
true
[]
true
887a13f861ea83631519403d01c71b3a40955380
86b4bc90eadd658472c72972b6f86a95c0bf9e3f
v1.0
instruct
Taco
Taco_45194_I
A delivery company is working on optimizing its route planning system. The goal is to minimize the total distance covered while delivering packages to multiple addresses. The company operates in a grid-like city where each cell represents an address and the distance between any two cells is calculated using the Manhatt...
import itertools def manhattan_distance(x1, y1, x2, y2): return abs(x1 - x2) + abs(y1 - y2) def find_shortest_route(x0, y0, addresses): min_distance = float('inf') address_permutations = itertools.permutations(addresses) for perm in address_permutations: current_distance = 0 curre...
from solution import find_shortest_route def test_example_case(): x0, y0 = 0, 0 addresses = [(1, 1), (2, 2), (3, 3)] assert find_shortest_route(x0, y0, addresses) == 12 def test_single_address(): x0, y0 = 0, 0 addresses = [(1, 1)] assert find_shortest_route(x0, y0, addresses) == 4 def test_tw...
[ { "docstring": null, "function_declaration": "def manhattan_distance(x1, y1, x2, y2):", "function_name": "manhattan_distance", "parameter_list": "(x1, y1, x2, y2)" }, { "docstring": null, "function_declaration": "def find_shortest_route(x0, y0, addresses):", "function_name": "find_sh...
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl", "solution_code": "from itertools import permutations\n\ndef manhattan_distance(p1, p2):\n return abs(p1[0] - p2[0]) + abs(p1[1] - p2[1])\n\ndef minimum_route_distance(warehouse, ...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00045194", "row_id": 45194, "seed_ids": "[14425]" }
0.753742
Taco_45194
I
[ "manhattan_distance", "find_shortest_route" ]
2
[ [ "find_shortest_route", "manhattan_distance" ] ]
1
[]
false
[]
false
pytest
true
[]
true
0b1fca351abe03de7da44d40bc7b977ca1d1d5d8
717ae08229c72bee412ef366205e7b8108eb04eb
v1.0
instruct
Taco
Taco_45208_I
Alice is interested in finding unique permutations of a given string. She wants to know the total number of unique permutations possible for her string. Given a string S which contains lowercase alphabets, find the number of unique permutations of the string. Input Format: The first line contains an integer T, the nu...
from math import factorial from collections import Counter def unique_permutations_count(s): """ Returns the number of unique permutations of the string s. """ char_count = Counter(s) denominator = 1 for count in char_count.values(): denominator *= factorial(count) return factorial(...
from solution import unique_permutations_count def test_example_cases(): assert unique_permutations_count("abc") == 6 assert unique_permutations_count("aab") == 3 def test_single_character_case(): assert unique_permutations_count("a") == 1 def test_repeated_characters_case(): assert unique_permutatio...
[ { "docstring": "Returns the number of unique permutations of the string s.", "function_declaration": "def unique_permutations_count(s):", "function_name": "unique_permutations_count", "parameter_list": "(s)" }, { "docstring": null, "function_declaration": "def process_test_cases(test_cas...
[ 1, 0, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl", "solution_code": "from math import factorial\nfrom collections import Counter\n\ndef unique_permutations_count(s):\n \"\"\"\n Returns the number of unique permutations of the ...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00045208", "row_id": 45208, "seed_ids": "[19468]" }
0.717054
Taco_45208
I
[ "unique_permutations_count", "process_test_cases", "gather_input", "output_results" ]
4
[ [ "process_test_cases", "unique_permutations_count" ] ]
1
[ "process_test_cases" ]
false
[]
false
pytest
true
[]
true
7e0f572c2126a364b38e8fb76557278033fa9b4d
835bcdd439ab1a1d49dc6a3a6f26f3ef375c1fdb
v1.0
instruct
Taco
Taco_45214_I
You are given a 2D grid of size 'n x m' representing a map where: - `'1'` represents land. - `'0'` represents water. An island is formed by connecting adjacent lands horizontally or vertically. You must write a function that finds and returns the number of islands. Input The first line contains two integers `n` and...
def num_islands(grid): """ Finds and returns the number of islands in the given grid. """ if not grid: return 0 n = len(grid) m = len(grid[0]) visited = [[False for _ in range(m)] for _ in range(n)] def dfs(x, y): if x < 0 or y < 0 or x >= n or y >= m or grid[x]...
def test_num_islands_single(): assert islands_from_input('3 3\n111\n010\n111') == 1 def test_num_islands_multiple(): assert islands_from_input('4 5\n11000\n11000\n00100\n00011') == 3 def test_num_islands_none(): assert islands_from_input('3 3\n000\n000\n000') == 0 def test_num_islands_one_row(): asse...
[ { "docstring": "Finds and returns the number of islands in the given grid.", "function_declaration": "def num_islands(grid):", "function_name": "num_islands", "parameter_list": "(grid)" }, { "docstring": "Parses the input and returns the grid and consists of the main logic to calculate the n...
[ 1, 1, 0 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl", "solution_code": "def count_islands(grid):\n \"\"\"\n Returns the number of islands in the given grid.\n \"\"\"\n if not grid:\n return 0\n\n n = len(grid)\n ...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00045214", "row_id": 45214, "seed_ids": "[11807]" }
0.595873
Taco_45214
I
[ "num_islands", "islands_from_input" ]
2
[ [ "islands_from_input", "num_islands" ] ]
1
[]
false
[]
false
pytest
false
[]
true
57659862e8aadc0ed626cd01a093f34b5b522975
5e17e42c92eae85647e26ad97c9722ef27139287
v1.0
instruct
Taco
Taco_45223_I
In a distant future, machines have become capable of forming social groups. Machines in a group communicate with each other through a network. Interestingly, they maintain records of their communications. Each communication is represented as a message from machine X to machine Y. Given such directed messages, we want t...
from collections import defaultdict def detect_cycle_util(v, visited, rec_stack, graph): visited[v] = True rec_stack[v] = True for neighbor in graph[v]: if not visited[neighbor]: if detect_cycle_util(neighbor, visited, rec_stack, graph): return True elif rec...
from solution import has_cycle_in_network def test_sample_input(): test_cases = [ (4, 4, [(1, 2), (2, 3), (3, 4), (4, 1)]), (3, 2, [(1, 2), (2, 3)]) ] assert has_cycle_in_network(test_cases) == ["Yes", "No"] def test_no_edges(): test_cases = [ (3, 0, []), (5, 0, []) ...
[ { "docstring": null, "function_declaration": "def detect_cycle_util(v, visited, rec_stack, graph):", "function_name": "detect_cycle_util", "parameter_list": "(v, visited, rec_stack, graph)" }, { "docstring": null, "function_declaration": "def detect_cycle(n, edges):", "function_name"...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl", "solution_code": "from collections import defaultdict\n\ndef has_cycle(N, communications):\n adj_list = defaultdict(list)\n for x, y in communications:\n adj_list[x].ap...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00045223", "row_id": 45223, "seed_ids": "[867]" }
0.708139
Taco_45223
I
[ "detect_cycle_util", "detect_cycle", "has_cycle_in_network" ]
3
[ [ "detect_cycle", "detect_cycle_util" ], [ "has_cycle_in_network", "detect_cycle" ] ]
2
[]
false
[]
false
pytest
true
[]
true
d4b7cad56664b73280a96448847ef58a1748414c
54be30fdaaf98f42f8f24a1becdbf517b0afd467
v1.0
instruct
Taco
Taco_45234_I
In a country where roads are organized as a tree of cities (i.e., a connected acyclic graph), each road has a beauty index. The beauty index of a set of roads is defined as the sum of their indices mod 10^9 + 7. You are a tourist who wants to travel from city A to city B. To make your travel memorable, you only want to...
MOD = 10**9 + 7 def dfs(graph, node, parent, target, path_sum, path): if node == target: return path_sum for neighbor, weight in graph[node]: if neighbor != parent: result = dfs(graph, neighbor, node, target, path_sum + weight, path + [weight]) if result is not None...
from solution import max_path_beauty def test_example_1(): n = 5 roads = [ (1, 2, 4), (1, 3, 6), (2, 4, 5), (2, 5, 3) ] A = 3 B = 4 assert max_path_beauty(n, roads, A, B) == 15 def test_small_tree(): n = 2 roads = [ (1, 2, 1) ] A = 1 ...
[ { "docstring": null, "function_declaration": "def dfs(graph, node, parent, target, path_sum, path):", "function_name": "dfs", "parameter_list": "(graph, node, parent, target, path_sum, path)" }, { "docstring": null, "function_declaration": "def max_path_beauty(n, roads, A, B):", "fun...
[ 0, 0, 1, 0 ]
1
hard
0.25
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl", "solution_code": "def max_path_beauty(n, roads, A, B):\n from collections import defaultdict, deque\n \n MOD = 10**9 + 7\n \n # Create an adjacency list to represent ...
trial_gpt4o_3
{ "original_instruction": "", "prompt_id": "00045234", "row_id": 45234, "seed_ids": "[21633]" }
0.664858
Taco_45234
I
[ "dfs", "max_path_beauty" ]
2
[ [ "max_path_beauty", "dfs" ] ]
1
[]
false
[]
false
pytest
true
[]
true
39bd3867bfdb358db545562fd5a3a255f7f7c05a
6b49c02836429851593dc5c4148847160b2657a3
v1.0
instruct
Taco
Taco_45255_I
There exists a unique sequence of integers a1, a2, ..., an that is subjected to the following iterative process: 1. Initially, the sequence contains only one element a1 = k. 2. For each subsequent element, ai = pi for i = 2 to n, where pi is the position of i-th prime number in the sequence obtained so far. Let's def...
def is_prime(num): if num <= 1: return False for i in range(2, int(num**0.5) + 1): if num % i == 0: return False return True def find_sequence(k, n): sequence = [k] current_num = k + 1 while len(sequence) < n: if is_prime(current_num): sequence...
from solution import is_prime, find_sequence 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(9) == False assert is_prime(11) == True def test_find_sequence_case_1(): assert find_sequence(1, 5)...
[ { "docstring": null, "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": null, "function_declaration": "def find_sequence(k, n):", "function_name": "find_sequence", "parameter_list": "(k, n)" } ]
[ 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 generate_primes(up_to):\n \"\"\"\n Helper function to generate a list of prime numbers up to a specified number.\n \"\"\"\n primes = []\n candid...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00045255", "row_id": 45255, "seed_ids": "[8674]" }
0.671116
Taco_45255
I
[ "is_prime", "find_sequence" ]
2
[ [ "find_sequence", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
e3d413cf5b25d60bd77d6dd5963fb16edc8af2a4
fa842ae4bfa438107dd0d8af600f9c4360112a42
v1.0
instruct
Taco
Taco_45306_I
In a remote village, the residents decided to construct a series of underground tunnels connecting various important locations like the town hall, market, school, and hospital. The tunnels are represented as a graph where nodes are the important locations and edges are the tunnels with their respective lengths. The vil...
def find(parent, u): if parent[u] != u: parent[u] = find(parent, parent[u]) return parent[u] def union(parent, rank, u, v): root_u = find(parent, u) root_v = find(parent, v) if root_u != root_v: if rank[root_u] > rank[root_v]: parent[root_v] = root_u elif rank[r...
def test_example_1(): input_data = """5 6\n1 2 3\n2 3 2\n3 4 4\n4 5 1\n1 3 5\n2 5 6""" assert main(input_data) == "2\n10" def test_example_2(): input_data = """4 5\n1 2 3\n1 3 2\n3 4 4\n2 4 1\n2 3 5""" assert main(input_data) == "2\n6" def test_minimum_case(): input_data = """2 1\n1 2 1""" ass...
[ { "docstring": null, "function_declaration": "def find(parent, u):", "function_name": "find", "parameter_list": "(parent, u)" }, { "docstring": null, "function_declaration": "def union(parent, rank, u, v):", "function_name": "union", "parameter_list": "(parent, rank, u, v)" }, ...
[ 0, 0, 1 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl", "solution_code": "def kruskal(n, edges):\n # Helper function to find the root of a node\n def find(parent, x):\n if parent[x] != x:\n parent[x] = find(parent...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00045306", "row_id": 45306, "seed_ids": "[15008]" }
0.614863
Taco_45306
I
[ "find", "union", "remove_redundant_tunnels", "main" ]
4
[ [ "remove_redundant_tunnels", "find" ], [ "remove_redundant_tunnels", "union" ], [ "union", "find" ] ]
3
[]
false
[]
false
pytest
false
[]
true
1b360f8172a3c18bc03cead531871b9d72baef89
6ab59bc18ef431c5a85d4d0b2152009f8072679c
v1.0
instruct
Taco
Taco_45423_I
A group of treasure hunters is exploring an ancient temple, and they encountered a corridor guarded by a series of traps. Each trap is represented by a cell in a grid, and the corridor has exactly M rows and N columns. The hunters need to navigate from the top-left corner to the bottom-right corner of the grid, but cer...
def count_paths(grid): MOD = 10**9 + 7 M = len(grid) N = len(grid[0]) # Create a dp array for storing number of ways to reach each cell dp = [[0] * N for _ in range(M)] # Start position always has one way to be reached dp[0][0] = 1 for i in range(M): for j in range...
def test_count_paths_example_1(): input_str = "3 3\n...\n.#.\n..." assert solve(input_str) == 2 def test_count_paths_no_path(): input_str = "3 3\n.#.\n.#.\n.#." assert solve(input_str) == 0 def test_count_paths_single_column(): input_str = "3 1\n.\n.\n." assert solve(input_str) == 1 def tes...
[ { "docstring": null, "function_declaration": "def count_paths(grid):", "function_name": "count_paths", "parameter_list": "(grid)" }, { "docstring": null, "function_declaration": "def solve(input_str):", "function_name": "solve", "parameter_list": "(input_str)" } ]
[ 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": "MOD = 10**9 + 7\n\ndef count_paths(m, n, grid):\n dp = [[0] * n for _ in range(m)]\n \n if grid[0][0] == '#':\n return 0\n \n dp[0][0] = 1\n ...
trial_gpt4o_4
{ "original_instruction": "", "prompt_id": "00045423", "row_id": 45423, "seed_ids": "[13908]" }
0.791291
Taco_45423
I
[ "count_paths", "solve" ]
2
[ [ "solve", "count_paths" ] ]
1
[]
false
[]
false
pytest
false
[]
true
019fdb4ebb7d2ed1a51335a5a5be4170f01b4fbb
a7988572916365622e2f58fd169a869b0e2e4dbd
v1.0
instruct
Taco
Taco_45447_I
Write a program that helps to organize a workshop by ensuring there is no schedule conflict between multiple sessions. Each session is represented by a start time and end time in the format HH:MM-HH:MM. Your task is to determine if any sessions overlap or if all sessions can be scheduled without conflicts. Input - The...
def time_to_minutes(time_str): """ Convert a time string in HH:MM format to minutes since midnight. """ hours, minutes = map(int, time_str.split(':')) return hours * 60 + minutes def check_schedule_conflict(sessions): """ Determine if there is any schedule conflict among the sessions. E...
from solution import organize_workshop, check_schedule_conflict def test_no_conflicts(): sessions = ["09:00-10:30", "10:45-12:00", "12:30-13:30"] assert check_schedule_conflict(sessions) == "No conflicts" def test_schedule_conflict(): sessions = ["09:00-10:30", "10:15-11:00", "11:00-12:30"] assert che...
[ { "docstring": "Convert a time string in HH:MM format to minutes since midnight.", "function_declaration": "def time_to_minutes(time_str):", "function_name": "time_to_minutes", "parameter_list": "(time_str)" }, { "docstring": "Determine if there is any schedule conflict among the sessions.\n...
[ 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 check_schedule_conflicts(t, test_cases):\n def time_to_minutes(time):\n hh, mm = map(int, time.split(':'))\n return hh * 60 + mm\n\n result...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00045447", "row_id": 45447, "seed_ids": "[7742]" }
0.637819
Taco_45447
I
[ "time_to_minutes", "check_schedule_conflict", "organize_workshop" ]
3
[ [ "check_schedule_conflict", "time_to_minutes" ], [ "organize_workshop", "check_schedule_conflict" ] ]
2
[]
false
[]
false
pytest
true
[]
true
d126fa52d47f3a324399066feab5f59f6fdd4ed3
e27eb86bc6ad8b0cb7e5ac14c7282e577e50415c
v1.0
instruct
Taco
Taco_45487_I
A logistics company handles the delivery of packages in a city which is represented as a grid of size n x m. Each cell in the grid either contains a delivery point (denoted as '*') or is empty (denoted as '.'). The company wants to find the shortest path that visits all the delivery points exactly once and returns to t...
from itertools import permutations from collections import deque import sys import numpy as np def bfs(start, grid, n, m): """ Perform BFS to find the shortest path from start to all delivery points. """ queue = deque([start]) distance = {start: 0} while queue: x, y = queue.popleft() ...
def test_example_case(): grid = [ ['*', '.', '.'], ['.', '*', '.'], ['.', '.', '*'] ] assert shortest_path_length(3, 3, grid) == 8 def test_all_empty(): grid = [ ['.', '.', '.'], ['.', '.', '.'], ['.', '.', '.'] ] assert shortest_path_length(3, 3,...
[ { "docstring": "Perform BFS to find the shortest path from start to all delivery points.", "function_declaration": "def bfs(start, grid, n, m):", "function_name": "bfs", "parameter_list": "(start, grid, n, m)" }, { "docstring": null, "function_declaration": "def shortest_path_length(n, m...
[ 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 itertools import permutations\nfrom collections import deque\n\ndef find_shortest_path_length(n, m, grid):\n # Extract all delivery point coordinates and a...
trial_gpt4o_3
{ "original_instruction": "", "prompt_id": "00045487", "row_id": 45487, "seed_ids": "[12369]" }
0.758496
Taco_45487
I
[ "bfs", "shortest_path_length" ]
2
[ [ "shortest_path_length", "bfs" ] ]
1
[]
false
[]
false
pytest
false
[ "numpy" ]
false
4ea130badc0f7725dcd65ac75e0e3e3f479346a4
54f0a92ecb7d5a63955c1fc00dc36fab5280043d
v1.0
instruct
Taco
Taco_45490_I
The kingdom of Algorithmsland is composed of numerous villages, each connected by a series of roads. Villagers want to place a fountain in their kingdom such that it minimizes the longest distance any villager has to walk to get water. The kingdom has $n$ villages and $n-1$ roads, making it a tree structure. Each road...
from collections import defaultdict, deque def find_furthest(node, n, graph): dist = [-1] * (n + 1) queue = deque([node]) dist[node] = 0 furthest_node, max_dist = node, 0 while queue: curr = queue.popleft() for nei, length in graph[curr]: if dist[nei] == -1: ...
from solution import minimize_max_distance def test_minimize_max_distance_basic(): assert minimize_max_distance(5, [(1, 2, 3), (2, 3, 4), (3, 4, 5), (4, 5, 6)]) == 9 def test_minimize_max_distance_single_node(): assert minimize_max_distance(1, []) == 0 def test_minimize_max_distance_two_nodes(): assert m...
[ { "docstring": null, "function_declaration": "def find_furthest(node, n, graph):", "function_name": "find_furthest", "parameter_list": "(node, n, graph)" }, { "docstring": null, "function_declaration": "def minimize_max_distance(n, roads):", "function_name": "minimize_max_distance", ...
[ 0, 0, 0, 0, 0, 0, 0, 0, 1 ]
1
hard
0.111
{ "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 bfs(start, n, adj):\n dist = [-1] * (n + 1)\n dist[start] = 0\n queue = deque([start])\n \n farthe...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00045490", "row_id": 45490, "seed_ids": "[13001]" }
0.699912
Taco_45490
I
[ "find_furthest", "minimize_max_distance" ]
2
[ [ "minimize_max_distance", "find_furthest" ] ]
1
[]
false
[]
false
pytest
true
[]
true
30b0aa466468aa698608f8fac1388995681dfc68
f892ccbf7d3ab20327515075f8c5361a8dcbc072
v1.0
instruct
Taco
Taco_45518_I
In a far land, King Arthur has several knights who are tasked with patrolling the kingdom. The kingdom is represented as a grid of size `N x M`. Each cell in the grid can either contain a knight, be empty, or be an impassable obstacle. The goal is to ensure that all empty cells in the grid are reachable by at least one...
from collections import deque def bfs(n, m, grid, start): visited = [[False] * m for _ in range(n)] queue = deque([start]) visited[start[0]][start[1]] = True while queue: x, y = queue.popleft() # Traverse in all 4 possible directions (up, down, left, right) for nx, ny in [(x-1,...
def test_min_knights_required_initial_knight_sufficient(): cases = [ ((3, 3), [ 'K.#', '.#.', '...' ]) ] assert min_knights_required(1, cases) == [1] def test_min_knights_required_additional_knight_needed(): cases = [ ((2, 4), [ 'K...
[ { "docstring": null, "function_declaration": "def bfs(n, m, grid, start):", "function_name": "bfs", "parameter_list": "(n, m, grid, start)" }, { "docstring": null, "function_declaration": "def min_knights_required(t, cases):", "function_name": "min_knights_required", "parameter_l...
[ 0, 0, 0, 0, 0, 0, 0, 0, 1 ]
1
hard
0.111
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl", "solution_code": "def bfs(grid, start, N, M):\n queue = [start]\n reachable = set([start])\n directions = [(-1, 0), (1, 0), (0, -1), (0, 1)]\n \n while queue:\n ...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00045518", "row_id": 45518, "seed_ids": "[18317]" }
0.683582
Taco_45518
I
[ "bfs", "min_knights_required" ]
2
[ [ "min_knights_required", "bfs" ] ]
1
[]
false
[]
false
pytest
false
[]
true
c53d51dacafaef64e058e2d1023859150fdcad27
2eebf150a08ec371b5ebbf920b56e0379c0a8ceb
v1.0
instruct
Taco
Taco_45573_I
Lee has a task of organizing a list of book titles by their length. He wants to determine which book title in the list is the shortest. Write a program that helps Lee find the shortest book title. ------ Input Format ------ - The first line will contain an integer N - the number of book titles. - The next N lines w...
def find_shortest_title(titles): """ Finds the shortest book title from a list of book titles. Parameters: titles (list): A list of book titles Returns: str: The shortest book title """ if not titles: return "" shortest_title = titles[0] shortest_length...
from solution import find_shortest_title def test_find_shortest_title_single_title(): assert find_shortest_title(["The Great Gatsby"]) == "The Great Gatsby" def test_find_shortest_title_same_length_titles(): assert find_shortest_title(["AA", "BB", "CC", "A"]) == "A" def test_find_shortest_title_varied_length...
[ { "docstring": "Finds the shortest book title from a list of book titles.\n\nParameters:\ntitles (list): A list of book titles\n\nReturns:\nstr: The shortest book title", "function_declaration": "def find_shortest_title(titles):", "function_name": "find_shortest_title", "parameter_list": "(titles)" ...
[ 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_shortest_title(titles):\n \"\"\"\n Finds the shortest book title from a list of book titles.\n \n Parameters:\n titles (list): A list of bo...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00045573", "row_id": 45573, "seed_ids": "[13422]" }
0.631077
Taco_45573
I
[ "find_shortest_title", "process_book_titles" ]
2
[ [ "process_book_titles", "find_shortest_title" ] ]
1
[]
false
[]
false
pytest
true
[]
true
9c97fe5788314c6b4b6108488b33c6c320a02eea
5ad548fffd828ccd72ec14571a63323b4e0ce43b
v1.0
instruct
Taco
Taco_45574_I
Given the head of a singly linked list, return the list after sorting it in ascending order. Example 1: Input: head = [4,2,1,3] Output: [1,2,3,4] Example 2: Input: head = [-1,5,3,4,0] Output: [ -1,0,3,4,5] Example 3: Input: head = [] Output: [] Constraints: The number of nodes in the list is in the range [0, 50...
class ListNode: def __init__(self, val=0, next=None): self.val = val self.next = next def sortList(head): """ Sorts a linked list in ascending order. :param head: ListNode, the head of the linked list :return: ListNode, the head of the sorted linked list """ if not head or ...
from solution import ListNode, sortList def list_to_linked_list(elements): if not elements: return None head = ListNode(elements[0]) current = head for element in elements[1:]: current.next = ListNode(element) current = current.next return head def linked_list_to_list(head)...
[]
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl", "solution_code": "class ListNode:\n def __init__(self, val=0, next=None):\n self.val = val\n self.next = next\n\ndef sort_list(head):\n \"\"\"\n Sorts a singl...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00045574", "row_id": 45574, "seed_ids": "[7485]" }
0.499175
Taco_45574
I
[ "sortList", "get_middle", "merge" ]
3
[ [ "sortList", "get_middle" ], [ "sortList", "merge" ] ]
2
[]
false
[ "ListNode" ]
true
pytest
true
[]
true
deb656ebf31cd38b9f16cd1802cf364fb7a4ccb2
183defe8f633cbebb1bbe36be8493c09815fcb4c
v1.0
instruct
Taco
Taco_45607_I
In a kingdom far away, there are N cities connected by M bi-directional roads. Each road has a specific distance associated with it. The kingdom wants to build a network such that every city is reachable from any other city, but they don't want to spend more distance than required. Therefore, they need to select a set ...
def find_parent(parent, i): if parent[i] == i: return i return find_parent(parent, parent[i]) def union(parent, rank, x, y): root_x = find_parent(parent, x) root_y = find_parent(parent, y) if rank[root_x] < rank[root_y]: parent[root_x] = root_y elif rank[root_x] > rank[root...
def test_minimal_spanning_tree(): N, M = 4, 5 roads = [ (1, 2, 3), (1, 3, 1), (3, 2, 3), (2, 4, 6), (3, 4, 5) ] assert minimal_spanning_tree(N, M, roads) == 9 def test_minimal_spanning_tree_single_edge(): N, M = 2, 1 roads = [ (1, 2, 3) ] ...
[ { "docstring": null, "function_declaration": "def find_parent(parent, i):", "function_name": "find_parent", "parameter_list": "(parent, i)" }, { "docstring": null, "function_declaration": "def union(parent, rank, x, y):", "function_name": "union", "parameter_list": "(parent, rank...
[ 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_parent(parent, i):\n if parent[i] == i:\n return i\n return find_parent(parent, parent[i])\n\ndef union(parent, rank, x, y):\n root_x = fi...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00045607", "row_id": 45607, "seed_ids": "[22345]" }
0.774142
Taco_45607
I
[ "find_parent", "union", "kruskal_mst", "minimal_spanning_tree" ]
4
[ [ "kruskal_mst", "find_parent" ], [ "kruskal_mst", "union" ], [ "minimal_spanning_tree", "kruskal_mst" ], [ "union", "find_parent" ] ]
4
[]
false
[]
false
pytest
false
[]
true
b8ec85287915b982c94a1c4dda7f35d57c09e30b
819780c9dc1bc69d532eab8d5ddaefcf9fa8568e
v1.0
instruct
Taco
Taco_45608_I
A treasure map provides coordinates of treasures buried in a $2000 \times 2000$ grid. Each treasure emits a magnetic field detectable within a certain radius. Charlotte must collect exactly three treasures while ensuring that she never passes through an area under the influence of more than one magnetic field at a time...
def can_collect_three_treasures(n, treasures): import itertools treasures.sort() def are_fields_separate(t1, t2): x1, y1, r1 = t1 x2, y2, r2 = t2 dx = x1 - x2 dy = y1 - y2 distance_squared = dx * dx + dy * dy radius_sum_squared = (r1 + r2) * (r1 + r2...
def test_example_1(monkeypatch): from io import StringIO monkeypatch.setattr('sys.stdin', StringIO('5\n100 100 50\n800 800 40\n1500 1500 60\n300 300 30\n1200 1200 50\n')) read_input_and_solve() def test_example_2(monkeypatch): from io import StringIO monkeypatch.setattr('sys.stdin', StringIO('4\n50...
[ { "docstring": null, "function_declaration": "def can_collect_three_treasures(n, treasures):", "function_name": "can_collect_three_treasures", "parameter_list": "(n, treasures)" }, { "docstring": null, "function_declaration": "def read_input_and_solve():", "function_name": "read_inpu...
[ 0, 0, 0, 1 ]
1
hard
0.25
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl", "solution_code": "def find_treasures(n, treasures):\n treasures.sort()\n \n def can_travel(treasures):\n selected = [treasures[0]]\n \n for i in range(...
trial_gpt4o_4
{ "original_instruction": "", "prompt_id": "00045608", "row_id": 45608, "seed_ids": "[21029]" }
0.565355
Taco_45608
I
[ "can_collect_three_treasures", "read_input_and_solve" ]
2
[ [ "read_input_and_solve", "can_collect_three_treasures" ] ]
1
[]
false
[]
false
pytest
false
[]
true
cd509f525d080dc43176c844995276fdeb12d000
9c7ff05fd58c84ecd899d45d44c37beb7114f6ab
v1.0
instruct
Taco
Taco_45645_I
Mia has just started learning programming and is excited to write her first function. She loves prime numbers and wants to write a function that identifies prime numbers in a given range. Help Mia by writing a program that takes two integers, `a` and `b`, as input and returns a list of all prime numbers in the range [a...
import math 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(math.sqrt(n)) + 1, 2): if n % i == 0: return False return True...
from solution import is_prime, primes_in_range, find_primes_in_multiple_ranges def test_is_prime(): assert is_prime(2) == True assert is_prime(3) == True assert is_prime(4) == False assert is_prime(17) == True assert is_prime(21) == False assert is_prime(1) == False assert is_prime(0) == Fa...
[ { "docstring": "Helper function to check if a number is prime.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Returns a list of all prime numbers in the range [a, b] (both inclusive).", "function_declaration": "def pr...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(n):\n \"\"\"\n Returns True if n is a prime number, else False.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n retur...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00045645", "row_id": 45645, "seed_ids": "[15128]" }
0.676045
Taco_45645
I
[ "is_prime", "primes_in_range", "find_primes_in_multiple_ranges" ]
3
[ [ "find_primes_in_multiple_ranges", "primes_in_range" ], [ "primes_in_range", "is_prime" ] ]
2
[]
false
[]
false
pytest
true
[]
true
199e1794cac0e3903f4c637ae8ea30bdc1ba4fcb
bb4d7237bcf38d90360e00c5437a797a3b7de393
v1.0
instruct
Taco
Taco_45685_I
In a faraway kingdom, there is a wizard named Merlin who has $n$ magic stones. Each stone has a unique positive integer written on it. Merlin loves to experiment with the stones by arranging them in different sequences. A sequence is considered special if for every pair of consecutive stones, the sum of their numbers i...
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 can_form_special_sequence(...
from solution import solve def test_solve(): assert solve(3, [4, 5, 3]) == ["YES", "NO", "YES"] # Add more specific tests related to prime checking and sequence validation assert solve(4, [1, 2, 3, 6]) == ["YES", "YES", "YES", "NO"] assert solve(2, [10, 7]) == ["NO", "NO"] assert solve(5, [15, 2, 8...
[ { "docstring": null, "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": null, "function_declaration": "def can_form_special_sequence(n):", "function_name": "can_form_special_sequence", "parameter_list": "(n)" }...
[ 0, 0, 0, 0, 0, 0, 1, 0, 0 ]
1
hard
0.111
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(num):\n \"\"\"\n Returns True if num is a prime number, otherwise False.\n \"\"\"\n if num <= 1:\n return False\n if num <= 3:\n...
trial_gpt4o_6
{ "original_instruction": "", "prompt_id": "00045685", "row_id": 45685, "seed_ids": "[5941]" }
0.645157
Taco_45685
I
[ "is_prime", "can_form_special_sequence", "solve" ]
3
[ [ "can_form_special_sequence", "is_prime" ], [ "solve", "can_form_special_sequence" ] ]
2
[]
false
[]
false
pytest
true
[]
true
df31849526541a224663c86794d1fba33c457aaa
3177b3e712f6de8d963568d26fca99553ac428f1
v1.0
instruct
Taco
Taco_45689_I
You are tasked with transporting an item across a grid while avoiding obstacles. The grid is represented as an n x m matrix where each cell can be either empty (.) or contain an obstacle (#). You start at the top-left corner of the grid (1,1) and must reach the bottom-right corner (n,m). You are allowed to move in four...
from collections import deque def min_moves_to_reach_end(grid): n = len(grid) m = len(grid[0]) directions = [(1, 0), (-1, 0), (0, 1), (0, -1)] def is_valid(x, y): return 0 <= x < n and 0 <= y < m and grid[x][y] == '.' queue = deque([(0, 0, 0)]) # (x, y, distance) visited = se...
from solution import escape_grid def test_example_1(): input_str = "5 5\n.....\n.###.\n.#.#.\n.#.#.\n....." assert escape_grid(input_str) == 8 def test_example_2(): input_str = "4 4\n....\n.##.\n####\n...." assert escape_grid(input_str) == -1 def test_no_obstacles(): input_str = "3 3\n...\n...\n....
[ { "docstring": null, "function_declaration": "def min_moves_to_reach_end(grid):", "function_name": "min_moves_to_reach_end", "parameter_list": "(grid)" }, { "docstring": null, "function_declaration": "def parse_input(input_str):", "function_name": "parse_input", "parameter_list":...
[ 0, 1, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl", "solution_code": "from collections import deque\n\ndef min_moves(grid, n, m):\n \"\"\"\n Finds the minimum number of moves required to reach the bottom-right corner of the gri...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00045689", "row_id": 45689, "seed_ids": "[16296]" }
0.785127
Taco_45689
I
[ "min_moves_to_reach_end", "parse_input", "escape_grid" ]
3
[ [ "escape_grid", "min_moves_to_reach_end" ], [ "escape_grid", "parse_input" ] ]
2
[ "parse_input" ]
false
[]
false
pytest
true
[]
true
d07ed4a85b3dbc4c6339780473b3aaf26384434b
c62e31cb2ca183e35fa3034cdcb9b9bde57a915e
v1.0
instruct
Taco
Taco_45697_I
Create a program that calculates the total sum of the interior angles of a simple polygon with `n` sides. The provided input consists of several datasets, where each dataset supplied as an integer `n` which represents the number of sides of the polygon. Your program should continue to process each dataset until it enco...
def sum_of_interior_angles(n): """ Calculate the total sum of the interior angles of a simple polygon with n sides. Args: n (int): Number of sides of the polygon Returns: int: Total sum of the interior angles in degrees """ return (n - 2) * 180 def sum_of_interior_angles_for_p...
from solution import sum_of_interior_angles, sum_of_interior_angles_for_polygons def test_sum_of_interior_angles(): assert sum_of_interior_angles(3) == 180 assert sum_of_interior_angles(4) == 360 assert sum_of_interior_angles(5) == 540 assert sum_of_interior_angles(6) == 720 def test_sum_of_interior_a...
[ { "docstring": "Calculate the total sum of the interior angles of a simple polygon with n sides.\n\nArgs:\nn (int): Number of sides of the polygon\n\nReturns:\nint: Total sum of the interior angles in degrees", "function_declaration": "def sum_of_interior_angles(n):", "function_name": "sum_of_interior_a...
[ 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 sum_of_interior_angles(n):\n \"\"\"\n Returns the sum of the interior angles of a polygon with n sides.\n \"\"\"\n if n < 3:\n return 0\n ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00045697", "row_id": 45697, "seed_ids": "[13003]" }
0.606109
Taco_45697
I
[ "sum_of_interior_angles", "sum_of_interior_angles_for_polygons" ]
2
[ [ "sum_of_interior_angles_for_polygons", "sum_of_interior_angles" ] ]
1
[]
false
[]
false
pytest
true
[]
true
a50378629e3d44de76de35bd532cc87227babf7f
e2ff95893ac10c988a5d02ad53e6b4654ef07b90
v1.0
instruct
Taco
Taco_45723_I
You are given a binary tree and two integers, `A` and `B`. Write a function that determines whether there is a path from the root of the tree to a leaf such that the sum of the node values along the path equals `A` or `B`. Assume all node values are non-negative integers. Input - The input parameters will be: - `roo...
class TreeNode: def __init__(self, val=0, left=None, right=None): self.val = val self.left = left self.right = right def has_path_sum(root, target_sum): """ Return True if there exists a root-to-leaf path in the binary tree where the sum of the node values is equal to target_sum. ...
from solution import TreeNode, has_path_sum_any def test_has_path_sum_any_example1(): root = TreeNode(5) root.left = TreeNode(4) root.right = TreeNode(8) root.left.left = TreeNode(11) root.left.left.left = TreeNode(7) root.left.left.right = TreeNode(2) root.right.left = TreeNode(13) roo...
[]
[ 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, val=0, left=None, right=None):\n self.val = val\n self.left = left\n self.right = right\n\ndef has_pat...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00045723", "row_id": 45723, "seed_ids": "[20910]" }
0.677807
Taco_45723
I
[ "has_path_sum", "has_path_sum_any" ]
2
[ [ "has_path_sum_any", "has_path_sum" ] ]
1
[]
false
[ "TreeNode" ]
true
pytest
true
[]
true
dbdbb7f5188912b1e6306915d485c94c37cd758c
30e2c2a0ab6168e3c59827a1582800246af87956
v1.0
instruct
Taco
Taco_45844_I
Alice and Bob are avid gamers and play a game where they collect points by completing various levels. They have to complete M levels in total, and each level gives a certain number of points. Alice and Bob want to divide the levels among themselves such that their total points are as balanced as possible. We need to d...
def minimum_point_difference(M, points): total_points = sum(points) half_points = total_points // 2 dp = [0] * (half_points + 1) for point in points: for j in range(half_points, point - 1, -1): dp[j] = max(dp[j], dp[j - point] + point) best_distribution = dp[half_points...
from solution import min_difference def test_min_difference_example_1(): assert min_difference(4, [1, 4, 2, 7]) == 0 def test_min_difference_example_2(): assert min_difference(3, [5, 8, 6]) == 3 # "|(5 + 6) - 8| = 3" def test_min_difference_example_3(): assert min_difference(5, [3, 1, 4, 2, 2]) == 0 # ...
[ { "docstring": null, "function_declaration": "def minimum_point_difference(M, points):", "function_name": "minimum_point_difference", "parameter_list": "(M, points)" }, { "docstring": null, "function_declaration": "def min_difference(M, points):", "function_name": "min_difference", ...
[ 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 minimum_difference(M, points):\n total_points = sum(points)\n half_points = total_points // 2\n \n # Initialize the DP array\n dp = [False] * (h...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00045844", "row_id": 45844, "seed_ids": "[24172]" }
0.669545
Taco_45844
I
[ "minimum_point_difference", "min_difference" ]
2
[ [ "min_difference", "minimum_point_difference" ] ]
1
[]
false
[]
false
pytest
true
[]
true
775587ab04bb43921c9d917db01f58fdfe36e5dd
18061e0f82dbe88039d16e0ec2efc09fbe9822ed
v1.0
instruct
Taco
Taco_45984_I
You are given a list of n elements and a series of m queries. Each query consists of two integers l and r, which represents a subarray of the list. You are required to answer the queries with the sum of the Fibonacci numbers from the elements in the specified subarray. Write a program that preprocesses the list of ele...
def fibonacci(n): """Returns the nth Fibonacci number.""" if n == 0: return 0 elif n == 1: return 1 a, b = 0, 1 for _ in range(2, n + 1): a, b = b, a + b return b def preprocess_fibonacci(elements): """Precompute the Fibonacci number for each element in the list to ...
def test_fibonacci(): assert fibonacci(0) == 0 assert fibonacci(1) == 1 assert fibonacci(2) == 1 assert fibonacci(3) == 2 assert fibonacci(4) == 3 assert fibonacci(5) == 5 assert fibonacci(6) == 8 assert fibonacci(10) == 55 def test_process_queries(): n = 5 elements = [3, 1, 4, ...
[ { "docstring": "Returns the nth Fibonacci number.", "function_declaration": "def fibonacci(n):", "function_name": "fibonacci", "parameter_list": "(n)" }, { "docstring": "Precompute the Fibonacci number for each element in the list to handle queries efficiently.", "function_declaration": ...
[ 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 fib(n, memo={0: 0, 1: 1}):\n \"\"\"\n Returns the Fibonacci number of n using memoization.\n \"\"\"\n if n not in memo:\n memo[n] = fib(n-1,...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00045984", "row_id": 45984, "seed_ids": "[20991]" }
0.618025
Taco_45984
I
[ "fibonacci", "preprocess_fibonacci", "precompute_sums", "sum_of_fibonacci_in_range", "process_queries" ]
5
[ [ "preprocess_fibonacci", "fibonacci" ], [ "process_queries", "precompute_sums" ], [ "process_queries", "preprocess_fibonacci" ], [ "process_queries", "sum_of_fibonacci_in_range" ] ]
4
[ "process_queries" ]
false
[]
false
pytest
false
[]
true
bac2ea7d98308fbc5491fe048a63839271814166
fb6679a4a2a3a12e70a34f3804ba3bc96dab22e5
v1.0
instruct
Taco
Taco_46027_I
An amusement park has several roller coaster rides. The park owners want to assign each visitor to a ride such that the number of visitors on any single ride does not exceed its capacity and each visitor enjoys a ride that they are satisfied with. Each visitor has a list of rides that they are willing to go on. Given t...
def assign_rides(ride_capacities, visitors_preferences): R = len(ride_capacities) V = len(visitors_preferences) # Initial ride allocation rides_allocation = [0] * R for preferences in visitors_preferences: assigned = False for pref in preferences: if rides_alloc...
from solution import park_rides def test_example_case_1(): R = 3 ride_capacities = [2, 1, 3] V = 4 visitors_preferences = [ [1, 3], [1, 2], [2, 3], [1, 3] ] assert park_rides(R, ride_capacities, V, visitors_preferences) == "Yes" def test_example_case_2(): R ...
[ { "docstring": null, "function_declaration": "def assign_rides(ride_capacities, visitors_preferences):", "function_name": "assign_rides", "parameter_list": "(ride_capacities, visitors_preferences)" }, { "docstring": "R - number of rides\nride_capacities - List of integers denoting capacities...
[ 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 assign_rides(ride_capacities, visitors_preferences):\n R = len(ride_capacities)\n V = len(visitors_preferences)\n \n # Initial ride allocation\n ...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00046027", "row_id": 46027, "seed_ids": "[23718]" }
0.679668
Taco_46027
I
[ "assign_rides", "park_rides" ]
2
[ [ "park_rides", "assign_rides" ] ]
1
[]
false
[]
false
pytest
true
[]
true
29429d121adb6387af63fdef4cb5c38660534f7d
78b9a9033f082a5e76ebf5d30d11819cd5b3abbd
v1.0
instruct
Taco
Taco_46032_I
Given an array of integers `arr`, you need to find two integers `x` and `y` such that: 1. `x` is the sum of the maximum subarray. 2. `y` is the sum of the minimum subarray. Return the sum of `x` and `y`. -----Constraints----- - 1 \leq |arr| \leq 10^5 - -10^4 \leq arr[i] \leq 10^4 -----Input----- Input is given from...
def max_subarray_sum(arr): """ Finds the sum of the maximum subarray using Kadane's algorithm. """ max_ending_here = max_so_far = arr[0] for x in arr[1:]: max_ending_here = max(x, max_ending_here + x) max_so_far = max(max_so_far, max_ending_here) return max_so_far def min_subarr...
def test_max_subarray_sum(): assert max_subarray_sum([1, -2, 3, -2, 5]) == 6 assert max_subarray_sum([-1, -2, -3, -4]) == -1 assert max_subarray_sum([1, 2, 3, 4]) == 10 assert max_subarray_sum([3, -1, 2, -1]) == 4 def test_min_subarray_sum(): assert min_subarray_sum([1, -2, 3, -2, 5]) == -2 ass...
[ { "docstring": "Finds the sum of the maximum subarray using Kadane's algorithm.", "function_declaration": "def max_subarray_sum(arr):", "function_name": "max_subarray_sum", "parameter_list": "(arr)" }, { "docstring": "Finds the sum of the minimum subarray, using a modified Kadane's algorithm...
[ 0, 0, 1 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl", "solution_code": "def max_subarray_sum(arr):\n max_ending_here = max_so_far = arr[0]\n for num in arr[1:]:\n max_ending_here = max(num, max_ending_here + num)\n ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00046032", "row_id": 46032, "seed_ids": "[12755]" }
0.79227
Taco_46032
I
[ "max_subarray_sum", "min_subarray_sum", "sum_of_max_and_min_subarray" ]
3
[ [ "sum_of_max_and_min_subarray", "max_subarray_sum" ], [ "sum_of_max_and_min_subarray", "min_subarray_sum" ] ]
2
[]
false
[]
false
pytest
false
[]
true
9a5b0d65f8e9b2ff6306d577b405176b19f92e3e
2cd36593cdc546823ce9af73faabedeffbeec841
v1.0
instruct
Taco
Taco_46118_I
You are planning a journey across a mountainous region with a group of hikers. There are several trails that connect different peaks, and each trail has a difficulty rating. To ensure the group's safety, you need to find a route from the starting peak to the destination peak that minimizes the maximum difficulty of any...
import heapq def find_min_max_difficulty(n, m, trails): def dijkstra(src, des, adj_list): max_difficulty = [float('inf')] * (n + 1) max_difficulty[src] = 0 pq = [(0, src)] while pq: curr_difficulty, u = heapq.heappop(pq) for v, d in adj_...
from solution import hiking_journey def test_hiking_journey_basic(): n, m = 4, 5 trails = [ (1, 2, 5), (1, 3, 6), (2, 3, 2), (2, 4, 3), (3, 4, 4) ] assert hiking_journey(n, m, trails) == 5 def test_hiking_journey_minimum(): n, m = 2, 1 trails = [ ...
[ { "docstring": null, "function_declaration": "def find_min_max_difficulty(n, m, trails):", "function_name": "find_min_max_difficulty", "parameter_list": "(n, m, trails)" }, { "docstring": null, "function_declaration": "def hiking_journey(n, m, trails):", "function_name": "hiking_jour...
[ 1, 0, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl", "solution_code": "from collections import defaultdict, deque\n\ndef can_reach_with_max_difficulty(graph, n, max_difficulty):\n \"\"\"\n Determines if there is a path from node...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00046118", "row_id": 46118, "seed_ids": "[21243]" }
0.684262
Taco_46118
I
[ "find_min_max_difficulty", "hiking_journey" ]
2
[ [ "hiking_journey", "find_min_max_difficulty" ] ]
1
[]
false
[]
false
pytest
true
[]
true
b5fbbc66b566433ac5d6867661a443c9e26a818e
1119baaa1d4fc3394c339928e2478fe22a78f5f7
v1.0
instruct
Taco
Taco_46119_I
Given a binary tree, convert it into a Doubly Linked List (DLL) in such a way that the order of the DLL is the same as the Inorder traversal of the binary tree. The left and right pointers in nodes are to be used as previous and next pointers respectively in the converted DLL. The head pointer of the Doubly Linked List...
class TreeNode: def __init__(self, key): self.data = key self.left = None self.right = None class DoubleListNode: def __init__(self, key): self.data = key self.prev = None self.next = None def bToDLL(root): if not root: return None # Ini...
def test_tree_to_dll_list_case1(): # Constructing the tree: # 10 # / \ # 12 15 # / \ / # 25 30 36 root = TreeNode(10) root.left = TreeNode(12) root.right = TreeNode(15) root.left.left = TreeNode(25) root.left.right = TreeNode(30) root.ri...
[]
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl", "solution_code": "class Node:\n def __init__(self, data):\n self.data = data\n self.left = None\n self.right = None\n\ndef bToDLL(root):\n \"\"\"\n Con...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00046119", "row_id": 46119, "seed_ids": "[6701]" }
0.468965
Taco_46119
I
[ "bToDLL", "tree_to_dll_list" ]
2
[ [ "tree_to_dll_list", "bToDLL" ] ]
1
[]
false
[ "TreeNode", "DoubleListNode" ]
true
pytest
false
[]
true
3c4e6fa39cfebc7ba15668270d9b5f68b1951b9a
404515fcfe0a142dc4ea72a6f63efafbc2857bde
v1.0
instruct
Taco
Taco_46136_I
You are given a rectangular garden with rows and columns. The gardener wants to plant trees in the garden such that no two trees are in the same row, column, or diagonal. Given the dimensions of the garden, determine the number of ways the gardener can plant exactly one tree in each row and column satisfying these cond...
def is_valid(board, row, col, n): """ Function to check if a tree can be planted at board[row][col]. """ for i in range(row): if board[i] == col or abs(board[i] - col) == abs(i - row): return False return True def solve_n_trees(n, row, board, solutions): """ Function to ...
from solution import n_trees_ways def test_n_trees_ways_1(): assert n_trees_ways(1) == 1 def test_n_trees_ways_2(): assert n_trees_ways(2) == 0 def test_n_trees_ways_3(): assert n_trees_ways(3) == 0 def test_n_trees_ways_4(): assert n_trees_ways(4) == 2 def test_n_trees_ways_5(): assert n_trees...
[ { "docstring": "Function to check if a tree can be planted at board[row][col].", "function_declaration": "def is_valid(board, row, col, n):", "function_name": "is_valid", "parameter_list": "(board, row, col, n)" }, { "docstring": "Function to recursively solve the n-trees problem by backtrac...
[ 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_safe(board, row, col, n):\n # Check this row on left side and above\n for i in range(col):\n if board[row][i] == 1:\n return False\n...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00046136", "row_id": 46136, "seed_ids": "[4384]" }
0.658409
Taco_46136
I
[ "is_valid", "solve_n_trees", "n_trees_ways" ]
3
[ [ "n_trees_ways", "solve_n_trees" ], [ "solve_n_trees", "is_valid" ] ]
2
[]
false
[]
false
pytest
true
[]
true
7bd99e2b19eebd4db70a210aeccd32123e103522
1da043dd58f993736e38eeacabf1de614d928ddd
v1.0
instruct
Taco
Taco_46196_I
----Input---- The input consists of a single string s containing only lowercase English letters (1 ≤ |s| ≤ 100). ----Output---- Output a single integer representing the minimum number of contiguous substrings that can be formed from s such that each substring is a palindrome. ----Examples---- Input abac Output 2 ...
def is_palindrome(s): """ Checks if the given string is a palindrome. """ return s == s[::-1] def min_palindromic_substrings(s): """ Returns the minimum number of contiguous substrings that can be formed from s such that each substring is a palindrome. """ if is_palindrome(s): ...
from solution import is_palindrome, min_palindromic_substrings def test_is_palindrome(): assert is_palindrome("a") == True assert is_palindrome("aa") == True assert is_palindrome("ab") == False assert is_palindrome("aba") == True assert is_palindrome("abc") == False def test_min_palindromic_substr...
[ { "docstring": "Checks if the given string is a palindrome.", "function_declaration": "def is_palindrome(s):", "function_name": "is_palindrome", "parameter_list": "(s)" }, { "docstring": "Returns the minimum number of contiguous substrings that can be \nformed from s such that each substring...
[ 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 min_palindrome_substrings(s):\n \"\"\"\n Returns the minimum number of contiguous substrings that are all palindromes.\n \"\"\"\n if s == s[::-1]:\...
trial_gpt4o_4
{ "original_instruction": "", "prompt_id": "00046196", "row_id": 46196, "seed_ids": "[23676]" }
0.841273
Taco_46196
I
[ "is_palindrome", "min_palindromic_substrings" ]
2
[ [ "min_palindromic_substrings", "is_palindrome" ] ]
1
[]
false
[]
false
pytest
true
[]
true
62eedffd55fd29fd08dbeea7d086c77703228cb3
d94e232d5de411f19fac4c74fb0e3c22b4911554
v1.0
instruct
Taco
Taco_46207_I
Problem: You are given a string S of length N consisting of lowercase alphabets ('a' - 'z'). You need to perform Q operations on this string, which can be of two types: Type 1: 1 L R K: Rotate the substring S[L:R] (inclusive) to the left by K positions. Type 2: 2 L R: Query the number of distinct characters in the su...
def rotate_left(s, k): return s[k:] + s[:k] def process_operations(n, s, operations): s = list(s) result = [] for op in operations: if op[0] == 1: L, R, K = op[1], op[2], op[3] L, R = L - 1, R - 1 # convert to 0-indexed K = K % (R - L + 1) s...
from solution import process_operations def test_example_case(): n = 7 s = "abacaba" operations = [ (2, 1, 3), (1, 2, 5, 2), (2, 1, 3), (1, 1, 7, 3), (2, 4, 6) ] expected_output = [2, 2, 2] assert process_operations(n, s, operations) == expected_output d...
[ { "docstring": null, "function_declaration": "def rotate_left(s, k):", "function_name": "rotate_left", "parameter_list": "(s, k)" }, { "docstring": null, "function_declaration": "def process_operations(n, s, operations):", "function_name": "process_operations", "parameter_list": ...
[ 0, 1, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl", "solution_code": "def rotate_left(s, L, R, K):\n substring = s[L-1:R]\n K %= len(substring)\n rotated = substring[K:] + substring[:K]\n return s[:L-1] + rotated + s[R:]\...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00046207", "row_id": 46207, "seed_ids": "[10517]" }
0.829143
Taco_46207
I
[ "rotate_left", "process_operations" ]
2
[ [ "process_operations", "rotate_left" ] ]
1
[]
false
[]
false
pytest
true
[]
true
6f7feccc754f61b78fa0853a430ac741a4a60e80
32b45caec65ff17441e988ad828b988dce99811b
v1.0
instruct
Taco
Taco_46269_I
You are given a tree with N nodes (numbered from 1 to N) and (N-1) edges. Your task is to determine the longest path between any two nodes in the tree. This is known as finding the diameter of the tree. The diameter of a tree is defined as the maximum distance between any pair of nodes in the tree. The distance betwee...
from collections import deque, defaultdict def find_farthest_node(start, n, graph): visited = [-1] * (n + 1) max_distance = 0 farthest_node = start queue = deque([(start, 0)]) visited[start] = 1 while queue: node, dist = queue.popleft() for neighbor in graph[node]: ...
from solution import solve def test_case_1(): t = 2 cases = [ (4, [(1, 2), (2, 3), (2, 4)]), (5, [(1, 2), (1, 3), (3, 4), (3, 5)]) ] expected = [2, 3] assert solve(t, cases) == expected def test_case_2(): t = 1 cases = [ (3, [(1, 2), (2, 3)]) ] expected = [2...
[ { "docstring": null, "function_declaration": "def find_farthest_node(start, n, graph):", "function_name": "find_farthest_node", "parameter_list": "(start, n, graph)" }, { "docstring": null, "function_declaration": "def tree_diameter(n, edges):", "function_name": "tree_diameter", ...
[ 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": "from collections import deque, defaultdict\n\ndef find_farthest_node(start, n, graph):\n visited = [-1] * (n + 1)\n max_distance = 0\n farthest_node = sta...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00046269", "row_id": 46269, "seed_ids": "[20148]" }
0.731611
Taco_46269
I
[ "find_farthest_node", "tree_diameter", "solve" ]
3
[ [ "solve", "tree_diameter" ], [ "tree_diameter", "find_farthest_node" ] ]
2
[]
false
[]
false
pytest
true
[]
true
b30ba4dec45e38a70c4901187522b401d8cab6d2
9ca6599c442293c529e6999b972b92011f9bd517
v1.0
instruct
Taco
Taco_46273_I
Library Book Locator Sophia is a librarian responsible for managing and organizing books in a large library. Each book in the library has a unique identifier and is placed on a particular shelf. A book can only be located on a specific shelf number. The library uses an advanced inventory system to keep track of which ...
import heapq def dijkstra(graph, start, n): # Initialize distances with infinity distances = {i: float('inf') for i in range(1, n + 1)} distances[start] = 0 priority_queue = [(0, start)] while priority_queue: current_distance, current_node = heapq.heappop(priority_queue) if cur...
from solution import locate_books def test_case_1(): n, m, q = 5, 7, 3 edges = [ (1, 2, 3), (2, 3, 4), (1, 3, 8), (1, 4, 7), (4, 5, 2), (5, 3, 1), (2, 5, 5) ] start = 1 book_shelves = [3, 5, 4] assert locate_books(n, m, q, edges, start, bo...
[ { "docstring": null, "function_declaration": "def dijkstra(graph, start, n):", "function_name": "dijkstra", "parameter_list": "(graph, start, n)" }, { "docstring": null, "function_declaration": "def locate_books(n, m, q, edges, start, book_shelves):", "function_name": "locate_books",...
[ 0, 0, 0, 0, 0, 0, 1, 1, 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 heapq\n\ndef find_shortest_paths(n, m, q, edges, s, books):\n # Create adjacency list for graph\n graph = {i: [] for i in range(1, n + 1)}\n for u,...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00046273", "row_id": 46273, "seed_ids": "[17137]" }
0.625774
Taco_46273
I
[ "dijkstra", "locate_books" ]
2
[ [ "locate_books", "dijkstra" ] ]
1
[]
false
[]
false
pytest
true
[]
true
ea9805f50c5162e6bd371c2a39d906cef76b616f
68194ca0d4081da137f161a96dff92077fc7ed81
v1.0
instruct
Taco
Taco_46276_I
You are tasked with developing software that processes and analyzes vehicle parking data. Each vehicle entry is logged with the following attributes: license plate number, entry time, and exit time. The challenge is to determine the vehicle that has stayed the longest in the parking lot among a provided set of vehicle ...
from datetime import datetime def calculate_duration(entry_time, exit_time): format = "%H:%M" entry = datetime.strptime(entry_time, format) exit = datetime.strptime(exit_time, format) duration = exit - entry return duration.total_seconds() def longest_parking_vehicle(n, entries): max_duration ...
from solution import longest_parking_vehicle def test_example_case(): n = 5 entries = [ ("ABC123", "08:00", "09:30"), ("XYZ789", "07:00", "09:00"), ("LMN456", "10:15", "12:00"), ("DEF000", "09:45", "11:30"), ("GHI111", "07:30", "08:45") ] assert longest_parking_v...
[ { "docstring": null, "function_declaration": "def calculate_duration(entry_time, exit_time):", "function_name": "calculate_duration", "parameter_list": "(entry_time, exit_time)" }, { "docstring": null, "function_declaration": "def longest_parking_vehicle(n, entries):", "function_name...
[ 0, 1, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl", "solution_code": "def parse_time(time_str):\n hours, minutes = map(int, time_str.split(':'))\n return hours * 60 + minutes\n\ndef find_longest_parked_vehicle(entries):\n lo...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00046276", "row_id": 46276, "seed_ids": "[3756]" }
0.592038
Taco_46276
I
[ "calculate_duration", "longest_parking_vehicle" ]
2
[ [ "longest_parking_vehicle", "calculate_duration" ] ]
1
[]
false
[]
false
pytest
true
[]
true
d997f864dfda91575d6bc2273b319a3fd77c868c
40299b8ae13176f1bcf3b5c1d5700ac53f03a9e8
v1.0
instruct
Taco
Taco_46291_I
Given a Binary Tree and a node, your task is to print the entire level of the Binary Tree in which the given node is present. Example 1: Input: 1 / \ 2 3 / \ / \ 4 5 6 7 / 8 Target Node: 5 Output: 4 5 6 7 Explanation: The target node 5 is at level 3. All nodes at...
class TreeNode: def __init__(self, key): self.left = None self.right = None self.val = key def find_level(root, target, level): if root is None: return 0 if root.val == target: return level downlevel = find_level(root.left, target, level + 1) if downlevel != ...
import pytest from solution import TreeNode, printLevel def test_example_1(): root = TreeNode(1) root.left = TreeNode(2) root.right = TreeNode(3) root.left.left = TreeNode(4) root.left.right = TreeNode(5) root.right.left = TreeNode(6) root.right.right = TreeNode(7) root.left.left.left =...
[]
[ 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": "class Node:\n def __init__(self, key):\n self.data = key\n self.left = None\n self.right = None\n\nfrom collections import deque\n\ndef get...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00046291", "row_id": 46291, "seed_ids": "[2445]" }
0.537459
Taco_46291
I
[ "find_level", "printGivenLevel", "printLevel" ]
3
[ [ "printLevel", "find_level" ], [ "printLevel", "printGivenLevel" ] ]
2
[]
false
[ "TreeNode" ]
true
pytest
true
[]
true
35782482486b2a0b4ef02e454973751cc67762c1
745508ff0b19f00b5099bb96f7dd1726214c75c3
v1.0
instruct
Taco
Taco_46336_I
In a magical forest, there are n different types of magical creatures identified by unique integer IDs from 1 to n. Each of these creatures has a specific strength, represented as an integer. Creatures with higher strength display dominance over those with lower strength, but the relationships among them are peculiar. ...
from math import gcd from itertools import combinations def is_coprime(x, y): return gcd(x, y) == 1 def largest_alliance_size(n, strengths): max_alliance_size = 1 for r in range(2, n+1): for subset in combinations(strengths, r): if all(is_coprime(pair[0], pair[1]) for pair in combinati...
from solution import largest_alliance_size def test_example_1(): assert largest_alliance_size(6, [2, 3, 5, 7, 11, 14]) == 5 def test_example_2(): assert largest_alliance_size(5, [4, 6, 8, 10, 12]) == 1 def test_single_creature(): assert largest_alliance_size(1, [10]) == 1 def test_all_coprime(): ass...
[ { "docstring": null, "function_declaration": "def is_coprime(x, y):", "function_name": "is_coprime", "parameter_list": "(x, y)" }, { "docstring": null, "function_declaration": "def largest_alliance_size(n, strengths):", "function_name": "largest_alliance_size", "parameter_list": ...
[ 0, 0, 1 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl", "solution_code": "import math\nfrom itertools import combinations\n\ndef largest_alliance(n, strengths):\n def are_coprime(a, b):\n return math.gcd(a, b) == 1\n \n m...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00046336", "row_id": 46336, "seed_ids": "[13220]" }
0.587108
Taco_46336
I
[ "is_coprime", "largest_alliance_size" ]
2
[ [ "largest_alliance_size", "is_coprime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
854e624831906a4681b4403df07c59ef5f3e265d
c121f0fe8c21baa17e328c70533334cb256c5160
v1.0
instruct
Taco
Taco_46499_I
Polycarp received a job of transforming a given string into a palindrome by rearranging its characters. A palindrome is a sequence of characters which reads the same backwards as forwards. Polycarp can perform the following operation as many times as needed: Select any two characters of the string and swap them. Your ...
from collections import Counter def can_form_palindrome(s): """ Checks if the string can form a palindrome. """ count = Counter(s) odd_count = sum(1 for c in count.values() if c % 2 != 0) # A string can be rearranged to a palindrome if at most one character has an odd count return odd_count...
def test_transform_to_palindrome(): test_cases = [ ("aabb", ("YES", "abba")), ("racecar", ("YES", "racecar")), ("abcd", ("NO",)) ] for case in test_cases: assert transform_to_palindrome([case[0]]) == list(case[1]) def test_single_character(): assert transform_to_palindro...
[ { "docstring": "Checks if the string can form a palindrome.", "function_declaration": "def can_form_palindrome(s):", "function_name": "can_form_palindrome", "parameter_list": "(s)" }, { "docstring": "Rearranges the string into a palindrome if possible.", "function_declaration": "def rear...
[ 0, 0, 0, 0, 1 ]
1
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl", "solution_code": "from collections import Counter\n\ndef can_form_palindrome(s):\n \"\"\"\n Determines if a given string can be rearranged to form a palindrome.\n If possib...
trial_gpt4o_4
{ "original_instruction": "", "prompt_id": "00046499", "row_id": 46499, "seed_ids": "[12615]" }
0.744155
Taco_46499
I
[ "can_form_palindrome", "rearrange_to_palindrome", "transform_to_palindrome" ]
3
[ [ "transform_to_palindrome", "can_form_palindrome" ], [ "transform_to_palindrome", "rearrange_to_palindrome" ] ]
2
[]
false
[]
false
pytest
false
[]
true
31e11bd2c2b5eaee3c7777a0fff2ad2d6781d669
693f6b46b3be5764cbdcd2ae6381ef226fdcfac4
v1.0
instruct
Taco
Taco_46526_I
Alice and Bob are playing a game with a string `S` that only consists of lowercase letters. The game rules are simple: - Alice starts first and picks a letter from the string. - Bob then picks another letter from the remaining string. - This process continues, alternating between Alice and Bob, until all letters are se...
def char_value(c): """ Return the alphabetical value of the character c. """ return ord(c) - ord('a') + 1 def max_value_for_alice(S): """ Calculate the maximum value Alice can obtain. """ # Convert each character to its corresponding value letter_values = [char_value(c) for c in S] ...
from solution import max_values_for_test_cases def test_example_cases(): assert max_values_for_test_cases(2, ["abc", "defg"]) == [4, 12] def test_single_character(): assert max_values_for_test_cases(1, ["a"]) == [1] def test_same_character(): assert max_values_for_test_cases(1, ["aaa"]) == [2] # Alice p...
[ { "docstring": "Return the alphabetical value of the character c.", "function_declaration": "def char_value(c):", "function_name": "char_value", "parameter_list": "(c)" }, { "docstring": "Calculate the maximum value Alice can obtain.", "function_declaration": "def max_value_for_alice(S):...
[ 0, 0, 0, 0, 0, 0, 1, 0, 0, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl", "solution_code": "def max_value_alice_can_obtain(T, test_cases):\n \"\"\"\n Returns a list of maximum values Alice can obtain for each test case.\n \n :param T: int, num...
trial_gpt4o_6
{ "original_instruction": "", "prompt_id": "00046526", "row_id": 46526, "seed_ids": "[4157]" }
0.702643
Taco_46526
I
[ "char_value", "max_value_for_alice", "max_values_for_test_cases" ]
3
[ [ "max_value_for_alice", "char_value" ], [ "max_values_for_test_cases", "max_value_for_alice" ] ]
2
[ "max_values_for_test_cases" ]
false
[]
false
pytest
true
[]
true
98f9fccd6dfc5e90df51659eaf558f967469b4c7
264453ceefbd13a465c315e55bdc3f92760ea793
v1.0
instruct
Taco
Taco_46580_I
You are given a list of strings, each representing an expression in Reverse Polish Notation (RPN). Write a program to evaluate each of these expressions and return the result for each. RPN is a mathematical notation in which every operator follows all of its operands. It does not need any parentheses as long as each o...
def evaluate_rpn_expression(expression): stack = [] tokens = expression.split() for token in tokens: if token in "+-*/": b = stack.pop() a = stack.pop() if token == '+': stack.append(a + b) elif token == '-': stack....
from solution import evaluate_rpn_expression, evaluate_multiple_rpn def test_evaluate_rpn_expression(): assert evaluate_rpn_expression("3 4 +") == 7 assert evaluate_rpn_expression("5 1 2 + 4 * + 3 -") == 14 assert evaluate_rpn_expression("15 7 1 1 + - / 3 * 2 1 1 + + -") == 5 assert evaluate_rpn_expres...
[ { "docstring": null, "function_declaration": "def evaluate_rpn_expression(expression):", "function_name": "evaluate_rpn_expression", "parameter_list": "(expression)" }, { "docstring": null, "function_declaration": "def evaluate_multiple_rpn(expressions):", "function_name": "evaluate_...
[ 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 evaluate_rpn(expressions):\n def eval_rpn(tokens):\n stack = []\n for token in tokens:\n if token in '+-*/':\n b = s...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00046580", "row_id": 46580, "seed_ids": "[752]" }
0.571108
Taco_46580
I
[ "evaluate_rpn_expression", "evaluate_multiple_rpn" ]
2
[ [ "evaluate_multiple_rpn", "evaluate_rpn_expression" ] ]
1
[]
false
[]
false
pytest
true
[]
true
81aa156f4cf0e17540716ce77659d77695845106
5149c78595399ee670f47a358d32e70454eb8405
v1.0
instruct
Taco
Taco_46644_I
Write a function to determine the maximum sum of a contiguous subarray within a given integer array A of length n. ------ Input ------ The first line of the input contains an integer T, denoting the number of test cases. The description of T test cases follows. The first line of each test case contains an integer, ...
def max_subarray_sum(arr): """ Returns the maximum sum of a contiguous subarray within the given integer array arr. """ max_sum = float('-inf') current_sum = 0 for num in arr: current_sum = max(num, current_sum + num) max_sum = max(max_sum, current_sum) return m...
def test_max_subarray_sum(): assert max_subarray_sum([1, 2, 3, 4, -10]) == 10 assert max_subarray_sum([-1, -2, -3, -4]) == -1 assert max_subarray_sum([5, 4, -1, 7, 8]) == 23 def test_process_input(): input_data = "3\n5\n1 2 3 4 -10\n4\n-1 -2 -3 -4\n6\n5 4 -1 7 8\n" assert process_input(input_data) ...
[ { "docstring": "Returns the maximum sum of a contiguous subarray within the given integer array arr.", "function_declaration": "def max_subarray_sum(arr):", "function_name": "max_subarray_sum", "parameter_list": "(arr)" }, { "docstring": null, "function_declaration": "def process_input(i...
[ 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_subarray_sum(T, test_cases):\n results = []\n for case in test_cases:\n n, A = case\n max_sum = float('-inf')\n current_sum = 0\...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00046644", "row_id": 46644, "seed_ids": "[7678]" }
0.793427
Taco_46644
I
[ "max_subarray_sum", "process_input", "solve" ]
3
[ [ "process_input", "max_subarray_sum" ], [ "solve", "process_input" ] ]
2
[ "process_input" ]
false
[]
false
pytest
false
[]
true
3b2dd806a61ed3158d36130cfd28a4ea5094998c
0acdc910b67c95011fecb019cf7937cb7e4cea10
v1.0
instruct
Taco
Taco_46658_I
Determine if a given set of points form a convex polygon. You will be given a list of points in 2D plane and you need to determine if these points form a convex polygon or not. A polygon is convex if all its internal angles are less than 180 degrees. Constraints * 3 ≤ n ≤ 100 * -1000 ≤ xi, yi ≤ 1000 Input The inp...
def is_convex_polygon(points): def cross_product(p1, p2, p3): return (p2[0] - p1[0]) * (p3[1] - p1[1]) - (p2[1] - p1[1]) * (p3[0] - p1[0]) n = len(points) if n < 3: return False last_product_sign = 0 for i in range(n): p1 = points[i] p2 = points[(i + 1) % n] ...
def test_parse_input(): input_str = '2\n4 0 0 0 1 1 1 1 0\n5 0 0 2 2 4 0 3 3 1 3' expected = [ [(0, 0), (0, 1), (1, 1), (1, 0)], [(0, 0), (2, 2), (4, 0), (3, 3), (1, 3)] ] assert parse_input(input_str) == expected def test_is_convex_polygon(): assert is_convex_polygon([(0, 0), (0, 1...
[ { "docstring": null, "function_declaration": "def is_convex_polygon(points):", "function_name": "is_convex_polygon", "parameter_list": "(points)" }, { "docstring": null, "function_declaration": "def check_convex_polygons(test_cases):", "function_name": "check_convex_polygons", "p...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_convex_polygon(points):\n def cross_product(p1, p2, p3):\n return (p2[0] - p1[0]) * (p3[1] - p1[1]) - (p2[1] - p1[1]) * (p3[0] - p1[0])\n\n n =...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00046658", "row_id": 46658, "seed_ids": "[12443]" }
0.561445
Taco_46658
I
[ "is_convex_polygon", "check_convex_polygons", "parse_input", "solution" ]
4
[ [ "check_convex_polygons", "is_convex_polygon" ], [ "solution", "check_convex_polygons" ], [ "solution", "parse_input" ] ]
3
[ "parse_input" ]
false
[]
false
pytest
false
[]
true
a294832b3710a7f7b20dd12aee16998d15bc558e
7c0417b89528d7c1645dcd2c8ec47569142b33c7
v1.0
instruct
Taco
Taco_46670_I
You are given an array of integers. Your task is to check if Hamming distance between consecutive elements in a subarray remains below a given threshold or not for multiple queries. The Hamming distance between two integers is the number of positions at which the corresponding bits are different. Write a function `che...
def hamming_distance(a, b): return bin(a ^ b).count('1') def checkHammingDistance(n, arr, threshold, queries): results = [] for L, R in queries: meets_criteria = True for i in range(L, R): if hamming_distance(arr[i], arr[i+1]) > threshold: meets_criteria = False ...
from solution import checkHammingDistance def test_example_1(): n = 5 arr = [1, 4, 3, 6, 7] threshold = 2 queries = [(0, 2), (2, 4)] assert checkHammingDistance(n, arr, threshold, queries) == [False, True] def test_single_element_subarray(): n = 4 arr = [1, 2, 3, 4] threshold = 1 q...
[ { "docstring": null, "function_declaration": "def hamming_distance(a, b):", "function_name": "hamming_distance", "parameter_list": "(a, b)" }, { "docstring": null, "function_declaration": "def checkHammingDistance(n, arr, threshold, queries):", "function_name": "checkHammingDistance"...
[ 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 hamming_distance(a, b):\n return bin(a ^ b).count('1')\n\ndef checkHammingDistance(n, arr, threshold, queries):\n results = []\n for L, R in queries:\...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00046670", "row_id": 46670, "seed_ids": "[8304]" }
0.644248
Taco_46670
I
[ "hamming_distance", "checkHammingDistance" ]
2
[ [ "checkHammingDistance", "hamming_distance" ] ]
1
[]
false
[]
false
pytest
true
[]
true
549a9138b950f531989655262da3cf5a5a530197
4697f1fb58654af4600ee3c96a250663beb25f35
v1.0
instruct
Taco
Taco_46709_I
-----Electric Car Battery Management----- A company is developing a software to manage the battery usage of their electric cars. Each car's battery can be represented as a sequence of battery cells stored in an array. Each cell has a certain amount of energy, represented by a positive integer. The car consumes energy ...
def max_complete_trips(E, N, energies): total_energy = sum(energies) return total_energy // E def process_test_cases(T, test_cases): results = [] for case in test_cases: E, N, energies = case results.append(max_complete_trips(E, N, energies)) return results def electric_car_battery...
from solution import electric_car_battery_management def test_example_case1(): T = 2 test_cases = [ (5, 3, [4, 3, 2]), (10, 5, [5, 6, 7, 8, 9]) ] assert electric_car_battery_management(T, test_cases) == [1, 3] def test_only_one_trip_possible(): T = 1 test_cases = [ (10,...
[ { "docstring": null, "function_declaration": "def max_complete_trips(E, N, energies):", "function_name": "max_complete_trips", "parameter_list": "(E, N, energies)" }, { "docstring": null, "function_declaration": "def process_test_cases(T, test_cases):", "function_name": "process_test...
[ 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_complete_trips(E, N, energies):\n total_energy = sum(energies)\n return total_energy // E\n\ndef process_test_cases(T, test_cases):\n results = []...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00046709", "row_id": 46709, "seed_ids": "[11691]" }
0.672187
Taco_46709
I
[ "max_complete_trips", "process_test_cases", "electric_car_battery_management" ]
3
[ [ "electric_car_battery_management", "process_test_cases" ], [ "process_test_cases", "max_complete_trips" ] ]
2
[ "process_test_cases" ]
false
[]
false
pytest
true
[]
true
ef653d7f9306cf3aa190e29fe1c36cbb70996d4e
1baf385b9b33161db5b843c5fb2c1ad10545cce4
v1.0
instruct
Taco
Taco_46713_I
Vijay loves numbers and patterns. He has recently stumbled upon a peculiar property of integers and wants to explore it further. He defines a "Magic Number" as an integer that satisfies the following conditions: 1. The sum of its digits is a prime number. 2. The number contains at least one digit '7'. To help Vijay i...
def is_prime(num): 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 is_magic_number(n): digits = [int(d) for d in str(n)] digit_...
from solution import is_magic_number def test_magic_with_prime_sum_and_seven(): assert is_magic_number(719) == "MAGIC!" def test_not_magic_due_to_non_prime_sum(): assert is_magic_number(37) == "NOT MAGIC!" def test_not_magic_without_seven(): assert is_magic_number(233) == "NOT MAGIC!" def test_magic_pri...
[ { "docstring": null, "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": null, "function_declaration": "def is_magic_number(n):", "function_name": "is_magic_number", "parameter_list": "(n)" } ]
[ 0, 0, 0, 0, 0, 0, 1, 1, 0, 0 ]
2
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(num):\n \"\"\"\n Helper function to check if a number is prime.\n \"\"\"\n if num <= 1:\n return False\n for i in range(2, int(n...
trial_gpt4o_6
{ "original_instruction": "", "prompt_id": "00046713", "row_id": 46713, "seed_ids": "[21321]" }
0.61315
Taco_46713
I
[ "is_prime", "is_magic_number" ]
2
[ [ "is_magic_number", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
d7737a725b1c9351e2bc5f8e9baff011a7fe209e
e312e807bddefc51d4b25e6d93ac7b4fe0c58b46
v1.0
instruct
Taco
Taco_46755_I
Description Given an array with `n` unique integers, write a program to find an integer `k` such that all elements in the array can be divided by `k` without a remainder. `k` should be the largest possible divisor. The first line of input denotes the value of `n` (1 <= n <= 100). The second line contains `n` space-sep...
import math from functools import reduce def find_gcd(x, y): """ Returns the greatest common divisor (GCD) of x and y using the Euclidean algorithm. """ while y: x, y = y, x % y return x def largest_divisor(arr): """ Finds the largest integer k such that all elements in the array c...
from solution import find_largest_divisor def test_single_element(): assert find_largest_divisor(1, [10]) == 10 assert find_largest_divisor(1, [25]) == 25 def test_multiple_elements(): assert find_largest_divisor(3, [6, 9, 15]) == 3 assert find_largest_divisor(4, [12, 15, 21, 27]) == 3 assert find...
[ { "docstring": "Returns the greatest common divisor (GCD) of x and y using the Euclidean algorithm.", "function_declaration": "def find_gcd(x, y):", "function_name": "find_gcd", "parameter_list": "(x, y)" }, { "docstring": "Finds the largest integer k such that all elements in the array can ...
[ 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 gcd_of_list(nums):\n \"\"\"\n Returns the greatest common divisor (GCD) of a list of numbers.\n \"\"\"\n return math.gcd(*nums)\n\nd...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00046755", "row_id": 46755, "seed_ids": "[18190]" }
0.709143
Taco_46755
I
[ "find_gcd", "largest_divisor", "find_largest_divisor" ]
3
[ [ "find_largest_divisor", "largest_divisor" ], [ "largest_divisor", "find_gcd" ] ]
2
[]
false
[]
false
pytest
true
[]
true
e416b81afac51f403d5f2464e32d13461da28674
590fae6b1b9857b3592ab6322a9a29a9baa36d94
v1.0
instruct
Taco
Taco_46812_I
A university library wishes to automate the process of booking study rooms. Each study room can be booked for a specific period and cannot be double-booked. Students can request a study room for a certain period, and if the room is available for the entire requested period, the request is granted; otherwise, it is deni...
def handle_booking_requests(n, requests): """ This function takes the number of booking requests and a list of booking requests. Each request is a tuple (start, end). It returns a list of strings "Yes" or "No" based on whether the booking request is granted or denied. """ bookings = [] resul...
from solution import handle_booking_requests def test_single_request(): assert handle_booking_requests(1, [(1, 3)]) == ["Yes"] def test_non_overlapping_requests(): assert handle_booking_requests(2, [(1, 3), (4, 5)]) == ["Yes", "Yes"] def test_overlapping_requests(): assert handle_booking_requests(2, [(1,...
[ { "docstring": "This function takes the number of booking requests and a list of booking requests.\nEach request is a tuple (start, end).\nIt returns a list of strings \"Yes\" or \"No\" based on whether the booking request is granted or denied.", "function_declaration": "def handle_booking_requests(n, reque...
[ 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 manage_bookings(N, requests):\n \"\"\"\n Manages booking requests for a single study room.\n \n Parameters:\n N (int): Number of booking request...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00046812", "row_id": 46812, "seed_ids": "[24645]" }
0.656553
Taco_46812
I
[ "handle_booking_requests", "read_input_and_process" ]
2
[ [ "read_input_and_process", "handle_booking_requests" ] ]
1
[]
false
[]
false
pytest
true
[]
true
f20fc3d19762027371fdb7364c1beb3cc9684dba
fb3845250c7c59f9d56ba98e6b93b2affe4ce71c
v1.0
instruct
Taco
Taco_46825_I
Given a set of $N$ integers and $Q$ range queries, your task is to compute the sum of the integers in given ranges efficiently. You will be provided with an array $A$ of $N$ integers, followed by $Q$ queries. Each query will specify a range $[L, R]$ (1-based index) and you need to return the sum of the elements $A[L] ...
def precompute_prefix_sums(array): """ Precompute the prefix sums of the input array. """ prefix_sums = [0] * (len(array) + 1) for i in range(1, len(array) + 1): prefix_sums[i] = prefix_sums[i - 1] + array[i - 1] return prefix_sums def range_sum(prefix_sums, L, R): """ Calculate...
def test_precompute_prefix_sums(): array = [1, 2, 3, 4, 5] expected_prefix_sums = [0, 1, 3, 6, 10, 15] assert precompute_prefix_sums(array) == expected_prefix_sums def test_range_sum(): prefix_sums = [0, 1, 3, 6, 10, 15] assert range_sum(prefix_sums, 1, 3) == 6 assert range_sum(prefix_sums, 2, ...
[ { "docstring": "Precompute the prefix sums of the input array.", "function_declaration": "def precompute_prefix_sums(array):", "function_name": "precompute_prefix_sums", "parameter_list": "(array)" }, { "docstring": "Calculate the sum of the range [L, R] using the prefix sums array.\nNote: L...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl", "solution_code": "def preprocess_prefix_sums(A):\n \"\"\"\n Precompute the prefix sums for array A.\n \"\"\"\n N = len(A)\n prefix_sums = [0] * (N + 1)\n for i in ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00046825", "row_id": 46825, "seed_ids": "[7218]" }
0.651342
Taco_46825
I
[ "precompute_prefix_sums", "range_sum", "process_queries" ]
3
[ [ "process_queries", "precompute_prefix_sums" ], [ "process_queries", "range_sum" ] ]
2
[ "process_queries" ]
false
[]
false
pytest
false
[]
true
e93f1942838bd46bbe158fab1d91250491c82094
a3940b3cb79a6dc7aab26d54cedb8d0f5a29af0e
v1.0
instruct
Taco
Taco_46837_I
Rebecca has recently started exploring the exciting world of data streams and is fascinated by the complex operations that can be performed on them in real-time. She came across a challenging problem related to the frequency of elements in a stream that she couldn't solve herself and has turned to you for help. Given ...
def update_stream(stream, index, value): stream[index - 1] = value def find_frequency_in_range(stream, left, right, value): return stream[left-1:right].count(value) def process_queries(n, q, stream, queries): results = [] for query in queries: if query[0] == 1: _, index, value = qu...
def test_update_stream(): stream = [1, 2, 1, 3, 2, 1] update_stream(stream, 3, 2) assert stream == [1, 2, 2, 3, 2, 1] def test_find_frequency_in_range(): stream = [1, 2, 2, 3, 2, 1] assert find_frequency_in_range(stream, 1, 6, 1) == 2 assert find_frequency_in_range(stream, 1, 4, 2) == 2 ass...
[ { "docstring": null, "function_declaration": "def update_stream(stream, index, value):", "function_name": "update_stream", "parameter_list": "(stream, index, value)" }, { "docstring": null, "function_declaration": "def find_frequency_in_range(stream, left, right, value):", "function_...
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl", "solution_code": "def process_queries(n, q, a, queries):\n results = []\n \n for query in queries:\n if query[0] == 1:\n i, x = query[1] - 1, query[2]\n ...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00046837", "row_id": 46837, "seed_ids": "[13877]" }
0.629221
Taco_46837
I
[ "update_stream", "find_frequency_in_range", "process_queries" ]
3
[ [ "process_queries", "find_frequency_in_range" ], [ "process_queries", "update_stream" ] ]
2
[ "process_queries" ]
false
[]
false
pytest
false
[]
true
7d70d79ca5415da8ed7ccee3b8687eefd097dadf
954aa004189f92258fb6217b481df68b1801f140
v1.0
instruct
Taco
Taco_46848_I
You are given a list of non-negative integers which represents the amount of money of n houses aligned in a row. A thief wants to rob these houses, but he cannot rob adjacent houses because the security systems will alert the police. Given the list of amounts, determine the maximum amount of money the thief can rob wit...
def rob(nums): """ Calculate the maximum amount of money that can be robbed without robbing two consecutive houses. """ if not nums: return 0 if len(nums) == 1: return nums[0] prev1 = 0 prev2 = 0 for num in nums: temp = prev1 prev1 = max(prev2 + num, prev...
from solution import rob, max_money_robbed, parse_input def test_rob_no_houses(): assert rob([]) == 0 def test_rob_one_house(): assert rob([5]) == 5 def test_rob_two_houses(): assert rob([3, 7]) == 7 def test_rob_multiple_houses(): assert rob([1, 2, 3, 1]) == 4 assert rob([2, 7, 9, 3, 1]) == 12 ...
[ { "docstring": "Calculate the maximum amount of money that can be robbed without robbing two consecutive houses.", "function_declaration": "def rob(nums):", "function_name": "rob", "parameter_list": "(nums)" }, { "docstring": null, "function_declaration": "def max_money_robbed(test_cases...
[ 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 rob(nums):\n \"\"\"\n Returns the maximum amount of money that can be robbed without robbing adjacent houses.\n \"\"\"\n if not nums:\n retu...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00046848", "row_id": 46848, "seed_ids": "[1543]" }
0.668016
Taco_46848
I
[ "rob", "max_money_robbed", "parse_input" ]
3
[ [ "max_money_robbed", "rob" ] ]
1
[ "parse_input" ]
false
[]
false
pytest
true
[]
true
6caf21a5118bf779e39def8ffcde85fc8c94ad29
3338a70311a0fde016f2108616996544735d0b7c
v1.0
instruct
Taco
Taco_46897_I
Samir loves playing games. One of his favorites involves moving on a 2D grid. The grid is an $N \times N$ matrix, and Samir starts in the top-left corner at (1,1). The goal is to reach the bottom-right corner at (N,N). However, there are certain cells in the grid through which Samir cannot pass because they contain ob...
def count_paths(grid, N): # DP table for the number of paths to each cell dp = [[0] * N for _ in range(N)] # if starting cell has obstacle, immediately return 0 paths if grid[0][0] == 1: return 0 # Initial position (1,1) -> (0,0) in zero-based index dp[0][0] = 1 # Fill...
def test_count_paths(): grid1 = [ [0, 0, 0], [0, 1, 0], [0, 0, 0] ] assert count_paths(grid1, 3) == 2 grid2 = [ [0, 1, 0], [0, 1, 0], [0, 0, 0] ] assert count_paths(grid2, 3) == 1 grid3 = [ [0, 0], [1, 0] ] assert coun...
[ { "docstring": null, "function_declaration": "def count_paths(grid, N):", "function_name": "count_paths", "parameter_list": "(grid, N)" }, { "docstring": null, "function_declaration": "def calculate_paths(test_cases):", "function_name": "calculate_paths", "parameter_list": "(test...
[ 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 count_paths(test_cases):\n results = []\n for N, grid in test_cases:\n if grid[0][0] == 1 or grid[N-1][N-1] == 1:\n # No path if start ...
trial_gpt4o_4
{ "original_instruction": "", "prompt_id": "00046897", "row_id": 46897, "seed_ids": "[4592]" }
0.786725
Taco_46897
I
[ "count_paths", "calculate_paths", "process_input", "main" ]
4
[ [ "calculate_paths", "count_paths" ] ]
1
[ "process_input" ]
false
[]
false
pytest
false
[]
true
3429bf948007b6e7437092c400d31bc5735c7c0f
0e5fc71a8c36bb4ce9743842cf2bd8ef8387b957
v1.0
instruct
Taco
Taco_46939_I
Kekoland is famous for its delicious mushrooms. Adil and Bera are on a mushroom picking expedition in the enchanted Kekoland forest. The forest can be represented as a rectangular grid of size m x n. Each cell in the grid either contains a mushroom or is empty. Adil and Bera start at the top-left corner of the grid and...
from collections import deque import itertools def bfs(grid, start, m, n): directions = [(0, 1), (1, 0), (0, -1), (-1, 0)] queue = deque([(start[0], start[1], 0)]) visited = [[False]*n for _ in range(m)] visited[start[0]][start[1]] = True distances = [[float('inf')]*n for _ in range(m)] distanc...
from solution import minimal_time_to_pick_mushrooms def test_case_1(): assert minimal_time_to_pick_mushrooms(4, 4, 3, [(1, 2), (2, 1), (3, 3)]) == 12 def test_case_2(): assert minimal_time_to_pick_mushrooms(3, 3, 2, [(1, 1), (2, 2)]) == 8 def test_case_3(): assert minimal_time_to_pick_mushrooms(1, 1, 0, ...
[ { "docstring": null, "function_declaration": "def bfs(grid, start, m, n):", "function_name": "bfs", "parameter_list": "(grid, start, m, n)" }, { "docstring": null, "function_declaration": "def minimal_time_to_pick_mushrooms(m, n, k, mushrooms):", "function_name": "minimal_time_to_pic...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl", "solution_code": "from collections import deque\nimport itertools\n\ndef bfs(grid, start, m, n):\n directions = [(0, 1), (1, 0), (0, -1), (-1, 0)]\n queue = deque([(start[0], ...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00046939", "row_id": 46939, "seed_ids": "[24236]" }
0.609554
Taco_46939
I
[ "bfs", "minimal_time_to_pick_mushrooms" ]
2
[ [ "minimal_time_to_pick_mushrooms", "bfs" ] ]
1
[]
false
[]
false
pytest
true
[]
true
585155a767c2636d7a7a288bf923e63b62467927
ab59b38c2eb5d65bf39d5b2221338084c65ed6fa
v1.0
instruct
Taco
Taco_46956_I
In a far-off galaxy, there exists a highly advanced civilization that uses a unique system of teleportation networks to travel between planets. Each planet in the galaxy is represented as a node, and each teleportation path between two planets is represented as an edge with a positive integer weight that signifies the ...
def find_parent(parent, i): if parent[i] == i: return i else: return find_parent(parent, parent[i]) def union(parent, rank, x, y): root_x = find_parent(parent, x) root_y = find_parent(parent, y) if rank[root_x] < rank[root_y]: parent[root_x] = root_y elif rank[root_...
def test_minimum_energy_cost(): T = 2 test_cases = [ (4, 5, [ (1, 2, 3), (2, 3, 4), (3, 4, 5), (4, 1, 6), (1, 3, 2) ]), (3, 3, [ (1, 2, 1), (2, 3, 2), (3, 1, 3) ]) ] expe...
[ { "docstring": null, "function_declaration": "def find_parent(parent, i):", "function_name": "find_parent", "parameter_list": "(parent, i)" }, { "docstring": null, "function_declaration": "def union(parent, rank, x, y):", "function_name": "union", "parameter_list": "(parent, rank...
[ 0, 0, 1 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl", "solution_code": "def find(parent, i):\n if parent[i] == i:\n return i\n return find(parent, parent[i])\n\ndef union(parent, rank, x, y):\n root_x = find(parent, x)\...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00046956", "row_id": 46956, "seed_ids": "[25155]" }
0.679412
Taco_46956
I
[ "find_parent", "union", "kruskal_mst", "minimum_energy_cost" ]
4
[ [ "kruskal_mst", "find_parent" ], [ "kruskal_mst", "union" ], [ "minimum_energy_cost", "kruskal_mst" ], [ "union", "find_parent" ] ]
4
[]
false
[]
false
pytest
false
[]
true
6acbc494dff52166565bf69094b21586e9dd2d1a
2048256ffe6bbcb2df51f32ec85ba1127fe72b7d
v1.0
instruct
Taco
Taco_46984_I
One day, Danny the Detective is hired to solve a mysterious case. During his investigation, he discovers a crucial piece of evidence in the form of a sequence of numbers. However, the sequence is encrypted using a special mechanism. Danny needs your help to decipher the code, which is hidden in the structure of a bina...
class TreeNode: def __init__(self, value=0, left=None, right=None): self.value = value self.left = left self.right = right def build_tree(index, nodes): value = nodes[index][0] left = nodes[index][1] right = nodes[index][2] node = TreeNode(value) if left is not...
from solution import decrypt_binary_tree def test_decrypt_binary_tree_case1(): n = 5 nodes = [ (1, 1, 2), (2, None, None), (3, 3, 4), (4, None, None), (5, None, None) ] assert decrypt_binary_tree(n, nodes) == [1, 2, 3, 4, 5, 2, 1, 4, 3, 5, 2, 4, 5, 3, 1] def tes...
[]
[ 0, 0, 0, 0, 0, 0, 1, 0, 0, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl", "solution_code": "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 \nd...
trial_gpt4o_6
{ "original_instruction": "", "prompt_id": "00046984", "row_id": 46984, "seed_ids": "[11583]" }
0.593426
Taco_46984
I
[ "build_tree", "pre_order_traversal", "in_order_traversal", "post_order_traversal", "decrypt_binary_tree" ]
5
[ [ "decrypt_binary_tree", "build_tree" ], [ "decrypt_binary_tree", "in_order_traversal" ], [ "decrypt_binary_tree", "post_order_traversal" ], [ "decrypt_binary_tree", "pre_order_traversal" ] ]
4
[]
false
[ "TreeNode" ]
true
pytest
true
[]
true
4b554fd46f456bf18e038f59d1591a41230f3c1a
fcffe1f0059d1cc197f54e009feda637c95a424c
v1.0
instruct
Taco
Taco_47024_I
A company is organizing a conference in a country. The country consists of $N$ cities numbered $1$ through $N$, with $M$ bidirectional roads connecting them. We will use the following terms: - A path is a sequence of roads in which each road starts in the city the preceding road ended in. - A simple path is a path whic...
from collections import defaultdict, deque def is_prime(n): """ Helper function to check if a number is prime. """ if n <= 1: return False if n <= 3: return True if n % 2 == 0 or n % 3 == 0: return False i = 5 while i * i <= n: if n % i == 0 or n % (i + 2...
from solution import largest_prime_subgraph def test_example_1(): N, M = 5, 4 roads = [(1, 2), (1, 3), (3, 4), (4, 5)] assert largest_prime_subgraph(N, M, roads) == 5 def test_example_2(): N, M = 6, 5 roads = [(1, 2), (2, 3), (2, 4), (3, 5), (4, 6)] assert largest_prime_subgraph(N, M, roads) =...
[ { "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 the number of cities N, number of roads M, and list of bidirectional roads, \nreturn the number of cities...
[ 0, 0, 0, 0, 1, 0, 0, 1, 0 ]
2
hard
0.222
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(n):\n \"\"\"\n Helper function to check if a number is prime.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return ...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00047024", "row_id": 47024, "seed_ids": "[13213]" }
0.645431
Taco_47024
I
[ "is_prime", "largest_prime_subgraph" ]
2
[ [ "largest_prime_subgraph", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
6ee9b8a1cf4e7b695c7277425199edc0aa2fc4f0
835c136cdc62920b0b3fa49f521dbfaac2ec9342
v1.0
instruct
Taco
Taco_47032_I
Given a string S and a dictionary of words D, find the longest word in D that can be formed by deleting some characters of S without reordering the remaining characters. If there are multiple possible results, return the longest word with the smallest lexicographical order. If there is no possible result, return an emp...
def can_form_by_deleting(s, word): it = iter(s) return all(char in it for char in word) def find_longest_word(s, dictionary): longest_word = "" for word in dictionary: if can_form_by_deleting(s, word): if len(word) > len(longest_word) or (len(word) == len(longest_word) and word < lo...
from solution import find_longest_word def test_example1(): s = "abpcplea" dictionary = ["ale", "apple", "monkey"] assert find_longest_word(s, dictionary) == "apple" def test_example2(): s = "abpcplea" dictionary = ["a", "b", "c"] assert find_longest_word(s, dictionary) == "a" def test_no_mat...
[ { "docstring": null, "function_declaration": "def can_form_by_deleting(s, word):", "function_name": "can_form_by_deleting", "parameter_list": "(s, word)" }, { "docstring": null, "function_declaration": "def find_longest_word(s, dictionary):", "function_name": "find_longest_word", ...
[ 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_subsequence(s, word):\n \"\"\"\n Check if `word` is a subsequence of `s`.\n \"\"\"\n it = iter(s)\n return all(char in it for char in word)\n...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00047032", "row_id": 47032, "seed_ids": "[5711]" }
0.760396
Taco_47032
I
[ "can_form_by_deleting", "find_longest_word" ]
2
[ [ "find_longest_word", "can_form_by_deleting" ] ]
1
[]
false
[]
false
pytest
true
[]
true
36ade7a4671999a5bef32af4c11847b447aa872a
4ba999528d44a0e77af3528786d2f25e064a0958
v1.0
instruct
Taco
Taco_47106_I
Bernie is learning about Fibonacci sequences and their properties. He read that Fibonacci sequences can be used to compose any positive integer uniquely by summing distinct Fibonacci numbers, where no two consecutive Fibonacci numbers are used. This is known as Zeckendorf's theorem. Intrigued, Bernie decided to practi...
def generate_fibonacci_until(n): """ Generates all Fibonacci numbers up to n. """ fibs = [1, 2] # Since Zeckendorf representation avoids two consecutive Fibonacci numbers, start from the second Fibonacci number while True: next_fib = fibs[-1] + fibs[-2] if next_fib > n: ...
from solution import zeckendorf_representation def test_primary_examples(): assert zeckendorf_representation(28) == [21, 5, 2] assert zeckendorf_representation(100) == [89, 8, 3] def test_zero_case(): assert zeckendorf_representation(1) == [1] assert zeckendorf_representation(2) == [2] def test_large...
[ { "docstring": "Generates all Fibonacci numbers up to n.", "function_declaration": "def generate_fibonacci_until(n):", "function_name": "generate_fibonacci_until", "parameter_list": "(n)" }, { "docstring": "Returns the Zeckendorf representation of the number n,\nwhich is a sum of distinct no...
[ 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 fibonacci_decomposition(n):\n # Generate Fibonacci sequence up to n\n fibs = [1, 2]\n while fibs[-1] <= n:\n fibs.append(fibs[-1] + fibs[-2])\n...
trial_gpt4o_3
{ "original_instruction": "", "prompt_id": "00047106", "row_id": 47106, "seed_ids": "[7294]" }
0.625528
Taco_47106
I
[ "generate_fibonacci_until", "zeckendorf_representation" ]
2
[ [ "zeckendorf_representation", "generate_fibonacci_until" ] ]
1
[]
false
[]
false
pytest
true
[]
true
626e468310df51a1825ff66e87cdba2a601275d2
8ca4bd65fabdb66176c1850c28177fc3b9da6883
v1.0
instruct
Taco
Taco_47183_I
In a land far away, there exists a peculiar library system managed by the diligent Librarian Lais. The library contains a fascinating collection of scrolls, each categorized by a unique topic. To facilitate efficient study sessions, the librarian has devised a unique way of organizing the scrolls. The librarian wants ...
def organize_scrolls(datasets): result = [] for dataset in datasets: N = dataset[0] scrolls = dataset[1:] # Grouping scrolls by topic scroll_dict = {} for scroll in scrolls: topic, length = scroll if topic not in scroll_dict: ...
from solution import library_organizer def test_example_case(): input_data = """5 1 5 2 3 1 2 3 7 2 4 6 1 3 1 6 2 3 2 6 3 3 3 6 0""" expected_output = """1 2 5 2 3 4 3 7 1 3 6 2 3 6 3 3 6""" assert library_organizer(input_data) == expected_output def test_single_scroll(): input_data = "...
[ { "docstring": null, "function_declaration": "def organize_scrolls(datasets):", "function_name": "organize_scrolls", "parameter_list": "(datasets)" }, { "docstring": null, "function_declaration": "def parse_input(input_str):", "function_name": "parse_input", "parameter_list": "(i...
[ 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 organize_scrolls(datasets):\n results = []\n for dataset in datasets:\n scrolls = {}\n N = dataset[0]\n for i in range(1, N + 1):\n ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00047183", "row_id": 47183, "seed_ids": "[23331]" }
0.551075
Taco_47183
I
[ "organize_scrolls", "parse_input", "parse_output", "library_organizer" ]
4
[ [ "library_organizer", "organize_scrolls" ], [ "library_organizer", "parse_input" ], [ "library_organizer", "parse_output" ] ]
3
[ "parse_input" ]
false
[]
false
pytest
true
[]
true
1e8188d0a9d3c56d6be320b9c7af44f2a06c46b8
42e2c8c1fc56b777864fbe9bfc4aa88168f1687d
v1.0
instruct
Taco
Taco_47216_I
You are given an array of n integers. You need to perform two types of operations on this array: 1. 1 l r x — Increase every element a[i] (l ≤ i ≤ r) by x. 2. 2 l r — Output the sum of all elements a[i] (l ≤ i ≤ r). You have to process q queries of the above types in an efficient manner. Input The first line contai...
class FenwickTree: def __init__(self, size): self.size = size self.tree = [0] * (size + 1) def update(self, index, value): while index <= self.size: self.tree[index] += value index += index & -index def query(self, index): sum = 0...
def test_fenwick_tree_operations_single_update(): n = 5 array = [2, 1, 5, 3, 4] queries = [ (1, 2, 4, 2), # Increase a[2, 3, 4] by 2 ] assert process_queries(n, array, queries) == [] def test_fenwick_tree_operations_single_sum(): n = 5 array = [2, 1, 5, 3, 4] queries = [ ...
[]
[ 0, 0, 0, 0, 1 ]
1
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl", "solution_code": "class NumArray:\n def __init__(self, nums):\n self.nums = nums\n self.n = len(nums)\n self.seg_tree = [0] * (4 * self.n)\n self.buil...
trial_gpt4o_4
{ "original_instruction": "", "prompt_id": "00047216", "row_id": 47216, "seed_ids": "[14007]" }
0.710937
Taco_47216
I
[ "range_update", "prefix_sum", "range_sum", "process_queries" ]
4
[ [ "process_queries", "range_sum" ], [ "process_queries", "range_update" ], [ "range_sum", "prefix_sum" ] ]
3
[ "process_queries" ]
false
[ "FenwickTree" ]
true
pytest
false
[]
true
7251ab05adb5086ef9a736db0379fe17938db69f
a60b16b54a6b70c4fd32173c8a42294d103e91ef
v1.0
instruct
Taco
Taco_47265_I
A balanced binary tree is a special type of binary tree in which the depth of the two subtrees of every node never differ by more than 1. Write a function to convert a sorted array into a balanced binary tree. You are given a sorted array of distinct integers. Your task is to create a balanced binary tree from this ar...
class TreeNode: def __init__(self, val=0, left=None, right=None): self.val = val self.left = left self.right = right def sorted_array_to_bst(nums): """ Convert a sorted array to a balanced binary search tree. """ if not nums: return None mid = len(nums) // 2 ...
from solution import sorted_array_to_bst, inorder_traversal, process_test_cases def test_sorted_array_to_bst_case1(): array = [-10, -3, 0, 5, 9] bst_root = sorted_array_to_bst(array) assert inorder_traversal(bst_root) == array def test_sorted_array_to_bst_case2(): array = [1, 2, 3, 4, 5, 6, 7] bst...
[]
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl", "solution_code": "class TreeNode:\n def __init__(self, val=0, left=None, right=None):\n self.val = val\n self.left = left\n self.right = right\n\ndef sorted_...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00047265", "row_id": 47265, "seed_ids": "[828]" }
0.756544
Taco_47265
I
[ "sorted_array_to_bst", "inorder_traversal", "process_test_cases" ]
3
[ [ "process_test_cases", "inorder_traversal" ], [ "process_test_cases", "sorted_array_to_bst" ] ]
2
[ "process_test_cases" ]
false
[ "TreeNode" ]
true
pytest
true
[]
true
4b997e84127be73cf8ba26205a7852f691e7630a
6a18eca2cfcfa34f0a9ee51d0d43fe767213e674
v1.0
instruct
Taco
Taco_47277_I
Dr. Strange has a list of spells, each represented by a string of lowercase letters. A spell is considered powerful if the number of distinct characters in it is a prime number. Your task is to count the number of powerful spells in the given list. Input First line contains an integer T, the number of testcases. Each ...
def is_prime(num): """ Returns True if num is a prime number, else False. """ if num <= 1: return False if num <= 3: return True if num % 2 == 0 or num % 3 == 0: return False i = 5 while i * i <= num: if num % i == 0 or num % (i + 2) == 0: retu...
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 def test_count_powerful_spells(): assert count_powerful_spells(['abc', 'abb', 'abcde']) == 3 assert c...
[ { "docstring": "Returns True if num is a prime number, else False.", "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": "Counts how many spells are powerful, i.e., have a prime number of distinct characters.", "function_...
[ 0, 0, 0, 0, 0, 1, 0, 0, 0, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl", "solution_code": "def 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_5
{ "original_instruction": "", "prompt_id": "00047277", "row_id": 47277, "seed_ids": "[11965]" }
0.57703
Taco_47277
I
[ "is_prime", "count_powerful_spells", "main" ]
3
[ [ "count_powerful_spells", "is_prime" ] ]
1
[]
false
[]
false
pytest
false
[]
true
ef664d7a37dc52690b3881afebb4be9e8f8f238c
81b9db64284ae89cb7df298883a6126fd6578940
v1.0
instruct
Taco
Taco_47382_I
A mysterious ancient text has been discovered, and it is made up of several encrypted messages. Each message is a sequence of integers. Archaeologists have learned that these integers can be decoded into words by following these steps: 1. Each integer corresponds to a position in the English alphabet (1 = 'a', 2 = 'b'...
def num_decodings(s: str) -> int: """ Returns the number of ways to decode a given string of digits. """ if not s or s[0] == '0': return 0 n = len(s) dp = [0] * (n + 1) dp[0], dp[1] = 1, 1 # An empty string has one way to decode, base case for i in range(2, n + 1):...
import pytest from solution import decode_messages def test_case_123(): messages = ["123"] assert decode_messages(messages) == [3] def test_case_226(): messages = ["226"] assert decode_messages(messages) == [3] def test_case_06(): messages = ["06"] assert decode_messages(messages) == [0] def...
[ { "docstring": "Returns the number of ways to decode a given string of digits.", "function_declaration": "def num_decodings(s):", "function_name": "num_decodings", "parameter_list": "(s)" }, { "docstring": "Decodes multiple messages and returns the results as a list of integers.", "funct...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl", "solution_code": "def count_decoding_ways(message: str) -> int:\n \"\"\"\n This function computes the number of ways a given sequence of integers can be decoded \n into val...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00047382", "row_id": 47382, "seed_ids": "[13082]" }
0.600773
Taco_47382
I
[ "num_decodings", "decode_messages" ]
2
[ [ "decode_messages", "num_decodings" ] ]
1
[]
false
[]
false
pytest
true
[]
true
299b1e20bc34132b51bf7cce041890b52d9dc4ff
ec3629c90b30d2cce551b968c0ecb336f081184f
v1.0
instruct
Taco
Taco_47482_I
John is organizing a series of workshops for a local tech conference. Each workshop has a specific start and end time. John wants to participate in as many workshops as possible, but the workshops may overlap. Your task is to write a program that helps John find the maximum number of non-overlapping workshops he can at...
def max_non_overlapping_workshops(datasets): results = [] for dataset in datasets: n, workshops = dataset workshops.sort(key=lambda x: x[1]) # Sort by end times count = 0 last_end_time = 0 for s, e in workshops: if s >= last_end_time: count +...
from solution import conference_workshops def test_example_case(): data = "3\n1 3\n2 4\n3 5\n4\n1 2\n3 4\n0 6\n5 7\n4\n1 4\n4 5\n5 6\n4 10\n0\n" expected = [2, 3, 3] assert conference_workshops(data) == expected def test_single_dataset_single_workshop(): data = "1\n1 2\n0\n" expected = [1] ass...
[ { "docstring": null, "function_declaration": "def max_non_overlapping_workshops(datasets):", "function_name": "max_non_overlapping_workshops", "parameter_list": "(datasets)" }, { "docstring": null, "function_declaration": "def parse_input(data):", "function_name": "parse_input", ...
[ 0, 1, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl", "solution_code": "def max_non_overlapping_workshops(datasets):\n results = []\n \n for workshops in datasets:\n # Sort workshops based on their end times\n so...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00047482", "row_id": 47482, "seed_ids": "[780]" }
0.652207
Taco_47482
I
[ "max_non_overlapping_workshops", "parse_input", "conference_workshops" ]
3
[ [ "conference_workshops", "max_non_overlapping_workshops" ], [ "conference_workshops", "parse_input" ] ]
2
[ "parse_input" ]
false
[]
false
pytest
true
[]
true
3796cc08bde26c22aad91e305d43b950fb097594
8afbcf26396d84990e8ec9231a3a96b4ffed9057
v1.0
instruct
Taco
Taco_47541_I
Alice and Bob are fond of puzzles, and while taking a break from their games, they stumbled upon a mathematical challenge. Given a number n, they are curious to find out how many pairs of positive integers (a, b) such that the greatest common divisor (gcd) of a and b is equal to their least common multiple (lcm) divide...
def count_pairs(n): """ Given an integer n, return the count of pairs (a, b) such that gcd(a, b) = lcm(a, b) / (a + b). """ count = 0 for a in range(1, n + 1): for b in range(1, n + 1): if a == b: count += 1 else: lcm_ab = (a * b) /...
from solution import number_of_pairs def test_sample_1(): assert number_of_pairs([1]) == [1] def test_sample_2(): assert number_of_pairs([2]) == [2] def test_sample_3(): assert number_of_pairs([4]) == [4] def test_large_number(): assert number_of_pairs([10]) == [10] assert number_of_pairs([100])...
[ { "docstring": "Given an integer n, return the count of pairs (a, b) such that\ngcd(a, b) = lcm(a, b) / (a + b).", "function_declaration": "def count_pairs(n):", "function_name": "count_pairs", "parameter_list": "(n)" }, { "docstring": null, "function_declaration": "def gcd(x, y):", ...
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl", "solution_code": "def count_pairs(n):\n \"\"\"\n Function to find the number of pairs (a, b) such that \n gcd(a, b) = lcm(a, b) / (a + b) for a given n.\n \"\"\"\n pa...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00047541", "row_id": 47541, "seed_ids": "[3288]" }
0.678825
Taco_47541
I
[ "count_pairs", "gcd", "number_of_pairs" ]
3
[ [ "count_pairs", "gcd" ], [ "number_of_pairs", "count_pairs" ] ]
2
[]
false
[]
false
pytest
true
[]
true
b6d45968b1860244f0f3c0d52500daa1be1acc8a
4a6f7d084f9d642d94ea38f4e8b0d4664b2e9f84
v1.0
instruct
Taco
Taco_47604_I
You are given a special string problem to solve. Your task is to determine whether a given string is a "mirrored" string or not. A mirrored string is one where the string reads the same backward as forward. However, the twist here is that you need to ignore case-sensitivity and only consider alphabets (ignore spaces, n...
def is_mirrored_string(S): """ Determine whether the given string S is a mirrored string, considering only alphabets and ignoring case. """ filtered_chars = [char.lower() for char in S if char.isalpha()] return filtered_chars == filtered_chars[::-1] def mirrored_strings(N, strings): """ ...
from solution import is_mirrored_string, mirrored_strings def test_is_mirrored_string(): assert is_mirrored_string("A man a plan a canal Panama") == True assert is_mirrored_string("Was it a car or a cat I saw") == True assert is_mirrored_string("No lemon no melon") == True assert is_mirrored_string("He...
[ { "docstring": "Determine whether the given string S is a mirrored string, considering only alphabets and ignoring case.", "function_declaration": "def is_mirrored_string(S):", "function_name": "is_mirrored_string", "parameter_list": "(S)" }, { "docstring": "Determine for each string in stri...
[ 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_mirrored_string(s):\n \"\"\"\n Determine if the given string is a mirrored string, ignoring case and non-alphabet characters.\n \"\"\"\n # Proce...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00047604", "row_id": 47604, "seed_ids": "[22162]" }
0.726748
Taco_47604
I
[ "is_mirrored_string", "mirrored_strings" ]
2
[ [ "mirrored_strings", "is_mirrored_string" ] ]
1
[]
false
[]
false
pytest
true
[]
true
d16afe82383391de677855545e7ff7304f327191
6496684543de795b527e1d56813f112ed7b54608
v1.0
instruct
Taco
Taco_47607_I
Implement a function that finds the k-th smallest element in a given list of integers. You should solve this problem using the Quickselect algorithm. Input Format The first line contains an integer n, representing the number of elements in the list. The second line contains n space-separated integers, the elements ...
def quickselect(arr, k): """ Return the k-th smallest element in the array using Quickselect. """ if len(arr) == 1: return arr[0] pivot = arr[len(arr) // 2] lows = [el for el in arr if el < pivot] highs = [el for el in arr if el > pivot] pivots = [el for el in arr if el == pivo...
from solution import kth_smallest_element def test_kth_smallest_element(): assert kth_smallest_element(6, [7, 10, 4, 3, 20, 15], 3) == 7 assert kth_smallest_element(5, [1, 2, 3, 4, 5], 1) == 1 assert kth_smallest_element(5, [1, 2, 3, 4, 5], 5) == 5 assert kth_smallest_element(7, [7, 10, 4, 3, 20, 15, 6...
[ { "docstring": "Return the k-th smallest element in the array using Quickselect.", "function_declaration": "def quickselect(arr, k):", "function_name": "quickselect", "parameter_list": "(arr, k)" }, { "docstring": null, "function_declaration": "def kth_smallest_element(n, arr, k):", ...
[ 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 random\n\ndef partition(arr, low, high):\n pivot = arr[high]\n i = low\n for j in range(low, high):\n if arr[j] <= pivot:\n arr[i...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00047607", "row_id": 47607, "seed_ids": "[1996]" }
0.644325
Taco_47607
I
[ "quickselect", "kth_smallest_element" ]
2
[ [ "kth_smallest_element", "quickselect" ] ]
1
[]
false
[]
false
pytest
true
[]
true
e580cfa5b46df671463925fa77290c1729c489af
4d03327950c60d55b49972b0c3ed574688da7f6b
v1.0
instruct
Taco
Taco_47619_I
Simon has a collection of $n$ integers that he likes to play around with. He wants to transform his collection in such a way that the product of all the integers becomes a perfect square. Simon can multiply any integer in the collection by any positive integer (including 1) as many times as he wants. However, he wants ...
from collections import Counter from math import gcd from functools import reduce def prime_factors(n): """Returns a Counter (hashmap) of prime factors of n with their powers.""" i = 2 factors = Counter() while i * i <= n: while (n % i) == 0: factors[i] += 1 n //= i ...
def test_prime_factors(): assert prime_factors(18) == Counter({2: 1, 3: 2}) assert prime_factors(25) == Counter({5: 2}) assert prime_factors(49) == Counter({7: 2}) def test_min_operations_to_perfect_square(): assert min_operations_to_perfect_square(3, [2, 2, 3]) == 1 assert min_operations_to_perfec...
[ { "docstring": "Returns a Counter (hashmap) of prime factors of n with their powers.", "function_declaration": "def prime_factors(n):", "function_name": "prime_factors", "parameter_list": "(n)" }, { "docstring": null, "function_declaration": "def min_operations_to_perfect_square(n, integ...
[ 0, 0, 0, 0, 0, 0, 1, 0, 0 ]
1
hard
0.111
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl", "solution_code": "from collections import Counter\nfrom math import isqrt\n\ndef min_operations_to_perfect_square(t, test_cases):\n def factor_count(n):\n count = Counter(...
trial_gpt4o_7
{ "original_instruction": "", "prompt_id": "00047619", "row_id": 47619, "seed_ids": "[19797]" }
0.74743
Taco_47619
I
[ "prime_factors", "min_operations_to_perfect_square", "solve" ]
3
[ [ "min_operations_to_perfect_square", "prime_factors" ], [ "solve", "min_operations_to_perfect_square" ] ]
2
[]
false
[]
false
pytest
false
[]
true
75960aeea34fbba7313a28cf6883e7a14b6f3dfd
5d61b75c8eefa6f939be61c0f0c1a4cdcab2e616
v1.0
instruct
Taco
Taco_47678_I
John has a list of activities that he needs to complete by the end of the day. Each activity has a start time and an end time. John wants to complete as many activities as possible, but no two activities can overlap in time. Design an algorithm that helps John determine the maximum number of non-overlapping activities...
def max_non_overlapping_activities(test_cases): """ Determines the maximum number of non-overlapping activities John can attend for each test case. :param test_cases: List of test cases, where each test case is a list of tuples representing activities with start and end times. :return: List of inte...
from solution import max_non_overlapping_activities, process_input, solution def test_max_non_overlapping_activities(): test_cases = [ [(1, 3), (2, 4), (3, 5)], [(1, 2), (2, 3), (3, 4), (4, 5)] ] expected = [2, 4] result = max_non_overlapping_activities(test_cases) assert result == ...
[ { "docstring": "Determines the maximum number of non-overlapping activities John can attend for each test case.\n\n:param test_cases: List of test cases, where each test case is a list of tuples representing activities with start and end times.\n:return: List of integers representing the maximum number of non-o...
[ 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 max_activities(test_cases):\n \"\"\"\n Determines the maximum number of non-overlapping activities John can attend for each test case.\n \n Paramet...
trial_gpt4o_3
{ "original_instruction": "", "prompt_id": "00047678", "row_id": 47678, "seed_ids": "[13057]" }
0.665839
Taco_47678
I
[ "max_non_overlapping_activities", "process_input", "solution" ]
3
[ [ "solution", "max_non_overlapping_activities" ], [ "solution", "process_input" ] ]
2
[ "process_input" ]
false
[]
false
pytest
true
[]
true
2eec894bea9c3b036ce7eee13ccfd3bc2a194db1
a0c4311261bb7a25061b99d35d3fb92a48867243
v1.0
instruct
Taco
Taco_47730_I
You are given a sequence of integers. You want to find the length of the longest subsequence that is strictly increasing and consists only of prime numbers. Input: The first line contains the number of test cases T. T test cases follow. Each test case contains two lines. The first line of each test case contains an in...
def is_prime(n): if n < 2: return False for i in range(2, int(n**0.5) + 1): if n % i == 0: return False return True def longest_increasing_prime_subsequence_length(sequence): primes = [num for num in sequence if is_prime(num)] if not primes: return 0 ...
def test_is_prime(): assert is_prime(2) == True assert is_prime(3) == True assert is_prime(4) == False assert is_prime(17) == True assert is_prime(18) == False def test_longest_increasing_prime_subsequence_length(): assert longest_increasing_prime_subsequence_length([2, 3, 5, 7, 11, 13]) == 6 ...
[ { "docstring": null, "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": null, "function_declaration": "def longest_increasing_prime_subsequence_length(sequence):", "function_name": "longest_increasing_prime_subsequence_l...
[ 1, 0, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(n):\n if n < 2:\n return False\n for i in range(2, int(n**0.5) + 1):\n if n % i == 0:\n return False\n return True\n...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00047730", "row_id": 47730, "seed_ids": "[13051]" }
0.733607
Taco_47730
I
[ "is_prime", "longest_increasing_prime_subsequence_length", "find_longest_increasing_prime_subsequence" ]
3
[ [ "find_longest_increasing_prime_subsequence", "longest_increasing_prime_subsequence_length" ], [ "longest_increasing_prime_subsequence_length", "is_prime" ] ]
2
[]
false
[]
false
pytest
false
[]
true
d07077d3b2c8f9cd7ece162adc2370c99c3d8cea
a03cffee67d1c2b604069c2a14661745161fb21d
v1.0
instruct
Taco
Taco_47740_I
Given a positive integer `n`, you need to construct a permutation `p` of integers from 1 to n, such that for any two consecutive integers i and j in the permutation, the sum `i + j` is not a prime number. If there are multiple valid permutations, output any one of them. If no valid permutation exists, return an empty l...
def is_prime(num): """ Helper function to check if a number is prime. """ if num <= 1: return False if num <= 3: return True if num % 2 == 0 or num % 3 == 0: return False i = 5 while i * i <= num: if num % i == 0 or num % (i + 2) == 0: return F...
import pytest from solution import construct_permutation, is_prime def test_single_element(): assert construct_permutation(1) == [1] def test_two_elements(): assert construct_permutation(2) == [] def test_three_elements(): assert construct_permutation(3) == [] def test_four_elements(): permutation =...
[ { "docstring": "Helper function to check if a number is prime.", "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": null, "function_declaration": "def construct_permutation(n):", "function_name": "construct_permutati...
[ 0, 1, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(n):\n \"\"\" Returns True if n is a prime number, False otherwise. \"\"\"\n if n <= 1:\n return False\n if n == 2:\n return Tru...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00047740", "row_id": 47740, "seed_ids": "[11527]" }
0.67915
Taco_47740
I
[ "is_prime", "construct_permutation" ]
2
[ [ "construct_permutation", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
5941749be3273789c9749c56d05aa6723853465a
f768c3b6a6b748c023a509b7b578f6b27f163c6e
v1.0
instruct
Taco
Taco_47818_I
You are given a list of strings, each consisting of uppercase English letters and digits. We define the "core" of a string as the longest contiguous substring that contains either only letters or only digits. If there are multiple substrings of the same maximum length, the leftmost one is considered the core. Your task...
def find_core(s): """ Returns the core of the string s, which is the longest contiguous substring that contains either only letters or only digits. If multiple substrings of the same maximum length exist, returns the leftmost one. """ max_len = 0 max_core = "" current_core = s[0] ...
from solution import find_core, process_strings def test_find_core(): assert find_core("AB12C34DE") == "AB" assert find_core("1234AB56") == "1234" assert find_core("ABCDE123") == "ABCDE" assert find_core("1000A5B67") == "1000" assert find_core("A") == "A" assert find_core("1") == "1" assert...
[ { "docstring": "Returns the core of the string s, which is the longest contiguous substring \nthat contains either only letters or only digits. If multiple substrings \nof the same maximum length exist, returns the leftmost one.", "function_declaration": "def find_core(s):", "function_name": "find_core"...
[ 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_core(s):\n \"\"\"\n Returns the core of the string s, which is the longest contiguous substring \n that contains either only letters or only digi...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00047818", "row_id": 47818, "seed_ids": "[14165]" }
0.681058
Taco_47818
I
[ "find_core", "process_strings" ]
2
[ [ "process_strings", "find_core" ] ]
1
[]
false
[]
false
pytest
true
[]
true
5873a13b245b11ab021aa476cefb2d4cdfec4d23
d67d4234e5ef2babed9aa0b4d116fad3f5498e28
v1.0
instruct
Taco
Taco_47834_I
In a given list of words, your task is to find the longest word that can be formed by deleting some characters of another given string `s`. A word `w` from the list can be formed by deleting some characters of `s` if without reordering the remaining characters of `s`, they match the characters of `w`. You need to retu...
def is_subsequence(x, y): """ Check if string x is a subsequence of string y. """ it = iter(y) return all(char in it for char in x) def find_longest_word(s, words): """ Finds the longest word that can be formed by deleting some characters of s from the list of words, where the longest w...
from solution import find_longest_word def test_example_1(): assert find_longest_word("abpcplea", ["apple", "apply", "ale", "plea"]) == "apple" def test_example_2(): assert find_longest_word("abc", ["a", "b", "c", "abc"]) == "abc" def test_no_possible_word(): assert find_longest_word("abc", ["d", "e", "f...
[ { "docstring": "Check if string x is a subsequence of string y.", "function_declaration": "def is_subsequence(x, y):", "function_name": "is_subsequence", "parameter_list": "(x, y)" }, { "docstring": "Finds the longest word that can be formed by deleting some characters of s\nfrom the list of...
[ 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 findLongestWord(s, words):\n def is_subsequence(x):\n it = iter(s)\n return all(c in it for c in x)\n\n words.sort(key=lambda x: (-len(x), ...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00047834", "row_id": 47834, "seed_ids": "[17018]" }
0.769735
Taco_47834
I
[ "is_subsequence", "find_longest_word" ]
2
[ [ "find_longest_word", "is_subsequence" ] ]
1
[]
false
[]
false
pytest
true
[]
true
7a345b427e909f6548d11fb542660dd5c5b786fb
9c6ff4500e1322df95c5a68bfa27c2b8f450f702
v1.0
instruct
Taco
Taco_47846_I
You are working on a navigation system for a new amusement park. The park consists of a network of attractions connected by bidirectional paths. Each path has a certain length. Visitors often like to start from one attraction and explore different attractions while minimizing the distance traveled. Your task is to dete...
import heapq import sys def dijkstra(graph, start, end): """ Use Dijkstra's algorithm to find the shortest path from start to end. """ n = len(graph) distances = [sys.maxsize] * n distances[start] = 0 priority_queue = [(0, start)] while priority_queue: current_distance...
def test_sample_case(): input_data = [ "5 6", "1 2 2", "1 3 4", "2 3 1", "2 4 7", "3 5 3", "4 5 1", "1 5", "0 0" ] expected_output = [6] assert find_shortest_paths(input_data) == expected_output def test_no_path(): input_data =...
[ { "docstring": "Use Dijkstra's algorithm to find the shortest path from start to end.", "function_declaration": "def dijkstra(graph, start, end):", "function_name": "dijkstra", "parameter_list": "(graph, start, end)" }, { "docstring": null, "function_declaration": "def shortest_path(num_...
[ 0, 0, 0, 0, 1, 0, 0, 1, 0 ]
2
hard
0.222
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl", "solution_code": "import heapq\nimport sys\n\ndef dijkstra(n, graph, start, end):\n \"\"\"\n Find the shortest path between start and end in a graph with n nodes.\n \"\"\"\...
trial_gpt4o_5
{ "original_instruction": "", "prompt_id": "00047846", "row_id": 47846, "seed_ids": "[1771]" }
0.707505
Taco_47846
I
[ "dijkstra", "shortest_path", "parse_input", "find_shortest_paths" ]
4
[ [ "find_shortest_paths", "parse_input" ], [ "parse_input", "shortest_path" ], [ "shortest_path", "dijkstra" ] ]
3
[ "parse_input" ]
false
[]
false
pytest
false
[]
true
c5a8506662971c66eba999d1104494d3535901b3
ccdc1bd4dffb446acb7266b3cb81cd70d68e31d0
v1.0
instruct
Taco
Taco_47880_I
You are given a list of integers $arr$ and an integer $k$. Your task is to partition the list into $k$ contiguous subarrays such that the maximum sum of the subarrays is minimized. Return the minimized maximum sum. For example, given $arr=[7,2,5,10,8]$ and $k=2$, the best partition would be: - Subarray 1: [7, 2] => Su...
def canPartition(arr, k, maxSum): currentSum = 0 requiredPartitions = 1 for num in arr: currentSum += num if currentSum > maxSum: requiredPartitions += 1 currentSum = num if requiredPartitions > k: return False return True def mini...
from solution import minimizeMaxSum def test_minimizeMaxSum_sample(): assert minimizeMaxSum([7, 2, 5, 10, 8], 2) == 18 def test_minimizeMaxSum_single_element_subarrays(): assert minimizeMaxSum([1, 2, 3, 4], 4) == 4 def test_minimizeMaxSum_entire_array_as_one_subarray(): assert minimizeMaxSum([1, 2, 3, 4]...
[ { "docstring": null, "function_declaration": "def canPartition(arr, k, maxSum):", "function_name": "canPartition", "parameter_list": "(arr, k, maxSum)" }, { "docstring": null, "function_declaration": "def minimizeMaxSum(arr, k):", "function_name": "minimizeMaxSum", "parameter_lis...
[ 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 canPartition(arr, k, maxSum):\n currentSum = 0\n requiredPartitions = 1\n\n for num in arr:\n currentSum += num\n\n if currentSum > maxS...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00047880", "row_id": 47880, "seed_ids": "[24610]" }
0.800186
Taco_47880
I
[ "canPartition", "minimizeMaxSum" ]
2
[ [ "minimizeMaxSum", "canPartition" ] ]
1
[]
false
[]
false
pytest
true
[]
true
52ab8b1aa7939ffa29b5dbb0ec89b8d10bde2f28
072731560ad08594a493e1a4b76776450042b168
v1.0
instruct
Taco
Taco_47901_I
You are given a grid with R rows and C columns. Each cell in the grid can either be passable ('.') or impassable ('#'). You start in the top-left cell (1, 1) and want to reach the bottom-right cell (R, C). You can only move to the right or down at each step. Your task is to count the number of distinct paths from the t...
MOD = 1000000_007 def num_paths(grid): R = len(grid) C = len(grid[0]) # DP table to store the number of ways to reach each cell dp = [[0] * C for _ in range(R)] # Starting point if grid[0][0] == '.': dp[0][0] = 1 # Fill the DP table for i in range(R): for ...
from solution import num_paths def test_example_1(): grid = [ ['.', '.', '.'], ['.', '#', '.'], ['.', '.', '.'] ] assert num_paths(grid) == 2 def test_example_2(): grid = [ ['#', '#', '#'], ['.', '#', '.'], ['.', '.', '.'] ] assert num_paths(grid...
[ { "docstring": null, "function_declaration": "def num_paths(grid):", "function_name": "num_paths", "parameter_list": "(grid)" }, { "docstring": null, "function_declaration": "def solve():", "function_name": "solve", "parameter_list": "()" } ]
[ 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 distinct_paths(grid):\n MOD = 1000000007\n R = len(grid)\n C = len(grid[0])\n \n # Create a 2D dp array filled with 0\n dp = [[0] * C for _ i...
trial_gpt4o_4
{ "original_instruction": "", "prompt_id": "00047901", "row_id": 47901, "seed_ids": "[14160]" }
0.779807
Taco_47901
I
[ "num_paths", "solve" ]
2
[ [ "solve", "num_paths" ] ]
1
[]
false
[]
false
pytest
true
[]
true
e52ecf2593eb2f27140263b6f61c8d1a14cbc400
6aba00e825070ae2c1f426d75aeea805b453affc
v1.0
instruct
Taco
Taco_47909_I
Given an integer array $A$ of size $N$, and two integers $K$ and $M$, determine the number of unique arrays you can form by keeping exactly $K$ elements and replacing the rest with any integer from $1$ to $M$ (inclusive). Two arrays are considered unique if they are different in at least one position. ------ Input: --...
def factorial(n): if n == 0 or n == 1: return 1 return n * factorial(n - 1) def binomial_coefficient(n, k): return factorial(n) // (factorial(k) * factorial(n - k)) def count_unique_arrays(N, K, M): return binomial_coefficient(N, K) * (M ** (N - K)) def process_test_cases(test_cases): res...
from solution import count_unique_arrays, process_test_cases def test_count_unique_arrays(): assert count_unique_arrays(5, 2, 5) == 1250 assert count_unique_arrays(3, 1, 3) == 27 def test_process_test_cases(): test_cases = [ ((5, 2, 5), [2, 3, 1, 4, 5]), ((3, 1, 3), [7, 8, 9]) ] re...
[ { "docstring": null, "function_declaration": "def factorial(n):", "function_name": "factorial", "parameter_list": "(n)" }, { "docstring": null, "function_declaration": "def binomial_coefficient(n, k):", "function_name": "binomial_coefficient", "parameter_list": "(n, k)" }, { ...
[ 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 math import comb\n\ndef count_unique_arrays(n, k, m):\n \"\"\"\n Count the number of unique arrays by keeping exactly k elements and replacing the rest ...
trial_gpt4o_5
{ "original_instruction": "", "prompt_id": "00047909", "row_id": 47909, "seed_ids": "[3894]" }
0.716981
Taco_47909
I
[ "factorial", "binomial_coefficient", "count_unique_arrays", "process_test_cases", "main" ]
5
[ [ "binomial_coefficient", "factorial" ], [ "count_unique_arrays", "binomial_coefficient" ], [ "process_test_cases", "count_unique_arrays" ] ]
3
[ "process_test_cases" ]
false
[]
false
pytest
true
[]
true
384e52cd20af2adb4bd74f2f1f1e05287369c4f4
a831f1326d3042a8f7f9b7faccb9e692cbcc66a5
v1.0
instruct
Taco
Taco_48048_I
A company needs to manage its employee information effectively. Each employee has a unique ID and belongs to a specific department. The goal is to determine the number of unique departments in the company based on given employee records. Can you help with this task? Write a program that takes the number of test cases....
def unique_departments(test_cases): results = [] for employees in test_cases: departments = set() for emp_id, dept in employees: departments.add(dept) results.append(len(departments)) return results def parse_input(input_str): lines = input_str.strip().split('\n') ...
import pytest from solution import unique_departments, parse_input, solve def test_unique_departments(): test_cases = [ [("E001", "HR"), ("E002", "Finance"), ("E003", "HR")], [("E004", "IT"), ("E005", "IT"), ("E006", "Marketing"), ("E007", "Finance")] ] assert unique_departments(test_cases...
[ { "docstring": null, "function_declaration": "def unique_departments(test_cases):", "function_name": "unique_departments", "parameter_list": "(test_cases)" }, { "docstring": null, "function_declaration": "def parse_input(input_str):", "function_name": "parse_input", "parameter_li...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl", "solution_code": "def count_unique_departments(test_cases):\n result = []\n for case in test_cases:\n unique_departments = set()\n for emp_id, dept in case:\n ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00048048", "row_id": 48048, "seed_ids": "[895]" }
0.634535
Taco_48048
I
[ "unique_departments", "parse_input", "solve" ]
3
[ [ "solve", "parse_input" ], [ "solve", "unique_departments" ] ]
2
[ "parse_input" ]
false
[]
false
pytest
true
[]
true
9412224586688c3b0722cb77f13f32c454d5ebe1
e44e1f84af5414dc0d454893edda58d17b8b13ef
v1.0
instruct
Taco
Taco_48053_I
Given a positive integer \(N\), your task is to find and print all pairs of prime numbers \((p1, p2)\) such that their sum is equal to \(N\). A prime number is a natural number greater than 1 that has no positive divisors other than 1 and itself. For example, 2, 3, 5, 7, and 11 are prime numbers. -----Input:----- The...
def is_prime(n): """Helper function to check if a number is prime.""" if n <= 1: return False if n <= 3: return True if n % 2 == 0 or n % 3 == 0: return False i = 5 while i * i <= n: if n % i == 0 or n % (i + 2) == 0: return False i += 6 re...
from solution import is_prime, find_prime_pairs def test_is_prime(): assert is_prime(2) == True assert is_prime(3) == True assert is_prime(4) == False assert is_prime(29) == True assert is_prime(97) == True assert is_prime(100) == False def test_find_prime_pairs_10(capsys): find_prime_pair...
[ { "docstring": "Helper function to check if a number is prime.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Function to find all pairs of prime numbers (p1, p2) such that their sum is equal to N.", "function_declara...
[ 0, 1, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_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": "00048053", "row_id": 48053, "seed_ids": "[8413]" }
0.83325
Taco_48053
I
[ "is_prime", "find_prime_pairs" ]
2
[ [ "find_prime_pairs", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
75db6dbb58d5ce28039f6f2b1223e592ae0e6666
e03dd19e8b216e756cacd4004753235e9af19eb9