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_11415_I
Aisha is planning her vacation and is excited about visiting several cities. She has a map with N cities connected by M bidirectional roads with travel times. Aisha wants to visit as many cities as possible within a specified time limit T. She can start her journey from any city. Help Aisha determine the maximum numbe...
from collections import defaultdict def dfs(graph, node, visited, time_elapsed, T, count): visited[node] = True max_cities = count for neighbor, travel_time in graph[node]: if time_elapsed + travel_time <= T and not visited[neighbor]: max_cities = max(max_cities, dfs(graph, neighbor, vi...
from solution import max_cities_visit def test_example_case(): N = 5 M = 6 T = 7 roads = [ (1, 2, 2), (1, 3, 4), (2, 3, 1), (2, 4, 5), (3, 5, 3), (4, 5, 2) ] assert max_cities_visit(N, M, T, roads) == 4 def test_no_roads(): N = 3 M = 0 ...
[ { "docstring": null, "function_declaration": "def dfs(graph, node, visited, time_elapsed, T, count):", "function_name": "dfs", "parameter_list": "(graph, node, visited, time_elapsed, T, count)" }, { "docstring": null, "function_declaration": "def max_cities_visit(N, M, T, roads):", "...
[ 0, 0, 0, 1, 0, 0, 0, 0, 0, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "import heapq\n\ndef max_cities_within_time(N, M, T, roads):\n graph = [[] for _ in range(N + 1)]\n for u, v, t in roads:\n graph[u].append((v, t)...
trial_gpt4o_3
{ "original_instruction": "", "prompt_id": "00011415", "row_id": 11415, "seed_ids": "[7691]" }
0.748152
Codeforces_11415
I
[ "dfs", "max_cities_visit" ]
2
[ [ "max_cities_visit", "dfs" ] ]
1
[]
false
[]
false
pytest
true
[]
true
79bb943f94d4ab101a5a1c041d54abbf08a338ac
42c9a846ddacd6df6511b765c62ae8fada267303
v1.0
instruct
Codeforces
Codeforces_11428_I
Michael and Sarah are playing a board game involving a grid of size $$$n \times n$$$. Each cell of the grid contains a token with a non-negative integer value. At the start of the game, all tokens are placed face down, and their values are hidden. Each token can either have a value of $$$0$$$ or $$$1$$$. Each round, ...
def expected_sums(n, r, grid, changes): expected_values = [] total_tokens = n * n current_sum = sum(sum(row) for row in grid) current_expected_value = current_sum / total_tokens expected_values.append(current_expected_value) for x, y, v in changes: current_sum -= grid[x][y] ...
import pytest from solution import expected_sums, parse_and_run def test_expected_sums_initial_case(): n, r = 3, 2 grid = [ [0, 1, 0], [1, 0, 1], [0, 0, 1] ] changes = [ (0, 0, 1), (2, 2, 0) ] expected = [4/9, 5/9, 4/9] result = expected_sums(n, r, gr...
[ { "docstring": null, "function_declaration": "def expected_sums(n, r, grid, changes):", "function_name": "expected_sums", "parameter_list": "(n, r, grid, changes)" }, { "docstring": null, "function_declaration": "def parse_and_run(input_str):", "function_name": "parse_and_run", "...
[ 1, 1, 0, 0, 1, 1, 1, 0, 0, 1 ]
6
medium
0.6
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def expected_sums(n, r, grid, ops):\n \"\"\"\n Returns the expected sum of all token values after each round.\n \n n: int : the size of the grid (...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00011428", "row_id": 11428, "seed_ids": "[7498]" }
0.612015
Codeforces_11428
I
[ "expected_sums", "parse_and_run" ]
2
[ [ "parse_and_run", "expected_sums" ] ]
1
[]
false
[]
false
pytest
true
[]
true
40f6774c2faacb0f3ca7374589ad6fcf21ba78da
421c9c2a816160a7d860af02bbfbb7e567cfe441
v1.0
instruct
Codeforces
Codeforces_11466_I
Let's create a question that involves graph traversal and is related to a transport network, but focuses more on optimizing the route time under specific conditions. In the city of Graphville, there is an efficient bus transport system. The city is represented as a set of n intersections connected by m directed bus ro...
import heapq import sys from collections import defaultdict def dijkstra(n, edges): graph = defaultdict(list) for u, v, t in edges: graph[u].append((v, t)) distances = [float('inf')] * (n + 1) distances[1] = 0 priority_queue = [(0, 1)] # (distance to node, node) while priority_qu...
from solution import express_bus_routes def test_example_1(): n = 5 m = 6 routes = [ (1, 2, 4), (1, 3, 2), (2, 3, 1), (3, 4, 7), (2, 5, 3), (4, 5, 1) ] assert express_bus_routes(n, m, routes) == [0, 4, 2, 9, 7] def test_example_2(): n = 4 m =...
[ { "docstring": null, "function_declaration": "def dijkstra(n, edges):", "function_name": "dijkstra", "parameter_list": "(n, edges)" }, { "docstring": null, "function_declaration": "def express_bus_routes(n, m, routes):", "function_name": "express_bus_routes", "parameter_list": "(...
[ 1, 1, 1, 0, 1, 1, 1, 1, 1, 1 ]
9
easy
0.9
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "import heapq\nimport sys\n\ndef shortest_travel_times_from_central_station(n, m, routes):\n graph = {i: [] for i in range(1, n + 1)}\n for u, v, t in ro...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00011466", "row_id": 11466, "seed_ids": "[1395]" }
0.73636
Codeforces_11466
I
[ "dijkstra", "express_bus_routes" ]
2
[ [ "express_bus_routes", "dijkstra" ] ]
1
[]
false
[]
false
pytest
true
[]
true
30eef78a1bd1d19f684cc62de7c280c3537d290a
9c9d25bac68421995d11869b502f36b436897242
v1.0
instruct
Codeforces
Codeforces_11494_I
Tom is learning about string manipulations and has just learned about the concept of palindromes. A palindrome is a string that reads the same backward as forward. He is particularly interested in finding the longest palindromic substring within a given string. Given a string of characters, help Tom determine the longe...
def longest_palindromic_substring(s): """ Returns the longest palindromic substring of s. """ n = len(s) if n == 0: return "" start = 0 end = 0 for i in range(n): len1 = expand_around_center(s, i, i) len2 = expand_around_center(s, i, i + 1) max_l...
from solution import longest_palindromic_substring def test_single_character(): assert longest_palindromic_substring("a") == "a" assert longest_palindromic_substring("b") == "b" def test_two_characters(): assert longest_palindromic_substring("aa") == "aa" assert longest_palindromic_substring("ab") == ...
[ { "docstring": "Returns the longest palindromic substring of s.", "function_declaration": "def longest_palindromic_substring(s):", "function_name": "longest_palindromic_substring", "parameter_list": "(s)" }, { "docstring": null, "function_declaration": "def expand_around_center(s, left, ...
[ 0, 1, 1, 0, 1, 1, 1, 0, 1, 0 ]
6
medium
0.6
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def longest_palindromic_substring(s):\n \"\"\"\n Returns the longest palindromic substring in the given string.\n \"\"\"\n n = len(s)\n if n ==...
trial_gpt4o_5
{ "original_instruction": "", "prompt_id": "00011494", "row_id": 11494, "seed_ids": "[4603]" }
0.855789
Codeforces_11494
I
[ "longest_palindromic_substring", "expand_around_center" ]
2
[ [ "longest_palindromic_substring", "expand_around_center" ] ]
1
[]
false
[]
false
pytest
true
[]
true
7aecc328549551c07fc9ccbc0268f9989d1db65a
45fcce74658400011a8e1db74b81e4ba17d33beb
v1.0
instruct
Codeforces
Codeforces_11505_I
The Great Generator Puzzle You are the head engineer at Future Energy Corp, and you've been tasked with optimizing the energy generators distributed across a power grid. The power grid consists of a series of connected nodes arranged in a tree structure. Each node represents a generator that provides a certain amount ...
from collections import defaultdict import sys sys.setrecursionlimit(200000) def build_tree(edges, n): tree = defaultdict(list) for u, v in edges: tree[u].append(v) tree[v].append(u) return tree def dfs(node, parent, tree, energies, subtree_max): subtree_max[node] = energies[node - 1]...
from solution import solve def test_example_case(): n = 5 q = 3 energies = [2, 3, 5, 4, 6] edges = [(1, 2), (1, 3), (3, 4), (3, 5)] queries = [1, 3, 4] result = solve(n, q, energies, edges, queries) assert result == [6, 6, 4] def test_single_node(): n = 1 q = 1 energies = [7] ...
[ { "docstring": null, "function_declaration": "def build_tree(edges, n):", "function_name": "build_tree", "parameter_list": "(edges, n)" }, { "docstring": null, "function_declaration": "def dfs(node, parent, tree, energies, subtree_max):", "function_name": "dfs", "parameter_list":...
[ 1, 0, 1, 0, 1, 1, 1, 1, 0, 1 ]
7
easy
0.7
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def find_max_energy_in_subtree(n, energies, edges, queries):\n from collections import defaultdict, deque\n \n # build the adjacency list for the tre...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00011505", "row_id": 11505, "seed_ids": "[3946]" }
0.660635
Codeforces_11505
I
[ "build_tree", "dfs", "precompute_subtree_max", "solve" ]
4
[ [ "precompute_subtree_max", "dfs" ], [ "solve", "build_tree" ], [ "solve", "precompute_subtree_max" ] ]
3
[]
false
[]
false
pytest
true
[]
true
5a5fbf5e583bb5ecc242721ddf5cacbe36b2e0fa
d1279a4e3e4fc52d95928037396b36e0638ed163
v1.0
instruct
Codeforces
Codeforces_11532_I
You are given a grid with n rows and m columns, which can be represented as an n by m matrix of cells. Each cell of the matrix can either be passable (denoted by '.') or blocked (denoted by '*'). You need to answer q queries about the grid. Each query will ask whether there exists a path between two specified cells (r1...
from collections import deque def preprocess_grid(grid, n, m): """ Preprocess the grid to determine the connectivity of cells using a simple BFS or DFS and label connected components. """ def in_bounds(x, y): return 0 <= x < n and 0 <= y < m def bfs(component_id, start_x, start_y)...
from solution import main def test_example_case(): n = 4 m = 4 grid = [ "....", ".*..", "..*.", "...." ] q = 3 queries = [ (1, 1, 4, 4), (1, 2, 3, 2), (1, 1, 1, 4) ] main(n, m, grid, q, queries) def test_case_no_path(): n...
[ { "docstring": "Preprocess the grid to determine the connectivity of cells using a simple BFS or DFS \nand label connected components.", "function_declaration": "def preprocess_grid(grid, n, m):", "function_name": "preprocess_grid", "parameter_list": "(grid, n, m)" }, { "docstring": "Determi...
[ 1, 0, 0, 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 collections import deque\n\ndef preprocess_grid(grid, n, m):\n \"\"\"\n Preprocess the grid to determine the connectivity of cells using a simple B...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00011532", "row_id": 11532, "seed_ids": "[6503]" }
0.674852
Codeforces_11532
I
[ "preprocess_grid", "solvable", "main" ]
3
[ [ "solvable", "preprocess_grid" ] ]
1
[]
false
[]
false
pytest
true
[]
true
27751ea472b41825ec96bf1c4a593f1ab297a757
78c9c31e9b2080382dc483df4f63e158049f0318
v1.0
instruct
Codeforces
Codeforces_11548_I
You are given an undirected graph with n nodes and m edges. Each node is numbered from 1 to n. Two nodes can either be connected with an edge or not. Each edge has a weight associated with it. Your task is to calculate the minimum weight of a path that connects two given nodes s and t. The edges are represented by thr...
import heapq def dijkstra(n, edges, start, end): 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)) pq = [(0, start)] distances = {i: float('inf') for i in range(1, n+1)} distances[start] = 0 while pq: c...
from solution import min_weight_path def test_example_case(): n = 6 m = 7 edges = [ (1, 2, 2), (1, 3, 4), (2, 3, 1), (2, 4, 7), (3, 5, 3), (4, 6, 1), (5, 6, 5) ] s = 1 t = 6 assert min_weight_path(n, m, edges, s, t) == 10 def test_no_...
[ { "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_weight_path(n, m, edges, s, t):", "function_name": "min_weight_path", ...
[ 1, 0, 1, 1, 1, 0, 0, 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 dijkstra(n, edges, start, end):\n # Initialize graph as an adjacency list\n graph = {i: [] for i in range(1, n + 1)}\n for u, v, ...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00011548", "row_id": 11548, "seed_ids": "[6204]" }
0.878784
Codeforces_11548
I
[ "dijkstra", "min_weight_path" ]
2
[ [ "min_weight_path", "dijkstra" ] ]
1
[]
false
[]
false
pytest
true
[]
true
861010df7129c404690fa179787985eda1a8849d
19ae48ba7a6dacc24b6687db8145880110a26fd6
v1.0
instruct
Codeforces
Codeforces_11583_I
You are given a sequence of integers. Your task is to find a pair of integers in the sequence such that their sum is a prime number. If there are multiple pairs, print the pair with the lowest first element. If there are still ties, print the pair with the lowest second element. If there are no such pairs, print "No pa...
import itertools def is_prime(num): if num < 2: return False for i in range(2, int(num**0.5) + 1): if num % i == 0: return False return True def find_pair_with_prime_sum(n, lst): lst.sort() pairs = list(itertools.combinations(lst, 2)) best_pair = None for a, b ...
from solution import find_pair_with_prime_sum def test_solution_example(): assert find_pair_with_prime_sum(5, [4, 7, 1, 10, 5]) == (1, 4) def test_no_pairs(): assert find_pair_with_prime_sum(3, [4, 6, 8]) == "No pairs found" def test_single_pair(): assert find_pair_with_prime_sum(2, [4, 3]) == (3, 4) de...
[ { "docstring": null, "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": null, "function_declaration": "def find_pair_with_prime_sum(n, lst):", "function_name": "find_pair_with_prime_sum", "parameter_list": "(n, l...
[ 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 is_prime(num):\n \"\"\"\n Checks if a number is prime.\n \"\"\"\n if num <= 1:\n return False\n if num == 2:\n return True\n ...
trial_gpt4o_5
{ "original_instruction": "", "prompt_id": "00011583", "row_id": 11583, "seed_ids": "[4121]" }
0.788837
Codeforces_11583
I
[ "is_prime", "find_pair_with_prime_sum" ]
2
[ [ "find_pair_with_prime_sum", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
7ca26492afc2542fbb3ed619f618d86027cfc63e
3bed6493a40205451fda6fafc4e2ca837f850ccb
v1.0
instruct
Codeforces
Codeforces_11591_I
You are given a town with n houses connected by m roads. Each road connects two houses and has a certain length. The town’s authorities want to ensure that every house can be reached from any other house by travelling along these roads. However, due to budget constraints, they want to minimize the total length of the r...
def find(parent, i): if parent[i] == i: return i else: return find(parent, parent[i]) def union(parent, rank, x, y): xroot = find(parent, x) yroot = find(parent, y) if rank[xroot] < rank[yroot]: parent[xroot] = yroot elif rank[xroot] > rank[yroot]: parent[yr...
def test_no_solution(): n, m = 3, 1 roads = [(1, 2, 1)] assert town_roads(n, m, roads) == "No solution" def test_simple_case(): n, m = 4, 5 roads = [ (1, 2, 3), (2, 3, 4), (3, 4, 5), (4, 1, 2), (2, 4, 6) ] assert town_roads(n, m, roads) == 9 def ...
[ { "docstring": null, "function_declaration": "def find(parent, i):", "function_name": "find", "parameter_list": "(parent, i)" }, { "docstring": null, "function_declaration": "def union(parent, rank, x, y):", "function_name": "union", "parameter_list": "(parent, rank, x, y)" }, ...
[ 1, 1, 1, 1, 0, 0, 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_minimum_spanning_tree(n, m, roads):\n \"\"\"\n This function calculates the minimum total length of the roads needed \n to keep all houses c...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00011591", "row_id": 11591, "seed_ids": "[2042]" }
0.726492
Codeforces_11591
I
[ "find", "union", "minimum_spanning_tree", "town_roads" ]
4
[ [ "minimum_spanning_tree", "find" ], [ "minimum_spanning_tree", "union" ], [ "town_roads", "minimum_spanning_tree" ], [ "union", "find" ] ]
4
[]
false
[]
false
pytest
false
[]
true
ef0f6c27d4da759ad6e1ccfbc6de13f4c8833cdc
83da0eb9c42d5da8f65f127399ee14a1bbea3690
v1.0
instruct
Codeforces
Codeforces_11593_I
You are given a grid-based game map represented by a matrix containing characters that indicate different types of terrain. The game involves navigating from the top-left corner to the bottom-right corner of the grid. The goal is to find the shortest path from the start to the end position while only traversing through...
from heapq import heappop, heappush def min_cost_to_reach_end(grid): m, n = len(grid), len(grid[0]) if grid[0][0] == '#' or grid[m-1][n-1] == '#': return -1 # Directions for moving in the grid directions = [(0, 1), (1, 0), (0, -1), (-1, 0)] # Priority queue for Dijkstra's algorith...
import pytest from solution import solve def test_example_1(): assert solve(3, 4, ["S.#.", ".*..", "..E."]) == 5 def test_example_2(): assert solve(4, 4, ["S.#*", ".#..", "#.E.", "****"]) == -1 def test_one_step_apart(): assert solve(2, 2, ["S.", ".E"]) == 2 def test_no_possible_path(): assert solve...
[ { "docstring": null, "function_declaration": "def min_cost_to_reach_end(grid):", "function_name": "min_cost_to_reach_end", "parameter_list": "(grid)" }, { "docstring": null, "function_declaration": "def solve(m, n, grid):", "function_name": "solve", "parameter_list": "(m, n, grid...
[ 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\n\ndef min_cost_to_reach_end(grid):\n if not grid or not grid[0]:\n return -1\n\n m, n = len(grid), len(grid[0])\n start, end = (...
trial_gpt4o_4
{ "original_instruction": "", "prompt_id": "00011593", "row_id": 11593, "seed_ids": "[200]" }
0.747994
Codeforces_11593
I
[ "min_cost_to_reach_end", "solve" ]
2
[ [ "solve", "min_cost_to_reach_end" ] ]
1
[]
false
[]
false
pytest
true
[]
true
85e76b1c37660f75cb186c8e4bfdee66c1a72989
1a685b310631065c81f3175ac4dbf25573c1f729
v1.0
instruct
Codeforces
Codeforces_11595_I
You are given a rectangular field represented by a grid with dimensions n x m, where 1 <= n, m <= 1000. Each cell in the grid can either be empty (marked as '.') or contain an obstacle (marked as '#'). A rectangle in the grid is defined as a set of contiguous cells forming a subgrid. The rectangle is considered "vali...
def is_valid_rectangle(grid, n, m): """ Returns True if there is at least one valid rectangle in the grid; otherwise, returns False. """ for top in range(n): for left in range(m): if grid[top][left] == '#': for bottom in range(top + 2, n): for righ...
from solution import exists_valid_rectangle def test_example_1(): n = 5 m = 7 grid = [ "#######", "#.....#", "#.....#", "#.....#", "#######" ] assert exists_valid_rectangle(n, m, grid) == "YES" def test_example_2(): n = 4 m = 4 grid = [ "...
[ { "docstring": "Returns True if there is at least one valid rectangle in the grid; otherwise, returns False.", "function_declaration": "def is_valid_rectangle(grid, n, m):", "function_name": "is_valid_rectangle", "parameter_list": "(grid, n, m)" }, { "docstring": null, "function_declarat...
[ 0, 1, 1, 0, 0, 1, 0, 0, 0, 0 ]
3
hard
0.3
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_valid_rectangle(n, m, grid):\n \"\"\"\n Returns \"YES\" if there exists at least one valid rectangle in the grid. Otherwise, returns \"NO\".\n ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00011595", "row_id": 11595, "seed_ids": "[20]" }
0.752506
Codeforces_11595
I
[ "is_valid_rectangle", "exists_valid_rectangle" ]
2
[ [ "exists_valid_rectangle", "is_valid_rectangle" ] ]
1
[]
false
[]
false
pytest
true
[]
true
aa01421482ced43e34c1f8ac8aa12928ba3500fc
32db2c8c27c7b850bd1dbf0c1bea69e1555af534
v1.0
instruct
Codeforces
Codeforces_11603_I
You are given a grid of size n by m filled with lowercase letters from 'a' to 'z'. Your task is to find out if there exists a rectangle in the grid such that the concatenation of the letters within this rectangle (traversed row-by-row) forms one of the given words. The grid can be represented using n strings, each of ...
def can_form_word(grid, word): n = len(grid) m = len(grid[0]) length = len(word) # Iterate through all possible starting points for x1 in range(n): for y1 in range(m): # Iterate through all possible ending points for x2 in range(x1, n): for y2 in ...
def test_can_form_word(): grid = [ "abde", "cabc", "deab" ] words = ["ab", "caad", "abc", "de"] results = ["YES", "NO", "YES", "YES"] for word, result in zip(words, results): assert can_form_word(grid, word) == result def test_solve(): n, m, k = 3, 4, 2 ...
[ { "docstring": null, "function_declaration": "def can_form_word(grid, word):", "function_name": "can_form_word", "parameter_list": "(grid, word)" }, { "docstring": null, "function_declaration": "def solve(n, m, k, grid, words):", "function_name": "solve", "parameter_list": "(n, m...
[ 1, 0, 0, 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": "def is_word_in_rectangle(grid, n, m, word):\n word_len = len(word)\n \n for x1 in range(n):\n for x2 in range(x1, n):\n for y1 in r...
trial_gpt4o_7
{ "original_instruction": "", "prompt_id": "00011603", "row_id": 11603, "seed_ids": "[284]" }
0.720575
Codeforces_11603
I
[ "can_form_word", "solve" ]
2
[ [ "solve", "can_form_word" ] ]
1
[]
false
[]
false
pytest
false
[]
true
2583466d417ee595eaae1e23d000ffa771cdb625
a37c7877ef4bd0716eee34d9fba0babcadf6d16e
v1.0
instruct
Codeforces
Codeforces_11627_I
You are given a sequence of n integers representing the heights of different buildings in a row. You are an urban planner tasked with placing a large advertising banner across these buildings. The banner can be placed such that it spans across multiple buildings, but due to regulations, the height of the banner must no...
def largestRectangleArea(heights): """ Function to calculate the largest rectangle area in a histogram. """ stack = [] max_area = 0 index = 0 while index < len(heights): # Push the current building to the stack if it's taller than the building at stack top if not stack or he...
from solution import max_banner_area def test_example_case(): assert max_banner_area(6, [2, 1, 5, 6, 2, 3]) == 10 def test_all_same_height(): assert max_banner_area(5, [2, 2, 2, 2, 2]) == 10 def test_increasing_heights(): assert max_banner_area(5, [1, 2, 3, 4, 5]) == 9 # The max area is at bar of height...
[ { "docstring": "Function to calculate the largest rectangle area in a histogram.", "function_declaration": "def largestRectangleArea(heights):", "function_name": "largestRectangleArea", "parameter_list": "(heights)" }, { "docstring": "Function to find the maximum possible area of the adverti...
[ 1, 0, 1, 0, 0, 0, 0, 1, 0 ]
3
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def max_banner_area(heights):\n \"\"\"\n Returns the maximum possible area of the advertisement banner\n given the heights of the buildings in a row....
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00011627", "row_id": 11627, "seed_ids": "[764]" }
0.71894
Codeforces_11627
I
[ "largestRectangleArea", "max_banner_area" ]
2
[ [ "max_banner_area", "largestRectangleArea" ] ]
1
[]
false
[]
false
pytest
true
[]
true
b227b14cba813e571707ba7ab49bc0dc528b6a52
dea0142a0c0d241db50d3b003ca3e3b5460cfee2
v1.0
instruct
Codeforces
Codeforces_11666_I
Berland city is well-known for its organized subway system. The city consists of n stations and m subway lines. Each subway line connects a pair of stations and has a certain distance di, which is the time it takes for a train to travel from one end of the line to the other. There can be multiple lines between a pair o...
import heapq def dijkstra(n, edges): """ Implements Dijkstra's algorithm to find the shortest path from station 1 to all others. Args: n (int): Number of stations. edges (list of tuple of int): List of edges where each is a tuple (ai, bi, di) representing a co...
def test_solve_berland(): input_data = "4\n4\n1 2 4\n1 3 2\n2 3 5\n3 4 3" assert solve_berland(input_data) == ['4', '2', '5'] def test_solve_berland_unreachable(): input_data = "4\n2\n1 2 4\n3 4 3" assert solve_berland(input_data) == ['4', 'unreachable', 'unreachable'] def test_solve_berland_single_li...
[ { "docstring": "Implements Dijkstra's algorithm to find the shortest path from station 1 to all others.\n\nArgs:\nn (int): Number of stations.\nedges (list of tuple of int): List of edges where each is a tuple (ai, bi, di) representing\n a connection from station ai to bi with dista...
[ 1, 1, 1, 1, 1, 0, 0, 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": "import heapq\nfrom collections import defaultdict, deque\n\ndef dijkstra(n, m, edges):\n # Create adjacency list\n graph = defaultdict(list)\n for u,...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00011666", "row_id": 11666, "seed_ids": "[5779]" }
0.767309
Codeforces_11666
I
[ "dijkstra", "solve_berland" ]
2
[ [ "solve_berland", "dijkstra" ] ]
1
[]
false
[]
false
pytest
false
[]
true
1d8e00f60af183e2304cb2c61e1c2ed46d56874f
c1c45eefcc1c73a94b2d869b0a79eaa89ce325e5
v1.0
instruct
Codeforces
Codeforces_11717_I
A group of biologists is studying the migration patterns of a species of birds. Each bird is equipped with a GPS tracker that records its latitude and longitude every minute of its flight. The biologists have the coordinates recorded for each bird at each minute interval over a period of one hour. Your task is to help...
import math def haversine(lat1, lon1, lat2, lon2): # Radius of the Earth in kilometers R = 6371.0 # Convert latitude and longitude from degrees to radians lat1_rad = math.radians(lat1) lon1_rad = math.radians(lon1) lat2_rad = math.radians(lat2) lon2_rad = math.radians(lon2) # ...
from solution import haversine, total_distance_traveled, main def test_haversine(): assert round(haversine(40.730610, -73.935242, 40.730611, -73.935200), 2) == 0.00 assert round(haversine(34.052235, -118.243683, 34.052245, -118.243679), 2) == 0.00 assert round(haversine(0, 0, 0, 1), 2) == 111.19 # Approxi...
[ { "docstring": null, "function_declaration": "def haversine(lat1, lon1, lat2, lon2):", "function_name": "haversine", "parameter_list": "(lat1, lon1, lat2, lon2)" }, { "docstring": null, "function_declaration": "def total_distance_traveled(bird_coordinates):", "function_name": "total_...
[ 0, 0, 0, 0, 1, 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": "import math\n\ndef haversine_distance(lat1, lon1, lat2, lon2):\n R = 6371 # Earth's radius in km\n \n # Convert latitude and longitude from degrees ...
trial_gpt4o_5
{ "original_instruction": "", "prompt_id": "00011717", "row_id": 11717, "seed_ids": "[219]" }
0.584211
Codeforces_11717
I
[ "haversine", "total_distance_traveled", "main" ]
3
[ [ "total_distance_traveled", "haversine" ] ]
1
[]
false
[]
false
pytest
true
[]
true
f73ac10ab19e7d7f015c7cc92e2deb11a10c9b07
979d827db7bc2b3172862cf2866530e7ec6825bc
v1.0
instruct
Codeforces
Codeforces_11826_I
In an ancient land, there is a magical library that consists of n scrolls arranged in a line. Each scroll contains a word, and some words are enchanted. A spell can be cast to transform one word into another only if they differ by exactly one character. Determining the minimum number of spell casts needed to transform ...
from collections import deque def is_one_char_diff(word1, word2): """ Returns True if word1 and word2 differ by exactly one character. """ diff_count = 0 for c1, c2 in zip(word1, word2): if c1 != c2: diff_count += 1 if diff_count > 1: return False ...
from solution import min_spell_casts def test_example_case(): assert min_spell_casts("hit", "hot", ["hit", "dot", "dog", "lot", "log"]) == 1 def test_same_word(): assert min_spell_casts("abc", "abc", ["abc", "def", "ghi"]) == 0 def test_no_possible_transformation(): assert min_spell_casts("abc", "xyz", [...
[ { "docstring": "Returns True if word1 and word2 differ by exactly one character.", "function_declaration": "def is_one_char_diff(word1, word2):", "function_name": "is_one_char_diff", "parameter_list": "(word1, word2)" }, { "docstring": "Returns the minimum number of spell casts needed to tra...
[ 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 deque\n\ndef is_one_char_diff(word1, word2):\n \"\"\"\n Returns True if word1 and word2 differ by exactly one character.\n \"...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00011826", "row_id": 11826, "seed_ids": "[886]" }
0.605279
Codeforces_11826
I
[ "is_one_char_diff", "min_spell_casts" ]
2
[ [ "min_spell_casts", "is_one_char_diff" ] ]
1
[]
false
[]
false
pytest
true
[]
true
d0b3b3a29ab755043cf69cba9397c4cb587c0fc4
41fbfcbee0070afe1c726c24631900bbf462ab9a
v1.0
instruct
Codeforces
Codeforces_11933_I
Polycarp has recently joined a new club where they are obsessed with numbers and their properties. One of the fun activities they do in the club is to compare two numbers based on their divisors. A number $$$x$$$ is said to "dominate" number $$$y$$$ if $$$x$$$ has more divisors than $$$y$$$. Polycarp has $$$n$$$ numb...
from collections import defaultdict def count_divisors(n): """ Returns the number of divisors of n. """ divisors = 0 i = 1 while i * i <= n: if n % i == 0: if i * i == n: divisors += 1 else: divisors += 2 i += 1 return ...
import pytest from solution import main def test_example_case(): n = 5 a = [6, 12, 15, 7, 10] m = 3 queries = [(1, 2), (3, 4), (5, 1)] assert main(n, a, m, queries) == ['NO', 'YES', 'NO'] def test_all_equal_numbers(): n = 3 a = [10, 10, 10] m = 3 queries = [(1, 2), (2, 3), (1, 3)] ...
[ { "docstring": "Returns the number of divisors of n.", "function_declaration": "def count_divisors(n):", "function_name": "count_divisors", "parameter_list": "(n)" }, { "docstring": "Preprocesses the list of numbers to calculate the number of divisors for each number.", "function_declara...
[ 1, 1, 1, 0, 0, 0, 1, 0, 1, 0 ]
5
medium
0.5
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "import math\nfrom collections import defaultdict\n\ndef count_divisors(x):\n \"\"\"\n Returns the number of divisors of x\n \"\"\"\n if x == 1:\n ...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00011933", "row_id": 11933, "seed_ids": "[1849]" }
0.617833
Codeforces_11933
I
[ "count_divisors", "preprocess_divisors", "check_dominance", "main" ]
4
[ [ "preprocess_divisors", "count_divisors" ] ]
1
[]
false
[]
false
pytest
true
[]
true
b402fdd483cb80eac13d2d4457f36f7c4323c7c2
e48e7c68bb5498f80f3d5103428470ff7a119bec
v1.0
instruct
Codeforces
Codeforces_11955_I
You are given a rectangular grid of size n x m where each cell can either be blocked (denoted by '#') or unblocked (denoted by '.'). You are initially located at the top-left corner of the grid (1, 1), and you want to move to the bottom-right corner of the grid (n, m). However, you can only move through unblocked cells...
MOD = 1000000007 def count_ways(grid, n, m): 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] == '#': continue if i > 0: ...
import pytest def test_example_case(): n, m = 3, 3 grid_lines = [".##", "...", "##."] assert solve(n, m, grid_lines) == 1 def test_no_way_case(): n, m = 3, 3 grid_lines = ["###", "...", "##."] assert solve(n, m, grid_lines) == 0 def test_full_path(): n, m = 2, 2 grid_lines = ["..", "....
[ { "docstring": null, "function_declaration": "def count_ways(grid, n, m):", "function_name": "count_ways", "parameter_list": "(grid, n, m)" }, { "docstring": null, "function_declaration": "def solve(n, m, grid_lines):", "function_name": "solve", "parameter_list": "(n, m, grid_lin...
[ 1, 0, 0, 1, 0, 1, 1, 1, 0, 0 ]
5
medium
0.5
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "MOD = 1000000007\n\ndef count_ways(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(...
trial_gpt4o_7
{ "original_instruction": "", "prompt_id": "00011955", "row_id": 11955, "seed_ids": "[6024]" }
0.783891
Codeforces_11955
I
[ "count_ways", "solve" ]
2
[ [ "solve", "count_ways" ] ]
1
[]
false
[]
false
pytest
false
[]
true
5b15b1085d1825cadb955ee42f8bb5b10fb80163
5723a560120bc27eed3f52656d2467380dfc0734
v1.0
instruct
Codeforces
Codeforces_12041_I
You are given an array of integers `arr` of length `n`, where `n` is even (1 <= n <= 1000) and `arr[i]` can be positive or negative (-1000 <= arr[i] <= 1000). Your task is to divide the array into two parts such that the absolute difference between the sum of the elements in the first part and the sum of the elements i...
def subset_sum(arr, n, total_sum, calculated_sum): if n == 0: return abs((total_sum - calculated_sum) - calculated_sum) # Including the current element in the first set inc_current = subset_sum(arr, n-1, total_sum, calculated_sum + arr[n-1]) # Excluding the current element from the fir...
from solution import minimize_difference def test_minimize_difference_example_1(): arr = [1, 6, 11, 5] assert minimize_difference(arr) == 1 def test_minimize_difference_example_2(): arr = [1, 2, 3, 4, 5, 6] assert minimize_difference(arr) == 1 def test_minimize_difference_example_3(): arr = [...
[ { "docstring": null, "function_declaration": "def subset_sum(arr, n, total_sum, calculated_sum):", "function_name": "subset_sum", "parameter_list": "(arr, n, total_sum, calculated_sum)" }, { "docstring": null, "function_declaration": "def minimize_difference(arr):", "function_name": ...
[ 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": "from itertools import combinations\n\ndef find_minimized_difference(arr):\n \"\"\"\n Returns the minimized absolute difference between the sums \n of...
trial_gpt4o_4
{ "original_instruction": "", "prompt_id": "00012041", "row_id": 12041, "seed_ids": "[6669]" }
0.805099
Codeforces_12041
I
[ "subset_sum", "minimize_difference" ]
2
[ [ "minimize_difference", "subset_sum" ] ]
1
[]
false
[]
false
pytest
true
[]
true
401dad41cfc58174770880d7faf36aad45b35fd2
ecf513813b345d63386be78f4eae879680c74ef1
v1.0
instruct
Codeforces
Codeforces_12052_I
A dedicated mathematician named Alice is fascinated by sequences and patterns. She came across a problem where she needs to find a sequence of numbers that meet a specific criterion. For a given positive integer k, she needs to generate the first k numbers in a sequence where every number is less than 1000 and devoid ...
def has_sequential_identical_digits(n): """Helper function to check if a number has sequential identical digits.""" num_str = str(n) for i in range(len(num_str) - 1): if num_str[i] == num_str[i+1]: return True return False def generate_sequence(k): """ Generate the first k n...
from solution import generate_sequence, has_sequential_identical_digits def test_has_sequential_identical_digits(): assert has_sequential_identical_digits(112) == True assert has_sequential_identical_digits(121) == False assert has_sequential_identical_digits(333) == True assert has_sequential_identica...
[ { "docstring": "Helper function to check if a number has sequential identical digits.", "function_declaration": "def has_sequential_identical_digits(n):", "function_name": "has_sequential_identical_digits", "parameter_list": "(n)" }, { "docstring": "Generate the first k numbers less than 100...
[ 1, 0, 1, 1, 1, 1, 0, 0, 1 ]
6
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def generate_sequence(k):\n \"\"\"\n Generates the first k numbers where every number is less than 1000 and devoid of \n any sequential identical dig...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00012052", "row_id": 12052, "seed_ids": "[6628]" }
0.687091
Codeforces_12052
I
[ "has_sequential_identical_digits", "generate_sequence" ]
2
[ [ "generate_sequence", "has_sequential_identical_digits" ] ]
1
[]
false
[]
false
pytest
true
[]
true
a0d862e8718bd98ceb49c03f0defe053e69b29fe
abd708ec51891ae72126c883205c372921095f2e
v1.0
instruct
Codeforces
Codeforces_12062_I
You are given a tree with n nodes rooted at node 1. Each node i has a value vi associated with it. You need to answer q queries. Each query is described by two integers u and k, where you are required to find the k-th ancestor of node u. If node u does not have a k-th ancestor, output -1. Write a function `find_kth_an...
from collections import defaultdict, deque def preprocess_ancestors(n, edges): # Initialize the tree and parent dictionary tree = defaultdict(list) for a, b in edges: tree[a].append(b) tree[b].append(a) # Ancestor table ancestors = {i: [] for i in range(1, n + 1)} # BF...
from solution import process_queries def test_sample(): n = 5 values = [10, 20, 30, 40, 50] edges = [(1, 2), (1, 3), (2, 4), (2, 5)] queries = [(4, 1), (5, 2), (3, 1), (3, 3)] expected_output = [2, 1, 1, -1] assert process_queries(n, values, edges, queries) == expected_output def test_no_ances...
[ { "docstring": null, "function_declaration": "def preprocess_ancestors(n, edges):", "function_name": "preprocess_ancestors", "parameter_list": "(n, edges)" }, { "docstring": null, "function_declaration": "def find_kth_ancestor(ancestors, u, k):", "function_name": "find_kth_ancestor",...
[ 1, 0, 1, 0, 0, 1, 1, 1, 0, 0 ]
5
medium
0.5
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def find_kth_ancestor(n, values, edges, q, queries):\n import sys\n sys.setrecursionlimit(200000)\n \n from collections import defaultdict, deque\...
trial_gpt4o_7
{ "original_instruction": "", "prompt_id": "00012062", "row_id": 12062, "seed_ids": "[2308]" }
0.66529
Codeforces_12062
I
[ "preprocess_ancestors", "find_kth_ancestor", "process_queries" ]
3
[ [ "process_queries", "find_kth_ancestor" ], [ "process_queries", "preprocess_ancestors" ] ]
2
[ "process_queries" ]
false
[]
false
pytest
true
[]
true
26f4e49a9dfb90b194f3daf534bc4840c7708484
b81b8ac17a9000af313b7ca662a68a3cd61ff9a9
v1.0
instruct
Codeforces
Codeforces_12125_I
You are given a binary tree where each node contains a value. We need to find the largest sum of a subtree where a subtree is defined as a node and all its descendants, and the value of the subtree is the sum of values of all the nodes within it. ## Requirements **Input:** - The input consists of a binary tree where ...
class TreeNode: def __init__(self, value=0, left=None, right=None): self.value = value self.left = left self.right = right def build_tree(nodes): tree_nodes = [None] * len(nodes) for i in range(len(nodes)): tree_nodes[i] = TreeNode(nodes[i][0]) for i in range(len(nodes))...
from solution import find_largest_subtree_sum def test_example(): n = 5 nodes = [ (1, 2, 3), (2, -1, -1), (3, 4, -1), (4, -1, 5), (5, -1, -1) ] assert find_largest_subtree_sum(n, nodes) == 15 def test_single_node(): n = 1 nodes = [ (10, -1, -1) ...
[]
[ 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": "class TreeNode:\n def __init__(self, value=0, left=None, right=None):\n self.value = value\n self.left = left\n self.right = right\n\n...
trial_gpt4o_7
{ "original_instruction": "", "prompt_id": "00012125", "row_id": 12125, "seed_ids": "[4693]" }
0.629438
Codeforces_12125
I
[ "build_tree", "max_subtree_sum", "find_largest_subtree_sum" ]
3
[ [ "find_largest_subtree_sum", "build_tree" ], [ "find_largest_subtree_sum", "max_subtree_sum" ] ]
2
[]
false
[ "TreeNode" ]
true
pytest
true
[]
true
24ec0967d69b61cb6e57d9d15146bd88a104765b
1c0554780eabb12b8977343826b4a9abe7e71c64
v1.0
instruct
Codeforces
Codeforces_12146_I
You are given an array of non-negative integers. Your task is to rearrange the elements of the array to form the largest possible number and print that number. Consider the following examples: - For the array [3, 30, 34, 5, 9], the largest number that can be formed is 9534330. - For the array [1, 20, 23, 4, 8], the la...
from functools import cmp_to_key def compare(x, y): """ Comparator function to decide the order of strings x and y. """ if x + y > y + x: return -1 elif x + y < y + x: return 1 else: return 0 def largest_number(arr): """ Given an array of non-negative integers, ...
from solution import largest_number def test_largest_number_example1(): assert largest_number([3, 30, 34, 5, 9]) == '9534330' def test_largest_number_example2(): assert largest_number([1, 20, 23, 4, 8]) == '8423201' def test_largest_number_same_numbers(): assert largest_number([0, 0, 0, 0]) == '0' def t...
[ { "docstring": "Comparator function to decide the order of strings x and y.", "function_declaration": "def compare(x, y):", "function_name": "compare", "parameter_list": "(x, y)" }, { "docstring": "Given an array of non-negative integers, rearranges them to form the largest possible number."...
[ 1, 1, 0, 1, 0, 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": "from functools import cmp_to_key\n\ndef largest_number(nums):\n \"\"\"\n Rearrange the elements of the given array to form the largest possible number.\...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00012146", "row_id": 12146, "seed_ids": "[6091]" }
0.7001
Codeforces_12146
I
[ "compare", "largest_number" ]
2
[ [ "largest_number", "compare" ] ]
1
[]
false
[]
false
pytest
true
[]
true
24fdf22899ec03018bf5ad79aefc42ffe602c80b
c85e854b202d03203f4fb7d8f6bfa21728622bc2
v1.0
instruct
Codeforces
Codeforces_12149_I
You are given a dataset containing information about various products sold by a fictional e-commerce company. Each product falls under one of three categories: Electronics, Clothing, or HomeGoods. Your task is to create a recommendation system that suggests products similar to a given product. Each product is represen...
import math from typing import List, Tuple def euclidean_distance(features1: List[int], features2: List[int]) -> float: return math.sqrt(sum((a - b) ** 2 for a, b in zip(features1, features2))) def most_similar_product(target: Tuple[int, List[int]], products: List[Tuple[int, List[int]]]) -> int: target_id, ta...
from solution import most_similar_product def test_most_similar_product_basic(): target = (1234, [90, 85, 70, 60, 88, 75, 80, 95, 85, 90]) products = [ (5678, [85, 80, 75, 70, 79, 85, 90, 88, 80, 85]), (2345, [75, 60, 78, 95, 82, 85, 88, 85, 75, 60]), (6789, [90, 85, 70, 60, 88, 75, 80,...
[ { "docstring": null, "function_declaration": "def euclidean_distance(features1, features2):", "function_name": "euclidean_distance", "parameter_list": "(features1, features2)" }, { "docstring": null, "function_declaration": "def most_similar_product(target, products):", "function_nam...
[ 0, 1, 0, 1, 0, 1, 1, 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": "import math\n\ndef euclidean_distance(features1, features2):\n distance = 0\n for a, b in zip(features1, features2):\n distance += (a - b) ** 2\n...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00012149", "row_id": 12149, "seed_ids": "[6121]" }
0.495698
Codeforces_12149
I
[ "euclidean_distance", "most_similar_product" ]
2
[ [ "most_similar_product", "euclidean_distance" ] ]
1
[]
false
[]
false
pytest
true
[]
true
a84f95dd9573bc2fd0e9e6157afffb33d13a9396
d1da92b5645dd445f174d063669e4b4aa3b30042
v1.0
instruct
Codeforces
Codeforces_12217_I
You're given $$$n$$$ distinct points on a 2D plane with integer coordinates that form the vertices of a simple polygon (no two edges intersect, except at their endpoints). Your task is to determine the area of the largest triangle that can be formed by any three of these points. The triangle's area should be calculat...
from itertools import combinations def calculate_triangle_area(x1, y1, x2, y2, x3, y3): """ Calculates the area of a triangle given its vertices' coordinates using the determinant formula. """ return abs(x1*(y2 - y3) + x2*(y3 - y1) + x3*(y1 - y2)) / 2.0 def find_largest_triangle_area(points): """ ...
from solution import find_largest_triangle_area def test_example(): points = [(0, 0), (0, 2), (2, 0), (2, 2), (1, 1)] assert abs(find_largest_triangle_area(points) - 2.0) < 1e-6 def test_all_points_on_a_line(): points = [(0, 0), (1, 1), (2, 2)] assert find_largest_triangle_area(points) == 0.0 def tes...
[ { "docstring": "Calculates the area of a triangle given its vertices' coordinates using the determinant formula.", "function_declaration": "def calculate_triangle_area(x1, y1, x2, y2, x3, y3):", "function_name": "calculate_triangle_area", "parameter_list": "(x1, y1, x2, y2, x3, y3)" }, { "do...
[ 1, 1, 0, 0, 0, 0, 0, 0, 0, 0 ]
2
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "from itertools import combinations\nfrom typing import List, Tuple\n\ndef triangle_area(p1: Tuple[int, int], p2: Tuple[int, int], p3: Tuple[int, int]) -> floa...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00012217", "row_id": 12217, "seed_ids": "[2216]" }
0.575331
Codeforces_12217
I
[ "calculate_triangle_area", "find_largest_triangle_area" ]
2
[ [ "find_largest_triangle_area", "calculate_triangle_area" ] ]
1
[]
false
[]
false
pytest
true
[]
true
7ef3fccd10d6a148acabc86f3508c8a36bd355d9
89a449b07bf0d1339614708173ada475a6e6376c
v1.0
instruct
Codeforces
Codeforces_12246_I
Given an array of integers and several queries about the sum of subarray elements, you need to preprocess the array to handle the queries efficiently. The first line contains an integer n (1 ≤ n ≤ 105) — the number of elements in the array. The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 105) — the elem...
def preprocess_sums(arr): """ Preprocesses the array to create a prefix sum array. """ prefix_sums = [0] * (len(arr) + 1) for i in range(len(arr)): prefix_sums[i + 1] = prefix_sums[i] + arr[i] return prefix_sums def query_sum(prefix_sums, l, r): """ Returns the sum of elements f...
from solution import preprocess_sums, query_sum, process_queries def test_preprocess_sums(): arr = [1, 2, 3, 4, 5] expected_prefix_sums = [0, 1, 3, 6, 10, 15] assert preprocess_sums(arr) == expected_prefix_sums def test_query_sum(): prefix_sums = [0, 1, 3, 6, 10, 15] assert query_sum(prefix_sums, ...
[ { "docstring": "Preprocesses the array to create a prefix sum array.", "function_declaration": "def preprocess_sums(arr):", "function_name": "preprocess_sums", "parameter_list": "(arr)" }, { "docstring": "Returns the sum of elements from the l-th to r-th index (1-indexed).", "function_de...
[ 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 preprocess_array(arr):\n \"\"\"\n Preprocesses the array to create a prefix sum array.\n \"\"\"\n n = len(arr)\n prefix_sum = [0] * (n + 1)...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00012246", "row_id": 12246, "seed_ids": "[1662]" }
0.727334
Codeforces_12246
I
[ "preprocess_sums", "query_sum", "process_queries" ]
3
[ [ "process_queries", "preprocess_sums" ], [ "process_queries", "query_sum" ] ]
2
[ "process_queries" ]
false
[]
false
pytest
true
[]
true
158ab3c9445322183a92753cc25acfab2b0cc965
7097045e9973459dce63075ac5d41bffc0569d9a
v1.0
instruct
Codeforces
Codeforces_12263_I
You are given an undirected, connected graph with n vertices, numbered from 1 to n, and m edges. Each vertex has a weight associated with it, represented by an array w where w[i] is the weight of vertex i (1 ≤ i ≤ n). You need to answer q queries about the graph. Each query is represented by a vertex u and an integer ...
def find_components(n, edges): """ Using DFS to find all connected components in the graph. Returns a list of sets where each set represents a component. """ from collections import defaultdict graph = defaultdict(list) for u, v in edges: graph[u].append(v) graph[v].appe...
def test_find_components(): # Test case 1 n, edges = 5, [(1, 2), (1, 3), (4, 5)] result = find_components(n, edges) expected = [{1, 2, 3}, {4, 5}] assert [set(c) for c in sorted([list(comp) for comp in result])] == [set(c) for c in sorted([list(comp) for comp in expected])] # Test case 2 with n...
[ { "docstring": "Using DFS to find all connected components in the graph.\nReturns a list of sets where each set represents a component.", "function_declaration": "def find_components(n, edges):", "function_name": "find_components", "parameter_list": "(n, edges)" }, { "docstring": null, "...
[ 0, 0, 1, 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": "def find_connected_components(n, edges):\n from collections import defaultdict, deque\n\n def bfs(start, adj_list, visited):\n queue = deque([sta...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00012263", "row_id": 12263, "seed_ids": "[4102]" }
0.827082
Codeforces_12263
I
[ "find_components", "solve" ]
2
[ [ "solve", "find_components" ] ]
1
[]
false
[]
false
pytest
false
[]
true
ec0f45f8b3cef785963cea6bd30c2a655a255f5b
65b47d727c053dc0557cfc8f0c94e9e302dcf87c
v1.0
instruct
Codeforces
Codeforces_12333_I
A word ladder is a sequence of words in which each word differs from the previous one by exactly one letter. Given a start word and an end word of the same length, and a dictionary of valid words, determine the length of the shortest word ladder from start to end, or return 0 if no such ladder exists. For example, giv...
from collections import deque def is_one_letter_diff(word1, word2): """ Check if the two words differ by exactly one letter. """ diff_count = 0 for i in range(len(word1)): if word1[i] != word2[i]: diff_count += 1 if diff_count > 1: return False return dif...
def test_shortest_word_ladder_length_basic(): assert shortest_word_ladder_length("hit", "cog", ["hot", "dot", "dog", "lot", "log", "cog"]) == 5 def test_shortest_word_ladder_length_no_ladder(): assert shortest_word_ladder_length("hit", "cog", ["hot", "dot", "dog", "lot", "log"]) == 0 def test_shortest_word_la...
[ { "docstring": "Check if the two words differ by exactly one letter.", "function_declaration": "def is_one_letter_diff(word1, word2):", "function_name": "is_one_letter_diff", "parameter_list": "(word1, word2)" }, { "docstring": "Determine the length of the shortest word ladder from start to ...
[ 1, 0, 0, 0, 0, 0, 1, 0, 0, 1 ]
3
hard
0.3
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "from collections import deque\n\ndef word_ladder_length(start, end, dictionary):\n \"\"\"\n Returns the length of the shortest word ladder from start to...
trial_gpt4o_6
{ "original_instruction": "", "prompt_id": "00012333", "row_id": 12333, "seed_ids": "[6436]" }
0.561345
Codeforces_12333
I
[ "is_one_letter_diff", "shortest_word_ladder_length" ]
2
[ [ "shortest_word_ladder_length", "is_one_letter_diff" ] ]
1
[]
false
[]
false
pytest
false
[]
true
d8c7a20b9ce60333364b97fa3202f03d8b81f4a1
a8baf124881d7195aba0f81c98927f3dc4e8a349
v1.0
instruct
Codeforces
Codeforces_12366_I
Petya recently learned about prime numbers and their interesting properties. In honor of his love for primes, his friends decided to play a game with him. They lined up n integers in a sequence and Petya's task is to find the sum of prime numbers from that sequence. You are given a list of n integers. Your task is to ...
def is_prime(num): """ Check if a number is a prime number. """ if num <= 1: return False for i in range(2, int(num**0.5) + 1): if num % i == 0: return False return True def sum_of_primes(nums): """ Returns the sum of prime numbers from the list of numbers. ...
from solution import is_prime, sum_of_primes def test_is_prime(): assert is_prime(2) == True assert is_prime(3) == True assert is_prime(4) == False assert is_prime(5) == True assert is_prime(10) == False assert is_prime(13) == True assert is_prime(1) == False assert is_prime(0) == False...
[ { "docstring": "Check if a number is a prime number.", "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": "Returns the sum of prime numbers from the list of numbers.", "function_declaration": "def sum_of_primes(nums):", ...
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
10
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(num):\n \"\"\"\n Returns True if num is a prime number, else False.\n \"\"\"\n if num <= 1:\n return False\n for i in range...
trial_gpt4o_7
{ "original_instruction": "", "prompt_id": "00012366", "row_id": 12366, "seed_ids": "[5329]" }
0.675409
Codeforces_12366
I
[ "is_prime", "sum_of_primes" ]
2
[ [ "sum_of_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
7d7abaad662f1a0a149aad96832c8dd4fbfad333
dfec97e9c9c036e4917f9b7a865f2c9cfc127d14
v1.0
instruct
Codeforces
Codeforces_12370_I
You are given a large tree with `n` nodes, rooted at node `1`. Each node has a value assigned to it. Your task is to process several queries of two types: 1. Update the value of a specific node. 2. Calculate the sum of values in the subtree of a given node. Input: - The first line contains two integers `n` and `q` (`...
def build_tree(n, edges): from collections import defaultdict tree = defaultdict(list) for u, v in edges: tree[u].append(v) tree[v].append(u) return tree def dfs_subtree_sum(node, parent, tree, node_values, subtree_sum): total_sum = node_values[node] for neighbor in tree[node]: ...
def test_build_tree(): edges = [(1, 2), (1, 3), (3, 4), (3, 5)] tree = build_tree(5, edges) expected_tree = { 1: [2, 3], 2: [1], 3: [1, 4, 5], 4: [3], 5: [3] } assert tree == expected_tree def test_dfs_subtree_sum(): initial_values = [1, 2, 3, 4, 5] t...
[ { "docstring": null, "function_declaration": "def build_tree(n, edges):", "function_name": "build_tree", "parameter_list": "(n, edges)" }, { "docstring": null, "function_declaration": "def dfs_subtree_sum(node, parent, tree, node_values, subtree_sum):", "function_name": "dfs_subtree_...
[ 0, 0, 1, 0, 1, 1, 0, 1, 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 Tree:\n def __init__(self, n, values):\n self.n = n\n self.values = values\n self.tree = [[] for _ in range(n + 1)]\n sel...
trial_gpt4o_7
{ "original_instruction": "", "prompt_id": "00012370", "row_id": 12370, "seed_ids": "[7753]" }
0.630756
Codeforces_12370
I
[ "build_tree", "dfs_subtree_sum", "process_queries" ]
3
[ [ "process_queries", "build_tree" ], [ "process_queries", "dfs_subtree_sum" ] ]
2
[ "process_queries" ]
false
[]
false
pytest
false
[]
true
48dd07d6381759f40c9db007ae94bed126913cba
19004a0aa7a8a1f3a7ab0fae51b1389698d70b93
v1.0
instruct
Codeforces
Codeforces_12376_I
Design an API endpoint that allows users to subscribe and unsubscribe from a newsletter. Requirements: 1. Create two endpoints: - `/subscribe`: accepts a user's email and subscribes them to the newsletter. - `/unsubscribe`: accepts a user's email and unsubscribes them from the newsletter. 2. Use basic authentica...
from flask import Flask, request, jsonify from werkzeug.security import generate_password_hash, check_password_hash from functools import wraps import re app = Flask(__name__) # A simple database placeholder subscribers = set() # Helper function to validate email format def is_valid_email(email): regex = r'^\b[A...
import pytest from solution import app, subscribers @pytest.fixture def client(): with app.test_client() as client: yield client def test_subscribe_success(client): response = client.post('/subscribe', json={"email": "test@example.com"}, headers={"Authorization": "Basic dXNlcjpwYXNzd29yZA=="}) # 'user...
[ { "docstring": null, "function_declaration": "def is_valid_email(email):", "function_name": "is_valid_email", "parameter_list": "(email)" }, { "docstring": null, "function_declaration": "def auth_required(f):", "function_name": "auth_required", "parameter_list": "(f)" }, { ...
[ 0, 0, 0, 1, 0, 0, 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": "from flask import Flask, request, jsonify\nfrom flask_httpauth import HTTPBasicAuth\nimport re\n\napp = Flask(__name__)\nauth = HTTPBasicAuth()\n\n# In-memory...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00012376", "row_id": 12376, "seed_ids": "[2291]" }
0.471073
Codeforces_12376
I
[ "is_valid_email", "auth_required", "subscribe", "unsubscribe" ]
4
[ [ "subscribe", "is_valid_email" ], [ "unsubscribe", "is_valid_email" ] ]
2
[]
false
[]
false
pytest
true
[ "flask", "werkzeug" ]
false
297791a5638b4492e9dc8774d495e6da0c781ac6
7e8c528a02b24bd2c80f13b606af91807ec60264
v1.0
instruct
Codeforces
Codeforces_12385_I
Alex is fond of playing games on a grid. He came up with one such game where he needs to traverse an $n \times n$ grid. The grid is represented by an $n \times n$ matrix filled with non-negative integers. The goal is to find the maximum sum of any path from the top-left corner (cell (1,1)) to the bottom-right corner (c...
def max_path_sum(grid): n = len(grid) dp = [[0] * n for _ in range(n)] # Initialize the dp table dp[0][0] = grid[0][0] # Fill the first row and first column for i in range(1, n): dp[0][i] = dp[0][i-1] + grid[0][i] dp[i][0] = dp[i-1][0] + grid[i][0] # Fill the r...
from solution import max_path_sum_from_input def test_case_1(): grid = [ [1, 3, 1, 4], [2, 2, 3, 2], [4, 1, 2, 1], [2, 1, 2, 3] ] assert max_path_sum_from_input(4, grid) == 16 def test_case_2(): grid = [ [1, 2, 3], [4, 5, 6], [7, 8, 9] ] ...
[ { "docstring": null, "function_declaration": "def max_path_sum(grid):", "function_name": "max_path_sum", "parameter_list": "(grid)" }, { "docstring": null, "function_declaration": "def max_path_sum_from_input(n, grid):", "function_name": "max_path_sum_from_input", "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": "def max_path_sum(n, grid):\n \"\"\"\n Returns the maximum sum of any path from the top-left corner to the bottom-right corner.\n \"\"\"\n # Create...
trial_gpt4o_4
{ "original_instruction": "", "prompt_id": "00012385", "row_id": 12385, "seed_ids": "[4576]" }
0.647379
Codeforces_12385
I
[ "max_path_sum", "max_path_sum_from_input" ]
2
[ [ "max_path_sum_from_input", "max_path_sum" ] ]
1
[]
false
[]
false
pytest
true
[]
true
7801ee0f7be236032f44f7d140eadd66dabcf59e
02d1d27b7838df8b8594c16c261774d03145df12
v1.0
instruct
Codeforces
Codeforces_12404_I
A prime P is a number that is greater than 1 and has no positive divisor other than 1 and itself. An anagram of P is any number that can be formed by rearranging the digits of P in any order, including leading zeros. For example, if P is 197, its anagrams include 197, 719, and 971. However, 179, 791, and 917, and othe...
from itertools import permutations def is_prime(n): """ Returns True if n is a prime number, otherwise False. """ if n <= 1: return False if n == 2: return True if n % 2 == 0: return False for i in range(3, int(n**0.5)+1, 2): if n % i == 0: return...
from solution import prime_anagram def test_prime_anagram_single(): assert prime_anagram(2) == "Prime Anagram" assert prime_anagram(0) == "Not Prime Anagram" assert prime_anagram(1) == "Not Prime Anagram" def test_prime_anagram_various(): assert prime_anagram(197) == "Prime Anagram" assert prime_a...
[ { "docstring": "Returns True if n is a prime number, otherwise False.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Returns \"Prime Anagram\" if any anagram of N is a prime number, otherwise \"Not Prime Anagram\".", ...
[ 1, 1, 1, 0, 1, 0, 0, 1, 0 ]
5
medium
0.556
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "from itertools import permutations\n\ndef is_prime(num):\n if num <= 1:\n return False\n if num == 2:\n return True\n if num % 2 == 0:\...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00012404", "row_id": 12404, "seed_ids": "[7977]" }
0.625548
Codeforces_12404
I
[ "is_prime", "prime_anagram" ]
2
[ [ "prime_anagram", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
a55dce67872da0303001a2a840427af8ba876e72
a3bb33640026e8f4d412bc20fc1e4272824ef699
v1.0
instruct
Codeforces
Codeforces_12422_I
You are given an array `arr` of `n` integers (1 ≤ n ≤ 10^5, 1 ≤ arr[i] ≤ 10^9) and `q` queries (1 ≤ q ≤ 10^5). Each query requires finding the sum of the elements in a specific subarray. The input format is as follows: - The first line contains two integers, `n` and `q`. - The second line contains `n` space-separated ...
def prefix_sum(arr): """ Generates the prefix sum array for the given array. """ n = len(arr) prefix = [0] * (n + 1) for i in range(1, n + 1): prefix[i] = prefix[i - 1] + arr[i - 1] return prefix def query_sum(l, r, prefix): """ Returns the sum of the subarray from index l t...
def test_prefix_sum(): arr = [1, 2, 3, 4, 5] expected_prefix = [0, 1, 3, 6, 10, 15] assert prefix_sum(arr) == expected_prefix def test_query_sum(): prefix = [0, 1, 3, 6, 10, 15] assert query_sum(1, 3, prefix) == 6 assert query_sum(2, 4, prefix) == 9 assert query_sum(1, 5, prefix) == 15 def...
[ { "docstring": "Generates the prefix sum array for the given array.", "function_declaration": "def prefix_sum(arr):", "function_name": "prefix_sum", "parameter_list": "(arr)" }, { "docstring": "Returns the sum of the subarray from index l to r using the prefix sum array.", "function_decl...
[ 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 compute_prefix_sums(arr):\n \"\"\"\n Computes the prefix sums of an array.\n \"\"\"\n n = len(arr)\n prefix_sums = [0] * (n + 1)\n # Com...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00012422", "row_id": 12422, "seed_ids": "[7307]" }
0.701238
Codeforces_12422
I
[ "prefix_sum", "query_sum", "solve" ]
3
[ [ "solve", "prefix_sum" ], [ "solve", "query_sum" ] ]
2
[]
false
[]
false
pytest
false
[]
true
22b7077b852210f9949ca9715a354989e80e8c7c
0523a635ba59bfd5f63710938378cb903b08de63
v1.0
instruct
Codeforces
Codeforces_12451_I
Alyssa is designing an amusement park layout. The park consists of three main attractions: a roller coaster, a Ferris wheel, and a water ride. She wants to create walking paths connecting these attractions, but needs to ensure that the paths cover certain constraints. Alyssa starts at the roller coaster (R) and first...
import math def calculate_distance(point1, point2): return math.sqrt((point2[0] - point1[0])**2 + (point2[1] - point1[1])**2) def can_complete_route(S, R, F, W): """ Determines if the route R -> F -> W -> R can be completed within the stamina limit S. Parameters: - S: int, the stamina limit. ...
from solution import can_complete_route def test_example_case(): S = 25 R = (0, 0) F = (3, 4) W = (6, 8) assert can_complete_route(S, R, F, W) == True def test_case_exceeding_stamina(): S = 15 R = (0, 0) F = (3, 4) W = (6, 8) assert can_complete_route(S, R, F, W) == False ...
[ { "docstring": null, "function_declaration": "def calculate_distance(point1, point2):", "function_name": "calculate_distance", "parameter_list": "(point1, point2)" }, { "docstring": "Determines if the route R -> F -> W -> R can be completed within the stamina limit S.\n\nParameters:\n- S: in...
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 0 ]
9
easy
0.9
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "import math\n\ndef distance(p1, p2):\n \"\"\"\n Calculate the Euclidean distance between two points.\n \"\"\"\n return math.sqrt((p1[0] - p2[0]) *...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00012451", "row_id": 12451, "seed_ids": "[4158]" }
0.673447
Codeforces_12451
I
[ "calculate_distance", "can_complete_route" ]
2
[ [ "can_complete_route", "calculate_distance" ] ]
1
[]
false
[]
false
pytest
true
[]
true
c1124f2739045cf3e2c6f6e648f7bc375257a15b
80082a34f2956c4d94ec1fff8941adef4ce635af
v1.0
instruct
Codeforces
Codeforces_12473_I
In a large competitive corporation, there is a hierarchical structure composed of n employees, including the CEO. Each employee (except the CEO) has exactly one direct manager, who is also an employee of the company. Recently, the company decided to restructure its departments by creating teams such that each team inc...
def dfs(u, parent, children, productivity, subtree_sum): subtree_sum[u] = productivity[u] for v in children[u]: if v != parent: dfs(v, u, children, productivity, subtree_sum) subtree_sum[u] += subtree_sum[v] def max_team_productivity(n, productivity, edges): # Create an adja...
from solution import max_team_productivity def test_example_case(): n = 6 productivity = [10, 5, 8, 7, 6, 5] edges = [(1, 2), (1, 3), (2, 4), (2, 5), (3, 6)] assert max_team_productivity(n, productivity, edges) == 18 def test_small_case(): n = 2 productivity = [1, 2] edges = [(1, 2)] a...
[ { "docstring": null, "function_declaration": "def dfs(u, parent, children, productivity, subtree_sum):", "function_name": "dfs", "parameter_list": "(u, parent, children, productivity, subtree_sum)" }, { "docstring": null, "function_declaration": "def max_team_productivity(n, productivity...
[ 0, 0, 1, 0, 0, 0, 0, 0, 1, 1 ]
3
hard
0.3
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def max_team_productivity_score(n, productivity_scores, subordinates):\n import collections\n\n # Convert productivity_scores to be 1-indexed\n produ...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00012473", "row_id": 12473, "seed_ids": "[7903]" }
0.615012
Codeforces_12473
I
[ "dfs", "max_team_productivity" ]
2
[ [ "max_team_productivity", "dfs" ] ]
1
[]
false
[]
false
pytest
true
[]
true
711eafb68a6323f410e18316bfd41adaff87eaa1
b8df6dbb4eb48d6397c3d7f1f5d5d8436b699c3b
v1.0
instruct
Codeforces
Codeforces_12524_I
A logistics company wants to optimize their delivery routes within a city. The city is represented as an undirected graph where intersections are nodes, and roads between intersections are edges. The company needs to determine the shortest path from their warehouse (node $$1$$) to all delivery points (given as a list o...
import heapq def dijkstra(graph, start, n): dist = [float('inf')] * (n + 1) dist[start] = 0 pq = [(0, start)] while pq: current_dist, u = heapq.heappop(pq) if current_dist > dist[u]: continue for v, weight in graph[u]: distance = current_dist + weight ...
from solution import logistics_optimizer def test_example(): n = 5 m = 6 roads = [(1, 2, 3), (1, 3, 7), (2, 3, 3), (2, 4, 2), (3, 4, 5), (3, 5, 6)] k = 3 closed_roads = [(1, 4, 2), (2, 3, 4), (3, 5, 8)] d = 2 delivery_points = [4, 5] output = logistics_optimizer(n, m, roads, k, closed_r...
[ { "docstring": null, "function_declaration": "def dijkstra(graph, start, n):", "function_name": "dijkstra", "parameter_list": "(graph, start, n)" }, { "docstring": null, "function_declaration": "def logistics_optimizer(n, m, roads, k, closed_roads, d, delivery_points):", "function_na...
[ 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": "import heapq\nfrom collections import defaultdict\nfrom typing import List, Tuple\n\ndef find_min_reopening_cost(n: int, m: int, roads: List[Tuple[int, int, i...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00012524", "row_id": 12524, "seed_ids": "[7710]" }
0.74998
Codeforces_12524
I
[ "dijkstra", "logistics_optimizer" ]
2
[ [ "logistics_optimizer", "dijkstra" ] ]
1
[]
false
[]
false
pytest
true
[]
true
b8aa7ff188c040f27bd9594cfe0b47de29ed511b
80d00ea5024bb8a7987f3beddc8e11a98df229d8
v1.0
instruct
Codeforces
Codeforces_12546_I
In a dense city, Bob is trying to create a network of public parks connected by pedestrian bridges. Each park has a unique integer ID. A pedestrian bridge can connect two parks bidirectionally, allowing people to walk between them. However, to minimize costs and maintenance, Bob wants to ensure that there is exactly on...
def assign_types(n, k, edges): from collections import defaultdict, deque if k == 1 and n > 1: return "NO" # Build the adjacency list graph = defaultdict(list) for u, v in edges: graph[u].append(v) graph[v].append(u) # BFS to color the tree types = [-1] * (...
from solution import solve def test_example_case(): parks = 5 types = 3 connections = [(1, 2), (1, 3), (2, 4), (3, 5)] solve(parks, types, connections) assert True def test_only_one_type_and_multiple_parks(): parks = 5 types = 1 connections = [(1, 2), (1, 3), (2, 4), (3, 5)] assert...
[ { "docstring": null, "function_declaration": "def assign_types(n, k, edges):", "function_name": "assign_types", "parameter_list": "(n, k, edges)" }, { "docstring": null, "function_declaration": "def solve(parks, types, connections):", "function_name": "solve", "parameter_list": "...
[ 0, 1, 1, 1, 0, 0, 0, 0, 0, 0 ]
3
hard
0.3
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "from collections import deque\n\ndef can_assign_types(n, k, edges):\n if k == 1 and n > 1:\n return False, []\n \n # Create adjacency list for...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00012546", "row_id": 12546, "seed_ids": "[6991]" }
0.661169
Codeforces_12546
I
[ "assign_types", "solve" ]
2
[ [ "solve", "assign_types" ] ]
1
[]
false
[]
false
pytest
true
[]
true
f54765230eacb3d0ede8c736df0251d5a89648cb
7408ec4c2e78c01af28f3efa7996c9b2ba3f3c82
v1.0
instruct
Codeforces
Codeforces_12639_I
You are hired to develop a streamlined ticketing system for a small movie theater that is handling multiple screenings throughout the day. Each screening has a start time, an end time, and a movie ID. You are required to determine if a person can watch all movies without any schedule conflicts. The input starts with a...
def can_watch_all_movies(screenings): """ Determines if a person can watch all movies without any schedule conflicts based on the provided screenings. Args: screenings (list of tuples): Each tuple contains three integers, start time, end time, and movie ID for e...
from solution import can_watch_all_movies, process_input, solve def test_can_watch_all_movies_possible(): screenings = [(60, 120, 1), (130, 170, 2), (180, 240, 3)] assert can_watch_all_movies(screenings) == "Possible" def test_can_watch_all_movies_impossible(): screenings = [(60, 120, 1), (100, 140, 2), (...
[ { "docstring": "Determines if a person can watch all movies without any schedule conflicts\nbased on the provided screenings.\n\nArgs:\nscreenings (list of tuples): Each tuple contains three integers, start time,\n end time, and movie ID for each screening.\n\nReturns:\nstr: \"Possib...
[ 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 can_watch_all_movies(screenings):\n \"\"\"\n Determine if it's possible to watch all movies without any scheduling conflicts.\n\n :param screenin...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00012639", "row_id": 12639, "seed_ids": "[3698]" }
0.658001
Codeforces_12639
I
[ "can_watch_all_movies", "process_input", "solve" ]
3
[ [ "solve", "can_watch_all_movies" ], [ "solve", "process_input" ] ]
2
[ "process_input" ]
false
[]
false
pytest
true
[]
true
a1154a7c0f19d9008bc7c9b0b03d791590227d73
48c7e682a7d654471c16082294dbc62053caf131
v1.0
instruct
Codeforces
Codeforces_12784_I
You are given an undirected graph with n vertices and m edges. Each edge has a weight w associated with it. A spanning tree of this graph is a subset of the edges that form a tree and connect all vertices. Your task is to determine the maximum weight of a spanning tree of this graph. Input The first line contains two ...
# Kruskal's Algorithm with maximum spanning tree concept def find(parent, i): if parent[i] == i: return i return find(parent, parent[i]) def union(parent, rank, x, y): root_x = find(parent, x) root_y = find(parent, y) if rank[root_x] > rank[root_y]: parent[root_y] = root_x elif...
def test_maximum_spanning_tree_simple(): n = 4 edges = [ (1, 2, 3), (2, 3, 4), (3, 4, 5), (4, 1, 6), (1, 3, 2) ] assert maximum_spanning_tree(n, edges) == 15 def test_maximum_spanning_tree_with_more_edges(): n = 5 edges = [ (1, 2, 10), (1,...
[ { "docstring": null, "function_declaration": "def find(parent, i):", "function_name": "find", "parameter_list": "(parent, i)" }, { "docstring": null, "function_declaration": "def union(parent, rank, x, y):", "function_name": "union", "parameter_list": "(parent, rank, x, y)" }, ...
[ 0, 0, 0, 1, 1, 1, 1, 0, 0 ]
4
medium
0.444
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def find_maximum_spanning_tree_weight(n, m, edges):\n \"\"\"\n Find the maximum weight of a spanning tree of the graph using Kruskal's algorithm\n mo...
trial_gpt4o_6
{ "original_instruction": "", "prompt_id": "00012784", "row_id": 12784, "seed_ids": "[3708]" }
0.747868
Codeforces_12784
I
[ "find", "union", "maximum_spanning_tree" ]
3
[ [ "maximum_spanning_tree", "find" ], [ "maximum_spanning_tree", "union" ], [ "union", "find" ] ]
3
[]
false
[]
false
pytest
false
[]
true
48c387192a04419ac8585c914f74c5f9cb59e852
2a5e71f80e5f4c43eb90d09f8d77d0a9639e8576
v1.0
instruct
Codeforces
Codeforces_12796_I
Alice and Bob are playing a game. They each start with a number `a` and `b` respectively. On each turn, the player with the larger number can reduce their number by the greatest common divisor (GCD) of the two numbers, and the game continues until one player's number becomes zero. Alice always starts first. Write a pro...
import math def game_winner(a, b): """ Determines the winner of the game between Alice and Bob. Alice starts first. Each player reduces their number by the GCD of the two numbers in each turn. The game continues until one player's number becomes zero. Parameters: a (int): Alice's starting ...
from solution import game_result def test_game_alice_wins(): assert game_result(3, 1) == "Alice" assert game_result(5, 1) == "Alice" assert game_result(7, 1) == "Alice" def test_game_bob_wins(): assert game_result(3, 9) == "Bob" assert game_result(4, 8) == "Bob" assert game_result(12, 24) == "...
[ { "docstring": "Determines the winner of the game between Alice and Bob.\nAlice starts first. Each player reduces their number by the GCD of the two numbers in each turn.\nThe game continues until one player's number becomes zero.\n\nParameters:\na (int): Alice's starting number\nb (int): Bob's starting number\...
[ 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 math\n\ndef get_winner(a, b):\n \"\"\"\n Determines the winner of the game. Alice starts first.\n Reduces numbers by the GCD until one of the ...
trial_gpt4o_7
{ "original_instruction": "", "prompt_id": "00012796", "row_id": 12796, "seed_ids": "[2092]" }
0.773484
Codeforces_12796
I
[ "game_winner", "game_result" ]
2
[ [ "game_result", "game_winner" ] ]
1
[]
false
[]
false
pytest
true
[]
true
f65c6d726b043921138f33e2f3f96abbd7b7baf1
2ee7cf653f8cb51b0981bf1e7c7e994b1b8c9632
v1.0
instruct
Codeforces
Codeforces_12827_I
Farmer Joe has a field of crops that he wants to harvest. The field is represented as a 2D grid with m rows and n columns. Each cell in the grid can either contain a crop (represented by a 1) or be empty (represented by a 0). Farmer Joe uses a special type of harvester that can only harvest crops in a single continuous...
def largestRectangleArea(heights): stack = [] max_area = 0 for i in range(len(heights)): start = i while stack and stack[-1][1] > heights[i]: index, height = stack.pop() max_area = max(max_area, height * (i - index)) start = index stack.append((sta...
from solution import maxAreaOfCrops def test_example_case(): grid = [ [1, 0, 1, 0, 0], [1, 0, 1, 1, 1], [1, 1, 1, 1, 1], [1, 0, 0, 1, 0] ] assert maxAreaOfCrops(4, 5, grid) == 6 def test_single_column(): grid = [[1], [1], [0], [1]] assert maxAreaOfCrops(4, 1, grid) ...
[ { "docstring": null, "function_declaration": "def largestRectangleArea(heights):", "function_name": "largestRectangleArea", "parameter_list": "(heights)" }, { "docstring": null, "function_declaration": "def maxAreaOfCrops(m, n, grid):", "function_name": "maxAreaOfCrops", "paramet...
[ 0, 1, 1, 1, 1, 0, 1, 0, 0, 1 ]
6
medium
0.6
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def max_histogram_area(heights):\n \"\"\"\n Helper function to calculate the maximum rectangular area in a histogram\n given the heights of the bars....
trial_gpt4o_6
{ "original_instruction": "", "prompt_id": "00012827", "row_id": 12827, "seed_ids": "[5981]" }
0.623271
Codeforces_12827
I
[ "largestRectangleArea", "maxAreaOfCrops" ]
2
[ [ "maxAreaOfCrops", "largestRectangleArea" ] ]
1
[]
false
[]
false
pytest
true
[]
true
1cb7ad548a8d28b8f8d7f9b8600fba77be1d60ad
7534bffff42a2300ffa34f71d2635ae52511da40
v1.0
instruct
Codeforces
Codeforces_12926_I
An explorer named Jayden is on a treasure hunt in a mysterious cave system. The cave system can be represented as an undirected graph where each cave is a vertex, and each tunnel between the caves is an edge. Jayden starts at cave `1` and wants to collect as much treasure as possible before exiting at cave `n`. Each t...
from collections import defaultdict, deque def bfs(capacity, source, sink, parent): visited = set() queue = deque([source]) visited.add(source) while queue: u = queue.popleft() for v in capacity[u]: if v not in visited and capacity[u][v] > 0: qu...
from solution import max_treasure_path def test_example_case(): edges = [(1, 2, 4), (2, 3, 3), (1, 3, 2), (3, 4, 2), (3, 5, 5), (4, 5, 1)] assert max_treasure_path(5, edges) == 5 def test_single_path_case(): edges = [(1, 2, 1), (2, 3, 1), (3, 4, 1), (4, 5, 1)] assert max_treasure_path(5, edges) == 1 ...
[ { "docstring": null, "function_declaration": "def bfs(capacity, source, sink, parent):", "function_name": "bfs", "parameter_list": "(capacity, source, sink, parent)" }, { "docstring": null, "function_declaration": "def edmonds_karp(capacity, source, sink):", "function_name": "edmonds...
[ 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 heapq import heappush, heappop\nimport sys\n\ndef maxTreasure(n, m, tunnels):\n graph = [[] for _ in range(n + 1)]\n \n for a, b, c in tunnels:\...
trial_gpt4o_4
{ "original_instruction": "", "prompt_id": "00012926", "row_id": 12926, "seed_ids": "[4272]" }
0.642139
Codeforces_12926
I
[ "bfs", "edmonds_karp", "max_treasure_path" ]
3
[ [ "edmonds_karp", "bfs" ], [ "max_treasure_path", "edmonds_karp" ] ]
2
[]
false
[]
false
pytest
true
[]
true
9fafae1a5f2b87ea4b7a047e143412ef3471d7cc
d40bc464a6ffa1622a30b072561af3c4ea0294d6
v1.0
instruct
Codeforces
Codeforces_13006_I
You are given two positive integers a and b (1 ≤ a < b ≤ 10^9). You need to find the smallest positive integer x such that x is divisible by both a and b. A single line contains two integers a and b. Output a single integer — the smallest positive integer x such that x is divisible by both a and b.
def gcd(a, b): while b: a, b = b, a % b return a def lcm(a, b): return (a * b) // gcd(a, b) def smallest_common_multiple(a, b): """ Returns the smallest positive integer x such that x is divisible by both a and b. """ return lcm(a, b)
from solution import smallest_common_multiple def test_smallest_common_multiple_basic(): assert smallest_common_multiple(4, 6) == 12 assert smallest_common_multiple(3, 5) == 15 assert smallest_common_multiple(7, 14) == 14 def test_smallest_common_multiple_co_prime(): assert smallest_common_multiple(8,...
[ { "docstring": null, "function_declaration": "def gcd(a, b):", "function_name": "gcd", "parameter_list": "(a, b)" }, { "docstring": null, "function_declaration": "def lcm(a, b):", "function_name": "lcm", "parameter_list": "(a, b)" }, { "docstring": "Returns the smallest p...
[ 1, 0, 1, 0, 1, 1, 0, 1, 0, 0 ]
5
medium
0.5
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "import math\n\ndef lcm(a, b):\n \"\"\"\n Returns the smallest positive integer x such that x is divisible by both a and b.\n \"\"\"\n return (a * ...
trial_gpt4o_7
{ "original_instruction": "", "prompt_id": "00013006", "row_id": 13006, "seed_ids": "[2970]" }
0.718094
Codeforces_13006
I
[ "gcd", "lcm", "smallest_common_multiple" ]
3
[ [ "lcm", "gcd" ], [ "smallest_common_multiple", "lcm" ] ]
2
[]
false
[]
false
pytest
true
[]
true
959fc2bad79ca952d5b647cab86cee9c17b487e1
b1d2318c15c102ea80c9d93750d2633651fd8eec
v1.0
instruct
Codeforces
Codeforces_13009_I
Gildong is also interested in prime numbers now. He learned that a prime number is a natural number greater than 1 that has no positive divisors other than 1 and itself. For example, the numbers 2, 3, 5, 7, and 11 are prime, while 4, 6, 8, 9, and 10 are not prime. He decides to play with a sequence of numbers and want...
def is_prime(num): """ Determines if a number is prime. """ if num <= 1: return False for i in range(2, int(num ** 0.5) + 1): if num % i == 0: return False return True def longest_prime_subsequence(n, sequence): """ Finds the longest subsequence of prime numb...
from solution import is_prime, longest_prime_subsequence 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(1) == False assert is_prime(0) == False assert is_prime(-5) == False def test_longest_...
[ { "docstring": "Determines if a number is prime.", "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": "Finds the longest subsequence of prime numbers from the given sequence.", "function_declaration": "def longest_prime_...
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
10
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(num):\n \"\"\" Helper function to check if a number is prime \"\"\"\n if num <= 1:\n return False\n if num == 2:\n return ...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00013009", "row_id": 13009, "seed_ids": "[2264]" }
0.635678
Codeforces_13009
I
[ "is_prime", "longest_prime_subsequence" ]
2
[ [ "longest_prime_subsequence", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
bd33466e807d63bec4ded2560a558b5fa5acb2f9
e4973fe3ed519b83a47fb027ede035afb4e779ec
v1.0
instruct
Codeforces
Codeforces_13046_I
Andrew the Mathematician is given an integer array `a` of length `n` where each element `a[i]` (1 ≤ a[i] ≤ n) denotes the index of the element that should come after `a[i]` in its sorted form. However, the array may contain some elements marked as 0. Andrew needs to replace the zeros with appropriate indices from 1 to ...
MOD = 998244353 def find_factorial(n): """ Returns the factorial of a number n modulo MOD. """ fact = 1 for i in range(2, n + 1): fact = (fact * i) % MOD return fact def count_single_cycle_permutations(n, a): """ Returns the number of ways to replace zeros in the array a to for...
from solution import count_single_cycle_permutations def test_single_cycle_permutations_1(): assert count_single_cycle_permutations(3, [0, 3, 0]) == 2 def test_single_cycle_permutations_2(): assert count_single_cycle_permutations(3, [0, 3, 1]) == 1 def test_single_cycle_permutations_3(): assert count_sin...
[ { "docstring": "Returns the factorial of a number n modulo MOD.", "function_declaration": "def find_factorial(n):", "function_name": "find_factorial", "parameter_list": "(n)" }, { "docstring": "Returns the number of ways to replace zeros in the array a to form a single cycle permutation.", ...
[ 0, 1, 0, 0, 0, 1, 0, 0, 0, 0 ]
2
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "from itertools import permutations\n\nMOD = 998244353\n\ndef count_single_cycle_permutations(n, a):\n \"\"\"\n Returns the number of ways to replace zer...
trial_gpt4o_5
{ "original_instruction": "", "prompt_id": "00013046", "row_id": 13046, "seed_ids": "[4780]" }
0.688268
Codeforces_13046
I
[ "find_factorial", "count_single_cycle_permutations" ]
2
[ [ "count_single_cycle_permutations", "find_factorial" ] ]
1
[]
false
[]
false
pytest
true
[]
true
61eda40de110af779dce51caf02debaced809d2a
2d5903fbfe9b83c56af91353717e0ae99a25674e
v1.0
instruct
Codeforces
Codeforces_13094_I
You are given a rectangular grid of size m x n, filled with 0's and 1's. An island is a group of 1's (representing land) connected 4-directionally (horizontal or vertical.) You may assume all four edges of the grid are surrounded by water. The goal is to determine the number of distinct islands where an island is cons...
def numDistinctIslands(grid): def dfs(x, y, origin): if not (0 <= x < m and 0 <= y < n) or grid[x][y] == 0: return grid[x][y] = 0 shape.append((x - origin[0], y - origin[1])) for dx, dy in [(-1, 0), (1, 0), (0, -1), (0, 1)]: dfs(x + dx, y + dy, origin) ...
from solution import process_islands def test_simple_case(): input_str = "3 3\n1 1 0\n1 0 0\n0 0 1" assert process_islands(input_str) == 2 def test_single_island(): input_str = "3 3\n1 0 0\n0 0 0\n0 0 0" assert process_islands(input_str) == 1 def test_no_islands(): input_str = "3 3\n0 0 0\n0 0 0\...
[ { "docstring": null, "function_declaration": "def numDistinctIslands(grid):", "function_name": "numDistinctIslands", "parameter_list": "(grid)" }, { "docstring": null, "function_declaration": "def parse_input(input_str):", "function_name": "parse_input", "parameter_list": "(input...
[ 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 numDistinctIslands(grid):\n \"\"\"\n Returns the number of distinct islands in the grid.\n \"\"\"\n def dfs(x, y, origin_x, origin_y, shape):\...
trial_gpt4o_5
{ "original_instruction": "", "prompt_id": "00013094", "row_id": 13094, "seed_ids": "[3012]" }
0.625537
Codeforces_13094
I
[ "numDistinctIslands", "parse_input", "process_islands" ]
3
[ [ "process_islands", "numDistinctIslands" ], [ "process_islands", "parse_input" ] ]
2
[ "parse_input" ]
false
[]
false
pytest
true
[]
true
5ad13bff1a686b83695c452c6f9164a8a9ebe0dd
5c650c342eae7d9b1698a28a97dbb310ff9e7091
v1.0
instruct
Codeforces
Codeforces_13097_I
This is an interactive problem. You are given a weighted undirected graph with n vertices and m edges. Each edge has a positive integer weight. Your task is to find the shortest path from a given start vertex to a target vertex, if such a path exists. More formally, the graph consists of vertices indexed from 1 to n ...
import sys import heapq def dijkstra(n, edges, start, target): # Build graph from queried 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)) # Min-heap priority queue pq = [(0, start)] # (distance, node) dist ...
def test_dijkstra_with_default_cases(): edges = [(1, 2, 2), (2, 3, 4), (1, 3, 6)] assert dijkstra(3, edges, 1, 3) == 6 def test_dijkstra_start_equal_target(): edges = [(1, 2, 2), (2, 3, 4), (1, 3, 6)] assert dijkstra(3, edges, 1, 1) == 0 def test_dijkstra_undirected_path(): edges = [(1, 2, 2), (2,...
[ { "docstring": null, "function_declaration": "def dijkstra(n, edges, start, target):", "function_name": "dijkstra", "parameter_list": "(n, edges, start, target)" }, { "docstring": null, "function_declaration": "def solve():", "function_name": "solve", "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": "import heapq\n\ndef shortest_path(n, m, start, target, edges):\n \"\"\"\n Computes the shortest path from start vertex to target vertex using Dijkstra's...
trial_gpt4o_4
{ "original_instruction": "", "prompt_id": "00013097", "row_id": 13097, "seed_ids": "[866]" }
0.775733
Codeforces_13097
I
[ "dijkstra", "solve" ]
2
[ [ "solve", "dijkstra" ] ]
1
[]
false
[]
false
pytest
false
[]
true
56afe00bec6d180d774167bdc4e3e17468ee1585
112edc3b67568057c5cd8293d1951d697354ac31
v1.0
instruct
Codeforces
Codeforces_13139_I
Annie is working as a software developer and has been assigned to work on a project involving hierarchical data processing using trees. As part of this, she needs to write an efficient algorithm to find the Lowest Common Ancestor (LCA) of two nodes in a tree. The LCA of two nodes \(u\) and \(v\) in a tree is the deepes...
from collections import defaultdict, deque import sys import math sys.setrecursionlimit(200000) def preprocess_lca(n, edges): LOG = math.ceil(math.log2(n)) + 1 parent = [[-1] * LOG for _ in range(n + 1)] depth = [0] * (n + 1) graph = defaultdict(list) for u, v in edges: graph[u].appen...
from solution import solve def test_example(): n = 5 edges = [(1, 2), (1, 3), (3, 4), (3, 5)] queries = [(2, 3), (4, 5), (2, 4)] assert solve(n, edges, queries) == [1, 3, 1] def test_small_tree(): n = 3 edges = [(1, 2), (1, 3)] queries = [(2, 3)] assert solve(n, edges, queries) == [1] ...
[ { "docstring": null, "function_declaration": "def preprocess_lca(n, edges):", "function_name": "preprocess_lca", "parameter_list": "(n, edges)" }, { "docstring": null, "function_declaration": "def lca(u, v, depth, parent):", "function_name": "lca", "parameter_list": "(u, v, depth...
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 0 ]
9
easy
0.9
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "import sys\nimport collections\n\n# A function to perform Depth-First Search for setting up depths and ancestors\ndef dfs(node, parent, depth, depths, ancesto...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00013139", "row_id": 13139, "seed_ids": "[1284]" }
0.628291
Codeforces_13139
I
[ "preprocess_lca", "lca", "solve" ]
3
[ [ "solve", "lca" ], [ "solve", "preprocess_lca" ] ]
2
[]
false
[]
false
pytest
true
[]
true
b46d606beb4d7af4b91df93a59b63a0b04157f53
c0a47840d83d0d83da40c6e75028f7e4f57009c4
v1.0
instruct
Codeforces
Codeforces_13171_I
A small village is planning to build a network of roads to connect all its houses. The village has n houses and m potential roads that could be built. Each road connects exactly two houses and has a certain construction cost. The houses are numbered from 1 to n. The village council has two conflicting goals: 1. Minimi...
def find(parent, i): if parent[i] == i: return i else: return find(parent, parent[i]) def union(parent, rank, x, y): xroot = find(parent, x) yroot = find(parent, y) if rank[xroot] < rank[yroot]: parent[xroot] = yroot elif rank[xroot] > rank[yroot]: parent[yr...
def test_simple_connected_case(): n, m = 4, 4 roads = [ (1, 2, 1), (2, 3, 2), (3, 4, 3), (4, 1, 4) ] assert minimum_cost_to_connect_houses(n, m, roads) == 6 def test_disconnected_case(): n, m = 4, 2 roads = [ (1, 2, 1), (3, 4, 2) ] assert ...
[ { "docstring": null, "function_declaration": "def find(parent, i):", "function_name": "find", "parameter_list": "(parent, i)" }, { "docstring": null, "function_declaration": "def union(parent, rank, x, y):", "function_name": "union", "parameter_list": "(parent, rank, x, y)" }, ...
[ 0, 1, 1, 1, 1, 1, 0, 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 find(parent, i):\n if parent[i] == i:\n return i\n parent[i] = find(parent, parent[i])\n return parent[i]\n\ndef union(parent, rank, x, y)...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00013171", "row_id": 13171, "seed_ids": "[6687]" }
0.72796
Codeforces_13171
I
[ "find", "union", "minimum_cost_to_connect_houses" ]
3
[ [ "minimum_cost_to_connect_houses", "find" ], [ "minimum_cost_to_connect_houses", "union" ], [ "union", "find" ] ]
3
[]
false
[]
false
pytest
false
[]
true
5bf7de79498d6a44c7f2d3fd996cd5cbe5ff56d5
dcd49bc19c87dac751e39b9e090c7367e7d5c0cf
v1.0
instruct
Codeforces
Codeforces_13213_I
### Prime Factorization Game Alice and Bob are playing a prime factorization game. Alice writes down a sequence of n distinct positive integers on the board. Bob then starts picking pairs of numbers from the sequence in such a way that the product of each picked pair is a unique number not picked before. For each pair...
def sieve_of_eratosthenes(max_num): primes = [] is_prime = [True] * (max_num + 1) for p in range(2, max_num + 1): if is_prime[p]: primes.append(p) for multiple in range(p * p, max_num + 1, p): is_prime[multiple] = False return primes def construct_sequenc...
def test_sieve_of_eratosthenes(): assert sieve_of_eratosthenes(10) == [2, 3, 5, 7] assert sieve_of_eratosthenes(1) == [] assert sieve_of_eratosthenes(2) == [2] def test_construct_sequence(): assert construct_sequence(3, 3) == [2, 3, 5] assert construct_sequence(1, 0) == [1] assert construct_seq...
[ { "docstring": null, "function_declaration": "def sieve_of_eratosthenes(max_num):", "function_name": "sieve_of_eratosthenes", "parameter_list": "(max_num)" }, { "docstring": null, "function_declaration": "def construct_sequence(n, k):", "function_name": "construct_sequence", "par...
[ 1, 0, 0, 0, 0, 0, 0, 0, 0 ]
1
hard
0.111
{ "trial_gpt4o_0": null, "trial_gpt4o_1": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared1_results_combined.jsonl", "solution_code": "def sieve_of_eratosthenes(max_num):\n primes = []\n is_prime = [True] * (max_num + 1)\n for p in range(2, max_num + 1):\n ...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00013213", "row_id": 13213, "seed_ids": "[6613]" }
0.589567
Codeforces_13213
I
[ "sieve_of_eratosthenes", "construct_sequence" ]
2
[ [ "construct_sequence", "sieve_of_eratosthenes" ] ]
1
[]
false
[]
false
pytest
false
[]
true
e31b30e0f57bedf8bab19f6e1f0f8d0e6f45a87e
313a09adf43805627490a411d8f52b2065e5e591
v1.0
instruct
Codeforces
Codeforces_13280_I
In a magical land, there are two groups of warriors. Each group is led by a commander. Each warrior is positioned at distinct integer coordinates along the x-axis, and each commander is positioned at a unique, but not necessarily integer, coordinate on the x-axis. The goal of each commander is to cast spells to protect...
def find_optimal_commander_position(x): """ Finds the optimal position for a commander to minimize the total distance to their warriors. The optimal position lies at the median of the coordinates of the warriors. """ x.sort() n = len(x) if n % 2 == 1: return float(x[n // 2]) ...
from solution import find_optimal_commander_position, optimal_commander_positions def test_find_optimal_commander_position_single_element(): assert find_optimal_commander_position([5]) == 5.0 def test_find_optimal_commander_position_two_elements(): assert find_optimal_commander_position([1, 3]) == 2.0 def te...
[ { "docstring": "Finds the optimal position for a commander to minimize the total distance\nto their warriors. The optimal position lies at the median of the coordinates\nof the warriors.", "function_declaration": "def find_optimal_commander_position(x):", "function_name": "find_optimal_commander_positio...
[ 1, 1, 1, 1, 1, 0, 1, 0, 1 ]
7
easy
0.778
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def optimal_commander_positions(n, m, warriors1, warriors2):\n \"\"\"\n Compute optimal commander positions for two groups of warriors.\n \n Args:...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00013280", "row_id": 13280, "seed_ids": "[7485]" }
0.635532
Codeforces_13280
I
[ "find_optimal_commander_position", "optimal_commander_positions" ]
2
[ [ "optimal_commander_positions", "find_optimal_commander_position" ] ]
1
[]
false
[]
false
pytest
true
[]
true
5d76be4ecb38bfbfea931eef9b602868f8dedd37
f15ec49cfdd03a90f72b54a0e02f21f64af389d4
v1.0
instruct
Codeforces
Codeforces_13290_I
You are given a grid with n rows and m columns, where each cell may contain an integer (positive, negative, or zero). Your task is to determine, for each of the p queries, the sum of the integers within a specified rectangular subgrid. A query is described by four integers r1, c1, r2, and c2, which represent the top-le...
def precompute_prefix_sum(grid): n = len(grid) m = len(grid[0]) prefix_sum = [[0] * (m + 1) for _ in range(n + 1)] for i in range(1, n + 1): for j in range(1, m + 1): prefix_sum[i][j] = (grid[i - 1][j - 1] + prefix_sum[i - 1][j] + ...
def test_precompute_prefix_sum(): grid = [ [1, 2, 3], [4, 5, 6], [7, 8, 9] ] expected_prefix_sum = [ [0, 0, 0, 0], [0, 1, 3, 6], [0, 5, 12, 21], [0, 12, 27, 45] ] prefix_sum = precompute_prefix_sum(grid) assert prefix_sum == expected_prefix...
[ { "docstring": null, "function_declaration": "def precompute_prefix_sum(grid):", "function_name": "precompute_prefix_sum", "parameter_list": "(grid)" }, { "docstring": null, "function_declaration": "def query_sum(prefix_sum, r1, c1, r2, c2):", "function_name": "query_sum", "param...
[ 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
9
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def prepare_prefix_sum(grid):\n n = len(grid)\n m = len(grid[0])\n prefix_sum = [[0] * (m + 1) for _ in range(n + 1)]\n \n for i in range(1, n ...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00013290", "row_id": 13290, "seed_ids": "[3316]" }
0.65683
Codeforces_13290
I
[ "precompute_prefix_sum", "query_sum", "process_queries" ]
3
[ [ "process_queries", "precompute_prefix_sum" ], [ "process_queries", "query_sum" ] ]
2
[ "process_queries" ]
false
[]
false
pytest
false
[]
true
de4403290e25b2a76eff1a8707590673473105f9
823c0a688c9de3fa5f1afcc4fdb7e6792895cbb8
v1.0
instruct
Codeforces
Codeforces_13313_I
A group of friends are planning a vacation trip together and they have decided to split the expenses equally among all. Each friend will keep receipts of their payments and at the end of the trip, they will settle the expenses so that everyone ends up paying the same amount. Write a function `settle_expenses` that tak...
from collections import defaultdict def settle_expenses(transactions): balance = defaultdict(float) for payer, amount, recipient in transactions: balance[payer] -= amount balance[recipient] += amount debts = list(balance.values()) return settle(debts, 0) def settle(debts, ind...
from solution import settle_expenses def test_settle_expenses_simple_case(): transactions = [ (1, 100.0, 2), (2, 50.0, 3), (3, 50.0, 1) ] assert settle_expenses(transactions) == 1 def test_settle_expenses_multiple_transactions(): transactions = [ (1, 100.0, 2), ...
[ { "docstring": null, "function_declaration": "def settle_expenses(transactions):", "function_name": "settle_expenses", "parameter_list": "(transactions)" }, { "docstring": null, "function_declaration": "def settle(debts, index):", "function_name": "settle", "parameter_list": "(de...
[ 0, 0, 0, 1, 0, 0, 0, 0, 0, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def settle_expenses(transactions):\n from collections import defaultdict\n balance = defaultdict(float)\n\n # Calculate the net balance of each perso...
trial_gpt4o_3
{ "original_instruction": "", "prompt_id": "00013313", "row_id": 13313, "seed_ids": "[6599]" }
0.578103
Codeforces_13313
I
[ "settle_expenses", "settle" ]
2
[ [ "settle_expenses", "settle" ] ]
1
[]
false
[]
false
pytest
true
[]
true
6655b2d601b3ad5417313b5a2adea5f2f4065c4d
8d5a0d5e8775391592999ad046e1dba9f579c5ad
v1.0
instruct
Codeforces
Codeforces_13363_I
A software company wants to optimize their cloud storage system to handle user uploads more efficiently. The system has n storage servers numbered from 1 to n. These servers are connected by bidirectional communication channels in some way. Each pair of servers is connected by at most one channel. Each channel has a st...
def find(parent, i): if parent[i] == i: return i else: return find(parent, parent[i]) def union(parent, rank, x, y): rootX = find(parent, x) rootY = find(parent, y) if rank[rootX] < rank[rootY]: parent[rootX] = rootY elif rank[rootX] > rank[rootY]: parent[ro...
from solution import maximum_spanning_tree def test_basic_example(): n = 4 channels = [ (1, 2, 10), (1, 3, 5), (2, 3, 6), (2, 4, 15), (3, 4, 4) ] assert maximum_spanning_tree(n, channels) == 31 def test_minimal_case(): n = 2 channels = [ (1, 2, 1...
[ { "docstring": null, "function_declaration": "def find(parent, i):", "function_name": "find", "parameter_list": "(parent, i)" }, { "docstring": null, "function_declaration": "def union(parent, rank, x, y):", "function_name": "union", "parameter_list": "(parent, rank, x, y)" }, ...
[ 0, 1, 0, 0, 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": "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_9
{ "original_instruction": "", "prompt_id": "00013363", "row_id": 13363, "seed_ids": "[6454]" }
0.690371
Codeforces_13363
I
[ "find", "union", "maximum_spanning_tree" ]
3
[ [ "maximum_spanning_tree", "find" ], [ "maximum_spanning_tree", "union" ], [ "union", "find" ] ]
3
[]
false
[]
false
pytest
true
[]
true
c3863d4de3582a74b39a06343d83a508ea6d4bf9
c0bc7169d904ba07e4da407113c4643b996e3b6d
v1.0
instruct
Codeforces
Codeforces_13389_I
Alice and Bob are playing a game on a binary tree. They take alternating turns, and Alice always starts first. On each turn, a player must remove a leaf node from the tree. A leaf node is a node that has no children. The player who cannot make a move loses the game. You are given the initial binary tree and need to de...
class TreeNode: def __init__(self, val=0, left=None, right=None): self.val = val self.left = left self.right = right def build_tree(nodes): node_map = {} for val, left, right in nodes: if val not in node_map: node_map[val] = TreeNode(val) node = node_map[...
from solution import determine_winner def test_case_1(): tree_nodes = [ (1, 2, 3), (2, -1, -1), (3, 4, 5), (4, -1, -1), (5, -1, -1) ] assert determine_winner(tree_nodes) == "Alice" def test_case_2(): tree_nodes = [ (1, 2, -1), (2, 3, -1), ...
[]
[ 1, 1, 1, 1, 0, 0, 0, 0, 0 ]
4
medium
0.444
{ "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\ndef build_tree(nodes):\n ...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00013389", "row_id": 13389, "seed_ids": "[7112]" }
0.688803
Codeforces_13389
I
[ "build_tree", "count_leaf_nodes", "determine_winner" ]
3
[ [ "determine_winner", "build_tree" ], [ "determine_winner", "count_leaf_nodes" ] ]
2
[]
false
[ "TreeNode" ]
true
pytest
true
[]
true
535e1bc7f0980d1158ae0a5d52f1448b1aa79576
a18b4e33bdc7c70b4355ee880c69846a0c18c45f
v1.0
instruct
Codeforces
Codeforces_13400_I
You need to create a program that manages a particular type of employee hierarchy in a company. Each employee is represented as a node in a tree, with the root node being the CEO. Each node contains the employee's name and a list of direct subordinates. You are given a list of relationships where each element contains...
from collections import defaultdict class EmployeeNode: def __init__(self, name): self.name = name self.subordinates = [] def build_hierarchy(n, relationships): nodes = {} subordinates = set() # Create nodes for each employee and build a mapping for emp, sub in relationships: ...
import io import pytest from contextlib import redirect_stdout from solution import manage_hierarchy def test_manage_hierarchy_case1(): n = 6 relationships = [ ('Alice', 'Bob'), ('Alice', 'Charlie'), ('Bob', 'Dave'), ('Charlie', 'Eve'), ('Charlie', 'Frank'), ('Ch...
[]
[ 1, 1, 0, 0, 0, 0, 1, 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 print_hierarchy(n, relationships):\n from collections import defaultdict, deque\n \n def build_tree():\n tree = defaultdict(list)\n ...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00013400", "row_id": 13400, "seed_ids": "[801]" }
0.538197
Codeforces_13400
I
[ "build_hierarchy", "print_hierarchy", "manage_hierarchy" ]
3
[ [ "manage_hierarchy", "build_hierarchy" ], [ "manage_hierarchy", "print_hierarchy" ] ]
2
[]
false
[ "EmployeeNode" ]
true
pytest
true
[]
true
5aacafda9a820e8f5caf3a7cf8d003b3337c055c
1f834ff477e2dff84d20180511c7b8c924858f80
v1.0
instruct
Codeforces
Codeforces_13401_I
You have been given a set of social media posts gathered from three different platforms. Each post can be labeled as originating from one of the following platforms: Twitter, Facebook, or Instagram. The goal is to identify the platform of a given post based on the patterns present in the posts from each platform. You ...
import os from collections import Counter import re platform_keywords = { "Twitter": Counter(), "Facebook": Counter(), "Instagram": Counter() } def preprocess_text(content): # Basic preprocessing to remove special characters and lowercase conversion content = re.sub(r'[^a-zA-Z0-9\s]', '', content)...
import pytest from solution import classify_post, train_model # Mock training data and function def mock_train_model(): sample_data = { "Twitter": ["tweet this is a tweet", "twitter is fun", "retweet this", "mentions"], "Facebook": ["facebook friends", "likes and comments", "facebook post", "groups...
[ { "docstring": null, "function_declaration": "def preprocess_text(content):", "function_name": "preprocess_text", "parameter_list": "(content)" }, { "docstring": null, "function_declaration": "def train_model(base_path='dataset'):", "function_name": "train_model", "parameter_list...
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "import os\nfrom collections import Counter\n\ndef extract_features_from_post(post_content):\n words = post_content.split()\n num_hashtags = sum(1 for wo...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00013401", "row_id": 13401, "seed_ids": "[6126]" }
0.472714
Codeforces_13401
I
[ "preprocess_text", "train_model", "classify_post" ]
3
[ [ "classify_post", "preprocess_text" ], [ "train_model", "preprocess_text" ] ]
2
[]
false
[]
false
pytest
true
[]
true
f04d36ab31ec08de8c36dc9b5b4fa66add7dc633
c0129cff894de8fed10daede4c55ba774fadc804
v1.0
instruct
Codeforces
Codeforces_13468_I
You have a collection of unique magical potions, where each potion is represented as a string of lowercase letters. These potions have a unique property: if you concatenate two potions, the resulting potion's magical strength is equal to the length of the longest common prefix (LCP) of the two potion strings. Given an...
def longest_common_prefix(s1, s2): """ Returns the length of the longest common prefix between strings s1 and s2. """ min_len = min(len(s1), len(s2)) for i in range(min_len): if s1[i] != s2[i]: return i return min_len def max_magical_strength(potions): """ Returns th...
from solution import longest_common_prefix, max_magical_strength # Tests for longest_common_prefix function def test_longest_common_prefix(): assert longest_common_prefix("abc", "abcd") == 3 assert longest_common_prefix("abc", "abf") == 2 assert longest_common_prefix("abc", "bde") == 0 assert longest_c...
[ { "docstring": "Returns the length of the longest common prefix between strings s1 and s2.", "function_declaration": "def longest_common_prefix(s1, s2):", "function_name": "longest_common_prefix", "parameter_list": "(s1, s2)" }, { "docstring": "Returns the maximum possible magical strength o...
[ 0, 0, 1, 0, 0, 0, 0, 0, 0, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def longest_common_prefix(s1, s2):\n \"\"\"\n Returns the length of the longest common prefix of strings s1 and s2.\n \"\"\"\n lcp_length = 0\n ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00013468", "row_id": 13468, "seed_ids": "[6950]" }
0.634476
Codeforces_13468
I
[ "longest_common_prefix", "max_magical_strength" ]
2
[ [ "max_magical_strength", "longest_common_prefix" ] ]
1
[]
false
[]
false
pytest
true
[]
true
699cde328082315d3febc7ee1bbc7e186ebae1bd
8935d97d285212c50bd39f0b08cab7e1fce70522
v1.0
instruct
Codeforces
Codeforces_13537_I
You are given an array of n integers (2 ≤ n ≤ 10^5) and q queries (1 ≤ q ≤ 10^5). Each element in the array is a non-negative integer that represents the height of a building. Similarly, each query consists of two integers l and r (1 ≤ l ≤ r ≤ n), which define a range within the array. For each query, you need to fin...
def build_sparse_table(arr): import math n = len(arr) K = math.floor(math.log2(n)) + 1 st = [[0] * K for _ in range(n)] for i in range(n): st[i][0] = arr[i] j = 1 while (1 << j) <= n: i = 0 while (i + (1 << j) - 1) < n: st[i][j] = max(st[i][j - 1...
from solution import max_in_ranges def test_sample_input_1(): n = 5 heights = [3, 6, 2, 7, 4] queries = [(1, 3), (2, 4), (1, 5)] expected_output = [6, 7, 7] assert max_in_ranges(n, heights, queries) == expected_output def test_sample_input_2(): n = 8 heights = [4, 2, 3, 5, 1, 7, 2, 9] ...
[ { "docstring": null, "function_declaration": "def build_sparse_table(arr):", "function_name": "build_sparse_table", "parameter_list": "(arr)" }, { "docstring": null, "function_declaration": "def query_rmq(st, l, r):", "function_name": "query_rmq", "parameter_list": "(st, l, r)" ...
[ 1, 1, 1, 1, 1, 1, 1, 0 ]
7
easy
0.875
{ "trial_gpt4o_0": null, "trial_gpt4o_1": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared1_results_combined.jsonl", "solution_code": "class MaxHeightQuery:\n def __init__(self, heights):\n self.heights = heights\n self.n = len(heights)\n self....
trial_gpt4o_6
{ "original_instruction": "", "prompt_id": "00013537", "row_id": 13537, "seed_ids": "[7046]" }
0.769091
Codeforces_13537
I
[ "build_sparse_table", "query_rmq", "max_in_ranges" ]
3
[ [ "max_in_ranges", "build_sparse_table" ], [ "max_in_ranges", "query_rmq" ] ]
2
[]
false
[]
false
pytest
true
[]
true
a17296b06a7949ad46dd9ff7942ac4320736a993
483b1bd36bceccd392d3014718f2a76603680904
v1.0
instruct
Codeforces
Codeforces_13565_I
You are working on an automated painting robot that operates on a large square grid with dimensions n x n. Each cell in the grid is initially unpainted (color code 0). The robot can paint each cell with a color c (1 ≤ c ≤ 100). However, the robot's painting capabilities are limited by a set of rules regarding adjacent ...
def is_valid_painting(n, m, painted_cells): from collections import defaultdict grid = [[0] * n for _ in range(n)] for cell in painted_cells: r, c, col = cell grid[r - 1][c - 1] = col def is_valid(x, y, col): for dx, dy in [(-1, 0), (1, 0), (0, -1), (0, 1)]: nx, ny ...
from solution import validate_painting def test_validate_painting(): assert validate_painting(5, 2, [(1, 1, 1), (3, 3, 2)]) == "YES" assert validate_painting(5, 2, [(1, 1, 1), (1, 2, 1)]) == "NO" assert validate_painting(5, 3, [(1, 1, 1), (1, 2, 2), (1, 3, 1)]) == "YES" assert validate_painting(3, 1, [...
[ { "docstring": null, "function_declaration": "def is_valid_painting(n, m, painted_cells):", "function_name": "is_valid_painting", "parameter_list": "(n, m, painted_cells)" }, { "docstring": null, "function_declaration": "def validate_painting(n, m, cells):", "function_name": "validat...
[ 0, 1, 0, 1, 1, 0, 0, 0, 0 ]
3
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_possible_to_paint(n, m, painted_cells):\n from collections import defaultdict\n \n neighbor_offsets = [(-1, 0), (1, 0), (0, -1), (0, 1)]\n ...
trial_gpt4o_5
{ "original_instruction": "", "prompt_id": "00013565", "row_id": 13565, "seed_ids": "[1686]" }
0.760033
Codeforces_13565
I
[ "is_valid_painting", "validate_painting" ]
2
[ [ "validate_painting", "is_valid_painting" ] ]
1
[]
false
[]
false
pytest
true
[]
true
11e893024ae61164b410ce7ea5e39ce0fc64117f
5ac039f94303db05b9ede75eb5ec36ffd48c86a0
v1.0
instruct
Codeforces
Codeforces_13634_I
You are given a rectangular grid of size m x n consisting of blank cells (represented by '.') and some obstacle cells (represented by '#'). A ball can move up, down, left, or right, but it will stop moving once it encounters an obstacle or the edge of the grid. Given the starting position of the ball and the destinat...
def can_reach_destination(grid, start, destination): m, n = len(grid), len(grid[0]) visited = [[False] * n for _ in range(m)] def has_path(x, y, dx, dy): if not (0 <= x < m and 0 <= y < n) or grid[x][y] == '#' or visited[x][y]: return False if (x, y) == (dx, dy): ...
from solution import solve_grid_reach def test_example_1(): m, n = 5, 5 grid = [ ".....", ".#...", ".###.", ".....", ".#..." ] assert solve_grid_reach(m, n, grid, 1, 1, 4, 5) == "YES" def test_example_2(): m, n = 3, 3 grid = [ ".#.", ".#....
[ { "docstring": null, "function_declaration": "def can_reach_destination(grid, start, destination):", "function_name": "can_reach_destination", "parameter_list": "(grid, start, destination)" }, { "docstring": null, "function_declaration": "def solve_grid_reach(m, n, grid, sx, sy, dx, dy):...
[ 1, 0, 0, 0, 1, 0, 1, 0, 0, 0 ]
3
hard
0.3
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def can_reach_destination(m, n, grid, sx, sy, dx, dy):\n def dfs(x, y, visited):\n if x == dx and y == dy:\n return True\n visited...
trial_gpt4o_6
{ "original_instruction": "", "prompt_id": "00013634", "row_id": 13634, "seed_ids": "[6851]" }
0.760509
Codeforces_13634
I
[ "can_reach_destination", "solve_grid_reach" ]
2
[ [ "solve_grid_reach", "can_reach_destination" ] ]
1
[]
false
[]
false
pytest
true
[]
true
f113edee1a944532aa0bff205cbda9cd3615e726
7011ac383bb8b4dc0e62cd19f19478828263e6ae
v1.0
instruct
Codeforces
Codeforces_13686_I
Polycarp loves treasure hunting. He has discovered a grid of size $$$n \times m$$$ that contains treasures and traps. Each cell in the grid either contains a treasure, a trap, or is empty. A treasure has a positive integer value, while a trap has a negative integer value. Empty cells are represented by zero. Polycarp ...
def find_safe_path(n, m, grid): from collections import deque # Define directions: right and down directions = [(0, 1), (1, 0)] # BFS Queue with initial point (0,0), initial score 0, and the path queue = deque([(0, 0, 0, [(1, 1)])]) visited = set([(0, 0)]) while queue: ...
from solution import treasure_hunt def test_example(): n = 3 m = 3 grid = [ [1, -2, 1], [0, 2, -1], [1, 0, 5] ] result = treasure_hunt(n, m, grid) assert result == "YES\n(1, 1) -> (2, 1) -> (2, 2) -> (2, 3) -> (3, 3)" def test_no_path(): n = 2 m = 2 grid = [...
[ { "docstring": null, "function_declaration": "def find_safe_path(n, m, grid):", "function_name": "find_safe_path", "parameter_list": "(n, m, grid)" }, { "docstring": null, "function_declaration": "def treasure_hunt(n, m, grid):", "function_name": "treasure_hunt", "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": "def find_path(grid):\n n, m = len(grid), len(grid[0])\n directions = [(1, 0), (0, 1)] # down, right\n \n def dfs(x, y, score, path):\n if ...
trial_gpt4o_4
{ "original_instruction": "", "prompt_id": "00013686", "row_id": 13686, "seed_ids": "[7677]" }
0.665063
Codeforces_13686
I
[ "find_safe_path", "treasure_hunt" ]
2
[ [ "treasure_hunt", "find_safe_path" ] ]
1
[]
false
[]
false
pytest
true
[]
true
74f8a7fd17e56361305e21a318a67f50ce224954
a583147a6905532afaab390a2d61fa114a2b9e24
v1.0
instruct
Codeforces
Codeforces_13717_I
The land of CodeLand is structured as a grid with dimensions M x N. The citizens of CodeLand are very interested in finding prime numbers within various subgrids of this large grid. They have chosen you to write a program that can count the number of prime numbers in any subgrid quickly. The grid is filled with non-ne...
def is_prime(n): if n <= 1: return False if n <= 3: return True if n % 2 == 0 or n % 3 == 0: return False i = 5 while i * i <= n: if n % i == 0 or n % (i + 2) == 0: return False i += 6 return True def preprocess_prime_count(grid, M, N): pr...
import pytest from solution import is_prime, preprocess_prime_count, query_prime_count 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 assert is_prime(0) == False assert is_prime(5...
[ { "docstring": null, "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": null, "function_declaration": "def preprocess_prime_count(grid, M, N):", "function_name": "preprocess_prime_count", "parameter_list": "(grid, M,...
[ 0, 1, 1, 0, 0, 0, 0, 0, 0 ]
2
hard
0.222
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(num):\n if num <= 1:\n return False\n if num <= 3:\n return True\n if num % 2 == 0 or num % 3 == 0:\n return False\...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00013717", "row_id": 13717, "seed_ids": "[3691]" }
0.643324
Codeforces_13717
I
[ "is_prime", "preprocess_prime_count", "query_prime_count" ]
3
[ [ "preprocess_prime_count", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
d94fe90c142ecfaf23e4844844af5551fd60fb94
c9f7f1f4d1f1392287d6bc04cd9737d640966869
v1.0
instruct
Codeforces
Codeforces_13793_I
Alice is an avid hiker and enjoys exploring various trails in a massive national park. The park can be represented as a grid with 'n' rows and 'm' columns. Each cell in the grid either contains a part of a trail represented by the character '.', or is an impassable area represented by the character '#'. Alice wants to ...
def longest_straight_path(n, m, grid): def max_path_length(dx, dy): max_len = 0 for x in range(n): for y in range(m): if grid[x][y] == '.': length = 0 nx, ny = x, y while 0 <= nx < n and 0 <= ny < m and grid[nx][...
def test_longest_straight_path(): assert solve_longest_path(6, 6, [ '......', '..#...', '......', '.#.#..', '......', '......' ]) == 6 assert solve_longest_path(5, 5, [ '#.###', '#####', '.#.#.', '##..#', '.####' ])...
[ { "docstring": null, "function_declaration": "def longest_straight_path(n, m, grid):", "function_name": "longest_straight_path", "parameter_list": "(n, m, grid)" }, { "docstring": null, "function_declaration": "def solve_longest_path(n, m, grid_list):", "function_name": "solve_longes...
[ 0, 0, 1, 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 longest_hiking_path(grid):\n n = len(grid)\n m = len(grid[0]) if n > 0 else 0\n\n def check_longest(a, b, delta_a, delta_b):\n max_len = 0...
trial_gpt4o_6
{ "original_instruction": "", "prompt_id": "00013793", "row_id": 13793, "seed_ids": "[1409]" }
0.669331
Codeforces_13793
I
[ "longest_straight_path", "solve_longest_path" ]
2
[ [ "solve_longest_path", "longest_straight_path" ] ]
1
[]
false
[]
false
pytest
false
[]
true
8876a75cc3c6ab05e4c5f0f95fa8938ba4555dfd
02090bf53edb8d02ad04ed341c1aad97a881bf7a
v1.0
instruct
Codeforces
Codeforces_13816_I
Jessica loves to collect prime numbers and she has recently encountered a fascinating problem. She wants to find the highest prime number less than or equal to a given number n. Could you help her accomplish this task? The input consists of a single integer n ($$1 \leq n \leq 10^7$$). Your task is to find the largest ...
def is_prime(num): """ Helper function to check if a number is prime. Returns True if num is prime, else False. """ if num <= 1: return False if num == 2: return True if num % 2 == 0: return False for i in range(3, int(num ** 0.5) + 1, 2): if num % i == 0:...
from solution import is_prime, highest_prime 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(1) == False def test_highest_prime(): assert highest_prime(10) == 7 assert highest_prime(29) == 29...
[ { "docstring": "Helper function to check if a number is prime.\nReturns True if num is prime, else False.", "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": "Returns the highest prime number less than or equal to n.\nIf no...
[ 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 find_highest_prime(n):\n \"\"\"\n Returns the highest prime number less than or equal to n.\n If no prime number is found, returns \"No prime num...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00013816", "row_id": 13816, "seed_ids": "[3788]" }
0.610995
Codeforces_13816
I
[ "is_prime", "highest_prime" ]
2
[ [ "highest_prime", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
e03f22c83fb78a01b786425f20758376268c998f
2869314370b483ae0e9e4db174b742aa9c55a8b2
v1.0
instruct
Codeforces
Codeforces_13842_I
Alice loves playing with prime numbers and often wonders about the prime gaps. She defines the "prime gap" between two primes \(p_1\) and \(p_2\) as \(p_2 - p_1\) where \(p_2 > p_1\). She is particularly keen on finding the longest prime gap within a given range of numbers. Given two integers \(a\) and \(b\) (\(2 \leq...
def sieve_of_eratosthenes(limit): is_prime = [True] * (limit + 1) is_prime[0] = is_prime[1] = False p = 2 while p * p <= limit: if is_prime[p]: for i in range(p * p, limit + 1, p): is_prime[i] = False p += 1 return is_prime def find_largest_prime_gap(a, b...
def test_find_largest_prime_gap_no_prime(): assert find_largest_prime_gap(14, 16) == -1, "Should return -1 when no primes in range" def test_find_largest_prime_gap_small_range(): assert find_largest_prime_gap(2, 3) == 1, "Should return 1 for prime gap between 2 and 3" def test_find_largest_prime_gap_multiple_...
[ { "docstring": null, "function_declaration": "def sieve_of_eratosthenes(limit):", "function_name": "sieve_of_eratosthenes", "parameter_list": "(limit)" }, { "docstring": null, "function_declaration": "def find_largest_prime_gap(a, b):", "function_name": "find_largest_prime_gap", ...
[ 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 largest_prime_gap(a, b):\n def sieve(n):\n is_prime = [True] * (n + 1)\n is_prime[0] = is_prime[1] = False\n for i in range(2, int...
trial_gpt4o_4
{ "original_instruction": "", "prompt_id": "00013842", "row_id": 13842, "seed_ids": "[3956]" }
0.676258
Codeforces_13842
I
[ "sieve_of_eratosthenes", "find_largest_prime_gap" ]
2
[ [ "find_largest_prime_gap", "sieve_of_eratosthenes" ] ]
1
[]
false
[]
false
pytest
false
[]
true
d756049be635a4588324a25f6b803f5606ed5109
235e9b497583da0b62aa9d75d014845be5c35460
v1.0
instruct
Codeforces
Codeforces_13843_I
Heidi finds herself in yet another peculiar situation - this time in the depths of a medieval dungeon. To escape, she needs to solve a puzzle involving ancient numerology and get past the enchanted door. The door is operated by an array of integers, and Heidi needs to convert this array into a specially ordered seque...
def longest_palindromic_subsequence_length(arr): n = len(arr) dp = [[0] * n for _ in range(n)] for i in range(n): dp[i][i] = 1 for cl in range(2, n + 1): for i in range(n - cl + 1): j = i + cl - 1 if arr[i] == arr[j] and cl == 2: dp[i][j]...
import pytest from solution import solve_puzzle, parse_input, generate_output def test_longest_palindromic_subsequence_basic_cases(): input_string = "3\n5\n1 2 3 2 1\n4\n1 2 3 4\n6\n1 2 1 2 2 1\n" expected_output = "5\n1\n5" test_cases = parse_input(input_string) results = solve_puzzle(test_cases) ...
[ { "docstring": null, "function_declaration": "def longest_palindromic_subsequence_length(arr):", "function_name": "longest_palindromic_subsequence_length", "parameter_list": "(arr)" }, { "docstring": null, "function_declaration": "def solve_puzzle(test_cases):", "function_name": "sol...
[ 1, 1, 0, 0, 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": "def longest_palindromic_subsequence(arr):\n n = len(arr)\n dp = [[0]*n for _ in range(n)]\n \n for i in range(n):\n dp[i][i] = 1\n \n ...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00013843", "row_id": 13843, "seed_ids": "[7151]" }
0.719437
Codeforces_13843
I
[ "longest_palindromic_subsequence_length", "solve_puzzle", "parse_input", "generate_output" ]
4
[ [ "solve_puzzle", "longest_palindromic_subsequence_length" ] ]
1
[ "parse_input", "generate_output" ]
false
[]
false
pytest
true
[]
true
35c2476e472792073101a5dff7b2dbef8c2c566e
8519a86e14f9204cc0feb3946deb70f43f9054f0
v1.0
instruct
Codeforces
Codeforces_13900_I
An online store wants to analyze its customers' buying patterns to provide better recommendations. Given a list of transactions, where each transaction is represented by a list of items bought together, help the store identify the most frequently purchased pair of items. The first line of the input contains an integer...
from collections import defaultdict from itertools import combinations def most_frequent_pair(transactions): pair_count = defaultdict(int) for transaction in transactions: pairs = combinations(sorted(transaction), 2) for pair in pairs: pair_count[pair] += 1 most_frequent =...
from solution import solution def test_example_case(): input_str = "5\n1 2 3\n2 3 4\n1 2\n1 3\n2 3" expected_output = "2 3" assert solution(input_str) == expected_output def test_lexicographic_order(): input_str = "3\n1 2\n2 3\n3 1" expected_output = "1 2" assert solution(input_str) == expecte...
[ { "docstring": null, "function_declaration": "def most_frequent_pair(transactions):", "function_name": "most_frequent_pair", "parameter_list": "(transactions)" }, { "docstring": null, "function_declaration": "def input_parser(input_str):", "function_name": "input_parser", "parame...
[ 1, 1, 0, 1, 1, 0, 1, 0, 1, 0 ]
6
medium
0.6
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "from collections import defaultdict\nfrom itertools import combinations\n\ndef most_frequent_pair(transactions):\n \"\"\"\n Given a list of transactions...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00013900", "row_id": 13900, "seed_ids": "[7879]" }
0.560848
Codeforces_13900
I
[ "most_frequent_pair", "input_parser", "solution" ]
3
[ [ "solution", "input_parser" ], [ "solution", "most_frequent_pair" ] ]
2
[]
false
[]
false
pytest
true
[]
true
7f9eddc723d871a8ce57c46c9e8bd54dcaf2812d
22fca3c81215ed7d6d00d19ea5084aa7a9e33cb2
v1.0
instruct
Codeforces
Codeforces_13938_I
A group of scientists discovers a unique pattern in a certain sequence of integers. Given the first few numbers of the sequence, they realize that each number in the sequence can be obtained by computing the sum of the unique prime factors of the previous number. They want to study this sequence for as many steps as po...
def unique_prime_factors_sum(n): """ Generates a sequence of n numbers where each number is obtained by computing the sum of unique prime factors of the previous number, starting from 2. """ def sum_of_unique_prime_factors(num): factors = set() d = 2 while num > 1: ...
from solution import generate_sequence def test_generate_sequence_1(): assert generate_sequence(1) == [2] def test_generate_sequence_5(): assert generate_sequence(5) == [2, 2, 2, 2, 2] def test_generate_sequence_10(): assert generate_sequence(10) == [2, 2, 2, 2, 2, 2, 2, 2, 2, 2] def test_generate_seque...
[ { "docstring": "Generates a sequence of n numbers where each number is obtained by computing the sum \nof unique prime factors of the previous number, starting from 2.", "function_declaration": "def unique_prime_factors_sum(n):", "function_name": "unique_prime_factors_sum", "parameter_list": "(n)" ...
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
10
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def prime_factors(n):\n \"\"\"\n Returns a set of unique prime factors of n.\n \"\"\"\n i = 2\n factors = set()\n while i * i <= n:\n ...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00013938", "row_id": 13938, "seed_ids": "[7460]" }
0.683537
Codeforces_13938
I
[ "unique_prime_factors_sum", "generate_sequence" ]
2
[ [ "generate_sequence", "unique_prime_factors_sum" ] ]
1
[]
false
[]
false
pytest
true
[]
true
c231527fcd8e8de84e55c86fa455f1c97dcff68b
1b80167bac9118224c9de9cf29ac33a974b10cc7
v1.0
instruct
Codeforces
Codeforces_13974_I
You are given a list of positive integers and you need to find the maximum sum of a contiguous subarray. This is a well-known problem called "Maximum Subarray Problem". Write a function that takes an array of positive integers as input and returns the maximum sum of any contiguous subarray within the input array. ###...
def max_subarray_sum(arr): """ Returns the maximum sum of any contiguous subarray within the input array. Uses Kadane's Algorithm. """ max_current = max_global = arr[0] for i in range(1, len(arr)): max_current = max(arr[i], max_current + arr[i]) if max_current > max_global: ...
from solution import get_maximum_subarray_sum def test_example_1(): assert get_maximum_subarray_sum(5, [1, 2, 3, 4, 5]) == 15 def test_example_2(): assert get_maximum_subarray_sum(9, [5, 4, 3, 2, 1, 5, 4, 3, 2]) == 29 def test_single_element(): assert get_maximum_subarray_sum(1, [7]) == 7 def test_two_e...
[ { "docstring": "Returns the maximum sum of any contiguous subarray within the input array.\nUses Kadane's Algorithm.", "function_declaration": "def max_subarray_sum(arr):", "function_name": "max_subarray_sum", "parameter_list": "(arr)" }, { "docstring": null, "function_declaration": "def...
[ 1, 0, 1, 0, 1, 1, 0, 1, 0, 0 ]
5
medium
0.5
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def max_subarray_sum(arr):\n \"\"\"\n Returns the maximum sum of any contiguous subarray within the input array.\n \n Parameters:\n arr (list):...
trial_gpt4o_7
{ "original_instruction": "", "prompt_id": "00013974", "row_id": 13974, "seed_ids": "[7280]" }
0.799828
Codeforces_13974
I
[ "max_subarray_sum", "get_maximum_subarray_sum" ]
2
[ [ "get_maximum_subarray_sum", "max_subarray_sum" ] ]
1
[]
false
[]
false
pytest
true
[]
true
e97b4b68a1f1291b8914c2d074031c105692c444
943dcc2f08e838ccabe8b6fad8eff97eb0e528a4
v1.0
instruct
Codeforces
Codeforces_13980_I
You are given an integer array `arr` of size `n` and a separate integer `m`. Your task is to find if it is possible to partition the array into exactly `m` non-empty contiguous subarrays such that the sum of elements in each subarray is a prime number. If such a partition is possible, print "YES", otherwise print "NO"....
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 can_partition(arr, n, m): ...
from solution import solve, from_input_string def test_example_1(): input_data = '''2 5 3 2 3 5 7 11 6 2 1 4 5 -3 6 8''' test_cases = from_input_string(input_data) assert solve(test_cases) == ["YES", "NO"] def test_case_all_positive_primes(): input_data = '''1 5 2 2 7 3 11 17''' test_cases = from_...
[ { "docstring": null, "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": null, "function_declaration": "def can_partition(arr, n, m):", "function_name": "can_partition", "parameter_list": "(arr, n, m)" }, { ...
[ 0, 0, 0, 0, 0, 1, 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 itertools import accumulate\n\ndef is_prime(num):\n if num < 2:\n return False\n for i in range(2, int(num**0.5) + 1):\n if num % i =...
trial_gpt4o_5
{ "original_instruction": "", "prompt_id": "00013980", "row_id": 13980, "seed_ids": "[1747]" }
0.679629
Codeforces_13980
I
[ "is_prime", "can_partition", "solve", "from_input_string" ]
4
[ [ "can_partition", "is_prime" ], [ "solve", "can_partition" ] ]
2
[]
false
[]
false
pytest
true
[]
true
a155238199ebd81343dbdb4f77245eaf46fdd2f1
6cd9b19b21b268ef8f9c7f0a575df3f0f313c2d8
v1.0
instruct
Codeforces
Codeforces_14015_I
Given a binary tree, you need to find out whether it is a valid Binary Search Tree (BST). A valid BST is defined as follows: - The left subtree of a node contains only nodes with keys less than the node's key. - The right subtree of a node contains only nodes with keys greater than the node's key. - Both the left and r...
class TreeNode: def __init__(self, val=0, left=None, right=None): self.val = val self.left = left self.right = right def construct_tree(arr): if not arr: return None nodes = [] for val in arr: if val is not None: nodes.append(TreeNode(val)) e...
from solution import validate_bst def test_example_1(): n = 7 arr = [2, 1, 3, None, None, None, None] assert validate_bst(n, arr) == True def test_example_2(): n = 7 arr = [5, 1, 4, None, None, 3, 6] assert validate_bst(n, arr) == False def test_empty_tree(): n = 0 arr = [] assert...
[]
[ 0, 0, 1, 0, 1, 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": "from typing import List, Optional\n\n# Definition for a binary tree node.\nclass TreeNode:\n def __init__(self, x):\n self.val = x\n self.lef...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00014015", "row_id": 14015, "seed_ids": "[5045]" }
0.680434
Codeforces_14015
I
[ "construct_tree", "is_valid_bst", "validate_bst" ]
3
[ [ "validate_bst", "construct_tree" ], [ "validate_bst", "is_valid_bst" ] ]
2
[]
false
[ "TreeNode" ]
true
pytest
true
[]
true
827c4e377d9841419b5e39e9d84f367848b0f5ad
d2b7233933cc93c038c9125fc15036aed0aee945
v1.0
instruct
Codeforces
Codeforces_14044_I
Ninja Turtle Leonardo is training in a grid town. The town is represented by an m x n grid, where some cells contain obstacles. Leonardo can only move right or down to reach the bottom-right cell of the grid. Determine the number of unique paths Leonardo can take to move from the top-left cell to the bottom-right cell,...
def unique_paths_with_obstacles(grid): """ Given a grid indicating obstacles (1) and free spaces (0), this function calculates the number of unique paths from the top-left corner to the bottom-right corner, moving only right or down. """ if not grid or grid[0][0] == 1: return 0 m, n = ...
from solution import unique_paths_with_obstacles, solve def test_unique_paths_with_obstacles(): assert unique_paths_with_obstacles([[0, 0, 0], [0, 1, 0], [0, 0, 0]]) == 2 assert unique_paths_with_obstacles([[0, 1], [0, 0]]) == 1 assert unique_paths_with_obstacles([[1, 0], [0, 0]]) == 0 assert unique_pa...
[ { "docstring": "Given a grid indicating obstacles (1) and free spaces (0), this function calculates the number of \nunique paths from the top-left corner to the bottom-right corner, moving only right or down.", "function_declaration": "def unique_paths_with_obstacles(grid):", "function_name": "unique_pa...
[ 0, 0, 1, 1, 1, 0, 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 unique_paths_with_obstacles(grid):\n \"\"\"\n Returns the number of unique paths from the top-left to bottom-right of a grid with obstacles.\n \"...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00014044", "row_id": 14044, "seed_ids": "[175]" }
0.721791
Codeforces_14044
I
[ "unique_paths_with_obstacles", "solve" ]
2
[ [ "solve", "unique_paths_with_obstacles" ] ]
1
[]
false
[]
false
pytest
true
[]
true
98679d9321da54447960edd75dffd82cce0a14b0
db28bd52d2616b7bc8c88f6299bfa8615a31edf9
v1.0
instruct
Codeforces
Codeforces_14069_I
You are given a grid-based city represented as a 2D plane with streets along the integer coordinates, similar to a chessboard. Each intersection of streets is a crossing point on the grid. The city also has special roads denoted as "express routes" that connect specific pairs of grid points directly. These express rou...
import heapq from math import sqrt def euclidean_distance(x1, y1, x2, y2): return sqrt((x2 - x1) ** 2 + (y2 - y1) ** 2) def grid_distance(x1, y1, x2, y2): return abs(x2 - x1) + abs(y2 - y1) def minimal_travel_distance(n, express_routes, ax, ay, bx, by): graph = { (ax, ay): [] if (ax, ay) == (bx, ...
from solution import minimal_travel_distance def test_no_express_routes(): n = 0 express_routes = [] ax, ay, bx, by = 1, 1, 3, 3 assert minimal_travel_distance(n, express_routes, ax, ay, bx, by) == 4 def test_simple_express_route(): n = 1 express_routes = [(1, 1, 3, 3)] ax, ay, bx, by = 1,...
[ { "docstring": null, "function_declaration": "def euclidean_distance(x1, y1, x2, y2):", "function_name": "euclidean_distance", "parameter_list": "(x1, y1, x2, y2)" }, { "docstring": null, "function_declaration": "def grid_distance(x1, y1, x2, y2):", "function_name": "grid_distance", ...
[ 0, 0, 0, 1, 0, 0, 0, 0, 0, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "import heapq\nimport math\n\ndef euclidean_distance(x1, y1, x2, y2):\n return math.sqrt((x2 - x1) ** 2 + (y2 - y1) ** 2)\n\ndef minimal_travel_distance(n, ...
trial_gpt4o_3
{ "original_instruction": "", "prompt_id": "00014069", "row_id": 14069, "seed_ids": "[7728]" }
0.759017
Codeforces_14069
I
[ "euclidean_distance", "grid_distance", "minimal_travel_distance" ]
3
[ [ "minimal_travel_distance", "euclidean_distance" ], [ "minimal_travel_distance", "grid_distance" ] ]
2
[]
false
[]
false
pytest
true
[]
true
527b253896a88152d2df0325616e25a8ece48213
b7922989bcbb84ca4f275c6587c2e584cf73ae31
v1.0
instruct
Codeforces
Codeforces_14073_I
Emily loves playing with sequences. She defines a sequence of positive integers as beautiful if the sequence forms an arithmetic progression. An arithmetic progression is a sequence of numbers such that the difference of any two successive members is a constant. Emily found a sequence of positive integers and wants t...
def longest_arithmetic_progression_length(arr): """ Returns the length of the longest arithmetic progression in the given array. """ if not arr: return 0 n = len(arr) if n == 1: return 1 arr.sort() dp = [{} for _ in range(n)] max_len = 1 for i ...
from solution import solve def test_example_1(): assert solve(6, [1, 3, 2, 5, 7, 10]) == 4 def test_example_2(): assert solve(5, [4, 7, 10, 13, 16]) == 5 def test_single_element(): assert solve(1, [1]) == 1 def test_two_elements(): assert solve(2, [1, 100]) == 2 def test_no_arithmetic_progression()...
[ { "docstring": "Returns the length of the longest arithmetic progression in the given array.", "function_declaration": "def longest_arithmetic_progression_length(arr):", "function_name": "longest_arithmetic_progression_length", "parameter_list": "(arr)" }, { "docstring": null, "function_...
[ 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 max_beautiful_sequence_length(sequence):\n \"\"\"\n Returns the maximum length of an arithmetic progression (beautiful sequence)\n that can be ob...
trial_gpt4o_4
{ "original_instruction": "", "prompt_id": "00014073", "row_id": 14073, "seed_ids": "[4395]" }
0.621092
Codeforces_14073
I
[ "longest_arithmetic_progression_length", "solve" ]
2
[ [ "solve", "longest_arithmetic_progression_length" ] ]
1
[]
false
[]
false
pytest
true
[]
true
e235f743baf7caa023c90d2a733fb80b59807120
c439e708caac0d81fdc1ea1721fb4f5e6a7e9e61
v1.0
instruct
Codeforces
Codeforces_14090_I
A large warehouse needs to keep track of its inventory. Each item in the inventory is represented by a unique identifier and a count of the available units. The warehouse manager wants a program that can manage the inventory efficiently. The program should support the following operations: 1. **Add an item (ID, coun...
def add_item(inventory, ID, count): if ID in inventory: inventory[ID] += count else: inventory[ID] = count def remove_item(inventory, ID, count): if ID in inventory: inventory[ID] -= count if inventory[ID] <= 0: del inventory[ID] def check_item(inventory, ID): ...
from solution import add_item, remove_item, check_item, list_items, manage_inventory def test_add_item(): inventory = {} add_item(inventory, "A123", 10) assert inventory == {"A123": 10} add_item(inventory, "A123", 5) assert inventory == {"A123": 15} def test_remove_item(): inventory = {"A123"...
[ { "docstring": null, "function_declaration": "def add_item(inventory, ID, count):", "function_name": "add_item", "parameter_list": "(inventory, ID, count)" }, { "docstring": null, "function_declaration": "def remove_item(inventory, ID, count):", "function_name": "remove_item", "p...
[ 1, 0, 0, 1, 0, 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": "class WarehouseInventory:\n def __init__(self):\n self.inventory = {}\n\n def add_item(self, ID, count):\n if ID in self.inventory:\n ...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00014090", "row_id": 14090, "seed_ids": "[3764]" }
0.623355
Codeforces_14090
I
[ "add_item", "remove_item", "check_item", "list_items", "manage_inventory" ]
5
[ [ "manage_inventory", "add_item" ], [ "manage_inventory", "check_item" ], [ "manage_inventory", "list_items" ], [ "manage_inventory", "remove_item" ] ]
4
[]
false
[]
false
pytest
true
[]
true
fe4d038d0597193792267598e57912b173e05312
77aa1488cd2cb293573ae60773f143aca3162490
v1.0
instruct
Codeforces
Codeforces_14114_I
You have been tasked with organizing a series of fine art paintings at a gallery. There are n paintings, each with a unique tag number. The gallery wants to ensure that a certain display constraint is met. Specifically, no two paintings with consecutive tag numbers can be placed next to each other in the display. Befo...
def can_arrange_paintings(n, m, restrictions): import itertools # Generate all possible arrangements arrangements = itertools.permutations(range(1, n + 1)) # Convert restrictions list to a set of tuples for quick lookup restriction_set = {tuple(sorted(pair)) for pair in restrictions} for arra...
from solution import can_arrange_paintings, solve def test_can_arrange_paintings_sample1(): n = 4 m = 2 restrictions = [(1, 2), (3, 4)] assert solve(n, m, restrictions) == "YES\n1 3 2 4" or solve(n, m, restrictions) == "YES\n3 1 4 2" def test_can_arrange_paintings_sample2(): n = 3 m = 3 re...
[ { "docstring": null, "function_declaration": "def can_arrange_paintings(n, m, restrictions):", "function_name": "can_arrange_paintings", "parameter_list": "(n, m, restrictions)" }, { "docstring": null, "function_declaration": "def solve(n, m, restrictions):", "function_name": "solve"...
[ 1, 1, 1, 0, 1, 0, 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 can_arrange_paintings(n, m, pairs):\n import itertools\n\n if n == 1:\n # If there's only one painting, it's trivially possible to display it...
trial_gpt4o_7
{ "original_instruction": "", "prompt_id": "00014114", "row_id": 14114, "seed_ids": "[2750]" }
0.674799
Codeforces_14114
I
[ "can_arrange_paintings", "solve" ]
2
[ [ "solve", "can_arrange_paintings" ] ]
1
[]
false
[]
false
pytest
true
[]
true
27b9715d75322b0eaaf8906e8713012999dfe25c
6f3699543cecab9fea331b3c90a9aefcc17d71a5
v1.0
instruct
Codeforces
Codeforces_14124_I
You are given a 2D grid filled with different non-negative integers. You need to write a program to find the most frequent element in the grid. If there is a tie for the most frequent element, return the smallest one among them. **Input:** - The first line contains two integers, `m` and `n`, representing the number o...
def most_frequent_element(grid): """ Finds the most frequent element in a 2D grid. If there's a tie, returns the smallest element. Parameters: - grid (list of list of ints): 2D grid of non-negative integers Returns: - int: the most frequent (or smallest if tied) element """ from collec...
def test_most_frequent_element_in_grid(): # Example test case m, n = 3, 3 grid_elements = [1, 2, 3, 3, 2, 1, 1, 1, 2] assert find_most_frequent_element_in_grid(m, n, grid_elements) == 1 # Edge case: everything is the same number m, n = 2, 2 grid_elements = [5, 5, 5, 5] assert find_most_...
[ { "docstring": "Finds the most frequent element in a 2D grid. If there's a tie, returns the smallest element.\n\nParameters:\n- grid (list of list of ints): 2D grid of non-negative integers\n\nReturns:\n- int: the most frequent (or smallest if tied) element", "function_declaration": "def most_frequent_eleme...
[ 0, 1, 1, 1, 1, 1, 1, 0, 1 ]
7
easy
0.778
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def most_frequent_element(m, n, grid):\n from collections import Counter\n \n # Flatten the grid into a single list of elements\n elements = [elem...
trial_gpt4o_6
{ "original_instruction": "", "prompt_id": "00014124", "row_id": 14124, "seed_ids": "[6190]" }
0.651467
Codeforces_14124
I
[ "most_frequent_element", "find_most_frequent_element_in_grid" ]
2
[ [ "find_most_frequent_element_in_grid", "most_frequent_element" ] ]
1
[]
false
[]
false
pytest
false
[]
true
ea0e16fe64f7484c08006a58781eeaf19e317683
05dc81dc394e8374a74a176a6bd7e7a29f3a0fb7
v1.0
instruct
Codeforces
Codeforces_14154_I
You are given an undirected graph with `n` vertices and `m` edges. Each edge has a positive integer weight. Your task is to find the minimum weight required to make the graph connected. The first line contains two integers `n` and `m` (`1 \leq n, m \leq 100,000`), the number of vertices and edges, respectively. The n...
def find(parent, i): if parent[i] == i: return i else: return find(parent, parent[i]) def union(parent, rank, x, y): rootX = find(parent, x) rootY = find(parent, y) if rank[rootX] < rank[rootY]: parent[rootX] = rootY elif rank[rootX] > rank[rootY]: parent[rootY]...
def test_example_1(): n, m = 4, 5 edges = [ (1, 2, 1), (2, 3, 3), (3, 4, 4), (1, 4, 5), (2, 4, 2) ] assert solve(n, m, edges) == 6 def test_example_2(): n, m = 3, 1 edges = [ (1, 2, 2) ] assert solve(n, m, edges) == -1 def test_smallest_i...
[ { "docstring": null, "function_declaration": "def find(parent, i):", "function_name": "find", "parameter_list": "(parent, i)" }, { "docstring": null, "function_declaration": "def union(parent, rank, x, y):", "function_name": "union", "parameter_list": "(parent, rank, x, y)" }, ...
[ 0, 0, 1, 0, 0, 0, 1, 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": "class UnionFind:\n def __init__(self, n):\n self.parent = list(range(n))\n self.rank = [1] * n\n\n def find(self, u):\n if self.par...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00014154", "row_id": 14154, "seed_ids": "[8101]" }
0.85992
Codeforces_14154
I
[ "find", "union", "minimum_weight_to_connect_graph", "solve" ]
4
[ [ "minimum_weight_to_connect_graph", "find" ], [ "minimum_weight_to_connect_graph", "union" ], [ "solve", "minimum_weight_to_connect_graph" ], [ "union", "find" ] ]
4
[]
false
[]
false
pytest
false
[]
true
48a93a9b352801350bb955eb3fc2bf6e17cd8d21
441b38234aae5a1743df4c94b94be9c39cb58c03
v1.0
instruct
Codeforces
Codeforces_14189_I
You are given a binary tree consisting of $$$n$$$ nodes, numbered from $$$1$$$ to $$$n$$$. Each node has a value associated with it, denoted as $$$a_i$$$. Your goal is to find the sum of values of all nodes that are on the longest path from the root node to any leaf node. If there are multiple longest paths, choose the...
class TreeNode: def __init__(self, value): self.value = value self.left = None self.right = None def build_tree(n, node_vals, edges): nodes = [TreeNode(value) for value in node_vals] adj_list = {i: [] for i in range(n)} for u, v in edges: adj_list[u-1].append(v-1) ...
from solution import solution def test_example(): n = 7 node_vals = [3, -1, 4, 2, 5, -3, 2] edges = [(1, 2), (1, 3), (2, 4), (2, 5), (3, 6), (3, 7)] assert solution(n, node_vals, edges) == 9 def test_single_node(): n = 1 node_vals = [10] edges = [] assert solution(n, node_vals, edges) ...
[]
[ 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": "class TreeNode:\n def __init__(self, value):\n self.value = value\n self.left = None\n self.right = None\n\ndef build_tree(n, values, ...
trial_gpt4o_6
{ "original_instruction": "", "prompt_id": "00014189", "row_id": 14189, "seed_ids": "[7953]" }
0.698832
Codeforces_14189
I
[ "build_tree", "sum_of_longest_path", "solution" ]
3
[ [ "solution", "build_tree" ], [ "solution", "sum_of_longest_path" ] ]
2
[]
false
[ "TreeNode" ]
true
pytest
true
[]
true
8086022f61b25ea2b4f2adc2c02eb33b7058862f
e8040ee20c8c59f2dac867392dad4c5fdebb2a5a
v1.0
instruct
Codeforces
Codeforces_14226_I
Peter loves to create interesting patterns using stars (*). He created a unique star pattern based on a specific number $$n$$ arranged in an $$n \times n$$ grid, where each row is filled with stars and spaces in a symmetrical order. Your task is to generate this pattern for a given number $$n$$. Here are the rules to ...
def generate_star_pattern(n): """ Generate an n x n star pattern based on the given number n. Parameters: n (int): The grid size Returns: list of str: The star pattern in the form of a list of strings, where each string is a row """ pattern = [] mid_point = n // 2 # It...
from solution import generate_star_pattern def test_generate_star_pattern_n_5(): pattern = generate_star_pattern(5) expected_pattern = [ "* *", " * *", " *", "*****", "*****" ] assert pattern == expected_pattern def test_generate_star_pattern_n_7(): patte...
[ { "docstring": "Generate an n x n star pattern based on the given number n.\n\nParameters:\nn (int): The grid size\n\nReturns:\nlist of str: The star pattern in the form of a list of strings, where each string is a row", "function_declaration": "def generate_star_pattern(n):", "function_name": "generate...
[ 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": "def create_star_pattern(n):\n \"\"\"\n Generates a star pattern based on the given number n arranged in an n x n grid.\n\n Parameters:\n n (int): ...
trial_gpt4o_7
{ "original_instruction": "", "prompt_id": "00014226", "row_id": 14226, "seed_ids": "[2176]" }
0.551254
Codeforces_14226
I
[ "generate_star_pattern", "print_star_pattern" ]
2
[ [ "print_star_pattern", "generate_star_pattern" ] ]
1
[]
false
[]
false
pytest
true
[]
true
a1e891137da1ee9f99eb64070f37129785cb0a85
2874740c633069b3e9c0bdbf447ef1d54d93f118
v1.0
instruct
Codeforces
Codeforces_14266_I
You are given a binary tree with n nodes. Each node has a unique value from 1 to n. Your task is to process q queries, where each query asks whether two nodes u and v are on the same level of the tree. The first line of the input consists of two integers, n and q (1 ≤ n ≤ 1000, 1 ≤ q ≤ 10000) — the number of nodes in ...
from collections import deque def tree_levels(n, edges): levels = [-1] * (n + 1) adj_list = [[] for _ in range(n + 1)] for u, v in edges: adj_list[u].append(v) adj_list[v].append(u) queue = deque([1]) levels[1] = 0 while queue: node = queue.popleft() ...
def test_tree_levels(): edges = [(1, 2), (1, 3), (2, 4), (2, 5)] levels = tree_levels(5, edges) assert levels == [-1, 0, 1, 1, 2, 2] # Index 0 is unused, root node is level 0 def test_are_on_same_level(): levels = [-1, 0, 1, 1, 2, 2] assert are_on_same_level(levels, 4, 5) == True assert are_on_...
[ { "docstring": null, "function_declaration": "def tree_levels(n, edges):", "function_name": "tree_levels", "parameter_list": "(n, edges)" }, { "docstring": null, "function_declaration": "def are_on_same_level(levels, a, b):", "function_name": "are_on_same_level", "parameter_list"...
[ 0, 0, 1, 1, 0, 0, 0, 0, 0 ]
2
hard
0.222
{ "trial_gpt4o_0": null, "trial_gpt4o_1": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared1_results_combined.jsonl", "solution_code": "from collections import defaultdict, deque\n\ndef construct_tree(n, edges):\n tree = defaultdict(list)\n for u, v in edges:\n ...
trial_gpt4o_4
{ "original_instruction": "", "prompt_id": "00014266", "row_id": 14266, "seed_ids": "[284]" }
0.647818
Codeforces_14266
I
[ "tree_levels", "are_on_same_level", "process_queries" ]
3
[ [ "process_queries", "are_on_same_level" ], [ "process_queries", "tree_levels" ] ]
2
[ "process_queries" ]
false
[]
false
pytest
false
[]
true
4b7c037b5623bf2b435c2b9dcc419aefb0410197
cccf578e25c53e7a570c960c7cbbc6ed512536dd
v1.0
instruct
Codeforces
Codeforces_14349_I
Michael is building a binary tree from a given array of integers. The tree is constructed using the following algorithm: 1. If the array is empty, return null. 2. Find the maximum value in the array and use it as the root of the tree or subtree. 3. Recursively apply the same steps to the left part of the array (elemen...
from typing import List class TreeNode: def __init__(self, val=0, left=None, right=None): self.val = val self.left = left self.right = right def build_tree(nums: List[int]) -> TreeNode: if not nums: return None max_val = max(nums) max_index = nums.index(max_val) ...
from solution import inorder_traversal def test_inorder_traversal_example_case(): assert inorder_traversal([3, 2, 1, 6, 0, 5]) == [3, 2, 1, 6, 0, 5] def test_inorder_traversal_single_element(): assert inorder_traversal([42]) == [42] def test_inorder_traversal_sorted_increasing(): assert inorder_traversal...
[]
[ 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": "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\n\ndef ...
trial_gpt4o_7
{ "original_instruction": "", "prompt_id": "00014349", "row_id": 14349, "seed_ids": "[1735]" }
0.576068
Codeforces_14349
I
[ "build_tree", "inorder_traversal" ]
2
[ [ "inorder_traversal", "build_tree" ] ]
1
[]
false
[ "TreeNode" ]
true
pytest
true
[]
true
0a714290e9d14da633026361292d7b9da1a64412
b67851882892a6d223189e369e48c9a9d2ea5ab7
v1.0
instruct
Codeforces
Codeforces_14370_I
You are given a list of integers. Your task is to reorder the list such that the digits of each number are sorted in non-descending order and the number itself is prime. If there are multiple re-orderings possible that satisfy this condition, print the lexicographically smallest arrangement. If it is not possible to ma...
from itertools import permutations def is_prime(num): """ Checks if a number is prime. """ if num <= 1: return False if num <= 3: return True if num % 2 == 0 or num % 3 == 0: return False i = 5 while i * i <= num: if num % i == 0 or num % (i + 2) == 0: ...
from solution import is_prime, smallest_prime_reordering, process_test_cases 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(10) == False def test_smallest_prime_reordering(): assert smallest_prim...
[ { "docstring": "Checks if a number is prime.", "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": "Returns the lexicographically smallest permutation of the digits of n that is a prime number.\nIf no such permutation exists,...
[ 0, 0, 1, 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": "from itertools import permutations\n\ndef is_prime(num):\n if num <= 1:\n return False\n if num <= 3:\n return True\n if num % 2 == 0 o...
trial_gpt4o_4
{ "original_instruction": "", "prompt_id": "00014370", "row_id": 14370, "seed_ids": "[4566]" }
0.624384
Codeforces_14370
I
[ "is_prime", "smallest_prime_reordering", "process_test_cases" ]
3
[ [ "process_test_cases", "smallest_prime_reordering" ], [ "smallest_prime_reordering", "is_prime" ] ]
2
[ "process_test_cases" ]
false
[]
false
pytest
true
[]
true
189b838f20799629d77332c12c9aaa63572db42b
0cd836f9d52c5455868efa488f0b89baf1c0f272
v1.0
instruct
Codeforces
Codeforces_14397_I
You are given a string consisting of lowercase letters. Your task is to check if the string is a palindrome after removing at most one character. A palindrome is a word that reads the same backward as forward, such as "madam" or "racecar". You need to determine if the given string can be rearranged into a palindrome b...
def can_become_palindrome(s): """ Check if the string can become a palindrome by removing at most one character. """ def is_palindrome_range(i, j): return all(s[k] == s[j - k + i] for k in range(i, j)) l, r = 0, len(s) - 1 while l < r: if s[l] != s[r]: return is_...
from solution import solution def test_example_1(): assert solution("abca") == "YES" def test_example_2(): assert solution("abcba") == "YES" def test_example_3(): assert solution("abcdef") == "NO" def test_single_char(): assert solution("a") == "YES" def test_two_same_chars(): assert solution("...
[ { "docstring": "Check if the string can become a palindrome by removing at most one character.", "function_declaration": "def can_become_palindrome(s):", "function_name": "can_become_palindrome", "parameter_list": "(s)" }, { "docstring": "Determines if the string can become a palindrome by r...
[ 0, 1, 0, 0, 0, 1, 1, 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 can_become_palindrome(s):\n \"\"\"\n Determines if a string can become a palindrome by removing at most one character.\n \n Parameters:\n s...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00014397", "row_id": 14397, "seed_ids": "[7715]" }
0.829856
Codeforces_14397
I
[ "can_become_palindrome", "solution" ]
2
[ [ "solution", "can_become_palindrome" ] ]
1
[]
false
[]
false
pytest
true
[]
true
8720dc07c3bcee451cd02617f4291901dd0a3b60
b884a5a6a8674d7dab2e2dbb6c8e85a8829c098f
v1.0
instruct
Codeforces
Codeforces_14419_I
Polycarp is a programmer who loves prime numbers. Recently, he encountered a problem where he needs to find out the smallest prime number which is greater than or equal to a given integer. Help Polycarp solve this problem efficiently as he might need to perform this operation multiple times. The first line of the inp...
def is_prime(n): """Check if a number is prime.""" if n <= 1: return False if n <= 3: return True if n % 2 == 0 or n % 3 == 0: return False i = 5 while i * i <= n: if n % i == 0 or n % (i + 2) == 0: return False i += 6 return True def find...
import pytest from solution import smallest_prime_greater_equal def test_example_case(): test_cases = [10, 14, 20] expected = [11, 17, 23] assert smallest_prime_greater_equal(test_cases) == expected def test_single_prime_case(): test_cases = [29] expected = [29] assert smallest_prime_greater_e...
[ { "docstring": "Check if a number is prime.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Find the smallest prime number greater than or equal to x.", "function_declaration": "def find_smallest_prime_gte(x):", "f...
[ 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 is_prime(n):\n \"\"\"\n Check if the given number `n` is prime.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return Tr...
trial_gpt4o_7
{ "original_instruction": "", "prompt_id": "00014419", "row_id": 14419, "seed_ids": "[2204]" }
0.548719
Codeforces_14419
I
[ "is_prime", "find_smallest_prime_gte", "smallest_prime_greater_equal" ]
3
[ [ "find_smallest_prime_gte", "is_prime" ], [ "smallest_prime_greater_equal", "find_smallest_prime_gte" ] ]
2
[]
false
[]
false
pytest
true
[]
true
51965c3820fd651a409b8f19e1c9b4dac2f235f7
38965ae3c15d61eb9f7c0f54d38680902e06fd87
v1.0
instruct
Codeforces
Codeforces_14424_I
You are given a set of articles from different news categories. Each article has a category, identified by an integer from 1 to 4. Your task is to write a program that takes as input the text of an article and predicts its category. Categories: 1. Sports 2. Politics 3. Technology 4. Health Each input article is struc...
import os from sklearn.feature_extraction.text import TfidfVectorizer from sklearn.naive_bayes import MultinomialNB from sklearn.pipeline import make_pipeline import joblib # Function to load training data def load_training_data(directory): texts = [] labels = [] for category in range(1, 5): catego...
from solution import train_model, predict_category import os import pytest @pytest.fixture(scope='module') def setup_training_model(): # We assume the training data is in './category_training' directory training_data_directory = './category_training' if not os.path.exists(training_data_directory): ...
[ { "docstring": null, "function_declaration": "def load_training_data(directory):", "function_name": "load_training_data", "parameter_list": "(directory)" }, { "docstring": null, "function_declaration": "def train_model(training_data_directory):", "function_name": "train_model", "...
[ 0, 0, 0, 0, 0, 0, 0, 0, 1, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "import os\nimport string\nimport numpy as np\nfrom sklearn.feature_extraction.text import TfidfVectorizer\nfrom sklearn.naive_bayes import MultinomialNB\nfrom...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00014424", "row_id": 14424, "seed_ids": "[6121]" }
0.48466
Codeforces_14424
I
[ "load_training_data", "train_model", "load_model", "predict_category" ]
4
[ [ "predict_category", "load_model" ], [ "train_model", "load_training_data" ] ]
2
[]
false
[]
false
pytest
true
[ "joblib", "sklearn" ]
false
e69a1f3b88b26e5300381df44f45cb9fa7e17ced
c823ececf2c9151c621af68502f503bbcfb12140
v1.0
instruct
Codeforces
Codeforces_14428_I
You are given a directed, weighted graph with $n$ nodes and $m$ edges. Each edge has an integer weight associated with it. Your task is to determine the shortest distance from a given source node $s$ to every other node in the graph. Additionally, you need to answer $q$ queries where each query asks for the shortest di...
import heapq def dijkstra(n, edges, src): graph = [[] for _ in range(n + 1)] for u, v, w in edges: graph[u].append((v, w)) dist = [float('inf')] * (n + 1) dist[src] = 0 pq = [(0, src)] while pq: d, node = heapq.heappop(pq) if d > dist[node]: con...
from solution import shortest_paths def test_shortest_paths_basic(): n, m = 5, 6 edges = [ (1, 2, 2), (2, 3, 4), (3, 4, 1), (4, 5, 7), (1, 3, 6), (1, 4, 10) ] q = 3 queries = [ (1, 5), (2, 4), (3, 1) ] assert shortest_p...
[ { "docstring": null, "function_declaration": "def dijkstra(n, edges, src):", "function_name": "dijkstra", "parameter_list": "(n, edges, src)" }, { "docstring": null, "function_declaration": "def shortest_paths(n, m, edges, q, queries):", "function_name": "shortest_paths", "parame...
[ 1, 0, 1, 1, 1, 1, 1, 1, 1 ]
8
easy
0.889
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "import heapq\n\ndef dijkstra(n, adj, start):\n \"\"\"\n Implements Dijkstra's algorithm to return the shortest path from start to all other nodes.\n ...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00014428", "row_id": 14428, "seed_ids": "[5860]" }
0.794504
Codeforces_14428
I
[ "dijkstra", "shortest_paths" ]
2
[ [ "shortest_paths", "dijkstra" ] ]
1
[]
false
[]
false
pytest
true
[]
true
6adfba6f09c1b7088395fc053046586573aad2bc
34b217be4b9bea1c3a2456b34f1fbb6dbd2dff76
v1.0
instruct
Codeforces
Codeforces_14493_I
Coding an Autonomous Delivery Drone With the increasing demand for contactless delivery solutions, an innovative tech company is designing an autonomous delivery drone. The drone operates in a rectangular grid, where each cell is either an open space ('.') or an obstacle ('#'). The drone start at an initial position a...
from collections import deque def shortest_path(grid, sr, sc, dr, dc): n = len(grid) m = len(grid[0]) directions = [(-1, 0), (1, 0), (0, -1), (0, 1)] # up, down, left, right # Initialize the queue with the starting position and distance of 0 queue = deque([(sr, sc, 0)]) visited = set((sr...
from solution import shortest_path_from_input def test_shortest_path_basic(): grid = [ ".....", ".###.", ".....", ".###.", "....." ] assert shortest_path_from_input(5, 5, grid, 0, 0, 4, 4) == 8 def test_shortest_path_no_obstacles(): grid = [ ".....", ...
[ { "docstring": null, "function_declaration": "def shortest_path(grid, sr, sc, dr, dc):", "function_name": "shortest_path", "parameter_list": "(grid, sr, sc, dr, dc)" }, { "docstring": null, "function_declaration": "def shortest_path_from_input(n, m, grid, sr, sc, dr, dc):", "function...
[ 0, 0, 0, 0, 0, 0, 0, 1, 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 deque\n\ndef shortest_path(n, m, grid, sr, sc, dr, dc):\n \"\"\"\n Returns the minimum number of moves the drone needs to reach ...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00014493", "row_id": 14493, "seed_ids": "[1912]" }
0.713661
Codeforces_14493
I
[ "shortest_path", "shortest_path_from_input" ]
2
[ [ "shortest_path_from_input", "shortest_path" ] ]
1
[]
false
[]
false
pytest
true
[]
true
a5577040efe74b145a17b7a47932684074d3e25c
74d00f867949431c773dd538df4c718a592f6fc8
v1.0
instruct
Codeforces
Codeforces_14523_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 remove some of the edges so that the remaining edges form a tree that has the minimum possible weight difference between the heaviest and the lightest edge in the resulting tree. The first line of the...
def find(parent, i): if parent[i] == i: return i return find(parent, parent[i]) def union(parent, rank, x, y): root_x = find(parent, x) root_y = find(parent, y) if root_x != root_y: if rank[root_x] > rank[root_y]: parent[root_y] = root_x elif rank[root_x] < rank[...
def test_min_weight_difference_sample(): assert min_weight_difference(6, 7, [ (1, 2, 3), (2, 3, 3), (3, 4, 5), (4, 5, 6), (5, 6, 7), (1, 6, 8), (1, 3, 2) ]) == 4 def test_min_weight_difference_tree(): assert min_weight_difference(4, 3, [ (1, ...
[ { "docstring": null, "function_declaration": "def find(parent, i):", "function_name": "find", "parameter_list": "(parent, i)" }, { "docstring": null, "function_declaration": "def union(parent, rank, x, y):", "function_name": "union", "parameter_list": "(parent, rank, x, y)" }, ...
[ 0, 0, 0, 0, 1, 0, 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 minimum_weight_difference(n, m, edges):\n \"\"\"\n Finds the minimum possible weight difference between the heaviest and the lightest edge \n in ...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00014523", "row_id": 14523, "seed_ids": "[5753]" }
0.75868
Codeforces_14523
I
[ "find", "union", "kruskal", "min_weight_difference" ]
4
[ [ "kruskal", "find" ], [ "kruskal", "union" ], [ "min_weight_difference", "kruskal" ], [ "union", "find" ] ]
4
[]
false
[]
false
pytest
false
[]
true
91d243e759f1fe9c9970024470ba9f62f8184e7e
34dff408955077ee248b2efd0b68f1a44079c021
v1.0
instruct
Codeforces
Codeforces_14595_I
In a mysterious forest realm, there exists an infinite two-dimensional grid of cells, where each cell can either be alive or dead. The state of the grid evolves in "generations" according to the following rules, similar to Conway's Game of Life: 1. A live cell with fewer than 2 live neighbors dies, as if by underpopul...
def count_live_neighbors(grid, i, j, m, n): directions = [(-1, -1), (-1, 0), (-1, 1), (0, -1), (0, 1), (1, -1), (1, 0), (1, 1)] live_neighbors = 0 for di, dj in directions: ni, nj = i + di, j + dj if 0 <= ni < m and 0 <= nj < n and grid[ni][nj] == '*': live_neighbors += 1 ret...
from solution import count_live_cells_after_generations def test_example_case(): m = 4 n = 5 g = 3 initial_grid = [ ".....", ".**..", "..*..", "....." ] assert count_live_cells_after_generations(m, n, g, initial_grid) == 4 def test_stable_formation(): m = 3 ...
[ { "docstring": null, "function_declaration": "def count_live_neighbors(grid, i, j, m, n):", "function_name": "count_live_neighbors", "parameter_list": "(grid, i, j, m, n)" }, { "docstring": null, "function_declaration": "def next_generation(grid, m, n):", "function_name": "next_gener...
[ 0, 0, 0, 0, 0, 0, 0, 0, 1, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def count_alive_cells_after_generations(grid, generations):\n def get_live_neighbors(x, y):\n directions = [(-1, -1), (-1, 0), (-1, 1),\n ...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00014595", "row_id": 14595, "seed_ids": "[2179]" }
0.601075
Codeforces_14595
I
[ "count_live_neighbors", "next_generation", "count_live_cells_after_generations", "main" ]
4
[ [ "count_live_cells_after_generations", "next_generation" ], [ "next_generation", "count_live_neighbors" ] ]
2
[]
false
[]
false
pytest
true
[]
true
73ade3ea82dec7ff5617c161d129be70a30dc260
2a9879b70621188f60dc7a192fb70cf058e0f374
v1.0
instruct
Codeforces
Codeforces_14641_I
PCS the Developer is working on a directed graph problem with n vertices numbered from 1 to n and m edges. Each edge has a positive integer weight associated with it. The graph may contain cycles. PCS the Developer wants to find the length of the shortest path from vertex a to vertex b. However, due to a malicious att...
import heapq def dijkstra(graph, start, end, n): pq = [(0, start)] distances = {i: float('inf') for i in range(1, n + 1)} distances[start] = 0 while pq: current_distance, current_vertex = heapq.heappop(pq) if current_vertex == end: return current_distance if current_...
def test_sample_case(): input_data = """5 6 3 1 2 4 2 3 -1 1 3 2 3 4 3 4 5 6 5 2 7 1 3 1 5 5 3""" expected_output = [2, 11, -1] assert handle_graph_queries(input_data) == expected_output def test_no_path(): input_data = """4 4 2 1 2 4 2 3 5 3 4 6 4 1 1 1 4 4 1""" expected_output = [15, 1] asse...
[ { "docstring": null, "function_declaration": "def dijkstra(graph, start, end, n):", "function_name": "dijkstra", "parameter_list": "(graph, start, end, n)" }, { "docstring": null, "function_declaration": "def shortest_paths(n, m, edges, queries):", "function_name": "shortest_paths", ...
[ 0, 0, 1, 1, 0, 0, 0, 0 ]
2
hard
0.25
{ "trial_gpt4o_0": null, "trial_gpt4o_1": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared1_results_combined.jsonl", "solution_code": "import heapq\n\ndef shortest_path(n, m, q, edges, queries):\n def dijkstra(graph, start, n):\n distances = [float('inf')] *...
trial_gpt4o_5
{ "original_instruction": "", "prompt_id": "00014641", "row_id": 14641, "seed_ids": "[4784]" }
0.743912
Codeforces_14641
I
[ "dijkstra", "shortest_paths", "handle_graph_queries" ]
3
[ [ "handle_graph_queries", "shortest_paths" ], [ "shortest_paths", "dijkstra" ] ]
2
[]
false
[]
false
pytest
false
[]
true
5f2d0ea1eacba69d2deda63367edd23de999b03c
0d131b35b6f1f61521ce1d48ed9bf8f2a65964aa
v1.0
instruct
Codeforces
Codeforces_14678_I
You are given an array of integers containing both negative and positive values. Your task is to determine the maximum sum of any non-empty subarray. A subarray is a contiguous part of an array. The possible subarrays of array $$[a_1, a_2, ..., a_n]$$ are $[a_i]$, $[a_i, a_{i+1}]$, ..., $[a_i, a_{i+1}, ..., a_j]$ for...
def max_subarray_sum(arr): """ Returns the maximum sum of any non-empty subarray in the input array. """ max_sum = arr[0] current_sum = arr[0] for num in arr[1:]: current_sum = max(num, current_sum + num) max_sum = max(max_sum, current_sum) return max_sum def solve...
from solution import main def test_example_1(): input_string = "3\n9\n-2 1 -3 4 -1 2 1 -5 4\n5\n1 2 3 4 5\n5\n-1 -2 -3 -4 -5" expected_output = [6, 15, -1] assert main(input_string) == expected_output def test_single_element(): input_string = "2\n1\n5\n1\n-7" expected_output = [5, -7] assert m...
[ { "docstring": "Returns the maximum sum of any non-empty subarray in the input array.", "function_declaration": "def max_subarray_sum(arr):", "function_name": "max_subarray_sum", "parameter_list": "(arr)" }, { "docstring": null, "function_declaration": "def solve(test_cases):", "func...
[ 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 max_subarray_sum(t, test_cases):\n def max_subarray(arr):\n max_ending_here = arr[0]\n max_so_far = arr[0]\n for x in arr[1:]:\n ...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00014678", "row_id": 14678, "seed_ids": "[5351]" }
0.842901
Codeforces_14678
I
[ "max_subarray_sum", "solve", "parse_input", "main" ]
4
[ [ "solve", "max_subarray_sum" ] ]
1
[ "parse_input" ]
false
[]
false
pytest
true
[]
true
61b1367b4dadacd9f3ce913530ce7a05561d15cc
09b098ab5f42f1656e024d9eb2306fd93aeccc83
v1.0
instruct
Codeforces
Codeforces_14713_I
**Problem Statement:** The kingdom of Numeria has a peculiar road system consisting of straight roads connecting various cities. The road network is represented as a tree (a connected graph with no cycles), with cities as nodes and roads as edges. Each road has a certain distance. Due to rising maintenance costs, the...
import sys from collections import defaultdict def dfs(u, parent, graph, max_edge, max_inconvenience): for v, w in graph[u]: if v == parent: continue max_edge[v] = max(max_edge[u], w) max_inconvenience[0] = max(max_inconvenience[0], max_edge[v]) dfs(v, u, graph, max_edge...
from solution import find_max_inconvenience def test_example_case(): assert find_max_inconvenience(5, [(1, 2, 3), (1, 3, 2), (3, 4, 4), (3, 5, 1)]) == 4 def test_small_tree(): assert find_max_inconvenience(2, [(1, 2, 10)]) == 10 def test_star_shape_tree(): assert find_max_inconvenience(4, [(1, 2, 7), (1,...
[ { "docstring": null, "function_declaration": "def dfs(u, parent, graph, max_edge, max_inconvenience):", "function_name": "dfs", "parameter_list": "(u, parent, graph, max_edge, max_inconvenience)" }, { "docstring": null, "function_declaration": "def find_max_inconvenience(n, roads):", ...
[ 1, 0, 1, 0, 0, 1, 0, 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 sys\nfrom collections import defaultdict\n\ndef max_inconvenience(n, roads):\n graph = defaultdict(list)\n for u, v, w in roads:\n graph[u...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00014713", "row_id": 14713, "seed_ids": "[4133]" }
0.770725
Codeforces_14713
I
[ "dfs", "find_max_inconvenience" ]
2
[ [ "find_max_inconvenience", "dfs" ] ]
1
[]
false
[]
false
pytest
true
[]
true
7ab5eaa09ab7a4ea13c8fe24139f1ab801fefa7f
d25230136842b575bd67c7d13b4499e8a2c31cc4
v1.0
instruct
Codeforces
Codeforces_14751_I
Vasily is preparing a special surprise for his friend. He has a box with n different colored balls and k unique friends. He wants to distribute all the balls such that each friend gets a distinct subset of balls. Given the number of balls n and the number of friends k, help Vasily determine how many distinct ways he ca...
from math import factorial from functools import lru_cache @lru_cache(None) def stirling_second_kind(n, k): """ Returns the Stirling number of the second kind S(n, k) which is the number of ways to partition a set of n objects into k non-empty subsets. """ if n == k: return 1 if k =...
from solution import distinct_ways_to_distribute_balls def test_example_case(): assert distinct_ways_to_distribute_balls(3, 2) == 6 def test_minimum_input(): assert distinct_ways_to_distribute_balls(1, 1) == 1 def test_all_balls_to_one_friend(): assert distinct_ways_to_distribute_balls(4, 1) == 1 def te...
[ { "docstring": "Returns the Stirling number of the second kind\nS(n, k) which is the number of ways to partition\na set of n objects into k non-empty subsets.", "function_declaration": "def stirling_second_kind(n, k):", "function_name": "stirling_second_kind", "parameter_list": "(n, k)" }, { ...
[ 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 math import factorial\n\ndef stirling_second_kind(n, k):\n if k == 0 or k > n:\n return 0\n if k == 1 or k == n:\n return 1\n S = ...
trial_gpt4o_4
{ "original_instruction": "", "prompt_id": "00014751", "row_id": 14751, "seed_ids": "[4729]" }
0.524709
Codeforces_14751
I
[ "stirling_second_kind", "distinct_ways_to_distribute_balls" ]
2
[ [ "distinct_ways_to_distribute_balls", "stirling_second_kind" ] ]
1
[]
false
[]
false
pytest
true
[]
true
7ec69dbed7c689231eca178b9cd9fb425731afea
e19d6437435403173522725e4ee35137ef64822d
v1.0
instruct
Codeforces
Codeforces_14796_I
A group of scientists in the Galactic Federation have found an ancient artifact that can store sequences of numbers. It’s up to you to determine if a given sequence can be made a palindrome by rearranging its numbers. A palindrome is a sequence that reads the same backward as forward. You are given a sequence of posit...
def can_form_palindrome(sequences): results = [] for sequence in sequences: if is_palindromable(sequence): results.append("YES") else: results.append("NO") return results def is_palindromable(sequence): from collections import Counter counter = Counter(s...
def test_is_palindromable(): assert is_palindromable([1, 2, 3, 2, 1]) == True assert is_palindromable([1, 2, 2, 3]) == False assert is_palindromable([1, 2, 3, 3, 2, 1]) == True assert is_palindromable([1, 1, 1]) == True assert is_palindromable([1, 2, 3, 4, 5]) == False assert is_palindromable([4...
[ { "docstring": null, "function_declaration": "def can_form_palindrome(sequences):", "function_name": "can_form_palindrome", "parameter_list": "(sequences)" }, { "docstring": null, "function_declaration": "def is_palindromable(sequence):", "function_name": "is_palindromable", "par...
[ 1, 1, 1, 1, 1, 0, 0, 1, 0, 1 ]
7
easy
0.7
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def can_form_palindrome(t, test_cases):\n from collections import Counter\n \n results = []\n for i in range(t):\n n = test_cases[i][0]\n ...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00014796", "row_id": 14796, "seed_ids": "[3690]" }
0.770598
Codeforces_14796
I
[ "can_form_palindrome", "is_palindromable" ]
2
[ [ "can_form_palindrome", "is_palindromable" ] ]
1
[]
false
[]
false
pytest
false
[]
true
15b56f176a274d8aa1b19c1482dc090dd7248e25
ed31220cad21329e8d359d55bfb0b2f698671fc0
v1.0
instruct
Codeforces
Codeforces_14819_I
A mobile app development company is offering n different subscription plans. Each plan has certain features that are of interest: - Number of hours of technical support per month - Amount of storage provided in GB - Number of team member accounts included - Monthly cost of the plan The company decides to discard any ...
def find_best_plan(plans): # Filter out plans that are strictly worse than another plan filtered_plans = [] for i, plan1 in enumerate(plans): worse = False for plan2 in plans: if (plan1 != plan2 and plan1[0] < plan2[0] and plan1[1] < plan2[1] and ...
from solution import best_subscription_plan def test_single_plan(): plans = ["24 50 5 100"] assert best_subscription_plan(1, plans) == 1 def test_discard_worse_plan(): plans = [ "24 50 5 100", "30 100 10 200", "24 50 5 80" ] assert best_subscription_plan(3, plans) == 2 def...
[ { "docstring": null, "function_declaration": "def find_best_plan(plans):", "function_name": "find_best_plan", "parameter_list": "(plans)" }, { "docstring": null, "function_declaration": "def best_subscription_plan(n, plans_list):", "function_name": "best_subscription_plan", "para...
[ 0, 0, 0, 1, 0, 0, 0, 0, 0, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def find_best_plan(n, plans):\n remaining_plans = []\n\n # Filter out plans that are strictly worse than any other plan\n for i in range(n):\n ...
trial_gpt4o_3
{ "original_instruction": "", "prompt_id": "00014819", "row_id": 14819, "seed_ids": "[3185]" }
0.695974
Codeforces_14819
I
[ "find_best_plan", "best_subscription_plan" ]
2
[ [ "best_subscription_plan", "find_best_plan" ] ]
1
[]
false
[]
false
pytest
true
[]
true
08b0bdb6b4405ecc4f2693810326b3709b487cfe
50a1cd4dc04b7336edaed3faded086d333778119
v1.0
instruct
Codeforces
Codeforces_14832_I
Aria enjoys organizing events and planning seating arrangements. She is organizing a round table event where people will be seated around a circular table, all facing the center. Aria wants to carefully assign seats to ensure maximum harmony among the guests, considering their preferences. Each guest has a list of oth...
from itertools import permutations def count_preferences(seating, preferences): count = 0 n = len(seating) for i in range(n): left = seating[i] right = seating[(i + 1) % n] if right in preferences[left]: count += 1 if left in preferences[right]: count...
from solution import maximize_harmony def test_maximize_harmony_example(): assert maximize_harmony(4, [(2, 2, 3), (1, 1), (1, 4), (1, 1)]) == (3, [1, 2, 3, 4]) or (3, [4, 1, 2, 3]) def test_maximize_harmony_all_no_pref(): assert maximize_harmony(3, [(0,), (0,), (0,)]) == (0, [1, 2, 3]) or (0, [3, 1, 2]) or (0...
[ { "docstring": null, "function_declaration": "def count_preferences(seating, preferences):", "function_name": "count_preferences", "parameter_list": "(seating, preferences)" }, { "docstring": null, "function_declaration": "def maximize_harmony(n, preferences):", "function_name": "max...
[ 0, 0, 0, 0, 0, 0, 0, 1, 0 ]
1
hard
0.111
{ "trial_gpt4o_0": null, "trial_gpt4o_1": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared1_results_combined.jsonl", "solution_code": "from itertools import permutations\n\ndef count_satisfied_preferences(arrangement, preferences):\n n = len(arrangement)\n satis...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00014832", "row_id": 14832, "seed_ids": "[2948]" }
0.709351
Codeforces_14832
I
[ "count_preferences", "maximize_harmony" ]
2
[ [ "maximize_harmony", "count_preferences" ] ]
1
[]
false
[]
false
pytest
true
[]
true
4022771c9c4bc62cb41c1e302952d6fa7735f57e
f3f548c2120d1a6df7b9189de73a29589bd9f37e
v1.0
instruct
Codeforces
Codeforces_14849_I
You are given a directed graph with $$$n$$$ nodes and $$$m$$$ edges. Each edge has a weight associated with it. Your task is to calculate the shortest path from a given source node to all other nodes. If a node is unreachable from the source, its distance should be considered infinity. ### Input - The first line conta...
import heapq def dijkstra(n, edges, s): graph = {i: [] for i in range(1, n + 1)} for u, v, w in edges: graph[u].append((v, w)) distances = {i: float('inf') for i in range(1, n + 1)} distances[s] = 0 priority_queue = [(0, s)] while priority_queue: curr_distance, node = heapq.he...
from solution import shortest_path def test_shortest_path_case1(): n = 5 m = 6 edges = [ (1, 2, -2), (1, 3, 4), (2, 3, 3), (2, 4, 2), (4, 2, 1), (4, 5, -1) ] s = 1 assert shortest_path(n, m, edges, s) == ['0', '-2', '1', '0', '-1'] def test_short...
[ { "docstring": null, "function_declaration": "def dijkstra(n, edges, s):", "function_name": "dijkstra", "parameter_list": "(n, edges, s)" }, { "docstring": null, "function_declaration": "def shortest_path(n, m, edge_list, s):", "function_name": "shortest_path", "parameter_list": ...
[ 1, 0, 1, 1, 1, 1, 1, 1, 0, 1 ]
8
easy
0.8
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "import heapq\n\ndef dijkstra(n, edges, s):\n \"\"\"\n Implements Dijkstra's algorithm to find the shortest paths from node s to all other nodes in a dir...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00014849", "row_id": 14849, "seed_ids": "[1857]" }
0.788522
Codeforces_14849
I
[ "dijkstra", "shortest_path" ]
2
[ [ "shortest_path", "dijkstra" ] ]
1
[]
false
[]
false
pytest
true
[]
true
cadc54275aa2c57902d689db4d9d7a121c38334b
94b7ab0ef396724c752a0847fa8846a1bd516812