version
stringclasses
1 value
style
stringclasses
2 values
subset
stringclasses
12 values
question_id
stringlengths
9
23
question
stringlengths
27
8.13k
solution
stringlengths
99
5.97k
test
stringlengths
105
4.45k
test_info
listlengths
0
13
gpt_pass_sequence
listlengths
1
10
gpt_pass_trial_num
int64
1
10
gpt_difficulty
stringclasses
3 values
gpt_pass_percentage
float64
0.1
1
trials
dict
chosen_trial
stringclasses
10 values
metadata
dict
benchmark_similarity
float64
0.16
0.93
benchmark_instruction
stringclasses
1 value
benchmark_task_id
stringclasses
1 value
filter_reason
stringclasses
1 value
base_id
stringlengths
7
21
variant
stringclasses
2 values
top_function_names
listlengths
2
13
n_top_functions
int64
2
13
helper_call_edges
listlengths
1
16
n_helper_call_edges
int64
1
16
harness_functions
listlengths
0
3
structural_wrapper
bool
1 class
class_names
listlengths
0
5
has_class
bool
2 classes
test_kind
stringclasses
1 value
test_has_solution_import
bool
2 classes
third_party_imports
listlengths
0
5
stdlib_only
bool
2 classes
question_norm_sha1
stringlengths
40
40
solution_ast_sha1
stringlengths
40
40
v1.0
complete
Codeforces
Codeforces_35201_C
import heapq import sys from typing import List, Tuple def find_optimal_planet(n: int, edges: List[Tuple[int, int, int]]) -> int: """ Finds the optimal planet for the central command such that the maximum travel cost to all other planets is minimized. >>> find_optimal_planet(5, [(1, 2, 3), (1, 3, 4), (2, 4, 2)...
import heapq import sys def dijkstra(graph, n, start): # Initial distances are set to infinity distances = [sys.maxsize] * (n + 1) distances[start] = 0 # Priority queue to process nodes priority_queue = [(0, start)] while priority_queue: current_distance, u = heapq.heappop(priority...
def test_optimal_planet_simple_case(): n = 5 edges = [ (1, 2, 3), (1, 3, 4), (2, 4, 2), (2, 5, 3), (3, 4, 1), (4, 5, 5) ] assert find_optimal_planet(n, edges) == 2 def test_optimal_planet_tie_case(): n = 4 edges = [ (1, 2, 1), (2, ...
[ { "docstring": null, "function_declaration": "def dijkstra(graph, n, start):", "function_name": "dijkstra", "parameter_list": "(graph, n, start)" }, { "docstring": null, "function_declaration": "def find_optimal_planet(n, edges):", "function_name": "find_optimal_planet", "paramet...
[ 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\nfrom collections import defaultdict\n\ndef dijkstra(n, graph, start):\n \"\"\"\n Performs Dijkstra's algorithm to find the shortest path f...
trial_gpt4o_2
{ "original_instruction": "In a distant galaxy, there are n planets that form a galactic network connected by m bidirectional paths. Each path directly connects two planets and has a certain travel cost associated with it. The Galactic Federation has decided to establish a central command on one of these planets, fro...
0.581565
Codeforces_35201
C
[ "dijkstra", "find_optimal_planet" ]
2
[ [ "find_optimal_planet", "dijkstra" ] ]
1
[]
false
[]
false
pytest
false
[]
true
cb5f7bda3dcceae600ea915cba527c1f8606e4b6
5a5acab3d13403aa5eff6f75abe6c6a7c2d85cec
v1.0
complete
Codeforces
Codeforces_35227_C
def minimum_spanning_tree(v: int, e: int, edges: List[Tuple[int, int, int]]) -> int: """ You are given a weighted graph with `v` vertices and `e` edges. The vertices are numbered from 0 to `v-1`. Each edge has a positive weight. Your task is to find the weight of the minimum spanning tree (MST) of the graph. ...
def find(parent, i): if parent[i] == i: return i return find(parent, parent[i]) def union(parent, rank, x, y): root_x = find(parent, x) root_y = find(parent, y) if rank[root_x] < rank[root_y]: parent[root_x] = root_y elif rank[root_x] > rank[root_y]: parent[root_y] = roo...
from solution import minimum_spanning_tree def test_example_1(): vertices = 4 edges_count = 5 edges = [ (0, 1, 10), (0, 2, 6), (0, 3, 5), (1, 3, 15), (2, 3, 4) ] assert minimum_spanning_tree(vertices, edges_count, edges) == 19 def test_example_2(): verti...
[ { "docstring": null, "function_declaration": "def find(parent, i):", "function_name": "find", "parameter_list": "(parent, i)" }, { "docstring": null, "function_declaration": "def union(parent, rank, x, y):", "function_name": "union", "parameter_list": "(parent, rank, x, y)" }, ...
[ 0, 1, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def find(parent, i):\n if parent[i] == i:\n return i\n else:\n return find(parent, parent[i])\n\ndef union(parent, rank, x, y):\n rootX...
trial_gpt4o_2
{ "original_instruction": "You are given a weighted graph with $$$v$$$ vertices and $$$e$$$ edges. The vertices are numbered from $$$0$$$ to $$$v-1$$$. Each edge has a positive weight. Your task is to find the weight of the minimum spanning tree (MST) of the graph.\n\nA spanning tree of a connected graph is a subgrap...
0.77548
Codeforces_35227
C
[ "find", "union", "kruskal_mst", "minimum_spanning_tree" ]
4
[ [ "kruskal_mst", "find" ], [ "kruskal_mst", "union" ], [ "minimum_spanning_tree", "kruskal_mst" ], [ "union", "find" ] ]
4
[]
false
[]
false
pytest
true
[]
true
31dafd3d8b03e76f308ec9d851bd5f9d86ab6cf5
257b44b64a1be2b10e2641033c5ff98e776b72ea
v1.0
complete
Codeforces
Codeforces_34729_C
from typing import List, Tuple def minimum_spanning_tree(n: int, edges: List[Tuple[int, int, int]], c: int) -> int: """ Given a connected, undirected graph with n vertices and m edges, each having an initial weight, calculate the minimum possible total weight of the MST under the condition that each edge's wei...
def find(parent, i): if parent[i] == i: return i parent[i] = find(parent, parent[i]) return parent[i] def union(parent, rank, x, y): root_x = find(parent, x) root_y = find(parent, y) if root_x != root_y: if rank[root_x] > rank[root_y]: parent[root_y] = root_x ...
def test_minimum_spanning_tree(): edges_1 = [ (0, 1, 5), (0, 2, 10), (0, 3, 3), (1, 2, 6), (2, 3, 7) ] assert minimum_spanning_tree(4, edges_1, 2) == 14 # Using initial weights for MST edges edges_2 = [ (0, 1, 4), (0, 2, 9), (0, 3, 15), ...
[ { "docstring": null, "function_declaration": "def find(parent, i):", "function_name": "find", "parameter_list": "(parent, i)" }, { "docstring": null, "function_declaration": "def union(parent, rank, x, y):", "function_name": "union", "parameter_list": "(parent, rank, x, y)" }, ...
[ 0, 0, 0, 0, 0, 0, 0, 0, 1 ]
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 xroot = find(parent,...
trial_gpt4o_8
{ "original_instruction": "You are given a connected, undirected graph with `n` vertices and `m` edges. Each edge has an integer weight associated with it. Your task is to remove some of the edges to form a Minimum Spanning Tree (MST) of the graph. However, there is a special requirement: the weight of an edge you re...
0.747119
Codeforces_34729
C
[ "find", "union", "minimum_spanning_tree" ]
3
[ [ "minimum_spanning_tree", "find" ], [ "minimum_spanning_tree", "union" ], [ "union", "find" ] ]
3
[]
false
[]
false
pytest
false
[]
true
3320bbfa42a1db67101b5f084c6a6eb89ac2f0ea
5ca7fc8fa31d5f289d6567ddd69ba50dd7effd72
v1.0
complete
Codeforces
Codeforces_35329_C
def lcs(s1: str, s2: str) -> str: """ Returns the longest common subsequence of s1 and s2. """ pass def lexicographically_smallest_permutation(lcs_str: str) -> str: """ Returns the lexicographically smallest permutation of the string lcs_str. """ pass def smallest_lcs_permutation(s1: s...
def lcs(s1, s2): """ Returns the longest common subsequence of s1 and s2. """ m = len(s1) n = len(s2) # Create a 2D array to store the lengths of longest common subsequence dp = [[0] * (n+1) for _ in range(m+1)] # Fill dp array for i in range(m): for j in range(n): ...
def test_lcs(): assert lcs("abcbdab", "bdcaba") == "bdab" assert lcs("XMJYAUZ", "MZJAWXU") == "MJAU" assert lcs("abc", "abc") == "abc" assert lcs("abc", "def") == "" assert lcs("a", "a") == "a" def test_lexicographically_smallest_permutation(): assert lexicographically_smallest_permutation("bda...
[ { "docstring": "Returns the longest common subsequence of s1 and s2.", "function_declaration": "def lcs(s1, s2):", "function_name": "lcs", "parameter_list": "(s1, s2)" }, { "docstring": "Returns the lexicographically smallest permutation of the string lcs_str.", "function_declaration": "...
[ 0, 0, 0, 0, 0, 0, 0, 1, 0, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def longest_common_subsequence(s1, s2):\n \"\"\"\n Finds the Longest Common Subsequence (LCS) of s1 and s2.\n Returns the LCS as a string.\n \"\"\...
trial_gpt4o_7
{ "original_instruction": "Alice and Bob are playing a game with strings. They have two strings, `s1` and `s2`, each consisting of lowercase English letters. The game involves finding the longest common subsequence (LCS) of `s1` and `s2` — a sequence that appears in both strings in the same order but not necessarily ...
0.666582
Codeforces_35329
C
[ "lcs", "lexicographically_smallest_permutation", "smallest_lcs_permutation" ]
3
[ [ "smallest_lcs_permutation", "lcs" ], [ "smallest_lcs_permutation", "lexicographically_smallest_permutation" ] ]
2
[]
false
[]
false
pytest
false
[]
true
20a487bc259b18146a3e759280badf6cdc0808da
e94912b83c620ebcd42ddfca663c081bc0076136
v1.0
complete
Codeforces
Codeforces_35342_C
from typing import Union def iahub_string_rearrangement(n: int, s: str) -> Union[str, int]: """ Iahub likes playing with strings and puzzles. He came up with an interesting problem for you. You are given a string `s` of length `n` consisting of lowercase English letters. Iahub wants to rearrange the letter...
from collections import Counter import heapq def rearrange_string(s): n = len(s) freq_counter = Counter(s) # max heap by frequency max_heap = [(-freq, char) for char, freq in freq_counter.items()] heapq.heapify(max_heap) prev_char = None prev_freq = 0 result = [] whil...
def test_3_characters_no_adjacent(): assert iahub_string_rearrangement(3, "aab") in ["aba"] def test_2_same_characters_not_possible(): assert iahub_string_rearrangement(2, "aa") == -1 def test_single_character(): assert iahub_string_rearrangement(1, "a") == "a" def test_no_possible_rearrangement(): a...
[ { "docstring": null, "function_declaration": "def rearrange_string(s):", "function_name": "rearrange_string", "parameter_list": "(s)" }, { "docstring": null, "function_declaration": "def iahub_string_rearrangement(n, s):", "function_name": "iahub_string_rearrangement", "parameter...
[ 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 Counter\nimport heapq\n\ndef rearrange_string(s: str) -> str:\n count = Counter(s)\n max_heap = [(-freq, char) for char, freq in...
trial_gpt4o_1
{ "original_instruction": "Iahub likes playing with strings and puzzles. He came up with an interesting problem for you. \n\nYou are given a string $$$s$$$ of length $$$n$$$ consisting of lowercase English letters. Iahub wants to rearrange the letters of the string in such a way that there are no two adjacent charact...
0.711365
Codeforces_35342
C
[ "rearrange_string", "iahub_string_rearrangement" ]
2
[ [ "iahub_string_rearrangement", "rearrange_string" ] ]
1
[]
false
[]
false
pytest
false
[]
true
af2d9343b266d5be928a746c6904d22f28d63fcb
e09b147a8a531652ac8146e975a8b29621ddbf68
v1.0
complete
Codeforces
Codeforces_35119_C
def find_minimum_travel_expenses(input_data: str): """ Given the number of castles, roads connecting them and their tolls, compute the minimum travel expenses in gold coins for each possible pair of castles. >>> input_data = "4 5\n1 2 1\n2 3 2\n3 4 1\n4 1 2\n1 3 1\n" >>> find_minimum_travel_expenses(in...
def floyd_warshall(p, q, roads): INF = float('inf') dist = [[INF] * p for _ in range(p)] for i in range(p): dist[i][i] = 0 for a, b, c in roads: dist[a-1][b-1] = c dist[b-1][a-1] = c for k in range(p): for i in range(p): for j in range(p): ...
from solution import find_minimum_travel_expenses def test_example_case(): input_data = "4 5\n1 2 1\n2 3 2\n3 4 1\n4 1 2\n1 3 1\n" expected_output = [ [0, 1, 1, 2], [1, 0, 2, 3], [1, 2, 0, 1], [2, 3, 1, 0], ] assert find_minimum_travel_expenses(input_data) == expected_ou...
[ { "docstring": null, "function_declaration": "def floyd_warshall(p, q, roads):", "function_name": "floyd_warshall", "parameter_list": "(p, q, roads)" }, { "docstring": null, "function_declaration": "def parse_input(input_data):", "function_name": "parse_input", "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 floyd_warshall(p, q, roads):\n # Initialize distances\n dist = [[float('inf')] * p for _ in range(p)]\n \n for i in range(p):\n dist[i]...
trial_gpt4o_2
{ "original_instruction": "In a faraway kingdom, there exist p castles connected by q roads. Each road connects two different castles, allowing travel in both directions. However, the kingdom's transportation system is unique. Each road has a toll associated with it – some roads are free (toll of zero) while others c...
0.616736
Codeforces_35119
C
[ "floyd_warshall", "parse_input", "find_minimum_travel_expenses" ]
3
[ [ "find_minimum_travel_expenses", "floyd_warshall" ], [ "find_minimum_travel_expenses", "parse_input" ] ]
2
[ "parse_input" ]
false
[]
false
pytest
true
[]
true
35564cbcc596bf695b2a5fc96403d1d2f8f5e9c8
7c781e7948795c48e62d617a02174c3930842148
v1.0
complete
Codeforces
Codeforces_34887_C
def split_into_sublists(n: int, S: int, integers: List[int]) -> List[List[int]]: """ Split the list into the minimum number of sublists such that the sum of the integers in each sublist does not exceed the given maximum allowable total sum. >>> split_into_sublists(6, 10, [2, 7, 1, 4, 3, 8]) == [[2, 7, 1], [4, 3...
def split_into_sublists(n, S, integers): result = [] current_sublist = [] current_sum = 0 for num in integers: if current_sum + num > S: result.append(current_sublist) current_sublist = [num] current_sum = num else: current_sublist.app...
from solution import split_into_sublists, number_of_sublists def test_split_into_sublists(): assert split_into_sublists(6, 10, [2, 7, 1, 4, 3, 8]) == [[2, 7, 1], [4, 3], [8]] assert split_into_sublists(6, 5, [2, 7, 1, 4, 3, 8]) == [[2], [7], [1, 4], [3], [8]] assert split_into_sublists(1, 1, [1]) == [[1]] ...
[ { "docstring": null, "function_declaration": "def split_into_sublists(n, S, integers):", "function_name": "split_into_sublists", "parameter_list": "(n, S, integers)" }, { "docstring": null, "function_declaration": "def number_of_sublists(n, S, integers):", "function_name": "number_of...
[ 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 split_list(n, S, nums):\n \"\"\"\n Splits the list into the minimum number of sublists such that the sum of the \n integers in each sublist does ...
trial_gpt4o_1
{ "original_instruction": "You are given a list of integers and a maximum allowable total sum. Your task is to split the list into the minimum number of sublists such that the sum of the integers in each sublist does not exceed the given maximum allowable total sum.\n\nThe input consists of:\n- The first line contain...
0.624615
Codeforces_34887
C
[ "split_into_sublists", "number_of_sublists" ]
2
[ [ "number_of_sublists", "split_into_sublists" ] ]
1
[]
false
[]
false
pytest
true
[]
true
cd829063f994f7db3dee98491746be4d4238e1fd
205097cdd1727ce8e6c18707c8e2705f99200f6d
v1.0
complete
Codeforces
Codeforces_35521_C
def fibonacci(n: int) -> int: """Function to calculate the nth Fibonacci number. >>> fibonacci(0) 0 >>> fibonacci(1) 1 >>> fibonacci(5) 5 >>> fibonacci(10) 55 """ def is_prime(n: int) -> bool: """Function to determine if a number n is prime. >>> is_prime(2) ...
def fibonacci(n): """ Function to calculate the nth Fibonacci number. """ if n <= 0: return 0 elif n == 1: return 1 a, b = 0, 1 for _ in range(2, n + 1): a, b = b, a + b return b def is_prime(n): """ Function to determine if a number n is prime. """ ...
from solution import fibonacci, is_prime, is_fibonacci_prime def test_fibonacci(): assert fibonacci(0) == 0 assert fibonacci(1) == 1 assert fibonacci(2) == 1 assert fibonacci(3) == 2 assert fibonacci(4) == 3 assert fibonacci(5) == 5 assert fibonacci(10) == 55 def test_is_prime(): asser...
[ { "docstring": "Function to calculate the nth Fibonacci number.", "function_declaration": "def fibonacci(n):", "function_name": "fibonacci", "parameter_list": "(n)" }, { "docstring": "Function to determine if a number n is prime.", "function_declaration": "def is_prime(n):", "functio...
[ 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 fibonacci(n):\n \"\"\"\n Returns the n-th Fibonacci number.\n \"\"\"\n if n == 0:\n return 0\n elif n == 1:\n return 1\n a...
trial_gpt4o_2
{ "original_instruction": "Alex has a deep interest in the Fibonacci sequence and prime numbers. Recently, Alex came across an interesting problem and needs your help to solve it. \n\nThe Fibonacci sequence is defined as follows:\n- \\( F(0) = 0 \\)\n- \\( F(1) = 1 \\)\n- \\( F(n) = F(n-1) + F(n-2) \\) for \\( n \\ge...
0.84657
Codeforces_35521
C
[ "fibonacci", "is_prime", "is_fibonacci_prime" ]
3
[ [ "is_fibonacci_prime", "fibonacci" ], [ "is_fibonacci_prime", "is_prime" ] ]
2
[]
false
[]
false
pytest
true
[]
true
2e51e5420eb6f33656f6d6ef40239b48d9777f6e
4332bc060c19dddeaf724a98c8a3ae0e5cb20cb5
v1.0
complete
Codeforces
Codeforces_35487_C
def is_prime(num: int) -> bool: """ Check if the given number is a prime. >>> is_prime(2) True >>> is_prime(4) False >>> is_prime(29) True """ pass def get_rotations(num: int) -> List[int]: """ Generate all rotations of a given number. >>> get_rotations(197) [197...
def is_prime(num): """ Check if the given number is a prime. """ if num < 2: 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...
from solution import count_circular_primes, is_prime, get_rotations, is_circular_prime def test_is_prime(): assert is_prime(2) == True assert is_prime(3) == True assert is_prime(4) == False assert is_prime(29) == True assert is_prime(25) == False def test_get_rotations(): assert get_rotations(...
[ { "docstring": "Check if the given number is a prime.", "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": "Generate all rotations of a given number.", "function_declaration": "def get_rotations(num):", "function_nam...
[ 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(num):\n if num <= 1:\n return False\n if num == 2:\n return True\n if num % 2 == 0:\n return False\n for i in ra...
trial_gpt4o_2
{ "original_instruction": "Stanley loves puzzles and has discovered a new type of number which he calls 'circular primes'. A circular prime is a prime number that remains prime under all rotations of its digits. For example, 197 is a circular prime because all of its rotations (197, 971, and 719) are prime. Stanley w...
0.679743
Codeforces_35487
C
[ "is_prime", "get_rotations", "is_circular_prime", "count_circular_primes" ]
4
[ [ "count_circular_primes", "is_circular_prime" ], [ "is_circular_prime", "get_rotations" ], [ "is_circular_prime", "is_prime" ] ]
3
[]
false
[]
false
pytest
true
[]
true
c802c7c7efcfe2553ece60aa691e7d988ec94022
2e325718a663321ebe429f383e0f008a7894173a
v1.0
complete
Codeforces
Codeforces_35638_C
from typing import List from math import gcd from functools import reduce def lcm(a: int, b: int) -> int: """ Calculate the Least Common Multiple of two integers. """ pass def first_common_on_time(cycles: List[int]) -> int: """ Given a list of cycle durations of signals, find the first time in second...
from math import gcd from functools import reduce def lcm(a, b): """ Calculate the Least Common Multiple of two integers. """ return a * b // gcd(a, b) def first_common_on_time(cycles): """ Given a list of cycle durations of signals, find the first time in seconds when all the signals are...
from solution import first_common_on_time def test_common_case(): assert first_common_on_time([3, 4]) == 12 assert first_common_on_time([5, 7, 9]) == 315 def test_single_signal(): assert first_common_on_time([10]) == 10 def test_large_cycles(): assert first_common_on_time([10**9, 10**9 + 1]) == (10**...
[ { "docstring": "Calculate the Least Common Multiple of two integers.", "function_declaration": "def lcm(a, b):", "function_name": "lcm", "parameter_list": "(a, b)" }, { "docstring": "Given a list of cycle durations of signals, find the first time in seconds \nwhen all the signals are on simu...
[ 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 functools import reduce\nimport math\n\ndef lcm(a, b):\n \"\"\"\n Calculate the Least Common Multiple of two numbers.\n \"\"\"\n return a * b...
trial_gpt4o_2
{ "original_instruction": "You are given a program that controls a complex signaling system in a factory. The system consists of multiple signals that need to turn on and off following a specific pattern. Each signal operates in its own unique cycle, specified in seconds. For example, a signal with a cycle of 5 secon...
0.62168
Codeforces_35638
C
[ "lcm", "first_common_on_time" ]
2
[ [ "first_common_on_time", "lcm" ] ]
1
[]
false
[]
false
pytest
true
[]
true
b0fa0504aa05e33feab24ddeda27e302ddf162ff
aa5b302c5c1cac149117d7df497d1353e05ddbb8
v1.0
complete
Codeforces
Codeforces_35147_C
def add_camera(cameras, a, b): """ Add a new camera with range [a, b]. """ cameras.append((a, b)) def count_cameras(cameras, x): """ Given a position x, count the number of cameras covering this position. >>> count_cameras([(1, 5), (2, 6), (8, 10), (3, 4)], 4) 3 >>> count_cameras([...
def add_camera(cameras, a, b): cameras.append((a, b)) def count_cameras(cameras, x): count = 0 for a, b in cameras: if a <= x <= b: count += 1 return count def process_camera_queries(n, q, cameras_data, queries): cameras = [] for a, b in cameras_data: add_camera(cam...
def test_process_camera_queries(): n = 4 q = 3 cameras_data = [(1, 5), (2, 6), (8, 10), (3, 4)] queries = [4, 7, 9] expected_output = [3, 0, 1] assert process_camera_queries(n, q, cameras_data, queries) == expected_output def test_process_camera_queries_single_camera(): n = 1 q = 2 ...
[ { "docstring": null, "function_declaration": "def add_camera(cameras, a, b):", "function_name": "add_camera", "parameter_list": "(cameras, a, b)" }, { "docstring": null, "function_declaration": "def count_cameras(cameras, x):", "function_name": "count_cameras", "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": "from bisect import bisect_left, bisect_right\n\ndef process_queries(n, q, camera_ranges, queries):\n starts = sorted([start for start, end in camera_ranges...
trial_gpt4o_1
{ "original_instruction": "In a small town, there is an advanced surveillance system installed to monitor all residents. The system performs two main tasks: adding a new camera and processing requests to detect the number of cameras currently covering a given location.\n\nEach camera has a fixed range that it covers ...
0.527836
Codeforces_35147
C
[ "add_camera", "count_cameras", "process_camera_queries" ]
3
[ [ "process_camera_queries", "add_camera" ], [ "process_camera_queries", "count_cameras" ] ]
2
[]
false
[]
false
pytest
false
[]
true
fb84aa5955a79247facbb9d642cd95231ae28126
553f2ef346ea9d224c8630c6a6eec8a764f18d14
v1.0
complete
Codeforces
Codeforces_35520_C
from typing import List def min_steps(grid: List[str]) -> int: """ Find the minimum number of steps required to walk from the top-left corner to the bottom-right corner. The walk is valid if the absolute difference between the number of '0's and '1's encountered is at most one. If it's not possible, return...
from collections import deque def is_valid_path(grid, n, m): directions = [(-1, 0), (1, 0), (0, -1), (0, 1)] def bfs(): queue = deque([(0, 0, 0, 0)]) # (row, col, count_0, count_1) visited = set([(0, 0, 0, 0)]) while queue: r, c, count_0, count_1 = queue.pople...
def test_min_steps(): grid = [ '010', '001', '100' ] assert min_steps(grid) == 4 def test_no_path(): grid = [ '111', '111', '111' ] assert min_steps(grid) == -1 def test_simple_path(): grid = [ '00', '10' ] assert min_...
[ { "docstring": null, "function_declaration": "def is_valid_path(grid, n, m):", "function_name": "is_valid_path", "parameter_list": "(grid, n, m)" }, { "docstring": null, "function_declaration": "def min_steps(grid):", "function_name": "min_steps", "parameter_list": "(grid)" }, ...
[ 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 min_steps(grid, n, m):\n \"\"\"\n Returns the minimum number of steps required to reach from top-left to bottom-rig...
trial_gpt4o_2
{ "original_instruction": "You are given a grid of size $$n \\times m$$ filled with characters. Each cell in the grid contains either '0' or '1'. You can only walk from a cell to its neighboring cell in one of the four directions: up, down, left, and right. The walk is considered valid if the absolute difference betw...
0.670193
Codeforces_35520
C
[ "is_valid_path", "min_steps" ]
2
[ [ "min_steps", "is_valid_path" ] ]
1
[]
false
[]
false
pytest
false
[]
true
f789727bc8203330eb0ce1b61de36a19514a7b3a
5be70cbeaea66a85cafae0c759ceb7e1bf4893a0
v1.0
complete
Codeforces
Codeforces_35403_C
import heapq import sys from typing import List, Tuple def min_travel_distance(n: int, m: int, roads: List[Tuple[int, int, int]]) -> int: """ Computes the minimum travel distance from intersection 1 to intersection n using the given roads. If there is no path, returns -1. >>> min_travel_distance(5, 6, [(1,...
import heapq import sys def dijkstra(n, adj): # Distance to each node, initialized as infinity dist = [sys.maxsize] * (n + 1) dist[1] = 0 # Min heap to get the node with the smallest distance heap = [(0, 1)] while heap: current_dist, u = heapq.heappop(heap) if...
def test_min_travel_distance(): assert min_travel_distance(5, 6, [(1, 2, 2), (1, 3, 4), (2, 3, 1), (2, 4, 7), (3, 5, 3), (4, 5, 1)]) == 6 assert min_travel_distance(3, 2, [(1, 2, 2), (2, 3, 3)]) == 5 assert min_travel_distance(4, 4, [(1, 2, 1), (1, 3, 4), (2, 3, 2), (3, 4, 1)]) == 4 assert min_travel_di...
[ { "docstring": null, "function_declaration": "def dijkstra(n, adj):", "function_name": "dijkstra", "parameter_list": "(n, adj)" }, { "docstring": null, "function_declaration": "def min_travel_distance(n, m, roads):", "function_name": "min_travel_distance", "parameter_list": "(n, ...
[ 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 heapq\nfrom collections import defaultdict\nimport sys\n\ndef find_min_distance(n, m, roads):\n \"\"\"\n Returns the minimum distance from inters...
trial_gpt4o_3
{ "original_instruction": "You are given a city with `n` intersections and `m` bidirectional roads. Each road has a length associated with it. Bob wants to find out the minimum travel distance he would need to go from intersection `1` to intersection `n`. Write a program that computes this minimum distance using the ...
0.709647
Codeforces_35403
C
[ "dijkstra", "min_travel_distance" ]
2
[ [ "min_travel_distance", "dijkstra" ] ]
1
[]
false
[]
false
pytest
false
[]
true
e6d1d754679b653727d023354f1376fa55e645be
65534d0334760ca39bce4b17148625268d57ce41
v1.0
complete
Codeforces
Codeforces_35409_C
def build_inverted_index(documents): """ Returns an inverted index from the given documents. """ pass def query_inverted_index(inverted_index, query_words): """ Returns the list of document indices for each query word. """ pass def process_documents_and_queries(doc_input, query_input):...
def build_inverted_index(documents): """ Returns an inverted index from the given documents. """ from collections import defaultdict inverted_index = defaultdict(list) for doc_id, doc in enumerate(documents, 1): words = doc.split() for word in words: if doc_id no...
def test_build_inverted_index(): documents = [ "hello world", "this is a test", "hello again", "test the inverted index" ] result = build_inverted_index(documents) expected = { 'hello': [1, 3], 'world': [1], 'this': [2], 'is': [2], ...
[ { "docstring": "Returns an inverted index from the given documents.", "function_declaration": "def build_inverted_index(documents):", "function_name": "build_inverted_index", "parameter_list": "(documents)" }, { "docstring": "Returns the list of document indices for each query word.", "f...
[ 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 create_inverted_index(documents):\n \"\"\"\n Create an inverted index from the given list of documents.\n \"\"\"\n inverted_index = {}\n fo...
trial_gpt4o_2
{ "original_instruction": "Inverted Index is a fundamental methodology that many search engines use to perform efficient textual searches. In this task, you are required to create an inverted index from a set of documents, and then perform queries on that index to find documents that contain specific words.\n\n### Ex...
0.485682
Codeforces_35409
C
[ "build_inverted_index", "query_inverted_index", "process_documents_and_queries" ]
3
[ [ "process_documents_and_queries", "build_inverted_index" ], [ "process_documents_and_queries", "query_inverted_index" ] ]
2
[]
false
[]
false
pytest
false
[]
true
39fb37890b659de97cbeed6e76867747ad232b40
40b569ceaf16ebe54ce1cdb13bfd8b72e5e53072
v1.0
complete
Codeforces
Codeforces_35518_C
def check_graph_connected(n: int, m: int, edges: List[Tuple[int, int]]) -> str: """ Determine whether the graph is connected or not. A graph is connected if there is a path between any pair of distinct nodes. Args: n (int): The number of nodes in the graph. m (int): The number of edges in the ...
def is_connected(n, m, edges): from collections import defaultdict, deque if n == 1: return True # Create adjacency list adj_list = defaultdict(list) for u, v in edges: adj_list[u].append(v) adj_list[v].append(u) # BFS to check connectivity visited = se...
def test_check_graph_connected(): assert check_graph_connected(4, 3, [(1, 2), (2, 3), (3, 4)]) == "YES" def test_check_graph_not_connected(): assert check_graph_connected(4, 2, [(1, 2), (3, 4)]) == "NO" def test_single_node_graph(): assert check_graph_connected(1, 0, []) == "YES" def test_two_nodes_conne...
[ { "docstring": null, "function_declaration": "def is_connected(n, m, edges):", "function_name": "is_connected", "parameter_list": "(n, m, edges)" }, { "docstring": null, "function_declaration": "def check_graph_connected(n, m, edges):", "function_name": "check_graph_connected", "...
[ 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_connected_graph(n, m, edges):\n from collections import defaultdict, deque\n\n # Create adjacency list\n adj_list = defaultdict(list)\n for...
trial_gpt4o_1
{ "original_instruction": "You are given an undirected graph with n nodes and m edges. Each node is labeled with a unique integer from 1 to n. The graph may contain multiple edges between the same pair of nodes and self-loops.\n\nYour task is to determine whether the graph is connected or not. A graph is connected if...
0.655063
Codeforces_35518
C
[ "is_connected", "check_graph_connected" ]
2
[ [ "check_graph_connected", "is_connected" ] ]
1
[]
false
[]
false
pytest
false
[]
true
4f1e7c1847850ee286cdc186c5dc29a37da4e1a9
01cb36df161b6712ad00353d41d6ac1e3d0009f8
v1.0
complete
Codeforces
Codeforces_35581_C
def findMinMaxTaskTime(n: int, m: int, tasks: List[int]) -> int: """ Determine the minimum possible maximum task completion time for any employee when the tasks are distributed optimally. >>> findMinMaxTaskTime(5, 2, [4, 7, 8, 3, 1]) 12 >>> findMinMaxTaskTime(3, 3, [1, 2, 3]) 3 >>> find...
def canDistribute(tasks, n, m, maxTime): """ This function checks if it is possible to distribute all tasks among 'm' employees such that no employee spends more than 'maxTime' on their tasks. """ employeesUsed = 1 currentTime = 0 for task in tasks: if currentTime + task > maxTi...
from solution import findMinMaxTaskTime def test_distribute_tasks_case_1(): assert findMinMaxTaskTime(5, 2, [4, 7, 8, 3, 1]) == 12 def test_distribute_tasks_case_2(): assert findMinMaxTaskTime(3, 3, [1, 2, 3]) == 3 def test_distribute_tasks_case_3(): assert findMinMaxTaskTime(4, 2, [10, 10, 10, 10]) == 2...
[ { "docstring": "This function checks if it is possible to distribute all tasks among 'm' employees\nsuch that no employee spends more than 'maxTime' on their tasks.", "function_declaration": "def canDistribute(tasks, n, m, maxTime):", "function_name": "canDistribute", "parameter_list": "(tasks, n, m...
[ 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 check(mid, tasks, m):\n current_sum = 0\n count = 1 # At least one employee is necessary\n for task in tasks:\n if current_sum + task > m...
trial_gpt4o_2
{ "original_instruction": "Paolo is a manager who needs to distribute a set of tasks among his employees. Each task takes a certain amount of time to complete. Paolo wants to minimize the maximum time taken by any employee to complete all their assigned tasks. To achieve this, he can distribute the tasks in any way h...
0.637435
Codeforces_35581
C
[ "canDistribute", "findMinMaxTaskTime" ]
2
[ [ "findMinMaxTaskTime", "canDistribute" ] ]
1
[]
false
[]
false
pytest
true
[]
true
3c141618ca4889283b893c3b56fc7864c5bd2d39
b1ba510ee75645e181366dc1a932d0d4e8a23d56
v1.0
complete
Codeforces
Codeforces_35380_C
from typing import List, Tuple def heaviest_edge_in_mst(n: int, m: int, edges: List[Tuple[int, int, int]]) -> int: """ You are given an undirected, connected graph with `n` vertices and `m` edges. Each edge `(u, v)` has a non-negative weight `w`. Determine the minimum spanning tree (MST) of the graph and ...
import heapq def find(parent, i): if parent[i] == i: return i else: parent[i] = find(parent, parent[i]) return parent[i] def union(parent, rank, x, y): root_x = find(parent, x) root_y = find(parent, y) if rank[root_x] < rank[root_y]: parent[root_x] = root_y ...
def test_example(): n = 4 m = 5 edges = [ (1, 2, 1), (2, 3, 2), (3, 4, 3), (1, 3, 4), (1, 4, 5) ] assert heaviest_edge_in_mst(n, m, edges) == 3 def test_single_edge(): n = 2 m = 1 edges = [(1, 2, 10)] assert heaviest_edge_in_mst(n, m, 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)" }, ...
[ 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": "import heapq\n\ndef find(parent, i):\n if parent[i] == i:\n return i\n else:\n parent[i] = find(parent, parent[i])\n return parent[...
trial_gpt4o_0
{ "original_instruction": "You are given an undirected, connected graph with \\( n \\) vertices and \\( m \\) edges. Each edge \\( (u, v) \\) has a non-negative weight \\( w \\). You need to determine the minimum spanning tree (MST) of the graph and then find the heaviest edge in the MST.\n\nThe MST of a graph is a s...
0.717671
Codeforces_35380
C
[ "find", "union", "kruskal_mst", "heaviest_edge_in_mst" ]
4
[ [ "heaviest_edge_in_mst", "kruskal_mst" ], [ "kruskal_mst", "find" ], [ "kruskal_mst", "union" ], [ "union", "find" ] ]
4
[]
false
[]
false
pytest
false
[]
true
254607d78038f5d2e7b60a29cdcaec946224d68f
e90dc7377220f42ce37ffc5d4e7fce88943edf2d
v1.0
complete
Codeforces
Codeforces_35788_C
def sieve_of_eratosthenes(limit): primes = [] is_prime = [True] * (limit + 1) is_prime[0] = is_prime[1] = False for number in range(2, limit + 1): if is_prime[number]: primes.append(number) for multiple in range(number * number, limit + 1, number): is...
def sieve_of_eratosthenes(limit): primes = [] is_prime = [True] * (limit + 1) is_prime[0] = is_prime[1] = False for number in range(2, limit + 1): if is_prime[number]: primes.append(number) for multiple in range(number * number, limit + 1, number): is...
from solution import prime_decomposition def test_prime_decomposition_6(): assert prime_decomposition(6) == [2, 2, 2] def test_prime_decomposition_10(): assert prime_decomposition(10) == [2, 2, 2, 2, 2] def test_prime_decomposition_13(): assert prime_decomposition(13) == [13] def test_prime_decompositio...
[ { "docstring": null, "function_declaration": "def sieve_of_eratosthenes(limit):", "function_name": "sieve_of_eratosthenes", "parameter_list": "(limit)" }, { "docstring": null, "function_declaration": "def prime_decomposition(n):", "function_name": "prime_decomposition", "paramete...
[ 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 decompose_to_primes(n):\n \"\"\"\n Decompose the given integer into the sum of the maximum number of prime numbers with the smallest lexicographical...
trial_gpt4o_2
{ "original_instruction": "Cryptographer Alice is working on a new type of cipher to encode messages. She decided to use prime numbers as the main tool for encoding. Given a positive integer n, she wants to decompose it into the sum of the maximum number of prime numbers. If there are multiple ways to achieve this, s...
0.644461
Codeforces_35788
C
[ "sieve_of_eratosthenes", "prime_decomposition" ]
2
[ [ "prime_decomposition", "sieve_of_eratosthenes" ] ]
1
[]
false
[]
false
pytest
true
[]
true
70be44f1237a047ad6d341121a5475800ee6eb59
7164accc3b7dabf5a771f12c95511004efdd1019
v1.0
complete
Codeforces
Codeforces_35556_C
def maximal_rectangle(R: int, C: int, garden: List[List[str]]) -> int: """ Grigor is a passionate gardener who loves planting flowers. He has a rectangular garden that consists of a grid of cells with R rows and C columns. Each cell can either be empty or contain a flower. Grigor has recently decided to organiz...
def maximal_rectangle(R, C, garden): # Initialize variables max_area = 0 height = [0] * (C + 1) # Adding a sentinel column to simplify the code # Iterate over rows of the garden for row in garden: for j in range(C): if row[j] == '*': height[j] += 1 e...
from solution import maximal_rectangle_from_input def test_example_case(): input_data = "4 5\n.....\n.***.\n.***.\n....." assert maximal_rectangle_from_input(input_data) == 6 def test_single_row(): input_data = "1 5\n.***." assert maximal_rectangle_from_input(input_data) == 3 def test_single_column()...
[ { "docstring": null, "function_declaration": "def maximal_rectangle(R, C, garden):", "function_name": "maximal_rectangle", "parameter_list": "(R, C, garden)" }, { "docstring": null, "function_declaration": "def process_input(data):", "function_name": "process_input", "parameter_l...
[ 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 maximalRectangleArea(R, C, grid):\n # Helper function to calculate maximum area in a histogram\n def largestHistogramArea(heights):\n stack =...
trial_gpt4o_1
{ "original_instruction": "Grigor is a passionate gardener who loves planting flowers. He has a rectangular garden that consists of a grid of cells with R rows and C columns. Each cell can either be empty or contain a flower. Grigor has recently decided to organize his garden by ensuring that he can create a flower b...
0.712602
Codeforces_35556
C
[ "maximal_rectangle", "process_input", "maximal_rectangle_from_input" ]
3
[ [ "maximal_rectangle_from_input", "maximal_rectangle" ], [ "maximal_rectangle_from_input", "process_input" ] ]
2
[ "process_input" ]
false
[]
false
pytest
true
[]
true
ec75a8a63f6531f670df2f9fa28b26b5d8213a77
a05d523e4b173de3831e5d649e0c5b6807201b8a
v1.0
complete
Codeforces
Codeforces_35250_C
from typing import List, Tuple def preprocess_array(arr: List[int]) -> Tuple[List[int], List[List[int]]]: """ Preprocess the input array to create prefix sums and a segment tree for range minima queries. Args: arr (List[int]): The input array of integers. Returns: Tuple containing the prefix ...
def preprocess_array(arr): n = len(arr) # Preprocess prefix sums prefix_sum = [0] * (n + 1) for i in range(n): prefix_sum[i + 1] = prefix_sum[i] + arr[i] # Preprocess segment tree for range minima queries import math st = [[0] * (math.ceil(math.log2(n))+1) for _ in range(n)] ...
import pytest from solution import preprocess_array, range_sum, range_minimum, answer_queries def test_preprocess_array(): arr = [1, 2, 7, 4, 5, 3, 6, 8] prefix_sum, st = preprocess_array(arr) assert prefix_sum == [0, 1, 3, 10, 14, 19, 22, 28, 36] # The segment tree can't be easily validated because o...
[ { "docstring": null, "function_declaration": "def preprocess_array(arr):", "function_name": "preprocess_array", "parameter_list": "(arr)" }, { "docstring": null, "function_declaration": "def range_sum(prefix_sum, left, right):", "function_name": "range_sum", "parameter_list": "(p...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def preprocess(arr):\n \"\"\"\n Preprocess the array to generate prefix sums and minimum elements for each subarray.\n \"\"\"\n n = len(arr)\n ...
trial_gpt4o_2
{ "original_instruction": "Given an array of integers, you are required to answer few queries where each query contains two integers left and right. For each query, you need to find subarray sum and the minimum element in the range from left to right (inclusive).\n\nThe array does not change over multiple queries. \n...
0.620932
Codeforces_35250
C
[ "preprocess_array", "range_sum", "range_minimum", "answer_queries" ]
4
[ [ "answer_queries", "preprocess_array" ], [ "answer_queries", "range_minimum" ], [ "answer_queries", "range_sum" ] ]
3
[]
false
[]
false
pytest
true
[]
true
49f8d40edf2f029eab743dbaa317edf6ff39d1ba
bcd926e2d72b6342a772201386827058231a2434
v1.0
complete
Codeforces
Codeforces_35432_C
import heapq from typing import List, Tuple def network_latency(n: int, m: int, cables: List[Tuple[int, int, int]]) -> int: """ Determine the minimum latency required to send data from computer 1 to computer n in a network. Args: n (int): The number of computers. m (int): The number of cables. ...
import heapq def network_latency(n, m, cables): graph = {i: [] for i in range(1, n + 1)} for u, v, l in cables: graph[u].append((v, l)) graph[v].append((u, l)) # Dijkstra's algorithm to find the minimum latency from node 1 to node n pq = [(0, 1)] # (latency, node) latencies = {i: ...
from solution import solve_network_latency_problem def test_case_1(): input_data = "4 4\n1 2 1\n2 3 2\n3 4 1\n1 4 5" assert solve_network_latency_problem(input_data) == 4 def test_case_2(): input_data = "4 3\n1 2 1\n2 3 2\n3 4 1" assert solve_network_latency_problem(input_data) == 4 def test_case_3()...
[ { "docstring": null, "function_declaration": "def network_latency(n, m, cables):", "function_name": "network_latency", "parameter_list": "(n, m, cables)" }, { "docstring": null, "function_declaration": "def solve_network_latency_problem(input_data):", "function_name": "solve_network_...
[ 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": "import heapq\n\ndef minimum_latency(n, m, edges):\n graph = [[] for _ in range(n + 1)]\n for u, v, l in edges:\n graph[u].append((v, l))\n ...
trial_gpt4o_1
{ "original_instruction": "A network of n computers is connected by m bidirectional cables. Each computer in the network is assigned a unique ID from 1 to n. Each cable directly connects exactly two different computers and has a specific latency associated with it.\n\nYour task is to determine the minimum latency req...
0.532557
Codeforces_35432
C
[ "network_latency", "solve_network_latency_problem" ]
2
[ [ "solve_network_latency_problem", "network_latency" ] ]
1
[]
false
[]
false
pytest
true
[]
true
bbae5b04922fa2ba5cb29001d172eb9d4e4ce118
0678916b63d783eeac6cd89775bc365bf8b381f9
v1.0
complete
Codeforces
Codeforces_35605_C
from collections import defaultdict, deque def longest_path_and_min_height(n, edges): """Compute the longest path in the tree (tree diameter) and the minimum height of the binary tree when restructured by selecting any node as the root. Args: n (int): The number of nodes in the tree. edges (List[...
from collections import deque, defaultdict def longestPathAndMinHeight(n, edges): if n == 1: return (0, 0) graph = defaultdict(list) for u, v in edges: graph[u].append(v) graph[v].append(u) def bfs(start): visited = [-1] * (n + 1) q = deque([start]) vi...
def test_example(): assert longestPathAndMinHeight(5, [(1, 2), (1, 3), (3, 4), (3, 5)]) == (3, 2) def test_single_node(): assert longestPathAndMinHeight(1, []) == (0, 0) def test_chain(): assert longestPathAndMinHeight(4, [(1, 2), (2, 3), (3, 4)]) == (3, 2) def test_star(): assert longestPathAndMinHe...
[ { "docstring": null, "function_declaration": "def longestPathAndMinHeight(n, edges):", "function_name": "longestPathAndMinHeight", "parameter_list": "(n, edges)" }, { "docstring": null, "function_declaration": "def solve():", "function_name": "solve", "parameter_list": "()" }, ...
[ 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 deque, defaultdict\n\ndef find_longest_path_and_min_height(n, edges):\n # Build the graph from node edges\n graph = defaultdict(...
trial_gpt4o_1
{ "original_instruction": "You are given a binary tree with `n` nodes. Each node contains a unique integer identifier `NodeID` from `1` to `n`. Your task is to compute the following:\n\n1. The longest path in the tree (also known as the tree diameter).\n2. The minimum height of the binary tree when restructured by se...
0.598867
Codeforces_35605
C
[ "longestPathAndMinHeight", "solve" ]
2
[ [ "solve", "longestPathAndMinHeight" ] ]
1
[]
false
[]
false
pytest
false
[]
true
d9f79b4aeb7367b2d1ee3faa5d7b7be574a8ff4a
8d32705aca72187f3ed3988fe458edee504f5699
v1.0
complete
Codeforces
Codeforces_35537_C
import math from typing import Tuple def lcm(a: int, b: int) -> int: """ Returns the Least Common Multiple (LCM) of a and b. >>> lcm(12, 15) 60 >>> lcm(1, 1) 1 """ return abs(a * b) // math.gcd(a, b) def secret_key(x: int, y: int) -> int: """ Calculate the secret key using the ...
import math def lcm(a, b): """ Returns the Least Common Multiple (LCM) of a and b. """ return abs(a * b) // math.gcd(a, b) def secret_key(x, y): """ Calculate the secret key using the given algorithm. """ lcm1 = lcm(x, y) swapped_lcm = lcm(y, x) return lcm1 + swapped_lcm
from solution import lcm, secret_key def test_lcm(): assert lcm(12, 15) == 60 assert lcm(15, 12) == 60 assert lcm(1, 1) == 1 assert lcm(1, 2) == 2 assert lcm(8, 12) == 24 assert lcm(21, 6) == 42 def test_secret_key(): assert secret_key(12, 15) == 120 assert secret_key(1, 1) == 2 as...
[ { "docstring": "Returns the Least Common Multiple (LCM) of a and b.", "function_declaration": "def lcm(a, b):", "function_name": "lcm", "parameter_list": "(a, b)" }, { "docstring": "Calculate the secret key using the given algorithm.", "function_declaration": "def secret_key(x, y):", ...
[ 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 math\n\ndef lcm(a, b):\n \"\"\"\n Calculate the Least Common Multiple (LCM) of two integers a and b.\n \"\"\"\n return abs(a*b) // math.gcd...
trial_gpt4o_2
{ "original_instruction": "You have been hired as a detective by ACME Corporation to investigate a series of data breaches. In your investigation, you found that the company uses a secret encryption algorithm that involves two numbers, `x` and `y`. The algorithm generates the secret key by finding the Least Common Mu...
0.60102
Codeforces_35537
C
[ "lcm", "secret_key" ]
2
[ [ "secret_key", "lcm" ] ]
1
[]
false
[]
false
pytest
true
[]
true
ddce8095565dbde703c3604a55141e584a7a02eb
3e03fc948465708d34da726852972e1c8a9c6664
v1.0
complete
Codeforces
Codeforces_35987_C
def minimum_total_length(n: int, m: int, edges: List[Tuple[int, int, int]]) -> Union[int, str]: """ Compute the total length of the Minimum Spanning Tree (MST) for the given castles and roads. Args: n (int): Number of castles. m (int): Number of roads. edges (List[Tuple[int, int, int]]): List o...
def find(parent, i): if parent[i] == i: return i return find(parent, parent[i]) def union(parent, rank, x, y): xroot = find(parent, x) yroot = find(parent, y) if rank[xroot] < rank[yroot]: parent[xroot] = yroot elif rank[xroot] > rank[yroot]: parent[yroot] = xroot el...
from solution import minimum_total_length def test_example_1(): n = 4 m = 5 edges = [ (1, 2, 4), (1, 3, 3), (1, 4, 2), (2, 3, 5), (3, 4, 1) ] assert minimum_total_length(n, m, edges) == 7 def test_example_2(): n = 3 m = 0 edges = [] assert mi...
[ { "docstring": null, "function_declaration": "def find(parent, i):", "function_name": "find", "parameter_list": "(parent, i)" }, { "docstring": null, "function_declaration": "def union(parent, rank, x, y):", "function_name": "union", "parameter_list": "(parent, rank, x, y)" }, ...
[ 0, 1, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def find(parent, i):\n while parent[i] != i:\n i = parent[i]\n return i\n\ndef union(parent, rank, x, y):\n root_x = find(parent, x)\n root...
trial_gpt4o_1
{ "original_instruction": "In a kingdom far away, there are n castles connected by m bidirectional roads. Each road connects two castles (u, v) and has a certain length (d). The kingdom needs to maintain an efficient and safe route system to ensure that all castles can communicate with one another directly or indirec...
0.621438
Codeforces_35987
C
[ "find", "union", "kruskal_mst", "minimum_total_length" ]
4
[ [ "kruskal_mst", "find" ], [ "kruskal_mst", "union" ], [ "minimum_total_length", "kruskal_mst" ], [ "union", "find" ] ]
4
[]
false
[]
false
pytest
true
[]
true
4e06b17de6ac33ab2f45253ce78e6407fd3c9b38
ad129ac2104a282d144a00ff48cbc31a01ca189d
v1.0
complete
Codeforces
Codeforces_35726_C
class TreeNode: def __init__(self, val=0, left=None, right=None): self.val = val self.left = left self.right = right def build_tree(in_order, pre_order): """ Build a binary tree given its in-order and pre-order traversal lists. """ def postorder_traversal(root, result=None): ...
class TreeNode: def __init__(self, val=0, left=None, right=None): self.val = val self.left = left self.right = right def build_tree(in_order, pre_order): if not in_order or not pre_order: return None root_val = pre_order.pop(0) root = TreeNode(root_val) root_index ...
from solution import TreeNode, build_tree, postorder_traversal, reconstruct_post_order def test_simple_case(): in_order = [4, 2, 5, 1, 3] pre_order = [1, 2, 4, 5, 3] expected_post_order = [4, 5, 2, 3, 1] assert reconstruct_post_order(5, in_order, pre_order) == expected_post_order def test_single_node(...
[]
[ 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": "class TreeNode:\n def __init__(self, x):\n self.val = x\n self.left = None\n self.right = None\n\ndef build_tree(in_order, pre_order):...
trial_gpt4o_2
{ "original_instruction": "Given two arrays, `in_order` and `pre_order`, representing the in-order and pre-order traversal of a binary tree, respectively, construct the binary tree.\n\nThe in-order traversal of a binary tree is the sequence in which the nodes are visited in the order: Left subtree, Root, Right subtre...
0.548942
Codeforces_35726
C
[ "build_tree", "postorder_traversal", "reconstruct_post_order" ]
3
[ [ "reconstruct_post_order", "build_tree" ], [ "reconstruct_post_order", "postorder_traversal" ] ]
2
[]
false
[ "TreeNode" ]
true
pytest
true
[]
true
348f2ff52ebbdaa7a187fbf84100fdfb993af7e0
447e595aeedf30a5e630354ab854095e640e5a80
v1.0
complete
Codeforces
Codeforces_35844_C
def is_beautiful_array(arr) -> str: """ Determines if the array contains an arithmetic progression of three elements. >>> is_beautiful_array([3, 6, 9, 12, 15]) "YES" >>> is_beautiful_array([1, 2, 4]) "NO" """ # Write your code here def check_beautiful_array(n, elements): return...
def is_beautiful_array(arr): """ Determines if the array contains an arithmetic progression of three elements. """ arr_set = set(arr) n = len(arr) for i in range(n): for j in range(i+1, n): num1, num2 = arr[i], arr[j] diff = num2 - num1 next_num =...
def test_is_beautiful_array(): assert check_beautiful_array(5, [3, 6, 9, 12, 15]) == "YES" assert check_beautiful_array(4, [1, 2, 3, 5]) == "YES" assert check_beautiful_array(3, [1, 2, 4]) == "NO" assert check_beautiful_array(7, [10, 20, 30, 40, 50, 60, 25]) == "YES" assert check_beautiful_array(8, ...
[ { "docstring": "Determines if the array contains an arithmetic progression of three elements.", "function_declaration": "def is_beautiful_array(arr):", "function_name": "is_beautiful_array", "parameter_list": "(arr)" }, { "docstring": null, "function_declaration": "def check_beautiful_ar...
[ 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_beautiful_array(arr):\n \"\"\"\n Determine whether the given array contains an arithmetic progression of three elements.\n \n :param arr: L...
trial_gpt4o_2
{ "original_instruction": "Vrohacs recently became interested in a type of sequence they call \"beautiful arrays.\" An array of integers is called beautiful if it contains an arithmetic progression of three elements. Your task is to help Vrohacs determine whether a given array is beautiful or not.\n\nAn array of inte...
0.520445
Codeforces_35844
C
[ "is_beautiful_array", "check_beautiful_array" ]
2
[ [ "check_beautiful_array", "is_beautiful_array" ] ]
1
[]
false
[]
false
pytest
false
[]
true
b464ed0e231ed737eefa1ee6749c0515c74718b6
20170fdda885da47dc2c76c777737746160f8992
v1.0
complete
Codeforces
Codeforces_34985_C
from typing import List, Tuple def solve(n: int, q: int, edges: List[Tuple[int, int, int]], queries: List[Tuple[int, int]]) -> List[int]: """ You are given an undirected tree of n nodes and n-1 edges, where each node is numbered from 1 to n. Each edge has a weight. You are also given q queries. In each qu...
from collections import defaultdict, deque def preprocess_tree(n, edges): """ Preprocess the tree to find the parent, and the maximum weight edge to reach each node """ tree = defaultdict(list) for u, v, w in edges: tree[u].append((v, w)) tree[v].append((u, w)) parent =...
def test_example(): n = 5 q = 3 edges = [ (1, 2, 3), (2, 3, 4), (2, 4, 5), (4, 5, 1) ] queries = [ (2, 5), (1, 3), (3, 4) ] expected_output = [5, 4, 5] assert solve(n, q, edges, queries) == expected_output def test_chain_tree(): ...
[ { "docstring": "Preprocess the tree to find the parent, and the maximum weight edge to reach each node", "function_declaration": "def preprocess_tree(n, edges):", "function_name": "preprocess_tree", "parameter_list": "(n, edges)" }, { "docstring": null, "function_declaration": "def find_...
[ 0, 0, 0, 1, 1 ]
2
medium
0.4
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "from collections import defaultdict, deque\n\ndef preprocess_tree(edges, n):\n \"\"\"\n Constructs the adjacency list of the tree and preprocesses the r...
trial_gpt4o_4
{ "original_instruction": "You are given an undirected tree of n nodes and n-1 edges, where each node is numbered from 1 to n. Each edge has a weight. You are also given q queries. In each query, you are given two nodes u and v, and you need to determine the maximum weighted edge on the unique path between u and v in...
0.674188
Codeforces_34985
C
[ "preprocess_tree", "find_max_edge_endpoint", "solve" ]
3
[ [ "solve", "find_max_edge_endpoint" ], [ "solve", "preprocess_tree" ] ]
2
[]
false
[]
false
pytest
false
[]
true
e3e033b62bc5d6541aa244bffdb23380be79f72b
c803e117192339e26d30356a9a257e68b69bd31d
v1.0
complete
Codeforces
Codeforces_36021_C
def minimal_max_distance(n: int, m: int, roads: List[Tuple[int, int, int]]) -> int: """ Determine the minimum possible value of the maximum distances on the roads in the optimal routes between all pairs of towns. >>> minimal_max_distance(4, 5, [(1, 2, 5), (2, 3, 6), (3, 4, 2), (1, 3, 10), (1, 4, 8)]) 6 ...
def find(parent, i): if parent[i] == i: return i else: parent[i] = find(parent, parent[i]) return parent[i] def union(parent, rank, x, y): xroot = find(parent, x) yroot = find(parent, y) if rank[xroot] < rank[yroot]: parent[xroot] = yroot elif rank[xroot] > rank...
import pytest from solution import minimal_max_distance def test_example(): n = 4 m = 5 roads = [ (1, 2, 5), (2, 3, 6), (3, 4, 2), (1, 3, 10), (1, 4, 8) ] assert minimal_max_distance(n, m, roads) == 6 def test_small_case(): n = 2 m = 1 roads = [ ...
[ { "docstring": null, "function_declaration": "def find(parent, i):", "function_name": "find", "parameter_list": "(parent, i)" }, { "docstring": null, "function_declaration": "def union(parent, rank, x, y):", "function_name": "union", "parameter_list": "(parent, rank, x, y)" }, ...
[ 1, 0, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def find(parent, i):\n if parent[i] == i:\n return i\n else:\n parent[i] = find(parent, parent[i])\n return parent[i]\n\ndef union(...
trial_gpt4o_0
{ "original_instruction": "The kingdom of Silvergrove is known for its intricate cobblestone roads connecting several towns in the kingdom. There are `n` towns labeled from 1 to `n` and `m` roads connecting these towns bidirectionally. Each road has a certain distance associated with it. The kingdom's wise ruler want...
0.737529
Codeforces_36021
C
[ "find", "union", "is_possible", "minimal_max_distance" ]
4
[ [ "is_possible", "find" ], [ "is_possible", "union" ], [ "minimal_max_distance", "is_possible" ], [ "union", "find" ] ]
4
[]
false
[]
false
pytest
true
[]
true
a1b8bb5b6216988747311b924d74884071d8b2eb
747367753deaae4c4eed24dc7a999f3c68b20fc6
v1.0
complete
Codeforces
Codeforces_35757_C
import itertools from typing import List def minMaxGenreWeight(n: int, k: int, weights: List[int]) -> int: """ Distributes books into k genres such that the maximum total weight of any genre group is minimized. Parameters: n (int): Number of books k (int): Number of genres weights (List[i...
def canDistribute(weights, n, k, maxWeight): current_sum = 0 required_genres = 1 for weight in weights: if current_sum + weight > maxWeight: required_genres += 1 current_sum = weight if required_genres > k: return False el...
def test_scenario1(): assert minMaxGenreWeight(5, 3, [10, 20, 30, 40, 50]) == 60 def test_scenario2(): assert minMaxGenreWeight(6, 2, [10, 10, 10, 10, 10, 10]) == 30 def test_scenario3(): assert minMaxGenreWeight(4, 2, [20, 10, 30, 10]) == 40 def test_scenario4(): assert minMaxGenreWeight(1, 1, [100]...
[ { "docstring": null, "function_declaration": "def canDistribute(weights, n, k, maxWeight):", "function_name": "canDistribute", "parameter_list": "(weights, n, k, maxWeight)" }, { "docstring": null, "function_declaration": "def minMaxGenreWeight(n, k, weights):", "function_name": "min...
[ 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 minimize_max_genre_weight(n, k, weights):\n def can_distribute(mid):\n genre_count, current_sum = 1, 0\n for weight in weights:\n ...
trial_gpt4o_3
{ "original_instruction": "Jenny is organizing her bookshelf and realizes she wants to group her books by genre such that the total weight of the books in each genre group is balanced as much as possible. She has n books, each with their weight wi, and k genres to classify them into.\n\nShe needs to find a way to dis...
0.624726
Codeforces_35757
C
[ "canDistribute", "minMaxGenreWeight" ]
2
[ [ "minMaxGenreWeight", "canDistribute" ] ]
1
[]
false
[]
false
pytest
false
[]
true
fb6c650c6922c78f9f10a9ba1a09a1f6d8141c73
f3c5d0cbd0c8da8339e88dee5f8384215f7d61d5
v1.0
complete
Codeforces
Codeforces_35492_C
def minimum_additional_paths_needed(n, m, paths): """ Determine the minimum number of additional paths required to make the cave system fully connected. Args: n (int): the number of chambers (1 ≤ n ≤ 1000). m (int): the number of paths (0 ≤ m ≤ 50,000). paths (List[Tuple[int, int]]): list of pa...
def find_parent(parent, i): if parent[i] == i: return i else: return find_parent(parent, parent[i]) def union(parent, rank, x, y): xroot = find_parent(parent, x) yroot = find_parent(parent, y) if rank[xroot] < rank[yroot]: parent[xroot] = yroot elif rank[xroot] > ra...
from solution import minimum_additional_paths_needed def test_example_case(): n = 5 m = 3 paths = [(1, 2), (1, 3), (4, 5)] assert minimum_additional_paths_needed(n, m, paths) == 1 def test_fully_connected(): n = 4 m = 3 paths = [(1, 2), (2, 3), (3, 4)] assert minimum_additional_paths_n...
[ { "docstring": null, "function_declaration": "def find_parent(parent, i):", "function_name": "find_parent", "parameter_list": "(parent, i)" }, { "docstring": null, "function_declaration": "def union(parent, rank, x, y):", "function_name": "union", "parameter_list": "(parent, rank...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def find_parent(parent, i):\n if parent[i] == i:\n return i\n else:\n return find_parent(parent, parent[i])\n\ndef union(parent, rank, x, ...
trial_gpt4o_0
{ "original_instruction": "A group of archeologists is exploring an ancient cave system. The cave has n chambers connected by m paths. Their goal is to map out the system by ensuring every chamber is reachable from any other chamber directly or indirectly. It's crucial that the group can efficiently travel between an...
0.571326
Codeforces_35492
C
[ "find_parent", "union", "minimum_additional_paths_needed" ]
3
[ [ "minimum_additional_paths_needed", "find_parent" ], [ "minimum_additional_paths_needed", "union" ], [ "union", "find_parent" ] ]
3
[]
false
[]
false
pytest
true
[]
true
76ce016047a98f2bedf01ab8337cf3a1298cab5e
1505ed79d51b993db3e53020c26314a1bd28e12f
v1.0
complete
Codeforces
Codeforces_36035_C
def longest_subsequence_with_prime_diff(n: int, arr: List[int]) -> int: """ Given an integer array `a` of length `n`, find the longest subsequence such that for any two elements `a_i` and `a_j` (i < j) in the subsequence, the difference `a_j - a_i` is a prime number. >>> longest_subsequence_with_prime_diff(5, [...
import math from collections import defaultdict 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 += ...
from solution import longest_subsequence_with_prime_diff def test_example_case(): assert longest_subsequence_with_prime_diff(5, [3, 7, 12, 8, 15]) == 3 def test_single_element(): assert longest_subsequence_with_prime_diff(1, [10]) == 1 def test_no_prime_diff(): assert longest_subsequence_with_prime_diff(...
[ { "docstring": null, "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": null, "function_declaration": "def generate_prime_set(max_diff):", "function_name": "generate_prime_set", "parameter_list": "(max_diff)" }...
[ 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 is_prime(n):\n \"\"\"Helper function to determine if n is a prime number.\"\"\"\n if n <= 1:\n return False\n if n <= 3:\n ...
trial_gpt4o_1
{ "original_instruction": "Vivek loves to play with numbers. Given an integer array $$$a$$$ of length $$$n$$$. He wants to find the longest subsequence, such that for any two elements $$$a_i$$$ and $$$a_j$$$ ($$$i < j$$$) in the subsequence the following conditions hold:\n\n1. $$$a_j - a_i$$$ is a prime number.\n\nGi...
0.770274
Codeforces_36035
C
[ "is_prime", "generate_prime_set", "longest_subsequence_with_prime_diff" ]
3
[ [ "generate_prime_set", "is_prime" ], [ "longest_subsequence_with_prime_diff", "generate_prime_set" ] ]
2
[]
false
[]
false
pytest
true
[]
true
676a5a6a1c62c71b813f826ee7dcb6bd458d3c2f
26c3f13281f762c6fbcf3e4bb52516127e645eb4
v1.0
complete
Codeforces
Codeforces_35931_C
def find_max_path_sum(m: int, n: int, matrix: List[List[int]]) -> int: """ In Ancient Grolen, there is a peculiar game involving a rectangular grid of dimensions m x n. Each cell in the grid contains a positive integer value. The player starts at the top-left corner of the grid and aims to reach the bottom-righ...
def max_path_sum(grid): """ Returns the maximum sum of values along a path from the top-left to the bottom-right corner of the grid. :param grid: List[List[int]] :return: int """ m = len(grid) n = len(grid[0]) # Initialize a dp array with the same dimensions as grid dp = [[0] * ...
from solution import find_max_path_sum def test_find_max_path_sum_example(): m = 3 n = 3 matrix = [ [1, 3, 1], [1, 5, 1], [4, 2, 1], ] assert find_max_path_sum(m, n, matrix) == 12 def test_find_max_path_sum_single_row(): m = 1 n = 5 matrix = [[1, 2, 3, 4, 5]] ...
[ { "docstring": "Returns the maximum sum of values along a path from the top-left to the bottom-right corner of the grid.\n:param grid: List[List[int]]\n:return: int", "function_declaration": "def max_path_sum(grid):", "function_name": "max_path_sum", "parameter_list": "(grid)" }, { "docstrin...
[ 0, 0, 1, 1 ]
2
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_path_sum(m, n, grid):\n \"\"\"\n Returns the maximum sum of values along the path from the top-left \n to the bottom...
trial_gpt4o_4
{ "original_instruction": "In Ancient Grolen, there is a peculiar game involving a rectangular grid of dimensions m x n. Each cell in the grid contains a positive integer value. The player starts at the top-left corner of the grid and aims to reach the bottom-right corner. \n\nThe player can only move in two possible...
0.682138
Codeforces_35931
C
[ "max_path_sum", "find_max_path_sum" ]
2
[ [ "find_max_path_sum", "max_path_sum" ] ]
1
[]
false
[]
false
pytest
true
[]
true
8cc610e4573aaf41c427fa268a9c8f28aaca65a5
19baf14eb0c07e2b9f9f5fcba4679c8ff8ada013
v1.0
complete
Codeforces
Codeforces_35470_C
from typing import List, Tuple def shortest_path_to_visit_islands(n: int, m: int, edges: List[Tuple[int, int, int]], k: int, islands: List[int]) -> int: """ Determine the shortest path that visits all given islands at least once. Args: n (int): Number of islands. m (int): Number of routes between ...
import heapq def dijkstra(graph, start, n): distances = [float('inf')] * (n + 1) distances[start] = 0 queue = [(0, start)] while queue: current_distance, current_node = heapq.heappop(queue) if current_distance > distances[current_node]: continue for neighbor, weight ...
from solution import shortest_path_to_visit_islands def test_example_case(): n = 6 m = 7 edges = [ (1, 2, 10), (1, 3, 15), (2, 4, 12), (3, 5, 10), (4, 5, 2), (5, 6, 5), (2, 6, 20) ] k = 4 islands = [1, 3, 4, 6] assert shortest_path_to_...
[ { "docstring": null, "function_declaration": "def dijkstra(graph, start, n):", "function_name": "dijkstra", "parameter_list": "(graph, start, n)" }, { "docstring": null, "function_declaration": "def shortest_path_to_visit_islands(n, m, edges, k, islands):", "function_name": "shortest...
[ 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 heapq\nimport sys\n\ndef dijkstra(graph, start):\n n = len(graph)\n dist = [sys.maxsize] * n\n dist[start] = 0\n pq = [(0, start)]\n \n ...
trial_gpt4o_1
{ "original_instruction": "Captain Ahab is planning his next whaling expedition and needs to chart the shortest possible route to visit a specific set of islands in the Pacific Ocean. The islands are represented as nodes in a graph, and the routes between them are the edges with weights representing the distance.\n\n...
0.66725
Codeforces_35470
C
[ "dijkstra", "shortest_path_to_visit_islands" ]
2
[ [ "shortest_path_to_visit_islands", "dijkstra" ] ]
1
[]
false
[]
false
pytest
true
[]
true
c172ac3556b7dfe412d3a66f6ab56f1683fb90cb
4caca57df6de09cf0e65b6318253de9f07272c5d
v1.0
complete
Codeforces
Codeforces_36079_C
def minimum_transmission_cost(n: int, m: int, edge_list: List[Tuple[int, int, int]]) -> int: """ Determine the minimum transmission cost needed to ensure that every server can communicate with every other server either directly or indirectly. If it's not possible to connect all the servers, return...
def find(parent, i): if parent[i] == i: return i else: return find(parent, parent[i]) def union(parent, rank, x, y): xroot = find(parent, x) yroot = find(parent, y) if rank[xroot] < rank[yroot]: parent[xroot] = yroot elif rank[xroot] > rank[yroot]: parent[yr...
def test_single_server(): assert minimum_transmission_cost(1, 0, []) == 0 def test_no_edges(): assert minimum_transmission_cost(4, 0, []) == -1 def test_general_case(): edge_list = [ (1, 2, 3), (2, 3, 4), (3, 4, 2), (4, 1, 1) ] assert minimum_transmission_cost(4, 4,...
[ { "docstring": null, "function_declaration": "def find(parent, i):", "function_name": "find", "parameter_list": "(parent, i)" }, { "docstring": null, "function_declaration": "def union(parent, rank, x, y):", "function_name": "union", "parameter_list": "(parent, rank, x, y)" }, ...
[ 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 find(parent, i):\n if parent[i] == i:\n return i\n else:\n return find(parent, parent[i])\n\ndef union(parent, rank, x, y):\n xroot...
trial_gpt4o_0
{ "original_instruction": "You're managing a network of n servers connected by m transmission lines. Each transmission line connects exactly two servers and data can be transmitted in both directions. Additionally, each line has an associated transmission cost. Unfortunately, not all servers are directly connected, a...
0.57604
Codeforces_36079
C
[ "find", "union", "kruskal_mst", "minimum_transmission_cost" ]
4
[ [ "kruskal_mst", "find" ], [ "kruskal_mst", "union" ], [ "minimum_transmission_cost", "kruskal_mst" ], [ "union", "find" ] ]
4
[]
false
[]
false
pytest
false
[]
true
bf66f27b416feb11b9e30fc8670184b9599c8e5b
6bb0aa3aa5d7e5910b151a26e17b912bd66adbd7
v1.0
complete
Codeforces
Codeforces_36150_C
from typing import List def is_perfect_word(word: str) -> str: """ Determine if a word is perfect based on Alice's criteria. A word is perfect if it alternates vowels and consonants and starts with a vowel. If perfect, return "PERFECT", otherwise return "IMPERFECT". >>> is_perfect_word("abecid") 'P...
def is_perfect_word(word): vowels = "aeiou" consonants = "bcdfghjklmnpqrstvwxyz" if word[0] not in vowels: return "IMPERFECT" for i in range(1, len(word)): if (word[i-1] in vowels and word[i] not in consonants) or (word[i-1] in consonants and word[i] not in vowels): ...
import pytest from solution import check_words, is_perfect_word def test_is_perfect_word(): assert is_perfect_word("abecid") == "PERFECT" assert is_perfect_word("bacde") == "IMPERFECT" assert is_perfect_word("aioue") == "IMPERFECT" assert is_perfect_word("a") == "PERFECT" assert is_perfect_word("ab...
[ { "docstring": null, "function_declaration": "def is_perfect_word(word):", "function_name": "is_perfect_word", "parameter_list": "(word)" }, { "docstring": null, "function_declaration": "def check_words(words):", "function_name": "check_words", "parameter_list": "(words)" } ]
[ 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_perfect_word(word):\n vowels = set('aeiou')\n consonants = set('bcdfghjklmnpqrstvwxyz')\n \n if len(word) == 0 or word[0] not in vowels:\n ...
trial_gpt4o_2
{ "original_instruction": "Bob's friend Alice has a peculiar interest in words and numbers. She recently encountered a challenge involving words composed of certain sets of letters. Alice describes a word as \"perfect\" if it solely consists of alternating vowels and consonants and starts with a vowel. For example, t...
0.64981
Codeforces_36150
C
[ "is_perfect_word", "check_words" ]
2
[ [ "check_words", "is_perfect_word" ] ]
1
[]
false
[]
false
pytest
true
[]
true
e9942121ada16da76dca63c602143966253657ff
0a4a334f8e1e2bb98aee45a32ae0393945e73c3f
v1.0
complete
Codeforces
Codeforces_36066_C
def find_max_filled_rectangle(n: int, m: int, grid: List[str]) -> int: """ Find the area of the largest filled rectangle in a grid with n rows and m columns consisting of characters '*' and '.'. :param n: the number of rows in the grid :param m: the number of columns in the grid :param grid: a list...
def max_filled_rectangle_area(n, m, grid): max_area = 0 # Convert grid to list of lists of ints for easier manipulation ('*' -> 1, '.' -> 0) matrix = [[1 if grid[r][c] == '*' else 0 for c in range(m)] for r in range(n)] # Prepare storage for heights heights = [0] * m for row in ma...
from solution import find_max_filled_rectangle def test_max_filled_rectangle_area(): n = 4 m = 5 grid = [ "*****", "*..**", "*****", "*****" ] assert find_max_filled_rectangle(n, m, grid) == 10 def test_single_cell_filled(): n = 1 m = 1 grid = ["*"] ...
[ { "docstring": null, "function_declaration": "def max_filled_rectangle_area(n, m, grid):", "function_name": "max_filled_rectangle_area", "parameter_list": "(n, m, grid)" }, { "docstring": null, "function_declaration": "def largest_rectangle_area_in_histogram(heights):", "function_nam...
[ 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_filled_rectangle(grid):\n \"\"\"\n Find the area of the largest filled rectangle in the grid.\n \n :param grid: A 2D list of character...
trial_gpt4o_2
{ "original_instruction": "You are given a grid with n rows and m columns consisting of characters '*' and '.'. A rectangle in the grid is defined by four corners (r1, c1), (r1, c2), (r2, c1), and (r2, c2) such that r1 ≤ r2 and c1 ≤ c2. A rectangle is called filled if every cell inside it contains a '*'. Your task is...
0.696167
Codeforces_36066
C
[ "max_filled_rectangle_area", "largest_rectangle_area_in_histogram", "find_max_filled_rectangle" ]
3
[ [ "find_max_filled_rectangle", "max_filled_rectangle_area" ], [ "max_filled_rectangle_area", "largest_rectangle_area_in_histogram" ] ]
2
[]
false
[]
false
pytest
true
[]
true
0993027aabdd3f9e2d8fcbe65c8e5f06b8e3147b
58a95036019f64c95c14f038171b1c49d3c3d867
v1.0
complete
Codeforces
Codeforces_35959_C
from typing import List, Tuple def shortest_path_after_adjustment(n: int, m: int, edges: List[Tuple[int, int, int]]) -> int: """ Henry needs to ensure it is possible to get from checkpoint 1 to checkpoint n by making the shortest path as short as possible by adjusting the length of at most one of the corr...
import heapq def dijkstra(adj_list, start, n): """ Runs Dijkstra's algorithm and returns the shortest distances from start to all nodes. """ dist = [float('inf')] * (n + 1) dist[start] = 0 min_heap = [(0, start)] while min_heap: current_dist, u = heapq.heappop(min_heap) ...
from solution import shortest_path_after_adjustment def test_example_case(): n = 5 m = 5 edges = [ (1, 2, 3), (2, 3, 4), (3, 4, 5), (4, 5, 2), (1, 5, 10) ] assert shortest_path_after_adjustment(n, m, edges) == 9 def test_single_edge(): n = 2 m = 1 ...
[ { "docstring": "Runs Dijkstra's algorithm and returns the shortest distances from start to all nodes.", "function_declaration": "def dijkstra(adj_list, start, n):", "function_name": "dijkstra", "parameter_list": "(adj_list, start, n)" }, { "docstring": null, "function_declaration": "def ...
[ 0, 0, 0, 0, 0, 0, 0, 1, 0, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "import heapq\n\ndef dijkstra(n, graph, start):\n distances = [float('inf')] * (n + 1)\n distances[start] = 0\n priority_queue = [(0, start)]\n \n ...
trial_gpt4o_7
{ "original_instruction": "Henry is the head guard of a large bank and he's in charge of security. The bank has n security checkpoints and these checkpoints are connected by m bidirectional corridors. Each corridor has a certain length. The bank's corridors form a connected graph. Henry needs to ensure that it is pos...
0.673574
Codeforces_35959
C
[ "dijkstra", "shortest_path_after_adjustment" ]
2
[ [ "shortest_path_after_adjustment", "dijkstra" ] ]
1
[]
false
[]
false
pytest
true
[]
true
1227ccdd6e25ef492cbf02efc45a9f50519217dd
4282fcbd2bacbd968812535f79f8b729fbbf4b6a
v1.0
complete
Codeforces
Codeforces_35687_C
from typing import List, Tuple from collections import defaultdict def warehouse_distances(n: int, edges: List[Tuple[int, int, int]], queries: List[Tuple[int, int]]) -> List[int]: """ Write a function to find the shortest distances between warehouses given the number of warehouses (n), a list of edges rep...
import sys from collections import defaultdict, deque sys.setrecursionlimit(200000) def add_edge(graph, u, v, d): graph[u].append((v, d)) graph[v].append((u, d)) def lca_preprocess(graph, n, root=1): # To store the parent and depth of each node parent = [-1] * (n + 1) depth = [0] * (n + 1) ma...
from solution import warehouse_distances def test_case_1(): n = 5 edges = [ (1, 2, 3), (1, 3, 2), (3, 4, 4), (3, 5, 5) ] queries = [ (2, 4), (4, 5), (1, 5) ] assert warehouse_distances(n, edges, queries) == [9, 9, 7] def test_case_2(): ...
[ { "docstring": null, "function_declaration": "def add_edge(graph, u, v, d):", "function_name": "add_edge", "parameter_list": "(graph, u, v, d)" }, { "docstring": null, "function_declaration": "def lca_preprocess(graph, n, root=1):", "function_name": "lca_preprocess", "parameter_l...
[ 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 sys\nfrom collections import defaultdict, deque\n\nsys.setrecursionlimit(200000)\n\ndef add_edge(graph, u, v, d):\n graph[u].append((v, d))\n gra...
trial_gpt4o_0
{ "original_instruction": "You are working on a logistics and distribution project for a large manufacturing company. The company operates numerous warehouses spread across different cities. The goal is to improve delivery efficiency by optimizing the routes taken to deliver goods between warehouses. The company has ...
0.625426
Codeforces_35687
C
[ "add_edge", "lca_preprocess", "lca", "calculate_distance", "preprocess_distances", "warehouse_distances" ]
6
[ [ "calculate_distance", "lca" ], [ "warehouse_distances", "add_edge" ], [ "warehouse_distances", "calculate_distance" ], [ "warehouse_distances", "lca_preprocess" ], [ "warehouse_distances", "preprocess_distances" ] ]
5
[]
false
[]
false
pytest
true
[]
true
bb0ebadc76d2dd09ff7b0ecbf6d6aad2f30f46a5
8eaf8cf2fd58a0eabd9460c3d5dc35df6da21f6e
v1.0
complete
Codeforces
Codeforces_36380_C
def min_steps_to_reach_bottom_right(n: int, m: int, grid: List[str]) -> int: """ Given a grid of size N x M consisting of '0's (empty cells) and '1's (walls), determine the shortest path from the top-left corner (0, 0) to the bottom-right corner (N-1, M-1). You can move up, down, left, or right, but canno...
from collections import deque def shortest_path_with_ability(grid, n, m): def is_valid(x, y): return 0 <= x < n and 0 <= y < m directions = [(0, 1), (1, 0), (0, -1), (-1, 0)] queue = deque([(0, 0, 0, False)]) # x, y, steps, used_ability visited = set((0, 0, False)) while queue: ...
def test_example_case_1(): grid = [ "01100", "00010", "00010", "11110", "00000" ] assert min_steps_to_reach_bottom_right(5, 5, grid) == 8 def test_example_case_2(): grid = [ "111", "111", "111" ] assert min_steps_to_reach_bottom_ri...
[ { "docstring": null, "function_declaration": "def shortest_path_with_ability(grid, n, m):", "function_name": "shortest_path_with_ability", "parameter_list": "(grid, n, m)" }, { "docstring": null, "function_declaration": "def min_steps_to_reach_bottom_right(n, m, grid):", "function_na...
[ 0, 0, 0, 0, 0, 0, 1, 0, 1 ]
2
hard
0.222
{ "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_with_transform(grid):\n N, M = len(grid), len(grid[0])\n directions = [(-1, 0), (1, 0), (0, -1), (0, ...
trial_gpt4o_9
{ "original_instruction": "Given a grid of size N x M consisting of '0's (empty cells) and '1's (walls), you need to determine the shortest path from the top-left corner (0, 0) to the bottom-right corner (N-1, M-1). You can move up, down, left, or right, but cannot pass through walls ('1's).\n\nIn addition, you have ...
0.704499
Codeforces_36380
C
[ "shortest_path_with_ability", "min_steps_to_reach_bottom_right" ]
2
[ [ "min_steps_to_reach_bottom_right", "shortest_path_with_ability" ] ]
1
[]
false
[]
false
pytest
false
[]
true
cb803c6641918087ac692aa193abc0f4548babf9
047e52e3e2f638cee989afb96dd26b1eb57508d0
v1.0
complete
Codeforces
Codeforces_36520_C
import math def factorial_sum(n: int) -> int: """ Calculates the sum of factorials of the digits of the given number n. """ return sum(math.factorial(int(digit)) for digit in str(n)) def steps_to_repeating_number(n: int) -> int: """ Generates the Factorial Sum Sequence starting from n and re...
import math def factorial_sum(n): """ Calculates the sum of factorials of the digits of the given number n. """ return sum(math.factorial(int(digit)) for digit in str(n)) def steps_to_repeating_number(n): """ Generates the Factorial Sum Sequence starting from n and returns the number of steps ...
from solution import steps_to_repeating_number def test_example_1(): assert steps_to_repeating_number(145) == 1 def test_example_2(): assert steps_to_repeating_number(69) == 5 def test_example_3(): assert steps_to_repeating_number(1) == 1 def test_example_4(): assert steps_to_repeating_number(40585)...
[ { "docstring": "Calculates the sum of factorials of the digits of the given number n.", "function_declaration": "def factorial_sum(n):", "function_name": "factorial_sum", "parameter_list": "(n)" }, { "docstring": "Generates the Factorial Sum Sequence starting from n and returns the number of...
[ 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 math\n\ndef factorial_sum_sequence_steps(n):\n def factorial_sum(num):\n return sum(math.factorial(int(digit)) for digit in str(num))\n\n ...
trial_gpt4o_2
{ "original_instruction": "Peter loves working with numbers and is fascinated by special number sequences. Recently, he came across a unique type of sequence called a \"Factorial Sum Sequence.\" In this sequence, each number is the sum of the factorials of its digits. He started experimenting with these sequences and...
0.681383
Codeforces_36520
C
[ "factorial_sum", "steps_to_repeating_number" ]
2
[ [ "steps_to_repeating_number", "factorial_sum" ] ]
1
[]
false
[]
false
pytest
true
[]
true
0132894704ed0bd981cec9454fffe19e575378ad
90cc17a6dbed4fdd49ef4cc60a9161f0a932e19b
v1.0
complete
Codeforces
Codeforces_36330_C
from typing import List def minimize_maximum_sum(arr: List[int], n: int, m: int) -> int: """ Partition the given array into exactly `m` non-overlapping subarrays such that the maximum sum of the values in any of the `m` subarrays is minimized. Args: arr (List[int]): List of integers representing the a...
def can_partition(arr, n, m, mid): count, current_sum = 1, 0 for num in arr: if current_sum + num > mid: count += 1 current_sum = num if count > m: return False else: current_sum += num return True def minimize_maximum_sum(arr,...
def test_minimize_maximum_sum_basic(): assert minimize_maximum_sum([7, 2, 5, 10, 8], 5, 2) == 18 def test_minimize_maximum_sum_single_element(): assert minimize_maximum_sum([5], 1, 1) == 5 def test_minimize_maximum_sum_single_partition(): assert minimize_maximum_sum([1, 2, 3, 4, 5], 5, 1) == 15 def test_...
[ { "docstring": null, "function_declaration": "def can_partition(arr, n, m, mid):", "function_name": "can_partition", "parameter_list": "(arr, n, m, mid)" }, { "docstring": null, "function_declaration": "def minimize_maximum_sum(arr, n, m):", "function_name": "minimize_maximum_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 can_partition(arr, m, max_sum):\n current_sum = 0\n count = 1\n \n for num in arr:\n if current_sum + num > max_sum:\n count...
trial_gpt4o_2
{ "original_instruction": "You are given an array of integers `arr` of length `n` and an integer `m`. Your task is to partition the array into exactly `m` non-overlapping subarrays such that the maximum sum of the values in any of the `m` subarrays is minimized.\n\nFormally, you need to select `m-1` partition points,...
0.698767
Codeforces_36330
C
[ "can_partition", "minimize_maximum_sum" ]
2
[ [ "minimize_maximum_sum", "can_partition" ] ]
1
[]
false
[]
false
pytest
false
[]
true
07b27206aa8e1d5633435dce8b16e32f436ae985
3437311ca1eda6814310f860f0a3be758add43a9
v1.0
complete
Codeforces
Codeforces_36535_C
def largest_clique_size(n, m, friendships): """ Finds the size of the largest clique in the friendship graph. n: number of members m: number of friendships friendships: list of tuples representing friendships >>> largest_clique_size(5, 6, [(1, 2), (1, 3), (1, 4), (2, 3), (2, 4), (3, 4)]) == 4 >>...
from itertools import combinations def is_clique(graph, nodes): """ Check if a given set of nodes forms a clique. """ for u, v in combinations(nodes, 2): if v not in graph[u]: return False return True def largest_clique_size(n, m, friendships): """ Finds the size of the...
from solution import largest_clique_size def test_example_case(): assert largest_clique_size(5, 6, [(1, 2), (1, 3), (1, 4), (2, 3), (2, 4), (3, 4)]) == 4 def test_single_member(): assert largest_clique_size(1, 0, []) == 1 def test_no_friendships(): assert largest_clique_size(4, 0, []) == 1 def test_two_...
[ { "docstring": "Check if a given set of nodes forms a clique.", "function_declaration": "def is_clique(graph, nodes):", "function_name": "is_clique", "parameter_list": "(graph, nodes)" }, { "docstring": "Finds the size of the largest clique in the friendship graph.\nn: number of members\nm: ...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def largest_clique(n, m, friendships):\n from itertools import combinations\n\n def is_clique(subset):\n for u, v in combinations(subset, 2):\n ...
trial_gpt4o_2
{ "original_instruction": "Ian is an anthropologist studying the social networks of a community. He models the community as a graph with $$$n$$$ members (numbered from $$$1$$$ to $$$n$$$) and $$$m$$$ friendships (undirected edges) between them. Ian is particularly interested in clique structures within this community...
0.644836
Codeforces_36535
C
[ "is_clique", "largest_clique_size" ]
2
[ [ "largest_clique_size", "is_clique" ] ]
1
[]
false
[]
false
pytest
true
[]
true
8b6af932424b406f3cc29e90658f943e39320e0e
5e51e8243f53919831fb0b140c8adf58a2f09144
v1.0
complete
Codeforces
Codeforces_36584_C
def min_roads_to_construct(n: int, m: int, roads: List[Tuple[int, int, int]]) -> int: """ Returns the minimum number of roads that must be constructed to make the network connected. >>> min_roads_to_construct(4, 2, [(1, 2, 4), (3, 4, 3)]) 1 >>> min_roads_to_construct(4, 3, [(1, 2, 1), (2, 3, 1), (3...
def find(parent, i): """ A utility function to find the set of an element i using path compression. """ if parent[i] == i: return i else: parent[i] = find(parent, parent[i]) return parent[i] def union(parent, rank, x, y): """ A function that does union of two subsets...
from solution import min_roads_to_construct def test_example_case(): roads = [(1, 2, 4), (3, 4, 3)] assert min_roads_to_construct(4, 2, roads) == 1 def test_already_connected(): roads = [(1, 2, 1), (2, 3, 1), (3, 4, 1)] assert min_roads_to_construct(4, 3, roads) == 0 def test_no_roads(): assert m...
[ { "docstring": "A utility function to find the set of an element i using path compression.", "function_declaration": "def find(parent, i):", "function_name": "find", "parameter_list": "(parent, i)" }, { "docstring": "A function that does union of two subsets x and y based on the rank.", ...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def find(parent, i):\n \"\"\"\n A utility function to find the set of an element i using path compression.\n \"\"\"\n if parent[i] == i:\n ...
trial_gpt4o_0
{ "original_instruction": "You are the manager of a logistics company. You have a network of warehouses connected by roads, each with a certain length. There are n warehouses and m bidirectional roads. Each road connects two warehouses and has a length associated with it. Your task is to ensure that every warehouse c...
0.701596
Codeforces_36584
C
[ "find", "union", "min_roads_to_construct" ]
3
[ [ "min_roads_to_construct", "find" ], [ "min_roads_to_construct", "union" ], [ "union", "find" ] ]
3
[]
false
[]
false
pytest
true
[]
true
2e4f043472a2b8b6907e1d9568f7b41bb710da71
39b28fa076393da5fee9c524ec03a8c8901b0154
v1.0
complete
Codeforces
Codeforces_36526_C
import math from typing import List, Tuple from itertools import permutations def calculate_distance(p1: Tuple[int, int], p2: Tuple[int, int]) -> float: """ Calculate the Euclidean distance between two points in 2D space. >>> calculate_distance((0, 0), (3, 4)) 5.0 """ pass def shortest_polygon_pat...
import math from itertools import permutations def calculate_distance(p1, p2): return math.sqrt((p1[0] - p2[0]) ** 2 + (p1[1] - p2[1]) ** 2) def calculate_path_length(path): total_length = 0 for i in range(len(path)): total_length += calculate_distance(path[i], path[(i + 1) % len(path)]) retur...
from solution import calculate_distance, shortest_polygon_path def test_calculate_distance(): assert calculate_distance((0, 0), (3, 4)) == 5.0 def test_shortest_polygon_path_square(): points = [(0, 0), (0, 1), (1, 1), (1, 0)] result = shortest_polygon_path(points) assert math.isclose(result, 4.0, abs_...
[ { "docstring": null, "function_declaration": "def calculate_distance(p1, p2):", "function_name": "calculate_distance", "parameter_list": "(p1, p2)" }, { "docstring": null, "function_declaration": "def calculate_path_length(path):", "function_name": "calculate_path_length", "param...
[ 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\nfrom functools import cmp_to_key\n\ndef compute_distance(p1, p2):\n \"\"\"\n Computes the Euclidean distance between two points p1 and p2.\...
trial_gpt4o_1
{ "original_instruction": "In a distant world, there are n ancient temples located in a vast desert. Each temple is a point in a 2D coordinate plane, and no two temples share the same location. The rulers of the land want to establish a new path that connects all the temples exactly once and forms a simple polygon (a...
0.591819
Codeforces_36526
C
[ "calculate_distance", "calculate_path_length", "shortest_polygon_path", "main" ]
4
[ [ "calculate_path_length", "calculate_distance" ], [ "shortest_polygon_path", "calculate_path_length" ] ]
2
[]
false
[]
false
pytest
true
[]
true
ffe58e73511a94b5ac5806ad6e363b79a4da2693
829c774022c3aab0eb82d4cb661d45d4f2aa5742
v1.0
complete
Codeforces
Codeforces_36320_C
class TreeNode: def __init__(self, val=0, id=0, left=None, right=None): self.val = val self.id = id self.left = left self.right = right def insert_into_BST(root, val, id): if not root: return TreeNode(val, id) if val < root.val or (val == root.val and id < root.id): ...
class TreeNode: def __init__(self, val=0, id=0, left=None, right=None): self.val = val self.id = id self.left = left self.right = right def insert_into_BST(root, val, id): if not root: return TreeNode(val, id) if val < root.val or (val == root.val and id < root....
from solution import find_kth_smallest def test_example_case(): n = 5 k = 3 nodes = [(4, 1), (2, 2), (6, 3), (1, 4), (3, 5)] assert find_kth_smallest(n, k, nodes) == 3 def test_single_node(): n = 1 k = 1 nodes = [(1, 1)] assert find_kth_smallest(n, k, nodes) == 1 def test_all_left_chi...
[]
[ 1, 1, 1 ]
3
easy
1
{ "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 insert_node(root, node):\n if...
trial_gpt4o_1
{ "original_instruction": "Eve and Adam are learning about binary trees. They are particularly interested in identifying the \"kth smallest element\" in a binary search tree (BST). They came up with a challenge: given a BST, find the kth smallest element within it.\n\nIn a binary search tree, the \"kth smallest eleme...
0.573549
Codeforces_36320
C
[ "insert_into_BST", "kth_smallest_element", "find_kth_smallest" ]
3
[ [ "find_kth_smallest", "insert_into_BST" ], [ "find_kth_smallest", "kth_smallest_element" ] ]
2
[]
false
[ "TreeNode" ]
true
pytest
true
[]
true
5a4996adfffebf3f4d28209ed8b51e41ca2e30db
18cf43e20384ae0809615d39b798e1875fe3e2aa
v1.0
complete
Codeforces
Codeforces_36304_C
def solve_word_search(N: int, M: int, grid: List[str], Q: int, words: List[str]) -> List[str]: """ You are given a rectangular grid of size N x M (1 ≤ N, M ≤ 1000) consisting of lowercase letters. A word search algorithm scans this grid to find words from a given dictionary. The algorithm can move hor...
def find_word_in_grid(grid, rows, cols, word): directions = [(-1, -1), (-1, 0), (-1, 1), (0, -1), (0, 1), (1, -1), (1, 0), (1, 1)] def dfs(x, y, index): if index == len(word): return True if not (0 <= x < rows and 0 <= y < cols) or grid[x][y] != word[index] or visited[x][y]: ...
from solution import solve_word_search def test_case_1(): N = 4 M = 5 grid = [ "abces", "sfcsf", "adees", "sster" ] Q = 3 words = ["abc", "see", "ssss"] assert solve_word_search(N, M, grid, Q, words) == ["YES", "YES", "NO"] def test_case_2(): N = 3 M...
[ { "docstring": null, "function_declaration": "def find_word_in_grid(grid, rows, cols, word):", "function_name": "find_word_in_grid", "parameter_list": "(grid, rows, cols, word)" }, { "docstring": null, "function_declaration": "def solve_word_search(N, M, grid, Q, words):", "function_...
[ 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 word_search(grid, words):\n def search_from(x, y, word):\n if not word:\n return True\n if not (0 <= x < n and 0 <= y < m):\n ...
trial_gpt4o_9
{ "original_instruction": "You are given a rectangular grid of size $$$N \\times M$$$ (1 ≤ N, M ≤ 1000) consisting of lowercase letters. A word search algorithm scans this grid to find words from a given dictionary. The algorithm can move horizontally, vertically, or diagonally to adjacent cells in eight possible dir...
0.670959
Codeforces_36304
C
[ "find_word_in_grid", "solve_word_search" ]
2
[ [ "solve_word_search", "find_word_in_grid" ] ]
1
[]
false
[]
false
pytest
true
[]
true
50d448583a58535fb9de3f35ba9cccbef1a36081
61443564717f71390ac18d67cbb3167a150d7028
v1.0
complete
Codeforces
Codeforces_36795_C
def transform_grid(n: int, initial: List[str], target: List[str]) -> None: """ Determine the sequence of moves that transforms the initial configuration into the target configuration. Args: n (int): the size of the grid. initial (List[str]): the initial configuration of the grid. target (List[s...
def find_moves(n, initial, target): moves = [] if initial == target: return moves def swap(x1, y1, x2, y2): nonlocal initial initial[x1][y1], initial[x2][y2] = initial[x2][y2], initial[x1][y1] moves.append(f"S {x1+1} {y1+1} {x2+1} {y2+1}") def rotate(x, y): ...
from solution import transform_grid def test_simple_swap(): n = 3 initial = [ "AAB", "BBC", "CCD" ] target = [ "ABB", "ABC", "BBC" ] transform_grid(n, initial, target) def test_no_change_needed(): n = 2 initial = [ "AB", "...
[ { "docstring": null, "function_declaration": "def find_moves(n, initial, target):", "function_name": "find_moves", "parameter_list": "(n, initial, target)" }, { "docstring": null, "function_declaration": "def transform_grid(n, initial, target):", "function_name": "transform_grid", ...
[ 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 find_moves_to_transform(n, initial_grid, target_grid):\n moves = []\n \n # Find positions of all gemstones in initial and target grids\n initi...
trial_gpt4o_1
{ "original_instruction": "In a land far away, there are multi-colored gemstones scattered across a magical grid of size `n x n`. Each gemstone has a unique color, and each stone occupies a distinct cell. These gemstones hold significant power which can only be unlocked when all stones of the same color are arranged ...
0.601434
Codeforces_36795
C
[ "find_moves", "transform_grid" ]
2
[ [ "transform_grid", "find_moves" ] ]
1
[]
false
[]
false
pytest
true
[]
true
e53f65c67d40ff009e630073040080c1da3e6329
e4f14d701bb2012e3a413713b98066e6f33f5843
v1.0
complete
Codeforces
Codeforces_36802_C
def vlad_loves_graphs(n, m, edges, q, queries): """ Determine if there exists a simple path between given vertices in the graph. Parameters: n (int): Number of vertices m (int): Number of edges edges (List[Tuple[int, int]]): List of edges represented as tuples q (int): Numbe...
def find(parent, i): if parent[i] == i: return i else: parent[i] = find(parent, parent[i]) return parent[i] def union(parent, rank, x, y): xroot = find(parent, x) yroot = find(parent, y) if xroot != yroot: if rank[xroot] < rank[yroot]: parent[xroot] ...
from solution import vlad_loves_graphs def test_graph_all_connected(): n = 5 m = 5 edges = [(1, 2), (2, 3), (3, 4), (4, 5), (5, 1)] q = 3 queries = [(1, 3), (2, 5), (4, 2)] expected = ["YES", "YES", "YES"] assert vlad_loves_graphs(n, m, edges, q, queries) == expected def test_graph_disconn...
[ { "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 find(parent, i):\n if parent[i] == i:\n return i\n else:\n parent[i] = find(parent, parent[i])\n return parent[i]\n\ndef union(...
trial_gpt4o_0
{ "original_instruction": "Vlad loves graphs very much. One day, he decided to play a game with his computer. He will give the computer a connected undirected graph with $$$n$$$ vertices and $$$m$$$ edges, and a sequence of queries. Each query will provide two vertices $$$u$$$ and $$$v$$$ in the graph. For each query...
0.683624
Codeforces_36802
C
[ "find", "union", "vlad_loves_graphs" ]
3
[ [ "union", "find" ], [ "vlad_loves_graphs", "find" ], [ "vlad_loves_graphs", "union" ] ]
3
[]
false
[]
false
pytest
true
[]
true
b21e22368dd97e70b6ceeb10752bb76d11c53a06
24e09765ccc5305d7021a87e164983335d9ad7c2
v1.0
complete
Codeforces
Codeforces_36928_C
def is_palindrome(num: int) -> bool: """ Check if a number is a palindrome. >>> is_palindrome(121) True >>> is_palindrome(12321) True >>> is_palindrome(123) False >>> is_palindrome(10) False """ def next_palindrome(n: int) -> int: """ Find the smallest palindrome greater than n....
def is_palindrome(num): """ Check if a number is a palindrome. """ return str(num) == str(num)[::-1] def next_palindrome(n): """ Find the smallest palindrome greater than n. """ n += 1 # Start checking from the next number while not is_palindrome(n): n += 1 return n de...
from solution import is_palindrome, next_palindrome, find_next_palindromes def test_is_palindrome(): assert is_palindrome(121) == True assert is_palindrome(12321) == True assert is_palindrome(123) == False assert is_palindrome(10) == False def test_next_palindrome(): assert next_palindrome(123) ==...
[ { "docstring": "Check if a number is a palindrome.", "function_declaration": "def is_palindrome(num):", "function_name": "is_palindrome", "parameter_list": "(num)" }, { "docstring": "Find the smallest palindrome greater than n.", "function_declaration": "def next_palindrome(n):", "fu...
[ 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 next_palindrome(n):\n \"\"\"\n Given a number n, find the smallest palindrome larger than n.\n \"\"\"\n def is_palindrome(num):\n s = s...
trial_gpt4o_4
{ "original_instruction": "Yuki loves palindromes. She especially adores numbers that are palindromes. One day, she came up with the idea of finding the smallest palindrome larger than a given number. \n\nA number is said to be a palindrome if it reads the same forward and backward. For example, 121 and 1331 are pali...
0.7244
Codeforces_36928
C
[ "is_palindrome", "next_palindrome", "find_next_palindromes" ]
3
[ [ "find_next_palindromes", "next_palindrome" ], [ "next_palindrome", "is_palindrome" ] ]
2
[]
false
[]
false
pytest
true
[]
true
5841f8417bae51f25e4805023c6ea49478e07697
023f4c666b05a84c494ece0ea32030d4aafbd025
v1.0
complete
Codeforces
Codeforces_36837_C
def find_prime_in_table(p: int, n: int, r: int, c: int) -> int: """ Find the prime number located at the specified row and column in Sid's prime number table. Args: p (int): the number of primes in Sid's collection. n (int): the number of columns in the table. r (int): the row number (1-based i...
import itertools def nth_prime(n): 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: ...
from solution import find_prime_in_table def test_find_prime_in_table_example1(): assert find_prime_in_table(15, 5, 3, 2) == 37 def test_find_prime_in_table_example2(): assert find_prime_in_table(10, 4, 3, 3) == -1 def test_find_prime_in_table_out_of_bounds(): assert find_prime_in_table(20, 5, 5, 3) == -...
[ { "docstring": null, "function_declaration": "def nth_prime(n):", "function_name": "nth_prime", "parameter_list": "(n)" }, { "docstring": null, "function_declaration": "def find_prime_in_table(p, n, r, c):", "function_name": "find_prime_in_table", "parameter_list": "(p, n, r, c)"...
[ 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 sieve_of_eratosthenes(max_num):\n \"\"\"\n Generate a list of prime numbers up to max_num.\n \"\"\"\n is_prime = [True] * (max_num + 1)\n p...
trial_gpt4o_4
{ "original_instruction": "Sid loves prime numbers and has a collection of them. His collection is organized in a unique way. He picks the primes sequentially starting from the smallest prime number and arranges them in a table with n columns. Consequently, the number of rows in the table is determined by the number ...
0.614892
Codeforces_36837
C
[ "nth_prime", "find_prime_in_table" ]
2
[ [ "find_prime_in_table", "nth_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
319f7f353eaaa7fda0831a7f5fcd5ea41db9b369
6e7a80f5ca0df95b74d260b137ea0b60c95d7da8
v1.0
complete
Codeforces
Codeforces_36968_C
def is_prime(num: int) -> bool: """ Determine if a number is prime >>> is_prime(2) True >>> is_prime(3) True >>> is_prime(4) False >>> is_prime(17) True >>> is_prime(18) False """ def sum_pairs(n: int) -> list: """ Generate the sequence pairs when n is a multiple of ...
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 find_special_sequence(n): ...
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 def test_sum_pairs(): assert sum_pairs(4) == [2, 1, 4, 3] assert sum_pairs(8) == [2, 1, 4, 3, 6, 5, 8, 7] def test_find_special_se...
[ { "docstring": null, "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": null, "function_declaration": "def find_special_sequence(n):", "function_name": "find_special_sequence", "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": "def is_prime(n):\n if n <= 1:\n return False\n if n <= 3:\n return True\n if n % 2 == 0 or n % 3 == 0:\n return False\n i = 5...
trial_gpt4o_1
{ "original_instruction": "John is a computer science student who loves solving puzzles. He recently came across a puzzle that involved finding a special sequence of numbers. The sequence must be a permutation of numbers from 1 to n, such that the sum of any two adjacent numbers in the sequence is a prime number.\n\n...
0.708059
Codeforces_36968
C
[ "is_prime", "find_special_sequence", "sum_pairs", "solve" ]
4
[ [ "find_special_sequence", "sum_pairs" ], [ "solve", "find_special_sequence" ] ]
2
[]
false
[]
false
pytest
false
[]
true
5e14c1d020cccca574dfa45b7f8c2253a6e1a462
febf2b8626f83611e27d9392c3e7028784645a09
v1.0
complete
Codeforces
Codeforces_37056_C
def number_of_components(n: int, m: int, roads: List[Tuple[int, int]], q: int, queries: List[Tuple[int, List[int]]]) -> List[int]: """ Determine the number of connected components in Graphland after certain roads are closed. >>> number_of_components(5, 4, [(1, 2), (2, 3), (4, 5), (3, 5)], 2, [(2, [1, 2]), (1, ...
from collections import defaultdict def find_parent(parent, i): if parent[i] == i: return i else: return find_parent(parent, parent[i]) def union(parent, rank, x, y): x_root = find_parent(parent, x) y_root = find_parent(parent, y) if x_root != y_root: if rank[x_root] <...
def test_case_1(): n = 5 m = 4 roads = [(1, 2), (2, 3), (4, 5), (3, 5)] q = 2 queries = [(2, [1, 2]), (1, [4])] assert number_of_components(n, m, roads, q, queries) == [3, 2] def test_case_2(): n = 6 m = 5 roads = [(1, 2), (2, 3), (3, 4), (4, 5), (5, 6)] q = 1 queries = [(3,...
[ { "docstring": null, "function_declaration": "def find_parent(parent, i):", "function_name": "find_parent", "parameter_list": "(parent, i)" }, { "docstring": null, "function_declaration": "def union(parent, rank, x, y):", "function_name": "union", "parameter_list": "(parent, 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": "from collections import defaultdict\n\nclass UnionFind:\n def __init__(self, size):\n self.parent = list(range(size))\n self.rank = [1] * siz...
trial_gpt4o_2
{ "original_instruction": "The city of Graphland consists of $$$n$$$ cities and $$$m$$$ two-way roads. The mayor wants to evaluate the connectivity of the city under the assumption that some roads may be closed for maintenance. For this purpose, you are to determine how many connected components the city will be divi...
0.656145
Codeforces_37056
C
[ "find_parent", "union", "number_of_components" ]
3
[ [ "number_of_components", "find_parent" ], [ "number_of_components", "union" ], [ "union", "find_parent" ] ]
3
[]
false
[]
false
pytest
false
[]
true
a7b0ccafcc5b1aa3081335f708b09d27b08725c1
7cd98e3a9c07aeae98f6f4c5608b354cc238889b
v1.0
complete
Codeforces
Codeforces_35900_C
class TreeNode: def __init__(self, value, left=None, right=None): self.value = value self.left = left self.right = right def build_tree(tree_list): nodes = {} for value, left, right in tree_list: if value not in nodes: nodes[value] = TreeNode(value) node ...
class TreeNode: def __init__(self, value, left=None, right=None): self.value = value self.left = left self.right = right def build_tree(tree_list): nodes = {} for value, left, right in tree_list: if value not in nodes: nodes[value] = TreeNode(value) node ...
from solution import transform_tree def test_simple_tree(): tree = [(1, 2, 3), (2, None, None), (3, None, None)] expected_output = [(6, 2, 3), (2, None, None), (3, None, None)] assert transform_tree(tree) == expected_output def test_extended_tree(): tree = [(1, 2, 3), (2, None, None), (3, 4, 5), (4, N...
[]
[ 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, value):\n self.value = value\n self.left = None\n self.right = None\n\ndef build_tree(nodes):\n ...
trial_gpt4o_2
{ "original_instruction": "You are given a binary tree where each node has a value. Your task is to transform the binary tree so that the value of each node is replaced by the sum of values of all the nodes in its subtree, including the node itself. The subtree of a node is the tree consisting of the node and all its...
0.594237
Codeforces_35900
C
[ "build_tree", "sum_subtree", "build_tuple_list", "transform_tree" ]
4
[ [ "transform_tree", "build_tree" ], [ "transform_tree", "build_tuple_list" ], [ "transform_tree", "sum_subtree" ] ]
3
[]
false
[ "TreeNode" ]
true
pytest
true
[]
true
6f5a6a615472b4f84bde672a69ce72a50117e69b
4515507f7b83583935d2281a5c196bd19a28bc9d
v1.0
complete
Codeforces
Codeforces_37035_C
from typing import List def partition_possible(n: int, k: int, array: List[int]) -> str: """ Determine if you can partition the array into k non-empty subsets such that each subset's sum is equal. >>> partition_possible(4, 2, [4, 3, 2, 3]) "YES" >>> partition_possible(4, 3, [4, 3, 2, 3]) "NO" >...
from typing import List def can_partition_k_subsets(nums: List[int], k: int) -> bool: total_sum = sum(nums) if total_sum % k != 0: return False target = total_sum // k n = len(nums) nums.sort(reverse=True) buckets = [0] * k def backtrack(index): if index == n: ...
from solution import partition_possible def test_partition_possible_yes(): assert partition_possible(4, 2, [4, 3, 2, 3]) == "YES" def test_partition_possible_no(): assert partition_possible(4, 3, [4, 3, 2, 3]) == "NO" def test_partition_possible_trivial_case(): assert partition_possible(1, 1, [1]) == "YE...
[ { "docstring": null, "function_declaration": "def can_partition_k_subsets(nums, k):", "function_name": "can_partition_k_subsets", "parameter_list": "(nums, k)" }, { "docstring": null, "function_declaration": "def partition_possible(n, k, array):", "function_name": "partition_possible...
[ 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 can_partition_k_subsets(nums, k):\n def can_partition(start, k, subset_sum, target, visited):\n if k == 0:\n return True\n if ...
trial_gpt4o_2
{ "original_instruction": "You are given an integer array and an integer k. You need to determine if you can partition the array into k non-empty subsets such that each subset's sum is equal. \n\nThe first line contains two integers n (1 ≤ n ≤ 16) — the number of elements in the array, and k (1 ≤ k ≤ 16) — the number...
0.63065
Codeforces_37035
C
[ "can_partition_k_subsets", "partition_possible" ]
2
[ [ "partition_possible", "can_partition_k_subsets" ] ]
1
[]
false
[]
false
pytest
true
[]
true
8c917f0c355adb1bc53f3160c43bb92019291347
28347d476619df84352d9d856a767cca518be797
v1.0
complete
Codeforces
Codeforces_37163_C
def find_beauty(n: int, arr: List[int]) -> int: """ Given an array of integers, find the beauty of the array, which is defined as the maximum possible sum of its contiguous subarray having a length of at least one less than the length of the original array. >>> find_beauty(5, [1, -2, 3, 4, -5]) 7 ...
def max_subarray_sum(arr): """ Finds the maximum sum of any contiguous subarray of the given array """ 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_ending_here) return max_so_far def find_b...
def test_max_subarray_sum(): assert max_subarray_sum([1, -2, 3, 4, -5]) == 7 assert max_subarray_sum([-1, -2, -3, -4]) == -1 assert max_subarray_sum([5, 4, -1, 7, 8]) == 23 assert max_subarray_sum([1]) == 1 assert max_subarray_sum([1, 2, 3, 4]) == 10 def test_find_beauty(): assert find_beauty(5...
[ { "docstring": "Finds the maximum sum of any contiguous subarray of the given array", "function_declaration": "def max_subarray_sum(arr):", "function_name": "max_subarray_sum", "parameter_list": "(arr)" }, { "docstring": "Finds the beauty of the array, which is the maximum sum of any contigu...
[ 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 find_beauty_of_array(arr):\n \"\"\"\n Finds the beauty of the array, defined as the maximum possible \n sum of its contiguous subarray which has ...
trial_gpt4o_1
{ "original_instruction": "Given an array of integers, we define its beauty as the maximum possible sum of its contiguous subarray which has a length of at least one less than the length of the original array. You are to find the beauty of the array.\n\nThe first line contains a single integer n (2 ≤ n ≤ 5000), the l...
0.687019
Codeforces_37163
C
[ "max_subarray_sum", "find_beauty" ]
2
[ [ "find_beauty", "max_subarray_sum" ] ]
1
[]
false
[]
false
pytest
false
[]
true
d61f8031fede5a66538924e830aaa3c3b27a8202
c4d128f833b9580fe13df40ce3f556fa28cc6ff3
v1.0
complete
Codeforces
Codeforces_36452_C
def sieve_of_eratosthenes(max_num: int) -> List[bool]: """Generates a list of booleans representing primality of numbers from 0 to max_num""" pass def find_twin_primes(l: int, r: int, is_prime: List[bool]) -> List[Tuple[int, int]]: """Finds all twin primes in the range [l, r] given a list of prime indicato...
def sieve_of_eratosthenes(max_num): """Generates a list of booleans representing primality of numbers from 0 to max_num""" is_prime = [True] * (max_num + 1) is_prime[0] = is_prime[1] = False # 0 and 1 are not primes for start in range(2, int(max_num**0.5) + 1): if is_prime[start]: ...
import pytest from solution import solve, format_results def test_sieve_of_eratosthenes(): sieve = sieve_of_eratosthenes(30) assert sieve[2] assert sieve[3] assert not sieve[4] assert sieve[5] assert sieve[29] assert not sieve[30] def test_find_twin_primes(): is_prime = sieve_of_erato...
[ { "docstring": "Generates a list of booleans representing primality of numbers from 0 to max_num", "function_declaration": "def sieve_of_eratosthenes(max_num):", "function_name": "sieve_of_eratosthenes", "parameter_list": "(max_num)" }, { "docstring": null, "function_declaration": "def f...
[ 1, 0, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def sieve_of_eratosthenes(max_num):\n \"\"\"Generates a list of booleans representing primality of numbers from 0 to max_num\"\"\"\n is_prime = [True] *...
trial_gpt4o_0
{ "original_instruction": "Aman loves solving problems related to prime numbers. He recently learned about twin primes and got curious. A twin prime is a prime number that has either a difference of 2 lower and/or 2 higher prime numbers. For example, (3, 5) and (11, 13) are twin primes.\n\nAman wants to find all twin...
0.613877
Codeforces_36452
C
[ "sieve_of_eratosthenes", "find_twin_primes", "solve", "format_results" ]
4
[ [ "solve", "find_twin_primes" ], [ "solve", "sieve_of_eratosthenes" ] ]
2
[ "format_results" ]
false
[]
false
pytest
true
[]
true
c43902103e05ff8aecf7b2fe26bed8f58f99f5f9
31a33272c87b506a1574d5300abca3229d0e681a
v1.0
complete
Codeforces
Codeforces_37124_C
def is_palindrome(s): """ Check if a given string s is a palindrome. """ return s == s[::-1] def can_form_k_palindrome(k, s): """ Check if the string s can be divided into k palindromic parts. """ # Your code here pass def process(t, test_cases): """ Process the input test ...
def is_palindrome(s): """ Check if a given string s is a palindrome. """ return s == s[::-1] def can_form_k_palindrome(k, s): """ Check if the string s can be divided into k palindromic parts. """ n = len(s) if k > n: return "NO" # dp[i][j] is True if s[i:j+1] is a ...
from solution import process def test_simple_case(): assert process(3, [(2, 'aab'), (3, 'abcba'), (1, 'racecar')]) == ["YES", "YES", "YES"] def test_single_character_string(): assert process(1, [(2, 'a')]) == ["NO"] assert process(1, [(1, 'a')]) == ["YES"] def test_all_same_characters(): assert proce...
[ { "docstring": "Check if a given string s is a palindrome.", "function_declaration": "def is_palindrome(s):", "function_name": "is_palindrome", "parameter_list": "(s)" }, { "docstring": "Check if the string s can be divided into k palindromic parts.", "function_declaration": "def can_for...
[ 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_palindrome(s):\n return s == s[::-1]\n\ndef k_palindrome_possible(t, test_cases):\n results = []\n for case in test_cases:\n k, s = cas...
trial_gpt4o_4
{ "original_instruction": "You are given a string $$$s$$$ consisting of lowercase letters and a number $$$k$$$. \n\nYour task is to transform the string into a k-palindrome. A string is called k-palindrome if it can be divided into exactly $$$k$$$ contiguous non-empty parts where each part is a palindrome.\n\nDetermi...
0.750888
Codeforces_37124
C
[ "is_palindrome", "can_form_k_palindrome", "process" ]
3
[ [ "process", "can_form_k_palindrome" ] ]
1
[]
false
[]
false
pytest
true
[]
true
91a798dd344084530363d6a7e7ad436a8bbe72d9
e0015f65e300e884e62637487a28b976a2158c8e
v1.0
complete
Codeforces
Codeforces_37205_C
def is_prime(num: int) -> bool: """ Return True if `num` is a prime number, otherwise False. >>> is_prime(2) == True >>> is_prime(3) == True >>> is_prime(4) == False >>> is_prime(5) == True >>> is_prime(10) == False >>> is_prime(11) == True """ def generate_prime_sequences(n: in...
def is_prime(num): """ Return True if `num` is a prime number, otherwise False. """ if num < 2: return False for i in range(2, int(num**0.5) + 1): if num % i == 0: return False return True def generate_prime_sequences(n): """ Generate sequences for all prime ...
def test_is_prime(): assert is_prime(2) == True assert is_prime(3) == True assert is_prime(4) == False assert is_prime(5) == True assert is_prime(10) == False assert is_prime(11) == True def test_generate_prime_sequences(): assert generate_prime_sequences(10) == [[2, 4, 6, 8, 10], [3, 6, 9]...
[ { "docstring": "Return True if `num` is a prime number, otherwise False.", "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": "Generate sequences for all prime numbers up to and including `n`.", "function_declaration": "...
[ 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 generate_prime_sequences(n):\n def is_prime(num):\n if num < 2:\n return False\n for i in range(2, int(num**0.5) + 1):\n ...
trial_gpt4o_1
{ "original_instruction": "The kingdom of Arithmania is famous for its elaborate encryption methods. The king has devised a particularly intriguing encryption algorithm based on the properties of prime numbers.\n\nGiven an integer `n`, the encryption algorithm involves the following steps:\n1. Find all prime numbers ...
0.746633
Codeforces_37205
C
[ "is_prime", "generate_prime_sequences", "format_prime_sequences" ]
3
[ [ "format_prime_sequences", "generate_prime_sequences" ], [ "generate_prime_sequences", "is_prime" ] ]
2
[]
false
[]
false
pytest
true
[]
true
a033dba2f83947ba989ba0db243369e914416b87
e13bf2b6bc13e0832a46f4de8864ad5985aef889
v1.0
complete
Codeforces
Codeforces_36903_C
from collections import defaultdict, deque from typing import List, Tuple def find_farthest_city_and_distance(n: int, graph: defaultdict, start_city: int) -> Tuple[int, int]: """ Find the farthest city and its distance from the start_city using BFS. """ visited = [False] * (n + 1) queue = deque([(s...
import sys from collections import defaultdict, deque def find_farthest_city_and_distance(n, graph, start_city): """ Find the farthest city and its distance from the start_city using BFS. """ visited = [False] * (n + 1) queue = deque([(start_city, 0)]) visited[start_city] = True farthest_ci...
from solution import max_travel_time, process_input def test_basic_case(): input_data = "2\n4\n1 2 4\n1 3 2\n3 4 3\n3\n1 2 5\n2 3 7\n" t, test_cases = process_input(input_data) results = max_travel_time(t, test_cases) assert results == [9, 12] def test_single_case_minimum_values(): input_data = "1...
[ { "docstring": "Find the farthest city and its distance from the start_city using BFS.", "function_declaration": "def find_farthest_city_and_distance(n, graph, start_city):", "function_name": "find_farthest_city_and_distance", "parameter_list": "(n, graph, start_city)" }, { "docstring": null...
[ 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": "import sys\nfrom collections import defaultdict, deque\n\ndef find_farthest_city_and_distance(n, graph, start_city):\n \"\"\"\n Find the farthest city a...
trial_gpt4o_0
{ "original_instruction": "In the kingdom of ByteLand, there are **n** cities. These cities are connected by **n-1** two-way roads such that there is exactly one path between any pair of cities. The inhabitants of ByteLand are friendly and often like to visit each other.\n\nYou are tasked with building an efficient t...
0.672773
Codeforces_36903
C
[ "find_farthest_city_and_distance", "max_travel_time", "process_input", "main" ]
4
[ [ "max_travel_time", "find_farthest_city_and_distance" ] ]
1
[ "process_input" ]
false
[]
false
pytest
true
[]
true
30e72d01ab1e8058e9aa7c98fab003d59c628a6d
859a15b713f810d8520d7da190386d4ed748e1c4
v1.0
complete
Codeforces
Codeforces_37195_C
from typing import List, Tuple def total_road_lengths(n: int, m: int, roads: List[Tuple[int, int, int]], q: int, toll_schemes: List[Tuple[int, int]]) -> List[int]: """ Calculate the total length of roads for each toll scheme. Parameters: n (int): Number of intersections m (int): Number of ...
def total_road_lengths(n, m, roads, q, toll_schemes): """ Calculate the total length of roads for each toll scheme. Parameters: n (int): Number of intersections m (int): Number of roads roads (list of tuples): List containing tuples with road informations (u, v, l) q (in...
import pytest from solution import total_road_lengths, solve def test_total_road_lengths(): n = 5 m = 5 roads = [(1, 2, 10), (2, 3, 20), (4, 5, 40), (3, 5, 30), (1, 4, 50)] q = 3 toll_schemes = [(1, 3), (2, 5), (1, 5)] expected = [70, 140, 150] assert total_road_lengths(n, m, roads, q,...
[ { "docstring": "Calculate the total length of roads for each toll scheme.\n\nParameters:\n n (int): Number of intersections\n m (int): Number of roads\n roads (list of tuples): List containing tuples with road informations (u, v, l)\n q (int): Number of toll schemes\n toll_schemes (list of tuples...
[ 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 calculate_length_of_roads(n, m, roads, q, schemes):\n \"\"\"\n Calculates the total length of roads included in each toll scheme.\n \n Paramet...
trial_gpt4o_1
{ "original_instruction": "In a city, there are n intersections and m roads connecting them. Each road is bi-directional and has a certain length. The city council wants to monitor the traffic and reduce congestion by imposing a toll on certain roads. Your task is to determine the total length of roads on which tolls...
0.601283
Codeforces_37195
C
[ "total_road_lengths", "solve" ]
2
[ [ "solve", "total_road_lengths" ] ]
1
[]
false
[]
false
pytest
true
[]
true
bae3d9cd00f3486a3fa83dc76f691815e131f465
76da242a116f194e3d4c46a781b14772622eb144
v1.0
complete
Codeforces
Codeforces_37133_C
def get_largest_magic_square(n: int, matrix: List[List[int]]) -> int: """ Find the largest magic square subgrid in a given n x n matrix. Magic square is a subgrid where numbers in each row, each column, and both main diagonals all add up to the same magic constant. >>> get_largest_magic_square(4, [ ...
def is_magic_square(grid, row, col, size): magic_sum = sum(grid[row][col:col+size]) # Check rows and columns for i in range(size): if sum(grid[row+i][col:col+size]) != magic_sum: return False if sum(grid[row+j][col+i] for j in range(size)) != magic_sum: return Fa...
def test_magic_square_4x4(): matrix = [ [8, 1, 6, 3], [3, 5, 7, 10], [4, 9, 2, 8], [11, 3, 6, 7] ] assert get_largest_magic_square(4, matrix) == 3 def test_no_magic_square(): matrix = [ [5, 6, 1], [2, 7, 8], [3, 4, 9] ] assert get_largest_...
[ { "docstring": null, "function_declaration": "def is_magic_square(grid, row, col, size):", "function_name": "is_magic_square", "parameter_list": "(grid, row, col, size)" }, { "docstring": null, "function_declaration": "def largest_magic_square(matrix, n):", "function_name": "largest_...
[ 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_magic_square(grid, row, col, size):\n magic_sum = sum(grid[row][col:col+size])\n for i in range(size):\n if sum(grid[row + i][col:col + si...
trial_gpt4o_4
{ "original_instruction": "You are given an n × n matrix filled with integers. Let's define a \"magic square\" as a subgrid of this matrix where the numbers in each row, each column, and both main diagonals all add up to the same constant, called the \"magic constant.\"\n\nYour task is to find the largest magic squar...
0.62531
Codeforces_37133
C
[ "is_magic_square", "largest_magic_square", "get_largest_magic_square" ]
3
[ [ "get_largest_magic_square", "largest_magic_square" ], [ "largest_magic_square", "is_magic_square" ] ]
2
[]
false
[]
false
pytest
false
[]
true
ff216ce26594c4b718685ec77082e28d1b5d3503
0c2e672572bb4a2bf9a4fc6b8868c240c48e9565
v1.0
complete
Codeforces
Codeforces_37366_C
MOD = 10**9 + 7 def matrix_mult(A, B, n): result = [[0] * n for _ in range(n)] for i in range(n): for j in range(n): for k in range(n): result[i][j] = (result[i][j] + A[i][k] * B[k][j]) % MOD return result def matrix_pow(A, k, n): result = [[1 if i == j else 0 for j...
MOD = 10**9 + 7 def matrix_mult(A, B, n): result = [[0] * n for _ in range(n)] for i in range(n): for j in range(n): for k in range(n): result[i][j] = (result[i][j] + A[i][k] * B[k][j]) % MOD return result def matrix_pow(A, k, n): result = [[1 if i == j else 0 for j...
from solution import matrix_mult, matrix_pow, compute_matrix_power def test_matrix_mult(): A = [[1, 1], [1, 0]] B = [[1, 1], [1, 0]] expected = [[2, 1], [1, 1]] assert matrix_mult(A, B, 2) == expected def test_matrix_pow(): A = [[1, 1], [1, 0]] expected = [[2, 1], [1, 1]] assert matrix_pow...
[ { "docstring": null, "function_declaration": "def matrix_mult(A, B, n):", "function_name": "matrix_mult", "parameter_list": "(A, B, n)" }, { "docstring": null, "function_declaration": "def matrix_pow(A, k, n):", "function_name": "matrix_pow", "parameter_list": "(A, k, n)" }, ...
[ 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": "MOD = 10**9 + 7\n\ndef matrix_mult(A, B, n):\n \"\"\"Multiplies two matrices A and B of size n and returns the resulting matrix modulo 10^9 + 7.\"\"\"\n ...
trial_gpt4o_2
{ "original_instruction": "Tarun is learning about matrix operations and has come across the concept of matrix exponentiation. He is particularly interested in computing the power of a square matrix. Given a square matrix A of size n and a positive integer k, the k-th power of the matrix A is defined as multiplying t...
0.588186
Codeforces_37366
C
[ "matrix_mult", "matrix_pow", "compute_matrix_power", "main" ]
4
[ [ "compute_matrix_power", "matrix_pow" ], [ "matrix_pow", "matrix_mult" ] ]
2
[]
false
[]
false
pytest
true
[]
true
f549425c8820c4c2ace80f4b7b6531a0dc5b013d
49325c58b0f939382522fa36077dbd6721faccc8
v1.0
complete
Codeforces
Codeforces_36613_C
from typing import List def maximalRectangle(matrix: List[List[int]]) -> int: """ Determine the area of the largest rectangular castle that can be built using the usable land cells. Args: matrix: List of List containing 0s and 1s representing the grid. Returns: An integer representing the...
def maximalRectangle(matrix): if not matrix or not matrix[0]: return 0 n = len(matrix) m = len(matrix[0]) # Initialize variables max_area = 0 # Heights array heights = [0] * m for row in range(n): for col in range(m): # Update the heights hi...
from solution import maximalRectangle def test_example_case(): matrix = [ [1, 0, 1, 0, 0], [1, 0, 1, 1, 1], [1, 1, 1, 1, 1], [1, 0, 0, 1, 0] ] assert maximalRectangle(matrix) == 6 def test_single_row(): matrix = [[1, 0, 1, 1, 1]] assert maximalRectangle(matrix) == 3...
[ { "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(matrix):\n if not matrix or not matrix[0]:\n return 0\n \n def max_histogram_area(heights):\n stack = []\n ...
trial_gpt4o_1
{ "original_instruction": "The kingdom of Farland is a prosperous region known for its powerful knights and magical beings. Recently, their king has called upon a special architect to plan the largest rectangular castle that can be built using specific sections of land within the kingdom.\n\nThe kingdom is represente...
0.635049
Codeforces_36613
C
[ "maximalRectangle", "largestRectangleArea" ]
2
[ [ "maximalRectangle", "largestRectangleArea" ] ]
1
[]
false
[]
false
pytest
true
[]
true
cca27c5cafe7e6bce884dccfd0257c886803bde2
a8989c7bd4745d22bd8faa95946289f92a9e80a6
v1.0
complete
Codeforces
Codeforces_35969_C
from typing import List, Tuple def find_shortest_path(n: int, m: int, k: int, edges: List[Tuple[int, int, int]]) -> int: """ Find the shortest path from node 1 to node n using at most k edges in an undirected, weighted graph. >>> find_shortest_path(6, 7, 3, [(1, 2, 5), (2, 3, 10), (1, 4, 2), (4, 5, 3), (5, 6,...
import heapq def shortest_path_with_k_edges(n, m, k, edges): # Initialize adjacency list graph = [[] for _ in range(n + 1)] for u, v, w in edges: graph[u].append((v, w)) graph[v].append((u, w)) # (dist, node, edges_used) pq = [(0, 1, 0)] # Start from node 1 with distance 0 and 0 ed...
from solution import find_shortest_path def test_case_1(): n = 6 m = 7 k = 3 edges = [ (1, 2, 5), (2, 3, 10), (1, 4, 2), (4, 5, 3), (5, 6, 8), (3, 6, 1), (2, 6, 4) ] assert find_shortest_path(n, m, k, edges) == 9 def test_case_2(): n ...
[ { "docstring": null, "function_declaration": "def shortest_path_with_k_edges(n, m, k, edges):", "function_name": "shortest_path_with_k_edges", "parameter_list": "(n, m, k, edges)" }, { "docstring": null, "function_declaration": "def find_shortest_path(n, m, k, edge_list):", "function...
[ 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 shortest_path(n, m, k, edges):\n INF = float('inf')\n dp = [[INF] * (k + 1) for _ in range(n + 1)]\n dp[1][0] = 0 # Starting point\n \n fo...
trial_gpt4o_1
{ "original_instruction": "You are given an undirected, weighted graph with $$$n$$$ nodes and $$$m$$$ edges. Each edge has a positive integer weight. Your task is to find the shortest path from node $$$1$$$ to node $$$n$$$ using at most $$$k$$$ edges. If there is no such path, output -1.\n\nThe first line contains th...
0.67013
Codeforces_35969
C
[ "shortest_path_with_k_edges", "find_shortest_path" ]
2
[ [ "find_shortest_path", "shortest_path_with_k_edges" ] ]
1
[]
false
[]
false
pytest
true
[]
true
f047e43c990cbbedf6494b48382c72852128f96f
89ec5a2e8ba885997e922b7b3a8aa38c762b4fc2
v1.0
complete
Codeforces
Codeforces_37754_C
def best_garden_plan(n: int, m: int, plans: List[str]) -> str: """ Find the garden plan that yields the highest beauty score. If there are multiple plans with the same score, choose the lexicographically smallest plan. Args: n (int): Number of plots in each garden plan. m (int): Number of ...
def calculate_beauty(plan): """ Calculate the beauty score of a garden plan. :param plan: A string representing the garden plan. :return: An integer representing the beauty score. """ num_flowers = plan.count('F') if num_flowers == 0: return 0 max_consecutive = 0 curren...
from solution import best_garden_plan def test_best_garden_plan_example(): assert best_garden_plan(5, 3, ["EFFFE", "FFFFE", "EEFEE"]) == "FFFFE" def test_best_garden_plan_single_plan(): assert best_garden_plan(5, 1, ["EFFFE"]) == "EFFFE" def test_best_garden_plan_identical_scores(): assert best_garden_pl...
[ { "docstring": "Calculate the beauty score of a garden plan.\n\n:param plan: A string representing the garden plan.\n:return: An integer representing the beauty score.", "function_declaration": "def calculate_beauty(plan):", "function_name": "calculate_beauty", "parameter_list": "(plan)" }, { ...
[ 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_beauty_score(garden_plan):\n flowers_count = garden_plan.count('F')\n max_consecutive_flowers = max(map(len, garden_plan.split('E')))\n ...
trial_gpt4o_2
{ "original_instruction": "A group of neighbors are planning a community garden with n plots arranged in a straight line, where each plot can either contain a flower or be empty. They want to grow flowers in such a way that the beauty score of the garden is maximized. The beauty score is calculated as the total numbe...
0.511111
Codeforces_37754
C
[ "calculate_beauty", "best_garden_plan" ]
2
[ [ "best_garden_plan", "calculate_beauty" ] ]
1
[]
false
[]
false
pytest
true
[]
true
9e3db9b87357a9a6c46aeb560f6da6d83f542877
9f111a756ed32674bba8ca5b8637dbdd8b192603
v1.0
complete
Codeforces
Codeforces_37628_C
import heapq from typing import List, Tuple def find_min_cost(n: int, m: int, corridors: List[Tuple[int, int, int, int]]) -> int: """ Compute the minimum cost required for Vasya to travel from room '1' to room 'n'. Args: n: int - the number of rooms m: int - the number of corridors corrid...
import heapq def find_min_cost(n, m, corridors): graph = {i: [] for i in range(1, n + 1)} for a, b, c, d in corridors: graph[a].append((b, c)) graph[b].append((a, d)) # Dijkstra's Algorithm pq = [(0, 1)] # (cost, node) dist = {i: float('inf') for i in range(1, n + 1)} dist...
from solution import find_min_cost def test_basic_case(): n = 5 m = 6 corridors = [ (1, 2, 5, 10), (1, 3, 10, 5), (2, 4, 2, 3), (3, 4, 3, 2), (4, 5, 1, 1), (3, 5, 8, 8) ] assert find_min_cost(n, m, corridors) == 8 def test_no_path(): n = 3 m ...
[ { "docstring": null, "function_declaration": "def find_min_cost(n, m, corridors):", "function_name": "find_min_cost", "parameter_list": "(n, m, corridors)" }, { "docstring": null, "function_declaration": "def example_usage():", "function_name": "example_usage", "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": "import heapq\n\ndef find_min_cost(n, m, corridors):\n graph = {i: [] for i in range(1, n + 1)}\n for a, b, c, d in corridors:\n graph[a].append((...
trial_gpt4o_0
{ "original_instruction": "Vasya is a student in a university that has a peculiar configuration of rooms. The university has 'n' rooms and there are several corridors connecting pairs of rooms. Vasya is in room '1' and he wants to reach room 'n'. The problem is that the university has specific rules for moving from o...
0.661178
Codeforces_37628
C
[ "find_min_cost", "example_usage" ]
2
[ [ "example_usage", "find_min_cost" ] ]
1
[]
false
[]
false
pytest
true
[]
true
92213ff4589c9081f1aa45bf0ec35f106ec8bc02
a3c2e84af338fcdef077f05b9ba78f4d09c3c0d3
v1.0
complete
Codeforces
Codeforces_37551_C
def analyze_performance(input_string: str) -> List[int]: """ Analyze athlete performance by querying points within specific date ranges. Args: input_string (str): A string containing the performance data and queries. Returns: List[int]: A list of the total points for each query range. ...
def parse_input(input_string): lines = input_string.strip().split('\n') n = int(lines[0]) performance_data = {} for i in range(1, n + 1): date, points = lines[i].split() performance_data[date] = int(points) m = int(lines[n + 1]) queries = [] for i in range(n + 2, n + 2 +...
def test_analyze_performance(): input_string = '''5 2023-01-01 10 2023-01-05 20 2023-02-01 15 2023-02-10 10 2023-02-15 5 3 2023-01-01 2023-01-31 2023-02-01 2023-02-28 2023-01-01 2023-02-28''' expected_output = [30, 30, 60] assert analyze_performance(input_string) == expected_output def test_analyze_perform...
[ { "docstring": null, "function_declaration": "def parse_input(input_string):", "function_name": "parse_input", "parameter_list": "(input_string)" }, { "docstring": null, "function_declaration": "def calculate_points(performance_data, queries):", "function_name": "calculate_points", ...
[ 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 parse_input(input_string):\n lines = input_string.strip().split('\\n')\n n = int(lines[0])\n performance_data = {}\n for i in range(1, n + 1):...
trial_gpt4o_0
{ "original_instruction": "A rising star athlete downloaded an app that records her training and competition results over the year. For each of her training sessions or competitions, the app records the date (in `YYYY-MM-DD` format) and her performance, quantified as an integer representing points scored.\n\nThe athl...
0.621102
Codeforces_37551
C
[ "parse_input", "calculate_points", "analyze_performance" ]
3
[ [ "analyze_performance", "calculate_points" ], [ "analyze_performance", "parse_input" ] ]
2
[ "parse_input" ]
false
[]
false
pytest
false
[]
true
1ad340ad74a8393eb6cc89fc72a268846ecbc6ac
b0268ed026b5a9438875b8e8b7f9e549d601ddb1
v1.0
complete
Codeforces
Codeforces_37957_C
from typing import List def words_in_grid(r: int, c: int, grid: List[str], w: int, words: List[str]) -> List[str]: """Given a 2D grid and a list of words, determine if each word can be found in the grid horizontally, vertically, or diagonally. >>> words_in_grid(4, 4, ["aabc", "bdaa", "daad", "cdba"], 3, ["ab",...
def find_word_in_grid(grid, word): rows, cols = len(grid), len(grid[0]) word_len = len(word) # 8 possible directions: (row movement, col movement) directions = [(-1, 0), (1, 0), (0, -1), (0, 1), (-1, -1), (-1, 1), (1, -1), (1, 1)] def in_bounds(x, y): return 0 <= x < row...
from solution import words_in_grid def test_example_case(): grid = [ "aabc", "bdaa", "daad", "cdba" ] words = ["ab", "cdd", "abcd"] result = words_in_grid(4, 4, grid, 3, words) assert result == ["YES", "YES", "NO"] def test_single_character_grid(): grid = ["a"] ...
[ { "docstring": null, "function_declaration": "def find_word_in_grid(grid, word):", "function_name": "find_word_in_grid", "parameter_list": "(grid, word)" }, { "docstring": null, "function_declaration": "def words_in_grid(r, c, grid, w, words):", "function_name": "words_in_grid", ...
[ 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 find_word_in_grid(grid, word):\n rows, cols = len(grid), len(grid[0])\n word_len = len(word)\n\n # 8 possible directions: (row movement, col move...
trial_gpt4o_0
{ "original_instruction": "Gina loves puzzles, and she recently came across a unique code-breaking challenge. The challenge involves a two-dimensional grid of characters, where hidden amongst the characters are target words that you must find.\n\nA word can be hidden horizontally, vertically, or diagonally in any dir...
0.684609
Codeforces_37957
C
[ "find_word_in_grid", "words_in_grid" ]
2
[ [ "words_in_grid", "find_word_in_grid" ] ]
1
[]
false
[]
false
pytest
true
[]
true
fda9abe9a48374d271aea58e3486f6c8dd5e1be4
b80ebdc495f0d5dc4bfe74d58a6f13d9a4c57551
v1.0
complete
Codeforces
Codeforces_38163_C
def number_of_good_permutations(t, cases): """ Determine the number of good permutations of integers from 1 to n for multiple test cases. Args: t: int - the number of test cases cases: List[int] - a list of integers, where each integer n represents the length of the permutation Returns: Li...
MOD = 10**9 + 7 def precompute_derangements(max_n): """ Precompute the derangements for all numbers from 0 to max_n. """ derangements = [0] * (max_n + 1) if max_n >= 2: derangements[1] = 0 derangements[2] = 1 for i in range(3, max_n + 1): derangements[i] = (i - 1...
from solution import number_of_good_permutations def test_single_case(): assert number_of_good_permutations(1, [1]) == [0] def test_multiple_cases(): assert number_of_good_permutations(3, [1, 2, 3]) == [0, 1, 2] def test_large_case(): n_max = 10**5 result = number_of_good_permutations(1, [n_max])...
[ { "docstring": "Precompute the derangements for all numbers from 0 to max_n.", "function_declaration": "def precompute_derangements(max_n):", "function_name": "precompute_derangements", "parameter_list": "(max_n)" }, { "docstring": null, "function_declaration": "def number_of_good_permut...
[ 0, 0, 0, 0, 0, 1, 0, 0, 1 ]
2
hard
0.222
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "MOD = 10**9 + 7\n\ndef preprocess(limit):\n dp = [0] * (limit + 1)\n dp[0], dp[1] = 1, 0\n\n for i in range(2, limit + 1):\n dp[i] = (i - 1) *...
trial_gpt4o_9
{ "original_instruction": "You are given a permutation of integers from $$$1$$$ to $$$n$$$. A permutation is called good if no element in the sequence is at its original position (i.e., the position it would be in if the permutation were sorted in ascending order). This type of permutation is also known as a derangem...
0.655278
Codeforces_38163
C
[ "precompute_derangements", "number_of_good_permutations" ]
2
[ [ "number_of_good_permutations", "precompute_derangements" ] ]
1
[]
false
[]
false
pytest
true
[]
true
d97f0d13ef3f5d0ea4d249e55feddbaecc8a0109
3be8c6515c5fc14dc5fe49d02e18526a08aaa549
v1.0
complete
Codeforces
Codeforces_38241_C
from typing import List def can_be_sorted(n: int, k: int, strings: List[str]) -> str: """ Determine if there exists a permutation of the columns such that all strings in the list are lexicographically sorted. Function parameters: n (int): The length of each string. k (int): The number of strings. ...
from itertools import permutations def is_lexicographically_sorted(strings): return all(strings[i] <= strings[i + 1] for i in range(len(strings) - 1)) def can_be_sorted(n, k, strings): for perm in permutations(range(n)): permuted_strings = ["".join(s[j] for j in perm) for s in strings] if is_l...
from solution import can_be_sorted def test_example_case1(): n = 3 k = 3 strings = ["abc", "cba", "bca"] assert can_be_sorted(n, k, strings) == "YES" def test_example_case2(): n = 3 k = 3 strings = ["aac", "caa", "bac"] assert can_be_sorted(n, k, strings) == "NO" def test_edge_cas...
[ { "docstring": null, "function_declaration": "def is_lexicographically_sorted(strings):", "function_name": "is_lexicographically_sorted", "parameter_list": "(strings)" }, { "docstring": null, "function_declaration": "def can_be_sorted(n, k, strings):", "function_name": "can_be_sorted...
[ 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 itertools import permutations\n\ndef is_lexicographically_sorted(lst):\n \"\"\" Check if the list of strings is lexicographically sorted \"\"\"\n r...
trial_gpt4o_2
{ "original_instruction": "You are given a list of $$$k$$$ strings. Each string contains lowercase Latin letters and has length exactly $$$n$$$. Your task is to determine if there exists a permutation of the columns such that all strings in the list are lexicographically sorted.\n\nA permutation of the columns means ...
0.664951
Codeforces_38241
C
[ "is_lexicographically_sorted", "can_be_sorted" ]
2
[ [ "can_be_sorted", "is_lexicographically_sorted" ] ]
1
[]
false
[]
false
pytest
true
[]
true
9d9d02ad3a53a59964abeee025efdb934ac14b7d
db007ac48209484b74d7970d7b3f95cc508f1550
v1.0
complete
Codeforces
Codeforces_38328_C
def max_rectangle_area(grid): """ Determine the area of the largest rectangular subgrid composed entirely of fertile land. >>> max_rectangle_area([[1, 0, 1, 1, 1], [1, 1, 1, 1, 0], [0, 1, 1, 0, 0], [1, 1, 1, 0, 1]]) 6 >>> max_rectangle_area([[1, 1, 1], [1, 1, 1], [1, 1, 1]]) 9 >>> max_rectangle_...
def max_rectangle_area(grid): if not grid: return 0 n = len(grid) m = len(grid[0]) max_area = 0 heights = [0] * m for row in grid: for j in range(m): if row[j] == 0: heights[j] = 0 else: heights[j] += 1 max_area =...
import pytest from solution import max_rectangle_area def test_max_rectangle_area_example1(): grid = [ [1, 0, 1, 1, 1], [1, 1, 1, 1, 0], [0, 1, 1, 0, 0], [1, 1, 1, 0, 1] ] assert max_rectangle_area(grid) == 6 def test_max_rectangle_area_all_fertile(): grid = [ [...
[ { "docstring": null, "function_declaration": "def max_rectangle_area(grid):", "function_name": "max_rectangle_area", "parameter_list": "(grid)" }, { "docstring": null, "function_declaration": "def largest_rectangle_area_histogram(heights):", "function_name": "largest_rectangle_area_h...
[ 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_fertile_subgrid_area(n, m, grid):\n \"\"\"\n Given a 2D grid, determines the area of the largest rectangular subgrid composed entirely of fe...
trial_gpt4o_2
{ "original_instruction": "Farmer Bob has a rectangular field represented as a grid of size n x m. Each cell in the grid can either be fertile land (represented by 1) or infertile land (represented by 0). Farmer Bob wants to grow his crops in a single rectangular subgrid within his field. However, he will only plant ...
0.717859
Codeforces_38328
C
[ "max_rectangle_area", "largest_rectangle_area_histogram" ]
2
[ [ "max_rectangle_area", "largest_rectangle_area_histogram" ] ]
1
[]
false
[]
false
pytest
true
[]
true
2b18bbbfd6cee15a79ccd778c31742d4bc959acc
61bca4f3fe45d2b80532b21a2e0874ff3cad20b5
v1.0
complete
Codeforces
Codeforces_38337_C
def minimum_new_roads(n: int, roads: List[Tuple[int, int]]) -> int: """ Bob the builder needs to construct a series of new roads to connect all the villages in the town of Slumberville. The town has n villages and r already existing bidirectional roads. Bob wants to ensure that after his new roads are built, th...
def find(parent, i): if parent[i] == i: return i else: return find(parent, parent[i]) def union(parent, rank, x, y): root_x = find(parent, x) root_y = find(parent, y) if root_x != root_y: if rank[root_x] > rank[root_y]: parent[root_y] = root_x elif rank[...
def test_minimum_new_roads(): assert minimum_new_roads(4, [(1, 2), (2, 3)]) == 1 assert minimum_new_roads(4, [(1, 2), (2, 3), (3, 4)]) == 0 assert minimum_new_roads(6, [(1, 2), (2, 3), (4, 5)]) == 2 assert minimum_new_roads(1, []) == 0 assert minimum_new_roads(5, [(1, 2), (2, 3), (3, 4), (4, 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, 0 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def find(parent, i):\n if parent[i] == i:\n return i\n else:\n return find(parent, parent[i])\n\ndef union(parent, rank, x, y):\n root_...
trial_gpt4o_0
{ "original_instruction": "Bob the builder needs to construct a series of new roads to connect all the villages in the town of Slumberville. The town has n villages and r already existing bidirectional roads. Bob wants to ensure that after his new roads are built, there is a way to travel between any two villages. Si...
0.726487
Codeforces_38337
C
[ "find", "union", "minimum_new_roads" ]
3
[ [ "minimum_new_roads", "find" ], [ "minimum_new_roads", "union" ], [ "union", "find" ] ]
3
[]
false
[]
false
pytest
false
[]
true
f6bdf8f9f17fc596a16b500890406023fd426671
f8c1475fdf444ab3f8773463fcd11350d7b95284
v1.0
complete
Codeforces
Codeforces_38104_C
def get(nums, index): """ Simulate the behavior of accessing an infinite array. Returns the element at index if within bounds, otherwise returns float('inf') to represent Integer.MAX_VALUE. """ if index < len(nums): return nums[index] else: return float('inf') def find_position(...
def get(nums, index): """ Simulate the behavior of accessing an infinite array. Returns the element at index if within bounds, otherwise returns float('inf') to represent Integer.MAX_VALUE. """ if index < len(nums): return nums[index] else: return float('inf') def find_position(...
from solution import find_position, get def test_element_present(): nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] assert find_position(nums, 5) == 4 def test_element_absent(): nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] assert find_position(nums, 20) == -1 def test_first_element(): nums = [1, 2, 3, 4, 5, 6, ...
[ { "docstring": "Simulate the behavior of accessing an infinite array.\nReturns the element at index if within bounds, otherwise returns float('inf') to represent Integer.MAX_VALUE.", "function_declaration": "def get(nums, index):", "function_name": "get", "parameter_list": "(nums, index)" }, { ...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "class InfiniteArraySearch:\n def get(self, index):\n \"\"\"\n Simulates accessing an infinite array. \n For the purpose of this soluti...
trial_gpt4o_2
{ "original_instruction": "You are given an infinite sorted array. You are unaware of the end of the array, and you do not know its length. The array has distinct integers in non-decreasing order. You need to find the position of a given target value in this sorted infinite array. \n\nImplement a function `int findPo...
0.604083
Codeforces_38104
C
[ "get", "find_position" ]
2
[ [ "find_position", "get" ] ]
1
[]
false
[]
false
pytest
true
[]
true
8677b352f5aa0ac3ae1b378c361564ffb28b53d8
88163c108b8d7368348a184c59fcdb0db9edf53d
v1.0
complete
Codeforces
Codeforces_38453_C
def minCostToConnectCities(n, m, connections): """ Determine the minimum cost required to connect all the cities such that every city is reachable from any other city. :param n: Number of cities :param m: Number of cable lines :param connections: List of connections, where each connection is with t...
def find(parent, i): if parent[i] == i: return i else: return find(parent, parent[i]) def union(parent, rank, x, y): xroot = find(parent, x) yroot = find(parent, y) if rank[xroot] < rank[yroot]: parent[xroot] = yroot elif rank[xroot] > rank[yroot]: parent[yr...
def test_min_cost_example(): connections = [(1, 2, 3), (2, 3, 1), (3, 4, 4), (4, 1, 2), (1, 3, 5)] assert minCostToConnectCities(4, 5, connections) == 6 def test_min_cost_single_city(): connections = [] assert minCostToConnectCities(1, 0, connections) == 0 def test_min_cost_no_connections(): conne...
[ { "docstring": null, "function_declaration": "def find(parent, i):", "function_name": "find", "parameter_list": "(parent, i)" }, { "docstring": null, "function_declaration": "def union(parent, rank, x, y):", "function_name": "union", "parameter_list": "(parent, rank, x, y)" }, ...
[ 0, 0, 1 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def find_parent(parent, x):\n if parent[x] != x:\n parent[x] = find_parent(parent, parent[x]) # Path compression\n return parent[x]\n\ndef union...
trial_gpt4o_2
{ "original_instruction": "You work for a company that provides internet services to several cities. To improve the infrastructure, they want to optimize their deployment of the internet cable lines between cities. Each cable line connects two distinct cities and has an associated cost.\n\nGiven the existing network ...
0.66977
Codeforces_38453
C
[ "find", "union", "minCostToConnectCities" ]
3
[ [ "minCostToConnectCities", "find" ], [ "minCostToConnectCities", "union" ], [ "union", "find" ] ]
3
[]
false
[]
false
pytest
false
[]
true
bf83c0ebbd506799908462a0287f3ceca8107c77
0df1d84373f7a40b8f68f2813f0fe5c0dba715ba
v1.0
complete
Codeforces
Codeforces_38401_C
def find_subarray_lengths(n: int, k: int, arr: List[int]) -> Tuple[int, int]: """ Find the length of the longest subarray with a sum of at most k and the length of the shortest subarray with a sum of at least k. Args: n (int): The number of elements in the array. k (int): The specified sum conditio...
def longest_subarray_with_at_most_sum(arr, k): n = len(arr) max_length = 0 current_sum = 0 start = 0 for end in range(n): current_sum += arr[end] while current_sum > k: current_sum -= arr[start] start += 1 max_length = max(max_le...
from solution import find_subarray_lengths def test_example_case(): n = 10 k = 15 arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] result = find_subarray_lengths(n, k, arr) assert result == (5, 2) def test_no_valid_longest(): n = 5 k = 2 arr = [5, 5, 5, 5, 5] result = find_subarray_lengths(n,...
[ { "docstring": null, "function_declaration": "def longest_subarray_with_at_most_sum(arr, k):", "function_name": "longest_subarray_with_at_most_sum", "parameter_list": "(arr, k)" }, { "docstring": null, "function_declaration": "def shortest_subarray_with_at_least_sum(arr, k):", "funct...
[ 0, 0, 0, 0, 0, 0, 0, 1, 0, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def find_subarray_lengths(n, k, arr):\n def longest_subarray_with_sum_at_most_k(n, k, arr):\n start = 0\n sum = 0\n max_length = 0\n ...
trial_gpt4o_7
{ "original_instruction": "You are given an array of n integers, and you need to perform the following tasks on it:\n\n1. Find the length of the longest subarray such that the sum of the elements in this subarray is at most k.\n2. Find the length of the shortest subarray such that the sum of the elements in this suba...
0.730063
Codeforces_38401
C
[ "longest_subarray_with_at_most_sum", "shortest_subarray_with_at_least_sum", "find_subarray_lengths" ]
3
[ [ "find_subarray_lengths", "longest_subarray_with_at_most_sum" ], [ "find_subarray_lengths", "shortest_subarray_with_at_least_sum" ] ]
2
[]
false
[]
false
pytest
true
[]
true
030d086e3403958334eb22b4324893cc1e5ff3db
13e8e917bdc0f212656527daa27ec91b4b06dbb0
v1.0
complete
Codeforces
Codeforces_38774_C
def shortest_paths(n, m, edges, q, queries): """ Compute the shortest path for each query, or determine that no such path exists. >>> shortest_paths(4, 4, [(1, 2, 1), (2, 3, 3), (3, 4, 1), (1, 4, 5)], 3, [(1, 4), (1, 3), (3, 1)]) [5, 4, -1] >>> shortest_paths(1, 0, [], 1, [(1, 1)]) [0] """
def floyd_warshall(n, edges): """ Uses the Floyd-Warshall algorithm to compute shortest paths between all pairs of vertices. """ inf = float('inf') dist = [[inf] * n for _ in range(n)] for i in range(n): dist[i][i] = 0 for a, b, w in edges: dist[a-1][b-1] = min(dist[a-1...
def test_shortest_paths(): n = 4 m = 4 edges = [ (1, 2, 1), (2, 3, 3), (3, 4, 1), (1, 4, 5) ] q = 3 queries = [ (1, 4), (1, 3), (3, 1) ] expected = [5, 4, -1] assert shortest_paths(n, m, edges, q, queries) == expected def test_...
[ { "docstring": "Uses the Floyd-Warshall algorithm to compute shortest paths between all pairs of vertices.", "function_declaration": "def floyd_warshall(n, edges):", "function_name": "floyd_warshall", "parameter_list": "(n, edges)" }, { "docstring": null, "function_declaration": "def sho...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "import heapq\n\ndef dijkstra(graph, start, n):\n \"\"\"\n Implements Dijkstra algorithm to find shortest paths from start node to all other nodes\n \...
trial_gpt4o_1
{ "original_instruction": "You are given a directed graph with **n** vertices and **m** edges. Each edge has a cost associated with it. You need to answer **q** queries, each query asking for the cost of the shortest path between two given vertices **u** and **v**.\n\nThe following constraints are guaranteed:\n\n- Th...
0.65705
Codeforces_38774
C
[ "floyd_warshall", "shortest_paths" ]
2
[ [ "shortest_paths", "floyd_warshall" ] ]
1
[]
false
[]
false
pytest
false
[]
true
712b274cc0efb28292151db434b423b30848ef67
6f3a44cdbbc14c9ee2b84b189b39ac9def36e30d
v1.0
complete
Codeforces
Codeforces_38656_C
def min_additional_edges_to_reduce_components(n: int, m: int, k: int, friendships: List[Tuple[int, int]]) -> int: """ Determine the minimum number of additional edges required to reduce the number of connected components in the friendship graph to no more than a given threshold. >>> min_additional_edges_to_...
def find_parent(parent, i): if parent[i] == i: return i return find_parent(parent, parent[i]) def union(parent, rank, x, y): xroot = find_parent(parent, x) yroot = find_parent(parent, y) if xroot != yroot: if rank[xroot] < rank[yroot]: parent[xroot] = yroot ...
from solution import min_additional_edges_to_reduce_components def test_example_case(): assert min_additional_edges_to_reduce_components(6, 3, 2, [(1, 2), (2, 3), (4, 5)]) == 1 def test_no_edges_needed(): assert min_additional_edges_to_reduce_components(5, 3, 2, [(1, 2), (2, 3), (4, 5)]) == 0 def test_alread...
[ { "docstring": null, "function_declaration": "def find_parent(parent, i):", "function_name": "find_parent", "parameter_list": "(parent, i)" }, { "docstring": null, "function_declaration": "def union(parent, rank, x, y):", "function_name": "union", "parameter_list": "(parent, rank...
[ 0, 0, 0, 0, 0, 0, 0, 1, 0, 1 ]
2
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def find_parent(parent, i):\n if parent[i] == i:\n return i\n else:\n parent[i] = find_parent(parent, parent[i])\n return parent[i]...
trial_gpt4o_7
{ "original_instruction": "In a large university, there is a popular social networking app called UniConnect. In this app, each student is uniquely represented by an ID number, and friendships between students can be represented as undirected edges in a graph. Unfortunately, the university's network team has observed...
0.610584
Codeforces_38656
C
[ "find_parent", "union", "min_additional_edges_to_reduce_components" ]
3
[ [ "min_additional_edges_to_reduce_components", "find_parent" ], [ "min_additional_edges_to_reduce_components", "union" ], [ "union", "find_parent" ] ]
3
[]
false
[]
false
pytest
true
[]
true
ed2683c850887c78c75855de6376b1ba4c6b25ec
65c3beffff8cbb98804a0f0a6089fc14b3c3f1d6
v1.0
complete
Codeforces
Codeforces_38528_C
from typing import List, Tuple def shortest_round_trip(n: int, m: int, roads: List[Tuple[int, int, int]], s: int, d: int) -> int: """ Calculate the minimum round-trip travel time from city s to city d and back to city s. Args: n (int): The number of cities. m (int): The number of roads. roads ...
import heapq def dijkstra(graph, start, n): """ Executes the Dijkstra algorithm to find the shortest paths from the start node. Returns the distances array. """ distances = [float("inf")] * (n + 1) distances[start] = 0 priority_queue = [(0, start)] while priority_queue: current_...
from solution import shortest_round_trip def test_example_case(): roads = [ (1, 2, 10), (2, 3, 10), (3, 4, 10), (4, 5, 10), (5, 1, 10), (1, 3, 15) ] assert shortest_round_trip(5, 6, roads, 1, 4) == 40 def test_single_direct_road(): roads = [ (1, ...
[ { "docstring": "Executes the Dijkstra algorithm to find the shortest paths from the start node.\nReturns the distances array.", "function_declaration": "def dijkstra(graph, start, n):", "function_name": "dijkstra", "parameter_list": "(graph, start, n)" }, { "docstring": null, "function_d...
[ 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": "import heapq\n\ndef dijkstra(graph, start, n):\n queue = [(0, start)]\n distances = {i: float('inf') for i in range(1, n + 1)}\n distances[start] = 0...
trial_gpt4o_8
{ "original_instruction": "In Farland, each city is represented as a node in a graph. Roads connect the cities, and each road has a time cost associated with it. The roads allow travel between any two cities in both directions. The ruler of Farland has a peculiar interest in finding the shortest round-trip path for a...
0.769587
Codeforces_38528
C
[ "dijkstra", "shortest_round_trip" ]
2
[ [ "shortest_round_trip", "dijkstra" ] ]
1
[]
false
[]
false
pytest
true
[]
true
b64a8edaeac695ec2fa519682c26eea6920b0e6a
b849d810f0d79aa0de4f3e93f0c6d46d060357b5
v1.0
complete
Codeforces
Codeforces_38644_C
import math from itertools import combinations from typing import List, Tuple def is_square(p1: Tuple[int, int], p2: Tuple[int, int], p3: Tuple[int, int], p4: Tuple[int, int]) -> bool: """ Check if the given four points form a square. >>> is_square((0, 0), (0, 1), (1, 0), (1, 1)) True >>> is_square((0,...
import math from itertools import combinations def is_square(p1, p2, p3, p4): """ Check if the given four points form a square """ points = [p1, p2, p3, p4] distances = sorted([distance(points[i], points[j]) for i in range(4) for j in range(i + 1, 4)]) return distances[0] > 0 and distances[0] ...
import pytest from solution import process_flatland_kingdom, four_towns_form_square def test_example_case(): data = """5 0 0 0 1 1 0 1 1 2 2""" assert process_flatland_kingdom(data) == "YES" def test_no_square(): data = """4 0 0 0 1 1 1 2 2""" assert process_flatland_kingdom(data) == "NO" def test_la...
[ { "docstring": "Check if the given four points form a square", "function_declaration": "def is_square(p1, p2, p3, p4):", "function_name": "is_square", "parameter_list": "(p1, p2, p3, p4)" }, { "docstring": "Calculate the squared distance between two points to avoid floating point precision i...
[ 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 is_square(x1, y1, x2, y2, x3, y3, x4, y4):\n \"\"\"\n Check if four points form a square.\n \"\"\"\n from collections import Counter\n impo...
trial_gpt4o_2
{ "original_instruction": "The kingdom of Flatland is a perfectly flat plane filled with intricate road networks connecting various towns. The king of Flatland has a peculiar fondness for squares, and he wants to identify all the possible squares that can be formed by towns connected through the road networks.\n\nYou...
0.569304
Codeforces_38644
C
[ "is_square", "distance", "four_towns_form_square", "process_flatland_kingdom" ]
4
[ [ "four_towns_form_square", "is_square" ], [ "is_square", "distance" ], [ "process_flatland_kingdom", "four_towns_form_square" ] ]
3
[]
false
[]
false
pytest
true
[]
true
550cf1ee3ca8f196f86b941c6713dd446c048aa9
717aacc6de221e7a8bca466ea0221532a232510c
v1.0
complete
Codeforces
Codeforces_38332_C
def find_land_masses(grid, n, m): def dfs(x, y): if x < 0 or y < 0 or x >= n or y >= m or grid[x][y] != 'L': return grid[x][y] = 'V' # Mark as visited for dx, dy in [(-1, 0), (1, 0), (0, -1), (0, 1)]: dfs(x + dx, y + dy) land_masses = 0 for i in range(n): ...
def find_land_masses(grid, n, m): def dfs(x, y): if x < 0 or y < 0 or x >= n or y >= m or grid[x][y] != 'L': return grid[x][y] = 'V' # Mark as visited for dx, dy in [(-1, 0), (1, 0), (0, -1), (0, 1)]: dfs(x + dx, y + dy) land_masses = 0 for i in range(n): ...
from solution import min_land_masses_after_change def test_min_land_masses_after_change(): n, m = 3, 3 grid = [ ['L', 'W', 'L'], ['L', 'L', 'L'], ['W', 'L', 'W'] ] assert min_land_masses_after_change(n, m, grid) == 1 def test_single_land(): n, m = 1, 1 grid = [ ...
[ { "docstring": null, "function_declaration": "def find_land_masses(grid, n, m):", "function_name": "find_land_masses", "parameter_list": "(grid, n, m)" }, { "docstring": null, "function_declaration": "def min_land_masses_after_change(n, m, grid):", "function_name": "min_land_masses_a...
[ 0, 1, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def min_land_masses(grid):\n from collections import deque\n \n def num_land_masses(grid):\n n, m = len(grid), len(grid[0])\n visited =...
trial_gpt4o_1
{ "original_instruction": "Given an n x m grid where each cell is either land or water, represented respectively by the characters 'L' and 'W', a land mass is formed by connecting adjacent lands horizontally or vertically. A player can change any land cell to water in order to minimize the number of distinct land mas...
0.591496
Codeforces_38332
C
[ "find_land_masses", "min_land_masses_after_change", "main" ]
3
[ [ "min_land_masses_after_change", "find_land_masses" ] ]
1
[]
false
[]
false
pytest
true
[]
true
ed4986163e7278f7f50d010769b9f1db0d9c9c70
e04c953bb9239c2e4c5272c0ffd6659c29dcb4e0
v1.0
complete
Codeforces
Codeforces_38114_C
from collections import deque from typing import List, Tuple def max_flow_from_input(n: int, m: int, s: int, t: int, pipes: List[Tuple[int, int, int]]) -> int: """ Determine the maximum flow of electricity from the given power station to the given storage unit. Args: n (int): Total number of nodes (2 ≤ n ≤...
from collections import deque def bfs(C, F, source, sink, parent): n = len(C) visited = [False] * n queue = deque([source]) visited[source] = True while queue: u = queue.popleft() for v in range(n): if not visited[v] and F[u][v] < C[u][v]: # there is remai...
def test_example_1(): input_str = "4 5 1 4\n1 2 1000\n2 4 1000\n1 3 1000\n3 4 1000\n2 3 1\n" assert from_io_string(input_str) == 2000 def test_min_input(): input_str = "2 1 1 2\n1 2 100\n" assert from_io_string(input_str) == 100 def test_no_capacity(): input_str = "3 3 1 3\n1 2 0\n2 3 0\n1 3 0\n" ...
[ { "docstring": null, "function_declaration": "def bfs(C, F, source, sink, parent):", "function_name": "bfs", "parameter_list": "(C, F, source, sink, parent)" }, { "docstring": null, "function_declaration": "def edmonds_karp(n, source, sink, capacity):", "function_name": "edmonds_karp...
[ 0, 0, 0, 0, 0, 1, 0, 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": "from collections import deque, defaultdict\n\ndef bfs_level_graph(capacity, source, sink, parent):\n visited = {source}\n queue = deque([source])\n w...
trial_gpt4o_9
{ "original_instruction": "In a futuristic city, there are several power stations providing electricity and storage units storing the power. The power stations and the storage units are connected by a complex network of pipes. Each pipe connects exactly two power stations or storage units and has a certain capacity i...
0.641672
Codeforces_38114
C
[ "bfs", "edmonds_karp", "max_flow_from_input", "from_io_string" ]
4
[ [ "edmonds_karp", "bfs" ], [ "from_io_string", "max_flow_from_input" ], [ "max_flow_from_input", "edmonds_karp" ] ]
3
[]
false
[]
false
pytest
false
[]
true
b2329fae6d76d93f5c78edfdafdfc4a43d857ad8
37bcdbc0049220af7abd2dd56cdb7b73944df38c
v1.0
complete
Codeforces
Codeforces_39148_C
def minimum_cost_to_connect_cities(n: int, m: int, portals: List[Tuple[int, int, int]]) -> int: """ Determine the minimum cost needed to connect all cities in the kingdom with teleportation portals. :param n: Number of cities :param m: Number of existing portals :param portals: List of tuples, ...
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...
from solution import minimum_cost_to_connect_cities def test_minimum_cost_to_connect_cities(): # Test case 1 assert minimum_cost_to_connect_cities(4, 4, [(1, 2, 3), (2, 3, 1), (3, 4, 4), (1, 4, 5)]) == 8 # Test case 2 assert minimum_cost_to_connect_cities(4, 2, [(1, 2, 3), (3, 4, 4)]) == -1 ...
[ { "docstring": null, "function_declaration": "def find(parent, i):", "function_name": "find", "parameter_list": "(parent, i)" }, { "docstring": null, "function_declaration": "def union(parent, rank, x, y):", "function_name": "union", "parameter_list": "(parent, rank, x, y)" }, ...
[ 0, 1, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def find(parent, i):\n if parent[i] == i:\n return i\n else:\n return find(parent, parent[i])\n\ndef union(parent, rank, x, y):\n xroot...
trial_gpt4o_2
{ "original_instruction": "In a distant galaxy, there is a kingdom consisting of several cities connected by teleportation portals. Each portal has a transportation cost associated with it. The monarch of the kingdom wants to ensure that his subjects can travel between any two cities with minimum cost, so he has deci...
0.651761
Codeforces_39148
C
[ "find", "union", "kruskal", "minimum_cost_to_connect_cities" ]
4
[ [ "kruskal", "find" ], [ "kruskal", "union" ], [ "minimum_cost_to_connect_cities", "kruskal" ], [ "union", "find" ] ]
4
[]
false
[]
false
pytest
true
[]
true
059ed7ca9c88f48b88cc997459cb23c0ede1008a
2cee371a80866a23845909563d628f5733fedf92
v1.0
complete
Codeforces
Codeforces_38931_C
class BSTNode: def __init__(self, key): self.key = key self.left = None self.right = None def insert_bst_node(root, key): """Insert a node with the given key into the BST.""" # Implementation here def calculate_distances_sum(root, current_distance): """Calculate the sum of dist...
class BSTNode: def __init__(self, key): self.key = key self.left = None self.right = None def insert_bst_node(root, key): if root is None: return BSTNode(key) if key < root.key: root.left = insert_bst_node(root.left, key) else: root.right = insert_bst_nod...
from solution import sum_of_distances def test_sum_of_distances_example(): assert sum_of_distances(5, [10, 5, 1, 7, 40]) == 6 def test_sum_of_distances_single_node(): assert sum_of_distances(1, [10]) == 0 def test_sum_of_distances_two_nodes(): assert sum_of_distances(2, [10, 5]) == 1 def test_sum_of_dis...
[]
[ 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": "class BSTNode:\n def __init__(self, key):\n self.key = key\n self.left = None\n self.right = None\n\ndef insert_bst_node(root, key):\n...
trial_gpt4o_0
{ "original_instruction": "Jason, a budding computer scientist, is fascinated by binary search trees (BSTs) and their properties. He recently learned about a unique property of BSTs - the sum of the distances from the root to all other nodes. He wants to write a program that, given a sequence of integers, constructs ...
0.498164
Codeforces_38931
C
[ "insert_bst_node", "calculate_distances_sum", "sum_of_distances" ]
3
[ [ "sum_of_distances", "calculate_distances_sum" ], [ "sum_of_distances", "insert_bst_node" ] ]
2
[]
false
[ "BSTNode" ]
true
pytest
true
[]
true
cc877ae5465a37f50d477cde9181bfa81302f609
5679a72b8e3f0492c5ceba4a3b098f01a7120a57
v1.0
complete
Codeforces
Codeforces_38879_C
from typing import List, Tuple def get_fungus_clusters(n: int, m: int, initial_grid: List[str], changes: List[Tuple[int, int, int]]) -> List[int]: """ Determine the number of unique clusters of fungus for each day's grid configuration. Args: n (int): Number of rows in the grid. m (int): Number of ...
def find_clusters(grid, n, m): def dfs(r, c): stack = [(r, c)] while stack: cr, cc = stack.pop() for dr, dc in [(-1, 0), (1, 0), (0, -1), (0, 1)]: nr, nc = cr + dr, cc + dc if 0 <= nr < n and 0 <= nc < m and grid[nr][nc] == 'X': ...
from solution import get_fungus_clusters def test_single_day_growth(): initial_grid = [ ".....", ".....", ".....", "....." ] changes = [(1, 1, 1)] result = get_fungus_clusters(4, 5, initial_grid, changes) assert result == [1] def test_multiple_days_single_cluster():...
[ { "docstring": null, "function_declaration": "def find_clusters(grid, n, m):", "function_name": "find_clusters", "parameter_list": "(grid, n, m)" }, { "docstring": null, "function_declaration": "def get_fungus_clusters(n, m, initial_grid, changes):", "function_name": "get_fungus_clus...
[ 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 count_clusters(grid):\n \"\"\"\n Count the number of unique clusters of fungus in the grid.\n \"\"\"\n n = len(grid)\n m = len(grid[0])\n ...
trial_gpt4o_1
{ "original_instruction": "A researcher is studying the growth patterns of a peculiar species of fungus. They observe that the fungus grows in a pattern resembling a rectangular grid and takes special interest in the number of unique clusters of fungus over time. Each grid cell can either be empty ('.') or occupied b...
0.54059
Codeforces_38879
C
[ "find_clusters", "get_fungus_clusters" ]
2
[ [ "get_fungus_clusters", "find_clusters" ] ]
1
[]
false
[]
false
pytest
true
[]
true
0e2dfa44c92a4f1e385f7301b0ecd3d265382a1a
26049a7c0b321e549f25ccaa9a5a30b49593f288
v1.0
complete
Codeforces
Codeforces_38188_C
from typing import List, Tuple def compute_prefix_sum(matrix: List[List[int]]) -> List[List[int]]: """Compute the prefix sum matrix for a given matrix.""" n = len(matrix) m = len(matrix[0]) prefix_sum = [[0] * (m + 1) for _ in range(n + 1)] # Fill the prefix sum matrix for i in range(1, n ...
def compute_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] + prefix_sum[i][j-1] - prefix_sum[i-1][j-1] return ...
import pytest from solution import submatrix_sum def test_submatrix_sum_example(): matrix = [ [1, 2, 3], [4, 5, 6], [7, 8, 9] ] queries = [(1, 1, 2, 2), (2, 2, 3, 3)] result = submatrix_sum(matrix, queries) assert result == [12, 28] def test_submatrix_sum_single_element(): ...
[ { "docstring": null, "function_declaration": "def compute_prefix_sum(matrix):", "function_name": "compute_prefix_sum", "parameter_list": "(matrix)" }, { "docstring": null, "function_declaration": "def submatrix_sum(matrix, queries):", "function_name": "submatrix_sum", "parameter_...
[ 0, 0, 1, 1 ]
2
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 prepare_prefix_sum_matrix(matrix):\n n = len(matrix)\n m = len(matrix[0])\n prefix_sum = [[0] * (m + 1) for _ in range(n...
trial_gpt4o_4
{ "original_instruction": "You are given a matrix of size $$$n \\times m$$$ filled with integers, and numerous queries to find the sum of elements in a submatrix. Efficiently compute the sum for each given submatrix.\n\nThe first line of the input contains two integers $$$n$$$ and $$$m$$$ ($$$1 \\leq n, m \\leq 10^3$...
0.569527
Codeforces_38188
C
[ "compute_prefix_sum", "submatrix_sum" ]
2
[ [ "submatrix_sum", "compute_prefix_sum" ] ]
1
[]
false
[]
false
pytest
true
[]
true
68bca0b38ec97be82fbb923be2e2adc8d35d1b53
67127bc058cae25d1242f95d48dae2614dba326a
v1.0
complete
Codeforces
Codeforces_39093_C
def shortest_paths(n: int, m: int, roads: List[Tuple[int, int, int]]) -> List[List[int]]: """ Compute the shortest distance between every pair of villages. Args: n (int): Number of villages. m (int): Number of roads. roads (List[Tuple[int, int, int]]): List of roads as tuples (u, v, w). Returns...
def floyd_warshall(n, m, roads): # Initialize the distance matrix dist = [[float('inf')] * n for _ in range(n)] # Distance from each village to itself is 0 for i in range(n): dist[i][i] = 0 # Initialize distances according to the roads given for u, v, w in roads: dist[u...
from solution import shortest_paths def test_example_case(): n, m = 4, 4 roads = [ (1, 2, 3), (2, 3, 4), (3, 4, 2), (4, 1, 5) ] result = shortest_paths(n, m, roads) expected = [ [0, 3, 7, 5], [3, 0, 4, 6], [7, 4, 0, 2], [5, 6, 2, 0] ...
[ { "docstring": null, "function_declaration": "def floyd_warshall(n, m, roads):", "function_name": "floyd_warshall", "parameter_list": "(n, m, roads)" }, { "docstring": null, "function_declaration": "def shortest_paths(n, m, roads):", "function_name": "shortest_paths", "parameter_...
[ 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 floyd_warshall(n, m, roads):\n # Initialize the distance matrix with infinity\n dist = [[float('inf')] * n for _ in range(n)]\n \n # Distance ...
trial_gpt4o_1
{ "original_instruction": "In a distant land called Yendoria, there are $$$n$$$ villages connected by $$$m$$$ bidirectional roads forming a connected graph. Each road has a certain length. There is a major festival happening, and the king wants to ensure that each village has the least possible travel cost to any oth...
0.747914
Codeforces_39093
C
[ "floyd_warshall", "shortest_paths" ]
2
[ [ "shortest_paths", "floyd_warshall" ] ]
1
[]
false
[]
false
pytest
true
[]
true
1a362f4712cf434e364d7c4bb6eff052754d9c01
feaeedcb91a35ebffdc41e7e784eef5783466b36
v1.0
complete
Codeforces
Codeforces_39300_C
def is_prime(n: int) -> bool: """ Checks if a number n is a prime number. >>> is_prime(2) True >>> is_prime(1) False """ def primes_in_range(low: int, high: int) -> list: """ Returns a list of all prime numbers between low and high (inclusive). >>> primes_in_range(10, 30) ...
def is_prime(n): """ Checks if a number n is a prime number. """ if n <= 1: return False if n <= 3: return True if n % 2 == 0 or n % 3 == 0: return False i = 5 while i * i <= n: if n % i == 0 or n % (i + 2) == 0: return False i += 6 ...
from solution import is_prime, primes_in_range, display_primes import io import sys def test_is_prime(): assert is_prime(2) == True assert is_prime(3) == True assert is_prime(5) == True assert is_prime(4) == False assert is_prime(1) == False assert is_prime(0) == False def test_primes_in_r...
[ { "docstring": "Checks if a number n is a prime number.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Returns a list of all prime numbers between low and high (inclusive).", "function_declaration": "def primes_in_ran...
[ 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 is_prime(num):\n \"\"\"\n Determines if a given number is a prime number.\n \"\"\"\n if num <= 1:\n return False\n if num <= 3:\n ...
trial_gpt4o_2
{ "original_instruction": "With the recent advancement in the AI industry, you decided to showcase your knowledge of prime numbers by developing a new algorithm to generate prime numbers in a given range. To help visualize the capability of your algorithm, you've decided to create a simple program to find all prime n...
0.761095
Codeforces_39300
C
[ "is_prime", "primes_in_range", "display_primes" ]
3
[ [ "display_primes", "primes_in_range" ], [ "primes_in_range", "is_prime" ] ]
2
[]
false
[]
false
pytest
true
[]
true
607467cfb39b37b42d51ff1a06f17f952e7e932a
4b36ffa717faf52dd65adfb0e2d767b6427cb4d9
v1.0
complete
Codeforces
Codeforces_38987_C
def largest_contiguous_positive_submatrix(matrix: List[List[int]]) -> int: """ Determine the largest contiguous submatrix containing only positive numbers and calculate its area. >>> matrix1 = [ ... [1, 2, 3, -1, 5], ... [-2, 3, 4, -5, 6], ... [7, 8, 9, 1, -4], ... [5, 4, -2, 3, ...
def largest_contiguous_positive_submatrix(matrix): n = len(matrix) m = len(matrix[0]) # Helper function to find maximum rectangle area in a histogram def max_histogram_area(histogram): stack = [] max_area = 0 index = 0 while index < len(histogram): ...
def test_largest_contiguous_positive_submatrix(): matrix1 = [ [1, 2, 3, -1, 5], [-2, 3, 4, -5, 6], [7, 8, 9, 1, -4], [5, 4, -2, 3, -6] ] assert solve(matrix1) == 6 matrix2 = [ [1, 2, -3, 4], [5, 6, 7, 8], [9, 10, 11, 12] ] assert solve(mat...
[ { "docstring": null, "function_declaration": "def largest_contiguous_positive_submatrix(matrix):", "function_name": "largest_contiguous_positive_submatrix", "parameter_list": "(matrix)" }, { "docstring": null, "function_declaration": "def solve(matrix):", "function_name": "solve", ...
[ 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 largest_contiguous_positive_submatrix(matrix):\n n = len(matrix)\n m = len(matrix[0])\n \n # Helper function to find maximum rectangle area in...
trial_gpt4o_0
{ "original_instruction": "David is working on a data analysis task and has a matrix of integers. He wants to determine the largest contiguous submatrix (a submatrix formed by selecting a contiguous range of rows and columns) that contains only positive numbers. The goal is to calculate the area of this submatrix, de...
0.602956
Codeforces_38987
C
[ "largest_contiguous_positive_submatrix", "solve" ]
2
[ [ "solve", "largest_contiguous_positive_submatrix" ] ]
1
[]
false
[]
false
pytest
false
[]
true
bfbaa89a6d952525e20915bda11f3d5639e53efb
e071c258ac9da21d5a32b9a1291235f4f8f36b44
v1.0
complete
Codeforces
Codeforces_38645_C
def preprocess_matrix(matrix, n, m): """ Preprocess the matrix to create a prefix sum array for efficient query handling. >>> preprocess_matrix([[1, 2, 3], [4, 5, 6], [7, 8, 9]], 3, 3) [[0, 0, 0, 0], [0, 1, 3, 6], [0, 5, 12, 21], [0, 12, 27, 45]] """ def query_sum(prefix_sum, x1, y1, x2, y2): ...
def preprocess_matrix(matrix, 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] = matrix[i-1][j-1] + prefix_sum[i][j-1] + prefix_sum[i-1][j] - prefix_sum[i-1][j-1] return prefix_sum def query_sum(prefix_sum, x1...
def test_preprocess_matrix(): matrix = [ [1, 2, 3], [4, 5, 6], [7, 8, 9] ] expected = [ [0, 0, 0, 0], [0, 1, 3, 6], [0, 5, 12, 21], [0, 12, 27, 45] ] assert preprocess_matrix(matrix, 3, 3) == expected def test_query_sum(): prefix_sum = [ ...
[ { "docstring": null, "function_declaration": "def preprocess_matrix(matrix, n, m):", "function_name": "preprocess_matrix", "parameter_list": "(matrix, n, m)" }, { "docstring": null, "function_declaration": "def query_sum(prefix_sum, x1, y1, x2, y2):", "function_name": "query_sum", ...
[ 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 n = len(matrix)\n m = len(matrix[0])\n \n prefix_sum = [[0] * (m + 1) for _ in range(n + 1)]\n \n for i in ...
trial_gpt4o_2
{ "original_instruction": "You are given a matrix of size `n x m` filled with integers. You need to perform multiple queries on this matrix. Each query is described by two pairs of coordinates `(x1, y1)` and `(x2, y2)` which represent the top-left and bottom-right corners of a submatrix. For each query, you need to f...
0.555218
Codeforces_38645
C
[ "preprocess_matrix", "query_sum", "matrix_queries" ]
3
[ [ "matrix_queries", "preprocess_matrix" ], [ "matrix_queries", "query_sum" ] ]
2
[]
false
[]
false
pytest
false
[]
true
d13193e36dfccaee9d4d017954fada01d39918d9
92227924a3ee4530f8a9f92cba9746a15f2c054b
v1.0
complete
Codeforces
Codeforces_39181_C
from typing import List def create_grid(R: int, C: int) -> List[List[int]]: """Creates a grid with specified rows and columns filled with zero. >>> create_grid(3, 3) [[0, 0, 0], [0, 0, 0], [0, 0, 0]] """ pass def add_value(grid: List[List[int]], r1: int, c1: int, r2: int, c2: int, V: int) -> None:...
def create_grid(R, C): """Creates a grid with specified rows and columns filled with zero.""" return [[0] * C for _ in range(R)] def add_value(grid, r1, c1, r2, c2, V): """Adds a given value V to all elements in a specific rectangular subgrid.""" for r in range(r1 - 1, r2): for c in range(c1 - ...
from solution import create_grid, add_value, set_value, get_value, process_queries def test_create_grid(): assert create_grid(3, 3) == [[0, 0, 0], [0, 0, 0], [0, 0, 0]] def test_add_value(): grid = create_grid(3, 3) add_value(grid, 1, 1, 2, 2, 5) assert grid == [[5, 5, 0], [5, 5, 0], [0, 0, 0]] def t...
[ { "docstring": "Creates a grid with specified rows and columns filled with zero.", "function_declaration": "def create_grid(R, C):", "function_name": "create_grid", "parameter_list": "(R, C)" }, { "docstring": "Adds a given value V to all elements in a specific rectangular subgrid.", "fu...
[ 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 create_grid(R, C):\n \"\"\"Creates a grid with specified rows and columns filled with zero.\"\"\"\n return [[0] * C for _ in range(R)]\n\ndef add_va...
trial_gpt4o_0
{ "original_instruction": "You are given a rectangular grid with R rows and C columns where each cell of the grid initially contains a value 0. Your task is to process a series of Q operations on this grid. Each operation can be one of the following types:\n\n1. **Add Value**: Add a given value V to all elements in a...
0.566077
Codeforces_39181
C
[ "create_grid", "add_value", "set_value", "get_value", "process_queries" ]
5
[ [ "process_queries", "add_value" ], [ "process_queries", "create_grid" ], [ "process_queries", "get_value" ], [ "process_queries", "set_value" ] ]
4
[ "process_queries" ]
false
[]
false
pytest
true
[]
true
e71969a4ef767cff88c5e523177bac8e89231609
36b33b871a032f8c586e6b0e5baac3d18e5a35a7
v1.0
complete
Codeforces
Codeforces_39501_C
from typing import List def is_prime(num: int) -> bool: """ Determines if a number is prime. >>> is_prime(2) True >>> is_prime(4) False """ pass def smallest_prime_gte(n: int) -> int: """ Finds the smallest prime number greater than or equal to n. >>> smallest_prime_gte(10)...
import math def is_prime(num): """ Determines if a number is prime. """ if num <= 1: return False if num == 2: return True if num % 2 == 0: return False for i in range(3, int(math.sqrt(num)) + 1, 2): if num % i == 0: return False return True ...
from solution import is_prime, smallest_prime_gte, process_test_cases def test_is_prime(): assert is_prime(2) == True assert is_prime(3) == True assert is_prime(4) == False assert is_prime(17) == True assert is_prime(18) == False assert is_prime(19) == True assert is_prime(1) == False a...
[ { "docstring": "Determines if a number is prime.", "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": "Finds the smallest prime number greater than or equal to n.", "function_declaration": "def smallest_prime_gte(n):", ...
[ 1, 1 ]
2
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(num):\n \"\"\"Return True if num is a prime number, else False.\"\"\"\n if num <= 1:\n return False\n if num <= 3:\n retur...
trial_gpt4o_1
{ "original_instruction": "Ravi is a big fan of prime numbers. He loves to play with them and has come up with an interesting problem. A prime number is a natural number greater than 1 that is not a product of two smaller natural numbers.\n\nGiven an integer $$$n$$$, Ravi wants to find the smallest prime number that ...
0.727452
Codeforces_39501
C
[ "is_prime", "smallest_prime_gte", "process_test_cases" ]
3
[ [ "process_test_cases", "smallest_prime_gte" ], [ "smallest_prime_gte", "is_prime" ] ]
2
[ "process_test_cases" ]
false
[]
false
pytest
true
[]
true
6d2c869755370ad0bcaa86c7a6f571c5f9e1d9a4
e0e1871d88794c638903be9aea7e4e9f944e8ee4
v1.0
complete
Codeforces
Codeforces_39116_C
def maximum_profit(n: int, m: int, min_routes: int, edges: List[Tuple[int, int, int]]) -> Union[int, str]: """ Determines the maximum possible profit that can be obtained while satisfying the connectivity and minimum routes constraints, or determines that it is impossible to meet the constraints. ...
def find(parent, i): if parent[i] == i: return i else: parent[i] = find(parent, parent[i]) return parent[i] def union(parent, rank, x, y): rootX = find(parent, x) rootY = find(parent, y) if rootX != rootY: if rank[rootX] > rank[rootY]: parent[rootY] ...
def test_maximum_profit(): assert maximum_profit(4, 5, 3, [(1, 2, 10), (2, 3, 20), (3, 4, 30), (4, 1, 40), (2, 4, -50)]) == 90 assert maximum_profit(4, 5, 4, [(1, 2, 10), (2, 3, 20), (3, 4, 30), (4, 1, 40), (2, 4, -50)]) == 100 assert maximum_profit(3, 3, 3, [(1, 2, 10), (2, 3, 20), (1, 3, 5)]) == 35 as...
[ { "docstring": null, "function_declaration": "def find(parent, i):", "function_name": "find", "parameter_list": "(parent, i)" }, { "docstring": null, "function_declaration": "def union(parent, rank, x, y):", "function_name": "union", "parameter_list": "(parent, rank, x, y)" }, ...
[ 0, 0, 0, 0, 0, 0, 0, 0, 1 ]
1
hard
0.111
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "import heapq\n\ndef find_max_profit(n, m, min_routes, routes):\n parent = list(range(n))\n rank = [0] * n\n def find(u):\n if u != parent[u]:\...
trial_gpt4o_9
{ "original_instruction": "You have been hired by a transportation company to design a scheduling algorithm for their bus routes. The company operates buses on a large number of routes, each connecting two different cities. Every bus route needs to be scheduled exactly once per day. Some bus routes are more profitabl...
0.663793
Codeforces_39116
C
[ "find", "union", "maximum_profit", "read_input" ]
4
[ [ "maximum_profit", "find" ], [ "maximum_profit", "union" ], [ "union", "find" ] ]
3
[ "read_input" ]
false
[]
false
pytest
true
[]
true
9cc99b322a0742b287c9c25ac01da80b608b5957
3657154ff9937ae85a30dcd01692849f63242929
v1.0
complete
Codeforces
Codeforces_39281_C
def minimum_new_roads(n: int, m: int, altitudes: List[int], roads: List[Tuple[int, int]]) -> int: """ Determine the minimum number of new roads that need to be built so that all cities can be connected under the condition that directly connected cities have different altitudes. :param n: Number of citi...
from collections import defaultdict, deque def find_root(city, parent): if parent[city] != city: parent[city] = find_root(parent[city], parent) return parent[city] def union(city1, city2, parent, rank): root1 = find_root(city1, parent) root2 = find_root(city2, parent) if root1 != root...
import pytest from solution import minimum_new_roads def test_example_1(): n = 4 m = 2 altitudes = [1, 2, 3, 4] roads = [(1, 2), (3, 4)] assert minimum_new_roads(n, m, altitudes, roads) == 1 def test_example_2(): n = 3 m = 0 altitudes = [5, 5, 5] roads = [] assert minimum_new_r...
[ { "docstring": null, "function_declaration": "def find_root(city, parent):", "function_name": "find_root", "parameter_list": "(city, parent)" }, { "docstring": null, "function_declaration": "def union(city1, city2, parent, rank):", "function_name": "union", "parameter_list": "(ci...
[ 0, 0, 0, 0, 0, 0, 0, 1, 0, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def min_new_roads_needed(n, m, altitudes, roads):\n from collections import defaultdict, deque\n\n def bfs_components():\n visited = [False] * n\...
trial_gpt4o_7
{ "original_instruction": "The roads in the kingdom of Casteland are quite peculiar. Casteland has n cities labeled from 1 to n, and certain bidirectional roads connect specific pairs of cities. Each city can be described as having a certain altitude. The kingdom is planning to build a new road system to connect all ...
0.680078
Codeforces_39281
C
[ "find_root", "union", "minimum_new_roads" ]
3
[ [ "minimum_new_roads", "find_root" ], [ "minimum_new_roads", "union" ], [ "union", "find_root" ] ]
3
[]
false
[]
false
pytest
true
[]
true
9906f0c07caa79f5d9ffc003ed48cbc570cdf99f
60972a6535858550788eaf3fdc15c43bcd62dd26
v1.0
complete
Codeforces
Codeforces_39557_C
def max_overlap(intervals): """ This function takes a list of intervals and returns the maximum number of overlapping intervals. >>> max_overlap([(1, 3), (2, 5), (4, 6), (7, 9), (8, 10)]) == 2 >>> max_overlap([(1, 2), (3, 4), (5, 6)]) == 1 >>> max_overlap([(1, 10), (2, 5), (1, 7)]) == 3 >>> max...
def max_overlap(intervals): """ This function takes a list of intervals and returns the maximum number of overlapping intervals. """ events = [] for interval in intervals: l, r = interval events.append((l, 1)) # start of interval events.append((r + 1, -1)) # end of interval...
from solution import process_intervals def test_max_overlap_example(): n = 5 interval_list = [(1, 3), (2, 5), (4, 6), (7, 9), (8, 10)] assert process_intervals(n, interval_list) == 2 def test_max_overlap_no_overlap(): n = 3 interval_list = [(1, 2), (3, 4), (5, 6)] assert process_intervals(n, i...
[ { "docstring": "This function takes a list of intervals and returns the maximum number of overlapping intervals.", "function_declaration": "def max_overlap(intervals):", "function_name": "max_overlap", "parameter_list": "(intervals)" }, { "docstring": "This function processes the input for i...
[ 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_overlap(intervals):\n \"\"\"\n This function takes a list of intervals and returns the maximum number of overlapping intervals.\n \"\"\"\n ...
trial_gpt4o_0
{ "original_instruction": "You are given a set of $$$n$$$ intervals on a number line, where each interval is represented by a pair of integers $$$[l_i, r_i]$$$ (1 ≤ $$$i$$$ ≤ n). Two intervals $$$[l_i, r_i]$$$ and $$$[l_j, r_j]$$$ are considered overlapping if they share at least one common point, i.e., there exists ...
0.697756
Codeforces_39557
C
[ "max_overlap", "process_intervals" ]
2
[ [ "process_intervals", "max_overlap" ] ]
1
[]
false
[]
false
pytest
true
[]
true
0c0b883ebcec966e7464f7691004fb18bd3a90a1
ddf8a7398d15e25217cfc003cda893abb5e88037
v1.0
complete
Codeforces
Codeforces_39604_C
def can_split_prime_sum(nums): """ Determines if it's possible to split the array into two non-empty subsets such that their prime sums are equal. >>> can_split_prime_sum([1, 4, 6, 8, 10]) "NO" >>> can_split_prime_sum([1, 2, 3, 4, 5, 6]) "YES" >>> can_split_prime_sum([2, 2, 3, 3]) "...
def is_prime(num): """ Helper function to check if a number is prime. """ if num <= 1: return False for i in range(2, int(num**0.5) + 1): if num % i == 0: return False return True def can_split_prime_sum(nums): """ Determines if it's possible to split the arr...
from solution import can_split_prime_sum def test_no_primes(): assert can_split_prime_sum([1, 4, 6, 8, 10]) == "NO" def test_primes_equal_split(): assert can_split_prime_sum([1, 2, 3, 4, 5, 6]) == "YES" assert can_split_prime_sum([2, 2, 3, 3]) == "YES" def test_primes_non_equal_split(): assert ca...
[ { "docstring": "Helper function to check if a number is prime.", "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": "Determines if it's possible to split the array into two non-empty subsets\nsuch that their prime sums are e...
[ 0, 1, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(num):\n \"\"\"\n Returns True if num is a prime number, else False.\n \"\"\"\n if num <= 1:\n return False\n if num == 2:\n...
trial_gpt4o_1
{ "original_instruction": "Liza loves collecting prime numbers. Recently she has started wondering about prime sums. She came up with a problem and is eager to know the answer.\n\nGiven an array of positive integers, can you determine if it is possible to split the array into two non-empty subsets such that the sum o...
0.634927
Codeforces_39604
C
[ "is_prime", "can_split_prime_sum" ]
2
[ [ "can_split_prime_sum", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
9978dcf167b72bcc6b8886d3514c7c98cfab9622
d507dc9317ad402713bf212ed6e1fc36e68560d9
v1.0
complete
Codeforces
Codeforces_39487_C
from collections import deque from typing import List, Tuple def find_tree_center(n: int, edges: List[Tuple[int, int]]) -> int: """ Given a maze represented by an undirected tree, find the center node of the tree. Args: n (int): The number of nodes in the tree. edges (List[Tuple[int, int]]): The edges...
from collections import deque def find_tree_diameter(n, edges): if n == 1: return [1] adj = [[] for _ in range(n+1)] for u, v in edges: adj[u].append(v) adj[v].append(u) def bfs(start): dist = [-1] * (n + 1) dist[start] = 0 queue = deque([start]...
def test_find_tree_center(): # Test on provided examples assert find_tree_center(4, [(1, 2), (1, 3), (2, 4)]) in {1} assert find_tree_center(5, [(1, 2), (1, 3), (3, 4), (4, 5)]) in {3} # Additional tests assert find_tree_center(1, []) == 1 assert find_tree_center(2, [(1, 2)]) in {1, 2} ...
[ { "docstring": null, "function_declaration": "def find_tree_diameter(n, edges):", "function_name": "find_tree_diameter", "parameter_list": "(n, edges)" }, { "docstring": null, "function_declaration": "def find_tree_center(n, edges):", "function_name": "find_tree_center", "paramet...
[ 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 find_tree_diameter(n, edges):\n if n == 1:\n return [1]\n \n adj = [[] for _ in range(n+1)]\n for u, v...
trial_gpt4o_0
{ "original_instruction": "Dominic has recently taken up the hobby of hedge maze design. He has decided to create mazes that have a unique feature: exactly one path exists between any two points in the maze. Essentially, each maze is a tree. Dominic wants to ensure that his mazes are well-designed and have certain pr...
0.53701
Codeforces_39487
C
[ "find_tree_diameter", "find_tree_center" ]
2
[ [ "find_tree_center", "find_tree_diameter" ] ]
1
[]
false
[]
false
pytest
false
[]
true
e44025c9ff59c7afb8a2b28b4d4bca3c6bd094d7
fb8a79d6413465e09869e4a8a852e8ab7775f5fb
v1.0
complete
Codeforces
Codeforces_39455_C
def max_rectangle_area(grid): """ Determines the maximum area of a rectangular sub-grid that contains only open cells ('.'). Args: grid : List[List[str]] : A 2D list representing the grid. Returns: int : Maximum area of a rectangular sub-grid with only open cells. Example: >>> max_rec...
def max_rectangle_area(grid): n = len(grid) m = len(grid[0]) heights = [0] * m max_area = 0 for row in grid: for col in range(m): if row[col] == '.': heights[col] += 1 else: heights[col] = 0 stack = [] for i in range(m...
from solution import main def test_case_1(): input_string = "2\n3 4\n.##.\n..#.\n....\n5 5\n.....\n.....\n..#..\n.....\n....." expected_output = "4\n10" assert main(input_string) == expected_output def test_case_empty_grid(): input_string = "1\n3 3\n###\n###\n###" expected_output = "0" assert ...
[ { "docstring": null, "function_declaration": "def max_rectangle_area(grid):", "function_name": "max_rectangle_area", "parameter_list": "(grid)" }, { "docstring": null, "function_declaration": "def solve(test_cases):", "function_name": "solve", "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": "def max_rect_area(grid, n, m):\n \"\"\"\n Helper function to calculate the maximum area of a rectangle of open cells in a grid.\n \"\"\"\n # Creat...
trial_gpt4o_2
{ "original_instruction": "You are given a grid with `n` rows and `m` columns, where each cell either contains a `.` (representing an open cell) or a `#` (representing an obstacle). Your task is to determine the maximum area of a rectangular sub-grid that contains only open cells (`.`).\n\nThe input data consists of ...
0.739024
Codeforces_39455
C
[ "max_rectangle_area", "solve", "parse_input", "main" ]
4
[ [ "solve", "max_rectangle_area" ] ]
1
[ "parse_input" ]
false
[]
false
pytest
true
[]
true
7552d930abbb2c0903a5d4c7cf4a7fc124ea7819
23b9f85a2500afc9ac485cdf3ba72413f031e8eb
v1.0
complete
Codeforces
Codeforces_39540_C
def max_fun(n: int, m: int, activities: List[Tuple[int, int, int]], k: int, incompatibilities: List[Tuple[int, int]]) -> int: """ Find the maximum total fun that can be achieved during the event. n (int): Total duration of the event in minutes. m (int): Number of available activities. activities (L...
def max_fun(n, m, activities, k, incompatibles): def can_schedule(activity, schedule): for sch in schedule: if incompatibles.get((min(activity, sch), max(activity, sch)), False): return False return True def dfs(idx, current_fun, schedule): nonlocal max_f...
from solution import solution def test_example_case(): n = 10 m = 3 activities = [ (1, 3, 5), (4, 6, 7), (7, 10, 4) ] k = 1 incompatibilities = [(1, 3)] assert solution(n, m, activities, k, incompatibilities) == 12 def test_no_incompatibilities(): n = 10 m =...
[ { "docstring": null, "function_declaration": "def max_fun(n, m, activities, k, incompatibles):", "function_name": "max_fun", "parameter_list": "(n, m, activities, k, incompatibles)" }, { "docstring": null, "function_declaration": "def solution(n, m, activities, k, incompatibilities):", ...
[ 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_fun(n, m, activities, k, incompatibles):\n def can_schedule(activity, schedule):\n for sch in schedule:\n if incompatibles.get((m...
trial_gpt4o_0
{ "original_instruction": "Jane is organizing a charity event and she has several booths offering different activities. The event lasts for n minutes and each activity takes a certain duration to complete and provides a certain amount of fun. Jane wants to maximize the total amount of fun that visitors can have by pa...
0.595266
Codeforces_39540
C
[ "max_fun", "solution" ]
2
[ [ "solution", "max_fun" ] ]
1
[]
false
[]
false
pytest
true
[]
true
cb8527d8767a5a70da334e227a27f82f6a2d290e
e4a23a23947d6a8c10049d1ad19f2a9bcf876a17
v1.0
complete
Codeforces
Codeforces_39283_C
import collections from typing import List, Tuple def preprocess_lca(n: int, edges: List[Tuple[int, int]]) -> Tuple[List[List[int]], List[int], int]: """Preprocess the tree to prepare for LCA queries. Args: - n: The number of nodes in the tree. - edges: A list of edges representing the tree. R...
import sys import collections def preprocess_lca(n, edges): LOG = 17 # As n <= 10^5, log2(10^5) is less than 17 # Create adjacency list for the tree tree = collections.defaultdict(list) for u, v in edges: tree[u].append(v) tree[v].append(u) # Initialize parent and depth array...
def test_example_case(): input_data = '''7 1 2 1 3 2 4 2 5 3 6 3 7 4 4 5 4 6 3 4 2 7''' expected_output = [2, 1, 1, 1] assert lca_queries(input_data) == expected_output def test_single_edge(): input_data = '''2 1 2 1 1 2''' expected_output = [1] assert lca_queries(input_data) == expected_output...
[ { "docstring": null, "function_declaration": "def preprocess_lca(n, edges):", "function_name": "preprocess_lca", "parameter_list": "(n, edges)" }, { "docstring": null, "function_declaration": "def lca(u, v, parent, depth, LOG):", "function_name": "lca", "parameter_list": "(u, v, ...
[ 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 defaultdict, deque\n\nclass BinaryTreeLCA:\n def __init__(self, n, edges):\n self.n = n\n self.edges = edges\n ...
trial_gpt4o_2
{ "original_instruction": "Alice and Bob are playing a friendly game on a binary tree. The tree has `n` nodes, numbered from 1 to `n`, rooted at node 1. Alice randomly selects a node `a`, and Bob randomly selects a different node `b`. They start from their respective nodes and try to meet at a common node by only mov...
0.573624
Codeforces_39283
C
[ "preprocess_lca", "lca", "solve_lca", "parse_input", "lca_queries" ]
5
[ [ "lca_queries", "parse_input" ], [ "lca_queries", "solve_lca" ], [ "solve_lca", "lca" ], [ "solve_lca", "preprocess_lca" ] ]
4
[ "parse_input" ]
false
[]
false
pytest
false
[]
true
4dd39ee97aedf15402b584f12c050a6c2ed976b5
e2ceec80a09f473e6a1fb072020c5d87ccc924b5
v1.0
complete
Codeforces
Codeforces_39465_C
import heapq from typing import List, Tuple def find_max_cost_removal(input_str: str) -> int: """ Determine the maximum travel cost of a single road that can be removed while keeping the kingdom connected. The input is a string containing: The first line: two integers N and M (2 ≤ N ≤ 1000, N-1 ≤ M ≤ ...
import heapq # Prim's Algorithm to find Minimum Spanning Tree Cost and Edges def prim_mst(graph, n): visited = [False] * (n + 1) min_heap = [(0, 1, -1)] # (cost, to_node, from_node) mst_cost = 0 mst_edges = [] while min_heap: cost, to_node, from_node = heapq.heappop(min_heap) ...
from solution import find_max_cost_removal def test_case_1(): input_str = "5 6\n1 2 3\n1 3 4\n2 3 1\n2 4 2\n3 5 5\n4 5 3\n" assert find_max_cost_removal(input_str) == 3 def test_case_2(): input_str = "4 5\n1 2 2\n1 3 3\n1 4 10\n2 3 1\n3 4 4\n" assert find_max_cost_removal(input_str) == 4 def test_cas...
[ { "docstring": null, "function_declaration": "def prim_mst(graph, n):", "function_name": "prim_mst", "parameter_list": "(graph, n)" }, { "docstring": null, "function_declaration": "def max_cost_removal(N, M, roads):", "function_name": "max_cost_removal", "parameter_list": "(N, M,...
[ 0, 0, 0, 0, 0, 0, 1, 0, 0, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005484_sanitized_prepared0_results_combined.jsonl", "solution_code": "def find_max_cost_road_to_remove(N, M, roads):\n \"\"\"\n Returns the maximum travel cost of a single road that can be removed while keeping the kingdom...
trial_gpt4o_6
{ "original_instruction": "There is a kingdom with N cities connected by M bidirectional roads. Each road has a certain travel cost associated with it. The kingdom has a peculiar rule: each city must be connected to every other city directly or indirectly. You are the royal cartographer tasked with ensuring the kingd...
0.596594
Codeforces_39465
C
[ "prim_mst", "max_cost_removal", "parse_input", "find_max_cost_removal" ]
4
[ [ "find_max_cost_removal", "max_cost_removal" ], [ "find_max_cost_removal", "parse_input" ], [ "max_cost_removal", "prim_mst" ] ]
3
[ "parse_input" ]
false
[]
false
pytest
true
[]
true
961f0fa7184d2a1b20fbf1e2e63a961db6450843
74c7186b65347c36533296b0d84f2f8f8d582bee