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. Rowtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou're given a row with n chairs. We call a seating of people "maximal" if the two following conditions hold: There are no neighbors adjacent to anyone seated. It's impossible to seat one more person without vio...
Input3101
OutputYes
1 second
256 megabytes
['brute force', 'constructive algorithms', '*1200']
H. K Pathstime limit per test4 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a tree of n vertices. You are to select k (not necessarily distinct) simple paths in such a way that it is possible to split all edges of the tree into three sets: edges not contained in any pat...
Input3 21 22 3
Output7
4 seconds
256 megabytes
['combinatorics', 'data structures', 'dp', 'fft', 'math', '*3100']
G. Magic multisetstime limit per test4 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputIn the School of Magic in Dirtpolis a lot of interesting objects are studied on Computer Science lessons.Consider, for example, the magic multiset. If you try to add an integer to it that is already p...
Input4 41 1 2 11 1 2 21 1 4 12 1 4
Output10
4 seconds
256 megabytes
['data structures', '*2500']
F. Round Marriagetime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputIt's marriage season in Ringland!Ringland has a form of a circle's boundary of length L. There are n bridegrooms and n brides, and bridegrooms decided to marry brides.Of course, each bridegroom should ...
Input2 40 12 3
Output1
3 seconds
256 megabytes
['binary search', 'graph matchings', 'greedy', '*2500']
E. Addition on Segmentstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputGrisha come to a contest and faced the following problem.You are given an array of size n, initially consisting of zeros. The elements of the array are enumerated from 1 to n. You perform q opera...
Input4 31 3 12 4 23 4 4
Output41 2 3 4
2 seconds
256 megabytes
['bitmasks', 'data structures', 'divide and conquer', 'dp', '*2200']
D. Bookshelvestime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputMr Keks is a typical white-collar in Byteland.He has a bookshelf in his office with some books on it, each book has an integer positive price.Mr Keks defines the value of a shelf as the sum of books prices...
Input10 49 14 28 1 7 13 15 29 2 31
Output24
1 second
256 megabytes
['bitmasks', 'dp', 'greedy', '*1900']
C. Useful Decompositiontime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputRamesses knows a lot about problems involving trees (undirected connected graphs without cycles)!He created a new useful tree decomposition, but he does not know how to construct it, so he asked y...
Input41 22 33 4
OutputYes11 4
1 second
256 megabytes
['implementation', 'trees', '*1400']
B. Businessmen Problemstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputTwo famous competing companies ChemForces and TopChemist decided to show their sets of recently discovered chemical elements on an exhibition. However they know that no element should be present ...
Input31 27 23 1041 42 43 44 4
Output24
2 seconds
256 megabytes
['sortings', '*1000']
A. Antipalindrometime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputA string is a palindrome if it reads the same from the left to the right and from the right to the left. For example, the strings "kek", "abacaba", "r" and "papicipap" are palindromes, while the strings...
Inputmew
Output3
1 second
256 megabytes
['brute force', 'implementation', 'strings', '*900']
F. Cactus to Treetime limit per test4 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a special connected undirected graph where each vertex belongs to at most one simple cycle.Your task is to remove as many edges as needed to convert this graph into a tree (connected grap...
Input9 107 29 21 63 14 34 77 69 85 85 9
Output5 3 5 4 5 4 3 5 4
4 seconds
256 megabytes
['dp', 'graphs', 'trees', '*2900']
E. The Number Gamestime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe nation of Panel holds an annual show called The Number Games, where each district in the nation will be represented by one contestant.The nation has n districts numbered from 1 to n, each distric...
Input6 32 12 64 25 62 3
Output1 3 4
3 seconds
256 megabytes
['data structures', 'greedy', 'trees', '*2200']
D. Perfect Groupstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputSaMer has written the greatest test case of all time for one of his problems. For a given array of integers, the problem asks to find the minimum number of groups the array can be divided into, such tha...
Input25 5
Output3 0
1 second
256 megabytes
['dp', 'math', 'number theory', '*2100']
C. Posterizedtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputProfessor Ibrahim has prepared the final homework for his algorithm’s class. He asked his students to implement the Posterization Image Filter.Their algorithm will be tested on an array of integers, where t...
Input4 32 14 3 4
Output0 12 3 3
1 second
256 megabytes
['games', 'greedy', '*1700']
B. Marlintime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe city of Fishtopia can be imagined as a grid of 4 rows and an odd number of columns. It has two main villages; the first is located at the top-left cell (1,1), people who stay there love fishing at the Tuna ...
Input7 2
OutputYES........#......#............
1 second
256 megabytes
['constructive algorithms', '*1600']
A. Links and Pearlstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputA necklace can be described as a string of links ('-') and pearls ('o'), with the last link or pearl connected to the first one. You can remove a link or a pearl and insert it between two other exist...
Input-o-o--
OutputYES
1 second
256 megabytes
['implementation', 'math', '*900']
E. Kuro and Topological Paritytime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputKuro has recently won the "Most intelligent cat ever" contest. The three friends then decided to go to Katie's home to celebrate Kuro's winning. After a big meal, they took a small break th...
Input3 1-1 0 1
Output6
1 second
256 megabytes
['dp', '*2400']
D. Kuro and GCD and XOR and SUMtime limit per test2 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputKuro is currently playing an educational game about numbers. The game focuses on the greatest common divisor (GCD), the XOR value, and the sum of two numbers. Kuro loves the game so much ...
Input51 11 22 1 1 32 1 1 22 1 1 1
Output21-1
2 seconds
512 megabytes
['binary search', 'bitmasks', 'brute force', 'data structures', 'dp', 'dsu', 'greedy', 'math', 'number theory', 'strings', 'trees', '*2200']
C. Kuro and Walking Routetime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputKuro is living in a country called Uberland, consisting of n towns, numbered from 1 to n, and n - 1 bidirectional roads connecting these towns. It is possible to reach each town from any other....
Input3 1 31 22 3
Output5
2 seconds
256 megabytes
['dfs and similar', 'trees', '*1600']
B. Treasure Hunttime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputAfter the big birthday party, Katie still wanted Shiro to have some more fun. Later, she came up with a game called treasure hunt. Of course, she invited her best friends Kuro and Shiro to play with her....
Input3KurooShiroKatie
OutputKuro
1 second
256 megabytes
['greedy', '*1800']
A. Pizza, Pizza, Pizza!!!time limit per test1 secondmemory limit per test128 megabytesinputstandard inputoutputstandard outputKatie, Kuro and Shiro are best friends. They have known each other since kindergarten. That's why they often share everything with each other and work together on some very hard problems.Today i...
Input3
Output2
1 second
128 megabytes
['math', '*1000']
G. Petya's Examstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputPetya studies at university. The current academic year finishes with n special days. Petya needs to pass m exams in those special days. The special days in this problem are numbered from 1 to n.There are...
Input5 21 3 11 5 1
Output1 2 3 0 3
1 second
256 megabytes
['greedy', 'implementation', 'sortings', '*1700']
F. Mentorstime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputIn BerSoft n programmers work, the programmer i is characterized by a skill r_i.A programmer a can be a mentor of a programmer b if and only if the skill of the programmer a is strictly greater than the skill...
Input4 210 4 10 151 24 3
Output0 0 1 2
3 seconds
256 megabytes
['binary search', 'data structures', 'implementation', '*1500']
E. Bus Video Systemtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe busses in Berland are equipped with a video surveillance system. The system records information about changes in the number of passengers in a bus after stops.If x is the number of passengers in a...
Input3 52 1 -3
Output3
1 second
256 megabytes
['combinatorics', 'math', '*1400']
D. Almost Arithmetic Progressiontime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputPolycarp likes arithmetic progressions. A sequence [a_1, a_2, \dots, a_n] is called an arithmetic progression if for each i (1 \le i < n) the value a_{i+1} - a_i is the same. For example,...
Input424 21 14 10
Output3
1 second
256 megabytes
['brute force', 'implementation', 'math', '*1500']
C. Letterstime limit per test4 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere are n dormitories in Berland State University, they are numbered with integers from 1 to n. Each dormitory consists of rooms, there are a_i rooms in i-th dormitory. The rooms in i-th dormitory are numbe...
Input3 610 15 121 9 12 23 26 37
Output1 11 92 22 133 13 12
4 seconds
256 megabytes
['binary search', 'implementation', 'two pointers', '*1000']
B. File Nametime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou can not just take the file and send it. When Polycarp trying to send a file in the social network "Codehorses", he encountered an unexpected problem. If the name of the file contains three or more "x" (l...
Input6xxxiii
Output1
1 second
256 megabytes
['greedy', 'strings', '*800']
A. Remove Duplicatestime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputPetya has an array a consisting of n integers. He wants to remove duplicate (equal) elements.Petya wants to leave only the rightmost entry (occurrence) for each element of the array. The relative ord...
Input61 5 5 1 6 1
Output35 6 1
1 second
256 megabytes
['implementation', '*800']
F. Consecutive Subsequencetime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given an integer array of length n.You have to choose some subsequence of this array of maximum length such that this subsequence forms a increasing sequence of consecutive integers. I...
Input73 3 4 7 5 6 8
Output42 3 5 6
2 seconds
256 megabytes
['dp', '*1700']
E. Cyclic Componentstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given an undirected graph consisting of n vertices and m edges. Your task is to find the number of connected components which are cycles.Here are some definitions of graph theory.An undirect...
Input5 41 23 45 43 5
Output1
2 seconds
256 megabytes
['dfs and similar', 'dsu', 'graphs', '*1500']
D. Divide by three, multiply by twotime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputPolycarp likes to play with numbers. He takes some integer number x, writes it down on the board, and then performs with it n - 1 operations of the two kinds: divide the number x by ...
Input64 8 6 3 12 9
Output9 3 6 12 4 8
1 second
256 megabytes
['dfs and similar', 'math', 'sortings', '*1400']
C. Less or Equaltime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a sequence of integers of length n and integer number k. You should print any integer number x in the range of [1; 10^9] (i.e. 1 \le x \le 10^9) such that exactly k elements of given seque...
Input7 43 7 5 1 10 3 20
Output6
2 seconds
256 megabytes
['sortings', '*1200']
B. Two-gramtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputTwo-gram is an ordered pair (i.e. string of length two) of capital Latin letters. For example, "AZ", "AA", "ZA" — three distinct two-grams.You are given a string s consisting of n capital Latin letters. Your ...
Input7ABACABA
OutputAB
1 second
256 megabytes
['implementation', 'strings', '*900']
A. Wrong Subtractiontime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputLittle girl Tanya is learning how to decrease a number by one, but she does it wrong with a number consisting of two or more digits. Tanya subtracts one from a number by the following algorithm: if ...
Input512 4
Output50
1 second
256 megabytes
['implementation', '*800']
F. Minimal k-coveringtime limit per test1.5 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a bipartite graph G = (U, V, E), U is the set of vertices of the first part, V is the set of vertices of the second part and E is the set of edges. There might be multiple edges.Let...
Input3 3 71 22 31 33 23 32 12 1
Output0 3 3 7 4 6 1 3 6 7 4 5
1.5 seconds
256 megabytes
['flows', 'graphs', '*2500']
E. Well played!time limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputRecently Max has got himself into popular CCG "BrainStone". As "BrainStone" is a pretty intellectual game, Max has to solve numerous hard problems during the gameplay. Here is one of them:Max owns n creat...
Input2 1 110 156 1
Output27
1 second
256 megabytes
['greedy', 'sortings', '*2100']
D. Degree Settime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a sequence of n positive integers d1, d2, ..., dn (d1 < d2 < ... < dn). Your task is to construct an undirected graph such that: there are exactly dn + 1 vertices; there are no self-loops; ...
Input32 3 4
Output83 14 24 52 55 13 22 15 3
2 seconds
256 megabytes
['constructive algorithms', 'graphs', 'implementation', '*2500']
C. Nested Segmentstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a sequence a1, a2, ..., an of one-dimensional segments numbered 1 through n. Your task is to find two distinct indices i and j such that segment ai lies within segment aj.Segment [l1, r1...
Input51 102 93 92 32 9
Output2 1
2 seconds
256 megabytes
['greedy', 'implementation', 'sortings', '*1500']
B. Lara Croft and the New Gametime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou might have heard about the next game in Lara Croft series coming out this year. You also might have watched its trailer. Though you definitely missed the main idea about its plot, so l...
Input4 3 0
Output1 1
2 seconds
256 megabytes
['implementation', 'math', '*1300']
A. Minimum Binary Numbertime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputString can be called correct if it consists of characters "0" and "1" and there are no redundant leading zeroes. Here are some examples: "0", "10", "1001".You are given a correct string s.You can...
Input41001
Output100
1 second
256 megabytes
['implementation', '*800']
E. Hag's Khashbatime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputHag is a very talented person. He has always had an artist inside him but his father forced him to study mechanical engineering.Yesterday he spent all of his time cutting a giant piece of wood trying to...
Input3 40 02 02 21 1 22 12 22 3
Output3.4142135624 -1.41421356242.0000000000 0.00000000000.5857864376 -1.4142135624
3 seconds
256 megabytes
['geometry', '*2600']
D. Ghoststime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputGhosts live in harmony and peace, they travel the space without any purpose other than scare whoever stands in their way.There are n ghosts in the universe, they move in the OXY plane, each one of them has its...
Input4 1 11 -1 -12 1 13 1 14 -1 -1
Output8
2 seconds
256 megabytes
['geometry', 'math', '*2000']
C. Valhalla Siegetime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputIvar the Boneless is a great leader. He is trying to capture Kattegat from Lagertha. The war has begun and wave after wave Ivar's warriors are falling in battle.Ivar has n warriors, he places them on a...
Input5 51 2 1 2 13 10 1 1 1
Output35443
2 seconds
256 megabytes
['binary search', '*1400']
B. Mancalatime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputMancala is a game famous in the Middle East. It is played on a board that consists of 14 holes. Initially, each hole has a_i stones. When a player makes a move, he chooses a hole which contains a positive nu...
Input0 1 1 0 0 0 0 0 0 7 0 0 0 0
Output4
1 second
256 megabytes
['brute force', 'implementation', '*1100']
A. Aramic scripttime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputIn Aramic language words can only represent objects.Words in Aramic have special properties: A word is a root if it does not contain the same letter more than once. A root and all its permutations rep...
Input5a aa aaa ab abb
Output2
1 second
256 megabytes
['implementation', 'strings', '*900']
B. Watering Systemtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputArkady wants to water his only flower. Unfortunately, he has a very poor watering system that was designed for n flowers and so it looks like a pipe with n holes. Arkady can only use the water that flo...
Input4 10 32 2 2 2
Output1
1 second
256 megabytes
['math', 'sortings', '*1000']
A. Mind the Gaptime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputThese days Arkady works as an air traffic controller at a large airport. He controls a runway which is usually used for landings only. Thus, he has a schedule of planes that are landing in the nearest fut...
Input6 600 01 203 215 019 3023 40
Output6 1
1 second
256 megabytes
['implementation', '*1100']
E. Short Codetime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputArkady's code contains n variables. Each variable has a unique name consisting of lowercase English letters only. One day Arkady decided to shorten his code.He wants to replace each variable name with its n...
Input3codeforcescodehorsescode
Output6
1 second
256 megabytes
['data structures', 'dp', 'greedy', 'strings', 'trees', '*2200']
D. Single-use Stonestime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputA lot of frogs want to cross a river. A river is w units width, but frogs can only jump l units long, where l < w. Frogs can also jump on lengths shorter than l. but can't jump longer. Hopefully, the...
Input10 50 0 1 0 2 0 0 1 0
Output3
1 second
256 megabytes
['binary search', 'flows', 'greedy', 'two pointers', '*1900']
C. Greedy Arkadytime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputk people want to split n candies between them. Each candy should be given to exactly one of them or be thrown away.The people are numbered from 1 to k, and Arkady is the first of them. To split the candi...
Input20 4 5 2
Output8
1 second
256 megabytes
['math', '*2000']
B. Battleshiptime limit per test1.5 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputArkady is playing Battleship. The rules of this game aren't really important.There is a field of n \times n cells. There should be exactly one k-decker on the field, i. e. a ship that is k cells long ori...
Input4 3#..##.#......###
Output3 2
1.5 seconds
256 megabytes
['implementation', '*1300']
A. Paper Airplanestime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputTo make a paper airplane, one has to use a rectangular piece of paper. From a sheet of standard size you can make s airplanes.A group of k people decided to make n airplanes each. They are going to buy...
Input5 3 2 3
Output4
1 second
256 megabytes
['math', '*800']
B. Messagestime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere are n incoming messages for Vasya. The i-th message is going to be received after ti minutes. Each message has a cost, which equals to A initially. After being received, the cost of a message decreases ...
Input4 5 5 3 51 5 5 4
Output20
1 second
256 megabytes
['math', '*1300']
A. Splitstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputLet's define a split of n as a nonincreasing sequence of positive integers, the sum of which is n. For example, the following sequences are splits of 8: [4, 4], [3, 3, 2], [2, 2, 1, 1, 1, 1], [5, 2, 1].The foll...
Input7
Output4
1 second
256 megabytes
['math', '*800']
E. Circles of Waitingtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputA chip was placed on a field with coordinate system onto point (0, 0).Every second the chip moves randomly. If the chip is currently at a point (x, y), after a second it moves to the point (x - 1, ...
Input0 1 1 1 1
Output1
2 seconds
256 megabytes
['math', '*3100']
D. Frequency of Stringtime limit per test1.5 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputYou are given a string s. You should answer n queries. The i-th query consists of integer k_i and string m_i. The answer for this query is the minimum length of such a string t that t is a subst...
Inputaaaaa53 a3 aa2 aaa3 aaaa1 aaaaa
Output344-15
1.5 seconds
512 megabytes
['hashing', 'string suffix structures', 'strings', '*2500']
C. Cutting Rectangletime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputA rectangle with sides A and B is cut into rectangles with cuts parallel to its sides. For example, if p horizontal and q vertical cuts were made, (p + 1) \cdot (q + 1) rectangles were left after th...
Input11 1 9
Output3
2 seconds
256 megabytes
['brute force', 'math', 'number theory', '*2600']
B. Destruction of a Treetime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a tree (a graph with n vertices and n - 1 edges in which it's possible to reach any vertex from any other vertex using only its edges).A vertex can be destroyed if this vertex has e...
Input50 1 2 1 2
OutputYES12354
1 second
256 megabytes
['constructive algorithms', 'dfs and similar', 'dp', 'greedy', 'trees', '*2000']
A. Alternating Sumtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given two integers a and b. Moreover, you are given a sequence s_0, s_1, \dots, s_{n}. All values in s are integers 1 or -1. It's known that sequence is k-periodic and k divides n+1. In other w...
Input2 2 3 3+-+
Output7
1 second
256 megabytes
['math', 'number theory', '*1800']
G. Visible Black Areastime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputPetya has a polygon consisting of n vertices. All sides of the Petya's polygon are parallel to the coordinate axes, and each two adjacent sides of the Petya's polygon are perpendicular. It is guara...
Input5 7 16 3160 018 018 616 616 110 110 47 47 22 22 612 612 1210 1210 80 8
Output2
1 second
256 megabytes
['data structures', 'dsu', 'geometry', 'trees', '*2800']
F. Simple Cycles Edgestime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given an undirected graph, consisting of n vertices and m edges. The graph does not necessarily connected. Guaranteed, that the graph does not contain multiple edges (more than one edges b...
Input3 31 22 33 1
Output31 2 3
2 seconds
256 megabytes
['dfs and similar', 'graphs', 'trees', '*2400']
E. Byteland, Berland and Disputed Citiestime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe cities of Byteland and Berland are located on the axis Ox. In addition, on this axis there are also disputed cities, which belong to each of the countries in their opinion. T...
Input4-5 R0 P3 P7 B
Output12
2 seconds
256 megabytes
['constructive algorithms', 'greedy', '*2200']
D. Merge Equalstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given an array of positive integers. While there are at least two equal elements, we will perform the following operation. We choose the smallest value x that occurs in the array 2 or more times....
Input73 4 1 2 2 1 1
Output43 8 2 1
2 seconds
256 megabytes
['data structures', 'implementation', '*1600']
C. Make a Squaretime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a positive integer n, written without leading zeroes (for example, the number 04 is incorrect). In one operation you can delete any digit of the given integer so that the result remains a ...
Input8314
Output2
2 seconds
256 megabytes
['brute force', 'implementation', 'math', '*1400']
B. Students in Railway Carriagetime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere are n consecutive seat places in a railway carriage. Each place is either empty or occupied by a passenger.The university team for the Olympiad consists of a student-programmers and...
Input5 1 1*...*
Output2
2 seconds
256 megabytes
['constructive algorithms', 'greedy', 'implementation', '*1300']
A. Equatortime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputPolycarp has created his own training plan to prepare for the programming contests. He will train for n days, all days are numbered from 1 to n, beginning from the first.On the i-th day Polycarp will necessar...
Input41 3 2 1
Output2
2 seconds
256 megabytes
['implementation', '*1300']
G. Partitionstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a set of n elements indexed from 1 to n. The weight of i-th element is wi. The weight of some subset of a given set is denoted as . The weight of some partition R of a given set into k subset...
Input4 22 3 2 3
Output160
2 seconds
256 megabytes
['combinatorics', 'math', 'number theory', '*2700']
F. k-substringstime limit per test4 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a string s consisting of n lowercase Latin letters.Let's denote k-substring of s as a string subsk = sksk + 1..sn + 1 - k. Obviously, subs1 = s, and there are exactly such substrings.Let's...
Input15bcabcabcabcabca
Output9 7 5 3 1 -1 -1 -1
4 seconds
256 megabytes
['binary search', 'hashing', 'string suffix structures', '*2700']
E. Tufuramatime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputOne day Polycarp decided to rewatch his absolute favourite episode of well-known TV series "Tufurama". He was pretty surprised when he got results only for season 7 episode 3 with his search query of "Watch ...
Input51 2 3 4 5
Output0
2 seconds
256 megabytes
['data structures', '*1900']
D. Pair Of Linestime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given n points on Cartesian plane. Every point is a lattice point (i. e. both of its coordinates are integers), and all points are distinct.You may draw two straight lines (not necessarily disti...
Input50 00 11 11 -12 2
OutputYES
2 seconds
256 megabytes
['geometry', '*2000']
C. Chessboardtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputMagnus decided to play a classic chess game. Though what he saw in his locker shocked him! His favourite chessboard got broken into 4 pieces, each of size n by n, n is always odd. And what's even worse, som...
Input10010
Output1
1 second
256 megabytes
['bitmasks', 'brute force', 'implementation', '*1400']
B. Lecture Sleeptime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYour friend Mishka and you attend a calculus lecture. Lecture lasts n minutes. Lecturer tells ai theorems during the i-th minute.Mishka is really interested in calculus, though it is so hard to stay awak...
Input6 31 3 5 2 5 41 1 0 1 0 0
Output16
1 second
256 megabytes
['data structures', 'dp', 'implementation', 'two pointers', '*1200']
A. Tetristime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a following process. There is a platform with n columns. 1 \times 1 squares are appearing one after another in some columns on this platform. If there are no squares in the column, a square will o...
Input3 91 1 2 2 2 3 1 2 3
Output2
1 second
256 megabytes
['implementation', '*900']
H. Santa's Gifttime limit per test4 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputSanta has an infinite number of candies for each of m flavours. You are given a rooted tree with n vertices. The root of the tree is the vertex 1. Each vertex contains exactly one candy. The i-th vertex ...
Input3 5 5 73 1 41 173 1 48 85 892 12 31 2 32 12 3
Output2920.333333333333593.00000000000049.0000000000003217.000000000000
4 seconds
512 megabytes
['data structures', 'trees', '*3100']
G. Bandit Bluestime limit per test3.5 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputJapate, while traveling through the forest of Mala, saw N bags of gold lying in a row. Each bag has some distinct weight of gold between 1 to N. Japate can carry only one bag of gold with him, so he us...
Input1 1 1
Output1
3.5 seconds
256 megabytes
['combinatorics', 'dp', 'fft', 'math', '*2900']
F. Pathwalkstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a directed graph with n nodes and m edges, with all edges having a certain weight. There might be multiple edges and self loops, and the graph can also be disconnected. You need to choose a pat...
Input3 33 1 31 2 12 3 2
Output2
1 second
256 megabytes
['data structures', 'dp', 'graphs', '*2100']
E. Alternating Treetime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputGiven a tree with n nodes numbered from 1 to n. Each node i has an associated value V_i.If the simple path from u_1 to u_m consists of m nodes namely u_1 \rightarrow u_2 \rightarrow u_3 \rightarrow \...
Input4-4 1 5 -21 21 31 4
Output40
2 seconds
256 megabytes
['combinatorics', 'dfs and similar', 'divide and conquer', 'dp', 'probabilities', 'trees', '*2300']
D. Full Binary Tree Queriestime limit per test4 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou have a full binary tree having infinite levels.Each node has an initial value. If a node has value x, then its left child has value 2·x and its right child has value 2·x + 1. The value of...
Input53 121 2 13 122 4 -13 8
Output12 6 3 1 12 6 2 1 8 4 2 1
4 seconds
256 megabytes
['brute force', 'implementation', 'trees', '*2100']
C. Subsequence Countingtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputPikachu had an array with him. He wrote down all the non-empty subsequences of the array on paper. Note that an array of size n has 2n - 1 non-empty subsequences in it. Pikachu being mischievous a...
Input10 5
Output65 50 7 15 6 100
1 second
256 megabytes
['bitmasks', 'constructive algorithms', 'greedy', 'implementation', '*1700']
B. Minimize the errortime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given two arrays A and B, each of size n. The error, E, between these two arrays is defined . You have to perform exactly k1 operations on array A and exactly k2 operations on array B. In on...
Input2 0 01 22 3
Output2
1 second
256 megabytes
['data structures', 'greedy', 'sortings', '*1500']
A. Check the stringtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputA has a string consisting of some number of lowercase English letters 'a'. He gives it to his friend B who appends some number of letters 'b' to the end of this string. Since both A and B like the cha...
Inputaaabccc
OutputYES
1 second
256 megabytes
['implementation', '*1200']
F. Mahmoud and Ehab and yet another xor tasktime limit per test1 secondmemory limit per test512 megabytesinputstandard inputoutputstandard outputEhab has an array a of n integers. He likes the bitwise-xor operation and he likes to bother Mahmoud so he came up with a problem. He gave Mahmoud q queries. In each of them, ...
Input5 50 1 2 3 44 32 03 75 75 8
Output42040
1 second
512 megabytes
['bitmasks', 'dp', 'math', 'matrices', '*2400']
E. Mahmoud and Ehab and the xor-MSTtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputEhab is interested in the bitwise-xor operation and the special graphs. Mahmoud gave him a problem that combines both. He has a complete graph consisting of n vertices numbered from 0...
Input4
Output4
2 seconds
256 megabytes
['bitmasks', 'dp', 'graphs', 'implementation', 'math', '*1900']
D. Mahmoud and Ehab and another array construction tasktime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputMahmoud has an array a consisting of n integers. He asked Ehab to find another array b of the same length such that: b is lexicographically greater than or equal ...
Input52 3 5 4 13
Output2 3 5 7 11
3 seconds
256 megabytes
['constructive algorithms', 'greedy', 'math', 'number theory', '*1900']
C. Mahmoud and Ehab and the wrong algorithmtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputMahmoud was trying to solve the vertex cover problem on trees. The problem statement is:Given an undirected tree consisting of n nodes, find the minimum number of vertices tha...
Input2
Output-11 2
2 seconds
256 megabytes
['constructive algorithms', 'trees', '*1500']
B. Mahmoud and Ehab and the messagetime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputMahmoud wants to send a message to his friend Ehab. Their language consists of n words numbered from 1 to n. Some words have the same meaning so there are k groups of words such that ...
Input5 4 4i loser am the second100 1 1 5 101 11 32 2 51 4i am the second
Output107
2 seconds
256 megabytes
['dsu', 'greedy', 'implementation', '*1200']
A. Mahmoud and Ehab and the even-odd gametime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputMahmoud and Ehab play a game called the even-odd game. Ehab chooses his favorite integer n and then they take turns, starting from Mahmoud. In each player's turn, he has to choos...
Input1
OutputEhab
1 second
256 megabytes
['games', 'math', '*800']
F3. Lightsabers (hard)time limit per test4 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere used to be unrest in the Galactic Senate. Several thousand solar systems had declared their intentions to leave the Republic. But fear not! Master Heidi was able to successfully select the J...
Input4 3 21 2 3 2
Output4
4 seconds
256 megabytes
['fft', '*2600']
F2. Lightsabers (medium)time limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere is unrest in the Galactic Senate. Several thousand solar systems have declared their intentions to leave the Republic. Master Heidi needs to select the Jedi Knights who will go on peacekeep...
Input8 33 3 1 2 2 1 1 33 1 1
Output1
1 second
256 megabytes
['binary search', 'two pointers', '*1800']
F1. Lightsabers (easy)time limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere is unrest in the Galactic Senate. Several thousand solar systems have declared their intentions to leave the Republic. Master Heidi needs to select the Jedi Knights who will go on peacekeepin...
Input5 21 1 2 2 11 2
OutputYES
1 second
256 megabytes
['implementation', '*1500']
E3. Guard Duty (hard)time limit per test5 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputNow that Heidi knows that she can assign Rebel spaceships to bases (recall the easy subtask), she is asking you: how exactly to do this? Now, given positions of N spaceships and N bases on a plane,...
Input46 65 12 44 05 41 22 13 5
Output4123
5 seconds
256 megabytes
['geometry', '*2700']
E2. Guard Duty (medium)time limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputPrincess Heidi decided to give orders to all her K Rebel ship commanders in person. Unfortunately, she is currently travelling through hyperspace, and will leave it only at N specific moments t1,...
Input2 51 4 6 7 12
Output4
3 seconds
256 megabytes
['binary search', 'dp', 'greedy', 'sortings', '*2200']
E1. Guard Duty (easy)time limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe Rebel fleet is afraid that the Empire might want to strike back again. Princess Heidi needs to know if it is possible to assign R Rebel spaceships to guard B bases so that every base has exactly...
Input3 30 02 03 1-2 10 32 2
OutputYes
1 second
256 megabytes
['brute force', 'geometry', 'greedy', 'math', '*1600']
D2. Hyperspace Jump (hard)time limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputIt is now 125 years later, but humanity is still on the run from a humanoid-cyborg race determined to destroy it. Or perhaps we are getting some stories mixed up here... In any case, the fleet...
Input8 215 010 110 120 60 120 11 02-5 -54 321 10 121 01 0
Output1 2 2 2 3 3 3 1
3 seconds
256 megabytes
['*2700']
D1. Hyperspace Jump (easy)time limit per test5 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe Rebel fleet is on the run. It consists of m ships currently gathered around a single planet. Just a few seconds ago, the vastly more powerful Empire fleet has appeared in the same solar sy...
Input4(99+98)/97(26+4)/10(12+33)/15(5+1)/7
Output1 2 2 1
5 seconds
256 megabytes
['expression parsing', 'math', '*1400']
C3. Encryption (hard)time limit per test2.2 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputHeidi is now just one code away from breaking the encryption of the Death Star plans. The screen that should be presenting her with the description of the next code looks almost like the previous...
Input4 3 103 4 7 2
Output6
2.2 seconds
512 megabytes
['data structures', 'dp', '*2500']
C2. Encryption (medium)time limit per test3 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputHeidi has now broken the first level of encryption of the Death Star plans, and is staring at the screen presenting her with the description of the next code she has to enter. It looks surprising...
Input4 3 103 4 7 2
Output16
3 seconds
512 megabytes
['dp', '*2000']
C1. Encryption (easy)time limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputRebel spy Heidi has just obtained the plans for the Death Star from the Empire and, now on her way to safety, she is trying to break the encryption of the plans (of course they are encrypted – the E...
Input4 103 4 7 2
Output16
1 second
256 megabytes
['brute force', '*1200']
B2. Maximum Control (medium)time limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe Resistance is trying to take control over as many planets of a particular solar system as possible. Princess Heidi is in charge of the fleet, and she must send ships to some planets in o...
Input31 22 3
Output1 3 3
3 seconds
256 megabytes
['data structures', 'dfs and similar', 'graphs', 'greedy', 'trees', '*2200']
B1. Maximum Control (easy)time limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe Resistance is trying to take control over all planets in a particular solar system. This solar system is shaped like a tree. More precisely, some planets are connected by bidirectional hyp...
Input54 14 21 31 5
Output3
2 seconds
256 megabytes
['implementation', '*1000']
A2. Death Stars (medium)time limit per test2.5 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe stardate is 1983, and Princess Heidi is getting better at detecting the Death Stars. This time, two Rebel spies have yet again given Heidi two maps with the possible locations of the Death...
Input10 5somerandomnoisemaytheforcebewithyouhctwoagainnoisesomermaythandomeforcnoiseebewiagainthyounoisehctwo
Output4 6
2.5 seconds
256 megabytes
['hashing', 'strings', '*2000']