version stringclasses 1
value | style stringclasses 2
values | subset stringclasses 12
values | question_id stringlengths 9 23 | question stringlengths 27 8.13k | solution stringlengths 99 5.97k | test stringlengths 105 4.45k | test_info listlengths 0 13 | gpt_pass_sequence listlengths 1 10 | gpt_pass_trial_num int64 1 10 | gpt_difficulty stringclasses 3
values | gpt_pass_percentage float64 0.1 1 | trials dict | chosen_trial stringclasses 10
values | metadata dict | benchmark_similarity float64 0.16 0.93 | benchmark_instruction stringclasses 1
value | benchmark_task_id stringclasses 1
value | filter_reason stringclasses 1
value | base_id stringlengths 7 21 | variant stringclasses 2
values | top_function_names listlengths 2 13 | n_top_functions int64 2 13 | helper_call_edges listlengths 1 16 | n_helper_call_edges int64 1 16 | harness_functions listlengths 0 3 | structural_wrapper bool 1
class | class_names listlengths 0 5 | has_class bool 2
classes | test_kind stringclasses 1
value | test_has_solution_import bool 2
classes | third_party_imports listlengths 0 5 | stdlib_only bool 2
classes | question_norm_sha1 stringlengths 40 40 | solution_ast_sha1 stringlengths 40 40 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
v1.0 | complete | Code_Contests | Code_Contests_2282_C | def minimal_total_cost(n, m, roads):
""" Determine the minimal total construction cost to connect all the intersections.
Args:
n (int): The number of intersections.
m (int): The number of proposed roads.
roads (list): List of tuples, where each tuple contains three integers u, v, and w.
... | 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] < ... | import pytest
from solution import minimal_total_cost
def test_minimal_total_cost_example1():
assert minimal_total_cost(4, 5, [
(1, 2, 1),
(1, 3, 4),
(2, 3, 6),
(2, 4, 5),
(3, 4, 3)
]) == 8
def test_minimal_total_cost_example2():
assert minimal_total_cost(3, 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,
1,
0
] | 1 | hard | 0.2 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def find(parent, i):\n if parent[i] == i:\n return i\n else:\n return find(parent, parent[i])\n\ndef union(parent, rank, x, y):\n xr... | trial_gpt4o_3 | {
"original_instruction": "The city of Greendale is undergoing a significant renovation project, and several roads are being built in a planned manner. However, due to budget constraints, not all proposed roads can be constructed immediately. Instead, the city council has decided to build as many roads as possible wh... | 0.632922 | Code_Contests_2282 | C | [
"find",
"union",
"minimal_total_cost"
] | 3 | [
[
"minimal_total_cost",
"find"
],
[
"minimal_total_cost",
"union"
],
[
"union",
"find"
]
] | 3 | [] | false | [] | false | pytest | true | [] | true | b7e0e28d9d81b1c3564143fcadbe0ba28368eafb | e88be84ab77b4d5a009f8352733bf54f43dffedd | |||
v1.0 | complete | Code_Contests | Code_Contests_3052_C | def rotate_sequence(seq, k):
"""
Returns the sequence rotated k places to the left.
"""
pass
def normalize_sequence(seq):
"""
Returns the normalized (canonical) form of the sequence by rotating it to the smallest lexicographical order.
"""
pass
def count_identical_flower_groups(n, m, f... | def rotate_sequence(seq, k):
"""
Returns the sequence rotated k places to the left.
"""
return seq[k:] + seq[:k]
def normalize_sequence(seq):
"""
Returns the normalized (canonical) form of the sequence by rotating it to the smallest lexicographical order.
"""
return min(rotate_sequence(... | from solution import rotate_sequence, normalize_sequence, count_identical_flower_groups
def test_rotate_sequence():
assert rotate_sequence([1, 2, 3, 4], 1) == [2, 3, 4, 1]
assert rotate_sequence([1, 2, 3, 4], 2) == [3, 4, 1, 2]
assert rotate_sequence([1, 2, 3, 4], 3) == [4, 1, 2, 3]
assert rotate_seque... | [
{
"docstring": "Returns the sequence rotated k places to the left.",
"function_declaration": "def rotate_sequence(seq, k):",
"function_name": "rotate_sequence",
"parameter_list": "(seq, k)"
},
{
"docstring": "Returns the normalized (canonical) form of the sequence by rotating it to the small... | [
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 number_of_flower_groups(n, m, petals):\n def canonical_rotation(flower):\n rotations = []\n for i in range(len(flower)):\n ... | trial_gpt4o_2 | {
"original_instruction": "A group of researchers are investigating a strange phenomenon involving magic flowers in an enchanted forest. Each flower displays petals with colors represented by integers. There are `n` flowers in total and each flower has exactly `m` petals. The flowers are considered identical if they ... | 0.534499 | Code_Contests_3052 | C | [
"rotate_sequence",
"normalize_sequence",
"count_identical_flower_groups"
] | 3 | [
[
"count_identical_flower_groups",
"normalize_sequence"
],
[
"normalize_sequence",
"rotate_sequence"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | a3da63b11ed9be1675a8b5b9159084c7ffb33073 | 588e4453c313895fc5cb8ddd7a8f527919bf3baf | |||
v1.0 | complete | Code_Contests | Code_Contests_1527_C | from collections import defaultdict, deque
def build_tree(N, labels, edges):
""" Build the tree representation from the given number of nodes, their labels, and edges.
Args:
- N: Number of nodes.
- labels: List containing labels for each node.
- edges: List of tuples representing edges between node... | from collections import defaultdict, deque
def build_tree(N, labels, edges):
tree = defaultdict(list)
node_labels = {i+1: labels[i] for i in range(N)}
for u, v in edges:
tree[u].append(v)
tree[v].append(u)
return tree, node_labels
def bfs(tree, start, end):
parent = {start: None}
... | def test_build_tree():
N = 5
labels = [1, 2, 3, 4, 5]
edges = [(1, 2), (1, 3), (2, 4), (2, 5)]
tree, node_labels = build_tree(N, labels, edges)
assert tree == {1: [2, 3], 2: [1, 4, 5], 3: [1], 4: [2], 5: [2]}
assert node_labels == {1: 1, 2: 2, 3: 3, 4: 4, 5: 5}
def test_bfs():
tree = {1: [2... | [
{
"docstring": null,
"function_declaration": "def build_tree(N, labels, edges):",
"function_name": "build_tree",
"parameter_list": "(N, labels, edges)"
},
{
"docstring": null,
"function_declaration": "def bfs(tree, start, end):",
"function_name": "bfs",
"parameter_list": "(tree, ... | [
1,
0,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from collections import defaultdict, deque\n\ndef build_tree(N, labels, edges):\n tree = defaultdict(list)\n node_labels = {i+1: labels[i] for i in r... | trial_gpt4o_0 | {
"original_instruction": "You are given a tree with N nodes and N-1 edges. Each node is labeled with a unique integer from 1 to N. You need to answer Q queries. Each query gives you two nodes u and v, and you need to find the sum of all nodes in the unique path from node u to node v in the tree.\n\nThe tree is repre... | 0.652912 | Code_Contests_1527 | C | [
"build_tree",
"bfs",
"path_sum",
"solve_tree_queries"
] | 4 | [
[
"path_sum",
"bfs"
],
[
"solve_tree_queries",
"build_tree"
],
[
"solve_tree_queries",
"path_sum"
]
] | 3 | [] | false | [] | false | pytest | false | [] | true | 4710f1d7ef8bf25b7468c78fd9c3ee41b06a4f88 | a575aa4073f0d1c340c01ae7020a4ea893664790 | |||
v1.0 | complete | Code_Contests | Code_Contests_3932_C | def minimum_cost_to_connect_castles(n: int, m: int, roads: List[Tuple[int, int, int]]) -> Union[int, str]:
""" Determine the minimum cost required to ensure every pair of castles is connected by constructing a Minimal Spanning Tree (MST).
>>> minimum_cost_to_connect_castles(4, 5, [(1, 2, 1), (1, 3, 4), (2,... | def find(parent, i):
if parent[i] == i:
return i
return find(parent, parent[i])
def union(parent, rank, x, y):
xroot = find(parent, x)
yroot = find(parent, y)
if rank[xroot] < rank[yroot]:
parent[xroot] = yroot
elif rank[xroot] > rank[yroot]:
parent[yroot] = xroot
... | from solution import minimum_cost_to_connect_castles
def test_example1():
n = 4
m = 5
roads = [
(1, 2, 1),
(1, 3, 4),
(2, 3, 2),
(3, 4, 3),
(1, 4, 5)
]
assert minimum_cost_to_connect_castles(n, m, roads) == 6
def test_example2():
n = 3
m = 1
road... | [
{
"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 else:\n parent[i] = find(parent, parent[i])\n return parent[i]\n\ndef uni... | trial_gpt4o_2 | {
"original_instruction": "In a distant kingdom, there are `n` castles connected by `m` bidirectional roads. Each road has a travel cost associated with it. The King decided to renovate the road network and needs to ensure that his knights can travel between any two castles at the minimum possible cost.\n\nAs the roy... | 0.674518 | Code_Contests_3932 | C | [
"find",
"union",
"minimum_cost_to_connect_castles"
] | 3 | [
[
"minimum_cost_to_connect_castles",
"find"
],
[
"minimum_cost_to_connect_castles",
"union"
],
[
"union",
"find"
]
] | 3 | [] | false | [] | false | pytest | true | [] | true | e801fe336136044f768b771e9078ff830d9e85f2 | faca3b2be8001cfe6b7bcdaab552b1176c42795d | |||
v1.0 | complete | Code_Contests | Code_Contests_3527_C | from typing import List, Tuple
from itertools import combinations
def is_prime(n: int) -> bool:
""" Checks if a number n is a prime number. """
# Implement the logic to check if n is a prime number
pass
def subset_prime_sum_exists(b: List[int]) -> str:
"""
Given a list of integers b, checks if th... | from itertools import combinations
def is_prime(n):
"""
Checks if a number n (n > 1) is prime.
"""
if n <= 1:
return False
if n <= 3:
return True
if n % 2 == 0 or n % 3 == 0:
return False
i = 5
while i * i <= n:
if n % i == 0 or n % (i + 2) == 0:
... | from solution import solve
def test_example_cases():
test_cases = [
(4, [1, 2, 3, 4]),
(3, [8, 10, 12]),
(5, [4, 3, 6, 9, 11])
]
results = solve(test_cases)
assert results == ["YES", "NO", "YES"]
def test_single_element_cases():
test_cases = [
(1, [2]),
(1, ... | [
{
"docstring": "Checks if a number n (n > 1) is prime.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Given a list of integers b, checks if there is a subset with a prime sum.",
"function_declaration": "def subset_pri... | [
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 combinations\nfrom math import isqrt\n\ndef is_prime(n):\n \"\"\"Returns True if n is a prime number, else False.\"\"\"\n if n ... | trial_gpt4o_2 | {
"original_instruction": "Zara, the Zebra, loves playing with numbers. She has recently come up with a fascinating number game involving prime numbers and sums.\n\nThe game starts with an array b of length m consisting of positive integers. Zara’s goal is to determine whether there exists a subset of numbers within ... | 0.665952 | Code_Contests_3527 | C | [
"is_prime",
"subset_prime_sum_exists",
"solve"
] | 3 | [
[
"solve",
"subset_prime_sum_exists"
],
[
"subset_prime_sum_exists",
"is_prime"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 7d6bc81045a6f5b358bdc2e93071f4148dd7a4ec | 5f539b69b6caa06ea3c49ff8a8d29e0cef9d3941 | |||
v1.0 | complete | Code_Contests | Code_Contests_3063_C | def calculate_product(x: int, y: int) -> int:
"""
Returns the product of x and y.
"""
return x * y
def parse_input(input_str: str) -> (int, int):
"""
Parses input in the form of a string with two large integers separated by a space.
Returns two integers.
"""
X_str, Y_str = input_str... | def calculate_product(x, y):
"""
Returns the product of x and y.
"""
return x * y
def parse_input(input_str):
"""
Parses input in the form of a string with two large integers separated by a space.
Returns two integers.
"""
X_str, Y_str = input_str.strip().split()
return int(X_st... | from solution import calculate_product, parse_input, product_of_large_numbers
def test_calculate_product():
assert calculate_product(3, 4) == 12
assert calculate_product(12345678901234567890, 98765432109876543210) == 1219326311370217952237463801111263526900
assert calculate_product(99999999999999999999, 99... | [
{
"docstring": "Returns the product of x and y.",
"function_declaration": "def calculate_product(x, y):",
"function_name": "calculate_product",
"parameter_list": "(x, y)"
},
{
"docstring": "Parses input in the form of a string with two large integers separated by a space.\nReturns two intege... | [
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 calculate_product(X, Y):\n \"\"\"\n Returns the product of two large positive integers X and Y.\n X and Y are given as strings to handle large... | trial_gpt4o_1 | {
"original_instruction": "Calculate the Product of Large Numbers\n\nGiven two positive integers $X$ and $Y$, compute the product, $X \\times Y$.\n\nInput\n\nTwo positive integers $X$ and $Y$ separated by a space character are given in a line.\n\nOutput\n\nPrint the product in a line.\n\nConstraints\n\n* $1 \\leq X, ... | 0.676933 | Code_Contests_3063 | C | [
"calculate_product",
"parse_input",
"product_of_large_numbers"
] | 3 | [
[
"product_of_large_numbers",
"calculate_product"
],
[
"product_of_large_numbers",
"parse_input"
]
] | 2 | [
"parse_input"
] | false | [] | false | pytest | true | [] | true | e92ae0fb1316c62716dd95b58ccce369ea2d535d | c8dcaeab59c0833dee26bc8b4a49f2d14afa3c42 | |||
v1.0 | complete | Code_Contests | Code_Contests_2652_C | def max_items_within_budget(budget, prices):
"""
Determine the maximum number of items that can be purchased within a given budget.
Args:
budget (int): The budget available for purchasing items.
prices (List[int]): List of prices of the items.
Returns:
int: The maximum number of ... | def max_items_within_budget(budget, prices):
prices.sort()
count = 0
total = 0
for price in prices:
if total + price <= budget:
total += price
count += 1
else:
break
return count
def solve_max_items(test_cases):
results = []
for budget, n,... | from solution import max_items_within_budget, solve_max_items, parse_input, format_output
def test_max_items_simple_case():
assert max_items_within_budget(50, [10, 20, 30, 40, 50]) == 2
def test_max_items_within_budget():
assert max_items_within_budget(75, [10, 20, 30, 40, 50]) == 3
assert max_items_withi... | [
{
"docstring": null,
"function_declaration": "def max_items_within_budget(budget, prices):",
"function_name": "max_items_within_budget",
"parameter_list": "(budget, prices)"
},
{
"docstring": null,
"function_declaration": "def solve_max_items(test_cases):",
"function_name": "solve_ma... | [
1,
1,
0
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def max_items_within_budget(T, test_cases):\n results = []\n\n for case in test_cases:\n budget, num_items, prices = case\n prices.sort... | trial_gpt4o_1 | {
"original_instruction": "Problem Statement:\n\nSarah has a list of items she needs to buy. Each item has a specific price, and she can only afford to spend up to a certain amount of money. She wants to maximize the number of items she can buy without exceeding her budget.\n\nYour task is to help Sarah determine the... | 0.604886 | Code_Contests_2652 | C | [
"max_items_within_budget",
"solve_max_items",
"parse_input",
"format_output"
] | 4 | [
[
"solve_max_items",
"max_items_within_budget"
]
] | 1 | [
"parse_input",
"format_output"
] | false | [] | false | pytest | true | [] | true | 4590567257c4a09bd04f9dbe2e7952fb4f23e445 | f2d690126e1acb2dbd8f1e415d481ab4fda54f2b | |||
v1.0 | complete | Code_Contests | Code_Contests_1871_C | def knapsack(max_capacity, weights, values, n):
# Helper function to solve 0/1 Knapsack problem using Dynamic Programming
dp = [[0 for x in range(max_capacity + 1)] for x in range(n + 1)]
for i in range(n + 1):
for w in range(max_capacity + 1):
if i == 0 or w == 0:
d... | def knapsack(max_capacity, weights, values, n):
dp = [[0 for x in range(max_capacity + 1)] for x in range(n + 1)]
for i in range(n + 1):
for w in range(max_capacity + 1):
if i == 0 or w == 0:
dp[i][w] = 0
elif weights[i-1] <= w:
dp[i][w] = max(val... | from solution import main
def test_case1(capfd):
input_data = '2\n50\n3\n10 60\n20 100\n30 120\n60\n2\n40 100\n50 140\n'
expected_output = '220\n140\n'
main(input_data)
out, _ = capfd.readouterr()
assert out == expected_output
def test_case2(capfd):
input_data = '1\n50\n1\n10 60\n'
expecte... | [
{
"docstring": null,
"function_declaration": "def knapsack(max_capacity, weights, values, n):",
"function_name": "knapsack",
"parameter_list": "(max_capacity, weights, values, n)"
},
{
"docstring": null,
"function_declaration": "def max_knapsack_value(test_cases):",
"function_name": ... | [
0,
0,
0,
1,
0
] | 1 | hard | 0.2 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def knapsack(W, items):\n \"\"\"\n Determines the maximum total value that can be achieved within the given weight capacity.\n \n Arguments:\n ... | trial_gpt4o_3 | {
"original_instruction": "Chris is participating in a game show where he has to maximize the value of his bag without exceeding its capacity. He is given a bag with a maximum capacity W and a list of items. Each item is characterized by its weight w and value v. Chris can only take items that will fit in the bag wit... | 0.585802 | Code_Contests_1871 | C | [
"knapsack",
"max_knapsack_value",
"parse_input",
"main"
] | 4 | [
[
"max_knapsack_value",
"knapsack"
]
] | 1 | [
"parse_input"
] | false | [] | false | pytest | true | [] | true | fec76b2dc043f12be97eaebaa8fdb377297f37c3 | fc3a7959755b4899221bb2cb1303ab6bccf00fe5 | |||
v1.0 | complete | Code_Contests | Code_Contests_2463_C | def warehouse_connectivity(n, m, roads, q, queries):
""" Determine if warehouses in a network are still connected given some roads are disabled.
Parameters:
n (int): The number of warehouses.
m (int): The number of roads.
roads (List[Tuple[int, int]]): A list of tuples representing roads between wa... | class DisjointSetUnion:
def __init__(self, n):
self.parent = list(range(n))
self.rank = [1] * n
def find(self, x):
if self.parent[x] != x:
self.parent[x] = self.find(self.parent[x])
return self.parent[x]
def union(self, x, y):
rootX = self.find(x)
... | from solution import warehouse_connectivity
def test_case_1():
assert warehouse_connectivity(5, 4, [(1, 2), (2, 3), (3, 4), (4, 5)], 3, [(1, 5), (2, 4), (1, 3)]) == ["YES", "YES", "YES"]
def test_case_2():
assert warehouse_connectivity(5, 3, [(1, 2), (2, 3), (4, 5)], 2, [(1, 3), (1, 5)]) == ["YES", "NO"]
def... | [] | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "class DisjointSetUnion:\n def __init__(self, n):\n self.parent = list(range(n))\n self.rank = [1] * n\n\n def find(self, x):\n i... | trial_gpt4o_0 | {
"original_instruction": "A company has designed a network of warehouses for effective goods distribution. Each warehouse has a single unique road leading in and out, connecting to other warehouses. The company's goal is to ensure that each warehouse is reachable from any other warehouse through a series of connecti... | 0.631757 | Code_Contests_2463 | C | [
"process_queries",
"warehouse_connectivity"
] | 2 | [
[
"warehouse_connectivity",
"process_queries"
]
] | 1 | [
"process_queries"
] | false | [
"DisjointSetUnion"
] | true | pytest | true | [] | true | a386f9b725c65be2f35046651b0b77e7bd3c7f77 | 837f0591e1311dc88388aa02819f8fb65a88ba69 | |||
v1.0 | complete | Code_Contests | Code_Contests_3801_C | def can_add_event(existing_events: List[Tuple[str, str]], new_event: Tuple[str, str]) -> bool:
""" Determine if a new event can be added without conflicting with existing events.
existing_events: List[Tuple[str, str]] - list of tuples representing current events in "HH:MM" format
new_event: Tuple[str, ... | def to_minutes(time):
hours, minutes = map(int, time.split(":"))
return hours * 60 + minutes
def can_add_event(existing_events, new_event):
new_start = to_minutes(new_event[0])
new_end = to_minutes(new_event[1])
for event in existing_events:
start = to_minutes(event[0])
end = to_mi... | def test_can_add_event_no_overlap():
existing_events = [("09:00", "10:30"), ("11:00", "12:00"), ("14:00", "15:30")]
new_event = ("12:15", "13:45")
assert can_add_event(existing_events, new_event) == True
def test_can_add_event_overlap():
existing_events = [("09:00", "10:30"), ("11:00", "12:00"), ("14:0... | [
{
"docstring": null,
"function_declaration": "def to_minutes(time):",
"function_name": "to_minutes",
"parameter_list": "(time)"
},
{
"docstring": null,
"function_declaration": "def can_add_event(existing_events, new_event):",
"function_name": "can_add_event",
"parameter_list": "(... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def can_add_event(existing_events, new_event):\n \"\"\"\n Checks if a new event can be added to the existing events list without any time conflicts.\... | trial_gpt4o_2 | {
"original_instruction": "A company has an event scheduling system that allows employees to create, edit, or cancel events. Each event is represented by its start time and end time. However, events cannot overlap; that is, an employee cannot have two events scheduled at the same time.\n\nYou are given a list of even... | 0.562474 | Code_Contests_3801 | C | [
"to_minutes",
"can_add_event"
] | 2 | [
[
"can_add_event",
"to_minutes"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | a5292a767199ca444a4ee72f193ffd6f300a453b | 75f76b3296208666d0e3b49fd74a4ec1e27c065b | |||
v1.0 | complete | Code_Contests | Code_Contests_3594_C | def find_odd_occurrence(arr):
""" Returns the integer that occurs odd number of times in the array.
>>> find_odd_occurrence([1, 2, 3, 2, 3])
1
>>> find_odd_occurrence([4, 4, 4, 5, 5, 5, 5])
4
>>> find_odd_occurrence([10])
10
>>> find_odd_occurrence([2, 2, 3, 3, 4])
4
>>> find_odd... | def find_odd_occurrence(arr):
"""
Returns the integer that occurs odd number of times in the array.
"""
result = 0
for number in arr:
result ^= number
return result
def find_odd_occurrence_from_input(input_str):
"""
Processes the input string and returns the integer that occurs ... | def test_find_odd_occurrence():
assert find_odd_occurrence([1, 2, 3, 2, 3]) == 1
assert find_odd_occurrence([4, 4, 4, 5, 5, 5, 5]) == 4
assert find_odd_occurrence([10]) == 10
assert find_odd_occurrence([2, 2, 3, 3, 4]) == 4
assert find_odd_occurrence([9, 12, 12, 9, 15, 15, 16, 16, 16]) == 16
def te... | [
{
"docstring": "Returns the integer that occurs odd number of times in the array.",
"function_declaration": "def find_odd_occurrence(arr):",
"function_name": "find_odd_occurrence",
"parameter_list": "(arr)"
},
{
"docstring": "Processes the input string and returns the integer that occurs odd... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def find_odd_occurrence(arr):\n \"\"\"\n Finds the integer which occurs odd number of times in the array.\n \n Args:\n arr: List of integers... | trial_gpt4o_2 | {
"original_instruction": "You are given an array of integers. One integer from the array occurs odd number of times while all others occur even number of times. Find the integer which occurs odd number of times.\n\nInput\n\nThe first line contains a single integer n (1 ≤ n ≤ 10^5), the number of elements in the arra... | 0.77862 | Code_Contests_3594 | C | [
"find_odd_occurrence",
"find_odd_occurrence_from_input"
] | 2 | [
[
"find_odd_occurrence_from_input",
"find_odd_occurrence"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | d29d7eb9558ba4f997c48fa2501f7117bbc0e4f0 | 65717786c38b4ba004c37e414e261e4d74868dcd | |||
v1.0 | complete | Code_Contests | Code_Contests_3452_C | from typing import List, Tuple
def earliest_password_reset(T: int, test_cases: List[Tuple[int, List[int]]]) -> List[int]:
"""
Alex and Sam are working on a security system that requires them to periodically update their credentials.
They have multiple passwords, each with a unique reset interval. They wan... | from math import gcd
from functools import reduce
def lcm(a, b):
return abs(a * b) // gcd(a, b)
def lcm_multiple(numbers):
return reduce(lcm, numbers)
def earliest_password_reset(T, test_cases):
results = []
modulo = 1000000007
for i in range(T):
n, intervals = test_cases[i]
resul... | from solution import earliest_password_reset
def test_earliest_password_reset():
T = 1
test_cases = [(3, [5, 10, 15])]
assert earliest_password_reset(T, test_cases) == [30]
def test_single_interval():
T = 1
test_cases = [(1, [7])]
assert earliest_password_reset(T, test_cases) == [7]
def test_... | [
{
"docstring": null,
"function_declaration": "def lcm(a, b):",
"function_name": "lcm",
"parameter_list": "(a, b)"
},
{
"docstring": null,
"function_declaration": "def lcm_multiple(numbers):",
"function_name": "lcm_multiple",
"parameter_list": "(numbers)"
},
{
"docstring":... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import math\n\nMOD = 1000000007\n\ndef lcm(a, b):\n return (a * b) // math.gcd(a, b)\n\ndef find_reset_time(n, intervals):\n reset_time = intervals[0... | trial_gpt4o_2 | {
"original_instruction": "Alex and Sam are working on a security system that requires them to periodically update their credentials. They have multiple passwords, each with a unique reset interval. They want to find the earliest time when all passwords will need to be reset simultaneously after a certain starting po... | 0.588592 | Code_Contests_3452 | C | [
"lcm",
"lcm_multiple",
"earliest_password_reset"
] | 3 | [
[
"earliest_password_reset",
"lcm_multiple"
],
[
"lcm_multiple",
"lcm"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 0bbdea5b9c962321f3da467cd6c8c3a4370b4788 | 2b40e1905180968d4e48ce5fe0ddf9207e61320f | |||
v1.0 | complete | Code_Contests | Code_Contests_3474_C | class TreeNode:
def __init__(self, value):
self.value = value
self.left = None
self.right = None
def build_tree_from_input(input_lines):
nodes = {}
for line in input_lines:
if line == '-1 -1 -1':
break
value, left, right = map(int, line.split())
i... | class TreeNode:
def __init__(self, value):
self.value = value
self.left = None
self.right = None
def build_tree_from_input(input_lines):
nodes = {}
for line in input_lines:
if line == '-1 -1 -1':
break
value, left, right = map(int, line.split())
i... | from solution import solution
def test_balanced_tree():
input_lines = [
"1 2 3",
"2 -1 4",
"4 -1 -1",
"3 -1 5",
"5 -1 -1",
"-1 -1 -1"
]
assert solution(input_lines) == "YES"
def test_unbalanced_tree():
input_lines = [
"1 2 3",
"2 4 -1",
... | [] | [
1,
1,
0
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "class TreeNode:\n def __init__(self, value):\n self.value = value\n self.left = None\n self.right = None\n\ndef build_tree_from_inp... | trial_gpt4o_0 | {
"original_instruction": "In a distant land, there lived a passionate gardener named Sofia, who loved to plant trees in her garden. Sofia's favorite type of tree is the \"Binary Tree.\" A Binary Tree is a data structure in which each node has at most two children, typically distinguished as \"left\" and \"right.\"\n... | 0.701355 | Code_Contests_3474 | C | [
"build_tree_from_input",
"is_balanced",
"solution"
] | 3 | [
[
"solution",
"build_tree_from_input"
],
[
"solution",
"is_balanced"
]
] | 2 | [] | false | [
"TreeNode"
] | true | pytest | true | [] | true | 0ff151e51ced5764ab59185a847f0adcbbffda06 | 692c910a84ba9c33f8a0f0c598617e61abf5e84f | |||
v1.0 | complete | Code_Contests | Code_Contests_3951_C | from typing import List
def fibonacci(n: int) -> int:
"""
Returns the nth Fibonacci number.
>>> fibonacci(0) 0
>>> fibonacci(1) 1
>>> fibonacci(2) 1
>>> fibonacci(3) 2
>>> fibonacci(4) 3
>>> fibonacci(5) 5
"""
def total_score(n: int, problems: List[int]) -> int:
"""
Ret... | def fibonacci(n):
"""
Returns the nth Fibonacci number.
"""
a, b = 0, 1
for _ in range(n):
a, b = b, a + b
return a
def total_score(n, problems):
"""
Returns the total score accumulated based on the solved problems' Fibonacci indices.
"""
total = 0
for p in problems:... | from solution import fibonacci, total_score
def test_fibonacci():
assert fibonacci(0) == 0
assert fibonacci(1) == 1
assert fibonacci(2) == 1
assert fibonacci(3) == 2
assert fibonacci(4) == 3
assert fibonacci(5) == 5
assert fibonacci(6) == 8
assert fibonacci(7) == 13
assert fibonacci... | [
{
"docstring": "Returns the nth Fibonacci number.",
"function_declaration": "def fibonacci(n):",
"function_name": "fibonacci",
"parameter_list": "(n)"
},
{
"docstring": "Returns the total score accumulated based on the solved problems' Fibonacci indices.",
"function_declaration": "def to... | [
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 fibonacci(n):\n # Function to return nth Fibonacci number\n if n == 0:\n return 0\n elif n == 1:\n return 1\n a, b = 0, 1\n ... | trial_gpt4o_2 | {
"original_instruction": "Sarah is a software engineer who participates in a coding contest every month. In each contest, she can solve a variable number of problems. By solving these problems, Sarah accumulates points that correspond to the difficulty level of each problem. The contest organizers have a unique scor... | 0.731986 | Code_Contests_3951 | C | [
"fibonacci",
"total_score"
] | 2 | [
[
"total_score",
"fibonacci"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | ae86d31f68bfc1e73640fc5c6d246581a1161128 | ba393c224f70fa5a262fb0636d356c3de72eddc1 | |||
v1.0 | complete | Code_Contests | Code_Contests_3901_C | def minimum_pipelines_required(n: int, m: int, pipelines: List[Tuple[int, int]]) -> str:
""" Determine if any sector can be designated as a central hub such that all other sectors are either directly connected to it or can be reached through a series of pipelines.
>>> minimum_pipelines_required(5, 3, [(1, ... | def find_connected_components(n, pipelines):
from collections import defaultdict, deque
graph = defaultdict(list)
for u, v in pipelines:
graph[u].append(v)
graph[v].append(u)
visited = [False] * (n + 1)
components = 0
def bfs(node):
queue = deque([... | from solution import minimum_pipelines_required
def test_example_1():
assert minimum_pipelines_required(5, 3, [(1, 2), (2, 3), (4, 5)]) == "Yes 1"
def test_example_2():
assert minimum_pipelines_required(6, 5, [(1, 2), (2, 3), (3, 4), (4, 5), (5, 6)]) == "Yes 0"
def test_example_3():
assert minimum_pipeli... | [
{
"docstring": null,
"function_declaration": "def find_connected_components(n, pipelines):",
"function_name": "find_connected_components",
"parameter_list": "(n, pipelines)"
},
{
"docstring": null,
"function_declaration": "def minimum_pipelines_required(n, m, pipelines):",
"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 find_connected_components(n, pipelines):\n from collections import defaultdict, deque\n \n graph = defaultdict(list)\n \n for u, v in pi... | trial_gpt4o_0 | {
"original_instruction": "In a galaxy far away, there is a circular planet known as Planet X which is divided into n sectors numbered from 1 to n. Each sector has a unique resource, and the inhabitants of Planet X have built m pipelines to distribute these resources among the sectors. Each pipeline can only connect ... | 0.593844 | Code_Contests_3901 | C | [
"find_connected_components",
"minimum_pipelines_required"
] | 2 | [
[
"minimum_pipelines_required",
"find_connected_components"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | c392a68d620b0ac287ec55ce914dc157e8b35de0 | 940cf4e7c9f7d84233fb9508fe5eac478c63808a | |||
v1.0 | complete | Code_Contests | Code_Contests_3740_C | def sum_of_digits(n):
"""
Returns the sum of the digits of a number n.
>>> sum_of_digits(123) 6
>>> sum_of_digits(29) 11
>>> sum_of_digits(7) 7
>>> sum_of_digits(11111) 5
"""
...
def g(a):
"""
Transforms the sequence a by replacing each element with the sum of its digits.
>>... | def sum_of_digits(n):
"""
Returns the sum of the digits of a number n.
"""
return sum(int(digit) for digit in str(n))
def g(a):
"""
Transforms the sequence a by replacing each element with the sum of its digits.
"""
return [sum_of_digits(num) for num in a]
def find_Ym(Y, m):
"""
... | from solution import sum_of_digits, g, find_Ym, Y_sequence
def test_sum_of_digits():
assert sum_of_digits(123) == 6
assert sum_of_digits(29) == 11
assert sum_of_digits(7) == 7
assert sum_of_digits(11111) == 5
def test_g():
assert g([123, 29, 7]) == [6, 11, 7]
assert g([999]) == [27]
assert... | [
{
"docstring": "Returns the sum of the digits of a number n.",
"function_declaration": "def sum_of_digits(n):",
"function_name": "sum_of_digits",
"parameter_list": "(n)"
},
{
"docstring": "Transforms the sequence a by replacing each element with the sum of its digits.",
"function_declara... | [
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 digit_sum(n):\n \"\"\"\n Returns the sum of the digits of number n in base-10 representation.\n \"\"\"\n return sum(int(digit) for digit in... | trial_gpt4o_1 | {
"original_instruction": "Alice is a researcher and developer who specializes in exploring sequences and their properties. She recently encountered a sequence transformation problem and needs your assistance.\n\nDefine a function g(a) where `a` is a sequence of positive integers. Function g(a) returns the transforme... | 0.68349 | Code_Contests_3740 | C | [
"sum_of_digits",
"g",
"find_Ym",
"Y_sequence"
] | 4 | [
[
"Y_sequence",
"find_Ym"
],
[
"find_Ym",
"g"
],
[
"g",
"sum_of_digits"
]
] | 3 | [] | false | [] | false | pytest | true | [] | true | 47d43acf14c2017f873878bce3a2df6efcbb00bc | c9dd84488f06637ae26b60d77d3ab326275c57c5 | |||
v1.0 | complete | Code_Contests | Code_Contests_4100_C | def rescue_robot(messages):
""" Determines if a robot can accomplish its mission in a gridded terrain.
The mission involves reaching a target location and returning to the starting position.
Input is taken from standard input in multiple datasets, with each dataset representing
the structure of th... | def parse_grid():
import sys
input = sys.stdin.read
data = input().splitlines()
index = 0
results = []
while True:
width, height = map(int, data[index].split())
if width == 0 and height == 0:
break
grid = []
for i in range(1, height + 1):
... | def test_rescue_robot():
import sys
from io import StringIO
# Original stdin
original_stdin = sys.stdin
# Sample input
input_data = """\
5 3
#####
#S.T#
#####
5 3
#####
#S#T#
#####
0 0
"""
sys.stdin = StringIO(input_data)
# Sample output
expected_output = [
"T... | [
{
"docstring": null,
"function_declaration": "def parse_grid():",
"function_name": "parse_grid",
"parameter_list": "()"
},
{
"docstring": null,
"function_declaration": "def find_position(grid, char):",
"function_name": "find_position",
"parameter_list": "(grid, char)"
},
{
... | [
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 is_within_bounds(x, y, width, height):\n return 0 <= x < width and 0 <= y < height\n\ndef bfs(grid, start, target):... | trial_gpt4o_1 | {
"original_instruction": "Rescue the Robot\n\nIn a distant future, there are automated robots designed to explore and gather data from various terrains. Unfortunately, one of the robots has malfunctioned during its mission on a gridded terrain. Your task is to design a program that can help this robot reach the targ... | 0.465818 | Code_Contests_4100 | C | [
"parse_grid",
"find_position",
"valid_moves",
"bfs",
"rescue_robot"
] | 5 | [
[
"bfs",
"valid_moves"
],
[
"rescue_robot",
"bfs"
],
[
"rescue_robot",
"find_position"
],
[
"rescue_robot",
"parse_grid"
]
] | 4 | [] | false | [] | false | pytest | false | [] | true | 8de08a6d5c86ab193b19b3b66d5e40765d7befd2 | a107c74d0cf79d9c1d229f41d854f2b15ad64f92 | |||
v1.0 | complete | Code_Contests | Code_Contests_3736_C | def find_prime_factors(n):
"""
Returns the list of prime factors of n.
"""
def max_prime_factor_diff(n):
"""
Returns the maximum difference between any two prime factors of n.
"""
def process_test_cases(test_cases):
"""
Processes multiple test cases and returns the results.
"""
... | def find_prime_factors(n):
"""
Returns the list of prime factors of n.
"""
prime_factors = []
# Check for number of 2s that divide n
while n % 2 == 0:
prime_factors.append(2)
n = n // 2
# n must be odd at this point so a skip of 2 (i = i + 2) can be used
for i in ran... | import pytest
from solution import find_prime_factors, max_prime_factor_diff, process_test_cases
def test_find_prime_factors():
assert find_prime_factors(6) == [2, 3]
assert find_prime_factors(15) == [3, 5]
assert find_prime_factors(13) == [13]
assert find_prime_factors(28) == [2, 7]
assert find_pr... | [
{
"docstring": "Returns the list of prime factors of n.",
"function_declaration": "def find_prime_factors(n):",
"function_name": "find_prime_factors",
"parameter_list": "(n)"
},
{
"docstring": "Returns the maximum difference between any two prime factors of n.",
"function_declaration": "... | [
0,
0,
0,
0,
0,
0,
0,
0,
0,
1
] | 1 | hard | 0.1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def sieve_of_eratosthenes(limit):\n is_prime = [True] * (limit + 1)\n p = 2\n while p * p <= limit:\n if is_prime[p]:\n for i in... | trial_gpt4o_9 | {
"original_instruction": "In a far-off kingdom, there resides a wise mathematician named Aria. Aria loves playing with numbers, especially focusing on prime numbers and their properties. She has recently discovered an interesting property concerning prime factors and wants to explore it further.\n\nGiven an integer ... | 0.642773 | Code_Contests_3736 | C | [
"find_prime_factors",
"max_prime_factor_diff",
"process_test_cases"
] | 3 | [
[
"max_prime_factor_diff",
"find_prime_factors"
],
[
"process_test_cases",
"max_prime_factor_diff"
]
] | 2 | [
"process_test_cases"
] | false | [] | false | pytest | true | [] | true | 296ba3144444350a92749611ea855393fd011a08 | 7d2debfb369ab7384484a27d0cb6f7b8f8132ea5 | |||
v1.0 | complete | Code_Contests | Code_Contests_4048_C | from typing import List
def max_fruits_per_day(N: int, fruits: List[int]) -> int:
""" Calculate the maximum number of fruits Alice can eat per day, ensuring she never runs out of fruits by the end of the N-th day.
>>> max_fruits_per_day(5, [7, 3, 4, 6, 2])
4
>>> max_fruits_per_day(3, [5, 2, 10])
3
... | def max_fruits_per_day(N, fruits):
low, high = 0, max(fruits)
result = 0
while low <= high:
mid = (low + high) // 2
if can_consume(mid, N, fruits):
result = mid
low = mid + 1
else:
high = mid - 1
return result
def can_consume(k, N, fruits... | from solution import max_fruits_per_day
def test_example_1():
assert max_fruits_per_day(5, [7, 3, 4, 6, 2]) == 4
def test_example_2():
assert max_fruits_per_day(3, [5, 2, 10]) == 3
def test_example_3():
assert max_fruits_per_day(4, [6, 6, 6, 6]) == 6
def test_single_day():
assert max_fruits_per_day(... | [
{
"docstring": null,
"function_declaration": "def max_fruits_per_day(N, fruits):",
"function_name": "max_fruits_per_day",
"parameter_list": "(N, fruits)"
},
{
"docstring": null,
"function_declaration": "def can_consume(k, N, fruits):",
"function_name": "can_consume",
"parameter_l... | [
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": "def max_fruits_per_day(N, fruits):\n low, high = 0, max(fruits)\n result = 0\n \n while low <= high:\n mid = (low + high) // 2\n ... | trial_gpt4o_0 | {
"original_instruction": "N is a positive integer indicating the number of days Alice wants to save fruits for, inclusive of the first day.\n\nEach day, starting from the first day, a certain number of fruits will be added to her stockpile.\n\nHer goal is to eat the maximum number of fruits each day, so that her sto... | 0.658419 | Code_Contests_4048 | C | [
"max_fruits_per_day",
"can_consume"
] | 2 | [
[
"max_fruits_per_day",
"can_consume"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 8eb1a632db703f5f5fd5b6dd6fb00c67dba1b08c | b56d300752fed4e32eae56bbaf03866149aa77de | |||
v1.0 | complete | Code_Contests | Code_Contests_4010_C | import re
from collections import Counter
from typing import List
def can_form_palindrome(s: str) -> str:
"""
Returns "YES" if the characters in the string s can be rearranged to form a palindrome, otherwise "NO".
>>> can_form_palindrome('A Santa at Nasa')
'YES'
>>> can_form_palindrome("Madam In E... | import re
from collections import Counter
def can_form_palindrome(s):
"""
Returns "YES" if the characters in the string s can be rearranged to form a palindrome, otherwise "NO".
"""
# Remove non-alphabetic characters and convert to lower case
cleaned_str = re.sub(r'[^a-zA-Z]', '', s).lower()
... | from solution import can_form_palindrome, check_palindrome_formation
def test_is_palindrome_rearrangeable():
assert can_form_palindrome('A Santa at Nasa') == 'YES'
assert can_form_palindrome("Madam In Eden, I'm Adam") == 'YES'
assert can_form_palindrome('A man, a plan, a canal, Panama!') == 'YES'
asser... | [
{
"docstring": "Returns \"YES\" if the characters in the string s can be rearranged to form a palindrome, otherwise \"NO\".",
"function_declaration": "def can_form_palindrome(s):",
"function_name": "can_form_palindrome",
"parameter_list": "(s)"
},
{
"docstring": null,
"function_declarati... | [
0,
1,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def can_form_palindrome(s):\n \"\"\"\n Given a string s, check if it can be rearranged to form a palindrome.\n Ignores spaces, punctuation, and is... | trial_gpt4o_2 | {
"original_instruction": "Create a program that, given a string of alphabets, checks if it can be transformed into a palindrome by rearranging its characters. A palindrome is a word, phrase, number, or other sequences of characters that reads the same forwards and backwards. You can ignore spaces, punctuation, and l... | 0.736373 | Code_Contests_4010 | C | [
"can_form_palindrome",
"check_palindrome_formation"
] | 2 | [
[
"check_palindrome_formation",
"can_form_palindrome"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | feccda696706d2c4eb2a818f2955de794c86673f | 4a85111c41a1194c2c56700c58418d9c98a84e1c | |||
v1.0 | complete | Code_Contests | Code_Contests_3098_C | def compute_prefix_sum(matrix):
""" Compute the prefix sum matrix. """
def subgrid_sum(prefix_sum, r1, c1, r2, c2):
""" Calculate the sum of the elements in the subgrid (r1, c1) to (r2, c2)
using the prefix sum matrix. """
def solve(R, C, Q, garden, queries):
"""
Calculate the subgrid magic value... | def compute_prefix_sum(matrix):
"""
Compute the prefix sum matrix.
"""
R = len(matrix)
C = len(matrix[0])
prefix_sum = [[0] * (C + 1) for _ in range(R + 1)]
for i in range(1, R + 1):
for j in range(1, C + 1):
prefix_sum[i][j] = (matrix[i - 1][j - 1]
... | from solution import solve
def test_basic_case():
R, C, Q = 3, 3, 2
garden = [
[1, 2, 3],
[4, 5, 6],
[7, 8, 9]
]
queries = [
(1, 1, 2, 2),
(2, 2, 3, 3)
]
result = solve(R, C, Q, garden, queries)
assert result == [12, 28]
def test_single_element_query... | [
{
"docstring": "Compute the prefix sum matrix.",
"function_declaration": "def compute_prefix_sum(matrix):",
"function_name": "compute_prefix_sum",
"parameter_list": "(matrix)"
},
{
"docstring": "Calculate the sum of the elements in the subgrid (r1, c1) to (r2, c2)\nusing the prefix sum matri... | [
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 calculate_subgrid_sums(R, C, grid, queries):\n # Generate prefix sums\n prefix_sum = [[0] * (C + 1) for _ in range(R + 1)]\n \n for i in ra... | trial_gpt4o_2 | {
"original_instruction": "In a mythical kingdom, there is a garden where magic flowers grow. Each flower has a unique magical value associated with it. The garden is arranged as a large grid of flowers with `R` rows and `C` columns. The magical value of each flower might change over time due to magical influences. \... | 0.514555 | Code_Contests_3098 | C | [
"compute_prefix_sum",
"subgrid_sum",
"solve"
] | 3 | [
[
"solve",
"compute_prefix_sum"
],
[
"solve",
"subgrid_sum"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | b4f81d7571170ff4f914cfb4008c3e8073ba8b95 | 98a0087bb89ba3864485ac2611809cf5cccbe3a3 | |||
v1.0 | complete | Code_Contests | Code_Contests_4061_C | def minimum_cost_to_connect_towns(n: int, m: int, connections: List[Tuple[int, int, int]]) -> Union[int, str]:
""" Determines the minimum cost to connect all towns.
Args:
n : int : The number of towns.
m : int : The number of possible connections.
connections : List[Tuple[int, int, int]] : A li... | def find(parent, i):
if parent[i] == i:
return i
else:
return find(parent, parent[i])
def union(parent, rank, x, y):
root_x = find(parent, x)
root_y = find(parent, y)
if root_x != root_y:
if rank[root_x] > rank[root_y]:
parent[root_y] = root_x
elif r... | from solution import minimum_cost_to_connect_towns
def test_example_1():
n = 4
m = 5
connections = [
(1, 2, 1),
(1, 3, 4),
(2, 3, 2),
(3, 4, 3),
(2, 4, 5)
]
assert minimum_cost_to_connect_towns(n, m, connections) == 6
def test_example_2():
n = 3
m = ... | [
{
"docstring": null,
"function_declaration": "def find(parent, i):",
"function_name": "find",
"parameter_list": "(parent, i)"
},
{
"docstring": null,
"function_declaration": "def union(parent, rank, x, y):",
"function_name": "union",
"parameter_list": "(parent, rank, x, y)"
},
... | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def find(parent, i):\n if parent[i] == i:\n return i\n return find(parent, parent[i])\n\ndef union(parent, rank, x, y):\n root_x = find(par... | trial_gpt4o_1 | {
"original_instruction": "Martin is playing a game on his computer in which he builds connected networks of towns. Each town is represented by a node, and each connection between two towns is represented by an edge. Initially, no towns are connected, and Martin can select from a given list of possible connections (e... | 0.638643 | Code_Contests_4061 | C | [
"find",
"union",
"minimum_cost_to_connect_towns"
] | 3 | [
[
"minimum_cost_to_connect_towns",
"find"
],
[
"minimum_cost_to_connect_towns",
"union"
],
[
"union",
"find"
]
] | 3 | [] | false | [] | false | pytest | true | [] | true | 24a712a95a24790d1101015f8add466051415b6b | a430bbfe809772da2275b320121d4f9123a05c8f | |||
v1.0 | complete | Code_Contests | Code_Contests_4133_C | def is_strobogrammatic(num: int) -> bool:
"""
Checks whether a number is strobogrammatic.
"""
strobo_map = {'0': '0', '1': '1', '6': '9', '8': '8', '9': '6'}
str_num = str(num)
rotated_str = ''.join(strobo_map.get(ch, '') for ch in reversed(str_num))
return str_num == rotated_str
def next_s... | def is_strobogrammatic(num):
"""
Checks whether a number is strobogrammatic.
"""
strobo_map = {'0': '0', '1': '1', '6': '9', '8': '8', '9': '6'}
str_num = str(num)
rotated_str = ''.join(strobo_map.get(ch, '') for ch in reversed(str_num))
return str_num == rotated_str
def next_strobogrammati... | from solution import is_strobogrammatic, next_strobogrammatic_number
def test_is_strobogrammatic():
assert is_strobogrammatic(69) == True
assert is_strobogrammatic(96) == True
assert is_strobogrammatic(818) == True
assert is_strobogrammatic(9966) == True
assert is_strobogrammatic(10) == False
a... | [
{
"docstring": "Checks whether a number is strobogrammatic.",
"function_declaration": "def is_strobogrammatic(num):",
"function_name": "is_strobogrammatic",
"parameter_list": "(num)"
},
{
"docstring": "Returns the next strobogrammatic number greater than n.",
"function_declaration": "def... | [
1,
0,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_strobogrammatic(num):\n \"\"\"\n Checks whether a number is strobogrammatic.\n \"\"\"\n strobo_map = {'0': '0', '1': '1', '6': '9', '8':... | trial_gpt4o_0 | {
"original_instruction": "A palindrome is a word, phrase, number, or other sequence of characters that reads the same backward as forward. When working with numbers, a palindromic number is a number that remains the same when its digits are reversed.\n\nWe define a base-10 integer as a Strobogrammatic number if the ... | 0.596236 | Code_Contests_4133 | C | [
"is_strobogrammatic",
"next_strobogrammatic_number"
] | 2 | [
[
"next_strobogrammatic_number",
"is_strobogrammatic"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | a524db2deb0793d4e0ee005902cfab0cab1b64aa | aecaf9fad25dbd96fda7136ef00dc7387de8843c | |||
v1.0 | complete | Code_Contests | Code_Contests_4104_C | import re
from typing import List, Tuple
def is_strong_password(password: str) -> bool:
""" Check if the password is strong.
>>> is_strong_password("Password123!")
True
>>> is_strong_password("weakpassword")
False
"""
def count_strong_weak_passwords(n: int, passwords: List[str]) -> Tuple[i... | import re
def is_strong_password(password):
if len(password) < 8:
return False
if not re.search(r'[a-z]', password):
return False
if not re.search(r'[A-Z]', password):
return False
if not re.search(r'\d', password):
return False
if not re.search(r'[!@#$%^&*()\-+]', p... | import pytest
from solution import is_strong_password, count_strong_weak_passwords
def test_is_strong_password_with_strong_passwords():
assert is_strong_password("Password123!") == True
assert is_strong_password("Stronger@1") == True
assert is_strong_password("Secure#Password1") == True
def test_is_strong... | [
{
"docstring": null,
"function_declaration": "def is_strong_password(password):",
"function_name": "is_strong_password",
"parameter_list": "(password)"
},
{
"docstring": null,
"function_declaration": "def count_strong_weak_passwords(n, passwords):",
"function_name": "count_strong_wea... | [
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 count_strong_and_weak_passwords(n, passwords):\n def is_strong_password(password):\n if len(password) < 8:\n return False\n ... | trial_gpt4o_4 | {
"original_instruction": "A company is designing a secure login system. Each user can have multiple login attempts, each with a different password. A password is considered strong if it satisfies the following criteria:\n\n1. It has at least 8 characters.\n2. It contains at least one lowercase letter.\n3. It contain... | 0.563109 | Code_Contests_4104 | C | [
"is_strong_password",
"count_strong_weak_passwords"
] | 2 | [
[
"count_strong_weak_passwords",
"is_strong_password"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | fde8a3f5ea86e1c362496c9c597254cf00c71e6e | 3ef93a1c5b566a51883331ee70b99f7809ba0ee1 | |||
v1.0 | complete | Code_Contests | Code_Contests_4641_C | def qualifies(S: int) -> str:
""" Determine if the score S qualifies based on the given criteria.
>>> qualifies(7) == "YES"
>>> qualifies(23) == "YES"
>>> qualifies(10) == "NO"
""" | def is_prime(n):
"""
Check if a number is prime.
"""
if n <= 1:
return False
if n <= 3:
return True
if n % 2 == 0 or n % 3 == 0:
return False
i = 5
while i * i <= n:
if n % i == 0 or n % (i + 2) == 0:
return False
i += 6
return True... | from solution import qualifies
def test_qualifies_prime_palindrome():
# 7 is a prime and a palindrome
assert qualifies(7) == "YES"
def test_qualifies_prime_sum_of_digits_prime():
# 23 is prime and sum of digits (2+3=5) is also prime
assert qualifies(23) == "YES"
def test_does_not_qualify_not_prime():... | [
{
"docstring": "Check if a number is prime.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Check if a number is a palindrome.",
"function_declaration": "def is_palindrome(n):",
"function_name": "is_palindrome",
... | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(n):\n \"\"\"\n Check if a number is a prime.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return True\n ... | trial_gpt4o_1 | {
"original_instruction": "Draco is designing a new coding challenge platform called CodeFlare. Participants are scored based on their code submission, where the score is derived from running time and memory consumption. Draco wants to determine if a participants' score after solving a problem meets certain criteria.... | 0.599794 | Code_Contests_4641 | C | [
"is_prime",
"is_palindrome",
"sum_of_digits",
"qualifies"
] | 4 | [
[
"qualifies",
"is_palindrome"
],
[
"qualifies",
"is_prime"
],
[
"qualifies",
"sum_of_digits"
]
] | 3 | [] | false | [] | false | pytest | true | [] | true | 77f48608422f182e9b28f4641e356c4771210d8e | 98666412a90234ca8732e7e141a5c8d238571094 | |||
v1.0 | complete | Code_Contests | Code_Contests_4255_C | def potion_measurement(n: int, m: int, bottles: List[int]) -> int:
""" Determine the minimum number of bottles needed to measure exactly m liters.
>>> potion_measurement(3, 11, [1, 3, 5])
3
>>> potion_measurement(2, 7, [2, 6])
-1
>>> potion_measurement(1, 7, [7])
1
>>> potion_measurement... | def min_bottles(n, m, bottles):
dp = [float('inf')] * (m + 1)
dp[0] = 0 # No bottles needed to measure 0 liters
for bottle in bottles:
for j in range(bottle, m + 1):
dp[j] = min(dp[j], dp[j - bottle] + 1)
return dp[m] if dp[m] != float('inf') else -1
def potion_measurement(n, m, ... | def test_min_bottles_example_1():
assert potion_measurement(3, 11, [1, 3, 5]) == 3
def test_min_bottles_example_2():
assert potion_measurement(2, 7, [2, 6]) == -1
def test_min_bottles_single_bottle_exact():
assert potion_measurement(1, 7, [7]) == 1
def test_min_bottles_multiple_ways():
assert potion_... | [
{
"docstring": null,
"function_declaration": "def min_bottles(n, m, bottles):",
"function_name": "min_bottles",
"parameter_list": "(n, m, bottles)"
},
{
"docstring": null,
"function_declaration": "def potion_measurement(n, m, bottles):",
"function_name": "potion_measurement",
"pa... | [
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 min_bottles_to_measure(n, m, capacities):\n \"\"\"\n Function to determine the minimum number of bottles needed to measure exactly m liters using... | trial_gpt4o_2 | {
"original_instruction": "In the magical world, a wizard needs to create a special potion that requires exactly m liters of a particular ingredient, which is available in bottles of various capacities. The wizard can use each bottle an infinite number of times. Given the capacities of the bottles and the total amoun... | 0.627866 | Code_Contests_4255 | C | [
"min_bottles",
"potion_measurement"
] | 2 | [
[
"potion_measurement",
"min_bottles"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | bb5a0062c44a0337d1019ab41700115950f6de96 | 556381726834c4516e596d85c4e31b3c7ae5c2d3 | |||
v1.0 | complete | Code_Contests | Code_Contests_4164_C | def is_prime(num: int) -> bool:
"""Returns True if num is a prime number, otherwise False."""
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... | def is_prime(num):
"""Returns True if num is a prime number, otherwise False."""
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 pr... | from solution import prime_numbers
def test_prime_numbers_5():
assert prime_numbers(5) == [2, 3, 5, 7, 11]
def test_prime_numbers_10():
assert prime_numbers(10) == [2, 3, 5, 7, 11, 13, 17, 19, 23, 29]
def test_prime_numbers_15():
assert prime_numbers(15) == [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41... | [
{
"docstring": "Returns True if num is a prime number, otherwise False.",
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": "Returns a list of the first `n` prime numbers in ascending order.",
"function_declaration": "d... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(num):\n \"\"\"Returns True if num is a prime number, otherwise False.\"\"\"\n if num <= 1:\n return False\n if num == 2:\n ... | trial_gpt4o_0 | {
"original_instruction": "Write a function that takes an integer `n` between 5 and 30 inclusive, and returns a list of the first `n` prime numbers in ascending order. Prime numbers are integers greater than 1 that have no divisors other than 1 and themselves.\n\nConstraints\n\n* 5 \\leq n \\leq 30\n\nInput\n\nThe in... | 0.82201 | Code_Contests_4164 | C | [
"is_prime",
"prime_numbers"
] | 2 | [
[
"prime_numbers",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 93a34792c776c38702b2124be8c72371b753ddf4 | 3ab21487ba36171fa0f6709d98de91d9c06d26d9 | |||
v1.0 | complete | Code_Contests | Code_Contests_4334_C | def can_reach_palindrome(maze: List[str], x_start: int, y_start: int, x_end: int, y_end: int) -> str:
""" Determine if it's possible to reach the end position by moving only through cells that form a palindrome sequence.
>>> maze = [
... 'ababa',
... 'bcccb',
... 'dadad',
... 'bcccb',
... 'a... | def is_palindrome(s):
return s == s[::-1]
def dfs(maze, x, y, path, visited, x_end, y_end):
if (x, y) == (x_end, y_end):
if is_palindrome(path):
return True
return False
visited.add((x, y))
directions = [(-1, 0), (1, 0), (0, -1), (0, 1)]
for dx, dy in direction... | import pytest
from solution import can_reach_palindrome
def test_sample_input_1():
maze = [
'ababa',
'bcccb',
'dadad',
'bcccb',
'ababa'
]
assert can_reach_palindrome(maze, 0, 0, 4, 4) == "Yes"
def test_sample_input_2():
maze = [
'abcd',
'bcdb',
... | [
{
"docstring": null,
"function_declaration": "def is_palindrome(s):",
"function_name": "is_palindrome",
"parameter_list": "(s)"
},
{
"docstring": null,
"function_declaration": "def dfs(maze, x, y, path, visited, x_end, y_end):",
"function_name": "dfs",
"parameter_list": "(maze, x... | [
1,
0,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_palindrome(s):\n return s == s[::-1]\n\ndef dfs(maze, x, y, path, visited, x_end, y_end):\n if (x, y) == (x_end, y_end):\n if is_palind... | trial_gpt4o_0 | {
"original_instruction": "Palindrome Maze\n\nStory\n\nIn the mysterious land of Palindor, there's a maze designed with a peculiar set of rules. The maze is comprised of cells, each containing a character that can be an alphabet letter. The maze-keeper, Palax, loves palindromes and has designed the maze such that one... | 0.66162 | Code_Contests_4334 | C | [
"is_palindrome",
"dfs",
"can_reach_palindrome"
] | 3 | [
[
"can_reach_palindrome",
"dfs"
],
[
"dfs",
"is_palindrome"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 5ec6845749dd6fd1b2d405dcf1f41968caa4c181 | ac390a19b4322ddf784358e801ae52b078b86dc0 | |||
v1.0 | complete | Code_Contests | Code_Contests_4027_C | def find_divisor_pairs(n):
"""
Given an integer n, finds all pairs of positive integers (a, b) such that:
- a is a divisor of n.
- b is a divisor of n.
- a * b = n.
Returns a list of tuples containing the pairs (a, b) in non-decreasing order of a.
If no such pairs exist, returns an empty lis... | def find_divisor_pairs(n):
"""
Given an integer n, finds all pairs of positive integers (a, b) such that:
- a is a divisor of n.
- b is a divisor of n.
- a * b = n.
Returns a list of tuples containing the pairs (a, b) in non-decreasing order of a.
If no such pairs exist, returns an empty lis... | from solution import find_divisor_pairs, find_pairs_for_all_cases
def test_find_divisor_pairs():
assert find_divisor_pairs(6) == [(1, 6), (2, 3)]
assert find_divisor_pairs(12) == [(1, 12), (2, 6), (3, 4)]
assert find_divisor_pairs(19) == [(1, 19)] # since 19 is a prime number
assert find_divisor_pairs(... | [
{
"docstring": "Given an integer n, finds all pairs of positive integers (a, b) such that:\n- a is a divisor of n.\n- b is a divisor of n.\n- a * b = n.\nReturns a list of tuples containing the pairs (a, b) in non-decreasing order of a.\nIf no such pairs exist, returns an empty list.",
"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": "def find_pairs(t, test_cases):\n results = []\n for n in test_cases:\n pairs = []\n for a in range(1, n + 1):\n if n % a == ... | trial_gpt4o_1 | {
"original_instruction": "You are given an integer n (1 ≤ n ≤ 1000). Find all pairs of positive integers (a, b) such that:\n\n- a is a divisor of n.\n- b is a divisor of n.\n- a * b = n.\n\nFor each test case, output all pairs (a, b) in non-decreasing order of a. If there are no such pairs, output \"NO\" (without qu... | 0.736093 | Code_Contests_4027 | C | [
"find_divisor_pairs",
"find_pairs_for_all_cases"
] | 2 | [
[
"find_pairs_for_all_cases",
"find_divisor_pairs"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 1b5d7beaf37504d7085d19c095ec5df3711c4094 | 1ffd3198bae53e4b3ff44bc23c1f1826ffba11ff | |||
v1.0 | complete | Code_Contests | Code_Contests_4522_C | from typing import List
def sum_of_digits(x: int) -> int:
"""
Calculates the sum of the digits of a given number x.
>>> sum_of_digits(1)
1
>>> sum_of_digits(123)
6
"""
def generate_mosaic(m: int, n: int) -> List[List[str]]:
"""
Generates an m x n grid of tiles based on the... | def sum_of_digits(x):
"""
Calculates the sum of the digits of a given number x.
"""
return sum(int(digit) for digit in str(x))
def generate_mosaic(m, n):
"""
Generates an m x n grid of tiles based on the color scheme rule.
"""
mosaic = []
for i in range(1, m + 1):
row = []
... | def test_sum_of_digits():
assert sum_of_digits(1) == 1
assert sum_of_digits(10) == 1
assert sum_of_digits(123) == 6
assert sum_of_digits(99) == 18
def test_generate_mosaic():
result = generate_mosaic(3, 4)
expected = [
['W', 'B', 'W', 'B'],
['B', 'W', 'B', 'W'],
['W', 'B... | [
{
"docstring": "Calculates the sum of the digits of a given number x.",
"function_declaration": "def sum_of_digits(x):",
"function_name": "sum_of_digits",
"parameter_list": "(x)"
},
{
"docstring": "Generates an m x n grid of tiles based on the color scheme rule.",
"function_declaration":... | [
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 digit_sum(x):\n \"\"\"\n Returns the sum of the digits of an integer x.\n \"\"\"\n return sum(int(digit) for digit in str(x))\n\ndef mosaic... | trial_gpt4o_2 | {
"original_instruction": "Archaeologist Alex is exploring an ancient temple. In one of the rooms, he discovers a mosaic made up of colored tiles arranged in a rectangular grid. The room guardian informs Alex that the mosaic follows a special pattern defined by the sum of the digits of the grid coordinates.\n\nThe ti... | 0.569597 | Code_Contests_4522 | C | [
"sum_of_digits",
"generate_mosaic"
] | 2 | [
[
"generate_mosaic",
"sum_of_digits"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | bb5b0af24e1484940fbac8735a4a3a827160683b | ecda1e48bf594318c9e6b8c2e88d37f67156f923 | |||
v1.0 | complete | Code_Contests | Code_Contests_3764_C | import math
import heapq
from typing import List, Tuple
def calculate_distance(x1, y1, x2, y2):
return math.sqrt((x2 - x1) ** 2 + (y2 - y1) ** 2)
def minimum_spanning_tree(cities):
""" Calculate the minimum spanning tree for given cities coordinates.
Args:
cities (List[Tuple[int, int]]): List of t... | import math
import heapq
def calculate_distance(x1, y1, x2, y2):
return math.sqrt((x2 - x1) ** 2 + (y2 - y1) ** 2)
def minimum_spanning_tree(cities):
N = len(cities)
if N == 0:
return 0.0
# Initialize the adjacency list for the graph
edges = [(0, i, 0) for i in range(N)]
visited =... | from solution import solve_minimum_roads
def test_example():
input_data = "4\n0 0\n0 1\n1 0\n1 1"
output_data = solve_minimum_roads(input_data)
assert output_data == 3.00
def test_single_city():
input_data = "1\n0 0"
output_data = solve_minimum_roads(input_data)
assert output_data == 0.00
def... | [
{
"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_spanning_tree(cities):",
"function_name": "minimum_spanning... | [
1,
1
] | 2 | easy | 1 | {
"trial_gpt4o_0": null,
"trial_gpt4o_1": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared1_results_combined.jsonl",
"solution_code": "import math\nimport heapq\n\ndef calculate_distance(x1, y1, x2, y2):\n return math.sqrt((x2 - x1) ** 2 + (y2 - y1) ** 2)\n\ndef... | trial_gpt4o_1 | {
"original_instruction": "You are given a list of cities with their respective coordinates on a 2D plane. Your task is to find the optimal way to connect all the cities using roads, so that the total length of the roads is minimized. This is essentially a Minimum Spanning Tree (MST) problem where each city is a vert... | 0.633033 | Code_Contests_3764 | C | [
"calculate_distance",
"minimum_spanning_tree",
"solve_minimum_roads"
] | 3 | [
[
"minimum_spanning_tree",
"calculate_distance"
],
[
"solve_minimum_roads",
"minimum_spanning_tree"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 59f5b3eb101b2492ce268df8b1cd879dcda5b0b1 | e41956588eb194b67403429156ebfc20d22ce361 | |||
v1.0 | complete | Code_Contests | Code_Contests_4535_C | def is_palindrome(s: str) -> bool:
""" Determine if a given string is a palindrome.
>>> is_palindrome("abcba")
True
>>> is_palindrome("hello")
False
"""
pass
def palindromify(word: str) -> str:
""" Convert a given word into a palindrome by appending the minimum number of characters at t... | def is_palindrome(s):
return s == s[::-1]
def palindromify(word):
n = len(word)
if is_palindrome(word):
return word
for length in range(n):
if is_palindrome(word[length:]):
return word + word[:length][::-1]
return word # Should never reach here since the loop should cov... | from solution import is_palindrome, palindromify, process_test_cases
def test_is_palindrome():
assert is_palindrome("abcba") == True
assert is_palindrome("racecar") == True
assert is_palindrome("hello") == False
assert is_palindrome("a") == True
assert is_palindrome("ab") == False
def test_palindr... | [
{
"docstring": null,
"function_declaration": "def is_palindrome(s):",
"function_name": "is_palindrome",
"parameter_list": "(s)"
},
{
"docstring": null,
"function_declaration": "def palindromify(word):",
"function_name": "palindromify",
"parameter_list": "(word)"
},
{
"doc... | [
0,
0,
0,
1,
0
] | 1 | hard | 0.2 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def palindromify(word):\n \"\"\"\n Converts a given word into a palindrome by appending the minimum number \n of characters at the end of the word... | trial_gpt4o_3 | {
"original_instruction": "In a mystical land called Wonderland, people speak in a special language known as \"Wondrous Talk\". In this language, there is a unique way of encoding words using a method called \"Palindromify\". The process works as follows:\n1) The given word is converted into a palindrome by appending... | 0.847067 | Code_Contests_4535 | C | [
"is_palindrome",
"palindromify",
"process_test_cases"
] | 3 | [
[
"palindromify",
"is_palindrome"
],
[
"process_test_cases",
"palindromify"
]
] | 2 | [
"process_test_cases"
] | false | [] | false | pytest | true | [] | true | 5191f283afa766d55ecf9b893b847e70c5151df9 | a1de45d94798250c1f9da4f60961449564590064 | |||
v1.0 | complete | Code_Contests | Code_Contests_3414_C | def merge_urls(n: int, url_list: List[str]) -> List[List[str]]:
"""
Given the number of URLs and the list of URLs, returns the grouped URLs based on the specified rules.
- URLs with http and https are distinct.
- URLs with or without www are considered equivalent.
- Order of query parameters doesn't... | from urllib.parse import urlparse, parse_qsl
def canonical_url(url):
"""
Converts a URL into its canonical form by:
- Removing 'www.' if it exists
- Sorting the query parameters
"""
parsed_url = urlparse(url)
# Remove 'www.' if it exists
netloc = parsed_url.netloc.replace('www.', '... | from solution import merge_urls
def test_merge_urls_example():
n = 6
urls = [
"http://example.com/path?a=1&b=2",
"https://example.com/path?a=1&b=2",
"http://www.example.com/path?b=2&a=1",
"http://example.com/otherpath?p=5&q=4",
"http://www.example.com/path?a=2&b=1",
... | [
{
"docstring": "Converts a URL into its canonical form by:\n- Removing 'www.' if it exists\n- Sorting the query parameters",
"function_declaration": "def canonical_url(url):",
"function_name": "canonical_url",
"parameter_list": "(url)"
},
{
"docstring": "Groups the URLs into their respective... | [
0,
0,
0,
0,
0,
0,
0,
0,
1,
0
] | 1 | hard | 0.1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from urllib.parse import urlparse, parse_qs\n\ndef normalize_url(url):\n parsed = urlparse(url)\n protocol = parsed.scheme\n domain = parsed.netlo... | trial_gpt4o_8 | {
"original_instruction": "Polycarp recently discovered that some websites handle URLs in a way that they redirect to canonical URLs. Specifically, some websites leverage URL shortening services, others might consider URLs with www and without www as the same, and some even ignore or change parameters in the URL quer... | 0.572625 | Code_Contests_3414 | C | [
"canonical_url",
"group_urls",
"merge_urls"
] | 3 | [
[
"group_urls",
"canonical_url"
],
[
"merge_urls",
"group_urls"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 70de7fd2c2851f34c173515430525356194feff1 | 16ad52e8da710ef6fb0a7b737f1f6811c8138d77 | |||
v1.0 | complete | Code_Contests | Code_Contests_3542_C | def preprocess_prefix_sums(arr):
"""
Preprocess the prefix sums of the array.
Returns a list where prefix_sums[i] is the sum of elements from arr[0] to arr[i-1].
"""
def range_sum(prefix_sums, l, r):
"""
Returns the sum of the array elements from index l to index r (inclusive),
based on the... | def preprocess_prefix_sums(arr):
"""
Preprocess the prefix sums of the array.
Returns a list where prefix_sums[i] is the sum of elements from arr[0] to arr[i-1].
"""
n = len(arr)
prefix_sums = [0] * (n + 1)
for i in range(1, n + 1):
prefix_sums[i] = prefix_sums[i - 1] + arr[i - 1]
... | from solution import preprocess_prefix_sums, range_sum, process_queries
def test_preprocess_prefix_sums():
arr = [1, 2, 3, 4, 5]
expected = [0, 1, 3, 6, 10, 15]
assert preprocess_prefix_sums(arr) == expected
def test_range_sum():
prefix_sums = [0, 1, 3, 6, 10, 15]
assert range_sum(prefix_sums, 1, ... | [
{
"docstring": "Preprocess the prefix sums of the array.\nReturns a list where prefix_sums[i] is the sum of elements from arr[0] to arr[i-1].",
"function_declaration": "def preprocess_prefix_sums(arr):",
"function_name": "preprocess_prefix_sums",
"parameter_list": "(arr)"
},
{
"docstring": "... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def compute_prefix_sums(array):\n # Compute prefix sums for the array\n prefix_sums = [0] * (len(array) + 1)\n for i in range(1, len(array) + 1):\... | trial_gpt4o_2 | {
"original_instruction": "You are given an array of n integers. You need to answer several queries about the sum of the integers in the array within certain ranges. Each query consists of two integers l and r (1 ≤ l ≤ r ≤ n), and you need to find the sum of the array elements from index l to index r (inclusive).\n\n... | 0.563129 | Code_Contests_3542 | C | [
"preprocess_prefix_sums",
"range_sum",
"process_queries"
] | 3 | [
[
"process_queries",
"preprocess_prefix_sums"
],
[
"process_queries",
"range_sum"
]
] | 2 | [
"process_queries"
] | false | [] | false | pytest | true | [] | true | 01d98069b749038ae1bc6b65ab5a49ab6dd02a2a | f4b82cdd84c7811a3a4e0e62aba11eb688e79f7e | |||
v1.0 | complete | Code_Contests | Code_Contests_4411_C | def caterer_route(n: int, m: int, edges: List[Tuple[int, int]], s: int) -> str:
""" Determine if the caterer can make a single round trip that covers every room exactly once and returns to the initial room.
Args:
n (int): The number of rooms.
m (int): The number of passages between rooms.
edges... | from itertools import permutations
def is_hamiltonian_cycle(graph, start, n):
for perm in permutations(range(1, n + 1)):
if perm[0] == start:
cycle = perm + (start,)
is_valid = True
for i in range(n):
if graph[cycle[i]][cycle[i + 1]] == 0:
... | import pytest
from solution import caterer_route
def test_case_1():
n = 4
m = 5
edges = [(1, 2), (2, 3), (3, 4), (4, 1), (1, 3)]
s = 1
result = caterer_route(n, m, edges, s)
assert result == "Possible\n1 2 3 4 1"
def test_case_2():
n = 4
m = 3
edges = [(1, 2), (2, 3), (3, 4)]
s... | [
{
"docstring": null,
"function_declaration": "def is_hamiltonian_cycle(graph, start, n):",
"function_name": "is_hamiltonian_cycle",
"parameter_list": "(graph, start, n)"
},
{
"docstring": null,
"function_declaration": "def solve(n, m, edges, s):",
"function_name": "solve",
"param... | [
0,
0,
0,
1
] | 1 | hard | 0.25 | {
"trial_gpt4o_0": null,
"trial_gpt4o_1": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared1_results_combined.jsonl",
"solution_code": "from itertools import permutations\n\ndef check_hamiltonian_cycle(n, m, edges, s):\n # Create adjacency matrix\n adj = [[0] ... | trial_gpt4o_4 | {
"original_instruction": "You are given a directed graph with n vertices and m edges. Each vertex represents a room at a party, and each edge represents a one-way passage between two rooms. A unique caterer is stationed in one of these rooms initially. The caterer has to deliver food to each room exactly once before... | 0.601256 | Code_Contests_4411 | C | [
"is_hamiltonian_cycle",
"solve",
"caterer_route"
] | 3 | [
[
"caterer_route",
"solve"
],
[
"solve",
"is_hamiltonian_cycle"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 8ee7e9bd47930b3daef65b36668f5c9e84d11d59 | 9d2c658ef0591f32e80088c4208ac3b7107e8658 | |||
v1.0 | complete | Code_Contests | Code_Contests_4542_C | def reverse_number(n: int) -> int:
""" Reverses the digits of an integer.
>>> reverse_number(123)
321
>>> reverse_number(4567)
7654
"""
pass
def is_palindrome(n: int) -> bool:
""" Checks if an integer is a palindrome.
>>> is_palindrome(121)
True
>>> is_palindrome(1... | def reverse_number(n):
"""
Reverses the digits of an integer.
"""
return int(str(n)[::-1])
def is_palindrome(n):
"""
Checks if an integer is a palindrome.
"""
return str(n) == str(n)[::-1]
def find_palindrome(n):
"""
Finds the palindrome by reversing and adding the digits of th... | from solution import reverse_number, is_palindrome, find_palindrome
def test_reverse_number():
assert reverse_number(123) == 321
assert reverse_number(4567) == 7654
assert reverse_number(0) == 0
assert reverse_number(1000) == 1
def test_is_palindrome():
assert is_palindrome(121) == True
assert... | [
{
"docstring": "Reverses the digits of an integer.",
"function_declaration": "def reverse_number(n):",
"function_name": "reverse_number",
"parameter_list": "(n)"
},
{
"docstring": "Checks if an integer is a palindrome.",
"function_declaration": "def is_palindrome(n):",
"function_name... | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def reverse_number(n):\n \"\"\"\n Returns the reverse of the given number.\n \"\"\"\n return int(str(n)[::-1])\n\ndef is_palindrome(n):\n \"... | trial_gpt4o_1 | {
"original_instruction": "Given a decimal number system, you need to perform certain operations on the numbers, such as reversing and adding until the number becomes a palindrome. \n\nA palindrome is a number that reads the same forward and backward. For example, 121 is a palindrome, while 123 is not.\n\nThe operati... | 0.736072 | Code_Contests_4542 | C | [
"reverse_number",
"is_palindrome",
"find_palindrome"
] | 3 | [
[
"find_palindrome",
"is_palindrome"
],
[
"find_palindrome",
"reverse_number"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 5743a0635eb9b7eb8b8c3294780198b4d12c8325 | 4f1579e414839f36cd7bc82dac2b87b5a580d7e8 | |||
v1.0 | complete | Code_Contests | Code_Contests_3821_C | def max_events(events):
"""
Returns the maximum number of events one can attend.
"""
events.sort(key=lambda x: x[1]) # Sort events by their end time
count = 0
last_end_time = -1
for start, end in events:
if start >= last_end_time:
count += 1
last_end_tim... | def max_events(events):
"""
Returns the maximum number of events one can attend.
"""
events.sort(key=lambda x: x[1]) # Sort events by their end time
count = 0
last_end_time = -1
for start, end in events:
if start >= last_end_time:
count += 1
last_end_tim... | from solution import max_events
def test_example_1():
events = [(1, 3), (2, 5), (4, 6), (6, 8), (9, 10)]
assert max_events(events) == 4
def test_example_2():
events = [(1, 2), (2, 3), (3, 4)]
assert max_events(events) == 3
def test_single_event():
events = [(1, 2)]
assert max_events(events) =... | [
{
"docstring": "Returns the maximum number of events one can attend.",
"function_declaration": "def max_events(events):",
"function_name": "max_events",
"parameter_list": "(events)"
},
{
"docstring": null,
"function_declaration": "def solve():",
"function_name": "solve",
"paramet... | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def max_events(n, events):\n \"\"\"\n Returns the maximum number of events that can be attended without overlaps.\n \n Parameters:\n n (int)... | trial_gpt4o_1 | {
"original_instruction": "You are tasked with organizing a series of events in a museum. There are n events and each event has a specific start time and end time. You need to find out the maximum number of events you can attend if you can only attend one event at a time. \n\nInput\nThe first line contains an integer... | 0.575035 | Code_Contests_3821 | C | [
"max_events",
"solve"
] | 2 | [
[
"solve",
"max_events"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 48e87e39fa0672435ac6c856126db40fd968ff84 | 566cdc003dc1145665914ec7f96c9b9b1cc2f15c | |||
v1.0 | complete | Code_Contests | Code_Contests_1195_C | import heapq
from collections import defaultdict
import sys
def dijkstra(graph, start, end):
priority_queue = [(0, start)]
distances = {start: 0}
while priority_queue:
current_distance, current_vertex = heapq.heappop(priority_queue)
if current_vertex == end:
return... | import heapq
from collections import defaultdict
import sys
def dijkstra(graph, start, end):
priority_queue = [(0, start)]
distances = {start: 0}
while priority_queue:
current_distance, current_vertex = heapq.heappop(priority_queue)
if current_vertex == end:
return... | from solution import find_shortest_path
def test_find_shortest_path_case1():
t = 1
test_cases = [
{
'A': (0, 0),
'B': (5, 5),
'edges_count': 3,
'edges': [
(0, 0, 3, 3, 6),
(0, 0, 1, 1, 3),
(1, 1, 5, 5, 4),
... | [
{
"docstring": null,
"function_declaration": "def dijkstra(graph, start, end):",
"function_name": "dijkstra",
"parameter_list": "(graph, start, end)"
},
{
"docstring": null,
"function_declaration": "def find_shortest_path(t, test_cases):",
"function_name": "find_shortest_path",
"... | [
1,
0,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import heapq\n\ndef dijkstra(graph, start, end):\n \"\"\"\n Find the shortest path in a graph from start to end using Dijkstra's algorithm.\n \"\"... | trial_gpt4o_2 | {
"original_instruction": "Given a coordinate plane with a directed graph embedded into it, you need to find the shortest path from point A to point B. The graph's edges are defined by a list of line segments on the plane and each segment has a weight representing the cost to traverse that segment.\n\nEach edge is re... | 0.605338 | Code_Contests_1195 | C | [
"dijkstra",
"find_shortest_path"
] | 2 | [
[
"find_shortest_path",
"dijkstra"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 2a804b92929420a168386078263bce57668cce88 | aca148c770698cdb7a747ba241fd46d2ddf84fca | |||
v1.0 | complete | Code_Contests | Code_Contests_3911_C | def can_allocate_seats(student_list):
"""
Determine if it is possible to arrange the seats according to the rules.
Args:
student_list: List of strings where each string represents a student's "first_last" name.
Returns:
'YES' if it is possible to arrange the seating as per the rules, o... | from collections import Counter
def can_allocate_seats(student_list):
"""
Determine if it is possible to arrange the seats according to the rules.
Args:
student_list: List of strings where each string represents a student's "first_last" name.
Returns:
'YES' if it is possible to arrang... | from solution import determine_seating_possible
def test_single_student():
input_str = "1\njohn_smith"
assert determine_seating_possible(input_str) == "YES"
def test_all_unique_last_names():
input_str = "4\njohn_smith\nemma_jones\nliam_taylor\nolivia_brown"
assert determine_seating_possible(input_str)... | [
{
"docstring": "Determine if it is possible to arrange the seats according to the rules.\n\nArgs:\nstudent_list: List of strings where each string represents a student's \"first_last\" name.\n\nReturns:\n'YES' if it is possible to arrange the seating as per the rules, otherwise 'NO'.",
"function_declaration... | [
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 Counter\n\ndef can_allocate_seats(student_list):\n \"\"\"\n Determine if it is possible to arrange the seats according to the... | trial_gpt4o_0 | {
"original_instruction": "A teacher needs to allocate seats for students in an exam hall. The seating arrangement must be done in a way that no two students with the same last names sit adjacent to each other in any row. The teacher has provided the list of students and their last names.\n\nYour task is to determine... | 0.566012 | Code_Contests_3911 | C | [
"can_allocate_seats",
"determine_seating_possible"
] | 2 | [
[
"determine_seating_possible",
"can_allocate_seats"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 9bc57b390f756ac9e6e15bb1dd8b375855d4f387 | 69d0e5768678c41b8032ede01af76c130cd3b988 | |||
v1.0 | complete | Code_Contests | Code_Contests_4705_C | def longest_distance(M, positions):
""" Determine the longest possible distance D such that poles can be installed at every D-th location starting from any of the given candidate locations.
>>> longest_distance(5, [1, 3, 7, 9, 13])
2
>>> longest_distance(4, [5, 10, 15, 20])
5
>>> longest_distanc... | def gcd(a, b):
while b:
a, b = b, a % b
return a
def longest_distance(M, positions):
positions.sort()
diffs = [positions[i] - positions[i - 1] for i in range(1, M)]
d = diffs[0]
for i in range(1, M - 1):
d = gcd(d, diffs[i])
if d == 1:
return 1
return d | from solution import longest_distance
def test_example_1():
M = 5
positions = [1, 3, 7, 9, 13]
assert longest_distance(M, positions) == 2
def test_example_2():
M = 4
positions = [5, 10, 15, 20]
assert longest_distance(M, positions) == 5
def test_example_3():
M = 3
positions = [1, 2, 4... | [
{
"docstring": null,
"function_declaration": "def gcd(a, b):",
"function_name": "gcd",
"parameter_list": "(a, b)"
},
{
"docstring": null,
"function_declaration": "def longest_distance(M, positions):",
"function_name": "longest_distance",
"parameter_list": "(M, positions)"
}
] | [
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_longest_distance(M, positions):\n \"\"\"\n Returns the longest possible distance D such that we can install a pole \n at every D-th locat... | trial_gpt4o_2 | {
"original_instruction": "A company is planning to install a series of utility poles along a new highway to provide electrical and communication services. The distance between consecutive utility poles should be the same to ensure uniformity.\n\nThe company has M candidate locations where the poles can be installed.... | 0.599096 | Code_Contests_4705 | C | [
"gcd",
"longest_distance"
] | 2 | [
[
"longest_distance",
"gcd"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 78f334f3bca7161514b3a6afaf18231ad405f951 | 8ba4d75d570611f509b7af00da40e7db9cd2736d | |||
v1.0 | complete | Code_Contests | Code_Contests_4419_C | def min_dishes_required(n, m, student_preferences):
""" Determine the minimum number of different dish types needed so that each student gets at least one of their preferred dishes.
Args:
n (int): Number of students.
m (int): Number of types of dishes.
student_preferences (List[List[int]]): Lis... | from itertools import combinations
def min_dishes_required(n, m, student_preferences):
# Construct the list containing sets of preferences for each student
student_sets = []
for pref in student_preferences:
student_sets.append(set(pref[1:]))
# Generate all possible combinations of dishes
a... | def test_min_dishes_required_example():
assert solve(4, 5, [
[3, 1, 2, 3],
[2, 2, 4],
[2, 3, 5],
[1, 4]
]) == 2
def test_min_dishes_required_single_student():
assert solve(1, 3, [
[2, 1, 2]
]) == 1
def test_min_dishes_required_all_dishes_needed():
assert... | [
{
"docstring": null,
"function_declaration": "def min_dishes_required(n, m, student_preferences):",
"function_name": "min_dishes_required",
"parameter_list": "(n, m, student_preferences)"
},
{
"docstring": null,
"function_declaration": "def solve(n, m, preferences):",
"function_name"... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from itertools import combinations\n\ndef min_dish_types(n, m, preferences):\n all_dishes = set(range(1, m + 1))\n for k in range(1, m + 1):\n ... | trial_gpt4o_1 | {
"original_instruction": "A university has n students, each with a unique ID number from 1 to n. The university cafeteria offers m different types of dishes, numbered from 1 to m. Each student has a list of their preferred dishes. Your task is to determine the minimum number of different dish types needed so that ea... | 0.714275 | Code_Contests_4419 | C | [
"min_dishes_required",
"solve"
] | 2 | [
[
"solve",
"min_dishes_required"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | 2ec44578f0c572a971cadd538e7e4a40754bacb2 | a58067c1901dc1315270504fb3af124a6e34b491 | |||
v1.0 | complete | Code_Contests | Code_Contests_4041_C | def optimal_energy_consumption(input_data: str) -> str:
"""
Determine if an optimal energy schedule exists given the constraints of each machine, ensuring that energy consumption
does not exceed the allowable energy consumption at any given time slot.
Parameters:
input_data (str): Formatted input ... | def is_optimizable(N, E, schedules):
"""
Determine if it's possible to rearrange the schedules such that the energy
consumption never exceeds E at any given time slot.
Parameters:
N (int): Number of machines
E (int): Maximum allowable energy consumption at any time
schedules (list): Li... | def test_optimal_energy_consumption():
input1 = "3 150\n3\n1 50\n2 50\n3 50\n2\n1 50\n2 70\n4\n1 30\n2 30\n3 30\n4 30"
input2 = "2 100\n2\n1 60\n2 60\n2\n2 50\n3 50"
assert optimal_energy_consumption(input1) == "Optimizable"
assert optimal_energy_consumption(input2) == "Not Optimizable"
def test_n... | [
{
"docstring": "Determine if it's possible to rearrange the schedules such that the energy \nconsumption never exceeds E at any given time slot.\n\nParameters:\nN (int): Number of machines\nE (int): Maximum allowable energy consumption at any time\nschedules (list): List of machines' schedules, where each sched... | [
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_optimizable(N, E, schedules):\n # Create a list to store the total energy consumption for each time slot\n energy_consumption = [0] * 25 # Ti... | trial_gpt4o_2 | {
"original_instruction": "**C - Optimal Energy Consumption**\n\nProblem Statement\n\nYou are managing a factory that operates across multiple machines, and energy consumption is a critical factor. Each machine operates based on certain schedules and consumes energy at different rates throughout the day. Your goal is... | 0.596281 | Code_Contests_4041 | C | [
"is_optimizable",
"optimal_energy_consumption"
] | 2 | [
[
"optimal_energy_consumption",
"is_optimizable"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | 1efadc5700f43f91d32de244c860ca7033727335 | 0ce1250f7cee7f60793ad8ad38ed9d42eb3c0432 | |||
v1.0 | complete | Code_Contests | Code_Contests_4425_C | def is_prime(n: int) -> bool:
""" Check if the given number is a prime number.
>>> is_prime(2) True
>>> is_prime(3) True
>>> is_prime(4) False
>>> is_prime(5) True
>>> is_prime(9) False
"""
def prime_factors(n: int) -> set:
""" Find all unique prime factors of the given number.
>>> ... | def is_prime(n):
if n <= 1:
return False
if n == 2:
return True
if n % 2 == 0:
return False
max_divisor = int(n ** 0.5) + 1
for i in range(3, max_divisor, 2):
if n % i == 0:
return False
return True
def prime_factors(n):
factors = set()
while ... | from solution import is_prime, prime_factors, prime_sum, prime_sum_chain
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
def test_prime_factors():
assert prime_factors(12) == {2, 3}
... | [
{
"docstring": null,
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": null,
"function_declaration": "def prime_factors(n):",
"function_name": "prime_factors",
"parameter_list": "(n)"
},
{
"docstring": null,... | [
1,
0,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(n):\n if n <= 1:\n return False\n if n == 2:\n return True\n if n % 2 == 0:\n return False\n max_divisor = in... | trial_gpt4o_0 | {
"original_instruction": "Sara is fascinated by prime numbers. She defines a \"prime sum\" of a number as the sum of its prime factors where each prime factor is counted only once, regardless of its multiplicity. For example, the prime sum of 12 is 5 since the prime factors of 12 are 2 and 3, and 2 + 3 = 5.\n\nSara ... | 0.714466 | Code_Contests_4425 | C | [
"is_prime",
"prime_factors",
"prime_sum",
"prime_sum_chain"
] | 4 | [
[
"prime_sum",
"prime_factors"
],
[
"prime_sum_chain",
"is_prime"
],
[
"prime_sum_chain",
"prime_sum"
]
] | 3 | [] | false | [] | false | pytest | true | [] | true | 9738d1cd9a0d5622a7bd33d6f7d858612667526d | 21d37bcd09a14253d153cbb0be40ca506cc51fca | |||
v1.0 | complete | Code_Contests | Code_Contests_4429_C | def is_interesting(number: int) -> bool:
"""
Checks if the number is interesting, which means it contains each digit from 0 to 9 exactly once.
>>> is_interesting(1234567890) True
>>> is_interesting(1023456789) True
>>> is_interesting(9876543210) True
>>> is_interesting(123456789) False
>>> ... | def is_interesting(number):
"""
Checks if the number is interesting, which means it contains each digit from 0 to 9 exactly once.
"""
number_str = str(number)
return len(number_str) == 10 and set(number_str) == set('0123456789')
def next_interesting_number(n):
"""
Returns the smallest inter... | from solution import next_interesting_number, is_interesting
def test_is_interesting():
assert is_interesting(1234567890) == True
assert is_interesting(1023456789) == True
assert is_interesting(9876543210) == True
assert is_interesting(123456789) == False # Less than 10 digits
assert is_interestin... | [
{
"docstring": "Checks if the number is interesting, which means it contains each digit from 0 to 9 exactly once.",
"function_declaration": "def is_interesting(number):",
"function_name": "is_interesting",
"parameter_list": "(number)"
},
{
"docstring": "Returns the smallest interesting numbe... | [
0,
0,
0,
0,
0,
0,
1,
0,
0,
0
] | 1 | hard | 0.1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_interesting(number):\n \"\"\"\n Checks if the given number is an interesting number.\n An interesting number contains all digits from 0 to ... | trial_gpt4o_6 | {
"original_instruction": "Polycarp is a big fan of unique and interesting numbers. He calls a number interesting if it contains all the digits from 0 to 9 exactly once (you cannot skip or repeat any digit from 0 to 9). Given an integer n, Polycarp wants to know the smallest interesting number that is greater than or... | 0.61374 | Code_Contests_4429 | C | [
"is_interesting",
"next_interesting_number"
] | 2 | [
[
"next_interesting_number",
"is_interesting"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | b871fb38feacc0df8dff383da41c6189b155769b | e0e15b3d816381a6ea08481575c7979ba35da20c | |||
v1.0 | complete | Code_Contests | Code_Contests_4749_C | def evaluate_prefix(expression: str) -> int:
"""
Evaluates a single prefix expression.
>>> evaluate_prefix("+ 10 2") 12
>>> evaluate_prefix("* - 3 2 8") 8
>>> evaluate_prefix("/ + 15 5 5") 4
"""
pass
def evaluate_multiple_prefix_expressions(expressions: List[str]) -> List[int]:
"""
... | def evaluate_prefix(expression):
"""
Evaluates a single prefix expression.
"""
stack = []
# Split the expression on whitespace
tokens = expression.split()
# Reverse tokens to process them from right to left
tokens.reverse()
# Define the operations
def operate(op, a, b):
... | from solution import evaluate_prefix, evaluate_multiple_prefix_expressions
def test_evaluate_prefix_addition():
assert evaluate_prefix("+ 10 2") == 12
def test_evaluate_prefix_subtraction():
assert evaluate_prefix("- 10 2") == 8
def test_evaluate_prefix_multiplication():
assert evaluate_prefix("* 3 2") =... | [
{
"docstring": "Evaluates a single prefix expression.",
"function_declaration": "def evaluate_prefix(expression):",
"function_name": "evaluate_prefix",
"parameter_list": "(expression)"
},
{
"docstring": "Evaluates multiple prefix expressions.",
"function_declaration": "def evaluate_multi... | [
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_prefix(expression):\n \"\"\"\n Evaluates a single prefix expression and returns the result.\n \"\"\"\n stack = []\n tokens = ex... | trial_gpt4o_2 | {
"original_instruction": "You are tasked with reading multiple lines of input where each line represents a mathematical expression in prefix notation. Your job is to evaluate each expression and produce the result. Prefix notation (also known as Polish notation) is a way of writing mathematical expressions where the... | 0.587896 | Code_Contests_4749 | C | [
"evaluate_prefix",
"evaluate_multiple_prefix_expressions"
] | 2 | [
[
"evaluate_multiple_prefix_expressions",
"evaluate_prefix"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 6de2283998aec022e17dbe4d17e9f39f773712cc | cfce8addd8d3dcdab59e56d8cc502a05f4644929 | |||
v1.0 | complete | Code_Contests | Code_Contests_3564_C | def word_count_grid(n: int, m: int, grid: List[str], num_words: int, words: List[str]) -> List[int]:
"""
Find out how many times each word appears in the given grid. Words can be constructed
from letters of sequentially adjacent cells (horizontally or vertically neighboring).
:param n: Number of rows i... | def find_word_in_grid(grid, word):
rows, cols = len(grid), len(grid[0])
word_len = len(word)
def backtrack(r, c, index):
if index == word_len:
return True
if r < 0 or r >= rows or c < 0 or c >= cols or grid[r][c] == '#':
return False
if word[index] ... | import pytest
from solution import word_count_grid
def test_example_1():
n, m = 3, 4
grid = ["abce", "sfcs", "adee"]
words = ["see", "bee", "sad"]
expected_output = [1, 0, 1]
assert word_count_grid(n, m, grid, len(words), words) == expected_output
def test_example_2():
n, m = 4, 5
grid = [... | [
{
"docstring": null,
"function_declaration": "def find_word_in_grid(grid, word):",
"function_name": "find_word_in_grid",
"parameter_list": "(grid, word)"
},
{
"docstring": null,
"function_declaration": "def word_count_grid(n, m, grid, num_words, words):",
"function_name": "word_count... | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def find_words(grid, words):\n def dfs(board, word, x, y, index, visited):\n if index == len(word):\n return True\n if (x < 0 o... | trial_gpt4o_1 | {
"original_instruction": "You are given a grid of size N x M filled with some characters. You are also given a list of words. Your task is to find out how many times each word appears in the grid. \n\nA word can be constructed from letters of sequentially adjacent cells, where \"adjacent\" cells are those horizontal... | 0.640647 | Code_Contests_3564 | C | [
"find_word_in_grid",
"word_count_grid"
] | 2 | [
[
"word_count_grid",
"find_word_in_grid"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 049419411bdb05da62a6c81006b963e0b40a3703 | 7850ad230b65c07c54d1f9e6b6a24ae4ac37bb0e | |||
v1.0 | complete | Code_Contests | Code_Contests_4111_C | def is_product_of_two_integers_greater_than_one(n):
"""
Determines if the number n can be represented as the product of two integers greater than 1.
>>> is_product_of_two_integers_greater_than_one(10) == True
>>> is_product_of_two_integers_greater_than_one(7) == False
>>> is_product_of_two_integers_... | def is_product_of_two_integers_greater_than_one(n):
"""
Determines if the number n can be represented as the product of two integers greater than 1.
"""
if n < 4: # The smallest product of integers > 1 is 2 * 2 = 4
return False
for i in range(2, int(n**0.5) + 1):
if n % i == 0 and n... | from solution import calculate_loyalty_points, is_product_of_two_integers_greater_than_one
def test_is_product_of_two_integers_greater_than_one():
assert is_product_of_two_integers_greater_than_one(10) == True
assert is_product_of_two_integers_greater_than_one(7) == False
assert is_product_of_two_integers_... | [
{
"docstring": "Determines if the number n can be represented as the product of two integers greater than 1.",
"function_declaration": "def is_product_of_two_integers_greater_than_one(n):",
"function_name": "is_product_of_two_integers_greater_than_one",
"parameter_list": "(n)"
},
{
"docstrin... | [
0,
0,
0,
0,
0,
1,
1,
0,
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 can_be_product_of_two_integers_greater_than_one(n):\n \"\"\"\n Check if a number n can be expressed as the product of two integers greater than 1... | trial_gpt4o_6 | {
"original_instruction": "A software company is launching a new loyalty points system. Each time a customer makes a purchase, they receive a number of points based on their total purchase amount. However, there are specific rules governing how points are accumulated depending on whether the total purchase amount can... | 0.610966 | Code_Contests_4111 | C | [
"is_product_of_two_integers_greater_than_one",
"calculate_loyalty_points"
] | 2 | [
[
"calculate_loyalty_points",
"is_product_of_two_integers_greater_than_one"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | c655eca905928f67a584efa381d969ee5e29aacd | cd69e8d376cb46e5b217d368eff1b35a7635b148 | |||
v1.0 | complete | Code_Contests | Code_Contests_4513_C | def process_sessions(input_data: str) -> List[int]:
""" Process multiple sessions of temperature readings and return the difference between the
maximum and minimum readings for each location in each session.
>>> process_sessions("2\n3\n-10 0 5\n4\n15 -20 35 10\n")
[15, 55]
>>> process_sess... | def temperature_difference(sessions):
result = []
for readings in sessions:
max_temp = max(readings)
min_temp = min(readings)
difference = max_temp - min_temp
result.append(difference)
return result
def process_sessions(input_data):
lines = input_data.strip().split("\n")... | from solution import process_sessions
def test_single_session():
input_data = "1\n3\n-10 0 5\n"
expected_output = [15]
assert process_sessions(input_data) == expected_output
def test_multiple_sessions():
input_data = "2\n3\n-10 0 5\n4\n15 -20 35 10\n"
expected_output = [15, 55]
assert process_... | [
{
"docstring": null,
"function_declaration": "def temperature_difference(sessions):",
"function_name": "temperature_difference",
"parameter_list": "(sessions)"
},
{
"docstring": null,
"function_declaration": "def process_sessions(input_data):",
"function_name": "process_sessions",
... | [
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 temperature_differences(sessions):\n \"\"\"\n Calculate the difference between \n the maximum and minimum temperature readings for each sessio... | trial_gpt4o_2 | {
"original_instruction": "Tom is interested in analyzing trends in temperature data. He has collected temperature readings from various sensors. Each sensor provides a reading taken at the same time, and he wants to analyze the difference between the highest and lowest readings for each time slot (session) and for e... | 0.568983 | Code_Contests_4513 | C | [
"temperature_difference",
"process_sessions"
] | 2 | [
[
"process_sessions",
"temperature_difference"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 3ec048c450ca7fe5cebae43f631c25aa21285e2c | 74b650d4c6cfc51d4fbce31617b472749426ab02 | |||
v1.0 | complete | Code_Contests | Code_Contests_4605_C | def mysterious_cave(N, M, tunnels):
""" Determine the shortest time in which both adventurers can simultaneously reach the final chamber N
without using the same tunnel at the same time. If it is not possible, return -1.
Example:
>>> mysterious_cave(5, 7, [(1, 2, 2), (1, 3, 3), (2, 3, 1), (2, 4, 2)... | import heapq
def dijkstra(graph, start, N):
dist = [float('inf')] * (N + 1)
dist[start] = 0
pq = [(0, start)]
while pq:
current_dist, node = heapq.heappop(pq)
if current_dist > dist[node]:
continue
for v, weight in graph[node]:
dist... | from solution import mysterious_cave
def test_example_1():
N = 5
M = 7
tunnels = [
(1, 2, 2),
(1, 3, 3),
(2, 3, 1),
(2, 4, 2),
(3, 4, 1),
(4, 5, 3),
(3, 5, 5)
]
assert mysterious_cave(N, M, tunnels) == 7
def test_example_2():
N = 4
M ... | [
{
"docstring": null,
"function_declaration": "def dijkstra(graph, start, N):",
"function_name": "dijkstra",
"parameter_list": "(graph, start, N)"
},
{
"docstring": null,
"function_declaration": "def solve(N, M, tunnels):",
"function_name": "solve",
"parameter_list": "(N, M, tunne... | [
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 heapq\n\ndef dijkstra(graph, start):\n N = len(graph)\n dist = [float('inf')] * N\n dist[start] = 0\n priority_queue = [(0, start)]\n ... | trial_gpt4o_1 | {
"original_instruction": "The Mysterious Cave\n\nProblem Statement\n\nA cave is represented as an undirected graph where each node represents a chamber and each edge represents a tunnel between chambers. \nThere are N chambers and M tunnels within the cave. The cave system starts at chamber 1, and two adventurers ar... | 0.631941 | Code_Contests_4605 | C | [
"dijkstra",
"solve",
"mysterious_cave"
] | 3 | [
[
"mysterious_cave",
"solve"
],
[
"solve",
"dijkstra"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | c42acc41d38f64d24799220d1869c95750339825 | 01db347650056aa51c910021ad15752fd1f6fe20 | |||
v1.0 | complete | Code_Contests | Code_Contests_4442_C | def dfs(grid, m, n, i, j, visited):
"""Helper function to perform depth-first search on the grid to determine if a path is possible."""
pass # Implementation
def is_path_possible(m, n, grid):
"""Determine if there is a path from the top-left to the bottom-right corner of the grid.
Args:
m... | def dfs(grid, m, n, i, j, visited):
if i < 0 or i >= m or j < 0 or j >= n or grid[i][j] == 1 or visited[i][j]:
return False
if i == m - 1 and j == n - 1:
return True
visited[i][j] = True
if dfs(grid, m, n, i + 1, j, visited): # down
return True
if dfs(grid, m, n, i... | from solution import process_input
def test_case_1():
input_data = "3 3\n0 0 0\n1 1 0\n0 0 0\n"
assert process_input(input_data) == ["YES"]
def test_case_2():
input_data = "4 4\n0 1 0 0\n0 1 1 0\n0 0 0 0\n0 1 0 0\n"
assert process_input(input_data) == ["YES"]
def test_case_3():
input_data = "3... | [
{
"docstring": null,
"function_declaration": "def dfs(grid, m, n, i, j, visited):",
"function_name": "dfs",
"parameter_list": "(grid, m, n, i, j, visited)"
},
{
"docstring": null,
"function_declaration": "def is_path_possible(m, n, grid):",
"function_name": "is_path_possible",
"p... | [
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(grid, m, n, i, j, visited):\n if i < 0 or i >= m or j < 0 or j >= n or grid[i][j] == 1 or visited[i][j]:\n return False\n if i == m - ... | trial_gpt4o_0 | {
"original_instruction": "In a bustling city, street intersections are represented on a grid of `m` rows and `n` columns. Each intersection can be represented as a cell in an `m x n` grid. Cars are allowed to travel either north, south, east, or west, but they cannot move diagonally. There are no traffic lights, so ... | 0.599338 | Code_Contests_4442 | C | [
"dfs",
"is_path_possible",
"process_input"
] | 3 | [
[
"is_path_possible",
"dfs"
],
[
"process_input",
"is_path_possible"
]
] | 2 | [
"process_input"
] | false | [] | false | pytest | true | [] | true | 9081fecaae1ee7e8fab782d0e14dadae9237b279 | a451a4eae443dd928cab14b43d5701eb0850e1e2 | |||
v1.0 | complete | Code_Contests | Code_Contests_4232_C | from typing import List, Tuple
def time_to_reach_all_houses(n: int, edges: List[Tuple[int, int, int]]) -> Tuple[List[int], List[int]]:
""" In a certain village, there is a festival where a peculiar game is played.
The game involves a tree with `n` vertices, where each vertex represents a house.
Villagers... | import heapq
import sys
from collections import defaultdict
def time_to_reach_all_houses(n, edges):
graph = defaultdict(list)
for a, b, t in edges:
graph[a].append((b, t))
graph[b].append((a, t))
dist = {i: sys.maxsize for i in range(1, n + 1)}
dist[1] = 0
heap = [(0,... | from solution import time_to_reach_all_houses
def test_example1():
n = 5
edges = [
(1, 2, 1),
(1, 3, 2),
(2, 4, 4),
(3, 5, 3)
]
assert time_to_reach_all_houses(n, edges) == ([0, 1, 2, 5, 5], [4, 5])
def test_example2():
n = 4
edges = [
(1, 2, 1),
... | [
{
"docstring": null,
"function_declaration": "def time_to_reach_all_houses(n, edges):",
"function_name": "time_to_reach_all_houses",
"parameter_list": "(n, edges)"
},
{
"docstring": null,
"function_declaration": "def solution(n, edge_list):",
"function_name": "solution",
"paramet... | [
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 heapq\nimport sys\nfrom collections import defaultdict\n\ndef time_to_reach_all_houses(n, edges):\n graph = defaultdict(list)\n \n for a, b... | trial_gpt4o_0 | {
"original_instruction": "In a certain village, there is a festival where a peculiar game is played. The game involves a tree with `n` vertices, where each vertex represents a house. Villagers use the vertices to encode news passing. The news starts at a root house (vertex 1) and spreads to other houses as per certa... | 0.571465 | Code_Contests_4232 | C | [
"time_to_reach_all_houses",
"solution"
] | 2 | [
[
"solution",
"time_to_reach_all_houses"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 19b23329a41fedd7da5d1f4cdfaedd155efab824 | 726a1a6e32379e09b074dd9d565709bf35c6f840 | |||
v1.0 | complete | Code_Contests | Code_Contests_4408_C | from typing import List
def filter_primes(numbers: List[int]) -> List[int]:
"""
Given a list of integers, returns a new list containing only the integers
that are prime numbers.
>>> filter_primes([2, 3, 4, 5, -7, 10, 13, 17, 23, 9, 11])
[2, 3, 5, 13, 17, 23, 11]
>>> filter_primes([2, 3, ... | from typing import List
def is_prime(n: int) -> bool:
"""
Helper function to determine if a given number n 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):
... | from solution import filter_primes
def test_filter_primes_with_mixed_numbers():
assert filter_primes([2, 3, 4, 5, -7, 10, 13, 17, 23, 9, 11]) == [2, 3, 5, 13, 17, 23, 11]
def test_filter_primes_with_all_primes():
assert filter_primes([2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71,... | [
{
"docstring": "Helper function to determine if a given number n is prime.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Given a list of integers, return a new list containing only the prime numbers.",
"function_decl... | [
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\n\ndef is_prime(n: int) -> bool:\n if n <= 1:\n return False\n if n <= 3:\n return True\n if n % 2 == 0 or n... | trial_gpt4o_1 | {
"original_instruction": "Your task is to write a function that, given a list of integers, returns a new list containing only the integers that are prime numbers.\n\n### Function Signature\n\n```python\ndef filter_primes(numbers: List[int]) -> List[int]:\n```\n\n### Input\n\n- `numbers`: A list of integers. `2 <= le... | 0.688725 | Code_Contests_4408 | C | [
"is_prime",
"filter_primes"
] | 2 | [
[
"filter_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | ccc126cdc248adb30dab868b93afaa6d7882d39b | cff4708b8db38318ddcfea10525c281fba5de4d3 | |||
v1.0 | complete | Code_Contests | Code_Contests_5047_C | from typing import List
def rotate_matrix_clockwise(matrix: List[List[str]]) -> List[List[str]]:
"""
Rotates the given N x N matrix 90 degrees clockwise.
Parameters:
matrix (list of list of str): The matrix to be rotated.
Returns:
list of list of str: The rotated matrix.
"""
def format_m... | def rotate_matrix_clockwise(matrix):
"""
Rotates the given N x N matrix 90 degrees clockwise.
Parameters:
matrix (list of list of str): The matrix to be rotated.
Returns:
list of list of str: The rotated matrix.
"""
# Transpose the matrix
transposed_matrix = [[matrix[j][i] ... | from solution import rotate_matrix_clockwise, format_matrix
def test_rotate_3x3_matrix():
matrix = [
['a', 'b', 'c'],
['d', 'e', 'f'],
['g', 'h', 'i']
]
rotated_matrix = rotate_matrix_clockwise(matrix)
expected = [
['g', 'd', 'a'],
['h', 'e', 'b'],
['i', ... | [
{
"docstring": "Rotates the given N x N matrix 90 degrees clockwise.\n\nParameters:\nmatrix (list of list of str): The matrix to be rotated.\n\nReturns:\nlist of list of str: The rotated matrix.",
"function_declaration": "def rotate_matrix_clockwise(matrix):",
"function_name": "rotate_matrix_clockwise",... | [
0,
0,
0,
0,
0,
0,
0,
0,
1,
0
] | 1 | hard | 0.1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def rotate_matrix_90_clockwise(matrix):\n \"\"\"\n Rotates the given N x N matrix 90 degrees clockwise.\n \n Parameters:\n matrix (list of l... | trial_gpt4o_8 | {
"original_instruction": "You are given a square matrix of size N x N consisting of lowercase Latin letters. You need to rotate the matrix 90 degrees clockwise.\n\nThe rotation can be achieved by first transposing the matrix and then reversing each row.\n\nInput\n\nThe first line contains an integer N (2 ≤ N ≤ 10) w... | 0.562093 | Code_Contests_5047 | C | [
"rotate_matrix_clockwise",
"format_matrix",
"read_and_rotate_matrix"
] | 3 | [
[
"read_and_rotate_matrix",
"format_matrix"
],
[
"read_and_rotate_matrix",
"rotate_matrix_clockwise"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 28120b46831cdd1c5c1e86d3fa5c1cc99ab01627 | d850b74c29747a00d97863bf4cae295733183c0d | |||
v1.0 | complete | Code_Contests | Code_Contests_3779_C | def validate_grid(grid, r, c):
""" Validates if a grid is connected.
"""
def is_connected(grid, r, c):
def dfs(x, y):
stack = [(x, y)]
while stack:
cx, cy = stack.pop()
if visited[cx][cy]:
continue
visited[cx... | def validate_grid(grid, r, c):
def is_connected(grid, r, c):
def dfs(x, y):
stack = [(x, y)]
while stack:
cx, cy = stack.pop()
if visited[cx][cy]:
continue
visited[cx][cy] = True
for nx, ny in ((cx + ... | import pytest
from solution import main, parse_input, game_level_validator
def test_main():
input_str = """4 5 2
1 0 2 2 1
2 2 0 1 2
2 1 1 1 1
1 1 2 2 2
2 3 10
1 5 10
3 3 1
1 1 1
1 0 1
1 1 1
1 6 6
0 0 0"""
expected_output = "VALID\nINVALID"
assert main(input_str) == expected_output
def test_game_level_val... | [
{
"docstring": null,
"function_declaration": "def validate_grid(grid, r, c):",
"function_name": "validate_grid",
"parameter_list": "(grid, r, c)"
},
{
"docstring": null,
"function_declaration": "def check_key_tiles(grid, r, c, key_constraints):",
"function_name": "check_key_tiles",
... | [
0,
0,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_connected(grid, r, c):\n from collections import deque\n \n directions = [(-1, 0), (1, 0), (0, -1), (0, 1)]\n \n # Find first non-zer... | trial_gpt4o_2 | {
"original_instruction": "Game Level Generator\n\nYou are developing a game that includes a level generator. Each level is represented by a grid with rows and columns filled with various tiles. Each tile is assigned a number, representing different types of terrain or obstacles. The level generator must ensure that ... | 0.622176 | Code_Contests_3779 | C | [
"validate_grid",
"check_key_tiles",
"game_level_validator",
"parse_input",
"main"
] | 5 | [
[
"game_level_validator",
"check_key_tiles"
],
[
"game_level_validator",
"validate_grid"
]
] | 2 | [
"parse_input"
] | false | [] | false | pytest | true | [] | true | 275a5cc94a7a1733f0822b659b26b0604a281699 | 7768ecb1dac7354ebd9133ce6295a21dc7f963fc | |||
v1.0 | complete | Code_Contests | Code_Contests_4800_C | def has_palindrome_path(N: int, M: int, node_values: str, edges: List[Tuple[int, int]]) -> str:
""" You are given an undirected graph represented as an adjacency list, in which each node contains a lowercase English letter as its value.
Your task is to determine if there exists a path between any two nodes such... | from collections import defaultdict, deque
def is_palindrome(s):
""" Helper function to check if a given string is a palindrome. """
return s == s[::-1]
def dfs(graph, visited, node, path, values, result):
""" Depth-first search to find if any path forms a palindrome. """
if result[0]: # If a palindr... | import pytest
from solution import has_palindrome_path
def test_example_1():
assert has_palindrome_path(5, 5, "abcba", [(0, 1), (1, 2), (2, 3), (3, 4), (4, 0)]) == "YES"
def test_example_2():
assert has_palindrome_path(3, 2, "abc", [(0, 1), (1, 2)]) == "NO"
def test_single_node():
assert has_palindrome_p... | [
{
"docstring": "Helper function to check if a given string is a palindrome. ",
"function_declaration": "def is_palindrome(s):",
"function_name": "is_palindrome",
"parameter_list": "(s)"
},
{
"docstring": "Depth-first search to find if any path forms a palindrome. ",
"function_declaration... | [
1,
0,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from collections import defaultdict, deque\n\ndef is_palindrome(s):\n \"\"\" Helper function to check if a given string is a palindrome. \"\"\"\n ret... | trial_gpt4o_0 | {
"original_instruction": "You are given an undirected graph represented as an adjacency list, in which each node contains a lowercase English letter as its value. Your task is to determine if there exists a path between any two nodes such that the concatenation of all node values along the path forms a palindrome.\n... | 0.697843 | Code_Contests_4800 | C | [
"is_palindrome",
"dfs",
"has_palindrome_path"
] | 3 | [
[
"dfs",
"is_palindrome"
],
[
"has_palindrome_path",
"dfs"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | f8b3808e6f90e9c762dddd5ac1882427b3a2e653 | bb1ae1d7139c02a8f489f83e838d5b2ee9346c87 | |||
v1.0 | complete | Code_Contests | Code_Contests_5065_C | def max_satisfaction_in_sublist(S: List[int], l: int, r: int) -> int:
"""Calculates the maximum total satisfaction for a sublist of activities with strictly increasing satisfaction values.
Args:
S (List[int]): List of satisfaction values of activities.
l (int): Start index of the sublist (1-based).
... | def max_satisfaction_in_sublist(S, l, r):
sublist = S[l-1:r]
n = len(sublist)
if n == 0:
return 0
dp = [0] * n
dp[0] = sublist[0]
max_sum = dp[0]
for i in range(1, n):
dp[i] = sublist[i]
for j in range(i):
if sublist[j] < sublist[i]:
... | def test_max_satisfaction_in_sublist():
assert max_satisfaction_in_sublist([1, 2, 3, 4, 5], 1, 5) == 15
assert max_satisfaction_in_sublist([1, 2, 1, 4, 5], 1, 5) == 12
assert max_satisfaction_in_sublist([1, 2, 1, 4, 2], 1, 5) == 7
def test_process_queries():
N = 5
S = [1, 2, 3, 4, 5]
queries = ... | [
{
"docstring": null,
"function_declaration": "def max_satisfaction_in_sublist(S, l, r):",
"function_name": "max_satisfaction_in_sublist",
"parameter_list": "(S, l, r)"
},
{
"docstring": null,
"function_declaration": "def process_queries(N, S, queries):",
"function_name": "process_que... | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def max_total_satisfaction(N, satisfaction_values, queries):\n from bisect import bisect_right\n import sys\n\n def process_query_type_2(l, r):\n ... | trial_gpt4o_1 | {
"original_instruction": "Angie is planning her weekend and wants to complete as many activities as possible. Each activity is associated with a certain level of satisfaction, Si. Angie wants to maximize her overall satisfaction after completing a series of activities.\n\nOn a particular weekend, she has N activitie... | 0.600435 | Code_Contests_5065 | C | [
"max_satisfaction_in_sublist",
"process_queries",
"angie_activities"
] | 3 | [
[
"angie_activities",
"process_queries"
],
[
"process_queries",
"max_satisfaction_in_sublist"
]
] | 2 | [
"process_queries"
] | false | [] | false | pytest | false | [] | true | 577db4a39568941e548aca8c4562eeb4c056715d | db9fe0e5b87bfd395ae7bfbda64d588333586fff | |||
v1.0 | complete | Code_Contests | Code_Contests_5380_C | import heapq
from typing import List, Tuple, Union
def dijkstra(N: int, edges: List[Tuple[int, int, int]], S: int) -> List[Union[int, str]]:
"""Find the shortest paths from a given source vertex S to all other vertices in a weighted directed graph using Dijkstra's algorithm.
N: int - Number of nodes
e... | import heapq
def dijkstra(N, edges, S):
graph = {i: [] for i in range(1, N+1)}
for u, v, w in edges:
graph[u].append((v, w))
dist = {i: float('inf') for i in range(1, N+1)}
dist[S] = 0
priority_queue = [(0, S)]
while priority_queue:
current_dist, u = heapq.heappop(priority... | from solution import run
def test_example_1():
input_string = "4 4\n1 2 2\n1 3 5\n2 4 10\n3 4 3\n1"
assert run(input_string) == [0, 2, 5, 8]
def test_example_2():
input_string = "3 3\n1 2 4\n1 3 1\n2 3 2\n2"
assert run(input_string) == ['INF', 0, 2]
def test_disconnected_graph():
input_string = "... | [
{
"docstring": null,
"function_declaration": "def dijkstra(N, edges, S):",
"function_name": "dijkstra",
"parameter_list": "(N, edges, S)"
},
{
"docstring": null,
"function_declaration": "def parse_input(input_string):",
"function_name": "parse_input",
"parameter_list": "(input_st... | [
1,
0,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import heapq\n\ndef dijkstra(N, edges, S):\n graph = {i: [] for i in range(1, N+1)}\n for u, v, w in edges:\n graph[u].append((v, w))\n\n d... | trial_gpt4o_0 | {
"original_instruction": "You are given a weighted directed graph with N nodes and M edges. Each edge has a positive weight associated with it. You need to find the shortest paths from a given source vertex S to all other vertices using Dijkstra's algorithm. If a node is unreachable from the source, print `INF` for ... | 0.650717 | Code_Contests_5380 | C | [
"dijkstra",
"parse_input",
"run"
] | 3 | [
[
"run",
"dijkstra"
],
[
"run",
"parse_input"
]
] | 2 | [
"parse_input"
] | false | [] | false | pytest | true | [] | true | 64660f583c542232dd2028f83d542f1b0f62e58c | 0c3d559ade4faa401d75ddc18f97542f0452dd9f | |||
v1.0 | complete | Code_Contests | Code_Contests_5395_C | from typing import List
def most_frequent_word(datasets: List[List[str]]) -> List[str]:
""" Given a list of words, find and return the most frequent word for each dataset.
If two or more words have the same highest frequency, return the lexicographically smallest one among them.
Args:
datasets: Li... | def most_frequent_word(datasets):
from collections import Counter
results = []
for dataset in datasets:
word_count = Counter(dataset)
# Find the maximum frequency
max_freq = max(word_count.values())
# Collect all words with the maximum frequency
max... | from solution import most_frequent_word, parse_input, get_most_frequent_in_datasets
def test_most_frequent_word():
datasets = [
['apple', 'banana', 'apple', 'orange', 'banana'],
['apple', 'apple', 'banana', 'banana'],
['apple', 'banana', 'apple', 'banana', 'cherry', 'cherry']
]
asse... | [
{
"docstring": null,
"function_declaration": "def most_frequent_word(datasets):",
"function_name": "most_frequent_word",
"parameter_list": "(datasets)"
},
{
"docstring": null,
"function_declaration": "def parse_input(input_str):",
"function_name": "parse_input",
"parameter_list":... | [
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 most_frequent_word(datasets):\n \"\"\"\n Given a list of datasets, this function returns the most frequent word in each dataset. If multiples wor... | trial_gpt4o_2 | {
"original_instruction": "Given a list of words, you are to find and print the most frequent word. If two or more words have the same highest frequency, print the lexicographically smallest one among them.\n\nInput\n\nThe input consists of up to 100 datasets. Each dataset is represented in the following format:\n\nT... | 0.7369 | Code_Contests_5395 | C | [
"most_frequent_word",
"parse_input",
"get_most_frequent_in_datasets"
] | 3 | [
[
"get_most_frequent_in_datasets",
"most_frequent_word"
],
[
"get_most_frequent_in_datasets",
"parse_input"
]
] | 2 | [
"parse_input"
] | false | [] | false | pytest | true | [] | true | 4f15281607690e6b9381c88eea5eccc31c9b9d55 | 48eafd59af0622205be315bba98a9f5be8f34a17 | |||
v1.0 | complete | Code_Contests | Code_Contests_5003_C | from typing import List, Tuple, Union
def solve(n: int, m: int, k: int, roads: List[Tuple[int, int]], agencies: List[int]) -> Union[str, Tuple[str, int]]:
"""In a small town, there's a series of roads connecting various intersections and detective agencies positioned at different intersections.
Each agenc... | import sys
from collections import defaultdict, deque
def find_scc(n, graph):
index = [None] * n
lowlink = [None] * n
on_stack = [False] * n
stack = []
sccs = []
index_counter = [0]
def strongconnect(v):
index[v] = index_counter[0]
lowlink[v] = index_counter[0]
... | from solution import solve
def test_case_1():
n = 6
m = 6
k = 2
roads = [(1, 2), (2, 3), (3, 4), (4, 5), (5, 6), (6, 1)]
agencies = [1, 4]
assert solve(n, m, k, roads, agencies) == "YES"
def test_case_2():
n = 6
m = 4
k = 2
roads = [(1, 2), (2, 3), (4, 5), (5, 6)]
agencies ... | [
{
"docstring": null,
"function_declaration": "def find_scc(n, graph):",
"function_name": "find_scc",
"parameter_list": "(n, graph)"
},
{
"docstring": null,
"function_declaration": "def minimum_additional_roads_to_connect_sccs(n, sccs, graph):",
"function_name": "minimum_additional_ro... | [
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 is_reachable_from_all_agencies(n, m, roads, k, agencies):\n def build_graph():\n graph = defaul... | trial_gpt4o_1 | {
"original_instruction": "In a small town, there's a series of roads connecting various intersections. Each intersection has a unique identifier ranging from 1 to n. However, some intersections have directed roads that only allow traffic in one direction. The town has k detective agencies, each positioned at differe... | 0.710694 | Code_Contests_5003 | C | [
"find_scc",
"minimum_additional_roads_to_connect_sccs",
"solve"
] | 3 | [
[
"solve",
"find_scc"
],
[
"solve",
"minimum_additional_roads_to_connect_sccs"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | bd368651629420f6407f511810d90914dcd9574b | 7bf3cab30c692c7657c7cba46bb6fec7ee169e2a | |||
v1.0 | complete | Code_Contests | Code_Contests_5702_C | def find_primes_between(a: int, b: int) -> List[int]:
""" Find all prime numbers between two given integers a and b (inclusive).
Args:
a (int): The start of the range.
b (int): The end of the range.
Returns:
List[int]: A list of prime numbers in the given range or "None" if there are n... | def sieve_of_eratosthenes(max_num):
# Create a boolean array "prime[0..n]" and initialize
# all entries it as true. A value in prime[i] will
# finally be false if i is Not a prime, else true.
prime = [True for _ in range(max_num + 1)]
p = 2
while p * p <= max_num:
# If prime[p] is not ch... | from solution import find_primes_between
def test_prime_range_with_primes():
assert find_primes_between(10, 30) == [11, 13, 17, 19, 23, 29]
def test_prime_range_without_primes():
assert find_primes_between(14, 16) == ["None"]
def test_prime_range_single_prime():
assert find_primes_between(29, 29) == [29]... | [
{
"docstring": null,
"function_declaration": "def sieve_of_eratosthenes(max_num):",
"function_name": "sieve_of_eratosthenes",
"parameter_list": "(max_num)"
},
{
"docstring": null,
"function_declaration": "def find_primes_between(a, b):",
"function_name": "find_primes_between",
"p... | [
1,
0,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def prime_numbers_in_range(a, b):\n \"\"\"\n Finds all prime numbers between a and b inclusive, using the Sieve of Eratosthenes algorithm.\n \n ... | trial_gpt4o_2 | {
"original_instruction": "Dr. Lyons: Mark, do you know about prime numbers?\n\nMark: Yes, a prime number is a natural number greater than 1 that has no positive divisors other than 1 and itself.\n\nDr. Lyons: Exactly. Do you think you could write a program that finds all prime numbers between two given integers?\n\n... | 0.693462 | Code_Contests_5702 | C | [
"sieve_of_eratosthenes",
"find_primes_between"
] | 2 | [
[
"find_primes_between",
"sieve_of_eratosthenes"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | c63504e2258dcbed94e20136baf02e6738435f5c | 445e39814d1ab5c638ad1a7404d0cb7a5050c4a4 | |||
v1.0 | complete | Code_Contests | Code_Contests_5769_C | def sum_of_squared_differences(n: int) -> int:
"""
Given an integer n, calculates the sum of squared differences
between every two elements in the sequence from 1 to n (inclusive).
>>> sum_of_squared_differences(3)
6
>>> sum_of_squared_differences(4)
20
"""
def compute_sum_of_squar... | def sum_of_squared_differences(n):
"""
Given an integer n, calculates the sum of squared differences
between every two elements in the sequence from 1 to n (inclusive).
"""
total_sum = 0
for i in range(1, n + 1):
for j in range(i + 1, n + 1):
total_sum += (i - j) ** 2
re... | from solution import sum_of_squared_differences, compute_sum_of_squared_differences
def test_sum_of_squared_differences():
assert sum_of_squared_differences(3) == 6
assert sum_of_squared_differences(4) == 20
assert sum_of_squared_differences(5) == 50
assert sum_of_squared_differences(1) == 0
assert... | [
{
"docstring": "Given an integer n, calculates the sum of squared differences \nbetween every two elements in the sequence from 1 to n (inclusive).",
"function_declaration": "def sum_of_squared_differences(n):",
"function_name": "sum_of_squared_differences",
"parameter_list": "(n)"
},
{
"doc... | [
1,
0,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def sum_of_squared_differences(n):\n \"\"\"\n Given an integer n, calculates the sum of squared differences \n between every two elements in the s... | trial_gpt4o_0 | {
"original_instruction": "Ben is a talented software engineer who loves everything about numbers. One day, he was exploring different properties of numbers and discovered an interesting property about sequences of consecutive integers. He defined a sequence of numbers from 1 to n (inclusive) and wanted to calculate ... | 0.750066 | Code_Contests_5769 | C | [
"sum_of_squared_differences",
"compute_sum_of_squared_differences",
"process_input"
] | 3 | [
[
"compute_sum_of_squared_differences",
"sum_of_squared_differences"
],
[
"process_input",
"compute_sum_of_squared_differences"
]
] | 2 | [
"process_input"
] | false | [] | false | pytest | true | [] | true | 2d9577add251aa95b34caf743051d2574fc171c2 | 778555662efe76a10338b2a547153bb38b770250 | |||
v1.0 | complete | Code_Contests | Code_Contests_5362_C | def rotate_matrix_90_degrees_clockwise(matrix: List[List[int]]) -> List[List[int]]:
""" Rotates a given NxN square matrix 90 degrees clockwise.
>>> rotate_matrix_90_degrees_clockwise([[1, 2, 3], [4, 5, 6], [7, 8, 9]])
[[7, 4, 1], [8, 5, 2], [9, 6, 3]]
>>> rotate_matrix_90_degrees_clockwise([[1, 2, 3, 4]... | def rotate_matrix_90_degrees_clockwise(matrix):
"""
Rotates a given NxN square matrix 90 degrees clockwise.
"""
N = len(matrix)
# The result matrix initialized with zeros
result = [[0] * N for _ in range(N)]
for i in range(N):
for j in range(N):
result[j][N-1-i] = ma... | from solution import rotate_matrix_90_degrees_clockwise, read_matrix_and_rotate, matrix_to_string
def test_rotate_3x3_matrix():
matrix = [
[1, 2, 3],
[4, 5, 6],
[7, 8, 9]
]
rotated = rotate_matrix_90_degrees_clockwise(matrix)
expected = [
[7, 4, 1],
[8, 5, 2],
... | [
{
"docstring": "Rotates a given NxN square matrix 90 degrees clockwise.",
"function_declaration": "def rotate_matrix_90_degrees_clockwise(matrix):",
"function_name": "rotate_matrix_90_degrees_clockwise",
"parameter_list": "(matrix)"
},
{
"docstring": "Helper function to read the matrix from ... | [
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 rotate_matrix_90_degrees(matrix):\n \"\"\"\n Rotate the NxN matrix 90 degrees clockwise.\n \n :param matrix: List of lists, where each inne... | trial_gpt4o_2 | {
"original_instruction": "Square Matrix Rotation\n\nWrite a program to rotate a given NxN square matrix 90 degrees clockwise.\n\nConstraints\n\n* $1 \\leq N \\leq 100$\n* Each element in the matrix is an integer between -1000 and 1000\n\nInput\n\nThe first line contains a single integer N, the size of the NxN matrix... | 0.578687 | Code_Contests_5362 | C | [
"rotate_matrix_90_degrees_clockwise",
"read_matrix_and_rotate",
"matrix_to_string"
] | 3 | [
[
"read_matrix_and_rotate",
"rotate_matrix_90_degrees_clockwise"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 4179e3ea3b366f6c4c688ddfc2c8877c0bea4879 | 855f699e3c49ef7826d608c88675ad0030b127d2 | |||
v1.0 | complete | Code_Contests | Code_Contests_5721_C | def main(input_string: str) -> List[str]:
"""
A company has a network of computers. Each computer can directly communicate with a set of other computers, and the communication is bi-directional. The company wants to ensure that information can be spread from one specific computer to all other computers through ... | def is_network_connected(n, m, connections):
from collections import deque, defaultdict
if n == 1:
return True
graph = defaultdict(list)
for u, v in connections:
graph[u].append(v)
graph[v].append(u)
visited = set()
queue = deque([1])
visited.add(1)
wh... | from solution import main
def test_example_case():
input_string = "3 2\n1 2\n2 3\n4 2\n1 2\n3 4\n5 0\n0\n"
expected_output = ["YES", "NO", "NO"]
assert main(input_string) == expected_output
def test_single_computer_case():
input_string = "1 0\n0\n"
expected_output = ["YES"]
assert main(input_s... | [
{
"docstring": null,
"function_declaration": "def is_network_connected(n, m, connections):",
"function_name": "is_network_connected",
"parameter_list": "(n, m, connections)"
},
{
"docstring": null,
"function_declaration": "def check_network_connectivity(datasets):",
"function_name": ... | [
0,
0,
0,
1,
1
] | 2 | medium | 0.4 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def can_inform_all_computers(n, m, connections):\n \"\"\"\n Determines if information can be spread from one specific computer\n to all other comp... | trial_gpt4o_4 | {
"original_instruction": "A company has a network of computers. Each computer can directly communicate with a set of other computers, and the communication is bi-directional. The company wants to ensure that information can be spread from one specific computer to all other computers through this network. You need to... | 0.546361 | Code_Contests_5721 | C | [
"is_network_connected",
"check_network_connectivity",
"parse_input",
"main"
] | 4 | [
[
"check_network_connectivity",
"is_network_connected"
]
] | 1 | [
"parse_input"
] | false | [] | false | pytest | true | [] | true | 2533cdc775011348eb91c4a9fd54ad0e7cd39eba | 1b1b3a60e6fdfb7145d0307077cf940ce4cf7964 | |||
v1.0 | complete | Code_Contests | Code_Contests_5868_C | from typing import List, Tuple
def num_distinct_paths(n: int, m: int) -> int:
"""
Returns the number of distinct paths from top-left to bottom-right
on an n x m grid moving only right or down.
>>> num_distinct_paths(2, 2)
2
>>> num_distinct_paths(3, 3)
6
"""
def calculate_paths(test_c... | from math import comb
def num_distinct_paths(n, m):
"""
Returns the number of distinct paths from top-left to bottom-right
on an n x m grid moving only right or down.
"""
return comb(n + m - 2, n - 1)
def calculate_paths(test_cases):
results = []
for n, m in test_cases:
results.ap... | from solution import num_distinct_paths, calculate_paths, parse_input
def test_num_distinct_paths():
assert num_distinct_paths(2, 2) == 2
assert num_distinct_paths(3, 3) == 6
assert num_distinct_paths(1, 1) == 1
assert num_distinct_paths(4, 5) == 35
def test_calculate_paths():
assert calculate_pat... | [
{
"docstring": "Returns the number of distinct paths from top-left to bottom-right \non an n x m grid moving only right or down.",
"function_declaration": "def num_distinct_paths(n, m):",
"function_name": "num_distinct_paths",
"parameter_list": "(n, m)"
},
{
"docstring": null,
"function_... | [
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 distinct_paths(n, m):\n \"\"\"\n Calculates the number of distinct paths in a n x m grid from the top-left to the bottom-right corner\n moving... | trial_gpt4o_2 | {
"original_instruction": "On a grid of size n x m, you start from the top-left corner and want to reach the bottom-right corner. You can only move either right or down. Your task is to calculate the number of distinct paths you can take to reach the destination.\n\nINPUT:\n\nThe first line contains the number of tes... | 0.619042 | Code_Contests_5868 | C | [
"num_distinct_paths",
"calculate_paths",
"parse_input"
] | 3 | [
[
"calculate_paths",
"num_distinct_paths"
]
] | 1 | [
"parse_input"
] | false | [] | false | pytest | true | [] | true | fdc2e79393423b7f5d5ffc192529c2caf9525098 | b35ccae8f558d81a1bc40aeaa6d49bc3264a7387 | |||
v1.0 | complete | Code_Contests | Code_Contests_5498_C | def sort_matrix(matrix):
"""
This function takes a matrix and returns a new matrix where each row and each
column is sorted in ascending order while maintaining the relative positions
of all matrix elements.
"""
def transform_and_print_matrix(N, M, matrix):
"""
This function takes matrix ... | def sort_matrix(matrix):
"""
This function takes a matrix and returns a new matrix where each row and each
column is sorted in ascending order while maintaining the relative positions
of all matrix elements.
"""
N = len(matrix)
M = len(matrix[0])
# Flatten the matrix and sort the ... | def test_sort_matrix_case_1():
matrix = [
[3, 1, 2],
[4, 6, 5],
[7, 9, 8]
]
expected = [
[1, 2, 3],
[4, 5, 6],
[7, 8, 9]
]
assert sort_matrix(matrix) == expected
def test_sort_matrix_case_2():
matrix = [
[1, 3, 5, 7],
[2, 4, 6, 8]
... | [
{
"docstring": "This function takes a matrix and returns a new matrix where each row and each \ncolumn is sorted in ascending order while maintaining the relative positions \nof all matrix elements.",
"function_declaration": "def sort_matrix(matrix):",
"function_name": "sort_matrix",
"parameter_list... | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def sort_matrix(matrix):\n \"\"\"\n Transforms the input matrix such that each row and column are sorted in ascending order\n while maintaining th... | trial_gpt4o_1 | {
"original_instruction": "You are given a matrix of size N x M filled with integers. Your task is to transform the matrix such that every row and every column is sorted in ascending order while maintaining the relative positions of all matrix elements. \n\nPrint the transformed matrix in the format specified in the ... | 0.53824 | Code_Contests_5498 | C | [
"sort_matrix",
"transform_and_print_matrix",
"main"
] | 3 | [
[
"transform_and_print_matrix",
"sort_matrix"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | c297b68d20f428dbb296154dd384e13673a196b2 | 16f91730b662e64a270f7b9e360657d6829f65f7 | |||
v1.0 | complete | Code_Contests | Code_Contests_5961_C | def is_prime(n: int) -> bool:
"""
Returns True if the number is prime, False otherwise.
>>> is_prime(2) True
>>> is_prime(4) False
>>> is_prime(17) True
"""
def prime_sum(x: int) -> int:
"""
Computes the sum of all prime numbers less than or equal to x.
>>> prime_sum(10) 17
... | def is_prime(n):
"""
Returns True if the number is prime, False otherwise.
"""
if n <= 1:
return False
if n <= 3:
return True
if n % 2 == 0 or n % 3 == 0:
return False
i = 5
while i * i <= n:
if n % i == 0 or n % (i + 2) == 0:
return False
... | from solution import is_prime, prime_sum, solve_primes
def test_is_prime():
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(4) == False
assert is_prime(5) == True
assert is_prime(29) == True
assert is_prime(30) == False
def test_prime_sum():
assert prime_sum(10) == 17... | [
{
"docstring": "Returns True if the number is prime, False otherwise.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Computes the sum of all prime numbers less than or equal to x.",
"function_declaration": "def prime_... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(n):\n \"\"\"\n Check if a number is prime.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return True\n i... | trial_gpt4o_1 | {
"original_instruction": "Maurice loves prime numbers. He came up with a function f(x) which is defined as the sum of all positive integers less than or equal to x. However, Maurice only wants the sum to include prime numbers. \n\nYour task is to help Maurice find the sum f(x) for a given integer x.\n\n### Input\n- ... | 0.733491 | Code_Contests_5961 | C | [
"is_prime",
"prime_sum",
"solve_primes"
] | 3 | [
[
"prime_sum",
"is_prime"
],
[
"solve_primes",
"prime_sum"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 5b5ceba20403fc38d802392f29249eba9e00191d | 03c7fa60e748029e21ee8768147a59484006c1b1 | |||
v1.0 | complete | Code_Contests | Code_Contests_5550_C | def check_numbers(t: int, numbers: List[int]) -> List[str]:
""" You are given a list of integers. For each integer, determine whether it can be represented as the sum
of two unique prime numbers. Write a program to solve this problem.
INPUT
The first line contains a single integer t (1 ≤ t ≤ 10^6),... | def sieve(n):
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
is_prime[0], is_prime[1] = False, False
primes = [p for p in range(n + 1) if is_prime[p]]
return primes, is_pr... | from solution import check_numbers
def test_example_case():
t = 3
numbers = [10, 17, 34]
expected = ["YES", "NO", "YES"]
assert check_numbers(t, numbers) == expected
def test_single_no_case():
t = 1
numbers = [17]
expected = ["NO"]
assert check_numbers(t, numbers) == expected
def test... | [
{
"docstring": null,
"function_declaration": "def sieve(n):",
"function_name": "sieve",
"parameter_list": "(n)"
},
{
"docstring": null,
"function_declaration": "def can_be_sum_of_two_unique_primes(n, primes, is_prime):",
"function_name": "can_be_sum_of_two_unique_primes",
"parame... | [
0,
0,
0,
1,
0
] | 1 | hard | 0.2 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def sieve_of_eratosthenes(limit):\n sieve = [True] * (limit + 1)\n sieve[0] = sieve[1] = False\n p = 2\n while p * p <= limit:\n if siev... | trial_gpt4o_3 | {
"original_instruction": "You are given a list of integers. For each integer, determine whether it can be represented as the sum of two unique prime numbers. Write a program to solve this problem.\n\nInput\nThe first line contains a single integer t (1 ≤ t ≤ 10^6), the number of test cases.\nEach of the next t lines... | 0.70773 | Code_Contests_5550 | C | [
"sieve",
"can_be_sum_of_two_unique_primes",
"check_numbers"
] | 3 | [
[
"check_numbers",
"can_be_sum_of_two_unique_primes"
],
[
"check_numbers",
"sieve"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | df2c5d86c301c3c4d45ae3cc0a1fa7e689a6ef7e | b1969036f3cc38af93cf643e47bf7d76c5498d90 | |||
v1.0 | complete | Code_Contests | Code_Contests_5798_C | class TreeNode:
def __init__(self, value=0, left=None, right=None):
self.value = value
self.left = left
self.right = right
def build_tree(node_list):
if not node_list:
return None
nodes = {}
for value, left, right in node_list:
if value not in nodes:
... | class TreeNode:
def __init__(self, value=0, left=None, right=None):
self.value = value
self.left = left
self.right = right
def build_tree(node_list):
if not node_list:
return None
nodes = {}
for value, left, right in node_list:
if value not in nodes:
... | from solution import height_of_binary_tree
def test_single_node_tree():
# Tree: 1
n = 1
nodes = [(1, -1, -1)]
assert height_of_binary_tree(n, nodes) == 0
def test_empty_tree():
# Tree: (empty)
n = 0
nodes = []
assert height_of_binary_tree(n, nodes) == -1
def test_three_level_tree():
... | [] | [
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=0, left=None, right=None):\n self.value = value\n self.left = left\n self.right = right\... | trial_gpt4o_3 | {
"original_instruction": "Write a function that determines the height of a binary tree. The height of a binary tree is the number of edges between the tree's root and its furthest leaf. You will need to implement a helper function to build the tree from a list of tuples representing the nodes and their respective le... | 0.607616 | Code_Contests_5798 | C | [
"build_tree",
"height_of_binary_tree"
] | 2 | [
[
"height_of_binary_tree",
"build_tree"
]
] | 1 | [] | false | [
"TreeNode"
] | true | pytest | true | [] | true | 24ccf9455ac20b14753bc7891cb46ac61b7aacbc | a0d3caa4783c9ea7781580d3601ce8b7c2f88cbc | |||
v1.0 | complete | Code_Contests | Code_Contests_6285_C | def is_prime(num: int) -> bool:
""" Check if the given number is a prime number.
>>> is_prime(2) == True
>>> is_prime(3) == True
>>> is_prime(4) == False
>>> is_prime(5) == True
>>> is_prime(1) == False
>>> is_prime(0) == False
"""
def nearest_prime(n: int) -> int:
""" Find the ... | def is_prime(num):
"""
Check if the given number is a prime number.
"""
if num <= 1:
return False
if num == 2:
return True
if num % 2 == 0:
return False
for i in range(3, int(num**0.5) + 1, 2):
if num % i == 0:
return False
return True
def nea... | def test_is_prime():
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(4) == False
assert is_prime(5) == True
assert is_prime(1) == False
assert is_prime(0) == False
def test_nearest_prime():
assert nearest_prime(10) == 7
assert nearest_prime(29) == 29
assert nea... | [
{
"docstring": "Check if the given number is a prime number.",
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": "Find the largest prime number less than or equal to n.",
"function_declaration": "def nearest_prime(n):",... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(num):\n \"\"\"\n Check if the given number is a prime number.\n \"\"\"\n if num <= 1:\n return False\n if num == 2:\n ... | trial_gpt4o_0 | {
"original_instruction": "The Chief Librarian at the Grand Library loves numbers and books. She is particularly interested in prime numbers. While cataloging books, she noticed that some books have prime numbers as their identification numbers and others do not. To make the cataloging process more interesting, she d... | 0.778872 | Code_Contests_6285 | C | [
"is_prime",
"nearest_prime"
] | 2 | [
[
"nearest_prime",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | 97725889fa5f1468d36ae4d8fdc6aea888545e0a | 3a8a30b7c3405b06d6295854ba9dbe07e591736d | |||
v1.0 | complete | Code_Contests | Code_Contests_5984_C | from typing import List, Tuple
def is_valid_arrangement(arrangement: List[int], preferences: List[Tuple[int, int, str]], A: int) -> bool:
""" Check if a given seating arrangement is valid based on preferences and acquaintance threshold.
Args:
arrangement (List[int]): The seating arrangement given as a ... | from itertools import permutations
def is_valid_arrangement(arrangement, preferences, A):
n = len(arrangement)
satisfaction_count = 0
for g1, g2, sign in preferences:
g1_index = arrangement.index(g1)
g2_index = arrangement.index(g2)
g1_next = arrangement[(g1_index + 1) % n]
... | import pytest
from solution import process_input, can_seat_guests, is_valid_arrangement
def test_is_valid_arrangement():
arrangement = [1, 2, 3, 4]
preferences = [(1, 2, '+'), (2, 3, '+'), (3, 4, '+'), (4, 1, '-')]
A = 3
assert is_valid_arrangement(arrangement, preferences, A) == True
arrangement ... | [
{
"docstring": null,
"function_declaration": "def is_valid_arrangement(arrangement, preferences, A):",
"function_name": "is_valid_arrangement",
"parameter_list": "(arrangement, preferences, A)"
},
{
"docstring": null,
"function_declaration": "def can_seat_guests(num_guests, preferences, ... | [
0,
0,
0,
0,
0,
1,
1,
1,
0,
0
] | 3 | hard | 0.3 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import itertools\n\ndef satisfies_preferences(arrangement, preferences, A):\n count = 0\n n = len(arrangement)\n for pref in preferences:\n ... | trial_gpt4o_5 | {
"original_instruction": "You are tasked with developing a seating arrangement algorithm for a circular dining table at a party. Each guest has a preference for who they would like to sit next to and who they do not want to sit next to. Given these preferences, your algorithm should determine if it's possible to arr... | 0.561508 | Code_Contests_5984 | C | [
"is_valid_arrangement",
"can_seat_guests",
"process_input"
] | 3 | [
[
"can_seat_guests",
"is_valid_arrangement"
],
[
"process_input",
"can_seat_guests"
]
] | 2 | [
"process_input"
] | false | [] | false | pytest | true | [] | true | 1505eadfc4f5eeccd504b761e412605409a58395 | d4ed231120f4fbe0686321f51824316b17d0088f | |||
v1.0 | complete | Code_Contests | Code_Contests_6320_C | def g(array):
"""
Calculate the minimum number of operations (reversals) needed to sort array in non-descending order.
>>> g([1, 2, 3]) == 0
>>> g([3, 2, 1]) == 1
>>> g([3, 1, 2]) == 2
>>> g([7, 1, 5]) == 2
>>> g([4, 3, 2, 1]) == 1
>>> g([10]) == 0
>>> g([2, 3, 1, 5, 4]) == 2
"""... | def g(array):
"""
Calculate the minimum number of operations (reversals) needed to sort array in non-descending order.
"""
if array == sorted(array):
return 0
n = len(array)
# Check if reversing the whole array sorts it
if array == sorted(array, reverse=True):
return 1
... | from solution import sum_of_min_operations, g
def test_g():
assert g([1, 2, 3]) == 0
assert g([3, 2, 1]) == 1
assert g([3, 1, 2]) == 2
assert g([7, 1, 5]) == 2
assert g([4, 3, 2, 1]) == 1
assert g([10]) == 0
assert g([2, 3, 1, 5, 4]) == 2
def test_sum_of_min_operations():
assert sum_of... | [
{
"docstring": "Calculate the minimum number of operations (reversals) needed to sort array in non-descending order.",
"function_declaration": "def g(array):",
"function_name": "g",
"parameter_list": "(array)"
},
{
"docstring": "Calculate the sum of g(a) for m arrays.",
"function_declara... | [
0,
0,
0,
0,
0,
0,
0,
1,
0,
0
] | 1 | hard | 0.1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def count_min_operations(arr):\n \"\"\"\n Returns the minimum number of operations required to sort the array in non-descending order.\n \"\"\"\n ... | trial_gpt4o_7 | {
"original_instruction": "You are given an array of integers. You can perform the following operation any number of times: choose any contiguous subarray of the array, and reverse the order of the elements in it. Let g(a) be the minimum number of operations required to sort the array in non-descending order.\n\nFor ... | 0.686037 | Code_Contests_6320 | C | [
"g",
"sum_of_min_operations"
] | 2 | [
[
"sum_of_min_operations",
"g"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | b5edd70372b02ad79ea1ade9fdf4fd7379b1f29e | 3d2b93e145848d565a74b293f75a4b5e9690fcf8 | |||
v1.0 | complete | Code_Contests | Code_Contests_6452_C | def is_prime(num: int) -> bool:
""" Helper function to determine if a number is prime.
"""
pass
def has_prime_twins(n: int) -> str:
""" Marta has recently learned about the concept of prime numbers and is fascinated by them. Now, she wants to find out more about prime twins, a pair of prime numbers tha... | import math
def is_prime(num):
if num <= 1:
return False
if num <= 3:
return True
if num % 2 == 0 or num % 3 == 0:
return False
i = 5
while i * i <= num:
if num % i == 0 or num % (i + 2) == 0:
return False
i += 6
return True
def has_prime_twi... | from solution import has_prime_twins
def test_example_case_1():
assert has_prime_twins(10) == "YES"
def test_example_case_2():
assert has_prime_twins(14) == "YES"
def test_example_case_3():
assert has_prime_twins(2) == "NO"
def test_example_case_4():
assert has_prime_twins(17) == "YES"
def test_pri... | [
{
"docstring": null,
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": null,
"function_declaration": "def has_prime_twins(n):",
"function_name": "has_prime_twins",
"parameter_list": "(n)"
}
] | [
1,
1
] | 2 | easy | 1 | {
"trial_gpt4o_0": null,
"trial_gpt4o_1": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared1_results_combined.jsonl",
"solution_code": "import math\n\ndef is_prime(num):\n if num <= 1:\n return False\n if num <= 3:\n return True\n if num % 2 =... | trial_gpt4o_1 | {
"original_instruction": "Marta has recently learned about the concept of prime numbers and is fascinated by them. Now, she wants to find out more about prime twins, a pair of prime numbers that differ by exactly 2 (for instance, 3 and 5, 11 and 13).\n\nGiven an integer n, help Marta determine if there is at least o... | 0.700518 | Code_Contests_6452 | C | [
"is_prime",
"has_prime_twins"
] | 2 | [
[
"has_prime_twins",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 001a659118b6bcb06b9f5e665c038929f88e7408 | 04a6c5ff5f12c325a329b430115a88411cbb8127 | |||
v1.0 | complete | Code_Contests | Code_Contests_6481_C | def can_be_x_ranked(n: int, arr: List[int]) -> str:
""" Determine if an array can be transformed into an x-ranked array.
Returns the x-ranked array if possible, otherwise "Impossible".
>>> can_be_x_ranked(5, [5, 3, 1, 4, 2]) "5 1 4 2 3"
>>> can_be_x_ranked(4, [4, 2, 3, 1]) "4 1 3 2"
>>> can_be_... | def x_rank(arr):
"""
This function takes a list of integers and returns an x-ranked list or "Impossible"
if the list cannot be transformed into an x-ranked list.
"""
n = len(arr)
# Sort the array to pick max and min easily
arr_sorted = sorted(arr)
# Create list to hold x-ranked ele... | from solution import can_be_x_ranked
def test_example1():
assert can_be_x_ranked(5, [5, 3, 1, 4, 2]) == "5 1 4 2 3"
def test_example2():
assert can_be_x_ranked(4, [4, 2, 3, 1]) == "4 1 3 2"
def test_single_element():
assert can_be_x_ranked(1, [7]) == "7"
def test_two_elements():
assert can_be_x_rank... | [
{
"docstring": "This function takes a list of integers and returns an x-ranked list or \"Impossible\" \nif the list cannot be transformed into an x-ranked list.",
"function_declaration": "def x_rank(arr):",
"function_name": "x_rank",
"parameter_list": "(arr)"
},
{
"docstring": "Returns the x... | [
1,
1,
0
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def x_rank(n, a):\n \"\"\"\n Determines if an array can be transformed into an x-ranked array.\n \n Parameters:\n n (int): The number of... | trial_gpt4o_1 | {
"original_instruction": "A company has developed a unique ranking system called x-rank. An array with n elements is considered x-ranked if the following conditions are met:\n\n1. For every even index i (0-based), the element should be the maximum of the remaining elements after previous selections.\n2. For every od... | 0.626332 | Code_Contests_6481 | C | [
"x_rank",
"can_be_x_ranked"
] | 2 | [
[
"can_be_x_ranked",
"x_rank"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 0df878067af04fb225fb7b99c2ee80318e13d98c | 7b93fdf9173b0f23db9db77c4d7cfd3d10f22d8c | |||
v1.0 | complete | Code_Contests | Code_Contests_6406_C | from typing import List, Tuple
def shortest_path_with_reduction(n: int, m: int, edges: List[Tuple[int, int, int]]) -> int:
"""
You are given an undirected graph with n vertices and m edges. Each edge has a non-negative weight.
The goal is to find the shortest path from vertex 1 to vertex n. However, due to... | import heapq
def dijkstra_reduce_edges(graph, n):
def dijkstra(source):
dist = [float('inf')] * (n + 1)
dist[source] = 0
pq = [(0, source)]
while pq:
current_dist, u = heapq.heappop(pq)
if current_dist > dist[u]:
continue... | from solution import shortest_path_with_reduction
def test_shortest_path_example_1():
n, m = 4, 4
edges = [(1, 2, 2), (2, 3, 2), (3, 4, 2), (1, 4, 4)]
assert shortest_path_with_reduction(n, m, edges) == 3
def test_shortest_path_example_2():
n, m = 4, 4
edges = [(1, 2, 1), (2, 3, 1), (3, 4, 1), (1,... | [
{
"docstring": null,
"function_declaration": "def dijkstra_reduce_edges(graph, n):",
"function_name": "dijkstra_reduce_edges",
"parameter_list": "(graph, n)"
},
{
"docstring": null,
"function_declaration": "def shortest_path_with_reduction(n, m, edges):",
"function_name": "shortest_p... | [
0,
0,
0,
0,
0,
1,
0,
0,
0,
0
] | 1 | hard | 0.1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import heapq\n\ndef dijkstra(graph, n, start):\n distances = [float('inf')] * (n + 1)\n distances[start] = 0\n pq = [(0, start)]\n while pq:\n ... | trial_gpt4o_5 | {
"original_instruction": "You are given an undirected graph with n vertices and m edges. Each edge has a non-negative weight. The goal is to find the shortest path from vertex 1 to vertex n. However, due to some constraints, you can reduce the weight of each edge by at most 1 unit. \n\nGiven the graph, compute the l... | 0.763251 | Code_Contests_6406 | C | [
"dijkstra_reduce_edges",
"shortest_path_with_reduction"
] | 2 | [
[
"shortest_path_with_reduction",
"dijkstra_reduce_edges"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | b5cfefbdf40ace4a35d45e73ae133bdde4bcfd24 | d0e0c5573d4943687973911bc4cd5bd0f8aa55b6 | |||
v1.0 | complete | Code_Contests | Code_Contests_6282_C | from typing import Tuple
def run_length_encode(s: str) -> str:
"""Encode the input string s using run-length encoding.
>>> run_length_encode("aaabbbcccaaa") == "a3b3c3a3"
>>> run_length_encode("abcd") == "a1b1c1d1"
"""
pass
def run_length_decode(encoded: str) -> str:
"""Decode the run-length e... | def run_length_encode(s):
"""
Encode the input string s using run-length encoding.
"""
encoded = ""
i = 0
while i < len(s):
count = 1
while i + 1 < len(s) and s[i] == s[i + 1]:
i += 1
count += 1
encoded += s[i] + str(count)
i += 1
retur... | from solution import run_length_encode, run_length_decode, encode_and_decode
def test_run_length_encode():
assert run_length_encode("aaabbbcccaaa") == "a3b3c3a3"
assert run_length_encode("abcd") == "a1b1c1d1"
assert run_length_encode("aaaa") == "a4"
assert run_length_encode("abcdddcba") == "a1b1c1d3c1b... | [
{
"docstring": "Encode the input string s using run-length encoding.",
"function_declaration": "def run_length_encode(s):",
"function_name": "run_length_encode",
"parameter_list": "(s)"
},
{
"docstring": "Decode the run-length encoded string.",
"function_declaration": "def run_length_dec... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def run_length_encode(s):\n \"\"\"\n Encodes the given string s using run-length encoding.\n \"\"\"\n if not s:\n return \"\"\n \n ... | trial_gpt4o_1 | {
"original_instruction": "Given a string $s$ consisting of lowercase English letters, encode it using run-length encoding (RLE). Then, decode the encoded string back to the original string and print both the encoded and decoded strings.\n\nRun-length encoding is a simple form of data compression where sequences of t... | 0.637679 | Code_Contests_6282 | C | [
"run_length_encode",
"run_length_decode",
"encode_and_decode"
] | 3 | [
[
"encode_and_decode",
"run_length_decode"
],
[
"encode_and_decode",
"run_length_encode"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 241f5d246a2e04e0bc26c7cea52c4d2709e9d0ce | cc8e75b5b4e756969bef5957f7d2d69532dd331d | |||
v1.0 | complete | Code_Contests | Code_Contests_6491_C | def assess_lanterns(input_string: str) -> List[str]:
"""
This function assesses whether each lantern will stay afloat or sink based on their weight limits and the weights of items placed in them.
Parameters:
input_string (str): Input string containing datasets. Each dataset consists of the number of la... | def check_lanterns(datasets):
"""
This function determines whether each lantern will float or sink.
Parameters:
datasets (list of list): Each list is a dataset that contains integers representing
the weight limit, number of items, and weights of the items
... | from solution import assess_lanterns
def test_single_lantern_sink():
input_data = "1\n100 3 30 40 40\n0\n"
result = assess_lanterns(input_data)
assert result == ["SINK"]
def test_single_lantern_float():
input_data = "1\n100 3 30 40 20\n0\n"
result = assess_lanterns(input_data)
assert result ==... | [
{
"docstring": "This function determines whether each lantern will float or sink.\n\nParameters:\ndatasets (list of list): Each list is a dataset that contains integers representing \n the weight limit, number of items, and weights of the items \n for each lantern... | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def lantern_status(data):\n results = []\n\n i = 0\n while i < len(data):\n n = data[i]\n if n == 0:\n break\n i +... | trial_gpt4o_1 | {
"original_instruction": "In the secluded village of Omijima, there is a unique tradition where villagers celebrate festivals by lighting lanterns and sending them down the river. Each lantern can hold a specific range of weights, and if overloaded, the lantern will sink, causing disappointment among villagers.\n\nE... | 0.574575 | Code_Contests_6491 | C | [
"check_lanterns",
"process_input",
"assess_lanterns"
] | 3 | [
[
"assess_lanterns",
"check_lanterns"
],
[
"assess_lanterns",
"process_input"
]
] | 2 | [
"process_input"
] | false | [] | false | pytest | true | [] | true | fcc429532b5f79b202aa70e67459b1449e12e5f6 | a9cd41a907426645d4c10abfc82539eaddbb8cf5 | |||
v1.0 | complete | Code_Contests | Code_Contests_5851_C | def preprocess_log(n):
log = [0] * (n + 1)
for i in range(2, n + 1):
log[i] = log[i // 2] + 1
return log
def preprocess_table(arr, n):
log = preprocess_log(n)
k = log[n] + 1
st = [[0] * k for _ in range(n)]
for i in range(n):
st[i][0] = arr[i]
j = 1
while (1 <<... | def preprocess_log(n):
log = [0] * (n + 1)
for i in range(2, n + 1):
log[i] = log[i // 2] + 1
return log
def preprocess_table(arr, n):
log = preprocess_log(n)
k = log[n] + 1
st = [[0] * k for _ in range(n)]
for i in range(n):
st[i][0] = arr[i]
j = 1
while (1 <<... | from solution import main
def test_example_case():
assert main('5 4\n3 1 4 1 5\n1 1 3\n2 2 6\n1 1 3\n2 5 2\n') == '4\n6'
def test_single_element_array():
assert main('1 1\n5\n1 1 1\n') == '5'
def test_update_only():
assert main('3 2\n1 2 3\n2 1 10\n2 2 20\n') == ''
def test_maximum_only():
assert ma... | [
{
"docstring": null,
"function_declaration": "def preprocess_log(n):",
"function_name": "preprocess_log",
"parameter_list": "(n)"
},
{
"docstring": null,
"function_declaration": "def preprocess_table(arr, n):",
"function_name": "preprocess_table",
"parameter_list": "(arr, n)"
}... | [
0,
1,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "class SegmentTree:\n def __init__(self, data):\n self.n = len(data)\n self.tree = [0] * (2 * self.n)\n self.build(data)\n\n def ... | trial_gpt4o_2 | {
"original_instruction": "Given an array of integers, you are tasked with handling two types of queries:\n\n 1. MAX l r — find the maximum value in the subarray from index l to r (inclusive).\n 2. UPDATE x y — update the element at index x to y.\n\nAfter performing the specified queries, produce the results for ea... | 0.615453 | Code_Contests_5851 | C | [
"preprocess_log",
"preprocess_table",
"range_max_query",
"process_queries",
"main"
] | 5 | [
[
"preprocess_table",
"preprocess_log"
],
[
"process_queries",
"preprocess_table"
],
[
"process_queries",
"range_max_query"
]
] | 3 | [
"process_queries"
] | false | [] | false | pytest | true | [] | true | 85c1b32d44d3d57abb8c0a632ff0cbf92d1b533c | e344c4323309a2e45693055a921c6f090bd513f3 | |||
v1.0 | complete | Code_Contests | Code_Contests_6634_C | def solve_bridge_networks(test_cases):
""" Determine the minimum cost to construct the network of bridges that connects all the islands.
Each test case consists of the number of islands, the number of possible bridges, and for each bridge,
u (island 1), v (island 2) and w (cost).
>>> test_cases = ... | def find(parent, i):
if parent[i] == i:
return i
return find(parent, parent[i])
def union(parent, rank, x, y):
root_x = find(parent, x)
root_y = find(parent, y)
if rank[root_x] < rank[root_y]:
parent[root_x] = root_y
elif rank[root_x] > rank[root_y]:
parent[root_y] ... | import pytest
from solution import solve_bridge_networks
def test_case_1():
test_cases = [(4, 6, [(1, 2, 1), (1, 3, 4), (2, 3, 2), (2, 4, 3), (3, 4, 5), (1, 4, 4)])]
results = solve_bridge_networks(test_cases)
assert results == [6]
def test_case_2():
test_cases = [(3, 3, [(1, 2, 5), (2, 3, 6), (1, 3, ... | [
{
"docstring": null,
"function_declaration": "def find(parent, i):",
"function_name": "find",
"parameter_list": "(parent, i)"
},
{
"docstring": null,
"function_declaration": "def union(parent, rank, x, y):",
"function_name": "union",
"parameter_list": "(parent, rank, x, y)"
},
... | [
1,
1,
0
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "class UnionFind:\n def __init__(self, size):\n self.parent = list(range(size))\n self.rank = [0] * size\n\n def find(self, u):\n ... | trial_gpt4o_1 | {
"original_instruction": "Flora is working on a construction project where she needs to build a network of bridges between several islands. Each island is represented as a node, and a bridge is represented as an edge between two nodes. However, the project has certain constraints and requirements:\n\n1. Each island ... | 0.735318 | Code_Contests_6634 | C | [
"find",
"union",
"minimum_cost_to_connect_islands",
"solve_bridge_networks"
] | 4 | [
[
"minimum_cost_to_connect_islands",
"find"
],
[
"minimum_cost_to_connect_islands",
"union"
],
[
"solve_bridge_networks",
"minimum_cost_to_connect_islands"
],
[
"union",
"find"
]
] | 4 | [] | false | [] | false | pytest | true | [] | true | afa91d67845b08e687346056bb7730db74659c3d | 0b382615254f4116837dcfd7a238d4bd6fd06539 | |||
v1.0 | complete | Code_Contests | Code_Contests_6869_C | import itertools
def is_prime(num):
"""
Check if a number is prime.
>>> is_prime(2)
True
>>> is_prime(4)
False
"""
pass
def has_prime_pair_sum_permutation(nums):
"""
Check if there exists a permutation of nums such that the sum of
every consecutive pair is prime.
>>> h... | import itertools
def is_prime(num):
"""
Check if a number is prime.
"""
if num <= 1:
return False
if num == 2:
return True
if num % 2 == 0:
return False
for i in range(3, int(num**0.5) + 1, 2):
if num % i == 0:
return False
return True
def ha... | from solution import is_prime, has_prime_pair_sum_permutation, permutation_sum_checker
def test_is_prime():
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(4) == False
assert is_prime(17) == True
assert is_prime(18) == False
def test_has_prime_pair_sum_permutation():
asse... | [
{
"docstring": "Check if a number is prime.",
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": "Check if there exists a permutation of nums such that the sum of \nevery consecutive pair is prime.",
"function_declaratio... | [
0,
0,
0,
1,
1
] | 2 | medium | 0.4 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from itertools import permutations\n\ndef is_prime(n):\n \"\"\"\n Checks if a number is prime.\n \"\"\"\n if n <= 1:\n return False\n ... | trial_gpt4o_3 | {
"original_instruction": "Permutation Sum Checker\n\nYou are asked to determine if there exists a permutation of an integer array `nums` such that the sum of every consecutive pair of integers in the permutation is prime.\n\nA prime number is a natural number greater than 1 that is not a product of two smaller natur... | 0.629195 | Code_Contests_6869 | C | [
"is_prime",
"has_prime_pair_sum_permutation",
"permutation_sum_checker"
] | 3 | [
[
"has_prime_pair_sum_permutation",
"is_prime"
],
[
"permutation_sum_checker",
"has_prime_pair_sum_permutation"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | f68e3f14145ad18b6113f587e6a22b07d5a62481 | 2a7028ca5fe47432f9393ae0d09a66d37a4a678f | |||
v1.0 | complete | Code_Contests | Code_Contests_6854_C | def max_energy_points(n: int, m: int, grid: List[List[int]]) -> int:
"""
Returns the maximum number of magical energy points that can be collected from top-left to bottom-right.
:param n: Number of rows in the grid
:param m: Number of columns in the grid
:param grid: 2D list representing the gr... | def max_energy_points(n, m, grid):
"""
Returns the maximum number of magical energy points that can be collected from top-left to bottom-right.
:param n: Number of rows in the grid
:param m: Number of columns in the grid
:param grid: 2D list representing the grid with magical energy points
... | from solution import max_energy_points
def test_max_energy_points_example():
n = 3
m = 3
grid = [
[1, 3, 1],
[1, 5, 1],
[4, 2, 1]
]
assert max_energy_points(n, m, grid) == 12
def test_max_energy_points_single_cell():
n = 1
m = 1
grid = [
[5]
]
as... | [
{
"docstring": "Returns the maximum number of magical energy points that can be collected from top-left to bottom-right.\n\n:param n: Number of rows in the grid\n:param m: Number of columns in the grid\n:param grid: 2D list representing the grid with magical energy points\n:return: Maximum number of energy poin... | [
0,
0,
0,
0,
1
] | 1 | hard | 0.2 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def max_energy_points(n, m, grid):\n \"\"\"\n Calculates the maximum number of magical energy points you can collect\n by starting from the top-le... | trial_gpt4o_4 | {
"original_instruction": "A magical forest is represented by a grid with n rows and m columns. Each cell in the grid contains a certain number of magical energy points, which are represented by positive integers. Your task is to collect as many energy points as possible by starting from the top-left cell (1, 1), and... | 0.653474 | Code_Contests_6854 | C | [
"max_energy_points",
"run_max_energy_points"
] | 2 | [
[
"run_max_energy_points",
"max_energy_points"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | c05e7d02a67e790d8fea712256cfa08eda106135 | 508ed75492b3340729a301784b799b0b2b339ba2 | |||
v1.0 | complete | Code_Contests | Code_Contests_6739_C | from typing import List, Tuple
def is_prime(num: int) -> bool:
"""
Checks if the given number is a prime number.
>>> is_prime(2)
True
>>> is_prime(3)
True
>>> is_prime(4)
False
>>> is_prime(5)
True
"""
pass
def can_choose_prime_subsequence(sequence: List[int]) -> bool:
... | def is_prime(num):
"""
Checks if the given number is a prime number.
"""
if num <= 1:
return False
if num <= 3:
return True
if num % 2 == 0 or num % 3 == 0:
return False
i = 5
while i * i <= num:
if num % i == 0 or num % (i + 2) == 0:
return Fa... | import pytest
from solution import main, is_prime, can_choose_prime_subsequence, game_winner
def test_is_prime():
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(4) == False
assert is_prime(5) == True
def test_can_choose_prime_subsequence():
assert can_choose_prime_subsequenc... | [
{
"docstring": "Checks if the given number is a prime number.",
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": "Determines if there's any non-empty subsequence with a prime sum.",
"function_declaration": "def can_cho... | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(num):\n \"\"\" Helper function to check if a number is prime \"\"\"\n if num <= 1:\n return False\n if num <= 3:\n retu... | trial_gpt4o_1 | {
"original_instruction": "Bob and Alice are playing a game with a sequence of numbers. The game consists of n integers arranged in a sequence. Bob and Alice take turns, with Bob going first. In each turn, the player must choose a non-empty subsequence of consecutive numbers from the sequence such that the sum of the... | 0.668792 | Code_Contests_6739 | C | [
"is_prime",
"can_choose_prime_subsequence",
"game_winner",
"main"
] | 4 | [
[
"can_choose_prime_subsequence",
"is_prime"
],
[
"game_winner",
"can_choose_prime_subsequence"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 84899874652428021d33fa21e74dea8f3103f21b | 3e6b867b8273cb3e19a721008ff424c9c76bdd19 | |||
v1.0 | complete | Code_Contests | Code_Contests_7089_C | def are_balanceable(A: List[int], B: List[int]) -> str:
"""
Determines if arrays A and B are balanceable.
>>> are_balanceable([1, 2, 3, 4], [4, 1, 2, 3]) == "YES"
>>> are_balanceable([1, 2, 3], [6, 0, 1]) == "NO"
"""
def prefix_sums_of_size(arr: List[int], target: int) -> bool:
"""
Retu... | def are_balanceable(A, B):
"""
Determines if arrays A and B are balanceable.
"""
total_A = sum(A)
total_B = sum(B)
if total_A == total_B:
return "YES"
difference = total_A - total_B
if abs(difference) % 2 != 0:
return "NO"
target = abs(difference) ... | from solution import are_balanceable
def test_example_1():
assert are_balanceable([1, 2, 3, 4], [4, 1, 2, 3]) == "YES"
def test_example_2():
assert are_balanceable([1, 2, 3], [6, 0, 1]) == "NO"
def test_same_sum():
assert are_balanceable([1, 2, 3], [1, 2, 3]) == "YES"
def test_no_balance_possible():
... | [
{
"docstring": "Determines if arrays A and B are balanceable.",
"function_declaration": "def are_balanceable(A, B):",
"function_name": "are_balanceable",
"parameter_list": "(A, B)"
},
{
"docstring": "Returns whether there exists a prefix sum equal to target.",
"function_declaration": "de... | [
0,
0,
0,
0,
0,
0,
0,
1,
0,
0
] | 1 | hard | 0.1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def are_arrays_balanceable(n, A, B):\n sum_A = sum(A)\n sum_B = sum(B)\n \n # Find the difference in sums\n difference = abs(sum_A - sum_B)\... | trial_gpt4o_7 | {
"original_instruction": "Imagine you are given two arrays of integers, `A` and `B`, both of length `n`. We call these arrays **balanceable** if it is possible to select some non-empty subarray from `A` and move it to any position in `B` (including the start or end) such that after this operation, the sum of the ele... | 0.618381 | Code_Contests_7089 | C | [
"are_balanceable",
"prefix_sums_of_size"
] | 2 | [
[
"are_balanceable",
"prefix_sums_of_size"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 95fc95d4ee936fff6562ffef9ef234ff7c8dfe6b | ef3d4e53a5bfc37f260d3cc2e0b1164d46a16c1c | |||
v1.0 | complete | Code_Contests | Code_Contests_6793_C | def min_steps_to_make_beautiful(n: int, array: List[int]) -> int:
"""Find the minimum number of steps required to make the array beautiful.
An array is considered beautiful if it satisfies this property: in at least one position `i` (1 ≤ i ≤ n), the number of elements before position `i` only contains elem... | def min_steps_to_make_beautiful(n, array):
# To find minimum number of moves the idea is to find the length of the longest increasing subsequence
# Since this subsequence already meets the criteria of being beautiful after sorting.
if n <= 1:
return 0
# Calculate Longest Increasing Sub... | from solution import min_steps_to_make_beautiful
def test_min_steps_example1():
assert min_steps_to_make_beautiful(6, [1, 5, 3, 4, 2, 6]) == 2
def test_min_steps_example2():
assert min_steps_to_make_beautiful(4, [2, 3, 1, 4]) == 1
def test_min_steps_no_moves_needed():
assert min_steps_to_make_beautiful(4... | [
{
"docstring": null,
"function_declaration": "def min_steps_to_make_beautiful(n, array):",
"function_name": "min_steps_to_make_beautiful",
"parameter_list": "(n, array)"
},
{
"docstring": null,
"function_declaration": "def binary_search(lis, num):",
"function_name": "binary_search",
... | [
0,
0,
0,
1,
0
] | 1 | hard | 0.2 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def find_min_steps_to_beautiful(n, array):\n \"\"\"\n This function finds the minimum number of steps required to make the array beautiful.\n \"\"... | trial_gpt4o_3 | {
"original_instruction": "You are given a positive integer `n` and an array of `n` integers. Your task is to find the minimum number of steps required to make the array \"beautiful\". An array is considered beautiful if it satisfies this property: in at least one position `i` (1 ≤ i ≤ n), the number of elements befo... | 0.652458 | Code_Contests_6793 | C | [
"min_steps_to_make_beautiful",
"binary_search"
] | 2 | [
[
"min_steps_to_make_beautiful",
"binary_search"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | b63ef36cde14fa7e1d593bd93bade080c3ef6af0 | d071c81a2693816fafeca624c187f5d7467a500c | |||
v1.0 | complete | Code_Contests | Code_Contests_6729_C | def max_profit_scheduler(n: int, task_input: List[str]) -> int:
""" You are given a sequence of tasks that must be scheduled on a single machine. Each task has a start time, end time, and a profit associated with it. You need to find the maximum profit that can be obtained by scheduling a subset of non-overlapping ... | from bisect import bisect_right
def max_profit(tasks):
"""
Args:
tasks (List[Tuple[int, int, int]]): List of tuples where each tuple contains (start, end, profit)
Returns:
int: Maximum profit obtainable by scheduling non-overlapping tasks.
"""
# Sort tasks by end time
tasks.sort(key=la... | from solution import max_profit_scheduler
def test_example():
assert max_profit_scheduler(4, ["1 3 500", "3 5 300", "0 6 600", "4 7 200"]) == 800
def test_non_overlapping_tasks():
assert max_profit_scheduler(3, ["1 2 100", "3 4 200", "5 6 300"]) == 600
def test_overlapping_tasks():
assert max_profit_sche... | [
{
"docstring": "Args:\ntasks (List[Tuple[int, int, int]]): List of tuples where each tuple contains (start, end, profit)\n\nReturns:\nint: Maximum profit obtainable by scheduling non-overlapping tasks.",
"function_declaration": "def max_profit(tasks):",
"function_name": "max_profit",
"parameter_list... | [
0,
0,
0,
0,
0,
1,
0,
0,
1,
0
] | 2 | hard | 0.2 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def max_profit(tasks):\n from bisect import bisect_right\n\n # Sort tasks by their end time\n tasks.sort(key=lambda x: x[1])\n\n # End times to... | trial_gpt4o_8 | {
"original_instruction": "You are given a sequence of tasks that must be scheduled on a single machine. Each task has a start time, end time, and a profit associated with it. You need to find the maximum profit that can be obtained by scheduling a subset of non-overlapping tasks.\n\nA task can only be executed if no... | 0.604576 | Code_Contests_6729 | C | [
"max_profit",
"max_profit_scheduler"
] | 2 | [
[
"max_profit_scheduler",
"max_profit"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | e74051343289767ce4da2aa73c172e006082e60e | 42ced0bee294a518adf63b78ca6ee6598f85e346 | |||
v1.0 | complete | Code_Contests | Code_Contests_6159_C | from typing import List, Tuple
def preprocess_chessboard(chessboard: List[List[int]]) -> List[List[int]]:
""" Preprocesses the chessboard to create a prefix sum matrix.
Args:
chessboard: List of List of integers representing the values in the cells of the chessboard.
Returns:
A 2D list wh... | def preprocess_chessboard(chessboard):
N = len(chessboard)
prefix_sum = [[0] * (N + 1) for _ in range(N + 1)]
for i in range(1, N + 1):
for j in range(1, N + 1):
prefix_sum[i][j] = (chessboard[i - 1][j - 1] +
prefix_sum[i - 1][j] +
... | from solution import solve_chessboard_queries, preprocess_chessboard, query_sum
def test_preprocess_chessboard():
chessboard = [
[1, 2, 3, 4],
[5, 6, 7, 8],
[9, 10, 11, 12],
[13, 14, 15, 16]
]
expected_prefix_sum = [
[0, 0, 0, 0, 0],
[0, 1, 3, 6, 10],
... | [
{
"docstring": null,
"function_declaration": "def preprocess_chessboard(chessboard):",
"function_name": "preprocess_chessboard",
"parameter_list": "(chessboard)"
},
{
"docstring": null,
"function_declaration": "def query_sum(prefix_sum, x1, y1, x2, y2):",
"function_name": "query_sum"... | [
0,
1,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def preprocess_chessboard(N, chessboard):\n # Create a prefix sum matrix\n prefix_sum = [[0] * (N + 1) for _ in range(N + 1)]\n \n for i in ran... | trial_gpt4o_2 | {
"original_instruction": "In an alternate universe, a king has a special type of chessboard of size N x N. Each cell of the chessboard can either be empty or contain a treasure with a certain value. The king is interested in knowing the sum of treasures in any given sub-board of the chessboard. You are tasked with w... | 0.674474 | Code_Contests_6159 | C | [
"preprocess_chessboard",
"query_sum",
"solve_chessboard_queries"
] | 3 | [
[
"solve_chessboard_queries",
"preprocess_chessboard"
],
[
"solve_chessboard_queries",
"query_sum"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 3494adc803cc81a64eeb8123e6d6b605a1e73abf | e9be87fef195afc58ddc2c89f04eb404f3cabdeb | |||
v1.0 | complete | Code_Contests | Code_Contests_7402_C | def steps_to_palindrome(n: int) -> (int, int):
"""
Given a starting number n, returns the number of steps required to reach a palindrome and the resulting palindrome.
>>> steps_to_palindrome(28)
(2, 121)
>>> steps_to_palindrome(89)
(24, 8813200023188)
>>> steps_to_palindrome(123)
(1, 44... | def reverse_number(n):
"""
Reverses the digits of an integer.
"""
return int(str(n)[::-1])
def is_palindrome(n):
"""
Checks whether an integer is a palindrome.
"""
return str(n) == str(n)[::-1]
def steps_to_palindrome(n):
"""
Returns the number of steps required to reach a pali... | from solution import steps_to_palindrome
def test_example_1():
assert steps_to_palindrome(28) == (2, 121)
def test_example_2():
assert steps_to_palindrome(89) == (24, 8813200023188)
def test_example_3():
assert steps_to_palindrome(123) == (1, 444)
def test_single_digit_numbers():
for i in range(10):... | [
{
"docstring": "Reverses the digits of an integer.",
"function_declaration": "def reverse_number(n):",
"function_name": "reverse_number",
"parameter_list": "(n)"
},
{
"docstring": "Checks whether an integer is a palindrome.",
"function_declaration": "def is_palindrome(n):",
"function... | [
1,
0,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def reverse_number(n):\n \"\"\"\n Reverses the digits of an integer.\n \"\"\"\n return int(str(n)[::-1])\n\ndef is_palindrome(n):\n \"\"\"\n... | trial_gpt4o_0 | {
"original_instruction": "In a parallel universe, there is a peculiar way of generating numbers. Starting from any given number n, the next number in the sequence is generated by reversing the digits of n and then adding it to the original number n. This process is repeated until a palindrome is produced.\n\nA palin... | 0.704322 | Code_Contests_7402 | C | [
"reverse_number",
"is_palindrome",
"steps_to_palindrome"
] | 3 | [
[
"steps_to_palindrome",
"is_palindrome"
],
[
"steps_to_palindrome",
"reverse_number"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | f10b7e9abb6b8750a46422b6d60a9b73d99f5a50 | 648dcfbf84629d16cfb715c03a436edff359d84f | |||
v1.0 | complete | Code_Contests | Code_Contests_7050_C | from typing import List, Tuple
def query_tree(n: int, q: int, values: List[int], edges: List[Tuple[int, int]], queries: List[Tuple[int, int]]) -> List[int]:
""" Perform q queries on a tree with n nodes to find the maximum/minimum value in the subtree of a given node.
Args:
n (int): Number of nodes... | from collections import defaultdict
def dfs(node, parent, values, adj, max_value, min_value):
curr_max = values[node - 1]
curr_min = values[node - 1]
for neighbor in adj[node]:
if neighbor == parent:
continue
max_sub, min_sub = dfs(neighbor, node, values, adj, max_value, min_val... | from solution import query_tree
def test_example_1():
n = 5
q = 3
values = [1, 2, 3, 4, 5]
edges = [(1, 2), (1, 3), (1, 4), (1, 5)]
queries = [(1, 1), (2, 2), (1, 3)]
result = query_tree(n, q, values, edges, queries)
expected = [5, 2, 3]
assert result == expected
def test_example_2():
... | [
{
"docstring": null,
"function_declaration": "def dfs(node, parent, values, adj, max_value, min_value):",
"function_name": "dfs",
"parameter_list": "(node, parent, values, adj, max_value, min_value)"
},
{
"docstring": null,
"function_declaration": "def query_tree(n, q, values, edges, que... | [
0,
0,
0,
1,
1
] | 2 | medium | 0.4 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from collections import defaultdict\nfrom sys import setrecursionlimit, stdin\nimport sys\nsys.setrecursionlimit(100010)\n\nclass TreeNode:\n def __init... | trial_gpt4o_4 | {
"original_instruction": "You are given a tree with n nodes, rooted at node 1. Each node has a value associated with it. We need to perform q operations on this tree. In each operation, you will be given a node, and you have to report the maximum value among all nodes in the subtree rooted at that node or the minimu... | 0.682527 | Code_Contests_7050 | C | [
"dfs",
"query_tree"
] | 2 | [
[
"query_tree",
"dfs"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 04c0dea727395ff279ab82ebc64715203e1f0878 | 23d5dc46083834a67b898e62a705bd985f10f9fd | |||
v1.0 | complete | Code_Contests | Code_Contests_7324_C | from typing import List, Tuple
def distinct_paths_to_employee(n: int, edges: List[Tuple[int, int]], target: int) -> int:
""" Find the number of distinct paths from the CEO to a given employee.
>>> distinct_paths_to_employee(7, [(1, 2), (1, 3), (2, 4), (2, 5), (3, 6), (3, 7)], 5) == 1
>>> distinct_paths_to_... | from typing import List, Tuple, Dict
from collections import defaultdict, deque
def build_tree(edges: List[Tuple[int, int]]) -> Dict[int, List[int]]:
tree = defaultdict(list)
for a, b in edges:
tree[a].append(b)
return tree
def distinct_paths_to_employee(n: int, edges: List[Tuple[int, int]], targe... | from solution import distinct_paths_to_employee
def test_single_path():
n = 7
edges = [(1, 2), (1, 3), (2, 4), (2, 5), (3, 6), (3, 7)]
target = 5
assert distinct_paths_to_employee(n, edges, target) == 1
def test_direct_supervision():
n = 4
edges = [(1, 2), (1, 3), (1, 4)]
target = 4
as... | [
{
"docstring": null,
"function_declaration": "def build_tree(edges):",
"function_name": "build_tree",
"parameter_list": "(edges)"
},
{
"docstring": null,
"function_declaration": "def distinct_paths_to_employee(n, edges, target):",
"function_name": "distinct_paths_to_employee",
"p... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from typing import List, Tuple\n\ndef distinct_paths_to_employee(n: int, edges: List[Tuple[int, int]], target: int) -> int:\n \"\"\"\n Given the numb... | trial_gpt4o_1 | {
"original_instruction": "A company runs a hierarchy of employees, where each employee except the CEO has one direct supervisor. They want to find out the number of distinct paths from the CEO to a given employee.\n\nThe company's hierarchy is represented as a tree rooted at the CEO (node 1). An employee is represen... | 0.633264 | Code_Contests_7324 | C | [
"build_tree",
"distinct_paths_to_employee"
] | 2 | [
[
"distinct_paths_to_employee",
"build_tree"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 28dfc257c693e521679814c53cb98f5d333aea49 | 71101bc7b23584c7e79d333023348485557bea30 | |||
v1.0 | complete | Code_Contests | Code_Contests_7350_C | def is_path_possible(N, M, edges, start, destination, sequence):
"""
Determines if there is a path from a starting node to a destination node passing through the specified sequence of intermediate nodes in order.
Args:
N (int): Number of nodes.
M (int): Number of edges.
edges (List[Tuple[in... | def create_graph(edges, N):
graph = {i: [] for i in range(1, N + 1)}
for u, v in edges:
graph[u].append(v)
graph[v].append(u)
return graph
def dfs(graph, current, target, visited, sequence=None, seq_index=0):
if seq_index < len(sequence) and current != sequence[seq_index]:
retur... | from solution import is_path_possible
def test_is_path_possible_case1():
N = 5
M = 5
edges = [(1, 2), (2, 3), (3, 4), (4, 5), (2, 4)]
start = 1
destination = 5
sequence = [2, 3, 4]
assert is_path_possible(N, M, edges, start, destination, sequence) == True
def test_is_path_possible_case2():... | [
{
"docstring": null,
"function_declaration": "def create_graph(edges, N):",
"function_name": "create_graph",
"parameter_list": "(edges, N)"
},
{
"docstring": null,
"function_declaration": "def dfs(graph, current, target, visited, sequence=None, seq_index=0):",
"function_name": "dfs",... | [
0,
0,
0,
0,
0,
0,
0,
1,
0
] | 1 | hard | 0.111 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def can_traverse_path(n, m, edges, start, destination, intermediates):\n from collections import defaultdict, deque\n \n def bfs_path_exists(graph... | trial_gpt4o_7 | {
"original_instruction": "A new coding question that matches the style, complexity, and scope of the provided question:\n\nA distribution network comprises several nodes connected by edges, representing the pathways goods can be transported from one node to another. Each node may have multiple edges connecting it to... | 0.626396 | Code_Contests_7350 | C | [
"create_graph",
"dfs",
"is_path_possible"
] | 3 | [
[
"is_path_possible",
"create_graph"
],
[
"is_path_possible",
"dfs"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 86e93f009c474f12c9672069aaa1e2acb1e8b91e | 9c2c8718fe7e48fa8d80ec7344cfbf2ce3555d8c | |||
v1.0 | complete | Code_Contests | Code_Contests_7425_C | from typing import List
def is_valid_word_chain(words: List[str]) -> bool:
""" Check if the given list of words forms a valid word chain.
>>> is_valid_word_chain(["cat", "tiger", "rabbit", "tarantula", "apple", "elephant", "toy", "yak", "kite", "echo", "owlet", "tuna", "alpaca"])
True
>>> is_valid_word... | def is_valid_word_chain(words):
if not words:
return False
for i in range(len(words) - 1):
if words[i][-1] != words[i + 1][0]:
return False
return True
def check_word_chain():
words = []
while True:
word = input().strip()
if word == "END":
... | from solution import is_valid_word_chain
def test_valid_chain():
assert is_valid_word_chain(["cat", "tiger", "rabbit", "tarantula", "apple", "elephant", "toy", "yak", "kite", "echo", "owlet", "tuna", "alpaca"]) == True
def test_invalid_chain_at_start():
assert is_valid_word_chain(["cat", "dog"]) == False
def... | [
{
"docstring": null,
"function_declaration": "def is_valid_word_chain(words):",
"function_name": "is_valid_word_chain",
"parameter_list": "(words)"
},
{
"docstring": null,
"function_declaration": "def check_word_chain():",
"function_name": "check_word_chain",
"parameter_list": "(... | [
0,
0,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_valid_word_chain(words):\n for i in range(len(words) - 1):\n if words[i][-1] != words[i+1][0]:\n return False\n return True\... | trial_gpt4o_2 | {
"original_instruction": "**Word Chain Validation**\n\nYou are given a list of words where each word is formed of lowercase letters (a-z). We define a word chain as a list of words [w1, w2, ..., wn] such that for each consecutive pair of words (wi, wi+1), the last letter of wi is the same as the first letter of wi+1... | 0.586306 | Code_Contests_7425 | C | [
"is_valid_word_chain",
"check_word_chain"
] | 2 | [
[
"check_word_chain",
"is_valid_word_chain"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 65bcb5a128b074702d9d219de3c0c34c8099200f | 8586f2dc8576383ded0f23c508758400207c68f0 | |||
v1.0 | complete | Code_Contests | Code_Contests_6982_C | def largest_box(dimensions):
"""
Given the dimensions of multiple cuboids, find the dimensions of the largest box that can fit within their union.
>>> largest_box([(0, 0, 4, 4, 5), (2, 2, 6, 6, 3), (4, 4, 8, 8, 2)])
(8.0000, 8.0000, 5.0000)
>>> largest_box([(0, 0, 3, 3, 7), (2, 2, 5, 5, 4)])
(5.... | def largest_box(dimensions):
"""
Given the dimensions of multiple cuboids, find the dimensions of the largest box that can fit within their union.
"""
# Initialize the boundaries for the union of cuboids
min_x, min_y, min_z = float('inf'), float('inf'), float('inf')
max_x, max_y, max_z = float('... | from solution import process
def test_sample_input():
input_str = """3
0 0 4 4 5
2 2 6 6 3
4 4 8 8 2
2
0 0 3 3 7
2 2 5 5 4
0"""
expected_output = """8.0000 8.0000 5.0000
5.0000 5.0000 7.0000"""
assert process(input_str) == expected_output
def test_single_cuboid():
input_str = """1
-3 -3 3 3 6
0"""
... | [
{
"docstring": "Given the dimensions of multiple cuboids, find the dimensions of the largest box that can fit within their union.",
"function_declaration": "def largest_box(dimensions):",
"function_name": "largest_box",
"parameter_list": "(dimensions)"
},
{
"docstring": "Parse the input stri... | [
0,
0,
0,
0,
0,
0,
1,
0
] | 1 | hard | 0.125 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def max_box_dimensions(datasets):\n results = []\n for cubes in datasets:\n if len(cubes) == 0:\n continue\n\n # Initialize ... | trial_gpt4o_7 | {
"original_instruction": "Problem Statement\n\nCubical Island is known for its unique formation: it consists of a series of cuboids, each with their lower corners on the $xy$-plane and their upper corners extending upwards along the $z$-axis. The cuboids' edges are parallel to the coordinate axes.\n\nThe Queen of Cu... | 0.653633 | Code_Contests_6982 | C | [
"largest_box",
"parse_input",
"format_output",
"process"
] | 4 | [
[
"process",
"format_output"
],
[
"process",
"largest_box"
],
[
"process",
"parse_input"
]
] | 3 | [
"parse_input",
"format_output"
] | false | [] | false | pytest | true | [] | true | 681c21022b97635ad7ea31b8ffa7cd2bdf78ae25 | a9dfa5d6cf987bd9ebb3cbcac066065d66238c77 | |||
v1.0 | complete | Code_Contests | Code_Contests_7342_C | def simulate_watering(n: int, m: int, field: List[List[int]], q: int, operations: List[Tuple[int, int, int, int, int]]) -> List[List[int]]:
""" Simulate the watering process on a field of crops and return the final heights of the plants.
Parameters:
n (int): Number of rows in the field.
m (int): Number... | def water_plants(field, operations):
n = len(field)
m = len(field[0])
for r1, c1, r2, c2, k in operations:
for i in range(r1, r2+1):
for j in range(c1, c2+1):
field[i][j] += k
return field
# Function to handle the complete flow
def simulate_watering(n, m, f... | def test_single_operation():
field = [
[1, 1],
[1, 1]
]
operations = [(0, 0, 1, 1, 5)]
result = simulate_watering(2, 2, field, 1, operations)
expected = [
[6, 6],
[6, 6]
]
assert result == expected
def test_multiple_operations():
field = [
[1, 2, ... | [
{
"docstring": null,
"function_declaration": "def water_plants(field, operations):",
"function_name": "water_plants",
"parameter_list": "(field, operations)"
},
{
"docstring": null,
"function_declaration": "def simulate_watering(n, m, field, q, operations):",
"function_name": "simula... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def apply_watering_operations(n, m, field, operations):\n \"\"\"\n Applies watering operations to the field and returns the final state of the field.... | trial_gpt4o_2 | {
"original_instruction": "A farming simulator game involves growing crops in a grid-like field. The field is represented by a 2D matrix where each cell contains an integer that denotes the height of the plant in meters.\n\nThe player can water the plants, which increases the height of every plant in a sub-rectangle ... | 0.578672 | Code_Contests_7342 | C | [
"water_plants",
"simulate_watering"
] | 2 | [
[
"simulate_watering",
"water_plants"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | 7dfedd478d188427025811699f856f6bca75e493 | f5892d6290065fa7fc28f65142a71aefe533d6cd | |||
v1.0 | complete | Code_Contests | Code_Contests_7317_C | def is_prime(num: int) -> bool:
""" Check if a number is prime.
>>> is_prime(2)
True
>>> is_prime(17)
True
>>> is_prime(20)
False
>>> is_prime(1)
False
>>> is_prime(51)
False
"""
pass
def game_outcome(n: int, m: int, grid: List[List[int]]) -> str:
""" Determine t... | def is_prime(num):
"""
Check if a number is prime.
"""
if num <= 1:
return False
if num == 2:
return True
if num % 2 == 0:
return False
max_div = int(num**0.5) + 1
for d in range(3, max_div, 2):
if num % d == 0:
return False
return True
de... | def test_is_prime():
assert is_prime(2) == True
assert is_prime(17) == True
assert is_prime(20) == False
assert is_prime(1) == False
assert is_prime(51) == False
def test_game_outcome():
assert game_outcome(3, 3, [[4, 5, 6], [7, 8, 9], [1, 2, 3]]) == "Alice"
assert game_outcome(1, 1, [[2]])... | [
{
"docstring": "Check if a number is prime.",
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": "Determine the outcome of the game.",
"function_declaration": "def game_outcome(n, m, grid):",
"function_name": "game_o... | [
0,
0,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(n):\n \"\"\"\n Checks if a number is prime.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return True\n ... | trial_gpt4o_2 | {
"original_instruction": "Alice and Bob are playing a game with a 2D grid of size n x m, where each cell contains a positive integer. The players take turns, and on each turn, a player can pick any row or column and add 1 to every element in that row or column. Alice always goes first.\n\nThe goal of the game is to ... | 0.681511 | Code_Contests_7317 | C | [
"is_prime",
"game_outcome"
] | 2 | [
[
"game_outcome",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | a1e3f5e965fad60a7c12fc4ec32796b4f136e9e2 | 3e43253f6597e668eaf5de1be8a5188a2fe927c7 | |||
v1.0 | complete | Code_Contests | Code_Contests_7529_C | def pseudo_prime_numbers(n: int) -> List[int]:
"""Generates a list of the first n pseudo-prime numbers.
A pseudo-prime number is a number that has exactly three distinct positive divisors.
>>> pseudo_prime_numbers(1) [4]
>>> pseudo_prime_numbers(5) [4, 9, 25, 49, 121]
>>> pseudo_prime_numbers(10... | def is_prime(num):
"""
Determines if the given number is prime.
"""
if num <= 1:
return False
if num <= 3:
return True
if num % 2 == 0 or num % 3 == 0:
return False
i = 5
while i * i <= num:
if num % i == 0 or num % (i + 2) == 0:
return False
... | from solution import pseudo_prime_numbers
def test_single_pseudo_prime():
assert pseudo_prime_numbers(1) == [4]
def test_first_five_pseudo_primes():
assert pseudo_prime_numbers(5) == [4, 9, 25, 49, 121]
def test_ten_pseudo_primes():
assert pseudo_prime_numbers(10) == [4, 9, 25, 49, 121, 169, 289, 361, 52... | [
{
"docstring": "Determines if the given number is prime.",
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": "Generates a list of the first n pseudo-prime numbers. Pseudo-prime number is a number \nthat has exactly three di... | [
0,
0,
0,
1,
0
] | 1 | hard | 0.2 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(num):\n \"\"\"\n Helper function to check if a number is prime.\n \"\"\"\n if num <= 1:\n return False\n for i in range(... | trial_gpt4o_3 | {
"original_instruction": "Given a list of integers, we define a \"pseudo-prime\" number as a number that has exactly three distinct positive divisors. A well-known example of a pseudo-prime is the square of a prime number, such as 9 (3^2), 25 (5^2), or 49 (7^2).\n\nWrite a function that, given an integer n, generate... | 0.648528 | Code_Contests_7529 | C | [
"is_prime",
"pseudo_prime_numbers"
] | 2 | [
[
"pseudo_prime_numbers",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | c26038e96d255a75056391dc9af5b48d583fd888 | 9b989adc4021061ed9eefb69c98be4516cf3a8fb | |||
v1.0 | complete | Code_Contests | Code_Contests_7100_C | def find_words_in_grid(N: int, M: int, grid: List[str], words: List[str]) -> List[str]:
"""Given a grid of size NxM filled with letters and a list of words, find all words in the list
that can be formed by tracing a path in the grid. A valid path can start from any cell and move
in any of the 8 possible d... | def find_word_in_grid(grid, word, x, y, visited):
if not word:
return True
if (
x < 0 or x >= len(grid) or
y < 0 or y >= len(grid[0]) or
visited[x][y] or
grid[x][y] != word[0]
):
return False
visited[x][y] = True
word = word[1:]
# 8 possible dir... | from solution import find_words_in_grid
def test_example_case():
N = 4
M = 4
grid = [
"ABCD",
"EFGH",
"IJKL",
"MNOP"
]
words = ["BEFI", "CFIM", "ABCDJ"]
expected = ["YES", "YES", "NO"]
assert find_words_in_grid(N, M, grid, words) == expected
def test_single_... | [
{
"docstring": null,
"function_declaration": "def find_word_in_grid(grid, word, x, y, visited):",
"function_name": "find_word_in_grid",
"parameter_list": "(grid, word, x, y, visited)"
},
{
"docstring": null,
"function_declaration": "def word_exists(grid, word):",
"function_name": "wo... | [
0,
0,
0,
0,
1
] | 1 | hard | 0.2 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_valid(x, y, N, M):\n return 0 <= x < N and 0 <= y < M\n\ndef dfs(grid, word, idx, x, y, visited):\n if idx == len(word):\n return True\... | trial_gpt4o_4 | {
"original_instruction": "Given a grid of size NxM filled with letters and a list of words, write a program to find all words in the list that can be formed by tracing a path in the grid. A valid path can start from any cell and move in any of the 8 possible directions (up, down, left, right, or diagonally), but you... | 0.677902 | Code_Contests_7100 | C | [
"find_word_in_grid",
"word_exists",
"find_words_in_grid"
] | 3 | [
[
"find_words_in_grid",
"word_exists"
],
[
"word_exists",
"find_word_in_grid"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | d7c573f50bac8b937e712f3c40fc3c45e19f1a01 | 48f2c36fcca5d584f1170052bf564c7f6a46931b | |||
v1.0 | complete | Code_Contests | Code_Contests_7492_C | import random
card_values = {
'2': 2, '3': 3, '4': 4, '5': 5, '6': 6, '7': 7,
'8': 8, '9': 9, '10': 10, 'J': 11, 'Q': 12, 'K': 13, 'A': 14
}
def draw_card():
"""
Simulates drawing a card from the deck.
Returns the value of the card drawn.
"""
card = random.choice(list(card_values.keys()))... | import random
# Define card values
card_values = {
'2': 2, '3': 3, '4': 4, '5': 5, '6': 6, '7': 7,
'8': 8, '9': 9, '10': 10, 'J': 11, 'Q': 12, 'K': 13, 'A': 14
}
def draw_card():
"""
Simulates drawing a card from the deck.
Returns the value of the card drawn.
"""
card = random.choice(list... | from solution import simulate_game
def test_simulate_game():
# Test with a fixed number of rounds to ensure the output is one of the expected results
results = set(simulate_game(10) for _ in range(1000))
assert "Player 1" in results
assert "Player 2" in results
assert "Draw" in results
def test_si... | [
{
"docstring": "Simulates drawing a card from the deck.\nReturns the value of the card drawn.",
"function_declaration": "def draw_card():",
"function_name": "draw_card",
"parameter_list": "()"
},
{
"docstring": "Simulates a game of n rounds and returns the winner.",
"function_declaration... | [
0,
0,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import random\n\ndef card_value(card):\n values = {'2': 2, '3': 3, '4': 4, '5': 5, '6': 6, '7': 7, '8': 8, \n '9': 9, '10': 10, 'J': 11, 'Q... | trial_gpt4o_2 | {
"original_instruction": "You are tasked with developing a program that runs a simulation of a simple card game between two players. The game uses a standard deck of 52 cards, and the objective is to determine the winner based on a series of random draws.\n\nEach player draws a card from the shuffled deck, and the p... | 0.687622 | Code_Contests_7492 | C | [
"draw_card",
"simulate_game"
] | 2 | [
[
"simulate_game",
"draw_card"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 8649652ffd533226333504a7e836390253e713a1 | 345cc898d520e45cd231cec36352b13e89ee5c0a | |||
v1.0 | complete | Code_Contests | Code_Contests_7364_C | def find_paths_to_target(graph, start, target, steps, current_steps, visited):
"""
Function to determine if the target can be reached with exactly 'steps' steps.
"""
...
def can_reach_end(S, C, X, connections):
"""
Determine whether it is possible to visit the designated end site after conducti... | def find_paths_to_target(graph, start, target, steps, current_steps, visited):
if current_steps > steps:
return False
if current_steps == steps and start == target:
return True
for neighbor in graph[start]:
if current_steps == 0 or visited[current_steps-1] != neighbor:
... | def test_parse_input():
input_data = """2 1 1
1 2
2 1 2
1 2
3 2 2
1 2
2 3
4 4 3
1 2
2 3
3 4
4 1
0 0 0"""
expected_output = [
{'SCX': (2, 1, 1), 'connections': [(1, 2)]},
{'SCX': (2, 1, 2), 'connections': [(1, 2)]},
{'SCX': (3, 2, 2), '... | [
{
"docstring": null,
"function_declaration": "def find_paths_to_target(graph, start, target, steps, current_steps, visited):",
"function_name": "find_paths_to_target",
"parameter_list": "(graph, start, target, steps, current_steps, visited)"
},
{
"docstring": null,
"function_declaration"... | [
1,
0,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_reachable_datasets(datasets):\n results = []\n\n for dataset in datasets:\n S, C, X, corridors = dataset\n # Build the graph as ... | trial_gpt4o_2 | {
"original_instruction": "A traveling scientist is tasked with exploring a series of experimental sites to collect data. Each site is connected to a number of other sites by corridors. The scientist has a specific number of experiments to conduct, represented by an integer X. The total distance the scientist must tr... | 0.555022 | Code_Contests_7364 | C | [
"find_paths_to_target",
"can_reach_end",
"process_multiple_datasets",
"parse_input"
] | 4 | [
[
"can_reach_end",
"find_paths_to_target"
],
[
"process_multiple_datasets",
"can_reach_end"
]
] | 2 | [
"process_multiple_datasets",
"parse_input"
] | false | [] | false | pytest | false | [] | true | 22c52894e5ec68dddd8263e8e96f1e74147284c2 | 4224d832fc02ad61043b6fcd06faf46482cb9318 | |||
v1.0 | complete | Code_Contests | Code_Contests_7702_C | def minimal_total_items(n: int, max_items: List[int]) -> int:
""" Determine the minimum total number of items per package.
Args:
n (int): Number of unique types of pastries.
max_items (List[int]): List of integers indicating the maximum allowed items for each type of pastry.
Returns:
int: ... | from math import gcd
from functools import reduce
def lcm(a, b):
return a * b // gcd(a, b)
def lcm_multiple(numbers):
return reduce(lcm, numbers, 1)
def minimal_total_items(n, max_items):
return lcm_multiple(max_items) | from solution import minimal_total_items
def test_minimal_total_items_example_1():
assert minimal_total_items(3, [4, 3, 2]) == 12
def test_minimal_total_items_example_2():
assert minimal_total_items(4, [2, 2, 2, 2]) == 2
def test_minimal_total_items_single_type():
assert minimal_total_items(1, [5]) == 5
... | [
{
"docstring": null,
"function_declaration": "def lcm(a, b):",
"function_name": "lcm",
"parameter_list": "(a, b)"
},
{
"docstring": null,
"function_declaration": "def lcm_multiple(numbers):",
"function_name": "lcm_multiple",
"parameter_list": "(numbers)"
},
{
"docstring":... | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from math import gcd\nfrom functools import reduce\n\ndef lcm(a, b):\n \"\"\"\n Calculates the Least Common Multiple (LCM) of two numbers a and b.\n ... | trial_gpt4o_1 | {
"original_instruction": "A novel bakery offers their packages in a special way. Each package can include up to **n** different unique types of pastries, and for each type of pastry, a specific number of items must be packed. The bakery wants to fill the packages in such a way where the total number of items per pac... | 0.664834 | Code_Contests_7702 | C | [
"lcm",
"lcm_multiple",
"minimal_total_items"
] | 3 | [
[
"lcm_multiple",
"lcm"
],
[
"minimal_total_items",
"lcm_multiple"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 4e43bbc05a3a7d83566420ee42735bf50f445d8c | b571c28eac0a1b59e59b6eecfcd70e829c45c68a | |||
v1.0 | complete | Code_Contests | Code_Contests_7296_C | def find_root(parent, i):
""" Find the root of the computer `i`. """
if parent[i] == i:
return i
else:
parent[i] = find_root(parent, parent[i]) # Path compression
return parent[i]
def union(parent, rank, x, y):
""" Union two sets containing `x` and `y`. """
root_x = find_ro... | def find_root(parent, i):
if parent[i] == i:
return i
else:
parent[i] = find_root(parent, parent[i]) # Path compression
return parent[i]
def union(parent, rank, x, y):
root_x = find_root(parent, x)
root_y = find_root(parent, y)
if root_x != root_y:
if rank[root... | def test_find_root():
parent = [0, 1, 2, 3, 4]
assert find_root(parent, 1) == 1
parent[2] = 1
assert find_root(parent, 2) == 1
parent[3] = 1
assert find_root(parent, 3) == 1
def test_union():
parent = [0, 1, 2, 3, 4]
rank = [0, 0, 0, 0, 0]
union(parent, rank, 1, 2)
assert find_r... | [
{
"docstring": null,
"function_declaration": "def find_root(parent, i):",
"function_name": "find_root",
"parameter_list": "(parent, i)"
},
{
"docstring": null,
"function_declaration": "def union(parent, rank, x, y):",
"function_name": "union",
"parameter_list": "(parent, rank, x,... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def find(parent, x):\n if parent[x] != x:\n parent[x] = find(parent, parent[x])\n return parent[x]\n\ndef union(parent, rank, x, y):\n root... | trial_gpt4o_1 | {
"original_instruction": "You have a network of n computers, identified by integers from 1 to n. Some pairs of computers are connected by bidirectional communication channels. Your task is to find out if all computers in the network are connected directly or indirectly.\n\nEach network configuration is represented b... | 0.575226 | Code_Contests_7296 | C | [
"find_root",
"union",
"is_connected_network",
"check_all_connected"
] | 4 | [
[
"check_all_connected",
"is_connected_network"
],
[
"is_connected_network",
"find_root"
],
[
"is_connected_network",
"union"
],
[
"union",
"find_root"
]
] | 4 | [] | false | [] | false | pytest | false | [] | true | 4af47df256656062abadb52e14ebc174080e9e1a | 53f891aae75a1e8ed9b491deac0022d7544c81c5 | |||
v1.0 | complete | Code_Contests | Code_Contests_7468_C | def minimum_distance_railway_network(n: int, m: int, routes: List[Tuple[int, int, int]]) -> int:
"""
Find the minimum possible total distance of the railway network that connects all the cities directly or indirectly.
If it is not possible to connect all cities, return -1.
>>> minimum_distanc... | def find(parent, i):
""" A utility function to find the set of an element i
(uses path compression technique)"""
if parent[i] == i:
return i
else:
parent[i] = find(parent, parent[i])
return parent[i]
def union(parent, rank, x, y):
""" A function that does union of two sets ... | import pytest
from solution import minimum_distance_railway_network
def test_example1():
n = 4
m = 5
routes = [
(1, 2, 5),
(1, 3, 10),
(2, 3, 4),
(2, 4, 11),
(3, 4, 7)
]
assert minimum_distance_railway_network(n, m, routes) == 16
def test_example2():
n =... | [
{
"docstring": "A utility function to find the set of an element i \n(uses path compression technique)",
"function_declaration": "def find(parent, i):",
"function_name": "find",
"parameter_list": "(parent, i)"
},
{
"docstring": "A function that does union of two sets of x and y \n(uses union... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def find(parent, i):\n if parent[i] == i:\n return i\n else:\n return find(parent, parent[i])\n\ndef union(parent, rank, x, y):\n xr... | trial_gpt4o_2 | {
"original_instruction": "Emma is designing a railway system that connects various cities with unique train routes. She has n cities and m unique bidirectional routes connecting them. Each route has a distance associated with it. Emma wants to ensure that there is a way to travel between any two distinct cities usin... | 0.630421 | Code_Contests_7468 | C | [
"find",
"union",
"kruskal",
"minimum_distance_railway_network"
] | 4 | [
[
"kruskal",
"find"
],
[
"kruskal",
"union"
],
[
"minimum_distance_railway_network",
"kruskal"
],
[
"union",
"find"
]
] | 4 | [] | false | [] | false | pytest | true | [] | true | 08deca97c7717e87c0045bb4384baab3e970df1e | c7772b08e936cf9eb8a05b4f8318dc9252cde759 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.