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_7709_C | import math
from typing import List, Tuple
def min_path_length(n: int, points: List[Tuple[int, int]]) -> float:
""" Calculate the minimum possible length of the path that visits every point exactly once and returns to the starting point.
>>> min_path_length(4, [(0, 0), (1, 0), (1, 1), (0, 1)]) == 4.000000... | import math
def calc_distance(p1, p2):
return math.sqrt((p1[0] - p2[0]) ** 2 + (p1[1] - p2[1]) ** 2)
def cross_product(o, a, b):
return (a[0] - o[0]) * (b[1] - o[1]) - (a[1] - o[1]) * (b[0] - o[0])
def convex_hull(points):
points.sort()
lower = []
for p in points:
while len(lower) >= 2 an... | def test_min_path_length_example_1():
n = 4
points = [(0, 0), (1, 0), (1, 1), (0, 1)]
assert min_path_length(n, points) == 4.000000
def test_min_path_length_example_2():
n = 5
points = [(1, 1), (2, 2), (2, 1), (3, 0), (1, 2)]
assert min_path_length(n, points) == 6.472136
def test_min_path_leng... | [
{
"docstring": null,
"function_declaration": "def calc_distance(p1, p2):",
"function_name": "calc_distance",
"parameter_list": "(p1, p2)"
},
{
"docstring": null,
"function_declaration": "def cross_product(o, a, b):",
"function_name": "cross_product",
"parameter_list": "(o, a, b)"... | [
1,
0,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import math\n\ndef calc_distance(p1, p2):\n return math.sqrt((p1[0] - p2[0]) ** 2 + (p1[1] - p2[1]) ** 2)\n\ndef cross_product(o, a, b):\n return (a[... | trial_gpt4o_0 | {
"original_instruction": "You are given n points on a 2D plane with integer coordinates. Your task is to connect these points with the shortest possible path that visits every point exactly once and returns to the starting point. This is a classic example of the Travelling Salesman Problem (TSP) with a twist: the po... | 0.643415 | Code_Contests_7709 | C | [
"calc_distance",
"cross_product",
"convex_hull",
"min_path_length"
] | 4 | [
[
"convex_hull",
"cross_product"
],
[
"min_path_length",
"calc_distance"
],
[
"min_path_length",
"convex_hull"
]
] | 3 | [] | false | [] | false | pytest | false | [] | true | b55cad3c96abf8d0bcd195f8b12fb232e956d31c | 7cab327ff7f794542a92074a3e4b13d77877ad4e | |||
v1.0 | complete | Code_Contests | Code_Contests_7724_C | def is_consecutive_sequence(message: str) -> str:
"""
Determines if the sorted letters of the message form a consecutive sequence
from the alphabet without any gaps.
>>> is_consecutive_sequence("BAC")
"YES"
>>> is_consecutive_sequence("ACD")
"NO"
"""
pass
def verify_consecutive... | def is_consecutive_sequence(message):
"""
Determines if the sorted letters of the message form a consecutive sequence
from the alphabet without any gaps.
"""
sorted_message = sorted(message)
for i in range(1, len(sorted_message)):
if ord(sorted_message[i]) - ord(sorted_message[i - 1]) !=... | from solution import is_consecutive_sequence, verify_consecutive_messages
def test_is_consecutive_sequence():
assert is_consecutive_sequence("BAC") == "YES"
assert is_consecutive_sequence("ECBAD") == "YES"
assert is_consecutive_sequence("ZXY") == "YES"
assert is_consecutive_sequence("ACD") == "NO"
... | [
{
"docstring": "Determines if the sorted letters of the message form a consecutive sequence\nfrom the alphabet without any gaps.",
"function_declaration": "def is_consecutive_sequence(message):",
"function_name": "is_consecutive_sequence",
"parameter_list": "(message)"
},
{
"docstring": "Giv... | [
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_consecutive_sequence(message):\n \"\"\"\n Returns \"YES\" if the sorted letters of the message form a consecutive alphabetic sequence, \"NO\" ... | trial_gpt4o_2 | {
"original_instruction": "To become a detective, Felix needs to crack a series of coded messages. Each message is a sequence of letters, and every letter is assigned a unique number (A=1, B=2, ..., Z=26). Felix can decode any message letter by letter using these numbers. However, the bad guys have tampered with the ... | 0.664845 | Code_Contests_7724 | C | [
"is_consecutive_sequence",
"verify_consecutive_messages"
] | 2 | [
[
"verify_consecutive_messages",
"is_consecutive_sequence"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 8dc62851f696feb4b33c210fb7c1e8aee4876d82 | 8262e016365705e87290b42bfa7c145cfc4d9b50 | |||
v1.0 | complete | Code_Contests | Code_Contests_7824_C | def find_cycles(n, f):
""" Identify all cycles in the permutation.
>>> find_cycles(4, [2, 3, 1, 4])
[[1, 2, 3], [4]]
>>> find_cycles(1, [1])
[[1]]
"""
def permutation_cycles(n, f):
""" Output the number of cycles and their details.
>>> permutation_cycles(4, [2, 3, 1, 4])
"2\n3 1 2 3... | def find_cycles(n, f):
visited = [False] * (n + 1)
cycles = []
for i in range(1, n + 1):
if not visited[i]:
cycle = []
x = i
while not visited[x]:
cycle.append(x)
visited[x] = True
x = f[x - 1]
cycles.ap... | import pytest
from solution import find_cycles, permutation_cycles
def test_find_cycles_simple():
assert find_cycles(4, [2, 3, 1, 4]) == [[1, 2, 3], [4]]
def test_find_cycles_single_element():
assert find_cycles(1, [1]) == [[1]]
def test_find_cycles_two_cycles():
assert find_cycles(2, [2, 1]) == [[1, 2]]... | [
{
"docstring": null,
"function_declaration": "def find_cycles(n, f):",
"function_name": "find_cycles",
"parameter_list": "(n, f)"
},
{
"docstring": null,
"function_declaration": "def permutation_cycles(n, f):",
"function_name": "permutation_cycles",
"parameter_list": "(n, f)"
}... | [
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_cycles(n, mapping):\n visited = [False] * n\n cycles = []\n\n for i in range(n):\n if not visited[i]:\n cycle = []\n ... | trial_gpt4o_2 | {
"original_instruction": "Artsem is challenging his friend Saunders with another intriguing problem related to permutations and cycle detection within functions.\n\nYou are given a list of integers representing the mapping of a function f: [n] → [n], where each integer is a positive value indicating the index (1-bas... | 0.557109 | Code_Contests_7824 | C | [
"find_cycles",
"permutation_cycles"
] | 2 | [
[
"permutation_cycles",
"find_cycles"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | ae869b625f9f1364f7ee057809aab4d116e652a8 | 6f2d2637f18643c10c682ac9cd36492070ddc51a | |||
v1.0 | complete | Code_Contests | Code_Contests_7614_C | def sort_tasks(T, test_cases):
"""
Sort tasks by priority first, then by identifier.
Arguments:
T : int : number of test cases
test_cases : list of lists : each sublist contains tuples of tasks with identifier and priority
Returns:
list of lists : each sublist contains sorted tasks... | def sort_tasks(T, test_cases):
"""
Sort tasks by priority first, then by identifier.
Arguments:
T : int : number of test cases
test_cases : list of lists : each sublist contains tuples of tasks with identifier and priority
Returns:
list of lists : each sublist contains sorted tasks... | def test_integrate():
input_string = '2\n3\n101 2\n105 1\n102 2\n4\n201 3\n202 2\n205 1\n204 2\n'
expected_output = '105 1\n101 2\n102 2\n205 1\n202 2\n204 2\n201 3'
assert organize_tasks(input_string) == expected_output
def test_parse_input():
input_string = '1\n3\n101 2\n105 1\n102 2\n'
... | [
{
"docstring": "Sort tasks by priority first, then by identifier.\n\nArguments:\nT : int : number of test cases\ntest_cases : list of lists : each sublist contains tuples of tasks with identifier and priority\n\nReturns:\nlist of lists : each sublist contains sorted tasks for the corresponding test case",
"... | [
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 sort_tasks(T, test_cases):\n \"\"\"\n Sort tasks by priority first, then by identifier.\n \n Arguments:\n T : int : number of test cases... | trial_gpt4o_0 | {
"original_instruction": "In a software company, project managers need to organize their tasks efficiently. Each task is given a unique identifier and a specified priority level. The managers need a function that, given a list of tasks, will sort the tasks based on their priority first, and then by their identifier ... | 0.554169 | Code_Contests_7614 | C | [
"sort_tasks",
"parse_input",
"format_output",
"organize_tasks"
] | 4 | [
[
"organize_tasks",
"format_output"
],
[
"organize_tasks",
"parse_input"
],
[
"organize_tasks",
"sort_tasks"
]
] | 3 | [
"parse_input",
"format_output"
] | false | [] | false | pytest | false | [] | true | 73ef1bb388e0fd74470c685abf55c77adccf4536 | ac09235516040a0eeddead2ea37fc2e55370ca4d | |||
v1.0 | complete | Code_Contests | Code_Contests_8415_C | def count_prime_palindromes(n: int) -> int:
""" Counts the number of prime palindromic numbers less than or equal to n.
>>> count_prime_palindromes(100)
5
>>> count_prime_palindromes(10)
4
"""
pass | def is_prime(num):
"""
Checks 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 +... | from solution import count_prime_palindromes
def test_count_prime_palindromes_example1():
assert count_prime_palindromes(100) == 5
def test_count_prime_palindromes_example2():
assert count_prime_palindromes(10) == 4
def test_count_prime_palindromes_lower_bound():
assert count_prime_palindromes(1) == 0
d... | [
{
"docstring": "Checks if a number is prime.",
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": "Checks if a number is palindromic.",
"function_declaration": "def is_palindrome(num):",
"function_name": "is_palindro... | [
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 is_palindrome(num):\n \"\"\"\n Returns True if num is a palindrome, False otherwise.\n \"\"\"\n return str(num) == str(num)[::-1]\n\ndef is... | trial_gpt4o_1 | {
"original_instruction": "Little Iris just learned about numeric palindromes and the magic of prime numbers, and she came up with a new interesting problem:\n\nYou are given an integer n. Your task is to find out how many prime numbers that are less than or equal to n are also palindromic numbers.\n\nA palindromic n... | 0.710042 | Code_Contests_8415 | C | [
"is_prime",
"is_palindrome",
"count_prime_palindromes"
] | 3 | [
[
"count_prime_palindromes",
"is_palindrome"
],
[
"count_prime_palindromes",
"is_prime"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 8515a3a5bde3332d59c98a9371ac53089642eddd | 0b74a2609a87644e920a18fd7545ec0e56f3fbc2 | |||
v1.0 | complete | Code_Contests | Code_Contests_7993_C | def min_travel_time(start, end):
"""
Calculate the minimum travel time from start to end on the given grid.
Arguments:
start -- the starting intersection coordinates (a, b)
end -- the destination intersection coordinates (c, d)
Returns:
The minimum travel time in minutes or "Impossible" if... | def min_travel_time(start, end):
"""
Calculate the minimum travel time from start to end on the given grid.
Arguments:
start -- the starting intersection coordinates (a, b)
end -- the destination intersection coordinates (c, d)
Returns:
The minimum travel time in minutes or "Impossible" if... | from solution import travel_times, min_travel_time
def test_min_travel_time():
assert min_travel_time((1, 2), (3, 4)) == 4
assert min_travel_time((0, 0), (7, 1)) == 8
assert min_travel_time((2, 3), (2, 3)) == 0
assert min_travel_time((4, 4), (1, 1)) == "Impossible"
assert min_travel_time((1, 2), (1... | [
{
"docstring": "Calculate the minimum travel time from start to end on the given grid.\n\nArguments:\nstart -- the starting intersection coordinates (a, b)\nend -- the destination intersection coordinates (c, d)\n\nReturns:\nThe minimum travel time in minutes or \"Impossible\" if the destination cannot be reach... | [
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 travel_time_on_grid(a, b, c, d):\n \"\"\"\n Calculates the minimum travel time in minutes from (a, b) to (c, d)\n following the one-way road r... | trial_gpt4o_2 | {
"original_instruction": "Travel Time on Grid\n\nKoto City is designed in a grid pattern with roads running north-south and east-west at intervals of 1 km. The lanes are one-way, where north-south roads allow movement only in the north direction and east-west roads allow movement only in the east direction. Koto sta... | 0.606596 | Code_Contests_7993 | C | [
"min_travel_time",
"travel_times"
] | 2 | [
[
"travel_times",
"min_travel_time"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 17ce8f00235486fe84eaf0c5b5862316840b8137 | 266af3cdcd65d5c9c507147913f841a4b20fb235 | |||
v1.0 | complete | Code_Contests | Code_Contests_8006_C | def is_toeplitz(matrix: List[List[int]], n: int, m: int) -> str:
"""
Check if the given n x m matrix is a Toeplitz matrix.
>>> is_toeplitz([[1, 2, 3, 4], [5, 1, 2, 3], [6, 5, 1, 2], [7, 6, 5, 1]], 4, 4)
'YES'
>>> is_toeplitz([[1, 2, 3, 4], [5, 1, 2, 8], [9, 5, 1, 2]], 3, 4)
'NO'
"""
def... | def is_toeplitz(matrix, n, m):
"""
Check if the given n x m matrix is a Toeplitz matrix.
"""
for i in range(1, n):
for j in range(1, m):
if matrix[i][j] != matrix[i - 1][j - 1]:
return "NO"
return "YES"
def check_toeplitz_matrices(test_cases):
results = []
... | def test_is_toeplitz():
assert is_toeplitz([[1, 2, 3, 4], [5, 1, 2, 3], [6, 5, 1, 2], [7, 6, 5, 1]], 4, 4) == "YES"
assert is_toeplitz([[1, 2, 3, 4], [5, 1, 2, 8], [9, 5, 1, 2]], 3, 4) == "NO"
assert is_toeplitz([[1, 2], [3, 1]], 2, 2) == "YES"
assert is_toeplitz([[1]], 1, 1) == "YES"
def test_check_to... | [
{
"docstring": "Check if the given n x m matrix is a Toeplitz matrix.",
"function_declaration": "def is_toeplitz(matrix, n, m):",
"function_name": "is_toeplitz",
"parameter_list": "(matrix, n, m)"
},
{
"docstring": null,
"function_declaration": "def check_toeplitz_matrices(test_cases):",... | [
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_toeplitz(matrix):\n \"\"\"\n Check if the given matrix is a Toeplitz matrix.\n \n :param matrix: 2D list of integers\n :return: Boole... | trial_gpt4o_2 | {
"original_instruction": "A square matrix is called a Toeplitz matrix if every diagonal from top-left to bottom-right has the same elements. For example, the following matrix is a Toeplitz matrix:\n\n\\[\n\\begin{matrix}\n1 & 2 & 3 & 4 \\\\\n5 & 1 & 2 & 3 \\\\\n6 & 5 & 1 & 2 \\\\\n7 & 6 & 5 & 1 \\\\\n\\end{matrix}\n... | 0.474521 | Code_Contests_8006 | C | [
"is_toeplitz",
"check_toeplitz_matrices",
"process_input"
] | 3 | [
[
"check_toeplitz_matrices",
"is_toeplitz"
],
[
"process_input",
"check_toeplitz_matrices"
]
] | 2 | [
"process_input"
] | false | [] | false | pytest | false | [] | true | 96634a8bab49670204bd134b1555da48783e8c16 | e81c6f159773ddfe5cfe46caedf004071a4a34ab | |||
v1.0 | complete | Code_Contests | Code_Contests_8056_C | from typing import List
def reverse_number(n: int) -> int:
""" Reverse the digits of an integer.
>>> reverse_number(123) == 321
>>> reverse_number(400) == 4
>>> reverse_number(0) == 0
>>> reverse_number(987654321) == 123456789
"""
def is_palindrome(n: int) -> bool:
""" Check if an integer ... | def reverse_number(n):
return int(str(n)[::-1])
def is_palindrome(n):
s = str(n)
return s == s[::-1]
def palindrome_chain_length(n):
steps = 0
while not is_palindrome(n):
n = n + reverse_number(n)
steps += 1
return steps
def process_palindrome_chain_length(nums):
results =... | from solution import reverse_number, is_palindrome, palindrome_chain_length, process_palindrome_chain_length
def test_reverse_number():
assert reverse_number(123) == 321
assert reverse_number(400) == 4
assert reverse_number(0) == 0
assert reverse_number(987654321) == 123456789
def test_is_palindrome()... | [
{
"docstring": null,
"function_declaration": "def reverse_number(n):",
"function_name": "reverse_number",
"parameter_list": "(n)"
},
{
"docstring": null,
"function_declaration": "def is_palindrome(n):",
"function_name": "is_palindrome",
"parameter_list": "(n)"
},
{
"docst... | [
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_palindrome(n):\n \"\"\"\n Checks if a given number n is a palindrome.\n \"\"\"\n return str(n) == str(n)[::-1]\n\ndef reverse_number(n):... | trial_gpt4o_4 | {
"original_instruction": "Palindrome Chain Length\n\nA palindrome is a word or phrase that reads the same forwards and backwards. For example, \"racecar\" and \"level\" are palindromes. Given a non-negative integer n, your task is to determine the minimum number of steps required to make n a palindrome by adding the... | 0.726483 | Code_Contests_8056 | C | [
"reverse_number",
"is_palindrome",
"palindrome_chain_length",
"process_palindrome_chain_length"
] | 4 | [
[
"palindrome_chain_length",
"is_palindrome"
],
[
"palindrome_chain_length",
"reverse_number"
],
[
"process_palindrome_chain_length",
"palindrome_chain_length"
]
] | 3 | [] | false | [] | false | pytest | true | [] | true | a1375dfe2073591e88e3661b1f4d4aa47fadb558 | cb27eb2f0ba7484ee062bc6349d8295f95fc3c62 | |||
v1.0 | complete | Code_Contests | Code_Contests_8136_C | def max_histogram_area(heights):
"""
Helper function to find the largest rectangular area in a histogram.
"""
pass
def largest_rectangle_fertile_land(matrix):
"""
Finds the largest rectangular area of fertile land ('1') in a given matrix.
>>> largest_rectangle_fertile_land([
... "10... | def max_histogram_area(heights):
"""
Helper function to find the largest rectangular area in a histogram.
"""
stack = []
max_area = 0
index = 0
while index < len(heights):
if not stack or heights[stack[-1]] <= heights[index]:
stack.append(index)
index += ... | def test_largest_rectangle_fertile_land_case1():
matrix = [
"10100",
"10111",
"11111",
"10010"
]
assert largest_rectangle_fertile_land(matrix) == 6
def test_largest_rectangle_fertile_land_case2():
matrix = [
"111",
"111",
"111"
]
assert la... | [
{
"docstring": "Helper function to find the largest rectangular area in a histogram.",
"function_declaration": "def max_histogram_area(heights):",
"function_name": "max_histogram_area",
"parameter_list": "(heights)"
},
{
"docstring": "Finds the largest rectangular area of fertile land ('1') ... | [
1,
1,
0
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def max_histogram_area(histogram):\n stack = []\n max_area = 0\n index = 0\n\n while index < len(histogram):\n if not stack or histogram... | trial_gpt4o_1 | {
"original_instruction": "A farmer has a rectangular field, where each cell in the field can either be fertile (denoted by '1') or barren (denoted by '0'). He wants to plant crops in the largest possible rectangular plot of fertile land. There may be multiple plots of the same size in the field.\n\nWrite a program t... | 0.640386 | Code_Contests_8136 | C | [
"max_histogram_area",
"largest_rectangle_fertile_land"
] | 2 | [
[
"largest_rectangle_fertile_land",
"max_histogram_area"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | 81d3b4622aced1e0a415af15493a51073e5ab9a3 | a22fad27a494b46de48ee5154690e5bf3cf55021 | |||
v1.0 | complete | Code_Contests | Code_Contests_8392_C | def is_balanced(sequence: str) -> str:
""" Returns 'YES' if the given sequence of parentheses is balanced, otherwise 'NO'.
>>> is_balanced("()[]{}") 'YES'
>>> is_balanced("([{}])") 'YES'
>>> is_balanced("([)]") 'NO'
"""
def check_sequences(n: int, sequences: List[str]) -> List[str]:
""" Returns... | def is_balanced(sequence):
"""
Returns 'YES' if the given sequence of parentheses is balanced, otherwise 'NO'.
A sequence is balanced if it has correct opening and closing parentheses.
"""
stack = []
matching_bracket = {')': '(', '}': '{', ']': '['}
for char in sequence:
if char in m... | from solution import is_balanced, check_sequences
def test_is_balanced():
assert is_balanced("()[]{}") == "YES"
assert is_balanced("([{}])") == "YES"
assert is_balanced("([)]") == "NO"
assert is_balanced("") == "YES"
assert is_balanced("(((((((((())))))))))") == "YES"
assert is_balanced("{[()]}... | [
{
"docstring": "Returns 'YES' if the given sequence of parentheses is balanced, otherwise 'NO'.\nA sequence is balanced if it has correct opening and closing parentheses.",
"function_declaration": "def is_balanced(sequence):",
"function_name": "is_balanced",
"parameter_list": "(sequence)"
},
{
... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_balanced(sequence):\n \"\"\"\n Check if the given sequence of parentheses is balanced.\n\n :param sequence: String consisting of characters... | trial_gpt4o_1 | {
"original_instruction": "You are given N sets of parentheses sequences. Your task is to determine if each sequence is balanced. A sequence of parentheses is balanced if it contains the correct order of opening and closing parentheses and each closing parenthesis has a corresponding opening parenthesis.\n\nInput\n\n... | 0.737749 | Code_Contests_8392 | C | [
"is_balanced",
"check_sequences"
] | 2 | [
[
"check_sequences",
"is_balanced"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 00fd74a19fc66c8643cb6c44a22523fe2cee1835 | 0745d840beb223b86cafd585e8ae0fea91ae1468 | |||
v1.0 | complete | Code_Contests | Code_Contests_8224_C | from typing import List, Tuple
def minimum_cost_to_connect_towns(n: int, m: int, roads: List[Tuple[int, int, int]]) -> int:
""" Determine the minimum cost to connect all towns using magical roads. Each road can only be used once.
Args:
n: int - the number of towns.
m: int - the number of magical roads... | def find(parent, i):
if parent[i] == i:
return i
else:
parent[i] = find(parent, parent[i])
return parent[i]
def union(parent, rank, x, y):
root_x = find(parent, x)
root_y = find(parent, y)
if root_x != root_y:
if rank[root_x] > rank[root_y]:
parent[r... | from solution import minimum_cost_to_connect_towns
def test_example_1():
n, m = 4, 5
roads = [
(1, 2, 3),
(2, 3, 2),
(3, 4, 4),
(1, 4, 1),
(1, 3, 5)
]
assert minimum_cost_to_connect_towns(n, m, roads) == 6
def test_example_2():
n, m = 3, 1
roads = [
... | [
{
"docstring": null,
"function_declaration": "def find(parent, i):",
"function_name": "find",
"parameter_list": "(parent, i)"
},
{
"docstring": null,
"function_declaration": "def union(parent, rank, x, y):",
"function_name": "union",
"parameter_list": "(parent, rank, x, y)"
},
... | [
0,
0,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def find(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_2 | {
"original_instruction": "In a far-off land, there exist n enchanted towns, each connected by magical roads. Each road has a certain cost to traverse it. As a gesture of goodwill, the king wants to make travel between any two towns as cheap as possible, ensuring that there exists a path (direct or indirect) between ... | 0.67949 | Code_Contests_8224 | C | [
"find",
"union",
"kruskal",
"minimum_cost_to_connect_towns"
] | 4 | [
[
"kruskal",
"find"
],
[
"kruskal",
"union"
],
[
"minimum_cost_to_connect_towns",
"kruskal"
],
[
"union",
"find"
]
] | 4 | [] | false | [] | false | pytest | true | [] | true | 1b03de71da129e5c2b5bb3e59529a47294aa5a6d | 5ec5c62c87583780bab99a64f3ab3134b997e3ba | |||
v1.0 | complete | Code_Contests | Code_Contests_8354_C | def is_passcode_valid(passcode):
"""
Determines if the given passcode is compliant with the security policy.
A compliant passcode does not contain the sequence "123" or "321".
Parameters:
passcode (str): The passcode to check.
Returns:
str: "Valid Passcode" if compliant, otherwise ... | def is_passcode_valid(passcode):
"""
Determines if the given passcode is compliant with the security policy.
A compliant passcode does not contain the sequence "123" or "321".
Parameters:
passcode (str): The passcode to check.
Returns:
str: "Valid Passcode" if compliant, otherwise ... | from solution import is_passcode_valid, check_passcodes
def test_is_passcode_valid():
assert is_passcode_valid("secure123code") == "Invalid Passcode"
assert is_passcode_valid("pass321word") == "Invalid Passcode"
assert is_passcode_valid("mysecurepasscode") == "Valid Passcode"
assert is_passcode_valid("... | [
{
"docstring": "Determines if the given passcode is compliant with the security policy.\nA compliant passcode does not contain the sequence \"123\" or \"321\".\n\nParameters:\npasscode (str): The passcode to check.\n\nReturns:\nstr: \"Valid Passcode\" if compliant, otherwise \"Invalid Passcode\".",
"functio... | [
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_valid_passcode(passcode):\n \"\"\"\n Checks if the passcode complies with the new security policy. \n Passcodes must not contain the sequen... | trial_gpt4o_2 | {
"original_instruction": "A security agency has set up a new policy for generating secure passcodes. The policy is to avoid using certain digits in any particular order within the passcode. Specifically, a passcode should not contain the sequence \"123\" or \"321\" anywhere within it.\n\nGiven this restriction, writ... | 0.504439 | Code_Contests_8354 | C | [
"is_passcode_valid",
"check_passcodes"
] | 2 | [
[
"check_passcodes",
"is_passcode_valid"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | be612984355aef5a4b817a01671cd0d109774ad3 | 38c976774a1a4a6d4379d5ad351c206fc7fdd306 | |||
v1.0 | complete | Code_Contests | Code_Contests_8407_C | from typing import List
def is_prime(n: int) -> bool:
""" Check if a number is prime. """
pass
def smallest_prime_geq_n(n: int) -> int:
""" Find the smallest prime number greater than or equal to n. """
pass
def solve(T: int, cases: List[int]) -> List[int]:
""" Solve the problem for T test cases.... | def is_prime(n):
"""
Check if a number is prime.
"""
if n <= 1:
return False
if n == 2:
return True
if n % 2 == 0:
return False
p = 3
while p * p <= n:
if n % p == 0:
return False
p += 2
return True
def smallest_prime_geq_n(n):
... | from solution import is_prime, smallest_prime_geq_n, solve
def test_is_prime():
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(4) == False
assert is_prime(17) == True
assert is_prime(18) == False
def test_smallest_prime_geq_n():
assert smallest_prime_geq_n(17) == 17
... | [
{
"docstring": "Check if a number is prime.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Find the smallest prime number greater than or equal to n.",
"function_declaration": "def smallest_prime_geq_n(n):",
"func... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(n):\n \"\"\"\n Check if a number is prime.\n \"\"\"\n if n <= 1:\n return False\n if n == 2:\n return True\n i... | trial_gpt4o_0 | {
"original_instruction": "Sarah loves numbers and especially enjoys finding interesting patterns in them. Recently, she has become fascinated with prime numbers. A prime number is a natural number greater than 1 that has no positive divisors other than 1 and itself. Sarah comes up with an interesting problem and nee... | 0.716191 | Code_Contests_8407 | C | [
"is_prime",
"smallest_prime_geq_n",
"solve"
] | 3 | [
[
"smallest_prime_geq_n",
"is_prime"
],
[
"solve",
"smallest_prime_geq_n"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 911f748925a2be6253d82ec673c4f56fa5c53d1a | a5969bed2dd41298ed274a226885fbf58f67e33f | |||
v1.0 | complete | Code_Contests | Code_Contests_8279_C | def count_set_bits(n: int) -> int:
"""
Count the number of set bits (1s) in the binary representation of an integer.
>>> count_set_bits(3)
2
>>> count_set_bits(7)
3
"""
def sort_by_set_bits(test_cases: List[List[int]]) -> List[List[int]]:
"""
Sort the numbers based on the ... | def count_set_bits(n):
return bin(n).count('1')
def sort_by_set_bits(test_cases):
sorted_cases = []
for case in test_cases:
sorted_case = sorted(case, key=lambda x: (count_set_bits(x), x))
sorted_cases.append(sorted_case)
return sorted_cases
def parse_input(input_string):
lines = i... | def test_count_set_bits():
assert count_set_bits(3) == 2
assert count_set_bits(7) == 3
assert count_set_bits(8) == 1
assert count_set_bits(9) == 2
def test_sort_by_set_bits():
assert sort_by_set_bits([[3, 7, 8, 9]]) == [[8, 3, 9, 7]]
assert sort_by_set_bits([[1, 2, 4, 8, 16]]) == [[1, 2, 4, 8, ... | [
{
"docstring": null,
"function_declaration": "def count_set_bits(n):",
"function_name": "count_set_bits",
"parameter_list": "(n)"
},
{
"docstring": null,
"function_declaration": "def sort_by_set_bits(test_cases):",
"function_name": "sort_by_set_bits",
"parameter_list": "(test_cas... | [
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 sort_by_set_bits(numbers):\n \"\"\"\n Sorts the list of numbers based on the number of set bits in their binary representation.\n If two numbe... | trial_gpt4o_1 | {
"original_instruction": "Assume you have a list of numbers and you need to arrange them in a specific order. The task is to sort the numbers based on the number of set bits (1s) in their binary representation. If two numbers have the same number of set bits, the smaller number should appear first. \n\n**Input:**\n... | 0.680787 | Code_Contests_8279 | C | [
"count_set_bits",
"sort_by_set_bits",
"parse_input"
] | 3 | [
[
"parse_input",
"sort_by_set_bits"
],
[
"sort_by_set_bits",
"count_set_bits"
]
] | 2 | [
"parse_input"
] | false | [] | false | pytest | false | [] | true | 74855234014709ce1b3f48a78490345048aca6d0 | 874c5ee77fe2b817e0fa1a9afc7122af4bb954d9 | |||
v1.0 | complete | Code_Contests | Code_Contests_8347_C | from typing import List, Tuple
def find_most_frequent_pair(logs: List[Tuple[int, int, int]]) -> Tuple[int, int]:
"""
Find the pair of modules with the highest interaction count.
Parameters:
logs (list of tuples): Each tuple contains three integers representing two modules and their interaction... | def find_most_frequent_pair(logs):
"""
Find the pair of modules with the highest interaction count.
Parameters:
logs (list of tuples): Each tuple contains three integers representing two modules and their interaction count.
Returns:
tuple: A pair of modules (module1, module... | def test_find_most_frequent_pair():
assert find_most_frequent_pair([(1, 2, 10), (2, 3, 5), (1, 3, 15)]) == (1, 3)
assert find_most_frequent_pair([(4, 5, 7), (5, 6, 12)]) == (5, 6)
assert find_most_frequent_pair([(1, 2, 8), (2, 3, 8), (3, 4, 8)]) in [(1, 2), (2, 3), (3, 4)]
def test_process_interaction_logs... | [
{
"docstring": "Find the pair of modules with the highest interaction count.\n\nParameters:\n logs (list of tuples): Each tuple contains three integers representing two modules and their interaction count.\n \nReturns:\n tuple: A pair of modules (module1, module2) with the highest interaction count.",
... | [
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_max_interaction_pair(interaction_logs):\n \"\"\"\n Finds the pair of modules with the highest interaction count.\n \n Parameters:\n ... | trial_gpt4o_2 | {
"original_instruction": "A large software system is developed by combining multiple smaller modules, each having its own unique responsibilities and role in the larger ecosystem. During extensive testing, it has been observed that certain pairs of modules interact more frequently, whereas others rarely communicate ... | 0.54169 | Code_Contests_8347 | C | [
"find_most_frequent_pair",
"process_interaction_logs"
] | 2 | [
[
"process_interaction_logs",
"find_most_frequent_pair"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | d8bd51f8371a25c66938019e983d72bbb3bf9509 | d017586506402c56267713be9922361a501720e5 | |||
v1.0 | complete | Code_Contests | Code_Contests_8497_C | def calculate_final_grades(students_scores):
""" Calculate the final grades for each student by dropping the lowest score and averaging the remaining scores.
Args:
students_scores (List[List[str]]): A list of lists where each inner list contains the student's name followed by their scores.
Ret... | def calculate_final_grades(students_scores):
final_grades = {}
for student_scores in students_scores:
name = student_scores[0]
scores = list(map(int, student_scores[1:]))
scores.remove(min(scores))
average_score = round(sum(scores) / len(scores))
final_grades[name] = aver... | from solution import calculate_final_grades, format_final_grades, main_grading_system
def test_calculate_final_grades():
test_data = [
["Alice", "70", "80", "90", "100"],
["Bob", "90", "60", "70"],
["Charlie", "100", "90", "80", "70"]
]
result = calculate_final_grades(test_data)
... | [
{
"docstring": null,
"function_declaration": "def calculate_final_grades(students_scores):",
"function_name": "calculate_final_grades",
"parameter_list": "(students_scores)"
},
{
"docstring": null,
"function_declaration": "def format_final_grades(final_grades):",
"function_name": "fo... | [
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 compute_final_grades(n, student_data):\n \"\"\"\n Computes the final grades for each student based on the given policy.\n \n Parameters:\n ... | trial_gpt4o_1 | {
"original_instruction": "In a completed university course, the students need their final grades calculated based on their scores in several assignments. The university has a peculiar grading policy whereby they drop the lowest score for each student and then take the average of the remaining scores to determine the... | 0.774358 | Code_Contests_8497 | C | [
"calculate_final_grades",
"format_final_grades",
"main_grading_system"
] | 3 | [
[
"main_grading_system",
"calculate_final_grades"
],
[
"main_grading_system",
"format_final_grades"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 470174f99baabc9264d690bc154db5e3989453ce | acb6c7c613ff080b57a1fb761645855802723947 | |||
v1.0 | complete | Code_Contests | Code_Contests_8357_C | def knapsack(capacity, weights):
"""
Solves the 0/1 knapsack problem for given capacity and weights.
"""
pass # Your implementation here
def maximize_loaded_weight(m, capacities, n, container_weights):
"""
For each ship, determines the maximum total weight of containers that can be
loaded ... | def knapsack(capacity, weights):
"""
Solves the 0/1 knapsack problem for given capacity and weights.
"""
n = len(weights)
dp = [0] * (capacity + 1)
for weight in weights:
for c in range(capacity, weight - 1, -1):
dp[c] = max(dp[c], dp[c - weight] + weight)
return dp[-1]
... | from solution import maximize_loaded_weight
def test_maximize_loaded_weight_sample1():
m = 3
capacities = [100, 150, 200]
n = 5
container_weights = [50, 50, 50, 50, 50]
expected_output = [100, 150, 200]
assert maximize_loaded_weight(m, capacities, n, container_weights) == expected_output
def t... | [
{
"docstring": "Solves the 0/1 knapsack problem for given capacity and weights.",
"function_declaration": "def knapsack(capacity, weights):",
"function_name": "knapsack",
"parameter_list": "(capacity, weights)"
},
{
"docstring": "For each ship, determines the maximum total weight of containe... | [
0,
0,
0,
0,
0,
0,
1,
1,
0,
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 calculate_max_weights(m, capacities, n, weights):\n \"\"\"\n Calculates the maximum weight that can be loaded onto each ship without exceeding it... | trial_gpt4o_9 | {
"original_instruction": "A --Shipping Containers Optimization\n\nProblem Statement\n\nYou are managing the storage and transportation of shipping containers at a large port. The port has an endless capacity but you need to optimize the loading of containers onto the ships. Each ship has a maximum weight it can carr... | 0.572163 | Code_Contests_8357 | C | [
"knapsack",
"maximize_loaded_weight"
] | 2 | [
[
"maximize_loaded_weight",
"knapsack"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 5ba9397f36d31e1efe48c0c462d088fdea81197e | df4e1d82b35d36ccad6c25a990d00d178bd7f4bb | |||
v1.0 | complete | Code_Contests | Code_Contests_8412_C | from typing import List, Tuple
def calculate_weighted_average(scores_and_weights: List[int]) -> float:
""" Calculate the weighted average score given a list of scores and weights.
>>> calculate_weighted_average([95, 4, 80, 2, 100, 1])
90.0
>>> calculate_weighted_average([80, 3, 90, 4])
86.67
>>... | def calculate_weighted_average(scores_and_weights):
total_weighted_score = 0
total_weight = 0
for score, weight in zip(scores_and_weights[0::2], scores_and_weights[1::2]):
total_weighted_score += score * weight
total_weight += weight
return total_weighted_score / total_weight
def find_s... | def test_calculate_weighted_average():
assert calculate_weighted_average([95, 4, 80, 2, 100, 1]) == (95*4 + 80*2 + 100*1) / (4 + 2 + 1)
assert calculate_weighted_average([80, 3, 90, 4]) == (80*3 + 90*4) / (3 + 4)
assert calculate_weighted_average([100, 1, 50, 1]) == (100*1 + 50*1) / (1 + 1)
assert calcu... | [
{
"docstring": null,
"function_declaration": "def calculate_weighted_average(scores_and_weights):",
"function_name": "calculate_weighted_average",
"parameter_list": "(scores_and_weights)"
},
{
"docstring": null,
"function_declaration": "def find_student_with_highest_average(n, students):... | [
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 calculate_weighted_average(scores):\n \"\"\"\n Computes the weighted average for a list of (score, weight) pairs.\n \"\"\"\n total_score = ... | trial_gpt4o_2 | {
"original_instruction": "You are given a list of students and their scores. Each student can take multiple tests, and each test has a different weight. Your task is to calculate the weighted average score for each student and determine the highest average score.\n\nInput\n\nThe input consists of several lines. The ... | 0.716436 | Code_Contests_8412 | C | [
"calculate_weighted_average",
"find_student_with_highest_average",
"main"
] | 3 | [
[
"find_student_with_highest_average",
"calculate_weighted_average"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | a718e134db09d8661579199df4b0709a79051e67 | c1d584f57a77171eeaff0981acd9ee97a971e073 | |||
v1.0 | complete | Code_Contests | Code_Contests_8216_C | def process_queries(n: int, q: int, arr: List[int], queries: List[Tuple[int, ...]]) -> List[int]:
"""Process a series of queries on an integer array A of length N.
Parameters:
n (int): Length of the array.
q (int): Number of queries.
arr (List[int]): The array of integers.
queries (List[Tup... | def process_queries(n, q, arr, queries):
results = []
for query in queries:
t = query[0]
if t == 1:
x, v = query[1], query[2]
arr[x-1] += v
elif t == 2:
l, r = query[1], query[2]
results.append(sum(arr[l-1:r]))
elif t == 3:
... | def test_process_queries():
n = 5
q = 5
arr = [1, 2, 3, 2, 1]
queries = [
(2, 1, 5),
(3, 2),
(1, 3, 1),
(2, 2, 4),
(3, 2)
]
expected_output = [9, 3, 8, 3]
assert process_queries(n, q, arr, queries) == expected_output
def test_process_queries_empty_arr... | [
{
"docstring": null,
"function_declaration": "def process_queries(n, q, arr, queries):",
"function_name": "process_queries",
"parameter_list": "(n, q, arr, queries)"
},
{
"docstring": null,
"function_declaration": "def process_input_output():",
"function_name": "process_input_output"... | [
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 process_queries(N, Q, A, queries):\n \"\"\"\n Processes the given queries and returns the results for each type 2 and\n type 3 query.\n \"\... | trial_gpt4o_1 | {
"original_instruction": "You are given an integer array A of length N and an integer Q representing the number of queries. Each query can be one of the following types:\n\n* T_i=1: Given two integers X_i and V_i, add V_i to A_{X_i}.\n* T_i=2: Given two integers L_i and R_i, calculate the sum of the subarray from A_... | 0.707587 | Code_Contests_8216 | C | [
"process_queries",
"process_input_output"
] | 2 | [
[
"process_input_output",
"process_queries"
]
] | 1 | [
"process_queries",
"process_input_output"
] | false | [] | false | pytest | false | [] | true | a67b5b81bfb7e6d700942ebb89923bc02b96db8e | 3fe4bdabc441c7708334465869d6f826674800ce | |||
v1.0 | complete | Code_Contests | Code_Contests_9047_C | def is_right_angle(x1, y1, x2, y2, x3, y3):
"""
Checks if the triangle formed by (x1, y1), (x2, y2), (x3, y3) is a right-angled triangle.
"""
def are_all_subsets_right_angled(points):
"""
Verifies if all subsets of three points out of the four provided points form a right-angled triangle.
:para... | def is_right_angle(x1, y1, x2, y2, x3, y3):
"""
Checks if the triangle formed by (x1, y1), (x2, y2), (x3, y3) is a right-angled triangle.
"""
# Calculate squares of the lengths of the sides
a2 = (x2 - x1) ** 2 + (y2 - y1) ** 2
b2 = (x3 - x1) ** 2 + (y3 - y1) ** 2
c2 = (x3 - x2) ** 2 + (y3 - ... | from solution import are_all_subsets_right_angled
def test_case_1():
points = [(0, 0), (3, 0), (0, 4), (3, 4)]
assert are_all_subsets_right_angled(points) == "YES"
def test_case_2():
points = [(0, 0), (1, 1), (2, 2), (3, 3)]
assert are_all_subsets_right_angled(points) == "NO"
def test_case_3():
p... | [
{
"docstring": "Checks if the triangle formed by (x1, y1), (x2, y2), (x3, y3) is a right-angled triangle.",
"function_declaration": "def is_right_angle(x1, y1, x2, y2, x3, y3):",
"function_name": "is_right_angle",
"parameter_list": "(x1, y1, x2, y2, x3, y3)"
},
{
"docstring": "Verifies if al... | [
1,
1,
0
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_right_angle(x1, y1, x2, y2, x3, y3):\n \"\"\"\n Checks if the triangle formed by (x1, y1), (x2, y2), (x3, y3) is a right-angled triangle.\n ... | trial_gpt4o_0 | {
"original_instruction": "Julia discovered an enchanted forest where magical coordinates are hidden in the form of integer points on the Cartesian plane. Each set of these points forms a triangle, often with unique properties. She is particularly interested in right-angled triangles, which have one angle exactly 90 ... | 0.810159 | Code_Contests_9047 | C | [
"is_right_angle",
"are_all_subsets_right_angled"
] | 2 | [
[
"are_all_subsets_right_angled",
"is_right_angle"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | e6629b84cede46f190e54a195037f2ab7dfd6908 | c74a964877f61c1229800ab37ce3d6d33c9928b2 | |||
v1.0 | complete | Code_Contests | Code_Contests_8608_C | def minimum_spanning_tree(input_data: str) -> Union[int, str]:
"""Find the minimum spanning tree (MST) for the village.
The input consists of multiple lines. The first line contains two integers, n and m (1 ≤ n ≤ 1000, 0 ≤ m ≤ 10000) –
the number of houses and the number of roads, respectively. Each o... | def find(parent, i):
if parent[i] == i:
return i
return find(parent, parent[i])
def union(parent, rank, x, y):
root_x = find(parent, x)
root_y = find(parent, y)
if rank[root_x] < rank[root_y]:
parent[root_x] = root_y
elif rank[root_x] > rank[root_y]:
parent[root_y] ... | def test_case_1():
input_data = "4 5\n1 2 1\n1 3 4\n2 3 2\n3 4 3\n4 1 5\n"
assert minimum_spanning_tree(input_data) == 6
def test_case_2():
input_data = "3 1\n1 2 2\n"
assert minimum_spanning_tree(input_data) == "IMPOSSIBLE"
def test_case_3():
input_data = "2 1\n1 2 3\n"
assert minimum_spannin... | [
{
"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 return find(parent, parent[i])\n\ndef union(parent, rank, x, y):\n root_x = find(par... | trial_gpt4o_0 | {
"original_instruction": "In a faraway land, there is a village with n houses numbered from 1 to n, and m bidirectional roads connecting pairs of houses. Each road has a certain length. The village chief wants to select some of these roads to build a central biking route such that villagers can travel between any tw... | 0.684988 | Code_Contests_8608 | C | [
"find",
"union",
"kruskal",
"minimum_spanning_tree"
] | 4 | [
[
"kruskal",
"find"
],
[
"kruskal",
"union"
],
[
"minimum_spanning_tree",
"kruskal"
],
[
"union",
"find"
]
] | 4 | [] | false | [] | false | pytest | false | [] | true | 73edb66124a6d42435cd97f7fec464ce1b704346 | 74c1e5e0e04ad8f0150c8a76978a3135a40776be | |||
v1.0 | complete | Code_Contests | Code_Contests_8585_C | def get_shortest_travel_time_matrix(M: int, edges: List[Tuple[int, int, int]]) -> List[List[int]]:
""" Determine the shortest possible travel time between any two cities via the train tracks.
Args:
M (int): The number of cities.
edges (List[Tuple[int, int, int]]): A list of tuples where each tuple ... | def floyd_warshall(matrix):
M = len(matrix)
# Initialize the distance matrix
dist = [[float('inf')] * M for _ in range(M)]
for i in range(M):
dist[i][i] = 0
# Copy the given adjacency matrix values into the distance matrix
for u in range(M):
for v in range(M):
... | import pytest
from solution import get_shortest_travel_time_matrix
def test_small_graph():
edges = [
(1, 2, 4),
(2, 3, 1),
(3, 1, 7)
]
expected = [
[0, 4, 5],
[4, 0, 1],
[5, 1, 0]
]
result = get_shortest_travel_time_matrix(3, edges)
assert result ... | [
{
"docstring": null,
"function_declaration": "def floyd_warshall(matrix):",
"function_name": "floyd_warshall",
"parameter_list": "(matrix)"
},
{
"docstring": null,
"function_declaration": "def get_shortest_travel_time_matrix(M, edges):",
"function_name": "get_shortest_travel_time_mat... | [
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 floyd_warshall(num_cities, tracks):\n import sys\n INF = sys.maxsize\n # Initialize adjacency matrix with infinities\n dist = [[INF] * num_... | trial_gpt4o_1 | {
"original_instruction": "In a faraway land, there are M cities connected by bidirectional train tracks. Each train track has a travel time assigned to it, defined by a non-negative integer. Your task is to determine the shortest possible travel time between any two cities via the train tracks. Due to the uniqueness... | 0.722612 | Code_Contests_8585 | C | [
"floyd_warshall",
"get_shortest_travel_time_matrix"
] | 2 | [
[
"get_shortest_travel_time_matrix",
"floyd_warshall"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 2ef653cbd3ded38c4273cc041cc59b7c5f001a13 | 5edca4885973e022ec917d57826d0ab7838ec2b1 | |||
v1.0 | complete | Code_Contests | Code_Contests_8703_C | from typing import List, Tuple
def preprocess(arr: List[int]) -> Tuple[List[List[int]], List[int]]:
"""
Preprocess the input array to allow efficient minimum queries using a Sparse Table.
Returns the Sparse Table and the log array.
"""
pass
def query(st: List[List[int]], log: List[int], l: int, r:... | def preprocess(arr):
"""
Preprocess the input array to allow efficient minimum queries using a Sparse Table.
Returns the Sparse Table and the log array.
"""
import math
n = len(arr)
MAX_LOG = math.floor(math.log2(n)) + 1
# Create Sparse Table
st = [[0] * MAX_LOG for _ in range(n)]... | def test_preprocess():
arr = [1, 3, 2, 5, 4]
st, log = preprocess(arr)
# Check the correct preprocessing of the array
assert st[0][0] == 1
assert st[1][0] == 3
assert st[2][0] == 2
# Check a higher level in the Sparse Table
assert st[0][1] == 1
def test_query():
arr = [1, 3, 2, 5,... | [
{
"docstring": "Preprocess the input array to allow efficient minimum queries using a Sparse Table.\nReturns the Sparse Table and the log array.",
"function_declaration": "def preprocess(arr):",
"function_name": "preprocess",
"parameter_list": "(arr)"
},
{
"docstring": "Query the minimum val... | [
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": "class SegmentTree:\n def __init__(self, data):\n self.n = len(data)\n self.tree = [0] * (2 * self.n)\n self._build(data)\n\n def... | trial_gpt4o_1 | {
"original_instruction": "You have been given an array `arr` consisting of `n` integers. Your task is to process `q` queries, each asking for the minimum value in a subarray defined by its starting and ending indices. \n\nWrite a program that processes these queries efficiently.\n\n### Input\n- The first line contai... | 0.561793 | Code_Contests_8703 | C | [
"preprocess",
"query",
"process_queries"
] | 3 | [
[
"process_queries",
"preprocess"
],
[
"process_queries",
"query"
]
] | 2 | [
"process_queries"
] | false | [] | false | pytest | false | [] | true | ffdfc3e98d95591e9e2750a880e2a3151fc7b767 | a9fe5f5314f3a48b9871b57d62bfb393e0b85bdb | |||
v1.0 | complete | Code_Contests | Code_Contests_8646_C | def minimum_travel_cost(n: int, m: int, bridges: List[Tuple[int, int, int]]) -> int:
"""
The Kingdom of Zolon consists of a cluster of islands connected by bridges.
There are n islands in total, numbered from 1 to n. Each bridge connects two
islands directly and has an associated travel cost. The Kin... | def find(parent, i):
if parent[i] == i:
return i
else:
parent[i] = find(parent, parent[i])
return parent[i]
def union(parent, rank, x, y):
root_x = find(parent, x)
root_y = find(parent, y)
if root_x != root_y:
if rank[root_x] > rank[root_y]:
parent[r... | def test_minimum_travel_cost_example_1():
n = 4
m = 5
bridges = [
(1, 2, 5),
(1, 3, 10),
(2, 3, 4),
(2, 4, 11),
(3, 4, 7)
]
assert minimum_travel_cost(n, m, bridges) == 16
def test_minimum_travel_cost_example_2():
n = 5
m = 3
bridges = [
(... | [
{
"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 return find(parent, parent[i])\n\ndef union(parent, rank, x, y):\n ro... | trial_gpt4o_2 | {
"original_instruction": "The Kingdom of Zolon consists of a cluster of islands connected by bridges. There are n islands in total, numbered from 1 to n. Each bridge connects two islands directly and has an associated travel cost. The King of Zolon wants to ensure he can travel between all islands with the minimum t... | 0.753422 | Code_Contests_8646 | C | [
"find",
"union",
"kruskal",
"minimum_travel_cost"
] | 4 | [
[
"kruskal",
"find"
],
[
"kruskal",
"union"
],
[
"minimum_travel_cost",
"kruskal"
],
[
"union",
"find"
]
] | 4 | [] | false | [] | false | pytest | false | [] | true | 56fe8ac60eb6e039fce8977acb4eeb4786fdf418 | 939ee5b2bfd87ad59744a2a0cc4d78708e485d65 | |||
v1.0 | complete | Code_Contests | Code_Contests_8786_C | def is_point_in_triangle(x1: int, y1: int, x2: int, y2: int, x3: int, y3: int, xp: int, yp: int) -> str:
"""
Determine if a point lies inside, outside, or on the border of a given triangle.
Parameters:
x1, y1, x2, y2, x3, y3, xp, yp : int
The coordinates of the vertices of the triangle (x1... | def orientation(p, q, r):
"""
Return the orientation of the triplet (p, q, r).
0 -> p, q and r are collinear
1 -> Clockwise
2 -> Counterclockwise
"""
val = (q[1] - p[1]) * (r[0] - q[0]) - (q[0] - p[0]) * (r[1] - q[1])
if val == 0:
return 0
elif val > 0:
return 1
e... | from solution import is_point_in_triangle
def test_inside():
assert is_point_in_triangle(0, 0, 5, 0, 0, 5, 1, 1) == "Inside"
def test_outside():
assert is_point_in_triangle(0, 0, 5, 0, 0, 5, 5, 1) == "Outside"
def test_border():
assert is_point_in_triangle(0, 0, 5, 0, 0, 5, 2.5, 0) == "Border"
def t... | [
{
"docstring": "Return the orientation of the triplet (p, q, r).\n0 -> p, q and r are collinear\n1 -> Clockwise\n2 -> Counterclockwise",
"function_declaration": "def orientation(p, q, r):",
"function_name": "orientation",
"parameter_list": "(p, q, r)"
},
{
"docstring": "Check if point q lies... | [
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 point_in_triangle(x1, y1, x2, y2, x3, y3, xp, yp):\n def area(x1, y1, x2, y2, x3, y3):\n return abs((x1*(y2-y3) + x2*(y3-y1) + x3*(y1-y2)) / ... | trial_gpt4o_2 | {
"original_instruction": "Write a program that determines if a point lies inside, outside, or on the border of a given triangle. The vertices of the triangle and the coordinates of the point are provided as input.\n\nConstraints\n\n* $-100 \\leq x_1, y_1, x_2, y_2, x_3, y_3, x_p, y_p \\leq 100$\n\nInput\n\nEight int... | 0.765787 | Code_Contests_8786 | C | [
"orientation",
"on_segment",
"is_point_in_triangle"
] | 3 | [
[
"is_point_in_triangle",
"on_segment"
],
[
"is_point_in_triangle",
"orientation"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 1de8f42c220172d2466cf9acf467596f2e23fd75 | 140c3d0166720e68c61db20948d2010626b0d40a | |||
v1.0 | complete | Code_Contests | Code_Contests_9722_C | def is_super_prime(n: int) -> str:
""" Given a positive integer n, determine whether it is a super prime.
A super prime is a prime number that occupies the prime position in the list of prime numbers.
>>> is_super_prime(5)
"YES"
>>> is_super_prime(12)
"NO"
""" | def is_prime(num):
if num < 2:
return False
for i in range(2, int(num ** 0.5) + 1):
if num % i == 0:
return False
return True
def generate_primes_up_to(n):
primes = []
candidate = 2
while len(primes) < n:
if is_prime(candidate):
primes.append(cand... | from solution import is_super_prime
def test_is_super_prime_case1():
assert is_super_prime(5) == "YES"
def test_is_super_prime_case2():
assert is_super_prime(12) == "NO"
def test_is_super_prime_first_few_primes():
assert is_super_prime(2) == "NO" # 2 is the 1st prime, 1 is not a prime
assert is_supe... | [
{
"docstring": null,
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": null,
"function_declaration": "def generate_primes_up_to(n):",
"function_name": "generate_primes_up_to",
"parameter_list": "(n)"
},
{
... | [
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_prime(num):\n \"\"\"\n Returns True if the given num is a prime number, otherwise False.\n \"\"\"\n if num <= 1:\n return False\n... | trial_gpt4o_2 | {
"original_instruction": "Given a positive integer `n`, determine whether it is a super prime. A super prime is a prime number that occupies the prime position in the list of prime numbers. For example, 5 is the third prime number and 3 is also a prime, so 5 is a super prime.\n\nInput\n\nThe single line of input con... | 0.777205 | Code_Contests_9722 | C | [
"is_prime",
"generate_primes_up_to",
"is_super_prime"
] | 3 | [
[
"generate_primes_up_to",
"is_prime"
],
[
"is_super_prime",
"generate_primes_up_to"
],
[
"is_super_prime",
"is_prime"
]
] | 3 | [] | false | [] | false | pytest | true | [] | true | 354ef975edbbbcc3c3da14e49c3dacfb2d01194b | 7fc16f2c580cad8a6f281ca0ad8e55e2cbbad231 | |||
v1.0 | complete | Code_Contests | Code_Contests_9430_C | def is_path_exist(grid):
""" Determine if there's a path from the top-left corner to the bottom-right corner of the grid.
"""
def solve(mazes):
""" Solve the path finding for multiple mazes.
"""
def process_input(input_data):
""" Process input data.
"""
def main(input_data):
""" Main ... | def is_path_exist(grid):
def dfs(x, y):
if x < 0 or x >= m or y < 0 or y >= n or grid[x][y] == 'X' or visited[x][y]:
return False
if x == m - 1 and y == n - 1:
return True
visited[x][y] = True
# Move in four possible directions: down, up, rig... | import pytest
from solution import main
def test_example_case():
input_data = "3\n3 3\nOXO\nOOX\nXOX\n4 4\nOOOO\nXXOX\nXXOX\nOOOX\n2 2\nOX\nXO\n"
expected_output = "NO\nYES\nNO\n"
main(input_data) | [
{
"docstring": null,
"function_declaration": "def is_path_exist(grid):",
"function_name": "is_path_exist",
"parameter_list": "(grid)"
},
{
"docstring": null,
"function_declaration": "def solve(mazes):",
"function_name": "solve",
"parameter_list": "(mazes)"
},
{
"docstring... | [
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 is_path_exist(maze):\n \"\"\"\n Returns 'YES' if there's a path from the top-left to the bottom-right\n corner of the maze. Otherwise returns ... | trial_gpt4o_5 | {
"original_instruction": "You are given an m x n grid representing a maze. Each cell in the grid is either an open space 'O' or a wall 'X'. The goal is to determine if there's a path from the top-left corner to the bottom-right corner of the grid, only moving up, down, left, or right through open spaces.\n\nInput\n\... | 0.548126 | Code_Contests_9430 | C | [
"is_path_exist",
"solve",
"process_input",
"main"
] | 4 | [
[
"solve",
"is_path_exist"
]
] | 1 | [
"process_input"
] | false | [] | false | pytest | true | [] | true | d5863cb06fab9d616af5a93b0feb02df745314ec | 602b788e7c669a693b4b38d26fdeec90d6c937f8 | |||
v1.0 | complete | Code_Contests | Code_Contests_9071_C | def can_form_palindrome(word: str) -> bool:
"""
Check if a word can be rearranged to form a palindrome.
>>> can_form_palindrome("civic") True
>>> can_form_palindrome("ivicc") True
>>> can_form_palindrome("hello") False
>>> can_form_palindrome("aabbcc") True
>>> can_form_palindrome("xyz") Fal... | def can_form_palindrome(word):
"""
Check if a word can be rearranged to form a palindrome.
"""
from collections import Counter
count = Counter(word)
odd_count = sum(1 for cnt in count.values() if cnt % 2 != 0)
return odd_count <= 1
def longest_palindromic_word(words):
"""
Find the l... | from solution import can_form_palindrome, longest_palindromic_word, process_test_cases
def test_can_form_palindrome():
assert can_form_palindrome("civic") == True
assert can_form_palindrome("ivicc") == True
assert can_form_palindrome("hello") == False
assert can_form_palindrome("aabbcc") == True
as... | [
{
"docstring": "Check if a word can be rearranged to form a palindrome.",
"function_declaration": "def can_form_palindrome(word):",
"function_name": "can_form_palindrome",
"parameter_list": "(word)"
},
{
"docstring": "Find the longest word in the list that can be rearranged to form a palindr... | [
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_form_palindrome(word):\n \"\"\"\n Checks if a given word can be rearranged to form a palindrome.\n \"\"\"\n from collections import Cou... | trial_gpt4o_3 | {
"original_instruction": "You are given a list of words. Write a program to determine the longest word in which the letters can be rearranged to form a palindrome. If there are multiple words with the same longest length, return any one of them. A word can be rearranged to form a palindrome if at most one character ... | 0.775969 | Code_Contests_9071 | C | [
"can_form_palindrome",
"longest_palindromic_word",
"process_test_cases"
] | 3 | [
[
"longest_palindromic_word",
"can_form_palindrome"
],
[
"process_test_cases",
"longest_palindromic_word"
]
] | 2 | [
"process_test_cases"
] | false | [] | false | pytest | true | [] | true | 6026c6f0ed1b601c832ce75a4ef8576ceaeed64b | cb36cf3bdae0d30b2e9c80ee0d8cafa0c01f6a4d | |||
v1.0 | complete | Code_Contests | Code_Contests_9433_C | def is_prime(num):
"""
Check if a number is a prime number.
"""
pass
def generate_fibonacci_primes(n):
"""
Generate the first N Fibonacci Primes.
"""
pass
def find_fibonacci_primes(n):
"""
Find the first N Fibonacci Primes and return them separated by spaces.
"""
pass... | def is_prime(num):
"""
Check if a number is a prime number.
"""
if num <= 1:
return False
if num <= 3:
return True
if num % 2 == 0 or num % 3 == 0:
return False
i = 5
while i * i <= num:
if num % i == 0 or num % (i + 2) == 0:
return False
... | from solution import find_fibonacci_primes
def test_find_fibonacci_primes_1():
assert find_fibonacci_primes(1) == "2"
def test_find_fibonacci_primes_3():
assert find_fibonacci_primes(3) == "2 3 5"
def test_find_fibonacci_primes_5():
assert find_fibonacci_primes(5) == "2 3 5 13 89"
def test_find_fibonacc... | [
{
"docstring": "Check if a number is a prime number.",
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": "Generate the first N Fibonacci Primes.",
"function_declaration": "def generate_fibonacci_primes(n):",
"functi... | [
1,
1
] | 2 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(num):\n \"\"\"Returns True if num is prime, otherwise False.\"\"\"\n if num <= 1:\n return False\n if num <= 3:\n retur... | trial_gpt4o_2 | {
"original_instruction": "A scientist discovered a new pattern in a specific sequence of numbers known as Fibonacci Primes. A Fibonacci Prime is a Fibonacci number that is also a prime number. The Fibonacci sequence is a series of numbers in which each number is the sum of the two preceding ones, usually starting wi... | 0.789622 | Code_Contests_9433 | C | [
"is_prime",
"generate_fibonacci_primes",
"find_fibonacci_primes"
] | 3 | [
[
"find_fibonacci_primes",
"generate_fibonacci_primes"
],
[
"generate_fibonacci_primes",
"is_prime"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | c2ae770c0244ca135552617fab90d72d09dc4194 | 8280beb887b9cbfd54125eefbc892be30deec691 | |||
v1.0 | complete | Code_Contests | Code_Contests_9078_C | def solve_game(n: int, m: int, k: int, grid: List[str], characters: List[Tuple[int, int, int, int]]) -> str:
""" Determine whether it is possible for each character to reach its respective target position in a grid.
If it is possible, return "YES" followed by k integers denoting the minimum number of steps each... | from collections import deque
def is_valid_move(grid, n, m, row, col):
return 0 <= row < n and 0 <= col < m and grid[row][col] == '.'
def bfs(grid, n, m, start, target):
directions = [(-1, 0), (1, 0), (0, -1), (0, 1)]
queue = deque([(start[0], start[1], 0)]) # (row, col, steps)
visited = set((start[0... | def test_solve_game():
assert solve_game(5, 5, 2, ["..#..", ".....", "####.", ".....", "....."], [(1, 1, 2, 2), (4, 4, 5, 5)]) == "YES\n2 2"
assert solve_game(3, 3, 1, [".#.", ".#.", ".#."], [(1, 1, 3, 3)]) == "NO"
assert solve_game(2, 2, 1, ["..", ".."], [(1, 1, 2, 2)]) == "YES\n2"
assert solve_game(3,... | [
{
"docstring": null,
"function_declaration": "def is_valid_move(grid, n, m, row, col):",
"function_name": "is_valid_move",
"parameter_list": "(grid, n, m, row, col)"
},
{
"docstring": null,
"function_declaration": "def bfs(grid, n, m, start, target):",
"function_name": "bfs",
"pa... | [
1,
1
] | 2 | easy | 1 | {
"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 is_valid_move(grid, n, m, row, col):\n return 0 <= row < n and 0 <= col < m and grid[row][col] == '.'\n\ndef bfs(gr... | trial_gpt4o_0 | {
"original_instruction": "In a fictional game, you are given a grid with n rows and m columns. This grid contains some obstacles and some empty cells. You can move in four possible directions from an empty cell: up, down, left, or right, but cannot move into a cell with an obstacle. You are provided with the initial... | 0.805794 | Code_Contests_9078 | C | [
"is_valid_move",
"bfs",
"solve_game"
] | 3 | [
[
"bfs",
"is_valid_move"
],
[
"solve_game",
"bfs"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | cd56272989b0ce92b25ac506740ee3185d76fe06 | 2d9f9c7aa7fe580b502bd6998015ad688ca2c6ae | |||
v1.0 | complete | Code_Contests | Code_Contests_9178_C | from typing import List, Tuple
def number_of_connected_components(input_data: str) -> int:
""" Determine the number of connected components in the given undirected graph.
Args:
input_data (str): Input in the format:
N M
u_1 v_1
u_2 v_2
... | def find_connected_components(N, edges):
from collections import defaultdict, deque
def bfs(start):
queue = deque([start])
visited.add(start)
while queue:
node = queue.popleft()
for neighbor in graph[node]:
if neighbor not in visited:
... | from solution import number_of_connected_components
def test_sample_input_1():
input_data = """5 3
1 2
2 3
4 5"""
assert number_of_connected_components(input_data) == 2
def test_sample_input_2():
input_data = """6 0"""
assert number_of_connected_components(input_data) == 6
def test_sample_input_3():
... | [
{
"docstring": null,
"function_declaration": "def find_connected_components(N, edges):",
"function_name": "find_connected_components",
"parameter_list": "(N, edges)"
},
{
"docstring": null,
"function_declaration": "def parse_input(input_data):",
"function_name": "parse_input",
"p... | [
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_connected_components(N, M, edges):\n from collections import defaultdict, deque\n \n # Create adjacency list\n adjacency_list = defaul... | trial_gpt4o_2 | {
"original_instruction": "You are given an undirected graph with N nodes and M edges. The nodes are numbered from 1 to N. The edges are given as an array of 2-element arrays where each element represents an edge between two nodes.\n\nYour task is to determine the number of connected components in the given graph.\n\... | 0.549696 | Code_Contests_9178 | C | [
"find_connected_components",
"parse_input",
"number_of_connected_components"
] | 3 | [
[
"number_of_connected_components",
"find_connected_components"
],
[
"number_of_connected_components",
"parse_input"
]
] | 2 | [
"parse_input"
] | false | [] | false | pytest | true | [] | true | 3ade723c86f8dfb51eb5261f0dd3bd92e16a3822 | fb9e8455ed15aaf07739467c31bee3ea71bc499f | |||
v1.0 | complete | Code_Contests | Code_Contests_9130_C | def is_prime(x):
"""
Helper function to check if a number is prime.
"""
pass
def next_prime(n):
"""
Function to find the next prime number greater than a given number n.
"""
pass
def smallest_prime_greater_than_max(arr):
"""
Function to find the smallest prime number greater th... | def is_prime(x):
"""
Helper function to check if a number is prime.
"""
if x <= 1:
return False
if x <= 3:
return True
if x % 2 == 0 or x % 3 == 0:
return False
i = 5
while i * i <= x:
if x % i == 0 or x % (i + 2) == 0:
return False
i +... | 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(1000000007) == True
assert is_prime(1000000009) == True
def test_next_prime():
assert next_prime(1) == 2
ass... | [
{
"docstring": "Helper function to check if a number is prime.",
"function_declaration": "def is_prime(x):",
"function_name": "is_prime",
"parameter_list": "(x)"
},
{
"docstring": "Function to find the next prime number greater than a given number n.",
"function_declaration": "def next_p... | [
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 math\n\ndef is_prime(x):\n if x == 2:\n return True\n if x < 2 or x % 2 == 0:\n return False\n for i in range(3, int(math.sqr... | trial_gpt4o_1 | {
"original_instruction": "You are given an array of n positive integers. Your task is to find the smallest prime number greater than the maximum number in the array. If the maximum number in the array is a prime, find the next prime number after it as well.\n\nA prime number is defined as a natural number greater th... | 0.704819 | Code_Contests_9130 | C | [
"is_prime",
"next_prime",
"smallest_prime_greater_than_max",
"solve"
] | 4 | [
[
"next_prime",
"is_prime"
],
[
"smallest_prime_greater_than_max",
"next_prime"
],
[
"solve",
"smallest_prime_greater_than_max"
]
] | 3 | [] | false | [] | false | pytest | false | [] | true | 06e69df1873b546337baa60bf6ce23ad95f80520 | 3f3eae7dceafbfd95b00fccc7044b246f5d9e1d1 | |||
v1.0 | complete | Code_Contests | Code_Contests_8800_C | class BinaryTreeNode:
def __init__(self, value):
self.value = value
self.left = None
self.right = None
def build_sample_tree() -> BinaryTreeNode:
"""
Builds the sample binary tree as described in the prompt.
Returns the root of the tree.
"""
nodes = {i: BinaryTreeNode(i... | class BinaryTreeNode:
def __init__(self, value):
self.value = value
self.left = None
self.right = None
def build_sample_tree():
"""
Builds the sample binary tree as described in the prompt.
Returns the root of the tree.
"""
nodes = {i: BinaryTreeNode(i) for i in rang... | from solution import solve
def test_example_cases():
test_input = ["LRL", "LLL", "RRRR"]
expected_output = [10, 8, None]
assert solve(test_input) == expected_output
def test_empty_path():
test_input = [""]
expected_output = [1]
assert solve(test_input) == expected_output
def test_single_step_... | [] | [
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 BinaryTreeNode:\n def __init__(self, value):\n self.value = value\n self.left = None\n self.right = None\n \ndef build_sam... | trial_gpt4o_0 | {
"original_instruction": "In a distant galaxy, there exists a highly advanced civilization known for its remarkable intelligence and problem-solving skills. Their core transportation system is based on teleportation nodes linked in a complex manner. These nodes are represented by a binary tree.\n\nEach node in this ... | 0.609633 | Code_Contests_8800 | C | [
"build_sample_tree",
"find_node_by_path",
"solve"
] | 3 | [
[
"solve",
"build_sample_tree"
],
[
"solve",
"find_node_by_path"
]
] | 2 | [] | false | [
"BinaryTreeNode"
] | true | pytest | true | [] | true | 018672c4e5b584068e9ab0e1dd5c11bfb3d73a37 | 6430118f232f85d244cb12109811a243b82c82c6 | |||
v1.0 | complete | Code_Contests | Code_Contests_9176_C | from typing import List, Tuple
def max_flow_fuel_network(n: int, m: int, edges: List[Tuple[int, int, int]], s: int, t: int) -> int:
""" Calculate the maximum possible flow of fuel from the source tank to the destination tank.
Arguments:
- n: Number of tanks
- m: Number of pipes
- edges: List of tup... | from collections import deque
def bfs_capacity(residual_graph, source, sink, parent):
"""
Perform BFS on the residual graph to find if there's a path from source to sink.
It also updates the parent array to store the path.
"""
visited = [False] * len(residual_graph)
queue = deque([source])
... | def test_max_flow_fuel_network_basic():
n = 4
m = 5
edges = [
(1, 2, 100),
(1, 3, 100),
(2, 4, 50),
(3, 4, 50),
(2, 3, 50)
]
s = 1
t = 4
assert max_flow_fuel_network(n, m, edges, s, t) == 100
def test_max_flow_fuel_network_single_path():
n = 3
... | [
{
"docstring": "Perform BFS on the residual graph to find if there's a path from source to sink.\nIt also updates the parent array to store the path.",
"function_declaration": "def bfs_capacity(residual_graph, source, sink, parent):",
"function_name": "bfs_capacity",
"parameter_list": "(residual_gra... | [
0,
0,
0,
0,
1
] | 1 | hard | 0.2 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from collections import defaultdict, deque\n\ndef bfs(capacity, flow, source, sink, parent):\n visited = set()\n queue = deque([source])\n visited... | trial_gpt4o_4 | {
"original_instruction": "Alyssa P. Hacker is a renowned engineer who likes to challenge herself with unique optimization problems. This time, she has devised a complex system of pipes interconnecting various fuel tanks in her laboratory. Each pipe has a certain flow capacity, and Alyssa wants to ensure that fuel fl... | 0.700996 | Code_Contests_9176 | C | [
"bfs_capacity",
"edmonds_karp",
"max_flow_fuel_network"
] | 3 | [
[
"edmonds_karp",
"bfs_capacity"
],
[
"max_flow_fuel_network",
"edmonds_karp"
]
] | 2 | [] | false | [] | false | pytest | false | [] | true | e9039443603d6f4bb2c4b51abfeb9237358dac33 | 78a951778c9aa7e385f7b9d07a95a22e8fd34b90 | |||
v1.0 | complete | Code_Contests | Code_Contests_10107_C | from typing import List
def largest_number(n: int, arr: List[int]) -> str:
"""
Reorder a list of non-negative integers to form the largest possible number.
>>> largest_number(3, [3, 30, 34])
'34330'
>>> largest_number(5, [9, 89, 90, 91, 92])
'992919089'
""" | from functools import cmp_to_key
def compare(x, y):
if x + y > y + x:
return -1
elif x + y < y + x:
return 1
else:
return 0
def largest_number(n, arr):
"""
Reorder a list of non-negative integers to form the largest possible number.
"""
arr = list(map(str, arr))
... | from solution import largest_number
def test_single_digit_numbers():
assert largest_number(3, [3, 30, 34]) == '34330'
def test_multiple_non_zero_numbers():
assert largest_number(5, [9, 89, 90, 91, 92]) == '992919089'
def test_all_zeros():
assert largest_number(3, [0, 0, 0]) == '0'
def test_large_numbers... | [
{
"docstring": null,
"function_declaration": "def compare(x, y):",
"function_name": "compare",
"parameter_list": "(x, y)"
},
{
"docstring": "Reorder a list of non-negative integers to form the largest possible number.",
"function_declaration": "def largest_number(n, arr):",
"function... | [
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 functools import cmp_to_key\n\ndef largest_possible_number(nums):\n # Comparator function for sorting\n def compare(a, b):\n if a + b > b... | trial_gpt4o_2 | {
"original_instruction": "Given a list of integers, your task is to reorder these integers to form the largest possible number.\n\nInput\n\nThe input consists of a line containing a single integer n (1 ≤ n ≤ 10^5), the number of integers.\n\nThe next line contains n non-negative integers, each of which is at most 10... | 0.733786 | Code_Contests_10107 | C | [
"compare",
"largest_number"
] | 2 | [
[
"largest_number",
"compare"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 89104254cd021f2b50044b46fb2194eae47220fb | 001fd0bbc084d2769b6d5b6e947fcea05096766d | |||
v1.0 | complete | Code_Contests | Code_Contests_8431_C | def calculate_scoreboard(participants_info, problem_scores):
"""
Calculate the scores of participants and return them sorted by total score (descending)
and by name (ascending) in case of ties.
"""
def get_scoreboard(p, q, problem_scores, participants):
"""
Get the sorted scoreboard for the par... | def calculate_scoreboard(participants_info, problem_scores):
scores = []
for participant in participants_info:
name = participant[0]
scores_for_problems = participant[1:]
total_score = sum(score for score, solved in zip(problem_scores, scores_for_problems) if solved == 1)
sc... | from solution import get_scoreboard, format_scoreboard
def test_example_1():
p = 3
q = 4
problem_scores = [500, 300, 200, 400]
participants = [
"alice 1 0 1 1",
"bob 0 1 1 0",
"charlie 1 1 0 0"
]
expected_output = [
"alice 1100",
"charlie 800",
"b... | [
{
"docstring": null,
"function_declaration": "def calculate_scoreboard(participants_info, problem_scores):",
"function_name": "calculate_scoreboard",
"parameter_list": "(participants_info, problem_scores)"
},
{
"docstring": null,
"function_declaration": "def get_scoreboard(p, q, problem_... | [
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": "def compute_scoreboard(participants, scores):\n \"\"\"\n Computes the scoreboard based on participants' performance.\n Participants are sorted by ... | trial_gpt4o_1 | {
"original_instruction": "You are organizing a coding competition and need to create a scoreboard. Each participant accumulates points for solving problems, but the score distribution is not based on the order in which the problems are solved, only on the number of problems solved and the points assigned to each.\n\... | 0.63084 | Code_Contests_8431 | C | [
"calculate_scoreboard",
"get_scoreboard",
"format_scoreboard"
] | 3 | [
[
"get_scoreboard",
"calculate_scoreboard"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 77baf1bb4cb5fa946bae0438d395a9f7bd5166b1 | 3a3a59073e18c88aa36fc237fb5b9b5800e6becd | |||
v1.0 | complete | Code_Contests | Code_Contests_9102_C | def validate_quiz_question(question_line: str) -> str:
"""
Validates a quiz question.
Args:
question_line (str): A single line representing a quiz question and its answers.
Returns:
str: "Valid Question" if the question is valid, "Invalid Question" otherwise.
>>> validate_quiz_question("W... | def validate_quiz_question(question_line):
"""
Validates a quiz question.
Args:
question_line (str): A single line representing a quiz question and its answers.
Returns:
str: "Valid Question" if the question is valid, "Invalid Question" otherwise.
"""
if not question_line:
... | from solution import validate_quiz_question, validate_quiz_questions
def test_single_valid_question():
question = "What is the capital of France? Paris(correct), London(incorrect), Berlin(incorrect)"
assert validate_quiz_question(question) == "Valid Question"
def test_single_invalid_question_no_correct_answer... | [
{
"docstring": "Validates a quiz question.\n\nArgs:\nquestion_line (str): A single line representing a quiz question and its answers.\n\nReturns:\nstr: \"Valid Question\" if the question is valid, \"Invalid Question\" otherwise.",
"function_declaration": "def validate_quiz_question(question_line):",
"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 re\n\ndef validate_quiz_questions(questions):\n results = []\n for question in questions:\n if is_valid_question(question):\n ... | trial_gpt4o_2 | {
"original_instruction": "You have been hired by an education software company to create a quiz application where users can add new quiz questions. To ensure the users provide valid inputs, you need to create a function that checks the format of the questions and answers. Each question consists of a question text fo... | 0.485541 | Code_Contests_9102 | C | [
"validate_quiz_question",
"validate_quiz_questions"
] | 2 | [
[
"validate_quiz_questions",
"validate_quiz_question"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | e3260ff1f8ac765e9ef9ee60b92ab2218457068e | a039530fd595915c67bc91459cc9aef9dddb5b42 | |||
v1.0 | complete | Code_Contests | Code_Contests_9121_C | def minimum_cost_to_connect_data_nodes(N: int, M: int, connections: List[Tuple[int, int, int]]) -> int:
""" Determine the minimum cost to ensure all DataNodes can communicate.
If it's not possible to connect all nodes, return -1.
Args:
N (int): The number of DataNodes.
M (int): The numb... | def find(parent, i):
if parent[i] == i:
return i
else:
return find(parent, 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] = rootX
elif rank[root... | from solution import minimum_cost_to_connect_data_nodes
def test_example_case():
assert minimum_cost_to_connect_data_nodes(5, 7, [
(0, 1, 10),
(0, 4, 20),
(1, 2, 30),
(1, 3, 40),
(2, 3, 50),
(3, 4, 60),
(1, 4, 70)
]) == 100
def test_single_connection():
... | [
{
"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,
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 find(parent, i):\n if parent[i] == i:\n return i\n else:\n return find(parent, parent[i])\n\ndef union(parent, rank, x, y):\n ro... | trial_gpt4o_1 | {
"original_instruction": "You are tasked with managing the DataTransferGrid of a corporation. The grid is composed of N DataNodes connected by M communication lines. Each communication line has an associated cost for data transfer. Your job is to ensure that data can be transferred between any two DataNodes in the g... | 0.624121 | Code_Contests_9121 | C | [
"find",
"union",
"minimum_cost_to_connect_data_nodes"
] | 3 | [
[
"minimum_cost_to_connect_data_nodes",
"find"
],
[
"minimum_cost_to_connect_data_nodes",
"union"
],
[
"union",
"find"
]
] | 3 | [] | false | [] | false | pytest | true | [] | true | f24b61e8eee12ec00c01a055737e7bf493f9b462 | ef783e185a219038b59923a925d3f54dea7f00dd | |||
v1.0 | complete | Code_Contests | Code_Contests_9744_C | from typing import List, Tuple
def shortest_path(n: int, m: int, k: int, roads: List[Tuple[int, int, int]], s: int) -> int:
""" Determines the shortest distance from a starting city to a destination city
using Dijkstra's algorithm.
Parameters:
n (int): The number of cities.
m (int): The number of... | import heapq
def dijkstra(n, edges, start, dest):
graph = {i: [] for i in range(1, n+1)}
for u, v, w in edges:
graph[u].append((w, v))
graph[v].append((w, u))
distance = {i: float('inf') for i in range(1, n+1)}
distance[start] = 0
priority_queue = [(0, start)]
while pr... | from solution import shortest_path
def test_shortest_path1():
assert shortest_path(4, 4, 3, [(1, 2, 4), (2, 3, 1), (1, 3, 7), (3, 4, 3)], 1) == 5
def test_shortest_path2():
assert shortest_path(4, 2, 4, [(1, 2, 4), (2, 3, 1)], 1) == -1
def test_shortest_path3():
assert shortest_path(3, 3, 3, [(1, 2, 2), ... | [
{
"docstring": null,
"function_declaration": "def dijkstra(n, edges, start, dest):",
"function_name": "dijkstra",
"parameter_list": "(n, edges, start, dest)"
},
{
"docstring": null,
"function_declaration": "def shortest_path(n, m, k, roads, s):",
"function_name": "shortest_path",
... | [
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 dijkstra(n, m, k, roads, start):\n graph = {i: [] for i in range(1, n+1)}\n for u, v, w in roads:\n graph[u].a... | trial_gpt4o_2 | {
"original_instruction": "There is a kingdom with several cities, and each city is connected to other cities by bidirectional roads. Each road has a certain length. The King wants to find the shortest path from one specified city to another specified city.\n\nGiven the number of cities, the number of roads, and the ... | 0.693704 | Code_Contests_9744 | C | [
"dijkstra",
"shortest_path"
] | 2 | [
[
"shortest_path",
"dijkstra"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | ca6281e7d36ad52c6d61cb0c5948850e62a12dc1 | 355d36f3a8dec95cf221ad56b28a1e3c7689f8a8 | |||
v1.0 | complete | Code_Contests | Code_Contests_9777_C | def create_path(N):
"""
Generates a sequence of cell numbers in an N x N grid
from the top-left corner to the bottom-right corner,
visiting each cell exactly once.
>>> create_path(2)
"1 2 4 3"
>>> create_path(3)
"1 2 3 6 9 8 7 4 5"
>>> create_path(4)
"1 2 3 4 8 12 16 15 14 13 9... | def create_path(N):
"""
Creates a sequence of cell numbers in an N x N grid
from the top-left corner to the bottom-right corner
visiting each cell exactly once.
"""
path = []
top, left, bottom, right = 0, 0, N-1, N-1
direction = 'right'
while top <= bottom and left <= right:
... | from solution import grid_path_sequence
def test_path_for_2():
assert grid_path_sequence(2) == "1 2 4 3"
def test_path_for_3():
assert grid_path_sequence(3) == "1 2 3 6 9 8 7 4 5"
def test_path_for_4():
assert grid_path_sequence(4) == "1 2 3 4 8 12 16 15 14 13 9 5 6 7 11 10"
def test_path_for_5():
a... | [
{
"docstring": "Creates a sequence of cell numbers in an N x N grid \nfrom the top-left corner to the bottom-right corner \nvisiting each cell exactly once.",
"function_declaration": "def create_path(N):",
"function_name": "create_path",
"parameter_list": "(N)"
},
{
"docstring": null,
"f... | [
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 create_path(N):\n \"\"\"\n Creates a sequence of cell numbers in an N x N grid \n from the top-left corner to the bottom-right corner \n vi... | trial_gpt4o_0 | {
"original_instruction": "Peter loves working with grids. He recently came across a problem where he needs to create a specific path in an N x N grid. Each cell in the grid has a number, starting from 1 at the top-left corner and increasing row-wise. That means the first cell of the first row will be 1, the second c... | 0.663631 | Code_Contests_9777 | C | [
"create_path",
"grid_path_sequence"
] | 2 | [
[
"grid_path_sequence",
"create_path"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 347cd22317fcaa517258ab95e993fe8c68290683 | cb85b8cdde001efc7d3da1bab61f318520b995f6 | |||
v1.0 | complete | Code_Contests | Code_Contests_8843_C | def ip_to_binary(ip: str) -> str:
""" Convert an IP address from dotted decimal format to a binary string.
>>> ip_to_binary("192.168.1.10")
'11000000101010000000000100001010'
>>> ip_to_binary("255.255.255.0")
'11111111111111111111111100000000'
"""
pass
def binary_to_ip(binary: str) -> str:
... | def ip_to_binary(ip):
return ''.join(f'{int(octet):08b}' for octet in ip.split('.'))
def binary_to_ip(binary):
return '.'.join(str(int(binary[i:i+8], 2)) for i in range(0, 32, 8))
def network_and_broadcast(ip, subnet):
ip_bin = ip_to_binary(ip)
subnet_bin = ip_to_binary(subnet)
# Calculate ne... | from solution import ip_to_binary, binary_to_ip, network_and_broadcast, process_input
def test_ip_to_binary():
assert ip_to_binary("192.168.1.10") == "11000000101010000000000100001010"
assert ip_to_binary("255.255.255.0") == "11111111111111111111111100000000"
assert ip_to_binary("0.0.0.0") == "000000000000... | [
{
"docstring": null,
"function_declaration": "def ip_to_binary(ip):",
"function_name": "ip_to_binary",
"parameter_list": "(ip)"
},
{
"docstring": null,
"function_declaration": "def binary_to_ip(binary):",
"function_name": "binary_to_ip",
"parameter_list": "(binary)"
},
{
... | [
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 dotted_decimal_to_binary(ip):\n return ''.join(f'{int(octet):08b}' for octet in ip.split('.'))\n\ndef binary_to_dotted_decimal(binary):\n return ... | trial_gpt4o_2 | {
"original_instruction": "The Company X, a web hosting provider, wants to manage its IP addresses more efficiently. One key aspect of this management is to identify the network address and the broadcast address for a given IP address and its subnet mask. In this task, you will write a program that takes an IP addres... | 0.582251 | Code_Contests_8843 | C | [
"ip_to_binary",
"binary_to_ip",
"network_and_broadcast",
"process_input"
] | 4 | [
[
"network_and_broadcast",
"binary_to_ip"
],
[
"network_and_broadcast",
"ip_to_binary"
],
[
"process_input",
"network_and_broadcast"
]
] | 3 | [
"process_input"
] | false | [] | false | pytest | true | [] | true | 85d128142e4778080e1c71708042b5c7d4428184 | 50ae7aa60c9057a4720a5ebafdead17a59f38704 | |||
v1.0 | complete | Code_Contests | Code_Contests_10141_C | def fib(n):
"""
Computes the nth Fibonacci number.
"""
# Write your code here
def total_fib_leaves(depth):
"""
Computes the total number of leaves in the Fibonacci Tree
up to the given depth.
>>> total_fib_leaves(0) 0
>>> total_fib_leaves(1) 1
>>> total_fib_leaves(2) 2
>>>... | def fib(n):
"""
Computes the nth Fibonacci number.
"""
if n == 0: return 0
if n == 1: return 1
a, b = 0, 1
for _ in range(2, n + 1):
a, b = b, a + b
return b
def total_fib_leaves(depth):
"""
Computes the total number of leaves in the Fibonacci Tree
up to the given d... | from solution import fib, total_fib_leaves, process_test_cases
def test_fib():
assert fib(0) == 0
assert fib(1) == 1
assert fib(2) == 1
assert fib(3) == 2
assert fib(4) == 3
assert fib(5) == 5
assert fib(6) == 8
assert fib(10) == 55
def test_total_fib_leaves():
assert total_fib_lea... | [
{
"docstring": "Computes the nth Fibonacci number.",
"function_declaration": "def fib(n):",
"function_name": "fib",
"parameter_list": "(n)"
},
{
"docstring": "Computes the total number of leaves in the Fibonacci Tree \nup to the given depth.",
"function_declaration": "def total_fib_leave... | [
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 fibonacci_sum_up_to_depth(d):\n \"\"\"\n Calculate the sum of Fibonacci numbers from F(0) to F(d).\n \"\"\"\n if d == 0:\n return 0\... | trial_gpt4o_2 | {
"original_instruction": "In a mythical universe, there is a magical tree known as the Fibonacci Tree. This tree has the special property that the number of leaves at depth n is equal to the nth Fibonacci number. The depth of a tree is the number of edges in the longest path from the root to any leaf.\n\nEmily, a bo... | 0.717172 | Code_Contests_10141 | C | [
"fib",
"total_fib_leaves",
"process_test_cases"
] | 3 | [
[
"process_test_cases",
"total_fib_leaves"
],
[
"total_fib_leaves",
"fib"
]
] | 2 | [
"process_test_cases"
] | false | [] | false | pytest | true | [] | true | 2bb5ebd281e8dcdc372219d10e202130b3f0bfef | 5508efc7d3951a87091c30eed971972cd8ed1073 | |||
v1.0 | complete | Code_Contests | Code_Contests_9800_C | from collections import Counter
from itertools import permutations
MOD = 10**9 + 7
def is_valid_permutation(perm: str) -> bool:
""" Check if the given permutation of a string is valid.
Valid permutation means no two consecutive characters in the permutation are the same.
>>> is_valid_permutation("abab") =... | MOD = 10**9 + 7
from collections import Counter
from itertools import permutations
def is_valid_permutation(perm):
for i in range(len(perm) - 1):
if perm[i] == perm[i + 1]:
return False
return True
def count_valid_permutations(s):
n = len(s)
count = 0
all_permutations = set(pe... | def test_is_valid_permutation():
assert is_valid_permutation("abab") == True
assert is_valid_permutation("aabb") == False
assert is_valid_permutation("abc") == True
assert is_valid_permutation("aabbcc") == False
def test_count_valid_permutations():
assert count_valid_permutations("abc") == 6
as... | [
{
"docstring": null,
"function_declaration": "def is_valid_permutation(perm):",
"function_name": "is_valid_permutation",
"parameter_list": "(perm)"
},
{
"docstring": null,
"function_declaration": "def count_valid_permutations(s):",
"function_name": "count_valid_permutations",
"pa... | [
0,
0,
0,
1,
0
] | 1 | hard | 0.2 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from collections import Counter\nimport itertools\nMOD = 10**9 + 7\n\n# Helper function to check if a permutation is valid\ndef is_valid_permutation(perm):... | trial_gpt4o_3 | {
"original_instruction": "You are given a string s consisting of lowercase English letters. For a string t, defined as a permutation of string s, let's call it a valid permutation if there are no two consecutive characters in t that are the same.\n\nDetermine the number of valid permutations of s. If the number is l... | 0.720371 | Code_Contests_9800 | C | [
"is_valid_permutation",
"count_valid_permutations",
"solve"
] | 3 | [
[
"count_valid_permutations",
"is_valid_permutation"
],
[
"solve",
"count_valid_permutations"
]
] | 2 | [] | false | [] | false | pytest | false | [] | true | 71bcb6575ce23acbde05f5b48a108c9836c572fe | 4270f2221be944da61b03fc176000aa02cf53399 | |||
v1.0 | complete | Code_Contests | Code_Contests_10332_C | def minimum_spanning_tree_cost(n: int, m: int, edges: List[Tuple[int, int, int]]) -> int:
""" Determine the minimum cost required to connect all rides in an amusement park (as a minimum spanning tree).
>>> minimum_spanning_tree_cost(4, 5, [(1, 2, 1), (1, 3, 4), (2, 3, 2), (2, 4, 7), (3, 4, 3)])
6
>>> mi... | def find(parent, i):
if parent[i] == i:
return i
return find(parent, parent[i])
def union(parent, rank, x, y):
root_x = find(parent, x)
root_y = find(parent, y)
if rank[root_x] < rank[root_y]:
parent[root_x] = root_y
elif rank[root_y] < rank[root_x]:
parent[root_y] ... | def test_example_case():
n, m = 4, 5
edges = [
(1, 2, 1),
(1, 3, 4),
(2, 3, 2),
(2, 4, 7),
(3, 4, 3)
]
assert minimum_spanning_tree_cost(n, m, edges) == 6
def test_disjoint_case():
n, m = 6, 7
edges = [
(1, 2, 1),
(2, 3, 4),
(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,
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(parent, i):\n if parent[i] == i:\n return i\n return find(parent, parent[i])\n\ndef union(parent, rank, x, y):\n root_x = find(par... | trial_gpt4o_2 | {
"original_instruction": "A city is planning to construct a series of amusement rides, each connected by paths. Each ride is represented as a node and each path between rides as an edge, forming a connected undirected graph. The cost of constructing each path varies.\n\nThe city planners want to ensure that the enti... | 0.725856 | Code_Contests_10332 | C | [
"find",
"union",
"kruskal",
"minimum_spanning_tree_cost"
] | 4 | [
[
"kruskal",
"find"
],
[
"kruskal",
"union"
],
[
"minimum_spanning_tree_cost",
"kruskal"
],
[
"union",
"find"
]
] | 4 | [] | false | [] | false | pytest | false | [] | true | 081b14fda016962d943540d6768299bed81e7425 | 6802d8b5185efff9288e6a4fdd7741f6af8bcae8 | |||
v1.0 | complete | Code_Contests | Code_Contests_9905_C | import math
from typing import List, Tuple
def gcd(a: int, b: int) -> int:
""" Calculate the greatest common divisor (GCD) of two integers.
>>> gcd(10, 5) 5
>>> gcd(14, 21) 7
>>> gcd(1, 1) 1
"""
pass
def minimum_in_range(arr: List[int], l: int, r: int) -> int:
""" Find the minimum integer ... | import math
def gcd(a, b):
while b:
a, b = b, a % b
return a
def minimum_in_range(arr, l, r):
return min(arr[l-1:r])
def process_queries(n, sequence, q, queries):
results = []
for l, r, k in queries:
min_in_range = minimum_in_range(sequence, l, r)
results.append(gcd(min_in... | from solution import gcd, minimum_in_range, process_queries
def test_gcd():
assert gcd(10, 5) == 5
assert gcd(14, 21) == 7
assert gcd(1, 1) == 1
assert gcd(27, 14) == 1
assert gcd(100, 200) == 100
def test_minimum_in_range():
assert minimum_in_range([2, 6, 4, 8, 10], 1, 3) == 2
assert mini... | [
{
"docstring": null,
"function_declaration": "def gcd(a, b):",
"function_name": "gcd",
"parameter_list": "(a, b)"
},
{
"docstring": null,
"function_declaration": "def minimum_in_range(arr, l, r):",
"function_name": "minimum_in_range",
"parameter_list": "(arr, l, r)"
},
{
... | [
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 gcd_of_min_in_range_and_k(n, sequence, queries):\n \"\"\"\n Determines the GCD of the minimum integer within a specified range in ... | trial_gpt4o_2 | {
"original_instruction": "Given a sequence of `n` integers and a series of queries, determine the greatest common divisor (GCD) of the minimum integer within a specified range in the sequence and a given integer `k`.\n\nEach query specifies a range of the sequence and an integer `k`. The task is to find the minimum ... | 0.655422 | Code_Contests_9905 | C | [
"gcd",
"minimum_in_range",
"process_queries"
] | 3 | [
[
"process_queries",
"gcd"
],
[
"process_queries",
"minimum_in_range"
]
] | 2 | [
"process_queries"
] | false | [] | false | pytest | true | [] | true | 2edd42db77a68baff19e868918b4b18ce6e3f779 | cc5fe4a4e47e36d255a29e5c22e5f980a49ef463 | |||
v1.0 | complete | Code_Contests | Code_Contests_8534_C | def evaluate_all_hierarchies(input_data: List[str]) -> str:
""" Evaluate hierarchical relationships in a company, verifying if statements about the hierarchy are valid or not.
:param input_data: List of strings representing hierarchy and statements
:return: String with each statement evaluation result in a ... | def process_hierarchy(n, m, hierarchy_lines, statements):
hierarchy = {}
superior_map = {}
colleague_map = {}
current_depth = -1
parent_stack = []
for line in hierarchy_lines:
depth = 0
while depth < len(line) and line[depth] == ' ':
depth += 1
name = line[d... | def test_single_hierarchy_single_statement():
input_data = [
"7 5",
"Alice",
" Bob",
" Carol",
" Dave",
" Eve",
" Frank",
" Grace",
"Carol is a direct subordinate of Bob.",
"Grace is a superior of Frank.",
"Dave is a collea... | [
{
"docstring": null,
"function_declaration": "def process_hierarchy(n, m, hierarchy_lines, statements):",
"function_name": "process_hierarchy",
"parameter_list": "(n, m, hierarchy_lines, statements)"
},
{
"docstring": null,
"function_declaration": "def evaluate_all_hierarchies(input_data... | [
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 parse_hierarchy(n, lines):\n hierarchy = {}\n stack = []\n for line in lines:\n level = len(line) - len(line.lstrip())\n employe... | trial_gpt4o_1 | {
"original_instruction": "A company manages a hierarchical structure of employees and their subordinates. The hierarchy is represented using a text file where each line contains the name of an employee. The first line contains the name of the CEO, and each subsequent line is indented to signify that the employee is ... | 0.561635 | Code_Contests_8534 | C | [
"process_hierarchy",
"evaluate_all_hierarchies"
] | 2 | [
[
"evaluate_all_hierarchies",
"process_hierarchy"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | 65165c31917e1e4044878a1e18057cfe380194aa | 8663906e13391566f26b9ae7c94df1af198af3ba | |||
v1.0 | complete | Code_Contests | Code_Contests_10137_C | def minimum_spanning_tree_cost(n: int, cables: List[Tuple[int, int, int]]) -> int:
"""
Calculate the minimum total data transfer cost within the network. n is the number of computers, and cables is a list of tuples
where each tuple contains three integers (u, v, c) representing a cable connecting computer... | def find(parent, i):
if parent[i] == i:
return i
return find(parent, parent[i])
def union(parent, rank, x, y):
root_x = find(parent, x)
root_y = find(parent, y)
if rank[root_x] < rank[root_y]:
parent[root_x] = root_y
elif rank[root_x] > rank[root_y]:
parent[root_y] = ro... | from solution import minimum_spanning_tree_cost
def test_example1():
n = 4
cables = [
(1, 2, 3),
(2, 3, 4),
(3, 4, 2),
(4, 1, 5)
]
assert minimum_spanning_tree_cost(n, cables) == 9
def test_example2():
n = 3
cables = [
(1, 2, 1),
(2, 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 find(parent, i):\n if parent[i] == i:\n return i\n return find(parent, parent[i])\n\ndef union(parent, rank, x, y):\n root_x = find(par... | trial_gpt4o_4 | {
"original_instruction": "Suppose you are given a network of computers where some pairs of computers are directly connected by cables. The problem involves calculating the total data transfer cost within the network. The cost to transfer data between two directly connected computers is given, and data can also be tr... | 0.754075 | Code_Contests_10137 | C | [
"find",
"union",
"minimum_spanning_tree_cost",
"solve"
] | 4 | [
[
"minimum_spanning_tree_cost",
"find"
],
[
"minimum_spanning_tree_cost",
"union"
],
[
"solve",
"minimum_spanning_tree_cost"
],
[
"union",
"find"
]
] | 4 | [] | false | [] | false | pytest | true | [] | true | fdb584fc505291d86b0592034b09f53a2f1cab44 | 11e7de89fba96ae8dd5c0bf461b1a18cb38c02d3 | |||
v1.0 | complete | Code_Contests | Code_Contests_9735_C | from typing import List, Tuple
def manhattan_distance(x1: int, y1: int, x2: int, y2: int) -> int:
"""Calculate the Manhattan Distance between two points (x1, y1) and (x2, y2).
>>> manhattan_distance(0, 0, 1, 2)
3
>>> manhattan_distance(1, 2, 3, 4)
4
"""
def optimal_delivery_route(n: int, locat... | import itertools
def manhattan_distance(x1, y1, x2, y2):
return abs(x1 - x2) + abs(y1 - y2)
def optimal_delivery_route(n, locations):
min_distance = float('inf')
# Generate all permutations of the delivery locations
for perm in itertools.permutations(locations):
current_distance = 0
... | from solution import manhattan_distance, optimal_delivery_route, parse_input
def test_manhattan_distance():
assert manhattan_distance(0, 0, 1, 2) == 3
assert manhattan_distance(1, 2, 3, 4) == 4
assert manhattan_distance(3, 4, -1, -2) == 10
def test_optimal_delivery_route_1():
n, locations = parse_inpu... | [
{
"docstring": null,
"function_declaration": "def manhattan_distance(x1, y1, x2, y2):",
"function_name": "manhattan_distance",
"parameter_list": "(x1, y1, x2, y2)"
},
{
"docstring": null,
"function_declaration": "def optimal_delivery_route(n, locations):",
"function_name": "optimal_d... | [
1,
0
] | 1 | medium | 0.5 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import itertools\n\ndef manhattan_distance(x1, y1, x2, y2):\n return abs(x1 - x2) + abs(y1 - y2)\n\ndef optimal_delivery_route(n, locations):\n min_d... | trial_gpt4o_0 | {
"original_instruction": "Problem Statement\n\nYou have been assigned the task of creating an optimal delivery route system for a delivery company. The goal is to minimize the total delivery time for a given set of orders, where each order must be delivered exactly once. The delivery starts from a central warehouse ... | 0.611396 | Code_Contests_9735 | C | [
"manhattan_distance",
"optimal_delivery_route",
"parse_input"
] | 3 | [
[
"optimal_delivery_route",
"manhattan_distance"
]
] | 1 | [
"parse_input"
] | false | [] | false | pytest | true | [] | true | f548f4e950d18c09565effc57acf8b109d99af00 | 295e23539d4dd0c1c3772433a1634d98bfc0f2f5 | |||
v1.0 | complete | Code_Contests | Code_Contests_10202_C | from typing import List
def max_fertility_score(matrix: List[List[int]]) -> int:
"""
Returns the maximum fertility score of any rectangular section in the given matrix.
>>> max_fertility_score([[1, 2, -1, -4, -20], [-8, -3, 4, 2, 1], [3, 8, 10, 1, 3], [-4, -1, 1, 7, -6]])
29
>>> max_fertility_score... | def max_fertility_score(matrix):
"""
Returns the maximum fertility score of any rectangular section in the given matrix.
"""
def kadane(arr):
# Standard Kadane's algorithm to find the maximum subarray sum in 1D array.
max_sum = curr_sum = arr[0]
for num in arr[1:]:
c... | from solution import max_fertility_score
def test_example_case():
matrix = [
[1, 2, -1, -4, -20],
[-8, -3, 4, 2, 1],
[3, 8, 10, 1, 3],
[-4, -1, 1, 7, -6]
]
assert max_fertility_score(matrix) == 29
def test_all_negative():
matrix = [
[-1, -2, -3],
[-4, -5... | [
{
"docstring": "Returns the maximum fertility score of any rectangular section in the given matrix.",
"function_declaration": "def max_fertility_score(matrix):",
"function_name": "max_fertility_score",
"parameter_list": "(matrix)"
},
{
"docstring": null,
"function_declaration": "def max_... | [
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 maximum_fertility_score(matrix):\n \"\"\"\n Returns the maximum fertility score of any rectangular section within a given matrix.\n :param mat... | trial_gpt4o_2 | {
"original_instruction": "The Problem of the Resilient Farmer\n\nA farmer owns a large rectangular field that he uses for planting crops. He has recently started using a new method to determine the sections of the field that need extra fertilizer. The idea is to calculate the fertility score of the rectangular secti... | 0.609929 | Code_Contests_10202 | C | [
"max_fertility_score",
"max_fertility_score_from_input"
] | 2 | [
[
"max_fertility_score_from_input",
"max_fertility_score"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | a8bca56c22ffeedad681cf28e441b524dc0fb6d1 | 902d3d0115f659f67951d2ce17f2d96183ddb1c1 | |||
v1.0 | complete | Code_Contests | Code_Contests_8972_C | def sort_products(products):
"""Sorts the list of products by price in increasing order.
If two products have the same price, they are sorted lexicographically by name.
Args:
products (List[Tuple[str, float]]): A list of tuples, where each tuple contains the product name and price.
... | def sort_products(products):
"""
Sorts the list of products by price in increasing order.
If two products have the same price, they are sorted lexicographically by name.
Args:
products: List of tuples, where each tuple contains the product name and price.
Returns:
A list of... | def test_sort_products():
assert sort_products([("Milk", 1.50), ("Bread", 2.20), ("Eggs", 1.50), ("Butter", 3.00)]) == [("Eggs", 1.50), ("Milk", 1.50), ("Bread", 2.20), ("Butter", 3.00)]
def test_parse_input():
input_lines = ["4", "Milk 1.50", "Bread 2.20", "Eggs 1.50", "Butter 3.00"]
assert parse_input(in... | [
{
"docstring": "Sorts the list of products by price in increasing order.\nIf two products have the same price, they are sorted lexicographically by name.\n\nArgs:\n products: List of tuples, where each tuple contains the product name and price.\n\nReturns:\n A list of tuples sorted by the mentioned criter... | [
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 sort_products(products):\n \"\"\"\n Sorts the list of products by price in increasing order.\n If two products have the same price, they are s... | trial_gpt4o_0 | {
"original_instruction": "A retail shop wants to optimize its inventory system by organizing its products efficiently. The shopkeeper has a list of products with their names and prices. To make the system better, he wants to sort the products primarily based on their price in increasing order. If two products have t... | 0.590271 | Code_Contests_8972 | C | [
"sort_products",
"parse_input",
"format_output",
"inventory_sort"
] | 4 | [
[
"inventory_sort",
"format_output"
],
[
"inventory_sort",
"parse_input"
],
[
"inventory_sort",
"sort_products"
]
] | 3 | [
"parse_input",
"format_output"
] | false | [] | false | pytest | false | [] | true | e00f636640f5b0110b019624f016d6989aacf5df | 5a7b1c66566b4ebbcd96a5b95151853f803e887e | |||
v1.0 | complete | Code_Contests | Code_Contests_9676_C | from typing import List, Tuple
class TreeNode:
def __init__(self, value):
self.value = value
self.children = []
def process_queries(n: int, q: int, node_values: List[int], edges: List[Tuple[int, int]], queries: List[List[int]]) -> List[int]:
"""Process queries on a tree with `n` nodes.
Ea... | class TreeNode:
def __init__(self, value):
self.value = value
self.children = []
def update_node_value(tree, node_id, new_value):
tree[node_id].value = new_value
def build_tree(n, node_values, edges):
nodes = {i: TreeNode(node_values[i-1]) for i in range(1, n+1)}
for u, v in edges... | import pytest
from solution import process_queries
def test_process_queries():
n, q = 5, 5
node_values = [1, 2, 3, 4, 5]
edges = [(1, 2), (1, 3), (2, 4), (2, 5)]
queries = [
[2, 1, 0],
[1, 2, 10],
[2, 2, 0],
[3, 2, 0],
[3, 3, 0]
]
expected_output = [... | [] | [
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 Tree:\n def __init__(self, n, values):\n self.n = n\n self.values = values\n self.tree = [[] for _ in range(n + 1)]\n ... | trial_gpt4o_1 | {
"original_instruction": "You are given a tree with `n` nodes, rooted at node 1. Each node i has a value `vi`. You are asked to process `q` queries on this tree. Each query can be of three types:\n1. Update the value of a node `u` to `x`.\n2. Find the sum of values in the subtree rooted at a node `u`.\n3. Find the s... | 0.614332 | Code_Contests_9676 | C | [
"update_node_value",
"build_tree",
"subtree_sum",
"subtree_min",
"process_queries"
] | 5 | [
[
"process_queries",
"build_tree"
],
[
"process_queries",
"subtree_min"
],
[
"process_queries",
"subtree_sum"
],
[
"process_queries",
"update_node_value"
]
] | 4 | [
"process_queries"
] | false | [
"TreeNode"
] | true | pytest | true | [] | true | 8abd58a1f28634c27867afc0fb310183f9f1a2ad | 13908904a4f31872489d4df961c7b32104e99625 | |||
v1.0 | complete | Code_Contests | Code_Contests_9026_C | from typing import List, Tuple
def max_subsequence_sum(a: List[int]) -> int:
"""
Returns the maximum sum of any subsequence of the array.
"""
pass
def process_operations(n: int, q: int, array: List[int], operations: List[Tuple[int, int]]) -> List[int]:
"""
Process the operations and returns th... | def max_subsequence_sum(a):
"""
Returns the maximum sum of any subsequence of the array.
"""
return sum(x for x in a if x > 0)
def process_operations(n, q, array, operations):
results = []
results.append(max_subsequence_sum(array))
for l, r in operations:
# Convert to zero-base... | from solution import solve, max_subsequence_sum, process_operations
def test_max_subsequence_sum():
assert max_subsequence_sum([3, 7, 2, 5, 1]) == 18
assert max_subsequence_sum([1, 3, 5, 4]) == 13
assert max_subsequence_sum([-1, -3, -5, -4]) == 0
assert max_subsequence_sum([0, 1, 0, 1]) == 2
def test... | [
{
"docstring": "Returns the maximum sum of any subsequence of the array.",
"function_declaration": "def max_subsequence_sum(a):",
"function_name": "max_subsequence_sum",
"parameter_list": "(a)"
},
{
"docstring": null,
"function_declaration": "def process_operations(n, q, array, operation... | [
0,
0,
0,
0,
0,
0,
0,
0,
1,
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 max_subsequence_sum(t, test_cases):\n results = []\n \n for case in test_cases:\n n, q, a, queries = case\n \n # Compute ... | trial_gpt4o_8 | {
"original_instruction": "You are the organizer of a coding competition, and you've decided to introduce a new challenge that involves sorting and reversing segments of arrays. The objective of the problem is to assess participants' ability to manipulate array segments efficiently.\n\nGiven an array of distinct inte... | 0.672161 | Code_Contests_9026 | C | [
"max_subsequence_sum",
"process_operations",
"solve"
] | 3 | [
[
"process_operations",
"max_subsequence_sum"
],
[
"solve",
"process_operations"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 03be1fbaf82edb40c68ce234d86e450fd3e4b7b1 | 83fc7abcd0a4cfa876c5121f1096004b735ca9f8 | |||
v1.0 | complete | Code_Contests | Code_Contests_8898_C | def max_load_after_distribution(t, test_cases):
"""
A software company has multiple servers. Over time, these servers can experience fluctuating loads due to different tasks assigned to them. The company's goal is to balance the load across the servers as evenly as possible to optimize performance.
Each s... | def max_load_after_distribution(t, test_cases):
results = []
for case in test_cases:
n, k = case['n'], case['k']
capacities = case['capacities']
max_capacity = max(capacities)
additional_tasks = min(k, n * max_capacity - sum(capacities))
results.app... | def test_max_load_after_distribution():
input_data = "2\n3 7\n5 10 3\n4 2\n4 8 6 3\n"
expected_output = [10, 8]
result = process(input_data)
assert result == expected_output
def test_with_no_additional_tasks():
input_data = "1\n3 0\n5 10 3\n"
expected_output = [10]
result = p... | [
{
"docstring": null,
"function_declaration": "def max_load_after_distribution(t, test_cases):",
"function_name": "max_load_after_distribution",
"parameter_list": "(t, test_cases)"
},
{
"docstring": null,
"function_declaration": "def parse_input(input_data):",
"function_name": "parse_... | [
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 balance_load(t, test_cases):\n results = []\n for testcase in test_cases:\n n, k, loads = testcase\n max_initial_load = max(loads)\... | trial_gpt4o_2 | {
"original_instruction": "A software company has multiple servers. Over time, these servers can experience fluctuating loads due to different tasks assigned to them. The company's goal is to balance the load across the servers as evenly as possible to optimize performance.\n\nEach server has a load capacity, which i... | 0.580096 | Code_Contests_8898 | C | [
"max_load_after_distribution",
"parse_input",
"process"
] | 3 | [
[
"process",
"max_load_after_distribution"
],
[
"process",
"parse_input"
]
] | 2 | [
"parse_input"
] | false | [] | false | pytest | false | [] | true | e16b890324322f5cf2537c573d35681b832292c8 | 7573264fcac68cb166a8206ca05a8a1f2987e78b | |||
v1.0 | complete | Code_Contests | Code_Contests_10436_C | def max_sum_of_contiguous_subarray(input_str: str) -> str:
"""
Determine the maximum sum of any contiguous subarray within the sequence after selecting the most optimal rotation.
>>> input_str = "6\n4 -1 2 1 -5 4\n0"
>>> max_sum_of_contiguous_subarray(input_str)
"10"
>>> input_str = "5... | def max_subarray_sum_circular(nums):
"""
Find the maximum sum of a subarray in a circular array.
This uses Kadane’s algorithm for regular subarrays and a modification for circular subarrays.
"""
def kadane(nums):
current_sum = max_sum = nums[0]
for num in nums[1:]:
curren... | from solution import max_sum_of_contiguous_subarray
def test_example_case_1():
input_str = "6\n4 -1 2 1 -5 4\n0"
expected = "10"
assert max_sum_of_contiguous_subarray(input_str) == expected
def test_example_case_2():
input_str = "5\n1 2 3 4 5\n0"
expected = "15"
assert max_sum_of_contiguous_su... | [
{
"docstring": "Find the maximum sum of a subarray in a circular array.\nThis uses Kadane’s algorithm for regular subarrays and a modification for circular subarrays.",
"function_declaration": "def max_subarray_sum_circular(nums):",
"function_name": "max_subarray_sum_circular",
"parameter_list": "(n... | [
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": "def max_subarray_sum(arr):\n # Kadane's algorithm to find maximum subarray sum in O(n)\n max_current = max_global = arr[0]\n for num in arr[1:]:\n... | trial_gpt4o_2 | {
"original_instruction": "There is a sequence of n integers. The sequence can be rotated any number of times. You are to determine the maximum sum of any contiguous subarray within the sequence after you select the most optimal rotation. The rotation can be done in either direction.\n\nConstraints\n\n* All inputs ar... | 0.656514 | Code_Contests_10436 | C | [
"max_subarray_sum_circular",
"find_max_sum_of_contiguous_subarray",
"parse_input",
"max_sum_of_contiguous_subarray"
] | 4 | [
[
"find_max_sum_of_contiguous_subarray",
"max_subarray_sum_circular"
],
[
"max_sum_of_contiguous_subarray",
"find_max_sum_of_contiguous_subarray"
],
[
"max_sum_of_contiguous_subarray",
"parse_input"
]
] | 3 | [
"parse_input"
] | false | [] | false | pytest | true | [] | true | cfd812b634efff780e6ec2bf122b667d26250730 | c777b3dc6740b3cfe457ad571367dc2645ed67b3 | |||
v1.0 | complete | Code_Contests | Code_Contests_10559_C | def max_water_flow(n, m, pipes):
"""Calculates the maximum water flow from reservoir 1 to reservoir n using the Edmonds-Karp algorithm.
>>> max_water_flow(4, 5, [(1, 2, 100), (1, 3, 100), (2, 3, 1), (2, 4, 100), (3, 4, 100)])
200
>>> max_water_flow(2, 1, [(1, 2, 50)])
50
""" | from collections import deque
def bfs(C, F, source, sink, parent):
"""
Perform Breadth-First Search to find an augmenting path.
"""
visited = set()
queue = deque([source])
visited.add(source)
while queue:
u = queue.popleft()
for v in range(len(C)):
if v not in v... | from solution import max_water_flow
def test_example_case():
assert max_water_flow(4, 5, [(1, 2, 100), (1, 3, 100), (2, 3, 1), (2, 4, 100), (3, 4, 100)]) == 200
def test_single_pipe():
assert max_water_flow(2, 1, [(1, 2, 50)]) == 50
def test_disconnected_graph():
assert max_water_flow(3, 2, [(1, 2, 30), ... | [
{
"docstring": "Perform Breadth-First Search to find an augmenting path.",
"function_declaration": "def bfs(C, F, source, sink, parent):",
"function_name": "bfs",
"parameter_list": "(C, F, source, sink, parent)"
},
{
"docstring": "Runs the Edmonds-Karp (Ford-Fulkerson) algorithm to find the ... | [
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 bfs(C, F, source, sink):\n \"\"\"\n Performs a BFS to find an augmenting path in the residual graph.\n \"\"\"... | trial_gpt4o_2 | {
"original_instruction": "In a peaceful village surrounded by mountains, the villagers rely on a water distribution system that comprises a series of reservoirs and pipes. You are given the layout of this water distribution system in the form of a graph, where nodes represent reservoirs, and edges represent pipes co... | 0.669371 | Code_Contests_10559 | C | [
"bfs",
"edmonds_karp",
"max_water_flow"
] | 3 | [
[
"edmonds_karp",
"bfs"
],
[
"max_water_flow",
"edmonds_karp"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | b37ea957cbf798c6bf7c99ac5ae74e33fff1c696 | 050906af7bbb835e4c57349a1127511ea8e936f8 | |||
v1.0 | complete | Code_Contests | Code_Contests_10322_C | def encrypt_message(k: int, plaintext: str) -> str:
""" Encrypts the plaintext using the coding wheel technique.
Parameters:
k (int): The number of positions to rotate the inner ring clockwise.
plaintext (str): The plaintext message to be encrypted.
Returns:
str: The encrypted ciphertext.
... | def encrypt_message(k, plaintext):
"""
Encrypts the plaintext using the coding wheel technique.
Parameters:
k (int): The number of positions to rotate the inner ring clockwise.
plaintext (str): The plaintext message to be encrypted.
Returns:
str: The encrypted ciphertext.
"""
... | from solution import encrypt_message, process_messages
def test_encrypt_message():
assert encrypt_message(3, 'HELLO') == 'KHOOR'
assert encrypt_message(1, 'WORLD') == 'XPSME'
assert encrypt_message(0, 'ZEBRAS') == 'ZEBRAS'
assert encrypt_message(25, 'ABCD') == 'ZABC'
assert encrypt_message(5, 'PYTH... | [
{
"docstring": "Encrypts the plaintext using the coding wheel technique.\n\nParameters:\nk (int): The number of positions to rotate the inner ring clockwise.\nplaintext (str): The plaintext message to be encrypted.\n\nReturns:\nstr: The encrypted ciphertext.",
"function_declaration": "def encrypt_message(k,... | [
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 encrypt_message(k, plaintext):\n \"\"\"\n Encrypts the plaintext by rotating the inner ring by k positions.\n Args:\n k (int): number of po... | trial_gpt4o_2 | {
"original_instruction": "In a small island nation, a highly confidential message is transmitted using a unique encryption technique that involves a coding wheel with Latin alphabets. The coding wheel consists of two concentric rings. The outer ring has all 26 uppercase Latin alphabets arranged in a standard order (... | 0.746229 | Code_Contests_10322 | C | [
"encrypt_message",
"process_messages"
] | 2 | [
[
"process_messages",
"encrypt_message"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | d8f552bb62febfe1a650939f722bb037fe912128 | 5538aa7e30800fb85854ab4882d038e8d0a5b240 | |||
v1.0 | complete | Code_Contests | Code_Contests_10635_C | from typing import List
def sumOfPrimes(arr: List[int]) -> int:
"""
Given an array of integers, returns the sum of all elements that are prime numbers.
Prime number is greater than 1 and has no divisors other than 1 and itself.
>>> sumOfPrimes([10, 15, 3, 7, 11]) 21
>>> sumOfPrimes([2, 3, 5, 1... | from typing import List
def is_prime(n: int) -> bool:
"""
Helper function to check if a number is prime.
"""
if n <= 1:
return False
if n == 2:
return True
if n % 2 == 0:
return False
for i in range(3, int(n**0.5) + 1, 2):
if n % i == 0:
return Fa... | from solution import sumOfPrimes
def test_case_1():
assert sumOfPrimes([10, 15, 3, 7, 11]) == 21
def test_case_2():
assert sumOfPrimes([2, 3, 5, 10, 13]) == 23
def test_case_3():
assert sumOfPrimes([0, 1, 4, 6, 8]) == 0
def test_case_4():
assert sumOfPrimes([2, 3, 5, 11, 17, 23, 29]) == 90
def test... | [
{
"docstring": "Helper function to check if a number is prime.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Returns the sum of all prime numbers in the given list of integers.",
"function_declaration": "def sumOfPri... | [
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 typing import List\nimport math\n\ndef is_prime(num: int) -> bool:\n if num <= 1:\n return False\n if num == 2:\n return True\n ... | trial_gpt4o_2 | {
"original_instruction": "Given an array of integers, implement a function that returns the sum of all elements that are prime numbers.\n\nWrite a function `sumOfPrimes(arr: List[int]) -> int` that takes in a list of integers and returns the sum of all prime numbers in the array.\n\n### Example\n\nInput:\n```python\... | 0.697157 | Code_Contests_10635 | C | [
"is_prime",
"sumOfPrimes"
] | 2 | [
[
"sumOfPrimes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | a4b2573891c33a461b522861aa3705600a5141fd | 0f7e6ba0f99324b4a3fb96a5ff45610019cea613 | |||
v1.0 | complete | Code_Contests | Code_Contests_10416_C | def sieve(n: int) -> List[int]:
""" Returns a list of all prime numbers up to n using the Sieve of Eratosthenes """
is_prime = [True] * (n + 1)
p = 2
while p * p <= n:
if is_prime[p]:
for i in range(p * p, n + 1, p):
is_prime[i] = False
p += 1
return [p fo... | MOD = 1000000007
def sieve(n):
""" Returns a list of all prime numbers up to n using the Sieve of Eratosthenes """
is_prime = [True] * (n + 1)
p = 2
while p * p <= n:
if is_prime[p]:
for i in range(p * p, n + 1, p):
is_prime[i] = False
p += 1
return [p fo... | from solution import count_partitions
def test_count_partitions_5():
assert count_partitions(5) == 2
def test_count_partitions_10():
assert count_partitions(10) == 5
def test_count_partitions_1():
assert count_partitions(1) == 0 # Since there are no prime numbers that sum to 1
def test_count_partitions... | [
{
"docstring": "Returns a list of all prime numbers up to n using the Sieve of Eratosthenes ",
"function_declaration": "def sieve(n):",
"function_name": "sieve",
"parameter_list": "(n)"
},
{
"docstring": null,
"function_declaration": "def count_partitions(n):",
"function_name": "coun... | [
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": "MOD = 1000000007\n\ndef count_prime_partitions(n):\n \"\"\"\n Returns the number of distinct partitions of n into prime numbers, modulo 1000000007.\n... | trial_gpt4o_5 | {
"original_instruction": "The citizens of Numberland are fascinated by prime numbers and their properties. One day, they discovered a new game involving prime numbers which goes as follows:\n\nGiven an integer n, partition the number into a non-empty sequence of positive integers such that:\n1. The sum of these inte... | 0.720073 | Code_Contests_10416 | C | [
"sieve",
"count_partitions"
] | 2 | [
[
"count_partitions",
"sieve"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 06eb2ca3b52875f5aec6abdf88e258976ed33779 | 693b636bd2b6f175fc4cbaf8698cd550ec67772f | |||
v1.0 | complete | Code_Contests | Code_Contests_10344_C | def minimum_cost_to_construct_network(N, M, roads):
"""Determine the minimum cost required to construct a road network
such that every two cities are connected either directly or indirectly
through the selected roads. If it's not possible to connect all the
cities, return -1.
Args:
N (int): ... | def find(parent, u):
if parent[u] != u:
parent[u] = find(parent, parent[u])
return parent[u]
def union(parent, rank, u, v):
root_u = find(parent, u)
root_v = find(parent, v)
if root_u != root_v:
if rank[root_u] > rank[root_v]:
parent[root_v] = root_u
elif ra... | def test_solution():
from solution import minimum_cost_to_construct_network
assert minimum_cost_to_construct_network(4, 5, [
(1, 2, 3),
(2, 3, 4),
(3, 4, 5),
(4, 1, 2),
(1, 3, 7)
]) == 9
assert minimum_cost_to_construct_network(3, 1, [
(1, 2, 1)
... | [
{
"docstring": null,
"function_declaration": "def find(parent, u):",
"function_name": "find",
"parameter_list": "(parent, u)"
},
{
"docstring": null,
"function_declaration": "def union(parent, rank, u, v):",
"function_name": "union",
"parameter_list": "(parent, rank, u, v)"
},
... | [
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": "class UnionFind:\n def __init__(self, n):\n self.parent = list(range(n))\n self.rank = [0] * n\n\n def find(self, u):\n if self.... | trial_gpt4o_2 | {
"original_instruction": "In a kingdom, there are N cities connected by M bidirectional roads. Each road connects two different cities and has an associated travel cost. The king wants to select a subset of these roads to construct a road network such that every two cities are connected either directly or indirectly... | 0.68278 | Code_Contests_10344 | C | [
"find",
"union",
"minimum_cost_to_construct_network"
] | 3 | [
[
"minimum_cost_to_construct_network",
"find"
],
[
"minimum_cost_to_construct_network",
"union"
],
[
"union",
"find"
]
] | 3 | [] | false | [] | false | pytest | true | [] | true | a93f3fab00c2de4c426174ea1c28244c4baef4cc | 5f73eecbe8e061b17146d9e7cbec9e2b410712d0 | |||
v1.0 | complete | Code_Contests | Code_Contests_9813_C | class TreeNode:
def __init__(self, val=0, left=None, right=None):
self.val = val
self.left = left
self.right = right
def build_tree_from_level_order(level_order):
"""Constructs a binary tree from its level order traversal.
Args:
level_order (List[int]): Level order traversal... | class TreeNode:
def __init__(self, val=0, left=None, right=None):
self.val = val
self.left = left
self.right = right
def build_tree_from_level_order(level_order):
if not level_order:
return None
root = TreeNode(level_order[0])
queue = [root]
i = 1
while queue and... | from solution import TreeNode, build_tree_from_level_order, tree_sum, tree_height, tree_max_value, process_queries
def test_build_tree_from_level_order():
level_order = [1, 2, 3]
root = build_tree_from_level_order(level_order)
assert root.val == 1
assert root.left.val == 2
assert root.right.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, value=0, left=None, right=None):\n self.value = value\n self.left = left\n self.right = right\... | trial_gpt4o_1 | {
"original_instruction": "Given a binary tree, we need to perform the following operations:\n\n1. Find the sum of all nodes in the binary tree.\n2. Find the height of the binary tree.\n3. Find the maximum value node in the binary tree.\n\nEach node in the binary tree has an integer value.\n\nYou are given multiple q... | 0.591525 | Code_Contests_9813 | C | [
"build_tree_from_level_order",
"tree_sum",
"tree_height",
"tree_max_value",
"process_queries"
] | 5 | [
[
"process_queries",
"build_tree_from_level_order"
],
[
"process_queries",
"tree_height"
],
[
"process_queries",
"tree_max_value"
],
[
"process_queries",
"tree_sum"
]
] | 4 | [
"process_queries"
] | false | [
"TreeNode"
] | true | pytest | true | [] | true | 2747b1919f344df7e015217ed8f229c51cc785b9 | 386e3554fd3d743d640666ac6214a2d60fd4766f | |||
v1.0 | complete | Code_Contests | Code_Contests_10780_C | def minimum_operations_to_connect_tanks(n: int, m: int, connections: List[Tuple[int, int]]) -> int:
""" Determines the minimum number of operations required to connect all tanks.
>>> minimum_operations_to_connect_tanks(6, 4, [(1, 2), (2, 3), (4, 5), (5, 6)])
2
>>> minimum_operations_to_connect_tanks(1, ... | def find(parent, i):
if parent[i] == i:
return i
else:
parent[i] = find(parent, parent[i])
return parent[i]
def union(parent, rank, x, y):
root_x = find(parent, x)
root_y = find(parent, y)
if root_x != root_y:
if rank[root_x] > rank[root_y]:
parent[r... | from solution import minimum_operations_to_connect_tanks
def test_single_node():
assert minimum_operations_to_connect_tanks(1, 0, []) == 0
def test_all_connected():
assert minimum_operations_to_connect_tanks(3, 3, [(1, 2), (2, 3), (3, 1)]) == 0
def test_two_components():
assert minimum_operations_to_conn... | [
{
"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 parent[i] = find(parent, parent[i])\n return parent[i]\n\ndef uni... | trial_gpt4o_0 | {
"original_instruction": "An engineer is working on an experiment involving a series of connected water tanks. Each tank can be thought of as a node in a graph, and each connection between two tanks as an edge. The complexity of the system is that water can flow in both directions between any two connected tanks.\n\... | 0.542529 | Code_Contests_10780 | C | [
"find",
"union",
"minimum_operations_to_connect_tanks"
] | 3 | [
[
"minimum_operations_to_connect_tanks",
"find"
],
[
"minimum_operations_to_connect_tanks",
"union"
],
[
"union",
"find"
]
] | 3 | [] | false | [] | false | pytest | true | [] | true | 1339e75c643b43bd7e7265d5234da55345474b3d | a6f210583ef905aa7d6c9141c8780a48b6e92995 | |||
v1.0 | complete | Code_Contests | Code_Contests_10399_C | from typing import List, Tuple
def alice_prime_transformation(arr: List[int]) -> Tuple[int, List[int]]:
"""Alice defines a transformation operation on an element of the array by changing it to the nearest prime number.
If two primes are equally close, choose the smaller one.
This function returns the numb... | from typing import List, Tuple
import math
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
de... | def test_alice_prime_transformation_even_numbers():
result = alice_prime_transformation([10, 14, 16, 20])
assert result == (4, [11, 13, 17, 19])
def test_alice_prime_transformation_mixed_numbers():
result = alice_prime_transformation([5, 15, 23, 30])
assert result == (2, [5, 13, 23, 29])
def test_alic... | [
{
"docstring": null,
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": null,
"function_declaration": "def nearest_prime(n):",
"function_name": "nearest_prime",
"parameter_list": "(n)"
},
{
"docstring": null,... | [
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 typing import List, Tuple\nimport math\n\ndef is_prime(n):\n if n <= 1:\n return False\n if n <= 3:\n return True\n if n % 2 ==... | trial_gpt4o_0 | {
"original_instruction": "Alice likes to play with prime numbers. She has a special way of transforming an array of integers. Alice defines a transformation operation on an element of the array by changing it to the nearest prime number. If two primes are equally close, choose the smaller one. Alice gives you an arr... | 0.671926 | Code_Contests_10399 | C | [
"is_prime",
"nearest_prime",
"alice_prime_transformation"
] | 3 | [
[
"alice_prime_transformation",
"nearest_prime"
],
[
"nearest_prime",
"is_prime"
]
] | 2 | [] | false | [] | false | pytest | false | [] | true | 9bf5e554f379e8a3be19a9707a494ec6cc8fc327 | 8a5dbd3eff62e3f2bdfdeef67ab0a41851bf8f78 | |||
v1.0 | complete | Code_Contests | Code_Contests_10440_C | from typing import List
def get_lexicographical_permutations(s: str) -> List[str]:
"""Returns all permutations of the string `s` in lexicographical order.
>>> get_lexicographical_permutations('abc')
['abc', 'acb', 'bac', 'bca', 'cab', 'cba']
>>> get_lexicographical_permutations('a')
['a']
"""
... | from itertools import permutations
def get_lexicographical_permutations(s):
"""
Returns all permutations of the string `s` in lexicographical order.
"""
perms = permutations(s)
unique_perms = sorted(set(''.join(p) for p in perms))
return unique_perms
def print_lexicographical_permutations(s):
... | from solution import get_lexicographical_permutations
import pytest
def test_permutations_single_character():
assert get_lexicographical_permutations('a') == ['a']
def test_permutations_two_characters():
assert get_lexicographical_permutations('ab') == ['ab', 'ba']
def test_permutations_three_characters():
... | [
{
"docstring": "Returns all permutations of the string `s` in lexicographical order.",
"function_declaration": "def get_lexicographical_permutations(s):",
"function_name": "get_lexicographical_permutations",
"parameter_list": "(s)"
},
{
"docstring": "Prints all permutations of the string `s`... | [
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 itertools import permutations\n\ndef lexicographical_permutations(s):\n \"\"\"\n Given a string s, returns all permutations of the string in lex... | trial_gpt4o_2 | {
"original_instruction": "Tom is passionate about programming and loves to solve puzzles with strings. Recently, he came across a problem related to permutations of strings and wants to write a program for it. Given a string consisting of lowercase alphabets, he is interested in finding all the permutations of this ... | 0.6656 | Code_Contests_10440 | C | [
"get_lexicographical_permutations",
"print_lexicographical_permutations"
] | 2 | [
[
"print_lexicographical_permutations",
"get_lexicographical_permutations"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | d3cd53dd6f681c96984f74bfca59fc7160405615 | 307cfcb590f23941290fa21fbb93849273a37f6c | |||
v1.0 | complete | Code_Contests | Code_Contests_10527_C | from typing import List, Tuple
def process_queries(N: int, rainfall: List[int], queries: List[Tuple[int, int]]) -> List[int]:
""" Process multiple queries to find the sum of rainfall over specific subarrays of days.
Args:
N (int): The number of days.
rainfall (List[int]): A list of integers repres... | def preprocess_rainfall_data(rainfall):
"""
Preprocess the rainfall data to compute prefix sums.
"""
N = len(rainfall)
prefix_sums = [0] * (N + 1)
for i in range(1, N + 1):
prefix_sums[i] = prefix_sums[i - 1] + rainfall[i - 1]
return prefix_sums
def query_rainfall_sum(prefix_sums, l... | from solution import process_queries
def test_given_example():
N = 5
rainfall = [3, 0, 4, 2, 5]
queries = [(1, 3), (2, 5), (3, 3)]
expected_output = [7, 11, 4]
assert process_queries(N, rainfall, queries) == expected_output
def test_single_day():
N = 1
rainfall = [10]
queries = [(1, 1)... | [
{
"docstring": "Preprocess the rainfall data to compute prefix sums.",
"function_declaration": "def preprocess_rainfall_data(rainfall):",
"function_name": "preprocess_rainfall_data",
"parameter_list": "(rainfall)"
},
{
"docstring": "Return the sum of rainfall from day l to r (1-based index) ... | [
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_rainfall(rainfall):\n \"\"\"\n Preprocesses the rainfall data to provide quick sum queries.\n \"\"\"\n N = len(rainfall)\n pr... | trial_gpt4o_2 | {
"original_instruction": "You are given an array of `N` integers representing the amount of rainfall recorded over `N` days. There are also `Q` queries, where each query asks for the sum of rainfall recorded over a specific subarray of days. Write a function that processes these queries efficiently.\n\n**Input**\n\n... | 0.645216 | Code_Contests_10527 | C | [
"preprocess_rainfall_data",
"query_rainfall_sum",
"process_queries"
] | 3 | [
[
"process_queries",
"preprocess_rainfall_data"
],
[
"process_queries",
"query_rainfall_sum"
]
] | 2 | [
"process_queries"
] | false | [] | false | pytest | true | [] | true | 3de42742bc6a2363929422c6ab8154124f7aa4ee | 5ef66a5939a72f0482bfe7cbfeb53488e81ece30 | |||
v1.0 | complete | Code_Contests | Code_Contests_10058_C | from typing import List, Tuple
def poker_game_outcome(test_cases: List[Tuple[List[str], List[str]]]) -> List[str]:
""" Determine the outcome of poker games for multiple test cases.
Each test case consists of hands dealt to Alice and Bob, and the function should return a list
of results indicating whether A... | from collections import Counter
def card_value(card):
"""Helper function to get the value of a card"""
value_str = "23456789TJQKA"
return value_str.index(card[0])
def hand_rank(hand):
"""Returns a tuple representing the rank of the hand"""
values = sorted([card_value(card) for card in hand], rever... | import pytest
from solution import poker_game_outcome
def test_poker_game_outcome():
test_cases = [
(["TS", "JS", "QS", "KS", "AS"], ["9H", "9D", "9S", "3C", "3D"]), # Alice wins with Royal Flush
(["2H", "3H", "4H", "5H", "6H"], ["2D", "3D", "4D", "5D", "6D"]), # Tie with Straight Flush of same r... | [
{
"docstring": "Helper function to get the value of a card",
"function_declaration": "def card_value(card):",
"function_name": "card_value",
"parameter_list": "(card)"
},
{
"docstring": "Returns a tuple representing the rank of the hand",
"function_declaration": "def hand_rank(hand):",
... | [
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 collections import Counter\n\ndef hand_rank(hand):\n \"\"\"\n Given a hand of 5 cards, return a tuple representing its rank.\n \"\"\"\n ra... | trial_gpt4o_2 | {
"original_instruction": "**Problem Statement**\n\nAlice and Bob are playing a card game with a standard deck of 52 cards. Each player is dealt a hand of 5 cards. The game consists of a single round, and the winner is determined by who has the higher ranking hand according to the common poker hand rankings: High Car... | 0.721932 | Code_Contests_10058 | C | [
"card_value",
"hand_rank",
"compare_hands",
"poker_game_outcome"
] | 4 | [
[
"compare_hands",
"hand_rank"
],
[
"hand_rank",
"card_value"
],
[
"poker_game_outcome",
"compare_hands"
]
] | 3 | [] | false | [] | false | pytest | true | [] | true | 7375541bd6d24ab49749efd3ed5c44f73f719b17 | a2a6c6c2449189847f197d492068cbcf087459f0 | |||
v1.0 | complete | Code_Contests | Code_Contests_10834_C | from typing import List
def is_prime(n: int) -> bool:
"""
Check if a number is prime.
>>> is_prime(2) True
>>> is_prime(4) False
"""
def prime_sum_pair(numbers: List[int], target_sum: int) -> List[int]:
"""
Find a pair of prime numbers in the list that sum up to the target sum.
>>> pr... | import math
def is_prime(n):
"""
Check if a number is prime.
"""
if n <= 1:
return False
if n == 2:
return True
if n % 2 == 0:
return False
max_divisor = math.isqrt(n)
for d in range(3, max_divisor + 1, 2):
if n % d == 0:
return False
retu... | from solution import is_prime, prime_sum_pair
def test_is_prime():
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(4) == False
assert is_prime(5) == True
assert is_prime(10) == False
def test_prime_sum_pair_with_valid_input():
assert prime_sum_pair([10, 7, 3, 5, 1], 8) ==... | [
{
"docstring": "Check if a number is prime.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Find a pair of prime numbers in the list that sum up to the target sum.",
"function_declaration": "def prime_sum_pair(numbers,... | [
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 is_prime(n):\n \"\"\"Check if a number is prime.\"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return True\n if n % 2 == 0... | trial_gpt4o_1 | {
"original_instruction": "Prime Sum Pair\nWrite a function that takes a list of integers and an integer target sum as input and returns a pair of numbers from the list whose sum is equal to the given target sum. Both numbers in the pair should be prime numbers. If no such pair exists, return an empty list.\n\nInput\... | 0.690121 | Code_Contests_10834 | C | [
"is_prime",
"prime_sum_pair"
] | 2 | [
[
"prime_sum_pair",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 17c7cf0093da41c6f0df596b349beec302cb8660 | cc884dc37ead2dd6594332d5ba8aa25a0d472069 | |||
v1.0 | complete | Code_Contests | Code_Contests_10991_C | def can_be_expressed_as_sum_of_three_primes(M: int) -> str:
""" Determine if M can be expressed as the sum of exactly three distinct prime numbers.
>>> can_be_expressed_as_sum_of_three_primes(28) == "YES"
>>> can_be_expressed_as_sum_of_three_primes(11) == "NO"
>>> can_be_expressed_as_sum_of_three_primes... | def is_prime(n):
if n <= 1:
return False
if n <= 3:
return True
if n % 2 == 0 or n % 3 == 0:
return False
i = 5
while i * i <= n:
if n % i == 0 or n % (i + 2) == 0:
return False
i += 6
return True
def can_be_expressed_as_sum_of_three_primes(M)... | from solution import can_be_expressed_as_sum_of_three_primes
def test_case_1():
assert can_be_expressed_as_sum_of_three_primes(28) == "YES"
def test_case_2():
assert can_be_expressed_as_sum_of_three_primes(11) == "NO"
def test_case_3():
assert can_be_expressed_as_sum_of_three_primes(31) == "YES"
... | [
{
"docstring": null,
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": null,
"function_declaration": "def can_be_expressed_as_sum_of_three_primes(M):",
"function_name": "can_be_expressed_as_sum_of_three_primes",
"pa... | [
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 is_prime(n):\n \"\"\"Helper function to check if a number is a prime.\"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return Tr... | trial_gpt4o_1 | {
"original_instruction": "Given an integer M, write a function to determine if it's possible to express M as the sum of exactly three distinct prime numbers. If it is possible, return \"YES\", otherwise return \"NO\".\n\nConstraints\n\n* 1 \\leq M \\leq 300\n\nInput\n\nInput is given from Standard Input in the follo... | 0.71064 | Code_Contests_10991 | C | [
"is_prime",
"can_be_expressed_as_sum_of_three_primes"
] | 2 | [
[
"can_be_expressed_as_sum_of_three_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | edc1a63a2fa2c0712635f301f85079faeaec7ca5 | 448e06b49ee17b375bc7ffa7ca126ff7e2b69567 | |||
v1.0 | complete | Code_Contests | Code_Contests_10852_C | from functools import reduce
import math
def lcm(a, b):
"""
Returns the least common multiple of a and b.
"""
return abs(a*b) // math.gcd(a, b)
def find_min_total_hours(m: int, hours: List[int]) -> int:
""" Finds the minimum total number of hours all machines can run together without any machine r... | import math
from functools import reduce
def lcm(a, b):
"""
Returns the least common multiple of a and b.
"""
return abs(a*b) // math.gcd(a, b)
def find_min_total_hours(m, hours):
"""
Finds the minimum total number of hours all machines can run together without any machine requiring maintenanc... | from solution import find_min_total_hours
def test_find_min_total_hours_case_1():
assert find_min_total_hours(3, [6, 8, 12]) == 24
def test_find_min_total_hours_case_2():
assert find_min_total_hours(5, [3, 4, 5, 6, 7]) == 420
def test_find_min_total_hours_case_3():
assert find_min_total_hours(4, [10, 15,... | [
{
"docstring": "Returns the least common multiple of a and b.",
"function_declaration": "def lcm(a, b):",
"function_name": "lcm",
"parameter_list": "(a, b)"
},
{
"docstring": "Finds the minimum total number of hours all machines can run together without any machine requiring maintenance.",
... | [
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\nfrom functools import reduce\n\ndef lcm(a, b):\n \"\"\"\n Helper function to return the LCM of two numbers.\n \"\"\"\n return abs(... | trial_gpt4o_1 | {
"original_instruction": "There are M different machines in a factory. Each machine can run for a certain number of hours before it needs maintenance. Given a list of integers where each integer represents the hours a corresponding machine can run before needing maintenance, find the minimum total number of hours al... | 0.562351 | Code_Contests_10852 | C | [
"lcm",
"find_min_total_hours",
"main"
] | 3 | [
[
"find_min_total_hours",
"lcm"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 1abc1f572773df091cca27cea84f19d80428ae2f | 0688255b156d99056eea3cc19ef5a59adfa1fbbe | |||
v1.0 | complete | Code_Contests | Code_Contests_10553_C | def get_active_periods(logs: List[List[int]]) -> List[List[int]]:
""" Determine the periods during which at least one user was active, merging overlapping periods.
>>> get_active_periods([[1, 5], [2, 6], [8, 10]])
[[1, 6], [8, 10]]
>>> get_active_periods([[1, 2], [3, 4], [5, 6]])
[[1, 2], [3, 4], [5... | def merge_intervals(intervals):
"""
Merges overlapping intervals and returns a list of condensed intervals.
"""
if not intervals:
return []
# Sort intervals based on the start time
intervals.sort(key=lambda x: x[0])
merged = []
for interval in intervals:
# If the list of... | from solution import get_active_periods
def test_non_overlapping_intervals():
logs = [[1, 2], [3, 4], [5, 6]]
assert get_active_periods(logs) == [[1, 2], [3, 4], [5, 6]]
def test_fully_overlapping_intervals():
logs = [[1, 4], [2, 3], [3, 5]]
assert get_active_periods(logs) == [[1, 5]]
def test_partia... | [
{
"docstring": "Merges overlapping intervals and returns a list of condensed intervals.",
"function_declaration": "def merge_intervals(intervals):",
"function_name": "merge_intervals",
"parameter_list": "(intervals)"
},
{
"docstring": null,
"function_declaration": "def get_active_periods... | [
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 merge_activity_periods(logs):\n \"\"\"\n Merges overlapping user activity periods.\n\n :param logs: List of tuples representing start and end ... | trial_gpt4o_1 | {
"original_instruction": "A company's internal service generates logs for user activities that consist of start and end times of user sessions. You need to determine and print the periods during which at least one user was active.\n\nInput:\n\nThe first line of the input contains an integer, n, which denotes the num... | 0.595683 | Code_Contests_10553 | C | [
"merge_intervals",
"get_active_periods"
] | 2 | [
[
"get_active_periods",
"merge_intervals"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 73cf5d57697afdb1dff0dd60793e6beb6300f1bf | 9b031b7f9596e2e94faa8a270cc5251ebf891551 | |||
v1.0 | complete | Code_Contests | Code_Contests_9521_C | def find_largest_rectangle(t: int, test_cases: List[Tuple[Tuple[int, int], List[List[int]]]]) -> List[int]:
"""
Identify the largest rectangular block of '1's in a binary matrix for each test case.
Arguments:
t -- The number of test cases.
test_cases -- A list of tuples, where each tuple conta... | def max_histogram_area(heights):
stack = []
max_area = 0
index = 0
while index < len(heights):
if not stack or heights[stack[-1]] <= heights[index]:
stack.append(index)
index += 1
else:
top_of_stack = stack.pop()
area = (heights[top_of_sta... | from solution import find_largest_rectangle
def test_sample_input():
input_data = """2
4 4
0 1 1 0
1 1 1 1
1 1 1 0
1 1 0 0
3 3
1 0 1
1 1 1
... | [
{
"docstring": null,
"function_declaration": "def max_histogram_area(heights):",
"function_name": "max_histogram_area",
"parameter_list": "(heights)"
},
{
"docstring": null,
"function_declaration": "def max_rectangle_area(matrix):",
"function_name": "max_rectangle_area",
"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": "def max_histogram_area(heights):\n stack = []\n max_area = 0\n index = 0\n\n while index < len(heights):\n if not stack or heights[stack... | trial_gpt4o_0 | {
"original_instruction": "Design a program that identifies the largest rectangular block of '1's in a binary matrix. Each cell in the matrix contains either '0' or '1'. The largest rectangular block is defined by the maximal area rectangle containing only '1's.\n\nInput:\nThe first line contains an integer T, the nu... | 0.662876 | Code_Contests_9521 | C | [
"max_histogram_area",
"max_rectangle_area",
"find_largest_rectangle",
"parse_input"
] | 4 | [
[
"find_largest_rectangle",
"max_rectangle_area"
],
[
"max_rectangle_area",
"max_histogram_area"
]
] | 2 | [
"parse_input"
] | false | [] | false | pytest | true | [] | true | fdf0bec44bbd1e949862db15165c4df8075d1080 | 2ed20e139113e63aabfe360f35cae588257837c3 | |||
v1.0 | complete | Code_Contests | Code_Contests_10336_C | from math import sqrt
from collections import defaultdict
from typing import List, Tuple
def distance(p1: Tuple[int, int, int], p2: Tuple[int, int, int]) -> float:
""" Calculate the distance between two points in 3D space.
>>> distance((0, 0, 0), (3, 4, 0)) == 5
>>> distance((0, 0, 0), (1, 1, 1)) == sqrt(3... | from math import sqrt
from collections import defaultdict
def parse_explorer_info():
nickname = input().strip()
times = []
velocities = []
t0, x0, y0, z0 = map(int, input().strip().split())
times.append(t0)
positions = [(x0, y0, z0)]
while True:
line = input().strip()
i... | from solution import distance, simulate_explorer_path
def test_distance():
assert distance((0, 0, 0), (3, 4, 0)) == 5
assert distance((0, 0, 0), (1, 1, 1)) == sqrt(3)
assert distance((0, 0, 0), (0, 0, 0)) == 0
def test_simulate_explorer_path():
times = [0, 10]
velocities = [(1, 1, 1)]
position... | [
{
"docstring": null,
"function_declaration": "def parse_explorer_info():",
"function_name": "parse_explorer_info",
"parameter_list": "()"
},
{
"docstring": null,
"function_declaration": "def parse_artifact_info():",
"function_name": "parse_artifact_info",
"parameter_list": "()"
... | [
0,
0,
0,
1,
0
] | 1 | hard | 0.2 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def simulate_explorer_movements(N, M, D, explorers, artifacts):\n import math\n \n def distance(p1, p2):\n return math.sqrt((p1[0] - p2[0])... | trial_gpt4o_3 | {
"original_instruction": "A group of explorers are traveling on different paths in a 3D space, and their mission is to collect a set of unique artifacts that are scattered across this space. Each artifact has its own unique location denoted by coordinates (x, y, z).\n\nAn explorer travels along piecewise linear path... | 0.497391 | Code_Contests_10336 | C | [
"parse_explorer_info",
"parse_artifact_info",
"distance",
"simulate_explorer_path",
"solve"
] | 5 | [
[
"solve",
"distance"
],
[
"solve",
"parse_artifact_info"
],
[
"solve",
"parse_explorer_info"
],
[
"solve",
"simulate_explorer_path"
]
] | 4 | [] | false | [] | false | pytest | true | [] | true | 4fbfec1488d232d60c9abfd9ff31bbacda65fcf0 | 1c115a851c539a1512d9b1b8ae758f9cb3b38e33 | |||
v1.0 | complete | Code_Contests | Code_Contests_10450_C | from typing import List
def rotate_right(grid: List[List[int]]) -> List[List[int]]:
""" Rotate the grid 90 degrees to the right.
>>> rotate_right([[1, 2, 3], [4, 5, 6], [7, 8, 9]])
[[7, 4, 1], [8, 5, 2], [9, 6, 3]]
"""
def rotate_left(grid: List[List[int]]) -> List[List[int]]:
""" Rotate the g... | def rotate_right(grid):
return [list(row) for row in zip(*grid[::-1])]
def rotate_left(grid):
return [list(row) for row in zip(*grid)][::-1]
def reflect(grid):
return [list(row) for row in zip(*grid)]
def apply_operations(grid, operations):
for op in operations:
if op == 'R':
grid... | from solution import reshape_grid, rotate_right, rotate_left, reflect
def test_rotate_right():
grid = [
[1, 2, 3],
[4, 5, 6],
[7, 8, 9]
]
expected = [
[7, 4, 1],
[8, 5, 2],
[9, 6, 3]
]
assert rotate_right(grid) == expected
def test_rotate_left():
... | [
{
"docstring": null,
"function_declaration": "def rotate_right(grid):",
"function_name": "rotate_right",
"parameter_list": "(grid)"
},
{
"docstring": null,
"function_declaration": "def rotate_left(grid):",
"function_name": "rotate_left",
"parameter_list": "(grid)"
},
{
"d... | [
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 rotate_right(grid):\n return [list(row) for row in zip(*grid[::-1])]\n\ndef rotate_left(grid):\n return [list(row)[::-1] for row in zip(*grid)]\n... | trial_gpt4o_2 | {
"original_instruction": "Professor McGonagall has recently developed a new spell that can manipulate and reshape magical energy grids. Each grid is a two-dimensional array of energy cells, with each cell containing an integer that represents the energy level at that point. McGonagall needs your help to harness this... | 0.579313 | Code_Contests_10450 | C | [
"rotate_right",
"rotate_left",
"reflect",
"apply_operations",
"reshape_grid"
] | 5 | [
[
"apply_operations",
"reflect"
],
[
"apply_operations",
"rotate_left"
],
[
"apply_operations",
"rotate_right"
],
[
"reshape_grid",
"apply_operations"
]
] | 4 | [] | false | [] | false | pytest | true | [] | true | 31fedb7de758f90f6083331b0cf0284990ebf460 | 2a071a17f7f5e34263e64729e2396e3b0da277db | |||
v1.0 | complete | Code_Contests | Code_Contests_11100_C | def find_number_of_paths(n: int, grid_lines: List[str]) -> int:
"""
Given an n x n grid where certain cells are blocked (i.e., they cannot be passed through),
determine the number of distinct paths one can take to travel from the top-left corner (0, 0)
to the bottom-right corner (n-1, n-1). You can on... | def count_paths(grid):
"""
This function returns the number of distinct paths from the top-left corner
to the bottom-right corner of the grid.
"""
n = len(grid)
if grid[0][0] == '#' or grid[n-1][n-1] == '#':
return 0
# Initialize the dp array
dp = [[0] * n for _ in range(n)... | from solution import find_number_of_paths
def test_simple_grid():
assert find_number_of_paths(3, [
". . .",
". # .",
". . ."
]) == 2
def test_no_path_grid():
assert find_number_of_paths(3, [
". # .",
"# . .",
". . ."
]) == 0
def test_grid_with_multiple_... | [
{
"docstring": "This function returns the number of distinct paths from the top-left corner \nto the bottom-right corner of the grid.",
"function_declaration": "def count_paths(grid):",
"function_name": "count_paths",
"parameter_list": "(grid)"
},
{
"docstring": null,
"function_declarati... | [
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 count_distinct_paths(n, grid):\n if grid[0][0] == '#' or grid[n-1][n-1] == '#':\n return 0\n\n dp = [[0] * n for _ in range(n)]\n dp[0]... | trial_gpt4o_2 | {
"original_instruction": "Given an n x n grid where certain cells are blocked (i.e., they cannot be passed through), your task is to determine the number of distinct paths one can take to travel from the top-left corner (0, 0) to the bottom-right corner (n-1, n-1). You can only move either down or to the right at an... | 0.771087 | Code_Contests_11100 | C | [
"count_paths",
"find_number_of_paths"
] | 2 | [
[
"find_number_of_paths",
"count_paths"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 6ebac591869eee7a879970c0c78f26c723744c63 | b00d5a045a75eb8c9f865d7aea78adcbff03475e | |||
v1.0 | complete | Code_Contests | Code_Contests_10117_C | from typing import List, Tuple
def process_matrix_queries(n: int, m: int, matrix: List[List[int]], q: int, queries: List[Tuple[int, int]]) -> List[int]:
"""
Given a matrix M of size N x M with integer entries, this function processes Q queries.
Each query consists of two integers r1 and r2 (0 ≤ r1, r2 < N)... | def preprocess_sums(matrix, n, m):
"""
Preprocess the matrix to calculate the prefix sums of each column.
This allows for quick calculations of sums between any two rows.
"""
prefix_sums = [[0] * m for _ in range(n)]
for j in range(m):
for i in range(n):
if i == 0:
... | from solution import process_matrix_queries
def test_example_case():
n = 3
m = 3
matrix = [
[1, 2, 3],
[4, 5, 6],
[7, 8, 9]
]
q = 2
queries = [(0, 1), (1, 2)]
expected_output = [21, 39]
assert process_matrix_queries(n, m, matrix, q, queries) == expected_output
d... | [
{
"docstring": "Preprocess the matrix to calculate the prefix sums of each column.\nThis allows for quick calculations of sums between any two rows.",
"function_declaration": "def preprocess_sums(matrix, n, m):",
"function_name": "preprocess_sums",
"parameter_list": "(matrix, n, m)"
},
{
"do... | [
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 preprocess_sums(matrix, n, m):\n \"\"\"\n Preprocess the matrix to calculate the prefix sums of each column.\n This allows for quick calculati... | trial_gpt4o_0 | {
"original_instruction": "Given a matrix M of size N x M with integer entries, write a program to process Q queries. Each query consists of two integers r1 and r2 (0 ≤ r1, r2 < N). The query should return the sum of all the elements in the submatrix bounded by rows r1 and r2 (inclusive) and all columns.\n\nConstrain... | 0.63657 | Code_Contests_10117 | C | [
"preprocess_sums",
"query_sums",
"process_matrix_queries",
"main"
] | 4 | [
[
"process_matrix_queries",
"preprocess_sums"
],
[
"process_matrix_queries",
"query_sums"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 9f0519fa95bf0eea1edc93f744f955c73443b091 | 51caa287f81426ae7f195a9288db7fce99338c75 | |||
v1.0 | complete | Code_Contests | Code_Contests_10155_C | def max_communication_times(n, edges):
"""
Find the maximum communication time from any tree to the king tree for all the trees in the Kingdom of Trees.
Args:
n (int): The number of trees in the kingdom.
edges (List[Tuple[int, int, int]]): Each tuple consists of three integers (ui, vi, ti)
... | def dfs(node, parent, adj, comm_time, max_comm_times):
for neighbor, time in adj[node]:
if neighbor != parent:
max_comm_times[neighbor] = max_comm_times[node] + time
dfs(neighbor, node, adj, comm_time, max_comm_times)
def max_communication_times(n, edges):
# Create adjacency lis... | from solution import max_communication_times
def test_example_1():
assert max_communication_times(4, [(1, 2, 2), (1, 3, 4), (3, 4, 1)]) == [0, 2, 4, 5]
def test_example_2():
assert max_communication_times(5, [(1, 2, 3), (1, 3, 2), (2, 4, 4), (3, 5, 6)]) == [0, 3, 2, 7, 8]
def test_single_connected_chain():
... | [
{
"docstring": null,
"function_declaration": "def dfs(node, parent, adj, comm_time, max_comm_times):",
"function_name": "dfs",
"parameter_list": "(node, parent, adj, comm_time, max_comm_times)"
},
{
"docstring": null,
"function_declaration": "def max_communication_times(n, edges):",
... | [
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 collections import defaultdict, deque\n\ndef compute_max_communication_times(n, edges):\n # Create a graph to represent the tree\n graph = defau... | trial_gpt4o_2 | {
"original_instruction": "The Kingdom of Trees is a magical land where trees communicate with each other through their branches. The kingdom is organized in a hierarchy starting from the king tree (root) down to the common trees (leaf nodes). Each tree is connected to its parent tree by a branch, and each branch has... | 0.551333 | Code_Contests_10155 | C | [
"dfs",
"max_communication_times"
] | 2 | [
[
"max_communication_times",
"dfs"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 8afe031a4cf133ea4742cecdbef9bea91f82d6d0 | e3a18a7b6a9b8c49509713913da6a1236cc2a7a9 | |||
v1.0 | complete | Code_Contests | Code_Contests_10726_C | def count_distinct_circuits(N: int, M: int, road_pairs: List[Tuple[int, int]]) -> int:
""" Determine the number of distinct circuits in a directed graph.
N : int : number of cities (vertices)
M : int : number of roads (edges)
road_pairs : List[Tuple[int, int]] : each tuple (u, v) representing a road fro... | def find_all_circuits(N, M, edges):
"""
N: int, number of cities (vertices)
M: int, number of roads (edges)
edges: list of tuples, each tuple (u, v) representing a road from city u to city v
"""
from collections import defaultdict, deque
# Create the graph adjacency list
graph = def... | from solution import count_distinct_circuits
def test_example_1():
N = 4
M = 5
road_pairs = [(1, 2), (2, 3), (3, 1), (3, 4), (4, 3)]
assert count_distinct_circuits(N, M, road_pairs) == 2
def test_example_2():
N = 5
M = 7
road_pairs = [(1, 2), (2, 3), (3, 1), (1, 4), (4, 5), (5, 4), (4, 2)]... | [
{
"docstring": "N: int, number of cities (vertices)\nM: int, number of roads (edges)\nedges: list of tuples, each tuple (u, v) representing a road from city u to city v",
"function_declaration": "def find_all_circuits(N, M, edges):",
"function_name": "find_all_circuits",
"parameter_list": "(N, M, ed... | [
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": "from collections import defaultdict\n\ndef count_circuits(N, M, edges):\n def dfs(v, start):\n nonlocal visited, recStack\n visited[v] = T... | trial_gpt4o_5 | {
"original_instruction": "In a certain country, the transportation system between cities is represented by a directed graph with N cities and M one-way roads. Each city is represented by a vertex, and each road is represented by a directed edge consisting of two integers u and v, signifying a road from city u to cit... | 0.625915 | Code_Contests_10726 | C | [
"find_all_circuits",
"count_distinct_circuits"
] | 2 | [
[
"count_distinct_circuits",
"find_all_circuits"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | c4764fd22cb7704047c94edcdbf0490f9611222b | a5f2b56a1814d64900a0d06346c8611bb119184d | |||
v1.0 | complete | Code_Contests | Code_Contests_10577_C | def calculate_min_distance(n: int, dist: List[List[int]]) -> int:
"""
This function calculates the shortest route to visit all landmarks starting and ending at the city center,
which is always landmark 0.
Args:
n (int): The number of landmarks in the town including the city center.
dist (L... | from itertools import permutations
def shortest_route(n, dist):
"""
This function calculates the shortest route to visit all landmarks starting
and ending at landmark 0 using the Travelling Salesman Problem (TSP) approach.
"""
landmarks = list(range(1, n)) # landmarks excluding the starting point... | from solution import calculate_min_distance
def test_example_case():
dist = [
[0, 10, 15, 20],
[10, 0, 35, 25],
[15, 35, 0, 30],
[20, 25, 30, 0]
]
assert calculate_min_distance(4, dist) == 80
def test_two_landmarks():
dist = [
[0, 5],
[5, 0]
]
as... | [
{
"docstring": "This function calculates the shortest route to visit all landmarks starting \nand ending at landmark 0 using the Travelling Salesman Problem (TSP) approach.",
"function_declaration": "def shortest_route(n, dist):",
"function_name": "shortest_route",
"parameter_list": "(n, dist)"
},... | [
0,
0,
0,
0,
1
] | 1 | hard | 0.2 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from itertools import permutations\n\ndef find_min_distance(n, dist):\n \"\"\"\n Returns the minimum distance the shuttle must travel to visit all la... | trial_gpt4o_4 | {
"original_instruction": "In a quiet town, there is a one-way circular track that connects several important landmarks. The town has decided to deploy a new shuttle service that will start from one of these landmarks and service all other landmarks in a single loop. \n\nThe distance between landmarks is provided in ... | 0.691649 | Code_Contests_10577 | C | [
"shortest_route",
"calculate_min_distance"
] | 2 | [
[
"calculate_min_distance",
"shortest_route"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | dbe4bb31476a987a393906c2009e501113d32320 | a79d300edc75bfa0c196bf27af1d2814bdd22118 | |||
v1.0 | complete | Code_Contests | Code_Contests_11123_C | def transform(input_string: str) -> str:
""" Given a list of words, determine if you can transform one word to another by changing exactly one letter at a time, with each intermediate word also being in the list. Each test case will include multiple pairs of words, and you need to check the transformability for eac... | def can_transform(word, target, word_set):
if word == target:
return True
visited = set()
queue = [(word, 0)]
while queue:
current_word, steps = queue.pop(0)
if current_word == target:
return True
for i in range(len(current_word)):
for char in 'abc... | def test_transform():
input_data = """1
6
hit
hot
dot
dog
cog
lot
3
hit cog
hit lot
dot dig"""
expected_output = "YES\nYES\nNO"
assert transform(input_data) == expected_output
def test_transform_single_word():
input_data = """1
1
hit
1
hit hot"""
expected_output = "NO"
assert transform(input_da... | [
{
"docstring": null,
"function_declaration": "def can_transform(word, target, word_set):",
"function_name": "can_transform",
"parameter_list": "(word, target, word_set)"
},
{
"docstring": null,
"function_declaration": "def check_transformability(test_cases):",
"function_name": "check... | [
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 can_transform(words, start, end):\n if start == end:\n return \"YES\"\n \n word_set = set(words)\n ... | trial_gpt4o_1 | {
"original_instruction": "Given a list of words, determine if you can transform one word to another by changing exactly one letter at a time, with each intermediate word also being in the list. Each test case will include multiple pairs of words, and you need to check the transformability for each pair.\n\nInput:\nT... | 0.646897 | Code_Contests_11123 | C | [
"can_transform",
"check_transformability",
"parse_input",
"transform"
] | 4 | [
[
"check_transformability",
"can_transform"
],
[
"transform",
"check_transformability"
],
[
"transform",
"parse_input"
]
] | 3 | [
"parse_input"
] | false | [] | false | pytest | false | [] | true | e8122b2d9ec4733f0d84e559886bd8a71307b155 | 517b62bd5bef9c4877b6e3e876453622098b0cfd | |||
v1.0 | complete | Code_Contests | Code_Contests_10161_C | def is_palindrome(s: str) -> bool:
""" Check if a given string is a palindrome.
>>> is_palindrome("")
True
>>> is_palindrome("A")
True
>>> is_palindrome("AB")
False
>>> is_palindrome("ABA")
True
>>> is_palindrome("ABCBA")
True
>>> is_palindrome("ABCA")
False
"""
... | def is_palindrome(s):
return s == s[::-1]
def can_form_palindrome_from_grid(grid, n, m):
path_1 = []
path_2 = []
# Traverse in top-right and bottom-left manner
for i in range(n+m-1):
if i < n:
path_1.append(grid[i][0])
else:
path_1.append(grid[n-1][i-n+1... | def test_is_palindrome():
from solution import is_palindrome
assert is_palindrome("") == True
assert is_palindrome("A") == True
assert is_palindrome("AB") == False
assert is_palindrome("ABA") == True
assert is_palindrome("ABCBA") == True
assert is_palindrome("ABCA") == False
def test_can_fo... | [
{
"docstring": null,
"function_declaration": "def is_palindrome(s):",
"function_name": "is_palindrome",
"parameter_list": "(s)"
},
{
"docstring": null,
"function_declaration": "def can_form_palindrome_from_grid(grid, n, m):",
"function_name": "can_form_palindrome_from_grid",
"par... | [
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 can_form_palindrome(grid):\n \"\"\"\n Determines if it's possible to traverse the grid from (1, 1) to (n, m) forming a palindrome.\n \"\"\"\n ... | trial_gpt4o_1 | {
"original_instruction": "You are given a grid of size n × m filled with uppercase English letters. Your task is to determine if you can traverse the grid starting from the cell (1, 1) to the cell (n, m), moving only right or down, such that the sequence of letters collected in the path form a palindrome.\n\nInput\n... | 0.790683 | Code_Contests_10161 | C | [
"is_palindrome",
"can_form_palindrome_from_grid",
"check_palindromic_paths",
"process_input",
"palindrome_path"
] | 5 | [
[
"can_form_palindrome_from_grid",
"is_palindrome"
],
[
"check_palindromic_paths",
"can_form_palindrome_from_grid"
],
[
"palindrome_path",
"check_palindromic_paths"
],
[
"palindrome_path",
"process_input"
]
] | 4 | [
"process_input"
] | false | [] | false | pytest | true | [] | true | 0466b076fedd24310ed6d6ede663d8deaf191f1b | 974657b30f2e276e02f0ed3475b02d266a020ab3 | |||
v1.0 | complete | Code_Contests | Code_Contests_10878_C | def group_anagrams_from_input(n: int, words: List[str]) -> List[str]:
""" Groups a list of n words into sets of anagrams and returns a list of these sets sorted in the specified format.
>>> group_anagrams_from_input(6, ["eat", "tea", "tan", "ate", "nat", "bat"])
['ate eat tea', 'bat', 'nat tan']
>>> gro... | def group_anagrams(words):
"""
Groups a list of words into sets of anagrams and returns a list of these sets sorted in the specified format.
"""
from collections import defaultdict
# Dictionary to hold sorted characters as keys and list of anagrams as values
anagrams = defaultdict(list)
... | from solution import group_anagrams_from_input
def test_group_anagrams_sample_input():
n = 6
words = ["eat", "tea", "tan", "ate", "nat", "bat"]
result = group_anagrams_from_input(n, words)
assert result == ["ate eat tea", "bat", "nat tan"]
def test_group_anagrams_empty():
n = 0
words = []
... | [
{
"docstring": "Groups a list of words into sets of anagrams and returns a list of these sets sorted in the specified format.",
"function_declaration": "def group_anagrams(words):",
"function_name": "group_anagrams",
"parameter_list": "(words)"
},
{
"docstring": null,
"function_declarati... | [
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 group_anagrams(strings):\n \"\"\"\n Groups the given list of strings into sets of anagrams and returns the result as a list of strings.\n Each... | trial_gpt4o_2 | {
"original_instruction": "Given a list of strings, write a program to group them into sets of anagrams. Two strings are anagrams if one string can be rearranged to form the other string. Your task is to group the provided strings into sets of anagrams and print out each set.\n\nInput:\n- The first line contains the ... | 0.621159 | Code_Contests_10878 | C | [
"group_anagrams",
"group_anagrams_from_input"
] | 2 | [
[
"group_anagrams_from_input",
"group_anagrams"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 007bc70dc719eb25d83316ec0f4ff674c84affaf | a6e524646ee50aad11a0bddeffa8efbda072443b | |||
v1.0 | complete | Code_Contests | Code_Contests_11197_C | from typing import List, Tuple
def determine_route(n: int, m: int, bridges: List[Tuple[int, int]]) -> str:
""" Determine if there is a route that allows visiting all islands without using any bridge more than once and return to the starting island.
>>> determine_route(4, 4, [(1, 2), (2, 3), (3, 4), (4, 1)])
... | def is_eulerian_cycle_possible(n, m, bridges):
from collections import defaultdict, deque
# Function to check if graph is connected
def is_connected():
visited = [False] * (n + 1)
queue = deque([1])
visited[1] = True
count = 1
while queue:
no... | def test_determine_route_yes_4_4():
n = 4
m = 4
bridges = [(1, 2), (2, 3), (3, 4), (4, 1)]
assert determine_route(n, m, bridges) == "YES"
def test_determine_route_yes_3_3():
n = 3
m = 3
bridges = [(1, 2), (2, 3), (3, 1)]
assert determine_route(n, m, bridges) == "YES"
def test_determine... | [
{
"docstring": null,
"function_declaration": "def is_eulerian_cycle_possible(n, m, bridges):",
"function_name": "is_eulerian_cycle_possible",
"parameter_list": "(n, m, bridges)"
},
{
"docstring": null,
"function_declaration": "def determine_route(n, m, bridges):",
"function_name": "d... | [
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 can_complete_tour(n, m, bridges):\n from collections import defaultdict, deque\n \n graph = defaultdict(list)\n degree = [0] * (n + 1)\n ... | trial_gpt4o_1 | {
"original_instruction": "Polyland has a river with n islands. The islands are numbered from 1 to n. There are m bridges connecting these islands. Each bridge connects exactly two different islands and can be traversed in both directions.\n\nDi takes a sightseeing tour and starts from the first island. His goal is t... | 0.629907 | Code_Contests_11197 | C | [
"is_eulerian_cycle_possible",
"determine_route"
] | 2 | [
[
"determine_route",
"is_eulerian_cycle_possible"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | 39a218da90e2d14394839c7b98344ce54ebe5f08 | 3a9920a0e93566908542cdc11a8a9d33417652f2 | |||
v1.0 | complete | Code_Contests | Code_Contests_10594_C | class TreeNode:
def __init__(self, value):
self.value = value
self.left = None
self.right = None
def build_tree(node_descriptions):
if not node_descriptions:
return None
nodes = {}
for value, left, right in node_descriptions:
if value not in nodes:
n... | class TreeNode:
def __init__(self, value):
self.value = value
self.left = None
self.right = None
def build_tree(node_descriptions):
if not node_descriptions:
return None
nodes = {}
for value, left, right in node_descriptions:
if value not in nodes:
n... | from solution import process_tree_input
def test_empty_tree():
assert process_tree_input(0, []) == 0
def test_single_node():
assert process_tree_input(1, ["1 -1 -1"]) == 1
def test_two_levels():
assert process_tree_input(3, ["1 2 3", "2 -1 -1", "3 -1 -1"]) == 2
def test_three_levels():
assert proces... | [] | [
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, value=0, left=None, right=None):\n self.value = value\n self.left = left\n self.right = right\... | trial_gpt4o_1 | {
"original_instruction": "You are given a binary tree, where each node contains an integer value. Implement a program that identifies the maximum depth (i.e., the longest path from the root node to a leaf) of the binary tree. A leaf is a node with no children.\n\nInput\n\nThe input consists of a binary tree, defined... | 0.580775 | Code_Contests_10594 | C | [
"build_tree",
"max_depth",
"process_tree_input"
] | 3 | [
[
"process_tree_input",
"build_tree"
],
[
"process_tree_input",
"max_depth"
]
] | 2 | [] | false | [
"TreeNode"
] | true | pytest | true | [] | true | c96827bba4e92401b3b1e79f9b310a4bfbfd8fc0 | df7fe5809ea43be74d480d8090cad64817dcc585 | |||
v1.0 | complete | Code_Contests | Code_Contests_11257_C | from typing import List, Tuple
def reorder_array(test_cases: List[List[int]]) -> List[List[int]]:
""" Reorder the array such that the absolute difference between any two consecutive elements is minimized.
>>> reorder_array([[4, 2, 1, 3], [10, 5, 8]])
[[1, 2, 3, 4], [5, 8, 10]]
>>> reorder_array([[3, 1,... | def reorder_array(test_cases):
results = []
for nums in test_cases:
nums_sorted = sorted(nums)
results.append(nums_sorted)
return results
# Wrapper function to handle input and output format
def handle_reorder_array(t, test_cases_data):
test_cases = []
for i in range(t):
n, ... | def test_reorder_array():
assert handle_reorder_array(2, [(4, [4, 2, 1, 3]), (3, [10, 5, 8])]) == [[1, 2, 3, 4], [5, 8, 10]]
def test_reorder_array_single_case():
assert handle_reorder_array(1, [(5, [3, 1, 4, 1, 5])]) == [[1, 1, 3, 4, 5]]
def test_reorder_array_all_same_elements():
assert handle_reorder_a... | [
{
"docstring": null,
"function_declaration": "def reorder_array(test_cases):",
"function_name": "reorder_array",
"parameter_list": "(test_cases)"
},
{
"docstring": null,
"function_declaration": "def handle_reorder_array(t, test_cases_data):",
"function_name": "handle_reorder_array",
... | [
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 reorder_array_min_absolute_difference(t: int, test_cases: list):\n \"\"\"\n Reorders each array of integers in such a way that the absolute \n ... | trial_gpt4o_1 | {
"original_instruction": "You are given an array of integers. Your task is to reorder the array in such a way that the absolute difference between any two consecutive elements is minimized.\n\nInput\n\nThe first line of the input contains a single integer t (1 ≤ t ≤ 100) — the number of test cases. The first line of... | 0.612859 | Code_Contests_11257 | C | [
"reorder_array",
"handle_reorder_array"
] | 2 | [
[
"handle_reorder_array",
"reorder_array"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | 8b2404de7dde544ff9044ea82e1e3515118e9095 | ec0c965f81ef2fcbfd8b884c3d8d1705a595c08b | |||
v1.0 | complete | Code_Contests | Code_Contests_10603_C | from typing import List, Tuple
def preprocess_matrix(matrix: List[List[int]]) -> List[List[int]]:
"""
Constructs the prefix sum matrix for the given matrix.
"""
pass
def query_sum(prefix_sum: List[List[int]], r1: int, c1: int, r2: int, c2: int) -> int:
"""
Given the prefix sum matrix, returns ... | def preprocess_matrix(matrix):
"""
Constructs the prefix sum matrix for the given matrix.
"""
M = len(matrix)
N = len(matrix[0])
prefix_sum = [[0] * (N + 1) for _ in range(M + 1)]
for i in range(1, M + 1):
for j in range(1, N + 1):
prefix_sum[i][j] = (matrix[i-1][j-1... | 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]
]
assert preprocess_matrix(matrix) == expected_prefix_sum
def test_query_sum():
... | [
{
"docstring": "Constructs the prefix sum matrix for the given matrix.",
"function_declaration": "def preprocess_matrix(matrix):",
"function_name": "preprocess_matrix",
"parameter_list": "(matrix)"
},
{
"docstring": "Given the prefix sum matrix, returns the sum of elements within the specifi... | [
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 preprocess_matrix(matrix):\n M, N = len(matrix), len(matrix[0])\n prefix_sum = [[0] * (N + 1) for _ in range(M + 1)]\n \n for i in range(1,... | trial_gpt4o_2 | {
"original_instruction": "Given a matrix of integers and a list of queries, your task is to return the sum of elements within the specified submatrix for each query. The matrix is of size $M \\times N$ and you will be given $Q$ queries. Each query contains four integers: the row and column indices of the top-left an... | 0.56407 | Code_Contests_10603 | C | [
"preprocess_matrix",
"query_sum",
"matrix_query"
] | 3 | [
[
"matrix_query",
"preprocess_matrix"
],
[
"matrix_query",
"query_sum"
]
] | 2 | [] | false | [] | false | pytest | false | [] | true | b2c5e1c78f7a19d51da1e85d3351613e40e0473e | bc4d1ced6556381329328dbee242371902fc7644 | |||
v1.0 | complete | Code_Contests | Code_Contests_10615_C | from typing import List, Tuple
def solve_road_network(n: int, m: int, roads: List[Tuple[int, int, int]]) -> Tuple[int, List[Tuple[int, int]]]:
""" In a faraway land, there exists a kingdom with n cities connected by m bidirectional roads.
Each road has a certain length. The king of this land wants to build a ... | def find(parent, i):
if parent[i] == i:
return i
return find(parent, parent[i])
def union(parent, rank, x, y):
root_x = find(parent, x)
root_y = find(parent, y)
if root_x != root_y:
if rank[root_x] > rank[root_y]:
parent[root_y] = root_x
elif rank[root_x] < ... | from solution import solve_road_network
def test_solve_road_network_case1():
n = 4
m = 5
roads = [
(1, 2, 3),
(1, 3, 4),
(4, 2, 2),
(4, 3, 1),
(2, 3, 5)
]
total_cost, mst = solve_road_network(n, m, roads)
assert total_cost == 6
assert len(mst) == 3
... | [
{
"docstring": null,
"function_declaration": "def find(parent, i):",
"function_name": "find",
"parameter_list": "(parent, i)"
},
{
"docstring": null,
"function_declaration": "def union(parent, rank, x, y):",
"function_name": "union",
"parameter_list": "(parent, rank, x, y)"
},
... | [
0,
0,
0,
0,
0,
1,
0,
0,
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 kruskal(n, m, roads):\n \"\"\"\n Finds the Minimum Spanning Tree using Kruskal's algorithm.\n\n Parameters:\n n : int - number of cities... | trial_gpt4o_8 | {
"original_instruction": "In a faraway land, there exists a kingdom with n cities connected by m bidirectional roads. Each road has a certain length. The king of this land wants to build a special road network that connects all the cities in such a way that the total length of the roads is minimized, and there exist... | 0.729649 | Code_Contests_10615 | C | [
"find",
"union",
"kruskal",
"solve_road_network"
] | 4 | [
[
"kruskal",
"find"
],
[
"kruskal",
"union"
],
[
"solve_road_network",
"kruskal"
],
[
"union",
"find"
]
] | 4 | [] | false | [] | false | pytest | true | [] | true | eeabae6d54b370d28a400d7f45e5f175b4755857 | 083d53b64e9759333ffcdba58ec8a2b89aac0bdb | |||
v1.0 | complete | Code_Contests | Code_Contests_10388_C | def count_barely_connected_cycles(n: int, m: int, edges: List[Tuple[int, int]]) -> int:
"""
Given a connected, undirected graph, identify and count all barely connected simple cycles.
A barely connected simple cycle is a cycle that doesn’t visit any vertex more than once
(except for the start/end verte... | from itertools import combinations
def count_barely_connected_cycles(n, m, edges):
from collections import defaultdict, deque
# Build adjacency list
graph = defaultdict(list)
for u, v in edges:
graph[u].append(v)
graph[v].append(u)
def find_cycles(start, visited, path):
... | def test_simple_case():
assert process_input_and_count_barely_connected_cycles(6, 7, [(1, 2), (2, 3), (3, 4), (4, 5), (5, 6), (6, 1), (2, 5)]) == 2
def test_no_cycles():
assert process_input_and_count_barely_connected_cycles(4, 3, [(1, 2), (2, 3), (3, 4)]) == 0
def test_single_barely_connected_cycle():
as... | [
{
"docstring": null,
"function_declaration": "def count_barely_connected_cycles(n, m, edges):",
"function_name": "count_barely_connected_cycles",
"parameter_list": "(n, m, edges)"
},
{
"docstring": null,
"function_declaration": "def process_input_and_count_barely_connected_cycles(n, m, i... | [
0,
0,
0,
0,
0,
1,
0,
1,
0
] | 2 | hard | 0.222 | {
"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 find_cycles(graph, n):\n def dfs(node, visited, parent):\n visited.add(node)\n for neigh in grap... | trial_gpt4o_7 | {
"original_instruction": "Given a connected, undirected graph, a cycle is a path that starts and ends at the same vertex while including other vertices. A simple cycle is a cycle that doesn’t visit any vertex more than once (except for the start/end vertex).\n\nWe call a simple cycle \"barely connected\" if it doesn... | 0.569778 | Code_Contests_10388 | C | [
"count_barely_connected_cycles",
"process_input_and_count_barely_connected_cycles"
] | 2 | [
[
"process_input_and_count_barely_connected_cycles",
"count_barely_connected_cycles"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | 68600483d391e7ced1598f19b380e42d8d5b92d9 | dd1b0bd866f95d757a0dbbb7f7a3d0c055cc4854 | |||
v1.0 | complete | Code_Contests | Code_Contests_11542_C | from typing import List
def kth_prime(k_list: List[int]) -> List[int]:
"""
For each k in k_list, return the k-th prime number.
>>> kth_prime([1])
[2]
>>> kth_prime([2])
[3]
>>> kth_prime([3])
[5]
>>> kth_prime([1, 2, 3, 4, 5])
[2, 3, 5, 7, 11]
>>> kth_prime([10, 3, 20,... | def sieve_eratosthenes(n):
"""
Generate a list of prime numbers up to n using the Sieve of Eratosthenes.
"""
is_prime = [True] * (n + 1)
p = 2
while p * p <= n:
if is_prime[p]:
for i in range(p * p, n + 1, p):
is_prime[i] = False
p += 1
prime_numbe... | from solution import kth_prime
def test_kth_prime_single_query():
assert kth_prime([1]) == [2]
assert kth_prime([2]) == [3]
assert kth_prime([3]) == [5]
def test_kth_prime_multiple_queries():
assert kth_prime([1, 2, 3, 4, 5]) == [2, 3, 5, 7, 11]
def test_kth_prime_large_queries():
result = kth_pr... | [
{
"docstring": "Generate a list of prime numbers up to n using the Sieve of Eratosthenes.",
"function_declaration": "def sieve_eratosthenes(n):",
"function_name": "sieve_eratosthenes",
"parameter_list": "(n)"
},
{
"docstring": "For each k in k_list, return the k-th prime number.",
"funct... | [
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 sieve(n):\n \"\"\"\n Sieve of Eratosthenes to generate all prime numbers up to n.\n \"\"\"\n is_prime = [True] * (n + 1)\n is_prime[0], ... | trial_gpt4o_2 | {
"original_instruction": "Sheldon’s Friendship Algorithm\n\nSheldon, Leonard, and their friends are obsessed with numbers and prime sequences. They've come up with a new challenge and they need your help.\n\nA prime number is a natural number greater than 1 that has no positive divisors other than 1 and itself. A pr... | 0.718519 | Code_Contests_11542 | C | [
"sieve_eratosthenes",
"kth_prime"
] | 2 | [
[
"kth_prime",
"sieve_eratosthenes"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | ac46bb4ea90e61e810c309cce0e0c8b643475ac1 | 9144120c2ec434438a0d9b7473e9de5f6acc4bcb | |||
v1.0 | complete | Code_Contests | Code_Contests_10851_C | def partition(s: str) -> List[List[str]]:
""" Given a string s, partition s such that every substring of the partition is a palindrome.
Return all possible palindrome partitioning of s.
>>> partition("aab")
[["a","a","b"],["aa","b"]]
>>> partition("racecar")
[["r","a","c","e","c","a","r"],... | def is_palindrome(sub):
"""
Checks if the given substring is a palindrome.
"""
return sub == sub[::-1]
def partition(s):
"""
Given a string s, partitions s such that every substring of the partition is a palindrome.
Returns all possible palindrome partitioning of s.
"""
result = []
... | from solution import partition
def test_example_1():
s = "aab"
expected = [["a", "a", "b"], ["aa", "b"]]
result = partition(s)
assert sorted(result) == sorted(expected)
def test_example_2():
s = "racecar"
expected = [["r","a","c","e","c","a","r"], ["r","aceca","r"], ["r","a","cec","a","r"], ["... | [
{
"docstring": "Checks if the given substring is a palindrome.",
"function_declaration": "def is_palindrome(sub):",
"function_name": "is_palindrome",
"parameter_list": "(sub)"
},
{
"docstring": "Given a string s, partitions s such that every substring of the partition is a palindrome.\nRetur... | [
0,
0,
0,
0,
0,
0,
0,
1,
1,
0
] | 2 | hard | 0.2 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_palindrome(s):\n \"\"\"\n Returns True if the string s is a palindrome, False otherwise.\n \"\"\"\n return s == s[::-1]\n\ndef partition... | trial_gpt4o_8 | {
"original_instruction": "Palindrome Partitioning\n\nProblem Statement\n\nGiven a string s, partition s such that every substring of the partition is a palindrome. Return all possible palindrome partitioning of s.\n\nA palindrome string is a string that reads the same backward as forward.\n\nInput format\n\n* s: A s... | 0.663977 | Code_Contests_10851 | C | [
"is_palindrome",
"partition",
"partition_helper"
] | 3 | [
[
"partition",
"partition_helper"
],
[
"partition_helper",
"is_palindrome"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 62a2b71024458b072cbc1be5af09a98e212e0bc3 | 0a00e40ec9fe6eec7a4665d9df84e4ad0ae5f3f3 | |||
v1.0 | complete | Code_Contests | Code_Contests_10346_C | from typing import List, Tuple
def longest_common_prefix(strs: List[str]) -> str:
"""
Function to find the longest common prefix string amongst an array of strings.
If there is no common prefix, return an empty string "".
>>> longest_common_prefix(["apple", "ape", "april"])
'ap'
>>> longest_co... | def longest_common_prefix(strs):
"""
Function to find the longest common prefix string amongst an array of strings.
If there is no common prefix, return an empty string "".
"""
if not strs:
return ""
# Start with the prefix being the first string in the array
prefix = strs[0]
... | from solution import longest_common_prefix, find_lcps_for_cases, process_input
def test_longest_common_prefix():
assert longest_common_prefix(["apple", "ape", "april"]) == "ap"
assert longest_common_prefix(["banana", "band", "bandana", "banner"]) == "ban"
assert longest_common_prefix(["dog", "racecar", "ca... | [
{
"docstring": "Function to find the longest common prefix string amongst an array of strings.\nIf there is no common prefix, return an empty string \"\".",
"function_declaration": "def longest_common_prefix(strs):",
"function_name": "longest_common_prefix",
"parameter_list": "(strs)"
},
{
"... | [
0,
1,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def find_longest_common_prefix(strs):\n \"\"\"\n This function returns the longest common prefix string amongst an array of strings.\n If there is... | trial_gpt4o_2 | {
"original_instruction": "Write a program to find the Longest Common Prefix (LCP) among a given list of strings. The LCP of a set of strings is the longest substring that is a prefix of all the strings in the set.\nFor example:\nL = {\"apple\", \"ape\", \"april\"} // Here LCP is \"ap\" because it is the longest star... | 0.775249 | Code_Contests_10346 | C | [
"longest_common_prefix",
"find_lcps_for_cases",
"process_input"
] | 3 | [
[
"find_lcps_for_cases",
"longest_common_prefix"
]
] | 1 | [
"process_input"
] | false | [] | false | pytest | true | [] | true | 32abaf482c09425ce6378f1fff63b2cb1954e8e8 | a0f58a3c734516c0de25b6ddbf785a812b32d63c | |||
v1.0 | complete | Code_Contests | Code_Contests_11302_C | from typing import List, Tuple
def answer_queries(N: int, Q: int, edges: List[Tuple[int, int]], queries: List[Tuple[int, int]]) -> List[int]:
""" Perform queries on a binary tree.
You are given a binary tree with N nodes where each node has a unique value from 1 to N.
The tree is represented in a 2D l... | from collections import defaultdict
def compute_subtree_properties(N, edges):
tree = defaultdict(list)
for u, v in edges:
tree[u].append(v)
tree[v].append(u)
subtree_size = [0] * (N + 1)
subtree_sum = [0] * (N + 1)
def dfs(node, parent):
subtree_size[node] = 1
subt... | import pytest
from solution import answer_queries
def test_example_case():
N = 5
Q = 4
edges = [(1,2), (1,3), (2,4), (2,5)]
queries = [(1,1), (1,2), (2,1), (2,2)]
expected_output = [5, 3, 15, 11]
assert answer_queries(N, Q, edges, queries) == expected_output
def test_single_node_tree():
... | [
{
"docstring": null,
"function_declaration": "def compute_subtree_properties(N, edges):",
"function_name": "compute_subtree_properties",
"parameter_list": "(N, edges)"
},
{
"docstring": null,
"function_declaration": "def answer_queries(N, Q, edges, queries):",
"function_name": "answe... | [
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\nfrom collections import defaultdict, deque\n\ninput = sys.stdin.read\n\ndef preprocess(N, edges):\n # Create adjacency list for the graph\n ... | trial_gpt4o_2 | {
"original_instruction": "You are given a binary tree with `N` nodes where each node has a unique value from `1` to `N`. The tree is represented in a 2D list `edges` of size `(N-1) x 2` where each `edges[i] = [u, v]` represents an undirected edge connecting nodes `u` and `v`. Perform `Q` queries of the following typ... | 0.679107 | Code_Contests_11302 | C | [
"compute_subtree_properties",
"answer_queries"
] | 2 | [
[
"answer_queries",
"compute_subtree_properties"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | a9d463d64de733c8b48f8e3c584453e773f0e373 | 0052889500dd744c5e2ba0060e9fb1fd44496824 | |||
v1.0 | complete | Code_Contests | Code_Contests_10971_C | from typing import List
def find_optimal_word(text: str, words: List[str]) -> str:
"""
Design a function called `find_optimal_word` which can take a text corpus
and a list of words as input. Your function should identify and return
the word that, when removed from the text, results in the highest po... | import statistics
def calculate_variance(text):
words = text.split()
lengths = [len(word) for word in words]
return statistics.variance(lengths) if len(lengths) > 1 else 0
def find_optimal_word(text, words):
original_variance = calculate_variance(text)
optimal_word = None
max_increase = float(... | from solution import find_optimal_word
def test_find_optimal_word():
text = "The quick brown fox jumps over the lazy dog"
words = ["the", "fox", "lazy"]
assert find_optimal_word(text, words) == "lazy"
def test_find_optimal_word_with_tie():
text = "the cat sat on the mat"
words = ["the", "cat"]
... | [
{
"docstring": null,
"function_declaration": "def calculate_variance(text):",
"function_name": "calculate_variance",
"parameter_list": "(text)"
},
{
"docstring": null,
"function_declaration": "def find_optimal_word(text, words):",
"function_name": "find_optimal_word",
"parameter_... | [
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 re\nimport numpy as np\n\ndef lexical_variance(word_lengths):\n \"\"\"\n Helper function to calculate variance in the length of words.\n \"... | trial_gpt4o_2 | {
"original_instruction": "Design a function called `find_optimal_word` which can take a text corpus and a list of words as input. Your function should identify and return the word that, when removed from the text, results in the highest possible increase in lexical variance (calculated as the variance in length of t... | 0.645837 | Code_Contests_10971 | C | [
"calculate_variance",
"find_optimal_word"
] | 2 | [
[
"find_optimal_word",
"calculate_variance"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 13885b8979505623305be871de42c31523150854 | 6c39af536a6b69d9ba609e51174662f688ad827b | |||
v1.0 | complete | Code_Contests | Code_Contests_10598_C | from typing import List, Tuple
def can_assign_activities(n: int, m: int, pairs: List[Tuple[int, int]]) -> str:
"""Determine if children can be assigned to activities such that no two children
who are friends end up in the same activity.
Args:
n (int): The number of children.
m (int): The numb... | from collections import deque
def is_bipartite(n, friendships):
# Graph adjacency list
graph = [[] for _ in range(n + 1)]
for u, v in friendships:
graph[u].append(v)
graph[v].append(u)
# Colors array to store colors of nodes
color = [-1] * (n + 1)
for i in range(1, n + 1)... | def test_can_assign_activities_yes():
assert can_assign_activities(4, 3, [(1, 2), (2, 3), (3, 4)]) == "YES"
def test_can_assign_activities_no():
assert can_assign_activities(3, 3, [(1, 2), (2, 3), (3, 1)]) == "NO"
def test_can_assign_activities_single_child():
assert can_assign_activities(1, 0, []) == "YE... | [
{
"docstring": null,
"function_declaration": "def is_bipartite(n, friendships):",
"function_name": "is_bipartite",
"parameter_list": "(n, friendships)"
},
{
"docstring": null,
"function_declaration": "def can_assign_activities(n, m, pairs):",
"function_name": "can_assign_activities",... | [
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 collections import deque\n\ndef is_bipartite(n, friendships):\n \"\"\"\n Determines if the given graph is bipartite.\n \n :param n: Number... | trial_gpt4o_2 | {
"original_instruction": "A local charity is organizing a fair where n children will participate in various activities. Each child is required to participate in exactly one activity, and the charity wants to ensure that no two children who are friends end up in the same activity. You are given a list of m pairs, whe... | 0.587102 | Code_Contests_10598 | C | [
"is_bipartite",
"can_assign_activities"
] | 2 | [
[
"can_assign_activities",
"is_bipartite"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | f51bac4fa75524ec025a15c88b2219ac1a9cf22a | 69006825f4dbb9cd2b363dc544a443a2e1b9ae7c | |||
v1.0 | complete | Code_Contests | Code_Contests_11140_C | from typing import List
def is_strictly_increasing(sequence: List[int]) -> bool:
"""
Given a sequence of numbers, determines if the sequence is strictly increasing.
:param sequence: List of integers
:return: Boolean, True if sequence is strictly increasing, False otherwise
>>> is_strictly_incr... | def is_strictly_increasing(sequence):
"""
Given a sequence of numbers, determines if the sequence is strictly increasing.
:param sequence: List of integers
:return: Boolean, True if sequence is strictly increasing, False otherwise
"""
for i in range(1, len(sequence)):
if sequence[i] <= s... | from solution import is_strictly_increasing, check_sequences
def test_is_strictly_increasing():
assert is_strictly_increasing([1, 2, 3, 4, 5]) == True
assert is_strictly_increasing([1, 2, 2, 3]) == False
assert is_strictly_increasing([-1, 0, 1, 2, 3, 4]) == True
assert is_strictly_increasing([5, 6, 7, ... | [
{
"docstring": "Given a sequence of numbers, determines if the sequence is strictly increasing.\n:param sequence: List of integers\n:return: Boolean, True if sequence is strictly increasing, False otherwise",
"function_declaration": "def is_strictly_increasing(sequence):",
"function_name": "is_strictly_... | [
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_strictly_increasing(sequences):\n \"\"\"\n This function takes a list of sequences and determines whether each sequence is strictly increasing... | trial_gpt4o_2 | {
"original_instruction": "Consider the following problem scenario: You are working on a project that involves manipulating sequences of numbers. One common operation you need to perform is checking whether a given sequence of numbers is strictly increasing or not. A strictly increasing sequence is one in which each ... | 0.716321 | Code_Contests_11140 | C | [
"is_strictly_increasing",
"check_sequences"
] | 2 | [
[
"check_sequences",
"is_strictly_increasing"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 16e5c91710ef37f15814469f0e402b5853fa93ee | bd93ee03b023f625cb73487fe251e0cf1010e10b | |||
v1.0 | complete | Code_Contests | Code_Contests_11409_C | from typing import List
def infix_to_postfix(expression: str) -> str:
""" Convert an infix expression to its equivalent postfix expression.
>>> infix_to_postfix('3+4*2/(1-5)^2')
'3 4 2 * 1 5 - 2 ^ / +'
>>> infix_to_postfix('2*(3+7)/4-1')
'2 3 7 + * 4 / 1 -'
"""
pass
def evaluate_postfix(e... | def infix_to_postfix(expression):
precedence = {'+': 1, '-': 1, '*': 2, '/': 2, '^': 3}
output = []
stack = []
for char in expression:
if char.isnumeric():
output.append(char)
elif char == '(':
stack.append(char)
elif char == ')':
while stack ... | from solution import infix_to_postfix, evaluate_postfix, process_input
def test_infix_to_postfix():
assert infix_to_postfix('3+4*2/(1-5)^2') == '3 4 2 * 1 5 - 2 ^ / +'
assert infix_to_postfix('2*(3+7)/4-1') == '2 3 7 + * 4 / 1 -'
assert infix_to_postfix('5+6*(7-3)/2') == '5 6 7 3 - * 2 / +'
def test_evalu... | [
{
"docstring": null,
"function_declaration": "def infix_to_postfix(expression):",
"function_name": "infix_to_postfix",
"parameter_list": "(expression)"
},
{
"docstring": null,
"function_declaration": "def evaluate_postfix(expression):",
"function_name": "evaluate_postfix",
"param... | [
1,
1,
0
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import operator\n\n# Define operator precedence and associativity\nprecedence = {\n '^': (4, 'Right'),\n '*': (3, 'Left'),\n '/': (3, 'Left'),\n ... | trial_gpt4o_1 | {
"original_instruction": "You have been given a string that contains a mathematical expression in infix notation. Your task is to write a program that converts this infix expression into its equivalent postfix (Reverse Polish) notation and then evaluates the postfix expression.\n\nThe input consists of multiple line... | 0.530515 | Code_Contests_11409 | C | [
"infix_to_postfix",
"evaluate_postfix",
"process_input"
] | 3 | [
[
"process_input",
"evaluate_postfix"
],
[
"process_input",
"infix_to_postfix"
]
] | 2 | [
"process_input"
] | false | [] | false | pytest | true | [] | true | 148ec1f57e99092a8db094ff3b681a87782a0d0f | f5bdd5ce1f1f28afcf6fe1cff664d9c388d51482 | |||
v1.0 | complete | Code_Contests | Code_Contests_11513_C | def evaluate_expressions(n: int, expressions: List[str]) -> List[int]:
""" Evaluates multiple mathematical expressions in infix notation, given the number of expressions n.
Returns a list of results.
>>> evaluate_expressions(1, ["3 + 5"]) == [8]
>>> evaluate_expressions(1, ["10 + 2 * 6"]) == [22]
>>... | def evaluate_expression(expression):
"""
Evaluates a single mathematical expression in infix notation with parentheses.
"""
return eval(expression)
def evaluate_expressions(n, expressions):
"""
Evaluates multiple mathematical expressions in infix notation, given the number of expressions n.
... | from solution import evaluate_expressions
def test_single_addition():
assert evaluate_expressions(1, ["3 + 5"]) == [8]
def test_with_multiplication():
assert evaluate_expressions(1, ["10 + 2 * 6"]) == [22]
def test_combined_operations():
assert evaluate_expressions(1, ["100 * 2 + 12"]) == [212]
def test... | [
{
"docstring": "Evaluates a single mathematical expression in infix notation with parentheses.",
"function_declaration": "def evaluate_expression(expression):",
"function_name": "evaluate_expression",
"parameter_list": "(expression)"
},
{
"docstring": "Evaluates multiple mathematical express... | [
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 evaluate_expression(expression):\n \"\"\"\n Evaluates a single mathematical expression in infix notation with parentheses.\n \"\"\"\n retur... | trial_gpt4o_0 | {
"original_instruction": "Vanya is developing a small scientific calculator application. The calculator needs to be able to perform some basic arithmetic operations such as addition, subtraction, multiplication, and division. Moreover, it should also support evaluating simple mathematical expressions in infix notati... | 0.634343 | Code_Contests_11513 | C | [
"evaluate_expression",
"evaluate_expressions"
] | 2 | [
[
"evaluate_expressions",
"evaluate_expression"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 6533ae0eada5f8cae9570c8e40306bfb463ed1a8 | 516d893e8f83255d5af49626dab5a1ef7367d384 | |||
v1.0 | complete | Code_Contests | Code_Contests_11870_C | def process_queries(queries: List[str]) -> List[int]:
""" Process a list of queries on an infinite array where A[i] = i^3.
1. Q1 l r: Compute the sum of the elements from index l to index r (inclusive).
2. Q2 l r: Compute the sum of the square of the elements from index l to index r (inclusive).
3. Q3 x... | def cube(n):
return n ** 3
def sum_of_cubes(l, r):
return sum(cube(x) for x in range(l, r + 1))
def sum_of_squares_of_cubes(l, r):
return sum(cube(x) ** 2 for x in range(l, r + 1))
def handle_query(query):
q_type, *params = query.split()
if q_type == 'Q1':
l, r = map(int, params)
... | from solution import process_queries
def test_sum_of_cubes():
queries = ["Q1 2 4"]
expected_output = [99]
assert process_queries(queries) == expected_output
def test_sum_of_squares_of_cubes():
queries = ["Q2 1 3"]
expected_output = [794]
assert process_queries(queries) == expected_output
def ... | [
{
"docstring": null,
"function_declaration": "def cube(n):",
"function_name": "cube",
"parameter_list": "(n)"
},
{
"docstring": null,
"function_declaration": "def sum_of_cubes(l, r):",
"function_name": "sum_of_cubes",
"parameter_list": "(l, r)"
},
{
"docstring": null,
... | [
0,
0,
0,
0,
1,
0,
0,
0
] | 1 | hard | 0.125 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def query_processor(queries):\n def sum_of_cubes(l, r):\n return sum(i ** 3 for i in range(l, r + 1))\n\n def sum_of_squares_of_cubes(l, r):\n... | trial_gpt4o_5 | {
"original_instruction": "You are given an infinite array where the i-th element is denoted by A[i] = i^3. Your task is to answer Q queries on this array. Each query is one of the following types:\n\n1. Q1 l r: Compute the sum of the elements from index l to index r (both inclusive).\n2. Q2 l r: Compute the sum of t... | 0.587705 | Code_Contests_11870 | C | [
"cube",
"sum_of_cubes",
"sum_of_squares_of_cubes",
"handle_query",
"process_queries"
] | 5 | [
[
"handle_query",
"cube"
],
[
"handle_query",
"sum_of_cubes"
],
[
"handle_query",
"sum_of_squares_of_cubes"
],
[
"process_queries",
"handle_query"
],
[
"sum_of_cubes",
"cube"
],
[
"sum_of_squares_of_cubes",
"cube"
]
] | 6 | [
"process_queries"
] | false | [] | false | pytest | true | [] | true | fd9245fe35fe321508e7ff9fc74b759ecd1a293f | 50cbf30dc98388dd904551363143fcfd23662862 | |||
v1.0 | complete | Code_Contests | Code_Contests_10130_C | from typing import List, Tuple
def rotate_90_clockwise(matrix: List[List[int]]) -> List[List[int]]:
""" Rotate a matrix 90 degrees clockwise.
Args:
matrix: A list of n rows, each containing m integers.
Returns:
A new matrix obtained by rotating the input matrix 90 degrees cloc... | def rotate_90_clockwise(matrix):
return list(zip(*matrix[::-1]))
def rotate_matrix(matrix, k):
# Determine the effective number of rotations
k = k % 4
for _ in range(k):
matrix = rotate_90_clockwise(matrix)
return matrix
def process_test_cases(test_cases):
results = []
for n, m, k,... | from solution import rotate_matrix, process_test_cases
def test_rotate_90_clockwise():
matrix = [
[1, 2, 3],
[4, 5, 6],
[7, 8, 9]
]
rotated = rotate_90_clockwise(matrix)
expected = [
(7, 4, 1),
(8, 5, 2),
(9, 6, 3)
]
assert rotated == expected
de... | [
{
"docstring": null,
"function_declaration": "def rotate_90_clockwise(matrix):",
"function_name": "rotate_90_clockwise",
"parameter_list": "(matrix)"
},
{
"docstring": null,
"function_declaration": "def rotate_matrix(matrix, k):",
"function_name": "rotate_matrix",
"parameter_list... | [
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 rotate_90_clockwise(matrix):\n \"\"\"\n Returns the matrix rotated 90 degrees clockwise.\n \"\"\"\n return [[row[i] for row in matrix[::-1]... | trial_gpt4o_1 | {
"original_instruction": "You and your friend Maya are engaged in a puzzle involving matrices. You have been given an n x m matrix filled with integers. Your task is to rotate this matrix 90 degrees clockwise k times. \n\nA single 90-degree clockwise rotation of a matrix involves:\n\n1. Translating each element at p... | 0.575947 | Code_Contests_10130 | C | [
"rotate_90_clockwise",
"rotate_matrix",
"process_test_cases"
] | 3 | [
[
"process_test_cases",
"rotate_matrix"
],
[
"rotate_matrix",
"rotate_90_clockwise"
]
] | 2 | [
"process_test_cases"
] | false | [] | false | pytest | true | [] | true | 470f6c85a0b74187bcfe182ae1176062f86faaa6 | 97f0711dfe38f54e41f6b7ceca34be53ccf70881 | |||
v1.0 | complete | Code_Contests | Code_Contests_11944_C | class TreeNode:
def __init__(self, value=0, left=None, right=None):
self.value = value
self.left = left
self.right = right
def construct_postorder_from_pre_in(preorder, inorder):
"""
Constructs the binary tree from the given pre-order and in-order traversal sequences and
outpu... | class TreeNode:
def __init__(self, value=0, left=None, right=None):
self.value = value
self.left = left
self.right = right
def build_tree(preorder, inorder):
if not preorder or not inorder:
return None
root_val = preorder.pop(0)
root = TreeNode(root_val)
inorder_in... | from solution import construct_postorder_from_pre_in
def test_example_1():
preorder = [1, 2, 4, 3]
inorder = [4, 2, 1, 3]
expected_postorder = [4, 2, 3, 1]
assert construct_postorder_from_pre_in(preorder, inorder) == expected_postorder
def test_example_2():
preorder = [3, 9, 20, 15, 7, 10, 8]
... | [] | [
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 ... | trial_gpt4o_2 | {
"original_instruction": "Lisa has been learning about binary trees in her computer science class and she came upon an interesting problem involving binary tree traversal. She wants to implement a function that constructs the binary tree given pre-order and in-order traversal sequences. However, she is having troubl... | 0.509746 | Code_Contests_11944 | C | [
"build_tree",
"postorder_traversal",
"construct_postorder_from_pre_in"
] | 3 | [
[
"construct_postorder_from_pre_in",
"build_tree"
],
[
"construct_postorder_from_pre_in",
"postorder_traversal"
]
] | 2 | [] | false | [
"TreeNode"
] | true | pytest | true | [] | true | 2cf0b4938bca034d29ed318a06ff05130f00972a | 5a8de6b46bc527c2376fd423c17190d6a69a1c33 | |||
v1.0 | complete | Code_Contests | Code_Contests_11234_C | def beautify_garden(n: int, flower_data: List[str]) -> str:
"""
Rearranges flowers in such a way that no two adjacent flowers are of the same type
and the arrangement is lexicographically smallest. If it is not possible, returns "Not possible".
Parameters:
n (int): The number of flowers.
f... | from collections import Counter
import heapq
def rearrange_flowers(n, flowers):
# Count frequencies and store flowers information
flower_count = Counter(flowers[i][0] for i in range(n))
max_freq = max(flower_count.values())
# If any flower appears more than (n + 1) // 2 times, it's impossible
... | def test_flower_rearrangement():
assert beautify_garden(5, ["a", "3", "b", "1", "a", "2", "c", "1", "a", "1"]) in [
"a 3 b 1 a 2 c 1 a 1",
"a 2 b 1 a 3 c 1 a 1",
"a 1 b 1 a 3 c 1 a 2"
]
assert beautify_garden(4, ["a", "1", "a", "2", "a", "3", "a", "4"]) == "Not possible"
as... | [
{
"docstring": null,
"function_declaration": "def rearrange_flowers(n, flowers):",
"function_name": "rearrange_flowers",
"parameter_list": "(n, flowers)"
},
{
"docstring": null,
"function_declaration": "def beautify_garden(n, flower_data):",
"function_name": "beautify_garden",
"p... | [
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 rearrange_flowers(n, flowers):\n from collections import Counter\n from heapq import heappush, heappop\n\n count = Counter(flower[0] for flowe... | trial_gpt4o_1 | {
"original_instruction": "A gardener plants flowers in a row. Each flower has a specific type and a height. Types of flowers are represented by a character (a-z), and the height of each flower is an integer (1 ≤ height ≤ 1000). The garden looks more beautiful if there are no adjacent flowers of the same type.\n\nYou... | 0.557954 | Code_Contests_11234 | C | [
"rearrange_flowers",
"beautify_garden",
"solve"
] | 3 | [
[
"beautify_garden",
"rearrange_flowers"
],
[
"solve",
"beautify_garden"
]
] | 2 | [] | false | [] | false | pytest | false | [] | true | 1bab54d8020b63267502e2c58a4d2d201f33f613 | b14ebd29223d192e4869efd5fc9f1f601eb27756 | |||
v1.0 | complete | Code_Contests | Code_Contests_11516_C | def is_prime(n: int) -> bool:
""" Check if a given number is a prime number.
>>> is_prime(2)
True
>>> is_prime(4)
False
"""
# Your implementation here
pass
def find_prime_ids(participant_ids: List[int]) -> List[Union[int, str]]:
""" Given a list of participant IDs, return a list of ... | def is_prime(n):
"""
Helper function to determine if a number is prime.
"""
if n <= 1:
return False
if n == 2:
return True
if n % 2 == 0:
return False
max_divisor = int(n**0.5) + 1
for d in range(3, max_divisor, 2):
if n % d == 0:
return False
... | from solution import is_prime, find_prime_ids
def test_is_prime():
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(4) == False
assert is_prime(17) == True
assert is_prime(18) == False
assert is_prime(1) == False
def test_find_prime_ids():
# Test case with prime IDs
... | [
{
"docstring": "Helper function to determine if a number is prime.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "This function takes a list of participant IDs and returns a list of prime IDs.",
"function_declaration"... | [
1,
1,
0
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(n):\n \"\"\"\n Helper function to determine if a number is prime.\n \"\"\"\n if n <= 1:\n return False\n if n == 2:\n ... | trial_gpt4o_0 | {
"original_instruction": "John is organizing a marathon where participants have unique positive integer IDs. The IDs represent the number of seconds they took to complete the marathon. John wants to congratulate participants who took a prime number of seconds.\n\nWrite a program that takes a list of participant IDs ... | 0.66266 | Code_Contests_11516 | C | [
"is_prime",
"find_prime_ids"
] | 2 | [
[
"find_prime_ids",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 13287380c05c8b19336c06b2fe24500e9950a92c | 1a1b03c4f57e82303f48e0061b60171141988775 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.