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 |
|---|---|---|---|---|---|
E. Wavy numberstime limit per test1.5 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputA wavy number is such positive integer that for any digit of its decimal representation except for the first one and the last one following condition holds: the digit is either strictly larger than bot... | Input123 4 | Output1845 | 1.5 seconds | 256 megabytes | ['brute force', 'dfs and similar', 'meet-in-the-middle', 'sortings', '*2900'] |
D. Red-Green Towerstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere are r red and g green blocks for construction of the red-green tower. Red-green tower can be built following next rules: Red-green tower is consisting of some number of levels; Let the red-gr... | Input4 6 | Output2 | 2 seconds | 256 megabytes | ['dp', '*2000'] |
C. Table Decorationstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou have r red, g green and b blue balloons. To decorate a single table for the banquet you need exactly three balloons. Three balloons attached to some table shouldn't have the same color. What maxi... | Input5 4 3 | Output4 | 1 second | 256 megabytes | ['greedy', '*1800'] |
B. Random Teamstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputn participants of the competition were split into m teams in some manner so that each team has at least one participant. After the competition each pair of participants from the same team became friends.Y... | Input5 1 | Output10 10 | 1 second | 256 megabytes | ['combinatorics', 'constructive algorithms', 'greedy', 'math', '*1300'] |
A. Initial Bettime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere are five people playing a game called "Generosity". Each person gives some non-zero number of coins b as an initial bet. After all players make their bets of b coins, the following operation is repea... | Input2 5 4 0 4 | Output3 | 1 second | 256 megabytes | ['implementation', '*1100'] |
E. Dreamoon and Notepadtime limit per test3.5 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputDreamoon has just created a document of hard problems using notepad.exe. The document consists of n lines of text, ai denotes the length of the i-th line. He now wants to know what is the faste... | Input91 3 5 3 1 3 5 3 143 5 3 13 3 7 31 0 3 36 0 7 3 | Output2532 | 3.5 seconds | 256 megabytes | ['data structures', '*3100'] |
D. Dreamoon and Binarytime limit per test2 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputDreamoon saw a large integer x written on the ground and wants to print its binary form out. Dreamoon has accomplished the part of turning x into its binary format. Now he is going to print it in ... | Input101 | Output16 | 2 seconds | 512 megabytes | ['dp', 'strings', '*2700'] |
E. Dreamoon and Stringstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputDreamoon has a string s and a pattern string p. He first removes exactly x characters from s obtaining string s' as a result. Then he calculates that is defined as the maximal number of non-overl... | Inputaaaaaaa | Output2 2 1 1 0 0 | 1 second | 256 megabytes | ['dp', 'strings', '*2200'] |
D. Dreamoon and Setstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputDreamoon likes to play with sets, integers and . is defined as the largest positive integer that divides both a and b.Let S be a set of exactly four distinct integers greater than 0. Define S to be ... | Input1 1 | Output51 2 3 5 | 1 second | 256 megabytes | ['constructive algorithms', 'greedy', 'math', '*1900'] |
C. Dreamoon and Sumstime limit per test1.5 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputDreamoon loves summing up something for no reason. One day he obtains two integers a and b occasionally. He wants to calculate the sum of all nice integers. Positive integer x is called nice if a... | Input1 1 | Output0 | 1.5 seconds | 256 megabytes | ['math', '*1600'] |
B. Dreamoon and WiFitime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputDreamoon is standing at the position 0 on a number line. Drazil is sending a list of commands through Wi-Fi to Dreamoon's smartphone and Dreamoon follows them.Each command is one of the following two... | Input++-+-+-+-+ | Output1.000000000000 | 1 second | 256 megabytes | ['bitmasks', 'brute force', 'combinatorics', 'dp', 'math', 'probabilities', '*1300'] |
A. Dreamoon and Stairstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputDreamoon wants to climb up a stair of n steps. He can climb 1 or 2 steps at each move. Dreamoon wants the number of moves to be a multiple of an integer m. What is the minimal number of moves makin... | Input10 2 | Output6 | 1 second | 256 megabytes | ['implementation', 'math', '*1000'] |
F. Meta-universetime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputConsider infinite grid of unit cells. Some of those cells are planets. Meta-universe Mβ=β{p1,βp2,β...,βpk} is a set of planets. Suppose there is an infinite row or column with following two properties: ... | Input50 00 22 02 12 2 | Output3 | 2 seconds | 256 megabytes | ['data structures', '*2900'] |
E. Strongly Connected City 2time limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputImagine a city with n junctions and m streets. Junctions are numbered from 1 to n.In order to increase the traffic flow, mayor of the city has decided to make each street one-way. This means... | Input5 41 21 31 41 5 | Output13 | 2 seconds | 256 megabytes | ['dfs and similar', '*2700'] |
D. CGCDSSQtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputGiven a sequence of integers a1,β...,βan and q queries x1,β...,βxq on it. For each query xi you have to count the number of pairs (l,βr) such that 1ββ€βlββ€βrββ€βn and gcd(al,βalβ+β1,β...,βar)β=βxi. is a greates... | Input32 6 3512346 | Output12201 | 2 seconds | 256 megabytes | ['brute force', 'data structures', 'math', '*2000'] |
C. Kamal-ol-molk's Paintingtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputRumors say that one of Kamal-ol-molk's paintings has been altered. A rectangular brush has been moved right and down on the painting.Consider the painting as a nβΓβm rectangular grid. At the ... | Input4 4XX..XX..XXXXXXXX | Output4 | 2 seconds | 256 megabytes | ['brute force', 'constructive algorithms', 'greedy', '*2100'] |
B. Strongly Connected Citytime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputImagine a city with n horizontal streets crossing m vertical streets, forming an (nβ-β1)βΓβ(mβ-β1) grid. In order to increase the traffic flow, mayor of the city has decided to make each stree... | Input3 3><>v^v | OutputNO | 2 seconds | 256 megabytes | ['brute force', 'dfs and similar', 'graphs', 'implementation', '*1400'] |
A. Bayan Bustime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe final round of Bayan Programming Contest will be held in Tehran, and the participants will be carried around with a yellow bus. The bus has 34 passenger seats: 4 seats in the last row and 3 seats in rem... | Input9 | Output+------------------------+|O.O.O.#.#.#.#.#.#.#.#.|D|)|O.O.O.#.#.#.#.#.#.#.#.|.||O.......................||O.O.#.#.#.#.#.#.#.#.#.|.|)+------------------------+ | 2 seconds | 256 megabytes | ['implementation', '*1100'] |
F. Ant colonytime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputMole is hungry again. He found one ant colony, consisting of n ants, ordered in a row. Each ant i (1ββ€βiββ€βn) has a strength si.In order to make his dinner more interesting, Mole organizes a version of Β«Hun... | Input51 3 2 4 241 52 53 54 5 | Output4411 | 1 second | 256 megabytes | ['data structures', 'math', 'number theory', '*2100'] |
E. Pillarstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputMarmot found a row with n pillars. The i-th pillar has the height of hi meters. Starting from one pillar i1, Marmot wants to jump on the pillars i2, ..., ik. (1ββ€βi1β<βi2β<β...β<βikββ€βn). From a pillar i Marmo... | Input5 21 3 6 7 4 | Output41 2 3 5 | 1 second | 256 megabytes | ['binary search', 'data structures', 'dp', 'sortings', 'trees', '*2000'] |
D. Flowerstime limit per test1.5 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputWe saw the little game Marmot made for Mole's lunch. Now it's Marmot's dinner time and, as we all know, Marmot eats flowers. At every dinner he eats some red and white flowers. Therefore a dinner can be rep... | Input3 21 32 34 4 | Output655 | 1.5 seconds | 256 megabytes | ['dp', '*1700'] |
C. Captain Marmottime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputCaptain Marmot wants to prepare a huge and important battle against his enemy, Captain Snake. For this battle he has n regiments, each consisting of 4 moles.Initially, each mole i (1ββ€βiββ€β4n) is placed... | Input41 1 0 0-1 1 0 0-1 1 0 01 -1 0 01 1 0 0-2 1 0 0-1 1 0 01 -1 0 01 1 0 0-1 1 0 0-1 1 0 0-1 1 0 02 2 0 1-1 0 0 -23 0 0 -2-1 1 -2 0 | Output1-133 | 1 second | 256 megabytes | ['brute force', 'geometry', '*2000'] |
B. Wormstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputIt is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive i... | Input52 7 3 4 931 25 11 | Output153 | 1 second | 256 megabytes | ['binary search', 'implementation', '*1200'] |
A. Keyboardtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputOur good friend Mole is trying to code a big message. He is typing on an unusual keyboard with characters arranged in following way:qwertyuiopasdfghjkl;zxcvbnm,./Unfortunately Mole is blind, so sometimes it ... | InputRs;;upimrrfod;pbr | Outputallyouneedislove | 2 seconds | 256 megabytes | ['implementation', '*900'] |
G. Design Tutorial: Increase the Constraintstime limit per test7 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere is a simple way to create hard tasks: take one simple problem as the query, and try to find an algorithm that can solve it faster than bruteforce. This kind of tasks us... | Input1010101111000030 0 32 3 45 7 1 | Output110 | 7 seconds | 256 megabytes | ['bitmasks', 'data structures', 'fft', '*2800'] |
F. Design Tutorial: Change the Goaltime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere are some tasks which have the following structure: you are given a model, and you can do some operations, you should use these operations to achive the goal. One way to create a... | Input23 56 0 | Output21 22 2 | 2 seconds | 256 megabytes | ['constructive algorithms', 'math', 'matrices', '*2700'] |
E. Design Tutorial: Learn from a Gametime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputOne way to create task is to learn from game. You should pick a game and focus on part of the mechanic of that game, then it might be a good task.Let's have a try. Puzzle and Dragon ... | Input2 21 32 31 33 2 | Output31 12 22 11 1 | 1 second | 256 megabytes | ['constructive algorithms', 'implementation', '*2800'] |
D. Design Tutorial: Inverse the Problemtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere is an easy way to obtain a new task from an old one called "Inverse the problem": we give an output of the original task, and ask to generate an input, such that solution to... | Input30 2 72 0 97 9 0 | OutputYES | 2 seconds | 256 megabytes | ['dfs and similar', 'dsu', 'shortest paths', 'trees', '*1900'] |
C. Design Tutorial: Make It Nondeterministictime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputA way to make a new task is to make it nondeterministic or probabilistic. For example, the hard task of Topcoder SRM 595, Constellation, is the probabilistic version of a con... | Input3gennady korotkevichpetr mitrichevgaoyuan chen1 2 3 | OutputNO | 2 seconds | 256 megabytes | ['greedy', '*1400'] |
B. Design Tutorial: Learn from Lifetime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputOne way to create a task is to learn from life. You can choose some experience in real life, formalize it and then you will get a new task.Let's think about a scene in real life: there... | Input3 22 3 4 | Output8 | 1 second | 256 megabytes | ['*1300'] |
A. Design Tutorial: Learn from Mathtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputOne way to create a task is to learn from math. You can generate some random math statement or modify some theorems to get something new and build a new task from that.For example, the... | Input12 | Output4 8 | 1 second | 256 megabytes | ['math', 'number theory', '*800'] |
E. MUH and Lots and Lots of Segmentstime limit per test2 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputPolar bears Menshykov and Uslada from the zoo of St. Petersburg and elephant Horace from the zoo of Kiev decided to do some painting. As they were trying to create their first master... | Input20 0 0 11 0 1 1 | Output1 | 2 seconds | 512 megabytes | ['data structures', 'dsu', '*2700'] |
D. MUH and Cube Wallstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputPolar bears Menshykov and Uslada from the zoo of St. Petersburg and elephant Horace from the zoo of Kiev got hold of lots of wooden cubes somewhere. They started making cube towers by placing the c... | Input13 52 4 5 5 4 3 2 2 2 3 3 2 13 4 4 3 2 | Output2 | 2 seconds | 256 megabytes | ['string suffix structures', 'strings', '*1800'] |
C. MUH and House of Cardstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputPolar bears Menshykov and Uslada from the zoo of St. Petersburg and elephant Horace from the zoo of Kiev decided to build a house of cards. For that they've already found a hefty deck of n playi... | Input13 | Output1 | 1 second | 256 megabytes | ['binary search', 'brute force', 'greedy', 'math', '*1700'] |
B. MUH and Important Thingstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputIt's time polar bears Menshykov and Uslada from the zoo of St. Petersburg and elephant Horace from the zoo of Kiev got down to business. In total, there are n tasks for the day and each animal... | Input41 3 3 1 | OutputYES1 4 2 3 4 1 2 3 4 1 3 2 | 1 second | 256 megabytes | ['implementation', 'sortings', '*1300'] |
A. MUH and Stickstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputTwo polar bears Menshykov and Uslada from the St.Petersburg zoo and elephant Horace from the Kiev zoo got six sticks to play with and assess the animals' creativity. Menshykov, Uslada and Horace decided... | Input4 2 5 4 4 4 | OutputBear | 1 second | 256 megabytes | ['implementation', '*1100'] |
H. Array Sortingtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputSorting arrays is traditionally associated with high-level languages. How hard can it be in FALSE? Sort the given array in non-descending order.InputThe input consists of a single line of space-separate... | Input3 3 1 2 | Output1 2 3 | 2 seconds | 256 megabytes | ['*special problem', '*2300'] |
G. Hamming Distancetime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputHamming distance between two strings of equal length is the number of positions at which the corresponding symbols are different. You are given two strings; calculate the distance between them.InputT... | InputCODECHEFTOPCODER | Output6 | 2 seconds | 256 megabytes | ['*special problem', '*2300'] |
F. Pairwise Sumstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given an array of n integers. For each element output the sum of itself and the previous element. For the first element, output the sum of the first and the last elements of the array.InputThe i... | Input4 1 2 3 4 | Output5 3 5 7 | 2 seconds | 256 megabytes | ['*special problem', '*2300'] |
E. Chessboardtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputChessboard is a board of nβΓβn squares arranged in two alternating colors (black and white). Top left square is white. You are given board size n. Output an image of a chessboard, with black and white squa... | Input4 | Output.#.##.#..#.##.#. | 2 seconds | 256 megabytes | ['*special problem', '*1900'] |
D. Caesar Ciphertime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputCaesar cipher is one of the simplest encryption techniques. To transform the original message into encrypted one using key k, one has to replace each letter with a letter which is k positions later in t... | Input5CODEFORCES | OutputHTIJKTWHJX | 2 seconds | 256 megabytes | ['*special problem', '*1900'] |
C. Evaltime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a simple arithmetic expression of the form a?b, where a and b are integer constants, and ? can be one of the following operations: '+' (addition), '-' (subtraction), '*' (multiplication), '/' (inte... | Input123+456 | Output579 | 2 seconds | 256 megabytes | ['*special problem', '*1900'] |
B. Hexakosioihexekontahexaphobiatime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThis (unpronounceable) word means simply fear of number 666. You are given a string of digits. Check whether it is scary for a person suffering from this phobia, i.e., whether it contain... | Input123098 | OutputNO | 2 seconds | 256 megabytes | ['*special problem', '*1800'] |
A. Crystal Ball Sequencetime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputCrystal ball sequence on hexagonal lattice is defined as follows: n-th element is the number of lattice points inside a hexagon with (nβ+β1) points on each side. The formula is Hnβ=β3Β·nΒ·(nβ+β1)β... | Input1 | Output7 | 2 seconds | 256 megabytes | ['*special problem', 'implementation', '*1400'] |
B. Chat Onlinetime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputLittle X and Little Z are good friends. They always chat online. But both of them have schedules.Little Z has fixed schedule. He always online at any moment of time between a1 and b1, between a2 and b2, ..... | Input1 1 0 42 30 1 | Output3 | 1 second | 256 megabytes | ['implementation', '*1300'] |
A. I Wanna Be the Guytime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere is a game called "I Wanna Be the Guy", consisting of n levels. Little X and his friend Little Y are addicted to the game. Each of them wants to pass the whole game.Little X can pass only p lev... | Input43 1 2 32 2 4 | OutputI become the guy. | 1 second | 256 megabytes | ['greedy', 'implementation', '*800'] |
E. Permanenttime limit per test2 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputLittle X has solved the #P-complete problem in polynomial time recently. So he gives this task to you. There is a special nβΓβn matrix A, you should calculate its permanent modulo 1000000007Β (109β+β7). The ... | Input3 11 1 2 | Output8 | 2 seconds | 512 megabytes | ['dp', 'graph matchings', 'math', 'meet-in-the-middle', '*3100'] |
D. Treetime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputLittle X has a tree consisting of n nodes (they are numbered from 1 to n). Each edge of the tree has a positive length. Let's define the distance between two nodes v and u (we'll denote it d(v,βu)) as the sum of... | Input21 2 3 | Output62 1 | 2 seconds | 256 megabytes | ['graph matchings', '*3100'] |
C. Hack it!time limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputLittle X has met the following problem recently. Let's define f(x) as the sum of digits in decimal representation of number x (for example, f(1234)β=β1β+β2β+β3β+β4). You are to calculate Of course Little X ha... | Input46 | Output1 10 | 1 second | 256 megabytes | ['binary search', 'constructive algorithms', 'math', '*2500'] |
B. Two Setstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputLittle X has n distinct integers: p1,βp2,β...,βpn. He wants to divide all of them into two sets A and B. The following two conditions must be satisfied: If number x belongs to set A, then number aβ-βx must a... | Input4 5 92 3 4 5 | OutputYES0 0 1 1 | 1 second | 256 megabytes | ['2-sat', 'dfs and similar', 'dsu', 'graph matchings', 'greedy', '*2000'] |
A. 24 Gametime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputLittle X used to play a card game called "24 Game", but recently he has found it too easy. So he invented a new game.Initially you have a sequence of n integers: 1,β2,β...,βn. In a single step, you can pick tw... | Input1 | OutputNO | 1 second | 256 megabytes | ['constructive algorithms', 'greedy', 'math', '*1500'] |
E. Alex and Complicated Tasktime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputAfter you have read all the problems, probably, you think Alex is genius person. That's true! One day he came up with the following task.Given a sequence of integer numbers a1,βa2,β...,βan. ... | Input43 5 3 5 | Output43 5 3 5 | 2 seconds | 256 megabytes | ['data structures', 'dp', 'greedy', '*2300'] |
D. Fedor and Essaytime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputAfter you had helped Fedor to find friends in the Β«Call of Soldiers 3Β» game, he stopped studying completely. Today, the English teacher told him to prepare an essay. Fedor didn't want to prepare the e... | Input3AbRb r Zz4xR abRbaA xrzz Zxr y | Output2 6 | 2 seconds | 256 megabytes | ['dfs and similar', 'dp', 'graphs', 'hashing', 'strings', '*2400'] |
C. George and Jobtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe new ITone 6 has been released recently and George got really keen to buy it. Unfortunately, he didn't have enough money, so George was going to work as a programmer. Now he faced the following probl... | Input5 2 11 2 3 4 5 | Output9 | 1 second | 256 megabytes | ['dp', 'implementation', '*1700'] |
B. Fedor and New Gametime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputAfter you had helped George and Alex to move in the dorm, they went to help their friend Fedor play a new computer game Β«Call of Soldiers 3Β».The game has (mβ+β1) players and n types of soldiers in t... | Input7 3 18511117 | Output0 | 1 second | 256 megabytes | ['bitmasks', 'brute force', 'constructive algorithms', 'implementation', '*1100'] |
A. George and Accommodationtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputGeorge has recently entered the BSUCP (Berland State University for Cool Programmers). George has a friend Alex who has also entered the university. Now they are moving into a dormitory. Georg... | Input31 12 23 3 | Output0 | 1 second | 256 megabytes | ['implementation', '*800'] |
E. Information Graphtime limit per test1 secondmemory limit per test512 megabytesinputstandard inputoutputstandard outputThere are n employees working in company "X" (let's number them from 1 to n for convenience). Initially the employees didn't have any relationships among each other. On each of m next days one of the... | Input4 91 4 32 43 3 11 2 32 23 1 21 3 12 23 1 3 | OutputYESNOYES | 1 second | 512 megabytes | ['dfs and similar', 'dsu', 'graphs', 'trees', '*2100'] |
D. Increase Sequencetime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputPeter has a sequence of integers a1,βa2,β...,βan. Peter wants all numbers in the sequence to equal h. He can perform the operation of "adding one on the segment [l,βr]": add one to all elements of th... | Input3 21 1 1 | Output4 | 1 second | 256 megabytes | ['combinatorics', 'dp', '*2100'] |
C. Number of Waystime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou've got array a[1],βa[2],β...,βa[n], consisting of n integers. Count the number of ways to split all the elements of the array into three contiguous parts so that the sum of elements in each part is... | Input51 2 3 0 3 | Output2 | 2 seconds | 256 megabytes | ['binary search', 'brute force', 'data structures', 'dp', 'two pointers', '*1700'] |
B. Wonder Roomtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe start of the new academic year brought about the problem of accommodation students into dormitories. One of such dormitories has a aβΓβb square meter wonder room. The caretaker wants to accommodate exa... | Input3 3 5 | Output183 6 | 1 second | 256 megabytes | ['brute force', 'math', '*2000'] |
A. Cheap Traveltime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputAnn has recently started commuting by subway. We know that a one ride subway ticket costs a rubles. Besides, Ann found out that she can buy a special ticket for m rides (she can buy it several times). It ... | Input6 2 1 2 | Output6 | 1 second | 256 megabytes | ['implementation', '*1200'] |
B. Inbox (100500)time limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputOver time, Alexey's mail box got littered with too many letters. Some of them are read, while others are unread.Alexey's mail program can either show a list of all letters or show the content of a singl... | Input50 1 0 1 0 | Output3 | 1 second | 256 megabytes | ['implementation', '*1000'] |
A. inc ARGtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputSergey is testing a next-generation processor. Instead of bytes the processor works with memory cells consisting of n bits. These bits are numbered from 1 to n. An integer is stored in the cell in the followin... | Input41100 | Output3 | 1 second | 256 megabytes | ['implementation', '*900'] |
E. The Classic Problemtime limit per test5 secondsmemory limit per test768 megabytesinputstandard inputoutputstandard outputYou are given a weighted undirected graph on n vertices and m edges. Find the shortest path from vertex s to vertex t or else state that such path doesn't exist.InputThe first line of the input co... | Input4 41 4 21 2 02 3 03 4 01 4 | Output341 2 3 4 | 5 seconds | 768 megabytes | ['data structures', 'graphs', 'shortest paths', '*3000'] |
D. World of Darkraft - 2time limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputRoma found a new character in the game "World of Darkraft - 2". In this game the character fights monsters, finds the more and more advanced stuff that lets him fight stronger monsters.The chara... | Input1 3 | Output1.0000000000 | 2 seconds | 256 megabytes | ['dp', 'probabilities', '*2700'] |
C. Substitutes in Numbertime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputAndrew and Eugene are playing a game. Initially, Andrew has string s, consisting of digits. Eugene sends Andrew multiple queries of type "diβββti", that means "replace all digits di in string s w... | Input12312312->00 | Output10031003 | 1 second | 256 megabytes | ['dp', '*2100'] |
B. Restore Cube time limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputPeter had a cube with non-zero length of a side. He put the cube into three-dimensional space in such a way that its vertices lay at integer points (it is possible that the cube's sides are not parallel ... | Input0 0 00 0 10 0 10 0 10 1 10 1 10 1 11 1 1 | OutputYES0 0 00 0 10 1 01 0 00 1 11 0 11 1 01 1 1 | 1 second | 256 megabytes | ['brute force', 'geometry', '*2000'] |
A. No to Palindromes!time limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputPaul hates palindromes. He assumes that string s is tolerable if each its character is one of the first p letters of the English alphabet and s doesn't contain any palindrome contiguous substring of... | Input3 3cba | OutputNO | 1 second | 256 megabytes | ['greedy', 'strings', '*1700'] |
E. Caisa and Treetime limit per test10 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputCaisa is now at home and his son has a simple task for him.Given a rooted tree with n vertices, numbered from 1 to n (vertex 1 is the root). Each vertex of the tree has a value. You should answer q qu... | Input4 610 8 4 31 22 33 41 11 21 31 42 1 91 4 | Output-112-11 | 10 seconds | 256 megabytes | ['brute force', 'dfs and similar', 'math', 'number theory', 'trees', '*2100'] |
D. Gargari and Permutationstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputGargari got bored to play with the bishops and now, after solving the problem about them, he is trying to do math homework. In a math book he have found k permutations. Each of them consists ... | Input4 31 4 2 34 1 2 31 2 4 3 | Output3 | 2 seconds | 256 megabytes | ['dfs and similar', 'dp', 'graphs', 'implementation', '*1900'] |
C. Gargari and Bishopstime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputGargari is jealous that his friend Caisa won the game from the previous problem. He wants to prove that he is a genius.He has a nβΓβn chessboard. Each cell of the chessboard has a number written o... | Input41 1 1 12 1 1 01 1 1 01 0 0 1 | Output122 2 3 2 | 3 seconds | 256 megabytes | ['greedy', 'hashing', 'implementation', '*1900'] |
B. Caisa and Pylonstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputCaisa solved the problem with the sugar and now he is on the way back to home. Caisa is playing a mobile game during his path. There are (nβ+β1) pylons numbered from 0 to n in this game. The pylon wit... | Input53 4 3 2 4 | Output4 | 1 second | 256 megabytes | ['brute force', 'implementation', 'math', '*1100'] |
A. Caisa and Sugartime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputCaisa is going to have a party and he needs to buy the ingredients for a big chocolate cake. For that he is going to the biggest supermarket in town.Unfortunately, he has just s dollars for sugar. But ... | Input5 103 9012 09 705 507 0 | Output50 | 1 second | 256 megabytes | ['brute force', 'implementation', '*1200'] |
B. Appleman and Card Gametime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputAppleman has n cards. Each card has an uppercase letter written on it. Toastman must choose k cards from Appleman's cards. Then Appleman should give Toastman some coins depending on the chosen c... | Input15 10DZFDFZDFDDDDDDF | Output82 | 1 second | 256 megabytes | ['greedy', '*1300'] |
A. Appleman and Easy Tasktime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputToastman came up with a very easy task. He gives it to Appleman, but Appleman doesn't know how to solve it. Can you help him?Given a nβΓβn checkerboard. Each cell of the board has either charact... | Input3xxoxoxoxx | OutputYES | 1 second | 256 megabytes | ['brute force', 'implementation', '*1000'] |
E. Appleman and a Gametime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputAppleman and Toastman like games. Today they play a game with strings with the following rules. Firstly Toastman tells Appleman two strings s and t both consisting only of letters 'A', 'B', 'C', 'D... | Input5ABCCAD | Output5 | 1 second | 256 megabytes | ['binary search', 'shortest paths', 'strings', '*3000'] |
D. Appleman and Complicated Tasktime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputToastman came up with a very complicated task. He gives it to Appleman, but Appleman doesn't know how to solve it. Can you help him?Given a nβΓβn checkerboard. Each cell of the board has... | Input3 21 1 x2 2 o | Output2 | 2 seconds | 256 megabytes | ['dsu', 'math', '*2800'] |
C. Appleman and a Sheet of Papertime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputAppleman has a very big sheet of paper. This sheet has a form of rectangle with dimensions 1βΓβn. Your task is help Appleman with folding of such a sheet. Actually, you need to perform q... | Input7 41 31 22 0 12 1 2 | Output43 | 2 seconds | 256 megabytes | ['data structures', 'implementation', '*2200'] |
B. Appleman and Treetime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputAppleman has a tree with n vertices. Some of the vertices (at least one) are colored black and other vertices are colored white.Consider a set consisting of k (0ββ€βkβ<βn) edges of Appleman's tree. I... | Input30 00 1 1 | Output2 | 2 seconds | 256 megabytes | ['dfs and similar', 'dp', 'trees', '*2000'] |
A. Appleman and Toastmantime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputAppleman and Toastman play a game. Initially Appleman gives one group of n numbers to the Toastman, then they start to complete the following tasks: Each time Toastman gets a group of numbers, ... | Input33 1 5 | Output26 | 2 seconds | 256 megabytes | ['greedy', 'sortings', '*1200'] |
E. Roland and Rosetime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputRoland loves growing flowers. He has recently grown a beautiful rose at point (0,β0) of the Cartesian coordinate system. The rose is so beautiful that Roland is afraid that the evil forces can try and... | Input4 1 | Output160 10 10 -10 -1 | 3 seconds | 256 megabytes | ['brute force', 'geometry', 'math', 'sortings', '*2700'] |
D. Little Victor and Settime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputLittle Victor adores the sets theory. Let us remind you that a set is a group of numbers where all numbers are pairwise distinct. Today Victor wants to find a set of integers S that has the follo... | Input8 15 3 | Output1210 11 | 1 second | 256 megabytes | ['brute force', 'constructive algorithms', 'math', '*2300'] |
C. Presenttime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputLittle beaver is a beginner programmer, so informatics is his favorite subject. Soon his informatics teacher is going to have a birthday and the beaver has decided to prepare a present for her. He planted n f... | Input6 2 32 2 2 2 1 1 | Output2 | 2 seconds | 256 megabytes | ['binary search', 'data structures', 'greedy', '*1700'] |
B. Little Dima and Equationtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputLittle Dima misbehaved during a math lesson a lot and the nasty teacher Mr. Pickles gave him the following problem as a punishment. Find all integer solutions x (0β<βxβ<β109) of the equation:x... | Input3 2 8 | Output310 2008 13726 | 1 second | 256 megabytes | ['brute force', 'implementation', 'math', 'number theory', '*1500'] |
A. Vasya and Sockstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputVasya has n pairs of socks. In the morning of each day Vasya has to put on a pair of socks before he goes to school. When he comes home in the evening, Vasya takes off the used socks and throws them aw... | Input2 2 | Output3 | 1 second | 256 megabytes | ['brute force', 'implementation', 'math', '*900'] |
E. Pashmak and Graphtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputPashmak's homework is a problem about graphs. Although he always tries to do his homework completely, he can't solve this problem. As you know, he's really weak at graph theory; so try to help him in... | Input3 31 2 12 3 13 1 1 | Output1 | 1 second | 256 megabytes | ['dp', 'sortings', '*1900'] |
D. Pashmak and Parmida's problemtime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputParmida is a clever girl and she wants to participate in Olympiads this year. Of course she wants her partner to be clever too (although he's not)! Parmida has prepared the following tes... | Input71 2 1 1 2 2 1 | Output8 | 3 seconds | 256 megabytes | ['data structures', 'divide and conquer', 'sortings', '*1800'] |
C. Pashmak and Busestime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputRecently Pashmak has been employed in a transportation company. The company has k buses and has a contract with a school which has n students. The school planned to take the students to d different p... | Input3 2 2 | Output1 1 2 1 2 1 | 1 second | 256 megabytes | ['combinatorics', 'constructive algorithms', 'math', '*1900'] |
B. Pashmak and Flowerstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputPashmak decided to give Parmida a pair of flowers from the garden. There are n flowers in the garden and the i-th of them has a beauty number bi. Parmida is a very strange girl so she doesn't want ... | Input21 2 | Output1 1 | 1 second | 256 megabytes | ['combinatorics', 'implementation', 'sortings', '*1300'] |
A. Pashmak and Gardentime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputPashmak has fallen in love with an attractive girl called Parmida since one year ago...Today, Pashmak set up a meeting with his partner in a romantic garden. Unfortunately, Pashmak has forgotten whe... | Input0 0 0 1 | Output1 0 1 1 | 1 second | 256 megabytes | ['implementation', '*1200'] |
F. An easy problem about treestime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputPieguy and Piegirl are playing a game. They have a rooted binary tree, that has a property that each node is either a leaf or has exactly two children. Each leaf has a number associated wi... | Input43-1 1 21055-1 1 2-1 3 4105207-1 1 2-1 3 4-1 5 6123411-1 1 2-1 3 4-1 5 6-1 7 8157-1 9 1078911 | Output101048 | 2 seconds | 256 megabytes | ['dp', 'games', 'greedy', 'trees', '*3200'] |
E. Flow Optimalitytime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere is a computer network consisting of n nodes numbered 1 through n. There are links in the network that connect pairs of nodes. A pair of nodes may have multiple links between them, but no node ha... | Input4 51 2 1 21 3 4 12 3 2 12 4 4 13 4 1 2 | Output6 | 2 seconds | 256 megabytes | ['constructive algorithms', 'flows', 'math', '*3000'] |
D. Bingo!time limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe game of bingo is played on a 5βΓβ5 square grid filled with distinct numbers between 1 and 75. In this problem you will consider a generalized version played on an nβΓβn grid with distinct numbers between 1 ... | Input1 2 1 | Output2.5 | 1 second | 256 megabytes | ['combinatorics', 'math', 'probabilities', '*2700'] |
C. Electionstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are running for a governor in a small city in Russia. You ran some polls and did some research, and for every person in the city you know whom he will vote for, and how much it will cost to bribe that p... | Input51 21 21 22 10 0 | Output3 | 2 seconds | 256 megabytes | ['brute force', '*2100'] |
B. Distributed Jointime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputPiegirl was asked to implement two table join operation for distributed database system, minimizing the network traffic.Suppose she wants to join two tables, A and B. Each of them has certain number o... | Input2 22 63 100 | Output11 | 1 second | 256 megabytes | ['greedy', '*1900'] |
A. Golden Systemtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputPiegirl got bored with binary, decimal and other integer based counting systems. Recently she discovered some interesting properties about number , in particular that q2β=βqβ+β1, and she thinks it would ... | Input1000111 | Output< | 1 second | 256 megabytes | ['math', 'meet-in-the-middle', '*1700'] |
B. Fedya and Mathstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputFedya studies in a gymnasium. Fedya's maths hometask is to calculate the following expression:(1nβ+β2nβ+β3nβ+β4n)Β modΒ 5for given value of n. Fedya managed to complete the task. Can you? Note that given... | Input4 | Output4 | 1 second | 256 megabytes | ['math', 'number theory', '*1200'] |
A. Laptopstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputOne day Dima and Alex had an argument about the price and quality of laptops. Dima thinks that the more expensive a laptop is, the better it is. Alex disagrees. Alex thinks that there are two laptops, such tha... | Input21 22 1 | OutputHappy Alex | 1 second | 256 megabytes | ['sortings', '*1100'] |
E. Functiontime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputSerega and Fedor play with functions. One day they came across a very interesting function. It looks like that: f(1,βj)β=βa[j], 1ββ€βjββ€βn. f(i,βj)β=βmin(f(iβ-β1,βj),βf(iβ-β1,βjβ-β1))β+βa[j], 2ββ€βiββ€βn, iββ€β... | Input62 2 3 4 3 444 53 43 42 3 | Output12995 | 1 second | 256 megabytes | ['data structures', '*2900'] |
D. Serega and Funtime limit per test4 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputSerega loves fun. However, everyone has fun in the unique manner. Serega has fun by solving query problems. One day Fedor came up with such a problem.You are given an array a consisting of n positive i... | Input76 6 2 7 4 2 571 3 62 2 4 22 2 4 72 2 2 51 2 61 1 42 1 7 3 | Output2100 | 4 seconds | 256 megabytes | ['data structures', '*2700'] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.