problem_statement
stringlengths
147
8.53k
input
stringlengths
1
771
output
stringlengths
1
592
time_limit
stringclasses
32 values
memory_limit
stringclasses
21 values
tags
stringlengths
6
168
A. Berland Pokertime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe game of Berland poker is played with a deck of n cards, m of which are jokers. k players play this game (n is divisible by k).At the beginning of the game, each player takes \frac{n}{k} cards from t...
4 8 3 2 4 2 4 9 6 3 42 0 7
3 0 1 0
2 seconds
256 megabytes
['brute force', 'greedy', 'math', '*1000']
F. Tasty Cookietime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputOh, no!The coronavirus has caught you, and now you're sitting in a dark cellar, with tied legs (but not hands). You have a delicious cookie, a laptop in front of you, and your ideal development environme...
2 5 7 5 7
SMALL 0
3 seconds
256 megabytes
['binary search', 'constructive algorithms', 'greedy', 'implementation', '*2700']
E. Are You Fired?time limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputLevian works as an accountant in a large company. Levian knows how much the company has earned in each of the n consecutive months — in the i-th month the company had income equal to a_i (positive inco...
3 2 -1 2
2
2 seconds
256 megabytes
['constructive algorithms', 'data structures', 'greedy', 'implementation', '*2400']
D. The Best Vacationtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou've been in love with Coronavirus-chan for a long time, but you didn't know where she lived until now. And just now you found out that she lives in a faraway place called Naha. You immediately de...
3 2 1 3 1
5
2 seconds
256 megabytes
['binary search', 'brute force', 'greedy', 'implementation', 'two pointers', '*1900']
C. Celex Updatetime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputDuring the quarantine, Sicromoft has more free time to create the new functions in "Celex-2021". The developers made a new function GAZ-GIZ, which infinitely fills an infinite table to the right and down...
4 1 1 2 2 1 2 2 4 179 1 179 100000 5 7 5 7
2 3 1 1
2 seconds
256 megabytes
['math', '*1600']
B. Maria Breaks the Self-isolationtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputMaria is the most active old lady in her house. She was tired of sitting at home. She decided to organize a ceremony against the coronavirus.She has n friends who are also grannies (Ma...
4 5 1 1 2 2 1 6 2 3 4 5 6 7 6 1 5 4 5 1 9 5 1 2 3 5 6
6 1 6 4
2 seconds
256 megabytes
['greedy', 'sortings', '*1000']
A. Park Lightingtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputDue to the coronavirus pandemic, city authorities obligated citizens to keep a social distance. The mayor of the city Semyon wants to light up Gluharniki park so that people could see each other even at...
5 1 1 1 3 2 2 3 3 5 3
1 2 2 5 8
2 seconds
256 megabytes
['greedy', 'math', '*800']
F. Guess Divisors Counttime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThis is an interactive problem.We have hidden an integer 1 \le X \le 10^{9}. You don't have to guess this number. You have to find the number of divisors of this number, and you don't even have t...
2 1 1 1 1024 1048576 4194304
? 982306799268821872 ? 230856864650023977 ? 134690134760714371 ! 5 ? 1024 ? 1048576 ? 1073741824 ! 42
2 seconds
256 megabytes
['constructive algorithms', 'interactive', 'number theory', '*2600']
E. Restorer Distancetime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou have to restore the wall. The wall consists of N pillars of bricks, the height of the i-th pillar is initially equal to h_{i}, the height is measured in number of bricks. After the restoration al...
3 1 100 100 1 3 8
12
1 second
256 megabytes
['binary search', 'greedy', 'math', 'sortings', 'ternary search', '*2100']
D. Game With Arraytime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputPetya and Vasya are competing with each other in a new interesting game as they always do.At the beginning of the game Petya has to come up with an array of N positive integers. Sum of all elements in ...
1 4
YES 4 2
1 second
256 megabytes
['constructive algorithms', 'math', '*1400']
C. Count Trianglestime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputLike any unknown mathematician, Yuri has favourite numbers: A, B, C, and D, where A \leq B \leq C \leq D. Yuri also likes triangles and once he thought: how many non-degenerate triangles with integer s...
1 2 3 4
4
1 second
256 megabytes
['binary search', 'implementation', 'math', 'two pointers', '*1800']
B. Young Explorerstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYoung wilderness explorers set off to their first expedition led by senior explorer Russell. Explorers went into a forest, set up a camp and decided to split into groups to explore as much interesting...
2 3 1 1 1 5 2 3 1 2 2
3 2
2 seconds
256 megabytes
['dp', 'greedy', 'sortings', '*1200']
A. Sequence with Digitstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputLet's define the following recurrence: a_{n+1} = a_{n} + minDigit(a_{n}) \cdot maxDigit(a_{n}).Here minDigit(x) and maxDigit(x) are the minimal and maximal digits in the decimal representation of ...
8 1 4 487 1 487 2 487 3 487 4 487 5 487 6 487 7
42 487 519 528 544 564 588 628
1 second
256 megabytes
['brute force', 'implementation', 'math', '*1200']
G. Find a Gifttime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThis is an interactive problem. Don't forget to flush output after printing queries using cout.flush() or fflush(stdout) in C++ or similar functions in other programming languages.There are n gift boxes i...
2 2 1 - - - FIRST - 5 2 - - - FIRST - - - SECOND - - - EQUAL -
- - ? 1 1 1 2 - ! 2 - ? 1 1 1 2 - ? 2 3 4 2 1 3 5 - ? 1 1 4 5 - ! 1
2 seconds
256 megabytes
['binary search', 'interactive', 'probabilities', '*2600']
F. Summoning Minionstime limit per test6 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputPolycarp plays a computer game. In this game, the players summon armies of magical minions, which then fight each other.Polycarp can summon n different minions. The initial power level of the i-th m...
3 5 2 5 3 7 0 5 0 4 0 10 0 2 1 10 100 50 10 5 5 1 5 2 4 3 3 4 2 5 1
4 2 1 -1 5 1 2 5 5 4 3 2 1
6 seconds
512 megabytes
['constructive algorithms', 'dp', 'flows', 'graph matchings', 'greedy', 'sortings', '*2500']
E. Graph Coloringtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given an undirected graph without self-loops or multiple edges which consists of n vertices and m edges. Also you are given three integers n_1, n_2 and n_3.Can you label each vertex with one of...
6 3 2 2 2 3 1 5 4 2 5
YES 112323
2 seconds
256 megabytes
['dfs and similar', 'dp', 'graphs', '*2100']
D. Multisettime limit per test1.5 secondsmemory limit per test28 megabytesinputstandard inputoutputstandard outputNote that the memory limit is unusual.You are given a multiset consisting of n integers. You have to process queries of two types: add integer k into the multiset; find the k-th order statistics in the mu...
5 5 1 2 3 4 5 -1 -1 -1 -1 -1
0
1.5 seconds
28 megabytes
['binary search', 'data structures', '*1900']
C2. Not So Simple Polygon Embeddingtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe statement of this problem is the same as the statement of problem C1. The only difference is that, in problem C1, n is always even, and in C2, n is always odd.You are given a regu...
3 3 5 199
1.931851653 3.196226611 126.687663595
2 seconds
256 megabytes
['binary search', 'brute force', 'geometry', 'math', '*2000']
C1. Simple Polygon Embeddingtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe statement of this problem is the same as the statement of problem C2. The only difference is that, in problem C1, n is always even, and in C2, n is always odd.You are given a regular pol...
3 2 4 200
1.000000000 2.414213562 127.321336469
2 seconds
256 megabytes
['binary search', 'geometry', 'math', 'ternary search', '*1400']
B. Ternary Stringtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a string s such that each its character is either 1, 2, or 3. You have to choose the shortest contiguous substring of s such that it contains each of these three characters at least once....
7 123 12222133333332 112233 332211 12121212 333333 31121
3 3 4 4 0 0 4
2 seconds
256 megabytes
['binary search', 'dp', 'implementation', 'two pointers', '*1200']
A. Alarm Clocktime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputPolycarp has spent the entire day preparing problems for you. Now he has to sleep for at least a minutes to feel refreshed.Polycarp can only wake up by hearing the sound of his alarm. So he has just falle...
7 10 3 6 4 11 3 6 4 5 9 4 10 6 5 2 3 1 1 1 1 3947465 47342 338129 123123 234123843 13 361451236 361451000
27 27 9 -1 1 6471793 358578060125049
2 seconds
256 megabytes
['math', '*900']
F. Decreasing Heightstime limit per test2.5 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are playing one famous sandbox game with the three-dimensional world. The map of the world can be represented as a matrix of size n \times m, where the height of the cell (i, j) is a_{i, j}.Y...
5 3 4 1 2 3 4 5 6 7 8 9 10 11 12 5 5 2 5 4 8 3 9 10 11 5 1 12 8 4 2 5 2 2 5 4 1 6 8 2 4 2 2 2 100 10 10 1 1 2 123456789876543 987654321234567 1 1 42
9 49 111 864197531358023 0
2.5 seconds
256 megabytes
['brute force', 'dp', '*2200']
E. K-periodic Garlandtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a garland consisting of n lamps. States of the lamps are represented by the string s of length n. The i-th character of the string s_i equals '0' if the i-th lamp is turned off or '1' ...
6 9 2 010001010 9 3 111100000 7 4 1111111 10 3 1001110101 1 1 1 1 1 0
1 2 5 4 0 0
1 second
256 megabytes
['brute force', 'dp', 'greedy', '*1900']
D. Constructing the Arraytime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given an array a of length n consisting of zeros. You perform n actions with this array: during the i-th action, the following sequence of operations appears: Choose the maximum by leng...
6 1 2 3 4 5 6
1 1 2 2 1 3 3 1 2 4 2 4 1 3 5 3 4 1 5 2 6
1 second
256 megabytes
['constructive algorithms', 'data structures', 'sortings', '*1600']
C. Board Movestime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a board of size n \times n, where n is odd (not divisible by 2). Initially, each cell of the board contains one figure.In one move, you can select exactly one figure presented in some cell an...
3 1 5 499993
0 40 41664916690999888
1 second
256 megabytes
['math', '*1000']
B. Two Arrays And Swapstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given two arrays a and b both consisting of n positive (greater than zero) integers. You are also given an integer k.In one move, you can choose two indices i and j (1 \le i, j \le n) and ...
5 2 1 1 2 3 4 5 5 5 5 6 6 5 1 2 5 4 3 5 3 1 2 3 4 5 10 9 10 10 9 4 0 2 2 4 3 2 4 2 3 4 4 1 2 2 1 4 4 5 4
6 27 39 11 17
1 second
256 megabytes
['greedy', 'sortings', '*800']
A. Most Unstable Arraytime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given two integers n and m. You have to construct the array a of length n consisting of non-negative integers (i.e. integers greater than or equal to zero) such that the sum of elements of ...
5 1 100 2 2 5 5 2 1000000000 1000000000 1000000000
0 2 10 1000000000 2000000000
1 second
256 megabytes
['constructive algorithms', 'greedy', 'math', '*800']
G. Special Permutationtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputA permutation of length n is an array p=[p_1,p_2,\dots,p_n], which contains every integer from 1 to n (inclusive) and, moreover, each number appears exactly once. For example, p=[3,1,4,2,5] is a p...
6 10 2 4 6 7 13
9 6 10 8 4 7 3 1 5 2 -1 3 1 4 2 5 3 6 2 4 1 5 1 3 6 2 4 7 13 9 7 11 8 4 1 3 5 2 6 10 12
2 seconds
256 megabytes
['constructive algorithms', '*1600']
F. Binary String Reconstructiontime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputFor some binary string s (i.e. each character s_i is either '0' or '1'), all pairs of consecutive (adjacent) characters were written. In other words, all substrings of length 2 were writte...
7 1 3 5 1 1 1 3 9 3 0 1 0 3 1 2 0 0 3 2 0 0
1110011110 0011 0110001100101011 10 0000111 1111 000
1 second
256 megabytes
['constructive algorithms', 'dfs and similar', 'math', '*1500']
E. Special Elementstime limit per test1 secondmemory limit per test64 megabytesinputstandard inputoutputstandard outputPay attention to the non-standard memory limit in this problem.In order to cut off efficient solutions from inefficient ones in this problem, the time limit is rather strict. Prefer to use compiled sta...
5 9 3 1 4 1 5 9 2 6 5 3 1 1 2 5 1 1 1 1 1 8 8 7 6 5 4 3 2 1 1 1
5 1 0 4 0
1 second
64 megabytes
['brute force', 'implementation', 'two pointers', '*1500']
D. Alice, Bob and Candiestime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere are n candies in a row, they are numbered from left to right from 1 to n. The size of the i-th candy is a_i.Alice and Bob play an interesting and tasty game: they eat candy. Alice will ea...
7 11 3 1 4 1 5 9 2 6 5 3 5 1 1000 3 1 1 1 13 1 2 3 4 5 6 7 8 9 10 11 12 13 2 2 1 6 1 1 1 1 1 1 7 1 1 1 1 1 1 1
6 23 21 1 1000 0 2 1 2 6 45 46 2 2 1 3 4 2 4 4 3
2 seconds
256 megabytes
['implementation', '*1300']
C. K-th Not Divisible by ntime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given two positive integers n and k. Print the k-th positive integer that is not divisible by n.For example, if n=3, and k=7, then all numbers that are not divisible by 3 are: 1, 2, 4, ...
6 3 7 4 12 2 1000000000 7 97 1000000000 1000000000 2 1
10 15 1999999999 113 1000000001 1
1 second
256 megabytes
['binary search', 'math', '*1200']
B. Same Parity Summandstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given two positive integers n (1 \le n \le 10^9) and k (1 \le k \le 100). Represent the number n as the sum of k positive integers of the same parity (have the same remainder when divided ...
8 10 3 100 4 8 7 97 2 8 8 3 10 5 3 1000000000 9
YES 4 2 4 YES 55 5 5 35 NO NO YES 1 1 1 1 1 1 1 1 NO YES 3 1 1 YES 111111110 111111110 111111110 111111110 111111110 111111110 111111110 111111110 111111120
1 second
256 megabytes
['constructive algorithms', 'math', '*1200']
A. Sum of Round Numberstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputA positive (strictly greater than zero) integer is called round if it is of the form d00...0. In other words, a positive integer is round if all its digits except the leftmost (most significant) a...
5 5009 7 9876 10000 10
2 5000 9 1 7 4 800 70 6 9000 1 10000 1 10
1 second
256 megabytes
['implementation', 'math', '*800']
C. Skiertime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputSkier rides on a snowy field. Its movements can be described by a string of characters 'S', 'N', 'W', 'E' (which correspond to 1 meter movement in the south, north, west or east direction respectively).It is kno...
5 NNN NS WWEN WWEE NWNWS
15 6 16 12 25
1 second
256 megabytes
['data structures', 'implementation', '*1400']
B. Square?time limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputVasya claims that he had a paper square. He cut it into two rectangular parts using one vertical or horizontal cut. Then Vasya informed you the dimensions of these two rectangular parts. You need to check whet...
3 2 3 3 1 3 2 1 3 3 3 1 3
Yes Yes No
1 second
256 megabytes
['brute force', 'implementation', 'math', '*900']
A. A+B (Trial Problem)time limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given two integers a and b. Print a+b.InputThe first line contains an integer t (1 \le t \le 10^4) — the number of test cases in the input. Then t test cases follow.Each test case is given ...
4 1 5 314 15 -99 99 123 987
6 329 0 1110
1 second
256 megabytes
['implementation', '*800']
B. Orac and Modelstime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere are n models in the shop numbered from 1 to n, with sizes s_1, s_2, \ldots, s_n.Orac will buy some of the models and will arrange them in the order of increasing numbers (i.e. indices, but not s...
4 4 5 3 4 6 7 1 4 2 3 6 4 9 5 5 4 3 2 1 1 9
2 3 1 1
3 seconds
256 megabytes
['dp', 'math', 'number theory', '*1400']
A. Orac and Factorstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputOrac is studying number theory, and he is interested in the properties of divisors.For two positive integers a and b, a is a divisor of b if and only if there exists an integer c, such that a\cdot c=...
3 5 1 8 2 3 4
10 12 12
2 seconds
256 megabytes
['math', '*900']
F2. Slime and Sequences (Hard Version)time limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputNote that the only differences between easy and hard versions are the constraints on n and the time limit. You can make hacks only if all versions are solved.Slime is interested in...
2
3 1
3 seconds
256 megabytes
['dp', 'fft', 'math', '*3500']
F1. Slime and Sequences (Easy Version)time limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputNote that the only differences between easy and hard versions are the constraints on n and the time limit. You can make hacks only if all versions are solved.Slime is interested in...
2
3 1
2 seconds
256 megabytes
['dp', 'fft', 'math', '*3100']
E. Slime and Hatstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputSlime and Orac are holding a turn-based game. In a big room, there are n players sitting on the chairs, looking forward to a column and each of them is given a number: player 1 sits in the front of the...
5 0 1 1 0 0
00000
2 seconds
256 megabytes
['constructive algorithms', 'dp', 'greedy', '*3500']
D. Slime and Biscuitstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputSlime 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...
2 1 1
1
2 seconds
256 megabytes
['math', 'probabilities', '*3200']
C. Orac and Game of Lifetime limit per test2 secondsmemory limit per test128 megabytesinputstandard inputoutputstandard outputPlease notice the unusual memory limit of this problem.Orac likes games. Recently he came up with the new game, "Game of Life".You should play this game on a black and white grid with n rows and...
3 3 3 000 111 000 1 1 1 2 2 2 3 3 3
1 1 1
2 seconds
128 megabytes
['dfs and similar', 'graphs', 'implementation', 'shortest paths', '*2000']
B. Orac and Medianstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputSlime has a sequence of positive integers a_1, a_2, \ldots, a_n.In one operation Orac can choose an arbitrary subsegment [l \ldots r] of this sequence and replace all values a_l, a_{l + 1}, \ldots, a...
5 5 3 1 5 2 6 1 1 6 6 3 2 1 2 3 4 3 3 1 2 3 10 3 1 2 3 4 5 6 7 8 9 10
no yes yes no yes
2 seconds
256 megabytes
['constructive algorithms', 'greedy', 'math', '*2000']
A. Orac and LCMtime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputFor 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 tha...
2 1 1
1
3 seconds
256 megabytes
['data structures', 'math', 'number theory', '*1600']
F. Phoenix and Memorytime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputPhoenix is trying to take a photo of his n friends with labels 1, 2, \dots, n who are lined up in a row in a special order. But before he can take the photo, his friends get distracted by a duck an...
4 4 4 1 3 2 4 3 4
YES 4 1 2 3
2 seconds
256 megabytes
['data structures', 'dfs and similar', 'graphs', 'greedy', '*2600']
E. Phoenix and Berriestime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputPhoenix is picking berries in his backyard. There are n shrubs, and each shrub has a_i red berries and b_i blue berries.Each basket can contain k berries. But, Phoenix has decided that each basket...
2 4 5 2 2 1
2
2 seconds
256 megabytes
['brute force', 'dp', 'greedy', 'math', '*2400']
D. Phoenix and Sciencetime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputPhoenix has decided to become a scientist! He is currently investigating the growth of bacteria.Initially, on day 1, there is one bacterium with mass 1.Every day, some number of bacteria will spli...
3 9 11 2
3 1 0 2 3 1 1 2 1 0
2 seconds
256 megabytes
['binary search', 'constructive algorithms', 'greedy', 'implementation', 'math', '*1900']
C. Phoenix and Distributiontime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputPhoenix has a string s consisting of lowercase Latin letters. He wants to distribute all the letters of his string into k non-empty strings a_1, a_2, \dots, a_k such that every letter of s go...
6 4 2 baba 5 2 baacb 5 3 baacb 5 3 aaaaa 6 4 aaxxzz 7 1 phoenix
ab abbc b aa x ehinopx
2 seconds
256 megabytes
['constructive algorithms', 'greedy', 'sortings', 'strings', '*1600']
B. Phoenix and Beautytime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputPhoenix loves beautiful arrays. An array is beautiful if all its subarrays of length k have the same sum. A subarray of an array is any sequence of consecutive elements.Phoenix currently has an arr...
4 4 2 1 2 2 1 4 3 1 2 2 1 3 2 1 2 3 4 4 4 3 4 2
5 1 2 1 2 1 4 1 2 2 1 -1 7 4 3 2 1 4 3 2
2 seconds
256 megabytes
['constructive algorithms', 'data structures', 'greedy', 'sortings', '*1400']
A. Phoenix and Balancetime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputPhoenix has n coins with weights 2^1, 2^2, \dots, 2^n. He knows that n is even.He wants to split the coins into two piles such that each pile has exactly \frac{n}{2} coins and the difference of we...
2 2 4
2 6
2 seconds
256 megabytes
['greedy', 'math', '*800']
I. Pac-Man 2.0time limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputPolycarp is developing a new version of an old video game "Pac-Man". Though he really enjoyed playing the original game, he didn't like some aspects of it, so he decided to alter the rules a bit.In Polyca...
3 4 2 1 3 1 2 1 2 2 1 1 3 3 1 5 8
1 3
3 seconds
256 megabytes
['*special problem', 'dp', '*2900']
H. Game with Segmentstime limit per test3 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputAlice and Bob are playing a game (yet again).They have two sequences of segments of the coordinate axis: a sequence of n initial segments: [l_1, r_1], [l_2, r_2], ..., [l_n, r_n], and a sequence of...
1 1 4 7 4 7
0
3 seconds
512 megabytes
['*special problem', 'data structures', 'games', '*2700']
G. Two IP Camerastime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou have two IP cameras of the same model. Each camera can take photos starting from some moment of time with a fixed period. You can freely choose the starting moment but you can choose the period onl...
3 5 3 5 7 1 4 5 7 12
YES 1 3 5 7
3 seconds
256 megabytes
['*special problem', 'math', 'number theory', '*2300']
F. Dune II: Battle For Arrakistime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou're at the last mission in one very old and very popular strategy game Dune II: Battle For Arrakis. The map of the mission can be represented as a rectangular matrix of size n \times m....
3 3 1 1 2 3 2 1 2 1 1 2 2 3 100
21 22
3 seconds
256 megabytes
['*special problem', 'data structures', 'greedy', 'math', '*2000']
E. Magic Trickstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputMasha is going to participate in a talent show conducted by the university she studies at. She wants to impress the audience with lots of different magic tricks!For one of her tricks, she uses n sponge b...
4 5 1 3 4 2 1 4 1 3 1 3 1
2 0 3 1
2 seconds
256 megabytes
['*special problem', 'dp', 'graphs', '*1700']
D. Constructing the Dungeontime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputPolycarp is developing an RPG game where the main character fights monsters and searches for treasure in dungeons. Now Polycarp is making one of the dungeons the character can explore.The dun...
3 3 2 1 2 1 2 3 1 5 7 3 2 7 3 4 9 1 5 5 1 2 5 4 1 5 4 2 7 3 1 5 4 4 1 2 5 3 2 2 4 1 3 3 4 4
YES 1 1 1 YES 5 7 9 9 5 NO
2 seconds
256 megabytes
['*special problem', 'graphs', 'greedy', '*1600']
C. Spring Cleaningtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputTanya wants to organize her bookcase. There are n bookshelves in the bookcase, the i-th bookshelf contains a_i books on it. Tanya will be satisfied if each bookshelf contains no more than k books.Tany...
6 5 4 3 5 1 2 2 3 5 5 3 4 5 1 5 1 5 5 5 4 5 6 1 2 5 3 5 4 3 2 10 4 4 1 1 4 3 10 2 4 4 1 1 4 1 5 4 1 2 1 3
3 9 6 4 2 9
2 seconds
256 megabytes
['*special problem', 'greedy', 'sortings', '*1600']
B. Boot Camptime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputBerland State University (BSU) is conducting a programming boot camp. The boot camp will last for n days, and the BSU lecturers are planning to give some number of lectures during these days.Some days of th...
4 4 5 7 1011 4 4 10 0101 5 3 4 11011 6 4 6 011101
12 8 8 14
2 seconds
256 megabytes
['*special problem', 'greedy', '*1400']
A. Color Revolutiontime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputHmm, how long has it been since the last color revolution? 5 years?! It's totally the time to make a new one!So the general idea is the following. Division 1 should have n_1 participants. Division 2 s...
4 40 3 1200 7 320802005 400 4 1
1 3 9 27 3 21 147 1029 5 2000 800000 320000000 1 1 1 1
1 second
256 megabytes
['*special problem', 'math', '*1000']
B. Card Constructionstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputA card pyramid of height 1 is constructed by resting two cards against each other. For h>1, a card pyramid of height h is constructed by placing a card pyramid of height h-1 onto a base. A base cons...
5 3 14 15 24 1
1 2 1 3 0
1 second
256 megabytes
['binary search', 'brute force', 'dp', 'math', '*1100']
A. Puzzle Piecestime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a special jigsaw puzzle consisting of n\cdot m identical pieces. Every piece has three tabs and one blank, as pictured below. The jigsaw puzzle is considered solved if the following condit...
3 1 3 100000 100000 2 2
YES NO YES
1 second
256 megabytes
['math', '*800']
F. Piet's Palettetime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputPiet Mondrian is an artist most famous for his minimalist works, consisting only of the four colors red, yellow, blue, and white. Most people attribute this to his style, but the truth is that his pain...
3 2 mix 2 2 1 R mix 2 1 3 Y
YES YB.
2 seconds
256 megabytes
['matrices', '*3200']
E. Train Trackstime limit per test5 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThat's right. I'm a Purdue student, and I shamelessly wrote a problem about trains.There are n stations and m trains. The stations are connected by n-1 one-directional railroads that form a tree rooted a...
5 4 1 2 1 1 3 2 3 4 1 3 5 3 2 1 4 2 2 6 5 10
-1 6
5 seconds
256 megabytes
['data structures', 'trees', '*3100']
D. Résumé Reviewtime limit per test4 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputUh oh! Applications to tech companies are due soon, and you've been procrastinating by doing contests instead! (Let's pretend for now that it is actually possible to get a job in these uncertain times.)...
10 32 1 2 3 4 5 5 5 5 5 5
1 2 3 3 3 4 4 4 4 4
4 seconds
256 megabytes
['binary search', 'greedy', 'math', '*2700']
C. Quantifier Questiontime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputLogical quantifiers are very useful tools for expressing claims about a set. For this problem, let's focus on the set of real numbers specifically. The set of real numbers includes zero and negativ...
2 1 1 2
1 AE
1 second
256 megabytes
['dfs and similar', 'dp', 'graphs', 'math', '*2600']
B. Monopole Magnetstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputA monopole magnet is a magnet that only has one pole, either north or south. They don't actually exist since real magnets have two poles, but this is a programming contest problem, so we don't care.T...
3 3 .#. ### ##.
1
2 seconds
256 megabytes
['constructive algorithms', 'dfs and similar', 'dsu', 'graphs', '*2000']
A. Hilbert's Hoteltime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputHilbert's Hotel is a very unusual hotel since the number of rooms is infinite! In fact, there is exactly one room for every integer, including zero and negative integers. Even stranger, the hotel is cu...
6 1 14 2 1 -1 4 5 5 5 1 3 3 2 1 2 0 1 5 -239 -2 -100 -3 -11
YES YES YES NO NO YES
1 second
256 megabytes
['math', 'number theory', 'sortings', '*1600']
F. Restore the Permutation by Sorted Segmentstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputWe guessed a permutation p consisting of n integers. The permutation of length n is the array of length n where each element from 1 to n appears exactly once. This permutati...
5 6 3 2 5 6 2 4 6 3 1 3 4 2 1 3 4 1 2 4 6 5 2 2 3 2 1 2 2 1 4 2 4 5 7 3 1 2 6 4 1 3 5 6 2 1 2 3 4 5 7 6 1 2 3 4 5 6 3 1 3 6 2 2 1 2 5 2 2 5 3 2 3 5 4 2 3 4 5 5 1 2 3 4 5
3 1 4 6 2 5 3 2 1 4 5 2 1 6 3 5 4 7 1 2 2 5 3 4 1
2 seconds
256 megabytes
['brute force', 'constructive algorithms', 'data structures', 'greedy', 'implementation', '*2400']
E. Weights Distributingtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given an undirected unweighted graph consisting of n vertices and m edges (which represents the map of Bertown) and the array of prices p of length m. It is guaranteed that there is a pat...
2 4 3 2 3 4 1 2 3 1 2 1 3 1 4 7 9 1 5 7 2 10 4 8 5 6 7 3 3 1 2 1 3 1 4 3 2 3 5 4 2 5 6 1 7 6 7
7 12
2 seconds
256 megabytes
['brute force', 'graphs', 'greedy', 'shortest paths', 'sortings', '*2100']
D. Constant Palindrome Sumtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given an array a consisting of n integers (it is guaranteed that n is even, i.e. divisible by 2). All a_i does not exceed some integer k.Your task is to replace the minimum number of el...
4 4 2 1 2 1 2 4 3 1 2 2 1 8 7 6 1 1 7 6 3 4 6 6 6 5 2 6 1 3 4
0 1 4 2
1 second
256 megabytes
['brute force', 'data structures', 'greedy', 'two pointers', '*1700']
C. Alternating Subsequencetime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputRecall that the sequence b is a a subsequence of the sequence a if b can be derived from a by removing zero or more elements without changing the order of the remaining elements. For example, i...
4 5 1 2 3 -1 -2 4 -1 -2 -1 -3 10 -2 8 3 8 -4 -15 5 -2 -3 1 6 1 -1000000000 1 -1000000000 1 -1000000000
2 -1 6 -2999999997
1 second
256 megabytes
['dp', 'greedy', 'two pointers', '*1200']
B. Balanced Arraytime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a positive integer n, it is guaranteed that n is even (i.e. divisible by 2).You want to construct the array a of length n such that: The first \frac{n}{2} elements of a are even (divisib...
5 2 4 6 8 10
NO YES 2 4 1 5 NO YES 2 4 6 8 1 3 5 11 NO
1 second
256 megabytes
['constructive algorithms', 'math', '*800']
A. Candiestime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputRecently Vova found n candy wrappers. He remembers that he bought x candies during the first day, 2x candies during the second day, 4x candies during the third day, \dots, 2^{k-1} x candies during the k-th day...
7 3 6 7 21 28 999999999 999999984
1 2 1 7 4 333333333 333333328
1 second
256 megabytes
['brute force', 'math', '*900']
F. Make It Ascendingtime limit per test7 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputYou are given an array a consisting of n elements. You may apply several operations (possibly zero) to it.During each operation, you choose two indices i and j (1 \le i, j \le n; i \ne j), increase ...
4 8 2 1 3 5 1 2 4 5 15 16384 8192 4096 2048 1024 512 256 128 64 32 16 8 4 2 1 2 3 3 14 1 2 3 4 5 6 7 8 9 10 11 12 13 14
3 6 8 1 6 4 1 7 1 15 1 13 1 11 1 9 1 7 1 5 1 3 1 2 1 0
7 seconds
512 megabytes
['bitmasks', 'brute force', 'dp', '*3000']
E. Placing Rookstime limit per test2 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputCalculate the number of ways to place n rooks on n \times n chessboard so that both following conditions are met: each empty cell is under attack; exactly k pairs of rooks attack each other. An empty ...
3 2
6
2 seconds
512 megabytes
['combinatorics', 'fft', 'math', '*2300']
D. Multiple Testcasestime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputSo you decided to hold a contest on Codeforces. You prepared the problems: statements, solutions, checkers, validators, tests... Suddenly, your coordinator asks you to change all your tests to mult...
4 3 1 2 2 3 4 1 1
3 1 2 2 1 3 1 2
2 seconds
256 megabytes
['binary search', 'constructive algorithms', 'data structures', 'greedy', 'sortings', 'two pointers', '*1900']
C. Yet Another Counting Problemtime limit per test3.5 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given two integers a and b, and q queries. The i-th query consists of two numbers l_i and r_i, and the answer to it is the number of integers x such that l_i \le x \le r_i, and ...
2 4 6 5 1 1 1 3 1 5 1 7 1 9 7 10 2 7 8 100 200
0 0 0 2 4 0 91
3.5 seconds
256 megabytes
['math', 'number theory', '*1600']
B. Binary Periodtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputLet's say string s has period k if s_i = s_{i + k} for all i from 1 to |s| - k (|s| means length of string s) and k is the minimum positive integer with this property.Some examples of a period: for s="0...
4 00 01 111 110
00 01 11111 1010
2 seconds
256 megabytes
['constructive algorithms', 'strings', '*1100']
A. Road To Zerotime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given two integers x and y. You can perform two types of operations: Pay a dollars and increase or decrease any of these integers by 1. For example, if x = 0 and y = 7 there are four possible ou...
2 1 3 391 555 0 0 9 4
1337 0
1 second
256 megabytes
['greedy', 'math', '*1000']
B. Nastya and Doortime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputOn February 14 Denis decided to give Valentine to Nastya and did not come up with anything better than to draw a huge red heart on the door of the length k (k \ge 3). Nastya was very confused by this p...
5 8 6 1 2 4 1 2 4 1 2 5 3 3 2 3 2 1 10 4 4 3 4 3 2 3 2 1 0 1 15 7 3 7 4 8 2 3 4 5 21 2 3 4 2 1 3 7 5 1 2 3 4 5 6 1
3 2 2 2 2 1 3 1 2 3
1 second
256 megabytes
['greedy', 'implementation', '*1300']
A. Nastya and Ricetime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputNastya just made a huge mistake and dropped a whole package of rice on the floor. Mom will come soon. If she sees this, then Nastya will be punished.In total, Nastya dropped n grains. Nastya read that ...
5 7 20 3 101 18 11 11 10 234 2 8 9 7 250 122 19 41 21 321 10 3 10 8 6 1
Yes No Yes No Yes
1 second
256 megabytes
['math', '*900']
F. Nastya and CBStime limit per test4 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard output Nastya is a competitive programmer, but she is only studying now. Recently, Denis told her about the way to check if the string is correct bracket sequence. After that, unexpectedly, Nastya came up wi...
2 1 1 -1 1 2 1 2
Yes
4 seconds
256 megabytes
['brute force', 'data structures', 'hashing', '*3300']
E. Nastya and Beestime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputUnfortunately, a mistake was found in the proof of the author's solution to this problem. Currently, we don't know the absolutely correct solution. However, you can solve this task, but if your solutio...
5 5 1 2 2 3 3 4 4 5 5 1 4 5
1 1 2 1 5 3
1 second
256 megabytes
['graphs', 'interactive', 'probabilities', '*3000']
D. Nastya and Time Machinetime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard output Denis came to Nastya and discovered that she was not happy to see him... There is only one chance that she can become happy. Denis wants to buy all things that Nastya likes so she will certai...
5 1 2 2 3 2 4 4 5
13 1 0 2 1 3 2 3 1 2 2 4 3 4 1 5 2 5 1 4 2 2 3 2 0 1 1
2 seconds
256 megabytes
['constructive algorithms', 'dfs and similar', 'graphs', 'trees', '*2600']
C. Nastya and Unexpected Guesttime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard output If the girl doesn't go to Denis, then Denis will go to the girl. Using this rule, the young man left home, bought flowers and went to Nastya. On the way from Denis's house to the girl's ho...
15 5 0 3 7 14 15 11 11
45
1 second
256 megabytes
['dfs and similar', 'dp', 'graphs', 'shortest paths', '*2400']
B. Nastya and Scoreboardtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard output Denis, after buying flowers and sweets (you will learn about this story in the next task), went to a date with Nastya to ask her to become a couple. Now, they are sitting in the cafe and finally...
1 7 0000000
8
1 second
256 megabytes
['bitmasks', 'dp', 'graphs', 'greedy', '*1700']
A. Nastya and Strange Generatortime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard output Denis was very sad after Nastya rejected him. So he decided to walk through the gateways to have some fun. And luck smiled at him! When he entered the first courtyard, he met a strange ma...
5 5 2 3 4 5 1 1 1 3 1 3 2 4 4 2 3 1 5 1 5 2 4 3
Yes Yes No Yes No
1 second
256 megabytes
['brute force', 'data structures', 'greedy', 'implementation', '*1500']
B. Sorted Adjacent Differencestime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou have array of n numbers a_{1}, a_{2}, \ldots, a_{n}. Rearrange these numbers to satisfy |a_{1} - a_{2}| \le |a_{2} - a_{3}| \le \ldots \le |a_{n-1} - a_{n}|, where |x| denotes absolute ...
2 6 5 -2 4 8 6 5 4 8 1 4 2
5 5 4 6 8 -2 1 2 4 8
1 second
256 megabytes
['constructive algorithms', 'sortings', '*1200']
A. Filling Diamondstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou have integer n. Calculate how many ways are there to fully cover belt-like area of 4n-2 triangles with diamond shapes. Diamond shape consists of two triangles. You can move, rotate or flip the sha...
2 2 1
2 1
1 second
256 megabytes
['brute force', 'dp', 'implementation', 'math', '*900']
E. JYPnationtime limit per test2 secondsmemory limit per test1024 megabytesinputstandard inputoutputstandard outputDue to the success of TWICE, JYP Entertainment has earned countless money and emerged as the biggest entertainment firm by market capitalization. Therefore, the boss, JYP, has decided to create a new natio...
4 7 2 1 4
7380
2 seconds
1024 megabytes
['graphs', '*3500']
D. Nested Rubber Bandstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou have a tree of n vertices. You are going to convert this tree into n rubber bands on infinitely large plane. Conversion rule follows: For every pair of vertices a and b, rubber bands a and b s...
6 1 3 2 3 3 4 4 5 4 6
4
1 second
256 megabytes
['constructive algorithms', 'dfs and similar', 'dp', 'math', 'trees', '*2700']
C. Perfect Triplestime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputConsider the infinite sequence s of positive integers, created by repeating the following steps: Find the lexicographically smallest triple of positive integers (a, b, c) such that a \oplus b \oplu...
9 1 2 3 4 5 6 7 8 9
1 2 3 4 8 12 5 10 15
2 seconds
256 megabytes
['bitmasks', 'brute force', 'constructive algorithms', 'divide and conquer', 'math', '*2200']
B. Edge Weight Assignmenttime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou have unweighted tree of n vertices. You have to assign a positive weight to each edge so that the following condition would hold: For every two different leaves v_{1} and v_{2} of this tree...
6 1 3 2 3 3 4 4 5 5 6
1 4
1 second
256 megabytes
['bitmasks', 'constructive algorithms', 'dfs and similar', 'greedy', 'math', 'trees', '*1800']
A. Powered Additiontime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou have an array a of length n. For every positive integer x you are going to perform the following operation during the x-th second: Select some distinct indices i_{1}, i_{2}, \ldots, i_{k} which a...
3 4 1 7 6 5 5 1 2 3 4 5 2 0 -4
2 0 3
1 second
256 megabytes
['greedy', 'math', '*1500']
B. Kana and Dragon Quest gametime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputKana was just an ordinary high school girl before a talent scout discovered her. Then, she became an idol. But different from the stereotype, she is also a gameholic. One day Kana gets inter...
7 100 3 4 189 3 4 64 2 3 63 2 3 30 27 7 10 9 1 69117 21 2
YES NO NO YES YES YES YES
1 second
256 megabytes
['greedy', 'implementation', 'math', '*900']
A. Ichihime and Triangletime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputIchihime is the current priestess of the Mahjong Soul Temple. She claims to be human, despite her cat ears.These days the temple is holding a math contest. Usually, Ichihime lacks interest in the...
4 1 3 5 7 1 5 5 7 100000 200000 300000 400000 1 1 977539810 977539810
3 4 5 5 5 5 182690 214748 300999 1 977539810 977539810
1 second
256 megabytes
['constructive algorithms', 'math', '*800']
F. Journeytime limit per test4 secondsmemory limit per test1024 megabytesinputstandard inputoutputstandard outputIn the wilds far beyond lies the Land of Sacredness, which can be viewed as a tree  — connected undirected graph consisting of n nodes and n-1 edges. The nodes are numbered from 1 to n. There are m travelers...
8 4 1 1 7 1 2 2 5 4 6 6 3 6 2 6 8 7 8 3 8 2 6 4 1
4
4 seconds
1024 megabytes
['data structures', 'divide and conquer', 'graphs', 'trees', '*3500']
E2. Chiori and Doll Picking (hard version)time limit per test3 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputThis is the hard 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 l...
4 4 3 5 8 14
2 2 6 6 0
3 seconds
512 megabytes
['bitmasks', 'brute force', 'combinatorics', 'math', '*3500']