version
stringclasses
1 value
style
stringclasses
2 values
subset
stringclasses
12 values
question_id
stringlengths
9
23
question
stringlengths
27
8.13k
solution
stringlengths
99
5.97k
test
stringlengths
105
4.45k
test_info
listlengths
0
13
gpt_pass_sequence
listlengths
1
10
gpt_pass_trial_num
int64
1
10
gpt_difficulty
stringclasses
3 values
gpt_pass_percentage
float64
0.1
1
trials
dict
chosen_trial
stringclasses
10 values
metadata
dict
benchmark_similarity
float64
0.16
0.93
benchmark_instruction
stringclasses
1 value
benchmark_task_id
stringclasses
1 value
filter_reason
stringclasses
1 value
base_id
stringlengths
7
21
variant
stringclasses
2 values
top_function_names
listlengths
2
13
n_top_functions
int64
2
13
helper_call_edges
listlengths
1
16
n_helper_call_edges
int64
1
16
harness_functions
listlengths
0
3
structural_wrapper
bool
1 class
class_names
listlengths
0
5
has_class
bool
2 classes
test_kind
stringclasses
1 value
test_has_solution_import
bool
2 classes
third_party_imports
listlengths
0
5
stdlib_only
bool
2 classes
question_norm_sha1
stringlengths
40
40
solution_ast_sha1
stringlengths
40
40
v1.0
instruct
Code_Contests
Code_Contests_6088_I
Given a list of integers and N queries, each querying about the subarray defined by indices Li and Ri (both inclusive), determine the sum of elements in the subarray for each query. Input First line: An integer M, the number of elements in the list. Next line: M integers, the elements of the list. Next line: An intege...
def prefix_sums(arr): """ Returns the prefix sum array of the given array. """ prefix_sum_arr = [0] * (len(arr) + 1) for i in range(1, len(arr) + 1): prefix_sum_arr[i] = prefix_sum_arr[i - 1] + arr[i - 1] return prefix_sum_arr def query_subarray_sum(prefix_sum_arr, li, ri): """ ...
def test_prefix_sums(): assert prefix_sums([1, 2, 3, 4, 5]) == [0, 1, 3, 6, 10, 15] assert prefix_sums([0, -1, 2]) == [0, 0, -1, 1] assert prefix_sums([2, 2, 2, 2]) == [0, 2, 4, 6, 8] def test_query_subarray_sum(): prefix_sum_arr = [0, 1, 3, 6, 10, 15] assert query_subarray_sum(prefix_sum_arr, 1, 3...
[ { "docstring": "Returns the prefix sum array of the given array.", "function_declaration": "def prefix_sums(arr):", "function_name": "prefix_sums", "parameter_list": "(arr)" }, { "docstring": "Returns the sum of elements from index li to ri using the prefix sum array.", "function_declara...
[ 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 subarray_sums(arr, queries):\n \"\"\"\n Returns the sums of subarrays for each query.\n \n Parameters:\n arr (list): A list of integers....
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00006088", "row_id": 6088, "seed_ids": "[9441]" }
0.708748
Code_Contests_6088
I
[ "prefix_sums", "query_subarray_sum", "solve_subarray_sums" ]
3
[ [ "solve_subarray_sums", "prefix_sums" ], [ "solve_subarray_sums", "query_subarray_sum" ] ]
2
[]
false
[]
false
pytest
false
[]
true
efffa658d7280102bc07dd67d1c70e7c9b8dc3da
0696b7c8ec78dffccfcb0a1a4749b4a03dbf2882
v1.0
instruct
Code_Contests
Code_Contests_6151_I
In a distant land, there exists a special type of number known as "Balanced Numbers." A number is considered balanced if the sum of digits on the left side of the middle digit(s) is equal to the sum of digits on the right side. The middle digit(s) in a number with an even number of digits are the two central digits, wh...
def is_balanced_number(number): """ Function to check if a number is balanced. """ number_str = str(number) length = len(number_str) if length == 1: return True # A single digit number is trivially balanced if length % 2 == 0: # Even length left_half = number_str[...
def test_is_balanced_number_single_digit(): assert is_balanced_number(1) == True def test_is_balanced_number_odd_length_balanced(): assert is_balanced_number(12321) == True def test_is_balanced_number_odd_length_not_balanced(): assert is_balanced_number(441) == False def test_is_balanced_number_even_leng...
[ { "docstring": "Function to check if a number is balanced.", "function_declaration": "def is_balanced_number(number):", "function_name": "is_balanced_number", "parameter_list": "(number)" }, { "docstring": "Function to check if each number in the list is balanced or not.", "function_decl...
[ 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 is_balanced_number(number):\n \"\"\"\n Function to check if a number is balanced.\n \"\"\"\n number_str = str(number)\n length = len(num...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00006151", "row_id": 6151, "seed_ids": "[13298]" }
0.804333
Code_Contests_6151
I
[ "is_balanced_number", "check_balanced_numbers" ]
2
[ [ "check_balanced_numbers", "is_balanced_number" ] ]
1
[]
false
[]
false
pytest
false
[]
true
6f8b51f0485af67db4e1a359cb653d6bc67947d3
fff780b4e403ac3c561417d8b8f35d1cf4df5167
v1.0
instruct
Code_Contests
Code_Contests_6159_I
In an alternate universe, a king has a special type of chessboard of size N x N. Each cell of the chessboard can either be empty or contain a treasure with a certain value. The king is interested in knowing the sum of treasures in any given sub-board of the chessboard. You are tasked with writing a program that can eff...
def preprocess_chessboard(chessboard): N = len(chessboard) prefix_sum = [[0] * (N + 1) for _ in range(N + 1)] for i in range(1, N + 1): for j in range(1, N + 1): prefix_sum[i][j] = (chessboard[i - 1][j - 1] + prefix_sum[i - 1][j] + ...
from solution import solve_chessboard_queries, preprocess_chessboard, query_sum def test_preprocess_chessboard(): chessboard = [ [1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12], [13, 14, 15, 16] ] expected_prefix_sum = [ [0, 0, 0, 0, 0], [0, 1, 3, 6, 10], ...
[ { "docstring": null, "function_declaration": "def preprocess_chessboard(chessboard):", "function_name": "preprocess_chessboard", "parameter_list": "(chessboard)" }, { "docstring": null, "function_declaration": "def query_sum(prefix_sum, x1, y1, x2, y2):", "function_name": "query_sum"...
[ 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_chessboard(N, chessboard):\n # Create a prefix sum matrix\n prefix_sum = [[0] * (N + 1) for _ in range(N + 1)]\n \n for i in ran...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00006159", "row_id": 6159, "seed_ids": "[5802]" }
0.648642
Code_Contests_6159
I
[ "preprocess_chessboard", "query_sum", "solve_chessboard_queries" ]
3
[ [ "solve_chessboard_queries", "preprocess_chessboard" ], [ "solve_chessboard_queries", "query_sum" ] ]
2
[]
false
[]
false
pytest
true
[]
true
4a69d18ee257e2804019a069053d7959697a20ba
e9be87fef195afc58ddc2c89f04eb404f3cabdeb
v1.0
instruct
Code_Contests
Code_Contests_6179_I
**Robot Chess Tournament** You are organizing a chess tournament where two robots, Robot_X and Robot_Y, will compete in a series of chess matches. Each match follows the standard rules of chess, but with a twist: robots have different capabilities to process moves. Robot_X is better at processing tactical sequences, w...
# Assume TX(px, py) and SY(px, py) functions are provided. # For the sake of the solution, let's implement dummy TX and SY functions. def TX(px, py): # Dummy implementation of TX return 2 * px + py def SY(px, py): # Dummy implementation of SY return px + 2 * py def determine_winner(T, matches): r...
def test_determine_winner(): T = 2 matches = [ (3, [(1, 2), (3, 4), (5, 6)]), (4, [(2, 3), (4, 5), (6, 7), (8, 9)]) ] expected_results = [ "Robot_X wins.", "Robot_Y wins." ] results = determine_winner(T, matches) assert results == expected_results def te...
[ { "docstring": null, "function_declaration": "def TX(px, py):", "function_name": "TX", "parameter_list": "(px, py)" }, { "docstring": null, "function_declaration": "def SY(px, py):", "function_name": "SY", "parameter_list": "(px, py)" }, { "docstring": null, "function...
[ 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": "# Assume TX(px, py) and SY(px, py) functions are provided.\n# For the sake of the solution, let's implement dummy TX and SY functions.\n\ndef TX(px, py):\n...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00006179", "row_id": 6179, "seed_ids": "[616]" }
0.623328
Code_Contests_6179
I
[ "TX", "SY", "determine_winner" ]
3
[ [ "determine_winner", "SY" ], [ "determine_winner", "TX" ] ]
2
[]
false
[]
false
pytest
false
[]
true
955592ff597903ba318d8a2fc5ff471393d437f6
cc7dd53babe535bd7c75e762d0fe3e0373ef1c0b
v1.0
instruct
Code_Contests
Code_Contests_6206_I
Given an array A of length N, perform the following operations: - Select any two elements in the array that are adjacent (i.e. have indices i and i+1) and swap them. You are required to sort the array in non-decreasing order using the minimum number of such adjacent swaps. If it is possible to sort the array, print t...
def min_adjacent_swaps_to_sort(N, A): """ Determines the minimum number of adjacent swaps needed to sort the array in non-decreasing order. If it is not possible, returns -1. Args: N : int : the number of elements in the array A : list : the array of integers Returns: int : th...
from solution import min_adjacent_swaps_to_sort def test_sorted_array(): assert min_adjacent_swaps_to_sort(4, [1, 2, 3, 4]) == 0 def test_reverse_sorted_array(): assert min_adjacent_swaps_to_sort(5, [5, 4, 3, 2, 1]) == 10 def test_mixed_array(): assert min_adjacent_swaps_to_sort(5, [3, 1, 2, 5, 4]) == 3 ...
[ { "docstring": "Determines the minimum number of adjacent swaps needed to sort the array in \nnon-decreasing order. If it is not possible, returns -1.\n\nArgs:\nN : int : the number of elements in the array\nA : list : the array of integers\n\nReturns:\nint : the minimum number of adjacent swaps needed or -1 if...
[ 0, 0, 0, 0, 0, 0, 1, 0, 0, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def minimum_swaps_to_sort(array):\n \"\"\"\n Returns the minimum number of adjacent swaps needed to sort the array in non-decreasing order.\n If i...
trial_gpt4o_6
{ "original_instruction": "", "prompt_id": "00006206", "row_id": 6206, "seed_ids": "[9240]" }
0.745936
Code_Contests_6206
I
[ "min_adjacent_swaps_to_sort", "is_possible_to_sort", "bubble_sort_count_swaps" ]
3
[ [ "min_adjacent_swaps_to_sort", "bubble_sort_count_swaps" ], [ "min_adjacent_swaps_to_sort", "is_possible_to_sort" ] ]
2
[]
false
[]
false
pytest
true
[]
true
bf8461b68299217771c7e8dd1d358fc0b5bf050f
4c9721f41bfdc68ad31ca9ad1968dc52249a0ded
v1.0
instruct
Code_Contests
Code_Contests_6216_I
Consider a grid with several houses located on it. Each house is represented by a tuple `(x, y)` which denotes its location on the grid. You are given a list of house locations and your task is to determine the shortest possible route for a mailman to visit each house exactly once, starting from any house and returning...
from itertools import permutations def calculate_manhattan_distance(p1, p2): return abs(p1[0] - p2[0]) + abs(p1[1] - p2[1]) def calculate_total_route_distance(route): total_distance = 0 for i in range(len(route) - 1): total_distance += calculate_manhattan_distance(route[i], route[i+1]) total_d...
def test_calculate_manhattan_distance(): assert calculate_manhattan_distance((0, 0), (2, 0)) == 2 assert calculate_manhattan_distance((0, 0), (2, 2)) == 4 assert calculate_manhattan_distance((2, 2), (2, 3)) == 1 def test_calculate_total_route_distance(): assert calculate_total_route_distance([(0, 0), (...
[ { "docstring": null, "function_declaration": "def calculate_manhattan_distance(p1, p2):", "function_name": "calculate_manhattan_distance", "parameter_list": "(p1, p2)" }, { "docstring": null, "function_declaration": "def calculate_total_route_distance(route):", "function_name": "calc...
[ 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 itertools import permutations\n\ndef calculate_manhattan_distance(p1, p2):\n return abs(p1[0] - p2[0]) + abs(p1[1] - p2[1])\n\ndef calculate_total_...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00006216", "row_id": 6216, "seed_ids": "[7565]" }
0.666876
Code_Contests_6216
I
[ "calculate_manhattan_distance", "calculate_total_route_distance", "tsp_minimum_distance", "main" ]
4
[ [ "calculate_total_route_distance", "calculate_manhattan_distance" ], [ "tsp_minimum_distance", "calculate_total_route_distance" ] ]
2
[]
false
[]
false
pytest
false
[]
true
c7e20f7f42a3ef2f25799b594eba1b596e9155ad
7956a18086b2a14bc879cee649671f0817b44c34
v1.0
instruct
Code_Contests
Code_Contests_6238_I
In a small town, there is a unique way of organizing street numbers. Each street number is assigned a "beauty score" which is calculated as the sum of all the digits in the number. For example, the beauty score of 123 is 1 + 2 + 3 = 6. Given a range of street numbers [L, R], the town council needs to find the street n...
def sum_of_digits(n): """ Returns the sum of the digits of a number. """ return sum(map(int, str(n))) def max_beauty_score_in_range(L, R): """ Returns the street number in the range [L, R] which has the highest beauty score. If there are multiple numbers with the same score, the smallest on...
from solution import sum_of_digits, max_beauty_score_in_range, find_max_beauty_scores def test_sum_of_digits(): assert sum_of_digits(123) == 6 assert sum_of_digits(0) == 0 assert sum_of_digits(10) == 1 assert sum_of_digits(999) == 27 def test_max_beauty_score_in_range(): assert max_beauty_score_in...
[ { "docstring": "Returns the sum of the digits of a number.", "function_declaration": "def sum_of_digits(n):", "function_name": "sum_of_digits", "parameter_list": "(n)" }, { "docstring": "Returns the street number in the range [L, R] which has the highest beauty score.\nIf there are multiple ...
[ 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 sum_of_digits(n):\n \"\"\"\n Returns the sum of the digits of a number.\n \"\"\"\n return sum(map(int, str(n)))\n\ndef max_beauty_score_in_...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00006238", "row_id": 6238, "seed_ids": "[7734]" }
0.641705
Code_Contests_6238
I
[ "sum_of_digits", "max_beauty_score_in_range", "find_max_beauty_scores" ]
3
[ [ "find_max_beauty_scores", "max_beauty_score_in_range" ], [ "max_beauty_score_in_range", "sum_of_digits" ] ]
2
[]
false
[]
false
pytest
true
[]
true
ce33ce7f3b55d644c7ea4fac256d81a434a3c694
d1ea0efd5dc0a24b952b4e0f4337bcaf2e60966f
v1.0
instruct
Code_Contests
Code_Contests_6267_I
Nicole is trying to develop a unique encryption system for her secret messages. The process involves rotating a set of characters by a certain number of positions, wrapping around from the end to the beginning as necessary. The set of characters she is working with includes the lowercase letters from 'a' to 'z' only. ...
def shift_char(c, rotation): """ Shifts a single character by the given rotation value. """ alpha_start = ord('a') new_char = chr((ord(c) - alpha_start + rotation) % 26 + alpha_start) return new_char def encrypt_decrypt(mode, rotation, message): """ Encrypts or decrypts the given messag...
from solution import encrypt_decrypt def test_encrypt_positive_rotation(): assert encrypt_decrypt("encrypt", 2, "abc") == "cde" assert encrypt_decrypt("encrypt", 1, "z") == "a" def test_encrypt_negative_rotation(): assert encrypt_decrypt("encrypt", -1, "xyz") == "wxy" def test_decrypt_positive_rotation()...
[ { "docstring": "Shifts a single character by the given rotation value.", "function_declaration": "def shift_char(c, rotation):", "function_name": "shift_char", "parameter_list": "(c, rotation)" }, { "docstring": "Encrypts or decrypts the given message based on the mode and rotation value.", ...
[ 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 rotate_char(c, rotation, mode):\n \"\"\"\n Rotate a single character by the specified rotation amount.\n \n Parameters:\n - c (char): Th...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00006267", "row_id": 6267, "seed_ids": "[2763]" }
0.776108
Code_Contests_6267
I
[ "shift_char", "encrypt_decrypt" ]
2
[ [ "encrypt_decrypt", "shift_char" ] ]
1
[]
false
[]
false
pytest
true
[]
true
90f2fdbc3c427dc6f0ebffa00df22f735eb817f2
c050da2ffd94ea3ad9b1984cb5ed6f1ce0adee94
v1.0
instruct
Code_Contests
Code_Contests_6282_I
Given a string $s$ consisting of lowercase English letters, encode it using run-length encoding (RLE). Then, decode the encoded string back to the original string and print both the encoded and decoded strings. Run-length encoding is a simple form of data compression where sequences of the same value are stored as a s...
def run_length_encode(s): """ Encode the input string s using run-length encoding. """ encoded = "" i = 0 while i < len(s): count = 1 while i + 1 < len(s) and s[i] == s[i + 1]: i += 1 count += 1 encoded += s[i] + str(count) i += 1 retur...
from solution import run_length_encode, run_length_decode, encode_and_decode def test_run_length_encode(): assert run_length_encode("aaabbbcccaaa") == "a3b3c3a3" assert run_length_encode("abcd") == "a1b1c1d1" assert run_length_encode("aaaa") == "a4" assert run_length_encode("abcdddcba") == "a1b1c1d3c1b...
[ { "docstring": "Encode the input string s using run-length encoding.", "function_declaration": "def run_length_encode(s):", "function_name": "run_length_encode", "parameter_list": "(s)" }, { "docstring": "Decode the run-length encoded string.", "function_declaration": "def run_length_dec...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def run_length_encode(s):\n \"\"\"\n Encodes the given string s using run-length encoding.\n \"\"\"\n if not s:\n return \"\"\n \n ...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00006282", "row_id": 6282, "seed_ids": "[1251]" }
0.603055
Code_Contests_6282
I
[ "run_length_encode", "run_length_decode", "encode_and_decode" ]
3
[ [ "encode_and_decode", "run_length_decode" ], [ "encode_and_decode", "run_length_encode" ] ]
2
[]
false
[]
false
pytest
true
[]
true
c36d1e147c6b955e2a2155809f63b11225bb1196
cc8e75b5b4e756969bef5957f7d2d69532dd331d
v1.0
instruct
Code_Contests
Code_Contests_6285_I
The Chief Librarian at the Grand Library loves numbers and books. She is particularly interested in prime numbers. While cataloging books, she noticed that some books have prime numbers as their identification numbers and others do not. To make the cataloging process more interesting, she devised a method to find the "...
def is_prime(num): """ Check if the given number is a prime number. """ if num <= 1: return False if num == 2: return True if num % 2 == 0: return False for i in range(3, int(num**0.5) + 1, 2): if num % i == 0: return False return True def nea...
def test_is_prime(): assert is_prime(2) == True assert is_prime(3) == True assert is_prime(4) == False assert is_prime(5) == True assert is_prime(1) == False assert is_prime(0) == False def test_nearest_prime(): assert nearest_prime(10) == 7 assert nearest_prime(29) == 29 assert nea...
[ { "docstring": "Check if the given number is a prime number.", "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": "Find the largest prime number less than or equal to n.", "function_declaration": "def nearest_prime(n):",...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(num):\n \"\"\"\n Check if the given number is a prime number.\n \"\"\"\n if num <= 1:\n return False\n if num == 2:\n ...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00006285", "row_id": 6285, "seed_ids": "[9644]" }
0.664145
Code_Contests_6285
I
[ "is_prime", "nearest_prime" ]
2
[ [ "nearest_prime", "is_prime" ] ]
1
[]
false
[]
false
pytest
false
[]
true
0baf39fd0b29967fd356e3cf00910b39dc436256
3a8a30b7c3405b06d6295854ba9dbe07e591736d
v1.0
instruct
Code_Contests
Code_Contests_6299_I
You are given a matrix of size N x M consisting of characters 'L', 'R', 'U', 'D', representing left, right, up, and down respectively. A path can be formed if adjacent cells contain valid movements according to the given characters. For instance, a valid path starting at (i, j) with 'L' will move to (i, j-1), 'R' will...
def find_cycles(grid, N, M): def move(i, j): if grid[i][j] == 'L': return i, j - 1 if grid[i][j] == 'R': return i, j + 1 if grid[i][j] == 'U': return i - 1, j if grid[i][j] == 'D': return i + 1, j visited = [[False] * M for _ in range(N)] cycle_count = 0 for i in range(...
def test_find_cycles(): grid = [ ['R', 'R', 'D'], ['L', 'U', 'L'], ['L', 'D', 'L'] ] assert find_cycles(grid, 3, 3) == 1 grid = [ ['R', 'R'], ['L', 'L'] ] assert find_cycles(grid, 2, 2) == 0 def test_count_cycles(): test_cases = [ (3, 3, ...
[ { "docstring": null, "function_declaration": "def find_cycles(grid, N, M):", "function_name": "find_cycles", "parameter_list": "(grid, N, M)" }, { "docstring": null, "function_declaration": "def count_cycles(test_cases):", "function_name": "count_cycles", "parameter_list": "(test...
[ 0, 0, 0, 0, 0, 0, 0, 0, 1 ]
1
hard
0.111
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def find_cycles(matrix):\n n = len(matrix)\n m = len(matrix[0])\n visited = [[False] * m for _ in range(n)]\n parent = [[None] * m for _ in ran...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00006299", "row_id": 6299, "seed_ids": "[590]" }
0.720039
Code_Contests_6299
I
[ "find_cycles", "count_cycles", "process_input", "solution" ]
4
[ [ "count_cycles", "find_cycles" ], [ "solution", "count_cycles" ], [ "solution", "process_input" ] ]
3
[ "process_input" ]
false
[]
false
pytest
false
[]
true
f6564307017f603dd717a569c3307a3b06640aea
b895b394644fdcd8cb91a67d3ec35e3d5d49351c
v1.0
instruct
Code_Contests
Code_Contests_6320_I
You are given an array of integers. You can perform the following operation any number of times: choose any contiguous subarray of the array, and reverse the order of the elements in it. Let g(a) be the minimum number of operations required to sort the array in non-descending order. For example: * g([1, 2, 3]) = 0 ...
def g(array): """ Calculate the minimum number of operations (reversals) needed to sort array in non-descending order. """ if array == sorted(array): return 0 n = len(array) # Check if reversing the whole array sorts it if array == sorted(array, reverse=True): return 1 ...
from solution import sum_of_min_operations, g def test_g(): assert g([1, 2, 3]) == 0 assert g([3, 2, 1]) == 1 assert g([3, 1, 2]) == 2 assert g([7, 1, 5]) == 2 assert g([4, 3, 2, 1]) == 1 assert g([10]) == 0 assert g([2, 3, 1, 5, 4]) == 2 def test_sum_of_min_operations(): assert sum_of...
[ { "docstring": "Calculate the minimum number of operations (reversals) needed to sort array in non-descending order.", "function_declaration": "def g(array):", "function_name": "g", "parameter_list": "(array)" }, { "docstring": "Calculate the sum of g(a) for m arrays.", "function_declara...
[ 0, 0, 0, 0, 0, 0, 0, 1, 0, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def count_min_operations(arr):\n \"\"\"\n Returns the minimum number of operations required to sort the array in non-descending order.\n \"\"\"\n ...
trial_gpt4o_7
{ "original_instruction": "", "prompt_id": "00006320", "row_id": 6320, "seed_ids": "[13254]" }
0.685799
Code_Contests_6320
I
[ "g", "sum_of_min_operations" ]
2
[ [ "sum_of_min_operations", "g" ] ]
1
[]
false
[]
false
pytest
true
[]
true
c68fb38b4e3719222df83c76c2d1036ef7bd5cc9
3d2b93e145848d565a74b293f75a4b5e9690fcf8
v1.0
instruct
Code_Contests
Code_Contests_6406_I
You are given an undirected graph with n vertices and m edges. Each edge has a non-negative weight. The goal is to find the shortest path from vertex 1 to vertex n. However, due to some constraints, you can reduce the weight of each edge by at most 1 unit. Given the graph, compute the length of the shortest path from...
import heapq def dijkstra_reduce_edges(graph, n): def dijkstra(source): dist = [float('inf')] * (n + 1) dist[source] = 0 pq = [(0, source)] while pq: current_dist, u = heapq.heappop(pq) if current_dist > dist[u]: continue...
from solution import shortest_path_with_reduction def test_shortest_path_example_1(): n, m = 4, 4 edges = [(1, 2, 2), (2, 3, 2), (3, 4, 2), (1, 4, 4)] assert shortest_path_with_reduction(n, m, edges) == 3 def test_shortest_path_example_2(): n, m = 4, 4 edges = [(1, 2, 1), (2, 3, 1), (3, 4, 1), (1,...
[ { "docstring": null, "function_declaration": "def dijkstra_reduce_edges(graph, n):", "function_name": "dijkstra_reduce_edges", "parameter_list": "(graph, n)" }, { "docstring": null, "function_declaration": "def shortest_path_with_reduction(n, m, edges):", "function_name": "shortest_p...
[ 0, 0, 0, 0, 0, 1, 0, 0, 0, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "import heapq\n\ndef dijkstra(graph, n, start):\n distances = [float('inf')] * (n + 1)\n distances[start] = 0\n pq = [(0, start)]\n while pq:\n ...
trial_gpt4o_5
{ "original_instruction": "", "prompt_id": "00006406", "row_id": 6406, "seed_ids": "[5019]" }
0.842191
Code_Contests_6406
I
[ "dijkstra_reduce_edges", "shortest_path_with_reduction" ]
2
[ [ "shortest_path_with_reduction", "dijkstra_reduce_edges" ] ]
1
[]
false
[]
false
pytest
true
[]
true
939ad9eebaa8a3519142955dbe25a2cf034d29d6
d0e0c5573d4943687973911bc4cd5bd0f8aa55b6
v1.0
instruct
Code_Contests
Code_Contests_6429_I
You are a participant in a coding competition organized by XYZ Inc. This time the challenge is about analyzing and classifying customer reviews based on their sentiment. The reviews can be categorized into three sentiments: positive, neutral, and negative. Each of these sentiments is represented by an integer: 1 for po...
import re from collections import defaultdict def load_training_data(): # This is a placeholder implementation to represent loading the training data. training_data = defaultdict(list) # Simulating loading data (you would replace this with actual file reading logic) training_data[1].append("Great ...
def test_classify_positive_review(): review_text = "Great product, very helpful!" assert classify_review(review_text) == 1 def test_classify_neutral_review(): review_text = "The product is okay, but could be improved." assert classify_review(review_text) == 2 def test_classify_negative_review(): r...
[ { "docstring": null, "function_declaration": "def load_training_data():", "function_name": "load_training_data", "parameter_list": "()" }, { "docstring": null, "function_declaration": "def classify_review(review_text):", "function_name": "classify_review", "parameter_list": "(rev...
[ 0, 0, 0, 0, 0, 1, 0, 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": "import os\nimport re\n\ndef classify_review(review_text):\n \"\"\"\n Classifies the sentiment of the review based on provided review text.\n Here,...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00006429", "row_id": 6429, "seed_ids": "[7115]" }
0.588338
Code_Contests_6429
I
[ "load_training_data", "classify_review" ]
2
[ [ "classify_review", "load_training_data" ] ]
1
[]
false
[]
false
pytest
false
[]
true
0028ace929b2912475f22c59097df25aa788f1f7
08c8ed4b8940ae5c36015bf89bb3ba34cdcc9f60
v1.0
instruct
Code_Contests
Code_Contests_6449_I
Ward loves prime numbers and he likes to play with arrays. Today, he got an array A of N positive integers. He wants to find the maximum difference between any two prime numbers in the array. If the array contains less than two prime numbers, print -1. Write a program that helps Ward find this maximum difference. Inp...
def is_prime(num): """ Checks if a number is a prime number. """ if num <= 1: return False for i in range(2, int(num ** 0.5) + 1): if num % i == 0: return False return True def max_prime_difference(array): """ Finds the maximum difference between any two prime numbers in...
from solution import process_test_cases def test_case_1(): T = 3 test_cases = [ (6, [8, 3, 15, 5, 14, 9]), (4, [4, 10, 6, 15]), (7, [2, 5, 11, 3, 17, 18, 19]) ] assert process_test_cases(T, test_cases) == [2, -1, 17] def test_case_no_primes(): T = 1 test_cases = [ ...
[ { "docstring": "Checks if a number is a prime number. ", "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": "Finds the maximum difference between any two prime numbers in the array. ", "function_declaration": "def max_pr...
[ 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 \"\"\" Checks if a number is a prime number. \"\"\"\n if num <= 1:\n return False\n for i in range(2, int(num ** 0.5) ...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00006449", "row_id": 6449, "seed_ids": "[11219]" }
0.741584
Code_Contests_6449
I
[ "is_prime", "max_prime_difference", "process_test_cases" ]
3
[ [ "max_prime_difference", "is_prime" ], [ "process_test_cases", "max_prime_difference" ] ]
2
[ "process_test_cases" ]
false
[]
false
pytest
true
[]
true
d3aba6890326a74b04e2ef13f1db55c3485d1582
a70d2356f83fc42a3843d626a8945436200b2e59
v1.0
instruct
Code_Contests
Code_Contests_6452_I
Marta has recently learned about the concept of prime numbers and is fascinated by them. Now, she wants to find out more about prime twins, a pair of prime numbers that differ by exactly 2 (for instance, 3 and 5, 11 and 13). Given an integer n, help Marta determine if there is at least one pair of prime twins (p, p+2)...
import math def is_prime(num): if num <= 1: return False if num <= 3: return True if num % 2 == 0 or num % 3 == 0: return False i = 5 while i * i <= num: if num % i == 0 or num % (i + 2) == 0: return False i += 6 return True def has_prime_twi...
from solution import has_prime_twins def test_example_case_1(): assert has_prime_twins(10) == "YES" def test_example_case_2(): assert has_prime_twins(14) == "YES" def test_example_case_3(): assert has_prime_twins(2) == "NO" def test_example_case_4(): assert has_prime_twins(17) == "YES" def test_pri...
[ { "docstring": null, "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": null, "function_declaration": "def has_prime_twins(n):", "function_name": "has_prime_twins", "parameter_list": "(n)" } ]
[ 1, 1 ]
2
easy
1
{ "trial_gpt4o_0": null, "trial_gpt4o_1": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared1_results_combined.jsonl", "solution_code": "import math\n\ndef is_prime(num):\n if num <= 1:\n return False\n if num <= 3:\n return True\n if num % 2 =...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00006452", "row_id": 6452, "seed_ids": "[6935]" }
0.690818
Code_Contests_6452
I
[ "is_prime", "has_prime_twins" ]
2
[ [ "has_prime_twins", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
8492f29b3d2d5a6140ea9f6751f8a3e2c37ac9f9
04a6c5ff5f12c325a329b430115a88411cbb8127
v1.0
instruct
Code_Contests
Code_Contests_6470_I
Kayla loves to collect gemstones. She has a collection of `n` gemstones, each having a unique integer identifier. She wants to reorganize her collection such that the sum of every two adjacent gemstones' identifiers is divisible by a given integer `k`. Your task is to determine if it's possible to rearrange the gemsto...
from itertools import permutations def can_rearrange_gemstones(n, k, gemstones): for perm in permutations(gemstones): is_valid = True for i in range(n - 1): if (perm[i] + perm[i + 1]) % k != 0: is_valid = False break if is_valid: retur...
from solution import can_rearrange_gemstones, gemstones_rearrangement def test_gemstones_rearrangement_possible_case_1(): assert gemstones_rearrangement(4, 5, [2, 3, 7, 8]) == ("YES", [2, 3, 7, 8]) def test_gemstones_rearrangement_impossible_case_2(): assert gemstones_rearrangement(3, 4, [1, 5, 6]) == "NO" d...
[ { "docstring": null, "function_declaration": "def can_rearrange_gemstones(n, k, gemstones):", "function_name": "can_rearrange_gemstones", "parameter_list": "(n, k, gemstones)" }, { "docstring": null, "function_declaration": "def gemstones_rearrangement(n, k, gemstones):", "function_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": "from itertools import permutations\n\ndef rearrange_gemstones(n, k, identifiers):\n \"\"\"\n Determine if it's possible to rearrange gemstones such t...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00006470", "row_id": 6470, "seed_ids": "[4225]" }
0.592495
Code_Contests_6470
I
[ "can_rearrange_gemstones", "gemstones_rearrangement" ]
2
[ [ "gemstones_rearrangement", "can_rearrange_gemstones" ] ]
1
[]
false
[]
false
pytest
true
[]
true
ac4943a9f390a26fb9aad3d4caf13db8582411a0
a6805d816690e9dd91f86ebc62038878864c13a4
v1.0
instruct
Code_Contests
Code_Contests_6481_I
A company has developed a unique ranking system called x-rank. An array with n elements is considered x-ranked if the following conditions are met: 1. For every even index i (0-based), the element should be the maximum of the remaining elements after previous selections. 2. For every odd index i (0-based), the element...
def x_rank(arr): """ This function takes a list of integers and returns an x-ranked list or "Impossible" if the list cannot be transformed into an x-ranked list. """ n = len(arr) # Sort the array to pick max and min easily arr_sorted = sorted(arr) # Create list to hold x-ranked ele...
from solution import can_be_x_ranked def test_example1(): assert can_be_x_ranked(5, [5, 3, 1, 4, 2]) == "5 1 4 2 3" def test_example2(): assert can_be_x_ranked(4, [4, 2, 3, 1]) == "4 1 3 2" def test_single_element(): assert can_be_x_ranked(1, [7]) == "7" def test_two_elements(): assert can_be_x_rank...
[ { "docstring": "This function takes a list of integers and returns an x-ranked list or \"Impossible\" \nif the list cannot be transformed into an x-ranked list.", "function_declaration": "def x_rank(arr):", "function_name": "x_rank", "parameter_list": "(arr)" }, { "docstring": "Returns the x...
[ 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 x_rank(n, a):\n \"\"\"\n Determines if an array can be transformed into an x-ranked array.\n \n Parameters:\n n (int): The number of...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00006481", "row_id": 6481, "seed_ids": "[3179]" }
0.644013
Code_Contests_6481
I
[ "x_rank", "can_be_x_ranked" ]
2
[ [ "can_be_x_ranked", "x_rank" ] ]
1
[]
false
[]
false
pytest
true
[]
true
b21b301a0540d5d0e432576fcf03d5969075fda2
7b93fdf9173b0f23db9db77c4d7cfd3d10f22d8c
v1.0
instruct
Code_Contests
Code_Contests_6491_I
In the secluded village of Omijima, there is a unique tradition where villagers celebrate festivals by lighting lanterns and sending them down the river. Each lantern can hold a specific range of weights, and if overloaded, the lantern will sink, causing disappointment among villagers. Each festival has multiple lante...
def check_lanterns(datasets): """ This function determines whether each lantern will float or sink. Parameters: datasets (list of list): Each list is a dataset that contains integers representing the weight limit, number of items, and weights of the items ...
from solution import assess_lanterns def test_single_lantern_sink(): input_data = "1\n100 3 30 40 40\n0\n" result = assess_lanterns(input_data) assert result == ["SINK"] def test_single_lantern_float(): input_data = "1\n100 3 30 40 20\n0\n" result = assess_lanterns(input_data) assert result ==...
[ { "docstring": "This function determines whether each lantern will float or sink.\n\nParameters:\ndatasets (list of list): Each list is a dataset that contains integers representing \n the weight limit, number of items, and weights of the items \n for each lantern...
[ 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 lantern_status(data):\n results = []\n\n i = 0\n while i < len(data):\n n = data[i]\n if n == 0:\n break\n i +...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00006491", "row_id": 6491, "seed_ids": "[1446]" }
0.581276
Code_Contests_6491
I
[ "check_lanterns", "process_input", "assess_lanterns" ]
3
[ [ "assess_lanterns", "check_lanterns" ], [ "assess_lanterns", "process_input" ] ]
2
[ "process_input" ]
false
[]
false
pytest
true
[]
true
c1db2bfda6b7be390cdc5c31ca619c8259b5b80f
a9cd41a907426645d4c10abfc82539eaddbb8cf5
v1.0
instruct
Code_Contests
Code_Contests_6523_I
A city's water distribution system consists of various tanks connected by pipes. Each tank can send water to other tanks, and each pipe has a maximum capacity of water it can carry per hour. The city needs to determine the maximum amount of water that can be sent from the main source tank to the main destination tank p...
from collections import defaultdict, deque def bfs(capacity, source, sink, parent): visited = [False] * len(capacity) queue = deque([source]) visited[source] = True while queue: u = queue.popleft() for ind, val in enumerate(capacity[u]): if visited[ind] == Fals...
def test_max_water_flow_ex1(): assert max_water_flow(4, 5, [ (1, 2, 10), (1, 3, 5), (2, 3, 15), (2, 4, 10), (3, 4, 10) ]) == 15 def test_max_water_flow_ex2(): assert max_water_flow(4, 2, [ (1, 2, 100), (3, 4, 100) ]) == 0 def test_max_water_flow_...
[ { "docstring": null, "function_declaration": "def bfs(capacity, source, sink, parent):", "function_name": "bfs", "parameter_list": "(capacity, source, sink, parent)" }, { "docstring": null, "function_declaration": "def edmonds_karp(n, adj_matrix, source, sink):", "function_name": "ed...
[ 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 defaultdict, deque\n\ndef bfs_capacity(graph, source, sink, parent):\n visited = set()\n queue = deque([source])\n visited...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00006523", "row_id": 6523, "seed_ids": "[5475]" }
0.66804
Code_Contests_6523
I
[ "bfs", "edmonds_karp", "max_water_flow" ]
3
[ [ "edmonds_karp", "bfs" ], [ "max_water_flow", "edmonds_karp" ] ]
2
[]
false
[]
false
pytest
false
[]
true
8e13a4f00053f0fd7fe75010fac68aa0151e9bec
f863bed4fbef7929d82b235ceee91e78fc87a5d6
v1.0
instruct
Code_Contests
Code_Contests_6542_I
Problem Description Jane has recently started discovering the world of cryptography and is fascinated by simple encryption techniques. She challenges herself by creating and deciphering ciphers using basic letter shifts. One of her favorite techniques is the Caesar Cipher, where each letter in the plaintext is shifted...
def caesar_cipher(t, cases): results = [] for case in cases: s, k = case encrypted = [] for char in s: new_char = chr(((ord(char) - ord('a') + k) % 26) + ord('a')) encrypted.append(new_char) results.append(''.join(encrypted)) return results def parse_...
import pytest from solution import caesar_cipher, run_caesar_cipher def test_single_case(): input_str = "1\nhello 3" expected_output = "khoor" assert run_caesar_cipher(input_str) == expected_output def test_multiple_cases(): input_str = "2\nhello 3\nxyz 2" expected_output = "khoor\nzab" assert...
[ { "docstring": null, "function_declaration": "def caesar_cipher(t, cases):", "function_name": "caesar_cipher", "parameter_list": "(t, cases)" }, { "docstring": null, "function_declaration": "def parse_input(input_str):", "function_name": "parse_input", "parameter_list": "(input_s...
[ 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 caesar_cipher(test_cases):\n results = []\n for s, k in test_cases:\n encrypted_string = ''\n for char in s:\n new_char ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00006542", "row_id": 6542, "seed_ids": "[13228]" }
0.618674
Code_Contests_6542
I
[ "caesar_cipher", "parse_input", "run_caesar_cipher" ]
3
[ [ "run_caesar_cipher", "caesar_cipher" ], [ "run_caesar_cipher", "parse_input" ] ]
2
[ "parse_input" ]
false
[]
false
pytest
true
[]
true
289d0e1309a8194b7735dcbbdc7a8844a4078889
e5ad5e124bd9c5411b73fcbe3404906b5dad7b55
v1.0
instruct
Code_Contests
Code_Contests_6634_I
Flora is working on a construction project where she needs to build a network of bridges between several islands. Each island is represented as a node, and a bridge is represented as an edge between two nodes. However, the project has certain constraints and requirements: 1. Each island must be connected directly or i...
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] ...
import pytest from solution import solve_bridge_networks def test_case_1(): test_cases = [(4, 6, [(1, 2, 1), (1, 3, 4), (2, 3, 2), (2, 4, 3), (3, 4, 5), (1, 4, 4)])] results = solve_bridge_networks(test_cases) assert results == [6] def test_case_2(): test_cases = [(3, 3, [(1, 2, 5), (2, 3, 6), (1, 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)" }, ...
[ 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": "class UnionFind:\n def __init__(self, size):\n self.parent = list(range(size))\n self.rank = [0] * size\n\n def find(self, u):\n ...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00006634", "row_id": 6634, "seed_ids": "[10987]" }
0.769471
Code_Contests_6634
I
[ "find", "union", "minimum_cost_to_connect_islands", "solve_bridge_networks" ]
4
[ [ "minimum_cost_to_connect_islands", "find" ], [ "minimum_cost_to_connect_islands", "union" ], [ "solve_bridge_networks", "minimum_cost_to_connect_islands" ], [ "union", "find" ] ]
4
[]
false
[]
false
pytest
true
[]
true
b7d047338866bad0b9e9ea2f9bcfe474c4881fc6
0b382615254f4116837dcfd7a238d4bd6fd06539
v1.0
instruct
Code_Contests
Code_Contests_6662_I
You are given a binary tree, where each node has two potential children and each node contains a unique integer value. A leaf node is a node that does not have any children. Your task is to find the longest path in the tree where the values along the path form a strictly increasing sequence. Input The first line con...
class TreeNode: def __init__(self, value=0): self.value = value self.left = None self.right = None def build_tree(nodes): if not nodes: return None tree_nodes = {} for value, left, right in nodes: if value not in tree_nodes: tree_nodes[value] = T...
from solution import longest_path_in_binary_tree def test_example_1(): n = 5 nodes = [ (4, 2, 5), (2, -1, -1), (5, 3, -1), (3, -1, -1), (1, -1, -1) ] assert longest_path_in_binary_tree(n, nodes) == 2 def test_example_2(): n = 7 nodes = [ (8, 3, 1...
[]
[ 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": "class TreeNode:\n def __init__(self, value):\n self.value = value\n self.left = None\n self.right = None\n\ndef build_tree(nodes):\...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00006662", "row_id": 6662, "seed_ids": "[10141]" }
0.6217
Code_Contests_6662
I
[ "build_tree", "longest_increasing_path", "longest_path_in_binary_tree" ]
3
[ [ "longest_path_in_binary_tree", "build_tree" ], [ "longest_path_in_binary_tree", "longest_increasing_path" ] ]
2
[]
false
[ "TreeNode" ]
true
pytest
true
[]
true
a84c0644de7da1632f4aaf13f6d6c7dc0dcbb81b
bebcaba819ff4215c04c3656ff3be8d7bc58da35
v1.0
instruct
Code_Contests
Code_Contests_6679_I
In Byteland, the King's castle is hosting a royal event and there is a special magical podium for the event. The podium has a special property: it can show different colors based on the arrangement of magical stones placed in it. There are N magical stones, each stone is unique and has a specific color. The King wants ...
MOD = 1000000007 def factorial_mod(n, mod): fact = 1 for i in range(2, n + 1): fact = (fact * i) % mod return fact def count_arrangements(cases): results = [] for n in cases: results.append(factorial_mod(n, MOD)) return results # Reading input from a hypothetical input functio...
from solution import count_arrangements, factorial_mod def test_factorial_mod(): assert factorial_mod(3, 1000000007) == 6 assert factorial_mod(4, 1000000007) == 24 assert factorial_mod(10, 1000000007) == 3628800 def test_count_arrangements(): assert count_arrangements([3, 4]) == [6, 24] assert cou...
[ { "docstring": null, "function_declaration": "def factorial_mod(n, mod):", "function_name": "factorial_mod", "parameter_list": "(n, mod)" }, { "docstring": null, "function_declaration": "def count_arrangements(cases):", "function_name": "count_arrangements", "parameter_list": "(c...
[ 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": "MOD = 1000000007\n\ndef factorial_mod(n, mod):\n \"\"\"\n Returns the factorial of n modulo mod.\n \"\"\"\n result = 1\n for i in range(2, n...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00006679", "row_id": 6679, "seed_ids": "[1151]" }
0.672507
Code_Contests_6679
I
[ "factorial_mod", "count_arrangements", "process_input", "main" ]
4
[ [ "count_arrangements", "factorial_mod" ] ]
1
[ "process_input" ]
false
[]
false
pytest
true
[]
true
1a0af7726cf0d5794b0441d912658fec4ccdf32e
c29d316b96209bbce4662ab151fe19459ffcecf0
v1.0
instruct
Code_Contests
Code_Contests_6729_I
You are given a sequence of tasks that must be scheduled on a single machine. Each task has a start time, end time, and a profit associated with it. You need to find the maximum profit that can be obtained by scheduling a subset of non-overlapping tasks. A task can only be executed if no other task is running during i...
from bisect import bisect_right def max_profit(tasks): """ Args: tasks (List[Tuple[int, int, int]]): List of tuples where each tuple contains (start, end, profit) Returns: int: Maximum profit obtainable by scheduling non-overlapping tasks. """ # Sort tasks by end time tasks.sort(key=la...
from solution import max_profit_scheduler def test_example(): assert max_profit_scheduler(4, ["1 3 500", "3 5 300", "0 6 600", "4 7 200"]) == 800 def test_non_overlapping_tasks(): assert max_profit_scheduler(3, ["1 2 100", "3 4 200", "5 6 300"]) == 600 def test_overlapping_tasks(): assert max_profit_sche...
[ { "docstring": "Args:\ntasks (List[Tuple[int, int, int]]): List of tuples where each tuple contains (start, end, profit)\n\nReturns:\nint: Maximum profit obtainable by scheduling non-overlapping tasks.", "function_declaration": "def max_profit(tasks):", "function_name": "max_profit", "parameter_list...
[ 0, 0, 0, 0, 0, 1, 0, 0, 1, 0 ]
2
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def max_profit(tasks):\n from bisect import bisect_right\n\n # Sort tasks by their end time\n tasks.sort(key=lambda x: x[1])\n\n # End times to...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00006729", "row_id": 6729, "seed_ids": "[2907]" }
0.663966
Code_Contests_6729
I
[ "max_profit", "max_profit_scheduler" ]
2
[ [ "max_profit_scheduler", "max_profit" ] ]
1
[]
false
[]
false
pytest
true
[]
true
78a7bd68f2f2c52855c66f149526a9fb98ac0a49
42ced0bee294a518adf63b78ca6ee6598f85e346
v1.0
instruct
Code_Contests
Code_Contests_6739_I
Bob and Alice are playing a game with a sequence of numbers. The game consists of n integers arranged in a sequence. Bob and Alice take turns, with Bob going first. In each turn, the player must choose a non-empty subsequence of consecutive numbers from the sequence such that the sum of the chosen subsequence is a prim...
def is_prime(num): """ Checks if the given 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 Fa...
import pytest from solution import main, is_prime, can_choose_prime_subsequence, game_winner def test_is_prime(): assert is_prime(2) == True assert is_prime(3) == True assert is_prime(4) == False assert is_prime(5) == True def test_can_choose_prime_subsequence(): assert can_choose_prime_subsequenc...
[ { "docstring": "Checks if the given number is a prime number.", "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": "Determines if there's any non-empty subsequence with a prime sum.", "function_declaration": "def can_cho...
[ 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(num):\n \"\"\" Helper function to check if a number is prime \"\"\"\n if num <= 1:\n return False\n if num <= 3:\n retu...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00006739", "row_id": 6739, "seed_ids": "[4817]" }
0.76112
Code_Contests_6739
I
[ "is_prime", "can_choose_prime_subsequence", "game_winner", "main" ]
4
[ [ "can_choose_prime_subsequence", "is_prime" ], [ "game_winner", "can_choose_prime_subsequence" ] ]
2
[]
false
[]
false
pytest
true
[]
true
ae4ae0cc38afd9f51095dcee33fd6b20211f6021
3e6b867b8273cb3e19a721008ff424c9c76bdd19
v1.0
instruct
Code_Contests
Code_Contests_6793_I
You are given a positive integer `n` and an array of `n` integers. Your task is to find the minimum number of steps required to make the array "beautiful". An array is considered beautiful if it satisfies this property: in at least one position `i` (1 ≤ i ≤ n), the number of elements before position `i` only contains e...
def min_steps_to_make_beautiful(n, array): # To find minimum number of moves the idea is to find the length of the longest increasing subsequence # Since this subsequence already meets the criteria of being beautiful after sorting. if n <= 1: return 0 # Calculate Longest Increasing Sub...
from solution import min_steps_to_make_beautiful def test_min_steps_example1(): assert min_steps_to_make_beautiful(6, [1, 5, 3, 4, 2, 6]) == 2 def test_min_steps_example2(): assert min_steps_to_make_beautiful(4, [2, 3, 1, 4]) == 1 def test_min_steps_no_moves_needed(): assert min_steps_to_make_beautiful(4...
[ { "docstring": null, "function_declaration": "def min_steps_to_make_beautiful(n, array):", "function_name": "min_steps_to_make_beautiful", "parameter_list": "(n, array)" }, { "docstring": null, "function_declaration": "def binary_search(lis, num):", "function_name": "binary_search", ...
[ 0, 0, 0, 1, 0 ]
1
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def find_min_steps_to_beautiful(n, array):\n \"\"\"\n This function finds the minimum number of steps required to make the array beautiful.\n \"\"...
trial_gpt4o_3
{ "original_instruction": "", "prompt_id": "00006793", "row_id": 6793, "seed_ids": "[5638]" }
0.715459
Code_Contests_6793
I
[ "min_steps_to_make_beautiful", "binary_search" ]
2
[ [ "min_steps_to_make_beautiful", "binary_search" ] ]
1
[]
false
[]
false
pytest
true
[]
true
bd8279b838a2de0c2cc9ad56487cd8bbec533a7b
d071c81a2693816fafeca624c187f5d7467a500c
v1.0
instruct
Code_Contests
Code_Contests_6853_I
A famous restaurant has decided to optimize their menu for faster preparation times. To achieve this, they have categorized their ingredients into two types - A and B. Ingredient A requires less time to prepare compared to ingredient B. To balance the menu and reduce waiting times, the restaurant wants to find out if i...
def is_balanced(dish): """ Determines if a dish is balanced, meaning it contains an equal number of 'A' and 'B' letters. :param dish: A string representing the dish description. :return: 'YES' if the dish is balanced, 'NO' otherwise. """ count_A = dish.count('A') count_B = dish.count('B...
from solution import is_balanced, balance_dishes def test_is_balanced(): assert is_balanced("ABABA") == "NO" assert is_balanced("AABB") == "YES" assert is_balanced("ABBAAB") == "YES" assert is_balanced("A") == "NO" assert is_balanced("BBAA") == "YES" assert is_balanced("") == "YES" # Simplest ...
[ { "docstring": "Determines if a dish is balanced, meaning it contains an equal number of 'A' and 'B' letters.\n\n:param dish: A string representing the dish description.\n:return: 'YES' if the dish is balanced, 'NO' otherwise.", "function_declaration": "def is_balanced(dish):", "function_name": "is_bala...
[ 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 balanced_dish(dishes):\n \"\"\"\n For each dish description in dishes, determine if it contains an equal number of 'A' and 'B'.\n \n Params...
trial_gpt4o_3
{ "original_instruction": "", "prompt_id": "00006853", "row_id": 6853, "seed_ids": "[8298]" }
0.681436
Code_Contests_6853
I
[ "is_balanced", "balance_dishes" ]
2
[ [ "balance_dishes", "is_balanced" ] ]
1
[]
false
[]
false
pytest
true
[]
true
9b2eeb457aabb6a53c935843962f22a6c722b6d4
343a7bc9b8fcce731c10b86459b80d6236637b34
v1.0
instruct
Code_Contests
Code_Contests_6854_I
A magical forest is represented by a grid with n rows and m columns. Each cell in the grid contains a certain number of magical energy points, which are represented by positive integers. Your task is to collect as many energy points as possible by starting from the top-left cell (1, 1), and always moving to the right o...
def max_energy_points(n, m, grid): """ Returns the maximum number of magical energy points that can be collected from top-left to bottom-right. :param n: Number of rows in the grid :param m: Number of columns in the grid :param grid: 2D list representing the grid with magical energy points ...
from solution import max_energy_points def test_max_energy_points_example(): n = 3 m = 3 grid = [ [1, 3, 1], [1, 5, 1], [4, 2, 1] ] assert max_energy_points(n, m, grid) == 12 def test_max_energy_points_single_cell(): n = 1 m = 1 grid = [ [5] ] as...
[ { "docstring": "Returns the maximum number of magical energy points that can be collected from top-left to bottom-right.\n\n:param n: Number of rows in the grid\n:param m: Number of columns in the grid\n:param grid: 2D list representing the grid with magical energy points\n:return: Maximum number of energy poin...
[ 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 max_energy_points(n, m, grid):\n \"\"\"\n Calculates the maximum number of magical energy points you can collect\n by starting from the top-le...
trial_gpt4o_4
{ "original_instruction": "", "prompt_id": "00006854", "row_id": 6854, "seed_ids": "[7416]" }
0.679668
Code_Contests_6854
I
[ "max_energy_points", "run_max_energy_points" ]
2
[ [ "run_max_energy_points", "max_energy_points" ] ]
1
[]
false
[]
false
pytest
true
[]
true
fe83fa587f57fce225bf056206be065a04252451
508ed75492b3340729a301784b799b0b2b339ba2
v1.0
instruct
Code_Contests
Code_Contests_6869_I
Permutation Sum Checker You are asked to determine if there exists a permutation of an integer array `nums` such that the sum of every consecutive pair of integers in the permutation is prime. A prime number is a natural number greater than 1 that is not a product of two smaller natural numbers. The smallest prime nu...
import itertools def is_prime(num): """ Check if a number is prime. """ if num <= 1: return False if num == 2: return True if num % 2 == 0: return False for i in range(3, int(num**0.5) + 1, 2): if num % i == 0: return False return True def ha...
from solution import is_prime, has_prime_pair_sum_permutation, permutation_sum_checker 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_has_prime_pair_sum_permutation(): asse...
[ { "docstring": "Check if a number is prime.", "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": "Check if there exists a permutation of nums such that the sum of \nevery consecutive pair is prime.", "function_declaratio...
[ 0, 0, 0, 1, 1 ]
2
medium
0.4
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "from itertools import permutations\n\ndef is_prime(n):\n \"\"\"\n Checks if a number is prime.\n \"\"\"\n if n <= 1:\n return False\n ...
trial_gpt4o_3
{ "original_instruction": "", "prompt_id": "00006869", "row_id": 6869, "seed_ids": "[8633]" }
0.65599
Code_Contests_6869
I
[ "is_prime", "has_prime_pair_sum_permutation", "permutation_sum_checker" ]
3
[ [ "has_prime_pair_sum_permutation", "is_prime" ], [ "permutation_sum_checker", "has_prime_pair_sum_permutation" ] ]
2
[]
false
[]
false
pytest
true
[]
true
f749451e11f5d911bb9aeddfa94f82ac81139efa
2a7028ca5fe47432f9393ae0d09a66d37a4a678f
v1.0
instruct
Code_Contests
Code_Contests_6873_I
The National Weather Service is developing a system to monitor weather conditions across multiple cities using a network of weather stations. Each city can have one or more weather stations, and data needs to be transmitted between stations to keep all cities updated about real-time weather conditions. To ensure effic...
import heapq from collections import defaultdict, deque def parse_input(): import sys input = sys.stdin.read data = input().split() idx = 0 n = int(data[idx]) idx += 1 city_info = {} stations_count = {} for _ in range(n): city_name = data[idx] mi = int...
def test_weather_data_system(): from io import StringIO import sys input_data = """4 alpha 3 bravo 2 charlie 1 delta 2 6 alpha 1 alpha 0 5 alpha 2 alpha 0 3 alpha 0 bravo 1 4 bravo 1 bravo 0 2 bravo 0 charlie 0 6 delta 0 delta 1 1 2 alpha 2 delta 0""" ...
[ { "docstring": null, "function_declaration": "def parse_input():", "function_name": "parse_input", "parameter_list": "()" }, { "docstring": null, "function_declaration": "def build_graph(edges):", "function_name": "build_graph", "parameter_list": "(edges)" }, { "docstring...
[ 0, 0, 0, 1, 0 ]
1
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "import heapq\n\ndef dijkstra(edges, start, num_stations):\n graph = {}\n for s_city, s_station, d_city, d_station, cost in edges:\n if (s_city...
trial_gpt4o_3
{ "original_instruction": "", "prompt_id": "00006873", "row_id": 6873, "seed_ids": "[8112]" }
0.619251
Code_Contests_6873
I
[ "parse_input", "build_graph", "dijkstra", "solve", "weather_data_system" ]
5
[ [ "solve", "build_graph" ], [ "solve", "dijkstra" ], [ "weather_data_system", "parse_input" ], [ "weather_data_system", "solve" ] ]
4
[ "parse_input" ]
false
[]
false
pytest
true
[]
true
e8f1f0d00e6db92694a8c89d49b727a71eac2057
e029fb79bd2deb92953d7e883227aa2edac265c9
v1.0
instruct
Code_Contests
Code_Contests_6966_I
Arman is learning about number sequences and he is fascinated by sequences whose elements are perfect squares. A sequence is considered to be composed of perfect squares if every element in it is a perfect square integer (i.e., 1, 4, 9, 16, etc.). Arman has a list of sequences and he wants your help to identify whethe...
import math def is_perfect_square(n): """Check if a number is a perfect square.""" return math.isqrt(n) ** 2 == n def sequence_product_or_not_all_perfect_squares(sequences): """ Given a list of sequences, return the product of all elements in the sequence if all elements are perfect squares, other...
def test_is_perfect_square(): assert is_perfect_square(1) == True assert is_perfect_square(4) == True assert is_perfect_square(9) == True assert is_perfect_square(10) == False assert is_perfect_square(15) == False def test_sequence_product_all_perfect_squares(): assert sequence_product_or_not_a...
[ { "docstring": "Check if a number is a perfect square.", "function_declaration": "def is_perfect_square(n):", "function_name": "is_perfect_square", "parameter_list": "(n)" }, { "docstring": "Given a list of sequences, return the product of all elements in the sequence\nif all elements are pe...
[ 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 math\n\ndef is_perfect_square(n):\n \"\"\"\n Checks if a number is a perfect square.\n \"\"\"\n root = int(math.sqrt(n))\n return n =...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00006966", "row_id": 6966, "seed_ids": "[12049]" }
0.651732
Code_Contests_6966
I
[ "is_perfect_square", "sequence_product_or_not_all_perfect_squares" ]
2
[ [ "sequence_product_or_not_all_perfect_squares", "is_perfect_square" ] ]
1
[]
false
[]
false
pytest
false
[]
true
74f1e6e40743f8a0c6cd8efe257f6b840ae50acd
fabfdda077eeb6901f09b3525fef01e2384de948
v1.0
instruct
Code_Contests
Code_Contests_6982_I
Problem Statement Cubical Island is known for its unique formation: it consists of a series of cuboids, each with their lower corners on the $xy$-plane and their upper corners extending upwards along the $z$-axis. The cuboids' edges are parallel to the coordinate axes. The Queen of Cubical Island plans to build the l...
def largest_box(dimensions): """ Given the dimensions of multiple cuboids, find the dimensions of the largest box that can fit within their union. """ # Initialize the boundaries for the union of cuboids min_x, min_y, min_z = float('inf'), float('inf'), float('inf') max_x, max_y, max_z = float('...
from solution import process def test_sample_input(): input_str = """3 0 0 4 4 5 2 2 6 6 3 4 4 8 8 2 2 0 0 3 3 7 2 2 5 5 4 0""" expected_output = """8.0000 8.0000 5.0000 5.0000 5.0000 7.0000""" assert process(input_str) == expected_output def test_single_cuboid(): input_str = """1 -3 -3 3 3 6 0""" ...
[ { "docstring": "Given the dimensions of multiple cuboids, find the dimensions of the largest box that can fit within their union.", "function_declaration": "def largest_box(dimensions):", "function_name": "largest_box", "parameter_list": "(dimensions)" }, { "docstring": "Parse the input stri...
[ 0, 0, 0, 0, 0, 0, 1, 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 max_box_dimensions(datasets):\n results = []\n for cubes in datasets:\n if len(cubes) == 0:\n continue\n\n # Initialize ...
trial_gpt4o_7
{ "original_instruction": "", "prompt_id": "00006982", "row_id": 6982, "seed_ids": "[8845]" }
0.653376
Code_Contests_6982
I
[ "largest_box", "parse_input", "format_output", "process" ]
4
[ [ "process", "format_output" ], [ "process", "largest_box" ], [ "process", "parse_input" ] ]
3
[ "parse_input", "format_output" ]
false
[]
false
pytest
true
[]
true
72b532167b449e00b10429cb579d6734738fba97
a9dfa5d6cf987bd9ebb3cbcac066065d66238c77
v1.0
instruct
Code_Contests
Code_Contests_7026_I
Input 6 B WB BWB WWB BWWB WBWB Output 14
def count_B_W_pairs(strings): """ Given a list of strings, this function counts the number of times 'B' is followed by 'W'. """ total_count = 0 for s in strings: total_count += s.count('BW') return total_count def input_handler(n, strings): """ Handles the input and calls th...
from solution import count_B_W_pairs, input_handler def test_count_B_W_pairs(): assert count_B_W_pairs(["B"]) == 0 assert count_B_W_pairs(["WB"]) == 0 assert count_B_W_pairs(["BWB"]) == 1 assert count_B_W_pairs(["WWB"]) == 0 assert count_B_W_pairs(["BWWB"]) == 1 assert count_B_W_pairs(["WBWB"])...
[ { "docstring": "Given a list of strings, this function counts the number of times 'B' is\nfollowed by 'W'.", "function_declaration": "def count_B_W_pairs(strings):", "function_name": "count_B_W_pairs", "parameter_list": "(strings)" }, { "docstring": "Handles the input and calls the appropria...
[ 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": "def calculate_positions_sum(n, strings):\n total_sum = 0\n for string in strings:\n for idx, char in enumerate(string):\n if char =...
trial_gpt4o_6
{ "original_instruction": "", "prompt_id": "00007026", "row_id": 7026, "seed_ids": "[10507]" }
0.406672
Code_Contests_7026
I
[ "count_B_W_pairs", "input_handler" ]
2
[ [ "input_handler", "count_B_W_pairs" ] ]
1
[]
false
[]
false
pytest
true
[]
true
56657dd01e680e6afec9f3365be98f294e1a2dbd
7bb8980544de00942d17bcb7f0969ec5ada4d5f3
v1.0
instruct
Code_Contests
Code_Contests_7050_I
You are given a tree with n nodes, rooted at node 1. Each node has a value associated with it. We need to perform q operations on this tree. In each operation, you will be given a node, and you have to report the maximum value among all nodes in the subtree rooted at that node or the minimum value among them. Input T...
from collections import defaultdict def dfs(node, parent, values, adj, max_value, min_value): curr_max = values[node - 1] curr_min = values[node - 1] for neighbor in adj[node]: if neighbor == parent: continue max_sub, min_sub = dfs(neighbor, node, values, adj, max_value, min_val...
from solution import query_tree def test_example_1(): n = 5 q = 3 values = [1, 2, 3, 4, 5] edges = [(1, 2), (1, 3), (1, 4), (1, 5)] queries = [(1, 1), (2, 2), (1, 3)] result = query_tree(n, q, values, edges, queries) expected = [5, 2, 3] assert result == expected def test_example_2(): ...
[ { "docstring": null, "function_declaration": "def dfs(node, parent, values, adj, max_value, min_value):", "function_name": "dfs", "parameter_list": "(node, parent, values, adj, max_value, min_value)" }, { "docstring": null, "function_declaration": "def query_tree(n, q, values, edges, que...
[ 0, 0, 0, 1, 1 ]
2
medium
0.4
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "from collections import defaultdict\nfrom sys import setrecursionlimit, stdin\nimport sys\nsys.setrecursionlimit(100010)\n\nclass TreeNode:\n def __init...
trial_gpt4o_4
{ "original_instruction": "", "prompt_id": "00007050", "row_id": 7050, "seed_ids": "[2321]" }
0.691888
Code_Contests_7050
I
[ "dfs", "query_tree" ]
2
[ [ "query_tree", "dfs" ] ]
1
[]
false
[]
false
pytest
true
[]
true
4771d447970665317535a535bcbd28273bdc9b7a
23d5dc46083834a67b898e62a705bd985f10f9fd
v1.0
instruct
Code_Contests
Code_Contests_7089_I
Imagine you are given two arrays of integers, `A` and `B`, both of length `n`. We call these arrays **balanceable** if it is possible to select some non-empty subarray from `A` and move it to any position in `B` (including the start or end) such that after this operation, the sum of the elements of the arrays `A` and `...
def are_balanceable(A, B): """ Determines if arrays A and B are balanceable. """ total_A = sum(A) total_B = sum(B) if total_A == total_B: return "YES" difference = total_A - total_B if abs(difference) % 2 != 0: return "NO" target = abs(difference) ...
from solution import are_balanceable def test_example_1(): assert are_balanceable([1, 2, 3, 4], [4, 1, 2, 3]) == "YES" def test_example_2(): assert are_balanceable([1, 2, 3], [6, 0, 1]) == "NO" def test_same_sum(): assert are_balanceable([1, 2, 3], [1, 2, 3]) == "YES" def test_no_balance_possible(): ...
[ { "docstring": "Determines if arrays A and B are balanceable.", "function_declaration": "def are_balanceable(A, B):", "function_name": "are_balanceable", "parameter_list": "(A, B)" }, { "docstring": "Returns whether there exists a prefix sum equal to target.", "function_declaration": "de...
[ 0, 0, 0, 0, 0, 0, 0, 1, 0, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def are_arrays_balanceable(n, A, B):\n sum_A = sum(A)\n sum_B = sum(B)\n \n # Find the difference in sums\n difference = abs(sum_A - sum_B)\...
trial_gpt4o_7
{ "original_instruction": "", "prompt_id": "00007089", "row_id": 7089, "seed_ids": "[10254]" }
0.685289
Code_Contests_7089
I
[ "are_balanceable", "prefix_sums_of_size" ]
2
[ [ "are_balanceable", "prefix_sums_of_size" ] ]
1
[]
false
[]
false
pytest
true
[]
true
6a765d4131c1a4b09b8cbce12236f7052eb066a1
ef3d4e53a5bfc37f260d3cc2e0b1164d46a16c1c
v1.0
instruct
Code_Contests
Code_Contests_7100_I
Given a grid of size NxM filled with letters and a list of words, write a program to find all words in the list that can be formed by tracing a path in the grid. A valid path can start from any cell and move in any of the 8 possible directions (up, down, left, right, or diagonally), but you cannot visit the same cell m...
def find_word_in_grid(grid, word, x, y, visited): if not word: return True if ( x < 0 or x >= len(grid) or y < 0 or y >= len(grid[0]) or visited[x][y] or grid[x][y] != word[0] ): return False visited[x][y] = True word = word[1:] # 8 possible dir...
from solution import find_words_in_grid def test_example_case(): N = 4 M = 4 grid = [ "ABCD", "EFGH", "IJKL", "MNOP" ] words = ["BEFI", "CFIM", "ABCDJ"] expected = ["YES", "YES", "NO"] assert find_words_in_grid(N, M, grid, words) == expected def test_single_...
[ { "docstring": null, "function_declaration": "def find_word_in_grid(grid, word, x, y, visited):", "function_name": "find_word_in_grid", "parameter_list": "(grid, word, x, y, visited)" }, { "docstring": null, "function_declaration": "def word_exists(grid, word):", "function_name": "wo...
[ 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_valid(x, y, N, M):\n return 0 <= x < N and 0 <= y < M\n\ndef dfs(grid, word, idx, x, y, visited):\n if idx == len(word):\n return True\...
trial_gpt4o_4
{ "original_instruction": "", "prompt_id": "00007100", "row_id": 7100, "seed_ids": "[8318]" }
0.767042
Code_Contests_7100
I
[ "find_word_in_grid", "word_exists", "find_words_in_grid" ]
3
[ [ "find_words_in_grid", "word_exists" ], [ "word_exists", "find_word_in_grid" ] ]
2
[]
false
[]
false
pytest
true
[]
true
8dca07540e7d915708bf3480a2167ff32fdf5ec6
48f2c36fcca5d584f1170052bf564c7f6a46931b
v1.0
instruct
Code_Contests
Code_Contests_7109_I
Problem statement You are given a rectangular field with dimensions N (height) and M (width). The field is covered with rectangular patches of grass, each of size 1x1. Some patches have flowers on them, while others do not. A flower on a patch is represented by "1", and no flower is represented by "0". Your task is to...
def maximalRectangle(matrix): if not matrix: return 0 max_area = 0 N, M = len(matrix), len(matrix[0]) heights = [0] * (M + 1) for i in range(N): for j in range(M): if matrix[i][j] == 1: heights[j] += 1 else: heights[j] = 0 ...
from solution import largest_rectangle_area def test_case_1(): N = 4 M = 5 field = [ [1, 0, 1, 0, 0], [1, 0, 1, 1, 1], [1, 1, 1, 1, 1], [1, 0, 0, 1, 0] ] assert largest_rectangle_area(N, M, field) == 6 def test_case_2(): N = 3 M = 4 field = [ [0,...
[ { "docstring": null, "function_declaration": "def maximalRectangle(matrix):", "function_name": "maximalRectangle", "parameter_list": "(matrix)" }, { "docstring": null, "function_declaration": "def largest_rectangle_area(N, M, field):", "function_name": "largest_rectangle_area", "...
[ 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 maximalRectangle(field):\n if not field:\n return 0\n\n max_area = 0\n dp = [0] * len(field[0])\n\n for row in field:\n for c...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00007109", "row_id": 7109, "seed_ids": "[724]" }
0.632498
Code_Contests_7109
I
[ "maximalRectangle", "largest_rectangle_area" ]
2
[ [ "largest_rectangle_area", "maximalRectangle" ] ]
1
[]
false
[]
false
pytest
true
[]
true
f2f8e000ea2e03019f40b5d51f39caeaf857245c
cabd25d9df607155a637ab3183e33700002b01cc
v1.0
instruct
Code_Contests
Code_Contests_7180_I
Iris is a young artist who loves to draw intricate patterns using small shapes. Recently, she has become interested in creating patterns using only two types of characters: '*' and '.'. Her goal is to draw symmetric patterns that follow specific rules. For a given integer `N`, Iris will create an NxN grid (a square gr...
def generate_pattern(n): """ Generates an NxN grid pattern with given rules: - '*' on the main diagonal - '.' everywhere else """ pattern = [] for i in range(n): row = ['.'] * n row[i] = '*' pattern.append(''.join(row)) return pattern def iris_patterns(test_cases...
def test_generate_pattern(): result = generate_pattern(3) assert result == ["*..", ".*.", "..*"] result = generate_pattern(5) assert result == ["*....", ".*...", "..*..", "...*.", "....*"] def test_iris_patterns(): test_cases = [3, 5] results = iris_patterns(test_cases) expected = [ ...
[ { "docstring": "Generates an NxN grid pattern with given rules:\n- '*' on the main diagonal\n- '.' everywhere else", "function_declaration": "def generate_pattern(n):", "function_name": "generate_pattern", "parameter_list": "(n)" }, { "docstring": "Generates the patterns for each test case a...
[ 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 generate_pattern(N):\n \"\"\"\n Generates an NxN grid with a specific pattern.\n - The diagonal from the top-left to the bottom-right is fille...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00007180", "row_id": 7180, "seed_ids": "[9650]" }
0.615407
Code_Contests_7180
I
[ "generate_pattern", "iris_patterns", "format_patterns" ]
3
[ [ "iris_patterns", "generate_pattern" ] ]
1
[]
false
[]
false
pytest
false
[]
true
190dd9998da15c29f056adf315e3fbd54fd778d7
9fc3785e9d85e425b56a76efb480d2b2fefe13d2
v1.0
instruct
Code_Contests
Code_Contests_7276_I
You are given a digital billboard that displays messages using a set of LEDs arranged in a grid of N rows and M columns. Each cell in the grid can be either ON or OFF. The billboard manager wants to know the largest rectangle of ON cells within the grid to maximize the display area for advertisements. Your task is to ...
def maximal_rectangle_area(matrix): if not matrix: return 0 max_area = 0 dp = [0] * len(matrix[0]) # DP array to store the height of columns for row in matrix: for index, value in enumerate(row): # Update the dp array to add height or reset the height dp[in...
def test_largest_rectangle_of_on_cells(): assert largest_rectangle_of_on_cells(4, 5, ["10100", "10111", "11111", "10010"]) == 6 assert largest_rectangle_of_on_cells(2, 2, ["11", "11"]) == 4 assert largest_rectangle_of_on_cells(3, 3, ["101", "111", "101"]) == 3 assert largest_rectangle_of_on_cells(4, 4, ...
[ { "docstring": null, "function_declaration": "def maximal_rectangle_area(matrix):", "function_name": "maximal_rectangle_area", "parameter_list": "(matrix)" }, { "docstring": null, "function_declaration": "def largest_histogram_area(heights):", "function_name": "largest_histogram_area...
[ 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 maximal_rectangle_area(matrix):\n if not matrix:\n return 0\n \n max_area = 0\n dp = [0] * len(matrix[0]) # DP array to store the h...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00007276", "row_id": 7276, "seed_ids": "[7156]" }
0.676363
Code_Contests_7276
I
[ "maximal_rectangle_area", "largest_histogram_area", "largest_rectangle_of_on_cells" ]
3
[ [ "largest_rectangle_of_on_cells", "maximal_rectangle_area" ], [ "maximal_rectangle_area", "largest_histogram_area" ] ]
2
[]
false
[]
false
pytest
false
[]
true
92cbe7ec722bb027f9e6fce498c54310ccaac6df
9c095195c65e20d83b9e721b400a07a7e809dd1d
v1.0
instruct
Code_Contests
Code_Contests_7296_I
You have a network of n computers, identified by integers from 1 to n. Some pairs of computers are connected by bidirectional communication channels. Your task is to find out if all computers in the network are connected directly or indirectly. Each network configuration is represented by a list of m pairs (u, v), whe...
def find_root(parent, i): if parent[i] == i: return i else: parent[i] = find_root(parent, parent[i]) # Path compression return parent[i] def union(parent, rank, x, y): root_x = find_root(parent, x) root_y = find_root(parent, y) if root_x != root_y: if rank[root...
def test_find_root(): parent = [0, 1, 2, 3, 4] assert find_root(parent, 1) == 1 parent[2] = 1 assert find_root(parent, 2) == 1 parent[3] = 1 assert find_root(parent, 3) == 1 def test_union(): parent = [0, 1, 2, 3, 4] rank = [0, 0, 0, 0, 0] union(parent, rank, 1, 2) assert find_r...
[ { "docstring": null, "function_declaration": "def find_root(parent, i):", "function_name": "find_root", "parameter_list": "(parent, i)" }, { "docstring": null, "function_declaration": "def union(parent, rank, x, y):", "function_name": "union", "parameter_list": "(parent, rank, x,...
[ 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, x):\n if parent[x] != x:\n parent[x] = find(parent, parent[x])\n return parent[x]\n\ndef union(parent, rank, x, y):\n root...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00007296", "row_id": 7296, "seed_ids": "[4809]" }
0.591152
Code_Contests_7296
I
[ "find_root", "union", "is_connected_network", "check_all_connected" ]
4
[ [ "check_all_connected", "is_connected_network" ], [ "is_connected_network", "find_root" ], [ "is_connected_network", "union" ], [ "union", "find_root" ] ]
4
[]
false
[]
false
pytest
false
[]
true
6c0d895c36de357b454fdaf819bd9670abd7b11f
53f891aae75a1e8ed9b491deac0022d7544c81c5
v1.0
instruct
Code_Contests
Code_Contests_7317_I
Alice and Bob are playing a game with a 2D grid of size n x m, where each cell contains a positive integer. The players take turns, and on each turn, a player can pick any row or column and add 1 to every element in that row or column. Alice always goes first. The goal of the game is to make the sum of all the element...
def is_prime(num): """ Check if a number is prime. """ if num <= 1: return False if num == 2: return True if num % 2 == 0: return False max_div = int(num**0.5) + 1 for d in range(3, max_div, 2): if num % d == 0: return False return True de...
def test_is_prime(): assert is_prime(2) == True assert is_prime(17) == True assert is_prime(20) == False assert is_prime(1) == False assert is_prime(51) == False def test_game_outcome(): assert game_outcome(3, 3, [[4, 5, 6], [7, 8, 9], [1, 2, 3]]) == "Alice" assert game_outcome(1, 1, [[2]])...
[ { "docstring": "Check if a number is prime.", "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": "Determine the outcome of the game.", "function_declaration": "def game_outcome(n, m, grid):", "function_name": "game_o...
[ 0, 0, 1 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(n):\n \"\"\"\n Checks if a number is prime.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return True\n ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00007317", "row_id": 7317, "seed_ids": "[8454]" }
0.71749
Code_Contests_7317
I
[ "is_prime", "game_outcome" ]
2
[ [ "game_outcome", "is_prime" ] ]
1
[]
false
[]
false
pytest
false
[]
true
d508d4fb4bdc6f00cd7599e9762bc2aa158e68b3
3e43253f6597e668eaf5de1be8a5188a2fe927c7
v1.0
instruct
Code_Contests
Code_Contests_7324_I
A company runs a hierarchy of employees, where each employee except the CEO has one direct supervisor. They want to find out the number of distinct paths from the CEO to a given employee. The company's hierarchy is represented as a tree rooted at the CEO (node 1). An employee is represented as a node, and a direct rel...
from typing import List, Tuple, Dict from collections import defaultdict, deque def build_tree(edges: List[Tuple[int, int]]) -> Dict[int, List[int]]: tree = defaultdict(list) for a, b in edges: tree[a].append(b) return tree def distinct_paths_to_employee(n: int, edges: List[Tuple[int, int]], targe...
from solution import distinct_paths_to_employee def test_single_path(): n = 7 edges = [(1, 2), (1, 3), (2, 4), (2, 5), (3, 6), (3, 7)] target = 5 assert distinct_paths_to_employee(n, edges, target) == 1 def test_direct_supervision(): n = 4 edges = [(1, 2), (1, 3), (1, 4)] target = 4 as...
[ { "docstring": null, "function_declaration": "def build_tree(edges):", "function_name": "build_tree", "parameter_list": "(edges)" }, { "docstring": null, "function_declaration": "def distinct_paths_to_employee(n, edges, target):", "function_name": "distinct_paths_to_employee", "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": "from typing import List, Tuple\n\ndef distinct_paths_to_employee(n: int, edges: List[Tuple[int, int]], target: int) -> int:\n \"\"\"\n Given the numb...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00007324", "row_id": 7324, "seed_ids": "[4474]" }
0.646438
Code_Contests_7324
I
[ "build_tree", "distinct_paths_to_employee" ]
2
[ [ "distinct_paths_to_employee", "build_tree" ] ]
1
[]
false
[]
false
pytest
true
[]
true
ab99e722c363929a64b3d75702431da6f6761226
71101bc7b23584c7e79d333023348485557bea30
v1.0
instruct
Code_Contests
Code_Contests_7342_I
A farming simulator game involves growing crops in a grid-like field. The field is represented by a 2D matrix where each cell contains an integer that denotes the height of the plant in meters. The player can water the plants, which increases the height of every plant in a sub-rectangle of the field by a fixed amount....
def water_plants(field, operations): n = len(field) m = len(field[0]) for r1, c1, r2, c2, k in operations: for i in range(r1, r2+1): for j in range(c1, c2+1): field[i][j] += k return field # Function to handle the complete flow def simulate_watering(n, m, f...
def test_single_operation(): field = [ [1, 1], [1, 1] ] operations = [(0, 0, 1, 1, 5)] result = simulate_watering(2, 2, field, 1, operations) expected = [ [6, 6], [6, 6] ] assert result == expected def test_multiple_operations(): field = [ [1, 2, ...
[ { "docstring": null, "function_declaration": "def water_plants(field, operations):", "function_name": "water_plants", "parameter_list": "(field, operations)" }, { "docstring": null, "function_declaration": "def simulate_watering(n, m, field, q, operations):", "function_name": "simula...
[ 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 apply_watering_operations(n, m, field, operations):\n \"\"\"\n Applies watering operations to the field and returns the final state of the field....
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00007342", "row_id": 7342, "seed_ids": "[3688]" }
0.635526
Code_Contests_7342
I
[ "water_plants", "simulate_watering" ]
2
[ [ "simulate_watering", "water_plants" ] ]
1
[]
false
[]
false
pytest
false
[]
true
ef72671970ed951f01b4c289a69c0df21104cc2e
f5892d6290065fa7fc28f65142a71aefe533d6cd
v1.0
instruct
Code_Contests
Code_Contests_7350_I
A new coding question that matches the style, complexity, and scope of the provided question: A distribution network comprises several nodes connected by edges, representing the pathways goods can be transported from one node to another. Each node may have multiple edges connecting it to other nodes. A critical challe...
def create_graph(edges, N): graph = {i: [] for i in range(1, N + 1)} for u, v in edges: graph[u].append(v) graph[v].append(u) return graph def dfs(graph, current, target, visited, sequence=None, seq_index=0): if seq_index < len(sequence) and current != sequence[seq_index]: retur...
from solution import is_path_possible def test_is_path_possible_case1(): N = 5 M = 5 edges = [(1, 2), (2, 3), (3, 4), (4, 5), (2, 4)] start = 1 destination = 5 sequence = [2, 3, 4] assert is_path_possible(N, M, edges, start, destination, sequence) == True def test_is_path_possible_case2():...
[ { "docstring": null, "function_declaration": "def create_graph(edges, N):", "function_name": "create_graph", "parameter_list": "(edges, N)" }, { "docstring": null, "function_declaration": "def dfs(graph, current, target, visited, sequence=None, seq_index=0):", "function_name": "dfs",...
[ 0, 0, 0, 0, 0, 0, 0, 1, 0 ]
1
hard
0.111
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def can_traverse_path(n, m, edges, start, destination, intermediates):\n from collections import defaultdict, deque\n \n def bfs_path_exists(graph...
trial_gpt4o_7
{ "original_instruction": "", "prompt_id": "00007350", "row_id": 7350, "seed_ids": "[7900]" }
0.656131
Code_Contests_7350
I
[ "create_graph", "dfs", "is_path_possible" ]
3
[ [ "is_path_possible", "create_graph" ], [ "is_path_possible", "dfs" ] ]
2
[]
false
[]
false
pytest
true
[]
true
e366c7ee41cba35f14acf13075d030d9e4280697
9c2c8718fe7e48fa8d80ec7344cfbf2ce3555d8c
v1.0
instruct
Code_Contests
Code_Contests_7351_I
BingLand is famous for its scenic river channels and floating markets. As tourism is growing, the government has decided to build a network of bridges to connect various islands. There are N islands in BingLand, each uniquely numbered from 1 to N. Each island must be connected with at least one other island to form a c...
def find(parent, x): if parent[x] != x: parent[x] = find(parent, parent[x]) return parent[x] def union(parent, rank, x, y): rootX = find(parent, x) rootY = find(parent, y) if rootX != rootY: if rank[rootX] > rank[rootY]: parent[rootY] = rootX elif rank[rootX...
from solution import minimum_cost_to_connect_islands def test_example_case(): n = 4 m = 5 bridges = [ (1, 2, 10), (2, 3, 15), (3, 4, 20), (4, 1, 25), (2, 4, 30) ] assert minimum_cost_to_connect_islands(n, m, bridges) == 45 def test_disconnected_graph(): ...
[ { "docstring": null, "function_declaration": "def find(parent, x):", "function_name": "find", "parameter_list": "(parent, x)" }, { "docstring": null, "function_declaration": "def union(parent, rank, x, y):", "function_name": "union", "parameter_list": "(parent, rank, x, y)" }, ...
[ 0, 0, 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 minimum_cost_to_connect_islands(N, M, bridges):\n \"\"\"\n Calculate the minimum cost to connect all islands using the potential bridges.\n \n...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00007351", "row_id": 7351, "seed_ids": "[8772]" }
0.794296
Code_Contests_7351
I
[ "find", "union", "kruskal", "minimum_cost_to_connect_islands" ]
4
[ [ "kruskal", "find" ], [ "kruskal", "union" ], [ "minimum_cost_to_connect_islands", "kruskal" ], [ "union", "find" ] ]
4
[]
false
[]
false
pytest
true
[]
true
ca806573d2461d3a4d25b61a2504c294ecb19cf9
51a0e1de40390d58f4ba2c9f7c50fcea9f93b250
v1.0
instruct
Code_Contests
Code_Contests_7364_I
A traveling scientist is tasked with exploring a series of experimental sites to collect data. Each site is connected to a number of other sites by corridors. The scientist has a specific number of experiments to conduct, represented by an integer X. The total distance the scientist must travel to conduct exactly X exp...
def find_paths_to_target(graph, start, target, steps, current_steps, visited): if current_steps > steps: return False if current_steps == steps and start == target: return True for neighbor in graph[start]: if current_steps == 0 or visited[current_steps-1] != neighbor: ...
def test_parse_input(): input_data = """2 1 1 1 2 2 1 2 1 2 3 2 2 1 2 2 3 4 4 3 1 2 2 3 3 4 4 1 0 0 0""" expected_output = [ {'SCX': (2, 1, 1), 'connections': [(1, 2)]}, {'SCX': (2, 1, 2), 'connections': [(1, 2)]}, {'SCX': (3, 2, 2), '...
[ { "docstring": null, "function_declaration": "def find_paths_to_target(graph, start, target, steps, current_steps, visited):", "function_name": "find_paths_to_target", "parameter_list": "(graph, start, target, steps, current_steps, visited)" }, { "docstring": null, "function_declaration"...
[ 1, 0, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_reachable_datasets(datasets):\n results = []\n\n for dataset in datasets:\n S, C, X, corridors = dataset\n # Build the graph as ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00007364", "row_id": 7364, "seed_ids": "[13111]" }
0.691792
Code_Contests_7364
I
[ "find_paths_to_target", "can_reach_end", "process_multiple_datasets", "parse_input" ]
4
[ [ "can_reach_end", "find_paths_to_target" ], [ "process_multiple_datasets", "can_reach_end" ] ]
2
[ "process_multiple_datasets", "parse_input" ]
false
[]
false
pytest
false
[]
true
aff963306d3c42e70badf5247f148ba4b78eb204
4224d832fc02ad61043b6fcd06faf46482cb9318
v1.0
instruct
Code_Contests
Code_Contests_7402_I
In a parallel universe, there is a peculiar way of generating numbers. Starting from any given number n, the next number in the sequence is generated by reversing the digits of n and then adding it to the original number n. This process is repeated until a palindrome is produced. A palindrome is a number that reads th...
def reverse_number(n): """ Reverses the digits of an integer. """ return int(str(n)[::-1]) def is_palindrome(n): """ Checks whether an integer is a palindrome. """ return str(n) == str(n)[::-1] def steps_to_palindrome(n): """ Returns the number of steps required to reach a pali...
from solution import steps_to_palindrome def test_example_1(): assert steps_to_palindrome(28) == (2, 121) def test_example_2(): assert steps_to_palindrome(89) == (24, 8813200023188) def test_example_3(): assert steps_to_palindrome(123) == (1, 444) def test_single_digit_numbers(): for i in range(10):...
[ { "docstring": "Reverses the digits of an integer.", "function_declaration": "def reverse_number(n):", "function_name": "reverse_number", "parameter_list": "(n)" }, { "docstring": "Checks whether an integer is a palindrome.", "function_declaration": "def is_palindrome(n):", "function...
[ 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 reverse_number(n):\n \"\"\"\n Reverses the digits of an integer.\n \"\"\"\n return int(str(n)[::-1])\n\ndef is_palindrome(n):\n \"\"\"\n...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00007402", "row_id": 7402, "seed_ids": "[7225]" }
0.695393
Code_Contests_7402
I
[ "reverse_number", "is_palindrome", "steps_to_palindrome" ]
3
[ [ "steps_to_palindrome", "is_palindrome" ], [ "steps_to_palindrome", "reverse_number" ] ]
2
[]
false
[]
false
pytest
true
[]
true
549cc62dfe0dab36ab7b1b1d5795d4c9b54baa54
648dcfbf84629d16cfb715c03a436edff359d84f
v1.0
instruct
Code_Contests
Code_Contests_7425_I
**Word Chain Validation** You are given a list of words where each word is formed of lowercase letters (a-z). We define a word chain as a list of words [w1, w2, ..., wn] such that for each consecutive pair of words (wi, wi+1), the last letter of wi is the same as the first letter of wi+1. Your task is to determine i...
def is_valid_word_chain(words): if not words: return False for i in range(len(words) - 1): if words[i][-1] != words[i + 1][0]: return False return True def check_word_chain(): words = [] while True: word = input().strip() if word == "END": ...
from solution import is_valid_word_chain def test_valid_chain(): assert is_valid_word_chain(["cat", "tiger", "rabbit", "tarantula", "apple", "elephant", "toy", "yak", "kite", "echo", "owlet", "tuna", "alpaca"]) == True def test_invalid_chain_at_start(): assert is_valid_word_chain(["cat", "dog"]) == False def...
[ { "docstring": null, "function_declaration": "def is_valid_word_chain(words):", "function_name": "is_valid_word_chain", "parameter_list": "(words)" }, { "docstring": null, "function_declaration": "def check_word_chain():", "function_name": "check_word_chain", "parameter_list": "(...
[ 0, 0, 1 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_valid_word_chain(words):\n for i in range(len(words) - 1):\n if words[i][-1] != words[i+1][0]:\n return False\n return True\...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00007425", "row_id": 7425, "seed_ids": "[12396]" }
0.619364
Code_Contests_7425
I
[ "is_valid_word_chain", "check_word_chain" ]
2
[ [ "check_word_chain", "is_valid_word_chain" ] ]
1
[]
false
[]
false
pytest
true
[]
true
785516b0dd06591f36dea07431f8b82d07d40aac
8586f2dc8576383ded0f23c508758400207c68f0
v1.0
instruct
Code_Contests
Code_Contests_7468_I
Emma is designing a railway system that connects various cities with unique train routes. She has n cities and m unique bidirectional routes connecting them. Each route has a distance associated with it. Emma wants to ensure that there is a way to travel between any two distinct cities using the most efficient way poss...
def find(parent, i): """ A utility function to find the set of an element i (uses path compression technique)""" if parent[i] == i: return i else: parent[i] = find(parent, parent[i]) return parent[i] def union(parent, rank, x, y): """ A function that does union of two sets ...
import pytest from solution import minimum_distance_railway_network def test_example1(): n = 4 m = 5 routes = [ (1, 2, 5), (1, 3, 10), (2, 3, 4), (2, 4, 11), (3, 4, 7) ] assert minimum_distance_railway_network(n, m, routes) == 16 def test_example2(): n =...
[ { "docstring": "A utility function to find the set of an element i \n(uses path compression technique)", "function_declaration": "def find(parent, i):", "function_name": "find", "parameter_list": "(parent, i)" }, { "docstring": "A function that does union of two sets of x and y \n(uses union...
[ 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 xr...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00007468", "row_id": 7468, "seed_ids": "[12525]" }
0.744338
Code_Contests_7468
I
[ "find", "union", "kruskal", "minimum_distance_railway_network" ]
4
[ [ "kruskal", "find" ], [ "kruskal", "union" ], [ "minimum_distance_railway_network", "kruskal" ], [ "union", "find" ] ]
4
[]
false
[]
false
pytest
true
[]
true
7096ab7ba21fb89da857545cdf56b0b617c20e4d
c7772b08e936cf9eb8a05b4f8318dc9252cde759
v1.0
instruct
Code_Contests
Code_Contests_7492_I
You are tasked with developing a program that runs a simulation of a simple card game between two players. The game uses a standard deck of 52 cards, and the objective is to determine the winner based on a series of random draws. Each player draws a card from the shuffled deck, and the player with the higher card wins...
import random # Define card values card_values = { '2': 2, '3': 3, '4': 4, '5': 5, '6': 6, '7': 7, '8': 8, '9': 9, '10': 10, 'J': 11, 'Q': 12, 'K': 13, 'A': 14 } def draw_card(): """ Simulates drawing a card from the deck. Returns the value of the card drawn. """ card = random.choice(list...
from solution import simulate_game def test_simulate_game(): # Test with a fixed number of rounds to ensure the output is one of the expected results results = set(simulate_game(10) for _ in range(1000)) assert "Player 1" in results assert "Player 2" in results assert "Draw" in results def test_si...
[ { "docstring": "Simulates drawing a card from the deck.\nReturns the value of the card drawn.", "function_declaration": "def draw_card():", "function_name": "draw_card", "parameter_list": "()" }, { "docstring": "Simulates a game of n rounds and returns the winner.", "function_declaration...
[ 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 random\n\ndef card_value(card):\n values = {'2': 2, '3': 3, '4': 4, '5': 5, '6': 6, '7': 7, '8': 8, \n '9': 9, '10': 10, 'J': 11, 'Q...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00007492", "row_id": 7492, "seed_ids": "[1214]" }
0.663849
Code_Contests_7492
I
[ "draw_card", "simulate_game" ]
2
[ [ "simulate_game", "draw_card" ] ]
1
[]
false
[]
false
pytest
true
[]
true
fa3770f2c60f305fe0a744fd35b73a61a2d90008
345cc898d520e45cd231cec36352b13e89ee5c0a
v1.0
instruct
Code_Contests
Code_Contests_7529_I
Given a list of integers, we define a "pseudo-prime" number as a number that has exactly three distinct positive divisors. A well-known example of a pseudo-prime is the square of a prime number, such as 9 (3^2), 25 (5^2), or 49 (7^2). Write a function that, given an integer n, generates a list of the first n pseudo-pr...
def is_prime(num): """ Determines if the given 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 ...
from solution import pseudo_prime_numbers def test_single_pseudo_prime(): assert pseudo_prime_numbers(1) == [4] def test_first_five_pseudo_primes(): assert pseudo_prime_numbers(5) == [4, 9, 25, 49, 121] def test_ten_pseudo_primes(): assert pseudo_prime_numbers(10) == [4, 9, 25, 49, 121, 169, 289, 361, 52...
[ { "docstring": "Determines if the given number is prime.", "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": "Generates a list of the first n pseudo-prime numbers. Pseudo-prime number is a number \nthat has exactly three di...
[ 0, 0, 0, 1, 0 ]
1
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(num):\n \"\"\"\n Helper function to check if a number is prime.\n \"\"\"\n if num <= 1:\n return False\n for i in range(...
trial_gpt4o_3
{ "original_instruction": "", "prompt_id": "00007529", "row_id": 7529, "seed_ids": "[7849]" }
0.606396
Code_Contests_7529
I
[ "is_prime", "pseudo_prime_numbers" ]
2
[ [ "pseudo_prime_numbers", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
d34392470281a8aedf939fef01592def89a5995b
9b989adc4021061ed9eefb69c98be4516cf3a8fb
v1.0
instruct
Code_Contests
Code_Contests_7572_I
There are N cities connected by bidirectional roads. Each road has a travel cost associated with it. You are given the adjacency matrix of a graph representing the cities and the cost of traveling between them. Your task is to find the minimum cost to travel from city 1 to city N. If there is no path from city 1 to cit...
import heapq def dijkstra(graph, start, end): n = len(graph) min_heap = [(0, start)] distances = {node: float('inf') for node in range(n)} distances[start] = 0 visited = set() while min_heap: current_dist, current_node = heapq.heappop(min_heap) if current_node in visited: ...
import pytest from solution import minimum_cost_to_travel def test_minimum_cost_to_travel_simple(): assert minimum_cost_to_travel(4, [ [0, 3, 1, -1], [3, 0, 7, 5], [1, 7, 0, 2], [-1, 5, 2, 0] ]) == 3 def test_minimum_cost_to_travel_no_path(): assert minimum_cost_to_travel(3...
[ { "docstring": null, "function_declaration": "def dijkstra(graph, start, end):", "function_name": "dijkstra", "parameter_list": "(graph, start, end)" }, { "docstring": null, "function_declaration": "def minimum_cost_to_travel(N, adjacency_matrix):", "function_name": "minimum_cost_to_...
[ 1, 0, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "import heapq\n\ndef minimum_cost_to_travel(n, adjacency_matrix):\n def dijkstra(source, destination):\n dist = [float('inf')] * n\n dist[s...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00007572", "row_id": 7572, "seed_ids": "[5596]" }
0.752663
Code_Contests_7572
I
[ "dijkstra", "minimum_cost_to_travel" ]
2
[ [ "minimum_cost_to_travel", "dijkstra" ] ]
1
[]
false
[]
false
pytest
true
[]
true
7e632771b92fab47e03454734151d012046c7db9
2830053957692e11c8ddc5445c54dbcdb6d1682c
v1.0
instruct
Code_Contests
Code_Contests_7614_I
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 if two tasks have the same pr...
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": "", "prompt_id": "00007614", "row_id": 7614, "seed_ids": "[12880]" }
0.583667
Code_Contests_7614
I
[ "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
a134d1f739a532c21efc6143cd3c3de478ab3320
ac09235516040a0eeddead2ea37fc2e55370ca4d
v1.0
instruct
Code_Contests
Code_Contests_7616_I
You are given a rectangular grid of size N x M filled with non-negative integers. Your task is to find and return the largest sum of a sub-grid (contiguous subarray). Input The input consists of a series of data sets, followed by a single line containing a single character '0', indicating the end of input. Each data ...
def kadane(arr): """Kadane's algorithm for maximum subarray sum in 1D array.""" max_sum = float('-inf') current_sum = 0 for num in arr: current_sum = max(num, current_sum + num) max_sum = max(max_sum, current_sum) return max_sum def largest_sum_subgrid(grid): """ Returns the...
import pytest from solution import process_input, kadane, largest_sum_subgrid def test_kadane(): assert kadane([1, 2, -1, 2, -3, 4, -5, 6]) == 6 assert kadane([4, -1, 2, 1]) == 6 assert kadane([-3, -1, -2, -1]) == -1 def test_largest_sum_subgrid(): grid1 = [ [1, 2, 3], [4, 5, 6], ...
[ { "docstring": "Kadane's algorithm for maximum subarray sum in 1D array.", "function_declaration": "def kadane(arr):", "function_name": "kadane", "parameter_list": "(arr)" }, { "docstring": "Returns the largest sum of a sub-grid (contiguous subarray) within the grid.", "function_declarat...
[ 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 max_subgrid_sum(matrix):\n \"\"\"\n Returns the maximum sum of any subgrid in the given 2D matrix.\n \"\"\"\n n = len(matrix)\n m = len(...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00007616", "row_id": 7616, "seed_ids": "[3843]" }
0.706018
Code_Contests_7616
I
[ "kadane", "largest_sum_subgrid", "process_input", "main" ]
4
[ [ "largest_sum_subgrid", "kadane" ], [ "process_input", "largest_sum_subgrid" ] ]
2
[ "process_input" ]
false
[]
false
pytest
true
[]
true
8013be4d5f4ceda1119d2c1049a254a183c748d8
a15f0eac563ae6d410bff7c9706f287f5ba7367f
v1.0
instruct
Code_Contests
Code_Contests_7702_I
A novel bakery offers their packages in a special way. Each package can include up to **n** different unique types of pastries, and for each type of pastry, a specific number of items must be packed. The bakery wants to fill the packages in such a way where the total number of items per package is minimized, but each p...
from math import gcd from functools import reduce def lcm(a, b): return a * b // gcd(a, b) def lcm_multiple(numbers): return reduce(lcm, numbers, 1) def minimal_total_items(n, max_items): return lcm_multiple(max_items)
from solution import minimal_total_items def test_minimal_total_items_example_1(): assert minimal_total_items(3, [4, 3, 2]) == 12 def test_minimal_total_items_example_2(): assert minimal_total_items(4, [2, 2, 2, 2]) == 2 def test_minimal_total_items_single_type(): assert minimal_total_items(1, [5]) == 5 ...
[ { "docstring": null, "function_declaration": "def lcm(a, b):", "function_name": "lcm", "parameter_list": "(a, b)" }, { "docstring": null, "function_declaration": "def lcm_multiple(numbers):", "function_name": "lcm_multiple", "parameter_list": "(numbers)" }, { "docstring":...
[ 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 math import gcd\nfrom functools import reduce\n\ndef lcm(a, b):\n \"\"\"\n Calculates the Least Common Multiple (LCM) of two numbers a and b.\n ...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00007702", "row_id": 7702, "seed_ids": "[2248]" }
0.757983
Code_Contests_7702
I
[ "lcm", "lcm_multiple", "minimal_total_items" ]
3
[ [ "lcm_multiple", "lcm" ], [ "minimal_total_items", "lcm_multiple" ] ]
2
[]
false
[]
false
pytest
true
[]
true
0dfd00ce4d3aea7981f620ba55fb10faa8aed32f
b571c28eac0a1b59e59b6eecfcd70e829c45c68a
v1.0
instruct
Code_Contests
Code_Contests_7709_I
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 points form a simple polygon (n...
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": "", "prompt_id": "00007709", "row_id": 7709, "seed_ids": "[9379]" }
0.60338
Code_Contests_7709
I
[ "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
57bb735ab522408d4327cb65a1bccebe08de43f7
7cab327ff7f794542a92074a3e4b13d77877ad4e
v1.0
instruct
Code_Contests
Code_Contests_7724_I
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 messages and some letters hav...
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": "", "prompt_id": "00007724", "row_id": 7724, "seed_ids": "[11733]" }
0.614972
Code_Contests_7724
I
[ "is_consecutive_sequence", "verify_consecutive_messages" ]
2
[ [ "verify_consecutive_messages", "is_consecutive_sequence" ] ]
1
[]
false
[]
false
pytest
true
[]
true
61f5c5504cf4fe4754cdf7d7625c58f86cd7869b
8262e016365705e87290b42bfa7c145cfc4d9b50
v1.0
instruct
Code_Contests
Code_Contests_7809_I
You are given an unsorted array of n positive integers. You need to find out if there's any subarray (contiguous subset) of size k which has an arithmetic progression. An arithmetic progression (AP) is a sequence of numbers such that the difference of any two successive members of the sequence is a constant. For exa...
def is_arithmetic_progression(subarray): """ Returns True if the given subarray forms an arithmetic progression, else False. """ if len(subarray) < 2: return False common_diff = subarray[1] - subarray[0] for i in range(2, len(subarray)): if subarray[i] - subarray[i - 1] != commo...
from solution import find_ap def test_example_1(): n = 5 k = 3 arr = [3, 5, 1, 3, 3] assert find_ap(n, k, arr) == "NO" def test_example_2(): n = 4 k = 2 arr = [1, 3, 5, 7] assert find_ap(n, k, arr) == "YES" def test_example_3(): n = 6 k = 4 arr = [20, 15, 10, 5, 0] ass...
[ { "docstring": "Returns True if the given subarray forms an arithmetic progression, else False.", "function_declaration": "def is_arithmetic_progression(subarray):", "function_name": "is_arithmetic_progression", "parameter_list": "(subarray)" }, { "docstring": "Returns \"YES\" if there is a ...
[ 0, 0, 1 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_arithmetic_progression(subarray):\n \"\"\"\n Check if the given subarray is an arithmetic progression (AP).\n \"\"\"\n if len(subarray) ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00007809", "row_id": 7809, "seed_ids": "[2670]" }
0.726285
Code_Contests_7809
I
[ "is_arithmetic_progression", "has_subarray_ap", "find_ap" ]
3
[ [ "find_ap", "has_subarray_ap" ], [ "has_subarray_ap", "is_arithmetic_progression" ] ]
2
[]
false
[]
false
pytest
true
[]
true
ef6ef885ca3106aa6e2e78b6e195fd7c083b7a8c
58bf04aa19bc331f91b793afd0c3b21d6486124a
v1.0
instruct
Code_Contests
Code_Contests_7824_I
Artsem is challenging his friend Saunders with another intriguing problem related to permutations and cycle detection within functions. You 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-based) it maps to. Your task is to...
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": "", "prompt_id": "00007824", "row_id": 7824, "seed_ids": "[473]" }
0.643613
Code_Contests_7824
I
[ "find_cycles", "permutation_cycles" ]
2
[ [ "permutation_cycles", "find_cycles" ] ]
1
[]
false
[]
false
pytest
true
[]
true
441a1984e1210a46503dcc6e1af4d65ecfa03c99
6f2d2637f18643c10c682ac9cd36492070ddc51a
v1.0
instruct
Code_Contests
Code_Contests_7993_I
Travel Time on Grid Koto 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 station is located at the coordina...
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": "", "prompt_id": "00007993", "row_id": 7993, "seed_ids": "[11555]" }
0.71436
Code_Contests_7993
I
[ "min_travel_time", "travel_times" ]
2
[ [ "travel_times", "min_travel_time" ] ]
1
[]
false
[]
false
pytest
true
[]
true
13758cfda3d721b4122c46fca7c65b23d1010047
266af3cdcd65d5c9c507147913f841a4b20fb235
v1.0
instruct
Code_Contests
Code_Contests_8006_I
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: \[ \begin{matrix} 1 & 2 & 3 & 4 \\ 5 & 1 & 2 & 3 \\ 6 & 5 & 1 & 2 \\ 7 & 6 & 5 & 1 \\ \end{matrix} \] Write a function that checks if a given matri...
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": "", "prompt_id": "00008006", "row_id": 8006, "seed_ids": "[7483]" }
0.524058
Code_Contests_8006
I
[ "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
635c40cdd89c6dfcc0fd04a8d4c3397f1eba4a06
e81c6f159773ddfe5cfe46caedf004071a4a34ab
v1.0
instruct
Code_Contests
Code_Contests_8056_I
Palindrome Chain Length A 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 number to its reverse until it bec...
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": "", "prompt_id": "00008056", "row_id": 8056, "seed_ids": "[2490]" }
0.693632
Code_Contests_8056
I
[ "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
15d3b7f27266ff98e32bf11bb57db3fe4d9cd665
cb27eb2f0ba7484ee062bc6349d8295f95fc3c62
v1.0
instruct
Code_Contests
Code_Contests_8095_I
A tech company is organizing a marathon for promoting fitness among its employees. The event features a unique algorithmic challenge: participants need to determine the total number of distinct ways to cover a certain distance using steps of different predefined lengths. Participants can use steps of lengths 1, 2, and...
def ways_to_cover_distance(n): """ Returns the number of distinct ways to cover a distance n using steps of 1, 2, or 3 units. """ if n == 0: return 0 dp = [0] * (n + 1) dp[0] = 1 # There's 1 way to cover distance 0 - do nothing if n >= 1: dp[1] = 1 # Only one way to cover ...
import pytest from solution import ways_to_cover_distance, process_distances def test_ways_to_cover_distance(): assert ways_to_cover_distance(4) == 7 assert ways_to_cover_distance(7) == 44 assert ways_to_cover_distance(10) == 274 assert ways_to_cover_distance(1) == 1 assert ways_to_cover_distance(2...
[ { "docstring": "Returns the number of distinct ways to cover a distance n using steps of 1, 2, or 3 units.", "function_declaration": "def ways_to_cover_distance(n):", "function_name": "ways_to_cover_distance", "parameter_list": "(n)" }, { "docstring": "Processes a list of distances and retur...
[ 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 distinct_ways(distance):\n \"\"\"\n Returns the number of distinct ways to cover the given distance using steps of lengths 1, 2, and 3.\n \"\"...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00008095", "row_id": 8095, "seed_ids": "[5298]" }
0.638678
Code_Contests_8095
I
[ "ways_to_cover_distance", "process_distances" ]
2
[ [ "process_distances", "ways_to_cover_distance" ] ]
1
[]
false
[]
false
pytest
true
[]
true
f4e812e9102b4807c8020c0793b8357a2d4ca888
6501ba8fada65e4812c040b642c7fcbc63a76aa9
v1.0
instruct
Code_Contests
Code_Contests_8136_I
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. Write a program to find the maximum area of the ...
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": "", "prompt_id": "00008136", "row_id": 8136, "seed_ids": "[4217]" }
0.667492
Code_Contests_8136
I
[ "max_histogram_area", "largest_rectangle_fertile_land" ]
2
[ [ "largest_rectangle_fertile_land", "max_histogram_area" ] ]
1
[]
false
[]
false
pytest
false
[]
true
61ba61853bd13147ec006664c17322b5cba50c0b
a22fad27a494b46de48ee5154690e5bf3cf55021
v1.0
instruct
Code_Contests
Code_Contests_8216_I
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: * T_i=1: Given two integers X_i and V_i, add V_i to A_{X_i}. * T_i=2: Given two integers L_i and R_i, calculate the sum of the subarray from A_{L_i} to A_{R_i}. * T_i=3: Given...
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": "", "prompt_id": "00008216", "row_id": 8216, "seed_ids": "[10387]" }
0.740544
Code_Contests_8216
I
[ "process_queries", "process_input_output" ]
2
[ [ "process_input_output", "process_queries" ] ]
1
[ "process_queries", "process_input_output" ]
false
[]
false
pytest
false
[]
true
1f8f356fe15eb223e23ca9fbf865ff5814622fb6
3fe4bdabc441c7708334465869d6f826674800ce
v1.0
instruct
Code_Contests
Code_Contests_8224_I
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 any pair of towns. However, t...
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": "", "prompt_id": "00008224", "row_id": 8224, "seed_ids": "[352]" }
0.712267
Code_Contests_8224
I
[ "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
e24a9690fd1aa8f3892d2e546656867f7d7b6d68
5ec5c62c87583780bab99a64f3ab3134b997e3ba
v1.0
instruct
Code_Contests
Code_Contests_8279_I
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. **Input:** - The first line contains an int...
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": "", "prompt_id": "00008279", "row_id": 8279, "seed_ids": "[11319]" }
0.632097
Code_Contests_8279
I
[ "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
d37b8ad396c8511443b1c213b2a96c15ae73efb5
874c5ee77fe2b817e0fa1a9afc7122af4bb954d9
v1.0
instruct
Code_Contests
Code_Contests_8347_I
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 with each other. This knowled...
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": "", "prompt_id": "00008347", "row_id": 8347, "seed_ids": "[7069]" }
0.525618
Code_Contests_8347
I
[ "find_most_frequent_pair", "process_interaction_logs" ]
2
[ [ "process_interaction_logs", "find_most_frequent_pair" ] ]
1
[]
false
[]
false
pytest
true
[]
true
aa81be6b4b33627992ae67ad5ac64b75df4ad1db
d017586506402c56267713be9922361a501720e5
v1.0
instruct
Code_Contests
Code_Contests_8354_I
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. Given this restriction, write a program that will take an input...
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": "", "prompt_id": "00008354", "row_id": 8354, "seed_ids": "[1758]" }
0.561561
Code_Contests_8354
I
[ "is_passcode_valid", "check_passcodes" ]
2
[ [ "check_passcodes", "is_passcode_valid" ] ]
1
[]
false
[]
false
pytest
true
[]
true
95b33b2c9850ccfe63b167e4d045d9bbfd22916b
38c976774a1a4a6d4379d5ad351c206fc7fdd306
v1.0
instruct
Code_Contests
Code_Contests_8357_I
A --Shipping Containers Optimization Problem Statement You 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 carry, and each container has a given...
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": "", "prompt_id": "00008357", "row_id": 8357, "seed_ids": "[12491]" }
0.651175
Code_Contests_8357
I
[ "knapsack", "maximize_loaded_weight" ]
2
[ [ "maximize_loaded_weight", "knapsack" ] ]
1
[]
false
[]
false
pytest
true
[]
true
6ca2f1fdd767231bb7ca682dc3bbe07e2bf09caf
df4e1d82b35d36ccad6c25a990d00d178bd7f4bb
v1.0
instruct
Code_Contests
Code_Contests_8392_I
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. Input The first line contains an intege...
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": "", "prompt_id": "00008392", "row_id": 8392, "seed_ids": "[10458]" }
0.697507
Code_Contests_8392
I
[ "is_balanced", "check_sequences" ]
2
[ [ "check_sequences", "is_balanced" ] ]
1
[]
false
[]
false
pytest
true
[]
true
41e66e7db21a794239329a33a34bdf7b919b317b
0745d840beb223b86cafd585e8ae0fea91ae1468
v1.0
instruct
Code_Contests
Code_Contests_8407_I
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 needs your help to solve it. Sa...
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": "", "prompt_id": "00008407", "row_id": 8407, "seed_ids": "[3203]" }
0.625724
Code_Contests_8407
I
[ "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
7f62dca9705fd5e8005ff5e789f1c5f4eed21f36
a5969bed2dd41298ed274a226885fbf58f67e33f
v1.0
instruct
Code_Contests
Code_Contests_8412_I
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. Input The input consists of several lines. The first line contains an integer n ...
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": "", "prompt_id": "00008412", "row_id": 8412, "seed_ids": "[826]" }
0.651896
Code_Contests_8412
I
[ "calculate_weighted_average", "find_student_with_highest_average", "main" ]
3
[ [ "find_student_with_highest_average", "calculate_weighted_average" ] ]
1
[]
false
[]
false
pytest
false
[]
true
8cb0d98786ba36bd695a06524058c301b219d60b
c1d584f57a77171eeaff0981acd9ee97a971e073
v1.0
instruct
Code_Contests
Code_Contests_8415_I
Little Iris just learned about numeric palindromes and the magic of prime numbers, and she came up with a new interesting problem: You 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. A palindromic number is a number that remains th...
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": "", "prompt_id": "00008415", "row_id": 8415, "seed_ids": "[6781]" }
0.701947
Code_Contests_8415
I
[ "is_prime", "is_palindrome", "count_prime_palindromes" ]
3
[ [ "count_prime_palindromes", "is_palindrome" ], [ "count_prime_palindromes", "is_prime" ] ]
2
[]
false
[]
false
pytest
true
[]
true
5351e109d6626407d74277e189ef58d544c2e3fa
0b74a2609a87644e920a18fd7545ec0e56f3fbc2
v1.0
instruct
Code_Contests
Code_Contests_8431_I
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. You need to determine the scor...
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": "", "prompt_id": "00008431", "row_id": 8431, "seed_ids": "[10563]" }
0.680047
Code_Contests_8431
I
[ "calculate_scoreboard", "get_scoreboard", "format_scoreboard" ]
3
[ [ "get_scoreboard", "calculate_scoreboard" ] ]
1
[]
false
[]
false
pytest
true
[]
true
c7ef2a455ad95708536d8e70cc24ad8ddd55606b
3a3a59073e18c88aa36fc237fb5b9b5800e6becd
v1.0
instruct
Code_Contests
Code_Contests_8471_I
Given a rectangular matrix of size N x M, each element in the matrix either contains a 0 or a 1. You need to find the row with the maximum number of 1s. If there are multiple rows with the same maximum number of 1s, return the index of the smallest row. Indices are 0-based. Input: The first line contains two integers...
def row_with_max_ones(matrix): """ Finds the row index with the maximum number of 1s in the given binary matrix. If multiple rows have the same number of maximum 1s, returns the smallest row index. Parameters: matrix (List[List[int]]): The binary matrix Returns: int: The row index ...
def test_row_with_max_ones(): matrix = [ [0, 1, 1, 1], [0, 0, 1, 1], [1, 1, 1, 0], [0, 0, 0, 0] ] assert row_with_max_ones(matrix) == 0 matrix = [ [0, 1, 1, 1], [0, 1, 1, 1], [1, 1, 1, 0], [0, 0, 0, 0] ] assert row_with_max_ones(ma...
[ { "docstring": "Finds the row index with the maximum number of 1s in the given binary matrix.\nIf multiple rows have the same number of maximum 1s, returns the smallest row index.\n\nParameters:\nmatrix (List[List[int]]): The binary matrix\n\nReturns:\nint: The row index with the maximum number of 1s", "fun...
[ 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 row_with_max_ones(matrix):\n \"\"\"\n This function takes a matrix of size N x M as input and returns the index of the \n row with the maximum...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00008471", "row_id": 8471, "seed_ids": "[6114]" }
0.602735
Code_Contests_8471
I
[ "row_with_max_ones", "read_input_and_find_row_max_ones" ]
2
[ [ "read_input_and_find_row_max_ones", "row_with_max_ones" ] ]
1
[]
false
[]
false
pytest
true
[]
true
d53d83a0d2217b04a1ef359105851c832a0041c4
e22af046f8dae9371066a1325d05c702dee5a5f3
v1.0
instruct
Code_Contests
Code_Contests_8497_I
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 final grade. Write a progra...
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": "", "prompt_id": "00008497", "row_id": 8497, "seed_ids": "[13132]" }
0.726487
Code_Contests_8497
I
[ "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
370aedcf393056755ace76a85388fa6a89028d53
acb6c7c613ff080b57a1fb761645855802723947
v1.0
instruct
Code_Contests
Code_Contests_8534_I
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 a direct subordinate of the p...
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": "", "prompt_id": "00008534", "row_id": 8534, "seed_ids": "[1970]" }
0.618967
Code_Contests_8534
I
[ "process_hierarchy", "evaluate_all_hierarchies" ]
2
[ [ "evaluate_all_hierarchies", "process_hierarchy" ] ]
1
[]
false
[]
false
pytest
false
[]
true
35769da80c39f44dd0e15696f9a443667651cc4f
8663906e13391566f26b9ae7c94df1af198af3ba
v1.0
instruct
Code_Contests
Code_Contests_8585_I
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 of this land, it is guarante...
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": "", "prompt_id": "00008585", "row_id": 8585, "seed_ids": "[6084]" }
0.74975
Code_Contests_8585
I
[ "floyd_warshall", "get_shortest_travel_time_matrix" ]
2
[ [ "get_shortest_travel_time_matrix", "floyd_warshall" ] ]
1
[]
false
[]
false
pytest
true
[]
true
88a44b921191647f9927e8a7116e8cef3f82d866
5edca4885973e022ec917d57826d0ab7838ec2b1
v1.0
instruct
Code_Contests
Code_Contests_8587_I
In a remote village, there is a famous bakery known for its delicious rectangular cakes. The bakery is planning to expand its facilities and distribute cakes to multiple shops in the village. For this purpose, they need to cut a large rectangular cake into smaller pieces based on specific customer orders. Each order sp...
def can_fulfill(order, selected_orders): for o in selected_orders: if not (order[2] < o[0] or order[0] > o[2] or order[3] < o[1] or order[1] > o[3]): return False return True def max_non_overlapping_orders(n, m, k, orders): fulfilled_orders = [] for order in orders: if ...
from solution import max_non_overlapping_orders def test_example_1(): n, m, k = 4, 5, 3 orders = [(1, 1, 2, 3), (2, 2, 4, 5), (3, 1, 4, 3)] expected_output = [(1, 1, 2, 3), (3, 1, 4, 3)] result = max_non_overlapping_orders(n, m, k, orders) assert len(result) == len(expected_output) assert resul...
[ { "docstring": null, "function_declaration": "def can_fulfill(order, selected_orders):", "function_name": "can_fulfill", "parameter_list": "(order, selected_orders)" }, { "docstring": null, "function_declaration": "def max_non_overlapping_orders(n, m, k, orders):", "function_name": "...
[ 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 maximum_non_overlapping_orders(n, m, k, orders):\n # Function to check if two rectangles overlap\n def is_overlap(rec1, rec2):\n if rec1[2...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00008587", "row_id": 8587, "seed_ids": "[3344]" }
0.716672
Code_Contests_8587
I
[ "can_fulfill", "max_non_overlapping_orders", "main" ]
3
[ [ "max_non_overlapping_orders", "can_fulfill" ] ]
1
[]
false
[]
false
pytest
true
[]
true
327f7b52fa2e82489d614ee3372530d4dd698474
0993ba2379d7227189e467aa21ef7f114fcd46ff
v1.0
instruct
Code_Contests
Code_Contests_8607_I
A city is trying to manage its traffic by controlling a set of traffic lights. The city's grid of streets can be represented as a graph where intersections are nodes and streets are edges connecting the nodes. Each street has a length and a traffic light at one end of the street. The traffic light at the start of a st...
import heapq import sys def find_minimum_time(n, m, start, end, streets): graph = [[] for _ in range(n + 1)] for u, v, length, t_i in streets: graph[u].append((v, length, t_i)) graph[v].append((u, length, t_i)) # PriorityQueue for Dijkstra's pq = [] heapq.heappush(pq, (0, start...
def test_example(): n = 5 m = 6 start = 1 end = 5 streets = [ (1, 2, 5, 3), (2, 3, 10, 2), (1, 3, 20, 2), (3, 4, 5, 1), (4, 5, 10, 2), (3, 5, 7, 3) ] assert find_minimum_time(n, m, start, end, streets) == 25 def test_no_path(): n = 5 m...
[ { "docstring": null, "function_declaration": "def find_minimum_time(n, m, start, end, streets):", "function_name": "find_minimum_time", "parameter_list": "(n, m, start, end, streets)" }, { "docstring": null, "function_declaration": "def minimum_time_from_input():", "function_name": "...
[ 0, 0, 0, 1 ]
1
hard
0.25
{ "trial_gpt4o_0": null, "trial_gpt4o_1": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared1_results_combined.jsonl", "solution_code": "import heapq\nimport sys\n\ndef dijkstra_with_traffic_lights(n, streets, start, end):\n graph = [[] for _ in range(n + 1)]\n ...
trial_gpt4o_4
{ "original_instruction": "", "prompt_id": "00008607", "row_id": 8607, "seed_ids": "[6120]" }
0.751527
Code_Contests_8607
I
[ "find_minimum_time", "minimum_time_from_input" ]
2
[ [ "minimum_time_from_input", "find_minimum_time" ] ]
1
[]
false
[]
false
pytest
false
[]
true
89f81b36292aa4dc520e2ec304d7fe98365e3420
7396b95fb1ab6338587a022353b36035cf051412
v1.0
instruct
Code_Contests
Code_Contests_8608_I
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 two houses using this route wit...
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": "", "prompt_id": "00008608", "row_id": 8608, "seed_ids": "[5377]" }
0.683998
Code_Contests_8608
I
[ "find", "union", "kruskal", "minimum_spanning_tree" ]
4
[ [ "kruskal", "find" ], [ "kruskal", "union" ], [ "minimum_spanning_tree", "kruskal" ], [ "union", "find" ] ]
4
[]
false
[]
false
pytest
false
[]
true
f0f738cf01e641f637d34ce0f44b0d1732a697c6
74c1e5e0e04ad8f0150c8a76978a3135a40776be
v1.0
instruct
Code_Contests
Code_Contests_8646_I
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 total travel cost. Your task ...
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": "", "prompt_id": "00008646", "row_id": 8646, "seed_ids": "[6596]" }
0.738431
Code_Contests_8646
I
[ "find", "union", "kruskal", "minimum_travel_cost" ]
4
[ [ "kruskal", "find" ], [ "kruskal", "union" ], [ "minimum_travel_cost", "kruskal" ], [ "union", "find" ] ]
4
[]
false
[]
false
pytest
false
[]
true
83b59320e97f5a5ba413b34d6f097f13ac6bba5e
939ee5b2bfd87ad59744a2a0cc4d78708e485d65
v1.0
instruct
Code_Contests
Code_Contests_8703_I
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. Write a program that processes these queries efficiently. ### Input - The first line contains an integer `n` (1 ≤ n ≤ 100,000...
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": "", "prompt_id": "00008703", "row_id": 8703, "seed_ids": "[2665]" }
0.722312
Code_Contests_8703
I
[ "preprocess", "query", "process_queries" ]
3
[ [ "process_queries", "preprocess" ], [ "process_queries", "query" ] ]
2
[ "process_queries" ]
false
[]
false
pytest
false
[]
true
fed53ea0ad407f67f45c1c01ca6f4e0f042ed4d1
a9fe5f5314f3a48b9871b57d62bfb393e0b85bdb
v1.0
instruct
Code_Contests
Code_Contests_8769_I
A software company wants to distribute badges among its employees based on their scores. The number of badges each employee receives should satisfy the following conditions: 1. Each employee must receive at least one badge. 2. Employees with a higher score should receive more badges than their immediate lower score ne...
def minimum_badges_required(num_cases, cases): results = [] for case in cases: n, scores = case if n == 0: results.append(0) continue badges = [1] * n # Forward pass for i in range(1, n): if scores[i] > scores[i - 1]: ...
def test_minimum_badges_required(): input_text = "3\n3\n1 2 2\n4\n4 6 4 5\n5\n1 2 3 4 5\n" expected_output = [4, 6, 15] assert badges_solver(input_text) == expected_output def test_minimum_badges_all_same_scores(): input_text = "1\n4\n7 7 7 7\n" expected_output = [4] assert badges_solver(input_...
[ { "docstring": null, "function_declaration": "def minimum_badges_required(num_cases, cases):", "function_name": "minimum_badges_required", "parameter_list": "(num_cases, cases)" }, { "docstring": null, "function_declaration": "def read_input_format(input_text):", "function_name": "re...
[ 0, 0, 1 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def compute_badges(t, test_cases):\n results = []\n for i in range(t):\n n = test_cases[i][0]\n scores = test_cases[i][1]\n if n...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00008769", "row_id": 8769, "seed_ids": "[7732]" }
0.705351
Code_Contests_8769
I
[ "minimum_badges_required", "read_input_format", "badges_solver" ]
3
[ [ "badges_solver", "minimum_badges_required" ], [ "badges_solver", "read_input_format" ] ]
2
[]
false
[]
false
pytest
false
[]
true
b1b6690d2b1a2df6ef2a865acbcd330b698a7192
a6177e9f98fd8d862999c325e793b562e6d0e17d
v1.0
instruct
Code_Contests
Code_Contests_8786_I
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. Constraints * $-100 \leq x_1, y_1, x_2, y_2, x_3, y_3, x_p, y_p \leq 100$ Input Eight integers $x_1, y_1, x_2, y_2, x_3, y_3, x_...
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": "", "prompt_id": "00008786", "row_id": 8786, "seed_ids": "[11975]" }
0.728304
Code_Contests_8786
I
[ "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
8c68a7ba3b31f2ac7cdc34d73ae3bbaf36f76243
140c3d0166720e68c61db20948d2010626b0d40a
v1.0
instruct
Code_Contests
Code_Contests_8800_I
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. Each node in this binary tree has a value, and ev...
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": "", "prompt_id": "00008800", "row_id": 8800, "seed_ids": "[9078]" }
0.622459
Code_Contests_8800
I
[ "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
410e658764ac609f911ddcc974568966d477a0b2
6430118f232f85d244cb12109811a243b82c82c6
v1.0
instruct
Code_Contests
Code_Contests_8843_I
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 address and a subnet mask as input ...
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": "", "prompt_id": "00008843", "row_id": 8843, "seed_ids": "[10510]" }
0.524253
Code_Contests_8843
I
[ "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
1f1735531746dc7009c822688e64a23a8fae5dec
50ae7aa60c9057a4720a5ebafdead17a59f38704
v1.0
instruct
Code_Contests
Code_Contests_8898_I
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 server has a load capacity, which is the maximum load it can handl...
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": "", "prompt_id": "00008898", "row_id": 8898, "seed_ids": "[1743]" }
0.653512
Code_Contests_8898
I
[ "max_load_after_distribution", "parse_input", "process" ]
3
[ [ "process", "max_load_after_distribution" ], [ "process", "parse_input" ] ]
2
[ "parse_input" ]
false
[]
false
pytest
false
[]
true
10382ae7cceadd570c67b27cfe187b078b5836a1
7573264fcac68cb166a8206ca05a8a1f2987e78b
v1.0
instruct
Code_Contests
Code_Contests_8972_I
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 the same price, they should be...
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": "", "prompt_id": "00008972", "row_id": 8972, "seed_ids": "[7885]" }
0.642409
Code_Contests_8972
I
[ "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
8e56af0ae995310b7f4f34d4d6286d2748dc144e
5a7b1c66566b4ebbcd96a5b95151853f803e887e
v1.0
instruct
Code_Contests
Code_Contests_9026_I
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. Given an array of distinct integers, you can perform a series ...
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": "", "prompt_id": "00009026", "row_id": 9026, "seed_ids": "[10127]" }
0.716899
Code_Contests_9026
I
[ "max_subsequence_sum", "process_operations", "solve" ]
3
[ [ "process_operations", "max_subsequence_sum" ], [ "solve", "process_operations" ] ]
2
[]
false
[]
false
pytest
true
[]
true
903b6b27725f0b9eeef742603cb49eed4f4a0bdc
83fc7abcd0a4cfa876c5121f1096004b735ca9f8
v1.0
instruct
Code_Contests
Code_Contests_9047_I
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 degrees. Julia wants to catal...
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": "", "prompt_id": "00009047", "row_id": 9047, "seed_ids": "[2975]" }
0.672609
Code_Contests_9047
I
[ "is_right_angle", "are_all_subsets_right_angled" ]
2
[ [ "are_all_subsets_right_angled", "is_right_angle" ] ]
1
[]
false
[]
false
pytest
true
[]
true
3f8799d7104fb8682f8fa9055228fbc7b81e114c
c74a964877f61c1229800ab37ce3d6d33c9928b2
v1.0
instruct
Code_Contests
Code_Contests_9071_I
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 occurs an odd number of times...
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": "", "prompt_id": "00009071", "row_id": 9071, "seed_ids": "[13292]" }
0.771238
Code_Contests_9071
I
[ "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
aef8dfe9673ea670e049d6eded5d598b2ddfc173
cb36cf3bdae0d30b2e9c80ee0d8cafa0c01f6a4d
v1.0
instruct
Code_Contests
Code_Contests_9078_I
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 positions of several charact...
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": "", "prompt_id": "00009078", "row_id": 9078, "seed_ids": "[11514]" }
0.848586
Code_Contests_9078
I
[ "is_valid_move", "bfs", "solve_game" ]
3
[ [ "bfs", "is_valid_move" ], [ "solve_game", "bfs" ] ]
2
[]
false
[]
false
pytest
true
[]
true
0c2b966d93d80e98d8af254b46aca221acfb23e9
2d9f9c7aa7fe580b502bd6998015ad688ca2c6ae
v1.0
instruct
Code_Contests
Code_Contests_9102_I
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 followed by a list of multiple-...
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": "", "prompt_id": "00009102", "row_id": 9102, "seed_ids": "[295]" }
0.564732
Code_Contests_9102
I
[ "validate_quiz_question", "validate_quiz_questions" ]
2
[ [ "validate_quiz_questions", "validate_quiz_question" ] ]
1
[]
false
[]
false
pytest
true
[]
true
b8df71b3144b687fcb131ae40ef0aad6442bc4dc
a039530fd595915c67bc91459cc9aef9dddb5b42
v1.0
instruct
Code_Contests
Code_Contests_9121_I
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 grid while minimizing the over...
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": "", "prompt_id": "00009121", "row_id": 9121, "seed_ids": "[3143]" }
0.622327
Code_Contests_9121
I
[ "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
e6267b2b495c9e2901439bd9bd0ef260d70fe9d1
ef783e185a219038b59923a925d3f54dea7f00dd
v1.0
instruct
Code_Contests
Code_Contests_9130_I
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. A prime number is defined as a natural number greater than 1 that has no positive divis...
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": "", "prompt_id": "00009130", "row_id": 9130, "seed_ids": "[6903]" }
0.726708
Code_Contests_9130
I
[ "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
42c42e5cab40ebd53727a0635252d3e57a063478
3f3eae7dceafbfd95b00fccc7044b246f5d9e1d1
v1.0
instruct
Code_Contests
Code_Contests_9176_I
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 flows optimally through the sys...
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": "", "prompt_id": "00009176", "row_id": 9176, "seed_ids": "[2137]" }
0.705596
Code_Contests_9176
I
[ "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
98153c3f90176aa8c66c552a8c7ec8e119bc9676
78a951778c9aa7e385f7b9d07a95a22e8fd34b90
v1.0
instruct
Code_Contests
Code_Contests_9178_I
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. Your task is to determine the number of connected components in the given graph. A connected component is a subgr...
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": "", "prompt_id": "00009178", "row_id": 9178, "seed_ids": "[3123]" }
0.754676
Code_Contests_9178
I
[ "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
e83aca056e703c3f89f87b2b709cd26686e31bd3
fb9e8455ed15aaf07739467c31bee3ea71bc499f