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_4776_C
from typing import List def is_feasible(capacities: List[int], tasks: List[int], max_load: int) -> bool: """Check if it is feasible to distribute tasks such that no server exceeds the max load. >>> is_feasible([10, 10, 10], [5, 5, 5, 5], 10) True >>> is_feasible([10, 10, 10], [10, 10, 10, 10], 10) ...
def is_feasible(capacities, tasks, max_load): servers = len(capacities) remaining_capacity = sorted(capacities, reverse=True) task_index = 0 while task_index < len(tasks): allocated = False for i in range(servers): if remaining_capacity[i] >= tasks[task_index]: ...
def test_is_feasible(): capacities = [10, 10, 10] tasks = [5, 5, 5, 5] max_load = 10 assert is_feasible(capacities, tasks, max_load) == True capacities = [10, 10, 10] tasks = [10, 10, 10, 10] max_load = 10 assert is_feasible(capacities, tasks, max_load) == False def test_min_max_load()...
[ { "docstring": null, "function_declaration": "def is_feasible(capacities, tasks, max_load):", "function_name": "is_feasible", "parameter_list": "(capacities, tasks, max_load)" }, { "docstring": null, "function_declaration": "def min_max_load(n, m, capacities, tasks):", "function_name...
[ 0, 0, 0, 0, 0, 0, 1, 0, 0, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def can_distribute_tasks(servers, tasks, max_load):\n \"\"\"\n Helper function to determine if tasks can be distributed to servers\n such that no ser...
trial_gpt4o_6
{ "original_instruction": "A company managing a network of servers has noticed that some tasks are failing due to overloaded servers. They want to optimize the way tasks are assigned to servers to ensure the load is balanced, thereby minimizing the chances of failure and maximizing efficiency.\n\nThere are n servers ...
0.583505
Codeforces_4776
C
[ "is_feasible", "min_max_load", "solve" ]
3
[ [ "min_max_load", "is_feasible" ], [ "solve", "min_max_load" ] ]
2
[]
false
[]
false
pytest
false
[]
true
de9cbaf1e0236e4e4c0bfa9aaa8d67ee3465f86e
dd4dcd3006bc87d970a350ea4dea8e7251113abd
v1.0
complete
Codeforces
Codeforces_5461_C
def is_palindrome(num: int) -> bool: """ Returns True if num is a palindrome, otherwise False. >>> is_palindrome(121) True >>> is_palindrome(123) False >>> is_palindrome(12321) True >>> is_palindrome(123456) False """ def largest_palindrome_product(n: int) -> int: """ Returns th...
def is_palindrome(num): """ Returns True if num is a palindrome, otherwise False. """ return str(num) == str(num)[::-1] def largest_palindrome_product(n): """ Returns the largest palindromic number made from the product of two n-digit numbers. """ if n < 1 or n > 3: raise ValueE...
from solution import is_palindrome, largest_palindrome_product def test_is_palindrome(): assert is_palindrome(121) is True assert is_palindrome(123) is False assert is_palindrome(12321) is True assert is_palindrome(123456) is False def test_largest_palindrome_product_1_digit(): assert largest_pali...
[ { "docstring": "Returns True if num is a palindrome, otherwise False.", "function_declaration": "def is_palindrome(num):", "function_name": "is_palindrome", "parameter_list": "(num)" }, { "docstring": "Returns the largest palindromic number made from the product of two n-digit numbers.", ...
[ 1, 1, 1, 1, 1, 1, 1, 1, 0, 1 ]
9
easy
0.9
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_palindrome(number):\n \"\"\"\n Checks if a given number is a palindrome.\n \"\"\"\n return str(number) == str(number)[::-1]\n\ndef largest_...
trial_gpt4o_9
{ "original_instruction": "Alyssa P. enjoys solving puzzles and recently came across an intriguing number problem. She learned about Palindromic Numbers; numbers that read the same backward as forward, like 121 or 909.\n\nOne day, she decided to challenge herself by finding the largest palindromic number that can be ...
0.709662
Codeforces_5461
C
[ "is_palindrome", "largest_palindrome_product" ]
2
[ [ "largest_palindrome_product", "is_palindrome" ] ]
1
[]
false
[]
false
pytest
true
[]
true
985e494599999d2bd7634081a786bf1bc1555c7d
29604dc79fea9e76dcbfedffaa49a8e7d2a915a8
v1.0
complete
Codeforces
Codeforces_2780_C
from typing import List, Tuple from collections import defaultdict, deque def max_path_under_weight(n: int, k: int, edges: List[Tuple[int, int, int]]) -> int: """ Find the maximum length of a path in the tree such that no edge in the path exceeds the given weight k. Parameters: n (int): Numbe...
from collections import defaultdict, deque def bfs_farthest_node(start, graph, k): """ Perform BFS to find the farthest node from the start node considering only edges with weight <= k. """ visited = {start} queue = deque([(start, 0)]) # (current_node, current_distance) farthest_node = sta...
from solution import max_path_under_weight def test_example(): edges = [(1, 2, 3), (1, 3, 10), (2, 4, 2), (2, 5, 4)] assert max_path_under_weight(5, 4, edges) == 2 def test_all_edges_below_k(): edges = [(1, 2, 1), (1, 3, 1), (2, 4, 1), (2, 5, 1)] assert max_path_under_weight(5, 2, edges) == 3 def tes...
[ { "docstring": "Perform BFS to find the farthest node from the start node\nconsidering only edges with weight <= k.", "function_declaration": "def bfs_farthest_node(start, graph, k):", "function_name": "bfs_farthest_node", "parameter_list": "(start, graph, k)" }, { "docstring": "Function to ...
[ 0, 0, 0, 0, 0, 0, 1, 0, 0, 1 ]
2
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def dfs(graph, node, k, visited):\n visited[node] = True\n max_length = 0\n for neighbor, weight in graph[node]:\n if not visited[neighbor] an...
trial_gpt4o_6
{ "original_instruction": "You are given an unrooted tree with `n` nodes, where each node is numbered from 1 to `n` and every edge has a certain weight. A tree is a connected acyclic graph. In other words, there are no cycles in the graph. You are required to find the maximum length of a path in the tree such that th...
0.740248
Codeforces_2780
C
[ "bfs_farthest_node", "max_path_under_weight" ]
2
[ [ "max_path_under_weight", "bfs_farthest_node" ] ]
1
[]
false
[]
false
pytest
true
[]
true
22f480d52fa3ffdf00cbcec0e3cd7bebc0508ecd
703c96618cdd082dbf104acb5d50a56b35486f1d
v1.0
complete
Codeforces
Codeforces_5096_C
from typing import List def generate_substrings(s: str) -> List[str]: """ Generate all possible substrings of the given string s. >>> generate_substrings("abc") ['a', 'ab', 'abc', 'b', 'bc', 'c'] """ def find_kth_lexicographical_substring(s: str, k: int) -> str: """ Find the k-th lexic...
def generate_substrings(s): """ Generate all possible substrings of the given string s. """ n = len(s) substrings = set() for len_sub in range(1, n + 1): for start in range(n - len_sub + 1): substrings.add(s[start:start + len_sub]) return sorted(substrings) def find_kth_...
from solution import generate_substrings, find_kth_lexicographical_substring def test_generate_substrings(): s = "abc" expected_result = ['a', 'ab', 'abc', 'b', 'bc', 'c'] assert generate_substrings(s) == expected_result def test_find_kth_lexicographical_substring(): s = "abc" assert find_kth_lexi...
[ { "docstring": "Generate all possible substrings of the given string s.", "function_declaration": "def generate_substrings(s):", "function_name": "generate_substrings", "parameter_list": "(s)" }, { "docstring": "Find the k-th lexicographical substring of s.", "function_declaration": "def...
[ 0, 0, 1, 0, 0, 0, 0, 0, 0, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def kth_lexicographical_substring(n, q, s, queries):\n \"\"\"\n Returns k-th lexicographical substring of s for each query in queries.\n If no such s...
trial_gpt4o_2
{ "original_instruction": "You are given a string s with length n and q queries. The i-th query consists of an integer k which asks you to determine the lexicographically k-th substring of s.\n\nThe first line contains two integers n, q (1 ≤ n ≤ 1000, 1 ≤ q ≤ 100) — the length of the string and the number of queries....
0.716844
Codeforces_5096
C
[ "generate_substrings", "find_kth_lexicographical_substring" ]
2
[ [ "find_kth_lexicographical_substring", "generate_substrings" ] ]
1
[]
false
[]
false
pytest
true
[]
true
567ddb4aed041683bc8b9b2557a008cc8fd33c4b
75585854ee04f955bb2185662a4c9d92a39bf75e
v1.0
complete
Codeforces
Codeforces_5287_C
def minimize_maximum_workload(n: int, m: int, difficulties: List[int]) -> int: """ Minimize the maximum workload of any worker >>> minimize_maximum_workload(3, 5, [10, 20, 30, 40, 50]) 60 >>> minimize_maximum_workload(1, 4, [10, 20, 30, 40]) 100 >>> minimize_maximum_workload(2, 4, [10, 10, 10, 10]) 20 ...
def is_valid_distribution(difficulties, n, max_workload): """ Check if it is possible to distribute tasks such that no worker has a workload exceeding max_workload """ current_sum = 0 workers_needed = 1 for task in difficulties: if current_sum + task > max_workload: work...
def test_minimize_maximum_workload_example(): assert minimize_maximum_workload(3, 5, [10, 20, 30, 40, 50]) == 60 def test_minimize_maximum_workload_single_worker(): assert minimize_maximum_workload(1, 4, [10, 20, 30, 40]) == 100 def test_minimize_maximum_workload_equal_tasks(): assert minimize_maximum_wor...
[ { "docstring": "Check if it is possible to distribute tasks such that no worker has a workload exceeding max_workload", "function_declaration": "def is_valid_distribution(difficulties, n, max_workload):", "function_name": "is_valid_distribution", "parameter_list": "(difficulties, n, max_workload)" ...
[ 1, 1, 1, 0, 1, 0, 1, 0, 0, 1 ]
6
medium
0.6
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def minimize_max_workload(n, m, difficulties):\n def can_distribute(max_workload):\n # Helper function to determine if we can distribute tasks \n ...
trial_gpt4o_9
{ "original_instruction": "In a distant galaxy, there exists a planet called Numera where the inhabitants have a peculiar way of managing work assignments. They believe in minimizing the maximum workload any individual has to bear. Here's the scenario on Numera:\n\nThere are `n` workers and `m` tasks. Each task `j` (...
0.612372
Codeforces_5287
C
[ "is_valid_distribution", "minimize_maximum_workload" ]
2
[ [ "minimize_maximum_workload", "is_valid_distribution" ] ]
1
[]
false
[]
false
pytest
false
[]
true
b7a7c17b1bc3bae73f8dbeb7ad7d0fa06ade09c7
e037bea7ce2d28879b398dfbf0491c5b32054d50
v1.0
complete
Codeforces
Codeforces_5349_C
def aria_vs_ben(n: int, string: str) -> str: """ Determine the winner of the game between Aria and Ben given the string and its length. The game is played with the following rules: - Aria and Ben take turns, with Aria starting first. - In each move, a player must choose a non-empty substring su...
def is_prime(num): """ Helper function to check if a given number is prime. """ if num <= 1: return False if num == 2: return True if num % 2 == 0: return False for i in range(3, int(num**0.5) + 1, 2): if num % i == 0: return False return True ...
from solution import aria_vs_ben def test_aria_wins_immediately(): assert aria_vs_ben(5, "abaca") == "Aria" assert aria_vs_ben(6, "abcdef") == "Aria" def test_aria_no_prime_move(): assert aria_vs_ben(3, "aaa") == "Ben" assert aria_vs_ben(5, "aaaaa") == "Ben" def test_ben_has_a_chance(): # Assumes...
[ { "docstring": "Helper function to check if a given number is prime.", "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": "Helper function to count the number of distinct characters in a string.", "function_declaration":...
[ 0, 0, 0, 0, 0, 0, 0, 0, 1, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(num):\n \"\"\"\n Helper function to check if a number is prime.\n \"\"\"\n if num <= 1:\n return False\n if num <= 3:\n ...
trial_gpt4o_8
{ "original_instruction": "Aria and Ben play a new game with a string of lowercase English letters. They move in turns, with Aria starting first. In each move, a player must choose a non-empty substring such that the number of distinct characters in this substring is a prime number, and remove it from the string. The...
0.742632
Codeforces_5349
C
[ "is_prime", "get_distinct_counts", "can_make_move", "aria_vs_ben" ]
4
[ [ "aria_vs_ben", "can_make_move" ], [ "can_make_move", "get_distinct_counts" ], [ "can_make_move", "is_prime" ] ]
3
[]
false
[]
false
pytest
true
[]
true
3020f276de1d3531c0a06379deed2a356071bda5
6132c3a00b63c8e7b52997b8d8aec1f08ef219e8
v1.0
complete
Codeforces
Codeforces_4707_C
MOD = 10**9 + 7 def count_paths(n, m, lines): """ Determine the number of distinct paths a robot can take from the top-left to the bottom-right cell in a grid with obstacles. Args: n (int): The number of rows in the grid. m (int): The number of columns in the grid. lines (List[str]): A lis...
MOD = 10**9 + 7 def num_paths(grid, n, m): if grid[0][0] == '#' or grid[n-1][m-1] == '#': return 0 dp = [[0 for _ in range(m)] for _ in range(n)] dp[0][0] = 1 for i in range(n): for j in range(m): if grid[i][j] == '#': dp[i][j] = 0 else:...
def test_num_paths(): assert count_paths(3, 3, ["...", ".#.", "..."]) == 2 assert count_paths(3, 3, ["...", "###", "..."]) == 0 assert count_paths(1, 1, ["."]) == 1 assert count_paths(2, 2, ["..", ".."]) == 2 assert count_paths(2, 2, ["#.", ".."]) == 0 assert count_paths(3, 3, [".#.", "...", ".....
[ { "docstring": null, "function_declaration": "def num_paths(grid, n, m):", "function_name": "num_paths", "parameter_list": "(grid, n, m)" }, { "docstring": null, "function_declaration": "def count_paths(n, m, lines):", "function_name": "count_paths", "parameter_list": "(n, m, lin...
[ 1, 1, 0, 1, 1, 0, 1, 1, 1, 0 ]
7
easy
0.7
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "MOD = 10**9 + 7\n\ndef num_paths(grid):\n n = len(grid)\n m = len(grid[0])\n dp = [[0] * m for _ in range(n)]\n\n # Starting point\n if grid[0]...
trial_gpt4o_8
{ "original_instruction": "You are given a rectangular grid with dimensions $$$n \\times m$$$. Each cell of the grid is either empty or contains an obstacle. A robot is initially positioned at the top-left cell of the grid and needs to reach the bottom-right cell. The robot can move either right or down at any step, ...
0.769031
Codeforces_4707
C
[ "num_paths", "count_paths" ]
2
[ [ "count_paths", "num_paths" ] ]
1
[]
false
[]
false
pytest
false
[]
true
a9dfa628b52ae85661a22bdd4a1ca3677ba6aec9
330509ff9b7cc08782fc5fbf6fe38fa01ae6d53c
v1.0
complete
Codeforces
Codeforces_3675_C
class TreeNode: def __init__(self, value=0, left=None, right=None): self.value = value self.left = left self.right = right def flip_and_invert_tree(root: TreeNode) -> TreeNode: """ Flip the binary tree vertically and invert the values of all nodes. :param root: TreeNode, th...
class TreeNode: def __init__(self, value=0, left=None, right=None): self.value = value self.left = left self.right = right def flip_and_invert_tree(root): if root is None: return None root.value = -root.value root.left, root.right = root.right, root.left fl...
from solution import flip_and_invert_tree_cases def test_single_case(): t = 1 test_cases = [ [ (1, 2, 3), (2, 4, 5), (3, -1, -1), (4, -1, -1), (5, -1, -1) ] ] expected = [[-1, -3, -2, -5, -4]] assert flip_and_invert_tree_ca...
[]
[ 1, 1, 1, 1, 1, 0, 1, 0, 1, 1 ]
8
easy
0.8
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "class TreeNode:\n def __init__(self, val=0, left=None, right=None):\n self.val = val\n self.left = left\n self.right = right\n\ndef bu...
trial_gpt4o_2
{ "original_instruction": "You are given a binary tree. Each node of the tree contains a value. Your task is to flip the binary tree vertically and invert the values of all nodes. \n\nFlipping the binary tree vertically means that the nodes of the tree are mirrored along the vertical axis, meaning that the left child...
0.574874
Codeforces_3675
C
[ "flip_and_invert_tree", "pre_order_traversal", "build_tree", "flip_and_invert_tree_cases" ]
4
[ [ "flip_and_invert_tree_cases", "build_tree" ], [ "flip_and_invert_tree_cases", "flip_and_invert_tree" ], [ "flip_and_invert_tree_cases", "pre_order_traversal" ] ]
3
[]
false
[ "TreeNode" ]
true
pytest
true
[]
true
e8ca6c7d18f6f33f2d2dd4b648082ff625d67fa5
e4e57a013d763dc1ad4ddcd69007f980287c1aad
v1.0
complete
Codeforces
Codeforces_5222_C
def min_cost_traffic_signals(n, m, street_info): """ Determine the minimum cost to place traffic signals in a city designed in a grid layout. The function computes the weight of the Minimum Spanning Tree (MST) for the given graph represented by intersections and streets. Each street has a certain traf...
import heapq def find(parent, i): if parent[i] == i: return i else: parent[i] = find(parent, parent[i]) return parent[i] def union(parent, rank, x, y): xroot = find(parent, x) yroot = find(parent, y) if rank[xroot] < rank[yroot]: parent[xroot] = yroot elif rank...
from solution import min_cost_traffic_signals def test_case_1(): n = 4 m = 5 street_info = [ (1, 2, 1), (1, 3, 2), (1, 4, 3), (2, 3, 4), (3, 4, 5) ] result = min_cost_traffic_signals(n, m, street_info) assert result == 6 def test_case_2(): n = 3 ...
[ { "docstring": null, "function_declaration": "def find(parent, i):", "function_name": "find", "parameter_list": "(parent, i)" }, { "docstring": null, "function_declaration": "def union(parent, rank, x, y):", "function_name": "union", "parameter_list": "(parent, rank, x, y)" }, ...
[ 1, 0, 1, 1, 0, 0, 1, 1, 0, 1 ]
6
medium
0.6
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "import heapq\n\ndef find(parent, i):\n if parent[i] == i:\n return i\n return find(parent, parent[i])\n\ndef union(parent, rank, x, y):\n root...
trial_gpt4o_9
{ "original_instruction": "The city of Hexagonville is designed in a grid layout where each intersection is represented as a node in a graph. Each street between intersections is a weighted edge. The city planners want to optimize the placement of traffic signals to minimize the overall traffic congestion.\n\nGiven a...
0.653942
Codeforces_5222
C
[ "find", "union", "kruskal", "min_cost_traffic_signals" ]
4
[ [ "kruskal", "find" ], [ "kruskal", "union" ], [ "min_cost_traffic_signals", "kruskal" ], [ "union", "find" ] ]
4
[]
false
[]
false
pytest
true
[]
true
5bf9136b12f08b0ddcdbd4336444befcfbf57cd6
2c16e3222b78b72159dc74d4b4992e5d07d222a3
v1.0
complete
Codeforces
Codeforces_5081_C
import sys from typing import List, Tuple def circle_road_system(n: int, m: int, roads: List[Tuple[int, int, int]]) -> int: """ Determine the minimum total length required to build a circle road system. :param n: number of towns :param m: number of roads :param roads: list of tuples (u, v, w) where u ...
import sys def tsp(n, graph): dp = [[sys.maxsize] * (1 << n) for _ in range(n)] dp[0][1] = 0 for mask in range(1 << n): for u in range(n): if mask & (1 << u): for v in range(n): if not mask & (1 << v) and graph[u][v] != sys.maxsize: ...
def test_circle_road_system(): # Test case from the example n, m = 4, 6 roads = [ (1, 2, 10), (1, 3, 15), (1, 4, 20), (2, 3, 35), (2, 4, 25), (3, 4, 30) ] assert circle_road_system(n, m, roads) == 80 # Test case with no possible cycle n, m...
[ { "docstring": null, "function_declaration": "def tsp(n, graph):", "function_name": "tsp", "parameter_list": "(n, graph)" }, { "docstring": null, "function_declaration": "def circle_road_system(n, m, roads):", "function_name": "circle_road_system", "parameter_list": "(n, m, roads...
[ 1, 0, 0, 0, 1, 0, 0, 0, 1, 0 ]
3
hard
0.3
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "from itertools import permutations\n\ndef solve_circle_road_system(n, m, roads):\n if m < n:\n return -1\n \n def total_length(perm):\n ...
trial_gpt4o_8
{ "original_instruction": "In a faraway land, there is a kingdom with n towns connected by m bidirectional roads. Each road has a certain length in kilometers. The king wants to build a special type of road system called a \"circle road system,\" where you should be able to start at any town and travel back to the sa...
0.656748
Codeforces_5081
C
[ "tsp", "circle_road_system" ]
2
[ [ "circle_road_system", "tsp" ] ]
1
[]
false
[]
false
pytest
false
[]
true
7e06b39a68c6129ebded6de82ec645a9c908416b
fecc5f586479e9ff63aa4d38d4eba6c1cee2ff0e
v1.0
complete
Codeforces
Codeforces_5564_C
def count_subarrays_of_ones(s: str) -> int: """ Counts the number of subarrays consisting entirely of '1's in the given binary string. >>> count_subarrays_of_ones("11001") 2 >>> count_subarrays_of_ones("00000") 0 >>> count_subarrays_of_ones("11111") 1 """ def process_operations(n: int, s: str, m: i...
def count_subarrays_of_ones(s): """ Counts the number of subarrays consisting entirely of '1's in the given binary string s. """ count = 0 in_subarray = False for char in s: if char == '1': if not in_subarray: count += 1 in_subarray = True...
from solution import process_operations, count_subarrays_of_ones def test_count_subarrays_of_ones(): assert count_subarrays_of_ones("11001") == 2 assert count_subarrays_of_ones("11101") == 2 assert count_subarrays_of_ones("00000") == 0 assert count_subarrays_of_ones("11111") == 1 assert count_subar...
[ { "docstring": "Counts the number of subarrays consisting entirely of '1's in the given binary string s.", "function_declaration": "def count_subarrays_of_ones(s):", "function_name": "count_subarrays_of_ones", "parameter_list": "(s)" }, { "docstring": "Processes a list of operations on the g...
[ 1, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def count_subarrays_of_ones(s):\n \"\"\"\n Counts the number of subarrays consisting entirely of '1's in the given binary string s.\n \"\"\"\n cou...
trial_gpt4o_0
{ "original_instruction": "You have a binary string s of length n consisting of characters '0' and '1'. You are allowed to perform the following operations on this string:\n\n1. Flip a bit: Change a '0' to '1' or a '1' to '0' at a specific index.\n2. Count subarrays: Count the number of subarrays which consist entire...
0.58575
Codeforces_5564
C
[ "count_subarrays_of_ones", "process_operations" ]
2
[ [ "process_operations", "count_subarrays_of_ones" ] ]
1
[]
false
[]
false
pytest
true
[]
true
8684dca0c4f0ddbc89c8d0d999767a004b9f8aa1
11bb4a93b5ed89fbdc32c8b9730021ce68f8b03e
v1.0
complete
Codeforces
Codeforces_5255_C
from typing import Tuple def min_travel_distance(h: int, k: int, m: int, x1: int, y1: int, x2: int, y2: int) -> float: """ Calculate the minimum possible travel distance between points A and B, considering both the grid streets and the curved road described by the equation y = k(x - h)^2 + m. >>> abs(...
import math import scipy.optimize def parabola_distance(h, k, m, x1, y1, x2, y2): def func_x1(x): return (k * (x - h)**2 + m - y1)**2 def func_x2(x): return (k * (x - h)**2 + m - y2)**2 # Finding the optimal point on the parabola for x1, y1 res_x1 = scipy.optimize.minimize_sca...
def test_parabola_distance(): # Test 1: Simple direct path assert abs(min_travel_distance(2, 1, 3, 1, 1, 5, 5) - 8) < 1e-6 # Test 2: Using the curved road assert abs(min_travel_distance(0, 1, 0, -1, 0, 1, 0) - 2) < 1e-6 # Test 3: Same points assert abs(min_travel_distance(2, 1, 3, 1, 1...
[ { "docstring": null, "function_declaration": "def parabola_distance(h, k, m, x1, y1, x2, y2):", "function_name": "parabola_distance", "parameter_list": "(h, k, m, x1, y1, x2, y2)" }, { "docstring": null, "function_declaration": "def min_travel_distance(h, k, m, x1, y1, x2, y2):", "fu...
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
1
hard
0.125
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "import math\nfrom scipy.optimize import minimize_scalar\n\ndef distance(p1, p2):\n \"\"\"\n Euclidean distance between points p1 and p2.\n \"\"\"\n ...
trial_gpt4o_4
{ "original_instruction": "You are a chief architect designing a new city with a unique street layout.\n\nThis city is built on a plane, using both vertical and horizontal streets similar to a grid. However, there is a special curved road, represented by the equation $$$y = k(x - h)^2 + m$$$. The curved road can be t...
0.659595
Codeforces_5255
C
[ "parabola_distance", "min_travel_distance" ]
2
[ [ "min_travel_distance", "parabola_distance" ] ]
1
[]
false
[]
false
pytest
false
[ "scipy" ]
false
bda5a3ba93e72a8702b443a8c3bec9f8378f64db
b07ff097705d63b263229e18ebde4abc2c9935dd
v1.0
complete
Codeforces
Codeforces_3805_C
import sys import heapq from typing import List, Tuple def create_adjacency_list(n: int, edges: List[Tuple[int, int]]) -> List[List[int]]: """ Create adjacency list from the list of edges. >>> create_adjacency_list(5, [(1, 2), (2, 3), (3, 4), (4, 5), (1, 5)]) [[], [2, 5], [3], [4], [5], []] """ pas...
import sys import heapq def create_adjacency_list(n, edges): adj_list = [[] for _ in range(n + 1)] for (a, b) in edges: adj_list[a].append(b) return adj_list def bfs(adj_list, start, end): n = len(adj_list) - 1 visited = [False] * (n + 1) queue = [start] visited[start] = True w...
def test_create_adjacency_list(): n = 5 edges = [(1, 2), (2, 3), (3, 4), (4, 5), (1, 5)] adj_list = create_adjacency_list(n, edges) assert adj_list == [[], [2, 5], [3], [4], [5], []] def test_bfs(): adj_list = [[], [2, 5], [3], [4], [5], []] assert bfs(adj_list, 1, 3) == True assert bfs(adj...
[ { "docstring": null, "function_declaration": "def create_adjacency_list(n, edges):", "function_name": "create_adjacency_list", "parameter_list": "(n, edges)" }, { "docstring": null, "function_declaration": "def bfs(adj_list, start, end):", "function_name": "bfs", "parameter_list"...
[ 0, 0, 1, 0, 0, 0, 0, 0, 0, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "from collections import deque, defaultdict\n\ndef bfs_shortest_path(graph, start, end):\n \"\"\"\n Uses BFS to find the shortest path in an unweighted g...
trial_gpt4o_2
{ "original_instruction": "Alice just started learning about directed graphs. Her friend Bob gave her a directed graph with n nodes and m edges. Each node is labeled from 1 to n. Bob wants Alice to process multiple queries about the connectivity between nodes.\n\nAlice needs to execute two types of queries:\n\n1. Che...
0.619401
Codeforces_3805
C
[ "create_adjacency_list", "bfs", "dijkstra", "process_queries", "main" ]
5
[ [ "process_queries", "bfs" ], [ "process_queries", "create_adjacency_list" ], [ "process_queries", "dijkstra" ] ]
3
[ "process_queries" ]
false
[]
false
pytest
false
[]
true
9d488e35602d76b12b5cbec16de317e7fdcf7e7a
47e2f88d9a9a8091be5abdb945944e373928fc36
v1.0
complete
Codeforces
Codeforces_4215_C
def floyd_warshall(n: int, edges: List[Tuple[int, int, int]]) -> List[List[int]]: """ Apply Floyd-Warshall algorithm to find the shortest paths between all pairs of vertices. Parameters: n (int): The number of vertices in the graph. edges (List[Tuple[int, int, int]]): List of tuples representi...
def floyd_warshall(n, edges): # Initialize the distance matrix dist = [[float('inf')] * n for _ in range(n)] for i in range(n): dist[i][i] = 0 for a, b, c in edges: dist[a-1][b-1] = min(dist[a-1][b-1], c) # Apply Floyd-Warshall algorithm for k in range(n): ...
def test_floyd_warshall_basic(): n = 4 edges = [(1, 2, 1), (2, 3, 3), (3, 4, 2), (1, 4, 10)] queries = [(1, 4), (4, 1), (1, 3)] expected_output = [6, -1, 4] assert shortest_path(n, edges, queries) == expected_output def test_graph_with_no_path(): n = 3 edges = [(1, 2, 4), (2, 3, 2)] ...
[ { "docstring": null, "function_declaration": "def floyd_warshall(n, edges):", "function_name": "floyd_warshall", "parameter_list": "(n, edges)" }, { "docstring": null, "function_declaration": "def shortest_path(n, edges, queries):", "function_name": "shortest_path", "parameter_li...
[ 1, 0, 0, 1, 0, 0, 0, 1, 1, 0 ]
4
medium
0.4
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def floyd_warshall(n, edges):\n \"\"\"\n Floyd-Warshall algorithm to find the shortest distances between all pairs of nodes.\n \"\"\"\n inf = floa...
trial_gpt4o_8
{ "original_instruction": "You are given a weighted directed graph with `n` vertices and `m` edges. Each vertex is numbered from `1` to `n`. You need to answer `q` queries, where each query asks for the shortest path from vertex `u` to vertex `v`.\n\nThe first line contains three integers `n`, `m`, and `q` ($1 \\le n...
0.619699
Codeforces_4215
C
[ "floyd_warshall", "shortest_path" ]
2
[ [ "shortest_path", "floyd_warshall" ] ]
1
[]
false
[]
false
pytest
false
[]
true
5d7a928b367fe36513f9d7a50770d55e31fa01e5
a8158b64432779fcae3ffa6264690c72d62de888
v1.0
complete
Codeforces
Codeforces_5368_C
def kth_lexicographic_permutation(string: str, k: int) -> str: """ Returns the k-th lexicographic permutation of the given string. >>> kth_lexicographic_permutation('abc', 2) 'acb' >>> kth_lexicographic_permutation('abcd', 1) 'abcd' >>> kth_lexicographic_permutation('abcd', 24) 'dcba' ""...
from itertools import permutations def kth_lexicographic_permutation(string, k): """ Returns the k-th lexicographic permutation of given string. """ perm = sorted(''.join(p) for p in permutations(string)) return perm[k-1] def distinct_substrings_of_length_k(s, k): """ Returns the number of...
def test_kth_lexicographic_permutation(): assert kth_lexicographic_permutation('abc', 2) == 'acb' assert kth_lexicographic_permutation('abcd', 1) == 'abcd' assert kth_lexicographic_permutation('abcd', 24) == 'dcba' def test_distinct_substrings_of_length_k(): assert distinct_substrings_of_length_k('abca...
[ { "docstring": "Returns the k-th lexicographic permutation of given string.", "function_declaration": "def kth_lexicographic_permutation(string, k):", "function_name": "kth_lexicographic_permutation", "parameter_list": "(string, k)" }, { "docstring": "Returns the number of distinct substring...
[ 1, 0, 0, 0, 0, 0, 0, 0, 0 ]
1
hard
0.111
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "from itertools import permutations\n\ndef kth_lexicographic_permutation(string, k):\n \"\"\"\n Returns the k-th lexicographic permutation of given strin...
trial_gpt4o_0
{ "original_instruction": "You are given a string S of length n and an integer k. The string consists of lowercase alphabets only. You need to perform q operations on the string, which can be of two types:\n\n1. Replace the substring starting from position l and ending at position r with its k-th lexicographic permut...
0.665895
Codeforces_5368
C
[ "kth_lexicographic_permutation", "distinct_substrings_of_length_k", "process_operations" ]
3
[ [ "process_operations", "distinct_substrings_of_length_k" ], [ "process_operations", "kth_lexicographic_permutation" ] ]
2
[]
false
[]
false
pytest
false
[]
true
960864d4da18fccbd0f2816c2ca88dea1f2843c1
d68eca9b61f771788344d6169c45b672d54705ca
v1.0
complete
Codeforces
Codeforces_5623_C
def is_valid_user_list(user_ids): """ Check if the list of user IDs is valid based on the given criteria: 1. All IDs must be positive integers. 2. No ID should appear more than once in the list. 3. The sum of all IDs should be a prime number. >>> is_valid_user_list([2, 3, 5, 7]) True >>...
def is_prime(n): if n <= 1: return False if n == 2: return True if n % 2 == 0: return False p = 3 while p * p <= n: if n % p == 0: return False p += 2 return True def is_valid_user_list(user_ids): """ Check if the list of user IDs is v...
from solution import is_valid_user_list def test_valid_list_with_prime_sum(): assert is_valid_user_list([2, 3, 5, 7]) == True def test_list_with_negative_ids(): assert is_valid_user_list([2, -3, 5, 7]) == False def test_list_with_non_integer_ids(): assert is_valid_user_list([2, 3.5, 5, 7]) == False def ...
[ { "docstring": null, "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Check if the list of user IDs is valid based on the given criteria.", "function_declaration": "def is_valid_user_list(user_ids):", "function_name":...
[ 0, 1, 0, 0, 1, 0, 0, 0, 0 ]
2
hard
0.222
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(n):\n if n <= 1:\n return False\n if n == 2:\n return True\n if n % 2 == 0:\n return False\n p = 3\n while p ...
trial_gpt4o_1
{ "original_instruction": "You are managing a database of users, each represented by a unique integer ID. You need to provide a function that checks if a given list of user IDs is valid based on the following criteria:\n\n1. All IDs must be positive integers.\n2. No ID should appear more than once in the list.\n3. Th...
0.614978
Codeforces_5623
C
[ "is_prime", "is_valid_user_list" ]
2
[ [ "is_valid_user_list", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
c942231f7da184242bd0ecb1368056b82bc55cb0
20d2258371af415b31e1d902c4d583f36bf3003e
v1.0
complete
Codeforces
Codeforces_5327_C
MOD = 10**9 + 7 def num_paths(grid, n, m): """ Determine the number of possible paths that the robot can take to reach the bottom-right corner (n, m), modulo 10^9 + 7, in a grid with blocked cells. The function takes a 2D list representing the grid and its dimensions as input. """ pass def read_in...
MOD = 10**9 + 7 def num_paths(grid, n, m): if grid[0][0] == '#': return 0 dp = [[0] * m for _ in range(n)] dp[0][0] = 1 for i in range(n): for j in range(m): if grid[i][j] == '#': dp[i][j] = 0 else: if i > 0: ...
from solution import read_input_and_solve def test_example_1(): input_string = '''3 3 ... .#. ...''' assert read_input_and_solve(input_string) == 2 def test_no_path(): input_string = '''3 3 ### ### ###''' assert read_input_and_solve(input_string) == 0 def test_single_row(): input_string = '''1 3 ...
[ { "docstring": null, "function_declaration": "def num_paths(grid, n, m):", "function_name": "num_paths", "parameter_list": "(grid, n, m)" }, { "docstring": null, "function_declaration": "def read_input_and_solve(input_string):", "function_name": "read_input_and_solve", "parameter...
[ 1, 1, 1, 0, 0, 0, 1, 0, 1, 0 ]
5
medium
0.5
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "MOD = 10**9 + 7\n\ndef count_paths(n, m, grid):\n dp = [[0] * m for _ in range(n)]\n \n if grid[0][0] == '#':\n return 0\n\n dp[0][0] = 1\n...
trial_gpt4o_8
{ "original_instruction": "In a rectangular grid of size $$$n \\times m$$$, you are given a robot starting at the top-left corner (1, 1). The robot is tasked to reach the bottom-right corner (n, m). The robot can only move either to the right or down at any point in time. Along the way, there are certain cells in the...
0.680437
Codeforces_5327
C
[ "num_paths", "read_input_and_solve" ]
2
[ [ "read_input_and_solve", "num_paths" ] ]
1
[]
false
[]
false
pytest
true
[]
true
25bb22635e089fa7799c179020c86e2d5f2d463e
ded2c4791025daf58259c296dd0eadbcb6f56025
v1.0
complete
Codeforces
Codeforces_5114_C
from typing import List def sum_digits(n: int) -> int: """Returns the sum of the digits of the number n. >>> sum_digits(123) 6 >>> sum_digits(456) 15 """ pass def reverse_number(n: int) -> int: """Returns the number n with its digits reversed. >>> reverse_number(123) 321 >>...
def sum_digits(n): """ Returns the sum of the digits of the number n. """ return sum(int(digit) for digit in str(n)) def reverse_number(n): """ Returns the number n with its digits reversed. """ return int(str(n)[::-1]) def magical_sequence(seed, k): """ Generates the k-th numb...
from solution import sum_digits, reverse_number, magical_sequence def test_sum_digits(): assert sum_digits(123) == 6 assert sum_digits(456) == 15 assert sum_digits(0) == 0 assert sum_digits(99999) == 45 def test_reverse_number(): assert reverse_number(123) == 321 assert reverse_number(456) == ...
[ { "docstring": "Returns the sum of the digits of the number n.", "function_declaration": "def sum_digits(n):", "function_name": "sum_digits", "parameter_list": "(n)" }, { "docstring": "Returns the number n with its digits reversed.", "function_declaration": "def reverse_number(n):", ...
[ 0, 0, 0, 0, 1, 0, 1, 0, 0, 0 ]
2
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def magical_sequence(seed, k):\n \"\"\"\n Generates the k-th number in the magical sequence starting from the seed.\n \"\"\"\n def sum_of_digits(n...
trial_gpt4o_6
{ "original_instruction": "A magical sequence is defined as a sequence of numbers where each number is obtained by summing the digits of the previous number and reversing the order of its digits. Given a seed number and an integer k, your task is to generate the k-th number in the magical sequence starting from the s...
0.59826
Codeforces_5114
C
[ "sum_digits", "reverse_number", "magical_sequence" ]
3
[ [ "magical_sequence", "reverse_number" ], [ "magical_sequence", "sum_digits" ] ]
2
[]
false
[]
false
pytest
true
[]
true
c534e0d0a7da8f3e6f2c683d596bbe5d6ced6128
b41d70c6dd8b07feab96da97387c1b2795457cf9
v1.0
complete
Codeforces
Codeforces_5570_C
def largest_rectangle_area(heights): """ Given a list of integers representing the height of vertical lines in a histogram, return the area of the largest rectangle that can be formed within the histogram. >>> largest_rectangle_area([2, 1, 5, 6, 2, 3]) 10 >>> largest_rectangle_area([2]) ...
def largest_rectangle_area(heights): """ Given a list of integers representing the height of vertical lines in a histogram, return the area of the largest rectangle that can be formed within the histogram. """ stack = [] max_area = 0 for i, h in enumerate(heights): while stack and he...
from solution import largest_rectangle_area, get_input_and_solve def test_largest_rectangle_area_basic(): assert largest_rectangle_area([2, 1, 5, 6, 2, 3]) == 10 def test_largest_rectangle_area_single_height(): assert largest_rectangle_area([2]) == 2 def test_largest_rectangle_area_multiple_same_heights(): ...
[ { "docstring": "Given a list of integers representing the height of vertical lines in a histogram,\nreturn the area of the largest rectangle that can be formed within the histogram.", "function_declaration": "def largest_rectangle_area(heights):", "function_name": "largest_rectangle_area", "paramete...
[ 1, 1, 0, 0, 0, 1, 1, 0, 1, 0 ]
5
medium
0.5
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def largest_rectangle_area(heights):\n \"\"\"\n Calculate the area of the largest rectangle that can be formed within a histogram.\n \n :param hei...
trial_gpt4o_8
{ "original_instruction": "You are given a list of integers where each integer represents the height of a vertical line on a Cartesian plane. The consecutive lines together form a histogram. Your objective is to find the largest rectangle that can be formed within the bounds of this histogram. The rectangle must be c...
0.674378
Codeforces_5570
C
[ "largest_rectangle_area", "get_input_and_solve" ]
2
[ [ "get_input_and_solve", "largest_rectangle_area" ] ]
1
[]
false
[]
false
pytest
true
[]
true
bb8aca39a6594651b9e0b578767b5fef757183e0
c46ae62ed8990de221da6a48022a13d1d8b8e003
v1.0
complete
Codeforces
Codeforces_5297_C
from typing import List, Tuple def max_subarray_sum(w: List[int]) -> int: """ Calculate the maximum subarray sum. >>> max_subarray_sum([5, 3, 8, 6, 1]) 23 >>> max_subarray_sum([2, 5, 1, 7]) 15 """ pass def max_powers(w: List[int], queries: List[Tuple[int, int]]) -> List[int]: """ Deter...
def max_subarray_sum(w): max_current = max_global = w[0] for i in range(1, len(w)): max_current = max(w[i], max_current + w[i]) if max_current > max_global: max_global = max_current return max_global def max_powers(w, queries): result = [max_subarray_sum(w[:])] for ...
from solution import max_subarray_sum, max_powers, kanto_water_flow def test_max_subarray_sum(): assert max_subarray_sum([5, 3, 8, 6, 1]) == 23 assert max_subarray_sum([2, 5, 1, 7]) == 15 assert max_subarray_sum([1, 3, 2, 5, 4, 6]) == 21 def test_max_powers(): assert max_powers([5, 3, 8, 6, 1], [(2, 3...
[ { "docstring": null, "function_declaration": "def max_subarray_sum(w):", "function_name": "max_subarray_sum", "parameter_list": "(w)" }, { "docstring": null, "function_declaration": "def max_powers(w, queries):", "function_name": "max_powers", "parameter_list": "(w, queries)" }...
[ 0, 0, 0, 0, 0, 0, 0, 0, 1, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def max_subarray_sum(arr):\n max_ending_here = max_so_far = arr[0]\n for x in arr[1:]:\n max_ending_here = max(x, max_ending_here + x)\n m...
trial_gpt4o_8
{ "original_instruction": "In the bustling city of Kanto, there's a dedicated team of researchers studying the behavior of Squirtles when they are arranged in a connected sequence of water tanks. To understand the dynamics, the team has built a series of operations to determine the water flow through these tanks.\n\n...
0.622601
Codeforces_5297
C
[ "max_subarray_sum", "max_powers", "kanto_water_flow" ]
3
[ [ "kanto_water_flow", "max_powers" ], [ "max_powers", "max_subarray_sum" ] ]
2
[]
false
[]
false
pytest
true
[]
true
773e70c31db0818cd126599ef3eb4dae2e09f828
29c2651153401dc7a5e0c1bd1b9b7b7b0de43f86
v1.0
complete
Codeforces
Codeforces_5268_C
def beautiful_string(s: str) -> str: """ Determine whether a given string is beautiful or not. A string is considered beautiful if it can be made a palindrome by removing at most one character. >>> beautiful_string("abca") "YES" >>> beautiful_string("abc") "NO" """
def is_beautiful(s): """ Determine if the string can be made a palindrome by removing at most one character. """ def is_palindrome_range(start, end): while start < end: if s[start] != s[end]: return False start += 1 end -= 1 return True...
from solution import beautiful_string def test_beautiful_string_yes_cases(): assert beautiful_string("abca") == "YES" # removing 'c' assert beautiful_string("radar") == "YES" # already palindrome assert beautiful_string("racecar") == "YES" # already palindrome assert beautiful_string("abccbaa") == "...
[ { "docstring": "Determine if the string can be made a palindrome by removing at most one character.", "function_declaration": "def is_beautiful(s):", "function_name": "is_beautiful", "parameter_list": "(s)" }, { "docstring": "Returns \"YES\" if the string is beautiful, otherwise \"NO\".", ...
[ 0, 0, 1, 0, 0, 0, 0, 0 ]
1
hard
0.125
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_beautiful(s):\n \"\"\"\n Returns \"YES\" if the string can be made a palindrome by removing at most one character, otherwise \"NO\".\n \"\"\"\...
trial_gpt4o_3
{ "original_instruction": "A string is considered beautiful if it can be made a palindrome by removing at most one character. A palindrome is a string that reads the same forward and backward.\n\nYour task is to determine whether a given string is beautiful or not.\n\n- Input: A single line containing a string $$$s$$...
0.713143
Codeforces_5268
C
[ "is_beautiful", "beautiful_string" ]
2
[ [ "beautiful_string", "is_beautiful" ] ]
1
[]
false
[]
false
pytest
true
[]
true
aa56218201dd265a1d6f6578925f66c7870936ee
7b28b9ae15495ca1f93327b5e9e506b569606595
v1.0
complete
Codeforces
Codeforces_6125_C
def contains_duplicates(numbers: List[int]) -> str: """ Returns 'YES' if there are duplicate numbers in the list, otherwise 'NO'. >>> contains_duplicates([1, 2, 3, 4, 5]) == "NO" >>> contains_duplicates([1, 2, 3, 4, 4]) == "YES" """ def check_duplicate_numbers(input_string: str) -> str: """ Parses ...
def contains_duplicates(numbers): """ Returns 'YES' if there are duplicate numbers in the list, otherwise 'NO'. """ # Create a set to store unique numbers seen = set() for number in numbers: if number in seen: return "YES" seen.add(number) return "NO" d...
from solution import contains_duplicates, check_duplicate_numbers def test_no_duplicates(): assert check_duplicate_numbers("1 2 3 4 5") == "NO" def test_with_duplicates(): assert check_duplicate_numbers("1 2 3 4 4") == "YES" def test_empty_list(): assert check_duplicate_numbers("") == "NO" def test_sing...
[ { "docstring": "Returns 'YES' if there are duplicate numbers in the list, otherwise 'NO'.", "function_declaration": "def contains_duplicates(numbers):", "function_name": "contains_duplicates", "parameter_list": "(numbers)" }, { "docstring": "Parses the input string and invokes the contains_d...
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
10
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def contains_duplicates(integers):\n \"\"\"\n Returns \"YES\" if the input list contains any duplicate elements, otherwise \"NO\".\n \"\"\"\n inte...
trial_gpt4o_9
{ "original_instruction": "You are given a list of integers. Your task is to determine whether the list contains any duplicate elements.\n\nInput\nThe input consists of a single line containing a space-separated list of integers, where each integer \\(n\\) (-10^6 <= \\(n\\) <= 10^6).\n\nOutput\nOutput \"YES\" if any ...
0.766132
Codeforces_6125
C
[ "contains_duplicates", "check_duplicate_numbers" ]
2
[ [ "check_duplicate_numbers", "contains_duplicates" ] ]
1
[]
false
[]
false
pytest
true
[]
true
467b04fb59daec9df931c3361997ee30ac4504a7
0ed69e81e5078bfbf62cce32717bb706791112dd
v1.0
complete
Codeforces
Codeforces_5651_C
def grid_path(h: int, w: int, grid: List[str]) -> str: """ Determine if there exists a valid path from the top-left corner to the bottom-right corner, moving only through empty cells. >>> grid_path(5, 5, ["..#..", "#####", "..#..", ".#...", "#...."]) "NO" >>> grid_path(5, 5, ["..#..", "#...#", "..#..", ...
def is_path_possible(h, w, grid): def is_in_bounds(x, y): return 0 <= x < h and 0 <= y < w def dfs(x, y): if x == h - 1 and y == w - 1: return True for dx, dy in [(1, 0), (-1, 0), (0, 1), (0, -1)]: nx, ny = x + dx, y + dy if is_in_bounds(nx, ny) a...
from solution import grid_path def test_no_path(): h, w = 5, 5 grid = [ "..#..", "#####", "..#..", ".#...", "#...." ] assert grid_path(h, w, grid) == "NO" def test_yes_path(): h, w = 5, 5 grid = [ "..#..", "#...#", "..#..", ...
[ { "docstring": null, "function_declaration": "def is_path_possible(h, w, grid):", "function_name": "is_path_possible", "parameter_list": "(h, w, grid)" }, { "docstring": null, "function_declaration": "def grid_path(h, w, grid):", "function_name": "grid_path", "parameter_list": "(...
[ 0, 1, 1, 0, 0, 0, 0, 0, 0 ]
2
hard
0.222
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_path_exist(h, w, grid):\n \"\"\"\n Determine if there exists a valid path from the top-left corner (1, 1) to the bottom right corner (h, w).\n ...
trial_gpt4o_1
{ "original_instruction": "You are given a tall rectangular grid of cells with dimensions $$$h$$$ by $$$w$$$ ($$$h$$$ rows and $$$w$$$ columns). Some of these cells are blocked and some are empty. An empty cell is represented by a '.' character, while a blocked cell is represented by a '#' character. Your task is to ...
0.645502
Codeforces_5651
C
[ "is_path_possible", "grid_path" ]
2
[ [ "grid_path", "is_path_possible" ] ]
1
[]
false
[]
false
pytest
true
[]
true
a6654b7e4544e1907a585a4c9ec991299f39e43d
7188b33ed337b468446d04c12552b1942e2c9030
v1.0
complete
Codeforces
Codeforces_6172_C
from typing import List def solve(r: int, c: int, grid: List[str]) -> str: """ Determines if there is a path from 'S' to 'T' in the given grid without passing through '#'. r: Number of rows in the grid c: Number of columns in the grid grid: List of strings representing the grid Return...
def is_path_possible(grid): """ Determines if there is a path from 'S' to 'T' in the given grid without passing through '#'. """ rows = len(grid) cols = len(grid[0]) def find_start_end(): for i in range(rows): for j in range(cols): if grid[i][j] == 'S': ...
def test_path_possible(): grid = [ "S....", ".#...", "...T.", "....." ] assert solve(4, 5, grid) == "YES" def test_path_impossible(): grid = [ "S..#.", ".#.#.", "###..", "..T.." ] assert solve(4, 5, grid) == "NO" def test_no_traps...
[ { "docstring": "Determines if there is a path from 'S' to 'T' in the given grid without passing through '#'.", "function_declaration": "def is_path_possible(grid):", "function_name": "is_path_possible", "parameter_list": "(grid)" }, { "docstring": null, "function_declaration": "def solve...
[ 0, 1, 0, 0, 1, 0, 0, 1, 1, 0 ]
4
medium
0.4
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_path_exist(grid):\n from collections import deque\n\n # Helper function to find the position of 'S' and 'T'\n def find_positions(grid):\n ...
trial_gpt4o_7
{ "original_instruction": "You are given a rectangular grid with rows and columns. Some cells of the grid contain traps, represented by '#', and the remaining cells are either free cells represented by '.', or starting point 'S', or target point 'T'. \n\nYour task is to determine if there is a path from the starting ...
0.640867
Codeforces_6172
C
[ "is_path_possible", "solve" ]
2
[ [ "solve", "is_path_possible" ] ]
1
[]
false
[]
false
pytest
false
[]
true
2c4c72bab9182366531bae6859da000f6fefe849
594f32a2890b936475b086c1d5906f808e92c05b
v1.0
complete
Codeforces
Codeforces_5788_C
def conference_order(m: int, l: int, s: List[int], constraints: List[Tuple[int, int]]) -> List[int]: """ Determine if there exists an ordering of topics that satisfies all the constraints, and if at least one exists, find any of them. Args: m (int): the number of topics. l (int): the number of spe...
from collections import deque, defaultdict def find_topic_order(m, l, s, constraints): # Create graph and in-degree list graph = defaultdict(list) in_degree = [0] * (m + 1) # Add edges for preparation topics for j in range(1, m + 1): if s[j - 1] != 0: # there's a preparation topic ...
from solution import conference_order def test_simple_case(): assert conference_order(3, 1, [0, 1, 2], [(1, 2)]) == [1, 2, 3] def test_complex_case(): result = conference_order(4, 2, [0, 1, 2, 2], [(1, 2), (3, 4)]) assert result in ([1, 2, 3, 4], [1, 3, 2, 4], [1, 3, 4, 2]) def test_no_valid_case(): ...
[ { "docstring": null, "function_declaration": "def find_topic_order(m, l, s, constraints):", "function_name": "find_topic_order", "parameter_list": "(m, l, s, constraints)" }, { "docstring": null, "function_declaration": "def conference_order(m, l, s, constraints):", "function_name": ...
[ 0, 0, 1, 1, 0, 0, 0, 0, 1, 0 ]
3
hard
0.3
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "from collections import defaultdict, deque\n\ndef find_ordering(m, l, s, constraints):\n # Create the graph and the in-degree count\n graph = defaultdic...
trial_gpt4o_3
{ "original_instruction": "Gina is organizing a conference where she will be the keynote speaker. During the conference, Gina plans to address $$$m$$$ different topics in $$$m$$$ different sessions. Each topic is to be covered in exactly one session. Gina needs to decide the order in which she will address the topics...
0.547333
Codeforces_5788
C
[ "find_topic_order", "conference_order" ]
2
[ [ "conference_order", "find_topic_order" ] ]
1
[]
false
[]
false
pytest
true
[]
true
7afdbecacfc0178101e4ced637812dbf7ced48a8
e537ffa731e34b46f181df952159a5222603b993
v1.0
complete
Codeforces
Codeforces_5394_C
from math import factorial def subfactorial(n): """ Compute the subfactorial (derangement) of a number n. !n = n! * sum((-1)^i / i! for i in range(n+1)) >>> subfactorial(0) == 1 True >>> subfactorial(1) == 0 True >>> subfactorial(2) == 1 True >>> subfactorial(3) == 2 True ...
from math import factorial def subfactorial(n): """ Compute the subfactorial (derangement) of a number n. !n = n! * sum((-1)^i / i! for i in range(n+1)) """ return round(factorial(n) * sum((-1)**i / factorial(i) for i in range(n + 1))) # Specific function to return the number of derangements for n...
from solution import subfactorial, derangements_without_2cycles def test_subfactorial(): # Verify subfactorial values as known from combinatorial math assert subfactorial(0) == 1 assert subfactorial(1) == 0 assert subfactorial(2) == 1 assert subfactorial(3) == 2 assert subfactorial(4) == 9 ...
[ { "docstring": "Compute the subfactorial (derangement) of a number n.\n!n = n! * sum((-1)^i / i! for i in range(n+1))", "function_declaration": "def subfactorial(n):", "function_name": "subfactorial", "parameter_list": "(n)" }, { "docstring": null, "function_declaration": "def derangemen...
[ 0, 0, 0, 0, 0, 0, 1, 0, 0, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "from itertools import permutations\n\ndef is_derangement(p):\n \"\"\"\n Check if the permutation p is a derangement.\n \"\"\"\n for i in range(len...
trial_gpt4o_6
{ "original_instruction": "Let $$$N=\\{1,2,3,4,5\\}$$$ be a set with $$$5$$$ elements. Determine the number of bijective functions $$$g: N \\to N$$$ such that there are no elements $$$a \\in N$$$ for which $$$g(a) = a$$$ and $$$g(g(a)) = a$$$.\n\nNote: A function $$$g: A \\to B$$$ is called bijective if it is both in...
0.609475
Codeforces_5394
C
[ "subfactorial", "derangements_without_2cycles" ]
2
[ [ "derangements_without_2cycles", "subfactorial" ] ]
1
[]
false
[]
false
pytest
true
[]
true
f6bae48e0ea97cf063c856aa958e6d71d3233810
1e03cc70cae8196e15223397601672a0636109e5
v1.0
complete
Codeforces
Codeforces_5880_C
from typing import List def is_prime(n: int) -> bool: """ Check if a number is prime. :param n: Integer to check. :return: True if the number is prime, False otherwise. """ if n <= 1: return False if n <= 3: return True if n % 2 == 0 or n % 3 == 0: return False i...
def is_prime(n): """ Check if a number is prime. :param n: Integer to check. :return: True if the number is prime, False otherwise. """ if n <= 1: return False if n <= 3: return True if n % 2 == 0 or n % 3 == 0: return False i = 5 while i * i <= n: ...
from solution import next_prime def test_next_prime_1(): assert next_prime(1) == 2 def test_next_prime_2(): assert next_prime(2) == 3 def test_next_prime_10(): assert next_prime(10) == 11 def test_next_prime_17(): assert next_prime(17) == 19 def test_next_prime_99(): assert next_prime(99) == 10...
[ { "docstring": "Check if a number is prime.\n\n:param n: Integer to check.\n:return: True if the number is prime, False otherwise.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Find the smallest prime number greater than...
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
10
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(n):\n \"\"\"\n Determines if a number n is prime.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return True\n ...
trial_gpt4o_9
{ "original_instruction": "A prime number is a natural number greater than 1 that has no positive divisors other than 1 and itself. Write a program to find the smallest prime number that is greater than a given integer X.\n\nThe input consists of a single integer X (1 ≤ X ≤ 100).\n\nOutput the smallest prime number g...
0.801376
Codeforces_5880
C
[ "is_prime", "next_prime" ]
2
[ [ "next_prime", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
f2ea73c33719fc9c0125a894e039a45707949701
f1ab6bac86c1f85f48de3f8798a54ccee5aa85a4
v1.0
complete
Codeforces
Codeforces_5722_C
from itertools import permutations from math import sqrt def calculate_distance(x1, y1, x2, y2): """ Calculate the Euclidean distance between two points (x1, y1) and (x2, y2). >>> round(calculate_distance(0, 0, 3, 4)) == 5 True >>> round(calculate_distance(0, 0, 0, 0)) == 0 True >>> round(calcu...
from itertools import permutations from math import sqrt from functools import lru_cache def calculate_distance(x1, y1, x2, y2): """ Calculate the Euclidean distance between two points (x1, y1) and (x2, y2) """ return sqrt((x1 - x2) ** 2 + (y1 - y2) ** 2) def calculate_total_distance(tour, cities): ...
from solution import calculate_distance, calculate_total_distance, tsp def test_calculate_distance(): # Tests for distance calculation assert round(calculate_distance(0, 0, 3, 4)) == 5 assert round(calculate_distance(0, 0, 0, 0)) == 0 assert round(calculate_distance(1, 1, 4, 5)) == 5 def test_calculat...
[ { "docstring": "Calculate the Euclidean distance between two points (x1, y1) and (x2, y2)", "function_declaration": "def calculate_distance(x1, y1, x2, y2):", "function_name": "calculate_distance", "parameter_list": "(x1, y1, x2, y2)" }, { "docstring": "Calculate the total distance of a give...
[ 0, 1, 0, 0, 0, 0, 0, 0, 0, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "from itertools import permutations\nimport math\n\ndef calculate_distance(city1, city2):\n \"\"\"\n Returns the Euclidean distance between two cities.\n...
trial_gpt4o_1
{ "original_instruction": "Alice is planning a road trip and wants to visit a number of cities. She wants to know the shortest route that allows her to visit each city exactly once and return to her starting city. This is a well-known problem in computer science known as the Traveling Salesperson Problem (TSP). Alice...
0.636341
Codeforces_5722
C
[ "calculate_distance", "calculate_total_distance", "tsp" ]
3
[ [ "calculate_total_distance", "calculate_distance" ], [ "tsp", "calculate_total_distance" ] ]
2
[]
false
[]
false
pytest
true
[]
true
1bb4b2ba2b9258b8c9341bc169ea08e511c852d9
0aa9057c0d47a2f88a42b44e24d8774fdc1f5e6e
v1.0
complete
Codeforces
Codeforces_5812_C
from typing import List def is_power_of_two(x: int) -> bool: """ Helper function to check if a given number is a power of two. >>> is_power_of_two(1) True >>> is_power_of_two(2) True >>> is_power_of_two(3) False >>> is_power_of_two(1024) True """ pass def longest_p...
def is_power_of_two(x): return (x & (x - 1)) == 0 and x != 0 def longest_power_of_two_subsequence_length(arr): power_of_two_elements = [x for x in arr if is_power_of_two(x)] return len(power_of_two_elements)
from solution import is_power_of_two, longest_power_of_two_subsequence_length def test_is_power_of_two(): assert is_power_of_two(1) == True assert is_power_of_two(2) == True assert is_power_of_two(3) == False assert is_power_of_two(4) == True assert is_power_of_two(5) == False assert is_power_o...
[ { "docstring": null, "function_declaration": "def is_power_of_two(x):", "function_name": "is_power_of_two", "parameter_list": "(x)" }, { "docstring": null, "function_declaration": "def longest_power_of_two_subsequence_length(arr):", "function_name": "longest_power_of_two_subsequence_...
[ 1, 1, 1, 1, 1, 1, 1, 1, 0, 1 ]
9
easy
0.9
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_power_of_two(x):\n \"\"\"\n Function to check if a given number is a power of two.\n \"\"\"\n return (x & (x - 1)) == 0 and x > 0\n\ndef lo...
trial_gpt4o_9
{ "original_instruction": "You are given an array of integers, and you need to find the length of the longest subsequence such that every element in the subsequence is a power of two.\n\nMore formally, a subsequence is a sequence that can be derived from the array by deleting some or no elements without changing the ...
0.668994
Codeforces_5812
C
[ "is_power_of_two", "longest_power_of_two_subsequence_length" ]
2
[ [ "longest_power_of_two_subsequence_length", "is_power_of_two" ] ]
1
[]
false
[]
false
pytest
true
[]
true
4424b0f70918b70448634a92f523a4e9be11eb77
0a10ff98a2798a424c511461e971c28346df80ed
v1.0
complete
Codeforces
Codeforces_5452_C
from typing import List, Tuple def can_build_reliable_system(n: int, m: int, pipes: List[Tuple[int, int]]) -> str: """ Determine whether it's possible to build a reliable water distribution system. Args: n: Number of water tanks (1 <= n <= 1000). m: Number of pipes (0 <= m <= 5000). pipes: Lis...
from collections import defaultdict def find_bridges(n, graph): timer = 0 disc = [-1] * n low = [-1] * n visited = [False] * n parent = [-1] * n bridges = [] def dfs(u): nonlocal timer visited[u] = True disc[u] = low[u] = timer timer += 1 for v in g...
from solution import can_build_reliable_system def test_single_tank(): assert can_build_reliable_system(1, 0, []) == "YES" def test_reliable_small_graph(): assert can_build_reliable_system(4, 5, [(1, 2), (1, 3), (2, 3), (2, 4), (3, 4)]) == "YES" def test_unreliable_small_graph(): assert can_build_reliabl...
[ { "docstring": null, "function_declaration": "def find_bridges(n, graph):", "function_name": "find_bridges", "parameter_list": "(n, graph)" }, { "docstring": null, "function_declaration": "def can_build_reliable_system(n, m, pipes):", "function_name": "can_build_reliable_system", ...
[ 0, 0, 1, 1, 0, 0, 0, 0, 0, 0 ]
2
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_reliable_water_distribution(n, m, pipes):\n from collections import defaultdict\n \n if n == 1:\n return \"YES\" if m == 0 else \"NO\"\...
trial_gpt4o_2
{ "original_instruction": "Samuel is designing a water distribution system for his small town. The town has n water tanks and m pipes connecting various pairs of water tanks. Each water tank needs to be connected directly or indirectly to the main water source for effective distribution. Samuel wants to ensure that t...
0.587286
Codeforces_5452
C
[ "find_bridges", "can_build_reliable_system" ]
2
[ [ "can_build_reliable_system", "find_bridges" ] ]
1
[]
false
[]
false
pytest
true
[]
true
30d56ee0c73634e3c60c8be8715988482051641f
109fa98f0939235097556ed4655e9affd420554a
v1.0
complete
Codeforces
Codeforces_5323_C
from typing import List, Tuple, Optional def min_cost_to_connect_neighborhoods(N: int, M: int, bridges: List[Tuple[int, int, int]]) -> Tuple[Optional[int], Optional[List[Tuple[int, int]]]]: """ Determine the minimum total cost required to construct the bridges such that all neighborhoods are connected, directly or...
def find(parent, i): if parent[i] == i: return i else: return find(parent, parent[i]) def union(parent, rank, x, y): xroot = find(parent, x) yroot = find(parent, y) if rank[xroot] < rank[yroot]: parent[xroot] = yroot elif rank[xroot] > rank[yroot]: parent[yr...
def test_min_cost_to_connect_neighborhoods(): N = 4 M = 5 bridges = [ (1, 2, 1), (1, 3, 2), (1, 4, 3), (2, 3, 1), (3, 4, 4) ] total_cost, result = min_cost_to_connect_neighborhoods(N, M, bridges) assert total_cost == 4 assert sorted(result) == sorted([...
[ { "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, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_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_6
{ "original_instruction": "There is a river that runs through a city, connecting various neighborhoods. The city administration wants to build new bridges across the river to improve connectivity between neighborhoods. Each bridge connects two different neighborhoods and has a cost associated with it. The goal is to ...
0.657334
Codeforces_5323
C
[ "find", "union", "min_cost_to_connect_neighborhoods", "main" ]
4
[ [ "min_cost_to_connect_neighborhoods", "find" ], [ "min_cost_to_connect_neighborhoods", "union" ], [ "union", "find" ] ]
3
[]
false
[]
false
pytest
false
[]
true
ed4ec6704df32be047bed4606d46a7247030c229
4ab0565957a28c15a0e107b6ff7a5d4340e411ec
v1.0
complete
Codeforces
Codeforces_5495_C
def is_wiggle_list(nums: List[int]) -> str: """ Determines if a list of integers is a wiggle list. Args: nums (list of int): A list of integers Returns: str: "YES" if the list is a wiggle list, otherwise "NO" """ def process_wiggle_lists(input_lists: List[List[int]]) -> List[s...
def is_wiggle_list(nums): """ Determines if a list of integers is a wiggle list. Args: nums (list of int): A list of integers Returns: str: "YES" if the list is a wiggle list, otherwise "NO" """ if len(nums) < 2: return "YES" for i in range(1, len(nums) - 1): ...
from solution import is_wiggle_list, process_wiggle_lists def test_is_wiggle_list(): assert is_wiggle_list([1, 3, 2]) == "YES" assert is_wiggle_list([4, 5, 6, 3]) == "NO" assert is_wiggle_list([1, 4, 2, 5, 3]) == "YES" assert is_wiggle_list([1]) == "YES" assert is_wiggle_list([1, 1, 1, 1]) == "NO" ...
[ { "docstring": "Determines if a list of integers is a wiggle list.\n\nArgs:\nnums (list of int): A list of integers\n\nReturns:\nstr: \"YES\" if the list is a wiggle list, otherwise \"NO\"", "function_declaration": "def is_wiggle_list(nums):", "function_name": "is_wiggle_list", "parameter_list": "(n...
[ 1, 1, 0, 1, 1, 0, 0, 1, 0, 0 ]
5
medium
0.5
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_wiggle_list(lst):\n \"\"\"\n Returns 'YES' if the given list lst is a wiggle list, otherwise returns 'NO'.\n \"\"\"\n m = len(lst)\n if ...
trial_gpt4o_7
{ "original_instruction": "A company has designed a special kind of list called a \"wiggle list\". A wiggle list is defined as a sequence of numbers such that the differences between successive numbers strictly alternate between positive and negative. Your task is to determine if a given list is a wiggle list.\n\nA w...
0.500263
Codeforces_5495
C
[ "is_wiggle_list", "process_wiggle_lists" ]
2
[ [ "process_wiggle_lists", "is_wiggle_list" ] ]
1
[]
false
[]
false
pytest
true
[]
true
84eac87fe1c34a1e6f9cdeb5c6c8ef7a554c93d8
5996999615e7097bddf22e136c3f5a2b1bac2070
v1.0
complete
Codeforces
Codeforces_5769_C
from typing import List, Tuple def minimum_delivery_time(n: int, m: int, k: int, roads: List[Tuple[int, int, int]], distribution_centers: List[int]) -> int: """ Determines the minimum delivery time from any distribution center to a new potential customer. Args: n : int : number of intersections ...
import heapq def dijkstra(n, graph, distribution_centers): """ Performs Dijkstra's algorithm from multiple sources (distribution centers). Returns the minimum delivery times from any distribution center to each intersection. """ dist = {i: float('inf') for i in range(1, n + 1)} pq = [] ...
from solution import minimum_delivery_time def test_example_case(): n = 5 m = 6 k = 2 roads = [ (1, 2, 5), (1, 3, 10), (2, 3, 2), (3, 4, 1), (2, 4, 8), (4, 5, 3) ] distribution_centers = [1, 4] assert minimum_delivery_time(n, m, k, roads, dist...
[ { "docstring": "Performs Dijkstra's algorithm from multiple sources (distribution centers).\nReturns the minimum delivery times from any distribution center to each intersection.", "function_declaration": "def dijkstra(n, graph, distribution_centers):", "function_name": "dijkstra", "parameter_list":...
[ 0, 0, 1, 0, 0, 0, 0, 0, 0, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "import heapq\n\ndef minimum_delivery_time(n, m, k, roads, centers):\n if k == 0:\n return -1\n\n # Create adjacency list\n adj_list = [[] for ...
trial_gpt4o_2
{ "original_instruction": "A delivery company operates in a town with n intersections numbered from 1 to n. The town has m directional roads, each connecting a pair of intersections. Every road has a particular delivery time in minutes.\n\nThe company currently has k distribution centers located at specified intersec...
0.673708
Codeforces_5769
C
[ "dijkstra", "minimum_delivery_time" ]
2
[ [ "minimum_delivery_time", "dijkstra" ] ]
1
[]
false
[]
false
pytest
true
[]
true
e07ff6c1552b6ad986c04ca08a3f7b913a37dc15
bc3cc85a4da8ed1435ffaa7645af2b2c9fd1c681
v1.0
complete
Codeforces
Codeforces_4713_C
from collections import deque, defaultdict def bfs_distance(n, graph, start): """Perform BFS to find the shortest distances from the start node to all other nodes.""" distances = [-1] * (n + 1) queue = deque([start]) distances[start] = 0 while queue: node = queue.popleft() for ...
from collections import deque, defaultdict def bfs_distance(n, graph, start): distances = [-1] * (n + 1) queue = deque([start]) distances[start] = 0 while queue: node = queue.popleft() for neighbor in graph[node]: if distances[neighbor] == -1: distances[...
import pytest from solution import find_centrality def test_small_tree(): n = 3 edges = [(1, 2), (2, 3)] find_centrality(n, edges) # Expected output: 1 \n 2 def test_single_city(): n = 1 edges = [] find_centrality(n, edges) # Expected output: 0 \n 1 def test_linear_tree(): n = 4...
[ { "docstring": null, "function_declaration": "def bfs_distance(n, graph, start):", "function_name": "bfs_distance", "parameter_list": "(n, graph, start)" }, { "docstring": null, "function_declaration": "def find_tree_diameter(n, graph):", "function_name": "find_tree_diameter", "p...
[ 1, 1, 0, 0, 0, 0, 1, 0, 0, 0 ]
3
hard
0.3
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "from collections import deque\n\ndef find_centrality(n, edges):\n if n == 1:\n print(0)\n print(1)\n return\n \n # Create adjace...
trial_gpt4o_6
{ "original_instruction": "In the kingdom of Zylandia, cities are connected by bidirectional roads forming a tree structure. There are exactly $$$n$$$ cities and $$$n-1$$$ roads. Each city is represented as a node in a tree, and each road is an edge. Your task is to help Zylandia's royal network administration determ...
0.617504
Codeforces_4713
C
[ "bfs_distance", "find_tree_diameter", "find_centrality" ]
3
[ [ "find_centrality", "find_tree_diameter" ], [ "find_tree_diameter", "bfs_distance" ] ]
2
[]
false
[]
false
pytest
true
[]
true
c3a8bdb6b1c8bebbc4e1030594790f211e1c391e
b9fc9941631c37b91fc1a58b9179a14e3de52ac0
v1.0
complete
Codeforces
Codeforces_6161_C
def minimum_new_roads(n: int, roads: List[Tuple[int, int, int]]) -> int: """ Determine the minimum number of new roads needed to ensure there's at least one path between every pair of cities. >>> minimum_new_roads(4, [(1, 2, 1), (2, 3, 1), (3, 4, 1)]) 0 >>> minimum_new_roads(6, [(1, 2, 3), (2, 3, 2), (4...
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] = roo...
from solution import minimum_new_roads def test_all_connected(): assert minimum_new_roads(4, [(1, 2, 1), (2, 3, 1), (3, 4, 1)]) == 0 def test_disjoint_sets(): assert minimum_new_roads(6, [(1, 2, 3), (2, 3, 2), (4, 5, 4), (5, 6, 6)]) == 1 def test_single_city(): assert minimum_new_roads(1, []) == 0 def t...
[ { "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, 1, 0 ]
2
hard
0.222
{ "trial_gpt4o_0": null, "trial_gpt4o_1": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared1_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):\...
trial_gpt4o_7
{ "original_instruction": "In a country, there are $$$n$$$ cities and $$$m$$$ bidirectional roads connecting them. The cities are numbered from $$$1$$$ to $$$n$$$. Each road has a certain weight, representing the time it takes to travel that road.\n\nThe government wants to improve the transportation system by ensuri...
0.769305
Codeforces_6161
C
[ "find", "union", "minimum_new_roads" ]
3
[ [ "minimum_new_roads", "find" ], [ "minimum_new_roads", "union" ], [ "union", "find" ] ]
3
[]
false
[]
false
pytest
true
[]
true
f8df3ca5ff23ec3b3f852a633fe93ba864f62983
3d8ac1afe5ed55d8b02fffb4ee2d82dcfeed472e
v1.0
complete
Codeforces
Codeforces_5271_C
from typing import List def max_contiguous_subgrid_sum(N: int, grid: List[List[int]]) -> int: """ Given an N x N grid of non-negative integers, find the maximum sum of any contiguous subgrid. Example usage: >>> max_contiguous_subgrid_sum(4, [ ... [1, 2, 3, 4], ... [5, 6, 7, 8], ... [9,...
def find_max_subgrid_sum(grid, N): def max_sum_subarray(arr): max_sum = arr[0] curr_sum = arr[0] for i in range(1, len(arr)): curr_sum = max(arr[i], curr_sum + arr[i]) max_sum = max(max_sum, curr_sum) return max_sum max_sum = float('-inf') for le...
from solution import max_contiguous_subgrid_sum def test_example_case(): N = 4 grid = [ [1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12], [13, 14, 15, 16] ] assert max_contiguous_subgrid_sum(N, grid) == 136 def test_single_element_grid(): N = 1 grid = [[42]] asse...
[ { "docstring": null, "function_declaration": "def find_max_subgrid_sum(grid, N):", "function_name": "find_max_subgrid_sum", "parameter_list": "(grid, N)" }, { "docstring": null, "function_declaration": "def max_contiguous_subgrid_sum(N, grid):", "function_name": "max_contiguous_subgr...
[ 0, 0, 1, 0, 0, 0, 1, 1, 0, 0 ]
3
hard
0.3
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def max_sum_subgrid(N, grid):\n \"\"\"\n Returns the maximum sum of any contiguous subgrid in the given N x N grid.\n \"\"\"\n max_sum = float('-i...
trial_gpt4o_6
{ "original_instruction": "A company is hosting a competition where participants are required to solve a unique puzzle. The puzzle involves a grid of size $$$N \\times N$$$, filled with non-negative integers. Participants need to determine the highest value that can be obtained by summing a contiguous subgrid within ...
0.601783
Codeforces_5271
C
[ "find_max_subgrid_sum", "max_contiguous_subgrid_sum" ]
2
[ [ "max_contiguous_subgrid_sum", "find_max_subgrid_sum" ] ]
1
[]
false
[]
false
pytest
true
[]
true
51d5078817baca153b686a1baca9d157c4571716
7f5b600695f639362d3fd9f6825c589458ae5cd0
v1.0
complete
Codeforces
Codeforces_6030_C
from typing import List from functools import reduce from itertools import combinations from math import gcd def find_gcd_of_list(lst: List[int]) -> int: if not lst: return 0 return reduce(gcd, lst) def largest_gcd_subset(n: int, numbers: List[int]) -> List[int]: """ Given a list of distinct posit...
from math import gcd from itertools import combinations from functools import reduce def find_gcd_of_list(lst): if not lst: return 0 return reduce(gcd, lst) def largest_gcd_subset(n, numbers): max_subset = [] for r in range(2, n + 1): for subset in combinations(numbers, r): ...
from solution import largest_gcd_subset def test_example_1(): result = largest_gcd_subset(3, [10, 20, 30]) assert sorted(result) == [10, 20, 30] def test_example_2(): result = largest_gcd_subset(3, [7, 11, 13]) assert result == [] def test_mixed_numbers(): result = largest_gcd_subset(4, [6, 10, 1...
[ { "docstring": null, "function_declaration": "def find_gcd_of_list(lst):", "function_name": "find_gcd_of_list", "parameter_list": "(lst)" }, { "docstring": null, "function_declaration": "def largest_gcd_subset(n, numbers):", "function_name": "largest_gcd_subset", "parameter_list"...
[ 0, 0, 0, 0, 0, 1, 0, 0, 0, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "import math\nfrom collections import defaultdict\n\ndef find_largest_subset_with_gcd_greater_than_one(n, arr):\n \"\"\"\n Find the largest subset of the...
trial_gpt4o_5
{ "original_instruction": "Given a list of distinct positive integers, find the largest subset of the list such that the greatest common divisor (GCD) of all the integers in the subset is greater than one. If no such subset exists, return an empty list.\n\nThe first line of the input contains a single integer n (1 ≤ ...
0.63591
Codeforces_6030
C
[ "find_gcd_of_list", "largest_gcd_subset" ]
2
[ [ "largest_gcd_subset", "find_gcd_of_list" ] ]
1
[]
false
[]
false
pytest
true
[]
true
59d0616d2f4b31780927866bb46f6c24a6e71a15
c7037994e677bb95959ef333e086cbdd6c9f100e
v1.0
complete
Codeforces
Codeforces_5792_C
from typing import List, Tuple def prefix_sums(arr: List[int]) -> List[int]: """ Returns the prefix sum array of the given array `arr`. >>> prefix_sums([1, 2, 3, 4, 5]) [0, 1, 3, 6, 10, 15] >>> prefix_sums([0, 0, 0]) [0, 0, 0, 0] >>> prefix_sums([10, 20, 30]) [0, 10, 30, 60] """ ...
def prefix_sums(arr): """ Returns the prefix sum array of the given array `arr`. """ n = len(arr) prefix = [0] * (n + 1) for i in range(1, n + 1): prefix[i] = prefix[i - 1] + arr[i - 1] return prefix def query_sum(prefix, l, r): """ Returns the sum of elements from index l t...
from solution import prefix_sums, query_sum, process_queries def test_prefix_sums(): assert prefix_sums([1, 2, 3, 4, 5]) == [0, 1, 3, 6, 10, 15] assert prefix_sums([0, 0, 0]) == [0, 0, 0, 0] assert prefix_sums([10, 20, 30]) == [0, 10, 30, 60] def test_query_sum(): prefix = prefix_sums([1, 2, 3, 4, 5])...
[ { "docstring": "Returns the prefix sum array of the given array `arr`.", "function_declaration": "def prefix_sums(arr):", "function_name": "prefix_sums", "parameter_list": "(arr)" }, { "docstring": "Returns the sum of elements from index l to r using the prefix sum array.", "function_dec...
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
10
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def process_queries(n, q, array, queries):\n # Precompute prefix sums\n prefix_sums = [0] * (n + 1)\n for i in range(n):\n prefix_sums[i + 1] ...
trial_gpt4o_9
{ "original_instruction": "## New Coding Assessment Question\n\n\n\nВ первой строке дано два целых числа $$$n$$$ и $$$q$$$ ($$$1 \\le n \\le 1\\,000\\,000$$$) — размер массива и количество запросов соответственно.\n\nВо второй строке даны $$$n$$$ целых чисел $$$arr_i$$$ ($$$0 \\le arr_i \\le 10^9$$$) — количество опе...
0.584073
Codeforces_5792
C
[ "prefix_sums", "query_sum", "process_queries" ]
3
[ [ "process_queries", "prefix_sums" ], [ "process_queries", "query_sum" ] ]
2
[ "process_queries" ]
false
[]
false
pytest
true
[]
true
33021d9fa60c6d9673c8907615375e5754e9320b
6cb10009447d02e1f6cadc236c47083fb745b980
v1.0
complete
Codeforces
Codeforces_6140_C
def reverse_and_remove_leading_zeros(n): """ Reverses the digits of n and removes any leading zeros from the reversed number. >>> reverse_and_remove_leading_zeros(104) 401 >>> reverse_and_remove_leading_zeros(100) 1 >>> reverse_and_remove_leading_zeros(1200) 21 >>> reverse_and_remove...
def reverse_and_remove_leading_zeros(n): """ Reverses the digits of n and removes any leading zeros from the reversed number. """ reversed_n = str(n)[::-1].lstrip('0') return int(reversed_n) def is_prime(m): """ Determines if a number m is a prime number. """ if m <= 1: retu...
from solution import reverse_prime, reverse_and_remove_leading_zeros, is_prime def test_reverse_and_remove_leading_zeros(): assert reverse_and_remove_leading_zeros(104) == 401 assert reverse_and_remove_leading_zeros(100) == 1 assert reverse_and_remove_leading_zeros(1200) == 21 assert reverse_and_remove...
[ { "docstring": "Reverses the digits of n and removes any leading zeros from the reversed number.", "function_declaration": "def reverse_and_remove_leading_zeros(n):", "function_name": "reverse_and_remove_leading_zeros", "parameter_list": "(n)" }, { "docstring": "Determines if a number m is a...
[ 1, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def reverse_and_remove_leading_zeros(n):\n \"\"\"\n Reverses the digits of n and removes any leading zeros from the reversed number.\n \"\"\"\n re...
trial_gpt4o_0
{ "original_instruction": "Alice and Bob are playing a game with numbers. The game starts with a non-negative integer $$$n$$$. Alice wants to test Bob's abilities by giving him the reverse of this number, $$$m$$$, but with a twist. She will remove any leading zeroes from the reversed number.\n\nBob's task is to deter...
0.761157
Codeforces_6140
C
[ "reverse_and_remove_leading_zeros", "is_prime", "reverse_prime" ]
3
[ [ "reverse_prime", "is_prime" ], [ "reverse_prime", "reverse_and_remove_leading_zeros" ] ]
2
[]
false
[]
false
pytest
true
[]
true
366066a7d0ffd2a9b9419c368acdd158bc144681
dac04e00c26f78208ced371215a802242a9240ee
v1.0
complete
Codeforces
Codeforces_6041_C
import math def euclidean_distance(x1, y1, x2, y2): """ Returns the Euclidean distance between two points (x1, y1) and (x2, y2). >>> math.isclose(euclidean_distance(0, 0, 3, 4), 5.0, rel_tol=1e-4) True >>> math.isclose(euclidean_distance(-1, -1, 1, 1), 2.8284, rel_tol=1e-4) True >>> math.isclos...
import math def euclidean_distance(x1, y1, x2, y2): """ Returns the Euclidean distance between two points (x1, y1) and (x2, y2). """ return math.sqrt((x2 - x1) ** 2 + (y2 - y1) ** 2) def shortest_path(x1, y1, x2, y2, rectangles): """ Returns the shortest path from (x1, y1) to (x2, y2) without ...
from solution import euclidean_distance, shortest_path def test_euclidean_distance(): assert math.isclose(euclidean_distance(0, 0, 3, 4), 5.0, rel_tol=1e-4) assert math.isclose(euclidean_distance(-1, -1, 1, 1), 2.8284, rel_tol=1e-4) assert math.isclose(euclidean_distance(2, 2, 5, 5), 4.2426, rel_tol=1e-4) ...
[ { "docstring": "Returns the Euclidean distance between two points (x1, y1) and (x2, y2).", "function_declaration": "def euclidean_distance(x1, y1, x2, y2):", "function_name": "euclidean_distance", "parameter_list": "(x1, y1, x2, y2)" }, { "docstring": "Returns the shortest path from (x1, y1)...
[ 1, 0, 0, 0, 0, 0, 1, 0, 0, 1 ]
3
hard
0.3
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "import math\n\ndef is_inside_rectangle(px, py, rect):\n \"\"\"\n Returns True if the point (px, py) is inside the rectangle\n defined by rect (xi1, y...
trial_gpt4o_6
{ "original_instruction": "You are given two points on a 2D plane and several rectangles. Your task is to draw the shortest possible line segment connecting the two points such that the segment does not intersect any of the given rectangles, but it can touch the edges of the rectangles.\n\nEach rectangle is axis-alig...
0.671281
Codeforces_6041
C
[ "euclidean_distance", "shortest_path" ]
2
[ [ "shortest_path", "euclidean_distance" ] ]
1
[]
false
[]
false
pytest
true
[]
true
ac397200795a8e3b6ced3620f752508f6557ed50
c556098db79430ec03e14562ec6be792164d167f
v1.0
complete
Codeforces
Codeforces_6122_C
from typing import List, Tuple def experiments_conflict(experiments: List[Tuple[str, str]]) -> str: """ Determine if there is a conflict between the given experiment times. >>> experiments_conflict([("09:00", "10:00"), ("10:00", "11:00"), ("11:30", "12:30")]) "NO CONFLICT" >>> experiments_conflict([("0...
from typing import List, Tuple def to_minutes(time_str: str) -> int: """ Convert a time string in format "HH:MM" to minutes since midnight. """ hours, minutes = map(int, time_str.split(':')) return hours * 60 + minutes def experiments_conflict(experiments: List[Tuple[str, str]]) -> str: times ...
def test_no_conflict(): experiments = [("09:00", "10:00"), ("10:00", "11:00"), ("11:30", "12:30")] assert experiments_conflict(experiments) == "NO CONFLICT" def test_conflict(): experiments = [("09:00", "10:00"), ("09:30", "10:30"), ("11:00", "12:00")] assert experiments_conflict(experiments) == "CONFL...
[ { "docstring": "Convert a time string in format \"HH:MM\" to minutes since midnight.", "function_declaration": "def to_minutes(time_str):", "function_name": "to_minutes", "parameter_list": "(time_str)" }, { "docstring": null, "function_declaration": "def experiments_conflict(experiments)...
[ 1, 1, 0, 1, 1, 1, 1, 1, 1, 0 ]
8
easy
0.8
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "from typing import List, Tuple\n\ndef time_to_minutes(time: str) -> int:\n \"\"\"\n Convert time in \"HH:MM\" format to minutes since midnight.\n \"\...
trial_gpt4o_8
{ "original_instruction": "The International Space Station (ISS) needs a new scheduling system for experiments. The ISS operates on an Earth-standard 24-hour day (00:00 to 23:59). The astronauts have a list of experiment start and end times they need to fit into a day’s schedule. Given the list of experiments and the...
0.537316
Codeforces_6122
C
[ "to_minutes", "experiments_conflict" ]
2
[ [ "experiments_conflict", "to_minutes" ] ]
1
[]
false
[]
false
pytest
false
[]
true
719814e18596d517b5e7e49d57663cd2876e054f
edb7032181d4450c1669683783c133c661f1cb16
v1.0
complete
Codeforces
Codeforces_6803_C
def determine_winner(a: int, b: int) -> str: """ Determine which player will win if both players play optimally given two stacks of coins. >>> determine_winner(5, 7) "Player 1" >>> determine_winner(1, 1) "Player 2" >>> determine_winner(4, 4) "Player 2" >>> determine_winner(10, 15) "Player 1" >>>...
def is_prime(n): """Helper function to check if a number is prime""" if n <= 1: return False if n <= 3: return True if n % 2 == 0 or n % 3 == 0: return False i = 5 while i * i <= n: if n % i == 0 or n % (i + 2) == 0: return False i += 6 ret...
from solution import determine_winner def test_case_1(): assert determine_winner(5, 7) == "Player 1" def test_case_2(): assert determine_winner(1, 1) == "Player 2" def test_case_3(): assert determine_winner(4, 4) == "Player 2" def test_case_4(): assert determine_winner(10, 15) == "Player 1" def tes...
[ { "docstring": "Helper function to check if a number is prime", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Compute the Grundy number for a given pile size", "function_declaration": "def find_grundy_number(n):", ...
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def sieve(n):\n \"\"\"\n Returns a list of prime numbers up to n (inclusive).\n \"\"\"\n is_prime = [True] * (n + 1)\n p = 2\n while (p * p ...
trial_gpt4o_9
{ "original_instruction": "You are provided with two stacks of coins. The first stack contains `a` coins and the second stack contains `b` coins. Two players alternate turns, with Player 1 acting first. On a player's turn, they can choose to either remove 1 coin or a prime number of coins from one of the stacks. The ...
0.752153
Codeforces_6803
C
[ "is_prime", "find_grundy_number", "determine_winner" ]
3
[ [ "determine_winner", "find_grundy_number" ], [ "find_grundy_number", "is_prime" ] ]
2
[]
false
[]
false
pytest
true
[]
true
e27df734546899cbe81159ebdc4d27810aa48b71
06b920d5f0962b4980462e6899a5d613365db342
v1.0
complete
Codeforces
Codeforces_5916_C
from typing import List def can_form_palindrome(s: str) -> str: """ Determine if the given string can be rearranged to form a palindrome. Args: s (str): Input string consisting of lowercase English letters. Returns: str: "Yes" if the string can be rearranged to form a palindrome, otherwise "N...
def can_form_palindrome(s): """ Determine if the given string can be rearranged to form a palindrome. Args: s (str): Input string consisting of lowercase English letters. Returns: str: "Yes" if the string can be rearranged to form a palindrome, otherwise "No". """ from collecti...
from solution import can_form_palindrome, process_strings def test_can_form_palindrome_yes(): assert can_form_palindrome("aabb") == "Yes" assert can_form_palindrome("carerac") == "Yes" assert can_form_palindrome("aaabbbb") == "Yes" assert can_form_palindrome("racecar") == "Yes" assert can_form_pali...
[ { "docstring": "Determine if the given string can be rearranged to form a palindrome.\n\nArgs:\ns (str): Input string consisting of lowercase English letters.\n\nReturns:\nstr: \"Yes\" if the string can be rearranged to form a palindrome, otherwise \"No\".", "function_declaration": "def can_form_palindrome(...
[ 0, 1, 0, 0, 0, 0, 1, 1, 1 ]
4
medium
0.444
{ "trial_gpt4o_0": null, "trial_gpt4o_1": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared1_results_combined.jsonl", "solution_code": "def can_form_palindrome(s):\n \"\"\"\n Check if the given string can be rearranged to form a palindrome.\n \n A string ca...
trial_gpt4o_9
{ "original_instruction": "A small village is organizing a tournament of string games. Each game involves rearranging strings according to specific rules. The tournament committee decided to create a challenge for the participants: for each given string, they must determine whether it can be rearranged to become a pa...
0.749146
Codeforces_5916
C
[ "can_form_palindrome", "process_strings" ]
2
[ [ "process_strings", "can_form_palindrome" ] ]
1
[]
false
[]
false
pytest
true
[]
true
91eeb97f58b7233e676b6c7e20eda8ce372b7690
917fa12ded372c2d25a1a309764df312a754301d
v1.0
complete
Codeforces
Codeforces_6091_C
from typing import List, Tuple def is_route_with_exactly_k_lit_intersections(n: int, m: int, k: int, lit: List[int], edges: List[Tuple[int, int]]) -> str: """ Determine if there exists a parade route that passes through exactly k lit intersections. >>> is_route_with_exactly_k_lit_intersections(6, 7, 3, [3, 5, ...
def dfs(graph, node, target_lights, lit, visited, lit_visited, result): if lit_visited == target_lights: result[0] = True return visited[node] = True for neighbor in graph[node]: if not visited[neighbor]: dfs(graph, neighbor, target_lights, lit, visited, lit_visited + (1...
def test_case_1(): n, m, k = 6, 7, 3 lit = [3, 5, 6] edges = [(1, 2), (2, 3), (3, 4), (4, 5), (5, 6), (6, 1), (1, 3)] assert is_route_with_exactly_k_lit_intersections(n, m, k, lit, edges) == "YES" def test_case_2(): n, m, k = 6, 7, 2 lit = [3, 5] edges = [(1, 2), (2, 3), (3, 4), (4, 5), (5,...
[ { "docstring": null, "function_declaration": "def dfs(graph, node, target_lights, lit, visited, lit_visited, result):", "function_name": "dfs", "parameter_list": "(graph, node, target_lights, lit, visited, lit_visited, result)" }, { "docstring": null, "function_declaration": "def is_rout...
[ 0, 0, 0, 0, 0, 0, 0, 0, 1, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def parade_route_exists(n, m, k, lit_intersections, streets):\n from collections import defaultdict, deque\n \n lit_intersections_set = set(lit_inter...
trial_gpt4o_8
{ "original_instruction": "A city has n intersections connected by m one-way streets. Each street allows travel from one intersection to another in one specific direction. Since this city is famous for its nightly parades, some intersections have been set up with colorful lights, while others remain unlit.\n\nThe cit...
0.640646
Codeforces_6091
C
[ "dfs", "is_route_with_exactly_k_lit_intersections" ]
2
[ [ "is_route_with_exactly_k_lit_intersections", "dfs" ] ]
1
[]
false
[]
false
pytest
false
[]
true
0ccab9f0b5e09dfd8c3c4057d86a54317eed251b
1a65531a6c6233139e6861ba012fa7b13e167f5d
v1.0
complete
Codeforces
Codeforces_5692_C
MOD = 1000000007 def is_perfect_square(x): return int(x**0.5)**2 == x def count_ways_to_fill_board(n, board): """You are given a square n × n board. Some cells are already filled with distinct positive integers. Your task is to fill each empty cell with any positive integer such that the resulting config...
MOD = 1000000007 def is_perfect_square(x): return int(x**0.5)**2 == x def count_ways_to_fill_board(n, board): # This is a highly non-trivial task, a simple direct approach won't work due to constraints # Instead we focus on constraints and perfect squares checking for 2x2 sub-matrix if n == 1: ...
from solution import count_ways_to_fill_board def test_single_filled_cell(): n = 1 board = [ [0] ] assert count_ways_to_fill_board(n, board) == 1 def test_single_fixed_filled_cell(): n = 1 board = [ [5] ] assert count_ways_to_fill_board(n, board) == 1 def test_4x4_boa...
[ { "docstring": null, "function_declaration": "def is_perfect_square(x):", "function_name": "is_perfect_square", "parameter_list": "(x)" }, { "docstring": null, "function_declaration": "def count_ways_to_fill_board(n, board):", "function_name": "count_ways_to_fill_board", "paramet...
[ 0, 1, 0, 1, 0, 0, 0 ]
2
hard
0.286
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_perfect_square(x):\n from math import isqrt\n s = isqrt(x)\n return s * s == x\n\ndef count_ways_to_fill_board(n, board):\n MOD = 100000000...
trial_gpt4o_1
{ "original_instruction": "You are given a square n × n board. Some cells are already filled with distinct positive integers. Your task is to fill each empty cell with any positive integer such that the resulting configuration satisfies the following property: For any 2 × 2 sub-board, the sum of its four cells must b...
0.615814
Codeforces_5692
C
[ "is_perfect_square", "count_ways_to_fill_board" ]
2
[ [ "count_ways_to_fill_board", "is_perfect_square" ] ]
1
[]
false
[]
false
pytest
true
[]
true
0d39cb6dc6faeb38f5f42c4aa497773a2f8509c1
d11920f0237efb9bf0b979c784f26529e7848aa9
v1.0
complete
Codeforces
Codeforces_5631_C
from typing import List, Tuple def solve_graph_queries(n: int, m: int, q: int, node_values: List[int], edges: List[Tuple[int, int, int]], queries: List[Tuple[int, int]]) -> List[int]: """ You are given an undirected graph with `n` nodes and `m` edges. Each node has a unique integer value assigned to it, and ea...
import heapq def calculate_minimum_costs(n, m, q, node_values, edges, queries): # Build the graph graph = {i: [] for i in range(1, n+1)} for u, v, w in edges: graph[u].append((v, w)) graph[v].append((u, w)) def dijkstra(source): dist = {i: float('inf') for i in range(1,...
from solution import solve_graph_queries def test_example(): n, m, q = 5, 6, 3 node_values = [5, 1, 3, 2, 4] edges = [ (1, 2, 2), (1, 3, 3), (2, 4, 4), (3, 5, 1), (4, 5, 5), (2, 5, 7) ] queries = [ (1, 4), (3, 4), (1, 5) ] ...
[ { "docstring": null, "function_declaration": "def calculate_minimum_costs(n, m, q, node_values, edges, queries):", "function_name": "calculate_minimum_costs", "parameter_list": "(n, m, q, node_values, edges, queries)" }, { "docstring": null, "function_declaration": "def solve_graph_queri...
[ 0, 0, 0, 0, 0, 1, 0, 0, 0, 1 ]
2
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "import heapq\nimport sys\nfrom collections import defaultdict\n\ndef min_cost_on_shortest_path(n, m, q, values, edges, queries):\n graph = defaultdict(list...
trial_gpt4o_9
{ "original_instruction": "You are given an undirected graph with `n` nodes and `m` edges. Each node has a unique integer value assigned to it, and each edge has a non-negative weight.\n\nYour task is to answer `q` queries. Each query provides two nodes, `u` and `v`, and asks for the minimum cost to visit all nodes' ...
0.750716
Codeforces_5631
C
[ "calculate_minimum_costs", "solve_graph_queries" ]
2
[ [ "solve_graph_queries", "calculate_minimum_costs" ] ]
1
[]
false
[]
false
pytest
true
[]
true
af455efb6d9dbf2664bef070d1562fdc21754217
b78e2dd9e026d252b4c4dcc6e9d06641c56143ed
v1.0
complete
Codeforces
Codeforces_5622_C
def parse_and_find_largest_rectangle_area(input_str: str) -> int: """ Given a string representation of the grid, determine the size of the largest rectangle that can be formed by empty spaces ('.'). The input string includes dimensions followed by the grid itself. >>> parse_and_find_largest_...
def largest_rectangle_area(grid): """ Given a grid of '.' and '#', find the area of the largest rectangle filled with only '.'. """ n = len(grid) m = len(grid[0]) # Create an array to store the height of histogram columns heights = [0] * m max_area = 0 for i in range(n...
def test_largest_rectangle_area(): assert parse_and_find_largest_rectangle_area("4 4\n....\n..#.\n...#\n##..") == 6, "Test case 1 failed" assert parse_and_find_largest_rectangle_area("1 1\n.") == 1, "Test case 2 failed" assert parse_and_find_largest_rectangle_area("1 1\n#") == 0, "Test case 3 failed" as...
[ { "docstring": "Given a grid of '.' and '#', find the area of the largest rectangle \nfilled with only '.'.", "function_declaration": "def largest_rectangle_area(grid):", "function_name": "largest_rectangle_area", "parameter_list": "(grid)" }, { "docstring": "Given an array of heights, deter...
[ 0, 0, 0, 0, 1, 1, 0, 1, 0, 1 ]
4
medium
0.4
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def max_histogram_area(histogram):\n stack = []\n max_area = 0\n index = 0\n while index < len(histogram):\n if not stack or histogram[stac...
trial_gpt4o_5
{ "original_instruction": "You're given a grid of size n × m filled with characters '.' (representing empty space) and '#' (representing walls). Your task is to determine the size of the largest rectangle that can be formed by empty spaces ('.') within the grid. \n\nThe first line of the input contains two integers n...
0.676024
Codeforces_5622
C
[ "largest_rectangle_area", "max_histogram_area", "parse_and_find_largest_rectangle_area" ]
3
[ [ "largest_rectangle_area", "max_histogram_area" ], [ "parse_and_find_largest_rectangle_area", "largest_rectangle_area" ] ]
2
[]
false
[]
false
pytest
false
[]
true
8f9630d0358ab34db918fdbbc3563d1296ec1270
4cf6ec2e41cbc3e22e3ec53213e179fa9c4218be
v1.0
complete
Codeforces
Codeforces_5266_C
from collections import deque from typing import List, Tuple def max_flow(N: int, M: int, edges: List[Tuple[int, int, int]]) -> int: """ Given a network represented as an undirected graph with N nodes and M edges, each edge having a certain capacity, find the maximum flow from node 1 to node N in this...
from collections import deque def bfs_capacity_capacity(network, source, sink, parent): visited = [False] * len(network) queue = deque([source]) visited[source] = True while queue: u = queue.popleft() for v, capacity in enumerate(network[u]): if not visited[v] ...
from solution import max_flow def test_example_case(): N = 4 M = 5 edges = [ (1, 2, 100), (1, 3, 100), (2, 4, 100), (3, 4, 100), (2, 3, 1) ] assert max_flow(N, M, edges) == 200 def test_small_graph(): N = 2 M = 1 edges = [ (1, 2, 10) ...
[ { "docstring": null, "function_declaration": "def bfs_capacity_capacity(network, source, sink, parent):", "function_name": "bfs_capacity_capacity", "parameter_list": "(network, source, sink, parent)" }, { "docstring": null, "function_declaration": "def edmonds_karp(network, source, sink)...
[ 1, 0, 0, 0, 1, 0, 1, 0, 0, 0 ]
3
hard
0.3
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "from collections import defaultdict, deque\n\ndef bfs(C, F, source, sink, parent):\n \"\"\"Breadth-First Search to find path with available capacity.\"\"\"...
trial_gpt4o_6
{ "original_instruction": "Given a network represented as an undirected graph with N nodes and M edges, each edge having a certain capacity. You need to find the maximum flow from node 1 to node N in this network using the Edmonds-Karp algorithm, an implementation of the Ford-Fulkerson method for computing the maximu...
0.564529
Codeforces_5266
C
[ "bfs_capacity_capacity", "edmonds_karp", "max_flow" ]
3
[ [ "edmonds_karp", "bfs_capacity_capacity" ], [ "max_flow", "edmonds_karp" ] ]
2
[]
false
[]
false
pytest
true
[]
true
ce2cc5e4798dadc8e54d8c4db7c05c1f29754b53
fd5df7297dc0d27d77815c3ec2dc65635c1051a3
v1.0
complete
Codeforces
Codeforces_6190_C
def minimum_steps_to_meet(m: int, n: int, grid: List[List[str]], friend1: Tuple[int, int], friend2: Tuple[int, int]) -> int: """ Determines the minimum number of steps required for two friends to meet in a rectangular grid farm represented by `m x n` cells. Parameters: - m (int): number of rows in the ...
from collections import deque def bfs_shortest_path(grid, start, end, m, n): queue = deque([(start[0], start[1], 0)]) # (x, y, distance) visited = set() visited.add((start[0], start[1])) directions = [(-1, 0), (1, 0), (0, -1), (0, 1)] while queue: x, y, dist = queue.popleft() ...
from solution import minimum_steps_to_meet def test_example_case(): m, n = 5, 5 grid = [ ['.', '.', '.', '.', '.'], ['.', 'T', '.', '.', 'T'], ['.', '.', '.', '.', '.'], ['T', '.', '.', '.', '.'], ['.', '.', '.', '.', '.'], ] friend1 = (1, 1) friend2 = (4, 4)...
[ { "docstring": null, "function_declaration": "def bfs_shortest_path(grid, start, end, m, n):", "function_name": "bfs_shortest_path", "parameter_list": "(grid, start, end, m, n)" }, { "docstring": null, "function_declaration": "def minimum_steps_to_meet(m, n, grid, friend1, friend2):", ...
[ 0, 0, 0, 0, 1, 0, 0, 0, 0, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "from collections import deque\n\ndef min_steps_to_meet(m, n, t, grid, empty_cells, friend1, friend2):\n \"\"\"\n Returns the minimum number of steps req...
trial_gpt4o_4
{ "original_instruction": "You are given a rectangular farm represented as a grid with `m x n` cells. Each cell can either be empty (represented by '.') or have a tree (represented by 'T'). Two friends are standing on two distinct empty cells, and they want to meet each other by the shortest path. They can move up, d...
0.66389
Codeforces_6190
C
[ "bfs_shortest_path", "minimum_steps_to_meet" ]
2
[ [ "minimum_steps_to_meet", "bfs_shortest_path" ] ]
1
[]
false
[]
false
pytest
true
[]
true
1717db6d855c94178f6e882a11c01e25812820a7
89aa0be97f9345a131820784201c6e167244f2b1
v1.0
complete
Codeforces
Codeforces_4293_C
import pandas as pd import numpy as np from sklearn.model_selection import train_test_split from sklearn.impute import SimpleImputer from sklearn.preprocessing import StandardScaler from sklearn.ensemble import RandomForestRegressor from sklearn.pipeline import Pipeline from sklearn.metrics import mean_squared_error fr...
import pandas as pd import numpy as np from sklearn.model_selection import train_test_split from sklearn.impute import SimpleImputer from sklearn.preprocessing import StandardScaler from sklearn.ensemble import RandomForestRegressor from sklearn.pipeline import Pipeline from sklearn.metrics import mean_squared_error fr...
from solution import preprocess_data, train_model, predict_rul, save_submission, calculate_rmse import pandas as pd import os def test_preprocess_data(): df = pd.DataFrame({ 'machine_id': [1, 2], 'timestamp': ['2023-01-01 00:00:00', '2023-01-01 00:01:00'], 'sensor_1': [1.0, 2.0], 's...
[ { "docstring": "Preprocess the input data by handling missing values and standardizing the features.\n\nParameters:\n- df: DataFrame containing the machine sensor data and RUL column.\n\nReturns:\n- Transformed DataFrame with sensor data preprocessed.", "function_declaration": "def preprocess_data(df):", ...
[ 0, 0, 0, 0, 0, 1, 1, 0, 0, 0 ]
2
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "import pandas as pd\nimport numpy as np\nfrom sklearn.preprocessing import StandardScaler\nfrom sklearn.impute import SimpleImputer\nfrom sklearn.ensemble imp...
trial_gpt4o_5
{ "original_instruction": "The task is to predict the remaining useful life (RUL) of a set of industrial machines based on historical sensor data. For each machine, you are given time-series sensor data collected from various sensors installed on the machines. Your goal is to build a model that can estimate the remai...
0.691013
Codeforces_4293
C
[ "preprocess_data", "train_model", "predict_rul", "save_submission", "calculate_rmse" ]
5
[ [ "predict_rul", "preprocess_data" ], [ "train_model", "preprocess_data" ] ]
2
[]
false
[]
false
pytest
true
[ "numpy", "pandas", "sklearn" ]
false
d8cbc33caeac8ea127c97096cbb8d59b749e5013
1731f056443417a557f1d99bdf5cb34dc27fdf41
v1.0
complete
Codeforces
Codeforces_6073_C
from typing import List def filter_valid_ips(ip_list: List[str]) -> List[str]: """ You are given a list of strings representing IP addresses, some of which are potentially valid IPv4 addresses and others are not. A valid IPv4 address is formatted as `a.b.c.d`, where `a`, `b`, `c`, and `d` are integers in the i...
from typing import List def is_valid_ipv4(ip: str) -> bool: parts = ip.split('.') if len(parts) != 4: return False for part in parts: if not part.isdigit(): return False if len(part) > 1 and part[0] == '0': return False if int(part) < 0 or int(part) >...
import pytest from solution import filter_valid_ips def test_mixed_ips(): assert filter_valid_ips([ "192.168.0.1", "255.255.255.255", "256.100.100.100", "123.45.67.89", "1.1.1", "01.02.03.04" ]) == ["123.45.67.89", "192.168.0.1", "255.255.255.255"] def test_all_valid_ips(): assert filter_...
[ { "docstring": null, "function_declaration": "def is_valid_ipv4(ip):", "function_name": "is_valid_ipv4", "parameter_list": "(ip)" }, { "docstring": null, "function_declaration": "def filter_valid_ips(ip_list):", "function_name": "filter_valid_ips", "parameter_list": "(ip_list)" ...
[ 1, 1, 1, 1, 0, 1, 1, 1, 1, 1 ]
9
easy
0.9
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "from typing import List\n\ndef filter_valid_ips(ip_list: List[str]) -> List[str]:\n def is_valid_ip(ip: str) -> bool:\n parts = ip.split('.')\n ...
trial_gpt4o_9
{ "original_instruction": "You are given a list of strings representing IP addresses, some of which are potentially valid IPv4 addresses and others are not. A valid IPv4 address is formatted as `a.b.c.d`, where `a`, `b`, `c`, and `d` are integers in the inclusive range from 0 to 255.\n\nYour task is to implement a fu...
0.601234
Codeforces_6073
C
[ "is_valid_ipv4", "filter_valid_ips" ]
2
[ [ "filter_valid_ips", "is_valid_ipv4" ] ]
1
[]
false
[]
false
pytest
true
[]
true
ed5afdaed1ecd3422cff10b5920fa23699170e40
595f6e0bd441ddf6ae238192c49e0d49a75bbb71
v1.0
complete
Codeforces
Codeforces_6070_C
from math import gcd from typing import List def lcm(a, b): return abs(a * b) // gcd(a, b) def smallest_multiple(N: int) -> int: """Find the smallest number that is evenly divisible by all of the numbers from 1 to N. Args: N (int): The given number such that 1 ≤ N ≤ 20. Returns: int:...
from math import gcd def lcm(a, b): return abs(a * b) // gcd(a, b) def smallest_multiple(N): multiple = 1 for i in range(1, N + 1): multiple = lcm(multiple, i) return multiple
from solution import smallest_multiple def test_smallest_multiple_1(): assert smallest_multiple(1) == 1 def test_smallest_multiple_2(): assert smallest_multiple(2) == 2 def test_smallest_multiple_3(): assert smallest_multiple(3) == 6 def test_smallest_multiple_5(): assert smallest_multiple(5) == 60 ...
[ { "docstring": null, "function_declaration": "def lcm(a, b):", "function_name": "lcm", "parameter_list": "(a, b)" }, { "docstring": null, "function_declaration": "def smallest_multiple(N):", "function_name": "smallest_multiple", "parameter_list": "(N)" } ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
10
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "import math\n\ndef smallest_multiple(N):\n \"\"\"\n Returns the smallest number that is evenly divisible by all of the numbers from 1 to N.\n \"\"\"\...
trial_gpt4o_9
{ "original_instruction": "Write a program to find the smallest number that is evenly divisible by all of the numbers from 1 to a given number N. The number N will be provided as input.\n\nThe program should output one line with the smallest number that is evenly divisible by all numbers in the range from 1 to N.\n\n...
0.695131
Codeforces_6070
C
[ "lcm", "smallest_multiple" ]
2
[ [ "smallest_multiple", "lcm" ] ]
1
[]
false
[]
false
pytest
true
[]
true
f80429e4611b30ac50a47ee05160fb1868a9b48f
2d3e3d48c58aa60e629d772fa7a32c7318b562f8
v1.0
complete
Codeforces
Codeforces_7047_C
def cinderella_flowers(n: int, k: int) -> str: """ Cinderella loves flowers and wants to grow a beautiful garden. She has n flower pots, each of which can grow a certain type of flower. However, she wants to ensure that her garden looks aesthetically pleasing by having at most two consecutive pots with the same typ...
def arrange_flowers(n, k): if k == 1: if n > 2: return -1 else: return [1] * n arrangement = [] for i in range(n): arrangement.append((i % k) + 1) return arrangement def cinderella_flowers(n, k): arrangement = arrange_flowers(n, k) if arrang...
from solution import cinderella_flowers def test_case_1(): assert cinderella_flowers(5, 2) == "1 2 1 2 1" def test_case_2(): assert cinderella_flowers(3, 1) == -1 def test_case_3(): assert cinderella_flowers(3, 3) == "1 2 3" def test_case_4(): assert cinderella_flowers(2, 1) == "1 1" def test_case_...
[ { "docstring": null, "function_declaration": "def arrange_flowers(n, k):", "function_name": "arrange_flowers", "parameter_list": "(n, k)" }, { "docstring": null, "function_declaration": "def cinderella_flowers(n, k):", "function_name": "cinderella_flowers", "parameter_list": "(n,...
[ 1, 0, 1, 0, 1, 1, 1, 1, 1, 1 ]
8
easy
0.8
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def arrange_flowers(n, k):\n if k == 1 and n > 2:\n return -1\n result = []\n for i in range(n):\n result.append((i % k) + 1)\n retu...
trial_gpt4o_9
{ "original_instruction": "Cinderella loves flowers and wants to grow a beautiful garden. She has n flower pots, each of which can grow a certain type of flower. However, she wants to ensure that her garden looks aesthetically pleasing by having at most two consecutive pots with the same type of flower.\n\nEach flowe...
0.529762
Codeforces_7047
C
[ "arrange_flowers", "cinderella_flowers" ]
2
[ [ "cinderella_flowers", "arrange_flowers" ] ]
1
[]
false
[]
false
pytest
true
[]
true
a3104ced36ab335ae19ffb6a1b3935aeaa8e821d
097516849501ac0dc4aa9bd50ccc90769ee561a5
v1.0
complete
Codeforces
Codeforces_6417_C
def calculate_effective_price(base_price, discount_phases, d, t): """ Calculate the effective price of a product given its base price, discount phases, duration of each phase, and time of purchase. >>> calculate_effective_price(100, [10, 20, 15, 5], 10, 0) == 90 >>> calculate_effective_price(100, [10, 20, 1...
def calculate_effective_price(base_price, discount_phases, d, t): phases_count = len(discount_phases) phase_index = (t // d) % phases_count discount_percentage = discount_phases[phase_index] effective_price = base_price * (1 - discount_percentage / 100) return round(effective_price) def calculate_p...
def test_calculate_effective_price(): assert calculate_effective_price(100, [10, 20, 15, 5], 10, 0) == 90 assert calculate_effective_price(100, [10, 20, 15, 5], 10, 15) == 80 assert calculate_effective_price(100, [10, 20, 15, 5], 10, 35) == 95 assert calculate_effective_price(250, [5, 10, 20], 5, 3) == ...
[ { "docstring": null, "function_declaration": "def calculate_effective_price(base_price, discount_phases, d, t):", "function_name": "calculate_effective_price", "parameter_list": "(base_price, discount_phases, d, t)" }, { "docstring": null, "function_declaration": "def calculate_prices_fo...
[ 0, 0, 0, 0, 0, 0, 1, 0, 1, 0 ]
2
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "from math import ceil\n\ndef calculate_effective_price(base_price, k, d, discounts, purchases):\n \"\"\"\n Calculate the effective price of a product fo...
trial_gpt4o_8
{ "original_instruction": "A mega department store uses a unique pricing system for its products. The store labels each product with a base price and a discount percentage that continually rotates in cycles.\n\nEach product has a price markdown schedule that goes through k cycles of varying discount percentages. For ...
0.616925
Codeforces_6417
C
[ "calculate_effective_price", "calculate_prices_for_customers", "mega_department_store" ]
3
[ [ "calculate_prices_for_customers", "calculate_effective_price" ], [ "mega_department_store", "calculate_prices_for_customers" ] ]
2
[]
false
[]
false
pytest
false
[]
true
91dca7a0921224b4d300d94fb43608ade8d0e6ea
d316a9bf0a379c61b8455118d0e996083ccedb13
v1.0
complete
Codeforces
Codeforces_6908_C
from typing import List, Tuple def minimize_max_edge_weight(n: int, m: int, edges: List[Tuple[int, int, int]], a: int, b: int) -> int: """ Determine the minimum possible value of the maximum weight of the edges in the path from node `a` to node `b`. If there is no path between `a` and `b`, return -1. If a...
import heapq from collections import defaultdict, deque def can_reach_with_max_weight(graph, start, end, max_weight, n): visited = [False] * n queue = deque([start]) while queue: node = queue.popleft() if node == end: return True for neighbor, weight in gra...
def test_minimize_max_edge_weight(): assert minimize_max_edge_weight(4, 4, [(1, 2, 2), (2, 3, 2), (2, 4, 5), (3, 4, 6)], 1, 4) == 5 def test_no_path(): assert minimize_max_edge_weight(4, 2, [(1, 2, 10), (2, 3, 10)], 1, 4) == -1 def test_single_node(): assert minimize_max_edge_weight(1, 0, [], 1, 1) == 0 ...
[ { "docstring": null, "function_declaration": "def can_reach_with_max_weight(graph, start, end, max_weight, n):", "function_name": "can_reach_with_max_weight", "parameter_list": "(graph, start, end, max_weight, n)" }, { "docstring": null, "function_declaration": "def minimize_max_edge_wei...
[ 0, 0, 0, 0, 0, 0, 0, 0, 1, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "import heapq\n\ndef minimize_max_edge_weight(n, m, edges, a, b):\n graph = [[] for _ in range(n + 1)]\n for u, v, w in edges:\n graph[u].append((...
trial_gpt4o_8
{ "original_instruction": "There is an undirected graph with $$$n$$$ nodes and $$$m$$$ edges. Each edge connects two nodes $$$u$$$ and $$$v$$$, and is assigned a weight $$$w$$$. Your task is to determine if there exists a path between any two given nodes $$$a$$$ and $$$b$$$ such that the maximum weight of the edges i...
0.753818
Codeforces_6908
C
[ "can_reach_with_max_weight", "minimize_max_edge_weight" ]
2
[ [ "minimize_max_edge_weight", "can_reach_with_max_weight" ] ]
1
[]
false
[]
false
pytest
false
[]
true
9ae0a225513f5cc703cd109c45971292e3c2dab5
33c105cb21844a8c034a0fad94478746912149be
v1.0
complete
Codeforces
Codeforces_6165_C
from collections import deque from typing import List def min_time_required(n: int, m: int, grid: List[str]) -> int: """ Given a grid containing only the characters '0' and '1', where each '0' represents an empty cell and each '1' represents an obstacle, find the minimum time required to reach the bottom-right...
from collections import deque def min_time_to_reach_end(grid): """ Returns the minimum time required to reach the bottom-right corner of the grid from the top-left corner, or -1 if it's impossible. """ n = len(grid) m = len(grid[0]) if grid[0][0] == '1' or grid[n-1][m-1] == '1': re...
from solution import min_time_required def test_basic_case(): n, m = 3, 3 grid = ["001", "010", "000"] assert min_time_required(n, m, grid) == 4 def test_no_path(): n, m = 3, 3 grid = ["011", "111", "111"] assert min_time_required(n, m, grid) == -1 def test_all_zeros(): n, m = 5, 5 gr...
[ { "docstring": "Returns the minimum time required to reach the bottom-right corner \nof the grid from the top-left corner, or -1 if it's impossible.", "function_declaration": "def min_time_to_reach_end(grid):", "function_name": "min_time_to_reach_end", "parameter_list": "(grid)" }, { "docstr...
[ 0, 0, 0, 1, 0, 1, 0, 1, 1, 0 ]
4
medium
0.4
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "from collections import deque\n\ndef min_time_to_reach_bottom_right(n, m, grid):\n if not grid or grid[0][0] == '1' or grid[-1][-1] == '1':\n return...
trial_gpt4o_8
{ "original_instruction": "You are given a grid containing only the characters '0' and '1'. Each '0' represents an empty cell, and each '1' represents an obstacle. You are initially positioned at the top-left corner of the grid (0, 0) and you want to reach the bottom-right corner of the grid (n-1, m-1). You can move ...
0.73012
Codeforces_6165
C
[ "min_time_to_reach_end", "min_time_required" ]
2
[ [ "min_time_required", "min_time_to_reach_end" ] ]
1
[]
false
[]
false
pytest
true
[]
true
439232412726d8f6854c7a14945c073983f0a08c
1ad9c2772fc597e92486c316601bdaad176e28d5
v1.0
complete
Codeforces
Codeforces_6475_C
from typing import List, Tuple def min_steps_to_destination(grid: List[List[int]], start: Tuple[int, int], destination: Tuple[int, int]) -> int: """ Determine the minimum number of steps needed for a car to get from a starting position to a destination position within the city map. Args: grid: A 2D li...
from collections import deque def min_steps_to_destination(grid, start, destination): n = len(grid) m = len(grid[0]) directions = [(1, 0), (-1, 0), (0, 1), (0, -1)] start = (start[0] - 1, start[1] - 1) destination = (destination[0] - 1, destination[1] - 1) if start == destination: ...
from solution import solve def test_min_steps_basic(): city_grid_input = "5 5\n0 0 1 0 0\n0 1 0 1 0\n0 0 0 0 0\n0 1 0 1 0\n0 0 0 0 0\n1 1 5 5" assert solve(city_grid_input) == 8 def test_min_steps_direct_path(): city_grid_input = "3 3\n0 0 0\n0 1 0\n0 0 0\n1 1 3 3" assert solve(city_grid_input) == 4 ...
[ { "docstring": null, "function_declaration": "def min_steps_to_destination(grid, start, destination):", "function_name": "min_steps_to_destination", "parameter_list": "(grid, start, destination)" }, { "docstring": null, "function_declaration": "def parse_input(input_string):", "funct...
[ 0, 1, 0, 1, 1, 1, 1, 0, 0, 1 ]
6
medium
0.6
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "from collections import deque\n\ndef min_steps(grid, start, end):\n \"\"\"\n Finds the minimum number of steps to travel from start to end in a grid.\n ...
trial_gpt4o_9
{ "original_instruction": "You are given a 2D grid representing a map of a city. Each cell in the grid can either be a building (denoted by 1) or an empty lot (denoted by 0). The roads in this city are aligned with the boundaries of the cells, meaning that you can move from one cell to an adjacent cell if this cell i...
0.680332
Codeforces_6475
C
[ "min_steps_to_destination", "parse_input", "solve" ]
3
[ [ "solve", "min_steps_to_destination" ], [ "solve", "parse_input" ] ]
2
[ "parse_input" ]
false
[]
false
pytest
true
[]
true
7421d34378b00fa37abad3f8669ef3a905081623
fd7ae495372d6e2d9af8342c4d3b714567bb79ab
v1.0
complete
Codeforces
Codeforces_6377_C
def sieve_of_eratosthenes(max_num): is_prime = [True] * (max_num + 1) is_prime[0] = is_prime[1] = False p = 2 while (p * p <= max_num): if is_prime[p] == True: for i in range(p * p, max_num + 1, p): is_prime[i] = False p += 1 return is_prime def sort_prim...
def sieve_of_eratosthenes(max_num): is_prime = [True] * (max_num + 1) is_prime[0] = is_prime[1] = False p = 2 while (p * p <= max_num): if is_prime[p] == True: for i in range(p * p, max_num + 1, p): is_prime[i] = False p += 1 return is_prime def sort_prim...
from solution import process_array def test_simple_case(): assert process_array(6, [10, 3, 7, 15, 14, 2]) == [2, 3, 7, 10, 14, 15] def test_all_primes(): assert process_array(5, [23, 19, 2, 3, 29]) == [2, 3, 19, 23, 29] def test_all_composites(): assert process_array(5, [4, 6, 8, 10, 12]) == [4, 6, 8, 10...
[ { "docstring": null, "function_declaration": "def sieve_of_eratosthenes(max_num):", "function_name": "sieve_of_eratosthenes", "parameter_list": "(max_num)" }, { "docstring": null, "function_declaration": "def sort_prime_composite(arr):", "function_name": "sort_prime_composite", "...
[ 1, 1, 0, 1, 0, 1, 0, 1, 1, 1 ]
7
easy
0.7
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_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_8
{ "original_instruction": "Create a program that sorts an array of positive integers such that prime numbers in the array appear at the beginning of the array in increasing order, followed by composite numbers in increasing order. The relative order of prime and composite numbers should be maintained from the origina...
0.647621
Codeforces_6377
C
[ "sieve_of_eratosthenes", "sort_prime_composite", "process_array" ]
3
[ [ "process_array", "sort_prime_composite" ], [ "sort_prime_composite", "sieve_of_eratosthenes" ] ]
2
[]
false
[]
false
pytest
true
[]
true
e09869b8245f29924ef7e83aadc6142cbb7655cf
bf695c2b75e3242f514437cad158df89d1b0e64c
v1.0
complete
Codeforces
Codeforces_6126_C
from typing import List, Tuple def generate_pairs(contestants: List[str]) -> List[Tuple[str, ...]]: """ Generate unique pairs of contestants for a round. """ pass def avoid_repeated_pairs(rounds: List[List[str]]) -> List[List[Tuple[str, ...]]]: """ For multiple rounds of contests, avoid repeat...
import random def generate_pairs(contestants): """ Generate unique pairs of contestants for a round. """ # Randomly shuffle the contestants' names for pairing random.shuffle(contestants) pairs = [] i = 0 while i < len(contestants) - 1: pairs.append((contestants[i], contesta...
from solution import generate_pairs, avoid_repeated_pairs def test_generate_pairs_even(): contestants = ["Alice", "Bob", "Charlie", "Dave"] pairs = generate_pairs(contestants) assert len(pairs) == 2 # Two pairs [("Alice", "Bob"), ("Charlie", "Dave")] def test_generate_pairs_odd(): contestants = ["Ali...
[ { "docstring": "Generate unique pairs of contestants for a round.", "function_declaration": "def generate_pairs(contestants):", "function_name": "generate_pairs", "parameter_list": "(contestants)" }, { "docstring": "For multiple rounds of contests, avoid repeated pairs, including reversed pa...
[ 1, 1, 0, 1, 0, 0, 0, 0 ]
3
medium
0.375
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "import random\n\ndef generate_pairs(rounds):\n \"\"\"\n Generate unique pairs of contestants for each round.\n\n :param rounds: List of tuples, where...
trial_gpt4o_1
{ "original_instruction": "You are organizing a programming competition and need to randomly pair up contestants for each round. You have a list of contestant names and need to ensure that every contestant is paired with exactly one other contestant. If the list has an odd number of contestants, one contestant will b...
0.583923
Codeforces_6126
C
[ "generate_pairs", "avoid_repeated_pairs" ]
2
[ [ "avoid_repeated_pairs", "generate_pairs" ] ]
1
[]
false
[]
false
pytest
true
[]
true
70aec000e877a265620847890c2af014818bbf80
8354d7dc8d400f12b341abe0486582694009e84d
v1.0
complete
Codeforces
Codeforces_7786_C
def treasure_hunt(input_data: str) -> Tuple[int, List[int]]: """ Determine the minimum number of keys required to open all the chests and return the key ids used. >>> treasure_hunt("5 3\n2 1 2\n2 2 3\n3 3 4 5") (2, [1, 3]) >>> treasure_hunt("3 3\n1 1\n1 2\n1 3") (3, [1, 2, 3]) >>> treasure_hunt(...
def min_keys_to_open_all_chests(n, m, keys): from itertools import combinations all_chests = set(range(1, n+1)) key_sets = [set(key[1:]) for key in keys] # Try all combinations of keys, starting from the smallest set size for r in range(1, m+1): for combo in combinations(range(m), r): ...
def test_treasure_hunt(): input_data = "5 3\n2 1 2\n2 2 3\n3 3 4 5" result = treasure_hunt(input_data) assert result == (2, [1, 3]) or result == (2, [2, 3]) input_data = "3 3\n1 1\n1 2\n1 3" result = treasure_hunt(input_data) assert result == (3, [1, 2, 3]) input_data = "4 3\n1 1\n2 2 3\n1...
[ { "docstring": null, "function_declaration": "def min_keys_to_open_all_chests(n, m, keys):", "function_name": "min_keys_to_open_all_chests", "parameter_list": "(n, m, keys)" }, { "docstring": null, "function_declaration": "def parse_input(input_lines):", "function_name": "parse_input...
[ 0, 0, 1, 1, 0, 0, 0, 1, 1, 0 ]
4
medium
0.4
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "from itertools import combinations\n\ndef min_keys_to_open_chests(n, m, keys_info):\n # List of sets indicating which chests each key can open\n keys = ...
trial_gpt4o_3
{ "original_instruction": "Kathryn is planning a treasure hunt game for her friends. The participants need to collect keys to unlock chests, and each key can open one or more specific chests. The objective is to determine the minimum number of keys required to open all the chests.\n\nThere are n chests and m keys. Ea...
0.516061
Codeforces_7786
C
[ "min_keys_to_open_all_chests", "parse_input", "treasure_hunt" ]
3
[ [ "treasure_hunt", "min_keys_to_open_all_chests" ], [ "treasure_hunt", "parse_input" ] ]
2
[ "parse_input" ]
false
[]
false
pytest
false
[]
true
3ffa9faef053b897eca53168dfd2d7351d5f5e39
0f86b8bdb1a3b43654d219b68b6d3b858ef12796
v1.0
complete
Codeforces
Codeforces_7933_C
def is_prime(num: int) -> bool: """ Determines if a number is a prime number. >>> is_prime(2) == True >>> is_prime(3) == True >>> is_prime(4) == False >>> is_prime(5) == True >>> is_prime(16) == False >>> is_prime(17) == True >>> is_prime(1) == False >>> is_prime(0) == False >>> ...
def is_prime(num): """ Determines if a number is a prime number. """ if num <= 1: return False if num <= 3: return True if num % 2 == 0 or num % 3 == 0: return False i = 5 while i * i <= num: if num % i == 0 or num % (i + 2) == 0: return False ...
from solution import is_prime, smallest_prime_sum_count def test_is_prime(): assert is_prime(2) == True assert is_prime(3) == True assert is_prime(4) == False assert is_prime(5) == True assert is_prime(16) == False assert is_prime(17) == True assert is_prime(1) == False assert is_prime(...
[ { "docstring": "Determines if a number is a prime number.", "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": "Determines the smallest number of prime numbers whose sum is equal to n.", "function_declaration": "def smal...
[ 0, 1, 0, 0, 0, 1, 0, 0, 0, 1 ]
3
hard
0.3
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(num):\n \"\"\"\n Helper function to check if a number is prime.\n \"\"\"\n if num <= 1:\n return False\n if num == 2:\n ...
trial_gpt4o_1
{ "original_instruction": "Given an integer `n` (1 ≤ n ≤ 10^6), determine the smallest number of prime numbers whose sum is equal to `n`. If `n` is itself a prime number, then the answer is 1. Otherwise, test different sums composed of two or three primes, as necessary. Summarize the minimum count under given constra...
0.753011
Codeforces_7933
C
[ "is_prime", "smallest_prime_sum_count" ]
2
[ [ "smallest_prime_sum_count", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
0fe0cebc1ece597dd68c4390da896a0ab7afc3e3
81215d4e7aa3e33d6dd4242fc2ffbb63f39b6332
v1.0
complete
Codeforces
Codeforces_7629_C
import itertools from typing import List, Tuple def calculate_distance(p1: Tuple[int, int], p2: Tuple[int, int]) -> int: """Calculate Manhattan distance between two points.""" return abs(p1[0] - p2[0]) + abs(p1[1] - p2[1]) def minimum_total_distance(N: int, M: int, package_coords: List[Tuple[int, int]]) -> in...
import itertools def calculate_distance(p1, p2): """ Calculates Manhattan distance between two points p1 and p2. """ return abs(p1[0] - p2[0]) + abs(p1[1] - p2[1]) def minimum_total_distance(N, M, package_coords): """ Computes the minimum total distance to deliver all packages and return to th...
def test_minimum_total_distance_1(): assert minimum_total_distance(4, 3, [(1, 2), (2, 2), (3, 3)]) == 12 def test_minimum_total_distance_2(): assert minimum_total_distance(3, 2, [(1, 1), (2, 2)]) == 8 def test_minimum_total_distance_3(): assert minimum_total_distance(2, 1, [(1, 1)]) == 4 def test_minimum...
[ { "docstring": "Calculates Manhattan distance between two points p1 and p2.", "function_declaration": "def calculate_distance(p1, p2):", "function_name": "calculate_distance", "parameter_list": "(p1, p2)" }, { "docstring": "Computes the minimum total distance to deliver all packages and retu...
[ 0, 0, 0, 0, 0, 0, 0, 1, 0 ]
1
hard
0.111
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "from itertools import permutations\n\ndef compute_min_distance(N, M, delivery_locations):\n def manhattan_distance(coord1, coord2):\n return abs(coo...
trial_gpt4o_8
{ "original_instruction": "Frank needs to deliver packages to different locations in his city using his delivery van. The city is represented as a grid of size \\( N \\times N \\), with Frank starting at the top-left corner of the grid (position (0,0)).\n\nFrank wants to minimize the total distance traveled while ens...
0.665819
Codeforces_7629
C
[ "calculate_distance", "minimum_total_distance" ]
2
[ [ "minimum_total_distance", "calculate_distance" ] ]
1
[]
false
[]
false
pytest
false
[]
true
d235cf7e622aa979282c4017a3fb9cd429cefd26
3f9baff324d7f2808a6d2195f42b7a4d8b18f9c6
v1.0
complete
Codeforces
Codeforces_6762_C
def allocate_tasks_to_workers(n: int, task_times: List[int], max_hours_per_worker: int) -> int: """ Determine the minimum number of workers needed to complete all tasks within one day. :param n: Number of tasks :param task_times: List of times required to complete each task :param max_hours_per_wor...
def min_workers_to_complete_tasks(task_times, max_hours_per_worker): task_times.sort(reverse=True) workers = [] for task_time in task_times: placed = False for i in range(len(workers)): if workers[i] + task_time <= max_hours_per_worker: workers[i] += task_time ...
from solution import allocate_tasks_to_workers def test_example_case(): n = 5 task_times = [4, 3, 2, 5, 6] max_hours_per_worker = 8 assert allocate_tasks_to_workers(n, task_times, max_hours_per_worker) == 3 def test_single_task_fits(): n = 1 task_times = [4] max_hours_per_worker = 8 as...
[ { "docstring": null, "function_declaration": "def min_workers_to_complete_tasks(task_times, max_hours_per_worker):", "function_name": "min_workers_to_complete_tasks", "parameter_list": "(task_times, max_hours_per_worker)" }, { "docstring": null, "function_declaration": "def allocate_task...
[ 0, 0, 1, 0, 0, 1, 0, 0, 0 ]
2
hard
0.222
{ "trial_gpt4o_0": null, "trial_gpt4o_1": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared1_results_combined.jsonl", "solution_code": "def min_workers(tasks, max_hours):\n \"\"\"\n Returns the minimum number of workers required to complete all tasks within a sin...
trial_gpt4o_6
{ "original_instruction": "### Allocate Tasks to Workers\n\nYou have a work schedule to assign tasks to workers. Each task requires a specific time to complete, and each worker has a maximum number of hours they can work per day. The goal is to determine the minimum number of workers needed to complete all tasks with...
0.643508
Codeforces_6762
C
[ "min_workers_to_complete_tasks", "allocate_tasks_to_workers" ]
2
[ [ "allocate_tasks_to_workers", "min_workers_to_complete_tasks" ] ]
1
[]
false
[]
false
pytest
true
[]
true
f3941a238435ae02e3a4e90af99544669143d723
7ba115510d2af38d0429d39d5c3aec41b74dd224
v1.0
complete
Codeforces
Codeforces_7602_C
from typing import List def process_events(n: int, events_list: List[str]) -> str: """ Group and sort events by their event type and timestamps. >>> process_events(5, [ ... "2023-01-01 12:00:00 A", ... "2023-01-01 13:00:00 B", ... "2023-01-01 11:00:00 A", ... "2023-01-02 12:00:0...
def group_and_sort_events(n, events): from collections import defaultdict import datetime event_dict = defaultdict(list) for event in events: timestamp, event_type = event.rsplit(' ', 1) event_dict[event_type].append(timestamp) result = [] for event_type, timestamps in event_d...
def test_group_and_sort_events(): n = 5 events = [ "2023-01-01 12:00:00 A", "2023-01-01 13:00:00 B", "2023-01-01 11:00:00 A", "2023-01-02 12:00:00 B", "2023-01-01 14:00:00 A" ] output = process_events(n, events) expected_output = ( 'A\n' '...
[ { "docstring": null, "function_declaration": "def group_and_sort_events(n, events):", "function_name": "group_and_sort_events", "parameter_list": "(n, events)" }, { "docstring": null, "function_declaration": "def format_output(events):", "function_name": "format_output", "paramet...
[ 1, 0, 0, 1, 0, 1, 1, 1, 0, 0 ]
5
medium
0.5
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "from collections import defaultdict\nfrom datetime import datetime\n\ndef group_and_sort_events(events):\n \"\"\"\n Groups events by their type and sort...
trial_gpt4o_7
{ "original_instruction": "You are given a series of events represented by tuples `(timestamp, event_type)`, where `timestamp` is in the format \"YYYY-MM-DD HH:MM:SS\", and `event_type` is a string representing the type of event. Your task is to group the events by their `event_type` and then sort each group of event...
0.567644
Codeforces_7602
C
[ "group_and_sort_events", "format_output", "process_events" ]
3
[ [ "process_events", "format_output" ], [ "process_events", "group_and_sort_events" ] ]
2
[ "format_output" ]
false
[]
false
pytest
false
[]
true
ab7e35cd7d9eea254eda07763b6a651e759627e4
ce9ad581af68ab0e7ba7a293530db94fa0d2dc79
v1.0
complete
Codeforces
Codeforces_8287_C
def solve(n, m, grid): """ Determine if it's possible to place a new building in one of the vacant cells such that it does not become adjacent horizontally or vertically to any pre-existing building. Args: n (int): number of rows in the grid. m (int): number of columns in the grid. grid (List[s...
def find_building_spot(grid): n = len(grid) m = len(grid[0]) def is_safe(x, y): directions = [(-1, 0), (1, 0), (0, -1), (0, 1)] for dx, dy in directions: nx, ny = x + dx, y + dy if 0 <= nx < n and 0 <= ny < m and grid[nx][ny] == 'B': return False ...
from solution import solve def test_case1(): n = 3 m = 3 grid = [ "LLL", "LBL", "LLL" ] assert solve(n, m, grid) == "1 1" def test_case2(): n = 2 m = 2 grid = [ "BL", "LB" ] assert solve(n, m, grid) == "NO" def test_case3(): n = 5 ...
[ { "docstring": null, "function_declaration": "def find_building_spot(grid):", "function_name": "find_building_spot", "parameter_list": "(grid)" }, { "docstring": null, "function_declaration": "def solve(n, m, grid):", "function_name": "solve", "parameter_list": "(n, m, grid)" }...
[ 0, 1, 1, 1, 0, 1, 0, 1, 1, 0 ]
6
medium
0.6
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def find_vacant_position(n, m, grid):\n \"\"\"\n Finds a vacant position in the grid where we can place a building such that\n it is not adjacent hor...
trial_gpt4o_8
{ "original_instruction": "You are given a grid-based city plot with n rows and m columns. Each cell in the grid can either contain a building denoted by 'B' or a vacant land denoted by 'L'. No two buildings are adjacent horizontally or vertically but only diagonally. \n\nWe need to construct a new building in one of...
0.681605
Codeforces_8287
C
[ "find_building_spot", "solve" ]
2
[ [ "solve", "find_building_spot" ] ]
1
[]
false
[]
false
pytest
true
[]
true
d59be879b94b883ae7c55d9b0e01fe6d4b477606
4f395202db4c4647210b2a552791c818b4d36515
v1.0
complete
Codeforces
Codeforces_7622_C
from typing import List MOD = 1_000_000_007 def update(index, value, arr, product): n = len(arr) old_value = arr[index] arr[index] = value # Efficiently update the product product = (product * pow(old_value, MOD-2, MOD) % MOD) * value % MOD return product def range_product(l, r, arr): ...
MOD = 1_000_000_007 def update(index, value, arr, product): n = len(arr) old_value = arr[index] arr[index] = value # Efficiently update the product product = (product * pow(old_value, MOD-2, MOD) % MOD) * value % MOD return product def range_product(l, r, arr): result = 1 for i in...
import pytest from solution import process_queries def test_process_queries(): n = 5 q = 3 arr = [2, 3, 4, 5, 6] queries = ["2 1 3", "1 2 10", "2 1 3"] expected_output = [24, 80] assert process_queries(n, q, arr, queries) == expected_output def test_process_queries_single_element(): n = 1 ...
[ { "docstring": null, "function_declaration": "def update(index, value, arr, product):", "function_name": "update", "parameter_list": "(index, value, arr, product)" }, { "docstring": null, "function_declaration": "def range_product(l, r, arr):", "function_name": "range_product", "...
[ 0, 0, 1, 0, 0, 1, 0, 0, 0, 0 ]
2
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "MOD = 1000000007\n\ndef build_segment_tree(arr, seg_tree, start, end, node):\n if start == end:\n seg_tree[node] = arr[start]\n else:\n mi...
trial_gpt4o_5
{ "original_instruction": "You are given an array of n integers. You have to handle q queries of the following types:\n\n1. Update the value of a specified element in the array.\n2. Calculate the product of elements in a specified range of the array.\n\nFor the update query, you will be given an index and a new value...
0.536647
Codeforces_7622
C
[ "update", "range_product", "process_queries" ]
3
[ [ "process_queries", "range_product" ], [ "process_queries", "update" ] ]
2
[ "process_queries" ]
false
[]
false
pytest
true
[]
true
d76b42856c07543ea2262c962f0c6251fa702f86
1cc82f632b58b19a8e3cf3de4ff308b749e0067f
v1.0
complete
Codeforces
Codeforces_7915_C
from itertools import permutations from typing import List def get_permutations(nums: List[int]) -> List[tuple]: """ Returns all possible permutations of the list nums. >>> get_permutations([1, 2]) == [(1, 2), (2, 1)] >>> get_permutations([1, 2, 3]) == [ (1, 2, 3), (1, 3, 2), (2, 1, 3), ...
from itertools import permutations def get_permutations(nums): """ Returns all possible permutations of the list nums. """ return list(permutations(nums)) def format_permutations(perms): """ Formats the permutations into a string representation, each permutation on a new line. """ ...
from solution import get_permutations, format_permutations, process_input def test_get_permutations(): assert get_permutations([1, 2]) == [(1, 2), (2, 1)] assert get_permutations([1, 2, 3]) == [ (1, 2, 3), (1, 3, 2), (2, 1, 3), (2, 3, 1), (3, 1, 2), (3, 2, 1) ...
[ { "docstring": "Returns all possible permutations of the list nums.", "function_declaration": "def get_permutations(nums):", "function_name": "get_permutations", "parameter_list": "(nums)" }, { "docstring": "Formats the permutations into a string representation, each permutation on a new lin...
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 0 ]
9
easy
0.9
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "from itertools import permutations\n\ndef generate_permutations(nums):\n \"\"\"\n Generate all possible permutations of the given list of distinct integ...
trial_gpt4o_7
{ "original_instruction": "Given an integer array `nums` of length `n` containing distinct integers, your task is to return all possible permutations of the array in any order. A permutation of the array is a rearrangement of its elements.\n\nYour function should handle arrays with lengths up to 8. You may assume tha...
0.686861
Codeforces_7915
C
[ "get_permutations", "format_permutations", "process_input" ]
3
[ [ "process_input", "format_permutations" ], [ "process_input", "get_permutations" ] ]
2
[ "process_input" ]
false
[]
false
pytest
true
[]
true
3a50772d408f2e4af95f74a4da1e2094098f267a
e1f422ff59a51a5d28a7a897d3dd43980e6bc6e7
v1.0
complete
Codeforces
Codeforces_7632_C
from typing import List, Tuple def subway_distances(n: int, edges: List[Tuple[int, int]], queries: List[Tuple[int, int]]) -> List[int]: """ Calculate the distance between the given pairs of stations in a subway system. Args: n (int): the number of stations edges (List[Tuple[int, int]]): the edges repre...
from collections import deque def build_tree(n, edges): tree = [[] for _ in range(n + 1)] for u, v in edges: tree[u].append(v) tree[v].append(u) return tree def bfs(tree, start): n = len(tree) dist = [-1] * n dist[start] = 0 queue = deque([start]) while queue: u...
from solution import subway_distances def test_example_case(): n = 6 q = 3 edges = [(1, 2), (2, 3), (2, 4), (4, 5), (4, 6)] queries = [(1, 4), (5, 3), (2, 6)] assert subway_distances(n, edges, queries) == [2, 3, 2] def test_single_node(): n = 1 q = 1 edges = [] queries = [(1, 1)] ...
[ { "docstring": null, "function_declaration": "def build_tree(n, edges):", "function_name": "build_tree", "parameter_list": "(n, edges)" }, { "docstring": null, "function_declaration": "def bfs(tree, start):", "function_name": "bfs", "parameter_list": "(tree, start)" }, { ...
[ 0, 1, 0, 0, 0, 0, 0, 0, 1 ]
2
hard
0.222
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "from collections import defaultdict, deque\n\ndef find_distances(n, q, edges, queries):\n tree = defaultdict(list)\n \n for u, v in edges:\n t...
trial_gpt4o_9
{ "original_instruction": "In a certain country, there is a new subway system. The subway map can be thought of as a tree with $$$n$$$ stations, where each station is represented as a node, and each corridor between stations (bidirectional) is represented as an edge. Stations are numbered from $$$1$$$ to $$$n$$$.\n\n...
0.646792
Codeforces_7632
C
[ "build_tree", "bfs", "subway_distances" ]
3
[ [ "subway_distances", "bfs" ], [ "subway_distances", "build_tree" ] ]
2
[]
false
[]
false
pytest
true
[]
true
5604088cb181e951573593d6cdf25917aa5a10f8
29c7f391c5defd6a3e1f31d511af7617d563d0d1
v1.0
complete
Codeforces
Codeforces_6713_C
def min_distance(s1: str, s2: str) -> int: """ Calculate the minimum number of operations required to transform s1 into s2 using insertion, deletion, and replacement operations. """ pass def transform_strings_transformations(t: int, test_cases: List[Tuple[int, int, str, str]]) -> List[int]: """...
def min_distance(s1, s2): """ Calculate the minimum number of operations required to transform s1 into s2 using insertion, deletion, and replacement operations. """ n = len(s1) m = len(s2) # Initialize a matrix to store the minimum edit distances. dp = [[0] * (m + 1) for _ in range(...
from solution import run_transformations def test_example_case_1(): test_input = [2, 5, 3, 'abcde', 'bcd', 3, 4, 'abc', 'adc'] expected_output = [2, 1] assert run_transformations(test_input) == expected_output def test_example_case_2(): test_input = [1, 4, 5, 'abcd', 'abcde'] expected_output = [1]...
[ { "docstring": "Calculate the minimum number of operations required to transform s1 into s2 using\ninsertion, deletion, and replacement operations.", "function_declaration": "def min_distance(s1, s2):", "function_name": "min_distance", "parameter_list": "(s1, s2)" }, { "docstring": null, ...
[ 1, 1, 1, 1, 1, 1, 0, 0, 0 ]
6
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def min_operations_string(s1, s2):\n \"\"\"\n Returns the minimum number of operations required to transform s1 into s2.\n Operations allowed are ins...
trial_gpt4o_6
{ "original_instruction": "Alice loves playing with strings. She has two strings, s1 and s2, of lengths n and m respectively. She wants to find out the minimum number of operations required to transform s1 into s2. The operations allowed are:\n\n1. Insert a character at any position in s1.\n2. Delete a character from...
0.640847
Codeforces_6713
C
[ "min_distance", "transform_strings_transformations", "run_transformations" ]
3
[ [ "run_transformations", "transform_strings_transformations" ], [ "transform_strings_transformations", "min_distance" ] ]
2
[]
false
[]
false
pytest
true
[]
true
cb49c02b243af21ab86569760741afbc9d951a82
25326c02490962ac644d3051a2924135e9ade837
v1.0
complete
Codeforces
Codeforces_8241_C
def min_spanning_tree(n, edges): """ Finds the total communication time of the minimum spanning tree. If it's impossible to connect all computers, returns "IMPOSSIBLE". Args: n (int): The number of computers. edges (List[Tuple[int, int, int]]): The list of edges, where each edge is described ...
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): rootX = find(parent, x) rootY = find(parent, y) if rootX != rootY: if rank[rootX] > rank[rootY]: parent[rootY] = rootX el...
from solution import min_spanning_tree def test_sample_input_1(): assert min_spanning_tree(4, [ (1, 2, 3), (1, 3, 2), (1, 4, 4), (2, 3, 1), (3, 4, 5) ]) == 7 def test_sample_input_2(): assert min_spanning_tree(3, [ (1, 2, 2) ]) == "IMPOSSIBLE" def test_single_node_no_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, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def find_minimum_spanning_tree(n, edges):\n \"\"\"\n Finds the minimum spanning tree of a graph using Kruskal's algorithm.\n \n :param n: Number o...
trial_gpt4o_6
{ "original_instruction": "You are an engineer working on a network of computers that need to communicate with each other. The network is represented as a graph where each computer is a node and the communication paths between them are edges with weights representing the time it takes to send a message between those ...
0.716627
Codeforces_8241
C
[ "find", "union", "min_spanning_tree" ]
3
[ [ "min_spanning_tree", "find" ], [ "min_spanning_tree", "union" ], [ "union", "find" ] ]
3
[]
false
[]
false
pytest
true
[]
true
b8f81bea2195caa0801dd9c04af9298592fa0418
3e80995947c929548de882cf829c3867f0a4cd9d
v1.0
complete
Codeforces
Codeforces_6967_C
def ant_travel_min_effort(matrix: List[List[int]]) -> int: """ Find the minimum effort required for an ant to travel from the top-left cell (0,0) to the bottom-right cell (n-1,m-1) in a matrix. Args: matrix (List[List[int]]): A 2D list of integers representing the heights of the cells. ...
import heapq def minimum_effort_path(heights): def can_travel(k): rows, cols = len(heights), len(heights[0]) visited = [[False for _ in range(cols)] for _ in range(rows)] pq = [(0, 0, 0)] # (effort, row, col) directions = [(1, 0), (-1, 0), (0, 1), (0, -1)] while pq...
from solution import ant_travel_min_effort def test_example_case(): matrix = [ [1, 2, 2], [3, 8, 2], [5, 3, 5] ] assert ant_travel_min_effort(matrix) == 2 def test_single_row(): matrix = [ [1, 2, 3, 4] ] assert ant_travel_min_effort(matrix) == 1 def test_single...
[ { "docstring": null, "function_declaration": "def minimum_effort_path(heights):", "function_name": "minimum_effort_path", "parameter_list": "(heights)" }, { "docstring": null, "function_declaration": "def ant_travel_min_effort(matrix):", "function_name": "ant_travel_min_effort", ...
[ 0, 0, 0, 0, 0, 1, 0, 0, 0, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "from heapq import heappush, heappop\n\ndef minimumEffortPath(heights):\n def canCross(threshold):\n n, m = len(heights), len(heights[0])\n vi...
trial_gpt4o_5
{ "original_instruction": "You are given a matrix of size n x m where each cell contains an integer representing the height of that cell's terrain.\n\nYour task is to find the minimum effort required for an ant to travel from the top-left cell (0,0) to the bottom-right cell (n-1,m-1).\n\nThe ant can travel to a neigh...
0.626735
Codeforces_6967
C
[ "minimum_effort_path", "ant_travel_min_effort" ]
2
[ [ "ant_travel_min_effort", "minimum_effort_path" ] ]
1
[]
false
[]
false
pytest
true
[]
true
0526d7273b4e0acc2844f0e7fd5be9be7d31ff10
313d9e6bbf00223b4c5c357bdfe91de18bb96aee
v1.0
complete
Codeforces
Codeforces_7208_C
def solve(m: int, n: int, grid: List[str]) -> str: """ Determine if it's possible to reach the bottom-right corner starting from top-left corner in a grid where each move must be to a cell of the same color. >>> solve(2, 2, ["RR", "RR"]) == "YES" >>> solve(3, 3, ["RGB", "GRG", "BBG"]) == "NO" >>> solve(...
def can_reach_bottom_right(m, n, grid): def dfs(x, y): if x == m - 1 and y == n - 1: return True visited[x][y] = True directions = [(0, 1), (1, 0)] for dx, dy in directions: nx, ny = x + dx, y + dy if 0 <= nx < m and 0 <= ny < n and grid[nx][ny] ==...
from solution import solve def test_grid_with_possible_path(): assert solve(2, 2, ["RR", "RR"]) == "YES" def test_grid_without_possible_path(): assert solve(3, 3, ["RGB", "GRG", "BBG"]) == "NO" def test_single_cell(): assert solve(1, 1, ["R"]) == "YES" assert solve(1, 1, ["G"]) == "YES" assert so...
[ { "docstring": null, "function_declaration": "def can_reach_bottom_right(m, n, grid):", "function_name": "can_reach_bottom_right", "parameter_list": "(m, n, grid)" }, { "docstring": null, "function_declaration": "def solve(m, n, grid):", "function_name": "solve", "parameter_list"...
[ 1, 0, 0, 0, 0, 0, 0, 1, 1, 1 ]
4
medium
0.4
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def can_reach_bottom_right(m, n, grid):\n def dfs(x, y, color):\n if x == m - 1 and y == n - 1:\n return True\n visited.add((x, y)...
trial_gpt4o_9
{ "original_instruction": "You are given a rectangular grid consisting of cells with a specific color: red, green, or blue. The grid is represented as an array of strings, where each string corresponds to a row of the grid, and each character in the string represents the color of a cell. The possible characters are '...
0.685917
Codeforces_7208
C
[ "can_reach_bottom_right", "solve" ]
2
[ [ "solve", "can_reach_bottom_right" ] ]
1
[]
false
[]
false
pytest
true
[]
true
dbd1a5ac0732015ff2e05eed5dcd850984ab93de
7540e1353fcd5889c8893a2d1440d2b34e299be2
v1.0
complete
Codeforces
Codeforces_7046_C
class TreeNode: def __init__(self, value=0, left=None, right=None): self.value = value self.left = left self.right = right def countNodesAtDistanceK(root: TreeNode, target: int, k: int) -> int: """ Function to count the number of nodes in a binary tree that are exactly k distance a...
from collections import deque class TreeNode: def __init__(self, value=0, left=None, right=None): self.value = value self.left = left self.right = right def countNodesAtDistanceK(root, target, k): if not root: return 0 # Find the target node target_node = findTargetNod...
def test_countNodesAtDistanceK_example(): root = TreeNode(3) root.left = TreeNode(5) root.right = TreeNode(1) root.left.left = TreeNode(6) root.left.right = TreeNode(2) root.right.left = TreeNode(0) root.right.right = TreeNode(8) root.left.right.left = TreeNode(7) root.left.right.rig...
[]
[ 1, 0, 1, 0, 1, 0, 1, 1, 0, 1 ]
6
medium
0.6
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "from collections import deque\n\nclass TreeNode:\n def __init__(self, value=0, left=None, right=None):\n self.value = value\n self.left = lef...
trial_gpt4o_0
{ "original_instruction": "Tom is working on a binary tree and needs to determine certain properties about it. Each node in the tree contains a unique integer value. Here is the problem:\n\nGiven the root of a binary tree, a target value, and an integer k, find the number of nodes that are at an exact distance of k f...
0.632852
Codeforces_7046
C
[ "countNodesAtDistanceK", "findTargetNode", "mapParents", "bfs_from_target" ]
4
[ [ "countNodesAtDistanceK", "bfs_from_target" ], [ "countNodesAtDistanceK", "findTargetNode" ], [ "countNodesAtDistanceK", "mapParents" ] ]
3
[]
false
[ "TreeNode" ]
true
pytest
false
[]
true
3cc22445623a0c5b79ffb7472217050ef90b578f
e8d3305780b265d32e8884091b2a94c541dbb073
v1.0
complete
Codeforces
Codeforces_8394_C
from itertools import combinations from typing import List, Tuple def is_circumcenter_collinear(p1: Tuple[int, int], p2: Tuple[int, int], p3: Tuple[int, int]) -> bool: """ Check if the circumcenter for three points is collinear """ x1, y1 = p1 x2, y2 = p2 x3, y3 = p3 return ((x2 - x1)*(y3 - y1) - (...
from itertools import combinations def is_circumcenter_collinear(p1, p2, p3): x1, y1 = p1 x2, y2 = p2 x3, y3 = p3 return ((x2 - x1)*(y3 - y1) - (y2 - y1)*(x3 - x1)) == 0 def circle_exists(points): for comb in combinations(points, 3): if not is_circumcenter_collinear(*comb): ret...
def test_circle_exists(): assert check_circle(["6", "2 3", "4 5", "1 1", "3 4", "7 8", "8 10"]) == "YES" assert check_circle(["4", "1 1", "2 2", "3 3", "4 4"]) == "NO" assert check_circle(["3", "1 1", "0 0", "-1 -1"]) == "NO" assert check_circle(["5", "0 0", "1 0", "0 1", "1 1", "0 2"]) == "YES" ass...
[ { "docstring": null, "function_declaration": "def is_circumcenter_collinear(p1, p2, p3):", "function_name": "is_circumcenter_collinear", "parameter_list": "(p1, p2, p3)" }, { "docstring": null, "function_declaration": "def circle_exists(points):", "function_name": "circle_exists", ...
[ 0, 1, 1, 1, 1, 0, 1, 1, 1, 1 ]
8
easy
0.8
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "from typing import List, Tuple\n\ndef exists_circle_encircling_three_points(points: List[Tuple[int, int]]) -> str:\n from math import isclose\n \n de...
trial_gpt4o_2
{ "original_instruction": "You are given a set of points in a 2D plane and are tasked with determining if there exists a circle that encircles at least three of these points. A circle is said to encircle a point if the point lies on the circumference of the circle. \n\nWrite a function to find out whether there exist...
0.620198
Codeforces_8394
C
[ "is_circumcenter_collinear", "circle_exists", "check_circle" ]
3
[ [ "check_circle", "circle_exists" ], [ "circle_exists", "is_circumcenter_collinear" ] ]
2
[]
false
[]
false
pytest
false
[]
true
2429c634ad17c1dd04975e1f5a8db63f966e11ad
07b876e354ae5d5c8efc84cfbd52b72af87f6ebe
v1.0
complete
Codeforces
Codeforces_8428_C
def minimum_spanning_tree(n: int, m: int, edge_list: List[List[int]]) -> Union[int, str]: """ Find the total weight of the Minimum Spanning Tree (MST) of an undirected graph, or return "IMPOSSIBLE" if the graph is disconnected. Args: n (int): Number of nodes in the graph. m (int): Number of edges in the...
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] ...
import pytest from solution import minimum_spanning_tree def test_example_case(): n = 4 m = 5 edges = [ [1, 2, 3], [1, 3, 1], [2, 3, 3], [2, 4, 6], [3, 4, 5] ] assert minimum_spanning_tree(n, m, edges) == 9 def test_disconnected_graph(): n = 4 m = 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, 0, 0, 0, 1, 0, 0, 0, 0, 1 ]
3
hard
0.3
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_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_0
{ "original_instruction": "You are given an undirected graph with n nodes and m edges. Each edge has a positive integer weight. The task is to find a minimum spanning tree (MST) of the graph, which is a subset of the graph's edges that connects all the nodes together without any cycles and with the minimum possible t...
0.81291
Codeforces_8428
C
[ "find", "union", "kruskal_mst", "minimum_spanning_tree" ]
4
[ [ "kruskal_mst", "find" ], [ "kruskal_mst", "union" ], [ "minimum_spanning_tree", "kruskal_mst" ], [ "union", "find" ] ]
4
[]
false
[]
false
pytest
true
[]
true
a046ea457515b91c2319e823812ea8cff90f3aa2
67836b9860d0ffaf60da0be9022f0d0c53d0076c
v1.0
complete
Codeforces
Codeforces_7488_C
def int_to_base(n, b): """ Converts an integer n to a given base b and returns the string representation. """ pass def base_to_int(s, b): """ Converts a string s in base b to an integer. """ pass def is_palindrome(s): """ Checks if a string s is a palindrome. """ pass ...
def int_to_base(n, b): """ Converts an integer n to a given base b and returns the string representation. """ if n == 0: return '0' digits = [] while n: digits.append(int(n % b)) n //= b return ''.join('0123456789abcdefghijklmnopqrstuvwxyz'[d] for d in digits[::-1]) ...
from solution import next_palindrome def test_next_palindrome_base_10(): assert next_palindrome('123', 10) == '131' assert next_palindrome('99', 10) == '101' assert next_palindrome('101', 10) == '111' def test_next_palindrome_base_16(): assert next_palindrome('1f', 16) == '22' assert next_palindro...
[ { "docstring": "Converts an integer n to a given base b and returns the string representation.", "function_declaration": "def int_to_base(n, b):", "function_name": "int_to_base", "parameter_list": "(n, b)" }, { "docstring": "Converts a string s in base b to an integer.", "function_declar...
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_palindrome(s):\n return s == s[::-1]\n\ndef increment_in_base(s, base):\n num = int(s, base)\n num += 1\n result = ''\n while num > 0:\n...
trial_gpt4o_9
{ "original_instruction": "Alice is fascinated by palindromes and wants to find them in different number systems. In particular, she is interested in finding the smallest palindrome greater than a given number n in a number system with base b.\n\nA number is considered a palindrome if it reads the same backward as fo...
0.725047
Codeforces_7488
C
[ "int_to_base", "base_to_int", "is_palindrome", "next_palindrome" ]
4
[ [ "next_palindrome", "base_to_int" ], [ "next_palindrome", "int_to_base" ], [ "next_palindrome", "is_palindrome" ] ]
3
[]
false
[]
false
pytest
true
[]
true
203d5ff6e7399baf34e4620f00a4b614b4b03f61
4d74815031c9dc081c447c5bf5849c2c6bd76a12
v1.0
complete
Codeforces
Codeforces_6871_C
import heapq from typing import List def merge_k_sorted_lists(lists: List[List[int]]) -> List[int]: """ Merges k sorted lists into one sorted list. Parameters: lists: List of lists, where each list is sorted. Returns: A single sorted list containing all elements of the k l...
import heapq def merge_k_sorted_lists(lists): """ Merges k sorted lists into one sorted list. Parameters: lists: List of lists, where each list is sorted. Returns: A single sorted list containing all elements of the k lists. """ min_heap = [] for l in lists: ...
from solution import merge_k_sorted_lists, parse_input, solve def test_merge_k_sorted_lists(): lists = [ [-10, -5, 0, 5], [2, 4, 8], [-7, -3, 1, 9, 10] ] assert merge_k_sorted_lists(lists) == [-10, -7, -5, -3, 0, 1, 2, 4, 5, 8, 9, 10] def test_parse_input(): input_data = "3\n4 ...
[ { "docstring": "Merges k sorted lists into one sorted list.\n\nParameters:\n lists: List of lists, where each list is sorted.\n \nReturns:\n A single sorted list containing all elements of the k lists.", "function_declaration": "def merge_k_sorted_lists(lists):", "function_name": "merge_k_sorte...
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
10
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "import heapq\n\ndef merge_k_sorted_lists(input_lists):\n \"\"\"\n Merge k sorted lists into one sorted list.\n \"\"\"\n min_heap = []\n for lst...
trial_gpt4o_9
{ "original_instruction": "Given an array of `k` lists of sorted integers, merge them into one sorted list. The input begins with an integer `k` ($$$1 \\leq k \\leq 10^3$$$), the number of lists. Each of the next `k` lines contains the elements of a list, prefixed by an integer `n_i` ($$$1 \\leq n_i \\leq 10^3$$$), t...
0.609784
Codeforces_6871
C
[ "merge_k_sorted_lists", "parse_input", "solve" ]
3
[ [ "solve", "merge_k_sorted_lists" ], [ "solve", "parse_input" ] ]
2
[ "parse_input" ]
false
[]
false
pytest
true
[]
true
4f01e2151066981d38889e0abab399b97adf219b
f17ee4f399b705b47296b255123e2d508959115b
v1.0
complete
Codeforces
Codeforces_8393_C
class TreeNode: def __init__(self, val=0, left=None, right=None): self.val = val self.left = left self.right = right def build_tree(nodes): if not nodes: return None val_to_node = {} for val, left, right in nodes: if val not in val_to_node: val_to_nod...
class TreeNode: def __init__(self, val=0, left=None, right=None): self.val = val self.left = left self.right = right def build_tree(nodes): if not nodes: return None val_to_node = {} for val, left, right in nodes: if val not in val_to_node: val_t...
def test_find_max_depth(): assert find_max_depth(3, [(1, 2, 3), (2, None, None), (3, None, None)]) == 2 assert find_max_depth(1, [(1, None, None)]) == 1 assert find_max_depth(5, [(1, 2, 3), (2, 4, None), (3, None, 5), (4, None, None), (5, None, None)]) == 3 def test_find_max_depth_deep_tree(): assert f...
[]
[ 1, 1, 1, 1, 1, 1, 1, 0, 1, 1 ]
9
easy
0.9
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "class TreeNode:\n def __init__(self, val=0, left=None, right=None):\n self.val = val\n self.left = left\n self.right = right\n\ndef bu...
trial_gpt4o_9
{ "original_instruction": "Anastasia is practicing her math skills and recently learned about binary trees. She finds them fascinating and wants to explore more. A binary tree is a tree where each node has at most two children, referred to as the left child and the right child.\n\nAnastasia is particularly interested...
0.55512
Codeforces_8393
C
[ "build_tree", "max_depth", "find_max_depth" ]
3
[ [ "find_max_depth", "build_tree" ], [ "find_max_depth", "max_depth" ] ]
2
[]
false
[ "TreeNode" ]
true
pytest
false
[]
true
c901d49173a345ab952d70c3c5e41f2d41ff7f26
cf030b2f73116c72a632ac42d03513dd1d6dc1a3
v1.0
complete
Codeforces
Codeforces_9043_C
from typing import List def can_be_permuted_to_palindrome(s: str) -> bool: """ Determines if the string s can be permuted to form a palindrome. >>> can_be_permuted_to_palindrome("civic") True >>> can_be_permuted_to_palindrome("hello") False """ def game_result(t: int, strings: List[str]) -> Li...
def can_be_permuted_to_palindrome(s): """ Determines if the string s can be permuted to form a palindrome. """ from collections import Counter count = Counter(s) odd_count = sum(1 for c in count.values() if c % 2 != 0) return odd_count <= 1 def game_result(t, strings): """ For each ...
from solution import can_be_permuted_to_palindrome, game_result def test_can_be_permuted_to_palindrome(): # Test cases where Bob wins assert can_be_permuted_to_palindrome("civic") == True assert can_be_permuted_to_palindrome("ivicc") == True assert can_be_permuted_to_palindrome("a") == True assert ...
[ { "docstring": "Determines if the string s can be permuted to form a palindrome.", "function_declaration": "def can_be_permuted_to_palindrome(s):", "function_name": "can_be_permuted_to_palindrome", "parameter_list": "(s)" }, { "docstring": "For each string in strings, determines if Bob wins ...
[ 1, 0, 1, 1, 1, 1, 0, 1, 0, 1 ]
7
easy
0.7
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_palindrome_permutation(s):\n \"\"\"\n Determines if a given string can be permuted to form a palindrome.\n \"\"\"\n from collections import...
trial_gpt4o_9
{ "original_instruction": "**Palindrome Permutation Check**\n\nAlice and Bob are playing a game with strings. They found a string consisting of lowercase English letters and decided to check if the string can be permuted to form a palindrome. In this game, Bob wins if the string can be permuted to form a palindrome, ...
0.648113
Codeforces_9043
C
[ "can_be_permuted_to_palindrome", "game_result" ]
2
[ [ "game_result", "can_be_permuted_to_palindrome" ] ]
1
[]
false
[]
false
pytest
true
[]
true
640b0347da03ad782f19a6ece7b6fabc9b0a90fe
36b51a7f54a38f85197e672070be5a02fdb2fcd2
v1.0
complete
Codeforces
Codeforces_8681_C
from typing import List def maximum_sum_of_subrectangle(input_str: str) -> int: """ Given input string representing a rectangular matrix, returns the maximum sum of any subrectangle in the given matrix. The first line of the input contains two integers `n` and `m` (1 ≤ n, m ≤ 100) - the dimensions of the ...
def max_subrectangle_sum(matrix): """ Returns the maximum sum of any subrectangle in the given matrix. """ n = len(matrix) m = len(matrix[0]) max_sum = float('-inf') for left in range(m): temp = [0] * n for right in range(left, m): for i in range(n): ...
def test_max_subrectangle_sum(): input_data = "3 3\n1 2 3\n4 5 6\n7 8 9" assert maximum_sum_of_subrectangle(input_data) == 45 input_data = "2 2\n-1 -2\n-3 -4" assert maximum_sum_of_subrectangle(input_data) == -1 input_data = "3 3\n1 2 -1\n-3 -4 2\n1 2 3" assert maximum_sum_of_subrectangle(inpu...
[ { "docstring": "Returns the maximum sum of any subrectangle in the given matrix.", "function_declaration": "def max_subrectangle_sum(matrix):", "function_name": "max_subrectangle_sum", "parameter_list": "(matrix)" }, { "docstring": null, "function_declaration": "def parse_input(input_str...
[ 0, 0, 0, 0, 0, 1, 0, 0, 0, 1 ]
2
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def max_subrectangle_sum(matrix):\n \"\"\"\n Given a matrix, returns the maximum sum of any subrectangle.\n\n Input:\n matrix: List of List of...
trial_gpt4o_9
{ "original_instruction": "You are given a rectangular matrix of dimensions $$$n \\times m$$$. Each cell in the matrix contains a non-negative integer. Your task is to find the maximum sum of a subrectangle. A subrectangle is defined as any contiguous submatrix within the given matrix.\n\nThe first line of the input ...
0.618436
Codeforces_8681
C
[ "max_subrectangle_sum", "parse_input", "maximum_sum_of_subrectangle" ]
3
[ [ "maximum_sum_of_subrectangle", "max_subrectangle_sum" ], [ "maximum_sum_of_subrectangle", "parse_input" ] ]
2
[ "parse_input" ]
false
[]
false
pytest
false
[]
true
871a35bce95d1e67fdb8228f1d1a71f75c36cac4
95f417a892911ad168def8605e6eb535d734210f
v1.0
complete
Codeforces
Codeforces_8749_C
import math from typing import List def is_prime(n: int) -> bool: """ Check if a given number is prime """ if n <= 1: return False if n <= 3: return True if n % 2 == 0 or n % 3 == 0: return False i = 5 while (i * i) <= n: if n % i == 0 or n % (i + 2) == 0: ...
import math def is_prime(n): """ Check if a given number is prime """ if n <= 1: return False if n <= 3: return True if n % 2 == 0 or n % 3 == 0: return False i = 5 while (i * i) <= n: if n % i == 0 or n % (i + 2) == 0: return False i += 6 ...
from solution import longest_prime_sum_subsegment def test_longest_prime_sum_subsegment_example(): assert longest_prime_sum_subsegment(5, [1, 2, 3, 4, 5]) == 2 def test_longest_prime_sum_subsegment_no_prime_sum(): assert longest_prime_sum_subsegment(3, [4, 6, 8]) == 0 def test_longest_prime_sum_subsegment_si...
[ { "docstring": "Check if a given number is prime ", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Find the length of the longest subsegment with a prime sum ", "function_declaration": "def longest_prime_sum_subsegment(...
[ 0, 0, 0, 0, 0, 0, 1, 0, 0, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "from sympy import isprime\n\ndef longest_prime_sum_subsegment(arr):\n n = len(arr)\n max_len = 0\n \n for i in range(n):\n current_sum = 0\...
trial_gpt4o_6
{ "original_instruction": "The Quick Rabbit loves sequences.\n\nHe has a sequence of positive integers and wants to find the longest subsegment of the sequence where the sum of the subsegment is a prime number.\n\nGiven an array of n integers, help the Quick Rabbit find the length of the longest subsegment with a sum...
0.656388
Codeforces_8749
C
[ "is_prime", "longest_prime_sum_subsegment" ]
2
[ [ "longest_prime_sum_subsegment", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
07e3783fa7caa28e24d15861267bfa964d08da00
78f68c61e3212276845093361604c758b4bd9d3b
v1.0
complete
Codeforces
Codeforces_8753_C
from typing import List def maxWaterParkArea(grid: List[List[str]]) -> int: """ Find the maximum area of water that can be transformed into a park. A park can only be built on water cells ('W'), and the park must be a rectangular region. >>> maxWaterParkArea([ ... ["O", "W", "W", "O", "T"], ...
def maxWaterParkArea(grid): # If the grid is empty, return 0 if not grid or not grid[0]: return 0 # Get the dimensions of the grid m, n = len(grid), len(grid[0]) # Initialize the dp array to store the height of consecutive 'W' from top to current row heights = [0] * n max_area = 0 ...
def test_maxWaterParkArea(): grid = [ ["O", "W", "W", "O", "T"], ["W", "W", "W", "O", "T"], ["T", "O", "O", "W", "W"], ["O", "W", "W", "O", "T"] ] assert maxWaterParkArea(grid) == 4 def test_grid_with_single_row(): grid = [ ["O", "W", "W", "O", "T"] ] ass...
[ { "docstring": null, "function_declaration": "def maxWaterParkArea(grid):", "function_name": "maxWaterParkArea", "parameter_list": "(grid)" }, { "docstring": null, "function_declaration": "def max_histogram_area(heights):", "function_name": "max_histogram_area", "parameter_list":...
[ 1, 1, 0, 0, 0, 1, 1, 0, 1 ]
5
medium
0.556
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def maxWaterParkArea(grid):\n # If the grid is empty, return 0\n if not grid or not grid[0]:\n return 0\n\n # Get the dimensions of the grid\n...
trial_gpt4o_0
{ "original_instruction": "You are given a map of a city represented as a grid of size m x n, where each cell can be either open land ('O'), water ('W'), or a tree ('T'). A tree cell cannot be traversed, but you can move through open land and water.\n\nThe city mayor wants to know the maximum area of water that can b...
0.716412
Codeforces_8753
C
[ "maxWaterParkArea", "max_histogram_area" ]
2
[ [ "maxWaterParkArea", "max_histogram_area" ] ]
1
[]
false
[]
false
pytest
false
[]
true
d46b3ad08a29de7d7963c6f237901965fd16f4ff
13735782fd2c7cac3986797a4af51c7e3f14f4da
v1.0
complete
Codeforces
Codeforces_8224_C
from collections import defaultdict from typing import List, Tuple def max_data_flow(n: int, m: int, links: List[Tuple[int, int, int]], s: int, t: int) -> int: """ Calculate the maximum potential data flow from a source server s to a destination server t. Args: n (int): Number of servers m (in...
from collections import deque, defaultdict def bfs(C, F, source, sink, parent): visited = set() queue = deque([source]) visited.add(source) while queue: u = queue.popleft() for v in C[u]: if v not in visited and C[u][v] - F[u][v] > 0: queue.appe...
from solution import max_data_flow def test_max_data_flow_basic(): n = 4 m = 5 links = [(1, 2, 100), (1, 3, 100), (2, 3, 1), (2, 4, 100), (3, 4, 100)] s = 1 t = 4 assert max_data_flow(n, m, links, s, t) == 200 def test_max_data_flow_single_path(): n = 3 m = 2 links = [(1, 2, 5), (2...
[ { "docstring": null, "function_declaration": "def bfs(C, F, source, sink, parent):", "function_name": "bfs", "parameter_list": "(C, F, source, sink, parent)" }, { "docstring": "Using Edmonds-Karp algorithm to find the maximum flow ", "function_declaration": "def edmonds_karp(C, source, s...
[ 0, 1, 0, 0, 1, 0, 1, 0, 1, 0 ]
4
medium
0.4
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "from collections import defaultdict, deque\n\ndef bfs(C, F, source, sink, parent):\n visited = set()\n queue = deque([source])\n visited.add(source)\...
trial_gpt4o_8
{ "original_instruction": "You are working on a project to optimize network usage for a company. The company's network consists of $$$n$$$ servers and $$$m$$$ two-way communication links between the servers. Each link has a certain amount of data $$$d$$$ that it can transfer per unit time. \n\nThe company wants to ma...
0.53678
Codeforces_8224
C
[ "bfs", "edmonds_karp", "max_data_flow" ]
3
[ [ "edmonds_karp", "bfs" ], [ "max_data_flow", "edmonds_karp" ] ]
2
[]
false
[]
false
pytest
true
[]
true
32f09cd06811c018e20736fd5cfa3e08e04604b8
f76611a15020b21a70586f48c40a97ec24527f3c
v1.0
complete
Codeforces
Codeforces_8777_C
from typing import List, Tuple def solve_tree_queries(n: int, values: List[int], edges: List[Tuple[int, int]], queries: List[int]) -> List[int]: """You are given a tree (connected acyclic undirected graph) with `n` nodes. Each node has an integer value assigned to it. Your task is to answer multiple querie...
from collections import defaultdict def build_tree(n, edges): tree = defaultdict(list) for u, v in edges: tree[u].append(v) tree[v].append(u) return tree def dfs(tree, node, parent, values, subtree_max): # Initially, the maximum of subtree rooted at `node` is the value of the node itse...
import pytest from solution import solve_tree_queries def test_example(): n = 7 values = [1, 2, 3, 4, 5, 6, 7] edges = [(1, 2), (1, 3), (2, 4), (2, 5), (3, 6), (3, 7)] queries = [1, 3, 6] expected = [7, 7, 6] assert solve_tree_queries(n, values, edges, queries) == expected def test_single_nod...
[ { "docstring": null, "function_declaration": "def build_tree(n, edges):", "function_name": "build_tree", "parameter_list": "(n, edges)" }, { "docstring": null, "function_declaration": "def dfs(tree, node, parent, values, subtree_max):", "function_name": "dfs", "parameter_list": "...
[ 1, 1, 1, 0, 1, 0, 0, 1, 0, 0 ]
5
medium
0.5
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def subtree_max_value(n, values, edges, queries):\n from collections import defaultdict, deque\n \n graph = defaultdict(list)\n for u, v in edges:...
trial_gpt4o_7
{ "original_instruction": "You are given a tree (connected acyclic undirected graph) with `n` nodes. Each node has an integer value assigned to it. Your task is to answer multiple queries on the tree. Each query asks for the maximum value within a given subtree of the tree.\n\n### Input\n- The first line contains an ...
0.604635
Codeforces_8777
C
[ "build_tree", "dfs", "preprocess_tree", "solve_tree_queries" ]
4
[ [ "preprocess_tree", "build_tree" ], [ "preprocess_tree", "dfs" ], [ "solve_tree_queries", "preprocess_tree" ] ]
3
[]
false
[]
false
pytest
true
[]
true
bc13469e163f315208f2d809e838eba2b3fd8172
905bb63ad9aa322bbc7532dc3fb5e6bb6b98ed1c
v1.0
complete
Codeforces
Codeforces_7972_C
from typing import List, Tuple def process_queries(n: int, edges: List[Tuple[int, int]], values: List[int], queries: List[int]) -> List[int]: """ You are given an undirected graph with `n` nodes and `m` edges. Each node has an integer value associated with it. The task is to process multiple queries where each...
def find_connected_components(n, edges): from collections import defaultdict, deque graph = defaultdict(list) for u, v in edges: graph[u].append(v) graph[v].append(u) visited = [False] * (n + 1) components = [] def bfs(node): queue = deque([node]) component...
from solution import process_queries def test_single_node(): assert process_queries(1, [], [10], [1]) == [10] def test_no_edges(): assert process_queries(3, [], [1, 2, 3], [1, 2, 3]) == [1, 2, 3] def test_all_connected(): assert process_queries(5, [(1, 2), (2, 3), (3, 4), (4, 5)], [1, 2, 3, 4, 5], [1, 3,...
[ { "docstring": null, "function_declaration": "def find_connected_components(n, edges):", "function_name": "find_connected_components", "parameter_list": "(n, edges)" }, { "docstring": null, "function_declaration": "def preprocess_values(n, values, components):", "function_name": "pre...
[ 0, 1, 1, 1, 1, 1, 0, 1, 1 ]
7
easy
0.778
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def calculate_connected_components_sum(n, m, node_values, edges, queries):\n from collections import defaultdict, deque\n \n # Represent the graph as...
trial_gpt4o_8
{ "original_instruction": "You are given an undirected graph with `n` nodes and `m` edges. Each node has an integer value associated with it. Your task is to process multiple queries where each query asks you to calculate the sum of values of nodes that are connected to a given starting node, either directly or indir...
0.620366
Codeforces_7972
C
[ "find_connected_components", "preprocess_values", "process_queries" ]
3
[ [ "process_queries", "find_connected_components" ], [ "process_queries", "preprocess_values" ] ]
2
[ "process_queries" ]
false
[]
false
pytest
true
[]
true
e518ecfcd6f921dacb9965cb4e99c616f150127a
5d63f6febb073f65cc7a45feacea6ae6cf23aedb
v1.0
complete
Codeforces
Codeforces_9322_C
def compute_prefix_sums(arr): """ Compute prefix sums for the given array. """ # Your code here def range_sum(prefix_sums, l, r): """ Compute the sum of the array elements between indices l and r (1-based) using prefix sums. """ # Your code here def process_queries(n, q, arr, queries):...
def compute_prefix_sums(arr): """ Compute prefix sums for the given array. """ prefix_sums = [0] * (len(arr) + 1) for i in range(1, len(arr) + 1): prefix_sums[i] = prefix_sums[i-1] + arr[i-1] return prefix_sums def range_sum(prefix_sums, l, r): """ Compute the sum of the array e...
from solution import compute_prefix_sums, range_sum, process_queries def test_compute_prefix_sums(): arr = [1, 2, 3, 4, 5] expected_prefix_sums = [0, 1, 3, 6, 10, 15] assert compute_prefix_sums(arr) == expected_prefix_sums def test_range_sum(): prefix_sums = [0, 1, 3, 6, 10, 15] assert range_sum(p...
[ { "docstring": "Compute prefix sums for the given array.", "function_declaration": "def compute_prefix_sums(arr):", "function_name": "compute_prefix_sums", "parameter_list": "(arr)" }, { "docstring": "Compute the sum of the array elements between indices l and r (1-based) using prefix sums."...
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
10
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def range_sum_queries(n, q, arr, queries):\n \"\"\"\n Returns the sum of elements between indices l and r for each query using prefix sum.\n n: int -...
trial_gpt4o_9
{ "original_instruction": "You are given an array of n integers, and you have to perform several operations on it. Each operation consists of two integers l and r and requires you to calculate the sum of all the elements of the array from index l to r inclusive. The array uses 1-based indexing.\n\nWrite a program tha...
0.567237
Codeforces_9322
C
[ "compute_prefix_sums", "range_sum", "process_queries" ]
3
[ [ "process_queries", "compute_prefix_sums" ], [ "process_queries", "range_sum" ] ]
2
[ "process_queries" ]
false
[]
false
pytest
true
[]
true
4aa34a234afca480035dae5b3da0709e815d7d0d
88b410d537988065c9f9ef7244cc032db71491d6
v1.0
complete
Codeforces
Codeforces_9324_C
def hasPathSum(tree: List[int], targetSum: int) -> bool: """ Determine if there exists a path in a binary tree such that the sum of the values along the path is equal to a given target sum. >>> hasPathSum([5, 4, 8, 11, -1, 13, 4, 7, 2, -1, -1, -1, 1], 22) True >>> hasPathSum([1, 2, 3], 5) False >>> hasP...
from typing import List, Optional class TreeNode: def __init__(self, x): self.val = x self.left = None self.right = None def build_tree(tree: List[int]) -> Optional[TreeNode]: if not tree or tree[0] == -1: return None root = TreeNode(tree[0]) nodes = [root] chi...
def test_case_1(): tree = [5, 4, 8, 11, -1, 13, 4, 7, 2, -1, -1, -1, 1] targetSum = 22 assert hasPathSum(tree, targetSum) == True def test_case_2(): tree = [1, 2, 3] targetSum = 5 assert hasPathSum(tree, targetSum) == False def test_case_3(): tree = [1, 2] targetSum = 3 assert hasP...
[]
[ 0, 0, 0, 0, 0, 0, 1, 0, 0, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def hasPathSum(tree, targetSum):\n def dfs(index, current_sum):\n if index >= len(tree) or tree[index] == -1:\n return False\n \n ...
trial_gpt4o_6
{ "original_instruction": "You are given an array of integers representing the node values of a binary tree in a level-order traversal. Your task is to determine if there exists a path in this binary tree such that the sum of the values along the path is equal to a given target sum.\n\nA path in the binary tree is a ...
0.603077
Codeforces_9324
C
[ "build_tree", "hasPathSum" ]
2
[ [ "hasPathSum", "build_tree" ] ]
1
[]
false
[ "TreeNode" ]
true
pytest
false
[]
true
a658387f44f73bba0db96938c58bc25dda2a255c
70e6a66ea092141ecc88f04944cfcec0e1e46e6d
v1.0
complete
Codeforces
Codeforces_9189_C
def perform_dfs(n: int, m: int, edges: List[Tuple[int, int]], s: int) -> List[int]: """ Perform a lexicographically smallest Depth First Search (DFS) on an undirected graph. Args: n (int): Number of vertices in the graph. m (int): Number of edges in the graph. edges (List[Tuple[int, int]])...
def dfs_lexicographic(n, m, edges, s): from collections import defaultdict import heapq # Create adjacency list graph = defaultdict(list) for u, v in edges: graph[u].append(v) graph[v].append(u) # Sort adjacency lists for lexicographical order for key in graph.keys(...
from solution import perform_dfs def test_example_case(): n = 5 m = 4 edges = [(1, 2), (1, 3), (2, 4), (2, 5)] start = 1 assert perform_dfs(n, m, edges, start) == [1, 2, 4, 5, 3] def test_single_node(): n = 1 m = 0 edges = [] start = 1 assert perform_dfs(n, m, edges, start) == ...
[ { "docstring": null, "function_declaration": "def dfs_lexicographic(n, m, edges, s):", "function_name": "dfs_lexicographic", "parameter_list": "(n, m, edges, s)" }, { "docstring": null, "function_declaration": "def perform_dfs(n, m, edge_list, start):", "function_name": "perform_dfs"...
[ 1, 0, 1, 1, 1, 1, 1, 1, 1, 1 ]
9
easy
0.9
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def dfs_lexicographically_smallest(graph, start):\n \"\"\"\n Perform DFS on the given graph starting from the vertex `start` in a lexicographically smal...
trial_gpt4o_9
{ "original_instruction": "You are given an undirected graph with `n` vertices and `m` edges. Each vertex is labeled from `1` to `n`. The graph is represented as an adjacency list, where each vertex has a list of vertices it is connected to.\n\nYou are required to perform a Depth First Search (DFS) starting from a gi...
0.555175
Codeforces_9189
C
[ "dfs_lexicographic", "perform_dfs" ]
2
[ [ "perform_dfs", "dfs_lexicographic" ] ]
1
[]
false
[]
false
pytest
true
[]
true
d10300d42401e64cb3dc9cf1c98ffd608ac1ecbb
4f918f601ee784b78d82214203e3518986b74f20
v1.0
complete
Codeforces
Codeforces_9463_C
def sieve(n): """ Returns a list of primes up to n, using the Sieve of Eratosthenes algorithm. """ is_prime = [True] * (n + 1) p = 2 while p * p <= n: if is_prime[p]: for i in range(p * p, n + 1, p): is_prime[i] = False p += 1 return [p for p in range(2, n...
def sieve(n): """ Returns a list of primes up to n, using the Sieve of Eratosthenes algorithm. """ is_prime = [True] * (n + 1) p = 2 while p * p <= n: if is_prime[p]: for i in range(p * p, n + 1, p): is_prime[i] = False p += 1 return [p for p in range(2, n...
from solution import prime_gaps_sum def test_prime_gaps_sum_example(): assert prime_gaps_sum(3, 11) == 8 def test_prime_gaps_sum_small_primes(): assert prime_gaps_sum(2, 5) == 3 def test_prime_gaps_sum_mid_primes(): assert prime_gaps_sum(23, 31) == 8 def test_prime_gaps_sum_large_primes(): assert pr...
[ { "docstring": "Returns a list of primes up to n, using the Sieve of Eratosthenes algorithm. ", "function_declaration": "def sieve(n):", "function_name": "sieve", "parameter_list": "(n)" }, { "docstring": "Returns the sum of all prime gaps between prime numbers p1 and p2, inclusive.", "f...
[ 1, 1, 0, 0, 0, 0, 0, 0, 0, 0 ]
2
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def sieve(n):\n \"\"\" Returns a list of primes up to n, using the Sieve of Eratosthenes algorithm. \"\"\"\n is_prime = [True] * (n + 1)\n p = 2\n ...
trial_gpt4o_0
{ "original_instruction": "You are a renowned cryptographer and have been tasked with creating a new encryption scheme based on prime numbers. Your idea is to use the properties of prime gaps (the difference between consecutive prime numbers) for the encryption scheme.\n\nGiven two prime numbers p1 and p2 such that p...
0.655064
Codeforces_9463
C
[ "sieve", "prime_gaps_sum" ]
2
[ [ "prime_gaps_sum", "sieve" ] ]
1
[]
false
[]
false
pytest
true
[]
true
f86d783803c62705a956838084e6f55d0906d602
dbb0737acea00552e47c2d5e8ded371d543ebb0b
v1.0
complete
Codeforces
Codeforces_7222_C
def dijkstra(n, graph, start): """ Use Dijkstra's algorithm to find the shortest paths from start to all other nodes. Parameters: n (int): Number of nodes in the graph. graph (dict): Adjacency list representation of the graph. start (int): The start node. Returns: list: List of sho...
import heapq def dijkstra(n, graph, start): """ Use Dijkstra's algorithm to find the shortest paths from start to all other nodes. Parameters: n (int): Number of nodes in the graph. graph (dict): Adjacency list representation of the graph. start (int): The start node. Returns: ...
def test_single_tree(): assert find_optimal_storage_tree(1, 0, []) == 0 def test_two_trees_one_branch(): assert find_optimal_storage_tree(2, 1, [(1, 2, 10)]) == 10 def test_three_trees_linear(): assert find_optimal_storage_tree(3, 2, [(1, 2, 5), (2, 3, 5)]) == 5 def test_three_trees_triangle(): asser...
[ { "docstring": "Use Dijkstra's algorithm to find the shortest paths from start to all other nodes.\n\nParameters:\nn (int): Number of nodes in the graph.\ngraph (dict): Adjacency list representation of the graph.\nstart (int): The start node.\n\nReturns:\nlist: List of shortest distance from start to each node....
[ 0, 0, 1, 0, 1, 0, 1, 0, 0 ]
3
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def floyd_warshall(n, edges):\n # Initialize distance matrix with infinity\n INF = float('inf')\n dist = [[INF] * n for _ in range(n)]\n \n # D...
trial_gpt4o_3
{ "original_instruction": "In a fictional kingdom called Forestland, there lives a clever squirrel called Nutty. Nutty loves gathering nuts and storing them in different locations throughout the forest. As winter approaches, Nutty wants to find the best place to hide her nuts, ensuring that they are safe from other a...
0.64323
Codeforces_7222
C
[ "dijkstra", "find_optimal_storage_tree" ]
2
[ [ "find_optimal_storage_tree", "dijkstra" ] ]
1
[]
false
[]
false
pytest
false
[]
true
806e2e5b26ab10581d72d9592ad998444daa49d8
1be4c5c3285a630a07cfad6e3f676c175270e764
v1.0
complete
Codeforces
Codeforces_7791_C
from typing import List, Tuple from collections import deque, defaultdict def build_graph(n: int, edges: List[Tuple[int, int]]) -> dict: """ Build the graph from given number of attractions and walkways. >>> build_graph(5, [(1, 2), (1, 3), (2, 4), (3, 4), (4, 5)]) { 1: [2, 3], 2: [1, 4], 3: [1, 4], 4: [2, ...
from collections import deque, defaultdict def build_graph(n, edges): graph = defaultdict(list) for u, v in edges: graph[u].append(v) graph[v].append(u) return graph def bfs_shortest_path(graph, start, end): if start == end: return 0 visited = set() queue = deque([(star...
def test_build_graph(): n = 5 edges = [(1, 2), (1, 3), (2, 4), (3, 4), (4, 5)] graph = build_graph(n, edges) assert graph == { 1: [2, 3], 2: [1, 4], 3: [1, 4], 4: [2, 3, 5], 5: [4] } def test_bfs_shortest_path(): n = 5 edges = [(1, 2), (1, 3), (2, 4),...
[ { "docstring": null, "function_declaration": "def build_graph(n, edges):", "function_name": "build_graph", "parameter_list": "(n, edges)" }, { "docstring": null, "function_declaration": "def bfs_shortest_path(graph, start, end):", "function_name": "bfs_shortest_path", "parameter_...
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 0 ]
9
easy
0.9
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "import heapq\nfrom collections import defaultdict, deque\n\ndef build_graph(n, edges):\n graph = defaultdict(list)\n for u, v in edges:\n graph[u...
trial_gpt4o_8
{ "original_instruction": "A large amusement park consists of several attractions connected by walkways. Your task is to determine if there's a route from the entrance to various attractions and to find the shortest route if one exists. You will represent the park as an undirected graph with n nodes and m edges. Node...
0.660145
Codeforces_7791
C
[ "build_graph", "bfs_shortest_path", "process_queries" ]
3
[ [ "process_queries", "bfs_shortest_path" ], [ "process_queries", "build_graph" ] ]
2
[ "process_queries" ]
false
[]
false
pytest
false
[]
true
9404bc01b8ec0b27c45d252781f20c237c44147f
8d33b3c27b0aa040c2f3721487404f1a1dcc38f6
v1.0
complete
Codeforces
Codeforces_9351_C
def two_sum(nums, target): """ Returns the indices of the two numbers from the array such that they add up to the target. >>> two_sum([2, 7, 11, 15], 9) in [(0, 1), (1, 0)] True >>> two_sum([3, 2, 4], 6) in [(1, 2), (2, 1)] True """ def solve_two_sum_problems(test_cases): """ Return...
def two_sum(nums, target): """ Returns the indices of the two numbers from the array such that they add up to the target. """ num_to_index = {} for index, num in enumerate(nums): complement = target - num if complement in num_to_index: return num_to_index[complement], ind...
from solution import two_sum, solve_two_sum_problems, read_input, format_output def test_two_sum_basic(): assert two_sum([2, 7, 11, 15], 9) in [(0, 1), (1, 0)] assert two_sum([3, 2, 4], 6) in [(1, 2), (2, 1)] def test_two_sum_negative_numbers(): assert two_sum([-3, 4, 3, 90], 0) in [(0, 2), (2, 0)] as...
[ { "docstring": "Returns the indices of the two numbers from the array such that they add up to the target.", "function_declaration": "def two_sum(nums, target):", "function_name": "two_sum", "parameter_list": "(nums, target)" }, { "docstring": null, "function_declaration": "def solve_two...
[ 1, 1, 1, 0, 1, 0, 1, 0, 1, 0 ]
6
medium
0.6
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def two_sum(nums, target):\n \"\"\"\n Returns the indices of the two numbers from the array such that they add up to the target.\n \"\"\"\n num_ma...
trial_gpt4o_8
{ "original_instruction": "You are given an integer array `nums` and an integer `target`. You need to return the indices of the two numbers from the array such that they add up to the `target`. You may assume that each input would have exactly one solution, and you may not use the same element twice.\n\nYou can retur...
0.655384
Codeforces_9351
C
[ "two_sum", "solve_two_sum_problems", "read_input", "format_output" ]
4
[ [ "solve_two_sum_problems", "two_sum" ] ]
1
[ "read_input", "format_output" ]
false
[]
false
pytest
true
[]
true
fefdfb45a55c9ad4d138fa350c6d082fe0db53b5
075fae622ad85f3d4e81aa928fee62532fb26026
v1.0
complete
Codeforces
Codeforces_9320_C
from collections import defaultdict, deque from typing import List, Tuple def max_fuel_distribution(n: int, demands: List[int], roads: List[Tuple[int, int, int]]) -> int: """ You are tasked with optimizing the fuel distribution in a network. Given n stations, demands of each station, and the one-way roads wit...
from collections import defaultdict, deque def max_fuel_distribution(n, demands, roads): graph = defaultdict(list) for u, v, c in roads: graph[u].append((v, c)) max_fuel = 0 visited = [False] * (n + 1) remaining_demand = demands[:] def bfs(start): visited[start] = True ...
from solution import max_fuel_distribution def test_example_case(): n = 4 demands = [30, 50, 60, 20] roads = [ (1, 2, 40), (1, 3, 20), (3, 4, 10) ] assert max_fuel_distribution(n, demands, roads) == 70 def test_corner_case_min_stations(): n = 2 demands = [10, 10] ...
[ { "docstring": null, "function_declaration": "def max_fuel_distribution(n, demands, roads):", "function_name": "max_fuel_distribution", "parameter_list": "(n, demands, roads)" }, { "docstring": null, "function_declaration": "def example():", "function_name": "example", "parameter...
[ 0, 0, 1, 0, 0, 0, 0, 0, 0, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def maxFuelDistributed(n, demands, roads):\n from collections import defaultdict, deque\n\n # Create an adjacency list to represent the graph\n adj =...
trial_gpt4o_2
{ "original_instruction": "You are tasked with optimizing the fuel distribution in a network of stations. Each station can either receive a fixed amount of fuel from its neighboring stations or not, following certain constraints. Your goal is to determine the maximum amount of fuel that can be distributed across the ...
0.646008
Codeforces_9320
C
[ "max_fuel_distribution", "example" ]
2
[ [ "example", "max_fuel_distribution" ] ]
1
[]
false
[]
false
pytest
true
[]
true
396cffac38b0d8c3898f1cc20df923f3090a4693
4ea77f0f20a78eab6b7d711a9986cd61bc7820ba
v1.0
complete
Codeforces
Codeforces_9667_C
def calculate_final_price(category: str, price: float) -> float: """Given a category and its price, calculate the final price after tax. The tax rates are: - Food: 5% - Electronics: 12% - Clothing: 8% - Other: 10% >>> calculate_final_price("Food", 100.00) 105.00 >>> calculate_fi...
def calculate_final_price(category, price): """ Given a category and its price, calculate the final price after tax. """ tax_rates = { "Food": 0.05, "Electronics": 0.12, "Clothing": 0.08, "Other": 0.10 } tax_rate = tax_rates.get(category, 0) final_price =...
from solution import calculate_final_price, process_items def test_food(): assert calculate_final_price("Food", 100.00) == 105.00 def test_electronics(): assert calculate_final_price("Electronics", 220.00) == 246.40 def test_clothing(): assert calculate_final_price("Clothing", 150.00) == 162.00 def test...
[ { "docstring": "Given a category and its price, calculate the final price after tax.", "function_declaration": "def calculate_final_price(category, price):", "function_name": "calculate_final_price", "parameter_list": "(category, price)" }, { "docstring": null, "function_declaration": "d...
[ 0, 0, 0, 0, 1, 0, 1, 1, 1, 0 ]
4
medium
0.4
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def calculate_final_price(n, items):\n \"\"\"\n Calculates the final price after applying tax based on the category.\n \n :param n: integer, numbe...
trial_gpt4o_7
{ "original_instruction": "You are helping to develop a software application that calculates the tax for various items in a store. The store applies different tax rates for different categories of items. Given an item category and its price, your task is to compute the final price after applying the respective tax ra...
0.587679
Codeforces_9667
C
[ "calculate_final_price", "process_items" ]
2
[ [ "process_items", "calculate_final_price" ] ]
1
[]
false
[]
false
pytest
true
[]
true
5b5e7346a4a49fa942914263126711254188d955
dc411b078100b4a6453175ce0d6c8215a52d5f23
v1.0
complete
Codeforces
Codeforces_9145_C
from typing import List, Optional class TreeNode: def __init__(self, val: int): self.val = val self.left = None self.right = None def max_path_sum(tree: List[Optional[int]]) -> int: """ You are given an array of integers representing a binary tree in level-order traversal form. ...
from typing import List, Optional class TreeNode: def __init__(self, val: int): self.val = val self.left = None self.right = None def build_tree(tree: List[Optional[int]]) -> Optional[TreeNode]: if not tree: return None nodes = [None if val is None else TreeNode(val) f...
import pytest from solution import max_path_sum def test_single_node(): assert max_path_sum([1]) == 1 def test_two_level_complete_tree(): assert max_path_sum([1, 2, 3]) == 6 def test_tree_with_null_nodes(): assert max_path_sum([1, 2, 3, None, 4, 5, 6]) == 16 def test_complex_tree_example(): assert m...
[]
[ 1, 0, 1, 1, 0, 1, 0, 0, 1, 1 ]
6
medium
0.6
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "from typing import List, Optional\n\nclass TreeNode:\n def __init__(self, val=0, left=None, right=None):\n self.val = val\n self.left = left\...
trial_gpt4o_2
{ "original_instruction": "You are given an array of integers representing a binary tree in level-order traversal form. Your goal is to construct the binary tree and find the maximum path sum. The path must start and end at any node in the binary tree but can only move through nodes consecutively along parent-child c...
0.644454
Codeforces_9145
C
[ "build_tree", "max_path_sum" ]
2
[ [ "max_path_sum", "build_tree" ] ]
1
[]
false
[ "TreeNode" ]
true
pytest
true
[]
true
49c2a5d574266a7feb40b69b620039a814d6a3a0
f12ed1768448dd263a7192ba8f0631180180f28a
v1.0
complete
Codeforces
Codeforces_8229_C
def count_inversions(arr: List[int]) -> int: """ Count the number of inversions in an array. An inversion is a pair of elements (arr[i], arr[j]) such that arr[i] > arr[j] and i < j. >>> count_inversions([1, 20, 6, 4, 5]) 5 >>> count_inversions([1, 2, 3, 4, 5]) 0 >>> count_inversions([5, 4...
def merge_and_count(arr, temp_arr, left, mid, right): i = left # Starting index for left subarray j = mid + 1 # Starting index for right subarray k = left # Starting index to be sorted inv_count = 0 # Conditions are checked to ensure that i doesn't exceed mid and j doesn't exceed right ...
from solution import count_inversions def test_count_inversions_example(): assert count_inversions([1, 20, 6, 4, 5]) == 5 def test_count_inversions_sorted_array(): assert count_inversions([1, 2, 3, 4, 5]) == 0 def test_count_inversions_reverse_sorted_array(): assert count_inversions([5, 4, 3, 2, 1]) == 1...
[ { "docstring": null, "function_declaration": "def merge_and_count(arr, temp_arr, left, mid, right):", "function_name": "merge_and_count", "parameter_list": "(arr, temp_arr, left, mid, right)" }, { "docstring": null, "function_declaration": "def merge_sort_and_count(arr, temp_arr, left, r...
[ 1, 1, 1, 1, 1, 1, 0, 1, 0, 1 ]
8
easy
0.8
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def count_inversions(arr):\n \"\"\"\n Counts the number of inversions in the array using a modified merge sort algorithm.\n \"\"\"\n if len(arr) <...
trial_gpt4o_9
{ "original_instruction": "Mishra loves coding and has just started learning about sorting algorithms. However, he finds the concept of inversion count in an array fascinating. An inversion in an array is a pair of elements (arr[i], arr[j]) such that arr[i] > arr[j] and i < j. Mishra wants to determine how \"unsorted...
0.871547
Codeforces_8229
C
[ "merge_and_count", "merge_sort_and_count", "count_inversions" ]
3
[ [ "count_inversions", "merge_sort_and_count" ], [ "merge_sort_and_count", "merge_and_count" ] ]
2
[]
false
[]
false
pytest
true
[]
true
1e81a65c17266625ac9fefd771e8b026a307f35b
a26c9b6a718c4902636c0e23856d3e4613edfe7d
v1.0
complete
Codeforces
Codeforces_7562_C
def max_of_mins(grid: List[List[int]]) -> int: """ Find the maximum value among the minimum values of each row in the grid. Parameters: grid (list of lists of int): The input grid Returns: int: The maximum value among the minimum values of each row """ def read_grid_and_find_max_of_mins(n...
def max_of_mins(grid): """ Find the maximum value among the minimum values of each row in the grid. Parameters: grid (list of lists of int): The input grid Returns: int: The maximum value among the minimum values of each row """ # Finding the minimum value in each row min_valu...
from solution import read_grid_and_find_max_of_mins def test_example_case(): n, m = 3, 3 lines = [ "3 7 5", "1 8 2", "9 4 6" ] assert read_grid_and_find_max_of_mins(n, m, lines) == 4 def test_single_row_case(): n, m = 1, 5 lines = ["7 3 5 1 6"] assert read_grid_and_...
[ { "docstring": "Find the maximum value among the minimum values of each row in the grid.\n\nParameters:\ngrid (list of lists of int): The input grid\n\nReturns:\nint: The maximum value among the minimum values of each row ", "function_declaration": "def max_of_mins(grid):", "function_name": "max_of_mins...
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def max_of_row_minima(grid):\n \"\"\"\n Returns the maximum value among the minimum values of each row of the grid.\n \"\"\"\n min_values = [min(r...
trial_gpt4o_9
{ "original_instruction": "You are given a rectangular grid filled with unique positive integers. Your task is to find the minimum value in each row of the grid and then the maximum value among those minimums.\n\nThe input consists of:\n- The first line contains two integers n and m (1 ≤ n, m ≤ 100), which represent ...
0.574626
Codeforces_7562
C
[ "max_of_mins", "read_grid_and_find_max_of_mins" ]
2
[ [ "read_grid_and_find_max_of_mins", "max_of_mins" ] ]
1
[]
false
[]
false
pytest
true
[]
true
a3a367ba1d75bde0a063738bcb629b49d0c503cc
733c377d993f1b837e1cb88f50f5e0a49dd4ec3d
v1.0
complete
Codeforces
Codeforces_9400_C
def minimum_spanning_tree(n: int, m: int, edge_list: List[Tuple[int, int, int]]) -> int: """ Find the minimum spanning tree (MST) of a weighted undirected graph. Arguments: n : int : the number of nodes in the graph. m : int : the number of edges in the graph. edge_list : List[Tuple[int, int, i...
def find(parent, i): if parent[i] == i: return i return find(parent, parent[i]) def union(parent, rank, x, y): xroot = find(parent, x) yroot = find(parent, y) if rank[xroot] < rank[yroot]: parent[xroot] = yroot elif rank[xroot] > rank[yroot]: parent[yroot] = xroot el...
from solution import minimum_spanning_tree def test_basic_case(): assert minimum_spanning_tree(4, 5, [(1, 2, 1), (2, 3, 2), (3, 4, 3), (4, 1, 4), (1, 3, 5)]) == 6 def test_disconnected_graph(): assert minimum_spanning_tree(4, 2, [(1, 2, 1), (3, 4, 2)]) == -1 def test_single_node(): assert minimum_spannin...
[ { "docstring": null, "function_declaration": "def find(parent, i):", "function_name": "find", "parameter_list": "(parent, i)" }, { "docstring": null, "function_declaration": "def union(parent, rank, x, y):", "function_name": "union", "parameter_list": "(parent, rank, x, y)" }, ...
[ 0, 0, 1, 1, 1, 0, 0, 0, 0, 0 ]
3
hard
0.3
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "class DisjointSet:\n def __init__(self, n):\n self.parent = list(range(n))\n self.rank = [0] * n\n\n def find(self, u):\n if self.p...
trial_gpt4o_4
{ "original_instruction": "You are given an undirected, connected weighted graph with `n` nodes and `m` edges. Each edge has a unique weight assigned to it. Your task is to find the minimum spanning tree (MST) of this graph, where MST is defined as a subset of the edges that forms a tree that includes every vertex, a...
0.784711
Codeforces_9400
C
[ "find", "union", "kruskal_mst", "minimum_spanning_tree" ]
4
[ [ "kruskal_mst", "find" ], [ "kruskal_mst", "union" ], [ "minimum_spanning_tree", "kruskal_mst" ], [ "union", "find" ] ]
4
[]
false
[]
false
pytest
true
[]
true
a29b8275b0440b40c507d4ba907409c452a5a28c
ed7ac2a7338c074d39700b55033962f48e2c5d61
v1.0
complete
Codeforces
Codeforces_7797_C
def min_steps(grid: List[List[str]], N: int, M: int, sr: int, sc: int, dr: int, dc: int) -> int: """ Determine the minimum number of steps required for Li to reach the destination or return -1 if not possible. >>> min_steps([ ... ['.', '.', '.', '.', '.'], ... ['.', '#', '#', '#', '.'], ... ...
from collections import deque def min_steps(grid, N, M, sr, sc, dr, dc): # Convert from 1-based to 0-based indexes sr -= 1 sc -= 1 dr -= 1 dc -= 1 directions = [(-1, 0), (1, 0), (0, -1), (0, 1)] # Up, Down, Left, Right queue = deque([(sr, sc, 0)]) # (row, col, steps) visited = set...
def test_min_steps_basic_case(): input_str = "5 5\n.....\n.###.\n.....\n.###.\n.....\n1 1 5 5" assert min_steps_from_input(input_str) == 8 def test_min_steps_no_obstacle_case(): input_str = "4 4\n....\n....\n....\n....\n1 1 4 4" assert min_steps_from_input(input_str) == 6 def test_min_steps_single_row...
[ { "docstring": null, "function_declaration": "def min_steps(grid, N, M, sr, sc, dr, dc):", "function_name": "min_steps", "parameter_list": "(grid, N, M, sr, sc, dr, dc)" }, { "docstring": null, "function_declaration": "def min_steps_from_input(input_str):", "function_name": "min_step...
[ 0, 0, 0, 0, 0, 1, 0, 1, 1, 0 ]
3
hard
0.3
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "from collections import deque\n\ndef min_steps_to_reach_destination(grid, n, m, sr, sc, dr, dc):\n \"\"\"\n Determines the minimum number of steps requi...
trial_gpt4o_8
{ "original_instruction": "Master Li is a master tactician in Cyberland!\n\nLi needs to safely transfer a package from one end of a dangerous alley to the other. The alley is represented as a grid with dimensions N x M, where each cell may contain obstacles. The grid cells are either empty ('.') or contain obstacles ...
0.640553
Codeforces_7797
C
[ "min_steps", "min_steps_from_input" ]
2
[ [ "min_steps_from_input", "min_steps" ] ]
1
[]
false
[]
false
pytest
false
[]
true
115eda876e262f94330b64642c32462f4b6d0ab0
a3f277062624a7d9a8390da1c899d3a10b7a5b96
v1.0
complete
Codeforces
Codeforces_10031_C
def minimal_parade_length(n: int, m: int, road_data: List[Tuple[int, int, int]]) -> int: """ In a magical kingdom, determine the minimal total length of the roads required for a parade route. Parameters: - n (int): Number of castles - m (int): Number of roads - road_data (List[Tuple[int, int, i...
def kruskal_minimum_spanning_tree(n, roads): parent = list(range(n)) rank = [0] * n def find(node): if parent[node] != node: parent[node] = find(parent[node]) return parent[node] def union(node1, node2): root1 = find(node1) root2 = find(node2) ...
from solution import minimal_parade_length def test_minimal_parade_length_example(): n = 4 m = 5 roads = [ (1, 2, 3), (2, 3, 4), (3, 4, 2), (4, 1, 6), (1, 3, 5) ] assert minimal_parade_length(n, m, roads) == 9 def test_minimal_parade_length_single_road(): ...
[ { "docstring": null, "function_declaration": "def kruskal_minimum_spanning_tree(n, roads):", "function_name": "kruskal_minimum_spanning_tree", "parameter_list": "(n, roads)" }, { "docstring": null, "function_declaration": "def minimal_parade_length(n, m, road_data):", "function_name"...
[ 0, 0, 1, 1, 1, 0, 0, 0, 1 ]
4
medium
0.444
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def find_minimal_parade_length(n, m, roads):\n \"\"\"\n Returns the minimal total length of the roads required for the parade\n using Prim's algorith...
trial_gpt4o_2
{ "original_instruction": "In a magical kingdom, there are n castles connected by m roads. Each road has a certain length, and exactly one road exists between each pair of castles.\n\nThe kingdom's ruler, King Arnav, wants to organize a grand parade that can pass through the roads in the kingdom. However, King Arnav ...
0.680468
Codeforces_10031
C
[ "kruskal_minimum_spanning_tree", "minimal_parade_length" ]
2
[ [ "minimal_parade_length", "kruskal_minimum_spanning_tree" ] ]
1
[]
false
[]
false
pytest
true
[]
true
6dbb525d6e49c12269352d7776b74a2c1caf0708
5a1257653cb2e7eda7874ebf877423dc02d8af78