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_14892_C
from typing import List, Tuple def longest_path(n: int, m: int, roads: List[Tuple[int, int]]) -> int: """ Find the length of the longest path in a city network where roads connect cities without revisiting any city. >>> longest_path(4, 2, [(1, 2), (2, 3)]) 2 >>> longest_path(4, 2, [(1, 2), (3, 4)]) ...
from collections import defaultdict def dfs(graph, node, visited): visited.add(node) distance = 0 for neighbor in graph[node]: if neighbor not in visited: distance = max(distance, 1 + dfs(graph, neighbor, visited)) visited.remove(node) return distance def longest_path(n, m, roa...
from solution import longest_path def test_single_road(): assert longest_path(4, 2, [(1, 2), (2, 3)]) == 2 def test_disconnected(): assert longest_path(4, 2, [(1, 2), (3, 4)]) == 1 def test_circle(): assert longest_path(3, 3, [(1, 2), (2, 3), (3, 1)]) == 2 def test_long_path(): assert lo...
[ { "docstring": null, "function_declaration": "def dfs(graph, node, visited):", "function_name": "dfs", "parameter_list": "(graph, node, visited)" }, { "docstring": null, "function_declaration": "def longest_path(n, m, roads):", "function_name": "longest_path", "parameter_list": "...
[ 0, 1, 0, 1, 1, 0, 0, 1, 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 longest_path(n, m, roads):\n from collections import defaultdict, deque\n\n def bfs(start):\n max_depth = 0\n queue = deque([(start, 0...
trial_gpt4o_8
{ "original_instruction": "You are given a list of cities connected by bidirectional roads and DZY wants to find the longest path he can drive without passing through any city more than once.\n\nYou will be given a number of cities, and some pairs of them are connected directly by roads. DZY can start from any city a...
0.693119
Codeforces_14892
C
[ "dfs", "longest_path" ]
2
[ [ "longest_path", "dfs" ] ]
1
[]
false
[]
false
pytest
true
[]
true
38bed0d9fc8d5a8fdabd6fbfade8fa5bf70b323c
9342909f8c9ab73a56ccf1acb28c301e3d32dff5
v1.0
complete
Codeforces
Codeforces_14428_C
from typing import List, Tuple def shortest_paths(n: int, m: int, edges: List[Tuple[int, int, int]], q: int, queries: List[Tuple[int, int]]) -> List[int]: """ Determine the shortest distance from a given source node to every other node in a directed, weighted graph. Args: n: Number of nodes. m: Nu...
import heapq def dijkstra(n, edges, src): graph = [[] for _ in range(n + 1)] for u, v, w in edges: graph[u].append((v, w)) dist = [float('inf')] * (n + 1) dist[src] = 0 pq = [(0, src)] while pq: d, node = heapq.heappop(pq) if d > dist[node]: con...
from solution import shortest_paths def test_shortest_paths_basic(): n, m = 5, 6 edges = [ (1, 2, 2), (2, 3, 4), (3, 4, 1), (4, 5, 7), (1, 3, 6), (1, 4, 10) ] q = 3 queries = [ (1, 5), (2, 4), (3, 1) ] assert shortest_p...
[ { "docstring": null, "function_declaration": "def dijkstra(n, edges, src):", "function_name": "dijkstra", "parameter_list": "(n, edges, src)" }, { "docstring": null, "function_declaration": "def shortest_paths(n, m, edges, q, queries):", "function_name": "shortest_paths", "parame...
[ 1, 0, 1, 1, 1, 1, 1, 1, 1 ]
8
easy
0.889
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "import heapq\n\ndef dijkstra(n, adj, start):\n \"\"\"\n Implements Dijkstra's algorithm to return the shortest path from start to all other nodes.\n ...
trial_gpt4o_9
{ "original_instruction": "You are given a directed, weighted graph with $n$ nodes and $m$ edges. Each edge has an integer weight associated with it. Your task is to determine the shortest distance from a given source node $s$ to every other node in the graph. Additionally, you need to answer $q$ queries where each q...
0.71617
Codeforces_14428
C
[ "dijkstra", "shortest_paths" ]
2
[ [ "shortest_paths", "dijkstra" ] ]
1
[]
false
[]
false
pytest
true
[]
true
7148c1b96d071af82c0c2322e62012e628d9d49f
34b217be4b9bea1c3a2456b34f1fbb6dbd2dff76
v1.0
complete
Codeforces
Codeforces_14907_C
def min_irrigation_systems(n: int, m: int, farm: List[str]) -> int: """ Determine the minimum number of irrigation systems required to water all the crops in the farm. An irrigation system can water a contiguous block of crops that are connected either vertically or horizontally but not diagonally. Ar...
def dfs(matrix, visited, i, j): stack = [(i, j)] while stack: x, y = stack.pop() for dx, dy in [(-1, 0), (1, 0), (0, -1), (0, 1)]: nx, ny = x + dx, y + dy if 0 <= nx < len(matrix) and 0 <= ny < len(matrix[0]) and not visited[nx][ny] and matrix[nx][ny] == 'C': ...
from solution import min_irrigation_systems def test_example_1(): n = 4 m = 4 farm = [ "C..C", ".C.C", "..C.", "C.C." ] assert min_irrigation_systems(n, m, farm) == 5 def test_single_crop(): n = 1 m = 1 farm = ["C"] assert min_irrigation_systems(n, m...
[ { "docstring": null, "function_declaration": "def dfs(matrix, visited, i, j):", "function_name": "dfs", "parameter_list": "(matrix, visited, i, j)" }, { "docstring": null, "function_declaration": "def min_irrigation_systems(n, m, farm):", "function_name": "min_irrigation_systems", ...
[ 0, 0, 0, 0, 1, 0, 1, 0, 1 ]
3
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def count_irrigation_systems(N, M, grid):\n \"\"\"\n Counts the minimum number of irrigation systems required to water all crops in the farm.\n\n :pa...
trial_gpt4o_9
{ "original_instruction": "You are given a rectangular farm represented as a grid of N rows and M columns. Each cell in the grid can either contain a crop (represented by 'C') or be a barren land (represented by '.'). Farmers want to build irrigation systems to water all the crops. An irrigation system can water a co...
0.632424
Codeforces_14907
C
[ "dfs", "min_irrigation_systems" ]
2
[ [ "min_irrigation_systems", "dfs" ] ]
1
[]
false
[]
false
pytest
true
[]
true
e756e1e496e27ea5e5267bfaa9f1933868d9a725
5af8ed7a776d5f404b5eee84502c397cd5cead35
v1.0
complete
Codeforces
Codeforces_15072_C
from itertools import permutations def unique_permutations(s: str) -> List[str]: """ Generates all unique permutations of the input string s, sorted in lexicographical order. >>> unique_permutations("abc") ["abc", "acb", "bac", "bca", "cab", "cba"] >>> unique_permutations("aab") ["aab...
from itertools import permutations def unique_permutations(s): """ Generates all unique permutations of the input string s, sorted in lexicographical order. """ perm = set(permutations(s)) sorted_perm = sorted([''.join(p) for p in perm]) return sorted_perm def print_permutations(s): """ ...
from solution import unique_permutations def test_unique_permutations_abc(): result = unique_permutations("abc") expected = ["abc", "acb", "bac", "bca", "cab", "cba"] assert result == expected def test_unique_permutations_aab(): result = unique_permutations("aab") expected = ["aab", "aba", "baa"] ...
[ { "docstring": "Generates all unique permutations of the input string s, sorted in lexicographical order.", "function_declaration": "def unique_permutations(s):", "function_name": "unique_permutations", "parameter_list": "(s)" }, { "docstring": "Prints each permutation on a new line.", "...
[ 0, 1, 1, 1, 0, 0, 0, 0, 0, 1 ]
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 permutations\n\ndef unique_permutations(s):\n \"\"\"\n Generates unique permutations of a given string s and returns them sorted i...
trial_gpt4o_3
{ "original_instruction": "In a certain programming challenge, you are asked to generate all possible permutations of a given string, ensuring that the permutations are unique. A string in this context can include uppercase and lowercase letters, digits, and special characters. Each character should be considered whe...
0.79367
Codeforces_15072
C
[ "unique_permutations", "print_permutations" ]
2
[ [ "print_permutations", "unique_permutations" ] ]
1
[]
false
[]
false
pytest
true
[]
true
1b61b8acbbc994da74df4414832cc572fcc9f06d
b367254aa0e8b83fdca12751e7434c3c0dae195c
v1.0
complete
Codeforces
Codeforces_14849_C
from typing import List, Tuple def shortest_path(n: int, m: int, edge_list: List[Tuple[int, int, int]], s: int) -> List[str]: """Calculate the shortest path from a given source node to all other nodes in a directed graph. Parameters: n (int): Number of nodes in the graph. m (int): Number of edges ...
import heapq def dijkstra(n, edges, s): graph = {i: [] for i in range(1, n + 1)} for u, v, w in edges: graph[u].append((v, w)) distances = {i: float('inf') for i in range(1, n + 1)} distances[s] = 0 priority_queue = [(0, s)] while priority_queue: curr_distance, node = heapq.he...
from solution import shortest_path def test_shortest_path_case1(): n = 5 m = 6 edges = [ (1, 2, -2), (1, 3, 4), (2, 3, 3), (2, 4, 2), (4, 2, 1), (4, 5, -1) ] s = 1 assert shortest_path(n, m, edges, s) == ['0', '-2', '1', '0', '-1'] def test_short...
[ { "docstring": null, "function_declaration": "def dijkstra(n, edges, s):", "function_name": "dijkstra", "parameter_list": "(n, edges, s)" }, { "docstring": null, "function_declaration": "def shortest_path(n, m, edge_list, s):", "function_name": "shortest_path", "parameter_list": ...
[ 1, 0, 1, 1, 1, 1, 1, 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": "import heapq\n\ndef dijkstra(n, edges, s):\n \"\"\"\n Implements Dijkstra's algorithm to find the shortest paths from node s to all other nodes in a dir...
trial_gpt4o_9
{ "original_instruction": "You are given a directed graph with $$$n$$$ nodes and $$$m$$$ edges. Each edge has a weight associated with it. Your task is to calculate the shortest path from a given source node to all other nodes. If a node is unreachable from the source, its distance should be considered infinity.\n\n#...
0.664633
Codeforces_14849
C
[ "dijkstra", "shortest_path" ]
2
[ [ "shortest_path", "dijkstra" ] ]
1
[]
false
[]
false
pytest
true
[]
true
6a428b554b384cce26d9f8fa945a41d1166c5b65
94b7ab0ef396724c752a0847fa8846a1bd516812
v1.0
complete
Codeforces
Codeforces_14069_C
import heapq from math import sqrt from typing import List, Tuple def euclidean_distance(x1, y1, x2, y2): return sqrt((x2 - x1) ** 2 + (y2 - y1) ** 2) def grid_distance(x1, y1, x2, y2): return abs(x2 - x1) + abs(y2 - y1) def minimal_travel_distance(n: int, express_routes: List[Tuple[int, int, int, int]], ax:...
import heapq from math import sqrt def euclidean_distance(x1, y1, x2, y2): return sqrt((x2 - x1) ** 2 + (y2 - y1) ** 2) def grid_distance(x1, y1, x2, y2): return abs(x2 - x1) + abs(y2 - y1) def minimal_travel_distance(n, express_routes, ax, ay, bx, by): graph = { (ax, ay): [] if (ax, ay) == (bx, ...
from solution import minimal_travel_distance def test_no_express_routes(): n = 0 express_routes = [] ax, ay, bx, by = 1, 1, 3, 3 assert minimal_travel_distance(n, express_routes, ax, ay, bx, by) == 4 def test_simple_express_route(): n = 1 express_routes = [(1, 1, 3, 3)] ax, ay, bx, by = 1,...
[ { "docstring": null, "function_declaration": "def euclidean_distance(x1, y1, x2, y2):", "function_name": "euclidean_distance", "parameter_list": "(x1, y1, x2, y2)" }, { "docstring": null, "function_declaration": "def grid_distance(x1, y1, x2, y2):", "function_name": "grid_distance", ...
[ 0, 0, 0, 1, 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\nimport math\n\ndef euclidean_distance(x1, y1, x2, y2):\n return math.sqrt((x2 - x1) ** 2 + (y2 - y1) ** 2)\n\ndef minimal_travel_distance(n, ...
trial_gpt4o_3
{ "original_instruction": "You are given a grid-based city represented as a 2D plane with streets along the integer coordinates, similar to a chessboard. Each intersection of streets is a crossing point on the grid.\n\nThe city also has special roads denoted as \"express routes\" that connect specific pairs of grid p...
0.625975
Codeforces_14069
C
[ "euclidean_distance", "grid_distance", "minimal_travel_distance" ]
3
[ [ "minimal_travel_distance", "euclidean_distance" ], [ "minimal_travel_distance", "grid_distance" ] ]
2
[]
false
[]
false
pytest
true
[]
true
2e4f705f220cf2e86b4b5b9b94b5bcbb718b41d8
b7922989bcbb84ca4f275c6587c2e584cf73ae31
v1.0
complete
Codeforces
Codeforces_15064_C
from typing import List, Tuple def cycle_in_graph(n: int, m: int, edge_list: List[Tuple[int, int]]) -> None: """ In a directed graph with `n` nodes and `m` edges, determine if there is a cycle and identify one if it exists. If there is no cycle, print "NO". If there is a cycle, print "YES" followed by the ...
from collections import defaultdict, deque def find_cycle(n, m, edges): def dfs(v): """Depth First Search for detecting a cycle""" visited[v] = 1 stack.append(v) for neighbour in graph[v]: if visited[neighbour] == 0: if dfs(neighbour): ...
from solution import cycle_in_graph def test_no_cycle(): edge_list = [ (1, 2), (2, 3), (3, 4) ] print("Expected: NO") cycle_in_graph(4, 3, edge_list) # Expected Output: NO assert True # This is just to indicate that there's no cycle as expected for simplicity def test_...
[ { "docstring": null, "function_declaration": "def find_cycle(n, m, edges):", "function_name": "find_cycle", "parameter_list": "(n, m, edges)" }, { "docstring": null, "function_declaration": "def cycle_in_graph(n, m, edge_list):", "function_name": "cycle_in_graph", "parameter_list...
[ 0, 0, 1, 1, 1, 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 find_cycle(n, m, edges):\n from collections import defaultdict, deque\n \n graph = defaultdict(list)\n for u, v in edges:\n graph[u].ap...
trial_gpt4o_9
{ "original_instruction": "In a directed graph with $$$n$$$ nodes labeled from 1 to n, and $$$m$$$ edges, your task is to determine if there exists a cycle and identify one if it exists.\n\nThe first line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \\le n \\le 10^5$$$, $$$0 \\le m \\le 10^5$$$).\n\nThe next $$$m$...
0.685644
Codeforces_15064
C
[ "find_cycle", "cycle_in_graph" ]
2
[ [ "cycle_in_graph", "find_cycle" ] ]
1
[]
false
[]
false
pytest
true
[]
true
0a53095d579cabf8f2495bfb2414ef386bb5df54
b584e148c9246ea8851cb056d84003a88515d5aa
v1.0
complete
Codeforces
Codeforces_15076_C
def count_encodings(N: int) -> int: """ Determine the number of ways to encode N using Dr. Euler's Fibonacci encoding scheme. The function returns 1 as there is only one valid encoding for any N. >>> count_encodings(1) == 1 >>> count_encodings(17) == 1 """
def fibonacci_sequence_up_to_n(n): """ Generates a list of Fibonacci numbers up to n. """ fibs = [0, 1] while fibs[-1] + fibs[-2] <= n: fibs.append(fibs[-1] + fibs[-2]) return fibs[1:] # We skip the initial 0 for encoding purposes def count_encodings(n): """ Returns the number ...
from solution import count_encodings def test_count_encodings_basic(): assert count_encodings(1) == 1 assert count_encodings(2) == 1 assert count_encodings(3) == 1 assert count_encodings(4) == 1 assert count_encodings(5) == 1 def test_count_encodings_example(): assert count_encodings(17) == 1 ...
[ { "docstring": "Generates a list of Fibonacci numbers up to n.", "function_declaration": "def fibonacci_sequence_up_to_n(n):", "function_name": "fibonacci_sequence_up_to_n", "parameter_list": "(n)" }, { "docstring": "Returns the number of ways to encode N using the given Fibonacci encoding s...
[ 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": "def fibonacci_numbers_up_to_n(n):\n \"\"\"\n Generate a list of Fibonacci numbers up to (but not necessarily including) n.\n \"\"\"\n fibs = [1, 2...
trial_gpt4o_4
{ "original_instruction": "The famous scientist Dr. Euler is working on a novel way to encode and decode secret messages. He discovered a unique property of Fibonacci numbers and decided to use it for his encoding scheme.\n\nA Fibonacci number sequence is defined as follows:\n- F(0) = 0\n- F(1) = 1\n- F(n) = F(n-1) +...
0.661952
Codeforces_15076
C
[ "fibonacci_sequence_up_to_n", "count_encodings" ]
2
[ [ "count_encodings", "fibonacci_sequence_up_to_n" ] ]
1
[]
false
[]
false
pytest
true
[]
true
99de39cee6019f43fce602743be41a0bb7c99e62
3fd354ce0ae1d880772295124f4d30c62aadbace
v1.0
complete
Codeforces
Codeforces_14641_C
from typing import List, Tuple def handle_graph_queries(input_data: str) -> List[int]: """ Parses input data and returns a list of shortest path lengths for each query. The function reads from a single string input representing the graph and queries. Each query asks for the shortest path between t...
import heapq def dijkstra(graph, start, end, n): pq = [(0, start)] distances = {i: float('inf') for i in range(1, n + 1)} distances[start] = 0 while pq: current_distance, current_vertex = heapq.heappop(pq) if current_vertex == end: return current_distance if current_...
def test_sample_case(): input_data = """5 6 3 1 2 4 2 3 -1 1 3 2 3 4 3 4 5 6 5 2 7 1 3 1 5 5 3""" expected_output = [2, 11, -1] assert handle_graph_queries(input_data) == expected_output def test_no_path(): input_data = """4 4 2 1 2 4 2 3 5 3 4 6 4 1 1 1 4 4 1""" expected_output = [15, 1] asse...
[ { "docstring": null, "function_declaration": "def dijkstra(graph, start, end, n):", "function_name": "dijkstra", "parameter_list": "(graph, start, end, n)" }, { "docstring": null, "function_declaration": "def shortest_paths(n, m, edges, queries):", "function_name": "shortest_paths", ...
[ 0, 0, 1, 1, 0, 0, 0, 0 ]
2
hard
0.25
{ "trial_gpt4o_0": null, "trial_gpt4o_1": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared1_results_combined.jsonl", "solution_code": "import heapq\n\ndef shortest_path(n, m, q, edges, queries):\n def dijkstra(graph, start, n):\n distances = [float('inf')] *...
trial_gpt4o_5
{ "original_instruction": "PCS the Developer is working on a directed graph problem with n vertices numbered from 1 to n and m edges. Each edge has a positive integer weight associated with it. The graph may contain cycles.\n\nPCS the Developer wants to find the length of the shortest path from vertex a to vertex b. ...
0.626595
Codeforces_14641
C
[ "dijkstra", "shortest_paths", "handle_graph_queries" ]
3
[ [ "handle_graph_queries", "shortest_paths" ], [ "shortest_paths", "dijkstra" ] ]
2
[]
false
[]
false
pytest
false
[]
true
a03a40e42dff91e49754d597d62f3a1c8e7404ee
0d131b35b6f1f61521ce1d48ed9bf8f2a65964aa
v1.0
complete
Codeforces
Codeforces_15189_C
def reorder_containers(n: int, weights: List[int]) -> Tuple[int, List[Tuple[int, int]]]: """ Vasya's puzzle solving function to reorder a stack of containers in reverse order. >>> reorder_containers(3, [3, 2, 1]) (7, [(1, 3), (1, 2), (3, 2), (1, 3), (2, 1), (2, 3), (1, 3)]) >>> reorder_containers(1...
def generate_moves(n, source, target, auxiliary, moves): if n == 1: moves.append((source, target)) return generate_moves(n - 1, source, auxiliary, target, moves) moves.append((source, target)) generate_moves(n - 1, auxiliary, target, source, moves) def reorder_containers(n, weights): ...
from solution import reorder_containers def test_reorder_containers(): n = 3 weights = [3, 2, 1] move_count, moves = reorder_containers(n, weights) assert move_count == 7 expected_moves = [(1, 3), (1, 2), (3, 2), (1, 3), (2, 1), (2, 3), (1, 3)] assert moves == expected_moves def test_reorder_c...
[ { "docstring": null, "function_declaration": "def generate_moves(n, source, target, auxiliary, moves):", "function_name": "generate_moves", "parameter_list": "(n, source, target, auxiliary, moves)" }, { "docstring": null, "function_declaration": "def reorder_containers(n, weights):", ...
[ 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 solve(n, weights):\n \"\"\"\n Reorders the stack of containers in reverse order using moves according to the given constraints.\n \"\"\"\n mov...
trial_gpt4o_9
{ "original_instruction": "Vasya is working on his next challenge and wants you to help him. Vasya has come up with a new kind of puzzle involving a stack of containers. There are $$$n$$$ containers labeled from $$$1$$$ to $$$n$$$, each with a certain weight. Initially, the containers are stacked in a specific order....
0.557844
Codeforces_15189
C
[ "generate_moves", "reorder_containers" ]
2
[ [ "reorder_containers", "generate_moves" ] ]
1
[]
false
[]
false
pytest
true
[]
true
a452b2f1625361b876af843083581073ab6ae684
cf8c9e90ce9c1e4e9e831fff314661a936545e60
v1.0
complete
Codeforces
Codeforces_15266_C
def is_prime(num: int) -> bool: """ Check if a number is prime. """ pass def emirp_numbers(n: int) -> list: """ Find all unique emirp numbers up to n. >>> emirp_numbers(100) [13, 17, 31, 37, 71, 73, 79, 97] >>> emirp_numbers(50) [13, 17, 31, 37] >>> emirp_numbers(10) [] >>> emirp_number...
def is_prime(num): if num <= 1: return False if num <= 3: return True if num % 2 == 0 or num % 3 == 0: return False i = 5 while i * i <= num: if num % i == 0 or num % (i + 2) == 0: return False i += 6 return True def emirp_numbers(n): emir...
from solution import emirp_numbers def test_emirp_numbers_up_to_100(): assert emirp_numbers(100) == [13, 17, 31, 37, 71, 73, 79, 97] def test_emirp_numbers_up_to_50(): assert emirp_numbers(50) == [13, 17, 31, 37] def test_emirp_numbers_no_emirps(): assert emirp_numbers(10) == [] def test_emirp_numbers_e...
[ { "docstring": null, "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": null, "function_declaration": "def emirp_numbers(n):", "function_name": "emirp_numbers", "parameter_list": "(n)" } ]
[ 0, 0, 0, 0, 0, 1, 0, 1, 1 ]
3
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(num):\n \"\"\"\n Checks if a number is a prime number.\n \"\"\"\n if num <= 1:\n return False\n if num == 2:\n retur...
trial_gpt4o_6
{ "original_instruction": "John loves playing with numbers and recently he stumbled upon an interesting pattern with prime numbers. He noticed that sometimes a prime number remains prime when its digits are reversed. For instance, 13 and 31 are both primes. John calls such primes 'emirp' numbers.\n\nGiven a positive ...
0.796898
Codeforces_15266
C
[ "is_prime", "emirp_numbers" ]
2
[ [ "emirp_numbers", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
6dd008f8e5a8b4b2d4bcb9d830e6dfcd8bae1c1b
f5514c642cb9ec659231ea3a546cc0ec5b986299
v1.0
complete
Codeforces
Codeforces_15241_C
def shortest_path(n: int, edges: List[Tuple[int, int, int]], queries: List[Tuple[int, int]]) -> List[int]: """ This function finds the shortest path between pairs of nodes in an undirected graph with weighted edges. Parameters: n (int): Number of nodes in the graph. edges (List[Tuple[int, int,...
def floyd_warshall(n, edges): # Initialize distance array inf = float('inf') distance = [[inf] * n for _ in range(n)] # Distance from each node to itself is 0 for i in range(n): distance[i][i] = 0 # Populate initial distances based on edges for a, b, w in edges: ...
from solution import shortest_path def test_single_path(): n = 2 edges = [(1, 2, 5)] queries = [(1, 2)] assert shortest_path(n, edges, queries) == [5] def test_direct_edge(): n = 3 edges = [(1, 2, 5), (2, 3, 10)] queries = [(1, 3), (1, 2), (2, 3)] assert shortest_path(n, edges, queries...
[ { "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...
[ 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 floyd_warshall(n, edges, queries):\n # Initialize the graph with 'inf' for all node pairs except the diagonal\n dist = [[float('inf')] * n for _ in ...
trial_gpt4o_6
{ "original_instruction": "You are given an undirected graph with $$$n$$$ nodes and $$$m$$$ edges. Each edge has a weight associated with it. Your task is to answer $$$q$$$ queries, where each query consists of a pair of nodes $$$u$$$ and $$$v$$$. For each query, find the shortest distance between the nodes $$$u$$$ a...
0.695917
Codeforces_15241
C
[ "floyd_warshall", "shortest_path" ]
2
[ [ "shortest_path", "floyd_warshall" ] ]
1
[]
false
[]
false
pytest
true
[]
true
21a9d703e35ff65dc03ace39db725e311e8c5562
105dfbe0e9d61d640ff8b15bb2913564d6f9e7dd
v1.0
complete
Codeforces
Codeforces_15345_C
from typing import List, Tuple def challenges_per_participant(m: int, challenges: List[int], p: int, participants: List[Tuple[int, int]]) -> List[int]: """ Determine the number of challenges each participant can solve based on their comfort zones. :param m: The number of challenges. :param challenges:...
def challenges_per_participant(m, challenges, p, participants): result = [] for (li, ri) in participants: count = sum(li <= d <= ri for d in challenges) result.append(count) return result def parse_input(input_str): lines = input_str.strip().split('\n') m = int(lines[0]) challen...
from solution import challenges_per_participant, solve_from_input def test_challenges_per_participant(): assert challenges_per_participant(6, [2, 3, 5, 6, 8, 10], 3, [(1, 5), (4, 9), (7, 10)]) == [3, 3, 2] def test_challenges_per_participant_all_out_of_range(): assert challenges_per_participant(6, [1, 2, 3, 4...
[ { "docstring": null, "function_declaration": "def challenges_per_participant(m, challenges, p, participants):", "function_name": "challenges_per_participant", "parameter_list": "(m, challenges, p, participants)" }, { "docstring": null, "function_declaration": "def parse_input(input_str):...
[ 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": "def challenges_within_comfort_zone(challenges, participants):\n \"\"\"\n Determines the number of challenges each participant can solve based on their c...
trial_gpt4o_9
{ "original_instruction": "In a coding competition, participants face multiple challenges and solve them to earn points. Each challenge has a predefined difficulty level represented by an integer. Participants prefer to solve challenges where the difficulty level is within their comfort zone. Each participant’s comfo...
0.626909
Codeforces_15345
C
[ "challenges_per_participant", "parse_input", "solve_from_input" ]
3
[ [ "solve_from_input", "challenges_per_participant" ], [ "solve_from_input", "parse_input" ] ]
2
[ "parse_input" ]
false
[]
false
pytest
true
[]
true
1bb247b75c3c7684950797378f21fa5d58b0e486
1862358d3500df931063a835b3277a6338e3eb70
v1.0
complete
Codeforces
Codeforces_15375_C
def is_password_secure(password: str) -> str: """ Determine if a password is secure. A secure password must: - Contain at least one digit (0-9), - Contain at least one lowercase Latin letter (a-z), - Contain at least one uppercase Latin letter (A-Z), - Contain at least one special character from...
def is_password_secure(password): if len(password) < 8 or len(password) > 20: return "Insecure" has_digit = any(char.isdigit() for char in password) has_lower = any(char.islower() for char in password) has_upper = any(char.isupper() for char in password) has_special = any(char in "!@#$%...
from solution import is_password_secure, analyze_passwords def test_is_password_secure(): assert is_password_secure("Aa1!aaaa") == "Secure" assert is_password_secure("Aa!aaaa") == "Insecure" # too short assert is_password_secure("Aa1!aaaa" * 3) == "Insecure" # too long assert is_password_secure("aaaa...
[ { "docstring": null, "function_declaration": "def is_password_secure(password):", "function_name": "is_password_secure", "parameter_list": "(password)" }, { "docstring": null, "function_declaration": "def analyze_passwords(passwords):", "function_name": "analyze_passwords", "para...
[ 0, 0, 0, 0, 0, 0, 0, 1, 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 re\n\ndef check_password_security(passwords):\n \"\"\"\n Check if each password in the list meets the security criteria.\n Criteria: \n - L...
trial_gpt4o_7
{ "original_instruction": "Write a program that analyzes whether a series of passwords from a user meet the requirements for a secure password. A secure password should have at least one digit (0-9), one lowercase Latin letter (a-z), one uppercase Latin letter (A-Z), and one special character from the set {!@#$%^&*()...
0.577245
Codeforces_15375
C
[ "is_password_secure", "analyze_passwords" ]
2
[ [ "analyze_passwords", "is_password_secure" ] ]
1
[]
false
[]
false
pytest
true
[]
true
841bdfe858701d41536f4a47a67ed63ec8a85c93
1534de70756b521220e9665d9f622ee6051328ca
v1.0
complete
Codeforces
Codeforces_15466_C
from collections import deque, defaultdict def solve(n, edge_list): """ Determine the distance between the two farthest nodes in a tree. The first argument is an integer `n` — the number of nodes in the tree. The second argument is a list of tuples representing the edges in the tree. >>> solve(5, ...
from collections import deque, defaultdict def find_farthest_node(start, n, graph): visited = [False] * (n + 1) queue = deque([(start, 0)]) # (current_node, distance) visited[start] = True farthest_node = start max_distance = 0 while queue: current_node, distance = queue.popleft()...
from solution import solve def test_simple_case(): edges = [(1, 2), (1, 3), (2, 4), (2, 5)] assert solve(5, edges) == 3 def test_line_tree(): edges = [(1, 2), (2, 3), (3, 4), (4, 5)] assert solve(5, edges) == 4 def test_star_tree(): edges = [(1, 2), (1, 3), (1, 4), (1, 5)] assert solve(5, edg...
[ { "docstring": null, "function_declaration": "def find_farthest_node(start, n, graph):", "function_name": "find_farthest_node", "parameter_list": "(start, n, graph)" }, { "docstring": null, "function_declaration": "def tree_diameter(n, edges):", "function_name": "tree_diameter", ...
[ 1, 1, 0, 0, 0, 1, 0, 1, 0 ]
4
medium
0.444
{ "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 find_farthest_node(start, n, adjacency_list):\n \"\"\"\n Performs BFS to find the farthest node from t...
trial_gpt4o_8
{ "original_instruction": "A tree is a connected acyclic graph consisting of `n` nodes labeled from `1` to `n`. The nodes are connected by `n-1` edges. Given such a tree, your task is to determine the distance between the two farthest nodes in the tree.\n\nThe first line of the input contains an integer `n` (2 ≤ n ≤ ...
0.655512
Codeforces_15466
C
[ "find_farthest_node", "tree_diameter", "solve" ]
3
[ [ "solve", "tree_diameter" ], [ "tree_diameter", "find_farthest_node" ] ]
2
[]
false
[]
false
pytest
true
[]
true
c8df3b3fb120faf20b6e4488fd17a7ed77fdf3b4
97f3c2ce233f4d6353be8ff125cd29fc651bcea4
v1.0
complete
Codeforces
Codeforces_15191_C
def hamiltonian_cycle_checker(n: int, m: int, edges: List[Tuple[int, int]]) -> str: """ Determine if an undirected graph contains a Hamiltonian cycle. :param n: Number of vertices in the graph :param m: Number of edges in the graph :param edges: List of edges where each edge is represented by a tuple (u...
def has_hamiltonian_cycle(n, edges): def is_valid(v, pos, path): # Check if this vertex is an adjacent vertex of the previously added vertex. if not graph[path[pos - 1]][v]: return False # Check if the vertex has already been included. if v in path: r...
import pytest from solution import hamiltonian_cycle_checker def test_example_case(): n, m = 4, 5 edges = [(1, 2), (1, 3), (2, 3), (3, 4), (4, 2)] assert hamiltonian_cycle_checker(n, m, edges) == "YES" def test_no_cycle(): n, m = 3, 2 edges = [(1, 2), (2, 3)] assert hamiltonian_cycle_checker(n...
[ { "docstring": null, "function_declaration": "def has_hamiltonian_cycle(n, edges):", "function_name": "has_hamiltonian_cycle", "parameter_list": "(n, edges)" }, { "docstring": null, "function_declaration": "def hamiltonian_cycle_checker(n, m, edges):", "function_name": "hamiltonian_c...
[ 0, 0, 1, 0, 0, 0, 0, 1, 0, 0 ]
2
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "from itertools import permutations\n\ndef contains_hamiltonian_cycle(n, m, edges):\n # Convert edge list to adjacency matrix\n adj = [[0] * n for _ in r...
trial_gpt4o_2
{ "original_instruction": "Given an undirected graph, determine if it contains a Hamiltonian cycle. A Hamiltonian cycle is a cycle that visits every vertex exactly once and returns to the starting vertex.\n\nThe first line contains two integers, $$$n$$$ and $$$m$$$, which denote the number of vertices and edges in th...
0.560879
Codeforces_15191
C
[ "has_hamiltonian_cycle", "hamiltonian_cycle_checker" ]
2
[ [ "hamiltonian_cycle_checker", "has_hamiltonian_cycle" ] ]
1
[]
false
[]
false
pytest
true
[]
true
9f2345d76f96f3aeca6e44e553126707cb5cc333
b555223fa378e439c3674a778cfc29bcc02fe76c
v1.0
complete
Codeforces
Codeforces_15436_C
from typing import List def is_prime(number: int) -> bool: """Determine if a given number is a prime number. Args: number (int): The number to check. Returns: bool: True if the number is prime, False otherwise. >>> is_prime(2) True >>> is_prime(4) False """ pass def find_...
import math def is_prime(number): """ Determine if a given number is a prime number. """ if number <= 1: return False if number <= 3: return True if number % 2 == 0 or number % 3 == 0: return False i = 5 while i * i <= number: if number % i == 0 or number...
from solution import is_prime, find_adjacent_prime_sum_indices def test_is_prime(): assert is_prime(2) == True assert is_prime(3) == True assert is_prime(4) == False assert is_prime(5) == True assert is_prime(9) == False assert is_prime(13) == True def test_find_adjacent_prime_sum_indices(): ...
[ { "docstring": "Determine if a given number is a prime number.", "function_declaration": "def is_prime(number):", "function_name": "is_prime", "parameter_list": "(number)" }, { "docstring": "Find the indices of the first pair of adjacent elements whose sum is a prime number.\nIf no such pair...
[ 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": "def is_prime(num):\n \"\"\"\n Checks if a number is a prime number.\n \"\"\"\n if num <= 1:\n return False\n if num <= 3:\n retur...
trial_gpt4o_4
{ "original_instruction": "Given a list of integers, determine if there is a pair of adjacent elements in the list whose sum is a prime number. If such a pair exists, print the indices of the first pair (1-based). If no such pair exists, print -1.\n\nInput:\nThe input consists of two lines. The first line contains an...
0.700334
Codeforces_15436
C
[ "is_prime", "find_adjacent_prime_sum_indices" ]
2
[ [ "find_adjacent_prime_sum_indices", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
7e95dd0884128bf9f8ee9a0d35fd797c4afc7988
71c505d6dd2e409d601a645afdb8aaadea11eba3
v1.0
complete
Codeforces
Codeforces_15374_C
from typing import List, Tuple def min_new_roads(n: int, m: int, t: int, roads: List[Tuple[int, int, int]]) -> int: """ Compute the minimum number of roads that need to be added to ensure all travel weights from the main warehouse to any other warehouse are within the threshold t, or determine that it is...
import heapq def shortest_path(n, graph, main_warehouse): distances = {i: float('inf') for i in range(1, n + 1)} distances[main_warehouse] = 0 min_heap = [(0, main_warehouse)] while min_heap: curr_distance, u = heapq.heappop(min_heap) if curr_distance > distances[u]: ...
from solution import min_new_roads def test_example_case(): n = 4 m = 4 t = 3 roads = [(1, 2, 1), (2, 3, 2), (3, 4, 1), (4, 1, 4)] assert min_new_roads(n, m, t, roads) == 1 def test_already_below_threshold(): n = 3 m = 3 t = 5 roads = [(1, 2, 2), (2, 3, 2), (1, 3, 4)] assert mi...
[ { "docstring": null, "function_declaration": "def shortest_path(n, graph, main_warehouse):", "function_name": "shortest_path", "parameter_list": "(n, graph, main_warehouse)" }, { "docstring": null, "function_declaration": "def min_new_roads(n, m, t, roads):", "function_name": "min_ne...
[ 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": "import heapq\nimport sys\nfrom collections import defaultdict\n\ndef min_roads_to_add(n, m, t, edges):\n def dijkstra(graph, start, n):\n distances ...
trial_gpt4o_4
{ "original_instruction": "A company has a road network connecting various warehouses. This road network can be represented as an undirected graph where nodes are warehouses and edges are roads connecting them. Each road has a different travel weight based on the condition and distance of the road.\n\nThe company wan...
0.691491
Codeforces_15374
C
[ "shortest_path", "min_new_roads" ]
2
[ [ "min_new_roads", "shortest_path" ] ]
1
[]
false
[]
false
pytest
true
[]
true
faf1f25ebd8f58ce8bc1807800a53cd97ea7f7ad
2fcdbaca55a963304774ffba1bf8becbb9ef0472
v1.0
complete
Codeforces
Codeforces_15723_C
def is_happy_number(n: int) -> bool: """ Returns whether a number is a Happy Number or not. >>> is_happy_number(19) True >>> is_happy_number(7) True >>> is_happy_number(10) True >>> is_happy_number(20) False >>> is_happy_number(4) False >>> is_happy_number(2) False """ def is_ha...
def is_happy_number(n): """ Returns whether a number is a Happy Number or not. """ seen = set() while n != 1 and n not in seen: seen.add(n) n = sum(int(digit) ** 2 for digit in str(n)) return n == 1 def is_happy_sequence(sequence): """ Determines if every number in the g...
from solution import is_happy_number, is_happy_sequence def test_is_happy_number(): assert is_happy_number(19) == True assert is_happy_number(7) == True assert is_happy_number(10) == True assert is_happy_number(20) == False assert is_happy_number(4) == False assert is_happy_number(2) == False ...
[ { "docstring": "Returns whether a number is a Happy Number or not.", "function_declaration": "def is_happy_number(n):", "function_name": "is_happy_number", "parameter_list": "(n)" }, { "docstring": "Determines if every number in the given sequence is a Happy Number.", "function_declarati...
[ 0, 0, 1, 1, 0, 1, 1, 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": "def is_happy_number(n):\n \"\"\"\n Returns True if n is a happy number, False otherwise.\n \"\"\"\n seen = set()\n while n != 1 and n not in se...
trial_gpt4o_9
{ "original_instruction": "You have been given a special kind of number sequence, called a \"Happy Sequence,\" of length N. A sequence is called a Happy Sequence if, for any element in the sequence, the sum of its digits, when taken repeatedly, eventually leads to the number 1. For example, 19 is a Happy number becau...
0.695114
Codeforces_15723
C
[ "is_happy_number", "is_happy_sequence" ]
2
[ [ "is_happy_sequence", "is_happy_number" ] ]
1
[]
false
[]
false
pytest
true
[]
true
2241fb8e7234f54f88e9e6549b5d70e30df2a2ff
e20024b25017499167ffa1b53c22870955f0733d
v1.0
complete
Codeforces
Codeforces_15497_C
from typing import List def calculate_visibility(heights: List[int]) -> List[int]: """ Calculate visibility for each tree. """ pass def best_position(n: int, heights: List[int], h_new: int) -> int: """ Determines the best position to plant the new tree. Args: n: The number of trees a...
def calculate_visibility(heights): """ Calculate visibility for each tree. """ n = len(heights) visibility = [0] * n stack = [] for i in range(n-1, -1, -1): while stack and stack[-1] <= heights[i]: stack.pop() visibility[i] = len(stack) stack.append(h...
from solution import best_position def test_best_position_case_1(): n = 5 heights = [2, 3, 1, 4, 6] h_new = 5 assert best_position(n, heights, h_new) == 5 def test_best_position_case_2(): n = 3 heights = [1, 2, 3] h_new = 4 assert best_position(n, heights, h_new) == 4 def test_best_po...
[ { "docstring": "Calculate visibility for each tree.", "function_declaration": "def calculate_visibility(heights):", "function_name": "calculate_visibility", "parameter_list": "(heights)" }, { "docstring": "Determines the best position to plant the new tree.", "function_declaration": "def...
[ 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": "def find_best_position(n, heights, h_new):\n def visibility(index, heights):\n visible_count = 0\n max_height = 0\n for j in range(ind...
trial_gpt4o_1
{ "original_instruction": "In a forest, there are $$$n$$$ trees arranged in a straight line from left to right. Each tree has a certain height. We want to plant a new tree at one of the positions such that the new tree either becomes the tallest tree or is positioned where it will maximize its visibility when viewed ...
0.537176
Codeforces_15497
C
[ "calculate_visibility", "best_position" ]
2
[ [ "best_position", "calculate_visibility" ] ]
1
[]
false
[]
false
pytest
true
[]
true
c02a83f44041f78b0a024185cacac350bee858e3
83389300d74438d6436598e59d47e40c03b39253
v1.0
complete
Codeforces
Codeforces_15732_C
from typing import List def max_row_sum(table: List[List[int]]) -> int: """ You are given a table represented by a list of rows, each containing a list of integers. Your task is to find the largest sum of contiguous sublist within each row and then return the maximum sum among all rows. A contiguous ...
from typing import List def max_sublist_sum(row: List[int]) -> int: """ Helper function that uses Kadane's algorithm to find the maximum sum of a contiguous sublist in a given list. """ max_sum = row[0] current_sum = row[0] for num in row[1:]: current_sum = max(num, current_sum...
from solution import max_row_sum def test_example_case(): assert max_row_sum([[1, -2, 3, 10, -4, 7, 2, -5], [-1, -2, -3, -4], [5, 1, -3, 7, 8]]) == 18 def test_single_element_rows(): assert max_row_sum([[1], [2], [-5]]) == 2 def test_all_negatives(): assert max_row_sum([[-3, -2, -1], [-6, -5, -4], [-7]])...
[ { "docstring": "Helper function that uses Kadane's algorithm to find\nthe maximum sum of a contiguous sublist in a given list.", "function_declaration": "def max_sublist_sum(row):", "function_name": "max_sublist_sum", "parameter_list": "(row)" }, { "docstring": "Returns the maximum sum of co...
[ 0, 1, 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": "def max_row_sum(table):\n def max_subarray_sum(arr):\n max_so_far = arr[0]\n max_ending_here = arr[0]\n for x in arr[1:]:\n ...
trial_gpt4o_9
{ "original_instruction": "You are given a table represented by a list of rows, each containing a list of integers. Your task is to find the largest sum of contiguous sublist within each row and then return the maximum sum among all rows. A contiguous sublist contains one or more elements from the original list, and ...
0.623713
Codeforces_15732
C
[ "max_sublist_sum", "max_row_sum" ]
2
[ [ "max_row_sum", "max_sublist_sum" ] ]
1
[]
false
[]
false
pytest
true
[]
true
1d07d66f6699aaa7a06da438ca215308f76510c9
68002273f7d25c0655c8255fcdcb5ec90c16397e
v1.0
complete
Codeforces
Codeforces_15885_C
from typing import List def palindromic_base_sequence(n: int) -> List[int]: """ Generate the first n numbers of the Palindromic Base Sequence. A sequence is called a Palindromic Base Sequence if for any prefix of the sequence, the sum of digits in its binary representation forms a palindrome. >>> palindro...
from typing import List def is_binary_palindrome(x: int) -> bool: binary_rep = bin(x)[2:] return binary_rep == binary_rep[::-1] def palindromic_base_sequence(n: int) -> List[int]: result = [] current_num = 1 while len(result) < n: if is_binary_palindrome(current_num): resu...
from solution import palindromic_base_sequence def test_palindromic_base_sequence_single_element(): assert palindromic_base_sequence(1) == [1] def test_palindromic_base_sequence_two_elements(): assert palindromic_base_sequence(2) == [1, 3] def test_palindromic_base_sequence_three_elements(): assert palin...
[ { "docstring": null, "function_declaration": "def is_binary_palindrome(x):", "function_name": "is_binary_palindrome", "parameter_list": "(x)" }, { "docstring": null, "function_declaration": "def palindromic_base_sequence(n):", "function_name": "palindromic_base_sequence", "parame...
[ 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": "from typing import List\n\ndef is_palindrome(s: str) -> bool:\n return s == s[::-1]\n\ndef palindromic_base_sequence(n: int) -> List[int]:\n sequence = ...
trial_gpt4o_6
{ "original_instruction": "Mazie is a software developer who loves working with numbers, and she is fascinated by sequences that have special properties. Mazie recently came across an interesting sequence called the Palindromic Base Sequence. A sequence is called a Palindromic Base Sequence if for any prefix of the s...
0.676859
Codeforces_15885
C
[ "is_binary_palindrome", "palindromic_base_sequence" ]
2
[ [ "palindromic_base_sequence", "is_binary_palindrome" ] ]
1
[]
false
[]
false
pytest
true
[]
true
40f855977bde09a5cfe790ac7d54e86e642f9b11
80187bd26cb6630a2199b9b7fad229b8828ca3c7
v1.0
complete
Codeforces
Codeforces_15589_C
def merge_meetings(meetings): """ Merges overlapping meetings into a list of non-overlapping meetings. :param meetings: List of tuples [(start, end), ...] :return: List of merged meetings [(start, end), ...] """ pass def process_input_and_solve(n, input_meetings): """ Processes input an...
def merge_meetings(meetings): """ Merges overlapping meetings into a list of non-overlapping meetings. :param meetings: List of tuples [(start, end), ...] :return: List of merged meetings [(start, end), ...] """ if not meetings: return [] # Sort meetings by the start time meetin...
from solution import merge_meetings, process_input_and_solve def test_merge_meetings_no_overlap(): meetings = [(1, 2), (3, 4)] assert merge_meetings(meetings) == [(1, 2), (3, 4)] def test_merge_meetings_all_overlap(): meetings = [(1, 4), (2, 3), (3, 5)] assert merge_meetings(meetings) == [(1, 5)] def...
[ { "docstring": "Merges overlapping meetings into a list of non-overlapping meetings.\n:param meetings: List of tuples [(start, end), ...]\n:return: List of merged meetings [(start, end), ...]", "function_declaration": "def merge_meetings(meetings):", "function_name": "merge_meetings", "parameter_lis...
[ 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": "def merge_meetings(meetings):\n \"\"\"\n Merges all overlapping meetings into one and returns the list of merged meetings.\n \"\"\"\n if not meeti...
trial_gpt4o_8
{ "original_instruction": "#### Efficiently Merging Meetings\n\nYou are given a list of meetings in an office represented as pairs of integers, where each pair (start, end) indicates the starting and ending time of a meeting. Each pair is inclusive, meaning a meeting from time 2 to 3 would be represented as (2, 3). Y...
0.512699
Codeforces_15589
C
[ "merge_meetings", "process_input_and_solve" ]
2
[ [ "process_input_and_solve", "merge_meetings" ] ]
1
[]
false
[]
false
pytest
true
[]
true
6d9863f3c8f5c52e4916ed9b78829779b598469c
aae6bd33380b92fb5345c5a9afd035ca335dfbc4
v1.0
complete
Codeforces
Codeforces_15855_C
def minimum_genres_to_identify_books(n: int, m: int, books_list: List[str]) -> int: """ Find the minimum number of unique genres required to ensure that each book has at least one genre identifier from this set. >>> minimum_genres_to_identify_books(3, 4, ["2 1 2", "3 2 3 4", "2 3 4"]) 2 >>> minimum_genr...
def min_genres_to_identify_books(n, m, books): from itertools import combinations # Creating a list of all genres unique_genres = set() for book in books: unique_genres.update(book) unique_genres = list(unique_genres) # Function to check if a given set of genres covers all book...
from solution import minimum_genres_to_identify_books def test_sample_input(): n = 3 m = 4 books_list = [ "2 1 2", "3 2 3 4", "2 3 4" ] assert minimum_genres_to_identify_books(n, m, books_list) == 2 def test_single_book(): n = 1 m = 3 books_list = ["2 1 2"] ...
[ { "docstring": null, "function_declaration": "def min_genres_to_identify_books(n, m, books):", "function_name": "min_genres_to_identify_books", "parameter_list": "(n, m, books)" }, { "docstring": null, "function_declaration": "def minimum_genres_to_identify_books(n, m, books_list):", ...
[ 0, 1, 0, 0, 1, 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 min_unique_genres(n, m, books):\n from itertools import combinations\n \n all_genres = {genre for book in books for genre in book}\n \n for...
trial_gpt4o_1
{ "original_instruction": "You are developing an application for a bookstore that needs to efficiently manage a large collection of books by categorizing them into different genres. Each book can belong to multiple genres, and each genre has a unique identifier.\n\nTo organize this system, you are given a list of boo...
0.616339
Codeforces_15855
C
[ "min_genres_to_identify_books", "minimum_genres_to_identify_books" ]
2
[ [ "minimum_genres_to_identify_books", "min_genres_to_identify_books" ] ]
1
[]
false
[]
false
pytest
true
[]
true
8f2e16aa6939958f5f7ecb22d3f8980f3ec04c43
c0ab4ee9d8cb1844a8e3b5eea7906b41ae6c0d49
v1.0
complete
Codeforces
Codeforces_15559_C
def can_place_plant(garden, plant, start_row, start_col): """ Check if a plant can be placed at the specified location in the garden. :param garden: List[List[str]], the garden grid :param plant: List[Tuple[int, int]], the shape of the plant :param start_row: int, the starting row to place the plant...
def can_place_plant(garden, plant, start_row, start_col): for r, c in plant: if start_row + r >= len(garden) or start_col + c >= len(garden[0]) or garden[start_row + r][start_col + c] != '.': return False return True def place_plant(garden, plant, start_row, start_col, plant_id): for r,...
import pytest def test_can_solve_garden(): from solution import main inputs = [ (4, 5, [ "..#..", ".....", "###..", "..#.."], 2, [ [0, 0, 1, 0, 2, 0, 2, 1, 2, 2], [0, 0, 1, 0, 1, 1] ]), ] outputs = [ ...
[ { "docstring": null, "function_declaration": "def can_place_plant(garden, plant, start_row, start_col):", "function_name": "can_place_plant", "parameter_list": "(garden, plant, start_row, start_col)" }, { "docstring": null, "function_declaration": "def place_plant(garden, plant, start_ro...
[ 0, 0, 0, 0, 0, 1, 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 fill_garden(n, m, garden, k, plants):\n def can_place_plant(grid, plant, r, c):\n for pr, pc in plant:\n nr, nc = r + pr, c + pc\n ...
trial_gpt4o_7
{ "original_instruction": "You are given a rectangular grid representing a garden and a list of plants with their specific growth patterns. Each plant grows in a specific shape that can occupy several cells in the garden. Your task is to arrange the plants in the garden in such a way that no unclaimed cells remain an...
0.550904
Codeforces_15559
C
[ "can_place_plant", "place_plant", "remove_plant", "solve_garden", "main", "read_input" ]
6
[ [ "solve_garden", "can_place_plant" ], [ "solve_garden", "place_plant" ], [ "solve_garden", "remove_plant" ] ]
3
[ "read_input" ]
false
[]
false
pytest
true
[]
true
1a11595a1e6575b30c01419309fb03a17c3771e7
48cb7e6dae753f07e1e1c10d2d90df8ea738458d
v1.0
complete
Codeforces
Codeforces_15861_C
def solve_water_pipeline(m: int, n: int, heights: List[List[int]]) -> int: """ Finds the minimum number of houses to pass through to lay down the pipeline from the top-left corner to the bottom-right corner. Returns -1 if it is impossible to lay down the pipeline. >>> solve_water_pipeline(3, 3, [ ....
from collections import deque def min_houses_to_pass(grid): """ Returns the minimum number of houses required to pass through to lay down the pipeline. """ m, n = len(grid), len(grid[0]) if m == 1 and n == 1: return 1 directions = [(0, 1), (0, -1), (1, 0), (-1, 0)] visited = [...
from solution import solve_water_pipeline def test_example(): m, n = 3, 3 heights = [ [1, 3, 2], [2, 4, 2], [2, 2, 1] ] assert solve_water_pipeline(m, n, heights) == 5 def test_single_house(): m, n = 1, 1 heights = [ [1] ] assert solve_water_pipeline(m, ...
[ { "docstring": "Returns the minimum number of houses required to pass through to lay down the pipeline.", "function_declaration": "def min_houses_to_pass(grid):", "function_name": "min_houses_to_pass", "parameter_list": "(grid)" }, { "docstring": null, "function_declaration": "def solve_...
[ 1, 1, 1, 0, 1, 1, 0, 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 collections import deque\n\ndef min_houses_pipelining(m, n, grid):\n \"\"\"\n Returns the minimum number of houses required to pass through to lay ...
trial_gpt4o_9
{ "original_instruction": "In a small town, there is a rectangular grid of streets representing houses. The town's mayor wants to build a new water pipeline that connects the top-left corner to the bottom-right corner. Each house has an integer height. A pipeline can be laid from one house to another if the height di...
0.656209
Codeforces_15861
C
[ "min_houses_to_pass", "solve_water_pipeline" ]
2
[ [ "solve_water_pipeline", "min_houses_to_pass" ] ]
1
[]
false
[]
false
pytest
true
[]
true
6e422a5d81fd7b86bc5ee312d1b968638457bb67
161e68bd75721ee5b39812dce162c3754a334b7c
v1.0
complete
Codeforces
Codeforces_15816_C
def largest_fertile_subgrid(n: int, grid: List[List[int]]) -> int: """ Determine the number of cells in the largest rectangular sub-grid that contains only fertile cells. >>> grid = [ ... [1, 0, 1, 1, 1], ... [1, 1, 1, 1, 1], ... [1, 1, 1, 0, 0], ... [0, 1, 1, 0, 1], ...
def maximalRectangle(matrix): if not matrix or not matrix[0]: return 0 max_area = 0 n = len(matrix) m = len(matrix[0]) heights = [0] * m for i in range(n): for j in range(m): if matrix[i][j] == 1: heights[j] += 1 else: ...
def test_example_case(): grid = [ [1, 0, 1, 1, 1], [1, 1, 1, 1, 1], [1, 1, 1, 0, 0], [0, 1, 1, 0, 1], [0, 0, 1, 1, 1] ] assert largest_fertile_subgrid(5, grid) == 6 def test_all_fertile(): grid = [ [1, 1, 1], [1, 1, 1], [1, 1, 1] ] ...
[ { "docstring": null, "function_declaration": "def maximalRectangle(matrix):", "function_name": "maximalRectangle", "parameter_list": "(matrix)" }, { "docstring": null, "function_declaration": "def largestRectangleArea(heights):", "function_name": "largestRectangleArea", "paramete...
[ 1, 0, 0, 0, 1, 1, 0, 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": "def maximalRectangle(matrix):\n if not matrix or not matrix[0]:\n return 0\n \n max_area = 0\n n = len(matrix)\n m = len(matrix[0])\n ...
trial_gpt4o_0
{ "original_instruction": "A farmer owns an \"n\" x \"n\" grid, represented as a matrix. Each cell in the matrix can either be fertile (represented by 1) or infertile (represented by 0). The farmer can plant crops on any fertile cells. However, he wants to maximize the yield by grouping the fertile cells into the lar...
0.589114
Codeforces_15816
C
[ "maximalRectangle", "largestRectangleArea", "largest_fertile_subgrid" ]
3
[ [ "largest_fertile_subgrid", "maximalRectangle" ], [ "maximalRectangle", "largestRectangleArea" ] ]
2
[]
false
[]
false
pytest
false
[]
true
5496db0526294434ffb7ac2f670608b3e84dfab9
e99e7919b6e2a55848f6bfb358f6597bb7cbffeb
v1.0
complete
Codeforces
Codeforces_16081_C
from typing import List, Tuple def min_moves_to_reach_end(m: int, n: int, grid: List[List[int]]) -> int: """ Determines the minimum number of moves required to traverse from the top-left corner to the bottom-right corner of the m x n grid. Returns -1 if no valid path exists. >>> min_moves_to_reach_en...
from collections import deque def min_moves_to_reach_end(m, n, grid): """ Function to determine the minimum number of moves required to traverse from the top-left corner to the bottom-right corner of the m x n grid. """ if grid[0][0] == 1 or grid[m-1][n-1] == 1: return -1 direction...
def test_min_moves_simple_path(): inputs = """\ 3 3 0 0 1 0 1 0 0 0 0""" assert process_input_and_find_min_moves(inputs) == 4 def test_min_moves_no_path(): inputs = """\ 3 3 0 1 1 1 1 1 0 0 0""" assert process_input_and_find_min_moves(inputs) == -1 def test_min_moves_start_blocked(): inputs = """\...
[ { "docstring": "Function to determine the minimum number of moves required to traverse\nfrom the top-left corner to the bottom-right corner of the m x n grid.", "function_declaration": "def min_moves_to_reach_end(m, n, grid):", "function_name": "min_moves_to_reach_end", "parameter_list": "(m, n, gri...
[ 1, 1, 1, 0, 1, 1, 0, 1, 0 ]
6
easy
0.667
{ "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_moves_to_reach_end(grid):\n m = len(grid)\n n = len(grid[0])\n \n if grid[0][0] == 1 or grid[m-1][n-1] ==...
trial_gpt4o_7
{ "original_instruction": "You are given a board game with a rectangular grid of size m × n. Each cell in the grid can either be empty (represented by 0) or contain an obstacle (represented by 1). You are given the following task:\n\nDetermine the minimum number of moves required to traverse from the top-left corner ...
0.673364
Codeforces_16081
C
[ "min_moves_to_reach_end", "process_input_and_find_min_moves" ]
2
[ [ "process_input_and_find_min_moves", "min_moves_to_reach_end" ] ]
1
[]
false
[]
false
pytest
false
[]
true
fc0ad31fedab2238cb492bdb31a736637436d297
f2feec60f4821e3e5fbb831375555c7046b98128
v1.0
complete
Codeforces
Codeforces_15964_C
from typing import List, Tuple def grand_function(test_cases: List[Tuple[int, int, str, List[Tuple[int, int, int]]]]) -> List[str]: """ Determines if the final string after all operations is a palindrome. >>> grand_function([(7, 2, "abcdeed", [(2, 4, 1), (3, 7, 2)])]) ["NO"] >>> grand_function([(5...
def is_palindrome(s): return s == s[::-1] def rotate_substring(s, l, r, k): k = k % (r - l + 1) if k != 0: return s[:l] + s[r-k+1:r+1] + s[l:r-k+1] + s[r+1:] return s def process_test_case(n, q, s, queries): for l, r, k in queries: s = rotate_substring(s, l-1, r-1, k) return "Y...
from solution import grand_function def test_process_test_case_example_1(): test_cases = [ (7, 2, "abcdeed", [(2, 4, 1), (3, 7, 2)]) ] assert grand_function(test_cases) == ["NO"] def test_process_test_case_example_2(): test_cases = [ (5, 3, "axaxa", [(1, 5, 3), (2, 4, 1), (1, 3, 1)]) ...
[ { "docstring": null, "function_declaration": "def is_palindrome(s):", "function_name": "is_palindrome", "parameter_list": "(s)" }, { "docstring": null, "function_declaration": "def rotate_substring(s, l, r, k):", "function_name": "rotate_substring", "parameter_list": "(s, l, r, k...
[ 1, 0, 0, 0, 0, 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 rotate_substring(s, l, r, k):\n \"\"\"\n Rotate the substring from l to r (inclusive) to the right by k positions.\n \"\"\"\n l -= 1 # adjust...
trial_gpt4o_6
{ "original_instruction": "Selena has a string of length $$$n$$$ consisting of lowercase English letters. Each day for $$$q$$$ days, she performs a string operation involving substring queries and transformations. On the $$$i$$$-th day, she is given three integers: $$$l_i$$$, $$$r_i$$$, and $$$k_i$$$.\n\nThe operatio...
0.698832
Codeforces_15964
C
[ "is_palindrome", "rotate_substring", "process_test_case", "grand_function" ]
4
[ [ "grand_function", "process_test_case" ], [ "process_test_case", "is_palindrome" ], [ "process_test_case", "rotate_substring" ] ]
3
[ "process_test_case" ]
false
[]
false
pytest
true
[]
true
564da8b7825a20d47c6e3b51dbdcd1e3631538f2
10330948be849b6a1cfdc7707c672a45f7aabe15
v1.0
complete
Codeforces
Codeforces_16248_C
def calculate_bill(customer_type: str, usage: int) -> float: """ Calculate the total bill for a customer based on their type and usage. Args: customer_type (str): Type of the customer (Residential, Commercial, Industrial). usage (int): Monthly usage amount. Returns: float: Total bill amoun...
def calculate_bill(customer_type, usage): """ Calculate the total bill for a customer based on their type and usage. """ if customer_type == 'Residential': base_rate = 15.00 rate_per_unit = 0.05 total_cost = base_rate + (rate_per_unit * usage) elif customer_type == 'Commercia...
from solution import calculate_bill, generate_bills def test_calculate_bill_residential(): assert calculate_bill('Residential', 100) == 20.00 assert calculate_bill('Residential', 0) == 15.00 assert calculate_bill('Residential', 2000) == 115.00 def test_calculate_bill_commercial(): assert calculate_bil...
[ { "docstring": "Calculate the total bill for a customer based on their type and usage.", "function_declaration": "def calculate_bill(customer_type, usage):", "function_name": "calculate_bill", "parameter_list": "(customer_type, usage)" }, { "docstring": "Generate bills for a list of customer...
[ 0, 0, 1, 1, 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 calculate_bill(customer_type, usage):\n if customer_type == \"Residential\":\n base_rate = 15.00\n unit_rate = 0.05\n bill = base_...
trial_gpt4o_9
{ "original_instruction": "Billing System Simulations\n\nYou are hired to design a simplified billing system for a new utility service provider. The company wants to be able to add customers and generate monthly bills based on their usage.\n\nThere are three types of customers: **Residential**, **Commercial**, and **...
0.630286
Codeforces_16248
C
[ "calculate_bill", "generate_bills" ]
2
[ [ "generate_bills", "calculate_bill" ] ]
1
[]
false
[]
false
pytest
true
[]
true
8ab248ac47e5475675ae84adb108aac54f14530d
00c764b55a12ac8474ed83485d3d31ad2ece6efc
v1.0
complete
Codeforces
Codeforces_16287_C
from typing import List, Tuple def solve(test_cases: List[Tuple[int, List[Tuple[int, int]]]]) -> List[int]: """Find the diameter of a tree represented as a list of edges for each test case. Args: test_cases (List[Tuple[int, List[Tuple[int, int]]]]): A list of test cases, where each test case is repres...
from collections import deque def find_furthest_node(n, edges, start_node): """ Finds the furthest node from the start_node and its distance in an unweighted tree. """ graph = {i: [] for i in range(1, n + 1)} for u, v in edges: graph[u].append(v) graph[v].append(u) visited = [F...
from solution import solve def test_tree_diameter_single_case(): assert solve([(4, [(1, 2), (2, 3), (2, 4)])]) == [2] assert solve([(3, [(1, 2), (1, 3)])]) == [2] def test_tree_diameter_multiple_cases(): assert solve([ (4, [(1, 2), (2, 3), (2, 4)]), (3, [(1, 2), (1, 3)]) ]) == [2, 2] ...
[ { "docstring": "Finds the furthest node from the start_node and its distance in an unweighted tree.", "function_declaration": "def find_furthest_node(n, edges, start_node):", "function_name": "find_furthest_node", "parameter_list": "(n, edges, start_node)" }, { "docstring": "Finds the diamet...
[ 0, 0, 1, 0, 1, 0, 1, 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 tree_diameter(edges, n):\n from collections import defaultdict, deque\n\n def bfs(start_node):\n queue = deque([start_node])\n distanc...
trial_gpt4o_3
{ "original_instruction": "Consider an undirected tree with `n` nodes, where each node is uniquely numbered from `1` to `n`. The diameter of a tree is the length of the longest path between any two nodes in the tree. A path length is defined by the number of edges in that path.\n\nYou are given the tree represented a...
0.60775
Codeforces_16287
C
[ "find_furthest_node", "tree_diameter", "solve" ]
3
[ [ "solve", "tree_diameter" ], [ "tree_diameter", "find_furthest_node" ] ]
2
[]
false
[]
false
pytest
true
[]
true
db91df2585716584f444b647bb7d2394dd7c1d4b
4b708286a6496e2d0c8c3a2a666f0e1595d39025
v1.0
complete
Codeforces
Codeforces_16417_C
from typing import List def is_fibonacci(n: int) -> bool: """ Determines if an integer n is a Fibonacci number. >>> is_fibonacci(0) == True >>> is_fibonacci(1) == True >>> is_fibonacci(2) == True >>> is_fibonacci(3) == True >>> is_fibonacci(4) == False >>> is_fibonacci(5) == True >...
def is_fibonacci(n): """ Determines if an integer n is a Fibonacci number. """ if n == 0: return True x, y = 0, 1 while y <= n: if y == n: return True x, y = y, x + y return False def check_fibonacci_numbers(numbers): """ Takes a list of numbers a...
from solution import check_fibonacci_numbers, is_fibonacci def test_is_fibonacci(): assert is_fibonacci(0) == True assert is_fibonacci(1) == True assert is_fibonacci(2) == True assert is_fibonacci(3) == True assert is_fibonacci(4) == False assert is_fibonacci(5) == True assert is_fibonacci(...
[ { "docstring": "Determines if an integer n is a Fibonacci number.", "function_declaration": "def is_fibonacci(n):", "function_name": "is_fibonacci", "parameter_list": "(n)" }, { "docstring": "Takes a list of numbers and returns a corresponding list of \"YES\" or \"NO\" \nindicating whether e...
[ 1, 1, 1, 1, 1, 1, 0, 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 is_perfect_square(x):\n \"\"\"\n Helper function to check if x is a perfect square.\n \"\"\"\n s = int(x**0.5)\n return s*s == x\n\ndef is_...
trial_gpt4o_7
{ "original_instruction": "Dr. Fibonacci frequently works with large Fibonacci numbers in his research. As part of his analysis, he often needs to determine if a given number is a Fibonacci number. The sequence of Fibonacci numbers is defined as follows: the first two terms are zero and one, and each subsequent term ...
0.770611
Codeforces_16417
C
[ "is_fibonacci", "check_fibonacci_numbers" ]
2
[ [ "check_fibonacci_numbers", "is_fibonacci" ] ]
1
[]
false
[]
false
pytest
true
[]
true
80866fc62316a2104c5ca76492d00be1fcfb0706
2ba2385e0c09c0b0849168d9d9c2925861e45563
v1.0
complete
Codeforces
Codeforces_16395_C
from typing import List, Tuple def update_grid(n: int, m: int, initial_grid: List[List[int]], updates: List[Tuple[int, int, int]]) -> List[List[int]]: """ Update the grid based on the given updates. >>> update_grid(3, 3, [[1, 2, 3], [4, 5, 6], [7, 8, 9]], [(1, 1, 10), (2, 3, -5), (3, 2, 0), (1, 2, 15)]) ...
def update_grid(n, m, initial_grid, updates): for row, col, value in updates: initial_grid[row-1][col-1] = value return initial_grid def perform_grid_operations(n, m, initial_grid, q, update_queries): updated_grid = update_grid(n, m, initial_grid, update_queries) return updated_grid
from solution import update_grid, perform_grid_operations def test_single_update(): n, m = 3, 3 initial_grid = [ [1, 2, 3], [4, 5, 6], [7, 8, 9] ] updates = [(1, 1, 10)] expected_grid = [ [10, 2, 3], [4, 5, 6], [7, 8, 9] ] assert update_grid(n...
[ { "docstring": null, "function_declaration": "def update_grid(n, m, initial_grid, updates):", "function_name": "update_grid", "parameter_list": "(n, m, initial_grid, updates)" }, { "docstring": null, "function_declaration": "def perform_grid_operations(n, m, initial_grid, q, update_queri...
[ 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 update_grid(n, m, grid, queries):\n \"\"\"\n Updates the grid based on the given queries and returns the final state of the grid.\n \n Paramet...
trial_gpt4o_9
{ "original_instruction": "You are given a grid with dimensions $$$n \\times m$$$ initially filled with numbers. You need to perform the following query operation multiple times:\n\n1. Update the value of the cell at position (row, col) to a new value specified.\n\nAfter all the updates, return the current state of t...
0.617056
Codeforces_16395
C
[ "update_grid", "perform_grid_operations" ]
2
[ [ "perform_grid_operations", "update_grid" ] ]
1
[]
false
[]
false
pytest
true
[]
true
70784040f3701c987e130a0b14945c71fb051bbe
7ddc6acdf0cef94f86ecfef3a0e8f969bbb6a7c6
v1.0
complete
Codeforces
Codeforces_16396_C
from typing import List, Tuple def are_they_connected(N: int, M: int, transporter_pairs: List[Tuple[int, int]], Q: int, queries: List[Tuple[int, int]]) -> List[str]: """ Determines if there exists a functional way to travel between given pairs of planets using the operable transporters. Args: N (...
from collections import defaultdict, deque def build_graph(N, transporter_pairs): graph = defaultdict(list) for u, v in transporter_pairs: graph[u].append(v) graph[v].append(u) return graph def bfs_connected_components(graph, N): visited = [False] * (N + 1) components = [-1] * (N +...
def test_basic_functionality(): N = 5 M = 3 transporter_pairs = [(1, 2), (2, 3), (4, 5)] Q = 2 queries = [(1, 3), (1, 5)] expected_output = ["YES", "NO"] assert are_they_connected(N, M, transporter_pairs, Q, queries) == expected_output def test_single_query(): N = 3 M = 1 transp...
[ { "docstring": null, "function_declaration": "def build_graph(N, transporter_pairs):", "function_name": "build_graph", "parameter_list": "(N, transporter_pairs)" }, { "docstring": null, "function_declaration": "def bfs_connected_components(graph, N):", "function_name": "bfs_connected...
[ 1, 1, 1, 1, 1, 1, 1, 1, 0, 0 ]
8
easy
0.8
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_connected(N, M, transporters, Q, queries):\n \"\"\"\n Determines if there exists a functional way to travel between given pairs of planets.\n ...
trial_gpt4o_7
{ "original_instruction": "In a distant galaxy, there are $$$N$$$ planets numbered from $$$1$$$ to $$$N$$$. The Intergalactic Transport Authority (ITA) has afforded the citizens modern transporters to travel between planets. Each planet has exactly one transporter, and each transporter is capable of connecting to exa...
0.657236
Codeforces_16396
C
[ "build_graph", "bfs_connected_components", "are_they_connected" ]
3
[ [ "are_they_connected", "bfs_connected_components" ], [ "are_they_connected", "build_graph" ] ]
2
[]
false
[]
false
pytest
false
[]
true
19f32769986784471071ecd6a1c1ea80605faac7
50e9edd4eb84dc898b3aa9d71dd29d0f87624ae1
v1.0
complete
Codeforces
Codeforces_16409_C
def compress_and_calculate_product(arr): """ Compresses the array by multiplying consecutive identical elements. >>> compress_and_calculate_product([2, 2, 3]) [4, 3] >>> compress_and_calculate_product([2, 3, 3, 3]) [2, 27] >>> compress_and_calculate_product([1, 2, 2, 1]) [1, 4, 1] >>> compress_and_c...
def compress_and_calculate_product(arr): compressed = [] current_product = 1 current_value = arr[0] # start with the first element for elem in arr: if elem == current_value: current_product *= elem else: compressed.append(current_product) current_prod...
def test_compress_and_calculate_product(): assert compress_and_calculate_product([2, 2, 3]) == [4, 3] assert compress_and_calculate_product([2, 3, 3, 3]) == [2, 27] assert compress_and_calculate_product([1, 2, 2, 1]) == [1, 4, 1] assert compress_and_calculate_product([5]) == [5] def test_can_transform_...
[ { "docstring": null, "function_declaration": "def compress_and_calculate_product(arr):", "function_name": "compress_and_calculate_product", "parameter_list": "(arr)" }, { "docstring": null, "function_declaration": "def can_transform_equal(A, B):", "function_name": "can_transform_equa...
[ 0, 0, 0, 1, 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": "def can_transform(a, b):\n \"\"\"\n Determines if arrays 'a' and 'b' can be made equal by repeated subsegment product operations.\n \n Args:\n ...
trial_gpt4o_3
{ "original_instruction": "You are given two arrays $$$A$$$ and $$$B$$$ of lengths $$$n$$$ and $$$m$$$, respectively. Arrays can only contain positive integers.\n\nYou can perform the following operation an arbitrary number of times: pick any subsegment of the array and replace it with its product. For example, from ...
0.622155
Codeforces_16409
C
[ "compress_and_calculate_product", "can_transform_equal", "check_arrays_equal" ]
3
[ [ "can_transform_equal", "compress_and_calculate_product" ], [ "check_arrays_equal", "can_transform_equal" ] ]
2
[]
false
[]
false
pytest
false
[]
true
80a9e3a40282b4b1ea8e2a63aca6c99c71db36c8
a91a1824b55fb48ab356d3a5168281154c7d1ec9
v1.0
complete
Codeforces
Codeforces_16567_C
from typing import List def max_subarray_sum(arr: List[int]) -> int: """ Find the contiguous subarray (containing at least one number) which has the largest sum and return this sum using a divide-and-conquer approach. >>> max_subarray_sum([-2, 1, -3, 4, -1, 2, 1, -5, 4]) 6 >>> max_subarr...
from typing import List def max_crossing_sum(arr: List[int], left: int, mid: int, right: int) -> int: # Include elements on the left of mid left_sum = float('-inf') total = 0 for i in range(mid, left - 1, -1): total += arr[i] if total > left_sum: left_sum = total # ...
from solution import max_subarray_sum def test_example_case(): assert max_subarray_sum([-2, 1, -3, 4, -1, 2, 1, -5, 4]) == 6 def test_single_element(): assert max_subarray_sum([1]) == 1 assert max_subarray_sum([-1]) == -1 def test_all_negative(): assert max_subarray_sum([-2, -3, -1, -5]) == -1 def t...
[ { "docstring": null, "function_declaration": "def max_crossing_sum(arr, left, mid, right):", "function_name": "max_crossing_sum", "parameter_list": "(arr, left, mid, right)" }, { "docstring": null, "function_declaration": "def max_subarray_sum_util(arr, left, right):", "function_name...
[ 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\n\ndef max_crossing_sum(arr, left, mid, right):\n # Include elements on the left of mid.\n sm = 0\n left_sum = float('-inf')\...
trial_gpt4o_9
{ "original_instruction": "You are given a list of integers. Your task is to find the contiguous subarray (containing at least one number) which has the largest sum and return this sum. Implement the function using a divide-and-conquer approach.\n\nFor example, given the array `arr = [-2, 1, -3, 4, -1, 2, 1, -5, 4]`,...
0.782788
Codeforces_16567
C
[ "max_crossing_sum", "max_subarray_sum_util", "max_subarray_sum" ]
3
[ [ "max_subarray_sum", "max_subarray_sum_util" ], [ "max_subarray_sum_util", "max_crossing_sum" ] ]
2
[]
false
[]
false
pytest
true
[]
true
d9ff564b73a3105ab784227e1e3184749d01c20f
a649bff520a6f7426b0ea078753173af4dde8ac2
v1.0
complete
Codeforces
Codeforces_16755_C
from typing import List def calculate_word_value(word: str) -> int: """Calculate the value of a word based on the position of its letters in the alphabet. >>> calculate_word_value("abcd") 10 >>> calculate_word_value("bcda") 10 >>> calculate_word_value("xyz") 75 """ pass def cou...
def calculate_word_value(word): return sum(ord(char) - ord('a') + 1 for char in word) def count_special_synonym_pairs(words): from collections import defaultdict word_value_counts = defaultdict(int) for word in words: value = calculate_word_value(word) word_value_counts[value]...
from solution import calculate_word_value, count_special_synonym_pairs def test_calculate_word_value(): assert calculate_word_value("abcd") == 1 + 2 + 3 + 4 assert calculate_word_value("bcda") == 2 + 3 + 4 + 1 assert calculate_word_value("xyz") == 24 + 25 + 26 def test_count_special_synonym_pairs_case_1()...
[ { "docstring": null, "function_declaration": "def calculate_word_value(word):", "function_name": "calculate_word_value", "parameter_list": "(word)" }, { "docstring": null, "function_declaration": "def count_special_synonym_pairs(words):", "function_name": "count_special_synonym_pairs...
[ 1, 1, 1, 1, 0, 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 calculate_word_value(word):\n \"\"\"\n Returns the sum of values of all characters in the word.\n Each character is valued according to its posit...
trial_gpt4o_9
{ "original_instruction": "In a distant kingdom, there exists a unique language called \"Kingdomese\". This language uses a special alphabet consisting of lowercase English letters, but each letter has a unique value associated with it. The value of each letter is its position in the English alphabet (i.e., 'a' has a...
0.674986
Codeforces_16755
C
[ "calculate_word_value", "count_special_synonym_pairs" ]
2
[ [ "count_special_synonym_pairs", "calculate_word_value" ] ]
1
[]
false
[]
false
pytest
true
[]
true
69ab52afdded5c119c7e79bfa482bae5ea77cfb5
5d4a18f442d92ef8278b94e56ed3b918a03c66f0
v1.0
complete
Codeforces
Codeforces_16786_C
def min_distance_wrapper(n: int, m: int, grid: List[str]) -> int: """ Calculate the minimum distance one needs to travel from the top-left corner of the grid to the bottom-right corner. If there is no valid path, return -1. Args: n (int): Number of rows in the grid. m (int): Number of columns in th...
from collections import deque def min_distance(city_map, n, m): if city_map[0][0] == '#' or city_map[n-1][m-1] == '#': return -1 directions = [(0, 1), (1, 0), (0, -1), (-1, 0)] queue = deque([(0, 0, 0)]) # (row, col, distance) visited = set((0, 0)) while queue: x, y, dist = q...
from solution import min_distance_wrapper def test_min_distance_general_case(): grid = [ ".....", ".###.", "...#.", ".#...", "....." ] assert min_distance_wrapper(5, 5, grid) == 8 def test_min_distance_no_path(): grid = [ ".#.", ".#.", "....
[ { "docstring": null, "function_declaration": "def min_distance(city_map, n, m):", "function_name": "min_distance", "parameter_list": "(city_map, n, m)" }, { "docstring": null, "function_declaration": "def min_distance_wrapper(n, m, grid):", "function_name": "min_distance_wrapper", ...
[ 0, 1, 1, 0, 1, 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": "from collections import deque\n\ndef min_distance(n, m, grid):\n # Directions for moving up, down, left, right\n directions = [(-1, 0), (1, 0), (0, -1),...
trial_gpt4o_8
{ "original_instruction": "You are given a road map of a city in the form of a grid. Each cell in the grid can either be empty or have a building. You can only walk on the empty cells. You CANNOT walk through or on the buildings.\n\nThe objective is to calculate the minimum distance one needs to travel from the top-l...
0.625681
Codeforces_16786
C
[ "min_distance", "min_distance_wrapper" ]
2
[ [ "min_distance_wrapper", "min_distance" ] ]
1
[]
false
[]
false
pytest
true
[]
true
3fcdd8d9dc34276eb6bfae8b29cd2fdeefd3ddcb
a0a28493be8c7e7a7ecb877775cd0515e6007507
v1.0
complete
Codeforces
Codeforces_16774_C
def sum_of_digits(num): """ Returns the sum of digits of a number. >>> sum_of_digits(246) 12 >>> sum_of_digits(1234) 10 >>> sum_of_digits(0) 0 >>> sum_of_digits(8888) 32 """ pass # Implement the function here def is_special_identifier(identifier): """ Checks if ...
def sum_of_digits(num): """ Returns the sum of digits of a number. """ return sum(int(digit) for digit in str(num)) def is_special_identifier(identifier): """ Checks if an identifier is special. """ identifier_str = str(identifier) if any(int(digit) % 2 != 0 for digit in identifier_...
def test_sum_of_digits(): assert sum_of_digits(246) == 12 assert sum_of_digits(1234) == 10 assert sum_of_digits(0) == 0 assert sum_of_digits(8888) == 32 def test_is_special_identifier(): assert is_special_identifier(246) == True assert is_special_identifier(248) == True assert is_special_id...
[ { "docstring": "Returns the sum of digits of a number.", "function_declaration": "def sum_of_digits(num):", "function_name": "sum_of_digits", "parameter_list": "(num)" }, { "docstring": "Checks if an identifier is special.", "function_declaration": "def is_special_identifier(identifier):...
[ 1, 0, 0, 0, 0, 0, 0, 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 sum_of_digits(num):\n \"\"\"\n Returns the sum of digits of a number.\n \"\"\"\n return sum(int(digit) for digit in s...
trial_gpt4o_1
{ "original_instruction": "In AntLand, there is a unique numbering system for the lands governed by different leaders. Each land is represented by a unique integer identifier. A land identifier is considered \"special\" if it meets the following criteria:\n\n1. The sum of its digits is equal to the sum of its reverse...
0.691561
Codeforces_16774
C
[ "sum_of_digits", "is_special_identifier", "generate_special_identifiers", "main" ]
4
[ [ "generate_special_identifiers", "is_special_identifier" ], [ "is_special_identifier", "sum_of_digits" ] ]
2
[]
false
[]
false
pytest
false
[]
true
76c936390b9cb896e73768d7f60ea8638c31b8da
6381486ca3db600d414304eb8cbb31bcb3076a11
v1.0
complete
Codeforces
Codeforces_16441_C
from typing import List, Tuple 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] > ra...
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[yroot]...
def test_minimum_cost_to_connect_villages(): roads1 = [ (1, 2, 10), (1, 3, 15), (1, 4, 20), (2, 3, 35), (3, 4, 25) ] assert minimum_cost_to_connect_villages(4, roads1) == 45 roads2 = [ (1, 2, 1), (2, 3, 1), (3, 4, 1), (4, 5, 1), ...
[ { "docstring": null, "function_declaration": "def find(parent, i):", "function_name": "find", "parameter_list": "(parent, i)" }, { "docstring": null, "function_declaration": "def union(parent, rank, x, y):", "function_name": "union", "parameter_list": "(parent, rank, x, y)" }, ...
[ 1, 0, 1, 0, 1, 1, 0, 0, 0, 0 ]
4
medium
0.4
{ "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 return find(parent, parent[i])\n\ndef union(parent, rank, x, y):\n root_x = find(parent...
trial_gpt4o_5
{ "original_instruction": "In a fictional land called Matrixia, there are n villages connected by m bidirectional roads such that you can travel between any pair of villages. Each road has a certain travel cost and is represented in the list of m roads. The villagers of Matrixia want to improve their travel system by...
0.63357
Codeforces_16441
C
[ "find", "union", "kruskal", "minimum_cost_to_connect_villages" ]
4
[ [ "kruskal", "find" ], [ "kruskal", "union" ], [ "minimum_cost_to_connect_villages", "kruskal" ], [ "union", "find" ] ]
4
[]
false
[]
false
pytest
false
[]
true
e65c45e49a5569708851d7d957749b7558c993fb
4f0e41e17ad9857bcdd497c97a527ded3b4567bb
v1.0
complete
Codeforces
Codeforces_16472_C
def unique_paths_with_obstacles(grid: List[List[int]]) -> int: """ Returns the number of unique paths from top-left to bottom-right corner of the grid. Parameters: grid (List[List[int]]): The grid with obstacles (1) and empty spaces (0). Returns: int: The number of unique paths modulo 10^9 + 7...
def unique_paths_with_obstacles(grid): """ Returns the number of unique paths from top-left to bottom-right corner of the grid. Parameters: grid (List[List[int]]): The grid with obstacles (1) and empty spaces (0). Returns: int: The number of unique paths modulo 10^9 + 7. """ MOD = 10**...
from solution import solve def test_example_case(): input_str = "3 3\n0 0 0\n0 1 0\n0 0 0" assert solve(input_str) == 2 def test_case_no_obstacle(): input_str = "3 3\n0 0 0\n0 0 0\n0 0 0" assert solve(input_str) == 6 def test_case_start_obstacle(): input_str = "3 3\n1 0 0\n0 0 0\n0 0 0" asser...
[ { "docstring": "Returns the number of unique paths from top-left to bottom-right corner of the grid.\n\nParameters:\ngrid (List[List[int]]): The grid with obstacles (1) and empty spaces (0).\n\nReturns:\nint: The number of unique paths modulo 10^9 + 7.", "function_declaration": "def unique_paths_with_obstac...
[ 0, 1, 0, 1, 1, 1, 0, 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": "MOD = 10**9 + 7\n\ndef unique_paths_with_obstacles(grid):\n m = len(grid)\n n = len(grid[0])\n \n if grid[0][0] == 1 or grid[m-1][n-1] == 1:\n ...
trial_gpt4o_9
{ "original_instruction": "You are given a rectangular grid of blocks with dimensions m (rows) by n (columns). Each block in the grid can either be empty or contain an obstacle. You are currently located at the top-left corner of the grid (position (0,0)) and your goal is to move to the bottom-right corner of the gri...
0.724292
Codeforces_16472
C
[ "unique_paths_with_obstacles", "parse_input", "solve" ]
3
[ [ "solve", "parse_input" ], [ "solve", "unique_paths_with_obstacles" ] ]
2
[ "parse_input" ]
false
[]
false
pytest
true
[]
true
c0a6980217ff568aa40e453f5772feb508598e2a
c3a477a065944ddf1d3b70476eeef776eda6de10
v1.0
complete
Codeforces
Codeforces_16570_C
from typing import List, Tuple def swap_and_level_order(n: int, parent_list: List[int], children: List[Tuple[int, int]]) -> List[int]: """ Given a binary tree with n nodes, each node having a unique value between 1 and n, swap all the left and right children of every node in the tree and output the level-order...
from collections import deque, defaultdict class TreeNode: def __init__(self, val): self.val = val self.left = None self.right = None def build_tree(n, parent_list, children): nodes = [TreeNode(i) for i in range(1, n+1)] root = None for i in range(n): if parent_lis...
from solution import swap_and_level_order def test_example_case(): n = 5 parent_list = [-1, 1, 1, 2, 2] children = [ (2, 3), (4, 5), (0, 0), (0, 0), (0, 0) ] assert swap_and_level_order(n, parent_list, children) == [1, 3, 2, 5, 4] def test_single_node(): ...
[]
[ 1, 1, 1, 0, 0, 0, 1, 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": "from collections import defaultdict, deque\n\ndef swap_children_and_level_order_traversal(n, parent, children):\n tree = defaultdict(lambda: [None, None])\...
trial_gpt4o_1
{ "original_instruction": "You are given a binary tree with n nodes, each node having a unique value between 1 and n. Your task is to swap all the left and right children of every node in the tree and then output the level-order traversal of the modified tree.\n\nThe first line contains an integer n (1 ≤ n ≤ 10^5) — ...
0.529811
Codeforces_16570
C
[ "build_tree", "swap_children", "level_order_traversal", "swap_and_level_order" ]
4
[ [ "swap_and_level_order", "build_tree" ], [ "swap_and_level_order", "level_order_traversal" ], [ "swap_and_level_order", "swap_children" ] ]
3
[]
false
[ "TreeNode" ]
true
pytest
true
[]
true
0874acf0da6bbc0c9a49af474c800614fee1307a
7387a57e72f2ad0ffa9a519939c3181d5cc33fba
v1.0
complete
Codeforces
Codeforces_16793_C
class TreeNode: def __init__(self, key): self.left = None self.right = None self.val = key def insertLevelOrder(arr, root, i, n): # Base case for recursion if i < n: temp = TreeNode(arr[i]) root = temp # insert left child root.left = insertLevelOrder(...
class TreeNode: def __init__(self, key): self.left = None self.right = None self.val = key def insertLevelOrder(arr, root, i, n): # Base case for recursion if i < n: temp = TreeNode(arr[i]) root = temp # insert left child root.left = insertLevelOrder(...
from solution import compute_tree_height def test_tree_height_1(): n = 5 seq = [3, 9, 20, 15, 7] assert compute_tree_height(n, seq) == 2 def test_tree_height_2(): n = 0 seq = [] assert compute_tree_height(n, seq) == -1 def test_tree_height_3(): n = 1 seq = [1] assert compute_tree_...
[]
[ 1, 0, 0, 1, 1, 1, 0, 0, 0, 0 ]
4
medium
0.4
{ "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_4
{ "original_instruction": "You are given a sequence of integers where you need to construct a binary tree. Each integer corresponds to a node, and the sequence dictates the structure and the order of the nodes to be inserted into the binary tree.\n\nThe sequence is given in level order traversal format, where each nu...
0.548577
Codeforces_16793
C
[ "insertLevelOrder", "height", "compute_tree_height" ]
3
[ [ "compute_tree_height", "height" ], [ "compute_tree_height", "insertLevelOrder" ] ]
2
[]
false
[ "TreeNode" ]
true
pytest
true
[]
true
31903269c6f16934bbe4bfb7fcc1d1e06884698b
a831cfcdb87b044bb679cc2792c12fe773fecd30
v1.0
complete
Codeforces
Codeforces_16622_C
from typing import List, Tuple def shortest_distances_to_treasures(n: int, m: int, sx: int, sy: int, grid: List[str], treasures: List[Tuple[int, int]]) -> List[int]: """ Determines the shortest distance from the submarine's starting position to each treasure chest. Parameters: n (int): Number of rows ...
from collections import deque def bfs_shortest_distance(n, m, grid, sx, sy): directions = [(-1, 0), (1, 0), (0, -1), (0, 1)] distances = [[-1 for _ in range(m)] for _ in range(n)] queue = deque([(sx, sy)]) distances[sx][sy] = 0 while queue: x, y = queue.popleft() for d...
def test_shortest_distances(): n = 5 m = 5 sx = 1 sy = 1 grid = [ ".....", "..#..", ".....", ".###.", "....." ] treasures = [(3, 3), (5, 5), (1, 5)] expected_output = [4, 8, 4] result = shortest_distances_to_treasures(n, m, sx, sy, grid, t...
[ { "docstring": null, "function_declaration": "def bfs_shortest_distance(n, m, grid, sx, sy):", "function_name": "bfs_shortest_distance", "parameter_list": "(n, m, grid, sx, sy)" }, { "docstring": null, "function_declaration": "def shortest_distances_to_treasures(n, m, sx, sy, grid, treas...
[ 0, 1, 0, 1, 0, 1, 0, 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 deque\n\ndef shortest_path(n, m, sx, sy, grid, treasures):\n directions = [(0, 1), (1, 0), (0, -1), (-1, 0)]\n \n def bfs(sx,...
trial_gpt4o_8
{ "original_instruction": "You are the captain of a submarine exploration mission. Your mission involves navigating through a grid of underwater cells. Each cell in the grid can either be an open water cell or an obstacle. Your submarine can move one cell at a time in any of the four directions (up, down, left, or ri...
0.61125
Codeforces_16622
C
[ "bfs_shortest_distance", "shortest_distances_to_treasures" ]
2
[ [ "shortest_distances_to_treasures", "bfs_shortest_distance" ] ]
1
[]
false
[]
false
pytest
false
[]
true
1ce24bd7608468ff2234846cc4d08e472dc837ad
75cccb865e44e37d80cd60303863bac71f06a19b
v1.0
complete
Codeforces
Codeforces_16845_C
class TreeNode: def __init__(self, value): self.value = value self.children = [] def is_balanced_binary_tree(n: int, edges: List[Tuple[int, int]]) -> str: """ Given a binary tree, determine if it is balanced or not. A binary tree is considered balanced if the depth of the two subtrees of ev...
class TreeNode: def __init__(self, value): self.value = value self.children = [] def build_tree(n, edges): nodes = {i: TreeNode(i) for i in range(1, n+1)} for u, v in edges: nodes[u].children.append(nodes[v]) nodes[v].children.append(nodes[u]) return nodes def is_balanc...
from solution import is_balanced_binary_tree def test_simple_balanced_tree(): n = 5 edges = [(1, 2), (1, 3), (2, 4), (2, 5)] assert is_balanced_binary_tree(n, edges) == "YES" def test_simple_unbalanced_tree(): n = 5 edges = [(1, 2), (1, 3), (3, 4), (4, 5)] assert is_balanced_binary_tree(n, edg...
[]
[ 1, 1, 1, 0, 0, 0, 0, 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": "class TreeNode:\n def __init__(self, val=0):\n self.val = val\n self.left = None\n self.right = None\n\ndef create_tree(edges):\n f...
trial_gpt4o_8
{ "original_instruction": "Given a binary tree, you need to determine if it is balanced or not. A binary tree is considered balanced if the depth of the two subtrees of every node never differs by more than 1.\n\nThe first line of input contains an integer, $$$n$$$, which represents the number of nodes in the binary ...
0.790128
Codeforces_16845
C
[ "build_tree", "is_balanced_tree", "is_balanced_binary_tree" ]
3
[ [ "is_balanced_binary_tree", "build_tree" ], [ "is_balanced_binary_tree", "is_balanced_tree" ] ]
2
[]
false
[ "TreeNode" ]
true
pytest
true
[]
true
faf9159ee07b6c9860258f5004fdbb5376289977
c628119ad98b0a9b8175732dc2cc3cb76cb8f979
v1.0
complete
Codeforces
Codeforces_16631_C
def build_tree(n, edges): """ Builds an adjacency list representation of the tree. :param n: int - the number of castles :param edges: List[Tuple[int, int, int]] - the list of edges in the format (u, v, w) :return: dict - adjacency list of the tree """ pass from collections import deque d...
import sys from collections import defaultdict, deque def build_tree(n, edges): tree = defaultdict(list) for u, v, w in edges: tree[u].append((v, w)) tree[v].append((u, w)) return tree def bfs_with_distances(tree, start): distances = {} queue = deque([(start, 0)]) visited = set...
def test_build_tree(): edges = [(1, 2, 3), (1, 3, 2), (3, 4, 4), (3, 5, 6)] tree = build_tree(5, edges) expected_tree = { 1: [(2, 3), (3, 2)], 2: [(1, 3)], 3: [(1, 2), (4, 4), (5, 6)], 4: [(3, 4)], 5: [(3, 6)] } assert tree == expected_tree def test_bfs_with_...
[ { "docstring": null, "function_declaration": "def build_tree(n, edges):", "function_name": "build_tree", "parameter_list": "(n, edges)" }, { "docstring": null, "function_declaration": "def bfs_with_distances(tree, start):", "function_name": "bfs_with_distances", "parameter_list":...
[ 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, defaultdict\n\ndef bfs(tree, n, start):\n distances = [-1] * (n + 1)\n distances[start] = 0\n queue = deque([start])\n...
trial_gpt4o_4
{ "original_instruction": "In a distant kingdom, there are **n** castles connected by **n-1** roads, forming a magical tree. Each road has a specific length measured in miles. The kingdom's queen, who loves travelling, wants to visit some of these castles. She has a certain number of travel requests.\n\nEach travel r...
0.645192
Codeforces_16631
C
[ "build_tree", "bfs_with_distances", "process_queries", "main" ]
4
[ [ "process_queries", "bfs_with_distances" ], [ "process_queries", "build_tree" ] ]
2
[ "process_queries" ]
false
[]
false
pytest
false
[]
true
69f8e1ad086508e71986851e671e8122306b55b9
c74cbe458c53e9de0d48ccf1b6438c820b21d44d
v1.0
complete
Codeforces
Codeforces_17401_C
def rotate_array(arr: List[int], k: int) -> List[int]: """ Rotates the array to the right by k steps. >>> rotate_array([1, 2, 3, 4, 5], 2) [4, 5, 1, 2, 3] >>> rotate_array([1, 2, 3, 4, 5], 0) [1, 2, 3, 4, 5] >>> rotate_array([1, 2, 3, 4, 5], 5) [1, 2, 3, 4, 5] >>> rotate_array([1, 2, 3, ...
def rotate_array(arr, k): """ Rotates the array to the right by k steps. Parameters: arr (list): The array of integers to rotate. k (int): The number of steps to rotate. Returns: list: The rotated array. """ n = len(arr) k = k % n # To handle the case when k is greater...
from solution import rotate_array def test_rotate_array_basic(): assert rotate_array([1, 2, 3, 4, 5], 2) == [4, 5, 1, 2, 3] def test_rotate_array_no_rotation(): assert rotate_array([1, 2, 3, 4, 5], 0) == [1, 2, 3, 4, 5] def test_rotate_array_full_rotation(): assert rotate_array([1, 2, 3, 4, 5], 5...
[ { "docstring": "Rotates the array to the right by k steps.\n\nParameters:\narr (list): The array of integers to rotate.\nk (int): The number of steps to rotate.\n\nReturns:\nlist: The rotated array.", "function_declaration": "def rotate_array(arr, k):", "function_name": "rotate_array", "parameter_li...
[ 1, 1, 1, 1, 1, 0, 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": "def rotate_array(arr, k):\n \"\"\"\n Rotates the array to the right by k steps.\n \n Parameters:\n arr (list): The list of integers to be rotat...
trial_gpt4o_8
{ "original_instruction": "Given an array of integers, rotate the array to the right by k steps, where k is a non-negative integer.\n\nThe first line of the input contains an integer n (1 ≤ n ≤ 10^5), representing the number of elements in the array. The second line of the input contains n space-separated integers, e...
0.6928
Codeforces_17401
C
[ "rotate_array", "process_rotation" ]
2
[ [ "process_rotation", "rotate_array" ] ]
1
[]
false
[]
false
pytest
true
[]
true
36addb0b5db34f868d376dc6f28db128094c50fa
52a53275de62b313b0dc3db56f2e4bb2e613d70b
v1.0
complete
Codeforces
Codeforces_17389_C
from typing import List def find_largest_park_area(R: int, C: int, grid: List[List[int]]) -> int: """ Determine the size of the largest possible park (measured by the number of empty plots) that can be constructed without overlapping trees or houses. :param R: Integer - the number of rows in the...
def largest_park_area(grid): """ This function takes a grid as input and returns the area of the largest rectangle containing only empty plots. :param grid: List of List of integers (0, 1, 2) representing the city grid. :returns: Integer representing the largest possible park area. """ ...
import pytest from solution import find_largest_park_area def test_example_1(): R = 4 C = 5 grid = [ [0, 1, 0, 0, 0], [0, 0, 0, 1, 0], [1, 0, 2, 0, 0], [0, 0, 0, 0, 0] ] assert find_largest_park_area(R, C, grid) == 5 def test_single_row(): R = 1 C = 5 g...
[ { "docstring": "This function takes a grid as input and returns the area of the largest rectangle containing\nonly empty plots.\n\n:param grid: List of List of integers (0, 1, 2) representing the city grid.\n:returns: Integer representing the largest possible park area.", "function_declaration": "def larges...
[ 1, 1, 1, 0, 0, 1, 1, 1, 0 ]
6
easy
0.667
{ "trial_gpt4o_0": null, "trial_gpt4o_1": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared1_results_combined.jsonl", "solution_code": "def max_park_area(R, C, grid):\n if R == 0 or C == 0:\n return 0\n\n max_area = 0\n\n height = [0] * C \n left = [...
trial_gpt4o_8
{ "original_instruction": "A city is represented by a grid (matrix) where each cell can either be an empty plot (0), a tree (1), or a house (2). A person wants to construct a single park, which must be a rectangular sub-grid of cells of size at least 1x1. The park cannot overlap a tree or a house but must include at ...
0.564468
Codeforces_17389
C
[ "largest_park_area", "largest_rect_area_histogram", "find_largest_park_area" ]
3
[ [ "find_largest_park_area", "largest_park_area" ], [ "largest_park_area", "largest_rect_area_histogram" ] ]
2
[]
false
[]
false
pytest
true
[]
true
1b5b88ee2244be0369f86f742a548a8970e993b8
f63fbc81126135c061142f6a1a515e50940d8179
v1.0
complete
Codeforces
Codeforces_17439_C
def is_prime(num: int) -> bool: """ Check if a number is a prime number. >>> is_prime(2) True >>> is_prime(4) False >>> is_prime(11) True """ pass def has_prime_digits(num: int) -> bool: """ Check if all digits of a number are prime digits (2, 3, 5, 7). >>> has_prime...
def is_prime(num): if num <= 1: return False if num <= 3: return True if num % 2 == 0 or num % 3 == 0: return False i = 5 while i * i <= num: if num % i == 0 or num % (i + 2) == 0: return False i += 6 return True def has_prime_digits(num): ...
from solution import is_prime, has_prime_digits, smallest_prime_with_prime_digits_greater_than_n def test_is_prime(): assert is_prime(2) == True assert is_prime(3) == True assert is_prime(4) == False assert is_prime(11) == True assert is_prime(1) == False def test_has_prime_digits(): assert ha...
[ { "docstring": null, "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": null, "function_declaration": "def has_prime_digits(num):", "function_name": "has_prime_digits", "parameter_list": "(num)" }, { "doc...
[ 0, 0, 0, 1, 0, 0, 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": "import itertools\n\ndef 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 ...
trial_gpt4o_7
{ "original_instruction": "John loves mathematics and he is currently studying number theory. He is particularly interested in prime numbers. A prime number is a number that is greater than 1 and has no positive divisors other than 1 and itself.\n\nNow, John came up with a new challenge: He wants to find the smallest...
0.775795
Codeforces_17439
C
[ "is_prime", "has_prime_digits", "smallest_prime_with_prime_digits_greater_than_n" ]
3
[ [ "smallest_prime_with_prime_digits_greater_than_n", "has_prime_digits" ], [ "smallest_prime_with_prime_digits_greater_than_n", "is_prime" ] ]
2
[]
false
[]
false
pytest
true
[]
true
e50e720ac228cce924cb732fedafe89f95c35f7f
5a76f815f62654bb578ed529eb7e45c86c737217
v1.0
complete
Codeforces
Codeforces_17295_C
def find_parent(parents, v): if parents[v] == v: return v parents[v] = find_parent(parents, parents[v]) return parents[v] def union(parents, ranks, v1, v2): """Helper function to perform union of two sets.""" root1 = find_parent(parents, v1) root2 = find_parent(parents, v2) if ...
def find_parent(parents, v): if parents[v] == v: return v parents[v] = find_parent(parents, parents[v]) return parents[v] def union(parents, ranks, v1, v2): root1 = find_parent(parents, v1) root2 = find_parent(parents, v2) if root1 != root2: if ranks[root1] > ranks[root2]: ...
def test_example_case(): from io import StringIO import sys input_data = """7 6 3 3 1 2 3 1 4 1 5 2 5 2 6 3 6 3 7 3 4 5 6 2 1 3 4 1 2 6 7 """ sys.stdin = StringIO(input_data) main() # expected: YES \n NO \n YES def test_connected_component(): from io import StringIO import sys input_...
[ { "docstring": null, "function_declaration": "def find_parent(parents, v):", "function_name": "find_parent", "parameter_list": "(parents, v)" }, { "docstring": null, "function_declaration": "def union(parents, ranks, v1, v2):", "function_name": "union", "parameter_list": "(parent...
[ 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": "def can_be_connected(n, m, q, X, edges, queries):\n from collections import defaultdict, deque\n\n # Initialize adjacency list for the graph\n adj_li...
trial_gpt4o_5
{ "original_instruction": "You are given a bipartite graph with $$$n$$$ vertices and $$$m$$$ edges. The vertices are divided into two sets: $$$X$$$ and $$$Y$$$. The graph is undirected, and there are no edges within the same set; edges only connect vertices from $$$X$$$ to vertices in $$$Y$$$. \n\nYou are also given ...
0.549982
Codeforces_17295
C
[ "find_parent", "union", "can_be_connected", "main" ]
4
[ [ "can_be_connected", "find_parent" ], [ "can_be_connected", "union" ], [ "union", "find_parent" ] ]
3
[]
false
[]
false
pytest
false
[]
true
d8a0b5cb48046d5d479cd82393384f30200f4254
6db95da0201066eee4ed1548aafdff49c3280af4
v1.0
complete
Codeforces
Codeforces_17403_C
from itertools import combinations from typing import List, Tuple def does_clique_exist(n: int, m: int, k: int, edges: List[Tuple[int, int]]) -> str: """ Determine if there exists a subset of nodes of size k such that the induced subgraph is a clique. Parameters: n (int): Number of nodes in the gr...
from itertools import combinations def does_clique_exist(n, m, k, edges): """ Determine if there exists a subset of nodes of size k such that the induced subgraph is a clique. Parameters: n (int): Number of nodes in the graph. m (int): Number of edges in the graph. k (int): Required size o...
from solution import does_clique_exist def test_small_cases(): assert does_clique_exist(5, 7, 3, [(1, 2), (1, 3), (1, 4), (2, 3), (2, 4), (3, 4), (4, 5)]) == "YES" assert does_clique_exist(5, 5, 4, [(1, 2), (1, 3), (1, 4), (2, 3), (3, 4)]) == "NO" def test_single_node_clique(): assert does_clique_exist(1,...
[ { "docstring": "Determine if there exists a subset of nodes of size k such that the induced subgraph is a clique.\n\nParameters:\nn (int): Number of nodes in the graph.\nm (int): Number of edges in the graph.\nk (int): Required size of the clique.\nedges (list of tuples): List of edges in the graph where each e...
[ 1, 0, 0, 0, 1, 1, 0, 1, 1, 1 ]
6
medium
0.6
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_clique_possible(n, m, k, edges):\n from itertools import combinations\n\n # Create an adjacency matrix\n adj_matrix = [[0] * n for _ in range(...
trial_gpt4o_9
{ "original_instruction": "Given an undirected graph with `n` nodes and `m` edges, and an integer `k`, you are required to determine if there exists a subset of nodes of size `k` such that the induced subgraph is a clique. A clique is a subset of nodes where every pair of nodes is connected by an edge.\n\nInput:\n- T...
0.519022
Codeforces_17403
C
[ "does_clique_exist", "is_clique" ]
2
[ [ "does_clique_exist", "is_clique" ] ]
1
[]
false
[]
false
pytest
true
[]
true
ec3bd037d5a10b61767d0f456d612a6e1da073fa
c449753693e207a65acce3eaf721ff98e6026130
v1.0
complete
Codeforces
Codeforces_17572_C
import heapq from typing import List, Tuple def dijkstra(n: int, edges: List[Tuple[int, int, int]], start: int, end: int) -> int: """Finds the minimum sum of weights of edges that form a path from node start to node end using Dijkstra's algorithm.""" graph = [[] for _ in range(n + 1)] for u, v, w in edges:...
import heapq import sys def dijkstra(n, edges, start, end): graph = [[] for _ in range(n + 1)] for u, v, w in edges: graph[u].append((v, w)) graph[v].append((u, w)) dist = [float('inf')] * (n + 1) dist[start] = 0 pq = [(0, start)] while pq: current_dist, u = he...
def test_min_path_weight_case_1(): n = 5 m = 6 edges = [ (1, 2, 1), (2, 3, 2), (3, 4, 3), (4, 5, 4), (1, 3, 2), (3, 5, 1) ] assert min_path_weight(n, m, edges) == 3 def test_min_path_weight_case_2(): n = 4 m = 2 edges = [ (1, 2, 3)...
[ { "docstring": null, "function_declaration": "def dijkstra(n, edges, start, end):", "function_name": "dijkstra", "parameter_list": "(n, edges, start, end)" }, { "docstring": null, "function_declaration": "def min_path_weight(n, m, edge_list):", "function_name": "min_path_weight", ...
[ 0, 0, 0, 0, 0, 1, 1, 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": "import heapq\nimport sys\n\ndef minimum_sum_of_weights(n, m, edges):\n \"\"\"\n Returns the minimum sum of weights of edges that form a path from node 1...
trial_gpt4o_8
{ "original_instruction": "You are given an undirected weighted graph with $$$n$$$ nodes and $$$m$$$ edges. Your task is to find the minimum sum of weights of edges that form a path from node $$$1$$$ to node $$$n$$$. If there is no such path, return -1.\n\nThe first line contains two integers $$$n$$$ ($$$2 \\le n \\l...
0.731579
Codeforces_17572
C
[ "dijkstra", "min_path_weight" ]
2
[ [ "min_path_weight", "dijkstra" ] ]
1
[]
false
[]
false
pytest
false
[]
true
3a2cc34f90aed378ce7f9cf4c02c8f4a4ccda58c
49000cc31c7fede558b0f6c5e243e422301d784f
v1.0
complete
Codeforces
Codeforces_17741_C
def is_valid_triangle(a: int, b: int, c: int) -> bool: """ Determines if the given sides a, b, c can form a valid triangle. >>> is_valid_triangle(3, 4, 5) True >>> is_valid_triangle(1, 2, 3) False >>> is_valid_triangle(2, 2, 2) True """ def valid_triangles(n: int, triplets: List[Tuple[int, ...
def is_valid_triangle(a, b, c): """ Determines if the given sides a, b, c can form a valid triangle. """ return a + b > c and a + c > b and b + c > a def valid_triangles(n, triplets): """ Returns a list of "Yes" or "No" for each triplet indicating if it can form a valid triangle. ...
from solution import is_valid_triangle, valid_triangles def test_is_valid_triangle(): assert is_valid_triangle(3, 4, 5) == True assert is_valid_triangle(1, 2, 3) == False assert is_valid_triangle(2, 2, 2) == True assert is_valid_triangle(7, 10, 5) == True assert is_valid_triangle(1, 10, 12) == Fals...
[ { "docstring": "Determines if the given sides a, b, c can form a valid triangle.", "function_declaration": "def is_valid_triangle(a, b, c):", "function_name": "is_valid_triangle", "parameter_list": "(a, b, c)" }, { "docstring": "Returns a list of \"Yes\" or \"No\" for each triplet indicating...
[ 0, 0, 1, 1, 1, 1, 1, 0, 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_valid_triangle(triplets):\n \"\"\"\n Given a list of triplets where each triplet contains three integers representing the sides of a triangle,\n ...
trial_gpt4o_9
{ "original_instruction": "During a dream, Anna saw a treasure map leading to a hidden gold chest. The map was encrypted into a set of triplets of positive integers. Each triplet (ai, bi, ci) represents the sides of a triangle. The elderly cartographer who drew the map told her that only triangles with integer sides ...
0.78586
Codeforces_17741
C
[ "is_valid_triangle", "valid_triangles" ]
2
[ [ "valid_triangles", "is_valid_triangle" ] ]
1
[]
false
[]
false
pytest
true
[]
true
870ba85530901e5b3b07e219e534d1ad5e364c8c
00c64f551221dee34f9438adc0d46ede01685f40
v1.0
complete
Codeforces
Codeforces_17706_C
def max_crossing_sum(arr, low, mid, high): left_sum = float('-inf') total = 0 for i in range(mid, low-1, -1): total += arr[i] if total > left_sum: left_sum = total right_sum = float('-inf') total = 0 for j in range(mid+1, high+1): total += arr[j] if t...
def max_crossing_sum(arr, low, mid, high): left_sum = float('-inf') total = 0 for i in range(mid, low-1, -1): total += arr[i] if total > left_sum: left_sum = total right_sum = float('-inf') total = 0 for j in range(mid+1, high+1): total += arr[j] if t...
from solution import find_maximum_sum def test_single_element(): assert find_maximum_sum([5]) == 5 assert find_maximum_sum([-5]) == -5 def test_all_positive_elements(): assert find_maximum_sum([1, 2, 3, 4, 5]) == 15 def test_all_negative_elements(): assert find_maximum_sum([-1, -2, -3, -4, -5]) == -1...
[ { "docstring": null, "function_declaration": "def max_crossing_sum(arr, low, mid, high):", "function_name": "max_crossing_sum", "parameter_list": "(arr, low, mid, high)" }, { "docstring": null, "function_declaration": "def max_subarray_sum(arr, low, high):", "function_name": "max_sub...
[ 1, 1, 0, 0, 0, 1, 1, 0, 0, 0 ]
4
medium
0.4
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def max_crossing_sum(arr, left, mid, right):\n \"\"\"\n Helper function to find the maximum sum of the subarray that crosses the midpoint.\n \"\"\"\n...
trial_gpt4o_5
{ "original_instruction": "Given an array of integers, write a program to find the maximum sum of a contiguous subarray using the divide and conquer method.\n\nInput\nThe first line of the input contains an integer n (1 ≤ n ≤ 200,000) — the number of elements in the array.\n\nThe second line contains n integers a1, a...
0.689697
Codeforces_17706
C
[ "max_crossing_sum", "max_subarray_sum", "find_maximum_sum" ]
3
[ [ "find_maximum_sum", "max_subarray_sum" ], [ "max_subarray_sum", "max_crossing_sum" ] ]
2
[]
false
[]
false
pytest
true
[]
true
5694794d998c682f5855e58a88a59dab8cee94c8
66968c7a36ad40927b50eba98f652b197a7709ea
v1.0
complete
Codeforces
Codeforces_17772_C
def max_sum_path(n: int, m: int, values: List[int], edges: List[Tuple[int, int]]) -> int: """ Find the maximum sum of the values of the vertices on a simple path in the graph. >>> max_sum_path(5, 6, [1, 2, 3, 4, 5], [(1, 2), (1, 3), (2, 3), (2, 4), (3, 5), (4, 5)]) 15 >>> max_sum_path(1, 0, [10], []) ...
def dfs(graph, values, vertex, visited, current_sum): visited.add(vertex) max_sum = current_sum + values[vertex] for neighbor in graph[vertex]: if neighbor not in visited: max_sum = max(max_sum, dfs(graph, values, neighbor, visited.copy(), current_sum + values[vertex])) return max_su...
from solution import max_sum_path def test_example_case(): n = 5 m = 6 values = [1, 2, 3, 4, 5] edges = [(1, 2), (1, 3), (2, 3), (2, 4), (3, 5), (4, 5)] assert max_sum_path(n, m, values, edges) == 15 def test_single_node(): n = 1 m = 0 values = [10] edges = [] assert max_sum_pa...
[ { "docstring": null, "function_declaration": "def dfs(graph, values, vertex, visited, current_sum):", "function_name": "dfs", "parameter_list": "(graph, values, vertex, visited, current_sum)" }, { "docstring": null, "function_declaration": "def max_sum_path(n, m, values, edges):", "f...
[ 0, 0, 1, 1, 0, 0, 0, 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_simple_path(n, m, values, edges):\n from collections import defaultdict\n\n def dfs(node, visited):\n visited[node] = True\n m...
trial_gpt4o_7
{ "original_instruction": "You are given an undirected graph with n vertices and m edges. Each vertex has a specific value assigned to it. Your task is to find a simple path in the graph such that the sum of the values of the vertices on this path is maximized. A simple path is a path that does not include any vertex...
0.662994
Codeforces_17772
C
[ "dfs", "max_sum_path" ]
2
[ [ "max_sum_path", "dfs" ] ]
1
[]
false
[]
false
pytest
true
[]
true
233cd6df5b95c553019cf53338846479ccdf374b
b97f6c69f2ff794beb788f7710dcce3f81f87bfe
v1.0
complete
Codeforces
Codeforces_17794_C
from typing import List, Tuple def shortest_path(n: int, m: int, edges: List[Tuple[int, int, int]]) -> int: """ Determine the shortest distance from node 1 to node n in an undirected, weighted graph. Parameters: - n (int): The number of nodes in the graph. - m (int): The number of edges in the gra...
import heapq def dijkstra(graph, start, n): """ Dijkstra's algorithm to find the shortest path in a weighted graph from the start node to the n-th node. """ distances = {node: float('infinity') for node in range(1, n + 1)} distances[start] = 0 priority_queue = [(0, start)] while priori...
import pytest from solution import shortest_path def test_case_1(): n = 5 m = 6 edges = [ (1, 2, 2), (2, 3, 2), (2, 4, 4), (3, 5, 3), (4, 5, 1), (1, 5, 10), ] assert shortest_path(n, m, edges) == 7 def test_case_no_path(): n = 4 m = 2 edg...
[ { "docstring": "Dijkstra's algorithm to find the shortest path in a weighted graph\nfrom the start node to the n-th node.", "function_declaration": "def dijkstra(graph, start, n):", "function_name": "dijkstra", "parameter_list": "(graph, start, n)" }, { "docstring": "Function to setup the gr...
[ 1, 1, 0, 1, 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": "import heapq\nimport sys\n\ndef shortest_path(n, m, edges):\n graph = [[] for _ in range(n + 1)]\n for u, v, w in edges:\n graph[u].append((v, w)...
trial_gpt4o_8
{ "original_instruction": "You are given an undirected, weighted graph with $$$n$$$ nodes and $$$m$$$ edges. Each edge has a positive weight. You need to determine the shortest distance from node $$$1$$$ to node $$$n$$$. If there is no path from node $$$1$$$ to node $$$n$$$, print $$$-1$$$.\n\nThe first line contains...
0.697815
Codeforces_17794
C
[ "dijkstra", "shortest_path" ]
2
[ [ "shortest_path", "dijkstra" ] ]
1
[]
false
[]
false
pytest
true
[]
true
96380f91aaacbb782f8da848bc3e71d80dfd9f7f
32e104fa398414407fcf64e231b9e5c6dbf4a9ab
v1.0
complete
Codeforces
Codeforces_17524_C
def minimum_latency(n: int, m: int, channels: List[Tuple[int, int, int]]) -> int: """ Calculate the minimum total latency required to connect all servers. >>> minimum_latency(4, 5, [(1, 2, 3), (1, 3, 1), (2, 3, 2), (3, 4, 4), (2, 4, 5)]) 7 >>> minimum_latency(2, 1, [(1, 2, 1)]) 1 """ from typin...
def find(parent, i): if parent[i] == i: return i else: parent[i] = find(parent, parent[i]) return parent[i] def union(parent, rank, x, y): root_x = find(parent, x) root_y = find(parent, y) if root_x != root_y: if rank[root_x] < rank[root_y]: parent[r...
from solution import minimum_latency def test_minimum_latency_example(): n = 4 m = 5 channels = [ (1, 2, 3), (1, 3, 1), (2, 3, 2), (3, 4, 4), (2, 4, 5) ] assert minimum_latency(n, m, channels) == 7 def test_minimum_latency_small(): n = 2 m = 1 ch...
[ { "docstring": null, "function_declaration": "def find(parent, i):", "function_name": "find", "parameter_list": "(parent, i)" }, { "docstring": null, "function_declaration": "def union(parent, rank, x, y):", "function_name": "union", "parameter_list": "(parent, rank, x, y)" }, ...
[ 0, 1, 0, 1, 1, 1, 0, 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": "def minimum_total_latency(n, m, channels):\n \"\"\"\n Returns the minimum total latency required to connect all servers.\n \n Parameters:\n n (...
trial_gpt4o_9
{ "original_instruction": "In a telecommunication network, there are $$$n$$$ servers connected by $$$m$$$ two-way channels. Each channel has a latency associated with it, representing the time it takes for a signal to travel from one server to another. The network needs to ensure that communication between the server...
0.522545
Codeforces_17524
C
[ "find", "union", "kruskal", "minimum_latency" ]
4
[ [ "kruskal", "find" ], [ "kruskal", "union" ], [ "minimum_latency", "kruskal" ], [ "union", "find" ] ]
4
[]
false
[]
false
pytest
true
[]
true
6b3e37be9ad50dfc78d78cda7ed4a4fce2235a8e
3768e0a877272ca8f9cdfa5728cc938c5d6ecb85
v1.0
complete
Codeforces
Codeforces_17758_C
class TreeNode: def __init__(self, value): self.value = value self.left = None self.right = None class BinaryTree: def __init__(self, root_value): self.nodes = {1: TreeNode(root_value)} def add(self, p, v, l_or_r): parent_node = self.nodes[p] new_node = Tree...
class TreeNode: def __init__(self, value): self.value = value self.left = None self.right = None class BinaryTree: def __init__(self, root_value): self.nodes = {1: TreeNode(root_value)} def add(self, p, v, l_or_r): parent_node = self.nodes[p] new_node = Tree...
import pytest from solution import process_operations def test_simple_case(): operations = [ "1 1 3 l", "1 1 8 r", "1 3 2 l", "2 1" ] assert process_operations(5, operations) == [13] def test_only_root(): operations = [ "2 1" ] assert process_operations(...
[]
[ 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": "class TreeNode:\n def __init__(self, value):\n self.value = value\n self.left = None\n self.right = None\n\nclass BinaryTree:\n def...
trial_gpt4o_0
{ "original_instruction": "Acy and Cataline love binary trees and are playing a game with them. They have a binary tree where each node is assigned a unique integer value. The tree is rooted at node 1. They perform two types of operations on this tree:\n\n1. **Add Operation**: Add a new node with a given value as a c...
0.595924
Codeforces_17758
C
[ "process_operations", "run" ]
2
[ [ "run", "process_operations" ] ]
1
[]
false
[ "TreeNode", "BinaryTree" ]
true
pytest
true
[]
true
64cdbcb49cc63363a19f8091ea8fb512bb969759
867b25a445e3e21a3d1ed80ca288dc1dc1ce43bb
v1.0
complete
Codeforces
Codeforces_17843_C
def is_l_shaped(grid, n, m): """ Check whether there is any "L" shape consisting of exactly three cells in the grid such that all three cells in this shape contain the same letter. >>> is_l_shaped(["AAA", "ABC", "DDD"], 3, 3) "YES" >>> is_l_shaped(["ABC", "DEF"], 2, 3) "NO" """ directions = [ ...
def is_l_shaped(grid, n, m): directions = [ ((1, 0), (2, 1)), ((1, 0), (2, -1)), # down-right, down-left ((-1, 0), (-2, 1)), ((-1, 0), (-2, -1)), # up-right, up-left ((0, 1), (1, 2)), ((0, 1), (-1, 2)), # right-down, right-up ((0, -1), (1, -2)), ((0, -1), (-1, -2)) # left-down, l...
from solution import check_l_shapes def test_l_shape_positive_case(): input_str = "3 3\nAAA\nABC\nDDD" assert check_l_shapes(input_str) == "YES" def test_l_shape_negative_case(): input_str = "2 3\nABC\nDEF" assert check_l_shapes(input_str) == "NO" def test_l_shape_edge_case_smallest_grid(): input...
[ { "docstring": null, "function_declaration": "def is_l_shaped(grid, n, m):", "function_name": "is_l_shaped", "parameter_list": "(grid, n, m)" }, { "docstring": null, "function_declaration": "def check_l_shapes(input_str):", "function_name": "check_l_shapes", "parameter_list": "(i...
[ 1, 0, 0, 0, 0, 1, 1, 1, 1 ]
5
medium
0.556
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def has_L_shape(grid, n, m):\n directions = [\n (2, 1), (2, -1), (-2, 1), (-2, -1),\n (1, 2), (1, -2), (-1, 2), (-1, -2)\n ]\n \n fo...
trial_gpt4o_7
{ "original_instruction": "You are given a rectangular grid of size `n x m` where each cell in the grid contains an uppercase English letter. Your task is to check whether there is any \"L\" shape consisting of exactly three cells in the grid such that all three cells in this shape contain the same letter. An \"L\" s...
0.612309
Codeforces_17843
C
[ "is_l_shaped", "check_l_shapes" ]
2
[ [ "check_l_shapes", "is_l_shaped" ] ]
1
[]
false
[]
false
pytest
true
[]
true
5112357ab242c6b1490b96142d01e65294f42d1d
773ec80079af4906f96b8d69d9ad5d38f7bcb763
v1.0
complete
Codeforces
Codeforces_17720_C
from typing import List, Dict, Any def is_bipartite(n: int, edges: List[List[int]]) -> str: """ Determine if the graph represented by n nodes and a list of edges is bipartite. Args: n (int): Number of nodes. edges (List[List[int]]): List of edges where each edge is represented by two integers. ...
def is_bipartite(n, edges): from collections import deque, defaultdict graph = defaultdict(list) for u, v in edges: graph[u].append(v) graph[v].append(u) color = [-1] * (n + 1) def bfs(start): queue = deque([start]) color[start] = 0 whi...
from solution import bird_migration, process_input def test_case_1(): input_data = "3\n3 3\n1 2\n2 3\n3 1\n4 4\n1 2\n2 3\n3 4\n4 1\n5 4\n1 2\n2 3\n3 4\n4 5" expected_output = ["NO", "YES", "YES"] test_cases = process_input(input_data) assert bird_migration(test_cases) == expected_output def test_case_...
[ { "docstring": null, "function_declaration": "def is_bipartite(n, edges):", "function_name": "is_bipartite", "parameter_list": "(n, edges)" }, { "docstring": null, "function_declaration": "def bird_migration(test_cases):", "function_name": "bird_migration", "parameter_list": "(te...
[ 1, 0, 0, 1, 0, 0, 0, 1, 1, 1 ]
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 deque\n\ndef is_bipartite_graph(n, edges):\n \"\"\"\n Returns True if the graph is bipartite, False otherwise.\n \n n: num...
trial_gpt4o_9
{ "original_instruction": "After experiencing wildlife documentaries about birds, Alex has found a deep interest in studying bird migrations. Given a set of bird migration routes, Alex identifies key cities that birds stop in and the bidirectional routes between these cities. Each city is represented as a node, and e...
0.559002
Codeforces_17720
C
[ "is_bipartite", "bird_migration", "process_input" ]
3
[ [ "bird_migration", "is_bipartite" ] ]
1
[ "process_input" ]
false
[]
false
pytest
true
[]
true
38f28b71c49118e30a6557b5544f9e5e38802c6a
172ca3e3350240337de35b0c032798884fda38b6
v1.0
complete
Codeforces
Codeforces_17912_C
def find_basic_unit_length(message: str) -> int: """ This function finds the length of the smallest substring that can be repeated to form the entire message. >>> find_basic_unit_length("ababab") 2 >>> find_basic_unit_length("aaaaa") 1 >>> find_basic_unit_length("xyzxyzxyzxyz") 3 """ ...
def find_basic_unit_length(message): """ This function finds the smallest substring that can be repeated to form the entire message. It returns the length of that substring. """ length = len(message) for i in range(1, length + 1): if length % i == 0: basic_unit = message...
def test_find_basic_unit_length(): # Single test to verify the function assert find_basic_unit_length("ababab") == 2 assert find_basic_unit_length("aaaaa") == 1 assert find_basic_unit_length("xyzxyzxyzxyz") == 3 assert find_basic_unit_length("abcabcabcabc") == 3 assert find_basic_unit_length("a"...
[ { "docstring": "This function finds the smallest substring that can be repeated to form the entire message.\nIt returns the length of that substring.", "function_declaration": "def find_basic_unit_length(message):", "function_name": "find_basic_unit_length", "parameter_list": "(message)" }, { ...
[ 1, 0, 1, 0, 1, 1, 1, 1, 0, 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_basic_unit_length(s):\n \"\"\"\n Finds the length of the smallest substring that can\n be repeated to form the entire input string s.\n \...
trial_gpt4o_6
{ "original_instruction": "Detective Liam is working on a peculiar case involving encoded messages exchanged between members of a secret organization. Each message is encoded as a string and is formed by a specific pattern of repeated substrings.\n\nLiam has intercepted `n` such messages and needs your help to determ...
0.590267
Codeforces_17912
C
[ "find_basic_unit_length", "get_basic_unit_lengths" ]
2
[ [ "get_basic_unit_lengths", "find_basic_unit_length" ] ]
1
[]
false
[]
false
pytest
false
[]
true
0ec9e1dedc700ee0e9842a292d3fac6510fd7bd6
56ada8c7b6b4f444f6b65c970a12b7f143106764
v1.0
complete
Codeforces
Codeforces_18048_C
def longest_subsequence(n: int, sequence: List[int]) -> int: """ Determine the length of the longest subsequence in which there are no two consecutive non-prime numbers. >>> longest_subsequence(6, [4, 4, 3, 7, 4, 4]) 2 >>> longest_subsequence(4, [2, 3, 5, 7]) 4 >>> longest_subsequence(4, [4...
def is_prime(num): if num <= 1: return False if num == 2: return True if num % 2 == 0: return False p = 3 while p * p <= num: if num % p == 0: return False p += 2 return True def longest_subsequence(n, sequence): # Check the primality of e...
from solution import longest_subsequence def test_longest_subsequence_all_primes(): assert longest_subsequence(4, [2, 3, 5, 7]) == 4 def test_longest_subsequence_all_non_primes(): assert longest_subsequence(4, [4, 9, 6, 8]) == 0 def test_longest_subsequence_mixed(): assert longest_subsequence(6, [4, 4, 3...
[ { "docstring": null, "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": null, "function_declaration": "def longest_subsequence(n, sequence):", "function_name": "longest_subsequence", "parameter_list": "(n, sequen...
[ 1, 0, 0, 0, 0, 0, 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": "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": "Felicity loves puzzles that involve numbers and sequences. One of her favorites is the prime number game. She wants to play the game on a sequence of numbers where she can perform a special operation: for any two consecutive elements in the sequence that are not prime, she can remove both o...
0.738248
Codeforces_18048
C
[ "is_prime", "longest_subsequence" ]
2
[ [ "longest_subsequence", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
f9eca7882b33bc4221d85c73f0abe9e792e1cbe8
ea392d73c6f0f81953bbf6ec8dafefadcbdbfb54
v1.0
complete
Codeforces
Codeforces_17908_C
from typing import List, Tuple def sieve(limit: int) -> List[int]: """Generate a list of prime numbers up to `limit` using the Sieve of Eratosthenes. >>> sieve(10) [2, 3, 5, 7] >>> sieve(1) [] >>> sieve(20) [2, 3, 5, 7, 11, 13, 17, 19] """ pass def count_distinct_prime_divisors(tes...
def sieve(limit): """Generate a list of prime numbers up to `limit` using the Sieve of Eratosthenes.""" is_prime = [True] * (limit + 1) p = 2 while (p * p <= limit): if (is_prime[p] == True): for i in range(p * p, limit + 1, p): is_prime[i] = False p += 1 ...
def test_sieve(): assert sieve(10) == [2, 3, 5, 7] assert sieve(1) == [] assert sieve(20) == [2, 3, 5, 7, 11, 13, 17, 19] def test_count_distinct_prime_divisors(): # Test case 1 test_cases = [(3, [6, 10, 15])] assert count_distinct_prime_divisors(test_cases) == [3] # Test case 2 te...
[ { "docstring": "Generate a list of prime numbers up to `limit` using the Sieve of Eratosthenes.", "function_declaration": "def sieve(limit):", "function_name": "sieve", "parameter_list": "(limit)" }, { "docstring": null, "function_declaration": "def count_distinct_prime_divisors(test_cas...
[ 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": "def sieve(limit):\n is_prime = [True] * (limit + 1)\n p = 2\n while (p * p <= limit):\n if (is_prime[p] == True):\n for i in range(...
trial_gpt4o_8
{ "original_instruction": "You are given a sequence of $$$n$$$ integers $$$a_1,a_2,\\dots,a_n$$$ where $$$1 \\le n \\le 1000$$$ and $$$1 \\le a_i \\le 1000$$$.\n\nYou need to determine the number of distinct prime numbers that divide at least one number in the sequence $$$a$$$.\n\nFor example, for the sequence $$$a =...
0.653496
Codeforces_17908
C
[ "sieve", "count_distinct_prime_divisors" ]
2
[ [ "count_distinct_prime_divisors", "sieve" ] ]
1
[]
false
[]
false
pytest
false
[]
true
22ed4cb15e619ee2a715ad25e4cd130170cb2615
7268dfacc99431bf235f9f811938a60716eed971
v1.0
complete
Codeforces
Codeforces_18036_C
def is_prime(n): """Helper function to check if a number is a 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 ...
def is_prime(n): """Helper function to check if a number is a 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 ...
def test_is_prime(): assert is_prime(2) == True assert is_prime(3) == True assert is_prime(4) == False assert is_prime(29) == True assert is_prime(100) == False def test_find_special_sequence(): assert find_special_sequence(3, 28) == (True, [2, 3, 23]) assert find_special_sequence(2, 50) ==...
[ { "docstring": "Helper function to check if a number is a prime.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Function to find the special sequence with exactly k primes and sum S.", "function_declaration": "def fin...
[ 0, 0, 0, 0, 0, 0, 1, 0, 0 ]
1
hard
0.111
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(n):\n \"\"\"Check if a number is prime.\"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return True\n if n % 2 == 0 or...
trial_gpt4o_6
{ "original_instruction": "Pieguy loves collecting special sequences of numbers. A sequence of integers is defined to be special if it contains exactly `k` prime numbers and the sum of the sequence is equal to `S`. Given integers `k` and `S`, determine if there exists such a special sequence. If it exists, output any...
0.721533
Codeforces_18036
C
[ "is_prime", "find_special_sequence", "solve" ]
3
[ [ "find_special_sequence", "is_prime" ], [ "solve", "find_special_sequence" ] ]
2
[]
false
[]
false
pytest
false
[]
true
af5c2de78522706139eebf18bc9194a18a3beb13
feb50f5a2ed91a790b4cf37a8d48dee66c083205
v1.0
complete
Codeforces
Codeforces_18100_C
def find_peaks(matrix): """ Given a matrix of n x m filled with integers, find all the peak positions. A cell is considered a "peak" if it is strictly greater than all of its neighbors. """ def parse_input(input_string): """ Parse the input string into the matrix format required. """ def s...
def find_peaks(matrix): """ Given a matrix of n x m filled with integers, find all the peak positions. A cell is considered a "peak" if it is strictly greater than all of its neighbors. """ n = len(matrix) m = len(matrix[0]) peaks = [] def is_peak(i, j): current = matrix[i][j] ...
from solution import find_peaks, parse_input, solution def test_peak_finder_simple(): input_string = "3 3\n1 2 1\n2 4 2\n1 2 1" expected_output = "1\n2 2" assert solution(input_string) == expected_output def test_no_peaks(): input_string = "3 3\n1 1 1\n1 1 1\n1 1 1" expected_output = "0" asser...
[ { "docstring": "Given a matrix of n x m filled with integers, find all the peak positions.\nA cell is considered a \"peak\" if it is strictly greater than all of its neighbors.", "function_declaration": "def find_peaks(matrix):", "function_name": "find_peaks", "parameter_list": "(matrix)" }, { ...
[ 0, 0, 0, 1, 1, 0, 1, 0, 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 find_peaks(matrix):\n \"\"\"\n Finds and returns the number and positions of peak cells in the given matrix.\n \n Parameters:\n matrix (lis...
trial_gpt4o_9
{ "original_instruction": "You are given a matrix of size n x m filled with integers. Each integer represents the height of a cell in a grid. A cell is considered a \"peak\" if it is strictly greater than all of its neighbors. Two cells are neighbors if they share a side (left, right, top, bottom). Write a program to...
0.666781
Codeforces_18100
C
[ "find_peaks", "parse_input", "solution" ]
3
[ [ "solution", "find_peaks" ], [ "solution", "parse_input" ] ]
2
[ "parse_input" ]
false
[]
false
pytest
true
[]
true
b89c52fb34cfe84de833c4e76f4678aba20981b8
1c354a51be2d1e441f607842ca989eb9f70f73be
v1.0
complete
Codeforces
Codeforces_18024_C
import heapq from typing import List, Tuple def dijkstra(n: int, m: int, edges: List[Tuple[int, int, int]], start: int, dest: int) -> int: graph = [[] for _ in range(n)] for u, v, t in edges: graph[u-1].append((t, v-1)) graph[v-1].append((t, u-1)) distances = [float('inf')] * n dis...
import heapq def dijkstra(n, m, edges, start, dest): graph = [[] for _ in range(n)] for u, v, t in edges: graph[u-1].append((t, v-1)) graph[v-1].append((t, u-1)) distances = [float('inf')] * n distances[start-1] = 0 priority_queue = [(0, start-1)] while priority_queue:...
from solution import shortest_travel_time def test_shortest_travel_time_direct_path(): assert shortest_travel_time(3, 3, [(1, 2, 1), (2, 3, 1), (1, 3, 3)], 1, 3) == 2 def test_shortest_travel_time_no_path(): assert shortest_travel_time(3, 1, [(1, 2, 1)], 1, 3) == -1 def test_shortest_travel_time_same_city():...
[ { "docstring": null, "function_declaration": "def dijkstra(n, m, edges, start, dest):", "function_name": "dijkstra", "parameter_list": "(n, m, edges, start, dest)" }, { "docstring": null, "function_declaration": "def shortest_travel_time(n, m, edges, s, d):", "function_name": "shorte...
[ 0, 0, 0, 1, 1, 0, 0, 0, 1, 1 ]
4
medium
0.4
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "import heapq\n\ndef shortest_path(n, m, roads, s, d):\n # Create adjacency list\n graph = {i: [] for i in range(1, n + 1)}\n for u, v, t in roads:\n ...
trial_gpt4o_9
{ "original_instruction": "Alice is a travel consultant who loves creating the shortest travel itinerary between cities. She has maps of cities and direct roads between them, along with the travel time for each road. Given a list of cities connected by roads, she wants to determine the shortest time to travel from a ...
0.691359
Codeforces_18024
C
[ "dijkstra", "shortest_travel_time" ]
2
[ [ "shortest_travel_time", "dijkstra" ] ]
1
[]
false
[]
false
pytest
true
[]
true
1b861a839fda04b673201ab39e5164d36196c442
db8b8f8c76159552b2b9f39cf09ba756c5268fa0
v1.0
complete
Codeforces
Codeforces_18232_C
def count_inversions(arr: List[int]) -> int: """ Calculate the total number of inversions in the array. >>> count_inversions([2, 4, 1, 3, 5]) 3 >>> count_inversions([10, 20, 30, 40]) 0 """
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_sample_input_1(): assert count_inversions([2, 4, 1, 3, 5]) == 3 def test_sample_input_2(): assert count_inversions([10, 20, 30, 40]) == 0 def test_no_inversions(): assert count_inversions([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 0 def test_all_inversions(): ...
[ { "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, 0, 1, 1, 1 ]
8
easy
0.889
{ "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 number of inversions in the array.\n \"\"\"\n def merge_and_count(arr, temp_arr, left, mid, right):\n...
trial_gpt4o_8
{ "original_instruction": "Given an array of integers, an inversion occurs if for any index pairs (i, j) where i < j, the element at i is greater than the element at j (i.e., arr[i] > arr[j]).\n\nYour task is to calculate the total number of such inversions in the array.\n\n### Input\n- The first line contains a sing...
0.89177
Codeforces_18232
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
b398b196f083b33d96ec56db19e08af1bbcc4cc0
a26c9b6a718c4902636c0e23856d3e4613edfe7d
v1.0
complete
Codeforces
Codeforces_17851_C
def warehouse_storage_system(L: int, W: int, H: int, N: int, packages: List[Tuple[int, int, int, int]]) -> str: """ You are given the task of designing a warehouse storage system. The warehouse is represented as a 3D grid of size LxWxH (length, width, height), where each cell can either be occupied or empty. Th...
def can_place_package(warehouse, dimensions, start_coords, size): L, W, H = warehouse lx, ly, lz = start_coords dl, dw, dh = size if (lx + dl > L) or (ly + dw > W) or (lz + dh > H): return False for x in range(lx, lx + dl): for y in range(ly, ly + dw): for z in range(lz...
import pytest from solution import warehouse_storage_system def test_warehouse_with_solution(): L = 10 W = 10 H = 10 N = 3 packages = [ (1, 2, 3, 4), (2, 5, 2, 2), (3, 3, 3, 3) ] result = warehouse_storage_system(L, W, H, N, packages) assert result != "NO SOLUTIO...
[ { "docstring": null, "function_declaration": "def can_place_package(warehouse, dimensions, start_coords, size):", "function_name": "can_place_package", "parameter_list": "(warehouse, dimensions, start_coords, size)" }, { "docstring": null, "function_declaration": "def place_package(dimen...
[ 0, 0, 1, 0, 1, 0, 0, 0 ]
2
hard
0.25
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "from itertools import permutations\n\ndef can_place_package(warehouse, lx, ly, lz):\n for x in range(len(warehouse) - lx + 1):\n for y in range(len(...
trial_gpt4o_4
{ "original_instruction": "You are given the task of designing a warehouse storage system. The warehouse is represented as a 3D grid of size $$$L$$$x$$$W$$$x$$$H$$$ (length, width, height), where each cell can either be occupied or empty. The system needs to store $$$N$$$ packages, each defined by its dimensions (len...
0.609622
Codeforces_17851
C
[ "can_place_package", "place_package", "remove_package", "find_placement", "warehouse_storage_system" ]
5
[ [ "find_placement", "can_place_package" ], [ "find_placement", "place_package" ], [ "find_placement", "remove_package" ], [ "warehouse_storage_system", "find_placement" ] ]
4
[]
false
[]
false
pytest
true
[]
true
cbd0fbeea7a873ec2a3ff14cf47f15fa04391a63
892b807b6b72ee0be1b397864ea686095937759d
v1.0
complete
Codeforces
Codeforces_18271_C
def count_and_say(n: int) -> str: """ Returns the nth number in the count-and-say sequence. >>> count_and_say(1) "1" >>> count_and_say(4) "1211" >>> count_and_say(7) "13112221" """ pass def solve(test_cases: List[int]) -> List[str]: """ Solves the problem for multiple te...
def count_and_say(n): """ Returns the nth number in the count-and-say sequence. """ if n == 1: return "1" result = "1" for _ in range(n - 1): result = next_sequence(result) return result def next_sequence(sequence): """ Generates the next sequence in the count-a...
def test_count_and_say(): assert count_and_say(1) == "1" assert count_and_say(2) == "11" assert count_and_say(3) == "21" assert count_and_say(4) == "1211" assert count_and_say(5) == "111221" assert count_and_say(6) == "312211" assert count_and_say(7) == "13112221" assert count_and_say(8)...
[ { "docstring": "Returns the nth number in the count-and-say sequence.", "function_declaration": "def count_and_say(n):", "function_name": "count_and_say", "parameter_list": "(n)" }, { "docstring": "Generates the next sequence in the count-and-say order given a current sequence.", "functi...
[ 1, 1, 1, 1, 0, 1, 0, 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": "def count_and_say(n):\n if n == 1:\n return \"1\"\n\n def next_number(s):\n result = \"\"\n i = 0\n while i < len(s):\n ...
trial_gpt4o_8
{ "original_instruction": "You are given an infinite sequence that starts with the number '1'. Every following number in the sequence is determined according to the following rule: if the number at the previous position is written as a chain of the character '1' repeated times, the next number in the sequence will be...
0.545564
Codeforces_18271
C
[ "count_and_say", "next_sequence", "solve" ]
3
[ [ "count_and_say", "next_sequence" ], [ "solve", "count_and_say" ] ]
2
[]
false
[]
false
pytest
false
[]
true
8f09c2da96a3c651a6b3cfc63fe5b7d3e1e139b0
28fac385587c7afa55806b80de3a1e42a4b721aa
v1.0
complete
Codeforces
Codeforces_18138_C
def rotate_matrix(m: int, n: int, matrix: List[List[int]]) -> List[List[int]]: """ Rotates the matrix of dimensions m x n by 90 degrees clockwise. :param m: number of rows :param n: number of columns :param matrix: the matrix to be rotated :return: rotated matrix >>> rotate_matrix(...
def rotate_matrix_90_degrees_clockwise(matrix): """ Rotates a given matrix 90 degrees clockwise. :param matrix: List of lists where each sublist represents a row in the matrix :return: Rotated matrix as a list of lists """ if not matrix: return [] # Transpose matrix and rev...
from solution import rotate_matrix def test_rotate_3x3_matrix(): matrix = [ [1, 2, 3], [4, 5, 6], [7, 8, 9] ] rotated = rotate_matrix(3, 3, matrix) expected = [ [7, 4, 1], [8, 5, 2], [9, 6, 3] ] assert rotated == expected def test_rotate_2x4_matr...
[ { "docstring": "Rotates a given matrix 90 degrees clockwise.\n\n:param matrix: List of lists where each sublist represents a row in the matrix\n:return: Rotated matrix as a list of lists", "function_declaration": "def rotate_matrix_90_degrees_clockwise(matrix):", "function_name": "rotate_matrix_90_degre...
[ 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 rotate_matrix(matrix):\n \"\"\"\n Rotates the given matrix by 90 degrees clockwise.\n \"\"\"\n if not matrix:\n return []\n\n m, n =...
trial_gpt4o_9
{ "original_instruction": "Rita works as a data analyst and she has a matrix of integers with dimensions m x n. She needs to rotate the elements of the matrix by 90 degrees clockwise. Given the matrix, transform it and output the new matrix after rotation.\n\nThe first line contains two space-separated integers m and...
0.535485
Codeforces_18138
C
[ "rotate_matrix_90_degrees_clockwise", "rotate_matrix" ]
2
[ [ "rotate_matrix", "rotate_matrix_90_degrees_clockwise" ] ]
1
[]
false
[]
false
pytest
true
[]
true
f307cd9006a67a7d640d8ae5894286b8718f95e3
e42dce4012a8841dcdeea7f55274804986375b26
v1.0
complete
Codeforces
Codeforces_18276_C
def sum_primes_in_ranges(test_cases: List[Tuple[int, int]]) -> List[int]: """Calculate the sum of all prime numbers in given ranges. >>> sum_primes_in_ranges([(1, 5)]) == [10] >>> sum_primes_in_ranges([(10, 20)]) == [60] >>> sum_primes_in_ranges([(1, 5), (10, 20)]) == [10, 60] >>> sum_primes_in_rang...
MOD = 10**9 + 7 def sieve_up_to(n): """Use Sieve of Eratosthenes to find all primes up to n.""" is_prime = [True] * (n + 1) p = 2 while (p * p <= n): if (is_prime[p] == True): for i in range(p * p, n + 1, p): is_prime[i] = False p += 1 primes = [] for...
from solution import sum_primes_in_ranges def test_single_case_small_range(): test_cases = [(1, 5)] assert sum_primes_in_ranges(test_cases) == [10] # Primes: 2, 3, 5 def test_single_case_larger_range(): test_cases = [(10, 20)] assert sum_primes_in_ranges(test_cases) == [60] # Primes: 11, 13, 17, 19 ...
[ { "docstring": "Use Sieve of Eratosthenes to find all primes up to n.", "function_declaration": "def sieve_up_to(n):", "function_name": "sieve_up_to", "parameter_list": "(n)" }, { "docstring": "Calculate sum of all primes in the given range [L, R].", "function_declaration": "def sum_prim...
[ 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 prime_sieve(limit):\n \"\"\"\n This function returns a list of boolean values indicating whether numbers\n from 0 to limit are prime.\n \"\"\"...
trial_gpt4o_9
{ "original_instruction": "Dreamoon loves numbers and math challenges. He has recently come across an interesting problem of calculating special values for given ranges. Here's the problem Dreamoon designed:\n\nYou are given two integers $$$L$$$ and $$$R$$$. Your task is to find the sum of all prime numbers between $...
0.665819
Codeforces_18276
C
[ "sieve_up_to", "sum_primes_range", "sum_primes_in_ranges" ]
3
[ [ "sum_primes_in_ranges", "sieve_up_to" ], [ "sum_primes_in_ranges", "sum_primes_range" ] ]
2
[]
false
[]
false
pytest
true
[]
true
7f196b015deaa0c43626e18f3d5a58c3e8b42d26
46cb8bc2bef26c7285012a2c4d40b0b022474579
v1.0
complete
Codeforces
Codeforces_18153_C
import requests import time def get_weather(api_key, location): """ Fetches the current weather data for the specified location from the OpenWeatherMap API. Args: api_key (str): Your OpenWeatherMap API key. location (str): The location for which to fetch the weather. Returns: dict: A d...
import requests import time def get_weather(api_key, location): """ Fetches the current weather data for the specified location from the OpenWeatherMap API. Args: api_key (str): Your OpenWeatherMap API key. location (str): The location for which to fetch the weather. Returns: dict: A d...
import time from unittest.mock import patch, Mock from solution import get_weather, format_weather_data, display_weather, get_cached_weather @patch('solution.requests.get') def test_get_weather_success(mock_get): mock_response = Mock() mock_response.status_code = 200 mock_response.json.return_value = {"nam...
[ { "docstring": "Fetches the current weather data for the specified location from the OpenWeatherMap API.\nArgs:\napi_key (str): Your OpenWeatherMap API key.\nlocation (str): The location for which to fetch the weather.\n\nReturns:\ndict: A dictionary containing the weather information.", "function_declarati...
[ 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": "import requests\nimport time\nfrom requests.exceptions import HTTPError\n\nclass WeatherApp:\n def __init__(self, api_key):\n self.api_key = api_key...
trial_gpt4o_8
{ "original_instruction": "Design and implement a screen for a weather forecasting application that displays current weather information pulled from an open weather API.\n\nRequirements:\n1. Layout: The screen should have sections for current temperature, weather conditions, location, and an icon representing the wea...
0.632482
Codeforces_18153
C
[ "get_weather", "format_weather_data", "display_weather", "get_cached_weather" ]
4
[ [ "get_cached_weather", "get_weather" ] ]
1
[]
false
[]
false
pytest
true
[ "requests" ]
false
24fb2a078271db10368b4f6805afd4056c19cb09
4bff9fe533008088948465abb487dd5dcdcbb42b
v1.0
complete
Codeforces
Codeforces_18403_C
def canTransport(n, m, k, bridges, s, t): """ Determines if it's possible for at least k people to travel from the source island to the destination island simultaneously. Args: n (int): The number of islands. m (int): The number of bridges. k (int): The desired number of people to transport...
import heapq def maxFlow(n, graph, source, sink): """ Implements the Edmonds-Karp algorithm to find the maximum flow in a graph. """ flow = 0 while True: parent = [-1] * n queue = [(0, source)] parent[source] = source while queue: _, u = heapq.heappop(que...
from solution import canTransport def test_example(): assert canTransport(3, 2, 5, [(1, 2, 10, 0), (2, 3, 5, 1)], 1, 3) == "YES" assert canTransport(3, 2, 6, [(1, 2, 10, 0), (2, 3, 5, 1)], 1, 3) == "NO" def test_one_way(): assert canTransport(3, 3, 4, [(1, 2, 4, 0), (2, 3, 4, 0), (3, 2, 2, 0)], 1, 3) == "...
[ { "docstring": "Implements the Edmonds-Karp algorithm to find the maximum flow in a graph.", "function_declaration": "def maxFlow(n, graph, source, sink):", "function_name": "maxFlow", "parameter_list": "(n, graph, source, sink)" }, { "docstring": null, "function_declaration": "def canTr...
[ 0, 1, 0, 0, 0, 1, 1, 0, 0, 1 ]
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 can_transport_people(n, m, k, bridges, s, t):\n graph = defaultdict(list)\n for u, v, c, d in bridges:...
trial_gpt4o_9
{ "original_instruction": "In a distant future, a network of interconnected islands has been developed. Each island is connected to other islands by bridges that can be one-way or two-way. Each bridge has a certain capacity, which is the maximum number of people that can cross the bridge at a time.\n\nAn island admin...
0.699069
Codeforces_18403
C
[ "maxFlow", "canTransport" ]
2
[ [ "canTransport", "maxFlow" ] ]
1
[]
false
[]
false
pytest
true
[]
true
4f83d1b0f3f9cfe7fd27548933fdcbe75f3ef44f
9e48c5dc0e8665c2f713c3f35955a7b56713cb27
v1.0
complete
Codeforces
Codeforces_18272_C
from typing import List, Tuple def preprocess_prefix_sums(a: List[int]) -> List[int]: """ Preprocess the prefix sums of the array for fast range sum queries. :param a: List[int] The input array. :return: List[int] The prefix sums array. """ def process_query(prefix_sums: List[int], x: int, y: int,...
def preprocess_prefix_sums(a): """ Preprocess the prefix sums of the array for fast range sum queries. :param a: List[int] The input array. :return: List[int] The prefix sums array. """ prefix_sums = [0] * (len(a) + 1) for i in range(1, len(a) + 1): prefix_sums[i] = prefix_sums[i - 1...
from solution import preprocess_prefix_sums, process_query, solve def test_preprocess_prefix_sums(): assert preprocess_prefix_sums([1, 2, 3, 4]) == [0, 1, 3, 6, 10] def test_process_query(): prefix_sums = preprocess_prefix_sums([1, 2, 3, 4]) assert process_query(prefix_sums, 1, 4, 5) == "YES" assert p...
[ { "docstring": "Preprocess the prefix sums of the array for fast range sum queries.\n:param a: List[int] The input array.\n:return: List[int] The prefix sums array.", "function_declaration": "def preprocess_prefix_sums(a):", "function_name": "preprocess_prefix_sums", "parameter_list": "(a)" }, {...
[ 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": "def is_divisible_by_k(n, q, array, queries):\n \"\"\"\n Returns the results for each query.\n \n Parameters:\n n (int): number of elements in t...
trial_gpt4o_1
{ "original_instruction": "You are given an array of integers $$$a_1, a_2, \\ldots, a_n$$$ and a series of $$$q$$$ queries. Each query contains three integers $$$x, y$$$ and $$$k$$$.\n\nFor each query, you need to find the sum of elements from index $$$x$$$ to index $$$y$$$, inclusive, and determine if this sum is di...
0.617051
Codeforces_18272
C
[ "preprocess_prefix_sums", "process_query", "solve" ]
3
[ [ "solve", "preprocess_prefix_sums" ], [ "solve", "process_query" ] ]
2
[]
false
[]
false
pytest
true
[]
true
8e5b332183724a233da55ca95871dcb73e5fc9a7
897902f0450b118cf4326dc49d3276505478677b
v1.0
complete
Codeforces
Codeforces_18545_C
from typing import List from math import gcd from functools import reduce def lcm(a: int, b: int) -> int: """ Compute the Least Common Multiple of two numbers a and b. """ return a * b // gcd(a, b) def min_time_elapse(frequencies: List[int]) -> int: """ Given a list of frequencies of magical animals, this...
from math import gcd from functools import reduce def lcm(a, b): """ Compute the Least Common Multiple of two numbers a and b. """ return a * b // gcd(a, b) def min_time_elapse(frequencies): """ Given a list of frequencies of magical animals, this function returns the minimum time that wil...
from solution import min_time_elapse def test_single_frequency(): assert min_time_elapse([3]) == 3 def test_all_same_frequencies(): assert min_time_elapse([1, 1, 1, 1]) == 1 assert min_time_elapse([5, 5, 5]) == 5 def test_different_frequencies(): assert min_time_elapse([2, 3, 5]) == 30 assert min...
[ { "docstring": "Compute the Least Common Multiple of two numbers a and b.", "function_declaration": "def lcm(a, b):", "function_name": "lcm", "parameter_list": "(a, b)" }, { "docstring": "Given a list of frequencies of magical animals, this function returns\nthe minimum time that will elapse...
[ 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": "from math import gcd\nfrom functools import reduce\n\ndef lcm(a, b):\n \"\"\"\n Returns the least common multiple of a and b.\n \"\"\"\n return a ...
trial_gpt4o_9
{ "original_instruction": "In a distant land, there are magical animals that can talk. Each magical animal has its own unique frequency of chirping. You have requested the help of these animals to alert you when something unusual happens.\n\nEach magical animal repeatedly chirps based on its unique frequency. You sus...
0.57493
Codeforces_18545
C
[ "lcm", "min_time_elapse" ]
2
[ [ "min_time_elapse", "lcm" ] ]
1
[]
false
[]
false
pytest
true
[]
true
f6152ffb8530b5eb5d718b532522055c63e0a570
4e568567ac9aee90f997e78a1f88752dc0090442
v1.0
complete
Codeforces
Codeforces_18286_C
from typing import List, Tuple def preprocess_tree(n: int, edges: List[Tuple[int, int]]) -> Tuple[dict, List[int], List[int]]: """ Preprocesses the tree to compute the level and parent of each node. :param n: Number of cities :param edges: List of edges where each edge is a tuple (u, v) :retur...
from collections import deque, defaultdict def preprocess_tree(n, edges): tree = defaultdict(list) for u, v in edges: tree[u].append(v) tree[v].append(u) level = [-1] * (n + 1) parent = [-1] * (n + 1) queue = deque([1]) level[1] = 0 while queue: node = queue.pop...
def test_preprocess_tree(): n = 5 edges = [(1, 2), (1, 3), (3, 4), (3, 5)] tree, level, parent = preprocess_tree(n, edges) assert level[1] == 0 assert level[2] == 1 assert level[3] == 1 assert level[4] == 2 assert level[5] == 2 assert parent[1] == -1 assert parent[2] == 1 ass...
[ { "docstring": null, "function_declaration": "def preprocess_tree(n, edges):", "function_name": "preprocess_tree", "parameter_list": "(n, edges)" }, { "docstring": null, "function_declaration": "def lca(u, v, parent, level):", "function_name": "lca", "parameter_list": "(u, v, par...
[ 0, 1, 0, 0, 0, 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": "import sys\nfrom collections import defaultdict, deque\nsys.setrecursionlimit(200000)\n\nclass LCA:\n def __init__(self, n):\n self.n = n\n s...
trial_gpt4o_6
{ "original_instruction": "Dušan is working on another railway map where cities are connected by bidirectional railways, making the map a tree again. He wants to perform certain queries efficiently. Specifically, he needs to answer two types of queries:\n\n1. The distance query: Given two cities $$a$$ and $$b$$, dete...
0.624805
Codeforces_18286
C
[ "preprocess_tree", "lca", "distance_between_cities", "smallest_city_on_path", "process_queries" ]
5
[ [ "distance_between_cities", "lca" ], [ "process_queries", "distance_between_cities" ], [ "process_queries", "preprocess_tree" ], [ "process_queries", "smallest_city_on_path" ], [ "smallest_city_on_path", "lca" ] ]
5
[ "process_queries" ]
false
[]
false
pytest
false
[]
true
fba33c456e69ae2a68c7f9a5994d70c47deeb5bc
c92bab17cdd565e1d0433ac57e68372587e2b05e
v1.0
complete
Codeforces
Codeforces_18507_C
class TreeNode: def __init__(self, value=0, left=None, right=None): self.value = value self.left = left self.right = right def is_balanced_and_height(node): """ Helper function to determine if a tree is balanced and to compute its height. Returns a tuple (is_balanced, height). ...
class TreeNode: def __init__(self, value=0, left=None, right=None): self.value = value self.left = left self.right = right def is_balanced_and_height(node): """ Helper function to determine if a tree is balanced and to compute its height. Returns a tuple (is_balanced, height). ...
def test_balanced_tree_example(): n = 5 nodes = [ (1, 2, 3), (2, 4, -1), (3, -1, 5), (4, -1, -1), (5, -1, -1) ] assert check_balanced_tree(n, nodes) == "BALANCED" def test_not_balanced_tree(): n = 3 nodes = [ (1, 2, -1), (2, 3, -1), ...
[]
[ 1, 1, 1, 1, 0, 0, 1, 0, 0, 0 ]
5
medium
0.5
{ "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_1
{ "original_instruction": "You are given a binary tree with `n` nodes, where each node contains a unique integer value. Your task is to determine if the binary tree is balanced. A binary tree is considered balanced if, for every node in the tree, the height difference between its left and right subtrees is at most 1....
0.774739
Codeforces_18507
C
[ "is_balanced_and_height", "build_tree", "check_balanced_tree" ]
3
[ [ "check_balanced_tree", "build_tree" ], [ "check_balanced_tree", "is_balanced_and_height" ] ]
2
[]
false
[ "TreeNode" ]
true
pytest
false
[]
true
e76eabf65b0bda3433cbad206a1eeae3ff4bf609
4870678a079beeda71de2fc4f12f905cb621405d
v1.0
complete
Codeforces
Codeforces_18691_C
import math from heapq import heappop, heappush from typing import List, Tuple def euclidean_distance(x1: int, y1: int, x2: int, y2: int) -> float: """ Returns the Euclidean distance between two points (x1, y1) and (x2, y2). """ return math.sqrt((x1 - x2) ** 2 + (y1 - y2) ** 2) def max_reachable_myste...
import math from heapq import heappop, heappush def euclidean_distance(x1, y1, x2, y2): """ Returns the Euclidean distance between two points (x1, y1) and (x2, y2). """ return math.sqrt((x1 - x2) ** 2 + (y1 - y2) ** 2) def max_reachable_mystery_points(n, m, d, mystery_points, goal_points): """ ...
from solution import max_reachable_mystery_points def test_max_reachable_mystery_points(): n = 3 m = 3 d = 5 mystery_points = [(1, 1), (2, 2), (3, 3)] goal_points = [(5, 5), (6, 6), (10, 10)] assert max_reachable_mystery_points(n, m, d, mystery_points, goal_points) == 2 def test_max_reachable_...
[ { "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 maximum number of mystery p...
[ 1, 0, 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": "from math import sqrt\ndef max_reachable_mystery_points(n, m, d, mystery_points, goal_points):\n def distance(p1, p2):\n return sqrt((p1[0] - p2[0])...
trial_gpt4o_9
{ "original_instruction": "You are given a set of points on a two-dimensional plane, where each point is either a Mystery Point or a Goal Point. Mystery Points are marked with the letter \"M\" and coordinate (xm, ym). Goal Points are marked with the letter \"G\" and coordinate (xg, yg). A Goal is \"reachable\" from a...
0.622733
Codeforces_18691
C
[ "euclidean_distance", "max_reachable_mystery_points" ]
2
[ [ "max_reachable_mystery_points", "euclidean_distance" ] ]
1
[]
false
[]
false
pytest
true
[]
true
8c20257abc7cd39a86df82bb1bebecfeba286254
1242b13386c7e354a2072487303e0416429e814e
v1.0
complete
Codeforces
Codeforces_18784_C
import math import itertools def euclidean_distance(p1, p2): """Calculate the Euclidean distance between two points. >>> euclidean_distance((0, 0), (3, 4)) 5.0 >>> euclidean_distance((0, 0), (1, 1)) 1.4142135623730951 """ pass def tsp_shortest_path(points): """Determine the length of t...
import itertools import math def euclidean_distance(p1, p2): return math.sqrt((p1[0] - p2[0])**2 + (p1[1] - p2[1])**2) def tsp_shortest_path(points): n = len(points) all_permutations = list(itertools.permutations(range(n))) min_path_length = float('inf') for perm in all_permutations: curr...
import math from solution import euclidean_distance, tsp_shortest_path def test_euclidean_distance(): assert math.isclose(euclidean_distance((0, 0), (3, 4)), 5, abs_tol=1e-9) assert math.isclose(euclidean_distance((0, 0), (1, 1)), math.sqrt(2), abs_tol=1e-9) def test_tsp_shortest_path(): points1 = [(0, 0)...
[ { "docstring": null, "function_declaration": "def euclidean_distance(p1, p2):", "function_name": "euclidean_distance", "parameter_list": "(p1, p2)" }, { "docstring": null, "function_declaration": "def tsp_shortest_path(points):", "function_name": "tsp_shortest_path", "parameter_l...
[ 0, 0, 0, 1, 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 itertools\nimport math\n\ndef read_coordinates(n, coordinates):\n points = []\n for i in range(n):\n x, y = coordinates[i]\n points...
trial_gpt4o_3
{ "original_instruction": "You are provided with a list of n points in a two-dimensional plane, represented as (x1, y1), (x2, y2), ..., (xn, yn). Each point is connected with every other point by a direct line segment. Your task is to determine the length of the shortest path that visits each of the n points exactly ...
0.642039
Codeforces_18784
C
[ "euclidean_distance", "tsp_shortest_path", "parse_input" ]
3
[ [ "tsp_shortest_path", "euclidean_distance" ] ]
1
[ "parse_input" ]
false
[]
false
pytest
true
[]
true
c6047e55bcb39c806694d2b9bc24672630b31c7b
4dca048fd46174cf1ff173a7116d88ce533f169e
v1.0
complete
Codeforces
Codeforces_18934_C
def palindrome_pairs(words: List[str]) -> List[Tuple[int, int]]: """ Given a string array words, find all unique pairs of distinct indices (i, j) such that the concatenation of words[i] and words[j] forms a palindrome. Args: words (List[str]): An array of strings. Returns: List[Tup...
def is_palindrome(s): return s == s[::-1] def palindrome_pairs(words): result = [] word_dict = {word: i for i, word in enumerate(words)} for i, word in enumerate(words): for j in range(len(word) + 1): prefix = word[:j] suffix = word[j:] if i...
from solution import palindrome_pairs def test_example_1(): words = ["bat", "tab", "cat"] expected = [(0, 1), (1, 0)] result = palindrome_pairs(words) assert set(result) == set(expected) def test_example_2(): words = ["abcd", "dcba", "lls", "s", "sssll"] expected = [(0, 1), (1, 0), (3, 2), (2,...
[ { "docstring": null, "function_declaration": "def is_palindrome(s):", "function_name": "is_palindrome", "parameter_list": "(s)" }, { "docstring": null, "function_declaration": "def palindrome_pairs(words):", "function_name": "palindrome_pairs", "parameter_list": "(words)" } ]
[ 0, 0, 0, 0, 0, 0, 1, 0, 0 ]
1
hard
0.111
{ "trial_gpt4o_0": null, "trial_gpt4o_1": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared1_results_combined.jsonl", "solution_code": "def palindrome_pairs(words):\n def is_palindrome(s):\n return s == s[::-1]\n\n pairs = []\n word_dict = {word: i for ...
trial_gpt4o_7
{ "original_instruction": "Given a string array words, you need to find all the pairs of distinct indices (i, j) in the array such that the concatenation of words[i] and words[j] is a palindrome.\n\nA palindrome is a word, phrase, number, or other sequences of characters that reads the same backward as forward (ignor...
0.733823
Codeforces_18934
C
[ "is_palindrome", "palindrome_pairs" ]
2
[ [ "palindrome_pairs", "is_palindrome" ] ]
1
[]
false
[]
false
pytest
true
[]
true
fc01aad918f97d2028788ef5c993d5e987cb7a19
38b231b92d69be55e23e6d0fb70ea987a148ba9a
v1.0
complete
Codeforces
Codeforces_18589_C
from typing import List, Tuple def minimum_rescue_stations(n: int, m: int, d: int, roads: List[Tuple[int, int, int]]) -> int: """ Determine the minimum number of rescue stations needed so that every intersection in the city can be reached by at least one rescue station within the distance d. >>> minimum_r...
import heapq from collections import defaultdict def dijkstra(n, graph, start): distances = {i: float('inf') for i in range(1, n + 1)} distances[start] = 0 priority_queue = [(0, start)] while priority_queue: current_distance, current_node = heapq.heappop(priority_queue) if...
def test_example_case(): n = 4 m = 4 d = 5 roads = [ (1, 2, 2), (2, 3, 3), (3, 4, 4), (1, 4, 1) ] assert minimum_rescue_stations(n, m, d, roads) == 1 def test_no_roads(): n = 5 m = 0 d = 10 roads = [] assert minimum_rescue_stations(n, m, d, ro...
[ { "docstring": null, "function_declaration": "def dijkstra(n, graph, start):", "function_name": "dijkstra", "parameter_list": "(n, graph, start)" }, { "docstring": null, "function_declaration": "def minimum_rescue_stations(n, m, d, roads):", "function_name": "minimum_rescue_stations"...
[ 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": "from heapq import heappop, heappush\nimport sys\n\ndef dijkstra(n, graph, src):\n distances = [float('inf')] * (n + 1)\n distances[src] = 0\n priorit...
trial_gpt4o_8
{ "original_instruction": "There is a city with $$n$$ intersections and $$m$$ bidirectional roads. Each intersection is numbered from $$1$$ to $$n$$. Each road connects two intersections and has a certain length. The mayor of the city wants to build an efficient emergency response system by placing rescue stations at...
0.669857
Codeforces_18589
C
[ "dijkstra", "minimum_rescue_stations" ]
2
[ [ "minimum_rescue_stations", "dijkstra" ] ]
1
[]
false
[]
false
pytest
false
[]
true
e4069fa8eab80f15f6f2552b10881972255deeba
d0ddde9bf944665c1844b32651c591b4a43484bb
v1.0
complete
Codeforces
Codeforces_18978_C
import math from typing import List, Tuple def min_max_distance_to_connect_all_nodes(coords: List[Tuple[int, int]]) -> float: """ Compute the minimum possible maximum distance required to connect all nodes. Args: coords: A list of tuples representing the x, y coordinates of the nodes. Returns: ...
import math def find_parent(parent, i): if parent[i] == i: return i else: parent[i] = find_parent(parent, parent[i]) return parent[i] def union(parent, rank, x, y): root_x = find_parent(parent, x) root_y = find_parent(parent, y) if root_x != root_y: if rank[root_...
from solution import min_max_distance_to_connect_all_nodes def test_example_case(): coordinates = [(0, 0), (3, 4), (6, 8), (10, 10)] assert abs(min_max_distance_to_connect_all_nodes(coordinates) - 5.000000) < 10**-6 def test_two_nodes(): coordinates = [(0, 0), (0, 3)] assert abs(min_max_distance_to_co...
[ { "docstring": null, "function_declaration": "def find_parent(parent, i):", "function_name": "find_parent", "parameter_list": "(parent, i)" }, { "docstring": null, "function_declaration": "def union(parent, rank, x, y):", "function_name": "union", "parameter_list": "(parent, rank...
[ 0, 0, 1, 1, 1, 0, 0, 1, 1 ]
5
medium
0.556
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "import math\nimport heapq\n\n\ndef minimum_maximum_distance(n, coordinates):\n def euclidean_distance(p1, p2):\n return math.sqrt((p1[0] - p2[0]) **...
trial_gpt4o_8
{ "original_instruction": "After a sudden rise in technological advancements, the citizens of Techland want to establish a new communication network by connecting various nodes spread across their country. The nodes are positioned at various (x, y) coordinates on a 2D plane, and they can only connect directly if thei...
0.597947
Codeforces_18978
C
[ "find_parent", "union", "compute_distance", "minimum_spanning_tree_kruskal", "min_max_distance_to_connect_all_nodes" ]
5
[ [ "min_max_distance_to_connect_all_nodes", "minimum_spanning_tree_kruskal" ], [ "minimum_spanning_tree_kruskal", "compute_distance" ], [ "minimum_spanning_tree_kruskal", "find_parent" ], [ "minimum_spanning_tree_kruskal", "union" ], [ "union", "find_parent" ...
5
[]
false
[]
false
pytest
true
[]
true
702d6fedf58a90a6a8d3cd1b1971ee5b2f3e92d6
e6fd4598ba320adc6b1e5ea7115991677fe549f2
v1.0
complete
Codeforces
Codeforces_18758_C
def solve(input_string: str) -> int: """ There are two cities in the kingdom, connected by different possible paths. Each path has a certain length associated with it. The citizen delivering messages has to travel between these two cities from e1 to e2 and back again to ensure that the messages are delivered s...
import heapq def dijkstra(graph, start): distance = {node: float('infinity') for node in graph} distance[start] = 0 pq = [(0, start)] while pq: current_distance, current_node = heapq.heappop(pq) if current_distance > distance[current_node]: continue for neighbor, ...
from solution import solve def test_example_case(): input_data = """4 1 2 1 2 5 1 3 9 2 3 3 2 4 2 3 4 7""" assert solve(input_data) == 10 def test_case_no_paths(): input_data = """2 1 2""" assert solve(input_data) == float('infinity') def test_case_single_path(): input_data = """2 1 2 1 2 3""" ...
[ { "docstring": null, "function_declaration": "def dijkstra(graph, start):", "function_name": "dijkstra", "parameter_list": "(graph, start)" }, { "docstring": null, "function_declaration": "def shortest_round_trip(n, e1, e2, paths):", "function_name": "shortest_round_trip", "param...
[ 0, 0, 0, 1, 0, 1, 1, 1, 0, 1 ]
5
medium
0.5
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "import heapq\n\ndef dijkstra(graph, start, n):\n \"\"\"\n Implementation of Dijkstra's algorithm to find the shortest path from start node to other node...
trial_gpt4o_9
{ "original_instruction": "There are two cities in the kingdom, connected by different possible paths. Each path has a certain length associated with it. The citizen delivering messages has to travel between these two cities from e1 to e2 and back again to ensure that the messages are delivered safely and correctly. ...
0.720303
Codeforces_18758
C
[ "dijkstra", "shortest_round_trip", "process_input", "solve" ]
4
[ [ "shortest_round_trip", "dijkstra" ], [ "solve", "process_input" ], [ "solve", "shortest_round_trip" ] ]
3
[ "process_input" ]
false
[]
false
pytest
true
[]
true
aafa440f38c9456a957d397eb6c73f5f9148eecf
7d5cbb217e31bd225b8383b7df10903f6aea7fd1
v1.0
complete
Codeforces
Codeforces_18685_C
def generate_daily_reports(m, d, traffic_data): """ Generates daily reports providing the maximum and minimum number of cars counted in any single minute. Args: m (int): Number of data points collected each minute in a day. d (int): Number of days. traffic_data (list of int): List of m * d ...
def generate_daily_reports(m, d, traffic_data): """ Generates daily reports providing the maximum and minimum number of cars counted in any single minute. Args: m (int): Number of data points collected each minute in a day. d (int): Number of days. traffic_data (list of int): List of m * d ...
from solution import generate_daily_reports, process_input_and_generate_reports def test_generate_daily_reports(): assert generate_daily_reports(5, 2, [20, 30, 10, 25, 50, 15, 35, 40, 10, 45]) == [(50, 10), (45, 10)] assert generate_daily_reports(3, 3, [12, 15, 23, 9, 8, 20, 32, 45, 53]) == [(23, 12), (20, 8),...
[ { "docstring": "Generates daily reports providing the maximum and minimum number of cars counted in any single minute.\n\nArgs:\nm (int): Number of data points collected each minute in a day.\nd (int): Number of days.\ntraffic_data (list of int): List of m * d integers representing the traffic data points.\n\nR...
[ 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 generate_daily_traffic_report(m, d, data_points):\n \"\"\"\n Generates the daily traffic report for the given number of days with m data points each...
trial_gpt4o_9
{ "original_instruction": "A smart traffic management system is being implemented in City S to ease traffic congestion. The system collects traffic data every minute, recording the number of cars passing through a particular checkpoint in a list.\n\nThe mayor of City S wants to generate daily traffic summary reports ...
0.581251
Codeforces_18685
C
[ "generate_daily_reports", "process_input_and_generate_reports" ]
2
[ [ "process_input_and_generate_reports", "generate_daily_reports" ] ]
1
[]
false
[]
false
pytest
true
[]
true
10bcb3da59b51e998ea26edb7c939dbd355edff4
2022e2cb7173e8cb4c9fde0d05ef79245a034316
v1.0
complete
Codeforces
Codeforces_18882_C
def gourmet_meal(n: int, m: int, raw_recipes: List[str]) -> int: """ Alex is a food enthusiast who recently started experimenting with recipes to create unique dishes. He has `n` recipes, each recipe having a unique ID ranging from `1` to `n`. Alex wants to prepare a gourmet meal by selecting a subset of these reci...
def max_recipes(n, m, recipes): def can_add_recipe(selected_recipes, new_recipe): for ingredient in new_recipe: if ingredient in selected_recipes: return False return True def backtrack(index, selected_recipes): if index == len(recipes): return le...
from solution import gourmet_meal def test_example_case(): n = 5 m = 7 recipes = [ "3 1 2 3", "2 3 4", "3 5 6 7", "2 2 5", "1 4" ] assert gourmet_meal(n, m, recipes) == 3 def test_single_recipe(): n = 1 m = 5 recipes = ["3 1 2 3"] assert gour...
[ { "docstring": null, "function_declaration": "def max_recipes(n, m, recipes):", "function_name": "max_recipes", "parameter_list": "(n, m, recipes)" }, { "docstring": null, "function_declaration": "def gourmet_meal(n, m, raw_recipes):", "function_name": "gourmet_meal", "parameter_...
[ 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 max_recipes(n, m, recipes):\n from itertools import combinations\n \n def has_common_ingredients(recipe1, recipe2):\n return not set(recip...
trial_gpt4o_9
{ "original_instruction": "Alex is a food enthusiast who recently started experimenting with recipes to create unique dishes. He has `n` recipes, each recipe having a unique ID ranging from `1` to `n`. Alex wants to prepare a gourmet meal by selecting a subset of these recipes. However, due to various dietary restric...
0.709573
Codeforces_18882
C
[ "max_recipes", "gourmet_meal" ]
2
[ [ "gourmet_meal", "max_recipes" ] ]
1
[]
false
[]
false
pytest
true
[]
true
8be40027e63e1f89bcc2590fb849a26c84734b5a
e2bb7fe4c10e377cf0eaccf102ede0fa0250fa91
v1.0
complete
Codeforces
Codeforces_19031_C
def is_path_possible(grid): """ Determines if there is a path from the top-left corner to the bottom-right corner of the grid avoiding barriers (1's). The function returns 'YES' if there is a path and 'NO' otherwise. :param grid: List of strings where each string is a row of the grid. :ret...
def is_path_possible(grid): """ Determines if there is a path from the top-left corner to the bottom-right corner of the grid avoiding barriers (1's). The function returns 'YES' if there is a path and 'NO' otherwise. :param grid: List of strings where each string is a row of the grid. :ret...
from solution import is_path_possible, is_path_possible_from_input def test_is_path_possible_single_path(): grid = ["0100", "0000", "0110", "0000"] assert is_path_possible(grid) == 'YES' def test_is_path_possible_no_path(): grid = ["010", "010", "011"] assert is_path_possible(grid) == 'NO' def test_i...
[ { "docstring": "Determines if there is a path from the top-left corner to the bottom-right corner\nof the grid avoiding barriers (1's). The function returns 'YES' if there is a \npath and 'NO' otherwise.\n\n:param grid: List of strings where each string is a row of the grid.\n:return: 'YES' if there is a path, ...
[ 0, 0, 0, 1, 0, 1, 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": "def is_path_possible(n, grid):\n \"\"\"\n Determines if there is a path from the top-left to the bottom-right of the grid.\n \n :param n: int, siz...
trial_gpt4o_6
{ "original_instruction": "A game company has developed a simple game involving a grid of size nxn. Each cell on the grid can either contain a '1' (indicating a barrier) or a '0' (indicating a free path). The goal of the game is to navigate from the top-left corner of the grid (0,0) to the bottom-right corner (n-1,n-...
0.621196
Codeforces_19031
C
[ "is_path_possible", "is_path_possible_from_input" ]
2
[ [ "is_path_possible_from_input", "is_path_possible" ] ]
1
[]
false
[]
false
pytest
true
[]
true
863a1b192128e95e0a8d71eddccb6f73d15abe52
d5b7547b5a5bdc2565e05797ca7e98124a2fe5bb
v1.0
complete
Codeforces
Codeforces_18829_C
def is_prime(num: int) -> bool: """ Determine if the given number is a prime number. >>> is_prime(2) True >>> is_prime(3) True >>> is_prime(4) False >>> is_prime(17) True >>> is_prime(18) False >>> is_prime(1) False """ def max_prime_tax(gold: int) -> int: ...
def is_prime(num): if num < 2: return False if num in (2, 3): return True if num % 2 == 0 or num % 3 == 0: return False i = 5 while i * i <= num: if num % i == 0 or num % (i + 2) == 0: return False i += 6 return True def max_prime_tax(gold): ...
def test_is_prime(): assert is_prime(2) == True assert is_prime(3) == True assert is_prime(4) == False assert is_prime(17) == True assert is_prime(18) == False assert is_prime(1) == False def test_max_prime_tax(): assert max_prime_tax(11) == 11 assert max_prime_tax(13) == 13 assert ...
[ { "docstring": null, "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": null, "function_declaration": "def max_prime_tax(gold):", "function_name": "max_prime_tax", "parameter_list": "(gold)" }, { "docstri...
[ 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 sieve_of_eratosthenes(max_num):\n \"\"\"\n Returns a list of prime numbers up to max_num using the Sieve of Eratosthenes algorithm.\n \"\"\"\n ...
trial_gpt4o_3
{ "original_instruction": "In a faraway land, an ancient kingdom maintains a unique and strict financial system. Every citizen receives exactly one integer amount of gold coins. As a part of a fair taxation system, the king has mandated a new rule:\n\nA citizen must pay tax such that the total number of gold coins pa...
0.631185
Codeforces_18829
C
[ "is_prime", "max_prime_tax", "compute_taxes" ]
3
[ [ "compute_taxes", "max_prime_tax" ], [ "max_prime_tax", "is_prime" ] ]
2
[]
false
[]
false
pytest
false
[]
true
38ea2a2c40fd2068d5f381dff7a56f4a471623a9
487b80b253bb747177f63336ff3e82a5c11da2e0
v1.0
complete
Codeforces
Codeforces_18948_C
def find_final_set(n: int, data: List[str]) -> List[int]: """ Given number of sets and their elements, merge sets based on the largest intersection until only one set remains and return it sorted in ascending order. >>> find_final_set(3, ["3 1 2 3", "3 2 3 4", "3 4 5 6"]) [1, 2, 3, 4, 5, 6] >>> find_fin...
def merge_sets(sets): """ Given a list of sets, merges the sets following a specific algorithm until only one set remains. """ while len(sets) > 1: max_intersection_size = 0 sets_to_merge = (0, 1) # Find pair with largest intersection for i in range(len(sets)): ...
from solution import find_final_set def test_example_case(): data = [ "3 1 2 3", "3 2 3 4", "3 4 5 6" ] result = find_final_set(3, data) assert result == [1, 2, 3, 4, 5, 6] def test_single_set(): data = [ "3 1 2 3" ] result = find_final_set(1, data) asse...
[ { "docstring": "Given a list of sets, merges the sets following a specific algorithm\nuntil only one set remains.", "function_declaration": "def merge_sets(sets):", "function_name": "merge_sets", "parameter_list": "(sets)" }, { "docstring": null, "function_declaration": "def convert_inpu...
[ 0, 1, 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 merge_sets(sets):\n while len(sets) > 1:\n max_intersection_size = -1\n merge_indices = (0, 1)\n \n for i in range(len(sets...
trial_gpt4o_7
{ "original_instruction": "You are given a list of sets of integers. Each set contains different, unique integers and no set is empty. Your task is to merge sets following a specific algorithm:\n\n1. Find two sets, A and B, such that they have the largest intersection (i.e., the maximum number of common elements). If...
0.508234
Codeforces_18948
C
[ "merge_sets", "convert_input_to_sets", "find_final_set" ]
3
[ [ "find_final_set", "convert_input_to_sets" ], [ "find_final_set", "merge_sets" ] ]
2
[]
false
[]
false
pytest
true
[]
true
516fd19d68ffaa3a8c28abb9b41cc4be4c40f9a1
2952e22ad323cd9c910fb0bf0d0749c46f23ea6d
v1.0
complete
Codeforces
Codeforces_19039_C
from typing import List, Tuple def gcd(a: int, b: int) -> int: """ Returns the greatest common divisor of a and b. """ pass # Replace with implementation def get_subarray_gcd(arr: List[int], l: int, r: int) -> int: """ Returns the gcd of the subarray from index l to r (inclusive) """ ...
import math from functools import reduce def gcd(a, b): """ Returns the greatest common divisor of a and b. """ while b: a, b = b, a % b return a def get_subarray_gcd(arr, l, r): """ Returns the gcd of the subarray from index l to r (inclusive) """ subarray = arr[l-1:r] ...
from solution import solve_gcd_queries def test_solve_gcd_queries_example(): n = 6 array = [12, 15, 21, 24, 18, 30] queries = [(1, 3), (2, 5), (1, 6)] expected = [3, 3, 3] assert solve_gcd_queries(n, array, queries) == expected def test_single_element_array(): n = 1 array = [5] queries...
[ { "docstring": "Returns the greatest common divisor of a and b.", "function_declaration": "def gcd(a, b):", "function_name": "gcd", "parameter_list": "(a, b)" }, { "docstring": "Returns the gcd of the subarray from index l to r (inclusive)", "function_declaration": "def get_subarray_gcd(...
[ 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\nfrom functools import reduce\n\ndef gcd(a, b):\n while b:\n a, b = b, a % b\n return a\n\ndef gcd_of_subarray(arr, l, r):\n retur...
trial_gpt4o_9
{ "original_instruction": "You are given a sequence of n integers. Your task is to answer m queries, where each query asks for the greatest common divisor (GCD) of a subarray of the original sequence. \n\nThe GCD of a subset of numbers is the largest positive integer that divides each of the numbers. For example, the...
0.749161
Codeforces_19039
C
[ "gcd", "get_subarray_gcd", "solve_gcd_queries" ]
3
[ [ "get_subarray_gcd", "gcd" ], [ "solve_gcd_queries", "get_subarray_gcd" ] ]
2
[]
false
[]
false
pytest
true
[]
true
23c7d212b0142ef78ba060fee0240139fad1d724
8893bebe6b8ac0d0bc5f2fafb33393944671346d
v1.0
complete
Codeforces
Codeforces_19082_C
def process_emissions(n: int, emissions: List[int]) -> Tuple[int, List[int]]: """ Find the longest strictly decreasing subsequence from the given array and the respective days when these levels were recorded. Args: n (int): The number of days. emissions (List[int]): The carbon emission levels recor...
def longest_decreasing_subsequence(days, emissions): n = len(emissions) dp = [1] * n previous = [-1] * n for i in range(1, n): for j in range(i): if emissions[i] < emissions[j] and dp[i] < dp[j] + 1: dp[i] = dp[j] + 1 previous[i] = j ...
from solution import process_emissions def test_example_case(): emissions = [5, 3, 4, 8, 6, 7, 2] n = len(emissions) max_length, seq = process_emissions(n, emissions) assert max_length == 3 assert seq == [1, 2, 7] def test_single_element_case(): emissions = [5] n = len(emissions) max_l...
[ { "docstring": null, "function_declaration": "def longest_decreasing_subsequence(days, emissions):", "function_name": "longest_decreasing_subsequence", "parameter_list": "(days, emissions)" }, { "docstring": null, "function_declaration": "def process_emissions(n, emissions):", "funct...
[ 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": "def longest_decreasing_subsequence(n, emissions):\n \"\"\"\n Finds the longest strictly decreasing subsequence in the given emission levels array.\n ...
trial_gpt4o_5
{ "original_instruction": "You are given an array of n integers where each integer represents the carbon emission level recorded over n days. An environmental organization wants to determine the longest strictly decreasing sequence of days to show the effectiveness of their programs in reducing carbon emissions. The ...
0.578974
Codeforces_19082
C
[ "longest_decreasing_subsequence", "process_emissions" ]
2
[ [ "process_emissions", "longest_decreasing_subsequence" ] ]
1
[]
false
[]
false
pytest
true
[]
true
bad08a7e2625a3e2785e45a7ac618cbdb452081f
6a8ad0f90bcac2fd468da5542b233131c0c5957e
v1.0
complete
Codeforces
Codeforces_19187_C
import json import itertools import math def calculate_distance(point1, point2): """Calculate Euclidean distance between two points.""" return math.sqrt((point1[0] - point2[0]) ** 2 + (point1[1] - point2[1]) ** 2) def calculate_route_distance(route, points): """Calculate the total distance of the given ro...
import json import itertools import math def calculate_distance(point1, point2): """Calculate Euclidean distance between two points.""" return math.sqrt((point1[0] - point2[0]) ** 2 + (point1[1] - point2[1]) ** 2) def calculate_route_distance(route, points): """Calculate the total distance of the given ro...
from solution import find_optimal_route def test_find_optimal_route_simple_example(tmp_path): input_json = { "Depot": [0, 0], "DeliveryPoints": [[1, 2], [3, 4], [5, 1]] } file_path = tmp_path / "input.json" with open(file_path, 'w') as file: json.dump(input_json, file) resu...
[ { "docstring": "Calculate Euclidean distance between two points.", "function_declaration": "def calculate_distance(point1, point2):", "function_name": "calculate_distance", "parameter_list": "(point1, point2)" }, { "docstring": "Calculate the total distance of the given route.", "functio...
[ 0, 0, 0, 0, 1, 1, 1, 0, 0 ]
3
medium
0.333
{ "trial_gpt4o_0": null, "trial_gpt4o_1": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared1_results_combined.jsonl", "solution_code": "import json\nimport math\nfrom itertools import permutations\n\ndef distance(point1, point2):\n return math.sqrt((point1[0] - poin...
trial_gpt4o_7
{ "original_instruction": "You work for a logistics company that needs to optimize the delivery route of a truck that has to visit a set of delivery points scattered around a city. The truck starts at the company's central depot, and the goal is to visit each delivery point exactly once and return to the central depo...
0.592314
Codeforces_19187
C
[ "calculate_distance", "calculate_route_distance", "find_optimal_route" ]
3
[ [ "calculate_route_distance", "calculate_distance" ], [ "find_optimal_route", "calculate_route_distance" ] ]
2
[]
false
[]
false
pytest
true
[]
true
1d120be8c8b7ffc58c52dc734c01b1567fbd4148
c796a5c40cbf8f03cbb30f4e5f9dd020ee567b67
v1.0
complete
Codeforces
Codeforces_19262_C
def solve(tree_info, queries): """ You are given a tree with n nodes. Each node has an integer value associated with it. You will perform several queries on this tree. Each query asks you to find the maximum value of the integers in the subtree of a given node. The tree is rooted at node 1. The ...
class SegmentTree: def __init__(self, data): self.n = len(data) self.tree = [0] * (2 * self.n) self.build(data) def build(self, data): # Insert leaf nodes in tree for i in range(self.n): self.tree[self.n + i] = data[i] # Build the tree by calculating ...
def test_solve(): tree_info = { 'n': 5, 'values': [1, 2, 3, 4, 5], 'edges': [(1, 2), (1, 3), (3, 4), (3, 5)] } queries = [(2, 3), (1, 3, 10), (2, 3)] expected_output = [5, 10] assert solve(tree_info, queries) == expected_output tree_info = { 'n': 3, ...
[]
[ 0, 1, 0, 0, 0, 1, 1, 1, 1, 0 ]
5
medium
0.5
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "class TreeNode:\n def __init__(self, value):\n self.value = value\n self.children = []\n self.max_subtree_value = value\n\ndef dfs_max...
trial_gpt4o_8
{ "original_instruction": "You are given a tree with $$$n$$$ nodes. Each node has an integer value $$$a_i$$$ associated with it. You will perform several queries on this tree. Each query asks you to find the maximum value of the integers in the subtree of a given node.\n\nThe tree is rooted at node 1. The subtree of ...
0.586432
Codeforces_19262
C
[ "dfs", "solve" ]
2
[ [ "solve", "dfs" ] ]
1
[]
false
[ "SegmentTree" ]
true
pytest
false
[]
true
66cb62c78b4059236c92829923c5fa3a03c38e35
82fcd77a83024f5b815b8107ba67390ce1d0344e
v1.0
complete
Codeforces
Codeforces_19306_C
def minimum_swaps_to_sort(arr: List[int]) -> int: """ Determine the minimum number of swaps required to sort the array in non-decreasing order of heights. >>> minimum_swaps_to_sort([3, 1, 2]) 2 >>> minimum_swaps_to_sort([5, 4, 3, 2, 1]) 10 >>> minimum_swaps_to_sort([1, 3, 5, 2]) 2 >>> mi...
def count_inversions(arr): temp_arr = [0]*len(arr) return merge_sort(arr, temp_arr, 0, len(arr)-1) def merge_sort(arr, temp_arr, left, right): inv_count = 0 if left < right: mid = (left + right)//2 inv_count += merge_sort(arr, temp_arr, left, mid) inv_count += merge_sort(arr, te...
from solution import minimum_swaps_to_sort def test_example1(): arr = [3, 1, 2] assert minimum_swaps_to_sort(arr) == 2 def test_example2(): arr = [5, 4, 3, 2, 1] assert minimum_swaps_to_sort(arr) == 10 def test_example3(): arr = [1, 3, 5, 2] assert minimum_swaps_to_sort(arr) == 2 def test_so...
[ { "docstring": null, "function_declaration": "def count_inversions(arr):", "function_name": "count_inversions", "parameter_list": "(arr)" }, { "docstring": null, "function_declaration": "def merge_sort(arr, temp_arr, left, right):", "function_name": "merge_sort", "parameter_list"...
[ 0, 0, 0, 1, 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 minimum_swaps(arr):\n \"\"\"\n Returns the minimum number of adjacent swaps required to sort the given list in non-decreasing order.\n \"\"\"\n ...
trial_gpt4o_3
{ "original_instruction": "You are given an array of integers representing the heights of students standing in a row. The school needs to rearrange the students such that the row of students becomes non-decreasing in height. To achieve this, you are allowed to perform the following operation as many times as necessar...
0.637668
Codeforces_19306
C
[ "count_inversions", "merge_sort", "merge", "minimum_swaps_to_sort" ]
4
[ [ "count_inversions", "merge_sort" ], [ "merge_sort", "merge" ], [ "minimum_swaps_to_sort", "count_inversions" ] ]
3
[]
false
[]
false
pytest
true
[]
true
a5df998f044bc941de5c80dc6a78638fe5b275a5
a1786d6199762600ef69b47e3be8fd35283e7baf
v1.0
complete
Codeforces
Codeforces_19313_C
import re from typing import List def is_camel_case(identifier: str) -> bool: """ Determine if the given identifier is in camel case format. >>> is_camel_case("camelCase") True >>> is_camel_case("CamelCase") False >>> is_camel_case("camelcase") True >>> is_camel_case("Camelcase") F...
import re def is_camel_case(identifier): """ Determine if the given identifier is in camel case format. """ pattern = '^[a-z]+(?:[A-Z][a-z]*)*$' return re.match(pattern, identifier) is not None def check_identifiers(identifiers): """ Given a list of identifiers, determine if each is in cam...
from solution import is_camel_case, check_identifiers def test_is_camel_case(): assert is_camel_case("camelCase") == True assert is_camel_case("CamelCase") == False assert is_camel_case("camelcase") == True assert is_camel_case("Camelcase") == False assert is_camel_case("camelCaseExample") == True ...
[ { "docstring": "Determine if the given identifier is in camel case format.", "function_declaration": "def is_camel_case(identifier):", "function_name": "is_camel_case", "parameter_list": "(identifier)" }, { "docstring": "Given a list of identifiers, determine if each is in camel case format ...
[ 1, 0, 0, 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": "import re\n\ndef is_camel_case(identifier):\n \"\"\"\n Returns 'YES' if the identifier follows the camel case naming convention, otherwise 'NO'.\n \"...
trial_gpt4o_7
{ "original_instruction": "You are given a list of strings, where each string is derived from an identifier used in a programming context. Each identifier follows a specific format and naming convention.\n\nYour task is to determine whether each identifier in the list follows a valid camel case naming convention. Cam...
0.641541
Codeforces_19313
C
[ "is_camel_case", "check_identifiers" ]
2
[ [ "check_identifiers", "is_camel_case" ] ]
1
[]
false
[]
false
pytest
true
[]
true
4b7f64f5b95b290b82cdc5f9c5b4da5a19f69e0f
e9c03cb80c38fb110b414b12c0efe4b5bf35f4bb
v1.0
complete
Codeforces
Codeforces_19184_C
from typing import List, Tuple def usc_least_common_mentor(n: int, edges: List[Tuple[int, int]], queries: List[Tuple[int, int]]) -> List[int]: """ The Union of Social Coders (USC) decided to create a social network for programmers. Each programmer can be identified by a unique integer ID starting from 1. The p...
from collections import defaultdict, deque def preprocess_lca(n, edges): # Initialize adjacency list, parents and depth adj_list = defaultdict(list) parent = [0] * (n + 1) depth = [0] * (n + 1) # Building adjacency list from edges for u, v in edges: adj_list[u].append(v) ad...
from solution import usc_least_common_mentor def test_case_1(): n = 5 edges = [(1, 2), (1, 3), (3, 4), (3, 5)] queries = [(2, 4), (4, 5), (2, 3)] assert usc_least_common_mentor(n, edges, queries) == [1, 3, 1] def test_case_2(): n = 6 edges = [(1, 2), (1, 3), (2, 4), (2, 5), (3, 6)] queries...
[ { "docstring": null, "function_declaration": "def preprocess_lca(n, edges):", "function_name": "preprocess_lca", "parameter_list": "(n, edges)" }, { "docstring": null, "function_declaration": "def find_lca(u, v, parent, depth):", "function_name": "find_lca", "parameter_list": "(u...
[ 1, 1, 1, 1, 1, 1, 1, 0, 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 collections import defaultdict, deque\n\ndef lca_preprocessing(n, edges):\n \"\"\"\n Preprocesses the tree to build up necessary data to answer LCA...
trial_gpt4o_8
{ "original_instruction": "The Union of Social Coders (USC) decided to create a social network for programmers. Each programmer can be identified by a unique integer ID starting from 1. The programmers form a hierarchical structure based on direct mentorship where one programmer can mentor multiple others, but each p...
0.590136
Codeforces_19184
C
[ "preprocess_lca", "find_lca", "usc_least_common_mentor" ]
3
[ [ "usc_least_common_mentor", "find_lca" ], [ "usc_least_common_mentor", "preprocess_lca" ] ]
2
[]
false
[]
false
pytest
true
[]
true
4daf0a9ae67e67d3db1b80dad1e7521b185503e4
0f43efd016c9edb5be48b7d9bfd4f54f8a3c4490
v1.0
complete
Codeforces
Codeforces_19121_C
class TreeNode: def __init__(self, key): self.left = None self.right = None self.val = key def insert(root, key): if root is None: return TreeNode(key) else: if root.val < key: root.right = insert(root.right, key) else: root.left = ins...
class TreeNode: def __init__(self, key): self.left = None self.right = None self.val = key def insert(root, key): if root is None: return TreeNode(key) else: if root.val < key: root.right = insert(root.right, key) else: root.left = ins...
from solution import process_input def test_example_cases(): assert process_input(2, [[4, "INSERT 5", "INSERT 2", "INSERT 8", "DELETE 5"], [3, "INSERT 1", "DELETE 1", "DELETE 1"]]) == [1, -1] def test_single_insert(): assert process_input(1, [[1, "INSERT 10"]]) == [0] def test_mu...
[]
[ 1, 1, 0, 0, 0, 0, 0, 0 ]
2
hard
0.25
{ "trial_gpt4o_0": null, "trial_gpt4o_1": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared1_results_combined.jsonl", "solution_code": "class TreeNode:\n def __init__(self, key):\n self.left = None\n self.right = None\n self.val = key\n\ndef ins...
trial_gpt4o_2
{ "original_instruction": "### Bob's Binary Tree Adventure\n\nBob is exploring binary trees and wants to check if a sequence of operations will maintain a tree-like structure. A sequence of operations contains nodes being added to create a tree or nodes being removed from the tree. The nodes are represented by unique...
0.620408
Codeforces_19121
C
[ "insert", "delete_node", "find_min", "height", "verify_sequence_of_operations", "contains", "process_input" ]
7
[ [ "delete_node", "find_min" ], [ "process_input", "verify_sequence_of_operations" ], [ "verify_sequence_of_operations", "contains" ], [ "verify_sequence_of_operations", "delete_node" ], [ "verify_sequence_of_operations", "height" ], [ "verify_sequence_...
6
[ "process_input" ]
false
[ "TreeNode" ]
true
pytest
true
[]
true
c7d672a381eab1c4bb529399588737daffbe38d2
58dd19c8a79426088e22e437765872049fc52b7f
v1.0
complete
Codeforces
Codeforces_19065_C
from typing import List, Tuple def solve_sudoku(sudoku: List[List[int]], constraints: List[Tuple[Tuple[int, int], int]]) -> List[List[int]]: """ Solves a modified Sudoku puzzle with additional constraints. Args: sudoku (List[List[int]]): A 2D list representing the partially filled 9x9 Sudoku grid with...
def is_valid(board, row, col, num): """ Checks whether a given number can be placed at board[row][col] according to the Sudoku rules. """ # Check row for i in range(9): if board[row][i] == num: return False # Check column for i in range(9): if board[i][col] =...
from solution import solve_sudoku def test_solve_sudoku_no_constraints(): sudoku = [ [5, 3, 0, 0, 7, 0, 0, 0, 0], [6, 0, 0, 1, 9, 5, 0, 0, 0], [0, 9, 8, 0, 0, 0, 0, 6, 0], [8, 0, 0, 0, 6, 0, 0, 0, 3], [4, 0, 0, 8, 0, 3, 0, 0, 1], [7, 0, 0, 0, 2, 0, 0, 0, 6], ...
[ { "docstring": "Checks whether a given number can be placed at board[row][col]\naccording to the Sudoku rules.", "function_declaration": "def is_valid(board, row, col, num):", "function_name": "is_valid", "parameter_list": "(board, row, col, num)" }, { "docstring": "Backtracking helper funct...
[ 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 is_valid(board, row, col, num):\n \"\"\"\n Checks whether a given number can be placed at board[row][col]\n according to the Sudoku rules.\n \...
trial_gpt4o_0
{ "original_instruction": "**Problem Statement:**\n\nMario loves solving puzzles and has recently taken up solving Sudoku puzzles. In the traditional Sudoku puzzle, there is a 9x9 grid that needs to be filled with digits from 1 to 9. Each row, each column, and each of the 3x3 smaller grids must contain all the digits...
0.572427
Codeforces_19065
C
[ "is_valid", "solve_sudoku_helper", "validate_constraints", "solve_sudoku" ]
4
[ [ "solve_sudoku", "solve_sudoku_helper" ], [ "solve_sudoku", "validate_constraints" ], [ "solve_sudoku_helper", "is_valid" ] ]
3
[]
false
[]
false
pytest
true
[]
true
8e2df7b8d0c99ffca1d083e0a272d71e00fea93e
eade40ba414edad598246756100beaa000312bc9
v1.0
complete
Codeforces
Codeforces_19490_C
def find_path_in_grid(n: int, m: int, grid: List[str], r1: int, c1: int, r2: int, c2: int) -> str: """ Determine if there's a path between two cells in the grid that only moves through empty cells. The grid consists of '.' for empty cells and '#' for obstacles. Args: n (int): Number of rows. m (in...
def is_path_exists(n, m, grid, start, end): from collections import deque def is_valid(x, y): return 0 <= x < n and 0 <= y < m and grid[x][y] == '.' directions = [(-1, 0), (1, 0), (0, -1), (0, 1)] queue = deque([start]) visited = set([start]) while queue: x, y = queue.popleft(...
def test_find_path_in_grid_empty_grid(): n, m = 4, 4 grid = [ "....", "....", "....", "...." ] r1, c1, r2, c2 = 1, 1, 4, 4 assert find_path_in_grid(n, m, grid, r1, c1, r2, c2) == "YES" def test_find_path_in_grid_obstacle_blocking_path(): n, m = 4, 4 grid = [ ...
[ { "docstring": null, "function_declaration": "def is_path_exists(n, m, grid, start, end):", "function_name": "is_path_exists", "parameter_list": "(n, m, grid, start, end)" }, { "docstring": null, "function_declaration": "def find_path_in_grid(n, m, grid, r1, c1, r2, c2):", "function_...
[ 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": "from collections import deque\n\ndef is_path_exist(n, m, grid, r1, c1, r2, c2):\n directions = [(0, 1), (1, 0), (0, -1), (-1, 0)]\n \n def is_valid(x...
trial_gpt4o_8
{ "original_instruction": "You are given a grid with $$$n$$$ rows and $$$m$$$ columns. Each cell in the grid is initially either empty or occupied by an obstacle. You can move from one cell to another if they are adjacent (vertically or horizontally) and both are empty. \n\nGiven two cells in the grid, determine if t...
0.705203
Codeforces_19490
C
[ "is_path_exists", "find_path_in_grid" ]
2
[ [ "find_path_in_grid", "is_path_exists" ] ]
1
[]
false
[]
false
pytest
false
[]
true
59708a24e879bf1d8ede3def27276ac142d53f65
979f8f5b3e09f9b13ef2abe1fb37c7c498923dfe
v1.0
complete
Codeforces
Codeforces_19519_C
from typing import List def merge_sort(arr: List[int]) -> List[int]: """ Sorts an array of unique integers using merge sort algorithm. :param arr: List of unique integers :return: Sorted list of integers """ pass def test_merge_sort_basic_input(): assert merge_sort([3, 1, 2]) == [1, 2...
from typing import List def merge_sort(arr: List[int]) -> List[int]: """ Sorts an array of unique integers using merge sort algorithm. :param arr: List of unique integers :return: Sorted list of integers """ if len(arr) <= 1: return arr # Split the array into two halves mi...
from solution import merge_sort def test_merge_sort_basic_input(): assert merge_sort([3, 1, 2]) == [1, 2, 3] def test_merge_sort_large_input(): assert merge_sort([10, 5, 3, 2, 8, 6, 7, 4, 1, 9]) == [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] def test_merge_sort_empty_array(): assert merge_sort([]) == [] def test_me...
[ { "docstring": "Sorts an array of unique integers using merge sort algorithm.\n\n:param arr: List of unique integers\n:return: Sorted list of integers", "function_declaration": "def merge_sort(arr):", "function_name": "merge_sort", "parameter_list": "(arr)" }, { "docstring": null, "funct...
[ 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
9
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "from typing import List\n\ndef merge_sort(arr: List[int]) -> List[int]:\n \"\"\"\n Sorts an array of unique integers using merge sort algorithm.\n \n...
trial_gpt4o_9
{ "original_instruction": "Alex is exploring different sorting algorithms and wants to implement a function to sort an array of unique integers. However, he is particularly interested in understanding how merge sort works and would like to test his understanding by writing a version of it.\n\nGiven an array of unique...
0.626032
Codeforces_19519
C
[ "merge_sort", "merge" ]
2
[ [ "merge_sort", "merge" ] ]
1
[]
false
[]
false
pytest
true
[]
true
c57095aae9a2673e9232bb1257cafae5b7855965
afe322550c01ed701d31c8c883a92204b4ddaf3c
v1.0
complete
Codeforces
Codeforces_19485_C
def validate_coupon(coupon: str) -> str: """ Validates a given coupon code based on specific rules. Rules: - It must contain exactly 10 characters. - It must include at least one uppercase letter. - It must include at least one digit. - It must include at least one special character from the...
def validate_coupon(coupon): """ Validates a given coupon code based on specific rules. Rules: - It must contain exactly 10 characters. - It must include at least one uppercase letter. - It must include at least one digit. - It must include at least one special character from the set: {'#', ...
from solution import validate_coupon, process_coupons def test_validate_coupon_valid(): assert validate_coupon("A1b2C3d4E!") == "VALID" assert validate_coupon("A2b3D4c5E#") == "VALID" assert validate_coupon("M7n6O5p4*!") == "VALID" def test_validate_coupon_invalid_length(): assert validate_coupon("A1b...
[ { "docstring": "Validates a given coupon code based on specific rules.\nRules:\n- It must contain exactly 10 characters.\n- It must include at least one uppercase letter.\n- It must include at least one digit.\n- It must include at least one special character from the set: {'#', '@', '!', '*'}.\n\n:param coupon...
[ 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": "import re\n\ndef is_valid_coupon(coupon: str) -> bool:\n \"\"\"\n Returns True if the coupon is valid according to the specified rules, False otherwise....
trial_gpt4o_9
{ "original_instruction": "Write a program that helps in processing unique coupon codes for a marketing campaign. Each coupon code is a string containing alphanumeric characters, and it should be validated according to a specific set of rules:\n1. The coupon code must contain exactly 10 characters.\n2. It must includ...
0.558946
Codeforces_19485
C
[ "validate_coupon", "process_coupons" ]
2
[ [ "process_coupons", "validate_coupon" ] ]
1
[]
false
[]
false
pytest
true
[]
true
5b00111b84c691472aaa48963eac3d69dbcbde7c
5e9ec35831ccfae2713fbcc4eb9537e096d5ce17