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_1793_I
You are given an integer array `nums` consisting of `n` elements, and two integers `k` and `t`. Your task is to determine whether there are two distinct indices `i` and `j` in the array such that the absolute difference between `nums[i]` and `nums[j]` is at most `t`, and the absolute difference between `i` and `j` is a...
def contains_nearby_almost_duplicate(nums, k, t): """ Check if there are two distinct indices i and j in the array such that the absolute difference between nums[i] and nums[j] is at most t, and the absolute difference between i and j is at most k. """ if k == 0 or t < 0: return False ...
import pytest from solution import solve, parse_input def test_solve(): input_str = "2\n4 3 0\n1 2 3 1\n4 2 2\n1 5 9 1\n" test_cases = parse_input(input_str) result = solve(test_cases) assert result == [True, False] def test_parse_input(): input_str = "2\n4 3 0\n1 2 3 1\n4 2 2\n1 5 9 1\n" resu...
[ { "docstring": "Check if there are two distinct indices i and j in the array such that \nthe absolute difference between nums[i] and nums[j] is at most t, and \nthe absolute difference between i and j is at most k.", "function_declaration": "def contains_nearby_almost_duplicate(nums, k, t):", "function_...
[ 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 check_cases(q, test_cases):\n result = []\n \n for case in test_cases:\n n, k, t, nums = case\n found = False\n for i in ran...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00001793", "row_id": 1793, "seed_ids": "[3487]" }
0.739125
Codeforces_1793
I
[ "contains_nearby_almost_duplicate", "solve", "parse_input" ]
3
[ [ "solve", "contains_nearby_almost_duplicate" ] ]
1
[ "parse_input" ]
false
[]
false
pytest
true
[]
true
de95b83f92f2f2be0cbfc614ea87ddd7aa1f497e
3526528289cbcfa8ba9c49f205ed527e9d960299
v1.0
instruct
Codeforces
Codeforces_1800_I
Design and implement a function that takes an integer array as input, and returns a new array which contains only the prime numbers from the input array, sorted in ascending order. Note that zero and negative numbers should not be considered prime. Your function should have the following signature: ```python def prime_...
from typing import List def is_prime(n: int) -> bool: """ Helper function to determine if a number is prime. """ if n <= 1: return False if n == 2: return True # Special case for 2, which is prime if n % 2 == 0: return False # No even number larger than 2 is prime ...
from solution import prime_sort def test_prime_sort_basic(): assert prime_sort([2, 4, 3, 1, 7, 0]) == [2, 3, 7] def test_prime_sort_with_negatives_and_non_primes(): assert prime_sort([-1, -2, 16, 17, 9]) == [17] def test_prime_sort_mixed_values(): assert prime_sort([10, 11, 10, 0, 5]) == [5, 11] def tes...
[ { "docstring": "Helper function to determine if a number is prime.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Returns a new list containing only the prime numbers from the input list,\nsorted in ascending order.", ...
[ 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": "from typing import List\n\ndef is_prime(n: int) -> bool:\n \"\"\"Returns True if n is a prime number, else False.\"\"\"\n if n <= 1:\n return Fal...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00001800", "row_id": 1800, "seed_ids": "[7844]" }
0.730369
Codeforces_1800
I
[ "is_prime", "prime_sort" ]
2
[ [ "prime_sort", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
874acd67335586b8ffee9133577dd3c73b4f7a2b
e4526475632f078dccf34b76e71e5f4e3e44c24e
v1.0
instruct
Codeforces
Codeforces_1868_I
You are given an array of integers `arr` of length `n` (1 ≤ n ≤ 100,000). You need to process `q` queries. Each query is described by integers `l` and `r` (1 ≤ l ≤ r ≤ n). For each query, you have to return the product of all elements in the subarray `arr[l:r]` modulo `1000000007`. The first line contains two integers...
MOD = 1000000007 def preprocess(arr): n = len(arr) prefix_prod = [1] * (n + 1) for i in range(1, n + 1): prefix_prod[i] = (prefix_prod[i - 1] * arr[i - 1]) % MOD return prefix_prod def product_query(prefix_prod, l, r): if l == 1: return prefix_prod[r] return (prefix_prod[r] *...
from solution import preprocess, product_query, process_queries def test_preprocess(): arr = [1, 2, 3, 4, 5] expected = [1, 1, 2, 6, 24, 120] assert preprocess(arr) == expected def test_product_query(): prefix_prod = preprocess([1, 2, 3, 4, 5]) assert product_query(prefix_prod, 1, 3) == 6 asse...
[ { "docstring": null, "function_declaration": "def preprocess(arr):", "function_name": "preprocess", "parameter_list": "(arr)" }, { "docstring": null, "function_declaration": "def product_query(prefix_prod, l, r):", "function_name": "product_query", "parameter_list": "(prefix_prod...
[ 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": "MOD = 1000000007\n\ndef product_subarray(arr, queries):\n n = len(arr)\n prefix_prods = [1] * (n + 1)\n \n for i in range(1, n + 1):\n pref...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00001868", "row_id": 1868, "seed_ids": "[4370]" }
0.671089
Codeforces_1868
I
[ "preprocess", "product_query", "process_queries" ]
3
[ [ "process_queries", "preprocess" ], [ "process_queries", "product_query" ] ]
2
[ "process_queries" ]
false
[]
false
pytest
true
[]
true
b167127aaf0a8506eca5a271071d000e4e6f1dd5
a3ce2042904cb682478d992e75d0650f2aa85b27
v1.0
instruct
Codeforces
Codeforces_1895_I
Bob is a botanist studying a unique type of plant with an unusual growth pattern. The plant is represented as a binary tree where each node corresponds to a part of the plant. Each node has a value representing the number of days since that part of the plant started growing. Bob wants to understand how balanced the gro...
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 n = len(nodes) node_dict = {i: TreeNode(val=nodes[i-1][0]) for i in range(1, n+1)} for i in...
def test_balanced_tree(): n = 5 nodes = [ (0, 2, 3), (1, 4, 0), (2, 0, 5), (3, 0, 0), (2, 0, 0) ] assert plant_balance(n, nodes) == "Balanced" def test_not_balanced_tree(): n = 3 nodes = [ (0, 2, 3), (2, 0, 0), (5, 0, 0) ]...
[]
[ 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": "class TreeNode:\n def __init__(self, value):\n self.value = value\n self.left = None\n self.right = None\n\ndef build_tree(nodes):\n ...
trial_gpt4o_3
{ "original_instruction": "", "prompt_id": "00001895", "row_id": 1895, "seed_ids": "[3319]" }
0.697257
Codeforces_1895
I
[ "build_tree", "subtree_info", "average_subtree", "check_balanced", "plant_balance" ]
5
[ [ "average_subtree", "subtree_info" ], [ "check_balanced", "average_subtree" ], [ "check_balanced", "build_tree" ], [ "plant_balance", "check_balanced" ] ]
4
[]
false
[ "TreeNode" ]
true
pytest
false
[]
true
7beb1ca14f91d17d7b133c8cc894dcabdfefcbb2
fc43ccb57111fed65c73fa69a088c9c7cd106480
v1.0
instruct
Codeforces
Codeforces_1955_I
A new popular tourist attraction in town, the Museum of Fiendish Puzzles, features a row of interactive panels where tourists can play a game. Each panel displays an arrangement of colored tiles in a grid, where each tile has a specific color represented by an integer. The game is to determine if there exists any row ...
def is_symmetric(grid): # Check for symmetric rows for row in grid: if row == row[::-1]: return "YES" # Check for symmetric columns num_columns = len(grid[0]) for col in range(num_columns): column = [row[col] for row in grid] if column == column[::-1]: ...
from solution import main def test_symmetric_rows(): input_data = "1\n3 3\n1 2 1\n3 4 3\n5 6 5" assert main(input_data) == ["YES"] def test_no_symmetric_row_col(): input_data = "1\n2 4\n1 2 3 4\n4 3 2 1" assert main(input_data) == ["NO"] def test_symmetric_columns(): input_data = "1\n3 3\n1 2 1\n...
[ { "docstring": null, "function_declaration": "def is_symmetric(grid):", "function_name": "is_symmetric", "parameter_list": "(grid)" }, { "docstring": null, "function_declaration": "def process_grids(grids):", "function_name": "process_grids", "parameter_list": "(grids)" }, { ...
[ 0, 0, 1, 1, 0, 1, 1, 1, 0, 0 ]
5
medium
0.5
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_symmetric(grid):\n \"\"\"\n Checks if there exists at least one symmetric row or column in the grid.\n \"\"\"\n n = len(grid)\n m = len(...
trial_gpt4o_6
{ "original_instruction": "", "prompt_id": "00001955", "row_id": 1955, "seed_ids": "[7161]" }
0.694504
Codeforces_1955
I
[ "is_symmetric", "process_grids", "main" ]
3
[ [ "process_grids", "is_symmetric" ] ]
1
[]
false
[]
false
pytest
true
[]
true
f7a22b95f150cb2dd075c5c01ffae2c74cfcc0d0
335499f6e04c3233c9e0dfcede2ceca66499fb68
v1.0
instruct
Codeforces
Codeforces_1958_I
You are given an integer array $$$arr$$$ of size $$$n$$$. Let's define a subarray $$$arr[l:r]$$$ (where $$$1 \leq l \leq r \leq n$$$) as *good* if it contains at least one element which is the sum of any two elements within that subarray. Calculate the number of *good* subarrays. The first line contains a single int...
def count_good_subarrays(arr): n = len(arr) good_count = 0 for i in range(n): for j in range(i, n): seen_sums = set() is_good = False for k in range(i, j + 1): for l in range(i, j + 1): if k != l: if...
from solution import number_of_good_subarrays def test_small_array(): assert number_of_good_subarrays(3, [1, 2, 3]) == 3 assert number_of_good_subarrays(4, [1, 1, 1, 1]) == 6 assert number_of_good_subarrays(2, [1, 2]) == 1 def test_single_element(): assert number_of_good_subarrays(1, [5]) == 0 def te...
[ { "docstring": null, "function_declaration": "def count_good_subarrays(arr):", "function_name": "count_good_subarrays", "parameter_list": "(arr)" }, { "docstring": null, "function_declaration": "def number_of_good_subarrays(n, arr):", "function_name": "number_of_good_subarrays", ...
[ 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 count_good_subarrays(arr):\n n = len(arr)\n good_subarray_count = 0\n\n for start in range(n):\n found_sums = set()\n for end in ra...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00001958", "row_id": 1958, "seed_ids": "[5374]" }
0.69901
Codeforces_1958
I
[ "count_good_subarrays", "number_of_good_subarrays" ]
2
[ [ "number_of_good_subarrays", "count_good_subarrays" ] ]
1
[]
false
[]
false
pytest
true
[]
true
467d83e8327609158eaa842410d2a40f015578b0
26edd34647c2ce4313cb19e549f9a07be55e4f9a
v1.0
instruct
Codeforces
Codeforces_1964_I
You are given a matrix of size $$$n \times m$$$ containing integers. Your task is to perform multiple queries on this matrix, where each query will ask you to calculate the sum of integers in a submatrix defined by its top-left and bottom-right coordinates. The first line of input contains two integers $$$n$$$ and $$$...
def preprocess_matrix(matrix): """ Preprocess the matrix to create a prefix sum matrix. :param matrix: 2D list of integers :return: 2D prefix sum matrix """ n = len(matrix) m = len(matrix[0]) prefix_sum = [[0] * (m+1) for _ in range(n+1)] for i in range(1, n+1): for j in...
from solution import preprocess_matrix, sum_submatrix, solve def test_sum_submatrix(): matrix = [ [1, 2, 3], [4, 5, 6], [7, 8, 9] ] prefix_sum = preprocess_matrix(matrix) assert sum_submatrix(prefix_sum, 1, 1, 2, 2) == 12 # Sum of submatrix (1, 1) to (2, 2) assert sum_subma...
[ { "docstring": "Preprocess the matrix to create a prefix sum matrix.\n:param matrix: 2D list of integers\n:return: 2D prefix sum matrix", "function_declaration": "def preprocess_matrix(matrix):", "function_name": "preprocess_matrix", "parameter_list": "(matrix)" }, { "docstring": "Calculate ...
[ 1, 1, 1, 1, 1, 0, 1, 1, 1, 0 ]
8
easy
0.8
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def preprocess_matrix(matrix):\n \"\"\"\n Preprocess the given matrix to calculate the prefix sum matrix.\n \"\"\"\n n = len(matrix)\n m = len(...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00001964", "row_id": 1964, "seed_ids": "[7519]" }
0.653916
Codeforces_1964
I
[ "preprocess_matrix", "sum_submatrix", "solve" ]
3
[ [ "solve", "preprocess_matrix" ], [ "solve", "sum_submatrix" ] ]
2
[]
false
[]
false
pytest
true
[]
true
bf357c6c1703954a6bfd310f01522eb529d4b3cc
fad9ddd5ca614bae8839e9f0220c6c73ecd14397
v1.0
instruct
Codeforces
Codeforces_1985_I
In a country called Arithmus, there are n cities (numbered from 1 to n) connected by m directed roads, where each road has a certain length. Additionally, each road connects two different cities. The road network is currently represented as a directed graph with n vertices and m edges. The king of Arithmus wants to im...
def find_connected_components(n, edges): from collections import defaultdict, deque graph = defaultdict(list) for u, v, l in edges: graph[u].append(v) graph[v].append(u) visited = [False] * (n + 1) components = [] def bfs(start): queue = deque([start]) ...
def test_min_train_routes(): input_data = "4 4 1\n1 2 5\n2 3 3\n3 4 7\n4 1 2\n" expected_result = "1 2 5\n2 3 3\n3 4 7\n4 1 2" assert solve(input_data) == expected_result def test_min_train_routes_impossible(): input_data = "4 2 0\n1 2 5\n3 4 7\n" expected_result = "IMPOSSIBLE" assert solve(inp...
[ { "docstring": null, "function_declaration": "def find_connected_components(n, edges):", "function_name": "find_connected_components", "parameter_list": "(n, edges)" }, { "docstring": null, "function_declaration": "def min_train_routes(n, m, p, edges):", "function_name": "min_train_r...
[ 0, 0, 0, 0, 1, 0, 0, 0, 0, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def find_connected_components(n, edges):\n parent = list(range(n))\n\n def find(x):\n if parent[x] != x:\n parent[x] = find(parent[x])...
trial_gpt4o_4
{ "original_instruction": "", "prompt_id": "00001985", "row_id": 1985, "seed_ids": "[72]" }
0.750204
Codeforces_1985
I
[ "find_connected_components", "min_train_routes", "solve" ]
3
[ [ "min_train_routes", "find_connected_components" ], [ "solve", "min_train_routes" ] ]
2
[]
false
[]
false
pytest
false
[]
true
dd34e97ed840577288508091138c46f7febefb7d
a26a630eadd00d5d74e6403e4b567b5cbe2ec61f
v1.0
instruct
Codeforces
Codeforces_2009_I
In a coastal city, the local government has decided to construct a series of interconnected sea bridges and islands to boost maritime navigation. Each bridge connects exactly two islands and there is no more than one bridge directly connecting any pair of islands. The mayor, being a fan of statistics, wants to determin...
def floyd_warshall(n, edges): INF = float('inf') dist = [[INF] * n for _ in range(n)] for i in range(n): dist[i][i] = 0 for u, v in edges: dist[u - 1][v - 1] = 1 dist[v - 1][u - 1] = 1 for k in range(n): for i in range(n): for j in r...
from solution import get_shortest_paths def test_example_case_1(): n = 4 m = 4 bridges = [(1, 2), (2, 3), (3, 4), (4, 1)] expected = [ [0, 1, 2, 1], [1, 0, 1, 2], [2, 1, 0, 1], [1, 2, 1, 0] ] assert get_shortest_paths(n, m, bridges) == expected def test_no_path_...
[ { "docstring": null, "function_declaration": "def floyd_warshall(n, edges):", "function_name": "floyd_warshall", "parameter_list": "(n, edges)" }, { "docstring": null, "function_declaration": "def get_shortest_paths(n, m, bridges):", "function_name": "get_shortest_paths", "parame...
[ 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 shortest_path_between_islands(n, m, connections):\n inf = float('inf')\n distance = [[inf] * n for _ in range(n)]\n \n for i in range(n):\n ...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00002009", "row_id": 2009, "seed_ids": "[2296]" }
0.783056
Codeforces_2009
I
[ "floyd_warshall", "get_shortest_paths" ]
2
[ [ "get_shortest_paths", "floyd_warshall" ] ]
1
[]
false
[]
false
pytest
true
[]
true
20ae7bf91f7e8ee6c15659a5b4b9cb62fd792419
86aaacaebe253e1e9083ffa6e5f3d455601e1a83
v1.0
instruct
Codeforces
Codeforces_2053_I
Create a program that computes the "weight" of a word, where the weight of a word is defined as the sum of the positions of its characters in the alphabet (a = 1, b = 2, ..., z = 26). Your task is to write a function that takes in a list of words and returns the word with the highest weight. In case of a tie (i.e., mu...
def get_word_weight(word): """ Calculates the weight of a given word. """ return sum(ord(char) - ord('a') + 1 for char in word) def highest_weight_word(words): """ Returns the word with the highest weight. In case of a tie, returns the lexicographically first word. """ word_list = words...
from solution import highest_weight_word def test_highest_weight_word_single_word(): assert highest_weight_word("apple") == "apple" def test_highest_weight_word_multiple_words(): assert highest_weight_word("dog cat zebra apple") == "zebra" def test_highest_weight_word_tie(): assert highest_weight...
[ { "docstring": "Calculates the weight of a given word.", "function_declaration": "def get_word_weight(word):", "function_name": "get_word_weight", "parameter_list": "(word)" }, { "docstring": "Returns the word with the highest weight. In case of a tie, returns the lexicographically first wor...
[ 0, 0, 1, 1, 1, 1, 0, 0, 1, 0 ]
5
medium
0.5
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def word_weight(word):\n \"\"\"\n Computes the weight of a word based on the sum of positions of its characters in the alphabet.\n \n :param word:...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00002053", "row_id": 2053, "seed_ids": "[4293]" }
0.697018
Codeforces_2053
I
[ "get_word_weight", "highest_weight_word" ]
2
[ [ "highest_weight_word", "get_word_weight" ] ]
1
[]
false
[]
false
pytest
true
[]
true
73bdb83aaf087d43223abc18c7322ec3e363e5b2
e8ba562faa605631fa45a47109ecb6bc1ac543cf
v1.0
instruct
Codeforces
Codeforces_2098_I
You are given two integers \(a\) and \(b\) (1 ≤ a, b ≤ 100). You need to determine the smallest integer \(c\) such that both \(a\) and \(b\) are divisors of \(c\). A number \(x\) is said to be a divisor of \(y\) if there exists an integer \(k\) such that \(y = k \times x\). Your task is to find the least common multi...
def gcd(x, y): """ Calculate the Greatest Common Divisor (GCD) of x and y. """ while y: x, y = y, x % y return x def lcm(a, b): """ Returns the Least Common Multiple (LCM) of a and b. """ return abs(a * b) // gcd(a, b)
from solution import lcm def test_lcm_example1(): assert lcm(4, 6) == 12 def test_lcm_example2(): assert lcm(5, 10) == 10 def test_lcm_same_numbers(): assert lcm(7, 7) == 7 def test_lcm_prime_numbers(): assert lcm(7, 13) == 91 def test_lcm_one(): assert lcm(1, 10) == 10 assert lcm(1, 1) == ...
[ { "docstring": "Calculate the Greatest Common Divisor (GCD) of x and y.", "function_declaration": "def gcd(x, y):", "function_name": "gcd", "parameter_list": "(x, y)" }, { "docstring": "Returns the Least Common Multiple (LCM) of a and b.", "function_declaration": "def lcm(a, b):", "f...
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
10
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "import math\n\ndef lcm(a, b):\n \"\"\"\n Returns the least common multiple (LCM) of two integers a and b.\n \"\"\"\n return abs(a*b) // math.gcd(a...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00002098", "row_id": 2098, "seed_ids": "[7213]" }
0.697461
Codeforces_2098
I
[ "gcd", "lcm" ]
2
[ [ "lcm", "gcd" ] ]
1
[]
false
[]
false
pytest
true
[]
true
285eec7b6de14a6cf21ce845fabc6910e95947c6
5f952c6f084acf098214bfc65f557a536f47d5c1
v1.0
instruct
Codeforces
Codeforces_2178_I
In a kingdom, there are multiple cities connected by bidirectional roads. Each road is associated with a toll cost. The kingdom's government decided to build a new road network such that the total toll cost from one specific city, the capital, to all other cities is minimized. They plan to implement this using a Minimu...
def find(parent, i): if parent[i] == i: return i else: 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]: p...
def test_example_case(): n, m = 5, 7 roads = [ (1, 2, 3), (1, 3, 4), (2, 3, 2), (2, 4, 5), (3, 4, 1), (3, 5, 6), (4, 5, 2) ] assert minimum_toll_cost(n, m, roads) == 8 def test_single_city(): n, m = 1, 0 roads = [] assert minimum_toll_...
[ { "docstring": null, "function_declaration": "def find(parent, i):", "function_name": "find", "parameter_list": "(parent, i)" }, { "docstring": null, "function_declaration": "def union(parent, rank, x, y):", "function_name": "union", "parameter_list": "(parent, rank, x, y)" }, ...
[ 0, 0, 0, 1, 0, 0, 0, 0, 1, 0 ]
2
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def find_mst_cost(n, m, roads):\n \"\"\"\n Returns the minimum total toll cost to connect all cities in the kingdom.\n \"\"\"\n # Implementing Kru...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00002178", "row_id": 2178, "seed_ids": "[3816]" }
0.740125
Codeforces_2178
I
[ "find", "union", "minimum_toll_cost" ]
3
[ [ "minimum_toll_cost", "find" ], [ "minimum_toll_cost", "union" ], [ "union", "find" ] ]
3
[]
false
[]
false
pytest
false
[]
true
1e91f54895104938fd90e2d12a0be9e3859f76f0
dcdf5735adcc044fef97926a6fd9c885eaf55e83
v1.0
instruct
Codeforces
Codeforces_2182_I
Given a list of logical expressions in prefix notation, determine the result of each expression. The logical expressions consist of the operators "AND", "OR", and "NOT", as well as the boolean values "TRUE" and "FALSE". - AND: returns TRUE if both operands are TRUE, otherwise returns FALSE. - OR: returns TRUE if at le...
def evaluate_expression(expression): elements = expression.split() def eval_tokens(tokens): token = tokens.pop(0) if token == "TRUE": return True elif token == "FALSE": return False elif token == "AND": return eval_tokens(tokens) ...
from solution import evaluate_expression, evaluate_logical_expressions def test_evaluate_single_true(): assert evaluate_expression("TRUE") == "TRUE" def test_evaluate_single_false(): assert evaluate_expression("FALSE") == "FALSE" def test_simple_and(): assert evaluate_expression("AND TRUE TRUE") == "TRUE...
[ { "docstring": null, "function_declaration": "def evaluate_expression(expression):", "function_name": "evaluate_expression", "parameter_list": "(expression)" }, { "docstring": null, "function_declaration": "def evaluate_logical_expressions(expressions):", "function_name": "evaluate_l...
[ 0, 1, 1, 0, 0, 0, 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 evaluate_expression(tokens):\n token = tokens.pop(0)\n if token == \"TRUE\":\n return True\n elif token == \"FALSE\":\n return Fals...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00002182", "row_id": 2182, "seed_ids": "[2581]" }
0.548345
Codeforces_2182
I
[ "evaluate_expression", "evaluate_logical_expressions" ]
2
[ [ "evaluate_logical_expressions", "evaluate_expression" ] ]
1
[]
false
[]
false
pytest
true
[]
true
76dc5e6a763852f4bfbfe5db846cce171405ffbb
44993f4787aa33fecb3166a15e7d574266ca84eb
v1.0
instruct
Codeforces
Codeforces_2193_I
Alice is an avid gardener who loves to grow a wide variety of flowers. She recently came across a collection of n different types of seeds, each with a respective growth time. From these seeds, she wants to plan her garden such that all grown flowers bloom at the same time in order to maximize the beauty of her garden....
import math from functools import reduce def lcm(a, b): return abs(a * b) // math.gcd(a, b) def lcm_multiple(numbers): return reduce(lcm, numbers) def min_days_to_bloom(n, growth_times): return lcm_multiple(growth_times)
from solution import min_days_to_bloom def test_example_case(): assert min_days_to_bloom(3, [5, 10, 15]) == 30 def test_single_seed_type(): assert min_days_to_bloom(1, [4]) == 4 def test_two_seed_types(): assert min_days_to_bloom(2, [6, 8]) == 24 def test_multiple_seed_types(): assert min_days_to_bl...
[ { "docstring": null, "function_declaration": "def lcm(a, b):", "function_name": "lcm", "parameter_list": "(a, b)" }, { "docstring": null, "function_declaration": "def lcm_multiple(numbers):", "function_name": "lcm_multiple", "parameter_list": "(numbers)" }, { "docstring":...
[ 1, 1, 1, 1, 1, 1, 1, 0, 1 ]
8
easy
0.889
{ "trial_gpt4o_0": null, "trial_gpt4o_1": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared1_results_combined.jsonl", "solution_code": "import math\nfrom functools import reduce\n\ndef lcm(x, y):\n return x * y // math.gcd(x, y)\n\ndef min_days_to_bloom(n, growth_ti...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00002193", "row_id": 2193, "seed_ids": "[6468]" }
0.670291
Codeforces_2193
I
[ "lcm", "lcm_multiple", "min_days_to_bloom" ]
3
[ [ "lcm_multiple", "lcm" ], [ "min_days_to_bloom", "lcm_multiple" ] ]
2
[]
false
[]
false
pytest
true
[]
true
529d567eadc0e74c1ce747c61a59faa1cb058576
da0526971a246ec5fd29bc178476590a91d52acd
v1.0
instruct
Codeforces
Codeforces_2219_I
You are given an array of integers and a series of operations to perform on it. Each operation involves finding the sum of elements in a specified subarray. There are multiple such operations, and you need to process each of them efficiently. The array is 1-indexed, meaning the first element of the array is at positio...
def preprocess_array(arr): """ Preprocess the given array to create a prefix sum array. This prefix sum array will let us quickly find the sum of any subarray. """ n = len(arr) - 1 # because arr is 1-indexed prefix_sum = [0] * (n + 1) # prefix_sum is also 1-indexed for i in range(1, n + 1)...
from solution import solve def test_example_case(): n = 5 q = 3 array = [1, 2, 3, 4, 5] queries = [(1, 3), (2, 4), (3, 5)] expected_results = [6, 9, 12] results = solve(n, q, array, queries) assert results == expected_results def test_single_element_array(): n = 1 q = 1 array =...
[ { "docstring": "Preprocess the given array to create a prefix sum array.\nThis prefix sum array will let us quickly find the sum of any subarray.", "function_declaration": "def preprocess_array(arr):", "function_name": "preprocess_array", "parameter_list": "(arr)" }, { "docstring": "Use the ...
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
10
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def process_queries(n, q, array, queries):\n \"\"\"\n Given a list of integers and subarray sum queries, returns the sum of elements in the specified su...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00002219", "row_id": 2219, "seed_ids": "[4950]" }
0.722505
Codeforces_2219
I
[ "preprocess_array", "query_sum", "solve" ]
3
[ [ "solve", "preprocess_array" ], [ "solve", "query_sum" ] ]
2
[]
false
[]
false
pytest
true
[]
true
b467d9ddaf4268e5aee19d3b25496598585738af
424e492733eb4058c974406107b76d24456eb03a
v1.0
instruct
Codeforces
Codeforces_2254_I
Given an undirected graph with $$$n$$$ nodes (numbered from 1 to $$$n$$$) and $$$m$$$ edges, each edge has a certain weight. The weight of an edge can be either 1 or 2. You are required to find the minimum cost to connect all nodes in the graph using these edges (construct the Minimum Spanning Tree). The first line co...
class UnionFind: def __init__(self, n): self.parent = list(range(n)) self.rank = [1] * n def find(self, u): if self.parent[u] != u: self.parent[u] = self.find(self.parent[u]) return self.parent[u] def union(self, u, v): root_u = self.find(u) root...
def test_case_1(): n, m = 4, 5 edges = [ (1, 2, 1), (1, 3, 2), (2, 3, 1), (2, 4, 2), (3, 4, 1) ] assert minimum_spanning_tree_cost(n, m, edges) == 3 def test_case_2(): n, m = 3, 3 edges = [ (1, 2, 1), (2, 3, 2), (1, 3, 1) ] ...
[]
[ 1, 1, 1, 1, 1, 1, 0, 0, 1, 1 ]
8
easy
0.8
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def find(parent, x):\n if parent[x] != x:\n parent[x] = find(parent, parent[x])\n return parent[x]\n\ndef union(parent, rank, x, y):\n rootX =...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00002254", "row_id": 2254, "seed_ids": "[593]" }
0.83228
Codeforces_2254
I
[ "find_minimum_spanning_tree", "minimum_spanning_tree_cost" ]
2
[ [ "minimum_spanning_tree_cost", "find_minimum_spanning_tree" ] ]
1
[]
false
[ "UnionFind" ]
true
pytest
false
[]
true
fed04c48fe5487499915c0b4cb6e86b26898cb9a
568eca1d85caab859270b6ee90be58cbc1312cb3
v1.0
instruct
Codeforces
Codeforces_2258_I
Emma is learning about prime numbers and wants to generate a prime matrix. A prime matrix is a matrix where all the elements are prime numbers. Emma wants you to help her generate a prime matrix of size n x n with prime numbers increasing row-wise and column-wise. Your task is to write a program to generate such a ma...
def is_prime(num): """ Utility function to check if a number is prime. """ if num < 2: return False for i in range(2, int(num**0.5) + 1): if num % i == 0: return False return True def prime_matrix(n): """ Generate an n x n matrix filled with prime numbers in ...
from solution import is_prime, prime_matrix def test_is_prime(): assert is_prime(2) == True assert is_prime(3) == True assert is_prime(4) == False assert is_prime(11) == True assert is_prime(1) == False def test_prime_matrix_1x1(): expected = [[2]] assert prime_matrix(1) == expected def t...
[ { "docstring": "Utility function to check if a number is prime.", "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": "Generate an n x n matrix filled with prime numbers in increasing order.", "function_declaration": "def...
[ 1, 0, 1, 1, 1, 1, 1, 1, 1, 0 ]
8
easy
0.8
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(num):\n if num <= 1:\n return False\n if num == 2:\n return True\n if num % 2 == 0:\n return False\n for i in ra...
trial_gpt4o_7
{ "original_instruction": "", "prompt_id": "00002258", "row_id": 2258, "seed_ids": "[1709]" }
0.575378
Codeforces_2258
I
[ "is_prime", "prime_matrix" ]
2
[ [ "prime_matrix", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
75b4b7fc0dcd720082f325a12f856945af5769bf
e553ba8da04662cff5df436ecc9ef77bf233599b
v1.0
instruct
Codeforces
Codeforces_2282_I
You are given a binary tree with $$$n$$$ nodes. Each node in the tree has a value associated with it. Your task is to find the maximum sum of values from any path in the binary tree. A path is defined as a sequence of nodes where each pair of adjacent nodes in the sequence has an edge connecting them. The path must con...
class TreeNode: def __init__(self, val=0, left=None, right=None): self.val = val self.left = left self.right = right def build_tree(values, edges): nodes = [TreeNode(val) for val in values] for a, b in edges: a -= 1 b -= 1 connect(nodes[a], nodes[b]) retu...
from solution import TreeNode, build_tree, maxPathSum def test_maxPathSum_single_node(): root = TreeNode(val=5) assert maxPathSum(root) == 5 def test_maxPathSum_two_nodes(): root = TreeNode(val=1) root.left = TreeNode(val=2) assert maxPathSum(root) == 3 def test_maxPathSum_three_nodes(): root...
[]
[ 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": "class TreeNode:\n def __init__(self, value=0):\n self.value = value\n self.left = None\n self.right = None\n\ndef maxPathSum(root):\n ...
trial_gpt4o_3
{ "original_instruction": "", "prompt_id": "00002282", "row_id": 2282, "seed_ids": "[7496]" }
0.705582
Codeforces_2282
I
[ "build_tree", "connect", "maxPathSum" ]
3
[ [ "build_tree", "connect" ] ]
1
[]
false
[ "TreeNode" ]
true
pytest
true
[]
true
4679edc575de00898c997c7be3ff36edaa2a5995
be20edd3eafc83ae06da3d0db4df3c9db153b7d3
v1.0
instruct
Codeforces
Codeforces_2304_I
You are given a list of points on a 2D plane. Your task is to find the maximum number of points that lie on the same straight line. The input consists of a single integer $$$n$$$ ($$$1 \le n \le 300$$$) — the number of points, and then $$$n$$$ pairs of integers representing the coordinates of the points ($$$-10^4 \le x...
from collections import defaultdict from math import gcd def max_points_on_same_line(points): if len(points) <= 2: return len(points) def slope(p1, p2): dx = p2[0] - p1[0] dy = p2[1] - p1[1] if dx == 0: return 'inf' if dy == 0: return 0 g...
from solution import solution def test_example_case(): input_str = "5\n1 1\n2 2\n3 3\n4 2\n5 1" assert solution(input_str) == 3 def test_two_points(): input_str = "2\n1 1\n2 2" assert solution(input_str) == 2 def test_no_duplicate_points(): input_str = "4\n1 1\n2 2\n3 4\n4 5" assert solution(...
[ { "docstring": null, "function_declaration": "def max_points_on_same_line(points):", "function_name": "max_points_on_same_line", "parameter_list": "(points)" }, { "docstring": null, "function_declaration": "def solution(input_str):", "function_name": "solution", "parameter_list":...
[ 0, 0, 1, 1, 0, 1, 0, 1, 1 ]
5
medium
0.556
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def max_points_on_line(points):\n from collections import defaultdict\n from math import gcd\n\n def slope(p1, p2):\n dy = p2[1] - p1[1]\n ...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00002304", "row_id": 2304, "seed_ids": "[1858]" }
0.743231
Codeforces_2304
I
[ "max_points_on_same_line", "solution" ]
2
[ [ "solution", "max_points_on_same_line" ] ]
1
[]
false
[]
false
pytest
true
[]
true
566d0be0b76165001db2301246ef58838c7ceaa2
6249de675c7c497b28731401babbc2f7e625d861
v1.0
instruct
Codeforces
Codeforces_2314_I
In a mysterious land, there are n cities and multiple bidirectional roads connecting pairs of these cities. Each road has a certain toll cost. The king of the land wants to travel from his capital city to all other cities. He demands to find the path that minimizes the maximum toll cost he has to pay on any single road...
def can_travel_with_max_toll(n, roads, max_toll): from collections import deque, defaultdict graph = defaultdict(list) for u, v, w in roads: if w <= max_toll: graph[u].append(v) graph[v].append(u) visited = set() queue = deque([1]) visited.add(1)...
from solution import min_max_toll def test_case_1(): n, m = 3, 3 roads = [(1, 2, 4), (2, 3, 3), (1, 3, 5)] assert min_max_toll(n, m, roads) == 4 def test_case_2(): n, m = 4, 4 roads = [(1, 2, 1), (1, 3, 4), (3, 4, 2), (2, 4, 3)] assert min_max_toll(n, m, roads) == 3 def test_case_3(): n, ...
[ { "docstring": null, "function_declaration": "def can_travel_with_max_toll(n, roads, max_toll):", "function_name": "can_travel_with_max_toll", "parameter_list": "(n, roads, max_toll)" }, { "docstring": null, "function_declaration": "def min_max_toll(n, m, roads):", "function_name": "...
[ 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": "class UnionFind:\n def __init__(self, n):\n self.parent = list(range(n))\n self.rank = [1] * n\n\n def find(self, p):\n if self.par...
trial_gpt4o_4
{ "original_instruction": "", "prompt_id": "00002314", "row_id": 2314, "seed_ids": "[7956]" }
0.736803
Codeforces_2314
I
[ "can_travel_with_max_toll", "min_max_toll" ]
2
[ [ "min_max_toll", "can_travel_with_max_toll" ] ]
1
[]
false
[]
false
pytest
true
[]
true
3761e2a30e3ee61c9752e2332866d5674dc4d798
5b4124fe78a0f9cccff22daa65a5daa596e20005
v1.0
instruct
Codeforces
Codeforces_2344_I
A travel company is developing an itinerary application that helps users plan their trips. One of the features of the application is to group nearby places of interest into clusters so that users can visit multiple places in one trip. You are given a list of places, each represented by their coordinates on a 2D plane, ...
from math import sqrt from collections import deque def euclidean_distance(x1, y1, x2, y2): return sqrt((x1 - x2)**2 + (y1 - y2)**2) def find_clusters(n, t, coordinates): visited = [False] * n clusters = 0 def bfs(start): queue = deque([start]) visited[start] = True while queu...
from solution import number_of_clusters def test_example_input(): n = 5 t = 3 points = [(0, 0), (3, 0), (6, 0), (10, 0), (0, 4)] assert number_of_clusters(n, t, points) == 3 def test_single_point(): n = 1 t = 3 points = [(0, 0)] assert number_of_clusters(n, t, points) == 1 def test_al...
[ { "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 find_clusters(n, t, coordinates):", "function_name": "find_clusters...
[ 1, 0, 0, 1, 0, 1, 0, 1, 1, 1 ]
6
medium
0.6
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "import math\n\ndef find_clusters(n, t, places):\n def euclidean_distance(p1, p2):\n return math.sqrt((p1[0] - p2[0]) ** 2 + (p1[1] - p2[1]) ** 2)\n ...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00002344", "row_id": 2344, "seed_ids": "[6645]" }
0.672023
Codeforces_2344
I
[ "euclidean_distance", "find_clusters", "number_of_clusters" ]
3
[ [ "find_clusters", "euclidean_distance" ], [ "number_of_clusters", "find_clusters" ] ]
2
[]
false
[]
false
pytest
true
[]
true
7dd12232d66646709c3a45a0dd1b16d80d4c2575
f3319202c7a92400aab7b5f016fb4246460cb27f
v1.0
instruct
Codeforces
Codeforces_2360_I
In a magical forest, there are n different types of mythical creatures. Each type of creature has its own characteristic length of life cycle. The life cycle length of the i-th type of creature is denoted by li. Every creature type starts its life cycle at the beginning of the year and lives exactly li years before the...
import math from functools import reduce def lcm(a, b): return abs(a*b) // math.gcd(a, b) def earliest_celebration_year(n, k, life_cycles): # Finding the LCM of all life cycle lengths lcm_all = reduce(lcm, life_cycles) # Find the first year that is multiple of both lcm_all and k if lcm_all % ...
from solution import earliest_celebration_year def test_case_1(): assert earliest_celebration_year(2, 12, [3, 4]) == 12 def test_case_2(): assert earliest_celebration_year(3, 6, [2, 3, 4]) == 12 def test_case_3(): assert earliest_celebration_year(4, 15, [3, 5, 10, 15]) == 30 def test_case_4(): asser...
[ { "docstring": null, "function_declaration": "def lcm(a, b):", "function_name": "lcm", "parameter_list": "(a, b)" }, { "docstring": null, "function_declaration": "def earliest_celebration_year(n, k, life_cycles):", "function_name": "earliest_celebration_year", "parameter_list": "...
[ 0, 0, 0, 0, 0, 0, 1, 0, 0 ]
1
hard
0.111
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "import math\nfrom functools import reduce\n\ndef lcm(a, b):\n \"\"\"Calculate the Least Common Multiple of two integers.\"\"\"\n return a * b // math.gc...
trial_gpt4o_7
{ "original_instruction": "", "prompt_id": "00002360", "row_id": 2360, "seed_ids": "[718]" }
0.624618
Codeforces_2360
I
[ "lcm", "earliest_celebration_year" ]
2
[ [ "earliest_celebration_year", "lcm" ] ]
1
[]
false
[]
false
pytest
true
[]
true
eebec3d6e504c162211b8844a58013581be3e180
43e0fb508ff201969529e733f9ec7fe5664669a5
v1.0
instruct
Codeforces
Codeforces_2411_I
You are organizing a programming competition, and you have a collection of $$$n$$$ problems. Each problem has a difficulty level associated with it, which is any integer between $$$1$$$ and $$$10^6$$$. You want to create the most balanced problem set for the competition. A balanced problem set is defined as a set of ...
def update_difficulties(difficulties, i, d): """ Updates the difficulty of the i-th problem to d. """ difficulties[i] = d def minimum_difficulty_range(difficulties, k): """ Finds the minimum possible difficulty range for any subset of exactly k problems. """ # Sort the list of difficult...
import pytest from solution import update_difficulties, minimum_difficulty_range, handle_queries def test_update_difficulties(): difficulties = [4, 1, 7, 3, 2] update_difficulties(difficulties, 2, 6) assert difficulties == [4, 1, 6, 3, 2] def test_minimum_difficulty_range(): difficulties = [4, 1, 7, 3...
[ { "docstring": "Updates the difficulty of the i-th problem to d.", "function_declaration": "def update_difficulties(difficulties, i, d):", "function_name": "update_difficulties", "parameter_list": "(difficulties, i, d)" }, { "docstring": "Finds the minimum possible difficulty range for any s...
[ 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": "from bisect import bisect_left, bisect_right, insort_left\n\ndef min_difficulty_range(n, q, initial_difficulties, queries):\n difficulties = sorted(initial...
trial_gpt4o_3
{ "original_instruction": "", "prompt_id": "00002411", "row_id": 2411, "seed_ids": "[1509]" }
0.661143
Codeforces_2411
I
[ "update_difficulties", "minimum_difficulty_range", "handle_queries" ]
3
[ [ "handle_queries", "minimum_difficulty_range" ], [ "handle_queries", "update_difficulties" ] ]
2
[ "handle_queries" ]
false
[]
false
pytest
true
[]
true
8cf8760f6f8c814c126d6fc2e0af7590af917f8e
fe63faa21fae074de6381a061b99738f33d9cd30
v1.0
instruct
Codeforces
Codeforces_2445_I
Bob likes to tinker with electronic circuits in his home workshop. He has n resistors, each with a resistance value. Bob wants to create a circuit where the total resistance is as close as possible to a target resistance R. He can arrange the resistors in series or parallel, or even leave some out entirely. The resist...
from itertools import combinations import math def calculate_parallel_resistance(res_list): # Return infinity if the list is empty to avoid division by zero if not res_list: return float('inf') inverse_sum = sum(1/r for r in res_list) if inverse_sum == 0: return float('inf') return ...
from solution import find_closest_resistance def test_single_resistor(): assert find_closest_resistance(1, 10, [10]) == 0 def test_series_and_parallel(): assert find_closest_resistance(3, 4, [1, 2, 3]) == 1 def test_exact_match(): assert find_closest_resistance(2, 10, [10, 15]) == 0 def test_parallel_re...
[ { "docstring": null, "function_declaration": "def calculate_parallel_resistance(res_list):", "function_name": "calculate_parallel_resistance", "parameter_list": "(res_list)" }, { "docstring": null, "function_declaration": "def find_closest_resistance(n, R, resistances):", "function_n...
[ 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 itertools\nimport math\n\ndef closest_resistance(n, R, resistances):\n optimal_diff = float('inf')\n best_combination = ()\n\n for i in range(...
trial_gpt4o_7
{ "original_instruction": "", "prompt_id": "00002445", "row_id": 2445, "seed_ids": "[6102]" }
0.575633
Codeforces_2445
I
[ "calculate_parallel_resistance", "find_closest_resistance" ]
2
[ [ "find_closest_resistance", "calculate_parallel_resistance" ] ]
1
[]
false
[]
false
pytest
true
[]
true
b7121f86062e8e72f4ac21a9b92acab30982ad6a
3a02592e5e5007b626138f4f8b0d513865b4904e
v1.0
instruct
Codeforces
Codeforces_2449_I
You are given an array of integers where the array represents a binary tree in a compressed form. The root of the tree starts at the first element of the array, and each subsequent element either extends the current node or starts a new level in the tree. An element at index i may have one or two children: - If there ...
from collections import deque from typing import List, Optional class TreeNode: def __init__(self, val=0, left=None, right=None): self.val = val self.left = left self.right = right def buildTree(arr: List[int]) -> Optional[TreeNode]: if not arr or arr[0] == -1: return None ...
import pytest from solution import level_order_traversal def test_single_node(): arr = [1] assert level_order_traversal(arr) == [[1]] def test_complete_tree(): arr = [1, 2, 3, 4, 5, 6, 7] assert level_order_traversal(arr) == [[1], [2, 3], [4, 5, 6, 7]] def test_right_heavy_tree(): arr = [1, -1, 2...
[]
[ 0, 1, 1, 1, 0, 0, 0, 0, 1, 1 ]
5
medium
0.5
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "from typing import List, Optional\n\nclass TreeNode:\n def __init__(self, val=0):\n self.val = val\n self.left = None\n self.right = N...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00002449", "row_id": 2449, "seed_ids": "[2114]" }
0.556852
Codeforces_2449
I
[ "buildTree", "level_order_traversal" ]
2
[ [ "level_order_traversal", "buildTree" ] ]
1
[]
false
[ "TreeNode" ]
true
pytest
true
[]
true
71fbb2ee1dba21c7928e51d1ae4f8c62af4ed5b2
02a981ab1a7bdce3a4d59ee31ea83b526df8d581
v1.0
instruct
Codeforces
Codeforces_2496_I
Sarah loves prime numbers and palindrome sequences. She recently came across a sequence of positive integers and wondered if she could extract a sub-sequence from it that is both a prime sequence and a palindrome. A sub-sequence is a sequence that can be derived from another sequence by deleting some or no elements wi...
def is_prime(num): if num < 2: return False for i in range(2, int(num ** 0.5) + 1): if num % i != 0: continue return False return True def longest_palindromic_prime_subsequence(n, arr): primes = [num for num in arr if is_prime(num)] if not primes: re...
from solution import longest_palindromic_prime_subsequence def test_no_primes(): assert longest_palindromic_prime_subsequence(6, [4, 6, 8, 9, 10, 12]) == 0 def test_no_palindrome_with_primes(): assert longest_palindromic_prime_subsequence(6, [2, 3, 5, 7, 11, 13]) == 1 def test_single_prime_sequence(): as...
[ { "docstring": null, "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": null, "function_declaration": "def longest_palindromic_prime_subsequence(n, arr):", "function_name": "longest_palindromic_prime_subsequence", ...
[ 0, 0, 0, 1, 0, 0, 0, 0, 0 ]
1
hard
0.111
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_palindrome(s):\n return s == s[::-1]\n\ndef is_prime(num):\n if num <= 1:\n return False\n for i in range(2, int(num**0.5) + 1):\n ...
trial_gpt4o_4
{ "original_instruction": "", "prompt_id": "00002496", "row_id": 2496, "seed_ids": "[2638]" }
0.681564
Codeforces_2496
I
[ "is_prime", "longest_palindromic_prime_subsequence" ]
2
[ [ "longest_palindromic_prime_subsequence", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
b379d28df640f3dc0ceb17784836c5462790b6fa
0a800a7a4e1fd2a786cb743fc930a65220480bca
v1.0
instruct
Codeforces
Codeforces_2525_I
You have a list of $$$n$$$ integers and you are required to answer $$$q$$$ queries. Each query provides two integers $$$l$$$ and $$$r$$$ and requires you to output whether the sum of the sublist from index $$$l$$$ to index $$$r$$$ (inclusive, 1-based indices) is odd or even. The first line of the input contains two in...
def prefix_sums(arr): """ Compute the prefix sum array of the given array. """ prefix = [0] * (len(arr) + 1) for i in range(1, len(prefix)): prefix[i] = prefix[i-1] + arr[i-1] return prefix def query_sums(prefix, l, r): """ Query the sum for a sublist from l to r (inclusive, 1-b...
from solution import process_queries def test_example_case(): n = 5 q = 3 arr = [1, 2, 3, 4, 5] queries = [(1, 3), (2, 4), (1, 5)] assert process_queries(n, q, arr, queries) == ["even", "odd", "odd"] def test_all_even_numbers(): n = 4 q = 2 arr = [2, 4, 6, 8] queries = [(1, 2), (1,...
[ { "docstring": "Compute the prefix sum array of the given array.", "function_declaration": "def prefix_sums(arr):", "function_name": "prefix_sums", "parameter_list": "(arr)" }, { "docstring": "Query the sum for a sublist from l to r (inclusive, 1-based index).\nCheck if the sum is even or od...
[ 0, 0, 0, 0, 1, 1, 1, 0, 1, 0 ]
4
medium
0.4
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def odd_or_even(n, q, numbers, queries):\n \"\"\"\n Determines if the sum of elements in specified sublists is odd or even.\n\n Parameters:\n n (i...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00002525", "row_id": 2525, "seed_ids": "[2557]" }
0.647475
Codeforces_2525
I
[ "prefix_sums", "query_sums", "process_queries" ]
3
[ [ "process_queries", "prefix_sums" ], [ "process_queries", "query_sums" ] ]
2
[ "process_queries" ]
false
[]
false
pytest
true
[]
true
9cb308e0ac46726ff0052efcfb92c148b207794e
277489dff831d4bd208058198e62c4c63f73c72b
v1.0
instruct
Codeforces
Codeforces_2780_I
You are given an unrooted tree with `n` nodes, where each node is numbered from 1 to `n` and every edge has a certain weight. A tree is a connected acyclic graph. In other words, there are no cycles in the graph. You are required to find the maximum length of a path in the tree such that the path does not use an edge w...
from collections import defaultdict, deque def bfs_farthest_node(start, graph, k): """ Perform BFS to find the farthest node from the start node considering only edges with weight <= k. """ visited = {start} queue = deque([(start, 0)]) # (current_node, current_distance) farthest_node = sta...
from solution import max_path_under_weight def test_example(): edges = [(1, 2, 3), (1, 3, 10), (2, 4, 2), (2, 5, 4)] assert max_path_under_weight(5, 4, edges) == 2 def test_all_edges_below_k(): edges = [(1, 2, 1), (1, 3, 1), (2, 4, 1), (2, 5, 1)] assert max_path_under_weight(5, 2, edges) == 3 def tes...
[ { "docstring": "Perform BFS to find the farthest node from the start node\nconsidering only edges with weight <= k.", "function_declaration": "def bfs_farthest_node(start, graph, k):", "function_name": "bfs_farthest_node", "parameter_list": "(start, graph, k)" }, { "docstring": "Function to ...
[ 0, 0, 0, 0, 0, 0, 1, 0, 0, 1 ]
2
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def dfs(graph, node, k, visited):\n visited[node] = True\n max_length = 0\n for neighbor, weight in graph[node]:\n if not visited[neighbor] an...
trial_gpt4o_6
{ "original_instruction": "", "prompt_id": "00002780", "row_id": 2780, "seed_ids": "[5209]" }
0.77455
Codeforces_2780
I
[ "bfs_farthest_node", "max_path_under_weight" ]
2
[ [ "max_path_under_weight", "bfs_farthest_node" ] ]
1
[]
false
[]
false
pytest
true
[]
true
ce57ebf039077541a61118c88b2cd433d508604c
703c96618cdd082dbf104acb5d50a56b35486f1d
v1.0
instruct
Codeforces
Codeforces_2792_I
You are given a binary tree where each node contains an integer value. Write a function to find the maximum path sum. The path is defined as any sequence of nodes from some starting node to any node in the tree along the parent-child connections. The path must contain at least one node and does not need to go through t...
from typing import List, Tuple class TreeNode: def __init__(self, val=0, left=None, right=None): self.val = val self.left = left self.right = right def build_tree(n: int, values: List[int], edges: List[Tuple[int, int]]) -> TreeNode: if not n: return None nodes = {i...
from solution import max_path_sum def test_example_case(): n = 5 values = [-10, 9, 20, 15, 7] edges = [(1, 2), (1, 3), (3, 4), (3, 5)] assert max_path_sum(n, values, edges) == 42 def test_single_node(): n = 1 values = [5] edges = [] assert max_path_sum(n, values, edges) == 5 def test_...
[]
[ 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 typing import List, Tuple, Dict\nimport sys\n\nclass TreeNode:\n def __init__(self, value):\n self.value = value\n self.left = None\n ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00002792", "row_id": 2792, "seed_ids": "[22]" }
0.68064
Codeforces_2792
I
[ "build_tree", "max_path_sum" ]
2
[ [ "max_path_sum", "build_tree" ] ]
1
[]
false
[ "TreeNode" ]
true
pytest
true
[]
true
b62e4bd5f51f7d4f2db63572edabfd18e169784d
c1cd1371cb484638ca74a6cb706b60c4943a8482
v1.0
instruct
Codeforces
Codeforces_2821_I
A city has m skyscrapers, and there are n bridges connecting them. Each bridge can be described as a pair of integers (x, y) indicating that there is a bridge between skyscraper x and skyscraper y. The city's builders want to know the maximum number of skyscrapers that are connected directly or indirectly through the b...
from collections import defaultdict, deque def largest_connected_component(m, n, bridges): def bfs(component_start): queue = deque([component_start]) visited.add(component_start) size = 0 while queue: node = queue.popleft() size += 1 for neighbor ...
from solution import find_largest_connected_component def test_example_case(): assert find_largest_connected_component(6, 5, [(1, 2), (2, 3), (4, 5), (5, 6), (1, 3)]) == 3 def test_disconnected_skyscrapers(): assert find_largest_connected_component(5, 0, []) == 1 def test_all_connected(): assert find_lar...
[ { "docstring": null, "function_declaration": "def largest_connected_component(m, n, bridges):", "function_name": "largest_connected_component", "parameter_list": "(m, n, bridges)" }, { "docstring": null, "function_declaration": "def find_largest_connected_component(m, n, pairs):", "f...
[ 1, 1, 1, 1, 1, 1, 0, 1, 1, 1 ]
9
easy
0.9
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def largest_component_size(m, n, bridges):\n from collections import defaultdict, deque\n \n # Create adjacency list for the graph\n graph = defau...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00002821", "row_id": 2821, "seed_ids": "[6027]" }
0.628892
Codeforces_2821
I
[ "largest_connected_component", "find_largest_connected_component" ]
2
[ [ "find_largest_connected_component", "largest_connected_component" ] ]
1
[]
false
[]
false
pytest
true
[]
true
ef5d6eed839a52c1b1e2898433cab8b123dfbf5c
6262a74135b611bde7360f818ab6b65961b890f6
v1.0
instruct
Codeforces
Codeforces_2827_I
You are given two arrays of integers `a` and `b` of the same length `n`. You should determine if you can make the arrays identical by performing the following allowed operations any number of times: 1. Select any index `i` in array `a` and multiply `a[i]` by any prime number. 2. Select any index `i` in array `b` and m...
def prime_factors(number): """ Returns the set of prime factors of a given number. """ i = 2 factors = set() while i * i <= number: while (number % i) == 0: factors.add(i) number //= i i += 1 if number > 1: factors.add(number) return factor...
from solution import can_make_identical def test_identical_arrays(): assert can_make_identical([1], [1]) == "YES" assert can_make_identical([6, 4, 3, 9], [18, 4, 27, 3]) == "YES" def test_different_arrays(): assert can_make_identical([2, 3, 5], [4, 9, 10]) == "NO" def test_single_element_arrays()...
[ { "docstring": "Returns the set of prime factors of a given number.", "function_declaration": "def prime_factors(number):", "function_name": "prime_factors", "parameter_list": "(number)" }, { "docstring": "Determines if two arrays `a` and `b` can be made identical by multiplying elements by ...
[ 0, 1, 0, 0, 0, 0, 0, 0, 0, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "from math import gcd\n\ndef gcd_list(numbers):\n \"\"\"\n Computes the GCD of a list of numbers.\n \"\"\"\n current_gcd = numbers[0]\n for num ...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00002827", "row_id": 2827, "seed_ids": "[3346]" }
0.671492
Codeforces_2827
I
[ "prime_factors", "can_make_identical" ]
2
[ [ "can_make_identical", "prime_factors" ] ]
1
[]
false
[]
false
pytest
true
[]
true
3a089dee0ed38018abf22028de681ce199e7ebc6
6f1a8792c99fb4d49be6e51fae4200c7810f3d09
v1.0
instruct
Codeforces
Codeforces_2845_I
You are given a sequence of integers and you need to determine the number of inversions in the sequence. An inversion is a pair of indices (i, j) such that i < j and ai > aj. This is a common task in computer science and is often used to measure how far a given sequence is from being sorted. ### Input: - The first lin...
def merge_and_count(arr, temp_arr, left, mid, right): i = left # Starting index for left subarray j = mid + 1 # Starting index for right subarray k = left # Starting index to be sorted inv_count = 0 # Conditions are checked to ensure that i doesn't exceed mid and j doesn't exceed right wh...
from solution import count_inversions def test_single_element(): assert count_inversions([1]) == 0 def test_sorted_array(): assert count_inversions([1, 2, 3, 4, 5]) == 0 def test_reverse_sorted_array(): assert count_inversions([5, 4, 3, 2, 1]) == 10 def test_mixed_array(): assert count_inversions([2...
[ { "docstring": null, "function_declaration": "def merge_and_count(arr, temp_arr, left, mid, right):", "function_name": "merge_and_count", "parameter_list": "(arr, temp_arr, left, mid, right)" }, { "docstring": null, "function_declaration": "def merge_sort_and_count(arr, temp_arr, left, r...
[ 1, 1, 1, 0, 1, 0, 0, 1, 0, 1 ]
6
medium
0.6
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def count_inversions(arr):\n \"\"\"\n Returns the number of inversions in the array `arr`.\n \"\"\"\n if not arr:\n return 0\n \n # A...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00002845", "row_id": 2845, "seed_ids": "[5804]" }
0.795371
Codeforces_2845
I
[ "merge_and_count", "merge_sort_and_count", "count_inversions" ]
3
[ [ "count_inversions", "merge_sort_and_count" ], [ "merge_sort_and_count", "merge_and_count" ] ]
2
[]
false
[]
false
pytest
true
[]
true
87e61c847a00706d4314da639d1b78213ef6c961
44cd622d1e17eafea2e05c18cbb60493acbfd46d
v1.0
instruct
Codeforces
Codeforces_2846_I
In a magical land, there exist enchanted trees that grant special abilities. Each enchanted tree can only transfer its power to one of its children, chosen based on a particular ranking system. You are given a forest with multiple enchanted trees. Your task is to determine the best destination for each tree's power tra...
def find_power_destination(t, test_cases): results = [] for i in range(t): n = test_cases[i][0] power_values = test_cases[i][1] edges = test_cases[i][2] from collections import defaultdict tree = defaultdict(list) for u, v in edges: tree[u].append(v) ...
import pytest from solution import solve_enchanted_trees def test_example1(): input_str = "2\n5\n1 10 3 6 8\n1 2\n1 3\n2 4\n2 5\n4\n9 3 5 2\n1 2\n2 3\n2 4\n" expected_output = "2\n2" assert solve_enchanted_trees(input_str) == expected_output def test_single_node(): input_str = "1\n1\n5\n" expecte...
[ { "docstring": null, "function_declaration": "def find_power_destination(t, test_cases):", "function_name": "find_power_destination", "parameter_list": "(t, test_cases)" }, { "docstring": null, "function_declaration": "def parse_input(input_str):", "function_name": "parse_input", ...
[ 0, 1, 0, 1, 1, 0, 0, 0, 0, 1 ]
4
medium
0.4
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def best_destination(t, data):\n results = []\n \n for tree_data in data:\n n = tree_data[\"n\"]\n power_values = tree_data[\"powers\"]...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00002846", "row_id": 2846, "seed_ids": "[6536]" }
0.579805
Codeforces_2846
I
[ "find_power_destination", "parse_input", "format_output", "solve_enchanted_trees" ]
4
[ [ "solve_enchanted_trees", "find_power_destination" ], [ "solve_enchanted_trees", "format_output" ], [ "solve_enchanted_trees", "parse_input" ] ]
3
[ "parse_input", "format_output" ]
false
[]
false
pytest
true
[]
true
cad84478c53e4a38827f8860a74f4fe454cc23bc
887a52cf9bab73e1bb48e61d28f10cd27d64136a
v1.0
instruct
Codeforces
Codeforces_2943_I
Consider a rectangular grid of cells with n rows and m columns. Each cell in the grid is either open (.) or blocked (#). You start from the top-left corner of the grid and want to reach the bottom-right corner. From your current cell, you can move to a directly adjacent cell to the right or down, but only if it is open...
MOD = 1000000007 def count_paths(grid): n = len(grid) m = len(grid[0]) if grid[0][0] == '#' or grid[n-1][m-1] == '#': return 0 dp = [[0] * m for _ in range(n)] dp[0][0] = 1 for i in range(n): for j in range(m): if grid[i][j] == '#': dp[...
from solution import number_of_paths_from_input def test_case_1(): input_string = "3 3\n...\n.#.\n..." assert number_of_paths_from_input(input_string) == 2 def test_case_2(): input_string = "3 3\n###\n###\n###" assert number_of_paths_from_input(input_string) == 0 def test_case_3(): input_string =...
[ { "docstring": null, "function_declaration": "def count_paths(grid):", "function_name": "count_paths", "parameter_list": "(grid)" }, { "docstring": null, "function_declaration": "def number_of_paths_from_input(input_string):", "function_name": "number_of_paths_from_input", "param...
[ 0, 0, 0, 0, 1, 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 num_paths(n, m, grid):\n MOD = 1000000007\n \n if grid[0][0] == '#' or grid[n-1][m-1] == '#':\n return 0\n\n dp = [[0] * m for _ in ran...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00002943", "row_id": 2943, "seed_ids": "[1491]" }
0.810257
Codeforces_2943
I
[ "count_paths", "number_of_paths_from_input" ]
2
[ [ "number_of_paths_from_input", "count_paths" ] ]
1
[]
false
[]
false
pytest
true
[]
true
1522cf4c3b9cfc20b2355b5194b8212f1c289f75
1ce65010a5be2bc6452436ce019cc1e38e7853d2
v1.0
instruct
Codeforces
Codeforces_2958_I
You are given an array consisting of $$$n$$$ integers. The array follows a specific pattern: it first strictly increases, then strictly decreases. Your task is to efficiently answer multiple queries regarding the given array. Each query asks you to determine if a given integer $$$x$$$ is a peak element of the array. A...
def find_peak_index(arr): """ Utility function to find the peak index in a mountain array. """ left, right = 0, len(arr) - 1 while left < right: mid = (left + right) // 2 if arr[mid] < arr[mid + 1]: left = mid + 1 else: right = mid return left def...
from solution import is_peak def test_peak_element(): arr = [1, 3, 8, 12, 4, 2, 1] assert is_peak(arr, 12) == "YES" assert is_peak(arr, 3) == "NO" assert is_peak(arr, 5) == "NO" def test_no_peak(): arr = [1, 2, 3, 2, 1] assert is_peak(arr, 4) == "NO" assert is_peak(arr, 1) == "NO" def tes...
[ { "docstring": "Utility function to find the peak index in a mountain array.", "function_declaration": "def find_peak_index(arr):", "function_name": "find_peak_index", "parameter_list": "(arr)" }, { "docstring": "Returns \"YES\" if x is a peak element in the mountain array arr, otherwise \"N...
[ 1, 1, 1, 1, 1, 1, 0, 0, 1, 1 ]
8
easy
0.8
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def find_peak(n, array, queries):\n peaks = []\n\n for i in range(1, n - 1):\n if array[i - 1] < array[i] > array[i + 1]:\n peaks.appe...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00002958", "row_id": 2958, "seed_ids": "[3482]" }
0.840756
Codeforces_2958
I
[ "find_peak_index", "is_peak" ]
2
[ [ "is_peak", "find_peak_index" ] ]
1
[]
false
[]
false
pytest
true
[]
true
fde9d0028bc83dfc7997f274aa5a9c7147df9a3f
0c52ba4113a7fae835c8942a98150fac084a0b9e
v1.0
instruct
Codeforces
Codeforces_2967_I
Given an undirected graph, we want to determine the number of connected components in the graph. A connected component is a maximal set of vertices such that there is a path between any two vertices in this set. You are provided with multiple test cases to analyze. Each test case consists of a separate graph descripti...
def dfs(node, graph, visited): """ Depth-First Search (DFS) to traverse the graph and mark all nodes in the same connected component. """ stack = [node] while stack: current = stack.pop() for neighbor in graph[current]: if not visited[neighbor]: visited[ne...
from solution import count_connected_components def test_single_node(): assert count_connected_components(1, [(1, 0, [])]) == [1] def test_no_edges(): assert count_connected_components(1, [(4, 0, [])]) == [4] def test_connected_graph(): assert count_connected_components(1, [(5, 4, [(1, 2), (2, 3), (3, 4)...
[ { "docstring": "Depth-First Search (DFS) to traverse the graph and mark all nodes in the same connected component.", "function_declaration": "def dfs(node, graph, visited):", "function_name": "dfs", "parameter_list": "(node, graph, visited)" }, { "docstring": null, "function_declaration"...
[ 1, 1, 1, 1, 1, 1, 1, 1, 0, 1 ]
9
easy
0.9
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def find_connected_components(t, test_cases):\n def dfs(node, visited, adj_list):\n stack = [node]\n while stack:\n current = stac...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00002967", "row_id": 2967, "seed_ids": "[2718]" }
0.756115
Codeforces_2967
I
[ "dfs", "count_connected_components" ]
2
[ [ "count_connected_components", "dfs" ] ]
1
[]
false
[]
false
pytest
true
[]
true
4c1f6aed33b823bd96e96a6424188c95a5b047f4
97b327757eeba6e88c76d63866f2b986a64b655c
v1.0
instruct
Codeforces
Codeforces_2996_I
A company wants to increase the productivity of their employees, so they decided to introduce a system where employees can log their working hours and breaks in a structured format. They need a program that can analyze these logs and compute the total working time for each employee, excluding breaks. Each log entry is...
from datetime import datetime, timedelta def parse_time(time_str): return datetime.strptime(time_str, "%H:%M") def total_working_time(n, logs): work_times = {} break_times = {} for log in logs: parts = log.split() date = parts[0] employee_id = parts[1] time_type = part...
def test_total_working_time(): logs = [ "2023-05-01 emp1 start:09:00 stop:12:30", "2023-05-01 emp1 break_start:10:00 break_stop:10:15", "2023-05-01 emp2 start:08:00 stop:16:00", "2023-05-01 emp2 break_start:12:00 break_stop:13:00", "2023-05-01 emp2 break_start:15:00 break_sto...
[ { "docstring": null, "function_declaration": "def parse_time(time_str):", "function_name": "parse_time", "parameter_list": "(time_str)" }, { "docstring": null, "function_declaration": "def total_working_time(n, logs):", "function_name": "total_working_time", "parameter_list": "(n...
[ 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": "from collections import defaultdict\nfrom datetime import datetime, timedelta\n\ndef parse_time(time_str):\n \"\"\"Parses a time string in HH:MM format and...
trial_gpt4o_3
{ "original_instruction": "", "prompt_id": "00002996", "row_id": 2996, "seed_ids": "[7343]" }
0.611122
Codeforces_2996
I
[ "parse_time", "total_working_time" ]
2
[ [ "total_working_time", "parse_time" ] ]
1
[]
false
[]
false
pytest
false
[]
true
98481b32e9666586a2ca921da3ea5034d392319b
18773e0be19b8a933239a01b390f45bfa7ac3ebc
v1.0
instruct
Codeforces
Codeforces_3119_I
You are given a positive integer N (1 ≤ N ≤ 1000). Your task is to determine how many distinct pairs of positive integers (a, b) satisfy the condition: a * b = N The format of the input and output should be as follows: **Input:** The input contains a single integer N. **Output:** In the first line, print the number...
def find_pairs(N): """ Returns the number of distinct pairs (a, b) such that a * b = N, and the pairs themselves in ascending order based on the value of a. """ pairs = [] for a in range(1, int(N**0.5) + 1): if N % a == 0: b = N // a pairs.append((a, b)) retu...
from solution import find_pairs, distinct_pairs def test_find_pairs_12(): assert find_pairs(12) == [(1, 12), (2, 6), (3, 4)] def test_find_pairs_25(): assert find_pairs(25) == [(1, 25), (5, 5)] def test_find_pairs_1(): assert find_pairs(1) == [(1, 1)] def test_find_pairs_100(): assert find_pairs(100...
[ { "docstring": "Returns the number of distinct pairs (a, b) such that a * b = N, \nand the pairs themselves in ascending order based on the value of a.", "function_declaration": "def find_pairs(N):", "function_name": "find_pairs", "parameter_list": "(N)" }, { "docstring": null, "function...
[ 1, 1, 0, 1, 0, 0, 0, 0, 1, 1 ]
5
medium
0.5
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def find_pairs(N):\n \"\"\"\n Returns the number of distinct pairs (a, b) such that a * b = N, \n and the pairs themselves sorted in ascending order ...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00003119", "row_id": 3119, "seed_ids": "[6716]" }
0.722824
Codeforces_3119
I
[ "find_pairs", "distinct_pairs" ]
2
[ [ "distinct_pairs", "find_pairs" ] ]
1
[]
false
[]
false
pytest
true
[]
true
a04ee45565d21713fd6fa8d5918297388e64222f
1a8878da8f74d1d51104c8a34145b63e405f1e36
v1.0
instruct
Codeforces
Codeforces_3167_I
The ancient kingdom of Treeland is composed of $$$N$$$ cities connected by $$$N-1$$$ roads, forming a tree structure. The king wants to fortify Treeland by placing castles in some of the cities. To ensure efficient administration, the king requires each castle to control a segment of cities such that every city is cont...
from collections import deque, defaultdict def bfs_longest(node, adjacency_list): queue = deque([(node, 0)]) visited = set() visited.add(node) farthest_node = node max_distance = 0 while queue: current, distance = queue.popleft() for neighbor in adjacency_list[current]: ...
import pytest from solution import min_max_distance def test_example_case(): N = 7 K = 2 roads = [(1, 2), (2, 3), (3, 4), (4, 5), (5, 6), (6, 7)] assert min_max_distance(N, K, roads) == 3 def test_single_city(): N = 1 K = 1 roads = [] assert min_max_distance(N, K, roads) == 0 def test...
[ { "docstring": null, "function_declaration": "def bfs_longest(node, adjacency_list):", "function_name": "bfs_longest", "parameter_list": "(node, adjacency_list)" }, { "docstring": null, "function_declaration": "def min_max_distance(N, K, roads):", "function_name": "min_max_distance",...
[ 1, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "from collections import deque, defaultdict\n\ndef bfs_longest(node, adjacency_list):\n queue = deque([(node, 0)])\n visited = set()\n visited.add(nod...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00003167", "row_id": 3167, "seed_ids": "[1273]" }
0.678091
Codeforces_3167
I
[ "bfs_longest", "min_max_distance", "can_place_castles" ]
3
[ [ "min_max_distance", "bfs_longest" ], [ "min_max_distance", "can_place_castles" ] ]
2
[]
false
[]
false
pytest
true
[]
true
9bd98f5296c507cf36f85d900488cad18f4c7c5f
fa7d58ae45309dbc5cf3fe83e4bc1f1de5d9b700
v1.0
instruct
Codeforces
Codeforces_3225_I
A game company is developing a new board game, and they need your help to simulate a specific game scenario. The game takes place on an n x m grid, and players place their tokens on the grid according to certain rules. Two players, Alice and Bob, take turns placing their tokens on the grid. Alice starts first and place...
def check_winner(grid, n, m, k): # Helper function to check if a sequence of k in a list is the same and not '.' def is_winner(sequence, player): return sequence == [player] * k # Check rows for r in range(n): for c in range(m - k + 1): if is_winner(grid[r][c:c+k], 'A'): ...
import pytest from solution import game_outcome def test_game_alice_wins_by_row(): assert game_outcome( 3, 3, 3, ["...", "...", "..."], 9, [('A', 1, 1), ('B', 1, 2), ('A', 1, 3), ('B', 2, 1), ('A', 2, 2), ('B', 2, 3), ('A', 3, 1), ('B', 3, 2), ('A', 3, 3)] ) == "Alice wins" ...
[ { "docstring": null, "function_declaration": "def check_winner(grid, n, m, k):", "function_name": "check_winner", "parameter_list": "(grid, n, m, k)" }, { "docstring": null, "function_declaration": "def game_outcome(n, m, k, initial_grid, q, moves):", "function_name": "game_outcome",...
[ 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 check_winner(grid, player, k):\n def check_line(line, player, k):\n count = 0\n for cell in line:\n if cell == player:\n ...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00003225", "row_id": 3225, "seed_ids": "[787]" }
0.73444
Codeforces_3225
I
[ "check_winner", "game_outcome" ]
2
[ [ "game_outcome", "check_winner" ] ]
1
[]
false
[]
false
pytest
true
[]
true
dbc63d49819c88c3f98b5e622ce083672bfd9b83
9f9544938dc0a3c4cb124e90a5ca7355a118b845
v1.0
instruct
Codeforces
Codeforces_3226_I
In a faraway land, there is a unique type of farmland management system where fields are arranged in a grid of size M x N. Each cell in this grid represents a specific field. All fields are either planted with crops or left barren. Every month, fields undergo changes based on certain rules applied to each field and it...
from typing import List def count_crops_neighbors(fields: List[List[int]], x: int, y: int) -> int: """ Count the number of neighboring cells with crops around the cell at (x, y). """ count = 0 rows = len(fields) cols = len(fields[0]) for dx in [-1, 0, 1]: for dy in [-1, 0, 1]: ...
from solution import simulate_farmland def test_simulate_farmland_initial_example(): initial_fields = [ [0, 1, 0], [0, 0, 1], [1, 1, 1] ] K = 1 expected = [ [0, 0, 0], [1, 0, 1], [0, 1, 1] ] assert simulate_farmland(initial_fields, K) == expected ...
[ { "docstring": "Count the number of neighboring cells with crops around the cell at (x, y).", "function_declaration": "def count_crops_neighbors(fields, x, y):", "function_name": "count_crops_neighbors", "parameter_list": "(fields, x, y)" }, { "docstring": "Simulate the changes in the farmla...
[ 0, 0, 0, 1, 1, 1, 1, 0, 0, 0 ]
4
medium
0.4
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def simulate_farmland(initial_fields, K):\n def get_neighbor_count(fields, i, j):\n count = 0\n directions = [(-1, -1), (-1, 0), (-1, 1), (0,...
trial_gpt4o_6
{ "original_instruction": "", "prompt_id": "00003226", "row_id": 3226, "seed_ids": "[6828]" }
0.517715
Codeforces_3226
I
[ "count_crops_neighbors", "simulate_farmland" ]
2
[ [ "simulate_farmland", "count_crops_neighbors" ] ]
1
[]
false
[]
false
pytest
true
[]
true
091577e60251cafd323a972e55d9414cf4e4c48e
e2b40c9c7bb635c45146073b9493dba744142657
v1.0
instruct
Codeforces
Codeforces_3256_I
A travel agency uses a mobile app to help tourists find the shortest path between two landmarks in a city. The city is represented by an undirected graph where landmarks are nodes, and roads are edges with positive integer weights representing the travel time. Given a list of queries, each containing a pair of landmark...
import heapq def dijkstra(graph, start): n = len(graph) distances = [float('inf')] * n distances[start] = 0 priority_queue = [(0, start)] while priority_queue: current_distance, current_node = heapq.heappop(priority_queue) if current_distance > distances[current_node]:...
def test_shortest_paths(): n = 5 m = 6 edges = [ (1, 2, 4), (1, 3, 2), (2, 3, 1), (2, 4, 7), (3, 5, 5), (4, 5, 1) ] q = 3 queries = [ (1, 5), (1, 4), (3, 4) ] expected_output = ['7', '8', '6'] assert shortest_pat...
[ { "docstring": null, "function_declaration": "def dijkstra(graph, start):", "function_name": "dijkstra", "parameter_list": "(graph, start)" }, { "docstring": null, "function_declaration": "def shortest_paths(n, m, edges, q, queries):", "function_name": "shortest_paths", "paramete...
[ 0, 1, 0, 1, 0, 1, 0, 0 ]
3
medium
0.375
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "import heapq\n\ndef dijkstra(n, roads, start):\n dist = [float('inf')] * (n + 1)\n adj = [[] for _ in range(n + 1)]\n \n for u, v, w in roads:\n ...
trial_gpt4o_7
{ "original_instruction": "", "prompt_id": "00003256", "row_id": 3256, "seed_ids": "[4287]" }
0.796399
Codeforces_3256
I
[ "dijkstra", "shortest_paths" ]
2
[ [ "shortest_paths", "dijkstra" ] ]
1
[]
false
[]
false
pytest
false
[]
true
3bb9b821809f94d1fce5bee5d51245704aeb1c4b
a829c07c6f81c1071eea058458000bfb0aa3e3c1
v1.0
instruct
Codeforces
Codeforces_3280_I
Given a list of n integers and q queries, each query asks about the sum of all integers between indices i and j in the list. Your task is to output these sums for each query. The first line contains two integers n and q (1 ≤ n, q ≤ 100,000), the number of elements in the list and the number of queries respectively. T...
def prefix_sums(arr): """ This function returns the prefix sums array for a given input array. """ n = len(arr) prefix = [0] * (n + 1) for i in range(1, n + 1): prefix[i] = prefix[i - 1] + arr[i - 1] return prefix def range_sum(prefix, i, j): """ This function returns the su...
from solution import prefix_sums, range_sum, solve def test_prefix_sums(): assert prefix_sums([3, 2, 4, 5, 1, 6]) == [0, 3, 5, 9, 14, 15, 21] assert prefix_sums([1, 2, 3]) == [0, 1, 3, 6] def test_range_sum(): prefix = prefix_sums([3, 2, 4, 5, 1, 6]) assert range_sum(prefix, 1, 3) == 9 assert rang...
[ { "docstring": "This function returns the prefix sums array for a given input array.", "function_declaration": "def prefix_sums(arr):", "function_name": "prefix_sums", "parameter_list": "(arr)" }, { "docstring": "This function returns the sum of the elements from index i to j (inclusive)\nus...
[ 1, 1, 1, 1, 1, 1, 1, 0, 1, 0 ]
8
easy
0.8
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def cumulative_sum(n, q, array, queries):\n prefix_sum = [0] * (n + 1)\n \n # Calculating prefix sums\n for i in range(1, n + 1):\n prefix_...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00003280", "row_id": 3280, "seed_ids": "[3332]" }
0.705451
Codeforces_3280
I
[ "prefix_sums", "range_sum", "solve" ]
3
[ [ "solve", "prefix_sums" ], [ "solve", "range_sum" ] ]
2
[]
false
[]
false
pytest
true
[]
true
d72bf7cb4b9955c0a3d9dc59c9a44f7259485f19
ddad86cc21e2a4fd397cc09ab0d5a3d714a28192
v1.0
instruct
Codeforces
Codeforces_3281_I
You are given an undirected graph with N nodes and M edges. Each edge has an associated weight. Your task is to determine if it's possible to remove some edges (possibly none) so that the sum of the weights of the remaining edges is as small as possible, while ensuring that the graph remains connected and has exactly N...
def find(parent, i): if parent[i] == i: return i else: return find(parent, parent[i]) def union(parent, rank, x, y): xroot = find(parent, x) yroot = find(parent, y) if rank[xroot] < rank[yroot]: parent[xroot] = yroot elif rank[xroot] > rank[yroot]: parent[yroot]...
import pytest from solution import minimum_spanning_tree def test_minimum_spanning_tree_case_1(): N = 4 M = 5 edges = [ (1, 2, 1), (1, 3, 3), (2, 3, 2), (2, 4, 4), (3, 4, 5) ] assert minimum_spanning_tree(N, M, edges) == 7 def test_minimum_spanning_tree_case...
[ { "docstring": null, "function_declaration": "def find(parent, i):", "function_name": "find", "parameter_list": "(parent, i)" }, { "docstring": null, "function_declaration": "def union(parent, rank, x, y):", "function_name": "union", "parameter_list": "(parent, rank, x, y)" }, ...
[ 0, 0, 0, 1, 1, 0, 0, 1, 0 ]
3
medium
0.333
{ "trial_gpt4o_0": null, "trial_gpt4o_1": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared1_results_combined.jsonl", "solution_code": "def minimum_spanning_tree(n, edges):\n \"\"\"\n Function to find the minimum spanning tree of a given graph using Kruskal's alg...
trial_gpt4o_4
{ "original_instruction": "", "prompt_id": "00003281", "row_id": 3281, "seed_ids": "[7795]" }
0.859425
Codeforces_3281
I
[ "find", "union", "kruskal_minimum_spanning_tree", "minimum_spanning_tree" ]
4
[ [ "kruskal_minimum_spanning_tree", "find" ], [ "kruskal_minimum_spanning_tree", "union" ], [ "minimum_spanning_tree", "kruskal_minimum_spanning_tree" ], [ "union", "find" ] ]
4
[]
false
[]
false
pytest
true
[]
true
0b4297bc9451b1460576b43aca9483c49e82c6d5
be017d33be18c04548ba16f34019b5d7f802bab2
v1.0
instruct
Codeforces
Codeforces_3286_I
You are given a tree with n nodes, but initially, it is not connected. There are m edges given in advance, which can be used only once in any order to connect the nodes. Each node represents an island, and each edge represents a ferry route between two islands. You need to determine the minimum time required to connect...
import heapq def find(parent, i): if parent[i] == i: return i else: parent[i] = find(parent, parent[i]) return parent[i] def union(parent, rank, x, y): root_x = find(parent, x) root_y = find(parent, y) if root_x != root_y: if rank[root_x] > rank[root_y]: ...
from solution import min_cost_to_connect_islands def test_min_cost_to_connect_islands(): n, m, t = 4, 2, 1 ferries = [(1, 2, 4), (3, 4, 2)] express = [(2, 3)] assert min_cost_to_connect_islands(n, m, t, ferries, express) == 6 def test_case_with_only_express_routes(): n, m, t = 4, 0, 3 ferries ...
[ { "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, 1, 0, 0, 1, 0, 0, 0 ]
3
hard
0.3
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def find_min_cost_to_connect_islands(n, m, t, ferry_routes, express_routes):\n \"\"\"\n Calculates the minimum cost to connect all islands using provide...
trial_gpt4o_6
{ "original_instruction": "", "prompt_id": "00003286", "row_id": 3286, "seed_ids": "[99]" }
0.735394
Codeforces_3286
I
[ "find", "union", "min_cost_to_connect_islands" ]
3
[ [ "min_cost_to_connect_islands", "find" ], [ "min_cost_to_connect_islands", "union" ], [ "union", "find" ] ]
3
[]
false
[]
false
pytest
true
[]
true
41e9910ee9f7b176f60aa56667ba18b539fc11d8
111fc8a89a3732856741dc0616d664c5d103c0b0
v1.0
instruct
Codeforces
Codeforces_3293_I
There are m small islands in Archipelago, numbered 1 through m. Each island is connected to at most two other islands via bridges, forming a series of interconnected islands. Lola is a mail carrier. She starts her delivery at island x and wants to ensure she delivers mail to every island at least once. Lola can only ...
def min_bridges_to_cross(m, x, bridges): from collections import defaultdict, deque # Create adjacency list for islands adj_list = defaultdict(list) for u, v in bridges: adj_list[u].append(v) adj_list[v].append(u) # BFS to count edges needed to visit all islands visited...
import pytest from solution import solve def test_example_case(): m = 5 x = 1 bridge_input = "1 2 1 3 2 4 2 5" assert solve(m, x, bridge_input) == 4 def test_single_island(): m = 1 x = 1 bridge_input = "" assert solve(m, x, bridge_input) == 0 def test_two_islands(): m = 2 x = ...
[ { "docstring": null, "function_declaration": "def min_bridges_to_cross(m, x, bridges):", "function_name": "min_bridges_to_cross", "parameter_list": "(m, x, bridges)" }, { "docstring": null, "function_declaration": "def solve(m, x, bridge_input):", "function_name": "solve", "param...
[ 1, 1, 0, 0, 0, 0, 1, 0, 1, 0 ]
4
medium
0.4
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def minimum_bridges_to_cross(m, x, bridges):\n from collections import defaultdict, deque\n \n # Create the adjacency list for the islands\n graph...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00003293", "row_id": 3293, "seed_ids": "[2684]" }
0.813921
Codeforces_3293
I
[ "min_bridges_to_cross", "solve" ]
2
[ [ "solve", "min_bridges_to_cross" ] ]
1
[]
false
[]
false
pytest
true
[]
true
13902d30bab8cc3a14180ea3b320dc3d8bb53602
31fa5e1eadfc77431e426fabe391c261fa20a0d6
v1.0
instruct
Codeforces
Codeforces_3332_I
Tom is working on a text editor and he wants to implement a feature for finding and replacing words efficiently in a given text document. The text document is represented as a string and the words to be replaced are given in the form of pairs where each pair consists of a target word and the replacement word. Your tas...
def find_and_replace(text, replacements): """ Perform find and replace operations on the input text based on the given replacements. :param text: The original text string. :param replacements: A list of tuples where each tuple consists of a target word and a replacement word. :return: The modif...
def test_find_and_replace(): assert process_replacement_operations(63, 3, "hello there this is a simple text document for testing purposes only", [("hello", "hi"), ("document", "file"), ("simple", "complex")]) == \ "hi there this is a complex text file for testi...
[ { "docstring": "Perform find and replace operations on the input text based on the given replacements.\n\n:param text: The original text string.\n:param replacements: A list of tuples where each tuple consists of a target word and a replacement word.\n:return: The modified text after all replacements.", "fu...
[ 1, 1, 0, 1, 1, 1, 0, 0, 1, 1 ]
7
easy
0.7
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def replace_words_in_text(n, m, text, replacements):\n \"\"\"\n Replace the words in the text according to the replacement pairs.\n \n Parameters:...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00003332", "row_id": 3332, "seed_ids": "[5086]" }
0.611469
Codeforces_3332
I
[ "find_and_replace", "process_replacement_operations" ]
2
[ [ "process_replacement_operations", "find_and_replace" ] ]
1
[]
false
[]
false
pytest
false
[]
true
ba2f84d490e7dadda924d3ebaa1b856b22193e3e
812b704f9c37c34daa2c3debfda9310c066b5532
v1.0
instruct
Codeforces
Codeforces_3387_I
Your friend Bob loves learning about binary trees. However, he is struggling with understanding how to calculate the depth of a binary tree. Can you help him out by writing a function to determine the depth of a given binary tree? In this problem, the depth (or height) of a binary tree is defined as the number of node...
class TreeNode: def __init__(self, value): self.value = value self.left = None self.right = None def build_tree(nodes): node_dict = {} root = None for value, left, right in nodes: if value not in node_dict: node_dict[value] = TreeNode(value) if left ...
import pytest from solution import find_tree_depth def test_tree_depth_1(): n = 5 node_data = [ "1 2 3", "2 4 5", "3 0 0", "4 0 0", "5 0 0" ] assert find_tree_depth(n, node_data) == 3 def test_tree_depth_2(): n = 1 node_data = ["1 0 0"] assert find_t...
[]
[ 1, 1, 1, 0, 0, 1, 1, 0, 1, 1 ]
7
easy
0.7
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "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_6
{ "original_instruction": "", "prompt_id": "00003387", "row_id": 3387, "seed_ids": "[2812]" }
0.582862
Codeforces_3387
I
[ "build_tree", "tree_depth", "find_tree_depth" ]
3
[ [ "find_tree_depth", "build_tree" ], [ "find_tree_depth", "tree_depth" ] ]
2
[]
false
[ "TreeNode" ]
true
pytest
true
[]
true
7b890f72a11cfa9ccc1bf4686cc26bb0cb168f31
c08f738be78de760e6ddc5dcdd6b033e6998af8d
v1.0
instruct
Codeforces
Codeforces_3452_I
You are given a two-dimensional grid of size $$$n \times m$$$ where each cell contains a non-negative integer. You need to perform a set of operations to reduce the positive value in each cell to zero. In one operation, you can select a subrectangle of the grid (comprising of a contiguous block of rows and columns) and...
def min_operations(grid): n = len(grid) m = len(grid[0]) operations = 0 max_value = max(max(row) for row in grid) return max_value def min_operations_from_input(n, m, grid_values): grid = [list(map(int, grid_values[i * m : (i + 1) * m])) for i in range(n)] return min_operations(grid)
def test_min_operations(): assert min_operations_from_input(2, 3, [1, 2, 1, 0, 1, 1]) == 2 assert min_operations_from_input(1, 1, [5]) == 5 assert min_operations_from_input(3, 3, [3, 3, 3, 3, 3, 3, 3, 3, 3]) == 3 assert min_operations_from_input(2, 2, [0, 0, 0, 0]) == 0 assert min_operations_from_in...
[ { "docstring": null, "function_declaration": "def min_operations(grid):", "function_name": "min_operations", "parameter_list": "(grid)" }, { "docstring": null, "function_declaration": "def min_operations_from_input(n, m, grid_values):", "function_name": "min_operations_from_input", ...
[ 0, 0, 1, 1, 1, 1, 0, 0, 0, 0 ]
4
medium
0.4
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def minimum_operations(grid):\n n = len(grid)\n m = len(grid[0])\n operations = 0\n\n # First, handle row-wise reductions\n for row in grid:\n ...
trial_gpt4o_5
{ "original_instruction": "", "prompt_id": "00003452", "row_id": 3452, "seed_ids": "[138]" }
0.681419
Codeforces_3452
I
[ "min_operations", "min_operations_from_input" ]
2
[ [ "min_operations_from_input", "min_operations" ] ]
1
[]
false
[]
false
pytest
false
[]
true
73dff95a958f6810751d1cc75b9037ae6a519cb3
d9c2d7998ec808c0c4dbad16b5a85b2b7cdd589d
v1.0
instruct
Codeforces
Codeforces_3513_I
You are given a string s, which consists of lowercase English characters only. A substring of s is defined as any contiguous sequence of characters within s. A k-palindrome is a substring that can be transformed into a palindrome by changing at most k characters. Your task is to find the number of substrings in s that...
def is_k_palindrome(sub, k): """ Check if the substring `sub` can be converted to a palindrome by changing at most `k` characters. """ l = len(sub) mismatch_count = 0 for i in range(l // 2): if sub[i] != sub[l - 1 - i]: mismatch_count += 1 if mismatch_count >...
from solution import count_k_palindromes def test_single_character(): assert count_k_palindromes("a", 0) == 1 assert count_k_palindromes("a", 1) == 1 def test_multiple_characters(): assert count_k_palindromes("ab", 0) == 2 assert count_k_palindromes("ab", 1) == 3 def test_example_case(): assert c...
[ { "docstring": "Check if the substring `sub` can be converted to a palindrome by changing at most `k` characters.", "function_declaration": "def is_k_palindrome(sub, k):", "function_name": "is_k_palindrome", "parameter_list": "(sub, k)" }, { "docstring": "Count the number of substrings in `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_k_palindrome(sub, k):\n \"\"\"\n Check if the substring `sub` can be converted to a palindrome by changing at most `k` characters.\n \"\"\"\n ...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00003513", "row_id": 3513, "seed_ids": "[6404]" }
0.866974
Codeforces_3513
I
[ "is_k_palindrome", "count_k_palindromes" ]
2
[ [ "count_k_palindromes", "is_k_palindrome" ] ]
1
[]
false
[]
false
pytest
true
[]
true
ccb3a9ac499310e919ba51f9441eefb1567e4f62
0520ee4e5c616963d724c6cf4c042df0dc41e83d
v1.0
instruct
Codeforces
Codeforces_3580_I
Anastasia is a brilliant mathematician who recently started exploring number theory. She has become fascinated with the concept of prime numbers and their properties. Recently, she came across Euler's Totient function, φ(n), which counts the number of positive integers up to n that are relatively prime to n. Given an ...
def gcd(a, b): """ Returns the greatest common divisor of a and b using the Euclidean algorithm. """ while b != 0: a, b = b, a % b return a def euler_totient(n): """ Returns the value of Euler's Totient function φ(n), which counts the number of positive integers up to n that ar...
from solution import euler_totient def test_euler_totient_1(): assert euler_totient(1) == 1 def test_euler_totient_10(): assert euler_totient(10) == 4 def test_euler_totient_2(): assert euler_totient(2) == 1 def test_euler_totient_3(): assert euler_totient(3) == 2 def test_euler_totient_4(): as...
[ { "docstring": "Returns the greatest common divisor of a and b using the Euclidean algorithm.", "function_declaration": "def gcd(a, b):", "function_name": "gcd", "parameter_list": "(a, b)" }, { "docstring": "Returns the value of Euler's Totient function φ(n), which counts the number \nof pos...
[ 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
9
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def euler_totient(n):\n \"\"\"\n Computes the value of Euler's Totient function φ(n).\n \"\"\"\n if n == 1:\n return 1\n \n result = ...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00003580", "row_id": 3580, "seed_ids": "[2610]" }
0.522004
Codeforces_3580
I
[ "gcd", "euler_totient" ]
2
[ [ "euler_totient", "gcd" ] ]
1
[]
false
[]
false
pytest
true
[]
true
f1f0827fd3373937afb4b9a5b91226a33d0f925b
deec4e5614229605e9e5cb541848ed118bfc7a3b
v1.0
instruct
Codeforces
Codeforces_3647_I
Given an undirected graph with `N` vertices and edges, you need to determine whether the graph contains any cycles. A cycle in a graph is a path that starts and ends at the same vertex and contains at least one other vertex. The first line contains an integer `N` (1 ≤ N ≤ 1000) — the number of vertices and `M` (0 ≤ M ...
def has_cycle(graph, n): visited = [False] * n parent = [-1] * n def dfs(v): visited[v] = True for u in graph[v]: if not visited[u]: parent[u] = v if dfs(u): return True elif parent[v] != u: return T...
from solution import contains_cycle def test_contains_cycle_case1(): N, M = 6, 6 edges = [(1, 2), (2, 3), (3, 4), (4, 1), (2, 5), (5, 6)] assert contains_cycle(N, M, edges) == "YES" def test_contains_cycle_case2(): N, M = 4, 3 edges = [(1, 2), (2, 3), (3, 4)] assert contains_cycle(N, M, edges)...
[ { "docstring": null, "function_declaration": "def has_cycle(graph, n):", "function_name": "has_cycle", "parameter_list": "(graph, n)" }, { "docstring": null, "function_declaration": "def contains_cycle(N, M, edges):", "function_name": "contains_cycle", "parameter_list": "(N, M, e...
[ 1, 1, 1, 1, 1, 1, 0, 0, 1, 1 ]
8
easy
0.8
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def has_cycle_dfs(graph, visited, parent, vertex):\n visited[vertex] = True\n for neighbor in graph[vertex]:\n if not visited[neighbor]:\n ...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00003647", "row_id": 3647, "seed_ids": "[6010]" }
0.715723
Codeforces_3647
I
[ "has_cycle", "contains_cycle" ]
2
[ [ "contains_cycle", "has_cycle" ] ]
1
[]
false
[]
false
pytest
true
[]
true
89ffcf22ccdb98d2cfbbb4f4eca7f12da427c71b
1134937ffbb87d0a564e7e0b6f87d6c97a30e678
v1.0
instruct
Codeforces
Codeforces_3649_I
You are given a number of balloons, each with a number of rings attached to it. Each balloon floats upwards with a certain initial velocity. If two balloons collide, they combine into one, maintaining a single ring count which is the sum of the original two. The velocity of the combined balloon is the average of their ...
import heapq def combine_balloons(n, balloons): # Priority queue for keeping track of smallest lexicographic pairs pq = [(i, balloons[i]) for i in range(n)] heapq.heapify(pq) result = [] while len(pq) > 1: # Get the two balloons with the smallest indices a_idx, a = heapq.heappo...
from solution import balloon_collisions def test_single_balloon(): input_data = ["1 500"] expected = [] assert balloon_collisions(1, input_data) == expected def test_two_balloons(): input_data = ["4 6", "7 1"] expected = [(0, 1)] assert balloon_collisions(2, input_data) == expected def test_t...
[ { "docstring": null, "function_declaration": "def combine_balloons(n, balloons):", "function_name": "combine_balloons", "parameter_list": "(n, balloons)" }, { "docstring": null, "function_declaration": "def balloon_collisions(n, input_data):", "function_name": "balloon_collisions", ...
[ 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 combine_balloons(initial_balloons):\n from heapq import heappop, heappush\n import heapq\n \n n = len(initial_balloons)\n events = []\n ...
trial_gpt4o_3
{ "original_instruction": "", "prompt_id": "00003649", "row_id": 3649, "seed_ids": "[6875]" }
0.555853
Codeforces_3649
I
[ "combine_balloons", "balloon_collisions" ]
2
[ [ "balloon_collisions", "combine_balloons" ] ]
1
[]
false
[]
false
pytest
true
[]
true
8c78342057699b5cb76f4f5f9aa242a32cbed361
3f790a766ba5a380344da4551cb61aee609ddb1e
v1.0
instruct
Codeforces
Codeforces_3675_I
You are given a binary tree. Each node of the tree contains a value. Your task is to flip the binary tree vertically and invert the values of all nodes. Flipping the binary tree vertically means that the nodes of the tree are mirrored along the vertical axis, meaning that the left child of a node becomes the right ch...
class TreeNode: def __init__(self, value=0, left=None, right=None): self.value = value self.left = left self.right = right def flip_and_invert_tree(root): if root is None: return None root.value = -root.value root.left, root.right = root.right, root.left fl...
from solution import flip_and_invert_tree_cases def test_single_case(): t = 1 test_cases = [ [ (1, 2, 3), (2, 4, 5), (3, -1, -1), (4, -1, -1), (5, -1, -1) ] ] expected = [[-1, -3, -2, -5, -4]] assert flip_and_invert_tree_ca...
[]
[ 1, 1, 1, 1, 1, 0, 1, 0, 1, 1 ]
8
easy
0.8
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "class TreeNode:\n def __init__(self, val=0, left=None, right=None):\n self.val = val\n self.left = left\n self.right = right\n\ndef bu...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00003675", "row_id": 3675, "seed_ids": "[5000]" }
0.66382
Codeforces_3675
I
[ "flip_and_invert_tree", "pre_order_traversal", "build_tree", "flip_and_invert_tree_cases" ]
4
[ [ "flip_and_invert_tree_cases", "build_tree" ], [ "flip_and_invert_tree_cases", "flip_and_invert_tree" ], [ "flip_and_invert_tree_cases", "pre_order_traversal" ] ]
3
[]
false
[ "TreeNode" ]
true
pytest
true
[]
true
a972342f3b8494fd5cb342ff4e51a0b68488fb3e
e4e57a013d763dc1ad4ddcd69007f980287c1aad
v1.0
instruct
Codeforces
Codeforces_3678_I
Tanya is playing a game with her friend Alex. In this game, Alex thinks of a binary string $$s$$ of length $$n$$ consisting only of characters '0' and '1'. To make things more interesting, Alex challenges Tanya to guess the binary string by asking a series of questions. Tanya is allowed to ask at most $$n \times \log_...
import math import sys from typing import List def make_query(substring: str) -> int: return substring.count('1') def guess_binary_string(s: str) -> str: n = len(s) guessed_string = ['0'] * n # Determine the number of queries we can make max_queries = round(n * math.log2(n)) # Perform th...
def test_guess_binary_string(): assert guess_binary_string("110") == "110" assert guess_binary_string("101010") == "101010" assert guess_binary_string("111000") == "111000" assert guess_binary_string("000111") == "000111" assert guess_binary_string("01010101") == "01010101" assert guess_binary_s...
[ { "docstring": null, "function_declaration": "def make_query(substring):", "function_name": "make_query", "parameter_list": "(substring)" }, { "docstring": null, "function_declaration": "def guess_binary_string(s):", "function_name": "guess_binary_string", "parameter_list": "(s)"...
[ 0, 1, 1, 1, 0, 0, 0, 1, 0 ]
4
medium
0.444
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "import sys\nimport math\n\ndef ask_query(start, end):\n \"\"\"\n Asks the question and returns the number of '1's in the substring s[start:end].\n \"...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00003678", "row_id": 3678, "seed_ids": "[584]" }
0.643744
Codeforces_3678
I
[ "make_query", "guess_binary_string" ]
2
[ [ "guess_binary_string", "make_query" ] ]
1
[]
false
[]
false
pytest
false
[]
true
8149233b241f842558979e02a01ebbe0e7cf69f8
c900997602d891d51b867403ea0a5ecf60b3b0d9
v1.0
instruct
Codeforces
Codeforces_3721_I
A company has a network of servers represented by a matrix $$$n \times n$$$ matrix $$$G$$$, where each cell $$$G[i][j]$$$ represents the time it takes to transfer data from server $$$i$$$ to server $$$j$$$. Given a specific server node $$$s$$$, determine the minimum time required to transfer data from the server $$$s$$...
from heapq import heappop, heappush import sys def dijkstra(n, G, s): dist = [float('inf')] * n dist[s] = 0 pq = [(0, s)] # priority queue of (cost, node) while pq: cur_dist, u = heappop(pq) if cur_dist > dist[u]: continue for v in range(n): ...
from solution import min_transfer_times def test_example(): n = 4 G = [ [0, 3, -1, -1], [3, 0, 1, -1], [-1, 1, 0, 2], [-1, -1, 2, 0] ] s = 0 assert min_transfer_times(n, G, s) == [0, 3, 4, 6] def test_unreachable_server(): n = 3 G = [ [0, 1, -1], ...
[ { "docstring": null, "function_declaration": "def dijkstra(n, G, s):", "function_name": "dijkstra", "parameter_list": "(n, G, s)" }, { "docstring": null, "function_declaration": "def min_transfer_times(n, G, s):", "function_name": "min_transfer_times", "parameter_list": "(n, G, s...
[ 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": "import heapq\n\ndef network_transfer_time(n, G, s):\n \"\"\"\n Determines the minimum time required to transfer data from server `s` to all other server...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00003721", "row_id": 3721, "seed_ids": "[3149]" }
0.644448
Codeforces_3721
I
[ "dijkstra", "min_transfer_times" ]
2
[ [ "min_transfer_times", "dijkstra" ] ]
1
[]
false
[]
false
pytest
true
[]
true
83c3c14c3f7ca4c2a79b893db09793073be94fd9
5e38d8664cbc6695c8f4a1929eec250fdd64030d
v1.0
instruct
Codeforces
Codeforces_3725_I
You are given an undirected graph with vertices numbered from 1 to n. Your task is to determine the minimum number of edges that need to be added to make the graph connected. A graph is connected if there is a path between any pair of vertices. The first line contains two integers n and m (1 ≤ n ≤ 100, 0 ≤ m ≤ n*(n-1)...
def find(parent, i): if parent[i] == i: return i return find(parent, parent[i]) def union(parent, x, y): root_x = find(parent, x) root_y = find(parent, y) if root_x != root_y: parent[root_x] = root_y def min_edges_to_connect_graph(n, m, edges): parent = list(range(n + 1)) ...
from solution import min_edges_to_connect_graph def test_single_node(): assert min_edges_to_connect_graph(1, 0, []) == 0 def test_already_connected_graph(): assert min_edges_to_connect_graph(4, 4, [(1, 2), (2, 3), (3, 4), (4, 1)]) == 0 def test_disconnected_graph(): assert min_edges_to_connect_graph(4, 2...
[ { "docstring": null, "function_declaration": "def find(parent, i):", "function_name": "find", "parameter_list": "(parent, i)" }, { "docstring": null, "function_declaration": "def union(parent, x, y):", "function_name": "union", "parameter_list": "(parent, x, y)" }, { "doc...
[ 1, 1, 1, 1, 1, 0, 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 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_8
{ "original_instruction": "", "prompt_id": "00003725", "row_id": 3725, "seed_ids": "[3108]" }
0.778014
Codeforces_3725
I
[ "find", "union", "min_edges_to_connect_graph" ]
3
[ [ "min_edges_to_connect_graph", "find" ], [ "min_edges_to_connect_graph", "union" ], [ "union", "find" ] ]
3
[]
false
[]
false
pytest
true
[]
true
7534fc470a8c519f66b105c48711cbd21de3987f
1afff2e6d804acb6220a443728542cc558e4cec5
v1.0
instruct
Codeforces
Codeforces_3805_I
Alice just started learning about directed graphs. Her friend Bob gave her a directed graph with n nodes and m edges. Each node is labeled from 1 to n. Bob wants Alice to process multiple queries about the connectivity between nodes. Alice needs to execute two types of queries: 1. Check if there is a path from node u...
import sys import heapq def create_adjacency_list(n, edges): adj_list = [[] for _ in range(n + 1)] for (a, b) in edges: adj_list[a].append(b) return adj_list def bfs(adj_list, start, end): n = len(adj_list) - 1 visited = [False] * (n + 1) queue = [start] visited[start] = True w...
def test_create_adjacency_list(): n = 5 edges = [(1, 2), (2, 3), (3, 4), (4, 5), (1, 5)] adj_list = create_adjacency_list(n, edges) assert adj_list == [[], [2, 5], [3], [4], [5], []] def test_bfs(): adj_list = [[], [2, 5], [3], [4], [5], []] assert bfs(adj_list, 1, 3) == True assert bfs(adj...
[ { "docstring": null, "function_declaration": "def create_adjacency_list(n, edges):", "function_name": "create_adjacency_list", "parameter_list": "(n, edges)" }, { "docstring": null, "function_declaration": "def bfs(adj_list, start, end):", "function_name": "bfs", "parameter_list"...
[ 0, 0, 1, 0, 0, 0, 0, 0, 0, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "from collections import deque, defaultdict\n\ndef bfs_shortest_path(graph, start, end):\n \"\"\"\n Uses BFS to find the shortest path in an unweighted g...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00003805", "row_id": 3805, "seed_ids": "[4009]" }
0.690694
Codeforces_3805
I
[ "create_adjacency_list", "bfs", "dijkstra", "process_queries", "main" ]
5
[ [ "process_queries", "bfs" ], [ "process_queries", "create_adjacency_list" ], [ "process_queries", "dijkstra" ] ]
3
[ "process_queries" ]
false
[]
false
pytest
false
[]
true
e14ec7f7f31dab35a797be2c3b5eb32b2b17fa60
47e2f88d9a9a8091be5abdb945944e373928fc36
v1.0
instruct
Codeforces
Codeforces_3881_I
Petya is also fond of different shapes and today he is playing with an n-sided regular polygon. He wants to draw a star within the polygon by connecting some of its vertices in a specific sequence. The sequence rules are as follows: 1. You start at vertex 1, then move to vertex k, then to vertex 2k, then 3k, and so on...
def is_star_possible(n, k): """ Determines if a non-degenerate star can be drawn using all vertices exactly once, and returns the sequence of vertices if possible. """ if n % k == 0 or gcd(n, k) != 1: return "NO" sequence = [] current_vertex = 0 for _ in range(n): s...
from solution import is_star_possible def test_example_1(): assert is_star_possible(5, 2) == "YES\n1 3 5 2 4" def test_example_2(): assert is_star_possible(6, 2) == "NO" def test_prime_number_sides(): assert is_star_possible(7, 3) == "YES\n1 4 7 3 6 2 5" def test_small_polygon(): assert is_star_...
[ { "docstring": "Determines if a non-degenerate star can be drawn using all vertices exactly once, \nand returns the sequence of vertices if possible.", "function_declaration": "def is_star_possible(n, k):", "function_name": "is_star_possible", "parameter_list": "(n, k)" }, { "docstring": "Re...
[ 0, 1, 0, 0, 1, 0, 0, 1, 1, 1 ]
5
medium
0.5
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_star_possible(n, k):\n \"\"\"\n Determines if a non-degenerate star can be drawn using all vertices exactly once. \n If possible, it returns \...
trial_gpt4o_7
{ "original_instruction": "", "prompt_id": "00003881", "row_id": 3881, "seed_ids": "[1903]" }
0.505127
Codeforces_3881
I
[ "is_star_possible", "gcd" ]
2
[ [ "is_star_possible", "gcd" ] ]
1
[]
false
[]
false
pytest
true
[]
true
1d3884606533c450a7e2eff2239c00876b699e4f
62d861364cb34d092a080df9ff0ca0479b160362
v1.0
instruct
Codeforces
Codeforces_3891_I
A software company has designed a new network routing protocol. Each router in the network can send packets to its neighboring routers. The routers are connected in an undirected graph, where each node represents a router and each edge represents a direct communication link between two routers. You are given a network ...
import heapq from collections import defaultdict def dijkstra(N, edges, S, D): graph = defaultdict(list) for u, v, w in edges: graph[u].append((v, w)) graph[v].append((u, w)) min_heap = [(0, S)] min_times = {i: float('inf') for i in range(1, N + 1)} min_times[S] = 0 ...
from solution import solve_network_routing def test_case_1(): N, M, K = 5, 6, 100 edges = [ (1, 2, 4), (1, 3, 2), (2, 3, 1), (2, 4, 5), (3, 4, 3), (3, 5, 10) ] S, D = 1, 5 assert solve_network_routing(N, M, K, edges, S, D) == 12 def test_case_2(): ...
[ { "docstring": null, "function_declaration": "def dijkstra(N, edges, S, D):", "function_name": "dijkstra", "parameter_list": "(N, edges, S, D)" }, { "docstring": null, "function_declaration": "def solve_network_routing(N, M, K, edges, S, D):", "function_name": "solve_network_routing"...
[ 1, 1, 1, 1, 1, 0, 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": "import heapq\nimport sys\n\ndef minimum_forwarding(N, M, K, edges, S, D):\n # Create adjacency list\n graph = {i: [] for i in range(1, N+1)}\n for u,...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00003891", "row_id": 3891, "seed_ids": "[3741]" }
0.721687
Codeforces_3891
I
[ "dijkstra", "solve_network_routing" ]
2
[ [ "solve_network_routing", "dijkstra" ] ]
1
[]
false
[]
false
pytest
true
[]
true
6231ba805a9043392b6c27e33a19499058d64956
58ddb64a60628030dee6947765707ea320dfcec8
v1.0
instruct
Codeforces
Codeforces_3953_I
Given an array A of n integers, return an array of all the prime numbers in the same relative order as they appear in A. Additionally, for each prime number found, replace its occurrence with the smallest integer greater than the prime number but not a prime itself (a composite number). A prime number is a natural num...
from typing import List def is_prime(num: int) -> bool: if num <= 1: return False for i in range(2, int(num**0.5) + 1): if num % i == 0: return False return True def smallest_composite_greater_than(n: int) -> int: candidatate = n + 1 while True: if not is_prime(...
from solution import replace_primes def test_replace_primes_with_primes(): assert replace_primes([2, 3, 5, 7]) == [4, 4, 6, 8] def test_replace_primes_with_mixed(): assert replace_primes([2, 3, 4, 5, 10, 15]) == [4, 4, 4, 6, 10, 15] def test_replace_primes_no_primes(): assert replace_primes([1, 4, 6,...
[ { "docstring": null, "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": null, "function_declaration": "def smallest_composite_greater_than(n):", "function_name": "smallest_composite_greater_than", "parameter_list...
[ 0, 1, 1, 1, 1, 1, 0, 0, 0, 0 ]
5
medium
0.5
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "from typing import List\n\ndef is_prime(num: int) -> bool:\n if num <= 1:\n return False\n if num == 2:\n return True\n if num % 2 == 0...
trial_gpt4o_4
{ "original_instruction": "", "prompt_id": "00003953", "row_id": 3953, "seed_ids": "[8264]" }
0.635187
Codeforces_3953
I
[ "is_prime", "smallest_composite_greater_than", "replace_primes" ]
3
[ [ "replace_primes", "is_prime" ], [ "replace_primes", "smallest_composite_greater_than" ], [ "smallest_composite_greater_than", "is_prime" ] ]
3
[]
false
[]
false
pytest
true
[]
true
60ee90f0a028a44aaefb37716e55e99595fa92a5
051c915c9a6d6f2a72a68ff6c0ba2389b1627b4b
v1.0
instruct
Codeforces
Codeforces_3986_I
Given an array of distinct integers, you need to construct a binary search tree (BST) by inserting the elements of the array one by one in the order they appear in the array. Your task is to determine the height of this BST. The height of a BST is defined as the number of edges in the longest path from the root to a le...
class TreeNode: def __init__(self, val): self.val = val self.left = None self.right = None def insert_into_bst(root, val): if not root: return TreeNode(val) if val < root.val: root.left = insert_into_bst(root.left, val) else: root.right = insert_into_bst(...
from solution import solve, TreeNode, insert_into_bst, bst_height, bst_from_array_height def test_example_case(): test_cases = [(5, [3, 2, 1, 5, 4]), (3, [10, 8, 12])] assert solve(test_cases) == [2, 1] def test_single_element(): test_cases = [(1, [4])] assert solve(test_cases) == [0] def test_increa...
[]
[ 0, 1, 1, 1, 1, 1, 1, 0, 1, 1 ]
8
easy
0.8
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "class TreeNode:\n def __init__(self, key):\n self.left = None\n self.right = None\n self.val = key\n\ndef insert(root, key):\n if r...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00003986", "row_id": 3986, "seed_ids": "[5810]" }
0.5518
Codeforces_3986
I
[ "insert_into_bst", "bst_height", "bst_from_array_height", "solve" ]
4
[ [ "bst_from_array_height", "bst_height" ], [ "bst_from_array_height", "insert_into_bst" ], [ "solve", "bst_from_array_height" ] ]
3
[]
false
[ "TreeNode" ]
true
pytest
true
[]
true
23c2c97ae30a1e37f231f1523c3fd1dcc4914917
c3db3048dacc5be35afbf0d965d6c38b619b4f42
v1.0
instruct
Codeforces
Codeforces_4004_I
You are given an array A of n integers and q queries. Each query is of the form i j which means find the sum of integers from the i-th to the j-th index (both inclusive) in the array. Output the result of each query. The first line contains two integers n, q (1 ≤ n ≤ 105, 1 ≤ q ≤ 50,000), the length of the array and ...
def preprocess_sum_array(arr): """ Preprocess the original array to create a prefix sum array. """ prefix_sum = [0] * (len(arr) + 1) for idx in range(len(arr)): prefix_sum[idx + 1] = prefix_sum[idx] + arr[idx] return prefix_sum def query_sum(prefix_sum, i, j): """ Returns the su...
from solution import preprocess_sum_array, query_sum, process_queries def test_preprocess_sum_array(): arr = [1, 2, 3, 4, 5] expected_prefix_sum = [0, 1, 3, 6, 10, 15] assert preprocess_sum_array(arr) == expected_prefix_sum def test_query_sum(): prefix_sum = [0, 1, 3, 6, 10, 15] assert query_sum(p...
[ { "docstring": "Preprocess the original array to create a prefix sum array.", "function_declaration": "def preprocess_sum_array(arr):", "function_name": "preprocess_sum_array", "parameter_list": "(arr)" }, { "docstring": "Returns the sum from index i to j using the prefix sum array.", "f...
[ 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 range_sum(arr, queries):\n \"\"\"\n Given an array of integers `arr` and a list of queries. Each query contains two integers i and j.\n This func...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00004004", "row_id": 4004, "seed_ids": "[3332]" }
0.747681
Codeforces_4004
I
[ "preprocess_sum_array", "query_sum", "process_queries" ]
3
[ [ "process_queries", "preprocess_sum_array" ], [ "process_queries", "query_sum" ] ]
2
[ "process_queries" ]
false
[]
false
pytest
true
[]
true
28df85dbfc01568de436f68ce93fb8625a1c4233
45d913bde0c628ec20c202f7fa49045db639ad5b
v1.0
instruct
Codeforces
Codeforces_4022_I
You are given a grid with n rows and m columns, consisting of cells filled with non-negative integers. Your task is to find the size of the largest square sub-grid where all the numbers are the same. The size of a square sub-grid is defined by the length of its side. The first line of the input contains two integers n...
def largest_square_subgrid_same_numbers(grid): n = len(grid) m = len(grid[0]) dp = [[0] * m for _ in range(n)] max_side = 0 for i in range(n): for j in range(m): if i == 0 or j == 0: dp[i][j] = 1 else: if grid[i][j] == grid[i-1][j]...
from solution import get_largest_square_size def test_example_case(): n = 4 m = 5 grid_data = "1 2 3 4 5\n1 1 1 2 2\n1 1 1 2 2\n1 1 1 2 2" assert get_largest_square_size(n, m, grid_data) == 3 def test_single_cell_grid(): n = 1 m = 1 grid_data = "7" assert get_largest_square_size(n, m, ...
[ { "docstring": null, "function_declaration": "def largest_square_subgrid_same_numbers(grid):", "function_name": "largest_square_subgrid_same_numbers", "parameter_list": "(grid)" }, { "docstring": null, "function_declaration": "def get_largest_square_size(n, m, grid_data):", "function...
[ 1, 1, 1, 0, 1, 1, 1, 1, 1, 1 ]
9
easy
0.9
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def largest_square_subgrid(grid, n, m):\n if n == 0 or m == 0:\n return 0\n dp = [[0] * m for _ in range(n)]\n max_side_length = 0\n\n for ...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00004022", "row_id": 4022, "seed_ids": "[2912]" }
0.664224
Codeforces_4022
I
[ "largest_square_subgrid_same_numbers", "get_largest_square_size" ]
2
[ [ "get_largest_square_size", "largest_square_subgrid_same_numbers" ] ]
1
[]
false
[]
false
pytest
true
[]
true
156373a5a57b98e005eb43505957c0b47d82420f
52daa01a0b53210da3eef56b7452ea0216e30080
v1.0
instruct
Codeforces
Codeforces_4057_I
Dr. Smith loves to model bacterial growth in his petri dishes. He records the growth as a grid of integers, where each integer represents the amount of bacteria in that section of the dish at a specific time. He notices a peculiar pattern: each integer is either a prime number or can be expressed as the product of two ...
def is_prime(num): if num <= 1: return False if num <= 3: return True if num % 2 == 0 or num % 3 == 0: return False i = 5 while (i * i) <= num: if num % i == 0 or num % (i + 2) == 0: return False i += 6 return True def is_valid_grid(grid, n):...
import pytest from solution import validate_bacterial_growth_grid def test_valid_grid(): n = 3 grid = [ [2, 3, 4], [7, 17, 6], [2, 2, 3] ] assert validate_bacterial_growth_grid(n, grid) == "Valid" def test_invalid_grid(): n = 2 grid = [ [8, 3], [7, 5] ...
[ { "docstring": null, "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": null, "function_declaration": "def is_valid_grid(grid, n):", "function_name": "is_valid_grid", "parameter_list": "(grid, n)" }, { "d...
[ 0, 0, 0, 0, 0, 0, 0, 1, 0, 1 ]
2
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(x):\n \"\"\"Helper function to check if a number is prime.\"\"\"\n if x <= 1:\n return False\n if x <= 3:\n return True\n ...
trial_gpt4o_7
{ "original_instruction": "", "prompt_id": "00004057", "row_id": 4057, "seed_ids": "[753]" }
0.577591
Codeforces_4057
I
[ "is_prime", "is_valid_grid", "validate_bacterial_growth_grid" ]
3
[ [ "is_valid_grid", "is_prime" ], [ "validate_bacterial_growth_grid", "is_valid_grid" ] ]
2
[]
false
[]
false
pytest
true
[]
true
3baae10664e2131d65fbf08b2dae1b15531db972
c533166c6e38f1946c03a59a2775365dce6f0fac
v1.0
instruct
Codeforces
Codeforces_4065_I
You have been given an integer array $$$a$$$ of length $$$n$$$ and a positive integer $$$k$$$ ($$$1 \le k \le n$$$). Your task is to partition the array into exactly $$$k$$$ non-empty contiguous subarrays such that the maximum sum among these subarrays is minimized. In other words, if we denote by $$$S_i$$$ the sum of ...
def can_partition(nums, k, max_sum): """ Helper function to check if we can partition the array into k parts with each part having sum <= max_sum """ current_sum = 0 required_parts = 1 for num in nums: if current_sum + num > max_sum: required_parts += 1 current_sum =...
from solution import solve def test_solve(): test_cases = [ (5, 2, [7, 2, 5, 10, 8]), (6, 3, [1, 2, 3, 4, 5, 6]), ] expected_outputs = [18, 9] results = solve(test_cases) for result, expected in zip(results, expected_outputs): assert result == expected def test_solve_s...
[ { "docstring": "Helper function to check if we can partition the array into k parts with each part having sum <= max_sum ", "function_declaration": "def can_partition(nums, k, max_sum):", "function_name": "can_partition", "parameter_list": "(nums, k, max_sum)" }, { "docstring": "Function to ...
[ 1, 0, 0, 0, 1, 1, 0, 0, 0, 1 ]
4
medium
0.4
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def canPartition(nums, k, maxSum):\n current_sum = 0\n num_subarrays = 1\n for num in nums:\n if current_sum + num > maxSum:\n curr...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00004065", "row_id": 4065, "seed_ids": "[489]" }
0.779531
Codeforces_4065
I
[ "can_partition", "minimize_max_sum", "solve" ]
3
[ [ "minimize_max_sum", "can_partition" ], [ "solve", "minimize_max_sum" ] ]
2
[]
false
[]
false
pytest
true
[]
true
37664f74d5b0e3a1da55b956d48f7cf90d069afa
5be9444a8f30af6c3b795ad3fd2bfc29931b5ed4
v1.0
instruct
Codeforces
Codeforces_4097_I
You are given a tree with `n` nodes rooted at node `1`. Each node has a value assigned to it. Your task is to support the following two types of operations: 1. **Update Operation**: - `1 u v`: Assign the value `v` to the node `u`. 2. **Query Operation**: - `2 u`: Determine the maximum value in the subtree r...
def update_value(values, u, v): """ Update the value of node u to v. Args: values (dict): A dictionary containing the values of the nodes. u (int): The node to update. v (int): The new value. """ values[u] = v def query_max_value(tree, values, u): """ Determine the maximum ...
import pytest from solution import update_value, query_max_value, process_operations def test_update_value(): values = {1: 1, 2: 5, 3: 3} update_value(values, 3, 10) assert values[3] == 10 def test_query_max_value(): tree = {1: [2], 2: [1, 3], 3: [2, 4, 5], 4: [3], 5: [3]} values = {1: 1, 2: 5, 3:...
[ { "docstring": "Update the value of node u to v.\n\nArgs:\nvalues (dict): A dictionary containing the values of the nodes.\nu (int): The node to update.\nv (int): The new value.", "function_declaration": "def update_value(values, u, v):", "function_name": "update_value", "parameter_list": "(values, ...
[ 0, 0, 1, 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": "class TreeNode:\n def __init__(self, value):\n self.value = value\n self.children = []\n self.max_value = value\n\nclass Tree:\n de...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00004097", "row_id": 4097, "seed_ids": "[3139]" }
0.65922
Codeforces_4097
I
[ "update_value", "query_max_value", "process_operations" ]
3
[ [ "process_operations", "query_max_value" ], [ "process_operations", "update_value" ] ]
2
[]
false
[]
false
pytest
true
[]
true
f5b01f5781bfa18e501148b41a82203197c68e54
4fe2695e315ac8ef7f78e6085a73af90788048ee
v1.0
instruct
Codeforces
Codeforces_4109_I
A company is hosting a coding competition, and they want to ensure that the competitors' usernames follow specific guidelines to avoid any conflicts or inappropriate names. The username must adhere to the following rules: 1. The username must start with an uppercase letter. 2. The username must be at least 6 character...
import re def is_valid_username(username): """ Validates a single username based on the given rules. """ if len(username) < 6 or len(username) > 12: return False if not username[0].isupper(): return False if not any(char.isdigit() for char in username): return False ...
from solution import is_valid_username, validate_usernames def test_is_valid_username(): assert is_valid_username("A1b234") == True assert is_valid_username("Zebra2020") == True assert is_valid_username("helloWorld") == False assert is_valid_username("Short1") == True assert is_valid_username("TooL...
[ { "docstring": "Validates a single username based on the given rules.", "function_declaration": "def is_valid_username(username):", "function_name": "is_valid_username", "parameter_list": "(username)" }, { "docstring": "Given a number of test cases t, and a list of usernames, returns a list ...
[ 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 validate_username(username):\n \"\"\"\n Validate if the username meets the required guidelines:\n - The username must start with an uppercase let...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00004109", "row_id": 4109, "seed_ids": "[7414]" }
0.69705
Codeforces_4109
I
[ "is_valid_username", "validate_usernames" ]
2
[ [ "validate_usernames", "is_valid_username" ] ]
1
[]
false
[]
false
pytest
true
[]
true
f9c1ecd6be758ecda6d3e23b09321fb8da3f8098
46dc24152eaa609bbf5ffd0d698c5bb6be57bd65
v1.0
instruct
Codeforces
Codeforces_4124_I
You are given an array of $$n$$ positive integers. A subarray is a contiguous part of the original array. We define the product of a subarray as the product of all its elements. We want to find the largest product of any subarray of the given array. Your task is to output the maximum product of any subarray. **Input...
def max_product_subarray(arr): """ Computes the maximum product of any subarray. """ n = len(arr) if n == 0: return 0 max_product = arr[0] min_product = arr[0] result = arr[0] for i in range(1, n): if arr[i] < 0: max_product, min_product = min_pr...
from solution import get_max_product_of_subarray def test_example_1(): assert get_max_product_of_subarray(5, [1, 2, 3, 4, 5]) == 120 def test_example_2(): assert get_max_product_of_subarray(4, [6, 2, 1, 8]) == 96 def test_single_element(): assert get_max_product_of_subarray(1, [10]) == 10 assert get_...
[ { "docstring": "Computes the maximum product of any subarray.", "function_declaration": "def max_product_subarray(arr):", "function_name": "max_product_subarray", "parameter_list": "(arr)" }, { "docstring": null, "function_declaration": "def get_max_product_of_subarray(n, array):", "...
[ 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 max_subarray_product(arr):\n \"\"\"\n Returns the maximum product of any subarray in the given array.\n \"\"\"\n # Initialize the variables fo...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00004124", "row_id": 4124, "seed_ids": "[7712]" }
0.833647
Codeforces_4124
I
[ "max_product_subarray", "get_max_product_of_subarray" ]
2
[ [ "get_max_product_of_subarray", "max_product_subarray" ] ]
1
[]
false
[]
false
pytest
true
[]
true
846d87f10e344b590551ff4c40b032b5f8f10d2d
adde5d40f2657e9b618f0351ca272ee5fef70edd
v1.0
instruct
Codeforces
Codeforces_4142_I
In a given city, there are several intersections connected by roads. Each road has an associated length. A traveler wants to determine the shortest possible distance between two specific intersections using the available roads. Implement an algorithm to help the traveler find this shortest path. The first input line c...
import heapq def dijkstra(n, roads, start, end): """ Returns the shortest path from start to end using Dijkstra's algorithm. Args: n (int): Number of intersections. roads (list of tuples): Roads between intersections (u, v, w). start (int): Starting intersection. end (int): Ending inte...
def test_get_shortest_path_basic(): n = 4 m = 4 roads_data = [ "1 2 5", "1 3 9", "2 3 2", "3 4 6" ] a, b = 1, 4 assert get_shortest_path(n, m, roads_data, a, b) == 13 def test_get_shortest_path_no_path(): n = 4 m = 2 roads_data = [ "1 2 5", ...
[ { "docstring": "Returns the shortest path from start to end using Dijkstra's algorithm.\n\nArgs:\nn (int): Number of intersections.\nroads (list of tuples): Roads between intersections (u, v, w).\nstart (int): Starting intersection.\nend (int): Ending intersection.\n\nReturns:\nint or str: The shortest path len...
[ 1, 0, 1, 1, 1, 0, 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 heapq\n\ndef dijkstra(n, adj_list, start, end):\n \"\"\"\n Function to find the shortest path using Dijkstra's algorithm.\n \"\"\"\n distan...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00004142", "row_id": 4142, "seed_ids": "[2959]" }
0.763419
Codeforces_4142
I
[ "dijkstra", "get_shortest_path" ]
2
[ [ "get_shortest_path", "dijkstra" ] ]
1
[]
false
[]
false
pytest
false
[]
true
e2623a0c654a2dc8899ff018935c406f177a57a8
b14dbc4a7ae93aa5a3a905dbf5042cecaafb1fea
v1.0
instruct
Codeforces
Codeforces_4215_I
You are given a weighted directed graph with `n` vertices and `m` edges. Each vertex is numbered from `1` to `n`. You need to answer `q` queries, where each query asks for the shortest path from vertex `u` to vertex `v`. The first line contains three integers `n`, `m`, and `q` ($1 \le n \le 2000$, $1 \le m \le 10000$,...
def floyd_warshall(n, edges): # Initialize the distance matrix dist = [[float('inf')] * n for _ in range(n)] for i in range(n): dist[i][i] = 0 for a, b, c in edges: dist[a-1][b-1] = min(dist[a-1][b-1], c) # Apply Floyd-Warshall algorithm for k in range(n): ...
def test_floyd_warshall_basic(): n = 4 edges = [(1, 2, 1), (2, 3, 3), (3, 4, 2), (1, 4, 10)] queries = [(1, 4), (4, 1), (1, 3)] expected_output = [6, -1, 4] assert shortest_path(n, edges, queries) == expected_output def test_graph_with_no_path(): n = 3 edges = [(1, 2, 4), (2, 3, 2)] ...
[ { "docstring": null, "function_declaration": "def floyd_warshall(n, edges):", "function_name": "floyd_warshall", "parameter_list": "(n, edges)" }, { "docstring": null, "function_declaration": "def shortest_path(n, edges, queries):", "function_name": "shortest_path", "parameter_li...
[ 1, 0, 0, 1, 0, 0, 0, 1, 1, 0 ]
4
medium
0.4
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def floyd_warshall(n, edges):\n \"\"\"\n Floyd-Warshall algorithm to find the shortest distances between all pairs of nodes.\n \"\"\"\n inf = floa...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00004215", "row_id": 4215, "seed_ids": "[3582]" }
0.734572
Codeforces_4215
I
[ "floyd_warshall", "shortest_path" ]
2
[ [ "shortest_path", "floyd_warshall" ] ]
1
[]
false
[]
false
pytest
false
[]
true
c4bf2161729c76fe97fc19f1cad2a20c8146204b
a8158b64432779fcae3ffa6264690c72d62de888
v1.0
instruct
Codeforces
Codeforces_4227_I
You are managing a set of servers and each server has a limited processing capacity. Occasionally, you need to distribute a set of tasks to these servers efficiently to minimize the maximum load among all servers. This is a classic load balancing problem. You are given two things: 1. An array of integers, `tasks`, whe...
def can_distribute(tasks, max_load, k): current_load = 0 servers_used = 1 for task in tasks: if current_load + task > max_load: servers_used += 1 current_load = task if servers_used > k: return False else: current_load += t...
def test_minimize_max_load_single_task(): assert minimize_max_load([5], 1) == 5 def test_minimize_max_load_all_equal_tasks(): assert minimize_max_load([10, 10, 10, 10], 2) == 20 def test_minimize_max_load_varied_tasks(): assert minimize_max_load([10, 20, 30, 40, 50], 3) == 60 def test_minimize_max_load_s...
[ { "docstring": null, "function_declaration": "def can_distribute(tasks, max_load, k):", "function_name": "can_distribute", "parameter_list": "(tasks, max_load, k)" }, { "docstring": null, "function_declaration": "def minimize_max_load(tasks, k):", "function_name": "minimize_max_load"...
[ 1, 0, 1, 0, 1, 0, 0, 0, 0, 1 ]
4
medium
0.4
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def canDistribute(tasks, k, max_load):\n servers = [0] * k\n for task in tasks:\n if task > max_load:\n return False\n for i in...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00004227", "row_id": 4227, "seed_ids": "[8045]" }
0.659424
Codeforces_4227
I
[ "can_distribute", "minimize_max_load" ]
2
[ [ "minimize_max_load", "can_distribute" ] ]
1
[]
false
[]
false
pytest
false
[]
true
88db7df49cebbdb22d133d56dd84010249667b6d
61cc08a84c551f2ca7114a85c57be09343894324
v1.0
instruct
Codeforces
Codeforces_4264_I
You are given a directed acyclic graph (DAG) with `n` nodes and `m` edges. Each node has a non-negative integer value assigned to it. You need to answer multiple queries about the graph. The DAG is represented as follows: - **First line**: Two integers `n` and `m` (1 ≤ n ≤ 10^5, 0 ≤ m ≤ 2*10^5), the number of nodes an...
from collections import defaultdict, deque def update_value(node_values, node, value): node_values[node] = value def reachable_sum(graph, node_values, node): visited = set() queue = deque([node]) total_sum = 0 while queue: current = queue.popleft() if current not in visited: ...
from solution import update_value, reachable_sum, process_queries def test_update_value(): node_values = [0, 10, 20, 30, 40, 50] update_value(node_values, 3, 0) assert node_values[3] == 0 def test_reachable_sum(): graph = defaultdict(list, {1: [2, 3], 2: [], 3: [4], 4: [5]}) node_values = [0, 10, ...
[ { "docstring": null, "function_declaration": "def update_value(node_values, node, value):", "function_name": "update_value", "parameter_list": "(node_values, node, value)" }, { "docstring": null, "function_declaration": "def reachable_sum(graph, node_values, node):", "function_name":...
[ 0, 0, 0, 1, 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": "from collections import defaultdict, deque\n\nclass DAGWithQueries:\n def __init__(self, n, node_values, edges):\n self.n = n\n self.node_val...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00004264", "row_id": 4264, "seed_ids": "[7768]" }
0.687378
Codeforces_4264
I
[ "update_value", "reachable_sum", "process_queries" ]
3
[ [ "process_queries", "reachable_sum" ], [ "process_queries", "update_value" ] ]
2
[ "process_queries" ]
false
[]
false
pytest
true
[]
true
97b919bd86139a09c0382bec2c97818556b5b02a
130ca1ea08c08f538a2c43236a7e99cf7fb0f9f7
v1.0
instruct
Codeforces
Codeforces_4293_I
The task is to predict the remaining useful life (RUL) of a set of industrial machines based on historical sensor data. For each machine, you are given time-series sensor data collected from various sensors installed on the machines. Your goal is to build a model that can estimate the remaining useful life of the machi...
import pandas as pd import numpy as np from sklearn.model_selection import train_test_split from sklearn.impute import SimpleImputer from sklearn.preprocessing import StandardScaler from sklearn.ensemble import RandomForestRegressor from sklearn.pipeline import Pipeline from sklearn.metrics import mean_squared_error fr...
from solution import preprocess_data, train_model, predict_rul, save_submission, calculate_rmse import pandas as pd import os def test_preprocess_data(): df = pd.DataFrame({ 'machine_id': [1, 2], 'timestamp': ['2023-01-01 00:00:00', '2023-01-01 00:01:00'], 'sensor_1': [1.0, 2.0], 's...
[ { "docstring": "Preprocess the input data by handling missing values and standardizing the features.\n\nParameters:\n- df: DataFrame containing the machine sensor data and RUL column.\n\nReturns:\n- Transformed DataFrame with sensor data preprocessed.", "function_declaration": "def preprocess_data(df):", ...
[ 0, 0, 0, 0, 0, 1, 1, 0, 0, 0 ]
2
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "import pandas as pd\nimport numpy as np\nfrom sklearn.preprocessing import StandardScaler\nfrom sklearn.impute import SimpleImputer\nfrom sklearn.ensemble imp...
trial_gpt4o_5
{ "original_instruction": "", "prompt_id": "00004293", "row_id": 4293, "seed_ids": "[3140]" }
0.578715
Codeforces_4293
I
[ "preprocess_data", "train_model", "predict_rul", "save_submission", "calculate_rmse" ]
5
[ [ "predict_rul", "preprocess_data" ], [ "train_model", "preprocess_data" ] ]
2
[]
false
[]
false
pytest
true
[ "numpy", "pandas", "sklearn" ]
false
5dd879c38e24a05875b8f718877aa008601dbcc8
1731f056443417a557f1d99bdf5cb34dc27fdf41
v1.0
instruct
Codeforces
Codeforces_4373_I
You are given a list of n strings. Your goal is to determine if any two strings in the list are anagrams of each other. Two strings are considered anagrams if they can be rearranged to form the same string. The first line of input contains an integer n (1 ≤ n ≤ 100), the number of strings. The following n lines each ...
def check_anagrams(strings): """ Returns "YES" if any two strings in the list are anagrams of each other, otherwise "NO". """ sorted_strings = [''.join(sorted(s)) for s in strings] return "YES" if len(sorted_strings) != len(set(sorted_strings)) else "NO" # Function to be used for testing purposes d...
from solution import anagram_detection def test_no_anagrams(): assert anagram_detection(3, ["abc", "def", "ghi"]) == "NO" def test_with_anagrams(): assert anagram_detection(5, ["listen", "silent", "apple", "pale", "leap"]) == "YES" def test_same_word_multiple_times(): assert anagram_detection(3, ["tes...
[ { "docstring": "Returns \"YES\" if any two strings in the list are anagrams of each other, otherwise \"NO\".", "function_declaration": "def check_anagrams(strings):", "function_name": "check_anagrams", "parameter_list": "(strings)" }, { "docstring": null, "function_declaration": "def ana...
[ 1, 0, 1, 0, 1, 1, 1, 0, 0, 1 ]
6
medium
0.6
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def are_any_anagrams(strings):\n \"\"\"\n Determines if any two strings in the list are anagrams of each other.\n \n Params:\n strings (list of...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00004373", "row_id": 4373, "seed_ids": "[3270]" }
0.642323
Codeforces_4373
I
[ "check_anagrams", "anagram_detection" ]
2
[ [ "anagram_detection", "check_anagrams" ] ]
1
[]
false
[]
false
pytest
true
[]
true
9ce0fbc3c68966d7ff7e0abd2b21b2538a10075c
888a8ff222823640219220122027064cdb1f026e
v1.0
instruct
Codeforces
Codeforces_4410_I
You are given an array of non-negative integers. Imagine placing each number in the array one after another to form the largest possible number. Your task is to write a function that takes the array as input and returns a string representing the largest number that can be formed by concatenating the array elements. T...
from functools import cmp_to_key def compare(x, y): if x + y > y + x: return -1 elif x + y < y + x: return 1 else: return 0 def largest_number(arr): """ Returns the largest number that can be formed by concatenating the array elements. """ # Convert all numbers to s...
from solution import largest_number def test_example_1(): assert largest_number([54, 546, 548]) == '54854654' def test_example_2(): assert largest_number([1, 34, 3, 98]) == '983431' def test_all_zeros(): assert largest_number([0, 0, 0, 0]) == '0' def test_single_element(): assert largest_number(...
[ { "docstring": null, "function_declaration": "def compare(x, y):", "function_name": "compare", "parameter_list": "(x, y)" }, { "docstring": "Returns the largest number that can be formed by concatenating the array elements.", "function_declaration": "def largest_number(arr):", "funct...
[ 0, 0, 1, 1, 0, 1, 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": "from functools import cmp_to_key\n\ndef largest_number(arr):\n \"\"\"\n Given a list of non-negative integers, arrange them such that they form the larg...
trial_gpt4o_6
{ "original_instruction": "", "prompt_id": "00004410", "row_id": 4410, "seed_ids": "[7033]" }
0.693125
Codeforces_4410
I
[ "compare", "largest_number" ]
2
[ [ "largest_number", "compare" ] ]
1
[]
false
[]
false
pytest
true
[]
true
445c514ad79e1c8ddbbe8fc54d1a1ece35fad578
a18604ef7d24ad03594e8b891620d306656f0967
v1.0
instruct
Codeforces
Codeforces_4535_I
A company is building a new office compound, which will consist of several connected buildings. Each building will be connected to exactly one other building, and this connection will be represented by bridges. The company's goal is to select the bridges in such a way that the overall maintenance cost of the bridges is...
def find(parent, i): if parent[i] == i: return i else: return find(parent, parent[i]) def union(parent, rank, x, y): xroot = find(parent, x) yroot = find(parent, y) if rank[xroot] < rank[yroot]: parent[xroot] = yroot elif rank[xroot] > rank[yroot]: parent[yr...
from solution import min_total_maintenance_cost def test_min_total_maintenance_cost_example1(): B = 4 P = 5 bridges = [ (1, 2, 10), (2, 3, 15), (3, 4, 4), (1, 4, 6), (1, 3, 5) ] assert min_total_maintenance_cost(B, P, bridges) == 19 def test_min_total_mainte...
[ { "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, 1, 0, 0, 1, 0 ]
3
medium
0.375
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def find(parent, i):\n if parent[i] == i:\n return i\n else:\n return find(parent, parent[i])\n\ndef union(parent, rank, x, y):\n root_...
trial_gpt4o_7
{ "original_instruction": "", "prompt_id": "00004535", "row_id": 4535, "seed_ids": "[3431]" }
0.668166
Codeforces_4535
I
[ "find", "union", "min_total_maintenance_cost" ]
3
[ [ "min_total_maintenance_cost", "find" ], [ "min_total_maintenance_cost", "union" ], [ "union", "find" ] ]
3
[]
false
[]
false
pytest
true
[]
true
d5619270ce71d5470ba34817a330c1b14ccc03c6
b4dc68d8ae2c05bb6a923ecd58bf3a756a4692b0
v1.0
instruct
Codeforces
Codeforces_4585_I
There is a network of computers where information needs to be efficiently relayed from one computer to another. The computers are connected by bidirectional communication channels. Each channel has a specific latency. Information can be sent from one computer to another either directly if there is a direct channel, or ...
import heapq def dijkstra(n, edges, source, target): 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)) pq = [(0, source, [])] visited = set() while pq: current_latency, node, path = heapq.heappop(pq) ...
from solution import min_latency_path def test_min_latency_path(): n = 5 m = 6 edges = [ (1, 2, 2), (1, 3, 4), (2, 3, 1), (2, 4, 7), (3, 5, 3), (4, 5, 1) ] s = 1 t = 5 result = min_latency_path(n, m, edges, s, t) assert result == "6\n1 2 3...
[ { "docstring": null, "function_declaration": "def dijkstra(n, edges, source, target):", "function_name": "dijkstra", "parameter_list": "(n, edges, source, target)" }, { "docstring": null, "function_declaration": "def min_latency_path(n, m, edges, s, t):", "function_name": "min_latenc...
[ 0, 0, 0, 1, 0, 0, 1, 1, 1 ]
4
medium
0.444
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "import heapq\n\ndef minimum_latency(n, m, edges, s, t):\n graph = {i: [] for i in range(1, n + 1)}\n for u, v, l in edges:\n graph[u].append((v, ...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00004585", "row_id": 4585, "seed_ids": "[6324]" }
0.604021
Codeforces_4585
I
[ "dijkstra", "min_latency_path" ]
2
[ [ "min_latency_path", "dijkstra" ] ]
1
[]
false
[]
false
pytest
true
[]
true
faba3d92ed68e3547488a1a85fad78a92d2f925e
3373be7a933375ba0b9dc208d818432107638151
v1.0
instruct
Codeforces
Codeforces_4612_I
You are given a function `manipulate_data` that takes an integer `n` and performs one of two actions: either multiplying `n` by a fixed prime number (2, 3, 5, or 7) or dividing `n` by it (if divisible). The function could apply different primes in different calls randomly but at most three times. Your task is to determ...
import random from typing import List, Tuple # Assuming we have the definition of manipulate_data function def manipulate_data(n: int) -> int: primes = [2, 3, 5, 7] prime = random.choice(primes) if random.choice([True, False]) and n % prime == 0: return n // prime else: return n * prime...
def test_detect_primes_single_multiply(): original_value = 10 # Mocking manipulate_data for specific behavior result = detect_primes(original_value) assert all(op in ['multiply', 'divide'] for prime, op in result) assert len(result) <= 3 assert all(prime in [2, 3, 5, 7] for prime, op in result) ...
[ { "docstring": null, "function_declaration": "def manipulate_data(n):", "function_name": "manipulate_data", "parameter_list": "(n)" }, { "docstring": null, "function_declaration": "def detect_primes(n):", "function_name": "detect_primes", "parameter_list": "(n)" } ]
[ 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 random\nfrom typing import List, Tuple\n\ndef manipulate_data(n: int) -> int:\n primes = [2, 3, 5, 7]\n prime = random.choice(primes)\n operat...
trial_gpt4o_3
{ "original_instruction": "", "prompt_id": "00004612", "row_id": 4612, "seed_ids": "[525]" }
0.682657
Codeforces_4612
I
[ "manipulate_data", "detect_primes" ]
2
[ [ "detect_primes", "manipulate_data" ] ]
1
[]
false
[]
false
pytest
false
[]
true
34e91b568029e04ae7f34063390b590de05d591d
08a4658acb56f9bb2c16847895aa59e459e672ee
v1.0
instruct
Codeforces
Codeforces_4698_I
You are given a system with n components, each initially working or malfunctioning. Each component may depend on some others' states to determine its own state in the next moment. The states of components are updated simultaneously based on these dependencies. You need to process a series of updates and queries: 1. A...
def update_component_state(states, component, new_state): """ Update the state of a specific component. """ states[component - 1] = new_state def propagate_states(states, dependencies): """ Propagate the state changes through the system based on dependencies. """ n = len(states) new...
def test_update_component_state(): states = [1, 0, 1] update_component_state(states, 1, 0) assert states == [0, 0, 1] def test_propagate_states(): states = [1, 0, 1] dependencies = [[2], [], [2, 1]] new_states = propagate_states(states, dependencies) assert new_states == [0, 0, 0] def test...
[ { "docstring": "Update the state of a specific component.", "function_declaration": "def update_component_state(states, component, new_state):", "function_name": "update_component_state", "parameter_list": "(states, component, new_state)" }, { "docstring": "Propagate the state changes throug...
[ 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 process_system(n, m, initial_states, dependencies, queries):\n current_states = initial_states[:]\n \n def propagate_states():\n new_state...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00004698", "row_id": 4698, "seed_ids": "[427]" }
0.58854
Codeforces_4698
I
[ "update_component_state", "propagate_states", "check_component_state", "process_queries" ]
4
[ [ "process_queries", "check_component_state" ], [ "process_queries", "propagate_states" ], [ "process_queries", "update_component_state" ] ]
3
[ "process_queries" ]
false
[]
false
pytest
false
[]
true
11398e92a817e81077e19c77bad6b6275430c737
2c1aea08ff996ebe1ef1bd93b4941123f5857715
v1.0
instruct
Codeforces
Codeforces_4707_I
You are given a rectangular grid with dimensions $$$n \times m$$$. Each cell of the grid is either empty or contains an obstacle. A robot is initially positioned at the top-left cell of the grid and needs to reach the bottom-right cell. The robot can move either right or down at any step, but cannot move into cells con...
MOD = 10**9 + 7 def num_paths(grid, n, m): if grid[0][0] == '#' or grid[n-1][m-1] == '#': return 0 dp = [[0 for _ in range(m)] for _ in range(n)] dp[0][0] = 1 for i in range(n): for j in range(m): if grid[i][j] == '#': dp[i][j] = 0 else:...
def test_num_paths(): assert count_paths(3, 3, ["...", ".#.", "..."]) == 2 assert count_paths(3, 3, ["...", "###", "..."]) == 0 assert count_paths(1, 1, ["."]) == 1 assert count_paths(2, 2, ["..", ".."]) == 2 assert count_paths(2, 2, ["#.", ".."]) == 0 assert count_paths(3, 3, [".#.", "...", ".....
[ { "docstring": null, "function_declaration": "def num_paths(grid, n, m):", "function_name": "num_paths", "parameter_list": "(grid, n, m)" }, { "docstring": null, "function_declaration": "def count_paths(n, m, lines):", "function_name": "count_paths", "parameter_list": "(n, m, lin...
[ 1, 1, 0, 1, 1, 0, 1, 1, 1, 0 ]
7
easy
0.7
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "MOD = 10**9 + 7\n\ndef num_paths(grid):\n n = len(grid)\n m = len(grid[0])\n dp = [[0] * m for _ in range(n)]\n\n # Starting point\n if grid[0]...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00004707", "row_id": 4707, "seed_ids": "[3199]" }
0.787971
Codeforces_4707
I
[ "num_paths", "count_paths" ]
2
[ [ "count_paths", "num_paths" ] ]
1
[]
false
[]
false
pytest
false
[]
true
37efc0ea6fa79dc0fd791b7c53b7988ad5b21cd8
330509ff9b7cc08782fc5fbf6fe38fa01ae6d53c
v1.0
instruct
Codeforces
Codeforces_4713_I
In the kingdom of Zylandia, cities are connected by bidirectional roads forming a tree structure. There are exactly $$$n$$$ cities and $$$n-1$$$ roads. Each city is represented as a node in a tree, and each road is an edge. Your task is to help Zylandia's royal network administration determine the optimal centrality of...
from collections import deque, defaultdict def bfs_distance(n, graph, start): distances = [-1] * (n + 1) queue = deque([start]) distances[start] = 0 while queue: node = queue.popleft() for neighbor in graph[node]: if distances[neighbor] == -1: distances[...
import pytest from solution import find_centrality def test_small_tree(): n = 3 edges = [(1, 2), (2, 3)] find_centrality(n, edges) # Expected output: 1 \n 2 def test_single_city(): n = 1 edges = [] find_centrality(n, edges) # Expected output: 0 \n 1 def test_linear_tree(): n = 4...
[ { "docstring": null, "function_declaration": "def bfs_distance(n, graph, start):", "function_name": "bfs_distance", "parameter_list": "(n, graph, start)" }, { "docstring": null, "function_declaration": "def find_tree_diameter(n, graph):", "function_name": "find_tree_diameter", "p...
[ 1, 1, 0, 0, 0, 0, 1, 0, 0, 0 ]
3
hard
0.3
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "from collections import deque\n\ndef find_centrality(n, edges):\n if n == 1:\n print(0)\n print(1)\n return\n \n # Create adjace...
trial_gpt4o_6
{ "original_instruction": "", "prompt_id": "00004713", "row_id": 4713, "seed_ids": "[3567]" }
0.594407
Codeforces_4713
I
[ "bfs_distance", "find_tree_diameter", "find_centrality" ]
3
[ [ "find_centrality", "find_tree_diameter" ], [ "find_tree_diameter", "bfs_distance" ] ]
2
[]
false
[]
false
pytest
true
[]
true
63c1ab16c4dab12ff71d621cbc1f272f4a24f499
b9fc9941631c37b91fc1a58b9179a14e3de52ac0
v1.0
instruct
Codeforces
Codeforces_4718_I
In a faraway land, there is a kingdom with n cities connected by a network of roads. The King wants to build a new road system such that there is exactly one additional road that directly connects two different cities, in order to improve the connectivity of the kingdom. The cities are numbered from 1 to n. However, t...
def is_possible_to_add_road(n, roads): """ Determines whether it is possible to add one road between two cities without creating a cycle. :param n: Number of cities :param roads: List of tuples (u, v) representing the current roads :return: "NO" if it is not possible to add any road without cre...
from solution import add_road_without_cycle def test_add_road_without_cycle_case1(): input_data = "5 4\n1 2\n1 3\n2 4\n3 4" expected_output = "YES\n" output = add_road_without_cycle(input_data) assert output.startswith("YES") a, b = map(int, output.split()[1:]) assert 1 <= a <= 5 and 1 <= b <= ...
[ { "docstring": "Determines whether it is possible to add one road between two cities without creating a cycle.\n\n:param n: Number of cities\n:param roads: List of tuples (u, v) representing the current roads\n:return: \"NO\" if it is not possible to add any road without creating a cycle,\n otherwise \"...
[ 1, 0, 0, 1, 0, 0, 0, 0, 1, 0 ]
3
hard
0.3
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def find_road_to_add(n, roads):\n \"\"\"\n Determine if there is a road that can be added without creating a cycle.\n \n Args:\n n: Number of c...
trial_gpt4o_3
{ "original_instruction": "", "prompt_id": "00004718", "row_id": 4718, "seed_ids": "[4723]" }
0.728211
Codeforces_4718
I
[ "is_possible_to_add_road", "add_road_without_cycle" ]
2
[ [ "add_road_without_cycle", "is_possible_to_add_road" ] ]
1
[]
false
[]
false
pytest
true
[]
true
19f5f0ebe4b3e54ab9b1d661e44b075615f22a6c
06746a3f22114ae9463c8512b4c02a7ececa5147
v1.0
instruct
Codeforces
Codeforces_4723_I
Develop a function that takes a square matrix of integers as input and determines if it is a magic square. A magic square is a matrix in which the sum of every row, the sum of every column, and the sum of both main diagonals are all the same. The matrix is guaranteed to be square (i.e., it has the same number of rows a...
def is_magic_square(matrix): """ Check if a given NxN matrix is a magic square. """ n = len(matrix) if n == 0: return "NO" magic_sum = sum(matrix[0]) # Check sums of each row for row in matrix: if sum(row) != magic_sum: return "NO" # Ch...
def test_is_magic_square(): assert is_magic_square([ [2, 7, 6], [9, 5, 1], [4, 3, 8] ]) == "YES" assert is_magic_square([ [1, 2, 3], [4, 5, 6], [7, 8, 9] ]) == "NO" assert is_magic_square([ [2, 7, 6], [9, 5, 1], [4, 3, 9] ...
[ { "docstring": "Check if a given NxN matrix is a magic square.", "function_declaration": "def is_magic_square(matrix):", "function_name": "is_magic_square", "parameter_list": "(matrix)" }, { "docstring": null, "function_declaration": "def read_input_and_check_magic_square():", "funct...
[ 0, 0, 1, 1, 0, 1, 1, 1, 1, 1 ]
7
easy
0.7
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_magic_square(matrix):\n n = len(matrix)\n \n # Calculate the target sum using the first row\n target_sum = sum(matrix[0])\n \n # Chec...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00004723", "row_id": 4723, "seed_ids": "[6536]" }
0.781081
Codeforces_4723
I
[ "is_magic_square", "read_input_and_check_magic_square" ]
2
[ [ "read_input_and_check_magic_square", "is_magic_square" ] ]
1
[]
false
[]
false
pytest
false
[]
true
b9e63e1586e6244316d6e55bcdc1122c08485736
14a96ce4b6b7c7916748206cdf7335be47ea1a1d
v1.0
instruct
Codeforces
Codeforces_4740_I
You are provided a tree (an acyclic connected graph) with $$$n$$$ nodes. Each node is labeled with a unique integer from $$$1$$$ to $$$n$$$. Each edge in the tree has a positive integer weight. You need to calculate the maximum sum of the weights on any simple path between two nodes in this tree. The first line of inp...
from collections import defaultdict def get_farthest_node(graph, start_node): visited = {start_node: 0} farthest_node = start_node farthest_distance = 0 stack = [(start_node, 0)] while stack: current_node, current_distance = stack.pop() if current_distance > farthest_distance: ...
from solution import max_path_sum def test_simple_path(): n = 3 edges = [(1, 2, 3), (2, 3, 4)] assert max_path_sum(n, edges) == 7 def test_balanced_tree(): n = 5 edges = [(1, 2, 1), (1, 3, 1), (2, 4, 1), (2, 5, 1)] assert max_path_sum(n, edges) == 3 def test_skewed_tree(): n = 4 edges...
[ { "docstring": null, "function_declaration": "def get_farthest_node(graph, start_node):", "function_name": "get_farthest_node", "parameter_list": "(graph, start_node)" }, { "docstring": null, "function_declaration": "def max_path_sum(n, edges):", "function_name": "max_path_sum", ...
[ 0, 0, 0, 0, 0, 1, 0, 0, 0, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def max_path_sum(n, edges):\n from collections import defaultdict, deque\n\n # Create adjacency list for the tree\n tree = defaultdict(list)\n for...
trial_gpt4o_5
{ "original_instruction": "", "prompt_id": "00004740", "row_id": 4740, "seed_ids": "[3483]" }
0.764522
Codeforces_4740
I
[ "get_farthest_node", "max_path_sum" ]
2
[ [ "max_path_sum", "get_farthest_node" ] ]
1
[]
false
[]
false
pytest
true
[]
true
4fea68315fa06d57034562c51d9afa30e50ba789
ae3b3c389ca6770aff0fbba8a7bd15911d7b2f10
v1.0
instruct
Codeforces
Codeforces_4751_I
Imagine you're working on a simple game involving a grid of size N x N. The game begins with each cell of the grid being empty, represented by a '.'. Players take turns to place their symbol ('X' or 'O') on the grid in one of the empty cells. The player who successfully places three of their symbols in a row horizontal...
def check_winner(grid, N): """ Checks for a winner in the grid. """ lines = [] # Rows and Columns for i in range(N): lines.append(grid[i]) # row lines.append([grid[j][i] for j in range(N)]) # column # Diagonals lines.append([grid[i][i] for i in range(N)]) # main diag...
from solution import game_result def test_game_result_X_wins(): N = 3 M = 6 moves = [ (1, 1, 'X'), (1, 2, 'O'), (2, 1, 'X'), (2, 2, 'O'), (3, 1, 'X'), (3, 2, 'O') ] assert game_result(N, M, moves) == "X wins" def test_game_result_O_wins(): N = 3 ...
[ { "docstring": "Checks for a winner in the grid.", "function_declaration": "def check_winner(grid, N):", "function_name": "check_winner", "parameter_list": "(grid, N)" }, { "docstring": "Simulates the game and returns the result.", "function_declaration": "def game_result(N, M, moves):",...
[ 1, 1, 1, 0, 1, 1, 0, 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 check_winner(grid, N):\n # Check rows and columns\n for i in range(N):\n if all(grid[i][j] == 'X' for j in range(N)) or all(grid[j][i] == 'X'...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00004751", "row_id": 4751, "seed_ids": "[2940]" }
0.748774
Codeforces_4751
I
[ "check_winner", "game_result" ]
2
[ [ "game_result", "check_winner" ] ]
1
[]
false
[]
false
pytest
true
[]
true
c1fd2f50415082d1c4142830a2a9ddc5f30ce735
82eff4b4ba2cd02b721b4a3b756d8bb4d388fabf
v1.0
instruct
Codeforces
Codeforces_4776_I
A company managing a network of servers has noticed that some tasks are failing due to overloaded servers. They want to optimize the way tasks are assigned to servers to ensure the load is balanced, thereby minimizing the chances of failure and maximizing efficiency. There are n servers and m tasks. Each server can ha...
def is_feasible(capacities, tasks, max_load): servers = len(capacities) remaining_capacity = sorted(capacities, reverse=True) task_index = 0 while task_index < len(tasks): allocated = False for i in range(servers): if remaining_capacity[i] >= tasks[task_index]: ...
def test_is_feasible(): capacities = [10, 10, 10] tasks = [5, 5, 5, 5] max_load = 10 assert is_feasible(capacities, tasks, max_load) == True capacities = [10, 10, 10] tasks = [10, 10, 10, 10] max_load = 10 assert is_feasible(capacities, tasks, max_load) == False def test_min_max_load()...
[ { "docstring": null, "function_declaration": "def is_feasible(capacities, tasks, max_load):", "function_name": "is_feasible", "parameter_list": "(capacities, tasks, max_load)" }, { "docstring": null, "function_declaration": "def min_max_load(n, m, capacities, tasks):", "function_name...
[ 0, 0, 0, 0, 0, 0, 1, 0, 0, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def can_distribute_tasks(servers, tasks, max_load):\n \"\"\"\n Helper function to determine if tasks can be distributed to servers\n such that no ser...
trial_gpt4o_6
{ "original_instruction": "", "prompt_id": "00004776", "row_id": 4776, "seed_ids": "[2605]" }
0.674927
Codeforces_4776
I
[ "is_feasible", "min_max_load", "solve" ]
3
[ [ "min_max_load", "is_feasible" ], [ "solve", "min_max_load" ] ]
2
[]
false
[]
false
pytest
false
[]
true
7e735773286fda90dda2d7fa734117e8015efaf6
dd4dcd3006bc87d970a350ea4dea8e7251113abd
v1.0
instruct
Codeforces
Codeforces_4816_I
In an ancient city, there is a square-shaped grid of size $$$n \times n$$$, where each cell can be either a building (**B**) or an empty plot (**E**). The city council plans to build a new road from the northwest corner (i.e., cell (1,1)) to the southeast corner (i.e., cell (n,n)) of the grid such that the road only pa...
def find_road(grid, n): def is_valid(x, y, visited): return 0 <= x < n and 0 <= y < n and grid[x][y] == 'E' and (x, y) not in visited def backtrack(x, y, path): if (x, y) == (n - 1, n - 1): return True directions = [(0, 1), (1, 0), (0, -1), (-1, 0)] for ...
def test_example_case(): n = 5 grid = [ "EEEEB", "BBBEE", "EEEEE", "BEEEE", "EBEEE" ] output = find_road(grid, n) assert output[0] == "Possible" def test_no_possible_path_case(): n = 4 grid = [ "EEEE", "BBBB", "EEEE", "...
[ { "docstring": null, "function_declaration": "def find_road(grid, n):", "function_name": "find_road", "parameter_list": "(grid, n)" }, { "docstring": null, "function_declaration": "def solve(n, grid):", "function_name": "solve", "parameter_list": "(n, grid)" }, { "docstri...
[ 0, 0, 0, 0, 0, 1, 0, 0, 0, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def dfs(city_grid, x, y, n, path, visited):\n if not (0 <= x < n and 0 <= y < n) or city_grid[x][y] == 'B' or visited[x][y]:\n return False\n pat...
trial_gpt4o_5
{ "original_instruction": "", "prompt_id": "00004816", "row_id": 4816, "seed_ids": "[7780]" }
0.718592
Codeforces_4816
I
[ "find_road", "solve" ]
2
[ [ "solve", "find_road" ] ]
1
[]
false
[]
false
pytest
false
[]
true
92130d2cf01cfd8efac9ede54892375977e82ab1
9086336b7f16b8d808f6c680733cedd3ff223ffd
v1.0
instruct
Codeforces
Codeforces_4965_I
You are given an integer array `arr` and an integer `k`, which represents the number of steps to rotate the array to the right. Write a function `rotateArray` to rotate the array in-place and return the modified array. ### Function Signature ```python def rotateArray(arr: List[int], k: int) -> List[int]: ``` ### Inpu...
from typing import List def rotateArray(arr: List[int], k: int) -> List[int]: """ Rotates the array `arr` in-place `k` steps to the right. """ n = len(arr) if n == 0: return arr # Ensure k is within the bounds of the array length k = k % n # Rotate the array in three s...
from solution import rotateArray def test_rotate_zero_steps(): assert rotateArray([1, 2, 3, 4, 5], 0) == [1, 2, 3, 4, 5] def test_rotate_small_array(): assert rotateArray([1], 3) == [1] def test_rotate_normal_case(): assert rotateArray([1, 2, 3, 4, 5], 2) == [4, 5, 1, 2, 3] def test_rotate_case_with_k_e...
[ { "docstring": "Rotates the array `arr` in-place `k` steps to the right.", "function_declaration": "def rotateArray(arr, k):", "function_name": "rotateArray", "parameter_list": "(arr, k)" }, { "docstring": null, "function_declaration": "def reverse(arr, start, end):", "function_name"...
[ 0, 1, 0, 0, 1, 1, 0, 1, 1, 1 ]
6
medium
0.6
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "from typing import List\n\ndef rotateArray(arr: List[int], k: int) -> List[int]:\n n = len(arr)\n if n == 0:\n return arr\n k = k % n # Handl...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00004965", "row_id": 4965, "seed_ids": "[2008]" }
0.669221
Codeforces_4965
I
[ "rotateArray", "reverse" ]
2
[ [ "rotateArray", "reverse" ] ]
1
[]
false
[]
false
pytest
true
[]
true
2a7dd8facc6ac29459ebdb8a9d783d62ea9f7ffd
0595423d04d89d0367c1014141db6039df25f67b
v1.0
instruct
Codeforces
Codeforces_5007_I
In an ancient kingdom, there are various castles that need to be connected by roads. The kingdom has `n` castles connected by `m` potential roads. Each road has a cost associated with its construction. The kingdom's goal is to build a network of roads such that any castle can be reached from any other castle (i.e., the...
def find(parent, i): if parent[i] == i: return i else: return find(parent, parent[i]) def union(parent, rank, x, y): root_x = find(parent, x) root_y = find(parent, y) if root_x != root_y: if rank[root_x] > rank[root_y]: parent[root_y] = root_x elif r...
from solution import minimum_cost_to_connect_all_castles def test_basic_example(): assert minimum_cost_to_connect_all_castles(4, 5, [(1, 2, 1), (2, 3, 4), (3, 4, 3), (4, 1, 2), (1, 3, 3)]) == 6 def test_no_possible_connection(): assert minimum_cost_to_connect_all_castles(4, 2, [(1, 2, 5), (3, 4, 10)]) == -1 ...
[ { "docstring": null, "function_declaration": "def find(parent, i):", "function_name": "find", "parameter_list": "(parent, i)" }, { "docstring": null, "function_declaration": "def union(parent, rank, x, y):", "function_name": "union", "parameter_list": "(parent, rank, x, y)" }, ...
[ 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": "def minimum_cost_to_connect_castles(n, m, roads):\n parent = list(range(n+1))\n \n def find(x):\n if parent[x] != x:\n parent[x] = ...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00005007", "row_id": 5007, "seed_ids": "[3]" }
0.684008
Codeforces_5007
I
[ "find", "union", "minimum_cost_to_connect_all_castles" ]
3
[ [ "minimum_cost_to_connect_all_castles", "find" ], [ "minimum_cost_to_connect_all_castles", "union" ], [ "union", "find" ] ]
3
[]
false
[]
false
pytest
true
[]
true
ef552f58d0768a2aa7101218bd328819761f782b
245f4c4db8959a16a66ea77a73698141ecac9324
v1.0
instruct
Codeforces
Codeforces_5050_I
A large company has a server system that stores several documents. Each document is represented by a unique number from 1 to n. The server receives multiple requests, and each request indicates a range of documents that need to be processed. You are required to write a program that will efficiently handle these reques...
def preprocess_accesses(access_counts): """ Preprocess the access counts to create a prefix sum array. """ n = len(access_counts) prefix_sum = [0] * (n + 1) for i in range(n): prefix_sum[i + 1] = prefix_sum[i] + access_counts[i] return prefix_sum def query_sum(prefix_sum, l, r): ...
from solution import preprocess_accesses, query_sum, process_document_accesses def test_preprocess_accesses(): access_counts = [3, 2, 1, 4, 5] prefix_sum = preprocess_accesses(access_counts) assert prefix_sum == [0, 3, 5, 6, 10, 15] def test_query_sum(): prefix_sum = [0, 3, 5, 6, 10, 15] assert qu...
[ { "docstring": "Preprocess the access counts to create a prefix sum array.", "function_declaration": "def preprocess_accesses(access_counts):", "function_name": "preprocess_accesses", "parameter_list": "(access_counts)" }, { "docstring": "Return the sum of accesses in the range [l, r].", ...
[ 1, 1, 1, 1, 1, 1, 0 ]
6
easy
0.857
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def process_requests(n, accesses, q, queries):\n \"\"\"\n n: int - number of documents\n accesses: List[int] - list of document accesses\n q: int ...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00005050", "row_id": 5050, "seed_ids": "[6604]" }
0.605121
Codeforces_5050
I
[ "preprocess_accesses", "query_sum", "process_document_accesses" ]
3
[ [ "process_document_accesses", "preprocess_accesses" ], [ "process_document_accesses", "query_sum" ] ]
2
[]
false
[]
false
pytest
true
[]
true
b6f51372075d5939dd20c23079f3bad357498263
d10c20e2e1bba17934bc575af1e6761a621f2551
v1.0
instruct
Codeforces
Codeforces_5066_I
You are given an encoded message consisting of digits. A letter can be encoded to digits in the range '1' to '26', mapped to the letters 'A' to 'Z', respectively (i.e., 'A' -> 1, 'B' -> 2, ..., 'Z' -> 26). The message can be decoded in multiple ways. Your task is to write a program to determine the number of distinct w...
def num_decodings(s: str) -> int: if not s or s[0] == '0': return 0 n = len(s) dp = [0] * (n + 1) dp[0] = 1 dp[1] = 1 for i in range(2, n + 1): if s[i - 1] != '0': dp[i] += dp[i - 1] if 10 <= int(s[i - 2:i]) <= 26: dp[i] += dp[i - 2] return ...
from solution import num_decodings_message def test_num_decodings_example(): assert num_decodings_message(5, "12321") == 6 def test_num_decodings_single_digit(): assert num_decodings_message(1, "1") == 1 assert num_decodings_message(1, "0") == 0 def test_num_decodings_with_zeroes(): assert num_decodi...
[ { "docstring": null, "function_declaration": "def num_decodings(s):", "function_name": "num_decodings", "parameter_list": "(s)" }, { "docstring": null, "function_declaration": "def num_decodings_message(n, s):", "function_name": "num_decodings_message", "parameter_list": "(n, s)"...
[ 0, 1, 1, 0, 0, 1, 1, 0, 0, 1 ]
5
medium
0.5
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def num_decodings(encoded_message):\n n = len(encoded_message)\n if n == 0 or encoded_message[0] == '0':\n return 0\n \n dp = [0] * (n + 1)...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00005066", "row_id": 5066, "seed_ids": "[153]" }
0.646422
Codeforces_5066
I
[ "num_decodings", "num_decodings_message" ]
2
[ [ "num_decodings_message", "num_decodings" ] ]
1
[]
false
[]
false
pytest
true
[]
true
47abaf93833d9e1cf02220f59fdcd270236a9ae8
4eb50592314b126a48e431a89c2cc3f41f7fe4e4
v1.0
instruct
Codeforces
Codeforces_5081_I
In a faraway land, there is a kingdom with n towns connected by m bidirectional roads. Each road has a certain length in kilometers. The king wants to build a special type of road system called a "circle road system," where you should be able to start at any town and travel back to the same town using a path that touch...
import sys def tsp(n, graph): dp = [[sys.maxsize] * (1 << n) for _ in range(n)] dp[0][1] = 0 for mask in range(1 << n): for u in range(n): if mask & (1 << u): for v in range(n): if not mask & (1 << v) and graph[u][v] != sys.maxsize: ...
def test_circle_road_system(): # Test case from the example n, m = 4, 6 roads = [ (1, 2, 10), (1, 3, 15), (1, 4, 20), (2, 3, 35), (2, 4, 25), (3, 4, 30) ] assert circle_road_system(n, m, roads) == 80 # Test case with no possible cycle n, m...
[ { "docstring": null, "function_declaration": "def tsp(n, graph):", "function_name": "tsp", "parameter_list": "(n, graph)" }, { "docstring": null, "function_declaration": "def circle_road_system(n, m, roads):", "function_name": "circle_road_system", "parameter_list": "(n, m, roads...
[ 1, 0, 0, 0, 1, 0, 0, 0, 1, 0 ]
3
hard
0.3
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "from itertools import permutations\n\ndef solve_circle_road_system(n, m, roads):\n if m < n:\n return -1\n \n def total_length(perm):\n ...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00005081", "row_id": 5081, "seed_ids": "[3633]" }
0.747245
Codeforces_5081
I
[ "tsp", "circle_road_system" ]
2
[ [ "circle_road_system", "tsp" ] ]
1
[]
false
[]
false
pytest
false
[]
true
f70304ad426036ce75b1aee4c4c2df6746431356
fecc5f586479e9ff63aa4d38d4eba6c1cee2ff0e
v1.0
instruct
Codeforces
Codeforces_5084_I
Consider a network of computers with n nodes (computers) and m edges (connections). Each connection between two computers has an associated cost (representing the cost to establish a direct communication between them). Your task is to find the minimum cost to connect all the computers in such a way that there is a dire...
def find(parent, x): if parent[x] != x: parent[x] = find(parent, parent[x]) return parent[x] def union(parent, rank, x, y): rootX = find(parent, x) rootY = find(parent, y) if rootX != rootY: if rank[rootX] > rank[rootY]: parent[rootY] = rootX elif rank[rootX] < r...
from solution import minimum_cost def test_minimum_cost_sample_1(): n = 4 m = 5 edges = [ (1, 2, 1), (1, 3, 2), (2, 3, 2), (2, 4, 3), (3, 4, 3) ] assert minimum_cost(n, m, edges) == 6 def test_minimum_cost_sample_2(): n = 3 m = 0 edges = [] a...
[ { "docstring": null, "function_declaration": "def find(parent, x):", "function_name": "find", "parameter_list": "(parent, x)" }, { "docstring": null, "function_declaration": "def union(parent, rank, x, y):", "function_name": "union", "parameter_list": "(parent, rank, x, y)" }, ...
[ 0, 0, 1, 0, 1, 0, 1, 0, 0, 1 ]
4
medium
0.4
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def find(parent, i):\n if parent[i] == i:\n return i\n else:\n return find(parent, parent[i])\n\ndef union(parent, rank, x, y):\n root_...
trial_gpt4o_4
{ "original_instruction": "", "prompt_id": "00005084", "row_id": 5084, "seed_ids": "[1309]" }
0.800715
Codeforces_5084
I
[ "find", "union", "kruskal", "minimum_cost" ]
4
[ [ "kruskal", "find" ], [ "kruskal", "union" ], [ "minimum_cost", "kruskal" ], [ "union", "find" ] ]
4
[]
false
[]
false
pytest
true
[]
true
6f76d4b035d2a84af38193bd2bb6759c02d4c5d4
b8633a4da013e9dde64a7b61416ce514dfd52536
v1.0
instruct
Codeforces
Codeforces_5096_I
You are given a string s with length n and q queries. The i-th query consists of an integer k which asks you to determine the lexicographically k-th substring of s. The first line contains two integers n, q (1 ≤ n ≤ 1000, 1 ≤ q ≤ 100) — the length of the string and the number of queries. The second line contains the ...
def generate_substrings(s): """ Generate all possible substrings of the given string s. """ n = len(s) substrings = set() for len_sub in range(1, n + 1): for start in range(n - len_sub + 1): substrings.add(s[start:start + len_sub]) return sorted(substrings) def find_kth_...
from solution import generate_substrings, find_kth_lexicographical_substring def test_generate_substrings(): s = "abc" expected_result = ['a', 'ab', 'abc', 'b', 'bc', 'c'] assert generate_substrings(s) == expected_result def test_find_kth_lexicographical_substring(): s = "abc" assert find_kth_lexi...
[ { "docstring": "Generate all possible substrings of the given string s.", "function_declaration": "def generate_substrings(s):", "function_name": "generate_substrings", "parameter_list": "(s)" }, { "docstring": "Find the k-th lexicographical substring of s.", "function_declaration": "def...
[ 0, 0, 1, 0, 0, 0, 0, 0, 0, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def kth_lexicographical_substring(n, q, s, queries):\n \"\"\"\n Returns k-th lexicographical substring of s for each query in queries.\n If no such s...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00005096", "row_id": 5096, "seed_ids": "[436]" }
0.835658
Codeforces_5096
I
[ "generate_substrings", "find_kth_lexicographical_substring" ]
2
[ [ "find_kth_lexicographical_substring", "generate_substrings" ] ]
1
[]
false
[]
false
pytest
true
[]
true
744d0e976dbdd1a186e63e2cf7a6614c44c8a154
75585854ee04f955bb2185662a4c9d92a39bf75e
v1.0
instruct
Codeforces
Codeforces_5114_I
A magical sequence is defined as a sequence of numbers where each number is obtained by summing the digits of the previous number and reversing the order of its digits. Given a seed number and an integer k, your task is to generate the k-th number in the magical sequence starting from the seed number. The first line c...
def sum_digits(n): """ Returns the sum of the digits of the number n. """ return sum(int(digit) for digit in str(n)) def reverse_number(n): """ Returns the number n with its digits reversed. """ return int(str(n)[::-1]) def magical_sequence(seed, k): """ Generates the k-th numb...
from solution import sum_digits, reverse_number, magical_sequence def test_sum_digits(): assert sum_digits(123) == 6 assert sum_digits(456) == 15 assert sum_digits(0) == 0 assert sum_digits(99999) == 45 def test_reverse_number(): assert reverse_number(123) == 321 assert reverse_number(456) == ...
[ { "docstring": "Returns the sum of the digits of the number n.", "function_declaration": "def sum_digits(n):", "function_name": "sum_digits", "parameter_list": "(n)" }, { "docstring": "Returns the number n with its digits reversed.", "function_declaration": "def reverse_number(n):", ...
[ 0, 0, 0, 0, 1, 0, 1, 0, 0, 0 ]
2
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "def magical_sequence(seed, k):\n \"\"\"\n Generates the k-th number in the magical sequence starting from the seed.\n \"\"\"\n def sum_of_digits(n...
trial_gpt4o_6
{ "original_instruction": "", "prompt_id": "00005114", "row_id": 5114, "seed_ids": "[3982]" }
0.56422
Codeforces_5114
I
[ "sum_digits", "reverse_number", "magical_sequence" ]
3
[ [ "magical_sequence", "reverse_number" ], [ "magical_sequence", "sum_digits" ] ]
2
[]
false
[]
false
pytest
true
[]
true
3929ee50ed8dc24b4cc7d02c52d9497dcb5c138f
b41d70c6dd8b07feab96da97387c1b2795457cf9
v1.0
instruct
Codeforces
Codeforces_5134_I
In a certain kingdom, there are $$$n$$$ towns connected by $$$n - 1$$$ two-way roads, forming a tree structure (i.e., all towns are reachable from any other town). The kingdom has decided to conduct automated deliveries between towns using drones. Each town has a few delivery hubs where drones are initially stationed. ...
from collections import deque, defaultdict def build_graph(n, roads): graph = defaultdict(list) for u, v in roads: graph[u].append(v) graph[v].append(u) return graph def bfs_distances(graph, start): # Perform BFS and calculate distances from the start node distances = {node: float(...
def test_case_1(): n = 5 roads = [(1, 2), (1, 3), (3, 4), (3, 5)] queries = [ (2, 2, [(1, 2), (3, 3)], [2, 4]), (1, 3, [(2, 1)], [1, 3, 5]) ] expected = [ [1, 1], [1, 0, 0] ] assert delivery_routes(n, roads, queries) == expected def test_case_2(): n = 3 ...
[ { "docstring": null, "function_declaration": "def build_graph(n, roads):", "function_name": "build_graph", "parameter_list": "(n, roads)" }, { "docstring": null, "function_declaration": "def bfs_distances(graph, start):", "function_name": "bfs_distances", "parameter_list": "(grap...
[ 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": "from collections import deque\n\ndef bfs(graph, start, limit):\n distances = {start: 0}\n queue = deque([start])\n while queue:\n node = queue...
trial_gpt4o_3
{ "original_instruction": "", "prompt_id": "00005134", "row_id": 5134, "seed_ids": "[4939]" }
0.713467
Codeforces_5134
I
[ "build_graph", "bfs_distances", "process_delivery_plans", "delivery_routes" ]
4
[ [ "delivery_routes", "process_delivery_plans" ], [ "process_delivery_plans", "bfs_distances" ], [ "process_delivery_plans", "build_graph" ] ]
3
[]
false
[]
false
pytest
false
[]
true
6e349d5d5b6bce28b9a96c114f79621e30ab2d60
56b68ce4377dc9496d9b0a69a76684d86f2f9c50
v1.0
instruct
Codeforces
Codeforces_5222_I
The city of Hexagonville is designed in a grid layout where each intersection is represented as a node in a graph. Each street between intersections is a weighted edge. The city planners want to optimize the placement of traffic signals to minimize the overall traffic congestion. Given a connected, undirected graph wi...
import heapq def find(parent, i): if parent[i] == i: return i else: parent[i] = find(parent, parent[i]) return parent[i] def union(parent, rank, x, y): xroot = find(parent, x) yroot = find(parent, y) if rank[xroot] < rank[yroot]: parent[xroot] = yroot elif rank...
from solution import min_cost_traffic_signals def test_case_1(): n = 4 m = 5 street_info = [ (1, 2, 1), (1, 3, 2), (1, 4, 3), (2, 3, 4), (3, 4, 5) ] result = min_cost_traffic_signals(n, m, street_info) assert result == 6 def test_case_2(): n = 3 ...
[ { "docstring": null, "function_declaration": "def find(parent, i):", "function_name": "find", "parameter_list": "(parent, i)" }, { "docstring": null, "function_declaration": "def union(parent, rank, x, y):", "function_name": "union", "parameter_list": "(parent, rank, x, y)" }, ...
[ 1, 0, 1, 1, 0, 0, 1, 1, 0, 1 ]
6
medium
0.6
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "import heapq\n\ndef find(parent, i):\n if parent[i] == i:\n return i\n return find(parent, parent[i])\n\ndef union(parent, rank, x, y):\n root...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00005222", "row_id": 5222, "seed_ids": "[543]" }
0.717632
Codeforces_5222
I
[ "find", "union", "kruskal", "min_cost_traffic_signals" ]
4
[ [ "kruskal", "find" ], [ "kruskal", "union" ], [ "min_cost_traffic_signals", "kruskal" ], [ "union", "find" ] ]
4
[]
false
[]
false
pytest
true
[]
true
dfe655eddccb82eff027148507ca44080cc9e88b
2c16e3222b78b72159dc74d4b4992e5d07d222a3
v1.0
instruct
Codeforces
Codeforces_5255_I
You are a chief architect designing a new city with a unique street layout. This city is built on a plane, using both vertical and horizontal streets similar to a grid. However, there is a special curved road, represented by the equation $$$y = k(x - h)^2 + m$$$. The curved road can be traveled like any other street. ...
import math import scipy.optimize def parabola_distance(h, k, m, x1, y1, x2, y2): def func_x1(x): return (k * (x - h)**2 + m - y1)**2 def func_x2(x): return (k * (x - h)**2 + m - y2)**2 # Finding the optimal point on the parabola for x1, y1 res_x1 = scipy.optimize.minimize_sca...
def test_parabola_distance(): # Test 1: Simple direct path assert abs(min_travel_distance(2, 1, 3, 1, 1, 5, 5) - 8) < 1e-6 # Test 2: Using the curved road assert abs(min_travel_distance(0, 1, 0, -1, 0, 1, 0) - 2) < 1e-6 # Test 3: Same points assert abs(min_travel_distance(2, 1, 3, 1, 1...
[ { "docstring": null, "function_declaration": "def parabola_distance(h, k, m, x1, y1, x2, y2):", "function_name": "parabola_distance", "parameter_list": "(h, k, m, x1, y1, x2, y2)" }, { "docstring": null, "function_declaration": "def min_travel_distance(h, k, m, x1, y1, x2, y2):", "fu...
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
1
hard
0.125
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "import math\nfrom scipy.optimize import minimize_scalar\n\ndef distance(p1, p2):\n \"\"\"\n Euclidean distance between points p1 and p2.\n \"\"\"\n ...
trial_gpt4o_4
{ "original_instruction": "", "prompt_id": "00005255", "row_id": 5255, "seed_ids": "[7594]" }
0.647466
Codeforces_5255
I
[ "parabola_distance", "min_travel_distance" ]
2
[ [ "min_travel_distance", "parabola_distance" ] ]
1
[]
false
[]
false
pytest
false
[ "scipy" ]
false
e9170f461486aaf3202f59acdb35178288a9982d
b07ff097705d63b263229e18ebde4abc2c9935dd
v1.0
instruct
Codeforces
Codeforces_5266_I
Given a network represented as an undirected graph with N nodes and M edges, each edge having a certain capacity. You need to find the maximum flow from node 1 to node N in this network using the Edmonds-Karp algorithm, an implementation of the Ford-Fulkerson method for computing the maximum flow in a flow network. Th...
from collections import deque def bfs_capacity_capacity(network, source, sink, parent): visited = [False] * len(network) queue = deque([source]) visited[source] = True while queue: u = queue.popleft() for v, capacity in enumerate(network[u]): if not visited[v] ...
from solution import max_flow def test_example_case(): N = 4 M = 5 edges = [ (1, 2, 100), (1, 3, 100), (2, 4, 100), (3, 4, 100), (2, 3, 1) ] assert max_flow(N, M, edges) == 200 def test_small_graph(): N = 2 M = 1 edges = [ (1, 2, 10) ...
[ { "docstring": null, "function_declaration": "def bfs_capacity_capacity(network, source, sink, parent):", "function_name": "bfs_capacity_capacity", "parameter_list": "(network, source, sink, parent)" }, { "docstring": null, "function_declaration": "def edmonds_karp(network, source, sink)...
[ 1, 0, 0, 0, 1, 0, 1, 0, 0, 0 ]
3
hard
0.3
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl", "solution_code": "from collections import defaultdict, deque\n\ndef bfs(C, F, source, sink, parent):\n \"\"\"Breadth-First Search to find path with available capacity.\"\"\"...
trial_gpt4o_6
{ "original_instruction": "", "prompt_id": "00005266", "row_id": 5266, "seed_ids": "[3239]" }
0.540327
Codeforces_5266
I
[ "bfs_capacity_capacity", "edmonds_karp", "max_flow" ]
3
[ [ "edmonds_karp", "bfs_capacity_capacity" ], [ "max_flow", "edmonds_karp" ] ]
2
[]
false
[]
false
pytest
true
[]
true
be1c57baf02cb17eaf6717a5c27112f4d1f52c63
fd5df7297dc0d27d77815c3ec2dc65635c1051a3