version
stringclasses
1 value
style
stringclasses
2 values
subset
stringclasses
12 values
question_id
stringlengths
9
23
question
stringlengths
27
8.13k
solution
stringlengths
99
5.97k
test
stringlengths
105
4.45k
test_info
listlengths
0
13
gpt_pass_sequence
listlengths
1
10
gpt_pass_trial_num
int64
1
10
gpt_difficulty
stringclasses
3 values
gpt_pass_percentage
float64
0.1
1
trials
dict
chosen_trial
stringclasses
10 values
metadata
dict
benchmark_similarity
float64
0.16
0.93
benchmark_instruction
stringclasses
1 value
benchmark_task_id
stringclasses
1 value
filter_reason
stringclasses
1 value
base_id
stringlengths
7
21
variant
stringclasses
2 values
top_function_names
listlengths
2
13
n_top_functions
int64
2
13
helper_call_edges
listlengths
1
16
n_helper_call_edges
int64
1
16
harness_functions
listlengths
0
3
structural_wrapper
bool
1 class
class_names
listlengths
0
5
has_class
bool
2 classes
test_kind
stringclasses
1 value
test_has_solution_import
bool
2 classes
third_party_imports
listlengths
0
5
stdlib_only
bool
2 classes
question_norm_sha1
stringlengths
40
40
solution_ast_sha1
stringlengths
40
40
v1.0
complete
Codeforces
Codeforces_25971_C
def min_append_to_palindrome(word): """ Returns the minimum number of characters that need to be appended to the end of the word to make it a palindrome. >>> min_append_to_palindrome("abc") 2 >>> min_append_to_palindrome("race") 3 >>> min_append_to_palindrome("madam") 0 """ ...
def min_append_to_palindrome(word): """ Returns the minimum number of characters that need to be appended to the end of the word to make it a palindrome. """ for i in range(len(word)): if word[i:] == word[i:][::-1]: return i return len(word) def process_words(n, words): ...
import pytest from solution import min_append_to_palindrome, process_words def test_min_append_to_palindrome(): assert min_append_to_palindrome("abc") == 2 assert min_append_to_palindrome("race") == 3 assert min_append_to_palindrome("madam") == 0 assert min_append_to_palindrome("ab") == 1 assert mi...
[ { "docstring": "Returns the minimum number of characters that need to be appended to the end\nof the word to make it a palindrome.", "function_declaration": "def min_append_to_palindrome(word):", "function_name": "min_append_to_palindrome", "parameter_list": "(word)" }, { "docstring": "Takes...
[ 0, 0, 0, 0, 0, 1, 0, 0, 0, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def min_chars_to_make_palindrome(word):\n \"\"\"\n Returns the minimum number of characters that need to be appended to the end of the word to make it a...
trial_gpt4o_5
{ "original_instruction": "You are given a collection of words composed of lowercase English letters. Each word is unique in this collection. Your task is to determine, for each word, the least number of characters you need to append to the end of it to make it a palindrome.\n\nA palindrome is a word that reads the s...
0.757775
Codeforces_25971
C
[ "min_append_to_palindrome", "process_words" ]
2
[ [ "process_words", "min_append_to_palindrome" ] ]
1
[]
false
[]
false
pytest
true
[]
true
2e852af294f56866e87525fcd1017a711b6313c2
aa0e32a0440a450fbaa528b0169fdf93b9a8e36c
v1.0
complete
Codeforces
Codeforces_26178_C
def max_crops(n: int, m: int): """ Returns the maximum number of different crops that can be planted in the field, and an arrangement of crops in the field. Args: n (int): Number of rows in the field. m (int): Number of columns in the field. Returns: tuple: A tuple containing the maxim...
def max_crops(n, m): """ Returns the maximum number of different crops that can be planted in the field, and an arrangement of crops in the field. """ crops = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" crop_arrangement = [] for i in range(n): row = [] for j in range(m): # The...
from solution import max_crops def test_max_crops_2x3(): max_crop_count, arrangement = max_crops(2, 3) assert max_crop_count == 2 assert len(arrangement) == 2 assert len(arrangement[0]) == 3 assert len(arrangement[1]) == 3 assert arrangement[0][0] != arrangement[0][1] assert arrangement[0][...
[ { "docstring": "Returns the maximum number of different crops that can be planted in the field,\nand an arrangement of crops in the field.", "function_declaration": "def max_crops(n, m):", "function_name": "max_crops", "parameter_list": "(n, m)" }, { "docstring": null, "function_declarat...
[ 0, 0, 0, 0, 0, 0, 0, 0, 1, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def max_crop_types(n, m):\n \"\"\"\n Returns the maximum number of different crop types that can be planted\n and the arrangement corresponding to th...
trial_gpt4o_8
{ "original_instruction": "A farmer wants to arrange his crops in a rectangular field with dimensions n × m. Each cell of the field can grow a certain type of crop and the farmer wants to maximize the variety of crops in the field. However, there is a restriction: No two adjacent cells (horizontally or vertically) sh...
0.542648
Codeforces_26178
C
[ "max_crops", "print_max_crops" ]
2
[ [ "print_max_crops", "max_crops" ] ]
1
[]
false
[]
false
pytest
true
[]
true
90426483cc3a23c6a45d77b091bbe2bc997e15f0
32c048e6e68fb0c507f0bf50d1ddeb4744efaf9d
v1.0
complete
Codeforces
Codeforces_26035_C
def min_repairs_from_input(input_string: str) -> int: """ Given the network topology as a list of direct connections, determine the minimum number of connections that need to be repaired to ensure that a virus can spread throughout the entire network. Args: input_string (str): The network top...
def find_min_repairs(n, m, connections): parent = list(range(n + 1)) def find(x): if parent[x] != x: parent[x] = find(parent[x]) return parent[x] def union(x, y): rootX = find(x) rootY = find(y) if rootX != rootY: parent[rootY] = rootX f...
def test_example_case(): input_string = "4 2\n1 2\n3 4\n" assert min_repairs_from_input(input_string) == 1 def test_single_node(): input_string = "1 0\n" assert min_repairs_from_input(input_string) == 0 def test_fully_connected(): input_string = "3 3\n1 2\n2 3\n1 3\n" assert min_repairs_from_i...
[ { "docstring": null, "function_declaration": "def find_min_repairs(n, m, connections):", "function_name": "find_min_repairs", "parameter_list": "(n, m, connections)" }, { "docstring": null, "function_declaration": "def min_repairs_from_input(input_string):", "function_name": "min_rep...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def find_min_repairs(n, connections):\n # Helper function to perform DFS and find connected components\n def dfs(node, visited, adj):\n visited[n...
trial_gpt4o_2
{ "original_instruction": "A network of computers is hit by a virus that exploits a bug in the system. The virus can spread from one computer to another if there is a direct connection between them. You are given the network's topology as a list of direct connections, but unfortunately, some connections have been des...
0.550103
Codeforces_26035
C
[ "find_min_repairs", "min_repairs_from_input" ]
2
[ [ "min_repairs_from_input", "find_min_repairs" ] ]
1
[]
false
[]
false
pytest
false
[]
true
8fbe66fd390da0c299afef3d2a50e996fadea2e9
a96110c4fce812703954cee693f19b2aa931d546
v1.0
complete
Codeforces
Codeforces_25990_C
from typing import List, Tuple class TreeNode: def __init__(self, val): self.val = val self.children = [] def build_tree(n: int, edges: List[Tuple[int, int]]) -> TreeNode: """ Build an adjacency list representation of the tree. """ nodes = {i: TreeNode(i) for i in range(1, n + 1)} ...
class TreeNode: def __init__(self, val): self.val = val self.children = [] def build_tree(n, edges): """ Build an adjacency list representation of the tree. """ nodes = {i: TreeNode(i) for i in range(1, n + 1)} for u, v in edges: nodes[u].children.append(nodes[v]) ...
import pytest from solution import find_longest_path def test_example(): n = 5 edges = [(1, 2), (1, 3), (3, 4), (3, 5)] assert find_longest_path(n, edges) == 2 def test_single_node(): n = 1 edges = [] assert find_longest_path(n, edges) == 0 def test_line_tree(): n = 4 edges = [(1, 2)...
[]
[ 0, 1, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "from collections import defaultdict, deque\n\ndef longest_path_in_binary_tree(n, edges):\n if n == 1:\n return 0\n \n graph = defaultdict(list...
trial_gpt4o_1
{ "original_instruction": "Given a binary tree, write a program to find the longest path from the root node to a leaf node. A path is defined as a sequence of nodes from the root to any leaf node, where each node in the sequence is connected by an edge.\n\nA root is a node with no parent, and a leaf is a node with no...
0.575219
Codeforces_25990
C
[ "build_tree", "longest_path", "find_longest_path" ]
3
[ [ "find_longest_path", "build_tree" ], [ "find_longest_path", "longest_path" ] ]
2
[]
false
[ "TreeNode" ]
true
pytest
true
[]
true
e2e3e7160fddd88ebda86935c6ebd414591fd778
1979dfb57269178db17c0b7f1bec11b0f6de7f1c
v1.0
complete
Codeforces
Codeforces_26298_C
def charity_auction(n: int, T: int, items: List[Tuple[int, int]]) -> int: """ Determine the minimum cost of achieving the target fund in a charity auction. Args: n (int): The number of items available for auction. T (int): The target fund to achieve. items (List[Tuple[int, int]]): A list of tup...
def minimum_cost_achieving_target(n, T, items): # Create a dp array where dp[i] represents the minimum cost to achieve at least value i dp = [float('inf')] * (T + 1) dp[0] = 0 for price, value in items: for i in range(T, value - 1, -1): dp[i] = min(dp[i], dp[i - value] + price) ...
from solution import charity_auction def test_example_case(): assert charity_auction(4, 10, [(4, 6), (2, 4), (7, 8), (5, 3)]) == 6 def test_single_item_exact(): assert charity_auction(1, 10, [(10, 10)]) == 10 def test_single_item_not_enough(): assert charity_auction(1, 11, [(10, 10)]) == -1 def test_mul...
[ { "docstring": null, "function_declaration": "def minimum_cost_achieving_target(n, T, items):", "function_name": "minimum_cost_achieving_target", "parameter_list": "(n, T, items)" }, { "docstring": null, "function_declaration": "def charity_auction(n, T, items):", "function_name": "c...
[ 0, 1, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def min_cost_to_achieve_target(n, T, items):\n \"\"\"\n Returns the minimum total price required to achieve at least the target fund or -1 if not possib...
trial_gpt4o_1
{ "original_instruction": "Alicia is organizing a charity auction and she needs to determine the minimum cost of achieving her target fund. She has a list of items, each with a given price and a value. Alicia can sell any subset of these items, and she wants to choose the subset that achieves at least her target fund...
0.569427
Codeforces_26298
C
[ "minimum_cost_achieving_target", "charity_auction" ]
2
[ [ "charity_auction", "minimum_cost_achieving_target" ] ]
1
[]
false
[]
false
pytest
true
[]
true
ec4031427285f7f226ca5b81949e924cedee34d3
6a778802881eb9550aff723df4a71e5ae94da58b
v1.0
complete
Codeforces
Codeforces_26207_C
def is_palindrome(n: int) -> bool: """ Check if the given number n is a palindrome. >>> is_palindrome(121) == True >>> is_palindrome(123) == False >>> is_palindrome(1) == True >>> is_palindrome(0) == True >>> is_palindrome(12321) == True """ def count_palindromes(L: int, R: int) -> int: ...
def is_palindrome(n): """ Check if the given number n is a palindrome. """ return str(n) == str(n)[::-1] def count_palindromes(L, R): """ Count the number of palindrome numbers between L and R, inclusive. """ count = 0 for i in range(L, R + 1): if is_palindrome(i): ...
from solution import is_palindrome, count_palindromes def test_is_palindrome(): assert is_palindrome(121) == True assert is_palindrome(123) == False assert is_palindrome(1) == True assert is_palindrome(0) == True assert is_palindrome(12321) == True def test_count_palindromes_small_range(): ass...
[ { "docstring": "Check if the given number n is a palindrome.", "function_declaration": "def is_palindrome(n):", "function_name": "is_palindrome", "parameter_list": "(n)" }, { "docstring": "Count the number of palindrome numbers between L and R, inclusive.", "function_declaration": "def c...
[ 0, 0, 0, 0, 0, 0, 0, 1, 0, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_palindrome(n):\n \"\"\"\n Checks if a number is a palindrome.\n \"\"\"\n return str(n) == str(n)[::-1]\n\ndef count_palindromes(L, R):\n ...
trial_gpt4o_7
{ "original_instruction": "Alex has recently started learning about palindrome numbers. A palindrome number is a number that remains the same when its digits are reversed. He is very curious to know how many palindrome numbers exist within a given range [L, R].\n\nGiven two integers L and R (1 ≤ L ≤ R ≤ 10^9), write ...
0.755398
Codeforces_26207
C
[ "is_palindrome", "count_palindromes" ]
2
[ [ "count_palindromes", "is_palindrome" ] ]
1
[]
false
[]
false
pytest
true
[]
true
67992907e400868c48e143e615c35162c90be543
9bd375b6f569ac32696a0ed49eb4cfc899bab09a
v1.0
complete
Codeforces
Codeforces_26231_C
from typing import List, Tuple def preprocess_prefix_sums(arr: List[int]) -> List[int]: """ Preprocess the array into a prefix sum array. >>> preprocess_prefix_sums([1, 2, 3, 4, 5]) == [0, 1, 3, 6, 10, 15] """ def sum_subarray(prefix_sums: List[int], l: int, r: int) -> int: """ Calculate t...
def preprocess_prefix_sums(arr): """ Preprocess the array into a prefix sum array. """ n = len(arr) prefix_sums = [0] * (n + 1) for i in range(1, n + 1): prefix_sums[i] = prefix_sums[i - 1] + arr[i - 1] return prefix_sums def sum_subarray(prefix_sums, l, r): """ Calculate th...
def test_preprocess_prefix_sums(): arr = [1, 2, 3, 4, 5] expected_prefix_sums = [0, 1, 3, 6, 10, 15] assert preprocess_prefix_sums(arr) == expected_prefix_sums def test_sum_subarray(): prefix_sums = [0, 1, 3, 6, 10, 15] assert sum_subarray(prefix_sums, 1, 3) == 6 assert sum_subarray(prefix_sums...
[ { "docstring": "Preprocess the array into a prefix sum array.", "function_declaration": "def preprocess_prefix_sums(arr):", "function_name": "preprocess_prefix_sums", "parameter_list": "(arr)" }, { "docstring": "Calculate the sum of the subarray using the prefix sums array.\nThe indices l an...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def preprocess_array(arr):\n \"\"\"\n Preprocess the array to create a prefix sum array.\n \"\"\"\n prefix_sum = [0] * (len(arr) + 1)\n for i i...
trial_gpt4o_2
{ "original_instruction": "In a land far away, there is a game played with an array of integers. The array can be split into subarrays and you perform specified operations to calculate the subarray sums. Let's define the problem more formally:\n\nYou are given an array of integers of length n. You are required to han...
0.61882
Codeforces_26231
C
[ "preprocess_prefix_sums", "sum_subarray", "process_queries" ]
3
[ [ "process_queries", "preprocess_prefix_sums" ], [ "process_queries", "sum_subarray" ] ]
2
[ "process_queries" ]
false
[]
false
pytest
false
[]
true
e0485d89ffd1c06648fdf1cb575a919f2856d71b
fb7f77efdafb8540c09381391ccb52e84f1beda3
v1.0
complete
Codeforces
Codeforces_26360_C
from typing import List, Tuple from collections import defaultdict def special_paths_sum(n: int, node_values: List[int], edges: List[Tuple[int, int]], queries: List[Tuple[int, int]]) -> List[int]: """ Calculate the minimum sum of node values on the special path between given pairs of nodes in a tree. Args: ...
from collections import defaultdict, deque def build_tree(edges, n): tree = defaultdict(list) for u, v in edges: tree[u].append(v) tree[v].append(u) return tree def calc_subtree_sums(tree, node_values, root): n = len(node_values) subtree_sums = [0] * (n + 1) visited = [False] *...
from solution import special_paths_sum def test_example(): n = 5 node_values = [1, 2, 3, 4, 5] edges = [(1, 2), (1, 3), (2, 4), (2, 5)] queries = [(1, 4), (1, 5), (3, 4)] expected = [7, 8, 10] result = special_paths_sum(n, node_values, edges, queries) assert result == expected def test_sin...
[ { "docstring": null, "function_declaration": "def build_tree(edges, n):", "function_name": "build_tree", "parameter_list": "(edges, n)" }, { "docstring": null, "function_declaration": "def calc_subtree_sums(tree, node_values, root):", "function_name": "calc_subtree_sums", "parame...
[ 0, 0, 0, 0, 1 ]
1
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "class TreeNode:\n def __init__(self, value):\n self.value = value\n self.children = []\n\ndef dfs(node, parent, values, subtree_sums, tree_no...
trial_gpt4o_4
{ "original_instruction": "Albert is playing with trees. A tree is a connected undirected graph with no cycles. He is particularly interested in certain properties of \"special paths\" in these trees. A special path between nodes u and v in a tree is defined as a path where the sum of the node values on the path is m...
0.645745
Codeforces_26360
C
[ "build_tree", "calc_subtree_sums", "find_special_path_sum", "special_paths_sum" ]
4
[ [ "special_paths_sum", "build_tree" ], [ "special_paths_sum", "calc_subtree_sums" ], [ "special_paths_sum", "find_special_path_sum" ] ]
3
[]
false
[]
false
pytest
true
[]
true
26036a3fd7452ccc58c23e31a816fb1627b93271
3d931cce0b5b799e4f5291b99b8855b68627f424
v1.0
complete
Codeforces
Codeforces_26358_C
def is_prime(num: int) -> bool: """ Checks if a number is prime. >>> is_prime(2) True >>> is_prime(3) True >>> is_prime(4) False >>> is_prime(5) True >>> is_prime(29) True >>> is_prime(25) False >>> is_prime(1) False >>> is_prime(0) False >>> i...
def is_prime(num): """ Checks if a number is prime. """ if num <= 1: return False if num == 2 or num == 3: return True if num % 2 == 0 or num % 3 == 0: return False i = 5 while i * i <= num: if num % i == 0 or num % (i + 2) == 0: return False ...
from solution import is_prime, next_prime def test_is_prime(): assert is_prime(2) == True assert is_prime(3) == True assert is_prime(4) == False assert is_prime(5) == True assert is_prime(29) == True assert is_prime(25) == False assert is_prime(1) == False assert is_prime(0) == False ...
[ { "docstring": "Checks if a number is prime.", "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": "Returns the smallest prime number greater than N.", "function_declaration": "def next_prime(N):", "function_name": "n...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(num):\n \"\"\"\n Checks if a number is prime.\n \"\"\"\n if num <= 1:\n return False\n if num == 2 or num == 3:\n re...
trial_gpt4o_0
{ "original_instruction": "Vasya is a curious boy and loves math puzzles. He recently learned about prime numbers and challenges you with the following task.\n\nGiven an integer \\( N \\), your task is to find the smallest prime number greater than \\( N \\). A prime number is a positive integer greater than 1 that h...
0.843118
Codeforces_26358
C
[ "is_prime", "next_prime" ]
2
[ [ "next_prime", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
d7f81213de57a10a0ec93b499dde274a40e1eb45
89f373bcde63220e423be8722e0f1143b503c2f5
v1.0
complete
Codeforces
Codeforces_26460_C
def next_palindrome(N: int) -> int: """ Find the next palindrome number larger than N. >>> next_palindrome(123) 131 >>> next_palindrome(999) 1001 >>> next_palindrome(1234) 1331 >>> next_palindrome(1) 2 >>> next_palindrome(11) 22 >>> next_palindrome(10**6 - 1) 1000001 >>> next_palindrome(...
def is_palindrome(num): return str(num) == str(num)[::-1] def next_palindrome(N): N += 1 while not is_palindrome(N): N += 1 return N
from solution import next_palindrome def test_next_palindrome(): assert next_palindrome(123) == 131 assert next_palindrome(1234) == 1331 assert next_palindrome(999) == 1001 assert next_palindrome(1) == 2 assert next_palindrome(11) == 22 def test_next_palindrome_edge_cases(): assert next_palind...
[ { "docstring": null, "function_declaration": "def is_palindrome(num):", "function_name": "is_palindrome", "parameter_list": "(num)" }, { "docstring": null, "function_declaration": "def next_palindrome(N):", "function_name": "next_palindrome", "parameter_list": "(N)" } ]
[ 1, 0, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_palindrome(num):\n \"\"\"\n Check if the given number is a palindrome.\n \"\"\"\n return str(num) == str(num)[::-1]\n\ndef next_palindrome(...
trial_gpt4o_2
{ "original_instruction": "Alice loves to play with numbers. Today she came across an interesting challenge about palindrome numbers and decided to test you with it.\n\nA palindrome number is a number that remains the same when its digits are reversed. For example, 121 and 1331 are palindromes while 123 and 1223 are ...
0.718976
Codeforces_26460
C
[ "is_palindrome", "next_palindrome" ]
2
[ [ "next_palindrome", "is_palindrome" ] ]
1
[]
false
[]
false
pytest
true
[]
true
d5486848a75d057df4b06c562d29e2c10b5a713b
515a9f37992d5048262b230a728afbef7b873d5f
v1.0
complete
Codeforces
Codeforces_26173_C
def lcm(a: int, b: int) -> int: """ Returns the least common multiple (LCM) of two integers a and b. >>> lcm(3, 5) 15 >>> lcm(4, 6) 12 """ def gcd(x: int, y: int) -> int: while y: x, y = y, x % y return x return abs(a * b) // gcd(a, b) def min_t...
def lcm(a, b): """ Returns the least common multiple (LCM) of two numbers a and b. """ def gcd(x, y): while y: x, y = y, x % y return x return abs(a * b) // gcd(a, b) def min_tshirts_order(S, L): """ Returns the minimum number of T-shirts that is divisible b...
def test_min_tshirts_order(): assert min_tshirts_order(3, 5) == 15, "Test case 1 failed" assert min_tshirts_order(4, 6) == 12, "Test case 2 failed" assert min_tshirts_order(1, 1) == 1, "Test case 3 failed" assert min_tshirts_order(6, 8) == 24, "Test case 4 failed" assert min_tshirts_order(7, 7) == 7...
[ { "docstring": "Returns the least common multiple (LCM) of two numbers a and b.", "function_declaration": "def lcm(a, b):", "function_name": "lcm", "parameter_list": "(a, b)" }, { "docstring": "Returns the minimum number of T-shirts that is divisible by both S and L.", "function_declarat...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def lcm(a, b):\n \"\"\"\n Returns the least common multiple of a and b.\n \"\"\"\n def gcd(x, y):\n while y:\n x, y = y, x % y\n...
trial_gpt4o_2
{ "original_instruction": "A corporation is planning to distribute company T-shirts to its employees. The corporation has arranged for a local printing shop to produce the T-shirts. However, due to a certain constraint, the printing shop can only produce T-shirts in two sizes: small (S) and large (L). Each order must...
0.660365
Codeforces_26173
C
[ "lcm", "min_tshirts_order" ]
2
[ [ "min_tshirts_order", "lcm" ] ]
1
[]
false
[]
false
pytest
false
[]
true
04a712d8225f9261e2d48dbfa6be3b456a705dfd
67d8f98b2a106d6df73cecb490283b8bef6ce843
v1.0
complete
Codeforces
Codeforces_26219_C
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_from_list(tree: List[int], index: int) -> TreeNode: """Construct the binary tree from the given list representation.""" ...
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_from_list(tree: List[int], index: int) -> TreeNode: if index >= len(tree) or tree[index] == -1: return None roo...
from solution import is_balanced_tree def test_balanced_tree(): # Balanced tree example tree = [1, 2, 3, 4, 5, 6, 7] assert is_balanced_tree(tree) == True def test_unbalanced_tree(): # Unbalanced tree example tree = [1, 2, 3, 4, 5, -1, -1, 6, -1, -1] assert is_balanced_tree(tree) == False def...
[]
[ 0, 0, 1 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "from typing import List, Tuple\n\nclass TreeNode:\n def __init__(self, x):\n self.val = x\n self.left = None\n self.right = None\n\nde...
trial_gpt4o_2
{ "original_instruction": "Maria is learning about binary trees and has come across the concept of a \"height-balanced\" binary tree. A binary tree is height-balanced if the difference in height between the left and right subtrees of every node is at most 1. She wants to write a function to determine if a given binar...
0.736555
Codeforces_26219
C
[ "build_tree_from_list", "check_balance_and_height", "is_balanced_tree" ]
3
[ [ "is_balanced_tree", "build_tree_from_list" ], [ "is_balanced_tree", "check_balance_and_height" ] ]
2
[]
false
[ "TreeNode" ]
true
pytest
true
[]
true
a92b24ac039c457d2b0fde307f96b957fdbefbb6
30ce4156aded1d1b44c5a6222f7cb9053f1b57f5
v1.0
complete
Codeforces
Codeforces_26374_C
import math from typing import List, Tuple def preprocess(arr: List[int], n: int) -> List[List[int]]: """ Preprocess the array to create the sparse table for range minimum query """ pass def query(sparse_table: List[List[int]], l: int, r: int) -> int: """ Query the sparse table to find the minimum in the ...
import sys import math def preprocess(arr, n): # Initialize sparse table for range minimum query log = math.ceil(math.log2(n)) sparse_table = [[0] * (log + 1) for _ in range(n)] # Initialize all minimum values for the intervals of length 1 for i in range(n): sparse_table[i][0] = arr[i]...
import pytest from solution import solve def test_example(): n, q = 5, 3 arr = [1, 2, 3, 4, 5] queries = [(1, 3), (2, 4), (1, 5)] expected_output = [1, 2, 1] assert solve(n, q, arr, queries) == expected_output def test_single_element(): n, q = 1, 1 arr = [42] queries = [(1, 1)] ex...
[ { "docstring": null, "function_declaration": "def preprocess(arr, n):", "function_name": "preprocess", "parameter_list": "(arr, n)" }, { "docstring": null, "function_declaration": "def query(sparse_table, l, r):", "function_name": "query", "parameter_list": "(sparse_table, l, r)"...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "import sys\nimport math\n\ndef preprocess(arr, n):\n # Initialize sparse table for range minimum query\n log = math.ceil(math.log2(n))\n sparse_table...
trial_gpt4o_0
{ "original_instruction": "Tom recently got a job at a renowned software company, and one of his tasks is to optimize memory usage of programs. He is working on a program that deals with an integer array, `arr`, of length `n`. He needs to answer `q` queries, each querying the smallest value in a subarray of `arr`.\n\...
0.608246
Codeforces_26374
C
[ "preprocess", "query", "solve" ]
3
[ [ "solve", "preprocess" ], [ "solve", "query" ] ]
2
[]
false
[]
false
pytest
true
[]
true
592e5c277c6b01abf91bc3b77ad6b3d3828fd32c
45315886de694cf21e4917c24e5d912658d136e0
v1.0
complete
Codeforces
Codeforces_26420_C
def max_min_distance(n: int, k: int, positions: List[int]) -> int: """ Determine the largest minimum distance possible between any two flowers if k flowers are planted at given positions in the garden. Args: n (int): The length of the array of positions. k (int): The number ...
def can_place_flowers(positions, k, min_distance): count = 1 # Place the first flower at the first position last_position = positions[0] for position in positions[1:]: if position - last_position >= min_distance: count += 1 last_position = position if c...
import pytest from solution import max_min_distance def test_example_case(): assert max_min_distance(5, 3, [1, 2, 8, 4, 9]) == 3 def test_small_case(): assert max_min_distance(2, 2, [1, 10]) == 9 def test_consecutive_positions(): assert max_min_distance(5, 3, [1, 2, 3, 4, 5]) == 2 def test_large_gap(): ...
[ { "docstring": null, "function_declaration": "def can_place_flowers(positions, k, min_distance):", "function_name": "can_place_flowers", "parameter_list": "(positions, k, min_distance)" }, { "docstring": null, "function_declaration": "def max_min_distance(n, k, positions):", "functio...
[ 0, 0, 0, 1, 0 ]
1
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def max_min_distance(n, k, positions):\n \"\"\"\n Returns the maximum minimum distance between any two flowers\n that can be planted at exactly k pos...
trial_gpt4o_3
{ "original_instruction": "Aria is a successful gardener with a large flower garden. She has a large section of the garden where she wants to plant flowers in a long straight line. To make the garden look beautiful, she decided to plant exactly k flowers and wants to maximize the minimum distance between any two adja...
0.592517
Codeforces_26420
C
[ "can_place_flowers", "max_min_distance" ]
2
[ [ "max_min_distance", "can_place_flowers" ] ]
1
[]
false
[]
false
pytest
true
[]
true
47045b4e80008b2885331d04337d7829fe710396
b94e46cbdec050dd7793a9b5364da4831e447e99
v1.0
complete
Codeforces
Codeforces_26065_C
def max_path_sum(grid): """ Hiroshi, an avid coder, has devised a game involving an NxM grid filled with numbers. Each cell of the grid contains a positive integer. The objective is to find a path from the top-left corner (cell (1,1)) to the bottom-right corner (cell (N,M)) such that the sum of the values on t...
def max_path_sum(grid): N = len(grid) M = len(grid[0]) # Create a 2D dp array to store the maximum sum up to each position dp = [[0]*M for _ in range(N)] # Initialize the top-left cell dp[0][0] = grid[0][0] # Initialize the first column for i in range(1, N): dp[i][...
from solution import max_path_sum, solve_max_path_sum def test_max_path_sum(): grid = [ [1, 2, 3], [4, 5, 6], [7, 8, 9] ] assert max_path_sum(grid) == 29 def test_solve_max_path_sum_example(): N = 3 M = 3 grid = [ [1, 2, 3], [4, 5, 6], [7, 8, 9] ...
[ { "docstring": null, "function_declaration": "def max_path_sum(grid):", "function_name": "max_path_sum", "parameter_list": "(grid)" }, { "docstring": null, "function_declaration": "def solve_max_path_sum(N, M, grid):", "function_name": "solve_max_path_sum", "parameter_list": "(N,...
[ 0, 0, 0, 0, 0, 0, 1, 0, 0, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def max_path_sum(grid):\n \"\"\"\n Returns the maximum sum of values on a path from the top-left corner to the bottom-right corner\n where one can on...
trial_gpt4o_6
{ "original_instruction": "Hiroshi, an avid coder, has devised a game involving an NxM grid filled with numbers. Each cell of the grid contains a positive integer. The objective is to find a path from the top-left corner (cell (1,1)) to the bottom-right corner (cell (N,M)) such that the sum of the values on the path ...
0.641491
Codeforces_26065
C
[ "max_path_sum", "solve_max_path_sum" ]
2
[ [ "solve_max_path_sum", "max_path_sum" ] ]
1
[]
false
[]
false
pytest
true
[]
true
ac9ef2e7bd4270551351160b245e17dc01e61837
92da9348a44255b3c7e1fe64d8f563595bf7f36b
v1.0
complete
Codeforces
Codeforces_26433_C
from typing import List def is_prime(num: int) -> bool: """ Check if a number is a prime. >>> is_prime(2) True >>> is_prime(4) False """ if num <= 1: return False for i in range(2, int(num ** 0.5) + 1): if num % i == 0: return False return True def can_p...
from itertools import combinations def is_prime(num): """ Check if a number is a prime. """ if num <= 1: return False for i in range(2, int(num ** 0.5) + 1): if num % i == 0: return False return True def can_partition_into_prime_sums(n, k, arr): """ Determin...
def test_can_partition_into_prime_sums(): assert can_partition_into_prime_sums(5, 3, [6, 5, 8, 12, 1]) == "NO" assert can_partition_into_prime_sums(3, 2, [5, 7, 6]) == "YES" assert can_partition_into_prime_sums(4, 2, [3, 11, 7, 2]) == "YES" assert can_partition_into_prime_sums(4, 2, [4, 6, 8, 9]) == "NO...
[ { "docstring": "Check if a number is a prime.", "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": "Determine if array can be partitioned into `k` non-empty subsets such that each subset sum is a prime number.", "functio...
[ 0, 0, 0, 0, 0, 1, 0, 0, 0, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(num):\n \"\"\" Returns True if num is a prime number, otherwise False. \"\"\"\n if num <= 1:\n return False\n if num == 2:\n ...
trial_gpt4o_5
{ "original_instruction": "You are given an array $$$a$$$ consisting of $$$n$$$ integers and an integer $$$k$$$. Your task is to determine whether it is possible to partition the array into exactly $$$k$$$ non-empty subsets such that the sum of each subset is a prime number.\n\nAn integer $$$p$$$ is considered a prim...
0.713309
Codeforces_26433
C
[ "is_prime", "can_partition_into_prime_sums" ]
2
[ [ "can_partition_into_prime_sums", "is_prime" ] ]
1
[]
false
[]
false
pytest
false
[]
true
70db246df845c04f0e7cd4ce0c720abfb20f9e35
53cc4e1528605ee3df378b9cbecfecbce7df5dda
v1.0
complete
Codeforces
Codeforces_26793_C
def max_min_difference(t: int, cases: List[Tuple[int, List[int]]]) -> List[int]: """ Given an integer array of size n, reorder the elements to maximize the minimum difference between adjacent elements and return the maximum possible value for each test case. >>> max_min_difference(3, [(4, [1, 2, 3, 4]), (5,...
def max_min_difference(t, cases): results = [] for case in cases: _, array = case array.sort() reordered = [] left = 0 right = len(array) - 1 while left <= right: if left == right: reordered.append(array[left]) ...
def test_max_min_difference(): cases = [ (4, [1, 2, 3, 4]), # Expected output: 1 (5, [10, 20, 30, 40, 50]), # Expected output: 10 (3, [5, 10, 5]), # Expected output: 5 ] expected_results = [1, 10, 5] assert max_min_difference(len(cases), cases) == expected_results def test_ma...
[ { "docstring": null, "function_declaration": "def max_min_difference(t, cases):", "function_name": "max_min_difference", "parameter_list": "(t, cases)" }, { "docstring": null, "function_declaration": "def solve():", "function_name": "solve", "parameter_list": "()" } ]
[ 0, 0, 0, 0, 1 ]
1
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def maximize_min_difference(t, cases):\n \"\"\"\n This function processes multiple test cases to reorder arrays such that the \n maximum possible val...
trial_gpt4o_4
{ "original_instruction": "Nina likes solving puzzles, and one of her favorite puzzles involves working with arrays. She has an array of integers and she likes rearranging its elements in specific ways to form new arrays. One of her preferences is to create arrays in which the difference between adjacent elements is ...
0.787045
Codeforces_26793
C
[ "max_min_difference", "solve" ]
2
[ [ "solve", "max_min_difference" ] ]
1
[]
false
[]
false
pytest
false
[]
true
258127196d9b82ee0dbb3d444ec1b89a3295a220
4c1dc60c5e5286cddf0a73cd9bb02bf017c712bc
v1.0
complete
Codeforces
Codeforces_26546_C
def find(parent, i): if parent[i] == i: return i return find(parent, parent[i]) def union(parent, rank, x, y): root_x = find(parent, x) root_y = find(parent, y) if root_x != root_y: if rank[root_x] > rank[root_y]: parent[root_y] = root_x elif rank[root_x] < ...
def find(parent, i): if parent[i] == i: return i return find(parent, parent[i]) def union(parent, rank, x, y): root_x = find(parent, x) root_y = find(parent, y) if root_x != root_y: if rank[root_x] > rank[root_y]: parent[root_y] = root_x elif rank[root_x] < ...
from solution import maximum_possible_minimal_road_toll def test_case_1(): n = 4 m = 5 edges = [ (0, 1, 4), (0, 2, 2), (1, 2, 1), (1, 3, 6), (2, 3, 3) ] assert maximum_possible_minimal_road_toll(n, m, edges) == 3 def test_case_2(): n = 3 m = 3 ed...
[ { "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 ]
1
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def find_maximal_minimal_road_toll(n, m, edges):\n import heapq\n\n parent = list(range(n + 1))\n \n def find(x):\n if parent[x] != x:\n ...
trial_gpt4o_3
{ "original_instruction": "You are given a weighted, connected, undirected graph with `n` vertices and `m` edges (1 ≤ n ≤ 50, 1 ≤ m ≤ 1250). Each vertex represents a city, and each edge represents a road with a certain toll. During the annual festival, the government wants to ensure that the maximum road toll between...
0.611797
Codeforces_26546
C
[ "find", "union", "kruskal", "maximum_possible_minimal_road_toll", "main" ]
5
[ [ "kruskal", "find" ], [ "kruskal", "union" ], [ "maximum_possible_minimal_road_toll", "kruskal" ], [ "union", "find" ] ]
4
[]
false
[]
false
pytest
true
[]
true
db4d21ee2c123ce8559fdc4b459702ffd50986c4
d73e56bf305f9896242193ebc60faae698648d52
v1.0
complete
Codeforces
Codeforces_26629_C
from typing import List, Tuple def calculate_highest_score(n: int, m: int, scores: List[List[int]]) -> Tuple[float, List[int]]: """ Calculate the highest overall score of dance pairs and their indices. Args: n (int): Number of dance pairs. m (int): Number of judges. scores (list of list of...
def calculate_highest_score(n, m, scores): """ Calculate the highest overall score of dance pairs and their indices. Args: n (int): Number of dance pairs. m (int): Number of judges. scores (list of list of int): Scores given to each pair by each judge. Returns: tuple: Highest o...
from solution import calculate_highest_score, find_winners def test_single_pair(): n = 1 m = 5 scores = [ [78, 82, 85, 88, 90] ] assert calculate_highest_score(n, m, scores) == (85.0, [1]) def test_multiple_pairs(): n = 3 m = 5 scores = [ [78, 82, 85, 88, 90], [...
[ { "docstring": "Calculate the highest overall score of dance pairs and their indices.\n\nArgs:\nn (int): Number of dance pairs.\nm (int): Number of judges.\nscores (list of list of int): Scores given to each pair by each judge.\n\nReturns:\ntuple: Highest overall score and a list of indices of pairs with the hi...
[ 0, 0, 0, 0, 0, 1, 0, 0, 0, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def find_winning_pairs(n, m, scores):\n \"\"\"\n Determine the highest overall score after removing the highest and lowest scores for each pair\n and...
trial_gpt4o_5
{ "original_instruction": "A dance competition is taking place and the judges need your help to determine the winners. There are `n` dance pairs competing, and each pair is evaluated by `m` judges. Each judge awards a score between 0 and 100 to each dance pair. To determine the overall score of a pair, the highest an...
0.659849
Codeforces_26629
C
[ "calculate_highest_score", "find_winners" ]
2
[ [ "find_winners", "calculate_highest_score" ] ]
1
[]
false
[]
false
pytest
true
[]
true
7e40c9817e57f19973bd7299617cf23d39daa815
f6d1bcb42b7e8967facc8ba9cfb12e53a37c16aa
v1.0
complete
Codeforces
Codeforces_26768_C
def find_optimal_village(n: int, roads: List[Tuple[int, int, int]]) -> int: """ Determine the optimal village to build the central warehouse such that the sum of distances from this warehouse to all other villages is minimized. Parameters: n (int): The number of villages. roads (List[Tu...
from collections import defaultdict import sys def find_centroid(n, edges): def dfs(node, parent): subtree_size[node] = 1 is_centroid = True for neighbor, weight in graph[node]: if neighbor != parent: dfs(neighbor, node) subtree_size[node] += sub...
from solution import find_optimal_village def test_example(): roads = [(1, 2, 3), (2, 3, 4), (3, 4, 2), (3, 5, 1)] assert find_optimal_village(5, roads) == 3 def test_single_edge(): roads = [(1, 2, 1)] assert find_optimal_village(2, roads) in [1, 2] def test_balanced_tree(): roads = [(1, 2, 1), (...
[ { "docstring": null, "function_declaration": "def find_centroid(n, edges):", "function_name": "find_centroid", "parameter_list": "(n, edges)" }, { "docstring": null, "function_declaration": "def find_optimal_village(n, road_list):", "function_name": "find_optimal_village", "param...
[ 0, 0, 1, 1 ]
2
medium
0.5
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "from collections import deque, defaultdict\n\ndef bfs(start, n, graph):\n distances = [-1] * (n + 1)\n queue = deque([start])\n distances[start] = 0\...
trial_gpt4o_4
{ "original_instruction": "In a certain kingdom, there are multiple villages connected by a network of roads. Villages are numbered from 1 to n. Each road connects exactly two villages and has a certain length associated with it. The king wants to build a single central warehouse in one of the villages such that the ...
0.587355
Codeforces_26768
C
[ "find_centroid", "find_optimal_village" ]
2
[ [ "find_optimal_village", "find_centroid" ] ]
1
[]
false
[]
false
pytest
true
[]
true
78e0b6488a35430304d95d2f65ac0850bbcde66a
829159708e33972ddb5a00b9fde0acb5b1cc2c5a
v1.0
complete
Codeforces
Codeforces_26539_C
from typing import List, Tuple def largest_scc(n: int, m: int, edges: List[Tuple[int, int]]) -> Tuple[int, List[int]]: """ Find the size and nodes of the largest Strongly Connected Component (SCC) in the network. :param n: number of servers :param m: number of communication channels :param edges:...
from collections import defaultdict, deque def kosaraju_scc(n, edges): def dfs(v): visited[v] = True for neighbour in graph[v]: if not visited[neighbour]: dfs(neighbour) order.append(v) def reverse_dfs(v, component): visited[v] = True compone...
from solution import largest_scc def test_case_1(): n = 6 m = 7 edges = [(1, 2), (2, 3), (3, 1), (3, 4), (4, 5), (5, 6), (6, 4)] size, scc = largest_scc(n, m, edges) assert size == 3 assert sorted(scc) in [sorted([1, 2, 3]), sorted([4, 5, 6])] def test_case_2(): n = 5 m = 5 edges =...
[ { "docstring": null, "function_declaration": "def kosaraju_scc(n, edges):", "function_name": "kosaraju_scc", "parameter_list": "(n, edges)" }, { "docstring": null, "function_declaration": "def largest_scc(n, m, edges):", "function_name": "largest_scc", "parameter_list": "(n, m, e...
[ 1, 0, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "from collections import defaultdict, deque\n\ndef kosaraju_scc(n, edges):\n def dfs(v):\n visited[v] = True\n for neighbour in graph[v]:\n ...
trial_gpt4o_0
{ "original_instruction": "In a post-apocalyptic world, communication between groups of survivors is crucial for their survival. They communicate via a network of old servers connected in a specific way. The network can be represented as a directed graph where nodes represent servers and edges represent one-way commu...
0.523892
Codeforces_26539
C
[ "kosaraju_scc", "largest_scc" ]
2
[ [ "largest_scc", "kosaraju_scc" ] ]
1
[]
false
[]
false
pytest
true
[]
true
260b35681ff95729ec93bb8a6790c18c1f252a58
dcc919fef10e0f01ec31d6cdd4e51473b246d977
v1.0
complete
Codeforces
Codeforces_27096_C
def ariel_palindrome(n: int, m: int, s: str, queries: List[Tuple[int, int]]) -> List[str]: """ Ariel is fascinated by palindromes. You are given a string `s` consisting of lowercase English letters and a list of `m` queries. Each query is composed of two integers `l` and `r` which define a substring of `s...
def is_palindrome(s, l, r): """ Returns whether the substring s[l:r+1] is a palindrome. """ sub_str = s[l:r+1] return sub_str == sub_str[::-1] def process_queries(n, m, s, queries): results = [] for l, r in queries: if is_palindrome(s, l, r): results.append("YES") ...
from solution import ariel_palindrome def test_ariel_palindrome(): n = 7 m = 3 s = "abacaba" queries = [(0, 6), (2, 4), (1, 2)] assert ariel_palindrome(n, m, s, queries) == ["YES", "YES", "NO"] n = 5 m = 2 s = "abcba" queries = [(0, 4), (1, 3)] assert ariel_palindrome(n, m, s, ...
[ { "docstring": "Returns whether the substring s[l:r+1] is a palindrome.", "function_declaration": "def is_palindrome(s, l, r):", "function_name": "is_palindrome", "parameter_list": "(s, l, r)" }, { "docstring": null, "function_declaration": "def process_queries(n, m, s, queries):", "...
[ 1, 0, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_palindrome(s, l, r):\n \"\"\"\n Check if the substring s[l:r+1] is a palindrome.\n \n :param s: The original string.\n :param l: The sta...
trial_gpt4o_2
{ "original_instruction": "Ariel is fascinated by palindromes, especially those that can be found in strings. Let's help Ariel with a problem involving checking palindromic properties of substrings.\n\nYou are given a string `s` consisting of lowercase English letters and a list of `m` queries. Each query is composed...
0.77604
Codeforces_27096
C
[ "is_palindrome", "process_queries", "ariel_palindrome" ]
3
[ [ "ariel_palindrome", "process_queries" ], [ "process_queries", "is_palindrome" ] ]
2
[ "process_queries" ]
false
[]
false
pytest
true
[]
true
9b2f30701bb3be1324a5754d65dc923ff44bb762
9a0464b26bf78e492b42b5db50a3f2f0db339ae6
v1.0
complete
Codeforces
Codeforces_26779_C
def solve_marathon_color_checkpoints(n: int, c: int, positions: List[int]) -> str: """ Determine if it is possible to color all checkpoint flags such that no two adjacent checkpoint flags have the same color, and if possible, output such a coloring scheme. >>> solve_marathon_color_checkpoints(5, 3, [1...
def color_checkpoints(n, c, positions): if c == 1 and n > 1: return "NO" colors = [0] * n for i in range(n): colors[i] = (i % c) + 1 return f"YES\n{' '.join(map(str, colors))}" def solve_marathon_color_checkpoints(n, c, positions): result = color_checkpoints(n, c, position...
from solution import solve_marathon_color_checkpoints def test_example1(): assert solve_marathon_color_checkpoints(5, 3, [1, 3, 7, 12, 18]) == "YES\n1 2 3 1 2" def test_example2(): assert solve_marathon_color_checkpoints(4, 2, [1, 2, 4, 8]) == "YES\n1 2 1 2" def test_not_possible_with_one_color(): assert...
[ { "docstring": null, "function_declaration": "def color_checkpoints(n, c, positions):", "function_name": "color_checkpoints", "parameter_list": "(n, c, positions)" }, { "docstring": null, "function_declaration": "def solve_marathon_color_checkpoints(n, c, positions):", "function_name...
[ 0, 1, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def can_color_checkpoints(n, c, positions):\n \"\"\"\n Determines if it is possible to color the checkpoints such that no two\n adjacent checkpoints ...
trial_gpt4o_1
{ "original_instruction": "Tom is organizing a marathon event in his city. He has a certain number of checkpoints in a straight-line track. Each checkpoint has a flag that needs to be colored. Tom has a set of colors and he wants to assign these colors to the flags in such a way that no two adjacent checkpoint flags ...
0.609015
Codeforces_26779
C
[ "color_checkpoints", "solve_marathon_color_checkpoints" ]
2
[ [ "solve_marathon_color_checkpoints", "color_checkpoints" ] ]
1
[]
false
[]
false
pytest
true
[]
true
9988516bfdbe78ec159fbce673532e3adef8aa70
daaa9077514fa72b1130494957e4bdba84f2946b
v1.0
complete
Codeforces
Codeforces_27267_C
def bfs_max_distance(n, graph, start): dist = [-1] * (n + 1) queue = deque([start]) dist[start] = 0 max_dist = 0 while queue: node = queue.popleft() for neighbor in graph[node]: if dist[neighbor] == -1: dist[neighbor] = dist[node] + 1 ...
from collections import deque def bfs_max_distance(n, graph, start): dist = [-1] * (n + 1) queue = deque([start]) dist[start] = 0 max_dist = 0 while queue: node = queue.popleft() for neighbor in graph[node]: if dist[neighbor] == -1: dist[neighbor] = ...
from solution import find_capital_city def test_example_case(): assert find_capital_city(5, [(1, 2), (1, 3), (2, 4), (2, 5)]) == 1 def test_single_city(): assert find_capital_city(1, []) == 1 def test_chain_structure_1(): assert find_capital_city(4, [(1, 2), (2, 3), (3, 4)]) == 2 def test_chain_structur...
[ { "docstring": null, "function_declaration": "def bfs_max_distance(n, graph, start):", "function_name": "bfs_max_distance", "parameter_list": "(n, graph, start)" }, { "docstring": null, "function_declaration": "def find_capital_city(n, roads):", "function_name": "find_capital_city", ...
[ 0, 0, 0, 1, 1 ]
2
medium
0.4
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "from collections import deque\n\ndef find_capital(n, roads):\n if n == 1:\n return 1\n \n graph = [[] for _ in range(n + 1)]\n for a, b in ...
trial_gpt4o_3
{ "original_instruction": "In a certain country, there is a unique way of determining the capital city every year. The country consists of $$n$$ cities, and the cities are connected by $$n-1$$ bidirectional roads in such a way that each city can be reached from any other city (i.e., they form a tree).\n\nEach year, t...
0.620757
Codeforces_27267
C
[ "bfs_max_distance", "find_capital_city" ]
2
[ [ "find_capital_city", "bfs_max_distance" ] ]
1
[]
false
[]
false
pytest
true
[]
true
ca174745f57c789265ab6d3580cafe8af812a77b
7183c9b5e434854b932f0fc2d39433ff3d605130
v1.0
complete
Codeforces
Codeforces_27188_C
from collections import defaultdict, deque from typing import List, Tuple def bfs_farthest_node(tree, start_node): visited = set() queue = deque([(start_node, 0)]) farthest_node, max_distance = start_node, 0 while queue: current_node, current_distance = queue.popleft() visited.add(...
from collections import defaultdict, deque def bfs_farthest_node(tree, start_node): visited = set() queue = deque([(start_node, 0)]) farthest_node, max_distance = start_node, 0 while queue: current_node, current_distance = queue.popleft() visited.add(current_node) ...
from solution import solution def test_single_case(): input_data = "1\n3\n1 2 3\n2 3 4\n" expected_output = "7" assert solution(input_data) == expected_output def test_multiple_cases(): input_data = "2\n3\n1 2 3\n2 3 4\n4\n1 2 1\n2 3 2\n3 4 3\n" expected_output = "7\n6" assert solution(input_d...
[ { "docstring": null, "function_declaration": "def bfs_farthest_node(tree, start_node):", "function_name": "bfs_farthest_node", "parameter_list": "(tree, start_node)" }, { "docstring": null, "function_declaration": "def largest_weighted_path(test_cases):", "function_name": "largest_we...
[ 0, 0, 0, 0, 1, 0, 0, 0, 0 ]
1
hard
0.111
{ "trial_gpt4o_0": null, "trial_gpt4o_1": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared1_results_combined.jsonl", "solution_code": "from collections import defaultdict, deque\n\ndef find_farthest_node(start_node, graph, n):\n # BFS to find the farthest node from...
trial_gpt4o_5
{ "original_instruction": "You are given a tree (i.e., a connected, undirected graph with no cycles) with `n` nodes and `n-1` edges. Each edge has an associated positive integer weight. Your task is to find the largest weighted path in the tree, where the weight of a path is defined as the sum of the weights of the e...
0.59046
Codeforces_27188
C
[ "bfs_farthest_node", "largest_weighted_path", "parse_input", "solution" ]
4
[ [ "largest_weighted_path", "bfs_farthest_node" ], [ "solution", "largest_weighted_path" ], [ "solution", "parse_input" ] ]
3
[ "parse_input" ]
false
[]
false
pytest
true
[]
true
601604266161b869d9eb778470bbea88d5a531f9
7501d05fdd47d2e1624385eae01080ce4af4dd88
v1.0
complete
Codeforces
Codeforces_27445_C
def minimum_cost_to_connect_all_cities(n: int, m: int, roads: List[Tuple[int, int, int]]) -> Union[int, str]: """ Calculate the minimum cost to connect all cities using the given roads. If it is possible to connect all cities, returns the minimum total length of the roads used. Otherwise, returns "impo...
def find(parent, i): if parent[i] == i: return i else: parent[i] = find(parent, parent[i]) # path compression 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]: ...
def test_minimum_cost_1(): n = 4 m = 5 roads = [ (1, 2, 5), (2, 3, 10), (3, 4, 3), (4, 1, 2), (1, 3, 12) ] assert minimum_cost_to_connect_all_cities(n, m, roads) == 10 def test_minimum_cost_2(): n = 4 m = 2 roads = [ (1, 2, 5), (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)" }, ...
[ 0, 0, 1 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def find(parent, i):\n if parent[i] == i:\n return i\n else:\n return find(parent, parent[i])\n\ndef union(parent, rank, x, y):\n xroot...
trial_gpt4o_2
{ "original_instruction": "In the kingdom of Logica, there are n cities connected by m bidirectional roads. Each road connects two different cities and has a certain length. The king wants to establish a postal service to ensure that all cities are connected and the total length of the roads used is minimized. In oth...
0.701031
Codeforces_27445
C
[ "find", "union", "kruskal", "minimum_cost_to_connect_all_cities" ]
4
[ [ "kruskal", "find" ], [ "kruskal", "union" ], [ "minimum_cost_to_connect_all_cities", "kruskal" ], [ "union", "find" ] ]
4
[]
false
[]
false
pytest
false
[]
true
764fe0e16d24c7ce11de6f38286ea5d8b59bb9d3
4e8dd80c20b488e4878ed791c0e1f2b62d9998e8
v1.0
complete
Codeforces
Codeforces_27436_C
def road_policy(n: int, m: int, roads: List[Tuple[int, int, int]]) -> Union[str, Tuple[str, int]]: """ Determine if the current network of roads satisfies the policy criteria. If not, determine the minimal number of roads that should be added or removed to ensure that all cities are connected directly or i...
def find(parent, i): if parent[i] == i: return i return find(parent, parent[i]) def union(parent, rank, x, y): root_x = find(parent, x) root_y = find(parent, y) if root_x != root_y: if rank[root_x] > rank[root_y]: parent[root_y] = root_x elif rank[root_x] < ...
def test_road_policy(): # Test case 1 - Already connected and meets policy n = 4 m = 3 roads = [(1, 2, 3), (2, 3, 4), (3, 4, 5)] assert road_policy(n, m, roads) == "YES" # Test case 2 - Not all cities connected, minimal roads needed n = 4 m = 2 roads = [(1, 2, 3), (3, 4, 4)] ...
[ { "docstring": null, "function_declaration": "def find(parent, i):", "function_name": "find", "parameter_list": "(parent, i)" }, { "docstring": null, "function_declaration": "def union(parent, rank, x, y):", "function_name": "union", "parameter_list": "(parent, rank, x, y)" }, ...
[ 0, 0, 0, 0, 0, 0, 0, 0, 1, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def can_travel_all_cities(n, m, roads):\n from collections import defaultdict\n import sys\n sys.setrecursionlimit(10000)\n \n # Create an adja...
trial_gpt4o_8
{ "original_instruction": "In a kingdom, there are n cities connected by m bidirectional roads. Each road has a certain length in kilometers. The kingdom has just established a new policy to promote travel between cities more effectively. The policy states that every two cities should have at most one direct road con...
0.747907
Codeforces_27436
C
[ "find", "union", "road_policy" ]
3
[ [ "road_policy", "find" ], [ "road_policy", "union" ], [ "union", "find" ] ]
3
[]
false
[]
false
pytest
false
[]
true
b59971af0ee174707004baddc801ca6b0a300cb5
f00b0b8f74fc535129e2c99a6ca10c92a967e26e
v1.0
complete
Codeforces
Codeforces_27438_C
from typing import List, Tuple from collections import defaultdict, deque def minimum_colors_needed(n: int, paths: List[Tuple[int, int]]) -> int: """ Given the number of trees and the edges connecting them, find the minimum number of colors needed to highlight the paths from the town square to the farthest tre...
from collections import defaultdict, deque def find_farthest_node(n, edges, start): # Perform BFS to find farthest node from the start node queue = deque([(start, 0)]) visited = [False] * (n + 1) visited[start] = True farthest_node = start max_distance = 0 while queue: current,...
from solution import minimum_colors_needed def test_example_case(): n = 6 paths = [(1, 2), (1, 3), (3, 4), (3, 5), (4, 6)] assert minimum_colors_needed(n, paths) == 2 def test_small_case(): n = 2 paths = [(1, 2)] assert minimum_colors_needed(n, paths) == 1 def test_line_graph(): n = 5 ...
[ { "docstring": null, "function_declaration": "def find_farthest_node(n, edges, start):", "function_name": "find_farthest_node", "parameter_list": "(n, edges, start)" }, { "docstring": null, "function_declaration": "def minimum_colors_needed(n, paths):", "function_name": "minimum_colo...
[ 1, 1, 0 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "from collections import defaultdict, deque\n\ndef find_farthest_node(n, edges, start):\n # Perform BFS to find farthest node from the start node\n queue...
trial_gpt4o_0
{ "original_instruction": "In the land of Treeland, there are $$$n$$$ trees forming a connected acyclic graph. Each tree is unique and labeled with an integer from 1 to n. Each tree is directly connected to one or more other trees by an undirected path.\n\nThe tradition in Treeland is to celebrate in the town square,...
0.571933
Codeforces_27438
C
[ "find_farthest_node", "minimum_colors_needed" ]
2
[ [ "minimum_colors_needed", "find_farthest_node" ] ]
1
[]
false
[]
false
pytest
true
[]
true
0c5bcf635e2de9bfb0885edb9f4e0ab863ea4491
dfe87eecf138e846261c3824128a7a5cf1bc06e8
v1.0
complete
Codeforces
Codeforces_27741_C
def minimum_spanning_tree(n: int, m: int, edges: List[Tuple[int, int, int]]) -> int: """ Determine the cost of the minimum spanning tree (MST) of a given undirected graph. If it's impossible to form an MST (i.e., the graph isn't connected), return -1. >>> minimum_spanning_tree(4, 5, [(1, 2, 1), (1, 3, ...
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 minimum_spanning_tree def test_example_1(): n = 4 m = 5 edges = [ (1, 2, 1), (1, 3, 1), (1, 4, 1), (2, 3, 1), (3, 4, 1) ] assert minimum_spanning_tree(n, m, edges) == 3 def test_example_2(): n = 4 m = 2 edges = [ (1, ...
[ { "docstring": null, "function_declaration": "def find(parent, i):", "function_name": "find", "parameter_list": "(parent, i)" }, { "docstring": null, "function_declaration": "def union(parent, rank, x, y):", "function_name": "union", "parameter_list": "(parent, rank, x, y)" }, ...
[ 0, 1, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_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_1
{ "original_instruction": "You're given an undirected graph with $$$n$$$ nodes and $$$m$$$ edges. Your task is to determine the cost of the minimum spanning tree (MST) of this graph. If it's impossible to form an MST (i.e., the graph isn't connected), return -1.\n\nThe MST is a subset of the edges that connects all t...
0.803193
Codeforces_27741
C
[ "find", "union", "kruskal_mst", "minimum_spanning_tree" ]
4
[ [ "kruskal_mst", "find" ], [ "kruskal_mst", "union" ], [ "minimum_spanning_tree", "kruskal_mst" ], [ "union", "find" ] ]
4
[]
false
[]
false
pytest
true
[]
true
b6245c34c2e36d8ecfa494d521e18504e4e5181b
ccf1caa57848a67535b1adeef00c1c06072de2ba
v1.0
complete
Codeforces
Codeforces_27717_C
from typing import List def is_prime(n: int) -> bool: """ Check if a number is a prime. >>> is_prime(2) True >>> is_prime(3) True >>> is_prime(4) False >>> is_prime(5) True >>> is_prime(1) False >>> is_prime(0) False """ def count_special_pairs(arr: List[int...
def is_prime(n): if n <= 1: return False if n <= 3: return True if n % 2 == 0 or n % 3 == 0: return False i = 5 while (i * i) <= n: if n % i == 0 or n % (i + 2) == 0: return False i += 6 return True def count_special_pairs(arr): count = 0 ...
from solution import is_prime, count_special_pairs def test_is_prime(): assert is_prime(2) == True assert is_prime(3) == True assert is_prime(4) == False assert is_prime(5) == True assert is_prime(1) == False assert is_prime(0) == False def test_count_special_pairs_example1(): arr = [2, 3,...
[ { "docstring": null, "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": null, "function_declaration": "def count_special_pairs(arr):", "function_name": "count_special_pairs", "parameter_list": "(arr)" } ]
[ 0, 1, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(n):\n if n <= 1:\n return False\n if n <= 3:\n return True\n if n % 2 == 0 or n % 3 == 0:\n return False\n i = 5...
trial_gpt4o_1
{ "original_instruction": "You are given an array of n integers a1, a2, ..., an. A pair of indices (i, j) (1 ≤ i < j ≤ n) is called special if it satisfies all of the following conditions:\n\n1. a[i] < a[j]\n2. a[i] is a prime number\n\nYou need to find the number of such special pairs in the array.\n\nThe first line...
0.698442
Codeforces_27717
C
[ "is_prime", "count_special_pairs" ]
2
[ [ "count_special_pairs", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
73d03205684205510e5fd24d93394946c8974481
e0915b098549397d3a66fda52b62899c7317d31b
v1.0
complete
Codeforces
Codeforces_28003_C
def sieve_of_eratosthenes(max_num): """ Generates a list of prime numbers up to max_num using the Sieve of Eratosthenes algorithm. """ # implementation here def find_prime_pair(n): """ Finds and returns a pair of prime numbers that sum up to n. """ # implementation here def main(n): ...
def sieve_of_eratosthenes(max_num): """ Generates a list of prime numbers up to max_num using the Sieve of Eratosthenes algorithm. """ is_prime = [True] * (max_num + 1) is_prime[0] = is_prime[1] = False # 0 and 1 are not prime numbers for start in range(2, int(max_num**0.5) + 1): i...
from solution import main def test_example_case(): pair = main(10) assert pair in [(3, 7), (7, 3)] def test_small_even_number(): pair = main(4) assert pair == (2, 2) def test_medium_even_number(): pair = main(28) assert pair in [(5, 23), (23, 5), (11, 17), (17, 11)] def test_large_even_numbe...
[ { "docstring": "Generates a list of prime numbers up to max_num using the Sieve of Eratosthenes algorithm.", "function_declaration": "def sieve_of_eratosthenes(max_num):", "function_name": "sieve_of_eratosthenes", "parameter_list": "(max_num)" }, { "docstring": "Finds and returns a pair of p...
[ 1, 0, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def sieve_of_eratosthenes(max_num):\n \"\"\"\n Generates a list of prime numbers up to max_num using the Sieve of Eratosthenes algorithm.\n \"\"\"\n ...
trial_gpt4o_0
{ "original_instruction": "Monica loves prime numbers and has recently learned about the Goldbach Conjecture. According to the conjecture, every even number greater than 2 can be expressed as the sum of two prime numbers.\n\nAs practice, Monica wants to write a program that, given an even number, finds two prime numb...
0.641552
Codeforces_28003
C
[ "sieve_of_eratosthenes", "find_prime_pair", "main" ]
3
[ [ "find_prime_pair", "sieve_of_eratosthenes" ] ]
1
[]
false
[]
false
pytest
true
[]
true
865cf25abc400a0061479df131d48ebdb958dd0c
d50676651afc64a4d0c01e2b793e20b222e7a340
v1.0
complete
Codeforces
Codeforces_27745_C
def largest_black_rect(grid: List[List[int]]) -> int: """Find the area of the largest rectangular sub-grid consisting only of black cells. :param grid: A list of lists of integers representing the grid (0 for white cell, 1 for black cell). :return: An integer representing the area of the largest sub-grid wi...
def largest_black_rect(grid): if not grid: return 0 n = len(grid) m = len(grid[0]) # Initialize a histogram array based on the same number of columns hist = [0] * m max_area = 0 # Update histogram for each row and calculate the maximal rectangle for i in range(n): ...
from solution import largest_black_rect def test_single_cell_black(): grid = [[1]] assert largest_black_rect(grid) == 1 def test_single_cell_white(): grid = [[0]] assert largest_black_rect(grid) == 0 def test_all_black(): grid = [ [1, 1], [1, 1] ] assert largest_black_rect...
[ { "docstring": null, "function_declaration": "def largest_black_rect(grid):", "function_name": "largest_black_rect", "parameter_list": "(grid)" }, { "docstring": null, "function_declaration": "def max_histogram_area(hist):", "function_name": "max_histogram_area", "parameter_list"...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def largest_rectangle_area(heights):\n \"\"\"\n Helper function to calculate the largest rectangle area in a histogram.\n :param heights: List[int]\n...
trial_gpt4o_2
{ "original_instruction": "A famous artist is creating a new type of artwork using a rectangular grid of colored cells. Each cell can be either black or white. The grid is represented by a matrix of 0s and 1s, where 0 denotes a white cell and 1 denotes a black cell. The artist wants to find the largest rectangular su...
0.625029
Codeforces_27745
C
[ "largest_black_rect", "max_histogram_area" ]
2
[ [ "largest_black_rect", "max_histogram_area" ] ]
1
[]
false
[]
false
pytest
true
[]
true
fe1fd8330ca7fef2c2366ef80b3c6c3bec241962
96f0f9f774239618e6b8f3b4f5a541bc9a5d14b9
v1.0
complete
Codeforces
Codeforces_27937_C
from typing import List def is_prime(n: int) -> bool: """Check if a number is prime. >>> is_prime(2) True >>> is_prime(3) True >>> is_prime(4) False >>> is_prime(17) True >>> is_prime(18) False >>> is_prime(19) True >>> is_prime(20) False """ ...
def is_prime(n): """Check if a number is prime.""" if n <= 1: return False if n <= 3: return True if n % 2 == 0 or n % 3 == 0: return False i = 5 while i * i <= n: if n % i == 0 or n % (i + 2) == 0: return False i += 6 return True def sum_...
from solution import is_prime, sum_of_primes def test_is_prime(): assert is_prime(2) == True assert is_prime(3) == True assert is_prime(4) == False assert is_prime(17) == True assert is_prime(18) == False assert is_prime(19) == True assert is_prime(20) == False def test_sum_of_primes(): ...
[ { "docstring": "Check if a number is prime.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Return the sum of all prime numbers in the range [l, r].", "function_declaration": "def sum_of_primes(l, r):", "function_n...
[ 1, 0, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(n):\n \"\"\"Check if a number is prime.\"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return True\n if n % 2 == 0 or...
trial_gpt4o_0
{ "original_instruction": "Alyona loves playing with numbers. She has recently learned about prime numbers and now she is very keen on them. For her, a positive integer x is prime if it has no positive integer divisors other than 1 and itself. She starts to wonder about the sums of these prime numbers. Given two inte...
0.794028
Codeforces_27937
C
[ "is_prime", "sum_of_primes" ]
2
[ [ "sum_of_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
7ca1b7318e24dd0bae69d3323ec1b5c47a4232f6
0a623bd4fd2161fd0acd7096d1bc4089caf51ef4
v1.0
complete
Codeforces
Codeforces_27849_C
def min_steps(input_str: str) -> int: """ You are given a grid with R rows and C columns. Each cell of the grid can either be passable ('.') or blocked ('#'). Your task is to determine the minimum number of steps required to reach from the top-left corner of the grid to the bottom-right corner. You can move up, dow...
from collections import deque def min_steps_to_reach_end(grid): R = len(grid) C = len(grid[0]) if grid[0][0] == '#' or grid[R-1][C-1] == '#': return -1 queue = deque([(0, 0, 0)]) # (row, col, distance) visited = [[False]*C for _ in range(R)] visited[0][0] = True directions = [(-1...
from solution import min_steps def test_example_1(): input_str = "5 5\n.....\n.#...\n#.#..\n.....\n...#." assert min_steps(input_str) == 8 def test_example_2(): input_str = "3 3\n.#.\n#.#\n.#." assert min_steps(input_str) == -1 def test_blocked_start(): input_str = "3 3\n###\n#.#\n.#." assert...
[ { "docstring": null, "function_declaration": "def min_steps_to_reach_end(grid):", "function_name": "min_steps_to_reach_end", "parameter_list": "(grid)" }, { "docstring": null, "function_declaration": "def parse_input(input_str):", "function_name": "parse_input", "parameter_list":...
[ 1, 0, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "from collections import deque\n\ndef min_steps_to_reach_end(grid):\n R = len(grid)\n C = len(grid[0])\n if grid[0][0] == '#' or grid[R-1][C-1] == '#'...
trial_gpt4o_0
{ "original_instruction": "You are given a grid with R rows and C columns. Each cell of the grid can either be passable ('.') or blocked ('#'). Your task is to determine the minimum number of steps required to reach from the top-left corner of the grid to the bottom-right corner. You can move up, down, left, or right...
0.678388
Codeforces_27849
C
[ "min_steps_to_reach_end", "parse_input", "min_steps" ]
3
[ [ "min_steps", "min_steps_to_reach_end" ], [ "min_steps", "parse_input" ] ]
2
[ "parse_input" ]
false
[]
false
pytest
true
[]
true
ce8cf36fdd1feff2d708369cee0d3afe1dd4991a
a6664037a23a980a4307bdb964909f74f3384020
v1.0
complete
Codeforces
Codeforces_27942_C
def min_max_travel_time(n: int, roads: List[Tuple[int, int, int]]) -> int: """ Find the most optimal town to be the new capital by calculating the minimum possible value of the maximum travel time to the farthest town. >>> min_max_travel_time(4, [(1, 2, 5), (2, 3, 10), (3, 4, 5), (1, 4, 20)]) 15 >>...
import heapq def dijkstra(n, graph, start): dist = [float('inf')] * (n + 1) dist[start] = 0 heap = [(0, start)] while heap: current_dist, u = heapq.heappop(heap) if current_dist > dist[u]: continue for v, length in graph[u]: distance = current_dist + leng...
from solution import min_max_travel_time def test_example(): n, m = 4, 4 roads = [(1, 2, 5), (2, 3, 10), (3, 4, 5), (1, 4, 20)] assert min_max_travel_time(n, roads) == 15 def test_two_towns(): n, m = 2, 1 roads = [(1, 2, 1)] assert min_max_travel_time(n, roads) == 1 def test_disconnected_grap...
[ { "docstring": null, "function_declaration": "def dijkstra(n, graph, start):", "function_name": "dijkstra", "parameter_list": "(n, graph, start)" }, { "docstring": null, "function_declaration": "def min_max_travel_time(n, roads):", "function_name": "min_max_travel_time", "paramet...
[ 0, 0, 1 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def find_new_capital(n, m, roads):\n inf = float('inf')\n distance = [[inf] * n for _ in range(n)]\n \n for i in range(n):\n distance[i][i]...
trial_gpt4o_2
{ "original_instruction": "In an ancient kingdom, there are n towns connected by m bidirectional roads. Each road has a certain time delay to travel between the two towns it connects. The king wants to establish a new capital in one of the towns. He wants to choose a town such that the maximum travel time from this c...
0.693013
Codeforces_27942
C
[ "dijkstra", "min_max_travel_time" ]
2
[ [ "min_max_travel_time", "dijkstra" ] ]
1
[]
false
[]
false
pytest
true
[]
true
3fac4728058a358e6019785f6b806f056046dfe4
3953b5ee93cfd78230100b17c4bbcd882729b789
v1.0
complete
Codeforces
Codeforces_27899_C
def max_energy_transport(m: int, n: int, demands: List[int], edges: List[Tuple[int, int, int]]) -> int: """ Determine the maximum amount of energy that can be transported from suppliers to consumers while respecting the capacity constraints of the transmission lines. >>> max_energy_transport(4, 4, [-5, 5, -5, 5...
from collections import defaultdict, deque def bfs_capacity(graph, capacity, source, sink, parent): visited = set() queue = deque([source]) visited.add(source) while queue: u = queue.popleft() for v in graph[u]: if v not in visited and capacity[u][v] > 0: ...
from solution import max_energy_transport def test_case_1(): m, n = 4, 4 demands = [-5, 5, -5, 5] edges = [(0, 1, 5), (1, 2, 5), (2, 3, 5), (0, 3, 5)] assert max_energy_transport(m, n, demands, edges) == 10 def test_case_2(): m, n = 4, 5 demands = [-10, 10, -10, 10] edges = [(0, 1, 15), (...
[ { "docstring": null, "function_declaration": "def bfs_capacity(graph, capacity, source, sink, parent):", "function_name": "bfs_capacity", "parameter_list": "(graph, capacity, source, sink, parent)" }, { "docstring": null, "function_declaration": "def edmonds_karp(graph, capacity, source,...
[ 0, 0, 0, 0, 1 ]
1
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "import networkx as nx\n\ndef max_energy_transport(m, n, demands, transmission_lines):\n \"\"\"\n Determines the maximum amount of energy that can be tra...
trial_gpt4o_4
{ "original_instruction": "You are working on a task to optimize energy distribution in a rising smart city. The city has m power stations connected by n bi-directional transmission lines, each with a specific capacity. Each power station may supply or consume energy, resulting in a net demand (positive for consumpti...
0.579705
Codeforces_27899
C
[ "bfs_capacity", "edmonds_karp", "max_energy_transport" ]
3
[ [ "edmonds_karp", "bfs_capacity" ], [ "max_energy_transport", "edmonds_karp" ] ]
2
[]
false
[]
false
pytest
true
[]
true
efb76bebf5c7086b571ddcf9df0708de8a12f41b
37046f951febc87d35f54a2637519c6676ae5d28
v1.0
complete
Codeforces
Codeforces_27680_C
def longest_word_in_grid(n: int, m: int, grid: List[List[str]], d: int, dictionary: List[str]) -> int: """ Sherlock Holmes needs to find the longest word that can be formed by moving through adjacent cells in a character grid. :param n: Number of rows in the grid :param m: Number of columns in the grid ...
def find_longest_word_path(grid, dictionary): n = len(grid) m = len(grid[0]) # Set of words for quick lookup word_set = set(dictionary) # Set of all prefix to quickly check if a prefix exists in dictionary prefix_set = {word[:i] for word in dictionary for i in range(1, len(word) + 1)} ...
from solution import longest_word_in_grid def test_find_longest_word_single_word(): n = 3 m = 4 grid = [ ['a', '.', 't', '.'], ['h', 'e', 'l', 'p'], ['.', 'e', '.', 'r'] ] d = 4 dictionary = ["help", "ale", "her", "tap"] assert longest_word_in_grid(n, m, grid, d, dic...
[ { "docstring": null, "function_declaration": "def find_longest_word_path(grid, dictionary):", "function_name": "find_longest_word_path", "parameter_list": "(grid, dictionary)" }, { "docstring": null, "function_declaration": "def longest_word_in_grid(n, m, grid, d, dictionary):", "fun...
[ 0, 0, 1 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def longest_path_in_grid(n, m, grid, d, dictionary):\n from collections import defaultdict\n \n def dfs(x, y, node, visited, path_length):\n i...
trial_gpt4o_2
{ "original_instruction": "Sherlock Holmes is working on a new case involving a secret message that is hidden within a grid. The message is encoded using a grid of characters, where each cell contains a single lowercase letter ('a' to 'z') and some cells are empty ('.'). To decode the message, Sherlock needs to ident...
0.669238
Codeforces_27680
C
[ "find_longest_word_path", "longest_word_in_grid" ]
2
[ [ "longest_word_in_grid", "find_longest_word_path" ] ]
1
[]
false
[]
false
pytest
true
[]
true
11dde81b3ddba33a87e89775d11ea44d83a188aa
7c6c1af2feac5ac998245f93c8f714656173ef59
v1.0
complete
Codeforces
Codeforces_27778_C
def largest_rectangle_area(heights): """ Helper function to compute the largest rectangle area in a histogram. Args: heights (List[int]): A list of integer heights in the histogram. Returns: int: The area of the largest rectangle. """ # Implementation needed here def maximal_rectangle...
def largest_rectangle_area(heights): stack = [] max_area = 0 index = 0 while index < len(heights): if not stack or heights[stack[-1]] <= heights[index]: stack.append(index) index += 1 else: top_of_stack = stack.pop() area = (heights[to...
from solution import main def test_example_case(): input_data = "4 5\n1 0 1 0 0\n1 0 1 1 1\n1 1 1 1 1\n1 0 0 1 0\n" assert main(input_data) == 6 def test_single_element_1(): input_data = "1 1\n1\n" assert main(input_data) == 1 def test_single_element_0(): input_data = "1 1\n0\n" # The questio...
[ { "docstring": null, "function_declaration": "def largest_rectangle_area(heights):", "function_name": "largest_rectangle_area", "parameter_list": "(heights)" }, { "docstring": null, "function_declaration": "def maximal_rectangle(matrix):", "function_name": "maximal_rectangle", "p...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def maximalRectangle(matrix):\n if not matrix:\n return 0\n\n n = len(matrix)\n m = len(matrix[0])\n height = [0] * (m + 1)\n max_area =...
trial_gpt4o_2
{ "original_instruction": "You are given a matrix with `n` rows and `m` columns. Each cell in the matrix contains either a '1' or a '0'. You need to process the matrix to locate the largest submatrix that consists entirely of '1's, then output the area of this largest submatrix.\n\nIt is guaranteed that the matrix co...
0.668433
Codeforces_27778
C
[ "largest_rectangle_area", "maximal_rectangle", "main" ]
3
[ [ "maximal_rectangle", "largest_rectangle_area" ] ]
1
[]
false
[]
false
pytest
true
[]
true
8a3eac4e37fc22419f60c2c2bbe4a177c1670a0f
8fb6c71afa19360e6cf058c4d7bf8d85d2da5404
v1.0
complete
Codeforces
Codeforces_28105_C
def find_maximal_rectangle(matrix: List[List[int]]) -> int: """ Compute the area of the largest rectangle that can be formed from the given boolean matrix. >>> find_maximal_rectangle([[1, 0, 1, 0, 0], [1, 0, 1, 1, 1], [1, 1, 1, 1, 1], [1, 0, 0, 1, 0]]) == 6 >>> find_maximal_rectangle([[0]]) == 0 >>> fin...
def maximalRectangle(matrix): if not matrix or not matrix[0]: return 0 m, n = len(matrix), len(matrix[0]) heights = [0] * n max_area = 0 for i in range(m): for j in range(n): if matrix[i][j] == 1: heights[j] += 1 else: ...
import pytest from solution import find_maximal_rectangle def test_maximal_rectangle(): assert find_maximal_rectangle([[1, 0, 1, 0, 0], [1, 0, 1, 1, 1], [1, 1, 1, 1, 1], [1, 0, 0, 1, 0]]) == 6 assert find_maximal_rectangle([[0]]) == 0 assert find_maximal_rectangle([[1]]) == 1 assert find_maximal_rectan...
[ { "docstring": null, "function_declaration": "def maximalRectangle(matrix):", "function_name": "maximalRectangle", "parameter_list": "(matrix)" }, { "docstring": null, "function_declaration": "def largestRectangleArea(heights):", "function_name": "largestRectangleArea", "paramete...
[ 0, 1 ]
1
medium
0.5
{ "trial_gpt4o_0": null, "trial_gpt4o_1": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared1_results_combined.jsonl", "solution_code": "def max_histogram_area(histogram):\n \"\"\"\n Helper function to find the maximum area of a histogram.\n \"\"\"\n stack =...
trial_gpt4o_2
{ "original_instruction": "You have just bought a new plot of land and you want to build a rectangular flower garden. You have a certain number of flower seedlings, and each seedling will cover exactly one unit plot of land. Your goal is to maximize the area of the flower garden.\n\nHowever, you have some constraints...
0.772368
Codeforces_28105
C
[ "maximalRectangle", "largestRectangleArea", "find_maximal_rectangle" ]
3
[ [ "find_maximal_rectangle", "maximalRectangle" ], [ "maximalRectangle", "largestRectangleArea" ] ]
2
[]
false
[]
false
pytest
true
[]
true
6311cd0eb2917811da8db9c296752d8c160e0739
432530ab6fb55cdd5dec8e09e145d03674cd963b
v1.0
complete
Codeforces
Codeforces_28455_C
def validate_parentheses_sequences(t: int, sequences: List[str]) -> List[str]: """ Validate t number of parentheses sequences. >>> validate_parentheses_sequences(3, ["()", "()[]{}", "(]"]) ["YES", "YES", "NO"] >>> validate_parentheses_sequences(1, ["{[()]}"]) ["YES"] >>> validate_parentheses_s...
def is_valid_parentheses(s): """ Returns True if the input string s containing only parentheses '(', ')', '{', '}', '[' and ']' is valid. """ stack = [] mapping = {")": "(", "}": "{", "]": "["} for char in s: if char in mapping: top_element = stack.pop() if stack else '#' ...
from solution import validate_parentheses_sequences def test_parentheses_sequences(): assert validate_parentheses_sequences(3, ["()", "()[]{}", "(]"]) == ["YES", "YES", "NO"] assert validate_parentheses_sequences(1, ["{[()]}"]) == ["YES"] assert validate_parentheses_sequences(2, ["{[()]}{", "{[()]"]) == ["...
[ { "docstring": "Returns True if the input string s containing only parentheses '(', ')', '{', '}', '[' and ']' is valid.", "function_declaration": "def is_valid_parentheses(s):", "function_name": "is_valid_parentheses", "parameter_list": "(s)" }, { "docstring": "Validate t number of parenthe...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_valid_brackets(s):\n \"\"\"\n Determines if the input string containing only parentheses '(', ')', '{', '}', '[' and ']' is valid.\n \n Ret...
trial_gpt4o_2
{ "original_instruction": "Given a string containing only parentheses '(', ')', '{', '}', '[' and ']', determine if the input string is valid. \n\nAn input string is valid if:\n1. Open brackets must be closed by the same type of brackets.\n2. Open brackets must be closed in the correct order.\n\nThe input string shou...
0.780048
Codeforces_28455
C
[ "is_valid_parentheses", "validate_parentheses_sequences" ]
2
[ [ "validate_parentheses_sequences", "is_valid_parentheses" ] ]
1
[]
false
[]
false
pytest
true
[]
true
5b49b0ede11fb6a37aa6f059978ed73ff180fe07
c32a223fb1fae7699c0c76657e87ef17746a20d3
v1.0
complete
Codeforces
Codeforces_28244_C
def is_prime(num): """ Determine if the provided number is a prime number. """ pass def longest_prime_subsequence(arr): """ Calculate the length of the longest contiguous subsequence of prime numbers in the array. >>> longest_prime_subsequence([1, 2, 3, 4, 5, 6, 7]) == 2 >>> longest_pr...
def is_prime(num): """ Determine if the provided number is a prime number. """ 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: ret...
from solution import is_prime, longest_prime_subsequence def test_is_prime(): assert is_prime(2) assert is_prime(3) assert not is_prime(4) assert is_prime(5) assert not is_prime(1) assert not is_prime(0) def test_longest_prime_subsequence(): assert longest_prime_subsequence([1, 2, 3, 4, 5,...
[ { "docstring": "Determine if the provided number is a prime number.", "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": "Calculate the length of the longest contiguous subsequence of prime numbers in the array.", "funct...
[ 1 ]
1
easy
1
{ "trial_gpt4o_0": null, "trial_gpt4o_1": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared1_results_combined.jsonl", "solution_code": "def is_prime(num):\n \"\"\"\n Determine if the provided number is a prime number.\n \"\"\"\n if num <= 1:\n return...
trial_gpt4o_1
{ "original_instruction": "Hermione is working on a spell digitizer machine, which converts a stream of magical energy into digital signals. The machine operates in a peculiar way: it only works effectively on subsequences that satisfy a specific condition related to prime numbers. The condition is that the digital v...
0.766978
Codeforces_28244
C
[ "is_prime", "longest_prime_subsequence" ]
2
[ [ "longest_prime_subsequence", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
d7e8dbd99c08d28f7ad5160f55888866dd3f8031
d311bd3d949dcf1cf95048fdf6c5aa754f537a9a
v1.0
complete
Codeforces
Codeforces_28119_C
def sieve_of_eratosthenes(max_num): """ Helper function to find all prime numbers up to max_num using the Sieve of Eratosthenes algorithm. """ is_prime = [True] * (max_num + 1) is_prime[0] = is_prime[1] = False # 0 and 1 are not prime numbers p = 2 while (p * p <= max_num): if is_pr...
def sieve_of_eratosthenes(max_num): is_prime = [True] * (max_num + 1) is_prime[0] = is_prime[1] = False # 0 and 1 are not prime numbers p = 2 while (p * p <= max_num): if is_prime[p]: for i in range(p * p, max_num + 1, p): is_prime[i] = False p += 1 retur...
def test_max_prime_gap_example1(): assert max_prime_gap(10, 30) == 6 def test_max_prime_gap_example2(): assert max_prime_gap(20, 22) == -1 def test_max_prime_gap_no_primes(): assert max_prime_gap(14, 16) == -1 def test_max_prime_gap_single_prime(): assert max_prime_gap(13, 13) == -1 def test_max_pri...
[ { "docstring": null, "function_declaration": "def sieve_of_eratosthenes(max_num):", "function_name": "sieve_of_eratosthenes", "parameter_list": "(max_num)" }, { "docstring": "Finds the maximum gap between successive prime numbers in the range [L, R].\nIf there are no prime numbers or only on...
[ 0, 0, 1 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def max_prime_gap(L, R):\n \"\"\"\n Returns the maximum gap between successive prime numbers in the range [L, R].\n If there are no prime numbers or ...
trial_gpt4o_2
{ "original_instruction": "Little Maya has recently started learning about prime numbers and their properties. She is particularly fascinated by the concept of prime gaps, which are the differences between successive prime numbers. Maya decided to explore the maximum gap between consecutive prime numbers within a giv...
0.625943
Codeforces_28119
C
[ "sieve_of_eratosthenes", "max_prime_gap" ]
2
[ [ "max_prime_gap", "sieve_of_eratosthenes" ] ]
1
[]
false
[]
false
pytest
false
[]
true
5151307e73ab23813814eb0450050d8df1571e80
0f9ed00c7f6a02c8ced0af107675ace0f73f015b
v1.0
complete
Codeforces
Codeforces_28477_C
def longest_contiguous_subsequence(n: int, stones: List[int]) -> int: """ Find the length of the longest contiguous subsequence of stones where the types of stones are in a strictly increasing order followed by a strictly decreasing order. >>> longest_contiguous_subsequence(7, [1, 2, 3, 4, 3, 2, 1]) 7 >...
def longest_subsequence(n, stones): if n < 3: return 0 max_len = 0 i = 0 while i < n - 1: if stones[i] < stones[i + 1]: start = i while i < n - 1 and stones[i] < stones[i + 1]: i += 1 peak = i if i < n - 1 and stones[i] > ...
from solution import longest_contiguous_subsequence def test_example_1(): assert longest_contiguous_subsequence(7, [1, 2, 3, 4, 3, 2, 1]) == 7 def test_example_2(): assert longest_contiguous_subsequence(5, [1, 5, 3, 2, 1]) == 5 def test_example_3(): assert longest_contiguous_subsequence(4, [1, 2, 3, 4]) ...
[ { "docstring": null, "function_declaration": "def longest_subsequence(n, stones):", "function_name": "longest_subsequence", "parameter_list": "(n, stones)" }, { "docstring": null, "function_declaration": "def longest_contiguous_subsequence(n, stones):", "function_name": "longest_cont...
[ 1, 0, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def longest_subsequence(n, stones):\n if n < 3:\n return 0\n\n max_len = 0\n i = 0\n\n while i < n - 1:\n if stones[i] < stones[i + ...
trial_gpt4o_0
{ "original_instruction": "Arya and Bran are playing a game with stones. Arya, as usual, has a bunch of stones, while Bran loves patterns. One evening, Arya decided to challenge Bran by asking him to find the longest contiguous subsequence of stones that forms a particular pattern.\n\nYou are given a sequence of inte...
0.726062
Codeforces_28477
C
[ "longest_subsequence", "longest_contiguous_subsequence" ]
2
[ [ "longest_contiguous_subsequence", "longest_subsequence" ] ]
1
[]
false
[]
false
pytest
true
[]
true
78a32116b54687f5e2d40126593991ccdb494bca
97e6ec1bebbb7b424997d35e2542fee565705842
v1.0
complete
Codeforces
Codeforces_28081_C
def maximum_spanning_tree(n, edges): """ Function to find the weight of the maximum spanning tree of a weighted undirected graph. Args: n (int): the number of vertices. edges (List[Tuple[int, int, int]]): the list of edges where each edge is represented by a tuple (u, v, w). Returns: int: ...
def find(parent, i): """ Function to find the representative member of the set to which i belongs. """ if parent[i] == i: return i return find(parent, parent[i]) def union(parent, rank, x, y): """ Function to perform union of two sets x and y using rank. """ xroot = find(par...
from solution import maximum_spanning_tree def test_single_edge(): assert maximum_spanning_tree(2, [(1, 2, 10)]) == 10 def test_multiple_edges(): assert maximum_spanning_tree(3, [(1, 2, 1), (2, 3, 2), (3, 1, 3)]) == 5 assert maximum_spanning_tree(4, [(1, 2, 1), (2, 3, 2), (3, 1, 3), (3, 4, 4)]) == 9 def ...
[ { "docstring": "Function to find the representative member of the set to which i belongs.", "function_declaration": "def find(parent, i):", "function_name": "find", "parameter_list": "(parent, i)" }, { "docstring": "Function to perform union of two sets x and y using rank.", "function_de...
[ 0, 0, 0, 0, 0, 0, 0, 0, 1, 1 ]
2
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "class DisjointSet:\n def __init__(self, n):\n self.parent = list(range(n))\n self.rank = [1] * n\n\n def find(self, v):\n if v != s...
trial_gpt4o_9
{ "original_instruction": "You are given a weighted undirected graph with $$$n$$$ vertices and $$$m$$$ edges. Each edge has a weight associated with it.\n\nDavid wants to find the weight of the maximum spanning tree of this graph. A spanning tree is a tree that includes all the vertices of the graph with the minimum ...
0.667527
Codeforces_28081
C
[ "find", "union", "maximum_spanning_tree" ]
3
[ [ "maximum_spanning_tree", "find" ], [ "maximum_spanning_tree", "union" ], [ "union", "find" ] ]
3
[]
false
[]
false
pytest
true
[]
true
94a6a2da4a75cd59410a5ea6ccbab4b08145f571
cd7736eed8cf026964dc7c063f78ea12da614ddc
v1.0
complete
Codeforces
Codeforces_28308_C
def minimize_max_subarray_sum(n: int, m: int, nums: List[int]) -> int: """ Given an array of n integers and an integer m, determine if there is a way to partition the array into exactly m subarrays such that the maximum sum of the subarrays is minimized. >>> minimize_max_subarray_sum(5, 2, [7, 2, 5, 10, 8]) 18 ...
def is_feasible(mid, nums, m): current_sum = 0 required_subarrays = 1 for num in nums: if current_sum + num > mid: required_subarrays += 1 current_sum = num if required_subarrays > m: return False else: current_sum += num ...
from solution import minimize_max_subarray_sum def test_example_case(): assert minimize_max_subarray_sum(5, 2, [7, 2, 5, 10, 8]) == 18 def test_single_element(): assert minimize_max_subarray_sum(1, 1, [10]) == 10 def test_same_elements(): assert minimize_max_subarray_sum(4, 2, [5, 5, 5, 5]) == 10 def te...
[ { "docstring": null, "function_declaration": "def is_feasible(mid, nums, m):", "function_name": "is_feasible", "parameter_list": "(mid, nums, m)" }, { "docstring": null, "function_declaration": "def minimize_max_subarray_sum(n, m, nums):", "function_name": "minimize_max_subarray_sum"...
[ 1, 0, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def minimize_max_subarray_sum(arr, m):\n def is_valid(mid):\n current_sum = 0\n parts = 1\n for num in arr:\n if current_su...
trial_gpt4o_2
{ "original_instruction": "You are given an array of n integers and an integer m. Your task is to determine if there is a way to partition the array into exactly m subarrays such that the maximum sum of the subarrays is minimized.\n\nThe first line of input contains two integers n and m (1 ≤ n, m ≤ 1000) — the length...
0.761949
Codeforces_28308
C
[ "is_feasible", "minimize_max_subarray_sum" ]
2
[ [ "minimize_max_subarray_sum", "is_feasible" ] ]
1
[]
false
[]
false
pytest
true
[]
true
fdcdfac63d166623ccaa4105103833dd37053704
bcdc7a8a76f52d00a0831df4472c8a6ba6f0849b
v1.0
complete
Codeforces
Codeforces_28177_C
def is_zigzag(subarray): """ Check if the subarray is zigzag. """ for i in range(1, len(subarray) - 1): if not ((subarray[i] > subarray[i-1] and subarray[i] > subarray[i+1]) or (subarray[i] < subarray[i-1] and subarray[i] < subarray[i+1])): return False return True ...
def is_zigzag(subarray): for i in range(1, len(subarray) - 1): if not ((subarray[i] > subarray[i-1] and subarray[i] > subarray[i+1]) or (subarray[i] < subarray[i-1] and subarray[i] < subarray[i+1])): return False return True def longest_zigzag_subarray(n, k, arr): max_l...
from solution import longest_zigzag_subarray def test_example(): assert longest_zigzag_subarray(10, 3, [1, 3, 2, 4, 3, 5, 6, 7, 1, 8]) == 3 def test_no_zigzag(): assert longest_zigzag_subarray(5, 3, [1, 2, 3, 4, 5]) == 0 def test_single_element_subarray(): assert longest_zigzag_subarray(1, 1, [10]) == 1 ...
[ { "docstring": null, "function_declaration": "def is_zigzag(subarray):", "function_name": "is_zigzag", "parameter_list": "(subarray)" }, { "docstring": null, "function_declaration": "def longest_zigzag_subarray(n, k, arr):", "function_name": "longest_zigzag_subarray", "parameter_...
[ 0, 0, 0, 0, 0, 1, 0, 0, 0, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def longest_zigzag_subarray(arr, k):\n n = len(arr)\n max_length = 0\n\n # Check all possible subarrays of length k\n for i in range(n - k + 1):\n...
trial_gpt4o_5
{ "original_instruction": "An array of integers is called a zigzag array if every element is either strictly greater than or strictly less than its neighboring elements. Specifically, for all valid indices i, one of the following conditions must hold: \n- `arr[i] > arr[i-1] and arr[i] > arr[i+1]`\n- `arr[i] < arr[i-1...
0.619118
Codeforces_28177
C
[ "is_zigzag", "longest_zigzag_subarray" ]
2
[ [ "longest_zigzag_subarray", "is_zigzag" ] ]
1
[]
false
[]
false
pytest
true
[]
true
fbe7eaec4ff65a52e7fe61e9ccb53aa63dbb7347
8225fb608e6138edb64d1306e1f31ba97702c4ae
v1.0
complete
Codeforces
Codeforces_28593_C
def process_operations(n: int, operations: List[str]) -> List[str]: """ Automate the attendance tracking system for employees. For each operation "IN" or "OUT", return "OK" if the operation is successful, or "INVALID" if it violates any constraints. Args: n : int : Number of operations operations :...
def attendance_tracking(n, operations): attendance_record = {} results = [] for operation in operations: op_type, identifier, timestamp = operation timestamp = int(timestamp) if identifier not in attendance_record: attendance_record[identifier] = { ...
from solution import process_operations def test_single_check_in_out(): operations = [ "IN alice 123", "OUT alice 456" ] assert process_operations(len(operations), operations) == ["OK", "OK"] def test_invalid_check_out_without_check_in(): operations = [ "OUT alice 456" ] ...
[ { "docstring": null, "function_declaration": "def attendance_tracking(n, operations):", "function_name": "attendance_tracking", "parameter_list": "(n, operations)" }, { "docstring": null, "function_declaration": "def process_operations(n, operations):", "function_name": "process_oper...
[ 0, 0, 0, 1, 1 ]
2
medium
0.4
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def process_attendance_log(n, operations):\n attendance = {}\n results = []\n\n for operation in operations:\n op, identifier, timestamp = ope...
trial_gpt4o_3
{ "original_instruction": "John wants to automate the attendance tracking at his workplace. The system should keep track of employee check-ins and check-outs, ensuring that no two events have the same timestamp for the same employee. Each employee's attendance record is represented as a sequence of events, each times...
0.510397
Codeforces_28593
C
[ "attendance_tracking", "process_operations" ]
2
[ [ "process_operations", "attendance_tracking" ] ]
1
[]
false
[]
false
pytest
true
[]
true
aa0c68cc2f62bcd85455e2378a8a051485b22749
965bf4434771511511630e0a634ce8291f538853
v1.0
complete
Codeforces
Codeforces_28425_C
def max_sum_non_adjacent_elements(n: int, k: int, arr: List[int]) -> int: """ Determine the maximum possible sum of selected elements such that no two adjacent elements are selected from the original array. Args: n (int): Number of elements in the array. k (int): Number of elements to select. ...
def max_sum_non_adjacent_elements(n, k, arr): # DP array where dp[i][j] stands for the maximum sum using the first i elements, selecting j of them. dp = [[0] * (k + 1) for _ in range(n + 1)] for i in range(1, n + 1): for j in range(1, k + 1): # Option 1: Skip this element dp...
from solution import max_sum_non_adjacent_elements def test_example_case(): assert max_sum_non_adjacent_elements(6, 3, [10, 5, 15, 7, 6, 18]) == 43 def test_single_element(): assert max_sum_non_adjacent_elements(1, 1, [5]) == 5 def test_all_elements_selected(): assert max_sum_non_adjacent_elements(4, 2, ...
[ { "docstring": null, "function_declaration": "def max_sum_non_adjacent_elements(n, k, arr):", "function_name": "max_sum_non_adjacent_elements", "parameter_list": "(n, k, arr)" }, { "docstring": null, "function_declaration": "def solve_max_sum_non_adjacent_elements():", "function_name...
[ 1, 0, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def max_sum_non_adjacent_elements(n, k, arr):\n # DP array where dp[i][j] stands for the maximum sum using the first i elements, selecting j of them.\n ...
trial_gpt4o_0
{ "original_instruction": "You have been given an array `arr` consisting of `n` positive integers (1 ≤ n ≤ 200000). You are allowed to select exactly `k` elements (1 ≤ k ≤ n) from the array. Your task is to determine the maximum possible sum of selected elements such that no two adjacent elements are selected from th...
0.725308
Codeforces_28425
C
[ "max_sum_non_adjacent_elements", "solve_max_sum_non_adjacent_elements" ]
2
[ [ "solve_max_sum_non_adjacent_elements", "max_sum_non_adjacent_elements" ] ]
1
[]
false
[]
false
pytest
true
[]
true
2fd4f9d832bfa2c8fdccec7d6916d409e058142a
25f94ff7f2d7a5ca1dbb8be306b8d8c581b315eb
v1.0
complete
Codeforces
Codeforces_28397_C
def balanced_trees_count(n, nodes): """ Returns the number of different balanced binary trees that can be formed using 'n' nodes. The 'nodes' list contains the given integers (not actually used for counting, just for matching problem statement). """ def num_trees(n): """ Computes the number...
def num_trees(n): """ Computes the number of different balanced trees that can be constructed with 'n' nodes. """ if n == 0 or n == 1: return 1 num_balanced = [0] * (n + 1) num_balanced[0] = num_balanced[1] = 1 for nodes in range(2, n + 1): for root in range(1, node...
from solution import balanced_trees_count def test_balanced_trees_count_3(): assert balanced_trees_count(3, [1, 2, 3]) == 5 def test_balanced_trees_count_4(): assert balanced_trees_count(4, [5, 3, 8, 6]) == 14 def test_balanced_trees_count_1(): assert balanced_trees_count(1, [7]) == 1 def test_balanced_...
[ { "docstring": "Computes the number of different balanced trees that can be constructed with 'n' nodes.", "function_declaration": "def num_trees(n):", "function_name": "num_trees", "parameter_list": "(n)" }, { "docstring": "Returns the number of different balanced binary trees that can be fo...
[ 0, 0, 0, 0, 1 ]
1
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "from math import comb\n\n# Function to calculate number of different balanced binary trees with n nodes\ndef count_balanced_trees(n):\n if n == 0 or n == 1...
trial_gpt4o_4
{ "original_instruction": "Alice has a collection of n integers which she can manipulate to form a balanced tree. A balanced tree is defined as a tree where for any internal node, the height of the left subtree and the right subtree do not differ by more than one. Alice wants to find out how many different balanced t...
0.656336
Codeforces_28397
C
[ "num_trees", "balanced_trees_count" ]
2
[ [ "balanced_trees_count", "num_trees" ] ]
1
[]
false
[]
false
pytest
true
[]
true
6902fc9f6ea461c98e4877ea9d2830e79c155dfe
331436c4ea53162eb8985c0512f65fcbf09cbb6d
v1.0
complete
Codeforces
Codeforces_27950_C
def max_area_of_plant_section(n, m, grid): """ Determine the maximum possible area of the rectangular section of the garden that can be watered containing only plants (1s). Args: n (int): Number of rows in the garden grid. m (int): Number of columns in the garden grid. grid (List[List[int]]): n...
def max_area_of_plant_section(n, m, grid): if not grid: return 0 max_area = 0 heights = [0] * m for row in grid: for i in range(m): if row[i] == 0: heights[i] = 0 else: heights[i] += 1 max_area = max(max_area, lar...
from solution import max_area_of_plant_section def test_max_area_small_grid(): assert max_area_of_plant_section(4, 5, [ [1, 0, 1, 0, 0], [1, 0, 1, 1, 1], [1, 1, 1, 1, 1], [1, 0, 0, 1, 0] ]) == 6 def test_max_area_entire_grid(): assert max_area_of_plant_section(3, 3, [ ...
[ { "docstring": null, "function_declaration": "def max_area_of_plant_section(n, m, grid):", "function_name": "max_area_of_plant_section", "parameter_list": "(n, m, grid)" }, { "docstring": null, "function_declaration": "def largest_rectangle_area(heights):", "function_name": "largest_...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def max_rect_area(matrix):\n if not matrix or not matrix[0]:\n return 0\n\n max_area = 0\n n, m = len(matrix), len(matrix[0])\n heights = [...
trial_gpt4o_1
{ "original_instruction": "Sophia loves gardening and has a beautiful garden with paths laid out in a grid. Each cell in the grid can either contain a plant or be empty. The grid is represented as an `n x m` matrix where each cell contains either a 0 (empty) or a 1 (plant). Sophia wants to water her plants, but she c...
0.625396
Codeforces_27950
C
[ "max_area_of_plant_section", "largest_rectangle_area" ]
2
[ [ "max_area_of_plant_section", "largest_rectangle_area" ] ]
1
[]
false
[]
false
pytest
true
[]
true
ed910616da9743055fd1eb9b071597a4ac5e6578
7b83ec577129f20444dc740c1b44bfba75d8df72
v1.0
complete
Codeforces
Codeforces_28524_C
def find_largest_rectangle_area(n: int, heights: List[int]) -> int: """ Given a list of building heights, find the area of the largest rectangle that can be formed using consecutive buildings. >>> find_largest_rectangle_area(6, [2, 1, 5, 6, 2, 3]) 10 >>> find_largest_rectangle_area(1, [1]) ...
def largest_rectangle_area(heights): """ Given a list of building heights, find the area of the largest rectangle that can be formed using consecutive buildings. """ stack = [] max_area = 0 index = 0 while index < len(heights): if not stack or heights[stack[-1]] <= heights[i...
from solution import find_largest_rectangle_area def test_example_case(): assert find_largest_rectangle_area(6, [2, 1, 5, 6, 2, 3]) == 10 def test_single_building(): assert find_largest_rectangle_area(1, [1]) == 1 assert find_largest_rectangle_area(1, [10]) == 10 def test_identical_heights(): assert ...
[ { "docstring": "Given a list of building heights, find the area of the largest rectangle\nthat can be formed using consecutive buildings.", "function_declaration": "def largest_rectangle_area(heights):", "function_name": "largest_rectangle_area", "parameter_list": "(heights)" }, { "docstring...
[ 0, 1, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def largest_rectangle_area(heights):\n \"\"\"\n Returns the area of the largest rectangle that can be formed using consecutive buildings.\n :param he...
trial_gpt4o_2
{ "original_instruction": "You are given a list of numbers representing heights of buildings in a skyline. Each building has a width of 1. You need to determine the area of the largest rectangle that can be formed using consecutive buildings. \n\nFor example, given the heights `[2, 1, 5, 6, 2, 3]`, the largest rectan...
0.712
Codeforces_28524
C
[ "largest_rectangle_area", "find_largest_rectangle_area" ]
2
[ [ "find_largest_rectangle_area", "largest_rectangle_area" ] ]
1
[]
false
[]
false
pytest
true
[]
true
b5a19f096c7a5415f1dd1f6a52973f08d89fce3e
6c1ef4417e7ab82c4edb3cb0afed7331e6c4b12f
v1.0
complete
Codeforces
Codeforces_28391_C
from typing import List def illuminate_grid(n: int, m: int, q: int, grid: List[List[int]], operations: List[List[int]]) -> List[List[int]]: """ Illuminate the grid based on a series of operations. Parameters: n (int): Number of rows in the grid. m (int): Number of columns in the grid. q (int):...
def illuminate_grid(n, m, q, grid, operations): for operation in operations: r1, c1, r2, c2, k = operation for i in range(r1 - 1, r2): for j in range(c1 - 1, c2): grid[i][j] += k return grid # We can define a function to parse input and encapsulate the entire process...
from solution import illuminate_grid, process_illumination def test_single_operation(): initial_grid = [ [1, 2, 3], [4, 5, 6], [7, 8, 9] ] operations = [ [1, 1, 2, 2, 10] ] expected_grid = [ [11, 12, 3], [14, 15, 6], [7, 8, 9] ] assert...
[ { "docstring": null, "function_declaration": "def illuminate_grid(n, m, q, grid, operations):", "function_name": "illuminate_grid", "parameter_list": "(n, m, q, grid, operations)" }, { "docstring": null, "function_declaration": "def process_illumination(input_str):", "function_name":...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def increase_brightness(n, m, grid, operations):\n \"\"\"\n Increases the brightness of the grid based on the given operations.\n\n Parameters:\n ...
trial_gpt4o_2
{ "original_instruction": "A scientist is working on an experiment that involves illuminating a grid of lights. The grid is a 2-dimensional array with `n` rows and `m` columns, where each cell initially has a certain brightness level. The scientist can perform a series of operations to increase the brightness of cert...
0.622315
Codeforces_28391
C
[ "illuminate_grid", "process_illumination" ]
2
[ [ "process_illumination", "illuminate_grid" ] ]
1
[]
false
[]
false
pytest
true
[]
true
aced52815c66e4387772c5c2ebfc03ec46ee993d
6e0b51579c0654000b44c1fa2e378bc248373d41
v1.0
complete
Codeforces
Codeforces_28315_C
def compute_prefix_sums(beauty: List[int]) -> List[int]: """ Compute the prefix sums of the beauty scores. Args: beauty (List[int]): A list of beauty scores of paintings. Returns: List[int]: A list containing the prefix sums of beauty scores. >>> compute_prefix_sums([1, 2, 3, 4, 5]) [0...
def compute_prefix_sums(beauty): prefix_sums = [0] * (len(beauty) + 1) for i in range(len(beauty)): prefix_sums[i + 1] = prefix_sums[i] + beauty[i] return prefix_sums def average_beauty_scores(n, q, beauty, queries): prefix_sums = compute_prefix_sums(beauty) results = [] for l, r in que...
def test_compute_prefix_sums(): beauty = [1, 2, 3, 4, 5] expected_prefix_sums = [0, 1, 3, 6, 10, 15] assert compute_prefix_sums(beauty) == expected_prefix_sums def test_average_beauty_scores(): n, q = 5, 3 beauty = [1, 2, 3, 4, 5] queries = [(1, 3), (2, 5), (1, 5)] expected_results = ["2...
[ { "docstring": null, "function_declaration": "def compute_prefix_sums(beauty):", "function_name": "compute_prefix_sums", "parameter_list": "(beauty)" }, { "docstring": null, "function_declaration": "def average_beauty_scores(n, q, beauty, queries):", "function_name": "average_beauty_...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def calculate_average_beauty(n, q, beauty, queries):\n # Precompute prefix sums for efficient range sum queries\n prefix_sums = [0] * (n + 1)\n for i...
trial_gpt4o_2
{ "original_instruction": "Jenia loves visiting art galleries, admiring the intricate details and stunning artwork. Today, while visiting a gallery, she came across an interesting statistic problem. Each painting in the gallery has a unique integer identifier.\n\nJenia now wants to select different sets of paintings ...
0.6066
Codeforces_28315
C
[ "compute_prefix_sums", "average_beauty_scores" ]
2
[ [ "average_beauty_scores", "compute_prefix_sums" ] ]
1
[]
false
[]
false
pytest
false
[]
true
d827d5e248690980f2bec52062c8529695d5d075
43a48b223264f9ba03215701739116fbefdca4bf
v1.0
complete
Codeforces
Codeforces_28249_C
class TreeNode: def __init__(self, value): self.value = value self.left = None self.right = None def create_tree(level_order): if not level_order or level_order[0] == '#': return None root = TreeNode(int(level_order[0])) queue = [root] i = 1 while queue and i < l...
class TreeNode: def __init__(self, value): self.value = value self.left = None self.right = None def create_tree(level_order): if not level_order or level_order[0] == '#': return None root = TreeNode(int(level_order[0])) queue = [root] i = 1 while queue and i < l...
import pytest from solution import count_balanced_trees def test_basic_case(): t = 3 trees = [ "1 2 3 # # 4 5", "1 2 # 3 4", "1 2 2 3 3 # #" ] assert count_balanced_trees(t, trees) == 2 def test_all_balanced(): t = 3 trees = [ "1", "1 2 3", "1 2 ...
[]
[ 1, 0, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_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 create_tree(level_orde...
trial_gpt4o_0
{ "original_instruction": "You are given a forest of trees, where each tree is defined by a number of positive integer nodes. Each node has a unique value.\n\nA tree is considered \"balanced\" if for every node the height difference between its left subtree and its right subtree is at most 1. The height of a subtree ...
0.672205
Codeforces_28249
C
[ "create_tree", "is_balanced", "count_balanced_trees" ]
3
[ [ "count_balanced_trees", "create_tree" ], [ "count_balanced_trees", "is_balanced" ] ]
2
[]
false
[ "TreeNode" ]
true
pytest
true
[]
true
9048e4f7cfef133e3686cc6f46d88122408c0f68
48a5b60c8e082027b53606efc5235c9af3fa3dc1
v1.0
complete
Codeforces
Codeforces_28754_C
def get_max_security_levels(n, q, a, queries): """ Answer queries regarding the maximum security levels of scrolls between given indices. Parameters: n (int): Number of scrolls. q (int): Number of queries. a (List[int]): Array of security levels. queries (List[Tuple[int, int]]): List o...
def preprocess_max_security_levels(a): """Preprocess the list to create the necessary data structure for answering range maximum queries.""" import math n = len(a) k = math.floor(math.log2(n)) + 1 st = [[0] * k for _ in range(n)] for i in range(n): st[i][0] = a[i] j = 1 while (...
from solution import get_max_security_levels def test_sample_case(): n = 5 q = 3 a = [1, 3, 4, 2, 5] queries = [(1, 3), (2, 4), (3, 5)] expected = [4, 4, 5] assert get_max_security_levels(n, q, a, queries) == expected def test_single_element_range(): n = 5 q = 3 a = [1, 3, 4, 2, 5]...
[ { "docstring": "Preprocess the list to create the necessary data structure for answering range maximum queries.", "function_declaration": "def preprocess_max_security_levels(a):", "function_name": "preprocess_max_security_levels", "parameter_list": "(a)" }, { "docstring": "Query the preproce...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def max_security_levels(n, q, a, queries):\n \"\"\"\n Returns a list of maximum security levels for given queries.\n \n Args:\n n : int : numbe...
trial_gpt4o_2
{ "original_instruction": "An ancient library contains $$$n$$$ historical scrolls arranged in a line, each assigned a unique index from $$$1$$$ to $$$n$$$. Some scrolls may contain sensitive information and must be protected from unauthorized access. To implement a security system, each scroll has a security level, r...
0.586376
Codeforces_28754
C
[ "preprocess_max_security_levels", "query_max_security_level", "get_max_security_levels" ]
3
[ [ "get_max_security_levels", "preprocess_max_security_levels" ], [ "get_max_security_levels", "query_max_security_level" ] ]
2
[]
false
[]
false
pytest
true
[]
true
de60e84d92adda072c82df7b51987d7993d7345e
5704b431df6964590a745790b2f37d353bfff82b
v1.0
complete
Codeforces
Codeforces_28704_C
def largest_prime_less_than(n: int) -> int: """ Find the largest prime number strictly less than the given integer n. >>> largest_prime_less_than(10) 7 >>> largest_prime_less_than(30) 29 >>> largest_prime_less_than(20) 19 from solution import largest_prime_less_than def test_largest_prime_...
def is_prime(k): """Returns True if k is a prime number, otherwise False.""" if k <= 1: return False if k <= 3: return True if k % 2 == 0 or k % 3 == 0: return False i = 5 while i * i <= k: if k % i == 0 or k % (i + 2) == 0: return False i += 6...
from solution import largest_prime_less_than def test_largest_prime_standard_cases(): assert largest_prime_less_than(10) == 7 assert largest_prime_less_than(30) == 29 assert largest_prime_less_than(20) == 19 assert largest_prime_less_than(3) == 2 def test_largest_prime_edge_cases(): # For the smal...
[ { "docstring": "Returns True if k is a prime number, otherwise False.", "function_declaration": "def is_prime(k):", "function_name": "is_prime", "parameter_list": "(k)" }, { "docstring": "Returns the largest prime number strictly less than n.", "function_declaration": "def largest_prime_...
[ 0, 1, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def sieve_of_eratosthenes(limit):\n \"\"\"\n Generate a list of boolean values, where True indicates a prime number.\n \"\"\"\n is_prime = [True] ...
trial_gpt4o_1
{ "original_instruction": "Paul is a young programmer who is intrigued by prime numbers. He has been exploring different properties of prime numbers and recently came across an interesting challenge. Paul wants to identify the largest prime number that is strictly less than the given integer n. However, Paul also wan...
0.681409
Codeforces_28704
C
[ "is_prime", "largest_prime_less_than" ]
2
[ [ "largest_prime_less_than", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
b8f1ac4cfc75b42d16b86ed44ad9712976703dee
17ccd8d72beed06752a27faf2620b6b5765a9eb5
v1.0
complete
Codeforces
Codeforces_28703_C
def process_input_and_check_consistency(input_data: str) -> str: """ Given input data of number of participants, number of pairs, and pairs of rankings, determines if the ranking list is consistent. >>> process_input_and_check_consistency("4 3\n1 2\n2 3\n3 4") 'Consistent' >>> process_input_and_check_co...
def check_consistency(n, m, pairs): from collections import defaultdict, deque # Create graph graph = defaultdict(list) in_degree = [0] * (n + 1) for a, b in pairs: graph[a].append(b) in_degree[b] += 1 # Perform topological sort queue = deque([i for i in range(1, n...
def test_consistent_case(): input_data = "4 3\n1 2\n2 3\n3 4" assert process_input_and_check_consistency(input_data) == "Consistent" def test_inconsistent_case(): input_data = "4 4\n1 2\n2 3\n3 4\n4 2" assert process_input_and_check_consistency(input_data) == "Inconsistent" def test_no_pairs(): in...
[ { "docstring": null, "function_declaration": "def check_consistency(n, m, pairs):", "function_name": "check_consistency", "parameter_list": "(n, m, pairs)" }, { "docstring": null, "function_declaration": "def process_input_and_check_consistency(input_data):", "function_name": "proces...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def check_consistency(n, m, pairs):\n from collections import defaultdict, deque\n \n def has_cycle(graph, n):\n in_degree = {i: 0 for i in ra...
trial_gpt4o_2
{ "original_instruction": "Each year, the Annual Programming Competition is organized in Anytown. There are `n` participants in this competition, each identified by a unique ID number from `1` to `n`. This year, the organizers have introduced a new rule to encourage participants to perform better in the early stages ...
0.61174
Codeforces_28703
C
[ "check_consistency", "process_input_and_check_consistency" ]
2
[ [ "process_input_and_check_consistency", "check_consistency" ] ]
1
[]
false
[]
false
pytest
false
[]
true
1a31ce55631a95e5794f1be3b40a3f3610a50e54
ea4e2c50cdd10570301cb08fe5adfc88cf5e0344
v1.0
complete
Codeforces
Codeforces_28884_C
def count_swaps(arr): """ Returns the minimum number of swaps required to make the array of plant heights a non-decreasing sequence. >>> count_swaps([1, 2, 3, 4, 5]) 0 >>> count_swaps([5, 4, 3, 2, 1]) 10 >>> count_swaps([5, 1, 3, 2, 4]) 5 >>> count_swaps([1]) 0 >>> count_swaps([2, 1]) 1 >>> ...
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 while i <= mid and j <= right: if arr[i] <= arr[j]: temp_arr[k] = arr[i] ...
from solution import count_swaps def test_sorted_array(): assert count_swaps([1, 2, 3, 4, 5]) == 0 def test_reverse_sorted_array(): assert count_swaps([5, 4, 3, 2, 1]) == 10 def test_random_array(): assert count_swaps([5, 1, 3, 2, 4]) == 5 def test_single_element_array(): assert count_swaps([1]) == ...
[ { "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...
[ 0, 1, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def minimum_swaps_to_sort(arr):\n \"\"\"\n This function computes the minimum number of swaps needed to sort the given array\n in non-decreasing orde...
trial_gpt4o_1
{ "original_instruction": "Eden is a passionate gardener who loves arranging plants in a perfect sequence according to their heights. Eden's garden has an array of plants, each with a distinct height.\n\nYou are given an array of integers representing the heights of the plants in Eden's garden. Eden wants the heights...
0.557044
Codeforces_28884
C
[ "merge_and_count", "merge_sort_and_count", "count_swaps", "main" ]
4
[ [ "count_swaps", "merge_sort_and_count" ], [ "merge_sort_and_count", "merge_and_count" ] ]
2
[]
false
[]
false
pytest
true
[]
true
1bf6882779c8ad23ba91654a25ec8774cf4d9318
60fc3e0ea92b3e0718ea5036cc0793ac9226bcde
v1.0
complete
Codeforces
Codeforces_28811_C
from typing import List def count_inversions(arr: List[int]) -> int: """Sort the array using the Merge Sort algorithm and count the number of inversions. An inversion is a pair of indices (i, j) such that i < j and array[i] > array[j]. Args: arr (List[int]): The array of integers to be sorted. Re...
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 i doesn't exceed mid and j doesn't exceed right while i...
from solution import count_inversions def test_example_case(): assert count_inversions([2, 4, 1, 3, 5]) == 3 def test_sorted_array(): assert count_inversions([1, 2, 3, 4, 5]) == 0 def test_reversed_array(): assert count_inversions([5, 4, 3, 2, 1]) == 10 def test_mixed_array(): assert count_inversion...
[ { "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...
[ 0, 1, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def merge_and_count(arr, temp_arr, left, mid, right):\n i = left # Starting index for left subarray\n j = mid + 1 # Starting index for right subarray...
trial_gpt4o_2
{ "original_instruction": "Vasya loves sorting algorithms and has recently started learning about the Merge Sort algorithm. Vasya wants to implement the Merge Sort algorithm on an array, but with a twist. He wants to count the number of inversions in the array while sorting it. An inversion is a pair of indices (i, j...
0.820127
Codeforces_28811
C
[ "merge_and_count", "merge_sort_and_count", "count_inversions" ]
3
[ [ "count_inversions", "merge_sort_and_count" ], [ "merge_sort_and_count", "merge_and_count" ] ]
2
[]
false
[]
false
pytest
true
[]
true
747b15eec792c75169434fae67ed4976b9f85940
a26c9b6a718c4902636c0e23856d3e4613edfe7d
v1.0
complete
Codeforces
Codeforces_28170_C
def preprocess(matrix: List[List[int]]) -> List[List[int]]: """ Preprocess the matrix to create a prefix sum matrix. :param matrix: The input matrix containing n rows and m columns. :return: The prefix sum matrix. """ def query_sum(prefix_sum: List[List[int]], r1: int, c1: int, r2: int, c2: int) -> int...
def preprocess(matrix): """ Preprocess the matrix to create a prefix sum matrix. """ n = len(matrix) m = len(matrix[0]) # Create a prefix sum matrix with an extra row and column of zeros. prefix_sum = [[0] * (m + 1) for _ in range(n + 1)] # Fill the prefix sum matrix. for i...
def test_preprocess(): matrix = [ [1, 2, 3], [4, 5, 6], [7, 8, 9] ] expected_prefix_sum = [ [0, 0, 0, 0], [0, 1, 3, 6], [0, 5, 12, 21], [0, 12, 27, 45] ] assert preprocess(matrix) == expected_prefix_sum def test_query_sum(): prefix_sum = [...
[ { "docstring": "Preprocess the matrix to create a prefix sum matrix.", "function_declaration": "def preprocess(matrix):", "function_name": "preprocess", "parameter_list": "(matrix)" }, { "docstring": "Get the sum of elements in the submatrix from (r1, c1) to (r2, c2) inclusive using the pref...
[ 0, 1, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def preprocess_matrix(matrix, n, m):\n # Creating prefix sum matrix\n prefix_sum = [[0] * (m + 1) for _ in range(n + 1)]\n \n for i in range(1, n+...
trial_gpt4o_2
{ "original_instruction": "You are given a matrix with n rows and m columns. The matrix contains integers, and you need to perform q queries. Each query consists of four integers r1, c1, r2, and c2, which represent a submatrix's top-left corner (r1, c1) and bottom-right corner (r2, c2). Your task is to determine the ...
0.567453
Codeforces_28170
C
[ "preprocess", "query_sum", "handle_queries" ]
3
[ [ "handle_queries", "preprocess" ], [ "handle_queries", "query_sum" ] ]
2
[ "handle_queries" ]
false
[]
false
pytest
false
[]
true
ea97c65fcb764beb38496cdb4edd444f29b4ccec
f9ded9de6ee269f8189cd88136c997eeba7395d1
v1.0
complete
Codeforces
Codeforces_28646_C
def canPlaceCows(stalls: List[int], c: int, min_dist: int) -> bool: """ Helper function to check if cows can be placed with at least min_dist distance.""" pass def largestMinDist(n: int, c: int, stalls: List[int]) -> int: """ Farmer John has a new barn that has n stalls. He wants to place c cows in the sta...
def canPlaceCows(stalls, c, min_dist): count = 1 last_position = stalls[0] for i in range(1, len(stalls)): if stalls[i] - last_position >= min_dist: count += 1 last_position = stalls[i] if count == c: return True return False def largestM...
from solution import largestMinDist def test_example_case(): assert largestMinDist(5, 3, [1, 2, 8, 4, 9]) == 3 def test_case_all_stalls_aligned(): assert largestMinDist(4, 2, [1, 2, 3, 4]) == 3 def test_case_larger_distances(): assert largestMinDist(6, 3, [4, 8, 15, 16, 23, 42]) == 19 def test_case_min_...
[ { "docstring": null, "function_declaration": "def canPlaceCows(stalls, c, min_dist):", "function_name": "canPlaceCows", "parameter_list": "(stalls, c, min_dist)" }, { "docstring": null, "function_declaration": "def largestMinDist(n, c, stalls):", "function_name": "largestMinDist", ...
[ 0, 0, 0, 1, 0 ]
1
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def can_place_cows(stalls, c, min_dist):\n count = 1\n last_position = stalls[0]\n \n for i in range(1, len(stalls)):\n if stalls[i] - last...
trial_gpt4o_3
{ "original_instruction": "Farmer John has a new barn that has $$$n$$$ stalls. He wants to place $$$c$$$ cows in the stalls, such that the minimum distance between any two of them is as large as possible. Can you help him accomplish this?\n\nThe stalls are located along a straight line at positions $$$x_1, x_2, \\ldo...
0.575718
Codeforces_28646
C
[ "canPlaceCows", "largestMinDist" ]
2
[ [ "largestMinDist", "canPlaceCows" ] ]
1
[]
false
[]
false
pytest
true
[]
true
a94fb0ec47f10476f6efa4b72d2730a1fb59ae8f
2b9e010fce46bac80de60d41c58c1765de43615d
v1.0
complete
Codeforces
Codeforces_28460_C
def process_operations(n: int, operations: List[str]) -> List[int]: """ Alice is playing a game with a list of integers. She starts with an empty list and can perform operations to either add an integer to the end of the list, remove an integer from the end of the list, or query the maximum subarray sum o...
def max_subarray_sum(arr): """ Returns the maximum subarray sum of the given array using Kadane's algorithm. """ if not arr: return 0 max_ending_here = max_so_far = arr[0] for x in arr[1:]: max_ending_here = max(x, max_ending_here + x) max_so_far = max(max_so_far, max_en...
import pytest from solution import process_operations def test_add_remove_query_operations(): n = 6 operations = ["ADD 1", "ADD 2", "QUERY", "ADD -3", "REMOVE", "QUERY"] expected = [3, 3] assert process_operations(n, operations) == expected def test_multiple_add_queries(): n = 5 operations = [...
[ { "docstring": "Returns the maximum subarray sum of the given array using Kadane's algorithm.", "function_declaration": "def max_subarray_sum(arr):", "function_name": "max_subarray_sum", "parameter_list": "(arr)" }, { "docstring": "Processes a sequence of operations and returns the results o...
[ 0, 0, 1 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "class MaxSubarraySum:\n def __init__(self):\n self.nums = []\n self.max_sum_segments = [0]\n \n def add(self, x):\n self.nums.appe...
trial_gpt4o_2
{ "original_instruction": "Alice is playing a game with a list of integers. She starts with an empty list and can perform operations to either add an integer to the end of the list, remove an integer from the end of the list, or query the maximum subarray sum of the current list. The maximum subarray sum is defined a...
0.61008
Codeforces_28460
C
[ "max_subarray_sum", "process_operations" ]
2
[ [ "process_operations", "max_subarray_sum" ] ]
1
[]
false
[]
false
pytest
true
[]
true
0b2af789601d657e16abb39beb81290bdc681f32
beaf2c0cb8ce7658472a9858a7e610d7a4c35e2f
v1.0
complete
Codeforces
Codeforces_28836_C
def find_max_rectangle_area(n: int, m: int, grid: List[str]) -> int: """ You are given a rectangular garden divided into a grid of cells. Each cell is either fertile (designated by a 1) or barren (designated by a 0). You want to plant a rectangular patch of flowers such that the flowers are planted only in fertile ...
def maximalRectangle(matrix): if not matrix or not matrix[0]: return 0 # Get the number of rows and columns n = len(matrix) m = len(matrix[0]) # Initialize heights array heights = [0] * m max_area = 0 for i in range(n): for j in range(m): #...
def test_example_case(): grid = [ "10100", "10111", "11111", "10010" ] assert find_max_rectangle_area(4, 5, grid) == 6 def test_single_row_single_rectangle(): grid = [ "11111" ] assert find_max_rectangle_area(1, 5, grid) == 5 def test_single_column_singl...
[ { "docstring": null, "function_declaration": "def maximalRectangle(matrix):", "function_name": "maximalRectangle", "parameter_list": "(matrix)" }, { "docstring": null, "function_declaration": "def largestRectangleArea(heights):", "function_name": "largestRectangleArea", "paramete...
[ 0, 1, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def maximal_rectangle_area(n, m, grid):\n if not grid:\n return 0\n \n max_area = 0\n heights = [0] * m\n \n for row in grid:\n ...
trial_gpt4o_1
{ "original_instruction": "You are given a rectangular garden divided into a grid of cells. Each cell is either fertile (designated by a 1) or barren (designated by a 0). You want to plant a rectangular patch of flowers such that the flowers are planted only in fertile cells. Out of all possible rectangular patches o...
0.713927
Codeforces_28836
C
[ "maximalRectangle", "largestRectangleArea", "find_max_rectangle_area" ]
3
[ [ "find_max_rectangle_area", "maximalRectangle" ], [ "maximalRectangle", "largestRectangleArea" ] ]
2
[]
false
[]
false
pytest
false
[]
true
5f0311f3d86bcfa260d29ea164ddc000b5bf9033
cb69c71422b44e2661b5eb06baacf6b5976efcb4
v1.0
complete
Codeforces
Codeforces_29270_C
def process_queries(n: int, q: int, positions: List[int], queries: List[Tuple[int, int]]) -> List[str]: """ Determine if turtles can reach target positions on the track. >>> process_queries(5, 3, [32, 45, 56, 78, 67], [(1, 3), (2, 5), (1, 4)]) ['Yes', 'No', 'Yes'] """
def sum_of_digits(num): return sum(int(digit) for digit in str(num)) def is_reachable(positions, x, y): current_pos = positions[x - 1] target_pos = positions[y - 1] for i in range(x, y): next_pos = positions[i] if sum_of_digits(next_pos) <= sum_of_digits(current_pos): r...
from solution import process_queries def test_single_jump_reachable(): n = 5 q = 1 positions = [32, 45, 56, 78, 67] queries = [(1, 3)] assert process_queries(n, q, positions, queries) == ["Yes"] def test_single_jump_not_reachable(): n = 5 q = 1 positions = [32, 45, 56, 78, 67] quer...
[ { "docstring": null, "function_declaration": "def sum_of_digits(num):", "function_name": "sum_of_digits", "parameter_list": "(num)" }, { "docstring": null, "function_declaration": "def is_reachable(positions, x, y):", "function_name": "is_reachable", "parameter_list": "(positions...
[ 0, 0, 0, 0, 1 ]
1
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def sum_of_digits(number):\n return sum(int(digit) for digit in str(number))\n\ndef can_reach(positions, x, y):\n x -= 1 # Convert to 0-based index\n ...
trial_gpt4o_4
{ "original_instruction": "Turtle Races organizes a unique race where turtles compete on a track represented by an array of integers. Each integer in the array signifies the position on the track. Turtles can only advance to positions with higher integers that are directly reachable. A position `j` is directly reacha...
0.558958
Codeforces_29270
C
[ "sum_of_digits", "is_reachable", "process_queries" ]
3
[ [ "is_reachable", "sum_of_digits" ], [ "process_queries", "is_reachable" ] ]
2
[ "process_queries" ]
false
[]
false
pytest
true
[]
true
ecc00c98b24cc82ec4880ab3a678ddbd8864862a
114c1f48bf7e6d9a2d19974929ba744db313a8d0
v1.0
complete
Codeforces
Codeforces_28155_C
from typing import List, Tuple def calculate_prefix_sums(arr: List[int]) -> List[int]: """ Calculate and return the prefix sum array for the given array. >>> calculate_prefix_sums([1, 2, 3, 4, 5]) == [0, 1, 3, 6, 10, 15] """ def query_subarray_sum(prefix_sums: List[int], l: int, r: int) -> int: ...
def calculate_prefix_sums(arr): """ Calculate and return the prefix sum array for the given array. """ n = len(arr) prefix_sums = [0] * (n + 1) for i in range(1, n + 1): prefix_sums[i] = prefix_sums[i - 1] + arr[i - 1] return prefix_sums def query_subarray_sum(prefix_sums, l, r): ...
from solution import calculate_prefix_sums, query_subarray_sum, sum_of_subarrays def test_calculate_prefix_sums(): assert calculate_prefix_sums([1, 2, 3, 4, 5]) == [0, 1, 3, 6, 10, 15] def test_query_subarray_sum(): prefix_sums = calculate_prefix_sums([1, 2, 3, 4, 5]) assert query_subarray_sum(prefix_sums...
[ { "docstring": "Calculate and return the prefix sum array for the given array.", "function_declaration": "def calculate_prefix_sums(arr):", "function_name": "calculate_prefix_sums", "parameter_list": "(arr)" }, { "docstring": "Return the sum of the subarray from index l to r (1-based) using ...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def preprocess_prefix_sum(array):\n \"\"\"\n Preprocess the array to calculate and return the prefix sum array.\n \"\"\"\n n = len(array)\n pre...
trial_gpt4o_1
{ "original_instruction": "You are given an array of integers and a series of queries. Each query asks you to calculate the sum of the elements in a specified subarray. Your task is to answer each query efficiently.\n\nThe first line of input contains two integers, n and q (1 ≤ n, q ≤ 10^5): the number of elements in...
0.605787
Codeforces_28155
C
[ "calculate_prefix_sums", "query_subarray_sum", "sum_of_subarrays" ]
3
[ [ "sum_of_subarrays", "calculate_prefix_sums" ], [ "sum_of_subarrays", "query_subarray_sum" ] ]
2
[]
false
[]
false
pytest
true
[]
true
dbe58ef3bdbd28b2c9729ee8458293d0e3e52118
518e65cb8073881dce0c2f5920403a9071d3dc72
v1.0
complete
Codeforces
Codeforces_29169_C
def rotate_matrix_90_degrees(matrix: List[List[int]]) -> List[List[int]]: """ Rotate the given n x n matrix 90 degrees clockwise. >>> rotate_matrix_90_degrees([[1, 2], [3, 4]]) [[3, 1], [4, 2]] """ def row_differences(rotated_matrix: List[List[int]]) -> List[int]: """ Calculate the difference ...
def rotate_matrix_90_degrees(matrix): n = len(matrix) rotated_matrix = [[0] * n for _ in range(n)] for i in range(n): for j in range(n): rotated_matrix[j][n-1-i] = matrix[i][j] return rotated_matrix def row_differences(rotated_matrix): differences = [] for row in rotated_mat...
from solution import matrix_operations, rotate_matrix_90_degrees, row_differences def test_matrix_operations_3x3(): matrix = [ [1, 2, 3], [4, 5, 6], [7, 8, 9] ] result = matrix_operations(3, matrix) assert result == [6, 6, 6] def test_rotate_matrix_90_degrees_2x2(): matrix ...
[ { "docstring": null, "function_declaration": "def rotate_matrix_90_degrees(matrix):", "function_name": "rotate_matrix_90_degrees", "parameter_list": "(matrix)" }, { "docstring": null, "function_declaration": "def row_differences(rotated_matrix):", "function_name": "row_differences", ...
[ 0, 0, 0, 0, 0, 0, 1, 0, 1, 1 ]
3
hard
0.3
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def matrix_operations(n, matrix):\n \"\"\"\n Rotates the matrix 90 degrees clockwise and returns a list of differences\n between maximum and minimum ...
trial_gpt4o_9
{ "original_instruction": "Eric is passionate about competitive programming and loves challenges involving logic and optimization. Recently, he encountered an intriguing problem related to matrix operations. He needs your help to solve it.\n\nEric has an n x n matrix filled with integers. He needs to perform the foll...
0.551257
Codeforces_29169
C
[ "rotate_matrix_90_degrees", "row_differences", "matrix_operations" ]
3
[ [ "matrix_operations", "rotate_matrix_90_degrees" ], [ "matrix_operations", "row_differences" ] ]
2
[]
false
[]
false
pytest
true
[]
true
507f494f1a03d09a334a6cdcb391e8a68c82b5e0
28e0547e4db1da03f66cff83588608fefc51df47
v1.0
complete
Codeforces
Codeforces_28520_C
def count_inversions(arr): """ Helper function to count the number of inversions in the array using a modified merge sort algorithm. """ if len(arr) < 2: return arr, 0 mid = len(arr) // 2 left, left_inv = count_inversions(arr[:mid]) right, right_inv = count_inversions(arr[mid:])...
def count_inversions(arr): """ Helper function to count the number of inversions in the array using a modified merge sort algorithm. """ if len(arr) < 2: return arr, 0 mid = len(arr) // 2 left, left_inv = count_inversions(arr[:mid]) right, right_inv = count_inversions(arr[mid:])...
def test_minimum_swaps(): assert minimum_swaps(2, [(5, [5, 4, 3, 2, 1]), (4, [1, 3, 2, 4])]) == [10, 1] assert minimum_swaps(1, [(3, [3, 1, 2])]) == [2] assert minimum_swaps(1, [(4, [4, 3, 2, 1])]) == [6] assert minimum_swaps(1, [(5, [1, 2, 3, 4, 5])]) == [0] assert minimum_swaps...
[ { "docstring": "Helper function to count the number of inversions in the array\nusing a modified merge sort algorithm.", "function_declaration": "def count_inversions(arr):", "function_name": "count_inversions", "parameter_list": "(arr)" }, { "docstring": "Helper function to merge two halves...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def count_inversions(arr):\n if len(arr) < 2:\n return 0\n mid = len(arr) // 2\n left = arr[:mid]\n right = arr[mid:]\n\n inversions = c...
trial_gpt4o_2
{ "original_instruction": "You are given an array `a` consisting of `n` integers. You need to perform a series of swaps to sort the array in non-decreasing order. In a single swap, you can take two adjacent elements `ai` and `ai+1` and swap them if the element `ai` is greater than `ai+1`.\n\nYour task is to determine...
0.736311
Codeforces_28520
C
[ "count_inversions", "merge_and_count", "minimum_swaps" ]
3
[ [ "count_inversions", "merge_and_count" ], [ "minimum_swaps", "count_inversions" ] ]
2
[]
false
[]
false
pytest
false
[]
true
1c84a17e3ae9def85df1757020ac89e33cf5fc56
10321f59b0145182b672eb8bbeef7b0f634b5bf5
v1.0
complete
Codeforces
Codeforces_28413_C
def calculate_rolling_sums(arr): """ Given an array of integers, this function returns the rolling sum array. """ # Your code here pass def query_rolling_sums(rolling_sums, queries): """ Given a rolling sum array and a list of queries, this function returns the results of the queries. "...
def calculate_rolling_sums(arr): """ Given an array of integers, this function returns the rolling sum array. """ rolling_sums = [] current_sum = 0 for num in arr: current_sum += num rolling_sums.append(current_sum) return rolling_sums def query_rolling_sums(rolling_sums, qu...
from solution import calculate_rolling_sums, query_rolling_sums, process_input def test_calculate_rolling_sums(): assert calculate_rolling_sums([1, 2, 3, 4]) == [1, 3, 6, 10] assert calculate_rolling_sums([5, 10, 15]) == [5, 15, 30] assert calculate_rolling_sums([1]) == [1] assert calculate_rolling_sum...
[ { "docstring": "Given an array of integers, this function returns the rolling sum array.", "function_declaration": "def calculate_rolling_sums(arr):", "function_name": "calculate_rolling_sums", "parameter_list": "(arr)" }, { "docstring": "Given a rolling sum array and a list of queries, this...
[ 0, 0, 0, 0, 0, 1, 0, 0, 0, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def rolling_sum_sequence(n, arr, queries):\n # Calculate the rolling sum array\n rolling_sum = [0] * n\n rolling_sum[0] = arr[0]\n for i in range(...
trial_gpt4o_5
{ "original_instruction": "The International Code Conference is in full swing, and one of the main events is the Rolling Numbers competition. Participants have been challenged to roll up their sleeves and write a program to calculate the cumulative sum sequence known as the \"rolling sum.\" The rolling sum is a seque...
0.572398
Codeforces_28413
C
[ "calculate_rolling_sums", "query_rolling_sums", "process_input" ]
3
[ [ "process_input", "calculate_rolling_sums" ], [ "process_input", "query_rolling_sums" ] ]
2
[ "process_input" ]
false
[]
false
pytest
true
[]
true
afd8999172d4f6ff82a001a2120a81a7c72b8158
a5c667c68115814fb1f250908286ac4774a2cdd5
v1.0
complete
Codeforces
Codeforces_29054_C
from collections import defaultdict, deque from typing import List, Tuple def find_tree_diameter(n: int, edges: List[Tuple[int, int, int]]) -> int: """ Finds the diameter of the tree. Args: n: An integer, the number of nodes in the tree. edges: A list of tuples, each containing three integers (u, ...
from collections import deque, defaultdict def find_furthest_node(start_node, graph, n): """ Perform BFS to find the furthest node and its distance from the start_node. """ distances = [-1] * (n + 1) distances[start_node] = 0 queue = deque([start_node]) while queue: node = queu...
def test_find_tree_diameter(): # Test case from the problem statement n = 5 edges = [ (1, 2, 3), (2, 3, 4), (3, 4, 5), (4, 5, 6) ] assert find_tree_diameter(n, edges) == 18 def test_simple_case(): # Simple case: a small tree with 2 nodes n = 2 edges = [ ...
[ { "docstring": "Perform BFS to find the furthest node and its distance from the start_node.", "function_declaration": "def find_furthest_node(start_node, graph, n):", "function_name": "find_furthest_node", "parameter_list": "(start_node, graph, n)" }, { "docstring": "Finds the diameter of th...
[ 0, 0, 1 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "import sys\nfrom collections import defaultdict, deque\n\ndef find_farthest(node, tree):\n visited = {}\n for n in tree:\n visited[n] = False\n\n...
trial_gpt4o_2
{ "original_instruction": "You are given a tree (a connected graph with n nodes and n-1 edges) with weights on its edges. The distance between two nodes in the tree is defined as the sum of weights on the path connecting them. Your task is to find the maximum distance between any two nodes in the tree.\n\n### Input\n...
0.704427
Codeforces_29054
C
[ "find_furthest_node", "find_tree_diameter" ]
2
[ [ "find_tree_diameter", "find_furthest_node" ] ]
1
[]
false
[]
false
pytest
false
[]
true
053a6cbe0676142c51446e7ef3e51f733ef8cbf2
2f2681c40c8476f23f0c63113cc639767d7f90d3
v1.0
complete
Codeforces
Codeforces_28552_C
from collections import defaultdict, deque def bfs_capacity(graph, residual, source, sink, parent): visited = {k: False for k in graph} queue = deque([source]) visited[source] = True while queue: u = queue.popleft() for v in graph[u]: if not visited[v] and residual[u][v] >...
from collections import defaultdict, deque def bfs_capacity(graph, residual, source, sink, parent): visited = {k: False for k in graph} queue = deque([source]) visited[source] = True while queue: u = queue.popleft() for v in graph[u]: if not visited[v] and residual[u][v] >...
def test_given_example(): assert max_water_flow(5, 7, [ (1, 2, 10), (1, 3, 5), (2, 3, 15), (2, 4, 20), (3, 4, 10), (3, 5, 5), (4, 5, 10) ]) == 15 def test_no_path(): assert max_water_flow(3, 1, [ (1, 2, 5) ]) == -1 def test_another_case()...
[ { "docstring": null, "function_declaration": "def bfs_capacity(graph, residual, source, sink, parent):", "function_name": "bfs_capacity", "parameter_list": "(graph, residual, source, sink, parent)" }, { "docstring": null, "function_declaration": "def edmonds_karp_max_flow(graph, source, ...
[ 0, 0, 0, 1 ]
1
hard
0.25
{ "trial_gpt4o_0": null, "trial_gpt4o_1": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared1_results_combined.jsonl", "solution_code": "from collections import defaultdict, deque\n\nclass Graph:\n def __init__(self, n):\n self.nodes = n\n self.graph = ...
trial_gpt4o_4
{ "original_instruction": "In a distant land, there is a kingdom called Arboleth, known for its lush gardens and intricate networks of fountains connected by pipes. The kingdom's primary water supply comes from a single source reservoir located at the entrance of the garden.\n\nThe garden can be represented as a conn...
0.634462
Codeforces_28552
C
[ "bfs_capacity", "edmonds_karp_max_flow", "max_water_flow" ]
3
[ [ "edmonds_karp_max_flow", "bfs_capacity" ], [ "max_water_flow", "edmonds_karp_max_flow" ] ]
2
[]
false
[]
false
pytest
false
[]
true
1ac2f10cd59337a55085ef0e565ab1c30ad686cc
f92f180f7af102ddfef948a4424f61f610a6bdb7
v1.0
complete
Codeforces
Codeforces_29512_C
def find_shortest_paths(input_data: str) -> List[int]: """ Find the shortest path from the top-left to the bottom-right corner of the grid. Example: >>> find_shortest_paths('2\\n4 4\\nOXOO\\nOOOO\\nXOXO\\nOOOO\\n3 3\\nOXO\\nXOX\\nOXO\\n') [6, -1] """
from collections import deque def shortest_path(grid): n = len(grid) m = len(grid[0]) if grid[0][0] == 'X' or grid[n-1][m-1] == 'X': return -1 directions = [(0, 1), (1, 0), (0, -1), (-1, 0)] queue = deque([(0, 0, 0)]) # (x, y, distance) visited = set((0, 0)) while queue: ...
from solution import find_shortest_paths def test_shortest_path(): input_data = '2\n4 4\nOXOO\nOOOO\nXOXO\nOOOO\n3 3\nOXO\nXOX\nOXO\n' expected_output = [6, -1] assert find_shortest_paths(input_data) == expected_output def test_no_possible_path(): input_data = '1\n3 3\nOXO\nXOX\nOXO\n' expected_ou...
[ { "docstring": null, "function_declaration": "def shortest_path(grid):", "function_name": "shortest_path", "parameter_list": "(grid)" }, { "docstring": null, "function_declaration": "def process_cases(test_cases):", "function_name": "process_cases", "parameter_list": "(test_cases...
[ 0, 0, 1 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "from collections import deque\n\ndef shortest_path(n, m, grid):\n if grid[0][0] == 'X' or grid[n - 1][m - 1] == 'X':\n return -1 # Start or end is ...
trial_gpt4o_2
{ "original_instruction": "Alice is a big fan of puzzles and recently she stumbled upon a peculiar grid problem. The grid is an n x m matrix consisting of only two characters: 'X' and 'O'. An 'X' represents an obstacle, while an 'O' represents an open space.\n\nAlice's goal is to navigate from the top-left corner of ...
0.693732
Codeforces_29512
C
[ "shortest_path", "process_cases", "parse_input", "find_shortest_paths" ]
4
[ [ "find_shortest_paths", "parse_input" ], [ "find_shortest_paths", "process_cases" ], [ "process_cases", "shortest_path" ] ]
3
[ "process_cases", "parse_input" ]
false
[]
false
pytest
true
[]
true
8f1502e5bcd8686e245b2bb07d869856c102801e
eb46e57bc76691510e8153caccbea773ba9594e3
v1.0
complete
Codeforces
Codeforces_29231_C
def treasure_hunt(M: int, N: int, grid: List[str]) -> int: """Find the minimum number of steps required to reach the treasure from the starting point in the grid. Return -1 if no path exists. Args: M: int - number of rows in the grid. N: int - number of columns in the grid. grid: List[str] ...
from collections import deque def find_shortest_path(grid): M = len(grid) N = len(grid[0]) # Directions for moving up, down, left, and right directions = [(-1, 0), (1, 0), (0, -1), (0, 1)] # Find starting position start = None for i in range(M): for j in range(N): ...
from solution import treasure_hunt def test_treasure_hunt(): grid1 = [ "S...#", ".#.##", ".#..#", "..##.", "...T." ] assert treasure_hunt(5, 5, grid1) == 7 grid2 = [ "S.#.", "####", "..T#" ] assert treasure_hunt(3, 4, grid2) == -1...
[ { "docstring": null, "function_declaration": "def find_shortest_path(grid):", "function_name": "find_shortest_path", "parameter_list": "(grid)" }, { "docstring": null, "function_declaration": "def treasure_hunt(M, N, grid):", "function_name": "treasure_hunt", "parameter_list": "(...
[ 0, 1, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "from collections import deque\n\ndef min_steps_to_treasure(grid):\n rows = len(grid)\n cols = len(grid[0])\n \n # Helper function to find the star...
trial_gpt4o_1
{ "original_instruction": "Jenny is organizing a treasure hunt for her friends, and she has created a map to guide them to the treasure. The map is represented by a grid of characters with `M` rows and `N` columns. Each cell in the grid can be one of the following:\n\n- `.`: an empty cell.\n- `S`: the starting point....
0.63997
Codeforces_29231
C
[ "find_shortest_path", "treasure_hunt" ]
2
[ [ "treasure_hunt", "find_shortest_path" ] ]
1
[]
false
[]
false
pytest
true
[]
true
8e6935533c14507e1ac591270a7b086b11600d5d
ed3ec3a56173271c7ea4d2f26296f6b7dab53dd1
v1.0
complete
Codeforces
Codeforces_29446_C
def plant_apple_trees(n: int, m: int) -> List[str]: """ Returns a n x m grid with apple trees ('T') placed such that no two apple trees are adjacent vertically, horizontally, or diagonally. >>> plant_apple_trees(3, 3) ['T.T', '.T.', 'T.T'] >>> plant_apple_trees(2, 2) ['T.', '.T'] >>> pl...
def plant_apple_trees(n, m): """ Returns a n x m grid with apple trees ('T') placed such that no two apple trees are adjacent vertically, horizontally, or diagonally. """ grid = [['.'] * m for _ in range(n)] for i in range(n): for j in range(m): # Place a tree if it does...
from solution import plant_apple_trees def test_3x3_grid(): result = plant_apple_trees(3, 3) expected = [ 'T.T', '.T.', 'T.T' ] assert result == expected def test_2x2_grid(): result = plant_apple_trees(2, 2) expected = [ 'T.', '.T' ] assert resul...
[ { "docstring": "Returns a n x m grid with apple trees ('T') placed such that\nno two apple trees are adjacent vertically, horizontally, or diagonally.", "function_declaration": "def plant_apple_trees(n, m):", "function_name": "plant_apple_trees", "parameter_list": "(n, m)" }, { "docstring": ...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def plant_apple_trees(n, m):\n \"\"\"\n Generate a field layout of size n x m with apple trees ('T')\n placed such that no two apple trees are adjace...
trial_gpt4o_2
{ "original_instruction": "Farmer Charlie has a rectangular field with dimensions n (length) and m (width). He wants to plant apple trees in the field, but due to space and soil restrictions, the trees need to be planted in a pattern.\n\nThe field is represented as a 2D grid of size n x m. Each cell in the grid can e...
0.594431
Codeforces_29446
C
[ "plant_apple_trees", "print_apple_trees_layout" ]
2
[ [ "print_apple_trees_layout", "plant_apple_trees" ] ]
1
[]
false
[]
false
pytest
true
[]
true
638be1a087a54b06e61c29c4a7d7769b6747590f
5a93bb6797a6330133208ca59c56cf40da063c34
v1.0
complete
Codeforces
Codeforces_29226_C
def garland_beauty_count(garlands): """ Given a list of garlands, computes the beauty of each garland. Args: - garlands (List[str]): List of garland strings. Returns: - List[int]: List of beauty values for each garland. """ # Your code here def process_garlands(t, garland_list): ...
def garland_beauty_count(garlands): """ Given a list of garlands, computes the beauty of each garland. Args: - garlands (List[str]): List of garland strings. Returns: - List[int]: List of beauty values for each garland. """ result = [] for s in garlands: max_beauty = 1 ...
from solution import process_garlands def test_example_case(): assert process_garlands(3, ['aaabb', 'abcd', 'bbbbbb']) == [3, 1, 6] def test_single_characters(): assert process_garlands(2, ['a', 'b']) == [1, 1] def test_all_identical_characters(): assert process_garlands(1, ['cccc']) == [4] def test_alt...
[ { "docstring": "Given a list of garlands, computes the beauty of each garland.\n\nArgs:\n- garlands (List[str]): List of garland strings.\n\nReturns:\n- List[int]: List of beauty values for each garland.", "function_declaration": "def garland_beauty_count(garlands):", "function_name": "garland_beauty_co...
[ 1, 0, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def garland_beauty_count(garlands):\n \"\"\"\n Given a list of garlands, computes the beauty of each garland.\n \n Args:\n - garlands (List[str...
trial_gpt4o_0
{ "original_instruction": "In the distant land of Algoria, people celebrate their grand ceremonies with beautiful garlands. A garland in Algoria is represented as a string of lowercase English letters. The beauty of the garland is determined by the longest substring of consecutively identical characters within it.\n\...
0.534135
Codeforces_29226
C
[ "garland_beauty_count", "process_garlands" ]
2
[ [ "process_garlands", "garland_beauty_count" ] ]
1
[]
false
[]
false
pytest
true
[]
true
481657f13f1e7fe28e5c63b9bd95bcce33ed58dd
ec6c1245d0eadfbaf5fb4855da34dfade7361505
v1.0
complete
Codeforces
Codeforces_29483_C
def longest_common_subsequence(strings: List[str]) -> int: """ Given a list of signal strings, find the length of the longest common subsequence shared by all the signals. Example: >>> longest_common_subsequence(["abac", "cab", "abc"]) 2 >>> longest_common_subsequence(["abc", "def", "ghi"])...
def lcs(X , Y): """ Returns the length of the Longest Common Subsequence (LCS) of X and Y """ m = len(X) n = len(Y) L = [[None] * (n + 1) for i in range(m + 1)] for i in range(m + 1): for j in range(n + 1): if i == 0 or j == 0: L[i][j] = 0 ...
from solution import longest_common_subsequence, get_lcs_string def test_lcs_with_example(): strings = ["abac", "cab", "abc"] assert longest_common_subsequence(strings) == 2 def test_lcs_with_no_common_subsequence(): strings = ["abc", "def", "ghi"] assert longest_common_subsequence(strings) == 0 def ...
[ { "docstring": "Returns the length of the Longest Common Subsequence (LCS) of X and Y", "function_declaration": "def lcs(X, Y):", "function_name": "lcs", "parameter_list": "(X, Y)" }, { "docstring": "Returns the length of the longest common subsequence among a list of strings.", "functio...
[ 0, 0, 0, 0, 1 ]
1
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def lcs_length(signal_list):\n \"\"\"\n Returns the length of the longest common subsequence among the signal strings in signal_list.\n \"\"\"\n d...
trial_gpt4o_4
{ "original_instruction": "Bob is a scientist working on a project that involves tracking migrating birds. Each bird emits a unique series of signals during its flight, which can be represented as a string of lowercase English letters. Bob has collected several signal strings and wants to determine the longest common...
0.675057
Codeforces_29483
C
[ "lcs", "longest_common_subsequence", "get_lcs_string" ]
3
[ [ "longest_common_subsequence", "get_lcs_string" ] ]
1
[]
false
[]
false
pytest
true
[]
true
d5c2bcc14e471be66f17a38cdc134246b1a782dd
a6bda0e071e8b1095b986c3176cd26f04287151b
v1.0
complete
Codeforces
Codeforces_29518_C
import math from typing import List, Tuple def calculate_distance(p1: Tuple[int, int], p2: Tuple[int, int]) -> int: return round(math.sqrt((p1[0] - p2[0])**2 + (p1[1] - p2[1])**2)) def tsp_minimum_cost(locations: List[Tuple[int, int]]) -> int: """ Calculate the minimum total distance for the delivery truck to...
import math import itertools def calculate_distance(p1, p2): return round(math.sqrt((p1[0] - p2[0])**2 + (p1[1] - p2[1])**2)) def tsp_minimum_cost(locations): N = len(locations) all_distances = [[calculate_distance(locations[i], locations[j]) for j in range(N)] for i in range(N)] # memoization ta...
import pytest from solution import tsp_minimum_cost def test_tsp_minimum_cost_4_points(): locations = [(0, 0), (0, 1), (1, 0), (1, 1)] assert tsp_minimum_cost(locations) == 4 def test_tsp_minimum_cost_3_points(): locations = [(0, 0), (3, 4), (6, 8)] assert tsp_minimum_cost(locations) == 20 def test_t...
[ { "docstring": null, "function_declaration": "def calculate_distance(p1, p2):", "function_name": "calculate_distance", "parameter_list": "(p1, p2)" }, { "docstring": null, "function_declaration": "def tsp_minimum_cost(locations):", "function_name": "tsp_minimum_cost", "parameter_...
[ 0, 0, 0, 0, 0, 0, 0, 0, 1, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "import math\nfrom itertools import permutations\n\ndef calculate_distance(p1, p2):\n \"\"\"\n Calculate the Euclidean distance between two points p1 and...
trial_gpt4o_8
{ "original_instruction": "You are designing a system for a popular delivery service to optimize their route planning. The goal is to minimize the total distance traveled by the delivery truck in a day.\n\nGiven a list of delivery locations, represented as coordinates on a 2D plane, your task is to calculate the shor...
0.650428
Codeforces_29518
C
[ "calculate_distance", "tsp_minimum_cost" ]
2
[ [ "tsp_minimum_cost", "calculate_distance" ] ]
1
[]
false
[]
false
pytest
true
[]
true
ac162b0ed7d5d6cdefe4fbc758698ca1148882b4
929cad23dd88adf799bd7dccc86a4b3d4325da5a
v1.0
complete
Codeforces
Codeforces_28175_C
class Node: def __init__(self, value=None): self.value = value self.left = None self.right = None def build_tree(nodes): if not nodes: return None node_dict = {i: Node(nodes[i][0]) for i in range(len(nodes))} for i in range(len(nodes)): value, left_index, right_i...
class Node: def __init__(self, value=None): self.value = value self.left = None self.right = None def build_tree(nodes): if not nodes: return None node_dict = {i: Node(nodes[i][0]) for i in range(len(nodes))} for i in range(len(nodes)): value, left_index, right_i...
def test_bst_deepest_level_sum_valid_bst(): n = 5 nodes = [ (10, 1, 2), (5, -1, -1), (15, 3, 4), (12, -1, -1), (20, -1, -1) ] assert bst_deepest_level_sum(n, nodes) == 32 def test_bst_deepest_level_sum_invalid_bst(): n = 3 nodes = [ (10, 1, 2), ...
[]
[ 0, 1, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "class TreeNode:\n def __init__(self, value):\n self.value = value\n self.left = None\n self.right = None\n\ndef build_tree(nodes):\n ...
trial_gpt4o_1
{ "original_instruction": "You are given a binary search tree (BST) with n nodes, each node containing a unique integer value. A BST is a binary tree where each node has at most two children, and for every node, all the nodes in its left subtree have smaller values and all the nodes in its right subtree have larger v...
0.569167
Codeforces_28175
C
[ "build_tree", "is_bst", "deepest_level_sum", "bst_deepest_level_sum" ]
4
[ [ "bst_deepest_level_sum", "build_tree" ], [ "bst_deepest_level_sum", "deepest_level_sum" ], [ "bst_deepest_level_sum", "is_bst" ] ]
3
[]
false
[ "Node" ]
true
pytest
false
[]
true
d023df600471f6c3260c0eba5959fee161c42d62
3c264b2ef521eb2f1a46a549eb3489478d1b8508
v1.0
complete
Codeforces
Codeforces_29010_C
def preprocess(s): # Create a prefix sum array for each character from 'a' to 'z' pass def count_char_in_substring(char_prefix, l, r, c): # Use the preprocessed prefix sum array to count occurrences of c in s[l-1:r] pass def process_operations(s, queries): """ Process a string and perform a list o...
def preprocess(s): # Create a prefix sum array for each character from 'a' to 'z' n = len(s) char_prefix = {chr(c): [0] * (n + 1) for c in range(ord('a'), ord('z') + 1)} for i in range(n): for c in char_prefix: char_prefix[c][i + 1] = char_prefix[c][i] + (1 if s[i] == c else 0) r...
from solution import process_operations def test_example_case(): s = "ababdcda" queries = [(1, 4, 'a'), (2, 7, 'b'), (3, 8, 'd')] assert process_operations(s, queries) == [2, 2, 2] def test_single_character_string(): s = "a" queries = [(1, 1, 'a'), (1, 1, 'b')] assert process_operations(s, que...
[ { "docstring": null, "function_declaration": "def preprocess(s):", "function_name": "preprocess", "parameter_list": "(s)" }, { "docstring": null, "function_declaration": "def count_char_in_substring(char_prefix, l, r, c):", "function_name": "count_char_in_substring", "parameter_l...
[ 1, 0, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def preprocess(s):\n # Create a prefix sum array for each character from 'a' to 'z'\n n = len(s)\n char_prefix = {chr(c): [0] * (n + 1) for c in rang...
trial_gpt4o_0
{ "original_instruction": "Alice loves string manipulation and recently she came up with a new challenge for Bob. She gives Bob a string `s` of length `n` consisting of lowercase English letters. She also gives him a list of `q` operations. Each operation is of the form `l r c`, instructing Bob to count the number of...
0.730785
Codeforces_29010
C
[ "preprocess", "count_char_in_substring", "process_operations" ]
3
[ [ "process_operations", "count_char_in_substring" ], [ "process_operations", "preprocess" ] ]
2
[]
false
[]
false
pytest
true
[]
true
6e4c9a2120df308c8a889f9c58f474fbc3f93779
29a49ef2d34111d82b63a0ebda805c77b35dccce
v1.0
complete
Codeforces
Codeforces_29497_C
from typing import List def max_score_in_grid(grid: List[List[int]]) -> int: """ Returns the maximum achievable score in the grid, moving only right or down from the top-left corner to the bottom-right corner. >>> max_score_in_grid([[1, -2, 3], [-4, 5, -6], [7, 8, 9]]) == 21 >>> max_score_in_grid([[5]...
def max_score_in_grid(grid): """ Returns the maximum achievable score in the grid, moving only right or down from the top-left corner to the bottom-right corner. """ n = len(grid) m = len(grid[0]) # Initialize dp table with the same size as grid dp = [[0] * m for _ in range(n)] ...
from solution import max_score_in_grid, get_max_score_from_input def test_max_score_basic(): grid = [ [1, -2, 3], [-4, 5, -6], [7, 8, 9] ] assert max_score_in_grid(grid) == 21 def test_max_score_single_cell(): grid = [ [5] ] assert max_score_in_grid(grid) == 5 ...
[ { "docstring": "Returns the maximum achievable score in the grid, moving only right or down from the top-left corner to the bottom-right corner.", "function_declaration": "def max_score_in_grid(grid):", "function_name": "max_score_in_grid", "parameter_list": "(grid)" }, { "docstring": null, ...
[ 0, 0, 0, 0, 0, 0, 0, 0, 1 ]
1
hard
0.111
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def max_score_in_magic_grid(grid):\n n = len(grid)\n m = len(grid[0])\n \n # Create a DP table to store the maximum achievable score up to each ce...
trial_gpt4o_9
{ "original_instruction": "Hogwarts is organizing a new game for its students called \"Magic Grid\". The grid is a 2D matrix consisting of n rows and m columns. Each cell in the grid has a certain score associated with it, which can be positive or negative. The goal of the game is to move from the top-left corner of ...
0.654426
Codeforces_29497
C
[ "max_score_in_grid", "get_max_score_from_input" ]
2
[ [ "get_max_score_from_input", "max_score_in_grid" ] ]
1
[]
false
[]
false
pytest
true
[]
true
eec30a1709a131e8558861cef9717d42956fa976
daf927ae395c9ce5a6eb8796c774003f031628c4
v1.0
complete
Codeforces
Codeforces_29897_C
def process_input_and_get_result(n: int, k: int, arr: List[int]) -> int: """ Determine whether it is possible to sort the list in non-decreasing order within at most k swaps. If it is possible, return the minimum number of swaps needed. Otherwise, return -1. >>> process_input_and_get_result(5, 2, [4, ...
def min_swaps_to_sort(arr, k): """ Determine the minimum number of swaps needed to sort the array in non-decreasing order within the allowed number of swaps. """ n = len(arr) # Create a pair of (value, index) and sort it by value sorted_arr = sorted([(arr[i], i) for i in range(n)]) visi...
from solution import process_input_and_get_result def test_example_1(): assert process_input_and_get_result(5, 2, [4, 3, 2, 1, 5]) == 2 def test_example_2(): assert process_input_and_get_result(4, 1, [4, 3, 2, 1]) == -1 def test_sorted_list(): assert process_input_and_get_result(5, 0, [1, 2, 3, 4, 5]) ==...
[ { "docstring": "Determine the minimum number of swaps needed to sort the array in \nnon-decreasing order within the allowed number of swaps.", "function_declaration": "def min_swaps_to_sort(arr, k):", "function_name": "min_swaps_to_sort", "parameter_list": "(arr, k)" }, { "docstring": null, ...
[ 0, 0, 0, 0, 1 ]
1
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def min_swaps_to_sort(n, k, arr):\n \"\"\"\n Determine if it is possible to sort the array `arr` in non-decreasing order \n within at most `k` swaps ...
trial_gpt4o_4
{ "original_instruction": "Given a list of integers, arr, you can perform the following operation at most k times: select any two integers, x and y, such that x > y and swap their positions in the list. Your goal is to sort the list in non-decreasing order with the minimum number of swaps, but you cannot perform more...
0.640268
Codeforces_29897
C
[ "min_swaps_to_sort", "process_input_and_get_result" ]
2
[ [ "process_input_and_get_result", "min_swaps_to_sort" ] ]
1
[]
false
[]
false
pytest
true
[]
true
b75b55652d8a7239cd4cdc6d5092f81df9affa53
548aa62e2f3763c7b759cf630758598e7c12cc3d
v1.0
complete
Codeforces
Codeforces_29536_C
from typing import List, Tuple def reorder_graph_to_dag(n: int, m: int, edges: List[Tuple[int, int]]) -> Tuple[str, List[int]]: """ Determines if it is possible to reorder the nodes of a directed graph such that it becomes a directed acyclic graph (DAG), and returns the reordering if possible. :param...
from collections import deque, defaultdict def can_become_dag(n, m, edges): graph = defaultdict(list) in_degree = {i: 0 for i in range(1, n + 1)} for u, v in edges: graph[u].append(v) in_degree[v] += 1 zero_in_degree_queue = deque([node for node in range(1, n + 1) if in_degree...
from solution import reorder_graph_to_dag def test_case_1(): n, m = 6, 6 edges = [ (1, 2), (1, 3), (2, 4), (3, 4), (4, 5), (5, 6) ] assert reorder_graph_to_dag(n, m, edges)[0] == "YES" assert reorder_graph_to_dag(n, m, edges)[1] == [1, 2, 3, 4, 5, 6] ...
[ { "docstring": null, "function_declaration": "def can_become_dag(n, m, edges):", "function_name": "can_become_dag", "parameter_list": "(n, m, edges)" }, { "docstring": null, "function_declaration": "def reorder_graph_to_dag(n, m, edge_list):", "function_name": "reorder_graph_to_dag",...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "from collections import deque, defaultdict\n\ndef topological_sort(n, edges):\n \"\"\"\n Tries to find a topological ordering of the nodes if the graph ...
trial_gpt4o_2
{ "original_instruction": "Tanya loves puzzles, especially those involving graphs. She has a directed graph with `n` nodes and `m` edges. Each node is numbered from `1` to `n`.\n\nTanya wants to know if it is possible to reorder the nodes such that the graph becomes acyclic (i.e., a directed acyclic graph or DAG). Yo...
0.575388
Codeforces_29536
C
[ "can_become_dag", "reorder_graph_to_dag" ]
2
[ [ "reorder_graph_to_dag", "can_become_dag" ] ]
1
[]
false
[]
false
pytest
true
[]
true
8acfb72b2784a2ed4547d9661591172668b1ba21
feb486b139e833044b1449481eb112cb72243827
v1.0
complete
Codeforces
Codeforces_29786_C
def maximum_sum_subrectangle(grid: List[List[int]]) -> int: """ Find the largest sum of numbers in any subrectangle of a grid. >>> maximum_sum_subrectangle([[1, 2, 3], [4, 5, 6], [7, 8, 9]]) 45 >>> maximum_sum_subrectangle([[1, 2, -1, -4, -20], [-8, -3, 4, 2, 1], [3, 8, 10, 1, 3], [-4, -1, 1, 7, -6]...
def maximum_sum_subrectangle(grid): """ Returns the largest sum of numbers in any subrectangle of the grid. """ n = len(grid) m = len(grid[0]) max_sum = float('-inf') for left in range(m): temp = [0] * n for right in range(left, m): for i in range(n): ...
def test_maximum_sum_subrectangle(): grid1 = [ [1, 2, 3], [4, 5, 6], [7, 8, 9] ] assert maximum_sum_subrectangle(grid1) == 45 grid2 = [ [1, 2, -1, -4, -20], [-8, -3, 4, 2, 1], [3, 8, 10, 1, 3], [-4, -1, 1, 7, -6] ] assert maximum_sum_subre...
[ { "docstring": "Returns the largest sum of numbers in any subrectangle of the grid.", "function_declaration": "def maximum_sum_subrectangle(grid):", "function_name": "maximum_sum_subrectangle", "parameter_list": "(grid)" }, { "docstring": "Returns the maximum sum of any contiguous subarray o...
[ 1, 0, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def maximum_sum_subrectangle(grid):\n \"\"\"\n Returns the largest sum of numbers in any subrectangle of the grid.\n \"\"\"\n n = len(grid)\n m...
trial_gpt4o_0
{ "original_instruction": "You are given a grid of size $$$n \\times m$$$ filled with non-negative integers. Your task is to find the largest sum of numbers in any subrectangle of this grid.\n\nA subrectangle is any rectangular part of the grid that can be identified by two pairs of coordinates: top-left ($$$x1, y1$$...
0.604425
Codeforces_29786
C
[ "maximum_sum_subrectangle", "maximum_sum_subarray" ]
2
[ [ "maximum_sum_subrectangle", "maximum_sum_subarray" ] ]
1
[]
false
[]
false
pytest
false
[]
true
f38ac785113c42ccbb914f19b13f1703a1c7b219
9b836fa336c0c065709ba78e30f0038e663f409b
v1.0
complete
Codeforces
Codeforces_29678_C
def is_prime(num: int) -> bool: """ Check if a number is a prime number. >>> is_prime(1) False >>> is_prime(2) True >>> is_prime(17) True >>> is_prime(18) False """ pass def smallest_prime_greater_equal(n: int) -> int: """ Find the smallest prime number that is greater t...
import math def is_prime(num): if num <= 1: return False if num == 2 or 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 s...
from solution import is_prime, smallest_prime_greater_equal def test_is_prime(): assert is_prime(1) == False assert is_prime(2) == True assert is_prime(3) == True assert is_prime(4) == False assert is_prime(17) == True assert is_prime(18) == False def test_smallest_prime_greater_equal(): a...
[ { "docstring": null, "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": null, "function_declaration": "def smallest_prime_greater_equal(n):", "function_name": "smallest_prime_greater_equal", "parameter_list": "(n...
[ 1, 1, 0 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "import math\n\ndef is_prime(num):\n \"\"\"\n Returns True if num is a prime number, else False.\n \"\"\"\n if num <= 1:\n return False\n ...
trial_gpt4o_1
{ "original_instruction": "Bob loves prime numbers and wants to create a prime number puzzle for his friend Alice. The puzzle works as follows:\n\nAlice is given an integer n, and she must compute the smallest prime number that is greater than or equal to n. If n itself is a prime number, then n is the answer.\n\nGiv...
0.763844
Codeforces_29678
C
[ "is_prime", "smallest_prime_greater_equal" ]
2
[ [ "smallest_prime_greater_equal", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
42b39d5f2f7ec3cf699876cf3a4e85c6592d4777
fafd91f8479949fc4b2cdd9088434fe98b766307
v1.0
complete
Codeforces
Codeforces_28640_C
from typing import List, Tuple def count_unique_ips_in_time_range(log_entries: List[Tuple[int, str]], queries: List[Tuple[int, int]]) -> List[int]: """ Counts unique IP addresses in specified time ranges. Parameters: - log_entries: a list of tuples (timestamp, IP_address) - queries: a list of ...
def count_unique_ips_in_time_range(log_entries, queries): """ Counts unique IP addresses in specified time ranges. Parameters: - log_entries: a list of tuples (timestamp, IP_address) - queries: a list of tuples (start_time, end_time) Returns: - A list of integers representing the c...
from solution import process_logs_and_queries def test_example_case(): n = 5 access_logs = [ (1000, "192.168.1.1"), (2000, "192.168.1.2"), (3000, "192.168.1.1"), (4000, "192.168.1.3"), (5000, "192.168.1.2") ] q = 2 query_ranges = [ (1000, 3000), ...
[ { "docstring": "Counts unique IP addresses in specified time ranges.\n\nParameters:\n- log_entries: a list of tuples (timestamp, IP_address)\n- queries: a list of tuples (start_time, end_time)\n\nReturns:\n- A list of integers representing the count of unique IP addresses in each time range.", "function_dec...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def unique_ips_in_range(log_entries, queries):\n \"\"\"\n Returns the number of unique IP addresses within the given time range for each query.\n \n ...
trial_gpt4o_1
{ "original_instruction": "Let’s create a coding assessment question that closely matches the style, length, complexity, and topics covered by the provided examples.\n\nHarold works in a network security team and is responsible for monitoring unauthorized accesses. A monitoring device captures each access attempt and...
0.654637
Codeforces_28640
C
[ "count_unique_ips_in_time_range", "process_logs_and_queries" ]
2
[ [ "process_logs_and_queries", "count_unique_ips_in_time_range" ] ]
1
[]
false
[]
false
pytest
true
[]
true
d88dac43f85184e52e006e9bf2803381ace126c1
8c4eeb88326aa5d4e26c8308106402983d294774
v1.0
complete
Codeforces
Codeforces_29869_C
def maximal_suitable_rectangle(n: int, m: int, grid: List[str]) -> int: """ Determine the maximum possible area of a suitable rectangle in a grid. Args: n: The number of rows in the grid. m: The number of columns in the grid. grid: A list of strings, where each string represents a row of...
def maximal_suitable_rectangle(n, m, grid): max_area = 0 # Convert the grid into a binary representation for easier processing binary_grid = [[1 if cell == 'S' else 0 for cell in row] for row in grid] # List to store heights of each column heights = [0] * m for i in range(n): for j in...
def test_case_single_s_row(): n, m = 1, 5 grid = ['SSSSS'] assert maximal_suitable_rectangle(n, m, grid) == 5 def test_case_single_u_row(): n, m = 1, 5 grid = ['UUUUU'] assert maximal_suitable_rectangle(n, m, grid) == 0 def test_case_single_s_column(): n, m = 5, 1 grid = ['S', 'S', 'S'...
[ { "docstring": null, "function_declaration": "def maximal_suitable_rectangle(n, m, grid):", "function_name": "maximal_suitable_rectangle", "parameter_list": "(n, m, grid)" }, { "docstring": null, "function_declaration": "def max_histogram_area(heights):", "function_name": "max_histog...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def maximal_rectangle_area(grid):\n def largest_histogram_area(heights):\n stack = []\n max_area = 0\n for i, h in enumerate(heights +...
trial_gpt4o_1
{ "original_instruction": "Yan is planning to build a new library in his town, and he has a grid of n x m cells representing potential locations for the library. Each cell in the grid can either be suitable (represented by 'S') or unsuitable (represented by 'U') for building. Yan wants to build the library such that ...
0.714471
Codeforces_29869
C
[ "maximal_suitable_rectangle", "max_histogram_area" ]
2
[ [ "maximal_suitable_rectangle", "max_histogram_area" ] ]
1
[]
false
[]
false
pytest
false
[]
true
952a79a3e97cad30b71647d978fe5670288deed9
4140b29c0263378aa39c036ad7b3a22eeffb849d
v1.0
complete
Codeforces
Codeforces_29429_C
def longest_prime_subsequence_length(n: int, sequence: List[int]) -> int: """ Alice has a favorite sequence consisting of n integers. Since she loves prime numbers, she wants to know the longest contiguous subsequence within her favorite sequence that consists entirely of prime numbers. A prime number...
def is_prime(num): if num <= 1: return False if num <= 3: return True if num % 2 == 0 or num % 3 == 0: return False i = 5 while i * i <= num: if num % i == 0 or num % (i + 2) == 0: return False i += 6 return True def longest_prime_subsequence_...
from solution import longest_prime_subsequence_length def test_all_primes(): assert longest_prime_subsequence_length(5, [2, 3, 5, 7, 11]) == 5 def test_no_primes(): assert longest_prime_subsequence_length(5, [1, 4, 6, 8, 10]) == 0 def test_primes_in_middle(): assert longest_prime_subsequence_length(10, [...
[ { "docstring": null, "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": null, "function_declaration": "def longest_prime_subsequence_length(n, sequence):", "function_name": "longest_prime_subsequence_length", "pa...
[ 0, 0, 0, 0, 1 ]
1
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(num):\n \"\"\"\n Check if a number is a prime number.\n \"\"\"\n if num <= 1:\n return False\n if num <= 3:\n return...
trial_gpt4o_4
{ "original_instruction": "Alice has a favorite sequence consisting of $$$n$$$ integers. Since she loves prime numbers, she wants to know the longest contiguous subsequence within her favorite sequence that consists entirely of prime numbers. A prime number is a natural number greater than 1 that has no positive divi...
0.664519
Codeforces_29429
C
[ "is_prime", "longest_prime_subsequence_length" ]
2
[ [ "longest_prime_subsequence_length", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
241826c54d53ad8e52b49adb6d9322b0a0b86c3e
6f684db87f999810d8c784e3085153d720da88d1
v1.0
complete
Codeforces
Codeforces_29892_C
def is_prime(n: int) -> bool: """ Check if a number is prime. >>> is_prime(2) True >>> is_prime(10) False >>> is_prime(13) True """ pass def reverse_number(n: int) -> int: """ Reverse the digits of a number. >>> reverse_number(123) 321 >>> reverse_number(100) 1 ...
def is_prime(n): if n <= 1: return False if n == 2: return True if n % 2 == 0: return False p = 3 while p * p <= n: if n % p == 0: return False p += 2 return True def reverse_number(n): return int(str(n)[::-1]) def super_primes(N): re...
from solution import super_primes, format_super_primes def test_is_prime(): assert is_prime(2) == True assert is_prime(10) == False assert is_prime(13) == True assert is_prime(31) == True assert is_prime(97) == True assert is_prime(1) == False def test_reverse_number(): assert reverse_numb...
[ { "docstring": null, "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": null, "function_declaration": "def reverse_number(n):", "function_name": "reverse_number", "parameter_list": "(n)" }, { "docstring": nul...
[ 1, 1, 0 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(n):\n if n <= 1:\n return False\n if n == 2 or n == 3:\n return True\n if n % 2 == 0 or n % 3 == 0:\n return False\...
trial_gpt4o_1
{ "original_instruction": "Bob the Coder is fascinated by algorithms that check a number's primality. However, he recently learned about \"Super Prime\" numbers and wants to write a code to identify them. A \"Super Prime\" is a prime number that, when reversed, is also a prime number (e.g., 13 is a prime number and i...
0.712453
Codeforces_29892
C
[ "is_prime", "reverse_number", "super_primes", "format_super_primes" ]
4
[ [ "format_super_primes", "super_primes" ], [ "super_primes", "is_prime" ], [ "super_primes", "reverse_number" ] ]
3
[]
false
[]
false
pytest
true
[]
true
066bb5e8a1748cc4cd891b88c2b851f245103fb0
d8ff205577a4fb489d86ab5dae5177047f67f5d9
v1.0
complete
Codeforces
Codeforces_29968_C
def sieve_of_eratosthenes(limit): """ Helper function to perform the Sieve of Eratosthenes algorithm and return a list indicating prime status for numbers from 0 to limit. """ is_prime = [True] * (limit + 1) is_prime[0], is_prime[1] = False, False for start in range(2, int(limit ** 0.5) + 1): ...
def sieve_of_eratosthenes(limit): is_prime = [True] * (limit + 1) is_prime[0], is_prime[1] = False, False for start in range(2, int(limit ** 0.5) + 1): if is_prime[start]: for multiple in range(start*start, limit + 1, start): is_prime[multiple] = False return is_prime...
from solution import max_prime_gap def test_max_prime_gap_example1(): assert max_prime_gap(10, 30) == 6 def test_max_prime_gap_example2(): assert max_prime_gap(14, 17) == "No prime gap" def test_max_prime_gap_no_primes_in_range(): assert max_prime_gap(20, 23) == "No prime gap" def test_max_prime_gap_lar...
[ { "docstring": null, "function_declaration": "def sieve_of_eratosthenes(limit):", "function_name": "sieve_of_eratosthenes", "parameter_list": "(limit)" }, { "docstring": null, "function_declaration": "def max_prime_gap(a, b):", "function_name": "max_prime_gap", "parameter_list": ...
[ 1, 0, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def sieve_of_eratosthenes(limit):\n is_prime = [True] * (limit + 1)\n is_prime[0], is_prime[1] = False, False\n for start in range(2, int(limit ** 0....
trial_gpt4o_0
{ "original_instruction": "Jiří is fascinated by prime numbers and their properties. He recently came across the concept of a \"prime gap\". The prime gap between two successive prime numbers is the absolute difference between them.\n\nJiří wants to write a program that, given a range of integers [a, b], computes the...
0.602723
Codeforces_29968
C
[ "sieve_of_eratosthenes", "max_prime_gap" ]
2
[ [ "max_prime_gap", "sieve_of_eratosthenes" ] ]
1
[]
false
[]
false
pytest
true
[]
true
666be8a7be7b9b3be1fadccd7ccedc919ee2ba77
c3be949e2a6350db8ba90a558511e6f63ab89287
v1.0
complete
Codeforces
Codeforces_29484_C
def sieve_of_eratosthenes(max_num: int) -> List[bool]: """ Returns a list of boolean values, where index i indicates whether i is prime. Uses the Sieve of Eratosthenes algorithm. """ pass def primes_in_range(a: int, b: int, is_prime: List[bool]) -> List[int]: """ Returns a list of prime num...
def sieve_of_eratosthenes(max_num): """ Returns a list of boolean values, where index i indicates whether i is prime. Uses the Sieve of Eratosthenes algorithm. """ is_prime = [True] * (max_num + 1) is_prime[0] = is_prime[1] = False # 0 and 1 are not primes p = 2 while p * p <= max_num:...
from solution import sieve_of_eratosthenes, primes_in_range, process_test_cases def test_sieve_of_eratosthenes(): is_prime = sieve_of_eratosthenes(10) assert not is_prime[0] assert not is_prime[1] assert is_prime[2] # 2 is prime assert is_prime[3] # 3 is prime assert not is_prime[4] # 4 is n...
[ { "docstring": "Returns a list of boolean values, where index i indicates whether i is prime.\nUses the Sieve of Eratosthenes algorithm.", "function_declaration": "def sieve_of_eratosthenes(max_num):", "function_name": "sieve_of_eratosthenes", "parameter_list": "(max_num)" }, { "docstring": ...
[ 0, 1, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "import math\n\ndef sieve(n):\n \"\"\"\n Returns a list of primes up to n using the Sieve of Eratosthenes.\n \"\"\"\n is_prime = [True] * (n+1)\n ...
trial_gpt4o_1
{ "original_instruction": "Jasmin has recently learned about prime numbers and wants to verify if her understanding is correct. She plans to write a program that identifies prime numbers in a given range and also counts the total number of prime numbers within that range. A prime number is a positive integer greater ...
0.658035
Codeforces_29484
C
[ "sieve_of_eratosthenes", "primes_in_range", "process_test_cases" ]
3
[ [ "process_test_cases", "primes_in_range" ], [ "process_test_cases", "sieve_of_eratosthenes" ] ]
2
[ "process_test_cases" ]
false
[]
false
pytest
true
[]
true
b29f1aba27214c48810da1c478c42d0950344863
d041530299d402a9fa35288189ddeb9f680cc5af
v1.0
complete
Codeforces
Codeforces_29282_C
class TreeNode: def __init__(self, value): self.value = value self.left = None self.right = None def insert_into_sparse_bst(root, value): if root is None: return TreeNode(value) # Insert into the tree in a fashion that maintains the sparse tree properties if value <...
class TreeNode: def __init__(self, value): self.value = value self.left = None self.right = None def insert_into_sparse_bst(root, value): if root is None: return TreeNode(value) # Insert into the tree in a fashion that maintains the sparse tree properties if value <...
from solution import sparse_binary_tree def test_single_test_case(): input_data = [(5, [3, 2, 5, 1, 4])] expected_output = [[3, 2, 1, 5, 4]] assert sparse_binary_tree(input_data, 1) == expected_output def test_multiple_test_cases(): input_data = [(5, [3, 2, 5, 1, 4]), (3, [1, 2, 3])] expected_outp...
[]
[ 0, 1, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "class Node:\n def __init__(self, value):\n self.value = value\n self.left = None\n self.right = None\n \nclass SparseBinaryTree...
trial_gpt4o_1
{ "original_instruction": "Mark is planning to design a special binary tree called Sparse Binary Tree. A Sparse Binary Tree is a binary tree with the following properties:\n\n1. Each node has at most two children.\n2. Every node with a right child must have a left child and the left subtree must not be empty.\n3. The...
0.519724
Codeforces_29282
C
[ "insert_into_sparse_bst", "preorder_traversal", "sparse_binary_tree", "main" ]
4
[ [ "sparse_binary_tree", "insert_into_sparse_bst" ], [ "sparse_binary_tree", "preorder_traversal" ] ]
2
[]
false
[ "TreeNode" ]
true
pytest
true
[]
true
76e3cb17f7300e7bff077a517b9837f4caaf7605
c3ccff0b2b43942f88dffcdc74f02b117172d4e1
v1.0
complete
Codeforces
Codeforces_30099_C
def is_magic_square_possible(n: int) -> (bool, List[List[int]]): """ Given an integer N, check if it's possible to construct a magic square of size NxN. If possible, return a tuple (True, magic_square), otherwise, return (False, []) >>> is_magic_square_possible(3) (True, [[2, 7, 6], [9, 5, 1], [4,...
def is_magic_square_possible(n): if n == 2: return False, [] if n == 1: return True, [[1]] magic_square = [[0] * n for _ in range(n)] row = 0 col = n // 2 num = 1 while num <= n*n: magic_square[row][col] = num num += 1 new_row = (row - 1...
from solution import is_magic_square_possible def test_magic_square_3x3(): possible, square = is_magic_square_possible(3) assert possible == True assert sum(square[0]) == sum(square[1]) == sum(square[2]) == 15 assert sum(row[0] for row in square) == sum(row[1] for row in square) == sum(row[2] for row i...
[ { "docstring": null, "function_declaration": "def is_magic_square_possible(n):", "function_name": "is_magic_square_possible", "parameter_list": "(n)" }, { "docstring": null, "function_declaration": "def print_magic_square(n):", "function_name": "print_magic_square", "parameter_li...
[ 0, 0, 0, 0, 1 ]
1
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def generate_magic_square(N):\n if N == 2:\n return \"NO\", []\n \n magic_square = [[0] * N for _ in range(N)]\n\n num = 1\n i, j = 0, N...
trial_gpt4o_4
{ "original_instruction": "A famous mathematician loves playing with numbers and geometrical shapes in his free time. One day, he came up with an interesting problem and decided to challenge his students.\n\nThe task is to fill an NxN grid with positive integers from 1 to N×N in such a way that each number appears ex...
0.728904
Codeforces_30099
C
[ "is_magic_square_possible", "print_magic_square" ]
2
[ [ "print_magic_square", "is_magic_square_possible" ] ]
1
[]
false
[]
false
pytest
true
[]
true
114fde246a27124fef2397e042a0b4aac4f7e856
b53e547d079cfbef8af470c366ef506e71e50a1f
v1.0
complete
Codeforces
Codeforces_29672_C
def max_park_area(n: int, m: int, grid_lines: List[str]) -> int: """ Determines the area of the largest rectangular park that can be built on the grid. The park can only be built on empty plots and must form a contiguous sub-rectangle on the grid. Arguments: n -- the number of rows in the ...
def maximalRectangle(grid): # Helper function to find the largest rectangle of 1s in each row def largestRectangleArea(heights): stack = [] max_area = 0 heights.append(0) for i in range(len(heights)): while stack and heights[i] < heights[stack[-1]]: ...
from solution import max_park_area def test_small_grid_with_clear_park(): n, m = 5, 6 grid = [ "..B..B", "......", "BB.BB.", "......", ".B...." ] assert max_park_area(n, m, grid) == 8 def test_all_buildings(): n, m = 3, 3 grid = [ "BBB", ...
[ { "docstring": null, "function_declaration": "def maximalRectangle(grid):", "function_name": "maximalRectangle", "parameter_list": "(grid)" }, { "docstring": null, "function_declaration": "def max_park_area(n, m, grid_lines):", "function_name": "max_park_area", "parameter_list": ...
[ 0, 0, 0, 1, 0 ]
1
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def maximalRectangle(matrix):\n if not matrix:\n return 0\n \n n = len(matrix)\n m = len(matrix[0])\n \n max_area = 0\n heights = ...
trial_gpt4o_3
{ "original_instruction": "You are given a rectangular grid map of a city that consists of n rows and m columns. Each cell in the grid is either a building (represented by 'B') or an empty plot (represented by '.'). The city is planning to build a park which must be a rectangular area on the grid. The park can only b...
0.601425
Codeforces_29672
C
[ "maximalRectangle", "max_park_area" ]
2
[ [ "max_park_area", "maximalRectangle" ] ]
1
[]
false
[]
false
pytest
true
[]
true
024526956a188f90218fb10577d470601c5b649c
1cd592a566dddedc18d342c1edd87cc1cffb3682
v1.0
complete
Codeforces
Codeforces_30047_C
def matrix_path_exists(N: int, K: int, matrix: List[List[int]]) -> str: """ Determine if there exists a simple path of length exactly N-1 in the matrix such that the sum of the elements in the path is divisible by K. Args: N : int : size of the matrix (N x N) K : int : the divisor integer matri...
def find_path(matrix, N, K): directions = [(-1, 0), (1, 0), (0, -1), (0, 1)] def dfs(x, y, length, current_sum, visited): if length == N - 1: return current_sum % K == 0 for dx, dy in directions: nx, ny = x + dx, y + dy if 0 <= nx < N an...
from solution import matrix_path_exists def test_example_case(): matrix = [ [1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12], [13, 14, 15, 16] ] N = 4 K = 5 assert matrix_path_exists(N, K, matrix) == "YES" def test_no_valid_path(): matrix = [ [1, 2], ...
[ { "docstring": null, "function_declaration": "def find_path(matrix, N, K):", "function_name": "find_path", "parameter_list": "(matrix, N, K)" }, { "docstring": null, "function_declaration": "def matrix_path_exists(N, K, matrix):", "function_name": "matrix_path_exists", "parameter...
[ 1, 0, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_path_exist(matrix, N, K):\n def dfs(x, y, length, current_sum, visited):\n if length == N-1:\n return current_sum % K == 0\n ...
trial_gpt4o_2
{ "original_instruction": "You are given a matrix of size N x N filled with integer values. The task is to find out if there exists a simple path of length exactly N-1 in this matrix such that the sum of the elements in the path is divisible by a given integer K. A simple path is a sequence of cells such that you can...
0.552399
Codeforces_30047
C
[ "find_path", "matrix_path_exists" ]
2
[ [ "matrix_path_exists", "find_path" ] ]
1
[]
false
[]
false
pytest
true
[]
true
77ad0970c797c4cf483b0f43976d11fb0d17cc0c
23b67487c37ba6bada607933b3f0d597df487ad0
v1.0
complete
Codeforces
Codeforces_30233_C
def calculate_fibonacci_sum(m: int, n: int) -> int: """ Calculate the sum of Fibonacci sequence numbers from the m-th term to the n-th term, inclusive, modulo 10^9 + 7. >>> calculate_fibonacci_sum(5, 10) 136 >>> calculate_fibonacci_sum(7, 10) 123 >>> calculate_fibonacci_sum(5, 5) 5 >>> c...
MOD = 10**9 + 7 def matrix_mult(A, B, mod=MOD): return [[(A[0][0] * B[0][0] + A[0][1] * B[1][0]) % mod, (A[0][0] * B[0][1] + A[0][1] * B[1][1]) % mod], [(A[1][0] * B[0][0] + A[1][1] * B[1][0]) % mod, (A[1][0] * B[0][1] + A[1][1] * B[1][1]) % mod]] def matrix_pow(M, power, mod=MOD): result = [[1, 0...
from solution import calculate_fibonacci_sum def test_calculate_fibonacci_sum_example_1(): assert calculate_fibonacci_sum(5, 10) == 136 def test_calculate_fibonacci_sum_example_2(): assert calculate_fibonacci_sum(7, 10) == 123 def test_calculate_fibonacci_sum_same_indices(): assert calculate_fibonacci_su...
[ { "docstring": null, "function_declaration": "def matrix_mult(A, B, mod=MOD):", "function_name": "matrix_mult", "parameter_list": "(A, B, mod=MOD)" }, { "docstring": null, "function_declaration": "def matrix_pow(M, power, mod=MOD):", "function_name": "matrix_pow", "parameter_list...
[ 1, 1, 0 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "MOD = 10**9 + 7\n\ndef matrix_mult(A, B, mod=MOD):\n return [[(A[0][0] * B[0][0] + A[0][1] * B[1][0]) % mod, (A[0][0] * B[0][1] + A[0][1] * B[1][1]) % mod]...
trial_gpt4o_0
{ "original_instruction": "There once was a treasure hidden deep in a dense forest, guarded by a series of gates, each with a numeric lock. Only the right code could open each gate and lead to the treasure. The integer code for each lock was derived from a sequence of numbers in a specific pattern, and the numerologi...
0.777885
Codeforces_30233
C
[ "matrix_mult", "matrix_pow", "fibonacci", "fibonacci_sum", "calculate_fibonacci_sum" ]
5
[ [ "calculate_fibonacci_sum", "fibonacci_sum" ], [ "fibonacci", "matrix_pow" ], [ "fibonacci_sum", "fibonacci" ], [ "matrix_pow", "matrix_mult" ] ]
4
[]
false
[]
false
pytest
true
[]
true
94fbc7b14bd211f6ddca0bda3065305751f6ed7c
0b9d3f42caa7de468231e24df2ecc041279a5c37
v1.0
complete
Codeforces
Codeforces_29089_C
def find(parent, i): """ A function to find the set of an element i (uses path compression technique). """ pass def union(parent, rank, x, y): """ A function that does union of two sets of x and y (uses union by rank). """ pass def kruskal_mst(N, edges): """ Function to...
def find(parent, i): """ A function to find the set of an element i (uses path compression technique). """ if parent[i] == i: return i else: return find(parent, parent[i]) def union(parent, rank, x, y): """ A function that does union of two sets of x and y (uses unio...
from solution import kruskal_mst def test_mst_example_1(): N = 4 edges = [(1, 2, 1), (1, 3, 1), (1, 4, 1), (2, 3, 2), (3, 4, 2)] assert kruskal_mst(N, edges) == 3 def test_mst_example_2(): N = 4 edges = [(1, 2, 1), (1, 3, 2), (1, 4, 2), (2, 3, 2), (2, 4, 3), (3, 4, 1)] assert kruskal_mst(N, ed...
[ { "docstring": "A function to find the set of an element i\n(uses path compression technique).", "function_declaration": "def find(parent, i):", "function_name": "find", "parameter_list": "(parent, i)" }, { "docstring": "A function that does union of two sets\nof x and y (uses union by rank)...
[ 0, 1, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def kruskal_mst(n, edges):\n \"\"\"\n Returns the weight of the Minimum Spanning Tree (MST) using Kruskal's algorithm.\n \"\"\"\n parent = [-1] * ...
trial_gpt4o_1
{ "original_instruction": "You are given an undirected graph with N vertices and M edges. Each edge has an associated weight. You need to find the weight of the Minimum Spanning Tree (MST) of the graph.\n\nThe first line of the input contains two integers N and M (1 ≤ N ≤ 1000, 0 ≤ M ≤ 100000) — the number of vertice...
0.667454
Codeforces_29089
C
[ "find", "union", "kruskal_mst" ]
3
[ [ "kruskal_mst", "find" ], [ "kruskal_mst", "union" ], [ "union", "find" ] ]
3
[]
false
[]
false
pytest
true
[]
true
d749d80f435be8109353f8f80b4f9b213e821c65
fef3b0b6c6c4393f03e6b65ca1162547be12666e
v1.0
complete
Codeforces
Codeforces_30207_C
def solve(n, m, grid_lines): """ Determine if it is possible for Alice and Bob to meet on a 2D grid. Alice starts from the top-left corner, and Bob starts from the bottom-right corner. :param n: int - The number of rows in the grid :param m: int - The number of columns in the grid :param gr...
def is_path_exists(grid, start, end): n = len(grid) m = len(grid[0]) queue = [start] visited = set() visited.add(start) while queue: x, y = queue.pop(0) if (x, y) == end: return True for dx, dy in [(-1, 0), (1, 0), (0, -1), (0, 1)]: nx, ny = x...
from solution import solve def test_case_1(): n = 3 m = 4 grid_lines = [ "....", ".##.", "...." ] assert solve(n, m, grid_lines) == "YES" def test_case_2(): n = 3 m = 3 grid_lines = [ "###", "#.#", "###" ] assert solve(n, m, g...
[ { "docstring": null, "function_declaration": "def is_path_exists(grid, start, end):", "function_name": "is_path_exists", "parameter_list": "(grid, start, end)" }, { "docstring": null, "function_declaration": "def can_meet(grid):", "function_name": "can_meet", "parameter_list": "(...
[ 0, 0, 1 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def can_meet(grid, n, m):\n from collections import deque\n \n def bfs(start):\n q = deque([start])\n visited = set([start])\n w...
trial_gpt4o_2
{ "original_instruction": "Alice and Bob are playing a game on a 2D grid of size n by m. Each cell in the grid can be either walkable or blocked. Alice starts from the top-left corner of the grid (cell (1, 1)), while Bob starts from the bottom-right corner of the grid (cell (n, m)). Both players can move to adjacent ...
0.670441
Codeforces_30207
C
[ "is_path_exists", "can_meet", "solve" ]
3
[ [ "can_meet", "is_path_exists" ], [ "solve", "can_meet" ] ]
2
[]
false
[]
false
pytest
true
[]
true
bfac76c0d8fe65f31df9501a3d488e5b28ecacd8
6cccd16b81f4fa779767adf72d713a522fa1822c
v1.0
complete
Codeforces
Codeforces_30100_C
def max_tasks_solver(n, m, server_caps, task_sizes): """ Determine the maximum number of tasks that can be successfully assigned to the servers without exceeding the capacity of any server. Arguments: n : int : the number of servers m : int : the number of tasks server_caps : List[int] : the capacit...
def max_tasks(servers, tasks): servers.sort(reverse=True) tasks.sort(reverse=True) task_count = 0 while tasks and servers: if tasks[-1] <= servers[-1]: servers[-1] -= tasks[-1] tasks.pop() task_count += 1 else: servers.pop() ...
from solution import max_tasks_solver def test_example_case(): n = 3 m = 5 server_caps = [10, 5, 8] task_sizes = [2, 3, 5, 7, 6] assert max_tasks_solver(n, m, server_caps, task_sizes) == 4 def test_all_servers_empty(): n = 2 m = 2 server_caps = [0, 0] task_sizes = [1, 1] assert...
[ { "docstring": null, "function_declaration": "def max_tasks(servers, tasks):", "function_name": "max_tasks", "parameter_list": "(servers, tasks)" }, { "docstring": null, "function_declaration": "def max_tasks_solver(n, m, server_caps, task_sizes):", "function_name": "max_tasks_solver...
[ 0, 0, 0, 0, 1 ]
1
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def max_tasks(n, m, capacities, task_sizes):\n \"\"\"\n Determines the maximum number of tasks that can be assigned to servers without exceeding server ...
trial_gpt4o_4
{ "original_instruction": "You are a new developer at a tech company and your task is to optimize the load distribution system. There are n servers, each with a certain processing capacity. Clients send tasks of varying sizes to the servers, and each server can handle multiple tasks, provided the total size of the ta...
0.609682
Codeforces_30100
C
[ "max_tasks", "max_tasks_solver" ]
2
[ [ "max_tasks_solver", "max_tasks" ] ]
1
[]
false
[]
false
pytest
true
[]
true
d52a998b7d0bf40eec9d3adfa0a72eee4fde5f1a
77c6c1a2a9047baf5352c12d4f55a366407999c4
v1.0
complete
Codeforces
Codeforces_30039_C
def solve(): """ In a land far away, there are n villages connected by n-1 roads such that there is exactly one path between any two villages. Each village has a natural number representing its beauty level. A traveler wants to travel between two villages u and v and wants to know the maximum beauty level he ca...
import sys from collections import defaultdict, deque sys.setrecursionlimit(200000) def dfs(node, parent, depth, max_beauty, beauty_levels, tree, depth_info, ancestor_info, max_beauty_to_ancestor): depth_info[node] = depth ancestor_info[node][0] = parent max_beauty_to_ancestor[node][0] = max_beauty ...
from solution import solve import sys from io import StringIO def test_solve(): input_data = """5 1 3 6 2 5 1 2 1 3 3 4 4 5 3 1 5 2 4 5 3 """ expected_output = """6 6 6 """ sys.stdin = StringIO(input_data) sys.stdout = StringIO() solve() output = sys.stdout.getvalue() assert output == expec...
[ { "docstring": null, "function_declaration": "def dfs(node, parent, depth, max_beauty, beauty_levels, tree, depth_info, ancestor_info, max_beauty_to_ancestor):", "function_name": "dfs", "parameter_list": "(node, parent, depth, max_beauty, beauty_levels, tree, depth_info, ancestor_info, max_beauty_to...
[ 1 ]
1
easy
1
{ "trial_gpt4o_0": null, "trial_gpt4o_1": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared1_results_combined.jsonl", "solution_code": "import sys\nfrom collections import defaultdict, deque\n\nsys.setrecursionlimit(200000)\n\ndef dfs(node, parent, depth, max_beauty, b...
trial_gpt4o_1
{ "original_instruction": "In a land far away, there are n villages connected by n-1 roads such that there is exactly one path between any two villages. Each village has a natural number representing its beauty level. A traveler wants to travel between two villages u and v and wants to know the maximum beauty level h...
0.675678
Codeforces_30039
C
[ "dfs", "find_max_beauty", "solve" ]
3
[ [ "solve", "dfs" ], [ "solve", "find_max_beauty" ] ]
2
[]
false
[]
false
pytest
true
[]
true
00cbcdc6b7a4d3231d660175a9e11ba47361de15
d2409ec66a960a7f9488ac5ca434a4fd9da3a681
v1.0
complete
Codeforces
Codeforces_30185_C
from typing import List def count_distinct_prime_factors(n: int) -> int: """ Returns the number of distinct prime factors of n. >>> count_distinct_prime_factors(6) 2 >>> count_distinct_prime_factors(10) 2 >>> count_distinct_prime_factors(15) 2 >>> count_distinct_prime_factors(2...
from math import isqrt def count_distinct_prime_factors(n): """ Returns the number of distinct prime factors of n. """ count = 0 original_n = n if n % 2 == 0: count += 1 while n % 2 == 0: n //= 2 for i in range(3, isqrt(n) + 1, 2): if n % i == 0: ...
from solution import count_distinct_prime_factors, sum_distinct_prime_factors def test_count_distinct_prime_factors(): assert count_distinct_prime_factors(6) == 2 assert count_distinct_prime_factors(10) == 2 assert count_distinct_prime_factors(15) == 2 assert count_distinct_prime_factors(28) == 2 # 2 ...
[ { "docstring": "Returns the number of distinct prime factors of n.", "function_declaration": "def count_distinct_prime_factors(n):", "function_name": "count_distinct_prime_factors", "parameter_list": "(n)" }, { "docstring": "Returns the sum of distinct prime factors for each element in the a...
[ 0, 0, 0, 0, 0, 0, 0, 1, 1, 0 ]
2
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def calculate_distinct_prime_factors_sum(n, a):\n \"\"\"\n Calculates the sum of the number of distinct prime factors for each element in the array.\n ...
trial_gpt4o_8
{ "original_instruction": "Eve is planning a coding competition for her friends. She decides to create a problem where participants need to find the number of distinct prime factors for given numbers.\n\nYou are given an array `a` consisting of `n` integers.\n\nYour task is to calculate the sum of the number of disti...
0.756552
Codeforces_30185
C
[ "count_distinct_prime_factors", "sum_distinct_prime_factors" ]
2
[ [ "sum_distinct_prime_factors", "count_distinct_prime_factors" ] ]
1
[]
false
[]
false
pytest
true
[]
true
e796ee281c190d8a73f8ceb946830aa36a7e178f
b3f98aa932114a0ead47456c14e8e720a976aa53
v1.0
complete
Codeforces
Codeforces_30340_C
from typing import List, Tuple def max_disjoint_paths(n: int, m: int, barriers: List[Tuple[int, int]]) -> int: """ Determine the maximum number of disjoint paths from any cell in the first row to any cell in the last row after placing a certain number of barriers optimally. >>> max_disjoint_paths(4, ...
from collections import deque, defaultdict def bfs(graph, parent, source, sink): visited = set() queue = deque([source]) visited.add(source) while queue: node = queue.popleft() for neighbor in graph[node]: if neighbor not in visited and graph[node][neighbor] > ...
def test_no_barriers(): # Simple test case with no barriers n, m, k = 4, 4, 0 barriers = [] assert max_disjoint_paths(n, m, barriers) == 4 def test_single_barrier(): # Test case with a single barrier n, m, k = 4, 4, 1 barriers = [(2, 2)] assert max_disjoint_paths(n, m, barriers) == 3 d...
[ { "docstring": null, "function_declaration": "def bfs(graph, parent, source, sink):", "function_name": "bfs", "parameter_list": "(graph, parent, source, sink)" }, { "docstring": null, "function_declaration": "def max_flow(graph, source, sink):", "function_name": "max_flow", "para...
[ 0, 0, 1 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def max_disjoint_paths(n, m, k, barriers):\n \"\"\"\n Returns the maximum number of disjoint paths from any cell in the first row to any cell in the las...
trial_gpt4o_2
{ "original_instruction": "You are given a grid of size $$$n \\times m$$$ consisting of empty cells (denoted by '.'). You can place barriers in order to control the movement in the grid. A barrier is represented by the character '#'. You want to maximize the number of disjoint paths that start from any cell in the fi...
0.640276
Codeforces_30340
C
[ "bfs", "max_flow", "max_disjoint_paths" ]
3
[ [ "max_disjoint_paths", "max_flow" ], [ "max_flow", "bfs" ] ]
2
[]
false
[]
false
pytest
false
[]
true
158f16a1b0a1b2cbec8f995a8fccbde378ca2dc5
6cb270522d37d348c8da12f4cfeae5827f4b4312