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 | complete | Code_Contests | Code_Contests_25999_C | from typing import List, Tuple
def find_max_sum_path(N: int, nodes: List[Tuple[int, int, int]]) -> List[int]:
""" 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 smallest when viewed ... | 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": "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 th... | 0.679909 | Code_Contests_25999 | C | [
"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 | 72192a437f5d42341d98770fec5997ab3c7fc67b | dadf3d87a03616b69cd4b2897a22b7803e4233c8 | |||
v1.0 | complete | Code_Contests | Code_Contests_27121_C | def is_palindrome(s: str) -> bool:
"""
Check if the given string s is a palindrome.
>>> is_palindrome("Was it a car or a cat I saw")
True
>>> is_palindrome("Hello, World!")
False
"""
pass
def check_palindromes(input_lines: List[str]) -> List[str]:
"""
Given a list of input strin... | 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": "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 o... | 0.888191 | Code_Contests_27121 | C | [
"is_palindrome",
"check_palindromes"
] | 2 | [
[
"check_palindromes",
"is_palindrome"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | af41773bed8b396f086f16429f4cdfb7b6e75409 | 2a8e28e0935ad40b8d0b9f9c3c1254e2aebf7073 | |||
v1.0 | complete | Code_Contests | Code_Contests_26890_C | def min_swaps_to_sort(arr: List[int]) -> int:
"""
Given the initial sequence of power levels of the wizards, determine the minimum number of swaps required to arrange
the wizards in non-decreasing order.
>>> min_swaps_to_sort([5, 4, 3, 2, 1])
10
>>> min_swaps_to_sort([1, 5, 3, 2, 4])
4... | 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": "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 le... | 0.585387 | Code_Contests_26890 | C | [
"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 | 87b5159c80fd8a6221123303c654b9cf1ddbc13d | 698399cb5ea2da6da1c45b7b93399ff89bb29bf5 | |||
v1.0 | complete | Code_Contests | Code_Contests_27433_C | import math
from typing import List
def is_prime(n: int) -> bool:
"""
Returns True if n is a prime number, else False.
"""
def is_palindrome(n: int) -> bool:
"""
Returns True if n is a palindrome, else False.
"""
def next_palindromic_prime(n: int) -> int:
"""
Returns the next palindro... | 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": "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... | 0.678388 | Code_Contests_27433 | C | [
"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 | 5a027ed728041f5428b564d82df9ef40c7d8b7f7 | 490cde10ff3a620b0393edfaca3d574e423e36b5 | |||
v1.0 | complete | Code_Contests | Code_Contests_27043_C | def is_prime(number: int) -> bool:
"""
Check if a number is a prime number.
>>> is_prime(2)
True
>>> is_prime(3)
True
>>> is_prime(4)
False
>>> is_prime(5)
True
>>> is_prime(11)
True
>>> is_prime(16)
False
"""
pass
def sum_of_digits(n: int) -> int:
""... | 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": "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 ... | 0.753064 | Code_Contests_27043 | C | [
"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 | 362c6b78a3b0909358f3df3886e31643c73aa22b | 1e47535f1de226fad4d1e42e57aa59d50425e987 | |||
v1.0 | complete | Code_Contests | Code_Contests_27092_C | from typing import List, Tuple
def dijkstra(graph, start, end, get_weight):
...
def shortest_paths(n: int, m: int, connections: List[Tuple[int, int, int, int, int]], queries: List[Tuple[int, int]]) -> List[str]:
"""Determine the shortest paths between devices in a network with variable weights.
Args:
... | 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": "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.\n\nDue to certain ... | 0.670592 | Code_Contests_27092 | C | [
"dijkstra",
"shortest_paths",
"process_input"
] | 3 | [
[
"process_input",
"shortest_paths"
],
[
"shortest_paths",
"dijkstra"
]
] | 2 | [
"process_input"
] | false | [] | false | pytest | false | [] | true | 7d28a421eab5b23fffcd7969c657aba30afa0e70 | e873aeb85d03e3ddbb682107c5fdd7e0b9054506 | |||
v1.0 | complete | Code_Contests | Code_Contests_27307_C | def fill_puzzle(grid, N):
""" Fill the given N x N grid with numbers from 1 to N according to the given rules, or determine if it's impossible.
>>> fill_puzzle([[1, 0, 3], [0, 0, 0], [2, 3, 0]], 3)
1 2 3
3 1 2
2 3 1
>>> fill_puzzle([[1, 2, 0], [2, 3, 1], [0, 1, 2]], 3)
NO SOLUTION
"""
... | 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": "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.\n\nThe grid is an N x N matrix. Each cell in the grid can be filled with a number from 1 t... | 0.5931 | Code_Contests_27307 | C | [
"is_safe",
"solve_grid",
"fill_puzzle"
] | 3 | [
[
"fill_puzzle",
"solve_grid"
],
[
"solve_grid",
"is_safe"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 9ae8e8824ffa2487490efd857c75fee46cd320b7 | 237ee238b4779a75a10e371a7395d9636159ac02 | |||
v1.0 | complete | Code_Contests | Code_Contests_26150_C | def polycarp_subarray_problem(n: int, m: int, k: int, arr: List[int]) -> List[Union[str, List[int]]]:
"""
Determine if it's possible to make the length of the largest contiguous subarray
consisting of equal integers at least k by changing at most m elements.
Parameters:
n (int): Length of the arra... | 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": "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.... | 0.614468 | Code_Contests_26150 | C | [
"find_subarray",
"polycarp_subarray_problem"
] | 2 | [
[
"polycarp_subarray_problem",
"find_subarray"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 8ae50fbe1ff1f6e59a0ecdb260fe2bdc7a68d64f | 174ecbd30319a85275655c40a168481fb6fa5f69 | |||
v1.0 | complete | Code_Contests | Code_Contests_27198_C | def solution(T, cases):
"""
Determines whether it is possible to complete the project given the availability
of the members. If it is possible, the function outputs all possible sets of intervals
for each member that sum to the task requirement (8 hours). If it is not possible,
output "Not possi... | 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": "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 ... | 0.634653 | Code_Contests_27198 | C | [
"can_form_eight_hours",
"solve",
"solution"
] | 3 | [
[
"solution",
"solve"
],
[
"solve",
"can_form_eight_hours"
]
] | 2 | [] | false | [] | false | pytest | false | [] | true | 7d58263a18948842a0df9955f1db67ef908b1b14 | 3e55bedd08165ac2d27ee2039b9b42ef3c35acaa | |||
v1.0 | complete | Code_Contests | Code_Contests_27208_C | def harvest_order(t: int, test_cases: List[Tuple[int, List[Tuple[int, int]]]]) -> List[List[Tuple[int, int]]]:
""" Identify the order in which the fruits should be harvested to maximize the magical power they absorb from the environment.
>>> harvest_order(2, [(3, [(1, 2), (3, 1), (2, 2)]), (4, [(-1, -1), (2, 2)... | 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": "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 ha... | 0.58947 | Code_Contests_27208 | C | [
"euclidean_distance",
"harvest_order"
] | 2 | [
[
"harvest_order",
"euclidean_distance"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 84d27b5b7f2de85ee1d93eef9b1d1ea0455757c4 | b9b22a2eee06981e4902eba925a86f7475ed98ed | |||
v1.0 | complete | Code_Contests | Code_Contests_26962_C | def is_palindrome(num: int) -> bool:
"""Checks if a number is a palindrome.
>>> is_palindrome(121)
True
>>> is_palindrome(12321)
True
>>> is_palindrome(123)
False
>>> is_palindrome(45654)
True
>>> is_palindrome(1221)
True
>>> is_palindrome(12345)
False
"""
pas... | 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": "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.\n\nFor t... | 0.82052 | Code_Contests_26962 | C | [
"is_palindrome",
"check_palindromes"
] | 2 | [
[
"check_palindromes",
"is_palindrome"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | f6dee21812707122afe280f546fbaeb3e2ec4541 | bcfe7eb681c3d2cba3bd58edc8005ea53f81843c | |||
v1.0 | complete | Code_Contests | Code_Contests_27162_C | def lcs(str1: str, str2: str) -> int:
"""
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... | 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": "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.\n\n**Input:**\n- Two strings `str1` and... | 0.663606 | Code_Contests_27162 | C | [
"lcs",
"shortest_common_supersequence_length"
] | 2 | [
[
"shortest_common_supersequence_length",
"lcs"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | bc73f473bf51988bf895ae590d025d58be7db6ca | e49512cc6e8503400581aaf36b262f6eb88e1146 | |||
v1.0 | complete | Code_Contests | Code_Contests_27511_C | def is_prime(num):
"""
Helper function to check if a number is prime.
"""
pass
def find_primes(numbers):
"""
Returns a list of prime numbers from the given list of integers.
If no prime numbers are found, returns "No primes".
"""
pass
# Example Test Cases
def test_is_prime():
a... | 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": "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.\n\n\nInput\n\nThe input is given in the... | 0.850744 | Code_Contests_27511 | C | [
"is_prime",
"find_primes"
] | 2 | [
[
"find_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | a079cdb51be93afbeae6dbf2408cc6492a2bca67 | 4cbe5bc441416561feb9346462fe32d64b0c47e1 | |||
v1.0 | complete | Code_Contests | Code_Contests_27491_C | def minimum_cost_to_connect_villages(N: int, M: int, roads: List[Tuple[int, int, int]]) -> int:
""" Determine the minimum cost to connect all the villages with the given roads.
Args:
N: int - Number of villages.
M: int - Number of roads.
roads: List[Tuple[int, int, int]] - List of roads, where ... | 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": "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.\n\nThe king of this land wants to construct a road network to ensure that all villages are connected with the ... | 0.665858 | Code_Contests_27491 | C | [
"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 | 688122b7cd162d1f0d7b931376f870fd22af76e7 | d6af27429532ccf50e5ebc5f8f80ef4a3b6b5179 | |||
v1.0 | complete | Code_Contests | Code_Contests_27331_C | import itertools
import math
from typing import List, Tuple
def calculate_distance(p1: Tuple[int, int], p2: Tuple[int, int]) -> float:
"""
Calculate the Euclidean distance between two points p1 and p2.
"""
pass
def total_distance(route: List[Tuple[int, int]]) -> float:
"""
Calculate the tota... | 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": "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 ... | 0.666503 | Code_Contests_27331 | C | [
"calculate_distance",
"total_distance",
"find_min_route"
] | 3 | [
[
"find_min_route",
"total_distance"
],
[
"total_distance",
"calculate_distance"
]
] | 2 | [] | false | [] | false | pytest | false | [] | true | aa627a9dd30675b9b1197948a1e3e0cf0168e6e3 | 6a76af6ac4285fd57b775e88604f7195253057ad | |||
v1.0 | complete | Code_Contests | Code_Contests_25961_C | def max_cities_to_visit(n, m, T, visit_times, roads):
"""
Determine the maximum number of unique cities John and his friends can visit within the given time limit.
Parameters:
n (int): Number of cities.
m (int): Number of direct roads.
T (int): Maximum time for the trip.
... | 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": "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.\n\nEach city i requires ti hours to visit. Additionally, travelling between certain pairs of cities requires some travel time. Specifica... | 0.698899 | Code_Contests_25961 | C | [
"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 | 5fc6fae13bf3a5e6c8b9437e538883493ca70836 | a9984f914decbe870dc1bcb98f309008e33f4857 | |||
v1.0 | complete | Code_Contests | Code_Contests_27093_C | from typing import List, Tuple
def subset_product_perfect_square(T: int, test_cases: List[Tuple[int, List[int]]]) -> List[str]:
""" 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.
Args:
T : int : th... | 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": "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.\n\nInput:\nThe first line contains an integer T, the number of test cases.\nEach test case consists of two lines: \n- The first line contains a sin... | 0.612387 | Code_Contests_27093 | C | [
"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 | c7745b9165606cca62770bb80eba6db6ac4fc945 | 02644ec16c41b3d43947460fb52a81da8d9d452a | |||
v1.0 | complete | Code_Contests | Code_Contests_28063_C | def count_palindromic_numbers(a: int, b: int) -> int:
""" Returns the count of palindromic numbers in the inclusive range [a, b].
>>> count_palindromic_numbers(1, 10)
9
>>> count_palindromic_numbers(100, 200)
10
>>> count_palindromic_numbers(10, 20)
1
>>> count_palindromic_numbers(0, 10)... | 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": "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.\n\nWrite a... | 0.764218 | Code_Contests_28063 | C | [
"is_palindrome",
"count_palindromic_numbers"
] | 2 | [
[
"count_palindromic_numbers",
"is_palindrome"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | f973738ea20e940c406415c66b582d940cb564c5 | 116c2961cef38691ad3661498380f9f1c1dbad86 | |||
v1.0 | complete | Code_Contests | Code_Contests_26234_C | from typing import List, Tuple
def query_results(n: int, q: int, array: List[int], queries: List[Tuple[int, int, int]]) -> List[str]:
"""
Determine if there is at least one integer within the subarray from index x to index y (inclusive) that is divisible by k.
Args:
n (int): The number of elements in... | 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": "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 divisibl... | 0.60964 | Code_Contests_26234 | C | [
"query_results",
"execute"
] | 2 | [
[
"execute",
"query_results"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 977dcd96e9f9a638ef07a40cbb79e62e3871a513 | 3aff4c1874b8d2d9cb4f6c7ad978ed071757a989 | |||
v1.0 | complete | Code_Contests | Code_Contests_26452_C | def calculate_final_balance(transactions: List[str]) -> int:
"""Calculate the final balance after applying all transactions.
Args:
transactions (List[str]): List of transactions in the form "ID TYPE AMOUNT".
Returns:
int: The final account balance.
>>> calculate_final_balance(["T1... | 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": "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 trans... | 0.532089 | Code_Contests_26452 | C | [
"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 | 42a14d9c3361d83083b2b144f4f9ac238bc05d92 | fff787ad5e28adacfca580001b1174c4924b4663 | |||
v1.0 | complete | Code_Contests | Code_Contests_28002_C | from typing import List
def find_shortest_path(m: int, n: int, grid_input: str) -> int:
""" Determine the length of the shortest path in a grid from the top-left corner to the bottom-right corner.
>>> find_shortest_path(3, 3, '...\n.#.\n...') == 4
>>> find_shortest_path(3, 3, '.#.\n##.\n...') == -1
>>>... | 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": "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... | 0.692151 | Code_Contests_28002 | C | [
"shortest_path",
"find_shortest_path"
] | 2 | [
[
"find_shortest_path",
"shortest_path"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | ccd71346fd6495fe65b803fd56fd9818b0293887 | 23259d59c21465f23c646bc0a2e3d3680fae2379 | |||
v1.0 | complete | Code_Contests | Code_Contests_27770_C | def maximal_rectangle(matrix):
""" 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.
>>> maximal_rectangle([
... [1, 0, 1, 0],
... [1, 0, 1, 1],
... [1, 0, 1, 1],
... [1, 1, 1, 1] ])
6
>>> maximal_re... | 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": "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.\n\nYou need to solve the problem using dynamic programming and optimize the solution efficiently for large inputs.\n\nInput\nThe first line of the input contains two in... | 0.735147 | Code_Contests_27770 | C | [
"maximal_rectangle",
"largest_rectangle_area"
] | 2 | [
[
"maximal_rectangle",
"largest_rectangle_area"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 97f9bc9c772af17f91e22c037b6fb796cf862825 | af2141dd188f9008b187afc316acad11b5123447 | |||
v1.0 | complete | Code_Contests | Code_Contests_27972_C | def min_additional_connections(n, m, connections):
"""
Determine the minimum number of additional direct connections
necessary to make the network fully connected.
Args:
n : int : number of computers
m : int : number of direct connections
connections : list of tuple : list of tuples wh... | 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": "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... | 0.618537 | Code_Contests_27972 | C | [
"find",
"union",
"min_additional_connections"
] | 3 | [
[
"min_additional_connections",
"find"
],
[
"min_additional_connections",
"union"
],
[
"union",
"find"
]
] | 3 | [] | false | [] | false | pytest | false | [] | true | 22c8a83c3959b6eb09cc3ff77aa778f3de24829d | f098579799bca6d977f113bf6fee8e504cffae6c | |||
v1.0 | complete | Code_Contests | Code_Contests_27451_C | from typing import List, Tuple
def preprocess_array(arr: List[int]) -> List[int]:
""" Preprocess the array to create a prefix sum array for efficient range queries.
>>> preprocess_array([1, 2, 3, 4, 5])
[0, 1, 3, 6, 10, 15]
>>> preprocess_array([-1, 2, -3, 4, -5])
[0, -1, 1, -2, 2, -3]
"""... | 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": "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 efficientl... | 0.621396 | Code_Contests_27451 | C | [
"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 | 8f3c363cd5a59c19772f5dd816e5806d55f66296 | 4faac10fb91d4665c851c9b01fbe1405392eb77b | |||
v1.0 | complete | Code_Contests | Code_Contests_26695_C | def min_cost_to_connect_all_cities(input_str: str) -> str:
""" Determines the minimum cost to connect all the cities in the kingdom of Vertlandia.
Args:
input_str (str): The input string representing multiple datasets. Each dataset begins with two integers n and m,
where n is the number of citie... | 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": "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.\n\nThe king wants to ensure that all the cities are connected with... | 0.714856 | Code_Contests_26695 | C | [
"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 | 84e5a5d9ce23a3e3690b878ff444076b41edf732 | 024f2bfdfce05942b29cde1e898f64494fd930d7 | |||
v1.0 | complete | Code_Contests | Code_Contests_27195_C | def minimum_cost_to_connect_islands(n: int, m: int, islands: List[Tuple[int, str]], bridges: List[Tuple[int, int, int]]) -> int:
""" Ensure that all Atlantis and Lemuria islands remain connected via the minimum cost of bridge construction.
>>> minimum_cost_to_connect_islands(
... 6,
... 7,
... | 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": "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, a... | 0.770316 | Code_Contests_27195 | C | [
"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 | 6ac8b3673511f8bdc04a537493b33fe8f3432d1f | 0ff1d6073a2cd957b48ee441d1e244309e575961 | |||
v1.0 | complete | Code_Contests | Code_Contests_25311_C | def minimum_travel_time(n: int, m: int, roads: List[Tuple[int, int, int]]) -> int:
"""
Calculate the minimum total travel time required to ensure that all towns are reachable from the capital.
Parameters:
n (int): The number of towns.
m (int): The number of roads.
roads (List[Tuple[int, in... | def find(parent, i):
if parent[i] == i:
return i
else:
return find(parent, parent[i])
def union(parent, rank, x, y):
xroot = find(parent, x)
yroot = find(parent, y)
if rank[xroot] < rank[yroot]:
parent[xroot] = yroot
elif rank[xroot] > rank[yroot]:
p... | import pytest
from solution import minimum_travel_time
def test_minimum_travel_time_example():
n = 4
m = 5
roads = [
(1, 2, 1),
(2, 3, 2),
(3, 4, 2),
(1, 3, 2),
(1, 4, 3)
]
assert minimum_travel_time(n, m, roads) == 5
def test_minimum_travel_time_single_road... | [
{
"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 \ndef union(parent, rank, x, y):... | trial_gpt4o_0 | {
"original_instruction": "The kingdom of Astoria has a network of N towns connected by M bidirectional roads. Each road connects exactly two towns and different roads can connect the same pair of towns. Schedules for travelling on each road are precisely maintained. The king wants to arrange messengers who can disse... | 0.67477 | Code_Contests_25311 | C | [
"find",
"union",
"kruskal",
"minimum_travel_time"
] | 4 | [
[
"kruskal",
"find"
],
[
"kruskal",
"union"
],
[
"minimum_travel_time",
"kruskal"
],
[
"union",
"find"
]
] | 4 | [] | false | [] | false | pytest | true | [] | true | 52fd04dd91436db4bc079031872817a8e48fca48 | de09c1de14eb068b5e3e12957293db63fd3cab5d | |||
v1.0 | complete | Code_Contests | Code_Contests_27031_C | 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)
inorder_in... | 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": "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. ... | 0.530617 | Code_Contests_27031 | C | [
"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 | 7b449dcc1cd4a81e8498969accd37608b166836f | c8855c1bb0ee9a2e2d83e7eecf955ea3d79131c2 | |||
v1.0 | complete | Code_Contests | Code_Contests_27153_C | def preprocess_fruit_counts(fruit_counts):
""" Precompute cumulative sums for the fruit counts of trees.
>>> preprocess_fruit_counts([2, 3, 7, 1, 5, 6, 2, 4, 8, 3])
[0, 2, 5, 12, 13, 18, 24, 26, 30, 38, 41]
"""
def query_fruit_sum(cumulative_sums, S, E):
""" Calculate the sum for the range S to... | 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": "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 e... | 0.681637 | Code_Contests_27153 | C | [
"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 | c3f7b9d1ceefaf2fdbe6784997b614c3adf82d5f | 2cbdb3921bd2497a7784ad20fd27afca167c34b9 | |||
v1.0 | complete | Code_Contests | Code_Contests_27174_C | from typing import List, Tuple
def combination_resistances(values: List[int]) -> set:
"""
Returns a set of all possible resistances that can be achieved
with combinations of given resistor values using series combinations.
"""
pass
def is_possible_to_achieve_resistance(target: int, resistances: L... | 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": "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.... | 0.496973 | Code_Contests_27174 | C | [
"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 | 9e3a3768133211500604ce1e214d6880ee1cff0c | 3deb02e4994a291b04154d65862424667bb574f6 | |||
v1.0 | complete | Code_Contests | Code_Contests_27150_C | 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):
"""
Inserts a key into the BST and returns the... | 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": "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:\n\n1. The key in each node must be greater than all keys stored in the left subtree of the node.\n2. The key in each node must be less th... | 0.488555 | Code_Contests_27150 | C | [
"generate_bst_from_list",
"bst_info"
] | 2 | [
[
"bst_info",
"generate_bst_from_list"
]
] | 1 | [] | false | [
"TreeNode",
"BST"
] | true | pytest | true | [] | true | 33b0f9c186359278321c0fcf7a74fd1b22fe0d32 | 5b770913274bd6cfdca9ea273471aff5d3f6d5c7 | |||
v1.0 | complete | Code_Contests | Code_Contests_27379_C | def display_board(board):
""" Display the current state of the 5x5 board.
>>> display_board([['-', '-', '-', '-', '-'], ['-', '-', '-', '-', '-'], ['-', '-', '-', '-', '-'], ['-', '-', '-', '-', '-'], ['-', '-', '-', '-', '-']])
- - - - -
- - - - -
- - - - -
- - - - -
- - - - -
"""
p... | 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": "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:\n\n- There are two players, Player X and Player O.\n- The players take turns to place... | 0.563995 | Code_Contests_27379 | C | [
"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 | bde713806c83955d6beb292eb3e3f0f53e80535a | b35cf3ed92a93f3b0197999e9d20b33d8f20200b | |||
v1.0 | complete | Code_Contests | Code_Contests_27541_C | from typing import List
def validate_password(password: str) -> str:
""" Validate if the given password meets the company's policy.
- Minimum 8 characters
- At least one uppercase letter
- At least one lowercase letter
- At least one digit
- At least one 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": "A company has a unique policy for password creation. The policy is defined as follows:\n1. Each password must be at least 8 characters long.\n2. Each password must contain at least one uppercase letter, one lowercase letter, and one digit.\n3. Each password must contain a special character ... | 0.584675 | Code_Contests_27541 | C | [
"validate_password",
"check_passwords"
] | 2 | [
[
"check_passwords",
"validate_password"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | f4e97b5c8c3b9b259294445fe1d826f16b505ff7 | d795e52d16c5c574fdf2f4bf4918f73b5f087268 | |||
v1.0 | complete | Code_Contests | Code_Contests_28395_C | 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.
"""
def check_collinear_points(sets_of_points):
"""
... | 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": "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 ... | 0.704617 | Code_Contests_28395 | C | [
"are_points_collinear",
"check_collinear_points"
] | 2 | [
[
"check_collinear_points",
"are_points_collinear"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 076c645a6e227c7a145512f63fbf0630fb2a810e | bcde54365b597aa3c3b2e8946cb14f2152ede25c | |||
v1.0 | complete | Code_Contests | Code_Contests_28199_C | def min_edges_to_connect_all_servers(n: int, m: int, edges: List[Tuple[int, int]]) -> int:
""" Determine the minimum number of edges that need to be added to ensure that any server can communicate with any other server, directly or indirectly.
>>> min_edges_to_connect_all_servers(5, 3, [(1, 2), (2, 3), (4,... | 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": "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, e... | 0.614625 | Code_Contests_28199 | C | [
"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 | 5fb5640d6fb80fe357c467d4e52445b11cc9043c | 381990ab00557334f583fc65116370963d68f8bc | |||
v1.0 | complete | Code_Contests | Code_Contests_28526_C | 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.
"""
pass
def find_min_pages(pages, N, M):
"""
Function which executes binary search to find the minimum of the maximum pages any student c... | 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": "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 ... | 0.592877 | Code_Contests_28526 | C | [
"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 | 973fba758b96e4e2f1c0f0bf85b0f682937fa931 | ff1fd4d7f80fdd1ad22679e71cdffa4b3fbab520 | |||
v1.0 | complete | Code_Contests | Code_Contests_27530_C | import heapq
from collections import defaultdict
from typing import List, Tuple
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_... | 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": "Problem\n\nA 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 min... | 0.708164 | Code_Contests_27530 | C | [
"dijkstra",
"min_travel_time"
] | 2 | [
[
"min_travel_time",
"dijkstra"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | 39aca24cfd3dec1355725cb3a93e9a66c79c4fc6 | 2e9998641bb0513a0bd46d758b5e6424f804a8ba | |||
v1.0 | complete | Code_Contests | Code_Contests_28117_C | def minimum_latency(N: int, M: int, cables: List[Tuple[int, int, int]]) -> int:
""" Find the minimum total latency required to connect all computers in the network.
Input
- N (int): number of computers
- M (int): number of cables
- cables (List[Tuple[int, int, int]]): each tuple contains three integ... | 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": "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 late... | 0.550426 | Code_Contests_28117 | C | [
"find_parent",
"union",
"kruskal",
"minimum_latency"
] | 4 | [
[
"kruskal",
"find_parent"
],
[
"kruskal",
"union"
],
[
"minimum_latency",
"kruskal"
],
[
"union",
"find_parent"
]
] | 4 | [] | false | [] | false | pytest | true | [] | true | 3fcf6413bd85167e7811542a965bf28064bf1923 | 8328a6d33dd73cef82af8a71da8b62258094b9dc | |||
v1.0 | complete | Code_Contests | Code_Contests_28336_C | from typing import List
def compress(ip_list: List[str]) -> List[str]:
""" Compress a list of IPv4 addresses by representing continuous blocks using a range notation.
>>> 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.1... | 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": "IP Address Compression\n\nIn 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.\n\n... | 0.596713 | Code_Contests_28336 | C | [
"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 | 605afa2cfbdd5258d52562461925492fc7f34784 | 64d6cd88ac1d4106096bc5283ff66dcd23e70cb4 | |||
v1.0 | complete | Code_Contests | Code_Contests_28830_C | def length_of_longest_substring(s: str) -> int:
"""
Returns the length of the longest substring without repeating characters.
>>> length_of_longest_substring("abcabcbb")
3
>>> length_of_longest_substring("bbbbb")
1
>>> length_of_longest_substring("pwwkew")
3
"""
def lengths_of_... | 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": "You are given n strings. For each string, find the length of the longest substring that contains no repeating characters. \n\nInput\n\nThe 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 stri... | 0.762395 | Code_Contests_28830 | C | [
"length_of_longest_substring",
"lengths_of_longest_substrings"
] | 2 | [
[
"lengths_of_longest_substrings",
"length_of_longest_substring"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 6e2609156253c4ed5eca13aeec8d944235252186 | a5708811dfbfcab574c52e25b194928b1ccb1f7a | |||
v1.0 | complete | Code_Contests | Code_Contests_28298_C | from typing import List, Tuple
def solve_hiker_problem(N: int, M: int, heights: List[List[int]], W: int, water_coordinates: List[Tuple[int, int]]) -> int:
""" Determine the minimum number of steps the hiker needs to take to reach the bottom-right corner
of the grid, or determine if it is impossible for the hik... | 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": "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... | 0.658183 | Code_Contests_28298 | C | [
"min_steps_to_reach_end",
"solve_hiker_problem"
] | 2 | [
[
"solve_hiker_problem",
"min_steps_to_reach_end"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | c23b612941bdbef90e41122b28ceb439427d9b75 | 435c9671b56d8d3f4322f88bf61ee890ddf45046 | |||
v1.0 | complete | Code_Contests | Code_Contests_28737_C | 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.
"""
pass
def perfect_number_tournament(T, numbers):
"""
Determines if each number in the list is a perfect number.
:param T: The... | 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": "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 divi... | 0.619814 | Code_Contests_28737 | C | [
"is_perfect_number",
"perfect_number_tournament"
] | 2 | [
[
"perfect_number_tournament",
"is_perfect_number"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | fb80762e404e64b9aadffc97d9cecbaa4349d97f | 2d1e2461d2ab9ee579c62448822eecbacde3991e | |||
v1.0 | complete | Code_Contests | Code_Contests_28564_C | def find_max_path_length(n: int, k: int, edges: List[Tuple[int, int]]) -> Tuple[int, str]:
"""
Determines the maximum path length between the farthest pair of routers in the network
and whether this length is within the given threshold.
Parameters:
- n (int): The number of routers (nodes)
-... | 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": "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. \n\nThe company wants to optimize the network by... | 0.631037 | Code_Contests_28564 | C | [
"bfs",
"find_max_path_length"
] | 2 | [
[
"find_max_path_length",
"bfs"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | c7fb0351f0d459dba5c186d7e01f0407a8952d24 | e354173db41da95938d62237bfb39a8098ca88b8 | |||
v1.0 | complete | Code_Contests | Code_Contests_29128_C | from typing import List
def detect_duplicates(ads: List[str]) -> List[int]:
""" The function detects duplicate advertisements. An advertisement is considered a duplicate
if it is a rearrangement of the words in another advertisement from the list.
Args:
ads (List[str]): A list of advertisements.
... | 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": "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.\n\nYour task is to... | 0.647382 | Code_Contests_29128 | C | [
"normalize_ad",
"detect_duplicates"
] | 2 | [
[
"detect_duplicates",
"normalize_ad"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | f58cdb9d18bb48053b035934b5d0533680ca04f9 | f71ba55b68d2d27ed7e359b2474c903334a3b462 | |||
v1.0 | complete | Code_Contests | Code_Contests_28177_C | import sys
import collections
def lca_preprocess(tree, n, root=1):
""" Preprocess the tree to calculate the up and depth table.
Args:
tree (defaultdict): Adjacency list representing the tree.
n (int): Number of nodes in the tree.
root (int): The root of the tree.
Returns:
t... | 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": "Given a rooted binary tree, you need to find the lowest common ancestor of two given nodes in the tree.\n\nThe 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 itse... | 0.576182 | Code_Contests_28177 | C | [
"lca_preprocess",
"lca",
"process_input"
] | 3 | [
[
"process_input",
"lca"
],
[
"process_input",
"lca_preprocess"
]
] | 2 | [
"process_input"
] | false | [] | false | pytest | true | [] | true | 51f9269c6f590e517908b42042ca2a3222382a75 | 79aa0d090c22455abe2fa331d7191e20bbbce683 | |||
v1.0 | complete | Code_Contests | Code_Contests_28492_C | def can_be_palindrome(s: str) -> bool:
""" Determine if a given string can be transformed into a palindrome
by removing at most one character (or not removing any character at all).
>>> can_be_palindrome("abca")
True
>>> can_be_palindrome("abc")
False
"""
def check_palindrome_possibil... | 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": "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). \n\nA palindrome is a string that reads the same forward and backward.\n\nYour task is to determine if it is... | 0.803389 | Code_Contests_28492 | C | [
"can_be_palindrome",
"check_palindrome_possibility"
] | 2 | [
[
"check_palindrome_possibility",
"can_be_palindrome"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | 8267b05176b47cd3249579bfdef1ca65fcab4dd7 | 12fdae88335c75fb2283f58989568a5c608a0592 | |||
v1.0 | complete | Code_Contests | Code_Contests_29297_C | def intersection_count(N: int, lines: List[Tuple[int, int, int]]) -> int:
"""Given N lines represented by equations of form ax + by + c = 0,
determine the number of distinct points where at least two lines intersect.
Args:
N (int): Number of lines.
lines (List[Tuple[int, int, int]]): List of tuples... | def gcd(x, y):
while y:
x, y = y, x % y
return x
def intersection_count(N, lines):
intersection_points = set()
for i in range(N):
for j in range(i + 1, N):
a1, b1, c1 = lines[i]
a2, b2, c2 = lines[j]
det = a1 * b2 - a2 * b1
i... | from solution import intersection_count
def test_intersection_count_case1():
N = 3
lines = [
(1, -1, -1),
(2, -2, -2),
(1, 0, -1)
]
assert intersection_count(N, lines) == 1
def test_intersection_count_case2():
N = 4
lines = [
(1, 2, -3),
(2, -1, 4),
... | [
{
"docstring": null,
"function_declaration": "def gcd(x, y):",
"function_name": "gcd",
"parameter_list": "(x, y)"
},
{
"docstring": null,
"function_declaration": "def intersection_count(N, lines):",
"function_name": "intersection_count",
"parameter_list": "(N, lines)"
}
] | [
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": "from itertools import combinations\n\ndef intersection_point(line1, line2):\n \"\"\"\n Returns intersection point of two lines if they are not parall... | trial_gpt4o_2 | {
"original_instruction": "A line in a 2D plane is represented by the equation ax + by + c = 0, where a, b, and c are integers. Given N lines, the aim is to determine the number of points (x, y) where at least two lines intersect. The output should be the count of these distinct intersection points.\n\nInput\n\nThe i... | 0.56895 | Code_Contests_29297 | C | [
"gcd",
"intersection_count"
] | 2 | [
[
"intersection_count",
"gcd"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | b7de1e114010e7348f0266a9f0c87bbf45578812 | a7ba8391ac006d8e65bd8cd8fbd849539e33525e | |||
v1.0 | complete | Code_Contests | Code_Contests_27845_C | class TreeNode:
def __init__(self, val=0, left=None, right=None):
self.val = val
self.left = left
self.right = right
def deleteNode(root: TreeNode, key: int) -> TreeNode:
""" Deletes a node with a given value from a binary search tree (BST) and returns the root of the modified tree.
... | 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": "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 element... | 0.621272 | Code_Contests_27845 | C | [
"deleteNode",
"findMin"
] | 2 | [
[
"deleteNode",
"findMin"
]
] | 1 | [] | false | [
"TreeNode"
] | true | pytest | true | [] | true | 8ea9b5b41612ff53eea95674585766f3d1306349 | e6c8fc5920a666f082d3739ba15ea9c8861ae97d | |||
v1.0 | complete | Code_Contests | Code_Contests_28928_C | def count_primes_in_range(prime_numbers: List[int], queries: List[Tuple[int, int]]) -> List[int]:
"""
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.
"""
r... | 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": "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.\n\nInput:\nFirst line contains N and K, ... | 0.722669 | Code_Contests_28928 | C | [
"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 | d2171314013d828455032f603f211804e79d16a2 | d71449d6f72e219f2beebfb3e7d489acd9cf5061 | |||
v1.0 | complete | Code_Contests | Code_Contests_29182_C | def is_subsequence(s1: str, s2: str) -> bool:
"""
Determine if s1 is a subsequence of s2.
"""
pass
def check_subsequence(str1: str, str2: str) -> str:
"""
Returns "Yes" if str1 is a subsequence of str2, otherwise "No".
"""
pass
# Tests
def test_positive_case():
assert check_subsequ... | def is_subsequence(s1, s2):
"""
Determine if s1 is a subsequence of s2.
"""
it = iter(s2)
return all(char in it for char in s1)
def check_subsequence(str1, str2):
"""
Returns "Yes" if str1 is a subsequence of str2, otherwise "No".
"""
if is_subsequence(str1, str2):
return "Y... | from solution import check_subsequence
def test_positive_case():
assert check_subsequence("ACE", "ABCDE") == "Yes"
def test_negative_case():
assert check_subsequence("HELLO", "WORLD") == "No"
def test_full_match():
assert check_subsequence("ABC", "ABC") == "Yes"
def test_subsequence_at_beginning():
... | [
{
"docstring": "Determine if s1 is a subsequence of s2.",
"function_declaration": "def is_subsequence(s1, s2):",
"function_name": "is_subsequence",
"parameter_list": "(s1, s2)"
},
{
"docstring": "Returns \"Yes\" if str1 is a subsequence of str2, otherwise \"No\".",
"function_declaration"... | [
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_subsequence(s1, s2):\n \"\"\"\n Determine if s1 is a subsequence of s2.\n \n Parameters:\n s1 (str): First string.\n s2 (str): Sec... | trial_gpt4o_2 | {
"original_instruction": "Given two strings, determine if one string is a subsequence of the other. A subsequence is a sequence derived from another sequence by deleting some or no elements, without changing the order of the remaining elements.\n\nInput\n\nThe input consists of two lines. Each line contains a string... | 0.64595 | Code_Contests_29182 | C | [
"is_subsequence",
"check_subsequence"
] | 2 | [
[
"check_subsequence",
"is_subsequence"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | c6ffda0784fa8e6c146b8c452c27a27020ecbd68 | c182b5d5065a7b4fed75e39f81d1afb2a2c22984 | |||
v1.0 | complete | Code_Contests | Code_Contests_28887_C | from typing import List
def find_best_starting_checkpoint(n: int, travel_times: List[List[int]]) -> int:
""" Determine the starting checkpoint for the relay race to minimize the total travel time.
Args:
n (int): the number of checkpoints.
travel_times (List[List[int]]): the matrix representing tra... | 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": "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... | 0.630613 | Code_Contests_28887 | C | [
"travel_time",
"find_best_starting_checkpoint"
] | 2 | [
[
"find_best_starting_checkpoint",
"travel_time"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | 370dac11f5dfe403b89c915b88a42f469045d25f | 693bc8ad03df8f62bbdeb9815861e37825e068d3 | |||
v1.0 | complete | Code_Contests | Code_Contests_28909_C | def is_special_number(n: int) -> bool:
"""
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... | 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": "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: \n\n- 1² + 9² = 82 \n- 8² + 2... | 0.597418 | Code_Contests_28909 | C | [
"is_special_number",
"special_numbers"
] | 2 | [
[
"special_numbers",
"is_special_number"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 3769b87e7056034882bb8b7a82e35e598c774069 | a3e74a2a263348b59934be868fa7cacc0f42e051 | |||
v1.0 | complete | Code_Contests | Code_Contests_29542_C | def max_rectangle_area(n, heights):
"""
Returns the maximum area of a rectangle formed by consecutive buildings.
>>> max_rectangle_area(6, [2, 1, 5, 6, 2, 3])
10
>>> max_rectangle_area(4, [1, 2, 3, 4])
6
>>> max_rectangle_area(5, [5, 4, 3, 2, 1])
9
>>> max_rectangle_area(1, [5])... | def max_area_histogram(heights):
"""
Returns the maximum area of rectangle formed using consecutive buildings.
"""
stack, max_area = [], 0
index = 0
while index < len(heights):
if not stack or heights[index] >= heights[stack[-1]]:
stack.append(index)
index +=... | from solution import max_rectangle_area
def test_max_rectangle_area_example1():
assert max_rectangle_area(6, [2, 1, 5, 6, 2, 3]) == 10
def test_max_rectangle_area_example2():
assert max_rectangle_area(4, [1, 2, 3, 4]) == 6
def test_max_rectangle_area_example3():
assert max_rectangle_area(5, [5, 4, 3, 2, ... | [
{
"docstring": "Returns the maximum area of rectangle formed using consecutive buildings.",
"function_declaration": "def max_area_histogram(heights):",
"function_name": "max_area_histogram",
"parameter_list": "(heights)"
},
{
"docstring": "Wrapper function to read input and return the maximu... | [
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 max_rectangle_area(heights):\n \"\"\"\n Returns the maximum area of a rectangle formed by consecutive buildings using the given heights.\n \"\... | trial_gpt4o_2 | {
"original_instruction": "You are given an array of integers representing the heights of several buildings arranged in a row. The goal is to determine the maximum area of a rectangle formed between the buildings, where the rectangle is confined by the height of the shortest building in the chosen range and spans one... | 0.722957 | Code_Contests_29542 | C | [
"max_area_histogram",
"max_rectangle_area"
] | 2 | [
[
"max_rectangle_area",
"max_area_histogram"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 0d608727eb19c5ba60d7e5e0062585ecce20a1e3 | 762aac331c3ece8819ed28f2d39b8f3a9b663d51 | |||
v1.0 | complete | Code_Contests | Code_Contests_29658_C | from collections import deque
from typing import List
def find_shortest_path(n: int, m: int, grid_str: List[str]) -> int:
""" Determine the shortest path the courier can take to deliver a package from the start cell to the destination cell.
>>> find_shortest_path(4, 4, ["....", "..#.", "...#", "#..."])
6
... | from collections import deque
def shortest_path(grid):
n = len(grid)
m = len(grid[0])
directions = [(-1, 0), (1, 0), (0, -1), (0, 1)]
def is_valid(x, y):
return 0 <= x < n and 0 <= y < m and grid[x][y] == '.'
queue = deque([(0, 0, 0)]) # (row, column, distance)
grid[0][0] = '#' ... | from solution import find_shortest_path
def test_example_1():
n, m = 4, 4
grid_str = [
"....",
"..#.",
"...#",
"#..."
]
assert find_shortest_path(n, m, grid_str) == 6
def test_example_2():
n, m = 3, 3
grid_str = [
".#.",
"###",
".#."
... | [
{
"docstring": null,
"function_declaration": "def shortest_path(grid):",
"function_name": "shortest_path",
"parameter_list": "(grid)"
},
{
"docstring": null,
"function_declaration": "def find_shortest_path(n, m, grid_str):",
"function_name": "find_shortest_path",
"parameter_list"... | [
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": "from collections import deque\n\ndef shortest_path(n, m, grid):\n def is_valid(x, y):\n return 0 <= x < n and 0 <= y < m and grid[x][y] == '.'\n\... | trial_gpt4o_2 | {
"original_instruction": "A courier is delivering packages in a city with a grid of size n x m. The city can be represented by a grid with n rows and m columns. There are certain cells that represent buildings (blocked cells) where the courier cannot enter. You need to determine the shortest path the courier can tak... | 0.631126 | Code_Contests_29658 | C | [
"shortest_path",
"find_shortest_path"
] | 2 | [
[
"find_shortest_path",
"shortest_path"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 4cd1320921b341d8fa722ff5afd64193f04c7a57 | 9869e2cb2d8586a5af2fbb31c8b76175d406f52b | |||
v1.0 | complete | Code_Contests | Code_Contests_29465_C | from typing import List, Tuple
def marathon_event_replenish_times(T: int, test_cases: List[Tuple[int, List[int]]]) -> List[int]:
""" Determine the least time at which all the water stations will be simultaneously replenished with water again.
Args:
T (int): Number of test cases.
test_cases (List[T... | import math
from functools import reduce
MOD = 1000000007
def lcm(a, b):
return (a * b) // math.gcd(a, b)
def lcm_multiple(numbers):
return reduce(lambda x, y: lcm(x, y) % MOD, numbers, 1)
def marathon_event_replenish_times(T, test_cases):
results = []
for test_case in test_cases:
n = test_c... | from solution import marathon_event_replenish_times
def test_single_interval():
assert marathon_event_replenish_times(1, [[1, 5]]) == [5]
def test_multiple_intervals_same():
assert marathon_event_replenish_times(1, [[3, 5, 5, 5]]) == [5]
def test_multiple_intervals_different():
assert marathon_event_repl... | [
{
"docstring": null,
"function_declaration": "def lcm(a, b):",
"function_name": "lcm",
"parameter_list": "(a, b)"
},
{
"docstring": null,
"function_declaration": "def lcm_multiple(numbers):",
"function_name": "lcm_multiple",
"parameter_list": "(numbers)"
},
{
"docstring":... | [
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": "import math\nfrom functools import reduce\n\nMOD = 1000000007\n\ndef gcd(a, b):\n while b:\n a, b = b, a % b\n return a\n\ndef lcm(a, b):\n ... | trial_gpt4o_2 | {
"original_instruction": "**Problem Description:**\n\nYou and your friend Alex are organizing a marathon event. On the marathon route, there are several water stations where volunteers provide water to the runners at specific intervals. You want to determine the least time at which all the water stations will be sim... | 0.554111 | Code_Contests_29465 | C | [
"lcm",
"lcm_multiple",
"marathon_event_replenish_times"
] | 3 | [
[
"lcm_multiple",
"lcm"
],
[
"marathon_event_replenish_times",
"lcm_multiple"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | fdee0800ae6c3c1975a6ae3bc4c83b39b630162d | 10ca34aff6f6c068fdc859eeb43ba1d06ff103d4 | |||
v1.0 | complete | Code_Contests | Code_Contests_29224_C | def is_prime(num):
"""
Helper function to determine if a number is prime.
"""
def preprocess_primes(arr):
"""
Preprocess primes in the array and their prefix sums.
"""
def query_prime_sum(prime_sum_prefix, L, R):
"""
Get the sum of primes in the subarray from L to R using the precomput... | def is_prime(num):
"""
Helper function to determine if a number is prime.
"""
if num <= 1:
return False
if num <= 3:
return True
if num % 2 == 0 or num % 3 == 0:
return False
i = 5
while i * i <= num:
if num % i == 0 or num % (i + 2) == 0:
retu... | def test_is_prime():
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(4) == False
assert is_prime(0) == False
assert is_prime(1) == False
assert is_prime(13) == True
assert is_prime(17) == True
assert is_prime(18) == False
def test_preprocess_primes():
arr = [2,... | [
{
"docstring": "Helper function to determine if a number is prime.",
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": "Preprocess primes in the array and their prefix sums.",
"function_declaration": "def preprocess_pri... | [
1,
0
] | 1 | medium | 0.5 | {
"trial_gpt4o_0": null,
"trial_gpt4o_1": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared1_results_combined.jsonl",
"solution_code": "def is_prime(num):\n \"\"\"\n Helper function to determine if a number is prime.\n \"\"\"\n if num <= 1:\n retu... | trial_gpt4o_1 | {
"original_instruction": "Wanda is fascinated by prime numbers and enjoys finding them in various ranges. She has invented a new challenge for herself: finding sums of prime numbers in dynamic ranges.\n\nGiven a large array `arr` of length `N` filled with integers, you will need to handle multiple queries. Each quer... | 0.676668 | Code_Contests_29224 | C | [
"is_prime",
"preprocess_primes",
"query_prime_sum",
"prime_sum_in_ranges"
] | 4 | [
[
"preprocess_primes",
"is_prime"
],
[
"prime_sum_in_ranges",
"preprocess_primes"
],
[
"prime_sum_in_ranges",
"query_prime_sum"
]
] | 3 | [] | false | [] | false | pytest | false | [] | true | 1dec8e8abbe05a8cb4aea139241396cd56d3ad10 | cef377de73006a5c0f9155272170d1a0818c96cb | |||
v1.0 | complete | Code_Contests | Code_Contests_29865_C | from typing import List, Tuple
def max_distance_in_tree(N: int, edges: List[Tuple[int, int]]) -> int:
""" Determine the maximum distance between any two vertices in a tree.
Args:
N (int): The number of vertices in the tree.
edges (List[Tuple[int, int]]): A list of tuples representing the edges ... | from collections import defaultdict, deque
def find_farthest(node, graph):
visited = set()
queue = deque([(node, 0)])
farthest_node = node
max_distance = 0
while queue:
current_node, distance = queue.popleft()
visited.add(current_node)
for neighbor in graph[cur... | from solution import max_distance_in_tree
def test_example_1():
N = 5
edges = [(1, 2), (1, 3), (2, 4), (2, 5)]
assert max_distance_in_tree(N, edges) == 3
def test_example_2():
N = 3
edges = [(1, 2), (2, 3)]
assert max_distance_in_tree(N, edges) == 2
def test_example_3():
N = 6
edges =... | [
{
"docstring": null,
"function_declaration": "def find_farthest(node, graph):",
"function_name": "find_farthest",
"parameter_list": "(node, graph)"
},
{
"docstring": null,
"function_declaration": "def max_distance_in_tree(N, edges):",
"function_name": "max_distance_in_tree",
"par... | [
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 sys\nsys.setrecursionlimit(200000)\n\ndef maximum_distance(N, edges):\n from collections import defaultdict, deque\n\n def bfs(start):\n ... | trial_gpt4o_2 | {
"original_instruction": "You are given a tree T, which is an undirected graph with N vertices and N-1 edges. Each vertex is numbered from 1 through N, and each edge connects two vertices.\n\nYour task is to determine the maximum distance between any two vertices in T. The distance between two vertices is defined as... | 0.624167 | Code_Contests_29865 | C | [
"find_farthest",
"max_distance_in_tree"
] | 2 | [
[
"max_distance_in_tree",
"find_farthest"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | f65637e2ac2005222b4a9eeff6bba47342b713a1 | b277c1874c051ff438fc8441857cef15932efee1 | |||
v1.0 | complete | Code_Contests | Code_Contests_30079_C | def find_longest_subsequence(arr: List[int]) -> int:
""" Given an array of integers, find the longest subsequence such that every two consecutive elements in the subsequence have a common factor greater than 1.
>>> find_longest_subsequence([4, 8, 15, 16, 23])
3
>>> find_longest_subsequence([7, 11, 13, 1... | from math import gcd
from functools import lru_cache
@lru_cache(None)
def gcd_memo(x, y):
return gcd(x, y)
def find_longest_subsequence(arr):
n = len(arr)
if n == 0:
return 0
dp = [1] * n
for i in range(1, n):
for j in range(i):
if gcd_memo(arr[i], arr[j]) > 1... | from solution import find_longest_subsequence
def test_longest_subsequence_example_1():
assert find_longest_subsequence([4, 8, 15, 16, 23]) == 3
def test_longest_subsequence_example_2():
assert find_longest_subsequence([7, 11, 13, 17]) == 1
def test_longest_subsequence_single_element():
assert find_longe... | [
{
"docstring": null,
"function_declaration": "def gcd_memo(x, y):",
"function_name": "gcd_memo",
"parameter_list": "(x, y)"
},
{
"docstring": null,
"function_declaration": "def find_longest_subsequence(arr):",
"function_name": "find_longest_subsequence",
"parameter_list": "(arr)"... | [
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\n\ndef longest_subsequence_with_common_factor(arr):\n n = len(arr)\n dp = [1] * n\n \n for i in range(1, n):\n for j in rang... | trial_gpt4o_5 | {
"original_instruction": "Given an array of integers, write a program to find the longest subsequence such that every two consecutive elements in the subsequence have a common factor greater than 1.\n\n### Input\n- The first line of input contains an integer n (2 ≤ n ≤ 1000), the number of elements in the array.\n- ... | 0.751537 | Code_Contests_30079 | C | [
"gcd_memo",
"find_longest_subsequence",
"main"
] | 3 | [
[
"find_longest_subsequence",
"gcd_memo"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | ae9181a39cc0ba88781e56b92a93ff05f9db8380 | 5993a6d4545c76172ec0ca9e68f9f09e6c943c84 | |||
v1.0 | complete | Code_Contests | Code_Contests_29719_C | from typing import List
def generate_fibonacci_until(max_value: int) -> List[int]:
""" Generate a list of Fibonacci numbers up to a maximum value.
>>> generate_fibonacci_until(50)
[1, 1, 2, 3, 5, 8, 13, 21, 34]
"""
pass
def find_closest_fib_subset(p: List[int], fibs: List[int]) -> List[int]:
... | def generate_fibonacci_until(max_value):
fibs = [1, 1]
while True:
next_fib = fibs[-1] + fibs[-2]
if next_fib > max_value:
break
fibs.append(next_fib)
return fibs
def find_closest_fib_subset(p, fibs):
target_sum = sum(p)
m = len(p)
closest_subset = []
cur... | from solution import generate_fibonacci_until, find_closest_fib_subset, find_fib_list
def test_generate_fibonacci_until():
assert generate_fibonacci_until(50) == [1, 1, 2, 3, 5, 8, 13, 21, 34]
def test_find_closest_fib_subset():
p_example = [10, 22, 35, 50]
fibs_example = [1, 1, 2, 3, 5, 8, 13, 21, 34, 55... | [
{
"docstring": null,
"function_declaration": "def generate_fibonacci_until(max_value):",
"function_name": "generate_fibonacci_until",
"parameter_list": "(max_value)"
},
{
"docstring": null,
"function_declaration": "def find_closest_fib_subset(p, fibs):",
"function_name": "find_closes... | [
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 find_fibonacci_list(m, p):\n def generate_fibonacci_up_to(max_value):\n fibs = [1, 1]\n while True:\n next_fib = fibs[-1] +... | trial_gpt4o_3 | {
"original_instruction": "John loves Fibonacci numbers and wants to create a special list based on them. He has a list p of m unique positive integers, and he asked you to find another list q of the same length such that:\n\n- q contains only Fibonacci numbers.\n- q contains each Fibonacci number exactly once.\n- Th... | 0.699674 | Code_Contests_29719 | C | [
"generate_fibonacci_until",
"find_closest_fib_subset",
"find_fib_list",
"main"
] | 4 | [
[
"find_fib_list",
"find_closest_fib_subset"
],
[
"find_fib_list",
"generate_fibonacci_until"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 1d4cb21c93a1b5dc32dd520d3af125c2def446be | 6ca9885cefdd492233890836066a0603fc8bb142 | |||
v1.0 | complete | Code_Contests | Code_Contests_29818_C | from typing import List
def can_first_player_win(t: int, n: int, test_cases: List[str]) -> List[str]:
""" Determine if the first player has a guaranteed winning strategy given the initial positions of all pieces on the board.
>>> can_first_player_win(2, 4, ["2 1 1 4 4", "3 1 1 2 2 3 3"]) ["NO", "YES"]
>>> ... | def can_first_player_win(t, n, test_cases):
results = []
for case in test_cases:
p = case[0]
positions = case[1:]
if p % 2 == 0:
results.append("NO")
else:
results.append("YES")
return results
# Function to parse input and c... | def test_can_first_player_win():
assert solve(2, 4, ["2 1 1 4 4", "3 1 1 2 2 3 3"]) == ["NO", "YES"]
assert solve(1, 5, ["4 1 1 2 2 3 3 4 4"]) == ["NO"]
assert solve(3, 3, ["1 2 2", "2 1 1 3 3", "4 1 1 2 2 3 3 2 3"]) == ["YES", "NO", "NO"]
assert solve(1, 1, ["1 1 1"]) == ["YES"]
assert solve(2, 6, ... | [
{
"docstring": null,
"function_declaration": "def can_first_player_win(t, n, test_cases):",
"function_name": "can_first_player_win",
"parameter_list": "(t, n, test_cases)"
},
{
"docstring": null,
"function_declaration": "def solve(t, n, cases):",
"function_name": "solve",
"parame... | [
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 has_winning_strategy(t, n, test_cases):\n results = []\n for case in test_cases:\n p = case[0]\n pieces = case[1:]\n board =... | trial_gpt4o_1 | {
"original_instruction": "Consider a new game played on an n x n chessboard with multiple chess pieces. Initially, each piece occupies a distinct cell, and each cell can hold at most one piece. During the game, the pieces are moved according to the following rules:\n\n1. A piece can move to any adjacent cell (up, do... | 0.676519 | Code_Contests_29818 | C | [
"can_first_player_win",
"solve"
] | 2 | [
[
"solve",
"can_first_player_win"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | 47372d784da4a1dc87a86a40e8eeaca6fbc6d685 | a79532d391c7758737cedd720a9260b3cd668ca2 | |||
v1.0 | complete | Code_Contests | Code_Contests_30019_C | def calculate_centroid_of_polygon(vertices):
"""
Calculate the centroid of a polygon given its vertices.
vertices: list of tuples, where each tuple is an (x, y) coordinate of a vertex.
Returns the centroid of the polygon as a tuple (Cx, Cy).
"""
def find_centroids_of_forests(input_dat... | def calculate_centroid_of_polygon(vertices):
"""
Calculate the centroid of a polygon given its vertices.
vertices: list of tuples, where each tuple is an (x, y) coordinate of a vertex.
Returns the centroid of the polygon as a tuple (Cx, Cy).
"""
n = len(vertices)
area = 0
Cx = ... | def test_calculate_centroid_of_polygon_triangle():
vertices = [(0, 0), (4, 0), (2, 3)]
assert calculate_centroid_of_polygon(vertices) == (2.0000, 1.0000)
def test_calculate_centroid_of_polygon_square():
vertices = [(1, 1), (4, 1), (4, 5), (1, 5)]
assert calculate_centroid_of_polygon(vertices) == (2.500... | [
{
"docstring": "Calculate the centroid of a polygon given its vertices.\n\nvertices: list of tuples, where each tuple is an (x, y) coordinate of a vertex.\n\nReturns the centroid of the polygon as a tuple (Cx, Cy).",
"function_declaration": "def calculate_centroid_of_polygon(vertices):",
"function_name"... | [
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 polygon_centroid(vertices):\n \"\"\"\n Computes the centroid of a polygon given a list of its vertices.\n Each vertex is represented as a tupl... | trial_gpt4o_4 | {
"original_instruction": "Eva Ecowarrior just embarked on a mission to protect a precious collection of rain forests. Each rain forest is represented as a non-overlapping convex polygon, and Eva is tasked with planting an anti-deforestation beacon in each rain forest to keep them secure.\n\nEva's drones have a limit... | 0.571351 | Code_Contests_30019 | C | [
"calculate_centroid_of_polygon",
"find_centroids_of_forests"
] | 2 | [
[
"find_centroids_of_forests",
"calculate_centroid_of_polygon"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | b31b54d80f75fbe58e75a7d921da1c21017abc33 | 72d8f636c10ff772fe588909717c20336717166b | |||
v1.0 | complete | Code_Contests | Code_Contests_29912_C | from typing import List, Tuple
def minimum_time_to_collect_treasure(N: int, temples: List[Tuple[int, int, int]], sequence: List[int]) -> int:
"""
Determine the shortest possible time to visit all specified temples and collect all pieces of the treasure.
:param N: Size of the grid (N x N)
:param temple... | from collections import deque
def shortest_path_bfs(grid, start, end):
N = len(grid)
directions = [(-1, 0), (1, 0), (0, -1), (0, 1)]
queue = deque([(start[0], start[1], 0)])
visited = set()
visited.add(start)
while queue:
x, y, dist = queue.popleft()
if (x, y) == end:
... | from solution import minimum_time_to_collect_treasure
def test_example_1():
N = 5
temples = [(0, 0, 1), (0, 1, 0), (1, 1, 1), (2, 2, 0), (4, 4, 1)]
sequence = [1, 3, 5]
assert minimum_time_to_collect_treasure(N, temples, sequence) == 8
def test_minimum_travel():
N = 3
temples = [(0, 0, 1), (1,... | [
{
"docstring": null,
"function_declaration": "def shortest_path_bfs(grid, start, end):",
"function_name": "shortest_path_bfs",
"parameter_list": "(grid, start, end)"
},
{
"docstring": null,
"function_declaration": "def minimum_time_to_collect_treasure(N, temples, sequence):",
"functi... | [
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 deque\n\ndef shortest_path_bfs(grid, start, end):\n N = len(grid)\n directions = [(-1, 0), (1, 0), (0, -1), (0, 1)]\n queu... | trial_gpt4o_0 | {
"original_instruction": "Problem E: The Lost Treasure Hunt\n\nMr. Damian is a renowned treasure hunter known for his extraordinary cartographical skills. He has recently discovered a map detailing the locations of several ancient temples scattered across a vast desert. Each temple may or may not contain a piece of ... | 0.5554 | Code_Contests_29912 | C | [
"shortest_path_bfs",
"minimum_time_to_collect_treasure",
"parse_input",
"main"
] | 4 | [
[
"minimum_time_to_collect_treasure",
"shortest_path_bfs"
]
] | 1 | [
"parse_input"
] | false | [] | false | pytest | true | [] | true | 6b70ca62e2a60305885618139f2cb75153b17374 | b56cb59126c8941d9597a63b3ad4a6a332283c45 | |||
v1.0 | complete | Code_Contests | Code_Contests_30313_C | def find_min_subset_difference(N: int, arr: List[int]) -> int:
""" Partition the list into two non-empty subsets such that the absolute difference between the sum of the elements in the two subsets is minimized.
>>> find_min_subset_difference(4, [1, 6, 5, 11]) == 1
>>> find_min_subset_difference(5, [3, 1, 4... | def min_subset_difference(arr):
"""
Function to calculate the minimum subset difference
Args:
arr: List of integers
Returns:
int: The minimum difference between the sums of two subsets
"""
total_sum = sum(arr)
n = len(arr)
dp = [[False] * (total_sum // 2 + 1) for _ in r... | from solution import find_min_subset_difference
def test_example_1():
assert find_min_subset_difference(4, [1, 6, 5, 11]) == 1
def test_example_2():
assert find_min_subset_difference(5, [3, 1, 4, 2, 2]) == 0
def test_single_element():
assert find_min_subset_difference(1, [1000]) == 1000
def test_same_el... | [
{
"docstring": "Function to calculate the minimum subset difference\n\nArgs:\narr: List of integers\n\nReturns:\nint: The minimum difference between the sums of two subsets",
"function_declaration": "def min_subset_difference(arr):",
"function_name": "min_subset_difference",
"parameter_list": "(arr)... | [
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 min_partition_difference(N, a):\n \"\"\"\n Returns the minimum possible absolute difference between the sums of two subsets of the list a.\n \... | trial_gpt4o_4 | {
"original_instruction": "You are given a single integer `N` (1 ≤ N ≤ 100) and a list of N integers `a_1, a_2, ..., a_N` where each `a_i` is between 1 and 1000. You need to partition the list into two non-empty subsets such that the absolute difference between the sum of the elements in the two subsets is minimized.... | 0.669349 | Code_Contests_30313 | C | [
"min_subset_difference",
"find_min_subset_difference"
] | 2 | [
[
"find_min_subset_difference",
"min_subset_difference"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | db248c6e46b5ebca499e2937b65efee44e15502b | b5060e24ac3174fcce5ddcc448d4bacc1e222d48 | |||
v1.0 | complete | Code_Contests | Code_Contests_30425_C | from typing import List
def words_from_chars(words: List[str], chars: str) -> List[str]:
""" Returns a list of words that can be formed using the given set of characters.
>>> words_from_chars(["apple"], "aelpp")
["apple"]
>>> words_from_chars(["apple", "orange", "grape", "melon"], "aelpp")
["apple"... | from collections import Counter
def can_form_word(word, chars):
"""
Check if a word can be formed using the given set of characters.
"""
word_count = Counter(word)
chars_count = Counter(chars)
for char in word_count:
if word_count[char] > chars_count.get(char, 0):
retur... | from solution import words_from_chars
def test_single_word():
words = ["apple"]
chars = "aelpp"
assert words_from_chars(words, chars) == ["apple"]
def test_multiple_words():
words = ["apple", "orange", "grape", "melon"]
chars = "aelpp"
assert words_from_chars(words, chars) == ["apple"]
def te... | [
{
"docstring": "Check if a word can be formed using the given set of characters.",
"function_declaration": "def can_form_word(word, chars):",
"function_name": "can_form_word",
"parameter_list": "(word, chars)"
},
{
"docstring": "Returns a list of words that can be formed using the given set ... | [
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_construct_word(word, char_count):\n \"\"\"\n Helper function to determine if a word can be constructed with given character counts.\n \"\"... | trial_gpt4o_3 | {
"original_instruction": "You are given a list of words from a dictionary. Write a program which identifies and prints all the words that can be constructed from the given characters. The characters can each be used only once. Each test case will provide a list of words and the available set of characters.\n\nInput\... | 0.711617 | Code_Contests_30425 | C | [
"can_form_word",
"words_from_chars"
] | 2 | [
[
"words_from_chars",
"can_form_word"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 4365871da0680a92aa7595920c03b570eeeaac78 | 25360c242a0c4f57b25fb6fdd0bff8e0898f230e | |||
v1.0 | complete | Code_Contests | Code_Contests_29167_C | 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 ... | 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": "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.\n\nThere are n junctions (numbered from 1 to n) connected by n-1 trails. Each trai... | 0.579124 | Code_Contests_29167 | C | [
"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 | 9d2b5795ad67149afbe22215b9622dbebc43875d | 5972907ff93d04714b20ae75f16133be061553f5 | |||
v1.0 | complete | Code_Contests | Code_Contests_30136_C | def binary_tree_traversals(n, arr):
""" Perform pre-order, in-order, and post-order traversals on a binary tree given as an array.
>>> binary_tree_traversals(7, [1, 2, 3, 4, 5, 6, 7])
([1, 2, 4, 5, 3, 6, 7], [4, 2, 5, 1, 6, 3, 7], [4, 5, 2, 6, 7, 3, 1])
>>> binary_tree_traversals(1, [1])
([1], [1], ... | def pre_order_traversal(arr, index=0):
if index >= len(arr):
return []
result = [arr[index]]
result += pre_order_traversal(arr, 2 * index + 1)
result += pre_order_traversal(arr, 2 * index + 2)
return result
def in_order_traversal(arr, index=0):
if index >= len(arr):
return []
... | from solution import binary_tree_traversals
def test_binary_tree_traversals_example():
n = 7
arr = [1, 2, 3, 4, 5, 6, 7]
pre_order, in_order, post_order = binary_tree_traversals(n, arr)
assert pre_order == [1, 2, 4, 5, 3, 6, 7]
assert in_order == [4, 2, 5, 1, 6, 3, 7]
assert post_order == [4, 5... | [
{
"docstring": null,
"function_declaration": "def pre_order_traversal(arr, index=0):",
"function_name": "pre_order_traversal",
"parameter_list": "(arr, index=0)"
},
{
"docstring": null,
"function_declaration": "def in_order_traversal(arr, index=0):",
"function_name": "in_order_traver... | [
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 pre_order(tree, index, traversal):\n if index >= len(tree):\n return\n traversal.append(tree[index])\n pre_order(tree, 2*index + 1, tra... | trial_gpt4o_1 | {
"original_instruction": "Ruby is learning binary trees and wants to solve some problems to better understand the concept. She has a binary tree given in the form of an array where for node i, `left child` is at index `2*i + 1` and `right child` is at index `2*i + 2`. Given this binary tree, Ruby wants to perform th... | 0.582441 | Code_Contests_30136 | C | [
"pre_order_traversal",
"in_order_traversal",
"post_order_traversal",
"binary_tree_traversals"
] | 4 | [
[
"binary_tree_traversals",
"in_order_traversal"
],
[
"binary_tree_traversals",
"post_order_traversal"
],
[
"binary_tree_traversals",
"pre_order_traversal"
]
] | 3 | [] | false | [] | false | pytest | true | [] | true | 911b4d7ead937ff54e1f78b8f3075423387d0c71 | 2ca2aa4bed7c16f22609477ae8f80c85cc19aedf | |||
v1.0 | complete | Code_Contests | Code_Contests_30806_C | def count_networks(grid):
""" Count the number of unique networks of connected computers in the grid.
>>> count_networks(["11000", "11000", "00100", "00011"])
3
>>> count_networks(["111", "010", "111"])
1
""" | def dfs(grid, i, j, visited):
"""
Depth-first search to mark all connected '1's as visited.
"""
n, m = len(grid), len(grid[0])
stack = [(i, j)]
while stack:
x, y = stack.pop()
if 0 <= x < n and 0 <= y < m and grid[x][y] == '1' and not visited[x][y]:
visited[x][y] = Tr... | from solution import count_networks
def test_example_1():
grid = [
"11000",
"11000",
"00100",
"00011",
]
assert count_networks(grid) == 3
def test_example_2():
grid = [
"111",
"010",
"111",
]
assert count_networks(grid) == 1
def test... | [
{
"docstring": "Depth-first search to mark all connected '1's as visited.",
"function_declaration": "def dfs(grid, i, j, visited):",
"function_name": "dfs",
"parameter_list": "(grid, i, j, visited)"
},
{
"docstring": "Count the number of unique networks of connected computers.",
"functio... | [
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 dfs(grid, i, j, visited):\n \"\"\"\n Depth-first search to mark all connected '1's as visited.\n \"\"\"\n n, m = len(grid), len(grid[0])\n ... | trial_gpt4o_0 | {
"original_instruction": "A network of computers is represented in a grid structure where each cell contains either a '0' (representing an empty space where no computer is present) or a '1' (representing a computer). Two computers are considered connected if they are adjacent horizontally or vertically.\n\nYour task... | 0.495329 | Code_Contests_30806 | C | [
"dfs",
"count_networks"
] | 2 | [
[
"count_networks",
"dfs"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | eebbc8d3c600c4cdd654d2947d017e3868058cc9 | bc4e972461d5c0e402234390d1cc3c69c4d79c79 | |||
v1.0 | complete | Code_Contests | Code_Contests_30052_C | from datetime import datetime, timedelta
from typing import List, Tuple
def compute_time_difference(start: str, end: str) -> timedelta:
start_time = datetime.strptime(start, "%H:%M")
end_time = datetime.strptime(end, "%H:%M")
if end_time < start_time:
end_time += timedelta(days=1)
return end_ti... | from datetime import datetime, timedelta
def compute_time_difference(start, end):
start_time = datetime.strptime(start, "%H:%M")
end_time = datetime.strptime(end, "%H:%M")
if end_time < start_time:
end_time += timedelta(days=1)
return end_time - start_time
def format_time_difference(diff):
... | from solution import train_schedule
def test_single_test_case():
T = 1
test_cases = [
(3, [("09:00", "11:00"), ("12:00", "14:00"), ("15:00", "17:00")]),
]
result = train_schedule(T, test_cases)
assert result == ["06:00", "02:00"]
def test_multiple_test_cases():
T = 2
test_cases = [... | [
{
"docstring": null,
"function_declaration": "def compute_time_difference(start, end):",
"function_name": "compute_time_difference",
"parameter_list": "(start, end)"
},
{
"docstring": null,
"function_declaration": "def format_time_difference(diff):",
"function_name": "format_time_dif... | [
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": "from datetime import datetime, timedelta\n\ndef calculate_travel_and_waiting_times(rides):\n def time_diff_in_minutes(start, end):\n start_dt = d... | trial_gpt4o_2 | {
"original_instruction": "Bob is an enthusiast for trains and loves to calculate the total time spent on each of his journeys. He is interested in knowing the actual time spent in transit and the total waiting time during his train travels. Bob's journey consists of multiple train rides with waiting times in between... | 0.611831 | Code_Contests_30052 | C | [
"compute_time_difference",
"format_time_difference",
"calc_travel_and_waiting_times",
"train_schedule"
] | 4 | [
[
"calc_travel_and_waiting_times",
"compute_time_difference"
],
[
"calc_travel_and_waiting_times",
"format_time_difference"
],
[
"train_schedule",
"calc_travel_and_waiting_times"
]
] | 3 | [] | false | [] | false | pytest | true | [] | true | 1356fe24b7f3ca0b2bc3cbf978e2b2ee429ddb83 | 83142c70ff83a7a0ec11276098204aa305e2492b | |||
v1.0 | complete | Code_Contests | Code_Contests_30276_C | def min_sum_path(matrix: List[List[int]]) -> int:
"""
Returns the sum of the numbers along the path that costs the least to traverse
from the top-left corner (0, 0) to the bottom-right corner (M-1, N-1).
Args:
matrix: List[List[int]] - A 2D list containing non-negative integers.
Returns:
i... | def min_sum_path(matrix):
"""
Returns the sum of the numbers along the path that costs the least to traverse
from the top-left corner (0, 0) to the bottom-right corner (M-1, N-1).
Args:
matrix: List[List[int]] - A 2D list containing non-negative integers.
Returns:
int - The minimum sum alo... | def test_min_sum_path():
matrix1 = [
[1, 3, 1],
[1, 5, 1],
[4, 2, 1]
]
assert min_sum_path(matrix1) == 7
matrix2 = [
[1, 2, 3],
[4, 5, 6]
]
assert min_sum_path(matrix2) == 12
matrix3 = [
[0, 0, 0],
[0, 0, 0]
]
assert min_sum_p... | [
{
"docstring": "Returns the sum of the numbers along the path that costs the least to traverse\nfrom the top-left corner (0, 0) to the bottom-right corner (M-1, N-1).\n\nArgs:\nmatrix: List[List[int]] - A 2D list containing non-negative integers.\n\nReturns:\nint - The minimum sum along the path.",
"functio... | [
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 minPathSum(matrix):\n \"\"\"\n Returns the sum of all numbers along the path that costs the least\n from the top-left corner to the bottom-rig... | trial_gpt4o_1 | {
"original_instruction": "You are given a matrix of size MxN filled with non-negative integers. A traversal from the top-left corner (0, 0) to the bottom-right corner (M-1, N-1) is performed, where at each step one can only move either right or down. Calculate the sum of all numbers along the path that costs the lea... | 0.712064 | Code_Contests_30276 | C | [
"min_sum_path",
"solve"
] | 2 | [
[
"solve",
"min_sum_path"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | 59e1b1ecadc70b34e6b3916f57f09ecb15a9f951 | 4bc9edcc6570999507516fe3f6af4646347a002f | |||
v1.0 | complete | Code_Contests | Code_Contests_30590_C | from typing import List
def max_tasks_completed(t: int, test_cases: List[List[List[int]]]) -> List[int]:
""" Determines the maximum number of tasks that can be completed given the
employees and their skills.
Args:
t (int): The number of test cases.
test_cases (List[List[List[int]]]): A... | from typing import List, Set
def can_handle(task: Set[int], employee_skills: Set[int]) -> bool:
return task.issubset(employee_skills)
def max_tasks_completed(t: int, test_cases: List[List[List[int]]]) -> List[int]:
results = []
for case in test_cases:
n, m = case[0]
employee_skills = [set(... | from solution import max_tasks_completed
def test_single_case_simple():
t = 1
test_cases = [
[
[3, 3],
[2, 1, 2],
[3, 2, 3, 4],
[1, 5],
[1, 1],
[2, 1, 4],
[2, 2, 5]
]
]
assert max_tasks_completed(t, test... | [
{
"docstring": null,
"function_declaration": "def can_handle(task, employee_skills):",
"function_name": "can_handle",
"parameter_list": "(task, employee_skills)"
},
{
"docstring": null,
"function_declaration": "def max_tasks_completed(t, test_cases):",
"function_name": "max_tasks_com... | [
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_complete_task(employee_skills, task_requirements):\n \"\"\"\n Check if the given employee can complete the given task.\n \"\"\"\n retur... | trial_gpt4o_4 | {
"original_instruction": "A company is planning a new project and needs to distribute their employees across various tasks. Each employee has a specific set of skills, and each task requires a minimum set of skills to be effectively completed. You need to determine the maximum number of tasks that can be completed i... | 0.611064 | Code_Contests_30590 | C | [
"can_handle",
"max_tasks_completed"
] | 2 | [
[
"max_tasks_completed",
"can_handle"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | a02e6881e9a87601f2535458edf8d6d1d72ccd2a | 1c3028ce2e02e5742fea0f1a47cdb8873cd26dc2 | |||
v1.0 | complete | Code_Contests | Code_Contests_30152_C | from typing import List, Tuple
def find_frequent_path_sum(n: int, nodes: List[Tuple[int, int, int]]) -> int:
"""
Given a binary tree, find the most frequent sum of root-to-leaf paths.
Args:
n (int): the number of nodes in the tree.
nodes (List[Tuple[int, int, int]]): a list of nodes, where each no... | from collections import defaultdict, deque
class TreeNode:
def __init__(self, value):
self.value = value
self.left = None
self.right = None
def build_tree(node_list):
if not node_list:
return None
nodes = {}
for v, l, r in node_list:
if v not in nodes:
... | def test_basic_case():
n = 5
nodes = [
(1, 2, 3),
(2, 4, -1),
(3, -1, 5),
(4, -1, -1),
(5, -1, -1)
]
assert find_frequent_path_sum(n, nodes) == 7
def test_single_node():
n = 1
nodes = [
(10, -1, -1)
]
assert find_frequent_path_sum(n, n... | [] | [
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 defaultdict, Counter\n\nclass TreeNode:\n def __init__(self, val=0, left=None, right=None):\n self.val = val\n sel... | trial_gpt4o_1 | {
"original_instruction": "Your task is to write a program that finds the most frequent sum of paths in a binary tree. Given a binary tree, you need to calculate the sum of values on each root-to-leaf path and determine which sum appears the most frequently.\n\nInput:\n\nThe first line contains an integer n, represen... | 0.571728 | Code_Contests_30152 | C | [
"build_tree",
"find_frequent_path_sum"
] | 2 | [
[
"find_frequent_path_sum",
"build_tree"
]
] | 1 | [] | false | [
"TreeNode"
] | true | pytest | false | [] | true | 4e4f3385d6e9f50d1582f2cb11a8f446ff238870 | f64555c422221c238e4d7f2da74d4fd84b51b983 | |||
v1.0 | complete | Code_Contests | Code_Contests_30140_C | def solve(input_lines: str) -> str:
""" Given an undirected graph G with N vertices and M edges,
determine if there's a path between given pairs of vertices.
Input:
5 4
1 2
2 3
3 4
4 5
3
1 5
2 4
5 1
Output:
YES
YES
YES
Input:
4 2
1 2... | def find_parent(parent, i):
if parent[i] == i:
return i
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[yroot]:
... | def test_example_case_1():
input_data = "5 4\n1 2\n2 3\n3 4\n4 5\n3\n1 5\n2 4\n5 1\n"
assert solve(input_data) == "YES\nYES\nYES"
def test_example_case_2():
input_data = "4 2\n1 2\n3 4\n2\n1 3\n4 2\n"
assert solve(input_data) == "NO\nNO"
def test_example_case_3():
input_data = "6 5\n1 2\n2 3\n1 4\... | [
{
"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,
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 return find(parent, parent[i])\n\ndef union(parent, rank, x, y):\n rootX = find(pare... | trial_gpt4o_1 | {
"original_instruction": "Given is an undirected graph G with N vertices and M edges. A path is defined as a sequence of edges that connects two vertices without revisiting any vertex.\n\nYou are given Q queries, where query i asks if there exists a path between Vertex U_i and Vertex V_i (1 \\leq U_i, V_i \\leq N an... | 0.701123 | Code_Contests_30140 | C | [
"find_parent",
"union",
"is_connected",
"solve"
] | 4 | [
[
"is_connected",
"find_parent"
],
[
"is_connected",
"union"
],
[
"solve",
"is_connected"
],
[
"union",
"find_parent"
]
] | 4 | [] | false | [] | false | pytest | false | [] | true | 3363064bafe46c8ad25722f4984108dc692b8b1f | eabc57e7876334c10d9825aad5d38cc36ba9ec8c | |||
v1.0 | complete | Code_Contests | Code_Contests_30886_C | def shortest_path(n: int, m: int, q: int, edges: List[Tuple[int, int, int]], queries: List[Tuple[int, int]]) -> List[int]:
"""
Determine the shortest communication path between different pairs of computers.
n: int : Number of computers.
m: int : Number of bi-directional communication channels.
q: ... | import heapq
def floyd_warshall(n, edges):
dist = [[float('inf')] * n for _ in range(n)]
for i in range(n):
dist[i][i] = 0
for u, v, l in edges:
dist[u-1][v-1] = min(dist[u-1][v-1], l)
dist[v-1][u-1] = min(dist[v-1][u-1], l)
for k in range(n):
for i in range(n):
... | def test_shortest_path_example_1():
assert shortest_path(
4, 4, 2,
[(1, 2, 4), (1, 3, 2), (2, 3, 1), (3, 4, 7)],
[(1, 4), (2, 3)]
) == [9, 1]
def test_shortest_path_example_2():
assert shortest_path(
5, 3, 3,
[(1, 2, 3), (1, 3, 10), (4, 5, 1)],
[(1, 4), (1, 5... | [
{
"docstring": null,
"function_declaration": "def floyd_warshall(n, edges):",
"function_name": "floyd_warshall",
"parameter_list": "(n, edges)"
},
{
"docstring": null,
"function_declaration": "def shortest_path(n, m, q, edges, queries):",
"function_name": "shortest_path",
"parame... | [
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": "import heapq\n\ndef find_shortest_paths(n, m, q, edges, queries):\n \"\"\"\n Uses Dijkstra's algorithm to find the shortest paths in a weighted graph... | trial_gpt4o_2 | {
"original_instruction": "Jenna is working on a network of computers connected with direct communication channels. The network consists of n computers and m bi-directional communication channels. Each communication channel has a latency value. Jenna needs to perform q queries on the network to determine the shortest... | 0.607104 | Code_Contests_30886 | C | [
"floyd_warshall",
"shortest_path"
] | 2 | [
[
"shortest_path",
"floyd_warshall"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | 2b1de468af7d338823e25e8f25a2a73c1e851105 | 5d800ab5ffd9623cd1b7bd35ca5bafe8f65d9eb4 | |||
v1.0 | complete | Code_Contests | Code_Contests_30682_C | from typing import List, Tuple
def simplify_fraction(numerator: int, denominator: int) -> Tuple[int, int]:
""" Simplifies the fraction by dividing the numerator and denominator by their greatest common divisor (GCD).
>>> simplify_fraction(4, 6)
(2, 3)
>>> simplify_fraction(2, 4)
(1, 2)
"""
... | from math import gcd
def simplify_fraction(numerator, denominator):
"""
Simplifies the fraction by dividing the numerator and denominator by their greatest common divisor (GCD).
"""
common_divisor = gcd(numerator, denominator)
return numerator // common_divisor, denominator // common_divisor
def a... | from solution import are_equivalent, check_equivalence
def test_simplify_fraction():
from solution import simplify_fraction
assert simplify_fraction(4, 6) == (2, 3)
assert simplify_fraction(2, 4) == (1, 2)
assert simplify_fraction(10, 25) == (2, 5)
assert simplify_fraction(5, 25) == (1, 5)
asse... | [
{
"docstring": "Simplifies the fraction by dividing the numerator and denominator by their greatest common divisor (GCD).",
"function_declaration": "def simplify_fraction(numerator, denominator):",
"function_name": "simplify_fraction",
"parameter_list": "(numerator, denominator)"
},
{
"docst... | [
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 fractions import Fraction\n\ndef are_equivalent_rationals(pair):\n \"\"\"\n Determines if two rational numbers in the given pair are equivalent.... | trial_gpt4o_1 | {
"original_instruction": "Rational numbers can be expressed as the ratio of two integers. Two rational numbers are considered to be equivalent if they reduce to the same fraction in their simplest forms. Write a program to determine if given pairs of rational numbers are equivalent.\n\nEach test case consists of a s... | 0.678717 | Code_Contests_30682 | C | [
"simplify_fraction",
"are_equivalent",
"check_equivalence"
] | 3 | [
[
"are_equivalent",
"simplify_fraction"
],
[
"check_equivalence",
"are_equivalent"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 8b584792e88e38fe12c9644af35165a91409eaf6 | 25d884fe222772034ae1cb106cfbec9c4c6ae795 | |||
v1.0 | complete | Code_Contests | Code_Contests_30045_C | def is_prime(n: int) -> bool:
""" Check if a number is a prime number.
>>> is_prime(1)
False
>>> is_prime(2)
True
>>> is_prime(3)
True
>>> is_prime(4)
False
>>> is_prime(17)
True
>>> is_prime(18)
False
"""
def sum_primes_in_range(a: int, b: int) -> int:
""" C... | 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 sum_primes_in_range(a, b):
prime_sum =... | from solution import is_prime, sum_primes_in_range, solve_primes_sum
def test_is_prime():
assert is_prime(1) == False
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_sum_primes_in_range():
a... | [
{
"docstring": null,
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": null,
"function_declaration": "def sum_primes_in_range(a, b):",
"function_name": "sum_primes_in_range",
"parameter_list": "(a, b)"
},
{
... | [
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(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_2 | {
"original_instruction": "Problem description\n\nJohn is a computer scientist who is fascinated with numbers. He recently came across a peculiar problem and needs your expertise to solve it. He has two integers, a and b, and he wants to calculate the sum of all the prime numbers in the range [a, b] inclusive.\n\nA p... | 0.637689 | Code_Contests_30045 | C | [
"is_prime",
"sum_primes_in_range",
"solve_primes_sum"
] | 3 | [
[
"solve_primes_sum",
"sum_primes_in_range"
],
[
"sum_primes_in_range",
"is_prime"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | ffcc8a9e9cd7aecf0f5e3fa2ea0abc4517e8b607 | 81c76c5b262aee107d45dde583b7b2afefd2f218 | |||
v1.0 | complete | Code_Contests | Code_Contests_30169_C | def solve(grid_data):
"""
Given the initial state of the canvas, determine the minimum number of color changes that the painter needs to make to achieve the desired pattern.
Input: A list of strings where the first element is the number of test cases (T).
For each test case, the next elemen... | def min_color_changes(T, test_cases):
results = []
def calculate_changes(grid, pattern1, pattern2):
changes1 = changes2 = 0
for i in range(len(grid)):
for j in range(len(grid[0])):
if grid[i][j] != pattern1[i % 2][j % 2]:
changes1 += 1
... | from solution import solve
def test_case_1():
input_data = [
"2",
"3 3",
"RRB", "BRB", "RRB",
"2 2",
"RR", "BB"
]
expected_output = [4, 2]
assert solve(input_data) == expected_output
def test_case_2():
input_data = [
"1",
"2 3",
... | [
{
"docstring": null,
"function_declaration": "def min_color_changes(T, test_cases):",
"function_name": "min_color_changes",
"parameter_list": "(T, test_cases)"
},
{
"docstring": null,
"function_declaration": "def solve(grid_data):",
"function_name": "solve",
"parameter_list": "(g... | [
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 min_color_changes_to_create_pattern(T, test_cases):\n def count_changes(grid, pattern, n, m):\n changes = 0\n for i in range(n):\n ... | trial_gpt4o_6 | {
"original_instruction": "A painter has a canvas with a grid of cells, each cell initially colored with either red (R) or blue (B). The painter wants to create a pattern where no two adjacent cells (horizontally or vertically) have the same color. To achieve this, the painter can change the color of a cell from red ... | 0.726905 | Code_Contests_30169 | C | [
"min_color_changes",
"solve"
] | 2 | [
[
"solve",
"min_color_changes"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | a5eb0b3c9f72cef3354ef0c12982cdec7adefed9 | d459f8398ea221878268fa85a55f5af87419916b | |||
v1.0 | complete | Code_Contests | Code_Contests_30955_C | def sum_of_digits(n: int) -> int:
"""
Returns the sum of digits of the given number n.
>>> sum_of_digits(1) 1
>>> sum_of_digits(4) 4
>>> sum_of_digits(16) 7
>>> sum_of_digits(25) 7
>>> sum_of_digits(100) 1
"""
pass # Implement this function
def generate_sequence(n: int) -> List[int... | def sum_of_digits(n):
"""
Returns the sum of digits of the given number n.
"""
return sum(int(digit) for digit in str(n))
def generate_sequence(n):
"""
Generates the first n terms of the sequence where each term is the sum of the digits
of the square of the index of that term.
"""
s... | from solution import sum_of_digits, generate_sequence
def test_sum_of_digits():
assert sum_of_digits(1) == 1
assert sum_of_digits(4) == 4
assert sum_of_digits(16) == 1 + 6
assert sum_of_digits(25) == 2 + 5
assert sum_of_digits(100) == 1 + 0 + 0
def test_generate_sequence():
assert generate... | [
{
"docstring": "Returns the sum of digits of the given number n.",
"function_declaration": "def sum_of_digits(n):",
"function_name": "sum_of_digits",
"parameter_list": "(n)"
},
{
"docstring": "Generates the first n terms of the sequence where each term is the sum of the digits\nof the square... | [
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 generate_sequence(n):\n \"\"\"\n Generates the first n terms of the sequence where each term is \n the sum of the digits of the square of the ... | trial_gpt4o_1 | {
"original_instruction": "Alex loves creating patterns with numbers. Recently, he came across an interesting problem: given a positive integer n, generate the first n terms of the sequence where each term is the sum of the digits of the square of the index of that term. Specifically, the k-th term of the sequence sh... | 0.724753 | Code_Contests_30955 | C | [
"sum_of_digits",
"generate_sequence"
] | 2 | [
[
"generate_sequence",
"sum_of_digits"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 6953e1b71d22d0602df0ab038409ae112f606817 | b739b89665452663ea7d18781c317265e19bb843 | |||
v1.0 | complete | Code_Contests | Code_Contests_30248_C | def prime_factors_count_up_to_m(M):
"""
Returns a list where the value at index i is the number of prime factors of i.
The returned list covers the range from 1 to M (inclusive).
"""
# Implement the function to return prime factors count up to M
pass
def sum_prime_factor_counts(T, test_cases):
... | def prime_factors_count_up_to_m(M):
"""
Returns a list where the value at index i is the number of prime factors of i.
The returned list covers the range from 1 to M (inclusive).
"""
# Initialize a list for counting prime factors.
factor_counts = [0] * (M + 1)
# Perform a sieve-like app... | import pytest
from solution import main, parse_input, sum_prime_factor_counts, prime_factors_count_up_to_m
def test_prime_factors_count_up_to_m():
assert prime_factors_count_up_to_m(5) == [0, 0, 1, 1, 2, 1]
assert prime_factors_count_up_to_m(10) == [0, 0, 1, 1, 2, 1, 2, 1, 3, 2, 2]
def test_sum_prime_factor_c... | [
{
"docstring": "Returns a list where the value at index i is the number of prime factors of i.\nThe returned list covers the range from 1 to M (inclusive).",
"function_declaration": "def prime_factors_count_up_to_m(M):",
"function_name": "prime_factors_count_up_to_m",
"parameter_list": "(M)"
},
... | [
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 compute_prime_factors_sum_for_range(M):\n \"\"\"\n Computes the sum of the number of prime factors (including multiplicity) for each integer from... | trial_gpt4o_2 | {
"original_instruction": "Alex is highly interested in number theory, particularly in prime numbers and their interesting properties. One day, he decided to play with the prime factorization of numbers. He wants to determine the sum of the number of prime factors (including multiplicity) for each integer from 1 to a... | 0.727426 | Code_Contests_30248 | C | [
"prime_factors_count_up_to_m",
"sum_prime_factor_counts",
"parse_input",
"main"
] | 4 | [
[
"sum_prime_factor_counts",
"prime_factors_count_up_to_m"
]
] | 1 | [
"parse_input"
] | false | [] | false | pytest | true | [] | true | 1dfa17af36030a669211185c96ef18e8325cdfb2 | b537088c1bb970224dd160b9a933d3d450099bc2 | |||
v1.0 | complete | Code_Contests | Code_Contests_30299_C | def longest_road_to_remove(n: int, m: int, roads: List[Tuple[int, int, int]]) -> int:
""" Monica is designing a ring road network for a new city. The city has n intersections connected by m bidirectional roads. Each road has a specific length in kilometers. Monica wants to identify the longest road in the city that... | from collections import defaultdict
import heapq
def find(parent, x):
if parent[x] != x:
parent[x] = find(parent, parent[x])
return parent[x]
def union(parent, rank, x, y):
rootX = find(parent, x)
rootY = find(parent, y)
if rootX != rootY:
if rank[rootX] > rank[rootY]:
... | from solution import longest_road_to_remove
def test_example():
n, m = 5, 6
roads = [
(1, 2, 3),
(1, 3, 4),
(2, 3, 2),
(3, 4, 6),
(4, 5, 5),
(2, 5, 8)
]
assert longest_road_to_remove(n, m, roads) == 8
def test_no_removable_road():
n, m = 3, 3
roa... | [
{
"docstring": null,
"function_declaration": "def find(parent, x):",
"function_name": "find",
"parameter_list": "(parent, x)"
},
{
"docstring": null,
"function_declaration": "def union(parent, rank, x, y):",
"function_name": "union",
"parameter_list": "(parent, rank, x, y)"
},
... | [
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 find_longest_safely_removable_road(n, m, roads):\n # Helper function to perform Union-Find operations\n parent = list(range(n))\n rank = [0] *... | trial_gpt4o_5 | {
"original_instruction": "Monica is designing a ring road network for a new city. The city has n intersections connected by m bidirectional roads. Each road has a specific length in kilometers. Monica wants to identify the longest road in the city that, when removed, does not change the city from being fully connect... | 0.661974 | Code_Contests_30299 | C | [
"find",
"union",
"kruskal",
"longest_road_to_remove"
] | 4 | [
[
"kruskal",
"find"
],
[
"kruskal",
"union"
],
[
"longest_road_to_remove",
"kruskal"
],
[
"union",
"find"
]
] | 4 | [] | false | [] | false | pytest | true | [] | true | 820d64795fe758147e5da41404110638c58cf982 | 38899183fff02be264a1506e181d56a61a0e3fd2 | |||
v1.0 | complete | Code_Contests | Code_Contests_30562_C | from typing import List
def is_prime(n: int) -> bool:
"""Return True if n is prime, else False"""
pass
def prime_sum_subarrays(n: int, a: List[int]) -> str:
"""
Given an array of integers, determine if there exist two non-overlapping subarrays
with sums equal to the same prime number.
>>... | def is_prime(n):
"""Return True if n is prime, 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 False
i += 6
return True... | from solution import prime_sum_subarrays
def test_case_1():
assert prime_sum_subarrays(7, [1, 2, 3, 6, 10, 3, 7]) == "YES"
def test_case_2():
assert prime_sum_subarrays(4, [4, 6, 8, 12]) == "NO"
def test_case_3():
assert prime_sum_subarrays(5, [1, 2, 1, 2, 3]) == "YES"
def test_case_4():
assert prim... | [
{
"docstring": "Return True if n is prime, else False",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": null,
"function_declaration": "def prime_sum_subarrays(n, a):",
"function_name": "prime_sum_subarrays",
"para... | [
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_prime(n):\n \"\"\"Returns True if n is a prime number, False otherwise.\"\"\"\n if n <= 1:\n return False\n if n <= 3:\n retu... | trial_gpt4o_2 | {
"original_instruction": "Petya is an avid fan of prime numbers. One day, Petya was given an array of integers and asked to perform a special operation on it. An operation consists of choosing two non-overlapping subarrays (segments) such that the sum of the elements in both subarrays is equal to the same prime numb... | 0.669536 | Code_Contests_30562 | C | [
"is_prime",
"prime_sum_subarrays"
] | 2 | [
[
"prime_sum_subarrays",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 3901953a7200ff6a58bf4adc487939c5204bef6d | a0f1a4318a9a36fb613a25c31839f8e617e09a64 | |||
v1.0 | complete | Code_Contests | Code_Contests_30707_C | from typing import List
def longest_substring_with_two_chars(s: str) -> str:
"""Find the longest substring in the given DNA sequence that contains at most two different characters.
Args:
s (str): A string representing the DNA sequence.
Returns:
str: The longest substring with ... | def longest_substring_with_two_chars(s):
from collections import defaultdict
# Sliding window approach with two pointers
left = 0
right = 0
max_substring = ""
char_map = defaultdict(int)
while right < len(s):
char_map[s[right]] += 1
while len(char_map) > 2:
cha... | def test_longest_substring_with_two_chars():
assert longest_substring_with_two_chars("GATTACA") == "ATTA"
assert longest_substring_with_two_chars("CGCGATTA") == "CGCG"
assert longest_substring_with_two_chars("A") == "A"
assert longest_substring_with_two_chars("AAAA") == "AAAA"
assert longest_substri... | [
{
"docstring": null,
"function_declaration": "def longest_substring_with_two_chars(s):",
"function_name": "longest_substring_with_two_chars",
"parameter_list": "(s)"
},
{
"docstring": null,
"function_declaration": "def process_sequences(sequences):",
"function_name": "process_sequenc... | [
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 longest_substring_two_chars(dna):\n \"\"\"\n Finds the longest substring containing at most two different characters.\n \"\"\"\n max_length... | trial_gpt4o_2 | {
"original_instruction": "A DNA sequence is represented by a string consisting of the characters 'A', 'C', 'G', and 'T'. Given a DNA sequence, your task is to find the longest substring that contains at most two different characters. If there are multiple substrings with the same length, return the leftmost one.\n\n... | 0.647216 | Code_Contests_30707 | C | [
"longest_substring_with_two_chars",
"process_sequences"
] | 2 | [
[
"process_sequences",
"longest_substring_with_two_chars"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | 44464d9692a42415542f92a1112440a5b0025acf | 200070e68ce9d9fe18796eebad3176f8216cce22 | |||
v1.0 | complete | Code_Contests | Code_Contests_30406_C | class TreeNode:
def __init__(self, value):
self.value = value
self.left = None
self.right = None
def build_tree(node_descriptions, k):
""" Construct a binary tree given the node descriptions.
Args:
node_descriptions: A list of tuples (p, l, r) where p is the parent node,
... | class TreeNode:
def __init__(self, value):
self.value = value
self.left = None
self.right = None
def build_tree(node_descriptions, k):
nodes = {i: TreeNode(i) for i in range(1, k + 1)}
for parent, left, right in node_descriptions:
if left != 0:
nodes[parent].lef... | def test_build_tree_single_node():
k = 1
node_descriptions = [(1, 0, 0)]
root = build_tree(node_descriptions, k)
assert root.value == 1
assert root.left == None
assert root.right == None
def test_build_tree():
k = 3
node_descriptions = [(1, 2, 3), (2, 0, 0), (3, 0, 0)]
root = build_... | [] | [
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\nde... | trial_gpt4o_2 | {
"original_instruction": "In a special school for programming, the students have a peculiar tradition. Each year, they select an integer k (1 ≤ k ≤ 100) and build a binary tree with k nodes. Each node in the tree has a unique value from 1 to k. To enhance their programming skills, students are given a task to transf... | 0.53809 | Code_Contests_30406 | C | [
"build_tree",
"in_order_traversal",
"canonical_form"
] | 3 | [
[
"canonical_form",
"build_tree"
],
[
"canonical_form",
"in_order_traversal"
]
] | 2 | [] | false | [
"TreeNode"
] | true | pytest | false | [] | true | c1bfebca7b9b6e660a90fe999e8d416fa793b954 | 600a6c62626257b92a94ee851197493a00410232 | |||
v1.0 | complete | Code_Contests | Code_Contests_30769_C | def min_additional_routes(n, m, routes):
""" Find the minimum number of additional routes required to make the network fully connected.
n: int - number of stations
m: int - number of existing direct routes
routes: List[Tuple[int, int]] - list of existing routes
Returns: int - minimum number of addit... | def find_root(parent, i):
if parent[i] == i:
return i
else:
return find_root(parent, parent[i])
def union(parent, rank, x, y):
root_x = find_root(parent, x)
root_y = find_root(parent, y)
if root_x != root_y:
if rank[root_x] > rank[root_y]:
parent[root_y] = root_... | from solution import min_additional_routes
def test_single_station():
assert min_additional_routes(1, 0, []) == 0
def test_double_disconnected():
assert min_additional_routes(4, 2, [(1, 2), (3, 4)]) == 1
def test_larger_disconnected():
assert min_additional_routes(5, 3, [(1, 2), (2, 3), (4, 5)]) == 1
de... | [
{
"docstring": null,
"function_declaration": "def find_root(parent, i):",
"function_name": "find_root",
"parameter_list": "(parent, i)"
},
{
"docstring": null,
"function_declaration": "def union(parent, rank, x, y):",
"function_name": "union",
"parameter_list": "(parent, rank, x,... | [
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_min_additional_routes(n, m, connections):\n parent = list(range(n))\n\n def find(x):\n if parent[x] == x:\n return x\n ... | trial_gpt4o_2 | {
"original_instruction": "An imaginary city has a unique transportation system consisting of multiple train routes where each route connects exactly two stations. Each station can be connected to multiple other stations, forming a network. \n\nThe city's transportation planner wants to ensure that there exists a way... | 0.633942 | Code_Contests_30769 | C | [
"find_root",
"union",
"min_additional_routes"
] | 3 | [
[
"min_additional_routes",
"find_root"
],
[
"min_additional_routes",
"union"
],
[
"union",
"find_root"
]
] | 3 | [] | false | [] | false | pytest | true | [] | true | dc86decb0be00773d577ada307ee07c22eaf6780 | 99a1633b68086dfffe74cf399f96a84c1d72d912 | |||
v1.0 | complete | Code_Contests | Code_Contests_30316_C | from typing import List, Tuple
def update_value(values: List[int], x: int, y: int):
"""Updates the value at node x to y."""
values[x-1] = y
def max_shortest_path_value(graph: List[List[int]], values: List[int], x: int, y: int) -> int:
"""Finds the maximum shortest path value between nodes x and y.
Arg... | import heapq
def update_value(values, x, y):
values[x-1] = y
def max_shortest_path_value(graph, values, x, y):
n = len(values)
INF = float('inf')
dist = [INF] * n
visited = [False] * n
max_values = [0] * n
pq = []
dist[x-1] = 0
max_values[x-1] = values[x-1]
heapq.heappush(... | def test_update_value():
values = [5, 3, 8, 6, 2]
update_value(values, 2, 10)
assert values == [5, 10, 8, 6, 2]
def test_max_shortest_path_value():
n, m = 5, 5
values = [5, 3, 8, 6, 2]
edges = [(1, 2), (2, 3), (1, 4), (4, 5), (3, 5)]
graph = [[] for _ in range(n)]
for u, v in edges:
... | [
{
"docstring": null,
"function_declaration": "def update_value(values, x, y):",
"function_name": "update_value",
"parameter_list": "(values, x, y)"
},
{
"docstring": null,
"function_declaration": "def max_shortest_path_value(graph, values, x, y):",
"function_name": "max_shortest_path... | [
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": "from heapq import heappop, heappush\nfrom collections import defaultdict, deque\n\nINF = float('inf')\n\ndef dijkstra_max_value(n, adj_list, start, values)... | trial_gpt4o_2 | {
"original_instruction": "There are n nodes in a network, numbered from 1 to n, connected by m bidirectional edges. Each node i has an associated value vi.\n\nNow, there are q queries you need to handle. There are two types of queries:\n\n * \"U x y\": Update the value at node x to y.\n * \"S x y\": Find the maxim... | 0.639744 | Code_Contests_30316 | C | [
"update_value",
"max_shortest_path_value",
"process_queries",
"main"
] | 4 | [
[
"process_queries",
"max_shortest_path_value"
],
[
"process_queries",
"update_value"
]
] | 2 | [
"process_queries"
] | false | [] | false | pytest | false | [] | true | 638da519d7fa39cc3fd8fc15a62b9cfbd56e340e | e4c4c1b5decf869df4fdc9c53d057585b2a41e8b | |||
v1.0 | complete | Code_Contests | Code_Contests_30262_C | def smooth_path(n: int, m: int, k: int, elevation_lines: List[str]) -> str:
""" Determine if there exists a smooth path from the upper-left corner to the bottom-right corner.
Args:
n (int): Number of rows in the grid.
m (int): Number of columns in the grid.
k (int): Maximum permitted elevation ... | def is_smooth_path(grid, n, m, k):
from collections import deque
directions = [(1, 0), (-1, 0), (0, 1), (0, -1)]
visited = [[False for _ in range(m)] for _ in range(n)]
queue = deque([(0, 0)])
visited[0][0] = True
while queue:
r, c = queue.popleft()
if r == n-1... | from solution import smooth_path
def test_smooth_path_case1():
n, m, k = 3, 3, 2
elevation_lines = [
"1 2 3",
"4 8 2",
"1 4 7"
]
assert smooth_path(n, m, k, elevation_lines) == "NO"
def test_smooth_path_case2():
n, m, k = 2, 2, 1
elevation_lines = [
"0 1",
... | [
{
"docstring": null,
"function_declaration": "def is_smooth_path(grid, n, m, k):",
"function_name": "is_smooth_path",
"parameter_list": "(grid, n, m, k)"
},
{
"docstring": null,
"function_declaration": "def smooth_path(n, m, k, elevation_lines):",
"function_name": "smooth_path",
... | [
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_smooth_path(n, m, k, grid):\n \"\"\"\n Determines if there exists a smooth path from the upper-left corner to the \n bottom-right corner of... | trial_gpt4o_2 | {
"original_instruction": "You are given a grid of size n × m filled with integers. Each integer in the grid represents the elevation of that cell. An elevation change between two adjacent cells (horizontally or vertically) is called a step. A path from the upper-left corner (0, 0) to the bottom-right corner (n-1, m-... | 0.525717 | Code_Contests_30262 | C | [
"is_smooth_path",
"smooth_path"
] | 2 | [
[
"smooth_path",
"is_smooth_path"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | a28430e7e50b056f5800ca66e26109ed1f8cd719 | 6f220fbb91db0dde8cb8fdd6730186036b1b22a0 | |||
v1.0 | complete | Code_Contests | Code_Contests_31320_C | MOD = 1000000007
def count_topological_orderings(n: int, m: int, edges: List[Tuple[int, int]]) -> int:
""" Determine the number of distinct topological orderings of a directed acyclic graph.
>>> count_topological_orderings(3, 2, [(1, 2), (2, 3)])
1
>>> count_topological_orderings(4, 3, [(1, 2), (1, 3),... | MOD = 1000000007
def count_topological_orderings(n, m, edges):
from functools import lru_cache
from itertools import permutations
graph = {i: [] for i in range(n)}
indegree = {i: 0 for i in range(n)}
for u, v in edges:
graph[u - 1].append(v - 1)
indegree[v - 1] += 1
@lru_cach... | from solution import solve_topological_orderings
def test_example_1():
graph_input = [
"3 2",
"1 2",
"2 3"
]
assert solve_topological_orderings(graph_input) == 1
def test_example_2():
graph_input = [
"4 3",
"1 2",
"1 3",
"3 4"
]
assert so... | [
{
"docstring": null,
"function_declaration": "def count_topological_orderings(n, m, edges):",
"function_name": "count_topological_orderings",
"parameter_list": "(n, m, edges)"
},
{
"docstring": null,
"function_declaration": "def solve_topological_orderings(graph_input):",
"function_n... | [
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": "MOD = 1000000007\n\ndef count_topological_orderings(n, m, edges):\n from functools import lru_cache\n from itertools import permutations\n\n graph... | trial_gpt4o_0 | {
"original_instruction": "John is studying algorithms and graph theory. He has encountered a problem involving directed acyclic graphs (DAGs). The problem is as follows:\n\nGiven a directed acyclic graph with `n` vertices and `m` edges, John needs to determine the number of distinct topological orderings of the grap... | 0.544995 | Code_Contests_31320 | C | [
"count_topological_orderings",
"solve_topological_orderings"
] | 2 | [
[
"solve_topological_orderings",
"count_topological_orderings"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 8bb8ad20ae98527513dd6463b9de232317ab2342 | dce541f06593ea5e78d5ac87dc67dd37c1d1c92b | |||
v1.0 | complete | Code_Contests | Code_Contests_30645_C | class TreeNode:
def __init__(self, value, left=None, right=None):
self.value = value
self.left = left
self.right = right
def is_balanced(root):
""" Helper function to check if the binary tree is balanced. """
def check_height(node):
if not node:
return 0, True
... | class TreeNode:
def __init__(self, value, left=None, right=None):
self.value = value
self.left = left
self.right = right
def is_balanced(root):
def check_height(node):
if not node:
return 0, True
left_height, left_balanced = check_height(node.left)
ri... | import pytest
from solution import is_binary_tree_balanced
def test_balanced_tree():
node_count = 5
node_list = [
(1, 2, 3),
(2, 4, 5),
(3, -1, -1),
(4, -1, -1),
(5, -1, -1)
]
assert is_binary_tree_balanced(node_count, node_list) == "YES"
def test_unbalanced_tre... | [] | [
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": "class TreeNode:\n def __init__(self, value, left=None, right=None):\n self.value = value\n self.left = left\n self.right = right\n\... | trial_gpt4o_0 | {
"original_instruction": "Binary Trees are a fundamental data structure in computer science. A binary tree is a hierarchical structure in which each node has at most two children, referred to as the left child and the right child.\n\nGiven a binary tree, your task is to determine if the tree is height-balanced. A he... | 0.743576 | Code_Contests_30645 | C | [
"is_balanced",
"build_tree",
"is_binary_tree_balanced"
] | 3 | [
[
"is_binary_tree_balanced",
"build_tree"
],
[
"is_binary_tree_balanced",
"is_balanced"
]
] | 2 | [] | false | [
"TreeNode"
] | true | pytest | true | [] | true | 86bdae724d3b0a410c6bca8f53f31d0aeef29deb | 54a5b4dd5f1781eaf96e51cd716a44191e1403c0 | |||
v1.0 | complete | Code_Contests | Code_Contests_31324_C | def is_prime(num: int) -> bool:
""" Check if a number is prime.
>>> is_prime(2) True
>>> is_prime(3) True
>>> is_prime(4) False
>>> is_prime(29) True
>>> is_prime(1) False
"""
def find_prime_sum_pair(n: int) -> str:
""" Determine if `n` can be expressed as the sum of two prime numbe... | def is_prime(num):
"""
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 False
i += 6... | from solution import find_prime_sum_pair, is_prime
def test_is_prime():
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(4) == False
assert is_prime(29) == True
assert is_prime(1) == False
def test_prime_sum_pair_34():
result = find_prime_sum_pair(34)
assert result.sta... | [
{
"docstring": "Check if a number is prime.",
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": "Determine if `n` can be expressed as the sum of two prime numbers.",
"function_declaration": "def find_prime_sum_pair(n):"... | [
1,
0
] | 1 | medium | 0.5 | {
"trial_gpt4o_0": null,
"trial_gpt4o_1": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared1_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 <=... | trial_gpt4o_1 | {
"original_instruction": "Given a number, determine if it can be expressed as the sum of two prime numbers. If the number can be expressed as the sum of two prime numbers, print \"YES\" followed by the pair of prime numbers. If there are multiple pairs, print any one of them. If the number cannot be expressed as the... | 0.781426 | Code_Contests_31324 | C | [
"is_prime",
"find_prime_sum_pair"
] | 2 | [
[
"find_prime_sum_pair",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | d28f2bd95b978649ec63e215dd1a6da09b5de5f1 | 17b9c060bbc8b0803595c0d42a33b56172f3170f | |||
v1.0 | complete | Code_Contests | Code_Contests_30994_C | def can_form_palindrome_with_one_edit(num_str: str) -> str:
"""
Determines if a number can be rearranged to form a palindrome with at most one digit change.
>>> can_form_palindrome_with_one_edit('12321') == 'Yes 12321'
>>> can_form_palindrome_with_one_edit('12121') == 'Yes 12121'
>>> can_form_palind... | def can_form_palindrome_with_one_edit(num_str):
"""
Determines if a number can be rearranged to form a palindrome with at most one digit change.
"""
n = len(num_str)
left, right = 0, n - 1
changes = 0
chars = list(num_str)
while left < right:
if chars[left] != chars[right]:
... | from solution import can_form_palindrome_with_one_edit, process_input_numbers
def test_can_form_palindrome_with_one_edit():
assert can_form_palindrome_with_one_edit('12321') == 'Yes 12321'
assert can_form_palindrome_with_one_edit('12121') == 'Yes 12121'
assert can_form_palindrome_with_one_edit('2002') == '... | [
{
"docstring": "Determines if a number can be rearranged to form a palindrome with at most one digit change.",
"function_declaration": "def can_form_palindrome_with_one_edit(num_str):",
"function_name": "can_form_palindrome_with_one_edit",
"parameter_list": "(num_str)"
},
{
"docstring": null... | [
0,
1
] | 1 | medium | 0.5 | {
"trial_gpt4o_0": null,
"trial_gpt4o_1": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared1_results_combined.jsonl",
"solution_code": "def can_form_palindrome_with_one_change(number):\n \"\"\"\n Determine if the digits of the given number can be rearranged to... | trial_gpt4o_2 | {
"original_instruction": "Dr. Azuma, an avid mathematician and puzzle enthusiast, has recently devised a new challenge involving palindrome numbers. He seeks your help to determine whether given numbers can be rearranged to form a palindrome with minimal changes.\n\nA palindrome number is a number that reads the sam... | 0.688827 | Code_Contests_30994 | C | [
"can_form_palindrome_with_one_edit",
"process_input_numbers"
] | 2 | [
[
"process_input_numbers",
"can_form_palindrome_with_one_edit"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 442bed72f3229127084f076779a8e9b5ef6cca2f | fb1e8bc68f8bc0d79d4b55e25867a34bc72e2f87 | |||
v1.0 | complete | Code_Contests | Code_Contests_31299_C | from typing import List
def is_palindrome(num: int) -> bool:
"""
Check if a given number is a palindrome.
"""
return str(num) == str(num)[::-1]
def next_palindrome(N: int) -> int:
"""
Find the smallest palindromic number greater than N.
>>> next_palindrome(123)
131
>>> next_palindr... | def is_palindrome(num):
"""
Check if a given number is a palindrome.
"""
return str(num) == str(num)[::-1]
def next_palindrome(N):
"""
Find the smallest palindromic number greater than N.
"""
N += 1
while not is_palindrome(N):
N += 1
return N
def find_next_palindromes(t... | from solution import find_next_palindromes, next_palindrome
def test_next_palindrome():
assert next_palindrome(123) == 131
assert next_palindrome(99) == 101
assert next_palindrome(1) == 2
assert next_palindrome(8) == 9
assert next_palindrome(808) == 818
assert next_palindrome(999) == 1001
def ... | [
{
"docstring": "Check if a given number is a palindrome.",
"function_declaration": "def is_palindrome(num):",
"function_name": "is_palindrome",
"parameter_list": "(num)"
},
{
"docstring": "Find the smallest palindromic number greater than N.",
"function_declaration": "def next_palindrome... | [
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 next_palindrome(N):\n \"\"\"\n Returns the smallest palindromic number greater than N.\n \"\"\"\n def is_palindrome(number):\n retur... | trial_gpt4o_2 | {
"original_instruction": "Eva loves numbers and is particularly fascinated by palindromic numbers - numbers that read the same forward and backward. One day, she decided to create a challenge for herself: finding the smallest palindromic number that is larger than a given integer N.\n\nA palindrome is a sequence tha... | 0.74897 | Code_Contests_31299 | C | [
"is_palindrome",
"next_palindrome",
"find_next_palindromes"
] | 3 | [
[
"find_next_palindromes",
"next_palindrome"
],
[
"next_palindrome",
"is_palindrome"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 9de8062847d4266584f64341f8db4d4b71f474b9 | e60d2be35f4240ea0a135611b30c9f05131f44dc | |||
v1.0 | complete | Code_Contests | Code_Contests_31069_C | from typing import List, Tuple
def find_shortest_paths(n: int, roads: List[Tuple[int, int, int]], queries: List[Tuple[int, int]]) -> List[int]:
"""
Find the shortest delivery routes between pairs of cities in Bellworld.
Args:
n: Number of cities.
roads: List of tuples where each tuple represe... | import sys
def floyd_warshall(n, dist):
for k in range(n):
for i in range(n):
for j in range(n):
if dist[i][j] > dist[i][k] + dist[k][j]:
dist[i][j] = dist[i][k] + dist[k][j]
def find_shortest_paths(n, roads, queries):
# Initialize the distances matrix w... | def test_single_dataset():
input_n = 3
input_r = 3
roads = [(1, 2, 5), (2, 3, 10), (1, 3, 15)]
queries = [(1, 3), (2, 1)]
expected_output = [15, -1]
assert find_shortest_paths(input_n, roads, queries) == expected_output
def test_no_path():
input_n = 4
input_r = 5
roads = [(1, 2... | [
{
"docstring": null,
"function_declaration": "def floyd_warshall(n, dist):",
"function_name": "floyd_warshall",
"parameter_list": "(n, dist)"
},
{
"docstring": null,
"function_declaration": "def find_shortest_paths(n, roads, queries):",
"function_name": "find_shortest_paths",
"pa... | [
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 floyd_warshall(n, roads):\n inf = float('inf')\n distances = [[inf] * n for _ in range(n)]\n\n for i in range(n):\n distances[i][i] = 0... | trial_gpt4o_2 | {
"original_instruction": "In Bellworld, there are n interconnected cities C1, C2, ..., Cn with one-way roads. Each road has a certain travel time. Your task is to help Bellworld's delivery company to find the shortest delivery routes between pairs of cities. \n\nYou will be given a list of roads between cities and a... | 0.737555 | Code_Contests_31069 | C | [
"floyd_warshall",
"find_shortest_paths"
] | 2 | [
[
"find_shortest_paths",
"floyd_warshall"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | 12941052909fd14f2e1eede9e0d922a7ace5fc61 | d778db61332b8fa8a5588f94d3f2cec030c9b1ae | |||
v1.0 | complete | Code_Contests | Code_Contests_31434_C | def min_subset_difference(arr):
"""
Returns the smallest possible absolute difference between the sums of two subsets.
>>> min_subset_difference([1, 6, 11, 5]) 1
>>> min_subset_difference([3, 1, 4]) 0
>>> min_subset_difference([10, 10, 10]) 10
>>> min_subset_difference([1, 2, 3, 4, 5]) 1
>>>... | def min_subset_difference(arr):
"""
Returns the smallest possible absolute difference between the sums of two subsets.
"""
total_sum = sum(arr)
n = len(arr)
# Initialize a 2D dp array
dp = [[False for _ in range(total_sum // 2 + 1)] for _ in range(n + 1)]
# Base case: it is alw... | def test_min_subset_difference():
assert min_subset_difference([1, 6, 11, 5]) == 1
assert min_subset_difference([3, 1, 4]) == 0
assert min_subset_difference([10, 10, 10]) == 10
assert min_subset_difference([1, 2, 3, 4, 5]) == 1
assert min_subset_difference([5]) == 5
def test_edge_cases():
asser... | [
{
"docstring": "Returns the smallest possible absolute difference between the sums of two subsets.",
"function_declaration": "def min_subset_difference(arr):",
"function_name": "min_subset_difference",
"parameter_list": "(arr)"
},
{
"docstring": null,
"function_declaration": "def solve()... | [
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 min_subset_difference(N, arr):\n total_sum = sum(arr)\n half_sum = total_sum // 2\n \n dp = [0] * (half_sum + 1)\n \n for num in arr:... | trial_gpt4o_1 | {
"original_instruction": "Given a list of N positive integers, you are required to partition this list into two subsets such that the sum of integers in each subset is as equal as possible. If there are multiple solutions, any valid one is acceptable. You need to output the difference between the sums of the two sub... | 0.655525 | Code_Contests_31434 | C | [
"min_subset_difference",
"solve"
] | 2 | [
[
"solve",
"min_subset_difference"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | 6fea6c10c3e74e7b750f94d1e7a230edad1fb7f4 | 590ee6f3e46ed51bbde4c0426d83f2106a9c51de | |||
v1.0 | complete | Code_Contests | Code_Contests_30670_C | from typing import List, Tuple
def merge_sort_and_count(arr: List[int]) -> Tuple[List[int], int]:
"""
Function to perform merge sort and count inversions in the array.
"""
if len(arr) <= 1:
return arr, 0
mid = len(arr) // 2
left, left_inv = merge_sort_and_count(arr[:mid])
right... | def merge_sort_and_count(arr):
"""
Function to perform merge sort and count inversions.
"""
if len(arr) <= 1:
return arr, 0
mid = len(arr) // 2
left, left_inv = merge_sort_and_count(arr[:mid])
right, right_inv = merge_sort_and_count(arr[mid:])
merged, split_inv = merge_and_coun... | from solution import count_inversions
def test_example_case_1():
arr = [2, 4, 1, 3, 5]
assert count_inversions(arr) == 3
def test_example_case_2():
arr = [5, 4, 3, 2, 1]
assert count_inversions(arr) == 10
def test_no_inversions():
arr = [1, 2, 3, 4, 5]
assert count_inversions(arr) == 0
def t... | [
{
"docstring": "Function to perform merge sort and count inversions.",
"function_declaration": "def merge_sort_and_count(arr):",
"function_name": "merge_sort_and_count",
"parameter_list": "(arr)"
},
{
"docstring": "Helper function to merge two sorted arrays and count inversions.",
"funct... | [
0,
0,
0,
0,
0,
0,
1,
0,
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 merge_and_count(arr, temp_arr, left, mid, right):\n i = left # Starting index for left subarray\n j = mid + 1 # Starting index for right subar... | trial_gpt4o_8 | {
"original_instruction": "A popular sorting algorithm is the merge sort algorithm. The beauty of merge sort is that it splits an array in half, recursively sorts the two halves, and then merges the sorted halves to produce a sorted whole. The process is efficient, yet intuitive.\n\nIn this problem, you are tasked wi... | 0.64129 | Code_Contests_30670 | C | [
"merge_sort_and_count",
"merge_and_count",
"count_inversions"
] | 3 | [
[
"count_inversions",
"merge_sort_and_count"
],
[
"merge_sort_and_count",
"merge_and_count"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | ff647ab3c6c552cafeee111697a5cc916ed3a207 | 642a377f8dabe5c2eb17314ba4d3ce7f542a1a28 | |||
v1.0 | complete | Code_Contests | Code_Contests_31616_C | def is_prime(n: int) -> bool:
""" Returns True if n is a prime number, otherwise False.
>>> is_prime(2)
True
>>> is_prime(4)
False
"""
def find_goldbach_pair(E: int) -> (int, int):
""" Returns two prime numbers P1 and P2 such that E = P1 + P2.
>>> find_goldbach_pair(20)
(3, 17)
... | def is_prime(n):
"""
Returns True if n is a prime number, otherwise False.
"""
if n < 2:
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 find_go... | from solution import is_prime, find_goldbach_pair
def test_is_prime():
# Test known prime numbers
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(5) == True
assert is_prime(11) == True
# Test known non-prime numbers
assert is_prime(1) == False
assert is_prime(4) =... | [
{
"docstring": "Returns True if n is a prime number, otherwise False.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Returns two prime numbers P1 and P2 such that E = P1 + P2.",
"function_declaration": "def find_goldb... | [
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(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_1 | {
"original_instruction": "Alex enjoys solving puzzles and recently discovered an interesting problem involving prime numbers. He read about the Goldbach Conjecture, which asserts that every even integer greater than 2 can be expressed as the sum of two prime numbers. He's thrilled and decides to write a program that... | 0.648385 | Code_Contests_31616 | C | [
"is_prime",
"find_goldbach_pair"
] | 2 | [
[
"find_goldbach_pair",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 1f19ebd5b11ac117cffa724d1d46418d927bdb08 | 7b8e1f3151321559113dd4db1a805a668924b95f | |||
v1.0 | complete | Code_Contests | Code_Contests_30163_C | import heapq
from typing import List, Tuple
def dijkstra(n: int, edges: List[Tuple[int, int, int]], start: int, end: int) -> int:
"""
Determines the minimum travel time from station start to station end using Dijkstra's algorithm.
:param n: The number of stations.
:param edges: A list of tuples (u... | import heapq
def dijkstra(n, edges, start, end):
"""
Determines the minimum travel time from station start to station end using Dijkstra's algorithm.
:param n: The number of stations.
:param edges: A list of tuples (u, v, t) representing the tracks between stations u and v with time t.
:param ... | from solution import find_minimum_travel_time
def test_case_1():
assert find_minimum_travel_time(5, 7, [(1, 2, 4), (1, 3, 2), (2, 4, 7), (3, 4, 1), (3, 5, 3), (4, 5, 2), (2, 3, 5)], 1, 5) == 5
def test_case_2():
assert find_minimum_travel_time(3, 3, [(1, 2, 1), (2, 3, 1), (1, 3, 4)], 1, 3) == 2
def test_case... | [
{
"docstring": "Determines the minimum travel time from station start to station end using Dijkstra's algorithm.\n\n:param n: The number of stations.\n:param edges: A list of tuples (u, v, t) representing the tracks between stations u and v with time t.\n:param start: The starting station.\n:param end: The dest... | [
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": "import heapq\n\ndef dijkstra(n, edges, start, end):\n \"\"\"\n Determines the minimum travel time from station start to station end using Dijkstra's ... | trial_gpt4o_0 | {
"original_instruction": "problem\n\nYou are a software engineer working on optimizing a railway system database. The railway system consists of multiple stations connected by train lines. Each station has multiple tracks, each with a specific travel time. Given a set of stations and tracks, your goal is to determin... | 0.695253 | Code_Contests_30163 | C | [
"dijkstra",
"find_minimum_travel_time"
] | 2 | [
[
"find_minimum_travel_time",
"dijkstra"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 6d62af10574a2f31df8d125d99f1964445f2369b | e01ef8efdef8353ab9444e9acbe5479713e3dfcd | |||
v1.0 | complete | Code_Contests | Code_Contests_31604_C | from typing import List, Tuple
def preprocess_matrix(matrix: List[List[int]]) -> List[List[int]]:
"""
Preprocess the matrix to create a prefix sum matrix.
"""
pass
def query_sum(prefix_sum: List[List[int]], r1: int, c1: int, r2: int, c2: int) -> int:
"""
Calculate the sum of the submatrix from... | def preprocess_matrix(matrix):
"""
Preprocess the matrix to create a prefix sum matrix.
"""
n = len(matrix)
m = len(matrix[0])
# Create a prefix sum matrix initialized with zeros
prefix_sum = [[0] * (m + 1) for _ in range(n + 1)]
# Fill the prefix sum matrix
for i in range(... | import pytest
from solution import preprocess_matrix, query_sum, matrix_sum_queries
def test_preprocess_matrix():
matrix = [
[1, 2, 3],
[4, 5, 6],
[7, 8, 9]
]
expected_prefix_sum = [
[0, 0, 0, 0],
[0, 1, 3, 6],
[0, 5, 12, 21],
[0, 12, 27, 45]
]
... | [
{
"docstring": "Preprocess the matrix to create a prefix sum matrix.",
"function_declaration": "def preprocess_matrix(matrix):",
"function_name": "preprocess_matrix",
"parameter_list": "(matrix)"
},
{
"docstring": "Calculate the sum of the submatrix from (r1, c1) to (r2, c2) using the prefix... | [
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 precompute_matrix_sums(matrix, n, m):\n \"\"\"\n Precomputes the sum of elements for all submatrices starting from (0,0) to (i,j) and stores them... | trial_gpt4o_2 | {
"original_instruction": "Alice loves playing with numbers and has recently started exploring matrices. She is curious about the sum of elements in a specific submatrix. Given a matrix and multiple queries, help Alice determine the sum of elements within each specified submatrix.\n\nInput:\nThe first line contains t... | 0.573048 | Code_Contests_31604 | C | [
"preprocess_matrix",
"query_sum",
"matrix_sum_queries"
] | 3 | [
[
"matrix_sum_queries",
"preprocess_matrix"
],
[
"matrix_sum_queries",
"query_sum"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 89cc467ea3309af739b4e4a6c9b4d2eafd81e75f | ef18d5c66a05f32777e724342a2aadb8e284c9d3 | |||
v1.0 | complete | Code_Contests | Code_Contests_31658_C | def minimal_steps(n: int, string_pairs: List[Tuple[str, str]]) -> List[int]:
""" Write a program that, given a list of string pairs, finds the minimum number of steps
required to transform the first string in each pair into the second string. A step consists
of either inserting, deleting, or replacing a s... | def minDistance(word1, word2):
"""
Given two words word1 and word2, this function returns the minimum number of operations
required to convert word1 to word2. You can insert, delete, or replace a character.
"""
m, n = len(word1), len(word2)
dp = [[0] * (n + 1) for _ in range(m + 1)]
for i i... | from solution import minimal_steps
def test_minimal_steps():
string_pairs = [
("horse", "ros"),
("intention", "execution")
]
result = minimal_steps(2, string_pairs)
assert result == [3, 5]
def test_minimal_steps_same_strings():
string_pairs = [
("abc", "abc")
]
res... | [
{
"docstring": "Given two words word1 and word2, this function returns the minimum number of operations\nrequired to convert word1 to word2. You can insert, delete, or replace a character.",
"function_declaration": "def minDistance(word1, word2):",
"function_name": "minDistance",
"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 min_steps_to_transform(str1, str2):\n \"\"\"\n Compute the minimum number of operations required to transform str1 into str2.\n An operation i... | trial_gpt4o_2 | {
"original_instruction": "Write a program that, given a list of string pairs, finds the minimum number of steps required to transform the first string in each pair into the second string. A step consists of either inserting, deleting, or replacing a single character.\n\nYou can assume the input strings will only con... | 0.642449 | Code_Contests_31658 | C | [
"minDistance",
"minimal_steps"
] | 2 | [
[
"minimal_steps",
"minDistance"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | b581f68e987fe10c0c9dc84ff30fdd79c4daef6f | 6c4c13ede72810cc023f4aefca365fe8d1f64f9f | |||
v1.0 | complete | Code_Contests | Code_Contests_31861_C | def minimum_total_tax(n: int, m: int, roads: List[Tuple[int, int, int]]) -> int:
""" Compute the minimum total tax the government can collect while maintaining the connectivity of all cities.
>>> minimum_total_tax(4, 5, [
... (1, 2, 1),
... (1, 3, 2),
... (1, 4, 3),
... (2, 3, 4),
... (3, 4,... | def find(parent, i):
if parent[i] == i:
return i
else:
return find(parent, parent[i])
def union(parent, rank, x, y):
xroot = find(parent, x)
yroot = find(parent, y)
if rank[xroot] < rank[yroot]:
parent[xroot] = yroot
elif rank[xroot] > rank[yroot]:
parent[yroot]... | def test_minimum_total_tax_simple_case():
assert minimum_total_tax(4, 5, [
(1, 2, 1),
(1, 3, 2),
(1, 4, 3),
(2, 3, 4),
(3, 4, 5)
]) == 6
def test_minimum_total_tax_another_case():
assert minimum_total_tax(3, 3, [
(1, 2, 2),
(2, 3, 3),
(1, 3, 4... | [
{
"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 minimum_total_tax(n, m, roads):\n \"\"\"\n Returns the minimum total tax the government can collect to ensure that all cities remain connected.\n... | trial_gpt4o_2 | {
"original_instruction": "In a country far, far away, there are n cities connected by m two-way roads. Each road connects exactly two different cities and no two roads connect the same pair of cities. The country’s government is planning to introduce a new tax on the roads. They want to ensure that the road network ... | 0.622496 | Code_Contests_31861 | C | [
"find",
"union",
"kruskal",
"minimum_total_tax"
] | 4 | [
[
"kruskal",
"find"
],
[
"kruskal",
"union"
],
[
"minimum_total_tax",
"kruskal"
],
[
"union",
"find"
]
] | 4 | [] | false | [] | false | pytest | false | [] | true | 5cc8be438089e4fa4927bf7090c367d970bff915 | 7824dfc56b8eeafd678870138921e041581ab92e | |||
v1.0 | complete | Code_Contests | Code_Contests_31273_C | def can_make_grid_equal(grid):
"""
Determines if it's possible to make all numbers in the grid equal.
If possible, returns a list of operations to achieve it.
"""
m = len(grid)
n = len(grid[0])
def process_grids(t, test_cases):
"""
Processes multiple test cases to determine if it's poss... | def can_make_grid_equal(grid):
"""
Determines if it's possible to make all numbers in the grid equal.
If possible, returns a list of operations to achieve it.
"""
m = len(grid)
n = len(grid[0])
# Calculate the modulo with respect to the first element in the grid.
base = grid[0][0]
... | def test_can_make_grid_equal():
grid1 = [
[1, 2, 3],
[4, 5, 6]
]
grid2 = [
[1, 2],
[3, 4]
]
grid3 = [
[5, 5],
[5, 5]
]
assert can_make_grid_equal(grid1) == ("NO", [])
assert can_make_grid_equal(grid2) == ("NO", [])
assert can_make_grid_... | [
{
"docstring": "Determines if it's possible to make all numbers in the grid equal.\nIf possible, returns a list of operations to achieve it.",
"function_declaration": "def can_make_grid_equal(grid):",
"function_name": "can_make_grid_equal",
"parameter_list": "(grid)"
},
{
"docstring": null,
... | [
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 make_all_numbers_equal(grids):\n results = []\n\n for grid in grids:\n m, n, matrix = grid\n first_elem = matrix[0][0]\n pos... | trial_gpt4o_4 | {
"original_instruction": "Alice loves rectangular grids and numbers. She decided to create a game involving these two.\n\nThe game is played on an m x n grid, where each cell initially contains a number. Alice can perform the following operation any number of times:\n\n- Select a subrectangle from the grid and add t... | 0.628461 | Code_Contests_31273 | C | [
"can_make_grid_equal",
"process_grids"
] | 2 | [
[
"process_grids",
"can_make_grid_equal"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | c2ace4277bc228d4877cb21488c9b507007b1f6e | b62b1d4f74a4d7e5d657f44dd3688897757ea795 | |||
v1.0 | complete | Code_Contests | Code_Contests_31768_C | def is_symmetrical_number(num):
"""
Determines if the number can be rearranged to form a palindrome.
>>> is_symmetrical_number("121") == True
>>> is_symmetrical_number("12321") == True
>>> is_symmetrical_number("1221") == True
>>> is_symmetrical_number("123") == False
>>> is_symmetrical_numb... | def is_symmetrical_number(num):
"""
Determines if the number can be rearranged to form a palindrome.
"""
from collections import Counter
# Count the frequency of each digit in the number
count = Counter(num)
# A number can form a palindrome if at most one digit has an odd count
odd... | from solution import symmetrical_numbers, is_symmetrical_number
def test_is_symmetrical_number():
assert is_symmetrical_number("121") == True
assert is_symmetrical_number("12321") == True
assert is_symmetrical_number("1221") == True
assert is_symmetrical_number("123") == False
assert is_symmetrical... | [
{
"docstring": "Determines if the number can be rearranged to form a palindrome.",
"function_declaration": "def is_symmetrical_number(num):",
"function_name": "is_symmetrical_number",
"parameter_list": "(num)"
},
{
"docstring": "Given N numbers, returns a list with \"YES\" if the number is 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": "from collections import Counter\n\ndef is_symmetrical_number(number):\n \"\"\"\n Determine if the digits of a given number can be rearranged to form ... | trial_gpt4o_2 | {
"original_instruction": "Alex is learning about symmetricalNumbers. A number is said to be a symmetricalNumber if its digits can be rearranged to form a palindrome. A palindrome is a number that reads the same forwards and backwards.\n\nGiven a set of numbers, you need to determine if each number is a symmetricalNu... | 0.707403 | Code_Contests_31768 | C | [
"is_symmetrical_number",
"symmetrical_numbers"
] | 2 | [
[
"symmetrical_numbers",
"is_symmetrical_number"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | cc3ea448190f9a68bcd35a9a2ae92eda968c585b | 0bfa3a597642be2d099f3b447af84c2d797694b9 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.