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_9430_I | You are given an m x n grid representing a maze. Each cell in the grid is either an open space 'O' or a wall 'X'. The goal is to determine if there's a path from the top-left corner to the bottom-right corner of the grid, only moving up, down, left, or right through open spaces.
Input
The input starts with a single i... | def is_path_exist(grid):
def dfs(x, y):
if x < 0 or x >= m or y < 0 or y >= n or grid[x][y] == 'X' or visited[x][y]:
return False
if x == m - 1 and y == n - 1:
return True
visited[x][y] = True
# Move in four possible directions: down, up, rig... | import pytest
from solution import main
def test_example_case():
input_data = "3\n3 3\nOXO\nOOX\nXOX\n4 4\nOOOO\nXXOX\nXXOX\nOOOX\n2 2\nOX\nXO\n"
expected_output = "NO\nYES\nNO\n"
main(input_data) | [
{
"docstring": null,
"function_declaration": "def is_path_exist(grid):",
"function_name": "is_path_exist",
"parameter_list": "(grid)"
},
{
"docstring": null,
"function_declaration": "def solve(mazes):",
"function_name": "solve",
"parameter_list": "(mazes)"
},
{
"docstring... | [
0,
0,
0,
0,
0,
1,
0,
0,
0,
0
] | 1 | hard | 0.1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_path_exist(maze):\n \"\"\"\n Returns 'YES' if there's a path from the top-left to the bottom-right\n corner of the maze. Otherwise returns ... | trial_gpt4o_5 | {
"original_instruction": "",
"prompt_id": "00009430",
"row_id": 9430,
"seed_ids": "[2628]"
} | 0.697819 | Code_Contests_9430 | I | [
"is_path_exist",
"solve",
"process_input",
"main"
] | 4 | [
[
"solve",
"is_path_exist"
]
] | 1 | [
"process_input"
] | false | [] | false | pytest | true | [] | true | a4fc9549d011852a6b56e8d0b95473125f554841 | 602b788e7c669a693b4b38d26fdeec90d6c937f8 | |||
v1.0 | instruct | Code_Contests | Code_Contests_9433_I | A scientist discovered a new pattern in a specific sequence of numbers known as Fibonacci Primes. A Fibonacci Prime is a Fibonacci number that is also a prime number. The Fibonacci sequence is a series of numbers in which each number is the sum of the two preceding ones, usually starting with 0 and 1. That is, the sequ... | def is_prime(num):
"""
Check if a number is a prime number.
"""
if num <= 1:
return False
if num <= 3:
return True
if num % 2 == 0 or num % 3 == 0:
return False
i = 5
while i * i <= num:
if num % i == 0 or num % (i + 2) == 0:
return False
... | from solution import find_fibonacci_primes
def test_find_fibonacci_primes_1():
assert find_fibonacci_primes(1) == "2"
def test_find_fibonacci_primes_3():
assert find_fibonacci_primes(3) == "2 3 5"
def test_find_fibonacci_primes_5():
assert find_fibonacci_primes(5) == "2 3 5 13 89"
def test_find_fibonacc... | [
{
"docstring": "Check if a number is a prime number.",
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": "Generate the first N Fibonacci Primes.",
"function_declaration": "def generate_fibonacci_primes(n):",
"functi... | [
1,
1
] | 2 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(num):\n \"\"\"Returns True if num is prime, otherwise False.\"\"\"\n if num <= 1:\n return False\n if num <= 3:\n retur... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00009433",
"row_id": 9433,
"seed_ids": "[7697]"
} | 0.786946 | Code_Contests_9433 | I | [
"is_prime",
"generate_fibonacci_primes",
"find_fibonacci_primes"
] | 3 | [
[
"find_fibonacci_primes",
"generate_fibonacci_primes"
],
[
"generate_fibonacci_primes",
"is_prime"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | c9d6c419d6a3cf173344a1d28fad938ec29a3fd5 | 8280beb887b9cbfd54125eefbc892be30deec691 | |||
v1.0 | instruct | Code_Contests | Code_Contests_9521_I | Design a program that identifies the largest rectangular block of '1's in a binary matrix. Each cell in the matrix contains either '0' or '1'. The largest rectangular block is defined by the maximal area rectangle containing only '1's.
Input:
The first line contains an integer T, the number of test cases. Each test ca... | def max_histogram_area(heights):
stack = []
max_area = 0
index = 0
while index < len(heights):
if not stack or heights[stack[-1]] <= heights[index]:
stack.append(index)
index += 1
else:
top_of_stack = stack.pop()
area = (heights[top_of_sta... | from solution import find_largest_rectangle
def test_sample_input():
input_data = """2
4 4
0 1 1 0
1 1 1 1
1 1 1 0
1 1 0 0
3 3
1 0 1
1 1 1
... | [
{
"docstring": null,
"function_declaration": "def max_histogram_area(heights):",
"function_name": "max_histogram_area",
"parameter_list": "(heights)"
},
{
"docstring": null,
"function_declaration": "def max_rectangle_area(matrix):",
"function_name": "max_rectangle_area",
"paramet... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def max_histogram_area(heights):\n stack = []\n max_area = 0\n index = 0\n\n while index < len(heights):\n if not stack or heights[stack... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00009521",
"row_id": 9521,
"seed_ids": "[5803]"
} | 0.696106 | Code_Contests_9521 | I | [
"max_histogram_area",
"max_rectangle_area",
"find_largest_rectangle",
"parse_input"
] | 4 | [
[
"find_largest_rectangle",
"max_rectangle_area"
],
[
"max_rectangle_area",
"max_histogram_area"
]
] | 2 | [
"parse_input"
] | false | [] | false | pytest | true | [] | true | 386a34fd19a004d50dc07ea8107d0d8031b9ec55 | 2ed20e139113e63aabfe360f35cae588257837c3 | |||
v1.0 | instruct | Code_Contests | Code_Contests_9588_I | In the Kingdom of Quaria, there are n cities connected by m bidirectional roads. Each road connects two different cities and has an associated travel cost.
The king of Quaria is concerned about the road network's robustness and the ability to traverse between cities under budget constraints. He decided to consult with... | import heapq
def dijkstra(graph, start, n):
"""
Use Dijkstra's algorithm to find the shortest paths from start to all other nodes.
"""
distances = {node: float('inf') for node in range(1, n + 1)}
distances[start] = 0
priority_queue = [(0, start)]
while priority_queue:
current_d... | from solution import can_travel_within_budget
def test_example_case():
n = 4
m = 4
q = 3
roads = [
(1, 2, 5),
(2, 3, 2),
(3, 4, 8),
(1, 3, 10)
]
queries = [
(1, 4, 15),
(1, 4, 10),
(2, 4, 10)
]
result = can_travel_within_budget(n, ... | [
{
"docstring": "Use Dijkstra's algorithm to find the shortest paths from start to all other nodes.",
"function_declaration": "def dijkstra(graph, start, n):",
"function_name": "dijkstra",
"parameter_list": "(graph, start, n)"
},
{
"docstring": "Determines if it's possible to travel from city... | [
0,
0,
0,
0,
1,
1,
0,
0,
1
] | 3 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import heapq\nimport sys\n\ndef dijkstra(n, edges, start):\n graph = [[] for _ in range(n + 1)]\n for u, v, w in edges:\n graph[u].append((w, ... | trial_gpt4o_9 | {
"original_instruction": "",
"prompt_id": "00009588",
"row_id": 9588,
"seed_ids": "[5154]"
} | 0.794447 | Code_Contests_9588 | I | [
"dijkstra",
"can_travel_within_budget"
] | 2 | [
[
"can_travel_within_budget",
"dijkstra"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 563a417b0ca4e5ecf04e7e3d6f5f8afa37d6feef | 9280038b0bac7e624e8ccca4aa48bd32fcc46c6d | |||
v1.0 | instruct | Code_Contests | Code_Contests_9676_I | You are given a tree with `n` nodes, rooted at node 1. Each node i has a value `vi`. You are asked to process `q` queries on this tree. Each query can be of three types:
1. Update the value of a node `u` to `x`.
2. Find the sum of values in the subtree rooted at a node `u`.
3. Find the smallest value in the subtree roo... | class TreeNode:
def __init__(self, value):
self.value = value
self.children = []
def update_node_value(tree, node_id, new_value):
tree[node_id].value = new_value
def build_tree(n, node_values, edges):
nodes = {i: TreeNode(node_values[i-1]) for i in range(1, n+1)}
for u, v in edges... | import pytest
from solution import process_queries
def test_process_queries():
n, q = 5, 5
node_values = [1, 2, 3, 4, 5]
edges = [(1, 2), (1, 3), (2, 4), (2, 5)]
queries = [
[2, 1, 0],
[1, 2, 10],
[2, 2, 0],
[3, 2, 0],
[3, 3, 0]
]
expected_output = [... | [] | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "class Tree:\n def __init__(self, n, values):\n self.n = n\n self.values = values\n self.tree = [[] for _ in range(n + 1)]\n ... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00009676",
"row_id": 9676,
"seed_ids": "[12105]"
} | 0.707199 | Code_Contests_9676 | I | [
"update_node_value",
"build_tree",
"subtree_sum",
"subtree_min",
"process_queries"
] | 5 | [
[
"process_queries",
"build_tree"
],
[
"process_queries",
"subtree_min"
],
[
"process_queries",
"subtree_sum"
],
[
"process_queries",
"update_node_value"
]
] | 4 | [
"process_queries"
] | false | [
"TreeNode"
] | true | pytest | true | [] | true | d6f81a4fc50e05fe0c2bc2ce53ff283b76506287 | 13908904a4f31872489d4df961c7b32104e99625 | |||
v1.0 | instruct | Code_Contests | Code_Contests_9722_I | Given a positive integer `n`, determine whether it is a super prime. A super prime is a prime number that occupies the prime position in the list of prime numbers. For example, 5 is the third prime number and 3 is also a prime, so 5 is a super prime.
Input
The single line of input contains an integer n (1 ≤ n ≤ 105).... | def is_prime(num):
if num < 2:
return False
for i in range(2, int(num ** 0.5) + 1):
if num % i == 0:
return False
return True
def generate_primes_up_to(n):
primes = []
candidate = 2
while len(primes) < n:
if is_prime(candidate):
primes.append(cand... | from solution import is_super_prime
def test_is_super_prime_case1():
assert is_super_prime(5) == "YES"
def test_is_super_prime_case2():
assert is_super_prime(12) == "NO"
def test_is_super_prime_first_few_primes():
assert is_super_prime(2) == "NO" # 2 is the 1st prime, 1 is not a prime
assert is_supe... | [
{
"docstring": null,
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": null,
"function_declaration": "def generate_primes_up_to(n):",
"function_name": "generate_primes_up_to",
"parameter_list": "(n)"
},
{
... | [
1,
0,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(num):\n \"\"\"\n Returns True if the given num is a prime number, otherwise False.\n \"\"\"\n if num <= 1:\n return False\n... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00009722",
"row_id": 9722,
"seed_ids": "[1099]"
} | 0.698885 | Code_Contests_9722 | I | [
"is_prime",
"generate_primes_up_to",
"is_super_prime"
] | 3 | [
[
"generate_primes_up_to",
"is_prime"
],
[
"is_super_prime",
"generate_primes_up_to"
],
[
"is_super_prime",
"is_prime"
]
] | 3 | [] | false | [] | false | pytest | true | [] | true | 3776001c880fc544ff776d28e364d390390408c5 | 7fc16f2c580cad8a6f281ca0ad8e55e2cbbad231 | |||
v1.0 | instruct | Code_Contests | Code_Contests_9735_I | Problem Statement
You have been assigned the task of creating an optimal delivery route system for a delivery company. The goal is to minimize the total delivery time for a given set of orders, where each order must be delivered exactly once. The delivery starts from a central warehouse located at the origin (0,0) and... | import itertools
def manhattan_distance(x1, y1, x2, y2):
return abs(x1 - x2) + abs(y1 - y2)
def optimal_delivery_route(n, locations):
min_distance = float('inf')
# Generate all permutations of the delivery locations
for perm in itertools.permutations(locations):
current_distance = 0
... | from solution import manhattan_distance, optimal_delivery_route, parse_input
def test_manhattan_distance():
assert manhattan_distance(0, 0, 1, 2) == 3
assert manhattan_distance(1, 2, 3, 4) == 4
assert manhattan_distance(3, 4, -1, -2) == 10
def test_optimal_delivery_route_1():
n, locations = parse_inpu... | [
{
"docstring": null,
"function_declaration": "def manhattan_distance(x1, y1, x2, y2):",
"function_name": "manhattan_distance",
"parameter_list": "(x1, y1, x2, y2)"
},
{
"docstring": null,
"function_declaration": "def optimal_delivery_route(n, locations):",
"function_name": "optimal_d... | [
1,
0
] | 1 | medium | 0.5 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import itertools\n\ndef manhattan_distance(x1, y1, x2, y2):\n return abs(x1 - x2) + abs(y1 - y2)\n\ndef optimal_delivery_route(n, locations):\n min_d... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00009735",
"row_id": 9735,
"seed_ids": "[4580]"
} | 0.72962 | Code_Contests_9735 | I | [
"manhattan_distance",
"optimal_delivery_route",
"parse_input"
] | 3 | [
[
"optimal_delivery_route",
"manhattan_distance"
]
] | 1 | [
"parse_input"
] | false | [] | false | pytest | true | [] | true | 878d20ac6ba935e91f3eddb5a02674c2e0fde6a2 | 295e23539d4dd0c1c3772433a1634d98bfc0f2f5 | |||
v1.0 | instruct | Code_Contests | Code_Contests_9744_I | There is a kingdom with several cities, and each city is connected to other cities by bidirectional roads. Each road has a certain length. The King wants to find the shortest path from one specified city to another specified city.
Given the number of cities, the number of roads, and the connectivity information of eac... | import heapq
def dijkstra(n, edges, start, dest):
graph = {i: [] for i in range(1, n+1)}
for u, v, w in edges:
graph[u].append((w, v))
graph[v].append((w, u))
distance = {i: float('inf') for i in range(1, n+1)}
distance[start] = 0
priority_queue = [(0, start)]
while pr... | from solution import shortest_path
def test_shortest_path1():
assert shortest_path(4, 4, 3, [(1, 2, 4), (2, 3, 1), (1, 3, 7), (3, 4, 3)], 1) == 5
def test_shortest_path2():
assert shortest_path(4, 2, 4, [(1, 2, 4), (2, 3, 1)], 1) == -1
def test_shortest_path3():
assert shortest_path(3, 3, 3, [(1, 2, 2), ... | [
{
"docstring": null,
"function_declaration": "def dijkstra(n, edges, start, dest):",
"function_name": "dijkstra",
"parameter_list": "(n, edges, start, dest)"
},
{
"docstring": null,
"function_declaration": "def shortest_path(n, m, k, roads, s):",
"function_name": "shortest_path",
... | [
0,
1,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import heapq\nimport sys\n\ndef dijkstra(n, m, k, roads, start):\n graph = {i: [] for i in range(1, n+1)}\n for u, v, w in roads:\n graph[u].a... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00009744",
"row_id": 9744,
"seed_ids": "[12759]"
} | 0.743433 | Code_Contests_9744 | I | [
"dijkstra",
"shortest_path"
] | 2 | [
[
"shortest_path",
"dijkstra"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 1a58d69734c9f50b079818c8eb61de499c7c3f12 | 355d36f3a8dec95cf221ad56b28a1e3c7689f8a8 | |||
v1.0 | instruct | Code_Contests | Code_Contests_9777_I | Peter loves working with grids. He recently came across a problem where he needs to create a specific path in an N x N grid. Each cell in the grid has a number, starting from 1 at the top-left corner and increasing row-wise. That means the first cell of the first row will be 1, the second cell will be 2, and so on with... | def create_path(N):
"""
Creates a sequence of cell numbers in an N x N grid
from the top-left corner to the bottom-right corner
visiting each cell exactly once.
"""
path = []
top, left, bottom, right = 0, 0, N-1, N-1
direction = 'right'
while top <= bottom and left <= right:
... | from solution import grid_path_sequence
def test_path_for_2():
assert grid_path_sequence(2) == "1 2 4 3"
def test_path_for_3():
assert grid_path_sequence(3) == "1 2 3 6 9 8 7 4 5"
def test_path_for_4():
assert grid_path_sequence(4) == "1 2 3 4 8 12 16 15 14 13 9 5 6 7 11 10"
def test_path_for_5():
a... | [
{
"docstring": "Creates a sequence of cell numbers in an N x N grid \nfrom the top-left corner to the bottom-right corner \nvisiting each cell exactly once.",
"function_declaration": "def create_path(N):",
"function_name": "create_path",
"parameter_list": "(N)"
},
{
"docstring": null,
"f... | [
1,
0,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def create_path(N):\n \"\"\"\n Creates a sequence of cell numbers in an N x N grid \n from the top-left corner to the bottom-right corner \n vi... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00009777",
"row_id": 9777,
"seed_ids": "[9940]"
} | 0.734936 | Code_Contests_9777 | I | [
"create_path",
"grid_path_sequence"
] | 2 | [
[
"grid_path_sequence",
"create_path"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | fa36ce13e5f6079a7d53dbda0c1364b7b4757a1f | cb85b8cdde001efc7d3da1bab61f318520b995f6 | |||
v1.0 | instruct | Code_Contests | Code_Contests_9800_I | You are given a string s consisting of lowercase English letters. For a string t, defined as a permutation of string s, let's call it a valid permutation if there are no two consecutive characters in t that are the same.
Determine the number of valid permutations of s. If the number is large, output it modulo 10⁹ + 7.... | MOD = 10**9 + 7
from collections import Counter
from itertools import permutations
def is_valid_permutation(perm):
for i in range(len(perm) - 1):
if perm[i] == perm[i + 1]:
return False
return True
def count_valid_permutations(s):
n = len(s)
count = 0
all_permutations = set(pe... | def test_is_valid_permutation():
assert is_valid_permutation("abab") == True
assert is_valid_permutation("aabb") == False
assert is_valid_permutation("abc") == True
assert is_valid_permutation("aabbcc") == False
def test_count_valid_permutations():
assert count_valid_permutations("abc") == 6
as... | [
{
"docstring": null,
"function_declaration": "def is_valid_permutation(perm):",
"function_name": "is_valid_permutation",
"parameter_list": "(perm)"
},
{
"docstring": null,
"function_declaration": "def count_valid_permutations(s):",
"function_name": "count_valid_permutations",
"pa... | [
0,
0,
0,
1,
0
] | 1 | hard | 0.2 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from collections import Counter\nimport itertools\nMOD = 10**9 + 7\n\n# Helper function to check if a permutation is valid\ndef is_valid_permutation(perm):... | trial_gpt4o_3 | {
"original_instruction": "",
"prompt_id": "00009800",
"row_id": 9800,
"seed_ids": "[2522]"
} | 0.751187 | Code_Contests_9800 | I | [
"is_valid_permutation",
"count_valid_permutations",
"solve"
] | 3 | [
[
"count_valid_permutations",
"is_valid_permutation"
],
[
"solve",
"count_valid_permutations"
]
] | 2 | [] | false | [] | false | pytest | false | [] | true | 960de8ecf6afb430a9e5bd65f88c256c62e84477 | 4270f2221be944da61b03fc176000aa02cf53399 | |||
v1.0 | instruct | Code_Contests | Code_Contests_9813_I | Given a binary tree, we need to perform the following operations:
1. Find the sum of all nodes in the binary tree.
2. Find the height of the binary tree.
3. Find the maximum value node in the binary tree.
Each node in the binary tree has an integer value.
You are given multiple queries where each query is a binary t... | class TreeNode:
def __init__(self, val=0, left=None, right=None):
self.val = val
self.left = left
self.right = right
def build_tree_from_level_order(level_order):
if not level_order:
return None
root = TreeNode(level_order[0])
queue = [root]
i = 1
while queue and... | from solution import TreeNode, build_tree_from_level_order, tree_sum, tree_height, tree_max_value, process_queries
def test_build_tree_from_level_order():
level_order = [1, 2, 3]
root = build_tree_from_level_order(level_order)
assert root.val == 1
assert root.left.val == 2
assert root.right.val == ... | [] | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "class TreeNode:\n def __init__(self, value=0, left=None, right=None):\n self.value = value\n self.left = left\n self.right = right\... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00009813",
"row_id": 9813,
"seed_ids": "[8451]"
} | 0.584177 | Code_Contests_9813 | I | [
"build_tree_from_level_order",
"tree_sum",
"tree_height",
"tree_max_value",
"process_queries"
] | 5 | [
[
"process_queries",
"build_tree_from_level_order"
],
[
"process_queries",
"tree_height"
],
[
"process_queries",
"tree_max_value"
],
[
"process_queries",
"tree_sum"
]
] | 4 | [
"process_queries"
] | false | [
"TreeNode"
] | true | pytest | true | [] | true | 888ff269422ec2c9d0028fd325f5a5732d8056c5 | 386e3554fd3d743d640666ac6214a2d60fd4766f | |||
v1.0 | instruct | Code_Contests | Code_Contests_9842_I | A company is hosting a programming competition where participants have to analyze user reviews to determine their sentiment. The reviews are classified into three categories: positive, neutral, and negative. Your task is to write a program that classifies a given review into one of these three categories based on a pre... | import os
import requests
from collections import Counter
from sklearn.feature_extraction.text import CountVectorizer
from sklearn.naive_bayes import MultinomialNB
# URLs pointing to the dataset
URLS = {
'positive': 'https://example.com/path/to/positive_reviews.txt',
'neutral': 'https://example.com/path/to/neu... | def test_classify_positive_review(monkeypatch):
def mock_download_reviews():
return {
'positive': ['the product is amazing', 'very satisfied with the service'],
'neutral': ['the product is okay', 'it is acceptable'],
'negative': ['the product is bad', 'very disappointed w... | [] | [
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 re\nfrom collections import Counter\nfrom sklearn.feature_extraction.text import CountVectorizer\nfrom sklearn.naive_bayes import MultinomialNB\nimp... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00009842",
"row_id": 9842,
"seed_ids": "[12737]"
} | 0.601387 | Code_Contests_9842 | I | [
"download_reviews",
"read_reviews",
"classify_review"
] | 3 | [
[
"classify_review",
"read_reviews"
],
[
"read_reviews",
"download_reviews"
]
] | 2 | [] | false | [] | false | pytest | false | [
"requests",
"sklearn"
] | false | 3f6d4db7becb42a3ca911c5c9dd209301492a418 | 33d624cec3ea45c47657fc933994d5e26c8a4b86 | |||
v1.0 | instruct | Code_Contests | Code_Contests_9852_I | A company has n employees numbered from 1 to n. The company has recorded the working hours of each employee for the past week. From these records, the company wants to identify whether an employee has worked consecutive hours that form a sequence of increasing hours.
An array of integers represents the working hours o... | def has_increasing_sequence(hours):
"""
Returns 'Yes' if there exists a subarray of consecutive working hours
that form an increasing sequence, otherwise returns 'No'.
"""
for i in range(len(hours) - 1):
if hours[i] < hours[i + 1]:
return 'Yes'
return 'No'
def check_employe... | from solution import has_increasing_sequence, check_employees_working_hours
def test_has_increasing_sequence():
assert has_increasing_sequence([1, 2, 3, 2, 5]) == 'Yes'
assert has_increasing_sequence([5, 4, 3, 2]) == 'No'
assert has_increasing_sequence([1, 5, 3, 4, 8, 7]) == 'Yes'
assert has_increasing... | [
{
"docstring": "Returns 'Yes' if there exists a subarray of consecutive working hours \nthat form an increasing sequence, otherwise returns 'No'.",
"function_declaration": "def has_increasing_sequence(hours):",
"function_name": "has_increasing_sequence",
"parameter_list": "(hours)"
},
{
"doc... | [
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_increasing_sequence(hours):\n \"\"\"\n Determines if there exists a consecutive subarray with an increasing sequence.\n \n :param hours... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00009852",
"row_id": 9852,
"seed_ids": "[7430]"
} | 0.677224 | Code_Contests_9852 | I | [
"has_increasing_sequence",
"check_employees_working_hours"
] | 2 | [
[
"check_employees_working_hours",
"has_increasing_sequence"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 769c51d6859a32efa2255a235f5419ec415f7f92 | 11bf7ebeaa6cd069be834b6d6fb1ef93544e3552 | |||
v1.0 | instruct | Code_Contests | Code_Contests_9905_I | Given a sequence of `n` integers and a series of queries, determine the greatest common divisor (GCD) of the minimum integer within a specified range in the sequence and a given integer `k`.
Each query specifies a range of the sequence and an integer `k`. The task is to find the minimum integer within the range and co... | import math
def gcd(a, b):
while b:
a, b = b, a % b
return a
def minimum_in_range(arr, l, r):
return min(arr[l-1:r])
def process_queries(n, sequence, q, queries):
results = []
for l, r, k in queries:
min_in_range = minimum_in_range(sequence, l, r)
results.append(gcd(min_in... | from solution import gcd, minimum_in_range, process_queries
def test_gcd():
assert gcd(10, 5) == 5
assert gcd(14, 21) == 7
assert gcd(1, 1) == 1
assert gcd(27, 14) == 1
assert gcd(100, 200) == 100
def test_minimum_in_range():
assert minimum_in_range([2, 6, 4, 8, 10], 1, 3) == 2
assert mini... | [
{
"docstring": null,
"function_declaration": "def gcd(a, b):",
"function_name": "gcd",
"parameter_list": "(a, b)"
},
{
"docstring": null,
"function_declaration": "def minimum_in_range(arr, l, r):",
"function_name": "minimum_in_range",
"parameter_list": "(arr, l, r)"
},
{
... | [
0,
0,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import math\n\ndef gcd_of_min_in_range_and_k(n, sequence, queries):\n \"\"\"\n Determines the GCD of the minimum integer within a specified range in ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00009905",
"row_id": 9905,
"seed_ids": "[1388]"
} | 0.710716 | Code_Contests_9905 | I | [
"gcd",
"minimum_in_range",
"process_queries"
] | 3 | [
[
"process_queries",
"gcd"
],
[
"process_queries",
"minimum_in_range"
]
] | 2 | [
"process_queries"
] | false | [] | false | pytest | true | [] | true | 9719885496a098cb24054698964225ce84284714 | cc5fe4a4e47e36d255a29e5c22e5f980a49ef463 | |||
v1.0 | instruct | Code_Contests | Code_Contests_10028_I | Alice is learning scientific computing and she is working on matrix operations. Given a square matrix of size N x N, her task is to calculate the maximum sum of any submatrix. A submatrix is defined as any contiguous block of cells within the original matrix.
Input:
First line contains integer T - number of test cases... | def max_submatrix_sum(matrix):
def max_sum_subarray(array):
max_ending_here, max_so_far = array[0], array[0]
for x in array[1:]:
max_ending_here = max(x, max_ending_here + x)
max_so_far = max(max_so_far, max_ending_here)
return max_so_far
rows = len(matrix)
i... | from solution import max_submatrix_sum, max_submatrix_sum_for_all, parse_input
def test_max_submatrix_sum_case_1():
matrix = [
[1, 2, -1],
[-4, -2, -1],
[3, 4, 5]
]
assert max_submatrix_sum(matrix) == 12
def test_max_submatrix_sum_case_2():
matrix = [
[-1, -2],
... | [
{
"docstring": null,
"function_declaration": "def max_submatrix_sum(matrix):",
"function_name": "max_submatrix_sum",
"parameter_list": "(matrix)"
},
{
"docstring": null,
"function_declaration": "def max_submatrix_sum_for_all(test_cases):",
"function_name": "max_submatrix_sum_for_all"... | [
0,
0,
0,
1
] | 1 | hard | 0.25 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def max_sum_submatrix(matrix, n):\n def kadane(arr):\n max_sum = float('-inf')\n current_sum = 0\n for num in arr:\n cur... | trial_gpt4o_4 | {
"original_instruction": "",
"prompt_id": "00010028",
"row_id": 10028,
"seed_ids": "[6844]"
} | 0.646715 | Code_Contests_10028 | I | [
"max_submatrix_sum",
"max_submatrix_sum_for_all",
"parse_input",
"main"
] | 4 | [
[
"max_submatrix_sum_for_all",
"max_submatrix_sum"
]
] | 1 | [
"parse_input"
] | false | [] | false | pytest | true | [] | true | f447fa06766605fc0b832e9664e37d76f6731b0e | 2ed7b40e1dbc073897060834d0df406c3e2a2efb | |||
v1.0 | instruct | Code_Contests | Code_Contests_10058_I | **Problem Statement**
Alice and Bob are playing a card game with a standard deck of 52 cards. Each player is dealt a hand of 5 cards. The game consists of a single round, and the winner is determined by who has the higher ranking hand according to the common poker hand rankings: High Card, One Pair, Two Pair, Three of... | from collections import Counter
def card_value(card):
"""Helper function to get the value of a card"""
value_str = "23456789TJQKA"
return value_str.index(card[0])
def hand_rank(hand):
"""Returns a tuple representing the rank of the hand"""
values = sorted([card_value(card) for card in hand], rever... | import pytest
from solution import poker_game_outcome
def test_poker_game_outcome():
test_cases = [
(["TS", "JS", "QS", "KS", "AS"], ["9H", "9D", "9S", "3C", "3D"]), # Alice wins with Royal Flush
(["2H", "3H", "4H", "5H", "6H"], ["2D", "3D", "4D", "5D", "6D"]), # Tie with Straight Flush of same r... | [
{
"docstring": "Helper function to get the value of a card",
"function_declaration": "def card_value(card):",
"function_name": "card_value",
"parameter_list": "(card)"
},
{
"docstring": "Returns a tuple representing the rank of the hand",
"function_declaration": "def hand_rank(hand):",
... | [
0,
1,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from collections import Counter\n\ndef hand_rank(hand):\n \"\"\"\n Given a hand of 5 cards, return a tuple representing its rank.\n \"\"\"\n ra... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00010058",
"row_id": 10058,
"seed_ids": "[4483]"
} | 0.707237 | Code_Contests_10058 | I | [
"card_value",
"hand_rank",
"compare_hands",
"poker_game_outcome"
] | 4 | [
[
"compare_hands",
"hand_rank"
],
[
"hand_rank",
"card_value"
],
[
"poker_game_outcome",
"compare_hands"
]
] | 3 | [] | false | [] | false | pytest | true | [] | true | 8a3f88442735a03f69b1904ede8c7f6ed4eedc1a | a2a6c6c2449189847f197d492068cbcf087459f0 | |||
v1.0 | instruct | Code_Contests | Code_Contests_10073_I | You are given a matrix consisting of n rows and m columns, each cell containing a single lowercase alphabet character. You are also given a word and you need to determine if the word exists in the matrix.
The word can be constructed from letters of sequentially adjacent cells, where "adjacent" cells are horizontally o... | def exists_in_matrix(matrix, word):
n = len(matrix)
m = len(matrix[0])
word_length = len(word)
def dfs(x, y, index):
if index == word_length:
return True
if x < 0 or x >= n or y < 0 or y >= m or matrix[x][y] != word[index]:
return False
# Mar... | from solution import exists_in_matrix, word_exists_from_input
def test_case_1():
input_data = """3 4
a b c e
s f c s
a d e e
abcced"""
assert word_exists_from_input(input_data) == "YES"
def test_case_2():
input_data = """3 4
a b c e
s f c s
a d e e
abcd"""
assert word_exists_from_input(input_data) == ... | [
{
"docstring": null,
"function_declaration": "def exists_in_matrix(matrix, word):",
"function_name": "exists_in_matrix",
"parameter_list": "(matrix, word)"
},
{
"docstring": null,
"function_declaration": "def word_exists_from_input(n_m_matrix_word):",
"function_name": "word_exists_fr... | [
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 exist(board, word):\n rows, cols = len(board), len(board[0])\n \n def backtrack(r, c, suffix):\n if len(suffix) == 0:\n retu... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00010073",
"row_id": 10073,
"seed_ids": "[7087]"
} | 0.740484 | Code_Contests_10073 | I | [
"exists_in_matrix",
"word_exists_from_input"
] | 2 | [
[
"word_exists_from_input",
"exists_in_matrix"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 76ddb380a58df836d7aeaf811570de483b7cda01 | bb649675f18beb7e0fe8de5c2480620843a00cf1 | |||
v1.0 | instruct | Code_Contests | Code_Contests_10107_I | Given a list of integers, your task is to reorder these integers to form the largest possible number.
Input
The input consists of a line containing a single integer n (1 ≤ n ≤ 10^5), the number of integers.
The next line contains n non-negative integers, each of which is at most 10^9.
Output
Output a single line c... | from functools import cmp_to_key
def compare(x, y):
if x + y > y + x:
return -1
elif x + y < y + x:
return 1
else:
return 0
def largest_number(n, arr):
"""
Reorder a list of non-negative integers to form the largest possible number.
"""
arr = list(map(str, arr))
... | from solution import largest_number
def test_single_digit_numbers():
assert largest_number(3, [3, 30, 34]) == '34330'
def test_multiple_non_zero_numbers():
assert largest_number(5, [9, 89, 90, 91, 92]) == '992919089'
def test_all_zeros():
assert largest_number(3, [0, 0, 0]) == '0'
def test_large_numbers... | [
{
"docstring": null,
"function_declaration": "def compare(x, y):",
"function_name": "compare",
"parameter_list": "(x, y)"
},
{
"docstring": "Reorder a list of non-negative integers to form the largest possible number.",
"function_declaration": "def largest_number(n, arr):",
"function... | [
0,
0,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from functools import cmp_to_key\n\ndef largest_possible_number(nums):\n # Comparator function for sorting\n def compare(a, b):\n if a + b > b... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00010107",
"row_id": 10107,
"seed_ids": "[12929]"
} | 0.653593 | Code_Contests_10107 | I | [
"compare",
"largest_number"
] | 2 | [
[
"largest_number",
"compare"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 5264e18017185eacacbb31e023728d7052b345a3 | 001fd0bbc084d2769b6d5b6e947fcea05096766d | |||
v1.0 | instruct | Code_Contests | Code_Contests_10117_I | Given a matrix M of size N x M with integer entries, write a program to process Q queries. Each query consists of two integers r1 and r2 (0 ≤ r1, r2 < N). The query should return the sum of all the elements in the submatrix bounded by rows r1 and r2 (inclusive) and all columns.
Constraints
* 1 ≤ N, M ≤ 1000
* -1000 ≤... | def preprocess_sums(matrix, n, m):
"""
Preprocess the matrix to calculate the prefix sums of each column.
This allows for quick calculations of sums between any two rows.
"""
prefix_sums = [[0] * m for _ in range(n)]
for j in range(m):
for i in range(n):
if i == 0:
... | from solution import process_matrix_queries
def test_example_case():
n = 3
m = 3
matrix = [
[1, 2, 3],
[4, 5, 6],
[7, 8, 9]
]
q = 2
queries = [(0, 1), (1, 2)]
expected_output = [21, 39]
assert process_matrix_queries(n, m, matrix, q, queries) == expected_output
d... | [
{
"docstring": "Preprocess the matrix to calculate the prefix sums of each column.\nThis allows for quick calculations of sums between any two rows.",
"function_declaration": "def preprocess_sums(matrix, n, m):",
"function_name": "preprocess_sums",
"parameter_list": "(matrix, n, m)"
},
{
"do... | [
1,
0,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def preprocess_sums(matrix, n, m):\n \"\"\"\n Preprocess the matrix to calculate the prefix sums of each column.\n This allows for quick calculati... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00010117",
"row_id": 10117,
"seed_ids": "[623]"
} | 0.710253 | Code_Contests_10117 | I | [
"preprocess_sums",
"query_sums",
"process_matrix_queries",
"main"
] | 4 | [
[
"process_matrix_queries",
"preprocess_sums"
],
[
"process_matrix_queries",
"query_sums"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 3673ff5386449b8df50338670c6786250358a415 | 51caa287f81426ae7f195a9288db7fce99338c75 | |||
v1.0 | instruct | Code_Contests | Code_Contests_10130_I | You and your friend Maya are engaged in a puzzle involving matrices. You have been given an n x m matrix filled with integers. Your task is to rotate this matrix 90 degrees clockwise k times.
A single 90-degree clockwise rotation of a matrix involves:
1. Translating each element at position (i, j) to position (j, n-... | def rotate_90_clockwise(matrix):
return list(zip(*matrix[::-1]))
def rotate_matrix(matrix, k):
# Determine the effective number of rotations
k = k % 4
for _ in range(k):
matrix = rotate_90_clockwise(matrix)
return matrix
def process_test_cases(test_cases):
results = []
for n, m, k,... | from solution import rotate_matrix, process_test_cases
def test_rotate_90_clockwise():
matrix = [
[1, 2, 3],
[4, 5, 6],
[7, 8, 9]
]
rotated = rotate_90_clockwise(matrix)
expected = [
(7, 4, 1),
(8, 5, 2),
(9, 6, 3)
]
assert rotated == expected
de... | [
{
"docstring": null,
"function_declaration": "def rotate_90_clockwise(matrix):",
"function_name": "rotate_90_clockwise",
"parameter_list": "(matrix)"
},
{
"docstring": null,
"function_declaration": "def rotate_matrix(matrix, k):",
"function_name": "rotate_matrix",
"parameter_list... | [
1,
1,
0
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def rotate_90_clockwise(matrix):\n \"\"\"\n Returns the matrix rotated 90 degrees clockwise.\n \"\"\"\n return [[row[i] for row in matrix[::-1]... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00010130",
"row_id": 10130,
"seed_ids": "[321]"
} | 0.621761 | Code_Contests_10130 | I | [
"rotate_90_clockwise",
"rotate_matrix",
"process_test_cases"
] | 3 | [
[
"process_test_cases",
"rotate_matrix"
],
[
"rotate_matrix",
"rotate_90_clockwise"
]
] | 2 | [
"process_test_cases"
] | false | [] | false | pytest | true | [] | true | 954a8da5d0ee0b473af6b4d0813911676651d26e | 97f0711dfe38f54e41f6b7ceca34be53ccf70881 | |||
v1.0 | instruct | Code_Contests | Code_Contests_10137_I | Suppose you are given a network of computers where some pairs of computers are directly connected by cables. The problem involves calculating the total data transfer cost within the network. The cost to transfer data between two directly connected computers is given, and data can also be transferred indirectly through ... | def find(parent, i):
if parent[i] == i:
return i
return find(parent, parent[i])
def union(parent, rank, x, y):
root_x = find(parent, x)
root_y = find(parent, y)
if rank[root_x] < rank[root_y]:
parent[root_x] = root_y
elif rank[root_x] > rank[root_y]:
parent[root_y] = ro... | from solution import minimum_spanning_tree_cost
def test_example1():
n = 4
cables = [
(1, 2, 3),
(2, 3, 4),
(3, 4, 2),
(4, 1, 5)
]
assert minimum_spanning_tree_cost(n, cables) == 9
def test_example2():
n = 3
cables = [
(1, 2, 1),
(2, 3, 2),
... | [
{
"docstring": null,
"function_declaration": "def find(parent, i):",
"function_name": "find",
"parameter_list": "(parent, i)"
},
{
"docstring": null,
"function_declaration": "def union(parent, rank, x, y):",
"function_name": "union",
"parameter_list": "(parent, rank, x, y)"
},
... | [
0,
0,
0,
0,
1
] | 1 | hard | 0.2 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def find(parent, i):\n if parent[i] == i:\n return i\n return find(parent, parent[i])\n\ndef union(parent, rank, x, y):\n root_x = find(par... | trial_gpt4o_4 | {
"original_instruction": "",
"prompt_id": "00010137",
"row_id": 10137,
"seed_ids": "[11300]"
} | 0.632101 | Code_Contests_10137 | I | [
"find",
"union",
"minimum_spanning_tree_cost",
"solve"
] | 4 | [
[
"minimum_spanning_tree_cost",
"find"
],
[
"minimum_spanning_tree_cost",
"union"
],
[
"solve",
"minimum_spanning_tree_cost"
],
[
"union",
"find"
]
] | 4 | [] | false | [] | false | pytest | true | [] | true | 4d2197b7eca038c78b081da72a8ed15e1d02f48b | 11e7de89fba96ae8dd5c0bf461b1a18cb38c02d3 | |||
v1.0 | instruct | Code_Contests | Code_Contests_10141_I | In a mythical universe, there is a magical tree known as the Fibonacci Tree. This tree has the special property that the number of leaves at depth n is equal to the nth Fibonacci number. The depth of a tree is the number of edges in the longest path from the root to any leaf.
Emily, a botanist, is studying the Fibonac... | def fib(n):
"""
Computes the nth Fibonacci number.
"""
if n == 0: return 0
if n == 1: return 1
a, b = 0, 1
for _ in range(2, n + 1):
a, b = b, a + b
return b
def total_fib_leaves(depth):
"""
Computes the total number of leaves in the Fibonacci Tree
up to the given d... | from solution import fib, total_fib_leaves, process_test_cases
def test_fib():
assert fib(0) == 0
assert fib(1) == 1
assert fib(2) == 1
assert fib(3) == 2
assert fib(4) == 3
assert fib(5) == 5
assert fib(6) == 8
assert fib(10) == 55
def test_total_fib_leaves():
assert total_fib_lea... | [
{
"docstring": "Computes the nth Fibonacci number.",
"function_declaration": "def fib(n):",
"function_name": "fib",
"parameter_list": "(n)"
},
{
"docstring": "Computes the total number of leaves in the Fibonacci Tree \nup to the given depth.",
"function_declaration": "def total_fib_leave... | [
0,
1,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def fibonacci_sum_up_to_depth(d):\n \"\"\"\n Calculate the sum of Fibonacci numbers from F(0) to F(d).\n \"\"\"\n if d == 0:\n return 0\... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00010141",
"row_id": 10141,
"seed_ids": "[1745]"
} | 0.602357 | Code_Contests_10141 | I | [
"fib",
"total_fib_leaves",
"process_test_cases"
] | 3 | [
[
"process_test_cases",
"total_fib_leaves"
],
[
"total_fib_leaves",
"fib"
]
] | 2 | [
"process_test_cases"
] | false | [] | false | pytest | true | [] | true | e661463f8b4d259371d916adbcb53db01b9ffffb | 5508efc7d3951a87091c30eed971972cd8ed1073 | |||
v1.0 | instruct | Code_Contests | Code_Contests_10155_I | The Kingdom of Trees is a magical land where trees communicate with each other through their branches. The kingdom is organized in a hierarchy starting from the king tree (root) down to the common trees (leaf nodes). Each tree is connected to its parent tree by a branch, and each branch has a specific communication tim... | def dfs(node, parent, adj, comm_time, max_comm_times):
for neighbor, time in adj[node]:
if neighbor != parent:
max_comm_times[neighbor] = max_comm_times[node] + time
dfs(neighbor, node, adj, comm_time, max_comm_times)
def max_communication_times(n, edges):
# Create adjacency lis... | from solution import max_communication_times
def test_example_1():
assert max_communication_times(4, [(1, 2, 2), (1, 3, 4), (3, 4, 1)]) == [0, 2, 4, 5]
def test_example_2():
assert max_communication_times(5, [(1, 2, 3), (1, 3, 2), (2, 4, 4), (3, 5, 6)]) == [0, 3, 2, 7, 8]
def test_single_connected_chain():
... | [
{
"docstring": null,
"function_declaration": "def dfs(node, parent, adj, comm_time, max_comm_times):",
"function_name": "dfs",
"parameter_list": "(node, parent, adj, comm_time, max_comm_times)"
},
{
"docstring": null,
"function_declaration": "def max_communication_times(n, edges):",
... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from collections import defaultdict, deque\n\ndef compute_max_communication_times(n, edges):\n # Create a graph to represent the tree\n graph = defau... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00010155",
"row_id": 10155,
"seed_ids": "[2964]"
} | 0.594978 | Code_Contests_10155 | I | [
"dfs",
"max_communication_times"
] | 2 | [
[
"max_communication_times",
"dfs"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | a2e4d0c9f275ca27638249a75866af585f45740a | e3a18a7b6a9b8c49509713913da6a1236cc2a7a9 | |||
v1.0 | instruct | Code_Contests | Code_Contests_10161_I | You are given a grid of size n × m filled with uppercase English letters. Your task is to determine if you can traverse the grid starting from the cell (1, 1) to the cell (n, m), moving only right or down, such that the sequence of letters collected in the path form a palindrome.
Input
The input consists of multiple ... | def is_palindrome(s):
return s == s[::-1]
def can_form_palindrome_from_grid(grid, n, m):
path_1 = []
path_2 = []
# Traverse in top-right and bottom-left manner
for i in range(n+m-1):
if i < n:
path_1.append(grid[i][0])
else:
path_1.append(grid[n-1][i-n+1... | def test_is_palindrome():
from solution import is_palindrome
assert is_palindrome("") == True
assert is_palindrome("A") == True
assert is_palindrome("AB") == False
assert is_palindrome("ABA") == True
assert is_palindrome("ABCBA") == True
assert is_palindrome("ABCA") == False
def test_can_fo... | [
{
"docstring": null,
"function_declaration": "def is_palindrome(s):",
"function_name": "is_palindrome",
"parameter_list": "(s)"
},
{
"docstring": null,
"function_declaration": "def can_form_palindrome_from_grid(grid, n, m):",
"function_name": "can_form_palindrome_from_grid",
"par... | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def can_form_palindrome(grid):\n \"\"\"\n Determines if it's possible to traverse the grid from (1, 1) to (n, m) forming a palindrome.\n \"\"\"\n ... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00010161",
"row_id": 10161,
"seed_ids": "[10128]"
} | 0.78191 | Code_Contests_10161 | I | [
"is_palindrome",
"can_form_palindrome_from_grid",
"check_palindromic_paths",
"process_input",
"palindrome_path"
] | 5 | [
[
"can_form_palindrome_from_grid",
"is_palindrome"
],
[
"check_palindromic_paths",
"can_form_palindrome_from_grid"
],
[
"palindrome_path",
"check_palindromic_paths"
],
[
"palindrome_path",
"process_input"
]
] | 4 | [
"process_input"
] | false | [] | false | pytest | true | [] | true | f7e888c634cc27d5bf1c9b057ad8b1e336266d96 | 974657b30f2e276e02f0ed3475b02d266a020ab3 | |||
v1.0 | instruct | Code_Contests | Code_Contests_10202_I | The Problem of the Resilient Farmer
A farmer owns a large rectangular field that he uses for planting crops. He has recently started using a new method to determine the sections of the field that need extra fertilizer. The idea is to calculate the fertility score of the rectangular sections of the field based on a giv... | def max_fertility_score(matrix):
"""
Returns the maximum fertility score of any rectangular section in the given matrix.
"""
def kadane(arr):
# Standard Kadane's algorithm to find the maximum subarray sum in 1D array.
max_sum = curr_sum = arr[0]
for num in arr[1:]:
c... | from solution import max_fertility_score
def test_example_case():
matrix = [
[1, 2, -1, -4, -20],
[-8, -3, 4, 2, 1],
[3, 8, 10, 1, 3],
[-4, -1, 1, 7, -6]
]
assert max_fertility_score(matrix) == 29
def test_all_negative():
matrix = [
[-1, -2, -3],
[-4, -5... | [
{
"docstring": "Returns the maximum fertility score of any rectangular section in the given matrix.",
"function_declaration": "def max_fertility_score(matrix):",
"function_name": "max_fertility_score",
"parameter_list": "(matrix)"
},
{
"docstring": null,
"function_declaration": "def max_... | [
0,
0,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def maximum_fertility_score(matrix):\n \"\"\"\n Returns the maximum fertility score of any rectangular section within a given matrix.\n :param mat... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00010202",
"row_id": 10202,
"seed_ids": "[12944]"
} | 0.613011 | Code_Contests_10202 | I | [
"max_fertility_score",
"max_fertility_score_from_input"
] | 2 | [
[
"max_fertility_score_from_input",
"max_fertility_score"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 6a228130369dc7bdf71171554fbabe0523dab368 | 902d3d0115f659f67951d2ce17f2d96183ddb1c1 | |||
v1.0 | instruct | Code_Contests | Code_Contests_10322_I | In a small island nation, a highly confidential message is transmitted using a unique encryption technique that involves a coding wheel with Latin alphabets. The coding wheel consists of two concentric rings. The outer ring has all 26 uppercase Latin alphabets arranged in a standard order ('A' to 'Z'), while the inner ... | def encrypt_message(k, plaintext):
"""
Encrypts the plaintext using the coding wheel technique.
Parameters:
k (int): The number of positions to rotate the inner ring clockwise.
plaintext (str): The plaintext message to be encrypted.
Returns:
str: The encrypted ciphertext.
"""
... | from solution import encrypt_message, process_messages
def test_encrypt_message():
assert encrypt_message(3, 'HELLO') == 'KHOOR'
assert encrypt_message(1, 'WORLD') == 'XPSME'
assert encrypt_message(0, 'ZEBRAS') == 'ZEBRAS'
assert encrypt_message(25, 'ABCD') == 'ZABC'
assert encrypt_message(5, 'PYTH... | [
{
"docstring": "Encrypts the plaintext using the coding wheel technique.\n\nParameters:\nk (int): The number of positions to rotate the inner ring clockwise.\nplaintext (str): The plaintext message to be encrypted.\n\nReturns:\nstr: The encrypted ciphertext.",
"function_declaration": "def encrypt_message(k,... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def encrypt_message(k, plaintext):\n \"\"\"\n Encrypts the plaintext by rotating the inner ring by k positions.\n Args:\n k (int): number of po... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00010322",
"row_id": 10322,
"seed_ids": "[925]"
} | 0.677028 | Code_Contests_10322 | I | [
"encrypt_message",
"process_messages"
] | 2 | [
[
"process_messages",
"encrypt_message"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | c05aad1e2362f063cb3833613c8a6e276a95f594 | 5538aa7e30800fb85854ab4882d038e8d0a5b240 | |||
v1.0 | instruct | Code_Contests | Code_Contests_10325_I | You are given a rectangular grid represented as an `n x m` matrix, where each element in the matrix is either `0` or `1`. Your task is to identify clusters of connected `1`s in the matrix. Two elements are considered connected if they are adjacent horizontally or vertically, but not diagonally.
A cluster is defined as... | DX = [0, 1, 0, -1]
DY = [1, 0, -1, 0]
def is_valid(x, y, n, m, grid, visited):
return 0 <= x < n and 0 <= y < m and grid[x][y] == 1 and not visited[x][y]
def dfs(x, y, n, m, grid, visited):
stack = [(x, y)]
while stack:
cx, cy = stack.pop()
for d in range(4):
nx, ny = cx + DX[d... | def test_simple_case():
input_data = "4 5\n1 1 0 0 0\n0 1 0 0 1\n1 0 0 1 1\n0 0 0 0 0"
assert find_clusters(input_data) == 3
def test_no_clusters():
input_data = "3 3\n0 0 0\n0 0 0\n0 0 0"
assert find_clusters(input_data) == 0
def test_all_connected_clusters():
input_data = "3 3\n1 1 1\n1 1 1\n1 1... | [
{
"docstring": null,
"function_declaration": "def is_valid(x, y, n, m, grid, visited):",
"function_name": "is_valid",
"parameter_list": "(x, y, n, m, grid, visited)"
},
{
"docstring": null,
"function_declaration": "def dfs(x, y, n, m, grid, visited):",
"function_name": "dfs",
"pa... | [
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": "DX = [0, 1, 0, -1]\nDY = [1, 0, -1, 0]\n\ndef is_valid(x, y, n, m, grid, visited):\n return 0 <= x < n and 0 <= y < m and grid[x][y] == 1 and not visite... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00010325",
"row_id": 10325,
"seed_ids": "[5762]"
} | 0.560544 | Code_Contests_10325 | I | [
"is_valid",
"dfs",
"count_clusters",
"find_clusters"
] | 4 | [
[
"count_clusters",
"dfs"
],
[
"dfs",
"is_valid"
],
[
"find_clusters",
"count_clusters"
]
] | 3 | [] | false | [] | false | pytest | false | [] | true | cbc645cc28e358b6dadde6457c0d6e29ec9ba1f7 | c4a6741d2ef00a92e275521516dbb0a3b3fc8c3a | |||
v1.0 | instruct | Code_Contests | Code_Contests_10332_I | A city is planning to construct a series of amusement rides, each connected by paths. Each ride is represented as a node and each path between rides as an edge, forming a connected undirected graph. The cost of constructing each path varies.
The city planners want to ensure that the entire amusement park is connected ... | def find(parent, i):
if parent[i] == i:
return i
return find(parent, parent[i])
def union(parent, rank, x, y):
root_x = find(parent, x)
root_y = find(parent, y)
if rank[root_x] < rank[root_y]:
parent[root_x] = root_y
elif rank[root_y] < rank[root_x]:
parent[root_y] ... | def test_example_case():
n, m = 4, 5
edges = [
(1, 2, 1),
(1, 3, 4),
(2, 3, 2),
(2, 4, 7),
(3, 4, 3)
]
assert minimum_spanning_tree_cost(n, m, edges) == 6
def test_disjoint_case():
n, m = 6, 7
edges = [
(1, 2, 1),
(2, 3, 4),
(3, 4,... | [
{
"docstring": null,
"function_declaration": "def find(parent, i):",
"function_name": "find",
"parameter_list": "(parent, i)"
},
{
"docstring": null,
"function_declaration": "def union(parent, rank, x, y):",
"function_name": "union",
"parameter_list": "(parent, rank, x, y)"
},
... | [
0,
0,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def find(parent, i):\n if parent[i] == i:\n return i\n return find(parent, parent[i])\n\ndef union(parent, rank, x, y):\n root_x = find(par... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00010332",
"row_id": 10332,
"seed_ids": "[3575]"
} | 0.785312 | Code_Contests_10332 | I | [
"find",
"union",
"kruskal",
"minimum_spanning_tree_cost"
] | 4 | [
[
"kruskal",
"find"
],
[
"kruskal",
"union"
],
[
"minimum_spanning_tree_cost",
"kruskal"
],
[
"union",
"find"
]
] | 4 | [] | false | [] | false | pytest | false | [] | true | 936eded3cd4e541dc3029d2e5b26af8af63599b4 | 6802d8b5185efff9288e6a4fdd7741f6af8bcae8 | |||
v1.0 | instruct | Code_Contests | Code_Contests_10344_I | In a kingdom, there are N cities connected by M bidirectional roads. Each road connects two different cities and has an associated travel cost. The king wants to select a subset of these roads to construct a road network such that every two cities are connected either directly or indirectly through the selected roads. ... | def find(parent, u):
if parent[u] != u:
parent[u] = find(parent, parent[u])
return parent[u]
def union(parent, rank, u, v):
root_u = find(parent, u)
root_v = find(parent, v)
if root_u != root_v:
if rank[root_u] > rank[root_v]:
parent[root_v] = root_u
elif ra... | def test_solution():
from solution import minimum_cost_to_construct_network
assert minimum_cost_to_construct_network(4, 5, [
(1, 2, 3),
(2, 3, 4),
(3, 4, 5),
(4, 1, 2),
(1, 3, 7)
]) == 9
assert minimum_cost_to_construct_network(3, 1, [
(1, 2, 1)
... | [
{
"docstring": null,
"function_declaration": "def find(parent, u):",
"function_name": "find",
"parameter_list": "(parent, u)"
},
{
"docstring": null,
"function_declaration": "def union(parent, rank, u, v):",
"function_name": "union",
"parameter_list": "(parent, rank, u, v)"
},
... | [
1,
0,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "class UnionFind:\n def __init__(self, n):\n self.parent = list(range(n))\n self.rank = [0] * n\n\n def find(self, u):\n if self.... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00010344",
"row_id": 10344,
"seed_ids": "[6647]"
} | 0.722977 | Code_Contests_10344 | I | [
"find",
"union",
"minimum_cost_to_construct_network"
] | 3 | [
[
"minimum_cost_to_construct_network",
"find"
],
[
"minimum_cost_to_construct_network",
"union"
],
[
"union",
"find"
]
] | 3 | [] | false | [] | false | pytest | true | [] | true | 003c06a28ccb3d77a1ecbe35668502ed8dd7c44d | 5f73eecbe8e061b17146d9e7cbec9e2b410712d0 | |||
v1.0 | instruct | Code_Contests | Code_Contests_10346_I | Write a program to find the Longest Common Prefix (LCP) among a given list of strings. The LCP of a set of strings is the longest substring that is a prefix of all the strings in the set.
For example:
L = {"apple", "ape", "april"} // Here LCP is "ap" because it is the longest starting substring common to all strings.
... | def longest_common_prefix(strs):
"""
Function to find the longest common prefix string amongst an array of strings.
If there is no common prefix, return an empty string "".
"""
if not strs:
return ""
# Start with the prefix being the first string in the array
prefix = strs[0]
... | from solution import longest_common_prefix, find_lcps_for_cases, process_input
def test_longest_common_prefix():
assert longest_common_prefix(["apple", "ape", "april"]) == "ap"
assert longest_common_prefix(["banana", "band", "bandana", "banner"]) == "ban"
assert longest_common_prefix(["dog", "racecar", "ca... | [
{
"docstring": "Function to find the longest common prefix string amongst an array of strings.\nIf there is no common prefix, return an empty string \"\".",
"function_declaration": "def longest_common_prefix(strs):",
"function_name": "longest_common_prefix",
"parameter_list": "(strs)"
},
{
"... | [
0,
1,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def find_longest_common_prefix(strs):\n \"\"\"\n This function returns the longest common prefix string amongst an array of strings.\n If there is... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00010346",
"row_id": 10346,
"seed_ids": "[9233]"
} | 0.799172 | Code_Contests_10346 | I | [
"longest_common_prefix",
"find_lcps_for_cases",
"process_input"
] | 3 | [
[
"find_lcps_for_cases",
"longest_common_prefix"
]
] | 1 | [
"process_input"
] | false | [] | false | pytest | true | [] | true | b960e148c450ae67dd751cf4daca0df5335e937e | a0f58a3c734516c0de25b6ddbf785a812b32d63c | |||
v1.0 | instruct | Code_Contests | Code_Contests_10388_I | Given a connected, undirected graph, a cycle is a path that starts and ends at the same vertex while including other vertices. A simple cycle is a cycle that doesn’t visit any vertex more than once (except for the start/end vertex).
We call a simple cycle "barely connected" if it doesn’t contain any chords. A chord is... | from itertools import combinations
def count_barely_connected_cycles(n, m, edges):
from collections import defaultdict, deque
# Build adjacency list
graph = defaultdict(list)
for u, v in edges:
graph[u].append(v)
graph[v].append(u)
def find_cycles(start, visited, path):
... | def test_simple_case():
assert process_input_and_count_barely_connected_cycles(6, 7, [(1, 2), (2, 3), (3, 4), (4, 5), (5, 6), (6, 1), (2, 5)]) == 2
def test_no_cycles():
assert process_input_and_count_barely_connected_cycles(4, 3, [(1, 2), (2, 3), (3, 4)]) == 0
def test_single_barely_connected_cycle():
as... | [
{
"docstring": null,
"function_declaration": "def count_barely_connected_cycles(n, m, edges):",
"function_name": "count_barely_connected_cycles",
"parameter_list": "(n, m, edges)"
},
{
"docstring": null,
"function_declaration": "def process_input_and_count_barely_connected_cycles(n, m, i... | [
0,
0,
0,
0,
0,
1,
0,
1,
0
] | 2 | hard | 0.222 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from itertools import combinations\n\ndef find_cycles(graph, n):\n def dfs(node, visited, parent):\n visited.add(node)\n for neigh in grap... | trial_gpt4o_7 | {
"original_instruction": "",
"prompt_id": "00010388",
"row_id": 10388,
"seed_ids": "[7901]"
} | 0.620544 | Code_Contests_10388 | I | [
"count_barely_connected_cycles",
"process_input_and_count_barely_connected_cycles"
] | 2 | [
[
"process_input_and_count_barely_connected_cycles",
"count_barely_connected_cycles"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | 5b2a51b0854c5a846f944dcbd77789fc02daa071 | dd1b0bd866f95d757a0dbbb7f7a3d0c055cc4854 | |||
v1.0 | instruct | Code_Contests | Code_Contests_10399_I | Alice likes to play with prime numbers. She has a special way of transforming an array of integers. Alice defines a transformation operation on an element of the array by changing it to the nearest prime number. If two primes are equally close, choose the smaller one. Alice gives you an array and asks for the number of... | from typing import List, Tuple
import math
def is_prime(n):
if n <= 1:
return False
if n <= 3:
return True
if n % 2 == 0 or n % 3 == 0:
return False
i = 5
while i * i <= n:
if n % i == 0 or n % (i + 2) == 0:
return False
i += 6
return True
de... | def test_alice_prime_transformation_even_numbers():
result = alice_prime_transformation([10, 14, 16, 20])
assert result == (4, [11, 13, 17, 19])
def test_alice_prime_transformation_mixed_numbers():
result = alice_prime_transformation([5, 15, 23, 30])
assert result == (2, [5, 13, 23, 29])
def test_alic... | [
{
"docstring": null,
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": null,
"function_declaration": "def nearest_prime(n):",
"function_name": "nearest_prime",
"parameter_list": "(n)"
},
{
"docstring": null,... | [
1,
1,
0
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from typing import List, Tuple\nimport math\n\ndef is_prime(n):\n if n <= 1:\n return False\n if n <= 3:\n return True\n if n % 2 ==... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00010399",
"row_id": 10399,
"seed_ids": "[1223]"
} | 0.647916 | Code_Contests_10399 | I | [
"is_prime",
"nearest_prime",
"alice_prime_transformation"
] | 3 | [
[
"alice_prime_transformation",
"nearest_prime"
],
[
"nearest_prime",
"is_prime"
]
] | 2 | [] | false | [] | false | pytest | false | [] | true | c552eb65f4a26918d41d91cdec7d39085a5948f6 | 8a5dbd3eff62e3f2bdfdeef67ab0a41851bf8f78 | |||
v1.0 | instruct | Code_Contests | Code_Contests_10416_I | The citizens of Numberland are fascinated by prime numbers and their properties. One day, they discovered a new game involving prime numbers which goes as follows:
Given an integer n, partition the number into a non-empty sequence of positive integers such that:
1. The sum of these integers is equal to n.
2. Each inte... | MOD = 1000000007
def sieve(n):
""" Returns a list of all prime numbers up to n using the Sieve of Eratosthenes """
is_prime = [True] * (n + 1)
p = 2
while p * p <= n:
if is_prime[p]:
for i in range(p * p, n + 1, p):
is_prime[i] = False
p += 1
return [p fo... | from solution import count_partitions
def test_count_partitions_5():
assert count_partitions(5) == 2
def test_count_partitions_10():
assert count_partitions(10) == 5
def test_count_partitions_1():
assert count_partitions(1) == 0 # Since there are no prime numbers that sum to 1
def test_count_partitions... | [
{
"docstring": "Returns a list of all prime numbers up to n using the Sieve of Eratosthenes ",
"function_declaration": "def sieve(n):",
"function_name": "sieve",
"parameter_list": "(n)"
},
{
"docstring": null,
"function_declaration": "def count_partitions(n):",
"function_name": "coun... | [
0,
0,
0,
0,
0,
1,
0,
0,
0
] | 1 | hard | 0.111 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "MOD = 1000000007\n\ndef count_prime_partitions(n):\n \"\"\"\n Returns the number of distinct partitions of n into prime numbers, modulo 1000000007.\n... | trial_gpt4o_5 | {
"original_instruction": "",
"prompt_id": "00010416",
"row_id": 10416,
"seed_ids": "[7325]"
} | 0.552297 | Code_Contests_10416 | I | [
"sieve",
"count_partitions"
] | 2 | [
[
"count_partitions",
"sieve"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | e81381cea72ace400a50a1768fa0b6c491f5b153 | 693b636bd2b6f175fc4cbaf8698cd550ec67772f | |||
v1.0 | instruct | Code_Contests | Code_Contests_10426_I | Given a list of integers representing the ages of people in a group, you are to determine the maximum number of pairs (i, j) such that age_i + age_j is a prime number. Each person can participate in at most one such pair.
Input format:
- The first line contains an integer N, the number of people in the group (1 ≤ N ≤... | def is_prime(num):
"""
Check if a number is prime.
"""
if num <= 1:
return False
if num <= 3:
return True
if num % 2 == 0 or num % 3 == 0:
return False
i = 5
while i * i <= num:
if num % i == 0 or num % (i + 2) == 0:
return False
i += 6... | from solution import max_prime_pairs
def test_example_case():
assert max_prime_pairs([3, 7, 1, 12, 6, 9]) == 2
def test_no_prime_pairs():
assert max_prime_pairs([4, 6, 8, 10]) == 0
def test_all_possible_pairs():
assert max_prime_pairs([1, 2, 3, 4, 5, 6]) == 3
def test_repeated_ages():
assert max_pri... | [
{
"docstring": "Check if a number is prime.",
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": "Determine the maximum number of pairs (i, j) such that ages[i] + ages[j] \nis a prime number. Each person can participate in a... | [
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 itertools\n\ndef sieve_of_eratosthenes(n):\n is_prime = [True] * (n + 1)\n is_prime[0] = is_prime[1] = False\n for i in range(2, int(n**0.5... | trial_gpt4o_6 | {
"original_instruction": "",
"prompt_id": "00010426",
"row_id": 10426,
"seed_ids": "[11210]"
} | 0.746354 | Code_Contests_10426 | I | [
"is_prime",
"max_prime_pairs"
] | 2 | [
[
"max_prime_pairs",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 130069952078a50325b489ea671d010d40ba3fb1 | d48a60683c810312af6bf6cb871cddae05349b87 | |||
v1.0 | instruct | Code_Contests | Code_Contests_10436_I | There is a sequence of n integers. The sequence can be rotated any number of times. You are to determine the maximum sum of any contiguous subarray within the sequence after you select the most optimal rotation. The rotation can be done in either direction.
Constraints
* All inputs are integers
* 1 ≤ n ≤ 10,000
* -10... | def max_subarray_sum_circular(nums):
"""
Find the maximum sum of a subarray in a circular array.
This uses Kadane’s algorithm for regular subarrays and a modification for circular subarrays.
"""
def kadane(nums):
current_sum = max_sum = nums[0]
for num in nums[1:]:
curren... | from solution import max_sum_of_contiguous_subarray
def test_example_case_1():
input_str = "6\n4 -1 2 1 -5 4\n0"
expected = "10"
assert max_sum_of_contiguous_subarray(input_str) == expected
def test_example_case_2():
input_str = "5\n1 2 3 4 5\n0"
expected = "15"
assert max_sum_of_contiguous_su... | [
{
"docstring": "Find the maximum sum of a subarray in a circular array.\nThis uses Kadane’s algorithm for regular subarrays and a modification for circular subarrays.",
"function_declaration": "def max_subarray_sum_circular(nums):",
"function_name": "max_subarray_sum_circular",
"parameter_list": "(n... | [
0,
1
] | 1 | medium | 0.5 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def max_subarray_sum(arr):\n # Kadane's algorithm to find maximum subarray sum in O(n)\n max_current = max_global = arr[0]\n for num in arr[1:]:\n... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00010436",
"row_id": 10436,
"seed_ids": "[5717]"
} | 0.716557 | Code_Contests_10436 | I | [
"max_subarray_sum_circular",
"find_max_sum_of_contiguous_subarray",
"parse_input",
"max_sum_of_contiguous_subarray"
] | 4 | [
[
"find_max_sum_of_contiguous_subarray",
"max_subarray_sum_circular"
],
[
"max_sum_of_contiguous_subarray",
"find_max_sum_of_contiguous_subarray"
],
[
"max_sum_of_contiguous_subarray",
"parse_input"
]
] | 3 | [
"parse_input"
] | false | [] | false | pytest | true | [] | true | 1d5391ce25d7097debd05cb963849dac003231ad | c777b3dc6740b3cfe457ad571367dc2645ed67b3 | |||
v1.0 | instruct | Code_Contests | Code_Contests_10440_I | Tom is passionate about programming and loves to solve puzzles with strings. Recently, he came across a problem related to permutations of strings and wants to write a program for it. Given a string consisting of lowercase alphabets, he is interested in finding all the permutations of this string and arranging them in ... | from itertools import permutations
def get_lexicographical_permutations(s):
"""
Returns all permutations of the string `s` in lexicographical order.
"""
perms = permutations(s)
unique_perms = sorted(set(''.join(p) for p in perms))
return unique_perms
def print_lexicographical_permutations(s):
... | from solution import get_lexicographical_permutations
import pytest
def test_permutations_single_character():
assert get_lexicographical_permutations('a') == ['a']
def test_permutations_two_characters():
assert get_lexicographical_permutations('ab') == ['ab', 'ba']
def test_permutations_three_characters():
... | [
{
"docstring": "Returns all permutations of the string `s` in lexicographical order.",
"function_declaration": "def get_lexicographical_permutations(s):",
"function_name": "get_lexicographical_permutations",
"parameter_list": "(s)"
},
{
"docstring": "Prints all permutations of the string `s`... | [
0,
0,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from itertools import permutations\n\ndef lexicographical_permutations(s):\n \"\"\"\n Given a string s, returns all permutations of the string in lex... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00010440",
"row_id": 10440,
"seed_ids": "[10278]"
} | 0.714474 | Code_Contests_10440 | I | [
"get_lexicographical_permutations",
"print_lexicographical_permutations"
] | 2 | [
[
"print_lexicographical_permutations",
"get_lexicographical_permutations"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | bd512663d4cb9f5e09b07868c4a00f0ca9a81df4 | 307cfcb590f23941290fa21fbb93849273a37f6c | |||
v1.0 | instruct | Code_Contests | Code_Contests_10450_I | Professor McGonagall has recently developed a new spell that can manipulate and reshape magical energy grids. Each grid is a two-dimensional array of energy cells, with each cell containing an integer that represents the energy level at that point. McGonagall needs your help to harness this spell to perform specific op... | def rotate_right(grid):
return [list(row) for row in zip(*grid[::-1])]
def rotate_left(grid):
return [list(row) for row in zip(*grid)][::-1]
def reflect(grid):
return [list(row) for row in zip(*grid)]
def apply_operations(grid, operations):
for op in operations:
if op == 'R':
grid... | from solution import reshape_grid, rotate_right, rotate_left, reflect
def test_rotate_right():
grid = [
[1, 2, 3],
[4, 5, 6],
[7, 8, 9]
]
expected = [
[7, 4, 1],
[8, 5, 2],
[9, 6, 3]
]
assert rotate_right(grid) == expected
def test_rotate_left():
... | [
{
"docstring": null,
"function_declaration": "def rotate_right(grid):",
"function_name": "rotate_right",
"parameter_list": "(grid)"
},
{
"docstring": null,
"function_declaration": "def rotate_left(grid):",
"function_name": "rotate_left",
"parameter_list": "(grid)"
},
{
"d... | [
0,
1,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def rotate_right(grid):\n return [list(row) for row in zip(*grid[::-1])]\n\ndef rotate_left(grid):\n return [list(row)[::-1] for row in zip(*grid)]\n... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00010450",
"row_id": 10450,
"seed_ids": "[3132]"
} | 0.60217 | Code_Contests_10450 | I | [
"rotate_right",
"rotate_left",
"reflect",
"apply_operations",
"reshape_grid"
] | 5 | [
[
"apply_operations",
"reflect"
],
[
"apply_operations",
"rotate_left"
],
[
"apply_operations",
"rotate_right"
],
[
"reshape_grid",
"apply_operations"
]
] | 4 | [] | false | [] | false | pytest | true | [] | true | 5baff8562db1f443c8097437405397b084a7f542 | 2a071a17f7f5e34263e64729e2396e3b0da277db | |||
v1.0 | instruct | Code_Contests | Code_Contests_10527_I | You are given an array of `N` integers representing the amount of rainfall recorded over `N` days. There are also `Q` queries, where each query asks for the sum of rainfall recorded over a specific subarray of days. Write a function that processes these queries efficiently.
**Input**
Input is given from standard inpu... | def preprocess_rainfall_data(rainfall):
"""
Preprocess the rainfall data to compute prefix sums.
"""
N = len(rainfall)
prefix_sums = [0] * (N + 1)
for i in range(1, N + 1):
prefix_sums[i] = prefix_sums[i - 1] + rainfall[i - 1]
return prefix_sums
def query_rainfall_sum(prefix_sums, l... | from solution import process_queries
def test_given_example():
N = 5
rainfall = [3, 0, 4, 2, 5]
queries = [(1, 3), (2, 5), (3, 3)]
expected_output = [7, 11, 4]
assert process_queries(N, rainfall, queries) == expected_output
def test_single_day():
N = 1
rainfall = [10]
queries = [(1, 1)... | [
{
"docstring": "Preprocess the rainfall data to compute prefix sums.",
"function_declaration": "def preprocess_rainfall_data(rainfall):",
"function_name": "preprocess_rainfall_data",
"parameter_list": "(rainfall)"
},
{
"docstring": "Return the sum of rainfall from day l to r (1-based index) ... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def preprocess_rainfall(rainfall):\n \"\"\"\n Preprocesses the rainfall data to provide quick sum queries.\n \"\"\"\n N = len(rainfall)\n pr... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00010527",
"row_id": 10527,
"seed_ids": "[2787]"
} | 0.633505 | Code_Contests_10527 | I | [
"preprocess_rainfall_data",
"query_rainfall_sum",
"process_queries"
] | 3 | [
[
"process_queries",
"preprocess_rainfall_data"
],
[
"process_queries",
"query_rainfall_sum"
]
] | 2 | [
"process_queries"
] | false | [] | false | pytest | true | [] | true | c823c5d45257794964dbdd50ae94dc7522408041 | 5ef66a5939a72f0482bfe7cbfeb53488e81ece30 | |||
v1.0 | instruct | Code_Contests | Code_Contests_10553_I | A company's internal service generates logs for user activities that consist of start and end times of user sessions. You need to determine and print the periods during which at least one user was active.
Input:
The first line of the input contains an integer, n, which denotes the number of log entries.
Then, n line... | def merge_intervals(intervals):
"""
Merges overlapping intervals and returns a list of condensed intervals.
"""
if not intervals:
return []
# Sort intervals based on the start time
intervals.sort(key=lambda x: x[0])
merged = []
for interval in intervals:
# If the list of... | from solution import get_active_periods
def test_non_overlapping_intervals():
logs = [[1, 2], [3, 4], [5, 6]]
assert get_active_periods(logs) == [[1, 2], [3, 4], [5, 6]]
def test_fully_overlapping_intervals():
logs = [[1, 4], [2, 3], [3, 5]]
assert get_active_periods(logs) == [[1, 5]]
def test_partia... | [
{
"docstring": "Merges overlapping intervals and returns a list of condensed intervals.",
"function_declaration": "def merge_intervals(intervals):",
"function_name": "merge_intervals",
"parameter_list": "(intervals)"
},
{
"docstring": null,
"function_declaration": "def get_active_periods... | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def merge_activity_periods(logs):\n \"\"\"\n Merges overlapping user activity periods.\n\n :param logs: List of tuples representing start and end ... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00010553",
"row_id": 10553,
"seed_ids": "[6945]"
} | 0.572832 | Code_Contests_10553 | I | [
"merge_intervals",
"get_active_periods"
] | 2 | [
[
"get_active_periods",
"merge_intervals"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 132dc5d7d2d52ef3075dda774a8a88e70029a295 | 9b031b7f9596e2e94faa8a270cc5251ebf891551 | |||
v1.0 | instruct | Code_Contests | Code_Contests_10559_I | In a peaceful village surrounded by mountains, the villagers rely on a water distribution system that comprises a series of reservoirs and pipes. You are given the layout of this water distribution system in the form of a graph, where nodes represent reservoirs, and edges represent pipes connecting these reservoirs. Ea... | from collections import deque
def bfs(C, F, source, sink, parent):
"""
Perform Breadth-First Search to find an augmenting path.
"""
visited = set()
queue = deque([source])
visited.add(source)
while queue:
u = queue.popleft()
for v in range(len(C)):
if v not in v... | from solution import max_water_flow
def test_example_case():
assert max_water_flow(4, 5, [(1, 2, 100), (1, 3, 100), (2, 3, 1), (2, 4, 100), (3, 4, 100)]) == 200
def test_single_pipe():
assert max_water_flow(2, 1, [(1, 2, 50)]) == 50
def test_disconnected_graph():
assert max_water_flow(3, 2, [(1, 2, 30), ... | [
{
"docstring": "Perform Breadth-First Search to find an augmenting path.",
"function_declaration": "def bfs(C, F, source, sink, parent):",
"function_name": "bfs",
"parameter_list": "(C, F, source, sink, parent)"
},
{
"docstring": "Runs the Edmonds-Karp (Ford-Fulkerson) algorithm to find the ... | [
0,
0,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from collections import deque\n\ndef bfs(C, F, source, sink):\n \"\"\"\n Performs a BFS to find an augmenting path in the residual graph.\n \"\"\"... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00010559",
"row_id": 10559,
"seed_ids": "[9923]"
} | 0.58634 | Code_Contests_10559 | I | [
"bfs",
"edmonds_karp",
"max_water_flow"
] | 3 | [
[
"edmonds_karp",
"bfs"
],
[
"max_water_flow",
"edmonds_karp"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | cd6bf536b7f84aa08b343aea4d7a91e4cf9ff092 | 050906af7bbb835e4c57349a1127511ea8e936f8 | |||
v1.0 | instruct | Code_Contests | Code_Contests_10571_I | Alice is exploring different graph algorithms and has recently learned about Depth First Search (DFS). She decides to write some code to traverse a given directed graph and find out if there are any cycles within it.
Alice knows that a graph contains a cycle if, during the DFS traversal, she encounters a vertex that h... | def dfs(graph, v, visited, rec_stack):
visited[v] = True
rec_stack[v] = True
# Recur for all neighbors of v
for neighbor in graph[v]:
if not visited[neighbor]:
if dfs(graph, neighbor, visited, rec_stack):
return True
elif rec_stack[neighbor]:
... | import pytest
from solution import detect_cycle
def test_detect_cycle_with_cycle():
n = 4
m = 4
edges = [(1, 2), (2, 3), (3, 4), (4, 2)]
assert detect_cycle(n, m, edges) == "Cycle Detected"
def test_detect_cycle_no_cycle():
n = 3
m = 2
edges = [(1, 2), (2, 3)]
assert detect_cycle(n, m,... | [
{
"docstring": null,
"function_declaration": "def dfs(graph, v, visited, rec_stack):",
"function_name": "dfs",
"parameter_list": "(graph, v, visited, rec_stack)"
},
{
"docstring": null,
"function_declaration": "def has_cycle(graph, n):",
"function_name": "has_cycle",
"parameter_l... | [
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 dfs(graph, v, visited, rec_stack):\n visited[v] = True\n rec_stack[v] = True\n \n # Recur for all neighbors of v\n for neighbor in graph... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00010571",
"row_id": 10571,
"seed_ids": "[6809]"
} | 0.658551 | Code_Contests_10571 | I | [
"dfs",
"has_cycle",
"detect_cycle"
] | 3 | [
[
"detect_cycle",
"has_cycle"
],
[
"has_cycle",
"dfs"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 718e7d10fcbbc686065edc6b2023320d5c120bd7 | 02b354de151fc634ca50f9718215bcdb0816ecd1 | |||
v1.0 | instruct | Code_Contests | Code_Contests_10577_I | In a quiet town, there is a one-way circular track that connects several important landmarks. The town has decided to deploy a new shuttle service that will start from one of these landmarks and service all other landmarks in a single loop.
The distance between landmarks is provided in the form of a matrix, where the... | from itertools import permutations
def shortest_route(n, dist):
"""
This function calculates the shortest route to visit all landmarks starting
and ending at landmark 0 using the Travelling Salesman Problem (TSP) approach.
"""
landmarks = list(range(1, n)) # landmarks excluding the starting point... | from solution import calculate_min_distance
def test_example_case():
dist = [
[0, 10, 15, 20],
[10, 0, 35, 25],
[15, 35, 0, 30],
[20, 25, 30, 0]
]
assert calculate_min_distance(4, dist) == 80
def test_two_landmarks():
dist = [
[0, 5],
[5, 0]
]
as... | [
{
"docstring": "This function calculates the shortest route to visit all landmarks starting \nand ending at landmark 0 using the Travelling Salesman Problem (TSP) approach.",
"function_declaration": "def shortest_route(n, dist):",
"function_name": "shortest_route",
"parameter_list": "(n, dist)"
},... | [
0,
0,
0,
0,
1
] | 1 | hard | 0.2 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from itertools import permutations\n\ndef find_min_distance(n, dist):\n \"\"\"\n Returns the minimum distance the shuttle must travel to visit all la... | trial_gpt4o_4 | {
"original_instruction": "",
"prompt_id": "00010577",
"row_id": 10577,
"seed_ids": "[258]"
} | 0.74153 | Code_Contests_10577 | I | [
"shortest_route",
"calculate_min_distance"
] | 2 | [
[
"calculate_min_distance",
"shortest_route"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 9b042f57d3b905a1c01eac75d62d01eeda84a51c | a79d300edc75bfa0c196bf27af1d2814bdd22118 | |||
v1.0 | instruct | Code_Contests | Code_Contests_10591_I | William recently started his own farm and he decided to grow a special type of crop that needs a very specific watering pattern. Each crop must be watered exactly once every k days. Given the number of crops and their different watering intervals, help William create a watering schedule that ensures each crop is watere... | import math
from functools import reduce
def lcm(a, b):
"""
Returns the least common multiple of a and b.
"""
return a * b // math.gcd(a, b)
def min_watering_days(n, intervals):
"""
Returns the minimum number of days needed to ensure each crop is watered at least once.
"""
return reduc... | from solution import min_watering_days
def test_example_1():
assert min_watering_days(3, [3, 7, 14]) == 42
def test_example_2():
assert min_watering_days(4, [4, 8, 6, 12]) == 24
def test_single_crop():
assert min_watering_days(1, [5]) == 5
def test_two_crops():
assert min_watering_days(2, [5, 7]) ==... | [
{
"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 minimum number of days needed to ensure each crop is watered at least once.",
"function_declaration"... | [
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 lcm(a, b):\n \"\"\"\n Returns the Least Common Multiple (LCM) of a and b.\n \"\"\"\n return ab... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00010591",
"row_id": 10591,
"seed_ids": "[9309]"
} | 0.642114 | Code_Contests_10591 | I | [
"lcm",
"min_watering_days"
] | 2 | [
[
"min_watering_days",
"lcm"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 44110bd984760c95f23bb9b2984016a77a76bb73 | d2ad4d39329016bef91132996fd48af9975dc79b | |||
v1.0 | instruct | Code_Contests | Code_Contests_10594_I | You are given a binary tree, where each node contains an integer value. Implement a program that identifies the maximum depth (i.e., the longest path from the root node to a leaf) of the binary tree. A leaf is a node with no children.
Input
The input consists of a binary tree, defined in the following format:
- The f... | class TreeNode:
def __init__(self, value):
self.value = value
self.left = None
self.right = None
def build_tree(node_descriptions):
if not node_descriptions:
return None
nodes = {}
for value, left, right in node_descriptions:
if value not in nodes:
n... | from solution import process_tree_input
def test_empty_tree():
assert process_tree_input(0, []) == 0
def test_single_node():
assert process_tree_input(1, ["1 -1 -1"]) == 1
def test_two_levels():
assert process_tree_input(3, ["1 2 3", "2 -1 -1", "3 -1 -1"]) == 2
def test_three_levels():
assert proces... | [] | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "class TreeNode:\n def __init__(self, value=0, left=None, right=None):\n self.value = value\n self.left = left\n self.right = right\... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00010594",
"row_id": 10594,
"seed_ids": "[5450]"
} | 0.546469 | Code_Contests_10594 | I | [
"build_tree",
"max_depth",
"process_tree_input"
] | 3 | [
[
"process_tree_input",
"build_tree"
],
[
"process_tree_input",
"max_depth"
]
] | 2 | [] | false | [
"TreeNode"
] | true | pytest | true | [] | true | f82adaad641c75c3f069a4112bb184b0d1e7747a | df7fe5809ea43be74d480d8090cad64817dcc585 | |||
v1.0 | instruct | Code_Contests | Code_Contests_10598_I | A local charity is organizing a fair where n children will participate in various activities. Each child is required to participate in exactly one activity, and the charity wants to ensure that no two children who are friends end up in the same activity. You are given a list of m pairs, where each pair represents two c... | from collections import deque
def is_bipartite(n, friendships):
# Graph adjacency list
graph = [[] for _ in range(n + 1)]
for u, v in friendships:
graph[u].append(v)
graph[v].append(u)
# Colors array to store colors of nodes
color = [-1] * (n + 1)
for i in range(1, n + 1)... | def test_can_assign_activities_yes():
assert can_assign_activities(4, 3, [(1, 2), (2, 3), (3, 4)]) == "YES"
def test_can_assign_activities_no():
assert can_assign_activities(3, 3, [(1, 2), (2, 3), (3, 1)]) == "NO"
def test_can_assign_activities_single_child():
assert can_assign_activities(1, 0, []) == "YE... | [
{
"docstring": null,
"function_declaration": "def is_bipartite(n, friendships):",
"function_name": "is_bipartite",
"parameter_list": "(n, friendships)"
},
{
"docstring": null,
"function_declaration": "def can_assign_activities(n, m, pairs):",
"function_name": "can_assign_activities",... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from collections import deque\n\ndef is_bipartite(n, friendships):\n \"\"\"\n Determines if the given graph is bipartite.\n \n :param n: Number... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00010598",
"row_id": 10598,
"seed_ids": "[12348]"
} | 0.722271 | Code_Contests_10598 | I | [
"is_bipartite",
"can_assign_activities"
] | 2 | [
[
"can_assign_activities",
"is_bipartite"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | 95b2682c2201b8f2189a4837b16a3d5e77408e90 | 69006825f4dbb9cd2b363dc544a443a2e1b9ae7c | |||
v1.0 | instruct | Code_Contests | Code_Contests_10603_I | Given a matrix of integers and a list of queries, your task is to return the sum of elements within the specified submatrix for each query. The matrix is of size $M \times N$ and you will be given $Q$ queries. Each query contains four integers: the row and column indices of the top-left and bottom-right corners of the ... | def preprocess_matrix(matrix):
"""
Constructs the prefix sum matrix for the given matrix.
"""
M = len(matrix)
N = len(matrix[0])
prefix_sum = [[0] * (N + 1) for _ in range(M + 1)]
for i in range(1, M + 1):
for j in range(1, N + 1):
prefix_sum[i][j] = (matrix[i-1][j-1... | def test_preprocess_matrix():
matrix = [
[1, 2, 3],
[4, 5, 6],
[7, 8, 9]
]
expected_prefix_sum = [
[0, 0, 0, 0],
[0, 1, 3, 6],
[0, 5, 12, 21],
[0, 12, 27, 45]
]
assert preprocess_matrix(matrix) == expected_prefix_sum
def test_query_sum():
... | [
{
"docstring": "Constructs the prefix sum matrix for the given matrix.",
"function_declaration": "def preprocess_matrix(matrix):",
"function_name": "preprocess_matrix",
"parameter_list": "(matrix)"
},
{
"docstring": "Given the prefix sum matrix, returns the sum of elements within the specifi... | [
0,
1,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def preprocess_matrix(matrix):\n M, N = len(matrix), len(matrix[0])\n prefix_sum = [[0] * (N + 1) for _ in range(M + 1)]\n \n for i in range(1,... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00010603",
"row_id": 10603,
"seed_ids": "[5934]"
} | 0.629005 | Code_Contests_10603 | I | [
"preprocess_matrix",
"query_sum",
"matrix_query"
] | 3 | [
[
"matrix_query",
"preprocess_matrix"
],
[
"matrix_query",
"query_sum"
]
] | 2 | [] | false | [] | false | pytest | false | [] | true | db27e6a7764176ded36ce20007aa1a82e1135b10 | bc4d1ced6556381329328dbee242371902fc7644 | |||
v1.0 | instruct | Code_Contests | Code_Contests_10615_I | In a faraway land, there exists a kingdom with n cities connected by m bidirectional roads. Each road has a certain length. The king of this land wants to build a special road network that connects all the cities in such a way that the total length of the roads is minimized, and there exists exactly one unique path bet... | def find(parent, i):
if parent[i] == i:
return i
return find(parent, parent[i])
def union(parent, rank, x, y):
root_x = find(parent, x)
root_y = find(parent, y)
if root_x != root_y:
if rank[root_x] > rank[root_y]:
parent[root_y] = root_x
elif rank[root_x] < ... | from solution import solve_road_network
def test_solve_road_network_case1():
n = 4
m = 5
roads = [
(1, 2, 3),
(1, 3, 4),
(4, 2, 2),
(4, 3, 1),
(2, 3, 5)
]
total_cost, mst = solve_road_network(n, m, roads)
assert total_cost == 6
assert len(mst) == 3
... | [
{
"docstring": null,
"function_declaration": "def find(parent, i):",
"function_name": "find",
"parameter_list": "(parent, i)"
},
{
"docstring": null,
"function_declaration": "def union(parent, rank, x, y):",
"function_name": "union",
"parameter_list": "(parent, rank, x, y)"
},
... | [
0,
0,
0,
0,
0,
1,
0,
0,
1,
1
] | 3 | hard | 0.3 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def kruskal(n, m, roads):\n \"\"\"\n Finds the Minimum Spanning Tree using Kruskal's algorithm.\n\n Parameters:\n n : int - number of cities... | trial_gpt4o_8 | {
"original_instruction": "",
"prompt_id": "00010615",
"row_id": 10615,
"seed_ids": "[7020]"
} | 0.687883 | Code_Contests_10615 | I | [
"find",
"union",
"kruskal",
"solve_road_network"
] | 4 | [
[
"kruskal",
"find"
],
[
"kruskal",
"union"
],
[
"solve_road_network",
"kruskal"
],
[
"union",
"find"
]
] | 4 | [] | false | [] | false | pytest | true | [] | true | c522a1e23b86ea22a4e3afe42016f1a016e9522c | 083d53b64e9759333ffcdba58ec8a2b89aac0bdb | |||
v1.0 | instruct | Code_Contests | Code_Contests_10618_I | A group of friends are playing a game where each friend thinks of a number between 1 and N (inclusive). Each friend either tells the truth or lies about their number. You need to implement a function that determines if it's possible that all friends could be telling the truth, given their answers and comparisons among ... | def validate_statements(N, K, statements):
from collections import defaultdict
graph = defaultdict(list)
equal_pairs = []
for statement in statements:
parts = statement.split()
X_i, relation, Y_i = int(parts[0]), parts[1], int(parts[2])
if relation == '<':
... | from solution import is_possible
def test_possible_case_1():
assert is_possible(5, 3, ["1 < 2", "2 = 3", "1 <= 3"]) == "Possible"
def test_impossible_case_1():
assert is_possible(3, 3, ["1 < 2", "2 < 3", "3 < 1"]) == "Impossible"
def test_possible_case_2():
assert is_possible(10, 4, ["2 <= 4", "5 = 7", "... | [
{
"docstring": null,
"function_declaration": "def validate_statements(N, K, statements):",
"function_name": "validate_statements",
"parameter_list": "(N, K, statements)"
},
{
"docstring": null,
"function_declaration": "def is_possible(N, K, relations):",
"function_name": "is_possible... | [
0,
0,
0,
0,
0,
1,
0,
0,
0,
0
] | 1 | hard | 0.1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_possible_statements(N, K, statements):\n \"\"\"\n Determine if the statements provided by all friends can be true simultaneously.\n \n A... | trial_gpt4o_5 | {
"original_instruction": "",
"prompt_id": "00010618",
"row_id": 10618,
"seed_ids": "[7891]"
} | 0.612636 | Code_Contests_10618 | I | [
"validate_statements",
"is_possible"
] | 2 | [
[
"is_possible",
"validate_statements"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | f5ae63321ef51b46edda8888bab6df2c060fb6e1 | 6eae2f8db81f632efdad64c2f8f07c207229741e | |||
v1.0 | instruct | Code_Contests | Code_Contests_10635_I | Given an array of integers, implement a function that returns the sum of all elements that are prime numbers.
Write a function `sumOfPrimes(arr: List[int]) -> int` that takes in a list of integers and returns the sum of all prime numbers in the array.
### Example
Input:
```python
arr = [10, 15, 3, 7, 11]
```
Output... | from typing import List
def is_prime(n: int) -> bool:
"""
Helper function to check if a number is prime.
"""
if n <= 1:
return False
if n == 2:
return True
if n % 2 == 0:
return False
for i in range(3, int(n**0.5) + 1, 2):
if n % i == 0:
return Fa... | from solution import sumOfPrimes
def test_case_1():
assert sumOfPrimes([10, 15, 3, 7, 11]) == 21
def test_case_2():
assert sumOfPrimes([2, 3, 5, 10, 13]) == 23
def test_case_3():
assert sumOfPrimes([0, 1, 4, 6, 8]) == 0
def test_case_4():
assert sumOfPrimes([2, 3, 5, 11, 17, 23, 29]) == 90
def test... | [
{
"docstring": "Helper function to check if a number is prime.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Returns the sum of all prime numbers in the given list of integers.",
"function_declaration": "def sumOfPri... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from typing import List\nimport math\n\ndef is_prime(num: int) -> bool:\n if num <= 1:\n return False\n if num == 2:\n return True\n ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00010635",
"row_id": 10635,
"seed_ids": "[411]"
} | 0.68286 | Code_Contests_10635 | I | [
"is_prime",
"sumOfPrimes"
] | 2 | [
[
"sumOfPrimes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | d6cca3d967a451b96e48a2de3ce3e3c50edf4a09 | 0f7e6ba0f99324b4a3fb96a5ff45610019cea613 | |||
v1.0 | instruct | Code_Contests | Code_Contests_10726_I | In a certain country, the transportation system between cities is represented by a directed graph with N cities and M one-way roads. Each city is represented by a vertex, and each road is represented by a directed edge consisting of two integers u and v, signifying a road from city u to city v.
Your task is to determi... | def find_all_circuits(N, M, edges):
"""
N: int, number of cities (vertices)
M: int, number of roads (edges)
edges: list of tuples, each tuple (u, v) representing a road from city u to city v
"""
from collections import defaultdict, deque
# Create the graph adjacency list
graph = def... | from solution import count_distinct_circuits
def test_example_1():
N = 4
M = 5
road_pairs = [(1, 2), (2, 3), (3, 1), (3, 4), (4, 3)]
assert count_distinct_circuits(N, M, road_pairs) == 2
def test_example_2():
N = 5
M = 7
road_pairs = [(1, 2), (2, 3), (3, 1), (1, 4), (4, 5), (5, 4), (4, 2)]... | [
{
"docstring": "N: int, number of cities (vertices)\nM: int, number of roads (edges)\nedges: list of tuples, each tuple (u, v) representing a road from city u to city v",
"function_declaration": "def find_all_circuits(N, M, edges):",
"function_name": "find_all_circuits",
"parameter_list": "(N, M, ed... | [
0,
0,
0,
0,
0,
1,
0,
0,
0,
0
] | 1 | hard | 0.1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from collections import defaultdict\n\ndef count_circuits(N, M, edges):\n def dfs(v, start):\n nonlocal visited, recStack\n visited[v] = T... | trial_gpt4o_5 | {
"original_instruction": "",
"prompt_id": "00010726",
"row_id": 10726,
"seed_ids": "[12685]"
} | 0.666905 | Code_Contests_10726 | I | [
"find_all_circuits",
"count_distinct_circuits"
] | 2 | [
[
"count_distinct_circuits",
"find_all_circuits"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 0cf9c327c58827e929da46441226f0970ed10a93 | a5f2b56a1814d64900a0d06346c8611bb119184d | |||
v1.0 | instruct | Code_Contests | Code_Contests_10780_I | An engineer is working on an experiment involving a series of connected water tanks. Each tank can be thought of as a node in a graph, and each connection between two tanks as an edge. The complexity of the system is that water can flow in both directions between any two connected tanks.
Given a graph where each node ... | def find(parent, i):
if parent[i] == i:
return i
else:
parent[i] = find(parent, parent[i])
return parent[i]
def union(parent, rank, x, y):
root_x = find(parent, x)
root_y = find(parent, y)
if root_x != root_y:
if rank[root_x] > rank[root_y]:
parent[r... | from solution import minimum_operations_to_connect_tanks
def test_single_node():
assert minimum_operations_to_connect_tanks(1, 0, []) == 0
def test_all_connected():
assert minimum_operations_to_connect_tanks(3, 3, [(1, 2), (2, 3), (3, 1)]) == 0
def test_two_components():
assert minimum_operations_to_conn... | [
{
"docstring": null,
"function_declaration": "def find(parent, i):",
"function_name": "find",
"parameter_list": "(parent, i)"
},
{
"docstring": null,
"function_declaration": "def union(parent, rank, x, y):",
"function_name": "union",
"parameter_list": "(parent, rank, x, y)"
},
... | [
1,
0,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def find(parent, i):\n if parent[i] == i:\n return i\n else:\n parent[i] = find(parent, parent[i])\n return parent[i]\n\ndef uni... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00010780",
"row_id": 10780,
"seed_ids": "[12347]"
} | 0.629673 | Code_Contests_10780 | I | [
"find",
"union",
"minimum_operations_to_connect_tanks"
] | 3 | [
[
"minimum_operations_to_connect_tanks",
"find"
],
[
"minimum_operations_to_connect_tanks",
"union"
],
[
"union",
"find"
]
] | 3 | [] | false | [] | false | pytest | true | [] | true | c0faffb1b74182dd58de2fd0ed424ec8c169be6c | a6f210583ef905aa7d6c9141c8780a48b6e92995 | |||
v1.0 | instruct | Code_Contests | Code_Contests_10834_I | Prime Sum Pair
Write a function that takes a list of integers and an integer target sum as input and returns a pair of numbers from the list whose sum is equal to the given target sum. Both numbers in the pair should be prime numbers. If no such pair exists, return an empty list.
Input
The first line contains a list o... | import math
def is_prime(n):
"""
Check if a number is prime.
"""
if n <= 1:
return False
if n == 2:
return True
if n % 2 == 0:
return False
max_divisor = math.isqrt(n)
for d in range(3, max_divisor + 1, 2):
if n % d == 0:
return False
retu... | from solution import is_prime, prime_sum_pair
def test_is_prime():
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(4) == False
assert is_prime(5) == True
assert is_prime(10) == False
def test_prime_sum_pair_with_valid_input():
assert prime_sum_pair([10, 7, 3, 5, 1], 8) ==... | [
{
"docstring": "Check if a number is prime.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Find a pair of prime numbers in the list that sum up to the target sum.",
"function_declaration": "def prime_sum_pair(numbers,... | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(n):\n \"\"\"Check if a number is prime.\"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return True\n if n % 2 == 0... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00010834",
"row_id": 10834,
"seed_ids": "[4171]"
} | 0.772107 | Code_Contests_10834 | I | [
"is_prime",
"prime_sum_pair"
] | 2 | [
[
"prime_sum_pair",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | ef89b1a7a86754bc06138e45ab08318ff64c0647 | cc884dc37ead2dd6594332d5ba8aa25a0d472069 | |||
v1.0 | instruct | Code_Contests | Code_Contests_10851_I | Palindrome Partitioning
Problem Statement
Given a string s, partition s such that every substring of the partition is a palindrome. Return all possible palindrome partitioning of s.
A palindrome string is a string that reads the same backward as forward.
Input format
* s: A single string consisting of lowercase En... | def is_palindrome(sub):
"""
Checks if the given substring is a palindrome.
"""
return sub == sub[::-1]
def partition(s):
"""
Given a string s, partitions s such that every substring of the partition is a palindrome.
Returns all possible palindrome partitioning of s.
"""
result = []
... | from solution import partition
def test_example_1():
s = "aab"
expected = [["a", "a", "b"], ["aa", "b"]]
result = partition(s)
assert sorted(result) == sorted(expected)
def test_example_2():
s = "racecar"
expected = [["r","a","c","e","c","a","r"], ["r","aceca","r"], ["r","a","cec","a","r"], ["... | [
{
"docstring": "Checks if the given substring is a palindrome.",
"function_declaration": "def is_palindrome(sub):",
"function_name": "is_palindrome",
"parameter_list": "(sub)"
},
{
"docstring": "Given a string s, partitions s such that every substring of the partition is a palindrome.\nRetur... | [
0,
0,
0,
0,
0,
0,
0,
1,
1,
0
] | 2 | hard | 0.2 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_palindrome(s):\n \"\"\"\n Returns True if the string s is a palindrome, False otherwise.\n \"\"\"\n return s == s[::-1]\n\ndef partition... | trial_gpt4o_8 | {
"original_instruction": "",
"prompt_id": "00010851",
"row_id": 10851,
"seed_ids": "[1039]"
} | 0.738196 | Code_Contests_10851 | I | [
"is_palindrome",
"partition",
"partition_helper"
] | 3 | [
[
"partition",
"partition_helper"
],
[
"partition_helper",
"is_palindrome"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 1e6f97f62ce44c9bf74b1ab6c1d226d7118b7159 | 0a00e40ec9fe6eec7a4665d9df84e4ad0ae5f3f3 | |||
v1.0 | instruct | Code_Contests | Code_Contests_10852_I | There are M different machines in a factory. Each machine can run for a certain number of hours before it needs maintenance. Given a list of integers where each integer represents the hours a corresponding machine can run before needing maintenance, find the minimum total number of hours all machines can run together w... | import math
from functools import reduce
def lcm(a, b):
"""
Returns the least common multiple of a and b.
"""
return abs(a*b) // math.gcd(a, b)
def find_min_total_hours(m, hours):
"""
Finds the minimum total number of hours all machines can run together without any machine requiring maintenanc... | from solution import find_min_total_hours
def test_find_min_total_hours_case_1():
assert find_min_total_hours(3, [6, 8, 12]) == 24
def test_find_min_total_hours_case_2():
assert find_min_total_hours(5, [3, 4, 5, 6, 7]) == 420
def test_find_min_total_hours_case_3():
assert find_min_total_hours(4, [10, 15,... | [
{
"docstring": "Returns the least common multiple of a and b.",
"function_declaration": "def lcm(a, b):",
"function_name": "lcm",
"parameter_list": "(a, b)"
},
{
"docstring": "Finds the minimum total number of hours all machines can run together without any machine requiring maintenance.",
... | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import math\nfrom functools import reduce\n\ndef lcm(a, b):\n \"\"\"\n Helper function to return the LCM of two numbers.\n \"\"\"\n return abs(... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00010852",
"row_id": 10852,
"seed_ids": "[8519]"
} | 0.686497 | Code_Contests_10852 | I | [
"lcm",
"find_min_total_hours",
"main"
] | 3 | [
[
"find_min_total_hours",
"lcm"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | d91336221c267b4c63a8669364c22507d3acd2ba | 0688255b156d99056eea3cc19ef5a59adfa1fbbe | |||
v1.0 | instruct | Code_Contests | Code_Contests_10878_I | Given a list of strings, write a program to group them into sets of anagrams. Two strings are anagrams if one string can be rearranged to form the other string. Your task is to group the provided strings into sets of anagrams and print out each set.
Input:
- The first line contains the number of strings n (1 ≤ n ≤ 100... | def group_anagrams(words):
"""
Groups a list of words into sets of anagrams and returns a list of these sets sorted in the specified format.
"""
from collections import defaultdict
# Dictionary to hold sorted characters as keys and list of anagrams as values
anagrams = defaultdict(list)
... | from solution import group_anagrams_from_input
def test_group_anagrams_sample_input():
n = 6
words = ["eat", "tea", "tan", "ate", "nat", "bat"]
result = group_anagrams_from_input(n, words)
assert result == ["ate eat tea", "bat", "nat tan"]
def test_group_anagrams_empty():
n = 0
words = []
... | [
{
"docstring": "Groups a list of words into sets of anagrams and returns a list of these sets sorted in the specified format.",
"function_declaration": "def group_anagrams(words):",
"function_name": "group_anagrams",
"parameter_list": "(words)"
},
{
"docstring": null,
"function_declarati... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def group_anagrams(strings):\n \"\"\"\n Groups the given list of strings into sets of anagrams and returns the result as a list of strings.\n Each... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00010878",
"row_id": 10878,
"seed_ids": "[2573]"
} | 0.671248 | Code_Contests_10878 | I | [
"group_anagrams",
"group_anagrams_from_input"
] | 2 | [
[
"group_anagrams_from_input",
"group_anagrams"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 9ea71536dbe5dca71c65627a4208b1d1de28efc5 | a6e524646ee50aad11a0bddeffa8efbda072443b | |||
v1.0 | instruct | Code_Contests | Code_Contests_10971_I | Design a function called `find_optimal_word` which can take a text corpus and a list of words as input. Your function should identify and return the word that, when removed from the text, results in the highest possible increase in lexical variance (calculated as the variance in length of the words within the text).
T... | import statistics
def calculate_variance(text):
words = text.split()
lengths = [len(word) for word in words]
return statistics.variance(lengths) if len(lengths) > 1 else 0
def find_optimal_word(text, words):
original_variance = calculate_variance(text)
optimal_word = None
max_increase = float(... | from solution import find_optimal_word
def test_find_optimal_word():
text = "The quick brown fox jumps over the lazy dog"
words = ["the", "fox", "lazy"]
assert find_optimal_word(text, words) == "lazy"
def test_find_optimal_word_with_tie():
text = "the cat sat on the mat"
words = ["the", "cat"]
... | [
{
"docstring": null,
"function_declaration": "def calculate_variance(text):",
"function_name": "calculate_variance",
"parameter_list": "(text)"
},
{
"docstring": null,
"function_declaration": "def find_optimal_word(text, words):",
"function_name": "find_optimal_word",
"parameter_... | [
0,
0,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import re\nimport numpy as np\n\ndef lexical_variance(word_lengths):\n \"\"\"\n Helper function to calculate variance in the length of words.\n \"... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00010971",
"row_id": 10971,
"seed_ids": "[2606]"
} | 0.630702 | Code_Contests_10971 | I | [
"calculate_variance",
"find_optimal_word"
] | 2 | [
[
"find_optimal_word",
"calculate_variance"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | a2183d17542eb16cff335fb5a23e612876a148c4 | 6c39af536a6b69d9ba609e51174662f688ad827b | |||
v1.0 | instruct | Code_Contests | Code_Contests_10991_I | Given an integer M, write a function to determine if it's possible to express M as the sum of exactly three distinct prime numbers. If it is possible, return "YES", otherwise return "NO".
Constraints
* 1 \leq M \leq 300
Input
Input is given from Standard Input in the following format:
M
Output
Print "YES" if M... | def is_prime(n):
if n <= 1:
return False
if n <= 3:
return True
if n % 2 == 0 or n % 3 == 0:
return False
i = 5
while i * i <= n:
if n % i == 0 or n % (i + 2) == 0:
return False
i += 6
return True
def can_be_expressed_as_sum_of_three_primes(M)... | from solution import can_be_expressed_as_sum_of_three_primes
def test_case_1():
assert can_be_expressed_as_sum_of_three_primes(28) == "YES"
def test_case_2():
assert can_be_expressed_as_sum_of_three_primes(11) == "NO"
def test_case_3():
assert can_be_expressed_as_sum_of_three_primes(31) == "YES"
... | [
{
"docstring": null,
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": null,
"function_declaration": "def can_be_expressed_as_sum_of_three_primes(M):",
"function_name": "can_be_expressed_as_sum_of_three_primes",
"pa... | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(n):\n \"\"\"Helper function to check if a number is a prime.\"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return Tr... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00010991",
"row_id": 10991,
"seed_ids": "[3518]"
} | 0.698806 | Code_Contests_10991 | I | [
"is_prime",
"can_be_expressed_as_sum_of_three_primes"
] | 2 | [
[
"can_be_expressed_as_sum_of_three_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 8c6e6a9815a67f37fef897e1bb7e72a9ea8498e6 | 448e06b49ee17b375bc7ffa7ca126ff7e2b69567 | |||
v1.0 | instruct | Code_Contests | Code_Contests_11100_I | Given an n x n grid where certain cells are blocked (i.e., they cannot be passed through), your task is to determine the number of distinct paths one can take to travel from the top-left corner (0, 0) to the bottom-right corner (n-1, n-1). You can only move either down or to the right at any step. Your solution should ... | def count_paths(grid):
"""
This function returns the number of distinct paths from the top-left corner
to the bottom-right corner of the grid.
"""
n = len(grid)
if grid[0][0] == '#' or grid[n-1][n-1] == '#':
return 0
# Initialize the dp array
dp = [[0] * n for _ in range(n)... | from solution import find_number_of_paths
def test_simple_grid():
assert find_number_of_paths(3, [
". . .",
". # .",
". . ."
]) == 2
def test_no_path_grid():
assert find_number_of_paths(3, [
". # .",
"# . .",
". . ."
]) == 0
def test_grid_with_multiple_... | [
{
"docstring": "This function returns the number of distinct paths from the top-left corner \nto the bottom-right corner of the grid.",
"function_declaration": "def count_paths(grid):",
"function_name": "count_paths",
"parameter_list": "(grid)"
},
{
"docstring": null,
"function_declarati... | [
1,
0,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def count_distinct_paths(n, grid):\n if grid[0][0] == '#' or grid[n-1][n-1] == '#':\n return 0\n\n dp = [[0] * n for _ in range(n)]\n dp[0]... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00011100",
"row_id": 11100,
"seed_ids": "[6725]"
} | 0.775319 | Code_Contests_11100 | I | [
"count_paths",
"find_number_of_paths"
] | 2 | [
[
"find_number_of_paths",
"count_paths"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 0e5d4cb008ce5220cd93a3c786f7dd066dfb74be | b00d5a045a75eb8c9f865d7aea78adcbff03475e | |||
v1.0 | instruct | Code_Contests | Code_Contests_11123_I | Given a list of words, determine if you can transform one word to another by changing exactly one letter at a time, with each intermediate word also being in the list. Each test case will include multiple pairs of words, and you need to check the transformability for each pair.
Input:
The first line of input specifies... | def can_transform(word, target, word_set):
if word == target:
return True
visited = set()
queue = [(word, 0)]
while queue:
current_word, steps = queue.pop(0)
if current_word == target:
return True
for i in range(len(current_word)):
for char in 'abc... | def test_transform():
input_data = """1
6
hit
hot
dot
dog
cog
lot
3
hit cog
hit lot
dot dig"""
expected_output = "YES\nYES\nNO"
assert transform(input_data) == expected_output
def test_transform_single_word():
input_data = """1
1
hit
1
hit hot"""
expected_output = "NO"
assert transform(input_da... | [
{
"docstring": null,
"function_declaration": "def can_transform(word, target, word_set):",
"function_name": "can_transform",
"parameter_list": "(word, target, word_set)"
},
{
"docstring": null,
"function_declaration": "def check_transformability(test_cases):",
"function_name": "check... | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from collections import deque\n\ndef can_transform(words, start, end):\n if start == end:\n return \"YES\"\n \n word_set = set(words)\n ... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00011123",
"row_id": 11123,
"seed_ids": "[5485]"
} | 0.648714 | Code_Contests_11123 | I | [
"can_transform",
"check_transformability",
"parse_input",
"transform"
] | 4 | [
[
"check_transformability",
"can_transform"
],
[
"transform",
"check_transformability"
],
[
"transform",
"parse_input"
]
] | 3 | [
"parse_input"
] | false | [] | false | pytest | false | [] | true | e65c495962b6787a75ca0c11b61a072ea4fe9970 | 517b62bd5bef9c4877b6e3e876453622098b0cfd | |||
v1.0 | instruct | Code_Contests | Code_Contests_11140_I | Consider the following problem scenario: You are working on a project that involves manipulating sequences of numbers. One common operation you need to perform is checking whether a given sequence of numbers is strictly increasing or not. A strictly increasing sequence is one in which each subsequent element is greater... | def is_strictly_increasing(sequence):
"""
Given a sequence of numbers, determines if the sequence is strictly increasing.
:param sequence: List of integers
:return: Boolean, True if sequence is strictly increasing, False otherwise
"""
for i in range(1, len(sequence)):
if sequence[i] <= s... | from solution import is_strictly_increasing, check_sequences
def test_is_strictly_increasing():
assert is_strictly_increasing([1, 2, 3, 4, 5]) == True
assert is_strictly_increasing([1, 2, 2, 3]) == False
assert is_strictly_increasing([-1, 0, 1, 2, 3, 4]) == True
assert is_strictly_increasing([5, 6, 7, ... | [
{
"docstring": "Given a sequence of numbers, determines if the sequence is strictly increasing.\n:param sequence: List of integers\n:return: Boolean, True if sequence is strictly increasing, False otherwise",
"function_declaration": "def is_strictly_increasing(sequence):",
"function_name": "is_strictly_... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_strictly_increasing(sequences):\n \"\"\"\n This function takes a list of sequences and determines whether each sequence is strictly increasing... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00011140",
"row_id": 11140,
"seed_ids": "[8541]"
} | 0.819995 | Code_Contests_11140 | I | [
"is_strictly_increasing",
"check_sequences"
] | 2 | [
[
"check_sequences",
"is_strictly_increasing"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | bfd39d8d4ba0043237c9641d8c2967ed216f5856 | bd93ee03b023f625cb73487fe251e0cf1010e10b | |||
v1.0 | instruct | Code_Contests | Code_Contests_11197_I | Polyland has a river with n islands. The islands are numbered from 1 to n. There are m bridges connecting these islands. Each bridge connects exactly two different islands and can be traversed in both directions.
Di takes a sightseeing tour and starts from the first island. His goal is to visit all the islands at leas... | def is_eulerian_cycle_possible(n, m, bridges):
from collections import defaultdict, deque
# Function to check if graph is connected
def is_connected():
visited = [False] * (n + 1)
queue = deque([1])
visited[1] = True
count = 1
while queue:
no... | def test_determine_route_yes_4_4():
n = 4
m = 4
bridges = [(1, 2), (2, 3), (3, 4), (4, 1)]
assert determine_route(n, m, bridges) == "YES"
def test_determine_route_yes_3_3():
n = 3
m = 3
bridges = [(1, 2), (2, 3), (3, 1)]
assert determine_route(n, m, bridges) == "YES"
def test_determine... | [
{
"docstring": null,
"function_declaration": "def is_eulerian_cycle_possible(n, m, bridges):",
"function_name": "is_eulerian_cycle_possible",
"parameter_list": "(n, m, bridges)"
},
{
"docstring": null,
"function_declaration": "def determine_route(n, m, bridges):",
"function_name": "d... | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def can_complete_tour(n, m, bridges):\n from collections import defaultdict, deque\n \n graph = defaultdict(list)\n degree = [0] * (n + 1)\n ... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00011197",
"row_id": 11197,
"seed_ids": "[9905]"
} | 0.795782 | Code_Contests_11197 | I | [
"is_eulerian_cycle_possible",
"determine_route"
] | 2 | [
[
"determine_route",
"is_eulerian_cycle_possible"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | 407789fe29e43ec95235f428b429f5d3ce35e675 | 3a9920a0e93566908542cdc11a8a9d33417652f2 | |||
v1.0 | instruct | Code_Contests | Code_Contests_11234_I | A gardener plants flowers in a row. Each flower has a specific type and a height. Types of flowers are represented by a character (a-z), and the height of each flower is an integer (1 ≤ height ≤ 1000). The garden looks more beautiful if there are no adjacent flowers of the same type.
You are given the initial sequence... | from collections import Counter
import heapq
def rearrange_flowers(n, flowers):
# Count frequencies and store flowers information
flower_count = Counter(flowers[i][0] for i in range(n))
max_freq = max(flower_count.values())
# If any flower appears more than (n + 1) // 2 times, it's impossible
... | def test_flower_rearrangement():
assert beautify_garden(5, ["a", "3", "b", "1", "a", "2", "c", "1", "a", "1"]) in [
"a 3 b 1 a 2 c 1 a 1",
"a 2 b 1 a 3 c 1 a 1",
"a 1 b 1 a 3 c 1 a 2"
]
assert beautify_garden(4, ["a", "1", "a", "2", "a", "3", "a", "4"]) == "Not possible"
as... | [
{
"docstring": null,
"function_declaration": "def rearrange_flowers(n, flowers):",
"function_name": "rearrange_flowers",
"parameter_list": "(n, flowers)"
},
{
"docstring": null,
"function_declaration": "def beautify_garden(n, flower_data):",
"function_name": "beautify_garden",
"p... | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def rearrange_flowers(n, flowers):\n from collections import Counter\n from heapq import heappush, heappop\n\n count = Counter(flower[0] for flowe... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00011234",
"row_id": 11234,
"seed_ids": "[11566]"
} | 0.686795 | Code_Contests_11234 | I | [
"rearrange_flowers",
"beautify_garden",
"solve"
] | 3 | [
[
"beautify_garden",
"rearrange_flowers"
],
[
"solve",
"beautify_garden"
]
] | 2 | [] | false | [] | false | pytest | false | [] | true | eb940199ef1a6dfea60b5e513d5376a7ec50d9fd | b14ebd29223d192e4869efd5fc9f1f601eb27756 | |||
v1.0 | instruct | Code_Contests | Code_Contests_11257_I | You are given an array of integers. Your task is to reorder the array in such a way that the absolute difference between any two consecutive elements is minimized.
Input
The first line of the input contains a single integer t (1 ≤ t ≤ 100) — the number of test cases. The first line of each test case contains a single... | def reorder_array(test_cases):
results = []
for nums in test_cases:
nums_sorted = sorted(nums)
results.append(nums_sorted)
return results
# Wrapper function to handle input and output format
def handle_reorder_array(t, test_cases_data):
test_cases = []
for i in range(t):
n, ... | def test_reorder_array():
assert handle_reorder_array(2, [(4, [4, 2, 1, 3]), (3, [10, 5, 8])]) == [[1, 2, 3, 4], [5, 8, 10]]
def test_reorder_array_single_case():
assert handle_reorder_array(1, [(5, [3, 1, 4, 1, 5])]) == [[1, 1, 3, 4, 5]]
def test_reorder_array_all_same_elements():
assert handle_reorder_a... | [
{
"docstring": null,
"function_declaration": "def reorder_array(test_cases):",
"function_name": "reorder_array",
"parameter_list": "(test_cases)"
},
{
"docstring": null,
"function_declaration": "def handle_reorder_array(t, test_cases_data):",
"function_name": "handle_reorder_array",
... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def reorder_array_min_absolute_difference(t: int, test_cases: list):\n \"\"\"\n Reorders each array of integers in such a way that the absolute \n ... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00011257",
"row_id": 11257,
"seed_ids": "[12207]"
} | 0.768376 | Code_Contests_11257 | I | [
"reorder_array",
"handle_reorder_array"
] | 2 | [
[
"handle_reorder_array",
"reorder_array"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | b675cccd804f304fcf0fdaae6f73b9d2a3ea590e | ec0c965f81ef2fcbfd8b884c3d8d1705a595c08b | |||
v1.0 | instruct | Code_Contests | Code_Contests_11266_I | You are given a list of N integers which represent the number of pages in N books. Your task is to divide these books into K students such that the maximum number of pages assigned to a student is minimized. Each student must get at least one book, and each book must be assigned to exactly one student.
Input
The fir... | def is_possible(books, n, k, max_pages):
student_count = 1
current_pages = 0
for pages in books:
if current_pages + pages > max_pages:
student_count += 1
current_pages = pages
if student_count > k:
return False
else:
curren... | def test_is_possible():
assert is_possible([10, 20, 30, 40], 4, 2, 60) == True
assert is_possible([10, 20, 30, 40], 4, 2, 50) == False
assert is_possible([10, 20, 30, 40], 4, 3, 40) == True
assert is_possible([5, 10, 20, 30, 40], 5, 3, 40) == True
def test_find_minimum_max_pages():
assert find_mini... | [
{
"docstring": null,
"function_declaration": "def is_possible(books, n, k, max_pages):",
"function_name": "is_possible",
"parameter_list": "(books, n, k, max_pages)"
},
{
"docstring": null,
"function_declaration": "def find_minimum_max_pages(books, n, k):",
"function_name": "find_min... | [
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_possible_to_allocate(pages, books, students, max_pages):\n cnt_students = 1\n current_sum = 0\n\n for page in pages:\n if current_su... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00011266",
"row_id": 11266,
"seed_ids": "[13120]"
} | 0.776085 | Code_Contests_11266 | I | [
"is_possible",
"find_minimum_max_pages",
"allocate_books"
] | 3 | [
[
"allocate_books",
"find_minimum_max_pages"
],
[
"find_minimum_max_pages",
"is_possible"
]
] | 2 | [] | false | [] | false | pytest | false | [] | true | 4051a167ad58110332bea52d7853d564287c5fee | 71e8944e344d06d6b238450bbdf0ffc9f6b95bbe | |||
v1.0 | instruct | Code_Contests | Code_Contests_11271_I | You are given a forest of rooted trees. Each tree's node has a unique positive integer value, and no two trees have overlapping nodes.
You need to perform Q queries. There are 3 types of queries:
1. Find the lowest common ancestor (LCA) of two nodes with values X and Y.
2. Determine if node with value X is an ancesto... | class TreeNode:
def __init__(self, value):
self.value = value
self.children = []
def build_tree(edges, root_val):
nodes = {}
for u, v in edges:
if u not in nodes:
nodes[u] = TreeNode(u)
if v not in nodes:
nodes[v] = TreeNode(v)
nodes[u].childr... | import pytest
from solution import TreeNode, build_tree, find_lca, is_ancestor, cyclic_shift
def test_find_lca():
edges = [(1, 2), (2, 3), (3, 4)]
root = build_tree(edges, 1)
assert find_lca(root, 2, 4).value == 2
def test_is_ancestor():
edges = [(1, 2), (2, 3), (3, 4)]
root = build_tree(edges, 1)... | [] | [
0,
0,
0,
1,
0
] | 1 | hard | 0.2 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "class TreeNode:\n def __init__(self, value):\n self.value = value\n self.children = []\n self.parent = None\n\nclass Forest:\n d... | trial_gpt4o_3 | {
"original_instruction": "",
"prompt_id": "00011271",
"row_id": 11271,
"seed_ids": "[6835]"
} | 0.624917 | Code_Contests_11271 | I | [
"build_tree",
"find_lca",
"is_ancestor",
"search",
"cyclic_shift",
"main"
] | 6 | [
[
"is_ancestor",
"search"
]
] | 1 | [] | false | [
"TreeNode"
] | true | pytest | true | [] | true | de748e4c2a280106095e8a015388ab7b6c98a5bb | d43f4f289c75562d7bd08d389f7efb7d446f4f5a | |||
v1.0 | instruct | Code_Contests | Code_Contests_11302_I | You are given a binary tree with `N` nodes where each node has a unique value from `1` to `N`. The tree is represented in a 2D list `edges` of size `(N-1) x 2` where each `edges[i] = [u, v]` represents an undirected edge connecting nodes `u` and `v`. Perform `Q` queries of the following types:
* `1 x`: Find the number... | from collections import defaultdict
def compute_subtree_properties(N, edges):
tree = defaultdict(list)
for u, v in edges:
tree[u].append(v)
tree[v].append(u)
subtree_size = [0] * (N + 1)
subtree_sum = [0] * (N + 1)
def dfs(node, parent):
subtree_size[node] = 1
subt... | import pytest
from solution import answer_queries
def test_example_case():
N = 5
Q = 4
edges = [(1,2), (1,3), (2,4), (2,5)]
queries = [(1,1), (1,2), (2,1), (2,2)]
expected_output = [5, 3, 15, 11]
assert answer_queries(N, Q, edges, queries) == expected_output
def test_single_node_tree():
... | [
{
"docstring": null,
"function_declaration": "def compute_subtree_properties(N, edges):",
"function_name": "compute_subtree_properties",
"parameter_list": "(N, edges)"
},
{
"docstring": null,
"function_declaration": "def answer_queries(N, Q, edges, queries):",
"function_name": "answe... | [
0,
1,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import sys\nfrom collections import defaultdict, deque\n\ninput = sys.stdin.read\n\ndef preprocess(N, edges):\n # Create adjacency list for the graph\n ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00011302",
"row_id": 11302,
"seed_ids": "[3933]"
} | 0.719204 | Code_Contests_11302 | I | [
"compute_subtree_properties",
"answer_queries"
] | 2 | [
[
"answer_queries",
"compute_subtree_properties"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 7ead0d361f2561abb751537a360019aedeba229a | 0052889500dd744c5e2ba0060e9fb1fd44496824 | |||
v1.0 | instruct | Code_Contests | Code_Contests_11409_I | You have been given a string that contains a mathematical expression in infix notation. Your task is to write a program that converts this infix expression into its equivalent postfix (Reverse Polish) notation and then evaluates the postfix expression.
The input consists of multiple lines. Each line contains a mathema... | def infix_to_postfix(expression):
precedence = {'+': 1, '-': 1, '*': 2, '/': 2, '^': 3}
output = []
stack = []
for char in expression:
if char.isnumeric():
output.append(char)
elif char == '(':
stack.append(char)
elif char == ')':
while stack ... | from solution import infix_to_postfix, evaluate_postfix, process_input
def test_infix_to_postfix():
assert infix_to_postfix('3+4*2/(1-5)^2') == '3 4 2 * 1 5 - 2 ^ / +'
assert infix_to_postfix('2*(3+7)/4-1') == '2 3 7 + * 4 / 1 -'
assert infix_to_postfix('5+6*(7-3)/2') == '5 6 7 3 - * 2 / +'
def test_evalu... | [
{
"docstring": null,
"function_declaration": "def infix_to_postfix(expression):",
"function_name": "infix_to_postfix",
"parameter_list": "(expression)"
},
{
"docstring": null,
"function_declaration": "def evaluate_postfix(expression):",
"function_name": "evaluate_postfix",
"param... | [
1,
1,
0
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import operator\n\n# Define operator precedence and associativity\nprecedence = {\n '^': (4, 'Right'),\n '*': (3, 'Left'),\n '/': (3, 'Left'),\n ... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00011409",
"row_id": 11409,
"seed_ids": "[5408]"
} | 0.512902 | Code_Contests_11409 | I | [
"infix_to_postfix",
"evaluate_postfix",
"process_input"
] | 3 | [
[
"process_input",
"evaluate_postfix"
],
[
"process_input",
"infix_to_postfix"
]
] | 2 | [
"process_input"
] | false | [] | false | pytest | true | [] | true | 8961ac5a51deeeb93925a84d7f87eb513252f1e4 | f5bdd5ce1f1f28afcf6fe1cff664d9c388d51482 | |||
v1.0 | instruct | Code_Contests | Code_Contests_11484_I | Given an undirected graph with n nodes and m edges, a path in the graph is considered a "special path" if it visits every node exactly once and returns to the starting node, forming a cycle known as a Hamiltonian cycle. Your task is to determine whether such a special path exists in the graph.
Input
The first line of... | from itertools import permutations
def is_hamiltonian_cycle(n, edges):
graph = {i: set() for i in range(1, n+1)}
for u, v in edges:
graph[u].add(v)
graph[v].add(u)
nodes = list(graph.keys())
for start in nodes:
for perm in permutations(nodes):
if perm[0... | import pytest
from solution import hamiltonian_path_exists
def test_given_example1():
n, m = 4, 6
edges = [(1, 2), (2, 3), (3, 4), (4, 1), (1, 3), (2, 4)]
assert hamiltonian_path_exists(n, m, edges) == "Yes"
def test_given_example2():
n, m = 4, 4
edges = [(1, 2), (2, 3), (3, 4), (1, 3)]
assert... | [
{
"docstring": null,
"function_declaration": "def is_hamiltonian_cycle(n, edges):",
"function_name": "is_hamiltonian_cycle",
"parameter_list": "(n, edges)"
},
{
"docstring": null,
"function_declaration": "def hamiltonian_path_exists(n, m, edges):",
"function_name": "hamiltonian_path_... | [
0,
0,
0,
0,
0,
1,
1,
0,
0,
1
] | 3 | hard | 0.3 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from itertools import permutations\n\ndef has_hamiltonian_cycle(n, edges):\n if n == 1:\n return False\n\n adjacency_list = {i: set() for i in... | trial_gpt4o_9 | {
"original_instruction": "",
"prompt_id": "00011484",
"row_id": 11484,
"seed_ids": "[12341]"
} | 0.638337 | Code_Contests_11484 | I | [
"is_hamiltonian_cycle",
"hamiltonian_path_exists"
] | 2 | [
[
"hamiltonian_path_exists",
"is_hamiltonian_cycle"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | db308ebec1c9438c12ee7c4add6d6804592e77b4 | 171e5ca8a9d6bcb89682afcc5fa9bf3025bd6f3a | |||
v1.0 | instruct | Code_Contests | Code_Contests_11513_I | Vanya is developing a small scientific calculator application. The calculator needs to be able to perform some basic arithmetic operations such as addition, subtraction, multiplication, and division. Moreover, it should also support evaluating simple mathematical expressions in infix notation with parentheses to denote... | def evaluate_expression(expression):
"""
Evaluates a single mathematical expression in infix notation with parentheses.
"""
return eval(expression)
def evaluate_expressions(n, expressions):
"""
Evaluates multiple mathematical expressions in infix notation, given the number of expressions n.
... | from solution import evaluate_expressions
def test_single_addition():
assert evaluate_expressions(1, ["3 + 5"]) == [8]
def test_with_multiplication():
assert evaluate_expressions(1, ["10 + 2 * 6"]) == [22]
def test_combined_operations():
assert evaluate_expressions(1, ["100 * 2 + 12"]) == [212]
def test... | [
{
"docstring": "Evaluates a single mathematical expression in infix notation with parentheses.",
"function_declaration": "def evaluate_expression(expression):",
"function_name": "evaluate_expression",
"parameter_list": "(expression)"
},
{
"docstring": "Evaluates multiple mathematical express... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def evaluate_expression(expression):\n \"\"\"\n Evaluates a single mathematical expression in infix notation with parentheses.\n \"\"\"\n retur... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00011513",
"row_id": 11513,
"seed_ids": "[7425]"
} | 0.584109 | Code_Contests_11513 | I | [
"evaluate_expression",
"evaluate_expressions"
] | 2 | [
[
"evaluate_expressions",
"evaluate_expression"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | d5877d508e6afde3378af63046b64a3e65f61cee | 516d893e8f83255d5af49626dab5a1ef7367d384 | |||
v1.0 | instruct | Code_Contests | Code_Contests_11516_I | John is organizing a marathon where participants have unique positive integer IDs. The IDs represent the number of seconds they took to complete the marathon. John wants to congratulate participants who took a prime number of seconds.
Write a program that takes a list of participant IDs and identifies IDs that are pri... | def is_prime(n):
"""
Helper function to determine if a number is prime.
"""
if n <= 1:
return False
if n == 2:
return True
if n % 2 == 0:
return False
max_divisor = int(n**0.5) + 1
for d in range(3, max_divisor, 2):
if n % d == 0:
return False
... | from solution import is_prime, find_prime_ids
def test_is_prime():
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(4) == False
assert is_prime(17) == True
assert is_prime(18) == False
assert is_prime(1) == False
def test_find_prime_ids():
# Test case with prime IDs
... | [
{
"docstring": "Helper function to determine if a number is prime.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "This function takes a list of participant IDs and returns a list of prime IDs.",
"function_declaration"... | [
1,
1,
0
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(n):\n \"\"\"\n Helper function to determine if a number is prime.\n \"\"\"\n if n <= 1:\n return False\n if n == 2:\n ... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00011516",
"row_id": 11516,
"seed_ids": "[11421]"
} | 0.642982 | Code_Contests_11516 | I | [
"is_prime",
"find_prime_ids"
] | 2 | [
[
"find_prime_ids",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 4e0cc15f0faaa762a40e65568220949b6f02b222 | 1a1b03c4f57e82303f48e0061b60171141988775 | |||
v1.0 | instruct | Code_Contests | Code_Contests_11542_I | Sheldon’s Friendship Algorithm
Sheldon, Leonard, and their friends are obsessed with numbers and prime sequences. They've come up with a new challenge and they need your help.
A prime number is a natural number greater than 1 that has no positive divisors other than 1 and itself. A prime sequence is a series of prime... | def sieve_eratosthenes(n):
"""
Generate a list of prime numbers up to n using the Sieve of Eratosthenes.
"""
is_prime = [True] * (n + 1)
p = 2
while p * p <= n:
if is_prime[p]:
for i in range(p * p, n + 1, p):
is_prime[i] = False
p += 1
prime_numbe... | from solution import kth_prime
def test_kth_prime_single_query():
assert kth_prime([1]) == [2]
assert kth_prime([2]) == [3]
assert kth_prime([3]) == [5]
def test_kth_prime_multiple_queries():
assert kth_prime([1, 2, 3, 4, 5]) == [2, 3, 5, 7, 11]
def test_kth_prime_large_queries():
result = kth_pr... | [
{
"docstring": "Generate a list of prime numbers up to n using the Sieve of Eratosthenes.",
"function_declaration": "def sieve_eratosthenes(n):",
"function_name": "sieve_eratosthenes",
"parameter_list": "(n)"
},
{
"docstring": "For each k in k_list, return the k-th prime number.",
"funct... | [
0,
0,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def sieve(n):\n \"\"\"\n Sieve of Eratosthenes to generate all prime numbers up to n.\n \"\"\"\n is_prime = [True] * (n + 1)\n is_prime[0], ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00011542",
"row_id": 11542,
"seed_ids": "[9121]"
} | 0.624499 | Code_Contests_11542 | I | [
"sieve_eratosthenes",
"kth_prime"
] | 2 | [
[
"kth_prime",
"sieve_eratosthenes"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | c451bf093a350f29143db8e017567dc72af85254 | 9144120c2ec434438a0d9b7473e9de5f6acc4bcb | |||
v1.0 | instruct | Code_Contests | Code_Contests_11602_I | Given a list of integer numbers, identify and return a sublist that forms the longest contiguous subsequence where all elements are of the same parity (either all odd or all even).
Input
The first line contains a single integer t (1 ≤ t ≤ 100) - number of test cases.
For each test case, the first line contains a sin... | def longest_contiguous_same_parity_sublist(lst):
"""
Returns a sublist that forms the longest contiguous subsequence where all elements
are of the same parity (either all odd or all even).
"""
max_length = 0
current_length = 0
best_start_index = 0
start_index = 0
is_even = lst[0] % ... | def test_longest_contiguous_same_parity_sublist():
assert longest_contiguous_same_parity_sublist([1, 2, 2, 2, 5, 7, 6, 4]) == [2, 2, 2]
assert longest_contiguous_same_parity_sublist([10, 12, 14, 1, 3]) == [10, 12, 14]
assert longest_contiguous_same_parity_sublist([2, 4, 8, 1, 1, 1, 2, 2]) == [2, 4, 8]
a... | [
{
"docstring": "Returns a sublist that forms the longest contiguous subsequence where all elements \nare of the same parity (either all odd or all even).",
"function_declaration": "def longest_contiguous_same_parity_sublist(lst):",
"function_name": "longest_contiguous_same_parity_sublist",
"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 longest_same_parity_subsequence(t, test_cases):\n results = []\n for case in test_cases:\n n, nums = case\n max_length = 0\n ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00011602",
"row_id": 11602,
"seed_ids": "[6067]"
} | 0.741258 | Code_Contests_11602 | I | [
"longest_contiguous_same_parity_sublist",
"solve",
"parse_input"
] | 3 | [
[
"solve",
"longest_contiguous_same_parity_sublist"
]
] | 1 | [
"parse_input"
] | false | [] | false | pytest | false | [] | true | cf6d9f7b28b6a5f0d9b2b951e21d0e2a3cecbb7e | fb5beffe4a8a6ee4bad485e365e05542b8fad9a1 | |||
v1.0 | instruct | Code_Contests | Code_Contests_11621_I | You are given a tree with $N$ nodes and $N-1$ edges. Each node is labeled from $1$ to $N$ and each edge is weighted. You need to find the maximum weighted path between any two nodes in the tree.
Input
The input consists of multiple test cases in the format below.
The first line contains an integer $T$ ($1 \leq T \le... | from collections import defaultdict
import sys
def tree_diameter(edges, N):
def bfs(start_node):
visited = [-1] * (N + 1)
visited[start_node] = 0
queue = [start_node]
max_distance, max_node = 0, start_node
while queue:
current_node = queue.pop(0)
cur... | def test_parse_input():
input_data = "2\n4\n1 2 3\n2 3 4\n2 4 2\n3\n1 2 1\n1 3 5"
expected_output = [
(4, [(1, 2, 3), (2, 3, 4), (2, 4, 2)]),
(3, [(1, 2, 1), (1, 3, 5)])
]
assert parse_input(input_data) == expected_output
def test_solve():
cases = [
(4, [(1, 2, 3), (2, 3, 4)... | [
{
"docstring": null,
"function_declaration": "def tree_diameter(edges, N):",
"function_name": "tree_diameter",
"parameter_list": "(edges, N)"
},
{
"docstring": null,
"function_declaration": "def solve(tree_cases):",
"function_name": "solve",
"parameter_list": "(tree_cases)"
},
... | [
1,
1,
0
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from collections import defaultdict\nimport sys\n\ndef tree_diameter(edges, N):\n def bfs(start_node):\n visited = [-1] * (N + 1)\n visite... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00011621",
"row_id": 11621,
"seed_ids": "[4685]"
} | 0.72583 | Code_Contests_11621 | I | [
"tree_diameter",
"solve",
"parse_input",
"main"
] | 4 | [
[
"solve",
"tree_diameter"
]
] | 1 | [
"parse_input"
] | false | [] | false | pytest | false | [] | true | 2ac8c50586f1ad248922f54d62db4f4be4afe4b6 | e3db36f6764a546c3d2bd74e9f9b16b8569e7efe | |||
v1.0 | instruct | Code_Contests | Code_Contests_11638_I | Alice and Bob are playing a game on a graph. The graph is undirected and simple, with no self-loops or multiple edges between any pair of nodes. The graph consists of n nodes and m edges.
The game is played in turns, starting with Alice. During each turn, a player must select an edge and remove it from the graph. The... | def determine_winner(n, m, edges):
# The outcome of the game is determined by the parity of the number of edges.
if m % 2 == 0:
return "Alice"
else:
return "Bob"
def find_winners(test_cases):
results = []
for test in test_cases:
n, m, edges = test
results.append(dete... | from solution import find_winners, parse_input
def test_example_cases():
input_str = "3\n3 3\n1 2\n2 3\n3 1\n4 4\n1 2\n2 3\n3 4\n4 1\n4 3\n1 2\n2 3\n3 4"
expected_output = ["Bob", "Alice", "Bob"]
test_cases = parse_input(input_str)
assert find_winners(test_cases) == expected_output
def test_all_edges_... | [
{
"docstring": null,
"function_declaration": "def determine_winner(n, m, edges):",
"function_name": "determine_winner",
"parameter_list": "(n, m, edges)"
},
{
"docstring": null,
"function_declaration": "def find_winners(test_cases):",
"function_name": "find_winners",
"parameter_l... | [
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 game_result(n, m, edges):\n \"\"\"\n Determine the winner of the game if both players play optimally.\n \"\"\"\n # Result is determined bas... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00011638",
"row_id": 11638,
"seed_ids": "[13248]"
} | 0.739944 | Code_Contests_11638 | I | [
"determine_winner",
"find_winners",
"parse_input"
] | 3 | [
[
"find_winners",
"determine_winner"
]
] | 1 | [
"parse_input"
] | false | [] | false | pytest | true | [] | true | db985c940f235f424a4bb3918e9ab1a18d8be988 | 4f6267d186503306eae2bac491ab5129965f0ed7 | |||
v1.0 | instruct | Code_Contests | Code_Contests_11704_I | You are given a list of integers, and your task is to determine the maximum possible sum of a subsequence such that no two elements are adjacent in the original list. Print the result modulo 10^9 + 7.
A subsequence means any sequence that can be derived from another sequence by deleting some elements without changing ... | def max_sum_no_adjacent(nums):
"""
Returns the maximum sum of a subsequence with no two elements being adjacent.
"""
MOD = 10**9 + 7
n = len(nums)
if n == 0:
return 0
elif n == 1:
return max(0, nums[0]) % MOD
dp = [0] * n
dp[0] = max(0, nums[0]) # Initialize dp[0] w... | from solution import max_sum_no_adjacent
def test_sample_case():
assert max_sum_no_adjacent([3, 2, 5, 10, 7]) == 15
def test_one_element():
assert max_sum_no_adjacent([5]) == 5
assert max_sum_no_adjacent([-5]) == 0
def test_all_non_positive():
assert max_sum_no_adjacent([-1, -2, -3]) == 0
assert ... | [
{
"docstring": "Returns the maximum sum of a subsequence with no two elements being adjacent.",
"function_declaration": "def max_sum_no_adjacent(nums):",
"function_name": "max_sum_no_adjacent",
"parameter_list": "(nums)"
},
{
"docstring": null,
"function_declaration": "def solve():",
... | [
0,
0,
0,
0,
0,
0,
1,
0,
0
] | 1 | hard | 0.111 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "MOD = 10**9 + 7\n\ndef max_non_adjacent_subsequence_sum(arr):\n \"\"\"\n Returns the maximum possible sum of non-adjacent subsequence elements modulo... | trial_gpt4o_7 | {
"original_instruction": "",
"prompt_id": "00011704",
"row_id": 11704,
"seed_ids": "[692]"
} | 0.795309 | Code_Contests_11704 | I | [
"max_sum_no_adjacent",
"solve"
] | 2 | [
[
"solve",
"max_sum_no_adjacent"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 0db01ed757f676121ef7a54341cea668d6d48fcc | f0bd91efbe3c4577d944ae6bd95b0607ef258f96 | |||
v1.0 | instruct | Code_Contests | Code_Contests_11779_I | In a remote village, the mayor wants to install a new communication tower to provide internet access to all households in the area. The village can be represented as a 2D plane with each house located at a specific coordinate. The communication tower will have a specific range that determines how far the signal can rea... | import math
def calculate_distance(x1, y1, x2, y2):
return math.sqrt((x2 - x1)**2 + (y2 - y1)**2)
def minimum_range_to_cover_houses(house_coordinates):
n = len(house_coordinates)
max_distance = 0
for i in range(n):
for j in range(i + 1, n):
distance = calculate_distance(house_coord... | import pytest
from solution import calculate_distance, minimum_range_to_cover_houses, parse_input_data, process_input_dataset
def test_calculate_distance():
assert calculate_distance(0, 0, 3, 4) == 5.0
assert calculate_distance(1, 1, 4, 5) == 5.0
assert calculate_distance(2, 0, 2, 3) == 3.0
def test_minim... | [
{
"docstring": null,
"function_declaration": "def calculate_distance(x1, y1, x2, y2):",
"function_name": "calculate_distance",
"parameter_list": "(x1, y1, x2, y2)"
},
{
"docstring": null,
"function_declaration": "def minimum_range_to_cover_houses(house_coordinates):",
"function_name"... | [
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 calculate_distance(x1, y1, x2, y2):\n return math.sqrt((x2 - x1)**2 + (y2 - y1)**2)\n\ndef minimum_range_to_cover_houses(house_coordi... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00011779",
"row_id": 11779,
"seed_ids": "[12796]"
} | 0.682901 | Code_Contests_11779 | I | [
"calculate_distance",
"minimum_range_to_cover_houses",
"process_input_dataset",
"parse_input_data"
] | 4 | [
[
"minimum_range_to_cover_houses",
"calculate_distance"
],
[
"process_input_dataset",
"minimum_range_to_cover_houses"
]
] | 2 | [
"parse_input_data"
] | false | [] | false | pytest | true | [] | true | 74708d51041311fee8c10cd78c265fd866c43e75 | 210e05bca7236f0a921144aa577f1bdc3876a083 | |||
v1.0 | instruct | Code_Contests | Code_Contests_11865_I | You are given a forest of trees, where each tree represents a hierarchy of departments in an organization. Every department can have multiple sub-departments, each of which can further have its own sub-departments, and so on. The purpose of this exercise is to determine the "maximum depth" of each tree in the forest. T... | def max_depth(tree_description):
"""
Returns the maximum depth of the tree described by the tree_description string.
"""
def helper(s, index):
max_depth_subtree = 0
current_depth = 0
while index < len(s):
char = s[index]
if char == '{':
... | from solution import max_depth, parse_input, calculate_max_depths
def test_max_depth():
assert max_depth("X") == 1
assert max_depth("{X}") == 2
assert max_depth("{X, X}") == 2
assert max_depth("{{X}}") == 3
assert max_depth("{X, {X, X}, X}") == 3
def test_parse_input():
input_data = "X\n{X}\n{... | [
{
"docstring": "Returns the maximum depth of the tree described by the tree_description string.",
"function_declaration": "def max_depth(tree_description):",
"function_name": "max_depth",
"parameter_list": "(tree_description)"
},
{
"docstring": "Parses the input data to list of tree descript... | [
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_depth(tree_description):\n \"\"\"\n Returns the maximum depth of the tree described by the tree_description string.\n \"\"\"\n def help... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00011865",
"row_id": 11865,
"seed_ids": "[11755]"
} | 0.591087 | Code_Contests_11865 | I | [
"max_depth",
"parse_input",
"calculate_max_depths"
] | 3 | [
[
"calculate_max_depths",
"max_depth"
],
[
"calculate_max_depths",
"parse_input"
]
] | 2 | [
"parse_input"
] | false | [] | false | pytest | true | [] | true | 6a4e61fdc0b30b2e58dc60529790548dcdd4dd01 | 816c2643f385bdb8208e34585d7d98415b5fd85d | |||
v1.0 | instruct | Code_Contests | Code_Contests_11870_I | You are given an infinite array where the i-th element is denoted by A[i] = i^3. Your task is to answer Q queries on this array. Each query is one of the following types:
1. Q1 l r: Compute the sum of the elements from index l to index r (both inclusive).
2. Q2 l r: Compute the sum of the square of the elements from i... | def cube(n):
return n ** 3
def sum_of_cubes(l, r):
return sum(cube(x) for x in range(l, r + 1))
def sum_of_squares_of_cubes(l, r):
return sum(cube(x) ** 2 for x in range(l, r + 1))
def handle_query(query):
q_type, *params = query.split()
if q_type == 'Q1':
l, r = map(int, params)
... | from solution import process_queries
def test_sum_of_cubes():
queries = ["Q1 2 4"]
expected_output = [99]
assert process_queries(queries) == expected_output
def test_sum_of_squares_of_cubes():
queries = ["Q2 1 3"]
expected_output = [794]
assert process_queries(queries) == expected_output
def ... | [
{
"docstring": null,
"function_declaration": "def cube(n):",
"function_name": "cube",
"parameter_list": "(n)"
},
{
"docstring": null,
"function_declaration": "def sum_of_cubes(l, r):",
"function_name": "sum_of_cubes",
"parameter_list": "(l, r)"
},
{
"docstring": null,
... | [
0,
0,
0,
0,
1,
0,
0,
0
] | 1 | hard | 0.125 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def query_processor(queries):\n def sum_of_cubes(l, r):\n return sum(i ** 3 for i in range(l, r + 1))\n\n def sum_of_squares_of_cubes(l, r):\n... | trial_gpt4o_5 | {
"original_instruction": "",
"prompt_id": "00011870",
"row_id": 11870,
"seed_ids": "[9063]"
} | 0.689796 | Code_Contests_11870 | I | [
"cube",
"sum_of_cubes",
"sum_of_squares_of_cubes",
"handle_query",
"process_queries"
] | 5 | [
[
"handle_query",
"cube"
],
[
"handle_query",
"sum_of_cubes"
],
[
"handle_query",
"sum_of_squares_of_cubes"
],
[
"process_queries",
"handle_query"
],
[
"sum_of_cubes",
"cube"
],
[
"sum_of_squares_of_cubes",
"cube"
]
] | 6 | [
"process_queries"
] | false | [] | false | pytest | true | [] | true | d77f9530243a6ab17627370ea7b6262d9ac5ac39 | 50cbf30dc98388dd904551363143fcfd23662862 | |||
v1.0 | instruct | Code_Contests | Code_Contests_11944_I | Lisa has been learning about binary trees in her computer science class and she came upon an interesting problem involving binary tree traversal. She wants to implement a function that constructs the binary tree given pre-order and in-order traversal sequences. However, she is having trouble figuring out how to correct... | class TreeNode:
def __init__(self, value=0, left=None, right=None):
self.value = value
self.left = left
self.right = right
def build_tree(preorder, inorder):
if not preorder or not inorder:
return None
root_val = preorder.pop(0)
root = TreeNode(root_val)
inorder_in... | from solution import construct_postorder_from_pre_in
def test_example_1():
preorder = [1, 2, 4, 3]
inorder = [4, 2, 1, 3]
expected_postorder = [4, 2, 3, 1]
assert construct_postorder_from_pre_in(preorder, inorder) == expected_postorder
def test_example_2():
preorder = [3, 9, 20, 15, 7, 10, 8]
... | [] | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "class TreeNode:\n def __init__(self, val=0, left=None, right=None):\n self.val = val\n self.left = left\n self.right = right\n ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00011944",
"row_id": 11944,
"seed_ids": "[12104]"
} | 0.522033 | Code_Contests_11944 | I | [
"build_tree",
"postorder_traversal",
"construct_postorder_from_pre_in"
] | 3 | [
[
"construct_postorder_from_pre_in",
"build_tree"
],
[
"construct_postorder_from_pre_in",
"postorder_traversal"
]
] | 2 | [] | false | [
"TreeNode"
] | true | pytest | true | [] | true | 4b642de3efc7a7d28d238ef02fa8b4b1c69d515a | 5a8de6b46bc527c2376fd423c17190d6a69a1c33 | |||
v1.0 | instruct | Code_Contests | Code_Contests_11950_I | Alice and Bob are two friends who love solving puzzles, and they've come up with an interesting game related to prime numbers.
The rules of the game are as follows:
1. There are N distinct integers given in a list.
2. Alice and Bob take turns; Alice always goes first.
3. During each turn, a player must remove one num... | 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 count_primes(arr):
return sum(1 for nu... | from solution import game_outcome
def test_single_prime():
assert game_outcome(1, [(1, [2])]) == ["Alice"]
def test_no_primes():
assert game_outcome(1, [(4, [4, 6, 8, 9])]) == ["Bob"]
def test_all_primes():
assert game_outcome(1, [(3, [2, 5, 7])]) == ["Alice"]
def test_even_primes():
assert game_out... | [
{
"docstring": null,
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": null,
"function_declaration": "def count_primes(arr):",
"function_name": "count_primes",
"parameter_list": "(arr)"
},
{
"docstring": nul... | [
0,
0,
0,
1
] | 1 | hard | 0.25 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(num):\n \"\"\"\n Returns True if num is a prime number, otherwise False.\n \"\"\"\n if num < 2:\n return False\n if num ... | trial_gpt4o_4 | {
"original_instruction": "",
"prompt_id": "00011950",
"row_id": 11950,
"seed_ids": "[3096]"
} | 0.698371 | Code_Contests_11950 | I | [
"is_prime",
"count_primes",
"game_outcome"
] | 3 | [
[
"count_primes",
"is_prime"
],
[
"game_outcome",
"count_primes"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 384b13958319217a023588501492c0eeed8c80b0 | 6225c6f226e43ffad0db233ab384280c6a360faa | |||
v1.0 | instruct | Code_Contests | Code_Contests_11978_I | In a famous kingdom, there were a lot of jewels in the royal treasure. One day, the king decided to distribute the jewels among the citizens in such a way that each citizen gets exactly two jewels and no two citizens get the same pair of jewels. For security reasons, he also decided that each pair of jewels must be uni... | def generate_jewel_pairs(test_cases):
result = []
for case in test_cases:
N, jewels = case
pairs = []
jewels.sort()
for i in range(N):
for j in range(i + 1, N):
pairs.append((jewels[i], jewels[j]))
result.append(pairs)
return result
def pa... | from solution import generate_jewel_pairs, parse_input, format_output, process_jewel_pairs
def test_generate_jewel_pairs_single_test():
test_cases = [(4, [8, 3, 1, 2])]
expected_output = [
[(1, 2), (1, 3), (1, 8), (2, 3), (2, 8), (3, 8)]
]
assert generate_jewel_pairs(test_cases) == expected_out... | [
{
"docstring": null,
"function_declaration": "def generate_jewel_pairs(test_cases):",
"function_name": "generate_jewel_pairs",
"parameter_list": "(test_cases)"
},
{
"docstring": null,
"function_declaration": "def parse_input(input_string):",
"function_name": "parse_input",
"param... | [
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 get_unique_pairs(T, test_cases):\n \"\"\"\n Given the number of test cases and the subsequent test cases,\n this function returns the unique p... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00011978",
"row_id": 11978,
"seed_ids": "[627]"
} | 0.600504 | Code_Contests_11978 | I | [
"generate_jewel_pairs",
"parse_input",
"format_output",
"process_jewel_pairs"
] | 4 | [
[
"process_jewel_pairs",
"format_output"
],
[
"process_jewel_pairs",
"generate_jewel_pairs"
],
[
"process_jewel_pairs",
"parse_input"
]
] | 3 | [
"parse_input",
"format_output"
] | false | [] | false | pytest | true | [] | true | 09489bebe14434bd4cf1140f0c4b19165f7e2bc6 | 51b4390070adc17d57fab564eded3ff428c57add | |||
v1.0 | instruct | Code_Contests | Code_Contests_12030_I | There is a kingdom with several castles connected by bidirectional roads. The king of the kingdom, Kind King, wants to ensure that in case of an attack, he can close a certain number of roads to minimize the damage by preventing the spread of the enemy troops. To do this, he needs to know the minimum number of roads th... | from collections import defaultdict, deque
def find_bridges(n, connections):
def dfs(u, parent):
nonlocal time
visited[u] = True
discovery[u] = low[u] = time
time += 1
for v in graph[u]:
if not visited[v]:
dfs(v, u)
low[u]... | from solution import min_roads_to_disconnect
def test_example():
assert min_roads_to_disconnect(6, 7, [(1, 2), (1, 3), (2, 3), (2, 4), (3, 4), (3, 5), (4, 6)]) == 2
def test_no_roads():
assert min_roads_to_disconnect(5, 0, []) == 0
def test_single_road():
assert min_roads_to_disconnect(2, 1, [(1, 2)]) ==... | [
{
"docstring": null,
"function_declaration": "def find_bridges(n, connections):",
"function_name": "find_bridges",
"parameter_list": "(n, connections)"
},
{
"docstring": null,
"function_declaration": "def min_roads_to_disconnect(n, r, roads):",
"function_name": "min_roads_to_disconne... | [
0,
0,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from collections import defaultdict, deque\n\nclass Graph:\n def __init__(self, n):\n self.graph = defaultdict(list)\n self.ROW = n\n \... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00012030",
"row_id": 12030,
"seed_ids": "[11358]"
} | 0.641451 | Code_Contests_12030 | I | [
"find_bridges",
"min_roads_to_disconnect"
] | 2 | [
[
"min_roads_to_disconnect",
"find_bridges"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | b454bdcac9ac4f055933edb84abd6ec6652e4887 | 0d833663aea62516a6add49277cc05a4f52c9847 | |||
v1.0 | instruct | Code_Contests | Code_Contests_12031_I | A rectangular grid is filled with non-negative integers. You need to write a program that finds the maximum sum of integers in any subgrid of the given grid. A subgrid is defined by any contiguous rectangular section of the grid.
Input:
The first line of the input contains two integers m and n, the number of rows and... | def max_sum_subgrid(grid):
"""
Returns the maximum sum of any subgrid in the given grid.
"""
if not grid or not grid[0]:
return 0
m, n = len(grid), len(grid[0])
max_sum = float('-inf')
for left in range(n):
temp = [0] * m
for right in range(left, n):
... | from solution import max_sum_subgrid
def test_small_grid():
grid = [
[1, 2, 3],
[4, 5, 6],
[7, 8, 9]
]
assert max_sum_subgrid(grid) == 45
def test_single_element_grid():
grid = [
[5]
]
assert max_sum_subgrid(grid) == 5
def test_all_negative_numbers():
grid ... | [
{
"docstring": "Returns the maximum sum of any subgrid in the given grid.",
"function_declaration": "def max_sum_subgrid(grid):",
"function_name": "max_sum_subgrid",
"parameter_list": "(grid)"
},
{
"docstring": "Returns the maximum sum of any subarray in the given array using Kadane's algori... | [
0,
0,
1,
0
] | 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": "def max_subgrid_sum(grid):\n def kadane(array):\n max_ending_here = max_so_far = array[0]\n for x in array[1:]:\n... | trial_gpt4o_3 | {
"original_instruction": "",
"prompt_id": "00012031",
"row_id": 12031,
"seed_ids": "[902]"
} | 0.689545 | Code_Contests_12031 | I | [
"max_sum_subgrid",
"kadane"
] | 2 | [
[
"max_sum_subgrid",
"kadane"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | d679c171b274c9de0c6e26a8a920795b44c53341 | 99facd19219c8b8d2028bfcffc6485e3efb838be | |||
v1.0 | instruct | Code_Contests | Code_Contests_12100_I | A village contains several houses connected by bidirectional roads. Each road has a certain length, which represents the time it takes to travel from one house to another. The village chief wants to ensure that every house is reachable from his house, which is labeled as house number 1, in at least one way, and he also... | from collections import defaultdict, deque
import sys
def bfs_min_time(N, adjacency_list):
dist = [-1] * (N + 1)
dist[1] = 0
queue = deque([1])
while queue:
current = queue.popleft()
for neighbor, time in adjacency_list[current]:
if dist[neighbor] == -1:
dis... | from solution import bfs_min_time, solve, process_input
def test_bfs_min_time():
test_cases = [
(4, [(1, 2, 5), (1, 3, 10), (2, 4, 3), (3, 4, 1)]),
(3, [(1, 2, 1), (1, 3, 4)])
]
expected_results = [
[5, 10, 8],
[1, 4]
]
for i, (N, roads) in enumerate(test_cases)... | [
{
"docstring": null,
"function_declaration": "def bfs_min_time(N, adjacency_list):",
"function_name": "bfs_min_time",
"parameter_list": "(N, adjacency_list)"
},
{
"docstring": null,
"function_declaration": "def solve(test_cases):",
"function_name": "solve",
"parameter_list": "(te... | [
1,
0,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from collections import defaultdict, deque\nimport sys\n\ndef bfs_min_time(N, adjacency_list):\n dist = [-1] * (N + 1)\n dist[1] = 0\n\n queue = d... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00012100",
"row_id": 12100,
"seed_ids": "[8295]"
} | 0.725637 | Code_Contests_12100 | I | [
"bfs_min_time",
"solve",
"process_input"
] | 3 | [
[
"solve",
"bfs_min_time"
]
] | 1 | [
"process_input"
] | false | [] | false | pytest | true | [] | true | fa179cb9ef2834e39329db5e01c87c87c76bb534 | 2ac5d7bb19d79db1036f101c646422aea2893464 | |||
v1.0 | instruct | Code_Contests | Code_Contests_12122_I | There is a special type of binary tree called a "Complete Binary Tree," in which every level, except possibly the last, is completely filled, and all nodes are as far left as possible.
You need to write a program that, given the in-order and pre-order traversal of a complete binary tree, reconstructs the original tre... | class Node:
def __init__(self, key):
self.left = None
self.right = None
self.val = key
def build_tree(inorder, preorder, inorder_start, inorder_end, preorder_index, in_index_map):
if inorder_start > inorder_end:
return None
root_val = preorder[preorder_index[0]]
preorde... | def test_solve():
assert solve(2, [(5, [4, 2, 5, 1, 3], [1, 2, 4, 5, 3]),
(7, [1, 2, 4, 5, 3, 6, 7], [3, 2, 1, 5, 4, 6, 7])]) == [
"4 5 2 3 1",
"1 4 5 2 7 6 3"
]
def test_single_node():
assert solve(1, [(1, [1], [1])]) == ["1"]
def test_two_nodes():
assert s... | [] | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def build_tree(in_order, pre_order, in_start, in_end, pre_index, in_index_map):\n if in_start > in_end:\n return None, pre_index\n \n # The... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00012122",
"row_id": 12122,
"seed_ids": "[6929]"
} | 0.571689 | Code_Contests_12122 | I | [
"build_tree",
"post_order_traversal",
"reconstruct_post_order",
"solve"
] | 4 | [
[
"reconstruct_post_order",
"build_tree"
],
[
"reconstruct_post_order",
"post_order_traversal"
],
[
"solve",
"reconstruct_post_order"
]
] | 3 | [] | false | [
"Node"
] | true | pytest | false | [] | true | a6e07fcaa1e6b281ddd756945610b387ea0fad23 | 004a2f118790db49839a22695189a8a1b6c5d45c | |||
v1.0 | instruct | Code_Contests | Code_Contests_12166_I | A **binary search tree (BST)** is a binary tree in which each node has at most two children. For any node $v$ with left subtree $L$ and right subtree $R$, all nodes in $L$ have values smaller than $v$, and all nodes in $R$ have values greater than $v$.
Given a list of integers, construct a BST by inserting the numbers... | 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 bst_in_order_traversal
def test_bst_in_order_traversal():
assert bst_in_order_traversal([5, 3, 7, 2, 4, 6, 8]) == [2, 3, 4, 5, 6, 7, 8]
assert bst_in_order_traversal([]) == []
assert bst_in_order_traversal([1]) == [1]
assert bst_in_order_traversal([5, 4, 6, 3, 7, 2, 8]) == [2, 3, 4... | [] | [
1,
1,
0
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from typing import List\n\nclass TreeNode:\n def __init__(self, val=0):\n self.val = val\n self.left = None\n self.right = None\n\n... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00012166",
"row_id": 12166,
"seed_ids": "[6872]"
} | 0.587824 | Code_Contests_12166 | I | [
"insert",
"bst_in_order_traversal"
] | 2 | [
[
"bst_in_order_traversal",
"insert"
]
] | 1 | [] | false | [
"TreeNode"
] | true | pytest | true | [] | true | 9302f8e0b1cad50781526e4d506734f924482ad3 | 993b873eac760fc0ba0dc14d804a431c88ad6f5d | |||
v1.0 | instruct | Code_Contests | Code_Contests_12191_I | You are given a list of integers where each integer represents the number of pages in a book. Your task is to divide these books into a given number of students in such a way that the maximum number of pages assigned to a student is minimized. Each student gets a contiguous sequence of books to read.
Write a function ... | def is_possible(pages, students, max_pages):
required_students = 1
current_pages = 0
for page in pages:
if current_pages + page > max_pages:
required_students += 1
current_pages = page
if required_students > students:
return False
else:
... | def test_find_minimized_maximum_pages():
assert find_minimized_maximum_pages([12, 34, 67, 90], 2) == 113
assert find_minimized_maximum_pages([10, 20, 30, 40], 2) == 60
assert find_minimized_maximum_pages([5, 17, 100, 11], 4) == 100
assert find_minimized_maximum_pages([12, 34, 67, 90], 3) == 90
asser... | [
{
"docstring": null,
"function_declaration": "def is_possible(pages, students, max_pages):",
"function_name": "is_possible",
"parameter_list": "(pages, students, max_pages)"
},
{
"docstring": null,
"function_declaration": "def find_minimized_maximum_pages(pages, students):",
"functio... | [
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_possible(pages, students, max_pages):\n required_students = 1\n current_pages = 0\n\n for page in pages:\n if current_pages + page >... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00012191",
"row_id": 12191,
"seed_ids": "[729]"
} | 0.713368 | Code_Contests_12191 | I | [
"is_possible",
"find_minimized_maximum_pages"
] | 2 | [
[
"find_minimized_maximum_pages",
"is_possible"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | cc4f97165542435040ef04aa0fcb04dc436170b9 | be25ed7ed7a6490f84e2e97e35f026067ebdf448 | |||
v1.0 | instruct | Code_Contests | Code_Contests_12198_I | Anna enjoys solving maze puzzles. She recently discovered a new type of maze where not all paths are visible from the start. She needs to use a special sequence to reveal paths as she moves through the maze. Help Anna find the shortest path from the starting point to the ending point in this special maze.
The maze is ... | from collections import deque
def generate_sequence(S0, P, Q, R, length):
sequence = [S0]
for _ in range(length - 1):
next_value = (sequence[-1] * P + Q) % R
sequence.append(next_value)
return sequence
def bfs(maze, sr, sc, er, ec, sequence):
n, m = len(maze), len(maze[0])
directio... | def test_shortest_path_in_maze_case_1():
T = 1
test_cases = [
(5, 5, [
".....",
".#...",
"....#",
".#.#.",
"....."],
0, 0, 4, 4, 1, 2, 3, 5)
]
expected = [8]
result = shortest_path_in_maze(T, test_cases)
assert result =... | [
{
"docstring": null,
"function_declaration": "def generate_sequence(S0, P, Q, R, length):",
"function_name": "generate_sequence",
"parameter_list": "(S0, P, Q, R, length)"
},
{
"docstring": null,
"function_declaration": "def bfs(maze, sr, sc, er, ec, sequence):",
"function_name": "bf... | [
0,
0,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from collections import deque\n\ndef generate_sequence(S0, P, Q, R, length):\n sequence = [S0]\n for _ in range(1, length):\n next_val = (sequ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00012198",
"row_id": 12198,
"seed_ids": "[6423]"
} | 0.621342 | Code_Contests_12198 | I | [
"generate_sequence",
"bfs",
"shortest_path_in_maze"
] | 3 | [
[
"shortest_path_in_maze",
"bfs"
],
[
"shortest_path_in_maze",
"generate_sequence"
]
] | 2 | [] | false | [] | false | pytest | false | [] | true | 6b67cb26afef29073c49a7cb872717c971e384fb | 0bbe33b2b6bda320cdd63b2b6cb743362be4cd2b | |||
v1.0 | instruct | Code_Contests | Code_Contests_12268_I | You are working on a software feature that occasionally needs to make API calls to fetch data. Each API call should return a JSON object that contains the following structure:
```json
{
"status": "ok" or "error",
"data": "the requested data" or null,
"error_message": "error description" or null
}
```
The ... | import time
def fetch_data(max_calls_per_minute: int) -> list:
"""
Fetches data from the API while adhering to the rate limit.
Parameters:
max_calls_per_minute (int): The maximum number of API calls allowed per minute.
Returns:
list: A list of all successfully fetched data.
"""
... | from solution import fetch_data, mock_api_call
def test_fetch_data_rate_limit():
data = fetch_data(10)
assert len(data) <= 10
assert all(d == "Some data" for d in data)
def test_fetch_data_handles_errors():
data = fetch_data(100)
assert len(data) <= 100
def test_fetch_data_rate_limit_exceeded():
... | [
{
"docstring": "Fetches data from the API while adhering to the rate limit.\n\nParameters:\nmax_calls_per_minute (int): The maximum number of API calls allowed per minute.\n\nReturns:\nlist: A list of all successfully fetched data.",
"function_declaration": "def fetch_data(max_calls_per_minute):",
"func... | [
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 time\n\ndef mock_api_call():\n import random\n if random.randint(1, 10) <= 2:\n return {\n \"status\": \"error\",\n ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00012268",
"row_id": 12268,
"seed_ids": "[11171]"
} | 0.575387 | Code_Contests_12268 | I | [
"fetch_data",
"mock_api_call"
] | 2 | [
[
"fetch_data",
"mock_api_call"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 026db868434f30674a60235fb2ab7afd0130ea2d | 0c492d07a8771c0889b26f8dbd92dd3fbf88e3fc | |||
v1.0 | instruct | Code_Contests | Code_Contests_12281_I | You are given a string s consisting of lowercase English letters, and a list of strings dictionary containing unique words. Your task is to determine how many distinct words from the dictionary can be formed as subsequences of s.
A subsequence of a string is a new string generated from the original string by deleting ... | def num_distinct_subsequences(s, dictionary):
def is_subsequence(s, word):
it = iter(s)
return all(char in it for char in word)
count = 0
for word in dictionary:
if is_subsequence(s, word):
count += 1
return count
# Function to process the input
def process_inpu... | from solution import num_distinct_subsequences
def test_example_1():
s = "abcde"
dictionary = ["a", "bb", "ace"]
assert num_distinct_subsequences(s, dictionary) == 2
def test_example_2():
s = "abcdef"
dictionary = ["ab", "cf", "ef", "gh"]
assert num_distinct_subsequences(s, dictionary) == 3
d... | [
{
"docstring": null,
"function_declaration": "def num_distinct_subsequences(s, dictionary):",
"function_name": "num_distinct_subsequences",
"parameter_list": "(s, dictionary)"
},
{
"docstring": null,
"function_declaration": "def process_input_and_compute(s, n, word_list):",
"function... | [
1,
0,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def num_distinct_subsequences(s, dictionary):\n def is_subsequence(s, word):\n it = iter(s)\n return all(char in it for char in word)\n ... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00012281",
"row_id": 12281,
"seed_ids": "[7643]"
} | 0.836467 | Code_Contests_12281 | I | [
"num_distinct_subsequences",
"process_input_and_compute"
] | 2 | [
[
"process_input_and_compute",
"num_distinct_subsequences"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 714fe93af760eb1e450b34f0065fd367a628d734 | 636ce8634d88b9895a6cccd921e635b6d88347dd | |||
v1.0 | instruct | Code_Contests | Code_Contests_12288_I | Little Hana loves solving mathematical puzzles, especially if it involves prime numbers. One day her friend Little Maya gave her an interesting challenge. Given a number `n`, Hana needs to find the largest prime number `p` such that `p <= n`. If no such prime number exists, she should return -1.
Hana quickly realized ... | def is_prime(n):
"""
Helper function to determine if a number n is prime.
"""
if n <= 1:
return False
if n == 2 or 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 F... | from solution import is_prime, largest_prime_leq
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(9) == False
assert is_prime(11) == True
assert is_prime(1) == False
def test_largest_prime_leq(... | [
{
"docstring": "Helper function to determine if a number n is prime.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Find the largest prime number less than or equal to n.\nReturns -1 if no such prime exists.",
"functi... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(n):\n if n <= 1:\n return False\n if n == 2:\n return True\n if n % 2 == 0:\n return False\n for i in range(3... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00012288",
"row_id": 12288,
"seed_ids": "[12463]"
} | 0.606122 | Code_Contests_12288 | I | [
"is_prime",
"largest_prime_leq"
] | 2 | [
[
"largest_prime_leq",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | a9741a465823829a994be3b5d0d1ef9ee685d3ab | e9c60ca43c9e2a024ca5479703006c3c2b0643a9 | |||
v1.0 | instruct | Code_Contests | Code_Contests_12361_I | You are given an integer array `arr` of size `n` consisting of positive integers. A subarray is defined as the contiguous portion of the array. A subarray is considered "beautiful" if the sum of its elements is a prime number. Write a function to determine the count of beautiful subarrays within the given array.
Input... | def is_prime(num):
"""
Helper function to check if a number is prime.
"""
if num <= 1:
return False
if num == 2:
return True
if num % 2 == 0:
return False
for i in range(3, int(num**0.5) + 1, 2):
if num % i == 0:
return False
return True
def c... | from solution import is_prime, count_beautiful_subarrays, main
def test_is_prime():
# Test some prime numbers
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(17) == True
assert is_prime(19) == True
# Test some non-prime numbers
assert is_prime(1) == False
assert i... | [
{
"docstring": "Helper function to check if a number is prime.",
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": "Function to count the number of beautiful subarrays for each test case.",
"function_declaration": "def ... | [
0,
0,
0,
0,
0,
1,
0,
0,
0,
0
] | 1 | hard | 0.1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(num):\n \"\"\"\n Check if a number is prime.\n \"\"\"\n if num <= 1:\n return False\n if num <= 3:\n return True\... | trial_gpt4o_5 | {
"original_instruction": "",
"prompt_id": "00012361",
"row_id": 12361,
"seed_ids": "[5133]"
} | 0.705334 | Code_Contests_12361 | I | [
"is_prime",
"count_beautiful_subarrays",
"main"
] | 3 | [
[
"count_beautiful_subarrays",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | d25990f3c0af807bc1f64ef90ffcd0db2a58b129 | e5f17b3dedc1cc9bd4d9b1c54ba107f46fd19be4 | |||
v1.0 | instruct | Code_Contests | Code_Contests_12396_I | Susan loves playing with numbers and is particularly fascinated with prime numbers. One day, she decides to create a game involving an array of integers. The game is played as follows:
1. Given an array of integers, Susan partitions the array into contiguous subarrays.
2. She checks if each subarray's sum is a prime n... | def is_prime(num):
if num <= 1:
return False
elif num <= 3:
return True
elif num % 2 == 0 or num % 3 == 0:
return False
i = 5
while i * i <= num:
if num % i == 0 or num % (i + 2) == 0:
return False
i += 6
return True
def can_be_partitioned(arr... | def test_is_prime():
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(4) == False
assert is_prime(11) == True
assert is_prime(-1) == False
def test_can_be_partitioned():
assert can_be_partitioned([2, 3, 5, 7]) == True
assert can_be_partitioned([1, -1, 3]) == False
a... | [
{
"docstring": null,
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": null,
"function_declaration": "def can_be_partitioned(arr):",
"function_name": "can_be_partitioned",
"parameter_list": "(arr)"
},
{
... | [
0,
0,
0,
0,
0,
0,
1,
1,
0,
0
] | 2 | hard | 0.2 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(n):\n \"\"\"\n Check if a number n is a prime number.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return ... | trial_gpt4o_7 | {
"original_instruction": "",
"prompt_id": "00012396",
"row_id": 12396,
"seed_ids": "[2299]"
} | 0.641598 | Code_Contests_12396 | I | [
"is_prime",
"can_be_partitioned",
"susans_game"
] | 3 | [
[
"can_be_partitioned",
"is_prime"
],
[
"susans_game",
"can_be_partitioned"
]
] | 2 | [] | false | [] | false | pytest | false | [] | true | 1a8de189b2af6880a9ba1f99d37f80df29205fe5 | ab969f1ddad88728244517a6caccbacc667f6adb | |||
v1.0 | instruct | Code_Contests | Code_Contests_12411_I | **Problem:**
A digital art auction house has n paintings available for a silent auction. Each painting has a minimum starting bid and can be bid on by multiple bidders throughout the auction period. At the end of the auction, each painting will be sold to the highest bidder.
Your task is to write a program that dete... | def total_revenue(num_paintings, min_bids, bids_list):
total = 0
for i in range(num_paintings):
num_bids = bids_list[i][0]
if num_bids == 0:
continue
highest_bid = max(bids_list[i][1:])
if highest_bid > min_bids[i]:
total += highest_bid
return total
d... | from solution import calculate_revenue
def test_example_case():
input_str = "3\n100 200 150\n2 130 140\n3 210 190 220\n1 160\n"
assert calculate_revenue(input_str) == 520
def test_no_bids():
input_str = "2\n100 200\n0\n0\n"
assert calculate_revenue(input_str) == 0
def test_all_below_minimum():
in... | [
{
"docstring": null,
"function_declaration": "def total_revenue(num_paintings, min_bids, bids_list):",
"function_name": "total_revenue",
"parameter_list": "(num_paintings, min_bids, bids_list)"
},
{
"docstring": null,
"function_declaration": "def parse_input(input_str):",
"function_n... | [
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 calculate_total_revenue(n, min_bids, bids):\n \"\"\"\n Calculate the total revenue by summing up the highest bids of each painting \n if the h... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00012411",
"row_id": 12411,
"seed_ids": "[10192]"
} | 0.653545 | Code_Contests_12411 | I | [
"total_revenue",
"parse_input",
"calculate_revenue"
] | 3 | [
[
"calculate_revenue",
"parse_input"
],
[
"calculate_revenue",
"total_revenue"
]
] | 2 | [
"parse_input"
] | false | [] | false | pytest | true | [] | true | a6a024f111a38a5b100aef09b715b9b1914f1b40 | d7c921a1d25bf8dc0f0219a3cc78da2be3ae21bf | |||
v1.0 | instruct | Code_Contests | Code_Contests_12444_I | You are given a grid with n rows and m columns. Each cell in the grid contains either a 0 or a 1. Your task is to transform this grid into a desired pattern using the following operation:
* Select any sub-grid of dimensions 2x2 and flip all the bits within this sub-grid (turn 0s into 1s and 1s into 0s).
The initial a... | def flip_subgrid(grid, x1, y1):
for i in range(2):
for j in range(2):
grid[x1 + i][y1 + j] = 1 - grid[x1 + i][y1 + j]
def transform_grid(n, m, initial, final):
ops = []
initial = [list(map(int, row)) for row in initial]
final = [list(map(int, row)) for row in final]
for i in ra... | from solution import transform_grid
def test_transform_grid_example_1():
n, m = 3, 3
initial = ["011", "101", "110"]
final = ["000", "111", "000"]
ops = transform_grid(n, m, initial, final)
assert len(ops) <= n * m # Ensure the number of operations is within bounds
for x1, y1, x2, y2 in ops:
... | [
{
"docstring": null,
"function_declaration": "def flip_subgrid(grid, x1, y1):",
"function_name": "flip_subgrid",
"parameter_list": "(grid, x1, y1)"
},
{
"docstring": null,
"function_declaration": "def transform_grid(n, m, initial, final):",
"function_name": "transform_grid",
"par... | [
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 transform_grid(n, m, initial, final):\n operations = []\n\n # Defining utility function to flip a 2x2 sub-grid\n def flip(x1, y1):\n fo... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00012444",
"row_id": 12444,
"seed_ids": "[11984]"
} | 0.742659 | Code_Contests_12444 | I | [
"flip_subgrid",
"transform_grid"
] | 2 | [
[
"transform_grid",
"flip_subgrid"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | a8ffa888fd897717bf41fe0b47e895b76d056a6f | 197d523c59a2ce91029ed46089a325b075660258 | |||
v1.0 | instruct | Code_Contests | Code_Contests_12479_I | In a small village, there is a unique marketplace where all the paths connecting the various shops form a tree. The local vendor, Rama, wants to maximize his profit by visiting exactly K unique shops in a single day, starting from his own shop (shop 1). However, to avoid exhaustion and plan his journey effectively, he ... | from collections import deque
def bfs_to_find_furthest(node, edges):
queue = deque([node])
visited = {node}
furthest_node = node
while queue:
current_node = queue.popleft()
furthest_node = current_node
for neighbor in edges[current_node]:
if neighbor not in visited:
... | from solution import max_distance_travel
def test_example_case():
assert max_distance_travel(5, 3, [(1, 2), (1, 3), (2, 4), (2, 5)]) == 2
def test_small_case():
assert max_distance_travel(3, 2, [(1, 2), (1, 3)]) == 1
def test_large_k_case():
assert max_distance_travel(4, 4, [(1, 2), (2, 3), (3, 4)]) == 3... | [
{
"docstring": null,
"function_declaration": "def bfs_to_find_furthest(node, edges):",
"function_name": "bfs_to_find_furthest",
"parameter_list": "(node, edges)"
},
{
"docstring": null,
"function_declaration": "def bfs_to_find_distance(node, target, edges, K):",
"function_name": "bfs... | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from collections import defaultdict, deque\n\ndef max_distance_to_k_shops(N, K, edges):\n if K == 1:\n return 0\n \n tree = defaultdict(lis... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00012479",
"row_id": 12479,
"seed_ids": "[6213]"
} | 0.659309 | Code_Contests_12479 | I | [
"bfs_to_find_furthest",
"bfs_to_find_distance",
"max_distance_travel"
] | 3 | [
[
"max_distance_travel",
"bfs_to_find_distance"
],
[
"max_distance_travel",
"bfs_to_find_furthest"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | cdcb5029319b0766fa38e8c4e62a57643fae32ea | 35aa66ce2699299ad09e40eb200c469df4e930cc | |||
v1.0 | instruct | Code_Contests | Code_Contests_12518_I | In a forest, there are N trees in a row, each with a certain height. Adjacent trees are fighting for sunlight, and the shorter tree between any two adjacent trees will die. This process repeats until no more trees can die because there are no more adjacent trees where one is shorter than the other. Trees of the same he... | def surviving_trees(trees):
while True:
new_trees = [trees[0]]
for i in range(1, len(trees)):
if trees[i] <= trees[i-1]:
new_trees.append(trees[i])
if len(new_trees) == len(trees):
return len(new_trees)
trees = new_trees
def solution(test_case... | from solution import solution, read_input
def test_solution_with_example_cases():
input_str = """2
6
1 3 2 1 4 5
5
4 4 4 4 4"""
test_cases = read_input(input_str)
results = solution(test_cases)
assert results == [2, 5]
def test_solution_with_all_same_height():
input_str = """1
4
2 2 2 2"""
tes... | [
{
"docstring": null,
"function_declaration": "def surviving_trees(trees):",
"function_name": "surviving_trees",
"parameter_list": "(trees)"
},
{
"docstring": null,
"function_declaration": "def solution(test_cases):",
"function_name": "solution",
"parameter_list": "(test_cases)"
... | [
0,
0,
0,
0,
0,
0,
0,
1,
0,
0
] | 1 | hard | 0.1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def surviving_trees(T, test_cases):\n \"\"\"\n Determines the number of surviving trees at the end of the process where shorter trees between any two... | trial_gpt4o_7 | {
"original_instruction": "",
"prompt_id": "00012518",
"row_id": 12518,
"seed_ids": "[6250]"
} | 0.714006 | Code_Contests_12518 | I | [
"surviving_trees",
"solution",
"read_input"
] | 3 | [
[
"solution",
"surviving_trees"
]
] | 1 | [
"read_input"
] | false | [] | false | pytest | true | [] | true | e0c2f45fe53fbeaef84cd8e2337a51342400fb96 | de2279808c802d41594dd4d1f46e47f9d86eef23 | |||
v1.0 | instruct | Code_Contests | Code_Contests_12590_I | In a small village, there is a network of N houses connected by M bidirectional roads. Each road connects two houses and has a certain weight representing the cost to travel that road.
The village head wants to ensure that there is a path to reach any house from any other house, but without spending too much. Hence, ... | def find(parent, i):
if parent[i] == i:
return i
return find(parent, parent[i])
def union(parent, rank, x, y):
root_x = find(parent, x)
root_y = find(parent, y)
if root_x != root_y:
if rank[root_x] > rank[root_y]:
parent[root_y] = root_x
elif rank[root_x] < ... | from solution import total_cost_of_mst
def test_example():
n = 4
m = 5
roads = [
(1, 2, 3),
(1, 3, 1),
(2, 3, 3),
(2, 4, 6),
(3, 4, 2)
]
assert total_cost_of_mst(n, m, roads) == 6
def test_single_road():
n = 2
m = 1
roads = [
(1, 2, 10)
... | [
{
"docstring": null,
"function_declaration": "def find(parent, i):",
"function_name": "find",
"parameter_list": "(parent, i)"
},
{
"docstring": null,
"function_declaration": "def union(parent, rank, x, y):",
"function_name": "union",
"parameter_list": "(parent, rank, x, y)"
},
... | [
0,
1,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "class DisjointSetUnion:\n def __init__(self, n):\n self.parent = list(range(n))\n self.rank = [1] * n\n\n def find(self, u):\n i... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00012590",
"row_id": 12590,
"seed_ids": "[3927]"
} | 0.76019 | Code_Contests_12590 | I | [
"find",
"union",
"kruskal_mst",
"total_cost_of_mst"
] | 4 | [
[
"kruskal_mst",
"find"
],
[
"kruskal_mst",
"union"
],
[
"total_cost_of_mst",
"kruskal_mst"
],
[
"union",
"find"
]
] | 4 | [] | false | [] | false | pytest | true | [] | true | cb28f897e7d65d69e0b167918ecd05bb2ec64191 | 406e1d5517d2c4057e4c957342155f2d2c9aa7fd | |||
v1.0 | instruct | Code_Contests | Code_Contests_12636_I | A secret agent wants to send encrypted messages to avoid the risk of being intercepted. He decides to use a substitution cipher to transform his messages. The strategy involves mapping each letter in the alphabet to its reverse counterpart, where 'a' becomes 'z', 'b' becomes 'y', and so on.
For example, given a senten... | def create_cipher_map():
"""
Creates a dictionary to map each letter to its reverse counterpart.
"""
from string import ascii_lowercase, ascii_uppercase
cipher_map = {}
for a, z in zip(ascii_lowercase, reversed(ascii_lowercase)):
cipher_map[a] = z
cipher_map[a.upper()] = z.u... | from solution import encrypt_message
def test_encrypt_message_simple():
assert encrypt_message("Hello World") == "Svool Dliow"
def test_encrypt_message_with_punctuation():
assert encrypt_message("Hello, World!") == "Svool, Dliow!"
def test_encrypt_message_all_lowercase():
assert encrypt_message("abcdefgh... | [
{
"docstring": "Creates a dictionary to map each letter to its reverse counterpart.",
"function_declaration": "def create_cipher_map():",
"function_name": "create_cipher_map",
"parameter_list": "()"
},
{
"docstring": "Encrypts the message using the substitution cipher strategy.\n\nParameters... | [
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 substitution_cipher(text):\n \"\"\"\n Encrypt the input text using a substitution cipher where each letter in the alphabet\n is mapped to its ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00012636",
"row_id": 12636,
"seed_ids": "[12570]"
} | 0.642315 | Code_Contests_12636 | I | [
"create_cipher_map",
"encrypt_message"
] | 2 | [
[
"encrypt_message",
"create_cipher_map"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | d009ccf7a94bb8d3f2ceb7e400b0e316279aacb9 | eada6e24c5c635b96fde7b93e370f47bd743cce8 | |||
v1.0 | instruct | Code_Contests | Code_Contests_12641_I | In a magical land, there are n floating islands connected by m magical bridges. Each bridge connects exactly two islands and has a certain fixed cost and fixed magical energy requirement to maintain it. The magical energy is supplied by a wizard, but his energy is limited. The wizard has only a certain amount of magica... | def find(parent, i):
if parent[i] == i:
return i
else:
parent[i] = find(parent, parent[i])
return parent[i]
def union(parent, rank, x, y):
xroot = find(parent, x)
yroot = find(parent, y)
if rank[xroot] < rank[yroot]:
parent[xroot] = yroot
elif rank[xroot] > rank... | def test_example_case_1():
n = 4
m = 5
bridge_data = [
(1, 2, 10, 5),
(2, 3, 15, 7),
(3, 4, 10, 6),
(4, 1, 20, 9),
(1, 3, 25, 8)
]
max_energy = 15
assert minimum_cost_to_connect_islands(n, m, bridge_data, max_energy) == 35
def test_example_case_2():
n... | [
{
"docstring": null,
"function_declaration": "def find(parent, i):",
"function_name": "find",
"parameter_list": "(parent, i)"
},
{
"docstring": null,
"function_declaration": "def union(parent, rank, x, y):",
"function_name": "union",
"parameter_list": "(parent, rank, x, y)"
},
... | [
0,
0,
0,
1
] | 1 | hard | 0.25 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def minimum_cost_to_connect_islands(n, m, bridges, max_energy):\n from heapq import heappush, heappop\n \n # Function to find the root of a node i... | trial_gpt4o_3 | {
"original_instruction": "",
"prompt_id": "00012641",
"row_id": 12641,
"seed_ids": "[1261]"
} | 0.729979 | Code_Contests_12641 | I | [
"find",
"union",
"kruskal",
"minimum_cost_to_connect_islands"
] | 4 | [
[
"kruskal",
"find"
],
[
"kruskal",
"union"
],
[
"minimum_cost_to_connect_islands",
"kruskal"
],
[
"union",
"find"
]
] | 4 | [] | false | [] | false | pytest | false | [] | true | f9218483a10748be2b574d607af8d8e835b88b2d | a44d494701d40fc95f3ff3fcbdaa339e4b76cd28 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.