problem_statement stringlengths 147 8.53k | input stringlengths 1 771 | output stringlengths 1 592 β | time_limit stringclasses 32
values | memory_limit stringclasses 21
values | tags stringlengths 6 168 |
|---|---|---|---|---|---|
A. Amr and Musictime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputAmr is a young coder who likes music a lot. He always wanted to learn how to play music but he was busy coding so he got an idea.Amr has n instruments, it takes ai days to learn i-th instrument. Being bu... | Input4 104 3 1 2 | Output41 2 3 4 | 1 second | 256 megabytes | ['greedy', 'implementation', 'sortings', '*1000'] |
E. Mr. Kitayuta's Gifttime limit per test6 secondsmemory limit per test768 megabytesinputstandard inputoutputstandard outputMr. Kitayuta has kindly given you a string s consisting of lowercase English letters. You are asked to insert exactly n lowercase English letters into s to make it a palindrome. (A palindrome is a... | Inputrevive1 | Output1 | 6 seconds | 768 megabytes | ['combinatorics', 'dp', 'matrices', 'strings', '*3000'] |
D. Mr. Kitayuta's Colorful Graphtime limit per test4 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputMr. Kitayuta has just bought an undirected graph with n vertices and m edges. The vertices of the graph are numbered from 1 to n. Each edge, namely edge i, has a color ci, connecting ver... | Input4 51 2 11 2 22 3 12 3 32 4 331 23 41 4 | Output210 | 4 seconds | 256 megabytes | ['brute force', 'dfs and similar', 'dsu', 'graphs', '*2400'] |
E. Mr. Kitayuta vs. Bamboostime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputMr. Kitayuta's garden is planted with n bamboos. (Bamboos are tall, fast-growing tropical plants with hollow stems.) At the moment, the height of the i-th bamboo is hi meters, and it grows ai... | Input3 1 2 510 1010 1015 2 | Output17 | 2 seconds | 256 megabytes | ['binary search', 'greedy', '*2900'] |
D. Mr. Kitayuta's Technologytime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputShuseki Kingdom is the world's leading nation for innovation and technology. There are n cities in the kingdom, numbered from 1 to n.Thanks to Mr. Kitayuta's research, it has finally become p... | Input4 51 21 31 42 32 4 | Output3 | 1 second | 256 megabytes | ['dfs and similar', '*2200'] |
C. Mr. Kitayuta, the Treasure Huntertime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe Shuseki Islands are an archipelago of 30001 small islands in the Yutampo Sea. The islands are evenly spaced along a line, numbered from 0 to 30000 from the west to the east. These... | Input4 1010212727 | Output3 | 1 second | 256 megabytes | ['dfs and similar', 'dp', 'two pointers', '*1900'] |
B. Mr. Kitayuta's Colorful Graphtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputMr. Kitayuta has just bought an undirected graph consisting of n vertices and m edges. The vertices of the graph are numbered from 1 to n. Each edge, namely edge i, has a color ci, connec... | Input4 51 2 11 2 22 3 12 3 32 4 331 23 41 4 | Output210 | 1 second | 256 megabytes | ['dfs and similar', 'dp', 'dsu', 'graphs', '*1400'] |
A. Mr. Kitayuta's Gifttime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputMr. Kitayuta has kindly given you a string s consisting of lowercase English letters. You are asked to insert exactly one lowercase English letter into s to make it a palindrome. A palindrome is a ... | Inputrevive | Outputreviver | 1 second | 256 megabytes | ['brute force', 'implementation', 'strings', '*1100'] |
E. Misha and LCP on Treetime limit per test8 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputMisha has a tree with characters written on the vertices. He can choose two vertices s and t of this tree and write down characters of vertices lying on a path from s to t. We'll say that such s... | Input6bbbabb2 13 24 35 26 562 5 3 11 5 2 35 6 5 66 3 4 16 2 3 42 2 4 5 | Output222010 | 8 seconds | 512 megabytes | ['binary search', 'dfs and similar', 'hashing', 'string suffix structures', 'trees', '*3000'] |
D. Misha and XORtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputAfter Misha's birthday he had many large numbers left, scattered across the room. Now it's time to clean up and Misha needs to put them in a basket. He ordered this task to his pet robot that agreed to ... | Input77654321 | Output0003 0 1 22 1 22 0 22 0 1 | 2 seconds | 256 megabytes | ['bitmasks', '*2700'] |
E. Misha and Palindrome Degreetime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputMisha has an array of n integers indexed by integers from 1 to n. Let's define palindrome degree of array a as the number of such index pairs (l,βr)(1ββ€βlββ€βrββ€βn), that the elements from t... | Input32 2 2 | Output6 | 1 second | 256 megabytes | ['binary search', 'combinatorics', 'implementation', '*2500'] |
D. Misha and Permutations Summationtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputLet's define the sum of two permutations p and q of numbers 0,β1,β...,β(nβ-β1) as permutation , where Perm(x) is the x-th lexicographically permutation of numbers 0,β1,β...,β(nβ-β1) (... | Input20 10 1 | Output0 1 | 2 seconds | 256 megabytes | ['data structures', '*2000'] |
C. Misha and Foresttime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputLet's define a forest as a non-directed acyclic graph (also without loops and parallel edges). One day Misha played with the forest consisting of n vertices. For each vertex v from 0 to nβ-β1 he wrote... | Input32 31 01 0 | Output21 02 0 | 1 second | 256 megabytes | ['constructive algorithms', 'data structures', 'greedy', 'sortings', 'trees', '*1500'] |
B. Misha and Changing Handlestime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputMisha hacked the Codeforces site. Then he decided to let all the users change their handles. A user can now change his handle any number of times. But each new handle must not be equal to an... | Input5Misha ILoveCodeforcesVasya PetrovPetrov VasyaPetrov123ILoveCodeforces MikeMirzayanovPetya Ivanov | Output3Petya IvanovMisha MikeMirzayanovVasya VasyaPetrov123 | 1 second | 256 megabytes | ['data structures', 'dsu', 'strings', '*1100'] |
A. Contesttime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputMisha and Vasya participated in a Codeforces contest. Unfortunately, each of them solved only one problem, though successfully submitted it at the first attempt. Misha solved the problem that costs a points an... | Input500 1000 20 30 | OutputVasya | 1 second | 256 megabytes | ['implementation', '*900'] |
G. New Year Runningtime limit per test4 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputNew Year is coming in Tree Island! In this island, as the name implies, there are n cities connected by nβ-β1 roads, and for any two distinct cities there always exists exactly one path between them.... | Input71 33 67 43 75 47 246 5 5 33 5 4 61 5 1 31 5 3 1 | Output210-1 | 4 seconds | 256 megabytes | ['number theory', 'trees', '*3200'] |
F. New Year Shoppingtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputDohyun is running a grocery store. He sells n items numbered by integers from 1 to n. The i-th (1ββ€βiββ€βn) of them costs ci dollars, and if I buy it, my happiness increases by hi. Each item can be d... | Input4 42 3 23 5 14 7 211 15 541 32 52 65 14 | Output581018 | 2 seconds | 256 megabytes | ['divide and conquer', 'dp', '*2700'] |
E. New Year Dominotime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputCelebrating the new year, many people post videos of falling dominoes; Here's a list of them: https://www.youtube.com/results?search_query=New+Years+Dominos User ainta, who lives in a 2D world, is goi... | Input61 53 34 49 210 112 141 22 42 52 6 | Output0112 | 2 seconds | 256 megabytes | ['data structures', 'dp', 'dsu', '*2300'] |
D. New Year Santa Networktime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputNew Year is coming in Tree World! In this world, as the name implies, there are n cities connected by nβ-β1 roads, and for any two distinct cities there always exists a path between them. The c... | Input32 3 51 3 351 42 21 22 11 1 | Output14.000000000012.00000000008.00000000006.00000000004.0000000000 | 2 seconds | 256 megabytes | ['combinatorics', 'dfs and similar', 'graphs', 'trees', '*1900'] |
C. New Year Book Readingtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputNew Year is coming, and Jaehyun decided to read many books during 2015, unlike this year. He has n books numbered by integers from 1 to n. The weight of the i-th (1ββ€βiββ€βn) book is wi.As Jaehyu... | Input3 51 2 31 3 2 3 1 | Output12 | 2 seconds | 256 megabytes | ['constructive algorithms', 'greedy', 'implementation', 'math', '*1600'] |
B. New Year Permutationtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputUser ainta has a permutation p1,βp2,β...,βpn. As the New Year is coming, he wants to make his permutation as pretty as possible.Permutation a1,βa2,β...,βan is prettier than permutation b1,βb2,β..... | Input75 2 4 3 6 7 10001001000000000000101000001000000000100001001000 | Output1 2 4 3 6 7 5 | 2 seconds | 256 megabytes | ['dfs and similar', 'dsu', 'graphs', 'greedy', 'math', 'sortings', '*1600'] |
A. New Year Transportationtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputNew Year is coming in Line World! In this world, there are n cells numbered by integers from 1 to n, as a 1βΓβn board. People live in cells. However, it was hard to move between distinct cells... | Input8 41 2 1 2 1 2 1 | OutputYES | 2 seconds | 256 megabytes | ['dfs and similar', 'graphs', 'implementation', '*1000'] |
B. Lecturetime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou have a new professor of graph theory and he speaks very quickly. You come up with the following plan to keep up with his lecture and make notes.You know two languages, and the professor is giving the lectu... | Input4 3codeforces codesecrofcontest roundletter messagecodeforces contest letter contest | Outputcodeforces round letter round | 1 second | 256 megabytes | ['implementation', 'strings', '*1000'] |
A. Watching a movietime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou have decided to watch the best moments of some movie. There are two buttons on your player: Watch the current minute of the movie. By pressing this button, you watch the current minute of the mo... | Input2 35 610 12 | Output6 | 1 second | 256 megabytes | ['greedy', 'implementation', '*1000'] |
E. Stairs and Linestime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a figure on a grid representing stairs consisting of 7 steps. The width of the stair on height i is wi squares. Formally, the figure is created by consecutively joining rectangles of si... | Input0 1 0 0 0 0 0 | Output1 | 2 seconds | 256 megabytes | ['dp', 'matrices', '*2700'] |
D. Traffic Jams in the Landtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputSome country consists of (nβ+β1) cities, located along a straight highway. Let's number the cities with consecutive integers from 1 to nβ+β1 in the order they occur along the highway. Thus, t... | Input102 5 3 2 3 5 3 4 2 410C 10 6A 2 6A 1 3C 3 4A 3 11A 4 9A 5 6C 7 3A 8 10A 2 5 | Output53146244 | 2 seconds | 256 megabytes | ['data structures', 'dp', 'number theory', '*2400'] |
C. Array and Operationstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou have written on a piece of paper an array of n positive integers a[1],βa[2],β...,βa[n] and m good pairs of integers (i1,βj1),β(i2,βj2),β...,β(im,βjm). Each good pair (ik,βjk) meets the followi... | Input3 28 3 81 22 3 | Output0 | 1 second | 256 megabytes | ['flows', 'graph matchings', 'number theory', '*2100'] |
B. Name That Tunetime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputIt turns out that you are a great fan of rock band AC/PE. Peter learned that and started the following game: he plays the first song of the list of n songs of the group, and you have to find out the nam... | Input2 250 210 1 | Output1.500000000 | 1 second | 256 megabytes | ['dp', 'probabilities', 'two pointers', '*2400'] |
A. Crazy Towntime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputCrazy Town is a plane on which there are n infinite line roads. Each road is defined by the equation aixβ+βbiyβ+βciβ=β0, where ai and bi are not both equal to the zero. The roads divide the plane into conne... | Input1 1-1 -120 1 01 0 0 | Output2 | 1 second | 256 megabytes | ['geometry', '*1700'] |
E. Subsequences Returntime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputAssume that sk(n) equals the sum of digits of number n in the k-based notation. For example, s2(5)β=βs2(1012)β=β1β+β0β+β1β=β2, s3(14)β=βs3(1123)β=β1β+β1β+β2β=β4.The sequence of integers a0,β...,βan... | Input4 2 | Output11 | 1 second | 256 megabytes | ['dp', 'matrices', '*2900'] |
E. Distributing Parts time limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are an assistant director in a new musical play. The play consists of n musical parts, each part must be performed by exactly one actor. After the casting the director chose m actors who can t... | Input31 32 43 521 4 22 5 1 | OutputYES1 1 2 | 2 seconds | 256 megabytes | ['greedy', 'sortings', '*2100'] |
D. Tennis Gametime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputPetya and Gena love playing table tennis. A single match is played according to the following rules: a match consists of multiple sets, each set consists of multiple serves. Each serve is won by one of th... | Input51 2 1 2 1 | Output21 33 1 | 2 seconds | 256 megabytes | ['binary search', '*1900'] |
C. Removing Columnstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given an nβΓβm rectangular table consisting of lower case English letters. In one operation you can completely remove one column from the table. The remaining parts are combined forming a new... | Input1 10codeforces | Output0 | 2 seconds | 256 megabytes | ['brute force', 'constructive algorithms', 'implementation', '*1500'] |
B. Secret Combinationtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou got a box with a combination lock. The lock has a display showing n digits. There are two buttons on the box, each button changes digits on the display. You have quickly discovered that the fir... | Input3579 | Output024 | 2 seconds | 256 megabytes | ['brute force', 'constructive algorithms', 'implementation', '*1500'] |
A. Minimum Difficultytime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputMike is trying rock climbing but he is awful at it. There are n holds on the wall, i-th hold is at height ai off the ground. Besides, let the sequence ai increase, that is, aiβ<βaiβ+β1 for all i fr... | Input31 4 6 | Output5 | 2 seconds | 256 megabytes | ['brute force', 'implementation', 'math', '*900'] |
B. Modular Equationstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputLast week, Hamed learned about a new type of equations in his math class called Modular Equations. Lets define i modulo j as the remainder of division of i by j and denote it by . A Modular Equation,... | Input21 5 | Output2 | 1 second | 256 megabytes | ['math', 'number theory', '*1600'] |
A. Digital Countertime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputMalek lives in an apartment block with 100 floors numbered from 0 to 99. The apartment has an elevator with a digital counter showing the floor that the elevator is currently on. The elevator shows eac... | Input89 | Output2 | 1 second | 256 megabytes | ['implementation', '*1100'] |
E. Shartitime limit per test5 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputDuring the last 24 hours Hamed and Malek spent all their time playing "Sharti". Now they are too exhausted to finish the last round. So they asked you for help to determine the winner of this round. "Sharti" i... | Input5 2 11 1 3 32 2 4 4 | OutputMalek | 5 seconds | 256 megabytes | ['data structures', 'games', '*3200'] |
D. Birthdaytime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputAli is Hamed's little brother and tomorrow is his birthday. Hamed wants his brother to earn his gift so he gave him a hard programming problem and told him if he can successfully solve it, he'll get him a br... | Input51 2 14 3 13 5 11 3 151 11 52 42 13 5 | Output1010000000051000000002231000000002 | 2 seconds | 256 megabytes | ['data structures', 'dfs and similar', 'dp', 'trees', '*2700'] |
C. Helping Peopletime limit per test2 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputMalek is a rich man. He also is very generous. That's why he decided to split his money between poor people. A charity institute knows n poor people numbered from 1 to n. The institute gave Malek q rec... | Input5 21 7 2 4 31 3 0.5002 2 0.500 | Output8.000000000 | 2 seconds | 512 megabytes | ['dp', 'probabilities', '*2600'] |
B. Obsessive Stringtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputHamed has recently found a string t and suddenly became quite fond of it. He spent several days trying to find all occurrences of t in other strings he had. Finally he became tired and started thinki... | Inputababaaba | Output5 | 2 seconds | 256 megabytes | ['dp', 'strings', '*2000'] |
A. Treasuretime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputMalek has recently found a treasure map. While he was looking for a treasure he found a locked door. There was a string s written on the door consisting of characters '(', ')' and '#'. Below there was a manu... | Input(((#)((#) | Output12 | 2 seconds | 256 megabytes | ['greedy', '*1500'] |
E. Vasya and Polynomialtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputVasya is studying in the last class of school and soon he will take exams. He decided to study polynomials. Polynomial is a function P(x)β=βa0β+βa1x1β+β...β+βanxn. Numbers ai are called coefficie... | Input2 2 2 | Output2 | 2 seconds | 256 megabytes | ['math', '*2800'] |
D. Vasya and Chesstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputVasya decided to learn to play chess. Classic chess doesn't seem interesting to him, so he plays his own sort of chess.The queen is the piece that captures all squares on its vertical, horizontal and ... | Input2 | Outputwhite1 2 | 2 seconds | 256 megabytes | ['constructive algorithms', 'games', 'math', '*1700'] |
C. Vasya and Basketballtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputVasya follows a basketball game and marks the distances from which each team makes a throw. He knows that each successful throw has value of either 2 or 3 points. A throw is worth 2 points if the... | Input31 2 325 6 | Output9:6 | 2 seconds | 256 megabytes | ['binary search', 'brute force', 'data structures', 'implementation', 'sortings', 'two pointers', '*1600'] |
B. Vasya and Wrestlingtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputVasya has become interested in wrestling. In wrestling wrestlers use techniques for which they are awarded points by judges. The wrestler who gets the most points wins.When the numbers of points o... | Input512-3-43 | Outputsecond | 2 seconds | 256 megabytes | ['implementation', '*1400'] |
A. Vasya and Footballtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputVasya has started watching football games. He has learned that for some fouls the players receive yellow cards, and for some fouls they receive red cards. A player who receives the second yellow ca... | InputMCCSKA928 a 3 y62 h 25 y66 h 42 y70 h 25 y77 a 4 y79 a 25 y82 h 42 r89 h 16 y90 a 13 r | OutputMC 25 70MC 42 82CSKA 13 90 | 2 seconds | 256 megabytes | ['implementation', '*1300'] |
E. Vanya and Fieldtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputVanya decided to walk in the field of size nβΓβn cells. The field contains m apple trees, the i-th apple tree is at the cell with coordinates (xi,βyi). Vanya moves towards vector (dx,βdy). That means ... | Input5 5 2 30 01 21 32 43 1 | Output1 3 | 2 seconds | 256 megabytes | ['math', '*2000'] |
D. Vanya and Computer Gametime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputVanya and his friend Vova play a computer game where they need to destroy n monsters to pass a level. Vanya's character performs attack with frequency x hits per second and Vova's character pe... | Input4 3 21234 | OutputVanyaVovaVanyaBoth | 2 seconds | 256 megabytes | ['binary search', 'implementation', 'math', 'sortings', '*1800'] |
C. Vanya and Examstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputVanya wants to pass n exams and get the academic scholarship. He will get the scholarship if the average grade mark for all the exams is at least avg. The exam grade cannot exceed r. Vanya has passed t... | Input5 5 45 24 73 13 22 5 | Output4 | 1 second | 256 megabytes | ['greedy', 'sortings', '*1400'] |
B. Vanya and Lanternstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputVanya walks late at night along a straight street of length l, lit by n lanterns. Consider the coordinate system with the beginning of the street corresponding to the point 0, and its end correspond... | Input7 1515 5 3 7 9 14 0 | Output2.5000000000 | 1 second | 256 megabytes | ['binary search', 'implementation', 'math', 'sortings', '*1200'] |
A. Vanya and Cubestime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputVanya got n cubes. He decided to build a pyramid from them. Vanya wants to build the pyramid as follows: the top level of the pyramid must consist of 1 cube, the second level must consist of 1β+β2β=β3 ... | Input1 | Output1 | 1 second | 256 megabytes | ['implementation', '*800'] |
C. Decipheringtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputOne day Maria Ivanovna found a Sasha's piece of paper with a message dedicated to Olya. Maria Ivanovna wants to know what is there in a message, but unfortunately the message is ciphered. Maria Ivanovna kn... | Input10 2aaabbbaaabbbbbabbbbb | Output7ba | 1 second | 256 megabytes | ['flows', 'graph matchings', '*2300'] |
B. New York Hoteltime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThink of New York as a rectangular grid consisting of N vertical avenues numerated from 1 to N and M horizontal streets numerated 1 to M. C friends are staying at C hotels located at some street-avenue... | Input10 1021 13 321 104 4 | Output62 | 2 seconds | 256 megabytes | ['greedy', 'math', '*2100'] |
A. Up the hilltime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputHiking club "Up the hill" just returned from a walk. Now they are trying to remember which hills they've just walked through.It is known that there were N stops, all on different integer heights between 1 ... | Input01 | Output2 1 | 1 second | 256 megabytes | ['constructive algorithms', 'implementation', '*1000'] |
F. Treeland Tourtime limit per test5 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe "Road Accident" band is planning an unprecedented tour around Treeland. The RA fans are looking forward to the event and making bets on how many concerts their favorite group will have.Treeland cons... | Input61 2 3 4 5 11 22 33 43 53 6 | Output4 | 5 seconds | 256 megabytes | ['data structures', 'dfs and similar', 'dp', 'trees', '*2200'] |
E. Restoring Increasing Sequencetime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputPeter wrote on the board a strictly increasing sequence of positive integers a1,βa2,β...,βan. Then Vasil replaced some digits in the numbers of this sequence by question marks. Thus, each... | Input3?181? | OutputYES11819 | 1 second | 256 megabytes | ['binary search', 'brute force', 'greedy', 'implementation', '*2000'] |
D. Chocolatetime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputPolycarpus likes giving presents to Paraskevi. He has bought two chocolate bars, each of them has the shape of a segmented rectangle. The first bar is a1βΓβb1 segments large and the second one is a2βΓβb2 seg... | Input2 62 3 | Output11 62 3 | 1 second | 256 megabytes | ['brute force', 'dfs and similar', 'math', 'meet-in-the-middle', 'number theory', '*1900'] |
C. Hacking Cyphertime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputPolycarpus participates in a competition for hacking into a new secure messenger. He's almost won.Having carefully studied the interaction protocol, Polycarpus came to the conclusion that the secret key... | Input11640102497 1024 | OutputYES116401024 | 1 second | 256 megabytes | ['brute force', 'math', 'number theory', 'strings', '*1700'] |
B. Queuetime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputDuring the lunch break all n Berland State University students lined up in the food court. However, it turned out that the food court, too, has a lunch break and it temporarily stopped working.Standing in a que... | Input492 310 731 07 141 | Output92 7 31 141 | 2 seconds | 256 megabytes | ['dsu', 'implementation', '*1500'] |
A. Team Olympiadtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe School β0 of the capital of Berland has n children studying in it. All the children in this school are gifted: some of them are good at programming, some are good at maths, others are good at PE (Phy... | Input71 3 1 3 2 1 2 | Output23 5 26 7 4 | 1 second | 256 megabytes | ['greedy', 'implementation', 'sortings', '*800'] |
F. Special Matricestime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputAn nβΓβn square matrix is special, if: it is binary, that is, each cell contains either a 0, or a 1; the number of ones in each row and column equals 2. You are given n and the first m rows of the m... | Input3 1 1000011 | Output2 | 1 second | 256 megabytes | ['combinatorics', 'dp', '*2100'] |
E. Hikingtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputA traveler is planning a water hike along the river. He noted the suitable rest points for the night and wrote out their distances from the starting point. Each of these locations is further characterized by it... | Input5 910 1020 1030 131 540 10 | Output1 2 4 5 | 1 second | 256 megabytes | ['binary search', 'dp', '*2300'] |
D. Unbearable Controversy of Beingtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputTomash keeps wandering off and getting lost while he is walking along the streets of Berland. It's no surprise! In his home town, for any pair of intersections there is exactly one way ... | Input5 41 22 31 44 3 | Output1 | 1 second | 256 megabytes | ['brute force', 'combinatorics', 'dfs and similar', 'graphs', '*1700'] |
C. Given Length and Sum of Digits...time limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbe... | Input2 15 | Output69 96 | 1 second | 256 megabytes | ['dp', 'greedy', 'implementation', '*1400'] |
B. BerSU Balltime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe Berland State University is hosting a ballroom dance in celebration of its 100500-th anniversary! n boys and m girls are already busy rehearsing waltz, minuet, polonaise and quadrille moves.We know that... | Input41 4 6 255 1 5 7 9 | Output3 | 1 second | 256 megabytes | ['dfs and similar', 'dp', 'graph matchings', 'greedy', 'sortings', 'two pointers', '*1200'] |
A. SwapSorttime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputIn this problem your goal is to sort an array consisting of n integers in at most n swaps. For the given array find the sequence of swaps that makes the array sorted in the non-descending order. Swaps are per... | Input55 2 5 1 4 | Output20 34 2 | 1 second | 256 megabytes | ['greedy', 'implementation', 'sortings', '*1200'] |
B. Candy Boxestime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere is an old tradition of keeping 4 boxes of candies in the house in Cyberland. The numbers of candies are special if their arithmetic mean, their median and their range are all equal. By definition, fo... | Input211 | OutputYES33 | 1 second | 256 megabytes | ['brute force', 'constructive algorithms', 'math', '*1900'] |
A. Giga Towertime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputGiga Tower is the tallest and deepest building in Cyberland. There are 17β777β777β777 floors, numbered from β-β8β888β888β888 to 8β888β888β888. In particular, there is floor 0 between floor β-β1 and floor 1.... | Input179 | Output1 | 1 second | 256 megabytes | ['brute force', '*1100'] |
E. Touriststime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere are n cities in Cyberland, numbered from 1 to n, connected by m bidirectional roads. The j-th road connects city aj and bj.For tourists, souvenirs are sold in every city of Cyberland. In particular, ci... | Input3 3 31231 22 31 3A 2 3C 1 5A 2 3 | Output12 | 2 seconds | 256 megabytes | ['data structures', 'dfs and similar', 'graphs', 'trees', '*3200'] |
D. Conveyor Beltstime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputAutomatic Bakery of Cyberland (ABC) recently bought an nβΓβm rectangle table. To serve the diners, ABC placed seats around the table. The size of each seat is equal to a unit square, so there are 2(nβ+... | Input2 2 3>>^^A 2 1C 1 2 <A 2 1 | Output1 3-1 -1 | 3 seconds | 256 megabytes | ['data structures', '*2700'] |
C. Prefix Product Sequencetime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputConsider a sequence [a1,βa2,β... ,βan]. Define its prefix product sequence .Now given n, find a permutation of [1,β2,β...,βn], such that its prefix product sequence is a permutation of [0,β1,β.... | Input7 | OutputYES1436527 | 1 second | 256 megabytes | ['constructive algorithms', 'math', 'number theory', '*2300'] |
B. Striptime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputAlexandra has a paper strip with n numbers on it. Let's call them ai from left to right.Now Alexandra wants to split it into some pieces (possibly 1). For each piece of strip, it must satisfy: Each piece should ... | Input7 2 21 3 1 2 4 1 2 | Output3 | 1 second | 256 megabytes | ['binary search', 'data structures', 'dp', 'two pointers', '*2000'] |
A. Fight the Monstertime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputA monster is attacking the Cyberland!Master Yang, a braver, is going to beat the monster. Yang and the monster each have 3 attributes: hitpoints (HP), offensive power (ATK) and defensive power (DEF).... | Input1 2 11 100 11 100 100 | Output99 | 1 second | 256 megabytes | ['binary search', 'brute force', 'implementation', '*1800'] |
E. LIS of Sequencetime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe next "Data Structures and Algorithms" lesson will be about Longest Increasing Subsequence (LIS for short) of a sequence. For better understanding, Nam decided to learn it a few days before the les... | Input14 | Output3 | 2 seconds | 256 megabytes | ['data structures', 'dp', 'greedy', 'hashing', 'math', '*2200'] |
D. Valid Setstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputAs you know, an undirected connected graph with n nodes and nβ-β1 edges is called a tree. You are given an integer d and a tree consisting of n nodes. Each node i has a value ai associated with it.We call a... | Input1 42 1 3 21 21 33 4 | Output8 | 1 second | 256 megabytes | ['dfs and similar', 'dp', 'math', 'trees', '*2100'] |
C. Palindrome Transformationtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputNam is playing with a string on his computer. The string consists of n lowercase English letters. It is meaningless, so Nam decided to make the string more beautiful, that is to make it be a ... | Input8 3aeabcaez | Output6 | 1 second | 256 megabytes | ['brute force', 'greedy', 'implementation', '*1700'] |
B. OR in Matrixtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputLet's define logical OR as an operation on two logical values (i. e. values that belong to the set {0,β1}) that is equal to 1 if either or both of the logical values is set to 1, otherwise it is 0. We can... | Input2 21 00 0 | OutputNO | 1 second | 256 megabytes | ['greedy', 'hashing', 'implementation', '*1300'] |
A. Calculating Functiontime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputFor a positive integer n let's define a function f:f(n)β=ββ-β1β+β2β-β3β+β..β+β(β-β1)nn Your task is to calculate f(n) for a given integer n.InputThe single line contains the positive integer n (1β... | Input4 | Output2 | 1 second | 256 megabytes | ['implementation', 'math', '*800'] |
B. Valuable Resourcestime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputMany computer strategy games require building cities, recruiting army, conquering tribes, collecting resources. Sometimes it leads to interesting problems. Let's suppose that your task is to build a... | Input20 02 2 | Output4 | 1 second | 256 megabytes | ['brute force', 'greedy', '*1300'] |
A. Factorytime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputOne industrial factory is reforming working plan. The director suggested to set a mythical detail production norm. If at the beginning of the day there were x details in the factory storage, then by the end of... | Input1 5 | OutputNo | 1 second | 256 megabytes | ['implementation', 'math', 'matrices', '*1400'] |
E. Sign on Fencetime limit per test4 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputBizon the Champion has recently finished painting his wood fence. The fence consists of a sequence of n panels of 1 meter width and of arbitrary height. The i-th panel's height is hi meters. The adjacen... | Input51 2 2 3 332 5 32 5 21 5 5 | Output231 | 4 seconds | 256 megabytes | ['binary search', 'constructive algorithms', 'data structures', '*2500'] |
D. Kindergartentime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputIn a kindergarten, the children are being divided into groups. The teacher put the children in a line and associated each child with his or her integer charisma value. Each child should go to exactly one... | Input51 2 3 1 2 | Output3 | 2 seconds | 256 megabytes | ['data structures', 'dp', 'greedy', '*2400'] |
C. Strange Sortingtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputHow many specific orders do you know? Ascending order, descending order, order of ascending length, order of ascending polar angle... Let's have a look at another specific order: d-sorting. This sorti... | Inputqwerty34 26 35 2 | Outputqertwyqtewryqetyrw | 2 seconds | 256 megabytes | ['implementation', 'math', '*2600'] |
B. Maximum Valuetime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a sequence a consisting of n integers. Find the maximum possible value of (integer remainder of ai divided by aj), where 1ββ€βi,βjββ€βn and aiββ₯βaj.InputThe first line contains integer nΒ β t... | Input33 4 5 | Output2 | 1 second | 256 megabytes | ['binary search', 'math', 'sortings', 'two pointers', '*2100'] |
A. Bitstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputLet's denote as the number of bits set ('1' bits) in the binary representation of the non-negative integer x.You are given multiple queries consisting of pairs of integers l and r. For each query, find the x, su... | Input31 22 41 10 | Output137 | 1 second | 256 megabytes | ['bitmasks', 'constructive algorithms', '*1700'] |
B. Friends and Presentstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou have two friends. You want to present each of them several positive integers. You want to present cnt1 numbers to the first friend and cnt2 numbers to the second friend. Moreover, you want all... | Input3 1 2 3 | Output5 | 1 second | 256 megabytes | ['binary search', 'math', '*1800'] |
A. Counterexample time limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYour friend has recently learned about coprime numbers. A pair of numbers {a,βb} is called coprime if the maximum number that divides both a and b is equal to one. Your friend often comes up with diffe... | Input2 4 | Output2 3 4 | 1 second | 256 megabytes | ['brute force', 'implementation', 'math', 'number theory', '*1100'] |
E. ELCAtime limit per test8 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou have a root tree containing n vertexes. Let's number the tree vertexes with integers from 1 to n. The tree root is in the vertex 1.Each vertex (except fot the tree root) v has a direct ancestor pv. Also each... | Input51 2 2 11 2 3 4 55P 3 4P 4 5V 2 3P 5 2P 1 4 | Output1.6400000001.8000000002.2800000002.3200000002.8000000001.840000000 | 8 seconds | 256 megabytes | ['data structures', 'trees', '*3200'] |
D. Random Function and Treetime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou have a rooted tree consisting of n vertices. Let's number them with integers from 1 to n inclusive. The root of the tree is the vertex 1. For each iβ>β1 direct parent of the vertex i is pi... | Input41 2 1 | Output8 | 1 second | 256 megabytes | ['combinatorics', 'dp', 'trees', '*2700'] |
C. Game with Stringstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou play the game with your friend. The description of this game is listed below. Your friend creates n distinct strings of the same length m and tells you all the strings. Then he randomly chooses o... | Input2aabaac | Output2.000000000000000 | 1 second | 256 megabytes | ['bitmasks', 'dp', 'probabilities', '*2600'] |
B. Interesting Arraytime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputWe'll call an array of n non-negative integers a[1],βa[2],β...,βa[n] interesting, if it meets m constraints. The i-th of the m constraints consists of three integers li, ri, qi (1ββ€βliββ€βriββ€βn) mean... | Input3 11 3 3 | OutputYES3 3 3 | 1 second | 256 megabytes | ['constructive algorithms', 'data structures', 'trees', '*1800'] |
A. Diverse Permutationtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputPermutation p is an ordered set of integers p1,βββp2,βββ...,βββpn, consisting of n distinct positive integers not larger than n. We'll denote as n the length of permutation p1,βββp2,βββ...,βββpn.Yo... | Input3 2 | Output1 3 2 | 1 second | 256 megabytes | ['constructive algorithms', 'greedy', '*1200'] |
E. Parking Lottime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputPetya's been bored at work and he is killing the time by watching the parking lot at the office. The parking lot looks from above like an nβΓβm table (a cell of the table corresponds to a single parking s... | Input7 8 4........X.....X..................X......................1 56 43 54 6 | Output5443 | 3 seconds | 256 megabytes | ['data structures', 'divide and conquer', '*2800'] |
D. Parcelstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputJaroslav owns a small courier service. He has recently got and introduced a new system of processing parcels. Each parcel is a box, the box has its weight and strength. The system works as follows. It origina... | Input3 20 1 1 1 11 2 1 1 10 2 1 1 1 | Output3 | 2 seconds | 256 megabytes | ['dp', 'graphs', '*2600'] |
E. Riding in a Lifttime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputImagine that you are in a building that has exactly n floors. You can move between the floors in a lift. Let's number the floors from bottom to top with integers from 1 to n. Now you're on the floor ... | Input5 2 4 1 | Output2 | 2 seconds | 256 megabytes | ['combinatorics', 'dp', '*1900'] |
D. Long Jumpstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputValery is a PE teacher at a school in Berland. Soon the students are going to take a test in long jumps, and Valery has lost his favorite ruler! However, there is no reason for disappointment, as Valery has... | Input3 250 185 2300 185 250 | Output1230 | 1 second | 256 megabytes | ['binary search', 'greedy', 'implementation', '*1700'] |
C. Examstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputStudent Valera is an undergraduate student at the University. His end of term exams are approaching and he is to pass exactly n exams. Valera is a smart guy, so he will be able to pass any exam he takes on his f... | Input35 23 14 2 | Output2 | 1 second | 256 megabytes | ['greedy', 'sortings', '*1400'] |
B. Towerstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputAs you know, all the kids in Berland love playing with cubes. Little Petya has n towers consisting of cubes of the same size. Tower with number i consists of ai cubes stacked one on top of the other. Petya defi... | Input3 25 8 5 | Output0 22 12 3 | 1 second | 256 megabytes | ['brute force', 'constructive algorithms', 'greedy', 'implementation', 'sortings', '*1400'] |
A. Expressiontime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputPetya studies in a school and he adores Maths. His class has been studying arithmetic expressions. On the last class the teacher wrote three positive integers a, b, c on the blackboard. The task was to inse... | Input123 | Output9 | 1 second | 256 megabytes | ['brute force', 'math', '*1000'] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.