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
Code_Contests
Code_Contests_25688_I
A prime number is a natural number greater than 1 that has no positive divisors other than 1 and itself. For instance: * the following numbers are prime: 2, 3, 5, 7, 11; * the following numbers are not prime: 4, 6, 8, 9, 10. You are given two positive integers n and m. Find a pair of prime numbers p1 and p2 such that...
def sieve_of_eratosthenes(limit): is_prime = [True] * (limit + 1) p = 2 while (p * p <= limit): if (is_prime[p] == True): for i in range(p * p, limit + 1, p): is_prime[i] = False p += 1 prime_numbers = [p for p in range(2, limit + 1) if is_prime[p]] return...
from solution import find_prime_pair def test_find_prime_pair_1(): p1, p2 = find_prime_pair(2, 10) assert abs(p1 - p2) == 2 assert p1 + p2 <= 10 def test_find_prime_pair_2(): p1, p2 = find_prime_pair(4, 20) assert abs(p1 - p2) == 4 assert p1 + p2 <= 20 def test_find_prime_pair_3(): p1, p2...
[ { "docstring": null, "function_declaration": "def sieve_of_eratosthenes(limit):", "function_name": "sieve_of_eratosthenes", "parameter_list": "(limit)" }, { "docstring": null, "function_declaration": "def find_prime_pair(n, m):", "function_name": "find_prime_pair", "parameter_lis...
[ 0, 0, 0, 0, 0, 1, 0, 0, 0, 1 ]
2
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def sieve(n):\n \"\"\"\n Sieve of Eratosthenes to find all primes less than or equal to n.\n \"\"\"\n is_prime = [True] * (n + 1)\n is_prime...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00025688", "row_id": 25688, "seed_ids": "[1584]" }
0.74238
Code_Contests_25688
I
[ "sieve_of_eratosthenes", "find_prime_pair" ]
2
[ [ "find_prime_pair", "sieve_of_eratosthenes" ] ]
1
[]
false
[]
false
pytest
true
[]
true
70d0780e261317e8f5d36f6d40eef077281e0a86
c2b95b6f29254c1bbb478f1dc3fe1ad070f42c30
v1.0
instruct
Code_Contests
Code_Contests_25733_I
Petya loves palindromic numbers very much. A palindromic number is a number that remains the same when its digits are reversed. For example, numbers 121, 4774, 12321 are palindromic and numbers 123, 789, 4567 are not. Petya also loves prime numbers. A prime number is a positive integer greater than 1 that has no posit...
def is_palindrome(n): """ Returns True if n is a palindrome, False otherwise. """ return str(n) == str(n)[::-1] def is_prime(n): """ Returns True if n is a prime number, False otherwise. """ if n <= 1: return False if n <= 3: return True if n % 2 == 0 or n % 3 ==...
from solution import is_palindromic_prime def test_palindromic_prime(): assert is_palindromic_prime(2) == "YES" assert is_palindromic_prime(131) == "YES" assert is_palindromic_prime(12) == "NO" assert is_palindromic_prime(9339) == "NO" def test_palindromic_not_prime(): assert is_palindromic_prime(...
[ { "docstring": "Returns True if n is a palindrome, False otherwise.", "function_declaration": "def is_palindrome(n):", "function_name": "is_palindrome", "parameter_list": "(n)" }, { "docstring": "Returns True if n is a prime number, False otherwise.", "function_declaration": "def is_prim...
[ 0, 0, 1 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_palindromic_prime(n):\n \"\"\"\n Checks if a given number is a palindromic prime.\n\n :param n: integer, the number to be checked\n :ret...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00025733", "row_id": 25733, "seed_ids": "[6589]" }
0.649477
Code_Contests_25733
I
[ "is_palindrome", "is_prime", "is_palindromic_prime" ]
3
[ [ "is_palindromic_prime", "is_palindrome" ], [ "is_palindromic_prime", "is_prime" ] ]
2
[]
false
[]
false
pytest
true
[]
true
814d2b8a89df4bca7a571628fb9021cb63a3f713
289fe961adcd5a35a61cd980ce10e277ca69dbde
v1.0
instruct
Code_Contests
Code_Contests_25867_I
Given a string `s` of lowercase English letters and a list of words `words`, find the number of words that are subsequences of `s`. A subsequence is a sequence that can be derived from another sequence by deleting some or no elements without changing the order of the remaining elements. Input The first line contains...
def is_subsequence(s, word): """ Check if word is a subsequence of string s. """ it = iter(s) return all(char in it for char in word) def count_subsequences(s, words): """ Count how many words in the list are subsequences of s. """ return sum(1 for word in words if is_subsequence(s,...
from solution import is_subsequence, count_subsequences, main def test_is_subsequence(): assert is_subsequence("abpcplea", "ale") == True assert is_subsequence("abpcplea", "apple") == True assert is_subsequence("abpcplea", "monkey") == False assert is_subsequence("abcdef", "a") == True assert is_su...
[ { "docstring": "Check if word is a subsequence of string s.", "function_declaration": "def is_subsequence(s, word):", "function_name": "is_subsequence", "parameter_list": "(s, word)" }, { "docstring": "Count how many words in the list are subsequences of s.", "function_declaration": "def...
[ 0, 0, 1 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_subsequence(s, word):\n \"\"\"\n Helper function to check if word is a subsequence of s.\n \"\"\"\n it = iter(s)\n return all(char in...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00025867", "row_id": 25867, "seed_ids": "[6415]" }
0.82322
Code_Contests_25867
I
[ "is_subsequence", "count_subsequences", "main" ]
3
[ [ "count_subsequences", "is_subsequence" ] ]
1
[]
false
[]
false
pytest
true
[]
true
fef2c097ce3b5a2b9d7e85912f91538ff08e6076
4bd87367d6f2559a88a436534b5bca4d9a05b28d
v1.0
instruct
Code_Contests
Code_Contests_25933_I
Problem Alice is planning a trip to visit different museums in a new city. She has a map of the city that shows the museums and the walking paths connecting them. Alice wants to maximize her total enjoyment by visiting as many distinct museums as possible, without visiting any museum more than once. Alice can start h...
def maximum_enjoyment(n, m, enjoyment_values, paths): from collections import defaultdict from itertools import permutations def dfs(start, graph, visited): stack = [start] total_enjoyment = 0 while stack: node = stack.pop() if node not in visited: ...
import pytest from solution import maximum_enjoyment_from_string def test_example_1(): input_str = """4 3 10 20 30 40 0 1 1 2 2 3""" assert maximum_enjoyment_from_string(input_str) == 100 def test_example_2(): input_str = """5 6 ...
[ { "docstring": null, "function_declaration": "def maximum_enjoyment(n, m, enjoyment_values, paths):", "function_name": "maximum_enjoyment", "parameter_list": "(n, m, enjoyment_values, paths)" }, { "docstring": null, "function_declaration": "def parse_input(input_str):", "function_nam...
[ 1, 1, 0 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def max_total_enjoyment(n, m, enjoyments, paths):\n from collections import defaultdict, deque\n \n # Build graph representation\n graph = defa...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00025933", "row_id": 25933, "seed_ids": "[12805]" }
0.753296
Code_Contests_25933
I
[ "maximum_enjoyment", "parse_input", "maximum_enjoyment_from_string" ]
3
[ [ "maximum_enjoyment_from_string", "maximum_enjoyment" ], [ "maximum_enjoyment_from_string", "parse_input" ] ]
2
[ "parse_input" ]
false
[]
false
pytest
true
[]
true
f31eb12ea08f77d6782edfb310b19bcb83e0d42e
2a09e056f3863d0c198646723eb516763a0a21fc
v1.0
instruct
Code_Contests
Code_Contests_25961_I
John is planning a road trip with his friends. He wants to visit as many cities as possible, but he only has a limited amount of time for the entire trip. Each city i requires ti hours to visit. Additionally, travelling between certain pairs of cities requires some travel time. Specifically, there are m direct roads, ...
import heapq import sys def max_cities_to_visit(n, m, T, visit_times, roads): # Use Dijkstra's algorithm for shortest path graph = [[] for _ in range(n + 1)] for u, v, w in roads: graph[u].append((v, w)) graph[v].append((u, w)) def dijkstra(time_limit): dist = [sys.maxsize]...
def test_max_cities_example1(): input_str = "6 7 12\n2 3 4 2 6 3\n1 2 1\n1 3 3\n2 3 1\n2 4 2\n3 5 1\n4 5 3\n5 6 2" assert input_and_solve(input_str) == 4 def test_max_cities_example2(): input_str = "5 5 10\n3 2 4 5 1\n1 2 1\n2 3 2\n3 4 3\n4 5 4\n1 3 4" assert input_and_solve(input_str) == 3 def test_m...
[ { "docstring": null, "function_declaration": "def max_cities_to_visit(n, m, T, visit_times, roads):", "function_name": "max_cities_to_visit", "parameter_list": "(n, m, T, visit_times, roads)" }, { "docstring": null, "function_declaration": "def parse_input(input_string):", "function_...
[ 0, 0, 0, 0, 0, 0, 0, 1, 0, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "from heapq import heappop, heappush\nfrom collections import defaultdict, deque\n\ndef max_cities_visit(n, m, T, visit_times, roads):\n graph = defaultd...
trial_gpt4o_7
{ "original_instruction": "", "prompt_id": "00025961", "row_id": 25961, "seed_ids": "[11515]" }
0.74511
Code_Contests_25961
I
[ "max_cities_to_visit", "parse_input", "input_and_solve" ]
3
[ [ "input_and_solve", "max_cities_to_visit" ], [ "input_and_solve", "parse_input" ] ]
2
[ "parse_input" ]
false
[]
false
pytest
false
[]
true
e59b55f211e71ffadd02b53b6f18e5d494301b53
a9984f914decbe870dc1bcb98f309008e33f4857
v1.0
instruct
Code_Contests
Code_Contests_25966_I
Write a program that calculates the complexity of a nested loop structure in terms of Big-O notation. In a given nested loop structure, represent each loop with triplet (s, e, u) where: - s: loop starts at s - e: loop ends at e - u: loop updates variable by u The loops are nested in such a way that there's no possibi...
def big_o_complexity(loop_structures): complexities = [] for loops in loop_structures: complexity = "O(" terms = [] for loop in loops: s, e, u = loop start_diff = f'({e} - {s})' term = f'{start_diff}/{u}' terms.append(term) ...
def test_complexity_single_structure(): input_string = "1\n1 n 1 1 m 2\n" expected_output = ["O((n - 1)/1(m - 1)/2)"] assert calculate_complexities(input_string) == expected_output def test_complexity_multiple_structures(): input_string = "2\n1 n 1 1 m 2\n0 n 2 0 m 2\n" expected_output = ["O((n - 1...
[ { "docstring": null, "function_declaration": "def big_o_complexity(loop_structures):", "function_name": "big_o_complexity", "parameter_list": "(loop_structures)" }, { "docstring": null, "function_declaration": "def parse_input(input_string):", "function_name": "parse_input", "par...
[ 1, 0, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def big_o_complexity(loop_structures):\n complexities = []\n \n for loops in loop_structures:\n complexity = \"O(\"\n terms = []\n ...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00025966", "row_id": 25966, "seed_ids": "[8318]" }
0.492573
Code_Contests_25966
I
[ "big_o_complexity", "parse_input", "calculate_complexities" ]
3
[ [ "calculate_complexities", "big_o_complexity" ], [ "calculate_complexities", "parse_input" ] ]
2
[ "parse_input" ]
false
[]
false
pytest
false
[]
true
4e289a7fbe43151b1311419371fb0858decaeeb4
6d159beeb1aeb0a14351a13de612915dd12d9fcb
v1.0
instruct
Code_Contests
Code_Contests_25999_I
You are given a binary tree with `N` nodes. Each node has a unique integer identifier from 1 to N, and a positive integer weight. Write a function to find the path from the root to any leaf that has the maximum sum of weights. If there are multiple paths with the same maximum sum, return the one which lexicographically...
from collections import defaultdict import heapq def find_max_sum_path(N, nodes): # Create adjacency list and weight dictionary tree = defaultdict(list) weight = {} root = None for node in nodes: id_i, weight_i, parent_i = node weight[id_i] = weight_i if parent_i == 0: ...
def test_find_max_sum_path(): input_str = "5\n1 10 0\n2 5 1\n3 20 1\n4 2 3\n5 1 3" N, nodes = parse_input(input_str) assert find_max_sum_path(N, nodes) == [1, 3, 4] def test_find_max_sum_path_multiple_paths(): input_str = "4\n1 100 0\n2 50 1\n3 50 1\n4 1 2" N, nodes = parse_input(input_str) ass...
[ { "docstring": null, "function_declaration": "def find_max_sum_path(N, nodes):", "function_name": "find_max_sum_path", "parameter_list": "(N, nodes)" }, { "docstring": null, "function_declaration": "def weight_sum_path(path, weight):", "function_name": "weight_sum_path", "paramet...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "class TreeNode:\n def __init__(self, id, weight):\n self.id = id\n self.weight = weight\n self.children = []\n\ndef find_max_sum_pa...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00025999", "row_id": 25999, "seed_ids": "[9667]" }
0.725783
Code_Contests_25999
I
[ "find_max_sum_path", "weight_sum_path", "parse_input", "main" ]
4
[ [ "find_max_sum_path", "weight_sum_path" ] ]
1
[ "parse_input" ]
false
[]
false
pytest
false
[]
true
4008ab3f750af0d3b2499cc9fb58199f78bd21ee
dadf3d87a03616b69cd4b2897a22b7803e4233c8
v1.0
instruct
Code_Contests
Code_Contests_26034_I
You are given a list of positive integers and you need to form the largest possible integer by concatenating the numbers together. Input - The first line contains an integer n (1 ≤ n ≤ 100), the number of integers in the list. - The second line contains n positive integers each less than 10^9. Output Output the la...
from functools import cmp_to_key def compare(x, y): if x + y > y + x: return -1 else: return 1 def largest_number(n, numbers): numbers = [str(number) for number in numbers] numbers.sort(key=cmp_to_key(compare)) return ''.join(numbers) def process_input(n, numbers): return larg...
from solution import process_input def test_single_number(): assert process_input(1, [1]) == "1" def test_two_numbers(): assert process_input(2, [10, 2]) == "210" def test_multiple_numbers(): assert process_input(3, [10, 2, 9]) == "9210" assert process_input(4, [54, 546, 548, 60]) == "6054854654" ...
[ { "docstring": null, "function_declaration": "def compare(x, y):", "function_name": "compare", "parameter_list": "(x, y)" }, { "docstring": null, "function_declaration": "def largest_number(n, numbers):", "function_name": "largest_number", "parameter_list": "(n, numbers)" }, ...
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "from functools import cmp_to_key\n\ndef largest_possible_integer(nums):\n \"\"\"\n Returns the largest possible integer formed by concatenating the g...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00026034", "row_id": 26034, "seed_ids": "[11305]" }
0.674226
Code_Contests_26034
I
[ "compare", "largest_number", "process_input" ]
3
[ [ "largest_number", "compare" ], [ "process_input", "largest_number" ] ]
2
[ "process_input" ]
false
[]
false
pytest
true
[]
true
3c8c8414b594067323fae7510b2c0d94b1f51225
0fade408266dcdd6aab778198dcea8d9050ac32a
v1.0
instruct
Code_Contests
Code_Contests_26126_I
In a merge sort algorithm, the idea is to divide the input array into two halves, call the same function recursively to sort both halves, and then merge the two sorted halves. The `merge` function is used for merging two halves. The `merge(arr, l, m, r)` is a key process that assumes that `arr[l..m]` and `arr[m+1..r]` ...
def merge(arr, l, m, r): """ Merges two subarrays of arr[]. First subarray is arr[l..m] Second subarray is arr[m+1..r] """ n1 = m - l + 1 n2 = r - m # Create temporary arrays L = [0] * n1 R = [0] * n2 # Copy data to temporary arrays L[] and R[] for i in range(n1): ...
from solution import merge_sort def test_merge_sort(): arr = [12, 11, 13, 5, 6, 7, 14, 9, 15, 2] merge_sort(arr, 0, len(arr) - 1) assert arr == [2, 5, 6, 7, 9, 11, 12, 13, 14, 15] def test_merge_sort_single_element(): arr = [1] merge_sort(arr, 0, len(arr) - 1) assert arr == [1] def test_merge...
[ { "docstring": "Merges two subarrays of arr[].\nFirst subarray is arr[l..m]\nSecond subarray is arr[m+1..r]", "function_declaration": "def merge(arr, l, m, r):", "function_name": "merge", "parameter_list": "(arr, l, m, r)" }, { "docstring": null, "function_declaration": "def merge_sort(a...
[ 1, 0, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def merge(arr, l, m, r):\n \"\"\"\n Merges two sorted subarrays of arr[l..r].\n First subarray is arr[l..m].\n Second subarray is arr[m+1..r].\...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00026126", "row_id": 26126, "seed_ids": "[1250]" }
0.667685
Code_Contests_26126
I
[ "merge", "merge_sort" ]
2
[ [ "merge_sort", "merge" ] ]
1
[]
false
[]
false
pytest
true
[]
true
e791ac856cd6f22d520179510a72b3ea0359c5d7
f7ed1dc74805e32e15664c389726fa5f2ce6a6c3
v1.0
instruct
Code_Contests
Code_Contests_26150_I
Polycarp has an array consisting of n integers. Let p be the length of the largest contiguous subarray consisting of equal integers. Polycarp wants to make some changes to this array so that p becomes at least k. To do this, he can change up to m elements of the array to any value he wants. Help Polycarp determine if i...
def find_subarray(arr, n, m, k): for i in range(n): changes = 0 j = i while j < n and (changes < m or arr[j] == arr[i]): if arr[j] != arr[i]: changes += 1 j += 1 if (j - i) >= k: result = list(arr) for x in rang...
from solution import polycarp_subarray_problem def test_example_1(): n = 6 m = 2 k = 3 arr = [1, 1, 2, 2, 3, 3] result = polycarp_subarray_problem(n, m, k, arr) assert result[0] == "YES" assert len(result[1]) == n assert result[1][:3] == [1, 1, 1] def test_example_2(): n = 5 m ...
[ { "docstring": null, "function_declaration": "def find_subarray(arr, n, m, k):", "function_name": "find_subarray", "parameter_list": "(arr, n, m, k)" }, { "docstring": null, "function_declaration": "def polycarp_subarray_problem(n, m, k, arr):", "function_name": "polycarp_subarray_pr...
[ 0, 0, 0, 0, 1 ]
1
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def can_make_p_at_least_k(n, m, k, array):\n \"\"\"\n Determines if it's possible to make the length of the longest contiguous subarray of equal inte...
trial_gpt4o_4
{ "original_instruction": "", "prompt_id": "00026150", "row_id": 26150, "seed_ids": "[12967]" }
0.668446
Code_Contests_26150
I
[ "find_subarray", "polycarp_subarray_problem" ]
2
[ [ "polycarp_subarray_problem", "find_subarray" ] ]
1
[]
false
[]
false
pytest
true
[]
true
68afc7fe530c492f1afb0829f0861f140016b466
174ecbd30319a85275655c40a168481fb6fa5f69
v1.0
instruct
Code_Contests
Code_Contests_26183_I
Write a function that takes a list of positive integers and returns a list of only the prime numbers from the original list, in the order they appear. **Input** - A list of positive integers **Output** - A list of prime numbers in the same order as they appear in the input list **Function Signature** ```python d...
from typing import List def is_prime(n: int) -> bool: """ Checks 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...
from solution import filter_primes def test_filter_primes_mixed_numbers(): assert filter_primes([2, 3, 4, 5, 10, 13, 17]) == [2, 3, 5, 13, 17] def test_filter_primes_no_primes(): assert filter_primes([1, 4, 6, 8, 9]) == [] def test_filter_primes_all_primes(): assert filter_primes([19, 23, 29, 31]) == [19...
[ { "docstring": "Checks if a number is prime.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Filters and returns a list of prime numbers from the given list of positive integers.", "function_declaration": "def filter_p...
[ 1, 0, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "from typing import List\n\ndef is_prime(n: int) -> bool:\n \"\"\"\n Checks if a number is prime.\n \"\"\"\n if n <= 1:\n return False\n ...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00026183", "row_id": 26183, "seed_ids": "[7014]" }
0.688663
Code_Contests_26183
I
[ "is_prime", "filter_primes" ]
2
[ [ "filter_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
56d5a71e86e7f5769d9853d9cff075d7fc71d5b1
268c4af1eaf135f30d51babec3bd5dd9ef1ca029
v1.0
instruct
Code_Contests
Code_Contests_26231_I
A "strobogrammatic number" is a number that looks the same when rotated 180 degrees (looked at upside down). For example, 69, 96, 88, and 818 are all strobogrammatic numbers. Given a range of numbers represented by strings low and high where 1 ≤ len(low) ≤ len(high) ≤ 15 and low ≤ high, find the total number of strobo...
def is_strobogrammatic(num_str): mapping = {'0': '0', '1': '1', '6': '9', '8': '8', '9': '6'} rotated = [] for char in reversed(num_str): if char not in mapping: return False rotated.append(mapping[char]) return "".join(rotated) == num_str def strobogrammatic_c...
from solution import is_strobogrammatic, strobogrammatic_count, solve def test_is_strobogrammatic(): assert is_strobogrammatic("69") == True assert is_strobogrammatic("88") == True assert is_strobogrammatic("962") == False assert is_strobogrammatic("818") == True def test_strobogrammatic_count(): ...
[ { "docstring": null, "function_declaration": "def is_strobogrammatic(num_str):", "function_name": "is_strobogrammatic", "parameter_list": "(num_str)" }, { "docstring": null, "function_declaration": "def strobogrammatic_count(low, high):", "function_name": "strobogrammatic_count", ...
[ 0, 0, 0, 0, 0, 0, 1, 0, 0, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_strobogrammatic(num):\n \"\"\"\n Checks if a number is strobogrammatic.\n \"\"\"\n strobo_pairs = {'0': '0', '1': '1', '6': '9', '8': '8...
trial_gpt4o_6
{ "original_instruction": "", "prompt_id": "00026231", "row_id": 26231, "seed_ids": "[1698]" }
0.540182
Code_Contests_26231
I
[ "is_strobogrammatic", "strobogrammatic_count", "solve" ]
3
[ [ "solve", "strobogrammatic_count" ], [ "strobogrammatic_count", "is_strobogrammatic" ] ]
2
[]
false
[]
false
pytest
true
[]
true
23324a21c5f13d372809fc9df0b4a4cdfa7c4c16
b008d844ff99f40f359b172b67b1421e6ded0a41
v1.0
instruct
Code_Contests
Code_Contests_26234_I
You are given an array of n integers and q queries. Each query is defined by three integers: x, y, and k, where (1 <= x <= y <= n) and k is a positive integer. For each query, determine if there is at least one integer within the subarray from index x to index y (inclusive) that is divisible by k. Input The first lin...
def query_results(n, q, array, queries): results = [] for x, y, k in queries: found = False for i in range(x - 1, y): if array[i] % k == 0: found = True break results.append("YES" if found else "NO") return results def execute(nu...
from solution import execute def test_small_inputs(): assert execute(5, 3, [3, 6, 8, 10, 15], [(1, 3, 2), (2, 5, 5), (1, 5, 7)]) == ["YES", "YES", "NO"] def test_no_divisibles(): assert execute(4, 2, [1, 2, 3, 4], [(1, 4, 5), (2, 4, 6)]) == ["NO", "NO"] def test_all_divisibles(): assert execute(3, 1, [2,...
[ { "docstring": null, "function_declaration": "def query_results(n, q, array, queries):", "function_name": "query_results", "parameter_list": "(n, q, array, queries)" }, { "docstring": null, "function_declaration": "def execute(number_of_elements, number_of_queries, elements, queries):", ...
[ 1, 0, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_divisible(arr, x, y, k):\n \"\"\"\n Determines if there is at least one integer within the subarray from index x to index y (inclusive) \n ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00026234", "row_id": 26234, "seed_ids": "[5766]" }
0.696172
Code_Contests_26234
I
[ "query_results", "execute" ]
2
[ [ "execute", "query_results" ] ]
1
[]
false
[]
false
pytest
true
[]
true
f17d69b2d404194a5d7322f1360b8c2c16da9154
3aff4c1874b8d2d9cb4f6c7ad978ed071757a989
v1.0
instruct
Code_Contests
Code_Contests_26248_I
Problem Description In a faraway land, there exists a special sequence known as the "magical arithmetic sequence." A sequence of integers is defined as magical if the difference between any two consecutive elements is always the same and is either a positive prime number or zero. Given an integer array, your task is ...
def is_prime(number): """ Check if a number is a prime number. """ if number <= 1: return False if number <= 3: return True if number % 2 == 0 or number % 3 == 0: return False i = 5 while i * i <= number: if number % i == 0 or number % (i + 2) == 0: ...
from solution import is_prime, check_magical_sequence, magical_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(17) == True assert is_prime(15) == False def test_check_magical_sequence(): ...
[ { "docstring": "Check if a number is a prime number.", "function_declaration": "def is_prime(number):", "function_name": "is_prime", "parameter_list": "(number)" }, { "docstring": "Check if the array can be rearranged into a magical arithmetic sequence.", "function_declaration": "def che...
[ 0, 0, 0, 0, 1 ]
1
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(n):\n \"\"\" Helper function to determine if a number is a prime number or zero. \"\"\"\n if n <= 1:\n return False\n if n == ...
trial_gpt4o_4
{ "original_instruction": "", "prompt_id": "00026248", "row_id": 26248, "seed_ids": "[13228]" }
0.688667
Code_Contests_26248
I
[ "is_prime", "check_magical_sequence", "magical_sequence" ]
3
[ [ "check_magical_sequence", "is_prime" ], [ "magical_sequence", "check_magical_sequence" ] ]
2
[]
false
[]
false
pytest
true
[]
true
c292bcda8fe65d21a6acaa617e6a49f830e0de07
c907c0fff7519ad3f2a31221d50efd536629a7e8
v1.0
instruct
Code_Contests
Code_Contests_26254_I
You are given an array `arr` of `n` positive integers. Your task is to find the maximum number of non-overlapping subarrays such that the sum of each subarray is a prime number. Input The first line contains one integer n (1 ≤ n ≤ 10^5) — the number of elements in the array. The second line contains n integers separ...
from math import isqrt def is_prime(n): if n <= 1: return False if n <= 3: return True if n % 2 == 0 or n % 3 == 0: return False i = 5 while i * i <= n: if n % i == 0 or n % (i + 2) == 0: return False i += 6 return True def max_non_overlappin...
from solution import is_prime, max_non_overlapping_subarrays_with_prime_sum def test_is_prime(): assert is_prime(2) == True assert is_prime(3) == True assert is_prime(4) == False assert is_prime(5) == True assert is_prime(10) == False assert is_prime(13) == True def test_max_non_overlapping_su...
[ { "docstring": null, "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": null, "function_declaration": "def max_non_overlapping_subarrays_with_prime_sum(arr):", "function_name": "max_non_overlapping_subarrays_with_prime_s...
[ 0, 1, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "import math\n\ndef is_prime(num):\n \"\"\"\n Helper function to check if a number is prime.\n \"\"\"\n if num <= 1:\n return False\n ...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00026254", "row_id": 26254, "seed_ids": "[3763]" }
0.663015
Code_Contests_26254
I
[ "is_prime", "max_non_overlapping_subarrays_with_prime_sum" ]
2
[ [ "max_non_overlapping_subarrays_with_prime_sum", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
add55f8dfa4e832009dd988c2ea5046710ce66e2
21c2b3be2cd4f8e1bdc4099aed86cbfcabd91063
v1.0
instruct
Code_Contests
Code_Contests_26255_I
Shreya is fascinated with numbers and she recently learned about prime numbers. She decides to create a sequence of consecutive prime numbers and wants to calculate the product of any two prime numbers in this sequence. However, Shreya finds it challenging to determine the positions in the sequence efficiently. Given ...
def sieve_of_eratosthenes(n): """ Returns a list of primes up to n (inclusive) using the Sieve of Eratosthenes algorithm. """ is_prime = [True] * (n + 1) p = 2 while (p * p <= n): if is_prime[p] == True: for i in range(p * p, n + 1, p): is_prime[i] = False ...
from solution import primes_product def test_single_query(): assert primes_product([(2, 4)]) == [21] def test_multiple_queries(): assert primes_product([(2, 4), (1, 3), (5, 5)]) == [21, 10, 121] def test_same_position(): assert primes_product([(5, 5)]) == [121] def test_large_query(): # Known primes...
[ { "docstring": "Returns a list of primes up to n (inclusive) using the Sieve of Eratosthenes algorithm.", "function_declaration": "def sieve_of_eratosthenes(n):", "function_name": "sieve_of_eratosthenes", "parameter_list": "(n)" }, { "docstring": "Generates the first n prime numbers.", "...
[ 0, 0, 0, 1 ]
1
hard
0.25
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def eratosthenes_sieve(limit):\n \"\"\" Generate all primes up to the specified limit using the Sieve of Eratosthenes \"\"\"\n is_prime = [True] * (l...
trial_gpt4o_4
{ "original_instruction": "", "prompt_id": "00026255", "row_id": 26255, "seed_ids": "[9810]" }
0.612647
Code_Contests_26255
I
[ "sieve_of_eratosthenes", "generate_primes", "primes_product" ]
3
[ [ "generate_primes", "sieve_of_eratosthenes" ], [ "primes_product", "generate_primes" ] ]
2
[]
false
[]
false
pytest
true
[]
true
2c787818da48503c4678cbef763605eca55cdeda
64b4a5a85a8738ceb4733257ffdc404acae60dd0
v1.0
instruct
Code_Contests
Code_Contests_26270_I
You are given a grid with n x m cells. Each cell can either be empty (represented by '.') or contain an obstacle (represented by '#'). You are tasked to help a group of robots to travel from the top-left cell (1,1) to the bottom-right cell (n,m). The robots can move up, down, left, or right, but they cannot move into o...
def find_unique_paths(grid, n, m): if grid[0][0] == '#' or grid[-1][-1] == '#': return 0 dp = [[0 for _ in range(m)] for _ in range(n)] dp[0][0] = 1 # Start point for i in range(n): for j in range(m): if grid[i][j] == '#': dp[i][j] = 0 else: ...
import pytest from solution import count_paths def test_sample_case_one(): input_grid = "3 3\n...\n.#.\n..." assert count_paths(input_grid) == 2 def test_sample_case_two(): input_grid = "2 2\n.#\n#." assert count_paths(input_grid) == 0 def test_no_obstacles(): input_grid = "2 2\n..\n.." asser...
[ { "docstring": null, "function_declaration": "def find_unique_paths(grid, n, m):", "function_name": "find_unique_paths", "parameter_list": "(grid, n, m)" }, { "docstring": null, "function_declaration": "def parse_input(input_grid):", "function_name": "parse_input", "parameter_lis...
[ 0, 0, 1 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def unique_paths(n, m, grid):\n if grid[0][0] == '#' or grid[n-1][m-1] == '#':\n return 0\n\n dp = [[0]*m for _ in range(n)]\n dp[0][0] = 1...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00026270", "row_id": 26270, "seed_ids": "[7220]" }
0.776318
Code_Contests_26270
I
[ "find_unique_paths", "parse_input", "count_paths" ]
3
[ [ "count_paths", "find_unique_paths" ], [ "count_paths", "parse_input" ] ]
2
[ "parse_input" ]
false
[]
false
pytest
true
[]
true
d03fc54543eeb081b921474b026c3a7db40a0e65
b455e9faf7f2bcdeb003ef0cea9e97315bff2bfa
v1.0
instruct
Code_Contests
Code_Contests_26330_I
Implement a function `find_anagram_pairs` that takes a list of strings as input and returns a list of tuples where each tuple contains indices of two strings that are anagrams of each other in the original list. Two strings are anagrams if they can be formed by rearranging the letters of each other. Ignore punctuation ...
import re from collections import defaultdict def normalize_string(s): """ Normalize the string by removing all non-alphabetic characters and sorting. """ s = re.sub(r'[^a-zA-Z]', '', s) # Remove non-alphabetic characters return ''.join(sorted(s.lower())) # Sort characters and make lowercase def...
from solution import find_anagram_pairs def test_find_anagram_pairs_basic(): words = ["Listen", "Silent", "enlist", "inlets", "google", "gogole"] assert find_anagram_pairs(words) == [(0, 1), (0, 2), (0, 3), (1, 2), (1, 3), (2, 3), (4, 5)] def test_find_anagram_pairs_empty(): assert find_anagram_pairs([]) ...
[ { "docstring": "Normalize the string by removing all non-alphabetic characters and sorting.", "function_declaration": "def normalize_string(s):", "function_name": "normalize_string", "parameter_list": "(s)" }, { "docstring": "Find pairs of indices of anagram strings in the given list of word...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "import re\nfrom collections import defaultdict\n\ndef normalize_string(s):\n \"\"\"\n Normalize the string by removing non-alphanumeric characters, \...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00026330", "row_id": 26330, "seed_ids": "[5586]" }
0.598021
Code_Contests_26330
I
[ "normalize_string", "find_anagram_pairs" ]
2
[ [ "find_anagram_pairs", "normalize_string" ] ]
1
[]
false
[]
false
pytest
true
[]
true
819bc48ca8291a1263b0651ad08706b9136a95ec
de028f2d2186f3b8896f7cd1d1cd223668c9a8b2
v1.0
instruct
Code_Contests
Code_Contests_26342_I
In a galaxy far, far away, there exists a programming droid named C3PO who loves solving problems. He is currently trying to understand a sequence of numbers generated by Tato, a young aspiring programmer. Tato generates a sequence a of length n using the following rule: - If i is even, a[i] is the greatest prime fact...
def sum_of_digits(num): return sum(int(digit) for digit in str(num)) def smallest_prime_factor(n): if n <= 1: return n for i in range(2, int(n ** 0.5) + 1): if n % i == 0: return i return n def greatest_prime_factor(n): i = 2 max_prime = -1 while i * i <= n:...
from solution import generate_sequence def test_example_case(): assert generate_sequence(5, 97) == [97, 2, 2, 2, 2] def test_single_element(): assert generate_sequence(1, 15) == [15] def test_two_elements(): assert generate_sequence(2, 14) == [14, 5] def test_three_elements(): assert generate_sequen...
[ { "docstring": null, "function_declaration": "def sum_of_digits(num):", "function_name": "sum_of_digits", "parameter_list": "(num)" }, { "docstring": null, "function_declaration": "def smallest_prime_factor(n):", "function_name": "smallest_prime_factor", "parameter_list": "(n)" ...
[ 0, 0, 0, 0, 0, 0, 0, 1, 1, 0 ]
2
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def sum_of_digits(num):\n \"\"\"\n Returns the sum of the digits of a number.\n \"\"\"\n return sum(int(digit) for digit in str(num))\n\ndef sm...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00026342", "row_id": 26342, "seed_ids": "[6628]" }
0.662017
Code_Contests_26342
I
[ "sum_of_digits", "smallest_prime_factor", "greatest_prime_factor", "generate_sequence" ]
4
[ [ "generate_sequence", "greatest_prime_factor" ], [ "generate_sequence", "smallest_prime_factor" ], [ "generate_sequence", "sum_of_digits" ] ]
3
[]
false
[]
false
pytest
true
[]
true
b5accbff071c579b1bce904d5df009d971b69438
a837ea8e0a16d3e917096565f1b967ccfe2668d1
v1.0
instruct
Code_Contests
Code_Contests_26395_I
Given an integer N, we want you to compute all the unique combinations of positive integers that sum up to N. Each combination should be a list of integers in non-decreasing order. Input: First line contains T, the number of test-cases. This is followed by T lines, where each line consists of the integer N. Output: ...
def find_combinations(target, start, current_combo, result): """ Recursive helper function to find all unique combinations of positive integers that sum up to target. """ if target == 0: result.append(list(current_combo)) return for i in range(start, target + 1): current_comb...
from solution import find_combinations_to_sum, process_test_cases def test_find_combinations_to_sum(): # Test case for N = 4 result = find_combinations_to_sum(4) expected = [[1, 1, 1, 1], [1, 1, 2], [1, 3], [2, 2], [4]] assert result == expected # Test case for N = 3 result = find_combinations...
[ { "docstring": "Recursive helper function to find all unique combinations of positive integers that sum up to target.", "function_declaration": "def find_combinations(target, start, current_combo, result):", "function_name": "find_combinations", "parameter_list": "(target, start, current_combo, resu...
[ 1, 0, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def find_combinations(n, start=1, current_combination=None, all_combinations=None):\n if current_combination is None:\n current_combination = []\...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00026395", "row_id": 26395, "seed_ids": "[5069]" }
0.66804
Code_Contests_26395
I
[ "find_combinations", "find_combinations_to_sum", "process_test_cases" ]
3
[ [ "find_combinations_to_sum", "find_combinations" ], [ "process_test_cases", "find_combinations_to_sum" ] ]
2
[ "process_test_cases" ]
false
[]
false
pytest
true
[]
true
826b973abf51f7978e9a00cbf6ca9ecf2ec232e7
65c78fd6492d48db00d4b5e7ea02fa17ae468eee
v1.0
instruct
Code_Contests
Code_Contests_26418_I
You are given a tree with n vertices labeled from 1 to n and with edges weighted by positive integers. Your task is to find the maximum possible sum of weights on a simple path between any two vertices in the tree. A tree with n vertices is a connected graph with n-1 edges and no cycles. ### Input The first line of i...
from collections import defaultdict import sys sys.setrecursionlimit(10**6) def find_farthest_node(tree, start_node, n): def dfs(node, parent, distance): farthest_node[0], farthest_dist[0] = (node, distance) if distance > farthest_dist[0] else (farthest_node[0], farthest_dist[0]) for neighbor, wei...
from solution import calculate_maximum_path_sum def test_example_case(): input_str = "5\n1 2 3\n2 3 4\n2 4 2\n3 5 6" assert calculate_maximum_path_sum(input_str) == 13 def test_minimum_case(): input_str = "2\n1 2 5" assert calculate_maximum_path_sum(input_str) == 5 def test_simple_case(): input_s...
[ { "docstring": null, "function_declaration": "def find_farthest_node(tree, start_node, n):", "function_name": "find_farthest_node", "parameter_list": "(tree, start_node, n)" }, { "docstring": null, "function_declaration": "def maximum_path_sum(n, edges):", "function_name": "maximum_p...
[ 1, 0, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "from collections import defaultdict\nimport sys\n\nsys.setrecursionlimit(10**6)\n\ndef find_farthest_node(tree, start_node, n):\n def dfs(node, parent, ...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00026418", "row_id": 26418, "seed_ids": "[9183]" }
0.776233
Code_Contests_26418
I
[ "find_farthest_node", "maximum_path_sum", "calculate_maximum_path_sum" ]
3
[ [ "calculate_maximum_path_sum", "maximum_path_sum" ], [ "maximum_path_sum", "find_farthest_node" ] ]
2
[]
false
[]
false
pytest
true
[]
true
94a44dfa078946d94edc806902a3b90e8c752858
d6e98ac72f10dae7faf97d70a1b71557022a871e
v1.0
instruct
Code_Contests
Code_Contests_26452_I
An international bank is migrating its transaction processing system to a new platform. As part of testing, they want to ensure the integrity of daily transactions. Each transaction is either a credit or a debit, and each has a unique ID and an amount associated with it. To verify the transactions, they need to calcula...
def calculate_final_balance(transactions): balance = 0 for transaction in transactions: tid, ttype, amount = transaction.split() amount = int(amount) if ttype == "credit": balance += amount elif ttype == "debit": balance -= amount return balance def p...
def test_calculate_final_balance(): transactions = [ "T1 credit 100", "T2 debit 50", "T3 credit 150" ] assert calculate_final_balance(transactions) == 200 transactions = [ "T1 debit 200", "T2 credit 100" ] assert calculate_final_balance(transactions) == -...
[ { "docstring": null, "function_declaration": "def calculate_final_balance(transactions):", "function_name": "calculate_final_balance", "parameter_list": "(transactions)" }, { "docstring": null, "function_declaration": "def process_multiple_test_cases(test_cases):", "function_name": "...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def calculate_closing_balance(test_cases):\n results = []\n for transactions in test_cases:\n balance = 0\n for transaction in transact...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00026452", "row_id": 26452, "seed_ids": "[10695]" }
0.623993
Code_Contests_26452
I
[ "calculate_final_balance", "process_multiple_test_cases", "parse_input", "calculate_balances_from_input" ]
4
[ [ "calculate_balances_from_input", "parse_input" ], [ "calculate_balances_from_input", "process_multiple_test_cases" ], [ "process_multiple_test_cases", "calculate_final_balance" ] ]
3
[ "process_multiple_test_cases", "parse_input" ]
false
[]
false
pytest
false
[]
true
707470e0a7f6f3ebbde451a9d01ef1b81687ff48
fff787ad5e28adacfca580001b1174c4924b4663
v1.0
instruct
Code_Contests
Code_Contests_26499_I
You are given a string of lowercase letters and a dictionary of words. Your task is to determine the length of the longest string that can be formed by deleting some characters of the given string so that it becomes a subsequence of a word in the dictionary. A subsequence is a sequence that appears in the same relati...
def is_subsequence(sub, main): it = iter(main) return all(char in it for char in sub) def longest_subsequence(s, words): longest = 0 for word in words: if is_subsequence(word, s): longest = max(longest, len(word)) return longest
def test_longest_subsequence(): s = "abppplee" words = ["able", "ale", "apple", "bale", "kangaroo", "app"] assert longest_subsequence(s, words) == 5 def test_longest_subsequence_example2(): s = "abcdef" words = ["fed", "abc", "abf", "ace"] assert longest_subsequence(s, words) == 3 def test_no_...
[ { "docstring": null, "function_declaration": "def is_subsequence(sub, main):", "function_name": "is_subsequence", "parameter_list": "(sub, main)" }, { "docstring": null, "function_declaration": "def longest_subsequence(s, words):", "function_name": "longest_subsequence", "paramet...
[ 1, 1, 0 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_subsequence(sub, main):\n it = iter(main)\n return all(char in it for char in sub)\n\ndef longest_subsequence(s, words):\n longest = 0\n ...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00026499", "row_id": 26499, "seed_ids": "[7333]" }
0.761763
Code_Contests_26499
I
[ "is_subsequence", "longest_subsequence" ]
2
[ [ "longest_subsequence", "is_subsequence" ] ]
1
[]
false
[]
false
pytest
false
[]
true
4e42ed30b7bb9669bab3ff58a8963db109dec2ae
044c94209d8f8b13aa95a15812f291f8de26a18a
v1.0
instruct
Code_Contests
Code_Contests_26517_I
Write a program that takes an integer n and returns the first n numbers in the Fibonacci sequence that are prime. The Fibonacci sequence is defined as: F(1) = 1 F(2) = 1 F(n) = F(n-1) + F(n-2) for n > 2 A prime number is a natural number greater than 1 that has no divisors other than 1 and itself. Input...
def is_prime(number): """ Returns True if the given number is prime, otherwise False. """ if number <= 1: return False if number == 2: return True if number % 2 == 0: return False for i in range(3, int(number**0.5) + 1, 2): if number % i == 0: retu...
def test_is_prime(): # Testing known primes assert is_prime(2) == True assert is_prime(3) == True assert is_prime(7) == True # Testing known non-primes assert is_prime(0) == False assert is_prime(1) == False assert is_prime(8) == False # Testing edge case assert is_prim...
[ { "docstring": "Returns True if the given number is prime, otherwise False.", "function_declaration": "def is_prime(number):", "function_name": "is_prime", "parameter_list": "(number)" }, { "docstring": "Returns the first n prime numbers in the Fibonacci sequence.", "function_declaration...
[ 0, 0, 0, 0, 0, 1, 0, 1, 1, 0 ]
3
hard
0.3
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(num):\n \"\"\"\n Check if a number is prime.\n \"\"\"\n if num <= 1:\n return False\n if num == 2:\n return True\...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00026517", "row_id": 26517, "seed_ids": "[12490]" }
0.824227
Code_Contests_26517
I
[ "is_prime", "fibonacci_primes" ]
2
[ [ "fibonacci_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
false
[]
true
2afbce0c07fa35126a85e85543c01b3b3cc117c2
23c3de3c521e60eac14696b56de4be038058a5bb
v1.0
instruct
Code_Contests
Code_Contests_26536_I
Write a function that takes a list of n natural numbers and returns the smallest multiple that is evenly divisible by all of the numbers in the list. Clue: You may need to use the relationship between the Least Common Multiple (LCM) and Greatest Common Divisor (GCD). Input The input consists of a single line contai...
import math from functools import reduce def lcm(a, b): """Function to return the least common multiple of two numbers""" return a * b // math.gcd(a, b) def smallest_multiple(numbers): """ Returns the smallest multiple that is evenly divisible by all numbers in the list. """ return reduce(lcm,...
from solution import lcm, smallest_multiple def test_lcm(): assert lcm(1, 1) == 1 assert lcm(2, 3) == 6 assert lcm(4, 5) == 20 assert lcm(6, 8) == 24 assert lcm(12, 15) == 60 def test_smallest_multiple(): assert smallest_multiple([3, 5, 7]) == 105 assert smallest_multiple([1, 2, 3, 4, 5]) ...
[ { "docstring": "Function to return the least common multiple of two numbers", "function_declaration": "def lcm(a, b):", "function_name": "lcm", "parameter_list": "(a, b)" }, { "docstring": "Returns the smallest multiple that is evenly divisible by all numbers in the list.", "function_dec...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "from math import gcd\nfrom functools import reduce\n\ndef lcm(a, b):\n \"\"\"\n Returns the Least Common Multiple (LCM) of a and b.\n \"\"\"\n ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00026536", "row_id": 26536, "seed_ids": "[6340]" }
0.642051
Code_Contests_26536
I
[ "lcm", "smallest_multiple" ]
2
[ [ "smallest_multiple", "lcm" ] ]
1
[]
false
[]
false
pytest
true
[]
true
a28416af341a54e186bde4aef12200d962ba948d
004d96fcb38a17b6cc88e216b3bdbc4c1ce2344f
v1.0
instruct
Code_Contests
Code_Contests_26555_I
Tom loves playing with his toy road-building set, where he builds a city with various roads connecting intersections. Each intersection has unique coordinates in a 2D plane. Tom wonders about the shortest distance required to connect all the intersections with roads while ensuring there's a direct or indirect route bet...
import math from heapq import heappop, heappush def euclidean_distance(x1, y1, x2, y2): return math.sqrt((x1 - x2) ** 2 + (y1 - y2) ** 2) def min_road_length(n, intersections): if n <= 1: return 0 adj = {i: [] for i in range(n)} # adjacency list for i in range(n): for j in range(i + ...
from solution import min_road_length def test_min_road_length_example(): n = 4 intersections = [(0, 0), (0, 1), (1, 0), (1, 1)] assert min_road_length(n, intersections) == 3.00 def test_min_road_length_single_intersection(): n = 1 intersections = [(0, 0)] assert min_road_length(n, intersection...
[ { "docstring": null, "function_declaration": "def euclidean_distance(x1, y1, x2, y2):", "function_name": "euclidean_distance", "parameter_list": "(x1, y1, x2, y2)" }, { "docstring": null, "function_declaration": "def min_road_length(n, intersections):", "function_name": "min_road_len...
[ 1, 0, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "import math\nfrom heapq import heappop, heappush\n\ndef euclidean_distance(x1, y1, x2, y2):\n return math.sqrt((x1 - x2) ** 2 + (y1 - y2) ** 2)\n\ndef m...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00026555", "row_id": 26555, "seed_ids": "[11674]" }
0.645637
Code_Contests_26555
I
[ "euclidean_distance", "min_road_length" ]
2
[ [ "min_road_length", "euclidean_distance" ] ]
1
[]
false
[]
false
pytest
true
[]
true
7305ec8f20f8fb27790f55ea7f26f181e68bceaa
e0b409f36131d53e7538abcdf911011b62d60ddc
v1.0
instruct
Code_Contests
Code_Contests_26694_I
You are given an array of distinct integers A, consisting of n elements. Your task is to determine if it is possible to rearrange the elements of the array in such a way that all the following conditions are satisfied: 1. For any prime number p ≤ n, the sum of every p-th element is even. 2. For each prime number p ≤ n...
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 rearrange_array(n, A): primes = [i for i in range(2, n + 1) if i...
from solution import is_prime, rearrange_array 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_rearrange_array_possible(): assert rearrange_array(4, [1, 2, 3, 4]) == ("YES",...
[ { "docstring": null, "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": null, "function_declaration": "def rearrange_array(n, A):", "function_name": "rearrange_array", "parameter_list": "(n, A)" } ]
[ 1, 1, 0 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(num):\n if num <= 1:\n return False\n if num == 2:\n return True\n if num % 2 == 0:\n return False\n for i in...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00026694", "row_id": 26694, "seed_ids": "[11368]" }
0.636161
Code_Contests_26694
I
[ "is_prime", "rearrange_array" ]
2
[ [ "rearrange_array", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
ee7680df53c679c0f1cd1ae7c85f0ec2f1cbe40d
5bbdd3af2eb035a2d2b1da5ab0e6e2b8bf32c910
v1.0
instruct
Code_Contests
Code_Contests_26695_I
In the kingdom of Vertlandia, the king has decided to construct a new road system to connect all the cities in the kingdom. The king has a list of possible roads to be constructed and each road has a cost associated with it. The king wants to ensure that all the cities are connected with the minimum possible cost. 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): xroot = find_parent(parent, x) yroot = find_parent(parent, y) if rank[xroot] < rank[yroot]: parent[xroot] = yroot elif rank[xroot] > rank[y...
def test_min_cost_to_connect_all_cities(): input_str = "4 5\n1 2 1\n2 3 2\n3 4 4\n4 1 8\n1 3 3\n3 3\n1 2 2\n2 3 3\n1 3 1\n0 0\n" expected_output = "7\n3" assert min_cost_to_connect_all_cities(input_str) == expected_output def test_min_cost_edge_case(): input_str = "2 1\n1 2 1\n0 0\n" expected_outpu...
[ { "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, 1, 0 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def find_parent(parent, i):\n if parent[i] == i:\n return i\n else:\n return find_parent(parent, parent[i])\n\ndef union(parent, rank, ...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00026695", "row_id": 26695, "seed_ids": "[1446]" }
0.749316
Code_Contests_26695
I
[ "find_parent", "union", "kruskal", "min_cost_to_connect_all_cities" ]
4
[ [ "kruskal", "find_parent" ], [ "kruskal", "union" ], [ "min_cost_to_connect_all_cities", "kruskal" ], [ "union", "find_parent" ] ]
4
[]
false
[]
false
pytest
false
[]
true
768d9fc9d2a5972f7f583713df49893c2d6f8f78
024f2bfdfce05942b29cde1e898f64494fd930d7
v1.0
instruct
Code_Contests
Code_Contests_26770_I
In a small town, the mayor wants to build a series of monuments and parks. There are n parks, each numbered from 1 to n, where some of them need to be connected to pipe networks to provide water. Each connection between parks is bidirectional and can supply water to both parks involved. However, connecting two parks co...
def find(parent, i): if parent[i] == i: return i return find(parent, parent[i]) def union(parent, rank, x, y): xroot = find(parent, x) yroot = find(parent, y) if rank[xroot] < rank[yroot]: parent[xroot] = yroot elif rank[xroot] > rank[yroot]: parent[yroot] = xroot ...
from solution import min_cost_to_connect_parks def test_example1(): assert min_cost_to_connect_parks(4, 5, [(1, 2, 1), (2, 3, 2), (3, 4, 3), (4, 1, 4), (1, 3, 5)]) == 6 def test_example2(): assert min_cost_to_connect_parks(4, 3, [(1, 2, 3), (2, 3, 4), (4, 4, 1)]) == -1 def test_single_connection(): asser...
[ { "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_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def find(parent, i):\n if parent[i] == i:\n return i\n else:\n return find(parent, parent[i])\n\ndef union(parent, rank, x, y):\n xr...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00026770", "row_id": 26770, "seed_ids": "[10671]" }
0.691145
Code_Contests_26770
I
[ "find", "union", "min_cost_to_connect_parks" ]
3
[ [ "min_cost_to_connect_parks", "find" ], [ "min_cost_to_connect_parks", "union" ], [ "union", "find" ] ]
3
[]
false
[]
false
pytest
true
[]
true
979d18bc20f3b5e157e57b5f62d8d62bd5983f0a
48956c3a18b9247173b0c01bda8b945063ce4ad1
v1.0
instruct
Code_Contests
Code_Contests_26890_I
In a mystical forest, there are n wizards standing in a line. Each wizard has a unique power level represented as an integer. The wizards want to perform a power alignment ritual, where each wizard must adjust their position in such a way that they form a non-decreasing sequence of power levels. The wizards can only sw...
def merge_count_split_inv(arr, temp_arr, left, mid, right): i = left # Starting index for left subarray j = mid + 1 # Starting index for right subarray k = left # Starting index to be sorted inv_count = 0 while i <= mid and j <= right: if arr[i] <= arr[j]: temp_arr[k] = ...
from solution import min_swaps_to_sort def test_example1(): assert min_swaps_to_sort([5, 4, 3, 2, 1]) == 10 def test_example2(): assert min_swaps_to_sort([1, 5, 3, 2, 4]) == 4 def test_example3(): assert min_swaps_to_sort([2, 3, 1]) == 2 def test_single_element(): assert min_swaps_to_sort([1]) == 0 ...
[ { "docstring": null, "function_declaration": "def merge_count_split_inv(arr, temp_arr, left, mid, right):", "function_name": "merge_count_split_inv", "parameter_list": "(arr, temp_arr, left, mid, right)" }, { "docstring": null, "function_declaration": "def merge_sort_and_count(arr, temp_...
[ 0, 0, 0, 1, 0 ]
1
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def min_swaps_to_sort(arr):\n \"\"\"\n Returns the minimum number of swaps required to sort the array.\n \"\"\"\n n = len(arr)\n arrpos = [(...
trial_gpt4o_3
{ "original_instruction": "", "prompt_id": "00026890", "row_id": 26890, "seed_ids": "[11478]" }
0.636784
Code_Contests_26890
I
[ "merge_count_split_inv", "merge_sort_and_count", "min_swaps_to_sort" ]
3
[ [ "merge_sort_and_count", "merge_count_split_inv" ], [ "min_swaps_to_sort", "merge_sort_and_count" ] ]
2
[]
false
[]
false
pytest
true
[]
true
84fd2c7a9e33e2b90c819311ec607168483aa94a
698399cb5ea2da6da1c45b7b93399ff89bb29bf5
v1.0
instruct
Code_Contests
Code_Contests_26962_I
Minimites are learning how to determine whether a given number is a palindrome. A palindrome is a number that remains the same when its digits are reversed. Your task is to help them by writing a function that reads a series of numbers and determines if each number is a palindrome. For the input, the first line contai...
def is_palindrome(num): """ Checks if a number is a palindrome. """ return str(num) == str(num)[::-1] def check_palindromes(numbers): """ Checks a list of numbers to determine if they are palindromes. Args: numbers: A list of integers Returns: A list of strings...
from solution import is_palindrome, check_palindromes def test_is_palindrome(): assert is_palindrome(121) == True assert is_palindrome(12321) == True assert is_palindrome(123) == False assert is_palindrome(45654) == True assert is_palindrome(1221) == True assert is_palindrome(12345) == False d...
[ { "docstring": "Checks if a number is a palindrome.", "function_declaration": "def is_palindrome(num):", "function_name": "is_palindrome", "parameter_list": "(num)" }, { "docstring": "Checks a list of numbers to determine if they are palindromes.\n\nArgs:\n numbers: A list of integers\n\n...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def check_palindromes(numbers):\n \"\"\"\n Given a list of numbers, determine if each number is a palindrome.\n A number is a palindrome if it rea...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00026962", "row_id": 26962, "seed_ids": "[11420]" }
0.745179
Code_Contests_26962
I
[ "is_palindrome", "check_palindromes" ]
2
[ [ "check_palindromes", "is_palindrome" ] ]
1
[]
false
[]
false
pytest
true
[]
true
3f8f8f64470cebe467cd6bc320586a3ccf64f334
bcfe7eb681c3d2cba3bd58edc8005ea53f81843c
v1.0
instruct
Code_Contests
Code_Contests_27002_I
You are provided with a list of words and a target word. Your task is to create a program that can identify the closest match to the target word from the list based on the Levenshtein distance (edit distance). The Levenshtein distance between two words is the minimum number of single-character edits (insertions, deleti...
def levenshtein_distance(a, b): """ Calculate the Levenshtein distance between two strings a and b. """ if len(a) < len(b): return levenshtein_distance(b, a) if len(b) == 0: return len(a) previous_row = range(len(b) + 1) for i, ca in enumerate(a): current_row = [i +...
def test_levenshtein_distance(): assert levenshtein_distance("kitten", "sitting") == 3 assert levenshtein_distance("kitten", "kitten") == 0 assert levenshtein_distance("kitten", "mittens") == 2 assert levenshtein_distance("kitten", "kit") == 3 assert levenshtein_distance("kitten", "bit") == 4 def t...
[ { "docstring": "Calculate the Levenshtein distance between two strings a and b.", "function_declaration": "def levenshtein_distance(a, b):", "function_name": "levenshtein_distance", "parameter_list": "(a, b)" }, { "docstring": "Find the closest word to the target based on Levenshtein distanc...
[ 0, 1, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def levenshtein_distance(word1, word2):\n \"\"\"\n Computes the Levenshtein Distance between two words.\n \"\"\"\n if len(word1) < len(word2):\...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00027002", "row_id": 27002, "seed_ids": "[12149]" }
0.663769
Code_Contests_27002
I
[ "levenshtein_distance", "find_closest_word" ]
2
[ [ "find_closest_word", "levenshtein_distance" ] ]
1
[]
false
[]
false
pytest
false
[]
true
6e8c30f8f26e8136385912e239a138364c898609
0ac4a6cbe9d3da9db5c902ef5c19b505cc1dd3f1
v1.0
instruct
Code_Contests
Code_Contests_27031_I
Riya is learning about trees in her data structures class. As part of her assignment, she is required to reconstruct a binary tree from its given inorder and postorder traversals. Reconstructing the tree will help her further understand the properties of binary trees and traversal methods. Given the inorder and postord...
class TreeNode: def __init__(self, value=0, left=None, right=None): self.value = value self.left = left self.right = right def build_tree(inorder, postorder): if not inorder or not postorder: return None root_val = postorder.pop() root = TreeNode(root_val) ...
def test_reconstruct_tree_and_print_preorder_case1(): t = 2 test_cases = [ (6, [4, 2, 5, 1, 6, 3], [4, 5, 2, 6, 3, 1]), (3, [3, 2, 1], [3, 2, 1]) ] expected = [ [1, 2, 4, 5, 3, 6], [1, 2, 3] ] result = reconstruct_tree_and_print_preorder(t, test_cases) assert ...
[]
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_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...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00027031", "row_id": 27031, "seed_ids": "[9269]" }
0.662978
Code_Contests_27031
I
[ "build_tree", "preorder_traversal", "reconstruct_tree_and_print_preorder" ]
3
[ [ "reconstruct_tree_and_print_preorder", "build_tree" ], [ "reconstruct_tree_and_print_preorder", "preorder_traversal" ] ]
2
[]
false
[ "TreeNode" ]
true
pytest
false
[]
true
62c205df6e0a9fac24ac03b2991be47c8a1e779d
c8855c1bb0ee9a2e2d83e7eecf955ea3d79131c2
v1.0
instruct
Code_Contests
Code_Contests_27043_I
Megan is learning about prime numbers in her mathematics class, and she came up with an interesting problem. She wants to find the smallest integer N greater than or equal to a given integer M such that the sum of the digits of N is also a prime number. However, Megan's problem is that she is not very good at writing c...
def is_prime(number): """ Check if a number is a prime number. """ if number <= 1: return False if number <= 3: return True if number % 2 == 0 or number % 3 == 0: return False i = 5 while i * i <= number: if number % i == 0 or number % (i + 2) == 0: ...
from solution import is_prime, sum_of_digits, smallest_number_with_prime_digit_sum 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(11) == True assert is_prime(16) == False def test_sum_of_digits()...
[ { "docstring": "Check if a number is a prime number.", "function_declaration": "def is_prime(number):", "function_name": "is_prime", "parameter_list": "(number)" }, { "docstring": "Returns the sum of the digits of n.", "function_declaration": "def sum_of_digits(n):", "function_name":...
[ 0, 0, 0, 0, 0, 0, 0, 1, 1, 1 ]
3
hard
0.3
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(n):\n \"\"\"\n Determine if a given number is prime.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return T...
trial_gpt4o_7
{ "original_instruction": "", "prompt_id": "00027043", "row_id": 27043, "seed_ids": "[613]" }
0.644243
Code_Contests_27043
I
[ "is_prime", "sum_of_digits", "smallest_number_with_prime_digit_sum" ]
3
[ [ "smallest_number_with_prime_digit_sum", "is_prime" ], [ "smallest_number_with_prime_digit_sum", "sum_of_digits" ] ]
2
[]
false
[]
false
pytest
true
[]
true
e398d513b4516d42b3849cddbd397b3fb7ebb7a4
1e47535f1de226fad4d1e42e57aa59d50425e987
v1.0
instruct
Code_Contests
Code_Contests_27092_I
You are working with a networked system on which multiple devices communicate with each other. Each device can be thought of as a node in a network, and the communication between any two given devices is represented as a weighted direct connection between those two nodes. Due to certain circumstances, you need to dete...
import heapq import sys def dijkstra(graph, start, end, get_weight): n = len(graph) dist = [sys.maxsize] * n dist[start] = 0 queue = [(0, start)] while queue: current_distance, current_node = heapq.heappop(queue) if current_distance > dist[current_node]: continue ...
def test_shortest_paths(): input_str = """4 4 2 1 2 4 10 1 2 3 3 5 0 2 4 1 2 1 3 4 2 7 0 1 3 1 4 0 0 0""" expected_output = ["7 15", "5 12"] assert process_input(input_str) == expected_output def test_no_path(): input_str = """3 1 1 1 2 4 5 0 2 3 0 0 0""" expected_output = ["NO PATH"] assert pr...
[ { "docstring": null, "function_declaration": "def dijkstra(graph, start, end, get_weight):", "function_name": "dijkstra", "parameter_list": "(graph, start, end, get_weight)" }, { "docstring": null, "function_declaration": "def shortest_paths(n, m, connections, queries):", "function_n...
[ 0, 0, 0, 0, 0, 1, 0, 0, 0 ]
1
hard
0.111
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "import heapq\nimport sys\n\nINF = float('inf')\n\nclass Graph:\n def __init__(self, n):\n self.n = n\n self.edges = {i: [] for i in range(...
trial_gpt4o_6
{ "original_instruction": "", "prompt_id": "00027092", "row_id": 27092, "seed_ids": "[11656]" }
0.725696
Code_Contests_27092
I
[ "dijkstra", "shortest_paths", "process_input" ]
3
[ [ "process_input", "shortest_paths" ], [ "shortest_paths", "dijkstra" ] ]
2
[ "process_input" ]
false
[]
false
pytest
false
[]
true
8dcade13b5a97921474efc9542155a841592b796
e873aeb85d03e3ddbb682107c5fdd7e0b9054506
v1.0
instruct
Code_Contests
Code_Contests_27093_I
Given an array of positive integers, determine if there exists a subset of the array such that the product of its elements is a perfect square. Input: The first line contains an integer T, the number of test cases. Each test case consists of two lines: - The first line contains a single integer N, representing the nu...
from collections import Counter import math def is_perfect_square(n): sqrt = int(math.sqrt(n)) return sqrt * sqrt == n def has_subset_with_perfect_square_product(arr): if contains_perfect_square(arr): return True # Find all subsets and check for perfect square products n = len(arr) ...
from solution import subset_product_perfect_square def test_case_1(): T = 2 test_cases = [ (4, [2, 3, 4, 6]), (3, [2, 5, 7]) ] assert subset_product_perfect_square(T, test_cases) == ["YES", "NO"] def test_case_perfect_square_elements(): T = 1 test_cases = [ (3, [4, 9, 1...
[ { "docstring": null, "function_declaration": "def is_perfect_square(n):", "function_name": "is_perfect_square", "parameter_list": "(n)" }, { "docstring": null, "function_declaration": "def has_subset_with_perfect_square_product(arr):", "function_name": "has_subset_with_perfect_square...
[ 0, 0, 0, 1, 0 ]
1
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "from collections import Counter\nfrom math import sqrt\n\ndef prime_factors(n):\n i = 2\n factors = Counter()\n while i * i <= n:\n while (...
trial_gpt4o_3
{ "original_instruction": "", "prompt_id": "00027093", "row_id": 27093, "seed_ids": "[1529]" }
0.630189
Code_Contests_27093
I
[ "is_perfect_square", "has_subset_with_perfect_square_product", "contains_perfect_square", "subset_product_perfect_square" ]
4
[ [ "contains_perfect_square", "is_perfect_square" ], [ "has_subset_with_perfect_square_product", "contains_perfect_square" ], [ "has_subset_with_perfect_square_product", "is_perfect_square" ], [ "subset_product_perfect_square", "has_subset_with_perfect_square_product" ] ...
4
[]
false
[]
false
pytest
true
[]
true
8a8d17cac56e6d50225e4a867a6423d14fe9c038
02644ec16c41b3d43947460fb52a81da8d9d452a
v1.0
instruct
Code_Contests
Code_Contests_27121_I
Write a program that reads a series of strings and determines which of them are palindromes. A palindrome is a string that reads the same backward as forward, ignoring spaces, punctuation, and case differences. The input consists of multiple lines, each containing one string, with the end of the input indicated by a li...
def is_palindrome(s): """ Check if the given string s is a palindrome. """ # Remove all non-alphanumeric characters and convert to lower case normalized = ''.join(char.lower() for char in s if char.isalnum()) # Compare the normalized string with its reverse return normalized == normalized[::...
from solution import is_palindrome, check_palindromes def test_is_palindrome(): assert is_palindrome("Was it a car or a cat I saw") == True assert is_palindrome("Madam In Eden, I’m Adam") == True assert is_palindrome("Hello, World!") == False assert is_palindrome("A man, a plan, a canal, Panama") == Tr...
[ { "docstring": "Check if the given string s is a palindrome.", "function_declaration": "def is_palindrome(s):", "function_name": "is_palindrome", "parameter_list": "(s)" }, { "docstring": "Given a list of input strings, check each one if it's a palindrome\nand return a corresponding list of ...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_palindrome(s):\n \"\"\"\n Determines if the string `s` is a palindrome, ignoring spaces,\n punctuation, and case differences.\n \"\"\"\n...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00027121", "row_id": 27121, "seed_ids": "[3630]" }
0.767097
Code_Contests_27121
I
[ "is_palindrome", "check_palindromes" ]
2
[ [ "check_palindromes", "is_palindrome" ] ]
1
[]
false
[]
false
pytest
true
[]
true
e4ac7273f78d47ab1d9ef2b44a617d3a944eedac
2a8e28e0935ad40b8d0b9f9c3c1254e2aebf7073
v1.0
instruct
Code_Contests
Code_Contests_27150_I
A binary search tree (BST) is a binary tree where each node has a comparable key (and an associated value) and satisfies the binary search tree property: 1. The key in each node must be greater than all keys stored in the left subtree of the node. 2. The key in each node must be less than all keys stored in the right ...
class TreeNode: def __init__(self, key): self.key = key self.left = None self.right = None self.parent = None self.depth = 0 class BST: def __init__(self): self.root = None def insert(self, key): if not self.root: self.root = TreeNode(key...
from solution import bst_info def test_single_node(): result = bst_info(1, [10]) expected = [(10, 'None', 0, [])] assert result == expected def test_balanced_bst(): result = bst_info(7, [10, 5, 15, 2, 7, 13, 17]) expected = [ (2, 5, 2, []), (5, 10, 1, [2, 7]), (7, 5, 2, [])...
[]
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "class TreeNode:\n def __init__(self, key):\n self.key = key\n self.left = None\n self.right = None\n self.parent = None\n ...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00027150", "row_id": 27150, "seed_ids": "[3541]" }
0.573453
Code_Contests_27150
I
[ "generate_bst_from_list", "bst_info" ]
2
[ [ "bst_info", "generate_bst_from_list" ] ]
1
[]
false
[ "TreeNode", "BST" ]
true
pytest
true
[]
true
9d42ad8c2b563b57ec6df1132f70db8806855c3d
5b770913274bd6cfdca9ea273471aff5d3f6d5c7
v1.0
instruct
Code_Contests
Code_Contests_27153_I
In a faraway land, there exists a mysterious forest known for its peculiar fruit trees. There are M different types of trees planted in a line in this forest, and each type of tree bears a unique fruit. Each tree is numbered from 0 to M-1 and is known to produce a certain number of fruits each day. The number of fruits...
def preprocess_fruit_counts(fruit_counts): # Precompute cumulative sums for fruit_counts cumulative_sums = [0] * (len(fruit_counts) + 1) for i in range(len(fruit_counts)): cumulative_sums[i + 1] = cumulative_sums[i] + fruit_counts[i] return cumulative_sums def query_fruit_sum(cumulative_sums, S...
from solution import preprocess_fruit_counts, query_fruit_sum, process_queries def test_preprocess_fruit_counts(): fruit_counts = [2, 3, 7, 1, 5, 6, 2, 4, 8, 3] cumulative_sums = preprocess_fruit_counts(fruit_counts) assert cumulative_sums == [0, 2, 5, 12, 13, 18, 24, 26, 30, 38, 41] def test_query_fruit_...
[ { "docstring": null, "function_declaration": "def preprocess_fruit_counts(fruit_counts):", "function_name": "preprocess_fruit_counts", "parameter_list": "(fruit_counts)" }, { "docstring": null, "function_declaration": "def query_fruit_sum(cumulative_sums, S, E):", "function_name": "q...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def precompute_prefix_sums(fruits):\n prefix_sums = [0] * (len(fruits) + 1)\n for i in range(len(fruits)):\n prefix_sums[i + 1] = prefix_sums[...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00027153", "row_id": 27153, "seed_ids": "[5594]" }
0.666231
Code_Contests_27153
I
[ "preprocess_fruit_counts", "query_fruit_sum", "process_queries" ]
3
[ [ "process_queries", "preprocess_fruit_counts" ], [ "process_queries", "query_fruit_sum" ] ]
2
[ "process_queries" ]
false
[]
false
pytest
true
[]
true
0e5ddb14d577c0b599b2d5e13c1baaf46f55d332
2cbdb3921bd2497a7784ad20fd27afca167c34b9
v1.0
instruct
Code_Contests
Code_Contests_27158_I
You are given an integer array `arr` of size `N` which may contain both positive and negative integers. You need to find the maximum sum of a non-empty subarray such that the sum is less than or equal to a given integer `T`. A subarray is defined as a contiguous part of an array. The result should be computed in a si...
def max_subarray_sum(arr, T): max_sum = float('-inf') n = len(arr) current_sum = 0 prefix_sums = [] for num in arr: current_sum += num if current_sum <= T: max_sum = max(max_sum, current_sum) for prefix in prefix_sums: if current_sum...
from solution import max_subarray_sum def test_example_1(): arr = [1, 2, 3, -2, 5] T = 10 assert max_subarray_sum(arr, T) == 9 def test_example_2(): arr = [-1, -2, -3, 4, -2] T = 4 assert max_subarray_sum(arr, T) == 4 def test_single_negative_element(): arr = [-5] T = -4 assert ma...
[ { "docstring": null, "function_declaration": "def max_subarray_sum(arr, T):", "function_name": "max_subarray_sum", "parameter_list": "(arr, T)" }, { "docstring": null, "function_declaration": "def run_solution():", "function_name": "run_solution", "parameter_list": "()" } ]
[ 0, 0, 0, 1, 0 ]
1
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def max_sum_subarray_leq_T(arr, N, T):\n \"\"\"\n Find the maximum sum of a non-empty subarray such that the sum is less than or equal to T.\n \"\...
trial_gpt4o_3
{ "original_instruction": "", "prompt_id": "00027158", "row_id": 27158, "seed_ids": "[3622]" }
0.80018
Code_Contests_27158
I
[ "max_subarray_sum", "run_solution" ]
2
[ [ "run_solution", "max_subarray_sum" ] ]
1
[]
false
[]
false
pytest
true
[]
true
64a585cb9a06328c133cdcd42112d0580e832d66
556be1584af38e103a3a16f18f6418a68dc1367e
v1.0
instruct
Code_Contests
Code_Contests_27162_I
Given two strings, `str1` and `str2`, you need to find the length of the shortest common supersequence (SCS) of these two strings. The shortest common supersequence of two strings is the shortest string that has both `str1` and `str2` as subsequences. **Input:** - Two strings `str1` and `str2` with 1 ≤ |str1|, |str2| ...
def lcs(str1, str2): """ Helper function to find the length of the Longest Common Subsequence (LCS) of str1 and str2. """ n, m = len(str1), len(str2) dp = [[0] * (m + 1) for _ in range(n + 1)] for i in range(1, n + 1): for j in range(1, m + 1): if str1[i - 1] == str2[j -...
from solution import shortest_common_supersequence_length def test_scs_length_example1(): assert shortest_common_supersequence_length("abc", "ac") == 3 def test_scs_length_example2(): assert shortest_common_supersequence_length("geek", "eke") == 5 def test_scs_length_example3(): assert shortest_common_su...
[ { "docstring": "Helper function to find the length of the Longest Common Subsequence (LCS) of str1 and str2.", "function_declaration": "def lcs(str1, str2):", "function_name": "lcs", "parameter_list": "(str1, str2)" }, { "docstring": "Returns the length of the shortest common supersequence o...
[ 0, 1, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def shortest_common_supersequence_length(str1, str2):\n def lcs_length(str1, str2):\n m, n = len(str1), len(str2)\n dp = [[0] * (n + 1) fo...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00027162", "row_id": 27162, "seed_ids": "[7309]" }
0.682957
Code_Contests_27162
I
[ "lcs", "shortest_common_supersequence_length" ]
2
[ [ "shortest_common_supersequence_length", "lcs" ] ]
1
[]
false
[]
false
pytest
true
[]
true
f06981e56138824ffa3c47b207ebe8dadc398f57
e49512cc6e8503400581aaf36b262f6eb88e1146
v1.0
instruct
Code_Contests
Code_Contests_27174_I
You are given an array of integers representing the resistance values of various resistors. Your task is to determine if it is possible to combine these resistors (using series or parallel combinations) to achieve a target resistance value. It is allowed to use each resistor more than once. A resistor in series is com...
from itertools import combinations def combination_resistances(values): """ Returns a set of all possible resistances that can be achieved with combinations of given resistor values using series combinations. """ all_combinations = set() for i in range(1, len(values) + 1): for comb in ...
import pytest from solution import process_test_cases, parse_input def test_example_case(): input_string = """3 4 3 1 2 3 6 2 2 3 5 4 1 2 3 4""" expected_output = ["POSSIBLE", "IMPOSSIBLE", "POSSIBLE"] T, test_cases = parse_input(input_string) assert process_test_cases(T, test_cases) == expected_output...
[ { "docstring": "Returns a set of all possible resistances that can be achieved \nwith combinations of given resistor values using series combinations.", "function_declaration": "def combination_resistances(values):", "function_name": "combination_resistances", "parameter_list": "(values)" }, { ...
[ 0, 0, 0, 1, 0 ]
1
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def can_achieve_target_resistance(target, resistors):\n \"\"\"\n Determines if it is possible to achieve the target resistance value using\n any c...
trial_gpt4o_3
{ "original_instruction": "", "prompt_id": "00027174", "row_id": 27174, "seed_ids": "[6980]" }
0.60041
Code_Contests_27174
I
[ "combination_resistances", "is_possible_to_achieve_resistance", "process_test_cases", "parse_input" ]
4
[ [ "is_possible_to_achieve_resistance", "combination_resistances" ], [ "process_test_cases", "is_possible_to_achieve_resistance" ] ]
2
[ "process_test_cases", "parse_input" ]
false
[]
false
pytest
true
[]
true
bf8c2aabca936ab70916f59e30d6a2cedc98673d
3deb02e4994a291b04154d65862424667bb574f6
v1.0
instruct
Code_Contests
Code_Contests_27195_I
In a land far away, there exists a series of islands connected by bridges. Some islands belong to the region of Atlantis and others to the region of Lemuria. Some islands are disputed and claimed by both Atlantis and Lemuria. Each bridge has a unique cost associated with its construction, and all bridges are bidirectio...
def find(parent, i): if parent[i] == i: return i else: parent[i] = find(parent, parent[i]) return parent[i] def union(parent, rank, x, y): rootX = find(parent, x) rootY = find(parent, y) if rootX != rootY: if rank[rootX] > rank[rootY]: parent[rootY] ...
from solution import minimum_cost_to_connect_islands def test_minimum_cost_to_connect_islands_example1(): n = 6 m = 7 islands = [ (1, 'A'), (2, 'L'), (3, 'A'), (4, 'D'), (5, 'L'), (6, 'D') ] bridges = [ (1, 4, 5), (4, 6, 3), (2...
[ { "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, 1 ]
1
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def minimal_cost_to_connect_islands(n, m, islands, bridges):\n from heapq import heappop, heappush\n from collections import defaultdict\n\n # Cre...
trial_gpt4o_4
{ "original_instruction": "", "prompt_id": "00027195", "row_id": 27195, "seed_ids": "[1631]" }
0.818798
Code_Contests_27195
I
[ "find", "union", "minimum_cost_to_connect_islands" ]
3
[ [ "minimum_cost_to_connect_islands", "find" ], [ "minimum_cost_to_connect_islands", "union" ], [ "union", "find" ] ]
3
[]
false
[]
false
pytest
true
[]
true
528659beadbb1c439afed7a7c969a62222bf7a68
0ff1d6073a2cd957b48ee441d1e244309e575961
v1.0
instruct
Code_Contests
Code_Contests_27198_I
You are given an array of integers representing the number of hours each member has available for a project within a month. Your task is to assign a task to every member in such a way that each task requires exactly 8 hours of work, and you can split the task into smaller intervals as long as each member's hours add up...
def can_form_eight_hours(hours): n = len(hours) dp = [False] * 25 # We care up to sum 24 (maximum hour given by constraint) dp[0] = True for h in hours: for j in range(24, h-1, -1): dp[j] = dp[j] or dp[j-h] return dp[8] def solve(test_cases): results = [] case...
def test_solution(): T = 2 cases = [ [4, 1, 2, 3, 2], [3, 5, 4, 7] ] expected_output = [ "Case #1: Possible", "Case #2: Not possible" ] assert solution(T, cases) == expected_output def test_all_individual_hours_not_possible(): T = 1 cases = [ ...
[ { "docstring": null, "function_declaration": "def can_form_eight_hours(hours):", "function_name": "can_form_eight_hours", "parameter_list": "(hours)" }, { "docstring": null, "function_declaration": "def solve(test_cases):", "function_name": "solve", "parameter_list": "(test_cases...
[ 0, 0, 1 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def can_complete_project(hours_per_member):\n \"\"\"\n Function to determine if the project can be completed given the hours per member.\n \"\"\"\...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00027198", "row_id": 27198, "seed_ids": "[2989]" }
0.71489
Code_Contests_27198
I
[ "can_form_eight_hours", "solve", "solution" ]
3
[ [ "solution", "solve" ], [ "solve", "can_form_eight_hours" ] ]
2
[]
false
[]
false
pytest
false
[]
true
a679e4630da0bd90405fef3e6e4c2487cb911bca
3e55bedd08165ac2d27ee2039b9b42ef3c35acaa
v1.0
instruct
Code_Contests
Code_Contests_27208_I
In a faraway land, there exists a magical forest where trees bear precious fruits. Each tree is rooted at position (0, 0) and grows fruits at various coordinates in the 2D plane. The forest keeper, an ancient wizard, has tasked you with identifying the order in which the fruits should be harvested to maximize the magic...
import math def euclidean_distance(p1, p2): return math.sqrt((p1[0] - p2[0]) ** 2 + (p1[1] - p2[1]) ** 2) def harvest_order(t, test_cases): results = [] for i in range(t): n, fruits = test_cases[i] if n == 0: results.append([]) continue current_position = (...
from solution import harvest_order def test_harvest_order_case_1(): t = 2 test_cases = [ (3, [(1, 2), (3, 1), (2, 2)]), (4, [(-1, -1), (2, 2), (-2, 2), (1, -1)]) ] expected_output = [ [(1, 2), (2, 2), (3, 1)], [(-1, -1), (1, -1), (2, 2), (-2, 2)] ] asse...
[ { "docstring": null, "function_declaration": "def euclidean_distance(p1, p2):", "function_name": "euclidean_distance", "parameter_list": "(p1, p2)" }, { "docstring": null, "function_declaration": "def harvest_order(t, test_cases):", "function_name": "harvest_order", "parameter_li...
[ 0, 1, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "import math\n\ndef harvest_order(t, test_cases):\n results = []\n \n for case in test_cases:\n n, fruits = case\n if n == 0:\n ...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00027208", "row_id": 27208, "seed_ids": "[1328]" }
0.616541
Code_Contests_27208
I
[ "euclidean_distance", "harvest_order" ]
2
[ [ "harvest_order", "euclidean_distance" ] ]
1
[]
false
[]
false
pytest
true
[]
true
b72dea7828c6b90f8bbc26be7cb7178e2bcae2b8
b9b22a2eee06981e4902eba925a86f7475ed98ed
v1.0
instruct
Code_Contests
Code_Contests_27307_I
Joe's favorite hobby is solving logic puzzles, especially grid-based puzzles. He recently stumbled upon a new puzzle game where he needs to fill a grid with numbers based on a set of given conditions. The grid is an N x N matrix. Each cell in the grid can be filled with a number from 1 to N. The rules for filling the ...
def is_safe(grid, N, row, col, num): """ Check if it's safe to place num in grid[row][col] """ for x in range(N): if grid[row][x] == num or grid[x][col] == num: return False # Check for adjacent cells if row > 0 and grid[row - 1][col] == num: return False if row ...
from solution import fill_puzzle def test_grid_with_solution(): grid = [ [1, 0, 3], [0, 0, 0], [2, 3, 0] ] N = 3 fill_puzzle(grid, N) # Expected Output: A filled grid without violation or NO SOLUTION def test_grid_no_solution(): grid = [ [1, 2, 0], [2, 3, 1...
[ { "docstring": "Check if it's safe to place num in grid[row][col]", "function_declaration": "def is_safe(grid, N, row, col, num):", "function_name": "is_safe", "parameter_list": "(grid, N, row, col, num)" }, { "docstring": null, "function_declaration": "def solve_grid(grid, N):", "fu...
[ 0, 0, 1 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_valid(grid, row, col, num, N):\n # Check if 'num' is not in the current row or column\n for x in range(N):\n if grid[row][x] == num or ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00027307", "row_id": 27307, "seed_ids": "[3212]" }
0.749516
Code_Contests_27307
I
[ "is_safe", "solve_grid", "fill_puzzle" ]
3
[ [ "fill_puzzle", "solve_grid" ], [ "solve_grid", "is_safe" ] ]
2
[]
false
[]
false
pytest
true
[]
true
1c6bc58661b84de6d078dfa6c96646aec256bec7
237ee238b4779a75a10e371a7395d9636159ac02
v1.0
instruct
Code_Contests
Code_Contests_27331_I
You are working for a logistics company, and you need to optimize package deliveries. Given a list of delivery locations, each represented by a coordinate in a 2D plane, you need to determine the minimum length of the delivery route that visits each location exactly once and returns to the starting point. The problem ...
import itertools import math def calculate_distance(p1, p2): """ Calculate the Euclidean distance between two points p1 and p2. """ return math.sqrt((p1[0] - p2[0]) ** 2 + (p1[1] - p2[1]) ** 2) def total_distance(route): """ Calculate the total distance of the given route which starts and ends...
def test_calculate_distance(): assert calculate_distance((0, 0), (3, 4)) == 5.0 assert calculate_distance((1, 1), (4, 5)) == 5.0 assert calculate_distance((0, 0), (0, 0)) == 0.0 def test_total_distance(): assert total_distance([(0, 0), (3, 4), (6, 8)]) == 20.0 assert total_distance([(0, 0), (0, 2),...
[ { "docstring": "Calculate the Euclidean distance between two points p1 and p2.", "function_declaration": "def calculate_distance(p1, p2):", "function_name": "calculate_distance", "parameter_list": "(p1, p2)" }, { "docstring": "Calculate the total distance of the given route which starts and ...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "from itertools import permutations\nimport math\n\ndef calculate_distance(point1, point2):\n \"\"\"\n Calculate the Euclidean distance between two po...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00027331", "row_id": 27331, "seed_ids": "[3010]" }
0.712889
Code_Contests_27331
I
[ "calculate_distance", "total_distance", "find_min_route" ]
3
[ [ "find_min_route", "total_distance" ], [ "total_distance", "calculate_distance" ] ]
2
[]
false
[]
false
pytest
false
[]
true
825349a439f157969a3e4a7833618e4bec986cae
6a76af6ac4285fd57b775e88604f7195253057ad
v1.0
instruct
Code_Contests
Code_Contests_27379_I
Create a new text-based game inspired by the "Tic-Tac-Toe" game, but with different rules and a unique twist. For this game, the board is a 5x5 grid, and it will be called "Five-O". Here are the rules: - There are two players, Player X and Player O. - The players take turns to place their mark (X or O) in an empty cel...
def display_board(board): for row in board: print(" ".join(row)) print() def is_winner(board, player): for r in range(5): for c in range(5): if c <= 0 and all(board[r][c+i] == player for i in range(5)): return True if r <= 0 and all(board[r+i][c] == p...
from solution import display_board, is_winner, is_draw, make_move def test_display_board(): board = [['-' for _ in range(5)] for _ in range(5)] # This is a visual test, make sure the output looks like a 5x5 grid with '-' display_board(board) def test_is_winner_horizontal(): board = [ ['X', 'X'...
[ { "docstring": null, "function_declaration": "def display_board(board):", "function_name": "display_board", "parameter_list": "(board)" }, { "docstring": null, "function_declaration": "def is_winner(board, player):", "function_name": "is_winner", "parameter_list": "(board, player...
[ 0, 1, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def init_board():\n \"\"\"\n Initialize the 5x5 board with empty cells.\n \"\"\"\n return [['-' for _ in range(5)] for _ in range(5)]\n\ndef di...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00027379", "row_id": 27379, "seed_ids": "[12169]" }
0.535406
Code_Contests_27379
I
[ "display_board", "is_winner", "is_draw", "make_move", "five_o_game" ]
5
[ [ "five_o_game", "display_board" ], [ "five_o_game", "is_draw" ], [ "five_o_game", "is_winner" ], [ "five_o_game", "make_move" ] ]
4
[]
false
[]
false
pytest
true
[]
true
a66e24dac634b08d858d63f89292f0859e682113
b35cf3ed92a93f3b0197999e9d20b33d8f20200b
v1.0
instruct
Code_Contests
Code_Contests_27432_I
### Balanced Brackets Problem Develop a function that determines if the input string has all its brackets properly balanced and nested. The input string will only consist of brackets: `(`, `)`, `{`, `}`, `[`, and `]`. #### Input - A list of strings where each string contains only the characters `(`, `)`, `{`, `}`, `[...
def is_balanced(brackets): """ Checks if the provided string of brackets is balanced. """ stack = [] bracket_map = {'(': ')', '{': '}', '[': ']'} for char in brackets: if char in bracket_map: stack.append(char) elif char in bracket_map.values(): if no...
from solution import check_balanced_brackets, is_balanced def test_basic_cases(): assert check_balanced_brackets(["()"]) == [True] assert check_balanced_brackets(["([])"]) == [True] assert check_balanced_brackets(["{[()]}"]) == [True] assert check_balanced_brackets(["(]"]) == [False] assert check_b...
[ { "docstring": "Checks if the provided string of brackets is balanced.", "function_declaration": "def is_balanced(brackets):", "function_name": "is_balanced", "parameter_list": "(brackets)" }, { "docstring": "Returns a list indicating if each string in the input list is balanced.", "func...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_balanced_brackets(strings):\n def is_balanced(s):\n stack = []\n matching_bracket = {')': '(', '}': '{', ']': '['}\n for cha...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00027432", "row_id": 27432, "seed_ids": "[8216]" }
0.750442
Code_Contests_27432
I
[ "is_balanced", "check_balanced_brackets" ]
2
[ [ "check_balanced_brackets", "is_balanced" ] ]
1
[]
false
[]
false
pytest
true
[]
true
e1ed855cc46e4f6e9885ebc15a7f32655fcf5a3c
0eaa3f98110573fc14c7e04b2f182526df8758d4
v1.0
instruct
Code_Contests
Code_Contests_27433_I
Emma is fascinated by numbers that are palindromic primes. A palindromic prime is a number that is both a palindrome (it reads the same forwards and backwards) and a prime (it is only divisible by 1 and itself). Given a number N, Emma wants to find the next palindromic prime that is greater than N. Input The first li...
import math def is_prime(n): """ Returns True if n is a prime number, else False. """ if n <= 1: return False if n <= 3: return True if n % 2 == 0 or n % 3 == 0: return False i = 5 while i * i <= n: if n % i == 0 or n % (i + 2) == 0: return Fa...
from solution import next_palindromic_prime, find_next_palindromic_primes def test_is_palindrome(): assert next_palindromic_prime(31) == 101 assert next_palindromic_prime(101) == 131 assert next_palindromic_prime(130) == 131 assert next_palindromic_prime(10) == 11 assert next_palindromic_prime(11) ...
[ { "docstring": "Returns True if n is a prime number, else False.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Returns True if n is a palindrome, else False.", "function_declaration": "def is_palindrome(n):", "fu...
[ 0, 0, 1 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "import math\n\ndef is_prime(n):\n if n <= 1:\n return False\n for i in range(2, int(math.sqrt(n)) + 1):\n if n % i == 0:\n r...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00027433", "row_id": 27433, "seed_ids": "[9167]" }
0.696791
Code_Contests_27433
I
[ "is_prime", "is_palindrome", "next_palindromic_prime", "find_next_palindromic_primes" ]
4
[ [ "find_next_palindromic_primes", "next_palindromic_prime" ], [ "next_palindromic_prime", "is_palindrome" ], [ "next_palindromic_prime", "is_prime" ] ]
3
[]
false
[]
false
pytest
true
[]
true
9ced54dd0338d53400407a043891c631027be056
490cde10ff3a620b0393edfaca3d574e423e36b5
v1.0
instruct
Code_Contests
Code_Contests_27451_I
You have an array of integers, and you need to perform a series of queries on this array. Each query will give you a range [l, r] and require you to calculate the sum of elements within this range. Your task is to preprocess the array in a way that allows you to answer each query efficiently. Input The first line con...
def preprocess_array(arr): """ Preprocess the array to create a prefix sum array for efficient range queries. """ n = len(arr) prefix_sum = [0] * (n + 1) for i in range(n): prefix_sum[i + 1] = prefix_sum[i] + arr[i] return prefix_sum def range_sum_query(prefix_sum, l, r): """ ...
from solution import preprocess_array, range_sum_query, process_queries def test_preprocess_array(): arr = [1, 2, 3, 4, 5] expected_prefix_sum = [0, 1, 3, 6, 10, 15] assert preprocess_array(arr) == expected_prefix_sum def test_range_sum_query(): prefix_sum = [0, 1, 3, 6, 10, 15] assert range_sum_q...
[ { "docstring": "Preprocess the array to create a prefix sum array for efficient range queries.", "function_declaration": "def preprocess_array(arr):", "function_name": "preprocess_array", "parameter_list": "(arr)" }, { "docstring": "Returns the sum of the elements in the range [l, r] using t...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def preprocess_array(arr):\n \"\"\"\n Preprocess the array to create a prefix sum array for efficient range sum queries.\n \"\"\"\n prefix_sums...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00027451", "row_id": 27451, "seed_ids": "[9740]" }
0.652978
Code_Contests_27451
I
[ "preprocess_array", "range_sum_query", "process_queries" ]
3
[ [ "process_queries", "preprocess_array" ], [ "process_queries", "range_sum_query" ] ]
2
[ "process_queries" ]
false
[]
false
pytest
true
[]
true
56aaa4cd1c39014d7daf0620cab8caedcec66da4
4faac10fb91d4665c851c9b01fbe1405392eb77b
v1.0
instruct
Code_Contests
Code_Contests_27491_I
In a galaxy far away, there is a land with N unique villages. These villages are connected by M bidirectional roads, each with a travel cost. The villages are numbered from 1 to N. The king of this land wants to construct a road network to ensure that all villages are connected with the minimum possible total cost. Th...
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 rank[root_x] < rank[root_y]: parent[root_x] = root_y elif rank[roo...
def test_minimum_cost_to_connect_villages(): assert minimum_cost_to_connect_villages(4, 5, [ (1, 2, 1), (1, 3, 4), (2, 3, 2), (2, 4, 3), (3, 4, 5) ]) == 6 def test_single_road(): assert minimum_cost_to_connect_villages(2, 1, [ (1, 2, 10) ]) == 10 def tes...
[ { "docstring": null, "function_declaration": "def find(parent, i):", "function_name": "find", "parameter_list": "(parent, i)" }, { "docstring": null, "function_declaration": "def union(parent, rank, x, y):", "function_name": "union", "parameter_list": "(parent, rank, x, y)" }, ...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_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 uni...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00027491", "row_id": 27491, "seed_ids": "[6116]" }
0.75718
Code_Contests_27491
I
[ "find", "union", "kruskal_mst", "minimum_cost_to_connect_villages" ]
4
[ [ "kruskal_mst", "find" ], [ "kruskal_mst", "union" ], [ "minimum_cost_to_connect_villages", "kruskal_mst" ], [ "union", "find" ] ]
4
[]
false
[]
false
pytest
false
[]
true
e251e74e2edc7d308fc3bbc058620de0948b0c5f
d6af27429532ccf50e5ebc5f8f80ef4a3b6b5179
v1.0
instruct
Code_Contests
Code_Contests_27511_I
Create a program that takes a list of integers and returns a new list containing only the prime numbers from the original list. The program should handle cases where the input can be of varying lengths, with each integer falling between 1 and 100,000. Input The input is given in the following format: n v1 v2 :: vn...
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...
def test_is_prime(): assert is_prime(2) == True assert is_prime(3) == True assert is_prime(4) == False assert is_prime(5) == True assert is_prime(1) == False assert is_prime(0) == False assert is_prime(97) == True assert is_prime(100000) == False def test_find_primes(): assert find_...
[ { "docstring": "Helper function to check if a number is prime.", "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": "Returns a list of prime numbers from the given list of integers.", "function_declaration": "def find_pr...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(num):\n \"\"\"\n Helper function to check if a number is prime.\n \"\"\"\n if num <= 1:\n return False\n if num <= 3:\n ...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00027511", "row_id": 27511, "seed_ids": "[12064]" }
0.656489
Code_Contests_27511
I
[ "is_prime", "find_primes" ]
2
[ [ "find_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
false
[]
true
702a4f53444106fefe0d254e76cf2c3a89dbc91f
4cbe5bc441416561feb9346462fe32d64b0c47e1
v1.0
instruct
Code_Contests
Code_Contests_27530_I
Problem A group of islands are connected by underwater roads. Each road directly connects exactly two different islands and has a certain travel time. The islands and roads form a connected undirected graph (i.e., there is a path between any pair of islands). You need to find out the minimum time required to travel be...
import heapq from collections import defaultdict def dijkstra(graph, start, target): # Priority queue to store minimum distances pq = [(0, start)] # Dictionary to store the shortest path to each node shortest_paths = {start: 0} while pq: current_time, current_island = heapq.heappop(pq) ...
def test_example1(): N = 6 E = 8 roads = [(1, 2, 1), (2, 3, 2), (3, 4, 1), (4, 5, 3), (5, 6, 1), (1, 5, 10), (2, 4, 1), (3, 6, 2)] A = 1 B = 6 assert min_travel_time(N, E, roads, A, B) == 5 def test_example2(): N = 5 E = 5 roads = [(1, 2, 2), (2, 3, 3), (3, 4, 4), (4, ...
[ { "docstring": null, "function_declaration": "def dijkstra(graph, start, target):", "function_name": "dijkstra", "parameter_list": "(graph, start, target)" }, { "docstring": null, "function_declaration": "def min_travel_time(N, E, roads, A, B):", "function_name": "min_travel_time", ...
[ 0, 1, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "import heapq\nimport sys\n\ndef find_min_travel_time(N, E, roads, start, end):\n # Create adjacency list\n adj_list = {i+1: [] for i in range(N)}\n ...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00027530", "row_id": 27530, "seed_ids": "[7079]" }
0.731448
Code_Contests_27530
I
[ "dijkstra", "min_travel_time" ]
2
[ [ "min_travel_time", "dijkstra" ] ]
1
[]
false
[]
false
pytest
false
[]
true
270c77a5b560136f1c7d3ac39828205f57596a45
2e9998641bb0513a0bd46d758b5e6424f804a8ba
v1.0
instruct
Code_Contests
Code_Contests_27541_I
A company has a unique policy for password creation. The policy is defined as follows: 1. Each password must be at least 8 characters long. 2. Each password must contain at least one uppercase letter, one lowercase letter, and one digit. 3. Each password must contain a special character from the set: {'@', '#', '%', '&...
def validate_password(password): if len(password) < 8: return "NO" has_upper = False has_lower = False has_digit = False has_special = False special_characters = {'@', '#', '%', '&', '$'} for char in password: if char.isupper(): has_upper = True ...
from solution import check_passwords def test_valid_password(): assert check_passwords(["Password123@"]) == ["YES"] def test_password_too_short(): assert check_passwords(["short1&"]) == ["NO"] def test_password_missing_digit(): assert check_passwords(["StrongPass#"]) == ["NO"] def test_password_missing_...
[ { "docstring": null, "function_declaration": "def validate_password(password):", "function_name": "validate_password", "parameter_list": "(password)" }, { "docstring": null, "function_declaration": "def check_passwords(passwords):", "function_name": "check_passwords", "parameter_...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "import re\n\ndef check_password_policy(passwords):\n SPECIAL_CHARACTERS = {'@', '#', '%', '&', '$'}\n \n def is_valid(password):\n if len(p...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00027541", "row_id": 27541, "seed_ids": "[3857]" }
0.639231
Code_Contests_27541
I
[ "validate_password", "check_passwords" ]
2
[ [ "check_passwords", "validate_password" ] ]
1
[]
false
[]
false
pytest
true
[]
true
ba8715c185023e5d06c055056e61fba85e3ee62d
d795e52d16c5c574fdf2f4bf4918f73b5f087268
v1.0
instruct
Code_Contests
Code_Contests_27770_I
Given an m by n binary matrix filled with 0's and 1's, find the largest rectangle containing only 1's and return its area. You need to solve the problem using dynamic programming and optimize the solution efficiently for large inputs. Input The first line of the input contains two integers m and n (1 ≤ m, n ≤ 200) — ...
def maximal_rectangle(matrix): if not matrix or not matrix[0]: return 0 m = len(matrix) n = len(matrix[0]) max_area = 0 dp = [0] * n for i in range(m): for j in range(n): # Update dp to record the height of 1's in column j up to row i dp[j] ...
from solution import maximal_rectangle def test_example_case(): matrix = [ [1, 0, 1, 0], [1, 0, 1, 1], [1, 0, 1, 1], [1, 1, 1, 1] ] assert maximal_rectangle(matrix) == 6 def test_single_row(): matrix = [[1, 1, 1, 1]] assert maximal_rectangle(matrix) == 4 def test_s...
[ { "docstring": null, "function_declaration": "def maximal_rectangle(matrix):", "function_name": "maximal_rectangle", "parameter_list": "(matrix)" }, { "docstring": null, "function_declaration": "def largest_rectangle_area(heights):", "function_name": "largest_rectangle_area", "pa...
[ 1, 0, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def maximalRectangle(matrix):\n if not matrix:\n return 0\n\n m, n = len(matrix), len(matrix[0])\n heights = [0] * (n + 1)\n max_area = ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00027770", "row_id": 27770, "seed_ids": "[3654]" }
0.745122
Code_Contests_27770
I
[ "maximal_rectangle", "largest_rectangle_area" ]
2
[ [ "maximal_rectangle", "largest_rectangle_area" ] ]
1
[]
false
[]
false
pytest
true
[]
true
cd808991bfe8514b6d99754016560ec1e6f2f402
af2141dd188f9008b187afc316acad11b5123447
v1.0
instruct
Code_Contests
Code_Contests_27845_I
John loves playing with binary trees, and he recently read about binary search trees (BST). He learned that a binary search tree is a binary tree in which each node has, at most, two children, and for each node, all the elements in its left subtree are less than the node and all the elements in its right subtree are gr...
class TreeNode: def __init__(self, val=0, left=None, right=None): self.val = val self.left = left self.right = right def deleteNode(root, key): if not root: return root if key < root.val: root.left = deleteNode(root.left, key) elif key > root.val: root.r...
from solution import TreeNode, deleteNode def tree_to_list(root): """Helper function to convert tree to list level-wise for easy comparison in tests.""" if not root: return [] result, queue = [], [root] while queue: node = queue.pop(0) if node: result.append(node.val...
[]
[ 0, 1, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_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...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00027845", "row_id": 27845, "seed_ids": "[6801]" }
0.538916
Code_Contests_27845
I
[ "deleteNode", "findMin" ]
2
[ [ "deleteNode", "findMin" ] ]
1
[]
false
[ "TreeNode" ]
true
pytest
true
[]
true
a0c59d2f83b3d71975185f18cdf9f4fef0dcaee0
e6c8fc5920a666f082d3739ba15ea9c8861ae97d
v1.0
instruct
Code_Contests
Code_Contests_27972_I
John is planning a new infrastructure for his local network. The network consists of n computers and m direct connections between them. Each direct connection allows the two connected computers to communicate directly. The network must be robust, ensuring that every computer can communicate with every other computer, e...
def find(parents, x): if parents[x] == x: return x parents[x] = find(parents, parents[x]) return parents[x] def union(parents, x, y): rootX = find(parents, x) rootY = find(parents, y) if rootX != rootY: parents[rootY] = rootX def min_additional_connections(n, m, connections): ...
def test_min_additional_connections(): assert min_additional_connections(4, 2, [(1, 2), (3, 4)]) == 1 assert min_additional_connections(5, 3, [(1, 2), (2, 3), (4, 5)]) == 1 assert min_additional_connections(6, 1, [(1, 2)]) == 4 assert min_additional_connections(3, 0, []) == 2 assert min_additional_c...
[ { "docstring": null, "function_declaration": "def find(parents, x):", "function_name": "find", "parameter_list": "(parents, x)" }, { "docstring": null, "function_declaration": "def union(parents, x, y):", "function_name": "union", "parameter_list": "(parents, x, y)" }, { ...
[ 1, 0, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def find_parent(parent, i):\n if parent[i] == i:\n return i\n else:\n parent[i] = find_parent(parent, parent[i])\n return parent...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00027972", "row_id": 27972, "seed_ids": "[2642]" }
0.664737
Code_Contests_27972
I
[ "find", "union", "min_additional_connections" ]
3
[ [ "min_additional_connections", "find" ], [ "min_additional_connections", "union" ], [ "union", "find" ] ]
3
[]
false
[]
false
pytest
false
[]
true
738d0ee4919bbd4f796a5d347bb9d73131deaec2
f098579799bca6d977f113bf6fee8e504cffae6c
v1.0
instruct
Code_Contests
Code_Contests_27982_I
Robo World Inc. has developed a new robot, RoboX, which can move within a 2D grid. The grid has cells with different energy levels. RoboX can move from one cell to another if and only if the destination cell has equal or higher energy level than the current cell. The objective of RoboX is to reach the bottom-right corn...
def can_robox_reach_destination(grid): N = len(grid) def dfs(x, y): if x == N-1 and y == N-1: return True visited.add((x, y)) directions = [(0, 1), (1, 0)] # right and down movements for dx, dy in directions: nx, ny = x + dx, y + dy if 0 <= nx...
def test_robox_in_grid(): input_string = """2 3 1 2 3 6 5 4 7 8 9 3 1 2 3 3 2 1 1 1 1""" expected_output = ["YES", "NO"] test_cases = parse_input(input_string) output = robox_in_grid(test_cases) assert output == expected_output def test_single_cell_grid(): input_string = """1 1 1""" expecte...
[ { "docstring": null, "function_declaration": "def can_robox_reach_destination(grid):", "function_name": "can_robox_reach_destination", "parameter_list": "(grid)" }, { "docstring": null, "function_declaration": "def robox_in_grid(test_cases):", "function_name": "robox_in_grid", "p...
[ 1, 1 ]
2
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def can_reach_bottom_right(grid):\n \"\"\"\n Given a grid of energy levels, return True if RoboX can reach the bottom-right corner from the top-left ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00027982", "row_id": 27982, "seed_ids": "[7462]" }
0.717238
Code_Contests_27982
I
[ "can_robox_reach_destination", "robox_in_grid", "parse_input" ]
3
[ [ "robox_in_grid", "can_robox_reach_destination" ] ]
1
[ "parse_input" ]
false
[]
false
pytest
false
[]
true
c18c110ffd241bf1a9c5ea94e3f299387ae565b0
5386795523f5e7ae1e1786d4e0223e516e5133e3
v1.0
instruct
Code_Contests
Code_Contests_28002_I
An advanced robotics company is developing a pathfinding algorithm for their warehouse robots. Given a grid of cells where each cell is either blocked or open, you need to determine the shortest path from the top-left corner to the bottom-right corner. The robot can only move up, down, left, or right, and cannot pass t...
from collections import deque def shortest_path(grid): m, n = len(grid), len(grid[0]) if grid[0][0] == '#' or grid[m-1][n-1] == '#': return -1 directions = [(0, 1), (1, 0), (0, -1), (-1, 0)] queue = deque([(0, 0, 0)]) # (x, y, distance) visited = set((0, 0)) while queue: x, y...
from solution import find_shortest_path def test_case_1(): assert find_shortest_path(3, 3, '...\n.#.\n...') == 4 def test_case_2(): assert find_shortest_path(3, 3, '.#.\n##.\n...') == -1 def test_case_3(): assert find_shortest_path(4, 4, '....\n#...\n..#.\n....') == 6 def test_case_4(): assert find_...
[ { "docstring": null, "function_declaration": "def shortest_path(grid):", "function_name": "shortest_path", "parameter_list": "(grid)" }, { "docstring": null, "function_declaration": "def find_shortest_path(m, n, grid_input):", "function_name": "find_shortest_path", "parameter_lis...
[ 0, 1, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "from collections import deque\n\ndef shortest_path(grid):\n \"\"\"\n Returns the shortest path from the top-left corner to the bottom-right corner of...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00028002", "row_id": 28002, "seed_ids": "[6709]" }
0.700396
Code_Contests_28002
I
[ "shortest_path", "find_shortest_path" ]
2
[ [ "find_shortest_path", "shortest_path" ] ]
1
[]
false
[]
false
pytest
true
[]
true
9d4cfba14bbc019bc4aa730bdedcfca5ef73205a
23259d59c21465f23c646bc0a2e3d3680fae2379
v1.0
instruct
Code_Contests
Code_Contests_28063_I
You are given two non-negative integers, `a` and `b`. Petya is fascinated by the beauty of palindromic numbers. A number is called palindromic if it remains the same when its digits are reversed. Petya wants to know how many integers in the inclusive range [a, b] are palindromic. Write a function that takes two intege...
def is_palindrome(n): """ Checks if the given number n is a palindrome. """ return str(n) == str(n)[::-1] def count_palindromic_numbers(a, b): """ Returns the count of palindromic numbers in the inclusive range [a, b]. """ count = 0 for num in range(a, b + 1): if is_palindro...
from solution import count_palindromic_numbers def test_count_palindromic_numbers_single_digit(): assert count_palindromic_numbers(1, 10) == 9 def test_count_palindromic_numbers_large_range(): assert count_palindromic_numbers(100, 200) == 10 def test_count_palindromic_numbers_small_range(): assert count_...
[ { "docstring": "Checks if the given number n is a palindrome.", "function_declaration": "def is_palindrome(n):", "function_name": "is_palindrome", "parameter_list": "(n)" }, { "docstring": "Returns the count of palindromic numbers in the inclusive range [a, b].", "function_declaration": ...
[ 0, 0, 0, 1, 0, 0, 1, 1 ]
3
medium
0.375
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def count_palindromic_numbers(a, b):\n \"\"\"\n Returns the count of palindromic numbers between a and b inclusive.\n \"\"\"\n def is_palindrom...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00028063", "row_id": 28063, "seed_ids": "[6589]" }
0.674763
Code_Contests_28063
I
[ "is_palindrome", "count_palindromic_numbers" ]
2
[ [ "count_palindromic_numbers", "is_palindrome" ] ]
1
[]
false
[]
false
pytest
true
[]
true
67ef2f10b5543b57328fe1b87001fe896756611e
116c2961cef38691ad3661498380f9f1c1dbad86
v1.0
instruct
Code_Contests
Code_Contests_28117_I
In a computer network, there are N computers connected through M cables. Each cable connects two computers and has a certain latency associated with it. The computers are labeled from 1 to N. Given the network with the latencies of the cables, you are required to find the minimum total latency required to connect all c...
def find_parent(parent, i): if parent[i] == i: return i else: return find_parent(parent, parent[i]) def union(parent, rank, x, y): xroot = find_parent(parent, x) yroot = find_parent(parent, y) if rank[xroot] < rank[yroot]: parent[xroot] = yroot elif rank[xroot] > ra...
from solution import minimum_latency def test_minimum_latency_example(): assert minimum_latency(4, 5, [(1, 2, 1), (1, 3, 4), (2, 3, 2), (3, 4, 3), (2, 4, 5)]) == 6 def test_minimum_latency_disconnected(): assert minimum_latency(4, 2, [(1, 2, 1), (3, 4, 2)]) == -1 def test_minimum_latency_minimum_edges(): ...
[ { "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, 1, 0 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def find_parent(parent, i):\n if parent[i] == i:\n return i\n else:\n return find_parent(parent, parent[i])\n\ndef union(parent, rank, ...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00028117", "row_id": 28117, "seed_ids": "[5]" }
0.749716
Code_Contests_28117
I
[ "find_parent", "union", "kruskal", "minimum_latency" ]
4
[ [ "kruskal", "find_parent" ], [ "kruskal", "union" ], [ "minimum_latency", "kruskal" ], [ "union", "find_parent" ] ]
4
[]
false
[]
false
pytest
true
[]
true
e04ec6222cbd8ff3b01c76aadb8129f2dfa6ef5e
8328a6d33dd73cef82af8a71da8b62258094b9dc
v1.0
instruct
Code_Contests
Code_Contests_28135_I
The Watchtower Problem In a far-off kingdom, there is a network of watchtowers connected by roads. The kingdom needs to set up a new defense strategy in order to maximize the visibility of these watchtowers. Each watchtower must be able to communicate with others in the network, but no two watchtowers should be able t...
from collections import deque, defaultdict def is_bipartite(n, edges): """ Determines if a graph is bipartite and returns the two sets of vertices if it is. :param n: Number of vertices :param edges: List of edges :return: Tuple (is_bipartite, set1, set2) or (False, [], []) if not bipartite ...
from solution import partition_watchtowers def test_example_1(): n = 6 m = 6 edges = [(1, 2), (1, 3), (2, 4), (3, 4), (4, 5), (5, 6)] output = partition_watchtowers(n, m, edges) assert output.startswith("YES") def test_example_2(): n = 5 m = 5 edges = [(1, 2), (1, 3), (2, 3), (3, 4), (...
[ { "docstring": "Determines if a graph is bipartite and returns the two sets of vertices if it is.\n\n:param n: Number of vertices\n:param edges: List of edges\n:return: Tuple (is_bipartite, set1, set2) or (False, [], []) if not bipartite", "function_declaration": "def is_bipartite(n, edges):", "function...
[ 0, 0, 0, 0, 1 ]
1
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "from collections import deque, defaultdict\n\ndef is_bipartite(n, roads):\n adj_list = defaultdict(list)\n for u, v in roads:\n adj_list[u].ap...
trial_gpt4o_4
{ "original_instruction": "", "prompt_id": "00028135", "row_id": 28135, "seed_ids": "[1158]" }
0.69197
Code_Contests_28135
I
[ "is_bipartite", "partition_watchtowers" ]
2
[ [ "partition_watchtowers", "is_bipartite" ] ]
1
[]
false
[]
false
pytest
true
[]
true
3e63de129a1d7000fe88ee42601e1d2f4a8d1642
b69e4329c0ed6bdc996cdd7425bd8b0bb6c99b20
v1.0
instruct
Code_Contests
Code_Contests_28177_I
Given a rooted binary tree, you need to find the lowest common ancestor of two given nodes in the tree. The lowest common ancestor (LCA) of nodes `p` and `q` in a tree is defined as the lowest node that has both `p` and `q` as descendants (where we allow a node to be a descendant of itself). Input The input consists...
import sys import collections def lca_preprocess(tree, n, root=1): LOG = 16 # Since 2^16 > 10^5 up = [[-1] * (LOG + 1) for _ in range(n + 1)] depth = [-1] * (n + 1) def dfs(node, parent): depth[node] = depth[parent] + 1 up[node][0] = parent for i in range(1, LOG + 1): ...
from solution import lca_preprocess, lca def test_lca_preprocess(): tree = {1: [2, 3], 2: [1, 4, 5], 3: [1, 6], 4: [2], 5: [2], 6: [3]} up, depth = lca_preprocess(tree, 6) assert depth[1] == 0 assert depth[2] == 1 assert depth[3] == 1 assert depth[4] == 2 assert depth[5] == 2 assert dep...
[ { "docstring": null, "function_declaration": "def lca_preprocess(tree, n, root=1):", "function_name": "lca_preprocess", "parameter_list": "(tree, n, root=1)" }, { "docstring": null, "function_declaration": "def lca(up, depth, p, q):", "function_name": "lca", "parameter_list": "(u...
[ 0, 1 ]
1
medium
0.5
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "class TreeNode:\n def __init__(self, x):\n self.val = x\n self.left = None\n self.right = None\n\ndef lca(root, p, q):\n \"\"\"\...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00028177", "row_id": 28177, "seed_ids": "[11477]" }
0.617596
Code_Contests_28177
I
[ "lca_preprocess", "lca", "process_input" ]
3
[ [ "process_input", "lca" ], [ "process_input", "lca_preprocess" ] ]
2
[ "process_input" ]
false
[]
false
pytest
true
[]
true
c74e33306fccd0b34d17901396399d45ed7481dc
79aa0d090c22455abe2fa331d7191e20bbbce683
v1.0
instruct
Code_Contests
Code_Contests_28199_I
Carlos is a computer engineer who is working on a unique project involving a large number of servers spread across different data centers. Each server can communicate with certain other servers directly. His task is to ensure that he can send a message from any server to any other server, either directly or through a s...
def find(parent, i): if parent[i] == i: return i else: return find(parent, 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]: parent[root_y] = root_x elif rank[r...
from solution import min_edges_to_connect_all_servers def test_min_edges_to_connect_all_servers_example1(): n = 5 m = 3 edges = [(1, 2), (2, 3), (4, 5)] assert min_edges_to_connect_all_servers(n, m, edges) == 1 def test_min_edges_to_connect_all_servers_example2(): n = 6 m = 5 edges = [(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)" }, ...
[ 1, 0, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def find(parent, i):\n if parent[i] == i:\n return i\n else:\n return find(parent, parent[i])\n\n\ndef union(parent, rank, x, y):\n ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00028199", "row_id": 28199, "seed_ids": "[60]" }
0.654507
Code_Contests_28199
I
[ "find", "union", "min_edges_to_connect_all_servers" ]
3
[ [ "min_edges_to_connect_all_servers", "find" ], [ "min_edges_to_connect_all_servers", "union" ], [ "union", "find" ] ]
3
[]
false
[]
false
pytest
true
[]
true
1151b7f144dbf6e4cd27c14c4ed1bf480197ce92
381990ab00557334f583fc65116370963d68f8bc
v1.0
instruct
Code_Contests
Code_Contests_28223_I
In a distant future, there is a network of autonomous delivery drones operating in a city that is represented as an undirected graph. The city has multiple intersections connected by bidirectional roads, and the intersections are denoted by nodes while the roads are denoted by edges. Each drone starts at a designated ...
import heapq def dijkstra(n, edges, target_nodes): graph = {i: [] for i in range(1, n + 1)} for u, v, w in edges: graph[u].append((v, w)) graph[v].append((u, w)) def shortest_path(start): distances = {i: float('inf') for i in range(1, n + 1)} distances[start] = 0 pq...
from solution import dijkstra, get_shortest_paths_from_input def test_dijkstra_basic_case(): n = 6 edges = [ (1, 2, 7), (1, 3, 9), (1, 6, 14), (2, 3, 10), (2, 4, 15), (3, 4, 11), (3, 6, 2), (4, 5, 6), (5, 6, 9) ] target_nodes = [4,...
[ { "docstring": null, "function_declaration": "def dijkstra(n, edges, target_nodes):", "function_name": "dijkstra", "parameter_list": "(n, edges, target_nodes)" }, { "docstring": null, "function_declaration": "def get_shortest_paths_from_input(input_data):", "function_name": "get_shor...
[ 0, 1, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "import heapq\n\ndef find_shortest_paths(n, edges, targets):\n graph = {i: [] for i in range(1, n + 1)}\n for u, v, w in edges:\n graph[u].appe...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00028223", "row_id": 28223, "seed_ids": "[3556]" }
0.727419
Code_Contests_28223
I
[ "dijkstra", "get_shortest_paths_from_input" ]
2
[ [ "get_shortest_paths_from_input", "dijkstra" ] ]
1
[]
false
[]
false
pytest
true
[]
true
2bca4ee7d595b77207e12365dc4a73cfe5ba797d
170218e4095d3201a285c830800c2f248f782db0
v1.0
instruct
Code_Contests
Code_Contests_28296_I
Detective John is investigating a series of crimes in the city. He has a list of suspects, the date and time each crime was reported, and the alibi timeframes provided by each suspect. John needs to find out if any of the suspects could have committed a specific crime given their alibis. Each crime's report time is gi...
def time_to_minutes(time): hours, minutes = map(int, time.split(':')) return hours * 60 + minutes def is_time_within_range(crime_time, start_time, end_time): crime_time_minutes = time_to_minutes(crime_time) start_time_minutes = time_to_minutes(start_time) end_time_minutes = time_to_minutes(end_time...
def test_time_to_minutes(): assert time_to_minutes("12:30") == 750 assert time_to_minutes("00:00") == 0 assert time_to_minutes("23:59") == 1439 def test_is_time_within_range(): assert is_time_within_range("12:30", "12:00", "13:00") == True assert is_time_within_range("11:59", "12:00", "13:00") == F...
[ { "docstring": null, "function_declaration": "def time_to_minutes(time):", "function_name": "time_to_minutes", "parameter_list": "(time)" }, { "docstring": null, "function_declaration": "def is_time_within_range(crime_time, start_time, end_time):", "function_name": "is_time_within_ra...
[ 0, 0, 1 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def time_to_minutes(time):\n hh, mm = time.split(':')\n return int(hh) * 60 + int(mm)\n\ndef is_alibi_cover(alibi, crime_time):\n start, end = ali...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00028296", "row_id": 28296, "seed_ids": "[9932]" }
0.551321
Code_Contests_28296
I
[ "time_to_minutes", "is_time_within_range", "find_potential_suspects", "solve" ]
4
[ [ "find_potential_suspects", "is_time_within_range" ], [ "is_time_within_range", "time_to_minutes" ], [ "solve", "find_potential_suspects" ] ]
3
[]
false
[]
false
pytest
false
[]
true
4741be9b9efc5cdbd81c065587bca7c020c61a0f
25600cd0f0fcd53de31f4402bb4f19cd15ab968e
v1.0
instruct
Code_Contests
Code_Contests_28298_I
You are given a grid of size N x M where each cell represents a particular height above sea level. There is a hiker who can move up, down, left, or right, but only to cells that are at most 1 unit higher than his current cell (he can move freely to cells of lower or equal height). The hiker starts at the top-left corne...
from collections import deque def min_steps_to_reach_end(N, M, grid, water_cells): # Create the visited grid and set water cells as visited visited = [[False] * M for _ in range(N)] for r, c in water_cells: visited[r][c] = True # Directions for moving up, down, left, right directions =...
from solution import solve_hiker_problem def test_example_1(): N, M = 5, 5 heights = [ [1, 2, 3, 4, 5], [2, 2, 3, 4, 5], [1, 1, 1, 2, 2], [3, 3, 3, 3, 3], [4, 4, 4, 4, 4] ] W = 3 water_coordinates = [(1, 3), (2, 2), (4, 0)] assert solve_hiker_problem(N, M...
[ { "docstring": null, "function_declaration": "def min_steps_to_reach_end(N, M, grid, water_cells):", "function_name": "min_steps_to_reach_end", "parameter_list": "(N, M, grid, water_cells)" }, { "docstring": null, "function_declaration": "def solve_hiker_problem(N, M, heights, W, water_c...
[ 0, 0, 0, 0, 0, 1, 0, 1, 0, 0 ]
2
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "from collections import deque\n\ndef min_steps_to_reach_bottom_right(N, M, grid, water_cells):\n # Mark water cells\n for r, c in water_cells:\n ...
trial_gpt4o_7
{ "original_instruction": "", "prompt_id": "00028298", "row_id": 28298, "seed_ids": "[11426]" }
0.736962
Code_Contests_28298
I
[ "min_steps_to_reach_end", "solve_hiker_problem" ]
2
[ [ "solve_hiker_problem", "min_steps_to_reach_end" ] ]
1
[]
false
[]
false
pytest
true
[]
true
79c0c0c85b20b1aefb92dea3f7e6da8a80455a3b
435c9671b56d8d3f4322f88bf61ee890ddf45046
v1.0
instruct
Code_Contests
Code_Contests_28317_I
Given a grid of dimensions m x n consisting of '0's (empty space) and '1's (land), write an algorithm to count the number of islands. An island is surrounded by water and is formed by connecting adjacent lands horizontally or vertically. You may assume all four edges of the grid are surrounded by water. Constraints: -...
def num_islands(grid): """ Returns the number of islands in the given grid. """ if not grid: return 0 def dfs(grid, x, y): if x < 0 or x >= len(grid) or y < 0 or y >= len(grid[0]) or grid[x][y] == '0': return grid[x][y] = '0' # Mark as visited dfs(grid, ...
from solution import count_islands def test_count_islands_case_1(): assert count_islands(4, 5, ["11000", "11000", "00100", "00011"]) == 3 def test_count_islands_single_row(): assert count_islands(1, 5, ["11110"]) == 1 def test_count_islands_single_column(): assert count_islands(5, 1, ["1", "0", "1", "0",...
[ { "docstring": "Returns the number of islands in the given grid.", "function_declaration": "def num_islands(grid):", "function_name": "num_islands", "parameter_list": "(grid)" }, { "docstring": null, "function_declaration": "def count_islands(m, n, grid_lines):", "function_name": "co...
[ 0, 0, 0, 0, 0, 1, 0, 0, 0, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def num_islands(m, n, grid):\n if not grid:\n return 0\n \n def dfs(grid, x, y):\n if x < 0 or y < 0 or x >= m or y >= n or grid[x][...
trial_gpt4o_5
{ "original_instruction": "", "prompt_id": "00028317", "row_id": 28317, "seed_ids": "[6457]" }
0.581913
Code_Contests_28317
I
[ "num_islands", "count_islands" ]
2
[ [ "count_islands", "num_islands" ] ]
1
[]
false
[]
false
pytest
true
[]
true
292ccbecd450e063e33f4bf1b631e1b3e25e61a2
7a8ca1f939eb027332c0186d193d53559d4fb624
v1.0
instruct
Code_Contests
Code_Contests_28335_I
## Random Points In Circle Constraints * 1 ≤ n ≤ 1000 * 1 ≤ radius ≤ 1000 Input n x1 y1 radius1 x2 y2 radius2 ... xn yn radiusn The first line contains an integer n, the number of circles. Each of the next n lines contains three integers: the coordinates of the center (xi, yi) and the radius of the ith circle. Ou...
import random import math def generate_points_in_circle(x_center, y_center, radius, num_points=10): points = [] while len(points) < num_points: angle = random.uniform(0, 2 * math.pi) r = radius * (random.random() ** 0.5) x = x_center + r * math.cos(angle) y = y_center + r * math...
from solution import generate_random_points_in_circles def test_single_circle(): input_data = "1\n0 0 5" output = generate_random_points_in_circles(input_data) lines = output.strip().split('\n') assert len(lines) == 10 for line in lines: x, y = map(float, line.split()) assert x**2 +...
[ { "docstring": null, "function_declaration": "def generate_points_in_circle(x_center, y_center, radius, num_points=10):", "function_name": "generate_points_in_circle", "parameter_list": "(x_center, y_center, radius, num_points=10)" }, { "docstring": null, "function_declaration": "def gen...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "import random\nimport math\n\ndef generate_random_points_in_circle(x, y, radius, num_points=10):\n points = set()\n \n while len(points) < num_poi...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00028335", "row_id": 28335, "seed_ids": "[4583]" }
0.709858
Code_Contests_28335
I
[ "generate_points_in_circle", "generate_random_points_in_circles" ]
2
[ [ "generate_random_points_in_circles", "generate_points_in_circle" ] ]
1
[]
false
[]
false
pytest
true
[]
true
a00a7fabb7e8d88b81bc5d1b291c24bb52fde09e
c44ee67ed3e1e0b01d7c493dcdef721c95804ce3
v1.0
instruct
Code_Contests
Code_Contests_28336_I
IP Address Compression In modern network management, the use of IP addresses, notably IPv4, is widespread. An IPv4 address is composed of four octets, each one represented as a decimal number in the range 0-255, and separated by dots. For example, 192.168.0.1 is a valid IPv4 address. Sometimes it is useful to compres...
def ip_to_int(ip): parts = map(int, ip.split('.')) return (next(parts) << 24) + (next(parts) << 16) + (next(parts) << 8) + next(parts) def int_to_ip(ip_int): return f"{(ip_int >> 24) & 0xFF}.{(ip_int >> 16) & 0xFF}.{(ip_int >> 8) & 0xFF}.{ip_int & 0xFF}" def compress(ip_list): if not ip_list: ...
from solution import compress, expand def test_compress(): assert compress([ "192.168.0.1", "192.168.0.2", "192.168.0.3", "192.168.0.10", "192.168.1.1", "192.168.1.2" ]) == [ "192.168.0.1-192.168.0.3", "192.168.0.10", "192.168.1.1-1...
[ { "docstring": null, "function_declaration": "def ip_to_int(ip):", "function_name": "ip_to_int", "parameter_list": "(ip)" }, { "docstring": null, "function_declaration": "def int_to_ip(ip_int):", "function_name": "int_to_ip", "parameter_list": "(ip_int)" }, { "docstring":...
[ 0, 1, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "import ipaddress\n\ndef compress(ip_addresses):\n def ip_to_int(ip):\n return int(ipaddress.IPv4Address(ip))\n \n def int_to_ip(ip_int):\n ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00028336", "row_id": 28336, "seed_ids": "[2284]" }
0.514725
Code_Contests_28336
I
[ "ip_to_int", "int_to_ip", "compress", "expand" ]
4
[ [ "compress", "ip_to_int" ], [ "expand", "int_to_ip" ], [ "expand", "ip_to_int" ] ]
3
[]
false
[]
false
pytest
true
[]
true
f3a5a2fa2bce8eda369c949a0198bffefb83fa43
64d6cd88ac1d4106096bc5283ff66dcd23e70cb4
v1.0
instruct
Code_Contests
Code_Contests_28368_I
Sudoku Solver Given a partially filled 9x9 Sudoku grid, the goal is to fill in the empty cells such that each row, each column, and each of the nine 3x3 subgrids contain all of the digits from 1 to 9. The Sudoku grid will be provided as a 9x9 matrix where empty cells are represented by 0s. Input The input is a singl...
def is_valid(board, row, col, num): """ Check if it's valid to place 'num' at board[row][col] """ # Check row for x in range(9): if board[row][x] == num: return False # Check column for x in range(9): if board[x][col] == num: return False # Check...
def test_sudoku_solver(): board = [ [5, 3, 0, 0, 7, 0, 0, 0, 0], [6, 0, 0, 1, 9, 5, 0, 0, 0], [0, 9, 8, 0, 0, 0, 0, 6, 0], [8, 0, 0, 0, 6, 0, 0, 0, 3], [4, 0, 0, 8, 0, 3, 0, 0, 1], [7, 0, 0, 0, 2, 0, 0, 0, 6], [0, 6, 0, 0, 0, 0, 2, 8, 0], [0, 0, 0, 4, ...
[ { "docstring": "Check if it's valid to place 'num' at board[row][col]", "function_declaration": "def is_valid(board, row, col, num):", "function_name": "is_valid", "parameter_list": "(board, row, col, num)" }, { "docstring": "Solve the Sudoku puzzle using backtracking.", "function_declar...
[ 0, 0, 0, 1, 1 ]
2
medium
0.4
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_valid(board, row, col, num):\n \"\"\"\n Check if 'num' can be placed at board[row][col].\n \"\"\"\n # Check if 'num' is in the current r...
trial_gpt4o_3
{ "original_instruction": "", "prompt_id": "00028368", "row_id": 28368, "seed_ids": "[822]" }
0.719515
Code_Contests_28368
I
[ "is_valid", "solve_sudoku", "find_empty_position", "print_sudoku" ]
4
[ [ "solve_sudoku", "find_empty_position" ], [ "solve_sudoku", "is_valid" ] ]
2
[]
false
[]
false
pytest
false
[]
true
17dbb1b10bb603d8400180367ef44995ed1ddd62
5ed030c5681e5f3d4dd63ffb62c857fd61aa1ac1
v1.0
instruct
Code_Contests
Code_Contests_28395_I
Emma is participating in a programming contest, and she's working on a problem that involves lines on a Cartesian plane. The problem requires her to determine if three points are collinear, which means they lie on the same straight line. Emma wants to automate the checking process. Can you help her write a program to d...
def are_points_collinear(x1, y1, x2, y2, x3, y3): """ Check if three points (x1, y1), (x2, y2), (x3, y3) are collinear. Points are collinear if the area of the triangle they form is zero. This can be determined using the determinant method. """ # Using the determinant formula to check for collin...
from solution import are_points_collinear, check_collinear_points def test_are_points_collinear(): assert are_points_collinear(0, 0, 1, 1, 2, 2) == True assert are_points_collinear(0, 0, 1, 1, 2, 3) == False assert are_points_collinear(1, 2, 3, 4, 5, 6) == True assert are_points_collinear(1, 1, 2, 2, 3...
[ { "docstring": "Check if three points (x1, y1), (x2, y2), (x3, y3) are collinear.\nPoints are collinear if the area of the triangle they form is zero.\nThis can be determined using the determinant method.", "function_declaration": "def are_points_collinear(x1, y1, x2, y2, x3, y3):", "function_name": "ar...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def are_points_collinear(x1, y1, x2, y2, x3, y3):\n \"\"\"\n Returns \"YES\" if points (x1, y1), (x2, y2), (x3, y3) are collinear, otherwise \"NO\".\...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00028395", "row_id": 28395, "seed_ids": "[10830]" }
0.647872
Code_Contests_28395
I
[ "are_points_collinear", "check_collinear_points" ]
2
[ [ "check_collinear_points", "are_points_collinear" ] ]
1
[]
false
[]
false
pytest
true
[]
true
295618b115dcfa0238a3b0a8d0b26399fee7ae9e
bcde54365b597aa3c3b2e8946cb14f2152ede25c
v1.0
instruct
Code_Contests
Code_Contests_28492_I
Alex loves playing with strings. Today, he is curious if a given string can be transformed into a palindrome by removing at most one character (or not removing any character at all). A palindrome is a string that reads the same forward and backward. Your task is to determine if it is possible to make the string a pa...
def can_be_palindrome(s): """ Determine if the string can be transformed into a palindrome by removing at most one character. """ def is_palindrome_range(l, r): # Check if the substring s[l:r+1] is a palindrome return all(s[i] == s[r - i + l] for i in range(l, (l + r) // 2 + 1)) ...
def test_can_be_palindrome(): assert can_be_palindrome("abca") == True assert can_be_palindrome("abc") == False assert can_be_palindrome("racecar") == True assert can_be_palindrome("radar") == True assert can_be_palindrome("a") == True assert can_be_palindrome("ae") == True assert can_be_pal...
[ { "docstring": "Determine if the string can be transformed into a palindrome\nby removing at most one character.", "function_declaration": "def can_be_palindrome(s):", "function_name": "can_be_palindrome", "parameter_list": "(s)" }, { "docstring": null, "function_declaration": "def check...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def can_be_palindrome(s):\n \"\"\"\n Determine if the string can be transformed into a palindrome\n by removing at most one character.\n \"\"\"...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00028492", "row_id": 28492, "seed_ids": "[2618]" }
0.761627
Code_Contests_28492
I
[ "can_be_palindrome", "check_palindrome_possibility" ]
2
[ [ "check_palindrome_possibility", "can_be_palindrome" ] ]
1
[]
false
[]
false
pytest
false
[]
true
daaa536d18252c576f5fe41edd79b726cda9f8dd
12fdae88335c75fb2283f58989568a5c608a0592
v1.0
instruct
Code_Contests
Code_Contests_28526_I
You are given a collection of books in a library represented by an array of integers where each element represents the number of pages in a book. You want to divide these books into a specified number of students such that each student gets at least one book and the maximum number of pages assigned to a student is mini...
def can_allocate(pages, N, M, max_pages): """ Helper function to determine if it is possible to allocate pages such that no student has more than max_pages. """ student_count = 1 current_pages = 0 for i in range(N): if pages[i] > max_pages: return False ...
from solution import minimum_maximum_pages def test_single_case(): T = 1 test_cases = [ ((4, 2), [12, 34, 67, 90]) ] assert minimum_maximum_pages(T, test_cases) == [113] def test_multiple_cases(): T = 2 test_cases = [ ((4, 2), [12, 34, 67, 90]), ((3, 2), [15, 10, 20]) ...
[ { "docstring": "Helper function to determine if it is possible to allocate pages such that no student has more than max_pages.", "function_declaration": "def can_allocate(pages, N, M, max_pages):", "function_name": "can_allocate", "parameter_list": "(pages, N, M, max_pages)" }, { "docstring"...
[ 0, 0, 1 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_feasible(pages, n, m, curr_min):\n students_required = 1\n curr_sum = 0\n\n for page in pages:\n if page > curr_min:\n re...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00028526", "row_id": 28526, "seed_ids": "[8194]" }
0.759673
Code_Contests_28526
I
[ "can_allocate", "find_min_pages", "minimum_maximum_pages" ]
3
[ [ "find_min_pages", "can_allocate" ], [ "minimum_maximum_pages", "find_min_pages" ] ]
2
[]
false
[]
false
pytest
true
[]
true
8f48e8c1aa227d63e988e0b509f7f63efd16a7ca
ff1fd4d7f80fdd1ad22679e71cdffa4b3fbab520
v1.0
instruct
Code_Contests
Code_Contests_28528_I
Problem Statement Rina is a biologist tracking population changes in an endangered species. She's collected data on the population's birth and death rates over a period of time. However, her field notes are incomplete or slightly flawed. She recorded the birth and death rates as arrays, but some birth or death rates m...
def estimate_neighbors(arr, i): """ Helper function to estimate the value at index `i` based on its non-missing neighbors. """ n = len(arr) left, right = i - 1, i + 1 while left >= 0 and arr[left] == -1: left -= 1 while right < n and arr[right] == -1: right += 1 le...
import pytest from solution import process_data, reconstruct_and_calculate_population_change def test_reconstruct_and_calculate_population_change(): assert reconstruct_and_calculate_population_change(5, [100, -1, 150, 200, -1], [-1, 50, -1, 100, 150]) == 350 assert reconstruct_and_calculate_population_change(4...
[ { "docstring": "Helper function to estimate the value at index `i` based on its non-missing neighbors.", "function_declaration": "def estimate_neighbors(arr, i):", "function_name": "estimate_neighbors", "parameter_list": "(arr, i)" }, { "docstring": null, "function_declaration": "def rec...
[ 0, 0, 0, 0, 1 ]
1
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def fill_missing(arr):\n \"\"\"\n Fill the missing values in the array (-1) using the average of the known neighbors.\n If a value has no valid ne...
trial_gpt4o_4
{ "original_instruction": "", "prompt_id": "00028528", "row_id": 28528, "seed_ids": "[2392]" }
0.578357
Code_Contests_28528
I
[ "estimate_neighbors", "reconstruct_and_calculate_population_change", "process_data" ]
3
[ [ "process_data", "reconstruct_and_calculate_population_change" ], [ "reconstruct_and_calculate_population_change", "estimate_neighbors" ] ]
2
[ "process_data" ]
false
[]
false
pytest
true
[]
true
1f6f8acdba4cf0ffc4355f18dcf0d6f3bf8b3726
0c4331d80ade5154f5341553ec214c62c8e9a249
v1.0
instruct
Code_Contests
Code_Contests_28564_I
You are part of a network team responsible for managing a company's computer network. This network can be represented as a tree (a connected acyclic graph) where nodes represent routers and edges represent the direct connections between them. The company wants to optimize the network by ensuring that communication be...
from collections import deque, defaultdict def bfs(node, n, adj): dist = [-1] * (n + 1) dist[node] = 0 q = deque([node]) farthest_node = node max_dist = 0 while q: current = q.popleft() for neighbor in adj[current]: if dist[neighbor] == -1: dist[...
from solution import find_max_path_length def test_example_1(): n, k = 5, 4 edges = [(1, 2), (1, 3), (3, 4), (3, 5)] assert find_max_path_length(n, k, edges) == (3, "YES") def test_example_2(): n, k = 6, 2 edges = [(1, 2), (2, 3), (3, 4), (4, 5), (5, 6)] assert find_max_path_length(n, k, edges...
[ { "docstring": null, "function_declaration": "def bfs(node, n, adj):", "function_name": "bfs", "parameter_list": "(node, n, adj)" }, { "docstring": null, "function_declaration": "def find_max_path_length(n, k, edges):", "function_name": "find_max_path_length", "parameter_list": "...
[ 0, 1, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "from collections import deque\n\ndef bfs_farthest_node(start, n, adj):\n visited = [-1] * (n+1)\n queue = deque([(start, 0)]) # (current_node, curre...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00028564", "row_id": 28564, "seed_ids": "[5535]" }
0.703465
Code_Contests_28564
I
[ "bfs", "find_max_path_length" ]
2
[ [ "find_max_path_length", "bfs" ] ]
1
[]
false
[]
false
pytest
true
[]
true
924ef87e64195ebac571a3afe972d642e696631f
e354173db41da95938d62237bfb39a8098ca88b8
v1.0
instruct
Code_Contests
Code_Contests_28594_I
Alex is planning a picnic in the local park which is designed as an n × m grid of cells, where each cell is either empty or contains an obstacle. The park authorities have placed rest stations at certain locations to ensure that visitors can comfortably enjoy their time. Alex wants to find the shortest path from one re...
from collections import deque def shortest_path(n, m, park, start, end): directions = [(-1, 0), (1, 0), (0, -1), (0, 1)] x1, y1 = start x2, y2 = end queue = deque([(x1, y1, 0)]) # (x, y, distance) visited = {(x1, y1)} while queue: x, y, dist = queue.popleft() ...
from solution import find_shortest_path def test_example_1(): n = 5 m = 5 grid = [ "..o..", "..##.", ".o..#", "..o..", "#.#o." ] coords = [2, 3, 4, 3] assert find_shortest_path(n, m, grid, coords) == 2 def test_example_2(): n = 4 m = 6 grid =...
[ { "docstring": null, "function_declaration": "def shortest_path(n, m, park, start, end):", "function_name": "shortest_path", "parameter_list": "(n, m, park, start, end)" }, { "docstring": null, "function_declaration": "def find_shortest_path(n, m, grid, coords):", "function_name": "f...
[ 1, 1, 0 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "from collections import deque\n\ndef shortest_path(n, m, grid, start, end):\n # Directions for moving in 4 possible directions (Up, Down, Left, Right)\n...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00028594", "row_id": 28594, "seed_ids": "[342]" }
0.757422
Code_Contests_28594
I
[ "shortest_path", "find_shortest_path" ]
2
[ [ "find_shortest_path", "shortest_path" ] ]
1
[]
false
[]
false
pytest
true
[]
true
a4a1365feed0df9fdb3430e6383b95845c5270aa
708a9921f79fa0d9c64aa9d772978b7f09238b0a
v1.0
instruct
Code_Contests
Code_Contests_28634_I
Palindrome Substring Indices Problem Statement Given a string S, find all the distinct pairs of indices (i, j) such that the substring S[i:j+1] is a palindrome. A string is a palindrome if it reads the same backward as forward. For example, the string "aba" is a palindrome, while the string "abc" is not. Input S ...
def is_palindrome(s): return s == s[::-1] def find_palindromic_substrings(S): result = [] for i in range(len(S)): for j in range(i, len(S)): if is_palindrome(S[i:j+1]): result.append((i, j)) return result if result else "No palindromic substrings"
from solution import find_palindromic_substrings def test_single_character(): assert find_palindromic_substrings("a") == [(0, 0)] def test_no_palindromic_substrings(): assert find_palindromic_substrings("abcd") == [(0, 0), (1, 1), (2, 2), (3, 3)] def test_mixed_palindromic_substrings(): assert find_palin...
[ { "docstring": null, "function_declaration": "def is_palindrome(s):", "function_name": "is_palindrome", "parameter_list": "(s)" }, { "docstring": null, "function_declaration": "def find_palindromic_substrings(S):", "function_name": "find_palindromic_substrings", "parameter_list":...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def find_palindromic_substrings_indices(S):\n \"\"\"\n This function finds all the distinct pairs of indices (i, j) such that the substring S[i:j+1] ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00028634", "row_id": 28634, "seed_ids": "[5935]" }
0.787182
Code_Contests_28634
I
[ "is_palindrome", "find_palindromic_substrings" ]
2
[ [ "find_palindromic_substrings", "is_palindrome" ] ]
1
[]
false
[]
false
pytest
true
[]
true
03e640751a333500fd6b788841ced3be42262334
44b0a6b043f1245f31d56b0e9493bcbbc0663817
v1.0
instruct
Code_Contests
Code_Contests_28737_I
In a distant land called Arithmeticia, a tournament is held every year where contestants solve intricate number sequences. This year, the sequence game involves a special number called the "Perfect Number." A Perfect Number is a positive integer that is equal to the sum of its proper divisors, excluding itself. For exa...
def is_perfect_number(n): """ Returns True if n is a perfect number, else False. A perfect number is equal to the sum of its proper divisors excluding itself. """ if n <= 1: return False sum_divisors = 1 # Start with 1 because 1 is a proper divisor of any number # Iterate over pos...
from solution import is_perfect_number, perfect_number_tournament def test_is_perfect_number(): assert is_perfect_number(28) == True assert is_perfect_number(6) == True assert is_perfect_number(12) == False assert is_perfect_number(1) == False assert is_perfect_number(0) == False assert is_perf...
[ { "docstring": "Returns True if n is a perfect number, else False.\nA perfect number is equal to the sum of its proper divisors excluding itself.", "function_declaration": "def is_perfect_number(n):", "function_name": "is_perfect_number", "parameter_list": "(n)" }, { "docstring": "Determines...
[ 0, 0, 0, 1, 1 ]
2
medium
0.4
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_perfect_number(n):\n \"\"\"\n Returns 'YES' if n is a perfect number, otherwise 'NO'.\n \"\"\"\n if n <= 1:\n return \"NO\"\n ...
trial_gpt4o_4
{ "original_instruction": "", "prompt_id": "00028737", "row_id": 28737, "seed_ids": "[11203]" }
0.684163
Code_Contests_28737
I
[ "is_perfect_number", "perfect_number_tournament" ]
2
[ [ "perfect_number_tournament", "is_perfect_number" ] ]
1
[]
false
[]
false
pytest
true
[]
true
5a1cfbbb3e993e029773915eca5f5755d139ab07
2d1e2461d2ab9ee579c62448822eecbacde3991e
v1.0
instruct
Code_Contests
Code_Contests_28743_I
You are given two strings $A = \\{a_0, a_1, ..., a_{n-1}\\}$ and $B = \\{b_0, b_1, ..., b_{m-1}\\}$ consisting of lowercase alphabets. Your task is to find the common characters between these two strings. Constraints * $1 \leq n, m \leq 200,000$ Input The input is given in the following format: $A$ $B$ The string...
from collections import Counter def common_characters(A, B): """ This function receives two strings A and B, and returns a list of common characters in alphabetical order, each on a new line. If there are no common characters, it returns a list with "No common characters". """ count_A = Counter...
from solution import common_characters def test_common_characters_with_common_chars(): assert common_characters("bananas", "cabana") == ["a", "b", "n"] def test_common_characters_without_common_chars(): assert common_characters("xyz", "abc") == ["No common characters"] def test_common_characters_all_chars_co...
[ { "docstring": "This function receives two strings A and B, and returns a list\nof common characters in alphabetical order, each on a new line.\nIf there are no common characters, it returns a list with \"No common characters\".", "function_declaration": "def common_characters(A, B):", "function_name": ...
[ 0, 0, 0, 0, 0, 0, 1, 0, 0, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def find_common_characters(A, B):\n \"\"\"\n Finds the common characters between two strings A and B and returns them sorted in alphabetical order.\n...
trial_gpt4o_6
{ "original_instruction": "", "prompt_id": "00028743", "row_id": 28743, "seed_ids": "[2918]" }
0.680737
Code_Contests_28743
I
[ "common_characters", "print_common_characters" ]
2
[ [ "print_common_characters", "common_characters" ] ]
1
[]
false
[]
false
pytest
true
[]
true
7675d65c1d7377eb6178d1b0ef6b530e08fb1b8c
84962861ea3b6c5f54cc4971c2eb654b42dc1721
v1.0
instruct
Code_Contests
Code_Contests_28758_I
A company has a network of n offices, connected by bidirectional roads of varying lengths. The CEO wants to implement a new communication system that connects every office directly or indirectly. The system should be installed in such a way that the total length of roads used is minimized. You need to design a program...
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]: parent[r...
from solution import solve def test_example_1(): input_data = "4 5\n1 2 3\n1 3 1\n2 3 2\n2 4 4\n3 4 5" assert solve(input_data) == 7 def test_example_2(): input_data = "5 3\n1 2 1\n2 3 2\n4 5 3" assert solve(input_data) == -1 def test_single_office(): input_data = "1 0" assert solve(i...
[ { "docstring": null, "function_declaration": "def find(parent, i):", "function_name": "find", "parameter_list": "(parent, i)" }, { "docstring": null, "function_declaration": "def union(parent, rank, x, y):", "function_name": "union", "parameter_list": "(parent, rank, x, y)" }, ...
[ 0, 0, 1 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def find_minimum_total_length(n, m, roads):\n # Kruskal's algorithm to find Minimum Spanning Tree.\n \n # Sort edges based on the weight\n road...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00028758", "row_id": 28758, "seed_ids": "[66]" }
0.710994
Code_Contests_28758
I
[ "find", "union", "minimum_total_length", "solve" ]
4
[ [ "minimum_total_length", "find" ], [ "minimum_total_length", "union" ], [ "solve", "minimum_total_length" ], [ "union", "find" ] ]
4
[]
false
[]
false
pytest
true
[]
true
9adf86f2fc9091429a1a14171ffbabdea193d493
41d9cb510d62af6621dc9c6835aab7d4150d20fb
v1.0
instruct
Code_Contests
Code_Contests_28769_I
Tom and Jerry are playing a game with an array of numbers. They take turns removing elements from the array, where a turn consists of removing one element and splitting it into two new elements such that their sum equals the value of the removed element and their product is maximized. These new elements are then reinse...
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 +...
from solution import is_prime, can_split, game_winner def test_is_prime(): assert is_prime(2) == True assert is_prime(3) == True assert is_prime(4) == False assert is_prime(5) == True assert is_prime(10) == False assert is_prime(13) == True def test_can_split(): assert can_split(2) == Fals...
[ { "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 check if a number can be split into two parts such that both parts are integers.", "function_de...
[ 0, 0, 0, 1, 0 ]
1
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "import math\n\ndef is_prime(n):\n \"\"\"Return True if n is a prime number; otherwise return False.\"\"\"\n if n <= 1:\n return False\n if ...
trial_gpt4o_3
{ "original_instruction": "", "prompt_id": "00028769", "row_id": 28769, "seed_ids": "[8645]" }
0.741896
Code_Contests_28769
I
[ "is_prime", "can_split", "game_winner" ]
3
[ [ "can_split", "is_prime" ], [ "game_winner", "can_split" ] ]
2
[]
false
[]
false
pytest
true
[]
true
37ea814716757af663618161e7f92fcf682704a9
c4b1edaf4d18bf8def07029ee1b59c2a1ebdbf3f
v1.0
instruct
Code_Contests
Code_Contests_28815_I
Given a string that contains a list of numbers separated by commas, write a program to identify and output the highest prime number in the list. If there are no prime numbers in the list, return -1. A prime number is a positive integer greater than 1 that has no positive integer divisors other than 1 and itself. Inpu...
def is_prime(n): """ Helper function to check if a number is prime. """ if n <= 1: return False if n == 2: return True if n % 2 == 0: return False for i in range(3, int(n**0.5) + 1, 2): if n % i == 0: return False return True def highest_prime_in_list...
from solution import highest_prime_in_list def test_highest_prime(): assert highest_prime_in_list("3,5,8,13,23,4,6") == 23 assert highest_prime_in_list("10,15,22,5,67,100") == 67 assert highest_prime_in_list("8,4,6,12,15") == -1 assert highest_prime_in_list("2,3,5,7,11,13,17,19") == 19 assert highe...
[ { "docstring": "Helper function to check if a number is prime. ", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Returns the highest prime number in the list or -1 if there are no prime numbers. ", "function_declaration...
[ 1, 1, 0 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(n):\n \"\"\"\n Helper function to check if a number is prime.\n Returns True if n is prime, otherwise False.\n \"\"\"\n if n <=...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00028815", "row_id": 28815, "seed_ids": "[8626]" }
0.621378
Code_Contests_28815
I
[ "is_prime", "highest_prime_in_list" ]
2
[ [ "highest_prime_in_list", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
f3a9b946cb93b7d14a6a8645b0fb204a7fb87726
4db2d6abab10ae380361e94ade71019ec746d419
v1.0
instruct
Code_Contests
Code_Contests_28830_I
You are given n strings. For each string, find the length of the longest substring that contains no repeating characters. Input The first line contains an integer n (1 ≤ n ≤ 10^5). Each of the following n lines contains a single string of lowercase English letters (1 ≤ length of string ≤ 10^5). Output For each str...
def length_of_longest_substring(s): """ Returns the length of the longest substring without repeating characters. """ char_map = {} left = 0 max_length = 0 for right in range(len(s)): if s[right] in char_map and char_map[s[right]] >= left: left = char_map[s[right]] +...
from solution import length_of_longest_substring, lengths_of_longest_substrings def test_length_of_longest_substring(): assert length_of_longest_substring("abcabcbb") == 3 assert length_of_longest_substring("bbbbb") == 1 assert length_of_longest_substring("pwwkew") == 3 assert length_of_longest_substri...
[ { "docstring": "Returns the length of the longest substring without repeating characters.", "function_declaration": "def length_of_longest_substring(s):", "function_name": "length_of_longest_substring", "parameter_list": "(s)" }, { "docstring": "Returns the lengths of the longest substrings ...
[ 1, 0, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def length_of_longest_substring(s):\n \"\"\"\n Returns the length of the longest substring without repeating characters in the given string s.\n \...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00028830", "row_id": 28830, "seed_ids": "[6781]" }
0.792646
Code_Contests_28830
I
[ "length_of_longest_substring", "lengths_of_longest_substrings" ]
2
[ [ "lengths_of_longest_substrings", "length_of_longest_substring" ] ]
1
[]
false
[]
false
pytest
true
[]
true
e7c3e56291239f1f893575441e3f67a02c476c0b
a5708811dfbfcab574c52e25b194928b1ccb1f7a
v1.0
instruct
Code_Contests
Code_Contests_28844_I
Write a program to simulate a simple compression and decompression mechanism using a form of run-length encoding for strings composed of uppercase letters only. * encode $s$: Compress the string $s$ using run-length encoding. * decode $s$: Decompress the run-length encoded string $s$ back to its original form. * check...
def encode(s): if not s: return "" n = len(s) encoded_str = [] count = 1 for i in range(1, n): if s[i] == s[i - 1]: count += 1 else: encoded_str.append(f"{count}{s[i - 1]}") count = 1 encoded_str.append(f"{count}{s[-1]}") return ''....
import pytest from solution import encode, decode, check, process_operations def test_encode(): assert encode("AAAABBBCCDA") == "4A3B2C1D1A" assert encode("CCCCDDD") == "4C3D" assert encode("") == "" assert encode("A") == "1A" def test_decode(): assert decode("4A3B2C1D1A") == "AAAABBBCCDA" ass...
[ { "docstring": null, "function_declaration": "def encode(s):", "function_name": "encode", "parameter_list": "(s)" }, { "docstring": null, "function_declaration": "def decode(s):", "function_name": "decode", "parameter_list": "(s)" }, { "docstring": null, "function_dec...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def encode(s):\n \"\"\"\n Encodes the given string using run-length encoding.\n \"\"\"\n if not s:\n return \"\"\n encoded_str = \"\"...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00028844", "row_id": 28844, "seed_ids": "[6456]" }
0.750954
Code_Contests_28844
I
[ "encode", "decode", "check", "process_operations" ]
4
[ [ "process_operations", "check" ], [ "process_operations", "decode" ], [ "process_operations", "encode" ] ]
3
[]
false
[]
false
pytest
true
[]
true
e9cd1592bc75cb4f5536146d00427c4af444ab42
4773cc406e9dd4ca5253b2ab6d1d70e4c4c8ce08
v1.0
instruct
Code_Contests
Code_Contests_28887_I
A group of friends is organizing a relay race in a park. The race track is circular, and there are different checkpoints placed around the track. Each checkpoint has a unique integer identifier. To start the race, the organizers need to determine the starting checkpoint from which the relay race will begin. Each frien...
from itertools import permutations def travel_time(travel_times, route): time = 0 for i in range(len(route)-1): time += travel_times[route[i]][route[i+1]] time += travel_times[route[-1]][route[0]] # return to start return time def find_best_starting_checkpoint(n, travel_times): best_time ...
def test_example(): n = 4 travel_times = [ [0, 10, 15, 20], [10, 0, 35, 25], [15, 35, 0, 30], [20, 25, 30, 0] ] assert find_best_starting_checkpoint(n, travel_times) == 1 def test_single_checkpoint(): n = 1 travel_times = [ [0] ] assert find_best_...
[ { "docstring": null, "function_declaration": "def travel_time(travel_times, route):", "function_name": "travel_time", "parameter_list": "(travel_times, route)" }, { "docstring": null, "function_declaration": "def find_best_starting_checkpoint(n, travel_times):", "function_name": "fin...
[ 0, 0, 0, 0, 1 ]
1
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def tsp_nearest_neighbor(matrix, start):\n n = len(matrix)\n visited = [False] * n\n visited[start] = True\n current = start\n total_time = ...
trial_gpt4o_4
{ "original_instruction": "", "prompt_id": "00028887", "row_id": 28887, "seed_ids": "[6269]" }
0.730921
Code_Contests_28887
I
[ "travel_time", "find_best_starting_checkpoint" ]
2
[ [ "find_best_starting_checkpoint", "travel_time" ] ]
1
[]
false
[]
false
pytest
false
[]
true
e18b1cffb86bd2bee47e8f74958dfaead73b1b53
693bc8ad03df8f62bbdeb9815861e37825e068d3
v1.0
instruct
Code_Contests
Code_Contests_28909_I
Alice enjoys solving numerical puzzles and has found a new interest in special numbers. She defines a special number as a number that becomes 1 after repeatedly replacing it with the sum of the squares of its digits. For example, 19 is a special number because: - 1² + 9² = 82 - 8² + 2² = 68 - 6² + 8² = 100 - 1² + ...
def is_special_number(n): """ Function to determine if a number is a special number. Returns True if the number is a special number, otherwise False. """ def sum_of_squares_of_digits(x): return sum(int(digit) ** 2 for digit in str(x)) seen = set() while n != 1 and n not in seen:...
from solution import is_special_number, special_numbers def test_is_special_number(): assert is_special_number(19) == True assert is_special_number(4) == False assert is_special_number(1) == True assert is_special_number(10) == True assert is_special_number(7) == True assert is_special_number(2...
[ { "docstring": "Function to determine if a number is a special number.\nReturns True if the number is a special number, otherwise False.", "function_declaration": "def is_special_number(n):", "function_name": "is_special_number", "parameter_list": "(n)" }, { "docstring": null, "function_...
[ 0, 0, 0, 0, 1 ]
1
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_special_number(n):\n \"\"\"\n Determines if a number is a special number.\n A number is considered special if it eventually reaches 1 when ...
trial_gpt4o_4
{ "original_instruction": "", "prompt_id": "00028909", "row_id": 28909, "seed_ids": "[8525]" }
0.635478
Code_Contests_28909
I
[ "is_special_number", "special_numbers" ]
2
[ [ "special_numbers", "is_special_number" ] ]
1
[]
false
[]
false
pytest
true
[]
true
7b656f3d84c4d6c1ed01dc00a914a0955e3b99d9
a3e74a2a263348b59934be868fa7cacc0f42e051
v1.0
instruct
Code_Contests
Code_Contests_28925_I
You are developing a game called "Robo Races" where players need to construct racing robots from various components. Each robot is built using a combination of a body, a motor, and a sensor. Each component has a performance score which collectively determines the overall performance score of the robot. The body provi...
def find_best_combination(datasets): results = [] for dataset in datasets: N, M, P, bodies, motors, sensors = dataset max_score = 0 best_combination = () for body in bodies: for motor in motors: for sensor in sensors: body_...
def test_robo_races(): input_data = [ "3 2 3", "body1 80", "body2 60", "body3 70", "motor1 50", "motor2 60", "sensor1 40", "sensor2 45", "sensor3 55", "2 3 2", "frame1 75", "frame2 85", "engine1 45", "eng...
[ { "docstring": null, "function_declaration": "def find_best_combination(datasets):", "function_name": "find_best_combination", "parameter_list": "(datasets)" }, { "docstring": null, "function_declaration": "def parse_input(input_lines):", "function_name": "parse_input", "paramete...
[ 0, 1, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def get_best_combination(components):\n n, m, p = map(int, components[0].split())\n if n == 0 and m == 0 and p == 0:\n return []\n \n bo...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00028925", "row_id": 28925, "seed_ids": "[4265]" }
0.620196
Code_Contests_28925
I
[ "find_best_combination", "parse_input", "robo_races" ]
3
[ [ "robo_races", "find_best_combination" ], [ "robo_races", "parse_input" ] ]
2
[ "parse_input" ]
false
[]
false
pytest
false
[]
true
150790727f013adaea8115599388977b83b4190f
8f04ebf95c87781f7d00060114a8d1ef7285e769
v1.0
instruct
Code_Contests
Code_Contests_28928_I
Ram loves to play with numbers. He recently learned about prime numbers and their interesting properties. Ram wants to test his understanding by solving a challenge. Rani, his friend, decided to help him by giving him an interesting problem to solve. Input: First line contains N and K, where N denotes the number of pr...
def count_primes_in_range(prime_numbers, queries): """ This function takes a list of prime numbers and a list of queries. Each query contains a range [L, R], and the function returns a list of the counts of prime numbers within those ranges. """ results = [] for L, R in queries: cou...
def test_count_primes_in_range(): prime_numbers = [2, 3, 5, 7, 11] queries = [(1, 10), (4, 6), (10, 20)] expected = [4, 1, 1] assert count_primes_in_range(prime_numbers, queries) == expected def test_parse_input(): input_data = "5 3\n2 3 5 7 11\n1 10\n4 6\n10 20\n" prime_numbers, queries = pars...
[ { "docstring": "This function takes a list of prime numbers and a list of queries.\nEach query contains a range [L, R], and the function returns a list of the counts \nof prime numbers within those ranges.", "function_declaration": "def count_primes_in_range(prime_numbers, queries):", "function_name": "...
[ 0, 1, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def count_primes_in_range(primes, queries):\n \"\"\"\n Counts the number of primes within specified ranges for each query.\n \n Parameters:\n ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00028928", "row_id": 28928, "seed_ids": "[7357]" }
0.64629
Code_Contests_28928
I
[ "count_primes_in_range", "parse_input", "prime_count_problem" ]
3
[ [ "prime_count_problem", "count_primes_in_range" ], [ "prime_count_problem", "parse_input" ] ]
2
[ "parse_input" ]
false
[]
false
pytest
false
[]
true
b02096b249c28142ca274c133ad2d1590e424c46
d71449d6f72e219f2beebfb3e7d489acd9cf5061
v1.0
instruct
Code_Contests
Code_Contests_28951_I
A large company wants to optimize its operations by utilizing a company-wide event management system. The system should be capable of managing a wide variety of events, including meetings, product launches, team-building activities, and remote work sessions. Each event has a specified start and end time, and no two eve...
def parse_time(time_str): hours, minutes = map(int, time_str.split(':')) return hours * 60 + minutes def max_non_overlapping_events(events): # Sort events by their end times events.sort(key=lambda x: x[1]) end_time = 0 count = 0 for start, end in events: if start >= end_ti...
def test_parse_time(): assert parse_time("09:00") == 540 assert parse_time("10:00") == 600 assert parse_time("10:30") == 630 def test_max_non_overlapping_events(): assert max_non_overlapping_events([(540, 630), (600, 660), (630, 720), (780, 840), (690, 750)]) == 3 assert max_non_overlapping_events(...
[ { "docstring": null, "function_declaration": "def parse_time(time_str):", "function_name": "parse_time", "parameter_list": "(time_str)" }, { "docstring": null, "function_declaration": "def max_non_overlapping_events(events):", "function_name": "max_non_overlapping_events", "param...
[ 1, 1, 0 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def convert_to_minutes(time_str):\n \"\"\"\n Converts a time string in HH:MM format to minutes past midnight.\n \"\"\"\n hours, minutes = map(i...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00028951", "row_id": 28951, "seed_ids": "[10090]" }
0.654351
Code_Contests_28951
I
[ "parse_time", "max_non_overlapping_events", "process_input" ]
3
[ [ "process_input", "max_non_overlapping_events" ], [ "process_input", "parse_time" ] ]
2
[ "process_input" ]
false
[]
false
pytest
false
[]
true
3e74518b9fe20070ba3092cad6492eb42f71592a
cff9465f81253c0c487b156ed0ae5ab0e3f6ce95
v1.0
instruct
Code_Contests
Code_Contests_28953_I
You are working for Fireworks Organization Inc., which is planning a massive fireworks display on New Year's Eve. The fireworks will be launched from platforms arranged in a large grid. Each platform will launch a firework that explodes at a certain height and is visible from afar. Your task is to determine the maximum...
def max_visible_fireworks(grid): N = len(grid) directions = [(1, 0), (0, 1), (1, 1), (-1, 1)] def is_valid(x, y): return 0 <= x < N and 0 <= y < N def dfs(x, y, visited): if (x, y) in visited: return visited.add((x, y)) for dx, dy in directi...
from solution import max_visible_fireworks, process_input, fireworks_organization def test_max_visible_fireworks(): assert max_visible_fireworks([ [3, 1, 4], [1, 5, 9], [2, 6, 5] ]) == 5 assert max_visible_fireworks([ [10, 20, 30, 40], [50, 60, 70, 80], [90,...
[ { "docstring": null, "function_declaration": "def max_visible_fireworks(grid):", "function_name": "max_visible_fireworks", "parameter_list": "(grid)" }, { "docstring": null, "function_declaration": "def process_input(input_data):", "function_name": "process_input", "parameter_lis...
[ 1, 0, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def max_visible_fireworks(grid):\n N = len(grid)\n directions = [(1, 0), (0, 1), (1, 1), (-1, 1)]\n \n def is_valid(x, y):\n return 0 <=...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00028953", "row_id": 28953, "seed_ids": "[2077]" }
0.643543
Code_Contests_28953
I
[ "max_visible_fireworks", "process_input", "fireworks_organization" ]
3
[ [ "fireworks_organization", "process_input" ], [ "process_input", "max_visible_fireworks" ] ]
2
[ "process_input" ]
false
[]
false
pytest
true
[]
true
5ddc49d664fb0204cba6cb127fb81a0217c71e00
17175e465b9c60375ab78aea26eae0d049810815
v1.0
instruct
Code_Contests
Code_Contests_28954_I
Write a Python script that accepts a directory path as an argument and generates a JSON file containing the following information for each file in the directory: 1. The file name 2. The size of the file in bytes 3. The creation time of the file in UNIX timestamp format 4. The last access time of the file in UNIX times...
import os import json import time from typing import List, Dict def get_file_info(directory: str) -> List[Dict]: file_info_list = [] for filename in os.listdir(directory): file_path = os.path.join(directory, filename) if os.path.isfile(file_path): file_stats = os.stat(file_path) ...
import os import json import time import pytest from solution import generate_directory_summary def setup_test_directory(tmpdir): test_data = [ ("file1.txt", 100), ("file2.txt", 200), ] for filename, size in test_data: file_path = tmpdir.join(filename) with open(file_path, "...
[ { "docstring": null, "function_declaration": "def get_file_info(directory):", "function_name": "get_file_info", "parameter_list": "(directory)" }, { "docstring": null, "function_declaration": "def generate_directory_summary(directory):", "function_name": "generate_directory_summary",...
[ 0, 0, 0, 1, 0 ]
1
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "import os\nimport json\nfrom pathlib import Path\n\ndef generate_directory_summary(directory_path):\n \"\"\"\n Generates a JSON file containing summa...
trial_gpt4o_3
{ "original_instruction": "", "prompt_id": "00028954", "row_id": 28954, "seed_ids": "[5591]" }
0.733729
Code_Contests_28954
I
[ "get_file_info", "generate_directory_summary" ]
2
[ [ "generate_directory_summary", "get_file_info" ] ]
1
[]
false
[]
false
pytest
true
[]
true
e9526d6a66aba961ce9eabafac364364fb3a7148
188a99ded9379a6ac1bbfe17e109b3b70e4857a0
v1.0
instruct
Code_Contests
Code_Contests_28961_I
The "Railway Department" has a network of n cities connected by m railway tracks. Each railway track connects two distinct cities and has a certain travel cost. The travel cost between cities can vary depending on the railway track. The Railway Department is planning to hold a major event in one of the cities, and th...
import heapq import sys def dijkstra(graph, start, n): """ Performs Dijkstra's algorithm to find the shortest paths from start to all other nodes. """ distances = [sys.maxsize] * (n + 1) distances[start] = 0 pq = [(0, start)] while pq: current_distance, current_vertex = heapq.h...
from solution import find_optimal_city def test_example_1(): n = 4 m = 4 tracks = [ (1, 2, 4), (2, 3, 1), (3, 4, 2), (4, 1, 5) ] assert find_optimal_city(n, m, tracks) == 2 def test_example_2(): n = 3 m = 3 tracks = [ (1, 2, 3), (2, 3, 1)...
[ { "docstring": "Performs Dijkstra's algorithm to find the shortest paths from start to all other nodes.", "function_declaration": "def dijkstra(graph, start, n):", "function_name": "dijkstra", "parameter_list": "(graph, start, n)" }, { "docstring": null, "function_declaration": "def find...
[ 1, 0, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "import heapq\nimport sys\n\ndef dijkstra(graph, start, n):\n \"\"\"\n Performs Dijkstra's algorithm to find the shortest paths from start to all othe...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00028961", "row_id": 28961, "seed_ids": "[2122]" }
0.757901
Code_Contests_28961
I
[ "dijkstra", "find_optimal_city" ]
2
[ [ "find_optimal_city", "dijkstra" ] ]
1
[]
false
[]
false
pytest
true
[]
true
b97e892368b22238ba064c27be81a688a64da8d4
922a5ef1e1f64d8e5aba4ea552b2126e847049ec
v1.0
instruct
Code_Contests
Code_Contests_28971_I
You are given a collection of text strings. For each text string, determine whether it is a palindrome or not. A palindrome is a word, phrase, or sequence of characters that reads the same backward as forward, ignoring case, spaces, and punctuation. Input The first line contains a single positive integer, n (1 ≤ n ≤ ...
import re def is_palindrome(s): """ Returns 'YES' if the string s is a palindrome, otherwise returns 'NO'. """ # Remove non-alphanumeric characters and convert to lowercase cleaned = re.sub(r'[^A-Za-z0-9]', '', s).lower() # Check if the cleaned string is a palindrome return "YES" if cleaned...
from solution import is_palindrome, check_palindromes def test_is_palindrome(): assert is_palindrome("A man a plan a canal Panama") == "YES" assert is_palindrome("Hello, World!") == "NO" assert is_palindrome("Was it a car or a cat I saw?") == "YES" assert is_palindrome("Madam In Eden, I'm Adam") == "YE...
[ { "docstring": "Returns 'YES' if the string s is a palindrome, otherwise returns 'NO'.", "function_declaration": "def is_palindrome(s):", "function_name": "is_palindrome", "parameter_list": "(s)" }, { "docstring": "Check each of the n strings to determine if they are palindromes.", "func...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "import re\n\ndef is_palindrome(text):\n \"\"\"\n Returns 'YES' if the provided text is a palindrome, 'NO' otherwise.\n \"\"\"\n # Remove non-al...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00028971", "row_id": 28971, "seed_ids": "[8677]" }
0.805469
Code_Contests_28971
I
[ "is_palindrome", "check_palindromes" ]
2
[ [ "check_palindromes", "is_palindrome" ] ]
1
[]
false
[]
false
pytest
true
[]
true
201e7e38374ff2d528d22f8b99b78fbcdd1f95b9
bcf9aa8d137c504ade8911121fc54dda2356aeea
v1.0
instruct
Code_Contests
Code_Contests_29097_I
Obi, a professional snowplow operator, is working tirelessly to clear the streets after a recent snowstorm. Each of the n streets he needs to clear is represented as a line segment on a 2D Cartesian plane, and each street can be described by its endpoints (x1, y1) and (x2, y2). Obi wants to know the total length of all...
from math import sqrt def calculate_distance(x1, y1, x2, y2): """ Calculates the Euclidean distance between two points (x1, y1) and (x2, y2) """ return sqrt((x2 - x1) ** 2 + (y2 - y1) ** 2) def union_line_segments(segments): """ Function to calculate the union of 2D line segments and return th...
from solution import total_street_length def test_single_street(): assert total_street_length(1, [(0, 0, 4, 3)]) == 5.0 # Length of single segment (0,0) to (4,3) def test_no_overlap(): assert total_street_length(2, [(0, 0, 3, 0), (4, 0, 5, 0)]) == 4.0 # Lengths add directly: 3 + 1 def test_partial_overlap(...
[ { "docstring": "Calculates the Euclidean distance between two points (x1, y1) and (x2, y2)", "function_declaration": "def calculate_distance(x1, y1, x2, y2):", "function_name": "calculate_distance", "parameter_list": "(x1, y1, x2, y2)" }, { "docstring": "Function to calculate the union of 2D...
[ 0, 0, 0, 0, 0, 1, 0, 0, 0, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "import math\nfrom typing import List, Tuple\n\nclass LineSegment:\n def __init__(self, x1, y1, x2, y2):\n self.x1, self.y1, self.x2, self.y2 = x1...
trial_gpt4o_5
{ "original_instruction": "", "prompt_id": "00029097", "row_id": 29097, "seed_ids": "[12632]" }
0.679225
Code_Contests_29097
I
[ "calculate_distance", "union_line_segments", "total_street_length" ]
3
[ [ "total_street_length", "union_line_segments" ], [ "union_line_segments", "calculate_distance" ] ]
2
[]
false
[]
false
pytest
true
[]
true
5f2758ef63eb792fafcc9d30237728d9e8955bbd
638b60649aa65ec7367bfc3d1fdb7c129726fed1
v1.0
instruct
Code_Contests
Code_Contests_29128_I
The editor of the university's magazine is working on a new classifieds section. They have noticed that many people post similar advertisements multiple times, which overcrowds the section. To prevent this, the editor needs a tool that checks for duplicate advertisements. Your task is to implement a function that will...
from typing import List def normalize_ad(ad: str) -> str: # Normalize by sorting words words = ad.split() words.sort() return " ".join(words) def detect_duplicates(ads: List[str]) -> List[int]: seen_ads = {} duplicates = [-1] * len(ads) for i, ad in enumerate(ads): normalized_...
from solution import detect_duplicates def test_no_duplicates(): ads = ["Buy milk", "Sell car", "Find job"] assert detect_duplicates(ads) == [-1, -1, -1] def test_simple_duplicates(): ads = ["Buy milk", "milk Buy"] assert detect_duplicates(ads) == [-1, 0] def test_multiple_duplicates(): ads = ["B...
[ { "docstring": null, "function_declaration": "def normalize_ad(ad):", "function_name": "normalize_ad", "parameter_list": "(ad)" }, { "docstring": null, "function_declaration": "def detect_duplicates(ads):", "function_name": "detect_duplicates", "parameter_list": "(ads)" } ]
[ 1, 0, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "from typing import List\n\ndef normalize_ad(ad: str) -> str:\n # Normalize by sorting words\n words = ad.split()\n words.sort()\n return \" \"....
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00029128", "row_id": 29128, "seed_ids": "[10647]" }
0.556212
Code_Contests_29128
I
[ "normalize_ad", "detect_duplicates" ]
2
[ [ "detect_duplicates", "normalize_ad" ] ]
1
[]
false
[]
false
pytest
true
[]
true
53c1906d0aea88521bfe38430ab582b4d31440c0
f71ba55b68d2d27ed7e359b2474c903334a3b462
v1.0
instruct
Code_Contests
Code_Contests_29135_I
Jane has a string s consisting of lowercase English letters. She wants to reorder the characters of the string so that no two adjacent characters are the same. Your task is to help Jane find any such reordering of the string, or determine that it is impossible to achieve. Input The first line contains a single intege...
from collections import Counter import heapq def rearrange_string(s): """ Rearranges the string such that no two adjacent characters are the same. If it's not possible, returns "IMPOSSIBLE". """ # Count the frequencies of each character freq = Counter(s) # Create a max heap based on fr...
from solution import jane_reorder_string def test_jane_reorder_string_possible(): assert jane_reorder_string(4, "aabb") in ["abab", "baba"] def test_jane_reorder_string_impossible(): assert jane_reorder_string(2, "aa") == "IMPOSSIBLE" def test_jane_reorder_string_single_letter(): assert jane_reorder_stri...
[ { "docstring": "Rearranges the string such that no two adjacent characters are the same.\nIf it's not possible, returns \"IMPOSSIBLE\".", "function_declaration": "def rearrange_string(s):", "function_name": "rearrange_string", "parameter_list": "(s)" }, { "docstring": null, "function_dec...
[ 1, 0, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "from collections import Counter\nimport heapq\n\ndef rearrange_string(s):\n \"\"\"\n Rearranges the string such that no two adjacent characters are t...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00029135", "row_id": 29135, "seed_ids": "[3449]" }
0.782917
Code_Contests_29135
I
[ "rearrange_string", "jane_reorder_string" ]
2
[ [ "jane_reorder_string", "rearrange_string" ] ]
1
[]
false
[]
false
pytest
true
[]
true
c7aa1b40810441c79c49826847a3b08c9e74fb3e
cdc2d55df8063cde501f1b09a91e559b3e047b4c
v1.0
instruct
Code_Contests
Code_Contests_29142_I
A king needs to find a way to equally distribute gold coins kept in a stack of boxes among his four daughters. His daughters will only accept the coins if they are distributed such that each daughter gets the same number of interesting gold coins. A gold coin is considered interesting if its value is a prime number. Ea...
def is_prime(n): if n <= 1: return False if n <= 3: return True if n % 2 == 0 or n % 3 == 0: return False i = 5 while i * i <= n: if n % i == 0 or n % (i + 2) == 0: return False i += 6 return True def can_distribute_gold_coins_equally(t, test_...
from solution import is_prime, can_distribute_gold_coins_equally def test_is_prime(): assert is_prime(2) == True assert is_prime(3) == True assert is_prime(4) == False assert is_prime(5) == True assert is_prime(10) == False assert is_prime(11) == True def test_can_distribute_gold_coins_equally...
[ { "docstring": null, "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": null, "function_declaration": "def can_distribute_gold_coins_equally(t, test_cases):", "function_name": "can_distribute_gold_coins_equally", "pa...
[ 0, 0, 0, 1, 0 ]
1
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_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 ...
trial_gpt4o_3
{ "original_instruction": "", "prompt_id": "00029142", "row_id": 29142, "seed_ids": "[279]" }
0.606238
Code_Contests_29142
I
[ "is_prime", "can_distribute_gold_coins_equally" ]
2
[ [ "can_distribute_gold_coins_equally", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
f6a320dee1a6a428fd0fd0f3bfeadc6d713104c7
221f0b1e9e91b3128c482ae128ee63f3a7d44565
v1.0
instruct
Code_Contests
Code_Contests_29167_I
Your friend is organizing a hiking adventure along a series of trails in the mountains. The hiking trails are connected and form a graph that is a tree. A tree is a connected, undirected graph with no cycles. There are n junctions (numbered from 1 to n) connected by n-1 trails. Each trail connects two junctions, and e...
from collections import deque, defaultdict def find_furthest_node(n, start_node, graph): """ Performs BFS to find the furthest node from the start_node. """ max_dist = 0 furthest_node = start_node queue = deque([(start_node, 0)]) visited = set([start_node]) while queue: node, dist ...
def test_simple_case(): input_string = '7\n1 2\n2 3\n2 4\n4 5\n5 6\n5 7\n' assert hiking_adventure(input_string) == 4 def test_small_tree(): input_string = '3\n1 2\n2 3\n' assert hiking_adventure(input_string) == 2 def test_direct_chain(): input_string = '4\n1 2\n2 3\n3 4\n' assert hiking_adve...
[ { "docstring": "Performs BFS to find the furthest node from the start_node. ", "function_declaration": "def find_furthest_node(n, start_node, graph):", "function_name": "find_furthest_node", "parameter_list": "(n, start_node, graph)" }, { "docstring": "BFS starting from start_node to get dis...
[ 1, 0, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "from collections import deque, defaultdict\n\ndef find_furthest_node(n, start_node, graph):\n \"\"\" Performs BFS to find the furthest node from the sta...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00029167", "row_id": 29167, "seed_ids": "[11449]" }
0.686489
Code_Contests_29167
I
[ "find_furthest_node", "bfs_to_get_distances", "find_special_junction", "hiking_adventure" ]
4
[ [ "find_special_junction", "bfs_to_get_distances" ], [ "find_special_junction", "find_furthest_node" ], [ "hiking_adventure", "find_special_junction" ] ]
3
[]
false
[]
false
pytest
false
[]
true
e6162300e03c4cb55a7f2e4c095459c5d92db4b0
5972907ff93d04714b20ae75f16133be061553f5