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
C. Sasha and a Patient Friendtime limit per test1.5 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputFedya and Sasha are friends, that's why Sasha knows everything about Fedya.Fedya keeps his patience in an infinitely large bowl. But, unlike the bowl, Fedya's patience isn't infinite, tha...
6 1 2 1 1 4 -3 3 1 6 1 3 1 6 3 3 1 6 4 3 1 6 5
5 5.666667 6 -1
1.5 seconds
256 megabytes
['binary search', 'data structures', 'implementation', '*2800']
B. Sasha and One More Nametime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputReading books is one of Sasha's passions. Once while he was reading one book, he became acquainted with an unusual character. The character told about himself like that: "Many are my names in m...
nolon
2
1 second
256 megabytes
['constructive algorithms', 'hashing', 'strings', '*1800']
A. Sasha and a Bit of Relaxtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputSasha likes programming. Once, during a very long contest, Sasha decided that he was a bit tired and needed to relax. So he did. But since Sasha isn't an ordinary guy, he prefers to relax unus...
Input51 2 3 4 5
Output1
1 second
256 megabytes
['dp', 'implementation', '*1600']
F. MST Unificationtime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given an undirected weighted connected graph with n vertices and m edges without loops and multiple edges.The i-th edge is e_i = (u_i, v_i, w_i); the distance between vertices u_i and v_i alon...
8 10 1 2 1 2 3 2 2 4 5 1 4 2 6 3 3 6 1 3 3 5 2 3 7 1 4 8 1 6 2 4
1
3 seconds
256 megabytes
['binary search', 'dsu', 'graphs', 'greedy', '*2100']
E2. Array and Segments (Hard version)time limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe only difference between easy and hard versions is a number of elements in the array.You are given an array a consisting of n integers. The value of the i-th element of the array...
5 4 2 -2 3 1 2 1 3 4 5 2 5 1 3
6 2 4 1
2 seconds
256 megabytes
['data structures', 'implementation', '*2100']
E1. Array and Segments (Easy version)time limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe only difference between easy and hard versions is a number of elements in the array.You are given an array a consisting of n integers. The value of the i-th element of the array...
5 4 2 -2 3 1 2 1 3 4 5 2 5 1 3
6 2 1 4
2 seconds
256 megabytes
['brute force', 'greedy', 'implementation', '*1800']
D. Diverse Garlandtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou have a garland consisting of n lamps. Each lamp is colored red, green or blue. The color of the i-th lamp is s_i ('R', 'G' and 'B' — colors of lamps in the garland).You have to recolor some lamps i...
9 RBGRRBRGG
2 RBGRGBRGR
1 second
256 megabytes
['constructive algorithms', 'dp', 'greedy', '*1400']
C. Nice Garlandtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou have a garland consisting of n lamps. Each lamp is colored red, green or blue. The color of the i-th lamp is s_i ('R', 'G' and 'B' — colors of lamps in the garland).You have to recolor some lamps in t...
3 BRB
1 GRB
1 second
256 megabytes
['brute force', 'greedy', 'math', '*1300']
B. Divisors of Two Integerstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputRecently you have received two positive integer numbers x and y. You forgot them, but you remembered a shuffled list containing all divisors of x (including 1 and x) and all divisors of y (inc...
10 10 2 8 1 2 4 1 20 4 5
20 8
1 second
256 megabytes
['brute force', 'greedy', 'math', 'number theory', '*1100']
A. Two distinct pointstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given two segments [l_1; r_1] and [l_2; r_2] on the x-axis. It is guaranteed that l_1 < r_1 and l_2 < r_2. Segments may intersect, overlap or even coincide with each other. The example of ...
5 1 2 1 2 2 6 3 4 2 4 1 3 1 2 1 3 1 4 5 8
2 1 3 4 3 2 1 2 3 7
1 second
256 megabytes
['implementation', '*800']
G. Vasya and Maximum Profittime limit per test3.5 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputVasya got really tired of these credits (from problem F) and now wants to earn the money himself! He decided to make a contest to gain a profit.Vasya has n problems to choose from. They are...
5 10 1 15 5 3 6 11 7 2 11 22
13
3.5 seconds
256 megabytes
['binary search', 'constructive algorithms', 'data structures', 'dp', 'dsu', '*2400']
F. Vasya and Endless Creditstime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputVasya wants to buy himself a nice new car. Unfortunately, he lacks some money. Currently he has exactly 0 burles.However, the local bank has n credit offers. Each offer can be described with...
4 10 9 2 20 33 1 30 115 1 5 3 2
32
3 seconds
256 megabytes
['dp', 'flows', 'graph matchings', 'graphs', 'sortings', '*2600']
E. Vasya and Binary Stringtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputVasya has a string s of length n consisting only of digits 0 and 1. Also he has an array a of length n. Vasya performs the following operation until the string becomes empty: choose some conse...
7 1101001 3 4 9 100 1 2 3
109
2 seconds
256 megabytes
['dp', '*2400']
D. Compressiontime limit per test2.5 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a binary matrix A of size n \times n. Let's denote an x-compression of the given matrix as a matrix B of size \frac{n}{x} \times \frac{n}{x} such that for every i \in [1, n], j \in [1, n] ...
8 E7 E7 E7 00 00 E7 E7 E7
1
2.5 seconds
256 megabytes
['dp', 'implementation', 'math', 'number theory', '*1800']
C. Brutalitytime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are playing a new famous fighting game: Kortal Mombat XII. You have to perform a brutality on your opponent's character.You are playing the game on the new generation console so your gamepad have 26 butt...
7 3 1 5 16 18 7 2 10 baaaaca
54
1 second
256 megabytes
['greedy', 'sortings', 'two pointers', '*1300']
B. Digital roottime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputToday at the lesson of mathematics, Petya learns about the digital root.The digital root of a non-negative integer is the single digit value obtained by an iterative process of summing digits, on each ite...
3 1 5 5 2 3 1
5 38 19
1 second
256 megabytes
['math', 'number theory', '*1000']
A. Digits Sequence Dividingtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a sequence s consisting of n digits from 1 to 9.You have to divide it into at least two segments (segment — is a consecutive sequence of elements) (in other words, you have to pl...
4 6 654321 4 1337 2 33 4 2122
YES 3 6 54 321 YES 3 1 3 37 NO YES 2 21 22
1 second
256 megabytes
['greedy', 'strings', '*900']
F. Lunar New Year and a Recursive Sequencetime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputLunar New Year is approaching, and Bob received a gift from his friend recently — a recursive sequence! He loves this sequence very much and wants to play with it.Let f_1, f_2,...
3 2 3 5 4 16
4
3 seconds
256 megabytes
['math', 'matrices', 'number theory', '*2400']
E. Lunar New Year and Red Envelopestime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputLunar New Year is approaching, and Bob is going to receive some red envelopes with countless money! But collecting money from red envelopes is a time-consuming process itself.Let's de...
5 0 2 1 3 4 5 2 5 5 8
13
3 seconds
256 megabytes
['data structures', 'dp', '*2100']
D. Lunar New Year and a Wandertime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputLunar New Year is approaching, and Bob decides to take a wander in a nearby park.The park can be represented as a connected graph with n nodes and m bidirectional edges. Initially Bob is a...
3 2 1 2 1 3
1 2 3
3 seconds
256 megabytes
['data structures', 'dfs and similar', 'graphs', 'greedy', 'shortest paths', '*1500']
C. Lunar New Year and Number Divisiontime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputLunar New Year is approaching, and Bob is struggling with his homework – a number division problem.There are n positive integers a_1, a_2, \ldots, a_n on Bob's homework paper, where...
4 8 5 2 3
164
2 seconds
256 megabytes
['greedy', 'implementation', 'math', 'sortings', '*900']
B. Lunar New Year and Food Orderingtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputLunar New Year is approaching, and Bob is planning to go for a famous restaurant — "Alice's".The restaurant "Alice's" serves n kinds of food. The cost for the i-th kind is always c_i....
8 5 8 6 2 1 4 5 7 5 6 3 3 2 6 2 3 2 2 8 1 4 4 7 3 4 6 10
22 24 14 10 39
2 seconds
256 megabytes
['data structures', 'implementation', '*1500']
A. Lunar New Year and Cross Countingtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputLunar New Year is approaching, and you bought a matrix with lots of "crosses".This matrix M of size n \times n contains only 'X' and '.' (without quotes). The element in the i-th row...
5 ..... .XXX. .XXX. .XXX. .....
1
2 seconds
256 megabytes
['implementation', '*800']
E. Helping Hiasat time limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputHiasat registered a new account in NeckoForces and when his friends found out about that, each one of them asked to use his name as Hiasat's handle.Luckily for Hiasat, he can change his handle in some...
5 3 1 2 motarack 2 mike 1 2 light
2
2 seconds
256 megabytes
['bitmasks', 'brute force', 'dp', 'meet-in-the-middle', '*2200']
D. Kilani and the Gametime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputKilani is playing a game with his friends. This game can be represented as a grid of size n \times m, where each cell is either empty or blocked, and every player has one or more castles in some c...
3 3 2 1 1 1.. ... ..2
6 3
2 seconds
256 megabytes
['dfs and similar', 'graphs', 'implementation', 'shortest paths', '*1900']
C. Ayoub and Lost Arraytime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputAyoub had an array a of integers of size n and this array had two interesting properties: All the integers in the array were between l and r (inclusive). The sum of all the elements was divisib...
2 1 3
3
1 second
256 megabytes
['combinatorics', 'dp', 'math', '*1500']
B. Zuhair and Stringstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputGiven a string s of length n and integer k (1 \le k \le n). The string s has a level x, if x is largest non-negative integer, such that it's possible to find in s: x non-intersecting (non-overlappi...
8 2 aaacaabb
2
1 second
256 megabytes
['brute force', 'implementation', 'strings', '*1100']
A. Salem and Sticks time limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputSalem gave you n sticks with integer positive lengths a_1, a_2, \ldots, a_n.For every stick, you can change its length to any other positive integer length (that is, either shrink or stretch it). The...
3 10 1 4
3 7
1 second
256 megabytes
['brute force', 'implementation', '*1100']
B. Game with stringtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputTwo people are playing a game with a string s, consisting of lowercase latin letters. On a player's turn, he should choose two consecutive equal letters in the string and delete them. For example, if ...
abacaba
No
1 second
256 megabytes
['data structures', 'implementation', 'math', '*1200']
A. Splitting into digitstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputVasya has his favourite number n. He wants to split it to some non-zero digits. It means, that he wants to choose some digits d_1, d_2, \ldots, d_k, such that 1 \leq d_i \leq 9 for all i and d_1 ...
1
1 1
1 second
256 megabytes
['constructive algorithms', 'implementation', 'math', '*800']
E. Radix sumtime limit per test4 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputLet's define radix sum of number a consisting of digits a_1, \ldots ,a_k and number b consisting of digits b_1, \ldots ,b_k(we add leading zeroes to the shorter number to match longer length) as number s(a,...
2 5 6
1 2
4 seconds
256 megabytes
['fft', 'math', 'number theory', '*3400']
D. Professional layertime limit per test3 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputCardbluff is popular sport game in Telegram. Each Cardbluff player has ever dreamed about entrance in the professional layer. There are n judges now in the layer and you are trying to pass the entr...
3 6 30 30 30 100 4 5
18
3 seconds
512 megabytes
['bitmasks', 'dp', '*3100']
C. Johnny Solvingtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputToday is tuesday, that means there is a dispute in JOHNNY SOLVING team again: they try to understand who is Johnny and who is Solving. That's why guys asked Umnik to help them. Umnik gave guys a connect...
4 6 2 1 2 1 3 1 4 2 3 2 4 3 4
PATH 4 1 2 3 4
1 second
256 megabytes
['constructive algorithms', 'dfs and similar', 'graphs', 'math', '*2700']
B. Game with modulotime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputThis is an interactive problem.Vasya and Petya are going to play the following game: Petya has some positive integer number a. After that Vasya should guess this number using the following questions. ...
start x x start x x y start x x y y end
? 0 0 ? 10 1 ! 1 ? 0 0 ? 3 4 ? 2 5 ! 2 ? 2 4 ? 2 5 ? 3 10 ? 9 1 ! 3
1 second
256 megabytes
['binary search', 'constructive algorithms', 'interactive', '*2000']
A. Grid gametime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a 4x4 grid. You play a game — there is a sequence of tiles, each of them is either 2x1 or 1x2. Your task is to consequently place all tiles from the given sequence in the grid. When tile is pla...
010
1 1 1 2 1 4
1 second
256 megabytes
['constructive algorithms', 'implementation', '*1400']
F. Elongated Matrixtime limit per test4 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a matrix a, consisting of n rows and m columns. Each cell contains an integer in it.You can change the order of rows arbitrarily (including leaving the initial order), but you can't cha...
4 2 9 9 10 8 5 3 4 3
5
4 seconds
256 megabytes
['binary search', 'bitmasks', 'brute force', 'dp', 'graphs', '*2000']
E. Monotonic Renumerationtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given an array a consisting of n integers. Let's denote monotonic renumeration of array a as an array b consisting of n integers such that all of the following conditions are met: b_1 ...
5 1 2 1 2 3
2
2 seconds
256 megabytes
['combinatorics', 'sortings', '*1700']
D. Balanced Ternary Stringtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a string s consisting of exactly n characters, and each character is either '0', '1' or '2'. Such strings are called ternary strings.Your task is to replace minimum number of cha...
3 121
021
2 seconds
256 megabytes
['greedy', 'strings', '*1500']
C. Doors Breaking and Repairingtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are policeman and you are playing a game with Slavik. The game is turn-based and each turn consists of two phases. During the first phase you make your move and during the second phase...
6 3 2 2 3 1 3 4 2
6
1 second
256 megabytes
['games', '*1200']
B. Array K-Coloringtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given an array a consisting of n integer numbers.You have to color this array in k colors in such a way that: Each element of the array should be colored in some color; For each i from 1 t...
4 2 1 2 2 3
YES 1 1 2 2
2 seconds
256 megabytes
['greedy', 'sortings', '*1400']
A. Integer Sequence Dividingtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given an integer sequence 1, 2, \dots, n. You have to divide it into two sets A and B in such a way that each element belongs to exactly one set and |sum(A) - sum(B)| is minimum possi...
3
0
1 second
256 megabytes
['math', '*800']
G. (Zero XOR Subset)-lesstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given an array a_1, a_2, \dots, a_n of integer numbers.Your task is to divide the array into the maximum number of segments in such a way that: each element is contained in exactly one...
4 5 5 7 2
2
2 seconds
256 megabytes
['math', 'matrices', '*2300']
F. Trucks and Citiestime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere are n cities along the road, which can be represented as a straight line. The i-th city is situated at the distance of a_i kilometers from the origin. All cities are situated in the same direc...
7 6 2 5 7 10 14 15 17 1 3 10 0 1 7 12 7 4 5 13 3 4 7 10 1 4 7 10 1 1 5 11 2
55
2 seconds
256 megabytes
['binary search', 'dp', '*2400']
E. Polycarp's New Jobtime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputPolycarp has recently got himself a new job. He now earns so much that his old wallet can't even store all the money he has.Berland bills somehow come in lots of different sizes. However, all of th...
9 + 3 2 + 2 3 ? 1 20 ? 3 3 ? 2 3 + 1 5 ? 10 10 ? 1 5 + 1 1
NO YES YES YES NO
3 seconds
256 megabytes
['implementation', '*1500']
D. GCD Countingtime limit per test4.5 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a tree consisting of n vertices. A number is written on each vertex; the number on vertex i is equal to a_i.Let's denote the function g(x, y) as the greatest common divisor of the numbers...
Input32 3 41 22 3
Output1
4.5 seconds
256 megabytes
['data structures', 'dfs and similar', 'dp', 'number theory', 'trees', '*2000']
C. Division and Uniontime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere are n segments [l_i, r_i] for 1 \le i \le n. You should divide all segments into two non-empty groups in such way that there is no pair of segments from different groups which have at least o...
3 2 5 5 2 3 3 3 5 2 3 2 3 3 3 3 4 4 5 5
2 1 -1 1 1 2
2 seconds
256 megabytes
['sortings', '*1500']
B. Accordiontime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputAn accordion is a string (yes, in the real world accordions are musical instruments, but let's forget about it for a while) which can be represented as a concatenation of: an opening bracket (ASCII code 091...
|[a:b:|]
4
3 seconds
256 megabytes
['greedy', 'implementation', '*1300']
A. Minimum Integertime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given q queries in the following form:Given three integers l_i, r_i and d_i, find minimum positive integer x_i such that it is divisible by d_i and it does not belong to the segment [l_i, r_i]....
5 2 4 2 5 10 4 3 10 1 1 2 3 4 6 5
6 4 1 3 10
1 second
256 megabytes
['math', '*1000']
F. Ivan and Burgerstime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputIvan loves burgers and spending money. There are n burger joints on the street where Ivan lives. Ivan has q friends, and the i-th friend suggested to meet at the joint l_i and walk to the joint r_i (...
Input47 2 3 431 42 31 3
Output737
3 seconds
256 megabytes
['data structures', 'divide and conquer', 'greedy', 'math', '*2500']
E. Andrew and Taxitime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputAndrew prefers taxi to other means of transport, but recently most taxi drivers have been acting inappropriately. In order to earn more money, taxi drivers started to drive in circles. Roads in Andrew...
Input5 62 1 15 2 62 3 23 4 34 5 51 5 4
Output2 21 3
2 seconds
256 megabytes
['binary search', 'dfs and similar', 'graphs', '*2200']
D. Dasha and Chesstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThis is an interactive task.Dasha and NN like playing chess. While playing a match they decided that normal chess isn't interesting enough for them, so they invented a game described below.There are 6...
Input999 9991 11 22 12 21 32 3<...>26 1326 1426 1526 161 700 8002 1 2<...>-1 -1 -1
Output999 998999 997<...>999 26
2 seconds
256 megabytes
['constructive algorithms', 'games', 'interactive', '*2500']
C. NN and the Optical Illusiontime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputNN is an experienced internet user and that means he spends a lot of time on the social media. Once he found the following image on the Net, which asked him to compare the sizes of inner c...
Input3 1
Output6.4641016
2 seconds
256 megabytes
['binary search', 'geometry', 'math', '*1200']
B. Build a Contesttime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputArkady coordinates rounds on some not really famous competitive programming platform. Each round features n problems of distinct difficulty, the difficulties are numbered from 1 to n.To hold a round Ar...
3 11 2 3 1 2 2 2 3 2 2 3 1
00100000001
1 second
256 megabytes
['data structures', 'implementation', '*1300']
A. Roman and Browsertime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputThis morning, Roman woke up and opened the browser with n opened tabs numbered from 1 to n. There are two kinds of tabs: those with the information required for the test and those with social network...
4 2 1 1 -1 1
2
1 second
256 megabytes
['implementation', '*1000']
F. Cookiestime limit per test3 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputMitya and Vasya are playing an interesting game. They have a rooted tree with n vertices, and the vertices are indexed from 1 to n. The root has index 1. Every other vertex i \ge 2 has its parent p_i, and ver...
5 26 1 5 1 7 7 1 3 2 2 2 1 1 1 1 2 0 2 0
11
3 seconds
512 megabytes
['binary search', 'data structures', 'dfs and similar', 'dp', 'games', 'trees', '*2400']
C. Postcardtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputAndrey received a postcard from Irina. It contained only the words "Hello, Andrey!", and a strange string consisting of lowercase Latin letters, snowflakes and candy canes. Andrey thought that this string is ...
hw?ap*yn?eww*ye*ar 12
happynewyear
1 second
256 megabytes
['constructive algorithms', 'implementation', '*1200']
B. Squares and Segmentstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputLittle Sofia is in fourth grade. Today in the geometry lesson she learned about segments and squares. On the way home, she decided to draw n squares in the snow with a side length of 1. For simpli...
1
2
1 second
256 megabytes
['binary search', 'constructive algorithms', 'math', '*1100']
A. Snowballtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputToday's morning was exceptionally snowy. Meshanya decided to go outside and noticed a huge snowball rolling down the mountain! Luckily, there are two stones on that mountain.Initially, snowball is at height h...
4 3 1 1 1 2
8
1 second
256 megabytes
['implementation', '*800']
F. Ж-functiontime limit per test6 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputThe length of the longest common prefix of two strings s=s_1 s_2 \ldots s_n and t = t_1 t_2 \ldots t_m is defined as the maximum k \le \min(n, m) such that s_1 s_2 \ldots s_k equals t_1 t_2 \ldots t_k. Let...
abbd 4 2 3 1 3 3 3 1 4
3 3 1 4
6 seconds
512 megabytes
['string suffix structures', 'strings', '*3500']
E. Fedya the Pottertime limit per test2.5 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputFedya loves problems involving data structures. Especially ones about different queries on subsegments. Fedya had a nice array a_1, a_2, \ldots a_n and a beautiful data structure. This data structu...
2 6 3
6
2.5 seconds
256 megabytes
['binary search', 'implementation', 'math', 'number theory', '*3400']
D. Eelstime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputVasya is a big fish lover, and his parents gave him an aquarium for the New Year. Vasya does not have a degree in ichthyology, so he thinks that filling a new aquarium with eels is a good idea. Unfortunately, ee...
2 + 1 - 1
0 0
3 seconds
256 megabytes
['data structures', '*2800']
C. Construct a treetime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputMisha walked through the snowy forest and he was so fascinated by the trees to decide to draw his own tree!Misha would like to construct a rooted tree with n vertices, indexed from 1 to n, where the r...
3 5
Yes 1 1
1 second
256 megabytes
['binary search', 'constructive algorithms', 'dfs and similar', 'graphs', 'greedy', 'trees', '*2400']
B. Nice tabletime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given an n \times m table, consisting of characters «A», «G», «C», «T». Let's call a table nice, if every 2 \times 2 square contains all four distinct characters. Your task is to find a nice table (...
2 2 AG CT
AG CT
1 second
256 megabytes
['brute force', 'constructive algorithms', 'greedy', 'math', '*2100']
A. Sum in the treetime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputMitya has a rooted tree with n vertices indexed from 1 to n, where the root has index 1. Each vertex v initially had an integer number a_v \ge 0 written on it. For every vertex v Mitya has computed s_...
5 1 1 1 1 1 -1 -1 -1 -1
1
2 seconds
256 megabytes
['constructive algorithms', 'dfs and similar', 'greedy', 'trees', '*1600']
H. Mateusz and an Infinite Sequencetime limit per test7 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputA Thue-Morse-Radecki-Mateusz sequence (Thorse-Radewoosh sequence in short) is an infinite sequence constructed from a finite sequence \mathrm{gen} of length d and an integer m, obtain...
2 2 0 1 4 0 1 1 0 2 21
6
7 seconds
512 megabytes
['bitmasks', 'brute force', 'dp', 'strings', '*3400']
G. Vladislav and a Great Legendtime limit per test3 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputA great legend used to be here, but some troll hacked Codeforces and erased it. Too bad for us, but in the troll society he earned a title of an ultimate-greatest-over troll. At least for...
4 1 1 2 2 3 2 4
21
3 seconds
512 megabytes
['combinatorics', 'dp', 'trees', '*3000']
F. Alex and a TV Showtime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputAlex decided to try his luck in TV shows. He once went to the quiz named "What's That Word?!". After perfectly answering the questions "How is a pseudonym commonly referred to in the Internet?" ("U...
4 13 1 1 1 1 2 4 1 3 6 4 4 4 1 4 4 2 2 1 2 2 3 3 4 4 4 4 3 2 2 3 4 2 1 4 2 2 4 2 3 4 2 4
010101
3 seconds
256 megabytes
['bitmasks', 'combinatorics', 'number theory', '*2500']
E. Egor and an RPG gametime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputOne Saturday afternoon Egor was playing his favorite RPG game. While discovering new lands and territories, he came across the following sign: Egor is a passionate player, but he is an algorithm...
3 4 4 3 1 2 6 4 5 6 1 3 2 10 1 2 3 4 5 6 7 8 9 10
2 3 4 3 1 1 2 3 2 4 1 2 5 6 2 3 2 1 10 1 2 3 4 5 6 7 8 9 10
2 seconds
256 megabytes
['constructive algorithms', 'greedy', '*3400']
D. Makoto and a Blackboardtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputMakoto has a big blackboard with a positive integer n written on it. He will perform the following action exactly k times:Suppose the number currently written on the blackboard is v. He will r...
6 1
3
2 seconds
256 megabytes
['dp', 'math', 'number theory', 'probabilities', '*2200']
C. Yuhao and a Parenthesistime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputOne day, Yuhao came across a problem about checking if some bracket sequences are correct bracket sequences.A bracket sequence is any non-empty sequence of opening and closing parentheses. A b...
7 )()) ) (( (( ( ) )
2
2 seconds
256 megabytes
['greedy', 'implementation', '*1400']
B. Petr and a Combination Locktime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputPetr has just bought a new car. He's just arrived at the most known Petersburg's petrol station to refuel it when he suddenly discovered that the petrol tank is secured with a combination l...
3 10 20 30
YES
1 second
256 megabytes
['bitmasks', 'brute force', 'dp', '*1200']
A. Gennady and a Card Gametime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputGennady owns a small hotel in the countryside where he lives a peaceful life. He loves to take long walks, watch sunsets and play cards with tourists staying in his hotel. His favorite game is ...
AS 2H 4C TH JH AD
YES
1 second
256 megabytes
['brute force', 'implementation', '*800']
G. Lucky Ticketstime limit per test5 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputAll bus tickets in Berland have their numbers. A number consists of n digits (n is even). Only k decimal digits d_1, d_2, \dots, d_k can be used to form ticket numbers. If 0 is among these digits, then ...
Input4 21 8
Output6
5 seconds
256 megabytes
['divide and conquer', 'dp', 'fft', '*2400']
F. Inversion Expectationtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputA permutation of size n is an array of size n such that each integer from 1 to n occurs exactly once in this array. An inversion in a permutation p is a pair of indices (i, j) such that i > j an...
3 3 -1 -1
499122179
2 seconds
256 megabytes
['dp', 'math', 'probabilities', '*2300']
E. The Top Scorertime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputHasan loves playing games and has recently discovered a game called TopScore. In this soccer-like game there are p players doing penalty shoot-outs. Winner is the one who scores the most. In case of ti...
Input2 6 3
Output124780545
3 seconds
256 megabytes
['combinatorics', 'dp', 'math', 'probabilities', '*2500']
D. Easy Problemtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputVasya is preparing a contest, and now he has written a statement for an easy problem. The statement is a string of length n consisting of lowercase Latin latters. Vasya thinks that the statement can be c...
6 hhardh 3 2 9 11 7 1
5
2 seconds
256 megabytes
['dp', '*1800']
C. Polygon for the Angletime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given an angle \text{ang}. The Jury asks You to find such regular n-gon (regular polygon with n vertices) that it has three vertices a, b and c (they can be non-consecutive) with \angle{...
4 54 50 2 178
10 18 90 180
2 seconds
256 megabytes
['brute force', 'geometry', '*1600']
B. Substring Removaltime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a string s of length n consisting only of lowercase Latin letters.A substring of a string is a contiguous subsequence of that string. So, string "forces" is substring of string "codefor...
4 abaa
6
1 second
256 megabytes
['combinatorics', 'math', 'strings', '*1300']
A. Find Divisibletime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a range of positive integers from l to r.Find such a pair of integers (x, y) that l \le x, y \le r, x \ne y and x divides y.If there are multiple answers, print any of them.You are also a...
3 1 10 3 14 1 10
1 7 3 9 5 10
2 seconds
256 megabytes
['greedy', 'implementation', 'math', '*800']
F. Make It Connectedtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given an undirected graph consisting of n vertices. A number is written on each vertex; the number on vertex i is a_i. Initially there are no edges in the graph.You may add some edges to thi...
3 2 1 3 3 2 3 5 2 1 1
5
2 seconds
256 megabytes
['dsu', 'graphs', 'greedy', '*1900']
E. Almost Regular Bracket Sequencetime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a bracket sequence s consisting of n opening '(' and closing ')' brackets.A regular bracket sequence is a bracket sequence that can be transformed into a correct arithmet...
6 (((())
3
3 seconds
256 megabytes
['implementation', '*1900']
D. Circular Dancetime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere are n kids, numbered from 1 to n, dancing in a circle around the Christmas tree. Let's enumerate them in a clockwise direction as p_1, p_2, ..., p_n (all these numbers are from 1 to n and are dis...
5 3 5 1 4 2 4 1 5 2 3
3 2 4 1 5
3 seconds
256 megabytes
['implementation', '*1600']
C. Powers Of Twotime limit per test4 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputA positive integer x is called a power of two if it can be represented as x = 2^y, where y is a non-negative integer. So, the powers of two are 1, 2, 4, 8, 16, \dots.You are given two positive integers ...
9 4
YES 1 2 2 4
4 seconds
256 megabytes
['bitmasks', 'greedy', '*1400']
B. Array Stabilizationtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given an array a consisting of n integer numbers.Let instability of the array be the following value: \max\limits_{i = 1}^{n} a_i - \min\limits_{i = 1}^{n} a_i.You have to remove exactly on...
4 1 3 3 7
2
1 second
256 megabytes
['implementation', '*900']
A. Repeating Ciphertime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputPolycarp loves ciphers. He has invented his own cipher called repeating.Repeating cipher is used for strings. To encrypt the string s=s_{1}s_{2} \dots s_{m} (1 \le m \le 10), Polycarp uses the followi...
6 baabbb
bab
1 second
256 megabytes
['implementation', '*800']
G. Multidimensional Queriestime limit per test6 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputYou are given an array a of n points in k-dimensional space. Let the distance between two points a_x and a_y be \sum \limits_{i = 1}^{k} |a_{x, i} - a_{y, i}| (it is also known as Manhattan d...
5 2 1 2 2 3 3 4 4 5 5 6 7 2 1 5 2 1 3 2 3 5 1 5 -1 -2 2 1 5 1 4 -1 -2 2 1 5
8 4 4 12 10
6 seconds
512 megabytes
['bitmasks', 'data structures', '*2300']
F. Vasya and Arraytime limit per test2 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputVasya has got an array consisting of n integers, and two integers k and len in addition. All numbers in the array are either between 1 and k (inclusive), or equal to -1. The array is good if there is ...
5 2 3 1 -1 1 -1 2
2
2 seconds
512 megabytes
['dp', '*2400']
E. Intersection of Permutationstime limit per test6 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputYou are given two permutations a and b, both consisting of n elements. Permutation of n elements is such a integer sequence that each value from 1 to n appears exactly once in it.You are ...
6 7 5 1 4 2 3 6 2 5 3 1 4 6 1 1 2 4 5 2 2 4 1 1 2 4 5 1 2 3 3 5 1 1 6 1 2 2 4 1 1 4 4 1 3
1 1 1 2 0
6 seconds
512 megabytes
['data structures', '*2400']
D. Beautiful Graphtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given an undirected unweighted graph consisting of n vertices and m edges.You have to write a number on each vertex of the graph. Each number should be 1, 2 or 3. The graph becomes beautiful i...
2 2 1 1 2 4 6 1 2 1 3 1 4 2 3 2 4 3 4
4 0
2 seconds
256 megabytes
['dfs and similar', 'graphs', '*1700']
C. Mishka and the Last Examtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputMishka is trying really hard to avoid being kicked out of the university. In particular, he was doing absolutely nothing for the whole semester, miraculously passed some exams so that just on...
4 5 6
2 3 3 3
2 seconds
256 megabytes
['greedy', '*1300']
B. Letters Rearrangingtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a string s consisting only of lowercase Latin letters.You can rearrange all letters of this string as you wish. Your task is to obtain a good string by rearranging the letters of the ...
3 aa abacaba xdd
-1 abaacba xdd
1 second
256 megabytes
['constructive algorithms', 'greedy', 'sortings', 'strings', '*900']
A. Dice Rollingtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputMishka got a six-faced dice. It has integer numbers from 2 to 7 written on its faces (all numbers on faces are different, so this is an almost usual dice).Mishka wants to get exactly x points by rolling h...
4 2 13 37 100
1 3 8 27
1 second
256 megabytes
['math', '*800']
F. Tree with Maximum Costtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a tree consisting exactly of n vertices. Tree is a connected undirected graph with n-1 edges. Each vertex v of this tree has a value a_v assigned to it.Let dist(x, y) be the dista...
8 9 4 1 7 10 1 6 5 1 2 2 3 1 4 1 5 5 6 5 7 5 8
121
2 seconds
256 megabytes
['dfs and similar', 'dp', 'trees', '*1900']
E. Minimal Diameter Foresttime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a forest — an undirected graph with n vertices such that each its connected component is a tree.The diameter (aka "longest shortest path") of a connected undirected graph is the ...
4 2 1 2 2 3
2 4 2
2 seconds
256 megabytes
['constructive algorithms', 'dfs and similar', 'greedy', 'trees', '*2000']
D2. Great Vova Wall (Version 2)time limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputVova's family is building the Great Vova Wall (named by Vova himself). Vova's parents, grandparents, grand-grandparents contributed to it. Now it's totally up to Vova to put the finishing...
5 2 1 1 2 5
YES
2 seconds
256 megabytes
['data structures', 'implementation', '*2200']
D1. Great Vova Wall (Version 1)time limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputVova's family is building the Great Vova Wall (named by Vova himself). Vova's parents, grandparents, grand-grandparents contributed to it. Now it's totally up to Vova to put the finishing...
5 2 1 1 2 5
YES
2 seconds
256 megabytes
['greedy', 'implementation', 'math', '*2200']
C. Prefixes and Suffixestime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputIvan wants to play a game with you. He picked some string s of length n consisting only of lowercase Latin letters. You don't know this string. Ivan has informed you about all its improper prefix...
5 ba a abab a aba baba ab aba
SPPSPSPS
1 second
256 megabytes
['strings', '*1700']
B. Teams Formingtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere are n students in a university. The number of students is even. The i-th student has programming skill equal to a_i. The coach wants to form \frac{n}{2} teams. Each team should consist of exactly t...
6 5 10 2 3 14 5
5
1 second
256 megabytes
['sortings', '*800']
A. Uniform Stringtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given two integers n and k.Your task is to construct such a string s of length n that for each i from 1 to k there is at least one i-th letter of the Latin alphabet in this string (the first let...
3 7 3 4 4 6 2
cbcacab abcd baabab
1 second
256 megabytes
['implementation', '*800']
H. New Year and the Tricolore Recreationtime limit per test4 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputAlice and Bob play a game on a grid with n rows and infinitely many columns. In each row, there are three tokens, blue, white and red one. Before the game starts and after every ...
1 6 0 3 9
Alice Bob
4 seconds
256 megabytes
['games', '*3200']