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
I. Sort the Tabletime limit per test2 secondsmemory limit per test64 megabytesinputstandard inputoutputstandard outputYou are given a rectangular table containing words. Each of its columns has its own name. You are also given the list of rules of sorting in form "FIELD_NAME SORT_ORDER", where SORT_ORDER is either ASC ...
InputNAME GROUP AGEGROUP ASC, AGE DESCAlex 412 19Peter 422 19Sergey 412 18Andrey 311 18
OutputAndrey 311 18Alex 412 19Sergey 412 18Peter 422 19
2 seconds
64 megabytes
['*special problem', 'sortings', '*2400']
H. Table Bowlingtime limit per test2 secondsmemory limit per test64 megabytesinputstandard inputoutputstandard outputTable bowling tournament participant completed the competition according to the given final standings table. The table is given as a sequence of lines, each line has a format "name score". Your task is t...
Input5vasya 10ted 11petya 10katya 33mike 44
Output1 mike2 katya3 ted4-5 petya4-5 vasya
2 seconds
64 megabytes
['*special problem', 'sortings', '*2300']
G. Path Canonizationtime limit per test2 secondsmemory limit per test64 megabytesinputstandard inputoutputstandard outputA path in some Unix-similar file system is given. The path consists of elements separated with characters "/". For example: "/usr/share/mysql/../tomcat6/conf/server.xml". The path starts with the roo...
Input/usr/share/mysql/../tomcat6/conf/server.xml
Output/usr/share/tomcat6/conf/server.xml
2 seconds
64 megabytes
['*special problem', '*2200']
F. Domaintime limit per test2 secondsmemory limit per test64 megabytesinputstandard inputoutputstandard outputThis problem doesn't contain real-world specifications about domains, just use the problem statement as a formal document to solve the problem.The given string s is a domain name if it contains the characters "...
Inputcodeforces.com
OutputYES
2 seconds
64 megabytes
['*special problem', 'expression parsing', '*2000']
E. Prime Segmenttime limit per test2 secondsmemory limit per test64 megabytesinputstandard inputoutputstandard outputPositive integer number x is called prime, if it has exactly two positive integer divisors. For example, 2, 3, 17, 97 are primes, but 1, 10, 120 are not.You are given an integer number n, find the shorte...
Input10
Output7 11
2 seconds
64 megabytes
['*special problem', 'brute force', 'math', 'number theory', '*1800']
D. Presentstime limit per test2 secondsmemory limit per test64 megabytesinputstandard inputoutputstandard outputYou are given the prices of three presents. Also there are three sisters. It is known that the most valuable present is for the eldest sister. The second (by price) is for the second sister. And the less valu...
Input11 13 1
Output2 1 3
2 seconds
64 megabytes
['*special problem', 'greedy', '*1800']
C. Tabletime limit per test2 secondsmemory limit per test64 megabytesinputstandard inputoutputstandard outputThe integer numbers from 1 to nm was put into rectangular table having n rows and m columns. The numbers was put from left to right, from top to bottom, i.e. the first row contains integers 1, 2, ..., m, the sec...
Input3 4 11
Output8
2 seconds
64 megabytes
['*special problem', 'greedy', 'implementation', 'math', '*1600']
B. Expressiontime limit per test2 secondsmemory limit per test64 megabytesinputstandard inputoutputstandard outputYou are given a line «n#m», where «n» and «m» are digits, and «#» is a sign «+» or «-». Print the value of the given expression.InputThe only given line has a string in form «n#m», where «n» and «m» are dig...
Input1-5
Output-4
2 seconds
64 megabytes
['*special problem', 'expression parsing', '*1500']
A. Factorialtime limit per test2 secondsmemory limit per test64 megabytesinputstandard inputoutputstandard outputPrint the factorial of the given integer number n. The factorial of n is equal to 1·2·...·n.InputThe only line contains n (1 ≤ n ≤ 10).OutputPrint the factorial of n.ExamplesInput3Output6Input5Output120
Input3
Output6
2 seconds
64 megabytes
['*special problem', 'implementation', '*1300']
E. Sweets Gametime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputKarlsson has visited Lillebror again. They found a box of chocolates and a big whipped cream cake at Lillebror's place. Karlsson immediately suggested to divide the sweets fairly between Lillebror and him...
Input . . . . . O .. . O O . . . . . . . .
OutputLillebror
3 seconds
256 megabytes
['bitmasks', 'dfs and similar', 'dp', 'games', 'implementation', '*2000']
D. Dividing Islandtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputA revolution took place on the Buka Island. New government replaced the old one. The new government includes n parties and each of them is entitled to some part of the island according to their contri...
Input3 4 2 2 35 8 3
OutputYESaaabbaabbbcbb..ccb..
2 seconds
256 megabytes
['constructive algorithms', '*1900']
C. Bulls and Cowstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe "Bulls and Cows" game needs two people to play. The thinker thinks of a number and the guesser tries to guess it.The thinker thinks of a four-digit number in the decimal system. All the digits in t...
Input21263 1 28103 2 1
OutputNeed more data
2 seconds
256 megabytes
['brute force', 'implementation', '*1700']
B. Settlers' Trainingtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputIn a strategic computer game "Settlers II" one has to build defense structures to expand and protect the territory. Let's take one of these buildings. At the moment the defense structure accommodat...
Input4 41 2 2 3
Output4
2 seconds
256 megabytes
['implementation', '*1200']
A. Sinking Shiptime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe ship crashed into a reef and is sinking. Now the entire crew must be evacuated. All n crew members have already lined up in a row (for convenience let's label them all from left to right with positiv...
Input6Jack captainAlice womanCharlie manTeddy ratBob childJulia woman
OutputTeddyAliceBobJuliaCharlieJack
2 seconds
256 megabytes
['implementation', 'sortings', 'strings', '*900']
E. World Eviltime limit per test5 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputAs a result of Pinky and Brain's mysterious experiments in the Large Hadron Collider some portals or black holes opened to the parallel dimension. And the World Evil has crept to the veil between their wor...
Input3 44 4 41 1 55 5 34 1 21 3 13 5 41 4 3
Output7
5 seconds
256 megabytes
['dp', 'flows', '*2700']
D. Wormhousetime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputArnie the Worm has finished eating an apple house yet again and decided to move. He made up his mind on the plan, the way the rooms are located and how they are joined by corridors. He numbered all the room...
Input3 31 2 3 1
Output1 3 2 1
2 seconds
256 megabytes
['dfs and similar', 'graphs', '*2300']
C. Inquisitiontime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputIn Medieval times existed the tradition of burning witches at steaks together with their pets, black cats. By the end of the 15-th century the population of black cats ceased to exist. The difficulty of t...
Input11 1 2 1 1 2
Output3.4142135624
3 seconds
256 megabytes
['geometry', 'implementation', 'sortings', '*2300']
B. Tyndex.Brometime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputTyndex is again well ahead of the rivals! The reaction to the release of Zoozle Chrome browser was the release of a new browser Tyndex.Brome!The popularity of the new browser is growing daily. And the se...
Input2 10codeforcescodeforcescodehorses
Output012
2 seconds
256 megabytes
['binary search', 'implementation', '*1800']
A. A Student's Dreamtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputStatistics claims that students sleep no more than three hours a day. But even in the world of their dreams, while they are snoring peacefully, the sense of impending doom is still upon them.A poor ...
Input5 110 5
OutputYES
2 seconds
256 megabytes
['greedy', 'math', '*1300']
E. Enemy is weaktime limit per test5 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe Romans have attacked again. This time they are much more than the Persians but Shapur is ready to defeat them. He says: "A lion is never afraid of a hundred sheep". Nevertheless Shapur has to find w...
Input33 2 1
Output1
5 seconds
256 megabytes
['data structures', 'trees', '*1900']
D. Eternal Victorytime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputValerian was captured by Shapur. The victory was such a great one that Shapur decided to carve a scene of Valerian's defeat on a mountain. So he had to find the best place to make his victory eternal!...
Input31 2 32 3 4
Output7
2 seconds
256 megabytes
['dfs and similar', 'graphs', 'greedy', 'shortest paths', 'trees', '*1800']
C. Capture Valeriantime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputIt's now 260 AD. Shapur, being extremely smart, became the King of Persia. He is now called Shapur, His majesty King of kings of Iran and Aniran.Recently the Romans declared war on Persia. They dream...
Input10 21
Output1
2 seconds
256 megabytes
['math', '*2000']
B. Hard Worktime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputAfter the contest in comparing numbers, Shapur's teacher found out that he is a real genius and that no one could possibly do the calculations faster than him even using a super computer!Some days before th...
InputIran_Persian;W_o;n;d;e;r;f;u;l;7WonderfulPersianIranwonderful_PersIAN_IRAN;;_WONDERFUL___IRAN__PERSIAN__;;Ira__Persiann__WonderfulWonder;;fulPersian___;I;r;a;n;__________IranPersianWonderful__________PersianIran_is_Wonderful
OutputACCACCACCWAACCACCWA
2 seconds
256 megabytes
['strings', '*1300']
A. Ultra-Fast Mathematiciantime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputShapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He...
Input10101000100101
Output1110001
2 seconds
256 megabytes
['implementation', '*800']
E. Mushroom Gnomestime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputOnce upon a time in the thicket of the mushroom forest lived mushroom gnomes. They were famous among their neighbors for their magic mushrooms. Their magic nature made it possible that between every t...
Input2 1 0 6572765451 2
Output6
3 seconds
256 megabytes
['math', 'matrices', '*2600']
D. Saviortime limit per test4 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputMisha decided to help Pasha and Akim be friends again. He had a cunning plan — to destroy all the laughy mushrooms. He knows that the laughy mushrooms can easily burst when they laugh. Mushrooms grow on the la...
Input12
Output1
4 seconds
256 megabytes
['brute force', 'dsu', 'math', '*2500']
C. Mushroom Strifetime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputPasha and Akim were making a forest map — the lawns were the graph's vertexes and the roads joining the lawns were its edges. They decided to encode the number of laughy mushrooms on every lawn in the...
Input1 0
OutputYES1
2 seconds
256 megabytes
['brute force', 'dfs and similar', '*2100']
B. Serial Time!time limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe Cereal Guy's friend Serial Guy likes to watch soap operas. An episode is about to start, and he hasn't washed his plate yet. But he decided to at least put in under the tap to be filled with water. T...
Input1 1 1.1 1
Output1
2 seconds
256 megabytes
['dfs and similar', 'dsu', '*1400']
A. Where Are My Flakes?time limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard output One morning the Cereal Guy found out that all his cereal flakes were gone. He found a note instead of them. It turned out that his smart roommate hid the flakes in one of n boxes. The boxes sta...
Input2 1To the left of 2
Output1
2 seconds
256 megabytes
['implementation', 'two pointers', '*1300']
E. Shortest Pathtime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputIn Ancient Berland there were n cities and m two-way roads of equal length. The cities are numbered with integers from 1 to n inclusively. According to an ancient superstition, if a traveller visits thr...
Input4 4 11 22 33 41 31 4 3
Output21 3 4
3 seconds
256 megabytes
['graphs', 'shortest paths', '*2000']
D. Team Arrangementtime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputRecently personal training sessions have finished in the Berland State University Olympiad Programmer Training Centre. By the results of these training sessions teams are composed for the oncoming te...
Input35 4 1 2 6 3 7 8 95 6 29 3 41 7 84
Output2 3 5 6 9 1 7 8
3 seconds
256 megabytes
['constructive algorithms', 'greedy', 'implementation', '*2000']
C. Titletime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputVasya has recently finished writing a book. Now he faces the problem of giving it the title. Vasya wants the title to be vague and mysterious for his book to be noticeable among others. That's why the title sho...
Input3a?c
OutputIMPOSSIBLE
2 seconds
256 megabytes
['expression parsing', '*1600']
B. Fortune Tellingtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputMarina loves Sasha. But she keeps wondering whether Sasha loves her. Of course, the best way to know it is fortune telling. There are many ways of telling fortune, but Marina has picked the easiest on...
Input11
Output1
2 seconds
256 megabytes
['implementation', 'number theory', '*1200']
A. Wordtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputVasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in e...
InputHoUse
Outputhouse
2 seconds
256 megabytes
['implementation', 'strings', '*800']
E. Expressiontime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputOne day Vasya was solving arithmetical problems. He wrote down an expression a + b = c in his notebook. When the teacher checked Vasya's work it turned out that Vasya had solved the problem incorrectly. No...
Input2+4=5
Output21+4=25
2 seconds
256 megabytes
['dp', '*2400']
D. Calendartime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputBerOilGasDiamondBank has branches in n cities, at that n is an even number. The bank management wants to publish a calendar with the names of all those cities written in two columns: the calendar should cons...
Input4baahgc.
Outputaa.bc.hg
2 seconds
256 megabytes
['greedy', 'strings', '*2000']
C. Treestime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputOn Bertown's main street n trees are growing, the tree number i has the height of ai meters (1 ≤ i ≤ n). By the arrival of the President of Berland these trees were decided to be changed so that their heights f...
Input32 2 2
Output1
2 seconds
256 megabytes
['brute force', '*1800']
B. Coinstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputIn Berland a money reform is being prepared. New coins are being introduced. After long economic calculations was decided that the most expensive coin should possess the denomination of exactly n Berland dollar...
Input10
Output10 5 1
2 seconds
256 megabytes
['greedy', '*1300']
A. Chat roomtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputVasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word s. It is considered that Vasya managed to say hel...
Inputahhellllloou
OutputYES
1 second
256 megabytes
['greedy', 'strings', '*1000']
E. Chesstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputBrian the Rabbit adores chess. Not long ago he argued with Stewie the Rabbit that a knight is better than a king. To prove his point he tries to show that the knight is very fast but Stewie doesn't accept state...
Input1 0
Output9
2 seconds
256 megabytes
['math', 'shortest paths', '*3000']
D. Journeytime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputStewie the Rabbit explores a new parallel universe. This two dimensional universe has the shape of a rectangular grid, containing n lines and m columns. The universe is very small: one cell of the grid can onl...
Input2 2...X
Output0.888888888889
1 second
256 megabytes
['dp', 'math', '*2500']
C. Arraytime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputChris the Rabbit has been interested in arrays ever since he was a child. At the moment he is researching arrays with the length of n, containing only integers from 1 to n. He is not good at math, that's why so...
Input2
Output4
2 seconds
256 megabytes
['combinatorics', 'math', '*1900']
B. Martian Architecturetime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputChris the Rabbit found the traces of an ancient Martian civilization. The brave astronomer managed to see through a small telescope an architecture masterpiece — "A Road to the Sun". The building...
Input5 2 11 5 12 4 13
Output5
2 seconds
256 megabytes
['implementation', '*1600']
A. Square Earth?time limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputMeg the Rabbit decided to do something nice, specifically — to determine the shortest distance between two points on the surface of our planet. But Meg... what can you say, she wants everything simple. ...
Input2 0 0 1 0
Output1
2 seconds
256 megabytes
['dfs and similar', 'greedy', 'implementation', '*1300']
E. Domino Principletime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputVasya is interested in arranging dominoes. He is fed up with common dominoes and he uses the dominoes of different heights. He put n dominoes on the table along one axis, going from left to right. Ev...
Input416 520 510 1018 2
Output3 1 4 1
2 seconds
256 megabytes
['binary search', 'data structures', 'sortings', '*2200']
D. Changing a Stringtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere is a string s, consisting of capital Latin letters. Let's denote its current length as |s|. During one move it is allowed to apply one of the following operations to it: INSERT pos ch — inse...
InputABAABBBA
Output2INSERT 3 BINSERT 4 B
2 seconds
256 megabytes
['dp', '*2100']
C. Corporation Mailtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe Beroil corporation structure is hierarchical, that is it can be represented as a tree. Let's examine the presentation of this structure as follows: employee ::= name. | name:employee1,employee2,...
InputMIKE:MAX.,ARTEM:MIKE..,DMITRY:DMITRY.,DMITRY...
Output3
2 seconds
256 megabytes
['data structures', 'expression parsing', 'implementation', '*1700']
B. Spoilt Permutationtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputVasya collects coins: he has exactly one coin for every year from 1 to n. Naturally, Vasya keeps all the coins in his collection in the order in which they were released. Once Vasya's younger broth...
Input81 6 5 4 3 2 7 8
Output2 6
2 seconds
256 megabytes
['implementation', '*1300']
A. Bartime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputAccording to Berland laws it is only allowed to sell alcohol to people not younger than 18 years. Vasya's job is to monitor the law's enforcement. Tonight he entered a bar and saw n people sitting there. For ever...
Input518VODKACOKE1917
Output2
2 seconds
256 megabytes
['implementation', '*1000']
E. Very simple problemtime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a convex polygon. Count, please, the number of triangles that contain a given point in the plane and their vertices are the vertices of the polygon. It is guaranteed, that the point ...
Input45 00 00 55 511 3
Output2
3 seconds
256 megabytes
['geometry', 'two pointers', '*2500']
D. Beautiful numberstime limit per test4 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputVolodya is an odd boy and his taste is strange as well. It seems to him that a positive integer number is beautiful if and only if it is divisible by each of its nonzero digits. We will not argue wi...
Input11 9
Output9
4 seconds
256 megabytes
['dp', 'number theory', '*2500']
C. Pie or dietime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputVolodya and Vlad play the following game. There are k pies at the cells of n  ×  m board. Each turn Volodya moves one pie to the neighbouring (by side) cell. If the pie lies at the border of the board then...
Input2 2 11 2
OutputYES
2 seconds
256 megabytes
['games', '*1900']
B. Smallest numbertime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputRecently, Vladimir got bad mark in algebra again. To avoid such unpleasant events in future he decided to train his arithmetic skills. He wrote four integer numbers a, b, c, d on the blackboard. Durin...
Input1 1 1 1+ + *
Output3
2 seconds
256 megabytes
['brute force', '*1600']
A. Flea traveltime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputA flea is sitting at one of the n hassocks, arranged in a circle, at the moment. After minute number k the flea jumps through k - 1 hassoсks (clockwise). For example, after the first minute the flea jumps ...
Input1
OutputYES
1 second
256 megabytes
['implementation', 'math', '*1200']
E. Vacuum Сleanertime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputOne winter evening the Hedgehog was relaxing at home in his cozy armchair and clicking through the TV channels. Stumbled on an issue of «TopShop», the Hedgehog was about to change the channel when all o...
Input40 01 01 10 1
Output0.00000000000000000000
1 second
256 megabytes
['geometry', '*2700']
D. Writing a Songtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputOne of the Hedgehog and his friend's favorite entertainments is to take some sentence or a song and replace half of the words (sometimes even all of them) with each other's names.The friend's birthday ...
Input5 2aba101
Outputababa
2 seconds
256 megabytes
['brute force', 'dp', 'strings', '*2100']
C. First Digit Lawtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputIn the probability theory the following paradox called Benford's law is known: "In many lists of random numbers taken from real sources, numbers starting with digit 1 occur much more often than number...
Input11 250
Output0.500000000000000
2 seconds
256 megabytes
['dp', 'math', 'probabilities', '*2000']
B. Cutting Jigsaw Puzzletime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe Hedgehog recently remembered one of his favorite childhood activities, — solving puzzles, and got into it with new vigor. He would sit day in, day out with his friend buried into thousands o...
Input2 4ABDCABDC
Output32 1
2 seconds
256 megabytes
['hashing', 'implementation', '*1800']
A. Presentstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe Hedgehog likes to give presents to his friend, but no less he likes to receive them.Having received another present today, the Hedgehog suddenly understood that he has no place to put it as there was no ...
Input5 21 3
Output3
2 seconds
256 megabytes
['implementation', '*1300']
E. Dead Endstime limit per test5 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputLife in Bertown has become hard. The city has too many roads and the government spends too much to maintain them. There are n junctions and m two way roads, at which one can get from each junction to any ot...
Input3 3 21 22 31 3
Output3
5 seconds
256 megabytes
['bitmasks', 'dp', '*2500']
D. Physical Educationtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputVasya is a school PE teacher. Unlike other PE teachers, Vasya doesn't like it when the students stand in line according to their height. Instead, he demands that the children stand in the following...
Input41 2 3 23 2 1 2
Output42 31 23 42 3
2 seconds
256 megabytes
['sortings', '*1500']
C. Little Frogtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputOnce upon a time a little frog whose name was Vasya decided to travel around his home swamp. Overall there are n mounds on the swamp, located on one line. The distance between the neighboring mounds is on...
Input2
Output1 2
2 seconds
256 megabytes
['constructive algorithms', '*1200']
B. Blog Phototime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputOne popular blog site edits the uploaded photos like this. It cuts a rectangular area out of them so that the ratio of height to width (i.e. the height / width quotient) can vary from 0.8 to 1.25 inclusive...
Input2 1
Output1 1
2 seconds
256 megabytes
['binary search', 'implementation', '*1700']
A. Autocompletetime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputAutocomplete is a program function that enables inputting the text (in editors, command line shells, browsers etc.) completing the text by its inputted part. Vasya is busy working on a new browser called...
Inputnext2nextpermutationnextelement
Outputnextelement
2 seconds
256 megabytes
['implementation', '*1100']
C. Circular RMQtime limit per test1.5 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given circular array a0, a1, ..., an - 1. There are two types of operations with it: inc(lf, rg, v) — this operation increases each element on the segment [lf, rg] (inclusively) by v; rmq(lf...
Input41 2 3 443 03 0 -10 12 1
Output100
1.5 seconds
256 megabytes
['data structures', '*2200']
B. Right Trianglestime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a n × m field consisting only of periods ('.') and asterisks ('*'). Your task is to count all right triangles with two sides parallel to the square sides, whose vertices are in the cente...
Input2 2***.
Output1
2 seconds
256 megabytes
['combinatorics', '*1600']
A. 123-sequencetime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere is a given sequence of integers a1, a2, ..., an, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are e...
Input91 3 2 2 2 1 1 2 3
Output5
2 seconds
256 megabytes
['implementation', '*900']
F. Caterpillartime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputAn undirected graph is called a caterpillar if it is a connected graph without cycles and it has such a path p that any vertex is located at a distance of at most 1 from the path p. The caterpillar can co...
Input4 41 22 33 44 2
Output2
2 seconds
256 megabytes
['dfs and similar', 'dp', 'graphs', 'trees', '*2800']
E. Pentagontime limit per test10 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputAccording to the last order issued by the president of Berland every city of the country must have its own Ministry Defense building (their own Pentagon). A megapolis Berbourg was not an exception. This cit...
Input5 51 22 33 44 55 1
Output1
10 seconds
256 megabytes
['combinatorics', 'graphs', 'matrices', '*2400']
D. Geometrical problemtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputPolycarp loves geometric progressions — he collects them. However, as such progressions occur very rarely, he also loves the sequences of numbers where it is enough to delete a single element to ge...
Input43 6 12 24
Output0
1 second
256 megabytes
['implementation', '*2200']
C. Three Base Stationstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe New Vasjuki village is stretched along the motorway and that's why every house on it is characterized by its shift relative to some fixed point — the xi coordinate. The village consists of n ho...
Input41 2 3 4
Output0.5000001.500000 2.500000 3.500000
1 second
256 megabytes
['binary search', 'greedy', '*1800']
B. bHTML Tables Analisystime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputIn this problem is used an extremely simplified version of HTML table markup. Please use the statement as a formal document and read it carefully.A string is a bHTML table, if it satisfies the g...
Input<table><tr><td></td></tr></table>
Output1
2 seconds
256 megabytes
['expression parsing', '*1700']
A. Cheaterius's Problemtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputCheaterius is a famous in all the Berland astrologist, magician and wizard, and he also is a liar and a cheater. One of his latest inventions is Cheaterius' amulets! They bring luck and wealth, b...
Input43123**3123**1332**3213
Output1
2 seconds
256 megabytes
['implementation', '*1300']
E. Square Equation Rootstime limit per test5 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputA schoolboy Petya studies square equations. The equations that are included in the school curriculum, usually look simple: x2 + 2bx + c = 0 where b, c are natural numbers.Petya noticed that some...
Input3 3
Output12
5 seconds
256 megabytes
['math', '*2300']
D. Bombingtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe commanding officers decided to drop a nuclear bomb on the enemy's forces. You are ordered to determine the power of the warhead that needs to be used.The enemy has N strategically important objects. Their...
Input11 5005 51 2
Output3.84257761518762740
2 seconds
256 megabytes
['binary search', 'dp', 'probabilities', '*2100']
C. Happy Farm 5time limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe Happy Farm 5 creators decided to invent the mechanism of cow grazing. The cows in the game are very slow and they move very slowly, it can even be considered that they stand still. However, carnivore...
Input41 15 15 31 3
Output16
2 seconds
256 megabytes
['geometry', '*2000']
B. Choosing Symbol Pairstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere is a given string S consisting of N symbols. Your task is to find the number of ordered pairs of integers i and j such that1. 1 ≤ i, j ≤ N2. S[i] = S[j], that is the i-th symbol of string ...
Inputgreat10
Output7
2 seconds
256 megabytes
['strings', '*1500']
A. Domino pilingtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a rectangular board of M × N squares. Also you are given an unlimited number of standard domino pieces of 2 × 1 squares. You are allowed to rotate the pieces. You are asked to place as man...
Input2 4
Output4
2 seconds
256 megabytes
['greedy', 'math', '*800']
E. Common ancestortime limit per test5 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe DNA sequence for every living creature in Berland can be represented as a non-empty line consisting of lowercase Latin letters. Berland scientists found out that all the creatures evolve by stages...
Inputababaaba2c->bac->cc
Output2
5 seconds
256 megabytes
['dp', '*2300']
D. Gametime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputVasya and Petya have invented a new game. Vasya takes a stripe consisting of 1 × n square and paints the squares black and white. After that Petya can start moves — during a move he may choose any two neighborin...
Input6111010
Output1
2 seconds
256 megabytes
['brute force', 'dp', 'implementation', '*1800']
C. Dispositiontime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputVasya bought the collected works of a well-known Berland poet Petya in n volumes. The volumes are numbered from 1 to n. He thinks that it does not do to arrange the book simply according to their order. V...
Input2
Output2 1
2 seconds
256 megabytes
['constructive algorithms', 'math', '*1700']
B. Sumtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputVasya studies positional numeral systems. Unfortunately, he often forgets to write the base of notation in which the expression is written. Once he saw a note in his notebook saying a + b = ?, and that the base o...
Input78 87
Output3
2 seconds
256 megabytes
['math', '*1500']
A. Sleuthtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputVasya plays the sleuth with his friends. The rules of the game are as follows: those who play for the first time, that is Vasya is the sleuth, he should investigate a "crime" and find out what is happening. He...
InputIs it a melon?
OutputNO
2 seconds
256 megabytes
['implementation', '*800']
H. Black and Whitetime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputAccording to the legends the king of Berland Berl I was noted for his love of beauty and order. One day he ordered to tile the palace hall's floor where balls and receptions used to take place with bl...
Input2 20 0 4
Output\../#\/#\##/.\/.
2 seconds
256 megabytes
['constructive algorithms', '*2800']
G. Galaxy Uniontime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputIn a far away galaxy there are n inhabited planets numbered with numbers from 1 to n. One day the presidents of all the n planets independently from each other came up with an idea of creating the Galaxy...
Input31 2 32 3 21 3 1
Output4 5 3
3 seconds
256 megabytes
['dp', 'trees', 'two pointers', '*2700']
F. Snow sellerstime limit per test10 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe New Year celebrations in Berland last n days. Only this year the winter is snowless, that’s why the winter celebrations’ organizers should buy artificial snow. There are m snow selling companies in ...
Input2 3 104 4 45 5 81 2 5
Output22.000000000000000
10 seconds
256 megabytes
['greedy', 'sortings', '*2800']
E. Ivan the Fool VS Gorynych the Dragontime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputOnce upon a time in a kingdom far, far away… Okay, let’s start at the point where Ivan the Fool met Gorynych the Dragon. Ivan took out his magic sword and the battle began. First ...
Input2 2 421 00 130 10 10 0
OutputIvan2
2 seconds
256 megabytes
['dp', 'games', 'graphs', '*2100']
D. Permutationstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputA permutation is a sequence of integers from 1 to n of length n containing each number exactly once. For example, (1), (4, 3, 5, 1, 2), (3, 2, 1) are permutations, and (1, 1), (4, 3, 1), (2, 3, 4) are not...
Input91 2 3 1 2 1 4 2 5
Output33 1 2 1 2 2 2 3 2
1 second
256 megabytes
['greedy', '*1500']
C. The Racetime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputEvery year a race takes place on the motorway between cities A and B. This year Vanya decided to take part in the race and drive his own car that has been around and bears its own noble name — The Huff-puffe...
Input31 2 4
Outputunique5
2 seconds
256 megabytes
['math', '*1800']
B. Land Lottime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputVasya has a beautiful garden where wonderful fruit trees grow and yield fantastic harvest every year. But lately thieves started to sneak into the garden at nights and steal the fruit too often. Vasya can’t ...
Input2 21 01 11 1
Output0
2 seconds
256 megabytes
['brute force', 'implementation', '*1200']
A. Rock-paper-scissorstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputUncle Fyodor, Matroskin the Cat and Sharic the Dog live their simple but happy lives in Prostokvashino. Sometimes they receive parcels from Uncle Fyodor’s parents and sometimes from anonymous bene...
Inputrockrockrock
Output?
2 seconds
256 megabytes
['implementation', 'schedules', '*900']
E. Cannontime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputBertown is under siege! The attackers have blocked all the ways out and their cannon is bombarding the city. Fortunately, Berland intelligence managed to intercept the enemies' shooting plan. Let's introduce t...
Input2 100.78530.335.0 5.04.0 2.46.0 1.9
Output5.000000000 2.5494993694.000000000 0.378324889
3 seconds
256 megabytes
['data structures', 'geometry', 'sortings', '*2200']
D. Safetime limit per test5 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputVasya tries to break in a safe. He knows that a code consists of n numbers, and every number is a 0 or a 1. Vasya has made m attempts to enter the code. After each attempt the system told him in how many positio...
Input6 2000000 2010100 4
Output6
5 seconds
256 megabytes
['brute force', '*2200']
C. Crosswordtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputVasya trains to compose crossword puzzles. He can only compose crosswords of a very simplе type so far. All of them consist of exactly six words; the words can be read only from top to bottom vertically and...
InputNODBAAYARDAIRWAYNEWTONBURN
OutputBAA...U.I...R.R...NEWTON..A..O..YARD
2 seconds
256 megabytes
['implementation', '*2000']
B. Coinstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputOne day Vasya came across three Berland coins. They didn't have any numbers that's why Vasya didn't understand how their denominations differ. He supposed that if one coin is heavier than the other one, then it...
InputA>BC<BA>C
OutputCBA
2 seconds
256 megabytes
['implementation', '*1200']
A. Triangular numberstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputA triangular number is the number of dots in an equilateral triangle uniformly filled with dots. For example, three dots can be arranged in a triangle; thus three is a triangular number. The n-th t...
Input1
OutputYES
2 seconds
256 megabytes
['brute force', 'math', '*800']
G. Emperor's Problemtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputIt happened at the times of the Great Berland Empire. Once the Emperor dreamt that the Messenger from the gods ordered to build a temple whose base would be a convex polygon with n angles. Next morn...
Input3
OutputYES0 01 00 2
2 seconds
256 megabytes
['geometry', '*2500']
F. Hercule Poirot Problemtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputToday you are to solve the problem even the famous Hercule Poirot can't cope with! That's why this crime has not yet been solved and this story was never included in Agatha Christie's detective...
Input2 1 21 2Dmitry 1 1 1Natalia 2 0Natalia 1 1 1Dmitry 2 0
OutputYES
2 seconds
256 megabytes
['dsu', 'graphs', '*2300']
E. Combtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputHaving endured all the hardships, Lara Croft finally found herself in a room with treasures. To her surprise she didn't find golden mountains there. Lara looked around and noticed on the floor a painted table n ×...
Input2 2-1 21 3
Output2
1 second
256 megabytes
['data structures', 'dp', '*1900']
D. Parking Lottime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputNowadays it is becoming increasingly difficult to park a car in cities successfully. Let's imagine a segment of a street as long as L meters along which a parking lot is located. Drivers should park their...
Input30 1 261 51 41 52 21 51 4
Output06111723
2 seconds
256 megabytes
['data structures', 'implementation', '*1800']