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. Empire Strikes Backtime limit per test5 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputIn a far away galaxy there is war again. The treacherous Republic made k precision strikes of power ai on the Empire possessions. To cope with the republican threat, the Supreme Council decided to...
Input21000 1000
Output2000
5 seconds
512 megabytes
['binary search', 'math', 'number theory', '*2300']
D. Painting Squaretime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputVasily the bear has got a large square white table of n rows and n columns. The table has got a black border around this table. The example of the initial table at n = 5. Vasily the bear wants to pai...
Input81 01 13 03 12 02 13 27 2
Output10111004
3 seconds
256 megabytes
['dp', 'fft', '*2300']
C. Beautiful Numberstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputVitaly is a very weird man. He's got two favorite digits a and b. Vitaly calls a positive integer good, if the decimal representation of this integer only contains digits a and b. Vitaly calls a goo...
Input1 3 3
Output1
2 seconds
256 megabytes
['brute force', 'combinatorics', '*1800']
B. Coachtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputA programming coach has n students to teach. We know that n is divisible by 3. Let's assume that all students are numbered from 1 to n, inclusive.Before the university programming championship the coach wants t...
Input3 0
Output3 2 1
2 seconds
256 megabytes
['brute force', 'dfs and similar', 'graphs', '*1500']
A. Arraytime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputVitaly has an array of n distinct integers. Vitaly wants to divide this array into three non-empty sets so as the following conditions hold: The product of all numbers in the first set is less than zero ( < 0...
Input3-1 2 0
Output1 -11 21 0
2 seconds
256 megabytes
['brute force', 'constructive algorithms', 'implementation', '*1100']
B. Ksusha the Squirreltime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputKsusha the Squirrel is standing at the beginning of a straight road, divided into n sectors. The sectors are numbered 1 to n, from left to right. Initially, Ksusha stands in sector 1. Ksusha wants ...
Input2 1..
OutputYES
1 second
256 megabytes
['brute force', 'implementation', '*900']
A. Ksusha and Arraytime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputKsusha is a beginner coder. Today she starts studying arrays. She has array a1, a2, ..., an, consisting of n positive integers.Her university teacher gave her a task. Find such number in the array, t...
Input32 2 4
Output2
2 seconds
256 megabytes
['brute force', 'number theory', 'sortings', '*1000']
B. Sailtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe polar bears are going fishing. They plan to sail from (sx, sy) to (ex, ey). However, the boat can only sail by wind. At each second, the wind blows in one of these directions: east, south, west or north. Assu...
Input5 0 0 1 1SESNW
Output4
1 second
256 megabytes
['brute force', 'greedy', 'implementation', '*1200']
A. Snow Footprintstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere is a straight snowy road, divided into n blocks. The blocks are numbered from 1 to n from left to right. If one moves from the i-th block to the (i + 1)-th block, he will leave a right footprint ...
Input9..RRLL...
Output3 4
1 second
256 megabytes
['greedy', 'implementation', '*1300']
E. Mystic Carvingstime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe polar bears have discovered a gigantic circular piece of floating ice with some mystic carvings on it. There are n lines carved on the ice. Each line connects two points on the boundary of the ice...
Input45 41 26 78 3
Output2
3 seconds
256 megabytes
['data structures', '*3000']
D. Color the Carpettime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputEven polar bears feel cold when lying on the ice. Therefore, a polar bear Alice is going to make a carpet. The carpet can be viewed as a grid with height h and width w. Then the grid is divided into h...
Input3 4 4ENENNEENEEENENENN
OutputYES1 1 2 23 4 1 13 3 2 4
1 second
256 megabytes
['constructive algorithms', '*2500']
C. Splitting the Uniquenesstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputPolar bears like unique arrays β€” that is, arrays without repeated elements. You have got a unique array s with length n containing non-negative integers. Since you are good friends with Alice ...
Input612 5 8 3 11 9
OutputYES6 2 6 0 2 46 3 2 3 9 5
1 second
256 megabytes
['constructive algorithms', '*2400']
B. Fish Weighttime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputIt is known that there are k fish species in the polar ocean, numbered from 1 to k. They are sorted by non-decreasing order of their weight, which is a positive number. Let the weight of the i-th type of f...
Input3 3 32 2 21 1 3
OutputYES
1 second
256 megabytes
['constructive algorithms', 'greedy', '*1600']
A. Parity Gametime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are fishing with polar bears Alice and Bob. While waiting for the fish to bite, the polar bears get bored. They come up with a game. First Alice and Bob each writes a 01-string (strings that only conta...
Input010110110
OutputYES
1 second
256 megabytes
['constructive algorithms', '*1700']
B. Yaroslav and Two Stringstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYaroslav thinks that two strings s and w, consisting of digits and having length n are non-comparable if there are two numbers, i and j (1 ≀ i, j ≀ n), such that si > wi and sj < wj. Here sig...
Input29009
Output1
2 seconds
256 megabytes
['combinatorics', 'dp', '*2000']
A. Yaroslav and Permutationstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYaroslav has an array that consists of n integers. In one second Yaroslav can swap two neighboring array elements. Now Yaroslav is wondering if he can obtain an array where any two neighbori...
Input11
OutputYES
2 seconds
256 megabytes
['greedy', 'math', '*1100']
E. Yaroslav and Pointstime limit per test5 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYaroslav has n points that lie on the Ox axis. The coordinate of the first point is x1, the coordinate of the second point is x2, ..., the coordinate of the n-th point is β€” xn. Now Yaroslav wants ...
Input836 50 28 -75 40 -60 -95 -48202 -61 291 5 -531 1 4291 5 1302 -101 -712 -69 531 1 4041 5 5182 -101 532 50 8721 1 -2072 -99 -401 7 -3891 6 -1711 2 4641 7 -7071 1 -7301 1 5602 635 6441 7 -677
Output17620406104616381560
5 seconds
256 megabytes
['data structures', '*2500']
D. Greg and Cavestime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputGreg has a pad. The pad's screen is an n × m rectangle, each cell can be either black or white. We'll consider the pad rows to be numbered with integers from 1 to n from top to bottom. Similarly, the p...
Input1 1
Output0
2 seconds
256 megabytes
['combinatorics', 'dp', '*2400']
C. Greg and Friendstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputOne day Greg and his friends were walking in the forest. Overall there were n people walking, including Greg. Soon he found himself in front of a river. The guys immediately decided to get across the...
Input1 5050
Output11
2 seconds
256 megabytes
['combinatorics', 'dp', 'graphs', 'shortest paths', '*2100']
B. Greg and Graphtime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputGreg has a weighed directed graph, consisting of n vertices. In this graph any pair of distinct vertices has an edge between them in both directions. Greg loves playing with the graph and now he has in...
Input101
Output0
3 seconds
256 megabytes
['dp', 'graphs', 'shortest paths', '*1700']
A. Greg and Arraytime limit per test1.5 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputGreg has an array a = a1, a2, ..., an and m operations. Each operation looks as: li, ri, di, (1 ≀ li ≀ ri ≀ n). To apply operation i to the array means to increase all array elements with numbers li,...
Input3 3 31 2 31 2 11 3 22 3 41 21 32 3
Output9 18 17
1.5 seconds
256 megabytes
['data structures', 'implementation', '*1400']
E. Shaass the Greattime limit per test3.5 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe great Shaass is the new king of the Drakht empire. The empire has n cities which are connected by n - 1 bidirectional roads. Each road has an specific length and connects a pair of cities. Ther...
Input31 2 21 3 4
Output12
3.5 seconds
256 megabytes
['dp', 'trees', '*2300']
D. Shaass and Painter Robottime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputShaass thinks a kitchen with all white floor tiles is so boring. His kitchen floor is made of nΒ·m square tiles forming a n × m rectangle. Therefore he's decided to color some of the tiles in ...
Input3 41 1 DR
Output7
2 seconds
256 megabytes
['brute force', 'implementation', 'number theory', '*2500']
C. Shaass and Lightstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere are n lights aligned in a row. These lights are numbered 1 to n from left to right. Initially some of the lights are switched on. Shaass wants to switch all the lights on. At each step he can s...
Input3 11
Output1
1 second
256 megabytes
['combinatorics', 'number theory', '*1900']
B. Shaass and Bookshelftime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputShaass has n books. He wants to make a bookshelf for all his books. He wants the bookshelf's dimensions to be as small as possible. The thickness of the i-th book is ti and its pages' width is equ...
Input51 121 32 152 52 1
Output5
1 second
256 megabytes
['dp', 'greedy', '*1700']
A. Shaass and Oskolstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputShaass has decided to hunt some birds. There are n horizontal electricity wires aligned parallel to each other. Wires are numbered 1 to n from top to bottom. On each wire there are some oskols sitti...
Input510 10 10 10 1052 53 132 121 134 6
Output0125016
2 seconds
256 megabytes
['implementation', 'math', '*800']
E. Close Verticestime limit per test5 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou've got a weighted tree, consisting of n vertices. Each edge has a non-negative weight. The length of the path between any two vertices of the tree is the number of edges in the path. The weight of ...
Input4 4 61 31 41 3
Output4
5 seconds
256 megabytes
['data structures', 'divide and conquer', 'trees', '*2700']
D. Ksusha and Squaretime limit per test4 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputKsusha is a vigorous mathematician. She is keen on absolutely incredible mathematical riddles. Today Ksusha came across a convex polygon of non-zero area. She is now wondering: if she chooses a pair...
Input30 05 55 0
Output4.6666666667
4 seconds
256 megabytes
['geometry', 'math', 'probabilities', 'two pointers', '*2700']
C. Cube Problemtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYaroslav, Andrey and Roman love playing cubes. Sometimes they get together and play cubes for hours and hours! Today they got together again and they are playing cubes. Yaroslav took unit cubes and compo...
Input24
Output1
2 seconds
256 megabytes
['brute force', 'math', 'number theory', '*2400']
B. Distinct Pathstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou have a rectangular n × m-cell board. Some cells are already painted some of k colors. You need to paint each uncolored cell one of the k colors so that any path from the upper left square to the lo...
Input2 2 40 00 0
Output48
2 seconds
256 megabytes
['brute force', 'combinatorics', '*2700']
A. Weird Gametime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYaroslav, Andrey and Roman can play cubes for hours and hours. But the game is for three, so when Roman doesn't show up, Yaroslav and Andrey play another game. Roman leaves a word for each of them. Each wo...
Input201110001
OutputFirst
2 seconds
256 megabytes
['games', 'greedy', '*1500']
E. Copying Datatime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputWe often have to copy large volumes of information. Such operation can take up many computer resources. Therefore, in this problem you are advised to come up with a way to copy some part of a number arra...
Input5 101 2 0 -1 33 1 5 -2 02 51 3 3 32 52 42 11 2 1 42 12 41 4 2 12 2
Output03-1323-1
2 seconds
256 megabytes
['data structures', '*1900']
D. Connected Componentstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputWe already know of the large corporation where Polycarpus works as a system administrator. The computer network there consists of n computers and m cables that connect some pairs of computers. In...
Input6 51 25 42 33 13 661 32 51 55 52 43 3
Output456342
2 seconds
256 megabytes
['data structures', 'dfs and similar', 'dp', 'dsu', '*1900']
C. Beautiful IP Addressestime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe problem uses a simplified TCP/IP address model, please read the statement carefully.An IP address is a 32-bit integer, represented as a group of four decimal 8-bit integers (without leading...
Input60 1 2 9 8 7
Output678.190.209.18779.180.208.19787.190.209.17889.170.207.19897.180.208.17998.170.207.189
2 seconds
256 megabytes
['brute force', '*2000']
B. Network Topologytime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThis problem uses a simplified network topology model, please read the problem statement carefully and use it as a formal document as you develop the solution.Polycarpus continues working as a system...
Input4 31 22 33 4
Outputbus topology
2 seconds
256 megabytes
['graphs', 'implementation', '*1200']
A. SMSCtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputSome large corporation where Polycarpus works has its own short message service center (SMSC). The center's task is to send all sorts of crucial information. Polycarpus decided to check the efficiency of the SMS...
Input21 12 1
Output3 1
2 seconds
256 megabytes
['implementation', '*1100']
E. Tree-String Problemtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputA rooted tree is a non-directed connected graph without any cycles with a distinguished vertex, which is called the tree root. Consider the vertices of a rooted tree, that consists of n vertices, n...
Input71 ab5 bacaba1 abacaba2 aca5 ba2 baaba
Output6
1 second
256 megabytes
['*special problem', 'dfs and similar', 'hashing', 'strings', '*2000']
D. Parallel Programmingtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputPolycarpus has a computer with n processors. Also, his computer has n memory cells. We'll consider the processors numbered by integers from 1 to n and that the memory cells are consecutively numb...
Input1 1
Output1
2 seconds
256 megabytes
['*special problem', 'greedy', '*1600']
C. Network Masktime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe problem uses a simplified TCP/IP address model, please make sure you've read the statement attentively.Polycarpus has found a job, he is a system administrator. One day he came across n IP addresses....
Input5 30.0.0.10.1.1.20.0.2.10.1.1.00.0.2.3
Output255.255.254.0
2 seconds
256 megabytes
['*special problem', 'bitmasks', 'brute force', 'implementation', '*1600']
B. Command Line Argumentstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe problem describes the properties of a command line. The description somehow resembles the one you usually see in real operating systems. However, there are differences in the behavior. Pleas...
Input"RUn.exe O" "" " 2ne, " two! . " "
Output<RUn.exe O><>< 2ne, ><two!><.>< >
1 second
256 megabytes
['*special problem', 'implementation', 'strings', '*1300']
A. Spyke Talkstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputPolycarpus is the director of a large corporation. There are n secretaries working for the corporation, each of them corresponds via the famous Spyke VoIP system during the day. We know that when two peop...
Input60 1 7 1 7 10
Output2
2 seconds
256 megabytes
['*special problem', 'implementation', 'sortings', '*800']
F. Greedy Petyatime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputPetya is an unexperienced programming contestant. Recently he has come across the following problem:You are given a non-directed graph which consists of n nodes and m edges. Your task is to determine whe...
Input2 31 22 11 1
OutputYes
2 seconds
256 megabytes
['*special problem', 'dfs and similar', 'graphs', 'greedy', '*2800']
E. HQtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe famous joke programming language HQ9+ has only 4 commands. In this problem we will explore its subset β€” a language called HQ...InputThe only line of the input is a string between 1 and 106 characters long.Outp...
InputHHHH
OutputYes
2 seconds
256 megabytes
['*special problem', 'constructive algorithms', '*2500']
D. Orangetime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard output InputThe first line of the input is a string (between 1 and 50 characters long, inclusive). Each character will be a letter of English alphabet, lowercase or uppercase.The second line of the input is an inte...
InputAprilFool14
OutputAprILFooL
2 seconds
256 megabytes
['*special problem', 'implementation', '*1400']
C. WTF?time limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputHAII HAS A TUXGIMMEH TUXI HAS A FOO ITS 0I HAS A BAR ITS 0I HAS A BAZ ITS 0I HAS A QUZ ITS 1TUX IS NOW A NUMBRIM IN YR LOOP NERFIN YR TUX TIL BOTH SAEM TUX AN 0I HAS A PURGIMMEH PURPUR IS NOW A NUMBRFOO R SUM OF...
Input3011
Output0.666667
2 seconds
256 megabytes
['*special problem', 'graph matchings', 'implementation', 'trees', '*1700']
B. QR codetime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard output InputThe input contains two integers a1, a2 (0 ≀ ai ≀ 32), separated by a single space.OutputOutput a single integer.ExamplesInput1 1Output0Input3 7Output0Input13 10Output1
Input1 1
Output0
2 seconds
256 megabytes
['*special problem', 'implementation', '*1500']
A. Mysterious stringstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputInputThe input contains a single integer a (1 ≀ a ≀ 40).OutputOutput a single string.ExamplesInput2OutputAdamsInput8OutputVan BurenInput29OutputHarding
Input2
OutputAdams
2 seconds
256 megabytes
['*special problem', 'implementation', '*1400']
B. Polo the Penguin and Matrixtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputLittle penguin Polo has an n × m matrix, consisting of integers. Let's index the matrix rows from 1 to n from top to bottom and let's index the columns from 1 to m from left to right. Let'...
Input2 2 22 46 8
Output4
2 seconds
256 megabytes
['brute force', 'dp', 'implementation', 'sortings', 'ternary search', '*1400']
A. Polo the Penguin and Segments time limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputLittle penguin Polo adores integer segments, that is, pairs of integers [l;Β r] (l ≀ r). He has a set that consists of n integer segments: [l1;Β r1], [l2;Β r2], ..., [ln;Β rn]. We know that...
Input2 31 23 4
Output2
2 seconds
256 megabytes
['brute force', 'implementation', '*1100']
E. Polo the Penguin and Lucky Numberstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputEverybody knows that lucky numbers are positive integers that contain only lucky digits 4 and 7 in their decimal representation. For example, numbers 47, 744, 4 are lucky and 5, 17,...
Input47
Output28
2 seconds
256 megabytes
['dp', 'implementation', 'math', '*2800']
D. Polo the Penguin and Trees time limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputLittle penguin Polo has got a tree β€” a non-directed connected acyclic graph, containing n nodes and n - 1 edges. We will consider the tree nodes numbered by integers from 1 to n.Today Polo...
Input41 22 33 4
Output2
2 seconds
256 megabytes
['combinatorics', 'dfs and similar', 'trees', '*2400']
C. Polo the Penguin and XOR operationtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputLittle penguin Polo likes permutations. But most of all he likes permutations of integers from 0 to n, inclusive.For permutation p = p0, p1, ..., pn, Polo has defined its beauty β€” n...
Input4
Output200 2 1 4 3
2 seconds
256 megabytes
['implementation', 'math', '*1700']
B. Polo the Penguin and Houses time limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputLittle penguin Polo loves his home village. The village has n houses, indexed by integers from 1 to n. Each house has a plaque containing an integer, the i-th house has a plaque containin...
Input5 2
Output54
2 seconds
256 megabytes
['combinatorics', '*1500']
A. Polo the Penguin and Stringstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputLittle penguin Polo adores strings. But most of all he adores strings of length n.One day he wanted to find a string that meets the following conditions: The string consists of n lowerca...
Input7 4
Outputababacd
2 seconds
256 megabytes
['greedy', '*1300']
B. Pipelinetime limit per test0.4 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputVova, the Ultimate Thule new shaman, wants to build a pipeline. As there are exactly n houses in Ultimate Thule, Vova wants the city to have exactly n pipes, each such pipe should be connected to the water...
Input4 3
Output2
0.4 seconds
256 megabytes
['binary search', 'math', '*1700']
A. IQ Testtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputIn the city of Ultima Thule job applicants are often offered an IQ test. The test is as follows: the person gets a piece of squared paper with a 4 × 4 square painted on it. Some of the square's cells are pain...
Input####.#..####....
OutputYES
2 seconds
256 megabytes
['brute force', 'implementation', '*1100']
E. Ladies' Shoptime limit per test8 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputA ladies' shop has recently opened in the city of Ultima Thule. To get ready for the opening, the shop bought n bags. Each bag is characterised by the total weight ai of the items you can put there. The ...
Input6 105 6 7 8 9 10
OutputYES55 6 7 8 9
8 seconds
256 megabytes
['constructive algorithms', 'fft', 'math', '*2800']
D. Touriststime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputA double tourist path, located at a park in Ultima Thule, is working by the following principle: We introduce the Cartesian coordinate system. At some points of time there are two tourists going (for a walk...
Input2 21 4 33 6 50 1
Output24
1 second
256 megabytes
['data structures', 'sortings', '*2600']
C. Main Sequencetime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputAs you know, Vova has recently become a new shaman in the city of Ultima Thule. So, he has received the shaman knowledge about the correct bracket sequences. The shamans of Ultima Thule have been using ...
Input21 10
OutputYES1 -1
2 seconds
256 megabytes
['greedy', 'implementation', '*2100']
B. Shiftingtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputJohn Doe has found the beautiful permutation formula.Let's take permutation p = p1, p2, ..., pn. Let's define transformation f of this permutation: where k (k > 1) is an integer, the transformation parameter...
Input2
Output2 1
2 seconds
256 megabytes
['implementation', '*2200']
A. Lucky Permutationtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputA permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≀ pi ≀ n).A lucky permutation is such permutation p, that any integer i (...
Input1
Output1
2 seconds
256 megabytes
['constructive algorithms', 'math', '*1400']
E. Positions in Permutationstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputPermutation p is an ordered set of integers p1,  p2,  ...,  pn, consisting of n distinct positive integers, each of them doesn't exceed n. We'll denote the i-th element of permutation p as p...
Input1 0
Output1
2 seconds
256 megabytes
['combinatorics', 'dp', 'math', '*2600']
D. Permutation Sumtime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputPermutation p is an ordered set of integers p1,  p2,  ...,  pn, consisting of n distinct positive integers, each of them doesn't exceed n. We'll denote the i-th element of permutation p as pi. We'll c...
Input3
Output18
3 seconds
256 megabytes
['bitmasks', 'combinatorics', 'dp', 'implementation', 'meet-in-the-middle', '*1900']
C. Building 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, each of them doesn't exceed n. We'll denote the i-th element of permutation p as pi. We'...
Input23 0
Output2
1 second
256 megabytes
['greedy', 'implementation', 'sortings', '*1200']
B. Find Marbletime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputPetya and Vasya are playing a game. Petya's got n non-transparent glasses, standing in a row. The glasses' positions are indexed with integers from 1 to n from left to right. Note that the positions are i...
Input4 2 12 3 4 1
Output3
2 seconds
256 megabytes
['implementation', '*1200']
A. Slightly Decreasing Permutationstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputPermutation p is an ordered set of integers p1,  p2,  ...,  pn, consisting of n distinct positive integers, each of them doesn't exceed n. We'll denote the i-th element of permutation...
Input5 2
Output1 5 2 4 3
2 seconds
256 megabytes
['greedy', 'implementation', '*1100']
B. Cows and Poker Gametime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere are n cows playing poker at a table. For the current betting phase, each player's status is either "ALLIN", "IN", or "FOLDED", and does not change throughout the phase. To increase the suspe...
Input6AFFAAA
Output4
2 seconds
256 megabytes
['brute force', 'implementation', '*1000']
A. Cows and Primitive Rootstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe cows have just learned what a primitive root is! Given a prime p, a primitive root is an integer x (1 ≀ x < p) such that none of integers x - 1, x2 - 1, ..., xp - 2 - 1 are divisible by ...
Input3
Output1
2 seconds
256 megabytes
['implementation', 'math', 'number theory', '*1400']
E. Cow Tennis Tournamenttime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputFarmer John is hosting a tennis tournament with his n cows. Each cow has a skill level si, and no two cows having the same skill level. Every cow plays every other cow exactly once in the tourna...
Input3 21 2 31 22 3
Output1
2 seconds
256 megabytes
['combinatorics', 'data structures', 'math', '*2800']
D. Cows and Cool Sequencestime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputBessie and the cows have recently been playing with "cool" sequences and are trying to construct some. Unfortunately they are bad at arithmetic, so they need your help!A pair (x, y) of positiv...
Input36 4 1
Output0
2 seconds
256 megabytes
['dp', 'math', 'number theory', '*2400']
C. Coin Troublestime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputIn the Isle of Guernsey there are n different types of coins. For each i (1 ≀ i ≀ n), coin of type i is worth ai cents. It is possible that ai = aj for some i and j (i ≠ j). Bessie has some set of these...
Input4 2 173 1 2 54 23 4
Output3
2 seconds
256 megabytes
['dp', '*2100']
B. Cow Programtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputFarmer John has just given the cows a program to play with! The program contains two integer variables, x and y, and performs the following operations on a sequence a1, a2, ..., an of positive integers: ...
Input42 4 1
Output368
2 seconds
256 megabytes
['dfs and similar', 'dp', 'graphs', '*1700']
A. Cows and Sequencetime limit per test1.5 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputBessie and the cows are playing with sequences and need your help. They start with a sequence, initially containing just the number 0, and perform n operations. Each operation is one of the follow...
Input52 132 32 13
Output0.5000000.0000001.5000001.3333331.500000
1.5 seconds
256 megabytes
['constructive algorithms', 'data structures', 'implementation', '*1600']
E. Sausage Maximizationtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe Bitlandians are quite weird people. They have their own problems and their own solutions. They have their own thoughts and their own beliefs, they have their own values and their own merits. ...
Input21 2
Output3
2 seconds
256 megabytes
['bitmasks', 'data structures', 'trees', '*2200']
D. Yet Another Number Gametime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputSince most contestants do not read this part, I have to repeat that Bitlandians are quite weird. They have their own jobs, their own working method, their own lives, their own sausages and the...
Input21 1
OutputBitLGM
2 seconds
256 megabytes
['dp', 'games', '*2100']
C. XOR and ORtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe Bitlandians are quite weird people. They do everything differently. They have a different alphabet so they have a different definition for a string.A Bitlandish string is a string made only of characte...
Input1110
OutputYES
2 seconds
256 megabytes
['constructive algorithms', 'implementation', 'math', '*1500']
B. Painting Eggstime limit per test5 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe Bitlandians are quite weird people. They have very peculiar customs.As is customary, Uncle J. wants to have n eggs painted for Bitruz (an ancient Bitland festival). He has asked G. and A. to do the ...
Input21 999999 1
OutputAG
5 seconds
256 megabytes
['greedy', 'math', '*1500']
A. Bit++time limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe classic programming language of Bitland is Bit++. This language is so peculiar and complicated.The language is that peculiar as it has exactly one variable, called x. Also, there are two operations: Operati...
Input1++X
Output1
1 second
256 megabytes
['implementation', '*800']
B. Nearest Fractiontime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given three positive integers x, y, n. Your task is to find the nearest fraction to fraction whose denominator is no more than n. Formally, you should find such pair of integers a, b (1 ≀ b ...
Input3 7 6
Output2/5
2 seconds
256 megabytes
['brute force', 'implementation', 'two pointers', '*1700']
A. Word Capitalizationtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputCapitalization is writing a word with its first letter as a capital letter. Your task is to capitalize the given word.Note, that during capitalization all the letters except the first one remains ...
InputApPLe
OutputApPLe
2 seconds
256 megabytes
['implementation', 'strings', '*800']
E. Sequence Transformationtime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou've got a non-decreasing sequence x1, x2, ..., xn (1 ≀ x1 ≀ x2 ≀ ... ≀ xn ≀ q). You've also got two integers a and b (a ≀ b;Β aΒ·(n - 1) < q).Your task is to transform sequence x1, x2, ..., x...
Input3 6 2 21 4 6
Output1.666667 3.666667 5.666667 0.666667
3 seconds
256 megabytes
['brute force', 'data structures', 'dp', 'implementation', 'math', '*3000']
D. k-Maximum Subsequence Sumtime limit per test4 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputConsider integer sequence a1, a2, ..., an. You should run queries of two types: The query format is "0 i val". In reply to this query you should make the following assignment: ai = val. Th...
Input99 -8 9 -1 -1 -1 9 -8 931 1 9 11 1 9 21 4 6 3
Output17250
4 seconds
256 megabytes
['data structures', 'flows', 'graphs', 'implementation', '*2800']
C. Game on Treetime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputMomiji has got a rooted tree, consisting of n nodes. The tree nodes are numbered by integers from 1 to n. The root has number 1. Momiji decided to play a game on this tree.The game consists of several ste...
Input21 2
Output1.50000000000000000000
1 second
256 megabytes
['implementation', 'math', 'probabilities', 'trees', '*2200']
B. Maximum Xor Secondarytime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputBike loves looking for the second maximum element in the sequence. The second maximum element in the sequence of distinct numbers x1, x2, ..., xk (k > 1) is such maximum element xj, that the foll...
Input55 2 1 4 3
Output7
1 second
256 megabytes
['data structures', 'implementation', 'two pointers', '*1800']
A. Rectangle Puzzletime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given two rectangles on a plane. The centers of both rectangles are located in the origin of coordinates (meaning the center of the rectangle's symmetry). The first rectangle's sides are para...
Input1 1 45
Output0.828427125
2 seconds
256 megabytes
['geometry', '*2000']
E. Beautiful Decompositiontime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputValera considers a number beautiful, if it equals 2k or -2k for some integer k (k β‰₯ 0). Recently, the math teacher asked Valera to represent number n as the sum of beautiful numbers. As Valera...
Input10
Output1
2 seconds
256 megabytes
['dp', 'games', 'greedy', 'number theory', '*1900']
D. The Minimum Number of Variablestime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou've got a positive integer sequence a1, a2, ..., an. All numbers in the sequence are distinct. Let's fix the set of variables b1, b2, ..., bm. Initially each variable bi (1 ≀ i ≀ m) ...
Input51 2 3 6 8
Output2
1 second
256 megabytes
['bitmasks', 'dp', '*2200']
C. Laddertime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou've got an array, consisting of n integers a1, a2, ..., an. Also, you've got m queries, the i-th query is described by two integers li, ri. Numbers li, ri define a subsegment of the original array, that is,...
Input8 61 2 1 3 3 5 2 11 32 32 48 81 45 8
OutputYesYesNoYesNoYes
2 seconds
256 megabytes
['dp', 'implementation', 'two pointers', '*1700']
B. Bookstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputWhen Valera has got some free time, he goes to the library to read some books. Today he's got t free minutes to read. That's why Valera took n books in the library and for each book he estimated the time he is ...
Input4 53 1 2 1
Output3
2 seconds
256 megabytes
['binary search', 'brute force', 'implementation', 'two pointers', '*1400']
A. Point on Spiraltime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputValera the horse lives on a plane. The Cartesian coordinate system is defined on this plane. Also an infinite spiral is painted on the plane. The spiral consists of segments: [(0, 0), (1, 0)], [(1, 0)...
Input0 0
Output0
2 seconds
256 megabytes
['brute force', 'geometry', 'implementation', '*1400']
B. New Problemtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputComing up with a new problem isn't as easy as many people think. Sometimes it is hard enough to name it. We'll consider a title original if it doesn't occur as a substring in any titles of recent Codeforc...
Input5threehorsesgoodsubstringssecretprimematrixbeautifulyear
Outputj
2 seconds
256 megabytes
['brute force', 'strings', '*1500']
A. Circle Linetime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe circle line of the Berland subway has n stations. We know the distances between all pairs of neighboring stations: d1 is the distance between the 1-st and the 2-nd station; d2 is the distance between ...
Input42 3 4 91 3
Output5
2 seconds
256 megabytes
['implementation', '*800']
E. Binary Tree on Planetime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputA root tree is a directed acyclic graph that contains one node (root), from which there is exactly one path to any other node.A root tree is binary if each node has at most two outgoing arcs.When...
Input30 01 02 1
Output3.650281539872885
3 seconds
256 megabytes
['flows', 'trees', '*2400']
D. Google Code Jamtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputMany of you must be familiar with the Google Code Jam round rules. Let us remind you of some key moments that are crucial to solving this problem. During the round, the participants are suggested to s...
Input3 4010 20 15 4 0.54 100 21 1 0.991 4 1 1 0.25
Output24.0 18.875
2 seconds
256 megabytes
['dp', 'probabilities', '*2800']
C. Gametime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputTwo players play the following game. Initially, the players have a knife and a rectangular sheet of paper, divided into equal square grid cells of unit size. The players make moves in turn, the player who can't ...
Input2 1 0
OutputFIRST1 0 1 1
2 seconds
256 megabytes
['games', 'implementation', '*2400']
B. Set of Pointstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputConvexity of a set of points on the plane is the size of the largest subset of points that form a convex polygon. Your task is to build a set of n points with the convexity of exactly m. Your set of poi...
Input4 3
Output0 03 00 31 1
2 seconds
256 megabytes
['constructive algorithms', 'geometry', '*2300']
A. Learning Languagestime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe "BerCorp" company has got n employees. These employees can use m approved official languages for the formal correspondence. The languages are numbered with integers from 1 to m. For each employ...
Input5 51 22 2 32 3 42 4 51 5
Output0
2 seconds
256 megabytes
['dfs and similar', 'dsu', '*1400']
E. Little Girl and Problem on Treestime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputA little girl loves problems on trees very much. Here's one of them.A tree is an undirected connected graph, not containing cycles. The degree of node x in the tree is the number of n...
Input3 61 21 30 3 1 20 2 3 10 1 5 21 11 21 3
Output996
2 seconds
256 megabytes
['data structures', 'graphs', 'trees', '*2100']
D. Little Girl and Maximum XORtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputA little girl loves problems on bitwise operations very much. Here's one of them.You are given two integers l and r. Let's consider the values of for all pairs of integers a and b (l ≀ a ≀...
Input1 2
Output3
1 second
256 megabytes
['bitmasks', 'dp', 'greedy', 'implementation', 'math', '*1700']
C. Little Girl and Maximum Sumtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe little girl loves the problems on array queries very much.One day she came across a rather well-known problem: you've got an array of n elements (the elements of the array are indexed s...
Input3 35 3 21 22 31 3
Output25
1 second
256 megabytes
['data structures', 'greedy', 'implementation', 'sortings', '*1500']