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 | Codeforces | Codeforces_29271_C | from datetime import datetime
def parse_log(log):
timestamp, user_id, transaction_amount = log.split(',')
timestamp = datetime.strptime(timestamp.strip(), "%Y-%m-%d %H:%M:%S")
user_id = int(user_id.strip())
transaction_amount = float(transaction_amount.strip())
return timestamp, user_id, transactio... | from datetime import datetime
def parse_log(log):
timestamp, user_id, transaction_amount = log.split(',')
timestamp = datetime.strptime(timestamp.strip(), "%Y-%m-%d %H:%M:%S")
user_id = int(user_id.strip())
transaction_amount = float(transaction_amount.strip())
return timestamp, user_id, transactio... | from solution import calculate_net_amount
def test_no_transactions():
input_data = """12345 2023-01-01 00:00:00 2023-12-31 23:59:59"""
assert calculate_net_amount(input_data) == 0.00
def test_single_transaction_in_range():
input_data = """12345 2023-01-01 00:00:00 2023-12-31 23:59:59
2023-01-10 15:30:... | [
{
"docstring": null,
"function_declaration": "def parse_log(log):",
"function_name": "parse_log",
"parameter_list": "(log)"
},
{
"docstring": null,
"function_declaration": "def calculate_net_amount(input_data):",
"function_name": "calculate_net_amount",
"parameter_list": "(input_... | [
1,
0,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from datetime import datetime\n\ndef parse_log(log):\n timestamp, user_id, transaction_amount = log.split(',')\n timestamp = datetime.strptime(timestamp... | trial_gpt4o_0 | {
"original_instruction": "You have recently been hired to work with a team of developers on a new project. Your first task is to implement a module for processing transaction logs in a large-scale financial application. The log file contains records of transactions with each line in the following format:\n\n```\ntim... | 0.641695 | Codeforces_29271 | C | [
"parse_log",
"calculate_net_amount"
] | 2 | [
[
"calculate_net_amount",
"parse_log"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 5efc6d35658ff370a68038a89adceaa8463a25fe | 357313eaf11556b92481de03a3b46b328914c759 | |||
v1.0 | complete | Codeforces | Codeforces_30254_C | def max_sum_submatrix(matrix: List[List[int]], n: int, m: int) -> int:
""" Determine the maximum sum of the heights in any contiguous rectangular subarea of the garden.
>>> max_sum_submatrix([[1, -2, -1, 4, 5], [2, 5, -8, 3, -1], [3, -2, -3, 4, 2], [2, 4, 3, -1, 1]], 4, 5)
"21"
>>> max_sum_submatrix([[2... | def max_subarray_sum(arr):
max_sum = arr[0]
current_sum = arr[0]
for num in arr[1:]:
current_sum = max(num, current_sum + num)
max_sum = max(max_sum, current_sum)
return max_sum
def max_sum_submatrix(matrix, n, m):
max_sum = float('-inf')
for left in range(m):
... | from solution import max_sum_submatrix
def test_small_matrix():
matrix = [
[1, -2, -1, 4, 5],
[2, 5, -8, 3, -1],
[3, -2, -3, 4, 2],
[2, 4, 3, -1, 1]
]
n = 4
m = 5
assert max_sum_submatrix(matrix, n, m) == 21
def test_single_row():
matrix = [
[2, 1, -... | [
{
"docstring": null,
"function_declaration": "def max_subarray_sum(arr):",
"function_name": "max_subarray_sum",
"parameter_list": "(arr)"
},
{
"docstring": null,
"function_declaration": "def max_sum_submatrix(matrix, n, m):",
"function_name": "max_sum_submatrix",
"parameter_list"... | [
0,
1,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def max_sum_submatrix(garden):\n \"\"\"\n Returns the maximum sum of rectangular subarea in the garden.\n \n Args:\n garden: List of list of in... | trial_gpt4o_2 | {
"original_instruction": "Margo is an avid gardener who has a rectangular garden of dimensions n x m. The garden is divided into n rows and m columns, forming a grid of square cells, each of which can either be empty or contain a plant. Each plant can be of a different height, and Margo wants to prune one contiguous... | 0.601298 | Codeforces_30254 | C | [
"max_subarray_sum",
"max_sum_submatrix"
] | 2 | [
[
"max_sum_submatrix",
"max_subarray_sum"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | baba30846a8c82abfbe36a5a222bae20dc780853 | 8fbea8e0c6c6c95e32fe008a7749bad933452bb7 | |||
v1.0 | complete | Codeforces | Codeforces_30526_C | def solve(texts):
""" Find the maximum total value of any subset of texts that can be concatenated to form a palindrome.
Args:
texts (list): A list of tuples, where each tuple contains a string and an integer value.
Returns:
int: The maximum total value of any subset of texts that can be c... | def is_palindrome(s):
return s == s[::-1]
def max_palindrome_subset_value(texts):
n = len(texts)
# Separate texts into palindrome and non-palindrome groups
palindromes = []
non_palindromes = []
for s, v in texts:
if is_palindrome(s):
palindromes.append((s, v))
else:
... | from solution import solve
def test_example():
texts = [
("abc", 10),
("cba", 20),
("bb", 30),
("a", 15)
]
assert solve(texts) == 45
def test_single_text_palindrome():
texts = [
("racecar", 50)
]
assert solve(texts) == 50
def test_single_text_non_palind... | [
{
"docstring": null,
"function_declaration": "def is_palindrome(s):",
"function_name": "is_palindrome",
"parameter_list": "(s)"
},
{
"docstring": null,
"function_declaration": "def max_palindrome_subset_value(texts):",
"function_name": "max_palindrome_subset_value",
"parameter_li... | [
0,
0,
0,
0,
0,
1,
0,
0,
0
] | 1 | hard | 0.111 | {
"trial_gpt4o_0": null,
"trial_gpt4o_1": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared1_results_combined.jsonl",
"solution_code": "def is_palindrome(s):\n return s == s[::-1]\n\ndef find_maximum_palindrome_value(texts):\n n = len(texts)\n\n # Split the te... | trial_gpt4o_6 | {
"original_instruction": "Fedor is exploring mysterious ancient ruins and has discovered a large library of ancient texts. Each text is inscribed with a sequence of symbols and has an associated value. Fedor believes that if he can find a subset of these texts whose concatenated string of symbols is a palindrome, he... | 0.706718 | Codeforces_30526 | C | [
"is_palindrome",
"max_palindrome_subset_value",
"solve"
] | 3 | [
[
"max_palindrome_subset_value",
"is_palindrome"
],
[
"solve",
"max_palindrome_subset_value"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | acb36f118de9670e39d443d1710cf883ab9b3bb4 | 45ca33f5ffa838d02ab2c409dbf89ea1be5ee630 | |||
v1.0 | complete | Codeforces | Codeforces_30390_C | def generate_tournament_schedule(n):
"""
Returns a list of matches for the tournament. Each match is represented
as a tuple (team1, team2).
>>> generate_tournament_schedule(2) == [(1, 2)]
>>> generate_tournament_schedule(3) == [(1, 2), (1, 3), (2, 3)]
>>> generate_tournament_schedule(4) == [(1, ... | def generate_tournament_schedule(n):
"""
Returns a list of matches for the tournament. Each match is represented
as a tuple (team1, team2).
"""
matches = []
for i in range(1, n):
for j in range(i+1, n+1):
matches.append((i, j))
return matches
def print_tournament_schedul... | from solution import generate_tournament_schedule, print_tournament_schedule
def test_generate_tournament_schedule():
assert generate_tournament_schedule(2) == [(1, 2)]
assert generate_tournament_schedule(3) == [(1, 2), (1, 3), (2, 3)]
assert generate_tournament_schedule(4) == [(1, 2), (1, 3), (1, 4), (2, ... | [
{
"docstring": "Returns a list of matches for the tournament. Each match is represented\nas a tuple (team1, team2).",
"function_declaration": "def generate_tournament_schedule(n):",
"function_name": "generate_tournament_schedule",
"parameter_list": "(n)"
},
{
"docstring": "Prints the schedul... | [
1,
0,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def generate_tournament_schedule(n):\n \"\"\"\n Generates the schedule for a tournament with n teams, where each team plays\n against every other tea... | trial_gpt4o_2 | {
"original_instruction": "Alex is organizing a sports tournament in his school and he has to schedule matches between teams. Each match is a pair between two distinct teams, and each team should compete against every other team exactly once. \n\nAlex wants to know the schedule of matches for a given number of teams.... | 0.640435 | Codeforces_30390 | C | [
"generate_tournament_schedule",
"print_tournament_schedule"
] | 2 | [
[
"print_tournament_schedule",
"generate_tournament_schedule"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 01bf891b5d188c7545d159a1fb704d08ed58c295 | 7444bfcc4b58c9b4f62646f685018e24340f46d0 | |||
v1.0 | complete | Codeforces | Codeforces_30462_C | def minimum_cost_to_connect_nodes(n: int, edges: List[Tuple[int, int, int]]) -> int:
""" Determine the minimum cost to connect all nodes in a town with the given edges.
>>> minimum_cost_to_connect_nodes(4, [(1, 2, 1), (2, 3, 4), (3, 4, 2), (4, 1, 3)])
6
>>> minimum_cost_to_connect_nodes(3, [(1, 2, 0), (... | def find(parent, i):
if parent[i] == i:
return i
else:
return find(parent, parent[i])
def union(parent, rank, x, y):
root_x = find(parent, x)
root_y = find(parent, y)
if rank[root_x] < rank[root_y]:
parent[root_x] = root_y
elif rank[root_x] > rank[root_y]:
p... | from solution import minimum_cost_to_connect_nodes
def test_example_case():
n = 4
m = 4
edges = [
(1, 2, 1),
(2, 3, 4),
(3, 4, 2),
(4, 1, 3)
]
assert minimum_cost_to_connect_nodes(n, edges) == 6
def test_all_nodes_already_connected():
n = 3
m = 3
edges =... | [
{
"docstring": null,
"function_declaration": "def find(parent, i):",
"function_name": "find",
"parameter_list": "(parent, i)"
},
{
"docstring": null,
"function_declaration": "def union(parent, rank, x, y):",
"function_name": "union",
"parameter_list": "(parent, rank, x, y)"
},
... | [
0,
0,
0,
0,
0,
0,
1,
0,
0
] | 1 | hard | 0.111 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def find(parent, i):\n if parent[i] == i:\n return i\n return find(parent, parent[i])\n\ndef union(parent, rank, x, y):\n rootX = find(parent,... | trial_gpt4o_6 | {
"original_instruction": "A town needs to be connected via power lines. The town has `n` electrical nodes, some of which are already directly connected by power lines. The goal is to determine the minimum cost to connect all the nodes such that each node is reachable from every other node.\n\nThe town can be represe... | 0.678815 | Codeforces_30462 | C | [
"find",
"union",
"minimum_cost_to_connect_nodes"
] | 3 | [
[
"minimum_cost_to_connect_nodes",
"find"
],
[
"minimum_cost_to_connect_nodes",
"union"
],
[
"union",
"find"
]
] | 3 | [] | false | [] | false | pytest | true | [] | true | b0232bfcdfd4981d852c351b2f7cd52ac41c2894 | 24d71054df62fff5efe5805e036baa30efd4cee4 | |||
v1.0 | complete | Codeforces | Codeforces_29209_C | from collections import deque, defaultdict
from typing import List, Tuple
def bfs_longest_path(start, graph, pathLen, n):
visited = {}
queue = deque([(start, 1, 0)]) # (node, pathLen count, pathLength)
max_len = -1
while queue:
node, count, path_length = queue.popleft()
if count =... | from collections import deque, defaultdict
def bfs_longest_path(start, graph, pathLen, n):
visited = {}
queue = deque([(start, 1, 0)]) # (node, pathLen count, pathLength)
max_len = -1
while queue:
node, count, path_length = queue.popleft()
if count == pathLen: # If the path lengt... | from solution import max_path_length
def test_case_1():
n = 5
pathLen = 3
nodes = [1, 2, 3, 4, 5]
m = 4
edges = [(1, 2), (2, 3), (3, 4), (4, 5)]
assert max_path_length(n, pathLen, nodes, m, edges) == 2
def test_case_2():
n = 6
pathLen = 4
nodes = [1, 2, 3, 4, 5, 6]
m = 6
ed... | [
{
"docstring": null,
"function_declaration": "def bfs_longest_path(start, graph, pathLen, n):",
"function_name": "bfs_longest_path",
"parameter_list": "(start, graph, pathLen, n)"
},
{
"docstring": null,
"function_declaration": "def max_path_length(n, pathLen, nodes, m, edges):",
"fu... | [
1,
0
] | 1 | medium | 0.5 | {
"trial_gpt4o_0": null,
"trial_gpt4o_1": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared1_results_combined.jsonl",
"solution_code": "from collections import deque, defaultdict\n\ndef bfs_longest_path(start, graph, pathLen, n):\n visited = {}\n queue = deque([(... | trial_gpt4o_1 | {
"original_instruction": "You are given an array of integers nodes of length $$$n$$$ ($$$1 \\le n \\le 10^5$$$) and an integer pathLen. Each integer in the array nodes represents a unique identifier of a node in an undirected graph.\n\nYour task is to determine the maximum length of any path in the graph containing ... | 0.594742 | Codeforces_29209 | C | [
"bfs_longest_path",
"max_path_length"
] | 2 | [
[
"max_path_length",
"bfs_longest_path"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | eafd4f778c1af9447d63b7280777419bd5cb434a | 6dc49c8728b020abde18581b7fb7a14f204b47f9 | |||
v1.0 | complete | Codeforces | Codeforces_30137_C | class TreeNode:
def __init__(self, x):
self.val = x
self.left = None
self.right = None
def build_tree(level_order: List[int]) -> TreeNode:
"""
Builds a binary tree from a list of values in level order.
"""
# Implementation here ...
def findLCA(root: TreeNode, p: int, q: int... | class TreeNode:
def __init__(self, x):
self.val = x
self.left = None
self.right = None
def build_tree(level_order):
"""
Builds a binary tree from a list of values in level order.
"""
if not level_order:
return None
root = TreeNode(level_order[0])
queue =... | from solution import lowest_common_ancestor
def test_lca_case1():
assert lowest_common_ancestor(7, [3, 5, 1, 6, 2, 0, 8], 5, 1) == 3
def test_lca_case2():
assert lowest_common_ancestor(7, [3, 5, 1, 6, 2, 0, 8], 6, 2) == 5
def test_lca_case3():
assert lowest_common_ancestor(7, [3, 5, 1, 6, 2, 0, 8], 6, 8)... | [] | [
0,
0,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl",
"solution_code": "class TreeNode:\n def __init__(self, x):\n self.val = x\n self.left = None\n self.right = None\n\ndef create_binary_tree_from_level_or... | trial_gpt4o_2 | {
"original_instruction": "You are given a binary tree with node values stored in an array in a level-order fashion. Given two nodes in the binary tree, return the lowest common ancestor (LCA) of these two nodes.\n\nThe Lowest Common Ancestor of two nodes p and q in a binary tree is defined as the lowest node in T th... | 0.511204 | Codeforces_30137 | C | [
"build_tree",
"findLCA",
"lowest_common_ancestor"
] | 3 | [
[
"lowest_common_ancestor",
"build_tree"
],
[
"lowest_common_ancestor",
"findLCA"
]
] | 2 | [] | false | [
"TreeNode"
] | true | pytest | true | [] | true | 9e8b81cd365f53df44ec323195b8e3a9fe223407 | b4f4bef7716eb560e4cf2dc1db4f45f5baafd38e | |||
v1.0 | complete | Codeforces | Codeforces_29763_C | class TreeNode:
def __init__(self, value):
self.value = value
self.children = []
def build_tree(n, values, edges):
""" Builds a tree from node values and edges. """
nodes = [TreeNode(value) for value in values]
tree = {i: nodes[i] for i in range(n)}
for u, v in edges:
tree[u... | class TreeNode:
def __init__(self, value):
self.value = value
self.children = []
def build_tree(n, values, edges):
nodes = [TreeNode(value) for value in values]
tree = {i: nodes[i] for i in range(n)}
for u, v in edges:
tree[u-1].children.append(tree[v-1])
tree[v-1].child... | from solution import process_queries
def test_simple_case():
n = 3
values = [1, 2, 3]
edges = [(1, 2), (1, 3)]
queries = [(2, 1)]
assert process_queries(n, values, edges, queries) == [6]
def test_update_case():
n = 3
values = [1, 2, 3]
edges = [(1, 2), (1, 3)]
queries = [(1, 1, 5),... | [] | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from collections import defaultdict, deque\n\nclass Tree:\n def __init__(self, n, values):\n self.n = n\n self.values = values\n self.... | trial_gpt4o_1 | {
"original_instruction": "You are given a tree with n nodes and n-1 edges. Each node has an initial value ai and you need to perform the following kinds of operations:\n\n1. Update the value of a particular node.\n2. Calculate the sum of the values of all nodes in the subtree of a given node (including the node itse... | 0.582388 | Codeforces_29763 | C | [
"build_tree",
"dfs_sum",
"update_value",
"query_subtree_sum",
"process_queries"
] | 5 | [
[
"process_queries",
"build_tree"
],
[
"process_queries",
"dfs_sum"
],
[
"process_queries",
"query_subtree_sum"
],
[
"process_queries",
"update_value"
]
] | 4 | [
"process_queries"
] | false | [
"TreeNode"
] | true | pytest | true | [] | true | 7aa1ee54a9aac671a24b1acf429c732dab6bb4b8 | ff466215662d66141152241e153753b0735ca095 | |||
v1.0 | complete | Codeforces | Codeforces_30091_C | import math
from typing import List, Tuple
def calculate_distance(p1: Tuple[int, int], p2: Tuple[int, int]) -> float:
"""
Calculates the Euclidean distance between two points
"""
return math.sqrt((p1[0] - p2[0]) ** 2 + (p1[1] - p2[1]) ** 2)
def find_max_distance(test_cases: List[List[Tuple[str, int,... | import math
def calculate_distance(p1, p2):
"""
Calculates the Euclidean distance between two points
"""
return math.sqrt((p1[0] - p2[0]) ** 2 + (p1[1] - p2[1]) ** 2)
def find_max_distance(test_cases):
results = []
for case in test_cases:
starts = []
ends = []
for point... | from solution import main
def test_example_case():
input_data = """2
2
S 0 0
E 3 4
S 1 1
E 4 5
3
S -1 -1
E 2 3
S 0 0
E 1 1
S -2 -2
E 4 4"""
expected_output = "5.000000\n8.485281"
assert main(input_data) == expected_output
def test_single_segment():
input_data = """1
1
S 1 1
E 4 5"""
expected_outpu... | [
{
"docstring": "Calculates the Euclidean distance between two points",
"function_declaration": "def calculate_distance(p1, p2):",
"function_name": "calculate_distance",
"parameter_list": "(p1, p2)"
},
{
"docstring": null,
"function_declaration": "def find_max_distance(test_cases):",
... | [
0,
0,
0,
0,
1
] | 1 | hard | 0.2 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import math\n\ndef calculate_distance(x1, y1, x2, y2):\n return math.sqrt((x1 - x2) ** 2 + (y1 - y2) ** 2)\n\ndef max_distance_between_segments(t, test_cas... | trial_gpt4o_4 | {
"original_instruction": "You are given a series of n points in a 2D plane. Each point can be either a \"start\" point or an \"end\" point, and collectively they form straight non-overlapping line segments, with each segment connecting exactly one \"start\" point to one \"end\" point.\n\nYour task is to identify all... | 0.6595 | Codeforces_30091 | C | [
"calculate_distance",
"find_max_distance",
"parse_input",
"main"
] | 4 | [
[
"find_max_distance",
"calculate_distance"
]
] | 1 | [
"parse_input"
] | false | [] | false | pytest | true | [] | true | d6b88ef1f12c5a7021a1d5e5b575a33b48eff86c | 7688f835a4015a0abf5e7197a5a962a50969bace | |||
v1.0 | complete | Codeforces | Codeforces_29962_C | def minimum_cost_to_connect_cities(n, existing_roads, proposed_roads):
"""
Determine the minimum total cost to ensure all cities in Zoria are connected using existing
and possibly some proposed new roads.
Args:
n: int - the number of cities.
existing_roads: List[Tuple[int, int, int]] - 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 rank[root_x] > rank[root_y]:
parent[root_y] = root_x
elif rank[root_x] < rank[root_y]:
paren... | def test_minimum_cost_to_connect_cities():
assert minimum_cost_to_connect_cities(4, [(1, 2, 1), (2, 3, 4), (3, 4, 2)], [(1, 3, 2), (1, 4, 3)]) == 5
assert minimum_cost_to_connect_cities(4, [(1, 2, 1), (2, 3, 1), (3, 4, 1)], [(1, 3, 2), (1, 4, 2)]) == 3
assert minimum_cost_to_connect_cities(4, [(1, 2, 4), (2... | [
{
"docstring": null,
"function_declaration": "def find(parent, i):",
"function_name": "find",
"parameter_list": "(parent, i)"
},
{
"docstring": null,
"function_declaration": "def union(parent, rank, x, y):",
"function_name": "union",
"parameter_list": "(parent, rank, x, y)"
},
... | [
0,
0,
0,
1,
1
] | 2 | medium | 0.4 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_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 union(... | trial_gpt4o_4 | {
"original_instruction": "The Kingdom of Zoria has a system of roads connecting various cities. The king has declared a plan to modernize the road system by constructing new roads between certain pairs of cities. However, Zoria's road construction budget is limited, so the king wants to ensure that the entire kingdo... | 0.678894 | Codeforces_29962 | C | [
"find",
"union",
"minimum_cost_to_connect_cities"
] | 3 | [
[
"minimum_cost_to_connect_cities",
"find"
],
[
"minimum_cost_to_connect_cities",
"union"
],
[
"union",
"find"
]
] | 3 | [] | false | [] | false | pytest | false | [] | true | af59722a110a90de833f20a18e818379870a0321 | 9de95704e5e9427b66d3e47478df9243af18bf17 | |||
v1.0 | complete | Codeforces | Codeforces_30385_C | def find_longest_path(R: int, C: int, grid: List[str]) -> int:
""" Returns the maximum length of the path in the grid such that no cell is
visited more than once, and no two consecutive cells in the path have the
same letter.
>>> find_longest_path(4, 4, ["ABCD", "EFGH", "IJKL", "MNOP"])
16
>>>... | def longest_unique_path(grid, R, C):
directions = [(0, 1), (1, 0), (0, -1), (-1, 0)]
def dfs(x, y, visited):
max_length = 0
for dx, dy in directions:
nx, ny = x + dx, y + dy
if 0 <= nx < R and 0 <= ny < C and grid[nx][ny] not in visited:
visited.add(g... | def test_longest_unique_path():
grid = [
"ABCD",
"EFGH",
"IJKL",
"MNOP"
]
R, C = 4, 4
result = find_longest_path(R, C, grid)
assert result == 16
def test_single_cell():
grid = ["A"]
R, C = 1, 1
result = find_longest_path(R, C, grid)
assert result == 1... | [
{
"docstring": null,
"function_declaration": "def longest_unique_path(grid, R, C):",
"function_name": "longest_unique_path",
"parameter_list": "(grid, R, C)"
},
{
"docstring": null,
"function_declaration": "def find_longest_path(R, C, grid):",
"function_name": "find_longest_path",
... | [
0,
0,
0,
1,
1
] | 2 | medium | 0.4 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def longest_unique_path(R, C, grid):\n def is_valid(x, y, visited):\n return 0 <= x < R and 0 <= y < C and grid[x][y] not in visited\n\n def dfs(... | trial_gpt4o_4 | {
"original_instruction": "You are given a grid with R rows and C columns. Each cell in the grid contains a letter from 'A' to 'Z'. A step consists of moving from one cell to an adjacent cell north, south, east, or west. You are to determine the length of the longest path you can take in this grid such that no cell i... | 0.680971 | Codeforces_30385 | C | [
"longest_unique_path",
"find_longest_path"
] | 2 | [
[
"find_longest_path",
"longest_unique_path"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | dd720c18d14899933c1f75ea9fdb932d266834b5 | dfeabb0cb3cc879fd4ca921f9c6c0223c87d036e | |||
v1.0 | complete | Codeforces | Codeforces_30860_C | def find_submatrix_with_sum(n: int, k: int, matrix: List[List[int]]) -> str:
""" Determines if there's any square submatrix where the sum of all its elements is equal to a given value k.
>>> find_submatrix_with_sum(3, 10, [
... [1, 2, 3],
... [4, 5, 1],
... [7, 8, 9]
... ])
'YES'
... | def does_submatrix_with_sum_exist(n, k, matrix):
def get_prefix_sum(matrix):
prefix_sum = [[0] * (n + 1) for _ in range(n + 1)]
for i in range(n):
for j in range(n):
prefix_sum[i + 1][j + 1] = matrix[i][j] + prefix_sum[i + 1][j] + prefix_sum[i][j + 1] - prefix_sum[i][j]
... | from solution import find_submatrix_with_sum
def test_example_1():
n = 3
k = 10
matrix = [
[1, 2, 3],
[4, 5, 1],
[7, 8, 9]
]
assert find_submatrix_with_sum(n, k, matrix) == "YES"
def test_example_2():
n = 3
k = 20
matrix = [
[1, 2, 3],
[4, 5, 1],... | [
{
"docstring": null,
"function_declaration": "def does_submatrix_with_sum_exist(n, k, matrix):",
"function_name": "does_submatrix_with_sum_exist",
"parameter_list": "(n, k, matrix)"
},
{
"docstring": null,
"function_declaration": "def find_submatrix_with_sum(n, k, matrix):",
"functio... | [
1,
1,
0
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def has_submatrix_with_sum(matrix, n, k):\n \"\"\"\n Determines if there exists at least one submatrix with sum equal to k.\n \n Args:\n matrix... | trial_gpt4o_1 | {
"original_instruction": "Gina is the manager of a warehouse and she has a square matrix consisting of integers where each cell $(i, j)$ represents the quantity of a product at that location. She wants to know if there's any square submatrix where the sum of all its elements is equal to a given value $k$. \n\nYou ar... | 0.577464 | Codeforces_30860 | C | [
"does_submatrix_with_sum_exist",
"find_submatrix_with_sum"
] | 2 | [
[
"find_submatrix_with_sum",
"does_submatrix_with_sum_exist"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 95169c281e1142963e204584d81b02d4a42ef85a | edaed4335c5d326678b25fd451ed509dc426f111 | |||
v1.0 | complete | Codeforces | Codeforces_30731_C | import string
from typing import List
def is_valid_code(code: str) -> bool:
""" Check if the code meets all the criteria for a valid security code.
>>> is_valid_code("Aa1bcdefgh")
True
>>> is_valid_code("1234567890")
False
>>> is_valid_code("aaBBccDDyy")
False
>>> is_valid_code("Aa1bB2c... | import string
def is_valid_code(code):
digits = any(char.isdigit() for char in code)
uppercases = any(char.isupper() for char in code)
lowercases = any(char.islower() for char in code)
no_repeats = all(code[i] != code[i+1] for i in range(len(code) - 1))
if len(code) == 10 and digits and upperc... | def test_is_valid_code():
assert is_valid_code("Aa1bcdefgh") == True
assert is_valid_code("1234567890") == False
assert is_valid_code("aaBBccDDyy") == False
assert is_valid_code("Aa1bB2cD3e") == True
def test_determine_changes():
assert determine_changes("1234567890") == ["Change a character to an ... | [
{
"docstring": null,
"function_declaration": "def is_valid_code(code):",
"function_name": "is_valid_code",
"parameter_list": "(code)"
},
{
"docstring": null,
"function_declaration": "def determine_changes(code):",
"function_name": "determine_changes",
"parameter_list": "(code)"
... | [
0,
0,
0,
0,
0,
0,
0,
0,
1,
0
] | 1 | hard | 0.1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def validate_security_code(code):\n \"\"\"\n Validate a single security code and return the result as either \"VALID\" or a list of changes needed.\n ... | trial_gpt4o_8 | {
"original_instruction": "You're tasked with generating security codes for a new, high profile software release. Each code must be a unique combination of alphanumeric characters that meets the following criteria:\n\n1. It should be exactly 10 characters long.\n2. At least one character should be a digit.\n3. At lea... | 0.587218 | Codeforces_30731 | C | [
"is_valid_code",
"determine_changes",
"validate_codes",
"check_security_codes"
] | 4 | [
[
"check_security_codes",
"validate_codes"
],
[
"validate_codes",
"determine_changes"
],
[
"validate_codes",
"is_valid_code"
]
] | 3 | [] | false | [] | false | pytest | false | [] | true | efc32a6cccc0d65ef9f827ab5f6bf33bf3f37505 | a15acee18f39e3aa84abba371b4f6ee34cf6c9a4 | |||
v1.0 | complete | Codeforces | Codeforces_30593_C | def minimum_spanning_tree(n: int, m: int, edges: List[Tuple[int, int, int]]) -> int:
"""
Calculates the minimum cost to connect all towns (minimum spanning tree) using Kruskal's algorithm.
>>> minimum_spanning_tree(4, 5, [(1, 2, 10), (1, 3, 6), (1, 4, 5), (2, 3, 15), (3, 4, 4)])
19
"""
pass
de... | def find(parent, i):
if parent[i] == i:
return i
else:
parent[i] = find(parent, parent[i])
return parent[i]
def union(parent, rank, x, y):
root_x = find(parent, x)
root_y = find(parent, y)
if root_x != root_y:
if rank[root_x] > rank[root_y]:
parent[r... | def test_example_case():
n = 4
m = 5
edges = [
(1, 2, 10),
(1, 3, 6),
(1, 4, 5),
(2, 3, 15),
(3, 4, 4)
]
assert minimum_spanning_tree(n, m, edges) == 19
def test_case_min_edges():
n = 2
m = 1
edges = [(1, 2, 1)]
assert minimum_spanning_tree(n,... | [
{
"docstring": null,
"function_declaration": "def find(parent, i):",
"function_name": "find",
"parameter_list": "(parent, i)"
},
{
"docstring": null,
"function_declaration": "def union(parent, rank, x, y):",
"function_name": "union",
"parameter_list": "(parent, rank, x, y)"
},
... | [
0,
0,
0,
0,
0,
0,
0,
1,
0
] | 1 | hard | 0.111 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_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 root_... | trial_gpt4o_8 | {
"original_instruction": "In a fictional country called Algoria, there are `n` towns connected by `m` bidirectional roads forming an undirected graph. You are to design a railway network that connects all towns such that:\n\n1. The total cost of building the railway is minimized.\n2. Each town can be reached from an... | 0.704797 | Codeforces_30593 | C | [
"find",
"union",
"minimum_spanning_tree",
"run"
] | 4 | [
[
"minimum_spanning_tree",
"find"
],
[
"minimum_spanning_tree",
"union"
],
[
"run",
"minimum_spanning_tree"
],
[
"union",
"find"
]
] | 4 | [] | false | [] | false | pytest | false | [] | true | 688c7516bbdff26b9e4dd8f98df6fa554a7b32b0 | 654e49babd28e0765892ccc4e8d956092a1e15d5 | |||
v1.0 | complete | Codeforces | Codeforces_30873_C | from collections import defaultdict, deque
def tree_diameter(n: int, edges: List[Tuple[int, int]]) -> int:
""" Find the diameter of a tree given its edges.
n: int - number of nodes in the tree
edges: List[Tuple[int, int]] - list of edges in the tree
>>> tree_diameter(1, [])
0
>>> tree_dia... | from collections import defaultdict, deque
def tree_diameter(n, edges):
if n == 1:
return 0
# Build the adjacency list
graph = defaultdict(list)
for u, v in edges:
graph[u].append(v)
graph[v].append(u)
# Helper function to perform BFS and return the farthest node and its d... | def test_tree_diameter_single_node():
assert solve(1, []) == 0
def test_tree_diameter_simple_case():
assert solve(5, [(1, 2), (1, 3), (2, 4), (2, 5)]) == 3
def test_tree_diameter_line_shape_tree():
assert solve(4, [(1, 2), (2, 3), (3, 4)]) == 3
def test_tree_diameter_star_shape_tree():
assert solve(5... | [
{
"docstring": null,
"function_declaration": "def tree_diameter(n, edges):",
"function_name": "tree_diameter",
"parameter_list": "(n, edges)"
},
{
"docstring": null,
"function_declaration": "def solve(n, edges):",
"function_name": "solve",
"parameter_list": "(n, edges)"
},
{
... | [
0,
0,
0,
1
] | 1 | hard | 0.25 | {
"trial_gpt4o_0": null,
"trial_gpt4o_1": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared1_results_combined.jsonl",
"solution_code": "def find_tree_diameter(n, edges):\n from collections import defaultdict, deque\n \n # Create adjacency list representation o... | trial_gpt4o_4 | {
"original_instruction": "You are given a tree with n nodes, where 1 ≤ n ≤ 100. The tree is rooted at node 1. Each node, excluding the root, has exactly one parent node. \n\nYour task is to find the diameter of this tree, which is the longest path between any two nodes.\n\nInput:\nThe first line contains an integer ... | 0.666882 | Codeforces_30873 | C | [
"tree_diameter",
"solve"
] | 2 | [
[
"solve",
"tree_diameter"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | b74683a8e52acfdad7e3200a42465fd07a7047ee | ffc3b15e8843628391e471416a7d8f76192a9fb9 | |||
v1.0 | complete | Codeforces | Codeforces_30636_C | def find_min_colors(n: int, m: int, adj_matrix: List[List[int]]) -> int:
""" Determine the minimum number of colors required to color the graph
such that no two adjacent nodes share the same color.
Args:
n (int): Number of nodes in the graph.
m (int): Number of edges in the graph.
adj_... | def is_safe(node, color, graph, c):
for i in range(len(graph)):
if graph[node][i] == 1 and color[i] == c:
return False
return True
def graph_coloring_util(graph, m, color, node):
if node == len(graph):
return True
for c in range(1, m+1):
if is_safe(node, color, grap... | from solution import find_min_colors
def test_case_1():
n = 4
m = 4
adj_matrix = [
"0 1 1 0",
"1 0 1 0",
"1 1 0 1",
"0 0 1 0"
]
adj_matrix = [row.split() for row in adj_matrix]
assert find_min_colors(n, m, adj_matrix) == 3
def test_case_2():
n = 5
m = 4
... | [
{
"docstring": null,
"function_declaration": "def is_safe(node, color, graph, c):",
"function_name": "is_safe",
"parameter_list": "(node, color, graph, c)"
},
{
"docstring": null,
"function_declaration": "def graph_coloring_util(graph, m, color, node):",
"function_name": "graph_color... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_safe(node, color, graph, c):\n for i in range(len(graph)):\n if graph[node][i] == 1 and color[i] == c:\n return False\n return ... | trial_gpt4o_0 | {
"original_instruction": "Problem: You are given an undirected graph with n nodes and m edges. The graph is represented by an adjacency matrix. Your task is to determine the minimum number of colors required to color the graph such that no two adjacent nodes share the same color.\n\nA valid coloring assigns a color ... | 0.554345 | Codeforces_30636 | C | [
"is_safe",
"graph_coloring_util",
"min_colors",
"find_min_colors"
] | 4 | [
[
"find_min_colors",
"min_colors"
],
[
"graph_coloring_util",
"is_safe"
],
[
"min_colors",
"graph_coloring_util"
]
] | 3 | [] | false | [] | false | pytest | true | [] | true | 7e94c7b1f0ed7ac3e416ae36c582f45bed158675 | f714493e99351b635dedf435e8db1be6e1147f76 | |||
v1.0 | complete | Codeforces | Codeforces_31156_C | from collections import defaultdict
from typing import List, Tuple
def calculate_subtree_weights(n: int, weights: List[int], edges: List[Tuple[int, int]]) -> List[int]:
""" Calculate the weight of the subtree for each node.
"""
pass
def subtree_query(subtree_weights: List[int], queries: List[int]) -> List... | from collections import defaultdict
def calculate_subtree_weights(n, weights, edges):
tree = defaultdict(list)
for u, v in edges:
tree[u].append(v)
tree[v].append(u)
subtree_weights = [0] * (n + 1)
visited = [False] * (n + 1)
def dfs(node):
visited[node] = True
... | from solution import solve
def test_subtree_weights_case_1():
n = 5
q = 3
weights = [1, 2, 3, 4, 5]
edges = [(1, 2), (1, 3), (3, 4), (3, 5)]
queries = [1, 3, 4]
expected = [15, 12, 4]
assert solve(n, q, weights, edges, queries) == expected
def test_subtree_weights_case_2():
n = 3
q... | [
{
"docstring": null,
"function_declaration": "def calculate_subtree_weights(n, weights, edges):",
"function_name": "calculate_subtree_weights",
"parameter_list": "(n, weights, edges)"
},
{
"docstring": null,
"function_declaration": "def subtree_query(subtree_weights, queries):",
"fun... | [
0,
0,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def calculate_subtree_weights(n, weights, edges, queries):\n from collections import defaultdict, deque\n \n tree = defaultdict(list)\n subtree_we... | trial_gpt4o_2 | {
"original_instruction": "You are given a weighted tree with `n` vertices. The tree is rooted at vertex 1, and each vertex i has a weight `wi`. The weight of a subtree rooted at vertex `u` is the sum of weights of all vertices in that subtree.\n\nYour task is to handle `q` queries. In each query, you are given a ver... | 0.564441 | Codeforces_31156 | C | [
"calculate_subtree_weights",
"subtree_query",
"solve"
] | 3 | [
[
"solve",
"calculate_subtree_weights"
],
[
"solve",
"subtree_query"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 8d822537a7f5532aa51071902f35924d9ab94ffb | 0b58dd46f52c140d4a6e2193a95385c45f4f74a0 | |||
v1.0 | complete | Codeforces | Codeforces_30855_C | from typing import List, Tuple
def optimal_partition(n: int, residents: List[int], edges: List[Tuple[int, int, int]]) -> Tuple[int, int]:
"""
Find the optimal division of houses into two clusters such that the total road length
to connect all houses is minimized and the absolute difference in the number ... | class UnionFind:
def __init__(self, size):
self.parent = list(range(size))
self.rank = [0] * size
def find(self, u):
if self.parent[u] != u:
self.parent[u] = self.find(self.parent[u])
return self.parent[u]
def union(self, u, v):
root_u = self.find(u)
... | def test_optimal_partition():
n, m = 5, 7
residents = [10, 20, 30, 40, 50]
edges = [
(1, 2, 10),
(1, 3, 20),
(2, 3, 30),
(2, 4, 40),
(3, 4, 50),
(3, 5, 60),
(4, 5, 70)
]
assert optimal_partition(n, residents, edges) == (60, 10)
def test_single... | [] | [
0,
0,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import itertools\nimport heapq\n\ndef find_road_connections(n, m, residents, roads):\n # Step 1: Use Kruskal's algorithm to find the minimum spanning tree ... | trial_gpt4o_2 | {
"original_instruction": "There are several houses scattered in a city, connected by roads. Each house has a certain number of residents and each road has a certain length. You, as the city planner, want to ensure that all houses are connected in a way that minimizes the total road length while also balancing the po... | 0.571724 | Codeforces_30855 | C | [
"kruskal",
"min_diff_partition",
"optimal_partition"
] | 3 | [
[
"optimal_partition",
"kruskal"
],
[
"optimal_partition",
"min_diff_partition"
]
] | 2 | [] | false | [
"UnionFind"
] | true | pytest | false | [] | true | 0c4b7ba66aaeccd84e9492609ed009b488595667 | 21bcff6827aeaa867b4ca60ab350e82b72df4cda | |||
v1.0 | complete | Codeforces | Codeforces_31209_C | MOD = 10**9 + 7
def binomial_coefficient(n, k):
""" Calculate binomial coefficient C(n, k).
>>> binomial_coefficient(5, 2)
10
>>> binomial_coefficient(10, 5)
252
>>> binomial_coefficient(4, 2)
6
"""
# Implementation here
def catalan_number(n):
""" Calculate the nth Catalan numb... | MOD = 10**9 + 7
def binomial_coefficient(n, k):
if k > n - k:
k = n - k
res = 1
for i in range(k):
res = res * (n - i) // (i + 1)
return res
def catalan_number(n):
return binomial_coefficient(2 * n, n) // (n + 1)
def sum_of_catalan_numbers(n):
catalan_sum = 0
for i in rang... | from solution import binomial_coefficient, catalan_number, sum_of_catalan_numbers
def test_binomial_coefficient():
assert binomial_coefficient(5, 2) == 10
assert binomial_coefficient(10, 5) == 252
assert binomial_coefficient(4, 2) == 6
def test_catalan_number():
assert catalan_number(0) == 1
asser... | [
{
"docstring": null,
"function_declaration": "def binomial_coefficient(n, k):",
"function_name": "binomial_coefficient",
"parameter_list": "(n, k)"
},
{
"docstring": null,
"function_declaration": "def catalan_number(n):",
"function_name": "catalan_number",
"parameter_list": "(n)"... | [
0,
0,
0,
0,
0,
0,
1,
0,
0
] | 1 | hard | 0.111 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl",
"solution_code": "MOD = 10**9 + 7\n\ndef catalan_number(n):\n if n == 0 or n == 1:\n return 1\n cat = [0] * (n + 1)\n cat[0], cat[1] = 1, 1\n \n for i in ... | trial_gpt4o_7 | {
"original_instruction": "Masha loves combinatorial problems. She recently came across the concept of Catalan numbers, which are a sequence of natural numbers that appear in various counting problems. The nth Catalan number C(n) can be expressed directly in terms of binomial coefficients:\n\nC(n) = (1 / (n + 1)) * (... | 0.583081 | Codeforces_31209 | C | [
"binomial_coefficient",
"catalan_number",
"sum_of_catalan_numbers"
] | 3 | [
[
"catalan_number",
"binomial_coefficient"
],
[
"sum_of_catalan_numbers",
"catalan_number"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 6600c029a8fe375d8b94e26fa07652f9292b8356 | 21359f5feed816c01d86140cac72e406b81b261b | |||
v1.0 | complete | Codeforces | Codeforces_30865_C | from typing import List
def find_shortest_path(input_str: str) -> int:
"""
You are given a grid of size n x m where some cells contain obstacles and some cells are empty.
You start at the top-left corner of the grid, and your goal is to reach the bottom-right corner.
You can move to any of the adjacen... | from collections import deque
def shortest_path(grid, n, m):
directions = [(-1, 0), (1, 0), (0, -1), (0, 1)] # up, down, left, right
visited = [[False] * m for _ in range(n)]
queue = deque([(0, 0, 0)]) # (row, col, distance)
visited[0][0] = True
while queue:
r, c, dist = queue.popleft()
... | from solution import find_shortest_path
def test_shortest_path_1():
input_data = "3 3\n..#\n.#.\n..."
assert find_shortest_path(input_data) == 4
def test_shortest_path_2():
input_data = "3 3\n.#.\n###\n.#."
assert find_shortest_path(input_data) == -1
def test_shortest_path_3():
input_data = "1 1\... | [
{
"docstring": null,
"function_declaration": "def shortest_path(grid, n, m):",
"function_name": "shortest_path",
"parameter_list": "(grid, n, m)"
},
{
"docstring": null,
"function_declaration": "def parse_input(input_str):",
"function_name": "parse_input",
"parameter_list": "(inp... | [
1,
0,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from collections import deque\n\ndef shortest_path(grid, n, m):\n directions = [(-1, 0), (1, 0), (0, -1), (0, 1)] # up, down, left, right\n visited = [... | trial_gpt4o_0 | {
"original_instruction": "You are given a grid of size $$$n \\times m$$$ where some cells contain obstacles and some cells are empty. You start at the top-left corner of the grid, and your goal is to reach the bottom-right corner. \n\nYou can move to any of the adjacent cells in the directions up, down, left, or rig... | 0.723203 | Codeforces_30865 | C | [
"shortest_path",
"parse_input",
"find_shortest_path"
] | 3 | [
[
"find_shortest_path",
"parse_input"
],
[
"find_shortest_path",
"shortest_path"
]
] | 2 | [
"parse_input"
] | false | [] | false | pytest | true | [] | true | 6ce5310258d43419e8e9d2947e4439a1456c9f68 | 5c52005391300fe14dfb6d641138a669492d4315 | |||
v1.0 | complete | Codeforces | Codeforces_31284_C | def largest_rectangle_possible_barn(n: int, m: int, grid: List[str]) -> int:
""" Determine the area of the largest possible rectangular barn that can be built
on the farm without overlapping any tree cells.
>>> largest_rectangle_possible_barn(4, 5, [".....", ".T..T", ".....", "...T."])
6
>>> la... | def max_histogram_area(histogram):
stack = []
max_area = 0
index = 0
while index < len(histogram):
if not stack or histogram[stack[-1]] <= histogram[index]:
stack.append(index)
index += 1
else:
top_of_stack = stack.pop()
current_area = (hi... | def test_largest_rectangle_possible_barn():
assert largest_rectangle_possible_barn(4, 5, [
".....",
".T..T",
".....",
"...T."
]) == 6
assert largest_rectangle_possible_barn(3, 3, [
"...",
"T.T",
"..."
]) == 3
assert largest_rectangle_possible... | [
{
"docstring": null,
"function_declaration": "def max_histogram_area(histogram):",
"function_name": "max_histogram_area",
"parameter_list": "(histogram)"
},
{
"docstring": null,
"function_declaration": "def largest_rectangle_area(grid):",
"function_name": "largest_rectangle_area",
... | [
0,
0,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def largest_rectangle_in_farm(n, m, farm):\n def max_histogram_area(histogram):\n stack = []\n max_area = 0\n index = 0\n\n whi... | trial_gpt4o_2 | {
"original_instruction": "A farmer has a rectangular farm divided into $$$n \\times m$$$ grid cells. Some of these cells have trees planted in them, while others are empty. The farmer wants to build a rectangular barn on his farm such that none of the cells where the barn is built have trees.\n\nThe task is to deter... | 0.61073 | Codeforces_31284 | C | [
"max_histogram_area",
"largest_rectangle_area",
"largest_rectangle_possible_barn"
] | 3 | [
[
"largest_rectangle_area",
"max_histogram_area"
],
[
"largest_rectangle_possible_barn",
"largest_rectangle_area"
]
] | 2 | [] | false | [] | false | pytest | false | [] | true | 1a6056608c8224736a6c16f4967aed47c4fb8777 | bcedcd2aeec61a69621022a91d2989642e709c62 | |||
v1.0 | complete | Codeforces | Codeforces_31332_C | def largest_prime_factors(sequence: List[int]) -> List[int]:
""" Given a sequence of integers, replace each integer with its largest prime factor.
>>> largest_prime_factors([10, 15, 21, 33, 35, 49])
[5, 5, 7, 11, 7, 7]
>>> largest_prime_factors([2, 3, 5, 7, 11])
[2, 3, 5, 7, 11]
""" | def max_prime_factor(n):
"""
Returns the largest prime factor of a given number n.
"""
def is_prime(x):
if x <= 1:
return False
if x <= 3:
return True
if x % 2 == 0 or x % 3 == 0:
return False
i = 5
while i * i <= x:
... | from solution import largest_prime_factors
def test_single_element():
assert largest_prime_factors([10]) == [5]
def test_multiple_elements():
assert largest_prime_factors([10, 15, 21, 33, 35, 49]) == [5, 5, 7, 11, 7, 7]
def test_prime_numbers():
assert largest_prime_factors([2, 3, 5, 7, 11]) == [2, 3, 5,... | [
{
"docstring": "Returns the largest prime factor of a given number n.",
"function_declaration": "def max_prime_factor(n):",
"function_name": "max_prime_factor",
"parameter_list": "(n)"
},
{
"docstring": "Given a sequence of integers, replace each integer with its largest prime factor.",
... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def max_prime_factor(n):\n \"\"\"\n Returns the largest prime factor of a given number n.\n \"\"\"\n def is_prime(x):\n if x <= 1:\n ... | trial_gpt4o_0 | {
"original_instruction": "Vova loves prime numbers and prime factorization. One day, he was playing with arrays and prime numbers and came up with an interesting problem.\n\nVova is given a sequence of n integers, and he wants to create a new sequence by replacing each integer with its largest prime factor. Your tas... | 0.843168 | Codeforces_31332 | C | [
"max_prime_factor",
"largest_prime_factors"
] | 2 | [
[
"largest_prime_factors",
"max_prime_factor"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 2d23bdca4513e6f337bf2f15c30a692249e8b73a | dd1f8490b11671458ed0e2cd0bc2d369cabf9ffc | |||
v1.0 | complete | Codeforces | Codeforces_31324_C | def is_strong_password(password: str) -> str:
""" Determine if a single password is strong according to given criteria.
>>> is_strong_password("Pass1!")
"NO 2"
>>> is_strong_password("password")
"NO 3"
>>> is_strong_password("P@ssword1")
"YES"
"""
def check_passwords(n: int, passwords: ... | def is_strong_password(password):
special_characters = {'!', '@', '#', '$', '%', '^', '&', '*', '(', ')', '-', '+'}
has_upper = any(c.isupper() for c in password)
has_lower = any(c.islower() for c in password)
has_digit = any(c.isdigit() for c in password)
has_special = any(c in special_charact... | from solution import is_strong_password, check_passwords
def test_is_strong_password():
assert is_strong_password("Pass1!") == "NO 2"
def test_is_strong_password_all_missing():
assert is_strong_password("passwrd") == "NO 3"
assert is_strong_password("PASSWORD") == "NO 3"
assert is_strong_password("123... | [
{
"docstring": null,
"function_declaration": "def is_strong_password(password):",
"function_name": "is_strong_password",
"parameter_list": "(password)"
},
{
"docstring": null,
"function_declaration": "def check_passwords(n, passwords):",
"function_name": "check_passwords",
"param... | [
0,
0,
0,
0,
0,
0,
0,
0,
1
] | 1 | hard | 0.111 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import string\n\ndef is_strong_password(password):\n special_characters = {'!', '@', '#', '$', '%', '^', '&', '*', '(', ')', '-', '+'}\n \n has_upper... | trial_gpt4o_9 | {
"original_instruction": "Masha and Strong Passwords\n\nMasha wants to help teachers at her school create strong passwords for their accounts. She knows that for a password to be considered strong, it must meet the following criteria:\n1. It must be at least 8 characters long.\n2. It must contain at least one upperc... | 0.55933 | Codeforces_31324 | C | [
"is_strong_password",
"check_passwords"
] | 2 | [
[
"check_passwords",
"is_strong_password"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 77a793316cad64b0dcf78d4bedbf1d1cd9c71a4f | 60ffd8e92046b33e716ded55076e9282b1fa0302 | |||
v1.0 | complete | Codeforces | Codeforces_30953_C | def minimum_spanning_tree(n: int, m: int, pathways: List[Tuple[int, int, int]]) -> Union[int, str]:
"""
Determine the minimum total cost to connect all the cities in Codoria.
Args:
n (int): Number of cities.
m (int): Number of pathways.
pathways (List[Tuple[int, int, int]]): List of tuples each... | def find(parent, i):
if parent[i] == i:
return i
else:
return find(parent, parent[i])
def union(parent, rank, x, y):
root_x = find(parent, x)
root_y = find(parent, y)
if rank[root_x] < rank[root_y]:
parent[root_x] = root_y
elif rank[root_x] > rank[root_y]:
p... | from solution import minimum_spanning_tree
def test_case_1():
n, m = 4, 5
pathways = [
(1, 2, 3),
(2, 3, 4),
(1, 3, 1),
(1, 4, 6),
(3, 4, 2)
]
assert minimum_spanning_tree(n, m, pathways) == 6
def test_case_2():
n, m = 4, 4
pathways = [
(1, 2, 1)... | [
{
"docstring": null,
"function_declaration": "def find(parent, i):",
"function_name": "find",
"parameter_list": "(parent, i)"
},
{
"docstring": null,
"function_declaration": "def union(parent, rank, x, y):",
"function_name": "union",
"parameter_list": "(parent, rank, x, y)"
},
... | [
0,
0,
0,
0,
0,
1,
0,
0,
0,
0
] | 1 | hard | 0.1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_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(parent... | trial_gpt4o_5 | {
"original_instruction": "In the mystical land of Codoria, land developers have the formidable task of creating pathways between various cities. The cities are modeled as nodes, and the potential pathways between cities are modeled as weighted edges in a graph. The goal is to construct a connected, spanning path tha... | 0.645745 | Codeforces_30953 | C | [
"find",
"union",
"minimum_spanning_tree"
] | 3 | [
[
"minimum_spanning_tree",
"find"
],
[
"minimum_spanning_tree",
"union"
],
[
"union",
"find"
]
] | 3 | [] | false | [] | false | pytest | true | [] | true | 384fb9b738c32147cca51134cd330bcf2e1f957e | be5ccfe99159fc5a35a757678701239297be9751 | |||
v1.0 | complete | Codeforces | Codeforces_31246_C | def minimum_travel_time(n: int, m: int, roads: List[List[int]]) -> Union[int, str]:
""" Determine the minimum total travel time required to connect all bus stops.
If it's not possible to connect all the bus stops, return the string "Impossible".
>>> minimum_travel_time(4, 3, [[1, 2, 1], [2, 3, 1], [3, ... | # Implementation of Kruskal's Algorithm to find Minimum Spanning Tree (MST)
def find_parent(parent, i):
if parent[i] == i:
return i
else:
return find_parent(parent, parent[i])
def union(parent, rank, x, y):
root_x = find_parent(parent, x)
root_y = find_parent(parent, y)
if rank... | import pytest
from solution import minimum_travel_time
def test_minimum_travel_time_sample1():
assert minimum_travel_time(4, 3, [[1, 2, 1], [2, 3, 1], [3, 4, 1]]) == 3
def test_minimum_travel_time_sample2():
assert minimum_travel_time(4, 2, [[1, 2, 1], [2, 3, 1]]) == "Impossible"
def test_minimum_travel_time... | [
{
"docstring": null,
"function_declaration": "def find_parent(parent, i):",
"function_name": "find_parent",
"parameter_list": "(parent, i)"
},
{
"docstring": null,
"function_declaration": "def union(parent, rank, x, y):",
"function_name": "union",
"parameter_list": "(parent, rank... | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def minimum_total_travel_time(n, m, roads):\n \"\"\"\n Determines the minimum total travel time required to connect all bus stops using Kruskal's algori... | trial_gpt4o_1 | {
"original_instruction": "Programming contests often require participants to flex their algorithm and logic muscles in solving unique and challenging problems. Below is a new problem that aligns with the given examples in terms of style, complexity, and scope:\n\nA popular transportation company is planning a new bu... | 0.686965 | Codeforces_31246 | C | [
"find_parent",
"union",
"minimum_travel_time"
] | 3 | [
[
"minimum_travel_time",
"find_parent"
],
[
"minimum_travel_time",
"union"
],
[
"union",
"find_parent"
]
] | 3 | [] | false | [] | false | pytest | true | [] | true | df061181fd725cc9bbb221925211ae778cf45088 | a068a2f070a5c051448e3377c9990adc5ca137a2 | |||
v1.0 | complete | Codeforces | Codeforces_31518_C | def final_integer(n: int, sequence: List[int]) -> int:
""" Perform the described operation repeatedly until the sequence becomes a single integer.
:param n: length of the sequence
:param sequence: list of integers in the sequence
:return: the final integer after performing the operations
>... | def perform_operation(sequence):
"""
Repeatedly performs the described operation until the sequence becomes a single integer.
"""
while len(sequence) > 1:
# Find the median of the entire sequence
sorted_sequence = sorted(sequence)
median_index = len(sorted_sequence) // 2
... | from solution import final_integer
def test_example_case():
assert final_integer(5, [3, 1, 2, 4, 6]) == 3
def test_single_element():
assert final_integer(1, [5]) == 5
def test_two_median_choices():
assert final_integer(7, [3, 1, 2, 4, 6, 7, 8]) == 4
def test_negative_numbers():
assert final_integer(... | [
{
"docstring": "Repeatedly performs the described operation until the sequence becomes a single integer.",
"function_declaration": "def perform_operation(sequence):",
"function_name": "perform_operation",
"parameter_list": "(sequence)"
},
{
"docstring": null,
"function_declaration": "def... | [
0,
0,
0,
0,
0,
0,
1,
1,
0,
0
] | 2 | hard | 0.2 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def find_final_integer(n, sequence):\n from heapq import heappush, heappop\n import heapq\n \n def compute_median(seq):\n min_heap, max_hea... | trial_gpt4o_7 | {
"original_instruction": "You are given a sequence of integers a1, a2, ..., an. We define an operation as follows: for a given odd-length subsequence of length k, replace the subsequence with its median. The median of a subsequence is the element that would be in the middle if the subsequence were sorted. If multipl... | 0.625289 | Codeforces_31518 | C | [
"perform_operation",
"final_integer"
] | 2 | [
[
"final_integer",
"perform_operation"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 208d87cc155b0c3b335542578951bdcb842f72ac | c4d82c4f5b46d6475424bf0c216c807538a8043a | |||
v1.0 | complete | Codeforces | Codeforces_31321_C | def min_total_length_of_cables(n: int, m: int, cables: List[Tuple[int, int, int]]) -> int:
"""Help Alice find the minimum total length of cables required to connect all computers in the network.
Args:
n (int): The number of computers.
m (int): The number of cables.
cables (List[Tuple[int, int, ... | def find(parent, i):
if parent[i] == i:
return i
else:
return find(parent, parent[i])
def union(parent, rank, x, y):
root_x = find(parent, x)
root_y = find(parent, y)
if rank[root_x] < rank[root_y]:
parent[root_x] = root_y
elif rank[root_x] > rank[root_y]:
... | from solution import min_total_length_of_cables
def test_example_case():
n = 4
m = 4
cables = [
(1, 2, 3),
(2, 3, 1),
(3, 4, 4),
(4, 1, 2)
]
assert min_total_length_of_cables(n, m, cables) == 6
def test_disconnected_case():
n = 4
m = 1
cables = [
... | [
{
"docstring": null,
"function_declaration": "def find(parent, i):",
"function_name": "find",
"parameter_list": "(parent, i)"
},
{
"docstring": null,
"function_declaration": "def union(parent, rank, x, y):",
"function_name": "union",
"parameter_list": "(parent, rank, x, y)"
},
... | [
0,
1,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl",
"solution_code": "class DisjointSetUnion:\n def __init__(self, n):\n self.parent = list(range(n))\n self.rank = [1] * n\n\n def find(self, u):\n if s... | trial_gpt4o_1 | {
"original_instruction": "Alice has recently built a network of computers in her office. The network consists of `n` computers connected by `m` cables. Each cable has a certain length associated with it. Alice wants to ensure that a message can be sent from any computer to any other computer in the network. Due to b... | 0.579787 | Codeforces_31321 | C | [
"find",
"union",
"kruskal",
"min_total_length_of_cables"
] | 4 | [
[
"kruskal",
"find"
],
[
"kruskal",
"union"
],
[
"min_total_length_of_cables",
"kruskal"
],
[
"union",
"find"
]
] | 4 | [] | false | [] | false | pytest | true | [] | true | 3901e7cb45dea4035eb08d288667417b40c8afe9 | 75d6d5b3a8f5873936763ae3b59399dc2e5457ee | |||
v1.0 | complete | Codeforces | Codeforces_31096_C | from collections import deque
def find_max_within_distance(n, values, edges, queries):
"""
You are given a tree (connected acyclic undirected graph) with n vertices labeled 1 through n. Each vertex has a positive integer value associated with it. Your task is to perform q queries of the following type: find th... | from collections import deque
def find_max_within_distance(n, values, edges, queries):
# Build the adjacency list for the graph
graph = {i: [] for i in range(1, n + 1)}
for a, b in edges:
graph[a].append(b)
graph[b].append(a)
def bfs_max_value(start, distance):
visited = {s... | def test_example():
n = 5
values = [5, 3, 6, 2, 9]
edges = [(1, 2), (1, 3), (3, 4), (3, 5)]
q = 3
queries = [(1, 2), (4, 1), (5, 0)]
expected_result = [9, 6, 9]
assert solve(n, values, edges, q, queries) == expected_result
def test_single_node():
n = 1
values = [10]
edges =... | [
{
"docstring": null,
"function_declaration": "def find_max_within_distance(n, values, edges, queries):",
"function_name": "find_max_within_distance",
"parameter_list": "(n, values, edges, queries)"
},
{
"docstring": null,
"function_declaration": "def solve(n, values, edges, q, queries):"... | [
1,
1,
0
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from collections import deque, defaultdict\n\ndef bfs_max_value(tree, values, start, distance):\n n = len(values)\n visited = [False] * (n + 1)\n que... | trial_gpt4o_1 | {
"original_instruction": "You are given a tree (connected acyclic undirected graph) with n vertices labeled 1 through n. Each vertex has a positive integer value associated with it. Your task is to perform q queries of the following type: find the maximum value among all vertices within a given distance d from a spe... | 0.736545 | Codeforces_31096 | C | [
"find_max_within_distance",
"solve"
] | 2 | [
[
"solve",
"find_max_within_distance"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | baf9388bafbb476f995019f91c52d8dec9262174 | 8018b30a6b50f1844dd9420dc5c7173f50565791 | |||
v1.0 | complete | Codeforces | Codeforces_31676_C | import math
from functools import reduce
def gcd_multiple(numbers):
"""
Returns the GCD of a list of numbers.
"""
pass
def max_friends(n, candies):
"""
Returns the maximum number of friends Alice can distribute the candies to.
>>> max_friends(5, [20, 50, 30, 40, 70]) == 10
>>> max_frie... | import math
from functools import reduce
def gcd_multiple(numbers):
"""
Returns the GCD of a list of numbers.
"""
return reduce(math.gcd, numbers)
def max_friends(n, candies):
"""
Returns the maximum number of friends Alice can distribute the candies to.
"""
return gcd_multiple(candies... | from solution import max_friends
def test_single_balloon():
assert max_friends(1, [10]) == 10
def test_two_balloons():
assert max_friends(2, [10, 20]) == 10
def test_multiple_balloons():
assert max_friends(3, [12, 15, 18]) == 3
assert max_friends(5, [20, 50, 30, 40, 70]) == 10
def test_no_common_div... | [
{
"docstring": "Returns the GCD of a list of numbers.",
"function_declaration": "def gcd_multiple(numbers):",
"function_name": "gcd_multiple",
"parameter_list": "(numbers)"
},
{
"docstring": "Returns the maximum number of friends Alice can distribute the candies to.",
"function_declarati... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from math import gcd\nfrom functools import reduce\n\ndef max_friends_from_candies(numbers):\n \"\"\"\n Returns the maximum number of friends such that ... | trial_gpt4o_2 | {
"original_instruction": "Alice has a collection of balloons, each with a certain number of candies inside. Alice wants to distribute the candies among her friends in such a way that each friend gets the same number of candies and each balloon is used completely. She can choose any number of friends (at least one). ... | 0.577485 | Codeforces_31676 | C | [
"gcd_multiple",
"max_friends"
] | 2 | [
[
"max_friends",
"gcd_multiple"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | db9fea4ab8f16834778e872b1a758b5425c01ff4 | 41d65bf4889413f5b43ac5ef8e44b69b1589963d | |||
v1.0 | complete | Codeforces | Codeforces_31405_C | def max_histogram_area(heights):
""" Helper function to compute the maximum rectangular area in a histogram.
>>> max_histogram_area([2, 1, 5, 6, 2, 3]) 10
>>> max_histogram_area([6, 2, 5, 4, 5, 1, 6]) 12
"""
def max_rectangle_area(matrix):
""" Determine the area of the largest rectangle contain... | def max_histogram_area(heights):
stack = []
max_area = 0
index = 0
while index < len(heights):
if not stack or heights[stack[-1]] <= heights[index]:
stack.append(index)
index += 1
else:
top_of_stack = stack.pop()
area = (heights[top_of_stac... | def test_single_row():
matrix = [[1, 0, 1, 1, 1]]
assert max_rectangle_area(matrix) == 3
def test_single_column():
matrix = [[1], [1], [0], [1]]
assert max_rectangle_area(matrix) == 2
def test_mixed_grid():
matrix = [
[1, 0, 1, 0, 0],
[1, 0, 1, 1, 1],
[1, 1, 1, 1, 1],
... | [
{
"docstring": null,
"function_declaration": "def max_histogram_area(heights):",
"function_name": "max_histogram_area",
"parameter_list": "(heights)"
},
{
"docstring": null,
"function_declaration": "def max_rectangle_area(matrix):",
"function_name": "max_rectangle_area",
"paramet... | [
1,
1,
0
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def maximalRectangle(matrix):\n if not matrix:\n return 0\n \n n, m = len(matrix), len(matrix[0])\n max_area = 0\n heights = [0] * m\n ... | trial_gpt4o_1 | {
"original_instruction": "Farmer John owns a piece of land that can be represented as an n x m grid. Each cell in the grid is either fertile or infertile. Farmer John wants to plant a single rectangular crop field on the land, and he wants the field to be as large as possible while only containing fertile cells.\n\n... | 0.571074 | Codeforces_31405 | C | [
"max_histogram_area",
"max_rectangle_area"
] | 2 | [
[
"max_rectangle_area",
"max_histogram_area"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | 7377a65a2f0ae18398cc5668dae7a3714131749c | b9054d04f0befe2181393dcedaaf70d5fb53d26f | |||
v1.0 | complete | Codeforces | Codeforces_31639_C | def min_cost_to_connect_cities(n: int, m: int, edges: List[Tuple[int, int, int]]) -> Union[int, str]:
""" Determine the minimum cost to connect all cities such that there is at least one path between any two cities.
This is known as finding the Minimum Spanning Tree (MST) of the graph.
If it is impossible t... | def find(parent, i):
if parent[i] == i:
return i
else:
return find(parent, parent[i])
def union(parent, rank, x, y):
xroot = find(parent, x)
yroot = find(parent, y)
if rank[xroot] < rank[yroot]:
parent[xroot] = yroot
elif rank[xroot] > rank[yroot]:
parent[y... | import pytest
from solution import min_cost_to_connect_cities
def test_sample_1():
n = 4
m = 5
edges = [
(1, 2, 1),
(1, 3, 3),
(1, 4, 4),
(2, 3, 2),
(3, 4, 5),
]
assert min_cost_to_connect_cities(n, m, edges) == 7
def test_sample_2():
n = 2
m = 1
... | [
{
"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_codeforces-i2i_20000_1739005484_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 xroot... | trial_gpt4o_1 | {
"original_instruction": "You are given a number of cities connected by bidirectional roads. Each road has a certain length. You need to determine the minimum cost to connect all the cities such that there is at least one path between any two cities. This is known as finding the Minimum Spanning Tree (MST) of the gr... | 0.692248 | Codeforces_31639 | C | [
"find",
"union",
"min_cost_to_connect_cities"
] | 3 | [
[
"min_cost_to_connect_cities",
"find"
],
[
"min_cost_to_connect_cities",
"union"
],
[
"union",
"find"
]
] | 3 | [] | false | [] | false | pytest | true | [] | true | 0399a13247e9c4775b5a8be1a00963c2aec51b8e | 08dc7e07b6975ed973ab87ab3b2c91e7eb05174c | |||
v1.0 | complete | Codeforces | Codeforces_31204_C | def find_min_highway_length_and_roads(n, m, roads):
"""
In a certain country, there are n cities connected by m bidirectional roads. Each road has a positive length given
in kilometers. The cities want to establish a network of highways such that every city is accessible from any
other city directly o... | class UnionFind:
"""Union-Find data structure (Disjoint Set Union) with path compression and union by rank."""
def __init__(self, n):
self.parent = list(range(n))
self.rank = [0] * n
def find(self, u):
if self.parent[u] != u:
self.parent[u] = self.find(self.parent[u]) #... | from solution import find_min_highway_length_and_roads
def test_example():
n, m = 4, 5
roads = [
(1, 2, 1),
(2, 3, 2),
(1, 3, 2),
(1, 4, 3),
(3, 4, 4)
]
expected_length = 6
expected_roads = [(1, 2), (2, 3), (1, 4)]
total_length, mst_edges = find_min_high... | [] | [
1,
0
] | 1 | medium | 0.5 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl",
"solution_code": "class UnionFind:\n \"\"\"Union-Find data structure (Disjoint Set Union) with path compression and union by rank.\"\"\"\n def __init__(self, n):\n ... | trial_gpt4o_0 | {
"original_instruction": "In a certain country, there are n cities connected by m bidirectional roads. Each road has a positive length given in kilometers. The cities want to establish a network of highways such that every city is accessible from any other city directly or indirectly through these highways. Addition... | 0.713526 | Codeforces_31204 | C | [
"kruskal",
"find_min_highway_length_and_roads"
] | 2 | [
[
"find_min_highway_length_and_roads",
"kruskal"
]
] | 1 | [] | false | [
"UnionFind"
] | true | pytest | true | [] | true | 95be10b78e10120602fe19543a34ab391ab2f719 | 86192d34b7ec5f6bd587ec07973bae1b810edfae | |||
v1.0 | complete | Codeforces | Codeforces_31994_C | def maximum_subsequence_sum(cards):
""" Returns the maximum subsequence sum after performing at most one swap and/or one subsequence reversal.
>>> maximum_subsequence_sum([10])
10
>>> maximum_subsequence_sum([-10])
0
>>> maximum_subsequence_sum([3, -1, 4, -2, 5])
12
>>> maximum_subsequen... | def maximum_subsequence_sum(cards):
"""
Returns the maximum subsequence sum after performing at most one swap and/or one subsequence reversal.
"""
# Optimal sub-sequence sum in the original array
max_sum = max_subsequence_sum(cards)
n = len(cards)
# Trying all possible single swaps... | from solution import maximum_subsequence_sum
def test_single_positive_number():
assert maximum_subsequence_sum([10]) == 10
def test_single_negative_number():
assert maximum_subsequence_sum([-10]) == 0
def test_multiple_mixed_numbers():
assert maximum_subsequence_sum([3, -1, 4, -2, 5]) == 12
def test_all... | [
{
"docstring": "Returns the maximum subsequence sum after performing at most one swap and/or one subsequence reversal.",
"function_declaration": "def maximum_subsequence_sum(cards):",
"function_name": "maximum_subsequence_sum",
"parameter_list": "(cards)"
},
{
"docstring": "Helper function t... | [
0,
0,
0,
0,
0,
0,
0,
1,
0,
0
] | 1 | hard | 0.1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def max_subsequence_sum(cards):\n \"\"\"\n Given the list of card power levels, this function returns the maximum sum\n of any subsequence after perf... | trial_gpt4o_7 | {
"original_instruction": "Sam is playing a digital card game where each card has a power level represented by an integer. He wants to maximize his score by arranging the cards in a specific order. Sam can make two moves to rearrange the cards:\n1. Swap the positions of any two cards.\n2. Reverse the sub-sequence of ... | 0.643974 | Codeforces_31994 | C | [
"maximum_subsequence_sum",
"max_subsequence_sum"
] | 2 | [
[
"maximum_subsequence_sum",
"max_subsequence_sum"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 420391ddd71a43e543431eb5041f2ba195cd2738 | 591d5625230b584654f0ff303a2b6d0ea30e0c69 | |||
v1.0 | complete | Codeforces | Codeforces_31825_C | from collections import defaultdict, deque
def find_maximum_containers(n: int, m: int, k: int, routes: List[Tuple[int, int, int]], s: int, t: int) -> int:
"""
Find the maximum number of containers that can be shipped from the source city to the destination city per day.
Args:
n (int): the number o... | from collections import defaultdict, deque
def bfs_capacity(graph, source, sink, parent):
visited = set()
queue = deque([(source, float('Inf'))])
while queue:
current_node, flow = queue.popleft()
if current_node not in visited:
visited.add(current_node)
... | from solution import find_maximum_containers
def test_example_case():
n, m, k = 4, 5, 10
routes = [(1, 2, 5), (1, 3, 5), (2, 4, 3), (3, 4, 2), (2, 3, 2)]
s, t = 1, 4
assert find_maximum_containers(n, m, k, routes, s, t) == 5
def test_case_with_insufficient_capacity():
n, m, k = 4, 5, 15
routes... | [
{
"docstring": null,
"function_declaration": "def bfs_capacity(graph, source, sink, parent):",
"function_name": "bfs_capacity",
"parameter_list": "(graph, source, sink, parent)"
},
{
"docstring": null,
"function_declaration": "def max_flow(graph, source, sink):",
"function_name": "ma... | [
0,
0,
0,
0,
0,
0,
0,
1,
0,
1
] | 2 | hard | 0.2 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import collections \nimport heapq\n\ndef max_flow(n, m, k, edges, s, t):\n def dikjstra(source, sink, parent):\n dist = [float('inf')] * (n + 1)\n ... | trial_gpt4o_7 | {
"original_instruction": "You are a developer for a logistics company that wants to optimize the allocation of shipping containers on various routes. Each route connects two cities and has a capacity that indicates the maximum number of containers it can handle per day.\n\nYour task is to find the maximum number of ... | 0.6569 | Codeforces_31825 | C | [
"bfs_capacity",
"max_flow",
"find_maximum_containers"
] | 3 | [
[
"find_maximum_containers",
"max_flow"
],
[
"max_flow",
"bfs_capacity"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 1e63bf11a87b443b38f0dd6c6196f1abf1f61644 | b9deae3ffb15b88e14d9bb2a5a11e850f362130d | |||
v1.0 | complete | Codeforces | Codeforces_32078_C | from typing import List, Tuple
def minimum_meeting_distance(N: int, M: int, L: int, A: int, B: int, roads: List[Tuple[int, int]]) -> int:
""" Calculate the minimum distance both Alice and Bob have to travel to meet at a common intersection.
>>> minimum_meeting_distance(5, 5, 2, 1, 3, [(1, 2), (2, 3), (3, 4), (... | from collections import deque
def bfs(start, N, adj):
dist = [-1] * (N + 1)
dist[start] = 0
queue = deque([start])
while queue:
u = queue.popleft()
for v in adj[u]:
if dist[v] == -1:
dist[v] = dist[u] + 1
queue.append(v)
return dist
def m... | from solution import minimum_meeting_distance
def test_example_case():
N = 5
M = 5
L = 2
A = 1
B = 3
roads = [(1, 2), (2, 3), (3, 4), (4, 5), (5, 1)]
assert minimum_meeting_distance(N, M, L, A, B, roads) == 4
def test_no_meeting_point():
N = 5
M = 3
L = 2
A = 1
B = 5
... | [
{
"docstring": null,
"function_declaration": "def bfs(start, N, adj):",
"function_name": "bfs",
"parameter_list": "(start, N, adj)"
},
{
"docstring": null,
"function_declaration": "def minimum_meeting_distance(N, M, L, A, B, roads):",
"function_name": "minimum_meeting_distance",
... | [
0,
0,
0,
0,
1
] | 1 | hard | 0.2 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from collections import deque, defaultdict\n\ndef bfs(start, n, adj_list):\n \"\"\"\n Perform Breadth-First Search (BFS) from the start node to compute ... | trial_gpt4o_4 | {
"original_instruction": "In a city, there are `N` intersections connected by `M` bidirectional roads. Each road has a length `L`. Two people, Alice and Bob, live at different intersections and want to meet at the same place. They want to find the shortest distance they each must travel to meet at a common intersect... | 0.6449 | Codeforces_32078 | C | [
"bfs",
"minimum_meeting_distance"
] | 2 | [
[
"minimum_meeting_distance",
"bfs"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 6590b531b2440a168aa783e70e0a4aebe2835eee | 171a0edb50b24a67e6fef2e78317785c065691cb | |||
v1.0 | complete | Codeforces | Codeforces_32307_C | def committee_group_size(n: int, edges: List[Tuple[int, int]], queries: List[Tuple[int, int]]) -> List[int]:
""" Determine the size of each committee group for given queries in a hierarchical tree structure.
Args:
n (int): Number of workers in the corporation.
edges (List[Tuple[int, int]]):... | def find_lca_and_depths(n, edges):
from collections import defaultdict, deque
tree = defaultdict(list)
for a, b in edges:
tree[a].append(b)
tree[b].append(a)
depth = [-1] * (n + 1)
parent = [-1] * (n + 1)
def bfs():
queue = deque([1])
depth[1] =... | def test_committee_group_size():
edges = [
(1, 2),
(1, 3),
(3, 4),
(3, 5)
]
queries = [
(2, 4),
(2, 5),
(4, 5)
]
expected_result = [4, 4, 3]
result = committee_group_size(5, edges, queries)
assert result == expected_result, f"Expec... | [
{
"docstring": null,
"function_declaration": "def find_lca_and_depths(n, edges):",
"function_name": "find_lca_and_depths",
"parameter_list": "(n, edges)"
},
{
"docstring": null,
"function_declaration": "def committee_group_size(n, edges, queries):",
"function_name": "committee_group_... | [
1,
0,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def find_lca_and_depths(n, edges):\n from collections import defaultdict, deque\n \n tree = defaultdict(list)\n for a, b in edges:\n tree[a... | trial_gpt4o_0 | {
"original_instruction": "In Berland, a special type of employee hierarchy is being used in their futuristic corporations. The corporations are organized as a tree, where each worker except the CEO (highest authority) has exactly one immediate supervisor. Given this hierarchy, workers tend to form different committe... | 0.514267 | Codeforces_32307 | C | [
"find_lca_and_depths",
"committee_group_size"
] | 2 | [
[
"committee_group_size",
"find_lca_and_depths"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | 1f0bdbefc4b35bc22ef14a3f21f3cc0635f3c0c2 | 9c1203789e693830cc299506694d2938731f4224 | |||
v1.0 | complete | Codeforces | Codeforces_31614_C | from typing import List, Tuple
def compute_prefix_sum(grid: List[List[int]], n: int, m: int) -> List[List[int]]:
"""
Compute the prefix sum matrix for a given grid.
"""
pass
def submatrix_sum(prefix_sum: List[List[int]], x1: int, y1: int, x2: int, y2: int) -> int:
"""
Calculate the sum of the ... | def compute_prefix_sum(grid, n, m):
"""
Computes the prefix sum matrix for a given grid.
"""
prefix_sum = [[0] * (m + 1) for _ in range(n + 1)]
for i in range(1, n + 1):
for j in range(1, m + 1):
prefix_sum[i][j] = (grid[i-1][j-1] +
prefix_sum... | from solution import compute_prefix_sum, submatrix_sum, process_queries
def test_compute_prefix_sum():
grid = [
[1, 2, 3],
[4, 5, 6],
[7, 8, 9]
]
expected_prefix_sum = [
[0, 0, 0, 0],
[0, 1, 3, 6],
[0, 5, 12, 21],
[0, 12, 27, 45]
]
assert comp... | [
{
"docstring": "Computes the prefix sum matrix for a given grid.",
"function_declaration": "def compute_prefix_sum(grid, n, m):",
"function_name": "compute_prefix_sum",
"parameter_list": "(grid, n, m)"
},
{
"docstring": "Calculates the sum of the submatrix from (x1, y1) to (x2, y2) using the... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def preprocess_matrix(matrix, n, m):\n \"\"\"\n Preprocess the given matrix to create a prefix sum matrix.\n \"\"\"\n prefix_sum = [[0] * (m + 1) ... | trial_gpt4o_2 | {
"original_instruction": "You are given a 2D grid of size $$$n \\times m$$$ filled with integers. Your goal is to answer $$$q$$$ queries. Each query contains two coordinates, $$$(x_1, y_1)$$$ and $$$(x_2, y_2)$$$, which represent a submatrix of the grid with top-left corner $$$(x_1, y_1)$$$ and bottom-right corner $... | 0.579934 | Codeforces_31614 | C | [
"compute_prefix_sum",
"submatrix_sum",
"process_queries"
] | 3 | [
[
"process_queries",
"compute_prefix_sum"
],
[
"process_queries",
"submatrix_sum"
]
] | 2 | [
"process_queries"
] | false | [] | false | pytest | true | [] | true | 4d05ccb07e532588452606d2e0ba58254024e4eb | 59d0c4e53d903522845c4ba6c99ce7f0f843cbc1 | |||
v1.0 | complete | Codeforces | Codeforces_31997_C | from typing import List, Tuple
from collections import defaultdict, deque
def tree_diameter(n: int, edges: List[Tuple[int, int, int]]) -> int:
"""
Compute the diameter of the tree.
Args:
n: An integer - number of vertices in the tree.
edges: A list of tuples (u, v, w) where u and v are vertic... | from collections import defaultdict, deque
def find_farthest_node(start, graph, n):
visited = [False] * (n + 1)
distances = [-1] * (n + 1)
distances[start] = 0
queue = deque([start])
farthest_node = start
max_distance = 0
while queue:
current = queue.popleft()
visited[... | def test_example_case():
edges = [(1, 2, 3), (1, 3, 2), (3, 4, 4), (3, 5, 2)]
assert tree_diameter(5, edges) == 9
def test_single_path():
edges = [(1, 2, 1)]
assert tree_diameter(2, edges) == 1
def test_all_nodes_connected_in_line():
edges = [(1, 2, 1), (2, 3, 1), (3, 4, 1)]
assert tree_diamet... | [
{
"docstring": null,
"function_declaration": "def find_farthest_node(start, graph, n):",
"function_name": "find_farthest_node",
"parameter_list": "(start, graph, n)"
},
{
"docstring": null,
"function_declaration": "def tree_diameter(n, edges):",
"function_name": "tree_diameter",
... | [
0,
0,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import collections\n\ndef find_tree_diameter(n, edges):\n if n == 1:\n return 0\n\n def bfs(start_node):\n distances = [-1] * (n + 1)\n ... | trial_gpt4o_2 | {
"original_instruction": "Vanya has recently started learning about graphs. A graph consists of vertices connected by edges. He learned that a tree is a special type of graph that is connected and acyclic, meaning there is exactly one path between any two vertices. Vanya is given an undirected tree with `n` vertices... | 0.652716 | Codeforces_31997 | C | [
"find_farthest_node",
"tree_diameter"
] | 2 | [
[
"tree_diameter",
"find_farthest_node"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | b5ffaefbf4e7a359413d41c84fbdb565326d7b50 | 2ad821dbdbd9185c43eb0fd86e7dae4ba0ae1adc | |||
v1.0 | complete | Codeforces | Codeforces_32223_C | def is_beautiful_subgrid(grid, top_row, bottom_row, left_col, right_col):
""" Check if a subgrid is beautiful.
>>> is_beautiful_subgrid(["abc", "def", "ghi"], 0, 0, 0, 2)
True
>>> is_beautiful_subgrid(["aab", "bcc", "cdd"], 0, 0, 0, 2)
False
"""
def find_largest_beautiful_subgrid(n, m, grid... | def is_beautiful_subgrid(grid, top_row, bottom_row, left_col, right_col):
for i in range(top_row, bottom_row + 1):
if len(set(grid[i][left_col:right_col + 1])) < (right_col - left_col + 1):
return False
return True
def find_largest_beautiful_subgrid(n, m, grid):
max_area = 0
best_to... | from solution import is_beautiful_subgrid, find_largest_beautiful_subgrid
def test_is_beautiful_subgrid():
grid1 = [
"abc",
"def",
"ghi"
]
assert is_beautiful_subgrid(grid1, 0, 0, 0, 2) == True # Single row, all unique
assert is_beautiful_subgrid(grid1, 0, 1, 0, 2) == True... | [
{
"docstring": null,
"function_declaration": "def is_beautiful_subgrid(grid, top_row, bottom_row, left_col, right_col):",
"function_name": "is_beautiful_subgrid",
"parameter_list": "(grid, top_row, bottom_row, left_col, right_col)"
},
{
"docstring": null,
"function_declaration": "def fin... | [
1,
0,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_beautiful_subgrid(grid, top_row, bottom_row, left_col, right_col):\n for i in range(top_row, bottom_row + 1):\n if len(set(grid[i][left_col:r... | trial_gpt4o_0 | {
"original_instruction": "You are given a 2D grid of size $$$n \\times m$$$ where each cell contains a single lower-case letter. A subgrid is a rectangular section of the grid that includes some rows and some columns. A subgrid is considered beautiful if each row in the subgrid contains all unique characters.\n\nYou... | 0.552238 | Codeforces_32223 | C | [
"is_beautiful_subgrid",
"find_largest_beautiful_subgrid"
] | 2 | [
[
"find_largest_beautiful_subgrid",
"is_beautiful_subgrid"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | a83338adbab812afa115c74f2be28243d09de9fc | f946a231598375690cb440313181cc7656beeee0 | |||
v1.0 | complete | Codeforces | Codeforces_32146_C | import heapq
from typing import List, Tuple
def dijkstra(graph: List[List[Tuple[int, int]]], start: int, n: int) -> List[int]:
""" Implements Dijkstra's algorithm to find the shortest paths from the start node to all other nodes in the graph.
>>> dijkstra([[], [(2, 2), (3, 6), (4, 10)], [(1, 2), (3, 3)], [(2, ... | import heapq
def dijkstra(graph, start, n):
distances = {node: float('infinity') for node in range(1, n + 1)}
distances[start] = 0
pq = [(0, start)]
while pq:
current_distance, current_node = heapq.heappop(pq)
if current_distance > distances[current_node]:
cont... | import pytest
def test_shortest_path_with_new_road():
assert shortest_path_with_new_road(5, 7, 1, 5,
[(1, 2, 2), (2, 3, 3), (3, 4, 4), (4, 5, 5), (1, 3, 6), (1, 4, 10), (3, 5, 1)],
(2, 5, 2)) == 4
assert shortest_path_with_new_road(... | [
{
"docstring": null,
"function_declaration": "def dijkstra(graph, start, n):",
"function_name": "dijkstra",
"parameter_list": "(graph, start, n)"
},
{
"docstring": null,
"function_declaration": "def shortest_path_with_new_road(n, m, s, d, roads, new_road):",
"function_name": "shortes... | [
1,
0
] | 1 | medium | 0.5 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import heapq\n\ndef dijkstra(graph, start, n):\n distances = {node: float('infinity') for node in range(1, n + 1)}\n distances[start] = 0\n pq = [(0,... | trial_gpt4o_0 | {
"original_instruction": "In a distant land, there exists a kingdom named Graphonia. The kingdom consists of N cities connected by a network of M bidirectional roads. Each road connects two cities and has a certain travel time associated with it. The king of Graphonia wishes to make communication as efficient as pos... | 0.706714 | Codeforces_32146 | C | [
"dijkstra",
"shortest_path_with_new_road"
] | 2 | [
[
"shortest_path_with_new_road",
"dijkstra"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | da13b52d99f87ae3baee8529374cdcbf716b0799 | 5e8484ac4fcd4bcaefe3635f28539abb5530aea2 | |||
v1.0 | complete | Codeforces | Codeforces_32006_C | from typing import List, Tuple
def find_optimal_capital(n: int, edges: List[Tuple[int, int]]) -> List[int]:
"""
In a fantasy kingdom, there are n cities connected by n-1 bidirectional roads, forming a tree. Each city has a unique
integer identifier from 1 to n. The King of this kingdom wants to establish a... | from collections import defaultdict, deque
def find_tree_diameter(n, edges):
# Build adjacency list
graph = defaultdict(list)
for u, v in edges:
graph[u].append(v)
graph[v].append(u)
# Helper function to perform BFS and return the farthest node and its distance
def bfs(start):
... | from solution import find_optimal_capital
def test_find_optimal_capital():
assert find_optimal_capital(6, [(1, 2), (1, 3), (2, 4), (2, 5), (3, 6)]) == [1]
assert find_optimal_capital(4, [(1, 2), (2, 3), (3, 4)]) == [2, 3]
assert find_optimal_capital(7, [(1, 2), (1, 3), (2, 4), (2, 5), (4, 6), (4, 7)]) == [... | [
{
"docstring": null,
"function_declaration": "def find_tree_diameter(n, edges):",
"function_name": "find_tree_diameter",
"parameter_list": "(n, edges)"
},
{
"docstring": null,
"function_declaration": "def find_optimal_capital(n, edges):",
"function_name": "find_optimal_capital",
... | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from collections import deque, defaultdict\n\ndef find_best_capital(n, roads):\n def bfs(start):\n distances = [-1] * (n + 1)\n queue = deque... | trial_gpt4o_1 | {
"original_instruction": "In a fantasy kingdom, there are n cities connected by n-1 bidirectional roads, forming a tree. Each city has a unique integer identifier from 1 to n. The King of this kingdom wants to establish a new capital in one of the cities. However, the city chosen as the capital must minimize the max... | 0.631296 | Codeforces_32006 | C | [
"find_tree_diameter",
"find_optimal_capital"
] | 2 | [
[
"find_optimal_capital",
"find_tree_diameter"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | e6d87137e7dde1f24fd81cc34ff72b11bbea7736 | f359e55094adca57fe35e723eb291c9290437a4e | |||
v1.0 | complete | Codeforces | Codeforces_32220_C | from collections import defaultdict, deque
def find_farthest_node(start, tree):
"""
Uses BFS to find the farthest node and its distance from the start node.
"""
pass
def maximum_path_weight(n, edges):
"""
Finds the maximum weight of a path between any two vertices in the tree.
Args:
n... | from collections import defaultdict, deque
def find_farthest_node(start, tree):
"""
Uses BFS to find the farthest node and its distance from the start node.
"""
visited = {}
queue = deque([(start, 0)])
max_distance = 0
farthest_node = start
while queue:
node, curr_distance ... | from solution import maximum_path_weight
def test_example_case():
n = 5
edges = [
(1, 2, 3),
(2, 3, 4),
(3, 4, 5),
(4, 5, 6)
]
assert maximum_path_weight(n, edges) == 18
def test_simple_case():
n = 3
edges = [
(1, 2, 1),
(2, 3, 2)
]
asser... | [
{
"docstring": "Uses BFS to find the farthest node and its distance from the start node.",
"function_declaration": "def find_farthest_node(start, tree):",
"function_name": "find_farthest_node",
"parameter_list": "(start, tree)"
},
{
"docstring": "Finds the two vertices in the tree such that ... | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def find_max_weight_path(n, edges):\n from collections import defaultdict, deque\n \n def bfs(start):\n distance = [-1] * (n + 1)\n que... | trial_gpt4o_1 | {
"original_instruction": "Nikita has a tree with $$$n$$$ vertices. Each edge in the tree has a weight. A path in the tree is a sequence of vertices such that there is an edge between every pair of consecutive vertices in the sequence. The weight of a path is the sum of the weights of its edges.\n\nNikita wants to fi... | 0.671873 | Codeforces_32220 | C | [
"find_farthest_node",
"maximum_path_weight"
] | 2 | [
[
"maximum_path_weight",
"find_farthest_node"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 23a7fee7e91f7ee910513ef3319c9f478c75b2d2 | c4979d718b6088872b3bf2a7cb0694c58e50bef0 | |||
v1.0 | complete | Codeforces | Codeforces_32700_C | def minimum_cost_to_connect_cities(m: int, n: int, roads: List[List[int]]) -> int:
""" Determine the minimum cost required to connect cities with roads.
Args:
m : int : number of cities
n : int : number of possible roads
roads : List[List[int]] : list of roads, each described by three integers ... | def find(parent, i):
if parent[i] == i:
return i
else:
parent[i] = find(parent, parent[i])
return parent[i]
def union(parent, rank, x, y):
rootX = find(parent, x)
rootY = find(parent, y)
if rootX != rootY:
if rank[rootX] > rank[rootY]:
parent[rootY] ... | from solution import minimum_cost_to_connect_cities
def test_case_1():
m = 4
n = 5
roads = [
[1, 2, 2],
[2, 3, 3],
[3, 4, 2],
[4, 1, 4],
[1, 3, 1]
]
assert minimum_cost_to_connect_cities(m, n, roads) == 5
def test_case_2():
m = 4
n = 4
roads = [
... | [
{
"docstring": null,
"function_declaration": "def find(parent, i):",
"function_name": "find",
"parameter_list": "(parent, i)"
},
{
"docstring": null,
"function_declaration": "def union(parent, rank, x, y):",
"function_name": "union",
"parameter_list": "(parent, rank, x, y)"
},
... | [
0,
1,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def minimum_cost_to_connect_cities(m, n, roads):\n from collections import defaultdict\n from heapq import heappop, heappush\n \n if n < m - 1:\n ... | trial_gpt4o_2 | {
"original_instruction": "Phoenix has made a bet with his friend Echo about the minimum cost required to connect cities with roads. There are $$$m$$$ cities and $$$n$$$ possible roads between certain pairs of cities, each road having a specific construction cost. The goal is to ensure that all cities are connected d... | 0.721299 | Codeforces_32700 | C | [
"find",
"union",
"minimum_cost_to_connect_cities"
] | 3 | [
[
"minimum_cost_to_connect_cities",
"find"
],
[
"minimum_cost_to_connect_cities",
"union"
],
[
"union",
"find"
]
] | 3 | [] | false | [] | false | pytest | true | [] | true | 68729f2192dff7255ff674df1b8a9b146812596e | ec005396ace720c2e2fefa581a17cf86277d00ef | |||
v1.0 | complete | Codeforces | Codeforces_32762_C | def prefix_sums(arr):
"""
Computes and returns the prefix sums for the given array.
"""
# Your code here
def query_sum(prefix, l, r):
"""
Computes the sum of the subarray from index l to index r using the prefix sums.
"""
# Your code here
def solve(arr, queries):
"""
Solve the ... | def prefix_sums(arr):
"""
Computes and returns the prefix sums for the given array.
"""
prefix = [0] * (len(arr) + 1)
for i in range(len(arr)):
prefix[i + 1] = prefix[i] + arr[i]
return prefix
def query_sum(prefix, l, r):
"""
Computes the sum of the subarray from index l to inde... | from solution import prefix_sums, query_sum, solve
def test_prefix_sums():
arr = [1, 2, 3, 4, 5]
prefix = prefix_sums(arr)
assert prefix == [0, 1, 3, 6, 10, 15]
def test_query_sum():
arr = [1, 2, 3, 4, 5]
prefix = prefix_sums(arr)
assert query_sum(prefix, 1, 3) == 6
assert query_sum(prefix... | [
{
"docstring": "Computes and returns the prefix sums for the given array.",
"function_declaration": "def prefix_sums(arr):",
"function_name": "prefix_sums",
"parameter_list": "(arr)"
},
{
"docstring": "Computes the sum of the subarray from index l to index r using the prefix sums.",
"fun... | [
0,
1,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def compute_prefix_sums(arr):\n \"\"\"\n Computes prefix sums for the input array.\n \"\"\"\n prefix_sums = [0] * (len(arr) + 1)\n for i in ran... | trial_gpt4o_2 | {
"original_instruction": "You are given an array `arr` of `n` integers and `q` queries. Each query consists of two integers `l` and `r`, and requires you to calculate the sum of the subarray from index `l` to index `r` (inclusive). You need to answer each query efficiently.\n\nThe first line contains two integers `n... | 0.565694 | Codeforces_32762 | C | [
"prefix_sums",
"query_sum",
"solve"
] | 3 | [
[
"solve",
"prefix_sums"
],
[
"solve",
"query_sum"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 92f0c4b7bedb46c0d17fbc654c078c2151e028ac | 7a4ea5d1370aa56461800c6a23762121d7f557ee | |||
v1.0 | complete | Codeforces | Codeforces_32924_C | def is_point_in_polygon(polygon, point):
""" Determine if a point is inside a polygon, on an edge of the polygon, or outside the polygon.
>>> is_point_in_polygon([(0,0),(4,0),(4,4),(0,4),(-1,2)], (-1,1)) "OUTSIDE"
>>> is_point_in_polygon([(0,0),(4,0),(4,4),(0,4),(-1,2)], (2,2)) "INSIDE"
>>> is_point_in_... | def is_point_in_polygon(polygon, point):
# Helper function for checking if a point is on a segment
def on_segment(p, q, r):
return (min(p[0], r[0]) <= q[0] <= max(p[0], r[0]) and
min(p[1], r[1]) <= q[1] <= max(p[1], r[1]))
# Helper function to find the orientation of the ordered tri... | from solution import is_point_in_polygon, process_polygon_and_points
def test_is_point_in_polygon():
polygon = [(0, 0), (4, 0), (4, 4), (0, 4), (-1, 2)]
point1 = (-1, 1)
point2 = (2, 2)
point3 = (4, 0)
assert is_point_in_polygon(polygon, point1) == "OUTSIDE"
assert is_point_in_polygon(polygon, ... | [
{
"docstring": null,
"function_declaration": "def is_point_in_polygon(polygon, point):",
"function_name": "is_point_in_polygon",
"parameter_list": "(polygon, point)"
},
{
"docstring": null,
"function_declaration": "def process_polygon_and_points(n, m, vertices, points):",
"function_n... | [
0,
0,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_point_on_segment(px, py, ax, ay, bx, by):\n \"\"\"\n Check if point (px, py) is on the segment from (ax, ay) to (bx, by).\n \"\"\"\n if min... | trial_gpt4o_2 | {
"original_instruction": "You are given an n-sided polygon in a 2D plane. The vertices of the polygon are provided in order, either clockwise or counterclockwise. A point is considered inside the polygon if it lies strictly inside, or on one of the edges. Given a list of m points, determine for each point if it is i... | 0.539386 | Codeforces_32924 | C | [
"is_point_in_polygon",
"process_polygon_and_points"
] | 2 | [
[
"process_polygon_and_points",
"is_point_in_polygon"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 13661eefb8b1efd646d45cc848e0b847a975a199 | 40009ffaf534e141e5aea442a570ad3474c93b0c | |||
v1.0 | complete | Codeforces | Codeforces_32242_C | def find_winners(n, m, scores):
""" Determine the participant(s) who win(s) the contest.
Each participant has a total score which is the sum of their scores for each problem.
The participant(s) with the highest total score is/are the winner(s).
If there are multiple participants with the highest score, ... | def find_winners(n, m, scores):
total_scores = [sum(scores[i]) for i in range(n)]
max_score = max(total_scores)
winners = [i + 1 for i, score in enumerate(total_scores) if score == max_score]
return winners
# Function to parse the input and find the winners
def determine_winners(n, m, score_matrix):
... | from solution import determine_winners
def test_single_winner():
n, m = 3, 4
scores = [
[50, 30, 20, 10],
[80, 60, 40, 0],
[50, 30, 0, 60]
]
assert determine_winners(n, m, scores) == [2]
def test_multiple_winners():
n, m = 3, 4
scores = [
[50, 30, 20, 10],
... | [
{
"docstring": null,
"function_declaration": "def find_winners(n, m, scores):",
"function_name": "find_winners",
"parameter_list": "(n, m, scores)"
},
{
"docstring": null,
"function_declaration": "def determine_winners(n, m, score_matrix):",
"function_name": "determine_winners",
... | [
1,
0,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def find_winners(n, m, scores):\n total_scores = [sum(scores[i]) for i in range(n)]\n max_score = max(total_scores)\n winners = [i + 1 for i, score i... | trial_gpt4o_0 | {
"original_instruction": "Tanya is organizing an online coding contest. She has n participants and each participant has a unique id from 1 to n. The contest consists of m problems, and each problem is scored differently.\n\nEach participant submits a solution to each problem and gets a score based on its correctness... | 0.687334 | Codeforces_32242 | C | [
"find_winners",
"determine_winners"
] | 2 | [
[
"determine_winners",
"find_winners"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | e46134cdc21cc987beb5619fa6f140eaf42619f3 | d1d7518a8058d966d70ba7df90856a07d03ec537 | |||
v1.0 | complete | Codeforces | Codeforces_32728_C | def maximum_subtree_sum(n: int, values: List[int], edges: List[Tuple[int, int]]) -> int:
""" Reza is a software engineer who has developed a passion for working with trees.
He came across an interesting problem involving tree structures. Given a tree with `n` nodes, each node has a value assigned to it.
Re... | import sys
sys.setrecursionlimit(200000)
def dfs(u, parent, adj, values, max_sum):
current_sum = values[u-1]
for v in adj[u]:
if v != parent:
child_sum = dfs(v, u, adj, values, max_sum)
current_sum += child_sum
max_sum[0] = max(max_sum[0], current_sum)
return current_sum... | from solution import maximum_subtree_sum
def test_example_case():
assert maximum_subtree_sum(5, [1, 2, 3, -2, 5], [(1, 2), (1, 3), (2, 4), (2, 5)]) == 9
def test_all_negative_values():
assert maximum_subtree_sum(5, [-1, -2, -3, -2, -1], [(1, 2), (1, 3), (2, 4), (2, 5)]) == -1
def test_single_node():
asse... | [
{
"docstring": null,
"function_declaration": "def dfs(u, parent, adj, values, max_sum):",
"function_name": "dfs",
"parameter_list": "(u, parent, adj, values, max_sum)"
},
{
"docstring": null,
"function_declaration": "def maximum_subtree_sum(n, values, edges):",
"function_name": "maxi... | [
0,
0,
0,
0,
0,
0,
0,
0,
0,
1
] | 1 | hard | 0.1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def max_subtree_sum(n, node_values, edges):\n from collections import defaultdict\n \n # Build the adjacency list for the tree\n tree = defaultdic... | trial_gpt4o_9 | {
"original_instruction": "Reza is a software engineer who has developed a passion for working with trees. He came across an interesting problem involving tree structures. Given a tree with `n` nodes, each node has a value assigned to it. Reza wants to know the maximum sum of values in any subtree of this tree. Can y... | 0.704031 | Codeforces_32728 | C | [
"dfs",
"maximum_subtree_sum"
] | 2 | [
[
"maximum_subtree_sum",
"dfs"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | c532d6d8208e6da6b6a60ab23bca93706ec3c73a | 766ca5386c679ae71c09af0ab7a16b79c74ef864 | |||
v1.0 | complete | Codeforces | Codeforces_33146_C | def preprocess_array(array):
""" Preprocess the array to create a prefix sum array.
>>> preprocess_array([1, 2, 3, 4, 5]) [0, 1, 3, 6, 10, 15]
"""
def query_sum(prefix_sum, l, r):
""" Returns the sum of the elements in the subarray from index l to r (1-based).
>>> prefix_sum = [0, 1, 3, 6, 10, 15]
... | def preprocess_array(array):
"""
Preprocess the array to create a prefix sum array.
Parameters:
array (list of int): The input array.
Returns:
list of int: The prefix sum array.
"""
prefix_sum = [0] * (len(array) + 1)
for i in range(1, len(array) + 1):
prefix_sum[i]... | from solution import preprocess_array, query_sum, process_queries
def test_preprocess_array():
assert preprocess_array([1, 2, 3, 4, 5]) == [0, 1, 3, 6, 10, 15]
def test_query_sum():
prefix_sum = [0, 1, 3, 6, 10, 15]
assert query_sum(prefix_sum, 1, 3) == 6
assert query_sum(prefix_sum, 2, 4) == 9
as... | [
{
"docstring": "Preprocess the array to create a prefix sum array.\n\nParameters:\narray (list of int): The input array.\n\nReturns:\nlist of int: The prefix sum array.",
"function_declaration": "def preprocess_array(array):",
"function_name": "preprocess_array",
"parameter_list": "(array)"
},
{... | [
1,
1,
0
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def preprocess_array(arr):\n \"\"\"\n Preprocessing array to create prefix sums\n \"\"\"\n n = len(arr)\n prefix_sums = [0] * (n + 1)\n for ... | trial_gpt4o_1 | {
"original_instruction": "You have an array of n integers and Q queries. For each query, you will be given two integers l and r, representing the 1-based indices of the array. You need to find the sum of the elements in the subarray from index l to index r (inclusive).\n\nThe first line contains an integer n (1 ≤ n ... | 0.58719 | Codeforces_33146 | C | [
"preprocess_array",
"query_sum",
"process_queries"
] | 3 | [
[
"process_queries",
"preprocess_array"
],
[
"process_queries",
"query_sum"
]
] | 2 | [
"process_queries"
] | false | [] | false | pytest | true | [] | true | 75900173a96cc66d9154452f34813478d27fa3e0 | 38ce17bc2bd6c78025f98dda06e33dcfd65d2969 | |||
v1.0 | complete | Codeforces | Codeforces_33158_C | def largest_coop_area(n: int, m: int, grid: List[str]) -> int:
""" Find the largest possible rectangular chicken coop area in a field
represented as a grid, where the coop area does not contain any fences ('#').
>>> largest_coop_area(5, 6, [
... "....#.",
... "..##..",
... "......",
...... | def largest_coop_area(n, m, grid):
# Initialize histogram height array
heights = [0] * m
max_area = 0
for row in grid:
for col in range(m):
heights[col] = heights[col] + 1 if row[col] == '.' else 0
max_area = max(max_area, max_histogram_area(heights))
return max_ar... | from solution import largest_coop_area
def test_largest_coop_area_1():
n = 5
m = 6
grid = [
"....#.",
"..##..",
"......",
".#..#.",
"##...."
]
assert largest_coop_area(n, m, grid) == 6
def test_largest_coop_area_2():
n = 1
m = 1
grid = [
... | [
{
"docstring": null,
"function_declaration": "def largest_coop_area(n, m, grid):",
"function_name": "largest_coop_area",
"parameter_list": "(n, m, grid)"
},
{
"docstring": null,
"function_declaration": "def max_histogram_area(heights):",
"function_name": "max_histogram_area",
"pa... | [
0,
0,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def max_rectangle_area(N, M, field):\n def max_histogram_area(heights):\n stack = []\n max_area = 0\n index = 0\n \n whi... | trial_gpt4o_2 | {
"original_instruction": "Farmer John has a rectangular field of N rows and M columns of cells. Each cell is either empty or has a fence. John wants to construct a chicken coop in the field. The coop must be a rectangular section of cells such that there are no fences within this section. Your task is to help John f... | 0.602675 | Codeforces_33158 | C | [
"largest_coop_area",
"max_histogram_area"
] | 2 | [
[
"largest_coop_area",
"max_histogram_area"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 37fca5571279a762ed59543d19ed96faa616cf33 | 10383eeb8b71f6ea6d5ca30273c373876a5ce027 | |||
v1.0 | complete | Codeforces | Codeforces_33180_C | def preprocess_array(arr):
"""
Preprocess the array to create prefix sums.
"""
pass
def range_sum(prefix_sums, l, r):
"""
Calculate the sum of elements in the range [l, r] using prefix sums.
"""
pass
def process_queries(n, arr, queries):
"""
Process the queries to find the sum ... | def preprocess_array(arr):
"""
Preprocess the array to create prefix sums.
"""
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]
return prefix_sums
def range_sum(prefix_sums, l, r):
"""
Calculate the sum of elemen... | def test_preprocess_array():
arr = [1, 2, 3, 4, 5]
expected = [0, 1, 3, 6, 10, 15]
assert preprocess_array(arr) == expected
def test_range_sum():
prefix_sums = preprocess_array([1, 2, 3, 4, 5])
assert range_sum(prefix_sums, 1, 3) == 6
assert range_sum(prefix_sums, 2, 4) == 9
assert range_su... | [
{
"docstring": "Preprocess the array to create prefix sums.",
"function_declaration": "def preprocess_array(arr):",
"function_name": "preprocess_array",
"parameter_list": "(arr)"
},
{
"docstring": "Calculate the sum of elements in the range [l, r] using prefix sums.",
"function_declarati... | [
1,
1
] | 2 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def preprocess(arr):\n \"\"\"\n Preprocess the array to create a prefix sum array.\n \n Parameters:\n arr (list): List of integers.\n \n ... | trial_gpt4o_1 | {
"original_instruction": "You are given an array of integers containing n (1 ≤ n ≤ 200,000) elements. You need to perform several queries on this array. Each query consists of two integers l and r (1 ≤ l ≤ r ≤ n), and you have to calculate the sum of the elements in the array from index l to index r, inclusive.\n\nT... | 0.517836 | Codeforces_33180 | C | [
"preprocess_array",
"range_sum",
"process_queries"
] | 3 | [
[
"process_queries",
"preprocess_array"
],
[
"process_queries",
"range_sum"
]
] | 2 | [
"process_queries"
] | false | [] | false | pytest | false | [] | true | 374306d3f900b643ba153810bdf5dd1f86d57d67 | 392d76138508df9268a418c8a37d4d23f20558d1 | |||
v1.0 | complete | Codeforces | Codeforces_32895_C | import heapq
from typing import List, Tuple
def dijkstra(graph: List[List[Tuple[int, int]]], start_nodes: List[int], n: int) -> List[int]:
distances = [float('inf')] * (n + 1)
pq = []
for node in start_nodes:
heapq.heappush(pq, (0, node))
distances[node] = 0
while pq:
... | import heapq
def dijkstra(graph, start_nodes, n):
distances = [float('inf')] * (n + 1)
pq = []
for node in start_nodes:
heapq.heappush(pq, (0, node))
distances[node] = 0
while pq:
current_distance, current_node = heapq.heappop(pq)
if current_distance >... | from solution import shortest_path_to_storage
def test_example_case():
n = 5
q = 3
edges = [
(1, 2, 3),
(1, 3, 2),
(3, 4, 4),
(2, 5, 6),
(4, 5, 1)
]
storage_rooms = [3, 5]
wrapping_rooms = [2, 4]
queries = [2, 4, 5]
expected = [5, 1, 0]
assert... | [
{
"docstring": null,
"function_declaration": "def dijkstra(graph, start_nodes, n):",
"function_name": "dijkstra",
"parameter_list": "(graph, start_nodes, n)"
},
{
"docstring": null,
"function_declaration": "def shortest_path_to_storage(n, q, edges, storage_rooms, wrapping_rooms, queries)... | [
1,
0,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import heapq\n\ndef dijkstra(graph, start_nodes, n):\n distances = [float('inf')] * (n + 1)\n pq = []\n \n for node in start_nodes:\n heapq... | trial_gpt4o_0 | {
"original_instruction": "Santa's elves are busy organizing the workshop for the annual gift wrapping event. The workshop consists of a series of connected rooms, and each room has a certain number of presents stored in it. Santa wants to maximize efficiency by ensuring that all presents are easily accessible.\n\nEa... | 0.639537 | Codeforces_32895 | C | [
"dijkstra",
"shortest_path_to_storage"
] | 2 | [
[
"shortest_path_to_storage",
"dijkstra"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 2dda238b3e3ef4cfd248d57c68c36aa8f34c0a43 | 191724bcda602fb2808ffa0fb61f5eb8b2652929 | |||
v1.0 | complete | Codeforces | Codeforces_32629_C | from typing import List
def count_intersected_paths(paths: List[List[int]]) -> int:
""" Determine the number of intersected paths.
>>> count_intersected_paths([[0, 0, 4, 4], [1, 4, 4, 1], [0, 4, 4, 0]]) == 3
>>> count_intersected_paths([[0, 0, 1, 1], [2, 2, 3, 3], [1, 0, 2, 3]]) == 0
"""
pass # Wr... | from itertools import combinations
def ccw(A, B, C):
return (C[1] - A[1]) * (B[0] - A[0]) > (B[1] - A[1]) * (C[0] - A[0])
def intersect(path1, path2):
A, B = path1[:2], path1[2:]
C, D = path2[:2], path2[2:]
return ccw(A, C, D) != ccw(B, C, D) and ccw(A, B, C) != ccw(A, B, D)
def count_intersected_pat... | def test_count_intersected_paths():
paths1 = [
[0, 0, 4, 4],
[1, 4, 4, 1],
[0, 4, 4, 0]
]
assert count_intersected_paths(paths1) == 3
paths2 = [
[0, 0, 1, 1],
[2, 2, 3, 3],
[1, 0, 2, 3]
]
assert count_intersected_paths(paths2) == 0
pa... | [
{
"docstring": null,
"function_declaration": "def ccw(A, B, C):",
"function_name": "ccw",
"parameter_list": "(A, B, C)"
},
{
"docstring": null,
"function_declaration": "def intersect(path1, path2):",
"function_name": "intersect",
"parameter_list": "(path1, path2)"
},
{
"d... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def number_of_intersected_paths(n, paths):\n def direction(a, b, c):\n return (b[0] - a[0]) * (c[1] - a[1]) - (b[1] - a[1]) * (c[0] - a[0])\n\n d... | trial_gpt4o_2 | {
"original_instruction": "In a small town, there is a park with n straight walking paths that intersect at different points. We can represent each path as a line segment on a 2D plane with endpoints (x1, y1) and (x2, y2).\n\nA path is considered \"intersected\" if there is at least one point on the path that interse... | 0.602277 | Codeforces_32629 | C | [
"ccw",
"intersect",
"count_intersected_paths"
] | 3 | [
[
"count_intersected_paths",
"intersect"
],
[
"intersect",
"ccw"
]
] | 2 | [] | false | [] | false | pytest | false | [] | true | b41147ea1d23034183f7d2235eea26a56a217c36 | fec9bc65e98e743aa6100ef899595d6e07c065f5 | |||
v1.0 | complete | Codeforces | Codeforces_33139_C | def minimum_travel_distance(n: int, m: int, k: int, roads: List[Tuple[int, int, int]], sequence: List[int]) -> int:
"""Find the minimum cost to travel from the first place in the sequence to the last place visiting all specified places in the given order.
Args:
n : int : the number of places
m : in... | import heapq
def dijkstra(graph, start_node, n):
"""
Dijkstra's algorithm to find the shortest path from a start node to all other nodes.
"""
distances = [float('inf')] * (n + 1)
distances[start_node] = 0
pq = [(0, start_node)]
while pq:
current_distance, current_node = heapq.heapp... | from solution import minimum_travel_distance
def test_case_1():
n = 5
m = 6
k = 4
roads = [
(1, 2, 3),
(1, 3, 5),
(2, 3, 4),
(2, 5, 6),
(3, 4, 2),
(4, 5, 1)
]
sequence = [1, 3, 4, 5]
assert minimum_travel_distance(n, m, k, roads, sequence) == ... | [
{
"docstring": "Dijkstra's algorithm to find the shortest path from a start node to all other nodes.",
"function_declaration": "def dijkstra(graph, start_node, n):",
"function_name": "dijkstra",
"parameter_list": "(graph, start_node, n)"
},
{
"docstring": null,
"function_declaration": "d... | [
0,
0,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import heapq\n\ndef dijkstra(graph, start, n):\n \"\"\"\n Computes the shortest path from the start node to all other nodes using Dijkstra's algorithm.\... | trial_gpt4o_2 | {
"original_instruction": "There are several places on the map linked by bidirectional roads in such a way that each place is reachable from every other place. You are given the description of the roads in the form of a weighted graph, where each road has a certain distance.\n\nYou are a delivery person and need to d... | 0.776542 | Codeforces_33139 | C | [
"dijkstra",
"minimum_travel_distance"
] | 2 | [
[
"minimum_travel_distance",
"dijkstra"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 9ced5422b8c4d99af891bbcd6420c34f7cc1bdbd | e94a9c4b0aa2d0632c6e4e2ee3b8d190d1f9c983 | |||
v1.0 | complete | Codeforces | Codeforces_33385_C | from typing import List, Tuple
def is_prime(n: int) -> bool:
""" Check if a given number is a prime number.
>>> is_prime(2)
True
>>> is_prime(4)
False
"""
def sum_of_primes_in_subarray(arr: List[int], l: int, r: int) -> int:
""" Calculate the sum of all prime numbers in the subarray from i... | def is_prime(n):
if n <= 1:
return False
if n <= 3:
return True
if n % 2 == 0 or n % 3 == 0:
return False
i = 5
while i * i <= n:
if n % i == 0 or n % (i + 2) == 0:
return False
i += 6
return True
def sum_of_primes_in_subarray(arr, l, r):
... | from solution import is_prime, sum_of_primes_in_subarray, process_queries
def test_is_prime():
assert is_prime(2)
assert is_prime(3)
assert not is_prime(4)
assert is_prime(5)
assert not is_prime(1)
assert is_prime(97)
assert not is_prime(99)
def test_sum_of_primes_in_subarray():
arr = ... | [
{
"docstring": null,
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": null,
"function_declaration": "def sum_of_primes_in_subarray(arr, l, r):",
"function_name": "sum_of_primes_in_subarray",
"parameter_list": "(arr... | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def sieve_of_eratosthenes(limit):\n \"\"\"\n Generates a list of prime numbers up to the given limit using the Sieve of Eratosthenes.\n \"\"\"\n i... | trial_gpt4o_1 | {
"original_instruction": "You are given an array of n integers, and you need to perform q queries on the array. Each query contains two integers l and r (1-indexed), and you need to find the sum of all prime numbers in the subarray from index l to index r.\n\nInput:\n- The first line of input contains two integers n... | 0.676011 | Codeforces_33385 | C | [
"is_prime",
"sum_of_primes_in_subarray",
"process_queries"
] | 3 | [
[
"process_queries",
"sum_of_primes_in_subarray"
],
[
"sum_of_primes_in_subarray",
"is_prime"
]
] | 2 | [
"process_queries"
] | false | [] | false | pytest | true | [] | true | fe7b26d3ef05d9cd7cc14cad8131ff2fe20aa05e | 50acb04a44eda64bff7461bcdfc40a0faaeb980f | |||
v1.0 | complete | Codeforces | Codeforces_33070_C | import collections
from typing import List, Tuple
def max_path_strength(n: int, edges: List[Tuple[int, int]], node_values: List[int]) -> int:
"""Find the maximum path strength in a tree for a ceremony where the path strength is calculated as
the sum of all the node values on the path connecting two leaf nodes... | from collections import defaultdict
def dfs(node, parent, tree, values, cache):
# We initialize the two largest distances from current node to any leaf
max1, max2 = 0, 0
# Iterate over all connected nodes
for neighbor in tree[node]:
if neighbor != parent:
neighbor_max = dfs(neighbor... | import pytest
from solution import max_path_strength
def test_example_case():
n = 5
edges = [(1, 2), (1, 3), (3, 4), (3, 5)]
node_values = [5, 8, 3, 7, 1]
assert max_path_strength(n, edges, node_values) == 23
def test_small_tree():
n = 2
edges = [(1, 2)]
node_values = [1, 2]
assert max... | [
{
"docstring": null,
"function_declaration": "def dfs(node, parent, tree, values, cache):",
"function_name": "dfs",
"parameter_list": "(node, parent, tree, values, cache)"
},
{
"docstring": null,
"function_declaration": "def max_path_strength(n, edges, node_values):",
"function_name"... | [
0,
0,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from collections import defaultdict, deque\n\ndef max_path_strength(n, edges, values):\n tree = defaultdict(list)\n for u, v in edges:\n tree[u].... | trial_gpt4o_2 | {
"original_instruction": "In an ancient kingdom, there is a highly advanced tree known for its exotic fruits. In this kingdom, they have a tradition of representing data in binary trees. Each node of the tree contains a non-negative integer value, and each tree has exactly one root node.\n\nFor this particular tree,... | 0.571188 | Codeforces_33070 | C | [
"dfs",
"max_path_strength"
] | 2 | [
[
"max_path_strength",
"dfs"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 161e63876c44e23983138de17fd6cb9ac4173f6d | 95740dd4d9877bb27252788907d4be80e7324e9c | |||
v1.0 | complete | Codeforces | Codeforces_33569_C | def number_of_points_on_convex_hull(n: int, points: List[Tuple[int, int]]) -> int:
""" Given a set of points in a 2D plane, determine the number of points that are on the convex hull.
The convex hull of a set of points is the smallest convex polygon that can enclose all the points.
Args:
n (int): Numbe... | def cross_product(o, a, b):
"""
Returns the cross product of vector OA and OB
A positive cross product indicates a counter-clockwise turn
A negative cross product indicates a clockwise turn
A zero cross product indicates collinearity
"""
return (a[0] - o[0]) * (b[1] - o[1]) - (a[1] - o[1]) *... | from solution import number_of_points_on_convex_hull
def test_convex_hull_example():
assert number_of_points_on_convex_hull(5, [(0, 0), (2, 2), (2, 0), (0, 2), (1, 1)]) == 4
def test_convex_hull_triangle():
assert number_of_points_on_convex_hull(3, [(0, 0), (1, 1), (2, 0)]) == 3
def test_convex_hull_square()... | [
{
"docstring": "Returns the cross product of vector OA and OB\nA positive cross product indicates a counter-clockwise turn\nA negative cross product indicates a clockwise turn\nA zero cross product indicates collinearity",
"function_declaration": "def cross_product(o, a, b):",
"function_name": "cross_pr... | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def convex_hull(points):\n def orientation(p, q, r):\n return (q[1] - p[1]) * (r[0] - q[0]) - (q[0] - p[0]) * (r[1] - q[1])\n\n points = sorted(p... | trial_gpt4o_1 | {
"original_instruction": "Given a set of points in a 2D plane, determine the number of points that are on the convex hull. The convex hull of a set of points is the smallest convex polygon that can enclose all the points.\n\nThe first line of input contains an integer `n` (3 ≤ n ≤ 10^4) — the number of points. Each ... | 0.517494 | Codeforces_33569 | C | [
"cross_product",
"convex_hull",
"number_of_points_on_convex_hull"
] | 3 | [
[
"convex_hull",
"cross_product"
],
[
"number_of_points_on_convex_hull",
"convex_hull"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | b9f6ca69f0f88f68ea59c904e9f3591512cecc2f | ab72c0542c10d63abffeca6b12023d02e2912aca | |||
v1.0 | complete | Codeforces | Codeforces_33472_C | def largest_rectangle_area(matrix: List[List[str]]) -> int:
"""
Find the area of the largest rectangular subgrid that contains only '1's.
:param matrix: A list of lists of '0's and '1's representing the grid.
:return: The area of the largest rectangular subgrid that contains only '1's.
>>> larg... | def largest_rectangle_area(matrix):
if not matrix:
return 0
n = len(matrix)
m = len(matrix[0])
heights = [0] * m
max_area = 0
for i in range(n):
for j in range(m):
if matrix[i][j] == '1':
heights[j] += 1
else:
heights... | def test_largest_rectangle_area():
matrix = [
['1', '0', '1', '0', '0'],
['1', '0', '1', '1', '1'],
['1', '1', '1', '1', '1'],
['1', '0', '0', '1', '0']
]
assert largest_rectangle_area(matrix) == 6
def test_largest_rectangle_area_single_row():
matrix = [['1', '1', '1', '... | [
{
"docstring": null,
"function_declaration": "def largest_rectangle_area(matrix):",
"function_name": "largest_rectangle_area",
"parameter_list": "(matrix)"
},
{
"docstring": null,
"function_declaration": "def largest_histogram_area(heights):",
"function_name": "largest_histogram_area... | [
1,
0,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def largest_rectangle_area(matrix):\n if not matrix:\n return 0\n\n n = len(matrix)\n m = len(matrix[0])\n \n heights = [0] * m\n max... | trial_gpt4o_0 | {
"original_instruction": "A farmer has a rectangular field divided into an n x m grid of unit squares. Each unit square can either be fertile or infertile, and the farmer wants to find the largest rectangular subgrid that is fully fertile so that he can plant his crops effectively.\n\nYou are given a binary matrix o... | 0.705923 | Codeforces_33472 | C | [
"largest_rectangle_area",
"largest_histogram_area"
] | 2 | [
[
"largest_rectangle_area",
"largest_histogram_area"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | e1359798198219606db126dfec6d8f163849f9f3 | 5ba4f7558491a6b97e1a3c29491071695583a437 | |||
v1.0 | complete | Codeforces | Codeforces_32334_C | from typing import List, Tuple, Union
def min_travel_time(n: int, m: int, s: int, t: int, roads: List[Tuple[int, int, int, int]], c: int) -> Union[int, str]:
"""
Calculate the minimum travel time between two intersections in a town, given the current time of day.
:param n: Number of intersections.
:pa... | import heapq
from collections import defaultdict, deque
def min_travel_time(n, m, s, t, roads, c):
# Graph representation
graph = defaultdict(list)
for u, v, l, z in roads:
if z == c: # only consider roads available at the given time c
graph[u].append((v, l))
graph[v].appen... | def test_min_travel_time_basic_case():
n = 5
m = 6
s = 1
t = 5
roads = [
(1, 2, 5, 3),
(1, 3, 10, 14),
(2, 4, 3, 3),
(3, 5, 7, 14),
(4, 5, 1, 3),
(2, 3, 4, 3)
]
c = 3
assert calculate_min_travel_time(n, m, s, t, roads, c) == 9
def test_min... | [
{
"docstring": null,
"function_declaration": "def min_travel_time(n, m, s, t, roads, c):",
"function_name": "min_travel_time",
"parameter_list": "(n, m, s, t, roads, c)"
},
{
"docstring": null,
"function_declaration": "def calculate_min_travel_time(n, m, s, t, roads, c):",
"function_... | [
1,
1,
0
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import heapq\n\ndef min_travel_time(n, m, s, t, roads, current_hour):\n graph = {i: [] for i in range(1, n + 1)}\n for u, v, l, z in roads:\n if ... | trial_gpt4o_1 | {
"original_instruction": "A town has n intersections and m bidirectional roads between them. Each road has a length and a maximum travel speed allowed. The townspeople want to know the minimum time required to get from one intersection to another. Some intersections and roads are available or unavailable with respec... | 0.667645 | Codeforces_32334 | C | [
"min_travel_time",
"calculate_min_travel_time"
] | 2 | [
[
"calculate_min_travel_time",
"min_travel_time"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | f7b907621a5b988cc56ed44afc6e90bbcd8d459e | 8413ccd5060ddcb96eb62b6da9811be2390242e2 | |||
v1.0 | complete | Codeforces | Codeforces_33565_C | def is_reachable(grid: List[str]) -> str:
""" Determine if it is possible to reach the bottom-right cell (n, m) starting from the top-left cell (1, 1) using the swaps and moves described.
>>> is_reachable(["4 4", "....", "..#.", ".#..", "...."])
"YES"
>>> is_reachable(["3 3", ".#.", "###", ".#."])
"... | def is_reachable(grid):
from collections import deque
n = len(grid)
m = len(grid[0])
if grid[0][0] == '#' or grid[n-1][m-1] == '#':
return "NO"
def in_bound(x, y):
return 0 <= x < n and 0 <= y < m and grid[x][y] == '.'
def bfs():
queue = deque([(0, 0)])
... | def test_is_reachable():
assert solve("4 4\n....\n..#.\n.#..\n....") == "YES"
assert solve("3 3\n.#.\n###\n.#.") == "NO"
assert solve("1 1\n.") == "YES"
assert solve("2 2\n..\n.#") == "NO"
assert solve("3 3\n...\n.#.\n...") == "YES"
assert solve("3 4\n....\n####\n....") == "NO"
if __name__ == '... | [
{
"docstring": null,
"function_declaration": "def is_reachable(grid):",
"function_name": "is_reachable",
"parameter_list": "(grid)"
},
{
"docstring": null,
"function_declaration": "def solve(input_data):",
"function_name": "solve",
"parameter_list": "(input_data)"
},
{
"d... | [
0,
0,
0,
0,
0,
0,
0,
1,
1
] | 2 | hard | 0.222 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_path_possible(n, m, grid):\n from collections import deque\n\n def in_bounds(x, y):\n return 0 <= x < n and 0 <= y < m\n\n def bfs():\n... | trial_gpt4o_9 | {
"original_instruction": "You are given a grid with `n` rows and `m` columns. Each cell in the grid is either empty ('.') or blocked by an obstacle ('#'). You are initially situated at the top-left cell (1, 1) and you need to reach the bottom-right cell (n, m). You can move up, down, left, or right, but you cannot m... | 0.622365 | Codeforces_33565 | C | [
"is_reachable",
"solve"
] | 2 | [
[
"solve",
"is_reachable"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | b967b898e431a76addf1133b3b47a9554d5bee5d | 877db31690c5f0da4f32ad4271662ce13223e2a3 | |||
v1.0 | complete | Codeforces | Codeforces_33528_C | def max_subsequence_sum_circular(n, a):
"""
Determines the maximum possible sum of any subsequence in the circular array.
Parameters:
n (int): Length of the array.
a (list): List of n integers representing the circular array.
Returns:
int: The maximum sum of any subsequence in the circ... | def max_subsequence_sum_circular(n, a):
"""
Determines the maximum possible sum of any subsequence in the circular array.
Parameters:
n (int): Length of the array.
a (list): List of n integers representing the circular array.
Returns:
int: The maximum sum of any subsequence in the circ... | def test_max_subsequence_sum_circular_basic():
assert max_subsequence_sum_circular(5, [5, -3, 5]) == 10
def test_max_subsequence_sum_circular_single_element():
assert max_subsequence_sum_circular(1, [7]) == 7
assert max_subsequence_sum_circular(1, [-5]) == -5
def test_max_subsequence_sum_circular_all_nega... | [
{
"docstring": "Determines the maximum possible sum of any subsequence in the circular array.\n\nParameters:\nn (int): Length of the array.\na (list): List of n integers representing the circular array.\n\nReturns:\nint: The maximum sum of any subsequence in the circular array.",
"function_declaration": "de... | [
0,
0,
0,
0,
0,
0,
1,
0,
1,
0
] | 2 | hard | 0.2 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def max_subsequence_sum_circular(array):\n def kadane(arr):\n max_current = max_global = arr[0]\n for num in arr[1:]:\n max_curren... | trial_gpt4o_8 | {
"original_instruction": "Alyssa loves solving problems with arrays. Recently, she came across a new challenge involving the maximum subsequence sum in circular arrays. A circular array is an array where the end of the array wraps around to the beginning of the array. Alyssa's goal is to find the maximum sum of any ... | 0.646606 | Codeforces_33528 | C | [
"max_subsequence_sum_circular",
"max_subsequence_sum"
] | 2 | [
[
"max_subsequence_sum_circular",
"max_subsequence_sum"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | 96c4bc87a28fd4ea2e601eb22ee873fca3db2628 | e3b6b1a0af187ddc94d96b4c4cc032ddca91035f | |||
v1.0 | complete | Codeforces | Codeforces_33777_C | def find_longest_palindromic_subsequence_lengths(strings: List[str]) -> List[int]:
"""
Given a list of strings, return the length of the longest palindromic subsequence for each string.
>>> find_longest_palindromic_subsequence_lengths(["character", "racecar", "level", "abcba"])
[5, 7, 5, 5]
>>> fin... | def longest_palindromic_subsequence_length(s):
"""
Given a string s, find the length of the longest palindromic subsequence.
"""
n = len(s)
if n == 0:
return 0
# Create a 2D array to store lengths of palindromic subsequences
dp = [[0] * n for _ in range(n)]
# All substrings of ... | from solution import find_longest_palindromic_subsequence_lengths
def test_longest_palindromic_subsequence_length():
inputs = ["character", "racecar", "level", "abcba"]
expected = [5, 7, 5, 5]
assert find_longest_palindromic_subsequence_lengths(inputs) == expected
def test_single_character_strings():
... | [
{
"docstring": "Given a string s, find the length of the longest palindromic subsequence.",
"function_declaration": "def longest_palindromic_subsequence_length(s):",
"function_name": "longest_palindromic_subsequence_length",
"parameter_list": "(s)"
},
{
"docstring": "Given a list of strings,... | [
1,
0,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def longest_palindromic_subsequence_length(s):\n \"\"\"\n Given a string s, find the length of the longest palindromic subsequence.\n \"\"\"\n n =... | trial_gpt4o_0 | {
"original_instruction": "Given a list of strings, create a function that finds the longest palindromic subsequence in each string. A palindromic subsequence is a sequence that reads the same forward and backward, and it need not be contiguous.\n\n### Input\nThe input consists of an integer `n` (1 ≤ n ≤ 1000) repres... | 0.793965 | Codeforces_33777 | C | [
"longest_palindromic_subsequence_length",
"find_longest_palindromic_subsequence_lengths"
] | 2 | [
[
"find_longest_palindromic_subsequence_lengths",
"longest_palindromic_subsequence_length"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | b3df8d2e430ab00090ba6db6a02e44c5717fd4ef | a8e99aac94644173f82da1cf63625f56013658fe | |||
v1.0 | complete | Codeforces | Codeforces_33796_C | from typing import List, Tuple
def max_subarray_sum(nums: List[int]) -> int:
""" Returns the maximum score (sum) of any contiguous subarray.
>>> max_subarray_sum([1, -2, 3, 4, -1])
7
>>> max_subarray_sum([-1, -2, -3])
-1
"""
def archery_sessions(t: int, sessions: List[Tuple[int, List[int]]... | def max_subarray_sum(nums):
"""
Returns the maximum score (sum) of any contiguous subarray.
"""
max_sum = current_sum = nums[0]
for num in nums[1:]:
current_sum = max(num, current_sum + num)
max_sum = max(max_sum, current_sum)
return max_sum
def archery_sessions(t, ses... | from solution import archery_sessions, max_subarray_sum
def test_max_subarray_sum():
assert max_subarray_sum([1, -2, 3, 4, -1]) == 7
assert max_subarray_sum([-1, -2, -3]) == -1
assert max_subarray_sum([5, -1, 2, -3, 4]) == 7
assert max_subarray_sum([1, 2, 3, 4]) == 10
assert max_subarray_sum([-2, -... | [
{
"docstring": "Returns the maximum score (sum) of any contiguous subarray.",
"function_declaration": "def max_subarray_sum(nums):",
"function_name": "max_subarray_sum",
"parameter_list": "(nums)"
},
{
"docstring": null,
"function_declaration": "def archery_sessions(t, sessions):",
"... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def max_contiguous_segment_score(t, sessions):\n \"\"\"\n Returns the maximum score achievable from any contiguous segment of targets.\n \n Args:\... | trial_gpt4o_2 | {
"original_instruction": "Lena loves archery and regularly practices at the training ground. The training ground has multiple targets positioned in a line, and each target has a certain score associated with hitting it. However, Lena has a unique way of practicing: she can only hit targets in a contiguous segment of... | 0.596262 | Codeforces_33796 | C | [
"max_subarray_sum",
"archery_sessions"
] | 2 | [
[
"archery_sessions",
"max_subarray_sum"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | dd02d3301822e855445b3df6e83b9338e2882d0c | b9c68a5b7e4b27ab951d062424bd322e6452dbdd | |||
v1.0 | complete | Codeforces | Codeforces_33559_C | def max_sum_submatrix(matrix: List[List[int]]) -> int:
"""
Find the largest sum of elements in any contiguous submatrix within a given matrix.
:param matrix: List[List[int]]: the nxm matrix of integers
:return: int: the largest sum of elements across all possible contiguous submatrices
>>>... | def max_sum_submatrix(matrix):
"""
Returns the maximum sum of any contiguous submatrix in the given 2D matrix.
"""
n = len(matrix)
m = len(matrix[0])
max_sum = float('-inf')
# Iterate over every possible combination of top and bottom row
for top in range(n):
temp = [0] * m
... | from solution import max_sum_submatrix, kadane
def test_single_element_matrix():
assert max_sum_submatrix([[5]]) == 5
assert max_sum_submatrix([[-5]]) == -5
def test_all_negative_matrix():
matrix = [
[-1, -2, -3],
[-4, -5, -6],
[-7, -8, -9]
]
assert max_sum_submatrix(matrix... | [
{
"docstring": "Returns the maximum sum of any contiguous submatrix in the given 2D matrix.",
"function_declaration": "def max_sum_submatrix(matrix):",
"function_name": "max_sum_submatrix",
"parameter_list": "(matrix)"
},
{
"docstring": "Helper function to find the maximum sum subarray using... | [
1,
0,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def max_sum_submatrix(matrix):\n \"\"\"\n Finds the maximum sum of any contiguous submatrix within the given matrix.\n \"\"\"\n def kadane(arr):\n... | trial_gpt4o_2 | {
"original_instruction": "Mina is working on a project that involves square matrices of integers. She needs to find the largest sum of elements in any contiguous submatrix within a given matrix. A submatrix is defined by selecting a rectangular section from the matrix, and its sum is the sum of all the elements with... | 0.625891 | Codeforces_33559 | C | [
"max_sum_submatrix",
"kadane"
] | 2 | [
[
"max_sum_submatrix",
"kadane"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 100e42f44c1774787b661795ff6ea8d6ac85390f | 453b01ad06e3ff644196721f33f355008845bb9c | |||
v1.0 | complete | Codeforces | Codeforces_33315_C | def find(parent, i):
"""Helper function to find the parent of node i in the Disjoint Set."""
if parent[i] == i:
return i
return find(parent, parent[i])
def union(parent, rank, x, y):
"""Helper function to perform union of two subsets x and y."""
root_x = find(parent, x)
root_y = find(pa... | def find(parent, i):
if parent[i] == i:
return i
return find(parent, parent[i])
def union(parent, rank, x, y):
root_x = find(parent, x)
root_y = find(parent, y)
if rank[root_x] < rank[root_y]:
parent[root_x] = root_y
elif rank[root_x] > rank[root_y]:
parent[root_y] ... | def test_solution():
# Test case 1
n = 4
m = 5
roads = [
(1, 2, 1),
(2, 3, 2),
(3, 4, 3),
(4, 1, 4),
(1, 3, 5)
]
assert minimal_cost_to_connect_cities(n, m, roads) == 6
# Test case 2: Minimum edge case
n = 2
m = 1
roads = [
(1, 2, ... | [
{
"docstring": null,
"function_declaration": "def find(parent, i):",
"function_name": "find",
"parameter_list": "(parent, i)"
},
{
"docstring": null,
"function_declaration": "def union(parent, rank, x, y):",
"function_name": "union",
"parameter_list": "(parent, rank, x, y)"
},
... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_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 xroot = find(parent,... | trial_gpt4o_1 | {
"original_instruction": "The city of Graphland has a unique railway system where each road connecting two cities is bidirectional and has an associated cost. The residents of Graphland are interested in making the railway system more efficient.\n\nThe mayor has proposed a new project where he plans to connect all c... | 0.682028 | Codeforces_33315 | C | [
"find",
"union",
"kruskal",
"minimal_cost_to_connect_cities"
] | 4 | [
[
"kruskal",
"find"
],
[
"kruskal",
"union"
],
[
"minimal_cost_to_connect_cities",
"kruskal"
],
[
"union",
"find"
]
] | 4 | [] | false | [] | false | pytest | false | [] | true | 313b08cc710635fd57b1b1f39d9248850fec27b5 | db2d1b19e7b93defba1efe66b5e1113c2e6167ca | |||
v1.0 | complete | Codeforces | Codeforces_33800_C | from typing import List, Tuple
def is_prime(num: int) -> bool:
"""
Check if a number is prime.
>>> is_prime(2)
True
>>> is_prime(3)
True
>>> is_prime(4)
False
>>> is_prime(17)
True
>>> is_prime(18)
False
>>> is_prime(19)
True
>>> is_prime(1)
False
"""... | import itertools
def is_prime(num):
"""
Check if a number is prime.
"""
if num <= 1:
return False
if num <= 3:
return True
if num % 2 == 0 or num % 3 == 0:
return False
i = 5
while i * i <= num:
if num % i == 0 or num % (i + 2) == 0:
return Fa... | from solution import is_prime, prime_sequence_exists
def test_is_prime():
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(4) == False
assert is_prime(17) == True
assert is_prime(18) == False
assert is_prime(19) == True
assert is_prime(1) == False
def test_prime_sequen... | [
{
"docstring": "Check if a number is prime.",
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": "Returns \"YES\" if there exists a non-empty subset of the sequence whose sum is a prime number.\nReturns \"NO\" otherwise.",
... | [
0,
1,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from itertools import combinations\n\ndef is_prime(num):\n \"\"\"\n Helper function to check if a number is prime.\n \"\"\"\n if num <= 1:\n ... | trial_gpt4o_1 | {
"original_instruction": "Daisy loves prime numbers and is fascinated by sequences. She recently encountered Prime Sequences and wants your help to solve a problem.\n\nShe gives you a sequence of integers and wants you to check if it's possible to delete some elements (possibly none) from the sequence so that the su... | 0.764139 | Codeforces_33800 | C | [
"is_prime",
"prime_sequence_exists"
] | 2 | [
[
"prime_sequence_exists",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 8cfa2b3ebd6db9c0593f8c1cf8798781d9885569 | 053f36b22ddb2d52e5684351a63dacd78a9bc281 | |||
v1.0 | complete | Codeforces | Codeforces_33190_C | import heapq
from typing import List, Tuple
def find(parent, x):
if parent[x] != x:
parent[x] = find(parent, parent[x])
return parent[x]
def union(parent, rank, x, y):
rootX = find(parent, x)
rootY = find(parent, y)
if rootX != rootY:
if rank[rootX] > rank[rootY]:
paren... | import heapq
def find(parent, x):
if parent[x] != x:
parent[x] = find(parent, parent[x])
return parent[x]
def union(parent, rank, x, y):
rootX = find(parent, x)
rootY = find(parent, y)
if rootX != rootY:
if rank[rootX] > rank[rootY]:
parent[rootY] = rootX
elif r... | from solution import minimum_cost_to_unblock
def test_all_passageways_open():
n = 4
h = 3
hallways = [(1, 2, 1), (2, 3, 2), (3, 4, 1)]
m = 0
unblockable_hallways = []
assert minimum_cost_to_unblock(n, h, hallways, m, unblockable_hallways) == 4
def test_some_blocked_passageways():
n = 4
... | [
{
"docstring": null,
"function_declaration": "def find(parent, x):",
"function_name": "find",
"parameter_list": "(parent, x)"
},
{
"docstring": null,
"function_declaration": "def union(parent, rank, x, y):",
"function_name": "union",
"parameter_list": "(parent, rank, x, y)"
},
... | [
1,
0,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import heapq\n\ndef 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, ... | trial_gpt4o_0 | {
"original_instruction": "A new gallery has recently opened in Metropolis. The gallery consists of a series of rooms connected by passageways, represented as a weighted undirected graph. Each room is a node, and each passageway is an edge with a weight corresponding to the time required to traverse it. There are h-h... | 0.650496 | Codeforces_33190 | C | [
"find",
"union",
"minimum_cost_to_unblock"
] | 3 | [
[
"minimum_cost_to_unblock",
"find"
],
[
"minimum_cost_to_unblock",
"union"
],
[
"union",
"find"
]
] | 3 | [] | false | [] | false | pytest | true | [] | true | 5e7af6ab92d3ed706962feda3cafb845cd679cb0 | 372580d70cc404fe20dd29e34ae59ec19c7e2844 | |||
v1.0 | complete | Codeforces | Codeforces_33953_C | def max_product_from_input_string(input_string: str) -> int:
""" Given an array of integers, determine the maximum product that can be obtained
by multiplying any three distinct elements of the array. The input is a string that
contains the number of elements in the array followed by the elements themselves... | def max_product_of_three(nums):
nums.sort()
return max(nums[-1] * nums[-2] * nums[-3], nums[0] * nums[1] * nums[-1])
def max_product_from_input_string(input_string):
# Parse input
input_lines = input_string.strip().split("\n")
n = int(input_lines[0])
nums = list(map(int, input_lines[1].split())... | from solution import max_product_from_input_string
def test_example_case():
input_str = "5\n-10 -10 5 2 1"
assert max_product_from_input_string(input_str) == 500
def test_all_positive_numbers():
input_str = "4\n1 2 3 4"
assert max_product_from_input_string(input_str) == 24
def test_all_negative_numbe... | [
{
"docstring": null,
"function_declaration": "def max_product_of_three(nums):",
"function_name": "max_product_of_three",
"parameter_list": "(nums)"
},
{
"docstring": null,
"function_declaration": "def max_product_from_input_string(input_string):",
"function_name": "max_product_from_i... | [
1,
0,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def max_product_of_three(nums):\n nums.sort()\n return max(nums[-1] * nums[-2] * nums[-3], nums[0] * nums[1] * nums[-1])\n\ndef max_product_from_input_s... | trial_gpt4o_0 | {
"original_instruction": "Given an array of integers, determine the maximum product that can be obtained by multiplying any three distinct elements of the array. The array can contain both positive and negative integers.\n\nThe first line of the input contains an integer n (3 ≤ n ≤ 105) — the number of elements in ... | 0.705426 | Codeforces_33953 | C | [
"max_product_of_three",
"max_product_from_input_string"
] | 2 | [
[
"max_product_from_input_string",
"max_product_of_three"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 42f63d8a9a605fceebe81ac06baac707d3a98582 | fb5601e90793940d6e99ecf351aa29dd50259836 | |||
v1.0 | complete | Codeforces | Codeforces_33841_C | from typing import List, Dict
def is_prime(n: int) -> bool:
""" Determines whether a given number n is prime.
>>> is_prime(2)
True
>>> is_prime(4)
False
"""
def build_tree(n: int) -> Dict[int, List[int]]:
""" Builds a tree from given input.
>>> build_tree(5)
{1: [2, 3], 2: [1],... | def is_prime(n):
if n <= 1:
return False
if n <= 3:
return True
if n % 2 == 0 or n % 3 == 0:
return False
i = 5
while i * i <= n:
if n % i == 0 or n % (i + 2) == 0:
return False
i += 6
return True
def build_tree(n):
from collections import... | from solution import is_prime, sum_prime_paths, find_leaf_paths
def test_is_prime():
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(4) == False
assert is_prime(13) == True
assert is_prime(20) == False
def test_find_leaf_paths():
tree = {1: [2, 3], 2: [1], 3: [1, 4, 5], 4... | [
{
"docstring": null,
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": null,
"function_declaration": "def build_tree(n):",
"function_name": "build_tree",
"parameter_list": "(n)"
},
{
"docstring": null,
"... | [
0,
0,
0,
0,
0,
0,
1,
0,
0,
0
] | 1 | hard | 0.1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from collections import defaultdict, deque\n\ndef is_prime(n):\n if n <= 1:\n return False\n if n <= 3:\n return True\n if n % 2 == 0 o... | trial_gpt4o_6 | {
"original_instruction": "You are given a binary tree with n nodes, rooted at node 1. Each node has a unique integer value assigned to it. Your task is to determine the sum of all root-to-leaf paths where each node in the path sums to a prime number.\n\nA leaf is defined as a node with no children. A root-to-leaf pa... | 0.622981 | Codeforces_33841 | C | [
"is_prime",
"build_tree",
"find_leaf_paths",
"sum_prime_paths",
"main"
] | 5 | [
[
"find_leaf_paths",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 00109a3c81098ddc822aabe6a732a67681957414 | a1b3320ae259baa7b8c49206bbcad94a788cb4dd | |||
v1.0 | complete | Codeforces | Codeforces_34010_C | def palindrome_transform(n: int) -> (int, int):
"""
Given an integer n, transform it into a palindrome by reversing its digits
and adding the result to the original number. If the sum is not a palindrome,
repeat the process until the sum is a palindrome. Return the resulting
palindrome and the numbe... | def is_palindrome(number):
"""
Check if the given integer is a palindrome.
"""
str_num = str(number)
return str_num == str_num[::-1]
def reverse_number(number):
"""
Return the reverse of the given integer.
"""
return int(str(number)[::-1])
def palindrome_transform(n):
"""
T... | from solution import palindrome_transform
def test_single_digit_palindrome():
assert palindrome_transform(5) == (5, 0)
def test_example_case():
assert palindrome_transform(96) == (4884, 4)
def test_no_iteration_needed():
assert palindrome_transform(121) == (121, 0)
def test_small_number():
assert pa... | [
{
"docstring": "Check if the given integer is a palindrome.",
"function_declaration": "def is_palindrome(number):",
"function_name": "is_palindrome",
"parameter_list": "(number)"
},
{
"docstring": "Return the reverse of the given integer.",
"function_declaration": "def reverse_number(num... | [
0,
0,
0,
0,
0,
0,
0,
0,
1,
1
] | 2 | hard | 0.2 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_palindrome(n):\n \"\"\"\n Checks if a given integer n is a palindrome.\n \"\"\"\n s = str(n)\n return s == s[::-1]\n\ndef reverse_number... | trial_gpt4o_9 | {
"original_instruction": "Given an integer n, you are asked to transform it into a palindrome by reversing its digits and adding the result to the original number. If the sum is not a palindrome, repeat the process until the sum is a palindrome. The task is to find the resulting palindrome and the number of iteratio... | 0.738858 | Codeforces_34010 | C | [
"is_palindrome",
"reverse_number",
"palindrome_transform"
] | 3 | [
[
"palindrome_transform",
"is_palindrome"
],
[
"palindrome_transform",
"reverse_number"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 8c4116dd99aa5266a5f63b34ed198a2775a0fb80 | 419298b1c2efce44d555382d3ea7a687fd85648d | |||
v1.0 | complete | Codeforces | Codeforces_33827_C | def solve(n: int, m: int, edge_list: List[Tuple[int, int, int]]) -> int:
"""
Determine the minimum number of edges to remove from the graph so that
the remaining graph has no cycles and preserves the maximum possible sum of weights of the remaining edges.
Args:
n (int): Number of nodes in the gra... | def find(parent, i):
"""
A utility function to find the subset of an element i
"""
if parent[i] == i:
return i
else:
return find(parent, parent[i])
def union(parent, rank, x, y):
"""
A utility function to do union of two subsets
"""
xroot = find(parent, x)
yroot ... | import pytest
from solution import solve
def test_example_case_1():
n = 6
m = 9
edge_list = [
(1, 2, 4),
(1, 3, 3),
(2, 3, 2),
(2, 4, 5),
(3, 4, 7),
(3, 5, 9),
(4, 5, 6),
(4, 6, 8),
(5, 6, 1)
]
assert solve(n, m, edge_list) == ... | [
{
"docstring": "A utility function to find the subset of an element i",
"function_declaration": "def find(parent, i):",
"function_name": "find",
"parameter_list": "(parent, i)"
},
{
"docstring": "A utility function to do union of two subsets",
"function_declaration": "def union(parent, r... | [
1,
0,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def find(parent, i):\n \"\"\"\n A utility function to find the subset of an element i\n \"\"\"\n if parent[i] == i:\n return i\n else:\n... | trial_gpt4o_0 | {
"original_instruction": "You are given an undirected, connected graph with `n` nodes and `m` edges. The nodes are numbered from `1` to `n`. Each edge has a weight, which is a positive integer. \n\nYour task is to determine the minimum number of edges to remove from the graph so that the remaining graph has no cycle... | 0.689957 | Codeforces_33827 | C | [
"find",
"union",
"max_spanning_tree",
"solve"
] | 4 | [
[
"max_spanning_tree",
"find"
],
[
"max_spanning_tree",
"union"
],
[
"solve",
"max_spanning_tree"
],
[
"union",
"find"
]
] | 4 | [] | false | [] | false | pytest | true | [] | true | cc75eb7535d9011b601a60964895b1a0d2c3a690 | 27bc56a5f34299179ca9ce92d69e71d7f705071e | |||
v1.0 | complete | Codeforces | Codeforces_34079_C | def max_time_to_farthest_city(n: int, roads: List[Tuple[int, int, int]]) -> int:
""" Calculate the maximum time it will take for the messenger to travel from city 1 to any other city in the kingdom.
>>> max_time_to_farthest_city(5, [(1, 2, 3), (1, 3, 2), (3, 4, 4), (3, 5, 5)])
7
>>> max_time_to_far... | import heapq
def max_communication_time(n, roads):
def dijkstra(graph, start):
distances = [float('inf')] * (n + 1)
distances[start] = 0
pq = [(0, start)]
while pq:
(current_distance, current_node) = heapq.heappop(pq)
if current_distance > distances[... | from solution import max_time_to_farthest_city
def test_max_time_to_farthest_city_1():
n = 5
roads = [
(1, 2, 3),
(1, 3, 2),
(3, 4, 4),
(3, 5, 5)
]
assert max_time_to_farthest_city(n, roads) == 7
def test_max_time_to_farthest_city_2():
n = 3
roads = [
(1... | [
{
"docstring": null,
"function_declaration": "def max_communication_time(n, roads):",
"function_name": "max_communication_time",
"parameter_list": "(n, roads)"
},
{
"docstring": null,
"function_declaration": "def max_time_to_farthest_city(n, edges):",
"function_name": "max_time_to_fa... | [
1,
0,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import heapq\n\ndef max_communication_time(n, roads):\n def dijkstra(graph, start):\n distances = [float('inf')] * (n + 1)\n distances[start]... | trial_gpt4o_0 | {
"original_instruction": "A kingdom consists of n cities connected by n-1 bidirectional roads in such a way that there is exactly one path between any two cities (forming a tree). Each road between cities i and j has a specific length d[i][j]. \n\nThe king lives in city 1 and wants to establish a communication netwo... | 0.676643 | Codeforces_34079 | C | [
"max_communication_time",
"max_time_to_farthest_city"
] | 2 | [
[
"max_time_to_farthest_city",
"max_communication_time"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 72c92567c4e5169206c247f0a9556a6719ccc049 | 5211d26653c7f77ecbfe99195db1af6dee77d6c3 | |||
v1.0 | complete | Codeforces | Codeforces_34207_C | from typing import List
def digit_sum(n: int) -> int:
"""Calculate the sum of the digits of a number.
>>> digit_sum(123) == 6
>>> digit_sum(10) == 1
>>> digit_sum(999) == 27
>>> digit_sum(0) == 0
"""
def transform_to_equal(arr: List[int]) -> int:
"""
Transforms the array into another a... | def digit_sum(n):
"""Calculate the sum of the digits of a number."""
return sum(int(d) for d in str(n))
def transform_to_equal(arr):
"""
Transforms the array into another array where each number is replaced by the sum of its digits.
Returns the minimum number of operations required to make all elem... | from solution import digit_sum, transform_to_equal
def test_digit_sum():
assert digit_sum(123) == 6
assert digit_sum(10) == 1
assert digit_sum(999) == 27
assert digit_sum(0) == 0
def test_transform_to_equal_single_element():
assert transform_to_equal([123]) == 1 # 123 -> 6
def test_transform... | [
{
"docstring": "Calculate the sum of the digits of a number.",
"function_declaration": "def digit_sum(n):",
"function_name": "digit_sum",
"parameter_list": "(n)"
},
{
"docstring": "Transforms the array into another array where each number is replaced by the sum of its digits.\nReturns the mi... | [
0,
0,
0,
0,
0,
0,
0,
0,
1,
0
] | 1 | hard | 0.1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def digit_sum(n):\n \"\"\"\n Helper function to calculate the sum of the digits of a number.\n \"\"\"\n return sum(int(digit) for digit in str(n))... | trial_gpt4o_8 | {
"original_instruction": "You are given an array of n positive integers. Your task is to transform this array into another array where each number is replaced by the sum of its digits. You need to determine the minimum number of operations required to make all elements in the transformed array equal.\n\nIn each oper... | 0.667356 | Codeforces_34207 | C | [
"digit_sum",
"transform_to_equal"
] | 2 | [
[
"transform_to_equal",
"digit_sum"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | a469525a2f4174ea19349930dd5dfc98091ad864 | ed22d53adf582d3bd2159c6e985b4d9f296c4f68 | |||
v1.0 | complete | Codeforces | Codeforces_33838_C | def sieve(max_num):
"""
Create a list to determine prime numbers up to max_num using the Sieve of Eratosthenes.
"""
is_prime = [True] * (max_num + 1)
is_prime[0] = is_prime[1] = False
for start in range(2, int(max_num**0.5) + 1):
if is_prime[start]:
for multiple in rang... | def sieve(max_num):
"""
Create a list to determine prime numbers up to max_num using the Sieve of Eratosthenes.
"""
is_prime = [True] * (max_num + 1)
is_prime[0] = is_prime[1] = False
for start in range(2, int(max_num**0.5) + 1):
if is_prime[start]:
for multiple in range... | from solution import find_prime_counts
def test_find_prime_counts():
queries = [(2, 10), (11, 20), (30, 50)]
result = find_prime_counts(queries)
assert result == [4, 4, 5]
def test_find_prime_counts_edge_case():
queries = [(1, 2), (1, 1), (10**6, 10**6)]
result = find_prime_counts(queries)
ass... | [
{
"docstring": "Create a list to determine prime numbers up to max_num using the Sieve of Eratosthenes.",
"function_declaration": "def sieve(max_num):",
"function_name": "sieve",
"parameter_list": "(max_num)"
},
{
"docstring": "Given a range [l, r] and a list of primes, count how many primes... | [
0,
0,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def sieve_of_eratosthenes(max_num):\n is_prime = [True] * (max_num + 1)\n p = 2\n while (p * p <= max_num):\n if (is_prime[p] == True):\n ... | trial_gpt4o_2 | {
"original_instruction": "Priya and Rohan are playing a game with prime numbers. The game involves finding certain prime numbers within specific ranges. A prime number is a natural number greater than 1 that cannot be formed by multiplying two smaller natural numbers. Priya wants to find prime numbers between two gi... | 0.683095 | Codeforces_33838 | C | [
"sieve",
"count_primes_in_range",
"find_prime_counts"
] | 3 | [
[
"find_prime_counts",
"count_primes_in_range"
],
[
"find_prime_counts",
"sieve"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | cd23254efa3a75cffa2cbca1ab38c585334ff1e7 | d81d01db14fbe359a9ab5a405fcac5c6b6fc916b | |||
v1.0 | complete | Codeforces | Codeforces_34333_C | def digital_root(num: int) -> int:
""" Returns the single digit result of repeatedly summing the digits of num until a single digit is obtained.
>>> digital_root(123)
6
>>> digital_root(9875)
2
>>> digital_root(67)
4
"""
def process_numbers(numbers: List[int]) -> List[int]:
""" Take... | def digital_root(num):
"""
Returns the single digit result of repeatedly summing the digits of num until a single digit is obtained.
"""
while num >= 10:
num = sum(int(digit) for digit in str(num))
return num
def process_numbers(numbers):
"""
Takes a list of numbers and returns a li... | from solution import digital_root, process_numbers
def test_digital_root_single_digit():
assert digital_root(5) == 5
def test_digital_root_multiple_iterations():
assert digital_root(9875) == 2
assert digital_root(123) == 6
def test_digital_root_two_digits():
assert digital_root(67) == 4
def test_pro... | [
{
"docstring": "Returns the single digit result of repeatedly summing the digits of num until a single digit is obtained.",
"function_declaration": "def digital_root(num):",
"function_name": "digital_root",
"parameter_list": "(num)"
},
{
"docstring": "Takes a list of numbers and returns a li... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def digital_root(n):\n \"\"\"\n Returns the digital root of an integer n.\n \"\"\"\n while n >= 10:\n n = sum(map(int, str(n)))\n return... | trial_gpt4o_2 | {
"original_instruction": "In a land where communication through codes is essential, a secret society has developed a unique way of encrypting their numeric messages. The encryption process involves taking a number and transforming it by repeatedly replacing each digit by the sum of the digits of the original number ... | 0.649292 | Codeforces_34333 | C | [
"digital_root",
"process_numbers"
] | 2 | [
[
"process_numbers",
"digital_root"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 96cc8d8e3c19e99e76f078ea9c7d96a069f90cda | ee0e588c0683e684625c9d8f813550c5b41f3bb8 | |||
v1.0 | complete | Codeforces | Codeforces_34171_C | def maximize_minimum_diameter(n: int, m: int, edges: List[Tuple[int, int, int]]) -> int:
""" Given the number of houses `n` and the number of available pipes `m`, along with a list of `edges`
where each edge is a tuple (u, v, d) representing a pipe between house `u` and house `v` with a
diameter of `d`, ... | def find(parent, i):
if parent[i] == i:
return i
else:
return find(parent, parent[i])
def union(parent, rank, x, y):
xroot = find(parent, x)
yroot = find(parent, y)
if rank[xroot] < rank[yroot]:
parent[xroot] = yroot
elif rank[xroot] > rank[yroot]:
paren... | from solution import maximize_minimum_diameter
def test_example_case():
assert maximize_minimum_diameter(4, 5, [(1, 2, 4), (1, 3, 2), (2, 3, 3), (2, 4, 5), (3, 4, 1)]) == 3
def test_no_connection():
assert maximize_minimum_diameter(2, 1, [(1, 2, 1)]) == 1
assert maximize_minimum_diameter(2, 0, []) == -1
... | [
{
"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_codeforces-i2i_20000_1739005484_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 union(... | trial_gpt4o_1 | {
"original_instruction": "A local construction company undertakes a project to build water supply pipelines for a new housing complex. The project involves connecting the houses with each other. There are n houses, and the company has an initial supply of various pipes, each with a defined length and diameter.\n\nTh... | 0.585785 | Codeforces_34171 | C | [
"find",
"union",
"maximize_minimum_diameter"
] | 3 | [
[
"maximize_minimum_diameter",
"find"
],
[
"maximize_minimum_diameter",
"union"
],
[
"union",
"find"
]
] | 3 | [] | false | [] | false | pytest | true | [] | true | 35a7a295d675e4086ae3cad151a128005f1139dd | e68fa26310d0990313a57e8fafbf34106b5d1617 | |||
v1.0 | complete | Codeforces | Codeforces_34298_C | def find_optimal_center(n: int, roads: List[Tuple[int, int, int]]) -> int:
"""
Find the minimum possible maximum travel time from the optimal center town to any other town.
Parameters:
n (int): Number of towns.
roads (List[Tuple[int, int, int]]): Each tuple contains three integers u, v, and t denot... | import heapq
def dijkstra(graph, start, n):
distances = [float('inf')] * (n + 1)
distances[start] = 0
priority_queue = [(0, start)]
while priority_queue:
current_distance, current_node = heapq.heappop(priority_queue)
if current_distance > distances[current_node]:
... | def test_example():
n, m = 4, 4
roads = [
(1, 2, 4),
(1, 3, 3),
(2, 3, 1),
(3, 4, 2)
]
assert find_optimal_center(n, roads) == 3
def test_small_case():
n, m = 2, 1
roads = [
(1, 2, 5)
]
assert find_optimal_center(n, roads) == 5
def test_complete_... | [
{
"docstring": null,
"function_declaration": "def dijkstra(graph, start, n):",
"function_name": "dijkstra",
"parameter_list": "(graph, start, n)"
},
{
"docstring": null,
"function_declaration": "def find_optimal_center(n, roads):",
"function_name": "find_optimal_center",
"paramet... | [
0,
0,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import heapq\n\ndef dijkstra(n, graph, start):\n max_time = [float('inf')] * (n + 1)\n max_time[start] = 0\n pq = [(0, start)]\n while pq:\n ... | trial_gpt4o_2 | {
"original_instruction": "A certain kingdom consists of $$$n$$$ towns connected by $$$m$$$ bidirectional roads. Each road has a travel time. The king wants to establish a center of the kingdom such that the maximum travel time from this center to any other town is minimized. The travel times between towns can be lar... | 0.68425 | Codeforces_34298 | C | [
"dijkstra",
"find_optimal_center"
] | 2 | [
[
"find_optimal_center",
"dijkstra"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | bc3308ff6ac732d269bd8c48c785c3a5d7d7f849 | 0a7517de36e9308b4bd46d7982a8d8f3cda4a2b8 | |||
v1.0 | complete | Codeforces | Codeforces_33708_C | def sieve_of_eratosthenes(n):
"""
Returns a list of boolean values. The index represents the number and the value at each index
is True if the number is prime, otherwise False.
"""
pass
def find_twin_primes(L, R):
"""
John is learning about prime numbers and is particularly interested in `t... | def sieve_of_eratosthenes(n):
"""
Returns a list of boolean values. The index represents the number and the value at each index
is True if the number is prime, otherwise False.
"""
is_prime = [True] * (n + 1)
is_prime[0] = is_prime[1] = False
for p in range(2, int(n**0.5) + 1):
... | from solution import find_twin_primes
def test_find_twin_primes_example_cases():
assert find_twin_primes(1, 20) == 4 # (3,5), (5,7), (11,13), (17,19)
assert find_twin_primes(10, 30) == 2 # (11,13), (17,19)
assert find_twin_primes(1, 10) == 2 # (3,5), (5,7)
def test_find_twin_primes_no_twins():
asser... | [
{
"docstring": "Returns a list of boolean values. The index represents the number and the value at each index\nis True if the number is prime, otherwise False.",
"function_declaration": "def sieve_of_eratosthenes(n):",
"function_name": "sieve_of_eratosthenes",
"parameter_list": "(n)"
},
{
"d... | [
0,
0,
0,
0,
1
] | 1 | hard | 0.2 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def find_twin_primes(L, R):\n def sieve(n):\n is_prime = [True] * (n + 1)\n p = 2\n while (p * p <= n):\n if (is_prime[p] =... | trial_gpt4o_4 | {
"original_instruction": "John is learning about prime numbers and is particularly interested in `twin primes`. Twin primes are pairs of prime numbers that have a difference of 2. For example, (3, 5) and (11, 13) are twin primes.\n\nJohn's teacher gave him an assignment where he needs to find the number of twin prim... | 0.650038 | Codeforces_33708 | C | [
"sieve_of_eratosthenes",
"find_twin_primes"
] | 2 | [
[
"find_twin_primes",
"sieve_of_eratosthenes"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 89a2660538dcb0a7e1953b99519dd9dce9643217 | 841da4517fe39ee4861d800d06b3f401ca7d4fde | |||
v1.0 | complete | Codeforces | Codeforces_34338_C | def utilize_substitution(t: str, q: int, rules: List[str]) -> str:
""" Given a string t representing a number in a letter-based numerical system and
a list of substitution rules, find the maximum numeric value that can be obtained
by performing a series of letter substitutions according to the given... | def max_numeric_value(t, rules):
from collections import defaultdict
# Create a dict to store the most valuable replacement for each character
replacement_map = defaultdict(str)
for rule in rules:
a, b = rule.split()
if replacement_map[a] == '' or replacement_map[a] < b:
... | from solution import utilize_substitution
def test_single_replacement():
t = "abc"
q = 3
rules = ["a d", "b e", "c f"]
assert utilize_substitution(t, q, rules) == "def"
def test_multiple_replacement():
t = "aaa"
q = 3
rules = ["a b", "b c", "c d"]
assert utilize_substitution(t, q, rule... | [
{
"docstring": null,
"function_declaration": "def max_numeric_value(t, rules):",
"function_name": "max_numeric_value",
"parameter_list": "(t, rules)"
},
{
"docstring": null,
"function_declaration": "def utilize_substitution(t, q, rules):",
"function_name": "utilize_substitution",
... | [
0,
0,
0,
1,
0
] | 1 | hard | 0.2 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def maximize_value(t, q, rules):\n # Create a dictionary to hold the best possible substitution for each letter\n best_substitution = {chr(i): chr(i) fo... | trial_gpt4o_3 | {
"original_instruction": "The citizens of Blueland have developed a unique numerical system based on letters from the alphabet. Each letter in the alphabet corresponds to a unique digit from 0 to 9. You are given a string t consisting of lowercase English letters, representing a number in this unusual system. You ar... | 0.619402 | Codeforces_34338 | C | [
"max_numeric_value",
"utilize_substitution"
] | 2 | [
[
"utilize_substitution",
"max_numeric_value"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 9798487e757f17b7be1643baf26b668d2c181b20 | 445e6a5a303ded505f77764716262b189fa5b337 | |||
v1.0 | complete | Codeforces | Codeforces_34078_C | from typing import List
def is_sorted_array(array: List[int]) -> str:
"""
Check if a given array is sorted in non-decreasing order.
"""
pass
def check_sorted_arrays(input_list: List[List[int]]) -> List[str]:
"""
Given a list of arrays, determine if each array is sorted in non-decreasing order.... | def is_sorted_array(array):
"""
Checks if the given array is sorted in non-decreasing order.
"""
for i in range(1, len(array)):
if array[i] < array[i - 1]:
return "NO"
return "YES"
def check_sorted_arrays(input_list):
"""
Processes multiple arrays and checks if each arra... | import pytest
from solution import check_sorted_arrays
def test_single_sorted_array():
input_list = [[5, 1, 2, 3, 4, 5]]
expected_output = ["YES"]
assert check_sorted_arrays(input_list) == expected_output
def test_single_unsorted_array():
input_list = [[4, 1, 3, 2, 4]]
expected_output = ["NO"]
... | [
{
"docstring": "Checks if the given array is sorted in non-decreasing order.",
"function_declaration": "def is_sorted_array(array):",
"function_name": "is_sorted_array",
"parameter_list": "(array)"
},
{
"docstring": "Processes multiple arrays and checks if each array is sorted\nin non-decrea... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_sorted_in_non_decreasing_order(arr):\n \"\"\"\n Checks if the given list is sorted in non-decreasing order.\n \"\"\"\n return all(arr[i] <=... | trial_gpt4o_2 | {
"original_instruction": "Anna is a software engineer who likes to analyze the performance of different sorting algorithms. She has been given n arrays and asked to determine if each array is already sorted in non-decreasing order.\n\nYour task is to help Anna by writing a program that checks if each given array is ... | 0.717712 | Codeforces_34078 | C | [
"is_sorted_array",
"check_sorted_arrays"
] | 2 | [
[
"check_sorted_arrays",
"is_sorted_array"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | d0156f08d4429e45e023c097845f3c03e445d909 | 6550aced69963c019908f7297fc3aed62ab62af9 | |||
v1.0 | complete | Codeforces | Codeforces_34208_C | def mst_weight_sum(n: int, m: int, edges: List[Tuple[int, int, int]]) -> Union[int, str]:
""" Compute the sum of the weights of the Minimum Spanning Tree (MST) of the graph.
If it is impossible to connect all vertices in the graph, return "IMPOSSIBLE".
Args:
n (int): Number of nodes (2 ≤ n ≤ 10^5).
... | class DisjointSet:
def __init__(self, n):
self.parent = list(range(n))
self.rank = [0] * n
def find(self, u):
if self.parent[u] != u:
self.parent[u] = self.find(self.parent[u])
return self.parent[u]
def union(self, u, v):
root_u = self.find(u)
... | def test_mst_weight_sum_example_1():
n, m = 4, 5
edges = [(1, 2, 1), (1, 3, 2), (2, 3, 2), (2, 4, 3), (3, 4, 3)]
assert mst_weight_sum(n, m, edges) == 6
def test_mst_weight_sum_example_2():
n, m = 4, 2
edges = [(1, 2, -1), (3, 4, -2)]
assert mst_weight_sum(n, m, edges) == "IMPOSSIBLE"
def test... | [] | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_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(parent... | trial_gpt4o_1 | {
"original_instruction": "You are given an undirected graph containing `n` nodes and `m` edges. Each edge has an associated weight, which can be positive, negative, or zero. Your task is to compute the sum of the weights of the Minimum Spanning Tree (MST) of the graph. If there are multiple MSTs with the same weight... | 0.798622 | Codeforces_34208 | C | [
"kruskal_mst",
"mst_weight_sum"
] | 2 | [
[
"mst_weight_sum",
"kruskal_mst"
]
] | 1 | [] | false | [
"DisjointSet"
] | true | pytest | false | [] | true | 42888efca74cb88faf4016f40d45c6a0737da512 | 1e03aaaf3acc1de1b716876164fac57d2b71c598 | |||
v1.0 | complete | Codeforces | Codeforces_34382_C | def find_shortest_substring_length(n: int, s: str) -> int:
""" Find the length of the shortest substring that contains all the unique characters present in the given string.
>>> find_shortest_substring_length(10, "abacdbedea")
5
>>> find_shortest_substring_length(5, "abcde")
5
>>> find_shortest_... | def shortest_substring_with_all_chars(string):
unique_chars = set(string)
num_unique_chars = len(unique_chars)
start = 0
min_len = len(string) + 1
char_count = {}
for end in range(len(string)):
char_count[string[end]] = char_count.get(string[end], 0) + 1
while ... | from solution import find_shortest_substring_length
def test_short_string():
assert find_shortest_substring_length(2, "ab") == 2
def test_no_repeats():
assert find_shortest_substring_length(5, "abcde") == 5
def test_same_char():
assert find_shortest_substring_length(4, "aaaa") == 1
def test_example_case... | [
{
"docstring": null,
"function_declaration": "def shortest_substring_with_all_chars(string):",
"function_name": "shortest_substring_with_all_chars",
"parameter_list": "(string)"
},
{
"docstring": null,
"function_declaration": "def find_shortest_substring_length(n, s):",
"function_nam... | [
0,
0,
0,
0,
0,
0,
0,
1
] | 1 | hard | 0.125 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def length_of_shortest_substring_with_all_unique_chars(s):\n from collections import defaultdict\n \n n = len(s)\n if n == 0:\n return 0\n ... | trial_gpt4o_9 | {
"original_instruction": "You are given a string composed of lowercase English letters. Your task is to find the length of the shortest substring that contains all the unique characters present in the given string.\n\nThe first line of input contains a single integer n (1 ≤ n ≤ 100000), representing the length of th... | 0.751705 | Codeforces_34382 | C | [
"shortest_substring_with_all_chars",
"find_shortest_substring_length"
] | 2 | [
[
"find_shortest_substring_length",
"shortest_substring_with_all_chars"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | d4763baf5db84c46c76ea6c796cc867f402b13a4 | b1f5dfe061526d40dbc467659144c9a0ac3ea51b | |||
v1.0 | complete | Codeforces | Codeforces_34344_C | def min_additional_roads_to_connect(n, m, edges):
""" Find the minimum total length of roads needed to be added to ensure all intersections are connected.
>>> min_additional_roads_to_connect(3, 3, [(1, 2, 1), (2, 3, 1), (3, 1, 1)]) 0
>>> min_additional_roads_to_connect(4, 2, [(1, 2, 5), (3, 4, 7)]) 12
>... | def find(parent, i):
if parent[i] == i:
return i
parent[i] = find(parent, parent[i])
return parent[i]
def union(parent, rank, x, y):
xroot = find(parent, x)
yroot = find(parent, y)
if rank[xroot] < rank[yroot]:
parent[xroot] = yroot
elif rank[xroot] > rank[yroot]:
... | from solution import min_additional_roads_to_connect
def test_no_road_needed():
n = 3
m = 3
edges = [(1, 2, 1), (2, 3, 1), (3, 1, 1)]
assert min_additional_roads_to_connect(n, m, edges) == 0
def test_one_road_needed():
n = 4
m = 2
edges = [(1, 2, 5), (3, 4, 7)]
assert min_additional_ro... | [
{
"docstring": null,
"function_declaration": "def find(parent, i):",
"function_name": "find",
"parameter_list": "(parent, i)"
},
{
"docstring": null,
"function_declaration": "def union(parent, rank, x, y):",
"function_name": "union",
"parameter_list": "(parent, rank, x, y)"
},
... | [
0,
0,
0,
0,
1
] | 1 | hard | 0.2 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_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 union(... | trial_gpt4o_4 | {
"original_instruction": "A city's road network can be represented as a graph consisting of $$$n$$$ intersections and $$$m$$$ bidirectional roads. Each road connects two intersections and has a certain length associated with it. The government has decided to build new roads. However, due to cost constraints, they wa... | 0.648837 | Codeforces_34344 | C | [
"find",
"union",
"min_additional_roads_to_connect"
] | 3 | [
[
"min_additional_roads_to_connect",
"find"
],
[
"min_additional_roads_to_connect",
"union"
],
[
"union",
"find"
]
] | 3 | [] | false | [] | false | pytest | true | [] | true | fdd138889b4ad53522ca1294d12140e8017ce490 | 49c449194cd489bb6fc0d7b015246e64c196c0cc | |||
v1.0 | complete | Codeforces | Codeforces_34351_C | from typing import List, Tuple
def is_prime(num: int) -> bool:
""" Check if a number is a prime number. """
pass
def prime_pairs_prefix_sequence(n: int) -> List[int]:
"""
Construct a sequence of length `n` such that the sum of any two adjacent elements is a prime number.
>>> prime_pairs_prefix_s... | 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 prime_pairs_prefix_seque... | from solution import solve, is_prime, prime_pairs_prefix_sequence
def test_is_prime():
assert is_prime(2)
assert is_prime(3)
assert not is_prime(4)
assert is_prime(5)
assert not is_prime(6)
assert is_prime(7)
def test_prime_pairs_prefix_sequence():
assert prime_pairs_prefix_sequence(2) == ... | [
{
"docstring": null,
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": null,
"function_declaration": "def prime_pairs_prefix_sequence(n):",
"function_name": "prime_pairs_prefix_sequence",
"parameter_list": "(n)"... | [
1
] | 1 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(num):\n if num <= 1:\n return False\n if num <= 3:\n return True\n if num % 2 == 0 or num % 3 == 0:\n return False\... | trial_gpt4o_0 | {
"original_instruction": "Sebastian loves sequences, especially ones with interesting properties. He is currently fascinated by sequences where the sum of any two adjacent elements is a prime number.\n\nGiven an integer $$$n$$$ ($$$2 \\le n \\le 10^5$$$), construct a sequence of length $$$n$$$ such that the sum of a... | 0.690414 | Codeforces_34351 | C | [
"is_prime",
"prime_pairs_prefix_sequence",
"solve",
"output_results"
] | 4 | [
[
"solve",
"prime_pairs_prefix_sequence"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | e07c2308f91cf87a4e83f35494edbaf18daff4d5 | 4eb83a62f55a04c30dd7038f038b035caa73eb21 | |||
v1.0 | complete | Codeforces | Codeforces_34292_C | from typing import List
def is_palindrome(s: str) -> bool:
return s == s[::-1]
def can_be_palindrome_by_removing_one_char(s: str) -> str:
left, right = 0, len(s) - 1
while left < right:
if s[left] != s[right]:
# Check by removing one character either from left or right
if i... | def is_palindrome(s: str) -> bool:
return s == s[::-1]
def can_be_palindrome_by_removing_one_char(s: str) -> str:
left, right = 0, len(s) - 1
while left < right:
if s[left] != s[right]:
# Check by removing one character either from left or right
if is_palindrome(s[left:right... | from solution import process_test_cases
def test_can_be_palindrome_by_removing_one_char():
assert process_test_cases(3, ["abca", "racecar", "abc"]) == ["YES", "YES", "NO"]
assert process_test_cases(2, ["madam", "aabaa"]) == ["YES", "YES"]
assert process_test_cases(1, ["abcdefg"]) == ["NO"]
assert proce... | [
{
"docstring": null,
"function_declaration": "def is_palindrome(s):",
"function_name": "is_palindrome",
"parameter_list": "(s)"
},
{
"docstring": null,
"function_declaration": "def can_be_palindrome_by_removing_one_char(s):",
"function_name": "can_be_palindrome_by_removing_one_char",... | [
1,
0,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def can_be_palindrome_by_removing_one_char(s):\n \"\"\"\n Checks if a string can be transformed into a palindrome by removing at most one character.\n ... | trial_gpt4o_2 | {
"original_instruction": "You are given a string $$$s$$$ consisting of lowercase English letters. Your task is to modify the string such that it becomes a palindrome by removing at most one character. A palindrome is a string that reads the same backward as forward.\n\nFor example, \"abca\" can be modified to \"aba\... | 0.763462 | Codeforces_34292 | C | [
"is_palindrome",
"can_be_palindrome_by_removing_one_char",
"process_test_cases"
] | 3 | [
[
"can_be_palindrome_by_removing_one_char",
"is_palindrome"
],
[
"process_test_cases",
"can_be_palindrome_by_removing_one_char"
]
] | 2 | [
"process_test_cases"
] | false | [] | false | pytest | true | [] | true | 7267ec214bee1b922f3da81d9e98883ba5724b28 | d6a93f27a340ac8bc656901c772f0f62813a8693 | |||
v1.0 | complete | Codeforces | Codeforces_34396_C | def min_roads_to_repair(N: int, M: int, roads: List[Tuple[int, int]]) -> int:
""" Compute the minimum number of roads that need to be repaired to ensure all houses are connected.
>>> min_roads_to_repair(5, 2, [(1, 2), (2, 3)])
2
>>> min_roads_to_repair(5, 0, [])
4
>>> min_roads_to_repair(4, 3, [... | def find_set(parent, u):
if parent[u] != u:
parent[u] = find_set(parent, parent[u])
return parent[u]
def union_sets(parent, rank, u, v):
root_u = find_set(parent, u)
root_v = find_set(parent, v)
if root_u != root_v:
if rank[root_u] > rank[root_v]:
parent[root_v] = root_... | import pytest
from solution import min_roads_to_repair
def test_example_case():
assert min_roads_to_repair(5, 2, [(1, 2), (2, 3)]) == 2
def test_no_working_roads():
assert min_roads_to_repair(5, 0, []) == 4
def test_fully_connected():
assert min_roads_to_repair(4, 3, [(1, 2), (2, 3), (3, 4)]) == 0
def t... | [
{
"docstring": null,
"function_declaration": "def find_set(parent, u):",
"function_name": "find_set",
"parameter_list": "(parent, u)"
},
{
"docstring": null,
"function_declaration": "def union_sets(parent, rank, u, v):",
"function_name": "union_sets",
"parameter_list": "(parent, ... | [
1,
1,
0
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def find_set(parent, u):\n if parent[u] != u:\n parent[u] = find_set(parent, parent[u])\n return parent[u]\n\ndef union_sets(parent, rank, u, v):... | trial_gpt4o_0 | {
"original_instruction": "In a village, each house is connected by a series of roads, and there's exactly one road between any two houses, forming a tree structure. However, recently some roads broke down, and now some of the houses can no longer be reached from others. The villagers need to repair the least number ... | 0.634599 | Codeforces_34396 | C | [
"find_set",
"union_sets",
"min_roads_to_repair"
] | 3 | [
[
"min_roads_to_repair",
"find_set"
],
[
"min_roads_to_repair",
"union_sets"
],
[
"union_sets",
"find_set"
]
] | 3 | [] | false | [] | false | pytest | true | [] | true | c039b54f27ad35b85315be8fb92ee789fc880028 | e39a3bd2479a291e084b0d8d9abd735d49e56aab | |||
v1.0 | complete | Codeforces | Codeforces_34386_C | def contains_all_numbers(M: List[List[int]], n: int, m: int, k: int) -> str:
"""
Returns "YES" if there exists a submatrix in M which contains all integers
from 1 to k, otherwise returns "NO".
>>> contains_all_numbers([
[1, 2, 3, 4],
[2, 5, 6, 1],
[3, 4, 2, 1]
... | def contains_all_numbers(M, n, m, k):
"""
Returns "YES" if there exists a submatrix in M which contains all integers
from 1 to k, otherwise returns "NO".
"""
num_set = set(range(1, k + 1))
numbers_found = set()
for i in range(n):
for j in range(m):
if M[i][j] in num_set:... | def test_case_1():
matrix = [
[3, 4, 5],
[1, 2, 3, 4],
[2, 5, 6, 1],
[3, 4, 2, 1]
]
assert solve(matrix) == "YES"
def test_case_2():
matrix = [
[3, 4, 6],
[1, 2, 3, 4],
[2, 5, 6, 1],
[3, 4, 2, 1]
]
assert solve(matrix) == "YES"
de... | [
{
"docstring": "Returns \"YES\" if there exists a submatrix in M which contains all integers\nfrom 1 to k, otherwise returns \"NO\".",
"function_declaration": "def contains_all_numbers(M, n, m, k):",
"function_name": "contains_all_numbers",
"parameter_list": "(M, n, m, k)"
},
{
"docstring": ... | [
0,
1,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def contains_all_numbers_with_square(nums_set, total_numbers):\n return len(nums_set) == total_numbers\n\ndef check_submatrix(matrix, n, m, k):\n # coll... | trial_gpt4o_2 | {
"original_instruction": "You are given an integer matrix $$$M$$$ with dimensions $$$n \\times m$$$. Your task is to determine if there exists a submatrix of $$$M$$$ which contains at least one of every number from 1 to $$$k$$$.\n\nThe first line contains three integers $$$n$$$, $$$m$$$, and $$$k$$$ ($$$1 \\le n, m ... | 0.59376 | Codeforces_34386 | C | [
"contains_all_numbers",
"solve"
] | 2 | [
[
"solve",
"contains_all_numbers"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | a77909096be9a61abf26620fd9fa61eb0c53123c | 424f4b3b4720e8a7a3532a15dff5b0cbd979f0ae | |||
v1.0 | complete | Codeforces | Codeforces_33948_C | import heapq
from collections import defaultdict
from typing import List, Tuple, Dict
def min_spanning_tree_prims(n: int, edges: List[Tuple[int, int, int]], exclude_edge: Tuple[int, int, int] = None) -> Tuple[Dict[int, List[int]], int]:
""" Function to find the minimum spanning tree using Prim's algorithm, optiona... | import heapq
from collections import defaultdict
def min_spanning_tree_prims(n, edges, exclude_edge=None):
if exclude_edge:
edges.remove(exclude_edge)
# Priority queue to select the smallest weight edge
pq = []
for u, v, d in edges:
heapq.heappush(pq, (d, u, v))
# To track... | from solution import minimum_guiding_signs, min_spanning_tree_prims
def test_min_spanning_tree_prims():
edges = [(1, 2, 1), (1, 3, 2), (2, 3, 4), (2, 4, 3), (3, 4, 5)]
min_edges, total_weight = min_spanning_tree_prims(4, edges.copy(), exclude_edge=(3, 4, 5))
assert total_weight == 6
assert len(min_edge... | [
{
"docstring": null,
"function_declaration": "def min_spanning_tree_prims(n, edges, exclude_edge=None):",
"function_name": "min_spanning_tree_prims",
"parameter_list": "(n, edges, exclude_edge=None)"
},
{
"docstring": null,
"function_declaration": "def minimum_guiding_signs(n, edges):",
... | [
0,
0,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import heapq\n\ndef find_min_guiding_signs(n, m, edges):\n \"\"\"\n Determines the minimal number of guiding signs needed if the longest edge is closed.... | trial_gpt4o_2 | {
"original_instruction": "Heidi is studying the structure of a large archaeological site that can be modeled as a simple undirected graph. Each area of the site is represented as a vertex, and a direct connection between two areas is represented as an edge. Heidi wants to place guiding signs in such a way that from ... | 0.690417 | Codeforces_33948 | C | [
"min_spanning_tree_prims",
"minimum_guiding_signs",
"process_input"
] | 3 | [
[
"minimum_guiding_signs",
"min_spanning_tree_prims"
],
[
"process_input",
"minimum_guiding_signs"
]
] | 2 | [
"process_input"
] | false | [] | false | pytest | true | [] | true | 038dc866dff027f5193f5d0c7d3fb03fe0b340bd | b50bf3fe0d0703666f3717bf856c36a03b5da170 | |||
v1.0 | complete | Codeforces | Codeforces_34604_C | def minimal_total_cost(n: int, cost_matrix: List[List[int]]) -> int:
""" Calculate the minimal total cost required to connect all the cities
such that there's a path between any two cities, directly or indirectly.
>>> minimal_total_cost(3, [[0, 1, 3], [1, 0, 2], [3, 2, 0]])
3
>>> minimal_total_cost(... | def find_mst_cost(n, cost_matrix):
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... | def test_minimal_total_cost_example():
n = 3
cost_matrix = [
[0, 1, 3],
[1, 0, 2],
[3, 2, 0]
]
assert minimal_total_cost(n, cost_matrix) == 3
def test_minimal_total_cost_all_equal():
n = 4
cost_matrix = [
[0, 1, 1, 1],
[1, 0, 1, 1],
[1, 1, 0, 1],
... | [
{
"docstring": null,
"function_declaration": "def find_mst_cost(n, cost_matrix):",
"function_name": "find_mst_cost",
"parameter_list": "(n, cost_matrix)"
},
{
"docstring": null,
"function_declaration": "def minimal_total_cost(n, cost_matrix):",
"function_name": "minimal_total_cost",
... | [
1,
0,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def find_mst_cost(n, cost_matrix):\n def find(parent, i):\n if parent[i] == i:\n return i\n else:\n return find(parent,... | trial_gpt4o_0 | {
"original_instruction": "In a distant kingdom, there's a peculiar road network connecting its many cities. Each city has a bidirectional road to every other city. However, the cost to build and maintain these roads varies depending on the pair of cities. The kingdom's ruler has decided to construct a minimal-cost n... | 0.680623 | Codeforces_34604 | C | [
"find_mst_cost",
"minimal_total_cost"
] | 2 | [
[
"minimal_total_cost",
"find_mst_cost"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | e111c0189365a033bacf501512f9703ef9e21621 | 40d0991ffd243ff54c958756b9005b4bb0b79924 | |||
v1.0 | complete | Codeforces | Codeforces_34513_C | from typing import List
def sieve_of_eratosthenes(max_num: int) -> List[int]:
""" Returns a list of primes up to max_num (inclusive) using the Sieve of Eratosthenes algorithm. """
is_prime = [True] * (max_num + 1)
is_prime[0] = is_prime[1] = False
for start in range(2, int(max_num**0.5) + 1):
... | def sieve_of_eratosthenes(max_num):
""" Returns a list of primes up to max_num (inclusive) using the Sieve of Eratosthenes algorithm. """
is_prime = [True] * (max_num + 1)
is_prime[0] = is_prime[1] = False
for start in range(2, int(max_num**0.5) + 1):
if is_prime[start]:
for i in ra... | from solution import min_prime_blocks
def test_min_prime_blocks():
assert min_prime_blocks(1) == 1
assert min_prime_blocks(2) == 1
assert min_prime_blocks(3) == 1
assert min_prime_blocks(4) == 2
assert min_prime_blocks(5) == 1
assert min_prime_blocks(6) == 2
assert min_prime_blocks(10) == 2... | [
{
"docstring": "Returns a list of primes up to max_num (inclusive) using the Sieve of Eratosthenes algorithm. ",
"function_declaration": "def sieve_of_eratosthenes(max_num):",
"function_name": "sieve_of_eratosthenes",
"parameter_list": "(max_num)"
},
{
"docstring": "Returns the minimum numbe... | [
0,
0,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(num):\n if num <= 1:\n return False\n if num <= 3:\n return True\n if num % 2 == 0 or num % 3 == 0:\n return False\... | trial_gpt4o_2 | {
"original_instruction": "You've been hired to help a software development team optimize their data storage system. The storage system has a specific limitation: it can only store data blocks if the block size is a prime number. Given an integer `n`, you are tasked with determining the smallest number of prime-sized... | 0.64829 | Codeforces_34513 | C | [
"sieve_of_eratosthenes",
"min_prime_blocks"
] | 2 | [
[
"min_prime_blocks",
"sieve_of_eratosthenes"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | f209511c277955fbfa82429a3fa206f6cd8c1fec | f3cef69a4d2ffca9b568e772761abc8a93ea00f2 | |||
v1.0 | complete | Codeforces | Codeforces_34384_C | def sieve(n):
"""
Implements the Sieve of Eratosthenes to find all prime numbers up to n.
"""
def precompute_prime_count(n, is_prime):
"""
Precompute the prime count up to each number from 1 to n.
"""
def count_primes_in_range(prime_count, a, b):
"""
Count the number of primes in the r... | def sieve(n):
"""
Implements the Sieve of Eratosthenes to find all prime numbers up to n.
"""
is_prime = [True] * (n + 1)
is_prime[0] = is_prime[1] = False
p = 2
while p * p <= n:
if is_prime[p]:
for i in range(p * p, n + 1, p):
is_prime[i] = False
... | from solution import sieve, precompute_prime_count, count_primes_in_range, process_queries
def test_sieve():
assert sieve(10) == [False, False, True, True, False, True, False, True, False, False, False]
assert sieve(1) == [False, False]
def test_precompute_prime_count():
assert precompute_prime_count(10,... | [
{
"docstring": "Implements the Sieve of Eratosthenes to find all prime numbers up to n.",
"function_declaration": "def sieve(n):",
"function_name": "sieve",
"parameter_list": "(n)"
},
{
"docstring": "Precompute the prime count up to each number from 1 to n.",
"function_declaration": "def... | [
0,
0,
0,
1,
0
] | 1 | hard | 0.2 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def sieve_of_eratosthenes(max_num):\n sieve = [True] * (max_num + 1)\n sieve[0] = sieve[1] = False # 0 and 1 are not primes\n for start in range(2, ... | trial_gpt4o_3 | {
"original_instruction": "Sandra is fascinated by prime numbers and decided to create a game where she challenges others to solve a specific prime-related problem. \n\nGiven an integer \\( n \\) and a set of queries, each query consists of a pair of integers \\( (a, b) \\). For each query, determine how many prime n... | 0.710292 | Codeforces_34384 | C | [
"sieve",
"precompute_prime_count",
"count_primes_in_range",
"process_queries"
] | 4 | [
[
"process_queries",
"count_primes_in_range"
],
[
"process_queries",
"precompute_prime_count"
],
[
"process_queries",
"sieve"
]
] | 3 | [
"process_queries"
] | false | [] | false | pytest | true | [] | true | 904e68dc63a4359b7c71ee82e5e11889d007f51e | 8865b5a97f1b050b55a778cb9ba37157ca254e2a | |||
v1.0 | complete | Codeforces | Codeforces_34667_C | def validate_parentheses(t: int, test_cases: List[str]) -> List[str]:
"""
You are given a string of parentheses. A string of parentheses is valid if:
1) Open brackets are closed by the same type of brackets.
2) Open brackets are closed in the correct order.
In this problem, we only have the types of... | def validate_parentheses(t, test_cases):
results = []
for s in test_cases:
if is_valid(s):
results.append("YES")
elif can_be_made_valid_by_removing_one(s):
results.append("YES")
else:
results.append("NO")
return results
def is_valid(s):
balanc... | from solution import validate_parentheses, run_validate_parentheses
def test_validate_parentheses():
t = 5
test_cases = ["()", "(())", "())", "))((", "(()(("]
expected = ["YES", "YES", "YES", "NO", "NO"]
result = validate_parentheses(t, test_cases)
assert result == expected
def test_validate_paren... | [
{
"docstring": null,
"function_declaration": "def validate_parentheses(t, test_cases):",
"function_name": "validate_parentheses",
"parameter_list": "(t, test_cases)"
},
{
"docstring": null,
"function_declaration": "def is_valid(s):",
"function_name": "is_valid",
"parameter_list":... | [
0,
0,
0,
0,
0,
1,
0,
0,
1,
0
] | 2 | hard | 0.2 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def validate_parentheses(s):\n \"\"\"\n Returns \"YES\" if the string s can be made valid by removing at most one character,\n otherwise returns \"NO... | trial_gpt4o_8 | {
"original_instruction": "You are given a string of parentheses. A string of parentheses is valid if:\n1) Open brackets are closed by the same type of brackets.\n2) Open brackets are closed in the correct order.\nIn this problem, we only have the types of brackets '(' and ')'.\n\nYou are given a string s containing ... | 0.813641 | Codeforces_34667 | C | [
"validate_parentheses",
"is_valid",
"can_be_made_valid_by_removing_one",
"run_validate_parentheses"
] | 4 | [
[
"can_be_made_valid_by_removing_one",
"is_valid"
],
[
"run_validate_parentheses",
"validate_parentheses"
],
[
"validate_parentheses",
"can_be_made_valid_by_removing_one"
],
[
"validate_parentheses",
"is_valid"
]
] | 4 | [] | false | [] | false | pytest | true | [] | true | 8313ae1327f30a8cc3086b1d1857a8c10fa10f77 | 62bd828003e6cdacdad1689d047dd07b7c62307e | |||
v1.0 | complete | Codeforces | Codeforces_34535_C | def min_bundles(test_cases: List[List[int]]) -> List[int]:
"""
Calculate the minimum number of bundles needed for the rods in each test case.
Each bundle must contain rods with the same length.
Args:
test_cases (List[List[int]]): List of test cases where each test case contains a list of rod l... | def min_bundles(test_cases):
results = []
for lengths in test_cases:
unique_lengths = set(lengths)
results.append(len(unique_lengths))
return results
# Helper function to parse input
def parse_input(input_str):
lines = input_str.strip().split("\n")
t = int(lines[0])
test_cases ... | import pytest
from solution import solve, parse_input, min_bundles
def test_parse_input():
input_str = "2\n5\n1 2 2 3 1\n4\n4 4 4 4"
expected_output = [
[1, 2, 2, 3, 1],
[4, 4, 4, 4]
]
assert parse_input(input_str) == expected_output
def test_min_bundles():
test_cases = [
[... | [
{
"docstring": null,
"function_declaration": "def min_bundles(test_cases):",
"function_name": "min_bundles",
"parameter_list": "(test_cases)"
},
{
"docstring": null,
"function_declaration": "def parse_input(input_str):",
"function_name": "parse_input",
"parameter_list": "(input_s... | [
0,
1,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def min_bundles(t, test_cases):\n \"\"\"\n Returns the minimum number of bundles needed to group rods with the same length for each test case.\n \n ... | trial_gpt4o_2 | {
"original_instruction": "You are working in a factory that produces metal rods. Each rod is characterized by its length in meters, and you need to group the rods into bundles. To ensure stability during transportation, each bundle must contain rods with the same length.\n\nYour task is to calculate the minimum numb... | 0.544765 | Codeforces_34535 | C | [
"min_bundles",
"parse_input",
"solve"
] | 3 | [
[
"solve",
"min_bundles"
],
[
"solve",
"parse_input"
]
] | 2 | [
"parse_input"
] | false | [] | false | pytest | true | [] | true | 7ddb83e2b242835545bc89b2e68bf89dacbb92be | 20724766ff4589aa0be24c8ed073fdc9985b1271 | |||
v1.0 | complete | Codeforces | Codeforces_34361_C | def numIslands(grid):
"""Given an m × n grid map where '1's represent land and '0's represent water,
return the number of islands. An island is surrounded by water and is formed
by connecting adjacent lands horizontally or vertically. You may assume all
four edges of the grid are all surrounded by wa... | def numIslands(grid):
if not grid:
return 0
m, n = len(grid), len(grid[0])
visited = [[False] * n for _ in range(m)]
def dfs(i, j):
stack = [(i, j)]
while stack:
x, y = stack.pop()
for dx, dy in [(-1, 0), (1, 0), (0, -1), (0, 1)]:
nx, ... | from solution import numIslands, find_num_of_islands_from_input
def test_single_island():
m = 4
n = 5
grid_lines = [
"11110",
"11010",
"11000",
"00000"
]
assert find_num_of_islands_from_input(m, n, grid_lines) == 1
def test_multiple_islands():
m = 4
n = 5
... | [
{
"docstring": null,
"function_declaration": "def numIslands(grid):",
"function_name": "numIslands",
"parameter_list": "(grid)"
},
{
"docstring": null,
"function_declaration": "def find_num_of_islands_from_input(m, n, grid_lines):",
"function_name": "find_num_of_islands_from_input",
... | [
0,
0,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def numIslands(grid):\n if not grid:\n return 0\n m, n = len(grid), len(grid[0])\n visited = [[False] * n for _ in range(m)]\n\n def dfs(i,... | trial_gpt4o_2 | {
"original_instruction": "You have a grid of size m × n representing a map where '1's represent land and '0's represent water. A cell is defined to be connected to another cell if they share edges (no diagonals). An island on this grid is a group of connected '1's (land cells) surrounded by '0's (water). A single co... | 0.555193 | Codeforces_34361 | C | [
"numIslands",
"find_num_of_islands_from_input"
] | 2 | [
[
"find_num_of_islands_from_input",
"numIslands"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 21c33c7b63fa2ef1da67efe2ca33b6eba43330a6 | 84a483e8a012db41836a99fba2fe44c1cb350658 | |||
v1.0 | complete | Codeforces | Codeforces_34442_C | from collections import deque, defaultdict
import itertools
def bfs_shortest_path(graph, start):
"""
Find the shortest path from start to all other nodes using BFS.
"""
distances = {start: 0}
queue = deque([start])
while queue:
node = queue.popleft()
current_distance = dist... | from collections import deque, defaultdict
import itertools
def bfs_shortest_path(graph, start):
"""
Find the shortest path from start to all other nodes using BFS.
"""
distances = {start: 0}
queue = deque([start])
while queue:
node = queue.popleft()
current_distance = dist... | from solution import find_minimum_distance
def test_find_minimum_distance():
assert find_minimum_distance(5, 6, 3, [(1, 2), (2, 3), (3, 4), (4, 5), (5, 1), (3, 5)], [1, 5, 4], 1) == 2
assert find_minimum_distance(5, 6, 3, [(1, 2), (2, 3), (3, 4), (4, 5), (5, 1), (3, 5)], [2, 3, 4], 1) == 3
assert find_mini... | [
{
"docstring": "Find the shortest path from start to all other nodes using BFS.",
"function_declaration": "def bfs_shortest_path(graph, start):",
"function_name": "bfs_shortest_path",
"parameter_list": "(graph, start)"
},
{
"docstring": null,
"function_declaration": "def find_minimum_dis... | [
0,
0,
0,
0,
0,
0,
0,
0,
1,
1
] | 2 | hard | 0.2 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import heapq\n\ndef min_distance_to_visit_stations(n, m, k, connections, desired_stations, start_station):\n # Create adjacency list for the graph\n gra... | trial_gpt4o_9 | {
"original_instruction": "You are given an underground system of interconnected stations represented as a graph. Each station is represented by a unique integer, and each bi-directional connection between the stations is represented by a pair of integers indicating a direct path.\n\nA traveler starts their journey a... | 0.608892 | Codeforces_34442 | C | [
"bfs_shortest_path",
"find_minimum_distance"
] | 2 | [
[
"find_minimum_distance",
"bfs_shortest_path"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 95bee5f49826bc94464effc5e3f0df4993355885 | b777d063140c4c2f1e9e60116128e8f0f6625be5 | |||
v1.0 | complete | Codeforces | Codeforces_34972_C | def can_be_palindrome_by_removing_one_char(s: str) -> bool:
""" Determine if it is possible to make the string a palindrome by removing exactly one character.
>>> can_be_palindrome_by_removing_one_char("abca")
True
>>> can_be_palindrome_by_removing_one_char("abc")
False
"""
def check_palindrome... | def can_be_palindrome_by_removing_one_char(s):
def is_palindrome(x):
return x == x[::-1]
l, r = 0, len(s) - 1
while l < r:
if s[l] != s[r]:
return is_palindrome(s[l+1:r+1]) or is_palindrome(s[l:r])
l += 1
r -= 1
return True
def check_palindromes(t, strings):... | from solution import check_palindromes
def test_example_cases():
assert check_palindromes(3, ["abca", "abc", "a"]) == ["YES", "NO", "YES"]
def test_single_character():
assert check_palindromes(2, ["a", "b"]) == ["YES", "YES"]
def test_complete_palindrome():
assert check_palindromes(1, ["racecar"]) == ["Y... | [
{
"docstring": null,
"function_declaration": "def can_be_palindrome_by_removing_one_char(s):",
"function_name": "can_be_palindrome_by_removing_one_char",
"parameter_list": "(s)"
},
{
"docstring": null,
"function_declaration": "def check_palindromes(t, strings):",
"function_name": "ch... | [
0,
0,
0,
1,
0
] | 1 | hard | 0.2 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def can_form_palindrome_by_removing_one_char(s):\n def is_palindrome_range(i, j):\n while i < j:\n if s[i] != s[j]:\n retu... | trial_gpt4o_3 | {
"original_instruction": "You are given a string consisting of lowercase Latin letters. You can remove any one character from it. Your task is to determine if it is possible to make the string a palindrome by removing exactly one character. \n\nA palindrome is a string that reads the same forward and backward.\n\nTh... | 0.802845 | Codeforces_34972 | C | [
"can_be_palindrome_by_removing_one_char",
"check_palindromes",
"main"
] | 3 | [
[
"check_palindromes",
"can_be_palindrome_by_removing_one_char"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 87ce03c5b4a1d12d8b1a3f6f1121271700902684 | 23ff4f25e8930e7df69b81057c1cb606d9765c35 | |||
v1.0 | complete | Codeforces | Codeforces_34721_C | from typing import List, Tuple
def find_shortest_path(n: int, m: int, a: int, b: int, edges: List[Tuple[int, int, int]]) -> int:
"""
Find the length of the shortest path between two given nodes a and b
in an undirected weighted graph with n vertices and m edges.
Parameters:
- n (int): The nu... | import heapq
def dijkstra(n, edges, a, b):
graph = [[] for _ in range(n + 1)]
for u, v, w in edges:
graph[u].append((v, w))
graph[v].append((u, w))
pq = [(0, a)]
distances = {i: float('inf') for i in range(1, n + 1)}
distances[a] = 0
while pq:
current_dist... | from solution import find_shortest_path
def test_example_case():
n = 5
m = 6
a, b = 1, 5
edges = [(1, 2, 2), (2, 3, 3), (3, 4, 1), (4, 5, 2), (2, 5, 6), (1, 5, 10)]
assert find_shortest_path(n, m, a, b, edges) == 8
def test_disconnected_graph():
n = 4
m = 2
a, b = 1, 4
edges = [(1,... | [
{
"docstring": null,
"function_declaration": "def dijkstra(n, edges, a, b):",
"function_name": "dijkstra",
"parameter_list": "(n, edges, a, b)"
},
{
"docstring": null,
"function_declaration": "def find_shortest_path(n, m, a, b, edges):",
"function_name": "find_shortest_path",
"pa... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import heapq\nimport sys\n\ndef shortest_path(n, m, a, b, edges):\n graph = {i: [] for i in range(1, n+1)}\n for u, v, w in edges:\n graph[u].app... | trial_gpt4o_2 | {
"original_instruction": "Andrei loves playing with graphs. He has an undirected weighted graph with n vertices and m edges. Each edge has a positive integer weight. He wants to find the length of the shortest path between two given nodes a and b.\n\nEach line contains four integers: n (2 ≤ n ≤ 1000) — the number of... | 0.747761 | Codeforces_34721 | C | [
"dijkstra",
"find_shortest_path"
] | 2 | [
[
"find_shortest_path",
"dijkstra"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 4a715c7436392d14d6e479b491cb32d3f82242df | 6911a0b104b6360d3852c5a1f0328416fd951f55 | |||
v1.0 | complete | Codeforces | Codeforces_34839_C | from typing import List, Tuple
def minimum_additional_flights(test_cases: List[Tuple[int, int, List[Tuple[int, int]]]]) -> List[int]:
"""
For each test case, determine the minimum number of additional direct flights required to ensure no city is left isolated.
Args:
test_cases: A list of tuples, ... | from collections import defaultdict
def dfs(node, visited, adj_list):
stack = [node]
while stack:
current = stack.pop()
for neighbor in adj_list[current]:
if neighbor not in visited:
visited.add(neighbor)
stack.append(neighbor)
def count_isolated_gro... | from solution import minimum_additional_flights
def test_minimum_with_isolated():
assert minimum_additional_flights([
(6, 4, [(1, 2), (2, 3), (4, 5), (5, 6)])
]) == [1]
def test_minimum_with_connected():
assert minimum_additional_flights([
(5, 5, [(1, 2), (2, 3), (3, 4), (4, 5), (5, 1)])
... | [
{
"docstring": null,
"function_declaration": "def dfs(node, visited, adj_list):",
"function_name": "dfs",
"parameter_list": "(node, visited, adj_list)"
},
{
"docstring": null,
"function_declaration": "def count_isolated_groups(n, edges):",
"function_name": "count_isolated_groups",
... | [
0,
1,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def min_additional_flights(test_cases):\n \"\"\"\n Returns the minimum number of additional flights required to ensure no city is left isolated.\n \"... | trial_gpt4o_2 | {
"original_instruction": "You are developing a flight scheduling program for an airline company. There are n direct flights available, each connecting two different cities. The company wants to schedule additional direct flights such that there are no cities left isolated. A city is considered isolated if it cannot ... | 0.634479 | Codeforces_34839 | C | [
"dfs",
"count_isolated_groups",
"minimum_additional_flights"
] | 3 | [
[
"count_isolated_groups",
"dfs"
],
[
"minimum_additional_flights",
"count_isolated_groups"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | e544bae395e01fe6f58229754b824adde8891a97 | d99d059ab3cb92705115a3716f785be1ed516fbf | |||
v1.0 | complete | Codeforces | Codeforces_34588_C | from typing import List, Tuple
def reverse_row(grid: List[List[int]], row_idx: int) -> None:
"""Reverses the elements of the given row in the grid."""
pass
def reverse_column(grid: List[List[int]], col_idx: int) -> None:
"""Reverses the elements of the given column in the grid."""
pass
def perform_op... | def reverse_row(grid, row_idx):
grid[row_idx] = grid[row_idx][::-1]
def reverse_column(grid, col_idx):
n = len(grid)
for i in range(n // 2):
grid[i][col_idx], grid[n-i-1][col_idx] = grid[n-i-1][col_idx], grid[i][col_idx]
def perform_operations(n, queries):
# Initialize the grid with all zeros
... | from solution import perform_operations
def test_example_case():
n = 3
q = 4
queries = [(1, 2), (2, 3), (1, 2), (2, 3)]
result = perform_operations(n, queries)
expected = [
[0, 0, 0],
[0, 0, 0],
[0, 0, 0]
]
assert result == expected
def test_single_row_reverse():
... | [
{
"docstring": null,
"function_declaration": "def reverse_row(grid, row_idx):",
"function_name": "reverse_row",
"parameter_list": "(grid, row_idx)"
},
{
"docstring": null,
"function_declaration": "def reverse_column(grid, col_idx):",
"function_name": "reverse_column",
"parameter_... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def process_grid(n, q, queries):\n grid = [[0 for _ in range(n)] for _ in range(n)]\n \n for rc, c in queries:\n c -= 1 # Convert to 0-based ... | trial_gpt4o_2 | {
"original_instruction": "Given a grid of size \\( n \\times n \\), you have to perform \\( q \\) queries. Each query is described as two integers \\( rc \\) and \\( c \\), where \\( rc \\) can be either 1 or 2, and \\( c \\) is an integer from 1 to \\( n \\). \n\n- If \\( rc \\) is 1, it indicates a row \\( c \\). ... | 0.577339 | Codeforces_34588 | C | [
"reverse_row",
"reverse_column",
"perform_operations"
] | 3 | [
[
"perform_operations",
"reverse_column"
],
[
"perform_operations",
"reverse_row"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 1b60666efc0941623cecdbf80935283e960af393 | 00f33689c042cd34d8a36d59d0a0bfa84c19a9d7 | |||
v1.0 | complete | Codeforces | Codeforces_34573_C | def kruskal_minimum_risk(n, roads):
"""
Kruskal's algorithm to find the minimum total risk factor required to connect all territories.
"""
# Sort the roads by their risk factor (weight)
roads.sort(key=lambda x: x[2])
# Helper function to find the parent of a node with path compression
d... | def kruskal_minimum_risk(n, roads):
"""
Kruskal's algorithm to find the minimum spanning tree's total risk factor.
"""
# Sort the roads by their risk factor (weight)
roads.sort(key=lambda x: x[2])
# Helper function to find the parent of a node with path compression
def find(parent, i):
... | def test_kruskal_minimum_risk():
# Example test case from the problem statement
n = 4
m = 5
roads = [
[1, 2, 3],
[1, 3, 1],
[2, 3, 3],
[2, 4, 6],
[3, 4, 5]
]
assert minimum_total_risk(n, m, roads) == 9
# Test case with only two territories and one roa... | [
{
"docstring": "Kruskal's algorithm to find the minimum spanning tree's total risk factor.",
"function_declaration": "def kruskal_minimum_risk(n, roads):",
"function_name": "kruskal_minimum_risk",
"parameter_list": "(n, roads)"
},
{
"docstring": null,
"function_declaration": "def minimum... | [
0,
0,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_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(parent... | trial_gpt4o_2 | {
"original_instruction": "In a certain land, there is a kingdom ruled by King Geoffrey. The kingdom is divided into n territories connected by m bidirectional roads. Each road connects exactly two different territories. \n\nUnfortunately, due to the rise of bandits, each road has a certain risk factor associated wit... | 0.590293 | Codeforces_34573 | C | [
"kruskal_minimum_risk",
"minimum_total_risk"
] | 2 | [
[
"minimum_total_risk",
"kruskal_minimum_risk"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | 37b58be50c02f4789ae08f48a4f82c008985aefc | f173ae79d90e11ca8807e8defc1dff4b457a940c | |||
v1.0 | complete | Codeforces | Codeforces_35162_C | import math
from typing import List, Tuple
def euclidean_distance(p1: Tuple[int, int], p2: Tuple[int, int]) -> float:
""" Calculate the Euclidean distance between two points.
Args:
p1: Tuple containing coordinates of the first point (x1, y1).
p2: Tuple containing coordinates of the second point (x... | import math
def euclidean_distance(p1, p2):
return math.sqrt((p1[0] - p2[0]) ** 2 + (p1[1] - p2[1]) ** 2)
def closest_pair_of_points(points):
points = sorted(points, key=lambda x: x[0])
def closest_pair_rec(start, end):
if end - start <= 3:
min_dist = float('inf')
for i in... | from solution import closest_pair_of_points
def test_small_number_of_points():
points = [(0, 0), (3, 4), (7, 7), (3, 0)]
assert abs(closest_pair_of_points(points) - 3.0) < 1e-6
def test_minimum_possible_distance():
points = [(0, 0), (0, 0)]
assert abs(closest_pair_of_points(points) - 0.0) < 1e-6
def ... | [
{
"docstring": null,
"function_declaration": "def euclidean_distance(p1, p2):",
"function_name": "euclidean_distance",
"parameter_list": "(p1, p2)"
},
{
"docstring": null,
"function_declaration": "def closest_pair_of_points(points):",
"function_name": "closest_pair_of_points",
"p... | [
0,
0,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from math import sqrt\nfrom itertools import combinations\n\ndef closest_pair(points):\n def distance(point1, point2):\n x1, y1 = point1\n x2... | trial_gpt4o_2 | {
"original_instruction": "You are given a set of n points in a 2D plane, each point represented by its coordinates (xi, yi). Your task is to determine the closest pair of points among the given set. The distance between two points (xi, yi) and (xj, yj) is defined as the Euclidean distance:\n\n\\[d((xi, yi), (xj, yj)... | 0.739984 | Codeforces_35162 | C | [
"euclidean_distance",
"closest_pair_of_points"
] | 2 | [
[
"closest_pair_of_points",
"euclidean_distance"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 856e0d82aead66bebbdf6ee076fab4aa825387cb | 58fca8bb4d622e3863d8ac8326897aa9fc69d5a9 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.