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_8287_I
You are given a grid-based city plot with n rows and m columns. Each cell in the grid can either contain a building denoted by 'B' or a vacant land denoted by 'L'. No two buildings are adjacent horizontally or vertically but only diagonally. We need to construct a new building in one of the vacant cells such that it ...
def find_building_spot(grid): n = len(grid) m = len(grid[0]) def is_safe(x, y): directions = [(-1, 0), (1, 0), (0, -1), (0, 1)] for dx, dy in directions: nx, ny = x + dx, y + dy if 0 <= nx < n and 0 <= ny < m and grid[nx][ny] == 'B': return False ...
from solution import solve def test_case1(): n = 3 m = 3 grid = [ "LLL", "LBL", "LLL" ] assert solve(n, m, grid) == "1 1" def test_case2(): n = 2 m = 2 grid = [ "BL", "LB" ] assert solve(n, m, grid) == "NO" def test_case3(): n = 5 ...
[ { "docstring": null, "function_declaration": "def find_building_spot(grid):", "function_name": "find_building_spot", "parameter_list": "(grid)" }, { "docstring": null, "function_declaration": "def solve(n, m, grid):", "function_name": "solve", "parameter_list": "(n, m, grid)" }...
[ 0, 1, 1, 1, 0, 1, 0, 1, 1, 0 ]
6
medium
0.6
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def find_vacant_position(n, m, grid):\n \"\"\"\n Finds a vacant position in the grid where we can place a building such that\n it is not adjacent hor...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00008287", "row_id": 8287, "seed_ids": "[3264]" }
0.67754
Codeforces_8287
I
[ "find_building_spot", "solve" ]
2
[ [ "solve", "find_building_spot" ] ]
1
[]
false
[]
false
pytest
true
[]
true
adf93105dd2b704d28a125e320e1f69eb7b48f56
4f395202db4c4647210b2a552791c818b4d36515
v1.0
instruct
Codeforces
Codeforces_8393_I
Anastasia is practicing her math skills and recently learned about binary trees. She finds them fascinating and wants to explore more. A binary tree is a tree where each node has at most two children, referred to as the left child and the right child. Anastasia is particularly interested in finding out the maximum dep...
class TreeNode: def __init__(self, val=0, left=None, right=None): self.val = val self.left = left self.right = right def build_tree(nodes): if not nodes: return None val_to_node = {} for val, left, right in nodes: if val not in val_to_node: val_t...
def test_find_max_depth(): assert find_max_depth(3, [(1, 2, 3), (2, None, None), (3, None, None)]) == 2 assert find_max_depth(1, [(1, None, None)]) == 1 assert find_max_depth(5, [(1, 2, 3), (2, 4, None), (3, None, 5), (4, None, None), (5, None, None)]) == 3 def test_find_max_depth_deep_tree(): assert f...
[]
[ 1, 1, 1, 1, 1, 1, 1, 0, 1, 1 ]
9
easy
0.9
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "class TreeNode:\n def __init__(self, val=0, left=None, right=None):\n self.val = val\n self.left = left\n self.right = right\n\ndef bu...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00008393", "row_id": 8393, "seed_ids": "[7810]" }
0.53828
Codeforces_8393
I
[ "build_tree", "max_depth", "find_max_depth" ]
3
[ [ "find_max_depth", "build_tree" ], [ "find_max_depth", "max_depth" ] ]
2
[]
false
[ "TreeNode" ]
true
pytest
false
[]
true
0654df9e81eb39538c327c6104dbb35fc4b555d7
cf030b2f73116c72a632ac42d03513dd1d6dc1a3
v1.0
instruct
Codeforces
Codeforces_8394_I
You are given a set of points in a 2D plane and are tasked with determining if there exists a circle that encircles at least three of these points. A circle is said to encircle a point if the point lies on the circumference of the circle. Write a function to find out whether there exists such a circle. If there are m...
from itertools import combinations def is_circumcenter_collinear(p1, p2, p3): x1, y1 = p1 x2, y2 = p2 x3, y3 = p3 return ((x2 - x1)*(y3 - y1) - (y2 - y1)*(x3 - x1)) == 0 def circle_exists(points): for comb in combinations(points, 3): if not is_circumcenter_collinear(*comb): ret...
def test_circle_exists(): assert check_circle(["6", "2 3", "4 5", "1 1", "3 4", "7 8", "8 10"]) == "YES" assert check_circle(["4", "1 1", "2 2", "3 3", "4 4"]) == "NO" assert check_circle(["3", "1 1", "0 0", "-1 -1"]) == "NO" assert check_circle(["5", "0 0", "1 0", "0 1", "1 1", "0 2"]) == "YES" ass...
[ { "docstring": null, "function_declaration": "def is_circumcenter_collinear(p1, p2, p3):", "function_name": "is_circumcenter_collinear", "parameter_list": "(p1, p2, p3)" }, { "docstring": null, "function_declaration": "def circle_exists(points):", "function_name": "circle_exists", ...
[ 0, 1, 1, 1, 1, 0, 1, 1, 1, 1 ]
8
easy
0.8
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "from typing import List, Tuple\n\ndef exists_circle_encircling_three_points(points: List[Tuple[int, int]]) -> str:\n from math import isclose\n \n de...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00008394", "row_id": 8394, "seed_ids": "[469]" }
0.653531
Codeforces_8394
I
[ "is_circumcenter_collinear", "circle_exists", "check_circle" ]
3
[ [ "check_circle", "circle_exists" ], [ "circle_exists", "is_circumcenter_collinear" ] ]
2
[]
false
[]
false
pytest
false
[]
true
c639862c06476c95c142fd6d8dd3edbea7cd5edb
07b876e354ae5d5c8efc84cfbd52b72af87f6ebe
v1.0
instruct
Codeforces
Codeforces_8410_I
Polycarp is organizing a card tournament. There are n players and each player has m randomly drawn cards from a deck containing cards with values c1, c2, ..., ck (0 ≤ ci ≤ 106). Each card value appears equally often in the deck. Polycarp wants to calculate the total sum of all card values for tournament purposes. Agri...
from collections import Counter from math import comb def calculate_combinations(n, m, k, card_values, remaining_values): """ Calculate possible combinations of remaining cards to maintain a sum V. Args: n (int): Number of players m (int): Number of cards each player has drawn k (in...
from solution import calculate_combinations def test_example_case(): assert calculate_combinations(2, 3, 3, [1, 2, 3], [1, 2, 2, 3, 3]) == 1 def test_all_cards_present(): assert calculate_combinations(1, 3, 1, [100], [100, 100, 100]) == 1 def test_some_missing_cards(): assert calculate_combinations(1, 3,...
[ { "docstring": "Calculate possible combinations of remaining cards to maintain a sum V.\nArgs:\n n (int): Number of players\n m (int): Number of cards each player has drawn\n k (int): Number of unique card values\n card_values (list): List of k card values\n remaining_values (list): List of remai...
[ 0, 0, 1, 0, 0, 0, 0, 0, 0, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "from collections import Counter\n\ndef calculate_possible_combinations(n, m, k, card_values, remaining_cards):\n \"\"\"\n Calculates the number of possi...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00008410", "row_id": 8410, "seed_ids": "[6746]" }
0.603665
Codeforces_8410
I
[ "calculate_combinations", "calculate_combinations_recursively" ]
2
[ [ "calculate_combinations", "calculate_combinations_recursively" ] ]
1
[]
false
[]
false
pytest
true
[]
true
094ad67d1261722f36c0f9fd77531015f1a221c4
8a5aca2050ee78be74baba0608e0e31d6caa8fe6
v1.0
instruct
Codeforces
Codeforces_8416_I
There is a large network of computers in a laboratory. Each computer is connected to other computers directly by a number of bidirectional cables. Unfortunately, some cables are prone to failure, and if enough cables fail, it might isolate some computers from the rest of the network. You have been tasked with minimizi...
from collections import defaultdict, deque def bfs(capacity, flow, source, sink, parent): visited = set() queue = deque([source]) while queue: u = queue.popleft() for v in capacity[u]: if v not in visited and capacity[u][v] - flow[u][v] > 0: parent[v] = u ...
def test_minimum_reliability_for_fault_tolerance(): assert minimum_reliability_for_fault_tolerance(6, 7, 1, 6, [ (1, 2, 4), (2, 3, 3), (3, 4, 2), (4, 5, 5), (5, 6, 4), (1, 3, 7), (2, 6, 6) ]) == 0 assert minimum_reliability_for_fault_tolerance(4, 3, 1, 4, [ (1, 2, 1), (2, 3, 1), (3, 4, 1) ...
[ { "docstring": null, "function_declaration": "def bfs(capacity, flow, source, sink, parent):", "function_name": "bfs", "parameter_list": "(capacity, flow, source, sink, parent)" }, { "docstring": null, "function_declaration": "def edmonds_karp(n, capacity, source, sink):", "function_...
[ 0, 0, 0, 0, 0, 0, 0, 0, 1, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "import heapq\nfrom collections import defaultdict\nimport sys\n\ndef find_min_total_reliability(n, m, s, t, cables):\n def dijkstra(source):\n dista...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00008416", "row_id": 8416, "seed_ids": "[4653]" }
0.585649
Codeforces_8416
I
[ "bfs", "edmonds_karp", "minimum_reliability_for_fault_tolerance" ]
3
[ [ "edmonds_karp", "bfs" ], [ "minimum_reliability_for_fault_tolerance", "edmonds_karp" ] ]
2
[]
false
[]
false
pytest
false
[]
true
00ad7180d1fb895f584bd33e47f88927090d0a75
1f6e91e98654deede94a762ed3fcccafee86a728
v1.0
instruct
Codeforces
Codeforces_8428_I
You are given an undirected graph with n nodes and m edges. Each edge has a positive integer weight. The task is to find a minimum spanning tree (MST) of the graph, which is a subset of the graph's edges that connects all the nodes together without any cycles and with the minimum possible total edge weight. You will ne...
def find(parent, i): if parent[i] == i: return i else: parent[i] = find(parent, parent[i]) return parent[i] def union(parent, rank, x, y): rootx = find(parent, x) rooty = find(parent, y) if rootx != rooty: if rank[rootx] > rank[rooty]: parent[rooty] ...
import pytest from solution import minimum_spanning_tree def test_example_case(): n = 4 m = 5 edges = [ [1, 2, 3], [1, 3, 1], [2, 3, 3], [2, 4, 6], [3, 4, 5] ] assert minimum_spanning_tree(n, m, edges) == 9 def test_disconnected_graph(): n = 4 m = 2 ...
[ { "docstring": null, "function_declaration": "def find(parent, i):", "function_name": "find", "parameter_list": "(parent, i)" }, { "docstring": null, "function_declaration": "def union(parent, rank, x, y):", "function_name": "union", "parameter_list": "(parent, rank, x, y)" }, ...
[ 1, 0, 0, 0, 1, 0, 0, 0, 0, 1 ]
3
hard
0.3
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def find(parent, i):\n if parent[i] == i:\n return i\n else:\n parent[i] = find(parent, parent[i])\n return parent[i]\n\ndef union(...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00008428", "row_id": 8428, "seed_ids": "[179]" }
0.837962
Codeforces_8428
I
[ "find", "union", "kruskal_mst", "minimum_spanning_tree" ]
4
[ [ "kruskal_mst", "find" ], [ "kruskal_mst", "union" ], [ "minimum_spanning_tree", "kruskal_mst" ], [ "union", "find" ] ]
4
[]
false
[]
false
pytest
true
[]
true
e56d978053d8cac8ce64c971ac0a84a98ca932bd
67836b9860d0ffaf60da0be9022f0d0c53d0076c
v1.0
instruct
Codeforces
Codeforces_8454_I
Given an integer `n` (1 ≤ n ≤ 10^9), determine if you can represent it as the sum of exactly two distinct positive integers such that both integers are prime. If it is possible, print "YES" and the two integers. Otherwise, print "NO". For example: 1. Input: 10 Output: YES 3 7 2. Input: 11 Output: NO ...
def is_prime(num): """Helper function to check if a number is prime""" if num <= 1: return False if num <= 3: return True if num % 2 == 0 or num % 3 == 0: return False i = 5 while i * i <= num: if num % i == 0 or num % (i + 2) == 0: return False ...
from solution import find_two_primes_sum def test_find_two_primes_sum_example_1(): assert find_two_primes_sum(10) == ("YES", 3, 7) or find_two_primes_sum(10) == ("YES", 5, 5) def test_find_two_primes_sum_example_2(): assert find_two_primes_sum(11) == ("NO",) def test_find_two_primes_sum_small_numbers(): ...
[ { "docstring": "Helper function to check if a number is prime", "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": "Determines if n can be represented as the sum of exactly two distinct positive integers that are both prime....
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_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_9
{ "original_instruction": "", "prompt_id": "00008454", "row_id": 8454, "seed_ids": "[4084]" }
0.650749
Codeforces_8454
I
[ "is_prime", "find_two_primes_sum" ]
2
[ [ "find_two_primes_sum", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
16bfc35e9dad12456806651eb278678002f91e2a
9d2f016a3ab42bfd869cab73a5270d3e5085de1d
v1.0
instruct
Codeforces
Codeforces_8503_I
Peter is working on optimizing a large dataset of numerical records. He wants to write a program that can compress a sequence of numbers by combining consecutive duplicates into a single number and recording the count of these duplicates. To achieve this, he plans to use run-length encoding. Run-length encoding is a ...
def run_length_encoding(sequence): """ Perform run-length encoding on a given list of integers. Args: sequence (list of int): List of integers to encode. Returns: list of tuples: Each tuple contains a number and its count. """ if not sequence: return [] encoded = [...
import pytest from solution import run_length_encoding_from_string def test_encoding_with_consecutive_numbers(): assert run_length_encoding_from_string("4 4 4 4 5 5 1 1 1") == "4 4 5 2 1 3" def test_encoding_with_single_number(): assert run_length_encoding_from_string("7") == "7 1" def test_encoding_with_no_...
[ { "docstring": "Perform run-length encoding on a given list of integers.\n\nArgs:\nsequence (list of int): List of integers to encode.\n\nReturns:\nlist of tuples: Each tuple contains a number and its count.", "function_declaration": "def run_length_encoding(sequence):", "function_name": "run_length_enc...
[ 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 run_length_encoding(sequence):\n \"\"\"\n Perform run-length encoding on a given list of integers.\n \n Parameters:\n sequence (list of int...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00008503", "row_id": 8503, "seed_ids": "[3157]" }
0.65294
Codeforces_8503
I
[ "run_length_encoding", "sequence_to_string", "run_length_encoding_from_string" ]
3
[ [ "run_length_encoding_from_string", "run_length_encoding" ], [ "run_length_encoding_from_string", "sequence_to_string" ] ]
2
[]
false
[]
false
pytest
true
[]
true
8aecedcedd5803c54c5cbdde3c688c4ad650d35f
5d16f42e7f6b426e29f55146d7f4578c6a792586
v1.0
instruct
Codeforces
Codeforces_8523_I
You are given a binary matrix where each cell can either be 0 or 1. The task is to find the largest square sub-matrix consisting entirely of 1's and return its area. The input consists of: - An integer n (1 ≤ n ≤ 1000), the number of rows in the matrix. - An integer m (1 ≤ m ≤ 1000), the number of columns in the matri...
def maximalSquare(matrix): """ Given a binary matrix, finds the area of the largest square sub-matrix consisting entirely of 1's. """ if not matrix or not matrix[0]: return 0 n = len(matrix) m = len(matrix[0]) dp = [[0] * m for _ in range(n)] max_side = 0 for i in r...
import pytest from solution import largest_square_submatrix_area def test_largest_square_submatrix_area_example(): matrix = [ [1, 0, 1, 0, 0, 1], [1, 0, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1], [1, 0, 0, 1, 1, 1], [1, 1, 1, 1, 1, 1] ] assert largest_square_submatrix_area(5, ...
[ { "docstring": "Given a binary matrix, finds the area of the largest square\nsub-matrix consisting entirely of 1's.", "function_declaration": "def maximalSquare(matrix):", "function_name": "maximalSquare", "parameter_list": "(matrix)" }, { "docstring": null, "function_declaration": "def ...
[ 0, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
9
easy
0.9
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def largest_square_area(matrix):\n \"\"\"\n Returns the area of the largest square sub-matrix filled with 1's.\n \"\"\"\n n = len(matrix)\n m =...
trial_gpt4o_3
{ "original_instruction": "", "prompt_id": "00008523", "row_id": 8523, "seed_ids": "[4945]" }
0.659567
Codeforces_8523
I
[ "maximalSquare", "largest_square_submatrix_area" ]
2
[ [ "largest_square_submatrix_area", "maximalSquare" ] ]
1
[]
false
[]
false
pytest
true
[]
true
c8ceffd017bc566c762a5fb583340caad9a9bb18
685dd7d40c6aaebd5d42ab3afbe39a7aa7f93199
v1.0
instruct
Codeforces
Codeforces_8548_I
A company has a team of software engineers who often collaborate on different projects. They usually communicate via a group chat, and each team member has unique preferences for how they like to be notified about new messages. Some prefer instant notifications, while others check messages only a few times a day. The ...
from math import gcd from functools import reduce from typing import List def lcm(a, b): """ Helper function to calculate the least common multiple of two numbers. """ return abs(a * b) // gcd(a, b) def max_notification_time(intervals: List[int]) -> int: """ Given an array of integers where ea...
from solution import max_notification_time def test_example_cases(): assert max_notification_time([5, 10, 15]) == 30 assert max_notification_time([1, 2, 3]) == 6 assert max_notification_time([7, 5, 6]) == 210 def test_single_interval(): assert max_notification_time([5]) == 5 assert max_notificatio...
[ { "docstring": "Helper function to calculate the least common multiple of two numbers.", "function_declaration": "def lcm(a, b):", "function_name": "lcm", "parameter_list": "(a, b)" }, { "docstring": "Given an array of integers where each integer represents the preferred notification interva...
[ 1, 1, 1, 1, 0, 1, 0, 1, 0, 1 ]
7
easy
0.7
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "import math\nfrom functools import reduce\nfrom typing import List\n\ndef lcm(a: int, b: int) -> int:\n return abs(a*b) // math.gcd(a, b)\n\ndef max_notifi...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00008548", "row_id": 8548, "seed_ids": "[7096]" }
0.559483
Codeforces_8548
I
[ "lcm", "max_notification_time" ]
2
[ [ "max_notification_time", "lcm" ] ]
1
[]
false
[]
false
pytest
true
[]
true
4e110acc6c53ca454dc4c2f16e3261816b76f571
67b1815b14a5af716919af77a9897e482b543d5f
v1.0
instruct
Codeforces
Codeforces_8570_I
In a certain wizarding world, there is a famous broom racing tournament held annually. In this race, broom riders must navigate through a series of checkpoints scattered throughout a large forest. Each rider starts at checkpoint 0 (the starting point) and must reach checkpoint n (the final point). They can fly through ...
import itertools import math def calculate_distance(coord1, coord2): """ Calculate the Euclidean distance between two coordinates. """ return math.sqrt((coord1[0] - coord2[0])**2 + (coord1[1] - coord2[1])**2) def min_total_distance(n, coordinates): """ Calculate the minimum total distance requ...
from solution import min_total_distance def test_example_case(): n = 4 coordinates = [(0, 0), (2, 2), (2, 0), (0, 2)] assert min_total_distance(n, coordinates) == 8 def test_single_checkpoint(): n = 1 coordinates = [(0, 0)] assert min_total_distance(n, coordinates) == 0 def test_two_checkpoin...
[ { "docstring": "Calculate the Euclidean distance between two coordinates.", "function_declaration": "def calculate_distance(coord1, coord2):", "function_name": "calculate_distance", "parameter_list": "(coord1, coord2)" }, { "docstring": "Calculate the minimum total distance required to visit...
[ 1, 0, 0, 1, 0, 0, 0, 0, 0, 0 ]
2
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "import itertools\nimport math\n\ndef euclidean_distance(p1, p2):\n \"\"\"\n Calculate the Euclidean distance between two points p1 and p2.\n \"\"\"\n...
trial_gpt4o_3
{ "original_instruction": "", "prompt_id": "00008570", "row_id": 8570, "seed_ids": "[6032]" }
0.739673
Codeforces_8570
I
[ "calculate_distance", "min_total_distance" ]
2
[ [ "min_total_distance", "calculate_distance" ] ]
1
[]
false
[]
false
pytest
true
[]
true
dccc4d3bffa9464bbd9c985f678d491a26239255
2b16dfad04fbcc5827760c86b855a5e7045b457a
v1.0
instruct
Codeforces
Codeforces_8608_I
A matrix is a rectangular array of numbers arranged in rows and columns. You are given a matrix of size $$$n \times m$$$ and you need to answer $$$q$$$ queries. Each query is defined by four integers $$$x_1, y_1, x_2, y_2$$$ which describe the top-left and bottom-right corners of a submatrix. Your task is to find the ...
def preprocess_matrix(matrix): """ Preprocess the matrix to create an auxiliary sum_matrix where sum_matrix[i][j] contains the sum of elements from (0,0) to (i-1, j-1) in the original matrix. """ n = len(matrix) m = len(matrix[0]) sum_matrix = [[0] * (m + 1) for _ in range(n + 1)] ...
from solution import preprocess_matrix, submatrix_sum, matrix_query_sums def test_preprocess_matrix(): matrix = [ [1, 2, 3], [4, 5, 6], [7, 8, 9] ] expected = [ [0, 0, 0, 0], [0, 1, 3, 6], [0, 5, 12, 21], [0, 12, 27, 45] ] assert preproces...
[ { "docstring": "Preprocess the matrix to create an auxiliary sum_matrix where sum_matrix[i][j]\ncontains the sum of elements from (0,0) to (i-1, j-1) in the original matrix.", "function_declaration": "def preprocess_matrix(matrix):", "function_name": "preprocess_matrix", "parameter_list": "(matrix)"...
[ 1, 1, 1, 1, 1, 1, 1, 0, 0, 0 ]
7
easy
0.7
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def matrix_sum_submatrix(n, m, matrix, queries):\n # Precomputing prefix sums\n prefix_sum = [[0] * (m + 1) for _ in range(n + 1)]\n \n for i in r...
trial_gpt4o_6
{ "original_instruction": "", "prompt_id": "00008608", "row_id": 8608, "seed_ids": "[7511]" }
0.678507
Codeforces_8608
I
[ "preprocess_matrix", "submatrix_sum", "matrix_query_sums" ]
3
[ [ "matrix_query_sums", "preprocess_matrix" ], [ "matrix_query_sums", "submatrix_sum" ] ]
2
[]
false
[]
false
pytest
true
[]
true
a5321170102432d51c7dca71a8c1dc76baf169c5
6ea2762d8761976e68732dc3fcc47db9f5df5ca0
v1.0
instruct
Codeforces
Codeforces_8655_I
You are given a list of n projects, each characterized by three parameters: start time, end time, and profit. The projects cannot overlap, meaning that any two selected projects must not be active simultaneously. You need to determine the maximum profit you can achieve by selecting a subset of non-overlapping projects...
from bisect import bisect_left def max_profit(n, projects): projects.sort(key=lambda x: x[1]) # Sort projects by end time # Initialize dp array where dp[i] will store the max profit by taking projects up to i-th dp = [(0, 0)] # (end_time, profit) for start, end, profit in projects: # Find t...
from solution import max_profit_from_input def test_single_project(): input_data = "1\n1 2 10" assert max_profit_from_input(input_data) == 10 def test_two_non_overlapping_projects(): input_data = "2\n1 2 10\n3 4 20" assert max_profit_from_input(input_data) == 30 def test_two_overlapping_projects(): ...
[ { "docstring": null, "function_declaration": "def max_profit(n, projects):", "function_name": "max_profit", "parameter_list": "(n, projects)" }, { "docstring": null, "function_declaration": "def max_profit_from_input(input_str):", "function_name": "max_profit_from_input", "parame...
[ 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 max_profit_non_overlapping_projects(n, projects):\n \"\"\"\n Finds the maximum profit from a list of non-overlapping projects.\n \n :param n: ...
trial_gpt4o_3
{ "original_instruction": "", "prompt_id": "00008655", "row_id": 8655, "seed_ids": "[6095]" }
0.658641
Codeforces_8655
I
[ "max_profit", "max_profit_from_input" ]
2
[ [ "max_profit_from_input", "max_profit" ] ]
1
[]
false
[]
false
pytest
true
[]
true
e2068206b1bb9f75e526fa0ababc72aea1643c31
18ed0a21423f13f2c2397ada45596946aa91f29c
v1.0
instruct
Codeforces
Codeforces_8681_I
You are given a rectangular matrix of dimensions $$$n \times m$$$. Each cell in the matrix contains a non-negative integer. Your task is to find the maximum sum of a subrectangle. A subrectangle is defined as any contiguous submatrix within the given matrix. The first line of the input contains two integers $$$n$$$ an...
def max_subrectangle_sum(matrix): """ Returns the maximum sum of any subrectangle in the given matrix. """ n = len(matrix) m = len(matrix[0]) max_sum = float('-inf') for left in range(m): temp = [0] * n for right in range(left, m): for i in range(n): ...
def test_max_subrectangle_sum(): input_data = "3 3\n1 2 3\n4 5 6\n7 8 9" assert maximum_sum_of_subrectangle(input_data) == 45 input_data = "2 2\n-1 -2\n-3 -4" assert maximum_sum_of_subrectangle(input_data) == -1 input_data = "3 3\n1 2 -1\n-3 -4 2\n1 2 3" assert maximum_sum_of_subrectangle(inpu...
[ { "docstring": "Returns the maximum sum of any subrectangle in the given matrix.", "function_declaration": "def max_subrectangle_sum(matrix):", "function_name": "max_subrectangle_sum", "parameter_list": "(matrix)" }, { "docstring": null, "function_declaration": "def parse_input(input_str...
[ 0, 0, 0, 0, 0, 1, 0, 0, 0, 1 ]
2
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def max_subrectangle_sum(matrix):\n \"\"\"\n Given a matrix, returns the maximum sum of any subrectangle.\n\n Input:\n matrix: List of List of...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00008681", "row_id": 8681, "seed_ids": "[1227]" }
0.633134
Codeforces_8681
I
[ "max_subrectangle_sum", "parse_input", "maximum_sum_of_subrectangle" ]
3
[ [ "maximum_sum_of_subrectangle", "max_subrectangle_sum" ], [ "maximum_sum_of_subrectangle", "parse_input" ] ]
2
[ "parse_input" ]
false
[]
false
pytest
false
[]
true
356e7863e5a7dfe229c3fab13248039398446e47
95f417a892911ad168def8605e6eb535d734210f
v1.0
instruct
Codeforces
Codeforces_8714_I
You are given an array of $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$. You can apply the following operation any number of times: choose any two elements in the array and swap their positions. Let $$$g(a)$$$ represent the minimum number of swap operations you need to sort the array in non-descending order. For exampl...
def min_swaps_to_sort(arr): """ This function returns the minimum number of swaps required to sort the array in non-descending order. """ n = len(arr) arrpos = list(enumerate(arr)) arrpos.sort(key=lambda it: it[1]) vis = {k: False for k in range(n)} ans = 0 for i in range(n): ...
from solution import min_swaps_to_sort, total_min_swaps_to_sort def test_min_swaps_to_sort(): assert min_swaps_to_sort([4, 3, 2, 1]) == 2 assert min_swaps_to_sort([1, 5, 4, 3, 2]) == 2 assert min_swaps_to_sort([1, 3, 5, 2, 4, 6]) == 3 assert min_swaps_to_sort([1, 2, 3, 4, 5]) == 0 def test_total_min_s...
[ { "docstring": "This function returns the minimum number of swaps required to sort the array in \nnon-descending order.", "function_declaration": "def min_swaps_to_sort(arr):", "function_name": "min_swaps_to_sort", "parameter_list": "(arr)" }, { "docstring": "This function calculates the tot...
[ 0, 1, 1, 0, 0, 0, 0, 0, 0, 0 ]
2
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def min_swaps_to_sort(arr):\n \"\"\"\n Returns the minimum number of swaps required to sort the array.\n\n Parameters:\n arr (list): List of integ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00008714", "row_id": 8714, "seed_ids": "[2548]" }
0.710287
Codeforces_8714
I
[ "min_swaps_to_sort", "total_min_swaps_to_sort" ]
2
[ [ "total_min_swaps_to_sort", "min_swaps_to_sort" ] ]
1
[]
false
[]
false
pytest
true
[]
true
5401738c53077758d62ec12b26e78876b0c30244
83af5fdf820e764d8b75247a12296b2bd0d8d113
v1.0
instruct
Codeforces
Codeforces_8749_I
The Quick Rabbit loves sequences. He has a sequence of positive integers and wants to find the longest subsegment of the sequence where the sum of the subsegment is a prime number. Given an array of n integers, help the Quick Rabbit find the length of the longest subsegment with a sum that is a prime number. If no su...
import math def is_prime(n): """ Check if a given number is prime """ if n <= 1: return False if n <= 3: return True if n % 2 == 0 or n % 3 == 0: return False i = 5 while (i * i) <= n: if n % i == 0 or n % (i + 2) == 0: return False i += 6 ...
from solution import longest_prime_sum_subsegment def test_longest_prime_sum_subsegment_example(): assert longest_prime_sum_subsegment(5, [1, 2, 3, 4, 5]) == 2 def test_longest_prime_sum_subsegment_no_prime_sum(): assert longest_prime_sum_subsegment(3, [4, 6, 8]) == 0 def test_longest_prime_sum_subsegment_si...
[ { "docstring": "Check if a given number is prime ", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Find the length of the longest subsegment with a prime sum ", "function_declaration": "def longest_prime_sum_subsegment(...
[ 0, 0, 0, 0, 0, 0, 1, 0, 0, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "from sympy import isprime\n\ndef longest_prime_sum_subsegment(arr):\n n = len(arr)\n max_len = 0\n \n for i in range(n):\n current_sum = 0\...
trial_gpt4o_6
{ "original_instruction": "", "prompt_id": "00008749", "row_id": 8749, "seed_ids": "[2970]" }
0.623508
Codeforces_8749
I
[ "is_prime", "longest_prime_sum_subsegment" ]
2
[ [ "longest_prime_sum_subsegment", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
af3e92ca180409c0d49ede20a54046717717f55d
78f68c61e3212276845093361604c758b4bd9d3b
v1.0
instruct
Codeforces
Codeforces_8753_I
You are given a map of a city represented as a grid of size m x n, where each cell can be either open land ('O'), water ('W'), or a tree ('T'). A tree cell cannot be traversed, but you can move through open land and water. The city mayor wants to know the maximum area of water that can be transformed into a park. A pa...
def maxWaterParkArea(grid): # If the grid is empty, return 0 if not grid or not grid[0]: return 0 # Get the dimensions of the grid m, n = len(grid), len(grid[0]) # Initialize the dp array to store the height of consecutive 'W' from top to current row heights = [0] * n max_area = 0 ...
def test_maxWaterParkArea(): grid = [ ["O", "W", "W", "O", "T"], ["W", "W", "W", "O", "T"], ["T", "O", "O", "W", "W"], ["O", "W", "W", "O", "T"] ] assert maxWaterParkArea(grid) == 4 def test_grid_with_single_row(): grid = [ ["O", "W", "W", "O", "T"] ] ass...
[ { "docstring": null, "function_declaration": "def maxWaterParkArea(grid):", "function_name": "maxWaterParkArea", "parameter_list": "(grid)" }, { "docstring": null, "function_declaration": "def max_histogram_area(heights):", "function_name": "max_histogram_area", "parameter_list":...
[ 1, 1, 0, 0, 0, 1, 1, 0, 1 ]
5
medium
0.556
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def maxWaterParkArea(grid):\n # If the grid is empty, return 0\n if not grid or not grid[0]:\n return 0\n\n # Get the dimensions of the grid\n...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00008753", "row_id": 8753, "seed_ids": "[3188]" }
0.656806
Codeforces_8753
I
[ "maxWaterParkArea", "max_histogram_area" ]
2
[ [ "maxWaterParkArea", "max_histogram_area" ] ]
1
[]
false
[]
false
pytest
false
[]
true
84de69c78d35c65d4ee535c6b358cf7b7708e550
13735782fd2c7cac3986797a4af51c7e3f14f4da
v1.0
instruct
Codeforces
Codeforces_8777_I
You are given a tree (connected acyclic undirected graph) with `n` nodes. Each node has an integer value assigned to it. Your task is to answer multiple queries on the tree. Each query asks for the maximum value within a given subtree of the tree. ### Input - The first line contains an integer `n` (1 ≤ n ≤ 100,000) — ...
from collections import defaultdict def build_tree(n, edges): tree = defaultdict(list) for u, v in edges: tree[u].append(v) tree[v].append(u) return tree def dfs(tree, node, parent, values, subtree_max): # Initially, the maximum of subtree rooted at `node` is the value of the node itse...
import pytest from solution import solve_tree_queries def test_example(): n = 7 values = [1, 2, 3, 4, 5, 6, 7] edges = [(1, 2), (1, 3), (2, 4), (2, 5), (3, 6), (3, 7)] queries = [1, 3, 6] expected = [7, 7, 6] assert solve_tree_queries(n, values, edges, queries) == expected def test_single_nod...
[ { "docstring": null, "function_declaration": "def build_tree(n, edges):", "function_name": "build_tree", "parameter_list": "(n, edges)" }, { "docstring": null, "function_declaration": "def dfs(tree, node, parent, values, subtree_max):", "function_name": "dfs", "parameter_list": "...
[ 1, 1, 1, 0, 1, 0, 0, 1, 0, 0 ]
5
medium
0.5
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def subtree_max_value(n, values, edges, queries):\n from collections import defaultdict, deque\n \n graph = defaultdict(list)\n for u, v in edges:...
trial_gpt4o_7
{ "original_instruction": "", "prompt_id": "00008777", "row_id": 8777, "seed_ids": "[2803]" }
0.683981
Codeforces_8777
I
[ "build_tree", "dfs", "preprocess_tree", "solve_tree_queries" ]
4
[ [ "preprocess_tree", "build_tree" ], [ "preprocess_tree", "dfs" ], [ "solve_tree_queries", "preprocess_tree" ] ]
3
[]
false
[]
false
pytest
true
[]
true
c6fd68bbea2d4200b070eaf9168713e8d5e8ebf3
905bb63ad9aa322bbc7532dc3fb5e6bb6b98ed1c
v1.0
instruct
Codeforces
Codeforces_8830_I
You are given an array of integers and two types of operations that you can perform: 1. Increment Operation: Choose an integer `k`, and increment all elements of the array by `k`. 2. Query Operation: Given an integer `q`, check if there is any subsequence of the array (not necessarily contiguous) such that the sum of ...
def can_form_sum(arr, q): """ Function to check if a subsequence with sum equal to q can be formed. Args: arr : List[int] : Input array of integers q : int : The target sum to check for subsequence Returns: bool : True if there exists a subsequence with sum equal to q, otherwise Fa...
import pytest from solution import process_operations def test_example_case(): n, m = 5, 3 arr = [1, 2, 3, 4, 5] operations = ["1 2", "2 15", "2 8"] assert process_operations(n, m, arr, operations) == ["YES", "NO"] def test_single_element_array(): n, m = 1, 2 arr = [10] operations = ["2 10...
[ { "docstring": "Function to check if a subsequence with sum equal to q can be formed.\n\nArgs:\narr : List[int] : Input array of integers\nq : int : The target sum to check for subsequence\n\nReturns:\nbool : True if there exists a subsequence with sum equal to q, otherwise False", "function_declaration": "...
[ 1, 0, 0, 0, 0, 0, 0, 0, 0 ]
1
hard
0.111
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def can_form_sum(arr, q):\n \"\"\"\n Function to check if a subsequence with sum equal to q can be formed.\n \n Args:\n arr : List[int] : Input...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00008830", "row_id": 8830, "seed_ids": "[4737]" }
0.767322
Codeforces_8830
I
[ "can_form_sum", "process_operations" ]
2
[ [ "process_operations", "can_form_sum" ] ]
1
[]
false
[]
false
pytest
true
[]
true
8e3af0cbb6befb1bab96e14fb2e16176e997f715
e9a31f65d8c20700dc2d36108490769f654aa5bf
v1.0
instruct
Codeforces
Codeforces_9010_I
John is working with an array of integers and wants to perform a series of operations on the array. Each operation is described by three integers l, r, and k, which mean the following: toggle (flip) all bits in the binary representation of numbers in the subarray from index l to index r (both inclusive) exactly k times...
def flip_bits(num): """ This function flips the bits of an integer `num` assuming a 32-bit integer. """ # Assuming a 32-bit integer return num ^ 0xFFFFFFFF def perform_operations(n, q, array, operations): """ This function performs q operations on the array of size n. The operations are...
from solution import perform_operations def test_single_operation_odd_k(): assert perform_operations(3, 1, [1, 2, 3], [(1, 2, 1)]) == [4294967294, 4294967293, 3] def test_single_operation_even_k(): assert perform_operations(3, 1, [1, 2, 3], [(1, 2, 2)]) == [1, 2, 3] def test_multiple_operations(): assert...
[ { "docstring": "This function flips the bits of an integer `num` assuming a 32-bit integer.", "function_declaration": "def flip_bits(num):", "function_name": "flip_bits", "parameter_list": "(num)" }, { "docstring": "This function performs q operations on the array of size n.\nThe operations ...
[ 1, 1, 0, 1, 0, 1, 1, 0, 0 ]
5
medium
0.556
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def toggle_bits_in_subarray(n, q, arr, operations):\n \"\"\"\n Toggle bits in the subarray from index l to index r exactly k times as described in opera...
trial_gpt4o_6
{ "original_instruction": "", "prompt_id": "00009010", "row_id": 9010, "seed_ids": "[3955]" }
0.691197
Codeforces_9010
I
[ "flip_bits", "perform_operations" ]
2
[ [ "perform_operations", "flip_bits" ] ]
1
[]
false
[]
false
pytest
true
[]
true
91f1b1b59c44b987fd20d9d77ed6a83dd99331bd
061fd1b0aedbb8575584a945efbc9cb254cacfaf
v1.0
instruct
Codeforces
Codeforces_9043_I
**Palindrome Permutation Check** Alice and Bob are playing a game with strings. They found a string consisting of lowercase English letters and decided to check if the string can be permuted to form a palindrome. In this game, Bob wins if the string can be permuted to form a palindrome, otherwise Alice wins. A strin...
def can_be_permuted_to_palindrome(s): """ Determines if the string s can be permuted to form a palindrome. """ from collections import Counter count = Counter(s) odd_count = sum(1 for c in count.values() if c % 2 != 0) return odd_count <= 1 def game_result(t, strings): """ For each ...
from solution import can_be_permuted_to_palindrome, game_result def test_can_be_permuted_to_palindrome(): # Test cases where Bob wins assert can_be_permuted_to_palindrome("civic") == True assert can_be_permuted_to_palindrome("ivicc") == True assert can_be_permuted_to_palindrome("a") == True assert ...
[ { "docstring": "Determines if the string s can be permuted to form a palindrome.", "function_declaration": "def can_be_permuted_to_palindrome(s):", "function_name": "can_be_permuted_to_palindrome", "parameter_list": "(s)" }, { "docstring": "For each string in strings, determines if Bob wins ...
[ 1, 0, 1, 1, 1, 1, 0, 1, 0, 1 ]
7
easy
0.7
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_palindrome_permutation(s):\n \"\"\"\n Determines if a given string can be permuted to form a palindrome.\n \"\"\"\n from collections import...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00009043", "row_id": 9043, "seed_ids": "[1254]" }
0.690443
Codeforces_9043
I
[ "can_be_permuted_to_palindrome", "game_result" ]
2
[ [ "game_result", "can_be_permuted_to_palindrome" ] ]
1
[]
false
[]
false
pytest
true
[]
true
0ddeabc0744bb6779dc921455ad86cacd9bdac2a
36b51a7f54a38f85197e672070be5a02fdb2fcd2
v1.0
instruct
Codeforces
Codeforces_9145_I
You are given an array of integers representing a binary tree in level-order traversal form. Your goal is to construct the binary tree and find the maximum path sum. The path must start and end at any node in the binary tree but can only move through nodes consecutively along parent-child connections. The tree is repr...
from typing import List, Optional class TreeNode: def __init__(self, val: int): self.val = val self.left = None self.right = None def build_tree(tree: List[Optional[int]]) -> Optional[TreeNode]: if not tree: return None nodes = [None if val is None else TreeNode(val) f...
import pytest from solution import max_path_sum def test_single_node(): assert max_path_sum([1]) == 1 def test_two_level_complete_tree(): assert max_path_sum([1, 2, 3]) == 6 def test_tree_with_null_nodes(): assert max_path_sum([1, 2, 3, None, 4, 5, 6]) == 16 def test_complex_tree_example(): assert m...
[]
[ 1, 0, 1, 1, 0, 1, 0, 0, 1, 1 ]
6
medium
0.6
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "from typing import List, Optional\n\nclass TreeNode:\n def __init__(self, val=0, left=None, right=None):\n self.val = val\n self.left = left\...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00009145", "row_id": 9145, "seed_ids": "[5309]" }
0.629326
Codeforces_9145
I
[ "build_tree", "max_path_sum" ]
2
[ [ "max_path_sum", "build_tree" ] ]
1
[]
false
[ "TreeNode" ]
true
pytest
true
[]
true
59e1df2b83d7f1f4caec41a29942820a3f79986d
f12ed1768448dd263a7192ba8f0631180180f28a
v1.0
instruct
Codeforces
Codeforces_9189_I
You are given an undirected graph with `n` vertices and `m` edges. Each vertex is labeled from `1` to `n`. The graph is represented as an adjacency list, where each vertex has a list of vertices it is connected to. You are required to perform a Depth First Search (DFS) starting from a given vertex `s`. During the DFS,...
def dfs_lexicographic(n, m, edges, s): from collections import defaultdict import heapq # Create adjacency list graph = defaultdict(list) for u, v in edges: graph[u].append(v) graph[v].append(u) # Sort adjacency lists for lexicographical order for key in graph.keys(...
from solution import perform_dfs def test_example_case(): n = 5 m = 4 edges = [(1, 2), (1, 3), (2, 4), (2, 5)] start = 1 assert perform_dfs(n, m, edges, start) == [1, 2, 4, 5, 3] def test_single_node(): n = 1 m = 0 edges = [] start = 1 assert perform_dfs(n, m, edges, start) == ...
[ { "docstring": null, "function_declaration": "def dfs_lexicographic(n, m, edges, s):", "function_name": "dfs_lexicographic", "parameter_list": "(n, m, edges, s)" }, { "docstring": null, "function_declaration": "def perform_dfs(n, m, edge_list, start):", "function_name": "perform_dfs"...
[ 1, 0, 1, 1, 1, 1, 1, 1, 1, 1 ]
9
easy
0.9
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def dfs_lexicographically_smallest(graph, start):\n \"\"\"\n Perform DFS on the given graph starting from the vertex `start` in a lexicographically smal...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00009189", "row_id": 9189, "seed_ids": "[295]" }
0.643276
Codeforces_9189
I
[ "dfs_lexicographic", "perform_dfs" ]
2
[ [ "perform_dfs", "dfs_lexicographic" ] ]
1
[]
false
[]
false
pytest
true
[]
true
d9d3c5768056a1378a370992e173c3851fcb79ab
4f918f601ee784b78d82214203e3518986b74f20
v1.0
instruct
Codeforces
Codeforces_9206_I
You have been assigned a task to analyze the social media activity of users in a new app. Each user can either like a post or share it, and each of these actions will be stored in a log file. The log file captures activities in the following format: ``` ACTION_TYPE USER_ID TIMESTAMP ``` Where: - `ACTION_TYPE` is eith...
from bisect import bisect_left, bisect_right from collections import defaultdict from datetime import datetime def parse_log(log): action_type, user_id, timestamp = log.split() return action_type, timestamp def social_media_activity(logs, queries): # Create a dictionary to hold the actions with timestamps...
def test_social_media_activity(): logs = [ "LIKE user1 2023-04-01T10:00:00Z", "SHARE user2 2023-04-01T10:05:00Z", "LIKE user1 2023-04-01T11:00:00Z", "SHARE user3 2023-04-01T12:00:00Z" ] queries = [ ("2023-04-01T10:00:00Z", "2023-04-01T11:00:00Z", "LIKE"), ("20...
[ { "docstring": null, "function_declaration": "def parse_log(log):", "function_name": "parse_log", "parameter_list": "(log)" }, { "docstring": null, "function_declaration": "def social_media_activity(logs, queries):", "function_name": "social_media_activity", "parameter_list": "(l...
[ 1, 1, 1, 1, 1, 1, 1, 1, 0, 1 ]
9
easy
0.9
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "from collections import defaultdict\nfrom bisect import bisect_left, bisect_right\nimport datetime\n\ndef parse_timestamp(timestamp):\n return datetime.dat...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00009206", "row_id": 9206, "seed_ids": "[4286]" }
0.672338
Codeforces_9206
I
[ "parse_log", "social_media_activity" ]
2
[ [ "social_media_activity", "parse_log" ] ]
1
[]
false
[]
false
pytest
false
[]
true
d249515e133de278d82bab1b4ab8086d5924cab3
0ddc31e301a55378ea9bb8e8bf2700a0ea95309e
v1.0
instruct
Codeforces
Codeforces_9262_I
In an industrial bakery, cookies are packed into boxes based on their type. There are three types of cookies: Chocolate Chip, Peanut Butter, and Oatmeal Raisin. You are given a list of boxes and each box contains a certain number of these three types of cookies. Your task is to determine if the boxes can be arranged in...
def determine_primary_cookie_type(c, p, o): """ Determine the primary cookie type based on the count provided. If there is a tie, return None. """ if c > p and c > o: return "Chocolate Chip" elif p > c and p > o: return "Peanut Butter" elif o > c and o > p: return "Oa...
from solution import can_arrange_boxes def test_example_1(): boxes = [(5, 3, 2), (1, 4, 3), (2, 2, 5)] assert can_arrange_boxes(3, boxes) == "Possible" def test_example_2(): boxes = [(3, 3, 1), (4, 4, 4)] assert can_arrange_boxes(2, boxes) == "Impossible" def test_single_box(): boxes = [(5, 0, 0)...
[ { "docstring": "Determine the primary cookie type based on the count provided.\nIf there is a tie, return None.", "function_declaration": "def determine_primary_cookie_type(c, p, o):", "function_name": "determine_primary_cookie_type", "parameter_list": "(c, p, o)" }, { "docstring": "Determin...
[ 1, 0, 0, 0, 0, 0, 0, 1, 1, 1 ]
4
medium
0.4
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def can_rearrange_boxes(n, boxes):\n from collections import Counter\n \n # Get the primary cookie type for each box\n primary_cookies = []\n f...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00009262", "row_id": 9262, "seed_ids": "[7093]" }
0.669005
Codeforces_9262
I
[ "determine_primary_cookie_type", "can_arrange_boxes" ]
2
[ [ "can_arrange_boxes", "determine_primary_cookie_type" ] ]
1
[]
false
[]
false
pytest
true
[]
true
956cb541ca1662fc5b8682a77ecd97ab8f8302ef
fa885237ba3a04cc45209cf8c09e40428c9a68f8
v1.0
instruct
Codeforces
Codeforces_9268_I
Maximal Rectangle in a Grid Given a 2D binary matrix filled with 0’s and 1’s, find the largest rectangle (containing only 1’s) and return its area. ### Input Format The input consists of two lines: - The first line contains two integers $$$ m $$$ and $$$ n $$$ ($$$1 \le m, n \le 200$$$) — the number of rows and colum...
def maximalRectangle(matrix): if not matrix: return 0 max_area = 0 dp = [0] * len(matrix[0]) for row in matrix: for i in range(len(row)): dp[i] = dp[i] + 1 if row[i] == 1 else 0 max_area = max(max_area, largestRectangleArea(dp)) return max_...
def test_maximalRectangle(): matrix1 = [ [1, 0, 1, 0, 0], [1, 0, 1, 1, 1], [1, 1, 1, 1, 1], [1, 0, 0, 1, 0] ] assert maximalRectangle(matrix1) == 6 matrix2 = [ [0, 1], [1, 0] ] assert maximalRectangle(matrix2) == 1 matrix3 = [ ...
[ { "docstring": null, "function_declaration": "def maximalRectangle(matrix):", "function_name": "maximalRectangle", "parameter_list": "(matrix)" }, { "docstring": null, "function_declaration": "def largestRectangleArea(heights):", "function_name": "largestRectangleArea", "paramete...
[ 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 maximalRectangle(m, n, matrix):\n def maximal_histogram_area(heights):\n stack = []\n max_area = 0\n index = 0\n \n ...
trial_gpt4o_4
{ "original_instruction": "", "prompt_id": "00009268", "row_id": 9268, "seed_ids": "[7825]" }
0.729745
Codeforces_9268
I
[ "maximalRectangle", "largestRectangleArea", "read_input" ]
3
[ [ "maximalRectangle", "largestRectangleArea" ] ]
1
[ "read_input" ]
false
[]
false
pytest
false
[]
true
ce9951691d716603565adcf1599cd0b7ebf21019
a3979c5fab90325d4b36f81d6346cd587ddc50fc
v1.0
instruct
Codeforces
Codeforces_9320_I
You are tasked with optimizing the fuel distribution in a network of stations. Each station can either receive a fixed amount of fuel from its neighboring stations or not, following certain constraints. Your goal is to determine the maximum amount of fuel that can be distributed across the network. The network consist...
from collections import defaultdict, deque def max_fuel_distribution(n, demands, roads): graph = defaultdict(list) for u, v, c in roads: graph[u].append((v, c)) max_fuel = 0 visited = [False] * (n + 1) remaining_demand = demands[:] def bfs(start): visited[start] = True ...
from solution import max_fuel_distribution def test_example_case(): n = 4 demands = [30, 50, 60, 20] roads = [ (1, 2, 40), (1, 3, 20), (3, 4, 10) ] assert max_fuel_distribution(n, demands, roads) == 70 def test_corner_case_min_stations(): n = 2 demands = [10, 10] ...
[ { "docstring": null, "function_declaration": "def max_fuel_distribution(n, demands, roads):", "function_name": "max_fuel_distribution", "parameter_list": "(n, demands, roads)" }, { "docstring": null, "function_declaration": "def example():", "function_name": "example", "parameter...
[ 0, 0, 1, 0, 0, 0, 0, 0, 0, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def maxFuelDistributed(n, demands, roads):\n from collections import defaultdict, deque\n\n # Create an adjacency list to represent the graph\n adj =...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00009320", "row_id": 9320, "seed_ids": "[6095]" }
0.711946
Codeforces_9320
I
[ "max_fuel_distribution", "example" ]
2
[ [ "example", "max_fuel_distribution" ] ]
1
[]
false
[]
false
pytest
true
[]
true
b0a857ed60958028370010fa286dab928c3478c1
4ea77f0f20a78eab6b7d711a9986cd61bc7820ba
v1.0
instruct
Codeforces
Codeforces_9322_I
You are given an array of n integers, and you have to perform several operations on it. Each operation consists of two integers l and r and requires you to calculate the sum of all the elements of the array from index l to r inclusive. The array uses 1-based indexing. Write a program that performs these operations eff...
def compute_prefix_sums(arr): """ Compute prefix sums for the given array. """ prefix_sums = [0] * (len(arr) + 1) for i in range(1, len(arr) + 1): prefix_sums[i] = prefix_sums[i-1] + arr[i-1] return prefix_sums def range_sum(prefix_sums, l, r): """ Compute the sum of the array e...
from solution import compute_prefix_sums, range_sum, process_queries def test_compute_prefix_sums(): arr = [1, 2, 3, 4, 5] expected_prefix_sums = [0, 1, 3, 6, 10, 15] assert compute_prefix_sums(arr) == expected_prefix_sums def test_range_sum(): prefix_sums = [0, 1, 3, 6, 10, 15] assert range_sum(p...
[ { "docstring": "Compute prefix sums for the given array.", "function_declaration": "def compute_prefix_sums(arr):", "function_name": "compute_prefix_sums", "parameter_list": "(arr)" }, { "docstring": "Compute the sum of the array elements between indices l and r (1-based) using prefix sums."...
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
10
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def range_sum_queries(n, q, arr, queries):\n \"\"\"\n Returns the sum of elements between indices l and r for each query using prefix sum.\n n: int -...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00009322", "row_id": 9322, "seed_ids": "[2319]" }
0.677835
Codeforces_9322
I
[ "compute_prefix_sums", "range_sum", "process_queries" ]
3
[ [ "process_queries", "compute_prefix_sums" ], [ "process_queries", "range_sum" ] ]
2
[ "process_queries" ]
false
[]
false
pytest
true
[]
true
6a294411bbb56d7591b616d29e74d2a97460e80c
88b410d537988065c9f9ef7244cc032db71491d6
v1.0
instruct
Codeforces
Codeforces_9324_I
You are given an array of integers representing the node values of a binary tree in a level-order traversal. Your task is to determine if there exists a path in this binary tree such that the sum of the values along the path is equal to a given target sum. A path in the binary tree is a sequence of nodes starting from...
from typing import List, Optional class TreeNode: def __init__(self, x): self.val = x self.left = None self.right = None def build_tree(tree: List[int]) -> Optional[TreeNode]: if not tree or tree[0] == -1: return None root = TreeNode(tree[0]) nodes = [root] chi...
def test_case_1(): tree = [5, 4, 8, 11, -1, 13, 4, 7, 2, -1, -1, -1, 1] targetSum = 22 assert hasPathSum(tree, targetSum) == True def test_case_2(): tree = [1, 2, 3] targetSum = 5 assert hasPathSum(tree, targetSum) == False def test_case_3(): tree = [1, 2] targetSum = 3 assert hasP...
[]
[ 0, 0, 0, 0, 0, 0, 1, 0, 0, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def hasPathSum(tree, targetSum):\n def dfs(index, current_sum):\n if index >= len(tree) or tree[index] == -1:\n return False\n \n ...
trial_gpt4o_6
{ "original_instruction": "", "prompt_id": "00009324", "row_id": 9324, "seed_ids": "[4106]" }
0.592848
Codeforces_9324
I
[ "build_tree", "hasPathSum" ]
2
[ [ "hasPathSum", "build_tree" ] ]
1
[]
false
[ "TreeNode" ]
true
pytest
false
[]
true
012381de7e3eb67a39678cc466c46c9a7644ceb4
70e6a66ea092141ecc88f04944cfcec0e1e46e6d
v1.0
instruct
Codeforces
Codeforces_9351_I
You are given an integer array `nums` and an integer `target`. You need to return the indices of the two numbers from the array such that they add up to the `target`. You may assume that each input would have exactly one solution, and you may not use the same element twice. You can return the answer in any order. ###...
def two_sum(nums, target): """ Returns the indices of the two numbers from the array such that they add up to the target. """ num_to_index = {} for index, num in enumerate(nums): complement = target - num if complement in num_to_index: return num_to_index[complement], ind...
from solution import two_sum, solve_two_sum_problems, read_input, format_output def test_two_sum_basic(): assert two_sum([2, 7, 11, 15], 9) in [(0, 1), (1, 0)] assert two_sum([3, 2, 4], 6) in [(1, 2), (2, 1)] def test_two_sum_negative_numbers(): assert two_sum([-3, 4, 3, 90], 0) in [(0, 2), (2, 0)] as...
[ { "docstring": "Returns the indices of the two numbers from the array such that they add up to the target.", "function_declaration": "def two_sum(nums, target):", "function_name": "two_sum", "parameter_list": "(nums, target)" }, { "docstring": null, "function_declaration": "def solve_two...
[ 1, 1, 1, 0, 1, 0, 1, 0, 1, 0 ]
6
medium
0.6
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def two_sum(nums, target):\n \"\"\"\n Returns the indices of the two numbers from the array such that they add up to the target.\n \"\"\"\n num_ma...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00009351", "row_id": 9351, "seed_ids": "[3879]" }
0.734952
Codeforces_9351
I
[ "two_sum", "solve_two_sum_problems", "read_input", "format_output" ]
4
[ [ "solve_two_sum_problems", "two_sum" ] ]
1
[ "read_input", "format_output" ]
false
[]
false
pytest
true
[]
true
f721919b9b134b2cfd99c12c8edad07f53fa27eb
075fae622ad85f3d4e81aa928fee62532fb26026
v1.0
instruct
Codeforces
Codeforces_9361_I
You are given a rectangular grid of size $$$n \times m$$$ filled with integers, and a list of queries. Each query asks for the sum of the integers within a specific subrectangle of the grid. To solve the problem, you need to preprocess the grid to answer each query efficiently. The first line contains two integers $...
def preprocess(grid, n, m): 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] + prefix_sum[i][j-1] - ...
from solution import preprocess, query_sum, solve def test_preprocess(): grid = [ [1, 2, 3], [4, 5, 6], [7, 8, 9] ] expected_prefix_sum = [ [0, 0, 0, 0], [0, 1, 3, 6], [0, 5, 12, 21], [0, 12, 27, 45] ] assert preprocess(grid, 3, 3) == expected...
[ { "docstring": null, "function_declaration": "def preprocess(grid, n, m):", "function_name": "preprocess", "parameter_list": "(grid, n, m)" }, { "docstring": null, "function_declaration": "def query_sum(prefix_sum, x1, y1, x2, y2):", "function_name": "query_sum", "parameter_list"...
[ 1, 1, 1, 1, 1, 1, 1, 1 ]
8
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def preprocess_grid(grid):\n \"\"\"\n Preprocess the grid using prefix sums to allow O(1) sum queries.\n \"\"\"\n n, m = len(grid), len(grid[0])\n...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00009361", "row_id": 9361, "seed_ids": "[481]" }
0.684268
Codeforces_9361
I
[ "preprocess", "query_sum", "solve" ]
3
[ [ "solve", "preprocess" ], [ "solve", "query_sum" ] ]
2
[]
false
[]
false
pytest
true
[]
true
80a18cda03ea981c91a58a58e7a8da99bbdf666f
715461c105c404228de1f410fdcd2aeb96cbce3d
v1.0
instruct
Codeforces
Codeforces_9400_I
You are given an undirected, connected weighted graph with `n` nodes and `m` edges. Each edge has a unique weight assigned to it. Your task is to find the minimum spanning tree (MST) of this graph, where MST is defined as a subset of the edges that forms a tree that includes every vertex, and the total weight of all th...
def find(parent, i): if parent[i] == i: return i return find(parent, parent[i]) def union(parent, rank, x, y): xroot = find(parent, x) yroot = find(parent, y) if rank[xroot] < rank[yroot]: parent[xroot] = yroot elif rank[xroot] > rank[yroot]: parent[yroot] = xroot el...
from solution import minimum_spanning_tree def test_basic_case(): assert minimum_spanning_tree(4, 5, [(1, 2, 1), (2, 3, 2), (3, 4, 3), (4, 1, 4), (1, 3, 5)]) == 6 def test_disconnected_graph(): assert minimum_spanning_tree(4, 2, [(1, 2, 1), (3, 4, 2)]) == -1 def test_single_node(): assert minimum_spannin...
[ { "docstring": null, "function_declaration": "def find(parent, i):", "function_name": "find", "parameter_list": "(parent, i)" }, { "docstring": null, "function_declaration": "def union(parent, rank, x, y):", "function_name": "union", "parameter_list": "(parent, rank, x, y)" }, ...
[ 0, 0, 1, 1, 1, 0, 0, 0, 0, 0 ]
3
hard
0.3
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "class DisjointSet:\n def __init__(self, n):\n self.parent = list(range(n))\n self.rank = [0] * n\n\n def find(self, u):\n if self.p...
trial_gpt4o_4
{ "original_instruction": "", "prompt_id": "00009400", "row_id": 9400, "seed_ids": "[2405]" }
0.816646
Codeforces_9400
I
[ "find", "union", "kruskal_mst", "minimum_spanning_tree" ]
4
[ [ "kruskal_mst", "find" ], [ "kruskal_mst", "union" ], [ "minimum_spanning_tree", "kruskal_mst" ], [ "union", "find" ] ]
4
[]
false
[]
false
pytest
true
[]
true
ecdf21beb35432062ca6685da52f8a8a2cbdefd6
ed7ac2a7338c074d39700b55033962f48e2c5d61
v1.0
instruct
Codeforces
Codeforces_9427_I
Daniel has a rectangular grid map of a city. The city is represented as a 2D grid, where some locations are buildings and others are roads. Daniel is planning an emergency route from the bottom-left corner of the city (at position (n-1, 0)) to the top-right corner (at position (0, m-1)). Each cell of the grid can eith...
def find_path(n, m, grid): from collections import deque # Directions for moving up, down, left, right directions = [(-1, 0), (1, 0), (0, -1), (0, 1)] # Start from (n-1, 0) queue = deque([(n-1, 0)]) visited = set() visited.add((n-1, 0)) while queue: x, y = queue.po...
import pytest from solution import can_escape_route def test_case_1(): n = 4 m = 4 grid = [ "....", ".##.", "....", ".#.." ] assert can_escape_route(n, m, grid) == "YES" def test_case_2(): n = 3 m = 3 grid = [ "..#", "#.#", "#.." ...
[ { "docstring": null, "function_declaration": "def find_path(n, m, grid):", "function_name": "find_path", "parameter_list": "(n, m, grid)" }, { "docstring": null, "function_declaration": "def can_escape_route(n, m, grid):", "function_name": "can_escape_route", "parameter_list": "(...
[ 0, 1, 0, 0, 0, 0, 0, 0, 0, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_path_possible(grid, n, m):\n from collections import deque\n \n def is_valid(x, y):\n return 0 <= x < n and 0 <= y < m and grid[x][y] =...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00009427", "row_id": 9427, "seed_ids": "[3325]" }
0.690488
Codeforces_9427
I
[ "find_path", "can_escape_route" ]
2
[ [ "can_escape_route", "find_path" ] ]
1
[]
false
[]
false
pytest
true
[]
true
46484b942479f9c92f2ed386e232446446214b7f
0a7ec6a4ca39702d86086317f3335d9c9143b1f2
v1.0
instruct
Codeforces
Codeforces_9463_I
You are a renowned cryptographer and have been tasked with creating a new encryption scheme based on prime numbers. Your idea is to use the properties of prime gaps (the difference between consecutive prime numbers) for the encryption scheme. Given two prime numbers p1 and p2 such that p1 < p2, let g(p1, p2) represent...
def sieve(n): """ Returns a list of primes up to n, using the Sieve of Eratosthenes algorithm. """ is_prime = [True] * (n + 1) p = 2 while p * p <= n: if is_prime[p]: for i in range(p * p, n + 1, p): is_prime[i] = False p += 1 return [p for p in range(2, n...
from solution import prime_gaps_sum def test_prime_gaps_sum_example(): assert prime_gaps_sum(3, 11) == 8 def test_prime_gaps_sum_small_primes(): assert prime_gaps_sum(2, 5) == 3 def test_prime_gaps_sum_mid_primes(): assert prime_gaps_sum(23, 31) == 8 def test_prime_gaps_sum_large_primes(): assert pr...
[ { "docstring": "Returns a list of primes up to n, using the Sieve of Eratosthenes algorithm. ", "function_declaration": "def sieve(n):", "function_name": "sieve", "parameter_list": "(n)" }, { "docstring": "Returns the sum of all prime gaps between prime numbers p1 and p2, inclusive.", "f...
[ 1, 1, 0, 0, 0, 0, 0, 0, 0, 0 ]
2
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def sieve(n):\n \"\"\" Returns a list of primes up to n, using the Sieve of Eratosthenes algorithm. \"\"\"\n is_prime = [True] * (n + 1)\n p = 2\n ...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00009463", "row_id": 9463, "seed_ids": "[2996]" }
0.583631
Codeforces_9463
I
[ "sieve", "prime_gaps_sum" ]
2
[ [ "prime_gaps_sum", "sieve" ] ]
1
[]
false
[]
false
pytest
true
[]
true
b8b8ce378f8702f2f2eb9c3ddab52826c61ee3b0
dbb0737acea00552e47c2d5e8ded371d543ebb0b
v1.0
instruct
Codeforces
Codeforces_9543_I
You are given an integer array $$$a$$$ of size $$$n$$$ and an integer $$$k$$$. Your task is to find the length of the longest contiguous subarray such that the sum of the subarray is less than or equal to $$$k$$$. For example, if the array is $$$[1, 2, 3, 4, 5]$$$ and $$$k = 10$$$, the longest subarray would be $$$[1,...
def longest_subarray_with_sum_leq_k(a, k): n = len(a) max_length = 0 current_sum = 0 start = 0 for end in range(n): current_sum += a[end] while current_sum > k: current_sum -= a[start] start += 1 max_length = max(max_length, end - st...
from solution import main def test_example_cases(): input_data = """3 5 10 1 2 3 4 5 5 14 2 2 2 7 7 5 15 1 2 3 4 5""" expected_output = [4, 4, 5] assert main(input_data) == expected_output def test_edge_cases(): input_data = """2 1 1 1 1 1000000000 1000000000""" expected_output = [1, 1] assert...
[ { "docstring": null, "function_declaration": "def longest_subarray_with_sum_leq_k(a, k):", "function_name": "longest_subarray_with_sum_leq_k", "parameter_list": "(a, k)" }, { "docstring": null, "function_declaration": "def solve(test_cases):", "function_name": "solve", "parameter...
[ 1, 0, 0, 0, 1, 0, 0, 0, 0, 0 ]
2
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def longest_subarray_with_sum_leq_k(a, k):\n n = len(a)\n max_length = 0\n current_sum = 0\n start = 0\n\n for end in range(n):\n curren...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00009543", "row_id": 9543, "seed_ids": "[2129]" }
0.760275
Codeforces_9543
I
[ "longest_subarray_with_sum_leq_k", "solve", "parse_input", "main" ]
4
[ [ "solve", "longest_subarray_with_sum_leq_k" ] ]
1
[ "parse_input" ]
false
[]
false
pytest
true
[]
true
46707fac1c4cbec74808a5a6d50652c80b8366c9
9d2923d83742e493bf147ec4fb8bb45656b3c180
v1.0
instruct
Codeforces
Codeforces_9566_I
Polycarp has decided to organize his bookshelf. He wants to arrange his collection of books in a straight line on a single shelf. He has a total of $$$m$$$ books, each with a specific height. Polycarp can perform one type of operation: swap any two books that are next to each other on the shelf. Each swap operation ha...
def count_inversions(arr): """ Count the number of inversions required to sort the array using a modified merge sort. """ # Helper function to merge two halves and count inversions def merge_and_count(arr, temp_arr, left, mid, right): i = left # Starting index for left subarray j ...
from solution import min_swaps_to_sort_books def test_single_book(): assert min_swaps_to_sort_books([1]) == 0 def test_sorted_books(): assert min_swaps_to_sort_books([1, 2, 3, 4, 5]) == 0 def test_reverse_sorted_books(): assert min_swaps_to_sort_books([5, 4, 3, 2, 1]) == 10 def test_random_order_books()...
[ { "docstring": "Count the number of inversions required to sort the array using a modified merge sort.", "function_declaration": "def count_inversions(arr):", "function_name": "count_inversions", "parameter_list": "(arr)" }, { "docstring": "Returns the minimum number of swap operations requi...
[ 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 minimum_swaps_to_sort(books):\n \"\"\"\n Returns the minimum number of swap operations required to sort the books in non-decreasing order of their h...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00009566", "row_id": 9566, "seed_ids": "[7861]" }
0.597305
Codeforces_9566
I
[ "count_inversions", "min_swaps_to_sort_books" ]
2
[ [ "min_swaps_to_sort_books", "count_inversions" ] ]
1
[]
false
[]
false
pytest
true
[]
true
3a897f7ab8b2e7fb01a1d9b6679da122956b7488
cb2cb77a59a5ec22987653ffc2cc9060ef8db494
v1.0
instruct
Codeforces
Codeforces_9626_I
A company produces a new type of smart vehicle capable of both ground and aerial movement. The vehicle switches its mode of movement based on the shortest path calculation from its current location to the target. On ground mode, it adheres to the typical road network, and in aerial mode, it can move in a straight line ...
import heapq from math import sqrt def euclidean_distance(x1, y1, x2, y2): return sqrt((x2 - x1)**2 + (y2 - y1)**2) def minimum_travel_cost(n, m, coordinates, edges, s, t): graph = {i: [] for i in range(n)} for u, v, w in edges: graph[u-1].append((v-1, w)) graph[v-1].append((u-1, w)) ...
from solution import main def test_example_case(): input_data = """6 7 0 0 2 2 4 4 6 6 8 8 10 10 1 2 3 1 3 10 2 3 2 2 4 8 3 5 2 4 5 3 5 6 1 1 6""" assert main(input_data) == 8 def test_no_edges(): input_data = """2 0 0 0 1 1 1 2""" assert main(input_data) == 1 # Direct aerial distance def test_singl...
[ { "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 minimum_travel_cost(n, m, coordinates, edges, s, t):", "function_na...
[ 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 minimum_travel_cost(n, m, coord...
trial_gpt4o_3
{ "original_instruction": "", "prompt_id": "00009626", "row_id": 9626, "seed_ids": "[7086]" }
0.700722
Codeforces_9626
I
[ "euclidean_distance", "minimum_travel_cost", "main" ]
3
[ [ "minimum_travel_cost", "euclidean_distance" ] ]
1
[]
false
[]
false
pytest
true
[]
true
d7bffde3b7ac4dbe3d99c348cc662024561cb3a5
fc658cfad26c640504b64b7ebecb5d6d6675539b
v1.0
instruct
Codeforces
Codeforces_9651_I
ally has received a new lesson in mathematics class about the number system. Her teacher taught her about prime numbers and palindromic numbers and gave her a challenge to merge these concepts. A number is called prime if it has only two distinct divisors: 1 and itself. A number is called palindromic if it reads the s...
def is_palindromic(num): """ Returns True if the given num is palindromic, False otherwise. """ return str(num) == str(num)[::-1] def sieve_of_eratosthenes(n): """ Generates a list of booleans representing prime status for numbers from 0 to n. True means prime, False means not prime. ""...
from solution import is_palindromic, sieve_of_eratosthenes, count_prime_palindromic def test_is_palindromic(): assert is_palindromic(121) == True assert is_palindromic(123) == False assert is_palindromic(11) == True assert is_palindromic(7) == True def test_sieve_of_eratosthenes(): primes = sieve_...
[ { "docstring": "Returns True if the given num is palindromic, False otherwise.", "function_declaration": "def is_palindromic(num):", "function_name": "is_palindromic", "parameter_list": "(num)" }, { "docstring": "Generates a list of booleans representing prime status for numbers from 0 to n....
[ 0, 0, 0, 0, 0, 0, 0, 0, 1, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(n):\n if n <= 1:\n return False\n if n == 2:\n return True\n if n % 2 == 0:\n return False\n for i in range(3, i...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00009651", "row_id": 9651, "seed_ids": "[623]" }
0.649859
Codeforces_9651
I
[ "is_palindromic", "sieve_of_eratosthenes", "count_prime_palindromic" ]
3
[ [ "count_prime_palindromic", "is_palindromic" ], [ "count_prime_palindromic", "sieve_of_eratosthenes" ] ]
2
[]
false
[]
false
pytest
true
[]
true
f4e5b156ca805946e60ef425d75f4ced3e797842
8e41d11d5e673300a17c5c240f7ff29e48a08e92
v1.0
instruct
Codeforces
Codeforces_9667_I
You are helping to develop a software application that calculates the tax for various items in a store. The store applies different tax rates for different categories of items. Given an item category and its price, your task is to compute the final price after applying the respective tax rate. The tax rates are fixed a...
def calculate_final_price(category, price): """ Given a category and its price, calculate the final price after tax. """ tax_rates = { "Food": 0.05, "Electronics": 0.12, "Clothing": 0.08, "Other": 0.10 } tax_rate = tax_rates.get(category, 0) final_price =...
from solution import calculate_final_price, process_items def test_food(): assert calculate_final_price("Food", 100.00) == 105.00 def test_electronics(): assert calculate_final_price("Electronics", 220.00) == 246.40 def test_clothing(): assert calculate_final_price("Clothing", 150.00) == 162.00 def test...
[ { "docstring": "Given a category and its price, calculate the final price after tax.", "function_declaration": "def calculate_final_price(category, price):", "function_name": "calculate_final_price", "parameter_list": "(category, price)" }, { "docstring": null, "function_declaration": "d...
[ 0, 0, 0, 0, 1, 0, 1, 1, 1, 0 ]
4
medium
0.4
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def calculate_final_price(n, items):\n \"\"\"\n Calculates the final price after applying tax based on the category.\n \n :param n: integer, numbe...
trial_gpt4o_7
{ "original_instruction": "", "prompt_id": "00009667", "row_id": 9667, "seed_ids": "[6708]" }
0.670854
Codeforces_9667
I
[ "calculate_final_price", "process_items" ]
2
[ [ "process_items", "calculate_final_price" ] ]
1
[]
false
[]
false
pytest
true
[]
true
0f96a1110c347cea6c12f6e8f7f5bd461c6d20d7
dc411b078100b4a6453175ce0d6c8215a52d5f23
v1.0
instruct
Codeforces
Codeforces_9716_I
You are given a tree with `n` nodes and `n-1` edges. A tree is a connected undirected graph with no cycles. You are also given an integer `k` and a list of `k` pairs of distinct nodes `(xi, yi)`. For each pair, you are asked to find the length of the shortest path between nodes `xi` and `yi`. The first line contains ...
from collections import deque, defaultdict def bfs(tree, n, start): """ Perform a breadth-first search (BFS) on the tree and return the distance from the start node to all other nodes. """ distances = [-1] * (n + 1) distances[start] = 0 queue = deque([start]) while queue: ...
def test_bfs(): edges = [(1, 2), (1, 3), (2, 4), (2, 5)] tree = defaultdict(list) for u, v in edges: tree[u].append(v) tree[v].append(u) assert bfs(tree, 5, 1) == [-1, 0, 1, 1, 2, 2] assert bfs(tree, 5, 2) == [-1, 1, 0, 2, 1, 1] assert bfs(tree, 5, 3) == [-1, 1, 2, 0, 3, 3] def ...
[ { "docstring": "Perform a breadth-first search (BFS) on the tree and return the \ndistance from the start node to all other nodes.", "function_declaration": "def bfs(tree, n, start):", "function_name": "bfs", "parameter_list": "(tree, n, start)" }, { "docstring": "Find the shortest path leng...
[ 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 collections import deque\n\ndef bfs_shortest_path(tree, start, end):\n \"\"\"\n Finds the shortest path between start and end nodes in an unweighte...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00009716", "row_id": 9716, "seed_ids": "[3028]" }
0.744865
Codeforces_9716
I
[ "bfs", "find_shortest_paths", "find_lca" ]
3
[ [ "find_shortest_paths", "bfs" ], [ "find_shortest_paths", "find_lca" ] ]
2
[]
false
[]
false
pytest
false
[]
true
ed7da12423401819efe7e1443e914c55803c7372
5bb799787dfc5ac6d5674797ae939cb4095745ba
v1.0
instruct
Codeforces
Codeforces_9755_I
A city contains $$$n$$$ intersections and between some of them, there are bidirectional roads. It is possible to travel between any two intersections by going through one or more roads. Each road has a toll associated with it. A police officer wants to select exactly $$$k$$$ roads such that the sum of tolls of the sele...
def find(parent, i): if parent[i] == i: return i else: parent[i] = find(parent, parent[i]) return parent[i] def union(parent, rank, x, y): root_x = find(parent, x) root_y = find(parent, y) if root_x != root_y: if rank[root_x] < rank[root_y]: parent[root_x...
def test_example_case(): n = 6 m = 9 k = 3 edges = [(1, 2, 5), (1, 3, 3), (2, 3, 6), (2, 4, 2), (3, 4, 4), (3, 5, 8), (4, 5, 7), (4, 6, 1), (5, 6, 9)] assert solution(n, m, k, edges) == 6 def test_two_intersections_one_needed(): n = 2 m = 1 k = 1 edges = [(1, 2, 10)] ...
[ { "docstring": null, "function_declaration": "def find(parent, i):", "function_name": "find", "parameter_list": "(parent, i)" }, { "docstring": null, "function_declaration": "def union(parent, rank, x, y):", "function_name": "union", "parameter_list": "(parent, rank, x, y)" }, ...
[ 0, 0, 0, 0, 0, 1, 0, 0, 0 ]
1
hard
0.111
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def find(parent, x):\n if parent[x] == x:\n return x\n else:\n parent[x] = find(parent, parent[x])\n return parent[x]\n\ndef union(...
trial_gpt4o_5
{ "original_instruction": "", "prompt_id": "00009755", "row_id": 9755, "seed_ids": "[7775]" }
0.715139
Codeforces_9755
I
[ "find", "union", "minimum_toll", "solution" ]
4
[ [ "minimum_toll", "find" ], [ "minimum_toll", "union" ], [ "solution", "minimum_toll" ], [ "union", "find" ] ]
4
[]
false
[]
false
pytest
false
[]
true
36235e24b3b5552601dce845b6f3026541387f5b
11630faf2f580008f9bee1bb673b7e492ec8c96b
v1.0
instruct
Codeforces
Codeforces_9778_I
You are given an array of integers with `n` elements and a series of `m` queries. Each query consists of two integers `L` and `R`. For each query, you are asked to find the sum of the integers in the subarray defined by the bounds `L` and `R` inclusive. Your task is to efficiently handle these queries using a preproce...
def preprocess_prefix_sum(arr): """ Preprocesses the input array to generate a prefix sum array. """ n = len(arr) prefix_sum = [0] * (n + 1) for i in range(1, n + 1): prefix_sum[i] = prefix_sum[i - 1] + arr[i - 1] return prefix_sum def range_sum(prefix_sum, L, R): """ Return...
from solution import preprocess_prefix_sum, range_sum, process_queries def test_preprocess_prefix_sum(): assert preprocess_prefix_sum([1, 2, 3, 4, 5]) == [0, 1, 3, 6, 10, 15] assert preprocess_prefix_sum([0, -1, 2, -3, 4]) == [0, 0, -1, 1, -2, 2] def test_range_sum(): prefix_sum = preprocess_prefix_sum([1...
[ { "docstring": "Preprocesses the input array to generate a prefix sum array.", "function_declaration": "def preprocess_prefix_sum(arr):", "function_name": "preprocess_prefix_sum", "parameter_list": "(arr)" }, { "docstring": "Returns the sum of the subarray from L to R using the prefix sum ar...
[ 1, 1, 0, 0, 1, 1, 0, 1, 1, 1 ]
7
easy
0.7
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def preprocess_prefix_sums(array):\n \"\"\"\n Preprocess the array to compute prefix sums.\n \n Parameters:\n array (list of int): The array of...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00009778", "row_id": 9778, "seed_ids": "[110]" }
0.731655
Codeforces_9778
I
[ "preprocess_prefix_sum", "range_sum", "process_queries" ]
3
[ [ "process_queries", "preprocess_prefix_sum" ], [ "process_queries", "range_sum" ] ]
2
[ "process_queries" ]
false
[]
false
pytest
true
[]
true
dbece19d477a304f6c54545c152c2194ccece71a
55bab59c2d1e23bd6331e40d36ff87a997c5997b
v1.0
instruct
Codeforces
Codeforces_9785_I
The company you work for has decided to host an internal hackathon to boost employee engagement and innovation. As part of the competition, one of the challenges presented is to solve the "magic square" problem. A "magic square" is a 3x3 grid filled with distinct integers from 1 to 9 such that the sum of the numbers i...
def is_magic_square(grid): """ Check if a 3x3 grid is a magic square. """ s = sum(grid[0]) for i in range(3): if sum(grid[i]) != s or sum(grid[j][i] for j in range(3)) != s: return False if sum(grid[i][i] for i in range(3)) != s or sum(grid[i][2-i] for i in range(3)) != s: ...
from solution import solve_magic_square def test_solve_magic_square_case_1(capsys): input_string = "8 1 6 3 5 0 4 9 0" solve_magic_square(input_string) captured = capsys.readouterr() assert captured.out == '8 1 6\n3 5 7\n4 9 2\n' def test_solve_magic_square_case_2(capsys): input_string = "5 3 4 1 ...
[ { "docstring": "Check if a 3x3 grid is a magic square.", "function_declaration": "def is_magic_square(grid):", "function_name": "is_magic_square", "parameter_list": "(grid)" }, { "docstring": null, "function_declaration": "def find_magic_square(grid):", "function_name": "find_magic_s...
[ 1, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_magic_square(grid):\n \"\"\"\n Check if a 3x3 grid is a magic square.\n \"\"\"\n s = sum(grid[0])\n for i in range(3):\n if sum(g...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00009785", "row_id": 9785, "seed_ids": "[2653]" }
0.675701
Codeforces_9785
I
[ "is_magic_square", "find_magic_square", "solve_magic_square" ]
3
[ [ "find_magic_square", "is_magic_square" ], [ "solve_magic_square", "find_magic_square" ] ]
2
[]
false
[]
false
pytest
true
[]
true
b4a9128a235300af1561e17939b3a41dc6e63e57
4914658e8b8df588dc999a502c522ed4bbda364b
v1.0
instruct
Codeforces
Codeforces_9832_I
You are given an array of $$$n$$$ integers. You have to process multiple queries on this array. For each query, you will be given two integers $$$l$$$ and $$$r$$$. Your task is to find the sum of all the elements from index $$$l$$$ to index $$$r$$$, inclusive. The first line contains two integers $$$n$$$ and $$$q$$$ $...
def compute_prefix_sums(arr): """ Computes and returns the prefix sums array for arr. """ 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 range_sum(prefix_sums, l, r): """ Returns the range sum from i...
from solution import compute_prefix_sums, range_sum, process_queries def test_compute_prefix_sums(): assert compute_prefix_sums([1, 2, 3, 4, 5]) == [0, 1, 3, 6, 10, 15] assert compute_prefix_sums([2, 4, 6, 8]) == [0, 2, 6, 12, 20] assert compute_prefix_sums([5, 5, 5, 5]) == [0, 5, 10, 15, 20] def test_ran...
[ { "docstring": "Computes and returns the prefix sums array for arr.", "function_declaration": "def compute_prefix_sums(arr):", "function_name": "compute_prefix_sums", "parameter_list": "(arr)" }, { "docstring": "Returns the range sum from index l to r using the prefix sums array.", "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 prefix_sum_array(arr):\n \"\"\"\n Given an array, this function computes the prefix sum array.\n \"\"\"\n prefix_sum = [0] * (len(arr) + 1) #...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00009832", "row_id": 9832, "seed_ids": "[7385]" }
0.716619
Codeforces_9832
I
[ "compute_prefix_sums", "range_sum", "process_queries" ]
3
[ [ "process_queries", "compute_prefix_sums" ], [ "process_queries", "range_sum" ] ]
2
[ "process_queries" ]
false
[]
false
pytest
true
[]
true
e1e11c1e3e37a095005b546ed04cd1b1744a8971
77138c139c9f783c85e72bad463a0da353eb2798
v1.0
instruct
Codeforces
Codeforces_9898_I
In a kingdom far away, there are n cities connected by several bidirectional roads. The king has decided to celebrate the kingdom's prosperity by organizing a series of grand parades. Each city must host exactly one parade, and the parade must start in some city and travel through one or more cities before ending at th...
from collections import defaultdict # Function to find all cycles in an undirected graph def find_cycles(n, roads): adj_list = defaultdict(list) for u, v in roads: adj_list[u].append(v) adj_list[v].append(u) def dfs(v, parent, visited, path): nonlocal cycle_count visited[v]...
from solution import count_unique_parade_paths def test_example_case(): assert count_unique_parade_paths(4, 5, [(1, 2), (2, 3), (3, 4), (4, 1), (1, 3)]) == 3 def test_no_cycle(): assert count_unique_parade_paths(3, 2, [(1, 2), (2, 3)]) == 0 def test_single_cycle(): assert count_unique_parade_paths(4, 4, ...
[ { "docstring": null, "function_declaration": "def find_cycles(n, roads):", "function_name": "find_cycles", "parameter_list": "(n, roads)" }, { "docstring": null, "function_declaration": "def count_unique_parade_paths(n, m, roads):", "function_name": "count_unique_parade_paths", "...
[ 0, 0, 0, 0, 0, 0, 0, 1, 0 ]
1
hard
0.111
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def count_unique_parades(n, m, roads):\n from collections import defaultdict, deque\n\n def dfs(node, parent, visited, depth):\n if depth == 2:\n...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00009898", "row_id": 9898, "seed_ids": "[6386]" }
0.687106
Codeforces_9898
I
[ "find_cycles", "count_unique_parade_paths" ]
2
[ [ "count_unique_parade_paths", "find_cycles" ] ]
1
[]
false
[]
false
pytest
true
[]
true
98e22f6fb914edda4fe2be3a43535c9244cb4961
132f5e2b75af0866fb08e1b97251b17bffadf439
v1.0
instruct
Codeforces
Codeforces_9958_I
You are given a sequence of integers which may or may not contain duplicates. Your task is to find the length of the longest subsequence that can be obtained by deleting some (possibly zero) elements and in which every element is a power of two (i.e., elements that are 1, 2, 4, 8, 16, ...). A subsequence of a sequence...
def is_power_of_two(x): """ Helper function that checks if a number is a power of two. """ return (x != 0) and ((x & (x - 1)) == 0) def longest_subsequence_power_of_two(arr): """ Returns the length of the longest subsequence consisting only of elements which are powers of two. """ power...
from solution import is_power_of_two, longest_subsequence_power_of_two def test_is_power_of_two(): assert is_power_of_two(1) == True assert is_power_of_two(2) == True assert is_power_of_two(3) == False assert is_power_of_two(4) == True assert is_power_of_two(5) == False assert is_power_of_two(8...
[ { "docstring": "Helper function that checks if a number is a power of two.", "function_declaration": "def is_power_of_two(x):", "function_name": "is_power_of_two", "parameter_list": "(x)" }, { "docstring": "Returns the length of the longest subsequence consisting only of elements which are p...
[ 1, 0, 0, 0, 1, 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": "def longest_power_of_two_subsequence_length(n, sequence):\n \"\"\"\n Returns the length of the longest subsequence consisting of elements that are power...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00009958", "row_id": 9958, "seed_ids": "[7988]" }
0.760924
Codeforces_9958
I
[ "is_power_of_two", "longest_subsequence_power_of_two" ]
2
[ [ "longest_subsequence_power_of_two", "is_power_of_two" ] ]
1
[]
false
[]
false
pytest
true
[]
true
156664b8bb1f4d6468e1c87e61acdd7b9558106a
74d942c76cedefc7312ca1ee039c36c804033586
v1.0
instruct
Codeforces
Codeforces_9961_I
You are given a directed graph with `n` nodes and `m` edges. Each node is labeled from `1` to `n`. The graph consists of multiple isolated strongly connected components (SCCs), and each SCC contains a path of nodes that leads from its start node to its end node, possibly forming cycles. You are given the start nodes of...
from collections import defaultdict, deque import sys sys.setrecursionlimit(200000) def find_sccs(n, graph): def dfs(node, index, stack, indices, lowlinks, on_stack, sccs): indices[node] = index lowlinks[node] = index index += 1 stack.append(node) on_stack[node] = True ...
from solution import longest_path_in_scc def test_example(): assert longest_path_in_scc(6, [(1, 2), (2, 3), (3, 1), (4, 5), (5, 6), (6, 4), (2, 5)]) == 3 def test_single_node_graph(): assert longest_path_in_scc(1, []) == 0 def test_no_edges(): assert longest_path_in_scc(5, []) == 0 def test_single_scc()...
[ { "docstring": null, "function_declaration": "def find_sccs(n, graph):", "function_name": "find_sccs", "parameter_list": "(n, graph)" }, { "docstring": null, "function_declaration": "def compute_longest_path_in_scc(graph, nodes):", "function_name": "compute_longest_path_in_scc", ...
[ 0, 0, 0, 0, 0, 0, 0, 0, 1, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "from collections import defaultdict, deque\n\ndef kosaraju(n, edges):\n def dfs(graph, node, visited, stack):\n visited[node] = True\n for ne...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00009961", "row_id": 9961, "seed_ids": "[1476]" }
0.597096
Codeforces_9961
I
[ "find_sccs", "compute_longest_path_in_scc", "longest_path_in_scc" ]
3
[ [ "longest_path_in_scc", "compute_longest_path_in_scc" ], [ "longest_path_in_scc", "find_sccs" ] ]
2
[]
false
[]
false
pytest
true
[]
true
f743350a306fd8a150a24a290f5c40d6204ca191
8b1be6744ee5f45707bb5296cab1a686885a22ba
v1.0
instruct
Codeforces
Codeforces_9995_I
You are given a rectangular garden represented by a grid of size $$$N \times M$$$ (1 ≤ $$$N, M$$$ ≤ 1000). Each cell in the grid can either be a plant (represented by 'P') or an obstacle (represented by 'O'). The garden can be divided into rectangular regions such that each region does not include any obstacle. Your t...
def largest_plant_region(garden): if not garden: return 0 max_area = 0 rows = len(garden) cols = len(garden[0]) heights = [0] * cols for r in range(rows): for c in range(cols): if garden[r][c] == 'P': heights[c] += 1 else...
def test_largest_plant_region(): assert largest_plant_region([]) == 0 assert largest_plant_region([['P']]) == 1 assert largest_plant_region([['P', 'P'], ['P', 'P']]) == 4 assert largest_plant_region([['P', 'O'], ['O', 'P']]) == 1 assert largest_plant_region([['P', 'P', 'O', 'P', 'P'], ['P', 'P', 'P'...
[ { "docstring": null, "function_declaration": "def largest_plant_region(garden):", "function_name": "largest_plant_region", "parameter_list": "(garden)" }, { "docstring": null, "function_declaration": "def max_histogram_area(heights):", "function_name": "max_histogram_area", "para...
[ 1, 0, 1, 0, 1, 1, 1, 1, 1 ]
7
easy
0.778
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def maximalRectangle(garden):\n if not garden:\n return 0\n \n n = len(garden)\n m = len(garden[0])\n heights = [0] * m\n max_area = ...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00009995", "row_id": 9995, "seed_ids": "[933]" }
0.617399
Codeforces_9995
I
[ "largest_plant_region", "max_histogram_area" ]
2
[ [ "largest_plant_region", "max_histogram_area" ] ]
1
[]
false
[]
false
pytest
false
[]
true
4b8547b9a87a3283b166248dbf87d1d26224037b
34a87997d77a806b8db008eaf422e5f02e16643b
v1.0
instruct
Codeforces
Codeforces_10004_I
Design a function that takes a list of integers and returns a new list with the same elements but with all prime numbers shifted to the end of the list, while preserving the order of the non-prime and prime numbers among themselves. ### Function Signature ```python def shift_primes_to_end(arr: list) -> list: pass...
from math import isqrt def is_prime(n): """ Helper function to check if a number is prime. """ if n <= 1: return False if n <= 3: return True if n % 2 == 0 or n % 3 == 0: return False for i in range(5, isqrt(n) + 1, 6): if n % i == 0 or n % (i + 2) == 0: ...
from solution import shift_primes_to_end def test_shift_primes_to_end_case_1(): arr = [7, 6, 5, 4, 3, 2] assert shift_primes_to_end(arr) == [6, 4, 7, 5, 3, 2] def test_shift_primes_to_end_case_2(): arr = [2, 3, 5, 8, 11, 13, 17, 19, 7, 4] assert shift_primes_to_end(arr) == [8, 4, 2, 3, 5, 11, 13, 17, ...
[ { "docstring": "Helper function to check if a number is prime.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Shifts all prime numbers to the end of the list while preserving the \norder of the non-prime and prime numbers...
[ 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 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_9
{ "original_instruction": "", "prompt_id": "00010004", "row_id": 10004, "seed_ids": "[4611]" }
0.670712
Codeforces_10004
I
[ "is_prime", "shift_primes_to_end" ]
2
[ [ "shift_primes_to_end", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
f2df6ac91494e15388bbad27db91c52c7e04ed0f
2712783bf393e2f4941372c5f5e46a96c4b7bcfc
v1.0
instruct
Codeforces
Codeforces_10015_I
You are given a sequence of `n` integers, `a1, a2, ..., an`. You have to perform the following operations exactly once: 1. Choose any two indices `i` and `j` (1 ≤ i ≤ j ≤ n) and reverse the subsequence from `i` to `j`. Your task is to determine the maximum possible length of the longest increasing subsequence (LIS) o...
def find_lis_length(arr): n = len(arr) lis = [1] * n for i in range(1, n): for j in range(i): if arr[i] > arr[j] and lis[i] < lis[j] + 1: lis[i] = lis[j] + 1 return max(lis) def max_lis_after_one_reverse(n, arr): max_lis = 0 for i in range(n): for j i...
from solution import solve def test_case_1(): test_cases = [ (5, [1, 2, 5, 3, 4]), # Example 1 (6, [4, 3, 2, 1, 6, 5]), # Example 2 ] expected_output = [4, 5] assert solve(test_cases) == expected_output def test_case_2(): test_cases = [ (3, [1, 3, 2]), ...
[ { "docstring": null, "function_declaration": "def find_lis_length(arr):", "function_name": "find_lis_length", "parameter_list": "(arr)" }, { "docstring": null, "function_declaration": "def max_lis_after_one_reverse(n, arr):", "function_name": "max_lis_after_one_reverse", "paramet...
[ 1, 0, 0, 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 find_lis_length(arr):\n \"\"\"\n Helper function to find the length of the Longest\n Increasing Subsequence in the given array.\n \"\"\"\n ...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00010015", "row_id": 10015, "seed_ids": "[4569]" }
0.789237
Codeforces_10015
I
[ "find_lis_length", "max_lis_after_one_reverse", "solve" ]
3
[ [ "max_lis_after_one_reverse", "find_lis_length" ], [ "solve", "max_lis_after_one_reverse" ] ]
2
[]
false
[]
false
pytest
true
[]
true
f0611e6582131ccd8a328c81ad733b6ef737ceb2
a8cd695f5932ca3f1cedc4bc86952c9dc382ad55
v1.0
instruct
Codeforces
Codeforces_10031_I
In a magical kingdom, there are n castles connected by m roads. Each road has a certain length, and exactly one road exists between each pair of castles. The kingdom's ruler, King Arnav, wants to organize a grand parade that can pass through the roads in the kingdom. However, King Arnav wishes to optimize the parade r...
def kruskal_minimum_spanning_tree(n, roads): parent = list(range(n)) rank = [0] * n def find(node): if parent[node] != node: parent[node] = find(parent[node]) return parent[node] def union(node1, node2): root1 = find(node1) root2 = find(node2) ...
from solution import minimal_parade_length def test_minimal_parade_length_example(): n = 4 m = 5 roads = [ (1, 2, 3), (2, 3, 4), (3, 4, 2), (4, 1, 6), (1, 3, 5) ] assert minimal_parade_length(n, m, roads) == 9 def test_minimal_parade_length_single_road(): ...
[ { "docstring": null, "function_declaration": "def kruskal_minimum_spanning_tree(n, roads):", "function_name": "kruskal_minimum_spanning_tree", "parameter_list": "(n, roads)" }, { "docstring": null, "function_declaration": "def minimal_parade_length(n, m, road_data):", "function_name"...
[ 0, 0, 1, 1, 1, 0, 0, 0, 1 ]
4
medium
0.444
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def find_minimal_parade_length(n, m, roads):\n \"\"\"\n Returns the minimal total length of the roads required for the parade\n using Prim's algorith...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00010031", "row_id": 10031, "seed_ids": "[4734]" }
0.749763
Codeforces_10031
I
[ "kruskal_minimum_spanning_tree", "minimal_parade_length" ]
2
[ [ "minimal_parade_length", "kruskal_minimum_spanning_tree" ] ]
1
[]
false
[]
false
pytest
true
[]
true
e3b0f3be5c76fc2b408ee1f2b5f8ead15bdada7c
5a1257653cb2e7eda7874ebf877423dc02d8af78
v1.0
instruct
Codeforces
Codeforces_10074_I
Given a connected undirected graph with N nodes and M edges, where each node has a certain value associated with it, you need to find the maximum value of the total weight of any path in the graph. A path can be defined as a sequence of edges connecting a sequence of vertices, where each edge is used at most once. The...
from collections import defaultdict import sys def dfs(node, graph, values, visited): visited[node] = True max_total_weight = values[node - 1] max_individual_path = 0 for neighbor in graph[node]: if not visited[neighbor]: weight = dfs(neighbor, graph, values, visited) ...
from solution import max_total_weight def test_single_path(): N = 5 M = 4 values = [3, 2, 1, 4, 5] edges = [(1, 2), (2, 3), (3, 4), (4, 5)] assert max_total_weight(N, M, values, edges) == 15 def test_multiple_paths(): N = 4 M = 4 values = [1, 2, 3, 4] edges = [(1, 2), (2, 3), (3, 4...
[ { "docstring": null, "function_declaration": "def dfs(node, graph, values, visited):", "function_name": "dfs", "parameter_list": "(node, graph, values, visited)" }, { "docstring": null, "function_declaration": "def max_total_weight(N, M, values, edges):", "function_name": "max_total_...
[ 0, 0, 1, 0, 1, 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 max_path_sum(N, M, values, edges):\n from collections import defaultdict, deque\n \n def bfs_max_path(adj, values, start):\n visited = [Fa...
trial_gpt4o_5
{ "original_instruction": "", "prompt_id": "00010074", "row_id": 10074, "seed_ids": "[2963]" }
0.76253
Codeforces_10074
I
[ "dfs", "max_total_weight" ]
2
[ [ "max_total_weight", "dfs" ] ]
1
[]
false
[]
false
pytest
true
[]
true
f1e6b2c6d6a788e9090ebb28b1b029e4858fe238
cfb239bdd2fa63b78e12a5cb2a7c6b4c7ec7c4a1
v1.0
instruct
Codeforces
Codeforces_10090_I
Mary loves playing the game "Guess the Word". She has a friend who will think of a secret word, and she will try to guess it. The secret word is always a single lowercase English word and has a length of exactly `n`. For each guessed word, her friend will provide her with feedback in the form of two numbers: the number...
from typing import List def get_feedback(guess: str, secret: str) -> (int, int): correct_positions = sum(g == s for g, s in zip(guess, secret)) wrong_positions = sum(min(guess.count(c), secret.count(c)) for c in set(guess)) - correct_positions return correct_positions, wrong_positions def find_secret_word...
from solution import find_secret_word def test_secret_at_beginning(): secret = "acckzz" wordlist = ["acckzz","ccbazz","eiowzz","abcczz"] assert find_secret_word(secret, wordlist) == "acckzz" def test_secret_in_middle(): secret = "gourmet" wordlist = ["soulful", "gourmet", "testing", "deftest"] ...
[ { "docstring": null, "function_declaration": "def get_feedback(guess, secret):", "function_name": "get_feedback", "parameter_list": "(guess, secret)" }, { "docstring": null, "function_declaration": "def find_secret_word(secret, wordlist):", "function_name": "find_secret_word", "p...
[ 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 get_feedback(guess: str, secret: str) -> (int, int):\n \"\"\"\n Returns the feedback in form of a tuple. The first element is the number of characte...
trial_gpt4o_7
{ "original_instruction": "", "prompt_id": "00010090", "row_id": 10090, "seed_ids": "[7346]" }
0.626386
Codeforces_10090
I
[ "get_feedback", "find_secret_word" ]
2
[ [ "find_secret_word", "get_feedback" ] ]
1
[]
false
[]
false
pytest
true
[]
true
bc6ededd2ff50c47765fb930d1a32f581444d5ed
36174c5f74a233832ef33df7f0fd97df290e86b7
v1.0
instruct
Codeforces
Codeforces_10126_I
You are given a tree with $$$n$$$ nodes (numbered from 1 to $$$n$$$) and $$$n-1$$$ edges. Each node has a value associated with it, given in the array $$$v$$$ of length $$$n$$$, where $$$v_i$$$ represents the value of node $$$i$$$ ($$$1 \leq v_i \leq 10^9$$$). Your task is to find the maximum possible sum of node valu...
import sys from collections import defaultdict sys.setrecursionlimit(200000) def dfs(graph, values, node, parent): max1, max2 = 0, 0 max_chain = 0 for child in graph[node]: if child == parent: continue chain_value = dfs(graph, values, child, node) if chain_value > max1:...
from solution import solve def test_sample_case_1(): input_data = "5\n1 2 3 4 5\n1 2\n2 3\n3 4\n4 5\n" assert solve(input_data) == 15 def test_single_node(): input_data = "1\n42\n" assert solve(input_data) == 42 def test_two_nodes(): input_data = "2\n3 7\n1 2\n" assert solve(input_data) == 10...
[ { "docstring": null, "function_declaration": "def dfs(graph, values, node, parent):", "function_name": "dfs", "parameter_list": "(graph, values, node, parent)" }, { "docstring": null, "function_declaration": "def max_path_sum(n, values, edges):", "function_name": "max_path_sum", ...
[ 0, 1, 0, 0, 0, 0, 0, 0, 0, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def maximum_path_sum(n, values, edges):\n from collections import defaultdict, deque\n\n tree = defaultdict(list)\n \n for u, v in edges:\n ...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00010126", "row_id": 10126, "seed_ids": "[684]" }
0.753382
Codeforces_10126
I
[ "dfs", "max_path_sum", "solve" ]
3
[ [ "max_path_sum", "dfs" ], [ "solve", "max_path_sum" ] ]
2
[]
false
[]
false
pytest
true
[]
true
2eb414e702555b202437fe01e7ef283eb0fa1a8e
27d88f8d50338c56699533eae57c8cd077703198
v1.0
instruct
Codeforces
Codeforces_10172_I
You are given an undirected graph represented by an adjacency list. The graph is guaranteed to be a tree. Your task is to find the longest path in this tree, also known as the diameter of the tree. The diameter of a tree is the longest path between any two nodes. The first line of the input contains a single integer n...
from collections import deque, defaultdict def bfs_find_farthest_node(start, adj): visited = set() queue = deque([(start, 0)]) # (node, distance) visited.add(start) farthest_node = start max_distance = 0 while queue: node, dist = queue.popleft() if dist > max...
from solution import find_tree_diameter def test_example(): n = 5 edges = [ (1, 2), (2, 3), (3, 4), (4, 5) ] assert find_tree_diameter(n, edges) == 4 def test_small_tree(): n = 2 edges = [ (1, 2) ] assert find_tree_diameter(n, edges) == 1 def te...
[ { "docstring": null, "function_declaration": "def bfs_find_farthest_node(start, adj):", "function_name": "bfs_find_farthest_node", "parameter_list": "(start, adj)" }, { "docstring": null, "function_declaration": "def find_tree_diameter(n, edges):", "function_name": "find_tree_diamete...
[ 1, 1, 1, 1, 0, 1, 0, 1, 1, 0 ]
7
easy
0.7
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "from collections import deque\n\ndef find_diameter(n, edges):\n def bfs(start):\n dist = [-1] * n\n dist[start] = 0\n q = deque([start...
trial_gpt4o_7
{ "original_instruction": "", "prompt_id": "00010172", "row_id": 10172, "seed_ids": "[5514]" }
0.669798
Codeforces_10172
I
[ "bfs_find_farthest_node", "find_tree_diameter" ]
2
[ [ "find_tree_diameter", "bfs_find_farthest_node" ] ]
1
[]
false
[]
false
pytest
true
[]
true
9fbd75ccf113c78ee5ee782e9b69ba9d4ee63029
28288777be092aeafb7aec54c4f459dafd40c037
v1.0
instruct
Codeforces
Codeforces_10174_I
You are given a collection of events log data from various servers in a distributed system. Each log entry is a single line in the format "timestamp server_id event_type description". The description can be any string and can include spaces, while the timestamp is in "YYYY-MM-DD hh:mm:ss" format. The server_id is an in...
def process_log_entries(log_entries, server_id): """ Processes log entries and generates a summary report for a specified server_id. :param log_entries: List of log entry strings. :param server_id: Integer representing the server_id for which the summary report is to be generated. :return: Dict...
from solution import generate_summary def test_generate_summary(): log_entries = [ "2023-01-01 12:00:00 1 ERROR Disk full", "2023-01-01 12:05:00 2 INFO Service started", "2023-01-01 12:10:00 1 WARNING CPU load high", "2023-01-01 12:15:00 1 INFO Service started", "2023-01-01 ...
[ { "docstring": "Processes log entries and generates a summary report for a specified server_id.\n\n:param log_entries: List of log entry strings.\n:param server_id: Integer representing the server_id for which the summary report is to be generated.\n:return: Dictionary with the count and last timestamp of each ...
[ 0, 0, 0, 1, 0, 0, 1, 0, 1, 0 ]
3
hard
0.3
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def process_logs(log_entries, target_server_id):\n \"\"\"\n Processes log entries and generates a summary report for the given server_id.\n \n Arg...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00010174", "row_id": 10174, "seed_ids": "[6127]" }
0.614154
Codeforces_10174
I
[ "process_log_entries", "format_summary", "generate_summary" ]
3
[ [ "generate_summary", "format_summary" ], [ "generate_summary", "process_log_entries" ] ]
2
[]
false
[]
false
pytest
true
[]
true
a560d9249a3864bc0fc705fcd1ec979f3e04907d
d9f01080b0ed99f74ffd5b4e16013e097f7e6e71
v1.0
instruct
Codeforces
Codeforces_10219_I
You are given an array of integers $$$a$$$. Your goal is to perform exactly one operation on the array to make it "Nearly Sorted". An array is considered "Nearly Sorted" if each element is either in its correct position, or can be moved to its correct position in exactly one swap. Your task is to determine whether it ...
def can_be_nearly_sorted(n, a): """ Determine whether it is possible to make the array "Nearly Sorted" by swapping exactly one pair of adjacent elements. Parameters: n (int): Length of the array a (list): List of integers representing the array a Returns: str: 'YES' if it is po...
def test_can_be_nearly_sorted_case1(): assert can_be_nearly_sorted(4, [2, 3, 1, 4]) == 'YES' def test_can_be_nearly_sorted_case2(): assert can_be_nearly_sorted(5, [1, 5, 3, 4, 2]) == 'NO' def test_can_be_nearly_sorted_case3(): assert can_be_nearly_sorted(5, [1, 2, 3, 5, 4]) == 'YES' def test_can_be_nearl...
[ { "docstring": "Determine whether it is possible to make the array \"Nearly Sorted\" by swapping\nexactly one pair of adjacent elements.\n\nParameters:\nn (int): Length of the array\na (list): List of integers representing the array a\n\nReturns:\nstr: 'YES' if it is possible, 'NO' otherwise", "function_dec...
[ 1, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def can_be_nearly_sorted(n, a):\n \"\"\"\n Determine whether it is possible to make the array \"Nearly Sorted\" by swapping\n exactly one pair of adj...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00010219", "row_id": 10219, "seed_ids": "[953]" }
0.739997
Codeforces_10219
I
[ "can_be_nearly_sorted", "is_nearly_sorted" ]
2
[ [ "can_be_nearly_sorted", "is_nearly_sorted" ] ]
1
[]
false
[]
false
pytest
false
[]
true
10ae1600ceda86a10e5122a57925d0c1c508b05c
930af24d4c7ca8da435ef8e30b651bf3a216130d
v1.0
instruct
Codeforces
Codeforces_10230_I
A company wishes to implement a special performance review system for its employees. Each employee has a number of recorded performance metrics for a given month, and each metric is an integer value. The system should identify and reward consistency among employees' performances. In particular, an employee is conside...
def is_consistent(differences): """ Helper function to determine if the list of differences are all the same. """ return all(d == differences[0] for d in differences) def check_consistency(t, data): """ Determine whether each employee's performance metrics are consistent. Parameter...
from solution import check_consistency def test_case_1(): # Single employee with consistent metric input_data = [(4, [-1, 1, 3, 5])] assert check_consistency(1, input_data) == ["Consistent"] def test_case_2(): # Single employee with inconsistent metrics input_data = [(5, [1, 2, 4, 8, 16])] ass...
[ { "docstring": "Helper function to determine if the list of differences are all the same.", "function_declaration": "def is_consistent(differences):", "function_name": "is_consistent", "parameter_list": "(differences)" }, { "docstring": "Determine whether each employee's performance metrics ...
[ 1, 1, 1, 1, 0, 0, 1, 1, 1 ]
7
easy
0.778
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def check_consistency(t, employees_metrics):\n \"\"\"\n Determines whether each employee's performance metrics are consistent.\n \n Parameters:\n ...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00010230", "row_id": 10230, "seed_ids": "[4033]" }
0.623464
Codeforces_10230
I
[ "is_consistent", "check_consistency" ]
2
[ [ "check_consistency", "is_consistent" ] ]
1
[]
false
[]
false
pytest
true
[]
true
d15be9e8c602bb361d468f0d81a944a21ebcd61e
d464371a964bd3713d7f2b943b31a4aee6bce4e3
v1.0
instruct
Codeforces
Codeforces_10232_I
Given a directed graph represented as an adjacency list, determine if there is a cycle in the graph. A cycle is defined as a path that starts and ends at the same vertex, with at least one other vertex involved in the path. ### Input - The first line contains an integer `n` (1 ≤ n ≤ 10^3), the number of vertices in th...
def detect_cycle(n, m, edges): from collections import defaultdict, deque def dfs(vertex): visited[vertex] = True recursion_stack[vertex] = True for neighbor in adj_list[vertex]: if not visited[neighbor]: if dfs(neighbor): return True ...
import pytest from solution import detect_cycle_from_input def test_no_cycle(): input_data = "4\n3\n1 2\n2 3\n3 4\n" assert detect_cycle_from_input(input_data) == "No cycle" def test_cycle_detected(): input_data = "4\n4\n1 2\n2 3\n3 4\n4 2\n" assert detect_cycle_from_input(input_data) == "Cycle detect...
[ { "docstring": null, "function_declaration": "def detect_cycle(n, m, edges):", "function_name": "detect_cycle", "parameter_list": "(n, m, edges)" }, { "docstring": null, "function_declaration": "def detect_cycle_from_input(input_data):", "function_name": "detect_cycle_from_input", ...
[ 1, 1, 0, 1, 1, 0, 1, 1, 1 ]
7
easy
0.778
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def detect_cycle(n, m, edges):\n from collections import defaultdict\n \n # Create adjacency list\n adjacency_list = defaultdict(list)\n for u,...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00010232", "row_id": 10232, "seed_ids": "[1583]" }
0.708835
Codeforces_10232
I
[ "detect_cycle", "detect_cycle_from_input" ]
2
[ [ "detect_cycle_from_input", "detect_cycle" ] ]
1
[]
false
[]
false
pytest
true
[]
true
9a0a3c8f66be603bb2090c35ab46cbd482e62f11
c8a3df3cb9c599e3bbbdcc31d90f03cc5acb4460
v1.0
instruct
Codeforces
Codeforces_10265_I
Ling just learned about tree data structures and is excited to solve a new problem using her knowledge. She encounters a problem where she needs to determine the longest path between any two nodes in an unweighted tree (a tree in which the edges have no weights). Ling knows that such a path is called the "diameter" of ...
from collections import deque, defaultdict def find_furthest_node(start, graph): """ Performs BFS to find the furthest node from the start node and its distance. """ visited = set() q = deque([(start, 0)]) furthest_node = start max_distance = 0 while q: current, distance = q.po...
from solution import tree_diameter def test_example(): n = 5 edges = [(1, 2), (1, 3), (3, 4), (3, 5)] assert tree_diameter(n, edges) == 3 def test_one_node(): n = 1 edges = [] assert tree_diameter(n, edges) == 0 def test_two_nodes(): n = 2 edges = [(1, 2)] assert tree_diameter(n, ...
[ { "docstring": "Performs BFS to find the furthest node from the start node and its distance.", "function_declaration": "def find_furthest_node(start, graph):", "function_name": "find_furthest_node", "parameter_list": "(start, graph)" }, { "docstring": "Finds the diameter of the tree.", "...
[ 1, 0, 0, 1, 0, 1, 1, 1, 1, 0 ]
6
medium
0.6
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "from collections import deque, defaultdict\n\ndef find_farthest(node, n, graph):\n visited = [False] * (n + 1)\n queue = deque([(node, 0)])\n visited...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00010265", "row_id": 10265, "seed_ids": "[5281]" }
0.718073
Codeforces_10265
I
[ "find_furthest_node", "tree_diameter" ]
2
[ [ "tree_diameter", "find_furthest_node" ] ]
1
[]
false
[]
false
pytest
true
[]
true
201cb6a8d890202d8745ac100f75100450e3fe33
973d2d8d7f9ba0bf3fb7b1b887bd2c64562d978f
v1.0
instruct
Codeforces
Codeforces_10278_I
In a parallel universe, binary trees have an additional constraint. They are constructed with nodes that strictly follow increasing order from the root. Each node's value has to be strictly greater than its parent node’s value, traversing any path from the root. Reversely, deleting nodes from such a binary tree also re...
class TreeNode: def __init__(self, val=0, left=None, right=None): self.val = val self.left = left self.right = right def insert_level_order(arr, root, i, n): # Base case for recursion if i < n: temp = TreeNode(arr[i]) root = temp # insert left child ...
import pytest from solution import cumulative_deletions def test_cumulative_deletions_case1(): arr = [4, 2, 6, 1, 3, 5, 7, 8, 9] deletions = [4, 2, 3, 6] assert cumulative_deletions(arr, deletions) == [4, 6, 9, 15] def test_cumulative_deletions_case2(): arr = [10, 5, 15, 3, 7, 13, 17] deletions = ...
[]
[ 1, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "class TreeNode:\n def __init__(self, val=0, left=None, right=None):\n self.val = val\n self.left = left\n self.right = right\n\ndef in...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00010278", "row_id": 10278, "seed_ids": "[4861]" }
0.670183
Codeforces_10278
I
[ "insert_level_order", "find_max", "delete_node", "cumulative_deletions" ]
4
[ [ "cumulative_deletions", "delete_node" ], [ "cumulative_deletions", "insert_level_order" ], [ "delete_node", "find_max" ] ]
3
[]
false
[ "TreeNode" ]
true
pytest
true
[]
true
b96b7b71440758f43b90a6e6e2dc1124c02e3d81
a4c2f049d5f6f582670686bb6506333fd148dbbc
v1.0
instruct
Codeforces
Codeforces_10312_I
Finn is a curious cat who loves playing with intersections of paths. In his favorite game, the city is represented as a grid of size `m x n`, where some cells are blocked and some are free. Finn has invented a new way of delivering parcels inside the grid by jumping from cell to cell. Finn can move either right or dow...
def count_paths(grid): m = len(grid) n = len(grid[0]) # If the start or end is blocked, return 0 paths if grid[0][0] == '1' or grid[m-1][n-1] == '1': return 0 # Initialize 2D DP array dp = [[0 for _ in range(n)] for _ in range(m)] # Starting position dp[0][0] = 1 ...
from solution import solve def test_two_paths(): m, n = 3, 3 grid_list = [ "0 0 0", "0 1 0", "0 0 0" ] assert solve(m, n, grid_list) == 2 def test_no_path_when_start_blocked(): m, n = 2, 2 grid_list = [ "1 0", "0 0" ] assert solve(m, n, grid_list...
[ { "docstring": null, "function_declaration": "def count_paths(grid):", "function_name": "count_paths", "parameter_list": "(grid)" }, { "docstring": null, "function_declaration": "def solve(m, n, grid_list):", "function_name": "solve", "parameter_list": "(m, n, grid_list)" } ]
[ 0, 1, 1, 0, 1, 1, 0, 1, 1, 0 ]
6
medium
0.6
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def count_paths(grid):\n \"\"\"\n Returns the number of distinct paths from top-left to bottom-right in a grid with blocked cells.\n \"\"\"\n m = ...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00010312", "row_id": 10312, "seed_ids": "[5291]" }
0.752417
Codeforces_10312
I
[ "count_paths", "solve" ]
2
[ [ "solve", "count_paths" ] ]
1
[]
false
[]
false
pytest
true
[]
true
6d743865143f47e477a96bc1c80792ff60a6f1ca
debeb9b6bd0abc20a7840f3fa683571855460e13
v1.0
instruct
Codeforces
Codeforces_10330_I
Liz and her friends love exploring ancient libraries. She has discovered a unique library, which can be represented as an undirected graph. The graph contains nodes $1$ through $n$ representing rooms, connected by $m$ edges representing pathways between the rooms. Each pathway has a length. Liz is currently in room $1...
import heapq def dijkstra(n, adj, start): """ Dijkstra's algorithm to find the shortest distance from start to all other nodes. """ dist = [float('inf')] * (n + 1) dist[start] = 0 pq = [(0, start)] # (distance, node) while pq: d, node = heapq.heappop(pq) if d > dist[node]: ...
def test_find_minimum_distance_to_visit_friends(): assert find_minimum_distance_to_visit_friends(5, 6, [ (1, 2, 1), (1, 3, 2), (2, 3, 2), (2, 4, 1), (3, 5, 1), (4, 5, 2) ], 3, [3, 4, 5]) == 5 # Single edge pathway with no friends assert find_minimum_distance_to_visit_friends(2, 1, [(1, ...
[ { "docstring": "Dijkstra's algorithm to find the shortest distance from start to all other nodes.", "function_declaration": "def dijkstra(n, adj, start):", "function_name": "dijkstra", "parameter_list": "(n, adj, start)" }, { "docstring": null, "function_declaration": "def find_minimum_d...
[ 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 dijkstra(graph, start):\n \"\"\"\n Find the shortest paths from start node to all other nodes using Dijkstra's algorithm.\n \"\"\...
trial_gpt4o_4
{ "original_instruction": "", "prompt_id": "00010330", "row_id": 10330, "seed_ids": "[1246]" }
0.700632
Codeforces_10330
I
[ "dijkstra", "find_minimum_distance_to_visit_friends" ]
2
[ [ "find_minimum_distance_to_visit_friends", "dijkstra" ] ]
1
[]
false
[]
false
pytest
false
[]
true
528c67a12603035d6acb6e7def0cf2dde1709216
df18e2ff7435f2a8a327bff627624eeb02e057d2
v1.0
instruct
Codeforces
Codeforces_10364_I
You are given a string $$$s$$$ consisting of lowercase English letters. Your task is to determine if it is possible to delete exactly one character from the string to make it a palindrome. If it is possible, print "YES", otherwise, print "NO". A string is considered a palindrome if it reads the same forward and backwa...
def can_form_palindrome_by_deleting_one_char(t, test_cases): results = [] for s in test_cases: if is_palindrome(s): results.append("YES") continue found = False length = len(s) for i in range(length): # Remove one charact...
from solution import can_form_palindrome_by_deleting_one_char, is_palindrome def test_is_palindrome(): assert is_palindrome("aba") == True assert is_palindrome("abca") == False assert is_palindrome("a") == True assert is_palindrome("") == True assert is_palindrome("abccba") == True def test_can_fo...
[ { "docstring": null, "function_declaration": "def can_form_palindrome_by_deleting_one_char(t, test_cases):", "function_name": "can_form_palindrome_by_deleting_one_char", "parameter_list": "(t, test_cases)" }, { "docstring": null, "function_declaration": "def is_palindrome(s):", "func...
[ 1, 1, 0, 1, 1, 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": "def can_become_palindrome_by_removing_one_char(s):\n \"\"\"\n Determine if it is possible to delete exactly one character from the string to make it a p...
trial_gpt4o_5
{ "original_instruction": "", "prompt_id": "00010364", "row_id": 10364, "seed_ids": "[483]" }
0.860534
Codeforces_10364
I
[ "can_form_palindrome_by_deleting_one_char", "is_palindrome" ]
2
[ [ "can_form_palindrome_by_deleting_one_char", "is_palindrome" ] ]
1
[]
false
[]
false
pytest
true
[]
true
417b9cb9243e5d597f7932204b371dd07904f996
5e0744a98cfa5a2818a47125c871e6096fcb3856
v1.0
instruct
Codeforces
Codeforces_10365_I
Alex is a skilled horse trainer. His job is to train horses for long-distance races. He wants to ensure that each horse gains maximum endurance by running unique paths in a horse training field represented as an undirected graph with n nodes and m edges. The goal is to pick the maximum number of unique paths starting f...
from collections import defaultdict, deque def bfs_find_path(capacity, source, sink, parent): visited = set() queue = deque([source]) visited.add(source) while queue: node = queue.popleft() for neighbor in capacity[node]: if neighbor not in visited and capacity...
from solution import max_unique_paths def test_example_case(): n, m, y = 5, 6, 3 edges = [(1, 2), (2, 3), (3, 5), (1, 4), (4, 5), (2, 4)] assert max_unique_paths(n, m, y, edges) == 2 def test_no_path_needed(): n, m, y = 5, 6, 0 edges = [(1, 2), (2, 3), (3, 5), (1, 4), (4, 5), (2, 4)] assert ma...
[ { "docstring": null, "function_declaration": "def bfs_find_path(capacity, source, sink, parent):", "function_name": "bfs_find_path", "parameter_list": "(capacity, source, sink, parent)" }, { "docstring": null, "function_declaration": "def ford_fulkerson(graph, source, sink):", "funct...
[ 0, 1, 0, 0, 1, 0, 0, 0, 0 ]
2
hard
0.222
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "from collections import defaultdict, deque\n\ndef max_unique_paths(n, m, y, edges):\n \"\"\"\n Returns the maximum number of unique paths from node 1 to...
trial_gpt4o_4
{ "original_instruction": "", "prompt_id": "00010365", "row_id": 10365, "seed_ids": "[5291]" }
0.643287
Codeforces_10365
I
[ "bfs_find_path", "ford_fulkerson", "max_unique_paths" ]
3
[ [ "ford_fulkerson", "bfs_find_path" ], [ "max_unique_paths", "ford_fulkerson" ] ]
2
[]
false
[]
false
pytest
true
[]
true
087eb09eeb401e17f4aa23a9e54f28b4d59fd944
4db0398c4587fdd044549cf53d8795a6babc3f67
v1.0
instruct
Codeforces
Codeforces_10371_I
Olga is organizing a bookshelf with multiple rows of books. Each book has a unique height. She wants the books in each row to be arranged such that the heights of the books are in non-decreasing order from left to right. To achieve this, Olga can perform the following operation any number of times: choose two adjacent ...
def count_inversions(arr): """ Helper function to count inversions using merge sort. """ if len(arr) < 2: return arr, 0 mid = len(arr) // 2 left, left_inv = count_inversions(arr[:mid]) right, right_inv = count_inversions(arr[mid:]) merged, split_inv = merge_and_count(left, righ...
import pytest from solution import min_swaps_to_sort_rows def test_example_case(): m = 3 n = [4, 3, 5] bookshelf = [ [4, 3, 1, 2], [8, 7, 5], [10, 12, 20, 15, 30] ] assert min_swaps_to_sort_rows(m, n, bookshelf) == [5, 3, 1] def test_single_row(): m = 1 n = [5] ...
[ { "docstring": "Helper function to count inversions using merge sort. ", "function_declaration": "def count_inversions(arr):", "function_name": "count_inversions", "parameter_list": "(arr)" }, { "docstring": "Merges two sorted subarrays and counts split inversions. ", "function_declarati...
[ 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": "def minimum_swaps_for_rows(m, rows):\n def count_min_swaps(arr):\n n = len(arr)\n arrpos = [*enumerate(arr)]\n arrpos.sort(key=lambda ...
trial_gpt4o_7
{ "original_instruction": "", "prompt_id": "00010371", "row_id": 10371, "seed_ids": "[1255]" }
0.656272
Codeforces_10371
I
[ "count_inversions", "merge_and_count", "min_swaps_to_sort_rows" ]
3
[ [ "count_inversions", "merge_and_count" ], [ "min_swaps_to_sort_rows", "count_inversions" ] ]
2
[]
false
[]
false
pytest
true
[]
true
e477abc145f4edf6603a56d276f500d5fb9cb469
d4feae4cc03dc6d7f17493563ecc8a26ea45f6bf
v1.0
instruct
Codeforces
Codeforces_10383_I
A company has introduced a new system that assigns workloads to its employees. Each employee can handle a maximum workload capacity, and the company wants to ensure that the total workload is distributed as evenly as possible among all employees while adhering to their maximum capacities. The company has `m` employees...
def assign_workloads(m, n, capacities, tasks): from heapq import heappush, heappop task_indices = sorted(range(n), key=lambda i: -tasks[i]) employees = [(0, i) for i in range(m)] assignments = [[] for _ in range(m)] assigned_workloads = [0] * m for task_idx in task_indices: ...
def test_workloads_possible(): m = 3 n = 5 capacities = [8, 5, 7] tasks = [2, 3, 4, 5, 1] result = workload_assignment(m, n, capacities, tasks) assert result.startswith("YES") def test_workloads_impossible(): m = 2 n = 3 capacities = [2, 2] tasks = [2, 2, 2] result = workloa...
[ { "docstring": null, "function_declaration": "def assign_workloads(m, n, capacities, tasks):", "function_name": "assign_workloads", "parameter_list": "(m, n, capacities, tasks)" }, { "docstring": null, "function_declaration": "def workload_assignment(m, n, capacities, tasks):", "func...
[ 0, 0, 0, 0, 0, 1, 1, 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 assign_workloads(m, n, capacities, tasks):\n from heapq import heappush, heappop\n\n # Sort tasks in descending order\n tasks = sorted([(task, id...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00010383", "row_id": 10383, "seed_ids": "[4886]" }
0.640198
Codeforces_10383
I
[ "assign_workloads", "workload_assignment" ]
2
[ [ "workload_assignment", "assign_workloads" ] ]
1
[]
false
[]
false
pytest
false
[]
true
8e64c8176bf8cfd59b186d04bf624f46dd190d54
7c39d5adf4e0aff5a6a4a912fb7327784b3087a4
v1.0
instruct
Codeforces
Codeforces_10439_I
You have been hired by a transportation company to help optimize their delivery routes. The company has n delivery locations, numbered from 1 to n, with each location uniquely connected by bidirectional roads forming a tree structure (a connected acyclic graph). Each road between locations i and j has a specific distan...
from collections import defaultdict, deque def bfs_to_find_distances(n, edges): graph = defaultdict(list) for u, v, w in edges: graph[u].append((v, w)) graph[v].append((u, w)) distances = [[0] * n for _ in range(n)] def bfs(start): dist = [-1] * n queue = deque([(start...
def test_delivery_times(): edges = [(1, 2, 3), (1, 3, 2), (3, 4, 4), (3, 5, 1)] queries = [(2, 4), (4, 5), (1, 5)] n = 5 assert delivery_times(n, edges, queries) == [9, 5, 3] edges = [(1, 2, 1), (1, 3, 2)] queries = [(1, 2), (2, 3), (1, 3)] n = 3 assert delivery_times(n, edges, queries)...
[ { "docstring": null, "function_declaration": "def bfs_to_find_distances(n, edges):", "function_name": "bfs_to_find_distances", "parameter_list": "(n, edges)" }, { "docstring": null, "function_declaration": "def delivery_times(n, edges, queries):", "function_name": "delivery_times", ...
[ 0, 0, 0, 1, 0, 1, 0, 0, 0, 1 ]
3
hard
0.3
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "from collections import defaultdict, deque\n\nclass Tree:\n def __init__(self, n):\n self.n = n\n self.tree = defaultdict(list)\n self...
trial_gpt4o_5
{ "original_instruction": "", "prompt_id": "00010439", "row_id": 10439, "seed_ids": "[6111]" }
0.734368
Codeforces_10439
I
[ "bfs_to_find_distances", "delivery_times" ]
2
[ [ "delivery_times", "bfs_to_find_distances" ] ]
1
[]
false
[]
false
pytest
false
[]
true
24b221c01a248fd35d113f7bd8391edef01dc367
b4172835383c613c272d97fc4748cd0613792b17
v1.0
instruct
Codeforces
Codeforces_10469_I
There is a forest represented by a grid of size n x m, where each cell in the grid contains a tree with a certain height. A lumberjack wants to cut down trees to create a clear path from the top-left corner to the bottom-right corner of the grid. The lumberjack can only move right or down from any cell. The cost of cut...
def min_path_cost(grid): n = len(grid) m = len(grid[0]) # Initialize a DP table dp = [[float('inf')] * m for _ in range(n)] dp[0][0] = grid[0][0] for i in range(n): for j in range(m): if i > 0: dp[i][j] = min(dp[i][j], dp[i-1][j] + grid[i][j]) if...
from solution import min_path_cost, min_path_cost_from_input def test_min_path_cost_basic(): grid = [ [1, 3, 1], [1, 5, 1], [4, 2, 1] ] assert min_path_cost(grid) == 7 def test_min_path_cost_single_cell(): grid = [ [5] ] assert min_path_cost(grid) == 5 def test...
[ { "docstring": null, "function_declaration": "def min_path_cost(grid):", "function_name": "min_path_cost", "parameter_list": "(grid)" }, { "docstring": null, "function_declaration": "def min_path_cost_from_input(grid_input):", "function_name": "min_path_cost_from_input", "paramet...
[ 1, 0, 0, 1, 1, 0, 0, 0, 0, 0 ]
3
hard
0.3
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def min_path_cost_grid(n, m, grid):\n \"\"\"\n Returns the minimum total cost required to create a clear path from the top-left to the bottom-right corn...
trial_gpt4o_4
{ "original_instruction": "", "prompt_id": "00010469", "row_id": 10469, "seed_ids": "[5864]" }
0.634802
Codeforces_10469
I
[ "min_path_cost", "min_path_cost_from_input" ]
2
[ [ "min_path_cost_from_input", "min_path_cost" ] ]
1
[]
false
[]
false
pytest
true
[]
true
3698f59903c16e18f8c8679773262c12003e8ecc
ff9ffea97172cae3914d434c91470e344aea9d44
v1.0
instruct
Codeforces
Codeforces_10478_I
You are given a list of integers representing the heights of trees lined up in a row. You can cut down trees in such a way that it does not disturb the beauty of the landscape, which means the heights of the trees on each side must appear non-decreasing. To cut down a tree, you remove it from the list entirely. Your t...
def max_trees_to_cut(heights): """ Determines the maximum number of trees that can be cut down such that the remaining tree heights form a non-decreasing sequence. """ n = len(heights) # If only one tree or already sorted, no need to cut any tree if n <= 1 or all(heights[i] <= heights[i...
def test_max_trees_to_cut_basic(): assert max_trees_to_cut([3, 7, 5, 8, 10, 5, 13]) == 2 def test_max_trees_to_cut_all_decreasing(): assert max_trees_to_cut([5, 4, 3, 2, 1]) == 4 def test_max_trees_to_cut_all_increasing(): assert max_trees_to_cut([1, 2, 3, 4, 5]) == 0 def test_max_trees_to_cut_one_tree()...
[ { "docstring": "Determines the maximum number of trees that can be cut down such\nthat the remaining tree heights form a non-decreasing sequence.", "function_declaration": "def max_trees_to_cut(heights):", "function_name": "max_trees_to_cut", "parameter_list": "(heights)" }, { "docstring": n...
[ 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 max_cut_trees_to_non_decreasing(n, heights):\n def lis_length(arr):\n if not arr:\n return 0\n dp = [1] * len(arr)\n fo...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00010478", "row_id": 10478, "seed_ids": "[6752]" }
0.655503
Codeforces_10478
I
[ "max_trees_to_cut", "binary_search" ]
2
[ [ "max_trees_to_cut", "binary_search" ] ]
1
[]
false
[]
false
pytest
false
[]
true
c1ab2bbb47e88aeea8297c92da24a4cc242107d2
6f26554e65326721022be76fdb9a879d315a45fc
v1.0
instruct
Codeforces
Codeforces_10479_I
Drake, the delivery drone, is used by a logistics company to deliver parcels between different warehouse locations. These locations are labeled with unique positive integers. The drone travels along predefined paths, and each path takes a certain amount of time to traverse. Given a starting warehouse and an ending ware...
import heapq def dijkstra(n, edges, start, end, max_time): graph = [[] for _ in range(n + 1)] for u, v, t in edges: graph[u].append((v, t)) graph[v].append((u, t)) min_heap = [(0, start)] distances = {i: float('inf') for i in range(1, n + 1)} distances[start] = 0 while...
import pytest from solution import delivery_possible def test_example_case(): n = 5 m = 7 edges = [ (1, 2, 10), (2, 3, 10), (1, 3, 15), (3, 4, 10), (4, 5, 5), (2, 5, 50), (3, 5, 30) ] start, end, max_time = 1, 5, 30 assert delivery_possibl...
[ { "docstring": null, "function_declaration": "def dijkstra(n, edges, start, end, max_time):", "function_name": "dijkstra", "parameter_list": "(n, edges, start, end, max_time)" }, { "docstring": null, "function_declaration": "def delivery_possible(n, m, edges, start, end, max_time):", ...
[ 1, 1, 1, 1, 0, 1, 0, 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": "import heapq\n\ndef shortest_path(n, m, edges, s, e, T):\n # Create adjacency list\n graph = {i: [] for i in range(1, n + 1)}\n for u, v, t in edges:...
trial_gpt4o_7
{ "original_instruction": "", "prompt_id": "00010479", "row_id": 10479, "seed_ids": "[5268]" }
0.748838
Codeforces_10479
I
[ "dijkstra", "delivery_possible" ]
2
[ [ "delivery_possible", "dijkstra" ] ]
1
[]
false
[]
false
pytest
true
[]
true
0f95d00f7322d4b024112329617916d4592037da
80ffabd5cb61e725f50aaf0619fef80a0e3e9b1d
v1.0
instruct
Codeforces
Codeforces_10516_I
You are given an array `a` consisting of `n` integers. Your task is to determine if there exists a pair of indices `i` and `j` (1 ≤ i < j ≤ n) such that the sum of `a[i]` and `a[j]` is a prime number. If such a pair exists, print "YES"; otherwise, print "NO". For example, if the array `a` is `[1, 4, 6, 3]`, the pairs...
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: return False i += 6 retu...
from solution import has_prime_sum_pair def test_no_prime_pair(): assert has_prime_sum_pair([4, 6, 8, 10]) == "NO" # No sums are prime def test_single_pair_of_primes(): assert has_prime_sum_pair([1, 2]) == "YES" # 1 + 2 = 3 is prime def test_multiple_prime_pairs(): assert has_prime_sum_pair([1, 4, 6, 3...
[ { "docstring": "Checks if a number is prime.", "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": "Determines if there exists a pair of indices (i, j) such that the sum of a[i] and a[j] is a prime number.", "function_dec...
[ 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 math\n\ndef is_prime(n):\n if n <= 1:\n return False\n if n <= 3:\n return True\n if n % 2 == 0 or n % 3 == 0:\n return F...
trial_gpt4o_3
{ "original_instruction": "", "prompt_id": "00010516", "row_id": 10516, "seed_ids": "[1164]" }
0.734424
Codeforces_10516
I
[ "is_prime", "has_prime_sum_pair" ]
2
[ [ "has_prime_sum_pair", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
72c6375d900f4ae9c444e355ce3d55db4e7c6268
ac53069bd430bd2efac7523ddce7ec76b7875632
v1.0
instruct
Codeforces
Codeforces_10550_I
Given an undirected graph with n nodes and m edges, your task is to determine if there exists a way to place the nodes on a straight line such that for every edge (u, v), node u appears before node v. If this is possible, then it's guaranteed that there will be a unique way to place the nodes satisfying the condition....
from collections import deque, defaultdict def can_place_nodes_on_line(n, m, edges): # Create an adjacency list and in-degree count. graph = defaultdict(list) in_degree = {i: 0 for i in range(n)} for u, v in edges: graph[u].append(v) in_degree[v] += 1 # Queue for nodes with in-...
from solution import solve def test_no_edges(): assert solve(3, 0, []) == "YES\n0 1 2" def test_simple_yes(): assert solve(3, 2, [(0, 1), (1, 2)]) == "YES\n0 1 2" def test_simple_no_cycle(): assert solve(3, 3, [(0, 1), (1, 2), (2, 0)]) == "NO" def test_multiple_zero_indegree(): assert solve(4, 2, [(...
[ { "docstring": null, "function_declaration": "def can_place_nodes_on_line(n, m, edges):", "function_name": "can_place_nodes_on_line", "parameter_list": "(n, m, edges)" }, { "docstring": null, "function_declaration": "def solve(n, m, edges):", "function_name": "solve", "parameter_...
[ 0, 0, 0, 0, 0, 0, 1, 1, 0, 1 ]
3
hard
0.3
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "from collections import defaultdict, deque\n\ndef find_linear_ordering(n, m, edges):\n \"\"\"\n Determines if there exists a linear ordering of the node...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00010550", "row_id": 10550, "seed_ids": "[6997]" }
0.67971
Codeforces_10550
I
[ "can_place_nodes_on_line", "solve" ]
2
[ [ "solve", "can_place_nodes_on_line" ] ]
1
[]
false
[]
false
pytest
true
[]
true
9f7789b7af80063d70c54732f2bc52c5dfb24fa1
54b841cdc0df08d2a217f92c30ce7c076651e9d4
v1.0
instruct
Codeforces
Codeforces_10554_I
Polycarpus recently got interested in the new area of artificial intelligence and neural networks. As part of his research, he needs to perform a series of transformations on a list of integers. Given a list of integers, he wants to transform this list into a new list by following these operations: 1. **Replace** ever...
def sum_of_digits(n): """ Returns the sum of digits of an integer n. """ return sum(int(digit) for digit in str(n)) def transform_list(nums, k): """ Transforms the list 'nums' k times by replacing each integer with the sum of its digits in each transformation. """ for _ in range(k)...
from solution import transform_list def test_transform_list_example_1(): assert transform_list([18, 29, 39], 2) == [9, 2, 3] def test_transform_list_example_2(): assert transform_list([999, 1000, 12345], 1) == [27, 1, 15] def test_transform_list_single_element(): assert transform_list([0], 5) == [0] def...
[ { "docstring": "Returns the sum of digits of an integer n.", "function_declaration": "def sum_of_digits(n):", "function_name": "sum_of_digits", "parameter_list": "(n)" }, { "docstring": "Transforms the list 'nums' k times by replacing each integer with \nthe sum of its digits in each transfo...
[ 0, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
9
easy
0.9
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def transform_list(nums, k):\n def sum_of_digits(n):\n return sum(int(digit) for digit in str(n))\n \n for _ in range(k):\n nums = [sum...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00010554", "row_id": 10554, "seed_ids": "[8193]" }
0.614044
Codeforces_10554
I
[ "sum_of_digits", "transform_list" ]
2
[ [ "transform_list", "sum_of_digits" ] ]
1
[]
false
[]
false
pytest
true
[]
true
176fe01200681559913fdc374b2e7c0da8e6fd5d
94520b98eadbd5fa6f8625f28d0263d1afffbcdc
v1.0
instruct
Codeforces
Codeforces_10594_I
You are given a tree with `n` nodes, where each node has some value. You need to find the maximum path sum in the tree. A path is defined as any sequence of nodes from some starting node to any node in the tree following the parent-child connections. The path must contain at least one node and does not need to go throu...
class TreeNode: def __init__(self, value): self.value = value self.children = [] def build_tree(values, edges): nodes = [TreeNode(value) for value in values] for u, v in edges: nodes[u-1].children.append(nodes[v-1]) nodes[v-1].children.append(nodes[u-1]) return n...
from solution import max_path_sum def test_max_path_sum_simple(): assert max_path_sum(5, [1, 2, 3, -1, -3], [(1, 2), (1, 3), (2, 4), (2, 5)]) == 6 def test_max_path_sum_single_node(): assert max_path_sum(1, [5], []) == 5 def test_max_path_sum_negative_values(): assert max_path_sum(3, [-1, -2, -3], [(1, 2...
[]
[ 0, 0, 0, 1, 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": "import sys\nsys.setrecursionlimit(100000)\n\ndef max_path_sum(n, node_values, edges):\n from collections import defaultdict\n import sys\n \n sys....
trial_gpt4o_5
{ "original_instruction": "", "prompt_id": "00010594", "row_id": 10594, "seed_ids": "[5911]" }
0.720782
Codeforces_10594
I
[ "build_tree", "find_max_path_sum", "max_path_sum" ]
3
[ [ "max_path_sum", "build_tree" ], [ "max_path_sum", "find_max_path_sum" ] ]
2
[]
false
[ "TreeNode" ]
true
pytest
true
[]
true
a1196eb4fc045218c2ff82c18b671039356c5dfc
e337873b2576f731c8e517666b0bcd3c10017526
v1.0
instruct
Codeforces
Codeforces_10651_I
A telecommunications company is laying high-speed fiber optic cables in a specific city. The city's layout is a grid of streets, represented by a 2D plane with intersections at integer coordinates. However, there are certain obstacles where the cable cannot be laid. These obstacles are given as rectangular zones with s...
from collections import deque def is_point_within_any_obstacle(x, y, obstacles): for x1, y1, x2, y2 in obstacles: if x1 <= x <= x2 and y1 <= y <= y2: return True return False def shortest_path(xA, yA, xB, yB, obstacles): if (xA, yA) == (xB, yB): return 0 if is_point_within...
import pytest from solution import shortest_path def test_no_obstacles_direct_path(): assert shortest_path(0, 0, 5, 5, []) == 10 def test_with_obstacles(): obstacles = [(2, 2, 4, 4), (5, 5, 7, 7)] assert shortest_path(0, 0, 10, 10, obstacles) == 20 def test_start_point_in_obstacle(): obstacles = [(2,...
[ { "docstring": null, "function_declaration": "def is_point_within_any_obstacle(x, y, obstacles):", "function_name": "is_point_within_any_obstacle", "parameter_list": "(x, y, obstacles)" }, { "docstring": null, "function_declaration": "def shortest_path(xA, yA, xB, yB, obstacles):", "...
[ 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 heapq\nfrom collections import deque\n\ndef is_inside_rect(x, y, rect):\n return rect[0] <= x <= rect[2] and rect[1] <= y <= rect[3]\n\ndef shortest...
trial_gpt4o_7
{ "original_instruction": "", "prompt_id": "00010651", "row_id": 10651, "seed_ids": "[7594]" }
0.714165
Codeforces_10651
I
[ "is_point_within_any_obstacle", "shortest_path" ]
2
[ [ "shortest_path", "is_point_within_any_obstacle" ] ]
1
[]
false
[]
false
pytest
true
[]
true
303c5a19ada405eaea527103d3c4418c62a8128f
4406a26c580e7d2ec3285822d3de8a686c165f2e
v1.0
instruct
Codeforces
Codeforces_10715_I
In a distant land, the monarchy has just begun and a new capital city is under construction. The city is designed as a grid of streets and avenues. Each intersection of a street and an avenue is given as (x, y). As part of a ceremony, the monarch decides to place a giant flag at every intersection that forms a square ...
def count_unique_squares(intersections): points = set((x, y) for x, y in intersections) count = 0 for (x1, y1) in points: for (x2, y2) in points: if x1 != x2 and y1 != y2 and (x1, y2) in points and (x2, y1) in points: count += 1 return count // 4...
def test_count_unique_squares(): # Test case 1 input_str = "5\n1 1\n1 2\n2 1\n2 2\n3 3" assert count_unique_squares_from_input(input_str) == 1 # Test case 2 input_str = "8\n1 1\n1 2\n2 1\n2 2\n3 3\n3 4\n4 3\n4 4" assert count_unique_squares_from_input(input_str) == 2 # Test case 3 ...
[ { "docstring": null, "function_declaration": "def count_unique_squares(intersections):", "function_name": "count_unique_squares", "parameter_list": "(intersections)" }, { "docstring": null, "function_declaration": "def count_unique_squares_from_input(input_str):", "function_name": "c...
[ 0, 1, 0, 1, 0, 0, 1, 0, 0 ]
3
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def count_unique_squares(n, intersections):\n \"\"\"\n This function receives the number of intersections and a list of coordinates, \n and returns t...
trial_gpt4o_7
{ "original_instruction": "", "prompt_id": "00010715", "row_id": 10715, "seed_ids": "[7320]" }
0.654008
Codeforces_10715
I
[ "count_unique_squares", "count_unique_squares_from_input" ]
2
[ [ "count_unique_squares_from_input", "count_unique_squares" ] ]
1
[]
false
[]
false
pytest
false
[]
true
4332158cc08717d8b26e27411779f5eb0f9cf7cb
a974c72030b15b10d75be8bf3d65e82de0163ac2
v1.0
instruct
Codeforces
Codeforces_10730_I
Johnny is fascinated with prime numbers and he has a special interest in prime number indices. A prime number index is defined as an index i in an array such that the value at index i is a prime number. Johnny has an array of integers and he wants to answer multiple queries regarding the prime number indices. You are ...
def is_prime(num): """ Helper function to determine if a number is prime. """ if num <= 1: return False if num == 2: return True if num % 2 == 0: return False sqrt_n = int(num**0.5) for i in range(3, sqrt_n + 1, 2): if num % i == 0: return Fals...
import pytest from solution import prime_indices_query def test_prime_indices_query_case1(): n = 6 arr = [2, 3, 4, 5, 6, 7] queries = [(1, 3), (4, 6), (1, 6)] expected = [2, 2, 4] assert prime_indices_query(n, arr, queries) == expected def test_prime_indices_query_case2(): n = 10 arr = [11...
[ { "docstring": "Helper function to determine if a number is prime.", "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": "Preprocess the array to get list of boolean values indicating\nif element at each index is prime or not...
[ 0, 1, 1, 0, 0, 1, 1, 1, 0 ]
5
medium
0.556
{ "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_5
{ "original_instruction": "", "prompt_id": "00010730", "row_id": 10730, "seed_ids": "[4265]" }
0.623686
Codeforces_10730
I
[ "is_prime", "preprocess_prime_indices", "count_prime_indices_in_subarray", "prime_indices_query" ]
4
[ [ "preprocess_prime_indices", "is_prime" ], [ "prime_indices_query", "count_prime_indices_in_subarray" ], [ "prime_indices_query", "preprocess_prime_indices" ] ]
3
[]
false
[]
false
pytest
true
[]
true
1f2baa443282e1e9a9685b3f238b913e51c5f0ff
af7caac3360bbb07eaca9001a0aa37465e221acb
v1.0
instruct
Codeforces
Codeforces_10732_I
Given a matrix of size n x m filled with non-negative integers, your task is to find the largest rectangle containing only zeros and return its area. Input Format: - The first line contains two integers n (number of rows) and m (number of columns) (1 ≤ n, m ≤ 1000). - Each of the next n lines contains m integers (0 or...
def maximal_rectangle(matrix): if not matrix: return 0 n, m = len(matrix), len(matrix[0]) max_area = 0 dp = [0] * m for i in range(n): for j in range(m): dp[j] = dp[j] + 1 if matrix[i][j] == 0 else 0 max_area = max(max_area, largest_rectangle_area(dp)) ret...
from solution import maximal_rectangle def test_maximal_rectangle_example_case(): matrix = [[1, 0, 0, 1], [0, 0, 0, 1], [0, 0, 1, 0], [1, 0, 0, 0]] assert maximal_rectangle(matrix) == 4 def test_maximal_rectangle_single_zero(): matrix = [[0]] assert maximal_re...
[ { "docstring": null, "function_declaration": "def maximal_rectangle(matrix):", "function_name": "maximal_rectangle", "parameter_list": "(matrix)" }, { "docstring": null, "function_declaration": "def largest_rectangle_area(heights):", "function_name": "largest_rectangle_area", "pa...
[ 1, 1, 1, 0, 0, 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 maximal_rectangle(matrix):\n if not matrix:\n return 0\n\n n, m = len(matrix), len(matrix[0])\n heights = [0] * (m + 1)\n max_area = 0\...
trial_gpt4o_5
{ "original_instruction": "", "prompt_id": "00010732", "row_id": 10732, "seed_ids": "[5607]" }
0.744078
Codeforces_10732
I
[ "maximal_rectangle", "largest_rectangle_area" ]
2
[ [ "maximal_rectangle", "largest_rectangle_area" ] ]
1
[]
false
[]
false
pytest
true
[]
true
fa9978fea82ddfcec0c8f61e5040b07912fb4e35
e309dd9fdc852c4adb8f224b38daee47539065e7
v1.0
instruct
Codeforces
Codeforces_10738_I
In a land far away, there is a great festival happening in the City of Miracles. The city has k districts, and each district is represented by a set of unique mystical creatures. There are p distinct species of mystical creatures across the city, numbered from 1 to p. The festival involves a grand event where each myst...
MOD = 10**9 + 7 def factorial_mod(n, mod): """ Compute n! % mod using iterative approach. """ result = 1 for i in range(1, n + 1): result = (result * i) % mod return result def number_of_transformation_plans(k, p, districts): """ Given the number of districts and species and th...
from solution import number_of_transformation_plans def test_number_of_transformation_plans_example(): k, p = 3, 3 districts = [ [5, 1, 2, 3, 2, 1], [4, 2, 3, 2, 3], [3, 1, 1, 1] ] assert number_of_transformation_plans(k, p, districts) == 6 def test_number_of_transformation_pla...
[ { "docstring": "Compute n! % mod using iterative approach.", "function_declaration": "def factorial_mod(n, mod):", "function_name": "factorial_mod", "parameter_list": "(n, mod)" }, { "docstring": "Given the number of districts and species and their distributions in districts,\nreturn the num...
[ 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": "MOD = 10**9 + 7\n\ndef factorial(n, mod):\n if n == 0 or n == 1:\n return 1\n fact = 1\n for i in range(2, n + 1):\n fact = (fact * i) ...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00010738", "row_id": 10738, "seed_ids": "[6949]" }
0.559408
Codeforces_10738
I
[ "factorial_mod", "number_of_transformation_plans" ]
2
[ [ "number_of_transformation_plans", "factorial_mod" ] ]
1
[]
false
[]
false
pytest
true
[]
true
1e62b4073e37e186874d90ded3723d51425c8bb7
8c38ceb03d08eddec22a7be03b45cfd784614c90
v1.0
instruct
Codeforces
Codeforces_10804_I
You are given the task of analyzing text files containing scientific research articles to determine their primary language of publication. For this problem, you've been provided with a collection of articles written either in English („en“), French („fr“), or German („de“). You can download the training set of article...
import os import string from collections import Counter def load_stopwords(): stopwords = { 'en': ["the", "and", "to", "of", "in", "that", "is", "it", "for", "with"], 'fr': ["et", "le", "de", "la", "les", "des", "une", "que", "en", "pour"], 'de': ["und", "die", "der", "das", "ist", "in", "z...
from solution import guess_language def test_guess_language_english(): article = "1\nThe title of the article\nThis is the body of the article. It is written in English." assert guess_language(article) == "en" def test_guess_language_french(): article = "2\nLe titre de l'article\nCeci est le corps de l'ar...
[ { "docstring": null, "function_declaration": "def load_stopwords():", "function_name": "load_stopwords", "parameter_list": "()" }, { "docstring": null, "function_declaration": "def preprocess(text):", "function_name": "preprocess", "parameter_list": "(text)" }, { "docstri...
[ 1, 0, 1, 0, 1, 0, 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 detect_language(article_id, title, body):\n \"\"\"\n Detects the language of a given article based on the content.\n The function uses common wor...
trial_gpt4o_6
{ "original_instruction": "", "prompt_id": "00010804", "row_id": 10804, "seed_ids": "[6125]" }
0.532774
Codeforces_10804
I
[ "load_stopwords", "preprocess", "guess_language" ]
3
[ [ "guess_language", "load_stopwords" ], [ "guess_language", "preprocess" ] ]
2
[]
false
[]
false
pytest
true
[]
true
f3dfcf831ab37e188999c5c940569ae674c87568
be8f251a5de75301ca35cdee7ef54862068e6a01
v1.0
instruct
Codeforces
Codeforces_10812_I
A city is represented as an undirected connected graph with `n` nodes (representing intersections) and `m` edges (representing roads). Each road connects two different nodes and has a positive integer length. You are tasked with initiating a series of paving operations to throw out certain roads from the map and pave n...
def find(parent, i): if parent[i] == i: return i return find(parent, parent[i]) def union(parent, rank, x, y): root_x = find(parent, x) root_y = find(parent, y) if rank[root_x] < rank[root_y]: parent[root_x] = root_y elif rank[root_x] > rank[root_y]: parent[root_y] = roo...
from solution import paving_operations def test_case_1(): n = 4 m = 5 edges = [ (1, 2, 5), (2, 3, 10), (3, 4, 1), (4, 1, 8), (2, 4, 3) ] k, operations = paving_operations(n, m, edges) assert k == 0 assert operations == [] def test_case_2(): n = 2...
[ { "docstring": null, "function_declaration": "def find(parent, i):", "function_name": "find", "parameter_list": "(parent, i)" }, { "docstring": null, "function_declaration": "def union(parent, rank, x, y):", "function_name": "union", "parameter_list": "(parent, rank, x, y)" }, ...
[ 1, 0, 0, 0, 1, 0, 1, 0, 0 ]
3
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def find(parent, i):\n if parent[i] == i:\n return i\n return find(parent, parent[i])\n\ndef union(parent, rank, x, y):\n root_x = find(parent...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00010812", "row_id": 10812, "seed_ids": "[6739]" }
0.654318
Codeforces_10812
I
[ "find", "union", "kruskal", "paving_operations" ]
4
[ [ "kruskal", "find" ], [ "kruskal", "union" ], [ "paving_operations", "kruskal" ], [ "union", "find" ] ]
4
[]
false
[]
false
pytest
true
[]
true
76fd2efd22a2095108239bc9a79153b9b5e3725e
2b2e44ba302a7b665516fa3a887fa508eba778a8
v1.0
instruct
Codeforces
Codeforces_10845_I
You are given a grid of size $$$n \times n$$$, initially filled with zeros. You will perform $$$q$$$ operations of the following types: 1. Add an integer $$$v$$$ to all elements in a subgrid defined by its top-left corner $$$(r_1, c_1)$$$ and bottom-right corner $$$(r_2, c_2)$$$. 2. Query the sum of all elements in a ...
def initialize_grid(n): """ Initialize an n x n grid with zeros. """ return [[0] * n for _ in range(n)] def add_to_subgrid(grid, r1, c1, r2, c2, v): """ Add v to all elements in the subgrid defined by its top-left corner (r1, c1) and bottom-right corner (r2, c2). """ for i in range...
import pytest from solution import initialize_grid, add_to_subgrid, sum_subgrid, process_operations def test_initialize_grid(): grid = initialize_grid(2) assert grid == [[0, 0], [0, 0]] def test_add_to_subgrid(): grid = initialize_grid(3) add_to_subgrid(grid, 1, 1, 2, 2, 10) assert grid == [ ...
[ { "docstring": "Initialize an n x n grid with zeros.", "function_declaration": "def initialize_grid(n):", "function_name": "initialize_grid", "parameter_list": "(n)" }, { "docstring": "Add v to all elements in the subgrid defined by its top-left corner (r1, c1) \nand bottom-right corner (r2,...
[ 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 execute_operations(n, q, operations):\n grid = [[0] * n for _ in range(n)]\n results = []\n\n for op in operations:\n if op[0] == 1:\n ...
trial_gpt4o_3
{ "original_instruction": "", "prompt_id": "00010845", "row_id": 10845, "seed_ids": "[1181]" }
0.663495
Codeforces_10845
I
[ "initialize_grid", "add_to_subgrid", "sum_subgrid", "process_operations" ]
4
[ [ "process_operations", "add_to_subgrid" ], [ "process_operations", "initialize_grid" ], [ "process_operations", "sum_subgrid" ] ]
3
[]
false
[]
false
pytest
true
[]
true
5496d12bd5fa3c0e28b47b4d97696f0785ba6f9a
52ae70d4acdd8574ba6fbce910d2f29556d6535e
v1.0
instruct
Codeforces
Codeforces_10869_I
You are given a list of words. Each word consists of lowercase English letters only. Determine the length of the longest word in the list that can be created by deleting some (or none) of the characters from a given string `s` in such a way that the remaining characters appear in the same order as in the word. Input: ...
def is_subsequence(word, s): """ Helper function to check if a `word` is a subsequence of `s`. """ it = iter(s) return all(char in it for char in word) def longest_word_subsequence_length(s, words): """ Returns the length of the longest word in `words` that can be formed as a subsequence of...
from solution import longest_word_subsequence_length def test_example_case(): s = "abpcplea" words = ["ale", "apple", "monkey", "plea"] assert longest_word_subsequence_length(s, words) == 5 def test_no_subsequence(): s = "abc" words = ["d", "e", "f"] assert longest_word_subsequence_length(s, w...
[ { "docstring": "Helper function to check if a `word` is a subsequence of `s`.", "function_declaration": "def is_subsequence(word, s):", "function_name": "is_subsequence", "parameter_list": "(word, s)" }, { "docstring": "Returns the length of the longest word in `words` that can be formed as ...
[ 1, 0, 1, 1, 1, 0, 1, 1, 1, 1 ]
8
easy
0.8
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def longest_word_length(s, word_list):\n def is_subsequence(x, y):\n it = iter(y)\n return all(c in it for c in x)\n\n max_length = 0\n\n ...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00010869", "row_id": 10869, "seed_ids": "[4750]" }
0.748266
Codeforces_10869
I
[ "is_subsequence", "longest_word_subsequence_length" ]
2
[ [ "longest_word_subsequence_length", "is_subsequence" ] ]
1
[]
false
[]
false
pytest
true
[]
true
48f66eb054ffc00555ed5678aa9d1c2d20519080
f11c3547bceb26477c8c58d700ca743c4c5815e9
v1.0
instruct
Codeforces
Codeforces_10878_I
Chef is a budding gourmet who is learning to cook using various ingredients. Chef maintains a recipe book where each recipe lists the required ingredients and the quantity of each ingredient needed. Chef has a pantry with a limited stock of ingredients. Given a list of recipes Chef wants to cook and the current stock...
def can_make_all_recipes(ingredients, quantities, recipes): ingredient_stock = dict(zip(ingredients, quantities)) for recipe in recipes: for ingredient, quantity in recipe.items(): if ingredient not in ingredient_stock or ingredient_stock[ingredient] < quantity: return "...
import pytest from solution import chef_recipes def test_chef_recipes_yes(): input_data = """5 sugar flour butter eggs milk 500 300 200 5 1000 2 3 sugar 200 flour 100 butter 5...
[ { "docstring": null, "function_declaration": "def can_make_all_recipes(ingredients, quantities, recipes):", "function_name": "can_make_all_recipes", "parameter_list": "(ingredients, quantities, recipes)" }, { "docstring": null, "function_declaration": "def parse_input(input_string):", ...
[ 0, 1, 1, 1, 0, 1, 1, 1, 1, 1 ]
8
easy
0.8
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def can_cook_all_recipes(pantry_ingredients, pantry_quantities, recipes):\n # Convert the pantry ingredients and quantities into a dictionary\n pantry =...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00010878", "row_id": 10878, "seed_ids": "[2829]" }
0.735067
Codeforces_10878
I
[ "can_make_all_recipes", "parse_input", "chef_recipes" ]
3
[ [ "chef_recipes", "can_make_all_recipes" ], [ "chef_recipes", "parse_input" ] ]
2
[ "parse_input" ]
false
[]
false
pytest
true
[]
true
de647397d77e518b52b7da139f2648da3506328b
0ba86f2bc190c4d5361f3b80feee864832f111fa
v1.0
instruct
Codeforces
Codeforces_10931_I
Given a list of integers, your task is to determine if there exists a pair of distinct indices `i` and `j` such that the sum of the elements at these indices is a prime number. Write a function `find_prime_pair(arr)` that takes a list of integers `arr`, and returns `True` if such a pair exists, and `False` otherwise. ...
def is_prime(n): """Check if a number is prime.""" if n <= 1: return False if n == 2: return True if n % 2 == 0: return False max_divisor = int(n**0.5) + 1 for d in range(3, max_divisor, 2): if n % d == 0: return False return True def find_prime_p...
from solution import find_prime_pair def test_pair_with_prime_sum_exists(): assert find_prime_pair([1, 4, 6, 7]) == True assert find_prime_pair([5, 10, 1, 3]) == True def test_no_pair_with_prime_sum(): assert find_prime_pair([2, 4, 6, 8]) == False assert find_prime_pair([20, 30, 40, 50]) == False def...
[ { "docstring": "Check if a number is prime.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Check if there exists a pair of indices (i, j) such that arr[i] + arr[j] is a prime number.", "function_declaration": "def fin...
[ 0, 0, 1, 0, 0, 0, 0, 1, 0, 0 ]
2
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "import math\n\ndef is_prime(n):\n \"\"\"\n Helper function to determine if n is a prime number.\n \"\"\"\n if n <= 1:\n return False\n i...
trial_gpt4o_7
{ "original_instruction": "", "prompt_id": "00010931", "row_id": 10931, "seed_ids": "[6582]" }
0.751239
Codeforces_10931
I
[ "is_prime", "find_prime_pair" ]
2
[ [ "find_prime_pair", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
01060719ec0613c82c557ac9138da7374a2eb889
3cfba47f9c0a8e6e05433e1c75b2815a4f07e200
v1.0
instruct
Codeforces
Codeforces_10957_I
Consider a connected, undirected graph represented as an adjacency list. Each node in the graph has a value associated with it. You are tasked with finding the diameter of the graph, where the diameter is defined as the maximum sum of values of nodes on the longest path between any two nodes. You need to write a funct...
from collections import deque, defaultdict def bfs(graph, start, values): visited = [-1] * len(values) queue = deque([(start, values[start])]) visited[start] = values[start] farthest_node = start max_sum = values[start] while queue: node, current_sum = queue.popleft() ...
from solution import find_graph_diameter def test_case_1(): graph = {0: [1, 2], 1: [0, 3], 2: [0], 3: [1]} values = [4, 3, 2, 1] assert find_graph_diameter(graph, values) == 10 def test_case_2(): graph = {0: [1], 1: [0, 2], 2: [1, 3], 3: [2]} values = [1, 2, 3, 4] assert find_graph_diameter(gr...
[ { "docstring": null, "function_declaration": "def bfs(graph, start, values):", "function_name": "bfs", "parameter_list": "(graph, start, values)" }, { "docstring": null, "function_declaration": "def find_graph_diameter(graph, values):", "function_name": "find_graph_diameter", "pa...
[ 0, 0, 0, 0, 0, 0, 1, 0, 0, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "from collections import defaultdict, deque\n\ndef bfs_furthest_node(start, graph, values):\n visited = set()\n queue = deque([(start, values[start])])\n...
trial_gpt4o_6
{ "original_instruction": "", "prompt_id": "00010957", "row_id": 10957, "seed_ids": "[8060]" }
0.582303
Codeforces_10957
I
[ "bfs", "find_graph_diameter" ]
2
[ [ "find_graph_diameter", "bfs" ] ]
1
[]
false
[]
false
pytest
true
[]
true
d6ca172c3d336da826d7b1d6b13e0d0fc6ccb196
6b23d8a3c6f7ccfb613b30ccd26736b85e33eddb
v1.0
instruct
Codeforces
Codeforces_10965_I
Alice is playing a new game on a grid-like battlefield. The battlefield is represented by a grid of size n x m where each cell can either be empty (represented by '.') or contain an obstacle (represented by '#'). Alice starts at the top-left corner of the grid and wants to move to the bottom-right corner. She can move...
def find_paths(grid, n, m): from collections import deque def bfs(start_x, start_y): queue = deque([(start_x, start_y)]) visited = [[False] * m for _ in range(n)] parent = [[None] * m for _ in range(n)] visited[start_x][start_y] = True while queue: ...
from solution import find_two_distinct_paths def test_example_case(): n, m = 4, 4 grid = [ "....", ".#..", "..#.", "...." ] assert find_two_distinct_paths(n, m, grid) == "YES" def test_no_paths(): n, m = 3, 3 grid = [ "###", "#.#", "###" ...
[ { "docstring": null, "function_declaration": "def find_paths(grid, n, m):", "function_name": "find_paths", "parameter_list": "(grid, n, m)" }, { "docstring": null, "function_declaration": "def find_two_distinct_paths(n, m, grid):", "function_name": "find_two_distinct_paths", "par...
[ 0, 0, 0, 0, 0, 0, 0, 1, 0 ]
1
hard
0.111
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "from collections import deque\n\ndef bfs(start, end, grid, n, m):\n directions = [(1, 0), (-1, 0), (0, 1), (0, -1)]\n queue = deque([start])\n parent...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00010965", "row_id": 10965, "seed_ids": "[4268]" }
0.755326
Codeforces_10965
I
[ "find_paths", "find_two_distinct_paths" ]
2
[ [ "find_two_distinct_paths", "find_paths" ] ]
1
[]
false
[]
false
pytest
true
[]
true
b40e21dfd0f393f0b2cfb1aed16381f81252f0f3
ab5f5d548732950bfecf444fdbf8d9bc1a504b66
v1.0
instruct
Codeforces
Codeforces_10968_I
You are given an undirected graph with `n` nodes and `m` edges. Each edge has a positive length. You need to find the shortest path between two nodes in this graph. The graph may contain cycles, and all nodes are numbered from 1 to `n`. The input consists of multiple test cases. For each test case, you will be given t...
from heapq import heappop, heappush import sys def shortest_path(n, edges, src, dst): graph = {i: [] for i in range(1, n + 1)} for u, v, l in edges: graph[u].append((v, l)) graph[v].append((u, l)) distances = {i: sys.maxsize for i in range(1, n + 1)} distances[src] = 0 priority_que...
def test_shortest_path(): input_lines = [ "2", "4 4", "1 2 1", "2 3 2", "3 4 3", "1 4 10", "1 4", "4 2", "1 2 5", "1 3 2", "1 4" ] expected_output = [6, -1] assert find_shortest_paths(input_lines) == expected_output ...
[ { "docstring": null, "function_declaration": "def shortest_path(n, edges, src, dst):", "function_name": "shortest_path", "parameter_list": "(n, edges, src, dst)" }, { "docstring": null, "function_declaration": "def process_test_cases(test_cases):", "function_name": "process_test_case...
[ 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 heapq\nimport sys\n\ndef dijkstra(n, graph, src, dst):\n # Distance to all nodes set to \"infinity\"\n dist = {i: sys.maxsize for i in range(1, n...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00010968", "row_id": 10968, "seed_ids": "[4792]" }
0.729897
Codeforces_10968
I
[ "shortest_path", "process_test_cases", "find_shortest_paths" ]
3
[ [ "find_shortest_paths", "process_test_cases" ], [ "process_test_cases", "shortest_path" ] ]
2
[ "process_test_cases" ]
false
[]
false
pytest
false
[]
true
7ae3e7359b80bdc046aa6c61e9271892ac973862
db17f68af740f4da066c82234e3e1dc956befae0
v1.0
instruct
Codeforces
Codeforces_10969_I
You are given a grid of size $$$n \times m$$$, where each cell in the grid contains either a '.', representing an empty space, or a '#', representing an obstacle. You need to find the number of ways to walk from the top-left corner of the grid (1, 1) to the bottom-right corner (n, m) such that you only move right or d...
def count_paths(grid, n, m): """ Returns the number of ways to reach the bottom-right corner from the top-left corner without passing through any obstacles. """ # Initialize dp table with 0s dp = [[0] * m for _ in range(n)] # Start position is (0, 0), initialize accordingly if grid[...
from solution import number_of_ways def test_example1(): n, m = 3, 3 grid = [ "...", ".#.", "..." ] assert number_of_ways(n, m, grid) == 2 def test_example2(): n, m = 3, 3 grid = [ ".#.", ".#.", "..." ] assert number_of_ways(n, m, grid) =...
[ { "docstring": "Returns the number of ways to reach the bottom-right corner\nfrom the top-left corner without passing through any obstacles.", "function_declaration": "def count_paths(grid, n, m):", "function_name": "count_paths", "parameter_list": "(grid, n, m)" }, { "docstring": null, ...
[ 1, 0, 1, 1, 1, 1, 1, 1, 0, 0 ]
7
easy
0.7
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def count_paths(grid, n, m):\n if grid[0][0] == '#' or grid[n-1][m-1] == '#':\n return 0\n \n dp = [[0]*m for _ in range(n)]\n dp[0][0] = 1...
trial_gpt4o_7
{ "original_instruction": "", "prompt_id": "00010969", "row_id": 10969, "seed_ids": "[4635]" }
0.780253
Codeforces_10969
I
[ "count_paths", "number_of_ways" ]
2
[ [ "number_of_ways", "count_paths" ] ]
1
[]
false
[]
false
pytest
true
[]
true
6ce37b80f39f4cd2810d8a3eb39c8814b2ea9bc0
11df5489671c9e431066003c6e69f58adc32f684
v1.0
instruct
Codeforces
Codeforces_10979_I
**Problem Statement** You are given a 2D grid of size `n x m` with each cell containing a lowercase English letter. Your task is to determine if there exists a path from the top-left corner (cell (1,1)) to the bottom-right corner (cell (n,m)) such that all cells in the path contain the same letter. You can only move r...
def is_uniform_path(grid): n = len(grid) m = len(grid[0]) target_char = grid[0][0] # DP table for marking reachable cells with the same character dp = [[False] * m for _ in range(n)] dp[0][0] = True for i in range(n): for j in range(m): if dp[i][j] and grid[i][j...
from solution import is_uniform_path def test_example_1(): grid = [ "aaaa", "abaa", "aaaa" ] assert is_uniform_path(grid) == "YES" def test_example_2(): grid = [ "ab", "bb" ] assert is_uniform_path(grid) == "NO" def test_example_3(): grid = [ ...
[ { "docstring": null, "function_declaration": "def is_uniform_path(grid):", "function_name": "is_uniform_path", "parameter_list": "(grid)" }, { "docstring": null, "function_declaration": "def uniform_path(grid):", "function_name": "uniform_path", "parameter_list": "(grid)" } ]
[ 0, 1, 0, 0, 1, 0, 0, 1, 0, 0 ]
3
hard
0.3
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def find_path(n, m, grid):\n visited = [[False for _ in range(m)] for _ in range(n)]\n target_letter = grid[0][0]\n\n def dfs(x, y):\n if x >=...
trial_gpt4o_4
{ "original_instruction": "", "prompt_id": "00010979", "row_id": 10979, "seed_ids": "[7238]" }
0.829985
Codeforces_10979
I
[ "is_uniform_path", "uniform_path" ]
2
[ [ "uniform_path", "is_uniform_path" ] ]
1
[]
false
[]
false
pytest
true
[]
true
521a1218ecb04ca4934f2ee727d63e409770bde1
f52b477c2a6a38386a14681f3ca74a62b83884fa
v1.0
instruct
Codeforces
Codeforces_11053_I
You are given several queries. In each query, you are given two positive integers `x` and `y`. Your task is to find the sum of all prime numbers between `x` and `y` (inclusive) for each query. If there are no prime numbers in the given range, return 0 for that query. A prime number is a natural number greater than 1 t...
def sieve_of_eratosthenes(n): """ Returns a list of primes up to n using the Sieve of Eratosthenes """ is_prime = [True] * (n + 1) p = 2 while p * p <= n: if is_prime[p]: for i in range(p * p, n + 1, p): is_prime[i] = False p += 1 prime_nums = [p for p in ...
def test_sum_primes_queries(): queries = [(10, 20), (21, 29), (1, 3)] expected = [60, 52, 5] assert sum_primes_queries(3, queries) == expected def test_sum_primes_queries_single_range(): queries = [(10, 10)] expected = [0] assert sum_primes_queries(1, queries) == expected def test_sum_primes_q...
[ { "docstring": "Returns a list of primes up to n using the Sieve of Eratosthenes ", "function_declaration": "def sieve_of_eratosthenes(n):", "function_name": "sieve_of_eratosthenes", "parameter_list": "(n)" }, { "docstring": "Returns the sum of primes in the range [x, y] ", "function_dec...
[ 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": "def sum_primes_in_range(x, y):\n \"\"\"\n Return the sum of all prime numbers between x and y (inclusive).\n \"\"\"\n def is_prime(n):\n if...
trial_gpt4o_5
{ "original_instruction": "", "prompt_id": "00011053", "row_id": 11053, "seed_ids": "[4362]" }
0.616814
Codeforces_11053
I
[ "sieve_of_eratosthenes", "sum_primes_in_range", "process_queries", "sum_primes_queries" ]
4
[ [ "process_queries", "sieve_of_eratosthenes" ], [ "process_queries", "sum_primes_in_range" ], [ "sum_primes_queries", "process_queries" ] ]
3
[ "process_queries" ]
false
[]
false
pytest
false
[]
true
0b54e3265d1a6e9a77679b3f5b3509cfe7de2f7f
ca19d0884d709ee763f9f211542b50b0dfa181be
v1.0
instruct
Codeforces
Codeforces_11064_I
In a galaxy far, far away, a rebel named Lea is trying to communicate with her team members on different planets. She uses a special communication device that sends messages to the team members. The device operates on a sequence of unique prime numbers to encrypt the messages. Lea wants to find out the K-th prime numb...
def sieve_of_eratosthenes(max_num): """ Generate all prime numbers up to max_num using the Sieve of Eratosthenes. """ is_prime = [True] * (max_num + 1) p = 2 while p * p <= max_num: if is_prime[p] == True: for i in range(p * p, max_num + 1, p): is_prime[i] = F...
from solution import kth_prime def test_kth_prime_small(): assert kth_prime(1) == 2 assert kth_prime(2) == 3 assert kth_prime(3) == 5 assert kth_prime(4) == 7 assert kth_prime(5) == 11 def test_kth_prime_medium(): assert kth_prime(100) == 541 assert kth_prime(500) == 3571 def test_kth_pri...
[ { "docstring": "Generate all prime numbers up to max_num using the Sieve of Eratosthenes.", "function_declaration": "def sieve_of_eratosthenes(max_num):", "function_name": "sieve_of_eratosthenes", "parameter_list": "(max_num)" }, { "docstring": "Returns the k-th prime number.", "function...
[ 0, 1, 0, 0, 1, 0, 0, 1, 0, 1 ]
4
medium
0.4
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def find_kth_prime(k):\n \"\"\"\n Returns the k-th prime number.\n \"\"\"\n if k < 1:\n raise ValueError(\"K must be a positive integer.\")...
trial_gpt4o_4
{ "original_instruction": "", "prompt_id": "00011064", "row_id": 11064, "seed_ids": "[2358]" }
0.567446
Codeforces_11064
I
[ "sieve_of_eratosthenes", "kth_prime" ]
2
[ [ "kth_prime", "sieve_of_eratosthenes" ] ]
1
[]
false
[]
false
pytest
true
[]
true
03adb1bdafbd4a87bd85cc6b7b68b94bd4974469
9e9c46df9738847e4c5cae7be5294f7cd0783b96
v1.0
instruct
Codeforces
Codeforces_11113_I
You are given an array of n integers and a sequence of q queries. Each query contains two integers l and r (1 ≤ l ≤ r ≤ n). For each query, you need to calculate the sum of the array elements from index l to index r (inclusive). Given the array size and the number of queries could be large, consider optimizing the sol...
def preprocess_array(arr): """ Preprocess the array to create a prefix sum array. """ prefix_sum = [0] * (len(arr) + 1) for i in range(1, len(arr) + 1): prefix_sum[i] = prefix_sum[i - 1] + arr[i - 1] return prefix_sum def range_sum(query, prefix_sum): """ Compute the sum of the ...
def test_preprocess_array(): assert preprocess_array([1, 2, 3, 4, 5]) == [0, 1, 3, 6, 10, 15] def test_range_sum_full_array(): arr = [1, 2, 3, 4, 5] prefix_sum = preprocess_array(arr) assert range_sum((1, 5), prefix_sum) == 15 def test_range_sum_partial_array(): arr = [1, 2, 3, 4, 5] prefix_su...
[ { "docstring": "Preprocess the array to create a prefix sum array.", "function_declaration": "def preprocess_array(arr):", "function_name": "preprocess_array", "parameter_list": "(arr)" }, { "docstring": "Compute the sum of the array elements from index l to r inclusive using the prefix sum ...
[ 1, 1, 1, 0, 1, 1, 1, 1 ]
7
easy
0.875
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def preprocess(arr):\n \"\"\"\n Preprocess the array to create prefix sums.\n \"\"\"\n n = len(arr)\n prefix_sums = [0] * (n + 1)\n for i in...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00011113", "row_id": 11113, "seed_ids": "[2423]" }
0.721937
Codeforces_11113
I
[ "preprocess_array", "range_sum", "process_queries" ]
3
[ [ "process_queries", "preprocess_array" ], [ "process_queries", "range_sum" ] ]
2
[ "process_queries" ]
false
[]
false
pytest
false
[]
true
b98ab11b9a8da60653db8662d16d982720574a58
2f9ecaebbb28a84264e053f0e75f6b1fe493c2a7
v1.0
instruct
Codeforces
Codeforces_11166_I
Mira wants to design a new video game with an expansive world map consisting of interconnected dungeons. Each dungeon is represented as a node, and each direct path between two dungeons is represented as an undirected edge. Mira needs to ensure that the game player can reach every dungeon from any starting dungeon; the...
def find_redundant_connections(n, m, connections): parent = list(range(n + 1)) def find(x): if parent[x] != x: parent[x] = find(parent[x]) return parent[x] def union(x, y): rootX = find(x) rootY = find(y) if rootX != rootY: parent[rootY] = ro...
import pytest from solution import handle_io def test_example(): input_data = "5 6\n1 2\n1 3\n2 3\n2 4\n3 4\n4 5" expected_output = "2\n2 3\n3 4" assert handle_io(input_data) == expected_output def test_no_connections(): input_data = "5 0" expected_output = "0" assert handle_io(input_data) == ...
[ { "docstring": null, "function_declaration": "def find_redundant_connections(n, m, connections):", "function_name": "find_redundant_connections", "parameter_list": "(n, m, connections)" }, { "docstring": null, "function_declaration": "def handle_io(input_data):", "function_name": "ha...
[ 0, 1, 1, 0, 0, 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": "def find_redundant_connections(n, m, connections):\n from collections import defaultdict, deque\n \n def build_graph(n, connections):\n graph ...
trial_gpt4o_5
{ "original_instruction": "", "prompt_id": "00011166", "row_id": 11166, "seed_ids": "[6927]" }
0.583165
Codeforces_11166
I
[ "find_redundant_connections", "handle_io" ]
2
[ [ "handle_io", "find_redundant_connections" ] ]
1
[]
false
[]
false
pytest
true
[]
true
de992ccf522d4bd7c107370a2b906e30dd7777f9
4aea3623f86d287d7d954ef79fcbb956f7057de4
v1.0
instruct
Codeforces
Codeforces_11176_I
You are given an array of n integers (1 ≤ n ≤ 100). You can perform the following operation on any two adjacent elements of the array: - Choose two adjacent elements, a[i] and a[i+1] (1 ≤ i < n), and swap them if a[i] > a[i+1]. Your task is to sort the array in non-decreasing order using the above operation. You need...
def bubble_sort_with_steps(arr): """ Sort the array using bubble sort and print each step where a swap is performed. """ n = len(arr) made_swap = True while made_swap: made_swap = False for i in range(n - 1): if arr[i] > arr[i + 1]: arr[i], arr[i ...
from solution import sort_array_with_steps def test_already_sorted(): # Capture the output of the function import io import sys captured_output = io.StringIO() sys.stdout = captured_output sort_array_with_steps(5, [1, 2, 3, 4, 5]) sys.stdout = sys.__stdout__ assert captured_output.getva...
[ { "docstring": "Sort the array using bubble sort and print each step where a swap is performed.", "function_declaration": "def bubble_sort_with_steps(arr):", "function_name": "bubble_sort_with_steps", "parameter_list": "(arr)" }, { "docstring": null, "function_declaration": "def sort_arr...
[ 1, 1, 1, 0, 1, 1, 0, 1, 1, 1 ]
8
easy
0.8
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def bubble_sort_with_steps(array):\n \"\"\"\n Sorts the array using bubble sort and prints the array after every swap operation until the array is sorte...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00011176", "row_id": 11176, "seed_ids": "[2715]" }
0.694835
Codeforces_11176
I
[ "bubble_sort_with_steps", "sort_array_with_steps" ]
2
[ [ "sort_array_with_steps", "bubble_sort_with_steps" ] ]
1
[]
false
[]
false
pytest
true
[]
true
15ea012e2e6a0423eeee7066caba7b983f6e2348
a36c8b18a35f6079a44791bb1737a425e65ef7ea
v1.0
instruct
Codeforces
Codeforces_11287_I
Given a directed graph represented as an adjacency list, determine whether the graph contains a cycle. Input: - The first line contains an integer \( n \) (\( 1 \le n \le 10^5 \)) — the number of nodes. - The second line contains an integer \( m \) (\( 0 \le m \le 2 \times 10^5 \)) — the number of directed edges. - Th...
def is_cyclic(n, edges): from collections import defaultdict, deque graph = defaultdict(list) indegree = [0] * (n + 1) for u, v in edges: graph[u].append(v) indegree[v] += 1 queue = deque([i for i in range(1, n + 1) if indegree[i] == 0]) count = 0 while qu...
from solution import contains_cycle def test_cycle_present(): assert contains_cycle(4, 4, [(1, 2), (2, 3), (3, 4), (4, 2)]) == "YES" def test_no_cycle(): assert contains_cycle(3, 2, [(1, 2), (2, 3)]) == "NO" def test_single_node_no_cycle(): assert contains_cycle(1, 0, []) == "NO" def test_disconnected_g...
[ { "docstring": null, "function_declaration": "def is_cyclic(n, edges):", "function_name": "is_cyclic", "parameter_list": "(n, edges)" }, { "docstring": null, "function_declaration": "def contains_cycle(n, m, edge_list):", "function_name": "contains_cycle", "parameter_list": "(n, ...
[ 1, 1, 1, 1, 0, 1, 1, 1, 1, 1 ]
9
easy
0.9
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def has_cycle(n, m, edges):\n from collections import defaultdict, deque\n\n adj_list = defaultdict(list)\n for u, v in edges:\n adj_list[u].a...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00011287", "row_id": 11287, "seed_ids": "[3238]" }
0.727997
Codeforces_11287
I
[ "is_cyclic", "contains_cycle" ]
2
[ [ "contains_cycle", "is_cyclic" ] ]
1
[]
false
[]
false
pytest
true
[]
true
5c0f42c61bd9024974282d5bc2df92f10b5cf2bf
0c4952e135c70e731546d7d34ea0b75947e5733f
v1.0
instruct
Codeforces
Codeforces_11399_I
A group of biologists is studying the movement patterns of a species of migratory birds. They have recorded the locations of these birds over a period of n days. On each day, the position of each bird is recorded as a point (x, y) on a 2D plane. Over time, they have hypothesized that birds tend to form clusters, and th...
import math from collections import defaultdict def calculate_distance(bird1, bird2): return math.sqrt((bird1[0] - bird2[0])**2 + (bird1[1] - bird2[1])**2) def find_clusters(n, d, coords): def dfs(bird_index, visited, cluster): visited[bird_index] = True cluster.append(bird_index) for ...
from solution import find_clusters def test_find_clusters_example(): n = 10 d = 2 coords = [(1, 1), (2, 2), (3, 3), (4, 4), (5, 5), (-1, -1), (-2, -2), (-3, -3), (-4, -4), (-5, -5)] expected_clusters = 2 expected_sizes = [5, 5] assert find_clusters(n, d, coords) == (expected_clusters, expected_...
[ { "docstring": null, "function_declaration": "def calculate_distance(bird1, bird2):", "function_name": "calculate_distance", "parameter_list": "(bird1, bird2)" }, { "docstring": null, "function_declaration": "def find_clusters(n, d, coords):", "function_name": "find_clusters", "p...
[ 1, 0, 0, 1, 1, 1, 0, 1, 1, 0 ]
6
medium
0.6
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "import math\n\ndef find_clusters(n, d, coordinates):\n \"\"\"\n Find the number of clusters and their sizes.\n \n Args:\n n (int) : Number of b...
trial_gpt4o_7
{ "original_instruction": "", "prompt_id": "00011399", "row_id": 11399, "seed_ids": "[1389]" }
0.629237
Codeforces_11399
I
[ "calculate_distance", "find_clusters" ]
2
[ [ "find_clusters", "calculate_distance" ] ]
1
[]
false
[]
false
pytest
true
[]
true
aa4bc4bc53c4098a9ced9c0f55dd9b8e3a67ecda
3039aea0f7245c56cb8799a0d52cc5d311375d39
v1.0
instruct
Codeforces
Codeforces_11402_I
Valera likes to play with numbers. One day, he found an interesting sequence and wants to know more about it. The sequence is constructed as follows: - It starts with a positive integer x. - For each next term in the sequence, Valera adds up the digits of the current term and appends this sum to the current term to fo...
def sum_of_digits(n): """ Returns the sum of the digits of a number n. """ return sum(int(digit) for digit in str(n)) def distinct_terms_count(x, k): """ Returns the number of distinct terms in the sequence after k iterations starting with x. """ sequence = set() current_term = x ...
from solution import distinct_terms_count def test_small_numbers(): assert distinct_terms_count(1, 1) == 2 assert distinct_terms_count(2, 2) == 3 def test_larger_number(): assert distinct_terms_count(13, 2) == 3 # Sequence: 13, 139, 1391 def test_large_k(): assert distinct_terms_count(9, 10) == 11 ...
[ { "docstring": "Returns the sum of the digits of a number n.", "function_declaration": "def sum_of_digits(n):", "function_name": "sum_of_digits", "parameter_list": "(n)" }, { "docstring": "Returns the number of distinct terms in the sequence after k iterations starting with x.", "functio...
[ 1, 0, 1, 0, 1, 1, 0, 0, 1, 1 ]
6
medium
0.6
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def digit_sum(n):\n \"\"\"\n Returns the sum of the digits of a number n.\n \"\"\"\n return sum(map(int, str(n)))\n\ndef count_distinct_terms(x, k...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00011402", "row_id": 11402, "seed_ids": "[6097]" }
0.646523
Codeforces_11402
I
[ "sum_of_digits", "distinct_terms_count" ]
2
[ [ "distinct_terms_count", "sum_of_digits" ] ]
1
[]
false
[]
false
pytest
true
[]
true
89a9c7d30339778f19ca92e1d047c7dd37e86779
0a533d2229540da4a1ed618aa8cf853b0dbed4c0
v1.0
instruct
Codeforces
Codeforces_11404_I
Robin is a boy who loves arranging books on a bookshelf. One day, Robin decided to rearrange his bookshelf which consists of $$$n$$$ books. Each book is characterized by its height and width. Robin wants to place all the books in a row such that the total height of the books in the row is minimized. Robin also has an...
from itertools import permutations def minimum_bookshelf_height(n, heights, widths, constraints): # Create an adjacency list for the constraints graph = {i: [] for i in range(n)} for u, v in constraints: graph[u - 1].append(v - 1) graph[v - 1].append(u - 1) # Helper function to che...
from solution import minimum_possible_height def test_single_book(): assert minimum_possible_height(1, [10], [5], 0, []) == 10 def test_no_constraints(): assert minimum_possible_height(3, [10, 50, 20], [5, 5, 5], 0, []) == 50 def test_given_example(): assert minimum_possible_height(4, [10, 20, 30, 40], [...
[ { "docstring": null, "function_declaration": "def minimum_bookshelf_height(n, heights, widths, constraints):", "function_name": "minimum_bookshelf_height", "parameter_list": "(n, heights, widths, constraints)" }, { "docstring": null, "function_declaration": "def minimum_possible_height(n...
[ 1, 0, 1, 1, 0, 1, 1, 1, 1 ]
7
easy
0.778
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def min_bookshelf_height(n, heights, widths, m, constraints):\n # Adjacency list for the graph of constrained books\n adj = {i: [] for i in range(n)}\n ...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00011404", "row_id": 11404, "seed_ids": "[8050]" }
0.686115
Codeforces_11404
I
[ "minimum_bookshelf_height", "minimum_possible_height" ]
2
[ [ "minimum_possible_height", "minimum_bookshelf_height" ] ]
1
[]
false
[]
false
pytest
true
[]
true
c38af5c15e1bdb55453a07fd8675bfe5f8c94e2d
0da4cfb5fa9b3b89d0686913ba0f3393d94df110