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. Hamsters and Tigerstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputToday there is going to be an unusual performance at the circus — hamsters and tigers will perform together! All of them stand in circle along the arena edge and now the trainer faces a difficult ...
Input3HTH
Output0
2 seconds
256 megabytes
['two pointers', '*1600']
B. T-shirts from Sponsortime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputOne day a well-known sponsor of a well-known contest decided to give every participant of the contest a T-shirt as a present. A natural problem occurred: on the one hand, it is not clear how man...
Input1 0 2 0 13XLXXLM
OutputXXLLL
2 seconds
256 megabytes
['implementation', '*1100']
A. Ball Gametime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputA kindergarten teacher Natalia Pavlovna has invented a new ball game. This game not only develops the children's physique, but also teaches them how to count. The game goes as follows. Kids stand in circle....
Input10
Output2 4 7 1 6 2 9 7 6
2 seconds
256 megabytes
['brute force', 'implementation', '*800']
J. Planting Treestime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputVasya is a Greencode wildlife preservation society proponent. One day he found an empty field nobody owned, divided it into n × m squares and decided to plant a forest there. Vasya will plant nm trees ...
Input2 3
Output3 6 25 1 4
2 seconds
256 megabytes
['constructive algorithms', '*1800']
I. TCMCF+++time limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputVasya has gotten interested in programming contests in TCMCF+++ rules. On the contest n problems were suggested and every problem had a cost — a certain integral number of points (perhaps, negative or even e...
Input51 2 -3 3 3
Output3 1 2 3
2 seconds
256 megabytes
['greedy', '*1400']
H. Road Problemtime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe Berland capital (as you very well know) contains n junctions, some pairs of which are connected by two-way roads. Unfortunately, the number of traffic jams in the capital has increased dramatically, ...
Input4 31 22 33 4
Output11 4
3 seconds
256 megabytes
['graphs', '*2100']
G. Prime Problemtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputIn Berland prime numbers are fashionable — the respectable citizens dwell only on the floors with numbers that are prime numbers. The numismatists value particularly high the coins with prime nominal val...
Input8
Output1 2 2 1 1 1 1 2
1 second
256 megabytes
['number theory', '*2200']
F. Goats and Wolvestime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputOnce Vasya needed to transport m goats and m wolves from riverbank to the other as quickly as possible. The boat can hold n animals and Vasya, in addition, he is permitted to put less than n animals ...
Input3 2
Output11
2 seconds
256 megabytes
['greedy', '*2500']
E. Directortime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputVasya is a born Berland film director, he is currently working on a new blockbuster, "The Unexpected". Vasya knows from his own experience how important it is to choose the main characters' names and surname...
Input4AnnAnnaSabrinaJohnPetrovIvanovaStoltzAbacaba
OutputAnn Abacaba, Anna Ivanova, John Petrov, Sabrina Stoltz
2 seconds
256 megabytes
['constructive algorithms', 'greedy', '*2000']
D. Event Datestime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputOn a history lesson the teacher asked Vasya to name the dates when n famous events took place. He doesn't remembers the exact dates but he remembers a segment of days [li, ri] (inclusive) on which the eve...
Input31 22 33 4
Output1 2 3
2 seconds
256 megabytes
['greedy', 'meet-in-the-middle', 'sortings', '*1900']
C. Dancing Lessonstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere are n people taking dancing lessons. Every person is characterized by his/her dancing skill ai. At the beginning of the lesson they line up from left to right. While there is at least one couple...
Input4BGBG4 2 4 3
Output23 41 2
2 seconds
256 megabytes
['data structures', '*1900']
B. Schooltime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere are n students studying in the 6th grade, in group "B" of a berland secondary school. Every one of them has exactly one friend whom he calls when he has some news. Let us denote the friend of the person ...
Input3 42 3 11 2 3 41 2 3 4
Output1110
2 seconds
256 megabytes
['dp', 'dsu', '*2200']
A. Codecraft IIItime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputToday Vasya visited a widely known site and learned that the continuation of his favourite game Codecraft II will appear after exactly k months. He looked at the calendar and learned that at the moment ...
InputNovember3
OutputFebruary
2 seconds
256 megabytes
['implementation', '*900']
J. Triminoestime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere are many interesting tasks on domino tilings. For example, an interesting fact is known. Let us take a standard chessboard (8 × 8) and cut exactly two squares out of it. It turns out that the resultin...
Input6 10.w.wbw.wbwwbwbw.w.w.bw.wbwbwbww.wbw.wbwb...wbw.w.w..wbw.wbw.
OutputYES.a.aaa.cccbaccc.c.a.ba.dddcbabb.aaa.cbab...bbb.b.b..ccc.ddd.
2 seconds
256 megabytes
['constructive algorithms', 'greedy', '*2000']
I. Toystime limit per test5 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputLittle Masha loves arranging her toys into piles on the floor. And she also hates it when somebody touches her toys. One day Masha arranged all her n toys into several piles and then her elder brother Sasha came...
Input3
Output5{1,2,3}{1,2},{3}{1},{2,3}{1},{2},{3}{1,3},{2}
5 seconds
256 megabytes
['brute force', 'combinatorics', '*2300']
H. Phone Numbertime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputAlas, finding one's true love is not easy. Masha has been unsuccessful in that yet. Her friend Dasha told Masha about a way to determine the phone number of one's Prince Charming through arithmancy. The ...
Input12345
Output48
2 seconds
256 megabytes
['dp', '*1700']
G. Shooting Gallerytime limit per test5 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputBerland amusement park shooting gallery is rightly acknowledged as one of the best in the world. Every day the country's best shooters master their skills there and the many visitors compete in clay ...
Input21 4 1 4 12 5 2 6 240 03 34 53 5
Output0120
5 seconds
256 megabytes
['data structures', 'implementation', '*2500']
F. BerPainttime limit per test5 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputAnfisa the monkey got disappointed in word processors as they aren't good enough at reflecting all the range of her emotions, that's why she decided to switch to graphics editors. Having opened the BerPaint,...
Input4 561 1 1 31 3 3 33 3 3 13 1 1 11 3 3 11 1 3 322 1 red2 2 blue
Outputblue 0.00000000white 20.00000000
5 seconds
256 megabytes
['geometry', 'graphs', '*2700']
E. Anfisa the Monkeytime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputAnfisa the monkey learns to type. She is yet unfamiliar with the "space" key and can only type in lower-case Latin letters. Having typed for a fairly long line, Anfisa understood that it would be gr...
Input3 2 5abrakadabra
Outputabrakadabra
2 seconds
256 megabytes
['dp', '*1400']
D. Hyperdrivetime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputIn a far away galaxy there are n inhabited planets, numbered with numbers from 1 to n. They are located at large distances from each other, that's why the communication between them was very difficult unti...
Input40 0 00 0 10 1 01 0 0
Output1.7071067812
2 seconds
256 megabytes
['math', '*1800']
C. Holidaystime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputSchool holidays come in Berland. The holidays are going to continue for n days. The students of school №N are having the time of their lives and the IT teacher Marina Sergeyevna, who has spent all the summer...
Input10 51 23 34 67 78 10
OutputOK
2 seconds
256 megabytes
['implementation', '*1300']
B. Colatime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputTo celebrate the opening of the Winter Computer School the organizers decided to buy in n liters of cola. However, an unexpected difficulty occurred in the shop: it turned out that cola is sold in bottles 0.5, 1...
Input10 5 5 5
Output9
2 seconds
256 megabytes
['implementation', '*1500']
A. Indian Summertime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputIndian summer is such a beautiful time of the year! A girl named Alyona is walking in the forest and picking a bouquet from fallen leaves. Alyona is very choosy — she doesn't take a leaf if it matches t...
Input5birch yellowmaple redbirch yellowmaple yellowmaple green
Output4
2 seconds
256 megabytes
['implementation', '*900']
E. Racetime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputToday s kilometer long auto race takes place in Berland. The track is represented by a straight line as long as s kilometers. There are n cars taking part in the race, all of them start simultaneously at the ver...
Input2 332 5 1 2 141 3 11
Output1
2 seconds
256 megabytes
['brute force', 'implementation', 'two pointers', '*2300']
D. Journeytime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe territory of Berland is represented by a rectangular field n × m in size. The king of Berland lives in the capital, located on the upper left square (1, 1). The lower right square has coordinates (n, m). ...
Input2 2
Output01 11 22 22 11 1
2 seconds
256 megabytes
['brute force', 'constructive algorithms', 'implementation', '*2000']
C. Lucky Ticketstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputVasya thinks that lucky tickets are the tickets whose numbers are divisible by 3. He gathered quite a large collection of such tickets but one day his younger brother Leonid was having a sulk and decide...
Input3123 123 99
Output1
2 seconds
256 megabytes
['greedy', '*1300']
B. Lettertime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputVasya decided to write an anonymous letter cutting the letters out of a newspaper heading. He knows heading s1 and text s2 that he wants to send. Vasya can use every single heading letter no more than once. Va...
InputInstead of dogging Your footsteps it disappears but you dont notice anythingwhere is your dog
OutputNO
2 seconds
256 megabytes
['implementation', 'strings', '*1100']
A. Footballtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputOne day Vasya decided to have a look at the results of Berland 1910 Football Championship’s finals. Unfortunately he didn't find the overall score of the match; however, he got hold of a profound description...
Input1ABC
OutputABC
2 seconds
256 megabytes
['strings', '*1000']
E. Baldman and the militarytime limit per test4 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputBaldman is a warp master. He possesses a unique ability — creating wormholes! Given two positions in space, Baldman can make a wormhole which makes it possible to move between them in both di...
Input211 2 311 2
Output0
4 seconds
256 megabytes
['dfs and similar', 'graphs', 'trees', '*2700']
D. Strange towntime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputVolodya has recently visited a very odd town. There are N tourist attractions in the town and every two of them are connected by a bidirectional road. Each road has some travel price (natural number) ass...
Input3
Output0 3 4 3 0 5 4 5 0
2 seconds
256 megabytes
['constructive algorithms', 'math', '*2300']
C. Safe crackingtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputRight now you are to solve a very, very simple problem — to crack the safe. Four positive integers stand one by one on a circle protecting the safe. You know that to unlock this striking safe you have t...
Input1 1 1 1
Output
2 seconds
256 megabytes
['brute force', 'constructive algorithms', '*2200']
B. Game of chess unfinishedtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputOnce Volodya was at the museum and saw a regular chessboard as a museum piece. And there were only four chess pieces on it: two white rooks, a white king and a black king. "Aha, blacks certai...
Inputa6 b4 c8 a8
OutputCHECKMATE
2 seconds
256 megabytes
['implementation', '*1700']
A. Guilty — to the kitchen!time limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputIt's a very unfortunate day for Volodya today. He got bad mark in algebra and was therefore forced to do some work in the kitchen, namely to cook borscht (traditional Russian soup). This shou...
Input1 100140
Output40.0
2 seconds
256 megabytes
['greedy', 'implementation', '*1400']
E. 3-cyclestime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputDuring a recent research Berland scientists found out that there were n cities in Ancient Berland, joined by two-way paths. Any two cities are joined by no more than one path. No path joins a city with itsel...
Input3
Output21 22 3
2 seconds
256 megabytes
['constructive algorithms', 'graphs', 'greedy', '*1900']
D. Pawntime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputOn some square in the lowest row of a chessboard a stands a pawn. It has only two variants of moving: upwards and leftwards or upwards and rightwards. The pawn can choose from which square of the lowest row it c...
Input3 3 1123456789
Output162RL
2 seconds
256 megabytes
['dp', '*1900']
C. Email addresstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputSometimes one has to spell email addresses over the phone. Then one usually pronounces a dot as dot, an at sign as at. As a result, we get something like vasyaatgmaildotcom. Your task is to transform it...
Inputvasyaatgmaildotcom
Output[email protected]
2 seconds
256 megabytes
['expression parsing', 'implementation', '*1300']
B. Martian Dollartime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputOne day Vasya got hold of information on the Martian dollar course in bourles for the next n days. The buying prices and the selling prices for one dollar on day i are the same and are equal to ai. Vas...
Input2 43 7
Output8
2 seconds
256 megabytes
['brute force', '*1400']
A. Translationtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: ...
Inputcodeedoc
OutputYES
2 seconds
256 megabytes
['implementation', 'strings', '*800']
E. Number Tabletime limit per test2 secondsmemory limit per test216 megabytesinputstandard inputoutputstandard outputAs it has been found out recently, all the Berland's current economical state can be described using a simple table n × m in size. n — the number of days in each Berland month, m — the number of months. ...
Input2 20100
Output2
2 seconds
216 megabytes
['combinatorics', '*2500']
D. Interesting Sequencetime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputBerland scientists noticed long ago that the world around them depends on Berland population. Due to persistent research in this area the scientists managed to find out that the Berland chronolog...
Input2
OutputYES110
3 seconds
256 megabytes
['math', '*2600']
C. Berland Squaretime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputLast year the world's largest square was built in Berland. It is known that the square can be represented as an infinite plane with an introduced Cartesian system of coordinates. On that square two set...
Input1 0 1 1
Output4
2 seconds
256 megabytes
['implementation', 'math', '*2300']
B. Repaintingstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputA chessboard n × m in size is given. During the zero minute we repaint all the black squares to the 0 color. During the i-th minute we repaint to the i color the initially black squares that have exactly ...
Input3 31
Output4
2 seconds
256 megabytes
['math', '*1600']
A. Find Colortime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputNot so long ago as a result of combat operations the main Berland place of interest — the magic clock — was damaged. The cannon's balls made several holes in the clock, that's why the residents are concern...
Input-2 1
Outputwhite
2 seconds
256 megabytes
['constructive algorithms', 'geometry', 'implementation', 'math', '*1300']
K. Testingtime limit per test2 secondsmemory limit per test64 megabytesinputstandard inputoutputstandard outputYou take part in the testing of new weapon. For the testing a polygon was created. The polygon is a rectangular field n × m in size, divided into unit squares 1 × 1 in size. The polygon contains k objects, eac...
Input3 3 3*.*...*..
Output21
2 seconds
64 megabytes
['*2600']
J. Spelling Checktime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputPetya has noticed that when he types using a keyboard, he often presses extra buttons and adds extra letters to the words. Of course, the spell-checking system underlines the words for him and he has t...
Inputabdrakadabraabrakadabra
Output13
2 seconds
256 megabytes
['hashing', 'implementation', 'strings', '*1500']
I. Tramtime limit per test2 secondsmemory limit per test64 megabytesinputstandard inputoutputstandard outputIn a Berland city S*** there is a tram engine house and only one tram. Three people work in the house — the tram driver, the conductor and the head of the engine house. The tram used to leave the engine house eve...
Input4 51 22 33 44 11 4
Output221 3
2 seconds
64 megabytes
['*2500']
H. Multiplication Tabletime limit per test2 secondsmemory limit per test64 megabytesinputstandard inputoutputstandard outputPetya studies positional notations. He has already learned to add and subtract numbers in the systems of notations with different radices and has moved on to a more complicated action — multiplica...
Input10
Output1 2 3 4 5 6 7 8 92 4 6 8 10 12 14 16 183 6 9 12 15 18 21 24 274 8 12 16 20 24 28 32 365 10 15 20 25 30 35 40 456 12 18 24 30 36 42 48 547 14 21 28 35 42 49 56 638 16 24 32 40 48 56 64 729 18 27 36 45 54 63 72 81
2 seconds
64 megabytes
['implementation', '*1300']
G. Inverse Functiontime limit per test5 secondsmemory limit per test64 megabytesinputstandard inputoutputstandard outputPetya wrote a programme on C++ that calculated a very interesting function f(n). Petya ran the program with a certain value of n and went to the kitchen to have some tea. The history has no records co...
Input17int f(int n){if (n < 100) return 17;if (n > 99) return 27;}
Output99
5 seconds
64 megabytes
['implementation', '*2400']
F. Pacifist frogstime limit per test2 secondsmemory limit per test64 megabytesinputstandard inputoutputstandard outputThumbelina has had an accident. She has found herself on a little island in the middle of a swamp and wants to get to the shore very much.One can get to the shore only by hills that are situated along a...
Input5 3 52 3 41 2 3 4 5
Output22 3
2 seconds
64 megabytes
['implementation', '*1300']
E. What Has Dirichlet Got to Do with That?time limit per test2 secondsmemory limit per test64 megabytesinputstandard inputoutputstandard outputYou all know the Dirichlet principle, the point of which is that if n boxes have no less than n + 1 items, that leads to the existence of a box in which there are at least two i...
Input2 2 10
OutputMasha
2 seconds
64 megabytes
['dp', 'games', '*2000']
D. Cubical Planettime limit per test2 secondsmemory limit per test64 megabytesinputstandard inputoutputstandard outputYou can find anything whatsoever in our Galaxy! A cubical planet goes round an icosahedral star. Let us introduce a system of axes so that the edges of the cubical planet are parallel to the coordinate ...
Input0 0 00 1 0
OutputYES
2 seconds
64 megabytes
['math', '*1100']
C. Moon Craterstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere are lots of theories concerning the origin of moon craters. Most scientists stick to the meteorite theory, which says that the craters were formed as a result of celestial bodies colliding with the ...
Input41 12 24 15 1
Output31 2 4
1 second
256 megabytes
['dp', 'sortings', '*2100']
B. Company Income Growthtime limit per test2 secondsmemory limit per test64 megabytesinputstandard inputoutputstandard outputPetya works as a PR manager for a successful Berland company BerSoft. He needs to prepare a presentation on the company income growth since 2001 (the year of its founding) till now. Petya knows t...
Input10-2 1 1 3 2 3 4 -10 -2 5
Output52002 2005 2006 2007 2010
2 seconds
64 megabytes
['greedy', '*1300']
A. C*++ Calculationstime limit per test2 secondsmemory limit per test64 megabytesinputstandard inputoutputstandard outputC*++ language is quite similar to C++. The similarity manifests itself in the fact that the programs written in C*++ sometimes behave unpredictably and lead to absolutely unexpected effects. For exam...
Input15*a++-3*++a+a++
Output11
2 seconds
64 megabytes
['expression parsing', 'greedy', '*2000']
H. The Great Marathontime limit per test4 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputOn the Berland Dependence Day it was decided to organize a great marathon. Berland consists of n cities, some of which are linked by two-way roads. Each road has a certain length. The cities are nu...
Input3 21 2 12 3 11 1 1 1
Output3
4 seconds
256 megabytes
['dp', '*2400']
G. Queuetime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputOn a cold winter evening our hero Vasya stood in a railway queue to buy a ticket for Codeforces championship final. As it usually happens, the cashier said he was going to be away for 5 minutes and left for an ...
Input21 02 1
Output2 1
2 seconds
256 megabytes
['data structures', '*2300']
F. Smart Boytime limit per test4 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputOnce Petya and Vasya invented a new game and called it "Smart Boy". They located a certain set of words — the dictionary — for the game. It is admissible for the dictionary to contain similar words. The rul...
Input2abaabac
OutputSecond29 35
4 seconds
256 megabytes
['dp', 'games', 'strings', '*2100']
E. Let's Go Rolling!time limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputOn a number axis directed from the left rightwards, n marbles with coordinates x1, x2, ..., xn are situated. Let's assume that the sizes of the marbles are infinitely small, that is in this task eac...
Input32 33 41 2
Output5
2 seconds
256 megabytes
['dp', 'sortings', '*1800']
D. Vasya the Architecttime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputOnce Vasya played bricks. All the bricks in the set had regular cubical shape. Vasya vas a talented architect, however the tower he built kept falling apart.Let us consider the building process. V...
Input20 0 3 31 0 4 3
Output2
2 seconds
256 megabytes
['implementation', '*1900']
C. Blindstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe blinds are known to consist of opaque horizontal stripes that can be rotated thus regulating the amount of light flowing in the room. There are n blind stripes with the width of 1 in the factory warehouse ...
Input4 21 2 3 4
Output8
2 seconds
256 megabytes
['brute force', '*1400']
B. Chesstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputTwo chess pieces, a rook and a knight, stand on a standard chessboard 8 × 8 in size. The positions in which they are situated are known. It is guaranteed that none of them beats the other one.Your task is to fi...
Inputa1b2
Output44
2 seconds
256 megabytes
['brute force', 'implementation', 'math', '*1200']
A. Armytime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe Berland Armed Forces System consists of n ranks that are numbered using natural numbers from 1 to n, where 1 is the lowest rank and n is the highest rank.One needs exactly di years to rise from rank i to ran...
Input35 61 2
Output5
2 seconds
256 megabytes
['implementation', '*800']
E. Trial for Chieftime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputHaving unraveled the Berland Dictionary, the scientists managed to read the notes of the chroniclers of that time. For example, they learned how the chief of the ancient Berland tribe was chosen.As so...
Input3 3WBWBWBWBW
Output2
2 seconds
256 megabytes
['graphs', 'greedy', 'shortest paths', '*2600']
D. Lesson Timetabletime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputWhen Petya has free from computer games time, he attends university classes. Every day the lessons on Petya’s faculty consist of two double classes. The floor where the lessons take place is a long co...
Input31 1 11 2 3
Output36
1 second
256 megabytes
['combinatorics', 'dp', 'math', '*2300']
C. Old Berland Languagetime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputBerland scientists know that the Old Berland language had exactly n words. Those words had lengths of l1, l2, ..., ln letters. Every word consisted of two letters, 0 and 1. Ancient Berland people...
Input31 2 3
OutputYES010110
2 seconds
256 megabytes
['data structures', 'greedy', 'trees', '*1900']
B. Computer Gametime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputVasya’s elder brother Petya loves playing computer games. In one of his favourite computer games Petya reached the final level where a fight with the boss take place.While playing the game Petya found sp...
Input2 10 3100 399 1
OutputNO
1 second
256 megabytes
['greedy', 'implementation', '*1800']
A. Towerstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputLittle Vasya has received a young builder’s kit. The kit consists of several wooden bars, the lengths of all of them are known. The bars can be put one on the top of the other if their lengths are the same.Vas...
Input31 2 3
Output1 3
2 seconds
256 megabytes
['sortings', '*1000']
E. Two Pathstime limit per test2 secondsmemory limit per test64 megabytesinputinput.txtoutputoutput.txtOnce archaeologists found m mysterious papers, each of which had a pair of integers written on them. Ancient people were known to like writing down the indexes of the roads they walked along, as «a b» or «b a», where ...
Input24 54 3
Output12 11
2 seconds
64 megabytes
['constructive algorithms', 'dsu', 'graphs', 'implementation', '*2600']
D. New Game with a Chess Piecetime limit per test2 secondsmemory limit per test64 megabytesinputinput.txtoutputoutput.txtPetya and Vasya are inventing a new game that requires a rectangular board and one chess piece. At the beginning of the game the piece stands in the upper-left corner of the board. Two players move t...
Input10 21 11 22 12 21 32 33 13 23 34 3
Output-++--+-+++
2 seconds
64 megabytes
['games', '*2300']
C. Bowlstime limit per test2 secondsmemory limit per test64 megabytesinputinput.txtoutputoutput.txtOnce Petya was in such a good mood that he decided to help his mum with the washing-up. There were n dirty bowls in the sink. From the geometrical point of view each bowl looks like a blunted cone. We can disregard the wi...
Input240 10 5060 20 30
Output70.00000000
2 seconds
64 megabytes
['geometry', 'implementation', '*2200']
B. Fractaltime limit per test2 secondsmemory limit per test64 megabytesinputinput.txtoutputoutput.txtEver since Kalevitch, a famous Berland abstractionist, heard of fractals, he made them the main topic of his canvases. Every morning the artist takes a piece of graph paper and starts with making a model of his future c...
Input2 3.*..
Output.*******..******.*.*****....****.***.***..**..**.*.*.*.*........
2 seconds
64 megabytes
['implementation', '*1600']
A. Extra-terrestrial Intelligencetime limit per test2 secondsmemory limit per test64 megabytesinputinput.txtoutputoutput.txtRecently Vasya got interested in finding extra-terrestrial intelligence. He made a simple extra-terrestrial signals’ receiver and was keeping a record of the signals for n days in a row. Each of t...
Input800111000
OutputYES
2 seconds
64 megabytes
['implementation', '*1300']
E. Paradetime limit per test2 secondsmemory limit per test64 megabytesinputinput.txtoutputoutput.txtNo Great Victory anniversary in Berland has ever passed without the war parade. This year is not an exception. That’s why the preparations are on in full strength. Tanks are building a line, artillery mounts are ready to...
Input23 0 24 1 3
Output60 00 31 31 43 43 0
2 seconds
64 megabytes
['data structures', 'sortings', '*2100']
D. Animalstime limit per test2 secondsmemory limit per test64 megabytesinputinput.txtoutputoutput.txtOnce upon a time DravDe, an outstanding person famous for his professional achievements (as you must remember, he works in a warehouse storing Ogudar-Olok, a magical but non-alcoholic drink) came home after a hard day. ...
Input3 41 1 1
Output2
2 seconds
64 megabytes
['dp', 'greedy', '*1700']
C. Fire Againtime limit per test2 secondsmemory limit per test64 megabytesinputinput.txtoutputoutput.txtAfter a terrifying forest fire in Berland a forest rebirth program was carried out. Due to it N rows with M trees each were planted and the rows were so neat that one could map it on a system of coordinates so that t...
Input3 312 2
Output1 1
2 seconds
64 megabytes
['brute force', 'dfs and similar', 'shortest paths', '*1500']
B. Warehousetime limit per test2 secondsmemory limit per test64 megabytesinputinput.txtoutputoutput.txtOnce upon a time, when the world was more beautiful, the sun shone brighter, the grass was greener and the sausages tasted better Arlandia was the most powerful country. And its capital was the place where our hero Dr...
Input2 2 9+1 1 1 cola+1 1 1 fanta+1 1 1 sevenup+1 1 1 whitekey-1 cola-1 fanta-1 sevenup-1 whitekey-1 cola
Output1 11 22 12 2-1 -1
2 seconds
64 megabytes
['implementation', '*1700']
A. Shell Gametime limit per test2 secondsmemory limit per test64 megabytesinputinput.txtoutputoutput.txtToday the «Z» city residents enjoy a shell game competition. The residents are gathered on the main square to watch the breath-taking performance. The performer puts 3 non-transparent cups upside down in a row. Then ...
Input11 22 12 1
Output2
2 seconds
64 megabytes
['implementation', '*1000']
E. Collisionstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputOn a number line there are n balls. At time moment 0 for each ball the following data is known: its coordinate xi, speed vi (possibly, negative) and weight mi. The radius of the balls can be ignored.The ba...
Input2 93 4 50 7 8
Output68.53846153844.538461538
2 seconds
256 megabytes
['brute force', 'implementation', 'math', '*2000']
D. Road Maptime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere are n cities in Berland. Each city has its index — an integer number from 1 to n. The capital has index r1. All the roads in Berland are two-way. The road system is such that there is exactly one path ...
Input3 2 32 2
Output2 3
2 seconds
256 megabytes
['dfs and similar', 'graphs', '*1600']
C. Page Numberstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard output«Bersoft» company is working on a new version of its most popular text editor — Bord 2010. Bord, like many other text editors, should be able to print out multipage documents. A user keys a sequence of t...
Input1,2,3,1,1,2,6,6,2
Output1-3,6
2 seconds
256 megabytes
['expression parsing', 'implementation', 'sortings', 'strings', '*1300']
B. Saletime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputOnce Bob got to a sale of old TV sets. There were n TV sets at that sale. TV set with index i costs ai bellars. Some TV sets have a negative price — their owners are ready to pay Bob if he buys their useless app...
Input5 3-6 0 35 -2 4
Output8
2 seconds
256 megabytes
['greedy', 'sortings', '*900']
A. Reconnaissance 2time limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputn soldiers stand in a circle. For each soldier his height ai is known. A reconnaissance unit can be made of such two neighbouring soldiers, whose heights difference is minimal, i.e. |ai - aj| is mini...
Input510 12 13 15 10
Output5 1
2 seconds
256 megabytes
['implementation', '*800']
E. Helpertime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputIt's unbelievable, but an exam period has started at the OhWord University. It's even more unbelievable, that Valera got all the tests before the exam period for excellent work during the term. As now he's fre...
Input3 3 4calculusalgebrahistory58 23 1500:00-08:1508:20-08:3509:30-10:2519:00-19:45calculus 1 09:36 100english 4 21:15 5000history 1 19:50 50
Output15021 1 08:16 1 09:293 1 10:26 1 10:40
2 seconds
256 megabytes
['*2600']
D. Knightstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputBerland is facing dark times again. The army of evil lord Van de Mart is going to conquer the whole kingdom. To the council of war called by the Berland's king Valery the Severe came n knights. After long dis...
Input2 1 10 03 32 0 01 2
Output1
2 seconds
256 megabytes
['geometry', 'graphs', 'shortest paths', 'sortings', '*2000']
C. Wonderful Randomized Sumtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputLearn, learn and learn again — Valera has to do this every day. He is studying at mathematical school, where math is the main discipline. The mathematics teacher loves her discipline very muc...
Input3-1 -2 -3
Output6
2 seconds
256 megabytes
['greedy', '*1800']
B. String Problemtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputBoy Valera likes strings. And even more he likes them, when they are identical. That's why in his spare time Valera plays the following game. He takes any two strings, consisting of lower case Latin le...
Inputuayduxxd3a x 8x y 13d c 3
Output21uxyd
2 seconds
256 megabytes
['shortest paths', '*1800']
A. What is for dinner?time limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputIn one little known, but very beautiful country called Waterland, lives a lovely shark Valerie. Like all the sharks, she has several rows of teeth, and feeds on crucians. One of Valerie's distingu...
Input4 3 182 31 23 62 3
Output11
2 seconds
256 megabytes
['greedy', 'implementation', '*1200']
E. Hide-and-Seektime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputVictor and Peter are playing hide-and-seek. Peter has hidden, and Victor is to find him. In the room where they are playing, there is only one non-transparent wall and one double-sided mirror. Victor an...
Input-1 31 30 2 0 40 0 0 1
OutputNO
2 seconds
256 megabytes
['geometry', 'implementation', '*2400']
D. Constellationtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputA star map in Berland is a checked field n × m squares. In each square there is or there is not a star. The favourite constellation of all Berland's astronomers is the constellation of the Cross. This c...
Input5 6 1....*....***....*...*....***..
Output2 51 53 52 42 6
2 seconds
256 megabytes
['implementation', '*1600']
C. Fleatime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputIt is known that fleas in Berland can jump only vertically and horizontally, and the length of the jump is always equal to s centimeters. A flea has found herself at the center of some cell of the checked board ...
Input2 3 1000000
Output6
2 seconds
256 megabytes
['math', '*1700']
B. Borzetime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputTernary numeric notation is quite popular in Berland. To telegraph the ternary number the Borze alphabet is used. Digit 0 is transmitted as «.», 1 as «-.» and 2 as «--». You are to decode the Borze code, i.e. t...
Input.-.--
Output012
2 seconds
256 megabytes
['expression parsing', 'implementation', '*800']
A. Reconnaissancetime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputAccording to the regulations of Berland's army, a reconnaissance unit should consist of exactly two soldiers. Since these two soldiers shouldn't differ much, their heights can differ by at most d centi...
Input5 1010 20 50 60 65
Output6
2 seconds
256 megabytes
['brute force', '*800']
E. TV Gametime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere is a new TV game on BerTV. In this game two players get a number A consisting of 2n digits. Before each turn players determine who will make the next move. Each player should make exactly n moves. On it...
Input21234
OutputHHMM
2 seconds
256 megabytes
['dp', '*2400']
D. Chocolatetime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputBob has a rectangular chocolate bar of the size W × H. He introduced a cartesian coordinate system so that the point (0, 0) corresponds to the lower-left corner of the bar, and the point (W, H) corresponds ...
Input2 2 21 0 1 20 1 1 1
Output1 1 2
2 seconds
256 megabytes
['dfs and similar', 'implementation', '*2000']
C. Scheduletime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputAt the beginning of the new semester there is new schedule in the Berland State University. According to this schedule, n groups have lessons at the room 31. For each group the starting time of the lesson an...
Input33 1020 301 3
Output31 2 3
2 seconds
256 megabytes
['implementation', '*1700']
B. Sysadmin Bobtime limit per test0.5 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputEmail address in Berland is a string of the form A@B, where A and B are arbitrary strings consisting of small Latin letters. Bob is a system administrator in «Bersoft» company. He keeps a list of email ...
Inputa@aa@a
Outputa@a,a@a
0.5 second
256 megabytes
['greedy', 'implementation', 'strings', '*1500']
A. Worms Evolutiontime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputProfessor Vasechkin is studying evolution of worms. Recently he put forward hypotheses that all worms evolve by division. There are n forms of worms. Worms of these forms have lengths a1, a2, ..., an....
Input51 2 3 5 7
Output3 2 1
2 seconds
256 megabytes
['implementation', '*1200']
E. Tricky and Clever Passwordtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputIn his very young years the hero of our story, king Copa, decided that his private data was hidden not enough securely, what is unacceptable for the king. That's why he invented tricky and ...
Inputabacaba
Output11 7
2 seconds
256 megabytes
['binary search', 'constructive algorithms', 'data structures', 'greedy', 'hashing', 'strings', '*2800']
D. King's Problem?time limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputEvery true king during his life must conquer the world, hold the Codeforces world finals, win pink panda in the shooting gallery and travel all over his kingdom.King Copa has already done the first th...
Input3 10 1 2 11
Output3.41421356237309490000
3 seconds
256 megabytes
['geometry', 'greedy', '*2600']
C. Shooting Gallerytime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputOne warm and sunny day king Copa decided to visit the shooting gallery, located at the Central Park, and try to win the main prize — big pink plush panda. The king is not good at shooting, so he invi...
Input10 0 0 0.5
Output0.5000000000
2 seconds
256 megabytes
['dp', 'probabilities', '*1800']