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
D. Polycarp's phone booktime limit per test4 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere are n phone numbers in Polycarp's contacts on his phone. Each number is a 9-digit integer, starting with a digit different from 0. All the numbers are distinct.There is the latest version ...
Input3123456789100000000100123456
Output900001
4 seconds
256 megabytes
['data structures', 'implementation', 'sortings', '*1600']
C. Did you mean...time limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputBeroffice text editor has a wide range of features that help working with text. One of the features is an automatic search for typos and suggestions of how to fix them.Beroffice works only with small E...
Inputhellno
Outputhell no
1 second
256 megabytes
['dp', 'greedy', 'implementation', '*1500']
B. Which floor?time limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputIn a building where Polycarp lives there are equal number of flats on each floor. Unfortunately, Polycarp don't remember how many flats are on each floor, but he remembers that the flats are numbered from...
Input10 36 22 17 3
Output4
1 second
256 megabytes
['brute force', 'implementation', '*1500']
A. k-roundingtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputFor a given positive integer n denote its k-rounding as the minimum positive integer x, such that x ends with k or more zeros in base 10 and is divisible by n.For example, 4-rounding of 375 is 375·80 = 3000...
Input375 4
Output30000
1 second
256 megabytes
['brute force', 'math', 'number theory', '*1100']
F. To Play or not to Playtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputVasya and Petya are playing an online game. As most online games, it has hero progress system that allows players to gain experience that make their heroes stronger. Of course, Vasya would like...
Input2 1 51 710 2010 20
Output25
2 seconds
256 megabytes
['greedy', '*3000']
E. Satellitestime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputReal Cosmic Communications is the largest telecommunication company on a far far away planet, located at the very edge of the universe. RCC launches communication satellites.The planet is at the very edge ...
Input5 81 -5 81 -4 81 -3 81 2 73 1 32 23 1 33 3 4
OutputNOYESYES
2 seconds
256 megabytes
['*3100']
D. Masha and Cactustime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputMasha is fond of cacti. When she was a little girl, she decided to plant a tree. Now Masha wants to make a nice cactus out of her tree.Recall that tree is a connected undirected graph that has no cyc...
Input7 31 1 2 2 3 34 5 16 7 12 3 1
Output2
2 seconds
256 megabytes
['dp', 'trees', '*2400']
C. Eleventh Birthdaytime limit per test2 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputIt is Borya's eleventh birthday, and he has got a great present: n cards with numbers. The i-th card has the number ai written on it. Borya wants to put his cards in a row to get one greater number....
Input421 131 31 12312345 67 8491 2 3 4 5 6 7 8 9
Output22231680
2 seconds
512 megabytes
['combinatorics', 'dp', 'math', '*2400']
B. Similar Wordstime limit per test2 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputLet us call a non-empty sequence of lowercase English letters a word. Prefix of a word x is a word y that can be obtained from x by removing zero or more last letters of x.Let us call two words similar,...
Input23abababaaaab2aaa
Output61
2 seconds
512 megabytes
['dp', 'hashing', 'strings', 'trees', '*2300']
A. Set Theorytime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputMasha and Grisha like studying sets of positive integers.One day Grisha has written a set A containing n different integers ai on a blackboard. Now he asks Masha to create a set B containing n different int...
Input331 10 1001122 4
OutputYES1 2 3 YES1 YES1 2
1 second
256 megabytes
['brute force', 'constructive algorithms', '*1600']
G. Harry Vs Voldemorttime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputAfter destroying all of Voldemort's Horcruxes, Harry and Voldemort are up for the final battle. They each cast spells from their wands and the spells collide.The battle scene is Hogwarts, which can...
Input31 22 312 3
Output24
2 seconds
256 megabytes
['dfs and similar', 'dp', 'graphs', 'trees', '*3300']
F. Naginitime limit per test4 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputNagini, being a horcrux You-know-who created with the murder of Bertha Jorkins, has accumulated its army of snakes and is launching an attack on Hogwarts school. Hogwarts' entrance can be imagined as a straigh...
Input31 1 10 101 2 4 -72 1 10
Output34
4 seconds
256 megabytes
['binary search', 'data structures', '*3100']
E. Salazar Slytherin's Lockettime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputHarry came to know from Dumbledore that Salazar Slytherin's locket is a horcrux. This locket was present earlier at 12 Grimmauld Place, the home of Sirius Black's mother. It was stolen from...
Input22 4 93 1 10
Output12
2 seconds
256 megabytes
['bitmasks', 'dp', '*2200']
D. Rowena Ravenclaw's Diademtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputHarry, upon inquiring Helena Ravenclaw's ghost, came to know that she told Tom Riddle or You-know-who about Rowena Ravenclaw's diadem and that he stole it from her. Harry thought that Riddle...
Input3-1 -11 02 021 1 32 1 3
OutputYESNO
2 seconds
256 megabytes
['trees', '*2500']
C. Helga Hufflepuff's Cuptime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputHarry, Ron and Hermione have figured out that Helga Hufflepuff's cup is a horcrux. Through her encounter with Bellatrix Lestrange, Hermione came to know that the cup is present in Bellatrix's f...
Input4 21 22 31 41 2
Output1
2 seconds
256 megabytes
['dp', 'trees', '*2000']
B. Marvolo Gaunt's Ringtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputProfessor Dumbledore is helping Harry destroy the Horcruxes. He went to Gaunt Shack as he suspected a Horcrux to be present there. He saw Marvolo Gaunt's Ring and identified it as a Horcrux. Alth...
Input5 1 2 31 2 3 4 5
Output30
2 seconds
256 megabytes
['brute force', 'data structures', 'dp', '*1500']
A. Tom Riddle's Diarytime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputHarry Potter is on a mission to destroy You-Know-Who's Horcruxes. The first Horcrux that he encountered in the Chamber of Secrets is Tom Riddle's diary. The diary was with Ginny and it forced her t...
Input6tomluciusginnyharryginnyharry
OutputNONONONOYESYES
2 seconds
256 megabytes
['brute force', 'implementation', 'strings', '*800']
B. Maxim Buys an Apartmenttime limit per test1 secondmemory limit per test512 megabytesinputstandard inputoutputstandard outputMaxim wants to buy an apartment in a new house at Line Avenue of Metropolis. The house has n apartments that are numbered from 1 to n and are arranged in a row. Two apartments are adjacent if t...
Input6 3
Output1 3
1 second
512 megabytes
['constructive algorithms', 'math', '*1200']
A. Fractiontime limit per test1 secondmemory limit per test512 megabytesinputstandard inputoutputstandard outputPetya is a big fan of mathematics, especially its part related to fractions. Recently he learned that a fraction is called proper iff its numerator is smaller than its denominator (a < b) and that the fracti...
Input3
Output1 2
1 second
512 megabytes
['brute force', 'constructive algorithms', 'math', '*800']
E. Lada Malinatime limit per test5 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputAfter long-term research and lots of experiments leading Megapolian automobile manufacturer «AutoVoz» released a brand new car model named «Lada Malina». One of the most impressive features of «Lada Malin...
Input2 4 11 1-1 12 3 12 -2 1-2 1 1-2 -2 10 0 2
Output3
5 seconds
256 megabytes
['data structures', 'geometry', '*3400']
D. Michael and Charging Stationstime limit per test2 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputMichael has just bought a new electric car for moving across city. Michael does not like to overwork, so each day he drives to only one of two his jobs.Michael's day starts from charging...
Input31000 2000 1000
Output3700
2 seconds
512 megabytes
['binary search', 'dp', 'greedy', '*2400']
C. Boredomtime limit per test2 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputIlya is sitting in a waiting area of Metropolis airport and is bored of looking at time table that shows again and again that his plane is delayed. So he took out a sheet of paper and decided to solve some pr...
Input2 31 21 1 1 11 1 1 21 1 2 2
Output111
2 seconds
512 megabytes
['data structures', '*2100']
B. Jury Meetingtime limit per test1 secondmemory limit per test512 megabytesinputstandard inputoutputstandard outputCountry of Metropolia is holding Olympiad of Metrpolises soon. It mean that all jury members of the olympiad should meet together in Metropolis (the capital of the country) for the problem preparation pro...
Input2 6 51 1 0 50003 2 0 55002 2 0 600015 0 2 90009 0 1 70008 0 2 6500
Output24500
1 second
512 megabytes
['greedy', 'sortings', 'two pointers', '*1800']
A. Planningtime limit per test1 secondmemory limit per test512 megabytesinputstandard inputoutputstandard outputHelen works in Metropolis airport. She is responsible for creating a departure schedule. There are n flights that must depart today, the i-th of them is planned to depart at the i-th minute of the day.Metropo...
Input5 24 2 1 10 2
Output203 6 7 4 5
1 second
512 megabytes
['greedy', '*1500']
I. Datingtime limit per test2 secondsmemory limit per test64 megabytesinputstandard inputoutputstandard outputThis story is happening in a town named BubbleLand. There are n houses in BubbleLand. In each of these n houses lives a boy or a girl. People there really love numbers and everyone has their favorite number f. ...
Input71 0 0 1 0 1 09 2 9 2 2 9 92 61 24 26 53 67 421 37 5
Output23
2 seconds
64 megabytes
['brute force', 'dfs and similar', 'graphs', 'trees', '*2300']
H. Bob and stagestime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe citizens of BubbleLand are celebrating their 10th anniversary so they decided to organize a big music festival. Bob got a task to invite N famous singers who would sing on the fest. He was too busy...
Input5 40 03 02 14 41 5
Output10.00
2 seconds
256 megabytes
['dp', 'geometry', '*3000']
G. Bathroom terminaltime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputSmith wakes up at the side of a dirty, disused bathroom, his ankle chained to pipes. Next to him is tape-player with a hand-written message "Play Me". He finds a tape in his own back pocket. After p...
Input3 1abcaecaca?c
Output3
2 seconds
256 megabytes
['implementation', '*1700']
F. Product transformationtime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputConsider an array A with N elements, all being the same integer a.Define the product transformation as a simultaneous update Ai = Ai·Ai + 1, that is multiplying each element to the element righ...
Input2 2 2 7
Output1 2
3 seconds
256 megabytes
['combinatorics', 'math', 'number theory', '*2200']
E. Casinos and traveltime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputJohn has just bought a new car and is planning a journey around the country. Country has N cities, some of which are connected by bidirectional roads. There are N - 1 roads and every city is reachab...
Input21 2
Output4
1 second
256 megabytes
['dp', '*2100']
D. Exploration plantime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe competitors of Bubble Cup X gathered after the competition and discussed what is the best way to get to know the host country and its cities.After exploring the map of Serbia for a while, the com...
Input6 7 5 45 5 2 2 51 3 31 5 21 6 52 5 42 6 73 4 113 5 3
Output3
2 seconds
256 megabytes
['binary search', 'flows', 'graph matchings', 'shortest paths', '*2100']
C. Propertytime limit per test0.5 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputBill is a famous mathematician in BubbleLand. Thanks to his revolutionary math discoveries he was able to make enough money to build a beautiful house. Unfortunately, for not paying property tax on time, c...
Input30 1 2
Output0 2 1
0.5 seconds
256 megabytes
['greedy', 'sortings', '*2100']
B. Neural Network countrytime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputDue to the recent popularity of the Deep learning new countries are starting to look like Neural Networks. That is, the countries are being built deep with many layers, each layer possibly havi...
Input2 3 134 62 13 4
Output2
2 seconds
256 megabytes
['dp', 'matrices', '*2000']
A. Digitstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputJohn gave Jack a very hard problem. He wrote a very big positive integer A0 on a piece of paper. The number is less than 10200000 . In each step, Jack is allowed to put ' + ' signs in between some of the digits...
Input11
Output111
1 second
256 megabytes
['brute force', 'implementation', 'math', '*2500']
B. Arpa and an exam about geometrytime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputArpa is taking a geometry exam. Here is the last problem of the exam.You are given three points a, b, c.Find a point and an angle such that if we rotate the page around the point by th...
Input0 1 1 1 1 0
OutputYes
2 seconds
256 megabytes
['geometry', 'math', '*1400']
A. Arpa and a research in Mexican wavetime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputArpa is researching the Mexican wave.There are n spectators in the stadium, labeled from 1 to n. They start the Mexican wave at time 0. At time 1, the first spectator stands. At ...
Input10 5 3
Output3
1 second
256 megabytes
['implementation', 'math', '*800']
F. Rainbow Ballstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou have a bag of balls of n different colors. You have ai balls of the i-th color.While there are at least two different colored balls in the bag, perform the following steps: Take out two random bal...
Input21 1
Output1
2 seconds
256 megabytes
['math', '*2800']
E. Random Electionstime limit per test2 secondsmemory limit per test1024 megabytesinputstandard inputoutputstandard outputThe presidential election is coming in Bearland next year! Everybody is so excited about this!So far, there are three candidates, Alice, Bob, and Charlie. There are n citizens in Bearland. The elect...
Input301010101
Output216
2 seconds
1024 megabytes
['bitmasks', 'brute force', 'divide and conquer', 'fft', 'math', '*2800']
D. Tournament Constructiontime limit per test2 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputIvan is reading a book about tournaments. He knows that a tournament is an oriented graph with exactly one oriented edge between each pair of vertices. The score of a vertex is the number of e...
Input21 2
Output40011100101000010
2 seconds
512 megabytes
['constructive algorithms', 'dp', 'graphs', 'greedy', 'math', '*2800']
C. Arpa and a game with Mojtabatime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputMojtaba and Arpa are playing a game. They have a list of n numbers in the game.In a player's turn, he chooses a number pk (where p is a prime number and k is a positive integer) such that ...
Input41 1 1 1
OutputArpa
1 second
256 megabytes
['bitmasks', 'dp', 'games', '*2200']
B. Arpa and a list of numberstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputArpa has found a list containing n numbers. He calls a list bad if and only if it is not empty and gcd (see notes section for more information) of numbers in the list is 1.Arpa can perform ...
Input4 23 171 17 17 16
Output40
2 seconds
256 megabytes
['implementation', 'number theory', '*2100']
A. Five Dimensional Pointstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given set of n points in 5-dimensional space. The points are labeled from 1 to n. No two points coincide.We will call point a bad if there are different points b and c, not equal to a,...
Input60 0 0 0 01 0 0 0 00 1 0 0 00 0 1 0 00 0 0 1 00 0 0 0 1
Output11
2 seconds
256 megabytes
['brute force', 'geometry', 'math', '*1700']
B. Tell Your Worldtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputConnect the countless points with lines, till we reach the faraway yonder.There are n points on a coordinate plane, the i-th of which being (i, yi).Determine whether it's possible to draw two parallel ...
Input57 5 8 6 9
OutputYes
1 second
256 megabytes
['brute force', 'geometry', '*1600']
A. Odds and Endstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputWhere do odds begin, and where do they end? Where does hope emerge, and will they ever break?Given an integer sequence a1, a2, ..., an of length n. Decide whether it is possible to divide it into an odd ...
Input31 3 5
OutputYes
1 second
256 megabytes
['implementation', '*1000']
E. Days of Floral Colourstime limit per test7 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe Floral Clock has been standing by the side of Mirror Lake for years. Though unable to keep time, it reminds people of the passage of time and the good old days.On the rim of the Floral Cloc...
Input3
Output24
7 seconds
256 megabytes
['combinatorics', 'divide and conquer', 'dp', 'fft', 'math', '*3400']
D. Shake It!time limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputA never-ending, fast-changing and dream-like world unfolds, as the secret door opens.A world is an unordered graph G, in whose vertex set V(G) there are two special vertices s(G) and t(G). An initial world ...
Input3 2
Output6
2 seconds
256 megabytes
['combinatorics', 'dp', 'flows', 'graphs', '*2900']
C. Goodbye Souvenirtime limit per test6 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputI won't feel lonely, nor will I be sorrowful... not before everything is buried.A string of n beads is left as the message of leaving. The beads are numbered from 1 to n from left to right, each havi...
Input7 61 2 3 1 3 2 12 3 72 1 31 7 21 3 22 1 62 5 7
Output5071
6 seconds
256 megabytes
['data structures', 'divide and conquer', '*2600']
B. Rooter's Songtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputWherever the destination is, whoever we meet, let's render this song together.On a Cartesian coordinate plane lies a rectangular stage of size w × h, represented by a rectangle with corners (0, 0), (w, ...
Input8 10 81 1 101 4 131 7 11 8 22 2 02 5 142 6 02 6 1
Output4 810 58 810 610 21 87 810 6
2 seconds
256 megabytes
['constructive algorithms', 'data structures', 'geometry', 'implementation', 'sortings', 'two pointers', '*1900']
A. From Y to Ytime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputFrom beginning till end, this message has been waiting to be conveyed.For a given unordered multiset of n lowercase English letters ("multi" means that a letter may appear more than once), we treat all let...
Input12
Outputabababab
1 second
256 megabytes
['constructive algorithms', '*1600']
M. Weather Tomorrowtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputVasya came up with his own weather forecasting method. He knows the information about the average air temperature for each of the last n days. Assume that the average air temperature for each day is i...
Input510 5 0 -5 -10
Output-15
1 second
256 megabytes
['implementation', 'math', '*1000']
L. Berland SU Computer Networktime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputIn the computer network of the Berland State University there are n routers numbered from 1 to n. Some pairs of routers are connected by patch cords. Information can be transmitted over pa...
Input32:3,21:1-1:32:1,2
Output22 12 3
2 seconds
256 megabytes
['constructive algorithms', 'dfs and similar', 'graphs', 'hashing', 'trees', '*2400']
K. Travel Cardstime limit per test4 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputIn the evening Polycarp decided to analyze his today's travel expenses on public transport.The bus system in the capital of Berland is arranged in such a way that each bus runs along the route between tw...
Input3 5 3 1 8BerBank UniversityUniversity BerMallUniversity BerBank
Output11
4 seconds
256 megabytes
['greedy', 'implementation', 'sortings', '*1800']
J. Students Initiationtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputSoon the first year students will be initiated into students at the University of Berland. The organizers of the initiation come up with a program for this holiday. In their opinion, it would be g...
Input5 42 11 32 32 5
Output11 22 33 15 2
2 seconds
256 megabytes
['binary search', 'flows', 'graphs', '*2400']
I. Noise Leveltime limit per test5 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe Berland's capital has the form of a rectangle with sizes n × m quarters. All quarters are divided into three types: regular (labeled with the character '.') — such quarters do not produce the noise b...
Input3 3 100 140...A*..B.
Output3
5 seconds
256 megabytes
['dfs and similar', 'implementation', 'math', '*1900']
H. Load Testingtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputPolycarp plans to conduct a load testing of its new project Fakebook. He already agreed with his friends that at certain points in time they will send requests to Fakebook. The load testing will last n mi...
Input51 4 3 2 5
Output6
1 second
256 megabytes
['greedy', '*1600']
G. University Classestime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere are n student groups at the university. During the study day, each group can take no more than 7 classes. Seven time slots numbered from 1 to 7 are allocated for the classes.The schedule on Mo...
Input201010101010101
Output1
1 second
256 megabytes
['implementation', '*900']
F. Berland Electionstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe elections to Berland parliament are happening today. Voting is in full swing!Totally there are n candidates, they are numbered from 1 to n. Based on election results k (1 ≤ k ≤ n) top candidates ...
Input3 1 5 41 2 1 3
Output1 3 3
1 second
256 megabytes
['greedy', 'sortings', '*2100']
E. Packmentime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputA game field is a strip of 1 × n square cells. In some cells there are Packmen, in some cells — asterisks, other cells are empty.Packman can move to neighboring cell in 1 time unit. If there is an asterisk in ...
Input7*..P*P*
Output3
1 second
256 megabytes
['binary search', 'dp', '*1800']
D. Dog Showtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputA new dog show on TV is starting next week. On the show dogs are required to demonstrate bottomless stomach, strategic thinking and self-preservation instinct. You and your dog are invited to compete with ot...
Input3 51 5 3
Output2
2 seconds
256 megabytes
['constructive algorithms', 'data structures', 'greedy', '*2200']
C. Sum of Nestingstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputRecall that the bracket sequence is considered regular if it is possible to insert symbols '+' and '1' into it so that the result is a correct arithmetic expression. For example, a sequence "(()())" i...
Input3 1
Output()(())
2 seconds
256 megabytes
['constructive algorithms', '*1800']
B. Preparing for Merge Sorttime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputIvan has an array consisting of n different integers. He decided to reorder all elements in increasing order. Ivan loves merge sort so he decided to represent his array with one or several in...
Input51 3 2 5 4
Output1 3 5 2 4
2 seconds
256 megabytes
['binary search', 'data structures', '*1600']
A. Union of Doubly Linked Liststime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputDoubly linked list is one of the fundamental data structures. A doubly linked list is a sequence of elements, each containing information about the previous and the next elements of the l...
Input74 75 00 06 10 20 41 0
Output4 75 60 56 13 22 41 0
2 seconds
256 megabytes
['implementation', '*1500']
F. Random Querytime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given an array a consisting of n positive integers. You pick two integer numbers l and r from 1 to n, inclusive (numbers are picked randomly, equiprobably and independently). If l > r, then you s...
Input21 2
Output1.500000
2 seconds
256 megabytes
['data structures', 'math', 'probabilities', 'two pointers', '*1800']
E. Chemistry in Berlandtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputIgor is a post-graduate student of chemistry faculty in Berland State University (BerSU). He needs to conduct a complicated experiment to write his thesis, but laboratory of BerSU doesn't contain...
Input31 2 33 2 11 11 1
OutputYES
2 seconds
256 megabytes
['dfs and similar', 'greedy', 'trees', '*2300']
D. Monitortime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputRecently Luba bought a monitor. Monitor is a rectangular matrix of size n × m. But then she started to notice that some pixels cease to work properly. Luba thinks that the monitor will become broken the first...
Input2 3 2 52 1 82 2 81 2 11 3 42 3 2
Output8
2 seconds
256 megabytes
['binary search', 'data structures', '*1900']
C. Four Segmentstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given an array of n integer numbers. Let sum(l, r) be the sum of all numbers on positions from l to r non-inclusive (l-th element is counted, r-th element is not counted). For indices l and r hol...
Input3-1 2 3
Output0 1 3
1 second
256 megabytes
['brute force', 'data structures', 'dp', '*1800']
B. Math Showtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputPolycarp takes part in a math show. He is given n tasks, each consists of k subtasks, numbered 1 through k. It takes him tj minutes to solve the j-th subtask of any task. Thus, time required to solve a subta...
Input3 4 111 2 3 4
Output6
1 second
256 megabytes
['brute force', 'greedy', '*1800']
A. Curriculum Vitaetime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputHideo Kojima has just quit his job at Konami. Now he is going to find a new place to work. Despite being such a well-known person, he still needs a CV to apply for a job.During all his career Hideo ha...
Input41 1 0 1
Output3
1 second
256 megabytes
['brute force', 'implementation', '*1500']
G. Shortest Path Problem?time limit per test3 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputYou are given an undirected graph with weighted edges. The length of some path between two vertices is the bitwise xor of weights of all edges belonging to this path (if some edge is traversed ...
Input3 31 2 31 3 23 2 0
Output2
3 seconds
512 megabytes
['dfs and similar', 'graphs', 'math', '*2300']
F. Guards In The Storehousetime limit per test1.5 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputPolycarp owns a shop in the capital of Berland. Recently the criminal activity in the capital increased, so Polycarp is thinking about establishing some better security in the storehouse of...
Input1 3.x.
Output3
1.5 seconds
512 megabytes
['bitmasks', 'dp', '*2500']
E. Fire in the Citytime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe capital of Berland looks like a rectangle of size n × m of the square blocks of same size.Fire!It is known that k + 1 blocks got caught on fire (k + 1 ≤ n·m). Those blocks are centers of ignition...
Input7 7 31 22 15 5
Output3
2 seconds
256 megabytes
['binary search', 'data structures', '*2400']
D. Driving Testtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputPolycarp has just attempted to pass the driving test. He ran over the straight road with the signs of four types. speed limit: this sign comes with a positive integer number — maximal speed of the car a...
Input111 1003 70423 12053 12061 15043 300
Output2
2 seconds
256 megabytes
['data structures', 'dp', 'greedy', '*1800']
C. Two TVstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputPolycarp is a great fan of television.He wrote down all the TV programs he is interested in for today. His list contains n shows, i-th of them starts at moment li and ends at moment ri.Polycarp owns two TVs. ...
Input31 22 34 5
OutputYES
2 seconds
256 megabytes
['data structures', 'greedy', 'sortings', '*1500']
B. Luba And The Tickettime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputLuba has a ticket consisting of 6 digits. In one move she can choose digit in any position and replace it with arbitrary digit. She wants to know the minimum number of digits she needs to replace ...
Input000000
Output0
2 seconds
256 megabytes
['brute force', 'greedy', 'implementation', '*1600']
A. Chess Tourneytime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputBerland annual chess tournament is coming!Organizers have gathered 2·n chess players who should be divided into two teams with n people each. The first team is sponsored by BerOil and the second team is ...
Input21 3 2 4
OutputYES
1 second
256 megabytes
['implementation', 'sortings', '*1100']
B. Rectanglestime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given n × m table. Each cell of the table is colored white or black. Find the number of non-empty sets of cells such that: All cells in a set have the same color. Every two cells in a set share ro...
Input1 10
Output1
1 second
256 megabytes
['combinatorics', 'math', '*1300']
A. Diversitytime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputCalculate the minimum number of characters you need to change in the string s, so that it contains at least k different letters, or print that it is impossible.String s consists only of lowercase Latin lette...
Inputyandex6
Output0
1 second
256 megabytes
['greedy', 'implementation', 'strings', '*1000']
E. Maximum Flowtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a directed graph, consisting of n vertices and m edges. The vertices s and t are marked as source and sink correspondingly. Additionally, there are no edges ending at s and there are no edge...
Input5 6 1 51 2 12 3 13 5 11 4 14 3 04 5 1
Output23 33 83 44 40 54 9
1 second
256 megabytes
['flows', 'graphs', '*3000']
D. Dynamic Shortest Pathtime limit per test10 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputYou are given a weighted directed graph, consisting of n vertices and m edges. You should answer q queries of two types: 1 v — find the length of shortest path from vertex 1 to vertex v. 2 c ...
Input3 2 91 2 02 3 02 1 21 31 22 1 11 31 22 2 1 21 31 2
Output102142
10 seconds
512 megabytes
['graphs', 'shortest paths', '*3400']
C. Upgrading Treetime limit per test4 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputYou are given a tree with n vertices and you are allowed to perform no more than 2n transformations on it. Transformation is defined by three vertices x, y, y' and consists of deleting edge (x, y) and ...
Input33 21 3
Output0
4 seconds
512 megabytes
['constructive algorithms', 'dfs and similar', 'graphs', 'math', 'trees', '*2600']
B. Interactive LowerBoundtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputThis is an interactive problem.You are given a sorted in increasing order singly linked list. You should find the minimum integer in the list which is greater than or equal to x.More formally, t...
Input5 3 8097 -158 516 281 179 4
Output? 1? 2? 3? 4? 5! 81
1 second
256 megabytes
['brute force', 'interactive', 'probabilities', '*2000']
A. Sorting by Subsequencestime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a sequence a1, a2, ..., an consisting of different integers. It is required to split this sequence into the maximum number of subsequences such that after sorting integers in each...
Input63 2 1 6 5 4
Output42 1 31 22 4 61 5
1 second
256 megabytes
['dfs and similar', 'dsu', 'implementation', 'math', 'sortings', '*1400']
E. Nikita and gametime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputNikita plays a new computer game. There are m levels in this game. In the beginning of each level a new class appears in the game; this class is a child-class of the class yi (and yi is called parent-...
Input41121
Output2223
2 seconds
256 megabytes
['binary search', 'dfs and similar', 'divide and conquer', 'graphs', 'trees', '*2800']
D. Vitya and Strange Lessontime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputToday at the lesson Vitya learned a very interesting function — mex. Mex of a sequence of numbers is the minimum non-negative number that is not present in the sequence as element. For exampl...
Input2 21 313
Output10
2 seconds
256 megabytes
['binary search', 'data structures', '*2000']
C. Ilya And The Treetime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputIlya is very fond of graphs, especially trees. During his last trip to the forest Ilya found a very interesting tree rooted at vertex 1. There is an integer number written on each vertex of the tree...
Input26 21 2
Output6 6
2 seconds
256 megabytes
['dfs and similar', 'graphs', 'math', 'number theory', 'trees', '*2000']
B. Gleb And Pizzatime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputGleb ordered pizza home. When the courier delivered the pizza, he was very upset, because several pieces of sausage lay on the crust, and he does not really like the crust.The pizza is a circle of radi...
Input8 477 8 1-7 3 20 2 10 -2 2-3 -3 10 6 25 3 1
Output2
2 seconds
256 megabytes
['geometry', '*1100']
A. Kirill And The Gametime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputKirill plays a new computer game. He came to the potion store where he can buy any potion. Each potion is characterized by two integers — amount of experience and cost. The efficiency of a potion ...
Input1 10 1 10 1
OutputYES
2 seconds
256 megabytes
['brute force', 'two pointers', '*1200']
B. Godsendtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputLeha somehow found an array consisting of n integers. Looking at it, he came up with a task. Two players play the game on the array. Players move one by one. The first player can choose for his move a subsegm...
Input41 3 2 3
OutputFirst
2 seconds
256 megabytes
['games', 'math', '*1100']
A. Generous Kefatime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputOne day Kefa found n baloons. For convenience, we denote color of i-th baloon as si — lowercase letter of the Latin alphabet. Also Kefa has k friends. Friend will be upset, If he get two baloons of the ...
Input4 2aabb
OutputYES
2 seconds
256 megabytes
['brute force', 'implementation', '*900']
E. In a Traptime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputLech got into a tree consisting of n vertices with a root in vertex number 1. At each vertex i written integer ai. He will not get out until he answers q queries of the form u v. Answer for the query is max...
Input5 30 3 2 1 41 22 33 43 51 41 52 4
Output343
3 seconds
256 megabytes
['trees', '*3200']
D. Destinytime limit per test2.5 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputOnce, Leha found in the left pocket an array consisting of n integers, and in the right pocket q queries of the form l r k. If there are queries, then they must be answered. Answer for the query is minimal ...
Input4 21 1 2 21 3 21 4 2
Output1-1
2.5 seconds
512 megabytes
['data structures', 'probabilities', '*2500']
C. On the Benchtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputA year ago on the bench in public park Leha found an array of n numbers. Leha believes that permutation p is right if for all 1 ≤ i < n condition, that api·api + 1 is not perfect square, holds. Leha want...
Input31 2 4
Output2
2 seconds
256 megabytes
['combinatorics', 'dp', '*2500']
B. Leha and another game about graphtime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputLeha plays a computer game, where is on each level is given a connected graph with n vertices and m edges. Graph can contain multiple edges, but can not contain self loops. Each vert...
Input1 01
Output-1
3 seconds
256 megabytes
['constructive algorithms', 'data structures', 'dfs and similar', 'dp', 'graphs', '*2100']
A. Leha and Functiontime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputLeha like all kinds of strange things. Recently he liked the function F(n, k). Consider all possible k-element subsets of the set [1, 2, ..., n]. For subset find minimal element in it. F(n, k) — mat...
Input57 3 5 3 42 1 3 2 3
Output4 7 3 5 3
2 seconds
256 megabytes
['combinatorics', 'greedy', 'math', 'number theory', 'sortings', '*1300']
E. Mother of Dragonstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere are n castles in the Lannister's Kingdom and some walls connect two castles, no two castles are connected by more than one wall, no wall connects a castle to itself. Sir Jaime Lannister has di...
Input3 10 1 01 0 00 0 0
Output0.250000000000
2 seconds
256 megabytes
['brute force', 'graphs', 'math', 'meet-in-the-middle', '*2700']
D. Winter is heretime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputWinter is here at the North and the White Walkers are close. John Snow has an army consisting of n soldiers. While the rest of the world is fighting for the Iron Throne, he is going to get ready for th...
Input33 3 1
Output12
3 seconds
256 megabytes
['combinatorics', 'dp', 'math', 'number theory', '*2200']
C. Journeytime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere are n cities and n - 1 roads in the Seven Kingdoms, each road connects two cities and we can reach any city from any other by the roads.Theon and Yara Greyjoy are on a horse in the first city, they are ...
Input41 21 32 4
Output1.500000000000000
2 seconds
256 megabytes
['dfs and similar', 'dp', 'graphs', 'probabilities', 'trees', '*1500']
B. Game of the Rowstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputDaenerys Targaryen has an army consisting of k groups of soldiers, the i-th group contains ai soldiers. She wants to bring her army to the other side of the sea to get the Iron Throne. She has recentl...
Input2 25 8
OutputYES
1 second
256 megabytes
['brute force', 'greedy', 'implementation', '*1900']
A. Arya and Brantime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputBran and his older sister Arya are from the same house. Bran like candies so much, so Arya is going to give him some Candies.At first, Arya and Bran have 0 Candies. There are n days, at the i-th day, Ary...
Input2 31 2
Output2
1 second
256 megabytes
['implementation', '*900']
F. Expected Earningstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are playing a game with a bag of red and black balls. Initially, you are told that the bag has n balls total. In addition, you are also told that the bag has probability pi / 106 of containing e...
Input3 200000250000 250000 250000 250000
Output0.9000000000
2 seconds
256 megabytes
['*2800']
E. Convex Countourtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given an strictly convex polygon with n vertices. It is guaranteed that no three points are collinear. You would like to take a maximum non intersecting path on the polygon vertices that visit...
Input40 00 11 11 0
Output3.4142135624
2 seconds
256 megabytes
['dp', '*2300']