task_id
stringlengths
7
9
prompt
stringlengths
237
6.2k
entry_point
stringlengths
2
37
test
stringlengths
70
6.28k
given_tests
listlengths
1
6
canonical_solution
stringclasses
1 value
difficulty
stringclasses
3 values
added_tests
listlengths
0
0
APPS/2199
def calculate_max_happiness(n: int, k: int, roads: List[Tuple[int, int]]) -> int: """ Writing light novels is the most important thing in Linova's life. Last night, Linova dreamed about a fantastic kingdom. She began to write a light novel for the kingdom as soon as she woke up, and of course, she is the queen ...
calculate_max_happiness
def check(candidate): assert candidate(7, 4, [(1, 2), (1, 3), (1, 4), (3, 5), (3, 6), (4, 7)]) == 7 assert candidate(4, 1, [(1, 2), (1, 3), (2, 4)]) == 2 assert candidate(8, 5, [(7, 5), (1, 7), (6, 1), (3, 7), (8, 3), (2, 1), (4, 5)]) == 9 assert candidate(2, 1, [(1, 2)]) == 1 assert candidate(20, ...
[ "assert calculate_max_happiness(7, 4, [(1, 2), (1, 3), (1, 4), (3, 5), (3, 6), (4, 7)]) == 7", "assert calculate_max_happiness(4, 1, [(1, 2), (1, 3), (2, 4)]) == 2", "assert calculate_max_happiness(8, 5, [(7, 5), (1, 7), (6, 1), (3, 7), (8, 3), (2, 1), (4, 5)]) == 9" ]
competition
[]
APPS/2083
def find_suitable_array(n: int, m: int, operations: List[Tuple[int, int, int, int]]) -> Tuple[str, List[int]]: """ Levko loves array a_1, a_2, ... , a_{n}, consisting of integers, very much. That is why Levko is playing with array a, performing all sorts of operations with it. Each operation Levko performs is o...
find_suitable_array
def check(candidate): assert candidate(4, 5, [(1, 2, 3, 1), (2, 1, 2, 8), (2, 3, 4, 7), (1, 1, 3, 3), (2, 3, 4, 8)]) == ('YES', [4, 7, 4, 7]) assert candidate(4, 5, [(1, 2, 3, 1), (2, 1, 2, 8), (2, 3, 4, 7), (1, 1, 3, 3), (2, 3, 4, 13)]) == 'NO' assert candidate(1, 4, [(1, 1, 1, 2), (2, 1, 1, 6), (1, 1, 1,...
[ "assert find_suitable_array(4, 5, [(1, 2, 3, 1), (2, 1, 2, 8), (2, 3, 4, 7), (1, 1, 3, 3), (2, 3, 4, 8)]) == ('YES', [4, 7, 4, 7])", "assert find_suitable_array(4, 5, [(1, 2, 3, 1), (2, 1, 2, 8), (2, 3, 4, 7), (1, 1, 3, 3), (2, 3, 4, 13)]) == 'NO'" ]
competition
[]
APPS/2178
def calculate_inversions(n: int, m: int, permutation: List[int], operations: List[Tuple[int, int]]) -> float: """ The Little Elephant loves permutations of integers from 1 to n very much. But most of all he loves sorting them. To sort a permutation, the Little Elephant repeatedly swaps some elements. As a resul...
calculate_inversions
def check(candidate): assert candidate(2, 1, [1, 2], [(1, 2)]) == 0.500000000 assert candidate(4, 3, [1, 3, 2, 4], [(1, 2), (2, 3), (1, 4)]) == 3.000000000 assert candidate(7, 4, [7, 6, 4, 2, 1, 5, 3], [(1, 3), (2, 1), (7, 2), (3, 5)]) == 11.250000000 assert candidate(10, 1, [1, 2, 3, 4, 5, 6, 7, 8, 9,...
[ "assert calculate_inversions(2, 1, [1, 2], [(1, 2)]) == 0.500000000", "assert calculate_inversions(4, 3, [1, 3, 2, 4], [(1, 2), (2, 3), (1, 4)]) == 3.000000000" ]
competition
[]
APPS/2164
def find_unobtainable_residues(N: int, M: int, A: List[int]) -> Tuple[int, List[int]]: """ Everybody seems to think that the Martians are green, but it turns out they are metallic pink and fat. Ajs has two bags of distinct nonnegative integers. The bags are disjoint, and the union of the sets of numbers in the ...
find_unobtainable_residues
def check(candidate): assert candidate(2, 5, [3, 4]) == (1, [2]) assert candidate(4, 1000000000, [5, 25, 125, 625]) == (0, []) assert candidate(2, 4, [1, 3]) == (2, [0, 2]) assert candidate(1, 2, [1]) == (1, [0]) assert candidate(14, 34, [1, 2, 4, 7, 10, 12, 13, 18, 19, 21, 24, 27, 29, 30]) == (2, ...
[ "assert find_unobtainable_residues(2, 5, [3, 4]) == (1, [2])", "assert find_unobtainable_residues(4, 1000000000, [5, 25, 125, 625]) == (0, [])", "assert find_unobtainable_residues(2, 4, [1, 3]) == (2, [0, 2])" ]
competition
[]
APPS/2329
def count_subsequences(N: int, M: int, A: List[int], B: List[int]) -> int: """ You are given an array A, consisting of N integers and an array B, consisting of M integers. The subsequence of A is the array that can be obtained by picking the elements at the arbitrary sorted set of positions from A. Your...
count_subsequences
def check(candidate): assert candidate(5, 3, [1, 5, 2, 4, 7], [7, 9, 6]) == 4 assert candidate(4, 2, [7, 7, 7, 7], [3, 4]) == 6 check(count_subsequences)
[ "assert count_subsequences(5, 3, [1, 5, 2, 4, 7], [7, 9, 6]) == 4", "assert count_subsequences(4, 2, [7, 7, 7, 7], [3, 4]) == 6" ]
competition
[]
APPS/2197
def find_palindrome(A: str) -> str: """ You are given a string A. Find a string B, where B is a palindrome and A is a subsequence of B. A subsequence of a string is a string that can be derived from it by deleting some (not necessarily consecutive) characters without changing the order of the remaining...
find_palindrome
def check(find_palindrome): assert find_palindrome('aba') == 'abaaba' assert find_palindrome('ab') == 'abba' assert find_palindrome('abca') == 'abcacba' assert find_palindrome('racecar') == 'racecaracecar' assert find_palindrome('a') == 'aa' check(find_palindrome)
[ "assert find_palindrome('aba') == 'aba'", "assert find_palindrome('ab') == 'aabaa'" ]
competition
[]
APPS/2097
def max_possible_f(n: int, edges: List[Tuple[int, int, int]], use_count: List[int]) -> int: """ DZY loves planting, and he enjoys solving tree problems. DZY has a weighted tree (connected undirected graph without cycles) containing n nodes (they are numbered from 1 to n). He defines the function g(x, y...
max_possible_f
def check(max_possible_f): assert max_possible_f(4, [(1, 2, 1), (2, 3, 2), (3, 4, 3)], [1, 1, 1, 1]) == 2 assert max_possible_f(4, [(1, 2, 1), (2, 3, 2), (3, 4, 3)], [4, 4, 4, 4]) == 3 assert max_possible_f(5, [(1, 2, 1), (1, 3, 1), (1, 4, 1), (1, 5, 1)], [1, 1, 1, 1, 1]) == 1 assert max_possible_f(3, ...
[ "assert max_possible_f(4, [(1, 2, 1), (2, 3, 2), (3, 4, 3)], [1, 1, 1, 1]) == 2", "assert max_possible_f(4, [(1, 2, 1), (2, 3, 2), (3, 4, 3)], [4, 4, 4, 4]) == 3" ]
competition
[]
APPS/2200
def xor_pairwise_sums(n: int, arr: List[int]) -> int: """ Catherine received an array of integers as a gift for March 8. Eventually she grew bored with it, and she started calculated various useless characteristics for it. She succeeded to do it for each one she came up with. But when she came up with another o...
xor_pairwise_sums
def check(xor_pairwise_sums): assert xor_pairwise_sums(2, [1, 2]) == 3 assert xor_pairwise_sums(3, [1, 2, 3]) == 2 assert xor_pairwise_sums(2, [1, 1]) == 2 assert xor_pairwise_sums(100, list(range(100))) == 102 assert xor_pairwise_sums(50, [i for i in range(50)]) == 3 assert xor_pairwise_sums(1...
[ "assert xor_pairwise_sums(2, [1, 2]) == 3", "assert xor_pairwise_sums(3, [1, 2, 3]) == 2" ]
competition
[]
APPS/2118
def game_of_stones(n: int, stones: List[int]) -> str: """ Sam has been teaching Jon the Game of Stones to sharpen his mind and help him devise a strategy to fight the white walkers. The rules of this game are quite simple: The game starts with n piles of stones indexed from 1 to n. The i-th pile contains s_{i}...
game_of_stones
def check(candidate): assert candidate(1, [5]) == 'NO' assert candidate(2, [1, 2]) == 'YES' assert candidate(3, [34, 44, 21]) == 'NO' assert candidate(6, [34, 44, 21, 55, 1, 36]) == 'NO' assert candidate(14, [34, 44, 21, 55, 1, 36, 53, 31, 58, 59, 11, 40, 20, 32]) == 'NO' assert candidate(10, [...
[ "assert game_of_stones(1, [5]) == 'NO'", "assert game_of_stones(2, [1, 2]) == 'YES'" ]
competition
[]
APPS/2034
def max_perimeter(n: int, points: List[List[int]]) -> str: """ You are given $n$ points on the plane. The polygon formed from all the $n$ points is strictly convex, that is, the polygon is convex, and there are no three collinear points (i.e. lying in the same straight line). The points are numbered from $1$ to...
max_perimeter
def check(candidate): assert candidate(4, [[2, 4], [4, 3], [3, 0], [1, 3]]) == '12 14' assert candidate(3, [[0, 0], [0, 2], [2, 0]]) == '8' assert candidate(8, [[0, 3], [2, 2], [3, 0], [2, -2], [0, -3], [-2, -2], [-3, 0], [-2, 2]]) == '20 24 24 24 24 24' assert candidate(4, [[-100000000, -100000000], [...
[ "assert max_perimeter(4, [[2, 4], [4, 3], [3, 0], [1, 3]]) == '12 14'", "assert max_perimeter(3, [[0, 0], [0, 2], [2, 0]]) == '8'" ]
competition
[]
APPS/2173
def process_paper_operations(n: int, q: int, queries: List[str]) -> List[int]: """ Appleman has a very big sheet of paper. This sheet has a form of rectangle with dimensions 1 × n. Your task is help Appleman with folding of such a sheet. Actually, you need to perform q queries. Each query will have one of the f...
process_paper_operations
def check(process_paper_operations): assert process_paper_operations(7, 4, ["1 3", "1 2", "2 0 1", "2 1 2"]) == [4, 3] assert process_paper_operations(10, 9, ["2 2 9", "1 1", "2 0 1", "1 8", "2 0 8", "1 2", "2 1 3", "1 4", "2 2 4"]) == [7, 2, 10, 4, 5] assert process_paper_operations(10, 5, ["2 1 9", "2 4 ...
[ "assert process_paper_operations(7, 4, [\"1 3\", \"1 2\", \"2 0 1\", \"2 1 2\"]) == [4, 3]", "assert process_paper_operations(10, 9, [\"2 2 9\", \"1 1\", \"2 0 1\", \"1 8\", \"2 0 8\", \"1 2\", \"2 1 3\", \"1 4\", \"2 2 4\"]) == [7, 2, 10, 4, 5]" ]
competition
[]
APPS/2030
def find_min_travel_cost(n: int, x: int, y: int, roads: List[Tuple[int, int]]) -> int: """ A group of n cities is connected by a network of roads. There is an undirected road between every pair of cities, so there are $\frac{n \cdot(n - 1)}{2}$ roads in total. It takes exactly y seconds to traverse any single r...
find_min_travel_cost
def check(find_min_travel_cost): assert find_min_travel_cost(5, 2, 3, [(1, 2), (1, 3), (3, 4), (5, 3)]) == 9 assert find_min_travel_cost(5, 3, 2, [(1, 2), (1, 3), (3, 4), (5, 3)]) == 8 assert find_min_travel_cost(50, 23129, 410924, [(18, 28), (17, 23), (21, 15), (18, 50), (50, 11), (32, 3), (44, 41), (50, ...
[ "assert find_min_travel_cost(5, 2, 3, [(1, 2), (1, 3), (3, 4), (5, 3)]) == 9", "assert find_min_travel_cost(5, 3, 2, [(1, 2), (1, 3), (3, 4), (5, 3)]) == 8" ]
competition
[]
APPS/2018
def find_min_goodness(n: int, h: int, a: List[int]) -> Tuple[int, List[int]]: """ This problem is the most boring one you've ever seen. Given a sequence of integers a_1, a_2, ..., a_{n} and a non-negative integer h, our goal is to partition the sequence into two subsequences (not necessarily consist of...
find_min_goodness
def check(find_min_goodness): assert find_min_goodness(3, 2, [1, 2, 3]) == (1, [1, 2, 2]) assert find_min_goodness(5, 10, [0, 1, 0, 2, 1]) == (3, [2, 2, 2, 2, 2]) assert find_min_goodness(9, 0, [11, 22, 33, 44, 55, 66, 77, 88, 99]) == (154, [2, 2, 2, 2, 2, 2, 2, 2, 2]) assert find_min_goodness(10, 100,...
[ "assert find_min_goodness(3, 2, [1, 2, 3]) == (1, [1, 2, 2])", "assert find_min_goodness(5, 10, [0, 1, 0, 2, 1]) == (3, [2, 2, 2, 2, 2])" ]
competition
[]
APPS/2158
def find_permutation(n: int) -> Tuple[str, List[int]]: """ Consider a sequence [a_1, a_2, ... , a_{n}]. Define its prefix product sequence $[ a_{1} \operatorname{mod} n,(a_{1} a_{2}) \operatorname{mod} n, \cdots,(a_{1} a_{2} \cdots a_{n}) \operatorname{mod} n ]$. Now given n, find a permutation of [1, ...
find_permutation
def check(find_permutation): assert find_permutation(7) == ('YES', [1, 2, 5, 6, 3, 4, 7]) assert find_permutation(6) == ('NO', []) assert find_permutation(7137) == ('NO', []) assert find_permutation(1941) == ('NO', []) assert find_permutation(55004) == ('NO', []) assert find_permutation(1) == (...
[ "assert find_permutation(7) == ('YES', [1, 2, 5, 6, 3, 4, 7])", "assert find_permutation(6) == ('NO', [])" ]
competition
[]
APPS/2149
def count_connected_components(n: int, m: int, a: List[int]) -> int: """ You are given a set of size $m$ with integer elements between $0$ and $2^{n}-1$ inclusive. Let's build an undirected graph on these integers in the following way: connect two integers $x$ and $y$ with an edge if and only if $x \& y = 0$. H...
count_connected_components
def check(count_connected_components): assert count_connected_components(2, 3, [1, 2, 3]) == 2 assert count_connected_components(5, 5, [5, 19, 10, 20, 12]) == 2 assert count_connected_components(3, 5, [3, 5, 0, 6, 7]) == 1 assert count_connected_components(0, 1, [0]) == 1 assert count_connected_com...
[ "assert count_connected_components(2, 3, [1, 2, 3]) == 2", "assert count_connected_components(5, 5, [5, 19, 10, 20, 12]) == 2" ]
competition
[]
APPS/2162
def find_final_label_probabilities(n: int, edges: List[Tuple[int, int]]) -> List[float]: """ Consider a tree $T$ (that is, a connected graph without cycles) with $n$ vertices labelled $1$ through $n$. We start the following process with $T$: while $T$ has more than one vertex, do the following: ...
find_final_label_probabilities
def check(find_final_label_probabilities): assert find_final_label_probabilities(4, [(1, 2), (1, 3), (1, 4)]) == [0.1250000000, 0.2916666667, 0.2916666667, 0.2916666667] assert find_final_label_probabilities(7, [(1, 2), (1, 3), (2, 4), (2, 5), (3, 6), (3, 7)]) == [0.0850694444, 0.0664062500, 0.0664062500, 0.19...
[ "assert find_final_label_probabilities(4, [(1, 2), (1, 3), (1, 4)]) == [0.1250000000, 0.2916666667, 0.2916666667, 0.2916666667]", "assert find_final_label_probabilities(7, [(1, 2), (1, 3), (2, 4), (2, 5), (3, 6), (3, 7)]) == [0.0850694444, 0.0664062500, 0.0664062500, 0.1955295139, 0.1955295139, 0.1955295139, 0.19...
competition
[]
APPS/2126
def find_gcd_of_lcms(n: int, a: List[int]) -> int: """ For the multiset of positive integers $s=\{s_1,s_2,\dots,s_k\}$, define the Greatest Common Divisor (GCD) and Least Common Multiple (LCM) of $s$ as follow: $\gcd(s)$ is the maximum positive integer $x$, such that all integers in $s$ are divisible on $x$. $\...
find_gcd_of_lcms
def check(find_gcd_of_lcms): assert find_gcd_of_lcms(2, [1, 1]) == 1 assert find_gcd_of_lcms(4, [10, 24, 40, 80]) == 40 assert find_gcd_of_lcms(10, [540, 648, 810, 648, 720, 540, 594, 864, 972, 648]) == 54 assert find_gcd_of_lcms(2, [199999, 200000]) == 39999800000 assert find_gcd_of_lcms(2, [19876...
[ "assert find_gcd_of_lcms(2, [1, 1]) == 1", "assert find_gcd_of_lcms(4, [10, 24, 40, 80]) == 40", "assert find_gcd_of_lcms(10, [540, 648, 810, 648, 720, 540, 594, 864, 972, 648]) == 54" ]
competition
[]
APPS/2274
def construct_array(n: int, r: int, c: List[int], changes: List[Tuple[int, int]]) -> List[float]: """ Allen and Bessie are playing a simple number game. They both know a function $f: \{0, 1\}^n \to \mathbb{R}$, i. e. the function takes $n$ binary arguments and returns a real value. At the start of the game, the...
construct_array
def check(candidate): assert construct_array(2, 2, [0, 1, 2, 3], [(2, 5), (0, 4)]) == [1.500000, 2.250000, 3.250000] assert candidate(1, 0, [2, 3], []) == [2.500000] assert construct_array(2, 0, [1, 1, 1, 1], []) == [1.000000] check(construct_array)
[ "assert construct_array(2, 2, [0, 1, 2, 3], [(2, 5), (0, 4)]) == [1.500000, 2.250000, 3.250000]", "assert construct_array(1, 0, [2, 3], []) == [2.500000]", "assert construct_array(2, 0, [1, 1, 1, 1], []) == [1.000000]" ]
competition
[]
APPS/2219
def coexist_in_peace(n: int, q: int, word: str, operations: List[Tuple[str, int, str]]) -> List[str]: """ During the archaeological research in the Middle East you found the traces of three ancient religions: First religion, Second religion and Third religion. You compiled the information on the evolution of ea...
coexist_in_peace
def check(candidate): assert coexist_in_peace(6, 8, 'abdabc', [('+', 1, 'a'), ('+', 1, 'd'), ('+', 2, 'b'), ('+', 2, 'c'), ('+', 3, 'a'), ('+', 3, 'b'), ('+', 1, 'c'), ('-', 2)]) == ['YES', 'YES', 'YES', 'YES', 'YES', 'YES', 'NO', 'YES'] assert coexist_in_peace(6, 8, 'abbaab', [('+', 1, 'a'), ('+', 2, 'a'), ('...
[ "assert coexist_in_peace(6, 8, 'abdabc', [('+', 1, 'a'), ('+', 1, 'd'), ('+', 2, 'b'), ('+', 2, 'c'), ('+', 3, 'a'), ('+', 3, 'b'), ('+', 1, 'c'), ('-', 2)]) == ['YES', 'YES', 'YES', 'YES', 'YES', 'YES', 'NO', 'YES']", "assert coexist_in_peace(6, 8, 'abbaab', [('+', 1, 'a'), ('+', 2, 'a'), ('+', 3, 'a'), ('+', 1,...
competition
[]
APPS/2060
def min_processing_time(n: int, k: int, contrasts: List[int]) -> int: """ Evlampiy has found one more cool application to process photos. However the application has certain limitations. Each photo i has a contrast v_{i}. In order for the processing to be truly of high quality, the application must rec...
min_processing_time
def check(candidate): assert min_processing_time(5, 2, [50, 110, 130, 40, 120]) == 20 assert min_processing_time(4, 1, [2, 3, 4, 1]) == 0 assert min_processing_time(1, 1, [4]) == 0 assert min_processing_time(2, 2, [7, 5]) == 2 assert candidate(3, 2, [34, 3, 75]) == 72 assert min_processing_time...
[ "assert min_processing_time(5, 2, [50, 110, 130, 40, 120]) == 20", "assert min_processing_time(4, 1, [2, 3, 4, 1]) == 0" ]
competition
[]
APPS/2228
def max_trip_people(n: int, m: int, k: int, friendships: List[Tuple[int, int]]) -> List[int]: """ There are $n$ persons who initially don't know each other. On each morning, two of them, who were not friends before, become friends. We want to plan a trip for every evening of $m$ days. On each trip, you...
max_trip_people
def check(candidate): assert candidate(4, 4, 2, [(2, 3), (1, 2), (1, 3), (1, 4)]) == [0, 0, 3, 3] assert candidate(5, 8, 2, [(2, 1), (4, 2), (5, 4), (5, 2), (4, 3), (5, 1), (4, 1), (3, 2)]) == [0, 0, 0, 3, 3, 4, 4, 5] assert candidate(5, 7, 2, [(1, 5), (3, 2), (2, 5), (3, 4), (1, 2), (5, 3), (1, 3)]) == [0...
[ "assert max_trip_people(4, 4, 2, [(2, 3), (1, 2), (1, 3), (1, 4)]) == [0, 0, 3, 3]", "assert max_trip_people(5, 8, 2, [(2, 1), (4, 2), (5, 4), (5, 2), (4, 3), (5, 1), (4, 1), (3, 2)]) == [0, 0, 0, 3, 3, 4, 4, 5]", "assert max_trip_people(5, 7, 2, [(1, 5), (3, 2), (2, 5), (3, 4), (1, 2), (5, 3), (1, 3)]) == [0, ...
competition
[]
APPS/2031
def color_cells(n: int, m: int, l: List[int]) -> Union[List[int], int]: """ Dreamoon likes coloring cells very much. There is a row of $n$ cells. Initially, all cells are empty (don't contain any color). Cells are numbered from $1$ to $n$. You are given an integer $m$ and $m$ integers $l_1, l_...
color_cells
def check(candidate): assert color_cells(5, 3, [3, 2, 2]) == [2, 4, 1] assert color_cells(10, 1, [1]) == -1 assert color_cells(1, 1, [1]) == [1] assert color_cells(2, 2, [1, 2]) == -1 assert color_cells(200, 50, [49, 35, 42, 47, 134, 118, 14, 148, 58, 159, 33, 33, 8, 123, 99, 126, 75, 94, 1, 141, 6...
[ "assert color_cells(5, 3, [3, 2, 2]) == [1, 2, 4]", "assert color_cells(10, 1, [1]) == -1" ]
competition
[]
APPS/2278
def count_u_shaped_parabolas(n: int, points: List[Tuple[int, int]]) -> int: """ Recently Vasya learned that, given two points with different $x$ coordinates, you can draw through them exactly one parabola with equation of type $y = x^2 + bx + c$, where $b$ and $c$ are reals. Let's call such a parabola an $U$-sh...
count_u_shaped_parabolas
def check(candidate): assert count_u_shaped_parabolas(3, [(-1, 0), (0, 2), (1, 0)]) == 2 assert count_u_shaped_parabolas(5, [(1, 0), (1, -1), (0, -1), (-1, 0), (-1, -1)]) == 1 assert count_u_shaped_parabolas(1, [(-751115, -925948)]) == 0 check(count_u_shaped_parabolas)
[ "assert count_u_shaped_parabolas(3, [(-1, 0), (0, 2), (1, 0)]) == 2", "assert count_u_shaped_parabolas(5, [(1, 0), (1, -1), (0, -1), (-1, 0), (-1, -1)]) == 1" ]
competition
[]
APPS/2136
def max_non_overlapping_dominos(n: int, heights: List[int]) -> int: """ You are given a Young diagram. Given diagram is a histogram with $n$ columns of lengths $a_1, a_2, \ldots, a_n$ ($a_1 \geq a_2 \geq \ldots \geq a_n \geq 1$). [Image] Young diagram for $a=[3,2,2,2,1]$. Your goal is to find ...
max_non_overlapping_dominos
def check(candidate): assert max_non_overlapping_dominos(5, [3, 2, 2, 2, 1]) == 4 assert max_non_overlapping_dominos(5, [1, 1, 1, 1, 1]) == 2 assert max_non_overlapping_dominos(3, [3, 3, 3]) == 4 assert max_non_overlapping_dominos(1, [1]) == 0 assert max_non_overlapping_dominos(10, [9, 8, 7, 7, 6, ...
[ "assert max_non_overlapping_dominos(5, [3, 2, 2, 2, 1]) == 4" ]
competition
[]
APPS/2070
def final_number_after_operations(n: int, nums: List[int]) -> int: """ Karen has just arrived at school, and she has a math test today! [Image] The test is about basic addition and subtraction. Unfortunately, the teachers were too busy writing tasks for Codeforces rounds, and had no time to make an act...
final_number_after_operations
def check(candidate): assert candidate(5, [3, 6, 9, 12, 15]) == 36 assert candidate(4, [3, 7, 5, 2]) == 1000000006 assert candidate(1, [1]) == 1 assert candidate(16, [985629174, 189232688, 48695377, 692426437, 952164554, 243460498, 173956955, 210310239, 237322183, 96515847, 678847559, 682240199, 498792...
[ "assert final_number_after_operations(5, [3, 6, 9, 12, 15]) == 36", "assert final_number_after_operations(4, [3, 7, 5, 2]) == 1000000006" ]
competition
[]
APPS/2318
def participants_excluded_from_ranking(n: int, k: int, ratings: List[int]) -> List[int]: """ During the last Sereja's Codesecrof round the server crashed many times, so the round was decided to be made unrated for some participants. Let's assume that n people took part in the contest. Let's assume that...
participants_excluded_from_ranking
def check(candidate): assert participants_excluded_from_ranking(5, 0, [5, 3, 4, 1, 2]) == [2, 3, 4] assert participants_excluded_from_ranking(10, -10, [5, 5, 1, 7, 5, 1, 2, 4, 9, 2]) == [2, 4, 5, 7, 8, 9] check(participants_excluded_from_ranking)
[ "assert participants_excluded_from_ranking(5, 0, [5, 3, 4, 1, 2]) == [2, 3, 4]", "assert participants_excluded_from_ranking(10, -10, [5, 5, 1, 7, 5, 1, 2, 4, 9, 2]) == [2, 4, 5, 7, 8, 9]" ]
competition
[]
APPS/2142
def restore_sequence(n: int, matrix: List[List[int]]) -> List[int]: """ Recently Polycarpus has learned the "bitwise AND" operation (which is also called "AND") of non-negative integers. Now he wants to demonstrate the school IT teacher his superb manipulation with the learned operation. For that Polyc...
restore_sequence
def check(candidate): assert restore_sequence(1, [[-1]]) == [0] assert restore_sequence(3, [[-1, 18, 0], [18, -1, 0], [0, 0, -1]]) == [18, 18, 0] assert restore_sequence(4, [[-1, 128, 128, 128], [128, -1, 148, 160], [128, 148, -1, 128], [128, 160, 128, -1]]) == [128, 180, 148, 160] assert restore_seque...
[ "assert restore_sequence(1, [[-1]]) == [0]", "assert restore_sequence(3, [[-1, 18, 0], [18, -1, 0], [0, 0, -1]]) == [18, 18, 0]", "assert restore_sequence(4, [[-1, 128, 128, 128], [128, -1, 148, 160], [128, 148, -1, 128], [128, 160, 128, -1]]) == [128, 180, 148, 160]" ]
competition
[]
APPS/2170
def minimize_eating_time(n: int, k: int, a: List[int]) -> int: """ There are some rabbits in Singapore Zoo. To feed them, Zookeeper bought $n$ carrots with lengths $a_1, a_2, a_3, \ldots, a_n$. However, rabbits are very fertile and multiply very quickly. Zookeeper now has $k$ rabbits and does not have enough ca...
minimize_eating_time
def check(candidate): assert minimize_eating_time(3, 6, [5, 3, 1]) == 15 assert minimize_eating_time(1, 4, [19]) == 91 assert minimize_eating_time(1, 3, [1000000]) == 333333333334 assert minimize_eating_time(1, 1, [1]) == 1 assert minimize_eating_time(10, 23, [343, 984, 238, 758983, 231, 74, 231, 5...
[ "assert minimize_eating_time(3, 6, [5, 3, 1]) == 15", "assert minimize_eating_time(1, 4, [19]) == 91" ]
competition
[]
APPS/2035
def count_picking_ways(n: int, m: int, a: List[int]) -> List[int]: """ This is the easy version of the problem. The only difference between easy and hard versions is the constraint of $m$. You can make hacks only if both versions are solved. Chiori loves dolls and now she is going to decorate her bedro...
count_picking_ways
def check(candidate): assert count_picking_ways(4, 4, [3, 5, 8, 14]) == [2, 2, 6, 6, 0] assert count_picking_ways(6, 7, [11, 45, 14, 9, 19, 81]) == [1, 2, 11, 20, 15, 10, 5, 0] assert count_picking_ways(1, 0, [0]) == [2] assert count_picking_ways(30, 35, [11712212162, 13887261936, 9226451478, 581057842...
[ "assert count_picking_ways(4, 4, [3, 5, 8, 14]) == [2, 2, 6, 6, 0]", "assert count_picking_ways(6, 7, [11, 45, 14, 9, 19, 81]) == [1, 2, 11, 20, 15, 10, 5, 0]" ]
competition
[]
APPS/2308
def maximize_column_sums(n: int, w: int, arrays: List[List[int]]) -> List[int]: """ You are given $n$ arrays that can have different sizes. You also have a table with $w$ columns and $n$ rows. The $i$-th array is placed horizontally in the $i$-th row. You can slide each array within its row as long as it occupi...
maximize_column_sums
def check(candidate): assert candidate(3, 3, [[3, 2, 4, 8], [2, 2, 5], [2, 6, 3]]) == [10, 15, 16] assert candidate(2, 2, [[2, 7, 8], [1, -8]]) == [7, 8] check(maximize_column_sums)
[ "assert maximize_column_sums(3, 3, [[3, 2, 4, 8], [2, 2, 5], [2, 6, 3]]) == [10, 15, 16]", "assert maximize_column_sums(2, 2, [[2, 7, 8], [1, -8]]) == [7, 8]" ]
competition
[]
APPS/2346
def maximize_haybales(t: int, test_cases: List[Tuple[int, int, List[int]]]) -> List[int]: """ The USA Construction Operation (USACO) recently ordered Farmer John to arrange a row of $n$ haybale piles on the farm. The $i$-th pile contains $a_i$ haybales. However, Farmer John has just left for vacation, ...
maximize_haybales
def check(candidate): assert candidate(3, [(4, 5, [1, 0, 3, 2]), (2, 2, [100, 1]), (1, 8, [0])]) == [3, 101, 0] check(maximize_haybales)
[ "assert maximize_haybales(3, [(4, 5, [1, 0, 3, 2]), (2, 2, [100, 1]), (1, 8, [0])]) == [3, 101, 0]" ]
competition
[]
APPS/2204
def shortest_time_to_move_token(n: int, m: int, edges: List[Tuple[int, int]]) -> int: """ You are given a directed graph of $n$ vertices and $m$ edges. Vertices are numbered from $1$ to $n$. There is a token in vertex $1$. The following actions are allowed: Token movement. To move the token from vert...
shortest_time_to_move_token
def check(candidate): assert candidate(4, 4, [(1, 2), (2, 3), (3, 4), (4, 1)]) == 2 assert candidate(4, 3, [(2, 1), (2, 3), (4, 3)]) == 10 assert candidate(10, 20, [(2, 1), (7, 9), (10, 2), (4, 9), (3, 1), (6, 4), (3, 6), (2, 9), (5, 2), (3, 9), (6, 8), (8, 7), (10, 4), (7, 4), (8, 5), (3, 4), (6, 7), (2, ...
[ "assert shortest_time_to_move_token(4, 4, [(1, 2), (2, 3), (3, 4), (4, 1)]) == 2", "assert shortest_time_to_move_token(4, 3, [(2, 1), (2, 3), (4, 3)]) == 10" ]
competition
[]
APPS/2175
def is_possible_xor_sum(m: int, numbers: List[int]) -> List[str]: """ After Misha's birthday he had many large numbers left, scattered across the room. Now it's time to clean up and Misha needs to put them in a basket. He ordered this task to his pet robot that agreed to complete the task at certain conditions....
is_possible_xor_sum
def check(candidate): assert candidate(7, [7, 6, 5, 4, 3, 2, 1]) == ['0', '0', '0', '3 0 1 2', '2 1 2', '2 0 2', '2 0 1'] assert candidate(2, [5, 5]) == ['0', '1 0'] assert candidate(10, [81, 97, 12, 2, 16, 96, 80, 99, 6, 83]) == ['0', '0', '0', '0', '0', '0', '3 0 1 5', '2 1 3', '0', '2 0 3'] assert c...
[ "assert is_possible_xor_sum(7, [7, 6, 5, 4, 3, 2, 1]) == ['0', '0', '0', '3 0 1 2', '2 1 2', '2 0 2', '2 0 1']", "assert is_possible_xor_sum(2, [5, 5]) == ['0', '1 0']" ]
competition
[]
APPS/2139
def partition_sum(n: int, a: List[int]) -> int: """ You are given an array $a$ of length $2n$. Consider a partition of array $a$ into two subsequences $p$ and $q$ of length $n$ each (each element of array $a$ should be in exactly one subsequence: either in $p$ or in $q$). Let's sort $p$ in non-decreasi...
partition_sum
def check(candidate): assert candidate(1, [1, 4]) == 6 assert candidate(2, [2, 1, 2, 1]) == 12 assert candidate(3, [2, 2, 2, 2, 2, 2]) == 0 assert candidate(5, [13, 8, 35, 94, 9284, 34, 54, 69, 123, 846]) == 2588544 assert candidate(1, [2, 5]) == 6 assert candidate(7, [2, 5, 6, 25, 22, 21, 7, 9...
[ "assert partition_sum(1, [1, 4]) == 6", "assert partition_sum(2, [2, 1, 2, 1]) == 12", "assert partition_sum(3, [2, 2, 2, 2, 2, 2]) == 0", "assert partition_sum(5, [13, 8, 35, 94, 9284, 34, 54, 69, 123, 846]) == 2588544" ]
competition
[]
APPS/2078
def minimal_coins(n: int, a: str, b: str) -> List[Union[int, Tuple[int, int]]]: """ One player came to a casino and found a slot machine where everything depends only on how he plays. The rules follow. A positive integer $a$ is initially on the screen. The player can put a coin into the machine and the...
minimal_coins
def check(candidate): assert candidate(3, '223', '322') == [2, (1, 1), (2, -1)] assert candidate(2, '20', '42') == [2, (1, 1), (1, 1)] assert candidate(2, '35', '44') == [-1] assert candidate(2, '99', '11') == [8, (1, -1), (1, -1), (1, -1), (1, -1), (1, -1), (1, -1), (1, -1), (1, -1)] assert candid...
[ "assert minimal_coins(3, '223', '322') == [2, (1, 1), (2, -1)]", "assert minimal_coins(2, '20', '42') == [2, (1, 1), (1, 1)]", "assert minimal_coins(2, '35', '44') == [-1]" ]
competition
[]
APPS/2259
def weight_of_array(n: int, q: int, a: List[int], queries: List[Tuple[int, int]]) -> List[int]: """ Let $a_1, \ldots, a_n$ be an array of $n$ positive integers. In one operation, you can choose an index $i$ such that $a_i = i$, and remove $a_i$ from the array (after the removal, the remaining parts are concaten...
weight_of_array
def check(candidate): assert candidate(13, 5, [2, 2, 3, 9, 5, 4, 6, 5, 7, 8, 3, 11, 13], [(3, 1), (0, 0), (2, 4), (5, 0), (0, 12)]) == [5, 11, 6, 1, 0] assert candidate(5, 2, [1, 4, 1, 2, 4], [(0, 0), (1, 0)]) == [2, 0] assert candidate(1, 1, [1], [(0, 0)]) == [1] assert candidate(30, 10, [1, 1, 3, 3, ...
[ "assert weight_of_array(13, 5, [2, 2, 3, 9, 5, 4, 6, 5, 7, 8, 3, 11, 13], [(3, 1), (0, 0), (2, 4), (5, 0), (0, 12)]) == [5, 11, 6, 1, 0]", "assert weight_of_array(5, 2, [1, 4, 1, 2, 4], [(0, 0), (1, 0)]) == [2, 0]" ]
competition
[]
APPS/2082
def expected_game_duration(n: int, a: List[int]) -> int: """ Slime and his $n$ friends are at a party. Slime has designed a game for his friends to play. At the beginning of the game, the $i$-th player has $a_i$ biscuits. At each second, Slime will choose a biscuit randomly uniformly among all $a_1 + a...
expected_game_duration
def check(candidate): assert candidate(2, [1, 1]) == 1 assert candidate(2, [1, 2]) == 3 assert candidate(5, [0, 0, 0, 0, 35]) == 0 assert candidate(5, [8, 4, 2, 0, 1]) == 801604029 assert candidate(5, [24348, 15401, 19543, 206086, 34622]) == 788526601 assert candidate(10, [7758, 19921, 15137, 1...
[ "assert expected_game_duration(2, [1, 1]) == 1", "assert expected_game_duration(2, [1, 2]) == 3", "assert expected_game_duration(5, [0, 0, 0, 0, 35]) == 0", "assert expected_game_duration(5, [8, 4, 2, 0, 1]) == 801604029" ]
competition
[]
APPS/2251
def dangerous_triples(n: int, m: int, dislikes: List[Tuple[int, int]], q: int, revisions: List[int]) -> List[int]: """ Konrad is a Human Relations consultant working for VoltModder, a large electrical equipment producer. Today, he has been tasked with evaluating the level of happiness in the company. T...
dangerous_triples
def check(candidate): assert candidate(4, 5, [(1, 2), (2, 4), (1, 3), (3, 4), (2, 3)], 2, [2, 3]) == [4, 3, 2] assert candidate(3, 3, [(1, 2), (2, 3), (1, 3)], 5, [1, 2, 2, 1, 3]) == [1, 1, 1, 1, 1, 1] assert candidate(1, 0, [], 0, []) == [0] assert candidate(10, 20, [(9, 1), (5, 3), (7, 9), (1, 8), (1...
[ "assert dangerous_triples(4, 5, [(1, 2), (2, 4), (1, 3), (3, 4), (2, 3)], 2, [2, 3]) == [4, 3, 2]", "assert dangerous_triples(3, 3, [(1, 2), (2, 3), (1, 3)], 5, [1, 2, 2, 1, 3]) == [1, 1, 1, 1, 1, 1]" ]
competition
[]
APPS/2284
def check_reducible_anagrams(s: str, q: int, queries: List[Tuple[int, int]]) -> List[str]: """ Let's call two strings $s$ and $t$ anagrams of each other if it is possible to rearrange symbols in the string $s$ to get a string, equal to $t$. Let's consider two strings $s$ and $t$ which are anagrams of e...
check_reducible_anagrams
def check(candidate): assert candidate('aaaaa', 3, [(1, 1), (2, 4), (5, 5)]) == ['Yes', 'No', 'Yes'] assert candidate('aabbbbbbc', 6, [(1, 2), (2, 4), (2, 2), (1, 9), (5, 7), (3, 5)]) == ['No', 'Yes', 'Yes', 'Yes', 'No', 'No'] assert candidate('f', 1, [(1, 1)]) == ['Yes'] check(check_reducible_anagrams)
[ "assert check_reducible_anagrams('aaaaa', 3, [(1, 1), (2, 4), (5, 5)]) == ['Yes', 'No', 'Yes']", "assert check_reducible_anagrams('aabbbbbbc', 6, [(1, 2), (2, 4), (2, 2), (1, 9), (5, 7), (3, 5)]) == ['No', 'Yes', 'Yes', 'Yes', 'No', 'No']" ]
competition
[]