version
stringclasses
1 value
style
stringclasses
2 values
subset
stringclasses
12 values
question_id
stringlengths
9
23
question
stringlengths
27
8.13k
solution
stringlengths
99
5.97k
test
stringlengths
105
4.45k
test_info
listlengths
0
13
gpt_pass_sequence
listlengths
1
10
gpt_pass_trial_num
int64
1
10
gpt_difficulty
stringclasses
3 values
gpt_pass_percentage
float64
0.1
1
trials
dict
chosen_trial
stringclasses
10 values
metadata
dict
benchmark_similarity
float64
0.16
0.93
benchmark_instruction
stringclasses
1 value
benchmark_task_id
stringclasses
1 value
filter_reason
stringclasses
1 value
base_id
stringlengths
7
21
variant
stringclasses
2 values
top_function_names
listlengths
2
13
n_top_functions
int64
2
13
helper_call_edges
listlengths
1
16
n_helper_call_edges
int64
1
16
harness_functions
listlengths
0
3
structural_wrapper
bool
1 class
class_names
listlengths
0
5
has_class
bool
2 classes
test_kind
stringclasses
1 value
test_has_solution_import
bool
2 classes
third_party_imports
listlengths
0
5
stdlib_only
bool
2 classes
question_norm_sha1
stringlengths
40
40
solution_ast_sha1
stringlengths
40
40
v1.0
instruct
Codeforces
Codeforces_14863_I
You are given an infinite chessboard. Each square on the board is uniquely identified by a pair of integers \((x, y)\), where \( x \) and \( y \) are both integers. A knight starts on the square \((0, 0)\). You are also given a list of target squares to which the knight can travel. A knight moves in an "L" shape, i.e....
from collections import deque def min_knight_moves(x, y): """ Function to calculate the minimum knight moves to reach the target (x, y) from (0, 0) """ # Directions a knight can move. directions = [ (2, 1), (2, -1), (-2, 1), (-2, -1), (1, 2), (1, -2), (-1, 2), (-1, -2) ] ...
from solution import min_knight_moves, solve_knight_moves def test_min_knight_moves(): assert min_knight_moves(2, 1) == 1 assert min_knight_moves(5, 5) == 4 assert min_knight_moves(-1, -1) == 2 assert min_knight_moves(0, 0) == 0 assert min_knight_moves(2, 2) == 4 assert min_knight_moves(1, 1) =...
[ { "docstring": "Function to calculate the minimum knight moves to reach the target (x, y) from (0, 0)", "function_declaration": "def min_knight_moves(x, y):", "function_name": "min_knight_moves", "parameter_list": "(x, y)" }, { "docstring": "Function to solve the minimum knight moves problem...
[ 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 min_knight_moves(targets):\n \"\"\"\n Returns the minimum number of moves required for the knight to reach each of ...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00014863", "row_id": 14863, "seed_ids": "[7510]" }
0.739476
Codeforces_14863
I
[ "min_knight_moves", "solve_knight_moves" ]
2
[ [ "solve_knight_moves", "min_knight_moves" ] ]
1
[]
false
[]
false
pytest
true
[]
true
77e01501042ced4aff79a0ef7533b018c5aba00d
aa4ca4216599b807b53c02c5acdad8678ab9dd2d
v1.0
instruct
Codeforces
Codeforces_14892_I
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. You will be given a number of cities, and some pairs of them are connected directly by roads. DZY can start from any city and travel along these roads to ...
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": "", "prompt_id": "00014892", "row_id": 14892, "seed_ids": "[2850]" }
0.754446
Codeforces_14892
I
[ "dfs", "longest_path" ]
2
[ [ "longest_path", "dfs" ] ]
1
[]
false
[]
false
pytest
true
[]
true
1584487e63feea8abe9502b6d4c935e039d7f211
9342909f8c9ab73a56ccf1acb28c301e3d32dff5
v1.0
instruct
Codeforces
Codeforces_14901_I
Jake, a software engineer, has developed a new encryption algorithm based on permutations of strings. The encryption of a given string \( s \) involves finding its lexicographical rank among all the permutations of the string that are smaller than or equal to \( s \) itself. The lexicographical rank is the position of ...
def factorial(n): result = 1 for i in range(2, n + 1): result *= i return result def find_lexicographical_rank(s: str) -> int: rank = 1 n = len(s) fact = factorial(n) for i in range(n): fact //= (n - i) smaller_chars = 0 for j in range(i + 1, n): ...
from solution import find_lexicographical_rank def test_example_case(): assert find_lexicographical_rank("bac") == 3 def test_single_character(): assert find_lexicographical_rank("a") == 1 def test_identical_characters(): assert find_lexicographical_rank("aaa") == 1 def test_sorted_string(): assert ...
[ { "docstring": null, "function_declaration": "def factorial(n):", "function_name": "factorial", "parameter_list": "(n)" }, { "docstring": null, "function_declaration": "def find_lexicographical_rank(s):", "function_name": "find_lexicographical_rank", "parameter_list": "(s)" } ]
[ 0, 0, 0, 0, 0, 0, 0, 0, 1 ]
1
hard
0.111
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def factorial(n):\n \"\"\"\n Returns the factorial of a given number n.\n \"\"\"\n if n == 0:\n return 1\n return n * factorial(n - 1)\n...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00014901", "row_id": 14901, "seed_ids": "[4664]" }
0.590096
Codeforces_14901
I
[ "factorial", "find_lexicographical_rank" ]
2
[ [ "find_lexicographical_rank", "factorial" ] ]
1
[]
false
[]
false
pytest
true
[]
true
0dc571f38515b4bd30fea3d711449ac90eb95815
cde99e9f4e7a6fcc101c16f7fb44e4146b15b03d
v1.0
instruct
Codeforces
Codeforces_14907_I
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 contiguous block of crops that ...
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": "", "prompt_id": "00014907", "row_id": 14907, "seed_ids": "[6494]" }
0.638068
Codeforces_14907
I
[ "dfs", "min_irrigation_systems" ]
2
[ [ "min_irrigation_systems", "dfs" ] ]
1
[]
false
[]
false
pytest
true
[]
true
2ba642b46091bff90e36804df3f7b6c1b410411b
5af8ed7a776d5f404b5eee84502c397cd5cead35
v1.0
instruct
Codeforces
Codeforces_15048_I
You are given a tree (not necessarily binary) with n nodes, where each node has a unique label from 1 to n. You are also given a list of m queries. Each query consists of two nodes u and v. For each query, you need to calculate the length of the shortest path from u to v in the tree. Input: - The first line contains t...
from collections import deque, defaultdict def bfs_depth_and_parent(n, edges): """ Perform BFS to determine depth of each node and its parent. :param n: Number of nodes :param edges: List of edges :return: (depth, parent) where depth[u] is the depth of node u and parent[u] is the parent of nod...
from solution import shortest_path_length def test_example_case(): n = 5 edges = [(1, 2), (1, 3), (3, 4), (3, 5)] queries = [(1, 5), (2, 4), (5, 5)] result = shortest_path_length(n, edges, queries) assert result == [2, 3, 0] def test_single_node_tree(): n = 1 edges = [] queries = [(1, ...
[ { "docstring": "Perform BFS to determine depth of each node and its parent.\n\n:param n: Number of nodes\n:param edges: List of edges\n:return: (depth, parent) where depth[u] is the depth of node u and parent[u] is the parent of node u", "function_declaration": "def bfs_depth_and_parent(n, edges):", "fu...
[ 0, 0, 0, 0, 1, 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 collections import defaultdict, deque\n\ndef bfs_distances_from_root(tree, n, root=1):\n \"\"\"\n Perform a BFS from the specified root and calcula...
trial_gpt4o_7
{ "original_instruction": "", "prompt_id": "00015048", "row_id": 15048, "seed_ids": "[2215]" }
0.701594
Codeforces_15048
I
[ "bfs_depth_and_parent", "lca", "shortest_path_length" ]
3
[ [ "shortest_path_length", "bfs_depth_and_parent" ], [ "shortest_path_length", "lca" ] ]
2
[]
false
[]
false
pytest
true
[]
true
4c0b6db958d79744a82d80981a3696a376c6b1b5
1bb3968ac36b59cf130a2cf50b50e6ad181142ee
v1.0
instruct
Codeforces
Codeforces_15064_I
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. The first line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n \le 10^5$$$, $$$0 \le m \le 10^5$$$). The next $$$m$$$ lines contain pairs of integers $$...
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": "", "prompt_id": "00015064", "row_id": 15064, "seed_ids": "[1458]" }
0.791077
Codeforces_15064
I
[ "find_cycle", "cycle_in_graph" ]
2
[ [ "cycle_in_graph", "find_cycle" ] ]
1
[]
false
[]
false
pytest
true
[]
true
63800a5e77e3ca272b732da36588140b8e0dccbb
b584e148c9246ea8851cb056d84003a88515d5aa
v1.0
instruct
Codeforces
Codeforces_15066_I
Samantha is training a newborn puppy and wants to create a personalized command list. Each command consists of a unique action and a unique object (for example, "sit_down" where "sit" is the action and "down" is the object). She has already identified a list of possible commands for her puppy. Unfortunately, the comma...
from collections import defaultdict def reorder_commands(n, commands): def is_valid_order(commands): for i in range(1, len(commands)): prev_action, prev_object = commands[i - 1].split('_') curr_action, curr_object = commands[i].split('_') if prev_action == curr_action or...
def test_restructure_commands_possible(): input_str = "4\nsit_down\nstay_still\nroll_over\nsit_stay" expected_output = "sit_down\nstay_still\nroll_over\nsit_stay" assert restructure_commands(input_str) == expected_output input_str = "3\njump_up\nsit_down\nstay_still" expected_output = "jump_up\...
[ { "docstring": null, "function_declaration": "def reorder_commands(n, commands):", "function_name": "reorder_commands", "parameter_list": "(n, commands)" }, { "docstring": null, "function_declaration": "def restructure_commands(input_str):", "function_name": "restructure_commands", ...
[ 0, 0, 0, 0, 0, 0, 0, 1, 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 restructure_commands(n, commands):\n from collections import defaultdict\n \n # Split each command into action and object\n commands_split = [...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00015066", "row_id": 15066, "seed_ids": "[270]" }
0.498666
Codeforces_15066
I
[ "reorder_commands", "restructure_commands" ]
2
[ [ "restructure_commands", "reorder_commands" ] ]
1
[]
false
[]
false
pytest
false
[]
true
bc8491d3cd5451302b08100b02a4a5529281c9b3
be56ed0d88e9c83e94c26500ba856945d0f4f107
v1.0
instruct
Codeforces
Codeforces_15072_I
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 when generating permutations, an...
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": "", "prompt_id": "00015072", "row_id": 15072, "seed_ids": "[8185]" }
0.757807
Codeforces_15072
I
[ "unique_permutations", "print_permutations" ]
2
[ [ "print_permutations", "unique_permutations" ] ]
1
[]
false
[]
false
pytest
true
[]
true
b98064a57ec8052ec03dbcf6aec08445c1a8ced7
b367254aa0e8b83fdca12751e7434c3c0dae195c
v1.0
instruct
Codeforces
Codeforces_15076_I
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. A Fibonacci number sequence is defined as follows: - F(0) = 0 - F(1) = 1 - F(n) = F(n-1) + F(n-2) for n > 1 Dr. Euler wants...
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": "", "prompt_id": "00015076", "row_id": 15076, "seed_ids": "[183]" }
0.650175
Codeforces_15076
I
[ "fibonacci_sequence_up_to_n", "count_encodings" ]
2
[ [ "count_encodings", "fibonacci_sequence_up_to_n" ] ]
1
[]
false
[]
false
pytest
true
[]
true
fd8062a40a6e3ce1a47007490becffed234c51be
3fd354ce0ae1d880772295124f4d30c62aadbace
v1.0
instruct
Codeforces
Codeforces_15189_I
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. Vasya wants to reorder them ...
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": "", "prompt_id": "00015189", "row_id": 15189, "seed_ids": "[3639]" }
0.547941
Codeforces_15189
I
[ "generate_moves", "reorder_containers" ]
2
[ [ "reorder_containers", "generate_moves" ] ]
1
[]
false
[]
false
pytest
true
[]
true
b06e01571a64fccbf2920119cf2f983c6c5cc8b9
cf8c9e90ce9c1e4e9e831fff314661a936545e60
v1.0
instruct
Codeforces
Codeforces_15191_I
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. The first line contains two integers, $$$n$$$ and $$$m$$$, which denote the number of vertices and edges in the graph, respectively ($$$1 \le...
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": "", "prompt_id": "00015191", "row_id": 15191, "seed_ids": "[8096]" }
0.62824
Codeforces_15191
I
[ "has_hamiltonian_cycle", "hamiltonian_cycle_checker" ]
2
[ [ "hamiltonian_cycle_checker", "has_hamiltonian_cycle" ] ]
1
[]
false
[]
false
pytest
true
[]
true
1d40c093bff1895f2e89fd712dc4e4f4243b56b4
b555223fa378e439c3674a778cfc29bcc02fe76c
v1.0
instruct
Codeforces
Codeforces_15241_I
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$$$ and $$$v$$$. If there is no p...
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": "", "prompt_id": "00015241", "row_id": 15241, "seed_ids": "[8144]" }
0.782619
Codeforces_15241
I
[ "floyd_warshall", "shortest_path" ]
2
[ [ "shortest_path", "floyd_warshall" ] ]
1
[]
false
[]
false
pytest
true
[]
true
4d5270b29c5713441c3281ac82214abad090f7cf
105dfbe0e9d61d640ff8b15bb2913564d6f9e7dd
v1.0
instruct
Codeforces
Codeforces_15266_I
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. Given a positive integer n (1 ≤ n ≤ 500), write ...
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": "", "prompt_id": "00015266", "row_id": 15266, "seed_ids": "[771]" }
0.536821
Codeforces_15266
I
[ "is_prime", "emirp_numbers" ]
2
[ [ "emirp_numbers", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
9fcd3c9c3ec9d31e39a2300e46769230e480632e
f5514c642cb9ec659231ea3a546cc0ec5b986299
v1.0
instruct
Codeforces
Codeforces_15345_I
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 comfort zone is an interval [li, r...
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": "", "prompt_id": "00015345", "row_id": 15345, "seed_ids": "[7051]" }
0.722076
Codeforces_15345
I
[ "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
1a301956066ee938543746be26f29e85e8d20e08
1862358d3500df931063a835b3277a6338e3eb70
v1.0
instruct
Codeforces
Codeforces_15374_I
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. The company wants to ensure efficient routing ...
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": "", "prompt_id": "00015374", "row_id": 15374, "seed_ids": "[4943]" }
0.753842
Codeforces_15374
I
[ "shortest_path", "min_new_roads" ]
2
[ [ "min_new_roads", "shortest_path" ] ]
1
[]
false
[]
false
pytest
true
[]
true
b531e2023252e35e50a5ac5fc0102bb4f554d2a8
2fcdbaca55a963304774ffba1bf8becbb9ef0472
v1.0
instruct
Codeforces
Codeforces_15375_I
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 {!@#$%^&*()}. The password length must b...
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": "", "prompt_id": "00015375", "row_id": 15375, "seed_ids": "[6277]" }
0.56504
Codeforces_15375
I
[ "is_password_secure", "analyze_passwords" ]
2
[ [ "analyze_passwords", "is_password_secure" ] ]
1
[]
false
[]
false
pytest
true
[]
true
c32f4e9a890641171e674b1b354633963f303865
1534de70756b521220e9665d9f622ee6051328ca
v1.0
instruct
Codeforces
Codeforces_15436_I
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. Input: The input consists of two lines. The first line contains an integer n (2 ≤ n ≤ 1000) — the ...
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": "", "prompt_id": "00015436", "row_id": 15436, "seed_ids": "[5543]" }
0.750487
Codeforces_15436
I
[ "is_prime", "find_adjacent_prime_sum_indices" ]
2
[ [ "find_adjacent_prime_sum_indices", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
06c212c23da7652e3f9d9168b47acdf88b3df228
71c505d6dd2e409d601a645afdb8aaadea11eba3
v1.0
instruct
Codeforces
Codeforces_15466_I
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. The first line of the input contains an integer `n` (2 ≤ n ≤ 1000) — the number of nodes in ...
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": "", "prompt_id": "00015466", "row_id": 15466, "seed_ids": "[5965]" }
0.680547
Codeforces_15466
I
[ "find_farthest_node", "tree_diameter", "solve" ]
3
[ [ "solve", "tree_diameter" ], [ "tree_diameter", "find_farthest_node" ] ]
2
[]
false
[]
false
pytest
true
[]
true
e73a339cc988441810b7e8154b4182c9055d2177
97f3c2ce233f4d6353be8ff125cd29fc651bcea4
v1.0
instruct
Codeforces
Codeforces_15497_I
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 from the left. Visibility of...
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": "", "prompt_id": "00015497", "row_id": 15497, "seed_ids": "[4989]" }
0.647153
Codeforces_15497
I
[ "calculate_visibility", "best_position" ]
2
[ [ "best_position", "calculate_visibility" ] ]
1
[]
false
[]
false
pytest
true
[]
true
d7b79ffafbbc6494811389a085051265e405aaf3
83389300d74438d6436598e59d47e40c03b39253
v1.0
instruct
Codeforces
Codeforces_15559_I
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 and no plants overlap each othe...
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": "", "prompt_id": "00015559", "row_id": 15559, "seed_ids": "[4289]" }
0.653502
Codeforces_15559
I
[ "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
5c2a774a38e9fda89f037d45df49560ae3085da6
48cb7e6dae753f07e1e1c10d2d90df8ea738458d
v1.0
instruct
Codeforces
Codeforces_15589_I
#### Efficiently Merging Meetings You 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). Your task is to merge all overla...
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": "", "prompt_id": "00015589", "row_id": 15589, "seed_ids": "[2088]" }
0.573884
Codeforces_15589
I
[ "merge_meetings", "process_input_and_solve" ]
2
[ [ "process_input_and_solve", "merge_meetings" ] ]
1
[]
false
[]
false
pytest
true
[]
true
46a4c2a032494143a8823c422857164c6c091198
aae6bd33380b92fb5345c5a9afd035ca335dfbc4
v1.0
instruct
Codeforces
Codeforces_15723_I
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 because 1 + 9 = 10, and then 1 + 0 =...
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": "", "prompt_id": "00015723", "row_id": 15723, "seed_ids": "[4333]" }
0.658697
Codeforces_15723
I
[ "is_happy_number", "is_happy_sequence" ]
2
[ [ "is_happy_sequence", "is_happy_number" ] ]
1
[]
false
[]
false
pytest
true
[]
true
d6c5b864aa37a91bd22f9658b6fabe8e5fc36af0
e20024b25017499167ffa1b53c22870955f0733d
v1.0
instruct
Codeforces
Codeforces_15732_I
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 the elements of the sublist a...
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": "", "prompt_id": "00015732", "row_id": 15732, "seed_ids": "[1998]" }
0.640183
Codeforces_15732
I
[ "max_sublist_sum", "max_row_sum" ]
2
[ [ "max_row_sum", "max_sublist_sum" ] ]
1
[]
false
[]
false
pytest
true
[]
true
1ec5d96901b0b19aaa296a332a1d86ebf5edcc3c
68002273f7d25c0655c8255fcdcb5ec90c16397e
v1.0
instruct
Codeforces
Codeforces_15816_I
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 largest possible rectangular sub-gri...
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": "", "prompt_id": "00015816", "row_id": 15816, "seed_ids": "[3546]" }
0.637522
Codeforces_15816
I
[ "maximalRectangle", "largestRectangleArea", "largest_fertile_subgrid" ]
3
[ [ "largest_fertile_subgrid", "maximalRectangle" ], [ "maximalRectangle", "largestRectangleArea" ] ]
2
[]
false
[]
false
pytest
false
[]
true
a0eeefc8796e4e57c7f5135d907eb2b6a8257378
e99e7919b6e2a55848f6bfb358f6597bb7cbffeb
v1.0
instruct
Codeforces
Codeforces_15838_I
A city is represented as a grid with $$$n$$$ rows and $$$m$$$ columns. Each cell of the grid can either be empty or contain an obstacle. You need to count the number of unique paths from the top-left corner of the grid (cell $$$1,1$$$) to the bottom-right corner of the grid (cell $$$n,m$$$). The only movements allowed ...
def unique_paths_with_obstacles(grid): n = len(grid) m = len(grid[0]) if grid[0][0] == '#' or grid[n-1][m-1] == '#': return 0 dp = [[0]*m for _ in range(n)] dp[0][0] = 1 for i in range(n): for j in range(m): if grid[i][j] == '#': dp[...
def test_unique_paths_no_obstacles(): input_str = "3 3\n...\n...\n..." assert read_input_and_solve(input_str) == 6 def test_unique_paths_with_obstacles(): input_str = "3 3\n...\n.#.\n..." assert read_input_and_solve(input_str) == 2 def test_no_path_due_to_start(): input_str = "2 2\n#.\n.." ass...
[ { "docstring": null, "function_declaration": "def unique_paths_with_obstacles(grid):", "function_name": "unique_paths_with_obstacles", "parameter_list": "(grid)" }, { "docstring": null, "function_declaration": "def read_input_and_solve(input_str):", "function_name": "read_input_and_s...
[ 0, 0, 0, 0, 1, 0, 0, 1, 0, 1 ]
3
hard
0.3
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def unique_paths_with_obstacles(n, m, grid):\n if grid[0][0] == '#' or grid[n-1][m-1] == '#':\n return 0\n\n dp = [[0]*m for _ in range(n)]\n ...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00015838", "row_id": 15838, "seed_ids": "[2493]" }
0.760129
Codeforces_15838
I
[ "unique_paths_with_obstacles", "read_input_and_solve" ]
2
[ [ "read_input_and_solve", "unique_paths_with_obstacles" ] ]
1
[]
false
[]
false
pytest
false
[]
true
404643a5fadaca45b8cb5bd25789e3fb511aa383
f980361b80a616d97de4ed98288f8db9fddad276
v1.0
instruct
Codeforces
Codeforces_15855_I
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. To organize this system, you are given a list of books, where each book is represen...
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": "", "prompt_id": "00015855", "row_id": 15855, "seed_ids": "[7440]" }
0.731419
Codeforces_15855
I
[ "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
d09e1cb74a6b1baa522e1e3ab3fdf08f82ae5e2f
c0ab4ee9d8cb1844a8e3b5eea7906b41ae6c0d49
v1.0
instruct
Codeforces
Codeforces_15861_I
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 difference between the two hous...
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": "", "prompt_id": "00015861", "row_id": 15861, "seed_ids": "[1533]" }
0.708346
Codeforces_15861
I
[ "min_houses_to_pass", "solve_water_pipeline" ]
2
[ [ "solve_water_pipeline", "min_houses_to_pass" ] ]
1
[]
false
[]
false
pytest
true
[]
true
5fa3a75cd6d10fb8cb0c6aad23da1e2034f458f2
161e68bd75721ee5b39812dce162c3754a334b7c
v1.0
instruct
Codeforces
Codeforces_15885_I
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 sequence, the sum of digits in...
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": "", "prompt_id": "00015885", "row_id": 15885, "seed_ids": "[2635]" }
0.601654
Codeforces_15885
I
[ "is_binary_palindrome", "palindromic_base_sequence" ]
2
[ [ "palindromic_base_sequence", "is_binary_palindrome" ] ]
1
[]
false
[]
false
pytest
true
[]
true
862e6aa7b6542d136c44d984b483a1cf77679437
80187bd26cb6630a2199b9b7fad229b8828ca3c7
v1.0
instruct
Codeforces
Codeforces_15964_I
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$$$. The operation for that day involves rotatin...
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": "", "prompt_id": "00015964", "row_id": 15964, "seed_ids": "[1506]" }
0.773591
Codeforces_15964
I
[ "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
56d31bf96ac5ab8ea1fe291565b4cf578e0c55b7
10330948be849b6a1cfdc7707c672a45f7aabe15
v1.0
instruct
Codeforces
Codeforces_16058_I
You're given a list of 'n' integers, each representing the calorie count of a different food item. You want to split this list into 'm' contiguous sublists such that the maximum sum of calories in any of the sublists is minimized. In other words, you want to divide the list into 'm' contiguous parts where the largest s...
from typing import List def can_split(nums: List[int], m: int, max_sum: int) -> bool: current_sum = 0 sublist_count = 1 for num in nums: if current_sum + num > max_sum: sublist_count += 1 current_sum = num if sublist_count > m: return False ...
from solution import find_minimized_max_sum def test_find_minimized_max_sum_example(): assert find_minimized_max_sum([4, 2, 4, 7, 3, 6, 1], 3) == 10 def test_find_minimized_max_sum_single_element(): assert find_minimized_max_sum([10], 1) == 10 def test_find_minimized_max_sum_equal_elements(): assert find...
[ { "docstring": null, "function_declaration": "def can_split(nums, m, max_sum):", "function_name": "can_split", "parameter_list": "(nums, m, max_sum)" }, { "docstring": null, "function_declaration": "def find_minimized_max_sum(calories, m):", "function_name": "find_minimized_max_sum",...
[ 0, 1, 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 find_minimized_max_sum(calories, m):\n def can_split(max_sum, m):\n current_sum = 0\n sublists = 1\n for calorie in calories:\n ...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00016058", "row_id": 16058, "seed_ids": "[2717]" }
0.640477
Codeforces_16058
I
[ "can_split", "find_minimized_max_sum" ]
2
[ [ "find_minimized_max_sum", "can_split" ] ]
1
[]
false
[]
false
pytest
true
[]
true
30348fb725fc1c1ee37769364b66b8c7167562d0
64874842302e432b2df7b7600f4890db1f49beae
v1.0
instruct
Codeforces
Codeforces_16081_I
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: Determine the minimum number of moves required to traverse from the top-left corner of the board (cell (1, 1)) to t...
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": "", "prompt_id": "00016081", "row_id": 16081, "seed_ids": "[4428]" }
0.806772
Codeforces_16081
I
[ "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
45efcbfef01aee47786b2477a85e725e8e9d5bbf
f2feec60f4821e3e5fbb831375555c7046b98128
v1.0
instruct
Codeforces
Codeforces_16248_I
Billing System Simulations You 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. There are three types of customers: **Residential**, **Commercial**, and **Industrial**. Each type has a dif...
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": "", "prompt_id": "00016248", "row_id": 16248, "seed_ids": "[1230]" }
0.574156
Codeforces_16248
I
[ "calculate_bill", "generate_bills" ]
2
[ [ "generate_bills", "calculate_bill" ] ]
1
[]
false
[]
false
pytest
true
[]
true
4924594c5308cb2ac07732ce37b993c174363e8b
00c764b55a12ac8474ed83485d3d31ad2ece6efc
v1.0
instruct
Codeforces
Codeforces_16270_I
A company is organizing a conference, and they want to schedule a series of lectures in multiple rooms, ensuring that there are no conflicts. Each lecture has a start time and an end time, and no two lectures in the same room can overlap. Given the schedule of lectures, the company wants to determine the minimum number...
import heapq def min_rooms(lectures): """ Calculates the minimum number of conference rooms required for the given lectures. lectures: List of tuples (start_time, end_time) Returns an integer representing the number of required rooms. """ if not lectures: return 0 lectures...
import pytest from solution import min_rooms, main def test_min_rooms_simple(): assert min_rooms([(1, 4), (2, 3), (3, 5)]) == 2 assert min_rooms([(2, 7), (3, 8)]) == 2 assert min_rooms([(1, 2), (3, 4), (5, 6)]) == 1 assert min_rooms([(1, 5), (1, 5), (1, 5)]) == 3 assert min_rooms([(5, 10), (5, 10),...
[ { "docstring": "Calculates the minimum number of conference rooms required for the given lectures.\nlectures: List of tuples (start_time, end_time)\n\nReturns an integer representing the number of required rooms.", "function_declaration": "def min_rooms(lectures):", "function_name": "min_rooms", "pa...
[ 0, 1, 0, 0, 0, 1, 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": "import heapq\n\ndef min_conference_rooms(lectures):\n \"\"\"\n Calculate the minimum number of conference rooms required to accommodate all lectures wit...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00016270", "row_id": 16270, "seed_ids": "[5389]" }
0.697178
Codeforces_16270
I
[ "min_rooms", "solve", "parse_input", "main" ]
4
[ [ "solve", "min_rooms" ] ]
1
[ "parse_input" ]
false
[]
false
pytest
true
[]
true
44e99a660bf0e8b82541c307c3c0221bbfa26012
2f22e16f9a93f1af3fef26e63654c1ed9b53552f
v1.0
instruct
Codeforces
Codeforces_16287_I
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. You are given the tree represented as a list of edges, with each ed...
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": "", "prompt_id": "00016287", "row_id": 16287, "seed_ids": "[5949]" }
0.729431
Codeforces_16287
I
[ "find_furthest_node", "tree_diameter", "solve" ]
3
[ [ "solve", "tree_diameter" ], [ "tree_diameter", "find_furthest_node" ] ]
2
[]
false
[]
false
pytest
true
[]
true
7d17b6ac8deeec6e24ba636e09b77aa085413c6a
4b708286a6496e2d0c8c3a2a666f0e1595d39025
v1.0
instruct
Codeforces
Codeforces_16395_I
You are given a grid with dimensions $$$n \times m$$$ initially filled with numbers. You need to perform the following query operation multiple times: 1. Update the value of the cell at position (row, col) to a new value specified. After all the updates, return the current state of the grid. The first line of input ...
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": "", "prompt_id": "00016395", "row_id": 16395, "seed_ids": "[3614]" }
0.67253
Codeforces_16395
I
[ "update_grid", "perform_grid_operations" ]
2
[ [ "perform_grid_operations", "update_grid" ] ]
1
[]
false
[]
false
pytest
true
[]
true
64af6c5f7540495839357740e90ab492cf273baa
7ddc6acdf0cef94f86ecfef3a0e8f969bbb6a7c6
v1.0
instruct
Codeforces
Codeforces_16396_I
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 exactly one other planet, creati...
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": "", "prompt_id": "00016396", "row_id": 16396, "seed_ids": "[3114]" }
0.590186
Codeforces_16396
I
[ "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
a64437245bbfc0b55e4c892411aacd640c66b142
50e9edd4eb84dc898b3aa9d71dd29d0f87624ae1
v1.0
instruct
Codeforces
Codeforces_16409_I
You are given two arrays $$$A$$$ and $$$B$$$ of lengths $$$n$$$ and $$$m$$$, respectively. Arrays can only contain positive integers. You 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 array $$$[2, 3, 4, 5]$$$ you ca...
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": "", "prompt_id": "00016409", "row_id": 16409, "seed_ids": "[7613]" }
0.720403
Codeforces_16409
I
[ "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
3a9bb8f9955454cafb62ce54cf0018eb5841bc96
a91a1824b55fb48ab356d3a5168281154c7d1ec9
v1.0
instruct
Codeforces
Codeforces_16417_I
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 is the sum of the previous tw...
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": "", "prompt_id": "00016417", "row_id": 16417, "seed_ids": "[5110]" }
0.70407
Codeforces_16417
I
[ "is_fibonacci", "check_fibonacci_numbers" ]
2
[ [ "check_fibonacci_numbers", "is_fibonacci" ] ]
1
[]
false
[]
false
pytest
true
[]
true
88932f520717f9b5872dde06b429b6be9e99ff41
2ba2385e0c09c0b0849168d9d9c2925861e45563
v1.0
instruct
Codeforces
Codeforces_16441_I
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 creating a new set of roads ...
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": "", "prompt_id": "00016441", "row_id": 16441, "seed_ids": "[3350]" }
0.712046
Codeforces_16441
I
[ "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
ebefa46b09feb7011ba2e0718eaf568b78fb980c
4f0e41e17ad9857bcdd497c97a527ded3b4567bb
v1.0
instruct
Codeforces
Codeforces_16472_I
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 grid (position (m-1, n-1)). Howe...
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": "", "prompt_id": "00016472", "row_id": 16472, "seed_ids": "[3345]" }
0.830414
Codeforces_16472
I
[ "unique_paths_with_obstacles", "parse_input", "solve" ]
3
[ [ "solve", "parse_input" ], [ "solve", "unique_paths_with_obstacles" ] ]
2
[ "parse_input" ]
false
[]
false
pytest
true
[]
true
2436371b1c25bce3c2b76d23f3933be5ea8fc05b
c3a477a065944ddf1d3b70476eeef776eda6de10
v1.0
instruct
Codeforces
Codeforces_16544_I
You are given an undirected graph with $$$n$$$ nodes and $$$m$$$ edges. Each node in the graph has a value associated with it. You need to perform the following queries on the graph: 1. Find and print the maximum node value in the connected component of the graph that contains node $$$u$$$. **Input:** The first line...
def find_connected_components(n, edges): from collections import defaultdict # Create adjacency list graph = defaultdict(list) for u, v in edges: graph[u].append(v) graph[v].append(u) visited = [False] * (n + 1) components = [] def dfs(node, component): ...
def test_simple_case(): n = 5 m = 4 values = [1, 2, 3, 4, 5] edges = [(1, 2), (2, 3), (4, 5), (1, 5)] queries = [2, 4, 1] expected_output = [5, 5, 5] assert max_node_value(n, m, values, edges, queries) == expected_output def test_disconnected_graph(): n = 4 m = 2 values = [1, 3,...
[ { "docstring": null, "function_declaration": "def find_connected_components(n, edges):", "function_name": "find_connected_components", "parameter_list": "(n, edges)" }, { "docstring": null, "function_declaration": "def preprocess_components(n, values, components):", "function_name": ...
[ 1, 0, 0, 0, 0, 0, 0, 0, 1, 0 ]
2
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "from collections import defaultdict, deque\n\ndef find_max_node_values(n, m, node_values, edges, queries):\n graph = defaultdict(list)\n for u, v in edg...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00016544", "row_id": 16544, "seed_ids": "[3897]" }
0.81273
Codeforces_16544
I
[ "find_connected_components", "preprocess_components", "max_node_value" ]
3
[ [ "max_node_value", "find_connected_components" ], [ "max_node_value", "preprocess_components" ] ]
2
[]
false
[]
false
pytest
false
[]
true
80f547ddf9b0f88bb2c7b6f561aee3377894807b
e1212107e39ba10f32a5d88ac6d6f4d20cbc9bfd
v1.0
instruct
Codeforces
Codeforces_16567_I
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. For example, given the array `arr = [-2, 1, -3, 4, -1, 2, 1, -5, 4]`, the contiguous subarray with t...
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": "", "prompt_id": "00016567", "row_id": 16567, "seed_ids": "[528]" }
0.745708
Codeforces_16567
I
[ "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
bd3235f9829d2e583d5a6aa16f16bb00c62842db
a649bff520a6f7426b0ea078753173af4dde8ac2
v1.0
instruct
Codeforces
Codeforces_16570_I
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. The first line contains an integer n (1 ≤ n ≤ 10^5) — the number of nodes in the tree...
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": "", "prompt_id": "00016570", "row_id": 16570, "seed_ids": "[1319]" }
0.564746
Codeforces_16570
I
[ "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
4d3515decb7cf2619c9cce74d8d081d96da170d3
7387a57e72f2ad0ffa9a519939c3181d5cc33fba
v1.0
instruct
Codeforces
Codeforces_16575_I
A company is developing a custom spell checker for their word processing software. They need a function that takes a dictionary of correct words and a list of typed words, and returns a list indicating if each typed word is correctly spelled or, if not, suggesting the closest word from the dictionary. If there are ties...
from typing import List def edit_distance(word1: str, word2: str) -> int: """ Calculate the edit distance between two words using dynamic programming. """ len1, len2 = len(word1), len(word2) dp = [[0] * (len2 + 1) for _ in range(len1 + 1)] for i in range(len1 + 1): for j in range(l...
from solution import spell_check def test_correct_words(): dictionary = ["apple", "banana", "orange", "grape"] typed_words = ["apple", "banana", "orange", "grape"] assert spell_check(dictionary, typed_words) == ["apple", "banana", "orange", "grape"] def test_typo_words(): dictionary = ["apple", "banan...
[ { "docstring": "Calculate the edit distance between two words using dynamic programming.", "function_declaration": "def edit_distance(word1, word2):", "function_name": "edit_distance", "parameter_list": "(word1, word2)" }, { "docstring": null, "function_declaration": "def spell_check(dic...
[ 1, 1, 0, 0, 1, 1, 1, 1, 1, 0 ]
7
easy
0.7
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "from typing import List\n\ndef edit_distance(word1: str, word2: str) -> int:\n \"\"\"\n Compute the edit distance between two words using dynamic progra...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00016575", "row_id": 16575, "seed_ids": "[8212]" }
0.611704
Codeforces_16575
I
[ "edit_distance", "spell_check" ]
2
[ [ "spell_check", "edit_distance" ] ]
1
[]
false
[]
false
pytest
true
[]
true
9798ce812efd0d0e6d6a6011f3f1396d94da7de9
40b09887f795a96189ae4a1e51641f1425b82415
v1.0
instruct
Codeforces
Codeforces_16622_I
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 right) but cannot pass through ...
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": "", "prompt_id": "00016622", "row_id": 16622, "seed_ids": "[6538]" }
0.684952
Codeforces_16622
I
[ "bfs_shortest_distance", "shortest_distances_to_treasures" ]
2
[ [ "shortest_distances_to_treasures", "bfs_shortest_distance" ] ]
1
[]
false
[]
false
pytest
false
[]
true
2b2307e4967bc867cdb033ac93a15a6d7c208f9a
75cccb865e44e37d80cd60303863bac71f06a19b
v1.0
instruct
Codeforces
Codeforces_16631_I
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. Each travel request contains two castles, an...
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": "", "prompt_id": "00016631", "row_id": 16631, "seed_ids": "[272]" }
0.712309
Codeforces_16631
I
[ "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
6c4e1e989b68c75ac15a6812143b64dd433cc62e
c74cbe458c53e9de0d48ccf1b6438c820b21d44d
v1.0
instruct
Codeforces
Codeforces_16731_I
You are given a grid consisting of $$$n$$$ rows and $$$m$$$ columns ($$$1 \leq n, m \leq 1000$$$). Each cell in the grid either contains a **0** or a **1**. Your task is to count the number of unique islands in the grid. An island is defined as a group of connected **1s** (cells containing 1). Two cells are connected i...
def find_unique_islands(grid): """ Returns the number of unique islands in the grid. """ n = len(grid) m = len(grid[0]) def dfs(x, y, base_x, base_y, island): if x < 0 or x >= n or y < 0 or y >= m or grid[x][y] == 0: return grid[x][y] = 0 # Mark as visited i...
from solution import count_unique_islands def test_example_1(): grid = [ [1, 1, 0, 0, 0], [1, 0, 0, 1, 1], [0, 0, 0, 1, 0], [1, 1, 0, 0, 0] ] assert count_unique_islands(4, 5, grid) == 2 def test_example_2(): grid = [ [1, 1, 1], [1, 0, 1], [1, 1,...
[ { "docstring": "Returns the number of unique islands in the grid.", "function_declaration": "def find_unique_islands(grid):", "function_name": "find_unique_islands", "parameter_list": "(grid)" }, { "docstring": "Wrapper function to handle input and output\nReturns the number of unique island...
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def num_unique_islands(grid):\n def dfs(r, c, r0, c0):\n # Traverse the island and record the relative position of each cell\n grid[r][c] = 0...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00016731", "row_id": 16731, "seed_ids": "[8018]" }
0.65029
Codeforces_16731
I
[ "find_unique_islands", "count_unique_islands" ]
2
[ [ "count_unique_islands", "find_unique_islands" ] ]
1
[]
false
[]
false
pytest
true
[]
true
785efeb86828c03ce7cab98e8b14f6063d29f8e8
c3b315546070091dfd776781c3b4c496445917a7
v1.0
instruct
Codeforces
Codeforces_16755_I
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 value of 1, 'b' has a value of...
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": "", "prompt_id": "00016755", "row_id": 16755, "seed_ids": "[6949]" }
0.581517
Codeforces_16755
I
[ "calculate_word_value", "count_special_synonym_pairs" ]
2
[ [ "count_special_synonym_pairs", "calculate_word_value" ] ]
1
[]
false
[]
false
pytest
true
[]
true
1723300dc99ad2035cde125e6495817aa0d8b607
5d4a18f442d92ef8278b94e56ed3b918a03c66f0
v1.0
instruct
Codeforces
Codeforces_16774_I
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: 1. The sum of its digits is equal to the sum of its reversed digits. 2. All digits in the id...
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": "", "prompt_id": "00016774", "row_id": 16774, "seed_ids": "[4690]" }
0.589018
Codeforces_16774
I
[ "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
497cfacc11b222462e9f7afc575997ee72f81e42
6381486ca3db600d414304eb8cbb31bcb3076a11
v1.0
instruct
Codeforces
Codeforces_16786_I
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. The objective is to calculate the minimum distance one needs to travel from the top-left corner of the grid to the b...
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": "", "prompt_id": "00016786", "row_id": 16786, "seed_ids": "[1921]" }
0.733818
Codeforces_16786
I
[ "min_distance", "min_distance_wrapper" ]
2
[ [ "min_distance_wrapper", "min_distance" ] ]
1
[]
false
[]
false
pytest
true
[]
true
d6ceaa0e349ffcc10a37583dd5645f4a6b55635c
a0a28493be8c7e7a7ecb877775cd0515e6007507
v1.0
instruct
Codeforces
Codeforces_16793_I
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. The sequence is given in level order traversal format, where each number represents a node value. ...
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": "", "prompt_id": "00016793", "row_id": 16793, "seed_ids": "[4984]" }
0.563089
Codeforces_16793
I
[ "insertLevelOrder", "height", "compute_tree_height" ]
3
[ [ "compute_tree_height", "height" ], [ "compute_tree_height", "insertLevelOrder" ] ]
2
[]
false
[ "TreeNode" ]
true
pytest
true
[]
true
b68746c937011338a8d391bdc0e10080eb898b5b
a831cfcdb87b044bb679cc2792c12fe773fecd30
v1.0
instruct
Codeforces
Codeforces_16845_I
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. The first line of input contains an integer, $$$n$$$, which represents the number of nodes in the binary tree ($$$1 \le n \le 10^4$$$). ...
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": "", "prompt_id": "00016845", "row_id": 16845, "seed_ids": "[582]" }
0.795792
Codeforces_16845
I
[ "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
367bc50d1fbb96161c495e3bb524666361e47ece
c628119ad98b0a9b8175732dc2cc3cb76cb8f979
v1.0
instruct
Codeforces
Codeforces_16910_I
You have a list of integers where each element represents the height of a person. You need to re-arrange the list in such a way that each person's height is greater than or equal to the height of the person immediately before them, without changing the relative order of people shorter than a given threshold. The first...
def rearrange_heights(n, heights, t): sorted_heights = sorted([h for h in heights if h >= t]) result = [] j = 0 for i in range(n): if heights[i] >= t: result.append(sorted_heights[j]) j += 1 else: result.append(heights[i]) return result # Function...
from solution import rearrange_heights_from_input def test_rearrange_heights_no_change_needed(): assert rearrange_heights_from_input(5, "1 2 3 4 5", 10) == [1, 2, 3, 4, 5] def test_rearrange_heights_all_below_threshold(): assert rearrange_heights_from_input(5, "1 2 3 4 5", 6) == [1, 2, 3, 4, 5] def test_rear...
[ { "docstring": null, "function_declaration": "def rearrange_heights(n, heights, t):", "function_name": "rearrange_heights", "parameter_list": "(n, heights, t)" }, { "docstring": null, "function_declaration": "def rearrange_heights_from_input(n, heights_list, t):", "function_name": "r...
[ 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 rearrange_heights(n, heights, t):\n \"\"\"\n Rearrange heights list such that each person's height is in non-decreasing\n order while preserving ...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00016910", "row_id": 16910, "seed_ids": "[310]" }
0.654269
Codeforces_16910
I
[ "rearrange_heights", "rearrange_heights_from_input" ]
2
[ [ "rearrange_heights_from_input", "rearrange_heights" ] ]
1
[]
false
[]
false
pytest
true
[]
true
07e6ea540a3ea9abf1c4d38988828ec7261c2f66
aa11364a71f1d0a0a6e168d0df83bc132b7f1f8d
v1.0
instruct
Codeforces
Codeforces_17295_I
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$$$. You are also given $$$q$$$ queries. Each query con...
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": "", "prompt_id": "00017295", "row_id": 17295, "seed_ids": "[5003]" }
0.723028
Codeforces_17295
I
[ "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
cf48f3bf221a1f3fe1c20abc2a947dbe46d81c66
6db95da0201066eee4ed1548aafdff49c3280af4
v1.0
instruct
Codeforces
Codeforces_17389_I
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 least one empty plot. The g...
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": "", "prompt_id": "00017389", "row_id": 17389, "seed_ids": "[4283]" }
0.607773
Codeforces_17389
I
[ "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
cc51eadc62784e9311d5e941bf6bf4a9f1af810c
f63fbc81126135c061142f6a1a515e50940d8179
v1.0
instruct
Codeforces
Codeforces_17401_I
Given an array of integers, rotate the array to the right by k steps, where k is a non-negative integer. The 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, each of them ranging from -10^9 ...
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": "", "prompt_id": "00017401", "row_id": 17401, "seed_ids": "[4310]" }
0.677946
Codeforces_17401
I
[ "rotate_array", "process_rotation" ]
2
[ [ "process_rotation", "rotate_array" ] ]
1
[]
false
[]
false
pytest
true
[]
true
576f9a1848904afeb4fc94c58c77e469b3283700
52a53275de62b313b0dc3db56f2e4bb2e613d70b
v1.0
instruct
Codeforces
Codeforces_17403_I
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. Input: - The first line contains three int...
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": "", "prompt_id": "00017403", "row_id": 17403, "seed_ids": "[8120]" }
0.572578
Codeforces_17403
I
[ "does_clique_exist", "is_clique" ]
2
[ [ "does_clique_exist", "is_clique" ] ]
1
[]
false
[]
false
pytest
true
[]
true
13060e9b5872c01d94cc9c41913c593963a61cce
c449753693e207a65acce3eaf721ff98e6026130
v1.0
instruct
Codeforces
Codeforces_17439_I
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. Now, John came up with a new challenge: He wants to find the smallest prime number which is greater ...
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": "", "prompt_id": "00017439", "row_id": 17439, "seed_ids": "[6913]" }
0.632009
Codeforces_17439
I
[ "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
cac324210830c7a0d3b7e5464fca2e554027aea7
5a76f815f62654bb578ed529eb7e45c86c737217
v1.0
instruct
Codeforces
Codeforces_17516_I
A transportation company needs to design a route network for its buses. The city has $$$N$$$ bus stops. Each bus stop is represented by a point in a 2D plane with integer coordinates. The company aims to minimize the total cost of constructing the routes. The cost of constructing a route between any two bus stops is eq...
import heapq import math def calculate_distance(p1, p2): """Calculate Euclidean distance between two points in 2D plane.""" return math.sqrt((p1[0] - p2[0]) ** 2 + (p1[1] - p2[1]) ** 2) def minimum_cost_to_connect_bustops(N, coordinates): """Calculate the minimum cost to connect all bus stops.""" # Cr...
from solution import minimum_cost_to_connect_bustops def test_example_case(): assert math.isclose(minimum_cost_to_connect_bustops(4, [(0, 0), (0, 1), (1, 0), (1, 1)]), 3.000000, rel_tol=1e-6) def test_case_two_points(): assert math.isclose(minimum_cost_to_connect_bustops(2, [(0, 0), (3, 4)]), 5.000000, rel_to...
[ { "docstring": "Calculate Euclidean distance between two points in 2D plane.", "function_declaration": "def calculate_distance(p1, p2):", "function_name": "calculate_distance", "parameter_list": "(p1, p2)" }, { "docstring": "Calculate the minimum cost to connect all bus stops.", "functio...
[ 0, 0, 0, 1, 0, 0, 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": "import math\nfrom heapq import heappop, heappush\n\ndef euclidean_distance(p1, p2):\n return math.sqrt((p1[0] - p2[0]) ** 2 + (p1[1] - p2[1]) ** 2)\n\ndef ...
trial_gpt4o_4
{ "original_instruction": "", "prompt_id": "00017516", "row_id": 17516, "seed_ids": "[1279]" }
0.709859
Codeforces_17516
I
[ "calculate_distance", "minimum_cost_to_connect_bustops" ]
2
[ [ "minimum_cost_to_connect_bustops", "calculate_distance" ] ]
1
[]
false
[]
false
pytest
true
[]
true
d953a55b23d83ca6aa7cc5f2be95b5d53b2bec62
c6018c5ea5f234655e4d8b68481e44bb2738ef6e
v1.0
instruct
Codeforces
Codeforces_17524_I
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 servers is efficient. Therefore, th...
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": "", "prompt_id": "00017524", "row_id": 17524, "seed_ids": "[7947]" }
0.663804
Codeforces_17524
I
[ "find", "union", "kruskal", "minimum_latency" ]
4
[ [ "kruskal", "find" ], [ "kruskal", "union" ], [ "minimum_latency", "kruskal" ], [ "union", "find" ] ]
4
[]
false
[]
false
pytest
true
[]
true
bcfda85dca2d239d6b42bea4d40761a4a1e49543
3768e0a877272ca8f9cdfa5728cc938c5d6ecb85
v1.0
instruct
Codeforces
Codeforces_17572_I
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. The first line contains two integers $$$n$$$ ($$$2 \le n \le 100\,000$$$) — the number of no...
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": "", "prompt_id": "00017572", "row_id": 17572, "seed_ids": "[7561]" }
0.87569
Codeforces_17572
I
[ "dijkstra", "min_path_weight" ]
2
[ [ "min_path_weight", "dijkstra" ] ]
1
[]
false
[]
false
pytest
false
[]
true
cacdf147e6d0fd215a8242f315cf3d3d9e2753e3
49000cc31c7fede558b0f6c5e243e422301d784f
v1.0
instruct
Codeforces
Codeforces_17706_I
Given an array of integers, write a program to find the maximum sum of a contiguous subarray using the divide and conquer method. Input The first line of the input contains an integer n (1 ≤ n ≤ 200,000) — the number of elements in the array. The second line contains n integers a1, a2, ..., an (−10^5 ≤ ai ≤ 10^5) — 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": "", "prompt_id": "00017706", "row_id": 17706, "seed_ids": "[5623]" }
0.787742
Codeforces_17706
I
[ "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
ff1dad49fcc85bfbaa267c8e76d0ca69d1c3648e
66968c7a36ad40927b50eba98f652b197a7709ea
v1.0
instruct
Codeforces
Codeforces_17720_I
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 each route as an edge between ...
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": "", "prompt_id": "00017720", "row_id": 17720, "seed_ids": "[3588]" }
0.629915
Codeforces_17720
I
[ "is_bipartite", "bird_migration", "process_input" ]
3
[ [ "bird_migration", "is_bipartite" ] ]
1
[ "process_input" ]
false
[]
false
pytest
true
[]
true
625618df4d4511c5c57680986d4daa33e3ac6917
172ca3e3350240337de35b0c032798884fda38b6
v1.0
instruct
Codeforces
Codeforces_17741_I
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 and a positive area can lead ...
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": "", "prompt_id": "00017741", "row_id": 17741, "seed_ids": "[4487]" }
0.622827
Codeforces_17741
I
[ "is_valid_triangle", "valid_triangles" ]
2
[ [ "valid_triangles", "is_valid_triangle" ] ]
1
[]
false
[]
false
pytest
true
[]
true
ebde394ba51e8ce02f9fdd305260b1c193003be8
00c64f551221dee34f9438adc0d46ede01685f40
v1.0
instruct
Codeforces
Codeforces_17758_I
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: 1. **Add Operation**: Add a new node with a given value as a child of a specified parent node...
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": "", "prompt_id": "00017758", "row_id": 17758, "seed_ids": "[348]" }
0.602923
Codeforces_17758
I
[ "process_operations", "run" ]
2
[ [ "run", "process_operations" ] ]
1
[]
false
[ "TreeNode", "BinaryTree" ]
true
pytest
true
[]
true
ad89c96acc42dbda89b92f7fb9fab88d309ff387
867b25a445e3e21a3d1ed80ca288dc1dc1ce43bb
v1.0
instruct
Codeforces
Codeforces_17772_I
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 more than once. The input c...
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": "", "prompt_id": "00017772", "row_id": 17772, "seed_ids": "[4668]" }
0.722604
Codeforces_17772
I
[ "dfs", "max_sum_path" ]
2
[ [ "max_sum_path", "dfs" ] ]
1
[]
false
[]
false
pytest
true
[]
true
fc758137b57dbdfe30cdb10f4ec89a7f335ce7c9
b97f6c69f2ff794beb788f7710dcce3f81f87bfe
v1.0
instruct
Codeforces
Codeforces_17794_I
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$$$. The first line contains two integers $$$n$$$ and $$$m$...
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": "", "prompt_id": "00017794", "row_id": 17794, "seed_ids": "[4570]" }
0.852052
Codeforces_17794
I
[ "dijkstra", "shortest_path" ]
2
[ [ "shortest_path", "dijkstra" ] ]
1
[]
false
[]
false
pytest
true
[]
true
3a462bee3f4036d444e59aa76a0948bc8a999071
32e104fa398414407fcf64e231b9e5c6dbf4a9ab
v1.0
instruct
Codeforces
Codeforces_17843_I
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" shape here means that starting fro...
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": "", "prompt_id": "00017843", "row_id": 17843, "seed_ids": "[1707]" }
0.744942
Codeforces_17843
I
[ "is_l_shaped", "check_l_shapes" ]
2
[ [ "check_l_shapes", "is_l_shaped" ] ]
1
[]
false
[]
false
pytest
true
[]
true
4c0f91afc1f004eb84ab68347125050e8b7561a4
773ec80079af4906f96b8d69d9ad5d38f7bcb763
v1.0
instruct
Codeforces
Codeforces_17851_I
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 (length, width, height) and a uni...
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": "", "prompt_id": "00017851", "row_id": 17851, "seed_ids": "[3423]" }
0.636637
Codeforces_17851
I
[ "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
c321cb1032f03ff8b34bd4d47748c4f2795bb681
892b807b6b72ee0be1b397864ea686095937759d
v1.0
instruct
Codeforces
Codeforces_17871_I
You are given an undirected graph with n nodes and m edges. Nodes are numbered from 1 to n. Each edge has a weight associated with it. Your task is to find the shortest path from node 1 to node n, and print its total weight. If no such path exists, print "NO PATH" (without quotes). The first line of input contains two...
import heapq def dijkstra_shortest_path(n, edges): graph = {i: [] for i in range(1, n+1)} for u, v, w in edges: graph[u].append((v, w)) graph[v].append((u, w)) dist = {i: float('inf') for i in range(1, n+1)} dist[1] = 0 priority_queue = [(0, 1)] # (distance, node) while p...
from solution import find_shortest_path def test_find_shortest_path_case1(): n = 5 m = 6 edges = [ (1, 2, 10), (1, 3, 5), (2, 3, 2), (3, 4, 2), (4, 5, 3), (3, 5, 1) ] assert find_shortest_path(n, m, edges) == 6 def test_find_shortest_path_no_path(): ...
[ { "docstring": null, "function_declaration": "def dijkstra_shortest_path(n, edges):", "function_name": "dijkstra_shortest_path", "parameter_list": "(n, edges)" }, { "docstring": null, "function_declaration": "def find_shortest_path(n, m, edges):", "function_name": "find_shortest_path...
[ 0, 1, 0, 1, 1, 0, 1, 0, 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 find_shortest_path(n, m, edges):\n from collections import defaultdict\n import sys\n \n # Create graph from given edges\n ...
trial_gpt4o_6
{ "original_instruction": "", "prompt_id": "00017871", "row_id": 17871, "seed_ids": "[2027]" }
0.811762
Codeforces_17871
I
[ "dijkstra_shortest_path", "find_shortest_path" ]
2
[ [ "find_shortest_path", "dijkstra_shortest_path" ] ]
1
[]
false
[]
false
pytest
true
[]
true
5a77cb7446db3761082d5fa79baec0c4656d417b
61240da96ec1a6b31966f14f4f584534540a8ba3
v1.0
instruct
Codeforces
Codeforces_17908_I
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$$$. You need to determine the number of distinct prime numbers that divide at least one number in the sequence $$$a$$$. For example, for the sequence $$$a = [6, 10, 15]$$$, the prime numbers tha...
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": "", "prompt_id": "00017908", "row_id": 17908, "seed_ids": "[3452]" }
0.609829
Codeforces_17908
I
[ "sieve", "count_distinct_prime_divisors" ]
2
[ [ "count_distinct_prime_divisors", "sieve" ] ]
1
[]
false
[]
false
pytest
false
[]
true
f67cf2bf35c43bf44262fae7caa85fb846de7b50
7268dfacc99431bf235f9f811938a60716eed971
v1.0
instruct
Codeforces
Codeforces_17912_I
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. Liam has intercepted `n` such messages and needs your help to determine the basic unit of each mess...
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": "", "prompt_id": "00017912", "row_id": 17912, "seed_ids": "[3697]" }
0.630924
Codeforces_17912
I
[ "find_basic_unit_length", "get_basic_unit_lengths" ]
2
[ [ "get_basic_unit_lengths", "find_basic_unit_length" ] ]
1
[]
false
[]
false
pytest
false
[]
true
a7752047a1514a718093867c08058d202ae9b7c7
56ada8c7b6b4f444f6b65c970a12b7f143106764
v1.0
instruct
Codeforces
Codeforces_17917_I
You are given an integer array of length n. You have to perform a certain type of query on this array. Each query can ask for the number of distinct primes in a subarray. You need to respond to each query efficiently. ### Task: You will be given an array of integers and must process multiple queries. Each query will p...
from itertools import accumulate from collections import defaultdict def sieve(n): is_prime = [True] * (n + 1) p = 2 while p * p <= n: if is_prime[p]: for i in range(p * p, n + 1, p): is_prime[i] = False p += 1 is_prime[0], is_prime[1] = False, False retu...
import pytest from solution import distinct_primes_queries def test_all_primes(): arr = [2, 3, 5, 7, 11, 13] queries = [(1, 3), (1, 6), (3, 5)] expected = [3, 6, 3] assert distinct_primes_queries(arr, queries) == expected def test_no_primes(): arr = [1, 4, 6, 8, 10, 12] queries = [(1, 3), (1, ...
[ { "docstring": null, "function_declaration": "def sieve(n):", "function_name": "sieve", "parameter_list": "(n)" }, { "docstring": null, "function_declaration": "def preprocess_primes(arr, max_value):", "function_name": "preprocess_primes", "parameter_list": "(arr, max_value)" }...
[ 1, 0, 0, 1, 0, 1, 1, 0, 1 ]
5
medium
0.556
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "from collections import defaultdict\n\ndef sieve(n):\n \"\"\"\n Simple Sieve of Eratosthenes to find all prime numbers up to n.\n Returns an array is...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00017917", "row_id": 17917, "seed_ids": "[3557]" }
0.609705
Codeforces_17917
I
[ "sieve", "preprocess_primes", "distinct_primes_queries" ]
3
[ [ "distinct_primes_queries", "preprocess_primes" ], [ "preprocess_primes", "sieve" ] ]
2
[]
false
[]
false
pytest
true
[]
true
b5c314e6a4328d12814eda1005703b4b761c0037
6c780f55512b4e2ed418371e996ee4d616be5e60
v1.0
instruct
Codeforces
Codeforces_18024_I
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 starting city to a destinatio...
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": "", "prompt_id": "00018024", "row_id": 18024, "seed_ids": "[7811]" }
0.791883
Codeforces_18024
I
[ "dijkstra", "shortest_travel_time" ]
2
[ [ "shortest_travel_time", "dijkstra" ] ]
1
[]
false
[]
false
pytest
true
[]
true
8b892c07dec7bd2314380e5148c17cd96335ef26
db8b8f8c76159552b2b9f39cf09ba756c5268fa0
v1.0
instruct
Codeforces
Codeforces_18036_I
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 such sequence. If it does no...
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": "", "prompt_id": "00018036", "row_id": 18036, "seed_ids": "[3909]" }
0.561096
Codeforces_18036
I
[ "is_prime", "find_special_sequence", "solve" ]
3
[ [ "find_special_sequence", "is_prime" ], [ "solve", "find_special_sequence" ] ]
2
[]
false
[]
false
pytest
false
[]
true
b8da52f9a69fa45737bd0ab0dbc7b02f0b07afec
feb50f5a2ed91a790b4cf37a8d48dee66c083205
v1.0
instruct
Codeforces
Codeforces_18048_I
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 of them. Given a sequence of ...
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": "", "prompt_id": "00018048", "row_id": 18048, "seed_ids": "[5407]" }
0.613875
Codeforces_18048
I
[ "is_prime", "longest_subsequence" ]
2
[ [ "longest_subsequence", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
83fe648b0d2acfec1063fa1367183aa28bba76fd
ea392d73c6f0f81953bbf6ec8dafefadcbdbfb54
v1.0
instruct
Codeforces
Codeforces_18086_I
Given an array of integers and a target value, find all unique combinations of the array's numbers that sum up to the target. Each number in the array can only be used once in the combination. The solution set must not contain duplicate combinations. For example, given the array `candidates = [2,3,6,7]` and the target...
from typing import List def find_combinations(candidates: List[int], target: int) -> List[List[int]]: def backtrack(start, end, tmp, target): if target == 0: result.append(tmp[:]) return if target < 0: return for i in range(start, end): ...
from solution import get_combinations def test_example_case(): assert get_combinations(4, [2, 3, 6, 7], 7) == [[7]] def test_no_combinations(): assert get_combinations(3, [1, 2, 4], 8) == [] def test_multiple_combinations(): combinations = get_combinations(5, [10, 1, 2, 7, 6, 5], 8) expected_output =...
[ { "docstring": null, "function_declaration": "def find_combinations(candidates, target):", "function_name": "find_combinations", "parameter_list": "(candidates, target)" }, { "docstring": null, "function_declaration": "def get_combinations(n, candidates, target):", "function_name": "...
[ 0, 0, 1, 1, 0, 0, 0, 0, 0, 0 ]
2
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def combinationSum2(candidates, target):\n \"\"\"\n Finds unique combinations in candidates that sum up to target.\n Each number in candidates may on...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00018086", "row_id": 18086, "seed_ids": "[5897]" }
0.64537
Codeforces_18086
I
[ "find_combinations", "get_combinations" ]
2
[ [ "get_combinations", "find_combinations" ] ]
1
[]
false
[]
false
pytest
true
[]
true
08fcc6ef6dca07f42399f017042b1ca76d600465
e32cd4bfa4773a14ab90665720215f98a4ed7cc6
v1.0
instruct
Codeforces
Codeforces_18100_I
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 find all the peak positions in...
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": "", "prompt_id": "00018100", "row_id": 18100, "seed_ids": "[5243]" }
0.67539
Codeforces_18100
I
[ "find_peaks", "parse_input", "solution" ]
3
[ [ "solution", "find_peaks" ], [ "solution", "parse_input" ] ]
2
[ "parse_input" ]
false
[]
false
pytest
true
[]
true
ee266830fcfe9880fa23168ed0292b0e60f976d7
1c354a51be2d1e441f607842ca989eb9f70f73be
v1.0
instruct
Codeforces
Codeforces_18120_I
You are given an undirected graph with n nodes and m edges. Each edge has a positive weight. You need to find the shortest path from node 1 to node n and print the path. If there are multiple shortest paths, print any one of them. The first line contains two integers n and m (2 ≤ n ≤ 1000, 1 ≤ m ≤ 10000) — the number...
import heapq def shortest_path(n, m, edges): # Create adjacency list for the graph graph = [[] for _ in range(n + 1)] for u, v, w in edges: graph[u].append((v, w)) graph[v].append((u, w)) # Dijkstra's algorithm implementation def dijkstra(start): distances = {node: floa...
def test_shortest_path(): result = find_shortest_path(5, 5, [(1, 2, 2), (2, 3, 3), (1, 3, 6), (3, 4, 1), (4, 5, 2)]) assert result == "8\n1 2 3 4 5" def test_case_no_path(): result = find_shortest_path(3, 1, [(1, 2, 3)]) assert result == "-1" def test_case_direct_path(): result = find_shortest_pat...
[ { "docstring": null, "function_declaration": "def shortest_path(n, m, edges):", "function_name": "shortest_path", "parameter_list": "(n, m, edges)" }, { "docstring": null, "function_declaration": "def find_shortest_path(n, m, edge_list):", "function_name": "find_shortest_path", "...
[ 0, 1, 1, 1, 0, 0, 0, 1, 0 ]
4
medium
0.444
{ "trial_gpt4o_0": null, "trial_gpt4o_1": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared1_results_combined.jsonl", "solution_code": "import heapq\n\ndef shortest_path(n, m, edges):\n # Create adjacency list\n graph = [[] for _ in range(n + 1)]\n for u, v, w...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00018120", "row_id": 18120, "seed_ids": "[4649]" }
0.807063
Codeforces_18120
I
[ "shortest_path", "find_shortest_path" ]
2
[ [ "find_shortest_path", "shortest_path" ] ]
1
[]
false
[]
false
pytest
false
[]
true
b3b4f67d75fd0a6225b539ca2198d4ea5157d584
97a12064b7afe6a28c8d1946afba3c3d8be5f63c
v1.0
instruct
Codeforces
Codeforces_18138_I
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. The first line contains two space-separated integers m and n (1 ≤ m, n ≤ 100), the number...
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": "", "prompt_id": "00018138", "row_id": 18138, "seed_ids": "[5632]" }
0.556238
Codeforces_18138
I
[ "rotate_matrix_90_degrees_clockwise", "rotate_matrix" ]
2
[ [ "rotate_matrix", "rotate_matrix_90_degrees_clockwise" ] ]
1
[]
false
[]
false
pytest
true
[]
true
5778c7d6f4ed81f5e660aa041fdd55af9d7a10a0
e42dce4012a8841dcdeea7f55274804986375b26
v1.0
instruct
Codeforces
Codeforces_18153_I
Design and implement a screen for a weather forecasting application that displays current weather information pulled from an open weather API. Requirements: 1. Layout: The screen should have sections for current temperature, weather conditions, location, and an icon representing the weather (sunny, rainy, etc.). 2. Us...
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": "", "prompt_id": "00018153", "row_id": 18153, "seed_ids": "[2288]" }
0.339115
Codeforces_18153
I
[ "get_weather", "format_weather_data", "display_weather", "get_cached_weather" ]
4
[ [ "get_cached_weather", "get_weather" ] ]
1
[]
false
[]
false
pytest
true
[ "requests" ]
false
531611b71089b48874c758476e0aa1af12b7d4ae
4bff9fe533008088948465abb487dd5dcdcbb42b
v1.0
instruct
Codeforces
Codeforces_18172_I
The zoo in Woodland Park has recently added a new attraction — a magical garden filled with exotic plants and flowers. The garden is represented as an undirected graph with n nodes and m edges. Each node represents a distinct section of the garden, and each edge represents a path between two sections. Every path has a ...
from itertools import permutations def find_max_beauty(n, m, edges): if n == 1: return 0 if m == 0 else edges[0][2] * 2 # Create adjacency matrix adj = [[-1] * n for _ in range(n)] for u, v, b in edges: adj[u-1][v-1] = b adj[v-1][u-1] = b max_beauty = -1 n...
from solution import max_beauty_of_tour def test_example(): n, m = 4, 5 edges = [ (1, 2, 3), (2, 3, 4), (3, 4, 5), (4, 1, 6), (1, 3, 2) ] assert max_beauty_of_tour(n, m, edges) == 18 def test_no_hamiltonian_cycle(): n, m = 3, 2 edges = [ (1, 2, 5...
[ { "docstring": null, "function_declaration": "def find_max_beauty(n, m, edges):", "function_name": "find_max_beauty", "parameter_list": "(n, m, edges)" }, { "docstring": null, "function_declaration": "def max_beauty_of_tour(n, m, edges):", "function_name": "max_beauty_of_tour", "...
[ 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": "from itertools import permutations\n\ndef maximum_beauty(n, m, edges):\n graph = [[0] * n for _ in range(n)]\n \n for u, v, b in edges:\n grap...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00018172", "row_id": 18172, "seed_ids": "[6444]" }
0.605913
Codeforces_18172
I
[ "find_max_beauty", "max_beauty_of_tour" ]
2
[ [ "max_beauty_of_tour", "find_max_beauty" ] ]
1
[]
false
[]
false
pytest
true
[]
true
f2e87c8cdfe2e5ea27ea7ddc8a49f88ab8c6ac07
cc00e8fb64d811bbf461255f7e89076aa348697e
v1.0
instruct
Codeforces
Codeforces_18232_I
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]). Your task is to calculate the total number of such inversions in the array. ### Input - The first line contains a single integer $$$n$$$ ($$$1 \le n \le...
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": "", "prompt_id": "00018232", "row_id": 18232, "seed_ids": "[8251]" }
0.777058
Codeforces_18232
I
[ "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
ae67470d0701ccddeddb0231ea9bf5b383eb6677
a26c9b6a718c4902636c0e23856d3e4613edfe7d
v1.0
instruct
Codeforces
Codeforces_18271_I
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 the count of '1's followed b...
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": "", "prompt_id": "00018271", "row_id": 18271, "seed_ids": "[3596]" }
0.656627
Codeforces_18271
I
[ "count_and_say", "next_sequence", "solve" ]
3
[ [ "count_and_say", "next_sequence" ], [ "solve", "count_and_say" ] ]
2
[]
false
[]
false
pytest
false
[]
true
742d898eea00203b90b33d0bc9bbf2cd766bad43
28fac385587c7afa55806b80de3a1e42a4b721aa
v1.0
instruct
Codeforces
Codeforces_18272_I
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$$$. For each query, you need to find the sum of elements from index $$$x$$$ to index $$$y$$$, inclusive, and determine if this sum is divisible by $$$k$$$. If the sum i...
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": "", "prompt_id": "00018272", "row_id": 18272, "seed_ids": "[5825]" }
0.685213
Codeforces_18272
I
[ "preprocess_prefix_sums", "process_query", "solve" ]
3
[ [ "solve", "preprocess_prefix_sums" ], [ "solve", "process_query" ] ]
2
[]
false
[]
false
pytest
true
[]
true
609e2863b55e6e7c7510bfeb081e4c6403efd43e
897902f0450b118cf4326dc49d3276505478677b
v1.0
instruct
Codeforces
Codeforces_18276_I
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: You are given two integers $$$L$$$ and $$$R$$$. Your task is to find the sum of all prime numbers between $$$L$$$ and $$$R$$$ inclusive. S...
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": "", "prompt_id": "00018276", "row_id": 18276, "seed_ids": "[5018]" }
0.568001
Codeforces_18276
I
[ "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
2c5bf9682849003e7caadb976290036130805139
46cb8bc2bef26c7285012a2c4d40b0b022474579
v1.0
instruct
Codeforces
Codeforces_18286_I
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: 1. The distance query: Given two cities $$a$$ and $$b$$, determine the distance between them...
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": "", "prompt_id": "00018286", "row_id": 18286, "seed_ids": "[3422]" }
0.722246
Codeforces_18286
I
[ "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
803c64d8881643ac7c858428021a1ef098bb9e66
c92bab17cdd565e1d0433ac57e68372587e2b05e
v1.0
instruct
Codeforces
Codeforces_18348_I
The National Park Service is planning a new hiking trail that stretches from a starting point at the park entrance (point S) to a scenic viewpoint (point V). The trail is represented as a series of waypoints connected by straight line segments. You are given the coordinates of each waypoint, including the starting poin...
import math import heapq def euclidean_distance(p1, p2): return math.sqrt((p1[0] - p2[0]) ** 2 + (p1[1] - p2[1]) ** 2) def shortest_path(n, coordinates, m, blocked_segments): graph = {i: [] for i in range(n)} blocked = {frozenset((u-1, v-1)) for u, v in blocked_segments} for i in range(n): f...
def test_example(): n = 5 coordinates = [(0, 0), (2, 3), (4, 4), (3, 2), (5, 5)] m = 2 blocked_segments = [(2, 3), (4, 5)] assert shortest_path(n, coordinates, m, blocked_segments) == 7.071 def test_no_blockages(): n = 3 coordinates = [(0, 0), (3, 4), (6, 8)] m = 0 blocked_segments ...
[ { "docstring": null, "function_declaration": "def euclidean_distance(p1, p2):", "function_name": "euclidean_distance", "parameter_list": "(p1, p2)" }, { "docstring": null, "function_declaration": "def shortest_path(n, coordinates, m, blocked_segments):", "function_name": "shortest_pa...
[ 0, 0, 0, 0, 0, 1, 0, 0, 0, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "import math\nimport heapq\n\ndef find_shortest_path(n, coordinates, m, blocked_segments):\n def euclidean_distance(p1, p2):\n return math.sqrt((p1[0...
trial_gpt4o_5
{ "original_instruction": "", "prompt_id": "00018348", "row_id": 18348, "seed_ids": "[5694]" }
0.716605
Codeforces_18348
I
[ "euclidean_distance", "shortest_path", "main" ]
3
[ [ "shortest_path", "euclidean_distance" ] ]
1
[]
false
[]
false
pytest
false
[]
true
6741070589a4b0ee07292b7758f75d1566eb1f3f
8b8b76c129c9e86351c6432a464db7f98d62d886
v1.0
instruct
Codeforces
Codeforces_18400_I
A village is planning to build a set of new roads connecting multiple houses, represented by nodes in a graph. Each pair of houses is connected by a potential road that has a certain construction cost. Your goal is to ensure that every house can be reached from any other house (i.e., the graph is connected), while mini...
def find(parent, i): if parent[i] == i: return i else: parent[i] = find(parent, parent[i]) return parent[i] def union(parent, rank, x, y): xroot = find(parent, x) yroot = find(parent, y) if rank[xroot] < rank[yroot]: parent[xroot] = yroot elif rank[xroot] > rank[...
import pytest from solution import minimal_construction_cost def test_example(): assert minimal_construction_cost(4, 5, [(1, 2, 1), (1, 3, 4), (2, 3, 2), (3, 4, 3), (2, 4, 5)]) == 6 def test_no_edges(): assert minimal_construction_cost(4, 0, []) == -1 def test_one_node(): assert minimal_construction_cost...
[ { "docstring": null, "function_declaration": "def find(parent, i):", "function_name": "find", "parameter_list": "(parent, i)" }, { "docstring": null, "function_declaration": "def union(parent, rank, x, y):", "function_name": "union", "parameter_list": "(parent, rank, x, y)" }, ...
[ 1, 0, 0, 0, 1, 1, 1, 1, 0, 1 ]
6
medium
0.6
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def find(parent, i):\n if parent[i] == i:\n return i\n else:\n return find(parent, parent[i])\n\ndef union(parent, rank, x, y):\n xroot...
trial_gpt4o_4
{ "original_instruction": "", "prompt_id": "00018400", "row_id": 18400, "seed_ids": "[1513]" }
0.732736
Codeforces_18400
I
[ "find", "union", "minimal_construction_cost" ]
3
[ [ "minimal_construction_cost", "find" ], [ "minimal_construction_cost", "union" ], [ "union", "find" ] ]
3
[]
false
[]
false
pytest
true
[]
true
5a48d13a2ea36ea3c6a38966a9cfe2a1a7442c5c
c4cf4ab6461aef1b7cbe0a0dee942453c087f86f
v1.0
instruct
Codeforces
Codeforces_18403_I
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. An island administrator wants to find out the ...
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": "", "prompt_id": "00018403", "row_id": 18403, "seed_ids": "[4070]" }
0.788784
Codeforces_18403
I
[ "maxFlow", "canTransport" ]
2
[ [ "canTransport", "maxFlow" ] ]
1
[]
false
[]
false
pytest
true
[]
true
215af45e33a27de69b568fac8a81529c44d4a6b4
9e48c5dc0e8665c2f713c3f35955a7b56713cb27
v1.0
instruct
Codeforces
Codeforces_18507_I
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. If the tree is balanced, pr...
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": "", "prompt_id": "00018507", "row_id": 18507, "seed_ids": "[500]" }
0.814457
Codeforces_18507
I
[ "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
fc893ae691d9b7c799ddad391ae1d31cedf9838e
4870678a079beeda71de2fc4f12f905cb621405d
v1.0
instruct
Codeforces
Codeforces_18535_I
In a small village, there is a well-known path that connects several houses. Each house can be represented as a vertex, and each path between two houses is represented as an edge with a given distance. The village council wants to improve the connectivity among the houses by ensuring each house can be reached from any ...
def floyd_warshall(n, edges): # Initialize the distance matrix inf = float('inf') dist = [[inf] * n for _ in range(n)] # Set the distance from a house to itself to 0 for i in range(n): dist[i][i] = 0 # Add the edges to the distance matrix for u, v, d in edges: dist[...
def test_shortest_path(): n, m = 4, 5 edges = [(1, 2, 5), (1, 3, 10), (2, 3, 2), (3, 4, 1), (2, 4, 9)] queries = [(1, 4), (1, 3), (4, 1), (2, 3)] expected = [8, 7, 8, 2] assert shortest_path(n, m, edges, queries) == expected def test_no_direct_path(): n, m = 4, 2 edges = [(1, 2, 3), (3, 4, ...
[ { "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, m, edges, queries):", "function_name": "shortest_path", "parameter...
[ 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 floyd_warshall(n, edges):\n # Initialize distance matrix with \"infinity\"\n dist = [[float('inf')] * n for _ in range(n)]\n \n # Distance fro...
trial_gpt4o_7
{ "original_instruction": "", "prompt_id": "00018535", "row_id": 18535, "seed_ids": "[1231]" }
0.755473
Codeforces_18535
I
[ "floyd_warshall", "shortest_path" ]
2
[ [ "shortest_path", "floyd_warshall" ] ]
1
[]
false
[]
false
pytest
false
[]
true
857955a1733315faa98382c4cb87eea549caa701
4620d17fd0f595951aeed06a8428e166e65a09c4
v1.0
instruct
Codeforces
Codeforces_18545_I
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. Each magical animal repeatedly chirps based on its unique frequency. You suspect that something unusual hap...
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": "", "prompt_id": "00018545", "row_id": 18545, "seed_ids": "[8039]" }
0.558834
Codeforces_18545
I
[ "lcm", "min_time_elapse" ]
2
[ [ "min_time_elapse", "lcm" ] ]
1
[]
false
[]
false
pytest
true
[]
true
d1451c367d2781baff100cb52082161160032ecd
4e568567ac9aee90f997e78a1f88752dc0090442
v1.0
instruct
Codeforces
Codeforces_18589_I
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 some intersections. A rescue...
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": "", "prompt_id": "00018589", "row_id": 18589, "seed_ids": "[7447]" }
0.721913
Codeforces_18589
I
[ "dijkstra", "minimum_rescue_stations" ]
2
[ [ "minimum_rescue_stations", "dijkstra" ] ]
1
[]
false
[]
false
pytest
false
[]
true
cdee6a753758e3e75d4999baf2d06f53ad058eaf
d0ddde9bf944665c1844b32651c591b4a43484bb
v1.0
instruct
Codeforces
Codeforces_18685_I
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. The mayor of City S wants to generate daily traffic summary reports to understand traffic patterns ...
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": "", "prompt_id": "00018685", "row_id": 18685, "seed_ids": "[5673]" }
0.649879
Codeforces_18685
I
[ "generate_daily_reports", "process_input_and_generate_reports" ]
2
[ [ "process_input_and_generate_reports", "generate_daily_reports" ] ]
1
[]
false
[]
false
pytest
true
[]
true
b18c980de1a319e28d6aafb288fffc1d35dc8dfd
2022e2cb7173e8cb4c9fde0d05ef79245a034316
v1.0
instruct
Codeforces
Codeforces_18691_I
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 Mystery Point if it is within a gi...
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": "", "prompt_id": "00018691", "row_id": 18691, "seed_ids": "[5260]" }
0.720732
Codeforces_18691
I
[ "euclidean_distance", "max_reachable_mystery_points" ]
2
[ [ "max_reachable_mystery_points", "euclidean_distance" ] ]
1
[]
false
[]
false
pytest
true
[]
true
3be018407f01a33772b0922dc25d452321b51233
1242b13386c7e354a2072487303e0416429e814e
v1.0
instruct
Codeforces
Codeforces_18703_I
Given a binary tree, determine the maximum sum of any path from the tree's root node to a leaf. Each node in the tree contains a single integer value. A path in a binary tree is defined as a sequence of nodes starting from the root node, moving downwards through the parent-child connections, and ending at a leaf node...
def max_sum_path(tree): def dfs(node_index): if node_index == -1: return 0 node = tree[node_index] left_sum = dfs(node['left']) right_sum = dfs(node['right']) return node['value'] + max(left_sum, right_sum) return dfs(0) def build_tree(nodes): tree = [] ...
def test_max_sum_case_1(): n = 5 treelist = [ (10, -1, 1), (2, 2, 3), (5, 4, -1), (1, -1, -1), (20, -1, -1) ] assert max_sum_from_input(n, treelist) == 37 def test_max_sum_single_node(): n = 1 treelist = [ (5, -1, -1) ] assert max_sum_from...
[ { "docstring": null, "function_declaration": "def max_sum_path(tree):", "function_name": "max_sum_path", "parameter_list": "(tree)" }, { "docstring": null, "function_declaration": "def build_tree(nodes):", "function_name": "build_tree", "parameter_list": "(nodes)" }, { "d...
[ 1, 1, 0, 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": "class Node:\n def __init__(self, val):\n self.val = val\n self.left = None\n self.right = None\n\ndef build_tree(node_data):\n if n...
trial_gpt4o_7
{ "original_instruction": "", "prompt_id": "00018703", "row_id": 18703, "seed_ids": "[961]" }
0.677265
Codeforces_18703
I
[ "max_sum_path", "build_tree", "max_sum_from_input" ]
3
[ [ "max_sum_from_input", "build_tree" ], [ "max_sum_from_input", "max_sum_path" ] ]
2
[]
false
[]
false
pytest
false
[]
true
ab35a040adb975167fcf396297c6b8158ac31531
f7d6d4ab660491a8c018a92570372c97f6b01e77
v1.0
instruct
Codeforces
Codeforces_18758_I
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. Given the possible paths be...
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": "", "prompt_id": "00018758", "row_id": 18758, "seed_ids": "[844]" }
0.786568
Codeforces_18758
I
[ "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
2b2270a0aec6269762ca1493768ed875dd924c30
7d5cbb217e31bd225b8383b7df10903f6aea7fd1
v1.0
instruct
Codeforces
Codeforces_18771_I
You are given an undirected tree with n nodes, where each node has a value. The values of different nodes can overlap. Specifically, the value of node i is vi. You are also given q queries. Each query consists of two integers u and k. For each query, you should find the k-th smallest node value in the subtree of node ...
from collections import defaultdict import heapq class Tree: def __init__(self, n, values): self.n = n self.values = values self.tree = defaultdict(list) self.subtree_values = {} self.subtree_sizes = {} def add_edge(self, u, v): self.tree[u].append(v) se...
def test_solve_tree_queries(): n = 5 values = [3, 9, 5, 7, 1] edges = [(1, 2), (1, 3), (3, 4), (3, 5)] q = 3 queries = [(3, 2), (1, 4), (4, 1)] expected_output = [5, 7, 7] result = solve_tree_queries(n, values, edges, q, queries) assert result == expected_output, f'Output was {resul...
[]
[ 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": "from collections import defaultdict\nimport heapq\n\nclass Tree:\n def __init__(self, n, values):\n self.n = n\n self.values = values\n ...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00018771", "row_id": 18771, "seed_ids": "[778]" }
0.709581
Codeforces_18771
I
[ "solve_tree_queries", "solve" ]
2
[ [ "solve", "solve_tree_queries" ] ]
1
[]
false
[ "Tree" ]
true
pytest
false
[]
true
b5b45730a03b287983f9536a0a838dfc5aba40d1
047c6fa9320d1759e22c93809207760dafcad54a
v1.0
instruct
Codeforces
Codeforces_18784_I
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 once and returns to the start...
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": "", "prompt_id": "00018784", "row_id": 18784, "seed_ids": "[7337]" }
0.72877
Codeforces_18784
I
[ "euclidean_distance", "tsp_shortest_path", "parse_input" ]
3
[ [ "tsp_shortest_path", "euclidean_distance" ] ]
1
[ "parse_input" ]
false
[]
false
pytest
true
[]
true
f568da57a4bc0c6a8564b6756590a0e2432a8e06
4dca048fd46174cf1ff173a7116d88ce533f169e