source
int64
2
2
difficulty
int64
7
25
name
stringlengths
9
60
description
stringlengths
164
7.12k
public_tests
dict
private_tests
dict
cf_rating
int64
0
3.5k
cf_points
float64
0
4k
2
10
1436_D. Bandit in a City
Bandits appeared in the city! One of them is trying to catch as many citizens as he can. The city consists of n squares connected by n-1 roads in such a way that it is possible to reach any square from any other square. The square number 1 is the main square. After Sunday walk all the roads were changed to one-way ro...
{ "input": [ "3\n1 1\n3 1 2\n", "3\n1 1\n3 1 3\n" ], "output": [ "3\n", "4\n" ] }
{ "input": [ "2\n1\n293175439 964211398\n", "50\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49\n82 30 98 3 92 42 28 41 90 67 83 5 2 77 38 39 96 22 18 37 88 42 91 34 39 2 89 72 100 18 11 79 77 82 10 48 61 39 80 13 61 76...
1,900
2,000
2
8
1461_B. Find the Spruce
Holidays are coming up really soon. Rick realized that it's time to think about buying a traditional spruce tree. But Rick doesn't want real trees to get hurt so he decided to find some in an n Γ— m matrix consisting of "*" and ".". <image> To find every spruce first let's define what a spruce in the matrix is. A set ...
{ "input": [ "4\n2 3\n.*.\n***\n2 3\n.*.\n**.\n4 5\n.***.\n*****\n*****\n*.*.*\n5 7\n..*.*..\n.*****.\n*******\n.*****.\n..*.*..\n" ], "output": [ "\n5\n3\n23\n34\n" ] }
{ "input": [ "6\n4 7\n...*...\n..***..\n.****..\n*******\n6 10\n....*.*...\n...*****..\n..*******.\n.********.\n********.*\n**********\n5 5\n*...*\n**.**\n*****\n**.**\n*...*\n5 6\n.*....\n.**...\n.***..\n.****.\n.*****\n3 3\n*.*\n...\n*.*\n2 4\n.**.\n****\n" ], "output": [ "24\n89\n19\n22\n4\n8\n" ] }
1,400
1,000
2
9
1486_C2. Guessing the Greatest (hard version)
The only difference between the easy and the hard version is the limit to the number of queries. This is an interactive problem. There is an array a of n different numbers. In one query you can ask the position of the second maximum element in a subsegment a[l..r]. Find the position of the maximum element in the arra...
{ "input": [ "5\n\n3\n\n4\n\n" ], "output": [ "\n? 1 5\n\n? 4 5\n\n! 1" ] }
{ "input": [ "10\n5 1 6 2 8 3 4 10 9 7\n", "5\n5 1 4 2 3\n", "100\n98 52 63 2 18 96 31 58 84 40 41 45 66 100 46 71 26 48 81 20 73 91 68 76 13 93 17 29 64 95 79 21 55 75 19 85 54 51 89 78 15 87 43 59 36 1 90 35 65 56 62 28 86 5 82 49 3 99 33 9 92 32 74 69 27 22 77 16 44 94 34 6 57 70 23 12 61 25 8 11 67 47...
1,900
750
2
11
1536_E. Omkar and Forest
Omkar's most recent follower, Ajit, has entered the Holy Forest. Ajit realizes that Omkar's forest is an n by m grid (1 ≀ n, m ≀ 2000) of some non-negative integers. Since the forest is blessed by Omkar, it satisfies some special conditions: 1. For any two adjacent (sharing a side) cells, the absolute value of the d...
{ "input": [ "4\n3 4\n0000\n00#0\n0000\n2 1\n#\n#\n1 2\n##\n6 29\n#############################\n#000##0###0##0#0####0####000#\n#0#0##00#00##00####0#0###0#0#\n#0#0##0#0#0##00###00000##00##\n#000##0###0##0#0##0###0##0#0#\n#############################\n" ], "output": [ "\n2\n3\n3\n319908071\n" ] }
{ "input": [ "1\n12 12\n#000#0#0##00\n0##########0\n0#0##0#0###0\n00#0##000###\n#0######0###\n#0####0####0\n#######000##\n0##0#00#00##\n##000##0####\n0########00#\n###000#000##\n####00####0#\n", "1\n10 10\n0####0###0\n00#000##00\n##0#0###00\n0#0##00#00\n####0###00\n###00#0#0#\n###00#0###\n###0##0#00\n#00##000...
2,300
2,250
2
7
231_A. Team
One day three best friends Petya, Vasya and Tonya decided to form a team and take part in programming contests. Participants are usually offered several problems during programming contests. Long before the start the friends decided that they will implement a problem if at least two of them are sure about the solution....
{ "input": [ "2\n1 0 0\n0 1 1\n", "3\n1 1 0\n1 1 1\n1 0 0\n" ], "output": [ "1\n", "2\n" ] }
{ "input": [ "1\n1 0 0\n", "16\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n", "1\n1 1 1\n", "10\n0 1 0\n0 1 0\n1 1 0\n1 0 0\n0 0 1\n0 1 1\n1 1 1\n1 1 0\n0 0 0\n0 0 0\n", "2\n1 0 0\n1 1 1\n", "5\n1 0 0\n0 1 0\n1 1 1\n0 0 1\n0 ...
800
500
2
11
27_E. Number With The Given Amount Of Divisors
Given the number n, find the smallest positive integer which has exactly n divisors. It is guaranteed that for the given n the answer will not exceed 1018. Input The first line of the input contains integer n (1 ≀ n ≀ 1000). Output Output the smallest positive integer with exactly n divisors. Examples Input 4 ...
{ "input": [ "6\n", "4\n" ], "output": [ "12", "6" ] }
{ "input": [ "1000\n", "20\n", "999\n", "8\n", "15\n", "118\n", "7\n", "473\n", "500\n", "940\n", "720\n", "59\n", "47\n", "1\n", "10\n", "9\n", "159\n", "265\n", "902\n", "312\n", "100\n", "637\n" ], "output": [ "81081000...
2,000
2,500
2
9
350_C. Bombs
You've got a robot, its task is destroying bombs on a square plane. Specifically, the square plane contains n bombs, the i-th bomb is at point with coordinates (xi, yi). We know that no two bombs are at the same point and that no bomb is at point with coordinates (0, 0). Initially, the robot is at point with coordinate...
{ "input": [ "2\n1 1\n-1 -1\n", "3\n5 0\n0 5\n1 0\n" ], "output": [ "12\n1 1 R\n1 1 U\n2\n1 1 L\n1 1 D\n3\n1 1 L\n1 1 D\n2\n1 1 R\n1 1 U\n3\n", "12\n1 1 R\n2\n1 1 L\n3\n1 5 R\n2\n1 5 L\n3\n1 5 U\n2\n1 5 D\n3\n" ] }
{ "input": [ "1\n-277226476 314722425\n", "24\n-2 -2\n-1 1\n0 1\n1 1\n0 2\n1 -1\n2 -2\n1 -2\n-1 0\n0 -2\n0 -1\n-2 0\n-2 -1\n2 -1\n2 2\n-1 -2\n-2 1\n2 0\n-1 2\n1 2\n-1 -1\n1 0\n2 1\n-2 2\n", "24\n-2 -2\n-1 1\n0 1\n1 1\n0 2\n1 -1\n2 -2\n1 -2\n-1 0\n0 -2\n0 -1\n-2 0\n-2 -1\n2 -1\n2 2\n-1 -2\n-2 1\n2 0\n-1 2\...
1,600
1,000
2
7
397_A. On Segment's Own Points
Our old friend Alexey has finally entered the University of City N β€” the Berland capital. Alexey expected his father to get him a place to live in but his father said it was high time for Alexey to practice some financial independence. So, Alexey is living in a dorm. The dorm has exactly one straight dryer β€” a 100 ce...
{ "input": [ "3\n0 5\n2 8\n1 6\n", "3\n0 10\n1 5\n7 15\n" ], "output": [ "1\n", "3\n" ] }
{ "input": [ "2\n1 5\n1 2\n", "2\n1 9\n3 5\n", "21\n0 97\n46 59\n64 95\n3 16\n86 95\n55 71\n51 77\n26 28\n47 88\n30 40\n26 34\n2 12\n9 10\n4 19\n35 36\n41 92\n1 16\n41 78\n56 81\n23 35\n40 68\n", "20\n69 72\n88 92\n77 80\n64 69\n66 67\n79 81\n91 96\n78 83\n81 86\n11 12\n48 53\n22 23\n81 84\n89 92\n56 ...
0
500
2
8
41_B. Martian Dollar
One day Vasya got hold of information on the Martian dollar course in bourles for the next n days. The buying prices and the selling prices for one dollar on day i are the same and are equal to ai. Vasya has b bourles. He can buy a certain number of dollars and then sell it no more than once in n days. According to Mar...
{ "input": [ "2 4\n3 7\n", "4 10\n4 3 2 1\n", "4 10\n4 2 3 1\n" ], "output": [ "8\n", "10\n", "15\n" ] }
{ "input": [ "5 1293\n1183 142 1356 889 134\n", "1 1483\n1126\n", "1 478\n1955\n", "93 867\n97 1270 616 1027 1685 27 1662 947 1480 20 1394 1528 191 1348 67 1694 1772 1706 1394 109 1391 878 1474 307 101 663 1064 116 143 1239 386 651 1534 1348 1604 636 793 1188 1293 24 1729 1204 1656 1579 1644 661 1470 ...
1,400
1,000
2
7
468_A. 24 Game
Little 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 two of them, let's denote them a and b, erase them from the sequence, and append to the sequence either a + b, ...
{ "input": [ "8\n", "1\n" ], "output": [ "YES\n1 * 2 = 2\n2 * 3 = 6\n6 * 4 = 24\n6 - 5 = 1\n24 * 1 = 24\n8 - 7 = 1\n24 * 1 = 24\n", "NO\n" ] }
{ "input": [ "987\n", "422\n", "100\n", "3\n", "5\n", "4\n", "6\n", "12\n", "116\n", "2\n", "580\n", "9782\n", "7\n", "1000\n", "447\n" ], "output": [ "YES\n2 - 1 = 1\n1 + 3 = 4\n4 * 5 = 20\n20 + 4 = 24\n7 - 6 = 1\n24 * 1 = 24\n9 - 8 = 1\n24 * 1 = 24...
1,500
500
2
7
490_A. Team Olympiad
The School β„–0 of the capital of Berland has n children studying in it. All the children in this school are gifted: some of them are good at programming, some are good at maths, others are good at PE (Physical Education). Hence, for each child we know value ti: * ti = 1, if the i-th child is good at programming, *...
{ "input": [ "4\n2 1 1 2\n", "7\n1 3 1 3 2 1 2\n" ], "output": [ "0\n", "2\n1 5 2\n3 7 4\n" ] }
{ "input": [ "3\n2 1 2\n", "5\n1 2 2 3 3\n", "220\n1 1 3 1 3 1 1 3 1 3 3 3 3 1 3 3 1 3 3 3 3 3 1 1 1 3 1 1 1 3 2 3 3 3 1 1 3 3 1 1 3 3 3 3 1 3 3 1 1 1 2 3 1 1 1 2 3 3 3 2 3 1 1 3 1 1 1 3 2 1 3 2 3 1 1 3 3 3 1 3 1 1 1 3 3 2 1 3 2 1 1 3 3 1 1 1 2 1 1 3 2 1 2 1 1 1 3 1 3 3 1 2 3 3 3 3 1 3 1 1 1 1 2 3 1 1 1 1...
800
500
2
7
514_A. Chewbaсca and Number
Luke Skywalker gave Chewbacca an integer number x. Chewbacca isn't good at numbers but he loves inverting digits in them. Inverting digit t means replacing it with digit 9 - t. Help Chewbacca to transform the initial number x to the minimum possible positive number by inverting some (possibly, zero) digits. The decim...
{ "input": [ "27\n", "4545\n" ], "output": [ "22\n", "4444\n" ] }
{ "input": [ "8772\n", "1000000000000000000\n", "5902\n", "1932\n", "41312150450968417\n", "2156\n", "164324828731963982\n", "270739\n", "429325660016\n", "3395184971407775\n", "9\n", "5728\n", "332711047202\n", "461117063340\n", "40289679\n", "635451083...
1,200
500
2
8
540_B. School Marks
Little Vova studies programming in an elite school. Vova and his classmates are supposed to write n progress tests, for each test they will get a mark from 1 to p. Vova is very smart and he can write every test for any mark, but he doesn't want to stand out from the crowd too much. If the sum of his marks for all tests...
{ "input": [ "5 3 5 18 4\n3 5 4\n", "5 3 5 16 4\n5 5 5\n" ], "output": [ "1 4 ", "-1" ] }
{ "input": [ "9 6 3 27 2\n1 1 1 2 1 1\n", "5 3 5 18 4\n1 1 1\n", "5 0 5 5 1\n\n", "995 1 42 28887 42\n13\n", "995 1 3 2877 3\n3\n", "9 7 2 14 1\n2 2 2 1 1 2 2\n", "9 7 2 13 1\n2 2 2 1 1 2 2\n", "7 4 5 26 5\n5 5 4 5\n", "5 3 5 12 1\n5 5 1\n", "9 7 2 18 2\n1 1 1 2 2 1 1\n", "...
1,700
1,000
2
7
58_A. Chat room
Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word s. It is considered that Vasya managed to say hello if several letters can be deleted from the typed word so that it resulted in the word "hello". For example, if...
{ "input": [ "ahhellllloou\n", "hlelo\n" ], "output": [ "YES\n", "NO\n" ] }
{ "input": [ "hyyhddqhxhekehkwfhlnlsihzefwchzerevcjtokefplholrbvxlltdlafjxrfhleglrvlolojoqaolagtbeyogxlbgfolllslli\n", "pfhhwctyqdlkrwhebfqfelhyebwllhemtrmeblgrynmvyhioesqklclocxmlffuormljszllpoo\n", "jhfbndhyzdvhbvhmhmefqllujdflwdpjbehedlsqfdsqlyelwjtyloxwsvasrbqosblzbowlqjmyeilcvotdlaouxhdpoeloaovb\n", ...
1,000
500
2
9
611_C. New Year and Domino
They say "years are like dominoes, tumbling one after the other". But would a year fit into a grid? I don't think so. Limak is a little polar bear who loves to play. He has recently got a rectangular grid with h rows and w columns. Each cell is a square, either empty (denoted by '.') or forbidden (denoted by '#'). Row...
{ "input": [ "7 39\n.......................................\n.###..###..#..###.....###..###..#..###.\n...#..#.#..#..#.........#..#.#..#..#...\n.###..#.#..#..###.....###..#.#..#..###.\n.#....#.#..#....#.....#....#.#..#..#.#.\n.###..###..#..###.....###..###..#..###.\n.......................................\n6\n1 1 ...
{ "input": [ "15 3\n...\n.#.\n.#.\n.#.\n..#\n...\n.#.\n.##\n.#.\n...\n...\n.##\n..#\n.#.\n#.#\n20\n1 1 10 1\n2 1 9 3\n1 2 15 3\n10 2 12 2\n4 1 8 1\n5 2 8 2\n10 1 12 3\n11 1 11 3\n7 2 14 3\n6 2 12 3\n8 1 11 2\n7 1 9 1\n2 1 6 2\n6 3 7 3\n7 1 10 2\n6 1 10 2\n1 1 2 2\n10 1 15 3\n1 1 11 1\n9 1 15 1\n", "1 1\n#\n1\...
1,500
1,250
2
25
630_R. Game
There is a legend in the IT City college. A student that failed to answer all questions on the game theory exam is given one more chance by his professor. The student has to play a game with the professor. The game is played on a square field consisting of n Γ— n cells. Initially all cells are empty. On each turn a pla...
{ "input": [ "1\n", "2\n" ], "output": [ "1", "2" ] }
{ "input": [ "4\n", "25496382240130775\n", "999999999999999999\n", "95451113283177888\n", "321392715309062180\n", "5\n", "3\n", "1000000000000000000\n" ], "output": [ "2", "1", "1", "2", "2", "1", "1", "2" ] }
1,200
0
2
9
65_C. Harry Potter and the Golden Snitch
Brothers Fred and George Weasley once got into the sporting goods store and opened a box of Quidditch balls. After long and painful experiments they found out that the Golden Snitch is not enchanted at all. It is simply a programmed device. It always moves along the same trajectory, which is a polyline with vertices at...
{ "input": [ "1\n1 2 3\n4 5 6\n20 10\n1 2 3\n", "4\n0 0 0\n0 10 0\n10 10 0\n10 0 0\n0 0 0\n1 1\n5 5 50\n", "4\n0 0 0\n0 10 0\n10 10 0\n10 0 0\n0 0 0\n1 1\n5 5 25\n" ], "output": [ "YES\n0.000000000000000\n1.000000000000000 2.000000000000000 3.000000000000000\n", "NO\n", "YES\n25.5000000000...
{ "input": [ "20\n26 47 23\n1 -2 17\n-14 -22 46\n19 34 -18\n22 -10 -34\n15 14 -48\n-30 -12 -12\n-23 40 -48\n-50 -41 -35\n48 -5 46\n-2 -11 10\n-49 47 -15\n31 6 10\n-41 35 15\n28 28 25\n43 -7 -10\n-19 -48 49\n-10 -29 28\n0 -10 28\n41 12 -26\n-14 40 17\n3 2\n-115 1407 1434\n", "4\n1 0 0\n0 1 0\n-1 0 0\n0 -1 0\n1...
2,100
1,500
2
7
706_A. Beru-taxi
Vasiliy lives at point (a, b) of the coordinate plane. He is hurrying up to work so he wants to get out of his house as soon as possible. New app suggested n available Beru-taxi nearby. The i-th taxi is located at point (xi, yi) and moves with a speed vi. Consider that each of n drivers will move directly to Vasiliy ...
{ "input": [ "1 3\n3\n3 3 2\n-2 3 6\n-2 7 10\n", "0 0\n2\n2 0 1\n0 2 2\n" ], "output": [ "0.5\n", "1.0\n" ] }
{ "input": [ "66 -82\n43\n27 -21 70\n-64 46 58\n-7 -20 41\n-42 60 57\n-93 -7 95\n26 -61 26\n-10 -72 25\n-78 -18 55\n-62 -64 69\n-33 95 50\n24 59 45\n4 72 37\n66 57 61\n16 -60 5\n17 -78 36\n-75 56 59\n-60 98 77\n-94 37 28\n76 6 63\n99 -35 75\n69 -40 1\n9 -48 56\n-94 -11 19\n69 1 63\n43 42 80\n-28 -83 21\n100 -23 6...
900
500
2
10
749_D. Leaving Auction
There 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 people made no bids at all. Each bid is define by two integers (ai, bi), where ai is the index of the person, who made this ...
{ "input": [ "6\n1 10\n2 100\n3 1000\n1 10000\n2 100000\n3 1000000\n3\n1 3\n2 2 3\n2 1 2\n", "3\n1 10\n2 100\n1 1000\n2\n2 1 2\n2 2 3\n" ], "output": [ "2 100000\n1 10\n3 1000\n", "0 0\n1 10\n" ] }
{ "input": [ "4\n2 8\n1 14\n3 24\n1 30\n15\n1 1\n1 2\n2 1 2\n1 3\n2 1 3\n2 2 3\n3 1 2 3\n1 4\n2 1 4\n2 2 4\n3 1 2 4\n2 3 4\n3 1 3 4\n3 2 3 4\n4 1 2 3 4\n", "4\n1 3\n2 4\n3 5\n1 7\n15\n1 1\n1 2\n1 3\n1 4\n2 1 2\n2 1 3\n2 1 4\n2 2 3\n2 2 4\n2 3 4\n3 1 2 3\n3 1 2 4\n3 1 3 4\n3 2 3 4\n4 1 2 3 4\n", "1\n1 1\n1...
2,000
2,000
2
9
772_C. Vulnerable Kerbals
You are given an integer m, and a list of n distinct integers between 0 and m - 1. You would like to construct a sequence satisfying the properties: * Each element is an integer between 0 and m - 1, inclusive. * All prefix products of the sequence modulo m are distinct. * No prefix product modulo m appears as...
{ "input": [ "3 10\n2 9 1\n", "0 5\n" ], "output": [ "6\n3 9 2 4 8 0 ", "5\n1 2 4 3 0 \n" ] }
{ "input": [ "0 720\n", "0 1\n", "3 19997\n6068 18563 12338\n", "0 9997\n", "3 19997\n4524 13719 9073\n", "3 19997\n2024 4058 6143\n" ], "output": [ "397\n1 7 413 263 389 467 77 283 299 187 293 563 269 47 677 463 599 367 173 143 149 347 557 643 179 547 53 443 29 647 437 103 479 7 653 2...
2,300
1,750
2
9
797_C. Minimal string
Petya recieved a gift of a string s with length up to 105 characters for his birthday. He took two more empty strings t and u and decided to play a game. This game has two possible moves: * Extract the first character of s and append t with this character. * Extract the last character of t and append u with this ...
{ "input": [ "cab\n", "acdb\n" ], "output": [ "abc\n", "abdc\n" ] }
{ "input": [ "babcaaccb\n", "badbdc\n", "bbbb\n", "aaaa\n", "abcc\n", "aabbb\n", "bhrmc\n", "bbba\n", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n", "bdd\n", "bbababa\n", "ab\n", "accbb\n", "baaabab\n", ...
1,700
0
2
11
863_E. Turn Off The TV
Luba needs your help again! Luba has n TV sets. She knows that i-th TV set will be working from moment of time li till moment ri, inclusive. Luba wants to switch off one of TV sets in order to free the socket. Let's call some TV set redundant if after switching it off the number of integer moments of time when at leas...
{ "input": [ "3\n1 3\n4 6\n1 7\n", "3\n1 2\n3 4\n6 8\n", "3\n1 2\n2 3\n3 4\n", "2\n0 10\n0 10\n" ], "output": [ "1\n", "-1\n", "2\n", "1\n" ] }
{ "input": [ "4\n63 63\n12 34\n17 29\n58 91\n", "1\n0 0\n", "6\n42 60\n78 107\n6 38\n58 81\n70 105\n70 105\n", "2\n50 67\n54 64\n", "6\n99 100\n65 65\n34 34\n16 18\n65 67\n88 88\n", "3\n5 6\n1 3\n1 4\n", "2\n1 2\n1 3\n", "3\n1 5\n1 2\n4 5\n", "3\n1 10\n5 15\n10 20\n", "7\n28 42...
2,000
0
2
8
889_B. Restoration of string
A substring of some string is called the most frequent, if the number of its occurrences is not less than number of occurrences of any other substring. You are given a set of strings. A string (not necessarily from this set) is called good if all elements of the set are the most frequent substrings of this string. Res...
{ "input": [ "3\nkek\npreceq\ncheburek\n", "4\nmail\nai\nlru\ncf\n" ], "output": [ "NO\n", "cfmailru\n" ] }
{ "input": [ "4\nab\nbc\nca\nd\n", "26\nhw\nwb\nba\nax\nxl\nle\neo\nod\ndj\njt\ntm\nmq\nqf\nfk\nkn\nny\nyz\nzr\nrg\ngv\nvc\ncs\nsi\niu\nup\nph\n", "3\nabcd\nefg\ncdefg\n", "20\nckdza\nw\ntvylck\nbqtv\ntvylckd\nos\nbqtvy\nrpx\nzaj\nrpxebqtvylckdzajfmi\nbqtvylckdzajf\nvylc\ntvyl\npxebq\nf\npxebqtv\nlckd...
2,000
2,000
2
8
960_B. Minimize the error
You are given two arrays A and B, each of size n. The error, E, between these two arrays is defined <image>. You have to perform exactly k1 operations on array A and exactly k2 operations on array B. In one operation, you have to choose one element of the array and increase or decrease it by 1. Output the minimum poss...
{ "input": [ "2 1 0\n1 2\n2 2\n", "2 0 0\n1 2\n2 3\n", "2 5 7\n3 4\n14 4\n" ], "output": [ "0\n", "2\n", "1\n" ] }
{ "input": [ "1 5 7\n1\n2\n", "10 300 517\n-6 -2 6 5 -3 8 9 -10 8 6\n5 -9 -2 6 1 4 6 -2 5 -3\n", "2 1 3\n2 2\n2 2\n", "2 0 1\n1 2\n2 2\n", "1 1 2\n0\n8\n", "3 1 4\n0 0 0\n1 5 6\n", "1 0 6\n0\n0\n", "1 1000 0\n1000000\n-1000000\n", "10 561 439\n76639 67839 10670 -23 -18393 65114 465...
1,500
1,000
2
11
1017_E. The Supersonic Rocket
After the war, the supersonic rocket became the most common public transportation. Each supersonic rocket consists of two "engines". Each engine is a set of "power sources". The first engine has n power sources, and the second one has m power sources. A power source can be described as a point (x_i, y_i) on a 2-D plan...
{ "input": [ "3 4\n0 0\n0 2\n2 0\n0 2\n2 2\n2 0\n1 1\n", "3 4\n0 0\n0 2\n2 0\n0 2\n2 2\n2 0\n0 0\n" ], "output": [ "YES\n", "NO\n" ] }
{ "input": [ "3 3\n1 1\n2 2\n3 3\n1 1\n1 2\n1 3\n", "5 5\n2 0\n0 4\n4 8\n8 4\n10 0\n0 2\n2 6\n6 10\n10 6\n8 2\n", "6 3\n0 0\n1 1\n2 2\n3 3\n4 4\n5 5\n0 6\n3 3\n6 0\n", "4 4\n0 0\n1 0\n1 1\n2 1\n0 1\n1 1\n1 0\n2 0\n", "4 4\n0 5\n5 10\n5 0\n10 5\n0 1\n7 2\n14 1\n7 0\n", "8 8\n53212775 61830464\n...
2,400
2,000
2
8
1041_B. Buying a TV Set
Monocarp has decided to buy a new TV set and hang it on the wall in his flat. The wall has enough free space so Monocarp can buy a TV set with screen width not greater than a and screen height not greater than b. Monocarp is also used to TV sets with a certain aspect ratio: formally, if the width of the screen is w, an...
{ "input": [ "4 2 6 4\n", "1000000000000000000 1000000000000000000 999999866000004473 999999822000007597\n", "14 16 7 22\n", "17 15 5 3\n" ], "output": [ "1\n", "1000000063\n", "0\n", "3\n" ] }
{ "input": [ "500 500 1000000000000000000 1\n", "281474976710656 1 1 281474976710656\n", "100 81 10 9\n", "100000 1 3 2\n", "3 3 2 4\n", "1043706193704 1177988368866 2133416547786 1380684288366\n", "1760355542088 1044709015401 1674331546848 2647835033212\n", "165 500 388 308\n", "2...
1,000
1,000
2
7
1064_A. Make a triangle!
Masha has three sticks of length a, b and c centimeters respectively. In one minute Masha can pick one arbitrary stick and increase its length by one centimeter. She is not allowed to break sticks. What is the minimum number of minutes she needs to spend increasing the stick's length in order to be able to assemble a ...
{ "input": [ "3 4 5\n", "100 10 10\n", "2 5 3\n" ], "output": [ "0\n", "81\n", "1\n" ] }
{ "input": [ "3 1 1\n", "68 1 67\n", "100 100 100\n", "14 21 76\n", "32 99 10\n", "2 10 2\n", "4 2 7\n", "100 1 1\n", "2 5 2\n", "100 1 99\n", "56 42 87\n", "4 5 6\n", "100 100 99\n", "23 56 33\n", "86 43 10\n", "2 3 6\n", "1 7 35\n", "88 2 6\n",...
800
500
2
10
1105_D. Kilani and the Game
Kilani is playing a game with his friends. This game can be represented as a grid of size n Γ— m, where each cell is either empty or blocked, and every player has one or more castles in some cells (there are no two castles in one cell). The game is played in rounds. In each round players expand turn by turn: firstly, t...
{ "input": [ "3 3 2\n1 1\n1..\n...\n..2\n", "3 4 4\n1 1 1 1\n....\n#...\n1234\n" ], "output": [ "6 3 \n", "1 4 3 3 \n" ] }
{ "input": [ "4 4 2\n5 1\n1#.2\n.#..\n.##.\n....\n", "2 3 2\n1 2\n...\n21.\n", "3 8 3\n1 1 1\n.222.321\n2.##3.31\n2#1.2131\n", "3 3 2\n4 1\n1#2\n.#.\n...\n", "3 7 1\n1\n###11..\n1...11.\n.1#1##.\n", "4 4 2\n1 1000000000\n....\n....\n..2.\n...1\n", "4 4 2\n1 1000000000\n....\n....\n..1.\n.....
1,900
2,000
2
9
1153_C. Serval and Parenthesis Sequence
Serval soon said goodbye to Japari kindergarten, and began his life in Japari Primary School. In his favorite math class, the teacher taught him the following interesting definitions. A parenthesis sequence is a string, containing only characters "(" and ")". A correct parenthesis sequence is a parenthesis sequence ...
{ "input": [ "6\n(?????\n", "10\n(???(???(?\n" ], "output": [ "((()))\n", ":(\n" ] }
{ "input": [ "30\n((??)?)???(????(????)???????((\n", "6\n))??((\n", "4\n??(?\n", "6\n((?())\n", "300\n)?)???????(?????????)??)??)?)??)??()???)??)??????????(?)???(?????)????????????????????)?????)???(???????)?????)?)??????????????))????(?)??????)???)?(?????????)?))???)???????????????))))???)???)???...
1,700
1,500
2
8
1175_B. Catch Overflow!
You are given a function f written in some basic language. The function accepts an integer value, which is immediately written into some variable x. x is an integer variable and can be assigned values from 0 to 2^{32}-1. The function contains three types of commands: * for n β€” for loop; * end β€” every command betw...
{ "input": [ "2\nfor 62\nend\n", "11\nfor 100\nfor 100\nfor 100\nfor 100\nfor 100\nadd\nend\nend\nend\nend\nend\n", "9\nadd\nfor 43\nend\nfor 10\nfor 15\nadd\nend\nadd\nend\n" ], "output": [ "0\n", "OVERFLOW!!!\n", "161\n" ] }
{ "input": [ "40\nfor 61\nfor 28\nfor 84\nadd\nend\nend\nadd\nend\nadd\nadd\nfor 27\nfor 55\nfor 70\nfor 81\nadd\nadd\nfor 23\nfor 89\nfor 97\nfor 58\nfor 83\nadd\nfor 42\nadd\nadd\nfor 100\nfor 75\nadd\nend\nend\nend\nend\nend\nend\nend\nend\nend\nend\nend\nend\n", "23\nfor 84\nfor 84\nfor 84\nfor 84\nfor 84...
1,600
0
2
7
1194_A. Remove a Progression
You have a list of numbers from 1 to n written from left to right on the blackboard. You perform an algorithm consisting of several steps (steps are 1-indexed). On the i-th step you wipe the i-th number (considering only remaining numbers). You wipe the whole number (not one digit). <image> When there are less than ...
{ "input": [ "3\n3 1\n4 2\n69 6\n" ], "output": [ "2\n4\n12\n" ] }
{ "input": [ "1\n241139 1\n", "1\n2441139 10\n", "1\n2452199 2\n", "1\n244139 1\n", "1\n2451199 2\n", "1\n244119 1\n", "1\n2441139 12\n", "1\n2441139 2\n", "2\n1000000000 1\n1000000000 500000000\n", "1\n2441139 1\n" ], "output": [ "2\n", "20\n", "4\n", "2\n"...
800
0
2
12
1272_F. Two Bracket Sequences
You are given two bracket sequences (not necessarily regular) s and t consisting only of characters '(' and ')'. You want to construct the shortest regular bracket sequence that contains both given bracket sequences as subsequences (not necessarily contiguous). Recall what is the regular bracket sequence: * () is t...
{ "input": [ ")\n)))\n", "())\n(()(()(()(\n", ")\n((\n", "(())(()\n()))()\n" ], "output": [ "((()))\n", "(()(()(()())))\n", "(())\n", "(())()()\n" ] }
{ "input": [ "()))()))))())(()))))))))()()()(()))()((()()()(()))()()()()((((())))))()))))(((())(()))())(())((()(((\n)\n", ")(()(((((()))(()))((()((((((()(())))((()()))()(())))(()))))()(()((((()(())))((()((((())(()))((())))))()()()(()()(()(())()(())()((()()())())()()))()())()((((())((()()))(())((())()()()())((...
2,200
0
2
7
1296_A. Array with Odd Sum
You are given an array a consisting of n integers. In one move, you can choose two indices 1 ≀ i, j ≀ n such that i β‰  j and set a_i := a_j. You can perform such moves any number of times (possibly, zero). You can choose different indices in different operations. The operation := is the operation of assignment (i.e. yo...
{ "input": [ "5\n2\n2 3\n4\n2 2 8 8\n3\n3 3 3\n4\n5 5 5 5\n4\n1 1 1 1\n" ], "output": [ "YES\nNO\nYES\nNO\nNO\n" ] }
{ "input": [ "1\n1\n114\n" ], "output": [ "NO\n" ] }
800
0
2
7
131_A. cAPS lOCK
wHAT DO WE NEED cAPS LOCK FOR? Caps lock is a computer keyboard key. Pressing it sets an input mode in which typed letters are capital by default. If it is pressed by accident, it leads to accidents like the one we had in the first passage. Let's consider that a word has been typed with the Caps lock key accidentall...
{ "input": [ "cAPS\n", "Lock\n" ], "output": [ "Caps\n", "Lock\n" ] }
{ "input": [ "A\n", "Zz\n", "XweAR\n", "F\n", "OOPS\n", "zA\n", "mogqx\n", "LoCK\n", "z\n", "aaAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\n", "aTF\n", "cAPSlOCK\n", "cTKDZNWVYRTFPQLDAUUNSPKTDJTUPPFPRXRSINTVFVNNQNKXWUZUDHZBUSOKTABUEDQKUIVRTTVUREEOBJTSDKJKVEGFXVHXEY...
1,000
500
2
10
1444_D. Rectangular Polyline
One drew a closed polyline on a plane, that consisted only of vertical and horizontal segments (parallel to the coordinate axes). The segments alternated between horizontal and vertical ones (a horizontal segment was always followed by a vertical one, and vice versa). The polyline did not contain strict self-intersecti...
{ "input": [ "2\n2\n1 1\n2\n1 1\n\n2\n1 2\n2\n3 3\n", "2\n4\n1 1 1 1\n4\n1 1 1 1\n\n3\n2 1 1\n3\n2 1 1\n", "2\n4\n1 4 1 2\n4\n3 4 5 12\n\n4\n1 2 3 6\n2\n1 3\n" ], "output": [ "Yes\n1 0\n1 1\n0 1\n0 0\nNo\n", "YES\n1 0\n1 1\n2 1\n2 2\n1 2\n1 1\n0 1\n0 0\nYES\n2 0\n2 1\n1 1\n1 2\n0 2\n0 0\n", ...
{ "input": [ "1\n4\n4 4 3 5\n4\n3 3 3 3\n", "12\n4\n3 4 4 5\n4\n3 3 3 3\n\n4\n3 4 5 4\n4\n3 3 3 3\n\n4\n3 5 4 4\n4\n3 3 3 3\n\n4\n4 3 4 5\n4\n3 3 3 3\n\n4\n4 3 5 4\n4\n3 3 3 3\n\n4\n4 4 3 5\n4\n3 3 3 3\n\n4\n4 4 5 3\n4\n3 3 3 3\n\n4\n4 5 3 4\n4\n3 3 3 3\n\n4\n4 5 4 3\n4\n3 3 3 3\n\n4\n5 3 4 4\n4\n3 3 3 3\n\n4...
2,900
2,000
2
11
1469_E. A Bit Similar
Let's call two strings a and b (both of length k) a bit similar if they have the same character in some position, i. e. there exists at least one i ∈ [1, k] such that a_i = b_i. You are given a binary string s of length n (a string of n characters 0 and/or 1) and an integer k. Let's denote the string s[i..j] as the su...
{ "input": [ "7\n4 2\n0110\n4 2\n1001\n9 3\n010001110\n9 3\n101110001\n10 3\n0101110001\n10 10\n1111111111\n11 10\n11111111110\n" ], "output": [ "\nYES\n11\nYES\n00\nYES\n010\nYES\n101\nNO\nYES\n0000000001\nYES\n0000000010\n" ] }
{ "input": [ "2\n64 32\n0000000001111111111111111111111011111111111111111111111111111111\n66 33\n000000000111111111111111111111110111111111111111111111111111111111\n", "1\n100 99\n0000000000111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n", "3\n22 22\n1111111111...
2,400
0
2
10
172_D. Calendar Reform
Reforms have started in Berland again! At this time, the Parliament is discussing the reform of the calendar. To make the lives of citizens of Berland more varied, it was decided to change the calendar. As more and more people are complaining that "the years fly by...", it was decided that starting from the next year t...
{ "input": [ "25 3\n", "50 5\n" ], "output": [ "30\n", "125\n" ] }
{ "input": [ "1 10\n", "1 5000000\n", "1 2\n", "1000000 5000000\n", "4000000 5000000\n", "5000000 5000000\n", "3000000 5000000\n", "1 1\n", "1 10000000\n" ], "output": [ "38\n", "8224640917276\n", "3\n", "11514506860120\n", "21384022194564\n", "246742312...
1,500
1,500
2
11
216_E. Martian Luck
You know that the Martians use a number system with base k. Digit b (0 ≀ b < k) is considered lucky, as the first contact between the Martians and the Earthlings occurred in year b (by Martian chronology). A digital root d(x) of number x is a number that consists of a single digit, resulting after cascading summing of...
{ "input": [ "7 6 4\n3 5 0 4\n", "10 5 6\n3 2 0 5 6 1\n", "257 0 3\n0 0 256\n" ], "output": [ "1\n", "5\n", "3\n" ] }
{ "input": [ "2 1 1\n0\n", "8 5 205\n5 6 5 0 2 1 1 3 7 2 1 7 7 7 7 6 5 5 0 2 0 7 4 3 0 4 3 6 6 4 1 5 0 3 2 5 2 5 6 3 5 7 6 6 3 4 4 0 0 5 6 4 2 7 4 1 2 1 5 5 1 2 5 2 3 7 2 3 6 2 1 7 3 3 5 5 4 3 0 6 4 4 0 6 2 2 3 3 5 4 2 4 0 2 1 2 7 0 5 1 0 2 4 0 3 6 0 4 2 4 4 1 1 0 5 0 6 6 1 1 1 5 3 3 5 5 4 6 5 0 3 0 7 3 6 4 4...
2,000
3,000
2
11
23_E. Tree
Recently Bob invented a new game with a tree (we should remind you, that a tree is a connected graph without cycles): he deletes any (possibly, zero) amount of edges of the tree, and counts the product of sizes of the connected components left after the deletion. Your task is to find out the maximum number that Bob can...
{ "input": [ "5\n1 2\n2 3\n3 4\n4 5\n", "3\n1 2\n1 3\n", "8\n1 2\n1 3\n2 4\n2 5\n3 6\n3 7\n6 8\n" ], "output": [ " 6\n", " 3\n", " ...
{ "input": [ "10\n4 8\n10 2\n6 3\n10 9\n2 3\n4 1\n7 10\n2 1\n5 1\n", "5\n1 5\n4 3\n2 4\n4 1\n", "10\n8 10\n5 7\n1 6\n4 9\n3 8\n8 9\n2 3\n5 8\n8 1\n", "15\n4 6\n15 1\n3 8\n15 2\n13 11\n9 10\n14 4\n9 12\n11 6\n8 10\n4 5\n2 11\n7 8\n8 4\n", "50\n45 39\n18 12\n13 6\n48 45\n46 36\n46 8\n40 36\n29 28\n2...
2,500
0
2
9
265_C. Escape from Stones
Squirrel Liss lived in a forest peacefully, but unexpected trouble happens. Stones fall from a mountain. Initially Squirrel Liss occupies an interval [0, 1]. Next, n stones will fall and Liss will escape from the stones. The stones are numbered from 1 to n in order. The stones always fall to the center of Liss's inter...
{ "input": [ "lrlrr\n", "llrlr\n", "rrlll\n" ], "output": [ "2\n4\n5\n3\n1\n", "3\n5\n4\n2\n1\n", "1\n2\n5\n4\n3\n" ] }
{ "input": [ "r\n", "llrlrlllrrllrllllrlrrlrlrrllrlrlrrlrrrrrrlllrrlrrrrrlrrrlrlrlrrlllllrrrrllrrlrlrrrllllrlrrlrrlrlrrll\n", "llrrrrllrrlllrlrllrlrllllllrrrrrrrrllrrrrrrllrlrrrlllrrrrrrlllllllrrlrrllrrrllllrrlllrrrlrlrrlrlrllr\n", "rrlllrrrlrrlrrrlllrlrlrrrlllrllrrllrllrrlrlrrllllrlrrrrlrlllrlrrrlrlr...
1,200
500
2
9
289_C. Polo the Penguin and Strings
Little 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: 1. The string consists of n lowercase English letters (that is, the string's length equals n), exactly k of these letters are distinct. 2. No two neighbouring...
{ "input": [ "7 4\n", "4 7\n" ], "output": [ "ababacd\n", "-1\n" ] }
{ "input": [ "6875 2\n", "3 3\n", "10 7\n", "47 2\n", "100000 7\n", "4585 1\n", "12 17\n", "26 26\n", "68754 25\n", "47 1\n", "6875 2\n", "1000000 1\n", "128 26\n", "100000 20\n", "26 2\n", "1 1\n", "68754 25\n", "6795 1\n", "100000 7\n", ...
1,300
500
2
11
430_E. Guess the Tree
Iahub and Iahubina went to a picnic in a forest full of trees. Less than 5 minutes passed before Iahub remembered of trees from programming. Moreover, he invented a new problem and Iahubina has to solve it, otherwise Iahub won't give her the food. Iahub asks Iahubina: can you build a rooted tree, such that * each ...
{ "input": [ "4\n1 1 1 4\n", "5\n1 1 5 2 1\n" ], "output": [ "YES\n", "NO" ] }
{ "input": [ "18\n6 1 1 3 1 1 1 1 1 1 4 1 8 1 1 18 1 5\n", "19\n9 7 1 8 1 1 1 13 1 1 3 3 19 1 1 1 1 1 1\n", "23\n1 1 1 1 3 7 3 1 1 1 3 7 1 3 1 15 1 3 7 3 23 1 1\n", "24\n8 5 3 1 1 5 10 1 1 1 1 5 1 2 7 3 4 1 1 24 1 1 2 8\n", "12\n12 7 4 3 3 1 1 1 1 1 1 1\n", "20\n20 9 4 4 3 3 3 1 1 1 1 1 1 1 1 ...
2,300
1,500
2
7
49_A. Sleuth
Vasya plays the sleuth with his friends. The rules of the game are as follows: those who play for the first time, that is Vasya is the sleuth, he should investigate a "crime" and find out what is happening. He can ask any questions whatsoever that can be answered with "Yes" or "No". All the rest agree beforehand to ans...
{ "input": [ "Is it an apple?\n", "Is it a banana ?\n", "Is it an apple and a banana simultaneouSLY?\n", "Is it a melon?\n" ], "output": [ "YES", "YES", "YES", "NO" ] }
{ "input": [ "iehvZNQXDGCuVmJPOEysLyUryTdfaIxIuTzTadDbqRQGoCLXkxnyfWSGoLXebNnQQNTqAQJebbyYvHOfpUnXeWdjx?\n", "hh?\n", "j ?\n", "J ?\n", "o ?\n", "T ?\n", "GlEmEPKrYcOn...
800
500
2
9
523_C. Name Quest
A Martian boy is named s β€” he has got this name quite recently from his parents for his coming of age birthday. Now he enjoys looking for his name everywhere. If he sees that he can obtain his name from some string by removing zero or more letters (at that, the remaining letters remain in the same order), he gets happy...
{ "input": [ "mars\nsunvenusearthmarsjupitersaturnuranusneptune\n", "aba\nbaobababbah\n" ], "output": [ "0\n", "2\n" ] }
{ "input": [ "a\na\n", "a\naaaaaaaaaaaaaa\n", "lol\nlol\n", "rry\nsorrymercuryismissedabove\n", "aaaaaaaaaaaa\naaaaaa\n", "abcaba\nabcabaabcabaabcabaabcaba\n" ], "output": [ "0\n", "13\n", "0\n", "3\n", "0\n", "13\n" ] }
1,400
1,500
2
7
54_A. Presents
The Hedgehog likes to give presents to his friend, but no less he likes to receive them. Having received another present today, the Hedgehog suddenly understood that he has no place to put it as there was no room left on the special shelf in the cupboard. He will have to choose another shelf, but which one should he c...
{ "input": [ "10 1\n3 6 7 8\n", "5 2\n1 3\n" ], "output": [ "10\n", "3\n" ] }
{ "input": [ "350 16\n12 31 76 103 116 191 201 241 256 260 291 306 336\n", "365 40\n30 1 14 21 31 32 36 56 59 68 96 119 131 137 166 179 181 202 235 248 272 294 309 315 322 327 334 341 347 362 365\n", "150 3\n0\n", "15 3\n1 11\n", "300 2\n14 29 94 122 123 158 160 164 191 200 202 208 246 272 286\n",...
1,300
500
2
8
576_B. Invariance of Tree
A tree of size n is an undirected connected graph consisting of n vertices without cycles. Consider some tree with n vertices. We call a tree invariant relative to permutation p = p1p2... pn, if for any two vertices of the tree u and v the condition holds: "vertices u and v are connected by an edge if and only if vert...
{ "input": [ "3\n3 1 2\n", "4\n4 3 2 1\n" ], "output": [ "NO\n", "YES\n1 4\n1 2\n4 3\n" ] }
{ "input": [ "6\n4 1 2 3 6 5\n", "6\n2 1 4 5 6 3\n", "5\n5 3 2 1 4\n", "11\n7 3 5 2 10 1 9 6 8 4 11\n", "6\n2 1 6 5 3 4\n", "3\n3 2 1\n", "2\n2 1\n", "2\n1 2\n", "4\n2 3 4 1\n", "4\n3 4 1 2\n", "8\n1 2 6 4 5 7 8 3\n", "6\n2 3 4 1 6 5\n", "1\n1\n" ], "output": [ ...
2,100
1,250
2
12
598_F. Cut Length
Given simple (without self-intersections) n-gon. It is not necessary convex. Also you are given m lines. For each line find the length of common part of the line and the n-gon. The boundary of n-gon belongs to polygon. It is possible that n-gon contains 180-degree angles. Input The first line contains integers n and...
{ "input": [ "4 3\n0 0\n1 0\n1 1\n0 1\n0 0 1 1\n0 0 0 1\n0 0 1 -1\n" ], "output": [ "1.414213562373095145\n1.000000000000000000\n0.000000000000000000\n" ] }
{ "input": [ "4 9\n0 0\n0 1\n1 1\n1 0\n0 0 1 1\n1 1 0 0\n0 0 1 0\n0 0 0.5 0\n0 0.5 1 0.5\n0 1 1 1\n1 1 1 0\n0.75 0.75 0.75 0.25\n0 0.25 1 0.75\n", "3 1\n2 2\n100000 100000\n-99999.99 -100000\n100000 100000 -99999.99 -100000\n", "9 5\n0 0\n0 2\n1 1\n2 2\n3 1\n4 2\n5 1\n6 2\n6 0\n-1 2 7.5 1\n0 1 6 1\n0 1.5 ...
2,900
0
2
10
61_D. Eternal Victory
Valerian was captured by Shapur. The victory was such a great one that Shapur decided to carve a scene of Valerian's defeat on a mountain. So he had to find the best place to make his victory eternal! He decided to visit all n cities of Persia to find the best available mountain, but after the recent war he was too ti...
{ "input": [ "3\n1 2 3\n2 3 4\n", "3\n1 2 3\n1 3 3\n" ], "output": [ "7", "9" ] }
{ "input": [ "1\n", "6\n1 2 3\n1 3 1\n3 4 1\n4 5 1\n5 6 1\n", "3\n1 2 0\n2 3 0\n", "2\n2 1 89\n", "12\n3 2 52\n4 1 2\n5 2 68\n6 1 93\n8 5 60\n2 1 88\n9 8 44\n7 5 48\n11 2 31\n10 4 45\n12 7 58\n", "13\n8 2 58\n2 1 49\n13 10 41\n11 9 67\n6 4 18\n7 1 79\n3 2 58\n9 7 92\n10 6 62\n4 3 5\n12 4 87\n5...
1,800
2,000
2
9
63_C. Bulls and Cows
The "Bulls and Cows" game needs two people to play. The thinker thinks of a number and the guesser tries to guess it. The thinker thinks of a four-digit number in the decimal system. All the digits in the number are different and the number may have a leading zero. It can't have more than one leading zero, because all...
{ "input": [ "2\n1263 1 2\n8103 2 1\n", "2\n0123 1 1\n4567 1 2\n", "2\n1234 2 2\n1256 0 2\n" ], "output": [ "Need more data", "Incorrect data", "2134" ] }
{ "input": [ "4\n1689 0 1\n0159 0 2\n4326 0 1\n9048 0 2\n", "4\n0123 1 3\n3012 1 3\n2301 2 2\n1230 0 4\n", "3\n6108 0 3\n4975 1 1\n0981 1 2\n", "2\n1340 0 0\n2435 0 0\n", "10\n0132 0 1\n6801 0 1\n8749 1 1\n8036 0 0\n7384 0 2\n8594 1 1\n9307 1 0\n7390 0 1\n6127 1 1\n0381 0 1\n", "4\n1789 1 0\n7...
1,700
1,500
2
7
669_A. Little Artem and Presents
Little Artem got n stones on his birthday and now wants to give some of them to Masha. He knows that Masha cares more about the fact of receiving the present, rather than the value of that present, so he wants to give her stones as many times as possible. However, Masha remembers the last present she received, so Artem...
{ "input": [ "3\n", "1\n", "2\n", "4\n" ], "output": [ "2", "1", "1", "3" ] }
{ "input": [ "999999996\n", "1000000000\n", "999999999\n", "999999992\n", "102\n", "999999998\n", "999999994\n", "6\n", "1000000\n", "1000\n", "999999993\n", "100\n", "5\n", "999999991\n", "7\n", "100000\n", "100000000\n", "10000000\n", "1000...
800
500
2
9
714_C. Sonya and Queries
Today Sonya learned about long integers and invited all her friends to share the fun. Sonya has an initially empty multiset with integers. Friends give her t queries, each of one of the following type: 1. + ai β€” add non-negative integer ai to the multiset. Note, that she has a multiset, thus there may be many occur...
{ "input": [ "12\n+ 1\n+ 241\n? 1\n+ 361\n- 241\n? 0101\n+ 101\n? 101\n- 101\n? 101\n+ 4000\n? 0\n", "4\n+ 200\n+ 200\n- 200\n? 0\n" ], "output": [ "2\n1\n2\n1\n1\n", "1\n" ] }
{ "input": [ "20\n+ 8\n+ 39532\n+ 813\n- 39532\n? 00011\n? 00000\n? 00011\n+ 70424\n- 8\n? 00011\n- 70424\n? 00011\n+ 29\n? 00001\n+ 6632\n+ 3319\n? 00001\n+ 3172\n? 01111\n- 29\n", "10\n+ 2\n- 2\n+ 778\n+ 3\n+ 4\n- 4\n+ 1\n+ 617\n? 011\n? 011\n", "20\n+ 61\n+ 99\n+ 51\n+ 70\n+ 7\n+ 34\n+ 71\n+ 86\n+ 68\n...
1,400
500
2
12
758_F. Geometrical Progression
For 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 progression the following must hold: l ≀ ai ≀ r and ai β‰  aj , where a1, a2, ..., an is the geometrical progression, 1 ≀ i, j ≀ n and i β‰  j...
{ "input": [ "3 1 10\n", "3 3 10\n", "1 1 10\n", "2 6 9\n" ], "output": [ "8\n", "2\n", "10\n", "12\n" ] }
{ "input": [ "3 100 1000000\n", "19 1 10000000\n", "10 100 1000000\n", "7 1 5000000\n", "5 1 5000000\n", "18 1 10000000\n", "8 100 1000000\n", "10000000 1 1\n", "5 25 845\n", "6 100 1000000\n", "13 100 1000000\n", "8 123 456789\n", "2 5000000 10000000\n", "12 12...
2,400
3,000
2
9
803_C. Maximal GCD
You are given positive integer number n. You should create such strictly increasing sequence of k positive numbers a1, a2, ..., ak, that their sum is equal to n and greatest common divisor is maximal. Greatest common divisor of sequence is maximum of such numbers that every element of sequence is divisible by them. I...
{ "input": [ "8 2\n", "5 3\n", "6 3\n" ], "output": [ "2 6 \n", "-1\n", "1 2 3 \n" ] }
{ "input": [ "2000 9324327498\n", "4 3\n", "9 2\n", "1 8\n", "6 1\n", "4294967296 4294967296\n", "479001600 4\n", "1 4\n", "479001600 6\n", "7 5\n", "7 8\n", "12344321 1\n", "4 1\n", "7 6\n", "3000000021 100000\n", "2 4\n", "7 4\n", "3 10\n", ...
1,900
0
2
7
828_A. Restaurant Tables
In a small restaurant there are a tables for one person and b tables for two persons. It it known that n groups of people come today, each consisting of one or two people. If a group consist of one person, it is seated at a vacant one-seater table. If there are none of them, it is seated at a vacant two-seater tabl...
{ "input": [ "4 1 1\n1 1 2 1\n", "4 1 2\n1 2 1 1\n" ], "output": [ "2\n", "0\n" ] }
{ "input": [ "5 2 2\n2 1 2 1 2\n", "20 4 3\n2 2 2 2 2 2 2 2 1 2 1 1 2 2 1 2 2 2 1 2\n", "3 1 2\n1 1 2\n", "6 1 4\n1 2 2 1 2 2\n", "8 1 4\n2 1 1 1 2 2 2 2\n", "3 10 2\n2 2 2\n", "3 5 1\n2 2 2\n", "4 1 1\n1 1 1 1\n", "1 1 1\n1\n", "3 3 1\n2 2 1\n", "5 3 3\n2 2 2 2 2\n", "...
1,200
500
2
8
84_B. Magical Array
Valery is very interested in magic. Magic attracts him so much that he sees it everywhere. He explains any strange and weird phenomenon through intervention of supernatural forces. But who would have thought that even in a regular array of numbers Valera manages to see something beautiful and magical. Valera absolutel...
{ "input": [ "4\n2 1 1 4\n", "5\n-2 -2 -2 0 1\n" ], "output": [ "5", "8" ] }
{ "input": [ "50\n2 0 2 0 0 0 0 -1 -2 -2 -2 1 1 2 2 0 2 0 2 -3 0 0 0 0 3 1 -2 0 -1 0 -2 3 -1 2 0 2 0 0 0 0 2 0 1 0 0 3 0 0 -2 0\n", "10\n7 1 0 10 0 -5 -3 -2 0 0\n", "2\n5 6\n", "2\n-510468670 0\n", "12\n-4 3 3 2 3 3 3 -4 2 -4 -4 -4\n", "20\n6 0 0 -3 1 -3 0 -8 1 3 5 2 -1 -5 -1 9 0 6 -2 4\n", ...
1,300
500
2
10
898_D. Alarm Clock
Every evening Vitalya sets n alarm clocks to wake up tomorrow. Every alarm clock rings during exactly one minute and is characterized by one integer ai β€” number of minute after midnight in which it rings. Every alarm clock begins ringing at the beginning of the minute and rings during whole minute. Vitalya will defin...
{ "input": [ "2 2 2\n1 3\n", "3 3 2\n3 5 1\n", "7 7 2\n7 3 4 1 6 5 2\n", "5 10 3\n12 8 18 25 1\n" ], "output": [ "0\n", "1\n", "6\n", "0\n" ] }
{ "input": [ "13 10 4\n5 28 67 70 68 3 84 4 30 82 96 37 49\n", "15 20 15\n8 18 12 15 1 9 4 21 23 3 24 5 2 25 14\n", "10 7 2\n30 9 1 40 34 4 35 27 11 3\n", "20 30 10\n37 220 115 125 266 821 642 424 376 542 91 997 813 858 770 447 760 362 392 132\n", "20 5 2\n2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 1...
1,600
1,750
2
11
919_E. Congruence Equation
Given an integer x. Your task is to find out how many positive integers n (1 ≀ n ≀ x) satisfy $$$n β‹… a^n ≑ b (mod\;p), where a, b, p$$$ are all known constants. Input The only line contains four integers a,b,p,x (2 ≀ p ≀ 10^6+3, 1 ≀ a,b < p, 1 ≀ x ≀ 10^{12}). It is guaranteed that p is a prime. Output Print a sin...
{ "input": [ "4 6 7 13\n", "233 233 10007 1\n", "2 3 5 8\n" ], "output": [ "1\n", "1\n", "2\n" ] }
{ "input": [ "66634 64950 66889 215112576953\n", "339138 549930 999883 962863668031\n", "699601 39672 1000003 1\n", "28361 465012 1000003 12693229\n", "533806 514846 1000003 999999999999\n", "620328 378284 999983 189501757723\n", "419620 683571 999979 243073161801\n", "629260 663548 73...
2,100
2,000
2
10
946_D. Timetable
Ivan is a student at Berland State University (BSU). There are n days in Berland week, and each of these days Ivan might have some classes at the university. There are m working hours during each Berland day, and each lesson at the university lasts exactly one hour. If at some day Ivan's first lesson is during i-th ho...
{ "input": [ "2 5 0\n01001\n10110\n", "2 5 1\n01001\n10110\n" ], "output": [ "8", "5" ] }
{ "input": [ "10 10 0\n1000000001\n1000000001\n1000000001\n1000000001\n1000000001\n1000000001\n1000000001\n1000000001\n1000000001\n1000000001\n", "1 5 1\n10001\n", "3 4 0\n0000\n0000\n0000\n", "1 1 5\n1\n", "1 1 1\n1\n", "4 16 11\n1111011101111111\n0111110111111111\n0011101111011000\n000001000...
1,800
0
2
8
975_B. Mancala
Mancala is a game famous in the Middle East. It is played on a board that consists of 14 holes. <image> Initially, each hole has a_i stones. When a player makes a move, he chooses a hole which contains a positive number of stones. He takes all the stones inside it and then redistributes these stones one by one in th...
{ "input": [ "0 1 1 0 0 0 0 0 0 7 0 0 0 0\n", "5 1 1 1 1 0 0 0 0 0 0 0 0 0\n" ], "output": [ "4\n", "8\n" ] }
{ "input": [ "787 393 649 463 803 365 81 961 989 531 303 407 579 915\n", "10001 10001 10001 10001 10001 10001 10001 10001 10001 10001 10001 10001 10001 1\n", "8789651 4466447 1218733 6728667 1796977 6198853 8263135 6309291 8242907 7136751 3071237 5397369 6780785 9420869\n", "0 0 0 0 0 0 0 0 0 0 0 0 1 ...
1,100
1,000
2
7
995_A. Tesla
Allen dreams of one day owning a enormous fleet of electric cars, the car of the future! He knows that this will give him a big status boost. As Allen is planning out all of the different types of cars he will own and how he will arrange them, he realizes that he has a problem. Allen's future parking lot can be repre...
{ "input": [ "4 5\n1 2 0 4\n1 2 0 4\n5 0 0 3\n0 5 0 3\n", "1 2\n1\n1\n2\n2\n", "1 2\n1\n2\n1\n2\n" ], "output": [ "6\n1 1 1\n2 1 2\n4 1 4\n3 4 4\n5 3 2\n5 4 2\n", "2\n1 1 1\n2 4 1\n", "-1\n" ] }
{ "input": [ "2 1\n0 0\n0 0\n0 1\n0 1\n", "7 14\n2 11 1 14 9 8 5\n12 6 7 1 10 2 3\n14 13 9 8 5 4 11\n13 6 4 3 12 7 10\n", "48 17\n0 0 0 0 0 0 14 0 0 0 0 2 0 0 0 0 0 0 0 0 0 0 0 0 0 8 0 0 16 0 0 0 1 0 0 0 3 0 0 15 0 0 0 0 0 0 0 11\n0 0 0 0 0 0 0 0 0 0 17 0 0 0 6 0 0 0 8 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 13 0 3...
2,100
500
2
9
1012_C. Hills
Welcome to Innopolis city. Throughout the whole year, Innopolis citizens suffer from everlasting city construction. From the window in your room, you see the sequence of n hills, where i-th of them has height ai. The Innopolis administration wants to build some houses on the hills. However, for the sake of city appea...
{ "input": [ "5\n1 2 3 2 2\n", "3\n1 2 3\n", "5\n1 1 1 1 1\n" ], "output": [ "0 1 3 ", "0 2 ", "1 2 2 " ] }
{ "input": [ "9\n1 100 1 100 1 100 1 100 1\n", "100\n637 61 394 666 819 664 274 652 123 152 765 524 375 60 812 832 20 275 85 193 846 815 538 807 15 439 688 882 272 630 132 669 820 646 757 233 470 778 97 450 304 439 240 586 531 59 192 456 540 689 747 507 570 379 375 57 653 512 325 816 640 322 827 48 248 94 838...
1,900
1,500
2
9
1037_C. Equalize
You are given two binary strings a and b of the same length. You can perform the following two operations on the string a: * Swap any two bits at indices i and j respectively (1 ≀ i, j ≀ n), the cost of this operation is |i - j|, that is, the absolute difference between i and j. * Select any arbitrary index i (1 ...
{ "input": [ "4\n0101\n0011\n", "3\n100\n001\n" ], "output": [ "1\n", "2\n" ] }
{ "input": [ "91\n0010010000110001001011011011111001000110001000100111110010010001100110010111100111011111100\n1101110110000100110000100011010110111101100000011011100111111000110000001101101111100100101\n", "19\n1111010011111010100\n1010000110100110110\n", "7\n1110001\n0000000\n", "4\n1000\n0001\n", ...
1,300
1,000
2
11
1081_E. Missing Numbers
Chouti is working on a strange math problem. There was a sequence of n positive integers x_1, x_2, …, x_n, where n is even. The sequence was very special, namely for every integer t from 1 to n, x_1+x_2+...+x_t is a square of some integer number (that is, a [perfect square](https://en.wikipedia.org/wiki/Square_number)...
{ "input": [ "6\n5 11 44\n", "6\n314 1592 6535\n", "2\n9900\n" ], "output": [ "Yes\n4 5 16 11 64 44 ", "No\n", "Yes\n100 9900 " ] }
{ "input": [ "4\n35 15\n", "82\n24 192 896 1568 2907 4840 7475 9775 11109 29939 22475 45951 46552 36859 66787 106329 85211 94423 65627 147436 143259 128699 139277 167743 178063 192167 150133 162719 177103 160732 139859 157301 176681 199291 152867 182611 199632 199535 199905 199959 23333\n", "6\n90 93 28\n...
1,900
2,500
2
11
1100_E. Andrew and Taxi
Andrew prefers taxi to other means of transport, but recently most taxi drivers have been acting inappropriately. In order to earn more money, taxi drivers started to drive in circles. Roads in Andrew's city are one-way, and people are not necessary able to travel from one part to another, but it pales in comparison to...
{ "input": [ "5 7\n2 1 5\n3 2 3\n1 3 3\n2 4 1\n4 3 5\n5 4 1\n1 5 3\n", "5 6\n2 1 1\n5 2 6\n2 3 2\n3 4 3\n4 5 5\n1 5 4\n" ], "output": [ "3 3\n2 6 7\n", "2 2\n1 3 " ] }
{ "input": [ "100000 10\n46122 79638 789057278\n86778 33379 443285900\n21112 73244 633154007\n77248 23596 430537716\n41202 48487 549896573\n38675 77119 815675406\n71488 96154 374480841\n84312 84448 419663315\n51244 87732 26745557\n22188 58973 334627707\n", "10 16\n1 4 894\n1 2 197\n10 4 325\n9 10 232\n10 8 90...
2,200
2,000
2
8
1129_B. Wrong Answer
Consider the following problem: given an array a containing n integers (indexed from 0 to n-1), find max_{0 ≀ l ≀ r ≀ n-1} βˆ‘_{l ≀ i ≀ r} (r-l+1) β‹… a_i. In this problem, 1 ≀ n ≀ 2 000 and |a_i| ≀ 10^6. In an attempt to solve the problem described, Alice quickly came up with a blazing-fast greedy algorithm and coded it....
{ "input": [ "612\n", "8\n" ], "output": [ "2\n-1 614\n", "2\n-1 10\n" ] }
{ "input": [ "2000000\n", "32768\n", "131072\n", "3\n", "1000002\n", "999999999\n", "2000002\n", "1000003\n", "2000004\n", "999998\n", "2000006\n", "1999993\n", "999997\n", "128\n", "268435456\n", "999999929\n", "1024\n", "999995\n", "1999991...
2,000
1,000
2
8
1189_B. Number Circle
You are given n numbers a_1, a_2, …, a_n. Is it possible to arrange them in a circle in such a way that every number is strictly less than the sum of its neighbors? For example, for the array [1, 4, 5, 6, 7, 8], the arrangement on the left is valid, while arrangement on the right is not, as 5β‰₯ 4 + 1 and 8> 1 + 6. <im...
{ "input": [ "4\n1 10 100 1000\n", "5\n1 2 3 4 4\n", "3\n2 4 3\n", "3\n13 8 5\n" ], "output": [ "NO\n", "YES\n1 2 3 4 4\n", "YES\n2 4 3\n", "NO\n" ] }
{ "input": [ "4\n4 2 2 3\n", "27\n496869708 6536632 139291 53540 27689600 72492314 189787341 364332 953704 2496779 10576485 307082368 85752 44802715 21328 10886 1543076 10000 17113116 32213 117295028 444 589373 803952075 10443 225042 4039854\n", "6\n6 3 10 7 14 4\n", "6\n2 7 14 9 2 4\n", "5\n1 2 3...
1,100
1,000
2
8
1208_B. Uniqueness
You are given an array a_{1}, a_{2}, …, a_{n}. You can remove at most one subsegment from it. The remaining elements should be pairwise distinct. In other words, at most one time you can choose two integers l and r (1 ≀ l ≀ r ≀ n) and delete integers a_l, a_{l+1}, …, a_r from the array. Remaining elements should be pa...
{ "input": [ "4\n1 1 2 2\n", "3\n1 2 3\n", "5\n1 4 1 4 9\n" ], "output": [ "2", "0", "2" ] }
{ "input": [ "8\n9 3 1 8 3 5 8 4\n", "13\n1 2 3 4 5 6 7 2 11 9 8 7 10\n", "6\n3 2 4 3 1 4\n", "10\n15 14 10 20 18 11 14 10 16 18\n", "12\n1 2 6 3 8 4 1 4 7 6 5 4\n", "10\n1 2 3 4 5 1 8 7 6 5\n", "8\n1 2 3 2 4 1 4 3\n", "8\n1 2 3 6 1 4 5 6\n", "20\n10 4 9 1 2 8 2 9 9 8 3 3 4 3 6 9 1...
1,500
1,000
2
9
1269_C. Long Beautiful Integer
You are given an integer x of n digits a_1, a_2, …, a_n, which make up its decimal notation in order from left to right. Also, you are given a positive integer k < n. Let's call integer b_1, b_2, …, b_m beautiful if b_i = b_{i+k} for each i, such that 1 ≀ i ≀ m - k. You need to find the smallest beautiful integer y,...
{ "input": [ "3 2\n353\n", "4 2\n1234\n" ], "output": [ "3\n353\n", "4\n1313\n" ] }
{ "input": [ "4 1\n1020\n", "6 2\n199119\n", "5 2\n99999\n", "5 2\n49792\n", "4 2\n2939\n", "12 7\n129679930099\n", "6 2\n199999\n", "20 19\n19999999999999999999\n", "5 3\n78989\n", "10 3\n9879879999\n", "4 2\n1102\n", "5 3\n12933\n", "9 3\n987987999\n", "4 2\n1...
1,700
500
2
10
1311_D. Three Integers
You are given three integers a ≀ b ≀ c. In one move, you can add +1 or -1 to any of these integers (i.e. increase or decrease any number by one). You can perform such operation any (possibly, zero) number of times, you can even perform this operation several times with one number. Note that you cannot make non-positiv...
{ "input": [ "8\n1 2 3\n123 321 456\n5 10 15\n15 18 21\n100 100 101\n1 22 29\n3 19 38\n6 30 46\n" ], "output": [ "1\n1 1 3\n102\n114 228 456\n4\n4 8 16\n6\n18 18 18\n1\n100 100 100\n7\n1 22 22\n2\n1 19 38\n8\n6 24 48\n" ] }
{ "input": [ "1\n451 10000 10000\n", "1\n3533 3533 10000\n", "2\n256 4096 10000\n2 749 1000\n", "1\n1429 1429 10000\n", "1\n73 73 10000\n", "1\n137 137 10000\n", "1\n1684 5052 10000\n", "2\n73 10000 10000\n71 10000 10000\n", "1\n75 10000 10000\n", "1\n71 9998 10000\n", "3\n...
2,000
0
2
8
1334_B. Middle Class
Many years ago Berland was a small country where only n people lived. Each person had some savings: the i-th one had a_i burles. The government considered a person as wealthy if he had at least x burles. To increase the number of wealthy people Berland decided to carry out several reforms. Each reform looked like that...
{ "input": [ "4\n4 3\n5 1 2 1\n4 10\n11 9 11 9\n2 5\n4 3\n3 7\n9 4 9\n" ], "output": [ "2\n4\n0\n3\n" ] }
{ "input": [ "1\n1 2\n13\n" ], "output": [ "1\n" ] }
1,100
0
2
10
1354_D. Multiset
Note that the memory limit is unusual. You are given a multiset consisting of n integers. You have to process queries of two types: * add integer k into the multiset; * find the k-th order statistics in the multiset and remove it. k-th order statistics in the multiset is the k-th element in the sorted list o...
{ "input": [ "5 4\n1 2 3 4 5\n-5 -1 -3 -1\n", "6 2\n1 1 1 2 3 4\n5 6\n", "5 5\n1 2 3 4 5\n-1 -1 -1 -1 -1\n" ], "output": [ "3\n", "1\n", "0\n" ] }
{ "input": [ "5 8\n1 1 1 1 1\n2 3 4 -1 -1 -1 -1 -1\n", "6 2\n1 1 1 2 3 4\n5 6\n", "2 2\n1 2\n1 -1\n" ], "output": [ "2\n", "1\n", "1\n" ] }
1,900
0
2
10
1397_D. Stoned Game
T is playing a game with his friend, HL. There are n piles of stones, the i-th pile initially has a_i stones. T and HL will take alternating turns, with T going first. In each turn, a player chooses a non-empty pile and then removes a single stone from it. However, one cannot choose a pile that has been chosen in th...
{ "input": [ "2\n1\n2\n2\n1 1\n" ], "output": [ "T\nHL\n" ] }
{ "input": [ "2\n2\n1 4\n3\n3 1 3\n", "1\n3\n2 1 1\n", "4\n5\n1 3 1 3 4\n1\n4\n1\n5\n2\n3 3\n", "3\n2\n4 3\n4\n2 2 2 3\n3\n1 4 1\n", "1\n2\n1 13\n", "1\n4\n2 3 1 2\n", "1\n7\n10 3 1 1 1 1 1\n", "1\n4\n3 1 1 1\n" ], "output": [ "T\nT\n", "HL\n", "HL\nT\nT\nHL\n", "T\...
1,800
1,000
2
11
1420_E. Battle Lemmings
A lighthouse keeper Peter commands an army of n battle lemmings. He ordered his army to stand in a line and numbered the lemmings from 1 to n from left to right. Some of the lemmings hold shields. Each lemming cannot hold more than one shield. The more protected Peter's army is, the better. To calculate the protection...
{ "input": [ "12\n0 0 0 0 1 1 1 1 0 1 1 0\n", "5\n1 0 0 0 1\n" ], "output": [ "9 12 13 14 14 14 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 \n", "0 2 3 3 3 3 3...
{ "input": [ "79\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0\n", "2\n0 0\n", "80\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0...
2,500
3,000
2
11
1490_E. Accidental Victory
A championship is held in Berland, in which n players participate. The player with the number i has a_i (a_i β‰₯ 1) tokens. The championship consists of n-1 games, which are played according to the following rules: * in each game, two random players with non-zero tokens are selected; * the player with more tokens ...
{ "input": [ "2\n4\n1 2 4 3\n5\n1 1 1 1 1\n" ], "output": [ "\n3\n2 3 4 \n5\n1 2 3 4 5 \n" ] }
{ "input": [ "1\n1\n2\n" ], "output": [ "1\n1 \n" ] }
1,400
0
2
7
1513_A. Array and Peaks
A sequence of n integers is called a permutation if it contains all integers from 1 to n exactly once. Given two integers n and k, construct a permutation a of numbers from 1 to n which has exactly k peaks. An index i of an array a of size n is said to be a peak if 1 < i < n and a_i \gt a_{i-1} and a_i \gt a_{i+1}. If...
{ "input": [ "5\n1 0\n5 2\n6 6\n2 1\n6 1\n" ], "output": [ "\n1 \n2 4 1 5 3 \n-1\n-1\n1 3 6 5 4 2\n" ] }
{ "input": [ "5\n1 0\n5 2\n6 6\n2 1\n6 1\n", "1\n79 29\n" ], "output": [ "1 \n2 4 1 5 3 \n-1\n-1\n1 6 2 3 4 5 \n", "1 79 2 78 3 77 4 76 5 75 6 74 7 73 8 72 9 71 10 70 11 69 12 68 13 67 14 66 15 65 16 64 17 63 18 62 19 61 20 60 21 59 22 58 23 57 24 56 25 55 26 54 27 53 28 52 29 51 30 31 32 33 34 35...
800
500
2
7
1540_A. Great Graphs
Farmer John has a farm that consists of n pastures connected by one-directional roads. Each road has a weight, representing the time it takes to go from the start to the end of the road. The roads could have negative weight, where the cows go so fast that they go back in time! However, Farmer John guarantees that it is...
{ "input": [ "3\n3\n0 2 3\n2\n0 1000000000\n1\n0\n" ], "output": [ "-3\n0\n0\n" ] }
{ "input": [ "3\n1\n0\n3\n0 2 3\n2\n0 1000000000\n" ], "output": [ "0\n-3\n0\n" ] }
1,400
500
2
8
235_B. Let's Play Osu!
You're playing a game called Osu! Here's a simplified version of it. There are n clicks in a game. For each click there are two outcomes: correct or bad. Let us denote correct as "O", bad as "X", then the whole play can be encoded as a sequence of n characters "O" and "X". Using the play sequence you can calculate the...
{ "input": [ "4\n0.7 0.2 0.1 0.9\n", "3\n0.5 0.5 0.5\n", "5\n1 1 1 1 1\n" ], "output": [ "2.489200", "2.750000", "25.000000" ] }
{ "input": [ "10\n0.999453 0.999188 0.998398 0.999609 0.999113 0.999426 0.998026 0.999244 0.998842 0.999807\n", "30\n0.999453 0.998210 0.999812 0.998309 0.999333 0.999463 0.999490 0.998975 0.999248 0.999782 0.999233 0.999062 0.999530 0.998674 0.999608 0.999654 0.998426 0.998941 0.998104 0.999541 0.999467 0.99...
2,000
1,000
2
11
25_E. Test
Sometimes it is hard to prepare tests for programming problems. Now Bob is preparing tests to new problem about strings β€” input data to his problem is one string. Bob has 3 wrong solutions to this problem. The first gives the wrong answer if the input data contains the substring s1, the second enters an infinite loop i...
{ "input": [ "abacaba\nabaaba\nx\n", "ab\nbc\ncd\n" ], "output": [ "11\n", "4\n" ] }
{ "input": [ "syvncqmfhautvxudqdhggz\nhrpxzeghsocjpicuixskfuzupytsgjsdiyb\nybcmnmnbpndbxlxbzhbfnqvwcffvrdhtickyqhupmcehls\n", "iefouqzxoyuieqdzalfktehtvdbvjmeubju\nocotspetkkhvwfgaqynhovjwjhciefouqzxoyuieqdzalfktehtvdbvjmeubjubcmnvpwgdpnchqhzjrchyrfpvigubp\nycnhjwgbocotspetkkhvwfgaqynhovjwjhcief\n", "ujgq...
2,200
0
2
9
354_C. Vasya and Beautiful Arrays
Vasya's got a birthday coming up and his mom decided to give him an array of positive integers a of length n. Vasya thinks that an array's beauty is the greatest common divisor of all its elements. His mom, of course, wants to give him as beautiful an array as possible (with largest possible beauty). Unfortunately, th...
{ "input": [ "5 3\n8 21 52 15 77\n", "6 1\n3 6 10 12 13 16\n" ], "output": [ "7", "3" ] }
{ "input": [ "25 7\n67 18 36 85 64 22 32 66 17 64 66 65 82 36 16 52 19 70 38 51 17 32 85 16 64\n", "10 10\n40141 53368 66538 64507 78114 34253 73242 42141 37430 6\n", "18 9\n85 29 29 15 17 71 46 69 48 80 44 73 40 55 61 57 22 68\n", "1 1\n1\n", "2 84794\n1000000 1000000\n", "13 11\n55 16 26 40 ...
2,100
1,500
2
12
39_F. Pacifist frogs
Thumbelina has had an accident. She has found herself on a little island in the middle of a swamp and wants to get to the shore very much. One can get to the shore only by hills that are situated along a straight line that connects the little island with the shore. Let us assume that the hills are numbered from 1 to n...
{ "input": [ "1000000000 2 3\n2 5\n999999995 999999998 999999996\n", "5 3 5\n2 3 4\n1 2 3 4 5\n" ], "output": [ "1\n2 ", "2\n2 3 " ] }
{ "input": [ "10 3 6\n5 2 8\n5 6 7 8 9 10\n", "1000 19 27\n656 162 264 790 579 786 877 998 516 247 650 150 858 281 279 549 354 353 533\n349 411 1 248 22 649 726 382 423 832 172 864 17 658 840 572 564 287 800 919 500 575 461 40 1000 383 624\n", "2 2 1\n2 1\n1\n", "20 3 5\n2 3 5\n2 5 6 10 15\n", "20...
1,300
0
2
8
425_B. Sereja and Table
Sereja has an n Γ— m rectangular table a, each cell of the table contains a zero or a number one. Sereja wants his table to meet the following requirement: each connected component of the same values forms a rectangle with sides parallel to the sides of the table. Rectangles should be filled with cells, that is, if a co...
{ "input": [ "3 4 1\n1 0 0 1\n0 1 1 0\n1 0 0 1\n", "5 5 2\n1 1 1 1 1\n1 1 1 1 1\n1 1 0 1 1\n1 1 1 1 1\n1 1 1 1 1\n", "3 4 1\n1 0 0 0\n0 1 1 1\n1 1 1 0\n" ], "output": [ "0", "1", "-1" ] }
{ "input": [ "2 2 1\n1 1\n1 0\n", "5 5 5\n0 1 1 1 1\n1 0 1 1 1\n1 1 0 1 1\n1 1 1 0 1\n1 1 1 1 0\n", "9 9 10\n0 0 0 0 0 0 1 0 0\n1 1 1 1 1 1 1 1 1\n0 0 0 0 0 0 0 0 0\n1 1 1 1 1 1 1 1 1\n1 1 1 0 1 1 1 1 1\n1 1 1 1 1 1 1 1 1\n0 0 0 0 1 0 1 0 0\n0 0 0 0 1 0 0 0 0\n0 0 0 0 1 0 0 0 0\n", "10 10 6\n0 0 0 0 0...
2,200
1,000
2
8
494_B. Obsessive String
Hamed has recently found a string t and suddenly became quite fond of it. He spent several days trying to find all occurrences of t in other strings he had. Finally he became tired and started thinking about the following problem. Given a string s how many ways are there to extract k β‰₯ 1 non-overlapping substrings from...
{ "input": [ "welcometoroundtwohundredandeightytwo\nd\n", "ababa\naba\n", "ddd\nd\n" ], "output": [ "274201", "5", "12" ] }
{ "input": [ "ababababab\nabab\n", "a\na\n", "vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv\nvvvvvvvv\n", "kpjmawawawawawawawawawawawawawawawawawawawawawawaw\nwawawawa\n", "vnssnssnssnssnssnssnssnssnssnssnssnssnssnssnssnssn\nnssnssns\n", "a\nb\n", "a\naa\n" ], "output": [ "35"...
2,000
1,000
2
12
518_F. Pasha and Pipe
On a certain meeting of a ruling party "A" minister Pavel suggested to improve the sewer system and to create a new pipe in the city. The city is an n Γ— m rectangular squared field. Each square of the field is either empty (then the pipe can go in it), or occupied (the pipe cannot go in such square). Empty squares are...
{ "input": [ "4 2\n..\n..\n..\n..\n", "4 5\n#...#\n#...#\n###.#\n###.#\n", "3 3\n...\n..#\n...\n" ], "output": [ " 2\n", " 4\n", " ...
{ "input": [ "10 10\n##........\n#.#....#..\n#.#...#..#\n.........#\n#..#......\n......#..#\n..#...#...\n..#...#...\n...#.....#\n..........\n", "9 37\n.......#................#.##...#.....\n..#......................##..........\n..#......#.........#.................\n..........#..#..#..#...........#.....\n......
2,300
2,500
2
7
545_A. Toy Cars
Little Susie, thanks to her older brother, likes to play with cars. Today she decided to set up a tournament between them. The process of a tournament is described in the next paragraph. There are n toy cars. Each pair collides. The result of a collision can be one of the following: no car turned over, one car turned ...
{ "input": [ "4\n-1 3 3 3\n3 -1 3 3\n3 3 -1 3\n3 3 3 -1\n", "3\n-1 0 0\n0 -1 1\n0 2 -1\n" ], "output": [ "0\n\n", "2\n1 3\n" ] }
{ "input": [ "2\n-1 1\n2 -1\n", "1\n-1\n", "2\n-1 0\n0 -1\n", "2\n-1 2\n1 -1\n", "2\n-1 3\n3 -1\n" ], "output": [ "1\n2\n", "1\n1\n", "2\n1 2\n", "1\n1\n", "0\n\n" ] }
900
500
2
7
593_A. 2Char
Andrew often reads articles in his favorite magazine 2Char. The main feature of these articles is that each of them uses at most two distinct letters. Andrew decided to send an article to the magazine, but as he hasn't written any article, he just decided to take a random one from magazine 26Char. However, before sendi...
{ "input": [ "4\nabb\ncacc\naaa\nbbb\n", "5\na\na\nbcbcb\ncdecdecdecdecdecde\naaaa\n" ], "output": [ "9\n", "6\n" ] }
{ "input": [ "4\nurkop\nvisualac\ngnutl\nwtf\n", "7\npavel\nerika\nalexxxxxxx\ngracio\nzhenya\nsudarev\nchelyaba\n", "5\nc\nbb\ne\ndd\nf\n", "1\nabc\n", "3\nab\nba\nzzzzz\n", "31\nfml\nfml\nfml\nfml\nfml\nfml\nfml\nfml\nfml\nfml\nfml\nfml\nfml\nfml\nfml\nfml\nfml\nfml\nfml\nfml\nfml\nfml\nfml\...
1,200
250
2
10
614_D. Skills
Lesha plays the recently published new version of the legendary game hacknet. In this version character skill mechanism was introduced. Now, each player character has exactly n skills. Each skill is represented by a non-negative integer ai β€” the current skill level. All skills have the same maximum level A. Along with...
{ "input": [ "3 5 10 1 5\n1 3 1\n", "3 5 10 1 339\n1 3 1\n" ], "output": [ "12\n2 5 2 \n", "35\n5 5 5 \n" ] }
{ "input": [ "1 1000000000 1000 1000 1000000000000000\n1000000000\n", "3 6 4 6 8\n6 4 5\n", "5 5 10 20 50\n0 0 0 0 0\n", "1 1000000000 1000 1000 1000000000000000\n0\n", "5 5 10 20 50\n3 3 3 3 3\n", "2 6 0 1 4\n5 1\n", "1 100 1 2 30\n1\n", "1 100 1 2 30\n71\n", "4 5 3 7 15\n4 3 3 1\...
1,900
1,250
2
7
634_A. Island Puzzle
A remote island chain contains n islands, labeled 1 through n. Bidirectional bridges connect the islands to form a simple cycle β€” a bridge connects islands 1 and 2, islands 2 and 3, and so on, and additionally a bridge connects islands n and 1. The center of each island contains an identical pedestal, and all but one o...
{ "input": [ "3\n1 0 2\n2 0 1\n", "2\n1 0\n0 1\n", "4\n1 2 3 0\n0 3 2 1\n" ], "output": [ "YES", "YES", "NO" ] }
{ "input": [ "10\n4 1 9 7 0 2 6 3 5 8\n6 4 2 9 1 8 5 3 0 7\n1 4\n1 7\n9 5\n6 1\n1 2\n1 9\n3 1\n10 1\n8 4\n", "10\n0 7 4 1 6 3 5 8 9 2\n4 7 1 2 3 9 5 6 0 8\n5 9\n4 1\n1 7\n10 1\n1 6\n8 4\n1 5\n2 1\n3 1\n", "10\n0 9 4 5 7 2 1 6 3 8\n7 0 9 8 3 4 1 2 6 5\n4 1\n1 7\n2 1\n1 8\n7 9\n10 8\n1 3\n8 6\n1 5\n", "...
1,300
500
2
10
662_D. International Olympiad
International Abbreviation Olympiad takes place annually starting from 1989. Each year the competition receives an abbreviation of form IAO'y, where y stands for some number of consequent last digits of the current year. Organizers always pick an abbreviation with non-empty string y that has never been used before. Amo...
{ "input": [ "5\nIAO'15\nIAO'2015\nIAO'1\nIAO'9\nIAO'0\n", "4\nIAO'9\nIAO'99\nIAO'999\nIAO'9999\n" ], "output": [ "2015\n12015\n1991\n1989\n1990\n", "1989\n1999\n2999\n9999\n" ] }
{ "input": [ "1\nIAO'123456789\n", "1\nIAO'111111\n", "4\nIAO'3098\nIAO'99\nIAO'999\nIAO'9999\n", "1\nIAO'100000\n", "1\nIAO'11111\n", "1\nIAO'1110222\n", "1\nIAO'111111111\n", "1\nIAO'11133333\n", "1\nIAO'11100000\n", "2\nIAO'999999999\nIAO'999999999\n", "1\nIAO'000000000\...
2,000
250
2
8
687_B. Remainders Game
Today Pari and Arya are playing a game called Remainders. Pari chooses two positive integer x and k, and tells Arya k but not x. Arya have to find the value <image>. There are n ancient numbers c1, c2, ..., cn and Pari has to tell Arya <image> if Arya wants. Given k and the ancient values, tell us if Arya has a winnin...
{ "input": [ "2 7\n2 3\n", "4 5\n2 3 5 12\n" ], "output": [ "NO\n", "YES\n" ] }
{ "input": [ "1 1\n3\n", "2 16\n8 4\n", "1 999983\n1\n", "3 16\n2 4 8\n", "2 8\n4 12\n", "2 27000\n5400 4500\n", "2 9\n3 3\n", "1 216000\n648000\n", "1 2\n1\n", "3 32\n2 4 8\n", "1 49\n7\n", "3 20\n2 2 5\n", "2 20998\n2 10499\n", "3 8\n1 2 4\n", "3 8\n4 4 4\...
1,800
1,000
2
7
70_A. Cookies
Fangy collects cookies. Once he decided to take a box and put cookies into it in some way. If we take a square k Γ— k in size, divided into blocks 1 Γ— 1 in size and paint there the main diagonal together with cells, which lie above it, then the painted area will be equal to the area occupied by one cookie k in size. Fan...
{ "input": [ "3\n" ], "output": [ "9\n" ] }
{ "input": [ "696\n", "6\n", "928\n", "589\n", "657\n", "617\n", "11\n", "14\n", "1000\n", "1\n", "2\n", "298\n", "823\n", "262\n", "69\n", "4\n", "910\n", "857\n", "0\n", "561\n", "15\n", "226\n", "7\n", "850\n" ], "o...
1,300
500
2
14
730_H. Delete Them
Polycarp is a beginner programmer. He is studying how to use a command line. Polycarp faced the following problem. There are n files in a directory and he needs to delete some of them. Polycarp wants to run a single delete command with filename pattern as an argument. All the files to be deleted should match the patte...
{ "input": [ "3 2\nab\nac\ncd\n1 2\n", "4 4\na\nb\nc\ndd\n1 2 3 4\n", "6 3\n.svn\n.git\n....\n...\n..\n.\n1 2 3\n", "5 3\ntest\ntezt\ntest.\n.est\ntes.\n1 4 5\n" ], "output": [ "Yes\na?\n", "No\n", "Yes\n.???\n", "Yes\n?es?\n" ] }
{ "input": [ "2 1\nb\naa\n1\n", "5 3\nlmljeqklg\nlclydkkxj\nuylscbk.g\neplpqakme\nablibhkfg\n1 3 5\n", "1 1\nuevim.mrr\n1\n", "5 4\naaaaaaa\nbaaaaab\ncaaaaac\ndaaaaad\nabacaba\n1 2 3 4\n", "2 2\nb\naa\n1 2\n", "2 1\nb\naa\n2\n", "2 1\na\nb\n1\n", "27 27\na\nb\nc\nd\ne\nf\ng\nh\ni\nj\nk...
1,300
0
2
9
754_C. Vladik and chat
Recently 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 need to download t chats. Vladik coded a script which should have downloaded the chats, however, something went wrong. ...
{ "input": [ "1\n2\nnetman vladik\n3\nnetman:how are you?\n?:wrong message\nvladik:im fine\n", "1\n2\nVladik netman\n2\n?: Hello, Vladik!\n?: Hi\n", "2\n3\nnetman vladik Fedosik\n2\n?: users are netman, vladik, Fedosik\nvladik: something wrong with this chat\n4\nnetman tigerrrrr banany2001 klinchuh\n4\n?:...
{ "input": [ "1\n1\nb\n1\nb:lala!\n", "1\n3\nA B C\n3\nA: HI\n?: HI\nB: HI\n", "1\n1\nb\n2\n?:lala hhe!\nb:wat?\n", "1\n1\nb\n1\n?:lala b!\n" ], "output": [ "b:lala!\n", "A: HI\nC: HI\nB: HI\n", "Impossible\n", "Impossible\n" ] }
2,200
1,500
2
19
774_L. Bars
Polycarp's workday lasts exactly n minutes. He loves chocolate bars and can eat one bar in one minute. Today Polycarp has k bars at the beginning of the workday. In some minutes of the workday Polycarp has important things to do and in such minutes he is not able to eat a chocolate bar. In other minutes he can either ...
{ "input": [ "8 3\n01010110\n", "3 3\n010\n" ], "output": [ "3", "1" ] }
{ "input": [ "10 3\n0111011010\n", "4 4\n0000\n", "4 2\n0010\n", "4 4\n0110\n", "9 5\n001100110\n", "100 89\n0011011110011111111010111101101100101111111111011011111111110111101111101111111101111011111011101110\n", "100 81\n0110111011000010010101011101110101110111000111101011110100011011100...
2,000
0
2
8
820_B. Mister B and Angle in Polygon
On one quiet day all of sudden Mister B decided to draw angle a on his field. Aliens have already visited his field and left many different geometric figures on it. One of the figures is regular convex n-gon (regular convex polygon with n sides). That's why Mister B decided to use this polygon. Now Mister B must find ...
{ "input": [ "4 68\n", "4 67\n", "3 15\n" ], "output": [ "2 1 4\n", "2 1 3\n", "2 1 3\n" ] }
{ "input": [ "100000 148\n", "68459 88\n", "100000 143\n", "100000 109\n", "3 15\n", "5 141\n", "3 180\n", "100000 49\n", "5 111\n", "100000 71\n", "4 16\n", "5 54\n", "5 126\n", "6 46\n", "8509 139\n", "100000 35\n", "100000 79\n", "5 162\n", ...
1,300
1,000
2
9
846_C. Four Segments
You are given an array of n integer numbers. Let sum(l, r) be the sum of all numbers on positions from l to r non-inclusive (l-th element is counted, r-th element is not counted). For indices l and r holds 0 ≀ l ≀ r ≀ n. Indices in array are numbered from 0. For example, if a = [ - 5, 3, 9, 4], then sum(0, 1) = - 5, ...
{ "input": [ "1\n10000\n", "4\n0 0 -1 0\n", "3\n-1 2 3\n" ], "output": [ "0 0 1\n", "0 0 0\n", "0 1 3\n" ] }
{ "input": [ "10\n0 0 0 0 0 0 0 0 0 0\n", "10\n-6 -4 -7 0 7 9 8 3 8 7\n", "1\n0\n", "100\n2 1 -2 -1 -2 0 -1 -2 1 2 0 1 0 -2 -1 -2 0 2 0 1 -2 -2 2 0 -2 2 -2 0 2 0 2 0 -1 0 -2 2 -1 -1 -2 -1 0 -2 2 0 -2 -2 -2 -1 1 0 -2 -1 2 -1 -2 1 -1 1 1 2 -2 1 -2 1 2 2 -2 1 -2 0 -1 -1 -2 -2 1 0 -1 -1 2 0 2 0 -1 2 1 -1 ...
1,800
0
2
8
893_B. Beautiful Divisors
Recently Luba learned about a special kind of numbers that she calls beautiful numbers. The number is called beautiful iff its binary representation consists of k + 1 consecutive ones, and then k consecutive zeroes. Some examples of beautiful numbers: * 12 (110); * 1102 (610); * 11110002 (12010); * 111110...
{ "input": [ "3\n", "992\n" ], "output": [ "1\n", "496\n" ] }
{ "input": [ "1027\n", "1024\n", "38304\n", "89408\n", "1\n", "55948\n", "66\n", "2018\n", "38021\n", "5\n", "21445\n", "22876\n", "32640\n", "12768\n", "497\n", "240\n", "28\n", "99990\n", "2016\n", "76920\n", "123\n", "14400\n",...
1,000
0
2
11
937_E. Lock Puzzle
Welcome to another task about breaking the code lock! Explorers Whitfield and Martin came across an unusual safe, inside of which, according to rumors, there are untold riches, among which one can find the solution of the problem of discrete logarithm! Of course, there is a code lock is installed on the safe. The lock...
{ "input": [ "6\nabacbb\nbabcba\n", "3\naba\nbba\n" ], "output": [ "18\n4 1 6 5 1 6 3 1 6 5 1 6 4 1 6 5 1 6 ", "-1\n" ] }
{ "input": [ "8\nvnidcatu\nuiacnvdt\n", "100\nmntyyerijtaaditeyqvxstrwxoxglpaubigaggtrepaegniybvfmssawvhrgjjhwwkwuqhtyrimxvolcstyllbhlcursvgfafpts\nbsgmhsgavsbgtwiiqaigmtyjxihphxdlseeajfywugawigrjruttuykthfrvwagpcsxlxsopnarqcvetnbtvfrvlyymwoyelrlta\n", "5\nutvrb\nvbtru\n", "50\nyfjtdvbotbvocjdqxdztqir...
2,300
1,500
2
9
990_C. Bracket Sequences Concatenation Problem
A bracket sequence is a string containing only characters "(" and ")". A regular bracket sequence is a bracket sequence that can be transformed into a correct arithmetic expression by inserting characters "1" and "+" between the original characters of the sequence. For example, bracket sequences "()()", "(())" are reg...
{ "input": [ "3\n)\n()\n(\n", "2\n()\n()\n" ], "output": [ "2\n", "4\n" ] }
{ "input": [ "10\n()()(\n)((\n)()(((()(\n(((()(\n)(()((\n))\n()()()()\n))()))((\n)\n))())(\n", "2\n((\n))\n", "3\n)())(\n()(()(\n(((\n", "6\n(\n((\n(((\n))))\n)))))\n))))))\n", "2\n(((((((((()\n)))))))))\n", "2\n((((((((((((((((((((((((\n))))))))))))))))))))))))\n", "1\n)(\n", "2\n(((\...
1,500
0
2
10
1013_D. Chemical table
Innopolis University scientists continue to investigate the periodic table. There are nΒ·m known elements and they form a periodic table: a rectangle with n rows and m columns. Each element can be described by its coordinates (r, c) (1 ≀ r ≀ n, 1 ≀ c ≀ m) in the table. Recently scientists discovered that for every four...
{ "input": [ "4 3 6\n1 2\n1 3\n2 2\n2 3\n3 1\n3 3\n", "1 5 3\n1 3\n1 1\n1 5\n", "2 2 3\n1 2\n2 2\n2 1\n" ], "output": [ "1\n", "2\n", "0\n" ] }
{ "input": [ "2 2 0\n", "1 20 20\n1 19\n1 5\n1 8\n1 12\n1 3\n1 9\n1 2\n1 10\n1 11\n1 18\n1 6\n1 7\n1 20\n1 4\n1 17\n1 16\n1 15\n1 14\n1 1\n1 13\n", "2 2 2\n1 1\n2 1\n", "20 10 20\n9 5\n15 6\n17 10\n14 1\n18 7\n7 4\n2 3\n19 6\n6 6\n16 10\n5 2\n3 5\n12 6\n10 6\n11 1\n4 1\n20 5\n13 8\n1 9\n8 7\n", "2...
1,900
1,250
2
8
1038_B. Non-Coprime Partition
Find out if it is possible to partition the first n positive integers into two non-empty disjoint sets S_1 and S_2 such that: gcd(sum(S_1), sum(S_2)) > 1 Here sum(S) denotes the sum of all elements present in set S and gcd means the[greatest common divisor](https://en.wikipedia.org/wiki/Greatest_common_divisor). Ev...
{ "input": [ "3\n", "1\n" ], "output": [ "Yes\n1 2\n2 1 3 ", "No\n" ] }
{ "input": [ "17471\n", "18253\n", "17676\n", "6631\n", "33231\n", "17118\n", "6711\n", "18066\n", "2\n", "22049\n", "27971\n", "30666\n", "10586\n", "14654\n", "24605\n", "28893\n", "32523\n", "18656\n", "11319\n", "20178\n", "16101\...
1,100
1,000