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. Lucky Treetime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputPetya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17,...
Input41 2 43 1 21 4 7
Output16
2 seconds
256 megabytes
['dp', 'dsu', 'trees', '*1900']
B. Lucky Probabilitytime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputPetya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and...
Input1 10 1 10 2
Output0.320000000000
2 seconds
256 megabytes
['brute force', 'probabilities', '*1900']
A. Lucky Sum of Digitstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputPetya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky a...
Input11
Output47
2 seconds
256 megabytes
['brute force', 'implementation', '*1000']
B. Datatypestime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputTattah's youngest brother, Tuftuf, is new to programming.Since his older brother is such a good programmer, his biggest dream is to outshine him. Tuftuf is a student at the German University in Cairo (GUC) ...
Input364 16 32
OutputNO
2 seconds
256 megabytes
['math', 'sortings', '*1400']
A. Palindromic Timestime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputTattah is asleep if and only if Tattah is attending a lecture. This is a well-known formula among Tattah's colleagues.On a Wednesday afternoon, Tattah was attending Professor HH's lecture. At 12:21,...
Input12:21
Output13:31
2 seconds
256 megabytes
['implementation', 'strings', '*1000']
E. Dartstime limit per test5 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe night after the graduation ceremony graduate students of German University in Cairo (GUC) are playing darts. As there's no real dart board available, the photographs of members of the GUC upper management a...
Input10 0 0 2 2 2 2 0
Output1.0000000000
5 seconds
256 megabytes
['geometry', 'probabilities', '*2700']
D. Crime Managementtime limit per test5 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputZeyad wants to commit n crimes in Egypt and not be punished at the end. There are several types of crimes. For example, bribery is a crime but is not considered such when repeated twice. Therefore, b...
Input5 2A 1B 2
Output16
5 seconds
256 megabytes
['dp', 'graphs', 'matrices', '*2400']
C. Arrangementtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputIn the year 2500 the annual graduation ceremony in the German University in Cairo (GUC) has run smoothly for almost 500 years so far.The most important part of the ceremony is related to the arrangement o...
Input3 2001 21 22 3
Output1 2 3
2 seconds
256 megabytes
['bitmasks', 'dp', '*2400']
B. Basketball Teamtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputAs a German University in Cairo (GUC) student and a basketball player, Herr Wafa was delighted once he heard the news. GUC is finally participating in the Annual Basketball Competition (ABC). A team is...
Input3 2 12 1
Output1
1 second
256 megabytes
['combinatorics', 'dp', 'math', 'probabilities', '*1600']
A. Dorm Water Supplytime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe German University in Cairo (GUC) dorm houses are numbered from 1 to n. Underground water pipes connect these houses together. Each pipe has certain direction (water can flow only in this directio...
Input3 21 2 102 3 20
Output11 3 10
1 second
256 megabytes
['dfs and similar', 'graphs', '*1400']
E. Space Rescuerstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe Galaxy contains n planets, there are many different living creatures inhabiting each planet. And each creature can get into troubles! Space rescuers know it perfectly well and they are always ready...
Input55 0 0-5 0 00 3 44 -3 02 2 -2
Output0.000 0.000 0.000
2 seconds
256 megabytes
['geometry', 'ternary search', '*2100']
D. Treasure Islandtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputOur brave travelers reached an island where pirates had buried treasure. However as the ship was about to moor, the captain found out that some rat ate a piece of the treasure map.The treasure map can...
Input6 10###########K#..######.#..##.###..L.#...####D###A.###########4N 2S 1E 1W 2
OutputAD
2 seconds
256 megabytes
['brute force', 'implementation', '*1700']
C. Bunstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputLavrenty, a baker, is going to make several buns with stuffings and sell them.Lavrenty has n grams of dough as well as m different stuffing types. The stuffing types are numerated from 1 to m. Lavrenty knows tha...
Input10 2 2 17 3 2 10012 3 1 10
Output241
2 seconds
256 megabytes
['dp', '*1700']
B. Choosing Laptoptime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputVasya is choosing a laptop. The shop has n laptops to all tastes.Vasya is interested in the following properties: processor speed, ram and hdd. Vasya is a programmer and not a gamer which is why he is...
Input52100 512 150 2002000 2048 240 3502300 1024 200 3202500 2048 80 3002000 512 180 150
Output4
2 seconds
256 megabytes
['brute force', 'implementation', '*1000']
A. Card Gametime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere is a card game called "Durak", which means "Fool" in Russian. The game is quite popular in the countries that used to form USSR. The problem does not state all the game's rules explicitly β€” you can fi...
InputHQH 9S
OutputYES
2 seconds
256 megabytes
['implementation', '*1000']
E. Lift and Throwtime limit per test1.5 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a straight half-line divided into segments of unit length, which we will call positions. The positions are numbered by positive integers that start with 1 from the end of half-line, i. ...
Input9 3 34 3 12 3 3
Output15
1.5 seconds
256 megabytes
['brute force', '*2500']
D. Entertaining Geodeticstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe maps in the game are divided into square cells called Geo Panels. Some of these panels are painted. We shall assume that the Geo Panels without color are painted the transparent color. Besid...
Input5 59 0 1 1 00 0 3 2 01 1 1 3 01 1 1 3 00 1 2 0 3-1 1 -1 3 -1-1 -1 -1 0 -1-1 -1 -1 -1 -1-1 2 3 -1 -1-1 -1 -1 -1 24 2
Output35
1 second
256 megabytes
['brute force', 'dsu', 'implementation', '*2700']
C. Item Worldtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputEach item in the game has a level. The higher the level is, the higher basic parameters the item has. We shall consider only the following basic parameters: attack (atk), defense (def) and resistance to di...
Input4sword weapon 10 2 3 2pagstarmor armor 0 15 3 1iceorb orb 3 2 13 2longbow weapon 9 1 2 15mike gladiator 5 longbowbobby sentry 6 pagstarmorpetr gladiator 7 iceorbteddy physician 6 swordblackjack sentry 8 sword
Outputsword 2 petr mike pagstarmor 1 blackjack iceorb 2 teddy bobby
2 seconds
256 megabytes
['brute force', 'implementation', 'sortings', '*2200']
B. Dark Assemblytime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputDark Assembly is a governing body in the Netherworld. Here sit the senators who take the most important decisions for the player. For example, to expand the range of the shop or to improve certain chara...
Input5 6 10011 8014 9023 7080 30153 70
Output1.0000000000
2 seconds
256 megabytes
['brute force', 'probabilities', '*1800']
A. Transmigrationtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputIn Disgaea as in most role-playing games, characters have skills that determine the character's ability to use certain weapons or spells. If the character does not have the necessary skill, he cannot u...
Input5 4 0.75axe 350impaler 300ionize 80megafire 120magicboost 220healmegafireshieldmagicboost
Output6axe 262heal 0impaler 225magicboost 165megafire 0shield 0
2 seconds
256 megabytes
['implementation', '*1700']
A. Blackjacktime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputOne rainy gloomy evening when all modules hid in the nearby cafes to drink hot energetic cocktails, the Hexadecimal virus decided to fly over the Mainframe to look for a Great Idea. And she has found one!Wh...
Input12
Output4
2 seconds
256 megabytes
['implementation', '*800']
E. Buying Setstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe Hexadecimal virus loves playing with number sets β€” intersecting them, uniting them. One beautiful day she was surprised to find out that Scuzzy, her spherical pet cat, united all sets in one and ate t...
Input31 12 2 31 310 20 -3
Output-3
2 seconds
256 megabytes
['flows', 'graph matchings', '*2900']
D. Time to Raid Cowavanstime limit per test4 secondsmemory limit per test70 megabytesinputstandard inputoutputstandard outputAs you know, the most intelligent beings on the Earth are, of course, cows. This conclusion was reached long ago by the Martian aliens, as well as a number of other intelligent civilizations from...
Input31 2 321 11 2
Output64
4 seconds
70 megabytes
['brute force', 'data structures', 'sortings', '*2100']
C. Russian Roulettetime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputAfter all the events in Orlando we all know, Sasha and Roma decided to find out who is still the team's biggest loser. Thankfully, Masha found somewhere a revolver with a rotating cylinder of n bulle...
Input3 1 3123
Output..X
2 seconds
256 megabytes
['constructive algorithms', 'greedy', '*1900']
B. Cthulhutime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard output...Once upon a time a man came to the sea. The sea was stormy and dark. The man started to call for the little mermaid to appear but alas, he only woke up Cthulhu...Whereas on the other end of the world Penta...
Input6 66 36 45 12 51 45 4
OutputFHTAGN!
2 seconds
256 megabytes
['dfs and similar', 'dsu', 'graphs', '*1500']
A. Testing Pants for Sadnesstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe average miner Vaganych took refresher courses. As soon as a miner completes the courses, he should take exams. The hardest one is a computer test called "Testing Pants for Sadness".The t...
Input21 1
Output2
2 seconds
256 megabytes
['greedy', 'implementation', 'math', '*1100']
B. Sum of Digitstime limit per test2 secondsmemory limit per test265 megabytesinputstandard inputoutputstandard outputHaving watched the last Harry Potter film, little Gerald also decided to practice magic. He found in his father's magical book a spell that turns any number in the sum of its digits. At the moment Geral...
Input0
Output0
2 seconds
265 megabytes
['implementation', '*1000']
A. Clothestime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputA little boy Gerald entered a clothes shop and found out something very unpleasant: not all clothes turns out to match. For example, Gerald noticed that he looks rather ridiculous in a smoking suit and a base...
Input3 31 2 31 22 33 1
Output6
2 seconds
256 megabytes
['brute force', '*1200']
E. Candies and Stonestime limit per test7.5 secondsmemory limit per test45 megabytesinputstandard inputoutputstandard outputLittle Gerald and his coach Mike play an interesting game. At the beginning of the game there is a pile consisting of n candies and a pile consisting of m stones. Gerald and Mike move in turns, Mi...
Input2 2 100 00 1
Output2SC
7.5 seconds
45 megabytes
['divide and conquer', 'dp', '*2500']
D. Castletime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputGerald is positioned in an old castle which consists of n halls connected with n - 1 corridors. It is exactly one way to go from any hall to any other one. Thus, the graph is a tree. Initially, at the moment o...
Input21 2 1
Output1.0
2 seconds
256 megabytes
['dp', 'greedy', 'probabilities', 'sortings', 'trees', '*2300']
C. Vectorstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputAt a geometry lesson Gerald was given a task: to get vector B out of vector A. Besides, the teacher permitted him to perform the following operations with vector А: Turn the vector by 90 degrees clockwise. Add...
Input0 01 10 1
OutputYES
1 second
256 megabytes
['implementation', 'math', '*2000']
B. Busestime limit per test2 secondsmemory limit per test265 megabytesinputstandard inputoutputstandard outputLittle boy Gerald studies at school which is quite far from his house. That's why he has to go there by bus every day. The way from home to school is represented by a segment of a straight line; the segment con...
Input2 20 11 2
Output1
2 seconds
265 megabytes
['binary search', 'data structures', 'dp', '*1700']
A. Homeworktime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputOnce when Gerald studied in the first year at school, his teacher gave the class the following homework. She offered the students a string consisting of n small Latin letters; the task was to learn the way t...
Inputaaaaa4
Output1aaaaa
2 seconds
256 megabytes
['greedy', '*1200']
J. Interval Coloringtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputAryo has got a lot of intervals for his 2418th birthday. He is really excited and decided to color all these intervals with some colors. He has a simple rule for himself. He calls a coloring nice if...
Input2[1,2)(3,4]
Output1
2 seconds
256 megabytes
['*special problem', 'greedy', 'math', '*2400']
I. Rotationtime limit per test2 secondsmemory limit per test64 megabytesinputstandard inputoutputstandard outputEhsan loves geometry! Especially he likes to rotate points!Given a point in the plane, Ehsan likes to rotate it by k degrees (counter-clockwise), around the origin. What is the result of this rotation?InputA ...
Input901 1
Output-1.00000000 1.00000000
2 seconds
64 megabytes
['*special problem', 'geometry', 'math', '*1500']
H. Battleshiptime limit per test2 secondsmemory limit per test64 megabytesinputstandard inputoutputstandard outputDo you know the game Battleship? If no, look into Wikipedia article http://en.wikipedia.org/wiki/Battleship_(game). You are given the positions of ships on a 10 × 10 board for playing Battleship. According ...
Input2****0000000000000000***00***00000000000000000000**000**0000000000000**000*00000000000*00*00*00000000****0000000000000000***00***00000000000000000000**000**0000000000000**0000*0000000000*00*00*00000000
OutputYESNO
2 seconds
64 megabytes
['*special problem', 'dfs and similar', 'implementation', '*2100']
G. Name the albumtime limit per test2 secondsmemory limit per test64 megabytesinputstandard inputoutputstandard outputThe famous singer, Aryo, is going to publish a new album of his great work!Unfortunately these days, there are many albums, Aryo wants to choose a new name for his album, a name that has not been used o...
Input3eyesonme 2008anewdayhascome 2002oneheart 20032oneheartbienbien
Outputbienbien
2 seconds
64 megabytes
['*special problem', 'data structures', 'implementation', '*1800']
F. Polynomtime limit per test2 secondsmemory limit per test64 megabytesinputstandard inputoutputstandard outputYou are given a polynom in form p(x) = (x + a1)Β·(x + a2)Β·... (x + an). Write Pike program to print it in a standard form p(x) = xn + b1xn - 1 + ... + bn - 1x + bn. You should write each addend in form Β«C*X^KΒ» ...
Input2-11
OutputX^2-1
2 seconds
64 megabytes
['*special problem', 'implementation', '*1800']
E. Lamps in a Linetime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere are n lamps in a line. The lamps are numbered 1 to n from left to right. There are also n keys. When key number i is pressed, all lamps number x such that i|x change their state.For two integer n...
Input2off off21 2
Outputon off
1 second
256 megabytes
['*special problem', 'math', '*1600']
D. World of Mouthtime limit per test5 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere are a lot of rumors in the media these days. One day Aida decided to find out how rumors are made.She asked n of her friends to help her. They all formed a circle and Aida told the person to her ...
Input100CodeforcesMMIODPC
OutputYes
5 seconds
256 megabytes
['*special problem', 'strings', '*1500']
C. A+Btime limit per test2 secondsmemory limit per test64 megabytesinputstandard inputoutputstandard outputBijan is new to programming. He learned recently that programmers do not code every bit of their apps from scratch.For example they never write a code to sum two integers, because their languages have the ability ...
Input23
Output5
2 seconds
64 megabytes
['*special problem', 'implementation', '*1400']
B. Friendly Numberstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputKiana thinks two integers are friends if and only if one of them divides the other one. For example, 12 and 4 are friends, also 6 and 6 are friends too, but 120 and 36 are not.A group of non-zero int...
Input41,3,6,12
OutputFRIENDS
2 seconds
256 megabytes
['*special problem', 'implementation', '*1500']
A. Carpeting the Roomtime limit per test2 secondsmemory limit per test64 megabytesinputstandard inputoutputstandard outputSoroush's room is a square with side length n. Before this contest he bought k fine Persian carpets to carpet his room for celebrating the 100th contest on his favorite site. Each Persian carpet is ...
Input10 4 6
OutputYES
2 seconds
64 megabytes
['*special problem', 'implementation', '*1100']
B. Help Chef Gerasimtime limit per test0.5 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputIn a far away kingdom young pages help to set the table for the King. As they are terribly mischievous, one needs to keep an eye on the control whether they have set everything correctly. This time...
Input5270250250230250
Output20 ml. from cup #4 to cup #1.
0.5 second
256 megabytes
['implementation', 'sortings', '*1300']
A. Help Far Away Kingdomtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputIn a far away kingdom lived the King, the Prince, the Shoemaker, the Dressmaker and many other citizens. They lived happily until great trouble came into the Kingdom. The ACMers settled there.Mo...
Input0.0
Output0
2 seconds
256 megabytes
['strings', '*800']
E. Help Shrek and Donkeytime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputShrek and the Donkey (as you can guess, they also live in the far away kingdom) decided to play a card game called YAGame. The rules are very simple: initially Shrek holds m cards and the Donkey...
Input0 3
Output0.25 0.75
2 seconds
256 megabytes
['dp', 'games', 'math', 'probabilities', '*2700']
D. Help Monkstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputIn a far away kingdom is the famous Lio Shan monastery. Gods constructed three diamond pillars on the monastery's lawn long ago. Gods also placed on one pillar n golden disks of different diameters (in the...
Input33 2 1
Output71 31 23 21 32 12 31 3
2 seconds
256 megabytes
['constructive algorithms', '*2500']
C. Help Greg the Dwarftime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputA very unusual citizen lives in a far away kingdom β€” Dwarf Gracula. However, his unusual name is not the weirdest thing (besides, everyone long ago got used to calling him simply Dwarf Greg). What...
Input2 2 1
Output1.0000000
2 seconds
256 megabytes
['geometry', 'ternary search', '*2500']
B. Help Kingtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThis is the modification of the problem used during the official round. Unfortunately, author's solution of the original problem appeared wrong, so the problem was changed specially for the archive.Once upo...
Input2
Output1/1
2 seconds
256 megabytes
['implementation', 'probabilities', 'trees', '*2200']
A. Help Victoria the Wisetime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputVasilisa the Wise from a far away kingdom got a present from her friend Helga the Wise from a farther away kingdom. The present is a surprise box, yet Vasilisa the Wise doesn't know yet what the...
InputYYYYYY
Output1
1 second
256 megabytes
['brute force', 'implementation', '*1700']
E. Leaderstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputAfter a revolution in Berland the new dictator faced an unexpected challenge: the country has to be somehow ruled. The dictator is a very efficient manager, yet he can't personally give orders to each and eve...
Input7 71 31 42 32 45 66 77 581 21 31 42 41 55 65 76 7
OutputNoYesYesYesNoYesYesYes
2 seconds
256 megabytes
['dfs and similar', 'dsu', 'graphs', 'trees', '*2200']
D. Robot in Basementtime limit per test4 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe Professor has lost his home robot yet again. After some thinking Professor understood that he had left the robot in the basement.The basement in Professor's house is represented by a rectangle n...
Input5 5 7######...##...##E..######UULLDDR
Output6
4 seconds
256 megabytes
['bitmasks', 'brute force', 'implementation', '*2700']
C. Winning Strategytime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputOne university has just found out about a sport programming contest called ACM ICPC v2.0. This contest doesn't differ much from the well-known ACM ICPC, for example, the participants are not allowed ...
Input30.115590 0.384031 0.443128 0.562356
Output0.4286122500
2 seconds
256 megabytes
['binary search', 'graphs', 'math', 'shortest paths', '*2400']
B. Supersettime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputA set of points on a plane is called good, if for any two points at least one of the three conditions is true: those two points lie on same horizontal line; those two points lie on same vertical line; the ...
Input21 12 2
Output31 12 21 2
2 seconds
256 megabytes
['constructive algorithms', 'divide and conquer', '*2300']
A. Dominotime limit per test0.5 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputLittle Gennady was presented with a set of domino for his birthday. The set consists of 28 different dominoes of size 2 × 1. Both halves of each domino contain one digit from 0 to 6. 0-0 0-1 0-2 0-3 0-4 0-5 0...
Input8 8.aabbcc..defghi.kdefghijklmnopqj.lmnopq..rstuvw.xrstuvwyxzzAABBy
Output10080.001122..001122.3344005533440055.225566..225566.6611334466113344
0.5 second
256 megabytes
['brute force', 'implementation', '*2400']
B. Lucky Numbers (easy)time limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputPetya loves lucky numbers. Everybody knows that positive integers are lucky if their decimal representation doesn't contain digits other than 4 and 7. For example, numbers 47, 744, 4 are lucky an...
Input4500
Output4747
2 seconds
256 megabytes
['binary search', 'bitmasks', 'brute force', '*1300']
A. Footballtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputPetya loves football very much. One day, as he was watching a football match, he was writing the players' current positions on a piece of paper. To simplify the situation he depicted it as a string consistin...
Input001001
OutputNO
2 seconds
256 megabytes
['implementation', 'strings', '*900']
E. Lucky Countrytime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputPetya loves lucky numbers. Everybody knows that positive integers are lucky if their decimal representation doesn't contain digits other than 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17,...
Input4 31 22 31 3
Output1
1 second
256 megabytes
['dp', 'dsu', 'graphs', '*2500']
D. Horse Racestime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputPetya likes horse racing very much. Horses numbered from l to r take part in the races. Petya wants to evaluate the probability of victory; for some reason, to do that he needs to know the amount of nearl...
Input1 21 100
Output4
2 seconds
256 megabytes
['dp', 'math', '*2500']
C. Volleyballtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputPetya loves volleyball very much. One day he was running late for a volleyball match. Petya hasn't bought his own car yet, that's why he had to take a taxi. The city has n junctions, some of which are conn...
Input4 41 31 2 31 4 12 4 12 3 52 77 21 27 7
Output9
2 seconds
256 megabytes
['shortest paths', '*1900']
B. Lucky Numberstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputPetya loves lucky numbers. Everybody knows that positive integers are lucky if their decimal representation doesn't contain digits other than 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17...
Input4500
Output4747
2 seconds
256 megabytes
['dp', 'greedy', '*1800']
A. Hockeytime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputPetya loves hockey very much. One day, as he was watching a hockey match, he fell asleep. Petya dreamt of being appointed to change a hockey team's name. Thus, Petya was given the original team name w and the ...
Input3bersuckyeluPetrLoveLuckyNumberst
OutputPetrLovtTttttNumtttt
2 seconds
256 megabytes
['implementation', 'strings', '*1600']
B. Friendstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputOne day Igor K. stopped programming and took up math. One late autumn evening he was sitting at a table reading a book and thinking about something. The following statement caught his attention: "Among any six...
Input41 32 31 45 3
OutputWIN
1 second
256 megabytes
['graphs', 'implementation', 'math', '*1300']
A. Restoring Passwordtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputIgor K. always used to trust his favorite Kashpirovsky Antivirus. That is why he didn't hesitate to download the link one of his groupmates sent him via QIP Infinium. The link was said to contain "...
Input010011001001011000000101100010010110010001011001100101101000010110101001011011000100110000010011001001011000000101100010010110010001011001100101101000010110101001011011000101101110
Output12345678
2 seconds
256 megabytes
['implementation', 'strings', '*900']
E. Lostborntime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputIgor K. very much likes a multiplayer role playing game WineAge II. Who knows, perhaps, that might be the reason for his poor performance at the university. As any person who plays the game, he is interested...
Input20 32 3 5
Output6
2 seconds
256 megabytes
['dp', 'math', 'number theory', '*2600']
D. Flagstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputWhen Igor K. was a freshman, his professor strictly urged him, as well as all other freshmen, to solve programming Olympiads. One day a problem called "Flags" from a website called Timmy's Online Judge caught h...
Input3 4
Output23
2 seconds
256 megabytes
['dp', 'math', 'matrices', '*2500']
C. Azemblertime limit per test5 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputAfter the Search Ultimate program that searched for strings in a text failed, Igor K. got to think: "Why on Earth does my program work so slowly?" As he double-checked his code, he said: "My code contains no...
Input41
Output2lea ebx, [eax + 4*eax]lea ecx, [eax + 8*ebx]
5 seconds
256 megabytes
['brute force', 'implementation', '*2500']
B. End of Examstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputStudents love to celebrate their holidays. Especially if the holiday is the day of the end of exams!Despite the fact that Igor K., unlike his groupmates, failed to pass a programming test, he decided to i...
Input2 500 3
OutputYES1 333.3333332 333.3333332 166.666667 1 166.666667
1 second
256 megabytes
['greedy', '*1900']
A. Framestime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThroughout Igor K.'s life he has had many situations worthy of attention. We remember the story with the virus, the story of his mathematical career and of course, his famous programming achievements. However,...
Input11 4 3 9
Output3
2 seconds
256 megabytes
['implementation', '*1700']
B. Binary Numbertime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputLittle walrus Fangy loves math very much. That's why when he is bored he plays with a number performing some operations.Fangy takes some positive integer x and wants to get a number one from it. While x ...
Input1
Output0
1 second
256 megabytes
['greedy', '*1300']
A. Chipstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere are n walruses sitting in a circle. All of them are numbered in the clockwise order: the walrus number 2 sits to the left of the walrus number 1, the walrus number 3 sits to the left of the walrus number ...
Input4 11
Output0
2 seconds
256 megabytes
['implementation', 'math', '*800']
E. Igloo Skyscrapertime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputToday the North Pole hosts an Olympiad in a sport called... toy igloo skyscrapers' building!There are n walruses taking part in the contest. Each walrus is given a unique number from 1 to n. After st...
Input5 44 13 56 23 56 51 5 21 3 51 1 01 5 0
Output5215
3 seconds
256 megabytes
['data structures', 'geometry', '*2500']
D. Grocer's Problemtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYesterday was a fair in a supermarket's grocery section. There were n jars with spices on the fair. Before the event the jars were numbered from 1 to n from the left to the right. After the event the...
Input63 5 6 1 2 4
Output241 3 6 4 3 6 4 1 22 5 5 2
2 seconds
256 megabytes
['constructive algorithms', 'graphs', 'greedy', '*2600']
C. Ski Basetime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputA ski base is planned to be built in Walrusland. Recently, however, the project is still in the constructing phase. A large land lot was chosen for the construction. It contains n ski junctions, numbered fro...
Input3 41 32 31 21 2
Output0013
2 seconds
256 megabytes
['combinatorics', 'dsu', 'graphs', '*2300']
B. Queuetime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere are n walruses standing in a queue in an airport. They are numbered starting from the queue's tail: the 1-st walrus stands at the end of the queue and the n-th walrus stands at the beginning of the queue....
Input610 8 5 3 50 45
Output2 1 0 -1 0 -1
2 seconds
256 megabytes
['binary search', 'data structures', '*1500']
A. Newspaper Headlinetime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputA newspaper is published in Walrusland. Its heading is s1, it consists of lowercase Latin letters. Fangy the little walrus wants to buy several such newspapers, cut out their headings, glue them on...
Inputabcxyz
Output-1
2 seconds
256 megabytes
['greedy', 'strings', '*1500']
B. African Crosswordtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputAn African crossword is a rectangular table n × m in size. Each cell of the table contains exactly one letter. This table (it is also referred to as grid) contains some encrypted word that needs to ...
Input3 3cbabcdcbc
Outputabcd
2 seconds
256 megabytes
['implementation', 'strings', '*1100']
A. Cablewaytime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputA group of university students wants to get to the top of a mountain to have a picnic there. For that they decided to use a cableway.A cableway is represented by some cablecars, hanged onto some cable statio...
Input1 3 2
Output34
2 seconds
256 megabytes
['greedy', 'math', '*1000']
E. Fire and Icetime limit per test0.5 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe Fire Lord attacked the Frost Kingdom. He has already got to the Ice Fortress, where the Snow Queen dwells. He arranged his army on a segment n in length not far from the city walls. And only the fro...
Input31 0 1
OutputARARARALLLA
0.5 second
256 megabytes
['greedy', '*2900']
D. Space minestime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputOnce upon a time in the galaxy of far, far away...Darth Wader found out the location of a rebels' base. Now he is going to destroy the base (and the whole planet that the base is located at), using the De...
Input0 0 0 1 0 0 5210 8 0 2 20 -3 02 2 020 0 0 4 32 4 0-4 3 01 -5 0
Output10.0000000000
2 seconds
256 megabytes
['geometry', '*2500']
C. Chip Playtime limit per test4 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputLet's consider the following game. We have a rectangular field n × m in size. Some squares of the field contain chips.Each chip has an arrow painted on it. Thus, each chip on the field points in one of the ...
Input4 4DRLDU.UL.UURRDDL
Output10 1
4 seconds
256 megabytes
['brute force', 'data structures', 'implementation', '*2300']
B. Widget Librarytime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputVasya writes his own library for building graphical user interface. Vasya called his creation VTK (VasyaToolKit). One of the interesting aspects of this library is that widgets are packed in each other...
Input12Widget me(50,40)VBox grandpaHBox fathergrandpa.pack(father)father.pack(me)grandpa.set_border(10)grandpa.set_spacing(20)Widget brother(30,60)father.pack(brother)Widget friend(20,60)Widget uncle(100,20)grandpa.pack(uncle)
Outputbrother 30 60father 80 60friend 20 60grandpa 120 120me 50 40uncle 100 20
2 seconds
256 megabytes
['dp', 'expression parsing', 'graphs', 'implementation', '*2300']
A. Robberytime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputIt is nighttime and Joe the Elusive got into the country's main bank's safe. The safe has n cells positioned in a row, each of them contains some amount of diamonds. Let's make the problem more comfortable to ...
Input2 3 12 3
Output0
1 second
256 megabytes
['greedy', '*1800']
B. Keyboardtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputVasya learns to type. He has an unusual keyboard at his disposal: it is rectangular and it has n rows of keys containing m keys in each row. Besides, the keys are of two types. Some of the keys have lowercase...
Input2 2 1abcd1A
Output-1
1 second
256 megabytes
['implementation', '*1500']
A. Chordtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputVasya studies music. He has learned lots of interesting stuff. For example, he knows that there are 12 notes: C, C#, D, D#, E, F, F#, G, G#, A, B, H. He also knows that the notes are repeated cyclically: after ...
InputC E G
Outputmajor
2 seconds
256 megabytes
['brute force', 'implementation', '*1200']
E. Mogohu-Rea Idoltime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputA long time ago somewhere in the depths of America existed a powerful tribe governed by the great leader Pinnie-the-Wooh. Once the tribe conquered three Maya cities. Pinnie-the-Wooh grew concerned: th...
Input30 01 01 148 85 56 48 43-1 -1-3 -1-2 -250 02 17 11 15 3
OutputNOYESNOYESNO
3 seconds
256 megabytes
['geometry', '*2600']
D. Beautiful Roadtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputA long time ago in some country in Asia were civil wars.Each of n cities wanted to seize power. That's why sometimes one city gathered an army and sent it to campaign against another city.Road making wa...
Input22 1 5
Output2 11
1 second
256 megabytes
['dfs and similar', 'dp', 'dsu', 'graphs', 'implementation', 'sortings', 'trees', '*2300']
C. Interesting Gametime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputTwo best friends Serozha and Gena play a game.Initially there is one pile consisting of n stones on the table. During one move one pile should be taken and divided into an arbitrary number of piles c...
Input3
Output2
2 seconds
256 megabytes
['dp', 'games', 'math', '*2000']
B. Vasya and Typestime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputProgrammer Vasya is studying a new programming language &K*. The &K* language resembles the languages of the C family in its syntax. However, it is more powerful, which is why the rules of the actual C...
Input5typedef void* ptvtypeof ptvtypedef &&ptv nodetypeof nodetypeof &ptv
Outputvoid*errtypevoid
1 second
256 megabytes
['implementation', 'strings', '*1800']
A. Trainstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputVasya the programmer lives in the middle of the Programming subway branch. He has two girlfriends: Dasha and Masha, who live at the different ends of the branch, each one is unaware of the other one's existenc...
Input3 7
OutputDasha
2 seconds
256 megabytes
['implementation', 'math', '*1500']
E. Long sequencetime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputA sequence a0, a1, ... is called a recurrent binary sequence, if each term ai (i = 0, 1, ...) is equal to 0 or 1 and there exist coefficients such that an = c1Β·an - 1 + c2Β·an - 2 + ... + ckΒ·an - k (mod...
Input2
Output1 11 0
2 seconds
256 megabytes
['brute force', 'math', 'matrices', '*2700']
D. Powerful arraytime limit per test5 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputAn array of positive integers a1, a2, ..., an is given. Let us consider its arbitrary subarray al, al + 1..., ar, where 1 ≀ l ≀ r ≀ n. For every positive integer s denote by Ks the number of occurrence...
Input3 21 2 11 21 3
Output36
5 seconds
256 megabytes
['data structures', 'implementation', 'math', 'two pointers', '*2200']
C. Genetic engineeringtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard output"Multidimensional spaces are completely out of style these days, unlike genetics problems" β€” thought physicist Woll and changed his subject of study to bioinformatics. Analysing results of sequenc...
Input2 1A
Output1
2 seconds
256 megabytes
['dp', 'string suffix structures', 'trees', '*2500']
B. Tetris revisitedtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputPhysicist Woll likes to play one relaxing game in between his search of the theory of everything.Game interface consists of a rectangular n × m playing field and a dashboard. Initially some cells of t...
Input2 3...#.#
Output000#0#
1 second
256 megabytes
['constructive algorithms', 'graph matchings', 'greedy', 'math', '*2200']
A. Reflectiontime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputFor each positive integer n consider the integer ψ(n) which is obtained from n by replacing every digit a in the decimal notation of n with the digit (9  -  a). We say that ψ(n) is the reflection of n. For...
Input3 7
Output20
2 seconds
256 megabytes
['math', '*1600']
E. Guard Towerstime limit per test1.5 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputIn a far away kingdom lives a very greedy king. To defend his land, he built n guard towers. Apart from the towers the kingdom has two armies, each headed by a tyrannical and narcissistic general. The ...
Input20 01 1
Output02
1.5 seconds
256 megabytes
['binary search', 'dsu', 'geometry', 'graphs', 'sortings', '*2600']
D. Sum of Medianstime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputIn one well-known algorithm of finding the k-th order statistics we should divide all elements into groups of five consecutive elements and find the median of each five. A median is called the middle e...
Input6add 4add 5add 1add 2add 3sum
Output3
3 seconds
256 megabytes
['binary search', 'brute force', 'data structures', 'implementation', '*2300']
C. Petya and Treetime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputOne night, having had a hard day at work, Petya saw a nightmare. There was a binary search tree in the dream. But it was not the actual tree that scared Petya. The horrifying thing was that Petya could...
Input7-1 81 41 122 22 63 103 1411
Output8.0000000000
3 seconds
256 megabytes
['binary search', 'dfs and similar', 'probabilities', 'sortings', 'trees', '*2200']
B. Embassy Queuetime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputIn an embassy of a well-known kingdom an electronic queue is organised. Every person who comes to the embassy, needs to make the following three actions: show the ID, pay money to the cashier and be fin...
Input1 1 11 1 151 1 1 1 1
Output7
2 seconds
256 megabytes
['data structures', 'greedy', '*1800']
A. Dominotime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputWe all know the problem about the number of ways one can tile a 2 × n field by 1 × 2 dominoes. You probably remember that it goes down to Fibonacci numbers. We will talk about some other problem below, there yo...
Input4
Outputyyzzbccdbxxdyyaa
1 second
256 megabytes
['constructive algorithms', 'implementation', '*1300']