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_12668_I | The library of a university stores numerous books and categorizes them based on different subjects. Each book belongs to only one subject from subject sets identified by integers from 1 to 5. Your task is to write a program that classifies a given book into one of the subject sets based on the words frequently appearin... | from collections import defaultdict, Counter
import os
def load_training_data():
training_data = defaultdict(list)
for i in range(1, 6):
directory = str(i)
for filename in os.listdir(directory):
filepath = os.path.join(directory, filename)
with open(filepath, 'r') as fil... | from solution import classify_books
import pytest
def mock_load_training_data():
return {
1: ["data mining techniques", "machine learning", "deep learning"],
2: ["modern physics for engineers", "quantum mechanics", "general relativity"],
3: ["ancient history of rome", "medieval europe", "re... | [
{
"docstring": null,
"function_declaration": "def load_training_data():",
"function_name": "load_training_data",
"parameter_list": "()"
},
{
"docstring": null,
"function_declaration": "def build_word_subject_map(training_data):",
"function_name": "build_word_subject_map",
"parame... | [
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 os\nimport zipfile\nfrom collections import Counter\nfrom pathlib import Path\n\ndef download_and_extract_zip(url, extract_to='.'):\n # Function ... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00012668",
"row_id": 12668,
"seed_ids": "[12321]"
} | 0.538609 | Code_Contests_12668 | I | [
"load_training_data",
"build_word_subject_map",
"predict_subject",
"classify_books"
] | 4 | [
[
"classify_books",
"build_word_subject_map"
],
[
"classify_books",
"load_training_data"
],
[
"classify_books",
"predict_subject"
]
] | 3 | [] | false | [] | false | pytest | true | [] | true | 0f890e60543652b752457acf2b3f9bca52c6f3c5 | a6e9a9108bc9abd2733d186dce028ca752e7f5fb | |||
v1.0 | instruct | Code_Contests | Code_Contests_12695_I | You are given an array of integers arr of length n.
Your task is to reorder the elements of the array such that for any two consecutive elements the greatest common divisor (GCD) is greater than 1. If it is possible to reorder the array to satisfy this condition, output "YES" and the reordered array. Otherwise, output... | import math
from itertools import permutations
def gcd(x, y):
return math.gcd(x, y)
def can_reorder(arr):
for perm in permutations(arr):
if all(gcd(perm[i], perm[i+1]) > 1 for i in range(len(perm) - 1)):
return "YES", perm
return "NO",
def reorder_arrays(test_cases):
results = []
... | from solution import can_reorder, reorder_arrays
def test_reorder_possible():
arr = [6, 10, 15]
result = can_reorder(arr)
assert result[0] == "YES"
assert all(math.gcd(result[1][i], result[1][i+1]) > 1 for i in range(len(result[1]) - 1))
def test_reorder_possible_another():
arr = [3, 9, 6, 12]
... | [
{
"docstring": null,
"function_declaration": "def gcd(x, y):",
"function_name": "gcd",
"parameter_list": "(x, y)"
},
{
"docstring": null,
"function_declaration": "def can_reorder(arr):",
"function_name": "can_reorder",
"parameter_list": "(arr)"
},
{
"docstring": null,
... | [
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": "import math\nfrom itertools import permutations\n\ndef can_be_reordered(arr):\n for perm in permutations(arr):\n if all(math.gcd(perm[i], perm[i ... | trial_gpt4o_6 | {
"original_instruction": "",
"prompt_id": "00012695",
"row_id": 12695,
"seed_ids": "[6070]"
} | 0.709473 | Code_Contests_12695 | I | [
"gcd",
"can_reorder",
"reorder_arrays",
"main"
] | 4 | [
[
"can_reorder",
"gcd"
],
[
"reorder_arrays",
"can_reorder"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 3737417245401ca3caea60ff24c9612623018802 | 945f59ed5870095a415bf0d1423ee7e27ccf3ab0 | |||
v1.0 | instruct | Code_Contests | Code_Contests_12732_I | Thomas loves climbing. He has found a sequence of steps and wants to figure out all the distinct ways to reach the top. The sequence of steps can be represented as an array where each element denotes the number of steps that can be climbed in one move (either 1 step or 2 steps only).
For example, if the sequence is [1... | def num_ways(n, steps):
"""
Returns the number of distinct ways to reach the top of n steps given the sequence of steps
that can be climbed in one move (either 1 step or 2 steps).
"""
# Handling edge cases where n is 0
if n == 0:
return 1
# Initialize dp array where dp[i] means the ... | from solution import distinct_ways_to_reach_top
def test_example_1():
assert distinct_ways_to_reach_top(3, [1, 2, 1]) == 3
def test_example_2():
assert distinct_ways_to_reach_top(2, [1, 2]) == 2
def test_single_step():
assert distinct_ways_to_reach_top(1, [1]) == 1
def test_two_single_steps():
asser... | [
{
"docstring": "Returns the number of distinct ways to reach the top of n steps given the sequence of steps\nthat can be climbed in one move (either 1 step or 2 steps).",
"function_declaration": "def num_ways(n, steps):",
"function_name": "num_ways",
"parameter_list": "(n, steps)"
},
{
"docs... | [
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 num_ways(n, steps):\n \"\"\"\n Returns the number of distinct ways to reach the top of n steps given the sequence of steps\n that can be climb... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00012732",
"row_id": 12732,
"seed_ids": "[11813]"
} | 0.678566 | Code_Contests_12732 | I | [
"num_ways",
"distinct_ways_to_reach_top"
] | 2 | [
[
"distinct_ways_to_reach_top",
"num_ways"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | ad13f3826144924921aaeb40365cd4bda1b397ea | 8e6b40da70e39dedce621c678edd1f42f3f537ec | |||
v1.0 | instruct | Code_Contests | Code_Contests_12738_I | You are given a maze represented by a 2D array of size n x m consisting of '.' and '#' characters. Here '.' represents an empty cell and '#' represents a wall. You start at the top-left corner of the maze (0,0) and need to reach the bottom-right corner (n-1,m-1). You can move up, down, left, or right, but you cannot pa... | from collections import deque
def shortest_path_in_maze(n, m, maze):
"""
Returns the length of the shortest path from the top-left corner to the bottom-right corner of the maze.
If no such path exists, return -1.
"""
def is_valid(x, y):
return 0 <= x < n and 0 <= y < m and maze[x][y] == '.... | from solution import solve_maze_problem
def test_example_1():
input_data = """5 5
. . . . #
# # . # #
. . . . .
. # # # .
. . . . ."""
result = solve_maze_problem(input_data)
assert result == 9
def test_example_2():
input_data = """4 4
. . # .
# . # .
# . # #
. . . ."""
result = solve_maze_problem... | [
{
"docstring": "Returns the length of the shortest path from the top-left corner to the bottom-right corner of the maze.\nIf no such path exists, return -1.",
"function_declaration": "def shortest_path_in_maze(n, m, maze):",
"function_name": "shortest_path_in_maze",
"parameter_list": "(n, m, maze)"
... | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from collections import deque\n\ndef shortest_path(maze, n, m):\n if maze[0][0] == '#' or maze[n-1][m-1] == '#':\n return -1\n \n direction... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00012738",
"row_id": 12738,
"seed_ids": "[1424]"
} | 0.693698 | Code_Contests_12738 | I | [
"shortest_path_in_maze",
"parse_input",
"solve_maze_problem"
] | 3 | [
[
"solve_maze_problem",
"parse_input"
],
[
"solve_maze_problem",
"shortest_path_in_maze"
]
] | 2 | [
"parse_input"
] | false | [] | false | pytest | true | [] | true | 13383acc55431909ac0f47f23546482ecc3ee0a6 | 5673f2f2898ca0389b7878a339a6dee2d5a79959 | |||
v1.0 | instruct | Code_Contests | Code_Contests_12804_I | ```markdown
Fibonacci Subsequence Sum
Given a sequence of integers, determine the sum of the largest subsequence that is a Fibonacci subsequence. A Fibonacci subsequence is defined as a subset of elements from the given sequence that follows the property of the Fibonacci sequence: every number in the subset (after the... | def is_fibonacci(num, fib_set):
"""
Check if a number is in the Fibonacci sequence using a set of precomputed Fibonacci numbers.
"""
return num in fib_set
def generate_fib_up_to_max(max_value):
"""
Generate all Fibonacci numbers up to max_value.
"""
fib_set = set()
a, b = 0, 1
w... | from solution import sum_largest_fib_subsequence
def test_example_case():
sequence = [1, 4, 3, 9, 7, 1, 2, 5]
assert sum_largest_fib_subsequence(sequence) == 12
def test_no_fib_numbers():
sequence = [4, 9, 20, 15]
assert sum_largest_fib_subsequence(sequence) == 0
def test_single_fib_number():
... | [
{
"docstring": "Check if a number is in the Fibonacci sequence using a set of precomputed Fibonacci numbers.",
"function_declaration": "def is_fibonacci(num, fib_set):",
"function_name": "is_fibonacci",
"parameter_list": "(num, fib_set)"
},
{
"docstring": "Generate all Fibonacci numbers up t... | [
0,
0,
0,
0,
0,
1,
0,
0,
1,
0
] | 2 | hard | 0.2 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def fibonacci_subsequence_sum(n, sequence):\n \"\"\"\n Returns the sum of the largest subsequence that is a Fibonacci subsequence in the given sequen... | trial_gpt4o_5 | {
"original_instruction": "",
"prompt_id": "00012804",
"row_id": 12804,
"seed_ids": "[10716]"
} | 0.662169 | Code_Contests_12804 | I | [
"is_fibonacci",
"generate_fib_up_to_max",
"sum_largest_fib_subsequence"
] | 3 | [
[
"sum_largest_fib_subsequence",
"generate_fib_up_to_max"
],
[
"sum_largest_fib_subsequence",
"is_fibonacci"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 922fe615f717dae2d9fb5ce01f837879e45b84f1 | e5cd62d1b813d40fba76dcd563e7256783c9c062 | |||
v1.0 | instruct | Code_Contests | Code_Contests_12829_I | ***Question:***
You are given a file system with a hierarchical directory structure. Each directory may contain files or subdirectories. Each file is denoted by a pair of integers `[x, y]`, where `x` is the size of the file in megabytes and `y` is the time taken to transfer the file in seconds. The directory structure... | def parse_input(input_string):
lines = input_string.strip().split("\n")
index = 0
T = int(lines[index])
index += 1
directories = []
while index < len(lines):
directory_name = lines[index]
index += 1
n = int(lines[index])
index += 1
files = []
for... | from solution import minimum_transfer_times
def test_single_directory():
input_data = "1\nMainDirectory\n2\n100 10\n200 20\n0\n"
assert minimum_transfer_times(input_data) == [30]
def test_multiple_directories_no_subdirectories():
input_data = "2\nMainDirectory\n1\n150 15\n0\nAnotherDirectory\n2\n100 10\n2... | [
{
"docstring": null,
"function_declaration": "def parse_input(input_string):",
"function_name": "parse_input",
"parameter_list": "(input_string)"
},
{
"docstring": null,
"function_declaration": "def calculate_transfer_time(directory, directories_dict):",
"function_name": "calculate_t... | [
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 Directory:\n def __init__(self, name):\n self.name = name\n self.files = []\n self.subdirectories = []\n\n def add_file(se... | trial_gpt4o_4 | {
"original_instruction": "",
"prompt_id": "00012829",
"row_id": 12829,
"seed_ids": "[3634]"
} | 0.521267 | Code_Contests_12829 | I | [
"parse_input",
"calculate_transfer_time",
"minimum_transfer_times"
] | 3 | [
[
"minimum_transfer_times",
"calculate_transfer_time"
],
[
"minimum_transfer_times",
"parse_input"
]
] | 2 | [
"parse_input"
] | false | [] | false | pytest | true | [] | true | 790c6a1e8ec10dd181414c06fb8f70ab29d6c1c1 | e3e0f887be3b5dc3cf5027c0323ae605f0edcc3b | |||
v1.0 | instruct | Code_Contests | Code_Contests_12877_I | Given an array of integers nums, return the length of the longest strictly decreasing subsequence (LDS) in nums.
A strictly decreasing subsequence is defined as a subsequence where for all i < j, nums[i] > nums[j].
Constraints
* 1 ≤ nums.length ≤ 100000
* -109 ≤ nums[i] ≤ 109
Input
First line: An integer n denotin... | def length_of_lds(nums):
"""
Returns the length of the longest strictly decreasing subsequence (LDS) in nums.
"""
if not nums:
return 0
n = len(nums)
dp = [1] * n # Initialize dp array where dp[i] is the length of LDS ending at index i
for i in range(1, n):
for j in range... | from solution import length_of_lds
def test_length_of_lds():
assert length_of_lds([9, 4, 3, 8, 6, 7]) == 3
assert length_of_lds([10, 20, 30, 0]) == 2
assert length_of_lds([5, 3, 4, 8, 6, 7]) == 2
assert length_of_lds([1, 2, 3, 4, 5]) == 1
assert length_of_lds([5, 4, 3, 2, 1]) == 5
assert length... | [
{
"docstring": "Returns the length of the longest strictly decreasing subsequence (LDS) in nums.",
"function_declaration": "def length_of_lds(nums):",
"function_name": "length_of_lds",
"parameter_list": "(nums)"
},
{
"docstring": null,
"function_declaration": "def process_input_and_find_... | [
1,
0,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def length_of_lds(nums):\n \"\"\"\n Returns the length of the longest strictly decreasing subsequence (LDS) in nums.\n \"\"\"\n\n if not nums:\... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00012877",
"row_id": 12877,
"seed_ids": "[1041]"
} | 0.83834 | Code_Contests_12877 | I | [
"length_of_lds",
"process_input_and_find_lds"
] | 2 | [
[
"process_input_and_find_lds",
"length_of_lds"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 3c08d108759060fb9419a5c344dd7953c3b27fa5 | bd4f98b70552822e4d254aacd22a2d1ef5b19c9c | |||
v1.0 | instruct | Code_Contests | Code_Contests_12883_I | In a gaming tournament, n participants compete in a single-elimination format (i.e., if you lose once, you are out). Each match results in either win or loss, and there is no draw. Given n participants, the tournament proceeds in rounds until one champion is determined.
However, during some of the tournaments, certai... | import math
def min_byes_required(n):
"""
Returns the minimum number of byes required to proceed in a single-elimination tournament
with n participants.
"""
# Calculate the next power of 2 greater than or equal to n
if n & (n - 1) == 0:
# n is already a power of 2
return 0
n... | from solution import min_byes_required, process_tournaments
def test_min_byes_required():
assert min_byes_required(5) == 3
assert min_byes_required(8) == 0
assert min_byes_required(13) == 3
assert min_byes_required(1) == 0
assert min_byes_required(31) == 1
assert min_byes_required(32) == 0
... | [
{
"docstring": "Returns the minimum number of byes required to proceed in a single-elimination tournament\nwith n participants.",
"function_declaration": "def min_byes_required(n):",
"function_name": "min_byes_required",
"parameter_list": "(n)"
},
{
"docstring": null,
"function_declarati... | [
1,
0,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import math\n\ndef min_byes_required(n):\n \"\"\"\n Returns the minimum number of byes required to proceed in a single-elimination tournament\n wi... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00012883",
"row_id": 12883,
"seed_ids": "[4316]"
} | 0.655356 | Code_Contests_12883 | I | [
"min_byes_required",
"process_tournaments"
] | 2 | [
[
"process_tournaments",
"min_byes_required"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 628dacba7c2c1771553c65ccc63e78062cb6c4e1 | e517902cbb27783fcb013dff87d7995df126a038 | |||
v1.0 | instruct | Code_Contests | Code_Contests_12893_I | Lara is very concerned about her Computer Science assignment that requires her to understand the concepts of arrays and matrix manipulation. She needs your help with solving a specific problem in her assignment.
You are given an MxN matrix and you need to find the sum of all elements in the matrix that are greater tha... | def sum_elements_greater_than_k(matrix, k):
"""
Returns the sum of all elements in the matrix that are greater than k.
"""
total_sum = 0
for row in matrix:
for element in row:
if element > k:
total_sum += element
return total_sum
def create_matrix_and_calcula... | from solution import create_matrix_and_calculate_sum
def test_example_case():
m = 3
n = 3
matrix_elements = [1, 2, 3, 4, 5, 6, 7, 8, 9]
k = 5
assert create_matrix_and_calculate_sum(m, n, matrix_elements, k) == 30
def test_all_elements_less_than_k():
m = 2
n = 2
matrix_elements = [1, 2,... | [
{
"docstring": "Returns the sum of all elements in the matrix that are greater than k.",
"function_declaration": "def sum_elements_greater_than_k(matrix, k):",
"function_name": "sum_elements_greater_than_k",
"parameter_list": "(matrix, k)"
},
{
"docstring": "Wrapper function to create a matr... | [
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 sum_elements_greater_than_k(matrix, k):\n \"\"\"\n Returns the sum of all elements in the matrix that are greater than k.\n \"\"\"\n total_... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00012893",
"row_id": 12893,
"seed_ids": "[2574]"
} | 0.609052 | Code_Contests_12893 | I | [
"sum_elements_greater_than_k",
"create_matrix_and_calculate_sum"
] | 2 | [
[
"create_matrix_and_calculate_sum",
"sum_elements_greater_than_k"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | ed2966b7d27182a425a845adfcce9f3758f4ddfb | d1e2e0fd5c69e26d8d45445cd54ae31cd0bb6b1b | |||
v1.0 | instruct | Code_Contests | Code_Contests_12966_I | Alice loves palindromes and numbers. She defines a "palindromic range" to be a range [L, R] of integers such that the number of palindromic numbers in the range is greater than or equal to P. She wants to check if a given range is a palindromic range or not.
A number is said to be palindromic if it reads the same back... | def is_palindromic_number(num):
return str(num) == str(num)[::-1]
def count_palindromic_numbers(L, R):
count = 0
for num in range(L, R + 1):
if is_palindromic_number(num):
count += 1
return count
def palindromic_range(queries):
results = []
for L, R, P in queries:
i... | from solution import palindromic_range, is_palindromic_number, count_palindromic_numbers
def test_is_palindromic_number():
assert is_palindromic_number(121) == True
assert is_palindromic_number(123) == False
assert is_palindromic_number(1221) == True
assert is_palindromic_number(10) == False
def test_... | [
{
"docstring": null,
"function_declaration": "def is_palindromic_number(num):",
"function_name": "is_palindromic_number",
"parameter_list": "(num)"
},
{
"docstring": null,
"function_declaration": "def count_palindromic_numbers(L, R):",
"function_name": "count_palindromic_numbers",
... | [
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_palindromic_number(num):\n return str(num) == str(num)[::-1]\n\ndef count_palindromic_numbers(L, R):\n count = 0\n for num in range(L, R + ... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00012966",
"row_id": 12966,
"seed_ids": "[12454]"
} | 0.720742 | Code_Contests_12966 | I | [
"is_palindromic_number",
"count_palindromic_numbers",
"palindromic_range"
] | 3 | [
[
"count_palindromic_numbers",
"is_palindromic_number"
],
[
"palindromic_range",
"count_palindromic_numbers"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | cd9e4933d3b8569117364a15e57d01c2f7df5cc5 | 2844e89e0580ffb9530e33c3101dc1780418e112 | |||
v1.0 | instruct | Code_Contests | Code_Contests_12971_I | Morty has recently started learning about prime numbers and their properties. To test his understanding, Rick gives him a challenge. Morty has to find the sum of all prime numbers up to a given positive integer N.
The problem: Given a positive integer N, find the sum of all prime numbers less than or equal to N.
INPU... | def sieve_of_eratosthenes(n):
"""
Returns a list of primes <= n using the Sieve of Eratosthenes algorithm.
"""
is_prime = [True] * (n + 1)
p = 2
while p * p <= n:
if is_prime[p]:
for i in range(p * p, n + 1, p):
is_prime[i] = False
p += 1
prime_num... | from solution import solve_primes_sums
def test_single_test_case():
assert solve_primes_sums([10]) == [17]
def test_multiple_test_cases():
assert solve_primes_sums([10, 100]) == [17, 1060]
def test_edge_case_1():
assert solve_primes_sums([1]) == [0]
def test_edge_case_2():
assert solve_primes_sums([... | [
{
"docstring": "Returns a list of primes <= n using the Sieve of Eratosthenes algorithm.",
"function_declaration": "def sieve_of_eratosthenes(n):",
"function_name": "sieve_of_eratosthenes",
"parameter_list": "(n)"
},
{
"docstring": "Returns the sum of all prime numbers less than or equal to ... | [
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 sum_primes_up_to(n):\n if n < 2:\n return 0\n\n sieve = [True] * (n + 1)\n sieve[0] = sieve[1] = False # 0 and 1 are not prime numbers... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00012971",
"row_id": 12971,
"seed_ids": "[1325]"
} | 0.562569 | Code_Contests_12971 | I | [
"sieve_of_eratosthenes",
"sum_of_primes_up_to_n",
"solve_primes_sums"
] | 3 | [
[
"solve_primes_sums",
"sum_of_primes_up_to_n"
],
[
"sum_of_primes_up_to_n",
"sieve_of_eratosthenes"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | c6dcfbc4f28801fb959a056574c379819ca7081c | da58226176fb3a8303f25ea0192ba2abf3fc2453 | |||
v1.0 | instruct | Code_Contests | Code_Contests_12999_I | Alice is participating in a programming competition where she needs to solve a grid-related problem. She has a grid of size n x m containing non-negative integers. Each cell (i, j) of the grid has a value grid[i][j]. Alice needs to find the maximum sum she can obtain by starting from the top-left cell (0, 0) and moving... | def max_sum_path(grid, n, m):
"""
Return the maximum sum path in a grid from the top-left to the bottom-right corner,
moving only right or down.
Parameters:
grid (list of list of int): The grid representation.
n (int): The number of rows in the grid.
m (int): The number of columns in th... | def test_max_sum_path():
grid = [
[1, 2, 3],
[4, 5, 6],
[7, 8, 9],
]
assert max_sum_path(grid, 3, 3) == 29
def test_max_sum_path_single_cell():
grid = [
[5]
]
assert max_sum_path(grid, 1, 1) == 5
def test_max_sum_path_single_row():
grid = [
[1, 2, 3,... | [
{
"docstring": "Return the maximum sum path in a grid from the top-left to the bottom-right corner,\nmoving only right or down.\n\nParameters:\ngrid (list of list of int): The grid representation.\nn (int): The number of rows in the grid.\nm (int): The number of columns in the grid.\n\nReturns:\nint: The maximu... | [
1,
0,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def max_sum_path(grid, n, m):\n \"\"\"\n Return the maximum sum path in a grid from the top-left to the bottom-right corner,\n moving only right o... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00012999",
"row_id": 12999,
"seed_ids": "[8803]"
} | 0.708194 | Code_Contests_12999 | I | [
"max_sum_path",
"solve"
] | 2 | [
[
"solve",
"max_sum_path"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | 820696efa2cb174d8f58111eed0de70351e6ea0d | 15540fea54485181db6706dd3b60fe53bc651561 | |||
v1.0 | instruct | Code_Contests | Code_Contests_13013_I | This is an algorithm implementation problem where you are given a binary tree and you need to find the maximum sum path from the root node down to any leaf node.
### Problem Statement:
Given a binary tree, where each node contains an integer value, find the maximum sum of the numbers along a path from the root node to... | class TreeNode:
def __init__(self, value, left=None, right=None):
self.value = value
self.left = left
self.right = right
def build_tree(node_list):
if not node_list:
return None
nodes = [None if val == -1 else TreeNode(val) for val, _, _ in node_list]
for idx, (val, left... | from solution import find_max_sum_path
def test_example_case_1():
node_data = [
(10, 1, 2),
(-2, 3, 4),
(-3, -1, -1),
(7, -1, -1),
(2, -1, -1)
]
assert find_max_sum_path(node_data) == 15
def test_single_node():
node_data = [
(5, -1, -1)
]
assert ... | [] | [
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": "00013013",
"row_id": 13013,
"seed_ids": "[9345]"
} | 0.673926 | Code_Contests_13013 | I | [
"build_tree",
"max_sum_path_from_root_to_leaf",
"find_max_sum_path"
] | 3 | [
[
"find_max_sum_path",
"build_tree"
],
[
"find_max_sum_path",
"max_sum_path_from_root_to_leaf"
]
] | 2 | [] | false | [
"TreeNode"
] | true | pytest | true | [] | true | 57c1ce33a86da25f9af23165df9fb0f0a206b310 | 3ff9e17452bccb08de2b7cb1594f1b92ee0c733c | |||
v1.0 | instruct | Code_Contests | Code_Contests_13022_I | A warehouse management system needs to optimize the routes of robots picking up inventory. The warehouse is organized in a grid of cells, where each cell may or may not contain obstacles. Each robot can only move up, down, left, or right, and cannot move diagonally or through obstacles. The goal is to find the shortest... | from collections import deque
def is_valid(cell, grid, rows, cols, visited):
x, y = cell
return 0 <= x < rows and 0 <= y < cols and grid[x][y] == 0 and not visited[x][y]
def bfs_shortest_path(grid, start, end):
rows, cols = len(grid), len(grid[0])
queue = deque([(start, 0)])
visited = [[False]*col... | import pytest
from solution import bfs_shortest_path, is_valid
def test_bfs_shortest_path_no_obstacles():
grid = [
[0, 0, 0],
[0, 0, 0],
[0, 0, 0]
]
assert bfs_shortest_path(grid, (0, 0), (2, 2)) == 4
def test_bfs_shortest_path_with_obstacles():
grid = [
[0, 1, 0],
... | [
{
"docstring": null,
"function_declaration": "def is_valid(cell, grid, rows, cols, visited):",
"function_name": "is_valid",
"parameter_list": "(cell, grid, rows, cols, visited)"
},
{
"docstring": null,
"function_declaration": "def bfs_shortest_path(grid, start, end):",
"function_name... | [
0,
0,
0,
0,
0,
1,
0,
0,
0
] | 1 | hard | 0.111 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from collections import deque\n\ndef shortest_path(m, n, start, end, obstacles):\n \"\"\"\n Returns the shortest path in a grid from start to end, av... | trial_gpt4o_5 | {
"original_instruction": "",
"prompt_id": "00013022",
"row_id": 13022,
"seed_ids": "[4153]"
} | 0.674133 | Code_Contests_13022 | I | [
"is_valid",
"bfs_shortest_path",
"process_test_cases"
] | 3 | [
[
"bfs_shortest_path",
"is_valid"
],
[
"process_test_cases",
"bfs_shortest_path"
]
] | 2 | [
"process_test_cases"
] | false | [] | false | pytest | true | [] | true | ba9f2bea169cabd406ba7fd2cd591dc92fffa3ff | 3b544ed762644ae3934f7cf610a9aab29be43c33 | |||
v1.0 | instruct | Code_Contests | Code_Contests_13038_I | Jon is passionate about gardening and decided to plant some flowers in his garden. He has several rows in his garden bed, and each row can be represented as a list of integers where each integer denotes the height of a plant. Jon wants to arrange the plants in each row such that the heights are in non-decreasing order ... | def merge_sort_and_count(arr):
"""
Helper function that uses merge sort and counts inversions.
Args:
arr (list): List of integers representing plant heights.
Returns:
tuple: A sorted list of integers and the count of adjacent swaps (inversions).
"""
if len(arr) <= 1:
re... | def test_minimum_adjacent_swaps():
assert minimum_adjacent_swaps([[3, 1, 2]]) == [2]
assert minimum_adjacent_swaps([[4, 5, 6]]) == [0]
assert minimum_adjacent_swaps([[1, 5, 3, 4]]) == [2]
assert minimum_adjacent_swaps([[1, 2, 3, 4, 5]]) == [0]
assert minimum_adjacent_swaps([[5, 4, 3, 2, 1]]) == [10]... | [
{
"docstring": "Helper function that uses merge sort and counts inversions.\n\nArgs:\narr (list): List of integers representing plant heights.\n\nReturns:\ntuple: A sorted list of integers and the count of adjacent swaps (inversions).",
"function_declaration": "def merge_sort_and_count(arr):",
"function... | [
0,
0,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def count_swaps_to_sort(arr):\n \"\"\"\n Returns the minimum number of adjacent swaps required to sort the array.\n \"\"\"\n n = len(arr)\n ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00013038",
"row_id": 13038,
"seed_ids": "[13188]"
} | 0.634432 | Code_Contests_13038 | I | [
"merge_sort_and_count",
"merge_and_count",
"minimum_adjacent_swaps"
] | 3 | [
[
"merge_sort_and_count",
"merge_and_count"
],
[
"minimum_adjacent_swaps",
"merge_sort_and_count"
]
] | 2 | [] | false | [] | false | pytest | false | [] | true | 66946b5f1ca26ffeb38d5cb2871d444020d23d07 | 31620f8ac0572a4ab832ef63f1b3041ded049b6b | |||
v1.0 | instruct | Code_Contests | Code_Contests_13072_I | A food delivery service operates in a city with n neighborhoods, connected by m two-way roads. Each road connects two neighborhoods and has a certain distance d. The delivery service wants to ensure that they can deliver food from their central kitchen located in neighborhood 1 to all other neighborhoods as efficiently... | import heapq
def dijkstra(n, roads):
graph = [[] for _ in range(n + 1)]
for u, v, d in roads:
graph[u].append((v, d))
graph[v].append((u, d))
distances = [float('inf')] * (n + 1)
distances[1] = 0
pq = [(0, 1)] # (distance, node)
while pq:
current_distance, u =... | from solution import calculate_min_distances
def test_example1():
n, m = 4, 4
roads = [
(1, 2, 4),
(1, 3, 2),
(2, 3, 5),
(2, 4, 10)
]
assert calculate_min_distances(n, m, roads) == [4, 2, 14]
def test_example2():
n, m = 5, 6
roads = [
(1, 2, 2),
... | [
{
"docstring": null,
"function_declaration": "def dijkstra(n, roads):",
"function_name": "dijkstra",
"parameter_list": "(n, roads)"
},
{
"docstring": null,
"function_declaration": "def calculate_min_distances(n, m, roads):",
"function_name": "calculate_min_distances",
"parameter_... | [
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": "import heapq\n\ndef calculate_min_distances(n, m, roads):\n \"\"\"\n Calculate minimum distances from the central kitchen (neighborhood 1) to all oth... | trial_gpt4o_4 | {
"original_instruction": "",
"prompt_id": "00013072",
"row_id": 13072,
"seed_ids": "[9490]"
} | 0.783122 | Code_Contests_13072 | I | [
"dijkstra",
"calculate_min_distances"
] | 2 | [
[
"calculate_min_distances",
"dijkstra"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 9df1217a6fd5c28c5eb5dd455bed8654d1eb1547 | a10c9884ca984d18d7884705ed52142bbb5167af | |||
v1.0 | instruct | Code_Contests | Code_Contests_13075_I | Sam is a software engineer working on a drone delivery system. The goal of the system is to ensure that drones take the most efficient path between multiple delivery points. Each delivery point can be represented as a node, and the connections (paths) between them are the edges of a graph. Each edge has an associated c... | from itertools import permutations
def tsp(adj_matrix):
n = len(adj_matrix)
nodes = list(range(n))
min_cost = float('inf')
# Create all permutations of nodes except the starting node 0
for perm in permutations(nodes[1:]):
current_cost = adj_matrix[0][perm[0]]
for i in range(len... | from solution import tsp, parse_input, solve_tsp
def test_tsp():
adj_matrix_1 = [
[0, 10, 15, 20],
[10, 0, 35, 25],
[15, 35, 0, 30],
[20, 25, 30, 0]
]
assert tsp(adj_matrix_1) == 80
adj_matrix_2 = [
[0, 29, 20],
[29, 0, 15],
[20, 15, 0]
]... | [
{
"docstring": null,
"function_declaration": "def tsp(adj_matrix):",
"function_name": "tsp",
"parameter_list": "(adj_matrix)"
},
{
"docstring": null,
"function_declaration": "def solve_tsp(problems):",
"function_name": "solve_tsp",
"parameter_list": "(problems)"
},
{
"doc... | [
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 itertools import permutations\n\ndef tsp(adj_matrix):\n n = len(adj_matrix)\n nodes = list(range(n))\n min_cost = fl... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00013075",
"row_id": 13075,
"seed_ids": "[6442]"
} | 0.680961 | Code_Contests_13075 | I | [
"tsp",
"solve_tsp",
"parse_input",
"main"
] | 4 | [
[
"solve_tsp",
"tsp"
]
] | 1 | [
"parse_input"
] | false | [] | false | pytest | true | [] | true | cb6330c834f57d82e24f044dec21e055f68cae5f | b6425c6187076636316693b81004d3513b60c846 | |||
v1.0 | instruct | Code_Contests | Code_Contests_13086_I | A city named Metroville has been expanding its subway network. The city has a series of subway stations connected by bi-directional lines. Each subway station has a unique identifier, and each line connecting two stations has an associated travel time. Commuters want to find the shortest travel time between any two giv... | def floyd_warshall(n, edges):
# Initialize the distance matrix
inf = float('inf')
dist = [[inf] * n for _ in range(n)]
# Distance to itself is 0
for i in range(n):
dist[i][i] = 0
# Initialize distances based on direct edges
for u, v, t in edges:
dist[u-1][v-1] = t
... | def test_shortest_travel_times():
n = 4
m = 4
subway_lines = [
(1, 2, 5),
(2, 3, 10),
(3, 4, 3),
(1, 4, 20)
]
q = 3
queries = [
(1, 3),
(1, 4),
(2, 4)
]
expected_results = [15, 18, 13]
assert shortest_travel_times(n, m, subway_l... | [
{
"docstring": null,
"function_declaration": "def floyd_warshall(n, edges):",
"function_name": "floyd_warshall",
"parameter_list": "(n, edges)"
},
{
"docstring": null,
"function_declaration": "def shortest_travel_times(n, m, subway_lines, q, queries):",
"function_name": "shortest_tra... | [
0,
1
] | 1 | medium | 0.5 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import heapq\n\ndef dijkstra(graph, start, n):\n \"\"\"\n Helper function to perform Dijkstra's algorithm for shortest paths.\n :param graph: adja... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00013086",
"row_id": 13086,
"seed_ids": "[7770]"
} | 0.765047 | Code_Contests_13086 | I | [
"floyd_warshall",
"shortest_travel_times"
] | 2 | [
[
"shortest_travel_times",
"floyd_warshall"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | 9b14528f5be06810927fb4325e3c9d9937a726af | 824c229ebef0de603238e14dfd0f85ab2dd35696 | |||
v1.0 | instruct | Code_Contests | Code_Contests_13087_I | A self-driving car company needs to ensure that all its cars use unique serial numbers that can be checked efficiently. Each serial number is a string consisting of both letters and numbers and follows these rules:
1. The serial number must contain both letters and digits.
2. The letters in the serial number are case-s... | def is_valid_serial(serial):
"""
Returns True if the serial number contains both letters and digits, False otherwise.
"""
has_letter = any(char.isalpha() for char in serial)
has_digit = any(char.isdigit() for char in serial)
return has_letter and has_digit
def check_serial_number(N, issued_seri... | from solution import is_valid_serial, check_serial_number
def test_is_valid_serial():
assert is_valid_serial("A1b2") == True
assert is_valid_serial("abcd") == False
assert is_valid_serial("1234") == False
assert is_valid_serial("a1") == True
assert is_valid_serial("A1B2c3") == True
def test_check_... | [
{
"docstring": "Returns True if the serial number contains both letters and digits, False otherwise.",
"function_declaration": "def is_valid_serial(serial):",
"function_name": "is_valid_serial",
"parameter_list": "(serial)"
},
{
"docstring": "Checks if the given serial number is valid and un... | [
0,
0,
0,
1,
1
] | 2 | medium | 0.4 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_valid_serial(serial):\n \"\"\"\n Check if a serial number is valid. A valid serial number must contain both letters and digits.\n \"\"\"\n ... | trial_gpt4o_4 | {
"original_instruction": "",
"prompt_id": "00013087",
"row_id": 13087,
"seed_ids": "[9253]"
} | 0.577944 | Code_Contests_13087 | I | [
"is_valid_serial",
"check_serial_number"
] | 2 | [
[
"check_serial_number",
"is_valid_serial"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 138a273d5d129c2cd30dacb65b48d9635e4d41a0 | 670246ce76a70b8e34658bd35b959b5b738033b8 | |||
v1.0 | instruct | Code_Contests | Code_Contests_13136_I | You are tasked to write a program that helps analyze a simple language. The language consists of variables, basic arithmetic operations (addition, subtraction, multiplication, and division), and assignment statements. Each expression or statement in the language is provided on a single line and your program must evalua... | import re
def evaluate_expression(expression, variables):
try:
result = eval(expression, {}, variables)
return int(result)
except NameError:
return 'UNDEFINED'
except ZeroDivisionError:
return 'UNDEFINED'
def parse_and_evaluate(input_lines):
variables = {}
output = ... | import pytest
from solution import parse_and_evaluate
def test_example_case():
input_lines = [
"x 10",
"y 20",
"END OF INITIALIZATION",
"z = x + y",
"a = z * 2",
"a / 5",
"b = a - 30",
"c = (a - (b * 2))",
"w = (d + y)",
"END OF EXPRES... | [
{
"docstring": null,
"function_declaration": "def evaluate_expression(expression, variables):",
"function_name": "evaluate_expression",
"parameter_list": "(expression, variables)"
},
{
"docstring": null,
"function_declaration": "def parse_and_evaluate(input_lines):",
"function_name":... | [
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": "import re\n\ndef evaluate_expression(expression, variables):\n tokens = re.findall(r'\\d+|[a-zA-Z_]\\w*|[+*/()-]', expression)\n postfix = to_postfix... | trial_gpt4o_4 | {
"original_instruction": "",
"prompt_id": "00013136",
"row_id": 13136,
"seed_ids": "[6966]"
} | 0.546089 | Code_Contests_13136 | I | [
"evaluate_expression",
"parse_and_evaluate"
] | 2 | [
[
"parse_and_evaluate",
"evaluate_expression"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | d9b29ab60dc3754bffa45cdfdbc5ef0775211802 | 9fbdc7caabbc40fd0818e8a42f9cc4256633db9d | |||
v1.0 | instruct | Code_Contests | Code_Contests_13198_I | In a distant galaxy, there exists an intricate network of teleportation stations, each connected by one-way teleport routes. A rebel pilot, Zane, is trying to navigate from the Headquarters station (HQ) to the Secret Base (SB). However, the terrorists have intercepted the detailed map of the teleportation network, leav... | def check_valid_route(sequence):
"""
Function to check if the binary sequence forms a valid route from HQ to SB.
"""
# For simplicity, assume a valid route is one ending with a specific pattern
valid_routes = ["0110", "011011", "10011"] # Dummy example of valid routes
return "Yes" if sequence i... | from solution import check_valid_route, navigate_routes
def test_check_valid_route():
assert check_valid_route("0110") == "Yes"
assert check_valid_route("011011") == "Yes"
assert check_valid_route("10011") == "Yes"
assert check_valid_route("1101") == "No"
assert check_valid_route("1010") == "No"
d... | [
{
"docstring": "Function to check if the binary sequence forms a valid route from HQ to SB.",
"function_declaration": "def check_valid_route(sequence):",
"function_name": "check_valid_route",
"parameter_list": "(sequence)"
},
{
"docstring": null,
"function_declaration": "def navigate_rou... | [
0,
0,
0,
0,
1
] | 1 | hard | 0.2 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_valid_route(binary_sequence):\n \"\"\"\n Determines if the binary sequence is a valid route from HQ to SB.\n A route is valid if it starts ... | trial_gpt4o_4 | {
"original_instruction": "",
"prompt_id": "00013198",
"row_id": 13198,
"seed_ids": "[1551]"
} | 0.569659 | Code_Contests_13198 | I | [
"check_valid_route",
"navigate_routes"
] | 2 | [
[
"navigate_routes",
"check_valid_route"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | bd34cd38cc3183a2117173c2cf901e532d8b8cbc | d53c2068149fd5f3ee5bee8f108a56e3fa95f659 | |||
v1.0 | instruct | Code_Contests | Code_Contests_13239_I | You are given a graph with n nodes numbered 1 through n. The graph is represented as an adjacency matrix A where Ai, j = 1 if there is an edge between node i and node j, and Ai, j = 0 otherwise.
Your task is to determine if there is a Hamiltonian path in the graph. A Hamiltonian path is a path in an undirected graph t... | from itertools import permutations
def query_edge(graph, u, v):
return "Yes" if graph[u-1][v-1] == 1 else "No"
def find_hamiltonian_path(n, graph):
nodes = range(1, n + 1)
for perm in permutations(nodes):
is_path = True
for i in range(n - 1):
u, v = perm[i], perm[i+1]
... | def test_hamiltonian_path_yes_case():
n = 4
graph = [
[0, 1, 0, 0],
[1, 0, 1, 0],
[0, 1, 0, 1],
[0, 0, 1, 0]
]
assert find_hamiltonian_path(n, graph) == "Yes"
def test_hamiltonian_path_no_case():
n = 4
graph = [
[0, 1, 0, 0],
[1, 0, 0, 0],
... | [
{
"docstring": null,
"function_declaration": "def query_edge(graph, u, v):",
"function_name": "query_edge",
"parameter_list": "(graph, u, v)"
},
{
"docstring": null,
"function_declaration": "def find_hamiltonian_path(n, graph):",
"function_name": "find_hamiltonian_path",
"paramet... | [
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 itertools\n\ndef hamiltonian_path_exist(adj_matrix):\n n = len(adj_matrix)\n \n def has_edge(u, v):\n return adj_matrix[u-1][v-1] ==... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00013239",
"row_id": 13239,
"seed_ids": "[10366]"
} | 0.634711 | Code_Contests_13239 | I | [
"query_edge",
"find_hamiltonian_path"
] | 2 | [
[
"find_hamiltonian_path",
"query_edge"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | b4603ebe26b8017eb08662aed0b8c2273cb5f024 | f122421d3031c406291a99400084590dfee51f32 | |||
v1.0 | instruct | Code_Contests | Code_Contests_13348_I | Garden Watering System
You are tasked with designing an efficient watering system for a rectangular garden represented as an $N \times M$ grid where each cell in the grid contains a certain number of plants. You want to water all the plants in the garden, but you also aim to minimize the amount of water used.
The wat... | def preprocess_garden(garden):
N = len(garden)
M = len(garden[0])
prefix_sum = [[0] * (M + 1) for _ in range(N + 1)]
for i in range(1, N + 1):
for j in range(1, M + 1):
prefix_sum[i][j] = (garden[i-1][j-1]
+ prefix_sum[i-1][j]
... | from solution import garden_watering
def test_garden_watering_single_request():
N, M = 4, 4
garden = [
[1, 2, 3, 4],
[5, 6, 7, 8],
[9, 10, 11, 12],
[13, 14, 15, 16]
]
requests = [(1, 1, 2, 2)]
assert garden_watering(N, M, garden, requests) == [14]
def test_garden_wa... | [
{
"docstring": null,
"function_declaration": "def preprocess_garden(garden):",
"function_name": "preprocess_garden",
"parameter_list": "(garden)"
},
{
"docstring": null,
"function_declaration": "def water_amount(prefix_sum, r1, c1, r2, c2):",
"function_name": "water_amount",
"par... | [
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 preprocess_plants(garden, N, M):\n # Create a prefix sum matrix\n prefix_sum = [[0] * (M + 1) for _ in range(N + 1)]\n \n for i in range(1,... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00013348",
"row_id": 13348,
"seed_ids": "[11027]"
} | 0.631186 | Code_Contests_13348 | I | [
"preprocess_garden",
"water_amount",
"garden_watering"
] | 3 | [
[
"garden_watering",
"preprocess_garden"
],
[
"garden_watering",
"water_amount"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | d06745d3220e80ee37f7985d64c718924e485865 | afa3fe19ce2e5a5d71c17dbacc272d7e364d83d3 | |||
v1.0 | instruct | Code_Contests | Code_Contests_13375_I | Two friends, A and B, are exploring a magical forest where each tree has a distinct treasure at its root. A being a curious programmer decides to amuse B with a coding puzzle related to trees. A presents B with a binary tree and asks B to find out if there exists any pair of nodes in the tree whose sum equals a given i... | class TreeNode:
def __init__(self, value=0, left=None, right=None):
self.value = value
self.left = left
self.right = right
def build_tree(values):
if not values or values[0] == -1:
return None
root = TreeNode(values[0])
queue = [root]
i = 1
while i < len(values):... | from solution import is_pair_present_in_tree
def test_single_case_yes():
t = 1
data = [(5, [5, 3, 7, 2, -1, -1, 8])]
x = [10]
expected = ["Yes"]
assert is_pair_present_in_tree(t, data, x) == expected
def test_single_case_no():
t = 1
data = [(3, [1, 2, 3])]
x = [10]
expected = ["No"... | [] | [
0,
0,
0,
0,
0,
0,
1,
1,
1,
1
] | 4 | medium | 0.4 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "class TreeNode:\n def __init__(self, value=0, left=None, right=None):\n self.value = value\n self.left = left\n self.right = right\... | trial_gpt4o_9 | {
"original_instruction": "",
"prompt_id": "00013375",
"row_id": 13375,
"seed_ids": "[11427]"
} | 0.594895 | Code_Contests_13375 | I | [
"build_tree",
"find_pair_with_sum",
"is_pair_present_in_tree"
] | 3 | [
[
"is_pair_present_in_tree",
"build_tree"
],
[
"is_pair_present_in_tree",
"find_pair_with_sum"
]
] | 2 | [] | false | [
"TreeNode"
] | true | pytest | true | [] | true | aae99d33c974482099fdec69766f87e0e1c4368f | 1c3c754858633ed03567c26051cc3078f379a85f | |||
v1.0 | instruct | Code_Contests | Code_Contests_13392_I | In a distant galaxy, there is a peculiar alien species that communicates via a very unique number system. Each number they use is composed of digits 0 and 1, much like binary numbers. However, the aliens have a special rule: they consider the numbers to be beautiful if the number of '1's in it is a prime number.
Your ... | import math
def is_prime(n):
if n <= 1:
return False
if n <= 3:
return True
if n % 2 == 0 or n % 3 == 0:
return False
i = 5
while i * i <= n:
if n % i == 0 or n % (i + 2) == 0:
return False
i += 6
return True
def is_beautiful_number(binary_st... | from solution import is_beautiful_number
def test_is_beautiful_number():
assert is_beautiful_number("101011") == "NO"
assert is_beautiful_number("100000") == "NO"
assert is_beautiful_number("11100") == "YES"
assert is_beautiful_number("1") == "NO"
assert is_beautiful_number("1111") == "NO"
asse... | [
{
"docstring": null,
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": null,
"function_declaration": "def is_beautiful_number(binary_string):",
"function_name": "is_beautiful_number",
"parameter_list": "(binary_stri... | [
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 math\n\ndef is_prime(n):\n if n <= 1:\n return False\n if n <= 3:\n return True\n if n % 2 == 0 or n % 3 == 0:\n retur... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00013392",
"row_id": 13392,
"seed_ids": "[12557]"
} | 0.567599 | Code_Contests_13392 | I | [
"is_prime",
"is_beautiful_number"
] | 2 | [
[
"is_beautiful_number",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | e7240eb23134802e1c9e69a0c3a9551982e24e63 | bcc2a40f8df30db33b9c54c30b7f2002b17eaa18 | |||
v1.0 | instruct | Code_Contests | Code_Contests_13441_I | A secret agent needs to travel through a network of safe houses in different cities to deliver an important message. The network consists of `n` safe houses, where each pair of safe houses is connected by a two-way route that can be open or closed. The mission starts at the first safe house and the message needs to be ... | from collections import deque, defaultdict
def find_shortest_path(n, m, routes):
if n == 2 and m == 0:
return -1
graph = defaultdict(list)
for u, v in routes:
graph[u].append(v)
graph[v].append(u)
dist = [-1] * (n + 1)
visited = [False] * (n + 1)
dist[1... | def test_find_shortest_path():
assert deliver_message(6, 7, [(1, 2), (2, 3), (3, 4), (4, 5), (5, 6), (1, 3), (4, 6)]) == (3, [1, 3, 4, 6])
assert deliver_message(6, 2, [(1, 2), (5, 6)]) == -1
assert deliver_message(3, 1, [(1, 2)]) == -1
assert deliver_message(5, 4, [(1, 2), (2, 3), (3, 4), (4, 5)]) == (... | [
{
"docstring": null,
"function_declaration": "def find_shortest_path(n, m, routes):",
"function_name": "find_shortest_path",
"parameter_list": "(n, m, routes)"
},
{
"docstring": null,
"function_declaration": "def deliver_message(n, m, initial_open_routes):",
"function_name": "deliver... | [
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": "from collections import deque, defaultdict\n\ndef min_route_changes(n, m, routes):\n # Graph adjacency list\n graph = defaultdict(list)\n for u, v... | trial_gpt4o_8 | {
"original_instruction": "",
"prompt_id": "00013441",
"row_id": 13441,
"seed_ids": "[1421]"
} | 0.671961 | Code_Contests_13441 | I | [
"find_shortest_path",
"deliver_message"
] | 2 | [
[
"deliver_message",
"find_shortest_path"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | 874df13885b1fa7ebfb812460e34b27631e9b085 | aa375746da805d197bded6fa8a9042858307309e | |||
v1.0 | instruct | Code_Contests | Code_Contests_13501_I | Mayank the Architect is designing an archipelago of islands connected by bridges. The goal is to ensure that every island can be visited starting from any other island, by using one or more bridges. Each bridge connects exactly two islands and can be traversed in both directions.
Initially, there are no bridges built,... | def find(parent, i):
if parent[i] == i:
return i
else:
return find(parent, parent[i])
def union(parent, rank, x, y):
root_x = find(parent, x)
root_y = find(parent, y)
if root_x != root_y:
if rank[root_x] > rank[root_y]:
parent[root_y] = root_x
elif rank[r... | from solution import min_cost_to_connect_islands
def test_example():
assert min_cost_to_connect_islands(4, 5, [(1, 2, 1), (2, 3, 2), (3, 4, 3), (1, 3, 2), (2, 4, 3)]) == 6
def test_minimal_case():
assert min_cost_to_connect_islands(2, 1, [(1, 2, 1)]) == 1
def test_small_case():
assert min_cost_to_connect... | [
{
"docstring": null,
"function_declaration": "def find(parent, i):",
"function_name": "find",
"parameter_list": "(parent, i)"
},
{
"docstring": null,
"function_declaration": "def union(parent, rank, x, y):",
"function_name": "union",
"parameter_list": "(parent, rank, x, y)"
},
... | [
1,
1,
0
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def find_parent(parent, i):\n if parent[i] == i:\n return i\n else:\n return find_parent(parent, parent[i])\n\ndef union(parent, rank, ... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00013501",
"row_id": 13501,
"seed_ids": "[8905]"
} | 0.805907 | Code_Contests_13501 | I | [
"find",
"union",
"min_cost_to_connect_islands"
] | 3 | [
[
"min_cost_to_connect_islands",
"find"
],
[
"min_cost_to_connect_islands",
"union"
],
[
"union",
"find"
]
] | 3 | [] | false | [] | false | pytest | true | [] | true | 1c5dee667a2318928cbcfffd9be68214880617d9 | 2ad71e028028d4f06bb7381fc192e241a8ee9b65 | |||
v1.0 | instruct | Code_Contests | Code_Contests_13536_I | You are working on a project that requires parsing a log file to extract and format specific information. The log file contains entries with timestamps, log levels, and messages. The task is to format these entries into structured JSON objects based on a given set of filtering criteria.
Each log entry follows this for... | import json
from datetime import datetime
def parse_log_entry(entry):
"""
Parses a single log entry and returns a dictionary with timestamp, level, and message keys.
"""
time, level, message = entry.split('] ', 2)
timestamp = time.strip('[')
level = level.strip('[').strip(']')
return {
... | from solution import filter_logs
def test_info_level():
n = 3
min_level = "INFO"
logs = [
"[2023-01-01 08:00:00] [INFO] Info log entry",
"[2023-01-01 09:00:00] [WARN] Warning log entry",
"[2023-01-01 10:00:00] [ERROR] Error log entry"
]
expected_output = json.dumps([
... | [
{
"docstring": "Parses a single log entry and returns a dictionary with timestamp, level, and message keys.",
"function_declaration": "def parse_log_entry(entry):",
"function_name": "parse_log_entry",
"parameter_list": "(entry)"
},
{
"docstring": "Converts a log level to a number for easy co... | [
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 json\nfrom datetime import datetime\n\nLOG_LEVELS = {\"INFO\": 1, \"WARN\": 2, \"ERROR\": 3}\n\ndef parse_log_file(n, min_level, log_entries):\n ... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00013536",
"row_id": 13536,
"seed_ids": "[348]"
} | 0.609081 | Code_Contests_13536 | I | [
"parse_log_entry",
"log_level_to_number",
"filter_logs"
] | 3 | [
[
"filter_logs",
"log_level_to_number"
],
[
"filter_logs",
"parse_log_entry"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 4e7ba08849d16eb1cc1efd10734280a16a867f60 | 6127748920cf5f983dc692da20ee8ed7b2df8205 | |||
v1.0 | instruct | Code_Contests | Code_Contests_13550_I | You're given an array of integers of length n. Your task is to find the length of the longest subarray consisting of only prime numbers from the array. The subarray should be contiguous.
A prime number is a positive integer greater than 1, with no positive integer divisors other than 1 and itself.
Input
The first li... | def is_prime(num):
if num <= 1:
return False
if num == 2:
return True
if num % 2 == 0:
return False
for i in range(3, int(num**0.5) + 1, 2):
if num % i == 0:
return False
return True
def longest_prime_subarray_length(n, array):
longest_length = 0
... | from solution import is_prime, longest_prime_subarray_length
def test_is_prime():
assert is_prime(2) is True
assert is_prime(3) is True
assert is_prime(4) is False
assert is_prime(29) is True
assert is_prime(1) is False
assert is_prime(-7) is False
def test_longest_prime_subarray_length():
... | [
{
"docstring": null,
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": null,
"function_declaration": "def longest_prime_subarray_length(n, array):",
"function_name": "longest_prime_subarray_length",
"parameter_l... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import math\n\ndef is_prime(num):\n \"\"\"\n Helper function to check if a number is prime.\n \"\"\"\n if num <= 1:\n return False\n ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00013550",
"row_id": 13550,
"seed_ids": "[6919]"
} | 0.668535 | Code_Contests_13550 | I | [
"is_prime",
"longest_prime_subarray_length"
] | 2 | [
[
"longest_prime_subarray_length",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | a56ae7ffbdae87ef96a095707ff205b5135949ea | 439e4920532ab721b4b0060ad5c18472d4268ccd | |||
v1.0 | instruct | Code_Contests | Code_Contests_13578_I | In Byteland, a magical land of bytes and bits, a new type of tree called a "BitTree" is being studied. A BitTree is a binary tree that follows a particular set of rules with respect to the values of its nodes.
The properties of a BitTree are:
1. Each node has a distinct integer value.
2. For any given node with value ... | class TreeNode:
def __init__(self, value):
self.value = value
self.left = None
self.right = None
def insert(root, value):
if root is None:
return TreeNode(value)
if value < root.value:
root.left = insert(root.left, value)
else:
root.right = insert(root.ri... | from solution import find_levels
def test_find_levels_case1():
T = 2
test_cases = [
{"NQ": (5, 3), "values": [10, 5, 3, 7, 15]},
{"NQ": (3, 10), "values": [5, 15, 20]}
]
assert find_levels(T, test_cases) == [3, -1]
def test_find_levels_case2():
T = 1
test_cases = [
{"NQ... | [] | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "class TreeNode:\n def __init__(self, val):\n self.val = val\n self.left = None\n self.right = None\n\ndef insert(root, key):\n i... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00013578",
"row_id": 13578,
"seed_ids": "[1151]"
} | 0.620141 | Code_Contests_13578 | I | [
"insert",
"find_level",
"find_levels"
] | 3 | [
[
"find_levels",
"find_level"
],
[
"find_levels",
"insert"
]
] | 2 | [] | false | [
"TreeNode"
] | true | pytest | true | [] | true | 0676b7323e313b983464ff75abf448b38de98f4b | 4edcf9d844268af551f92c6bc866f237a432c2bf | |||
v1.0 | instruct | Code_Contests | Code_Contests_13596_I | A digital library system keeps records of books being borrowed. Each book is associated with a unique ID number, and for simplicity, the library has decided to categorize books by their ID number based on the sum of their digits.
Your task is to create a program that categorizes and lists IDs of books that have been ... | def sum_of_digits(n):
"""
Returns the sum of the digits of the given number n.
"""
return sum(int(digit) for digit in str(n))
def categorize_books_by_digit_sum(datasets):
"""
Categorizes book IDs by the sum of their digits.
Args:
datasets (list of list): A list where each element i... | from solution import sum_of_digits, categorize_books_by_digit_sum
def test_sum_of_digits():
assert sum_of_digits(123) == 6
assert sum_of_digits(456) == 15
assert sum_of_digits(789) == 24
assert sum_of_digits(101112) == 6
assert sum_of_digits(131415) == 15
assert sum_of_digits(111111) == 6
a... | [
{
"docstring": "Returns the sum of the digits of the given number n.",
"function_declaration": "def sum_of_digits(n):",
"function_name": "sum_of_digits",
"parameter_list": "(n)"
},
{
"docstring": "Categorizes book IDs by the sum of their digits.\n\nArgs:\ndatasets (list of list): A list wher... | [
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 sum_of_digits(n):\n return sum(int(digit) for digit in str(n))\n\ndef categorize_books_by_digit_sum(datasets):\n results = []\n for dataset in... | trial_gpt4o_6 | {
"original_instruction": "",
"prompt_id": "00013596",
"row_id": 13596,
"seed_ids": "[11752]"
} | 0.622959 | Code_Contests_13596 | I | [
"sum_of_digits",
"categorize_books_by_digit_sum"
] | 2 | [
[
"categorize_books_by_digit_sum",
"sum_of_digits"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | feac33166a99f2220bb82ab051a723689144fe36 | 370621bd65b8d1d4f11212efe8fb725710811817 | |||
v1.0 | instruct | Code_Contests | Code_Contests_13629_I | A programmer is designing an automatic alarm system for a building with multiple sensors distributed across different rooms. Each sensor can detect either fire or smoke but not both. Each sensor has a periodic update interval, indicating how often it sends data to the central monitoring system.
The programmer needs to... | import math
from functools import reduce
def lcm(a, b):
"""
Returns the least common multiple of a and b.
"""
return abs(a * b) // math.gcd(a, b)
def lcm_multiple(numbers):
"""
Returns the least common multiple of a list of numbers.
"""
return reduce(lcm, numbers)
def earliest_report_... | def test_lcm():
assert lcm(1, 2) == 2
assert lcm(2, 3) == 6
assert lcm(3, 5) == 15
assert lcm(4, 5) == 20
def test_lcm_multiple():
assert lcm_multiple([1, 2, 3]) == 6
assert lcm_multiple([5, 10, 15, 20]) == 60
assert lcm_multiple([2, 3, 4, 5]) == 60
assert lcm_multiple([10, 20, 30]) == ... | [
{
"docstring": "Returns the least common multiple of a and b.",
"function_declaration": "def lcm(a, b):",
"function_name": "lcm",
"parameter_list": "(a, b)"
},
{
"docstring": "Returns the least common multiple of a list of numbers.",
"function_declaration": "def lcm_multiple(numbers):",
... | [
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\nfrom functools import reduce\n\ndef lcm(a, b):\n return a * b // math.gcd(a, b)\n\ndef earliest_complete_report_time(n, update_intervals):\... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00013629",
"row_id": 13629,
"seed_ids": "[7661]"
} | 0.61331 | Code_Contests_13629 | I | [
"lcm",
"lcm_multiple",
"earliest_report_time"
] | 3 | [
[
"earliest_report_time",
"lcm_multiple"
],
[
"lcm_multiple",
"lcm"
]
] | 2 | [] | false | [] | false | pytest | false | [] | true | 23cc43938bf8fa9cc7862797732be37dbae549a5 | fca993721423ca0cdbc846983dfe02a8a5beac42 | |||
v1.0 | instruct | Code_Contests | Code_Contests_13666_I | Alice loves prime numbers and has recently found an interesting property related to them. A prime number is a natural number greater than 1 that has no positive divisors other than 1 and itself. Alice defines an **exactly half prime** as a number that is prime and exactly half of another prime number.
For example, sup... | from sympy import isprime
def find_exactly_half_prime(t, primes):
results = []
for p in primes:
q = p // 2
if p % 2 == 0 and isprime(q):
results.append(f"YES {q}")
else:
results.append("NO")
return results
def prime_as_half_of_another_prime(test_cases):
... | from solution import prime_as_half_of_another_prime
def test_case_1():
input_data = ["3", "7", "11", "13"]
expected_output = ["NO", "NO", "NO"]
assert prime_as_half_of_another_prime(input_data) == expected_output
def test_case_2():
input_data = ["3", "3", "5", "7"]
expected_output = ["NO", "NO", "... | [
{
"docstring": null,
"function_declaration": "def find_exactly_half_prime(t, primes):",
"function_name": "find_exactly_half_prime",
"parameter_list": "(t, primes)"
},
{
"docstring": null,
"function_declaration": "def prime_as_half_of_another_prime(test_cases):",
"function_name": "pri... | [
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 sympy import isprime\n\ndef find_exactly_half_prime(t, primes):\n results = []\n for p in primes:\n q = p // 2\n if p % 2 == 0 and... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00013666",
"row_id": 13666,
"seed_ids": "[10027]"
} | 0.625336 | Code_Contests_13666 | I | [
"find_exactly_half_prime",
"prime_as_half_of_another_prime"
] | 2 | [
[
"prime_as_half_of_another_prime",
"find_exactly_half_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [
"sympy"
] | false | f329bc4c26bcfa6c21be8bbe822b93d3676d33f2 | b4d6be7697504d3a8a537487d911f583804d26c6 | |||
v1.0 | instruct | Code_Contests | Code_Contests_13683_I | You are given a binary tree of n nodes, where each node has a unique integer value. You need to determine if the tree is a valid Binary Search Tree (BST). A binary search tree is defined as follows:
- The left subtree of a node contains only nodes with values less than the node's value.
- The right subtree of a node c... | class TreeNode:
def __init__(self, val=0, left=None, right=None):
self.val = val
self.left = left
self.right = right
def isValidBST(root):
def validate(node, low=float('-inf'), high=float('inf')):
# Empty trees are valid BSTs
if not node:
return True
... | import pytest
from solution import validate_bst_for_test_cases, process_input
def test_case_1():
input_str = "2\n3\n2 1 3\n1 -1 -1\n3 -1 -1\n3\n2 3 1\n3 -1 -1\n1 -1 -1"
test_cases = process_input(input_str)
assert validate_bst_for_test_cases(test_cases) == [True, False]
def test_case_2():
input_str =... | [] | [
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_0 | {
"original_instruction": "",
"prompt_id": "00013683",
"row_id": 13683,
"seed_ids": "[7360]"
} | 0.626617 | Code_Contests_13683 | I | [
"isValidBST",
"create_tree_from_list",
"validate_bst_for_test_cases",
"process_input"
] | 4 | [
[
"validate_bst_for_test_cases",
"create_tree_from_list"
],
[
"validate_bst_for_test_cases",
"isValidBST"
]
] | 2 | [
"validate_bst_for_test_cases",
"process_input"
] | false | [
"TreeNode"
] | true | pytest | true | [] | true | 973a0a068cf7efce33ee16324788637fe25c4da0 | d31ad0fd91562ac2f8d1d281da43fe352ed3c6a2 | |||
v1.0 | instruct | Code_Contests | Code_Contests_13695_I | You are given a list of integers. Find and return the second largest number in the list.
Input
The first line of input contains an integer n (2 ≤ n ≤ 100) - the number of integers in the list. The second line contains n integers, separated by spaces. Each integer is between -1000 and 1000, inclusive.
Output
Output ... | def second_largest(input_list):
"""
Returns the second largest number in the list.
"""
unique_numbers = list(set(input_list))
unique_numbers.sort()
if len(unique_numbers) < 2:
return None
return unique_numbers[-2]
# Function to handle the input as per the problem statement... | from solution import find_second_largest
def test_find_second_largest_example1():
assert find_second_largest(5, [2, 3, 6, 6, 5]) == 5
def test_find_second_largest_example2():
assert find_second_largest(3, [10, 5, 10]) == 5
def test_find_second_largest_all_same():
assert find_second_largest(4, [1, 1, 1, 1... | [
{
"docstring": "Returns the second largest number in the list.",
"function_declaration": "def second_largest(input_list):",
"function_name": "second_largest",
"parameter_list": "(input_list)"
},
{
"docstring": null,
"function_declaration": "def find_second_largest(n, numbers):",
"fun... | [
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 second_largest(n, numbers):\n \"\"\"\n Returns the second largest number in the list.\n \"\"\"\n first_largest = second_largest = -float('i... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00013695",
"row_id": 13695,
"seed_ids": "[6790]"
} | 0.777408 | Code_Contests_13695 | I | [
"second_largest",
"find_second_largest"
] | 2 | [
[
"find_second_largest",
"second_largest"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 3acc98c5769fea8b5ee541f7facee16e0c1edbda | 1be29f2377178ba7c689d89a7acf058e144bb5f8 | |||
v1.0 | instruct | Code_Contests | Code_Contests_13767_I | Peter is organizing a science fair. There are N students who will participate in the fair. Each of these students has exactly M projects they are interested in, conveniently numbered from 1 to M. Each student ranks these projects by preference where 1 indicates their most preferred and M indicates their least preferred... | import collections
def can_assign(preferences, N, M, limit):
counters = [0] * M
for pref in preferences:
assigned = False
for i in range(M):
project_index = pref[i] - 1
if counters[project_index] < limit:
counters[project_index] += 1
assig... | def test_case_1():
input_str = "3 4\n2 1 3 4\n1 3 2 4\n3 2 4 1"
assert main(input_str) == 1
def test_case_2():
input_str = "5 5\n1 2 3 4 5\n2 3 1 5 4\n3 4 2 1 5\n4 5 3 2 1\n5 1 4 3 2"
assert main(input_str) == 1
def test_case_3():
input_str = "4 3\n1 2 3\n2 1 3\n3 1 2\n2 3 1"
assert main(input... | [
{
"docstring": null,
"function_declaration": "def can_assign(preferences, N, M, limit):",
"function_name": "can_assign",
"parameter_list": "(preferences, N, M, limit)"
},
{
"docstring": null,
"function_declaration": "def find_minimum_maximum(N, M, preferences):",
"function_name": "fi... | [
1,
0,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import collections\n\ndef can_assign(preferences, N, M, limit):\n counters = [0] * M\n for pref in preferences:\n assigned = False\n fo... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00013767",
"row_id": 13767,
"seed_ids": "[6646]"
} | 0.648198 | Code_Contests_13767 | I | [
"can_assign",
"find_minimum_maximum",
"main"
] | 3 | [
[
"find_minimum_maximum",
"can_assign"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | 6ef477fafc39f57dd41c39e58c211d852dccc7a4 | 30ae74c7c77d6bbc7688b2a8fd4eeca539a640c7 | |||
v1.0 | instruct | Code_Contests | Code_Contests_13770_I | Farmer John has a rectangular farmland grid made of cells, where each cell can be plowed or unplowed. He represents the plowed cells with a 1 and unplowed cells with a 0. He wants to effectively prepare the farmland by ensuring that every contiguous block of plowed cells forms a single rectangular area.
Given the 2D ... | def maximalRectangle(matrix):
if not matrix:
return 0
max_area = 0
dp = [0] * len(matrix[0])
for row in matrix:
for j in range(len(row)):
dp[j] = dp[j] + 1 if row[j] == 1 else 0
max_area = max(max_area, largestRectangleArea(dp))
return max_area
def large... | from solution import maximalRectangle
def test_maximal_rectangle_case_1():
matrix = [
[1, 0, 1, 0, 0],
[1, 0, 1, 1, 1],
[1, 1, 1, 1, 1],
[1, 0, 0, 1, 0]
]
assert maximalRectangle(matrix) == 6
def test_maximal_rectangle_case_2():
matrix = [
[0, 0, 0],
[0,... | [
{
"docstring": null,
"function_declaration": "def maximalRectangle(matrix):",
"function_name": "maximalRectangle",
"parameter_list": "(matrix)"
},
{
"docstring": null,
"function_declaration": "def largestRectangleArea(heights):",
"function_name": "largestRectangleArea",
"paramete... | [
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 maximalRectangle(matrix):\n if not matrix:\n return 0\n\n max_area = 0\n dp = [0] * len(matrix[0])\n \n for row in matrix:\n ... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00013770",
"row_id": 13770,
"seed_ids": "[9799]"
} | 0.717701 | Code_Contests_13770 | I | [
"maximalRectangle",
"largestRectangleArea"
] | 2 | [
[
"maximalRectangle",
"largestRectangleArea"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 18de185ca58748acee84c01f2136947398d54b0f | 083f6f63ebed595c17bce7cc41de1e7509783924 | |||
v1.0 | instruct | Code_Contests | Code_Contests_13789_I | A directed graph is represented using an adjacency matrix of size n x n, where n is the number of vertices. An entry (i, j) in this matrix indicates the weight of the edge from vertex i to vertex j. A weight of 0 means there is no edge between these vertices. Your task is to determine if there is a cycle in the graph.
... | def has_cycle(n, graph):
def dfs(v, visited, rec_stack):
visited[v] = True
rec_stack[v] = True
for neighbour in range(n):
if graph[v][neighbour] != 0: # there is an edge
if not visited[neighbour]:
if dfs(neighbour, visited, rec_stack):
... | from solution import cycle_detector
def test_example_1():
n = 3
matrix = [
[0, 1, 0],
[0, 0, 1],
[1, 0, 0]
]
assert cycle_detector(n, matrix) == "YES"
def test_example_2():
n = 3
matrix = [
[0, 1, 0],
[0, 0, 1],
[0, 0, 0]
]
assert cycle_d... | [
{
"docstring": null,
"function_declaration": "def has_cycle(n, graph):",
"function_name": "has_cycle",
"parameter_list": "(n, graph)"
},
{
"docstring": null,
"function_declaration": "def cycle_detector(n, matrix):",
"function_name": "cycle_detector",
"parameter_list": "(n, matrix... | [
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 has_cycle(n, graph):\n def dfs(vertex, visited, rec_stack):\n visited[vertex] = True\n rec_stack[vertex] = True\n\n for neighbo... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00013789",
"row_id": 13789,
"seed_ids": "[1058]"
} | 0.732535 | Code_Contests_13789 | I | [
"has_cycle",
"cycle_detector"
] | 2 | [
[
"cycle_detector",
"has_cycle"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 49b6d82b5a3c045bdf7620fdf7acf9a7b9cb6719 | 791086aaa6571d4d1f8128b41b507e0775dce9e7 | |||
v1.0 | instruct | Code_Contests | Code_Contests_13792_I | Milo is fascinated by strings and their transformations. He has recently come across a string transformation problem and needs your help.
He has a string s consisting of lowercase English letters. The string can be transformed based on a set of rules. Each transformation rule is defined as follows:
- For each letter i... | def transform_string(s, k, p):
"""
Transforms the string s by moving each character k positions to the right p times.
"""
n = len(s)
# since p full cycles of n moves bring it back to the same string
effective_p = (k * p) % n
# rotating string by calculated effective_p steps
return s[-eff... | from solution import transform_string, solve, parse_input
def test_transform_string():
# Single test case, examples
assert transform_string("abcde", 1, 1) == "eabcd"
assert transform_string("xyz", 2, 3) == "xyz"
assert transform_string("hello", 1, 5) == "hello"
# Additional test cases
assert t... | [
{
"docstring": "Transforms the string s by moving each character k positions to the right p times.",
"function_declaration": "def transform_string(s, k, p):",
"function_name": "transform_string",
"parameter_list": "(s, k, p)"
},
{
"docstring": null,
"function_declaration": "def solve(tes... | [
0,
0,
0,
0,
0,
0,
0,
0,
1,
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 transform_string(s, k, p):\n \"\"\"\n Transform the string s by shifting it k positions to the right, p times.\n \"\"\"\n n = len(s)\n e... | trial_gpt4o_9 | {
"original_instruction": "",
"prompt_id": "00013792",
"row_id": 13792,
"seed_ids": "[6423]"
} | 0.795214 | Code_Contests_13792 | I | [
"transform_string",
"solve",
"parse_input"
] | 3 | [
[
"solve",
"transform_string"
]
] | 1 | [
"parse_input"
] | false | [] | false | pytest | true | [] | true | 929e012f2db770e17b73315517b4db0c4d5f6404 | d98c378f7470cf4e9d2878d1a64920c6717915cb | |||
v1.0 | instruct | Code_Contests | Code_Contests_13804_I | John recently got interested in studying sequences of prime numbers. He has a sequence of N integers and wants to find the length of the longest contiguous subsequence where all the integers are prime.
A prime number is a positive integer greater than 1 that has no positive integer divisors other than 1 and itself.
G... | def is_prime(num):
if num <= 1:
return False
for i in range(2, int(num**0.5) + 1):
if num % i == 0:
return False
return True
def longest_prime_subsequence_length(n, sequence):
max_len = 0
current_len = 0
for num in sequence:
if is_prime(num):
curr... | from solution import is_prime, longest_prime_subsequence_length
def test_is_prime():
assert is_prime(2)
assert is_prime(3)
assert not is_prime(4)
assert is_prime(5)
assert is_prime(7)
assert not is_prime(1)
assert not is_prime(0)
assert not is_prime(-5)
def test_longest_prime_subsequen... | [
{
"docstring": null,
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": null,
"function_declaration": "def longest_prime_subsequence_length(n, sequence):",
"function_name": "longest_prime_subsequence_length",
"pa... | [
1,
0,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(num):\n if num <= 1:\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_0 | {
"original_instruction": "",
"prompt_id": "00013804",
"row_id": 13804,
"seed_ids": "[74]"
} | 0.691702 | Code_Contests_13804 | I | [
"is_prime",
"longest_prime_subsequence_length"
] | 2 | [
[
"longest_prime_subsequence_length",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | bed5deab0d7595f5f2ed3bd50960f9fc91fc604b | 5e296d80c4d3036a675cc5bd62a5b727250b9a96 | |||
v1.0 | instruct | Code_Contests | Code_Contests_13882_I | Sylvia is organizing a conference, and she has to determine the schedule for n different presentations. Each presentation lasts for a certain amount of time, and there are m time slots available for presentations throughout the day. Sylvia must assign each presentation to one of the available time slots, and she cannot... | def can_schedule_presentations(test_cases):
results = []
for case in test_cases:
n, m, durations, limits = case
if n > m:
results.append("NO")
continue
durations.sort()
limits.sort()
possible = True
for duration, limit in zip(durations, ... | def test_can_schedule_presentations():
input_str = '3\n3 3\n2 3 5\n6 5 4\n4 2\n3 1 2 4\n5 3\n5 5\n4 4 4 4 4\n5 5 5 5 1\n'
expected_output = 'YES\nNO\nNO'
assert process_input_output(input_str) == expected_output
def test_single_case_yes():
input_str = '1\n1 2\n3\n5 4\n'
expected_output = 'YES'
... | [
{
"docstring": null,
"function_declaration": "def can_schedule_presentations(test_cases):",
"function_name": "can_schedule_presentations",
"parameter_list": "(test_cases)"
},
{
"docstring": null,
"function_declaration": "def input_parser(input_lines):",
"function_name": "input_parser... | [
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 can_schedule_presentations(t, test_cases):\n results = []\n for i in range(t):\n n, m = test_cases[i][0]\n d = test_cases[i][1]\n ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00013882",
"row_id": 13882,
"seed_ids": "[11782]"
} | 0.698057 | Code_Contests_13882 | I | [
"can_schedule_presentations",
"input_parser",
"process_input_output"
] | 3 | [
[
"process_input_output",
"can_schedule_presentations"
],
[
"process_input_output",
"input_parser"
]
] | 2 | [
"process_input_output"
] | false | [] | false | pytest | false | [] | true | 5fe8f0426e14408734f102b325cee3c5d9529d5a | 74222a364c9bad8acd8d45d01fec29928a97f573 | |||
v1.0 | instruct | Code_Contests | Code_Contests_13893_I | You are given a list of non-negative integers representing the heights of walls in a histogram. Each bar in the histogram is 1 unit wide. Your task is to calculate the maximum rectangular area that can be formed within the bounds of the histogram.
Input
The first line contains a single integer n (1 ≤ n ≤ 10^5) — the ... | def find_max_area_histogram(heights):
"""
Calculate the largest rectangular area possible in a given histogram.
:param heights: List of non-negative integers representing the heights of the histogram's bars.
:return: The area of the largest possible rectangle.
"""
stack = []
max_area = ... | def test_parse_input():
input_str = "6\n2 1 5 6 2 3\n"
assert parse_input(input_str) == [2, 1, 5, 6, 2, 3]
def test_find_max_area_histogram():
assert find_max_area_histogram([2, 1, 5, 6, 2, 3]) == 10
assert find_max_area_histogram([4, 4, 4, 4, 4]) == 20
assert find_max_area_histogram([6, 2, 5, 4, 5... | [
{
"docstring": "Calculate the largest rectangular area possible in a given histogram.\n\n:param heights: List of non-negative integers representing the heights of the histogram's bars.\n:return: The area of the largest possible rectangle.",
"function_declaration": "def find_max_area_histogram(heights):",
... | [
1,
1,
0
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def max_histogram_area(heights):\n \"\"\"\n Calculate the maximum rectangular area in a histogram.\n\n :param heights: List of non-negative intege... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00013893",
"row_id": 13893,
"seed_ids": "[9597]"
} | 0.662256 | Code_Contests_13893 | I | [
"find_max_area_histogram",
"parse_input",
"solve"
] | 3 | [
[
"solve",
"find_max_area_histogram"
],
[
"solve",
"parse_input"
]
] | 2 | [
"parse_input"
] | false | [] | false | pytest | false | [] | true | ddff4dbdca086f5263525be5ad8482cffeb859ab | ad411a716241ba4195886050629ad3f796692cde | |||
v1.0 | instruct | Code_Contests | Code_Contests_13967_I | ## Problem
Sam is building a railway system connecting N cities. Each city is numbered from 1 to N. Some pairs of cities need to be connected with a bidirectional track, and each track has a specific cost. Sam is tasked with selecting the minimum number of tracks such that every city can be reached from any other city... | def find_parent(parent, i):
if parent[i] == i:
return i
else:
return find_parent(parent, parent[i])
def union(parent, rank, x, y):
xroot = find_parent(parent, x)
yroot = find_parent(parent, y)
if rank[xroot] < rank[yroot]:
parent[xroot] = yroot
elif rank[xroot] > rank[y... | from solution import minimum_total_cost
def test_case_1():
N = 4
E = 5
tracks = [
(1, 2, 3),
(1, 3, 4),
(4, 2, 2),
(3, 4, 8),
(1, 4, 10)
]
assert minimum_total_cost(N, E, tracks) == 9
def test_case_2():
N = 3
E = 3
tracks = [
(1, 2, 1),
... | [
{
"docstring": null,
"function_declaration": "def find_parent(parent, i):",
"function_name": "find_parent",
"parameter_list": "(parent, i)"
},
{
"docstring": null,
"function_declaration": "def union(parent, rank, x, y):",
"function_name": "union",
"parameter_list": "(parent, rank... | [
0,
0,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def find(parent, i):\n # Function to find the parent of a node i\n if parent[i] == i:\n return i\n else:\n return find(parent, paren... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00013967",
"row_id": 13967,
"seed_ids": "[11966]"
} | 0.753241 | Code_Contests_13967 | I | [
"find_parent",
"union",
"kruskal_mst",
"minimum_total_cost"
] | 4 | [
[
"kruskal_mst",
"find_parent"
],
[
"kruskal_mst",
"union"
],
[
"minimum_total_cost",
"kruskal_mst"
],
[
"union",
"find_parent"
]
] | 4 | [] | false | [] | false | pytest | true | [] | true | aa963db490f2717bb2fbe338cb88aeae6f5cdf15 | db70cabe7b5fc32e0cf99ab52a9cb614666bea77 | |||
v1.0 | instruct | Code_Contests | Code_Contests_13977_I | You are working on a unique navigation system for a museum. The museum is arranged as an undirected graph with **n** rooms connected by **m** corridors. Each room is represented as a node, and each corridor is represented as an edge between two nodes. You need to make sure the system can efficiently answer shortest pat... | def floyd_warshall(n, edges):
"""
Computes the shortest paths between all pairs of nodes using Floyd-Warshall algorithm.
Parameters:
n (int): Number of nodes.
edges (list of tuple): List of edges where each edge is (u, v, w) denoting an edge between u and v with weight w.
Returns:
... | def test_floyd_warshall():
n = 5
edges = [
(1, 2, 3),
(1, 3, 5),
(2, 3, 2),
(2, 4, 4),
(3, 4, 1),
(4, 5, 7)
]
expected_dist = [
[0, 3, 5, 6, 13],
[3, 0, 2, 3, 10],
[5, 2, 0, 1, 8],
[6, 3, 1, 0, 7],
[13, 10, 8, 7, 0]
... | [
{
"docstring": "Computes the shortest paths between all pairs of nodes using Floyd-Warshall algorithm.\n\nParameters:\nn (int): Number of nodes.\nedges (list of tuple): List of edges where each edge is (u, v, w) denoting an edge between u and v with weight w.\n\nReturns:\nlist: 2D list representing shortest pat... | [
0,
0,
1,
0
] | 1 | hard | 0.25 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import heapq\n\ndef preprocess_graph(n, m, edges):\n \"\"\"\n Preprocess the graph using Floyd-Warshall algorithm to find shortest paths \n betwee... | trial_gpt4o_3 | {
"original_instruction": "",
"prompt_id": "00013977",
"row_id": 13977,
"seed_ids": "[321]"
} | 0.711259 | Code_Contests_13977 | I | [
"floyd_warshall",
"preprocess_graph_and_answer_queries"
] | 2 | [
[
"preprocess_graph_and_answer_queries",
"floyd_warshall"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | abfb30887afa45254819dc2d3c87d4fadc90b336 | 6ab4da79b5320aedc9ed1a895a696fbffd2be5ca | |||
v1.0 | instruct | Code_Contests | Code_Contests_13997_I | In a game development project, you need to generate a leaderboard for players based on their scores. Each player can obtain scores from multiple games, and the leaderboard should reflect the highest score obtained by each player. The leaderboard should list the players in descending order of their highest scores. In th... | def generate_leaderboard(player_data):
"""
Generates a leaderboard based on the highest scores of players.
Args:
player_data (list of tuple): List of tuples where each tuple contains player's name and their highest score.
Returns:
list of tuple: List of tuples representing the sorted l... | from solution import generate_leaderboard, get_leaderboard_from_input
def test_generate_leaderboard():
player_data = [("alice", 300), ("bob", 200), ("charlie", 400), ("dave", 300), ("eve", 500)]
expected_output = [("eve", 500), ("charlie", 400), ("alice", 300), ("dave", 300), ("bob", 200)]
assert generate_... | [
{
"docstring": "Generates a leaderboard based on the highest scores of players.\n\nArgs:\nplayer_data (list of tuple): List of tuples where each tuple contains player's name and their highest score.\n\nReturns:\nlist of tuple: List of tuples representing the sorted leaderboard.",
"function_declaration": "de... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def generate_leaderboard(player_data):\n \"\"\"\n Generates a leaderboard sorted by highest score in descending order.\n In case of a tie, players... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00013997",
"row_id": 13997,
"seed_ids": "[10486]"
} | 0.721853 | Code_Contests_13997 | I | [
"generate_leaderboard",
"get_leaderboard_from_input"
] | 2 | [
[
"get_leaderboard_from_input",
"generate_leaderboard"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 1439ae59aed83e3ae8c9bd93ae3f6bac291ebbc8 | 08f5eac583736775942af5e7a5fc72f071e1b8db | |||
v1.0 | instruct | Code_Contests | Code_Contests_14009_I | Given a 9×9 Sudoku puzzle where some of the cells are already filled with digits ranging from 1 to 9, determine whether it is possible to completely fill the grid following the Sudoku rules:
- Each row must contain all digits from 1 to 9 without repetition.
- Each column must contain all digits from 1 to 9 without rep... | def is_valid_sudoku(board):
rows, cols, squares = {}, {}, {}
for r in range(9):
for c in range(9):
val = board[r][c]
if val != '.':
if r not in rows:
rows[r] = set()
if c not in cols:
cols[c] = set()
... | from solution import main
def test_valid_sudoku():
input_puzzle = """\
53..7....
6..195...
.98....6.
8...6...3
4..8.3..1
7...2...6
.6....28.
...419..5
....8..79
0"""
assert main(input_puzzle) == "Yes"
def test_invalid_sudoku():
input_puzzle = """\
53..7....
65.195...
.98....6.
8...6...3
4..8.3..1
7...2...... | [
{
"docstring": null,
"function_declaration": "def is_valid_sudoku(board):",
"function_name": "is_valid_sudoku",
"parameter_list": "(board)"
},
{
"docstring": null,
"function_declaration": "def solve_sudoku(board):",
"function_name": "solve_sudoku",
"parameter_list": "(board)"
}... | [
0,
0,
0,
1,
0
] | 1 | hard | 0.2 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_valid(board, row, col, num):\n for i in range(9):\n if board[row][i] == num:\n return False\n if board[i][col] == num:\n... | trial_gpt4o_3 | {
"original_instruction": "",
"prompt_id": "00014009",
"row_id": 14009,
"seed_ids": "[3738]"
} | 0.638545 | Code_Contests_14009 | I | [
"is_valid_sudoku",
"solve_sudoku",
"find_empty_location",
"is_safe",
"process_input",
"main"
] | 6 | [
[
"process_input",
"solve_sudoku"
],
[
"solve_sudoku",
"find_empty_location"
],
[
"solve_sudoku",
"is_safe"
],
[
"solve_sudoku",
"is_valid_sudoku"
]
] | 4 | [
"process_input"
] | false | [] | false | pytest | true | [] | true | 7a89c4dc75ca2082f1376e0362f13ab92e46d7fe | a438390be3c1770ddf871ba3bc817e968a2f4888 | |||
v1.0 | instruct | Code_Contests | Code_Contests_14027_I | Problem Statement
You are given a binary tree composed of N nodes. Each node in the tree has an integer value assigned to it. Your task is to find a path from the root to a leaf such that the sum of the values of the nodes in the path is maximized.
A path is defined as a sequence of nodes starting from some node and p... | class TreeNode:
def __init__(self, value=0, left=None, right=None):
self.value = value
self.left = left
self.right = right
def construct_tree(nodes):
tree_nodes = [TreeNode(value) for value, _, _ in nodes]
for idx, (value, left, right) in enumerate(nodes):
if left != -1:
... | from solution import TreeNode, construct_tree, find_maximum_sum_path, max_sum_path_for_test_cases
def test_single_node():
nodes = [(3, -1, -1)]
root = construct_tree(nodes)
assert find_maximum_sum_path(root) == ([3], 3)
def test_example_case_1():
nodes = [
(3, 1, 2),
(1, -1, -1),
... | [] | [
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 TreeNode:\n def __init__(self, value):\n self.value = value\n self.left = None\n self.right = None\n\ndef build_tree(nodes):\... | trial_gpt4o_4 | {
"original_instruction": "",
"prompt_id": "00014027",
"row_id": 14027,
"seed_ids": "[10416]"
} | 0.709411 | Code_Contests_14027 | I | [
"construct_tree",
"find_maximum_sum_path",
"max_sum_path_for_test_cases"
] | 3 | [
[
"max_sum_path_for_test_cases",
"construct_tree"
],
[
"max_sum_path_for_test_cases",
"find_maximum_sum_path"
]
] | 2 | [
"max_sum_path_for_test_cases"
] | false | [
"TreeNode"
] | true | pytest | true | [] | true | 921d82efa3ad6cc35911b07db1f0642addd87092 | 81f58eae1f295ba5790353b1ded296c38635a738 | |||
v1.0 | instruct | Code_Contests | Code_Contests_14028_I | Bob is designing a traffic system in his city. The city consists of n intersections connected by m one-way roads. Due to budget constraints, Bob needs to minimize the number of roads to keep only essential ones while ensuring that it is still possible to travel from any intersection to any other intersection using the ... | from collections import defaultdict, deque
def find_sccs(n, graph):
index = [None] * n
lowlink = [None] * n
on_stack = [False] * n
stack = []
sccs = []
current_index = 0
def strongconnect(node):
nonlocal current_index
index[node] = current_index
lowlink[node] = curr... | def test_possible_to_retain_roads():
test_cases = [
(4, 5, [(1, 2), (2, 3), (3, 4), (4, 1), (2, 4)]),
(3, 3, [(1, 2), (2, 3), (3, 1)]),
(4, 4, [(1, 2), (2, 3), (3, 4), (4, 1)])
]
expected_output = [
("YES", 5, [(1, 2), (2, 3), (3, 4), (4, 1), (2, 4)]),
("YES", 3, [(1... | [
{
"docstring": null,
"function_declaration": "def find_sccs(n, graph):",
"function_name": "find_sccs",
"parameter_list": "(n, graph)"
},
{
"docstring": null,
"function_declaration": "def possible_to_retain_roads(test_cases):",
"function_name": "possible_to_retain_roads",
"paramet... | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def find_minimum_roads(t, test_cases):\n from collections import defaultdict, deque\n results = []\n \n def kosaraju(n, edges):\n graph ... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00014028",
"row_id": 14028,
"seed_ids": "[11790]"
} | 0.741464 | Code_Contests_14028 | I | [
"find_sccs",
"possible_to_retain_roads"
] | 2 | [
[
"possible_to_retain_roads",
"find_sccs"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | 177994e144eb9bc861987e50b66ce75a1c64797c | 4578274f581ce6de9bd0a3dd213e49caefd5ad0a | |||
v1.0 | instruct | Code_Contests | Code_Contests_14037_I | F: Sweets Distribution
Tamara is organizing a sweets distribution event at her school.
There are `N` different types of sweet packets, each containing `A_1, A_2, A_3, \dots, A_N` pieces of sweets respectively.
Tamara wants to distribute the sweets such that each student gets an equal number of sweets and no sweets a... | import math
from functools import reduce
def gcd_multiple(numbers):
return reduce(math.gcd, numbers)
def max_students(N, A):
return gcd_multiple(A) | from solution import max_students
def test_case_1():
assert max_students(5, [4, 6, 8, 12, 16]) == 2
def test_case_2():
assert max_students(3, [2, 4, 8]) == 2
def test_case_3():
assert max_students(4, [1, 1, 1, 1]) == 1
def test_case_4():
assert max_students(2, [5, 10]) == 5
def test_case_5():
a... | [
{
"docstring": null,
"function_declaration": "def gcd_multiple(numbers):",
"function_name": "gcd_multiple",
"parameter_list": "(numbers)"
},
{
"docstring": null,
"function_declaration": "def max_students(N, A):",
"function_name": "max_students",
"parameter_list": "(N, A)"
}
] | [
0,
1,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import math\nfrom functools import reduce\n\ndef gcd_of_list(numbers):\n \"\"\"\n Function to calculate gcd of a list of numbers\n \"\"\"\n ret... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00014037",
"row_id": 14037,
"seed_ids": "[4165]"
} | 0.688198 | Code_Contests_14037 | I | [
"gcd_multiple",
"max_students"
] | 2 | [
[
"max_students",
"gcd_multiple"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | a7d118dfc9c9e4cb10c065af8d329e8ca51059a5 | 3cea1c44c841648fbf951f0411418d5255640233 | |||
v1.0 | instruct | Code_Contests | Code_Contests_14061_I | Write a program that reads an integer $n$ (2 ≤ n ≤ 50) and then reads $n$ strings each representing a mathematical expression containing only non-negative integers and the operators '+', '-', '*', and '/'. Determine if each expression evaluates to a prime number.
Constraints
- Each mathematical expression is valid an... | def is_prime(num):
"""
Check if the given number is a prime number.
"""
if num <= 1:
return False
if num <= 3:
return True
if num % 2 == 0 or num % 3 == 0:
return False
i = 5
while i * i <= num:
if num % i == 0 or num % (i + 2) == 0:
return Fal... | from solution import is_prime, evaluate_expressions
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(29) == True
assert is_prime(30) == False
def test_evaluate_expressions():
expressions = [
... | [
{
"docstring": "Check if the given number is a prime number.",
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": "Evaluate a list of mathematical expressions and determine if\ntheir results are prime numbers.",
"functio... | [
0,
0,
0,
1
] | 1 | hard | 0.25 | {
"trial_gpt4o_0": null,
"trial_gpt4o_1": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared1_results_combined.jsonl",
"solution_code": "import math\n\ndef is_prime(num):\n \"\"\"\n Determines if a number is prime.\n \"\"\"\n if num <= 1:\n return ... | trial_gpt4o_4 | {
"original_instruction": "",
"prompt_id": "00014061",
"row_id": 14061,
"seed_ids": "[1877]"
} | 0.655325 | Code_Contests_14061 | I | [
"is_prime",
"evaluate_expressions"
] | 2 | [
[
"evaluate_expressions",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | fde48db3d2497e43e5dfbea49058052bba4aa091 | 7aa5d8fef265128a6a0a9060e60e19f5985c0bc8 | |||
v1.0 | instruct | Code_Contests | Code_Contests_14064_I | Given an NxM grid, you are standing at the top-left corner (1, 1). Your goal is to reach the bottom-right corner (N, M). From any cell (i, j) in the grid, you can move either right to (i, j+1) or down to (i+1, j). You cannot move diagonally or out of the grid's bounds. Your task is to calculate the number of unique pat... | def factorial(n):
if n == 0 or n == 1:
return 1
result = 1
for i in range(2, n + 1):
result *= i
return result
def unique_paths(N, M):
# The number of unique paths is given by the binomial coefficient (N+M-2) choose (M-1)
return factorial(N + M - 2) // (factorial(N - 1) * factor... | def test_factorial():
assert factorial(0) == 1
assert factorial(1) == 1
assert factorial(2) == 2
assert factorial(3) == 6
assert factorial(4) == 24
assert factorial(5) == 120
def test_unique_paths():
assert unique_paths(2, 2) == 2
assert unique_paths(3, 3) == 6
assert unique_paths(3... | [
{
"docstring": null,
"function_declaration": "def factorial(n):",
"function_name": "factorial",
"parameter_list": "(n)"
},
{
"docstring": null,
"function_declaration": "def unique_paths(N, M):",
"function_name": "unique_paths",
"parameter_list": "(N, M)"
},
{
"docstring":... | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import math\n\ndef number_of_paths(n, m):\n \"\"\"\n Function to calculate the number of unique paths in an NxM grid.\n It uses the binomial coeff... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00014064",
"row_id": 14064,
"seed_ids": "[11666]"
} | 0.756198 | Code_Contests_14064 | I | [
"factorial",
"unique_paths",
"process_test_cases",
"main"
] | 4 | [
[
"process_test_cases",
"unique_paths"
],
[
"unique_paths",
"factorial"
]
] | 2 | [
"process_test_cases"
] | false | [] | false | pytest | false | [] | true | 3d379a40cfff80c2c59ba43d0e974e91e658d55a | 974cd6168bccf88e5f34785abf36ed46c6e04579 | |||
v1.0 | instruct | Code_Contests | Code_Contests_14101_I | You are given a grid with n rows and m columns. Each cell in the grid contains a lowercase alphabet character. Two cells are considered connected if they share a side (top, bottom, left, or right) and contain the same character. A region is defined as a maximal set of connected cells that contain the same character.
F... | def find_region_size(grid, x, y, n, m, visited):
# Directions for moving up, down, left, right
directions = [(-1, 0), (1, 0), (0, -1), (0, 1)]
stack = [(x, y)]
start_char = grid[x][y]
size = 0
while stack:
cx, cy = stack.pop()
if visited[cx][cy]:
continue
... | def test_case_1():
n, m, q = 4, 4, 3
grid = [
"abab",
"baba",
"abab",
"baba"
]
queries = [(1, 1), (2, 2), (4, 2)]
assert solve(n, m, q, grid, queries) == [1, 1, 1]
def test_case_2():
n, m, q = 3, 3, 3
grid = [
"aaa",
"aba",
"aaa"
]... | [
{
"docstring": null,
"function_declaration": "def find_region_size(grid, x, y, n, m, visited):",
"function_name": "find_region_size",
"parameter_list": "(grid, x, y, n, m, visited)"
},
{
"docstring": null,
"function_declaration": "def solve(n, m, q, grid, queries):",
"function_name":... | [
0,
0,
0,
0,
1
] | 1 | hard | 0.2 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def find_region_size(grid, n, m, x, y, visited, char):\n \"\"\"\n Returns the size of the region containing the cell (x, y)\n \"\"\"\n if x < 0... | trial_gpt4o_4 | {
"original_instruction": "",
"prompt_id": "00014101",
"row_id": 14101,
"seed_ids": "[10011]"
} | 0.715712 | Code_Contests_14101 | I | [
"find_region_size",
"solve",
"fill_region_sizes"
] | 3 | [
[
"solve",
"fill_region_sizes"
],
[
"solve",
"find_region_size"
]
] | 2 | [] | false | [] | false | pytest | false | [] | true | 1539b9eaa8fc853bc7b4002f0ceb9531fae78b2a | 3af12277ced4221e84dfa0a596f5ab0df85524e5 | |||
v1.0 | instruct | Code_Contests | Code_Contests_14132_I | A palindrome is a word, number, phrase, or other sequences of characters that reads the same forward and backward (ignoring spaces, punctuation, and capitalization).
In this problem, you need to write a program that checks if a given string is a palindrome. Your task is to read an integer n, followed by n strings. Fo... | def is_palindrome(s):
"""
Checks if the given string s is a palindrome, ignoring spaces, punctuation, and capitalization.
"""
cleaned_s = ''.join(char.lower() for char in s if char.isalnum())
return cleaned_s == cleaned_s[::-1]
def check_palindromes(n, strings):
"""
For each string in strin... | from solution import is_palindrome, check_palindromes
def test_is_palindrome_single_word():
assert is_palindrome("racecar") == True
assert is_palindrome("hello") == False
def test_is_palindrome_with_spaces_and_punctuations():
assert is_palindrome("A man, a plan, a canal, Panama") == True
assert is_pal... | [
{
"docstring": "Checks if the given string s is a palindrome, ignoring spaces, punctuation, and capitalization.",
"function_declaration": "def is_palindrome(s):",
"function_name": "is_palindrome",
"parameter_list": "(s)"
},
{
"docstring": "For each string in strings, checks if it is a palind... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import re\n\ndef is_palindrome(s):\n \"\"\"\n Checks if the given string s is a palindrome, ignoring non-alphanumeric characters\n and case sensit... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00014132",
"row_id": 14132,
"seed_ids": "[5401]"
} | 0.801167 | Code_Contests_14132 | I | [
"is_palindrome",
"check_palindromes"
] | 2 | [
[
"check_palindromes",
"is_palindrome"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 31f6210788258c15917d62e64f4fe221e4f2c1bf | 4c81cedaf809e01337460a8439502b0a454ed959 | |||
v1.0 | instruct | Code_Contests | Code_Contests_14178_I | Ravi is building a special type of string called a "balanced string" for his research. A string is considered balanced if it has an equal number of 'A's and 'B's, and for any prefix of the string, the number of 'A's should never be less than the number of 'B's.
For instance, "AABB", "AABABB", and "AAABBB" are balanced... | MOD = 10**9 + 7
def catalan_number(n):
if n == 0:
return 1
c = [0]* (n + 1)
c[0] = 1
for i in range(1, n + 1):
c[i] = (2 * (2 * i - 1) * c[i - 1]) // (i + 1)
c[i] %= MOD
return c[n]
def count_balanced_strings(n):
if n % 2 != 0:
return 0
n //= 2
return ca... | from solution import count_balanced_strings
def test_balanced_strings_length_4():
assert count_balanced_strings(4) == 2
def test_balanced_strings_length_6():
assert count_balanced_strings(6) == 5
def test_balanced_strings_length_3():
assert count_balanced_strings(3) == 0
def test_balanced_strings_length... | [
{
"docstring": null,
"function_declaration": "def catalan_number(n):",
"function_name": "catalan_number",
"parameter_list": "(n)"
},
{
"docstring": null,
"function_declaration": "def count_balanced_strings(n):",
"function_name": "count_balanced_strings",
"parameter_list": "(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": "MOD = 10**9 + 7\n\ndef balanced_string_count(n):\n \"\"\"\n Returns the number of balanced strings of length n.\n \"\"\"\n if n % 2 != 0:\n ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00014178",
"row_id": 14178,
"seed_ids": "[8803]"
} | 0.735349 | Code_Contests_14178 | I | [
"catalan_number",
"count_balanced_strings"
] | 2 | [
[
"count_balanced_strings",
"catalan_number"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 6dfe6589b6b2a1bd9b81e84c48da96055ca41e24 | c2c960d2edd7a7708e71c001b915bb2da0fe4f59 | |||
v1.0 | instruct | Code_Contests | Code_Contests_14206_I | You are tasked with processing a list of words. For each word in the list, you need to determine if it is a palindrome. A word is considered a palindrome if it reads the same backward as forward (ignoring case). You should return the results for all words in the list.
A palindrome is a word that remains the same when ... | def is_palindrome(word):
"""
Check if a given word is a palindrome, ignoring case.
Returns "YES" if word is a palindrome, otherwise "NO".
"""
word = word.lower()
if word == word[::-1]:
return "YES"
else:
return "NO"
def process_words(words):
"""
Process a list of wor... | from solution import is_palindrome, process_words
def test_is_palindrome():
assert is_palindrome("Madam") == "YES"
assert is_palindrome("Hello") == "NO"
assert is_palindrome("Racecar") == "YES"
assert is_palindrome("World") == "NO"
assert is_palindrome("a") == "YES"
assert is_palindrome("Aa") =... | [
{
"docstring": "Check if a given word is a palindrome, ignoring case.\nReturns \"YES\" if word is a palindrome, otherwise \"NO\".",
"function_declaration": "def is_palindrome(word):",
"function_name": "is_palindrome",
"parameter_list": "(word)"
},
{
"docstring": "Process a list of words to 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_palindrome(word):\n \"\"\"\n Determines if a word is a palindrome. A word is considered a palindrome \n if it reads the same backward as fo... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00014206",
"row_id": 14206,
"seed_ids": "[11163]"
} | 0.774708 | Code_Contests_14206 | I | [
"is_palindrome",
"process_words"
] | 2 | [
[
"process_words",
"is_palindrome"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 207603163a6d0efb68dc8d97f21d6971d9733794 | b0b89fe4ffcf5ea6c78a44ac487c7933c74a928b | |||
v1.0 | instruct | Code_Contests | Code_Contests_14241_I | There is a city consisting of N intersections and M roads. Each road connects a pair of intersections. Your task is to find the number of intersections that, if removed along with their incident roads, will divide the city into two or more disconnected parts.
An intersection is called a "cut vertex" if removing it (an... | def find_cut_vertices(n, adj):
"""
Function to find all cut vertices in a graph using Tarjan's Algorithm.
:param n: number of vertices
:param adj: adjacency list of the graph
:return: a list of cut vertices
"""
def dfs(current, discovery, low, parent, visited, articulation_points, time):
... | import pytest
from solution import main
def test_example():
input_data = "2\n5 5\n1 2\n1 3\n3 4\n4 5\n4 2\n4 4\n1 2\n2 3\n3 4\n4 2"
output_data = "1\n1"
assert main(input_data) == output_data
def test_no_edges():
input_data = "1\n3 0"
output_data = "0"
assert main(input_data) == output_data
d... | [
{
"docstring": "Function to find all cut vertices in a graph using Tarjan's Algorithm.\n:param n: number of vertices\n:param adj: adjacency list of the graph\n:return: a list of cut vertices",
"function_declaration": "def find_cut_vertices(n, adj):",
"function_name": "find_cut_vertices",
"parameter_... | [
0,
0,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def find_cut_vertices(N, M, roads):\n import sys\n sys.setrecursionlimit(2000)\n from collections import defaultdict\n \n def dfs(cur, paren... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00014241",
"row_id": 14241,
"seed_ids": "[11109]"
} | 0.648459 | Code_Contests_14241 | I | [
"find_cut_vertices",
"count_cut_vertices",
"process_input",
"main"
] | 4 | [
[
"count_cut_vertices",
"find_cut_vertices"
]
] | 1 | [
"process_input"
] | false | [] | false | pytest | true | [] | true | 088d01e4190ec734b415ff60a3e49b51f6096680 | 1e2667f2d90838a1ffe9ef34ab9323451cf80172 | |||
v1.0 | instruct | Code_Contests | Code_Contests_14251_I | A group of explorers discovered an ancient, secretive code in the depths of a hidden cave. The code revealed a mysterious language known as "Circular Prime". This language involves evaluating string sequences that circle around a wheel with digits from 0 to 9.
Given a string of digits, the origin of each sequence can ... | def is_prime(n):
"""
Helper function to check if a number is prime.
"""
if n <= 1:
return False
if n <= 3:
return True
if n % 2 == 0 or n % 3 == 0:
return False
i = 5
while i * i <= n:
if n % i == 0 or n % (i + 2) == 0:
return False
i +... | from solution import is_circular_prime, generate_rotations, is_prime
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(20) == False
def test_generate_rotations():
assert generate_rotations("123") =... | [
{
"docstring": "Helper function to check if a number is prime.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Generate all rotations of the string s.",
"function_declaration": "def generate_rotations(s):",
"functi... | [
0,
0,
0,
0,
0,
1,
1,
1,
1,
0
] | 4 | medium | 0.4 | {
"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.\n \"\"\"\n if num <= 1:\n return False\n if num == 2:\n return Tru... | trial_gpt4o_7 | {
"original_instruction": "",
"prompt_id": "00014251",
"row_id": 14251,
"seed_ids": "[1974]"
} | 0.55823 | Code_Contests_14251 | I | [
"is_prime",
"generate_rotations",
"is_circular_prime"
] | 3 | [
[
"is_circular_prime",
"generate_rotations"
],
[
"is_circular_prime",
"is_prime"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 32d88d2af13f73629259674880c6f677e0e4ff62 | fd797e4d67b05c6639bf5806f6a74d5b485865c6 | |||
v1.0 | instruct | Code_Contests | Code_Contests_14321_I | In a mythical kingdom, there are n villages connected by n-1 roads, making up a tree structure. Each village is labeled from 1 to n. The king wants to set up a courier system to facilitate communication between the villages. The courier system is designed so that every village has exactly one courier, and each courier ... | from collections import deque
def find_furthest_node(n, graph, start):
"""
Perform BFS to find the furthest node from the start node.
Returns the node and its distance from the start.
"""
visited = [False] * (n + 1)
queue = deque([(start, 0)]) # (current_node, current_distance)
visited[sta... | import pytest
from solution import minimum_max_distance
def test_case_1():
n = 4
roads = [(1, 2), (2, 3), (3, 4)]
assert minimum_max_distance(n, roads) == 2
def test_case_2():
n = 6
roads = [(1, 2), (1, 3), (3, 4), (3, 5), (4, 6)]
assert minimum_max_distance(n, roads) == 2
def test_case_3():... | [
{
"docstring": "Perform BFS to find the furthest node from the start node.\nReturns the node and its distance from the start.",
"function_declaration": "def find_furthest_node(n, graph, start):",
"function_name": "find_furthest_node",
"parameter_list": "(n, graph, start)"
},
{
"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": "from collections import deque\n\ndef find_farthest_node(n, graph, start):\n \"\"\"\n Function to return the farthest node and its distance from the s... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00014321",
"row_id": 14321,
"seed_ids": "[2462]"
} | 0.692572 | Code_Contests_14321 | I | [
"find_furthest_node",
"minimum_max_distance"
] | 2 | [
[
"minimum_max_distance",
"find_furthest_node"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 0724fe04ee0b76ffdd6312cb667c1884c2a241de | 993a78a386c4ce52dae7076dd5c6bd7318b2b891 | |||
v1.0 | instruct | Code_Contests | Code_Contests_14327_I | You are tasked with designing a program to simulate an online auction. In an online auction, bidders can place bids on items within a certain timeframe. Each bid consists of the bidder's name and the bid amount. At the end of the auction, the highest bid wins the item. If there are multiple bids with the same highest a... | def find_auction_winner(n, bids, t):
"""
Returns the winner's name in the auction or "No bids" if no valid bids exist.
"""
valid_bids = [bid for bid in bids if bid[1] <= t]
if not valid_bids:
return "No bids"
valid_bids.sort(key=lambda x: (-x[2], x[1]))
return valid_bi... | def test_auction():
input_data1 = "5\nalice 100 150\nbob 200 200\ncarol 300 150\nalice 250 200\nbob 150 200\n250"
assert auction(input_data1) == "bob"
input_data2 = "2\nalice 50 100\nbob 60 100\n30"
assert auction(input_data2) == "No bids"
input_data3 = "3\nalice 100 150\nbob 200 200\ncarol 300 15... | [
{
"docstring": "Returns the winner's name in the auction or \"No bids\" if no valid bids exist.",
"function_declaration": "def find_auction_winner(n, bids, t):",
"function_name": "find_auction_winner",
"parameter_list": "(n, bids, t)"
},
{
"docstring": null,
"function_declaration": "def ... | [
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 determine_winner(bids, end_time):\n \"\"\"\n Determines the winner of the auction based on the highest bid amount and \n earliest bid time in ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00014327",
"row_id": 14327,
"seed_ids": "[7553]"
} | 0.601485 | Code_Contests_14327 | I | [
"find_auction_winner",
"auction"
] | 2 | [
[
"auction",
"find_auction_winner"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | 4fe7040482e907fb5b17fed3413e0785d5d1268a | 232bc2cefb2d87a8d89ddf7000d03bdab38d4ae7 | |||
v1.0 | instruct | Code_Contests | Code_Contests_14338_I | You are developing a new communication system for a space station. The system consists of a network of nodes, each representing a communication device. There are cables connecting the nodes, enabling direct communication between them. Your task is to ensure that the communication network is robust and can tolerate fail... | from collections import defaultdict, deque
def is_robust_network(n, m, cables):
"""
Determines if the network is robust and returns the cost if it is, otherwise returns -1.
:param n: Number of nodes
:param m: Number of cables
:param cables: List of tuples representing undirected cables between... | from solution import communication_network_cost
def test_robust_network():
assert communication_network_cost(5, 6, [(1, 2), (2, 3), (3, 4), (4, 5), (5, 1), (2, 4)]) == 6
def test_non_robust_network():
assert communication_network_cost(4, 2, [(1, 2), (3, 4)]) == -1
def test_minimal_network():
assert commu... | [
{
"docstring": "Determines if the network is robust and returns the cost if it is, otherwise returns -1.\n\n:param n: Number of nodes\n:param m: Number of cables\n:param cables: List of tuples representing undirected cables between nodes\n:return: Cost of the network if robust, otherwise -1",
"function_decl... | [
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_robust_and_cost(n, m, cables):\n from collections import defaultdict, deque\n\n # Build the graph\n graph = defaultdict(list)\n for u, v... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00014338",
"row_id": 14338,
"seed_ids": "[6368]"
} | 0.580446 | Code_Contests_14338 | I | [
"is_robust_network",
"communication_network_cost"
] | 2 | [
[
"communication_network_cost",
"is_robust_network"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 488b88ca1253c518c941297ad887b4bb2750763e | 7a0e7394a2a3c0c36a9076b4aa0f393129030e41 | |||
v1.0 | instruct | Code_Contests | Code_Contests_14340_I | A large event is being organized in a city with several locations connected by roads. To ensure efficient transportation of attendees, the organizers want to calculate the minimum distance required to travel between various pairs of locations. Attendees can travel in both directions along any road. Given multiple queri... | import sys
import heapq
def floyd_warshall(n, graph):
dist = [[float('inf')] * n for _ in range(n)]
for u in range(n):
for v in range(n):
dist[u][v] = graph[u][v]
for k in range(n):
for i in range(n):
for j in range(n):
if dist[i][j] > dist[i][k] + ... | from solution import find_minimum_distances
def test_case_1():
T = 1
test_cases = [
(
4, 4,
[
(1, 2, 5),
(2, 3, 6),
(3, 4, 2),
(1, 4, 9)
],
3,
[
(1, 3),
... | [
{
"docstring": null,
"function_declaration": "def floyd_warshall(n, graph):",
"function_name": "floyd_warshall",
"parameter_list": "(n, graph)"
},
{
"docstring": null,
"function_declaration": "def find_minimum_distances(T, test_cases):",
"function_name": "find_minimum_distances",
... | [
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": "import heapq\nfrom collections import defaultdict, deque\n\ndef dijkstra(adj_list, start, n):\n \"\"\"\n Computes the shortest paths from start node ... | trial_gpt4o_4 | {
"original_instruction": "",
"prompt_id": "00014340",
"row_id": 14340,
"seed_ids": "[1260]"
} | 0.825222 | Code_Contests_14340 | I | [
"floyd_warshall",
"find_minimum_distances"
] | 2 | [
[
"find_minimum_distances",
"floyd_warshall"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | bb00639cf3e61f6f6de46ff22a435e8cfb40ad6e | afc94453c21813ea136601021e1eb4be8891ed48 | |||
v1.0 | instruct | Code_Contests | Code_Contests_14372_I | Given a directed graph with N nodes and M edges, where each edge has a specific weight, you are to find out if there is a path from a node S to a node T, such that the sum of the weights of the edges on that path is a prime number.
Constraints:
* 1 ≤ N, M ≤ 100
* 1 ≤ edge weight ≤ 10^6
* 1 ≤ S, T ≤ N
* The graph may ... | from collections import deque
from math import isqrt
def is_prime(n):
"""Returns True if n is a prime number else False."""
if n <= 1:
return False
if n <= 3:
return True
if n % 2 == 0 or n % 3 == 0:
return False
i = 5
while i * i <= n:
if n % i == 0 or n % (i + ... | import pytest
from solution import is_prime, path_with_prime_sum
def test_is_prime():
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(4) == False
assert is_prime(17) == True
assert is_prime(18) == False
def test_path_with_prime_sum_yes():
N = 5
M = 6
edges = [(1, ... | [
{
"docstring": "Returns True if n is a prime number else False.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Returns True if there's a path from start to end with prime-weight sum.",
"function_declaration": "def fin... | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import math\nfrom collections import defaultdict, deque\n\ndef is_prime(n):\n \"\"\" Check if a number is prime. \"\"\"\n if n <= 1:\n return ... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00014372",
"row_id": 14372,
"seed_ids": "[12166]"
} | 0.6441 | Code_Contests_14372 | I | [
"is_prime",
"find_prime_path",
"path_with_prime_sum",
"main"
] | 4 | [
[
"find_prime_path",
"is_prime"
],
[
"path_with_prime_sum",
"find_prime_path"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 58df1a7abc17ed424e37ce448e5419c2084e2fd0 | 337e326ef3eb8905150655b5b550a28348250ec8 | |||
v1.0 | instruct | Code_Contests | Code_Contests_14427_I | You are given a list of integers and a series of queries. For each query, you will be given two integers `L` and `R`, representing the left and right indices of a subarray within the list (inclusive). Your task is to find the sum of all the prime numbers in that subarray.
A prime number is a natural number greater tha... | def is_prime(n):
"""
Returns True if n is a prime number, False otherwise.
"""
if n <= 1:
return False
if n <= 3:
return True
if n % 2 == 0 or n % 3 == 0:
return False
i = 5
while i * i <= n:
if n % i == 0 or n % (i + 2) == 0:
return False
... | from solution import is_prime, sum_of_primes_subarray, process_queries
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
def test_sum_of_primes_subarray():
... | [
{
"docstring": "Returns True if n is a prime number, False otherwise.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Returns the sum of prime numbers in the subarray defined by the indices L and R (inclusive).",
"func... | [
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(n):\n \"\"\"\n Returns True if n is a prime number, False otherwise.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00014427",
"row_id": 14427,
"seed_ids": "[7773]"
} | 0.641229 | Code_Contests_14427 | I | [
"is_prime",
"sum_of_primes_subarray",
"process_queries"
] | 3 | [
[
"process_queries",
"sum_of_primes_subarray"
],
[
"sum_of_primes_subarray",
"is_prime"
]
] | 2 | [
"process_queries"
] | false | [] | false | pytest | true | [] | true | 44a850099582b0be8b2d6a26e3555a69d47a2d90 | 8051b13318b73b374c430d9d17d3f5effcd85ec6 | |||
v1.0 | instruct | Code_Contests | Code_Contests_14454_I | Calculate the sum of factorials from 1 to N.
Constraints
* 1 ≤ N ≤ 10
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N
Output
Print the sum of factorials from 1 to N.
Examples
Input
3
Output
9
Input
5
Output
153
Explanation:
For the first exa... | def factorial(n):
"""
Returns the factorial of n.
"""
if n == 0 or n == 1:
return 1
else:
return n * factorial(n - 1)
def sum_of_factorials(N):
"""
Returns the sum of factorials from 1 to N.
"""
return sum(factorial(i) for i in range(1, N + 1)) | from solution import factorial, sum_of_factorials
def test_factorial():
assert factorial(1) == 1
assert factorial(2) == 2
assert factorial(3) == 6
assert factorial(4) == 24
assert factorial(5) == 120
assert factorial(6) == 720
def test_sum_of_factorials():
assert sum_of_factorials(1) == 1
... | [
{
"docstring": "Returns the factorial of n.",
"function_declaration": "def factorial(n):",
"function_name": "factorial",
"parameter_list": "(n)"
},
{
"docstring": "Returns the sum of factorials from 1 to N.",
"function_declaration": "def sum_of_factorials(N):",
"function_name": "sum_... | [
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 sum_of_factorials(N):\n \"\"\"\n Returns the sum of factorials from 1 to N.\n \n Parameters:\n N (int): An integer up to ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00014454",
"row_id": 14454,
"seed_ids": "[390]"
} | 0.570822 | Code_Contests_14454 | I | [
"factorial",
"sum_of_factorials"
] | 2 | [
[
"sum_of_factorials",
"factorial"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | a6ba4bff57a76b6697149bbe29f52d715470c47e | d9deaf8f142e656f31b0b52bbc8f2af243b62ec7 | |||
v1.0 | instruct | Code_Contests | Code_Contests_14480_I | Create a program that checks if a given string is a valid palindrome and then determines the longest palindromic substring within that string.
Input
A single string consisting of lowercase letters.
Output
First, output "YES" if the entire input string is a palindrome, otherwise output "NO". Next, output the longest... | def is_palindrome(s):
"""
Checks if the entire string s is a palindrome.
"""
return s == s[::-1]
def longest_palindromic_substring(s):
"""
Finds the longest palindromic substring in s.
"""
n = len(s)
if n == 0:
return ""
# Initialize the table to store palindrome st... | from solution import check_palindrome_and_longest_substring
def test_palindrome_string():
assert check_palindrome_and_longest_substring("racecar") == ("YES", "racecar")
def test_non_palindrome_string():
assert check_palindrome_and_longest_substring("banana") == ("NO", "anana")
def test_mixed_case():
asse... | [
{
"docstring": "Checks if the entire string s is a palindrome.",
"function_declaration": "def is_palindrome(s):",
"function_name": "is_palindrome",
"parameter_list": "(s)"
},
{
"docstring": "Finds the longest palindromic substring in s.",
"function_declaration": "def longest_palindromic_... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_palindrome(s):\n \"\"\"\n Returns 'YES' if the string s is a palindrome, otherwise returns 'NO'.\n \"\"\"\n return \"YES\" if s == s[::-... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00014480",
"row_id": 14480,
"seed_ids": "[9565]"
} | 0.857595 | Code_Contests_14480 | I | [
"is_palindrome",
"longest_palindromic_substring",
"check_palindrome_and_longest_substring"
] | 3 | [
[
"check_palindrome_and_longest_substring",
"is_palindrome"
],
[
"check_palindrome_and_longest_substring",
"longest_palindromic_substring"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 203778995eb4cf8bf0c75044f8ed48e0179ac06c | 74e96c86ce9140c7c6b950c81758ba920b18fbd8 | |||
v1.0 | instruct | Code_Contests | Code_Contests_14585_I | Given an integer array `arr` of size `n`, your task is to find and print the sum of the elements that are prime numbers. A number is prime if it is greater than 1 and has no divisors other than 1 and itself. Note that 1 is not a prime number.
INPUT:
The first line contains an integer `n`, the size of the array.
The s... | def is_prime(num):
"""
Helper function to check if a number is prime.
"""
if num <= 1:
return False
if num == 2:
return True # 2 is the only even prime number
if num % 2 == 0:
return False # No other even number can be prime
sq_root = int(num**0.5) + 1
for i in ... | from solution import is_prime, sum_of_primes
def test_is_prime():
assert not is_prime(1)
assert is_prime(2)
assert not is_prime(4)
assert is_prime(3)
assert is_prime(5)
assert not is_prime(9)
assert is_prime(23)
def test_sum_of_primes():
assert sum_of_primes([2, 4, 6, 7, 11, 13]) == 33... | [
{
"docstring": "Helper function to check if a number is prime.",
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": "Returns the sum of prime numbers in the array.",
"function_declaration": "def sum_of_primes(arr):",
... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(num):\n \"\"\"\n Check whether a given number is prime.\n \"\"\"\n if num <= 1:\n return False\n if num == 2:\n r... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00014585",
"row_id": 14585,
"seed_ids": "[8296]"
} | 0.671524 | Code_Contests_14585 | I | [
"is_prime",
"sum_of_primes",
"main"
] | 3 | [
[
"sum_of_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 0b6da8235accfdf5c295f34c339fc5eafbd25685 | 43bf58ada13224475307e8dcdd60e18cc5811014 | |||
v1.0 | instruct | Code_Contests | Code_Contests_14605_I | You are tasked with developing a simple card game simulation. The game is played with a standard deck of 52 cards. Each player is dealt a hand of 5 cards. The goal of the game is to determine the player with the highest-ranking hand based on standard poker hand rankings.
### Hand Rankings
1. Royal Flush
2. Straight Fl... | from collections import Counter
# Card order and value for poker rankings
CARD_VALUES = '23456789TJQKA'
CARD_VALUE_DICT = {CARD_VALUES[i]: i for i in range(len(CARD_VALUES))}
def parse_hand(hand):
""" Convert hand into sorted (rank, suit) tuples """
return sorted([(CARD_VALUE_DICT[card[0]], card[1]) for card ... | import pytest
def test_determine_winner():
assert determine_winner("KH QH JH TH AH", "9C 9D 9H 9S 2C") == "Player 1 wins"
assert determine_winner("5H 5D 5C 5S 4D", "3C 3D 3H 3S 2D") == "Player 1 wins"
assert determine_winner("2H 3D 4C 5S 6D", "AH KH QH JH TH") == "Player 2 wins"
assert determine_winner... | [
{
"docstring": "Convert hand into sorted (rank, suit) tuples ",
"function_declaration": "def parse_hand(hand):",
"function_name": "parse_hand",
"parameter_list": "(hand)"
},
{
"docstring": "Check if the ranks form a straight ",
"function_declaration": "def is_straight(ranks):",
"func... | [
1,
0,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from collections import Counter\n\n# Card order and value for poker rankings\nCARD_VALUES = '23456789TJQKA'\nCARD_VALUE_DICT = {CARD_VALUES[i]: i for i in ... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00014605",
"row_id": 14605,
"seed_ids": "[7663]"
} | 0.660673 | Code_Contests_14605 | I | [
"parse_hand",
"is_straight",
"evaluate_hand",
"determine_winner",
"solve"
] | 5 | [
[
"determine_winner",
"evaluate_hand"
],
[
"determine_winner",
"parse_hand"
],
[
"evaluate_hand",
"is_straight"
],
[
"solve",
"determine_winner"
]
] | 4 | [] | false | [] | false | pytest | false | [] | true | 1d9755049195b28fd1a8ba631d6404413bdc4c92 | 9fd58e0f10e38fc77370db1f6aac2c86b5dfc96c | |||
v1.0 | instruct | Code_Contests | Code_Contests_14610_I | You are given a rectangular grid with dimensions n x m. Some cells in the grid are blocked, and others are open. A cell (i,j) in the grid is blocked if `grid[i][j]` is `1` and open if `grid[i][j]` is `0`. You need to find the length of the shortest path from the top-left cell (0,0) to the bottom-right cell (n-1,m-1).
... | from collections import deque
def shortest_path_in_grid(n, m, grid):
"""
Returns the length of the shortest path from the top-left corner to the bottom-right corner in the grid.
If no such path exists, returns -1.
"""
if grid[0][0] == 1 or grid[n-1][m-1] == 1:
return -1
directions = [(... | def test_shortest_path_in_grid():
assert shortest_path_in_grid(3, 3, [[0, 1, 0], [0, 1, 0], [0, 0, 0]]) == 5
assert shortest_path_in_grid(3, 3, [[1, 0, 0], [0, 1, 1], [0, 0, 0]]) == -1
assert shortest_path_in_grid(1, 1, [[0]]) == 1
assert shortest_path_in_grid(2, 2, [[0, 0], [1, 0]]) == 3
assert sho... | [
{
"docstring": "Returns the length of the shortest path from the top-left corner to the bottom-right corner in the grid.\nIf no such path exists, returns -1.",
"function_declaration": "def shortest_path_in_grid(n, m, grid):",
"function_name": "shortest_path_in_grid",
"parameter_list": "(n, m, 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": "from collections import deque\n\ndef shortest_path_in_grid(n, m, grid):\n \"\"\"\n Returns the length of the shortest path from the top-left corner t... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00014610",
"row_id": 14610,
"seed_ids": "[10210]"
} | 0.73771 | Code_Contests_14610 | I | [
"shortest_path_in_grid",
"solve"
] | 2 | [
[
"solve",
"shortest_path_in_grid"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | 9c52e02df8e105d9478825ca9bba64b4b5c5b221 | 3faa8d1e1d353e0af6e1636132c92614b3e898b7 | |||
v1.0 | instruct | Code_Contests | Code_Contests_14678_I | Chris is fascinated by palindrome numbers. A palindrome is a number that reads the same forwards and backwards, such as 121 or 1331. Chris is interested not only in plain palindromes but also in products of two numbers that result in a palindrome.
He wonders about the largest palindromic number that can be obtained by... | def is_palindrome(num):
return str(num) == str(num)[::-1]
def largest_palindromic_product(n):
if n < 1 or n > 6:
return -1
max_num = 10**n - 1
min_num = 10**(n-1)
max_palindrome = -1
for i in range(max_num, min_num - 1, -1):
for j in range(i, min_num - 1, -1):
... | from solution import is_palindrome, largest_palindromic_product
def test_is_palindrome():
assert is_palindrome(121) == True
assert is_palindrome(12321) == True
assert is_palindrome(123) == False
assert is_palindrome(1221) == True
assert is_palindrome(1001) == True
assert is_palindrome(1234) == ... | [
{
"docstring": null,
"function_declaration": "def is_palindrome(num):",
"function_name": "is_palindrome",
"parameter_list": "(num)"
},
{
"docstring": null,
"function_declaration": "def largest_palindromic_product(n):",
"function_name": "largest_palindromic_product",
"parameter_li... | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_palindrome(number):\n \"\"\"\n Check if a number is a palindrome.\n \"\"\"\n return str(number) == str(number)[::-1]\n\ndef largest_pali... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00014678",
"row_id": 14678,
"seed_ids": "[2825]"
} | 0.729793 | Code_Contests_14678 | I | [
"is_palindrome",
"largest_palindromic_product"
] | 2 | [
[
"largest_palindromic_product",
"is_palindrome"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | fc3d33488b745d766f29bef6f0608a98ce7e9a05 | 2bc8774dbeba5c2e8cdd6068129f2e6f50bbecc0 | |||
v1.0 | instruct | Code_Contests | Code_Contests_14680_I | You are given a tree with `n` nodes numbered from 1 to `n`. Each node has a value. You have to answer `q` queries. Each query consists of two integers, `u` and `v` and asks for the maximum value of the nodes in the path from `u` to `v`.
Input
The first line of the input contains an integer `n` (2 ≤ n ≤ 10^5) — the nu... | from collections import defaultdict, deque
import sys
sys.setrecursionlimit(200000)
def preprocess_tree(n, values, edges):
LOG = 17
adj = defaultdict(list)
for a, b in edges:
adj[a].append(b)
adj[b].append(a)
up = [[-1] * (LOG + 1) for _ in range(n + 1)]
max_on_path = [[-1] * (... | from solution import solve
def test_example_case():
n = 5
values = [1, 5, 2, 4, 3]
edges = [(1, 2), (1, 3), (3, 4), (3, 5)]
queries = [(2, 3), (4, 1), (4, 5)]
results = solve(n, values, edges, queries)
expected = [5, 4, 4]
assert results == expected
def test_simple_case():
n = 2
... | [
{
"docstring": null,
"function_declaration": "def preprocess_tree(n, values, edges):",
"function_name": "preprocess_tree",
"parameter_list": "(n, values, edges)"
},
{
"docstring": null,
"function_declaration": "def solve(n, values, edges, queries):",
"function_name": "solve",
"pa... | [
1,
0
] | 1 | medium | 0.5 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from collections import defaultdict, deque\nimport sys\n\nsys.setrecursionlimit(200000)\n\ndef preprocess_tree(n, values, edges):\n LOG = 17 \n\n ad... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00014680",
"row_id": 14680,
"seed_ids": "[7031]"
} | 0.726844 | Code_Contests_14680 | I | [
"preprocess_tree",
"solve"
] | 2 | [
[
"solve",
"preprocess_tree"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | b30a09f704d881181a6e230384e87dfd5653b6d2 | 81405d7f7dde4ce6225851d992b7b848daccb5dc | |||
v1.0 | instruct | Code_Contests | Code_Contests_14728_I | Your task is to convert a given list of non-negative integers into a new list such that every given integer is replaced by its prime factors (listed in ascending order). If the number is prime, it will be included as-is.
Input
The first line contains an integer `n` — the number of integers in the list (1 ≤ n ≤ 100).
... | def prime_factors(n):
"""
Returns a list of prime factors of the given number n.
"""
factors = []
# factor out 2s
while n % 2 == 0:
factors.append(2)
n //= 2
# factor out all odd numbers
for i in range(3, int(n**0.5) + 1, 2):
while n % i == 0:
factors... | from solution import convert_list_to_prime_factors
def test_convert_list_to_prime_factors():
assert convert_list_to_prime_factors([10, 15, 23, 50]) == [2, 5, 3, 5, 23, 2, 5, 5]
assert convert_list_to_prime_factors([4, 17, 8]) == [2, 2, 17, 2, 2, 2]
assert convert_list_to_prime_factors([2, 3, 5, 7]) == [2, ... | [
{
"docstring": "Returns a list of prime factors of the given number n.",
"function_declaration": "def prime_factors(n):",
"function_name": "prime_factors",
"parameter_list": "(n)"
},
{
"docstring": "Converts a list of non-negative integers to a list of their prime factors.",
"function_de... | [
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 prime_factors(n):\n factors = []\n # Check for number of 2s in n\n while n % 2 == 0:\n factors.append(2)\n n = n // 2\n # n m... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00014728",
"row_id": 14728,
"seed_ids": "[8]"
} | 0.656963 | Code_Contests_14728 | I | [
"prime_factors",
"convert_list_to_prime_factors"
] | 2 | [
[
"convert_list_to_prime_factors",
"prime_factors"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | e565ec6ae26df880da11b1a1aa9fa60d9362b7a8 | 0f4ada5620d7f31770c7734e47bdfd7498d4c982 | |||
v1.0 | instruct | Code_Contests | Code_Contests_14774_I | You are given a binary tree with N nodes where each node has a unique value ranging from 1 to N. The binary tree nodes are represented using integer values from 1 to N, and you are also given an array of queries where each query consists of two integers `u` and `v`. For each query, you need to find the lowest common an... | class TreeNode:
def __init__(self, x):
self.val = x
self.left = None
self.right = None
def build_tree(edges, N):
nodes = {i: TreeNode(i) for i in range(1, N + 1)}
for parent, child in edges:
if nodes[parent].left is None:
nodes[parent].left = nodes[child]
... | from solution import lca_multiple_queries
def test_simple_case():
N = 5
edges = [(1, 2), (1, 3), (2, 4), (2, 5)]
queries = [(4, 5), (3, 2), (4, 3)]
result = lca_multiple_queries(N, edges, queries)
assert result == [2, 1, 1]
def test_disparate_nodes():
N = 7
edges = [(1, 2), (1, 3), (2, 4),... | [] | [
1,
0,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "class TreeNode:\n def __init__(self, value):\n self.value = value\n self.parent = None\n self.left = None\n self.right = Non... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00014774",
"row_id": 14774,
"seed_ids": "[184]"
} | 0.571429 | Code_Contests_14774 | I | [
"build_tree",
"find_LCA",
"process_queries",
"lca_multiple_queries"
] | 4 | [
[
"lca_multiple_queries",
"process_queries"
],
[
"process_queries",
"build_tree"
],
[
"process_queries",
"find_LCA"
]
] | 3 | [
"process_queries"
] | false | [
"TreeNode"
] | true | pytest | true | [] | true | 13f92b0be63a41d00f62b88a89e3426cbebbb8e9 | d73a0742cb155ed24f83193819d0da5e7d63619c | |||
v1.0 | instruct | Code_Contests | Code_Contests_14832_I | In a galaxy far far away, there is a strange binary gimmick. You are given an array of n integers. All integers are either 0 or 1. You need to perform exactly one swap in the array (swap two distinct positions), such that the resulting array either has more 1s than 0s, or more 0s than 1s. If the array already has eithe... | def perform_swap(arr):
n = len(arr)
count_1s = arr.count(1)
count_0s = n - count_1s
# If already balanced
if count_1s == count_0s:
for i in range(n):
for j in range(i + 1, n):
arr[i], arr[j] = arr[j], arr[i]
new_count_1s = arr.count(1)
... | from solution import swap_to_unbalance
def test_case_1():
assert swap_to_unbalance(5, [1, 0, 1, 1, 0]) == [1, 1, 0, 1, 0] or [1, 0, 1, 1, 0]
def test_case_2():
assert swap_to_unbalance(3, [1, 1, 1]) == "NO"
def test_case_3():
assert swap_to_unbalance(6, [0, 1, 0, 1, 0, 1]) == "NO"
def test_case_4():
... | [
{
"docstring": null,
"function_declaration": "def perform_swap(arr):",
"function_name": "perform_swap",
"parameter_list": "(arr)"
},
{
"docstring": null,
"function_declaration": "def swap_to_unbalance(n, arr):",
"function_name": "swap_to_unbalance",
"parameter_list": "(n, arr)"
... | [
0,
0,
0,
0,
1
] | 1 | hard | 0.2 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def binary_gimmick(n, arr):\n \"\"\"\n Returns the modified array after performing one swap to achieve either\n more 1s than 0s or more 0s than 1s... | trial_gpt4o_4 | {
"original_instruction": "",
"prompt_id": "00014832",
"row_id": 14832,
"seed_ids": "[5531]"
} | 0.756598 | Code_Contests_14832 | I | [
"perform_swap",
"swap_to_unbalance"
] | 2 | [
[
"swap_to_unbalance",
"perform_swap"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 22d8e41b8513f11fa9c3619cc0a246966ef0c17e | 2b0cac0189b19139a1363c7f8b6d14b36029b5ec | |||
v1.0 | instruct | Code_Contests | Code_Contests_14845_I | You are given an array of n integers where there are some pairs of integers that are special. A pair of integers (x, y) is considered special if x + y is even. Your task is to count the number of such special pairs in the array.
You can swap any two elements of the array k times. Determine the maximum number of speci... | def count_special_pairs(arr):
"""
This function counts the number of special pairs in the array
where a pair (x, y) is special if x + y is even.
"""
even_count = sum(1 for x in arr if x % 2 == 0)
odd_count = len(arr) - even_count
# Special pairs within evens and within odds
return even_... | from solution import max_special_pairs
def test_no_swaps():
assert max_special_pairs(4, 0, [2, 4, 6, 8]) == 6
assert max_special_pairs(5, 0, [1, 3, 5, 7, 9]) == 10
assert max_special_pairs(3, 0, [2, 3, 4]) == 1
def test_with_swaps():
assert max_special_pairs(6, 1, [1, 3, 5, 7, 2, 8]) == 15
assert ... | [
{
"docstring": "This function counts the number of special pairs in the array \nwhere a pair (x, y) is special if x + y is even.",
"function_declaration": "def count_special_pairs(arr):",
"function_name": "count_special_pairs",
"parameter_list": "(arr)"
},
{
"docstring": "This function retur... | [
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 max_special_pairs(n, k, arr):\n # Count the number of even and odd numbers in the array\n num_even = sum(1 for x in arr if x % 2 == 0)\n num_o... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00014845",
"row_id": 14845,
"seed_ids": "[6804]"
} | 0.652562 | Code_Contests_14845 | I | [
"count_special_pairs",
"max_special_pairs"
] | 2 | [
[
"max_special_pairs",
"count_special_pairs"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | ee23ec7c0becd17a3b88c94d2ceed632b6a98d6f | 0b380654a866cb5eb78d37958c32dc60a0efba64 | |||
v1.0 | instruct | Code_Contests | Code_Contests_14898_I | A balanced parenthesis sequence is a string containing only characters '(' and ')' such that the number of opening brackets '(' is equal to the number of closing brackets ')' and for any prefix of the string, the number of opening brackets is at least the number of closing brackets.
Given an integer n, generate all po... | def generate_parenthesis(n):
"""
Generates all possible balanced parenthesis sequences of length 2n.
"""
result = []
def backtrack(s='', left=0, right=0):
if len(s) == 2 * n:
result.append(s)
return
if left < n:
backtrack(s + '(', left + 1, right)
... | from solution import generate_parenthesis, generate_parenthesis_lexicographic
def test_generate_parenthesis():
assert generate_parenthesis(1) == ["()"]
assert generate_parenthesis(2) == ["(())", "()()"]
assert generate_parenthesis(3) == ["((()))", "(()())", "(())()", "()(())", "()()()"]
assert generate... | [
{
"docstring": "Generates all possible balanced parenthesis sequences of length 2n.",
"function_declaration": "def generate_parenthesis(n):",
"function_name": "generate_parenthesis",
"parameter_list": "(n)"
},
{
"docstring": "Generates and prints all possible balanced parenthesis sequences o... | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def generate_parenthesis(n):\n \"\"\"\n Generates all balanced parenthesis sequences of length 2n in lexicographic order.\n n: int, the number of ... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00014898",
"row_id": 14898,
"seed_ids": "[1487]"
} | 0.735523 | Code_Contests_14898 | I | [
"generate_parenthesis",
"generate_parenthesis_lexicographic"
] | 2 | [
[
"generate_parenthesis_lexicographic",
"generate_parenthesis"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | caaeb6052ab3549e40d8cfb5d8128f3b74565b94 | 9f041a89b8fc6cfa4adb5e3623024845c15f7603 | |||
v1.0 | instruct | Code_Contests | Code_Contests_14927_I | Problem Statement
Given a list of words and a list of letters, write a function that returns the list of words that can be formed using the given letters exactly once. Each letter can be used only once in a word. The order of words in the output should be the same as in the input.
Input
The input consists of two lin... | def can_form_word(word, letters):
"""
Check if a word can be formed with the given list of letters exactly once.
"""
letter_count = {}
for letter in letters:
if letter in letter_count:
letter_count[letter] += 1
else:
letter_count[letter] = 1
for char ... | from solution import can_form_word, words_from_letters
def test_can_form_word():
assert can_form_word("dog", ["d", "o", "g"]) == True
assert can_form_word("cat", ["c", "a", "t"]) == True
assert can_form_word("mouse", ["m", "o", "u", "s", "e"]) == True
assert can_form_word("bat", ["b", "a", "t", "x"]) =... | [
{
"docstring": "Check if a word can be formed with the given list of letters exactly once.",
"function_declaration": "def can_form_word(word, letters):",
"function_name": "can_form_word",
"parameter_list": "(word, letters)"
},
{
"docstring": "Returns the list of words that can be formed usin... | [
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_form_word(word, letter_counts):\n for char in word:\n if char not in letter_counts or letter_counts[char] == 0:\n return False... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00014927",
"row_id": 14927,
"seed_ids": "[8845]"
} | 0.656068 | Code_Contests_14927 | I | [
"can_form_word",
"words_from_letters"
] | 2 | [
[
"words_from_letters",
"can_form_word"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 3ac952507f57a45176c7e626a28084b0e1e3244f | 0e6ad8134b7e5c8c74eecfedb5c4af583637ba5d | |||
v1.0 | instruct | Code_Contests | Code_Contests_14955_I | Samantha is hiking in the mountain range and plans to visit several landmark spots there. The mountain range is modeled as a collection of n landmarks connected by m undirected trails, each with a certain length. The length of each trail represents the time (in minutes) it takes to traverse it. Samantha starts her hike... | def tsp(n, m, edges, s):
import itertools
# Initializing adjacency matrix with a large value for non-adjacent nodes
inf = float('inf')
dist = [[inf] * n for _ in range(n)]
for a, b, t in edges:
dist[a-1][b-1] = min(dist[a-1][b-1], t)
dist[b-1][a-1] = min(dist[b-1][a-1], t)
... | def test_minimum_hike_time():
assert minimum_hike_time(4, 5, ["1 2 4", "2 3 3", "3 4 5", "4 1 2", "1 3 6"], 1) == 14
assert minimum_hike_time(3, 3, ["1 2 2", "2 3 2", "3 1 3"], 2) == 7
def test_minimum_hike_time_more_cases():
assert minimum_hike_time(4, 6, ["1 2 10", "1 3 15", "1 4 20", "2 3 35", "2 4 25",... | [
{
"docstring": null,
"function_declaration": "def tsp(n, m, edges, s):",
"function_name": "tsp",
"parameter_list": "(n, m, edges, s)"
},
{
"docstring": null,
"function_declaration": "def minimum_hike_time(n, m, trails, s):",
"function_name": "minimum_hike_time",
"parameter_list":... | [
0,
0,
0,
0,
0,
1,
1,
0,
0
] | 2 | hard | 0.222 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import heapq\n\ndef min_time_to_visit_all_landmarks(n, m, trails, s):\n def prim_mst(adj_list, n):\n visited = [False] * (n + 1)\n min_hea... | trial_gpt4o_7 | {
"original_instruction": "",
"prompt_id": "00014955",
"row_id": 14955,
"seed_ids": "[2772]"
} | 0.720108 | Code_Contests_14955 | I | [
"tsp",
"minimum_hike_time"
] | 2 | [
[
"minimum_hike_time",
"tsp"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | a2127d95cdc2928f041521a2a115feaa0f5568ea | 7a4911fb82f8d97d62ca34b086d856c298afdfa8 | |||
v1.0 | instruct | Code_Contests | Code_Contests_14978_I | ### Problem Description:
Alex loves playing with numbers and has recently discovered the concept of 'Semi-Perfect Numbers'. A number is considered 'Semi-Perfect' if it can be expressed as the sum of some (or all) of its proper divisors. Alex is curious to find out if a given number is a 'Semi-Perfect Number' or not.
Y... | def is_semi_perfect(num):
def proper_divisors(n):
divisors = []
for i in range(1, n // 2 + 1):
if n % i == 0:
divisors.append(i)
return divisors
def can_sum_to_n(divisors, n):
subset_sums = {0}
for d in divisors:
new_sums = sub... | from solution import is_semi_perfect, solve_semi_perfect_numbers
def test_is_semi_perfect():
assert is_semi_perfect(12) == True
assert is_semi_perfect(28) == True
assert is_semi_perfect(15) == False
assert is_semi_perfect(6) == True
assert is_semi_perfect(16) == False
assert is_semi_perfect(20)... | [
{
"docstring": null,
"function_declaration": "def is_semi_perfect(num):",
"function_name": "is_semi_perfect",
"parameter_list": "(num)"
},
{
"docstring": null,
"function_declaration": "def solve_semi_perfect_numbers(T, numbers):",
"function_name": "solve_semi_perfect_numbers",
"p... | [
0,
0,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_semi_perfect(n):\n def get_proper_divisors(num):\n divisors = []\n for i in range(1, num // 2 + 1):\n if num % i == 0:\n... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00014978",
"row_id": 14978,
"seed_ids": "[9374]"
} | 0.693501 | Code_Contests_14978 | I | [
"is_semi_perfect",
"solve_semi_perfect_numbers"
] | 2 | [
[
"solve_semi_perfect_numbers",
"is_semi_perfect"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 09d6b3f2f47575d70345c23f18469337aa61e3e7 | 59a50a80547570097f9ddfa6546d760fde0472f9 | |||
v1.0 | instruct | Code_Contests | Code_Contests_15017_I | Marc loves collecting data. Recently, he started analyzing numerical sequences to determine specific patterns and properties. One property that caught Marc's attention is the "prime sum" of a sequence. The prime sum of a sequence is the summation of all prime numbers present in the sequence.
A prime number is a natura... | import math
def is_prime(n):
if n <= 1:
return False
if n <= 3:
return True
if n % 2 == 0 or n % 3 == 0:
return False
i = 5
while i * i <= n:
if n % i == 0 or n % (i + 2) == 0:
return False
i += 6
return True
def prime_sum(sequence):
retu... | from solution import prime_sum
def test_primes_in_sequence():
assert prime_sum([3, 4, 7, 6, 5, 11]) == 26
def test_only_primes():
assert prime_sum([1, 2, 3, 4, 5]) == 10
def test_no_primes():
assert prime_sum([6, 8, 10]) == 0
def test_large_prime():
assert prime_sum([999983, 1000000]) == 999983
def... | [
{
"docstring": null,
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": null,
"function_declaration": "def prime_sum(sequence):",
"function_name": "prime_sum",
"parameter_list": "(sequence)"
}
] | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import math\n\ndef is_prime(n):\n \"\"\"\n Checks whether a number is prime.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00015017",
"row_id": 15017,
"seed_ids": "[10334]"
} | 0.702447 | Code_Contests_15017 | I | [
"is_prime",
"prime_sum"
] | 2 | [
[
"prime_sum",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | f9b5619ec154ad6c048d33b449851efdcfcdfd89 | 704e3d52857abe3b138098c11453d9f96b6b945a | |||
v1.0 | instruct | Code_Contests | Code_Contests_15028_I | In a faraway land, there's a kingdom with N cities connected by M bidirectional roads. The kingdom is currently at peace and wants to maintain a minimum level of connectivity between its cities. The king has decided that at least one path should exist between any pair of cities. It's your task to determine how many roa... | def find_parent(parents, city):
if parents[city] == city:
return city
parents[city] = find_parent(parents, parents[city])
return parents[city]
def union(parents, rank, u, v):
rootU = find_parent(parents, u)
rootV = find_parent(parents, v)
if rootU != rootV:
if rank[rootU] >... | from solution import additional_roads_needed
def test_sample():
assert additional_roads_needed(4, 2, [(1, 2), (2, 3)]) == 1
def test_single_city():
assert additional_roads_needed(1, 0, []) == 0
def test_fully_connected():
assert additional_roads_needed(3, 3, [(1, 2), (2, 3), (3, 1)]) == 0
def test_disco... | [
{
"docstring": null,
"function_declaration": "def find_parent(parents, city):",
"function_name": "find_parent",
"parameter_list": "(parents, city)"
},
{
"docstring": null,
"function_declaration": "def union(parents, rank, u, v):",
"function_name": "union",
"parameter_list": "(par... | [
1,
0,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def find_parent(parents, city):\n if parents[city] == city:\n return city\n parents[city] = find_parent(parents, parents[city])\n return pa... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00015028",
"row_id": 15028,
"seed_ids": "[2054]"
} | 0.757847 | Code_Contests_15028 | I | [
"find_parent",
"union",
"additional_roads_needed"
] | 3 | [
[
"additional_roads_needed",
"find_parent"
],
[
"additional_roads_needed",
"union"
],
[
"union",
"find_parent"
]
] | 3 | [] | false | [] | false | pytest | true | [] | true | 4ba89741340a43bdc1c73d2137336cbe3c0edc07 | f9b7d981cf3a811992206c857a18d3ed1e4330c3 | |||
v1.0 | instruct | Code_Contests | Code_Contests_15076_I | You have been tasked with implementing a text editor with undo and redo functionalities. The editor supports two types of operations:
1. Insert a character at the end of the current text.
2. Undo the last operation.
3. Redo the last undone operation.
The operations are given as a sequence of commands. Each command is ... | def text_editor(commands):
current_text = []
undo_stack = []
redo_stack = []
for command in commands:
if command.startswith("1"):
_, char = command.split()
current_text.append(char)
undo_stack.append(char)
redo_stack.clear() # Clear redo stac... | def test_process_commands():
assert process_commands(5, ["1 a", "1 b", "2", "3", "1 c"]) == "abc"
assert process_commands(7, ["1 x", "1 y", "1 z", "2", "2", "3", "3"]) == "xyz"
assert process_commands(4, ["1 d", "1 e", "1 f", "2"]) == "de"
assert process_commands(6, ["1 a", "1 b", "2", "1 c", "3", "3"])... | [
{
"docstring": null,
"function_declaration": "def text_editor(commands):",
"function_name": "text_editor",
"parameter_list": "(commands)"
},
{
"docstring": null,
"function_declaration": "def process_commands(n, command_lines):",
"function_name": "process_commands",
"parameter_lis... | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def process_commands(n, commands):\n text = []\n undo_stack = []\n redo_stack = []\n\n for command in commands:\n if command.startswith(... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00015076",
"row_id": 15076,
"seed_ids": "[5654]"
} | 0.590402 | Code_Contests_15076 | I | [
"text_editor",
"process_commands"
] | 2 | [
[
"process_commands",
"text_editor"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | 1d0c6b3be62f3418261b6e428dfe682808c295c2 | c85729310747e93498d016c55c1c3d47af4b32a7 | |||
v1.0 | instruct | Code_Contests | Code_Contests_15108_I | In a faraway land, there is a kingdom where they love circles. The kingdom has exactly N cities, each uniquely represented as a point in a 2D plane. The King of this land decides to connect his cities using the minimum number of circular roads. Each circular road can cover any set of cities such that all cities lie on ... | import math
def distance(p1, p2):
return math.hypot(p2[0] - p1[0], p2[1] - p1[1])
def is_collinear(points):
if len(points) < 3:
return True
(x1, y1), (x2, y2), (x3, y3) = points[:3]
return (y2 - y1) * (x3 - x2) == (y3 - y2) * (x2 - x1)
def min_circles_to_cover(N, points):
# If there are o... | from solution import min_circles_to_cover
def test_single_point():
assert min_circles_to_cover(1, [(1, 1)]) == 1
def test_two_points():
assert min_circles_to_cover(2, [(1, 1), (2, 2)]) == 1
def test_collinear_points():
assert min_circles_to_cover(3, [(1, 1), (2, 2), (3, 3)]) == 1
def test_non_collinear_... | [
{
"docstring": null,
"function_declaration": "def distance(p1, p2):",
"function_name": "distance",
"parameter_list": "(p1, p2)"
},
{
"docstring": null,
"function_declaration": "def is_collinear(points):",
"function_name": "is_collinear",
"parameter_list": "(points)"
},
{
... | [
1,
0,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import math\n\ndef distance(p1, p2):\n return math.hypot(p2[0] - p1[0], p2[1] - p1[1])\n\ndef is_collinear(points):\n if len(points) < 3:\n re... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00015108",
"row_id": 15108,
"seed_ids": "[2896]"
} | 0.6969 | Code_Contests_15108 | I | [
"distance",
"is_collinear",
"min_circles_to_cover"
] | 3 | [
[
"min_circles_to_cover",
"is_collinear"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | e54324a64c682af346471d952b76b04031d67a1b | c3d6ae38a3a6aa6e67b3de69097978b11b6b0fb3 | |||
v1.0 | instruct | Code_Contests | Code_Contests_15136_I | Sakura is a ninja who has to complete her missions stealthily. Each mission requires navigating through fields of sensors that detect her movements. These sensors have circular detection ranges and are placed on a 2D coordinate system.
Each sensor is described by its center coordinates (xi, yi) and its detection radiu... | import math
def is_detected(xi, yi, ri, Ax, Ay, Bx, By):
"""
Check if the line segment from (Ax, Ay) to (Bx, By) intersects with the circle centered at (xi, yi) with radius ri.
"""
# Vector AB
ABx = Bx - Ax
ABy = By - Ay
# Vector AP
APx = xi - Ax
APy = yi - Ay
# Project vector A... | from solution import ninja_mission
def test_sample_input_1():
N = 3
sensors = [(0, 0, 5), (10, 10, 3), (-5, -5, 2)]
Ax, Ay, Bx, By = -20, -20, 20, 20
assert ninja_mission(N, sensors, Ax, Ay, Bx, By) == "NO"
def test_sample_input_2():
N = 2
sensors = [(0, 0, 5), (10, 10, 3)]
Ax, Ay, Bx, By ... | [
{
"docstring": "Check if the line segment from (Ax, Ay) to (Bx, By) intersects with the circle centered at (xi, yi) with radius ri.",
"function_declaration": "def is_detected(xi, yi, ri, Ax, Ay, Bx, By):",
"function_name": "is_detected",
"parameter_list": "(xi, yi, ri, Ax, Ay, Bx, By)"
},
{
... | [
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 math\n\ndef is_point_in_circle(px, py, cx, cy, cr):\n \"\"\"\n Check if a point (px, py) is inside a circle with center (cx, cy) and radius cr... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00015136",
"row_id": 15136,
"seed_ids": "[3329]"
} | 0.673311 | Code_Contests_15136 | I | [
"is_detected",
"can_reach_destination",
"ninja_mission"
] | 3 | [
[
"can_reach_destination",
"is_detected"
],
[
"ninja_mission",
"can_reach_destination"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 8ae3e9d86ae087c920a57bef2bf5f736e39a576e | 4ff9f23a3ec6034af5612c0590dd294401fa2ffd | |||
v1.0 | instruct | Code_Contests | Code_Contests_15156_I | You are tasked with writing a program to help distribute tasks among employees in a way that minimizes the maximum workload any single employee receives.
You are given n tasks, each of which has a specific time requirement t_i (1 ≤ i ≤ n), and k employees available to undertake the tasks. Each task can only be assigne... | def is_possible(tasks, k, max_load):
current_sum = 0
required_workers = 1
for task in tasks:
if current_sum + task > max_load:
required_workers += 1
current_sum = task
if required_workers > k:
return False
else:
current_sum += ... | from solution import minimize_max_workload
def test_minimize_max_workload_example1():
assert minimize_max_workload(5, 2, [4, 3, 7, 8, 9]) == 17
def test_minimize_max_workload_example2():
assert minimize_max_workload(3, 3, [2, 15, 10]) == 15
def test_minimize_max_workload_example3():
assert minimize_max_w... | [
{
"docstring": null,
"function_declaration": "def is_possible(tasks, k, max_load):",
"function_name": "is_possible",
"parameter_list": "(tasks, k, max_load)"
},
{
"docstring": null,
"function_declaration": "def minimize_max_workload(n, k, tasks):",
"function_name": "minimize_max_work... | [
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_possible(tasks, k, max_load):\n current_sum = 0\n required_workers = 1\n\n for task in tasks:\n if current_sum + task > max_load:\n ... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00015156",
"row_id": 15156,
"seed_ids": "[473]"
} | 0.719103 | Code_Contests_15156 | I | [
"is_possible",
"minimize_max_workload"
] | 2 | [
[
"minimize_max_workload",
"is_possible"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 96e17078848f4d276b0702ab55afef91a5eee285 | 46f7edca2e2a64146e53b4913c4962be31f5a763 | |||
v1.0 | instruct | Code_Contests | Code_Contests_15203_I | A palindrome is a word that reads the same backward as forward, such as "madam" or "level". Another similar concept is a "Mirror Palindrome," where the word forms the same word when replaced with their mirrored alphabets. For example:
- 'A' ⇔ 'A'
- 'H' ⇔ 'H'
- 'I' ⇔ 'I'
- 'M' ⇔ 'M'
- 'O' ⇔ 'O'
- 'T' ⇔ 'T'
- 'U' ⇔ 'U'
... | def is_mirror_palindrome(s):
mirror_letters = {'A', 'H', 'I', 'M', 'O', 'T', 'U', 'V', 'W', 'X', 'Y'}
# Check if all characters in the string are mirror letters
if all(char in mirror_letters for char in s):
return s == s[::-1]
return False
def check_mirror_palindrome(s):
"""
Return... | from solution import check_mirror_palindrome
def test_mirror_palindrome_yes():
assert check_mirror_palindrome("AHA") == "YES"
assert check_mirror_palindrome("WOW") == "YES"
assert check_mirror_palindrome("OTTO") == "YES"
assert check_mirror_palindrome("HIH") == "YES"
def test_mirror_palindrome_no():
... | [
{
"docstring": null,
"function_declaration": "def is_mirror_palindrome(s):",
"function_name": "is_mirror_palindrome",
"parameter_list": "(s)"
},
{
"docstring": "Returns \"YES\" if the string s is a mirror palindrome, otherwise returns \"NO\"",
"function_declaration": "def check_mirror_pa... | [
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_mirror_palindrome(s):\n \"\"\"\n Returns \"YES\" if the input string is a \"Mirror Palindrome\", otherwise returns \"NO\".\n \"\"\"\n mi... | trial_gpt4o_3 | {
"original_instruction": "",
"prompt_id": "00015203",
"row_id": 15203,
"seed_ids": "[3112]"
} | 0.73075 | Code_Contests_15203 | I | [
"is_mirror_palindrome",
"check_mirror_palindrome"
] | 2 | [
[
"check_mirror_palindrome",
"is_mirror_palindrome"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | d95c9e54a5a751735e0c8fff70002bd8c0ba135e | 3a34b96289baa99b98a694634afee87841abe85f | |||
v1.0 | instruct | Code_Contests | Code_Contests_15209_I | You are given an array of n unique integers and an integer k. Your task is to find and return the k-th smallest element in the array using the recursive QuickSelect algorithm.
Inputs:
The first line contains two integers n and k (1 ≤ k ≤ n ≤ 1000) — the number of elements in the array and the index of the k-th smalle... | def quickselect(arr, low, high, k):
if low == high: # If the list contains only one element
return arr[low]
pivot_index = partition(arr, low, high)
if pivot_index == k:
return arr[pivot_index]
elif pivot_index < k:
return quickselect(arr, pivot_index + 1, high, k)
... | from solution import find_kth_smallest
def test_find_kth_smallest():
data = [
([7, 10, 4, 3, 20, 15], 6, 2, 4),
([7, 10, 4, 3, 20], 5, 5, 20),
([1], 1, 1, 1),
([2, 1], 2, 1, 1),
([3, 2, 1], 3, 3, 3),
([10, 9, 8, 7, 6, 5, 4, 3, 2, 1], 10, 7, 7),
([7, 10, 4, 3,... | [
{
"docstring": null,
"function_declaration": "def quickselect(arr, low, high, k):",
"function_name": "quickselect",
"parameter_list": "(arr, low, high, k)"
},
{
"docstring": null,
"function_declaration": "def partition(arr, low, high):",
"function_name": "partition",
"parameter_l... | [
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 partition(arr, left, right):\n pivot = arr[right]\n i = left - 1\n for j in range(left, right):\n if arr[j] <= pivot:\n i +=... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00015209",
"row_id": 15209,
"seed_ids": "[11358]"
} | 0.608076 | Code_Contests_15209 | I | [
"quickselect",
"partition",
"find_kth_smallest"
] | 3 | [
[
"find_kth_smallest",
"quickselect"
],
[
"quickselect",
"partition"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 1910de56cd297a586bd35135b763505b6b0b3092 | 5478065f71ed8e68fea224e2cac6272da88626a2 | |||
v1.0 | instruct | Code_Contests | Code_Contests_15238_I | Dušan has also developed a fascination with road networks, modeled as graphs where vertices represent cities and edges represent roads between them. He wants to improve the road network by adding new roads to minimize travel time between cities. Each road has a specific travel time, represented by the edge weight.
Giv... | from heapq import heappop, heappush
def find(parent, i):
if parent[i] == i:
return i
else:
return find(parent, parent[i])
def union(parent, rank, x, y):
root_x = find(parent, x)
root_y = find(parent, y)
if rank[root_x] < rank[root_y]:
parent[root_x] = root_y
elif r... | def test_minimum_cost_road_network():
t = 2
test_cases = [
(4, 2, [(1, 2, 3), (3, 4, 4)]),
(3, 3, [(1, 2, 1), (2, 3, 2), (3, 1, 4)])
]
expected = ["Impossible", 3]
assert minimum_cost_road_network(t, test_cases) == expected
def test_no_existing_roads():
t = 1
test_cases = [
... | [
{
"docstring": null,
"function_declaration": "def find(parent, i):",
"function_name": "find",
"parameter_list": "(parent, i)"
},
{
"docstring": null,
"function_declaration": "def union(parent, rank, x, y):",
"function_name": "union",
"parameter_list": "(parent, rank, x, y)"
},
... | [
0,
0,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import heapq\n\ndef find(parent, i):\n if parent[i] == i:\n return i\n return find(parent, parent[i])\n\ndef union(parent, rank, x, y):\n r... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00015238",
"row_id": 15238,
"seed_ids": "[4714]"
} | 0.755446 | Code_Contests_15238 | I | [
"find",
"union",
"kruskal",
"minimum_cost_road_network"
] | 4 | [
[
"kruskal",
"find"
],
[
"kruskal",
"union"
],
[
"minimum_cost_road_network",
"kruskal"
],
[
"union",
"find"
]
] | 4 | [] | false | [] | false | pytest | false | [] | true | 129f3492e4ba29913f797b461d565810f955ffe5 | 2d825189d512433aac577e9322a045f5cabd7f4c | |||
v1.0 | instruct | Code_Contests | Code_Contests_15254_I | Anna is a fan of word games and loves rearranging letters of words to form meaningful anagrams. She has a collection of words and she wants to determine if one particular word can be rearranged to form another word in her collection.
Your task is to write a program that checks if one word is an anagram of another word... | def are_anagrams(word1, word2):
"""
Helper function to check if two words are anagrams.
"""
return sorted(word1) == sorted(word2)
def check_anagrams(T, test_cases):
results = []
for i in range(T):
W = test_cases[i][0]
N = test_cases[i][1]
words_collection = test_cases[i]... | from solution import are_anagrams, check_anagrams
def test_are_anagrams():
assert are_anagrams("listen", "silent") == True
assert are_anagrams("evil", "vile") == True
assert are_anagrams("apple", "pale") == False
def test_check_anagrams():
assert check_anagrams(2, [
("listen", 3, ["enlist", "s... | [
{
"docstring": "Helper function to check if two words are anagrams.",
"function_declaration": "def are_anagrams(word1, word2):",
"function_name": "are_anagrams",
"parameter_list": "(word1, word2)"
},
{
"docstring": null,
"function_declaration": "def check_anagrams(T, 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": "def is_anagram(word1, word2):\n \"\"\"\n Check if word1 is an anagram of word2.\n \"\"\"\n return sorted(word1) == sorted(word2)\n\ndef check_a... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00015254",
"row_id": 15254,
"seed_ids": "[8955]"
} | 0.66307 | Code_Contests_15254 | I | [
"are_anagrams",
"check_anagrams"
] | 2 | [
[
"check_anagrams",
"are_anagrams"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | bed631b8279131b8ffa59a8082500caf6aa3a041 | d3568905a965fd9fc5d6646303901d6987d84ebd | |||
v1.0 | instruct | Code_Contests | Code_Contests_15299_I | A: Prime Subsequence Sum
problem
Dr. Prime, an esteemed mathematician, is exploring interesting properties of prime numbers within sequences. One of his recent studies involves identifying and analyzing subsequences of prime numbers within a given sequence of integers. Specifically, he is interested in finding the su... | import math
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
... | import pytest
from solution import longest_prime_subsequence_sum
def test_longest_prime_subsequence_sum():
assert longest_prime_subsequence_sum([6, 2, 3, 4, 5, 7, 11, 13]) == 36
assert longest_prime_subsequence_sum([1, 4, 6, 8, 10, 12]) == 0
assert longest_prime_subsequence_sum([2, 3, 5, 6, 7, 11, 13, 17, ... | [
{
"docstring": "Check if a number is prime.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Returns the sum of the longest contiguous subsequence consisting solely of prime numbers.",
"function_declaration": "def longe... | [
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 if n <= 1:\n return False\n for i in range(2, int(n**0.5) + 1):\n if n % i == 0:\n return False\n retu... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00015299",
"row_id": 15299,
"seed_ids": "[3330]"
} | 0.649272 | Code_Contests_15299 | I | [
"is_prime",
"longest_prime_subsequence_sum",
"main"
] | 3 | [
[
"longest_prime_subsequence_sum",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 5943a8b5024b4e13e9b454d4d491810b65bf8a66 | fbb5c6ffb1cddc0c029edd0db45b5596350ea959 | |||
v1.0 | instruct | Code_Contests | Code_Contests_15312_I | There is a strange magical kingdom where the streets are laid out in a grid. The kingdom has n rows and m columns of streets. Each street section has a unique non-negative integer associated with it, representing the amount of magical energy stored in that section. The king wishes to know the sum of magical energy in c... | def preprocess_grid(grid, n, m):
"""
Preprocess the grid to build a prefix sum matrix for efficient query summation.
"""
prefix_sum = [[0] * (m + 1) for _ in range(n + 1)]
for i in range(1, n + 1):
for j in range(1, m + 1):
prefix_sum[i][j] = grid[i-1][j-1] + prefix_sum[i-1]... | def test_handle_queries():
n = 3
m = 3
grid = [
[1, 2, 3],
[4, 5, 6],
[7, 8, 9]
]
queries = [
(1, 1, 2, 2),
(2, 2, 3, 3)
]
expected = [12, 28]
assert handle_queries(n, m, grid, queries) == expected
def test_handle_queries_entire_grid():
n = 4
... | [
{
"docstring": "Preprocess the grid to build a prefix sum matrix for efficient query summation.",
"function_declaration": "def preprocess_grid(grid, n, m):",
"function_name": "preprocess_grid",
"parameter_list": "(grid, n, m)"
},
{
"docstring": "Use the prefix sum matrix to compute the sum f... | [
1,
0,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def preprocess_grid(grid, n, m):\n \"\"\"\n Preprocess the grid to build a prefix sum matrix for efficient query summation.\n \"\"\"\n prefix_s... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00015312",
"row_id": 15312,
"seed_ids": "[6410]"
} | 0.664245 | Code_Contests_15312 | I | [
"preprocess_grid",
"query_sum",
"handle_queries"
] | 3 | [
[
"handle_queries",
"preprocess_grid"
],
[
"handle_queries",
"query_sum"
]
] | 2 | [
"handle_queries"
] | false | [] | false | pytest | false | [] | true | 55b536c25cd07874aaceaa9af6b27f9d37173227 | afc369327ac3a5c8b354dec856a9d069b40ad277 | |||
v1.0 | instruct | Code_Contests | Code_Contests_15362_I | You are an invigilator at a prestigious university and you need to print the seating arrangement for an examination hall. The hall is arranged in a grid of `r` rows and `c` columns, and each student will be given a number `1` to `r*c` (in row-major order). Your task is to generate the seating arrangement for the studen... | def generate_seating_arrangement(r, c):
mtrx = [[0] * c for _ in range(r)]
num = r * c
left, right, top, bottom = 0, c - 1, 0, r - 1
while left <= right and top <= bottom:
for i in range(left, right + 1): # left to right
mtrx[top][i] = num
num -= 1
top += 1
... | import pytest
from solution import generate_seating_arrangement, print_seating_arrangement
def test_3x3():
result = generate_seating_arrangement(3, 3)
expected = [
[9, 8, 7],
[2, 1, 6],
[3, 4, 5]
]
assert result == expected
def test_4x4():
result = generate_seating_arrangem... | [
{
"docstring": null,
"function_declaration": "def generate_seating_arrangement(r, c):",
"function_name": "generate_seating_arrangement",
"parameter_list": "(r, c)"
},
{
"docstring": null,
"function_declaration": "def print_seating_arrangement(r, c):",
"function_name": "print_seating_... | [
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 generate_seating_arrangement(r, c):\n # Initialize the matrix with zeros\n matrix = [[0] * c for _ in range(r)]\n \n num = r * c\n top, ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00015362",
"row_id": 15362,
"seed_ids": "[664]"
} | 0.68811 | Code_Contests_15362 | I | [
"generate_seating_arrangement",
"print_seating_arrangement"
] | 2 | [
[
"print_seating_arrangement",
"generate_seating_arrangement"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 233c4396da771d22dd9a3b38fe4358de36ea8ef7 | 2997578bd71709d7e9a4c8997386f19adfca8a83 | |||
v1.0 | instruct | Code_Contests | Code_Contests_15439_I | Given an undirected graph with `n` nodes and `m` edges, you are to determine the maximum distance between any two nodes in the graph, also known as the diameter of the graph. If the graph is not connected, return `-1`.
Input
The first line contains two integers `n` and `m` (1 ≤ n ≤ 1000, 0 ≤ m ≤ 10000) representing t... | from collections import deque
def bfs_max_distance(graph, start_node, n):
distances = [-1] * n
queue = deque([(start_node, 0)])
distances[start_node] = 0
max_distance = 0
while queue:
node, distance = queue.popleft()
for neighbor in graph[node]:
if distances[neighbo... | from solution import graph_diameter
def test_graph_diameter_example_1():
n = 5
m = 4
edges = [(1, 2), (1, 3), (3, 4), (4, 5)]
assert graph_diameter(n, m, edges) == 4
def test_graph_diameter_example_2():
n = 4
m = 3
edges = [(1, 2), (2, 3), (2, 4)]
assert graph_diameter(n, m, edges) == ... | [
{
"docstring": null,
"function_declaration": "def bfs_max_distance(graph, start_node, n):",
"function_name": "bfs_max_distance",
"parameter_list": "(graph, start_node, n)"
},
{
"docstring": null,
"function_declaration": "def graph_diameter(n, m, edges):",
"function_name": "graph_diam... | [
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 bfs(farthest, graph, n):\n visited = [-1] * (n + 1)\n max_distance = 0\n queue = deque([(farthest, 0)])\n ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00015439",
"row_id": 15439,
"seed_ids": "[8344]"
} | 0.700097 | Code_Contests_15439 | I | [
"bfs_max_distance",
"graph_diameter"
] | 2 | [
[
"graph_diameter",
"bfs_max_distance"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 2a61df4c2e09966395e4b30d98b520ce792850e3 | 5a009a3506c9895fed12a7c0eaccaf525208f6a9 | |||
v1.0 | instruct | Code_Contests | Code_Contests_15459_I | A company wants to implement a new security system for their office building. The building has several entry points and each room inside requires a pin code to unlock. The pin codes for each room are generated based on specific rules to ensure maximum security.
The rules to generate a pin code for each room are:
1. Ea... | from typing import List, Union
def is_valid_pin(pin: str) -> bool:
# Checks if pin is a 4-digit number with all unique digits and not a palindrome
if len(pin) != 4 or len(set(pin)) != 4:
return False
return pin != pin[::-1]
def generate_pin_codes(n: int) -> Union[str, List[str]]:
if n > 5040:
... | def test_generate_pin_codes_min_value():
result = generate_pin_codes(1)
assert isinstance(result, list)
assert len(result) == 1
assert len(result[0]) == 4
assert len(set(result[0])) == 4
assert result[0] != result[0][::-1]
def test_generate_pin_codes_sample_value():
result = generate_pin_co... | [
{
"docstring": null,
"function_declaration": "def is_valid_pin(pin):",
"function_name": "is_valid_pin",
"parameter_list": "(pin)"
},
{
"docstring": null,
"function_declaration": "def generate_pin_codes(n):",
"function_name": "generate_pin_codes",
"parameter_list": "(n)"
}
] | [
1,
0
] | 1 | medium | 0.5 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from typing import List, Union\n\ndef is_valid_pin(pin: str) -> bool:\n # Checks if pin is a 4-digit number with all unique digits and not a palindrome\... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00015459",
"row_id": 15459,
"seed_ids": "[2300]"
} | 0.507749 | Code_Contests_15459 | I | [
"is_valid_pin",
"generate_pin_codes"
] | 2 | [
[
"generate_pin_codes",
"is_valid_pin"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | fddc3a5128edcf13861d8c6f15dee3e2d0f20f3e | 5e5dc42870dde1b45457a9120a2e533f41ec0494 | |||
v1.0 | instruct | Code_Contests | Code_Contests_15493_I | You are given a long string containing various characters. Your task is to find all the distinct permutations of the characters in the string that are palindromes.
A palindrome is a string that reads the same backward as forward.
Constraints:
- The input string will consist of only lowercase English letters ('a' to ... | from itertools import permutations
def is_palindrome(s):
return s == s[::-1]
def palindrome_permutations(s):
"""
Returns all distinct palindromic permutations of the input string.
If no such permutations exist, returns ["None"].
"""
unique_permutations = set(permutations(s))
palindromes = ... | from solution import palindrome_permutations
def test_example1():
assert palindrome_permutations("aabb") == ["abba", "baab"]
def test_example2():
assert palindrome_permutations("abc") == ["None"]
def test_single_character():
assert palindrome_permutations("a") == ["a"]
def test_two_same_characters():
... | [
{
"docstring": null,
"function_declaration": "def is_palindrome(s):",
"function_name": "is_palindrome",
"parameter_list": "(s)"
},
{
"docstring": "Returns all distinct palindromic permutations of the input string.\nIf no such permutations exist, returns [\"None\"].",
"function_declaratio... | [
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 itertools import permutations\nfrom collections import Counter\n\ndef can_form_palindrome(s):\n \"\"\"\n Helper function to determine if a strin... | trial_gpt4o_3 | {
"original_instruction": "",
"prompt_id": "00015493",
"row_id": 15493,
"seed_ids": "[8537]"
} | 0.761082 | Code_Contests_15493 | I | [
"is_palindrome",
"palindrome_permutations"
] | 2 | [
[
"palindrome_permutations",
"is_palindrome"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | a2e67eb8fec1afbddceed4bfaee873ef51c12f7d | 4b27af4ea46eadfb208c1b14bde4c87734bebe2b | |||
v1.0 | instruct | Code_Contests | Code_Contests_15536_I | You are given a grid with n rows and m columns filled with binary digits (0s and 1s). Your task is to find the maximum size of a square subgrid consisting only of 1s.
Input
The first line contains two integers n and m (1 ≤ n, m ≤ 100) — the number of rows and columns in the grid.
Each of the next n lines contains exa... | def largest_square_subgrid(grid, n, m):
if n == 0 or m == 0:
return 0
# Create a DP table to store the size of the largest square subgrid ending at (i, j)
dp = [[0] * m for _ in range(n)]
max_side_length = 0
for i in range(n):
for j in range(m):
if grid[i][j] == '1':
... | from solution import find_largest_square
def test_sample_input():
n = 5
m = 6
grid = [
"101001",
"111111",
"111111",
"011111",
"011111"
]
assert find_largest_square(n, m, grid) == 4
def test_no_ones():
n = 3
m = 3
grid = [
"000",
... | [
{
"docstring": null,
"function_declaration": "def largest_square_subgrid(grid, n, m):",
"function_name": "largest_square_subgrid",
"parameter_list": "(grid, n, m)"
},
{
"docstring": null,
"function_declaration": "def find_largest_square(n, m, input_grid):",
"function_name": "find_lar... | [
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 largest_square_subgrid(grid):\n \"\"\"\n Finds the size of the largest square subgrid consisting only of 1s.\n \n :param grid: List of stri... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00015536",
"row_id": 15536,
"seed_ids": "[11513]"
} | 0.677864 | Code_Contests_15536 | I | [
"largest_square_subgrid",
"find_largest_square"
] | 2 | [
[
"find_largest_square",
"largest_square_subgrid"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 5fdb8b248409e4efb45d8bf1b2812312a8810131 | 79250235d53947994c661241b1407e7b384043da | |||
v1.0 | instruct | Code_Contests | Code_Contests_15559_I | You are given an array of N integers A[1], A[2], ..., A[N]. You need to perform M update and retrieve operations. Each operation is one of the following types:
1. Update: "1 x v" - Update the value of A[x] to v.
2. Retrieve: "2 L R" - Retrieve the product of the elements in the subarray from index L to index R, inclus... | MOD = 1_000_000_007
def update(arr, index, value):
arr[index - 1] = value
def retrieve(arr, L, R):
result = 1
for i in range(L-1, R):
result = (result * arr[i]) % MOD
return result
def process_operations(N, M, arr, operations):
result = []
for op in operations:
parts = op.spli... | from solution import process_operations
def test_sample_input():
N = 5
M = 3
arr = [2, 3, 7, 5, 6]
operations = ["2 2 4", "1 3 4", "2 2 4"]
expected_output = [105, 60]
assert process_operations(N, M, arr, operations) == expected_output
def test_all_updates():
N = 3
M = 3
arr = [1, ... | [
{
"docstring": null,
"function_declaration": "def update(arr, index, value):",
"function_name": "update",
"parameter_list": "(arr, index, value)"
},
{
"docstring": null,
"function_declaration": "def retrieve(arr, L, R):",
"function_name": "retrieve",
"parameter_list": "(arr, L, R... | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "MOD = 1000000007\n\ndef update(arr, idx, val):\n arr[idx-1] = val\n\ndef retrieve(arr, L, R):\n product = 1\n for i in range(L-1, R):\n pro... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00015559",
"row_id": 15559,
"seed_ids": "[9760]"
} | 0.692243 | Code_Contests_15559 | I | [
"update",
"retrieve",
"process_operations"
] | 3 | [
[
"process_operations",
"retrieve"
],
[
"process_operations",
"update"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 7178aa9c839a02a97263d60538c7605d9893d1c8 | c1eaacb7d88571c13039eb3903a6dc821b716236 | |||
v1.0 | instruct | Code_Contests | Code_Contests_15570_I | In a distant galaxy, payloads are delivered via a series of relay stations. Each station has a unique ID, and the routes between the stations are represented as a network of directed edges with varying transmission times.
A space delivery company wants to analyze the transmission times across this network to ensure ti... | import heapq
def update_route(graph, u, v, t):
"""
Updates the transmission time in the graph
"""
graph[u][v] = t
def shortest_time(graph, n, u, v):
"""
Calculates the shortest propagation time between u and v using Dijkstra's algorithm
"""
distances = {node: float('inf') for node in r... | from solution import update_route, shortest_time
def test_update_route():
graph = {1: {2: 10}, 2: {}, 3: {}}
update_route(graph, 1, 2, 15)
update_route(graph, 2, 3, 20)
assert graph[1][2] == 15
assert graph[2][3] == 20
def test_shortest_time():
graph = {1: {2: 10}, 2: {3: 15}, 3: {4: 20},... | [
{
"docstring": "Updates the transmission time in the graph",
"function_declaration": "def update_route(graph, u, v, t):",
"function_name": "update_route",
"parameter_list": "(graph, u, v, t)"
},
{
"docstring": "Calculates the shortest propagation time between u and v using Dijkstra's algorit... | [
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 heapq\n\ndef update_route(graph, u, v, t):\n graph[u][v] = t\n\ndef shortest_path(graph, start, end, n):\n distances = {i: float('inf') for i ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00015570",
"row_id": 15570,
"seed_ids": "[8279]"
} | 0.682219 | Code_Contests_15570 | I | [
"update_route",
"shortest_time",
"solve"
] | 3 | [
[
"solve",
"shortest_time"
],
[
"solve",
"update_route"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 3eda2f2e7da14fccd40510d5692e29a687bac634 | a4b1971fa3d33e4dc31b46022a34e66e7810eb00 | |||
v1.0 | instruct | Code_Contests | Code_Contests_15650_I | You have N unique items and a box that can hold up to a maximum capacity of W units. Each item has a weight and a value. Your task is to determine the maximum total value of items you can put into the box without exceeding the weight limit.
Constraints
* 1 ≤ N ≤ 1000
* 1 ≤ W ≤ 10000
* 1 ≤ weight_i ≤ 1000
* 1 ≤ value_... | def knapsack(N, W, items):
"""
Returns the maximum total value of items that can be put into the box
with capacity W using the given items with their weights and values.
"""
# Initialize DP table
dp = [[0] * (W + 1) for _ in range(N + 1)]
for i in range(1, N + 1):
weight, value... | from solution import knapsack
def test_knapsack_example_1():
assert knapsack(3, 50, [(10, 60), (20, 100), (30, 120)]) == 220
def test_knapsack_example_2():
assert knapsack(4, 10, [(5, 10), (4, 40), (6, 30), (3, 50)]) == 90
def test_knapsack_edge_case_1():
assert knapsack(1, 5, [(10, 60)]) == 0
def test_... | [
{
"docstring": "Returns the maximum total value of items that can be put into the box \nwith capacity W using the given items with their weights and values.",
"function_declaration": "def knapsack(N, W, items):",
"function_name": "knapsack",
"parameter_list": "(N, W, items)"
},
{
"docstring"... | [
1,
0,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def knapsack_max_value(N, W, items):\n \"\"\"\n Returns the maximum total value of items that can be put into the box\n without exceeding the weig... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00015650",
"row_id": 15650,
"seed_ids": "[8826]"
} | 0.756396 | Code_Contests_15650 | I | [
"knapsack",
"knapsack_from_input"
] | 2 | [
[
"knapsack_from_input",
"knapsack"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 1c947d02ffa343f6ec8194498315b4d1005c7274 | 7f9fbcbb2a07a20e6ce1178c9dd649db14578df7 | |||
v1.0 | instruct | Code_Contests | Code_Contests_15673_I | You are given an array of `n` integers, and your task is to perform `m` operations on this array to transform it into the target array. In one operation, you can select any subarray (contiguous subarray) and increment every element of that subarray by 1.
For example, let the initial array be `[1, 2, 3, 4]`. If we choo... | def can_transform(initial, target):
n = len(initial)
ops = []
# Finding the difference between each element
diff = [target[i] - initial[i] for i in range(n)]
# If there's any negative difference, it's impossible to transform
if any(d < 0 for d in diff):
return "NO", []
... | def test_no_transformation_needed():
assert transform_array(4, [1, 2, 3, 4], [1, 2, 3, 4]) == "YES\n0"
def test_transform_example_1():
assert transform_array(4, [1, 2, 3, 4], [3, 4, 5, 6]) == "YES\n2\n1 4\n1 4"
def test_transform_impossible():
assert transform_array(3, [1, 2, 3], [3, 2, 1]) == "NO"
def t... | [
{
"docstring": null,
"function_declaration": "def can_transform(initial, target):",
"function_name": "can_transform",
"parameter_list": "(initial, target)"
},
{
"docstring": null,
"function_declaration": "def transform_array(n, initial, target):",
"function_name": "transform_array",
... | [
0,
0,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def can_transform(initial, target):\n \"\"\"\n Determines if it is possible to transform the initial array into the target array\n using the speci... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00015673",
"row_id": 15673,
"seed_ids": "[3557]"
} | 0.763683 | Code_Contests_15673 | I | [
"can_transform",
"transform_array"
] | 2 | [
[
"transform_array",
"can_transform"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | 46ddef2110246c5978938f98748deeef8c7949b9 | 3ef7f49a8bd621e1c8510c2c1331937f6f23948f | |||
v1.0 | instruct | Code_Contests | Code_Contests_15690_I | Write a program to read information about a rooted n-ary tree and print the following details for each node u of the tree:
* node ID of u
* parent of u
* number of children of u
* depth of u
* height of u
* node type (root, internal node or leaf)
In an n-ary tree, each node can have zero or more children.
The depth ... | class TreeNode:
def __init__(self, node_id, parent_id=-1):
self.node_id = node_id
self.parent_id = parent_id
self.children = []
self.depth = 0
self.height = 0
def calculate_depth(node, depth):
node.depth = depth
for child in node.children:
calculate_depth(chi... | import pytest
from solution import TreeNode, calculate_depth, calculate_height, classify_nodes, create_tree, tree_info
def test_tree_info_basic():
n = 9
node_info = [
[0, 3, 1, 4, 5],
[1, 2, 2, 3],
[2, 0],
[3, 0],
[4, 0],
[5, 2, 6, 7],
[6, 0],
[7... | [] | [
1,
0,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "class Node:\n def __init__(self, id):\n self.id = id\n self.parent = None\n self.children = []\n\ndef calculate_depth(node, depth=0... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00015690",
"row_id": 15690,
"seed_ids": "[8641]"
} | 0.656014 | Code_Contests_15690 | I | [
"calculate_depth",
"calculate_height",
"classify_nodes",
"create_tree",
"tree_info"
] | 5 | [
[
"tree_info",
"calculate_depth"
],
[
"tree_info",
"calculate_height"
],
[
"tree_info",
"classify_nodes"
],
[
"tree_info",
"create_tree"
]
] | 4 | [] | false | [
"TreeNode"
] | true | pytest | true | [] | true | aeefb0d31463c7f6b3e5e7bb04412eeb7cdd78fc | 4742414744967432f536041f7034034aeff84327 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.