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. Oath of the Night's Watchtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard output"Night gathers, and now my watch begins. It shall not end until my death. I shall take no wife, hold no lands, father no children. I shall wear no crowns and win no glory. I shall live and d... | Input21 5 | Output0 | 2 seconds | 256 megabytes | ['constructive algorithms', 'sortings', '*900'] |
E. Change-freetime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputStudent Arseny likes to plan his life for n days ahead. He visits a canteen every day and he has already decided what he will order in each of the following n days. Prices in the canteen do not change and ... | Input5 42117 71 150 243 2001 1 1 1 1 | Output791 171 02 02 432 0 | 1 second | 256 megabytes | ['greedy', '*2400'] |
D. Cartons of milktime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputOlya likes milk very much. She drinks k cartons of milk each day if she has at least k and drinks all of them if she doesn't. But there's an issue — expiration dates. Each carton has a date after whic... | Input3 6 21 0 12 0 2 0 0 2 | Output31 2 3 | 2 seconds | 256 megabytes | ['binary search', 'data structures', 'greedy', 'sortings', 'two pointers', '*2100'] |
C. Garlandtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputOnce at New Year Dima had a dream in which he was presented a fairy garland. A garland is a set of lamps, some pairs of which are connected by wires. Dima remembered that each two lamps in the garland were co... | Input62 40 54 22 11 14 2 | Output1 4 | 2 seconds | 256 megabytes | ['dfs and similar', 'graphs', 'greedy', 'trees', '*2000'] |
B. The Queuetime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputFinally! Vasya have come of age and that means he can finally get a passport! To do it, he needs to visit the passport office, but it's not that simple. There's only one receptionist at the passport office a... | Input10 15 2210 13 | Output12 | 1 second | 256 megabytes | ['brute force', 'greedy', '*2100'] |
A. Snacktowertime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputAccording to an old legeng, a long time ago Ankh-Morpork residents did something wrong to miss Fortune, and she cursed them. She said that at some time n snacks of distinct sizes will fall on the city, and... | Input33 1 2 | Output3 2 1 | 2 seconds | 256 megabytes | ['data structures', 'implementation', '*1100'] |
E. Mahmoud and a xor triptime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputMahmoud and Ehab live in a country with n cities numbered from 1 to n and connected by n - 1 undirected roads. It's guaranteed that you can reach any city from any other using these roads. Each... | Input31 2 31 22 3 | Output10 | 2 seconds | 256 megabytes | ['bitmasks', 'constructive algorithms', 'data structures', 'dfs and similar', 'dp', 'math', 'trees', '*2100'] |
D. Mahmoud and a Dictionarytime limit per test4 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputMahmoud wants to write a new dictionary that contains n words and relations between them. There are two types of relations: synonymy (i. e. the two words mean the same) and antonymy (i. e. th... | Input3 3 4hate love like1 love like2 love hate1 hate likelove likelove hatelike hatehate like | OutputYESYESNO1222 | 4 seconds | 256 megabytes | ['data structures', 'dfs and similar', 'dp', 'dsu', 'graphs', '*2000'] |
C. Mahmoud and a Messagetime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputMahmoud wrote a message s of length n. He wants to send it as a birthday present to his friend Moaz who likes strings. He wrote it on a magical paper but he was surprised because some characters... | Input3aab2 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 | Output322 | 2 seconds | 256 megabytes | ['brute force', 'dp', 'greedy', 'strings', '*1700'] |
B. Mahmoud and a Triangletime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputMahmoud has n line segments, the i-th of them has length ai. Ehab challenged him to use exactly 3 line segments to form a non-degenerate triangle. Mahmoud doesn't accept challenges unless he is... | Input51 5 3 2 4 | OutputYES | 2 seconds | 256 megabytes | ['constructive algorithms', 'geometry', 'greedy', 'math', 'number theory', 'sortings', '*1000'] |
A. Mahmoud and Longest Uncommon Subsequencetime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputWhile Mahmoud and Ehab were practicing for IOI, they found a problem which name was Longest common subsequence. They solved it, and then Ehab challenged Mahmoud with another p... | Inputabcddefgh | Output5 | 2 seconds | 256 megabytes | ['constructive algorithms', 'strings', '*1000'] |
G. Math, math everywheretime limit per test5 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputIf you have gone that far, you'll probably skip unnecessary legends anyway...You are given a binary string and an integer . Find the number of integers k, 0 ≤ k < N, such that for all i = 0, 1,... | Input122 13 1 | Output2 | 5 seconds | 512 megabytes | ['brute force', 'dp', 'math', 'meet-in-the-middle', 'number theory', '*3200'] |
F. Souvenirstime limit per test3 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputArtsem is on vacation and wants to buy souvenirs for his two teammates. There are n souvenir shops along the street. In i-th shop Artsem can buy one souvenir for ai dollars, and he cannot buy more than one ... | Input83 1 4 1 5 9 2 641 81 34 85 7 | Output0113 | 3 seconds | 512 megabytes | ['data structures', '*3100'] |
E. Tree Foldingtime limit per test2 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputVanya wants to minimize a tree. He can perform the following operation multiple times: choose a vertex v, and two disjoint (except for v) paths of equal length a0 = v, a1, ..., ak, and b0 = v, b1, ..., b... | Input61 22 32 44 51 6 | Output3 | 2 seconds | 512 megabytes | ['dfs and similar', 'dp', 'greedy', 'implementation', 'trees', '*2200'] |
D. Artsem and Saunderstime limit per test2 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputArtsem has a friend Saunders from University of Chicago. Saunders presented him with the following problem.Let [n] denote the set {1, ..., n}. We will also write f: [x] → [y] when a function f is ... | Input31 2 3 | Output31 2 31 2 3 | 2 seconds | 512 megabytes | ['constructive algorithms', 'dsu', 'math', '*1700'] |
C. Table Tennis Game 2time limit per test2 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputMisha and Vanya have played several table tennis sets. Each set consists of several serves, each serve is won by one of the players, he receives one point and the loser receives nothing. Once one ... | Input11 11 5 | Output1 | 2 seconds | 512 megabytes | ['math', '*1200'] |
B. Code obfuscationtime limit per test2 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputKostya likes Codeforces contests very much. However, he is very disappointed that his solutions are frequently hacked. That's why he decided to obfuscate (intentionally make less readable) his code b... | Inputabacaba | OutputYES | 2 seconds | 512 megabytes | ['greedy', 'implementation', 'strings', '*1100'] |
A. Neverending competitionstime limit per test2 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputThere are literally dozens of snooker competitions held each year, and team Jinotega tries to attend them all (for some reason they prefer name "snookah")! When a competition takes place some... | Input4SVOSVO->CDGLHR->SVOSVO->LHRCDG->SVO | Outputhome | 2 seconds | 512 megabytes | ['implementation', 'math', '*900'] |
B. Timofey and cubestime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYoung Timofey has a birthday today! He got kit of n cubes as a birthday present from his parents. Every cube has a number ai, which is written on it. Timofey put all the cubes in a row and went to un... | Input74 3 7 6 9 1 2 | Output2 3 9 6 7 1 4 | 1 second | 256 megabytes | ['constructive algorithms', 'implementation', '*900'] |
A. Taymyr is calling youtime limit per test1 secondmemory limit per test255 megabytesinputstandard inputoutputstandard outputComrade Dujikov is busy choosing artists for Timofey's birthday and is recieving calls from Taymyr from Ilia-alpinist.Ilia-alpinist calls every n minutes, i.e. in minutes n, 2n, 3n and so on. Art... | Input1 1 10 | Output10 | 1 second | 255 megabytes | ['brute force', 'implementation', 'math', '*800'] |
E. Timofey and our friends animalstime limit per test7 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputAfter his birthday party, Timofey went to his favorite tree alley in a park. He wants to feed there his favorite birds — crows.It's widely known that each tree is occupied by a single ... | Input5 331 32 34 551 11 22 31 31 5 | Output12112 | 7 seconds | 256 megabytes | ['data structures', 'divide and conquer', 'dsu', '*2900'] |
D. Timofey and a flat treetime limit per test4 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputLittle Timofey has a big tree — an undirected connected graph with n vertices and no simple cycles. He likes to walk along it. His tree is flat so when he walks along it he sees it entirely. Q... | Input31 22 3 | Output1 | 4 seconds | 256 megabytes | ['data structures', 'graphs', 'hashing', 'shortest paths', 'trees', '*2900'] |
C. Timofey and remodulingtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputLittle Timofey likes integers a lot. Unfortunately, he is very young and can't work with very big integers, so he does all the operations modulo his favorite prime m. Also, Timofey likes to loo... | Input17 50 2 4 13 15 | Output13 2 | 2 seconds | 256 megabytes | ['brute force', 'implementation', 'math', 'number theory', '*2600'] |
B. Timofey and rectanglestime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputOne of Timofey's birthday presents is a colourbook in a shape of an infinite plane. On the plane n rectangles with sides parallel to coordinate axes are situated. All sides of the rectangles ha... | Input80 0 5 32 -1 5 0-3 -4 2 -1-1 -1 2 0-3 0 0 55 2 10 37 -3 10 24 -2 7 -1 | OutputYES12232241 | 2 seconds | 256 megabytes | ['constructive algorithms', 'geometry', '*2100'] |
A. Timofey and a treetime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputEach New Year Timofey and his friends cut down a tree of n vertices and bring it home. After that they paint all the n its vertices, so that the i-th vertex gets color ci.Now it's time for Timofey ... | Input41 22 33 41 2 1 1 | OutputYES2 | 2 seconds | 256 megabytes | ['dfs and similar', 'dp', 'dsu', 'graphs', 'implementation', 'trees', '*1600'] |
F. Tree nestingtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given two trees (connected undirected acyclic graphs) S and T.Count the number of subtrees (connected subgraphs) of S that are isomorphic to tree T. Since this number can get quite large, output ... | Input51 22 33 44 531 22 3 | Output3 | 2 seconds | 256 megabytes | ['combinatorics', 'graphs', 'trees', '*2800'] |
E. Radio stationstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputIn the lattice points of the coordinate line there are n radio stations, the i-th of which is described by three integers: xi — the coordinate of the i-th station on the line, ri — the broadcasting r... | Input3 21 3 103 2 54 10 8 | Output1 | 2 seconds | 256 megabytes | ['binary search', 'data structures', '*2200'] |
D. Maximum pathtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a rectangular table 3 × n. Each cell contains an integer. You can move from one cell to another if they share a side.Find such path from the upper left cell to the bottom right cell of the t... | Input31 1 11 -1 11 1 1 | Output7 | 1 second | 256 megabytes | ['dp', 'greedy', 'implementation', '*2300'] |
C. Two stringstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given two strings a and b. You have to remove the minimum possible number of consecutive (standing one after another) characters from string b in such a way that it becomes a subsequence of string... | Inputhibob | Output- | 2 seconds | 256 megabytes | ['binary search', 'hashing', 'strings', 'two pointers', '*2100'] |
B. USB vs. PS/2time limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputDue to the increase in the number of students of Berland State University it was decided to equip a new computer room. You were given the task of buying mouses, and you have to spend as little as possibl... | Input2 1 145 USB6 PS/23 PS/27 PS/2 | Output3 14 | 2 seconds | 256 megabytes | ['greedy', 'implementation', 'sortings', 'two pointers', '*1400'] |
A. k-th divisortime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given two integers n and k. Find k-th smallest divisor of n, or report that it doesn't exist.Divisor of n is any such natural number, that n can be divided by it without remainder.InputThe first ... | Input4 2 | Output2 | 2 seconds | 256 megabytes | ['math', 'number theory', '*1400'] |
F. Dasha and Photostime limit per test4 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputDasha decided to have a rest after solving the problem D and began to look photos from previous competitions.Let's call photos as the matrix with the size n × m, which consists of lowercase English l... | Input3 3 2aaaaaaaaa1 1 2 2 b2 2 3 3 c | Output10 | 4 seconds | 512 megabytes | ['brute force', 'data structures', 'dp', 'implementation', '*2600'] |
E. Dasha and Puzzletime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputDasha decided to have a rest after solving the problem. She had been ready to start her favourite activity — origami, but remembered the puzzle that she could not solve. The tree is a non-oriented ... | Input71 21 32 42 53 63 7 | OutputYES0 01 00 12 01 -1-1 10 2 | 2 seconds | 256 megabytes | ['constructive algorithms', 'dfs and similar', 'graphs', 'greedy', 'trees', '*2000'] |
D. Dasha and Very Difficult Problemtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputDasha logged into the system and began to solve problems. One of them is as follows:Given two sequences a and b of length n each you need to write a sequence c of length n, the i-th e... | Input5 1 51 1 1 1 13 1 5 4 2 | Output3 1 5 4 2 | 2 seconds | 256 megabytes | ['binary search', 'brute force', 'constructive algorithms', 'greedy', 'sortings', '*1700'] |
C. Dasha and Passwordtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputAfter overcoming the stairs Dasha came to classes. She needed to write a password to begin her classes. The password is a string of length n which satisfies the following requirements: There is at... | Input3 41**2a3*0c4** | Output1 | 2 seconds | 256 megabytes | ['brute force', 'dp', 'implementation', '*1500'] |
B. Dasha and friendstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputRunning with barriers on the circle track is very popular in the country where Dasha lives, so no wonder that on her way to classes she saw the following situation:The track is the circle with lengt... | Input3 82 4 61 5 7 | OutputYES | 2 seconds | 256 megabytes | ['brute force', 'implementation', 'math', '*1300'] |
A. Dasha and Stairstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputOn her way to programming school tiger Dasha faced her first test — a huge staircase! The steps were numbered from one to infinity. As we know, tigers are very fond of all striped things, it is poss... | Input2 3 | OutputYES | 2 seconds | 256 megabytes | ['brute force', 'constructive algorithms', 'implementation', 'math', '*1000'] |
B. Frodo and pillowstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputn hobbits are planning to spend the night at Frodo's house. Frodo has n beds standing in a row and m pillows (n ≤ m). Each hobbit needs a bed and at least one pillow to sleep, however, everyone wants... | Input4 6 2 | Output2 | 1 second | 256 megabytes | ['binary search', 'greedy', '*1500'] |
A. Petr and a calendartime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputPetr wants to make a calendar for current month. For this purpose he draws a table in which columns correspond to weeks (a week is seven consequent days from Monday to Sunday), rows correspond to ... | Input1 7 | Output6 | 2 seconds | 256 megabytes | ['implementation', 'math', '*800'] |
F. Geometrical Progressiontime limit per test4 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputFor given n, l and r find the number of distinct geometrical progression, each of which contains n distinct integers not less than l and not greater than r. In other words, for each progressio... | Input1 1 10 | Output10 | 4 seconds | 256 megabytes | ['brute force', 'math', 'number theory', '*2400'] |
E. Broken Treetime limit per test4 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a tree that has n vertices, which are numbered from 1 to n, where the vertex number one is the root. Each edge has weight wi and strength pi.Botanist Innokentiy, who is the only member of th... | Input31 3 5 73 2 4 3 | Output31 3 5 73 2 4 3 | 4 seconds | 256 megabytes | ['dfs and similar', 'dp', 'graphs', 'greedy', 'trees', '*2600'] |
D. Ability To Converttime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputAlexander is learning how to convert numbers from the decimal system to any other, however, he doesn't know English letters, so he writes any number only as a decimal number, it means that instead o... | Input1312 | Output12 | 1 second | 256 megabytes | ['constructive algorithms', 'dp', 'greedy', 'math', 'strings', '*2000'] |
C. Unfair Polltime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputOn the Literature lesson Sergei noticed an awful injustice, it seems that some students are asked more often than others.Seating in the class looks like a rectangle, where n rows with m pupils in each. The... | Input1 3 8 1 1 | Output3 2 3 | 1 second | 256 megabytes | ['binary search', 'constructive algorithms', 'implementation', 'math', '*1700'] |
B. Blown Garlandtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputNothing is eternal in the world, Kostya understood it on the 7-th of January when he saw partially dead four-color garland.Now he has a goal to replace dead light bulbs, however he doesn't know how many ... | InputRYBGRYBGR | Output0 0 0 0 | 1 second | 256 megabytes | ['brute force', 'implementation', 'number theory', '*1100'] |
A. Holiday Of Equalitytime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputIn Berland it is the holiday of equality. In honor of the holiday the king decided to equalize the welfare of all citizens in Berland by the expense of the state treasury. Totally in Berland there ... | Input50 1 2 3 4 | Output10 | 1 second | 256 megabytes | ['implementation', 'math', '*800'] |
G. Can Bash Save the Day?time limit per test5 secondsmemory limit per test768 megabytesinputstandard inputoutputstandard outputWhoa! You did a great job helping Team Rocket who managed to capture all the Pokemons sent by Bash. Meowth, part of Team Rocket, having already mastered the human language, now wants to become ... | Input5 54 5 1 3 24 2 41 3 94 1 44 5 211 5 4122 20 20238239136 38 38 | Output233728 | 5 seconds | 768 megabytes | ['data structures', 'divide and conquer', 'graphs', 'trees', '*3400'] |
F. Team Rocket Rises Againtime limit per test2.5 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputIt's the turn of the year, so Bash wants to send presents to his friends. There are n cities in the Himalayan region and they are connected by m bidirectional roads. Bash is living in city s... | Input4 4 31 2 12 3 12 4 13 1 1 | Output2 | 2.5 seconds | 512 megabytes | ['data structures', 'graphs', 'shortest paths', '*2800'] |
E. Bash Plays with Functionstime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputBash got tired on his journey to become the greatest Pokemon master. So he decides to take a break and play with functions.Bash defines a function f0(n), which denotes the number of ways of ... | Input50 301 253 652 54 48 | Output85254630 | 3 seconds | 256 megabytes | ['brute force', 'combinatorics', 'dp', 'number theory', '*2500'] |
D. Felicity's Big Secret Revealedtime limit per test4 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputThe gym leaders were fascinated by the evolutions which took place at Felicity camp. So, they were curious to know about the secret behind evolving Pokemon. The organizers of the camp g... | Input41011 | Output10 | 4 seconds | 512 megabytes | ['bitmasks', 'dp', '*2200'] |
C. Felicity is Coming!time limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputIt's that time of the year, Felicity is around the corner and you can see people celebrating all around the Himalayan region. The Himalayan region has n gyms. The i-th gym has gi Pokemon in it. Th... | Input2 32 1 22 2 3 | Output1 | 2 seconds | 256 megabytes | ['data structures', 'hashing', 'sortings', 'strings', '*1900'] |
B. Bash's Big Daytime limit per test2 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputBash has set out on a journey to become the greatest Pokemon master. To get his first Pokemon, he went to Professor Zulu's Lab. Since Bash is Professor Zulu's favourite student, Zulu allows him to take... | Input32 3 4 | Output2 | 2 seconds | 512 megabytes | ['greedy', 'math', 'number theory', '*1400'] |
A. Gotta Catch Em' All!time limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputBash wants to become a Pokemon master one day. Although he liked a lot of Pokemon, he has always been fascinated by Bulbasaur the most. Soon, things started getting serious and his fascination tur... | InputBulbbasaur | Output1 | 1 second | 256 megabytes | ['implementation', '*1000'] |
F. Long numbertime limit per test2 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputConsider the following grammar: <expression> ::= <term> | <expression> '+' <term> <term> ::= <number> | <number> '-' <number> | <number> '(' <expression> ')' <number> ::= <pos_digit> | <number> <digit> <d... | Input8-11 | Output891011 | 2 seconds | 512 megabytes | ['expression parsing', 'math', 'number theory', '*3400'] |
E. Byteland coinstime limit per test1 secondmemory limit per test512 megabytesinputstandard inputoutputstandard outputThere are n types of coins in Byteland. Conveniently, the denomination of the coin type k divides the denomination of the coin type k + 1, the denomination of the coin type 1 equals 1 tugrick. The ratio... | Input142 | Output1 | 1 second | 512 megabytes | ['combinatorics', 'dp', 'math', '*3200'] |
D. Bacterial Meleetime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputJulia is conducting an experiment in her lab. She placed several luminescent bacterial colonies in a horizontal testtube. Different types of bacteria can be distinguished by the color of light they em... | Input3aaa | Output1 | 2 seconds | 256 megabytes | ['brute force', 'combinatorics', 'dp', 'string suffix structures', '*2400'] |
C. Nikita and stacktime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputNikita has a stack. A stack in this problem is a data structure that supports two operations. Operation push(x) puts an integer x on the top of the stack, and operation pop() deletes the top integer ... | Input22 1 21 0 | Output22 | 2 seconds | 256 megabytes | ['data structures', '*2200'] |
B. Travel Cardtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputA new innovative ticketing systems for public transport is introduced in Bytesburg. Now there is a single travel card for all transport. To make a trip a passenger scan his card and then he is charged acc... | Input3102030 | Output202010 | 2 seconds | 256 megabytes | ['binary search', 'dp', '*1600'] |
A. Pavel and barbecuetime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputPavel cooks barbecue. There are n skewers, they lay on a brazier in a row, each on one of n positions. Pavel wants each skewer to be cooked some time in every of n positions in two directions: in t... | Input44 3 2 10 1 1 1 | Output2 | 2 seconds | 256 megabytes | ['constructive algorithms', 'dfs and similar', '*1700'] |
G. PolandBall and Many Other Ballstime limit per test6 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputPolandBall is standing in a row with Many Other Balls. More precisely, there are exactly n Balls. Balls are proud of their home land — and they want to prove that it's strong.The Balls... | Input3 3 | Output5 5 1 | 6 seconds | 256 megabytes | ['combinatorics', 'divide and conquer', 'dp', 'fft', 'math', 'number theory', '*3200'] |
F. PolandBall and Giftstime limit per test1.5 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputIt's Christmas time! PolandBall and his friends will be giving themselves gifts. There are n Balls overall. Each Ball has someone for whom he should bring a present according to some permutatio... | Input5 23 4 1 5 2 | Output2 4 | 1.5 seconds | 256 megabytes | ['bitmasks', 'dp', 'greedy', '*2600'] |
E. PolandBall and White-Red graphtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputPolandBall has an undirected simple graph consisting of n vertices. Unfortunately, it has no edges. The graph is very sad because of that. PolandBall wanted to make it happier, adding s... | Input4 1 | Output-1 | 2 seconds | 256 megabytes | ['constructive algorithms', 'graphs', 'shortest paths', '*2400'] |
D. PolandBall and Polygontime limit per test4 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputPolandBall has such a convex polygon with n veritces that no three of its diagonals intersect at the same point. PolandBall decided to improve it and draw some red segments. He chose a number k... | Input5 2 | Output2 3 5 8 11 | 4 seconds | 256 megabytes | ['data structures', '*2000'] |
C. PolandBall and Foresttime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputPolandBall lives in a forest with his family. There are some trees in the forest. Trees are undirected acyclic graphs with k vertices and k - 1 edges, where k is some integer. Note that one verte... | Input52 1 5 3 3 | Output2 | 1 second | 256 megabytes | ['dfs and similar', 'dsu', 'graphs', 'interactive', 'trees', '*1300'] |
B. PolandBall and Gametime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputPolandBall is playing a game with EnemyBall. The rules are simple. Players have to say words in turns. You cannot say a word which was already said. PolandBall starts. The Ball which can't say a ne... | Input5 1polandballisacoolcharacternope | OutputYES | 1 second | 256 megabytes | ['binary search', 'data structures', 'games', 'greedy', 'sortings', 'strings', '*1100'] |
A. PolandBall and Hypothesistime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputPolandBall is a young, clever Ball. He is interested in prime numbers. He has stated a following hypothesis: "There exists such a positive integer n that for each positive integer m number n... | Input3 | Output1 | 2 seconds | 256 megabytes | ['brute force', 'graphs', 'math', 'number theory', '*800'] |
E. Dasha and cyclic tabletime limit per test6 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputDasha is fond of challenging puzzles: Rubik's Cube 3 × 3 × 3, 4 × 4 × 4, 5 × 5 × 5 and so on. This time she has a cyclic table of size n × m, and each cell of the table contains a lowercase Eng... | Input5 7qcezchshhedywqwikywqyqckrqztbqexcxz3 2??yw?q | Output00001000001001000000000000000000000 | 6 seconds | 512 megabytes | ['bitmasks', 'brute force', 'fft', 'strings', 'trees', '*2600'] |
D. Fedor and couponstime limit per test4 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputAll our characters have hobbies. The same is true for Fedor. He enjoys shopping in the neighboring supermarket. The goods in the supermarket have unique integer ids. Also, for every integer there is... | Input4 21 10040 70120 130125 180 | Output311 2 | 4 seconds | 256 megabytes | ['binary search', 'data structures', 'greedy', 'sortings', '*2100'] |
C. Vladik and chattime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputRecently Vladik discovered a new entertainment — coding bots for social networks. He would like to use machine learning in his bots so now he want to prepare some learning data for them.At first, he n... | Input12Vladik netman2?: Hello, Vladik!?: Hi | Outputnetman: Hello, Vladik!Vladik: Hi | 2 seconds | 256 megabytes | ['brute force', 'constructive algorithms', 'dp', 'implementation', 'strings', '*2200'] |
B. Ilya and tic-tac-toe gametime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputIlya is an experienced player in tic-tac-toe on the 4 × 4 field. He always starts and plays with Xs. He played a lot of games today with his friend Arseny. The friends became tired and didn'... | Inputxx...oo.x...oox. | OutputYES | 2 seconds | 256 megabytes | ['brute force', 'implementation', '*1100'] |
A. Lesha and array splittingtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputOne spring day on his way to university Lesha found an array A. Lesha likes to split arrays into several parts. This time Lesha decided to split the array A into several, possibly one, new a... | Input31 2 -3 | OutputYES21 23 3 | 2 seconds | 256 megabytes | ['constructive algorithms', 'greedy', 'implementation', '*1200'] |
C. Interactive Bulls and Cows (Hard)time limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe only difference from the previous problem is the constraint on the number of requests. In this problem your program should guess the answer doing at most 7 requests.This problem ... | Input0 12 01 10 42 14 0 | Output800001793159321001120123 | 2 seconds | 256 megabytes | ['brute force', 'constructive algorithms', 'interactive', '*2500'] |
B. Interactive Bulls and Cows (Easy)time limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThis problem is a little bit unusual. Here you are to implement an interaction with a testing system. That means that you can make queries and get responses in the online mode. Pleas... | Input0 12 01 10 42 14 0 | Output800001793159321001120123 | 2 seconds | 256 megabytes | ['brute force', 'constructive algorithms', 'implementation', '*1600'] |
A. Santa Claus and Candiestime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputSanta Claus has n candies, he dreams to give them as gifts to children.What is the maximal number of children for whose he can give candies if Santa Claus want each kid should get distinct posi... | Input5 | Output22 3 | 1 second | 256 megabytes | ['dp', 'greedy', 'math', '*1000'] |
H. New Year and Snowy Gridtime limit per test9 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputPay attention to the output section below, where you will see the information about flushing the output.Bearland is a grid with h rows and w columns. Rows are numbered 1 through h from top to ... | Input3 5 4...........#...11 411 522 43 121 53 3 | OutputNOYESYESNO | 9 seconds | 256 megabytes | ['dfs and similar', 'dsu', 'graphs', 'interactive', '*3500'] |
G. New Year and Binary Tree Pathstime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe New Year tree is an infinite perfect binary tree rooted in the node 1. Each node v has two children: nodes indexed (2·v) and (2·v + 1). Polar bears love decorating the New Year tre... | Input10 | Output4 | 3 seconds | 256 megabytes | ['bitmasks', 'brute force', 'combinatorics', 'dp', '*3200'] |
F. New Year and Finding Rootstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThis is an interactive problem. In the interaction section below you will find the information about flushing the output.The New Year tree of height h is a perfect binary tree with vertices... | Input1334 5 721 212 | Output? 1? 5? 6! 5 | 2 seconds | 256 megabytes | ['constructive algorithms', 'implementation', 'interactive', 'trees', '*2800'] |
E. New Year and Old Subsequencetime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputA string t is called nice if a string "2017" occurs in t as a subsequence but a string "2016" doesn't occur in t as a subsequence. For example, strings "203434107" and "9220617" are nice,... | Input8 3201667661 81 72 8 | Output43-1 | 3 seconds | 256 megabytes | ['data structures', 'divide and conquer', 'dp', 'matrices', '*2600'] |
D. New Year and Fireworkstime limit per test2.5 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputOne tradition of welcoming the New Year is launching fireworks into the sky. Usually a launched firework flies vertically upward for some period of time, then explodes, splitting into several... | Input44 2 2 3 | Output39 | 2.5 seconds | 256 megabytes | ['brute force', 'data structures', 'dfs and similar', 'dp', 'implementation', '*1900'] |
C. New Year and Ratingtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputEvery Codeforces user has rating, described with one integer, possibly negative or zero. Users are divided into two divisions. The first division is for users with rating 1900 or higher. Those wit... | Input3-7 15 28 2 | Output1907 | 2 seconds | 256 megabytes | ['binary search', 'greedy', 'math', '*1600'] |
B. New Year and North Poletime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputIn this problem we assume the Earth to be a completely round ball and its surface a perfect sphere. The length of the equator and any meridian is considered to be exactly 40 000 kilometers. Th... | Input57500 South10000 East3500 North4444 West4000 North | OutputYES | 2 seconds | 256 megabytes | ['geometry', 'implementation', '*1300'] |
A. New Year and Hurrytime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputLimak is going to participate in a contest on the last day of the 2016. The contest will start at 20:00 and will last four hours, exactly until midnight. There will be n problems, sorted by difficul... | Input3 222 | Output2 | 1 second | 256 megabytes | ['binary search', 'brute force', 'implementation', 'math', '*800'] |
E. Inversions After Shuffletime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a permutation of integers from 1 to n. Exactly once you apply the following operation to this permutation: pick a random segment and shuffle its elements. Formally: Pick a rando... | Input32 3 1 | Output1.916666666666666666666666666667 | 1 second | 256 megabytes | ['data structures', 'probabilities', '*2400'] |
D. Leaving Auctiontime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere are n people taking part in auction today. The rules of auction are classical. There were n bids made, though it's not guaranteed they were from different people. It might happen that some peopl... | Input61 102 1003 10001 100002 1000003 100000031 32 2 32 1 2 | Output2 1000001 103 1000 | 2 seconds | 256 megabytes | ['binary search', 'data structures', '*2000'] |
C. Votingtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere are n employees in Alternative Cake Manufacturing (ACM). They are now voting on some very important question and the leading world media are trying to predict the outcome of the vote.Each of the employees... | Input5DDRRR | OutputD | 1 second | 256 megabytes | ['greedy', 'implementation', 'two pointers', '*1500'] |
B. Parallelogram is Backtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputLong time ago Alex created an interesting problem about parallelogram. The input data for this problem contained four integer points on the Cartesian plane, that defined the set of vertices of so... | Input0 01 00 1 | Output31 -1-1 11 1 | 1 second | 256 megabytes | ['brute force', 'constructive algorithms', 'geometry', '*1200'] |
A. Bachgold Problemtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputBachgold problem is very easy to formulate. Given a positive integer n represent it as a sum of maximum possible number of prime numbers. One can prove that such representation exists for any integer ... | Input5 | Output22 3 | 1 second | 256 megabytes | ['greedy', 'implementation', 'math', 'number theory', '*800'] |
F. Santa Clauses and a Soccer Championshiptime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe country Treeland consists of n cities connected with n - 1 bidirectional roads in such a way that it's possible to reach every city starting from any other city using these... | Input6 21 21 32 42 53 62 5 4 6 | Output125 4 26 2 2 | 2 seconds | 256 megabytes | ['constructive algorithms', 'dfs and similar', 'graphs', 'trees', '*2300'] |
E. Santa Claus and Tangerinestime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputSanta Claus has n tangerines, and the i-th of them consists of exactly ai slices. Santa Claus came to a school which has k pupils. Santa decided to treat them with tangerines.However, there... | Input3 25 9 3 | Output5 | 2 seconds | 256 megabytes | ['binary search', 'data structures', 'greedy', 'two pointers', '*2100'] |
D. Santa Claus and a Palindrometime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputSanta Claus likes palindromes very much. There was his birthday recently. k of his friends came to him to congratulate him, and each of them presented to him a string si having the same l... | Input7 3abb 2aaa -3bba -1zyz -4abb 5aaa 7xyx 4 | Output12 | 2 seconds | 256 megabytes | ['constructive algorithms', 'data structures', 'greedy', '*2100'] |
C. Santa Claus and Robottime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputSanta Claus has Robot which lives on the infinite grid and can move along its lines. He can also, having a sequence of m points p1, p2, ..., pm with integer coordinates, do the following: denote... | Input4RURD | Output2 | 2 seconds | 256 megabytes | ['constructive algorithms', 'math', '*1400'] |
B. Santa Claus and Keyboard Checktime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputSanta Claus decided to disassemble his keyboard to clean it. After he returned all the keys back, he suddenly realized that some pairs of keys took each other's place! That is, Santa su... | Inputhelloworldehoolwlroz | Output3h el od z | 2 seconds | 256 megabytes | ['implementation', 'strings', '*1500'] |
A. Santa Claus and a Place in a Classtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputSanta Claus is the first who came to the Christmas Olympiad, and he is going to be the first to take his place at a desk! In the classroom there are n lanes of m desks each, and the... | Input4 3 9 | Output2 2 L | 2 seconds | 256 megabytes | ['implementation', 'math', '*800'] |
F. Igor and Interesting Numberstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputIgor likes hexadecimal notation and considers positive integer in the hexadecimal notation interesting if each digit and each letter in it appears no more than t times. For example, if t ... | Input17 1 | Output12 | 2 seconds | 256 megabytes | ['brute force', 'combinatorics', 'dp', 'math', '*2500'] |
E. Commentstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputA rare article in the Internet is posted without a possibility to comment it. On a Polycarp's website each article has comments feed.Each comment on Polycarp's website is a non-empty string consisting of upp... | Inputhello,2,ok,0,bye,0,test,0,one,1,two,2,a,0,b,0 | Output3hello test one ok bye two a b | 2 seconds | 256 megabytes | ['dfs and similar', 'expression parsing', 'implementation', 'strings', '*1700'] |
D. Winter Is Comingtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe winter in Berland lasts n days. For each day we know the forecast for the average air temperature that day. Vasya has a new set of winter tires which allows him to drive safely no more than k days... | Input4 3-5 20 -3 0 | Output2 | 1 second | 256 megabytes | ['dp', 'greedy', 'sortings', '*1800'] |
C. Serverstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere are n servers in a laboratory, each of them can perform tasks. Each server has a unique id — integer from 1 to n.It is known that during the day q tasks will come, the i-th of them is characterized with... | Input4 31 3 22 2 13 4 3 | Output6-110 | 2 seconds | 256 megabytes | ['implementation', '*1300'] |
B. Mammoth's Genome Decodingtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe process of mammoth's genome decoding in Berland comes to its end!One of the few remaining tasks is to restore unrecognized nucleotides in a found chain s. Each nucleotide is coded with a ... | Input8AG?C??CT | OutputAGACGTCT | 1 second | 256 megabytes | ['implementation', 'strings', '*900'] |
A. Display Sizetime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputA big company decided to launch a new series of rectangular displays, and decided that the display must have exactly n pixels. Your task is to determine the size of the rectangular display — the number of... | Input8 | Output2 4 | 1 second | 256 megabytes | ['brute force', 'math', '*800'] |
G. New Roadstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere are n cities in Berland, each of them has a unique id — an integer from 1 to n, the capital is the one with id 1. Now there is a serious problem in Berland with roads — there are no roads.That is why ... | Input7 3 32 3 1 | Output71 32 12 62 47 43 5 | 2 seconds | 256 megabytes | ['constructive algorithms', 'graphs', 'trees', '*2100'] |
F. Music in Cartime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputSasha reaches the work by car. It takes exactly k minutes. On his way he listens to music. All songs in his playlist go one by one, after listening to the i-th song Sasha gets a pleasure which equals ai. ... | Input7 2 113 4 3 5 1 4 67 7 3 6 5 3 9 | Output12 | 1 second | 256 megabytes | ['data structures', 'greedy', 'two pointers', '*2200'] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.