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_9755_C | def minimum_toll(n: int, m: int, k: int, edges: List[Tuple[int, int, int]]) -> int:
"""
Determine the minimum sum of tolls of exactly k roads forming a connected subgraph.
Args:
n (int): Number of intersections.
m (int): Number of roads.
k (int): Number of roads to select.
edges (List[T... | def find(parent, i):
if parent[i] == i:
return i
else:
parent[i] = find(parent, parent[i])
return parent[i]
def union(parent, rank, x, y):
root_x = find(parent, x)
root_y = find(parent, y)
if root_x != root_y:
if rank[root_x] < rank[root_y]:
parent[root_x... | def test_example_case():
n = 6
m = 9
k = 3
edges = [(1, 2, 5), (1, 3, 3), (2, 3, 6), (2, 4, 2), (3, 4, 4), (3, 5, 8),
(4, 5, 7), (4, 6, 1), (5, 6, 9)]
assert solution(n, m, k, edges) == 6
def test_two_intersections_one_needed():
n = 2
m = 1
k = 1
edges = [(1, 2, 10)]
... | [
{
"docstring": null,
"function_declaration": "def find(parent, i):",
"function_name": "find",
"parameter_list": "(parent, i)"
},
{
"docstring": null,
"function_declaration": "def union(parent, rank, x, y):",
"function_name": "union",
"parameter_list": "(parent, rank, x, y)"
},
... | [
0,
0,
0,
0,
0,
1,
0,
0,
0
] | 1 | hard | 0.111 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def find(parent, x):\n if parent[x] == x:\n return x\n else:\n parent[x] = find(parent, parent[x])\n return parent[x]\n\ndef union(... | trial_gpt4o_5 | {
"original_instruction": "A city contains $$$n$$$ intersections and between some of them, there are bidirectional roads. It is possible to travel between any two intersections by going through one or more roads. Each road has a toll associated with it. A police officer wants to select exactly $$$k$$$ roads such that... | 0.659233 | Codeforces_9755 | C | [
"find",
"union",
"minimum_toll",
"solution"
] | 4 | [
[
"minimum_toll",
"find"
],
[
"minimum_toll",
"union"
],
[
"solution",
"minimum_toll"
],
[
"union",
"find"
]
] | 4 | [] | false | [] | false | pytest | false | [] | true | c527ffe659f20376594a980623cf4faf9deab195 | 11630faf2f580008f9bee1bb673b7e492ec8c96b | |||
v1.0 | complete | Codeforces | Codeforces_9361_C | from typing import List, Tuple
def preprocess(grid: List[List[int]], n: int, m: int) -> List[List[int]]:
"""Preprocess the grid to create a prefix sum array.
Args:
grid: 2D list of integers representing the grid.
n: Number of rows in the grid.
m: Number of columns in the grid.
Returns:
... | def preprocess(grid, n, m):
prefix_sum = [[0] * (m + 1) for _ in range(n + 1)]
for i in range(1, n + 1):
for j in range(1, m + 1):
prefix_sum[i][j] = (grid[i-1][j-1] +
prefix_sum[i-1][j] +
prefix_sum[i][j-1] -
... | from solution import preprocess, query_sum, solve
def test_preprocess():
grid = [
[1, 2, 3],
[4, 5, 6],
[7, 8, 9]
]
expected_prefix_sum = [
[0, 0, 0, 0],
[0, 1, 3, 6],
[0, 5, 12, 21],
[0, 12, 27, 45]
]
assert preprocess(grid, 3, 3) == expected... | [
{
"docstring": null,
"function_declaration": "def preprocess(grid, n, m):",
"function_name": "preprocess",
"parameter_list": "(grid, n, m)"
},
{
"docstring": null,
"function_declaration": "def query_sum(prefix_sum, x1, y1, x2, y2):",
"function_name": "query_sum",
"parameter_list"... | [
1,
1,
1,
1,
1,
1,
1,
1
] | 8 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def preprocess_grid(grid):\n \"\"\"\n Preprocess the grid using prefix sums to allow O(1) sum queries.\n \"\"\"\n n, m = len(grid), len(grid[0])\n... | trial_gpt4o_9 | {
"original_instruction": "You are given a rectangular grid of size $$$n \\times m$$$ filled with integers, and a list of queries. Each query asks for the sum of the integers within a specific subrectangle of the grid. \n\nTo solve the problem, you need to preprocess the grid to answer each query efficiently.\n\nThe ... | 0.574258 | Codeforces_9361 | C | [
"preprocess",
"query_sum",
"solve"
] | 3 | [
[
"solve",
"preprocess"
],
[
"solve",
"query_sum"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 750ede15dcb8f8ac7932457919fc8dcf0587e4ed | 715461c105c404228de1f410fdcd2aeb96cbce3d | |||
v1.0 | complete | Codeforces | Codeforces_9958_C | def is_power_of_two(x: int) -> bool:
"""
Helper function that checks if a number is a power of two.
>>> is_power_of_two(1) True
>>> is_power_of_two(2) True
>>> is_power_of_two(3) False
>>> is_power_of_two(4) True
"""
def longest_subsequence_power_of_two(arr: List[int]) -> int:
"""
... | def is_power_of_two(x):
"""
Helper function that checks if a number is a power of two.
"""
return (x != 0) and ((x & (x - 1)) == 0)
def longest_subsequence_power_of_two(arr):
"""
Returns the length of the longest subsequence consisting only of elements which are powers of two.
"""
power... | from solution import is_power_of_two, longest_subsequence_power_of_two
def test_is_power_of_two():
assert is_power_of_two(1) == True
assert is_power_of_two(2) == True
assert is_power_of_two(3) == False
assert is_power_of_two(4) == True
assert is_power_of_two(5) == False
assert is_power_of_two(8... | [
{
"docstring": "Helper function that checks if a number is a power of two.",
"function_declaration": "def is_power_of_two(x):",
"function_name": "is_power_of_two",
"parameter_list": "(x)"
},
{
"docstring": "Returns the length of the longest subsequence consisting only of elements which are p... | [
1,
0,
0,
0,
1,
1,
1,
1,
1,
1
] | 7 | easy | 0.7 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def longest_power_of_two_subsequence_length(n, sequence):\n \"\"\"\n Returns the length of the longest subsequence consisting of elements that are power... | trial_gpt4o_9 | {
"original_instruction": "You are given a sequence of integers which may or may not contain duplicates. Your task is to find the length of the longest subsequence that can be obtained by deleting some (possibly zero) elements and in which every element is a power of two (i.e., elements that are 1, 2, 4, 8, 16, ...).... | 0.639921 | Codeforces_9958 | C | [
"is_power_of_two",
"longest_subsequence_power_of_two"
] | 2 | [
[
"longest_subsequence_power_of_two",
"is_power_of_two"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 0cf254b2a46b85a06c9f1b86dc854f0746b901df | 74d942c76cedefc7312ca1ee039c36c804033586 | |||
v1.0 | complete | Codeforces | Codeforces_9832_C | def compute_prefix_sums(arr):
"""
Computes and returns the prefix sums array for arr.
>>> compute_prefix_sums([1, 2, 3, 4, 5]) == [0, 1, 3, 6, 10, 15]
>>> compute_prefix_sums([2, 4, 6, 8]) == [0, 2, 6, 12, 20]
>>> compute_prefix_sums([5, 5, 5, 5]) == [0, 5, 10, 15, 20]
"""
def range_sum(pre... | def compute_prefix_sums(arr):
"""
Computes and returns the prefix sums array for arr.
"""
prefix_sums = [0] * (len(arr) + 1)
for i in range(len(arr)):
prefix_sums[i+1] = prefix_sums[i] + arr[i]
return prefix_sums
def range_sum(prefix_sums, l, r):
"""
Returns the range sum from i... | from solution import compute_prefix_sums, range_sum, process_queries
def test_compute_prefix_sums():
assert compute_prefix_sums([1, 2, 3, 4, 5]) == [0, 1, 3, 6, 10, 15]
assert compute_prefix_sums([2, 4, 6, 8]) == [0, 2, 6, 12, 20]
assert compute_prefix_sums([5, 5, 5, 5]) == [0, 5, 10, 15, 20]
def test_ran... | [
{
"docstring": "Computes and returns the prefix sums array for arr.",
"function_declaration": "def compute_prefix_sums(arr):",
"function_name": "compute_prefix_sums",
"parameter_list": "(arr)"
},
{
"docstring": "Returns the range sum from index l to r using the prefix sums array.",
"func... | [
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] | 10 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def prefix_sum_array(arr):\n \"\"\"\n Given an array, this function computes the prefix sum array.\n \"\"\"\n prefix_sum = [0] * (len(arr) + 1) #... | trial_gpt4o_9 | {
"original_instruction": "You are given an array of $$$n$$$ integers. You have to process multiple queries on this array. For each query, you will be given two integers $$$l$$$ and $$$r$$$. Your task is to find the sum of all the elements from index $$$l$$$ to index $$$r$$$, inclusive.\n\nThe first line contains two... | 0.607915 | Codeforces_9832 | C | [
"compute_prefix_sums",
"range_sum",
"process_queries"
] | 3 | [
[
"process_queries",
"compute_prefix_sums"
],
[
"process_queries",
"range_sum"
]
] | 2 | [
"process_queries"
] | false | [] | false | pytest | true | [] | true | 5f33438aff9c80fbe3a4e78d84e482dac1a5d217 | 77138c139c9f783c85e72bad463a0da353eb2798 | |||
v1.0 | complete | Codeforces | Codeforces_10265_C | from typing import List, Tuple
def tree_diameter(n: int, edges: List[Tuple[int, int]]) -> int:
"""
Determines the longest path between any two nodes in an unweighted tree.
Parameters:
n (int): The number of nodes in the tree.
edges (List[Tuple[int, int]]): A list of edges in the tree.
Ret... | from collections import deque, defaultdict
def find_furthest_node(start, graph):
"""
Performs BFS to find the furthest node from the start node and its distance.
"""
visited = set()
q = deque([(start, 0)])
furthest_node = start
max_distance = 0
while q:
current, distance = q.po... | from solution import tree_diameter
def test_example():
n = 5
edges = [(1, 2), (1, 3), (3, 4), (3, 5)]
assert tree_diameter(n, edges) == 3
def test_one_node():
n = 1
edges = []
assert tree_diameter(n, edges) == 0
def test_two_nodes():
n = 2
edges = [(1, 2)]
assert tree_diameter(n, ... | [
{
"docstring": "Performs BFS to find the furthest node from the start node and its distance.",
"function_declaration": "def find_furthest_node(start, graph):",
"function_name": "find_furthest_node",
"parameter_list": "(start, graph)"
},
{
"docstring": "Finds the diameter of the tree.",
"... | [
1,
0,
0,
1,
0,
1,
1,
1,
1,
0
] | 6 | medium | 0.6 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from collections import deque, defaultdict\n\ndef find_farthest(node, n, graph):\n visited = [False] * (n + 1)\n queue = deque([(node, 0)])\n visited... | trial_gpt4o_8 | {
"original_instruction": "Ling just learned about tree data structures and is excited to solve a new problem using her knowledge. She encounters a problem where she needs to determine the longest path between any two nodes in an unweighted tree (a tree in which the edges have no weights). Ling knows that such a path... | 0.701115 | Codeforces_10265 | C | [
"find_furthest_node",
"tree_diameter"
] | 2 | [
[
"tree_diameter",
"find_furthest_node"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 05d20172100bd7cf627490801d1fdb10b2f828de | 973d2d8d7f9ba0bf3fb7b1b887bd2c64562d978f | |||
v1.0 | complete | Codeforces | Codeforces_9566_C | from typing import List
def min_swaps_to_sort_books(heights: List[int]) -> int:
"""Calculate the minimum number of swap operations required to sort the books in non-decreasing order of their heights.
>>> min_swaps_to_sort_books([1])
0
>>> min_swaps_to_sort_books([1, 2, 3, 4, 5])
0
>>> min_swaps... | def count_inversions(arr):
"""
Count the number of inversions required to sort the array using a modified merge sort.
"""
# Helper function to merge two halves and count inversions
def merge_and_count(arr, temp_arr, left, mid, right):
i = left # Starting index for left subarray
j ... | from solution import min_swaps_to_sort_books
def test_single_book():
assert min_swaps_to_sort_books([1]) == 0
def test_sorted_books():
assert min_swaps_to_sort_books([1, 2, 3, 4, 5]) == 0
def test_reverse_sorted_books():
assert min_swaps_to_sort_books([5, 4, 3, 2, 1]) == 10
def test_random_order_books()... | [
{
"docstring": "Count the number of inversions required to sort the array using a modified merge sort.",
"function_declaration": "def count_inversions(arr):",
"function_name": "count_inversions",
"parameter_list": "(arr)"
},
{
"docstring": "Returns the minimum number of swap operations requi... | [
0,
0,
1,
0,
0,
0,
0,
0,
0,
0
] | 1 | hard | 0.1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def minimum_swaps_to_sort(books):\n \"\"\"\n Returns the minimum number of swap operations required to sort the books in non-decreasing order of their h... | trial_gpt4o_2 | {
"original_instruction": "Polycarp has decided to organize his bookshelf. He wants to arrange his collection of books in a straight line on a single shelf. He has a total of $$$m$$$ books, each with a specific height.\n\nPolycarp can perform one type of operation: swap any two books that are next to each other on th... | 0.611341 | Codeforces_9566 | C | [
"count_inversions",
"min_swaps_to_sort_books"
] | 2 | [
[
"min_swaps_to_sort_books",
"count_inversions"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | a459fc26fc1e1479f905c5862372da76b7df34ff | cb2cb77a59a5ec22987653ffc2cc9060ef8db494 | |||
v1.0 | complete | Codeforces | Codeforces_8158_C | def shortest_path(n: int, edges: List[Tuple[int, int, int]], queries: List[Tuple[int, int]]) -> List[int]:
"""
You are tasked with developing a new navigation system for a quantum computing research facility. The facility's network can be represented as a directed graph with n nodes and m edges, where each node... | import sys
import heapq
def dijkstra(n, adj, start):
dist = [sys.maxsize] * (n + 1)
dist[start] = 0
priority_queue = [(0, start)]
while priority_queue:
current_distance, current_node = heapq.heappop(priority_queue)
if current_distance > dist[current_node]:
continue
... | def test_shortest_path():
n = 4
m = 4
edges = [
(1, 2, 5),
(2, 3, 10),
(3, 4, 1),
(1, 3, 20)
]
queries = [(1, 3), (2, 4), (1, 4)]
expected_output = [15, 11, 16]
assert shortest_path(n, edges, queries) == expected_output
def test_no_path():
n = 3... | [
{
"docstring": null,
"function_declaration": "def dijkstra(n, adj, start):",
"function_name": "dijkstra",
"parameter_list": "(n, adj, start)"
},
{
"docstring": null,
"function_declaration": "def shortest_path(n, edges, queries):",
"function_name": "shortest_path",
"parameter_list... | [
0,
0,
0,
0,
1,
0,
0,
1,
0,
1
] | 3 | hard | 0.3 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import sys\nimport heapq\n\ndef dijkstra(graph, start, n):\n distances = [float('inf')] * (n + 1)\n distances[start] = 0\n min_heap = [(0, start)]\n ... | trial_gpt4o_9 | {
"original_instruction": "**You are tasked with developing a new navigation system for a quantum computing research facility. The facility's network can be represented as a directed graph with n nodes and m edges, where each node corresponds to a specific location within the facility, and each edge represents a perm... | 0.71864 | Codeforces_8158 | C | [
"dijkstra",
"shortest_path"
] | 2 | [
[
"shortest_path",
"dijkstra"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | 688b40b7e7b80a249a81384b6af1c8337a2e850d | 889fac0b79022d911f88c8816e1fc65ef01e6e9d | |||
v1.0 | complete | Codeforces | Codeforces_10554_C | from typing import List
def sum_of_digits(n: int) -> int:
"""
Returns the sum of digits of an integer n.
"""
return sum(int(digit) for digit in str(n))
def transform_list(nums: List[int], k: int) -> List[int]:
"""
Transforms the list 'nums' k times by replacing each integer with
the sum o... | def sum_of_digits(n):
"""
Returns the sum of digits of an integer n.
"""
return sum(int(digit) for digit in str(n))
def transform_list(nums, k):
"""
Transforms the list 'nums' k times by replacing each integer with
the sum of its digits in each transformation.
"""
for _ in range(k)... | from solution import transform_list
def test_transform_list_example_1():
assert transform_list([18, 29, 39], 2) == [9, 2, 3]
def test_transform_list_example_2():
assert transform_list([999, 1000, 12345], 1) == [27, 1, 15]
def test_transform_list_single_element():
assert transform_list([0], 5) == [0]
def... | [
{
"docstring": "Returns the sum of digits of an integer n.",
"function_declaration": "def sum_of_digits(n):",
"function_name": "sum_of_digits",
"parameter_list": "(n)"
},
{
"docstring": "Transforms the list 'nums' k times by replacing each integer with \nthe sum of its digits in each transfo... | [
0,
1,
1,
1,
1,
1,
1,
1,
1,
1
] | 9 | easy | 0.9 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def transform_list(nums, k):\n def sum_of_digits(n):\n return sum(int(digit) for digit in str(n))\n \n for _ in range(k):\n nums = [sum... | trial_gpt4o_9 | {
"original_instruction": "Polycarpus recently got interested in the new area of artificial intelligence and neural networks. As part of his research, he needs to perform a series of transformations on a list of integers. Given a list of integers, he wants to transform this list into a new list by following these ope... | 0.724331 | Codeforces_10554 | C | [
"sum_of_digits",
"transform_list"
] | 2 | [
[
"transform_list",
"sum_of_digits"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 0ffd40c924ab2f12cbcb4949a0c20166d48db618 | 94520b98eadbd5fa6f8625f28d0263d1afffbcdc | |||
v1.0 | complete | Codeforces | Codeforces_10516_C | def is_prime(num):
"""
Checks if a number is prime.
"""
pass
def has_prime_sum_pair(a):
"""
Determines if there exists a pair of indices (i, j) such that the sum of a[i] and a[j] is a prime number.
Args:
a: List[int] - an array of integers
Returns:
str - "YES" if there exists ... | def is_prime(num):
"""Checks if a number is prime."""
if num <= 1:
return False
if num <= 3:
return True
if num % 2 == 0 or num % 3 == 0:
return False
i = 5
while i * i <= num:
if num % i == 0 or num % (i + 2) == 0:
return False
i += 6
retu... | from solution import has_prime_sum_pair
def test_no_prime_pair():
assert has_prime_sum_pair([4, 6, 8, 10]) == "NO" # No sums are prime
def test_single_pair_of_primes():
assert has_prime_sum_pair([1, 2]) == "YES" # 1 + 2 = 3 is prime
def test_multiple_prime_pairs():
assert has_prime_sum_pair([1, 4, 6, 3... | [
{
"docstring": "Checks if a number is prime.",
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": "Determines if there exists a pair of indices (i, j) such that the sum of a[i] and a[j] is a prime number.",
"function_dec... | [
0,
0,
0,
1,
0,
0,
0,
0,
0,
0
] | 1 | hard | 0.1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import math\n\ndef is_prime(n):\n if n <= 1:\n return False\n if n <= 3:\n return True\n if n % 2 == 0 or n % 3 == 0:\n return F... | trial_gpt4o_3 | {
"original_instruction": "You are given an array `a` consisting of `n` integers.\n\nYour task is to determine if there exists a pair of indices `i` and `j` (1 ≤ i < j ≤ n) such that the sum of `a[i]` and `a[j]` is a prime number. If such a pair exists, print \"YES\"; otherwise, print \"NO\".\n\nFor example, if the a... | 0.744443 | Codeforces_10516 | C | [
"is_prime",
"has_prime_sum_pair"
] | 2 | [
[
"has_prime_sum_pair",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 8d660026ce50c9571368c9f5844c2cda6e259c44 | ac53069bd430bd2efac7523ddce7ec76b7875632 | |||
v1.0 | complete | Codeforces | Codeforces_10478_C | def max_trees_to_cut(heights: List[int]) -> int:
"""
Determines the maximum number of trees that can be cut down such
that the remaining tree heights form a non-decreasing sequence.
>>> max_trees_to_cut([3, 7, 5, 8, 10, 5, 13]) == 2
>>> max_trees_to_cut([5, 4, 3, 2, 1]) == 4
>>> max_trees_to_cu... | def max_trees_to_cut(heights):
"""
Determines the maximum number of trees that can be cut down such
that the remaining tree heights form a non-decreasing sequence.
"""
n = len(heights)
# If only one tree or already sorted, no need to cut any tree
if n <= 1 or all(heights[i] <= heights[i... | def test_max_trees_to_cut_basic():
assert max_trees_to_cut([3, 7, 5, 8, 10, 5, 13]) == 2
def test_max_trees_to_cut_all_decreasing():
assert max_trees_to_cut([5, 4, 3, 2, 1]) == 4
def test_max_trees_to_cut_all_increasing():
assert max_trees_to_cut([1, 2, 3, 4, 5]) == 0
def test_max_trees_to_cut_one_tree()... | [
{
"docstring": "Determines the maximum number of trees that can be cut down such\nthat the remaining tree heights form a non-decreasing sequence.",
"function_declaration": "def max_trees_to_cut(heights):",
"function_name": "max_trees_to_cut",
"parameter_list": "(heights)"
},
{
"docstring": n... | [
0,
1,
0,
0,
0,
1,
1,
1,
0,
1
] | 5 | medium | 0.5 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def max_cut_trees_to_non_decreasing(n, heights):\n def lis_length(arr):\n if not arr:\n return 0\n dp = [1] * len(arr)\n fo... | trial_gpt4o_9 | {
"original_instruction": "You are given a list of integers representing the heights of trees lined up in a row. You can cut down trees in such a way that it does not disturb the beauty of the landscape, which means the heights of the trees on each side must appear non-decreasing. To cut down a tree, you remove it fr... | 0.590112 | Codeforces_10478 | C | [
"max_trees_to_cut",
"binary_search"
] | 2 | [
[
"max_trees_to_cut",
"binary_search"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | 97c796c9b6ed5cc82bcad81e6de7cf3a52b43fb3 | 6f26554e65326721022be76fdb9a879d315a45fc | |||
v1.0 | complete | Codeforces | Codeforces_10004_C | def shift_primes_to_end(arr: list) -> list:
"""
Shifts all prime numbers to the end of the list while preserving the
order of the non-prime and prime numbers among themselves.
Parameters:
arr (list): A list of integers.
Returns:
list: A new list with all prime numbers at the end.
Exa... | from math import isqrt
def is_prime(n):
"""
Helper function to check if a number is prime.
"""
if n <= 1:
return False
if n <= 3:
return True
if n % 2 == 0 or n % 3 == 0:
return False
for i in range(5, isqrt(n) + 1, 6):
if n % i == 0 or n % (i + 2) == 0:
... | from solution import shift_primes_to_end
def test_shift_primes_to_end_case_1():
arr = [7, 6, 5, 4, 3, 2]
assert shift_primes_to_end(arr) == [6, 4, 7, 5, 3, 2]
def test_shift_primes_to_end_case_2():
arr = [2, 3, 5, 8, 11, 13, 17, 19, 7, 4]
assert shift_primes_to_end(arr) == [8, 4, 2, 3, 5, 11, 13, 17, ... | [
{
"docstring": "Helper function to check if a number is prime.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Shifts all prime numbers to the end of the list while preserving the \norder of the non-prime and prime numbers... | [
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] | 10 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(num):\n if num <= 1:\n return False\n if num <= 3:\n return True\n if num % 2 == 0 or num % 3 == 0:\n return False\... | trial_gpt4o_9 | {
"original_instruction": "Design a function that takes a list of integers and returns a new list with the same elements but with all prime numbers shifted to the end of the list, while preserving the order of the non-prime and prime numbers among themselves. \n\n### Function Signature\n```python\ndef shift_primes_to... | 0.633858 | Codeforces_10004 | C | [
"is_prime",
"shift_primes_to_end"
] | 2 | [
[
"shift_primes_to_end",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 1574999c5b084704b67452517df9b9e3601d2075 | 2712783bf393e2f4941372c5f5e46a96c4b7bcfc | |||
v1.0 | complete | Codeforces | Codeforces_9995_C | from typing import List
def largest_plant_region(garden: List[List[str]]) -> int:
""" Find the largest rectangular region (by area) in the garden that contains only plants.
>>> largest_plant_region([['P', 'P', 'O', 'P', 'P'], ['P', 'P', 'P', 'P', 'P'], ['P', 'O', 'P', 'P', 'P'], ['P', 'P', 'P', 'O', 'P']])
... | def largest_plant_region(garden):
if not garden:
return 0
max_area = 0
rows = len(garden)
cols = len(garden[0])
heights = [0] * cols
for r in range(rows):
for c in range(cols):
if garden[r][c] == 'P':
heights[c] += 1
else... | def test_largest_plant_region():
assert largest_plant_region([]) == 0
assert largest_plant_region([['P']]) == 1
assert largest_plant_region([['P', 'P'], ['P', 'P']]) == 4
assert largest_plant_region([['P', 'O'], ['O', 'P']]) == 1
assert largest_plant_region([['P', 'P', 'O', 'P', 'P'], ['P', 'P', 'P'... | [
{
"docstring": null,
"function_declaration": "def largest_plant_region(garden):",
"function_name": "largest_plant_region",
"parameter_list": "(garden)"
},
{
"docstring": null,
"function_declaration": "def max_histogram_area(heights):",
"function_name": "max_histogram_area",
"para... | [
1,
0,
1,
0,
1,
1,
1,
1,
1
] | 7 | easy | 0.778 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def maximalRectangle(garden):\n if not garden:\n return 0\n \n n = len(garden)\n m = len(garden[0])\n heights = [0] * m\n max_area = ... | trial_gpt4o_8 | {
"original_instruction": "You are given a rectangular garden represented by a grid of size $$$N \\times M$$$ (1 ≤ $$$N, M$$$ ≤ 1000). Each cell in the grid can either be a plant (represented by 'P') or an obstacle (represented by 'O'). The garden can be divided into rectangular regions such that each region does not... | 0.555907 | Codeforces_9995 | C | [
"largest_plant_region",
"max_histogram_area"
] | 2 | [
[
"largest_plant_region",
"max_histogram_area"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | ca0075a077f66a218063bae26678f673639b51ed | 34a87997d77a806b8db008eaf422e5f02e16643b | |||
v1.0 | complete | Codeforces | Codeforces_10365_C | def max_unique_paths(n: int, m: int, y: int, edges: List[Tuple[int,int]]) -> int:
""" Output the maximum number of unique paths that Alex can pick from node 1 to node n.
If no such path exists, output 0.
>>> max_unique_paths(5, 6, 3, [(1, 2), (2, 3), (3, 5), (1, 4), (4, 5), (2, 4)])
2
>>> max_u... | from collections import defaultdict, deque
def bfs_find_path(capacity, source, sink, parent):
visited = set()
queue = deque([source])
visited.add(source)
while queue:
node = queue.popleft()
for neighbor in capacity[node]:
if neighbor not in visited and capacity... | from solution import max_unique_paths
def test_example_case():
n, m, y = 5, 6, 3
edges = [(1, 2), (2, 3), (3, 5), (1, 4), (4, 5), (2, 4)]
assert max_unique_paths(n, m, y, edges) == 2
def test_no_path_needed():
n, m, y = 5, 6, 0
edges = [(1, 2), (2, 3), (3, 5), (1, 4), (4, 5), (2, 4)]
assert ma... | [
{
"docstring": null,
"function_declaration": "def bfs_find_path(capacity, source, sink, parent):",
"function_name": "bfs_find_path",
"parameter_list": "(capacity, source, sink, parent)"
},
{
"docstring": null,
"function_declaration": "def ford_fulkerson(graph, source, sink):",
"funct... | [
0,
1,
0,
0,
1,
0,
0,
0,
0
] | 2 | hard | 0.222 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from collections import defaultdict, deque\n\ndef max_unique_paths(n, m, y, edges):\n \"\"\"\n Returns the maximum number of unique paths from node 1 to... | trial_gpt4o_4 | {
"original_instruction": "Alex is a skilled horse trainer. His job is to train horses for long-distance races. He wants to ensure that each horse gains maximum endurance by running unique paths in a horse training field represented as an undirected graph with n nodes and m edges. The goal is to pick the maximum numb... | 0.62392 | Codeforces_10365 | C | [
"bfs_find_path",
"ford_fulkerson",
"max_unique_paths"
] | 3 | [
[
"ford_fulkerson",
"bfs_find_path"
],
[
"max_unique_paths",
"ford_fulkerson"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 6728a0530df313dea1d6458d519c2bbe4ae5fb48 | 4db0398c4587fdd044549cf53d8795a6babc3f67 | |||
v1.0 | complete | Codeforces | Codeforces_10230_C | def check_consistency(t: int, data: List[Tuple[int, List[int]]]) -> List[str]:
""" Determine whether each employee's performance metrics are consistent.
Parameters:
t (int): number of employees.
data (list): list of tuples for each employee, where each tuple contains
- an integer n... | def is_consistent(differences):
"""
Helper function to determine if the list of differences are all the same.
"""
return all(d == differences[0] for d in differences)
def check_consistency(t, data):
"""
Determine whether each employee's performance metrics are consistent.
Parameter... | from solution import check_consistency
def test_case_1():
# Single employee with consistent metric
input_data = [(4, [-1, 1, 3, 5])]
assert check_consistency(1, input_data) == ["Consistent"]
def test_case_2():
# Single employee with inconsistent metrics
input_data = [(5, [1, 2, 4, 8, 16])]
ass... | [
{
"docstring": "Helper function to determine if the list of differences are all the same.",
"function_declaration": "def is_consistent(differences):",
"function_name": "is_consistent",
"parameter_list": "(differences)"
},
{
"docstring": "Determine whether each employee's performance metrics ... | [
1,
1,
1,
1,
0,
0,
1,
1,
1
] | 7 | easy | 0.778 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def check_consistency(t, employees_metrics):\n \"\"\"\n Determines whether each employee's performance metrics are consistent.\n \n Parameters:\n ... | trial_gpt4o_9 | {
"original_instruction": "A company wishes to implement a special performance review system for its employees. Each employee has a number of recorded performance metrics for a given month, and each metric is an integer value. The system should identify and reward consistency among employees' performances. \n\nIn par... | 0.539611 | Codeforces_10230 | C | [
"is_consistent",
"check_consistency"
] | 2 | [
[
"check_consistency",
"is_consistent"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 45101c10fda3f93d7fe31ec9eda3c8a91267a4af | d464371a964bd3713d7f2b943b31a4aee6bce4e3 | |||
v1.0 | complete | Codeforces | Codeforces_10804_C | def guess_language(article: str) -> str:
""" Classify the language of a given article based on its content.
>>> guess_language("1\nThe title of the article\nThis is the body of the article. It is written in English.")
"en"
>>> guess_language("2\nLe titre de l'article\nCeci est le corps de l'article. Il ... | import os
import string
from collections import Counter
def load_stopwords():
stopwords = {
'en': ["the", "and", "to", "of", "in", "that", "is", "it", "for", "with"],
'fr': ["et", "le", "de", "la", "les", "des", "une", "que", "en", "pour"],
'de': ["und", "die", "der", "das", "ist", "in", "z... | from solution import guess_language
def test_guess_language_english():
article = "1\nThe title of the article\nThis is the body of the article. It is written in English."
assert guess_language(article) == "en"
def test_guess_language_french():
article = "2\nLe titre de l'article\nCeci est le corps de l'ar... | [
{
"docstring": null,
"function_declaration": "def load_stopwords():",
"function_name": "load_stopwords",
"parameter_list": "()"
},
{
"docstring": null,
"function_declaration": "def preprocess(text):",
"function_name": "preprocess",
"parameter_list": "(text)"
},
{
"docstri... | [
1,
0,
1,
0,
1,
0,
1,
1,
0,
0
] | 5 | medium | 0.5 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def detect_language(article_id, title, body):\n \"\"\"\n Detects the language of a given article based on the content.\n The function uses common wor... | trial_gpt4o_6 | {
"original_instruction": "You are given the task of analyzing text files containing scientific research articles to determine their primary language of publication. For this problem, you've been provided with a collection of articles written either in English („en“), French („fr“), or German („de“).\n\nYou can downl... | 0.475967 | Codeforces_10804 | C | [
"load_stopwords",
"preprocess",
"guess_language"
] | 3 | [
[
"guess_language",
"load_stopwords"
],
[
"guess_language",
"preprocess"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 2f83c179925c4bb49fd474b4eb89ec3fb2d7ee3f | be8f251a5de75301ca35cdee7ef54862068e6a01 | |||
v1.0 | complete | Codeforces | Codeforces_8714_C | def min_swaps_to_sort(arr):
""" This function returns the minimum number of swaps required to sort the array in
non-descending order.
>>> min_swaps_to_sort([4, 3, 2, 1]) 2
>>> min_swaps_to_sort([1, 5, 4, 3, 2]) 2
>>> min_swaps_to_sort([1, 3, 5, 2, 4, 6]) 3
>>> min_swaps_to_sort([1, 2, 3, 4, 5])... | def min_swaps_to_sort(arr):
"""
This function returns the minimum number of swaps required to sort the array in
non-descending order.
"""
n = len(arr)
arrpos = list(enumerate(arr))
arrpos.sort(key=lambda it: it[1])
vis = {k: False for k in range(n)}
ans = 0
for i in range(n):
... | from solution import min_swaps_to_sort, total_min_swaps_to_sort
def test_min_swaps_to_sort():
assert min_swaps_to_sort([4, 3, 2, 1]) == 2
assert min_swaps_to_sort([1, 5, 4, 3, 2]) == 2
assert min_swaps_to_sort([1, 3, 5, 2, 4, 6]) == 3
assert min_swaps_to_sort([1, 2, 3, 4, 5]) == 0
def test_total_min_s... | [
{
"docstring": "This function returns the minimum number of swaps required to sort the array in \nnon-descending order.",
"function_declaration": "def min_swaps_to_sort(arr):",
"function_name": "min_swaps_to_sort",
"parameter_list": "(arr)"
},
{
"docstring": "This function calculates the tot... | [
0,
1,
1,
0,
0,
0,
0,
0,
0,
0
] | 2 | hard | 0.2 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def min_swaps_to_sort(arr):\n \"\"\"\n Returns the minimum number of swaps required to sort the array.\n\n Parameters:\n arr (list): List of integ... | trial_gpt4o_2 | {
"original_instruction": "You are given an array of $$$n$$$ integers $$$a_1, a_2, \\dots, a_n$$$. You can apply the following operation any number of times: choose any two elements in the array and swap their positions. Let $$$g(a)$$$ represent the minimum number of swap operations you need to sort the array in non-... | 0.62271 | Codeforces_8714 | C | [
"min_swaps_to_sort",
"total_min_swaps_to_sort"
] | 2 | [
[
"total_min_swaps_to_sort",
"min_swaps_to_sort"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 123484f495d676119a371d3cdcba5ece005eb634 | 83af5fdf820e764d8b75247a12296b2bd0d8d113 | |||
v1.0 | complete | Codeforces | Codeforces_8503_C | def run_length_encoding_from_string(input_string: str) -> str:
"""
Perform run-length encoding on a given list of integers represented as a string.
Args:
input_string (str): String of integers to encode, separated by spaces.
Returns:
str: Run-length encoded string.
Examples:
... | def run_length_encoding(sequence):
"""
Perform run-length encoding on a given list of integers.
Args:
sequence (list of int): List of integers to encode.
Returns:
list of tuples: Each tuple contains a number and its count.
"""
if not sequence:
return []
encoded = [... | import pytest
from solution import run_length_encoding_from_string
def test_encoding_with_consecutive_numbers():
assert run_length_encoding_from_string("4 4 4 4 5 5 1 1 1") == "4 4 5 2 1 3"
def test_encoding_with_single_number():
assert run_length_encoding_from_string("7") == "7 1"
def test_encoding_with_no_... | [
{
"docstring": "Perform run-length encoding on a given list of integers.\n\nArgs:\nsequence (list of int): List of integers to encode.\n\nReturns:\nlist of tuples: Each tuple contains a number and its count.",
"function_declaration": "def run_length_encoding(sequence):",
"function_name": "run_length_enc... | [
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] | 10 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def run_length_encoding(sequence):\n \"\"\"\n Perform run-length encoding on a given list of integers.\n \n Parameters:\n sequence (list of int... | trial_gpt4o_9 | {
"original_instruction": "Peter is working on optimizing a large dataset of numerical records. He wants to write a program that can compress a sequence of numbers by combining consecutive duplicates into a single number and recording the count of these duplicates. To achieve this, he plans to use run-length encoding... | 0.717789 | Codeforces_8503 | C | [
"run_length_encoding",
"sequence_to_string",
"run_length_encoding_from_string"
] | 3 | [
[
"run_length_encoding_from_string",
"run_length_encoding"
],
[
"run_length_encoding_from_string",
"sequence_to_string"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 5237d2a5ba5266e63b06ea7ab2113064319bcc5f | 5d16f42e7f6b426e29f55146d7f4578c6a792586 | |||
v1.0 | complete | Codeforces | Codeforces_10869_C | def is_subsequence(word: str, s: str) -> bool:
"""
Helper function to check if a `word` is a subsequence of `s`.
"""
it = iter(s)
return all(char in it for char in word)
def longest_word_subsequence_length(s: str, words: List[str]) -> int:
"""
Determine the length of the longest word in the... | def is_subsequence(word, s):
"""
Helper function to check if a `word` is a subsequence of `s`.
"""
it = iter(s)
return all(char in it for char in word)
def longest_word_subsequence_length(s, words):
"""
Returns the length of the longest word in `words` that can be formed as a subsequence of... | from solution import longest_word_subsequence_length
def test_example_case():
s = "abpcplea"
words = ["ale", "apple", "monkey", "plea"]
assert longest_word_subsequence_length(s, words) == 5
def test_no_subsequence():
s = "abc"
words = ["d", "e", "f"]
assert longest_word_subsequence_length(s, w... | [
{
"docstring": "Helper function to check if a `word` is a subsequence of `s`.",
"function_declaration": "def is_subsequence(word, s):",
"function_name": "is_subsequence",
"parameter_list": "(word, s)"
},
{
"docstring": "Returns the length of the longest word in `words` that can be formed as ... | [
1,
0,
1,
1,
1,
0,
1,
1,
1,
1
] | 8 | easy | 0.8 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def longest_word_length(s, word_list):\n def is_subsequence(x, y):\n it = iter(y)\n return all(c in it for c in x)\n\n max_length = 0\n\n ... | trial_gpt4o_9 | {
"original_instruction": "You are given a list of words. Each word consists of lowercase English letters only. Determine the length of the longest word in the list that can be created by deleting some (or none) of the characters from a given string `s` in such a way that the remaining characters appear in the same o... | 0.757105 | Codeforces_10869 | C | [
"is_subsequence",
"longest_word_subsequence_length"
] | 2 | [
[
"longest_word_subsequence_length",
"is_subsequence"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 60728afe4d06537f6146294e6a1bfa28e6dae390 | f11c3547bceb26477c8c58d700ca743c4c5815e9 | |||
v1.0 | complete | Codeforces | Codeforces_10383_C | def workload_assignment(m: int, n: int, capacities: List[int], tasks: List[int]) -> str:
""" Determines an optimal workload assignment to employees such that the difference
in total workload between the most and least loaded employees is minimized, and no
employee exceeds their maximum capacity. If it is po... | def assign_workloads(m, n, capacities, tasks):
from heapq import heappush, heappop
task_indices = sorted(range(n), key=lambda i: -tasks[i])
employees = [(0, i) for i in range(m)]
assignments = [[] for _ in range(m)]
assigned_workloads = [0] * m
for task_idx in task_indices:
... | def test_workloads_possible():
m = 3
n = 5
capacities = [8, 5, 7]
tasks = [2, 3, 4, 5, 1]
result = workload_assignment(m, n, capacities, tasks)
assert result.startswith("YES")
def test_workloads_impossible():
m = 2
n = 3
capacities = [2, 2]
tasks = [2, 2, 2]
result = workloa... | [
{
"docstring": null,
"function_declaration": "def assign_workloads(m, n, capacities, tasks):",
"function_name": "assign_workloads",
"parameter_list": "(m, n, capacities, tasks)"
},
{
"docstring": null,
"function_declaration": "def workload_assignment(m, n, capacities, tasks):",
"func... | [
0,
0,
0,
0,
0,
1,
1,
1,
0
] | 3 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def assign_workloads(m, n, capacities, tasks):\n from heapq import heappush, heappop\n\n # Sort tasks in descending order\n tasks = sorted([(task, id... | trial_gpt4o_8 | {
"original_instruction": "A company has introduced a new system that assigns workloads to its employees. Each employee can handle a maximum workload capacity, and the company wants to ensure that the total workload is distributed as evenly as possible among all employees while adhering to their maximum capacities.\n... | 0.581613 | Codeforces_10383 | C | [
"assign_workloads",
"workload_assignment"
] | 2 | [
[
"workload_assignment",
"assign_workloads"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | 1c21fec058b8b62bb16f24be6c1c9748f09a046b | 7c39d5adf4e0aff5a6a4a912fb7327784b3087a4 | |||
v1.0 | complete | Codeforces | Codeforces_10479_C | def delivery_possible(n: int, m: int, edges: List[Tuple[int, int, int]], start: int, end: int, max_time: int) -> Union[str, Tuple[str, int]]:
""" Determine if Drake can deliver a parcel within a given amount of time in a logistics network.
Args:
n (int): Number of warehouses.
m (int): Number of paths c... | import heapq
def dijkstra(n, edges, start, end, max_time):
graph = [[] for _ in range(n + 1)]
for u, v, t in edges:
graph[u].append((v, t))
graph[v].append((u, t))
min_heap = [(0, start)]
distances = {i: float('inf') for i in range(1, n + 1)}
distances[start] = 0
while... | import pytest
from solution import delivery_possible
def test_example_case():
n = 5
m = 7
edges = [
(1, 2, 10),
(2, 3, 10),
(1, 3, 15),
(3, 4, 10),
(4, 5, 5),
(2, 5, 50),
(3, 5, 30)
]
start, end, max_time = 1, 5, 30
assert delivery_possibl... | [
{
"docstring": null,
"function_declaration": "def dijkstra(n, edges, start, end, max_time):",
"function_name": "dijkstra",
"parameter_list": "(n, edges, start, end, max_time)"
},
{
"docstring": null,
"function_declaration": "def delivery_possible(n, m, edges, start, end, max_time):",
... | [
1,
1,
1,
1,
0,
1,
0,
1,
0,
0
] | 6 | medium | 0.6 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import heapq\n\ndef shortest_path(n, m, edges, s, e, T):\n # Create adjacency list\n graph = {i: [] for i in range(1, n + 1)}\n for u, v, t in edges:... | trial_gpt4o_7 | {
"original_instruction": "Drake, the delivery drone, is used by a logistics company to deliver parcels between different warehouse locations. These locations are labeled with unique positive integers. The drone travels along predefined paths, and each path takes a certain amount of time to traverse. Given a starting... | 0.631423 | Codeforces_10479 | C | [
"dijkstra",
"delivery_possible"
] | 2 | [
[
"delivery_possible",
"dijkstra"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 089f583fd62eb7cad6b35cceecbebdd6da62f74c | 80ffabd5cb61e725f50aaf0619fef80a0e3e9b1d | |||
v1.0 | complete | Codeforces | Codeforces_9716_C | from collections import deque, defaultdict
from typing import List, Tuple
def bfs(tree: defaultdict(list), n: int, start: int) -> List[int]:
"""
Perform a breadth-first search (BFS) on the tree and return the
distance from the start node to all other nodes.
Args:
tree: The tree represented as... | from collections import deque, defaultdict
def bfs(tree, n, start):
"""
Perform a breadth-first search (BFS) on the tree and return the
distance from the start node to all other nodes.
"""
distances = [-1] * (n + 1)
distances[start] = 0
queue = deque([start])
while queue:
... | def test_bfs():
edges = [(1, 2), (1, 3), (2, 4), (2, 5)]
tree = defaultdict(list)
for u, v in edges:
tree[u].append(v)
tree[v].append(u)
assert bfs(tree, 5, 1) == [-1, 0, 1, 1, 2, 2]
assert bfs(tree, 5, 2) == [-1, 1, 0, 2, 1, 1]
assert bfs(tree, 5, 3) == [-1, 1, 2, 0, 3, 3]
def ... | [
{
"docstring": "Perform a breadth-first search (BFS) on the tree and return the \ndistance from the start node to all other nodes.",
"function_declaration": "def bfs(tree, n, start):",
"function_name": "bfs",
"parameter_list": "(tree, n, start)"
},
{
"docstring": "Find the shortest path leng... | [
0,
0,
0,
0,
0,
1,
0,
0,
1,
0
] | 2 | hard | 0.2 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from collections import deque\n\ndef bfs_shortest_path(tree, start, end):\n \"\"\"\n Finds the shortest path between start and end nodes in an unweighte... | trial_gpt4o_8 | {
"original_instruction": "You are given a tree with `n` nodes and `n-1` edges. A tree is a connected undirected graph with no cycles.\n\nYou are also given an integer `k` and a list of `k` pairs of distinct nodes `(xi, yi)`. For each pair, you are asked to find the length of the shortest path between nodes `xi` and ... | 0.611654 | Codeforces_9716 | C | [
"bfs",
"find_shortest_paths",
"find_lca"
] | 3 | [
[
"find_shortest_paths",
"bfs"
],
[
"find_shortest_paths",
"find_lca"
]
] | 2 | [] | false | [] | false | pytest | false | [] | true | 18a298d27799d762d7e36572b9d7eccd12038dcf | 5bb799787dfc5ac6d5674797ae939cb4095745ba | |||
v1.0 | complete | Codeforces | Codeforces_10232_C | def detect_cycle(n, m, edges):
""" Given a directed graph represented as an adjacency list, determine if there is a cycle in the graph.
A cycle is defined as a path that starts and ends at the same vertex, with at least one other vertex involved in the path.
>>> detect_cycle(4, 4, [(1, 2), (2, 3), (3, 4), (... | def detect_cycle(n, m, edges):
from collections import defaultdict, deque
def dfs(vertex):
visited[vertex] = True
recursion_stack[vertex] = True
for neighbor in adj_list[vertex]:
if not visited[neighbor]:
if dfs(neighbor):
return True
... | import pytest
from solution import detect_cycle_from_input
def test_no_cycle():
input_data = "4\n3\n1 2\n2 3\n3 4\n"
assert detect_cycle_from_input(input_data) == "No cycle"
def test_cycle_detected():
input_data = "4\n4\n1 2\n2 3\n3 4\n4 2\n"
assert detect_cycle_from_input(input_data) == "Cycle detect... | [
{
"docstring": null,
"function_declaration": "def detect_cycle(n, m, edges):",
"function_name": "detect_cycle",
"parameter_list": "(n, m, edges)"
},
{
"docstring": null,
"function_declaration": "def detect_cycle_from_input(input_data):",
"function_name": "detect_cycle_from_input",
... | [
1,
1,
0,
1,
1,
0,
1,
1,
1
] | 7 | easy | 0.778 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def detect_cycle(n, m, edges):\n from collections import defaultdict\n \n # Create adjacency list\n adjacency_list = defaultdict(list)\n for u,... | trial_gpt4o_9 | {
"original_instruction": "Given a directed graph represented as an adjacency list, determine if there is a cycle in the graph. A cycle is defined as a path that starts and ends at the same vertex, with at least one other vertex involved in the path.\n\n### Input\n- The first line contains an integer `n` (1 ≤ n ≤ 10^... | 0.635489 | Codeforces_10232 | C | [
"detect_cycle",
"detect_cycle_from_input"
] | 2 | [
[
"detect_cycle_from_input",
"detect_cycle"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 04c884a840bdb5dfab65ca719fa092c4a829383f | c8a3df3cb9c599e3bbbdcc31d90f03cc5acb4460 | |||
v1.0 | complete | Codeforces | Codeforces_11287_C | def contains_cycle(n: int, m: int, edge_list: List[Tuple[int, int]]) -> str:
"""
Given a directed graph represented as an adjacency list, determine whether the graph contains a cycle.
Args:
n : int : the number of nodes.
m : int : the number of directed edges.
edge_list : List[Tuple[int, int]] ... | def is_cyclic(n, edges):
from collections import defaultdict, deque
graph = defaultdict(list)
indegree = [0] * (n + 1)
for u, v in edges:
graph[u].append(v)
indegree[v] += 1
queue = deque([i for i in range(1, n + 1) if indegree[i] == 0])
count = 0
while qu... | from solution import contains_cycle
def test_cycle_present():
assert contains_cycle(4, 4, [(1, 2), (2, 3), (3, 4), (4, 2)]) == "YES"
def test_no_cycle():
assert contains_cycle(3, 2, [(1, 2), (2, 3)]) == "NO"
def test_single_node_no_cycle():
assert contains_cycle(1, 0, []) == "NO"
def test_disconnected_g... | [
{
"docstring": null,
"function_declaration": "def is_cyclic(n, edges):",
"function_name": "is_cyclic",
"parameter_list": "(n, edges)"
},
{
"docstring": null,
"function_declaration": "def contains_cycle(n, m, edge_list):",
"function_name": "contains_cycle",
"parameter_list": "(n, ... | [
1,
1,
1,
1,
0,
1,
1,
1,
1,
1
] | 9 | easy | 0.9 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def has_cycle(n, m, edges):\n from collections import defaultdict, deque\n\n adj_list = defaultdict(list)\n for u, v in edges:\n adj_list[u].a... | trial_gpt4o_8 | {
"original_instruction": "Given a directed graph represented as an adjacency list, determine whether the graph contains a cycle.\n\nInput:\n- The first line contains an integer \\( n \\) (\\( 1 \\le n \\le 10^5 \\)) — the number of nodes.\n- The second line contains an integer \\( m \\) (\\( 0 \\le m \\le 2 \\times ... | 0.665492 | Codeforces_11287 | C | [
"is_cyclic",
"contains_cycle"
] | 2 | [
[
"contains_cycle",
"is_cyclic"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | b953d9d561a17ef6553f3cdeb5268fd9831b1e30 | 0c4952e135c70e731546d7d34ea0b75947e5733f | |||
v1.0 | complete | Codeforces | Codeforces_10469_C | def min_path_cost(grid):
""" Calculate the minimum total cost required to create a clear path from
the top-left to the bottom-right corner of the grid where only right
and down moves are allowed. The cost of cutting down a tree is equal to
its height.
Args:
grid (List[List[int]]): a 2D li... | def min_path_cost(grid):
n = len(grid)
m = len(grid[0])
# Initialize a DP table
dp = [[float('inf')] * m for _ in range(n)]
dp[0][0] = grid[0][0]
for i in range(n):
for j in range(m):
if i > 0:
dp[i][j] = min(dp[i][j], dp[i-1][j] + grid[i][j])
if... | from solution import min_path_cost, min_path_cost_from_input
def test_min_path_cost_basic():
grid = [
[1, 3, 1],
[1, 5, 1],
[4, 2, 1]
]
assert min_path_cost(grid) == 7
def test_min_path_cost_single_cell():
grid = [
[5]
]
assert min_path_cost(grid) == 5
def test... | [
{
"docstring": null,
"function_declaration": "def min_path_cost(grid):",
"function_name": "min_path_cost",
"parameter_list": "(grid)"
},
{
"docstring": null,
"function_declaration": "def min_path_cost_from_input(grid_input):",
"function_name": "min_path_cost_from_input",
"paramet... | [
1,
0,
0,
1,
1,
0,
0,
0,
0,
0
] | 3 | hard | 0.3 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def min_path_cost_grid(n, m, grid):\n \"\"\"\n Returns the minimum total cost required to create a clear path from the top-left to the bottom-right corn... | trial_gpt4o_4 | {
"original_instruction": "There is a forest represented by a grid of size n x m, where each cell in the grid contains a tree with a certain height. A lumberjack wants to cut down trees to create a clear path from the top-left corner to the bottom-right corner of the grid. The lumberjack can only move right or down f... | 0.572726 | Codeforces_10469 | C | [
"min_path_cost",
"min_path_cost_from_input"
] | 2 | [
[
"min_path_cost_from_input",
"min_path_cost"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | d377115d4a11d4ea56a8817d255e5ec265527f9a | ff9ffea97172cae3914d434c91470e344aea9d44 | |||
v1.0 | complete | Codeforces | Codeforces_9262_C | def determine_primary_cookie_type(c, p, o):
"""
Determine the primary cookie type based on the count provided.
"""
# Implement this function to return the primary cookie type as a string if there is one,
# otherwise return None if there is a tie.
def can_arrange_boxes(n, boxes):
"""
Determi... | def determine_primary_cookie_type(c, p, o):
"""
Determine the primary cookie type based on the count provided.
If there is a tie, return None.
"""
if c > p and c > o:
return "Chocolate Chip"
elif p > c and p > o:
return "Peanut Butter"
elif o > c and o > p:
return "Oa... | from solution import can_arrange_boxes
def test_example_1():
boxes = [(5, 3, 2), (1, 4, 3), (2, 2, 5)]
assert can_arrange_boxes(3, boxes) == "Possible"
def test_example_2():
boxes = [(3, 3, 1), (4, 4, 4)]
assert can_arrange_boxes(2, boxes) == "Impossible"
def test_single_box():
boxes = [(5, 0, 0)... | [
{
"docstring": "Determine the primary cookie type based on the count provided.\nIf there is a tie, return None.",
"function_declaration": "def determine_primary_cookie_type(c, p, o):",
"function_name": "determine_primary_cookie_type",
"parameter_list": "(c, p, o)"
},
{
"docstring": "Determin... | [
1,
0,
0,
0,
0,
0,
0,
1,
1,
1
] | 4 | medium | 0.4 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def can_rearrange_boxes(n, boxes):\n from collections import Counter\n \n # Get the primary cookie type for each box\n primary_cookies = []\n f... | trial_gpt4o_9 | {
"original_instruction": "In an industrial bakery, cookies are packed into boxes based on their type. There are three types of cookies: Chocolate Chip, Peanut Butter, and Oatmeal Raisin. You are given a list of boxes and each box contains a certain number of these three types of cookies. Your task is to determine if... | 0.665453 | Codeforces_9262 | C | [
"determine_primary_cookie_type",
"can_arrange_boxes"
] | 2 | [
[
"can_arrange_boxes",
"determine_primary_cookie_type"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | dec8370949e7280c6c2a799f127e9ad5d2581f05 | fa885237ba3a04cc45209cf8c09e40428c9a68f8 | |||
v1.0 | complete | Codeforces | Codeforces_9651_C | def is_palindromic(num: int) -> bool:
""" Returns True if the given num is palindromic, False otherwise.
>>> is_palindromic(121)
True
>>> is_palindromic(123)
False
"""
pass
def sieve_of_eratosthenes(n: int) -> List[bool]:
""" Generates a list of booleans representing prime status for nu... | def is_palindromic(num):
"""
Returns True if the given num is palindromic, False otherwise.
"""
return str(num) == str(num)[::-1]
def sieve_of_eratosthenes(n):
"""
Generates a list of booleans representing prime status for numbers from 0 to n.
True means prime, False means not prime.
""... | from solution import is_palindromic, sieve_of_eratosthenes, count_prime_palindromic
def test_is_palindromic():
assert is_palindromic(121) == True
assert is_palindromic(123) == False
assert is_palindromic(11) == True
assert is_palindromic(7) == True
def test_sieve_of_eratosthenes():
primes = sieve_... | [
{
"docstring": "Returns True if the given num is palindromic, False otherwise.",
"function_declaration": "def is_palindromic(num):",
"function_name": "is_palindromic",
"parameter_list": "(num)"
},
{
"docstring": "Generates a list of booleans representing prime status for numbers from 0 to n.... | [
0,
0,
0,
0,
0,
0,
0,
0,
1,
0
] | 1 | hard | 0.1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(n):\n if n <= 1:\n return False\n if n == 2:\n return True\n if n % 2 == 0:\n return False\n for i in range(3, i... | trial_gpt4o_8 | {
"original_instruction": "ally has received a new lesson in mathematics class about the number system. Her teacher taught her about prime numbers and palindromic numbers and gave her a challenge to merge these concepts.\n\nA number is called prime if it has only two distinct divisors: 1 and itself. A number is calle... | 0.683735 | Codeforces_9651 | C | [
"is_palindromic",
"sieve_of_eratosthenes",
"count_prime_palindromic"
] | 3 | [
[
"count_prime_palindromic",
"is_palindromic"
],
[
"count_prime_palindromic",
"sieve_of_eratosthenes"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 6ab80fa9a4075b2581fbf6299237a2bb20735541 | 8e41d11d5e673300a17c5c240f7ff29e48a08e92 | |||
v1.0 | complete | Codeforces | Codeforces_10931_C | def is_prime(n: int) -> bool:
""" Check if a number is prime.
>>> is_prime(7)
True
>>> is_prime(10)
False
"""
pass
def find_prime_pair(arr: List[int]) -> bool:
""" Given a list of integers, determine if there exists a pair of distinct indices
such that the sum of the elements at th... | def is_prime(n):
"""Check if a number is prime."""
if n <= 1:
return False
if n == 2:
return True
if n % 2 == 0:
return False
max_divisor = int(n**0.5) + 1
for d in range(3, max_divisor, 2):
if n % d == 0:
return False
return True
def find_prime_p... | from solution import find_prime_pair
def test_pair_with_prime_sum_exists():
assert find_prime_pair([1, 4, 6, 7]) == True
assert find_prime_pair([5, 10, 1, 3]) == True
def test_no_pair_with_prime_sum():
assert find_prime_pair([2, 4, 6, 8]) == False
assert find_prime_pair([20, 30, 40, 50]) == False
def... | [
{
"docstring": "Check if a number is prime.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Check if there exists a pair of indices (i, j) such that arr[i] + arr[j] is a prime number.",
"function_declaration": "def fin... | [
0,
0,
1,
0,
0,
0,
0,
1,
0,
0
] | 2 | hard | 0.2 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import math\n\ndef is_prime(n):\n \"\"\"\n Helper function to determine if n is a prime number.\n \"\"\"\n if n <= 1:\n return False\n i... | trial_gpt4o_7 | {
"original_instruction": "Given a list of integers, your task is to determine if there exists a pair of distinct indices `i` and `j` such that the sum of the elements at these indices is a prime number.\n\nWrite a function `find_prime_pair(arr)` that takes a list of integers `arr`, and returns `True` if such a pair ... | 0.724016 | Codeforces_10931 | C | [
"is_prime",
"find_prime_pair"
] | 2 | [
[
"find_prime_pair",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 71418d7efde4761faf15064729be01060ff821a8 | 3cfba47f9c0a8e6e05433e1c75b2815a4f07e200 | |||
v1.0 | complete | Codeforces | Codeforces_10715_C | def count_unique_squares(intersections):
""" Determines how many unique squares can be formed by the given intersections.
>>> count_unique_squares([(1, 1), (1, 2), (2, 1), (2, 2), (3, 3)])
1
>>> count_unique_squares([(1, 1), (1, 2), (2, 1), (2, 2), (3, 3), (3, 4), (4, 3), (4, 4)])
2
"""
pass... | def count_unique_squares(intersections):
points = set((x, y) for x, y in intersections)
count = 0
for (x1, y1) in points:
for (x2, y2) in points:
if x1 != x2 and y1 != y2 and (x1, y2) in points and (x2, y1) in points:
count += 1
return count // 4... | def test_count_unique_squares():
# Test case 1
input_str = "5\n1 1\n1 2\n2 1\n2 2\n3 3"
assert count_unique_squares_from_input(input_str) == 1
# Test case 2
input_str = "8\n1 1\n1 2\n2 1\n2 2\n3 3\n3 4\n4 3\n4 4"
assert count_unique_squares_from_input(input_str) == 2
# Test case 3
... | [
{
"docstring": null,
"function_declaration": "def count_unique_squares(intersections):",
"function_name": "count_unique_squares",
"parameter_list": "(intersections)"
},
{
"docstring": null,
"function_declaration": "def count_unique_squares_from_input(input_str):",
"function_name": "c... | [
0,
1,
0,
1,
0,
0,
1,
0,
0
] | 3 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def count_unique_squares(n, intersections):\n \"\"\"\n This function receives the number of intersections and a list of coordinates, \n and returns t... | trial_gpt4o_7 | {
"original_instruction": "In a distant land, the monarchy has just begun and a new capital city is under construction. The city is designed as a grid of streets and avenues. Each intersection of a street and an avenue is given as (x, y).\n\nAs part of a ceremony, the monarch decides to place a giant flag at every in... | 0.606916 | Codeforces_10715 | C | [
"count_unique_squares",
"count_unique_squares_from_input"
] | 2 | [
[
"count_unique_squares_from_input",
"count_unique_squares"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | 5bef209553d6ad905b786981d078ca4655f3e455 | a974c72030b15b10d75be8bf3d65e82de0163ac2 | |||
v1.0 | complete | Codeforces | Codeforces_9785_C | def solve_magic_square(input: str) -> None:
"""Given a partially filled 3x3 grid, complete the grid with distinct integers
from 1 to 9 such that it forms a magic square. The integer 0 represents an
empty cell. If it is possible to complete the grid to form a magic square,
print the completed grid. Ot... | def is_magic_square(grid):
"""
Check if a 3x3 grid is a magic square.
"""
s = sum(grid[0])
for i in range(3):
if sum(grid[i]) != s or sum(grid[j][i] for j in range(3)) != s:
return False
if sum(grid[i][i] for i in range(3)) != s or sum(grid[i][2-i] for i in range(3)) != s:
... | from solution import solve_magic_square
def test_solve_magic_square_case_1(capsys):
input_string = "8 1 6 3 5 0 4 9 0"
solve_magic_square(input_string)
captured = capsys.readouterr()
assert captured.out == '8 1 6\n3 5 7\n4 9 2\n'
def test_solve_magic_square_case_2(capsys):
input_string = "5 3 4 1 ... | [
{
"docstring": "Check if a 3x3 grid is a magic square.",
"function_declaration": "def is_magic_square(grid):",
"function_name": "is_magic_square",
"parameter_list": "(grid)"
},
{
"docstring": null,
"function_declaration": "def find_magic_square(grid):",
"function_name": "find_magic_s... | [
1,
0,
0,
0,
0,
0,
0,
0,
0,
0
] | 1 | hard | 0.1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_magic_square(grid):\n \"\"\"\n Check if a 3x3 grid is a magic square.\n \"\"\"\n s = sum(grid[0])\n for i in range(3):\n if sum(g... | trial_gpt4o_0 | {
"original_instruction": "The company you work for has decided to host an internal hackathon to boost employee engagement and innovation. As part of the competition, one of the challenges presented is to solve the \"magic square\" problem.\n\nA \"magic square\" is a 3x3 grid filled with distinct integers from 1 to 9... | 0.639857 | Codeforces_9785 | C | [
"is_magic_square",
"find_magic_square",
"solve_magic_square"
] | 3 | [
[
"find_magic_square",
"is_magic_square"
],
[
"solve_magic_square",
"find_magic_square"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | e4be182e2a1dcac2da1ca9d5be46fa09e1c94614 | 4914658e8b8df588dc999a502c522ed4bbda364b | |||
v1.0 | complete | Codeforces | Codeforces_11113_C | def preprocess_array(arr):
"""
Preprocess the array to create a prefix sum array.
>>> preprocess_array([1, 2, 3, 4, 5])
[0, 1, 3, 6, 10, 15]
"""
def range_sum(query, prefix_sum):
"""
Compute the sum of the array elements from index l to r inclusive using the prefix sum array.
>>> ra... | def preprocess_array(arr):
"""
Preprocess the array to create a prefix sum array.
"""
prefix_sum = [0] * (len(arr) + 1)
for i in range(1, len(arr) + 1):
prefix_sum[i] = prefix_sum[i - 1] + arr[i - 1]
return prefix_sum
def range_sum(query, prefix_sum):
"""
Compute the sum of the ... | def test_preprocess_array():
assert preprocess_array([1, 2, 3, 4, 5]) == [0, 1, 3, 6, 10, 15]
def test_range_sum_full_array():
arr = [1, 2, 3, 4, 5]
prefix_sum = preprocess_array(arr)
assert range_sum((1, 5), prefix_sum) == 15
def test_range_sum_partial_array():
arr = [1, 2, 3, 4, 5]
prefix_su... | [
{
"docstring": "Preprocess the array to create a prefix sum array.",
"function_declaration": "def preprocess_array(arr):",
"function_name": "preprocess_array",
"parameter_list": "(arr)"
},
{
"docstring": "Compute the sum of the array elements from index l to r inclusive using the prefix sum ... | [
1,
1,
1,
0,
1,
1,
1,
1
] | 7 | easy | 0.875 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def preprocess(arr):\n \"\"\"\n Preprocess the array to create prefix sums.\n \"\"\"\n n = len(arr)\n prefix_sums = [0] * (n + 1)\n for i in... | trial_gpt4o_8 | {
"original_instruction": "You are given an array of n integers and a sequence of q queries. Each query contains two integers l and r (1 ≤ l ≤ r ≤ n). For each query, you need to calculate the sum of the array elements from index l to index r (inclusive).\n\nGiven the array size and the number of queries could be lar... | 0.602468 | Codeforces_11113 | C | [
"preprocess_array",
"range_sum",
"process_queries"
] | 3 | [
[
"process_queries",
"preprocess_array"
],
[
"process_queries",
"range_sum"
]
] | 2 | [
"process_queries"
] | false | [] | false | pytest | false | [] | true | 7103f64232fa2779d97857402850ec99a3ee6030 | 2f9ecaebbb28a84264e053f0e75f6b1fe493c2a7 | |||
v1.0 | complete | Codeforces | Codeforces_11494_C | def longest_palindromic_substring(s: str) -> str:
""" Returns the longest palindromic substring of s.
>>> longest_palindromic_substring("banana") == "anana"
>>> longest_palindromic_substring("racecar") == "racecar"
>>> longest_palindromic_substring("cbbd") == "bb"
>>> longest_palindromic_substring("... | def longest_palindromic_substring(s):
"""
Returns the longest palindromic substring of s.
"""
n = len(s)
if n == 0:
return ""
start = 0
end = 0
for i in range(n):
len1 = expand_around_center(s, i, i)
len2 = expand_around_center(s, i, i + 1)
max_l... | from solution import longest_palindromic_substring
def test_single_character():
assert longest_palindromic_substring("a") == "a"
assert longest_palindromic_substring("b") == "b"
def test_two_characters():
assert longest_palindromic_substring("aa") == "aa"
assert longest_palindromic_substring("ab") == ... | [
{
"docstring": "Returns the longest palindromic substring of s.",
"function_declaration": "def longest_palindromic_substring(s):",
"function_name": "longest_palindromic_substring",
"parameter_list": "(s)"
},
{
"docstring": null,
"function_declaration": "def expand_around_center(s, left, ... | [
0,
1,
1,
0,
1,
1,
1,
0,
1,
0
] | 6 | medium | 0.6 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def longest_palindromic_substring(s):\n \"\"\"\n Returns the longest palindromic substring in the given string.\n \"\"\"\n n = len(s)\n if n ==... | trial_gpt4o_5 | {
"original_instruction": "Tom is learning about string manipulations and has just learned about the concept of palindromes. A palindrome is a string that reads the same backward as forward. He is particularly interested in finding the longest palindromic substring within a given string. Given a string of characters,... | 0.768044 | Codeforces_11494 | C | [
"longest_palindromic_substring",
"expand_around_center"
] | 2 | [
[
"longest_palindromic_substring",
"expand_around_center"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | b9ca193285b4417e03edeebe647e526bc08c6393 | 45fcce74658400011a8e1db74b81e4ba17d33beb | |||
v1.0 | complete | Codeforces | Codeforces_11053_C | def sieve_of_eratosthenes(n):
""" Returns a list of primes up to n using the Sieve of Eratosthenes """
pass
def sum_primes_in_range(x, y, primes):
""" Returns the sum of primes in the range [x, y] """
pass
def process_queries(queries):
""" Returns a list of results for the sum of primes in range f... | def sieve_of_eratosthenes(n):
""" Returns a list of primes up to n using the Sieve of Eratosthenes """
is_prime = [True] * (n + 1)
p = 2
while p * p <= n:
if is_prime[p]:
for i in range(p * p, n + 1, p):
is_prime[i] = False
p += 1
prime_nums = [p for p in ... | def test_sum_primes_queries():
queries = [(10, 20), (21, 29), (1, 3)]
expected = [60, 52, 5]
assert sum_primes_queries(3, queries) == expected
def test_sum_primes_queries_single_range():
queries = [(10, 10)]
expected = [0]
assert sum_primes_queries(1, queries) == expected
def test_sum_primes_q... | [
{
"docstring": "Returns a list of primes up to n using the Sieve of Eratosthenes ",
"function_declaration": "def sieve_of_eratosthenes(n):",
"function_name": "sieve_of_eratosthenes",
"parameter_list": "(n)"
},
{
"docstring": "Returns the sum of primes in the range [x, y] ",
"function_dec... | [
0,
0,
1,
0,
1,
1,
0,
1,
0,
0
] | 4 | medium | 0.4 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def sum_primes_in_range(x, y):\n \"\"\"\n Return the sum of all prime numbers between x and y (inclusive).\n \"\"\"\n def is_prime(n):\n if... | trial_gpt4o_5 | {
"original_instruction": "You are given several queries. In each query, you are given two positive integers `x` and `y`. Your task is to find the sum of all prime numbers between `x` and `y` (inclusive) for each query. If there are no prime numbers in the given range, return 0 for that query.\n\nA prime number is a ... | 0.625212 | Codeforces_11053 | C | [
"sieve_of_eratosthenes",
"sum_primes_in_range",
"process_queries",
"sum_primes_queries"
] | 4 | [
[
"process_queries",
"sieve_of_eratosthenes"
],
[
"process_queries",
"sum_primes_in_range"
],
[
"sum_primes_queries",
"process_queries"
]
] | 3 | [
"process_queries"
] | false | [] | false | pytest | false | [] | true | 727fb9a371d8ed9be9329a79095196316533755b | ca19d0884d709ee763f9f211542b50b0dfa181be | |||
v1.0 | complete | Codeforces | Codeforces_10738_C | MOD = 10**9 + 7
def factorial_mod(n, mod):
"""
Compute n! % mod using iterative approach.
"""
result = 1
for i in range(1, n + 1):
result = (result * i) % mod
return result
def number_of_transformation_plans(k, p, districts):
"""
Given the number of districts and species and th... | MOD = 10**9 + 7
def factorial_mod(n, mod):
"""
Compute n! % mod using iterative approach.
"""
result = 1
for i in range(1, n + 1):
result = (result * i) % mod
return result
def number_of_transformation_plans(k, p, districts):
"""
Given the number of districts and species and th... | from solution import number_of_transformation_plans
def test_number_of_transformation_plans_example():
k, p = 3, 3
districts = [
[5, 1, 2, 3, 2, 1],
[4, 2, 3, 2, 3],
[3, 1, 1, 1]
]
assert number_of_transformation_plans(k, p, districts) == 6
def test_number_of_transformation_pla... | [
{
"docstring": "Compute n! % mod using iterative approach.",
"function_declaration": "def factorial_mod(n, mod):",
"function_name": "factorial_mod",
"parameter_list": "(n, mod)"
},
{
"docstring": "Given the number of districts and species and their distributions in districts,\nreturn the num... | [
0,
0,
0,
0,
0,
0,
0,
0,
0,
1
] | 1 | hard | 0.1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl",
"solution_code": "MOD = 10**9 + 7\n\ndef factorial(n, mod):\n if n == 0 or n == 1:\n return 1\n fact = 1\n for i in range(2, n + 1):\n fact = (fact * i) ... | trial_gpt4o_9 | {
"original_instruction": "In a land far away, there is a great festival happening in the City of Miracles. The city has k districts, and each district is represented by a set of unique mystical creatures. There are p distinct species of mystical creatures across the city, numbered from 1 to p. The festival involves ... | 0.514938 | Codeforces_10738 | C | [
"factorial_mod",
"number_of_transformation_plans"
] | 2 | [
[
"number_of_transformation_plans",
"factorial_mod"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | d860e64f55b0206a6e6037636581afef4235c7ae | 8c38ceb03d08eddec22a7be03b45cfd784614c90 | |||
v1.0 | complete | Codeforces | Codeforces_9626_C | from math import sqrt
import heapq
def euclidean_distance(x1, y1, x2, y2):
""" Calculate the Euclidean distance between two points (x1, y1) and (x2, y2).
"""
return sqrt((x2 - x1)**2 + (y1 - y2)**2)
def minimum_travel_cost(n, m, coordinates, edges, s, t):
""" Determine the minimum travel cost for a ve... | import heapq
from math import sqrt
def euclidean_distance(x1, y1, x2, y2):
return sqrt((x2 - x1)**2 + (y2 - y1)**2)
def minimum_travel_cost(n, m, coordinates, edges, s, t):
graph = {i: [] for i in range(n)}
for u, v, w in edges:
graph[u-1].append((v-1, w))
graph[v-1].append((u-1, w))
... | from solution import main
def test_example_case():
input_data = """6 7
0 0
2 2
4 4
6 6
8 8
10 10
1 2 3
1 3 10
2 3 2
2 4 8
3 5 2
4 5 3
5 6 1
1 6"""
assert main(input_data) == 8
def test_no_edges():
input_data = """2 0
0 0
1 1
1 2"""
assert main(input_data) == 1 # Direct aerial distance
def test_singl... | [
{
"docstring": null,
"function_declaration": "def euclidean_distance(x1, y1, x2, y2):",
"function_name": "euclidean_distance",
"parameter_list": "(x1, y1, x2, y2)"
},
{
"docstring": null,
"function_declaration": "def minimum_travel_cost(n, m, coordinates, edges, s, t):",
"function_na... | [
0,
0,
0,
1,
0,
0,
0,
0,
0,
0
] | 1 | hard | 0.1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import heapq\nimport math\n\ndef euclidean_distance(x1, y1, x2, y2):\n return math.sqrt((x2 - x1)**2 + (y2 - y1)**2)\n\ndef minimum_travel_cost(n, m, coord... | trial_gpt4o_3 | {
"original_instruction": "A company produces a new type of smart vehicle capable of both ground and aerial movement. The vehicle switches its mode of movement based on the shortest path calculation from its current location to the target. On ground mode, it adheres to the typical road network, and in aerial mode, it... | 0.609065 | Codeforces_9626 | C | [
"euclidean_distance",
"minimum_travel_cost",
"main"
] | 3 | [
[
"minimum_travel_cost",
"euclidean_distance"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 351c7f23e1019f1c223ac9b9de5f23f5e0723057 | fc658cfad26c640504b64b7ebecb5d6d6675539b | |||
v1.0 | complete | Codeforces | Codeforces_10172_C | from typing import List, Tuple
from collections import deque, defaultdict
def bfs_find_farthest_node(start, adj):
visited = set()
queue = deque([(start, 0)]) # (node, distance)
visited.add(start)
farthest_node = start
max_distance = 0
while queue:
node, dist = queue.popleft()... | from collections import deque, defaultdict
def bfs_find_farthest_node(start, adj):
visited = set()
queue = deque([(start, 0)]) # (node, distance)
visited.add(start)
farthest_node = start
max_distance = 0
while queue:
node, dist = queue.popleft()
if dist > max... | from solution import find_tree_diameter
def test_example():
n = 5
edges = [
(1, 2),
(2, 3),
(3, 4),
(4, 5)
]
assert find_tree_diameter(n, edges) == 4
def test_small_tree():
n = 2
edges = [
(1, 2)
]
assert find_tree_diameter(n, edges) == 1
def te... | [
{
"docstring": null,
"function_declaration": "def bfs_find_farthest_node(start, adj):",
"function_name": "bfs_find_farthest_node",
"parameter_list": "(start, adj)"
},
{
"docstring": null,
"function_declaration": "def find_tree_diameter(n, edges):",
"function_name": "find_tree_diamete... | [
1,
1,
1,
1,
0,
1,
0,
1,
1,
0
] | 7 | easy | 0.7 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from collections import deque\n\ndef find_diameter(n, edges):\n def bfs(start):\n dist = [-1] * n\n dist[start] = 0\n q = deque([start... | trial_gpt4o_7 | {
"original_instruction": "You are given an undirected graph represented by an adjacency list. The graph is guaranteed to be a tree. Your task is to find the longest path in this tree, also known as the diameter of the tree. The diameter of a tree is the longest path between any two nodes.\n\nThe first line of the in... | 0.659551 | Codeforces_10172 | C | [
"bfs_find_farthest_node",
"find_tree_diameter"
] | 2 | [
[
"find_tree_diameter",
"bfs_find_farthest_node"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | fcaaed40d4ab5c4ebd6931ab66c54199b63566e1 | 28288777be092aeafb7aec54c4f459dafd40c037 | |||
v1.0 | complete | Codeforces | Codeforces_11466_C | from typing import List, Tuple
def express_bus_routes(n: int, m: int, routes: List[Tuple[int, int, int]]) -> List[int]:
""" Determine the shortest possible time it takes for an express bus to travel from the central station (intersection 1) to each of the other intersections.
Parameters:
n (int): Number o... | import heapq
import sys
from collections import defaultdict
def dijkstra(n, edges):
graph = defaultdict(list)
for u, v, t in edges:
graph[u].append((v, t))
distances = [float('inf')] * (n + 1)
distances[1] = 0
priority_queue = [(0, 1)] # (distance to node, node)
while priority_qu... | from solution import express_bus_routes
def test_example_1():
n = 5
m = 6
routes = [
(1, 2, 4),
(1, 3, 2),
(2, 3, 1),
(3, 4, 7),
(2, 5, 3),
(4, 5, 1)
]
assert express_bus_routes(n, m, routes) == [0, 4, 2, 9, 7]
def test_example_2():
n = 4
m =... | [
{
"docstring": null,
"function_declaration": "def dijkstra(n, edges):",
"function_name": "dijkstra",
"parameter_list": "(n, edges)"
},
{
"docstring": null,
"function_declaration": "def express_bus_routes(n, m, routes):",
"function_name": "express_bus_routes",
"parameter_list": "(... | [
1,
1,
1,
0,
1,
1,
1,
1,
1,
1
] | 9 | easy | 0.9 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import heapq\nimport sys\n\ndef shortest_travel_times_from_central_station(n, m, routes):\n graph = {i: [] for i in range(1, n + 1)}\n for u, v, t in ro... | trial_gpt4o_8 | {
"original_instruction": "Let's create a question that involves graph traversal and is related to a transport network, but focuses more on optimizing the route time under specific conditions.\n\nIn the city of Graphville, there is an efficient bus transport system. The city is represented as a set of n intersections... | 0.67553 | Codeforces_11466 | C | [
"dijkstra",
"express_bus_routes"
] | 2 | [
[
"express_bus_routes",
"dijkstra"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 5c4d465445fd06f95b385992c997436a7a28e2c3 | 9c9d25bac68421995d11869b502f36b436897242 | |||
v1.0 | complete | Codeforces | Codeforces_10732_C | def maximal_rectangle(matrix: List[List[int]]) -> int:
""" Given a matrix of size n x m filled with non-negative integers, find the largest rectangle containing only zeros and return its area.
>>> maximal_rectangle([[1, 0, 0, 1],
[0, 0, 0, 1],
[0, 0, 1, 0],
... | def maximal_rectangle(matrix):
if not matrix:
return 0
n, m = len(matrix), len(matrix[0])
max_area = 0
dp = [0] * m
for i in range(n):
for j in range(m):
dp[j] = dp[j] + 1 if matrix[i][j] == 0 else 0
max_area = max(max_area, largest_rectangle_area(dp))
ret... | from solution import maximal_rectangle
def test_maximal_rectangle_example_case():
matrix = [[1, 0, 0, 1],
[0, 0, 0, 1],
[0, 0, 1, 0],
[1, 0, 0, 0]]
assert maximal_rectangle(matrix) == 4
def test_maximal_rectangle_single_zero():
matrix = [[0]]
assert maximal_re... | [
{
"docstring": null,
"function_declaration": "def maximal_rectangle(matrix):",
"function_name": "maximal_rectangle",
"parameter_list": "(matrix)"
},
{
"docstring": null,
"function_declaration": "def largest_rectangle_area(heights):",
"function_name": "largest_rectangle_area",
"pa... | [
1,
1,
1,
0,
0,
1,
1,
0,
1,
0
] | 6 | medium | 0.6 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def maximal_rectangle(matrix):\n if not matrix:\n return 0\n\n n, m = len(matrix), len(matrix[0])\n heights = [0] * (m + 1)\n max_area = 0\... | trial_gpt4o_5 | {
"original_instruction": "Given a matrix of size n x m filled with non-negative integers, your task is to find the largest rectangle containing only zeros and return its area.\n\nInput Format:\n- The first line contains two integers n (number of rows) and m (number of columns) (1 ≤ n, m ≤ 1000).\n- Each of the next ... | 0.772701 | Codeforces_10732 | C | [
"maximal_rectangle",
"largest_rectangle_area"
] | 2 | [
[
"maximal_rectangle",
"largest_rectangle_area"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 3c89ddc3bbd6e22ad2f2786c74cc7c879a8f9bda | e309dd9fdc852c4adb8f224b38daee47539065e7 | |||
v1.0 | complete | Codeforces | Codeforces_11548_C | def min_weight_path(n: int, m: int, edges: List[Tuple[int, int, int]], s: int, t: int) -> int:
""" Calculate the minimum weight of a path that connects two given nodes s and t in an undirected graph.
>>> min_weight_path(6, 7, [(1, 2, 2), (1, 3, 4), (2, 3, 1), (2, 4, 7), (3, 5, 3), (4, 6, 1), (5, 6, 5)], 1, 6) 1... | import heapq
def dijkstra(n, edges, start, end):
graph = {i: [] for i in range(1, n+1)}
for u, v, w in edges:
graph[u].append((v, w))
graph[v].append((u, w))
pq = [(0, start)]
distances = {i: float('inf') for i in range(1, n+1)}
distances[start] = 0
while pq:
c... | from solution import min_weight_path
def test_example_case():
n = 6
m = 7
edges = [
(1, 2, 2),
(1, 3, 4),
(2, 3, 1),
(2, 4, 7),
(3, 5, 3),
(4, 6, 1),
(5, 6, 5)
]
s = 1
t = 6
assert min_weight_path(n, m, edges, s, t) == 10
def test_no_... | [
{
"docstring": null,
"function_declaration": "def dijkstra(n, edges, start, end):",
"function_name": "dijkstra",
"parameter_list": "(n, edges, start, end)"
},
{
"docstring": null,
"function_declaration": "def min_weight_path(n, m, edges, s, t):",
"function_name": "min_weight_path",
... | [
1,
0,
1,
1,
1,
0,
0,
0,
0,
1
] | 5 | medium | 0.5 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import heapq\n\ndef dijkstra(n, edges, start, end):\n # Initialize graph as an adjacency list\n graph = {i: [] for i in range(1, n + 1)}\n for u, v, ... | trial_gpt4o_9 | {
"original_instruction": "You are given an undirected graph with n nodes and m edges. Each node is numbered from 1 to n. Two nodes can either be connected with an edge or not. Each edge has a weight associated with it. Your task is to calculate the minimum weight of a path that connects two given nodes s and t.\n\nT... | 0.815395 | Codeforces_11548 | C | [
"dijkstra",
"min_weight_path"
] | 2 | [
[
"min_weight_path",
"dijkstra"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | b94271e2f4115553a6b475f5ccc11bf284909fe7 | 19ae48ba7a6dacc24b6687db8145880110a26fd6 | |||
v1.0 | complete | Codeforces | Codeforces_11595_C | def exists_valid_rectangle(n: int, m: int, grid: List[str]) -> str:
""" Determine if there exists at least one valid rectangle in the grid.
>>> exists_valid_rectangle(5, 7, [
... "#######",
... "#.....#",
... "#.....#",
... "#.....#",
... "#######",
... ])
"YES"
>>> exists_vali... | def is_valid_rectangle(grid, n, m):
"""
Returns True if there is at least one valid rectangle in the grid; otherwise, returns False.
"""
for top in range(n):
for left in range(m):
if grid[top][left] == '#':
for bottom in range(top + 2, n):
for righ... | from solution import exists_valid_rectangle
def test_example_1():
n = 5
m = 7
grid = [
"#######",
"#.....#",
"#.....#",
"#.....#",
"#######"
]
assert exists_valid_rectangle(n, m, grid) == "YES"
def test_example_2():
n = 4
m = 4
grid = [
"... | [
{
"docstring": "Returns True if there is at least one valid rectangle in the grid; otherwise, returns False.",
"function_declaration": "def is_valid_rectangle(grid, n, m):",
"function_name": "is_valid_rectangle",
"parameter_list": "(grid, n, m)"
},
{
"docstring": null,
"function_declarat... | [
0,
1,
1,
0,
0,
1,
0,
0,
0,
0
] | 3 | hard | 0.3 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_valid_rectangle(n, m, grid):\n \"\"\"\n Returns \"YES\" if there exists at least one valid rectangle in the grid. Otherwise, returns \"NO\".\n ... | trial_gpt4o_2 | {
"original_instruction": "You are given a rectangular field represented by a grid with dimensions n x m, where 1 <= n, m <= 1000. Each cell in the grid can either be empty (marked as '.') or contain an obstacle (marked as '#'). \n\nA rectangle in the grid is defined as a set of contiguous cells forming a subgrid. Th... | 0.663025 | Codeforces_11595 | C | [
"is_valid_rectangle",
"exists_valid_rectangle"
] | 2 | [
[
"exists_valid_rectangle",
"is_valid_rectangle"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 2718c9be7dca168b8637130c54aa83f7aabca0dc | 32db2c8c27c7b850bd1dbf0c1bea69e1555af534 | |||
v1.0 | complete | Codeforces | Codeforces_10957_C | from typing import Dict, List
from collections import deque, defaultdict
def find_graph_diameter(graph: Dict[int, List[int]], values: List[int]) -> int:
"""
Find the diameter of a connected, undirected graph where the diameter is defined as the maximum sum of values of nodes on the longest path between any tw... | from collections import deque, defaultdict
def bfs(graph, start, values):
visited = [-1] * len(values)
queue = deque([(start, values[start])])
visited[start] = values[start]
farthest_node = start
max_sum = values[start]
while queue:
node, current_sum = queue.popleft()
... | from solution import find_graph_diameter
def test_case_1():
graph = {0: [1, 2], 1: [0, 3], 2: [0], 3: [1]}
values = [4, 3, 2, 1]
assert find_graph_diameter(graph, values) == 10
def test_case_2():
graph = {0: [1], 1: [0, 2], 2: [1, 3], 3: [2]}
values = [1, 2, 3, 4]
assert find_graph_diameter(gr... | [
{
"docstring": null,
"function_declaration": "def bfs(graph, start, values):",
"function_name": "bfs",
"parameter_list": "(graph, start, values)"
},
{
"docstring": null,
"function_declaration": "def find_graph_diameter(graph, values):",
"function_name": "find_graph_diameter",
"pa... | [
0,
0,
0,
0,
0,
0,
1,
0,
0,
0
] | 1 | hard | 0.1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from collections import defaultdict, deque\n\ndef bfs_furthest_node(start, graph, values):\n visited = set()\n queue = deque([(start, values[start])])\n... | trial_gpt4o_6 | {
"original_instruction": "Consider a connected, undirected graph represented as an adjacency list. Each node in the graph has a value associated with it. You are tasked with finding the diameter of the graph, where the diameter is defined as the maximum sum of values of nodes on the longest path between any two node... | 0.577548 | Codeforces_10957 | C | [
"bfs",
"find_graph_diameter"
] | 2 | [
[
"find_graph_diameter",
"bfs"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 27ce3f80db932b02f44ae710fca61dccc845c828 | 6b23d8a3c6f7ccfb613b30ccd26736b85e33eddb | |||
v1.0 | complete | Codeforces | Codeforces_11064_C | def sieve_of_eratosthenes(max_num: int) -> List[int]:
""" Generate all prime numbers up to max_num using the Sieve of Eratosthenes. """
pass
def kth_prime(k: int) -> int:
""" Returns the k-th prime number.
Args:
k (int): The position of the prime number to retrieve (1 ≤ k ≤ 10^6).
Ret... | def sieve_of_eratosthenes(max_num):
"""
Generate all prime numbers up to max_num using the Sieve of Eratosthenes.
"""
is_prime = [True] * (max_num + 1)
p = 2
while p * p <= max_num:
if is_prime[p] == True:
for i in range(p * p, max_num + 1, p):
is_prime[i] = F... | from solution import kth_prime
def test_kth_prime_small():
assert kth_prime(1) == 2
assert kth_prime(2) == 3
assert kth_prime(3) == 5
assert kth_prime(4) == 7
assert kth_prime(5) == 11
def test_kth_prime_medium():
assert kth_prime(100) == 541
assert kth_prime(500) == 3571
def test_kth_pri... | [
{
"docstring": "Generate all prime numbers up to max_num using the Sieve of Eratosthenes.",
"function_declaration": "def sieve_of_eratosthenes(max_num):",
"function_name": "sieve_of_eratosthenes",
"parameter_list": "(max_num)"
},
{
"docstring": "Returns the k-th prime number.",
"function... | [
0,
1,
0,
0,
1,
0,
0,
1,
0,
1
] | 4 | medium | 0.4 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def find_kth_prime(k):\n \"\"\"\n Returns the k-th prime number.\n \"\"\"\n if k < 1:\n raise ValueError(\"K must be a positive integer.\")... | trial_gpt4o_4 | {
"original_instruction": "In a galaxy far, far away, a rebel named Lea is trying to communicate with her team members on different planets. She uses a special communication device that sends messages to the team members. The device operates on a sequence of unique prime numbers to encrypt the messages.\n\nLea wants ... | 0.685584 | Codeforces_11064 | C | [
"sieve_of_eratosthenes",
"kth_prime"
] | 2 | [
[
"kth_prime",
"sieve_of_eratosthenes"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 568929e31ae4bef8e80c7120e5a992625058c444 | 9e9c46df9738847e4c5cae7be5294f7cd0783b96 | |||
v1.0 | complete | Codeforces | Codeforces_11428_C | def expected_sums(n: int, r: int, grid: List[List[int]], changes: List[Tuple[int, int, int]]) -> List[float]:
""" Determine the expected sum of all token values after each round.
>>> expected_sums(3, 2, [[0, 1, 0], [1, 0, 1], [0, 0, 1]], [(0, 0, 1), (2, 2, 0)])
[4/9, 5/9, 4/9]
>>> expected_sums(2, 1, [[... | def expected_sums(n, r, grid, changes):
expected_values = []
total_tokens = n * n
current_sum = sum(sum(row) for row in grid)
current_expected_value = current_sum / total_tokens
expected_values.append(current_expected_value)
for x, y, v in changes:
current_sum -= grid[x][y]
... | import pytest
from solution import expected_sums, parse_and_run
def test_expected_sums_initial_case():
n, r = 3, 2
grid = [
[0, 1, 0],
[1, 0, 1],
[0, 0, 1]
]
changes = [
(0, 0, 1),
(2, 2, 0)
]
expected = [4/9, 5/9, 4/9]
result = expected_sums(n, r, gr... | [
{
"docstring": null,
"function_declaration": "def expected_sums(n, r, grid, changes):",
"function_name": "expected_sums",
"parameter_list": "(n, r, grid, changes)"
},
{
"docstring": null,
"function_declaration": "def parse_and_run(input_str):",
"function_name": "parse_and_run",
"... | [
1,
1,
0,
0,
1,
1,
1,
0,
0,
1
] | 6 | medium | 0.6 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def expected_sums(n, r, grid, ops):\n \"\"\"\n Returns the expected sum of all token values after each round.\n \n n: int : the size of the grid (... | trial_gpt4o_9 | {
"original_instruction": "Michael and Sarah are playing a board game involving a grid of size $$$n \\times n$$$. Each cell of the grid contains a token with a non-negative integer value. At the start of the game, all tokens are placed face down, and their values are hidden. Each token can either have a value of $$$0... | 0.568453 | Codeforces_11428 | C | [
"expected_sums",
"parse_and_run"
] | 2 | [
[
"parse_and_run",
"expected_sums"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 150b1f28152129dbd6f0d174121735426b8cae62 | 421c9c2a816160a7d860af02bbfbb7e567cfe441 | |||
v1.0 | complete | Codeforces | Codeforces_12146_C | def largest_number(arr: List[int]) -> str:
"""
Given an array of non-negative integers, rearranges them to form the largest possible number.
>>> largest_number([3, 30, 34, 5, 9])
'9534330'
>>> largest_number([1, 20, 23, 4, 8])
'8423201'
>>> largest_number([0, 0, 0, 0])
'0'
>>> ... | from functools import cmp_to_key
def compare(x, y):
"""
Comparator function to decide the order of strings x and y.
"""
if x + y > y + x:
return -1
elif x + y < y + x:
return 1
else:
return 0
def largest_number(arr):
"""
Given an array of non-negative integers, ... | from solution import largest_number
def test_largest_number_example1():
assert largest_number([3, 30, 34, 5, 9]) == '9534330'
def test_largest_number_example2():
assert largest_number([1, 20, 23, 4, 8]) == '8423201'
def test_largest_number_same_numbers():
assert largest_number([0, 0, 0, 0]) == '0'
def t... | [
{
"docstring": "Comparator function to decide the order of strings x and y.",
"function_declaration": "def compare(x, y):",
"function_name": "compare",
"parameter_list": "(x, y)"
},
{
"docstring": "Given an array of non-negative integers, rearranges them to form the largest possible number."... | [
1,
1,
0,
1,
0,
0,
0,
1,
1,
0
] | 5 | medium | 0.5 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from functools import cmp_to_key\n\ndef largest_number(nums):\n \"\"\"\n Rearrange the elements of the given array to form the largest possible number.\... | trial_gpt4o_8 | {
"original_instruction": "You are given an array of non-negative integers. Your task is to rearrange the elements of the array to form the largest possible number and print that number.\n\nConsider the following examples:\n- For the array [3, 30, 34, 5, 9], the largest number that can be formed is 9534330.\n- For th... | 0.80126 | Codeforces_12146 | C | [
"compare",
"largest_number"
] | 2 | [
[
"largest_number",
"compare"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | cbb01424bb5ad623874d265de5652ad941d29e9d | c85e854b202d03203f4fb7d8f6bfa21728622bc2 | |||
v1.0 | complete | Codeforces | Codeforces_10812_C | def paving_operations(n, m, edges):
""" A city is represented as an undirected connected graph with `n` nodes (representing intersections) and `m` edges (representing roads). Each road connects two different nodes and has a positive integer length. You are tasked with initiating a series of paving operations to thr... | def find(parent, i):
if parent[i] == i:
return i
return find(parent, parent[i])
def union(parent, rank, x, y):
root_x = find(parent, x)
root_y = find(parent, y)
if rank[root_x] < rank[root_y]:
parent[root_x] = root_y
elif rank[root_x] > rank[root_y]:
parent[root_y] = roo... | from solution import paving_operations
def test_case_1():
n = 4
m = 5
edges = [
(1, 2, 5),
(2, 3, 10),
(3, 4, 1),
(4, 1, 8),
(2, 4, 3)
]
k, operations = paving_operations(n, m, edges)
assert k == 0
assert operations == []
def test_case_2():
n = 2... | [
{
"docstring": null,
"function_declaration": "def find(parent, i):",
"function_name": "find",
"parameter_list": "(parent, i)"
},
{
"docstring": null,
"function_declaration": "def union(parent, rank, x, y):",
"function_name": "union",
"parameter_list": "(parent, rank, x, y)"
},
... | [
1,
0,
0,
0,
1,
0,
1,
0,
0
] | 3 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def find(parent, i):\n if parent[i] == i:\n return i\n return find(parent, parent[i])\n\ndef union(parent, rank, x, y):\n root_x = find(parent... | trial_gpt4o_0 | {
"original_instruction": "A city is represented as an undirected connected graph with `n` nodes (representing intersections) and `m` edges (representing roads). Each road connects two different nodes and has a positive integer length. You are tasked with initiating a series of paving operations to throw out certain ... | 0.626973 | Codeforces_10812 | C | [
"find",
"union",
"kruskal",
"paving_operations"
] | 4 | [
[
"kruskal",
"find"
],
[
"kruskal",
"union"
],
[
"paving_operations",
"kruskal"
],
[
"union",
"find"
]
] | 4 | [] | false | [] | false | pytest | true | [] | true | 747d7b9601ce606e3bc68078b6065f43e56523d2 | 2b2e44ba302a7b665516fa3a887fa508eba778a8 | |||
v1.0 | complete | Codeforces | Codeforces_10845_C | def initialize_grid(n):
"""
Initialize an n x n grid with zeros.
"""
return [[0] * n for _ in range(n)]
def add_to_subgrid(grid, r1, c1, r2, c2, v):
"""
Add v to all elements in the subgrid defined by its top-left corner (r1, c1)
and bottom-right corner (r2, c2).
"""
for i in range... | def initialize_grid(n):
"""
Initialize an n x n grid with zeros.
"""
return [[0] * n for _ in range(n)]
def add_to_subgrid(grid, r1, c1, r2, c2, v):
"""
Add v to all elements in the subgrid defined by its top-left corner (r1, c1)
and bottom-right corner (r2, c2).
"""
for i in range... | import pytest
from solution import initialize_grid, add_to_subgrid, sum_subgrid, process_operations
def test_initialize_grid():
grid = initialize_grid(2)
assert grid == [[0, 0], [0, 0]]
def test_add_to_subgrid():
grid = initialize_grid(3)
add_to_subgrid(grid, 1, 1, 2, 2, 10)
assert grid == [
... | [
{
"docstring": "Initialize an n x n grid with zeros.",
"function_declaration": "def initialize_grid(n):",
"function_name": "initialize_grid",
"parameter_list": "(n)"
},
{
"docstring": "Add v to all elements in the subgrid defined by its top-left corner (r1, c1) \nand bottom-right corner (r2,... | [
0,
0,
0,
1,
0,
0,
0,
0,
0,
0
] | 1 | hard | 0.1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def execute_operations(n, q, operations):\n grid = [[0] * n for _ in range(n)]\n results = []\n\n for op in operations:\n if op[0] == 1:\n ... | trial_gpt4o_3 | {
"original_instruction": "You are given a grid of size $$$n \\times n$$$, initially filled with zeros. You will perform $$$q$$$ operations of the following types:\n\n1. Add an integer $$$v$$$ to all elements in a subgrid defined by its top-left corner $$$(r_1, c_1)$$$ and bottom-right corner $$$(r_2, c_2)$$$.\n2. Qu... | 0.585984 | Codeforces_10845 | C | [
"initialize_grid",
"add_to_subgrid",
"sum_subgrid",
"process_operations"
] | 4 | [
[
"process_operations",
"add_to_subgrid"
],
[
"process_operations",
"initialize_grid"
],
[
"process_operations",
"sum_subgrid"
]
] | 3 | [] | false | [] | false | pytest | true | [] | true | 3489f1a7e386b723e1f30f1cfc9971ddac31bc79 | 52ae70d4acdd8574ba6fbce910d2f29556d6535e | |||
v1.0 | complete | Codeforces | Codeforces_10330_C | import heapq
from typing import List, Tuple
def dijkstra(n: int, adj: List[List[Tuple[int, int]]], start: int) -> List[int]:
""" Dijkstra's algorithm to find the shortest distance from start to all other nodes. """
dist = [float('inf')] * (n + 1)
dist[start] = 0
pq = [(0, start)] # (distance, node)
... | import heapq
def dijkstra(n, adj, start):
"""
Dijkstra's algorithm to find the shortest distance from start to all other nodes.
"""
dist = [float('inf')] * (n + 1)
dist[start] = 0
pq = [(0, start)] # (distance, node)
while pq:
d, node = heapq.heappop(pq)
if d > dist[node]:
... | def test_find_minimum_distance_to_visit_friends():
assert find_minimum_distance_to_visit_friends(5, 6, [
(1, 2, 1), (1, 3, 2), (2, 3, 2), (2, 4, 1),
(3, 5, 1), (4, 5, 2)
], 3, [3, 4, 5]) == 5
# Single edge pathway with no friends
assert find_minimum_distance_to_visit_friends(2, 1, [(1, ... | [
{
"docstring": "Dijkstra's algorithm to find the shortest distance from start to all other nodes.",
"function_declaration": "def dijkstra(n, adj, start):",
"function_name": "dijkstra",
"parameter_list": "(n, adj, start)"
},
{
"docstring": null,
"function_declaration": "def find_minimum_d... | [
0,
0,
0,
0,
1,
0,
0,
0,
0,
0
] | 1 | hard | 0.1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import heapq\n\ndef dijkstra(graph, start):\n \"\"\"\n Find the shortest paths from start node to all other nodes using Dijkstra's algorithm.\n \"\"\... | trial_gpt4o_4 | {
"original_instruction": "Liz and her friends love exploring ancient libraries. She has discovered a unique library, which can be represented as an undirected graph. The graph contains nodes $1$ through $n$ representing rooms, connected by $m$ edges representing pathways between the rooms. Each pathway has a length.... | 0.634481 | Codeforces_10330 | C | [
"dijkstra",
"find_minimum_distance_to_visit_friends"
] | 2 | [
[
"find_minimum_distance_to_visit_friends",
"dijkstra"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | 38ab4525a662acde033d532f29b1444935193759 | df18e2ff7435f2a8a327bff627624eeb02e057d2 | |||
v1.0 | complete | Codeforces | Codeforces_11955_C | MOD = 1000000007
def count_ways(grid: List[List[str]], n: int, m: int) -> int:
""" Count the number of ways to reach the bottom-right corner from the top-left corner in a grid.
>>> count_ways([['.', '#', '#'], ['.', '.', '.'], ['#', '#', '.']], 3, 3)
1
>>> count_ways([['#', '#', '#'], ['.', '.', '.'], ... | MOD = 1000000007
def count_ways(grid, n, m):
if grid[0][0] == '#' or grid[n-1][m-1] == '#':
return 0
dp = [[0] * m for _ in range(n)]
dp[0][0] = 1
for i in range(n):
for j in range(m):
if grid[i][j] == '#':
continue
if i > 0:
... | import pytest
def test_example_case():
n, m = 3, 3
grid_lines = [".##", "...", "##."]
assert solve(n, m, grid_lines) == 1
def test_no_way_case():
n, m = 3, 3
grid_lines = ["###", "...", "##."]
assert solve(n, m, grid_lines) == 0
def test_full_path():
n, m = 2, 2
grid_lines = ["..", ".... | [
{
"docstring": null,
"function_declaration": "def count_ways(grid, n, m):",
"function_name": "count_ways",
"parameter_list": "(grid, n, m)"
},
{
"docstring": null,
"function_declaration": "def solve(n, m, grid_lines):",
"function_name": "solve",
"parameter_list": "(n, m, grid_lin... | [
1,
0,
0,
1,
0,
1,
1,
1,
0,
0
] | 5 | medium | 0.5 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl",
"solution_code": "MOD = 1000000007\n\ndef count_ways(n, m, grid):\n if grid[0][0] == '#' or grid[n-1][m-1] == '#':\n return 0\n \n dp = [[0] * m for _ in range(... | trial_gpt4o_7 | {
"original_instruction": "You are given a rectangular grid of size n x m where each cell can either be blocked (denoted by '#') or unblocked (denoted by '.'). You are initially located at the top-left corner of the grid (1, 1), and you want to move to the bottom-right corner of the grid (n, m). However, you can only... | 0.628349 | Codeforces_11955 | C | [
"count_ways",
"solve"
] | 2 | [
[
"solve",
"count_ways"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | a907825bf6e2c5cc8a5b3382678b06e395417dfe | 5723a560120bc27eed3f52656d2467380dfc0734 | |||
v1.0 | complete | Codeforces | Codeforces_11627_C | def max_banner_area(n: int, heights: List[int]) -> int:
"""
Function to find the maximum possible area of the advertisement banner.
>>> max_banner_area(6, [2, 1, 5, 6, 2, 3])
10
>>> max_banner_area(5, [2, 2, 2, 2, 2])
10
>>> max_banner_area(5, [1, 2, 3, 4, 5])
9
>>> max_banner_a... | def largestRectangleArea(heights):
"""
Function to calculate the largest rectangle area in a histogram.
"""
stack = []
max_area = 0
index = 0
while index < len(heights):
# Push the current building to the stack if it's taller than the building at stack top
if not stack or he... | from solution import max_banner_area
def test_example_case():
assert max_banner_area(6, [2, 1, 5, 6, 2, 3]) == 10
def test_all_same_height():
assert max_banner_area(5, [2, 2, 2, 2, 2]) == 10
def test_increasing_heights():
assert max_banner_area(5, [1, 2, 3, 4, 5]) == 9 # The max area is at bar of height... | [
{
"docstring": "Function to calculate the largest rectangle area in a histogram.",
"function_declaration": "def largestRectangleArea(heights):",
"function_name": "largestRectangleArea",
"parameter_list": "(heights)"
},
{
"docstring": "Function to find the maximum possible area of the adverti... | [
1,
0,
1,
0,
0,
0,
0,
1,
0
] | 3 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def max_banner_area(heights):\n \"\"\"\n Returns the maximum possible area of the advertisement banner\n given the heights of the buildings in a row.... | trial_gpt4o_8 | {
"original_instruction": "You are given a sequence of n integers representing the heights of different buildings in a row. You are an urban planner tasked with placing a large advertising banner across these buildings. The banner can be placed such that it spans across multiple buildings, but due to regulations, the... | 0.561947 | Codeforces_11627 | C | [
"largestRectangleArea",
"max_banner_area"
] | 2 | [
[
"max_banner_area",
"largestRectangleArea"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 8ff930d7e7460296452cf3e17c66aa741579a2b3 | dea0142a0c0d241db50d3b003ca3e3b5460cfee2 | |||
v1.0 | complete | Codeforces | Codeforces_12217_C | from typing import List, Tuple
def calculate_triangle_area(x1: int, y1: int, x2: int, y2: int, x3: int, y3: int) -> float:
"""
Calculates the area of a triangle given its vertices' coordinates using the determinant formula.
"""
pass
def find_largest_triangle_area(points: List[Tuple[int, int]]) -> floa... | from itertools import combinations
def calculate_triangle_area(x1, y1, x2, y2, x3, y3):
"""
Calculates the area of a triangle given its vertices' coordinates using the determinant formula.
"""
return abs(x1*(y2 - y3) + x2*(y3 - y1) + x3*(y1 - y2)) / 2.0
def find_largest_triangle_area(points):
"""
... | from solution import find_largest_triangle_area
def test_example():
points = [(0, 0), (0, 2), (2, 0), (2, 2), (1, 1)]
assert abs(find_largest_triangle_area(points) - 2.0) < 1e-6
def test_all_points_on_a_line():
points = [(0, 0), (1, 1), (2, 2)]
assert find_largest_triangle_area(points) == 0.0
def tes... | [
{
"docstring": "Calculates the area of a triangle given its vertices' coordinates using the determinant formula.",
"function_declaration": "def calculate_triangle_area(x1, y1, x2, y2, x3, y3):",
"function_name": "calculate_triangle_area",
"parameter_list": "(x1, y1, x2, y2, x3, y3)"
},
{
"do... | [
1,
1,
0,
0,
0,
0,
0,
0,
0,
0
] | 2 | hard | 0.2 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from itertools import combinations\nfrom typing import List, Tuple\n\ndef triangle_area(p1: Tuple[int, int], p2: Tuple[int, int], p3: Tuple[int, int]) -> floa... | trial_gpt4o_1 | {
"original_instruction": "You're given $$$n$$$ distinct points on a 2D plane with integer coordinates that form the vertices of a simple polygon (no two edges intersect, except at their endpoints). \n\nYour task is to determine the area of the largest triangle that can be formed by any three of these points. The tri... | 0.807049 | Codeforces_12217 | C | [
"calculate_triangle_area",
"find_largest_triangle_area"
] | 2 | [
[
"find_largest_triangle_area",
"calculate_triangle_area"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 00bfb89f35c833d81fffeca12d2827dd90cdc988 | 89a449b07bf0d1339614708173ada475a6e6376c | |||
v1.0 | complete | Codeforces | Codeforces_11404_C | def minimum_possible_height(n, heights, widths, m, constraint_list):
""" Determine the minimum possible total height of the bookshelf arrangement.
Each book can be represented as a tuple (h_i, w_i) where h_i is the height and w_i is the width of the i-th book.
The total height of the bookshelf row... | from itertools import permutations
def minimum_bookshelf_height(n, heights, widths, constraints):
# Create an adjacency list for the constraints
graph = {i: [] for i in range(n)}
for u, v in constraints:
graph[u - 1].append(v - 1)
graph[v - 1].append(u - 1)
# Helper function to che... | from solution import minimum_possible_height
def test_single_book():
assert minimum_possible_height(1, [10], [5], 0, []) == 10
def test_no_constraints():
assert minimum_possible_height(3, [10, 50, 20], [5, 5, 5], 0, []) == 50
def test_given_example():
assert minimum_possible_height(4, [10, 20, 30, 40], [... | [
{
"docstring": null,
"function_declaration": "def minimum_bookshelf_height(n, heights, widths, constraints):",
"function_name": "minimum_bookshelf_height",
"parameter_list": "(n, heights, widths, constraints)"
},
{
"docstring": null,
"function_declaration": "def minimum_possible_height(n... | [
1,
0,
1,
1,
0,
1,
1,
1,
1
] | 7 | easy | 0.778 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def min_bookshelf_height(n, heights, widths, m, constraints):\n # Adjacency list for the graph of constrained books\n adj = {i: [] for i in range(n)}\n ... | trial_gpt4o_9 | {
"original_instruction": "Robin is a boy who loves arranging books on a bookshelf.\n\nOne day, Robin decided to rearrange his bookshelf which consists of $$$n$$$ books. Each book is characterized by its height and width. Robin wants to place all the books in a row such that the total height of the books in the row i... | 0.675201 | Codeforces_11404 | C | [
"minimum_bookshelf_height",
"minimum_possible_height"
] | 2 | [
[
"minimum_possible_height",
"minimum_bookshelf_height"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | d2155fbf126d1d89188ff49900a1f07353aa2e50 | 0da4cfb5fa9b3b89d0686913ba0f3393d94df110 | |||
v1.0 | complete | Codeforces | Codeforces_11591_C | def town_roads(n: int, m: int, roads: List[Tuple[int, int, int]]) -> Union[int, str]:
"""
Determine the minimum total length of the roads needed to keep all houses connected.
Args:
n (int): Number of houses
m (int): Number of roads
roads (List[Tuple[int, int, int]]): List of roads where ea... | 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_no_solution():
n, m = 3, 1
roads = [(1, 2, 1)]
assert town_roads(n, m, roads) == "No solution"
def test_simple_case():
n, m = 4, 5
roads = [
(1, 2, 3),
(2, 3, 4),
(3, 4, 5),
(4, 1, 2),
(2, 4, 6)
]
assert town_roads(n, m, roads) == 9
def ... | [
{
"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,
1,
0,
0,
0,
0,
0,
0
] | 4 | medium | 0.4 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def find_minimum_spanning_tree(n, m, roads):\n \"\"\"\n This function calculates the minimum total length of the roads needed \n to keep all houses c... | trial_gpt4o_1 | {
"original_instruction": "You are given a town with n houses connected by m roads. Each road connects two houses and has a certain length. The town’s authorities want to ensure that every house can be reached from any other house by travelling along these roads. However, due to budget constraints, they want to minim... | 0.66627 | Codeforces_11591 | C | [
"find",
"union",
"minimum_spanning_tree",
"town_roads"
] | 4 | [
[
"minimum_spanning_tree",
"find"
],
[
"minimum_spanning_tree",
"union"
],
[
"town_roads",
"minimum_spanning_tree"
],
[
"union",
"find"
]
] | 4 | [] | false | [] | false | pytest | false | [] | true | 7582adb2397d21eb52a7da7cef74309213b91ceb | 83da0eb9c42d5da8f65f127399ee14a1bbea3690 | |||
v1.0 | complete | Codeforces | Codeforces_11593_C | from typing import List
def solve(m: int, n: int, grid: List[str]) -> int:
"""
Find the minimum cost to reach the ending position from the starting position in a grid.
Args:
m (int): The number of rows in the grid.
n (int): The number of columns in the grid.
grid (List[str]): The game map... | from heapq import heappop, heappush
def min_cost_to_reach_end(grid):
m, n = len(grid), len(grid[0])
if grid[0][0] == '#' or grid[m-1][n-1] == '#':
return -1
# Directions for moving in the grid
directions = [(0, 1), (1, 0), (0, -1), (-1, 0)]
# Priority queue for Dijkstra's algorith... | import pytest
from solution import solve
def test_example_1():
assert solve(3, 4, ["S.#.", ".*..", "..E."]) == 5
def test_example_2():
assert solve(4, 4, ["S.#*", ".#..", "#.E.", "****"]) == -1
def test_one_step_apart():
assert solve(2, 2, ["S.", ".E"]) == 2
def test_no_possible_path():
assert solve... | [
{
"docstring": null,
"function_declaration": "def min_cost_to_reach_end(grid):",
"function_name": "min_cost_to_reach_end",
"parameter_list": "(grid)"
},
{
"docstring": null,
"function_declaration": "def solve(m, n, grid):",
"function_name": "solve",
"parameter_list": "(m, n, grid... | [
0,
0,
0,
0,
1,
0,
0,
0,
0,
0
] | 1 | hard | 0.1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import heapq\n\ndef min_cost_to_reach_end(grid):\n if not grid or not grid[0]:\n return -1\n\n m, n = len(grid), len(grid[0])\n start, end = (... | trial_gpt4o_4 | {
"original_instruction": "You are given a grid-based game map represented by a matrix containing characters that indicate different types of terrain. The game involves navigating from the top-left corner to the bottom-right corner of the grid. The goal is to find the shortest path from the start to the end position ... | 0.605675 | Codeforces_11593 | C | [
"min_cost_to_reach_end",
"solve"
] | 2 | [
[
"solve",
"min_cost_to_reach_end"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 69391e363edae56914c8b726f8838a32d87ea86b | 1a685b310631065c81f3175ac4dbf25573c1f729 | |||
v1.0 | complete | Codeforces | Codeforces_11505_C | def solve(n: int, q: int, energies: List[int], edges: List[Tuple[int, int]], queries: List[int]) -> List[int]:
""" Optimize energy generation in the power grid. Return the maximum energy generation for each query.
:param n: Number of nodes in the tree (1 ≤ n ≤ 100000)
:param q: Number of queries (1 ≤ q... | from collections import defaultdict
import sys
sys.setrecursionlimit(200000)
def build_tree(edges, n):
tree = defaultdict(list)
for u, v in edges:
tree[u].append(v)
tree[v].append(u)
return tree
def dfs(node, parent, tree, energies, subtree_max):
subtree_max[node] = energies[node - 1]... | from solution import solve
def test_example_case():
n = 5
q = 3
energies = [2, 3, 5, 4, 6]
edges = [(1, 2), (1, 3), (3, 4), (3, 5)]
queries = [1, 3, 4]
result = solve(n, q, energies, edges, queries)
assert result == [6, 6, 4]
def test_single_node():
n = 1
q = 1
energies = [7]
... | [
{
"docstring": null,
"function_declaration": "def build_tree(edges, n):",
"function_name": "build_tree",
"parameter_list": "(edges, n)"
},
{
"docstring": null,
"function_declaration": "def dfs(node, parent, tree, energies, subtree_max):",
"function_name": "dfs",
"parameter_list":... | [
1,
0,
1,
0,
1,
1,
1,
1,
0,
1
] | 7 | easy | 0.7 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def find_max_energy_in_subtree(n, energies, edges, queries):\n from collections import defaultdict, deque\n \n # build the adjacency list for the tre... | trial_gpt4o_9 | {
"original_instruction": "The Great Generator Puzzle\n\nYou are the head engineer at Future Energy Corp, and you've been tasked with optimizing the energy generators distributed across a power grid. The power grid consists of a series of connected nodes arranged in a tree structure. Each node represents a generator ... | 0.561308 | Codeforces_11505 | C | [
"build_tree",
"dfs",
"precompute_subtree_max",
"solve"
] | 4 | [
[
"precompute_subtree_max",
"dfs"
],
[
"solve",
"build_tree"
],
[
"solve",
"precompute_subtree_max"
]
] | 3 | [] | false | [] | false | pytest | true | [] | true | f8c62d39d0b4da83a8c6e2e2e6d1ad5149169cad | d1279a4e3e4fc52d95928037396b36e0638ed163 | |||
v1.0 | complete | Codeforces | Codeforces_11666_C | def solve_berland(input_data: str) -> List[str]:
""" Determine the minimum traveling time required to get from the starting station (station 1)
to all other stations in Berland.
Args:
input_data (str): Input data containing the number of stations, the number of subway lines, and
... | import heapq
def dijkstra(n, edges):
"""
Implements Dijkstra's algorithm to find the shortest path from station 1 to all others.
Args:
n (int): Number of stations.
edges (list of tuple of int): List of edges where each is a tuple (ai, bi, di) representing
a co... | def test_solve_berland():
input_data = "4\n4\n1 2 4\n1 3 2\n2 3 5\n3 4 3"
assert solve_berland(input_data) == ['4', '2', '5']
def test_solve_berland_unreachable():
input_data = "4\n2\n1 2 4\n3 4 3"
assert solve_berland(input_data) == ['4', 'unreachable', 'unreachable']
def test_solve_berland_single_li... | [
{
"docstring": "Implements Dijkstra's algorithm to find the shortest path from station 1 to all others.\n\nArgs:\nn (int): Number of stations.\nedges (list of tuple of int): List of edges where each is a tuple (ai, bi, di) representing\n a connection from station ai to bi with dista... | [
1,
1,
1,
1,
1,
0,
0,
0,
0,
1
] | 6 | medium | 0.6 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import heapq\nfrom collections import defaultdict, deque\n\ndef dijkstra(n, m, edges):\n # Create adjacency list\n graph = defaultdict(list)\n for u,... | trial_gpt4o_9 | {
"original_instruction": "Berland city is well-known for its organized subway system. The city consists of n stations and m subway lines. Each subway line connects a pair of stations and has a certain distance di, which is the time it takes for a train to travel from one end of the line to the other. There can be mu... | 0.613723 | Codeforces_11666 | C | [
"dijkstra",
"solve_berland"
] | 2 | [
[
"solve_berland",
"dijkstra"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | d96128227f861212d47929ae7381e0d9f21238bf | c1c45eefcc1c73a94b2d869b0a79eaa89ce325e5 | |||
v1.0 | complete | Codeforces | Codeforces_12041_C | def minimize_difference(arr: List[int]) -> int:
""" Divide the array into two parts such that the absolute difference between the sum
of the elements in the first part and the sum of the elements in the second part is minimized.
>>> minimize_difference([1, 6, 11, 5])
1
>>> minimize_difference(... | def subset_sum(arr, n, total_sum, calculated_sum):
if n == 0:
return abs((total_sum - calculated_sum) - calculated_sum)
# Including the current element in the first set
inc_current = subset_sum(arr, n-1, total_sum, calculated_sum + arr[n-1])
# Excluding the current element from the fir... | from solution import minimize_difference
def test_minimize_difference_example_1():
arr = [1, 6, 11, 5]
assert minimize_difference(arr) == 1
def test_minimize_difference_example_2():
arr = [1, 2, 3, 4, 5, 6]
assert minimize_difference(arr) == 1
def test_minimize_difference_example_3():
arr = [... | [
{
"docstring": null,
"function_declaration": "def subset_sum(arr, n, total_sum, calculated_sum):",
"function_name": "subset_sum",
"parameter_list": "(arr, n, total_sum, calculated_sum)"
},
{
"docstring": null,
"function_declaration": "def minimize_difference(arr):",
"function_name": ... | [
0,
0,
0,
1,
0,
0,
0,
0,
0
] | 1 | hard | 0.111 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from itertools import combinations\n\ndef find_minimized_difference(arr):\n \"\"\"\n Returns the minimized absolute difference between the sums \n of... | trial_gpt4o_4 | {
"original_instruction": "You are given an array of integers `arr` of length `n`, where `n` is even (1 <= n <= 1000) and `arr[i]` can be positive or negative (-1000 <= arr[i] <= 1000). Your task is to divide the array into two parts such that the absolute difference between the sum of the elements in the first part ... | 0.733016 | Codeforces_12041 | C | [
"subset_sum",
"minimize_difference"
] | 2 | [
[
"minimize_difference",
"subset_sum"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 8d98616a3219f41dc8f73652af445e458b22cf12 | ecf513813b345d63386be78f4eae879680c74ef1 | |||
v1.0 | complete | Codeforces | Codeforces_12404_C | from typing import List
from itertools import permutations
def is_prime(n: int) -> bool:
"""
Returns True if n is a prime number, otherwise False.
"""
def prime_anagram(N: int) -> str:
"""
Returns 'Prime Anagram' if any anagram of N is a prime number, otherwise 'Not Prime Anagram'.
>>> prime_... | from itertools import permutations
def is_prime(n):
"""
Returns True if n is a prime number, otherwise False.
"""
if n <= 1:
return False
if n == 2:
return True
if n % 2 == 0:
return False
for i in range(3, int(n**0.5)+1, 2):
if n % i == 0:
return... | from solution import prime_anagram
def test_prime_anagram_single():
assert prime_anagram(2) == "Prime Anagram"
assert prime_anagram(0) == "Not Prime Anagram"
assert prime_anagram(1) == "Not Prime Anagram"
def test_prime_anagram_various():
assert prime_anagram(197) == "Prime Anagram"
assert prime_a... | [
{
"docstring": "Returns True if n is a prime number, otherwise False.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Returns \"Prime Anagram\" if any anagram of N is a prime number, otherwise \"Not Prime Anagram\".",
... | [
1,
1,
1,
0,
1,
0,
0,
1,
0
] | 5 | medium | 0.556 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from itertools import permutations\n\ndef is_prime(num):\n if num <= 1:\n return False\n if num == 2:\n return True\n if num % 2 == 0:\... | trial_gpt4o_8 | {
"original_instruction": "A prime P is a number that is greater than 1 and has no positive divisor other than 1 and itself. An anagram of P is any number that can be formed by rearranging the digits of P in any order, including leading zeros.\n\nFor example, if P is 197, its anagrams include 197, 719, and 971. Howev... | 0.635044 | Codeforces_12404 | C | [
"is_prime",
"prime_anagram"
] | 2 | [
[
"prime_anagram",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | f68e1e1286d079bd4f01f3f57df64cbfb0cd57ff | a3bb33640026e8f4d412bc20fc1e4272824ef699 | |||
v1.0 | complete | Codeforces | Codeforces_12246_C | def preprocess_sums(arr):
""" Preprocesses the array to create a prefix sum array.
>>> preprocess_sums([1, 2, 3, 4, 5])
[0, 1, 3, 6, 10, 15]
"""
def query_sum(prefix_sums, l, r):
""" Returns the sum of elements from the l-th to r-th index (1-indexed).
>>> prefix_sums = [0, 1, 3, 6, 10, 15]
... | def preprocess_sums(arr):
"""
Preprocesses the array to create a prefix sum array.
"""
prefix_sums = [0] * (len(arr) + 1)
for i in range(len(arr)):
prefix_sums[i + 1] = prefix_sums[i] + arr[i]
return prefix_sums
def query_sum(prefix_sums, l, r):
"""
Returns the sum of elements f... | from solution import preprocess_sums, query_sum, process_queries
def test_preprocess_sums():
arr = [1, 2, 3, 4, 5]
expected_prefix_sums = [0, 1, 3, 6, 10, 15]
assert preprocess_sums(arr) == expected_prefix_sums
def test_query_sum():
prefix_sums = [0, 1, 3, 6, 10, 15]
assert query_sum(prefix_sums, ... | [
{
"docstring": "Preprocesses the array to create a prefix sum array.",
"function_declaration": "def preprocess_sums(arr):",
"function_name": "preprocess_sums",
"parameter_list": "(arr)"
},
{
"docstring": "Returns the sum of elements from the l-th to r-th index (1-indexed).",
"function_de... | [
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] | 10 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def preprocess_array(arr):\n \"\"\"\n Preprocesses the array to create a prefix sum array.\n \"\"\"\n n = len(arr)\n prefix_sum = [0] * (n + 1)... | trial_gpt4o_9 | {
"original_instruction": "Given an array of integers and several queries about the sum of subarray elements, you need to preprocess the array to handle the queries efficiently.\n\nThe first line contains an integer n (1 ≤ n ≤ 105) — the number of elements in the array.\n\nThe second line contains n integers a1, a2, ... | 0.620477 | Codeforces_12246 | C | [
"preprocess_sums",
"query_sum",
"process_queries"
] | 3 | [
[
"process_queries",
"preprocess_sums"
],
[
"process_queries",
"query_sum"
]
] | 2 | [
"process_queries"
] | false | [] | false | pytest | true | [] | true | 27db330364be78229bb6867027d34d6311b78a54 | 7097045e9973459dce63075ac5d41bffc0569d9a | |||
v1.0 | complete | Codeforces | Codeforces_11603_C | def can_form_word(grid: List[str], word: str) -> str:
""" Check if a word can be formed by a rectangle in the grid.
>>> can_form_word(["abde", "cabc", "deab"], "ab")
"YES"
>>> can_form_word(["abde", "cabc", "deab"], "caad")
"NO"
>>> can_form_word(["abde", "cabc", "deab"], "abc")
"YES"
>>... | def can_form_word(grid, word):
n = len(grid)
m = len(grid[0])
length = len(word)
# Iterate through all possible starting points
for x1 in range(n):
for y1 in range(m):
# Iterate through all possible ending points
for x2 in range(x1, n):
for y2 in ... | def test_can_form_word():
grid = [
"abde",
"cabc",
"deab"
]
words = ["ab", "caad", "abc", "de"]
results = ["YES", "NO", "YES", "YES"]
for word, result in zip(words, results):
assert can_form_word(grid, word) == result
def test_solve():
n, m, k = 3, 4, 2
... | [
{
"docstring": null,
"function_declaration": "def can_form_word(grid, word):",
"function_name": "can_form_word",
"parameter_list": "(grid, word)"
},
{
"docstring": null,
"function_declaration": "def solve(n, m, k, grid, words):",
"function_name": "solve",
"parameter_list": "(n, m... | [
1,
0,
0,
0,
0,
0,
0,
1,
0,
0
] | 2 | hard | 0.2 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_word_in_rectangle(grid, n, m, word):\n word_len = len(word)\n \n for x1 in range(n):\n for x2 in range(x1, n):\n for y1 in r... | trial_gpt4o_7 | {
"original_instruction": "You are given a grid of size n by m filled with lowercase letters from 'a' to 'z'. Your task is to find out if there exists a rectangle in the grid such that the concatenation of the letters within this rectangle (traversed row-by-row) forms one of the given words.\n\nThe grid can be repres... | 0.64 | Codeforces_11603 | C | [
"can_form_word",
"solve"
] | 2 | [
[
"solve",
"can_form_word"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | 08441f7a95011ea662440597e644cf06af8ff10b | a37c7877ef4bd0716eee34d9fba0babcadf6d16e | |||
v1.0 | complete | Codeforces | Codeforces_12263_C | from typing import List, Tuple
def find_components(n: int, edges: List[Tuple[int, int]]) -> List[set]:
"""Using DFS to find all connected components in the graph.
Args:
n (int): Number of vertices in the graph.
edges (List[Tuple[int, int]]): List of edges representing the graph.
Returns:
List... | def find_components(n, edges):
"""
Using DFS to find all connected components in the graph.
Returns a list of sets where each set represents a component.
"""
from collections import defaultdict
graph = defaultdict(list)
for u, v in edges:
graph[u].append(v)
graph[v].appe... | def test_find_components():
# Test case 1
n, edges = 5, [(1, 2), (1, 3), (4, 5)]
result = find_components(n, edges)
expected = [{1, 2, 3}, {4, 5}]
assert [set(c) for c in sorted([list(comp) for comp in result])] == [set(c) for c in sorted([list(comp) for comp in expected])]
# Test case 2 with n... | [
{
"docstring": "Using DFS to find all connected components in the graph.\nReturns a list of sets where each set represents a component.",
"function_declaration": "def find_components(n, edges):",
"function_name": "find_components",
"parameter_list": "(n, edges)"
},
{
"docstring": null,
"... | [
0,
0,
1,
1,
0,
1,
0,
0,
1,
0
] | 4 | medium | 0.4 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def find_connected_components(n, edges):\n from collections import defaultdict, deque\n\n def bfs(start, adj_list, visited):\n queue = deque([sta... | trial_gpt4o_8 | {
"original_instruction": "You are given an undirected, connected graph with n vertices, numbered from 1 to n, and m edges. Each vertex has a weight associated with it, represented by an array w where w[i] is the weight of vertex i (1 ≤ i ≤ n).\n\nYou need to answer q queries about the graph. Each query is represente... | 0.653074 | Codeforces_12263 | C | [
"find_components",
"solve"
] | 2 | [
[
"solve",
"find_components"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | 279385ea0818f2ff9b2b5fbe5fa3ea0135163f0a | 65b47d727c053dc0557cfc8f0c94e9e302dcf87c | |||
v1.0 | complete | Codeforces | Codeforces_12366_C | def is_prime(num: int) -> bool:
"""
Check if a number is a prime number.
>>> is_prime(2) True
>>> is_prime(4) False
>>> is_prime(11) True
>>> is_prime(1) False
>>> is_prime(17) True
"""
def sum_of_primes(nums: List[int]) -> int:
"""
Returns the sum of prime numbers from the ... | def is_prime(num):
"""
Check if a number is a prime number.
"""
if num <= 1:
return False
for i in range(2, int(num**0.5) + 1):
if num % i == 0:
return False
return True
def sum_of_primes(nums):
"""
Returns the sum of prime numbers from the list of numbers.
... | from solution import is_prime, sum_of_primes
def test_is_prime():
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(4) == False
assert is_prime(5) == True
assert is_prime(10) == False
assert is_prime(13) == True
assert is_prime(1) == False
assert is_prime(0) == False... | [
{
"docstring": "Check if a number is a prime number.",
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": "Returns the sum of prime numbers from the list of numbers.",
"function_declaration": "def sum_of_primes(nums):",
... | [
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] | 10 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(num):\n \"\"\"\n Returns True if num is a prime number, else False.\n \"\"\"\n if num <= 1:\n return False\n for i in range... | trial_gpt4o_7 | {
"original_instruction": "Petya recently learned about prime numbers and their interesting properties. In honor of his love for primes, his friends decided to play a game with him. They lined up n integers in a sequence and Petya's task is to find the sum of prime numbers from that sequence.\n\nYou are given a list ... | 0.763772 | Codeforces_12366 | C | [
"is_prime",
"sum_of_primes"
] | 2 | [
[
"sum_of_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 2172f77931303617cad5799ac119c407b59eb515 | dfec97e9c9c036e4917f9b7a865f2c9cfc127d14 | |||
v1.0 | complete | Codeforces | Codeforces_12333_C | from typing import List
from collections import deque
def is_one_letter_diff(word1: str, word2: str) -> bool:
"""
Check if the two words differ by exactly one letter.
"""
diff_count = 0
for i in range(len(word1)):
if word1[i] != word2[i]:
diff_count += 1
if diff_count > ... | from collections import deque
def is_one_letter_diff(word1, word2):
"""
Check if the two words differ by exactly one letter.
"""
diff_count = 0
for i in range(len(word1)):
if word1[i] != word2[i]:
diff_count += 1
if diff_count > 1:
return False
return dif... | def test_shortest_word_ladder_length_basic():
assert shortest_word_ladder_length("hit", "cog", ["hot", "dot", "dog", "lot", "log", "cog"]) == 5
def test_shortest_word_ladder_length_no_ladder():
assert shortest_word_ladder_length("hit", "cog", ["hot", "dot", "dog", "lot", "log"]) == 0
def test_shortest_word_la... | [
{
"docstring": "Check if the two words differ by exactly one letter.",
"function_declaration": "def is_one_letter_diff(word1, word2):",
"function_name": "is_one_letter_diff",
"parameter_list": "(word1, word2)"
},
{
"docstring": "Determine the length of the shortest word ladder from start to ... | [
1,
0,
0,
0,
0,
0,
1,
0,
0,
1
] | 3 | hard | 0.3 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from collections import deque\n\ndef word_ladder_length(start, end, dictionary):\n \"\"\"\n Returns the length of the shortest word ladder from start to... | trial_gpt4o_6 | {
"original_instruction": "A word ladder is a sequence of words in which each word differs from the previous one by exactly one letter. Given a start word and an end word of the same length, and a dictionary of valid words, determine the length of the shortest word ladder from start to end, or return 0 if no such lad... | 0.619402 | Codeforces_12333 | C | [
"is_one_letter_diff",
"shortest_word_ladder_length"
] | 2 | [
[
"shortest_word_ladder_length",
"is_one_letter_diff"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | 1dd77f32169a748f5c8b736682bdaa8be353a01e | a8baf124881d7195aba0f81c98927f3dc4e8a349 | |||
v1.0 | complete | Codeforces | Codeforces_12827_C | def maxAreaOfCrops(m: int, n: int, grid: List[List[int]]) -> int:
""" Find the area of the largest rectangular block of crops that can be harvested
>>> maxAreaOfCrops(4, 5, [
... [1, 0, 1, 0, 0],
... [1, 0, 1, 1, 1],
... [1, 1, 1, 1, 1],
... [1, 0, 0, 1, 0]
... ]) == 6
>>> maxAreaOfCrops... | def largestRectangleArea(heights):
stack = []
max_area = 0
for i in range(len(heights)):
start = i
while stack and stack[-1][1] > heights[i]:
index, height = stack.pop()
max_area = max(max_area, height * (i - index))
start = index
stack.append((sta... | from solution import maxAreaOfCrops
def test_example_case():
grid = [
[1, 0, 1, 0, 0],
[1, 0, 1, 1, 1],
[1, 1, 1, 1, 1],
[1, 0, 0, 1, 0]
]
assert maxAreaOfCrops(4, 5, grid) == 6
def test_single_column():
grid = [[1], [1], [0], [1]]
assert maxAreaOfCrops(4, 1, grid) ... | [
{
"docstring": null,
"function_declaration": "def largestRectangleArea(heights):",
"function_name": "largestRectangleArea",
"parameter_list": "(heights)"
},
{
"docstring": null,
"function_declaration": "def maxAreaOfCrops(m, n, grid):",
"function_name": "maxAreaOfCrops",
"paramet... | [
0,
1,
1,
1,
1,
0,
1,
0,
0,
1
] | 6 | medium | 0.6 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def max_histogram_area(heights):\n \"\"\"\n Helper function to calculate the maximum rectangular area in a histogram\n given the heights of the bars.... | trial_gpt4o_6 | {
"original_instruction": "Farmer Joe has a field of crops that he wants to harvest. The field is represented as a 2D grid with m rows and n columns. Each cell in the grid can either contain a crop (represented by a 1) or be empty (represented by a 0). Farmer Joe uses a special type of harvester that can only harvest... | 0.653979 | Codeforces_12827 | C | [
"largestRectangleArea",
"maxAreaOfCrops"
] | 2 | [
[
"maxAreaOfCrops",
"largestRectangleArea"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 398c5576fdd04f8b15969728c8ed1e0c094b755a | 7534bffff42a2300ffa34f71d2635ae52511da40 | |||
v1.0 | complete | Codeforces | Codeforces_13009_C | def is_prime(num):
"""
Determines if a number is prime.
>>> is_prime(2) == True
>>> is_prime(3) == True
>>> is_prime(4) == False
>>> is_prime(29) == True
>>> is_prime(1) == False
>>> is_prime(0) == False
>>> is_prime(-5) == False
"""
pass
def longest_prime_subsequence(n, se... | def is_prime(num):
"""
Determines 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 longest_prime_subsequence(n, sequence):
"""
Finds the longest subsequence of prime numb... | from solution import is_prime, longest_prime_subsequence
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(1) == False
assert is_prime(0) == False
assert is_prime(-5) == False
def test_longest_... | [
{
"docstring": "Determines if a number is prime.",
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": "Finds the longest subsequence of prime numbers from the given sequence.",
"function_declaration": "def longest_prime_... | [
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] | 10 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(num):\n \"\"\" Helper function to check if a number is prime \"\"\"\n if num <= 1:\n return False\n if num == 2:\n return ... | trial_gpt4o_9 | {
"original_instruction": "Gildong is also interested in prime numbers now. He learned that a prime number is a natural number greater than 1 that has no positive divisors other than 1 and itself. For example, the numbers 2, 3, 5, 7, and 11 are prime, while 4, 6, 8, 9, and 10 are not prime.\n\nHe decides to play with... | 0.753729 | Codeforces_13009 | C | [
"is_prime",
"longest_prime_subsequence"
] | 2 | [
[
"longest_prime_subsequence",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | af3553640b0dab60e5160390f2ef7c33394df09c | e4973fe3ed519b83a47fb027ede035afb4e779ec | |||
v1.0 | complete | Codeforces | Codeforces_13097_C | from typing import List, Tuple
def dijkstra(n: int, edges: List[Tuple[int, int, int]], start: int, target: int) -> int:
""" Find the shortest path from the start vertex to the target vertex in a weighted undirected graph.
>>> dijkstra(3, [(1, 2, 2), (2, 3, 4), (1, 3, 6)], 1, 3)
6
>>> dijkstra(3, [... | import sys
import heapq
def dijkstra(n, edges, start, target):
# Build graph from queried edges
graph = {i: [] for i in range(1, n+1)}
for u, v, w in edges:
graph[u].append((v, w))
graph[v].append((u, w))
# Min-heap priority queue
pq = [(0, start)] # (distance, node)
dist ... | def test_dijkstra_with_default_cases():
edges = [(1, 2, 2), (2, 3, 4), (1, 3, 6)]
assert dijkstra(3, edges, 1, 3) == 6
def test_dijkstra_start_equal_target():
edges = [(1, 2, 2), (2, 3, 4), (1, 3, 6)]
assert dijkstra(3, edges, 1, 1) == 0
def test_dijkstra_undirected_path():
edges = [(1, 2, 2), (2,... | [
{
"docstring": null,
"function_declaration": "def dijkstra(n, edges, start, target):",
"function_name": "dijkstra",
"parameter_list": "(n, edges, start, target)"
},
{
"docstring": null,
"function_declaration": "def solve():",
"function_name": "solve",
"parameter_list": "()"
}
] | [
0,
0,
0,
0,
1,
0,
0,
0,
0,
0
] | 1 | hard | 0.1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import heapq\n\ndef shortest_path(n, m, start, target, edges):\n \"\"\"\n Computes the shortest path from start vertex to target vertex using Dijkstra's... | trial_gpt4o_4 | {
"original_instruction": "This is an interactive problem.\n\nYou are given a weighted undirected graph with n vertices and m edges. Each edge has a positive integer weight. Your task is to find the shortest path from a given start vertex to a target vertex, if such a path exists.\n\nMore formally, the graph consists... | 0.663613 | Codeforces_13097 | C | [
"dijkstra",
"solve"
] | 2 | [
[
"solve",
"dijkstra"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | 596d6bb24a0ace6da3c00f9ba9686ac95fb01bcb | 112edc3b67568057c5cd8293d1951d697354ac31 | |||
v1.0 | complete | Codeforces | Codeforces_12524_C | def logistics_optimizer(n: int, m: int, roads: List[Tuple[int, int, int]], k: int, closed_roads: List[Tuple[int, int, int]], d: int, delivery_points: List[int]) -> int:
""" A logistics company wants to optimize their delivery routes within a city. The city is represented as an undirected graph where intersections a... | import heapq
def dijkstra(graph, start, n):
dist = [float('inf')] * (n + 1)
dist[start] = 0
pq = [(0, start)]
while pq:
current_dist, u = heapq.heappop(pq)
if current_dist > dist[u]:
continue
for v, weight in graph[u]:
distance = current_dist + weight
... | from solution import logistics_optimizer
def test_example():
n = 5
m = 6
roads = [(1, 2, 3), (1, 3, 7), (2, 3, 3), (2, 4, 2), (3, 4, 5), (3, 5, 6)]
k = 3
closed_roads = [(1, 4, 2), (2, 3, 4), (3, 5, 8)]
d = 2
delivery_points = [4, 5]
output = logistics_optimizer(n, m, roads, k, closed_r... | [
{
"docstring": null,
"function_declaration": "def dijkstra(graph, start, n):",
"function_name": "dijkstra",
"parameter_list": "(graph, start, n)"
},
{
"docstring": null,
"function_declaration": "def logistics_optimizer(n, m, roads, k, closed_roads, d, delivery_points):",
"function_na... | [
0,
0,
0,
0,
0,
0,
0,
0,
1
] | 1 | hard | 0.111 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import heapq\nfrom collections import defaultdict\nfrom typing import List, Tuple\n\ndef find_min_reopening_cost(n: int, m: int, roads: List[Tuple[int, int, i... | trial_gpt4o_9 | {
"original_instruction": "A logistics company wants to optimize their delivery routes within a city. The city is represented as an undirected graph where intersections are nodes, and roads between intersections are edges. The company needs to determine the shortest path from their warehouse (node $$1$$) to all deliv... | 0.69229 | Codeforces_12524 | C | [
"dijkstra",
"logistics_optimizer"
] | 2 | [
[
"logistics_optimizer",
"dijkstra"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | b9b8b50d960ee216ac7a295892d4410c7818fe7b | 80d00ea5024bb8a7987f3beddc8e11a98df229d8 | |||
v1.0 | complete | Codeforces | Codeforces_12784_C | def maximum_spanning_tree(n: int, edges: List[Tuple[int, int, int]]) -> int:
""" Determine the maximum weight of a spanning tree of the given graph.
>>> maximum_spanning_tree(4, [(1, 2, 3), (2, 3, 4), (3, 4, 5), (4, 1, 6), (1, 3, 2)])
15
>>> maximum_spanning_tree(5, [(1, 2, 10), (1, 3, 5), (3, 4, 7), (2... | # Kruskal's Algorithm with maximum spanning tree concept
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_y] = root_x
elif... | def test_maximum_spanning_tree_simple():
n = 4
edges = [
(1, 2, 3),
(2, 3, 4),
(3, 4, 5),
(4, 1, 6),
(1, 3, 2)
]
assert maximum_spanning_tree(n, edges) == 15
def test_maximum_spanning_tree_with_more_edges():
n = 5
edges = [
(1, 2, 10),
(1,... | [
{
"docstring": null,
"function_declaration": "def find(parent, i):",
"function_name": "find",
"parameter_list": "(parent, i)"
},
{
"docstring": null,
"function_declaration": "def union(parent, rank, x, y):",
"function_name": "union",
"parameter_list": "(parent, rank, x, y)"
},
... | [
0,
0,
0,
1,
1,
1,
1,
0,
0
] | 4 | medium | 0.444 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def find_maximum_spanning_tree_weight(n, m, edges):\n \"\"\"\n Find the maximum weight of a spanning tree of the graph using Kruskal's algorithm\n mo... | trial_gpt4o_6 | {
"original_instruction": "You are given an undirected graph with n vertices and m edges. Each edge has a weight w associated with it. A spanning tree of this graph is a subset of the edges that form a tree and connect all vertices. Your task is to determine the maximum weight of a spanning tree of this graph.\n\nInp... | 0.684268 | Codeforces_12784 | C | [
"find",
"union",
"maximum_spanning_tree"
] | 3 | [
[
"maximum_spanning_tree",
"find"
],
[
"maximum_spanning_tree",
"union"
],
[
"union",
"find"
]
] | 3 | [] | false | [] | false | pytest | false | [] | true | f9eda461e1a40c9d1f2f1879c22bb8c97d66e076 | 2a5e71f80e5f4c43eb90d09f8d77d0a9639e8576 | |||
v1.0 | complete | Codeforces | Codeforces_13213_C | from typing import List
def sieve_of_eratosthenes(max_num: int) -> List[int]:
""" Generate a list of prime numbers up to max_num using the Sieve of Eratosthenes algorithm.
>>> sieve_of_eratosthenes(10)
[2, 3, 5, 7]
>>> sieve_of_eratosthenes(1)
[]
>>> sieve_of_eratosthenes(2)
[2]
"""
... | def sieve_of_eratosthenes(max_num):
primes = []
is_prime = [True] * (max_num + 1)
for p in range(2, max_num + 1):
if is_prime[p]:
primes.append(p)
for multiple in range(p * p, max_num + 1, p):
is_prime[multiple] = False
return primes
def construct_sequenc... | def test_sieve_of_eratosthenes():
assert sieve_of_eratosthenes(10) == [2, 3, 5, 7]
assert sieve_of_eratosthenes(1) == []
assert sieve_of_eratosthenes(2) == [2]
def test_construct_sequence():
assert construct_sequence(3, 3) == [2, 3, 5]
assert construct_sequence(1, 0) == [1]
assert construct_seq... | [
{
"docstring": null,
"function_declaration": "def sieve_of_eratosthenes(max_num):",
"function_name": "sieve_of_eratosthenes",
"parameter_list": "(max_num)"
},
{
"docstring": null,
"function_declaration": "def construct_sequence(n, k):",
"function_name": "construct_sequence",
"par... | [
1,
0,
0,
0,
0,
0,
0,
0,
0
] | 1 | hard | 0.111 | {
"trial_gpt4o_0": null,
"trial_gpt4o_1": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared1_results_combined.jsonl",
"solution_code": "def sieve_of_eratosthenes(max_num):\n primes = []\n is_prime = [True] * (max_num + 1)\n for p in range(2, max_num + 1):\n ... | trial_gpt4o_1 | {
"original_instruction": "### Prime Factorization Game\n\nAlice and Bob are playing a prime factorization game. Alice writes down a sequence of n distinct positive integers on the board. Bob then starts picking pairs of numbers from the sequence in such a way that the product of each picked pair is a unique number n... | 0.634403 | Codeforces_13213 | C | [
"sieve_of_eratosthenes",
"construct_sequence"
] | 2 | [
[
"construct_sequence",
"sieve_of_eratosthenes"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | c1df928c446f0b87fe277aaa7e7c820fb436d882 | 313a09adf43805627490a411d8f52b2065e5e591 | |||
v1.0 | complete | Codeforces | Codeforces_12385_C | def max_path_sum(grid):
"""Find the maximum sum path from the top-left corner to the bottom-right corner
of a grid with the constraint of only moving right or down.
Args:
grid (List[List[int]]): The grid represented as a 2D list of non-negative integers.
Returns:
int: The maxim... | def max_path_sum(grid):
n = len(grid)
dp = [[0] * n for _ in range(n)]
# Initialize the dp table
dp[0][0] = grid[0][0]
# Fill the first row and first column
for i in range(1, n):
dp[0][i] = dp[0][i-1] + grid[0][i]
dp[i][0] = dp[i-1][0] + grid[i][0]
# Fill the r... | from solution import max_path_sum_from_input
def test_case_1():
grid = [
[1, 3, 1, 4],
[2, 2, 3, 2],
[4, 1, 2, 1],
[2, 1, 2, 3]
]
assert max_path_sum_from_input(4, grid) == 16
def test_case_2():
grid = [
[1, 2, 3],
[4, 5, 6],
[7, 8, 9]
]
... | [
{
"docstring": null,
"function_declaration": "def max_path_sum(grid):",
"function_name": "max_path_sum",
"parameter_list": "(grid)"
},
{
"docstring": null,
"function_declaration": "def max_path_sum_from_input(n, grid):",
"function_name": "max_path_sum_from_input",
"parameter_list... | [
0,
0,
0,
0,
1,
0,
0,
0,
0,
0
] | 1 | hard | 0.1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def max_path_sum(n, grid):\n \"\"\"\n Returns the maximum sum of any path from the top-left corner to the bottom-right corner.\n \"\"\"\n # Create... | trial_gpt4o_4 | {
"original_instruction": "Alex is fond of playing games on a grid. He came up with one such game where he needs to traverse an $n \\times n$ grid. The grid is represented by an $n \\times n$ matrix filled with non-negative integers. The goal is to find the maximum sum of any path from the top-left corner (cell (1,1)... | 0.656763 | Codeforces_12385 | C | [
"max_path_sum",
"max_path_sum_from_input"
] | 2 | [
[
"max_path_sum_from_input",
"max_path_sum"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 6936a612e3c4bececd6da9a58c5a48b6e3df8332 | 02d1d27b7838df8b8594c16c261774d03145df12 | |||
v1.0 | complete | Codeforces | Codeforces_12473_C | def max_team_productivity(n: int, productivity: List[int], edges: List[Tuple[int, int]]) -> int:
"""
Determine the maximum possible productivity score that any single team can achieve.
Parameters:
n (int): The number of employees.
productivity (List[int]): The productivity scores of the employe... | def dfs(u, parent, children, productivity, subtree_sum):
subtree_sum[u] = productivity[u]
for v in children[u]:
if v != parent:
dfs(v, u, children, productivity, subtree_sum)
subtree_sum[u] += subtree_sum[v]
def max_team_productivity(n, productivity, edges):
# Create an adja... | from solution import max_team_productivity
def test_example_case():
n = 6
productivity = [10, 5, 8, 7, 6, 5]
edges = [(1, 2), (1, 3), (2, 4), (2, 5), (3, 6)]
assert max_team_productivity(n, productivity, edges) == 18
def test_small_case():
n = 2
productivity = [1, 2]
edges = [(1, 2)]
a... | [
{
"docstring": null,
"function_declaration": "def dfs(u, parent, children, productivity, subtree_sum):",
"function_name": "dfs",
"parameter_list": "(u, parent, children, productivity, subtree_sum)"
},
{
"docstring": null,
"function_declaration": "def max_team_productivity(n, productivity... | [
0,
0,
1,
0,
0,
0,
0,
0,
1,
1
] | 3 | hard | 0.3 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def max_team_productivity_score(n, productivity_scores, subordinates):\n import collections\n\n # Convert productivity_scores to be 1-indexed\n produ... | trial_gpt4o_9 | {
"original_instruction": "In a large competitive corporation, there is a hierarchical structure composed of n employees, including the CEO. Each employee (except the CEO) has exactly one direct manager, who is also an employee of the company.\n\nRecently, the company decided to restructure its departments by creatin... | 0.617623 | Codeforces_12473 | C | [
"dfs",
"max_team_productivity"
] | 2 | [
[
"max_team_productivity",
"dfs"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 29004d9296578e80487f26fb304ff9a28e560512 | b8df6dbb4eb48d6397c3d7f1f5d5d8436b699c3b | |||
v1.0 | complete | Codeforces | Codeforces_13537_C | def max_in_ranges(n: int, heights: List[int], queries: List[Tuple[int, int]]) -> List[int]:
"""
Find the maximum height of buildings in the specified range for each query.
Parameters:
n (int): The number of buildings.
heights (List[int]): The heights of the buildings.
queries (List[Tuple[i... | def build_sparse_table(arr):
import math
n = len(arr)
K = math.floor(math.log2(n)) + 1
st = [[0] * K for _ in range(n)]
for i in range(n):
st[i][0] = arr[i]
j = 1
while (1 << j) <= n:
i = 0
while (i + (1 << j) - 1) < n:
st[i][j] = max(st[i][j - 1... | from solution import max_in_ranges
def test_sample_input_1():
n = 5
heights = [3, 6, 2, 7, 4]
queries = [(1, 3), (2, 4), (1, 5)]
expected_output = [6, 7, 7]
assert max_in_ranges(n, heights, queries) == expected_output
def test_sample_input_2():
n = 8
heights = [4, 2, 3, 5, 1, 7, 2, 9]
... | [
{
"docstring": null,
"function_declaration": "def build_sparse_table(arr):",
"function_name": "build_sparse_table",
"parameter_list": "(arr)"
},
{
"docstring": null,
"function_declaration": "def query_rmq(st, l, r):",
"function_name": "query_rmq",
"parameter_list": "(st, l, r)"
... | [
1,
1,
1,
1,
1,
1,
1,
0
] | 7 | easy | 0.875 | {
"trial_gpt4o_0": null,
"trial_gpt4o_1": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared1_results_combined.jsonl",
"solution_code": "class MaxHeightQuery:\n def __init__(self, heights):\n self.heights = heights\n self.n = len(heights)\n self.... | trial_gpt4o_6 | {
"original_instruction": "You are given an array of n integers (2 ≤ n ≤ 10^5) and q queries (1 ≤ q ≤ 10^5). Each element in the array is a non-negative integer that represents the height of a building. Similarly, each query consists of two integers l and r (1 ≤ l ≤ r ≤ n), which define a range within the array. \n\n... | 0.628813 | Codeforces_13537 | C | [
"build_sparse_table",
"query_rmq",
"max_in_ranges"
] | 3 | [
[
"max_in_ranges",
"build_sparse_table"
],
[
"max_in_ranges",
"query_rmq"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 74d5ea577ecca1ab95db736700eb3c0c6695f7c4 | 483b1bd36bceccd392d3014718f2a76603680904 | |||
v1.0 | complete | Codeforces | Codeforces_13401_C | import os
from collections import Counter
platform_keywords = {
"Twitter": Counter(),
"Facebook": Counter(),
"Instagram": Counter()
}
def preprocess_text(content):
""" Basic preprocessing to remove special characters and lower case the content """
return content
def train_model(base_path="dataset... | import os
from collections import Counter
import re
platform_keywords = {
"Twitter": Counter(),
"Facebook": Counter(),
"Instagram": Counter()
}
def preprocess_text(content):
# Basic preprocessing to remove special characters and lowercase conversion
content = re.sub(r'[^a-zA-Z0-9\s]', '', content)... | import pytest
from solution import classify_post, train_model
# Mock training data and function
def mock_train_model():
sample_data = {
"Twitter": ["tweet this is a tweet", "twitter is fun", "retweet this", "mentions"],
"Facebook": ["facebook friends", "likes and comments", "facebook post", "groups... | [
{
"docstring": null,
"function_declaration": "def preprocess_text(content):",
"function_name": "preprocess_text",
"parameter_list": "(content)"
},
{
"docstring": null,
"function_declaration": "def train_model(base_path='dataset'):",
"function_name": "train_model",
"parameter_list... | [
0,
0,
0,
0,
0,
0,
0,
0,
0,
1
] | 1 | hard | 0.1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import os\nfrom collections import Counter\n\ndef extract_features_from_post(post_content):\n words = post_content.split()\n num_hashtags = sum(1 for wo... | trial_gpt4o_9 | {
"original_instruction": "You have been given a set of social media posts gathered from three different platforms. Each post can be labeled as originating from one of the following platforms: Twitter, Facebook, or Instagram. The goal is to identify the platform of a given post based on the patterns present in the po... | 0.526719 | Codeforces_13401 | C | [
"preprocess_text",
"train_model",
"classify_post"
] | 3 | [
[
"classify_post",
"preprocess_text"
],
[
"train_model",
"preprocess_text"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 5c2bb598846660e5cd6c4d20f7a5edd6d9e49a34 | c0129cff894de8fed10daede4c55ba774fadc804 | |||
v1.0 | complete | Codeforces | Codeforces_13094_C | from typing import List
def process_islands(input_str: str) -> int:
""" Determine the number of distinct islands in a given grid.
The input string starts with the dimensions of the grid followed by the grid rows.
Each row contains m integers (either 0 or 1), representing the grid itself.
The... | def numDistinctIslands(grid):
def dfs(x, y, origin):
if not (0 <= x < m and 0 <= y < n) or grid[x][y] == 0:
return
grid[x][y] = 0
shape.append((x - origin[0], y - origin[1]))
for dx, dy in [(-1, 0), (1, 0), (0, -1), (0, 1)]:
dfs(x + dx, y + dy, origin)
... | from solution import process_islands
def test_simple_case():
input_str = "3 3\n1 1 0\n1 0 0\n0 0 1"
assert process_islands(input_str) == 2
def test_single_island():
input_str = "3 3\n1 0 0\n0 0 0\n0 0 0"
assert process_islands(input_str) == 1
def test_no_islands():
input_str = "3 3\n0 0 0\n0 0 0\... | [
{
"docstring": null,
"function_declaration": "def numDistinctIslands(grid):",
"function_name": "numDistinctIslands",
"parameter_list": "(grid)"
},
{
"docstring": null,
"function_declaration": "def parse_input(input_str):",
"function_name": "parse_input",
"parameter_list": "(input... | [
0,
0,
0,
0,
0,
1,
0,
0,
0,
0
] | 1 | hard | 0.1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def numDistinctIslands(grid):\n \"\"\"\n Returns the number of distinct islands in the grid.\n \"\"\"\n def dfs(x, y, origin_x, origin_y, shape):\... | trial_gpt4o_5 | {
"original_instruction": "You are given a rectangular grid of size m x n, filled with 0's and 1's. An island is a group of 1's (representing land) connected 4-directionally (horizontal or vertical.) You may assume all four edges of the grid are surrounded by water.\n\nThe goal is to determine the number of distinct ... | 0.583177 | Codeforces_13094 | C | [
"numDistinctIslands",
"parse_input",
"process_islands"
] | 3 | [
[
"process_islands",
"numDistinctIslands"
],
[
"process_islands",
"parse_input"
]
] | 2 | [
"parse_input"
] | false | [] | false | pytest | true | [] | true | 64296656c4f0b821443f8dc1c024520690a5a844 | 5c650c342eae7d9b1698a28a97dbb310ff9e7091 | |||
v1.0 | complete | Codeforces | Codeforces_12376_C | from flask import Flask, request, jsonify
from werkzeug.security import generate_password_hash, check_password_hash
from functools import wraps
import re
app = Flask(__name__)
subscribers = set()
def is_valid_email(email):
""" Check if the provided email is in valid format. """
regex = r'^\b[A-Za-z0-9._%+-]+... | from flask import Flask, request, jsonify
from werkzeug.security import generate_password_hash, check_password_hash
from functools import wraps
import re
app = Flask(__name__)
# A simple database placeholder
subscribers = set()
# Helper function to validate email format
def is_valid_email(email):
regex = r'^\b[A... | import pytest
from solution import app, subscribers
@pytest.fixture
def client():
with app.test_client() as client:
yield client
def test_subscribe_success(client):
response = client.post('/subscribe', json={"email": "test@example.com"}, headers={"Authorization": "Basic dXNlcjpwYXNzd29yZA=="}) # 'user... | [
{
"docstring": null,
"function_declaration": "def is_valid_email(email):",
"function_name": "is_valid_email",
"parameter_list": "(email)"
},
{
"docstring": null,
"function_declaration": "def auth_required(f):",
"function_name": "auth_required",
"parameter_list": "(f)"
},
{
... | [
0,
0,
0,
1,
0,
0,
0,
0,
0,
1
] | 2 | hard | 0.2 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from flask import Flask, request, jsonify\nfrom flask_httpauth import HTTPBasicAuth\nimport re\n\napp = Flask(__name__)\nauth = HTTPBasicAuth()\n\n# In-memory... | trial_gpt4o_9 | {
"original_instruction": "Design an API endpoint that allows users to subscribe and unsubscribe from a newsletter.\n\nRequirements:\n1. Create two endpoints:\n - `/subscribe`: accepts a user's email and subscribes them to the newsletter.\n - `/unsubscribe`: accepts a user's email and unsubscribes them from the n... | 0.625003 | Codeforces_12376 | C | [
"is_valid_email",
"auth_required",
"subscribe",
"unsubscribe"
] | 4 | [
[
"subscribe",
"is_valid_email"
],
[
"unsubscribe",
"is_valid_email"
]
] | 2 | [] | false | [] | false | pytest | true | [
"flask",
"werkzeug"
] | false | b23b3165baa42bd0f385ce8bcfdf953e4c5125e7 | 7e8c528a02b24bd2c80f13b606af91807ec60264 | |||
v1.0 | complete | Codeforces | Codeforces_13843_C | def solve_puzzle(test_cases):
""" Solves the puzzle for each given test case, determining the length of the longest palindromic subsequence for each array.
Args:
test_cases (List[Tuple[int, List[int]]]): A list of tuples, where each tuple contains an integer N and a list of N integers.
Returns:
... | def longest_palindromic_subsequence_length(arr):
n = len(arr)
dp = [[0] * n for _ in range(n)]
for i in range(n):
dp[i][i] = 1
for cl in range(2, n + 1):
for i in range(n - cl + 1):
j = i + cl - 1
if arr[i] == arr[j] and cl == 2:
dp[i][j]... | import pytest
from solution import solve_puzzle, parse_input, generate_output
def test_longest_palindromic_subsequence_basic_cases():
input_string = "3\n5\n1 2 3 2 1\n4\n1 2 3 4\n6\n1 2 1 2 2 1\n"
expected_output = "5\n1\n5"
test_cases = parse_input(input_string)
results = solve_puzzle(test_cases)
... | [
{
"docstring": null,
"function_declaration": "def longest_palindromic_subsequence_length(arr):",
"function_name": "longest_palindromic_subsequence_length",
"parameter_list": "(arr)"
},
{
"docstring": null,
"function_declaration": "def solve_puzzle(test_cases):",
"function_name": "sol... | [
1,
1,
0,
0,
0,
1,
0,
0,
1,
0
] | 4 | medium | 0.4 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def longest_palindromic_subsequence(arr):\n n = len(arr)\n dp = [[0]*n for _ in range(n)]\n \n for i in range(n):\n dp[i][i] = 1\n \n ... | trial_gpt4o_8 | {
"original_instruction": "Heidi finds herself in yet another peculiar situation - this time in the depths of a medieval dungeon. To escape, she needs to solve a puzzle involving ancient numerology and get past the enchanted door. \n\nThe door is operated by an array of integers, and Heidi needs to convert this array... | 0.695453 | Codeforces_13843 | C | [
"longest_palindromic_subsequence_length",
"solve_puzzle",
"parse_input",
"generate_output"
] | 4 | [
[
"solve_puzzle",
"longest_palindromic_subsequence_length"
]
] | 1 | [
"parse_input",
"generate_output"
] | false | [] | false | pytest | true | [] | true | 18d6acbb83db443698b9f59e65abfce724924346 | 8519a86e14f9204cc0feb3946deb70f43f9054f0 | |||
v1.0 | complete | Codeforces | Codeforces_13389_C | class TreeNode:
def __init__(self, val=0, left=None, right=None):
self.val = val
self.left = left
self.right = right
def build_tree(nodes):
""" Build a binary tree from the list of nodes.
"""
node_map = {}
for val, left, right in nodes:
if val not in node_map:
... | class TreeNode:
def __init__(self, val=0, left=None, right=None):
self.val = val
self.left = left
self.right = right
def build_tree(nodes):
node_map = {}
for val, left, right in nodes:
if val not in node_map:
node_map[val] = TreeNode(val)
node = node_map[... | from solution import determine_winner
def test_case_1():
tree_nodes = [
(1, 2, 3),
(2, -1, -1),
(3, 4, 5),
(4, -1, -1),
(5, -1, -1)
]
assert determine_winner(tree_nodes) == "Alice"
def test_case_2():
tree_nodes = [
(1, 2, -1),
(2, 3, -1),
... | [] | [
1,
1,
1,
1,
0,
0,
0,
0,
0
] | 4 | medium | 0.444 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl",
"solution_code": "class TreeNode:\n def __init__(self, value):\n self.value = value\n self.left = None\n self.right = None\n\ndef build_tree(nodes):\n ... | trial_gpt4o_1 | {
"original_instruction": "Alice and Bob are playing a game on a binary tree. They take alternating turns, and Alice always starts first. On each turn, a player must remove a leaf node from the tree. A leaf node is a node that has no children. The player who cannot make a move loses the game.\n\nYou are given the ini... | 0.60902 | Codeforces_13389 | C | [
"build_tree",
"count_leaf_nodes",
"determine_winner"
] | 3 | [
[
"determine_winner",
"build_tree"
],
[
"determine_winner",
"count_leaf_nodes"
]
] | 2 | [] | false | [
"TreeNode"
] | true | pytest | true | [] | true | 9d11e99fb8fc8d7f1174cf95142384aa1ebbe557 | a18b4e33bdc7c70b4355ee880c69846a0c18c45f | |||
v1.0 | complete | Codeforces | Codeforces_13468_C | from typing import List
def longest_common_prefix(s1: str, s2: str) -> int:
"""Returns the length of the longest common prefix between strings s1 and s2.
>>> longest_common_prefix("abc", "abcd") == 3
>>> longest_common_prefix("abc", "abf") == 2
>>> longest_common_prefix("abc", "bde") == 0
>>> longe... | def longest_common_prefix(s1, s2):
"""
Returns the length of the longest common prefix between strings s1 and s2.
"""
min_len = min(len(s1), len(s2))
for i in range(min_len):
if s1[i] != s2[i]:
return i
return min_len
def max_magical_strength(potions):
"""
Returns th... | from solution import longest_common_prefix, max_magical_strength
# Tests for longest_common_prefix function
def test_longest_common_prefix():
assert longest_common_prefix("abc", "abcd") == 3
assert longest_common_prefix("abc", "abf") == 2
assert longest_common_prefix("abc", "bde") == 0
assert longest_c... | [
{
"docstring": "Returns the length of the longest common prefix between strings s1 and s2.",
"function_declaration": "def longest_common_prefix(s1, s2):",
"function_name": "longest_common_prefix",
"parameter_list": "(s1, s2)"
},
{
"docstring": "Returns the maximum possible magical strength o... | [
0,
0,
1,
0,
0,
0,
0,
0,
0,
0
] | 1 | hard | 0.1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def longest_common_prefix(s1, s2):\n \"\"\"\n Returns the length of the longest common prefix of strings s1 and s2.\n \"\"\"\n lcp_length = 0\n ... | trial_gpt4o_2 | {
"original_instruction": "You have a collection of unique magical potions, where each potion is represented as a string of lowercase letters. These potions have a unique property: if you concatenate two potions, the resulting potion's magical strength is equal to the length of the longest common prefix (LCP) of the ... | 0.639756 | Codeforces_13468 | C | [
"longest_common_prefix",
"max_magical_strength"
] | 2 | [
[
"max_magical_strength",
"longest_common_prefix"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 32fc314d16adcf5419e773d63227b85fca3092f1 | 8935d97d285212c50bd39f0b08cab7e1fce70522 | |||
v1.0 | complete | Codeforces | Codeforces_13974_C | def get_maximum_subarray_sum(n: int, arr: List[int]) -> int:
"""
You are given a list of positive integers and you need to find the maximum sum of a contiguous subarray.
This is a well-known problem called "Maximum Subarray Problem".
Write a function that takes an array of positive integers as in... | def max_subarray_sum(arr):
"""
Returns the maximum sum of any contiguous subarray within the input array.
Uses Kadane's Algorithm.
"""
max_current = max_global = arr[0]
for i in range(1, len(arr)):
max_current = max(arr[i], max_current + arr[i])
if max_current > max_global:
... | from solution import get_maximum_subarray_sum
def test_example_1():
assert get_maximum_subarray_sum(5, [1, 2, 3, 4, 5]) == 15
def test_example_2():
assert get_maximum_subarray_sum(9, [5, 4, 3, 2, 1, 5, 4, 3, 2]) == 29
def test_single_element():
assert get_maximum_subarray_sum(1, [7]) == 7
def test_two_e... | [
{
"docstring": "Returns the maximum sum of any contiguous subarray within the input array.\nUses Kadane's Algorithm.",
"function_declaration": "def max_subarray_sum(arr):",
"function_name": "max_subarray_sum",
"parameter_list": "(arr)"
},
{
"docstring": null,
"function_declaration": "def... | [
1,
0,
1,
0,
1,
1,
0,
1,
0,
0
] | 5 | medium | 0.5 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def max_subarray_sum(arr):\n \"\"\"\n Returns the maximum sum of any contiguous subarray within the input array.\n \n Parameters:\n arr (list):... | trial_gpt4o_7 | {
"original_instruction": "You are given a list of positive integers and you need to find the maximum sum of a contiguous subarray. This is a well-known problem called \"Maximum Subarray Problem\".\n\nWrite a function that takes an array of positive integers as input and returns the maximum sum of any contiguous suba... | 0.786635 | Codeforces_13974 | C | [
"max_subarray_sum",
"get_maximum_subarray_sum"
] | 2 | [
[
"get_maximum_subarray_sum",
"max_subarray_sum"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | d39964f237e02526fc3bb64c03462a7182cf883f | 943dcc2f08e838ccabe8b6fad8eff97eb0e528a4 | |||
v1.0 | complete | Codeforces | Codeforces_13313_C | from typing import List, Tuple
def settle_expenses(transactions: List[Tuple[int, float, int]]) -> int:
"""
A group of friends are planning a vacation trip together and they have decided to split the expenses equally among all.
Each friend will keep receipts of their payments and at the end of the trip, t... | from collections import defaultdict
def settle_expenses(transactions):
balance = defaultdict(float)
for payer, amount, recipient in transactions:
balance[payer] -= amount
balance[recipient] += amount
debts = list(balance.values())
return settle(debts, 0)
def settle(debts, ind... | from solution import settle_expenses
def test_settle_expenses_simple_case():
transactions = [
(1, 100.0, 2),
(2, 50.0, 3),
(3, 50.0, 1)
]
assert settle_expenses(transactions) == 1
def test_settle_expenses_multiple_transactions():
transactions = [
(1, 100.0, 2),
... | [
{
"docstring": null,
"function_declaration": "def settle_expenses(transactions):",
"function_name": "settle_expenses",
"parameter_list": "(transactions)"
},
{
"docstring": null,
"function_declaration": "def settle(debts, index):",
"function_name": "settle",
"parameter_list": "(de... | [
0,
0,
0,
1,
0,
0,
0,
0,
0,
0
] | 1 | hard | 0.1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def settle_expenses(transactions):\n from collections import defaultdict\n balance = defaultdict(float)\n\n # Calculate the net balance of each perso... | trial_gpt4o_3 | {
"original_instruction": "A group of friends are planning a vacation trip together and they have decided to split the expenses equally among all. Each friend will keep receipts of their payments and at the end of the trip, they will settle the expenses so that everyone ends up paying the same amount.\n\nWrite a func... | 0.543725 | Codeforces_13313 | C | [
"settle_expenses",
"settle"
] | 2 | [
[
"settle_expenses",
"settle"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | a6074e3b85549817a4da086cdd746a5d1aca3b21 | 8d5a0d5e8775391592999ad046e1dba9f579c5ad | |||
v1.0 | complete | Codeforces | Codeforces_14044_C | def unique_paths_with_obstacles(grid: List[List[int]]) -> int:
"""Given a grid indicating obstacles (1) and free spaces (0), this function calculates the number of
unique paths from the top-left corner to the bottom-right corner, moving only right or down.
>>> unique_paths_with_obstacles([[0, 0, 0], [... | def unique_paths_with_obstacles(grid):
"""
Given a grid indicating obstacles (1) and free spaces (0), this function calculates the number of
unique paths from the top-left corner to the bottom-right corner, moving only right or down.
"""
if not grid or grid[0][0] == 1:
return 0
m, n = ... | from solution import unique_paths_with_obstacles, solve
def test_unique_paths_with_obstacles():
assert unique_paths_with_obstacles([[0, 0, 0], [0, 1, 0], [0, 0, 0]]) == 2
assert unique_paths_with_obstacles([[0, 1], [0, 0]]) == 1
assert unique_paths_with_obstacles([[1, 0], [0, 0]]) == 0
assert unique_pa... | [
{
"docstring": "Given a grid indicating obstacles (1) and free spaces (0), this function calculates the number of \nunique paths from the top-left corner to the bottom-right corner, moving only right or down.",
"function_declaration": "def unique_paths_with_obstacles(grid):",
"function_name": "unique_pa... | [
0,
0,
1,
1,
1,
0,
0,
1,
1,
1
] | 6 | medium | 0.6 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def unique_paths_with_obstacles(grid):\n \"\"\"\n Returns the number of unique paths from the top-left to bottom-right of a grid with obstacles.\n \"... | trial_gpt4o_9 | {
"original_instruction": "Ninja Turtle Leonardo is training in a grid town. The town is represented by an m x n grid, where some cells contain obstacles. Leonardo can only move right or down to reach the bottom-right cell of the grid. Determine the number of unique paths Leonardo can take to move from the top-left c... | 0.67278 | Codeforces_14044 | C | [
"unique_paths_with_obstacles",
"solve"
] | 2 | [
[
"solve",
"unique_paths_with_obstacles"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | e9cc02b360c30f6a198191008b5b0ba18873b3c0 | db28bd52d2616b7bc8c88f6299bfa8615a31edf9 | |||
v1.0 | complete | Codeforces | Codeforces_13816_C | def is_prime(num: int) -> bool:
"""
Helper function to check if a number is prime.
Returns True if num is prime, else False.
>>> is_prime(2)
True
>>> is_prime(3)
True
>>> is_prime(4)
False
>>> is_prime(29)
True
>>> is_prime(1)
False
"""
def highest_prime(n: int):... | def is_prime(num):
"""
Helper function to check if a number is prime.
Returns True if num is prime, else False.
"""
if num <= 1:
return False
if num == 2:
return True
if num % 2 == 0:
return False
for i in range(3, int(num ** 0.5) + 1, 2):
if num % i == 0:... | from solution import is_prime, highest_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(1) == False
def test_highest_prime():
assert highest_prime(10) == 7
assert highest_prime(29) == 29... | [
{
"docstring": "Helper function to check if a number is prime.\nReturns True if num is prime, else False.",
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": "Returns the highest prime number less than or equal to n.\nIf no... | [
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] | 10 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def find_highest_prime(n):\n \"\"\"\n Returns the highest prime number less than or equal to n.\n If no prime number is found, returns \"No prime num... | trial_gpt4o_1 | {
"original_instruction": "Jessica loves to collect prime numbers and she has recently encountered a fascinating problem. She wants to find the highest prime number less than or equal to a given number n. Could you help her accomplish this task?\n\nThe input consists of a single integer n ($$1 \\leq n \\leq 10^7$$). ... | 0.833211 | Codeforces_13816 | C | [
"is_prime",
"highest_prime"
] | 2 | [
[
"highest_prime",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 6b4e8d3b4903f9d5dd2accd7a22b84d0a4fe6b7d | 2869314370b483ae0e9e4db174b742aa9c55a8b2 | |||
v1.0 | complete | Codeforces | Codeforces_13565_C | def validate_painting(n: int, m: int, cells: List[Tuple[int, int, int]]) -> str:
""" Determine if it is possible to paint the entire grid following the painting robot’s rules.
Args:
n : int : Dimension of the grid (n x n)
m : int : Number of initially painted cells
cells : List[Tuple[int, int, ... | def is_valid_painting(n, m, painted_cells):
from collections import defaultdict
grid = [[0] * n for _ in range(n)]
for cell in painted_cells:
r, c, col = cell
grid[r - 1][c - 1] = col
def is_valid(x, y, col):
for dx, dy in [(-1, 0), (1, 0), (0, -1), (0, 1)]:
nx, ny ... | from solution import validate_painting
def test_validate_painting():
assert validate_painting(5, 2, [(1, 1, 1), (3, 3, 2)]) == "YES"
assert validate_painting(5, 2, [(1, 1, 1), (1, 2, 1)]) == "NO"
assert validate_painting(5, 3, [(1, 1, 1), (1, 2, 2), (1, 3, 1)]) == "YES"
assert validate_painting(3, 1, [... | [
{
"docstring": null,
"function_declaration": "def is_valid_painting(n, m, painted_cells):",
"function_name": "is_valid_painting",
"parameter_list": "(n, m, painted_cells)"
},
{
"docstring": null,
"function_declaration": "def validate_painting(n, m, cells):",
"function_name": "validat... | [
0,
1,
0,
1,
1,
0,
0,
0,
0
] | 3 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_possible_to_paint(n, m, painted_cells):\n from collections import defaultdict\n \n neighbor_offsets = [(-1, 0), (1, 0), (0, -1), (0, 1)]\n ... | trial_gpt4o_5 | {
"original_instruction": "You are working on an automated painting robot that operates on a large square grid with dimensions n x n. Each cell in the grid is initially unpainted (color code 0). The robot can paint each cell with a color c (1 ≤ c ≤ 100). However, the robot's painting capabilities are limited by a set... | 0.53354 | Codeforces_13565 | C | [
"is_valid_painting",
"validate_painting"
] | 2 | [
[
"validate_painting",
"is_valid_painting"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 11693dc88bc69cef965512dfe20616481ef9482a | 5ac039f94303db05b9ede75eb5ec36ffd48c86a0 | |||
v1.0 | complete | Codeforces | Codeforces_13980_C | def is_prime(num):
""" Determines if a number is a prime number. """
pass
def can_partition(arr, n, m):
""" Determines if the array can be partitioned into exactly m non-empty contiguous subarrays
such that the sum of elements in each subarray is a prime number. """
pass
def solve(test_cases):
... | 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 can_partition(arr, n, m):
... | from solution import solve, from_input_string
def test_example_1():
input_data = '''2
5 3
2 3 5 7 11
6 2
1 4 5 -3 6 8'''
test_cases = from_input_string(input_data)
assert solve(test_cases) == ["YES", "NO"]
def test_case_all_positive_primes():
input_data = '''1
5 2
2 7 3 11 17'''
test_cases = from_... | [
{
"docstring": null,
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": null,
"function_declaration": "def can_partition(arr, n, m):",
"function_name": "can_partition",
"parameter_list": "(arr, n, m)"
},
{
... | [
0,
0,
0,
0,
0,
1,
0,
0,
1,
0
] | 2 | hard | 0.2 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from itertools import accumulate\n\ndef is_prime(num):\n if num < 2:\n return False\n for i in range(2, int(num**0.5) + 1):\n if num % i =... | trial_gpt4o_5 | {
"original_instruction": "You are given an integer array `arr` of size `n` and a separate integer `m`. Your task is to find if it is possible to partition the array into exactly `m` non-empty contiguous subarrays such that the sum of elements in each subarray is a prime number. If such a partition is possible, print... | 0.651211 | Codeforces_13980 | C | [
"is_prime",
"can_partition",
"solve",
"from_input_string"
] | 4 | [
[
"can_partition",
"is_prime"
],
[
"solve",
"can_partition"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | aa1f5852129b0bc86ef57a14653e69bc919556c4 | 6cd9b19b21b268ef8f9c7f0a575df3f0f313c2d8 | |||
v1.0 | complete | Codeforces | Codeforces_14154_C | from typing import List, Tuple
def minimum_weight_to_connect_graph(n: int, m: int, edges: List[Tuple[int, int, int]]) -> int:
""" Find the minimum weight required to make an undirected graph connected.
Parameters:
n (int): The number of vertices.
m (int): The number of edges.
edges (List[Tuple... | def find(parent, i):
if parent[i] == i:
return i
else:
return find(parent, parent[i])
def union(parent, rank, x, y):
rootX = find(parent, x)
rootY = find(parent, y)
if rank[rootX] < rank[rootY]:
parent[rootX] = rootY
elif rank[rootX] > rank[rootY]:
parent[rootY]... | def test_example_1():
n, m = 4, 5
edges = [
(1, 2, 1),
(2, 3, 3),
(3, 4, 4),
(1, 4, 5),
(2, 4, 2)
]
assert solve(n, m, edges) == 6
def test_example_2():
n, m = 3, 1
edges = [
(1, 2, 2)
]
assert solve(n, m, edges) == -1
def test_smallest_i... | [
{
"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,
0,
0,
0,
1,
0,
1,
1
] | 4 | medium | 0.4 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl",
"solution_code": "class UnionFind:\n def __init__(self, n):\n self.parent = list(range(n))\n self.rank = [1] * n\n\n def find(self, u):\n if self.par... | trial_gpt4o_2 | {
"original_instruction": "You are given an undirected graph with `n` vertices and `m` edges. Each edge has a positive integer weight. Your task is to find the minimum weight required to make the graph connected.\n\nThe first line contains two integers `n` and `m` (`1 \\leq n, m \\leq 100,000`), the number of vertice... | 0.717554 | Codeforces_14154 | C | [
"find",
"union",
"minimum_weight_to_connect_graph",
"solve"
] | 4 | [
[
"minimum_weight_to_connect_graph",
"find"
],
[
"minimum_weight_to_connect_graph",
"union"
],
[
"solve",
"minimum_weight_to_connect_graph"
],
[
"union",
"find"
]
] | 4 | [] | false | [] | false | pytest | false | [] | true | 00e95f0a440510573b4872eece56ffe8ee6bc881 | 441b38234aae5a1743df4c94b94be9c39cb58c03 | |||
v1.0 | complete | Codeforces | Codeforces_13280_C | from typing import List, Tuple
def find_optimal_commander_position(x: List[int]) -> float:
"""
Finds the optimal position for a commander to minimize the total distance
to their warriors. The optimal position lies at the median of the coordinates
of the warriors.
"""
# Implementation here
def ... | def find_optimal_commander_position(x):
"""
Finds the optimal position for a commander to minimize the total distance
to their warriors. The optimal position lies at the median of the coordinates
of the warriors.
"""
x.sort()
n = len(x)
if n % 2 == 1:
return float(x[n // 2])
... | from solution import find_optimal_commander_position, optimal_commander_positions
def test_find_optimal_commander_position_single_element():
assert find_optimal_commander_position([5]) == 5.0
def test_find_optimal_commander_position_two_elements():
assert find_optimal_commander_position([1, 3]) == 2.0
def te... | [
{
"docstring": "Finds the optimal position for a commander to minimize the total distance\nto their warriors. The optimal position lies at the median of the coordinates\nof the warriors.",
"function_declaration": "def find_optimal_commander_position(x):",
"function_name": "find_optimal_commander_positio... | [
1,
1,
1,
1,
1,
0,
1,
0,
1
] | 7 | easy | 0.778 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def optimal_commander_positions(n, m, warriors1, warriors2):\n \"\"\"\n Compute optimal commander positions for two groups of warriors.\n \n Args:... | trial_gpt4o_9 | {
"original_instruction": "In a magical land, there are two groups of warriors. Each group is led by a commander. Each warrior is positioned at distinct integer coordinates along the x-axis, and each commander is positioned at a unique, but not necessarily integer, coordinate on the x-axis. The goal of each commander... | 0.582038 | Codeforces_13280 | C | [
"find_optimal_commander_position",
"optimal_commander_positions"
] | 2 | [
[
"optimal_commander_positions",
"find_optimal_commander_position"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 8749c874522fd7ed768e4662043be014b07f01ac | f15ec49cfdd03a90f72b54a0e02f21f64af389d4 | |||
v1.0 | complete | Codeforces | Codeforces_14397_C | def solution(s: str) -> str:
""" Determines if the string can become a palindrome by removing at most one character.
>>> solution("abca") == "YES"
>>> solution("abcba") == "YES"
>>> solution("abcdef") == "NO"
>>> solution("a") == "YES"
>>> solution("aa") == "YES"
>>> solution("ab") == "YES"
... | def can_become_palindrome(s):
"""
Check if the string can become a palindrome by removing at most one character.
"""
def is_palindrome_range(i, j):
return all(s[k] == s[j - k + i] for k in range(i, j))
l, r = 0, len(s) - 1
while l < r:
if s[l] != s[r]:
return is_... | from solution import solution
def test_example_1():
assert solution("abca") == "YES"
def test_example_2():
assert solution("abcba") == "YES"
def test_example_3():
assert solution("abcdef") == "NO"
def test_single_char():
assert solution("a") == "YES"
def test_two_same_chars():
assert solution("... | [
{
"docstring": "Check if the string can become a palindrome by removing at most one character.",
"function_declaration": "def can_become_palindrome(s):",
"function_name": "can_become_palindrome",
"parameter_list": "(s)"
},
{
"docstring": "Determines if the string can become a palindrome by r... | [
0,
1,
0,
0,
0,
1,
1,
1,
1,
1
] | 6 | medium | 0.6 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def can_become_palindrome(s):\n \"\"\"\n Determines if a string can become a palindrome by removing at most one character.\n \n Parameters:\n s... | trial_gpt4o_8 | {
"original_instruction": "You are given a string consisting of lowercase letters. Your task is to check if the string is a palindrome after removing at most one character.\n\nA palindrome is a word that reads the same backward as forward, such as \"madam\" or \"racecar\". You need to determine if the given string ca... | 0.785676 | Codeforces_14397 | C | [
"can_become_palindrome",
"solution"
] | 2 | [
[
"solution",
"can_become_palindrome"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | ab8365167aa8e8a4e1f7ffe6e4ccd36495873624 | b884a5a6a8674d7dab2e2dbb6c8e85a8829c098f | |||
v1.0 | complete | Codeforces | Codeforces_13900_C | def most_frequent_pair(transactions):
""" Find the most frequently purchased pair of items from a list of transactions.
Each transaction is represented by a list of item IDs bought together.
Return the pair of item IDs that appear together most frequently.
If multiple pairs have the same frequency, ret... | from collections import defaultdict
from itertools import combinations
def most_frequent_pair(transactions):
pair_count = defaultdict(int)
for transaction in transactions:
pairs = combinations(sorted(transaction), 2)
for pair in pairs:
pair_count[pair] += 1
most_frequent =... | from solution import solution
def test_example_case():
input_str = "5\n1 2 3\n2 3 4\n1 2\n1 3\n2 3"
expected_output = "2 3"
assert solution(input_str) == expected_output
def test_lexicographic_order():
input_str = "3\n1 2\n2 3\n3 1"
expected_output = "1 2"
assert solution(input_str) == expecte... | [
{
"docstring": null,
"function_declaration": "def most_frequent_pair(transactions):",
"function_name": "most_frequent_pair",
"parameter_list": "(transactions)"
},
{
"docstring": null,
"function_declaration": "def input_parser(input_str):",
"function_name": "input_parser",
"parame... | [
1,
1,
0,
1,
1,
0,
1,
0,
1,
0
] | 6 | medium | 0.6 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from collections import defaultdict\nfrom itertools import combinations\n\ndef most_frequent_pair(transactions):\n \"\"\"\n Given a list of transactions... | trial_gpt4o_8 | {
"original_instruction": "An online store wants to analyze its customers' buying patterns to provide better recommendations. Given a list of transactions, where each transaction is represented by a list of items bought together, help the store identify the most frequently purchased pair of items.\n\nThe first line o... | 0.558074 | Codeforces_13900 | C | [
"most_frequent_pair",
"input_parser",
"solution"
] | 3 | [
[
"solution",
"input_parser"
],
[
"solution",
"most_frequent_pair"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 1ae28b58fb77fe0fe100225a514698153d8cd0ec | 22fca3c81215ed7d6d00d19ea5084aa7a9e33cb2 | |||
v1.0 | complete | Codeforces | Codeforces_14370_C | def is_prime(num):
"""
Checks if a number is prime.
>>> is_prime(2) True
>>> is_prime(3) True
>>> is_prime(4) False
>>> is_prime(5) True
>>> is_prime(10) False
"""
def smallest_prime_reordering(n):
"""
Returns the lexicographically smallest permutation of the digits of n that is... | from itertools import permutations
def is_prime(num):
"""
Checks if a number is prime.
"""
if num <= 1:
return False
if num <= 3:
return True
if num % 2 == 0 or num % 3 == 0:
return False
i = 5
while i * i <= num:
if num % i == 0 or num % (i + 2) == 0:
... | from solution import is_prime, smallest_prime_reordering, 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(5) == True
assert is_prime(10) == False
def test_smallest_prime_reordering():
assert smallest_prim... | [
{
"docstring": "Checks if a number is prime.",
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": "Returns the lexicographically smallest permutation of the digits of n that is a prime number.\nIf no such permutation exists,... | [
0,
0,
1,
0,
1,
0,
0,
0,
0,
0
] | 2 | hard | 0.2 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from itertools import permutations\n\ndef is_prime(num):\n if num <= 1:\n return False\n if num <= 3:\n return True\n if num % 2 == 0 o... | trial_gpt4o_4 | {
"original_instruction": "You are given a list of integers. Your task is to reorder the list such that the digits of each number are sorted in non-descending order and the number itself is prime. If there are multiple re-orderings possible that satisfy this condition, print the lexicographically smallest arrangement... | 0.758733 | Codeforces_14370 | C | [
"is_prime",
"smallest_prime_reordering",
"process_test_cases"
] | 3 | [
[
"process_test_cases",
"smallest_prime_reordering"
],
[
"smallest_prime_reordering",
"is_prime"
]
] | 2 | [
"process_test_cases"
] | false | [] | false | pytest | true | [] | true | 77265eb186bbb027310a1e4018147ab708b3235c | 0cd836f9d52c5455868efa488f0b89baf1c0f272 | |||
v1.0 | complete | Codeforces | Codeforces_14114_C | def can_arrange_paintings(n: int, m: int, restrictions: List[Tuple[int, int]]) -> Tuple[str, List[int]]:
""" Determine if it's possible to arrange all the paintings such that none of the given pairs are adjacent.
>>> can_arrange_paintings(4, 2, [(1, 2), (3, 4)]) == ("YES", [1, 3, 2, 4]) or can_arrange_paintings... | def can_arrange_paintings(n, m, restrictions):
import itertools
# Generate all possible arrangements
arrangements = itertools.permutations(range(1, n + 1))
# Convert restrictions list to a set of tuples for quick lookup
restriction_set = {tuple(sorted(pair)) for pair in restrictions}
for arra... | from solution import can_arrange_paintings, solve
def test_can_arrange_paintings_sample1():
n = 4
m = 2
restrictions = [(1, 2), (3, 4)]
assert solve(n, m, restrictions) == "YES\n1 3 2 4" or solve(n, m, restrictions) == "YES\n3 1 4 2"
def test_can_arrange_paintings_sample2():
n = 3
m = 3
re... | [
{
"docstring": null,
"function_declaration": "def can_arrange_paintings(n, m, restrictions):",
"function_name": "can_arrange_paintings",
"parameter_list": "(n, m, restrictions)"
},
{
"docstring": null,
"function_declaration": "def solve(n, m, restrictions):",
"function_name": "solve"... | [
1,
1,
1,
0,
1,
0,
1,
1,
0,
0
] | 6 | medium | 0.6 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def can_arrange_paintings(n, m, pairs):\n import itertools\n\n if n == 1:\n # If there's only one painting, it's trivially possible to display it... | trial_gpt4o_7 | {
"original_instruction": "You have been tasked with organizing a series of fine art paintings at a gallery. There are n paintings, each with a unique tag number. The gallery wants to ensure that a certain display constraint is met. Specifically, no two paintings with consecutive tag numbers can be placed next to eac... | 0.612879 | Codeforces_14114 | C | [
"can_arrange_paintings",
"solve"
] | 2 | [
[
"solve",
"can_arrange_paintings"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 7da8e4674eb2112f109b447d78997f5d4b971055 | 6f3699543cecab9fea331b3c90a9aefcc17d71a5 | |||
v1.0 | complete | Codeforces | Codeforces_14419_C | def is_prime(n):
"""Check if a number is prime."""
pass
def find_smallest_prime_gte(x):
"""Find the smallest prime number greater than or equal to x."""
pass
def smallest_prime_greater_equal(test_cases):
"""
Given a list of integers, returns a list of the smallest prime numbers
greater tha... | def is_prime(n):
"""Check if a number is prime."""
if n <= 1:
return False
if n <= 3:
return True
if n % 2 == 0 or n % 3 == 0:
return False
i = 5
while i * i <= n:
if n % i == 0 or n % (i + 2) == 0:
return False
i += 6
return True
def find... | import pytest
from solution import smallest_prime_greater_equal
def test_example_case():
test_cases = [10, 14, 20]
expected = [11, 17, 23]
assert smallest_prime_greater_equal(test_cases) == expected
def test_single_prime_case():
test_cases = [29]
expected = [29]
assert smallest_prime_greater_e... | [
{
"docstring": "Check if a number is prime.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Find the smallest prime number greater than or equal to x.",
"function_declaration": "def find_smallest_prime_gte(x):",
"f... | [
1,
1,
1,
1,
1,
1,
1,
1,
1,
0
] | 9 | easy | 0.9 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(n):\n \"\"\"\n Check if the given number `n` is prime.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return Tr... | trial_gpt4o_7 | {
"original_instruction": "Polycarp is a programmer who loves prime numbers. Recently, he encountered a problem where he needs to find out the smallest prime number which is greater than or equal to a given integer.\n\nHelp Polycarp solve this problem efficiently as he might need to perform this operation multiple ti... | 0.768208 | Codeforces_14419 | C | [
"is_prime",
"find_smallest_prime_gte",
"smallest_prime_greater_equal"
] | 3 | [
[
"find_smallest_prime_gte",
"is_prime"
],
[
"smallest_prime_greater_equal",
"find_smallest_prime_gte"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 8abbf35ec03a7616431b4026fefadf8309d24028 | 38965ae3c15d61eb9f7c0f54d38680902e06fd87 | |||
v1.0 | complete | Codeforces | Codeforces_13717_C | def is_prime(n: int) -> bool:
""" Check if a number is prime.
>>> is_prime(2)
True
>>> is_prime(4)
False
"""
pass
def preprocess_prime_count(grid: List[List[int]], M: int, N: int) -> List[List[int]]:
""" Preprocess the grid to count prime numbers.
Args:
grid: the 2D list of int... | def is_prime(n):
if n <= 1:
return False
if n <= 3:
return True
if n % 2 == 0 or n % 3 == 0:
return False
i = 5
while i * i <= n:
if n % i == 0 or n % (i + 2) == 0:
return False
i += 6
return True
def preprocess_prime_count(grid, M, N):
pr... | import pytest
from solution import is_prime, preprocess_prime_count, query_prime_count
def test_is_prime():
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(4) == False
assert is_prime(11) == True
assert is_prime(1) == False
assert is_prime(0) == False
assert is_prime(5... | [
{
"docstring": null,
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": null,
"function_declaration": "def preprocess_prime_count(grid, M, N):",
"function_name": "preprocess_prime_count",
"parameter_list": "(grid, M,... | [
0,
1,
1,
0,
0,
0,
0,
0,
0
] | 2 | hard | 0.222 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(num):\n if num <= 1:\n return False\n if num <= 3:\n return True\n if num % 2 == 0 or num % 3 == 0:\n return False\... | trial_gpt4o_2 | {
"original_instruction": "The land of CodeLand is structured as a grid with dimensions M x N. The citizens of CodeLand are very interested in finding prime numbers within various subgrids of this large grid. They have chosen you to write a program that can count the number of prime numbers in any subgrid quickly.\n\... | 0.702892 | Codeforces_13717 | C | [
"is_prime",
"preprocess_prime_count",
"query_prime_count"
] | 3 | [
[
"preprocess_prime_count",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 5c950bb0ca3e824d4b5a1d981b6e067ef7734e37 | c9f7f1f4d1f1392287d6bc04cd9737d640966869 | |||
v1.0 | complete | Codeforces | Codeforces_14349_C | from typing import List
class TreeNode:
def __init__(self, val=0, left=None, right=None):
self.val = val
self.left = left
self.right = right
def build_tree(nums: List[int]) -> TreeNode:
'''
Builds a binary tree from a list of numbers using the maximum value as the root of the subtr... | from typing import List
class TreeNode:
def __init__(self, val=0, left=None, right=None):
self.val = val
self.left = left
self.right = right
def build_tree(nums: List[int]) -> TreeNode:
if not nums:
return None
max_val = max(nums)
max_index = nums.index(max_val)
... | from solution import inorder_traversal
def test_inorder_traversal_example_case():
assert inorder_traversal([3, 2, 1, 6, 0, 5]) == [3, 2, 1, 6, 0, 5]
def test_inorder_traversal_single_element():
assert inorder_traversal([42]) == [42]
def test_inorder_traversal_sorted_increasing():
assert inorder_traversal... | [] | [
0,
0,
0,
0,
1,
0,
0,
1,
0,
0
] | 2 | hard | 0.2 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl",
"solution_code": "class TreeNode:\n def __init__(self, val=0, left=None, right=None):\n self.val = val\n self.left = left\n self.right = right\n\n\ndef ... | trial_gpt4o_7 | {
"original_instruction": "Michael is building a binary tree from a given array of integers. The tree is constructed using the following algorithm:\n\n1. If the array is empty, return null.\n2. Find the maximum value in the array and use it as the root of the tree or subtree.\n3. Recursively apply the same steps to t... | 0.552561 | Codeforces_14349 | C | [
"build_tree",
"inorder_traversal"
] | 2 | [
[
"inorder_traversal",
"build_tree"
]
] | 1 | [] | false | [
"TreeNode"
] | true | pytest | true | [] | true | c89a808dac96a88eebdf4d9c0c7bfeb441fbaa26 | b67851882892a6d223189e369e48c9a9d2ea5ab7 | |||
v1.0 | complete | Codeforces | Codeforces_14713_C | from typing import List, Tuple
import sys
from collections import defaultdict
def find_max_inconvenience(n: int, roads: List[Tuple[int, int, int]]) -> int:
""" Determines the maximum inconvenience (length of the longest road on any path) over all pairs of cities.
Args:
n: Integer, number of cities.
... | import sys
from collections import defaultdict
def dfs(u, parent, graph, max_edge, max_inconvenience):
for v, w in graph[u]:
if v == parent:
continue
max_edge[v] = max(max_edge[u], w)
max_inconvenience[0] = max(max_inconvenience[0], max_edge[v])
dfs(v, u, graph, max_edge... | from solution import find_max_inconvenience
def test_example_case():
assert find_max_inconvenience(5, [(1, 2, 3), (1, 3, 2), (3, 4, 4), (3, 5, 1)]) == 4
def test_small_tree():
assert find_max_inconvenience(2, [(1, 2, 10)]) == 10
def test_star_shape_tree():
assert find_max_inconvenience(4, [(1, 2, 7), (1,... | [
{
"docstring": null,
"function_declaration": "def dfs(u, parent, graph, max_edge, max_inconvenience):",
"function_name": "dfs",
"parameter_list": "(u, parent, graph, max_edge, max_inconvenience)"
},
{
"docstring": null,
"function_declaration": "def find_max_inconvenience(n, roads):",
... | [
1,
0,
1,
0,
0,
1,
0,
1,
0,
1
] | 5 | medium | 0.5 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import sys\nfrom collections import defaultdict\n\ndef max_inconvenience(n, roads):\n graph = defaultdict(list)\n for u, v, w in roads:\n graph[u... | trial_gpt4o_2 | {
"original_instruction": "**Problem Statement:**\n\nThe kingdom of Numeria has a peculiar road system consisting of straight roads connecting various cities. The road network is represented as a tree (a connected graph with no cycles), with cities as nodes and roads as edges. Each road has a certain distance.\n\nDue... | 0.653788 | Codeforces_14713 | C | [
"dfs",
"find_max_inconvenience"
] | 2 | [
[
"find_max_inconvenience",
"dfs"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 92fce94f8861371aa70b54a405e85680cf21610a | d25230136842b575bd67c7d13b4499e8a2c31cc4 | |||
v1.0 | complete | Codeforces | Codeforces_14424_C | def train_model(training_data_directory: str):
"""
Function to preprocess and train the model.
Args:
- training_data_directory (str): The directory containing the training data
Returns:
- model: The trained model
"""
pass
def load_model():
"""
Load the trained model from the di... | import os
from sklearn.feature_extraction.text import TfidfVectorizer
from sklearn.naive_bayes import MultinomialNB
from sklearn.pipeline import make_pipeline
import joblib
# Function to load training data
def load_training_data(directory):
texts = []
labels = []
for category in range(1, 5):
catego... | from solution import train_model, predict_category
import os
import pytest
@pytest.fixture(scope='module')
def setup_training_model():
# We assume the training data is in './category_training' directory
training_data_directory = './category_training'
if not os.path.exists(training_data_directory):
... | [
{
"docstring": null,
"function_declaration": "def load_training_data(directory):",
"function_name": "load_training_data",
"parameter_list": "(directory)"
},
{
"docstring": null,
"function_declaration": "def train_model(training_data_directory):",
"function_name": "train_model",
"... | [
0,
0,
0,
0,
0,
0,
0,
0,
1,
0
] | 1 | hard | 0.1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import os\nimport string\nimport numpy as np\nfrom sklearn.feature_extraction.text import TfidfVectorizer\nfrom sklearn.naive_bayes import MultinomialNB\nfrom... | trial_gpt4o_8 | {
"original_instruction": "You are given a set of articles from different news categories. Each article has a category, identified by an integer from 1 to 4. Your task is to write a program that takes as input the text of an article and predicts its category.\n\nCategories:\n1. Sports\n2. Politics\n3. Technology\n4. ... | 0.586379 | Codeforces_14424 | C | [
"load_training_data",
"train_model",
"load_model",
"predict_category"
] | 4 | [
[
"predict_category",
"load_model"
],
[
"train_model",
"load_training_data"
]
] | 2 | [] | false | [] | false | pytest | true | [
"joblib",
"sklearn"
] | false | 2bcc3f79922455cd83616cd69465162cf06d2dda | c823ececf2c9151c621af68502f503bbcfb12140 | |||
v1.0 | complete | Codeforces | Codeforces_14090_C | def add_item(inventory, ID, count):
"""Adds the item with the given identifier and the count to the inventory.
Args:
inventory: dict, the current inventory.
ID: str, the unique identifier of the item.
count: int, the number of units to add.
"""
pass
def remove_item(inventory, ID, count... | def add_item(inventory, ID, count):
if ID in inventory:
inventory[ID] += count
else:
inventory[ID] = count
def remove_item(inventory, ID, count):
if ID in inventory:
inventory[ID] -= count
if inventory[ID] <= 0:
del inventory[ID]
def check_item(inventory, ID):
... | from solution import add_item, remove_item, check_item, list_items, manage_inventory
def test_add_item():
inventory = {}
add_item(inventory, "A123", 10)
assert inventory == {"A123": 10}
add_item(inventory, "A123", 5)
assert inventory == {"A123": 15}
def test_remove_item():
inventory = {"A123"... | [
{
"docstring": null,
"function_declaration": "def add_item(inventory, ID, count):",
"function_name": "add_item",
"parameter_list": "(inventory, ID, count)"
},
{
"docstring": null,
"function_declaration": "def remove_item(inventory, ID, count):",
"function_name": "remove_item",
"p... | [
1,
0,
0,
1,
0,
1,
0,
1,
1,
1
] | 6 | medium | 0.6 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl",
"solution_code": "class WarehouseInventory:\n def __init__(self):\n self.inventory = {}\n\n def add_item(self, ID, count):\n if ID in self.inventory:\n ... | trial_gpt4o_9 | {
"original_instruction": "A large warehouse needs to keep track of its inventory. Each item in the inventory is represented by a unique identifier and a count of the available units. The warehouse manager wants a program that can manage the inventory efficiently. \n\nThe program should support the following operatio... | 0.489134 | Codeforces_14090 | C | [
"add_item",
"remove_item",
"check_item",
"list_items",
"manage_inventory"
] | 5 | [
[
"manage_inventory",
"add_item"
],
[
"manage_inventory",
"check_item"
],
[
"manage_inventory",
"list_items"
],
[
"manage_inventory",
"remove_item"
]
] | 4 | [] | false | [] | false | pytest | true | [] | true | fcbaffbe677cca27464d592d778eb94b8bc780df | 77aa1488cd2cb293573ae60773f143aca3162490 | |||
v1.0 | complete | Codeforces | Codeforces_14015_C | class TreeNode:
def __init__(self, val=0, left=None, right=None):
self.val = val
self.left = left
self.right = right
def construct_tree(arr):
if not arr:
return None
nodes = []
for val in arr:
if val is not None:
nodes.append(TreeNode(val))
e... | class TreeNode:
def __init__(self, val=0, left=None, right=None):
self.val = val
self.left = left
self.right = right
def construct_tree(arr):
if not arr:
return None
nodes = []
for val in arr:
if val is not None:
nodes.append(TreeNode(val))
e... | from solution import validate_bst
def test_example_1():
n = 7
arr = [2, 1, 3, None, None, None, None]
assert validate_bst(n, arr) == True
def test_example_2():
n = 7
arr = [5, 1, 4, None, None, 3, 6]
assert validate_bst(n, arr) == False
def test_empty_tree():
n = 0
arr = []
assert... | [] | [
0,
0,
1,
0,
1,
1,
1,
0,
1,
1
] | 6 | medium | 0.6 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from typing import List, Optional\n\n# Definition for a binary tree node.\nclass TreeNode:\n def __init__(self, x):\n self.val = x\n self.lef... | trial_gpt4o_8 | {
"original_instruction": "Given a binary tree, you need to find out whether it is a valid Binary Search Tree (BST). A valid BST is defined as follows:\n- The left subtree of a node contains only nodes with keys less than the node's key.\n- The right subtree of a node contains only nodes with keys greater than the no... | 0.624484 | Codeforces_14015 | C | [
"construct_tree",
"is_valid_bst",
"validate_bst"
] | 3 | [
[
"validate_bst",
"construct_tree"
],
[
"validate_bst",
"is_valid_bst"
]
] | 2 | [] | false | [
"TreeNode"
] | true | pytest | true | [] | true | 82a00041b56ee819b29f9cf7734c5e6dd27a4650 | d2b7233933cc93c038c9125fc15036aed0aee945 | |||
v1.0 | complete | Codeforces | Codeforces_14751_C | from math import factorial
from functools import lru_cache
@lru_cache(None)
def stirling_second_kind(n, k):
"""
Returns the Stirling number of the second kind
S(n, k) which is the number of ways to partition
a set of n objects into k non-empty subsets.
"""
def distinct_ways_to_distribute_balls(n, ... | from math import factorial
from functools import lru_cache
@lru_cache(None)
def stirling_second_kind(n, k):
"""
Returns the Stirling number of the second kind
S(n, k) which is the number of ways to partition
a set of n objects into k non-empty subsets.
"""
if n == k:
return 1
if k =... | from solution import distinct_ways_to_distribute_balls
def test_example_case():
assert distinct_ways_to_distribute_balls(3, 2) == 6
def test_minimum_input():
assert distinct_ways_to_distribute_balls(1, 1) == 1
def test_all_balls_to_one_friend():
assert distinct_ways_to_distribute_balls(4, 1) == 1
def te... | [
{
"docstring": "Returns the Stirling number of the second kind\nS(n, k) which is the number of ways to partition\na set of n objects into k non-empty subsets.",
"function_declaration": "def stirling_second_kind(n, k):",
"function_name": "stirling_second_kind",
"parameter_list": "(n, k)"
},
{
... | [
0,
0,
0,
0,
1,
0,
0,
1,
0,
0
] | 2 | hard | 0.2 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from math import factorial\n\ndef stirling_second_kind(n, k):\n if k == 0 or k > n:\n return 0\n if k == 1 or k == n:\n return 1\n S = ... | trial_gpt4o_4 | {
"original_instruction": "Vasily is preparing a special surprise for his friend. He has a box with n different colored balls and k unique friends. He wants to distribute all the balls such that each friend gets a distinct subset of balls. Given the number of balls n and the number of friends k, help Vasily determine... | 0.517686 | Codeforces_14751 | C | [
"stirling_second_kind",
"distinct_ways_to_distribute_balls"
] | 2 | [
[
"distinct_ways_to_distribute_balls",
"stirling_second_kind"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 4615890c6eb7a66ff64d928ad076ef4a33805e6a | e19d6437435403173522725e4ee35137ef64822d | |||
v1.0 | complete | Codeforces | Codeforces_14678_C | def max_subarray_sum(arr):
"""
Returns the maximum sum of any non-empty subarray in the input array.
>>> max_subarray_sum([-2, 1, -3, 4, -1, 2, 1, -5, 4]) 6
>>> max_subarray_sum([1, 2, 3, 4, 5]) 15
>>> max_subarray_sum([-1, -2, -3, -4, -5]) -1
""" | def max_subarray_sum(arr):
"""
Returns the maximum sum of any non-empty subarray in the input array.
"""
max_sum = arr[0]
current_sum = arr[0]
for num in arr[1:]:
current_sum = max(num, current_sum + num)
max_sum = max(max_sum, current_sum)
return max_sum
def solve... | from solution import main
def test_example_1():
input_string = "3\n9\n-2 1 -3 4 -1 2 1 -5 4\n5\n1 2 3 4 5\n5\n-1 -2 -3 -4 -5"
expected_output = [6, 15, -1]
assert main(input_string) == expected_output
def test_single_element():
input_string = "2\n1\n5\n1\n-7"
expected_output = [5, -7]
assert m... | [
{
"docstring": "Returns the maximum sum of any non-empty subarray in the input array.",
"function_declaration": "def max_subarray_sum(arr):",
"function_name": "max_subarray_sum",
"parameter_list": "(arr)"
},
{
"docstring": null,
"function_declaration": "def solve(test_cases):",
"func... | [
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] | 10 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def max_subarray_sum(t, test_cases):\n def max_subarray(arr):\n max_ending_here = arr[0]\n max_so_far = arr[0]\n for x in arr[1:]:\n ... | trial_gpt4o_9 | {
"original_instruction": "You are given an array of integers containing both negative and positive values. Your task is to determine the maximum sum of any non-empty subarray. \n\nA subarray is a contiguous part of an array. The possible subarrays of array $$[a_1, a_2, ..., a_n]$$ are $[a_i]$, $[a_i, a_{i+1}]$, ...,... | 0.77296 | Codeforces_14678 | C | [
"max_subarray_sum",
"solve",
"parse_input",
"main"
] | 4 | [
[
"solve",
"max_subarray_sum"
]
] | 1 | [
"parse_input"
] | false | [] | false | pytest | true | [] | true | 3e0f3060c278cd3623f03544fe552ed772a8e8c1 | 09b098ab5f42f1656e024d9eb2306fd93aeccc83 | |||
v1.0 | complete | Codeforces | Codeforces_14493_C | from typing import List
def shortest_path_from_input(n: int, m: int, grid: List[str], sr: int, sc: int, dr: int, dc: int) -> int:
""" Determine the shortest path from the starting position to the destination position in a grid, avoiding obstacles.
>>> shortest_path_from_input(5, 5, [".....", ".###.", "...... | from collections import deque
def shortest_path(grid, sr, sc, dr, dc):
n = len(grid)
m = len(grid[0])
directions = [(-1, 0), (1, 0), (0, -1), (0, 1)] # up, down, left, right
# Initialize the queue with the starting position and distance of 0
queue = deque([(sr, sc, 0)])
visited = set((sr... | from solution import shortest_path_from_input
def test_shortest_path_basic():
grid = [
".....",
".###.",
".....",
".###.",
"....."
]
assert shortest_path_from_input(5, 5, grid, 0, 0, 4, 4) == 8
def test_shortest_path_no_obstacles():
grid = [
".....",
... | [
{
"docstring": null,
"function_declaration": "def shortest_path(grid, sr, sc, dr, dc):",
"function_name": "shortest_path",
"parameter_list": "(grid, sr, sc, dr, dc)"
},
{
"docstring": null,
"function_declaration": "def shortest_path_from_input(n, m, grid, sr, sc, dr, dc):",
"function... | [
0,
0,
0,
0,
0,
0,
0,
1,
1,
0
] | 2 | hard | 0.2 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from collections import deque\n\ndef shortest_path(n, m, grid, sr, sc, dr, dc):\n \"\"\"\n Returns the minimum number of moves the drone needs to reach ... | trial_gpt4o_8 | {
"original_instruction": "Coding an Autonomous Delivery Drone\n\nWith the increasing demand for contactless delivery solutions, an innovative tech company is designing an autonomous delivery drone. The drone operates in a rectangular grid, where each cell is either an open space ('.') or an obstacle ('#'). The drone... | 0.694845 | Codeforces_14493 | C | [
"shortest_path",
"shortest_path_from_input"
] | 2 | [
[
"shortest_path_from_input",
"shortest_path"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 46d382e70f85b40dba4609efbd7e5db62d50c70f | 74d00f867949431c773dd538df4c718a592f6fc8 | |||
v1.0 | complete | Codeforces | Codeforces_14189_C | class TreeNode:
def __init__(self, value):
self.value = value
self.left = None
self.right = None
def build_tree(n, node_vals, edges):
""" Build a binary tree from the given node values and edges.
Args:
n (int): Number of nodes in the binary tree.
node_vals (List[int]): Value... | class TreeNode:
def __init__(self, value):
self.value = value
self.left = None
self.right = None
def build_tree(n, node_vals, edges):
nodes = [TreeNode(value) for value in node_vals]
adj_list = {i: [] for i in range(n)}
for u, v in edges:
adj_list[u-1].append(v-1)
... | from solution import solution
def test_example():
n = 7
node_vals = [3, -1, 4, 2, 5, -3, 2]
edges = [(1, 2), (1, 3), (2, 4), (2, 5), (3, 6), (3, 7)]
assert solution(n, node_vals, edges) == 9
def test_single_node():
n = 1
node_vals = [10]
edges = []
assert solution(n, node_vals, edges) ... | [] | [
0,
0,
0,
0,
0,
0,
1,
0,
0,
0
] | 1 | hard | 0.1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl",
"solution_code": "class TreeNode:\n def __init__(self, value):\n self.value = value\n self.left = None\n self.right = None\n\ndef build_tree(n, values, ... | trial_gpt4o_6 | {
"original_instruction": "You are given a binary tree consisting of $$$n$$$ nodes, numbered from $$$1$$$ to $$$n$$$. Each node has a value associated with it, denoted as $$$a_i$$$. Your goal is to find the sum of values of all nodes that are on the longest path from the root node to any leaf node. If there are multi... | 0.645064 | Codeforces_14189 | C | [
"build_tree",
"sum_of_longest_path",
"solution"
] | 3 | [
[
"solution",
"build_tree"
],
[
"solution",
"sum_of_longest_path"
]
] | 2 | [] | false | [
"TreeNode"
] | true | pytest | true | [] | true | 9eab758d62cf489e4b1c37457acf4beda2e8d11b | e8040ee20c8c59f2dac867392dad4c5fdebb2a5a | |||
v1.0 | complete | Codeforces | Codeforces_14819_C | def best_subscription_plan(n: int, plans_list: List[str]) -> int:
""" Given a number of subscription plans, finds the best plan based on these criteria:
- Discard plans if all features are strictly less than another plan.
- From the remaining plans, choose the one with the highest number of team member acco... | def find_best_plan(plans):
# Filter out plans that are strictly worse than another plan
filtered_plans = []
for i, plan1 in enumerate(plans):
worse = False
for plan2 in plans:
if (plan1 != plan2 and plan1[0] < plan2[0] and plan1[1] < plan2[1] and
... | from solution import best_subscription_plan
def test_single_plan():
plans = ["24 50 5 100"]
assert best_subscription_plan(1, plans) == 1
def test_discard_worse_plan():
plans = [
"24 50 5 100",
"30 100 10 200",
"24 50 5 80"
]
assert best_subscription_plan(3, plans) == 2
def... | [
{
"docstring": null,
"function_declaration": "def find_best_plan(plans):",
"function_name": "find_best_plan",
"parameter_list": "(plans)"
},
{
"docstring": null,
"function_declaration": "def best_subscription_plan(n, plans_list):",
"function_name": "best_subscription_plan",
"para... | [
0,
0,
0,
1,
0,
0,
0,
0,
0,
0
] | 1 | hard | 0.1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def find_best_plan(n, plans):\n remaining_plans = []\n\n # Filter out plans that are strictly worse than any other plan\n for i in range(n):\n ... | trial_gpt4o_3 | {
"original_instruction": "A mobile app development company is offering n different subscription plans. Each plan has certain features that are of interest:\n\n- Number of hours of technical support per month\n- Amount of storage provided in GB\n- Number of team member accounts included\n- Monthly cost of the plan\n\... | 0.57779 | Codeforces_14819 | C | [
"find_best_plan",
"best_subscription_plan"
] | 2 | [
[
"best_subscription_plan",
"find_best_plan"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 14d83ec86e78935f0dad36a0b2502ffce198c41b | 50a1cd4dc04b7336edaed3faded086d333778119 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.