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
9
1265_C. Beautiful Regional Contest
So the Beautiful Regional Contest (BeRC) has come to an end! n students took part in the contest. The final standings are already known: the participant in the i-th place solved p_i problems. Since the participants are primarily sorted by the number of solved problems, then p_1 β‰₯ p_2 β‰₯ ... β‰₯ p_n. Help the jury distrib...
{ "input": [ "5\n12\n5 4 4 3 2 2 1 1 1 1 1 1\n4\n4 3 2 1\n1\n1000000\n20\n20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1\n32\n64 64 63 58 58 58 58 58 37 37 37 37 34 34 28 28 28 28 28 28 24 24 19 17 17 17 17 16 16 16 16 11\n" ], "output": [ "1 2 3\n0 0 0\n0 0 0\n1 2 7\n2 6 6\n" ] }
{ "input": [ "5\n12\n5 4 4 3 2 2 1 1 1 1 1 1\n4\n4 3 2 1\n1\n1000000\n20\n20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1\n32\n64 64 63 58 58 58 58 58 37 37 37 37 34 34 28 28 28 28 28 28 24 24 19 17 17 17 17 16 16 16 16 11\n" ], "output": [ "1 2 3\n0 0 0\n0 0 0\n1 2 7\n2 6 6\n" ] }
1,500
500
2
8
134_B. Pairs of Numbers
Let's assume that we have a pair of numbers (a, b). We can get a new pair (a + b, b) or (a, a + b) from the given pair in a single step. Let the initial pair of numbers be (1,1). Your task is to find number k, that is, the least number of steps needed to transform (1,1) into the pair where at least one number equals n...
{ "input": [ "5\n", "1\n" ], "output": [ "3\n", "0\n" ] }
{ "input": [ "999998\n", "4\n", "123455\n", "10000\n", "998756\n", "1000000\n", "999879\n", "345612\n", "6\n", "999997\n", "990001\n", "8\n", "623423\n", "2\n", "345634\n", "777777\n", "9009\n", "100000\n", "2009\n", "976438\n", "3\n"...
1,900
1,000
2
8
1370_B. GCD Compression
Ashish has an array a of consisting of 2n positive integers. He wants to compress a into an array b of size n-1. To do this, he first discards exactly 2 (any two) elements from a. He then performs the following operation until there are no elements left in a: * Remove any two elements from a and append their sum to...
{ "input": [ "3\n3\n1 2 3 4 5 6\n2\n5 7 9 10\n5\n1 3 3 4 5 90 100 101 2 3\n" ], "output": [ "2 4\n1 3\n1 2\n4 6\n7 9\n1 2\n3 5\n" ] }
{ "input": [ "10\n9\n7 5 4 3 1 4 8 8 2 10 5 9 6 9 4 9 8 7\n2\n4 6 4 2\n2\n9 4 7 7\n4\n9 2 3 7 6 7 6 4\n10\n1 3 7 4 6 5 8 2 7 7 1 4 2 10 3 10 9 7 3 7\n10\n6 3 6 10 10 7 6 4 4 2 8 3 9 6 4 3 2 10 3 7\n3\n7 8 7 8 3 9\n5\n7 4 4 4 7 5 9 7 7 3\n3\n7 6 4 9 8 1\n8\n6 5 7 7 10 7 2 2 9 5 10 1 2 2 10 9\n", "10\n9\n8 8 2 ...
1,100
1,000
2
9
1417_C. k-Amazing Numbers
You are given an array a consisting of n integers numbered from 1 to n. Let's define the k-amazing number of the array as the minimum number that occurs in all of the subsegments of the array having length k (recall that a subsegment of a of length k is a contiguous part of a containing exactly k elements). If there i...
{ "input": [ "3\n5\n1 2 3 4 5\n5\n4 4 4 4 2\n6\n1 3 1 5 3 1\n" ], "output": [ "-1 -1 3 2 1 \n-1 4 4 4 2 \n-1 -1 1 1 1 1 \n" ] }
{ "input": [ "3\n5\n4 4 4 4 2\n5\n1 2 3 4 5\n6\n1 3 1 5 3 1\n" ], "output": [ "-1 4 4 4 2 \n-1 -1 3 2 1 \n-1 -1 1 1 1 1 \n" ] }
1,500
500
2
7
1434_A. Perform Easily
After battling Shikamaru, Tayuya decided that her flute is too predictable, and replaced it with a guitar. The guitar has 6 strings and an infinite number of frets numbered from 1. Fretting the fret number j on the i-th string produces the note a_{i} + j. Tayuya wants to play a melody of n notes. Each note can be play...
{ "input": [ "1 4 100 10 30 5\n6\n101 104 105 110 130 200\n", "1 1 2 2 3 3\n7\n13 4 11 12 11 13 12\n" ], "output": [ "0\n", "7\n" ] }
{ "input": [ "5 4 7 6 4 1\n10\n19 16 18 12 16 15 16 20 16 14\n", "158260522 877914575 602436426 24979445 861648772 623690081\n1\n896194147\n", "58260522 77914575 2436426 24979445 61648772 23690081\n10\n582107247 906728404 411434947 673536177 411497300 488012525 561127307 800305059 992325267 112738006\n", ...
1,900
1,500
2
7
1485_A. Add and Divide
You have two positive integers a and b. You can perform two kinds of operations: * a = ⌊ a/b βŒ‹ (replace a with the integer part of the division between a and b) * b=b+1 (increase b by 1) Find the minimum number of operations required to make a=0. Input The first line contains a single integer t (1 ≀ t ≀ 10...
{ "input": [ "6\n9 2\n1337 1\n1 1\n50000000 4\n991026972 997\n1234 5678\n" ], "output": [ "\n4\n9\n2\n12\n3\n1\n" ] }
{ "input": [ "9\n871488411 1\n361430393 1\n555768197 15\n191 44\n635551913 23\n282073944 35\n128 69\n842026539 6\n40 39\n", "19\n45713448 35\n788943748 304424261\n345831907 1\n887647097 205879610\n467441822 2\n716573439 455654889\n385540845 22\n170 66\n405486250 27\n980146694 822587672\n147 56\n329515648 1\n8...
1,000
500
2
9
1535_C. Unstable String
You are given a string s consisting of the characters 0, 1, and ?. Let's call a string unstable if it consists of the characters 0 and 1 and any two adjacent characters are different (i. e. it has the form 010101... or 101010...). Let's call a string beautiful if it consists of the characters 0, 1, and ?, and you can...
{ "input": [ "3\n0?10\n???\n?10??1100\n" ], "output": [ "\n8\n6\n25\n" ] }
{ "input": [ "1\n00000000\n" ], "output": [ "8\n" ] }
1,400
0
2
8
182_B. Vasya's Calendar
Vasya lives in a strange world. The year has n months and the i-th month has ai days. Vasya got a New Year present β€” the clock that shows not only the time, but also the date. The clock's face can display any number from 1 to d. It is guaranteed that ai ≀ d for all i from 1 to n. The clock does not keep information ab...
{ "input": [ "31\n12\n31 28 31 30 31 30 31 31 30 31 30 31\n", "5\n3\n3 4 3\n", "4\n2\n2 2\n" ], "output": [ "7", "3", "2" ] }
{ "input": [ "102\n100\n31 22 59 16 11 56 81 4 19 31 8 72 4 92 18 7 13 12 62 40 34 67 40 23 96 4 90 28 3 18 54 49 10 71 73 79 69 7 41 75 59 13 2 78 72 6 95 33 52 97 7 86 57 94 12 93 19 94 59 28 5 96 46 102 2 101 57 85 53 69 72 39 14 75 8 16 10 57 26 4 85 18 89 84 48 93 54 21 78 6 67 35 11 78 91 91 97 15 8 32\n", ...
1,000
500
2
10
205_D. Little Elephant and Cards
The Little Elephant loves to play with color cards. He has n cards, each has exactly two colors (the color of the front side and the color of the back side). Initially, all the cards lay on the table with the front side up. In one move the Little Elephant can turn any card to the other side. The Little Elephant thinks...
{ "input": [ "3\n4 7\n4 7\n7 4\n", "5\n4 7\n7 4\n2 11\n9 7\n1 1\n" ], "output": [ "0\n", "2\n" ] }
{ "input": [ "1\n1 2\n", "2\n1 1\n1 1\n", "5\n1 2\n1 3\n4 1\n5 1\n6 7\n", "4\n1 5\n2 5\n3 5\n4 4\n", "5\n1 5\n2 5\n3 5\n4 7\n2 5\n", "5\n1 6\n2 6\n3 6\n4 4\n5 5\n", "12\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n", "3\n2 1\n3 1\n4 1\n", "5\n4 7\n4 7\n2 7\n9 7\n1 1...
1,500
500
2
9
22_C. System Administrator
Bob got a job as a system administrator in X corporation. His first task was to connect n servers with the help of m two-way direct connection so that it becomes possible to transmit data from one server to any other server via these connections. Each direct connection has to link two different servers, each pair of se...
{ "input": [ "5 6 3\n", "6 100 1\n" ], "output": [ "3 1\n3 2\n3 4\n3 5\n2 4\n2 5\n", "-1\n" ] }
{ "input": [ "10 39377 1\n", "300 44553 1\n", "20 155 1\n", "300 44553 300\n", "100000 99998 1\n", "100000 0 100000\n", "200 34305 75\n", "30 393 29\n", "100 4283 65\n", "100000 99998 100000\n", "20 155 1\n", "5 6 3\n", "30 393 29\n", "123 13527 42\n", "100 ...
1,700
0
2
8
255_B. Code Parsing
Little Vitaly loves different algorithms. Today he has invented a new algorithm just for you. Vitaly's algorithm works with string s, consisting of characters "x" and "y", and uses two following operations at runtime: 1. Find two consecutive characters in the string, such that the first of them equals "y", and the s...
{ "input": [ "x\n", "yxyxy\n", "xxxxxy\n" ], "output": [ "x", "y", "xxxx" ] }
{ "input": [ "xxxyx\n", "xxxxxxxxxxxyxyyxxxxyxxxxxyxxxxxyxxxxxxxxyx\n", "yxyyxyyx\n", "yxxyxyx\n", "xxx\n", "xyyxyyyyyxxxxxxxyxyxyyxyyxyyxxyxyxyxxxyxxy\n", "yxxxx\n", "xxyxx\n", "yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy\n", "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n" ], ...
1,200
1,000
2
8
279_B. Books
When 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 going to need to read it. Let's number the books by integers from 1 to n. Valera needs ai minutes to read the ...
{ "input": [ "4 5\n3 1 2 1\n", "3 3\n2 2 3\n" ], "output": [ "3\n", "1\n" ] }
{ "input": [ "20 30\n8 1 2 6 9 4 1 9 9 10 4 7 8 9 5 7 1 8 7 4\n", "2 10\n6 4\n", "100 100\n75 92 18 6 81 67 7 92 100 65 82 32 50 67 85 31 80 91 84 63 39 52 92 81 1 98 24 12 43 48 17 86 51 72 48 95 45 50 12 66 19 79 49 89 34 1 97 75 20 33 96 27 42 23 73 71 93 1 85 19 66 14 17 61 20 39 36 33 42 61 56 64 23 ...
1,400
1,000
2
7
301_A. Yaroslav and Sequence
Yaroslav has an array, consisting of (2Β·n - 1) integers. In a single operation Yaroslav can change the sign of exactly n elements in the array. In other words, in one operation Yaroslav can select exactly n array elements, and multiply each of them by -1. Yaroslav is now wondering: what maximum sum of array elements c...
{ "input": [ "2\n-1 -100 -1\n", "2\n50 50 50\n" ], "output": [ "100\n", "150\n" ] }
{ "input": [ "5\n270 -181 957 -509 -6 937 -175 434 -625\n", "6\n-403 901 -847 -708 -624 413 -293 709 886 445 716\n", "4\n717 473 344 -51 -548 703 -869\n", "5\n-1 -2 -3 -4 -5 -6 -7 8 9\n", "22\n549 635 969 -519 -858 185 -788 126 -840 533 -560 168 -539 -962 649 -721 -574 245 -986 -859 496 -257 -361 ...
1,800
500
2
10
327_D. Block Tower
After too much playing on paper, Iahub has switched to computer games. The game he plays is called "Block Towers". It is played in a rectangular grid with n rows and m columns (it contains n Γ— m cells). The goal of the game is to build your own city. Some cells in the grid are big holes, where Iahub can't build any bui...
{ "input": [ "1 3\n...\n", "2 3\n..#\n.#.\n" ], "output": [ "7\nB 1 1\nB 1 2\nB 1 3\nD 1 3\nR 1 3\nD 1 2\nR 1 2\n", "8\nB 1 1\nB 2 1\nD 2 1\nR 2 1\nB 1 2\nD 1 2\nR 1 2\nB 2 3\n" ] }
{ "input": [ "1 1\n#\n", "1 500\n........................................................................................................................................................................................................................................................................................
1,900
2,000
2
7
373_A. Collecting Beats is Fun
Cucumber boy is fan of Kyubeat, a famous music game. Kyubeat has 16 panels for playing arranged in 4 Γ— 4 table. When a panel lights up, he has to press that panel. Each panel has a timing to press (the preffered time when a player should press it), and Cucumber boy is able to press at most k panels in a time with his...
{ "input": [ "5\n..1.\n1111\n..1.\n..1.\n", "1\n.135\n1247\n3468\n5789\n", "1\n....\n12.1\n.2..\n.2..\n" ], "output": [ "YES\n", "YES\n", "NO\n" ] }
{ "input": [ "4\n7777\n..7.\n.7..\n7...\n", "2\n8888\n8888\n8888\n8888\n", "4\n1111\n1221\n1221\n1111\n", "4\n...1\n..2.\n.3..\n4...\n", "1\n....\n....\n....\n....\n", "5\n4.4.\n4.4.\n4444\n..4.\n", "5\n9999\n9999\n9999\n9999\n", "4\n4.4.\n4.4.\n4444\n..4.\n", "1\n6981\n.527\n4163\...
900
500
2
9
394_C. Dominoes
During the break, we decided to relax and play dominoes. Our box with Domino was empty, so we decided to borrow the teacher's dominoes. The teacher responded instantly at our request. He put nm dominoes on the table as an n Γ— 2m rectangle so that each of the n rows contained m dominoes arranged horizontally. Each half...
{ "input": [ "4 1\n11\n10\n01\n00\n", "2 3\n01 11 00\n00 01 11\n" ], "output": [ "11 \n10 \n01 \n00 \n", "11 11 10 \n00 00 01 \n" ] }
{ "input": [ "1 1\n11\n", "2 3\n00 10 01\n01 01 00\n", "9 9\n10 10 10 01 10 11 11 01 10\n11 00 10 10 11 10 01 00 00\n10 00 11 01 00 01 01 11 10\n10 11 10 00 01 11 11 10 11\n01 11 11 01 11 00 10 00 01\n01 00 00 10 01 01 10 00 01\n11 10 11 10 01 00 00 11 00\n10 11 10 10 01 10 10 10 01\n10 10 10 10 11 11 01 ...
0
1,500
2
9
466_C. Number of Ways
You've got array a[1], a[2], ..., a[n], consisting of n integers. Count the number of ways to split all the elements of the array into three contiguous parts so that the sum of elements in each part is the same. More formally, you need to find the number of such pairs of indices i, j (2 ≀ i ≀ j ≀ n - 1), that <image>...
{ "input": [ "2\n4 1\n", "4\n0 1 -1 0\n", "5\n1 2 3 0 3\n" ], "output": [ "0\n", "1\n", "2\n" ] }
{ "input": [ "5\n1 1 1 1 1\n", "4\n0 2 -1 2\n", "9\n0 0 0 0 0 0 0 0 0\n", "100\n1 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 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\n", "2\n0 0\n", ...
1,700
1,500
2
7
48_A. Rock-paper-scissors
Uncle Fyodor, Matroskin the Cat and Sharic the Dog live their simple but happy lives in Prostokvashino. Sometimes they receive parcels from Uncle Fyodor’s parents and sometimes from anonymous benefactors, in which case it is hard to determine to which one of them the package has been sent. A photographic rifle is obvio...
{ "input": [ "scissors\nrock\nrock\n", "scissors\npaper\nrock\n", "rock\nrock\nrock\n", "paper\nrock\nrock\n" ], "output": [ "?\n", "?\n", "?\n", "F\n" ] }
{ "input": [ "rock\npaper\nrock\n", "scissors\nscissors\nrock\n", "rock\nscissors\npaper\n", "rock\npaper\nscissors\n", "scissors\nscissors\nscissors\n", "scissors\nscissors\npaper\n", "scissors\npaper\npaper\n", "rock\nscissors\nrock\n", "scissors\nrock\nscissors\n", "paper\np...
900
0
2
7
567_A. Lineland Mail
All cities of Lineland are located on the Ox coordinate axis. Thus, each city is associated with its position xi β€” a coordinate on the Ox axis. No two cities are located at a single point. Lineland residents love to send letters to each other. A person may send a letter only if the recipient lives in another city (bec...
{ "input": [ "2\n-1 1\n", "4\n-5 -2 2 7\n" ], "output": [ "2 2\n2 2\n", "3 12\n3 9\n4 7\n5 12\n" ] }
{ "input": [ "3\n-1000000000 0 1000000000\n", "5\n-2 -1 0 1 2\n", "10\n-876779400 -829849659 -781819137 -570920213 18428128 25280705 121178189 219147240 528386329 923854124\n", "3\n-1 0 1\n", "4\n-1 0 1 3\n", "10\n-857422304 -529223472 82412729 145077145 188538640 265299215 527377039 588634631...
900
500
2
9
588_C. Duff and Weight Lifting
Recently, Duff has been practicing weight lifting. As a hard practice, Malek gave her a task. He gave her a sequence of weights. Weight of i-th of them is 2wi pounds. In each step, Duff can lift some of the remaining weights and throw them away. She does this until there's no more weight left. Malek asked her to minimi...
{ "input": [ "5\n1 1 2 3 3\n", "4\n0 1 2 3\n" ], "output": [ "2\n", "4\n" ] }
{ "input": [ "13\n92 194 580495 0 10855 41704 13 96429 33 213 0 92 140599\n", "1\n120287\n", "35\n130212 3176 77075 8071 18 1369 7539 1683 80757 1847 0 1374 122 8524 4 2 21333 270264 4 9254 151921 0 1 33596 73002 54382 0 1 29233 75952 15 38892 1877 6167 4\n", "2\n95745 95745\n", "35\n0 0 298 0 0 0...
1,500
500
2
11
60_E. Mushroom Gnomes
Once upon a time in the thicket of the mushroom forest lived mushroom gnomes. They were famous among their neighbors for their magic mushrooms. Their magic nature made it possible that between every two neighboring mushrooms every minute grew another mushroom with the weight equal to the sum of weights of two neighbori...
{ "input": [ "2 1 0 657276545\n1 2\n", "4 5 0 10000\n1 2 3 4\n", "2 1 1 888450282\n1 2\n" ], "output": [ "6", "1825", "14" ] }
{ "input": [ "8 4 9 371687114\n1 7 22 31 35 38 62 84\n", "2 1000000000 1000000000000 10000\n1 2\n", "1 1 1 2\n0\n", "4 0 8 414790855\n1 88 97 99\n", "1 1 1 2\n1000000000\n", "1 1 1 2\n2\n", "1 0 1 1000000000\n1000000000\n", "11 10 6 560689961\n2 17 20 24 32 37 38 39 40 61 86\n", "4...
2,600
2,500
2
16
630_J. Divisibility
IT City company developing computer games invented a new way to reward its employees. After a new game release users start buying it actively, and the company tracks the number of sales with precision to each transaction. Every time when the next number of sales is divisible by all numbers from 2 to 10 every developer ...
{ "input": [ "3000\n" ], "output": [ "1\n" ] }
{ "input": [ "2519\n", "12\n", "2520\n", "1\n", "3628800\n", "718281828459045235\n", "2521\n", "987654321234567890\n", "1000000000000000000\n", "314159265\n", "504000000000000000\n" ], "output": [ "0\n", "0\n", "1\n", "0\n", "1440\n", "2850324716...
1,100
0
2
8
659_B. Qualifying Contest
Very soon Berland will hold a School Team Programming Olympiad. From each of the m Berland regions a team of two people is invited to participate in the olympiad. The qualifying contest to form teams was held and it was attended by n Berland students. There were at least two schoolboys participating from each of the m ...
{ "input": [ "5 2\nIvanov 1 763\nAndreev 2 800\nPetrov 1 595\nSidorov 1 790\nSemenov 2 503\n", "5 2\nIvanov 1 800\nAndreev 2 763\nPetrov 1 800\nSidorov 1 800\nSemenov 2 503\n" ], "output": [ "Sidorov Ivanov\nAndreev Semenov\n", "?\nAndreev Semenov\n" ] }
{ "input": [ "2 1\na 1 10\nb 1 10\n", "2 1\nOAELh 1 733\nbFGs 1 270\n", "2 1\nA 1 5\nB 1 5\n", "3 1\nA 1 5\nB 1 4\nC 1 4\n", "3 1\na 1 10\nb 1 20\nc 1 20\n", "4 2\nIvanov 1 1\nAndreev 1 1\nPetrov 2 1\nSidorov 2 1\n", "2 1\na 1 0\nb 1 0\n", "10 2\nSHiBIEz 2 628\nXxwaAxB 1 190\nXwR 2 290...
1,300
1,000
2
10
681_D. Gifts by the List
Sasha lives in a big happy family. At the Man's Day all the men of the family gather to celebrate it following their own traditions. There are n men in Sasha's family, so let's number them with integers from 1 to n. Each man has at most one father but may have arbitrary number of sons. Man number A is considered to b...
{ "input": [ "3 2\n1 2\n2 3\n1 2 1\n", "4 2\n1 2\n3 4\n1 2 3 3\n" ], "output": [ "-1\n", "3\n2\n1\n3\n" ] }
{ "input": [ "1 0\n1\n", "4 3\n4 3\n3 2\n2 1\n3 4 4 4\n", "4 3\n1 2\n2 3\n3 4\n1 1 1 2\n", "4 3\n1 2\n2 3\n3 4\n1 1 3 2\n", "2 1\n2 1\n1 2\n", "2 1\n2 1\n2 2\n" ], "output": [ "1\n1\n", "-1\n", "-1\n", "-1\n", "2\n1\n2\n", "1\n2\n" ] }
2,000
2,000
2
7
727_A. Transformation: from A to B
Vasily has a number a, which he wants to turn into a number b. For this purpose, he can do two types of operations: * multiply the current number by 2 (that is, replace the number x by 2Β·x); * append the digit 1 to the right of current number (that is, replace the number x by 10Β·x + 1). You need to help Vasil...
{ "input": [ "4 42\n", "2 162\n", "100 40021\n" ], "output": [ "NO\n", "YES\n5\n2 4 8 81 162 \n", "YES\n5\n100 200 2001 4002 40021 \n" ] }
{ "input": [ "999999999 1000000000\n", "13494 1079528\n", "92387 184774\n", "25539 510782222\n", "91939 9193911\n", "9411 188222222\n", "250000000 705032705\n", "1 111111111\n", "30518 610361\n", "96022 1920442\n", "30070 300701\n", "5440 27853056\n", "59139 946224\...
1,000
1,000
2
8
748_B. Santa Claus and Keyboard Check
Santa Claus decided to disassemble his keyboard to clean it. After he returned all the keys back, he suddenly realized that some pairs of keys took each other's place! That is, Santa suspects that each key is either on its place, or on the place of another key, which is located exactly where the first key should be. ...
{ "input": [ "helloworld\nehoolwlroz\n", "hastalavistababy\nhastalavistababy\n", "merrychristmas\nchristmasmerry\n" ], "output": [ "3\nh e\nl o\nd z\n", "0\n", "-1\n" ] }
{ "input": [ "acbacacbbb\nacbacacbbb\n", "dacbdbbbdd\nadbdadddaa\n", "ijpanyhovzwjjxsvaiyhchfaulcsdgfszjnwtoqbtaqygfmxuwvynvlhqhvmkjbooklxfhmqlqvfoxlnoclfxtbhvnkmhjcmrsdc\nijpanyhovzwjjxsvaiyhchfaulcsdgfszjnwtoqbtaqygfmxuwvynvlhqhvmkjbooklxfhmqlqvfoxlnoclfxtbhvnkmhjcmrsdc\n", "qwertyuiopasdfghjklzx\nz...
1,500
1,000
2
7
771_A. Bear and Friendship Condition
Bear Limak examines a social network. Its main functionality is that two members can become friends (then they can talk with each other and share funny pictures). There are n members, numbered 1 through n. m pairs of members are friends. Of course, a member can't be a friend with themselves. Let A-B denote that membe...
{ "input": [ "10 4\n4 3\n5 10\n8 9\n1 2\n", "4 4\n3 1\n2 3\n3 4\n1 2\n", "3 2\n1 2\n2 3\n", "4 3\n1 3\n3 4\n1 4\n" ], "output": [ "YES\n", "NO\n", "NO\n", "YES\n" ] }
{ "input": [ "4 5\n1 2\n1 3\n1 4\n2 3\n2 4\n", "6 6\n1 2\n2 3\n3 4\n4 5\n5 6\n1 6\n", "4 3\n1 2\n1 3\n1 4\n", "4 4\n1 2\n2 3\n3 4\n4 1\n", "5 5\n1 2\n2 3\n3 4\n4 5\n5 1\n", "150000 3\n150000 149999\n149998 149999\n149998 150000\n", "5 9\n1 2\n5 1\n3 1\n1 4\n2 4\n5 3\n5 4\n2 3\n5 2\n", ...
1,500
250
2
7
796_A. Buying A House
Zane the wizard had never loved anyone before, until he fell in love with a girl, whose name remains unknown to us. <image> The girl lives in house m of a village. There are n houses in that village, lining in a straight line from left to right: house 1, house 2, ..., house n. The village is also well-structured: hou...
{ "input": [ "10 5 100\n1 0 1 0 0 0 0 0 1 1\n", "5 1 20\n0 27 32 21 19\n", "7 3 50\n62 0 0 0 99 33 22\n" ], "output": [ "20", "40", "30" ] }
{ "input": [ "10 2 14\n2 0 1 26 77 39 41 100 13 32\n", "30 29 10\n59 79 34 12 100 6 1 58 18 73 54 11 37 46 89 90 80 85 73 45 64 5 31 0 89 19 0 74 0 82\n", "100 100 34\n5 73 0 0 44 0 0 0 79 55 0 0 0 0 0 0 0 0 83 67 75 0 0 0 0 59 0 74 0 0 47 98 0 0 72 41 0 55 87 0 0 78 84 0 0 39 0 79 72 95 0 0 0 0 0 85 53 8...
800
500
2
8
816_B. Karen and Coffee
To stay woke and attentive during classes, Karen needs some coffee! <image> Karen, a coffee aficionado, wants to know the optimal temperature for brewing the perfect cup of coffee. Indeed, she has spent some time reading several recipe books, including the universally acclaimed "The Art of the Covfefe". She knows n ...
{ "input": [ "3 2 4\n91 94\n92 97\n97 99\n92 94\n93 97\n95 96\n90 100\n", "2 1 1\n1 1\n200000 200000\n90 100\n" ], "output": [ "3\n3\n0\n4\n", "0\n" ] }
{ "input": [ "1 1 1\n1 1\n1 1\n", "1 1 1\n200000 200000\n200000 200000\n" ], "output": [ "1\n", "1\n" ] }
1,400
1,000
2
8
841_B. Godsend
Leha somehow found an array consisting of n integers. Looking at it, he came up with a task. Two players play the game on the array. Players move one by one. The first player can choose for his move a subsegment of non-zero length with an odd sum of numbers and remove it from the array, after that the remaining parts a...
{ "input": [ "4\n1 3 2 3\n", "2\n2 2\n" ], "output": [ "First\n", "Second\n" ] }
{ "input": [ "6\n2 2 1 1 4 2\n", "3\n1 2 2\n", "5\n1 1 1 1 1\n", "3\n2 1 1\n", "4\n2 1 1 2\n", "4\n1000000000 1000000000 1000000000 1\n", "11\n2 2 2 2 2 1 2 2 2 2 2\n", "2\n1 1\n", "1\n1\n", "1\n0\n", "4\n2 4 6 8\n", "4\n3 3 4 4\n", "8\n2 2 2 1 1 2 2 2\n", "3\n2...
1,100
1,000
2
9
862_C. Mahmoud and Ehab and the xor
Mahmoud and Ehab are on the third stage of their adventures now. As you know, Dr. Evil likes sets. This time he won't show them any set from his large collection, but will ask them to create a new set to replenish his beautiful collection of sets. Dr. Evil has his favorite evil integer x. He asks Mahmoud and Ehab to f...
{ "input": [ "3 6\n", "5 5\n" ], "output": [ "YES\n0 131072 131078\n", "YES\n1 2 0 131072 131078\n" ] }
{ "input": [ "3 3\n", "3 10203\n", "4 2\n", "5 9\n", "1 0\n", "3 0\n", "3 1\n", "3 4\n", "5 5\n", "2 3\n", "10 2\n", "1 1\n", "3 2\n", "4 0\n", "5 2\n", "5 6\n", "4 3\n", "3 6\n", "5 3\n", "32 32\n", "5 1\n", "3 10100\n", "6 0...
1,900
1,500
2
7
888_A. Local Extrema
You are given an array a. Some element of this array ai is a local minimum iff it is strictly less than both of its neighbours (that is, ai < ai - 1 and ai < ai + 1). Also the element can be called local maximum iff it is strictly greater than its neighbours (that is, ai > ai - 1 and ai > ai + 1). Since a1 and an have ...
{ "input": [ "3\n1 2 3\n", "4\n1 5 2 5\n" ], "output": [ "0\n", "2\n" ] }
{ "input": [ "3\n3 2 3\n", "1\n548\n", "3\n1 2 1\n", "1\n1\n", "2\n1 1\n", "2\n1 1000\n" ], "output": [ "1\n", "0\n", "1\n", "0\n", "0\n", "0\n" ] }
800
0
2
8
910_B. Door Frames
Petya has equal wooden bars of length n. He wants to make a frame for two equal doors. Each frame has two vertical (left and right) sides of length a and one top side of length b. A solid (i.e. continuous without breaks) piece of bar is needed for each side. Determine a minimal number of wooden bars which are needed t...
{ "input": [ "6\n4\n2\n", "5\n3\n4\n", "8\n1\n2\n", "20\n5\n6\n" ], "output": [ "4", "6", "1", "2" ] }
{ "input": [ "8\n3\n5\n", "586\n22\n272\n", "266\n38\n164\n", "648\n624\n384\n", "11\n3\n5\n", "100\n40\n60\n", "5\n2\n4\n", "828\n363\n56\n", "593\n442\n112\n", "7\n4\n1\n", "1000\n1\n498\n", "5\n1\n3\n", "6\n6\n1\n", "156\n34\n7\n", "169\n158\n11\n", "...
1,600
1,000
2
11
959_E. Mahmoud and Ehab and the xor-MST
Ehab is interested in the bitwise-xor operation and the special graphs. Mahmoud gave him a problem that combines both. He has a complete graph consisting of n vertices numbered from 0 to n - 1. For all 0 ≀ u < v < n, vertex u and vertex v are connected with an undirected edge that has weight <image> (where <image> is t...
{ "input": [ "4\n" ], "output": [ "4\n" ] }
{ "input": [ "2\n", "7\n", "536870913\n", "1048576\n", "1024\n", "999999999999\n", "123456789\n", "3\n", "10\n", "12000\n", "1000\n", "549755813889\n", "549755813888\n", "100000\n", "536870911\n", "1000000000000\n", "65536\n", "536870912\n", ...
1,900
2,000
2
9
986_C. AND Graph
You are given a set of size m with integer elements between 0 and 2^{n}-1 inclusive. Let's build an undirected graph on these integers in the following way: connect two integers x and y with an edge if and only if x \& y = 0. Here \& is the [bitwise AND operation](https://en.wikipedia.org/wiki/Bitwise_operation#AND). C...
{ "input": [ "2 3\n1 2 3\n", "5 5\n5 19 10 20 12\n" ], "output": [ "2\n", "2\n" ] }
{ "input": [ "6 19\n15 23 27 29 30 31 43 46 47 51 53 55 57 58 59 60 61 62 63\n", "3 5\n3 5 0 6 7\n", "0 1\n0\n", "1 1\n0\n", "1 1\n1\n", "6 22\n21 23 26 28 31 35 38 39 41 42 44 45 47 50 51 52 54 55 56 59 62 63\n", "6 35\n5 7 10 11 13 14 17 18 25 27 28 29 30 31 33 35 36 37 39 40 41 43 46 47...
2,500
1,750
2
12
1006_F. Xor-Paths
There is a rectangular grid of size n Γ— m. Each cell has a number written on it; the number on the cell (i, j) is a_{i, j}. Your task is to calculate the number of paths from the upper-left cell (1, 1) to the bottom-right cell (n, m) meeting the following constraints: * You can move to the right or to the bottom onl...
{ "input": [ "3 4 1000000000000000000\n1 3 3 3\n0 3 3 2\n3 0 1 1\n", "3 3 11\n2 1 5\n7 10 0\n12 6 4\n", "3 4 2\n1 3 3 3\n0 3 3 2\n3 0 1 1\n" ], "output": [ "0\n", "3\n", "5\n" ] }
{ "input": [ "1 1 982347923479\n1\n", "2 10 2047\n1 2 4 8 16 32 64 128 256 512\n2 4 8 16 32 64 128 256 512 1024\n", "1 1 1\n1\n", "20 1 1048575\n1\n2\n4\n8\n16\n32\n64\n128\n256\n512\n1024\n2048\n4096\n8192\n16384\n32768\n65536\n131072\n262144\n524288\n", "10 1 1023\n1\n2\n4\n8\n16\n32\n64\n128\n2...
2,100
0
2
11
1051_E. Vasya and Big Integers
Vasya owns three big integers β€” a, l, r. Let's define a partition of x such a sequence of strings s_1, s_2, ..., s_k that s_1 + s_2 + ... + s_k = x, where + is a concatanation of strings. s_i is the i-th element of the partition. For example, number 12345 has the following partitions: ["1", "2", "3", "4", "5"], ["123",...
{ "input": [ "135\n1\n15\n", "10000\n0\n9\n" ], "output": [ "2", "1" ] }
{ "input": [ "8698272232067125804692796793285996652907461532074057999849092982935510140661249431760679611642931478\n6\n68270\n", "1254298816872758107814873768638894851215334772406487549640220733524354123084977151799244616404710412\n35\n9634401298\n", "123\n0\n0\n", "12212222221212222221221221222222121...
2,600
0
2
12
1073_F. Choosing Two Paths
You are given an undirected unweighted tree consisting of n vertices. An undirected tree is a connected undirected graph with n - 1 edges. Your task is to choose two pairs of vertices of this tree (all the chosen vertices should be distinct) (x_1, y_1) and (x_2, y_2) in such a way that neither x_1 nor y_1 belong to t...
{ "input": [ "9\n9 3\n3 5\n1 2\n4 3\n4 7\n1 7\n4 6\n3 8\n", "10\n6 8\n10 3\n3 7\n5 8\n1 7\n7 2\n2 9\n2 8\n1 4\n", "11\n1 2\n2 3\n3 4\n1 5\n1 6\n6 7\n5 8\n5 9\n4 10\n4 11\n", "7\n1 4\n1 5\n1 6\n2 3\n2 4\n4 7\n" ], "output": [ "8 2\n5 6\n", "10 6\n4 5\n", "11 9\n10 8\n", "3 6\n7 5\n"...
{ "input": [ "6\n1 2\n1 3\n1 4\n4 5\n4 6\n", "14\n3 2\n4 10\n10 6\n7 12\n8 7\n14 1\n8 4\n5 10\n3 13\n3 9\n8 1\n11 5\n3 8\n" ], "output": [ "6 3\n5 2\n", "11 2\n6 13\n" ] }
2,500
0
2
12
1095_F. Make It Connected
You are given an undirected graph consisting of n vertices. A number is written on each vertex; the number on vertex i is a_i. Initially there are no edges in the graph. You may add some edges to this graph, but you have to pay for them. The cost of adding an edge between vertices x and y is a_x + a_y coins. There are...
{ "input": [ "5 4\n1 2 3 4 5\n1 2 8\n1 3 10\n1 4 7\n1 5 15\n", "3 2\n1 3 3\n2 3 5\n2 1 1\n", "4 0\n1 3 3 7\n" ], "output": [ "18\n", "5\n", "16\n" ] }
{ "input": [ "1 0\n4\n", "10 0\n9 9 5 2 2 5 8 5 1 7\n", "10 1\n2 2 9 7 2 3 7 7 1 1\n5 8 4\n", "2 1\n100000000000 100000000000\n1 2 199999999999\n", "10 10\n3 4 5 10 10 9 5 4 7 8\n1 5 5\n10 3 18\n1 7 20\n7 8 20\n10 4 8\n10 2 17\n9 4 2\n7 5 16\n1 8 17\n7 10 18\n", "1 0\n1\n", "2 1\n72 94\n2 ...
1,900
0
2
7
1117_A. Best Subsegment
You are given array a_1, a_2, ..., a_n. Find the subsegment a_l, a_{l+1}, ..., a_r (1 ≀ l ≀ r ≀ n) with maximum arithmetic mean (1)/(r - l + 1)βˆ‘_{i=l}^{r}{a_i} (in floating-point numbers, i.e. without any rounding). If there are many such subsegments find the longest one. Input The first line contains single integer...
{ "input": [ "5\n6 1 6 6 0\n" ], "output": [ "2\n" ] }
{ "input": [ "2\n1 5\n", "5\n1 0 0 0 0\n", "15\n2 2 1 2 2 2 2 1 2 2 2 1 2 2 3\n", "2\n1 2\n", "4\n2 2 1 3\n", "3\n0 0 0\n", "5\n1 3 3 1 3\n", "10\n0 0 0 0 0 0 0 0 0 0\n", "2\n1000 16777252\n", "1\n0\n", "4\n0 0 0 0\n", "7\n1 1 1 0 1 2 2\n", "5\n1 1 1 0 2\n", "5\...
1,100
0
2
9
1143_C. Queen
You are given a rooted tree with vertices numerated from 1 to n. A tree is a connected graph without cycles. A rooted tree has a special vertex named root. Ancestors of the vertex i are all vertices on the path from the root to the vertex i, except the vertex i itself. The parent of the vertex i is the nearest to the ...
{ "input": [ "5\n3 1\n1 1\n-1 0\n2 1\n3 0\n", "8\n2 1\n-1 0\n1 0\n1 1\n1 1\n4 0\n5 1\n7 0\n", "5\n-1 0\n1 1\n1 1\n2 0\n3 0\n" ], "output": [ "1 2 4\n", "5\n", "-1\n" ] }
{ "input": [ "1\n-1 0\n" ], "output": [ "-1\n" ] }
1,400
1,000
2
9
1163_C1. Power Transmission (Easy Edition)
This problem is same as the next one, but has smaller constraints. It was a Sunday morning when the three friends Selena, Shiro and Katie decided to have a trip to the nearby power station (do not try this at home). After arriving at the power station, the cats got impressed with a large power transmission system cons...
{ "input": [ "4\n0 0\n1 1\n0 3\n1 2\n", "4\n0 0\n0 2\n0 4\n2 0\n", "3\n-1 -1\n1 0\n3 1\n" ], "output": [ "14\n", "6\n", "0\n" ] }
{ "input": [ "2\n10000 10000\n-10000 -10000\n", "5\n-8893 8986\n-3629 9045\n-7719 -6470\n-258 4491\n-6902 -6866\n", "25\n1964 -4517\n5939 -4080\n9503 -7541\n-5037 -6950\n-9914 5015\n-435 7555\n-9321 -2202\n-5036 4224\n4946 -6785\n-6824 -9830\n-9124 9117\n-8396 -2748\n9284 556\n-1672 -6681\n-8782 9912\n-81...
1,900
1,000
2
7
1184_A1. Heidi Learns Hashing (Easy)
Melody Pond was stolen from her parents as a newborn baby by Madame Kovarian, to become a weapon of the Silence in their crusade against the Doctor. Madame Kovarian changed Melody's name to River Song, giving her a new identity that allowed her to kill the Eleventh Doctor. Heidi figured out that Madame Kovarian uses a...
{ "input": [ "19\n", "16\n" ], "output": [ "1 8\n", "NO\n" ] }
{ "input": [ "768407398177\n", "7\n", "156231653273\n", "426262703497\n", "688373050717\n", "149890929717\n", "5\n", "185589070745\n", "943447972637\n", "15\n", "21\n", "540024979445\n", "963761198401\n", "215283472163\n", "17\n", "54336309171\n", "7...
1,200
0
2
10
1201_D. Treasure Hunting
You are on the island which can be represented as a n Γ— m table. The rows are numbered from 1 to n and the columns are numbered from 1 to m. There are k treasures on the island, the i-th of them is located at the position (r_i, c_i). Initially you stand at the lower left corner of the island, at the position (1, 1). I...
{ "input": [ "3 6 3 2\n1 6\n2 2\n3 4\n1 6\n", "3 3 3 2\n1 1\n2 1\n3 1\n2 3\n", "3 5 3 2\n1 2\n2 3\n3 1\n1 5\n" ], "output": [ "15\n", "6\n", "8\n" ] }
{ "input": [ "2 11 7 6\n1 1\n1 5\n1 2\n1 4\n1 11\n1 8\n1 3\n3 6 5 10 2 7\n", "2 2 2 2\n1 1\n1 2\n1 2\n", "200000 200000 2 2\n104889 58569\n855 142967\n125218 47859\n", "5 5 10 3\n3 1\n3 2\n3 5\n1 5\n2 1\n2 5\n1 2\n1 4\n3 3\n2 4\n2 1 5\n", "3 21 49 11\n3 5\n1 14\n2 17\n3 17\n3 9\n1 9\n3 20\n2 9\n3 ...
2,100
2,000
2
9
1219_C. Periodic integer number
Alice became interested in periods of integer numbers. We say positive X integer number is periodic with length L if there exists positive integer number P with L digits such that X can be written as PPPP…P. For example: X = 123123123 is periodic number with length L = 3 and L = 9 X = 42424242 is periodic number with...
{ "input": [ "3\n12345\n", "3\n123456\n" ], "output": [ "100100", "124124" ] }
{ "input": [ "3\n145023023\n", "4\n50265026\n", "23423\n1948916891390760969925517119308508122462261178994392760622205428062301680068135601856269086680512047953392436718960113434350798719501978568591385156725298362975132597530210233687905324089918151808143789592402149024855221050883884379010555802046542371...
1,700
0
2
9
1243_C. Tile Painting
Ujan has been lazy lately, but now has decided to bring his yard to good shape. First, he decided to paint the path from his house to the gate. The path consists of n consecutive tiles, numbered from 1 to n. Ujan will paint each tile in some color. He will consider the path aesthetic if for any two different tiles wit...
{ "input": [ "5\n", "4\n" ], "output": [ "5\n", "2\n" ] }
{ "input": [ "2\n", "54241012609\n", "4294967318\n", "370758709373\n", "546739553053\n", "922350872881\n", "442654694329\n", "832972004929\n", "931667836027\n", "6469693230\n", "9\n", "243\n", "549755813888\n", "902076349729\n", "2000006\n", "91651710780...
1,500
500
2
8
1263_B. PIN Codes
A PIN code is a string that consists of exactly 4 digits. Examples of possible PIN codes: 7013, 0000 and 0990. Please note that the PIN code can begin with any digit, even with 0. Polycarp has n (2 ≀ n ≀ 10) bank cards, the PIN code of the i-th card is p_i. Polycarp has recently read a recommendation that it is bette...
{ "input": [ "3\n2\n1234\n0600\n2\n1337\n1337\n4\n3139\n3139\n3139\n3139\n" ], "output": [ "0\n1234\n0600\n1\n1337\n0337\n3\n3139\n0139\n1139\n2139\n" ] }
{ "input": [ "1\n3\n1111\n1111\n1112\n", "1\n3\n0000\n0000\n0009\n", "1\n4\n0000\n0000\n0000\n0001\n", "1\n3\n1234\n1234\n1230\n", "3\n10\n0000\n0000\n0000\n0000\n0000\n0000\n0000\n0000\n0000\n0000\n1\n1234\n7\n1234\n4567\n8901\n2345\n6789\n0123\n4567\n", "3\n3\n0000\n0000\n0001\n4\n0000\n0000...
1,400
1,250
2
7
1328_A. Divisibility Problem
You are given two positive integers a and b. In one move you can increase a by 1 (replace a with a+1). Your task is to find the minimum number of moves you need to do in order to make a divisible by b. It is possible, that you have to make 0 moves, as a is already divisible by b. You have to answer t independent test c...
{ "input": [ "5\n10 4\n13 9\n100 13\n123 456\n92 46\n" ], "output": [ "2\n5\n4\n333\n0\n" ] }
{ "input": [ "1\n515151 2\n", "21\n1 3218\n28 10924\n908802 141084\n82149 9274\n893257 10248\n2750048 802705\n2857 142\n980 209385\n1 3218\n28 10924\n908802 141084\n82149 9274\n893257 10248\n2750048 802705\n2857 142\n980 209385\n1 3218\n28 10924\n908802 141084\n82149 9274\n893257 10248\n", "1\n9987 1\n", ...
800
0
2
7
1348_A. Phoenix and Balance
Phoenix has n coins with weights 2^1, 2^2, ..., 2^n. He knows that n is even. He wants to split the coins into two piles such that each pile has exactly n/2 coins and the difference of weights between the two piles is minimized. Formally, let a denote the sum of weights in the first pile, and b denote the sum of weigh...
{ "input": [ "2\n2\n4\n" ], "output": [ "2\n6\n" ] }
{ "input": [ "100\n2\n4\n6\n8\n10\n12\n14\n16\n18\n20\n22\n24\n26\n28\n30\n30\n30\n30\n20\n30\n30\n18\n14\n16\n30\n24\n30\n30\n10\n20\n30\n10\n2\n18\n30\n30\n12\n24\n30\n24\n18\n28\n30\n16\n30\n30\n30\n30\n22\n26\n30\n30\n30\n10\n14\n6\n18\n30\n16\n30\n30\n4\n30\n20\n30\n30\n30\n30\n30\n24\n30\n30\n12\n30\n30\n30...
800
500
2
7
1413_A. Finding Sasuke
Naruto has sneaked into the Orochimaru's lair and is now looking for Sasuke. There are T rooms there. Every room has a door into it, each door can be described by the number n of seals on it and their integer energies a_1, a_2, ..., a_n. All energies a_i are nonzero and do not exceed 100 by absolute value. Also, n is e...
{ "input": [ "2\n2\n1 100\n4\n1 2 3 6\n" ], "output": [ "-100 1\n-2 1 -6 3\n" ] }
{ "input": [ "2\n2\n1 100\n4\n1 2 3 6\n", "6\n6\n-1 1 1 1 1 1\n6\n1 -1 1 1 1 1\n6\n1 1 -1 1 1 1\n6\n1 1 1 -1 1 1\n6\n1 1 1 1 -1 1\n6\n1 1 1 1 1 -1\n" ], "output": [ "-100 1\n-2 1 -6 3\n", "-1 -1 -1 1 -1 1\n1 1 -1 1 -1 1\n-1 1 -1 -1 -1 1\n-1 1 1 1 -1 1\n-1 1 -1 1 -1 -1\n-1 1 -1 1 1 1\n" ] }
800
500
2
7
1455_A. Strange Functions
Let's define a function f(x) (x is a positive integer) as follows: write all digits of the decimal representation of x backwards, then get rid of the leading zeroes. For example, f(321) = 123, f(120) = 21, f(1000000) = 1, f(111) = 111. Let's define another function g(x) = (x)/(f(f(x))) (x is a positive integer as well...
{ "input": [ "5\n4\n37\n998244353\n1000000007\n12345678901337426966631415\n" ], "output": [ "\n1\n2\n9\n10\n26\n" ] }
{ "input": [ "1\n10000000\n", "1\n1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\n", "1\n99999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999\n", "5\n9999999999999999999999999999999999999999999999999999999...
800
0
2
8
1479_B2. Painting the Array II
The only difference between the two versions is that this version asks the minimal possible answer. Homer likes arrays a lot. Today he is painting an array a_1, a_2, ..., a_n with two kinds of colors, white and black. A painting assignment for a_1, a_2, ..., a_n is described by an array b_1, b_2, ..., b_n that b_i ind...
{ "input": [ "7\n1 2 1 2 1 2 1\n", "6\n1 2 3 1 2 2\n" ], "output": [ "\n2\n", "\n4\n" ] }
{ "input": [ "1\n1\n", "11\n2 3 10 3 3 8 9 2 11 10 3\n", "11\n10 5 8 8 2 7 9 3 5 1 10\n", "15\n4 4 8 8 10 10 15 7 2 15 2 12 12 3 15\n" ], "output": [ "1\n", "8\n", "9\n", "8\n" ] }
2,100
750
2
8
1529_B. Sifid and Strange Subsequences
A sequence (b_1, b_2, …, b_k) is called strange, if the absolute difference between any pair of its elements is greater than or equal to the maximum element in the sequence. Formally speaking, it's strange if for every pair (i, j) with 1 ≀ i<j ≀ k, we have |a_i-a_j|β‰₯ MAX, where MAX is the largest element of the sequenc...
{ "input": [ "6\n4\n-1 -2 0 0\n7\n-3 4 -2 0 -4 6 1\n5\n0 5 -3 2 -5\n3\n2 3 1\n4\n-3 0 2 0\n6\n-3 -2 -1 1 1 1\n" ], "output": [ "\n4\n5\n4\n1\n3\n4\n" ] }
{ "input": [ "1\n1\n0\n", "1\n5\n-1 -1 -1 -1 -1\n", "1\n6\n1 1 0 0 0 0\n", "1\n3\n1000000000 1000000000 1000000000\n", "1\n2\n-1000000000 1000000000\n", "1\n4\n-4 -1 0 3\n", "1\n2\n0 1\n", "1\n3\n-2 0 3\n" ], "output": [ "1\n", "5\n", "4\n", "1\n", "2\n", "3...
1,100
1,250
2
8
160_B. Unlucky Ticket
Each of you probably has your personal experience of riding public transportation and buying tickets. After a person buys a ticket (which traditionally has an even number of digits), he usually checks whether the ticket is lucky. Let us remind you that a ticket is lucky if the sum of digits in its first half matches th...
{ "input": [ "2\n3754\n", "2\n0135\n", "2\n2421\n" ], "output": [ "NO\n", "YES\n", "YES\n" ] }
{ "input": [ "20\n7405800505032736115894335199688161431589\n", "100\n02002102210011010100120120200220102011120101221112212222120020210120100100210020110121012200202122003345665163205330111020604514053164225655212253500113103534213313020162345540026653211623642123220355\n", "10\n10001222212022211120\n", ...
1,100
1,000
2
10
227_D. Naughty Stone Piles
There are n piles of stones of sizes a1, a2, ..., an lying on the table in front of you. During one move you can take one pile and add it to the other. As you add pile i to pile j, the size of pile j increases by the current size of pile i, and pile i stops existing. The cost of the adding operation equals the size of...
{ "input": [ "5\n2 3 4 1 1\n2\n2 3\n" ], "output": [ "9 8\n" ] }
{ "input": [ "3\n1 6 8\n1\n6\n", "1\n10\n5\n5 3 7 7 1\n", "4\n7 4 1 7\n3\n6 8 3\n", "1\n1\n3\n2 1 10\n", "1\n1\n3\n2 1 10\n", "2\n2 9\n5\n4 10 7 3 4\n", "1\n10\n5\n5 3 7 7 1\n", "1\n2\n5\n7 3 9 8 1\n", "2\n9 3\n1\n6\n", "1\n7\n4\n6 2 3 3\n", "2\n7 4\n1\n7\n", "2\n7 10\n...
1,900
1,000
2
8
251_B. Playing with Permutations
Little Petya likes permutations a lot. Recently his mom has presented him permutation q1, q2, ..., qn of length n. A permutation a of length n is a sequence of integers a1, a2, ..., an (1 ≀ ai ≀ n), all integers there are distinct. There is only one thing Petya likes more than permutations: playing with little Masha...
{ "input": [ "4 1\n4 3 1 2\n3 4 2 1\n", "4 1\n4 3 1 2\n2 1 4 3\n", "4 3\n4 3 1 2\n3 4 2 1\n", "4 1\n2 3 4 1\n1 2 3 4\n", "4 2\n4 3 1 2\n2 1 4 3\n" ], "output": [ "YES\n", "NO\n", "YES\n", "NO\n", "YES\n" ] }
{ "input": [ "4 2\n2 1 4 3\n2 1 4 3\n", "13 2\n2 3 4 5 6 7 8 9 10 11 12 13 1\n3 4 5 6 7 8 9 10 11 12 13 1 2\n", "1 1\n1\n1\n", "8 10\n2 3 1 5 6 7 8 4\n2 3 1 4 5 6 7 8\n", "9 3\n2 3 4 5 6 7 8 9 1\n3 4 5 6 7 8 9 1 2\n", "55 28\n34 11 18 6 16 43 12 25 48 27 35 17 19 14 33 30 7 53 52 2 15 10 44 1 ...
1,800
1,000
2
9
276_C. Little Girl and Maximum Sum
The 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 starting from 1); also, there are q queries, each one is defined by a pair of integers l_i, r_i (1 ≀ l_i ≀ r_i ≀ n). You need to f...
{ "input": [ "5 3\n5 2 4 1 3\n1 5\n2 3\n2 3\n", "3 3\n5 3 2\n1 2\n2 3\n1 3\n" ], "output": [ "33\n", "25\n" ] }
{ "input": [ "31 48\n45 19 16 42 38 18 50 7 28 40 39 25 45 14 36 18 27 30 16 4 22 6 1 23 16 47 14 35 27 47 2\n6 16\n11 28\n4 30\n25 26\n11 30\n5 9\n4 17\n15 17\n10 25\n15 26\n1 3\n9 26\n8 29\n16 30\n5 24\n27 30\n9 10\n22 29\n2 6\n15 24\n6 21\n19 21\n4 28\n1 7\n18 21\n10 22\n6 15\n14 28\n4 29\n12 13\n19 29\n5 6\n1...
1,500
1,500
2
9
322_C. Ciel and Robot
Fox Ciel has a robot on a 2D plane. Initially it is located in (0, 0). Fox Ciel code a command to it. The command was represented by string s. Each character of s is one move operation. There are four move operations at all: * 'U': go up, (x, y) β†’ (x, y+1); * 'D': go down, (x, y) β†’ (x, y-1); * 'L': go left...
{ "input": [ "0 0\nD\n", "-1 1000000000\nLRRLU\n", "2 2\nRU\n", "1 2\nRU\n" ], "output": [ "Yes\n", "Yes\n", "Yes\n", "No\n" ] }
{ "input": [ "999999999 -999999999\nRRRRRRRRRRRRRRRRRRRRRRRRRDDDDDDDDDDDDDDDDDDDDDDDDDLLLLLLLLLLLLLLLLLLLLLLLUUUUUUUUUUUUUUUUUUUUUUU\n", "0 -3\nRDDL\n", "0 0\nUURRDL\n", "100 100\nRUL\n", "1000000000 1000000000\nRURURURURURURURURURURURURURURURURURURURURURURURURURURURURURURURURURURURURURURURURURURU...
1,700
500
2
7
347_A. Difference Row
You want to arrange n integers a1, a2, ..., an in some order in a row. Let's define the value of an arrangement as the sum of differences between all pairs of adjacent integers. More formally, let's denote some arrangement as a sequence of integers x1, x2, ..., xn, where sequence x is a permutation of sequence a. The ...
{ "input": [ "5\n100 -100 50 0 -50\n" ], "output": [ "100 -50 0 50 -100\n" ] }
{ "input": [ "50\n-262 -377 -261 903 547 759 -800 -53 670 92 758 109 547 877 152 -901 -318 -527 -388 24 139 -227 413 -135 811 -886 -22 -526 -643 -431 284 609 -745 -62 323 -441 743 -800 86 862 587 -513 -468 -651 -760 197 141 -414 -909 438\n", "2\n1000 -1000\n", "3\n-1 -1 -1\n", "100\n-790 341 910 905 -...
1,300
500
2
8
370_B. Berland Bingo
Lately, a national version of a bingo game has become very popular in Berland. There are n players playing the game, each player has a card with numbers. The numbers on each card are distinct, but distinct cards can have equal numbers. The card of the i-th player contains mi numbers. During the game the host takes num...
{ "input": [ "2\n1 1\n1 1\n", "3\n1 1\n3 2 4 1\n2 10 11\n" ], "output": [ "NO\nNO\n", "YES\nNO\nYES\n" ] }
{ "input": [ "40\n2 12 19\n4 10 7 1 3\n2 15 17\n1 6\n3 17 8 20\n4 8 16 11 18\n2 2 7\n4 12 13 8 7\n3 6 1 15\n3 19 11 13\n1 2\n2 16 14\n5 1 17 8 9 5\n1 2\n3 15 17 12\n4 20 4 19 18\n1 10\n4 12 1 17 16\n4 5 10 8 11\n1 10\n1 13\n1 17\n2 19 18\n1 3\n2 6 20\n1 8\n2 3 14\n3 17 3 1\n2 4 3\n1 12\n1 15\n1 2\n2 13 9\n2 1 14\...
1,300
500
2
9
441_C. Valera and Tubes
Valera has got a rectangle table consisting of n rows and m columns. Valera numbered the table rows starting from one, from top to bottom and the columns – starting from one, from left to right. We will represent cell that is on the intersection of row x and column y by a pair of integers (x, y). Valera wants to place...
{ "input": [ "3 3 3\n", "2 3 1\n" ], "output": [ "2 1 1 1 2\n2 1 3 2 3\n5 2 2 2 1 3 1 3 2 3 3\n", "6 1 1 1 2 1 3 2 3 2 2 2 1\n" ] }
{ "input": [ "2 4 3\n", "5 5 12\n", "5 5 3\n", "3 3 4\n", "60 136 8\n", "2 3 3\n", "32 27 153\n", "95 4 177\n", "2 298 1\n", "15 68 212\n", "7 5 17\n", "298 2 1\n", "2 2 2\n", "2 15 3\n", "89 82 2330\n", "135 91 4352\n", "74 83 2667\n", "91 183 7...
1,500
1,500
2
10
463_D. Gargari and Permutations
Gargari got bored to play with the bishops and now, after solving the problem about them, he is trying to do math homework. In a math book he have found k permutations. Each of them consists of numbers 1, 2, ..., n in some order. Now he should find the length of the longest common subsequence of these permutations. Can...
{ "input": [ "4 3\n1 4 2 3\n4 1 2 3\n1 2 4 3\n" ], "output": [ "3" ] }
{ "input": [ "6 3\n2 5 1 4 6 3\n5 1 4 6 2 3\n5 4 2 6 3 1\n", "6 3\n2 5 1 4 6 3\n5 1 4 3 2 6\n5 4 2 6 3 1\n", "41 4\n24 15 17 35 13 41 4 14 23 5 8 16 21 18 30 36 6 22 11 29 26 1 40 31 7 3 32 10 28 38 12 20 39 37 34 19 33 27 2 25 9\n22 13 25 24 38 35 29 12 15 8 11 37 3 19 4 23 18 32 30 40 36 21 16 34 27 9 5...
1,900
2,000
2
9
487_C. Prefix Product Sequence
Consider a sequence [a1, a2, ... , an]. Define its prefix product sequence <image>. Now given n, find a permutation of [1, 2, ..., n], such that its prefix product sequence is a permutation of [0, 1, ..., n - 1]. Input The only input line contains an integer n (1 ≀ n ≀ 105). Output In the first output line, print ...
{ "input": [ "6\n", "7\n" ], "output": [ "NO\n", "YES\n1\n2\n5\n6\n3\n4\n7\n" ] }
{ "input": [ "2\n", "1\n", "16553\n", "6577\n", "55004\n", "18047\n", "5\n", "4\n", "1941\n", "7137\n", "7\n", "8677\n", "2647\n", "3\n", "19333\n", "31513\n", "10529\n", "21341\n" ], "output": [ "YES\n1\n2\n", "YES\n1\n", "YES\n1...
2,300
1,500
2
8
510_B. Fox And Two Dots
Fox Ciel is playing a mobile puzzle game called "Two Dots". The basic levels are played on a board of size n Γ— m cells, like this: <image> Each cell contains a dot that has some color. We will use different uppercase Latin characters to express different colors. The key of this game is to find a cycle that contain d...
{ "input": [ "2 13\nABCDEFGHIJKLM\nNOPQRSTUVWXYZ\n", "7 6\nAAAAAB\nABBBAB\nABAAAB\nABABBB\nABAAAB\nABBBAB\nAAAAAB\n", "3 4\nAAAA\nABCA\nAAAA\n", "3 4\nAAAA\nABCA\nAADA\n", "4 4\nYYYR\nBYBY\nBBBY\nBBBY\n" ], "output": [ "No\n", "Yes\n", "Yes\n", "No\n", "Yes\n" ] }
{ "input": [ "10 10\nHIICQRHPUJ\nBCDUKHMBFK\nPFTUIDOBOE\nQQPITLRKUP\nERMUJMOSMF\nMRSICEILQB\nODIGFNCHFR\nGHIOAFLHJH\nFBLAQNGEIF\nFDLEGDUTNG\n", "2 2\nAA\nAB\n", "2 50\nDADCDBCCDAACDBCAACADBCBDBACCCCDADCBACADBCCBDBCCBCC\nDADAADCABBBACCDDBABBBDCBACBCCCCDDADCDABADDDCABACDB\n", "50 2\nAA\nCD\nEE\nFC\nED\n...
1,500
1,000
2
9
535_C. Tavas and Karafs
Karafs is some kind of vegetable in shape of an 1 Γ— h rectangle. Tavaspolis people love Karafs and they use Karafs in almost any kind of food. Tavas, himself, is crazy about Karafs. <image> Each Karafs has a positive integer height. Tavas has an infinite 1-based sequence of Karafses. The height of the i-th Karafs is ...
{ "input": [ "1 5 2\n1 5 10\n2 7 4\n", "2 1 4\n1 5 3\n3 3 10\n7 10 2\n6 4 8\n" ], "output": [ "1\n2\n", "4\n-1\n8\n-1\n" ] }
{ "input": [ "1 1 1\n1 1000000 1000000\n", "447 74474 4\n47 777474 747\n74 744744 74477\n477 477447 777\n7 477777 444444\n", "1000000 1000000 1\n1000000 1000000 1000000\n", "1 1 4\n1 1000000 1000000\n1 1 1000000\n1 1000000 1\n1 1 1\n", "1 5000 1\n1 1000000 1000000\n", "1 1000000 1\n1 1000000 1...
1,900
1,500
2
7
586_A. Alena's Schedule
Alena has successfully passed the entrance exams to the university and is now looking forward to start studying. One two-hour lesson at the Russian university is traditionally called a pair, it lasts for two academic hours (an academic hour is equal to 45 minutes). The University works in such a way that every day it...
{ "input": [ "5\n0 1 0 1 1\n", "7\n1 0 1 0 0 1 0\n", "1\n0\n" ], "output": [ "4\n", "4\n", "0\n" ] }
{ "input": [ "95\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n", "44\n0 1 1 1 1 0 1 0 0 1 0 1 0 0 1 1 0 1 1 0 0 1 0 1 0 1 1 0 1 0 1 0 1 0 1 0 0 0 0 0 1 0 1 1\n", ...
900
500
2
8
608_B. Hamming Distance Sum
Genos needs your help. He was asked to solve the following programming problem by Saitama: The length of some string s is denoted |s|. The Hamming distance between two strings s and t of equal length is defined as <image>, where si is the i-th character of s and ti is the i-th character of t. For example, the Hamming ...
{ "input": [ "01\n00111\n", "0011\n0110\n" ], "output": [ "3\n", "2\n" ] }
{ "input": [ "1001101001101110101101000\n01111000010011111111110010001101000100011110101111\n", "1\n0\n", "0\n1\n", "0\n0\n", "1\n1\n", "1110010001000101001011111\n00011011000000100001010000010100110011010001111010\n" ], "output": [ "321\n", "1\n", "1\n", "0\n", "0\n", ...
1,500
1,000
2
7
62_A. A Student's Dream
Statistics claims that students sleep no more than three hours a day. But even in the world of their dreams, while they are snoring peacefully, the sense of impending doom is still upon them. A poor student is dreaming that he is sitting the mathematical analysis exam. And he is examined by the most formidable profess...
{ "input": [ "4 5\n3 3\n", "5 1\n10 5\n", "1 2\n11 6\n" ], "output": [ "YES\n", "YES\n", "NO\n" ] }
{ "input": [ "100 100\n50 50\n", "13 23\n19 63\n", "5 23\n12 17\n", "65 8\n73 25\n", "100 3\n4 1\n", "2 25\n8 24\n", "19 17\n5 8\n", "24 43\n96 39\n", "11 17\n6 4\n", "25 9\n16 12\n", "58 86\n40 46\n", "100 1\n4 1\n", "82 60\n100 38\n", "9 21\n13 16\n", "6 1...
1,300
500
2
7
724_A. Checking the Calendar
You are given names of two days of the week. Please, determine whether it is possible that during some non-leap year the first day of some month was equal to the first day of the week you are given, while the first day of the next month was equal to the second day of the week you are given. Both months should belong t...
{ "input": [ "monday\ntuesday\n", "saturday\ntuesday\n", "sunday\nsunday\n" ], "output": [ "NO\n", "YES\n", "YES\n" ] }
{ "input": [ "friday\ntuesday\n", "thursday\nmonday\n", "tuesday\nsunday\n", "thursday\nsaturday\n", "saturday\nfriday\n", "thursday\nsunday\n", "monday\nsaturday\n", "saturday\nsunday\n", "saturday\nsaturday\n", "sunday\nfriday\n", "monday\nthursday\n", "thursday\nthur...
1,000
500
2
7
746_A. Compote
Nikolay has a lemons, b apples and c pears. He decided to cook a compote. According to the recipe the fruits should be in the ratio 1: 2: 4. It means that for each lemon in the compote should be exactly 2 apples and exactly 4 pears. You can't crumble up, break up or cut these fruits into pieces. These fruits β€” lemons, ...
{ "input": [ "2\n5\n7\n", "4\n7\n13\n", "2\n3\n2\n" ], "output": [ "7", "21", "0" ] }
{ "input": [ "1000\n500\n1000\n", "1\n1000\n1000\n", "1000\n2\n1000\n", "15\n313\n525\n", "204\n412\n824\n", "1000\n1000\n3\n", "1000\n1000\n4\n", "5\n4\n16\n", "127\n256\n512\n", "1\n2\n999\n", "22\n481\n633\n", "1\n1\n4\n", "200\n399\n800\n", "201\n400\n800\n"...
800
500
2
7
769_A. Year of University Entrance
There is the faculty of Computer Science in Berland. In the social net "TheContact!" for each course of this faculty there is the special group whose name equals the year of university entrance of corresponding course of students at the university. Each of students joins the group of his course and joins all groups f...
{ "input": [ "1\n2050\n", "3\n2014 2016 2015\n" ], "output": [ "2050\n", "2015\n" ] }
{ "input": [ "5\n2099 2096 2095 2097 2098\n", "3\n2011 2010 2012\n", "5\n2097 2099 2100 2098 2096\n", "5\n2011 2014 2013 2010 2012\n", "5\n2021 2023 2024 2020 2022\n", "5\n2011 2014 2012 2013 2010\n", "5\n2043 2042 2041 2044 2040\n", "3\n2012 2011 2010\n", "3\n2012 2010 2011\n", ...
800
500
2
7
793_A. Oleg and shares
Oleg the bank client checks share prices every day. There are n share prices he is interested in. Today he observed that each second exactly one of these prices decreases by k rubles (note that each second exactly one price changes, but at different seconds different prices can change). Prices can become negative. Oleg...
{ "input": [ "2 2\n10 9\n", "3 3\n12 9 15\n", "4 1\n1 1000000000 1000000000 1000000000\n" ], "output": [ "-1\n", "3\n", "2999999997\n" ] }
{ "input": [ "3 3\n1 3 5\n", "10 2\n2 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000\n", "2 1\n2 3\n", "3 5\n2 4 5\n", "4 4\n1 5 8 14\n", "2 6\n8 16\n", "3 3\n1 3 4\n", "4 3\n2 2 5 1\n", "3 3\n7 8 8\n", "3 5\n6 11 17\n", "...
900
500
2
10
813_D. Two Melodies
Alice is a beginner composer and now she is ready to create another masterpiece. And not even the single one but two at the same time! Alice has a sheet with n notes written on it. She wants to take two such non-empty non-intersecting subsequences that both of them form a melody and sum of their lengths is maximal. ...
{ "input": [ "6\n62 22 60 61 48 49\n", "4\n1 2 4 5\n" ], "output": [ "5\n", "4\n" ] }
{ "input": [ "10\n7776 32915 1030 71664 7542 72359 65387 75222 95899 40333\n", "6\n7 20 21 22 23 28\n", "2\n1 4\n", "10\n9 6 8 5 5 2 8 9 2 2\n", "10\n1 1 1 1 1 1 1 1 1 1\n", "6\n3 12 4 12 5 6\n", "2\n5 4\n", "3\n1 36 6\n", "4\n15 11 28 17\n" ], "output": [ "6\n", "6\n",...
2,600
0
2
9
839_C. Journey
There are n cities and n - 1 roads in the Seven Kingdoms, each road connects two cities and we can reach any city from any other by the roads. Theon and Yara Greyjoy are on a horse in the first city, they are starting traveling through the roads. But the weather is foggy, so they can’t see where the horse brings them....
{ "input": [ "5\n1 2\n1 3\n3 4\n2 5\n", "4\n1 2\n1 3\n2 4\n" ], "output": [ "2.000000\n", "1.500000\n" ] }
{ "input": [ "1\n", "10\n8 6\n9 10\n8 7\n1 4\n1 8\n9 5\n9 8\n2 5\n3 1\n", "70\n1 25\n57 1\n18 1\n65 1\n38 1\n1 41\n1 5\n1 69\n1 3\n31 1\n1 8\n1 9\n53 1\n70 1\n45 1\n1 24\n1 42\n1 30\n1 12\n1 37\n64 1\n1 28\n1 58\n1 22\n11 1\n1 4\n1 27\n1 16\n1 21\n54 1\n1 51\n1 43\n29 1\n56 1\n1 39\n32 1\n1 15\n1 17\n1 19...
1,500
1,500
2
13
908_G. New Year and Original Order
Let S(n) denote the number that represents the digits of n in sorted order. For example, S(1) = 1, S(5) = 5, S(50394) = 3459, S(353535) = 333555. Given a number X, compute <image> modulo 109 + 7. Input The first line of input will contain the integer X (1 ≀ X ≀ 10700). Output Print a single integer, the answer to ...
{ "input": [ "345342\n", "21\n" ], "output": [ "390548434", "195" ] }
{ "input": [ "33340691714056185860211260984431382156326935244157\n", "446490140549710812136081378174660462546524926277418604782585582063971131982328238598703638210071884764059516110693472996891702400239790481987117450115427742681790553110130540730751761227556434833802489996576492114599977662210723991035799774...
2,800
2,750
2
7
930_A. Peculiar apple-tree
In Arcady's garden there grows a peculiar apple-tree that fruits one time per year. Its peculiarity can be explained in following way: there are n inflorescences, numbered from 1 to n. Inflorescence number 1 is situated near base of tree and any other inflorescence with number i (i > 1) is situated at the top of branch...
{ "input": [ "18\n1 1 1 4 4 3 2 2 2 10 8 9 9 9 10 10 4\n", "3\n1 1\n", "5\n1 2 2 2\n" ], "output": [ "4\n", "1\n", "3\n" ] }
{ "input": [ "3\n1 2\n", "20\n1 2 2 4 3 5 5 6 6 9 11 9 9 12 13 10 15 13 15\n", "30\n1 1 1 1 3 3 2 3 7 4 1 2 4 6 2 8 1 2 13 7 5 15 3 3 8 4 4 18 3\n", "10\n1 2 3 4 5 5 5 7 9\n", "40\n1 1 1 2 1 2 1 2 4 8 1 7 1 6 2 8 2 12 4 11 5 5 15 3 12 11 22 11 13 13 24 6 10 15 3 6 7 1 2\n", "50\n1 2 2 4 5 5 7 ...
1,500
500
2
7
984_A. Game
Two players play a game. Initially there are n integers a_1, a_2, …, a_n written on the board. Each turn a player selects one number and erases it from the board. This continues until there is only one number left on the board, i. e. n - 1 turns are made. The first player makes the first move, then players alternate t...
{ "input": [ "3\n2 2 2\n", "3\n2 1 3\n" ], "output": [ "2\n", "2\n" ] }
{ "input": [ "10\n38 82 23 37 96 4 81 60 67 86\n", "9\n44 53 51 80 5 27 74 79 94\n", "3\n9 92 12\n", "3\n1 2 2\n", "2\n322 322\n", "10\n58 26 77 15 53 81 68 48 22 65\n", "1\n124\n", "3\n1 1 1000\n", "2\n2 1\n" ], "output": [ "60\n", "53\n", "12\n", "2\n", "3...
800
500
2
8
1045_B. Space Isaac
Everybody seems to think that the Martians are green, but it turns out they are metallic pink and fat. Ajs has two bags of distinct nonnegative integers. The bags are disjoint, and the union of the sets of numbers in the bags is \{0,1,…,M-1\}, for some positive integer M. Ajs draws a number from the first bag and a num...
{ "input": [ "4 1000000000\n5 25 125 625\n", "2 4\n1 3\n", "2 5\n3 4\n" ], "output": [ "0\n", "2\n0 2 \n", "1\n2 \n" ] }
{ "input": [ "4 20\n5 6 7 16\n", "9 10\n1 2 3 4 5 6 7 8 9\n", "3 100000011\n678 500678 1000678\n", "14 34\n1 2 4 7 10 12 13 18 19 21 24 27 29 30\n", "36 81\n4 5 7 8 13 14 16 17 22 23 25 26 31 32 34 35 40 41 43 44 49 50 52 53 58 59 61 62 67 68 70 71 76 77 79 80\n", "1 2\n1\n" ], "output": [...
2,400
0
2
8
1068_B. LCM
Ivan has number b. He is sorting through the numbers a from 1 to 10^{18}, and for every a writes ([a, b])/(a) on blackboard. Here [a, b] stands for least common multiple of a and b. Ivan is very lazy, that's why this task bored him soon. But he is interested in how many different numbers he would write on the boa...
{ "input": [ "1\n", "2\n" ], "output": [ "1\n", "2\n" ] }
{ "input": [ "244078129\n", "2793510720\n", "16\n", "179\n", "1048576\n", "5\n", "1102701600\n", "4324320\n", "2000000014\n", "8872504640\n", "963837006\n", "8\n", "2327925600\n", "58697100\n", "51\n", "2095133040\n", "196729490\n", "6508183\n", ...
1,200
1,250
2
7
1139_A. Even Substrings
You are given a string s=s_1s_2... s_n of length n, which only contains digits 1, 2, ..., 9. A substring s[l ... r] of s is a string s_l s_{l + 1} s_{l + 2} … s_r. A substring s[l ... r] of s is called even if the number represented by it is even. Find the number of even substrings of s. Note, that even if some subs...
{ "input": [ "4\n1234\n", "4\n2244\n" ], "output": [ "6\n", "10\n" ] }
{ "input": [ "3\n112\n", "3\n121\n", "3\n122\n", "39\n263254663359864483324578786753512345165\n", "3\n211\n", "3\n111\n", "2\n81\n", "3\n222\n", "3\n212\n", "2\n13\n", "10\n9572683145\n", "1\n3\n", "3\n221\n", "2\n18\n", "2\n68\n", "1\n6\n" ], "outpu...
800
500
2
8
1157_B. Long Number
You are given a long decimal number a consisting of n digits from 1 to 9. You also have a function f that maps every digit from 1 to 9 to some (possibly the same) digit from 1 to 9. You can perform the following operation no more than once: choose a non-empty contiguous subsegment of digits in a, and replace each digi...
{ "input": [ "2\n33\n1 1 1 1 1 1 1 1 1\n", "4\n1337\n1 2 5 4 6 6 3 1 9\n", "5\n11111\n9 8 7 6 5 4 3 2 1\n" ], "output": [ "33", "1557", "99999" ] }
{ "input": [ "18\n263583239493593927\n7 7 3 7 7 6 9 7 6\n", "3\n649\n1 5 2 9 7 8 8 3 1\n", "3\n985\n3 5 3 8 8 6 4 4 3\n", "19\n2612437771227631192\n6 7 3 6 8 7 9 9 9\n", "1\n3\n2 8 4 5 4 1 7 2 3\n", "1\n6\n4 8 2 6 8 8 8 8 3\n", "3\n931\n4 7 8 6 2 4 3 1 2\n", "4\n1234\n1 1 4 5 1 1 1 1 1...
1,300
0
2
11
1197_E. Culture Code
There are famous Russian nesting dolls named matryoshkas sold in one of the souvenir stores nearby, and you'd like to buy several of them. The store has n different matryoshkas. Any matryoshka is a figure of volume out_i with an empty space inside of volume in_i (of course, out_i > in_i). You don't have much free spac...
{ "input": [ "7\n4 1\n4 2\n4 2\n2 1\n5 4\n6 4\n3 2\n" ], "output": [ "6" ] }
{ "input": [ "1\n1000000000 999999999\n", "4\n3 2\n10 2\n4 3\n5 4\n", "10\n7 6\n15 14\n6 5\n8 7\n9 8\n17 16\n9 8\n2 1\n3 2\n5 4\n", "10\n19 17\n14 11\n16 15\n19 18\n12 9\n5 3\n18 16\n13 12\n13 11\n3 2\n", "10\n12 11\n14 13\n17 16\n3 2\n13 12\n4 3\n16 15\n16 15\n10 9\n12 11\n", "20\n41 31\n51 4...
2,300
0
2
14
1237_H. Balanced Reversals
You have two strings a and b of equal even length n consisting of characters 0 and 1. We're in the endgame now. To finally make the universe perfectly balanced, you need to make strings a and b equal. In one step, you can choose any prefix of a of even length and reverse it. Formally, if a = a_1 a_2 … a_n, you can ch...
{ "input": [ "4\n0100011011\n1101011000\n10101010\n10101010\n0011\n1001\n100011\n110010\n" ], "output": [ "11\n2 2 4 4 6 4 6 6 8 8 10 \n8\n8 2 2 4 4 6 6 8 \n-1\n6\n2 2 2 4 4 6 \n" ] }
{ "input": [ "4\n0100011011\n1101011000\n10101010\n10101010\n0011\n1001\n100011\n110010\n" ], "output": [ "11\n2 2 4 4 6 4 6 6 8 8 10 \n8\n8 2 2 4 4 6 6 8 \n-1\n6\n2 2 2 4 4 6 \n" ] }
3,300
4,000
2
7
1256_A. Payment Without Change
You have a coins of value n and b coins of value 1. You always pay in exact change, so you want to know if there exist such x and y that if you take x (0 ≀ x ≀ a) coins of value n and y (0 ≀ y ≀ b) coins of value 1, then the total value of taken coins will be S. You have to answer q independent test cases. Input The...
{ "input": [ "4\n1 2 3 4\n1 2 3 6\n5 2 6 27\n3 3 5 18\n" ], "output": [ "YES\nNO\nNO\nYES\n" ] }
{ "input": [ "1\n16 2 3 55\n", "1\n87 63 54 9\n", "6\n1 1000000000 1 1000000000\n1 1000000000 1 1000000000\n1 1000000000 1 1000000000\n1 1000000000 1 1000000000\n1 1000000000 1 1000000000\n1 1000000000 1 1000000000\n", "1\n2104 2104 1 2104\n", "1\n500 1000 600 131\n", "1\n2104 2104 2104 2104\n...
1,000
0
2
7
127_A. Wasted Time
Mr. Scrooge, a very busy man, decided to count the time he wastes on all sorts of useless stuff to evaluate the lost profit. He has already counted the time he wastes sleeping and eating. And now Mr. Scrooge wants to count the time he has wasted signing papers. Mr. Scrooge's signature can be represented as a polyline ...
{ "input": [ "2 1\n0 0\n10 0\n", "6 10\n5 0\n4 0\n6 0\n3 0\n7 0\n2 0\n", "5 10\n3 1\n-5 6\n-2 -1\n3 2\n10 0\n" ], "output": [ "0.200000000\n", "3.000000000\n", "6.032163204\n" ] }
{ "input": [ "48 447\n14 9\n9 -17\n-17 11\n-14 14\n19 -8\n-14 -17\n-7 10\n-6 -11\n-9 -19\n19 10\n-4 2\n-5 16\n20 9\n-10 20\n-7 -17\n14 -16\n-2 -10\n-18 -17\n14 12\n-6 -19\n5 -18\n-3 2\n-3 10\n-5 5\n13 -12\n10 -18\n10 -12\n-2 4\n7 -15\n-5 -5\n11 14\n11 10\n-6 -9\n13 -4\n13 9\n6 12\n-13 17\n-9 -12\n14 -19\n10 12\n-...
900
500
2
8
1323_B. Count Subrectangles
You are given an array a of length n and array b of length m both consisting of only integers 0 and 1. Consider a matrix c of size n Γ— m formed by following rule: c_{i, j} = a_i β‹… b_j (i.e. a_i multiplied by b_j). It's easy to see that c consists of only zeroes and ones too. How many subrectangles of size (area) k con...
{ "input": [ "3 5 4\n1 1 1\n1 1 1 1 1\n", "3 3 2\n1 0 1\n1 1 1\n" ], "output": [ "14\n", "4\n" ] }
{ "input": [ "50 50 6\n1 0 0 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 0 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 1 0 1 1 1 0 1\n1 1 0 1 0 1 1 0 1 1 1 1 1 1 0 1 1 0 1 0 0 1 1 1 1 0 0 1 0 1 1 1 0 1 1 1 1 1 1 1 1 1 1 0 1 1 1 1 1 0\n", "1 1 1\n1\n1\n" ], "output": [ "2153\n", "1\n" ] }
1,500
1,000
2
7
1342_A. Road To Zero
You are given two integers x and y. You can perform two types of operations: 1. Pay a dollars and increase or decrease any of these integers by 1. For example, if x = 0 and y = 7 there are four possible outcomes after this operation: * x = 0, y = 6; * x = 0, y = 8; * x = -1, y = 7; * x = 1, y = ...
{ "input": [ "2\n1 3\n391 555\n0 0\n9 4\n" ], "output": [ "1337\n0\n" ] }
{ "input": [ "1\n129 8437\n5 3\n", "3\n1 3\n391 555\n129 8437\n9 4\n321 654\n3 4\n", "2\n1 3\n391 555\n129 8437\n9 4\n", "1\n321 654\n3 4\n", "1\n150 140\n1 1\n" ], "output": [ "41927\n", "1337\n75288\n2283\n", "1337\n75288\n", "2283\n", "150\n" ] }
1,000
0
2
7
1364_A. XXXXX
Ehab loves number theory, but for some reason he hates the number x. Given an array a, find the length of its longest subarray such that the sum of its elements isn't divisible by x, or determine that such subarray doesn't exist. An array a is a subarray of an array b if a can be obtained from b by deletion of several...
{ "input": [ "3\n3 3\n1 2 3\n3 4\n1 2 3\n2 2\n0 6\n" ], "output": [ "2\n3\n-1\n" ] }
{ "input": [ "2\n2\n1 1\n1\n1\n", "2\n4\n1 3 3 3\n3\n1 2 3\n", "1\n5\n1 3 4 5 2\n", "2\n5\n1 2 3 4 5\n4\n2 3 4 5\n", "2\n3\n3 2 1\n6\n3 1 4 1 5 9\n", "1\n3\n1 1 274005660\n", "2\n5\n5 5 5 5 5\n3\n1 2 5\n", "4\n7\n6 6 8 8 6 6 6\n1\n2\n5\n4 5 9 8 7\n7\n1 2 7 1 6 10 2\n", "2\n3\n1 1 1...
1,200
750
2
8
1384_B2. Koa and the Beach (Hard Version)
The only difference between easy and hard versions is on constraints. In this version constraints are higher. You can make hacks only if all versions of the problem are solved. Koa the Koala is at the beach! The beach consists (from left to right) of a shore, n+1 meters of sea and an island at n+1 meters from the sho...
{ "input": [ "7\n2 1 1\n1 0\n5 2 3\n1 2 3 2 2\n4 3 4\n0 2 4 3\n2 3 5\n3 0\n7 2 3\n3 0 2 1 3 0 1\n7 1 4\n4 4 3 0 2 4 2\n5 2 3\n1 2 3 2 2\n" ], "output": [ "Yes\nNo\nYes\nYes\nYes\nNo\nNo\n" ] }
{ "input": [ "10\n1 1 1\n1\n1 1 1\n0\n1 1 1\n2\n1 1 1\n3\n1 1 1\n4\n2 2 2\n2 3\n2 1 2\n1 1\n2 1 2\n0 0\n14 3 9\n1 3 2 3 3 2 4 2 1 3 6 7 10 1\n7 1 1\n1 1 1 1 1 1 1\n", "1\n100 5 4\n0 0 0 0 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 4 4 4 4 4 4 2 2 2 2 2 2 2 2 ...
2,200
750
2
10
1405_D. Tree Tag
Alice and Bob are playing a fun game of tree tag. The game is played on a tree of n vertices numbered from 1 to n. Recall that a tree on n vertices is an undirected, connected graph with n-1 edges. Initially, Alice is located at vertex a, and Bob at vertex b. They take turns alternately, and Alice makes the first mov...
{ "input": [ "4\n4 3 2 1 2\n1 2\n1 3\n1 4\n6 6 1 2 5\n1 2\n6 5\n2 3\n3 4\n4 5\n9 3 9 2 5\n1 2\n1 6\n1 9\n1 3\n9 5\n7 9\n4 8\n4 3\n11 8 11 3 3\n1 2\n11 9\n4 9\n6 5\n2 10\n3 2\n5 9\n8 3\n7 4\n7 10\n" ], "output": [ "Alice\nBob\nAlice\nAlice\n" ] }
{ "input": [ "1\n5 5 4 3 4\n1 2\n4 1\n5 1\n5 3\n", "1\n9 1 5 3 7\n1 2\n2 3\n3 4\n4 5\n3 6\n7 8\n8 9\n6 7\n", "10\n10 9 10 6 6\n6 1\n7 6\n4 2\n4 10\n5 1\n9 5\n6 8\n3 4\n4 5\n2 1 2 1 1\n2 1\n9 7 4 2 3\n5 1\n2 4\n4 8\n8 6\n8 9\n7 8\n1 8\n1 3\n11 2 11 6 8\n1 10\n6 11\n8 2\n11 3\n1 7\n11 4\n5 8\n11 7\n1 9\n1 8...
1,900
1,000
2
12
1426_F. Number of Subsequences
You are given a string s consisting of lowercase Latin letters "a", "b" and "c" and question marks "?". Let the number of question marks in the string s be k. Let's replace each question mark with one of the letters "a", "b" and "c". Here we can obtain all 3^{k} possible strings consisting only of letters "a", "b" and...
{ "input": [ "9\ncccbbbaaa\n", "7\n???????\n", "5\na???c\n", "6\nac?b?c\n" ], "output": [ "0\n", "2835\n", "46\n", "24\n" ] }
{ "input": [ "3\nabc\n", "200\n???c????????ba?????c?b???c???a??a?b??bb?c???cccc?ac?????c??????b??c?aa?cb?ca?a??cc?b???a?c???c??bbb?cacbbac?ccc?a?aca??b??a??c?c?a??????b??a????baa?a?a?????a????bb??b?????ac?b?aacb??c????????a?c??????\n", "100\naccbaccabccbbbbabacabaaccacbcbcababbbcbcbcccabcbbc?caaabcabcaacc...
2,000
0
2
11
1473_E. Minimum Path
You are given a weighted undirected connected graph consisting of n vertices and m edges. It is guaranteed that there are no self-loops or multiple edges in the given graph. Let's define the weight of the path consisting of k edges with indices e_1, e_2, ..., e_k as βˆ‘_{i=1}^{k}{w_{e_i}} - max_{i=1}^{k}{w_{e_i}} + min_...
{ "input": [ "7 10\n7 5 5\n2 3 3\n4 7 1\n5 3 6\n2 7 6\n6 2 6\n3 7 6\n4 2 1\n3 1 4\n1 7 4\n", "5 4\n5 3 4\n2 1 1\n3 2 2\n2 4 2\n", "6 8\n3 1 1\n3 6 2\n5 4 2\n4 2 2\n6 1 1\n5 2 1\n3 2 3\n1 5 4\n" ], "output": [ "\n3 4 2 7 7 3 \n", "\n1 2 2 4 \n", "\n2 1 4 3 1 \n" ] }
{ "input": [ "13 37\n3 9 6\n8 7 1\n7 4 10\n10 2 8\n13 1 8\n9 8 1\n8 1 1\n5 1 8\n4 13 5\n5 12 1\n2 9 8\n3 8 5\n1 10 10\n11 12 3\n11 8 3\n11 4 10\n7 1 2\n3 1 3\n10 13 10\n6 8 6\n8 5 1\n6 12 7\n5 7 4\n10 12 1\n9 7 6\n2 1 9\n7 11 2\n8 13 2\n5 13 9\n3 11 6\n10 9 10\n3 7 5\n12 4 3\n11 10 4\n1 11 2\n2 5 4\n3 12 4\n", ...
2,400
0
2
11
1521_E. Nastia and a Beautiful Matrix
You like numbers, don't you? Nastia has a lot of numbers and she wants to share them with you! Isn't it amazing? Let a_i be how many numbers i (1 ≀ i ≀ k) you have. An n Γ— n matrix is called beautiful if it contains all the numbers you have, and for each 2 Γ— 2 submatrix of the original matrix is satisfied: 1. The...
{ "input": [ "2\n3 4\n2 0 0 1\n15 4\n2 4 8 1\n" ], "output": [ "\n2\n4 1\n0 1\n5\n3 0 0 2 2\n3 2 3 3 0\n0 1 0 4 0\n3 0 0 0 0\n2 1 3 3 3" ] }
{ "input": [ "1\n9 3\n1 0 8\n", "1\n12 3\n9 2 1\n", "2\n3 4\n2 0 0 1\n15 4\n2 4 8 1\n" ], "output": [ "4\n3 3 3 3 \n0 0 0 0 \n3 3 3 3 \n0 0 1 0 \n", "5\n0 1 0 1 0 \n0 0 0 0 0 \n0 1 0 1 0 \n3 0 2 0 2 \n1 1 1 1 1 \n", "2\n1 1 \n4 0 \n5\n0 3 0 3 0 \n1 0 1 0 2 \n0 3 0 3 0 \n2 0 2 0 2 \n4 3 3 3...
2,700
2,750
2
11
1550_E. Stringforces
You are given a string s of length n. Each character is either one of the first k lowercase Latin letters or a question mark. You are asked to replace every question mark with one of the first k lowercase Latin letters in such a way that the following value is maximized. Let f_i be the maximum length substring of str...
{ "input": [ "2 3\n??\n", "10 2\na??ab????b\n", "9 4\n?????????\n", "4 4\ncabd\n", "15 3\n??b?babbc??b?aa\n" ], "output": [ "0\n", "4\n", "2\n", "1\n", "3\n" ] }
{ "input": [ "8 2\naa??ba??\n", "466 10\nhga??dfdgae??j?f???h?jdd?????dhgc???????bj?j????b?be?b?jedd??g?cg????bj?b?h?heg?cb?e??hgf???fcd?g??hf?a????ie???if?deibf?j?g??cea?????????f?i?geh??h??gb?c?a?a?iei???caa?cieehd?b????cf??ei????ebjb?gijcf??fg?eg?agjba?eb????hh????aa??d????gg?e?b?g?bba???d??ea??b??c????bab...
2,500
0
2
8
177_B1. Rectangular Game
The Smart Beaver from ABBYY decided to have a day off. But doing nothing the whole day turned out to be too boring, and he decided to play a game with pebbles. Initially, the Beaver has n pebbles. He arranges them in a equal rows, each row has b pebbles (a > 1). Note that the Beaver must use all the pebbles he has, i. ...
{ "input": [ "10\n", "8\n" ], "output": [ "16\n", "15\n" ] }
{ "input": [ "999161856\n", "999999937\n", "9\n", "999936000\n", "18\n", "33\n", "999999948\n", "13\n", "14\n", "5\n", "48\n", "50\n", "1000\n", "999999000\n", "39\n", "999989760\n", "998244352\n", "1011\n", "222953472\n", "35\n", "49...
1,000
30
2
7
221_A. Little Elephant and Function
The Little Elephant enjoys recursive functions. This time he enjoys the sorting function. Let a is a permutation of an integers from 1 to n, inclusive, and ai denotes the i-th element of the permutation. The Little Elephant's recursive function f(x), that sorts the first x permutation's elements, works as follows: ...
{ "input": [ "1\n", "2\n" ], "output": [ "1\n", "2 1\n" ] }
{ "input": [ "1000\n", "683\n", "998\n", "195\n", "811\n", "419\n", "6\n", "67\n", "875\n", "25\n", "999\n", "101\n", "7\n", "971\n", "683\n", "875\n", "4\n", "5\n", "971\n", "291\n", "101\n", "24\n", "998\n", "779\n", ...
1,000
500
2
8
245_B. Internet Address
Vasya is an active Internet user. One day he came across an Internet resource he liked, so he wrote its address in the notebook. We know that the address of the written resource has format: <protocol>://<domain>.ru[/<context>] where: * <protocol> can equal either "http" (without the quotes) or "ftp" (without the q...
{ "input": [ "httpsunrux\n", "ftphttprururu\n" ], "output": [ "http://sun.ru/x\n", "ftp://http.ru/ruru\n" ] }
{ "input": [ "httpuurrruurruuruuruuurrrurururuurruuuuuuruurr\n", "httpfttpftpfttftpftpftppfrurururu\n", "ftptpruuhttpuhttphuhtuhtrurrutphttuhtuht\n", "ftprftprupruftptprurururftprrftpftprurftprrftprup\n", "httpftphttptphttphrururuhpftphtpftphtpftphtptpft\n", "httpaaaaaaarurururu\n", "ftppr...
1,100
0
2
11
26_E. Multithreading
You are given the following concurrent program. There are N processes and the i-th process has the following pseudocode: repeat ni times yi := y y := yi + 1 end repeat Here y is a shared variable. Everything else is local for the process. All actions on a given row are a...
{ "input": [ "1 10\n11\n", "2 3\n4 4\n", "3 6\n1 2 3\n" ], "output": [ "No\n", "Yes\n1 2 2 2 2 2 2 1 2 1 1 1 1 2 1 1\n", "Yes\n1 1 2 2 2 2 3 3 3 3 3 3\n" ] }
{ "input": [ "5 1\n2 3 4 5 6\n", "95 -200797120\n832 159 171 230 750 361 800 516 567 380 405 527 58 86 68 172 923 920 248 854 804 557 246 61 106 190 67 552 310 645 120 154 244 308 355 832 432 314 824 774 988 513 228 361 390 863 586 732 798 630 798 210 894 978 686 668 674 103 793 600 110 493 775 327 487 441 91...
2,400
2,500
2
11
340_E. Iahub and Permutations
Iahub is so happy about inventing bubble sort graphs that he's staying all day long at the office and writing permutations. Iahubina is angry that she is no more important for Iahub. When Iahub goes away, Iahubina comes to his office and sabotage his research work. The girl finds an important permutation for the resea...
{ "input": [ "5\n-1 -1 4 3 -1\n" ], "output": [ "2\n" ] }
{ "input": [ "6\n-1 -1 -1 -1 -1 -1\n", "7\n-1 -1 4 -1 7 1 6\n", "10\n4 10 -1 1 6 8 9 2 -1 -1\n", "8\n2 4 5 3 -1 8 -1 6\n", "2\n-1 -1\n", "20\n-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1\n" ], "output": [ "265\n", "4\n", "4\n", "1\n", "1\n", "92779975...
2,000
3,000
2
7
388_A. Fox and Box Accumulation
Fox Ciel has n boxes in her room. They have the same size and weight, but they might have different strength. The i-th box can hold at most xi boxes on its top (we'll call xi the strength of the box). Since all the boxes have the same size, Ciel cannot put more than one box directly on the top of some box. For exampl...
{ "input": [ "9\n0 1 0 2 0 1 1 2 10\n", "5\n0 1 2 3 4\n", "3\n0 0 10\n", "4\n0 0 0 0\n" ], "output": [ "3\n", "1\n", "2\n", "4\n" ] }
{ "input": [ "59\n61 33 84 76 56 47 70 94 46 77 95 85 35 90 83 62 48 74 36 74 83 97 62 92 95 75 70 82 94 67 82 42 78 70 50 73 80 76 94 83 96 80 80 88 91 79 83 54 38 90 33 93 53 33 86 95 48 34 46\n", "18\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n", "5\n4 1 1 1 1\n", "100\n3 4 4 4 3 3 3 3 3 4 4 4 3 3 3 4 3 ...
1,400
500