version
stringclasses
1 value
style
stringclasses
2 values
subset
stringclasses
12 values
question_id
stringlengths
9
23
question
stringlengths
27
8.13k
solution
stringlengths
99
5.97k
test
stringlengths
105
4.45k
test_info
listlengths
0
13
gpt_pass_sequence
listlengths
1
10
gpt_pass_trial_num
int64
1
10
gpt_difficulty
stringclasses
3 values
gpt_pass_percentage
float64
0.1
1
trials
dict
chosen_trial
stringclasses
10 values
metadata
dict
benchmark_similarity
float64
0.16
0.93
benchmark_instruction
stringclasses
1 value
benchmark_task_id
stringclasses
1 value
filter_reason
stringclasses
1 value
base_id
stringlengths
7
21
variant
stringclasses
2 values
top_function_names
listlengths
2
13
n_top_functions
int64
2
13
helper_call_edges
listlengths
1
16
n_helper_call_edges
int64
1
16
harness_functions
listlengths
0
3
structural_wrapper
bool
1 class
class_names
listlengths
0
5
has_class
bool
2 classes
test_kind
stringclasses
1 value
test_has_solution_import
bool
2 classes
third_party_imports
listlengths
0
5
stdlib_only
bool
2 classes
question_norm_sha1
stringlengths
40
40
solution_ast_sha1
stringlengths
40
40
v1.0
instruct
Codeforces
Codeforces_28055_I
A group of archaeologists discovered an ancient grid map with certain code inscriptions written in some cells. Each cell of the grid has coordinates \((i, j)\), where \(i\) represents the row number and \(j\) represents the column number. The grid has \(N\) rows and \(M\) columns. The inscriptions are located on certa...
def preprocess_grid(grid, N, M): prefix_sum = [[0] * (M + 1) for _ in range(N + 1)] for i in range(1, N + 1): for j in range(1, M + 1): prefix_sum[i][j] = grid[i - 1][j - 1] + prefix_sum[i - 1][j] + prefix_sum[i][j - 1] - prefix_sum[i - 1][j - 1] return prefix_sum def query_sum(prefix_s...
def test_process_queries(): grid = [ [1, 2, 0, 3, 4], [0, 6, 0, 7, 0], [3, 4, 5, 6, 7], [0, 0, 0, 1, 2] ] N, M = 4, 5 queries = [ (1, 1, 3, 3), (2, 2, 4, 5), (1, 1, 4, 5) ] expected_results = [21, 38, 51] results = process_que...
[ { "docstring": null, "function_declaration": "def preprocess_grid(grid, N, M):", "function_name": "preprocess_grid", "parameter_list": "(grid, N, M)" }, { "docstring": null, "function_declaration": "def query_sum(prefix_sum, x1, y1, x2, y2):", "function_name": "query_sum", "param...
[ 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 calculate_subgrid_sums(N, M, Q, matrix, queries):\n # Create a prefix sum matrix\n prefix_sum = [[0] * (M + 1) for _ in range(N + 1)]\n \n for...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00028055", "row_id": 28055, "seed_ids": "[3440, 7583, 3162]" }
0.648275
Codeforces_28055
I
[ "preprocess_grid", "query_sum", "process_queries" ]
3
[ [ "process_queries", "preprocess_grid" ], [ "process_queries", "query_sum" ] ]
2
[ "process_queries" ]
false
[]
false
pytest
false
[]
true
019e4b9d96bff219c55e4eac8917bfcdf18da9aa
53a7562f4c6f6a71c6ab975a3097195bd9c052c1
v1.0
instruct
Codeforces
Codeforces_28081_I
You are given a weighted undirected graph with $$$n$$$ vertices and $$$m$$$ edges. Each edge has a weight associated with it. David 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 possible number of edges. The w...
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": "", "prompt_id": "00028081", "row_id": 28081, "seed_ids": "[8319, 1935, 3864]" }
0.746204
Codeforces_28081
I
[ "find", "union", "maximum_spanning_tree" ]
3
[ [ "maximum_spanning_tree", "find" ], [ "maximum_spanning_tree", "union" ], [ "union", "find" ] ]
3
[]
false
[]
false
pytest
true
[]
true
09ab6f5dcfdaa184fe3171e955289e296b7ad1aa
cd7736eed8cf026964dc7c063f78ea12da614ddc
v1.0
instruct
Codeforces
Codeforces_28105_I
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. However, you have some constraints. The land available to you can...
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": "", "prompt_id": "00028105", "row_id": 28105, "seed_ids": "[1073, 1141, 8280]" }
0.688146
Codeforces_28105
I
[ "maximalRectangle", "largestRectangleArea", "find_maximal_rectangle" ]
3
[ [ "find_maximal_rectangle", "maximalRectangle" ], [ "maximalRectangle", "largestRectangleArea" ] ]
2
[]
false
[]
false
pytest
true
[]
true
675edac7f8d513187f8d950ead7c62064465beb5
432530ab6fb55cdd5dec8e09e145d03674cd963b
v1.0
instruct
Codeforces
Codeforces_28119_I
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 given range. However, calculatin...
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": "", "prompt_id": "00028119", "row_id": 28119, "seed_ids": "[4787, 6900, 5700]" }
0.679821
Codeforces_28119
I
[ "sieve_of_eratosthenes", "max_prime_gap" ]
2
[ [ "max_prime_gap", "sieve_of_eratosthenes" ] ]
1
[]
false
[]
false
pytest
false
[]
true
46849097cbc33d5578446c7e3aaf4260fb355ef0
0f9ed00c7f6a02c8ced0af107675ace0f73f015b
v1.0
instruct
Codeforces
Codeforces_28155_I
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. The first line of input contains two integers, n and q (1 ≤ n, q ≤ 10^5): the number of elements in the array and the number of qu...
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": "", "prompt_id": "00028155", "row_id": 28155, "seed_ids": "[4924, 3520, 1799]" }
0.707958
Codeforces_28155
I
[ "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
e1a87e31d7638b6f666b47f06700eb1ddffed380
518e65cb8073881dce0c2f5920403a9071d3dc72
v1.0
instruct
Codeforces
Codeforces_28170_I
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 sum of all the elements in th...
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": "", "prompt_id": "00028170", "row_id": 28170, "seed_ids": "[5539, 7951, 4593]" }
0.666542
Codeforces_28170
I
[ "preprocess", "query_sum", "handle_queries" ]
3
[ [ "handle_queries", "preprocess" ], [ "handle_queries", "query_sum" ] ]
2
[ "handle_queries" ]
false
[]
false
pytest
false
[]
true
b8cc6b85905d77f69acc6e4a8b58d8998c51823d
f9ded9de6ee269f8189cd88136c997eeba7395d1
v1.0
instruct
Codeforces
Codeforces_28175_I
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 values. You need to write a p...
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": "", "prompt_id": "00028175", "row_id": 28175, "seed_ids": "[825, 5043, 3169]" }
0.625295
Codeforces_28175
I
[ "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
50dc243a9c5eb76a60052e163f8fa21d269ea651
3c264b2ef521eb2f1a46a549eb3489478d1b8508
v1.0
instruct
Codeforces
Codeforces_28176_I
Simon is playing with strings and he is particularly interested in finding special substrings. A substring is considered special if it meets the following conditions: 1. It is a palindrome (reads the same forward and backward). 2. It consists of only one unique character or there is exactly one character that appears a...
def is_special_palindrome(s): """ Check if a string is a special palindrome: 1. It is a palindrome. 2. It consists of only one unique character or there is exactly one character that appears an odd number of times, and all other characters appear an even number of times. """ n = l...
from solution import is_special_palindrome, count_special_substrings, process_test_cases def test_is_special_palindrome(): assert is_special_palindrome("a") == True assert is_special_palindrome("aa") == True assert is_special_palindrome("ab") == False assert is_special_palindrome("aba") == True ass...
[ { "docstring": "Check if a string is a special palindrome:\n1. It is a palindrome.\n2. It consists of only one unique character or there is exactly one character\n that appears an odd number of times, and all other characters appear an \n even number of times.", "function_declaration": "def is_special_p...
[ 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 count_special_substrings(t, strings):\n \"\"\"\n Returns the number of special substrings for each string in the input.\n \"\"\"\n def is_spec...
trial_gpt4o_5
{ "original_instruction": "", "prompt_id": "00028176", "row_id": 28176, "seed_ids": "[2812, 3447, 908]" }
0.744673
Codeforces_28176
I
[ "is_special_palindrome", "count_special_substrings", "process_test_cases" ]
3
[ [ "count_special_substrings", "is_special_palindrome" ], [ "process_test_cases", "count_special_substrings" ] ]
2
[ "process_test_cases" ]
false
[]
false
pytest
true
[]
true
38fabbfe2e60592304f544761b68a8598f3eb562
df935e7814068f15bd498fc88bbfea747c20c1a7
v1.0
instruct
Codeforces
Codeforces_28177_I
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: - `arr[i] > arr[i-1] and arr[i] > arr[i+1]` - `arr[i] < arr[i-1] and arr[i] < arr[i+1]` Given...
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": "", "prompt_id": "00028177", "row_id": 28177, "seed_ids": "[3965, 1800, 1693]" }
0.673326
Codeforces_28177
I
[ "is_zigzag", "longest_zigzag_subarray" ]
2
[ [ "longest_zigzag_subarray", "is_zigzag" ] ]
1
[]
false
[]
false
pytest
true
[]
true
fd8bda5397f834941c2883e68912f70ee1fde345
8225fb608e6138edb64d1306e1f31ba97702c4ae
v1.0
instruct
Codeforces
Codeforces_28197_I
A company operates a network of computers connected by bidirectional communication channels. The network is represented by a graph with `n` nodes, where each node represents a computer and each edge represents a communication channel. Each edge has a certain bandwidth, represented by an integer, indicating the maximum ...
from heapq import heappush, heappop from collections import defaultdict def dijkstra_max_min_bandwidth(n, edges, queries): graph = defaultdict(list) for u, v, w in edges: graph[u].append((w, v)) graph[v].append((w, u)) def max_bandwidth_dijkstra(s, t): max_bandwidth = [-1]...
import pytest from solution import solve def test_example_1(): input_data = """5 6 1 2 5 1 3 10 1 4 7 2 3 3 3 4 6 4 5 4 3 1 5 2 4 3 5""" expected_output = """4 5 4""" assert solve(input_data) == expected_output def test_single_edge(): input_data = """2 1 1 2 10 1 1 2""" expected_output = """10"""...
[ { "docstring": null, "function_declaration": "def dijkstra_max_min_bandwidth(n, edges, queries):", "function_name": "dijkstra_max_min_bandwidth", "parameter_list": "(n, edges, queries)" }, { "docstring": null, "function_declaration": "def process_input(inputs):", "function_name": "pr...
[ 0, 0, 0, 0, 0, 1, 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 heapq import heappop, heappush\nfrom collections import defaultdict, deque\n\ndef max_bandwidth_path(n, edges, queries):\n # ...
trial_gpt4o_6
{ "original_instruction": "", "prompt_id": "00028197", "row_id": 28197, "seed_ids": "[8040, 912, 7260]" }
0.660623
Codeforces_28197
I
[ "dijkstra_max_min_bandwidth", "process_input", "solve" ]
3
[ [ "solve", "dijkstra_max_min_bandwidth" ], [ "solve", "process_input" ] ]
2
[ "process_input" ]
false
[]
false
pytest
true
[]
true
34d5646d511d09b6eacbe8065261c0a4d9158512
5c7847d1e63200edcd08b213966c3c5a15d57bcf
v1.0
instruct
Codeforces
Codeforces_28244_I
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 value of each element in the v...
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": "", "prompt_id": "00028244", "row_id": 28244, "seed_ids": "[4263, 1544, 1190]" }
0.686876
Codeforces_28244
I
[ "is_prime", "longest_prime_subsequence" ]
2
[ [ "longest_prime_subsequence", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
d484b32bec015ecb511986490fdd479c085ffbb9
d311bd3d949dcf1cf95048fdf6c5aa754f537a9a
v1.0
instruct
Codeforces
Codeforces_28249_I
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. A 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 is the number of edges on the lon...
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": "", "prompt_id": "00028249", "row_id": 28249, "seed_ids": "[7388, 7892, 4456]" }
0.647108
Codeforces_28249
I
[ "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
7eff324a47c4ce0d7f9b4d679f758f03d76697fb
48a5b60c8e082027b53606efc5235c9af3fa3dc1
v1.0
instruct
Codeforces
Codeforces_28308_I
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. The first line of input contains two integers n and m (1 ≤ n, m ≤ 1000) — the length of the array and the number of...
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": "", "prompt_id": "00028308", "row_id": 28308, "seed_ids": "[3795, 3536, 6877]" }
0.783025
Codeforces_28308
I
[ "is_feasible", "minimize_max_subarray_sum" ]
2
[ [ "minimize_max_subarray_sum", "is_feasible" ] ]
1
[]
false
[]
false
pytest
true
[]
true
5e01d0e28458bed42ab3aa4fa7bd9ed08ef18048
bcdc7a8a76f52d00a0831df4472c8a6ba6f0849b
v1.0
instruct
Codeforces
Codeforces_28315_I
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. Jenia now wants to select different sets of paintings to observe average beauty score...
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": "", "prompt_id": "00028315", "row_id": 28315, "seed_ids": "[2433, 3300, 7056]" }
0.579306
Codeforces_28315
I
[ "compute_prefix_sums", "average_beauty_scores" ]
2
[ [ "average_beauty_scores", "compute_prefix_sums" ] ]
1
[]
false
[]
false
pytest
false
[]
true
746d1ffa21862d25a9b3b014e5db743b19249518
43a48b223264f9ba03215701739116fbefdca4bf
v1.0
instruct
Codeforces
Codeforces_28391_I
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 certain sections of the grid. Ea...
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": "", "prompt_id": "00028391", "row_id": 28391, "seed_ids": "[3095, 3289, 5188]" }
0.730074
Codeforces_28391
I
[ "illuminate_grid", "process_illumination" ]
2
[ [ "process_illumination", "illuminate_grid" ] ]
1
[]
false
[]
false
pytest
true
[]
true
2cb043d21297fa7fb3a56576b744fc49f15b21e2
6e0b51579c0654000b44c1fa2e378bc248373d41
v1.0
instruct
Codeforces
Codeforces_28397_I
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 trees she can possibly form us...
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": "", "prompt_id": "00028397", "row_id": 28397, "seed_ids": "[4200, 6346, 6058]" }
0.542096
Codeforces_28397
I
[ "num_trees", "balanced_trees_count" ]
2
[ [ "balanced_trees_count", "num_trees" ] ]
1
[]
false
[]
false
pytest
true
[]
true
d23f882622b8a1425b8cbde838871dda60f26865
331436c4ea53162eb8985c0512f65fcbf09cbb6d
v1.0
instruct
Codeforces
Codeforces_28413_I
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 sequence where each element at posit...
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": "", "prompt_id": "00028413", "row_id": 28413, "seed_ids": "[4522, 717, 7951]" }
0.585229
Codeforces_28413
I
[ "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
954a441ad5e80343b96bf98480ec576acb6f1734
a5c667c68115814fb1f250908286ac4774a2cdd5
v1.0
instruct
Codeforces
Codeforces_28424_I
As a proficient coder, you're challenged to decrypt a mysterious message left by an anonymous user. The message is hidden within a sequence of lowercase alphabetic characters, and it contains some recurring patterns. Your task is to find the longest substring that appears at least twice in the given message. If there a...
def longest_repeated_substring(s): n = len(s) # Helper function: Get the suffix array of s def build_suffix_array(s): suffixes = sorted((s[i:], i) for i in range(n)) return [suffix[1] for suffix in suffixes] # Helper function: Get the Longest Common Prefix (LCP) of two strings ...
from solution import find_longest_repeated_substring def test_find_longest_repeated_substring(): assert find_longest_repeated_substring(10, "bananapine") == "ana" assert find_longest_repeated_substring(5, "apple") == "p" assert find_longest_repeated_substring(6, "aabbcc") == "a" assert find_longest_rep...
[ { "docstring": null, "function_declaration": "def longest_repeated_substring(s):", "function_name": "longest_repeated_substring", "parameter_list": "(s)" }, { "docstring": null, "function_declaration": "def find_longest_repeated_substring(n, message):", "function_name": "find_longest...
[ 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_longest_repeated_substring(s):\n \"\"\"\n Given a string s, finds the longest substring that appears at least twice.\n If there are multiple...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00028424", "row_id": 28424, "seed_ids": "[111, 347, 1682]" }
0.693376
Codeforces_28424
I
[ "longest_repeated_substring", "find_longest_repeated_substring" ]
2
[ [ "find_longest_repeated_substring", "longest_repeated_substring" ] ]
1
[]
false
[]
false
pytest
true
[]
true
a793e3f064ca50e4f5bcea98622e75db89f7419a
eacb40558731dd9f62f34fc3ab07e650365955b9
v1.0
instruct
Codeforces
Codeforces_28425_I
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 the original array. More forma...
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": "", "prompt_id": "00028425", "row_id": 28425, "seed_ids": "[6748, 5420, 4269]" }
0.765594
Codeforces_28425
I
[ "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
2d97c29ce70881df4b196f07fc7ef190aeb39b43
25f94ff7f2d7a5ca1dbb8be306b8d8c581b315eb
v1.0
instruct
Codeforces
Codeforces_28455_I
Given a string containing only parentheses '(', ')', '{', '}', '[' and ']', determine if the input string is valid. An input string is valid if: 1. Open brackets must be closed by the same type of brackets. 2. Open brackets must be closed in the correct order. The input string should either be balanced and correctly...
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": "", "prompt_id": "00028455", "row_id": 28455, "seed_ids": "[2989, 7377, 3645]" }
0.800993
Codeforces_28455
I
[ "is_valid_parentheses", "validate_parentheses_sequences" ]
2
[ [ "validate_parentheses_sequences", "is_valid_parentheses" ] ]
1
[]
false
[]
false
pytest
true
[]
true
625d4d700cc18e94d8faea6933fedd401fbeb30f
c32a223fb1fae7699c0c76657e87ef17746a20d3
v1.0
instruct
Codeforces
Codeforces_28460_I
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 as the maximum sum of any cont...
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": "", "prompt_id": "00028460", "row_id": 28460, "seed_ids": "[1698, 255, 3432]" }
0.725298
Codeforces_28460
I
[ "max_subarray_sum", "process_operations" ]
2
[ [ "process_operations", "max_subarray_sum" ] ]
1
[]
false
[]
false
pytest
true
[]
true
5b58f1c99b3728f475f6ef989c1c954afc25582b
beaf2c0cb8ce7658472a9858a7e610d7a4c35e2f
v1.0
instruct
Codeforces
Codeforces_28477_I
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. You are given a sequence of integers where each integer represe...
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": "", "prompt_id": "00028477", "row_id": 28477, "seed_ids": "[840, 4787, 4868]" }
0.700711
Codeforces_28477
I
[ "longest_subsequence", "longest_contiguous_subsequence" ]
2
[ [ "longest_contiguous_subsequence", "longest_subsequence" ] ]
1
[]
false
[]
false
pytest
true
[]
true
db634b598d7e93fb4b507cbc47629925ddd2098b
97e6ec1bebbb7b424997d35e2542fee565705842
v1.0
instruct
Codeforces
Codeforces_28481_I
You are given a list of activities for a day along with their start and end times. Your goal is to determine the maximum number of non-overlapping activities that can be attended. Each activity is represented by a pair of integers (start_time, end_time). The input consists of multiple test cases. The first line conta...
def max_non_overlapping_activities(test_cases): results = [] for test in test_cases: n, activities = test # Sort activities based on their end time activities.sort(key=lambda x: x[1]) count = 0 last_end_time = 0 for start_time, end_time in activi...
import pytest from solution import process_activities def test_single_test_case(): input_str = "1\n3\n1 2\n3 4\n0 6\n" expected_output = [2] assert process_activities(input_str) == expected_output def test_multiple_test_cases(): input_str = "3\n3\n1 2\n3 4\n0 6\n4\n1 3\n2 5\n4 6\n5 7\n5\n1 2\n3 4\n0 6...
[ { "docstring": null, "function_declaration": "def max_non_overlapping_activities(test_cases):", "function_name": "max_non_overlapping_activities", "parameter_list": "(test_cases)" }, { "docstring": null, "function_declaration": "def parse_input(input_str):", "function_name": "parse_i...
[ 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 max_non_overlapping_activities(test_cases):\n results = []\n for case in test_cases:\n n, activities = case\n # Sort activities by the...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00028481", "row_id": 28481, "seed_ids": "[5476, 1305, 3584]" }
0.711487
Codeforces_28481
I
[ "max_non_overlapping_activities", "parse_input", "process_activities" ]
3
[ [ "process_activities", "max_non_overlapping_activities" ], [ "process_activities", "parse_input" ] ]
2
[ "parse_input" ]
false
[]
false
pytest
true
[]
true
81d7e2a25af0d88abfa06200a9c37eecb0b90a77
e223c839d7af317e989acd6135af8b056300c8dc
v1.0
instruct
Codeforces
Codeforces_28520_I
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`. Your task is to determine the minimum number of swaps re...
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": "", "prompt_id": "00028520", "row_id": 28520, "seed_ids": "[3374, 987, 4404]" }
0.71461
Codeforces_28520
I
[ "count_inversions", "merge_and_count", "minimum_swaps" ]
3
[ [ "count_inversions", "merge_and_count" ], [ "minimum_swaps", "count_inversions" ] ]
2
[]
false
[]
false
pytest
false
[]
true
aa0a621576768b6774280522aafb6e4e3c5bcac5
10321f59b0145182b672eb8bbeef7b0f634b5bf5
v1.0
instruct
Codeforces
Codeforces_28524_I
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. For example, given the heights `[2, 1, 5, 6, 2, 3]`, the largest rectangle has an area of 10 (from hei...
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": "", "prompt_id": "00028524", "row_id": 28524, "seed_ids": "[6141, 4984, 1956]" }
0.683959
Codeforces_28524
I
[ "largest_rectangle_area", "find_largest_rectangle_area" ]
2
[ [ "find_largest_rectangle_area", "largest_rectangle_area" ] ]
1
[]
false
[]
false
pytest
true
[]
true
d40b2e439bde2defd12d17600ec8baeb90ae0775
6c1ef4417e7ab82c4edb3cb0afed7331e6c4b12f
v1.0
instruct
Codeforces
Codeforces_28552_I
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. The garden can be represented as a connected, undirected graph with n ...
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": "", "prompt_id": "00028552", "row_id": 28552, "seed_ids": "[2412, 7286, 4252]" }
0.623895
Codeforces_28552
I
[ "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
6e526812376dda95d4fa5e275177410278d6d64b
f92f180f7af102ddfef948a4424f61f610a6bdb7
v1.0
instruct
Codeforces
Codeforces_28557_I
Polycarpus loves geometry and has recently come across a problem involving quadrilaterals in a 2D plane. He has n points with distinct integer coordinates, and he wants to find the four points that form a convex quadrilateral with the maximum possible area. A quadrilateral is convex if all its internal angles are less...
from itertools import combinations import math def shoelace_formula(points): n = len(points) area = 0.0 for i in range(n): j = (i + 1) % n area += points[i][0] * points[j][1] area -= points[j][0] * points[i][1] return abs(area) / 2.0 def is_convex_quad(quad): def cross_prod...
from solution import max_area_convex_quadrilateral def test_example_case(): input_data = "5\n0 0\n1 0\n0 1\n1 1\n2 2" expected_output = 1.0 assert abs(max_area_convex_quadrilateral(5, [(0, 0), (1, 0), (0, 1), (1, 1), (2, 2)])) - expected_output < 10**-6 def test_four_collinear_points(): input_data = "...
[ { "docstring": null, "function_declaration": "def shoelace_formula(points):", "function_name": "shoelace_formula", "parameter_list": "(points)" }, { "docstring": null, "function_declaration": "def is_convex_quad(quad):", "function_name": "is_convex_quad", "parameter_list": "(quad...
[ 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": "from itertools import combinations\nfrom typing import List, Tuple\n\ndef shoelace_formula(points: List[Tuple[int, int]]) -> float:\n \"\"\"\n Calculate...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00028557", "row_id": 28557, "seed_ids": "[6025, 5290, 6253]" }
0.665588
Codeforces_28557
I
[ "shoelace_formula", "is_convex_quad", "max_area_convex_quadrilateral", "process_input_output" ]
4
[ [ "max_area_convex_quadrilateral", "is_convex_quad" ], [ "max_area_convex_quadrilateral", "shoelace_formula" ], [ "process_input_output", "max_area_convex_quadrilateral" ] ]
3
[ "process_input_output" ]
false
[]
false
pytest
true
[]
true
6fc764f4c198a8189d391982a6e8358a1d5ae391
499300cb0c7a50656baf480bcea2f1e10907d7de
v1.0
instruct
Codeforces
Codeforces_28593_I
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 timestamped with the number of min...
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": "", "prompt_id": "00028593", "row_id": 28593, "seed_ids": "[6329, 3973, 1429]" }
0.594806
Codeforces_28593
I
[ "attendance_tracking", "process_operations" ]
2
[ [ "process_operations", "attendance_tracking" ] ]
1
[]
false
[]
false
pytest
true
[]
true
b9e998c13e871078b4e94c4e2cc542d6a0395e23
965bf4434771511511630e0a634ce8291f538853
v1.0
instruct
Codeforces
Codeforces_28640_I
Let’s create a coding assessment question that closely matches the style, length, complexity, and topics covered by the provided examples. Harold works in a network security team and is responsible for monitoring unauthorized accesses. A monitoring device captures each access attempt and logs the IP address and timest...
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": "", "prompt_id": "00028640", "row_id": 28640, "seed_ids": "[4659, 5625, 2664]" }
0.577867
Codeforces_28640
I
[ "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
a2f116ef881523d0f7361e15810960a172a8a798
8c4eeb88326aa5d4e26c8308106402983d294774
v1.0
instruct
Codeforces
Codeforces_28646_I
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? The stalls are located along a straight line at positions $$$x_1, x_2, \ldots, x_n$$$. You need to determin...
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": "", "prompt_id": "00028646", "row_id": 28646, "seed_ids": "[974, 5459, 3709]" }
0.621254
Codeforces_28646
I
[ "canPlaceCows", "largestMinDist" ]
2
[ [ "largestMinDist", "canPlaceCows" ] ]
1
[]
false
[]
false
pytest
true
[]
true
a25471bbaf7aaed7ecec801eff7b94730fb51fae
2b9e010fce46bac80de60d41c58c1765de43615d
v1.0
instruct
Codeforces
Codeforces_28703_I
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 of the competition. They have...
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": "", "prompt_id": "00028703", "row_id": 28703, "seed_ids": "[5537, 5744, 2120]" }
0.716852
Codeforces_28703
I
[ "check_consistency", "process_input_and_check_consistency" ]
2
[ [ "process_input_and_check_consistency", "check_consistency" ] ]
1
[]
false
[]
false
pytest
false
[]
true
75d88e1222cfa8b37506f8367bddc2c97301c3d0
ea4e2c50cdd10570301cb08fe5adfc88cf5e0344
v1.0
instruct
Codeforces
Codeforces_28704_I
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 wants to ensure his code runs ef...
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": "", "prompt_id": "00028704", "row_id": 28704, "seed_ids": "[6985, 470, 1414]" }
0.636808
Codeforces_28704
I
[ "is_prime", "largest_prime_less_than" ]
2
[ [ "largest_prime_less_than", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
c9ca890a3b31ea4c8d0edbe2a202c942f7a3c936
17ccd8d72beed06752a27faf2620b6b5765a9eb5
v1.0
instruct
Codeforces
Codeforces_28754_I
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, represented by an integer arra...
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": "", "prompt_id": "00028754", "row_id": 28754, "seed_ids": "[5030, 4141, 5793]" }
0.635326
Codeforces_28754
I
[ "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
8ec857a55b49067ccb34d4ee4cf323c28908c2e7
5704b431df6964590a745790b2f37d353bfff82b
v1.0
instruct
Codeforces
Codeforces_28811_I
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) such that i < j and array[i...
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": "", "prompt_id": "00028811", "row_id": 28811, "seed_ids": "[6411, 3338, 7847]" }
0.690654
Codeforces_28811
I
[ "merge_and_count", "merge_sort_and_count", "count_inversions" ]
3
[ [ "count_inversions", "merge_sort_and_count" ], [ "merge_sort_and_count", "merge_and_count" ] ]
2
[]
false
[]
false
pytest
true
[]
true
64f07514a638efafc7c25daed8e840a3c16d7deb
a26c9b6a718c4902636c0e23856d3e4613edfe7d
v1.0
instruct
Codeforces
Codeforces_28836_I
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 of flowers, find out the maxim...
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": "", "prompt_id": "00028836", "row_id": 28836, "seed_ids": "[2329, 7428, 5891]" }
0.612395
Codeforces_28836
I
[ "maximalRectangle", "largestRectangleArea", "find_max_rectangle_area" ]
3
[ [ "find_max_rectangle_area", "maximalRectangle" ], [ "maximalRectangle", "largestRectangleArea" ] ]
2
[]
false
[]
false
pytest
false
[]
true
0f90b29b31a41f623a4238daead30e5296ddecdc
cb69c71422b44e2661b5eb06baacf6b5976efcb4
v1.0
instruct
Codeforces
Codeforces_28884_I
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. You are given an array of integers representing the heights of the plants in Eden's garden. Eden wants the heights of the plants to form a non-de...
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": "", "prompt_id": "00028884", "row_id": 28884, "seed_ids": "[1516, 3020, 5689]" }
0.657165
Codeforces_28884
I
[ "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
a72bd051560201fd07ed96a2426fbc3c2847bbc5
60fc3e0ea92b3e0718ea5036cc0793ac9226bcde
v1.0
instruct
Codeforces
Codeforces_29004_I
Alice enjoys solving mathematical puzzles and is particularly interested in properties of prime numbers. She recently encountered a challenge where she was given an integer n and needed to construct an array a of length n such that: 1. Each element of the array is a positive integer. 2. The sum of all elements in the ...
def is_prime(num): """ Helper function to determine if a number is prime. """ if num <= 1: return False if num <= 3: return True if num % 2 == 0 or num % 3 == 0: return False i = 5 while (i * i) <= num: if num % i == 0 or num % (i + 2) == 0: re...
from solution import is_prime, generate_array def test_is_prime(): assert is_prime(2) is True assert is_prime(3) is True assert is_prime(4) is False assert is_prime(17) is True assert is_prime(18) is False assert is_prime(19) is True assert is_prime(20) is False def test_generate_array(): ...
[ { "docstring": "Helper function to determine if a number is prime.", "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": "Generate an array of length n such that each element is a positive integer,\nthe array contains distinc...
[ 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 itertools\n\ndef is_prime(k):\n \"\"\"Check if the number k is a prime number.\"\"\"\n if k <= 1:\n return False\n if k <= 3:\n ...
trial_gpt4o_4
{ "original_instruction": "", "prompt_id": "00029004", "row_id": 29004, "seed_ids": "[6475, 1969, 7479]" }
0.66195
Codeforces_29004
I
[ "is_prime", "generate_array" ]
2
[ [ "generate_array", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
098f09ed9881e151328a52b7ddbcb53c2e5e25eb
d9f023448d2108244880de847025870a5ee15e8b
v1.0
instruct
Codeforces
Codeforces_29010_I
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 character `c` in the substri...
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": "", "prompt_id": "00029010", "row_id": 29010, "seed_ids": "[3273, 7088, 7128]" }
0.844415
Codeforces_29010
I
[ "preprocess", "count_char_in_substring", "process_operations" ]
3
[ [ "process_operations", "count_char_in_substring" ], [ "process_operations", "preprocess" ] ]
2
[]
false
[]
false
pytest
true
[]
true
21ddc01bc5d92c7696f3d40259da0f07ffe2a9d7
29a49ef2d34111d82b63a0ebda805c77b35dccce
v1.0
instruct
Codeforces
Codeforces_29054_I
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. ### Input - The first line of the input co...
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": "", "prompt_id": "00029054", "row_id": 29054, "seed_ids": "[7361, 1040, 1626]" }
0.697488
Codeforces_29054
I
[ "find_furthest_node", "find_tree_diameter" ]
2
[ [ "find_tree_diameter", "find_furthest_node" ] ]
1
[]
false
[]
false
pytest
false
[]
true
2794350f83bb7892da4607bf05e63fa937f37d20
2f2681c40c8476f23f0c63113cc639767d7f90d3
v1.0
instruct
Codeforces
Codeforces_29089_I
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. The first line of the input contains two integers N and M (1 ≤ N ≤ 1000, 0 ≤ M ≤ 100000) — the number of vertices and edges, respectively. The...
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": "", "prompt_id": "00029089", "row_id": 29089, "seed_ids": "[7647, 5306, 3220]" }
0.827708
Codeforces_29089
I
[ "find", "union", "kruskal_mst" ]
3
[ [ "kruskal_mst", "find" ], [ "kruskal_mst", "union" ], [ "union", "find" ] ]
3
[]
false
[]
false
pytest
true
[]
true
72fdc31b87208ee27dac43308812885c7efec079
fef3b0b6c6c4393f03e6b65ca1162547be12666e
v1.0
instruct
Codeforces
Codeforces_29117_I
You are given a list of integers. The integers represent the power levels of soldiers in an army. Two players, Player1 and Player2, are playing a game where they take turns to perform the following action: on a player's turn, they must remove a non-empty contiguous subarray such that the sum of the subarray is a prime ...
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 ** 2 <= num: if num % i == 0 or num % (i + 2) == 0: return False i += 6 return True def can_make_move(array): ...
from solution import optimal_game_winner def test_example_case(): assert optimal_game_winner(4, [2, 3, 4, 5]) == "Player1" def test_no_prime_subarray(): assert optimal_game_winner(3, [4, 4, 4]) == "Player2" def test_single_prime_element(): assert optimal_game_winner(1, [3]) == "Player1" assert optima...
[ { "docstring": null, "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": null, "function_declaration": "def can_make_move(array):", "function_name": "can_make_move", "parameter_list": "(array)" }, { "docst...
[ 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 is_prime(n):\n \"\"\"Check if a number is prime.\"\"\"\n if n <= 1:\n return False\n if n == 2:\n return True\n if n % 2 == 0:\n...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00029117", "row_id": 29117, "seed_ids": "[2918, 1371, 7212]" }
0.720639
Codeforces_29117
I
[ "is_prime", "can_make_move", "optimal_game_winner" ]
3
[ [ "can_make_move", "is_prime" ], [ "optimal_game_winner", "can_make_move" ], [ "optimal_game_winner", "is_prime" ] ]
3
[]
false
[]
false
pytest
true
[]
true
bddf258624bb0432257e9fa478f9efb521ae304f
91ca7a6c1f42a6b44b78b1c15e10bb2b5c2c8457
v1.0
instruct
Codeforces
Codeforces_29169_I
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. Eric has an n x n matrix filled with integers. He needs to perform the following operations on the matrix:...
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": "", "prompt_id": "00029169", "row_id": 29169, "seed_ids": "[2764, 1375, 1777]" }
0.623475
Codeforces_29169
I
[ "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
e0b089b6afd9a804664d063cb6ce701474806e85
28e0547e4db1da03f66cff83588608fefc51df47
v1.0
instruct
Codeforces
Codeforces_29209_I
You are given an array of integers nodes of length $$$n$$$ ($$$1 \le n \le 10^5$$$) and an integer pathLen. Each integer in the array nodes represents a unique identifier of a node in an undirected graph. Your task is to determine the maximum length of any path in the graph containing exactly $$$pathLen$$$ nodes. A pa...
from collections import deque, defaultdict def bfs_longest_path(start, graph, pathLen, n): visited = {} queue = deque([(start, 1, 0)]) # (node, pathLen count, pathLength) max_len = -1 while queue: node, count, path_length = queue.popleft() if count == pathLen: # If the path lengt...
from solution import max_path_length def test_case_1(): n = 5 pathLen = 3 nodes = [1, 2, 3, 4, 5] m = 4 edges = [(1, 2), (2, 3), (3, 4), (4, 5)] assert max_path_length(n, pathLen, nodes, m, edges) == 2 def test_case_2(): n = 6 pathLen = 4 nodes = [1, 2, 3, 4, 5, 6] m = 6 ed...
[ { "docstring": null, "function_declaration": "def bfs_longest_path(start, graph, pathLen, n):", "function_name": "bfs_longest_path", "parameter_list": "(start, graph, pathLen, n)" }, { "docstring": null, "function_declaration": "def max_path_length(n, pathLen, nodes, m, edges):", "fu...
[ 1, 0 ]
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": "from collections import deque, defaultdict\n\ndef bfs_longest_path(start, graph, pathLen, n):\n visited = {}\n queue = deque([(...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00029209", "row_id": 29209, "seed_ids": "[2073, 4558, 5383]" }
0.731105
Codeforces_29209
I
[ "bfs_longest_path", "max_path_length" ]
2
[ [ "max_path_length", "bfs_longest_path" ] ]
1
[]
false
[]
false
pytest
true
[]
true
003e7ce56dcd1d681ce178ef373dbd6db41c5a62
6dc49c8728b020abde18581b7fb7a14f204b47f9
v1.0
instruct
Codeforces
Codeforces_29226_I
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. However, due to a recent storm...
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": "", "prompt_id": "00029226", "row_id": 29226, "seed_ids": "[2373, 2586, 2179]" }
0.612423
Codeforces_29226
I
[ "garland_beauty_count", "process_garlands" ]
2
[ [ "process_garlands", "garland_beauty_count" ] ]
1
[]
false
[]
false
pytest
true
[]
true
6eacae6fbb3d1e539e15911106fcff09a53307d7
ec6c1245d0eadfbaf5fb4855da34dfade7361505
v1.0
instruct
Codeforces
Codeforces_29231_I
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: - `.`: an empty cell. - `S`: the starting point. - `T`: the treasure. - `#`: an ...
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": "", "prompt_id": "00029231", "row_id": 29231, "seed_ids": "[1217, 5138, 4340]" }
0.752916
Codeforces_29231
I
[ "find_shortest_path", "treasure_hunt" ]
2
[ [ "treasure_hunt", "find_shortest_path" ] ]
1
[]
false
[]
false
pytest
true
[]
true
a0b03a8cb6d0c3463cb9b379ddd59c6d2119e196
ed3ec3a56173271c7ea4d2f26296f6b7dab53dd1
v1.0
instruct
Codeforces
Codeforces_29270_I
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 reachable from position `i` if the ...
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": "", "prompt_id": "00029270", "row_id": 29270, "seed_ids": "[4056, 5910, 961]" }
0.706624
Codeforces_29270
I
[ "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
9734aae108fba3b851b024d869091991897620d4
114c1f48bf7e6d9a2d19974929ba744db313a8d0
v1.0
instruct
Codeforces
Codeforces_29271_I
You have recently been hired to work with a team of developers on a new project. Your first task is to implement a module for processing transaction logs in a large-scale financial application. The log file contains records of transactions with each line in the following format: ``` timestamp, user_id, transaction_amo...
from datetime import datetime def parse_log(log): timestamp, user_id, transaction_amount = log.split(',') timestamp = datetime.strptime(timestamp.strip(), "%Y-%m-%d %H:%M:%S") user_id = int(user_id.strip()) transaction_amount = float(transaction_amount.strip()) return timestamp, user_id, transactio...
from solution import calculate_net_amount def test_no_transactions(): input_data = """12345 2023-01-01 00:00:00 2023-12-31 23:59:59""" assert calculate_net_amount(input_data) == 0.00 def test_single_transaction_in_range(): input_data = """12345 2023-01-01 00:00:00 2023-12-31 23:59:59 2023-01-10 15:30:...
[ { "docstring": null, "function_declaration": "def parse_log(log):", "function_name": "parse_log", "parameter_list": "(log)" }, { "docstring": null, "function_declaration": "def calculate_net_amount(input_data):", "function_name": "calculate_net_amount", "parameter_list": "(input_...
[ 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 datetime import datetime\n\ndef parse_log(log):\n timestamp, user_id, transaction_amount = log.split(',')\n timestamp = datetime.strptime(timestamp...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00029271", "row_id": 29271, "seed_ids": "[6209, 3527, 7133]" }
0.51818
Codeforces_29271
I
[ "parse_log", "calculate_net_amount" ]
2
[ [ "calculate_net_amount", "parse_log" ] ]
1
[]
false
[]
false
pytest
true
[]
true
ef73d8624a8fb2e9fa5a25ee70928b04fcdba748
357313eaf11556b92481de03a3b46b328914c759
v1.0
instruct
Codeforces
Codeforces_29282_I
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: 1. Each node has at most two children. 2. Every node with a right child must have a left child and the left subtree must not be empty. 3. The depths of the left and right sub...
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": "", "prompt_id": "00029282", "row_id": 29282, "seed_ids": "[1549, 5035, 6747]" }
0.625297
Codeforces_29282
I
[ "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
db5c74eec1a5d3b5264c8ef810c034b21c7cabbb
c3ccff0b2b43942f88dffcdc74f02b117172d4e1
v1.0
instruct
Codeforces
Codeforces_29343_I
A new startup company offers a ride-sharing service in a city with a grid-like road network. Riders can request rides from one intersection to another, and the company's goal is to minimize the total travel distance for all rides served. The city has n intersections, and each intersection is connected by bi-directiona...
import heapq def dijkstra(graph, start): """ Dijkstra's algorithm to find the shortest path from start node to all other nodes. """ n = len(graph) dist = [float('inf')] * n dist[start] = 0 pq = [(0, start)] while pq: current_dist, u = heapq.heappop(pq) if c...
from solution import solve def test_solve_example(): num_intersections = 6 num_requests = 3 roads = [ (1, 2, 4), (1, 3, 2), (2, 4, 5), (3, 5, 1), (3, 6, 3) ] requests = [ (1, 4), (5, 6), (2, 3) ] expected_output = [9, 4, 6] ...
[ { "docstring": "Dijkstra's algorithm to find the shortest path from start node to all other nodes.", "function_declaration": "def dijkstra(graph, start):", "function_name": "dijkstra", "parameter_list": "(graph, start)" }, { "docstring": null, "function_declaration": "def solve(num_inter...
[ 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": "import heapq\n\ndef dijkstra(graph, start, n):\n distances = {i: float('inf') for i in range(1, n+1)}\n distances[start] = 0\n priority_queue = [(0, ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00029343", "row_id": 29343, "seed_ids": "[6051, 2698, 784]" }
0.759234
Codeforces_29343
I
[ "dijkstra", "solve" ]
2
[ [ "solve", "dijkstra" ] ]
1
[]
false
[]
false
pytest
true
[]
true
ff222271b60109a9db8509ec57f1725664a70142
e64cda4cf467ed672f774459d9b9798a1c8df5d1
v1.0
instruct
Codeforces
Codeforces_29350_I
One day, Max received a rectangular matrix of integers as a gift. He finds beauty in matrices and wants to know how beautiful his matrix is based on the sum of its submatrices. For each query, Max wants to find the sum of elements in a submatrix defined by its top-left and bottom-right corners. Specifically, each query...
def calculate_prefix_sum(matrix): n = len(matrix) m = len(matrix[0]) prefix_sum = [[0]*(m+1) for _ in range(n+1)] for i in range(1, n+1): for j in range(1, m+1): prefix_sum[i][j] = (matrix[i-1][j-1] + prefix_sum[i-1][j] + ...
def test_calculate_prefix_sum(): 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 calculate_prefix_sum(matrix) == expected_prefix_sum def test_sum_submatr...
[ { "docstring": null, "function_declaration": "def calculate_prefix_sum(matrix):", "function_name": "calculate_prefix_sum", "parameter_list": "(matrix)" }, { "docstring": null, "function_declaration": "def sum_submatrix(prefix_sum, r1, c1, r2, c2):", "function_name": "sum_submatrix", ...
[ 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 matrix_query(matrix, queries):\n \"\"\"\n Given a matrix and a list of queries, returns the sum of elements in submatrices defined by the queries.\n...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00029350", "row_id": 29350, "seed_ids": "[8045, 6397, 5547]" }
0.649496
Codeforces_29350
I
[ "calculate_prefix_sum", "sum_submatrix", "process_queries", "main" ]
4
[ [ "process_queries", "calculate_prefix_sum" ], [ "process_queries", "sum_submatrix" ] ]
2
[ "process_queries" ]
false
[]
false
pytest
false
[]
true
c2a7df3b9e067a29c81bb828aa1d9d8c91193eb5
932211a5d4f73b603ab96ca3f01707f6100c08e1
v1.0
instruct
Codeforces
Codeforces_29429_I
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 divisors other than 1 and itself....
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": "", "prompt_id": "00029429", "row_id": 29429, "seed_ids": "[3222, 729, 8230]" }
0.688351
Codeforces_29429
I
[ "is_prime", "longest_prime_subsequence_length" ]
2
[ [ "longest_prime_subsequence_length", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
9fe96cf07ce354e874663acf6b366b79990df62b
6f684db87f999810d8c784e3085153d720da88d1
v1.0
instruct
Codeforces
Codeforces_29446_I
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. The field is represented as a 2D grid of size n x m. Each cell in the grid can either have an apple tree (denot...
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": "", "prompt_id": "00029446", "row_id": 29446, "seed_ids": "[423, 7499, 4174]" }
0.66048
Codeforces_29446
I
[ "plant_apple_trees", "print_apple_trees_layout" ]
2
[ [ "print_apple_trees_layout", "plant_apple_trees" ] ]
1
[]
false
[]
false
pytest
true
[]
true
135bfaf0270052131fe4b402d8a2a165e386815c
5a93bb6797a6330133208ca59c56cf40da063c34
v1.0
instruct
Codeforces
Codeforces_29483_I
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 subsequence (LCS) among all ...
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": "", "prompt_id": "00029483", "row_id": 29483, "seed_ids": "[6531, 4259, 3964]" }
0.677625
Codeforces_29483
I
[ "lcs", "longest_common_subsequence", "get_lcs_string" ]
3
[ [ "longest_common_subsequence", "get_lcs_string" ] ]
1
[]
false
[]
false
pytest
true
[]
true
fda1ed51de403916244a1415fdad1de1e40cbdb2
a6bda0e071e8b1095b986c3176cd26f04287151b
v1.0
instruct
Codeforces
Codeforces_29484_I
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 than 1 that has no positive i...
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": "", "prompt_id": "00029484", "row_id": 29484, "seed_ids": "[8258, 669, 1506]" }
0.698593
Codeforces_29484
I
[ "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
be5ebe92c466a2828443f066242d4f9491926640
d041530299d402a9fa35288189ddeb9f680cc5af
v1.0
instruct
Codeforces
Codeforces_29497_I
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 the grid (1,1) to the bottom-ri...
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": "", "prompt_id": "00029497", "row_id": 29497, "seed_ids": "[4263, 4709, 5635]" }
0.688838
Codeforces_29497
I
[ "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
d124fb1c38f7c44ff9e728e740cd27a860a9c9d9
daf927ae395c9ce5a6eb8796c774003f031628c4
v1.0
instruct
Codeforces
Codeforces_29512_I
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. Alice's goal is to navigate from the top-left corner of the grid (1, 1) to the bottom-r...
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": "", "prompt_id": "00029512", "row_id": 29512, "seed_ids": "[2535, 6900, 4087]" }
0.757175
Codeforces_29512
I
[ "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
eb37bdbcfd0883f43e0142d91eabd1a01895ce09
eb46e57bc76691510e8153caccbea773ba9594e3
v1.0
instruct
Codeforces
Codeforces_29518_I
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. Given a list of delivery locations, represented as coordinates on a 2D plane, your task is to calculate the shortest route that visits each loc...
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": "", "prompt_id": "00029518", "row_id": 29518, "seed_ids": "[932, 302, 6341]" }
0.71033
Codeforces_29518
I
[ "calculate_distance", "tsp_minimum_cost" ]
2
[ [ "tsp_minimum_cost", "calculate_distance" ] ]
1
[]
false
[]
false
pytest
true
[]
true
32aadc139ae8ec2981e5a9da1b3940bf5045ada7
929cad23dd88adf799bd7dccc86a4b3d4325da5a
v1.0
instruct
Codeforces
Codeforces_29536_I
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`. Tanya 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). Your task is to help Tanya by wri...
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": "", "prompt_id": "00029536", "row_id": 29536, "seed_ids": "[4571, 552, 7986]" }
0.655692
Codeforces_29536
I
[ "can_become_dag", "reorder_graph_to_dag" ]
2
[ [ "reorder_graph_to_dag", "can_become_dag" ] ]
1
[]
false
[]
false
pytest
true
[]
true
67fdd9d321a1c17a2714bd9657cf64782f4083ca
feb486b139e833044b1449481eb112cb72243827
v1.0
instruct
Codeforces
Codeforces_29672_I
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 be built on empty plots and mu...
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": "", "prompt_id": "00029672", "row_id": 29672, "seed_ids": "[5688, 3683, 768]" }
0.647344
Codeforces_29672
I
[ "maximalRectangle", "max_park_area" ]
2
[ [ "max_park_area", "maximalRectangle" ] ]
1
[]
false
[]
false
pytest
true
[]
true
2e298396fcd024375863ce3388f7cb147d854611
1cd592a566dddedc18d342c1edd87cc1cffb3682
v1.0
instruct
Codeforces
Codeforces_29678_I
Bob loves prime numbers and wants to create a prime number puzzle for his friend Alice. The puzzle works as follows: Alice 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. Given the nature of the problem, the...
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": "", "prompt_id": "00029678", "row_id": 29678, "seed_ids": "[4228, 3697, 7908]" }
0.597708
Codeforces_29678
I
[ "is_prime", "smallest_prime_greater_equal" ]
2
[ [ "smallest_prime_greater_equal", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
0f6e9bb2475112ccc59d25aefd917374e87c6d42
fafd91f8479949fc4b2cdd9088434fe98b766307
v1.0
instruct
Codeforces
Codeforces_29763_I
You are given a tree with n nodes and n-1 edges. Each node has an initial value ai and you need to perform the following kinds of operations: 1. Update the value of a particular node. 2. Calculate the sum of the values of all nodes in the subtree of a given node (including the node itself). The first line of the inpu...
class TreeNode: def __init__(self, value): self.value = value self.children = [] def build_tree(n, values, edges): nodes = [TreeNode(value) for value in values] tree = {i: nodes[i] for i in range(n)} for u, v in edges: tree[u-1].children.append(tree[v-1]) tree[v-1].child...
from solution import process_queries def test_simple_case(): n = 3 values = [1, 2, 3] edges = [(1, 2), (1, 3)] queries = [(2, 1)] assert process_queries(n, values, edges, queries) == [6] def test_update_case(): n = 3 values = [1, 2, 3] edges = [(1, 2), (1, 3)] queries = [(1, 1, 5),...
[]
[ 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\nclass Tree:\n def __init__(self, n, values):\n self.n = n\n self.values = values\n self....
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00029763", "row_id": 29763, "seed_ids": "[1196, 6474, 1976]" }
0.69859
Codeforces_29763
I
[ "build_tree", "dfs_sum", "update_value", "query_subtree_sum", "process_queries" ]
5
[ [ "process_queries", "build_tree" ], [ "process_queries", "dfs_sum" ], [ "process_queries", "query_subtree_sum" ], [ "process_queries", "update_value" ] ]
4
[ "process_queries" ]
false
[ "TreeNode" ]
true
pytest
true
[]
true
7353a0b63745ec0e01a29a87f838a032013fcf6b
ff466215662d66141152241e153753b0735ca095
v1.0
instruct
Codeforces
Codeforces_29786_I
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. A subrectangle is any rectangular part of the grid that can be identified by two pairs of coordinates: top-left ($$$x1, y1$$$) and bottom-right ($$$x2, y2$$...
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": "", "prompt_id": "00029786", "row_id": 29786, "seed_ids": "[596, 3693, 703]" }
0.639429
Codeforces_29786
I
[ "maximum_sum_subrectangle", "maximum_sum_subarray" ]
2
[ [ "maximum_sum_subrectangle", "maximum_sum_subarray" ] ]
1
[]
false
[]
false
pytest
false
[]
true
03e4759e484595a008d09a86f2a96d8cc695a538
9b836fa336c0c065709ba78e30f0038e663f409b
v1.0
instruct
Codeforces
Codeforces_29869_I
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 it forms a rectangle with sid...
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": "", "prompt_id": "00029869", "row_id": 29869, "seed_ids": "[2960, 1401, 2277]" }
0.674191
Codeforces_29869
I
[ "maximal_suitable_rectangle", "max_histogram_area" ]
2
[ [ "maximal_suitable_rectangle", "max_histogram_area" ] ]
1
[]
false
[]
false
pytest
false
[]
true
ed915b1054fe11b4413c60c738c3032ddb42c581
4140b29c0263378aa39c036ad7b3a22eeffb849d
v1.0
instruct
Codeforces
Codeforces_29892_I
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 its reverse, 31, is also a prime n...
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": "", "prompt_id": "00029892", "row_id": 29892, "seed_ids": "[4779, 6104, 1195]" }
0.65273
Codeforces_29892
I
[ "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
6fc49f989eadee4019570759edb565c564525c9c
d8ff205577a4fb489d86ab5dae5177047f67f5d9
v1.0
instruct
Codeforces
Codeforces_29897_I
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 than k swaps. Write a progr...
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": "", "prompt_id": "00029897", "row_id": 29897, "seed_ids": "[1368, 2875, 739]" }
0.70232
Codeforces_29897
I
[ "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
0b204f12cb71f5613384c5af6b016bcb5d7fba3d
548aa62e2f3763c7b759cf630758598e7c12cc3d
v1.0
instruct
Codeforces
Codeforces_29953_I
Given an undirected graph with `n` nodes and `m` edges, each edge `i` has a weight `w_i`. You are required to find the minimum number of edges that need to be removed to make the graph acyclic while keeping as few connected components as possible. The first line of input contains two integers `n` and `m` (1 ≤ n ≤ 1000...
def find(parent, i): if parent[i] == i: return i else: return find(parent, parent[i]) def union(parent, rank, x, y): xroot = find(parent, x) yroot = find(parent, y) if rank[xroot] < rank[yroot]: parent[xroot] = yroot elif rank[xroot] > rank[yroot]: parent[yroot...
from solution import min_edges_to_remove, parse_input def test_min_edges_to_remove_sample1(): input_data = "5 3\n1 2 3\n2 3 2\n3 1 1\n" n, m, edges = parse_input(input_data) assert min_edges_to_remove(n, m, edges) == 1 def test_min_edges_to_remove_sample2(): input_data = "6 5\n1 2 2\n2 3 3\n3 4 1\n4 5...
[ { "docstring": null, "function_declaration": "def find(parent, i):", "function_name": "find", "parameter_list": "(parent, i)" }, { "docstring": null, "function_declaration": "def union(parent, rank, x, y):", "function_name": "union", "parameter_list": "(parent, rank, x, y)" }, ...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def min_edges_to_remove_to_acyclic(n, m, edges):\n \"\"\"\n This function finds the minimum number of edges to remove to make the graph acyclic \n wh...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00029953", "row_id": 29953, "seed_ids": "[8267, 1466, 4821]" }
0.631818
Codeforces_29953
I
[ "find", "union", "min_edges_to_remove", "parse_input" ]
4
[ [ "min_edges_to_remove", "find" ], [ "min_edges_to_remove", "union" ], [ "union", "find" ] ]
3
[ "parse_input" ]
false
[]
false
pytest
true
[]
true
07098364449f4a426c894e364a497a7a839d5c58
c4dee1de3f3b9f363528c79ced7c63e72e48a787
v1.0
instruct
Codeforces
Codeforces_29962_I
The Kingdom of Zoria has a system of roads connecting various cities. The king has declared a plan to modernize the road system by constructing new roads between certain pairs of cities. However, Zoria's road construction budget is limited, so the king wants to ensure that the entire kingdom remains connected with the ...
def find(parent, i): if parent[i] == i: return i else: return find(parent, parent[i]) def union(parent, rank, x, y): root_x = find(parent, x) root_y = find(parent, y) if rank[root_x] > rank[root_y]: parent[root_y] = root_x elif rank[root_x] < rank[root_y]: paren...
def test_minimum_cost_to_connect_cities(): assert minimum_cost_to_connect_cities(4, [(1, 2, 1), (2, 3, 4), (3, 4, 2)], [(1, 3, 2), (1, 4, 3)]) == 5 assert minimum_cost_to_connect_cities(4, [(1, 2, 1), (2, 3, 1), (3, 4, 1)], [(1, 3, 2), (1, 4, 2)]) == 3 assert minimum_cost_to_connect_cities(4, [(1, 2, 4), (2...
[ { "docstring": null, "function_declaration": "def find(parent, i):", "function_name": "find", "parameter_list": "(parent, i)" }, { "docstring": null, "function_declaration": "def union(parent, rank, x, y):", "function_name": "union", "parameter_list": "(parent, rank, x, y)" }, ...
[ 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 find(parent, i):\n if parent[i] == i:\n return i\n else:\n parent[i] = find(parent, parent[i])\n return parent[i]\n\ndef union(...
trial_gpt4o_4
{ "original_instruction": "", "prompt_id": "00029962", "row_id": 29962, "seed_ids": "[3243, 3269, 2398]" }
0.7415
Codeforces_29962
I
[ "find", "union", "minimum_cost_to_connect_cities" ]
3
[ [ "minimum_cost_to_connect_cities", "find" ], [ "minimum_cost_to_connect_cities", "union" ], [ "union", "find" ] ]
3
[]
false
[]
false
pytest
false
[]
true
e084f4b5fb45582262f9b15b946e01d05a72d81b
9de95704e5e9427b66d3e47478df9243af18bf17
v1.0
instruct
Codeforces
Codeforces_29968_I
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. Jiří wants to write a program that, given a range of integers [a, b], computes the maximum prime gap among all prim...
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": "", "prompt_id": "00029968", "row_id": 29968, "seed_ids": "[7240, 3815, 6543]" }
0.687463
Codeforces_29968
I
[ "sieve_of_eratosthenes", "max_prime_gap" ]
2
[ [ "max_prime_gap", "sieve_of_eratosthenes" ] ]
1
[]
false
[]
false
pytest
true
[]
true
5bfc98b956042bbfd9669e6afa26e408d240e459
c3be949e2a6350db8ba90a558511e6f63ab89287
v1.0
instruct
Codeforces
Codeforces_30039_I
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 can encounter on the path f...
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": "", "prompt_id": "00030039", "row_id": 30039, "seed_ids": "[6352, 825, 2927]" }
0.689852
Codeforces_30039
I
[ "dfs", "find_max_beauty", "solve" ]
3
[ [ "solve", "dfs" ], [ "solve", "find_max_beauty" ] ]
2
[]
false
[]
false
pytest
true
[]
true
36e73775a67a35c35402cfd34458a1318dd42edf
d2409ec66a960a7f9488ac5ca434a4fd9da3a681
v1.0
instruct
Codeforces
Codeforces_30047_I
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 move from one cell to anothe...
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": "", "prompt_id": "00030047", "row_id": 30047, "seed_ids": "[4285, 6757, 3845]" }
0.693413
Codeforces_30047
I
[ "find_path", "matrix_path_exists" ]
2
[ [ "matrix_path_exists", "find_path" ] ]
1
[]
false
[]
false
pytest
true
[]
true
6146b03ad4e21493202fce1bad8cce9a1b1092d2
23b67487c37ba6bada607933b3f0d597df487ad0
v1.0
instruct
Codeforces
Codeforces_30077_I
Evelyn is building a shopping complex that contains multiple shops, and she wants to determine the best placement for a new mega store based on potential customer traffic. The shopping complex can be represented as a graph with `N` nodes (shops) and `M` bidirectional edges (paths between shops). Each path has a certain...
import heapq from collections import defaultdict, deque def dijkstra(graph, start, n): dists = [float('inf')] * (n + 1) dists[start] = 0 priority_queue = [(0, start)] while priority_queue: current_dist, u = heapq.heappop(priority_queue) if current_dist > dists[u]: ...
from solution import optimal_shop_placement def test_optimal_shop_placement_case_1(): input_str = ''' 4 4 1 2 1 2 3 2 3 4 1 1 3 4 ''' assert optimal_shop_placement(input_str) == 2 def test_optimal_shop_placement_case_2(): input_str = ''' 3 3 1 2 3 2 3 1 1 3 7 ''...
[ { "docstring": null, "function_declaration": "def dijkstra(graph, start, n):", "function_name": "dijkstra", "parameter_list": "(graph, start, n)" }, { "docstring": null, "function_declaration": "def find_optimal_shop(N, M, paths):", "function_name": "find_optimal_shop", "paramete...
[ 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 heapq\nfrom collections import defaultdict\n\ndef optimal_shop(N, M, edges):\n def dijkstra(start):\n dist = [float('inf')] * (N + 1)\n ...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00030077", "row_id": 30077, "seed_ids": "[4247, 2930, 5399]" }
0.664822
Codeforces_30077
I
[ "dijkstra", "find_optimal_shop", "optimal_shop_placement" ]
3
[ [ "find_optimal_shop", "dijkstra" ], [ "optimal_shop_placement", "find_optimal_shop" ] ]
2
[]
false
[]
false
pytest
true
[]
true
2d0597e3a1a7fdbbb50311cd362b360e98de348c
a9b393c50f977d0e993a6391484755af3fe7ebcd
v1.0
instruct
Codeforces
Codeforces_30091_I
You are given a series of n points in a 2D plane. Each point can be either a "start" point or an "end" point, and collectively they form straight non-overlapping line segments, with each segment connecting exactly one "start" point to one "end" point. Your task is to identify all the line segments and determine the la...
import math def calculate_distance(p1, p2): """ Calculates the Euclidean distance between two points """ return math.sqrt((p1[0] - p2[0]) ** 2 + (p1[1] - p2[1]) ** 2) def find_max_distance(test_cases): results = [] for case in test_cases: starts = [] ends = [] for point...
from solution import main def test_example_case(): input_data = """2 2 S 0 0 E 3 4 S 1 1 E 4 5 3 S -1 -1 E 2 3 S 0 0 E 1 1 S -2 -2 E 4 4""" expected_output = "5.000000\n8.485281" assert main(input_data) == expected_output def test_single_segment(): input_data = """1 1 S 1 1 E 4 5""" expected_outpu...
[ { "docstring": "Calculates the Euclidean distance between two points", "function_declaration": "def calculate_distance(p1, p2):", "function_name": "calculate_distance", "parameter_list": "(p1, p2)" }, { "docstring": null, "function_declaration": "def find_max_distance(test_cases):", ...
[ 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 math\n\ndef calculate_distance(x1, y1, x2, y2):\n return math.sqrt((x1 - x2) ** 2 + (y1 - y2) ** 2)\n\ndef max_distance_between_segments(t, test_cas...
trial_gpt4o_4
{ "original_instruction": "", "prompt_id": "00030091", "row_id": 30091, "seed_ids": "[6990, 5835, 6045]" }
0.744529
Codeforces_30091
I
[ "calculate_distance", "find_max_distance", "parse_input", "main" ]
4
[ [ "find_max_distance", "calculate_distance" ] ]
1
[ "parse_input" ]
false
[]
false
pytest
true
[]
true
941e9dbec3cf661c10cdb5555c8bb75e88b3d7d4
7688f835a4015a0abf5e7197a5a962a50969bace
v1.0
instruct
Codeforces
Codeforces_30099_I
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. The task is to fill an NxN grid with positive integers from 1 to N×N in such a way that each number appears exactly once and the sum of the n...
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": "", "prompt_id": "00030099", "row_id": 30099, "seed_ids": "[8123, 7067, 6719]" }
0.633881
Codeforces_30099
I
[ "is_magic_square_possible", "print_magic_square" ]
2
[ [ "print_magic_square", "is_magic_square_possible" ] ]
1
[]
false
[]
false
pytest
true
[]
true
94fbe33edb3e8128514d1664711d81ecb353f865
b53e547d079cfbef8af470c366ef506e71e50a1f
v1.0
instruct
Codeforces
Codeforces_30100_I
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 tasks does not exceed its capac...
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": "", "prompt_id": "00030100", "row_id": 30100, "seed_ids": "[230, 5272, 5904]" }
0.676767
Codeforces_30100
I
[ "max_tasks", "max_tasks_solver" ]
2
[ [ "max_tasks_solver", "max_tasks" ] ]
1
[]
false
[]
false
pytest
true
[]
true
f57403adf3ebd9c155caa88952d06d0f2b5a0aec
77c6c1a2a9047baf5352c12d4f55a366407999c4
v1.0
instruct
Codeforces
Codeforces_30137_I
You are given a binary tree with node values stored in an array in a level-order fashion. Given two nodes in the binary tree, return the lowest common ancestor (LCA) of these two nodes. The Lowest Common Ancestor of two nodes p and q in a binary tree is defined as the lowest node in T that has both p and q as descenda...
class TreeNode: def __init__(self, x): self.val = x self.left = None self.right = None def build_tree(level_order): """ Builds a binary tree from a list of values in level order. """ if not level_order: return None root = TreeNode(level_order[0]) queue =...
from solution import lowest_common_ancestor def test_lca_case1(): assert lowest_common_ancestor(7, [3, 5, 1, 6, 2, 0, 8], 5, 1) == 3 def test_lca_case2(): assert lowest_common_ancestor(7, [3, 5, 1, 6, 2, 0, 8], 6, 2) == 5 def test_lca_case3(): assert lowest_common_ancestor(7, [3, 5, 1, 6, 2, 0, 8], 6, 8)...
[]
[ 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 TreeNode:\n def __init__(self, x):\n self.val = x\n self.left = None\n self.right = None\n\ndef create_binary_tree_from_level_or...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00030137", "row_id": 30137, "seed_ids": "[7659, 7084, 4651]" }
0.599753
Codeforces_30137
I
[ "build_tree", "findLCA", "lowest_common_ancestor" ]
3
[ [ "lowest_common_ancestor", "build_tree" ], [ "lowest_common_ancestor", "findLCA" ] ]
2
[]
false
[ "TreeNode" ]
true
pytest
true
[]
true
88d345c353a558b08071087362dcb2386f628619
b4f4bef7716eb560e4cf2dc1db4f45f5baafd38e
v1.0
instruct
Codeforces
Codeforces_30165_I
You have a grid of size `n x m` where some cells are removable (represented by '.') and others are walls (represented by '#'). You need to find the largest connected component of removable cells. A connected component is a group of 'removable' cells ('#') that are adjacent horizontally or vertically. Your task is to w...
def dfs(grid, visited, x, y, n, m): if x < 0 or x >= n or y < 0 or y >= m or grid[x][y] == '#' or visited[x][y]: return 0 visited[x][y] = True size = 1 for dx, dy in [(-1, 0), (1, 0), (0, -1), (0, 1)]: size += dfs(grid, visited, x + dx, y + dy, n, m) return size def largest_conne...
from solution import dfs, largest_connected_component def test_single_cell_removable(): grid = ["."] assert largest_connected_component(grid, 1, 1) == 1 def test_single_cell_wall(): grid = ["#"] assert largest_connected_component(grid, 1, 1) == 0 def test_all_removable(): grid = ["....", "...."] ...
[ { "docstring": null, "function_declaration": "def dfs(grid, visited, x, y, n, m):", "function_name": "dfs", "parameter_list": "(grid, visited, x, y, n, m)" }, { "docstring": null, "function_declaration": "def largest_connected_component(grid, n, m):", "function_name": "largest_connec...
[ 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 dfs(grid, visited, x, y, n, m):\n if x < 0 or x >= n or y < 0 or y >= m or grid[x][y] == '#' or visited[x][y]:\n return 0\n\n visited[x][y] =...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00030165", "row_id": 30165, "seed_ids": "[7858, 2685, 1681]" }
0.605456
Codeforces_30165
I
[ "dfs", "largest_connected_component", "read_input" ]
3
[ [ "largest_connected_component", "dfs" ] ]
1
[ "read_input" ]
false
[]
false
pytest
true
[]
true
09ba05f344794332ff41db1e402162d16cd35bb4
dd3358c7630d3745b24416764bdfb2bf337203f5
v1.0
instruct
Codeforces
Codeforces_30185_I
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. You are given an array `a` consisting of `n` integers. Your task is to calculate the sum of the number of distinct prime factors for each elemen...
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": "", "prompt_id": "00030185", "row_id": 30185, "seed_ids": "[7070, 1164, 1297]" }
0.609584
Codeforces_30185
I
[ "count_distinct_prime_factors", "sum_distinct_prime_factors" ]
2
[ [ "sum_distinct_prime_factors", "count_distinct_prime_factors" ] ]
1
[]
false
[]
false
pytest
true
[]
true
be7adede22429038de1adfb9df3a220342596def
b3f98aa932114a0ead47456c14e8e720a976aa53
v1.0
instruct
Codeforces
Codeforces_30207_I
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 cells in one of the four poss...
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": "", "prompt_id": "00030207", "row_id": 30207, "seed_ids": "[2817, 2079, 254]" }
0.786515
Codeforces_30207
I
[ "is_path_exists", "can_meet", "solve" ]
3
[ [ "can_meet", "is_path_exists" ], [ "solve", "can_meet" ] ]
2
[]
false
[]
false
pytest
true
[]
true
1f424d80d3634ac2aa91b125bfe63a80621a5d2b
6cccd16b81f4fa779767adf72d713a522fa1822c
v1.0
instruct
Codeforces
Codeforces_30229_I
You are given an array of integers and a set of queries. Each query consists of two integers, start and end, representing the inclusive range from which you need to return the sum of the array elements. Given that the number of queries can be quite large, your task is to preprocess the array in such a way that each que...
def preprocess_array(arr): """ Preprocess the array to create the prefix sum array. """ n = len(arr) prefix_sum = [0] * (n + 1) for i in range(n): prefix_sum[i + 1] = prefix_sum[i] + arr[i] return prefix_sum def range_sum(prefix_sum, start, end): """ Use the prefix sum array...
from solution import preprocess_array, range_sum, process_queries def test_preprocess_array(): arr = [1, 2, 3, 4, 5] expected_prefix_sum = [0, 1, 3, 6, 10, 15] assert preprocess_array(arr) == expected_prefix_sum def test_range_sum(): prefix_sum = [0, 1, 3, 6, 10, 15] assert range_sum(prefix_sum, 1...
[ { "docstring": "Preprocess the array to create the prefix sum array.", "function_declaration": "def preprocess_array(arr):", "function_name": "preprocess_array", "parameter_list": "(arr)" }, { "docstring": "Use the prefix sum array to get the sum of elements from `start` to `end` (inclusive)...
[ 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": "", "prompt_id": "00030229", "row_id": 30229, "seed_ids": "[7761, 8224, 6869]" }
0.666317
Codeforces_30229
I
[ "preprocess_array", "range_sum", "process_queries" ]
3
[ [ "process_queries", "preprocess_array" ], [ "process_queries", "range_sum" ] ]
2
[ "process_queries" ]
false
[]
false
pytest
true
[]
true
1025599d5b132cc171775362281503ee15ca60d9
8c835c05ab736aca6652ba0f8d07fa6ce4fcd850
v1.0
instruct
Codeforces
Codeforces_30233_I
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 numerologists claimed the magic lay in ...
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": "", "prompt_id": "00030233", "row_id": 30233, "seed_ids": "[4601, 7456, 2250]" }
0.586687
Codeforces_30233
I
[ "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
b6cd8761411b4adf85008e07e2b610d013f6403d
0b9d3f42caa7de468231e24df2ecc041279a5c37
v1.0
instruct
Codeforces
Codeforces_30254_I
Margo is an avid gardener who has a rectangular garden of dimensions n x m. The garden is divided into n rows and m columns, forming a grid of square cells, each of which can either be empty or contain a plant. Each plant can be of a different height, and Margo wants to prune one contiguous rectangular area in the gard...
def max_subarray_sum(arr): max_sum = arr[0] current_sum = arr[0] for num in arr[1:]: current_sum = max(num, current_sum + num) max_sum = max(max_sum, current_sum) return max_sum def max_sum_submatrix(matrix, n, m): max_sum = float('-inf') for left in range(m): ...
from solution import max_sum_submatrix def test_small_matrix(): matrix = [ [1, -2, -1, 4, 5], [2, 5, -8, 3, -1], [3, -2, -3, 4, 2], [2, 4, 3, -1, 1] ] n = 4 m = 5 assert max_sum_submatrix(matrix, n, m) == 21 def test_single_row(): matrix = [ [2, 1, -...
[ { "docstring": null, "function_declaration": "def max_subarray_sum(arr):", "function_name": "max_subarray_sum", "parameter_list": "(arr)" }, { "docstring": null, "function_declaration": "def max_sum_submatrix(matrix, n, m):", "function_name": "max_sum_submatrix", "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": "def max_sum_submatrix(garden):\n \"\"\"\n Returns the maximum sum of rectangular subarea in the garden.\n \n Args:\n garden: List of list of in...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00030254", "row_id": 30254, "seed_ids": "[6094, 1618, 4817]" }
0.628883
Codeforces_30254
I
[ "max_subarray_sum", "max_sum_submatrix" ]
2
[ [ "max_sum_submatrix", "max_subarray_sum" ] ]
1
[]
false
[]
false
pytest
true
[]
true
bf4103e240410a96ab9e6207e8be56f9f024a4d2
8fbea8e0c6c6c95e32fe008a7749bad933452bb7
v1.0
instruct
Codeforces
Codeforces_30262_I
You are given an array of integers. Your task is to find all the possible contiguous subarrays such that the sum of the elements in each subarray is a prime number. A prime number is a natural number greater than 1 that has no positive divisors other than 1 and itself. ### Input Format - The first line contains a sin...
def is_prime(num): """ Returns True if the number is prime, otherwise False. """ 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: r...
from solution import is_prime, count_prime_sum_subarrays 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(1) == False assert is_prime(0) == False assert is_prim...
[ { "docstring": "Returns True if the number is prime, otherwise False.", "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": "Returns the number of contiguous subarrays whose sum is a prime number.", "function_declaration"...
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 ]
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 if num <= 1:\n return False\n if num <= 3:\n return True\n if num % 2 == 0 or num % 3 == 0:\n return False\...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00030262", "row_id": 30262, "seed_ids": "[7937, 4479, 4959]" }
0.629788
Codeforces_30262
I
[ "is_prime", "count_prime_sum_subarrays" ]
2
[ [ "count_prime_sum_subarrays", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
de136e03ef9e6663027b4b907d4447d24006eff6
c0d29b01d63aa3f4838ceb8ea6a2202ac068b424
v1.0
instruct
Codeforces
Codeforces_30340_I
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 first row and end at any cell in...
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": "", "prompt_id": "00030340", "row_id": 30340, "seed_ids": "[8150, 2352, 103]" }
0.722609
Codeforces_30340
I
[ "bfs", "max_flow", "max_disjoint_paths" ]
3
[ [ "max_disjoint_paths", "max_flow" ], [ "max_flow", "bfs" ] ]
2
[]
false
[]
false
pytest
false
[]
true
82f395dc790383d11c54298c59253dbfa999c8c2
6cb270522d37d348c8da12f4cfeae5827f4b4312
v1.0
instruct
Codeforces
Codeforces_30359_I
In Byteland, there is a unique festival being celebrated where the town square is decorated with N lights, each capable of shining with a certain brightness. Instead of turning them all on at once, they have a unique rule: there are Q queries, and for each query, a subset of these lights should be turned on to maximize...
def preprocess_brightness(brightness): """ Preprocesses the brightness list to create a prefix sum array. """ prefix_sum = [0] * (len(brightness) + 1) for i in range(len(brightness)): prefix_sum[i+1] = prefix_sum[i] + brightness[i] return prefix_sum def query_brightness(prefix_sum, l, r...
from solution import process_queries def test_single_light(): N, Q = 1, 1 brightness = [5] queries = [(1, 1)] assert process_queries(N, Q, brightness, queries) == [5] def test_multiple_lights_single_query(): N, Q = 5, 1 brightness = [2, 1, 5, 3, 4] queries = [(1, 3)] assert process_que...
[ { "docstring": "Preprocesses the brightness list to create a prefix sum array.", "function_declaration": "def preprocess_brightness(brightness):", "function_name": "preprocess_brightness", "parameter_list": "(brightness)" }, { "docstring": "Uses the preprocessed prefix sum array to calculate...
[ 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_total_brightness(n, q, brightness, queries):\n \"\"\"\n Calculate total brightness for each query.\n \"\"\"\n # Create prefix sum ar...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00030359", "row_id": 30359, "seed_ids": "[1789, 2009, 4049]" }
0.672826
Codeforces_30359
I
[ "preprocess_brightness", "query_brightness", "process_queries" ]
3
[ [ "process_queries", "preprocess_brightness" ], [ "process_queries", "query_brightness" ] ]
2
[ "process_queries" ]
false
[]
false
pytest
true
[]
true
5dc898251b84ce72acb47b8b909e1c888506bfff
104533673800a10cb8deb1134ea18687beed8770
v1.0
instruct
Codeforces
Codeforces_30385_I
You are given a grid with R rows and C columns. Each cell in the grid contains a letter from 'A' to 'Z'. A step consists of moving from one cell to an adjacent cell north, south, east, or west. You are to determine the length of the longest path you can take in this grid such that no cell is visited more than once and ...
def longest_unique_path(grid, R, C): directions = [(0, 1), (1, 0), (0, -1), (-1, 0)] def dfs(x, y, visited): max_length = 0 for dx, dy in directions: nx, ny = x + dx, y + dy if 0 <= nx < R and 0 <= ny < C and grid[nx][ny] not in visited: visited.add(g...
def test_longest_unique_path(): grid = [ "ABCD", "EFGH", "IJKL", "MNOP" ] R, C = 4, 4 result = find_longest_path(R, C, grid) assert result == 16 def test_single_cell(): grid = ["A"] R, C = 1, 1 result = find_longest_path(R, C, grid) assert result == 1...
[ { "docstring": null, "function_declaration": "def longest_unique_path(grid, R, C):", "function_name": "longest_unique_path", "parameter_list": "(grid, R, C)" }, { "docstring": null, "function_declaration": "def find_longest_path(R, C, grid):", "function_name": "find_longest_path", ...
[ 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 longest_unique_path(R, C, grid):\n def is_valid(x, y, visited):\n return 0 <= x < R and 0 <= y < C and grid[x][y] not in visited\n\n def dfs(...
trial_gpt4o_4
{ "original_instruction": "", "prompt_id": "00030385", "row_id": 30385, "seed_ids": "[3043, 1394, 4531]" }
0.736129
Codeforces_30385
I
[ "longest_unique_path", "find_longest_path" ]
2
[ [ "find_longest_path", "longest_unique_path" ] ]
1
[]
false
[]
false
pytest
false
[]
true
7a1f4c3b718033737f7e0c7b81a22fc91a6afbf6
dfeabb0cb3cc879fd4ca921f9c6c0223c87d036e
v1.0
instruct
Codeforces
Codeforces_30390_I
Alex is organizing a sports tournament in his school and he has to schedule matches between teams. Each match is a pair between two distinct teams, and each team should compete against every other team exactly once. Alex wants to know the schedule of matches for a given number of teams. Your task is to write a progr...
def generate_tournament_schedule(n): """ Returns a list of matches for the tournament. Each match is represented as a tuple (team1, team2). """ matches = [] for i in range(1, n): for j in range(i+1, n+1): matches.append((i, j)) return matches def print_tournament_schedul...
from solution import generate_tournament_schedule, print_tournament_schedule def test_generate_tournament_schedule(): assert generate_tournament_schedule(2) == [(1, 2)] assert generate_tournament_schedule(3) == [(1, 2), (1, 3), (2, 3)] assert generate_tournament_schedule(4) == [(1, 2), (1, 3), (1, 4), (2, ...
[ { "docstring": "Returns a list of matches for the tournament. Each match is represented\nas a tuple (team1, team2).", "function_declaration": "def generate_tournament_schedule(n):", "function_name": "generate_tournament_schedule", "parameter_list": "(n)" }, { "docstring": "Prints the schedul...
[ 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 generate_tournament_schedule(n):\n \"\"\"\n Generates the schedule for a tournament with n teams, where each team plays\n against every other tea...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00030390", "row_id": 30390, "seed_ids": "[1641, 4819, 880]" }
0.699297
Codeforces_30390
I
[ "generate_tournament_schedule", "print_tournament_schedule" ]
2
[ [ "print_tournament_schedule", "generate_tournament_schedule" ] ]
1
[]
false
[]
false
pytest
true
[]
true
e16bad60c4c2f17c17c99bd520c7dfa221dafee4
7444bfcc4b58c9b4f62646f685018e24340f46d0
v1.0
instruct
Codeforces
Codeforces_30462_I
A town needs to be connected via power lines. The town has `n` electrical nodes, some of which are already directly connected by power lines. The goal is to determine the minimum cost to connect all the nodes such that each node is reachable from every other node. The town can be represented as an undirected graph wit...
def find(parent, i): if parent[i] == i: return i else: return find(parent, parent[i]) def union(parent, rank, x, y): root_x = find(parent, x) root_y = find(parent, y) if rank[root_x] < rank[root_y]: parent[root_x] = root_y elif rank[root_x] > rank[root_y]: p...
from solution import minimum_cost_to_connect_nodes def test_example_case(): n = 4 m = 4 edges = [ (1, 2, 1), (2, 3, 4), (3, 4, 2), (4, 1, 3) ] assert minimum_cost_to_connect_nodes(n, edges) == 6 def test_all_nodes_already_connected(): n = 3 m = 3 edges =...
[ { "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, 1, 0, 0 ]
1
hard
0.111
{ "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 return find(parent, parent[i])\n\ndef union(parent, rank, x, y):\n rootX = find(parent,...
trial_gpt4o_6
{ "original_instruction": "", "prompt_id": "00030462", "row_id": 30462, "seed_ids": "[2179, 6926, 4126]" }
0.739568
Codeforces_30462
I
[ "find", "union", "minimum_cost_to_connect_nodes" ]
3
[ [ "minimum_cost_to_connect_nodes", "find" ], [ "minimum_cost_to_connect_nodes", "union" ], [ "union", "find" ] ]
3
[]
false
[]
false
pytest
true
[]
true
612839004bb027853b538a8c3c4f079080c858b5
24d71054df62fff5efe5805e036baa30efd4cee4
v1.0
instruct
Codeforces
Codeforces_30526_I
Fedor is exploring mysterious ancient ruins and has discovered a large library of ancient texts. Each text is inscribed with a sequence of symbols and has an associated value. Fedor believes that if he can find a subset of these texts whose concatenated string of symbols is a palindrome, he will uncover the secret of t...
def is_palindrome(s): return s == s[::-1] def max_palindrome_subset_value(texts): n = len(texts) # Separate texts into palindrome and non-palindrome groups palindromes = [] non_palindromes = [] for s, v in texts: if is_palindrome(s): palindromes.append((s, v)) else: ...
from solution import solve def test_example(): texts = [ ("abc", 10), ("cba", 20), ("bb", 30), ("a", 15) ] assert solve(texts) == 45 def test_single_text_palindrome(): texts = [ ("racecar", 50) ] assert solve(texts) == 50 def test_single_text_non_palind...
[ { "docstring": null, "function_declaration": "def is_palindrome(s):", "function_name": "is_palindrome", "parameter_list": "(s)" }, { "docstring": null, "function_declaration": "def max_palindrome_subset_value(texts):", "function_name": "max_palindrome_subset_value", "parameter_li...
[ 0, 0, 0, 0, 0, 1, 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": "def is_palindrome(s):\n return s == s[::-1]\n\ndef find_maximum_palindrome_value(texts):\n n = len(texts)\n\n # Split the te...
trial_gpt4o_6
{ "original_instruction": "", "prompt_id": "00030526", "row_id": 30526, "seed_ids": "[878, 7034, 7575]" }
0.763087
Codeforces_30526
I
[ "is_palindrome", "max_palindrome_subset_value", "solve" ]
3
[ [ "max_palindrome_subset_value", "is_palindrome" ], [ "solve", "max_palindrome_subset_value" ] ]
2
[]
false
[]
false
pytest
true
[]
true
67c82602de5236ad444f7aa031632f485e44ca83
45ca33f5ffa838d02ab2c409dbf89ea1be5ee630
v1.0
instruct
Codeforces
Codeforces_30593_I
In a fictional country called Algoria, there are `n` towns connected by `m` bidirectional roads forming an undirected graph. You are to design a railway network that connects all towns such that: 1. The total cost of building the railway is minimized. 2. Each town can be reached from any other town, directly or indire...
def find(parent, i): if parent[i] == i: return i else: parent[i] = find(parent, parent[i]) return parent[i] def union(parent, rank, x, y): root_x = find(parent, x) root_y = find(parent, y) if root_x != root_y: if rank[root_x] > rank[root_y]: parent[r...
def test_example_case(): n = 4 m = 5 edges = [ (1, 2, 10), (1, 3, 6), (1, 4, 5), (2, 3, 15), (3, 4, 4) ] assert minimum_spanning_tree(n, m, edges) == 19 def test_case_min_edges(): n = 2 m = 1 edges = [(1, 2, 1)] assert minimum_spanning_tree(n,...
[ { "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, 1, 0 ]
1
hard
0.111
{ "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_8
{ "original_instruction": "", "prompt_id": "00030593", "row_id": 30593, "seed_ids": "[4669, 7868, 7682]" }
0.744462
Codeforces_30593
I
[ "find", "union", "minimum_spanning_tree", "run" ]
4
[ [ "minimum_spanning_tree", "find" ], [ "minimum_spanning_tree", "union" ], [ "run", "minimum_spanning_tree" ], [ "union", "find" ] ]
4
[]
false
[]
false
pytest
false
[]
true
db046228c1f9dc075915b964936cffc6ba3e7f9f
654e49babd28e0765892ccc4e8d956092a1e15d5
v1.0
instruct
Codeforces
Codeforces_30599_I
Olivia is a music enthusiast and loves to organize her music library. Her music collection consists of clips of various genres, and each clip has a unique identifier, a genre identifier, a name, and lyrics. She wants a program to identify the genre of any given clip based on her training set of clips. The training set...
import os from collections import Counter import re from sklearn.feature_extraction.text import TfidfVectorizer from sklearn.naive_bayes import MultinomialNB from sklearn.pipeline import make_pipeline def load_training_data(training_path): texts = [] labels = [] for genre in ['1', '2', '3', '4']: g...
import pytest from solution import train_genre_classifier, predict_genre # Here we are assuming a function that creates a temporary training directory with known data. from tempfile import TemporaryDirectory import os def create_temp_training_data(base_dir): os.makedirs(os.path.join(base_dir, '1'), exist_ok=True)...
[ { "docstring": null, "function_declaration": "def load_training_data(training_path):", "function_name": "load_training_data", "parameter_list": "(training_path)" }, { "docstring": null, "function_declaration": "def clean_text(text):", "function_name": "clean_text", "parameter_lis...
[ 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": "import os\nimport zipfile\nfrom collections import Counter\nfrom sklearn.feature_extraction.text import TfidfVectorizer\nfrom sklearn.naive_bayes import Multi...
trial_gpt4o_3
{ "original_instruction": "", "prompt_id": "00030599", "row_id": 30599, "seed_ids": "[6148, 376, 5371]" }
0.508875
Codeforces_30599
I
[ "load_training_data", "clean_text", "train_genre_classifier", "predict_genre" ]
4
[ [ "predict_genre", "clean_text" ], [ "train_genre_classifier", "clean_text" ], [ "train_genre_classifier", "load_training_data" ] ]
3
[]
false
[]
false
pytest
true
[ "sklearn" ]
false
e5610c9bbeb028443b1c411b7e8a7dc3e11d883a
6d2275c265f4c645ab65448c016ff58289c1366e
v1.0
instruct
Codeforces
Codeforces_30636_I
Problem: You are given an undirected graph with n nodes and m edges. The graph is represented by an adjacency matrix. Your task is to determine the minimum number of colors required to color the graph such that no two adjacent nodes share the same color. A valid coloring assigns a color to each node such that adjacent...
def is_safe(node, color, graph, c): for i in range(len(graph)): if graph[node][i] == 1 and color[i] == c: return False return True def graph_coloring_util(graph, m, color, node): if node == len(graph): return True for c in range(1, m+1): if is_safe(node, color, grap...
from solution import find_min_colors def test_case_1(): n = 4 m = 4 adj_matrix = [ "0 1 1 0", "1 0 1 0", "1 1 0 1", "0 0 1 0" ] adj_matrix = [row.split() for row in adj_matrix] assert find_min_colors(n, m, adj_matrix) == 3 def test_case_2(): n = 5 m = 4 ...
[ { "docstring": null, "function_declaration": "def is_safe(node, color, graph, c):", "function_name": "is_safe", "parameter_list": "(node, color, graph, c)" }, { "docstring": null, "function_declaration": "def graph_coloring_util(graph, m, color, node):", "function_name": "graph_color...
[ 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_safe(node, color, graph, c):\n for i in range(len(graph)):\n if graph[node][i] == 1 and color[i] == c:\n return False\n return ...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00030636", "row_id": 30636, "seed_ids": "[6192, 5712, 32]" }
0.690461
Codeforces_30636
I
[ "is_safe", "graph_coloring_util", "min_colors", "find_min_colors" ]
4
[ [ "find_min_colors", "min_colors" ], [ "graph_coloring_util", "is_safe" ], [ "min_colors", "graph_coloring_util" ] ]
3
[]
false
[]
false
pytest
true
[]
true
b362231f4085f72de6cecb1eb21c0e22dab81da5
f714493e99351b635dedf435e8db1be6e1147f76
v1.0
instruct
Codeforces
Codeforces_30669_I
Leo has recently started exploring the world of binary trees. He has learned how to construct binary trees and traverse them, but now he wants to understand more complex operations. He is particularly interested in reading about Binary Search Trees (BST) and how they maintain certain order properties. To deepen his un...
class TreeNode: def __init__(self, val=0, left=None, right=None): self.val = val self.left = left self.right = right def is_valid_bst(root, min_val=float('-inf'), max_val=float('inf')): if not root: return True if not (min_val < root.val < max_val): return False...
def test_is_bst(): assert is_bst(3, [(8, 3, 10), (3, -1, 6), (10, -1, -1), (6, 4, 7), (4, -1, -1), (7, -1, -1)]) == "YES" assert is_bst(3, [(8, 3, 10), (3, 6, -1), (10, -1, -1), (6, 4, 7), (4, -1, -1), (7, -1, -1)]) == "NO" assert is_bst(3, [(5, 1, 4), (1, -1, -1), (4, 3, 6), (3, -1, -1), (6, -1, -1)]) == "...
[]
[ 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": "class TreeNode:\n def __init__(self, val=0, left=None, right=None):\n self.val = val\n self.left = left\n sel...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00030669", "row_id": 30669, "seed_ids": "[3814, 1602, 3720]" }
0.659068
Codeforces_30669
I
[ "is_valid_bst", "create_tree_from_nodes", "is_bst" ]
3
[ [ "is_bst", "create_tree_from_nodes" ], [ "is_bst", "is_valid_bst" ] ]
2
[]
false
[ "TreeNode" ]
true
pytest
false
[]
true
f96a599f3cd7f4d793eddf3bb2596482e389e5ae
66544c80e99e2534128fe3f5bec8ae30e1a42cb1
v1.0
instruct
Codeforces
Codeforces_30731_I
You're tasked with generating security codes for a new, high profile software release. Each code must be a unique combination of alphanumeric characters that meets the following criteria: 1. It should be exactly 10 characters long. 2. At least one character should be a digit. 3. At least one character should be an upp...
import string def is_valid_code(code): digits = any(char.isdigit() for char in code) uppercases = any(char.isupper() for char in code) lowercases = any(char.islower() for char in code) no_repeats = all(code[i] != code[i+1] for i in range(len(code) - 1)) if len(code) == 10 and digits and upperc...
def test_is_valid_code(): assert is_valid_code("Aa1bcdefgh") == True assert is_valid_code("1234567890") == False assert is_valid_code("aaBBccDDyy") == False assert is_valid_code("Aa1bB2cD3e") == True def test_determine_changes(): assert determine_changes("1234567890") == ["Change a character to an ...
[ { "docstring": null, "function_declaration": "def is_valid_code(code):", "function_name": "is_valid_code", "parameter_list": "(code)" }, { "docstring": null, "function_declaration": "def determine_changes(code):", "function_name": "determine_changes", "parameter_list": "(code)" ...
[ 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 validate_security_code(code):\n \"\"\"\n Validate a single security code and return the result as either \"VALID\" or a list of changes needed.\n ...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00030731", "row_id": 30731, "seed_ids": "[2092, 814, 3386]" }
0.56677
Codeforces_30731
I
[ "is_valid_code", "determine_changes", "validate_codes", "check_security_codes" ]
4
[ [ "check_security_codes", "validate_codes" ], [ "validate_codes", "determine_changes" ], [ "validate_codes", "is_valid_code" ] ]
3
[]
false
[]
false
pytest
false
[]
true
98502ee4e8d2898b0f974b715f06c180c7d1b9fd
a15acee18f39e3aa84abba371b4f6ee34cf6c9a4
v1.0
instruct
Codeforces
Codeforces_30855_I
There are several houses scattered in a city, connected by roads. Each house has a certain number of residents and each road has a certain length. You, as the city planner, want to ensure that all houses are connected in a way that minimizes the total road length while also balancing the population served by each clust...
class UnionFind: def __init__(self, size): self.parent = list(range(size)) self.rank = [0] * size def find(self, u): if self.parent[u] != u: self.parent[u] = self.find(self.parent[u]) return self.parent[u] def union(self, u, v): root_u = self.find(u) ...
def test_optimal_partition(): n, m = 5, 7 residents = [10, 20, 30, 40, 50] edges = [ (1, 2, 10), (1, 3, 20), (2, 3, 30), (2, 4, 40), (3, 4, 50), (3, 5, 60), (4, 5, 70) ] assert optimal_partition(n, residents, edges) == (60, 10) def test_single...
[]
[ 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 itertools\nimport heapq\n\ndef find_road_connections(n, m, residents, roads):\n # Step 1: Use Kruskal's algorithm to find the minimum spanning tree ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00030855", "row_id": 30855, "seed_ids": "[4544, 3795, 3388]" }
0.638889
Codeforces_30855
I
[ "kruskal", "min_diff_partition", "optimal_partition" ]
3
[ [ "optimal_partition", "kruskal" ], [ "optimal_partition", "min_diff_partition" ] ]
2
[]
false
[ "UnionFind" ]
true
pytest
false
[]
true
e7e2dbaba3fc82b45167a5f7b371e6e765a88bc1
21bcff6827aeaa867b4ca60ab350e82b72df4cda
v1.0
instruct
Codeforces
Codeforces_30860_I
Gina is the manager of a warehouse and she has a square matrix consisting of integers where each cell $(i, j)$ represents the quantity of a product at that location. She wants to know if there's any square submatrix where the sum of all its elements is equal to a given value $k$. You are tasked to help Gina by writin...
def does_submatrix_with_sum_exist(n, k, matrix): def get_prefix_sum(matrix): prefix_sum = [[0] * (n + 1) for _ in range(n + 1)] for i in range(n): for j in range(n): prefix_sum[i + 1][j + 1] = matrix[i][j] + prefix_sum[i + 1][j] + prefix_sum[i][j + 1] - prefix_sum[i][j] ...
from solution import find_submatrix_with_sum def test_example_1(): n = 3 k = 10 matrix = [ [1, 2, 3], [4, 5, 1], [7, 8, 9] ] assert find_submatrix_with_sum(n, k, matrix) == "YES" def test_example_2(): n = 3 k = 20 matrix = [ [1, 2, 3], [4, 5, 1],...
[ { "docstring": null, "function_declaration": "def does_submatrix_with_sum_exist(n, k, matrix):", "function_name": "does_submatrix_with_sum_exist", "parameter_list": "(n, k, matrix)" }, { "docstring": null, "function_declaration": "def find_submatrix_with_sum(n, k, matrix):", "functio...
[ 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 has_submatrix_with_sum(matrix, n, k):\n \"\"\"\n Determines if there exists at least one submatrix with sum equal to k.\n \n Args:\n matrix...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00030860", "row_id": 30860, "seed_ids": "[5169, 5596, 567]" }
0.675837
Codeforces_30860
I
[ "does_submatrix_with_sum_exist", "find_submatrix_with_sum" ]
2
[ [ "find_submatrix_with_sum", "does_submatrix_with_sum_exist" ] ]
1
[]
false
[]
false
pytest
true
[]
true
f4f1b83fe850f51e8bd331381c2478b8b55b6362
edaed4335c5d326678b25fd451ed509dc426f111
v1.0
instruct
Codeforces
Codeforces_30865_I
You are given a grid of size $$$n \times m$$$ where some cells contain obstacles and some cells are empty. You start at the top-left corner of the grid, and your goal is to reach the bottom-right corner. You can move to any of the adjacent cells in the directions up, down, left, or right, but you cannot leave the gri...
from collections import deque def shortest_path(grid, n, m): directions = [(-1, 0), (1, 0), (0, -1), (0, 1)] # up, down, left, right visited = [[False] * m for _ in range(n)] queue = deque([(0, 0, 0)]) # (row, col, distance) visited[0][0] = True while queue: r, c, dist = queue.popleft() ...
from solution import find_shortest_path def test_shortest_path_1(): input_data = "3 3\n..#\n.#.\n..." assert find_shortest_path(input_data) == 4 def test_shortest_path_2(): input_data = "3 3\n.#.\n###\n.#." assert find_shortest_path(input_data) == -1 def test_shortest_path_3(): input_data = "1 1\...
[ { "docstring": null, "function_declaration": "def shortest_path(grid, n, m):", "function_name": "shortest_path", "parameter_list": "(grid, n, m)" }, { "docstring": null, "function_declaration": "def parse_input(input_str):", "function_name": "parse_input", "parameter_list": "(inp...
[ 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 deque\n\ndef shortest_path(grid, n, m):\n directions = [(-1, 0), (1, 0), (0, -1), (0, 1)] # up, down, left, right\n visited = [...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00030865", "row_id": 30865, "seed_ids": "[7852, 6907, 8004]" }
0.765716
Codeforces_30865
I
[ "shortest_path", "parse_input", "find_shortest_path" ]
3
[ [ "find_shortest_path", "parse_input" ], [ "find_shortest_path", "shortest_path" ] ]
2
[ "parse_input" ]
false
[]
false
pytest
true
[]
true
9854478a497fc972521011f36e5658e3ce7f01b6
5c52005391300fe14dfb6d641138a669492d4315
v1.0
instruct
Codeforces
Codeforces_30873_I
You are given a tree with n nodes, where 1 ≤ n ≤ 100. The tree is rooted at node 1. Each node, excluding the root, has exactly one parent node. Your task is to find the diameter of this tree, which is the longest path between any two nodes. Input: The first line contains an integer n, the number of nodes in the tree...
from collections import defaultdict, deque def tree_diameter(n, edges): if n == 1: return 0 # Build the adjacency list graph = defaultdict(list) for u, v in edges: graph[u].append(v) graph[v].append(u) # Helper function to perform BFS and return the farthest node and its d...
def test_tree_diameter_single_node(): assert solve(1, []) == 0 def test_tree_diameter_simple_case(): assert solve(5, [(1, 2), (1, 3), (2, 4), (2, 5)]) == 3 def test_tree_diameter_line_shape_tree(): assert solve(4, [(1, 2), (2, 3), (3, 4)]) == 3 def test_tree_diameter_star_shape_tree(): assert solve(5...
[ { "docstring": null, "function_declaration": "def tree_diameter(n, edges):", "function_name": "tree_diameter", "parameter_list": "(n, edges)" }, { "docstring": null, "function_declaration": "def solve(n, edges):", "function_name": "solve", "parameter_list": "(n, edges)" }, { ...
[ 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": "def find_tree_diameter(n, edges):\n from collections import defaultdict, deque\n \n # Create adjacency list representation o...
trial_gpt4o_4
{ "original_instruction": "", "prompt_id": "00030873", "row_id": 30873, "seed_ids": "[4684, 4, 4685]" }
0.675294
Codeforces_30873
I
[ "tree_diameter", "solve" ]
2
[ [ "solve", "tree_diameter" ] ]
1
[]
false
[]
false
pytest
false
[]
true
142855a855d3d7f174b94aa72db5ead4c0ebacc6
ffc3b15e8843628391e471416a7d8f76192a9fb9
v1.0
instruct
Codeforces
Codeforces_30914_I
Given an integer array `arr` of size `n` (1 ≤ n ≤ 100000) consisting of positive integers, and an integer `k` (1 ≤ k ≤ 50000), find the length of the shortest subarray such that the sum of the subarray is greater than or equal to `k`. If no such subarray exists, return -1. The first line of the input contains two inte...
def shortest_subarray_with_sum(arr, k): n = len(arr) min_length = float('inf') current_sum = 0 start = 0 for end in range(n): current_sum += arr[end] while current_sum >= k: min_length = min(min_length, end - start + 1) current_sum -= arr[start] ...
from solution import solution def test_example_case(): assert solution(10, 15, [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 2 def test_no_valid_subarray(): assert solution(5, 20, [1, 2, 3, 4, 5]) == -1 def test_whole_array_as_result(): assert solution(5, 15, [5, 1, 2, 3, 4]) == 5 def test_single_element_valid_su...
[ { "docstring": null, "function_declaration": "def shortest_subarray_with_sum(arr, k):", "function_name": "shortest_subarray_with_sum", "parameter_list": "(arr, k)" }, { "docstring": null, "function_declaration": "def solution(n, k, arr):", "function_name": "solution", "parameter_...
[ 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 shortest_subarray_length(arr, k):\n \"\"\"\n Finds the length of the shortest subarray with sum >= k.\n \"\"\"\n n = len(arr)\n shortest_le...
trial_gpt4o_4
{ "original_instruction": "", "prompt_id": "00030914", "row_id": 30914, "seed_ids": "[4063, 6394, 547]" }
0.850424
Codeforces_30914
I
[ "shortest_subarray_with_sum", "solution" ]
2
[ [ "solution", "shortest_subarray_with_sum" ] ]
1
[]
false
[]
false
pytest
true
[]
true
080b6de7b3fbd94e3fcfad607f4e0299480e142d
12ed802f185715aacc9da472c7d1b51e7cbf846c
v1.0
instruct
Codeforces
Codeforces_30953_I
In the mystical land of Codoria, land developers have the formidable task of creating pathways between various cities. The cities are modeled as nodes, and the potential pathways between cities are modeled as weighted edges in a graph. The goal is to construct a connected, spanning path that minimizes the total cost. ...
def find(parent, i): if parent[i] == i: return i else: return find(parent, parent[i]) def union(parent, rank, x, y): root_x = find(parent, x) root_y = find(parent, y) if rank[root_x] < rank[root_y]: parent[root_x] = root_y elif rank[root_x] > rank[root_y]: p...
from solution import minimum_spanning_tree def test_case_1(): n, m = 4, 5 pathways = [ (1, 2, 3), (2, 3, 4), (1, 3, 1), (1, 4, 6), (3, 4, 2) ] assert minimum_spanning_tree(n, m, pathways) == 6 def test_case_2(): n, m = 4, 4 pathways = [ (1, 2, 1)...
[ { "docstring": null, "function_declaration": "def find(parent, i):", "function_name": "find", "parameter_list": "(parent, i)" }, { "docstring": null, "function_declaration": "def union(parent, rank, x, y):", "function_name": "union", "parameter_list": "(parent, rank, x, y)" }, ...
[ 0, 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(parent, i):\n if parent[i] == i:\n return i\n return find(parent, parent[i])\n\ndef union(parent, rank, x, y):\n root_x = find(parent...
trial_gpt4o_5
{ "original_instruction": "", "prompt_id": "00030953", "row_id": 30953, "seed_ids": "[6582, 5977, 1509]" }
0.718162
Codeforces_30953
I
[ "find", "union", "minimum_spanning_tree" ]
3
[ [ "minimum_spanning_tree", "find" ], [ "minimum_spanning_tree", "union" ], [ "union", "find" ] ]
3
[]
false
[]
false
pytest
true
[]
true
4ba9b59083567df5fe015e3ffbff40843c44c545
be5ccfe99159fc5a35a757678701239297be9751
v1.0
instruct
Codeforces
Codeforces_30969_I
In a city, there is a system of one-way streets connecting intersections. Intersections are numbered from 1 to n. Each street can be represented as a directed edge from one intersection to another. A street network can be described as a directed graph where intersections are vertices and streets are edges. Given two ...
from collections import defaultdict, deque def build_graph(n, edges): graph = defaultdict(list) reverse_graph = defaultdict(list) for u, v in edges: graph[u].append(v) reverse_graph[v].append(u) return graph, reverse_graph def bfs(graph, start): visited = set() queue = deque([s...
from solution import has_multiple_paths def test_case_1(): n = 5 m = 6 edges = [ (1, 2), (2, 3), (3, 4), (4, 5), (1, 3), (3, 5) ] queries = [ (1, 5), (1, 3), (2, 5) ] expected_output = ["YES", "YES", "NO"] assert has_multiple_paths(n, edges, queries) == expected_output ...
[ { "docstring": null, "function_declaration": "def build_graph(n, edges):", "function_name": "build_graph", "parameter_list": "(n, edges)" }, { "docstring": null, "function_declaration": "def bfs(graph, start):", "function_name": "bfs", "parameter_list": "(graph, start)" }, { ...
[ 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": "from collections import defaultdict, deque\n\ndef find_paths(n, edges, queries):\n def bfs_multiple_paths(source, target):\n \"\"\"\n Perform...
trial_gpt4o_6
{ "original_instruction": "", "prompt_id": "00030969", "row_id": 30969, "seed_ids": "[4390, 1753, 838]" }
0.745795
Codeforces_30969
I
[ "build_graph", "bfs", "has_multiple_paths", "main" ]
4
[ [ "has_multiple_paths", "bfs" ], [ "has_multiple_paths", "build_graph" ] ]
2
[]
false
[]
false
pytest
true
[]
true
a13827092f501f488a7eb416ed96306ebd9aadb6
e8bc3943908ea09e3526babb183b75f257955851