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_45288_I
Petya loves prime numbers. He finds prime numbers fascinating and enjoys the challenge of discovering them. A prime number is a natural number greater than 1 that has no positive divisors other than 1 and itself. Petya wants to create an array of length n, where the value at each index is a prime number starting from ...
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 find_kth_prime_in_n_primes...
from solution import is_prime, find_kth_prime_in_n_primes def test_is_prime(): assert not is_prime(1) assert is_prime(2) assert is_prime(3) assert not is_prime(4) assert is_prime(5) assert not is_prime(9) assert is_prime(11) def test_find_kth_prime_in_n_primes(): assert find_kth_prime_...
[ { "docstring": null, "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": null, "function_declaration": "def find_kth_prime_in_n_primes(n, k):", "function_name": "find_kth_prime_in_n_primes", "parameter_list": "(n,...
[ 1, 0, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(num):\n if num <= 1:\n return False\n if num <= 3:\n return True\n if num % 2 == 0 or num % 3 == 0:\n return Fal...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00045288", "row_id": 45288, "seed_ids": "[4393]" }
0.72124
Code_Contests_45288
I
[ "is_prime", "find_kth_prime_in_n_primes" ]
2
[ [ "find_kth_prime_in_n_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
d589b6dd78a289c1a0b1bbefea9dbd9aeb4a48fe
77a5571017c30d8e411c5a1ed728c9c4c2286488
v1.0
instruct
Code_Contests
Code_Contests_45336_I
Consider a robot that is placed on a 2D grid. The grid has n rows and m columns. Each cell in the grid can either be empty or contain an obstacle. The robot can move one step at a time to any of its four neighboring cells - up, down, left, or right, but it cannot move into a cell that contains an obstacle. The robot s...
from collections import deque def is_valid(x, y, n, m, grid, visited): return 0 <= x < n and 0 <= y < m and grid[x][y] == '.' and not visited[x][y] def bfs(grid, start, end, n, m): directions = [(-1,0), (1,0), (0,-1), (0,1)] queue = deque([(start[0], start[1], 0)]) # (x, y, distance) visited = [[False...
import pytest from solution import min_steps_to_and_return def test_min_steps_example_1(): grid = [ ".....", "....#", "##...", "...#.", "....." ] assert min_steps_to_and_return(5, 5, grid) == 16 def test_min_steps_example_2(): grid = [ ".#.", "##...
[ { "docstring": null, "function_declaration": "def is_valid(x, y, n, m, grid, visited):", "function_name": "is_valid", "parameter_list": "(x, y, n, m, grid, visited)" }, { "docstring": null, "function_declaration": "def bfs(grid, start, end, n, m):", "function_name": "bfs", "param...
[ 0, 1, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "from collections import deque\n\ndef bfs(grid, start, end):\n n, m = len(grid), len(grid[0])\n visited = [[False for _ in range(m)] for _ in range(n)...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00045336", "row_id": 45336, "seed_ids": "[7201]" }
0.7825
Code_Contests_45336
I
[ "is_valid", "bfs", "min_steps_to_and_return" ]
3
[ [ "bfs", "is_valid" ], [ "min_steps_to_and_return", "bfs" ] ]
2
[]
false
[]
false
pytest
true
[]
true
6734f2eb82ceb2930bdbd2827e2096b160733366
82c7ca93cb6f04a54b43cd3e7fd72c515e14efb6
v1.0
instruct
Code_Contests
Code_Contests_45411_I
Problem Statement: Alice loves to play with numbers, and she's particularly fascinated by prime numbers. One day she came up with a problem for herself: Given an integer 'x', she wants to find all the prime numbers less than or equal to 'x' that contain the digit '7'. Being new to programming, Alice needs your help t...
def sieve_of_eratosthenes(n): """ Returns a list of all primes less than or equal to n using the Sieve of Eratosthenes algorithm. """ prime = [True for _ in range(n+1)] p = 2 while (p * p <= n): if prime[p] == True: for i in range(p * p, n + 1, p): prime[i] = ...
from solution import sieve_of_eratosthenes, primes_with_digit_7, solve_queries def test_sieve_of_eratosthenes(): assert sieve_of_eratosthenes(10) == [2, 3, 5, 7] assert sieve_of_eratosthenes(30) == [2, 3, 5, 7, 11, 13, 17, 19, 23, 29] assert sieve_of_eratosthenes(100) == [2, 3, 5, 7, 11, 13, 17, 19, 23, 29...
[ { "docstring": "Returns a list of all primes less than or equal to n using the Sieve of Eratosthenes algorithm.", "function_declaration": "def sieve_of_eratosthenes(n):", "function_name": "sieve_of_eratosthenes", "parameter_list": "(n)" }, { "docstring": null, "function_declaration": "de...
[ 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 sieve(n):\n \"\"\"\n Returns a list of boolean values representing whether numbers up to n are prime.\n \"\"\"\n is_prime = [True] * (n + 1...
trial_gpt4o_4
{ "original_instruction": "", "prompt_id": "00045411", "row_id": 45411, "seed_ids": "[12988]" }
0.593381
Code_Contests_45411
I
[ "sieve_of_eratosthenes", "primes_with_digit_7", "solve_queries", "main" ]
4
[ [ "primes_with_digit_7", "sieve_of_eratosthenes" ], [ "solve_queries", "primes_with_digit_7" ] ]
2
[ "solve_queries" ]
false
[]
false
pytest
true
[]
true
30e4fa84aeeeb4708bf04a979f5d95c9dca92b4c
0cb791660d237b282f22692e4a9115e69250a12b
v1.0
instruct
Code_Contests
Code_Contests_45436_I
A city is planning to develop a new water distribution system to supply water to all its neighborhoods. The system will include pipes connecting the neighborhoods to ensure water from the central water source can reach every neighborhood. The city consists of n neighborhoods, numbered from 1 to n. There is a direct pi...
def find(parent, i): if parent[i] == i: return i 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[rootX] = rootY elif rank[rootX] > rank[root...
def test_minimum_cost_to_construct_network_case1(): n = 4 m = 5 pipelines = [ (1, 2, 3), (2, 3, 4), (3, 4, 5), (1, 3, 1), (1, 4, 10) ] assert minimum_cost_to_construct_network(n, m, pipelines) == 9 def test_minimum_cost_to_construct_network_case2(): n = 3...
[ { "docstring": null, "function_declaration": "def find(parent, i):", "function_name": "find", "parameter_list": "(parent, i)" }, { "docstring": null, "function_declaration": "def union(parent, rank, x, y):", "function_name": "union", "parameter_list": "(parent, rank, x, y)" }, ...
[ 0, 1, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def find_minimum_cost(n, m, pipelines):\n \"\"\"\n Finds the minimum cost required to construct a water distribution network linking all neighborhood...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00045436", "row_id": 45436, "seed_ids": "[5957]" }
0.673078
Code_Contests_45436
I
[ "find", "union", "kruskal_mst", "minimum_cost_to_construct_network" ]
4
[ [ "kruskal_mst", "find" ], [ "kruskal_mst", "union" ], [ "minimum_cost_to_construct_network", "kruskal_mst" ], [ "union", "find" ] ]
4
[]
false
[]
false
pytest
false
[]
true
4f674e918d749f4ff6fad32f47506640e3a63913
4dda262e2fcd3fd15575f6f3ca816ff413963487
v1.0
instruct
Code_Contests
Code_Contests_45482_I
Palindrome Partitioning Constraints * 1 ≤ s.length ≤ 20 * s consists only of lowercase English letters. Input A single string s. Output Return all possible palindrome partitioning of s as a list of lists. Example Input "aab" Output [ ["a","a","b"], ["aa","b"] ] Explanation The string "aab" can be parti...
def is_palindrome(sub): return sub == sub[::-1] def partition(s): result = [] def backtrack(start, path): if start == len(s): result.append(path[:]) return for end in range(start + 1, len(s) + 1): if is_palindrome(s[start:end]): ...
from solution import partition def test_partition_single_char(): result = partition("a") assert result == [["a"]], f"Unexpected result: {result}" def test_partition_two_chars(): result = partition("aa") assert result == [["a", "a"], ["aa"]], f"Unexpected result: {result}" def test_partition_diffe...
[ { "docstring": null, "function_declaration": "def is_palindrome(sub):", "function_name": "is_palindrome", "parameter_list": "(sub)" }, { "docstring": null, "function_declaration": "def partition(s):", "function_name": "partition", "parameter_list": "(s)" }, { "docstring":...
[ 0, 1, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_palindrome(s):\n return s == s[::-1]\n\ndef partition(s):\n def backtrack(start, path):\n if start == len(s):\n result.appen...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00045482", "row_id": 45482, "seed_ids": "[4583]" }
0.729056
Code_Contests_45482
I
[ "is_palindrome", "partition" ]
2
[ [ "partition", "is_palindrome" ] ]
1
[]
false
[]
false
pytest
true
[]
true
933cc95295b6ecc12f1d3b392d02aca915124eaa
d87c77788f0cadc16638ab811646863ff7e9d6c7
v1.0
instruct
Code_Contests
Code_Contests_45505_I
Professor Ana is working on a special sequence of integers. She defines an Ana Number as a positive integer where the sum of the factorials of its digits equals the number itself. For example, 145 is an Ana Number, because 1! + 4! + 5! = 1 + 24 + 120 = 145. Your task is to write a program that finds all Ana Numbers le...
import math def is_ana_number(num): """ Check if a number is an Ana Number. An Ana Number is a positive integer where the sum of the factorial of its digits equals the number itself. """ return num == sum(math.factorial(int(digit)) for digit in str(num)) def find_ana_numbers(n): """ Find a...
from solution import is_ana_number, find_ana_numbers def test_is_ana_number(): assert is_ana_number(1) == True assert is_ana_number(2) == True assert is_ana_number(145) == True assert is_ana_number(123) == False def test_find_ana_numbers(): assert find_ana_numbers(150) == [1, 2, 145] assert fi...
[ { "docstring": "Check if a number is an Ana Number.\nAn Ana Number is a positive integer where the sum of the factorial of its digits equals the number itself.", "function_declaration": "def is_ana_number(num):", "function_name": "is_ana_number", "parameter_list": "(num)" }, { "docstring": "...
[ 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_ana_number(num):\n \"\"\"\n Check if the given number is an Ana Number.\n \"\"\"\n return num == sum(math.factorial(int(d...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00045505", "row_id": 45505, "seed_ids": "[12955]" }
0.576877
Code_Contests_45505
I
[ "is_ana_number", "find_ana_numbers" ]
2
[ [ "find_ana_numbers", "is_ana_number" ] ]
1
[]
false
[]
false
pytest
true
[]
true
7046f6cb203094932d1d8deba548f48bde06d21e
beb9153db2d5fa96636d1a246f789e39dbece9e6
v1.0
instruct
Code_Contests
Code_Contests_45517_I
A computer has a list of N integers that needs to be processed. The task is to identify the "peak elements" in the list. A peak element is defined as an element that is strictly greater than its neighbors. For an element a[i] to be a peak element, the following conditions should hold true: - If i > 0, then a[i] > a[i...
def find_peaks(N, arr): """ Finds the positions of all the peak elements in the list. Parameters: - N (int): Number of elements in the list. - arr (list of int): The list of integers. Returns: - list of int: The positions of all the peak elements. """ peaks = [] if...
from solution import find_peaks def test_single_element(): assert find_peaks(1, [10]) == [0] def test_all_decreasing(): assert find_peaks(6, [9, 8, 7, 6, 5, 4]) == [0] def test_mixed_elements(): assert find_peaks(5, [1, 3, 2, 4, 3]) == [1, 3] def test_no_peaks(): assert find_peaks(4, [11, 11, 11, 11...
[ { "docstring": "Finds the positions of all the peak elements in the list.\n\nParameters:\n- N (int): Number of elements in the list.\n- arr (list of int): The list of integers.\n\nReturns:\n- list of int: The positions of all the peak elements.", "function_declaration": "def find_peaks(N, arr):", "funct...
[ 1, 1, 0 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def find_peaks(n, array):\n \"\"\"\n Finds the peak elements in the given list of integers and returns their positions.\n\n Parameters:\n n (in...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00045517", "row_id": 45517, "seed_ids": "[2273]" }
0.72799
Code_Contests_45517
I
[ "find_peaks", "print_peaks" ]
2
[ [ "print_peaks", "find_peaks" ] ]
1
[]
false
[]
false
pytest
true
[]
true
a09ec9e1301f2ac9a4e8c7072517218d8a24b016
38dc6d6e093bc3bc728e4c63f142ba4da87f703d
v1.0
instruct
Code_Contests
Code_Contests_45521_I
**Question: Matrix Transformation** Given an `n x n` matrix, determine if it is possible to transform it into an identity matrix by rotating its rows and columns. You can rotate any row or column such that the last element becomes the first one and all other elements shift one position to the right (for rows) or down ...
def can_transform_to_identity(n, matrix): # Check if every row contains exactly one 1 for row in matrix: if row.count(1) != 1: return "NO" # Check if every column contains exactly one 1 for col in range(n): col_count = 0 for row in range(n): if matrix...
from solution import matrix_transformation_possible def test_example1(): n = 2 matrix = [ [0, 1], [1, 0] ] assert matrix_transformation_possible(n, matrix) == "YES" def test_example2(): n = 3 matrix = [ [1, 2, 3], [4, 5, 6], [7, 8, 9] ] assert ma...
[ { "docstring": null, "function_declaration": "def can_transform_to_identity(n, matrix):", "function_name": "can_transform_to_identity", "parameter_list": "(n, matrix)" }, { "docstring": null, "function_declaration": "def matrix_transformation_possible(n, matrix):", "function_name": "...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def can_transform_to_identity(n, matrix):\n # Check if every row contains exactly one 1\n for row in matrix:\n if row.count(1) != 1:\n ...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00045521", "row_id": 45521, "seed_ids": "[4746]" }
0.557126
Code_Contests_45521
I
[ "can_transform_to_identity", "matrix_transformation_possible" ]
2
[ [ "matrix_transformation_possible", "can_transform_to_identity" ] ]
1
[]
false
[]
false
pytest
true
[]
true
ae53934deb3f9a5cb8f7e340d7b5321b455298e7
ebca7190546bede30f1ec21f77dc2ec08584884c
v1.0
instruct
Code_Contests
Code_Contests_45595_I
### Travel Route Optimization You are a tour guide planning to organize trips for tourists in a city. The city has numerous attractions, and there are multiple possible routes connecting different attractions. Your goal is to plan the shortest possible route that visits each attraction exactly once and returns to the ...
from itertools import permutations def tsp_minimum_distance(d): N = len(d) min_distance = float('inf') # Generate all possible routes (permutations) for perm in permutations(range(N)): # Calculate the distance of this route distance = 0 for i in range(N): distan...
from solution import travel_route_optimization, parse_input def test_travel_route_optimization(): input_text = "2\n0 10\n10 0\n3\n0 29 20\n29 0 15\n20 15 0\n0" expected_output = [20, 64] datasets = parse_input(input_text) assert travel_route_optimization(datasets) == expected_output def test_travel_r...
[ { "docstring": null, "function_declaration": "def tsp_minimum_distance(d):", "function_name": "tsp_minimum_distance", "parameter_list": "(d)" }, { "docstring": null, "function_declaration": "def travel_route_optimization(datasets):", "function_name": "travel_route_optimization", ...
[ 1, 1 ]
2
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "import itertools\n\ndef tsp_brute_force(dist_matrix):\n \"\"\"\n Solve the Traveling Salesman Problem using brute force method.\n Parameters:\n ...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00045595", "row_id": 45595, "seed_ids": "[6246]" }
0.704004
Code_Contests_45595
I
[ "tsp_minimum_distance", "travel_route_optimization", "parse_input" ]
3
[ [ "travel_route_optimization", "tsp_minimum_distance" ] ]
1
[ "parse_input" ]
false
[]
false
pytest
true
[]
true
3c22e851aa604d8e6dd9500ab9f3887ba775ec4e
b5deca1e835a2a797b8cf672aa459d0fb61e4cc5
v1.0
instruct
Code_Contests
Code_Contests_45665_I
Your task is to help Takahashi manage his food inventory. He has a list of \(N\) food items, each identified by a unique integer ID from \(1\) to \(N\). Each food item has an associated expiration date, represented as a non-negative integer \(e_i\), where \(0\) means the food item never expires. Takahashi wants to sto...
from bisect import bisect_right def preprocess_expiration_dates(expiration_dates): """ Preprocess the list of expiration dates by sorting them. """ expiration_dates.sort() def count_expired_items_by_day(expiration_dates, day): """ Count the number of food items that will expire on or before a ...
from solution import handle_queries def test_example_case(): expiration_dates = [2, 3, 1, 4, 0] queries = [0, 3, 10] expected_output = [1, 4, 5] assert handle_queries(expiration_dates, queries) == expected_output def test_all_never_expire(): expiration_dates = [0, 0, 0, 0, 0] queries = [0, 1, ...
[ { "docstring": "Preprocess the list of expiration dates by sorting them.", "function_declaration": "def preprocess_expiration_dates(expiration_dates):", "function_name": "preprocess_expiration_dates", "parameter_list": "(expiration_dates)" }, { "docstring": "Count the number of food items th...
[ 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 preprocess_expiration_dates(expiration_dates):\n \"\"\"\n Preprocess the list of expiration dates to facilitate quick querying.\n \"\"\"\n ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00045665", "row_id": 45665, "seed_ids": "[1334]" }
0.643866
Code_Contests_45665
I
[ "preprocess_expiration_dates", "count_expired_items_by_day", "handle_queries" ]
3
[ [ "handle_queries", "count_expired_items_by_day" ], [ "handle_queries", "preprocess_expiration_dates" ] ]
2
[ "handle_queries" ]
false
[]
false
pytest
true
[]
true
3d5de977924bf4d035c44af52b2b4330519a2a61
875f3b083e8abbb70222c3de76e2f14ffd06120c
v1.0
instruct
Code_Contests
Code_Contests_45773_I
Shiro is an avid collector of antique coins. He arranges his coins in a straight line on a shelf. Each coin has a unique value assigned to it, and he wants to know the most valuable sub-segment of his collection. A sub-segment is defined as a continuous portion of the line of coins. Given the values of the coins, help...
def maxSubArraySum(values): """ Function to find the sum of the most valuable sub-segment Args: values : List[int] : List containing values of coins Returns: int : Maximum sub-segment sum """ max_sum = values[0] current_sum = values[0] for i in range(1, len(values)): cu...
from solution import find_maximum_sub_segment_sum def test_single_value(): assert find_maximum_sub_segment_sum(1, [5]) == 5 def test_all_positive(): assert find_maximum_sub_segment_sum(5, [1, 2, 3, 4, 5]) == 15 def test_all_negative(): assert find_maximum_sub_segment_sum(3, [-1, -2, -3]) == -1 def test_...
[ { "docstring": "Function to find the sum of the most valuable sub-segment\nArgs:\nvalues : List[int] : List containing values of coins\n\nReturns:\nint : Maximum sub-segment sum", "function_declaration": "def maxSubArraySum(values):", "function_name": "maxSubArraySum", "parameter_list": "(values)" ...
[ 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_subsegment_sum(N, coins):\n \"\"\"\n Returns the sum of the most valuable sub-segment.\n \"\"\"\n max_sum = current_sum = coins[0]\n ...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00045773", "row_id": 45773, "seed_ids": "[1978]" }
0.665267
Code_Contests_45773
I
[ "maxSubArraySum", "find_maximum_sub_segment_sum" ]
2
[ [ "find_maximum_sub_segment_sum", "maxSubArraySum" ] ]
1
[]
false
[]
false
pytest
true
[]
true
c8291740416ed562b4beb94f6dcca92f8a8534de
ba15bf1ff308ec3adf7b25982e7d0001aac9fe97
v1.0
instruct
Code_Contests
Code_Contests_45794_I
B: Sudoku Validator problem Sudoku is a popular number puzzle consisting of a 9x9 grid divided into nine 3x3 subgrids, where the objective is to fill the grid with digits from 1 to 9. Each digit must appear exactly once in each row, column, and 3x3 subgrid. Given a partially filled Sudoku board, you need to determin...
def is_valid_sudoku(board): """ Check if a given 9x9 Sudoku board is valid. :param board: List[List[str]] - A 2D list representing the Sudoku board :return: bool - True if the current state of the board is valid, otherwise False """ # Use sets to keep track of seen numbers in rows, columns ...
from solution import validate_sudoku def test_valid_sudoku(): board = [ ['5', '3', '.', '.', '7', '.', '.', '.', '.'], ['6', '.', '.', '1', '9', '5', '.', '.', '.'], ['.', '9', '8', '.', '.', '.', '.', '6', '.'], ['8', '.', '.', '.', '6', '.', '.', '.', '3'], ['4', '.', '.',...
[ { "docstring": "Check if a given 9x9 Sudoku board is valid.\n\n:param board: List[List[str]] - A 2D list representing the Sudoku board\n:return: bool - True if the current state of the board is valid, otherwise False", "function_declaration": "def is_valid_sudoku(board):", "function_name": "is_valid_sud...
[ 0, 0, 0, 1 ]
1
hard
0.25
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_valid_sudoku(board):\n \"\"\"\n Validates the current state of the Sudoku board.\n \n Parameters:\n board (List[List[str]]): 9x9 grid...
trial_gpt4o_3
{ "original_instruction": "", "prompt_id": "00045794", "row_id": 45794, "seed_ids": "[3749]" }
0.71748
Code_Contests_45794
I
[ "is_valid_sudoku", "validate_sudoku" ]
2
[ [ "validate_sudoku", "is_valid_sudoku" ] ]
1
[]
false
[]
false
pytest
true
[]
true
b32998fbde5ed409bbb94ebb41344cfd44d2073d
9d6502f173887c21a5699f03be15efebe5e5afc9
v1.0
instruct
Code_Contests
Code_Contests_45816_I
Late at night, you were stargazing on a rooftop when you saw a peculiar constellation. The constellation is formed by `n` stars placed on a 2D coordinate plane. Each star is represented as a point `(xi, yi)`. Your task is to determine if the stars form a polygon that resembles a regular polygon when viewed from any tw...
import math def is_regular_polygon(n, points): # Helper to calculate distance between two points def distance(p1, p2): return math.sqrt((p1[0] - p2[0])**2 + (p1[1] - p2[1])**2) # Calculate the distances between consecutive points sides = [distance(points[i], points[(i + 1) % n]) for i in range...
from solution import is_regular_polygon def test_square(): points = [(0, 0), (2, 0), (2, 2), (0, 2)] assert is_regular_polygon(4, points) == "YES" def test_triangle(): points = [(0, 0), (1, 1), (2, 0)] assert is_regular_polygon(3, points) == "NO" def test_regular_hexagon(): points = [(1, 0), (0.5...
[ { "docstring": null, "function_declaration": "def is_regular_polygon(n, points):", "function_name": "is_regular_polygon", "parameter_list": "(n, points)" }, { "docstring": null, "function_declaration": "def solve():", "function_name": "solve", "parameter_list": "()" }, { ...
[ 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 is_regular_polygon(points):\n import math\n \n def distance(p1, p2):\n return math.sqrt((p2[0] - p1[0])**2 + (p2[1] - p1[1])**2)\n \...
trial_gpt4o_7
{ "original_instruction": "", "prompt_id": "00045816", "row_id": 45816, "seed_ids": "[6140]" }
0.558872
Code_Contests_45816
I
[ "is_regular_polygon", "solve" ]
2
[ [ "solve", "is_regular_polygon" ] ]
1
[]
false
[]
false
pytest
true
[]
true
5c96567a7a3440c65f320aecc900e58c2e961579
c6fe658b0e65fb10202db3c5e057dc3af5b7f15a
v1.0
instruct
Code_Contests
Code_Contests_45824_I
You are given the task of constructing the highest possible integer value from a list of non-negative integers. However, this new integer should be as large as possible when the numbers are concatenated together in any order. Write a function `largestNumber(nums)` that accepts a list `nums` of non-negative integers an...
from functools import cmp_to_key def compare(a, b): """ Custom comparator for sorting the numbers. It returns: - a negative number when a + b is greater than b + a - a positive number when a + b is less than b + a - zero when a + b is equal to b + a """ if a + b > b + a: return ...
from solution import largestNumber def test_example_case_1(): assert largestNumber([10, 2]) == "210" def test_example_case_2(): assert largestNumber([3, 30, 34, 5, 9]) == "9534330" def test_single_element(): assert largestNumber([1]) == "1" def test_double_digit(): assert largestNumber([10]) == "10"...
[ { "docstring": "Custom comparator for sorting the numbers.\nIt returns:\n- a negative number when a + b is greater than b + a\n- a positive number when a + b is less than b + a\n- zero when a + b is equal to b + a", "function_declaration": "def compare(a, b):", "function_name": "compare", "parameter...
[ 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 functools import cmp_to_key\n\ndef custom_compare(x, y):\n if x + y > y + x:\n return -1\n elif x + y < y + x:\n return 1\n els...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00045824", "row_id": 45824, "seed_ids": "[6227]" }
0.705126
Code_Contests_45824
I
[ "compare", "largestNumber" ]
2
[ [ "largestNumber", "compare" ] ]
1
[]
false
[]
false
pytest
true
[]
true
c48997ac033e372f1b1d8340bb6e8467962f9820
a662434efa5789338cc98e3b21a012c0f7b4c014
v1.0
instruct
Code_Contests
Code_Contests_45927_I
Sam is working on a data-driven project that involves analyzing a collection of strings. Each string is composed exclusively of lower case alphabets. After pre-processing, he generates a list where each element is a string. The final task is to identify special strings in this list. A string is considered special if no...
def is_subsequence(small, large): it = iter(large) return all(char in it for char in small) def find_special_strings(t, test_cases): results = [] for i in range(t): n = test_cases[i][0] strings = test_cases[i][1] special_strings = [] for s in strings: ...
from solution import is_subsequence, find_special_strings def test_is_subsequence(): assert is_subsequence("ab", "abc") assert not is_subsequence("abc", "ab") assert is_subsequence("abc", "aabbcc") assert not is_subsequence("acb", "abc") def test_find_special_strings(): assert find_special_strings...
[ { "docstring": null, "function_declaration": "def is_subsequence(small, large):", "function_name": "is_subsequence", "parameter_list": "(small, large)" }, { "docstring": null, "function_declaration": "def find_special_strings(t, test_cases):", "function_name": "find_special_strings",...
[ 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 is_subsequence(small, large):\n it = iter(large)\n return all(char in it for char in small)\n \ndef find_special_strings(test_cases):\n res...
trial_gpt4o_7
{ "original_instruction": "", "prompt_id": "00045927", "row_id": 45927, "seed_ids": "[8610]" }
0.69641
Code_Contests_45927
I
[ "is_subsequence", "find_special_strings" ]
2
[ [ "find_special_strings", "is_subsequence" ] ]
1
[]
false
[]
false
pytest
true
[]
true
d497a50fff47366d72ca863ab03e08035b5ada28
8a651f1f839c336eab99e7c6ed76321b514ab174
v1.0
instruct
Code_Contests
Code_Contests_45975_I
An online store has n items, each with a unique item ID and a rating. You have to process q queries from users, each query asking for the best item from a particular range of item IDs. The best item is defined as the one with the highest rating in the queried range. Write a solution to handle these queries efficiently...
class SegmentTree: def __init__(self, data): n = len(data) self.n = n self.tree = [None] * (2 * n) for i in range(n): self.tree[n + i] = data[i] for i in range(n - 1, 0, -1): self.tree[i] = self._merge(self.tree[2 * i], self.tree[2 * i + 1]) def _...
def test_solution(): assert solve(4, [(1, 100), (2, 50), (3, 120), (4, 80)], 2, [(1, 3), (2, 4)]) == [3, 3] assert solve(5, [(1, -5), (2, -2), (3, -1), (4, -2), (5, -5)], 3, [(1, 2), (3, 5), (1, 5)]) == [2, 3, 3] assert solve(3, [(1, 5), (2, 5), (3, 5)], 2, [(1, 2), (2, 3)]) == [1, 2] assert solve(6, [(...
[]
[ 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": "class SegmentTree:\n def __init__(self, data):\n self.n = len(data)\n self.data = data\n self.tree = [None] * (2 * self.n)\n ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00045975", "row_id": 45975, "seed_ids": "[10688]" }
0.646632
Code_Contests_45975
I
[ "preprocess", "process_queries", "solve" ]
3
[ [ "solve", "preprocess" ], [ "solve", "process_queries" ] ]
2
[ "process_queries" ]
false
[ "SegmentTree" ]
true
pytest
false
[]
true
b7276f8e0a7050747e310914db0cea36965fdb96
12f0b94516332c0f26085d3ae4c41e9cbe680a54
v1.0
instruct
Code_Contests
Code_Contests_46042_I
You are given a dense forest with n trees. Each tree is located at a distinct point in a 2D plane. There is a ranger who needs to travel from one tree to another to mark all trees with a special mark for research purposes. The ranger can travel only vertically or horizontally from one tree to another, never diagonally,...
import itertools def calculate_distance(x1, y1, x2, y2): return abs(x1 - x2) + abs(y1 - y2) def minimal_total_distance(n, trees): if n == 1: return 0 # If there's only one tree, no travel is needed. min_distance = float('inf') for perm in itertools.permutations(range(n)): cu...
from solution import minimal_total_distance def test_minimal_total_distance(): assert minimal_total_distance(4, [(0, 0), (10, 10), (10, 0), (0, 10)]) == 40 assert minimal_total_distance(3, [(1, 1), (2, 2), (3, 3)]) == 8 assert minimal_total_distance(1, [(5, 5)]) == 0 assert minimal_total_distance(2, [(...
[ { "docstring": null, "function_declaration": "def calculate_distance(x1, y1, x2, y2):", "function_name": "calculate_distance", "parameter_list": "(x1, y1, x2, y2)" }, { "docstring": null, "function_declaration": "def minimal_total_distance(n, trees):", "function_name": "minimal_total...
[ 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 itertools\n\ndef calculate_manhattan_distance(point1, point2):\n \"\"\"Calculate the Manhattan distance between two points.\"\"\"\n return abs...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00046042", "row_id": 46042, "seed_ids": "[12850]" }
0.642204
Code_Contests_46042
I
[ "calculate_distance", "minimal_total_distance" ]
2
[ [ "minimal_total_distance", "calculate_distance" ] ]
1
[]
false
[]
false
pytest
true
[]
true
5b0a4cf252cdd14886bb88d9ce7153d90f0bafb2
543a52182560a46343475fd5af3856bd3049a2e3
v1.0
instruct
Code_Contests
Code_Contests_46099_I
Given two positive integers N and K, determine the number of ways to divide N distinct colors of paint into K groups such that each group contains at least one color. The answer can be very large, so return the result modulo a prime number P. Constraints: - 1 <= N <= 1000 - 1 <= K <= N - 10^8 <= P <= 10^9 + 7 - P is a...
def stirling_second_kind(n, k, p): """ Calculate the Stirling number of the second kind modulo p. """ dp = [[0] * (k + 1) for _ in range(n + 1)] dp[0][0] = 1 for i in range(1, n + 1): for j in range(1, k + 1): dp[i][j] = (dp[i-1][j-1] + j * dp[i-1][j]) % p r...
from solution import number_of_ways def test_number_of_ways_example1(): assert number_of_ways(4, 2, 1000000007) == 7 def test_number_of_ways_example2(): assert number_of_ways(5, 3, 998244353) == 25 def test_number_of_ways_example3(): assert number_of_ways(10, 5, 1000000009) == 42525 def test_number_of_w...
[ { "docstring": "Calculate the Stirling number of the second kind modulo p.", "function_declaration": "def stirling_second_kind(n, k, p):", "function_name": "stirling_second_kind", "parameter_list": "(n, k, p)" }, { "docstring": null, "function_declaration": "def number_of_ways(N, K, P):"...
[ 0, 0, 0, 0, 0, 0, 0, 1, 1 ]
2
hard
0.222
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def count_ways_to_divide_colors(n, k, p):\n \"\"\"\n Returns the number of ways to divide n distinct colors into k groups such that each group contai...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00046099", "row_id": 46099, "seed_ids": "[9659]" }
0.543582
Code_Contests_46099
I
[ "stirling_second_kind", "number_of_ways" ]
2
[ [ "number_of_ways", "stirling_second_kind" ] ]
1
[]
false
[]
false
pytest
true
[]
true
db91853924d1d5e1298d4afd9fe4d0c04bb77f6b
e05c40f978f5a5b81db30fc70b66613b38c3ad2a
v1.0
instruct
Code_Contests
Code_Contests_46142_I
Given an undirected graph with `n` vertices and `m` edges, where each edge has a positive weight, find the minimum possible weight of a spanning tree that can be formed using some (or all) of the edges of the initial graph, under the constraint that this spanning tree must be bipartite. A graph is bipartite if its ver...
class UnionFind: def __init__(self, n): self.parent = list(range(n)) self.rank = [0] * n def find(self, u): if self.parent[u] != u: self.parent[u] = self.find(self.parent[u]) return self.parent[u] def union(self, u, v): root_u = self.find(u) root...
def test_minimum_bipartite_spanning_tree(): assert minimum_bipartite_spanning_tree(5, 6, [(1-1, 2-1, 3), (1-1, 3-1, 4), (2-1, 3-1, 2), (2-1, 4-1, 5), (3-1, 5-1, 1), (4-1, 5-1, 6)]) == 11 assert minimum_bipartite_spanning_tree(3, 2, [(1-1, 2-1, 1), (2-1, 3-1, 2)]) == 3 assert minimum_bipartite_span...
[]
[ 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": "class UnionFind:\n def __init__(self, n):\n self.parent = list(range(n))\n self.rank = [1] * n\n\n def find(self, u):\n if u != ...
trial_gpt4o_4
{ "original_instruction": "", "prompt_id": "00046142", "row_id": 46142, "seed_ids": "[1505]" }
0.784477
Code_Contests_46142
I
[ "is_bipartite_dfs", "kruskal_min_bipartite_spanning_tree", "minimum_bipartite_spanning_tree" ]
3
[ [ "kruskal_min_bipartite_spanning_tree", "is_bipartite_dfs" ], [ "minimum_bipartite_spanning_tree", "kruskal_min_bipartite_spanning_tree" ] ]
2
[]
false
[ "UnionFind" ]
true
pytest
false
[]
true
1f8b2b1f9d378d97fbbf9a08a0e687f747195b3b
a9ebb95474fffb84313153a079d60d1752e92a47
v1.0
instruct
Code_Contests
Code_Contests_46161_I
You are given a forest (an acyclic undirected graph) consisting of n nodes and n - 1 edges. Each edge has a certain weight. Find two such nodes in the forest that the sum of the weights of the edges in the path between them is maximized. Note that the path between any two nodes in the graph is unique since it is a tree...
from collections import defaultdict, deque def find_farthest_node(start, graph): n = len(graph) distances = [-1] * n distances[start] = 0 max_distance = 0 farthest_node = start queue = deque([start]) while queue: current = queue.popleft() for neighbor, weight in graph[curre...
from solution import max_path_sum_in_forest def test_example_1(): n = 5 edges = [ (1, 2, 3), (2, 3, 4), (3, 4, 2), (3, 5, 1) ] assert max_path_sum_in_forest(n, edges) == 9 def test_example_2(): n = 4 edges = [ (1, 2, 5), (2, 3, 6), (3, 4,...
[ { "docstring": null, "function_declaration": "def find_farthest_node(start, graph):", "function_name": "find_farthest_node", "parameter_list": "(start, graph)" }, { "docstring": null, "function_declaration": "def max_path_sum_in_forest(n, edges):", "function_name": "max_path_sum_in_f...
[ 1, 0, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "from collections import defaultdict, deque\n\ndef find_farthest_node(start, graph):\n n = len(graph)\n distances = [-1] * n\n distances[start] = 0...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00046161", "row_id": 46161, "seed_ids": "[13282]" }
0.767102
Code_Contests_46161
I
[ "find_farthest_node", "max_path_sum_in_forest" ]
2
[ [ "max_path_sum_in_forest", "find_farthest_node" ] ]
1
[]
false
[]
false
pytest
true
[]
true
9d4fba6bec4135eef788c4354b8a347bf85fc837
afd15bf9ec03b9fbd7b86baa988e3a9f56d66e51
v1.0
instruct
Code_Contests
Code_Contests_46165_I
Alyssa loves collecting ancient books. She has found a rare book consisting of `n` infinite chapters, each of which is a string of lowercase English letters. The content of the book is represented as a sequence of `n` strings where each string corresponds to a chapter. Alyssa wants to perform `q` operations to modify ...
def update_chapters(chapters, operations): """ Update the chapters based on the given operations. Parameters: chapters (list of str): The original chapter contents. operations (list of tuple): List of operations in the form (index, new_content). Returns: list of str: The up...
from solution import update_chapters, find_lexicographically_smallest, process_operations_and_queries def test_update_chapters(): chapters = ['book', 'ancient', 'collection', 'rare', 'text'] operations = [(3, 'forgot'), (2, 'archaeic'), (4, 'manuscript')] updated_chapters = update_chapters(chapters, operat...
[ { "docstring": "Update the chapters based on the given operations.\n\nParameters:\n chapters (list of str): The original chapter contents.\n operations (list of tuple): List of operations in the form (index, new_content).\n\nReturns:\n list of str: The updated chapter contents.", "function_declarat...
[ 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 manage_book_operations_and_queries(n, chapters, operations, queries):\n # Apply all operations\n for index, new_content in operations:\n c...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00046165", "row_id": 46165, "seed_ids": "[472]" }
0.723066
Code_Contests_46165
I
[ "update_chapters", "find_lexicographically_smallest", "process_operations_and_queries" ]
3
[ [ "process_operations_and_queries", "find_lexicographically_smallest" ], [ "process_operations_and_queries", "update_chapters" ] ]
2
[]
false
[]
false
pytest
true
[]
true
8aa93e069b8bbac47e5f7884e7154af094c00da7
16ba752c3bddbc13dde3c8f25380b8a27bed3199
v1.0
instruct
Code_Contests
Code_Contests_46210_I
Given an integer `n`, generate the next `n` prime numbers in the sequence after a specified starting number `start`. A prime number is a natural number greater than 1 that cannot be formed by multiplying two smaller natural numbers. The sequence of prime numbers begins as 2, 3, 5, 7, 11, 13, 17, 19, and so on. Your ta...
def is_prime(num): """ Helper function to check if a 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 Tr...
from solution import next_n_primes def test_next_n_primes_example_1(): assert next_n_primes(10, 5) == [11, 13, 17, 19, 23] def test_next_n_primes_example_2(): assert next_n_primes(20, 3) == [23, 29, 31] def test_next_n_primes_start_0(): assert next_n_primes(0, 4) == [2, 3, 5, 7] def test_next_n_primes_s...
[ { "docstring": "Helper function to check if a number is a prime number.", "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": "Returns the next n prime numbers greater than a given start.", "function_declaration": "def ne...
[ 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 Returns whether a number is a prime number.\n \"\"\"\n if num <= 1:\n return False\n if num <= 3:\n ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00046210", "row_id": 46210, "seed_ids": "[1371]" }
0.719856
Code_Contests_46210
I
[ "is_prime", "next_n_primes" ]
2
[ [ "next_n_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
5e78b2eb253d0db0670178f4b37398d36cd072b6
528ebf7c83ed781c02d533cdf8ca491c47e3f936
v1.0
instruct
Code_Contests
Code_Contests_46239_I
Evelyn loves solving puzzles involving geometric figures. One day, she came across an interesting problem about rectangles and decided to share it with her friends. A rectangle is defined by its width and height. For each rectangle, we define its area as the product of its width and height. Given a list of rectangles,...
def smallest_enclosing_rectangle(rectangles): """ Given a list of rectangles represented by their width and height, this function returns the dimensions of the smallest possible enclosing rectangle. """ max_width, max_height = 0, 0 for w, h in rectangles: if (w > max_width): ...
import pytest from solution import parse_input_rectangle, smallest_enclosing_rectangle def test_example1(): input_string = "3\n4 6\n7 2\n5 5" assert parse_input_rectangle(input_string) == (7, 6) def test_example2(): input_string = "2\n1 8\n8 1" assert parse_input_rectangle(input_string) == (8, 8) def...
[ { "docstring": "Given a list of rectangles represented by their width and height,\nthis function returns the dimensions of the smallest possible enclosing rectangle.", "function_declaration": "def smallest_enclosing_rectangle(rectangles):", "function_name": "smallest_enclosing_rectangle", "parameter...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def smallest_enclosing_rectangle(rectangles):\n \"\"\"\n Given a list of rectangles' dimensions, find the dimensions of the smallest possible enclosi...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00046239", "row_id": 46239, "seed_ids": "[11475]" }
0.652196
Code_Contests_46239
I
[ "smallest_enclosing_rectangle", "parse_input_rectangle" ]
2
[ [ "parse_input_rectangle", "smallest_enclosing_rectangle" ] ]
1
[]
false
[]
false
pytest
true
[]
true
29739b87bec2527c7392ea758e390662bf92bf84
c3ffce392ed360cfa0ff753995217aa5686171fd
v1.0
instruct
Code_Contests
Code_Contests_46324_I
A news website has articles categorized under different topics – World, Technology, Health, Sports, and Entertainment. Each article has a unique identifier, a title, and the content of the article. The topics of the articles are identified by integers from 1 to 5: 1. World 2. Technology 3. Health 4. Sports 5. Entertai...
import os # Dummy function to simulate reading training data def load_training_data(): training_data = { 1: ["world", "global", "international", "country"], 2: ["technology", "tech", "innovation", "AI", "software", "hardware"], 3: ["health", "medicine", "disease", "wellness", "healthcare"],...
from solution import determine_topic def test_technology_article(): title = "Latest Technology Trends" content = "With the advancement in AI, the world of technology is rapidly evolving..." assert determine_topic(title, content) == 2 def test_world_article(): title = "Global News Update" content =...
[ { "docstring": null, "function_declaration": "def load_training_data():", "function_name": "load_training_data", "parameter_list": "()" }, { "docstring": null, "function_declaration": "def determine_topic(title, content):", "function_name": "determine_topic", "parameter_list": "(...
[ 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": "import os\nimport zipfile\nimport requests\nfrom collections import defaultdict\nfrom sklearn.feature_extraction.text import TfidfVectorizer\nfrom sklearn....
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00046324", "row_id": 46324, "seed_ids": "[11905]" }
0.61033
Code_Contests_46324
I
[ "load_training_data", "determine_topic" ]
2
[ [ "determine_topic", "load_training_data" ] ]
1
[]
false
[]
false
pytest
true
[]
true
1d39592da56e0d2eb2d26cc73b214b58428f1fc4
ff8fd5273da1a7033d799f68037020e0d25074c1
v1.0
instruct
Code_Contests
Code_Contests_46373_I
Chouti has recently discovered the concept of prime factorization and is fascinated by it. He wants to create a function that determines the prime factorization of a given integer n. Chouti wants the prime factors to be listed in non-decreasing order and each factor should appear as many times as it divides n. Your ta...
def prime_factorization(n): """ Returns a list of the prime factors of a given integer n in non-decreasing order. """ factors = [] # Start with the smallest prime factor d = 2 while d * d <= n: while (n % d) == 0: factors.append(d) n //= d d += 1 i...
from solution import prime_factorization, format_prime_factorization def test_prime_factorization_18(): assert prime_factorization(18) == [2, 3, 3] def test_prime_factorization_100(): assert prime_factorization(100) == [2, 2, 5, 5] def test_prime_factorization_37(): assert prime_factorization(37) == [37]...
[ { "docstring": "Returns a list of the prime factors of a given integer n in non-decreasing order.", "function_declaration": "def prime_factorization(n):", "function_name": "prime_factorization", "parameter_list": "(n)" }, { "docstring": "Returns the prime factorization of the given integer n...
[ 1, 0, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def prime_factors(n):\n \"\"\"\n Returns the prime factorization of n as a list of prime factors in non-decreasing order.\n \"\"\"\n factors = ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00046373", "row_id": 46373, "seed_ids": "[9]" }
0.765697
Code_Contests_46373
I
[ "prime_factorization", "format_prime_factorization" ]
2
[ [ "format_prime_factorization", "prime_factorization" ] ]
1
[]
false
[]
false
pytest
true
[]
true
41c31f3dafcbc31b901470edd446f6ad3ed3bcd3
44491d5e938cb84ba49a94c42aded342aa675720
v1.0
instruct
Code_Contests
Code_Contests_46450_I
A group of explorers have discovered a mysterious island with a set of N stone pillars arranged in a circle. Each pillar has an inscription that indicates a number, representing the height of the pillar. The heights of these pillars are given in a list where each integer denotes the height of a pillar. The explorers wa...
import math def gcd(a, b): while b: a, b = b, a % b return a def find_final_height(pillars): current_gcd = pillars[0] for height in pillars[1:]: current_gcd = gcd(current_gcd, height) if current_gcd == 1: # early exit, as the smallest possible gcd is 1 break re...
from solution import process_test_cases def test_example_1(): T = 2 test_cases = [ (4, [3, 9, 12, 15]), (3, [6, 6, 9]) ] assert process_test_cases(T, test_cases) == [3, 3] def test_all_identical_heights(): T = 1 test_cases = [ (5, [7, 7, 7, 7, 7]) ] assert proce...
[ { "docstring": null, "function_declaration": "def gcd(a, b):", "function_name": "gcd", "parameter_list": "(a, b)" }, { "docstring": null, "function_declaration": "def find_final_height(pillars):", "function_name": "find_final_height", "parameter_list": "(pillars)" }, { "d...
[ 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 gcd(a, b):\n while b:\n a, b = b, a % b\n return a\n\ndef find_final_height(heights):\n \"\"\"\n Returns the final equal height afte...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00046450", "row_id": 46450, "seed_ids": "[6009]" }
0.683072
Code_Contests_46450
I
[ "gcd", "find_final_height", "process_test_cases" ]
3
[ [ "find_final_height", "gcd" ], [ "process_test_cases", "find_final_height" ] ]
2
[ "process_test_cases" ]
false
[]
false
pytest
true
[]
true
efb5a372c68f5bcf4e9b18ee7bcde6f13bc993ba
70da98da1540e355d7d8831220c8e1955851e2d8
v1.0
instruct
Code_Contests
Code_Contests_46522_I
Charlotte is a renowned botanist conducting research on a unique species of tree. Each tree consists of nodes connected by branches, forming an acyclic connected graph (or simply a tree). Each node has a value assigned to it. Charlotte is particularly interested in finding the sum of the nodes' values in the heaviest p...
import sys sys.setrecursionlimit(200000) def get_heaviest_path_sum(node, parent, adj_list, values): max_path_1, max_path_2 = 0, 0 for neighbor in adj_list[node]: if neighbor == parent: continue path_sum = get_heaviest_path_sum(neighbor, node, adj_list, values) if path_sum > ...
def test_heaviest_path_example_1(): assert heaviest_path(3, [1, 2, 3], [(0, 1), (0, 2)]) == 6 def test_heaviest_path_example_2(): assert heaviest_path(5, [1, -2, 3, 4, -1], [(0, 1), (0, 2), (1, 3), (1, 4)]) == 6 def test_heaviest_path_single_node(): assert heaviest_path(1, [1], []) == 1 def test_heaviest...
[ { "docstring": null, "function_declaration": "def get_heaviest_path_sum(node, parent, adj_list, values):", "function_name": "get_heaviest_path_sum", "parameter_list": "(node, parent, adj_list, values)" }, { "docstring": null, "function_declaration": "def heaviest_path(n, values, edges):"...
[ 0, 0, 0, 1, 1 ]
2
medium
0.4
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def read_input():\n import sys\n input = sys.stdin.read\n data = input().split()\n idx = 0\n \n T = int(data[idx])\n idx += 1\n tes...
trial_gpt4o_4
{ "original_instruction": "", "prompt_id": "00046522", "row_id": 46522, "seed_ids": "[11422]" }
0.727022
Code_Contests_46522
I
[ "get_heaviest_path_sum", "heaviest_path", "process_test_cases" ]
3
[ [ "heaviest_path", "get_heaviest_path_sum" ], [ "process_test_cases", "heaviest_path" ] ]
2
[ "process_test_cases" ]
false
[]
false
pytest
false
[]
true
708ef9d28ccb3f330b439de53527edfe276ee30a
9f4d794fbb64731e3f3592fb9b51031ebb4b1580
v1.0
instruct
Code_Contests
Code_Contests_46686_I
Write a program that determines whether three given sides can form a valid triangle and if so, calculates its perimeter and area. Constraints * 1 ≤ a, b, c ≤ 100 Input The lengths a, b, and c of the three sides of the triangle are given in a line separated by single spaces. Output If the sides form a valid triang...
import math def check_valid_triangle(a, b, c): """ Check whether the sides can form a valid triangle. """ return a + b > c and a + c > b and b + c > a def calculate_perimeter(a, b, c): """ Returns the perimeter of the triangle. """ return a + b + c def calculate_area(a, b, c): """...
from solution import triangle def test_valid_triangle_345(): assert triangle(3, 4, 5) == "12 6" def test_invalid_triangle_11012(): assert triangle(1, 10, 12) == "Invalid" def test_valid_triangle_equilateral(): assert triangle(6, 6, 6) == "18 15.5885" def test_valid_triangle_isosceles(): assert trian...
[ { "docstring": "Check whether the sides can form a valid triangle.", "function_declaration": "def check_valid_triangle(a, b, c):", "function_name": "check_valid_triangle", "parameter_list": "(a, b, c)" }, { "docstring": "Returns the perimeter of the triangle.", "function_declaration": "d...
[ 0, 0, 1 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "import math\n\ndef triangle_properties(a, b, c):\n \"\"\"\n Determine whether the sides a, b, and c form a valid triangle.\n If they do, return it...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00046686", "row_id": 46686, "seed_ids": "[3438]" }
0.730833
Code_Contests_46686
I
[ "check_valid_triangle", "calculate_perimeter", "calculate_area", "triangle" ]
4
[ [ "triangle", "calculate_area" ], [ "triangle", "calculate_perimeter" ], [ "triangle", "check_valid_triangle" ] ]
3
[]
false
[]
false
pytest
true
[]
true
33017e24b1a50305448e23d2af17393b948fbeb2
289b0d37eaa5857672f075b6aade10076b573da8
v1.0
instruct
Code_Contests
Code_Contests_46767_I
In a large garden, there are n trees planted in a single line, numbered from 1 to n. Each tree can bear a certain quantity of fruits. Initially, each tree has no fruits. You will be given q operations which are either increasing the number of fruits on the trees or querying the total number of fruits on a segment of co...
MOD = 10**9 + 7 class FenwickTree: def __init__(self, size): self.size = size self.tree = [0] * (size + 1) def update(self, index, delta): while index <= self.size: self.tree[index] = (self.tree[index] + delta) % MOD index += index & -index def query(self, ...
def test_example_case(): n = 5 queries = [ [1, 1, 3, 10], [1, 2, 5, 5], [2, 1, 5], [1, 4, 5, 5], [2, 3, 5] ] assert process_queries(n, queries) == [50, 35] def test_single_tree(): n = 1 queries = [ [1, 1, 1, 10], [2, 1, 1], [1, 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": "MOD = 10**9 + 7\n\nclass Garden:\n def __init__(self, n):\n self.n = n\n self.tree = [0] * (n + 1)\n self.lazy = [0] * (n + 1)\n\n ...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00046767", "row_id": 46767, "seed_ids": "[8084]" }
0.733979
Code_Contests_46767
I
[ "range_update", "prefix_sum", "range_query", "process_queries" ]
4
[ [ "process_queries", "range_query" ], [ "process_queries", "range_update" ], [ "range_query", "prefix_sum" ] ]
3
[ "process_queries" ]
false
[ "FenwickTree" ]
true
pytest
false
[]
true
0b6c7e756d30e56afa73639a3ac1cda0e9835495
cc6cb0b14fa39088cb09d54ae19d7801a1bd3c55
v1.0
instruct
Code_Contests
Code_Contests_46795_I
James and his team are working on a new e-commerce platform. To improve the search functionality, they want to implement an algorithm that can find the closest match for a set of search phrases in a database of product titles. Help them by writing a program to determine the closest matching product title for each searc...
def levenshtein_distance(a, b): """ Calculates the Levenshtein distance between two strings a and b. """ n, m = len(a), len(b) if n > m: a, b = b, a n, m = m, n current_row = range(n+1) for i in range(1, m+1): previous_row, current_row = current_row, [i...
def test_levenshtein_distance(): assert levenshtein_distance('kitten', 'sitting') == 3 assert levenshtein_distance('flaw', 'lawn') == 2 assert levenshtein_distance('intention', 'execution') == 5 assert levenshtein_distance('', 'abc') == 3 assert levenshtein_distance('abc', '') == 3 def test_closest...
[ { "docstring": "Calculates the Levenshtein distance between two strings a and b.", "function_declaration": "def levenshtein_distance(a, b):", "function_name": "levenshtein_distance", "parameter_list": "(a, b)" }, { "docstring": "Finds the closest matching product title from the product title...
[ 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 levenshtein_distance(a, b):\n \"\"\"\n Calculates the Levenshtein distance between two strings a and b.\n \"\"\"\n n, m = len(a), len(b)\n ...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00046795", "row_id": 46795, "seed_ids": "[10297]" }
0.590464
Code_Contests_46795
I
[ "levenshtein_distance", "closest_matching_title", "process_datasets", "format_output", "main" ]
5
[ [ "closest_matching_title", "levenshtein_distance" ], [ "process_datasets", "closest_matching_title" ] ]
2
[ "process_datasets", "format_output" ]
false
[]
false
pytest
false
[]
true
2c248f35a8400f89bf075c76632c4435b98fbb38
0623e4e440660b30ea7041898a52e1a7b71c3107
v1.0
instruct
Code_Contests
Code_Contests_46938_I
You have been tasked to design a new navigation system for a city. The city has several intersections connected by roads, where each road has a specified travel time. However, due to recent construction, some roads have become unreliable, and you need to determine the most reliable path between two intersections. Form...
import heapq def dijkstra(n, roads, k, start, end): graph = {i: [] for i in range(1, n + 1)} for u, v, t, r in roads: if r >= k: graph[u].append((v, t)) graph[v].append((u, t)) queue = [(0, start)] distances = {i: float('inf') for i in range(1, n + 1)} distances[sta...
def test_shortest_reliable_path(): # Test Case 1 n = 4 m = 4 k = 50 roads = [ (1, 2, 10, 60), (2, 3, 20, 70), (3, 4, 30, 80), (1, 3, 40, 30), ] s = 1 e = 4 assert shortest_reliable_path(n, m, k, roads, s, e) == 60 # Test Case 2 n = 3 m = 3...
[ { "docstring": null, "function_declaration": "def dijkstra(n, roads, k, start, end):", "function_name": "dijkstra", "parameter_list": "(n, roads, k, start, end)" }, { "docstring": null, "function_declaration": "def shortest_reliable_path(n, m, k, roads, s, e):", "function_name": "sho...
[ 1, 1, 0 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "import heapq\n\ndef shortest_reliable_path(n, m, k, roads, s, e):\n graph = {i: [] for i in range(1, n + 1)}\n for u, v, t, r in roads:\n if r...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00046938", "row_id": 46938, "seed_ids": "[6368]" }
0.672555
Code_Contests_46938
I
[ "dijkstra", "shortest_reliable_path" ]
2
[ [ "shortest_reliable_path", "dijkstra" ] ]
1
[]
false
[]
false
pytest
false
[]
true
f26f832a2be5177f9b4e8620164153aa9a7fc1bf
670f08400f8035e8ba80c39a95cd8984b8ca7f93
v1.0
instruct
Code_Contests
Code_Contests_46946_I
Given a positive integer n, generate all structurally unique Binary Search Trees (BST) that store values 1 ... n and print the pre-order traversal of each unique BST. INPUT The first and only line of the input contains a single integer, n. OUTPUT Each line of the output should contain the pre-order traversal of one u...
class TreeNode: def __init__(self, val=0, left=None, right=None): self.val = val self.left = left self.right = right def generate_trees(n): if n == 0: return [] return generate_trees_rec(1, n) def generate_trees_rec(start, end): if start > end: return [None] ...
from solution import print_unique_bsts_pre_order def test_unique_bsts_pre_order(): result = print_unique_bsts_pre_order(3) expected = [ [1, 2, 3], [1, 3, 2], [2, 1, 3], [3, 1, 2], [3, 2, 1] ] assert sorted(result) == sorted(expected) def test_empty_bsts_pre_orde...
[]
[ 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 TreeNode:\n def __init__(self, val=0, left=None, right=None):\n self.val = val\n self.left = left\n self.right = right\n\ndef...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00046946", "row_id": 46946, "seed_ids": "[9344]" }
0.481388
Code_Contests_46946
I
[ "generate_trees", "generate_trees_rec", "pre_order_traversal", "print_unique_bsts_pre_order" ]
4
[ [ "generate_trees", "generate_trees_rec" ], [ "print_unique_bsts_pre_order", "generate_trees" ], [ "print_unique_bsts_pre_order", "pre_order_traversal" ] ]
3
[]
false
[ "TreeNode" ]
true
pytest
true
[]
true
7c918a1cde88b0fb06216930f0edcd1dd03c7baa
0d1a47e791463e014458df40fac4e03b4fb88c99
v1.0
instruct
Code_Contests
Code_Contests_46952_I
Palindromic Email Addresses Alice works in the IT department and is responsible for managing email addresses for a large organization. She has recently noticed that some users prefer more "unique" email addresses, ones that are palindromic. A palindromic string reads the same backward as forward. For simplicity, cons...
def is_palindromic_email(email): """ Checks if the local part of the given email address is palindromic. """ local_part = email.split('@')[0] return local_part == local_part[::-1] def check_palindromic_emails(n, emails): """ For each email in emails, prints "YES" if the local part is palind...
from solution import is_palindromic_email, check_palindromic_emails def test_is_palindromic_email(): assert is_palindromic_email("madam@company.com") == True assert is_palindromic_email("racecar@fastmail.com") == True assert is_palindromic_email("hello@world.com") == False assert is_palindromic_email("...
[ { "docstring": "Checks if the local part of the given email address is palindromic.", "function_declaration": "def is_palindromic_email(email):", "function_name": "is_palindromic_email", "parameter_list": "(email)" }, { "docstring": "For each email in emails, prints \"YES\" if the local part...
[ 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_palindromic_email(email):\n \"\"\"\n Checks if the local part of an email address is palindromic.\n \"\"\"\n local_part = email.split('@...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00046952", "row_id": 46952, "seed_ids": "[1707]" }
0.679184
Code_Contests_46952
I
[ "is_palindromic_email", "check_palindromic_emails" ]
2
[ [ "check_palindromic_emails", "is_palindromic_email" ] ]
1
[]
false
[]
false
pytest
true
[]
true
6d76aabb2c2cde5742ca65f6d27fe86e1ace557b
93f6e235020038061e32c6a6e9e2c5e9767d6495
v1.0
instruct
Code_Contests
Code_Contests_47018_I
Nina is planning to design a rectangular garden and needs to determine the placement of two trees along one of its sides. She knows the length l and width w of the garden. She wants to place the two trees such that they are aligned along the length of the rectangle, at integer distances d1 and d2 from one of the corner...
def is_prime(n): """ Helper function to check if a number is a prime number. """ if n <= 1: return False if n <= 3: return True if n % 2 == 0 or n % 3 == 0: return False i = 5 while i * i <= n: if n % i == 0 or n % (i + 2) == 0: return False ...
from solution import find_tree_positions def test_find_tree_positions_single_case(): results = find_tree_positions(1, [(10, 5)]) assert len(results) == 1 d1, d2 = results[0] assert d1 < d2 assert d2 - d1 in {2, 3, 5, 7, 11, 13, 17, 19, 23, 29} def test_find_tree_positions_multiple_cases(): res...
[ { "docstring": "Helper function to check if a number is a prime number.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "For each test case, find valid positions (d1, d2) for the two trees such that they are aligned\nalong ...
[ 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 sympy\n\ndef find_tree_positions(l, w):\n \"\"\"\n Finds the positions d1 and d2 for placing two trees such that they are aligned \n along ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00047018", "row_id": 47018, "seed_ids": "[4506]" }
0.584483
Code_Contests_47018
I
[ "is_prime", "find_tree_positions" ]
2
[ [ "find_tree_positions", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
3f8356cce2f7931a0b01e0fc8ab42716aee80ed1
c311362237aeca5d2b8296d1fc8469d80c572ec2
v1.0
instruct
Code_Contests
Code_Contests_47026_I
Given an integer, determine if it is a power of two. Write a program that takes multiple test cases and checks for each case if the number is a power of two. Input Format The first line contains the number of test cases T. Each of the next T lines contains one integer N to be checked. Output Format For each test ca...
def is_power_of_two(n): """ Checks if n is a power of two. """ if n <= 0: return False return (n & (n - 1)) == 0 def check_powers_of_two(nums): """ Takes a list of integers and returns a list of results, where each result is "Yes" if the corresponding integer is a power of...
from solution import is_power_of_two, check_powers_of_two def test_is_power_of_two(): assert is_power_of_two(1) == True assert is_power_of_two(16) == True assert is_power_of_two(10) == False assert is_power_of_two(0) == False assert is_power_of_two(-2) == False assert is_power_of_two(1024) == T...
[ { "docstring": "Checks if n is a power of two.", "function_declaration": "def is_power_of_two(n):", "function_name": "is_power_of_two", "parameter_list": "(n)" }, { "docstring": "Takes a list of integers and returns a list of results, \nwhere each result is \"Yes\" if the corresponding integ...
[ 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_power_of_two(n):\n \"\"\"\n Checks if the given integer n is a power of two.\n \"\"\"\n if n <= 0:\n return False\n return (n ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00047026", "row_id": 47026, "seed_ids": "[6424]" }
0.695662
Code_Contests_47026
I
[ "is_power_of_two", "check_powers_of_two" ]
2
[ [ "check_powers_of_two", "is_power_of_two" ] ]
1
[]
false
[]
false
pytest
true
[]
true
4a2bff471e013c7d00e3493e6608fff93458ef20
8f71dd7a67a084c89d8b72bd1494259dedf14404
v1.0
instruct
Code_Contests
Code_Contests_47073_I
You are given a rectangular grid consisting of N rows and M columns. Each cell in the grid contains an integer value representing the height at that cell. Construct a function that calculates the total number of "peaks" in the grid. A cell is considered a peak if it is higher than any of its adjacent cells (left, right...
def count_peaks(grid): """ Returns the number of peaks in the given grid. :param grid: A list of lists containing integers representing the heights of the grid. :return: Number of peaks in the grid. """ N = len(grid) M = len(grid[0]) def is_peak(i, j): current = grid[i][j] ...
from solution import solve def test_example_case(): heights = [1, 2, 1, 4, 3, 4, 1, 5, 1] assert solve(3, 3, heights) == 3 def test_single_peak(): heights = [1, 1, 1, 1, 2, 1, 1, 1, 1] assert solve(3, 3, heights) == 1 def test_multiple_peaks(): heights = [8, 1, 4, 3, 9, 2, 6, 5, 7] assert sol...
[ { "docstring": "Returns the number of peaks in the given grid.\n:param grid: A list of lists containing integers representing the heights of the grid.\n:return: Number of peaks in the grid.", "function_declaration": "def count_peaks(grid):", "function_name": "count_peaks", "parameter_list": "(grid)"...
[ 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 count_peaks(grid):\n \"\"\"\n Returns the number of peaks in the given grid.\n :param grid: A list of lists containing integers representing t...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00047073", "row_id": 47073, "seed_ids": "[108]" }
0.643682
Code_Contests_47073
I
[ "count_peaks", "solve" ]
2
[ [ "solve", "count_peaks" ] ]
1
[]
false
[]
false
pytest
true
[]
true
517d07fbfe9b283be088bdc90438a54fcba4957c
ea06b3448a700fb81044b28588a7abcb0cf6f8b8
v1.0
instruct
Code_Contests
Code_Contests_47075_I
Sara is learning about trees in data structures. She came across the concept of Binary Search Trees (BST) and is fascinated by their properties, such as how they allow for efficient searching, insertion, and deletion. She decides to write a program that can help her visualize the process of building a BST and determini...
class TreeNode: def __init__(self, key): self.left = None self.right = None self.val = key def insert(root, key): if root is None: return TreeNode(key) else: if root.val < key: root.right = insert(root.right, key) else: root.left = ins...
from solution import TreeNode, insert, find_height, process_input def test_insert_and_height(): root = None for val in [5, 3, 8, 1, 4, 7]: root = insert(root, val) assert find_height(root) == 2 root = None for val in [2, 1, 3]: root = insert(root, val) assert find_height(ro...
[]
[ 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": "class TreeNode:\n def __init__(self, key):\n self.left = None\n self.right = None\n self.val = key\n\ndef insert(root, key):\n \...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00047075", "row_id": 47075, "seed_ids": "[1117]" }
0.606466
Code_Contests_47075
I
[ "insert", "find_height", "process_input" ]
3
[ [ "process_input", "find_height" ], [ "process_input", "insert" ] ]
2
[ "process_input" ]
false
[ "TreeNode" ]
true
pytest
true
[]
true
7998f60665057fd5d6d5c4a4c3e76ddfb43ef49b
3a16c865244fce37631a6800a1981d201ea72ddf
v1.0
instruct
Code_Contests
Code_Contests_47194_I
In a kingdom far away, there lies a magical forest divided into n sectors, each connected with some of k paths. Each path connects two different sectors and has a certain time cost associated with it. The king wants to connect all sectors in a way that the total time cost is minimized and every sector is reachable from...
def find(parent, i): if parent[i] == i: return i else: return find(parent, parent[i]) def union(parent, rank, x, y): xroot = find(parent, x) yroot = find(parent, y) if rank[xroot] < rank[yroot]: parent[xroot] = yroot elif rank[xroot] > rank[yroot]: parent[yr...
from solution import min_cost_to_connect_sectors def test_case_1(): n = 4 k = 5 paths = [ (1, 2, 1), (2, 3, 2), (3, 4, 3), (1, 4, 6), (2, 4, 5) ] assert min_cost_to_connect_sectors(n, k, paths) == 6 def test_case_2(): n = 5 k = 6 paths = [ ...
[ { "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, 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 xr...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00047194", "row_id": 47194, "seed_ids": "[9718]" }
0.58412
Code_Contests_47194
I
[ "find", "union", "min_cost_to_connect_sectors" ]
3
[ [ "min_cost_to_connect_sectors", "find" ], [ "min_cost_to_connect_sectors", "union" ], [ "union", "find" ] ]
3
[]
false
[]
false
pytest
true
[]
true
32f5e6b97d9eb3aee206aeab812ebc901072d1f1
2f4badd5a607ab3a81e07590e585c7b98d60579d
v1.0
instruct
Code_Contests
Code_Contests_47211_I
A group of N friends are playing a game where they arrange themselves in a circle and pass a ball. They pass the ball to the friend standing K positions to their right. When the ball reaches a friend, they can either keep it or pass it again to the friend standing K positions to their right. The game continues until a ...
def can_final_position(N, K): """ Returns a list of size N where each element at index i is True if friend i can end up with the ball, or False otherwise. """ gcd_value = gcd(N, K) result = [False] * N for i in range(0, N, gcd_value): result[i] = True return result def gcd(a, b)...
from solution import can_final_position def test_example_cases(): assert can_final_position(5, 2) == [True, True, True, True, True] assert can_final_position(6, 4) == [True, False, True, False, True, False] def test_single_jump_cycle(): assert can_final_position(4, 1) == [True, True, True, True] asser...
[ { "docstring": "Returns a list of size N where each element at index i is True if friend i can end up with the ball,\nor False otherwise.", "function_declaration": "def can_final_position(N, K):", "function_name": "can_final_position", "parameter_list": "(N, K)" }, { "docstring": "Helper fun...
[ 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_final_position(N, K):\n \"\"\"\n Returns a list of size N indicating whether each friend can end up with the ball.\n \"\"\"\n gcd = gcd...
trial_gpt4o_3
{ "original_instruction": "", "prompt_id": "00047211", "row_id": 47211, "seed_ids": "[5385]" }
0.819259
Code_Contests_47211
I
[ "can_final_position", "gcd" ]
2
[ [ "can_final_position", "gcd" ] ]
1
[]
false
[]
false
pytest
true
[]
true
91ffb729d7e8d30c33bdf35c27bbe5cfc8a08a57
61cf6442aeda3709f470a3f69702b8b70e983b7c
v1.0
instruct
Code_Contests
Code_Contests_47228_I
A technology startup is planning to organize a Hackathon event. For the successful operation of the event, they need to arrange the participants in a manner that maximizes network engagement and collaboration. In this Hackathon, n participants are competing, each having a unique skill rating represented by an integer ...
def form_teams(n, T, skill_ratings): participants = list(enumerate(skill_ratings, start=1)) participants.sort(key=lambda x: x[1], reverse=True) teams = [] visited = [False] * n for i in range(n): if visited[i]: continue for j in range(i + 1, n): if v...
from solution import organize_hackathon def test_organize_hackathon_example_case(): n, T = 6, 10 a = [2, 3, 7, 5, 4, 1] num_teams, teams = organize_hackathon(n, T, a) assert num_teams == 3 assert len(teams) == 3 for team in teams: assert len(team[1:]) == 2 # Ensure each team has exactl...
[ { "docstring": null, "function_declaration": "def form_teams(n, T, skill_ratings):", "function_name": "form_teams", "parameter_list": "(n, T, skill_ratings)" }, { "docstring": null, "function_declaration": "def organize_hackathon(n, T, a):", "function_name": "organize_hackathon", ...
[ 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 form_teams(n, T, skill_ratings):\n skill_ratings = [(skill, i + 1) for i, skill in enumerate(skill_ratings)]\n skill_ratings.sort(reverse=True) ...
trial_gpt4o_7
{ "original_instruction": "", "prompt_id": "00047228", "row_id": 47228, "seed_ids": "[559]" }
0.739273
Code_Contests_47228
I
[ "form_teams", "organize_hackathon" ]
2
[ [ "organize_hackathon", "form_teams" ] ]
1
[]
false
[]
false
pytest
true
[]
true
8413d4308c45ad82fa00df5a9a9a3d0ed2d16549
a9916f9b3415f9bc01367b42e4ba279080dc3768
v1.0
instruct
Code_Contests
Code_Contests_47231_I
Given an array of integers, determine whether the array can form a palindrome after at most one modification (i.e., changing at most one integer). A palindrome is a sequence that reads the same backward as forward. Input The first line contains an integer n (1 ≤ n ≤ 10^5) — the number of elements in the array. The s...
def can_form_palindrome(arr): """ Determine if the array can form a palindrome after at most one modification. Parameters: arr (list): List of integers representing the array. Returns: str: "YES" if the array can be modified to form a palindrome, "NO" otherwise. """ def is_almo...
from solution import can_form_palindrome, solve def test_can_form_palindrome(): assert can_form_palindrome([1, 2, 3, 2, 1]) == "YES" assert can_form_palindrome([1, 2, 3, 4, 1]) == "NO" assert can_form_palindrome([1, 2, 2, 1]) == "YES" assert can_form_palindrome([1, 2, 2, 2, 1]) == "YES" assert can_...
[ { "docstring": "Determine if the array can form a palindrome after at most one modification.\n\nParameters:\narr (list): List of integers representing the array.\n\nReturns:\nstr: \"YES\" if the array can be modified to form a palindrome, \"NO\" otherwise.", "function_declaration": "def can_form_palindrome(...
[ 0, 0, 0, 0, 0, 0, 1, 0, 0, 1 ]
2
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def can_form_palindrome_after_one_modification(arr):\n \"\"\"\n Determine if the array can be modified to form a palindrome\n after at most one mo...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00047231", "row_id": 47231, "seed_ids": "[12456]" }
0.77848
Code_Contests_47231
I
[ "can_form_palindrome", "solve" ]
2
[ [ "solve", "can_form_palindrome" ] ]
1
[]
false
[]
false
pytest
true
[]
true
7253dfcf772f1c51f310446453010b6fe0a152b7
83d8afd24837cd1a9c287e1f471390020dc5e720
v1.0
instruct
Code_Contests
Code_Contests_47281_I
You are given an array of integers. Your task is to determine whether there exists a subarray with length greater than 1 such that the product of its elements is a perfect square. Input The first line of the input contains an integer T denoting the number of test cases. Each of the next T lines contains one integer N ...
def is_perfect_square(x): """ Checks if a number x is a perfect square. """ if x < 0: return False root = int(x**0.5) return root * root == x def has_subarray_with_square_product(arr): """ Determines if there exists a subarray with length greater than 1 such that the produc...
from solution import check_subarray_square def test_case_1(): t = 3 cases = [ (4, [1, 2, 2, 1]), (3, [3, 4, 2]), (5, [2, 3, 4, 6, 5]) ] expected = ["YES", "NO", "YES"] assert check_subarray_square(t, cases) == expected def test_case_2(): t = 1 cases = [ (2, ...
[ { "docstring": "Checks if a number x is a perfect square.", "function_declaration": "def is_perfect_square(x):", "function_name": "is_perfect_square", "parameter_list": "(x)" }, { "docstring": "Determines if there exists a subarray with length greater than 1 such \nthat the product of its el...
[ 0, 1, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "import math\n\ndef is_perfect_square(num):\n \"\"\"\n Returns True if the num is a perfect square, False otherwise.\n \"\"\"\n if num < 0:\n ...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00047281", "row_id": 47281, "seed_ids": "[11459]" }
0.622618
Code_Contests_47281
I
[ "is_perfect_square", "has_subarray_with_square_product", "main", "check_subarray_square" ]
4
[ [ "check_subarray_square", "main" ], [ "has_subarray_with_square_product", "is_perfect_square" ] ]
2
[]
false
[]
false
pytest
true
[]
true
d3023aad5c91ddc00072e8f8ffbe3f3e49c7faac
9093dfe7ec0c19de958f2752d4b6de9bed1c28e4
v1.0
instruct
Code_Contests
Code_Contests_47333_I
You are given a list of integers and a target integer. Your task is to determine if there are three distinct integers in the list that add up to the target integer. Write a function that returns True if such a triplet exists, and False otherwise. Input The input consists of two lines. The first line contains space-s...
def three_sum(nums, target): """ Returns True if there are three distinct integers in nums that add up to the target. """ nums.sort() n = len(nums) for i in range(n - 2): left, right = i + 1, n - 1 while left < right: s = nums[i] + nums[left] + nums[right] ...
from solution import three_sum, solve def test_three_sum_exists(): assert three_sum([1, 2, 3, 4, 5], 9) == True assert three_sum([-1, 0, 1, 2, -1, -4], 0) == True assert three_sum([0, 0, 0], 0) == True def test_three_sum_not_exists(): assert three_sum([1, 2, 3, 4, 5], 15) == False assert three_sum...
[ { "docstring": "Returns True if there are three distinct integers in nums that add up to the target.", "function_declaration": "def three_sum(nums, target):", "function_name": "three_sum", "parameter_list": "(nums, target)" }, { "docstring": null, "function_declaration": "def solve(input...
[ 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 has_triplet_sum(nums, target):\n \"\"\"\n Returns True if there exist three distinct integers in nums that add up to the target.\n \"\"\"\n ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00047333", "row_id": 47333, "seed_ids": "[6466]" }
0.689351
Code_Contests_47333
I
[ "three_sum", "solve" ]
2
[ [ "solve", "three_sum" ] ]
1
[]
false
[]
false
pytest
true
[]
true
4d9a524772370fbdc3e25764123a72c5b4284d1a
9ad3e227b6d4643fd2bf449c449ed5ddb5502748
v1.0
instruct
Code_Contests
Code_Contests_47334_I
In a mystical forest, there are N magical creatures living in harmony. These creatures communicate using a special language where words are linked if they differ by exactly one letter. For example, "hat" and "hot" can communicate with each other, but "hat" and "hit" cannot because they differ by two letters. One day, ...
from collections import deque def is_one_letter_diff(word1, word2): """ Check if two words differ by exactly one letter. """ if len(word1) != len(word2): return False count_diff = 0 for a, b in zip(word1, word2): if a != b: count_diff += 1 if count_diff >...
from solution import is_one_letter_diff, transform_word def test_is_one_letter_diff(): assert is_one_letter_diff("hit", "hot") == True assert is_one_letter_diff("hot", "dot") == True assert is_one_letter_diff("hit", "dot") == False assert is_one_letter_diff("hit", "hits") == False def test_transform_w...
[ { "docstring": "Check if two words differ by exactly one letter.", "function_declaration": "def is_one_letter_diff(word1, word2):", "function_name": "is_one_letter_diff", "parameter_list": "(word1, word2)" }, { "docstring": "Returns the minimum number of transformations required to change th...
[ 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 deque\n\ndef get_neighbors(word, word_set):\n neighbors = []\n for i in range(len(word)):\n for c in 'abcdefghijklmnop...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00047334", "row_id": 47334, "seed_ids": "[8876]" }
0.656592
Code_Contests_47334
I
[ "is_one_letter_diff", "transform_word" ]
2
[ [ "transform_word", "is_one_letter_diff" ] ]
1
[]
false
[]
false
pytest
true
[]
true
c66595337bdf8eb34e0aa7d5018dd89b61d56472
8486c5fa99d6de19974e0cda588d0ee37e48d032
v1.0
instruct
Code_Contests
Code_Contests_47372_I
<!-- Problem D --> Garden Pathways You are working on a project to design an efficient network of pathways to connect a series of garden plots in a public park. Each plot can be seen as a node in a graph, and the pathways connecting them are the edges. To make the paths easily navigable, minimal walking distance is...
def find(parent, i): if parent[i] == i: return i else: return find(parent, parent[i]) def union(parent, rank, x, y): xroot = find(parent, x) yroot = find(parent, y) if rank[xroot] < rank[yroot]: parent[xroot] = yroot elif rank[xroot] > rank[yroot]: parent[yr...
from solution import garden_pathways def test_single_dataset_connected(): inputs = [ (3, 3), (1, 2, 1), (2, 3, 2), (1, 3, 3), (0, 0) ] result = garden_pathways(inputs) assert result == [3] def test_single_dataset_not_connected(): inputs = [ (4, 2), (1, 2, 5), (3, 4, 7), ...
[ { "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 xr...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00047372", "row_id": 47372, "seed_ids": "[3325]" }
0.708754
Code_Contests_47372
I
[ "find", "union", "kruskal_mst", "garden_pathways" ]
4
[ [ "garden_pathways", "kruskal_mst" ], [ "kruskal_mst", "find" ], [ "kruskal_mst", "union" ], [ "union", "find" ] ]
4
[]
false
[]
false
pytest
true
[]
true
3b02bac75ad6971ac37dfc8617889b6086eb25f4
8e5c609c16dcf3ccbc77f9db0099b9f49890d590
v1.0
instruct
Code_Contests
Code_Contests_47381_I
Tara loves number theory, and she particularly enjoys working with special sequences of numbers. Today, she came across a sequence where each element is either a prime number or a perfect square. She wants to know how many prime numbers are in the sequence and how many perfect squares are in the sequence. Input: The f...
import math def is_prime(num): """ Check if a number is a prime. """ if num <= 1: return False if num == 2: return True if num % 2 == 0: return False for i in range(3, int(math.sqrt(num)) + 1, 2): if num % i == 0: return False return True def...
from solution import is_prime, is_perfect_square, count_prime_and_squares def test_is_prime(): assert is_prime(2) == True assert is_prime(3) == True assert is_prime(4) == False assert is_prime(11) == True assert is_prime(21) == False assert is_prime(47) == True def test_is_perfect_square(): ...
[ { "docstring": "Check if a number is a prime.", "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": "Check if a number is a perfect square.", "function_declaration": "def is_perfect_square(num):", "function_name": "is...
[ 0, 0, 0, 0, 0, 0, 0, 1, 0, 1 ]
2
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "import math\n\ndef is_prime(num):\n if num <= 1:\n return False\n if num == 2:\n return True\n if num % 2 == 0:\n return Fals...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00047381", "row_id": 47381, "seed_ids": "[7669]" }
0.686467
Code_Contests_47381
I
[ "is_prime", "is_perfect_square", "count_prime_and_squares" ]
3
[ [ "count_prime_and_squares", "is_perfect_square" ], [ "count_prime_and_squares", "is_prime" ] ]
2
[]
false
[]
false
pytest
true
[]
true
aeaf9a77f8b70fc6ba2a0611627a1b3b53ef7a25
3f111e81481c0949b50a91216e8105a45a18ca74
v1.0
instruct
Code_Contests
Code_Contests_47388_I
You are tasked with developing a new type of servo system used for robotic arms. The system involves a sequence of motor movements that need to be optimized for a given set of tasks. Each task requires moving the robotic arm from one position to another, and each move takes a certain amount of time. The robotic arm can...
def min_total_time(tasks): # Function to sort the tasks based on start position, then time tasks.sort(key=lambda x: (x[0], x[2])) total_time = 0 current_position = None for task in tasks: if current_position != task[0]: total_time += task[2] current_position = task[1]...
from solution import solve def test_example1(): n = 3 tasks = [ (1, 3, 5), (4, 3, 7), (1, 2, 4) ] assert solve(n, tasks) == 16 def test_example2(): n = 4 tasks = [ (2, 5, 2), (1, 4, 3), (2, 3, 1), (3, 2, 4) ] assert solve(n, tasks...
[ { "docstring": null, "function_declaration": "def min_total_time(tasks):", "function_name": "min_total_time", "parameter_list": "(tasks)" }, { "docstring": null, "function_declaration": "def solve(n, task_list):", "function_name": "solve", "parameter_list": "(n, task_list)" } ]
[ 0, 1, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def min_total_time(tasks):\n \"\"\"\n Calculate the minimum total time required to complete all tasks given the conditions.\n \n :param tasks: ...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00047388", "row_id": 47388, "seed_ids": "[13157]" }
0.620808
Code_Contests_47388
I
[ "min_total_time", "solve" ]
2
[ [ "solve", "min_total_time" ] ]
1
[]
false
[]
false
pytest
true
[]
true
edd2d51827579b1263bb448ba0f9fb34e47dde96
ddaab991d9b117c869d428d388c3a666b7bb34c2
v1.0
instruct
Code_Contests
Code_Contests_47400_I
Vasya is fond of binary palindromes. A binary palindrome is a number that reads the same forwards as backwards when written in binary form. For example, 5 (which is 101 in binary) and 9 (which is 1001 in binary) are binary palindromes. Given an integer `n`, find the smallest integer greater than `n` that is a binary p...
def is_binary_palindrome(n): binary_representation = bin(n)[2:] return binary_representation == binary_representation[::-1] def next_binary_palindrome(n): n += 1 while not is_binary_palindrome(n): n += 1 return n
from solution import is_binary_palindrome, next_binary_palindrome def test_is_binary_palindrome(): assert is_binary_palindrome(0) == True assert is_binary_palindrome(1) == True assert is_binary_palindrome(3) == True # binary: 11 assert is_binary_palindrome(5) == True # binary: 101 assert is_binar...
[ { "docstring": null, "function_declaration": "def is_binary_palindrome(n):", "function_name": "is_binary_palindrome", "parameter_list": "(n)" }, { "docstring": null, "function_declaration": "def next_binary_palindrome(n):", "function_name": "next_binary_palindrome", "parameter_li...
[ 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 is_binary_palindrome(n):\n \"\"\"\n Checks if the given number n is a binary palindrome.\n \"\"\"\n binary_str = bin(n)[2:]\n return bin...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00047400", "row_id": 47400, "seed_ids": "[12714]" }
0.685883
Code_Contests_47400
I
[ "is_binary_palindrome", "next_binary_palindrome" ]
2
[ [ "next_binary_palindrome", "is_binary_palindrome" ] ]
1
[]
false
[]
false
pytest
true
[]
true
1fc63680598d26d860a45a8005b5f7bda884e98e
cc77a01eb843b935adfd1c388b5a10d1966f5ad7
v1.0
instruct
Code_Contests
Code_Contests_47413_I
In a computer simulation game, players construct networks of pipelines to transport water between different cities. Each city has a water requirement, and water flows through the network to meet these requirements. You need to write a program that calculates the maximum flow from a source city to a destination city in ...
from collections import deque, defaultdict class MaxFlow: def __init__(self, n): self.n = n self.capacity = defaultdict(lambda: defaultdict(int)) self.flow = defaultdict(lambda: defaultdict(int)) def add_edge(self, u, v, c): self.capacity[u][v] += c def bfs(self, source, s...
def test_sample_input(): input_str = '''4 5 1 2 100 1 3 100 2 3 1 2 4 100 3 4 100 1 4''' assert simulate_game(input_str) == 200 def test_no_flow(): input_str = '''4 2 1 2 100 3 4 100 1 4''' assert simulate_game(input_str) == 0 def test_single_path(): input_str = '''3 2 1 2 10 2 3 5 1 3''' asse...
[]
[ 1, 0, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "from collections import deque, defaultdict\n\nclass MaxFlow:\n def __init__(self, n):\n self.n = n\n self.capacity = defaultdict(lambda: d...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00047413", "row_id": 47413, "seed_ids": "[2362]" }
0.642778
Code_Contests_47413
I
[ "max_water_flow", "simulate_game" ]
2
[ [ "simulate_game", "max_water_flow" ] ]
1
[]
false
[ "MaxFlow" ]
true
pytest
false
[]
true
0e8b443fe2da3c43f0b87e97e0ef68425edcaae1
6080d60a398aa4f473d917ebe8255022669f12cb
v1.0
instruct
Code_Contests
Code_Contests_47486_I
You are given a grid of size n x n, where each cell contains a single lowercase letter. You need to find the largest possible palindromic subgrid contained within this grid. A subgrid is a contiguous block of cells within the grid, and a palindrome reads the same forwards and backwards both row-wise and column-wise. I...
def is_subgrid_palindromic(grid, start_row, start_col, size): subgrid = [grid[i][start_col:start_col + size] for i in range(start_row, start_row + size)] for i in range(size): # Check row-wise palindrome if subgrid[i] != subgrid[i][::-1]: return False # Check column-wise pali...
def test_is_subgrid_palindromic(): grid1 = ["aba", "bab", "aba"] assert is_subgrid_palindromic(grid1, 0, 0, 3) grid2 = ["abcd", "efgh", "ijkl", "mnop"] assert not is_subgrid_palindromic(grid2, 0, 0, 2) grid3 = ["ababa", "bacab", "ababa", "bacab", "ababa"] assert is_subgrid_palindromic(...
[ { "docstring": null, "function_declaration": "def is_subgrid_palindromic(grid, start_row, start_col, size):", "function_name": "is_subgrid_palindromic", "parameter_list": "(grid, start_row, start_col, size)" }, { "docstring": null, "function_declaration": "def largest_palindromic_subgrid...
[ 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_subgrid_palindromic(grid, start_row, start_col, size):\n subgrid = [grid[i][start_col:start_col + size] for i in range(start_row, start_row + siz...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00047486", "row_id": 47486, "seed_ids": "[11064]" }
0.75897
Code_Contests_47486
I
[ "is_subgrid_palindromic", "largest_palindromic_subgrid", "process_input" ]
3
[ [ "largest_palindromic_subgrid", "is_subgrid_palindromic" ] ]
1
[ "process_input" ]
false
[]
false
pytest
false
[]
true
361a339ecaa595563ca3003e3db4111e33294bb4
75e79465109f5ea0f1b169aa9a3af3de6ea7a1cc
v1.0
instruct
Code_Contests
Code_Contests_47533_I
A software company is developing a new messaging application. As a part of the different features, they want to incorporate an encryption mechanism to secure the messages. The encryption algorithm they intend to use involves shifting each character in the message alphabetically by a fixed number, with wrap-around at th...
def encrypt(message, shift): encrypted_message = [] for char in message: if char.isalpha(): if char.islower(): encrypted_message.append(chr((ord(char) - ord('a') + shift) % 26 + ord('a'))) elif char.isupper(): encrypted_message.append(chr((ord(char...
from solution import encrypt, decrypt def test_encrypt_simple_case(): assert encrypt("Hello World", 3) == "Khoor Zruog" def test_decrypt_simple_case(): assert decrypt("Khoor Zruog", 3) == "Hello World" def test_encrypt_with_wrap_around(): assert encrypt("xyz", 3) == "abc" def test_decrypt_with_wrap_arou...
[ { "docstring": null, "function_declaration": "def encrypt(message, shift):", "function_name": "encrypt", "parameter_list": "(message, shift)" }, { "docstring": null, "function_declaration": "def decrypt(encrypted_message, shift):", "function_name": "decrypt", "parameter_list": "(...
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def encrypt(message, key):\n encrypted_message = []\n for char in message:\n if char.islower():\n encrypted_message.append(chr((ord...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00047533", "row_id": 47533, "seed_ids": "[8937]" }
0.675675
Code_Contests_47533
I
[ "encrypt", "decrypt" ]
2
[ [ "decrypt", "encrypt" ] ]
1
[]
false
[]
false
pytest
true
[]
true
57dc4be35d2bc67f6352b659468e4de38e9b7ee2
e49418f1bb7e819ff7538542c18cc02823315066
v1.0
instruct
Code_Contests
Code_Contests_47550_I
In the land of Arithma, there are N houses arranged in a straight line, each owned by a wizard. Each wizard has a certain amount of magical power associated with their house. The wizards want to form the most powerful alliance by combining the magical power of contiguous houses. However, there is a catch: they can only...
def is_prime(n): if n <= 1: return False if n <= 3: return True if n % 2 == 0 or n % 3 == 0: return False i = 5 while i * i <= n: if n % i == 0 or n % (i + 2) == 0: return False i += 6 return True def longest_prime_subarray_length(N, houses): ...
from solution import is_prime, longest_prime_subarray_length 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(25) == False assert is_prime(1) == False def test_longest_prime_subarray_length(): ...
[ { "docstring": null, "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": null, "function_declaration": "def longest_prime_subarray_length(N, houses):", "function_name": "longest_prime_subarray_length", "parameter_list...
[ 0, 1, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "import math\n\ndef is_prime(n):\n \"\"\"\n Check if a number is prime.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n ret...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00047550", "row_id": 47550, "seed_ids": "[4226]" }
0.570598
Code_Contests_47550
I
[ "is_prime", "longest_prime_subarray_length" ]
2
[ [ "longest_prime_subarray_length", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
9fb1dcd6373ca2be0ab76bfe52f2ba3033d98435
b1f2311dea481cff6b9d851c14e9cc93017f0ca6
v1.0
instruct
Code_Contests
Code_Contests_47585_I
The city of Algorithmia is organizing an annual marathon event. The marathon route must be designed in such a way that it forms a single closed loop (i.e., the starting point is the same as the endpoint) and every street is a part of the loop exactly once. Given the streets in the city and their respective lengths, you...
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] = ...
from solution import marathon_route def test_marathon_route_simple_loop(): n = 5 m = 7 streets = [ (1, 2, 10), (2, 3, 15), (3, 4, 20), (4, 5, 25), (5, 1, 30), (2, 5, 35), (3, 1, 40) ] assert marathon_route(n, m, streets) == 100 def test_marat...
[ { "docstring": null, "function_declaration": "def find(parent, i):", "function_name": "find", "parameter_list": "(parent, i)" }, { "docstring": null, "function_declaration": "def union(parent, rank, x, y):", "function_name": "union", "parameter_list": "(parent, rank, x, y)" }, ...
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "from collections import defaultdict\nimport heapq\n\ndef minimal_marathon_route(N, M, streets):\n def find(parent, i):\n \"\"\" Helper function t...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00047585", "row_id": 47585, "seed_ids": "[7627]" }
0.707088
Code_Contests_47585
I
[ "find", "union", "kruskal_mst", "min_marathon_route", "marathon_route" ]
5
[ [ "kruskal_mst", "find" ], [ "kruskal_mst", "union" ], [ "marathon_route", "min_marathon_route" ], [ "min_marathon_route", "kruskal_mst" ], [ "union", "find" ] ]
5
[]
false
[]
false
pytest
true
[]
true
18242a01c80c4257cfa42e6c7c0315768a340b91
687c4d00577518ca744a31551c5999ca66dd07d4
v1.0
instruct
Code_Contests
Code_Contests_47598_I
Given an array of integers, you are to determine whether there exists a triplet (i, j, k) with 0 ≤ i < j < k < n such that arr[i] * arr[j] * arr[k] is a perfect square. A perfect square is an integer that is the square of another integer. For example, 1, 4, 9, 16, and 25 are perfect squares (1 = 1^2, 4 = 2^2, 9 = 3^2,...
import math def is_perfect_square(x): if x < 0: return False root = int(math.isqrt(x)) return root * root == x def hasPerfectSquareTriplet(arr): n = len(arr) for i in range(n): for j in range(i + 1, n): for k in range(j + 1, n): product = arr[i] * arr[j]...
from solution import is_perfect_square, hasPerfectSquareTriplet, process_test_cases def test_is_perfect_square(): assert is_perfect_square(4) == True assert is_perfect_square(16) == True assert is_perfect_square(25) == True assert is_perfect_square(-1) == False assert is_perfect_square(10) == False...
[ { "docstring": null, "function_declaration": "def is_perfect_square(x):", "function_name": "is_perfect_square", "parameter_list": "(x)" }, { "docstring": null, "function_declaration": "def hasPerfectSquareTriplet(arr):", "function_name": "hasPerfectSquareTriplet", "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": "import math\n\ndef hasPerfectSquareTriplet(arr):\n n = len(arr)\n for i in range(n):\n for j in range(i+1, n):\n for k in range(j+1...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00047598", "row_id": 47598, "seed_ids": "[9335]" }
0.612542
Code_Contests_47598
I
[ "is_perfect_square", "hasPerfectSquareTriplet", "process_test_cases" ]
3
[ [ "hasPerfectSquareTriplet", "is_perfect_square" ], [ "process_test_cases", "hasPerfectSquareTriplet" ] ]
2
[ "process_test_cases" ]
false
[]
false
pytest
true
[]
true
5379bd0989e5ac4ce89d4e3bcd53aa247238f459
9cb44e231a7d3040e3a3feceaf11d68f0dfb7458
v1.0
instruct
Code_Contests
Code_Contests_47635_I
In the land of Dracovania, there is a game of magic squares that many inhabitants enjoy. The game involves a 5x5 grid where each cell contains a different integer from 1 to 25. A player can select any subgrid of size 3x3 and must check if it forms a "magic square." A 3x3 magic square is defined as a grid where the sum ...
def is_magic_square(subgrid): """ Check if the 3x3 subgrid is a magic square. """ target_sum = sum(subgrid[0]) # Check rows and columns for i in range(3): if sum(subgrid[i]) != target_sum or sum(row[i] for row in subgrid) != target_sum: return False # Check diagonal...
from solution import contains_magic_square, parse_grid def test_contains_magic_square_1(): input_string = "1 2 3 4 5\n5 6 7 8 9\n9 10 11 12 13\n13 14 15 16 17\n17 18 19 20 21" grid = parse_grid(input_string) assert contains_magic_square(grid) == "NO" def test_contains_magic_square_2(): input_string = ...
[ { "docstring": "Check if the 3x3 subgrid is a magic square.", "function_declaration": "def is_magic_square(subgrid):", "function_name": "is_magic_square", "parameter_list": "(subgrid)" }, { "docstring": "Check if there is any 3x3 magic square in the 5x5 grid.", "function_declaration": "d...
[ 0, 1, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_magic_square_3x3(grid, x, y):\n # Extract the 3x3 subgrid starting at (x, y)\n subgrid = [grid[x+i][y:y+3] for i in range(3)]\n \n # Cal...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00047635", "row_id": 47635, "seed_ids": "[7222]" }
0.669892
Code_Contests_47635
I
[ "is_magic_square", "contains_magic_square", "parse_grid" ]
3
[ [ "contains_magic_square", "is_magic_square" ] ]
1
[]
false
[]
false
pytest
true
[]
true
166b51401360d20d97574500acd54c8764451b99
36bd83c292b2696a2f848b54ab64788f3d5b2b70
v1.0
instruct
Code_Contests
Code_Contests_47644_I
Carla loves gardening and has a special garden where she grows two types of flowers: sunflowers and roses. She places them in a 2D grid where each cell can either be a sunflower, a rose, or empty. Sunflowers are represented by `S`, roses by `R`, and empty cells by `.`. Carla is interested in finding out how many diffe...
def count_flower_patches(grid, N, M): def dfs(x, y, flower): stack = [(x, y)] while stack: cx, cy = stack.pop() for nx, ny in [(cx+1, cy), (cx-1, cy), (cx, cy+1), (cx, cy-1)]: if 0 <= nx < N and 0 <= ny < M and not visited[nx][ny] and grid[nx][ny] == flower: ...
def test_count_flower_patches(): grid1 = [ "S...R", "SS..R", "..RR.", "R..S." ] assert count_flower_patches(grid1, 4, 5) == 5 grid2 = [ "SSS", "RRR", "SSS" ] assert count_flower_patches(grid2, 3, 3) == 3 grid3 = [ "...", ...
[ { "docstring": null, "function_declaration": "def count_flower_patches(grid, N, M):", "function_name": "count_flower_patches", "parameter_list": "(grid, N, M)" }, { "docstring": null, "function_declaration": "def input_flower_patches():", "function_name": "input_flower_patches", ...
[ 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 count_flower_patches(grid, n, m):\n def dfs(x, y, flower):\n if x < 0 or y < 0 or x >= n or y >= m or grid[x][y] != flower:\n retu...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00047644", "row_id": 47644, "seed_ids": "[5101]" }
0.68227
Code_Contests_47644
I
[ "count_flower_patches", "input_flower_patches" ]
2
[ [ "input_flower_patches", "count_flower_patches" ] ]
1
[]
false
[]
false
pytest
false
[]
true
2183cb0c193cd711825beb8dc967f4654cbd3de1
a0fc58da04d41ad01c91b7729cf508446a80b05b
v1.0
instruct
Code_Contests
Code_Contests_47668_I
You are given a grid of size N x M filled with zeros and ones. Your task is to find the largest rectangular subgrid consisting entirely of ones. Input - The first line contains two integers, N (1 ≤ N ≤ 500) and M (1 ≤ M ≤ 500), representing the grid dimensions. - The next N lines each contain M characters ('0' or '1')...
def max_rectangle_area(grid): """ Given a grid of size N x M filled with zeros and ones, this function returns the area of the largest rectangular subgrid consisting entirely of ones. """ if not grid or not grid[0]: return 0 n, m = len(grid), len(grid[0]) max_area = 0 height...
def test_max_rectangle_area_1(): grid = [ "11001", "11011", "11111", "00011" ] assert max_rectangle_area(grid) == 6 def test_max_rectangle_area_2(): grid = [ "000", "000", "000" ] assert max_rectangle_area(grid) == 0 def test_max_rectangl...
[ { "docstring": "Given a grid of size N x M filled with zeros and ones, this function returns the area of the largest\nrectangular subgrid consisting entirely of ones.", "function_declaration": "def max_rectangle_area(grid):", "function_name": "max_rectangle_area", "parameter_list": "(grid)" }, {...
[ 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_rectangle_area(grid):\n \"\"\"\n Given a grid of size N x M filled with zeros and ones, this function returns the area of the largest\n re...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00047668", "row_id": 47668, "seed_ids": "[9618]" }
0.706947
Code_Contests_47668
I
[ "max_rectangle_area", "largest_rectangle_histogram" ]
2
[ [ "max_rectangle_area", "largest_rectangle_histogram" ] ]
1
[]
false
[]
false
pytest
false
[]
true
08e1f464d6f0a87410b4e3c7c83c76344e88b77a
3304d9fd8fa0e29e0a6937bfb317f7b98f85f449
v1.0
instruct
Code_Contests
Code_Contests_47679_I
A large company has a number of conference rooms in different buildings. Each conference room has a unique identifier, a capacity, and a list of facilities it offers, such as a projector, whiteboard, or video conferencing. Employees can book these conference rooms for meetings. You are asked to write a program that he...
def find_available_rooms(rooms, booking_requests): result = [] for request in booking_requests: num_participants, required_facilities = request available_rooms = [] for room in rooms: room_id, capacity, facilities = room if capacity >= num_participants and all(f...
from solution import conference_room_booker def test_sample_input(): input_data = """4 101 10 projector whiteboard; 102 20 projector teleconference whiteboard video; 103 15 teleconference projector; 104 25 video; 3 8 projector; 12 projector teleconference; 30 video projector; """ expected_output = ["101 102 10...
[ { "docstring": null, "function_declaration": "def find_available_rooms(rooms, booking_requests):", "function_name": "find_available_rooms", "parameter_list": "(rooms, booking_requests)" }, { "docstring": null, "function_declaration": "def process_input(input_data):", "function_name":...
[ 0, 0, 0, 0, 0, 0, 1, 0, 0, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def find_suitable_rooms(n, room_data, m, booking_requests):\n rooms = []\n for i in range(n):\n room = room_data[i].split()\n room_id =...
trial_gpt4o_6
{ "original_instruction": "", "prompt_id": "00047679", "row_id": 47679, "seed_ids": "[11112]" }
0.667697
Code_Contests_47679
I
[ "find_available_rooms", "process_input", "conference_room_booker" ]
3
[ [ "conference_room_booker", "find_available_rooms" ], [ "conference_room_booker", "process_input" ] ]
2
[ "process_input" ]
false
[]
false
pytest
true
[]
true
5031a7949a33b8721f562f0deba76969dbf14c7a
b8fbd844d15e048f6debd3c4781d46d9c26d2f30
v1.0
instruct
Code_Contests
Code_Contests_47686_I
Tanya is passionate about palindrome numbers. A number is considered a palindrome if it reads the same forward and backward. For instance, 121 and 1331 are palindromes, whereas 123 is not. Tanya is particularly interested in the smallest palindrome number that meets certain criteria. Given an integer n (1 ≤ n ≤ 5000)...
def is_palindrome(number): """ Checks if a number is a palindrome. """ return str(number) == str(number)[::-1] def smallest_palindrome_greater_than_or_equal_to(n): """ Returns the smallest palindrome number greater than or equal to n. """ while not is_palindrome(n): n += 1 r...
from solution import is_palindrome, smallest_palindrome_greater_than_or_equal_to def test_is_palindrome(): assert is_palindrome(121) assert is_palindrome(1331) assert is_palindrome(1) assert not is_palindrome(123) def test_smallest_palindrome_greater_than_or_equal_to(): assert smallest_palindrome_...
[ { "docstring": "Checks if a number is a palindrome.", "function_declaration": "def is_palindrome(number):", "function_name": "is_palindrome", "parameter_list": "(number)" }, { "docstring": "Returns the smallest palindrome number greater than or equal to n.", "function_declaration": "def ...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_palindrome(num):\n \"\"\"\n Check if a given number is a palindrome.\n \"\"\"\n return str(num) == str(num)[::-1]\n\ndef smallest_palind...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00047686", "row_id": 47686, "seed_ids": "[2009]" }
0.823744
Code_Contests_47686
I
[ "is_palindrome", "smallest_palindrome_greater_than_or_equal_to" ]
2
[ [ "smallest_palindrome_greater_than_or_equal_to", "is_palindrome" ] ]
1
[]
false
[]
false
pytest
true
[]
true
09d29a37bd98b2a634eabf4ddad899a66e218973
cc4369a8f3bd55b524f7dddd1e8e11d53265f49b
v1.0
instruct
Code_Contests
Code_Contests_47687_I
Vasya is fond of playing with numbers, and one day he came across an interesting sequence known as a "fibonacci". The sequence starts with two 1s, and each subsequent number in the sequence is the sum of the two preceding ones. The first ten elements of the fibonacci sequence are: 1, 1, 2, 3, 5, 8, 13, 21, 34, 55 Vas...
def is_prime(num): """ Returns True if the number is prime, otherwise False. """ if num <= 1: return False if num <= 3: return True if num % 2 == 0 or num % 3 == 0: return False i = 5 while i * i <= num: if num % i == 0 or num % (i + 2) == 0: r...
import pytest from solution import is_prime, count_prime_fibonacci def test_is_prime(): assert is_prime(2) == True assert is_prime(3) == True assert is_prime(4) == False assert is_prime(17) == True assert is_prime(18) == False assert is_prime(19) == True assert is_prime(0) == False asse...
[ { "docstring": "Returns True if the number is prime, otherwise False.", "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": "Returns the number of prime fibonacci numbers up to and including the N-th fibonacci number.", "...
[ 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 is_prime(num):\n \"\"\"\n Check if a number is a prime number.\n \"\"\"\n if num < 2:\n return False\n for i in range(2, int(num ...
trial_gpt4o_7
{ "original_instruction": "", "prompt_id": "00047687", "row_id": 47687, "seed_ids": "[10480]" }
0.722758
Code_Contests_47687
I
[ "is_prime", "count_prime_fibonacci" ]
2
[ [ "count_prime_fibonacci", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
b0a52c7886e4c40864f1544c0c3757bcf7b5ed21
29fc81e74c82d592a383f14ceffa419050d7363c
v1.0
instruct
Code_Contests
Code_Contests_47698_I
Alex and Bob are playing a game involving a row of stones. Each stone has a positive integer value written on it. Alex and Bob take turns picking up a stone from either end of the row. Alex goes first, and both players aim to maximize the sum of the stones they pick up. Design an algorithm to determine the maximum pos...
def max_score_stones(stones): n = len(stones) if n == 0: return 0 # dp[i][j] will be the maximum score the player can achieve from stones[i] to stones[j] dp = [[0] * n for _ in range(n)] for size in range(1, n + 1): # size is the length of the subproblem we are solving for...
from solution import parse_input_and_get_results def test_single_case(): input_str = "1\n4\n4 7 2 3\n" expected_output = "10" assert parse_input_and_get_results(input_str) == expected_output def test_multiple_cases(): input_str = "2\n4\n4 7 2 3\n3\n2 2 10\n" expected_output = "10\n12" assert p...
[ { "docstring": null, "function_declaration": "def max_score_stones(stones):", "function_name": "max_score_stones", "parameter_list": "(stones)" }, { "docstring": null, "function_declaration": "def maximum_scores_for_cases(test_cases):", "function_name": "maximum_scores_for_cases", ...
[ 0, 0, 0, 1, 0 ]
1
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def max_score(stones):\n def helper(i, j):\n if i > j:\n return 0\n if memo[i][j] != -1:\n return memo[i][j]\n ...
trial_gpt4o_3
{ "original_instruction": "", "prompt_id": "00047698", "row_id": 47698, "seed_ids": "[8397]" }
0.697077
Code_Contests_47698
I
[ "max_score_stones", "maximum_scores_for_cases", "parse_input_and_get_results" ]
3
[ [ "maximum_scores_for_cases", "max_score_stones" ], [ "parse_input_and_get_results", "maximum_scores_for_cases" ] ]
2
[ "parse_input_and_get_results" ]
false
[]
false
pytest
true
[]
true
ad6efd30461067663e9eb4b8a8ca826c5ab52e01
165cc5f1b5b2c6ded9ecb118b8ca173c1adb8875
v1.0
instruct
Code_Contests
Code_Contests_47782_I
There is a matrix of size N x M consisting of non-negative integers. You need to perform a series of operations. In each operation, you will be given a row index `r_i` and a cyclic shift amount `k_i`. You will perform a right cyclic shift of the elements in the row `r_i` by `k_i` positions. After performing all the op...
def cyclic_shift(matrix, r, k): """ Perform a right cyclic shift on the given row of the matrix by k positions. """ n = len(matrix[r]) k = k % n # To handle cases where k is larger than the number of columns return matrix[r][-k:] + matrix[r][:-k] def sum_after_operations(n, m, matrix, operatio...
def test_cyclic_shift_basic(): matrix = [ [1, 2, 3], [4, 5, 6], [7, 8, 9] ] assert cyclic_shift(matrix, 0, 1) == [3, 1, 2] assert cyclic_shift(matrix, 2, 2) == [8, 9, 7] def test_sum_after_operations_case1(): n = 3 m = 3 matrix = [ [1, 2, 3], [4, 5, 6...
[ { "docstring": "Perform a right cyclic shift on the given row of the matrix by k positions.", "function_declaration": "def cyclic_shift(matrix, r, k):", "function_name": "cyclic_shift", "parameter_list": "(matrix, r, k)" }, { "docstring": "Perform a series of cyclic shift operations on the m...
[ 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 matrix_cyclic_shift_and_sum(matrix, operations):\n \"\"\"\n Perform cyclic shifts on specified rows of the matrix and return the sum of all eleme...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00047782", "row_id": 47782, "seed_ids": "[8104]" }
0.590858
Code_Contests_47782
I
[ "cyclic_shift", "sum_after_operations" ]
2
[ [ "sum_after_operations", "cyclic_shift" ] ]
1
[]
false
[]
false
pytest
false
[]
true
a75d6790aff67d799ea4d3c7a668a3b7e3a1483f
8e1c493934d7b2e7506a1406627f3222a0f9aafd
v1.0
instruct
Code_Contests
Code_Contests_47806_I
Design a function to read a sequence of comma-separated integers representing a pyramid (triangle) structure, where each row of the pyramid has one more integer than the previous row. Then, calculate the maximum path sum from the top to the bottom of the pyramid, where at each step, you can move to the adjacent number ...
def read_pyramid(input_lines): """ Reads a list of strings representing the rows of a pyramid, where each string contains comma-separated integers. Returns a 2D list representing the pyramid. """ pyramid = [list(map(int, line.split(','))) for line in input_lines] return pyramid def maximum_pat...
import pytest from solution import read_pyramid, maximum_path_sum, max_path_sum_from_top_to_bottom def test_read_pyramid(): input_lines = ["3", "7,4", "2,4,6", "8,5,9,3"] expected_output = [[3], [7, 4], [2, 4, 6], [8, 5, 9, 3]] assert read_pyramid(input_lines) == expected_output def test_maximum_path_sum(...
[ { "docstring": "Reads a list of strings representing the rows of a pyramid, where each string \ncontains comma-separated integers. Returns a 2D list representing the pyramid.", "function_declaration": "def read_pyramid(input_lines):", "function_name": "read_pyramid", "parameter_list": "(input_lines)...
[ 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 read_pyramid(input_lines):\n \"\"\"\n Reads a list of strings representing the rows of a pyramid, where each string \n contains comma-separate...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00047806", "row_id": 47806, "seed_ids": "[7897]" }
0.692889
Code_Contests_47806
I
[ "read_pyramid", "maximum_path_sum", "max_path_sum_from_top_to_bottom" ]
3
[ [ "max_path_sum_from_top_to_bottom", "maximum_path_sum" ], [ "max_path_sum_from_top_to_bottom", "read_pyramid" ] ]
2
[]
false
[]
false
pytest
true
[]
true
5962546d472a3ca2654f22d73ae5f7c36a931960
a2a8d373a621ecb61b1ed9b2e4a2b316433e23cb
v1.0
instruct
Code_Contests
Code_Contests_47815_I
Sam loves solving puzzles and his latest fascination is with finding specific strings in a grid. Help Sam by writing a function that can find the maximum length of a word formed by concatenating characters from a non-overlapping path in the grid. Sam can only move either right or down from a cell. Input The input con...
def max_length_of_word(grid): """ Returns the length of the longest possible word that can be formed by moving right or down from the top-left corner to the bottom-right corner in a grid. :param grid: List of strings representing the grid :return: Integer representing the length of the longest ...
from solution import max_length_of_word, find_max_length def test_max_length_of_word_example1(): grid = [ "abc", "def", "ghi" ] assert max_length_of_word(grid) == 5 def test_max_length_of_word_example2(): grid = [ "aa", "bb" ] assert max_length_of_word(g...
[ { "docstring": "Returns the length of the longest possible word that can be formed by moving right or down from the top-left corner\nto the bottom-right corner in a grid.\n\n:param grid: List of strings representing the grid\n:return: Integer representing the length of the longest word", "function_declarati...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def max_word_length_in_grid(n, m, grid):\n \"\"\"\n Function that finds the maximum length of a word formed by concatenating characters from a \n ...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00047815", "row_id": 47815, "seed_ids": "[4331]" }
0.665378
Code_Contests_47815
I
[ "max_length_of_word", "find_max_length" ]
2
[ [ "find_max_length", "max_length_of_word" ] ]
1
[]
false
[]
false
pytest
true
[]
true
2dc1423f0c6c5b07f1117039d9f0b173775cba86
9a398fa8ddccd21f3edb825e9c822da768235990
v1.0
instruct
Code_Contests
Code_Contests_47844_I
You are given a binary tree with N nodes, where each node has a unique integer value. The task is to find the length of the longest path between any two nodes in the tree. The path may or may not pass through the root of the tree. A binary tree is defined as: - A tree in which each node has at most two children. The...
class TreeNode: def __init__(self, value=0): self.value = value self.left = None self.right = None def longest_path_length(root): def dfs(node): nonlocal diameter if not node: return 0 left_length = dfs(node.left) right_length = dfs(node.right...
def test_find_longest_path(): assert find_longest_path(5, [1, 2, 3, 4, 5], [(1, 2), (1, 3), (2, 4), (2, 5)]) == 3 assert find_longest_path(3, [1, 2, 3], [(1, 2), (1, 3)]) == 2 assert find_longest_path(6, [1, 2, 3, 4, 5, 6], [(1, 2), (1, 3), (2, 4), (2, 5), (5, 6)]) == 4 def test_single_path_tree(): ass...
[]
[ 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": "class TreeNode:\n def __init__(self, value):\n self.value = value\n self.left = None\n self.right = None\n\ndef find_longest_path_l...
trial_gpt4o_7
{ "original_instruction": "", "prompt_id": "00047844", "row_id": 47844, "seed_ids": "[3130]" }
0.62293
Code_Contests_47844
I
[ "longest_path_length", "build_tree", "find_longest_path" ]
3
[ [ "find_longest_path", "build_tree" ], [ "find_longest_path", "longest_path_length" ] ]
2
[]
false
[ "TreeNode" ]
true
pytest
false
[]
true
c272fee15a6a9f9bf15caa26e193f0a44c1c1832
1da249d463e9b6b07db803a2270aa361a47701ca
v1.0
instruct
Code_Contests
Code_Contests_47862_I
Michael is planning a treasure hunt for his friends. He designed a map with several waypoints, each labeled with a unique number. To add an extra level of challenge, Michael introduced a rule: Starting from the first waypoint, participants must find a path to the destination waypoint such that the sum of the waypoint n...
def is_prime(n): """Check if a number is prime.""" if n <= 1: return False if n <= 3: return True if n % 2 == 0 or n % 3 == 0: return False i = 5 while i * i <= n: if n % i == 0 or n % (i + 2) == 0: return False i += 6 return True def path...
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_single_test_case_yes(): N, A, B, D = 4, 10, 50, 4 waypoints = [11, 15, 29, 4] assert path_exists(N, A, B, D-1, waypoin...
[ { "docstring": "Check if a number is prime.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Check if there is a path to destination with the prime sum condition.", "function_declaration": "def path_exists(N, A, B, D, w...
[ 0, 0, 0, 0, 0, 0, 0, 1, 1, 0 ]
2
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(num):\n if num < 2:\n return False\n for i in range(2, int(num**0.5) + 1):\n if num % i == 0:\n return False\n ...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00047862", "row_id": 47862, "seed_ids": "[10275]" }
0.634096
Code_Contests_47862
I
[ "is_prime", "path_exists", "treasure_hunt" ]
3
[ [ "path_exists", "is_prime" ], [ "treasure_hunt", "path_exists" ] ]
2
[]
false
[]
false
pytest
false
[]
true
e4c9dc8f8f2eb9aa298f0606b451fddbf8413df3
4a08ab873aef76e6e39d211bbffa6eb0e3d9ea35
v1.0
instruct
Code_Contests
Code_Contests_47911_I
The GCD (Greatest Common Divisor) and LCM (Least Common Multiple) are fundamental concepts in number theory. Given two numbers, find both their GCD and LCM. Input The input consists of a single line containing two integers a and b (1 ≤ a, b ≤ 10^9). Output Print two integers, the GCD and LCM of the given numbers. ...
def gcd(a, b): """ Compute the Greatest Common Divisor of a and b. """ while b: a, b = b, a % b return a def lcm(a, b, gcd_val): """ Compute the Least Common Multiple of a and b using their GCD. """ return a * b // gcd_val def gcd_and_lcm(a, b): """ Compute both the...
from solution import gcd_and_lcm def test_gcd_lcm_case_1(): assert gcd_and_lcm(15, 20) == (5, 60) def test_gcd_lcm_case_2(): assert gcd_and_lcm(27, 36) == (9, 108) def test_gcd_lcm_case_3(): assert gcd_and_lcm(1, 1) == (1, 1) def test_gcd_lcm_case_4(): assert gcd_and_lcm(2, 3) == (1, 6) def test_gc...
[ { "docstring": "Compute the Greatest Common Divisor of a and b.", "function_declaration": "def gcd(a, b):", "function_name": "gcd", "parameter_list": "(a, b)" }, { "docstring": "Compute the Least Common Multiple of a and b using their GCD.", "function_declaration": "def lcm(a, b, gcd_val...
[ 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 gcd(a, b):\n \"\"\"\n Returns the greatest common divisor of a and b.\n Uses the Euclidean algorithm.\n \"\"\"\n while b:\n a, b ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00047911", "row_id": 47911, "seed_ids": "[9390]" }
0.627193
Code_Contests_47911
I
[ "gcd", "lcm", "gcd_and_lcm" ]
3
[ [ "gcd_and_lcm", "gcd" ], [ "gcd_and_lcm", "lcm" ] ]
2
[]
false
[]
false
pytest
true
[]
true
ebd5c4176933ecea4f4838d8c1047f243168cc63
de57d4eb63ff1afc29d77c59f6d89c5bafafdeb8
v1.0
instruct
Code_Contests
Code_Contests_47933_I
There is a rectangular grid with n rows and m columns. Some cells in this grid contain obstacles, while others are free. You want to find a path from the top-left corner (1,1) to the bottom-right corner (n,m) such that the path avoids obstacles and only moves right or down. Write a program to determine if such a path ...
def find_path(n, m, grid): def is_valid(x, y): return 0 <= x < n and 0 <= y < m and grid[x][y] == '.' def dfs(x, y): if x == n - 1 and y == m - 1: return True if not is_valid(x, y): return False grid[x][y] = '#' # mark the cell as visited ...
from solution import grid_path def test_grid_path_example1(): n, m = 3, 3 grid_lines = [ '...', '.#.', '...' ] result = grid_path(n, m, grid_lines) assert result == "YES\nRRDD" or result == "YES\nDDRR" def test_grid_path_example2(): n, m = 3, 3 grid_lines = [ ...
[ { "docstring": null, "function_declaration": "def find_path(n, m, grid):", "function_name": "find_path", "parameter_list": "(n, m, grid)" }, { "docstring": null, "function_declaration": "def grid_path(n, m, grid_lines):", "function_name": "grid_path", "parameter_list": "(n, m, gr...
[ 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_path(n, m, grid):\n def is_valid(x, y):\n return 0 <= x < n and 0 <= y < m and grid[x][y] == '.'\n \n def dfs(x, y):\n if x...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00047933", "row_id": 47933, "seed_ids": "[7338]" }
0.741926
Code_Contests_47933
I
[ "find_path", "grid_path" ]
2
[ [ "grid_path", "find_path" ] ]
1
[]
false
[]
false
pytest
true
[]
true
6e60fecc959aa55917313098e259f82119bdc19b
33fb48a92e8a147850e69e38678f61ee7db2a610
v1.0
instruct
Code_Contests
Code_Contests_47981_I
You are given an array of n integers. You need to find the "beauty" of every subarray of the given array. The "beauty" of a subarray is defined as the number of distinct prime numbers that are present in that subarray. A prime number is a number that has no divisors other than 1 and itself. A subarray is a contiguous...
def sieve_of_eratosthenes(max_num): """ Generate a list of primes up to max_num (inclusive) """ is_prime = [True] * (max_num + 1) p = 2 while p * p <= max_num: if is_prime[p]: for i in range(p * p, max_num + 1, p): is_prime[i] = False p += 1 is_prime[0] = ...
from solution import find_beauty_of_subarrays def test_single_element_prime(): assert find_beauty_of_subarrays([2]) == [1] def test_single_element_non_prime(): assert find_beauty_of_subarrays([4]) == [0] def test_multiple_elements(): array = [2, 3, 4, 5, 6] expected_output = [ 1, 2, 2, 3, 3, ...
[ { "docstring": "Generate a list of primes up to max_num (inclusive) ", "function_declaration": "def sieve_of_eratosthenes(max_num):", "function_name": "sieve_of_eratosthenes", "parameter_list": "(max_num)" }, { "docstring": "Finds the beauty of each subarray of the given array 'a'\nwhere bea...
[ 0, 0, 0, 0, 0, 0, 0, 1, 1, 0 ]
2
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(num):\n if num <= 1:\n return False\n if num <= 3:\n return True\n if num % 2 == 0 or num % 3 == 0:\n return Fal...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00047981", "row_id": 47981, "seed_ids": "[10261]" }
0.627672
Code_Contests_47981
I
[ "sieve_of_eratosthenes", "find_beauty_of_subarrays" ]
2
[ [ "find_beauty_of_subarrays", "sieve_of_eratosthenes" ] ]
1
[]
false
[]
false
pytest
true
[]
true
613af0834753fb9992ccf009e1031191983005a0
d9d3b7257e9c569c26991ad7559bb556e9f72641
v1.0
instruct
Code_Contests
Code_Contests_47995_I
Tom is a fan of unique sequences and has recently come across a fascinating sequence that he wants to explore further. The sequence is defined by the following rules: 1. The sequence starts with an integer `n`. 2. The next number in the sequence is obtained by reversing the digits of the current number and then adding...
def reverse_number(n): """ Returns the reverse of the given number. """ return int(str(n)[::-1]) def is_palindromic(n): """ Checks if the given number is palindromic. """ return str(n) == str(n)[::-1] def find_palindromic_number(n): """ Finds the smallest palindromic number sta...
from solution import reverse_number, is_palindromic, find_palindromic_number, process_test_cases def test_reverse_number(): assert reverse_number(123) == 321 assert reverse_number(87) == 78 assert reverse_number(1) == 1 assert reverse_number(4321) == 1234 def test_is_palindromic(): assert is_palin...
[ { "docstring": "Returns the reverse of the given number.", "function_declaration": "def reverse_number(n):", "function_name": "reverse_number", "parameter_list": "(n)" }, { "docstring": "Checks if the given number is palindromic.", "function_declaration": "def is_palindromic(n):", "f...
[ 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 reverse_number(n):\n \"\"\"\n Reverses the digits of the given number.\n \"\"\"\n return int(str(n)[::-1])\n\ndef is_palindrome(n):\n \"...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00047995", "row_id": 47995, "seed_ids": "[11736]" }
0.731954
Code_Contests_47995
I
[ "reverse_number", "is_palindromic", "find_palindromic_number", "process_test_cases" ]
4
[ [ "find_palindromic_number", "is_palindromic" ], [ "find_palindromic_number", "reverse_number" ], [ "process_test_cases", "find_palindromic_number" ] ]
3
[ "process_test_cases" ]
false
[]
false
pytest
true
[]
true
581b9c602b5b8b711144270a26d61f9001ee220f
0c6c022dde631d13126fc0e4de0aa618bca0f1ce
v1.0
instruct
Code_Contests
Code_Contests_48010_I
Alex loves exploring prime numbers. A prime number is a natural number greater than 1 that has no positive divisors other than 1 and itself. Alex is particularly fascinated by pairs of prime numbers that differ by exactly 2. Such pairs of primes are called "twin primes". For example, (3, 5) and (11, 13) are twin primes...
def sieve_of_eratosthenes(n): """Use the Sieve of Eratosthenes to find all primes up to n.""" is_prime = [True] * (n + 1) is_prime[0] = is_prime[1] = False for start in range(2, int(n**0.5) + 1): if is_prime[start]: for multiple in range(start*start, n + 1, start): ...
from solution import largest_twin_prime_pair def test_example_1(): assert largest_twin_prime_pair(10) == "5 7" def test_example_2(): assert largest_twin_prime_pair(15) == "11 13" def test_example_3(): assert largest_twin_prime_pair(2) == "-1" def test_no_twin_primes(): assert largest_twin_prime_pair...
[ { "docstring": "Use the Sieve of Eratosthenes to find all primes up to n.", "function_declaration": "def sieve_of_eratosthenes(n):", "function_name": "sieve_of_eratosthenes", "parameter_list": "(n)" }, { "docstring": "Find the largest twin prime pair (p, p+2) where p+2 ≤ n.", "function_d...
[ 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 sieve_of_eratosthenes(n):\n \"\"\"Use the Sieve of Eratosthenes to find all primes up to n.\"\"\"\n is_prime = [True] * (n + 1)\n is_prime[0] ...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00048010", "row_id": 48010, "seed_ids": "[2009]" }
0.737727
Code_Contests_48010
I
[ "sieve_of_eratosthenes", "largest_twin_prime_pair" ]
2
[ [ "largest_twin_prime_pair", "sieve_of_eratosthenes" ] ]
1
[]
false
[]
false
pytest
true
[]
true
f203da02148b15f668e338cb02929511632506db
99c049564f8b542c33c3216b9e7c532dbe5d3056
v1.0
instruct
Code_Contests
Code_Contests_48050_I
A scientist in a lab is studying DNA sequences. Each sequence is represented as a string consisting of characters 'A', 'C', 'G', and 'T'. The scientist defines a good substring as one that has an equal number of 'A's, 'C's, 'G's, and 'T's. Given a DNA sequence, help the scientist determine the length of the shortest go...
def find_shortest_good_substring_length(dna_sequences): results = [] for dna in dna_sequences: n = len(dna) min_length = n + 1 # Initialize with a large value (larger than any possible substring) for start in range(n): count = {'A': 0, 'C': 0, 'G': 0, 'T': 0} ...
from solution import process_input_and_find_shortest_good_substring_length def test_single_case(): sequences = ["AGCT"] result = process_input_and_find_shortest_good_substring_length(1, sequences) assert result == [4] def test_multiple_cases(): sequences = ["AGCT", "AAGGCCTT", "ACGTACGTACGT"] resu...
[ { "docstring": null, "function_declaration": "def find_shortest_good_substring_length(dna_sequences):", "function_name": "find_shortest_good_substring_length", "parameter_list": "(dna_sequences)" }, { "docstring": null, "function_declaration": "def process_input_and_find_shortest_good_su...
[ 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 find_shortest_good_substring_length(dna_sequences):\n results = []\n for dna in dna_sequences:\n n = len(dna)\n min_length = n + 1 ...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00048050", "row_id": 48050, "seed_ids": "[7206]" }
0.696843
Code_Contests_48050
I
[ "find_shortest_good_substring_length", "process_input_and_find_shortest_good_substring_length" ]
2
[ [ "process_input_and_find_shortest_good_substring_length", "find_shortest_good_substring_length" ] ]
1
[]
false
[]
false
pytest
true
[]
true
e66f2eea6c6c431fa94ffb270fc0a60d3685f176
7f2cd9803caaae1c3619e089a9cac42c8919884c
v1.0
instruct
Code_Contests
Code_Contests_48062_I
Sophia enjoys playing a computer game in which she must navigate a character through a maze. The maze is represented by a grid, where some cells contain obstacles and others are free paths. Sophia can move her character up, down, left, or right, but can't move diagonally or through obstacles. Sophia wants to determine ...
from collections import deque def shortest_path(maze, n, m, sx, sy, dx, dy): # Directions for movement: right, down, left, up directions = [(0, 1), (1, 0), (0, -1), (-1, 0)] # BFS initialization queue = deque([(sx, sy, 0)]) # queue holds tuples of (current_x, current_y, steps_taken) visited = ...
import pytest from solution import solve, parse_input def test_shortest_path(): input_list = [ "2", "5 5", ".....", ".###.", "..#..", ".###.", ".....", "0 0 4 4", "3 3", "..#", "#.#", "..#", "0 0 2 2" ] ...
[ { "docstring": null, "function_declaration": "def shortest_path(maze, n, m, sx, sy, dx, dy):", "function_name": "shortest_path", "parameter_list": "(maze, n, m, sx, sy, dx, dy)" }, { "docstring": null, "function_declaration": "def solve(mazes):", "function_name": "solve", "parame...
[ 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 deque\n\ndef shortest_path(grid, start, end):\n n = len(grid)\n m = len(grid[0])\n sx, sy = start\n dx, dy = end\n \...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00048062", "row_id": 48062, "seed_ids": "[5157]" }
0.761587
Code_Contests_48062
I
[ "shortest_path", "solve", "parse_input" ]
3
[ [ "solve", "shortest_path" ] ]
1
[ "parse_input" ]
false
[]
false
pytest
true
[]
true
cb75bd38b6f470386f1802833ae5b6ba67cdaf44
67d83c8ec55ec09000047f07cc2e29768807a51a
v1.0
instruct
Code_Contests
Code_Contests_48078_I
A company is developing an automated delivery system involving autonomous drones. The drones have to deliver packages to various locations in a city grid. We need to calculate the shortest path a drone should take to deliver a package from a start location to a destination. The drones can move up, down, left, or right ...
from collections import deque def bfs_shortest_path(grid, start, end): """ Finds the shortest path in a grid from start to end avoiding obstacles. """ directions = [(-1, 0), (1, 0), (0, -1), (0, 1)] queue = deque([(start[0], start[1], 0)]) # (x, y, distance) seen = set([(start[0], start[1])]) ...
def test_shortest_path(): input_data = """5 5 0 0 4 4 3 1 1 2 2 3 3 5 5 0 0 4 4 0 0 0""" results = process_input(input_data) assert results == [8, 8] def test_no_possible_path(): input_data = """5 5 0 0 4 4 25 0 1 0 2 0 3 0 4 1 0 1 1 1 2 1 3 1 4 2 0 2 1 2 2 2 3 2 4 3 0 3 1 3 2 3 3 3 4 4 0 4 1 4 2 4 3 4...
[ { "docstring": "Finds the shortest path in a grid from start to end avoiding obstacles.", "function_declaration": "def bfs_shortest_path(grid, start, end):", "function_name": "bfs_shortest_path", "parameter_list": "(grid, start, end)" }, { "docstring": null, "function_declaration": "def ...
[ 1, 0 ]
1
medium
0.5
{ "trial_gpt4o_0": null, "trial_gpt4o_1": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared1_results_combined.jsonl", "solution_code": "from collections import deque\n\ndef bfs_shortest_path(grid, start, end):\n \"\"\"\n Finds the shortest path in a grid from ...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00048078", "row_id": 48078, "seed_ids": "[9781]" }
0.701151
Code_Contests_48078
I
[ "bfs_shortest_path", "shortest_path", "process_input" ]
3
[ [ "process_input", "shortest_path" ], [ "shortest_path", "bfs_shortest_path" ] ]
2
[ "process_input" ]
false
[]
false
pytest
false
[]
true
c322a7c393e5019d0caa9014c9680643376b64aa
3da3a35c0bf5333bf2ae1d5cb4a288fe597174ae
v1.0
instruct
Code_Contests
Code_Contests_48119_I
You are given two segments in a 2D plane. Each segment is defined by its endpoints. Determine if these two segments intersect. Here is a simplified description of the segments and the intersection: Segments are defined by their endpoints (x1, y1), (x2, y2) and (x3, y3), (x4, y4). Two segments intersect if they have ...
def orientation(p, q, r): """ Return the orientation of the ordered 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...
from solution import do_segments_intersect def test_case_1(): assert do_segments_intersect(1, 1, 4, 4, 1, 8, 2, 4) == "NO" def test_case_2(): assert do_segments_intersect(1, 1, 4, 4, 2, 2, 3, 3) == "YES" def test_case_3(): assert do_segments_intersect(1, 1, 4, 4, 4, 4, 5, 5) == "YES" def test_collinear_...
[ { "docstring": "Return the orientation of the ordered 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": "Given three c...
[ 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 intersect(x1, y1, x2, y2, x3, y3, x4, y4):\n def orientation(px, py, qx, qy, rx, ry):\n # To find the orientation of the ordered triplet (p, ...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00048119", "row_id": 48119, "seed_ids": "[5274]" }
0.645948
Code_Contests_48119
I
[ "orientation", "on_segment", "segments_intersect", "do_segments_intersect" ]
4
[ [ "do_segments_intersect", "segments_intersect" ], [ "segments_intersect", "on_segment" ], [ "segments_intersect", "orientation" ] ]
3
[]
false
[]
false
pytest
true
[]
true
ee014a83364e22b445775625468d967611322e8c
960ec6e38bdfab9d3818030d1efca91b755df948
v1.0
instruct
Code_Contests
Code_Contests_48210_I
You are tasked with maintaining a water distribution network. The network consists of N reservoirs connected by M unidirectional pipes. Each reservoir is represented by a node, and each pipe is represented by a directed edge with a specific flow capacity. The goal is to maximize the water flow from the main reservoir (...
from collections import deque def bfs(capacity, source, sink, parent): visited = [False] * len(capacity) queue = deque([source]) visited[source] = True while queue: current = queue.popleft() for adj, cap in enumerate(capacity[current]): if not visited[adj] and cap > 0: ...
def test_small_case(): n = 6 m = 9 edges = [ (0, 1, 16), (0, 2, 13), (1, 2, 10), (1, 3, 12), (2, 1, 4), (2, 4, 14), (3, 2, 9), (3, 5, 20), (4, 3, 7), (4, 5, 4) ] assert edmonds_karp(n, m, edges) == 23 def test_single_pi...
[ { "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, m, edges):", "function_name": "edmonds_karp", ...
[ 0, 0, 1 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "from collections import deque\n\ndef bfs_capacity(graph, source, sink, parent):\n visited = set()\n queue = deque([source])\n visited.add(source)\...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00048210", "row_id": 48210, "seed_ids": "[3143]" }
0.567897
Code_Contests_48210
I
[ "bfs", "edmonds_karp" ]
2
[ [ "edmonds_karp", "bfs" ] ]
1
[]
false
[]
false
pytest
false
[]
true
91c18a36dcbdf210e571c944087aec11ad279622
10e19a8a5e11be76c8ffabad3e62fe255a6c0ff3
v1.0
instruct
Code_Contests
Code_Contests_48236_I
You are given a binary search tree (BST) with n nodes. Each node of the BST contains an integer value and a pointer to its left and right child nodes. Your task is to implement a function that deletes a given node from the BST while preserving the properties of the BST. The properties of a BST are: - The left subtree ...
class TreeNode: def __init__(self, val=0, left=None, right=None): self.val = val self.left = left self.right = right def delete_node(root: TreeNode, value: int) -> TreeNode: if root is None: return None if value < root.val: root.left = delete_node(root.left, value) ...
from solution import TreeNode, delete_node def build_tree(values, index=0): if index >= len(values) or values[index] is None: return None node = TreeNode(values[index]) node.left = build_tree(values, 2*index + 1) node.right = build_tree(values, 2*index + 2) return node def tree_to_list(roo...
[]
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "class TreeNode:\n def __init__(self, val=0, left=None, right=None):\n self.val = val\n self.left = left\n self.right = right\n\ndef...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00048236", "row_id": 48236, "seed_ids": "[13068]" }
0.531341
Code_Contests_48236
I
[ "delete_node", "get_min" ]
2
[ [ "delete_node", "get_min" ] ]
1
[]
false
[ "TreeNode" ]
true
pytest
true
[]
true
860ae843c12ddeabd5f6946575d50cb7b14ce4a2
a8f044e77b298ddb72516405197a5ff2008b9ee7
v1.0
instruct
Code_Contests
Code_Contests_48243_I
A local delivery company wants to optimize its delivery routes. The company has one central warehouse and several delivery points distributed in a city. A delivery truck will start from the warehouse, deliver packages to all the points, and return to the warehouse. The company uses a bidirectional road network where ro...
import itertools def calculate_min_travel_time(n, roads): # Create a 2D array (matrix) to store the travel times between points travel_times = [[float('inf')] * n for _ in range(n)] # Fill in the travel times from the roads data for u, v, t in roads: travel_times[u-1][v-1] = t trav...
from solution import minimum_travel_time def test_example_case(): n, m = 4, 6 roads = [ (1, 2, 10), (1, 3, 15), (1, 4, 20), (2, 3, 35), (2, 4, 25), (3, 4, 30) ] assert minimum_travel_time(n, m, roads) == 80 def test_two_points_case(): n, m = 2, 1 ...
[ { "docstring": null, "function_declaration": "def calculate_min_travel_time(n, roads):", "function_name": "calculate_min_travel_time", "parameter_list": "(n, roads)" }, { "docstring": null, "function_declaration": "def minimum_travel_time(n, m, roads):", "function_name": "minimum_tra...
[ 0, 0, 0, 1 ]
1
hard
0.25
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "from itertools import permutations\n\ndef min_travel_time(n, m, roads):\n # Initialize adjacency matrix with infinite travel times\n inf = float('inf...
trial_gpt4o_4
{ "original_instruction": "", "prompt_id": "00048243", "row_id": 48243, "seed_ids": "[1243]" }
0.780263
Code_Contests_48243
I
[ "calculate_min_travel_time", "minimum_travel_time" ]
2
[ [ "minimum_travel_time", "calculate_min_travel_time" ] ]
1
[]
false
[]
false
pytest
true
[]
true
bc1eae03266415191bdd58320e7615cdd65c1c66
3f3d29cdb00f361b93b533365846b5a1f09bde86
v1.0
instruct
Code_Contests
Code_Contests_48253_I
John has a garden with a variety of flowers each identified by a unique integer ID. He wants to create a beautiful flower arrangement for a special event. However, he has a peculiar rule for choosing the flowers for the arrangement: he wants the arrangement to consist of flowers in consecutive IDs (with no gaps in betw...
def max_even_consecutive_flowers(n, flower_ids): """ Returns the maximum number of flowers in the largest arrangement that John can create while following the rule of consecutive IDs and even total number of flowers. Parameters: - n: int, number of flower IDs available. - flower_ids: list o...
from solution import max_even_consecutive_flowers def test_example_1(): assert max_even_consecutive_flowers(5, [1, 3, 5, 6, 7]) == 2 def test_example_2(): assert max_even_consecutive_flowers(7, [2, 3, 5, 6, 7, 8, 10]) == 4 def test_single_flower(): assert max_even_consecutive_flowers(1, [1]) == 0 def te...
[ { "docstring": "Returns the maximum number of flowers in the largest arrangement that John\ncan create while following the rule of consecutive IDs and even total number of flowers.\n\nParameters:\n- n: int, number of flower IDs available.\n- flower_ids: list of int, distinct flower IDs.\n\nReturns:\n- int, the ...
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def max_even_consecutive_flowers(n, flower_ids):\n \"\"\"\n Determine the maximum number of flowers John can choose \n while satisfying his rule o...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00048253", "row_id": 48253, "seed_ids": "[1939]" }
0.610043
Code_Contests_48253
I
[ "max_even_consecutive_flowers", "is_consecutive" ]
2
[ [ "max_even_consecutive_flowers", "is_consecutive" ] ]
1
[]
false
[]
false
pytest
true
[]
true
3ddfa6865c4aee23b4122a8491d87be5f9372f90
9776271f9d404f0f7d0e62539307ae40febd614c
v1.0
instruct
Code_Contests
Code_Contests_48257_I
You are given a grid of n x m (n rows and m columns), where each cell contains either '0' or '1'. A cell with '1' is considered a point. The task is to find the largest rectangle (in terms of the number of cells) containing only '1's and return its area. Input The first line contains two integers n (1 ≤ n ≤ 200) and ...
def maximalRectangle(matrix): if not matrix: return 0 n, m = len(matrix), len(matrix[0]) heights = [0] * (m + 1) max_area = 0 for i in range(n): for j in range(m): if matrix[i][j] == '1': heights[j] += 1 else: heights[j] =...
from solution import parse_and_solve def test_example1(): input_str = "4 4\n1010\n1011\n1111\n0011" assert parse_and_solve(input_str) == 6 def test_example2(): input_str = "3 3\n111\n110\n011" assert parse_and_solve(input_str) == 4 def test_example3(): input_str = "5 6\n011011\n111010\n110110\n11...
[ { "docstring": null, "function_declaration": "def maximalRectangle(matrix):", "function_name": "maximalRectangle", "parameter_list": "(matrix)" }, { "docstring": null, "function_declaration": "def parse_and_solve(input_string):", "function_name": "parse_and_solve", "parameter_lis...
[ 1, 0, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def maximalRectangle(matrix):\n if not matrix:\n return 0\n \n n, m = len(matrix), len(matrix[0])\n heights = [0] * (m + 1)\n max_are...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00048257", "row_id": 48257, "seed_ids": "[8484]" }
0.734531
Code_Contests_48257
I
[ "maximalRectangle", "parse_and_solve" ]
2
[ [ "parse_and_solve", "maximalRectangle" ] ]
1
[]
false
[]
false
pytest
true
[]
true
1ea3761dc87692847aa46e3bdeb848a5c2fea11b
41afb5f71c7e1cb89c8eca51901a85581a00c89e
v1.0
instruct
Code_Contests
Code_Contests_48266_I
You are given a binary string which only contains the characters '0' and '1'. You need to perform a series of flip operations and query operations on this string. In a flip operation, you can flip the bits between two given indices (inclusive). In a query operation, you need to return the count of '1's within a given r...
def flip_bits(binary_string, l, r): binary_list = list(binary_string) for i in range(l-1, r): binary_list[i] = '1' if binary_list[i] == '0' else '0' return ''.join(binary_list) def count_ones(binary_string, l, r): return binary_string[l-1:r].count('1') def process_operations(s, operations): ...
from solution import process_operations def test_example_case(): s = "1100" operations = ["1 2 3", "2 1 4", "1 1 4", "2 1 4", "2 1 2"] assert process_operations(s, operations) == [2, 2, 1] def test_single_flip(): s = "0000" operations = ["1 1 4", "2 1 4"] assert process_operations(s, operation...
[ { "docstring": null, "function_declaration": "def flip_bits(binary_string, l, r):", "function_name": "flip_bits", "parameter_list": "(binary_string, l, r)" }, { "docstring": null, "function_declaration": "def count_ones(binary_string, l, r):", "function_name": "count_ones", "para...
[ 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_operations(s, operations):\n s = list(s) # Modify string as a list of characters for easier mutation.\n \n output = []\n\n for ope...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00048266", "row_id": 48266, "seed_ids": "[13175]" }
0.736537
Code_Contests_48266
I
[ "flip_bits", "count_ones", "process_operations" ]
3
[ [ "process_operations", "count_ones" ], [ "process_operations", "flip_bits" ] ]
2
[]
false
[]
false
pytest
true
[]
true
b6a45047ee16aa92afadc81a13cf2049bc099eac
89b09ed06223279bd46c85c738c72e7c9d847d7d
v1.0
instruct
Code_Contests
Code_Contests_48289_I
Write a function that takes a list of integers and returns a new list containing only the prime numbers from the original list. Input A list of integers. Output A list containing only the prime numbers from the input list. The order of the elements in the output list should be the same as their order in the input l...
def is_prime(n): """ Helper function to check if a number is a prime. """ if n <= 1: return False if n == 2: return True # 2 is the only even prime number if n % 2 == 0: return False max_divisor = int(n**0.5) + 1 for d in range(3, max_divisor, 2): if n % ...
from solution import is_prime, filter_primes def test_is_prime(): assert not is_prime(1) # 1 is not prime assert is_prime(2) # 2 is prime assert is_prime(3) # 3 is prime assert not is_prime(4) # 4 is not prime assert is_prime(29) # 29 is prime assert not is_prime(10) #...
[ { "docstring": "Helper function to check if a number is a prime.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Returns a list containing only the prime numbers from the input list.", "function_declaration": "def filt...
[ 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 Helper function to check if a number is a prime.\n \"\"\"\n if n <= 1:\n return False\n if n == 2:\n ...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00048289", "row_id": 48289, "seed_ids": "[1981]" }
0.652135
Code_Contests_48289
I
[ "is_prime", "filter_primes" ]
2
[ [ "filter_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
22d076664d0c774788e1d2d70c2d6ad55d387b4a
3dd8043b7e024d1b06599129e9ac0f7c44e1b4c7
v1.0
instruct
Code_Contests
Code_Contests_48330_I
Given an integer N, find the smallest prime number greater than N for which the sum of its digits is a prime number as well. Input format: The first line contains an integer T, the number of test cases. Each of the next T lines contains an integer N. Output format: For each test case, print the smallest prime number ...
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 sum_of_digits...
from solution import is_prime, sum_of_digits, smallest_prime_with_prime_digit_sum, find_primes_for_cases def test_is_prime(): assert is_prime(2) == True assert is_prime(3) == True assert is_prime(4) == False assert is_prime(29) == True assert is_prime(30) == False def test_sum_of_digits(): ass...
[ { "docstring": null, "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": null, "function_declaration": "def sum_of_digits(n):", "function_name": "sum_of_digits", "parameter_list": "(n)" }, { "docstring": n...
[ 0, 0, 1 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "import math\n\ndef is_prime(n):\n \"\"\"Check if a number is prime.\"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return True\n ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00048330", "row_id": 48330, "seed_ids": "[2782]" }
0.632274
Code_Contests_48330
I
[ "is_prime", "sum_of_digits", "smallest_prime_with_prime_digit_sum", "find_primes_for_cases" ]
4
[ [ "find_primes_for_cases", "smallest_prime_with_prime_digit_sum" ], [ "smallest_prime_with_prime_digit_sum", "is_prime" ], [ "smallest_prime_with_prime_digit_sum", "sum_of_digits" ] ]
3
[]
false
[]
false
pytest
true
[]
true
cf90b7c50ac15159d7a071c7ce422366b3dd3861
0dc07e52b1f88a5a007356f3fffe159c1d6888b0
v1.0
instruct
Code_Contests
Code_Contests_48382_I
Given a sequence of n numbers, your task is to determine if it is possible to split the sequence into two partitions such that the sum of the numbers in each partition is the same. If it is possible, print "YES", otherwise print "NO". Each input line contains a sequence of space-separated integers. The end of the inpu...
def can_partition(nums): """ Determines if it is possible to partition the nums list into two subsets such that the sum of the subsets is equal. """ total_sum = sum(nums) if total_sum % 2 != 0: return "NO" target = total_sum // 2 n = len(nums) dp = [False] * (t...
from solution import can_partition, process_input_lines def test_can_partition(): assert can_partition([1, 5, 11, 5]) == "YES" assert can_partition([1, 2, 3, 5]) == "NO" assert can_partition([3, 3, 3, 3]) == "YES" assert can_partition([1, 1, 1]) == "NO" assert can_partition([]) == "YES" # Edge cas...
[ { "docstring": "Determines if it is possible to partition the nums list into two subsets\nsuch that the sum of the subsets is equal.", "function_declaration": "def can_partition(nums):", "function_name": "can_partition", "parameter_list": "(nums)" }, { "docstring": "Processes the given list ...
[ 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 can_partition(nums):\n \"\"\"\n Determines if a list of numbers can be partitioned into two subsets with equal sum.\n \n Parameters:\n n...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00048382", "row_id": 48382, "seed_ids": "[6654]" }
0.656239
Code_Contests_48382
I
[ "can_partition", "process_input_lines" ]
2
[ [ "process_input_lines", "can_partition" ] ]
1
[]
false
[]
false
pytest
true
[]
true
88186e9d72c03d5ecacb47d0149a8d300276f624
9f551c3a9f7e35ffd24027bde7ebbeab74d4339d
v1.0
instruct
Code_Contests
Code_Contests_48654_I
Two scientists, Dr. Xavier and Dr. Yara, are collaborating on a special experiment. They are using a computer simulation that involves prime numbers and dynamic arrays. The experiment starts with an empty list, and the scientists take turns adding elements to this list. Dr. Xavier always adds the smallest prime numbe...
def generate_primes_upto(n): """ Generates all prime numbers up to n using the Sieve of Eratosthenes. """ is_prime = [True] * (n + 1) p = 2 while p * p <= n: if is_prime[p]: for i in range(p * p, n + 1, p): is_prime[i] = False p += 1 primes = [p fo...
def test_generate_primes_upto(): assert generate_primes_upto(10) == [2, 3, 5, 7] assert generate_primes_upto(20) == [2, 3, 5, 7, 11, 13, 17, 19] def test_product_of_primes(): assert product_of_primes(3) == 30 assert product_of_primes(4) == 210 assert product_of_primes(5) == 2310 def test_primes_pr...
[ { "docstring": "Generates all prime numbers up to n using the Sieve of Eratosthenes.", "function_declaration": "def generate_primes_upto(n):", "function_name": "generate_primes_upto", "parameter_list": "(n)" }, { "docstring": "Returns the product of the first k prime numbers modulo 10^9 + 7....
[ 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 generate_primes_upto(n):\n \"\"\"\n Generates all prime numbers up to n using the Sieve of Eratosthenes.\n \"\"\"\n is_prime = [True] * (n ...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00048654", "row_id": 48654, "seed_ids": "[13248]" }
0.604517
Code_Contests_48654
I
[ "generate_primes_upto", "product_of_primes", "primes_product_for_turns", "main" ]
4
[ [ "primes_product_for_turns", "product_of_primes" ], [ "product_of_primes", "generate_primes_upto" ] ]
2
[]
false
[]
false
pytest
false
[]
true
5080faf4ced7df8de1f0be79617bf91d637ca2cb
f44f7491262a4c2b25bf7c7a94e8f1c2274ffd75
v1.0
instruct
Code_Contests
Code_Contests_48791_I
Alice loves trees, particularly binary trees. She has a special type of binary tree called a "perfect binary tree". A perfect binary tree is one in which all interior nodes have two children and all leaves are at the same level. Alice also enjoys prime numbers. She thinks that a binary tree is beautiful if the number ...
def is_prime(n): """Check if a number is prime""" if n <= 1: return False if n <= 3: return True if n % 2 == 0 or n % 3 == 0: return False i = 5 while i * i <= n: if n % i == 0 or n % (i + 2) == 0: return False i += 6 return True def is_tr...
from solution import is_tree_beautiful def test_height_1(): # For height 1, perfect binary tree has 1 non-leaf node, which is not prime. assert is_tree_beautiful(1) == "NO" def test_height_2(): # For height 2, perfect binary tree has 3 non-leaf nodes, which is prime. assert is_tree_beautiful(2) == "YE...
[ { "docstring": "Check if a number is prime", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Determines if a perfect binary tree of height h is beautiful.\nA tree is beautiful if the number of non-leaf nodes is a prime numbe...
[ 0, 1, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(n):\n \"\"\"\n Returns True if n is a prime number, otherwise False.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00048791", "row_id": 48791, "seed_ids": "[1313]" }
0.566773
Code_Contests_48791
I
[ "is_prime", "is_tree_beautiful" ]
2
[ [ "is_tree_beautiful", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
dc5489fc3e46bc8226a3d11db940d5616e1c8dfb
a78b12d21cf260d23ca1eb8fa854bb6163283cb9
v1.0
instruct
Code_Contests
Code_Contests_48808_I
You are given a grid representing a battlefield, where: - '.' denotes an empty cell. - '#' denotes a blocked cell that cannot be passed through. - 'S' denotes the starting point. - 'E' denotes the endpoint. Your task is to determine if there exists a path from the starting point to the endpoint using only horizontal a...
def is_path_possible(grid, N): from collections import deque def bfs(sx, sy, ex, ey): directions = [(-1, 0), (1, 0), (0, -1), (0, 1)] queue = deque([(sx, sy)]) visited = set([(sx, sy)]) while queue: x, y = queue.popleft() if (x, ...
def test_is_path_possible(): assert is_path_possible([ ['S', '.', '.'], ['.', '#', '.'], ['.', '.', 'E'] ], 3) == "POSSIBLE" assert is_path_possible([ ['S', '.', '.'], ['#', '#', '#'], ['.', '.', 'E'] ], 3) == "IMPOSSIBLE" assert is_path_possible...
[ { "docstring": null, "function_declaration": "def is_path_possible(grid, N):", "function_name": "is_path_possible", "parameter_list": "(grid, N)" }, { "docstring": null, "function_declaration": "def evaluate_grids(grids):", "function_name": "evaluate_grids", "parameter_list": "(g...
[ 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_path_possible(grid, N):\n from collections import deque\n \n def bfs(sx, sy, ex, ey):\n directions = [(-1, 0), (1, 0), (0, -1), (0, ...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00048808", "row_id": 48808, "seed_ids": "[11561]" }
0.749213
Code_Contests_48808
I
[ "is_path_possible", "evaluate_grids", "bfs_solve_battlefield" ]
3
[ [ "bfs_solve_battlefield", "is_path_possible" ], [ "evaluate_grids", "is_path_possible" ] ]
2
[]
false
[]
false
pytest
false
[]
true
4376261f1810b17c0f2a5afc96b748b9bbaf3826
aad55d1e148d2163eca4e9f0e17b21096ac8dc85
v1.0
instruct
Code_Contests
Code_Contests_48823_I
A brilliant programmer loves working with strings. Here’s a problem that challenges their abilities. You are given a string `s` that consists of lowercase English letters. Your task is to quickly process the requests of two types: * Request of form: 0 p q. For this request, calculate the number of distinct substrings...
def count_distinct_substrings(s): """ Function to count the number of distinct substrings of a given string s. """ n = len(s) substrings = set() # Generate all possible substrings and store in a set to avoid duplicates for i in range(n): for j in range(i + 1, n + 1): ...
from solution import process_requests def test_example_case(): n = 7 q = 5 s = "abcdeab" requests = [ (0, 1, 3), (1, 7, 'f'), (0, 1, 7), (1, 5, 'z'), (0, 1, 5) ] expected_output = [6, 27, 15] assert process_requests(n, q, s, requests) == expected_outp...
[ { "docstring": "Function to count the number of distinct substrings of a given string s.", "function_declaration": "def count_distinct_substrings(s):", "function_name": "count_distinct_substrings", "parameter_list": "(s)" }, { "docstring": "Function to process the given requests and return r...
[ 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": "class SubstringProcessor:\n\n def __init__(self, s):\n self.s = list(s)\n\n def count_distinct_substrings(self, p, q):\n substring = ''...
trial_gpt4o_3
{ "original_instruction": "", "prompt_id": "00048823", "row_id": 48823, "seed_ids": "[6182]" }
0.83731
Code_Contests_48823
I
[ "count_distinct_substrings", "process_requests" ]
2
[ [ "process_requests", "count_distinct_substrings" ] ]
1
[]
false
[]
false
pytest
true
[]
true
bf7482f7276e20823f8f1ccfcf9fb7ce4789ee00
40965c11f33807dc0420a9db39517f484e4746c3
v1.0
instruct
Code_Contests
Code_Contests_48826_I
Given two cousins A and B, both play a number game to test their arithmetic skills. They take turns to choose a single positive integer from a list of integers and the chosen number is added to either A or B's active number according to predefined rules. The purpose of the game is to find out the final combined sum of ...
def combined_sum(n, numbers): """ Returns combined sum of A and B's active numbers after all integers are chosen. As we can add the integers to either A or B, the final combined sum will simply be the sum of all integers in the list. """ return sum(numbers) # Function to parse the input, compute th...
from solution import combined_sum, calculate_combined_sum def test_combined_sum_simple_case(): assert combined_sum(5, [1, 2, 3, 4, 5]) == 15 def test_combined_sum_another_case(): assert combined_sum(3, [10, 20, 30]) == 60 def test_combined_sum_single_element(): assert combined_sum(1, [42]) == 42 def tes...
[ { "docstring": "Returns combined sum of A and B's active numbers after all integers are chosen.\nAs we can add the integers to either A or B, the final combined sum will simply be the sum of all integers in the list.", "function_declaration": "def combined_sum(n, numbers):", "function_name": "combined_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 combined_sum_of_game_numbers(n, numbers):\n \"\"\"\n Returns the combined total sum of all chosen numbers for A and B in the game.\n \n Arg...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00048826", "row_id": 48826, "seed_ids": "[5880]" }
0.64578
Code_Contests_48826
I
[ "combined_sum", "calculate_combined_sum" ]
2
[ [ "calculate_combined_sum", "combined_sum" ] ]
1
[]
false
[]
false
pytest
true
[]
true
6d9f7fc9326ba294a4a6e0084535c4ad1b2b270b
3fe7633472a525ac0c8710335b25be61c27e9fb6
v1.0
instruct
Code_Contests
Code_Contests_48859_I
Palindromic Subsequence Transformation You are given a sequence of integers A: A1 A2 ... An and a set of transformation rules of the form "x -> y". The following transformation on the sequence is allowed an arbitrary number of times: * Transformation: With a transformation rule "x -> y", transform a sequence c1 c2 .....
from collections import defaultdict, deque def is_palindromic(seq): return seq == seq[::-1] def min_transformations_to_palindrome(n, r, A, transformations): if is_palindromic(A): return 0 transform_dict = defaultdict(list) for x, y in transformations: transform_dict[x].append(...
import pytest from solution import palindromic_transformation def test_case_1(): input_data = "3 3\n1 2 3\n1 3\n2 2\n3 1\n0 0\n" assert palindromic_transformation(input_data) == [1] def test_case_2(): input_data = "4 2\n4 4 2 1\n4 1\n2 3\n0 0\n" assert palindromic_transformation(input_data) == [-1] d...
[ { "docstring": null, "function_declaration": "def is_palindromic(seq):", "function_name": "is_palindromic", "parameter_list": "(seq)" }, { "docstring": null, "function_declaration": "def min_transformations_to_palindrome(n, r, A, transformations):", "function_name": "min_transformati...
[ 1, 0, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "from collections import defaultdict, deque\n\ndef is_palindromic(seq):\n return seq == seq[::-1]\n \ndef min_transformations_to_palindrome(n, r, A, t...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00048859", "row_id": 48859, "seed_ids": "[13004]" }
0.661034
Code_Contests_48859
I
[ "is_palindromic", "min_transformations_to_palindrome", "palindromic_transformation" ]
3
[ [ "min_transformations_to_palindrome", "is_palindromic" ], [ "palindromic_transformation", "min_transformations_to_palindrome" ] ]
2
[]
false
[]
false
pytest
true
[]
true
545c237cf84b3062431369a93cb4f2e11a31bf59
0f9058a75501a4f4b6fab6b6652562bd4eac3a2b
v1.0
instruct
Code_Contests
Code_Contests_48909_I
In a distant land, there is a unique factory called ShapeMaker which specializes in creating a variety of different shapes from a given set of building blocks. Each building block is defined by its size and shape. The factory can create a new composite shape by combining a specified number of building blocks in a parti...
def can_create_composite_shapes(blocks, required_shapes): from collections import defaultdict # Parse block sizes by shape block_sizes = defaultdict(list) for shape, size in blocks: block_sizes[shape].append(size) # Sort each shape's block sizes for efficient comparison for sha...
def test_possible_creation_case_1(): blocks_data = [('circle', 10), ('circle', 20), ('square', 5), ('square', 10)] required_data = [('circle', 25), ('square', 10)] assert is_creation_possible(4, blocks_data, 2, required_data) == 'Possible' def test_impossible_creation_case_2(): blocks_data = [('circle'...
[ { "docstring": null, "function_declaration": "def can_create_composite_shapes(blocks, required_shapes):", "function_name": "can_create_composite_shapes", "parameter_list": "(blocks, required_shapes)" }, { "docstring": null, "function_declaration": "def is_creation_possible(N, blocks_data...
[ 0, 0, 0, 1, 1 ]
2
medium
0.4
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_possible_to_create_composite_shape(n, blocks, m, requirements):\n # Organize blocks by shape\n block_dict = {}\n for shape, size in blocks:...
trial_gpt4o_4
{ "original_instruction": "", "prompt_id": "00048909", "row_id": 48909, "seed_ids": "[8951]" }
0.589495
Code_Contests_48909
I
[ "can_create_composite_shapes", "is_creation_possible" ]
2
[ [ "is_creation_possible", "can_create_composite_shapes" ] ]
1
[]
false
[]
false
pytest
false
[]
true
5a50b6da2e94e03b5c72a9374ca3bbbc2603cd2d
0f6387cdece70c5ac81dd92784d1e7ab18fdbbbc
v1.0
instruct
Code_Contests
Code_Contests_48949_I
You are tasked with developing a spelling correction algorithm that can suggest corrections for a list of misspelled words given a dictionary of correct words. The algorithm should calculate the edit distance between the misspelled word and each word in the dictionary and suggest the closest matches. Edit distance is ...
def edit_distance(word1, word2): """ Compute the edit distance between two words. """ m, n = len(word1), len(word2) dp = [[0] * (n + 1) for _ in range(m + 1)] for i in range(m + 1): for j in range(n + 1): if i == 0: dp[i][j] = j elif j ==...
from solution import spell_correction, edit_distance def test_edit_distance(): assert edit_distance("apple", "aplle") == 1 assert edit_distance("banana", "bannana") == 1 assert edit_distance("orage", "orange") == 1 assert edit_distance("cot", "cat") == 1 assert edit_distance("bat", "bat") == 0 def...
[ { "docstring": "Compute the edit distance between two words.", "function_declaration": "def edit_distance(word1, word2):", "function_name": "edit_distance", "parameter_list": "(word1, word2)" }, { "docstring": null, "function_declaration": "def spell_correction(test_cases):", "functi...
[ 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 edit_distance(word1, word2):\n len1, len2 = len(word1), len(word2)\n dp = [[0] * (len2 + 1) for _ in range(len1 + 1)]\n\n for i in range(len1 ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00048949", "row_id": 48949, "seed_ids": "[9342]" }
0.62033
Code_Contests_48949
I
[ "edit_distance", "spell_correction" ]
2
[ [ "spell_correction", "edit_distance" ] ]
1
[]
false
[]
false
pytest
true
[]
true
fda7143f1a825a1a20f940514c3b5a63c7a960a5
90d53db10ff8afbf77d4e7976cd402b2009ff9ef
v1.0
instruct
Code_Contests
Code_Contests_49082_I
A company is creating a system to manage the books in their library. Each book has a unique identifier and falls into one of the following categories represented by integers from 1 to 5: - 1: Science Fiction - 2: Romance - 3: Mystery - 4: Biography - 5: Philosophy They have provided you with a pre-labeled dataset, co...
import re from collections import Counter import random # Predefined categories and related sample words for simplification. CATEGORY_WORDS = { 1: ["space", "robot", "time", "future", "alien"], 2: ["love", "romance", "heart", "kiss", "wedding"], 3: ["murder", "detective", "mystery", "crime", "clue"], 4...
def test_predict_category_scifi(): content = "In the future, humanity may encounter alien spaceships and robots." assert predict_category(content) == 1 def test_predict_category_romance(): content = "Their love story began with a romantic wedding by the beach." assert predict_category(content) == 2 de...
[ { "docstring": "Predicts the category of the book based on the content using\nsimplified keyword matching.", "function_declaration": "def predict_category(book_content):", "function_name": "predict_category", "parameter_list": "(book_content)" }, { "docstring": "Classifies the book into a ca...
[ 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 zipfile\nimport os\nimport requests\nfrom sklearn.feature_extraction.text import TfidfVectorizer\nfrom sklearn.naive_bayes import MultinomialNB\nimp...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00049082", "row_id": 49082, "seed_ids": "[7115]" }
0.582378
Code_Contests_49082
I
[ "predict_category", "classify_book" ]
2
[ [ "classify_book", "predict_category" ] ]
1
[]
false
[]
false
pytest
false
[]
true
c0e332a9bfab6d600e937e19ccd10064d128a53e
0bb4c1b9a650f6638394b386aab099ac629f02c2
v1.0
instruct
Code_Contests
Code_Contests_49154_I
The Travelling Salesman Problem (TSP) is a classic algorithmic problem in the fields of computer science and operations research. Given a list of cities and the distances between each pair of cities, the objective is to find the shortest possible route that visits each city exactly once and returns to the original city...
from itertools import permutations def tsp(distance_matrix): N = len(distance_matrix) cities = list(range(N)) min_dist = float('inf') for perm in permutations(cities[1:]): curr_dist = 0 prev_city = 0 for city in perm: curr_dist += distance_matrix[prev_city][city...
from solution import tsp, solve_tsp, parse_input def test_tsp_case_1(): distance_matrix = [ [0, 10, 15, 20], [10, 0, 35, 25], [15, 35, 0, 30], [20, 25, 30, 0] ] assert tsp(distance_matrix) == 80 def test_tsp_case_2(): distance_matrix = [ [0, 29, 20], [29...
[ { "docstring": null, "function_declaration": "def tsp(distance_matrix):", "function_name": "tsp", "parameter_list": "(distance_matrix)" }, { "docstring": null, "function_declaration": "def solve_tsp(test_cases):", "function_name": "solve_tsp", "parameter_list": "(test_cases)" }...
[ 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 tsp(distance_matrix):\n N = len(distance_matrix)\n cities = list(range(N))\n min_dist = float('inf')\n ...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00049154", "row_id": 49154, "seed_ids": "[9572]" }
0.693669
Code_Contests_49154
I
[ "tsp", "solve_tsp", "parse_input", "main" ]
4
[ [ "solve_tsp", "tsp" ] ]
1
[ "parse_input" ]
false
[]
false
pytest
true
[]
true
305bcff65f5adbf41990e2fb0e33562c3438988d
e9e7b0f927be7fa5f7891f7f894f7079808e104a
v1.0
instruct
Code_Contests
Code_Contests_49161_I
Kevin is building his skills in competitive programming and stumbled upon a problem involving leap years. He decided to write a program that checks if a given year is a leap year or not. However, Kevin later found out that the rules he had were not correct, and he needs your help to verify a year based on the correct r...
def is_leap_year(year): """ Returns 'YES' if the given year is a leap year, 'NO' otherwise. """ if (year % 400 == 0) or (year % 4 == 0 and year % 100 != 0): return "YES" else: return "NO" def leap_years(years): """ Given a list of years, returns a list indicating whether eac...
from solution import is_leap_year, leap_years def test_is_leap_year(): assert is_leap_year(2000) == "YES" assert is_leap_year(1900) == "NO" assert is_leap_year(2004) == "YES" assert is_leap_year(1999) == "NO" assert is_leap_year(1600) == "YES" assert is_leap_year(2020) == "YES" assert is_le...
[ { "docstring": "Returns 'YES' if the given year is a leap year, 'NO' otherwise.", "function_declaration": "def is_leap_year(year):", "function_name": "is_leap_year", "parameter_list": "(year)" }, { "docstring": "Given a list of years, returns a list indicating whether each year is a leap yea...
[ 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 is_leap_year(year):\n \"\"\"\n Determines if a given year is a leap year.\n\n :param year: int, the year to check\n :return: str, \"YES\" i...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00049161", "row_id": 49161, "seed_ids": "[7608]" }
0.634129
Code_Contests_49161
I
[ "is_leap_year", "leap_years" ]
2
[ [ "leap_years", "is_leap_year" ] ]
1
[]
false
[]
false
pytest
true
[]
true
160c74eef23fd96a48a5ccb55be2bae123474f31
0b591c43d5ccee630932d1e6cae8d4fa5b1b7ce6
v1.0
instruct
Code_Contests
Code_Contests_49182_I
You are given a directed graph represented as an adjacency list. Your task is to detect if the graph contains a cycle. If a cycle exists, determine the length of the shortest cycle in the graph. If no cycle exists, output -1. A cycle is defined as a non-empty sequence of edges where the start and end vertices are the...
from collections import deque, defaultdict def find_shortest_cycle(n, adj_list): """ Finds the length of the shortest cycle in a directed graph. If no cycle exists, returns -1. Parameters: n (int): Number of vertices in the graph. adj_list (dict): Adjacency list of the graph. Returns: ...
import pytest from solution import detect_cycles def test_single_cycle(): test_cases = [ (4, 5, [(1, 2), (2, 3), (3, 1), (3, 4), (4, 2)]) ] expected = [3] assert detect_cycles(test_cases) == expected def test_no_cycle(): test_cases = [ (3, 2, [(1, 2), (2, 3)]) ] expected = ...
[ { "docstring": "Finds the length of the shortest cycle in a directed graph.\nIf no cycle exists, returns -1.\n\nParameters:\nn (int): Number of vertices in the graph.\nadj_list (dict): Adjacency list of the graph.\n\nReturns:\nint: Length of the shortest cycle, or -1 if no cycle exists.", "function_declarat...
[ 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 deque, defaultdict\n\ndef shortest_cycle_length(n, edges):\n graph = defaultdict(list)\n for u, v in edges:\n graph[u]...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00049182", "row_id": 49182, "seed_ids": "[8455]" }
0.806486
Code_Contests_49182
I
[ "find_shortest_cycle", "process_test_cases", "detect_cycles" ]
3
[ [ "detect_cycles", "process_test_cases" ], [ "process_test_cases", "find_shortest_cycle" ] ]
2
[ "process_test_cases" ]
false
[]
false
pytest
true
[]
true
21353d5bf2b1e842cc8794249b2b93fb73d5e608
3aba487b1bf83030e3f8bbdb526575540211c091
v1.0
instruct
Code_Contests
Code_Contests_49200_I
In a distant galaxy, there are n planets (numbered 1 through n) and m one-way wormholes connecting them. The planets have a unique hierarchy such that each planet can influence certain other planets directly through a wormhole. A scientist on planet 1 wants to send a robot to planet n to gather data. The robot needs t...
import heapq def max_energy_capsules(n, m, wormholes): # Create a graph from the wormholes graph = [[] for _ in range(n + 1)] for u, v, w in wormholes: graph[u].append((v, w)) # Dijkstra-like algorithm to find the maximum path value max_capsules = [-1] * (n + 1) max_capsules[1] = 0...
def test_max_energy_capsules(): input_data_1 = "5 6\n1 2 5\n1 3 10\n2 4 15\n3 4 5\n4 5 10\n3 5 20" assert max_energy_capsules_from_input(input_data_1) == 30 input_data_2 = "4 3\n1 2 10\n2 3 5\n3 4 10" assert max_energy_capsules_from_input(input_data_2) == 25 input_data_3 = "3 1\n1 3 7" assert ...
[ { "docstring": null, "function_declaration": "def max_energy_capsules(n, m, wormholes):", "function_name": "max_energy_capsules", "parameter_list": "(n, m, wormholes)" }, { "docstring": null, "function_declaration": "def max_energy_capsules_from_input(input_data):", "function_name": ...
[ 0, 0, 1 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "from heapq import heappop, heappush\nimport sys\n\ndef max_energy_capsules(n, m, wormholes):\n adj = [[] for _ in range(n + 1)]\n for u, v, w in worm...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00049200", "row_id": 49200, "seed_ids": "[6299]" }
0.570914
Code_Contests_49200
I
[ "max_energy_capsules", "max_energy_capsules_from_input" ]
2
[ [ "max_energy_capsules_from_input", "max_energy_capsules" ] ]
1
[]
false
[]
false
pytest
false
[]
true
8801522329c5eec1c4c32a16b98dbc4d2d627008
219bab6f96274632e8e2f7e805c220cd10f05e82
v1.0
instruct
Code_Contests
Code_Contests_49204_I
A railway system consists of several tracks, each connecting two different stations. Each station is assigned a unique positive integer as its identifier. In any track, a train can travel in both directions. A query can be made to find out: 1. How many railway tracks are directly connected to a specific station. 2. Ho...
def preprocess_tracks(n, tracks): from collections import defaultdict # Dictionary to store counts of tracks connected to each station track_count = defaultdict(int) # Sets to store unique connections direct_connections = defaultdict(set) for a, b in tracks: track_count[a] += 1 ...
from solution import preprocess_tracks, process_queries, railway_system def test_preprocess_tracks(): tracks = [ (1, 2), (2, 3), (3, 4), (4, 5) ] track_count, direct_connections = preprocess_tracks(4, tracks) assert track_count == {1: 1, 2: 2, 3: 2, 4: 2, 5: 1} asser...
[ { "docstring": null, "function_declaration": "def preprocess_tracks(n, tracks):", "function_name": "preprocess_tracks", "parameter_list": "(n, tracks)" }, { "docstring": null, "function_declaration": "def process_queries(q, queries, track_count, direct_connections):", "function_name"...
[ 0, 0, 0, 1, 0 ]
1
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "from collections import defaultdict\n\nclass RailwaySystem:\n def __init__(self, n_tracks):\n # Initialize adjacency list to represent the railwa...
trial_gpt4o_3
{ "original_instruction": "", "prompt_id": "00049204", "row_id": 49204, "seed_ids": "[12018]" }
0.681496
Code_Contests_49204
I
[ "preprocess_tracks", "process_queries", "railway_system" ]
3
[ [ "railway_system", "preprocess_tracks" ], [ "railway_system", "process_queries" ] ]
2
[ "process_queries" ]
false
[]
false
pytest
true
[]
true
90ff0a1eb6b35b74896b4f36e98cb36bf6c99fca
0ae96be4507ca368c1ab4292c6a28b6ac86d30cf
v1.0
instruct
Code_Contests
Code_Contests_49223_I
Ariana is learning about binary trees in her computer science class. Given a binary tree, she needs to find the sum of all left leaves. A leaf is a node with no children. A left leaf is a leaf node that is the left child of its parent. Please help Ariana by writing a function `sumOfLeftLeaves(root)`, where `root` is ...
class TreeNode: def __init__(self, val=0, left=None, right=None): self.val = val self.left = left self.right = right def is_leaf(node: TreeNode) -> bool: return node is not None and node.left is None and node.right is None def sumOfLeftLeaves(root: TreeNode) -> int: if root is None...
from solution import TreeNode, sumOfLeftLeaves def test_example_tree(): # Tree: # 3 # / \ # 9 20 # / \ # 15 7 root = TreeNode(3) root.left = TreeNode(9) root.right = TreeNode(20) root.right.left = TreeNode(15) root.right.right = TreeNode(7) asser...
[]
[ 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": "class TreeNode:\n def __init__(self, val=0, left=None, right=None):\n self.val = val\n self.left = left\n self.right = right\n\ndef...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00049223", "row_id": 49223, "seed_ids": "[6005]" }
0.636022
Code_Contests_49223
I
[ "is_leaf", "sumOfLeftLeaves" ]
2
[ [ "sumOfLeftLeaves", "is_leaf" ] ]
1
[]
false
[ "TreeNode" ]
true
pytest
true
[]
true
0921fa748a27e46f7b972f1bef0ae25457688746
0f4b5453af401b306efb4decee2cf794f7046b7d
v1.0
instruct
Code_Contests
Code_Contests_49227_I
Wall-E loves exploring the world of strings and one day he stumbled upon a special problem. He came across a compressed way of representing string sequences using counts of each character. For example, a string "aabbcc" can be represented as {(a, 2), (b, 2), (c, 2)}. Wall-E wants to generate strings of certain lengths ...
from math import factorial MOD = 10**9 + 7 def count_valid_strings(n, k, char_counts): """ Calculate the number of valid permutations of a string with given character counts. """ # calculate numerator: n! numerator = factorial(n) % MOD # calculate denominator: product of factorials of counts ...
from solution import process_input_and_calculate def test_example_1(): n, k = 6, 3 char_data = [('a', 2), ('b', 2), ('c', 2)] assert process_input_and_calculate(n, k, char_data) == 90 def test_example_2(): n, k = 4, 2 char_data = [('x', 2), ('y', 2)] assert process_input_and_calculate(n, k, ch...
[ { "docstring": "Calculate the number of valid permutations of a string with given character counts.", "function_declaration": "def count_valid_strings(n, k, char_counts):", "function_name": "count_valid_strings", "parameter_list": "(n, k, char_counts)" }, { "docstring": "Process the input an...
[ 0, 1, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "import math\n\nMOD = 10**9 + 7\n\ndef count_valid_strings(n, k, char_counts):\n \"\"\"\n Returns the number of valid strings of length n with exactly...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00049227", "row_id": 49227, "seed_ids": "[8442]" }
0.731414
Code_Contests_49227
I
[ "count_valid_strings", "process_input_and_calculate" ]
2
[ [ "process_input_and_calculate", "count_valid_strings" ] ]
1
[]
false
[]
false
pytest
true
[]
true
f341e66ff6e3cd91baab563edfc39b321ef68680
99b431484ec33fb36378409c2f0861e9ceaa414b