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
8
1143_B. Nirvana
Kurt reaches nirvana when he finds the product of all the digits of some positive integer. Greater value of the product makes the nirvana deeper. Help Kurt find the maximum possible product of digits among all integers from 1 to n. Input The only input line contains the integer n (1 ≀ n ≀ 2β‹…10^9). Output Print the...
{ "input": [ "7\n", "1000000000\n", "390\n" ], "output": [ "7", "387420489", "216" ] }
{ "input": [ "1\n", "9\n", "10\n", "890133136\n", "11\n", "485908655\n", "282587478\n", "1001\n", "889878787\n", "396579088\n", "791812587\n", "100\n", "25\n", "691993260\n", "389041744\n", "288\n", "268\n", "2000000000\n", "999999999\n", ...
1,200
1,000
2
8
1163_B2. Cat Party (Hard Edition)
This problem is same as the previous one, but has larger constraints. Shiro's just moved to the new house. She wants to invite all friends of her to the house so they can play monopoly. However, her house is too small, so she can only invite one friend at a time. For each of the n days since the day Shiro moved to th...
{ "input": [ "5\n10 100 20 200 1\n", "6\n1 1 1 2 2 2\n", "1\n100000\n", "13\n1 1 1 2 2 2 3 3 3 4 4 4 5\n", "7\n3 2 1 1 4 5 1\n" ], "output": [ "5\n", "5\n", "1\n", "13\n", "6\n" ] }
{ "input": [ "10\n30518 96518 74071 59971 50121 4862 43967 73607 19138 90754\n", "10\n4 10 4 4 5 10 10 4 10 10\n", "10\n63649 14562 779 31060 84730 3390 1402 70955 27426 79066\n", "10\n8 8 1 1 1 2 7 7 8 4\n", "10\n4131 4373 75721 60904 4027 25878 13621 3245 60722 8295\n", "10\n1 4 5 2 5 2 3 3 ...
1,600
500
2
14
1183_H. Subsequences (hard version)
The only difference between the easy and the hard versions is constraints. A subsequence is a string that can be derived from another string by deleting some or no symbols without changing the order of the remaining symbols. Characters to be deleted are not required to go successively, there can be any gaps between th...
{ "input": [ "4 5\nasdf\n", "5 6\naaaaa\n", "5 7\naaaaa\n", "10 100\najihiushda\n" ], "output": [ "4\n", "15\n", "-1\n", "233\n" ] }
{ "input": [ "50 50\ndxldyzmsrrwzwaofkcxwehgvtrsximxgdqrhjthkgfucrjdvwl\n", "10 25\nbpehfvamul\n", "1 10\ns\n", "10 10\nhittmcsvmo\n", "30 656341937\nqrzlwlvhfatfwmlpvndtgrxyphfjnn\n", "5 50\nbhhaj\n", "10 1023\nhsjztkorpv\n", "5 5\nwnxcc\n", "7 100\nasdfgha\n", "10 889\nltwnwd...
1,900
0
2
9
1201_C. Maximum Median
You are given an array a of n integers, where n is odd. You can make the following operation with it: * Choose one of the elements of the array (for example a_i) and increase it by 1 (that is, replace it with a_i + 1). You want to make the median of the array the largest possible using at most k operations. The...
{ "input": [ "3 2\n1 3 5\n", "7 7\n4 1 2 4 3 4 4\n", "5 5\n1 2 1 1 1\n" ], "output": [ "5", "5", "3" ] }
{ "input": [ "21 787008906\n335521569 160137548 807874739 723325809 995465063 693137631 646771913 971489138 603747543 801665542 882310956 163114045 892278880 371370111 459773357 909727810 630170326 940240523 886200899 882106547 953987440\n", "3 399138249\n524125987 923264237 374288891\n", "3 524125987\n92...
1,400
1,500
2
8
1243_B2. Character Swap (Hard Version)
This problem is different from the easy version. In this version Ujan makes at most 2n swaps. In addition, k ≀ 1000, n ≀ 50 and it is necessary to print swaps themselves. You can hack this problem if you solve it. But you can hack the previous problem only if you solve both problems. After struggling and failing many ...
{ "input": [ "4\n5\nsouse\nhouhe\n3\ncat\ndog\n2\naa\naz\n3\nabc\nbca\n" ], "output": [ "YES\n1\n4 1\nNO\nNO\nYES\n3\n3 3\n3 1\n3 2\n" ] }
{ "input": [ "4\n5\nsouse\nhouhe\n3\ncat\ndog\n2\naa\naz\n3\nabc\nbca\n" ], "output": [ "YES\n1\n4 1\nNO\nNO\nYES\n3\n3 3\n3 1\n3 2\n" ] }
1,600
750
2
10
1284_D. New Year and Conference
Filled with optimism, Hyunuk will host a conference about how great this new year will be! The conference will have n lectures. Hyunuk has two candidate venues a and b. For each of the n lectures, the speaker specified two time intervals [sa_i, ea_i] (sa_i ≀ ea_i) and [sb_i, eb_i] (sb_i ≀ eb_i). If the conference is s...
{ "input": [ "3\n1 3 2 4\n4 5 6 7\n3 4 5 5\n", "6\n1 5 2 9\n2 4 5 8\n3 6 7 11\n7 10 12 16\n8 11 13 17\n9 12 14 18\n", "2\n1 2 3 6\n3 4 7 8\n" ], "output": [ "NO\n", "YES\n", "YES\n" ] }
{ "input": [ "4\n1 5 1 3\n2 6 2 4\n3 7 3 5\n4 8 4 6\n", "4\n1 5 1 5\n2 3 2 3\n4 6 6 8\n100 200 100 200\n", "4\n1 2 5 6\n2 3 1 2\n5 6 2 3\n6 7 6 7\n", "4\n1 3 5 7\n2 4 1 3\n5 7 6 8\n6 8 2 4\n", "16\n3 4 3 4\n3 4 1 2\n1 2 3 4\n1 2 1 2\n1 2 1 2\n1 2 3 4\n3 4 1 2\n3 4 3 4\n1 2 1 2\n1 2 3 4\n3 4 1 2\n3...
2,100
2,500
2
8
138_B. Digits Permutations
Andrey's favourite number is n. Andrey's friends gave him two identical numbers n as a New Year present. He hung them on a wall and watched them adoringly. Then Andrey got bored from looking at the same number and he started to swap digits first in one, then in the other number, then again in the first number and so o...
{ "input": [ "500\n", "198\n" ], "output": [ "500\n500", "981\n819\n" ] }
{ "input": [ "8679647744\n", "9070901003919040000887091134838800004472724709967020097067025050205000220352709096100405900207957128\n", "3311314413231141411421432122343321141133112122342341334443214\n", "1099\n", "993522733475817\n", "346762409573609367635944363650432097309\n", "30372250375...
1,900
1,000
2
12
1454_F. Array Partition
You are given an array a consisting of n integers. Let min(l, r) be the minimum value among a_l, a_{l + 1}, …, a_r and max(l, r) be the maximum value among a_l, a_{l + 1}, …, a_r. Your task is to choose three positive (greater than 0) integers x, y and z such that: * x + y + z = n; * max(1, x) = min(x + 1, x + ...
{ "input": [ "6\n11\n1 2 3 3 3 4 4 3 4 2 1\n8\n2 9 1 7 3 9 4 1\n9\n2 1 4 2 4 3 3 1 2\n7\n4 2 1 1 4 1 4\n5\n1 1 1 1 1\n7\n4 3 4 3 3 3 4\n" ], "output": [ "\nYES\n6 1 4\nNO\nYES\n2 5 2\nYES\n4 1 2\nYES\n1 1 3\nYES\n2 1 4\n" ] }
{ "input": [ "4\n3\n1 1 1\n3\n1 1 1\n3\n1 1 1\n3\n1 1 1\n", "8\n3\n1000000000 1000000000 1000000000\n3\n1 1000000000 1000000000\n3\n1000000000 1 1000000000\n3\n1 1 1000000000\n3\n1000000000 1000000000 1\n3\n1 1000000000 1\n3\n1000000000 1 1\n3\n1 1 1\n", "3\n3\n1 1 1\n3\n1 1 1\n3\n1 1 1\n" ], "output"...
2,100
0
2
7
1479_A. Searching Local Minimum
This is an interactive problem. Homer likes arrays a lot and he wants to play a game with you. Homer has hidden from you a permutation a_1, a_2, ..., a_n of integers 1 to n. You are asked to find any index k (1 ≀ k ≀ n) which is a local minimum. For an array a_1, a_2, ..., a_n, an index i (1 ≀ i ≀ n) is said to be...
{ "input": [ "5\n3\n2\n1\n4\n5\n" ], "output": [ "\n? 1\n? 2\n? 3\n? 4\n? 5\n! 3\n" ] }
{ "input": [ "31\n2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 1 22 23 24 25 26 27 28 29 30 31\n", "26\n12 8 5 1 3 4 6 7 9 10 13 14 15 16 18 19 20 2 11 17 21 22 23 24 25 26\n", "73\n14 61 69 73 59 26 8 2 65 51 68 3 22 31 30 36 5 64 60 62 9 24 48 46 12 19 18 52 39 67 42 50 71 66 16 28 25 70 27 53 32...
1,700
500
2
13
1505_G. Encoded message
Input The first line of the input contains a single integer N (1 ≀ N ≀ 24). The next N lines contain 5 space-separated integers each. The first three integers will be between 0 and 2, inclusive. The last two integers will be between 0 and 3, inclusive. The sum of the first three integers will be equal to the sum of ...
{ "input": [ "1\n1 0 0 1 0\n", "10\n2 0 0 1 1\n1 1 1 2 1\n2 1 0 1 2\n1 1 0 1 1\n2 1 0 2 1\n1 1 1 2 1\n1 2 1 3 1\n2 0 0 1 1\n1 1 0 1 1\n1 1 2 2 2\n" ], "output": [ "\na\n", "\ncodeforcez\n" ] }
{ "input": [ "1\n1 0 0 1 0\n" ], "output": [ "codeforcez\n" ] }
2,600
0
2
7
1529_A. Eshag Loves Big Arrays
Eshag has an array a consisting of n integers. Eshag can perform the following operation any number of times: choose some subsequence of a and delete every element from it which is strictly larger than AVG, where AVG is the average of the numbers in the chosen subsequence. For example, if a = [1 , 4 , 3 , 2 , 4] and ...
{ "input": [ "3\n6\n1 1 1 2 2 3\n6\n9 9 9 9 9 9\n6\n6 4 1 1 4 1\n" ], "output": [ "\n3\n0\n3\n" ] }
{ "input": [ "1\n2\n1 2\n" ], "output": [ "1\n" ] }
800
500
2
7
160_A. Twins
Imagine that you have a twin brother or sister. Having another person that looks exactly like you seems very unusual. It's hard to say if having something of an alter ego is good or bad. And if you do have a twin, then you very well know what it's like. Now let's imagine a typical morning in your family. You haven't w...
{ "input": [ "2\n3 3\n", "3\n2 1 2\n" ], "output": [ "2\n", "2\n" ] }
{ "input": [ "100\n5 5 4 3 5 1 2 5 1 1 3 5 4 4 1 1 1 1 5 4 4 5 1 5 5 1 2 1 3 1 5 1 3 3 3 2 2 2 1 1 5 1 3 4 1 1 3 2 5 2 2 5 5 4 4 1 3 4 3 3 4 5 3 3 3 1 2 1 4 2 4 4 1 5 1 3 5 5 5 5 3 4 4 3 1 2 5 2 3 5 4 2 4 5 3 2 4 2 4 3\n", "5\n2 2 2 4 4\n", "100\n85 50 17 89 65 89 5 20 86 26 16 21 85 14 44 31 87 31 6 2 48...
900
500
2
9
227_C. Flying Saucer Segments
An expedition group flew from planet ACM-1 to Earth in order to study the bipedal species (its representatives don't even have antennas on their heads!). The flying saucer, on which the brave pioneers set off, consists of three sections. These sections are connected by a chain: the 1-st section is adjacent only to the...
{ "input": [ "1 10\n", "3 8\n" ], "output": [ "2\n", "2\n" ] }
{ "input": [ "8 100\n", "514853447 9\n", "7 63\n", "9 95\n", "333734901 647005907\n", "602799218 494169337\n", "6 29\n", "1 3\n", "3 1\n", "2 3\n", "6 5\n", "523061914 144515354\n", "2 81\n", "3 27\n", "357780112 9\n", "528551307 729\n", "1 39\n", ...
1,400
500
2
7
251_A. Points on Line
Little Petya likes points a lot. Recently his mom has presented him n points lying on the line OX. Now Petya is wondering in how many ways he can choose three distinct points so that the distance between the two farthest of them doesn't exceed d. Note that the order of the points inside the group of three chosen point...
{ "input": [ "4 2\n-3 -2 -1 0\n", "4 3\n1 2 3 4\n", "5 19\n1 10 20 30 50\n" ], "output": [ "2\n", "4\n", "1\n" ] }
{ "input": [ "1 14751211\n847188590\n", "10 90\n24 27 40 41 61 69 73 87 95 97\n", "10 50\n1 4 20 27 65 79 82 83 99 100\n", "10 5\n31 36 43 47 48 50 56 69 71 86\n", "100 100\n-98 -97 -96 -93 -92 -91 -90 -87 -86 -84 -81 -80 -79 -78 -76 -75 -73 -71 -69 -67 -65 -64 -63 -62 -61 -54 -51 -50 -49 -48 -46 ...
1,300
500
2
8
276_B. Little Girl and Game
The Little Girl loves problems on games very much. Here's one of them. Two players have got a string s, consisting of lowercase English letters. They play a game that is described by the following rules: * The players move in turns; In one move the player can remove an arbitrary letter from string s. * If the pl...
{ "input": [ "aba\n", "abca\n" ], "output": [ "First\n", "Second\n" ] }
{ "input": [ "zz\n", "aabc\n", "vqdtkbvlbdyndheoiiwqhnvcmmhnhsmwwrvesnpdfxvprqbwzbodoihrywagphlsrcbtnvppjsquuuzkjazaenienjiyctyajsqdfsdiedzugkymgzllvpxfetkwfabbiotjcknzdwsvmbbuqrxrulvgljagvxdmfsqtcczhifhoghqgffkbviphbabwiaqburerfkbqfjbptkwlahysrrfwjbqfnrgnsnsukqqcxxwqtuhvdzqmpfwrbqzdwxcaifuyhvojgurmchh\n"...
1,300
1,000
2
8
322_B. Ciel and Flowers
Fox Ciel has some flowers: r red flowers, g green flowers and b blue flowers. She wants to use these flowers to make several bouquets. There are 4 types of bouquets: * To make a "red bouquet", it needs 3 red flowers. * To make a "green bouquet", it needs 3 green flowers. * To make a "blue bouquet", it needs 3 ...
{ "input": [ "3 6 9\n", "4 4 4\n", "0 0 0\n" ], "output": [ "6\n", "4\n", "0\n" ] }
{ "input": [ "0 1 0\n", "2 2 0\n", "7 8 9\n", "666806767 385540591 357848286\n", "3 3 5\n", "494914467 356982656 757942689\n", "242854896 442432924 180395753\n", "32 62 92\n", "8 8 9\n", "139978911 5123031 935395222\n", "937984449 184405994 992844522\n", "0 1 1\n", ...
1,600
1,000
2
7
370_A. Rook, Bishop and King
Little Petya is learning to play chess. He has already learned how to move a king, a rook and a bishop. Let us remind you the rules of moving chess pieces. A chessboard is 64 square fields organized into an 8 Γ— 8 table. A field is represented by a pair of integers (r, c) β€” the number of the row and the number of the co...
{ "input": [ "5 5 5 6\n", "4 3 1 6\n" ], "output": [ "1 0 1", "2 1 3" ] }
{ "input": [ "1 4 6 2\n", "8 1 1 8\n", "1 3 1 6\n", "6 7 4 1\n", "1 7 5 4\n", "1 5 2 7\n", "4 2 6 4\n", "1 2 3 2\n", "3 3 1 5\n", "1 1 8 1\n", "1 3 3 7\n", "3 8 7 2\n", "1 1 8 8\n", "8 1 1 1\n", "6 5 1 4\n", "8 1 8 8\n", "1 8 8 8\n", "8 8 8 1\n",...
1,100
500
2
12
391_F1. Stock Trading
This problem consists of three subproblems: for solving subproblem F1 you will receive 8 points, for solving subproblem F2 you will receive 15 points, and for solving subproblem F3 you will receive 10 points. Manao has developed a model to predict the stock price of a company over the next n days and wants to design a...
{ "input": [ "10 2\n2\n7\n3\n9\n8\n7\n9\n7\n1\n9\n", "10 5\n2\n7\n3\n9\n8\n7\n9\n7\n1\n9\n" ], "output": [ "15", "21" ] }
{ "input": [ "2 1\n2\n1\n" ], "output": [ "0" ] }
0
8
2
8
441_B. Valera and Fruits
Valera loves his garden, where n fruit trees grow. This year he will enjoy a great harvest! On the i-th tree bi fruit grow, they will ripen on a day number ai. Unfortunately, the fruit on the tree get withered, so they can only be collected on day ai and day ai + 1 (all fruits that are not collected in these two days,...
{ "input": [ "5 10\n3 20\n2 20\n1 20\n4 20\n5 20\n", "2 3\n1 5\n2 3\n" ], "output": [ "60\n", "8\n" ] }
{ "input": [ "5 3000\n5 772\n1 2522\n2 575\n4 445\n3 426\n", "2 100\n3000 100\n3000 100\n", "1 40\n3000 42\n", "1 10\n3000 20\n", "10 3000\n1 2522\n4 445\n8 1629\n5 772\n9 2497\n6 81\n3 426\n7 1447\n2 575\n10 202\n", "1 1\n3000 2\n", "1 1\n3000 3000\n", "2 10\n2999 100\n3000 100\n", ...
1,400
1,000
2
9
463_C. Gargari and Bishops
Gargari is jealous that his friend Caisa won the game from the previous problem. He wants to prove that he is a genius. He has a n Γ— n chessboard. Each cell of the chessboard has a number written on it. Gargari wants to place two bishops on the chessboard in such a way that there is no cell that is attacked by both of...
{ "input": [ "4\n1 1 1 1\n2 1 1 0\n1 1 1 0\n1 0 0 1\n" ], "output": [ "12\n2 2 3 2" ] }
{ "input": [ "8\n3 6 9 2 2 1 4 2\n1 4 10 1 1 10 1 4\n3 8 9 1 8 4 4 4\n5 8 10 5 5 6 4 7\n3 2 10 6 5 3 8 5\n6 7 5 8 8 5 4 2\n4 4 3 1 8 8 5 4\n5 6 8 9 3 1 8 5\n", "10\n48 43 75 80 32 30 65 31 18 91\n99 5 12 43 26 90 54 91 4 88\n8 87 68 95 73 37 53 46 53 90\n50 1 85 24 32 16 5 48 98 74\n38 49 78 2 91 3 43 96 93 4...
1,900
1,500
2
8
487_B. Strip
Alexandra has a paper strip with n numbers on it. Let's call them ai from left to right. Now Alexandra wants to split it into some pieces (possibly 1). For each piece of strip, it must satisfy: * Each piece should contain at least l numbers. * The difference between the maximal and the minimal number on the piece...
{ "input": [ "7 2 2\n1 100 1 100 1 100 1\n", "7 2 2\n1 3 1 2 4 1 2\n" ], "output": [ "-1\n", "3\n" ] }
{ "input": [ "1 0 1\n0\n", "10 3 3\n1 1 1 1 1 5 6 7 8 9\n", "2 1000000000 2\n-1000000000 1000000000\n", "6 565 2\n31 76 162 -182 -251 214\n", "1 0 1\n-1000000000\n", "2 1000000000 1\n-1000000000 1000000000\n", "1 100 2\n42\n", "10 3 3\n1 1 1 2 2 5 6 7 8 9\n" ], "output": [ "1\n...
2,000
1,500
2
7
510_A. Fox And Snake
Fox Ciel starts to learn programming. The first task is drawing a fox! However, that turns out to be too hard for a beginner, so she decides to draw a snake instead. A snake is a pattern on a n by m table. Denote c-th cell of r-th row as (r, c). The tail of the snake is located at (1, 1), then it's body extends to (1,...
{ "input": [ "9 9\n", "5 3\n", "3 3\n", "3 4\n" ], "output": [ "#########\n........#\n#########\n#........\n#########\n........#\n#########\n#........\n#########\n", "###\n..#\n###\n#..\n###\n", "###\n..#\n###\n", "####\n...#\n####\n" ] }
{ "input": [ "45 45\n", "11 3\n", "11 15\n", "7 7\n", "5 6\n", "19 3\n", "7 5\n", "45 4\n", "45 3\n", "3 6\n", "45 49\n", "43 27\n", "33 43\n", "49 49\n", "7 3\n", "49 50\n", "5 5\n", "3 5\n", "7 6\n", "33 44\n", "5 4\n", "43 50\n...
800
500
2
8
535_B. Tavas and SaDDas
Once again Tavas started eating coffee mix without water! Keione told him that it smells awful, but he didn't stop doing that. That's why Keione told his smart friend, SaDDas to punish him! SaDDas took Tavas' headphones and told him: "If you solve the following problem, I'll return it to you." <image> The problem is:...
{ "input": [ "4\n", "77\n", "7\n" ], "output": [ "1", "6", "2" ] }
{ "input": [ "7747\n", "447\n", "7474747\n", "77474\n", "774477\n", "774\n", "477477447\n", "777774\n", "777744747\n", "47\n", "747777\n", "7774477\n", "444\n", "7747474\n", "444444444\n", "7444\n", "4447\n", "4447744\n", "474744\n", "777...
1,100
1,000
2
9
55_C. Pie or die
Volodya and Vlad play the following game. There are k pies at the cells of n Γ— m board. Each turn Volodya moves one pie to the neighbouring (by side) cell. If the pie lies at the border of the board then Volodya can move it outside the board, get the pie and win. After Volodya's move, Vlad bans some edge at the border ...
{ "input": [ "100 50 2\n50 25\n50 25\n", "3 4 0\n", "2 2 1\n1 2\n" ], "output": [ "NO\n", "NO\n", "YES\n" ] }
{ "input": [ "20 20 5\n10 6\n6 8\n16 11\n11 11\n7 15\n", "66 94 26\n11 75\n46 72\n55 74\n34 10\n33 84\n25 11\n13 23\n27 73\n45 22\n54 34\n53 63\n28 8\n57 46\n26 78\n52 46\n32 38\n22 55\n17 71\n56 18\n9 60\n31 54\n6 84\n59 57\n60 81\n51 49\n41 77\n", "20 20 5\n10 6\n6 8\n16 11\n11 11\n7 15\n", "25 11 0...
1,900
1,500
2
7
608_A. Saitama Destroys Hotel
Saitama accidentally destroyed a hotel again. To repay the hotel company, Genos has volunteered to operate an elevator in one of its other hotels. The elevator is special β€” it starts on the top floor, can only move down, and has infinite capacity. Floors are numbered from 0 to s and elevator initially starts on floor s...
{ "input": [ "5 10\n2 77\n3 33\n8 21\n9 12\n10 64\n", "3 7\n2 1\n3 8\n5 2\n" ], "output": [ "79\n", "11\n" ] }
{ "input": [ "2 10\n9 10\n6 11\n", "2 7\n6 3\n1 5\n", "2 10\n9 3\n1 4\n", "2 20\n10 10\n19 9\n", "2 20\n1 1\n2 2\n", "2 100\n4 100\n7 99\n", "4 4\n4 6\n4 8\n1 7\n2 9\n", "2 100\n99 9\n1 10\n", "100 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1...
1,000
500
2
12
792_F. Mages and Monsters
Vova plays a computer game known as Mages and Monsters. Vova's character is a mage. Though as he has just started, his character knows no spells. Vova's character can learn new spells during the game. Every spell is characterized by two values xi and yi β€” damage per second and mana cost per second, respectively. Vova ...
{ "input": [ "3 100\n1 4 9\n2 19 49\n2 19 49\n" ], "output": [ "YES\nNO\n" ] }
{ "input": [ "2 424978864039\n2 7 3\n2 10 8\n", "15 100\n1 8 8\n2 200 101\n2 10 99\n1 9 9\n2 10 99\n2 200 101\n1 14 4\n2 194 195\n2 194 194\n2 990 290\n1 2 999992\n2 6 256\n2 7 256\n1 2 999988\n2 2 252\n", "3 10\n1 1 1\n2 1 1\n2 999999 999999\n", "12 100\n1 8 8\n2 200 101\n2 10 99\n1 9 9\n2 10 99\n2 2...
3,100
0
2
9
813_C. The Tag Game
Alice got tired of playing the tag game by the usual rules so she offered Bob a little modification to it. Now the game should be played on an undirected rooted tree of n vertices. Vertex 1 is the root of the tree. Alice starts at vertex 1 and Bob starts at vertex x (x β‰  1). The moves are made in turns, Bob goes first...
{ "input": [ "4 3\n1 2\n2 3\n2 4\n", "5 2\n1 2\n2 3\n3 4\n2 5\n" ], "output": [ "4", "6" ] }
{ "input": [ "3 3\n1 2\n3 2\n", "8 3\n2 1\n3 1\n4 3\n5 1\n6 1\n7 1\n8 6\n", "10 4\n5 4\n8 3\n4 6\n5 3\n7 9\n1 3\n5 10\n2 9\n9 8\n", "2 2\n2 1\n", "3 3\n2 1\n3 1\n", "34 33\n2 1\n3 2\n4 3\n5 2\n6 3\n7 2\n8 5\n9 7\n10 8\n11 7\n12 7\n13 8\n14 2\n15 10\n16 1\n17 9\n18 14\n19 1\n20 2\n21 8\n22 21\n...
1,700
0
2
8
839_B. Game of the Rows
Daenerys Targaryen has an army consisting of k groups of soldiers, the i-th group contains ai soldiers. She wants to bring her army to the other side of the sea to get the Iron Throne. She has recently bought an airplane to carry her army through the sea. The airplane has n rows, each of them has 8 seats. We call two s...
{ "input": [ "2 2\n5 8\n", "1 2\n7 1\n", "1 4\n2 2 1 2\n", "1 2\n4 4\n" ], "output": [ "YES\n", "NO\n", "YES\n", "YES\n" ] }
{ "input": [ "1 4\n1 2 2 2\n", "8459 91\n778 338 725 1297 115 540 1452 2708 193 1806 1496 1326 2648 176 199 93 342 3901 2393 2718 800 3434 657 4037 291 690 1957 3280 73 6011 2791 1987 440 455 444 155 261 234 829 1309 1164 616 34 627 107 213 52 110 323 81 98 8 7 73 20 12 56 3 40 12 8 7 69 1 14 3 6 2 6 8 3 5 4 ...
1,900
1,000
2
11
859_E. Desk Disorder
A new set of desks just arrived, and it's about time! Things were getting quite cramped in the office. You've been put in charge of creating a new seating chart for the engineers. The desks are numbered, and you sent out a survey to the engineering team asking each engineer the number of the desk they currently sit at,...
{ "input": [ "4\n1 5\n5 2\n3 7\n7 3\n", "5\n1 10\n2 10\n3 10\n4 10\n5 5\n" ], "output": [ "6\n", "5\n" ] }
{ "input": [ "1\n1 2\n", "30\n22 37\n12 37\n37 58\n29 57\n43 57\n57 58\n58 53\n45 4\n1 4\n4 51\n35 31\n21 31\n31 51\n51 53\n53 48\n60 55\n52 55\n55 33\n36 9\n10 9\n9 33\n33 19\n5 23\n47 23\n23 32\n50 44\n26 44\n44 32\n32 19\n19 48\n", "5\n1 2\n2 3\n3 4\n4 5\n5 1\n", "10\n15 8\n8 13\n13 3\n1 4\n14 3\n1...
2,100
2,000
2
10
884_D. Boxes And Balls
Ivan has n different boxes. The first of them contains some balls of n different colors. Ivan wants to play a strange game. He wants to distribute the balls into boxes in such a way that for every i (1 ≀ i ≀ n) i-th box will contain all balls with color i. In order to do this, Ivan will make some turns. Each turn he ...
{ "input": [ "3\n1 2 3\n", "4\n2 3 4 5\n" ], "output": [ "6\n", "19\n" ] }
{ "input": [ "2\n3 4\n", "8\n821407370 380061316 428719552 90851747 825473738 704702117 845629927 245820158\n", "1\n10\n", "1\n1\n", "1\n4\n", "6\n1 4 4 4 4 4\n", "1\n12312\n" ], "output": [ "7\n", "8176373828\n", "0\n", "0\n", "0\n", "38\n", "0\n" ] }
2,300
0
2
12
908_F. New Year and Rainbow Roads
Roy and Biv have a set of n points on the infinite number line. Each point has one of 3 colors: red, green, or blue. Roy and Biv would like to connect all the points with some edges. Edges can be drawn between any of the two of the given points. The cost of an edge is equal to the distance between the two points it c...
{ "input": [ "4\n1 G\n2 R\n3 B\n10 G\n", "4\n1 G\n5 R\n10 B\n15 G\n" ], "output": [ "12", "23" ] }
{ "input": [ "4\n1 G\n123123 R\n987987987 B\n1000000000 G\n", "1\n3 R\n" ], "output": [ "1012135134", "0" ] }
2,400
2,000
2
11
92_E. Ski Base
A ski base is planned to be built in Walrusland. Recently, however, the project is still in the constructing phase. A large land lot was chosen for the construction. It contains n ski junctions, numbered from 1 to n. Initially the junctions aren't connected in any way. In the constructing process m bidirectional ski r...
{ "input": [ "3 4\n1 3\n2 3\n1 2\n1 2\n" ], "output": [ "0\n0\n1\n3\n" ] }
{ "input": [ "27 29\n12 11\n21 20\n19 26\n16 24\n22 4\n1 3\n23 5\n9 1\n4 3\n21 23\n22 8\n14 6\n25 13\n7 20\n9 16\n3 20\n23 19\n17 10\n13 18\n8 14\n23 25\n25 27\n19 15\n19 15\n17 24\n12 27\n18 11\n25 5\n22 17\n", "15 29\n6 11\n14 3\n10 4\n14 7\n6 14\n7 15\n13 8\n10 13\n4 14\n15 8\n12 7\n3 5\n6 7\n8 1\n4 5\n11 ...
2,300
1,500
2
9
958_C1. Encryption (easy)
Rebel spy Heidi has just obtained the plans for the Death Star from the Empire and, now on her way to safety, she is trying to break the encryption of the plans (of course they are encrypted – the Empire may be evil, but it is not stupid!). The encryption has several levels of security, and here is how the first one lo...
{ "input": [ "4 10\n3 4 7 2\n", "10 12\n16 3 24 13 9 8 7 5 12 12\n" ], "output": [ "16", "13" ] }
{ "input": [ "10 5 12\n16 3 24 13 9 8 7 5 12 12\n", "5 50\n1 1 1 1 1\n", "5 50\n100 150 200 100 50\n", "4 3 10\n3 4 7 2\n", "2 2\n9 9\n", "2 2\n8 8\n" ], "output": [ "4", "5", "0", "3", "2", "0" ] }
1,200
0
2
8
1004_B. Sonya and Exhibition
Sonya decided to organize an exhibition of flowers. Since the girl likes only roses and lilies, she decided that only these two kinds of flowers should be in this exhibition. There are n flowers in a row in the exhibition. Sonya can put either a rose or a lily in the i-th position. Thus each of n positions should cont...
{ "input": [ "6 3\n5 6\n1 4\n4 6\n", "5 3\n1 3\n2 4\n2 5\n" ], "output": [ "010101", "01010" ] }
{ "input": [ "1000 10\n3 998\n2 1000\n1 999\n2 1000\n3 998\n2 1000\n3 998\n1 1000\n2 1000\n3 999\n", "1 1\n1 1\n", "1000 20\n50 109\n317 370\n710 770\n440 488\n711 757\n236 278\n314 355\n131 190\n115 162\n784 834\n16 56\n677 730\n802 844\n632 689\n23 74\n647 702\n930 986\n926 983\n769 822\n508 558\n", ...
1,300
1,000
2
8
1028_B. Unnatural Conditions
Let s(x) be sum of digits in decimal representation of positive integer x. Given two integers n and m, find some positive integers a and b such that * s(a) β‰₯ n, * s(b) β‰₯ n, * s(a + b) ≀ m. Input The only line of input contain two integers n and m (1 ≀ n, m ≀ 1129). Output Print two lines, one for decimal...
{ "input": [ "8 16\n", "6 5\n" ], "output": [ "11111111\n88888889", "111111\n888889" ] }
{ "input": [ "578 3\n", "20 2\n", "1000 1\n", "4 1\n", "10 1\n", "843 152\n", "1 1\n", "3 10\n", "1 1000\n", "9 1\n", "1000 1000\n", "123 5\n", "1 1129\n", "999 999\n", "1129 1129\n", "1129 1\n", "321 1129\n", "123 1000\n", "100 10\n", "4...
1,200
750
2
14
1046_H. Palindrome Pairs
After learning a lot about space exploration, a little girl named Ana wants to change the subject. Ana is a girl who loves palindromes (string that can be read the same backwards as forward). She has learned how to check for a given string whether it's a palindrome or not, but soon she grew tired of this problem, so s...
{ "input": [ "3\naa\nbb\ncd\n", "6\naab\nabcac\ndffe\ned\naa\naade\n" ], "output": [ "1\n", "6\n" ] }
{ "input": [ "20\niw\nix\nudb\nbg\noi\nuo\njsm\num\ns\nquy\nqo\nbxct\nng\nrmr\nnu\nps\nio\nkh\nw\nk\n", "17\npo\nuej\ndtc\nj\ncnj\ncn\nbt\nnrj\nyye\nkol\nz\ntm\narb\ne\nzq\nj\nk\n" ], "output": [ "5\n", "4\n" ] }
1,600
0
2
13
1070_G. Monsters and Potions
Polycarp is an introvert person. In fact he is so much of an introvert that he plays "Monsters and Potions" board game alone. The board of the game is a row of n cells. The cells are numbered from 1 to n from left to right. There are three types of cells: a cell containing a single monster, a cell containing a single p...
{ "input": [ "8 3\n8 2\n1 3\n4 9\n0 3 -5 0 -5 -4 -1 0\n", "1 1\n1 1\n0\n", "8 3\n1 15\n5 10\n8 1\n0 -5 -5 -5 0 -5 -5 0\n", "3 2\n1 1\n3 1\n0 -5000 0\n" ], "output": [ "6\n3 2 1 \n", "1\n1 \n", "7\n2 1 3 \n", "-1\n" ] }
{ "input": [ "4 2\n1 1\n4 1\n0 -2 1 0\n", "5 2\n1 1\n5 1\n0 1 -3 1 0\n", "10 2\n1 1\n10 1\n0 1 1 1 1 1 1 1 -8 0\n", "100 2\n1 1\n100 1\n0 -98 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 ...
2,300
0
2
9
1092_C. Prefixes and Suffixes
Ivan wants to play a game with you. He picked some string s of length n consisting only of lowercase Latin letters. You don't know this string. Ivan has informed you about all its improper prefixes and suffixes (i.e. prefixes and suffixes of lengths from 1 to n-1), but he didn't tell you which strings are prefixes an...
{ "input": [ "3\na\naa\naa\na\n", "5\nba\na\nabab\na\naba\nbaba\nab\naba\n", "2\na\nc\n" ], "output": [ "PPSS", "SPPSPSPS", "PS" ] }
{ "input": [ "5\na\na\nab\nba\naba\naba\nbaba\nabab\n", "4\nab\na\nb\nbab\nab\naba\n", "5\na\naa\naaa\naaaa\nb\nba\nbaa\nbaaa\n", "4\na\nba\naba\nb\nba\nbab\n", "4\na\nb\nab\nab\nbab\naba\n", "5\nbaba\nabab\na\nab\naba\na\nba\naba\n", "4\nzn\nz\nn\nnzn\nzn\nznz\n", "4\nb\nab\nbab\na\na...
1,700
0
2
7
1111_A. Superhero Transformation
We all know that a superhero can transform to certain other superheroes. But not all Superheroes can transform to any other superhero. A superhero with name s can transform to another superhero with name t if s can be made equal to t by changing any vowel in s to any other vowel and any consonant in s to any other cons...
{ "input": [ "akm\nua\n", "a\nu\n", "abc\nukm\n" ], "output": [ "No\n", "YES\n", "YES\n" ] }
{ "input": [ "b\na\n", "abcdef\ncdabef\n", "ka\nak\n", "aabcd\nbcaad\n", "aabb\nabab\n", "zenudggmyopddhszhrbmftgzmjorabhgojdtfnzxjkayjlkgczsyshczutkdchiytqlfsevymipufxkxojlvkkqxvjhpjmcxeiluua\nblcdiwjphlpzwvknsyvbcodpyktizgatrlieiikktghixbikehsiknjuateltwkyyhgabygwtclyeyquaoiqnypoxnvyzvyhfejo...
1,000
500
2
10
1159_D. The minimal unique substring
Let s be some string consisting of symbols "0" or "1". Let's call a string t a substring of string s, if there exists such number 1 ≀ l ≀ |s| - |t| + 1 that t = s_l s_{l+1} … s_{l + |t| - 1}. Let's call a substring t of string s unique, if there exist only one such l. For example, let s = "1010111". A string t = "010...
{ "input": [ "4 4\n", "7 3\n", "5 3\n" ], "output": [ "1111", "0010010", "01010" ] }
{ "input": [ "100000 33334\n", "81 1\n", "99999 3\n", "99985 45273\n", "3 3\n", "99997 64685\n", "87 43\n", "6 4\n", "3 1\n", "99999 1\n", "100000 99992\n", "99999 99991\n", "99999 99999\n", "99999 50719\n", "22359 1593\n", "99999 46087\n", "100000 9...
2,200
1,000
2
10
1181_D. Irrigation
Misha was interested in water delivery from childhood. That's why his mother sent him to the annual Innovative Olympiad in Irrigation (IOI). Pupils from all Berland compete there demonstrating their skills in watering. It is extremely expensive to host such an olympiad, so after the first n olympiads the organizers int...
{ "input": [ "4 5 4\n4 4 5 1\n15\n9\n13\n6\n", "6 4 10\n3 1 1 1 2 2\n7\n8\n9\n10\n11\n12\n13\n14\n15\n16\n" ], "output": [ "5\n3\n3\n3\n", "4\n3\n4\n2\n3\n4\n1\n2\n3\n4\n" ] }
{ "input": [ "100 21 20\n11 17 21 14 7 15 18 6 17 11 21 3 17 21 21 7 21 17 14 21 14 14 3 6 18 21 17 17 18 14 14 21 15 13 3 15 11 11 16 11 6 10 15 17 11 15 13 13 21 16 21 13 11 14 21 21 13 18 16 3 21 16 13 16 15 3 16 21 21 21 14 15 16 17 16 16 21 2 14 21 7 7 21 16 17 21 17 15 21 10 7 17 21 11 13 17 14 3 11 14\n170...
2,200
1,750
2
9
119_C. Education Reform
Yet another education system reform has been carried out in Berland recently. The innovations are as follows: An academic year now consists of n days. Each day pupils study exactly one of m subjects, besides, each subject is studied for no more than one day. After the lessons of the i-th subject pupils get the home ta...
{ "input": [ "4 5 2\n1 10 1\n1 10 2\n1 10 3\n1 20 4\n1 100 5\n", "3 4 3\n1 3 1\n2 4 4\n2 3 3\n2 2 2\n" ], "output": [ "YES\n1 8\n2 10\n4 ...
{ "input": [ "50 50 1\n1 1 1\n1 1 2\n1 1 3\n1 1 4\n1 1 5\n1 1 6\n1 1 7\n1 1 8\n1 1 9\n1 1 10\n1 1 11\n1 1 12\n1 1 13\n1 1 14\n1 1 15\n1 1 16\n1 1 17\n1 1 18\n1 1 19\n1 1 20\n1 1 21\n1 1 22\n1 1 23\n1 1 24\n1 1 25\n1 1 26\n1 1 27\n1 1 28\n1 1 29\n1 1 30\n1 1 31\n1 1 32\n1 1 33\n1 1 34\n1 1 35\n1 1 36\n1 1 37\n1 1 ...
2,000
1,500
2
7
1217_A. Creating a Character
You play your favourite game yet another time. You chose the character you didn't play before. It has str points of strength and int points of intelligence. Also, at start, the character has exp free experience points you can invest either in strength or in intelligence (by investing one point you can either raise stre...
{ "input": [ "4\n5 3 4\n2 1 0\n3 5 5\n4 10 6\n" ], "output": [ "3\n1\n2\n0\n" ] }
{ "input": [ "5\n1 1 100000000\n100000000 100000000 100000000\n100000000 1 100000000\n1 100000000 100000000\n100000000 100000000 1\n" ], "output": [ "50000000\n50000000\n100000000\n1\n1\n" ] }
1,300
0
2
12
1325_F. Ehab's Last Theorem
It's the year 5555. You have a graph, and you want to find a long cycle and a huge independent set, just because you can. But for now, let's just stick with finding either. Given a connected graph with n vertices, you can choose to either: * find an independent set that has exactly ⌈√{n}βŒ‰ vertices. * find a simpl...
{ "input": [ "6 6\n1 3\n3 4\n4 2\n2 6\n5 6\n5 1\n", "6 8\n1 3\n3 4\n4 2\n2 6\n5 6\n5 1\n1 4\n2 5\n", "5 4\n1 2\n1 3\n2 4\n2 5\n" ], "output": [ "2\n6\n5 6 2 4 3 1 \n", "2\n6\n5 6 2 4 3 1\n", "1\n3 4 5\n" ] }
{ "input": [ "5 5\n1 2\n1 3\n2 3\n1 4\n4 5\n", "17 51\n3 12\n6 13\n15 1\n3 10\n13 2\n17 8\n3 14\n13 17\n2 6\n16 2\n1 10\n3 17\n3 15\n9 12\n7 8\n2 8\n7 13\n9 2\n2 14\n5 6\n12 8\n15 13\n14 8\n4 14\n16 12\n5 14\n15 14\n10 7\n15 6\n17 5\n16 5\n8 4\n15 11\n17 7\n15 8\n12 7\n4 13\n8 16\n1 2\n2 11\n2 7\n7 9\n16 1\n4...
2,500
2,750
2
11
1366_E. Two Arrays
You are given two arrays a_1, a_2, ... , a_n and b_1, b_2, ... , b_m. Array b is sorted in ascending order (b_i < b_{i + 1} for each i from 1 to m - 1). You have to divide the array a into m consecutive subarrays so that, for each i from 1 to m, the minimum on the i-th subarray is equal to b_i. Note that each element ...
{ "input": [ "6 3\n12 10 20 20 25 30\n10 20 30\n", "8 2\n1 2 2 2 2 2 2 2\n1 2\n", "4 2\n1 3 3 7\n3 7\n" ], "output": [ "2", "7", "0" ] }
{ "input": [ "71 4\n9 9 6 9 8 2 10 9 2 5 10 1 9 7 5 6 4 9 3 7 3 8 5 3 4 10 5 9 9 1 2 1 10 1 10 8 2 9 2 2 8 8 2 4 10 1 6 9 7 2 7 5 1 1 8 6 7 9 5 6 8 2 3 4 3 1 3 7 2 7 4\n1 2 3 7\n", "2 2\n10 7\n5 7\n", "2 3\n1 3\n1 2 3\n", "24 3\n4 12 3 14 2 7 12 7 11 3 5 10 14 1 6 12 13 4 1 5 5 9 8 6\n1 5 8\n", "9...
2,100
0
2
8
1387_B1. Village (Minimum)
This problem is split into two tasks. In this task, you are required to find the minimum possible answer. In the task Village (Maximum) you are required to find the maximum possible answer. Each task is worth 50 points. There are N houses in a certain village. A single villager lives in each of the houses. The houses ...
{ "input": [ "4\n1 2\n2 3\n3 4\n", "7\n4 2\n5 7\n3 4\n6 3\n1 3\n4 5\n" ], "output": [ "4\n2 1 4 3 ", "8\n6 4 1 2 7 3 5 " ] }
{ "input": [ "10\n9 8\n1 3\n7 5\n8 6\n8 10\n6 4\n1 6\n10 2\n6 5\n", "10\n5 7\n4 1\n10 5\n9 3\n7 9\n8 2\n6 1\n8 6\n2 7\n", "2\n1 2\n", "10\n10 2\n4 10\n1 10\n5 10\n10 7\n9 10\n3 10\n1 6\n8 1\n", "7\n4 1\n7 6\n7 5\n1 3\n3 2\n1 6\n", "10\n9 2\n10 4\n10 5\n2 5\n8 3\n3 6\n7 4\n9 8\n1 6\n", "10\...
2,100
0
2
11
1408_E. Avoid Rainbow Cycles
You are given m sets of integers A_1, A_2, …, A_m; elements of these sets are integers between 1 and n, inclusive. There are two arrays of positive integers a_1, a_2, …, a_m and b_1, b_2, …, b_n. In one operation you can delete an element j from the set A_i and pay a_i + b_j coins for that. You can make several (ma...
{ "input": [ "7 8\n3 6 7 9 10 7 239\n8 1 9 7 10 2 6 239\n3 2 1 3\n2 4 1\n3 1 3 7\n2 4 3\n5 3 4 5 6 7\n2 5 7\n1 8\n", "3 2\n1 2 3\n4 5\n2 1 2\n2 1 2\n2 1 2\n" ], "output": [ "66\n", "11\n" ] }
{ "input": [ "2 2\n1 1\n1 1\n2 1 2\n2 1 2\n" ], "output": [ "2\n" ] }
2,400
2,500
2
9
1452_C. Two Brackets
You are given a string s, consisting of brackets of two types: '(', ')', '[' and ']'. A string is called a regular bracket sequence (RBS) if it's of one of the following types: * empty string; * '(' + RBS + ')'; * '[' + RBS + ']'; * RBS + RBS. where plus is a concatenation of two strings. In one move...
{ "input": [ "5\n()\n[]()\n([)]\n)]([\n)[(]\n" ], "output": [ "\n1\n2\n2\n0\n1\n" ] }
{ "input": [ "4\n()\n()\n()\n()\n", "7\n()\n()\n()\n()\n()\n()\n()\n", "4\n[()]\n[]\n[]\n()\n" ], "output": [ "1\n1\n1\n1\n", "1\n1\n1\n1\n1\n1\n1\n", "2\n1\n1\n1\n" ] }
800
0
2
7
1476_A. K-divisible Sum
You are given two integers n and k. You should create an array of n positive integers a_1, a_2, ..., a_n such that the sum (a_1 + a_2 + ... + a_n) is divisible by k and maximum element in a is minimum possible. What is the minimum possible maximum element in a? Input The first line contains a single integer t (1 ≀ ...
{ "input": [ "4\n1 5\n4 3\n8 8\n8 17\n" ], "output": [ "\n5\n2\n1\n3\n" ] }
{ "input": [ "10\n1000000000 3\n1000000000 3\n1000000000 3\n1000000000 3\n1000000000 3\n1000000000 3\n1000000000 3\n1000000000 3\n1000000000 3\n1000000000 3\n", "12\n1000000000 1\n1000000000 1\n1000000000 1\n1000000000 1\n1000000000 1\n1000000000 1\n1000000000 1\n1000000000 1\n1000000000 1\n1000000000 1\n1 10...
1,000
0
2
8
1526_B. I Hate 1111
You are given an integer x. Can you make x by summing up some number of 11, 111, 1111, 11111, …? (You can use any number among them any number of times). For instance, * 33=11+11+11 * 144=111+11+11+11 Input The first line of input contains a single integer t (1 ≀ t ≀ 10000) β€” the number of testcases. The fi...
{ "input": [ "3\n33\n144\n69\n" ], "output": [ "\nYES\nYES\nNO\n" ] }
{ "input": [ "1\n1\n" ], "output": [ "NO\n" ] }
1,400
1,000
2
7
1_A. Theatre Square
Theatre Square in the capital city of Berland has a rectangular shape with the size n Γ— m meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each flagstone is of the size a Γ— a. What is the least number of flagstones needed to pave the Square? It'...
{ "input": [ "6 6 4\n" ], "output": [ "4\n" ] }
{ "input": [ "1 1 3\n", "1000000000 1000000000 1\n", "2 1 2\n", "222 332 5\n", "2 2 1\n", "456784567 1000000000 51\n", "1001 1000 10\n", "2 3 4\n", "1000000000 1000000000 999999999\n", "2 1 1\n", "100 10001 1000000000\n", "39916800 134217728 40320\n", "12 13 4\n", ...
1,000
0
2
8
224_B. Array
You've got an array a, consisting of n integers: a1, a2, ..., an. Your task is to find a minimal by inclusion segment [l, r] (1 ≀ l ≀ r ≀ n) such, that among numbers al, al + 1, ..., ar there are exactly k distinct numbers. Segment [l, r] (1 ≀ l ≀ r ≀ n; l, r are integers) of length m = r - l + 1, satisfying the given...
{ "input": [ "7 4\n4 7 7 4 7 4 7\n", "4 2\n1 2 2 3\n", "8 3\n1 1 2 2 3 3 4 5\n" ], "output": [ "-1 -1\n", "1 2", "2 5" ] }
{ "input": [ "10 4\n1 2 3 1 2 3 4 3 2 1\n", "4 2\n3 3 4 3\n", "5 3\n1 2 1 2 3\n", "10 4\n1 1 2 2 3 3 4 4 4 4\n", "5 3\n1 3 1 3 4\n", "9 3\n1 2 1 2 1 2 2 3 1\n", "4 3\n4 4 4 2\n", "5 1\n1 7 2 3 2\n", "10 3\n1 1 2 1 2 2 3 4 5 6\n", "7 3\n2 1 2 2 1 2 3\n", "10 5\n15 17 2 13 3 ...
1,500
1,000
2
7
273_A. Dima and Staircase
Dima's got a staircase that consists of n stairs. The first stair is at height a1, the second one is at a2, the last one is at an (1 ≀ a1 ≀ a2 ≀ ... ≀ an). Dima decided to play with the staircase, so he is throwing rectangular boxes at the staircase from above. The i-th box has width wi and height hi. Dima throws eac...
{ "input": [ "1\n1\n5\n1 2\n1 10\n1 10\n1 10\n1 10\n", "3\n1 2 3\n2\n1 1\n3 1\n", "5\n1 2 3 6 6\n4\n1 1\n3 1\n1 1\n4 3\n" ], "output": [ "1\n3\n13\n23\n33\n", "1\n3\n", "1\n3\n4\n6\n" ] }
{ "input": [ "7\n8 13 19 21 25 30 32\n3\n5 4\n6 5\n1 2\n", "3\n1 6 8\n5\n3 4\n3 9\n3 3\n1 2\n1 6\n", "2\n1 6\n5\n2 6\n1 2\n1 1\n1 2\n1 7\n", "1\n9\n8\n1 4\n1 10\n1 9\n1 9\n1 7\n1 1\n1 9\n1 2\n", "1\n1\n1\n1 1\n", "5\n1 2 3 6 6\n25\n1 1000000000\n1 1000000000\n1 1000000000\n1 1000000000\n1 1000...
1,500
1,500
2
9
296_C. Greg and Array
Greg has an array a = a1, a2, ..., an and m operations. Each operation looks as: li, ri, di, (1 ≀ li ≀ ri ≀ n). To apply operation i to the array means to increase all array elements with numbers li, li + 1, ..., ri by value di. Greg wrote down k queries on a piece of paper. Each query has the following form: xi, yi, ...
{ "input": [ "4 3 6\n1 2 3 4\n1 2 1\n2 3 2\n3 4 4\n1 2\n1 3\n2 3\n1 2\n1 3\n2 3\n", "1 1 1\n1\n1 1 1\n1 1\n", "3 3 3\n1 2 3\n1 2 1\n1 3 2\n2 3 4\n1 2\n1 3\n2 3\n" ], "output": [ "5 18 31 20\n", "2\n", "9 18 17\n" ] }
{ "input": [ "1 1 1\n0\n1 1 0\n1 1\n" ], "output": [ "0\n" ] }
1,400
500
2
7
31_A. Worms Evolution
Professor Vasechkin is studying evolution of worms. Recently he put forward hypotheses that all worms evolve by division. There are n forms of worms. Worms of these forms have lengths a1, a2, ..., an. To prove his theory, professor needs to find 3 different forms that the length of the first form is equal to sum of len...
{ "input": [ "5\n1 2 3 5 7\n", "5\n1 8 1 5 1\n" ], "output": [ "3 1 2", "-1\n" ] }
{ "input": [ "100\n611 697 572 770 603 870 128 245 49 904 468 982 788 943 549 288 668 796 803 515 999 735 912 49 298 80 412 841 494 434 543 298 17 571 271 105 70 313 178 755 194 279 585 766 412 164 907 841 776 556 731 268 735 880 176 267 287 65 239 588 155 658 821 47 783 595 585 69 226 906 429 161 999 148 7 484 3...
1,200
500
2
7
344_A. Magnets
Mad scientist Mike entertains himself by arranging rows of dominoes. He doesn't need dominoes, though: he uses rectangular magnets instead. Each magnet has two poles, positive (a "plus") and negative (a "minus"). If two magnets are put together at a close distance, then the like poles will repel each other and the oppo...
{ "input": [ "4\n01\n01\n10\n10\n", "6\n10\n10\n10\n01\n10\n10\n" ], "output": [ "2\n", "3\n" ] }
{ "input": [ "1\n10\n", "3\n10\n01\n10\n", "3\n10\n10\n01\n", "115\n10\n10\n10\n10\n01\n01\n10\n10\n10\n01\n01\n10\n01\n01\n10\n10\n10\n01\n10\n01\n10\n10\n01\n01\n10\n10\n10\n10\n01\n10\n01\n01\n10\n10\n10\n10\n01\n10\n10\n10\n01\n10\n01\n10\n10\n10\n10\n01\n01\n01\n10\n10\n01\n01\n01\n10\n10\n01\n10...
800
500
2
9
367_C. Sereja and the Arrangement of Numbers
Let's call an array consisting of n integer numbers a1, a2, ..., an, beautiful if it has the following property: * consider all pairs of numbers x, y (x β‰  y), such that number x occurs in the array a and number y occurs in the array a; * for each pair x, y must exist some position j (1 ≀ j < n), such that at leas...
{ "input": [ "100 3\n1 2\n2 1\n3 1\n", "1 2\n1 1\n2 100\n", "5 2\n1 2\n2 3\n" ], "output": [ "4\n", "100\n", "5\n" ] }
{ "input": [ "58 38\n6384 48910\n97759 90589\n28947 5031\n45169 32592\n85656 26360\n88538 42484\n44042 88351\n42837 79021\n96022 59200\n485 96735\n98000 3939\n3789 64468\n10894 58484\n26422 26618\n25515 95617\n37452 5250\n39557 66304\n79009 40610\n80703 60486\n90344 37588\n57504 61201\n62619 79797\n51282 68799\n1...
2,000
1,500
2
7
411_A. Password Check
You have probably registered on Internet sites many times. And each time you should enter your invented password. Usually the registration form automatically checks the password's crypt resistance. If the user's password isn't complex enough, a message is displayed. Today your task is to implement such an automatic che...
{ "input": [ "X12345\n", "CONTEST_is_STARTED!!11\n", "abacaba\n" ], "output": [ "Too weak\n", "Correct\n", "Too weak\n" ] }
{ "input": [ "Vu7jQU8.!FvHBYTsDp6AphaGfnEmySP9te\n", "P1H\n", "c7jqaudcqmv8o7zvb5x_gp6zcgl6nwr7tz5or!28.tj8s1m2.wxz5a4id03!rq07?662vy.7.p5?vk2f2mc7ag8q3861rgd0rmbr\n", "Hi7zYuVXCPhaho68YgCMzzgLILM6toQTJq8akMqqrnUn6ZCD36iA1yVVpvlsIiMpCu!1QZd4ycIrQ5Kcrhk5k0jTrwdAAEEP_T2f\n", "T,NDMUYCCXH_L_FJHMCCAGX...
800
0
2
8
460_B. Little Dima and Equation
Little Dima misbehaved during a math lesson a lot and the nasty teacher Mr. Pickles gave him the following problem as a punishment. Find all integer solutions x (0 < x < 109) of the equation: x = bΒ·s(x)a + c, where a, b, c are some predetermined constant values and function s(x) determines the sum of all digits in...
{ "input": [ "3 2 8\n", "2 2 -1\n", "1 2 -18\n" ], "output": [ "3\n10 2008 13726\n", "4\n1 31 337 967\n", "0\n\n" ] }
{ "input": [ "5 10000 9\n", "3 1139 6335\n", "2 8468 -3666\n", "5 5 13\n", "5 3903 153\n", "5 9999 9999\n", "1 3034 -9234\n", "1 1 0\n", "5 12 3\n", "2 28 12\n", "5 10000 0\n", "5 1 0\n", "3 2570 4109\n", "5 19 -666\n", "5 8975 -4\n", "4 1870 9912\n", ...
1,500
1,000
2
7
484_A. Bits
Let's denote as <image> the number of bits set ('1' bits) in the binary representation of the non-negative integer x. You are given multiple queries consisting of pairs of integers l and r. For each query, find the x, such that l ≀ x ≀ r, and <image> is maximum possible. If there are multiple such numbers find the sma...
{ "input": [ "3\n1 2\n2 4\n1 10\n" ], "output": [ "1\n3\n7\n" ] }
{ "input": [ "18\n1 10\n1 100\n1 1000\n1 10000\n1 100000\n1 1000000\n1 10000000\n1 100000000\n1 1000000000\n1 10000000000\n1 100000000000\n1 1000000000000\n1 10000000000000\n1 100000000000000\n1 1000000000000000\n1 10000000000000000\n1 100000000000000000\n1 1000000000000000000\n", "17\n0 0\n0 8\n1 8\n36 39\n3...
1,700
500
2
7
508_A. Pasha and Pixels
Pasha loves his phone and also putting his hair up... But the hair is now irrelevant. Pasha has installed a new game to his phone. The goal of the game is following. There is a rectangular field consisting of n row with m pixels in each row. Initially, all the pixels are colored white. In one move, Pasha can choose an...
{ "input": [ "2 2 4\n1 1\n1 2\n2 1\n2 2\n", "5 3 7\n2 3\n1 2\n1 1\n4 1\n3 1\n5 3\n3 2\n", "2 3 6\n2 3\n2 2\n1 3\n2 2\n1 2\n1 1\n" ], "output": [ "4", "0", "5" ] }
{ "input": [ "3 3 11\n2 1\n3 1\n1 1\n1 3\n1 2\n2 3\n3 3\n3 2\n2 2\n1 3\n3 3\n", "1000 1000 4\n1000 1000\n999 999\n1000 999\n999 1000\n", "1 1 5\n1 1\n1 1\n1 1\n1 1\n1 1\n", "2 2 5\n1 1\n2 1\n2 1\n1 2\n2 2\n", "1 1 1\n1 1\n", "10 10 4\n5 9\n6 9\n6 10\n5 10\n", "5 1 5\n1 1\n2 1\n3 1\n4 1\n5 ...
1,100
500
2
8
557_B. Pasha and Tea
Pasha decided to invite his friends to a tea party. For that occasion, he has a large teapot with the capacity of w milliliters and 2n tea cups, each cup is for one of Pasha's friends. The i-th cup can hold at most ai milliliters of water. It turned out that among Pasha's friends there are exactly n boys and exactly n...
{ "input": [ "1 5\n2 3\n", "2 4\n1 1 1 1\n", "3 18\n4 4 4 2 2 2\n" ], "output": [ "4.5\n", "3.0\n", "18.0\n" ] }
{ "input": [ "4 1000000000\n1 1 1 1 2 2 2 2\n", "4 30\n3 3 3 3 4 5 6 7\n", "2 19\n3 3 5 5\n", "4 1000000000\n1 1 1 1 1 1 1 1\n", "4 1\n3 3 3 3 4 4 4 4\n", "1 100\n1 200\n", "1 1\n1 1\n", "2 100\n1 1 1 10\n", "2 4\n1 1 1 1\n", "5 15\n2 3 4 1 2 4 5 3 5 10\n", "3 31\n3 3 3 5 5...
1,500
1,000
2
11
604_E. Lieges of Legendre
Kevin and Nicky Sun have invented a new game called Lieges of Legendre. In this game, two players take turns modifying the game state with Kevin moving first. Initially, the game is set up so that there are n piles of cows, with the i-th pile containing ai cows. During each player's turn, that player calls upon the pow...
{ "input": [ "1 2\n3\n", "2 1\n3 4\n" ], "output": [ "Nicky\n", "Kevin\n" ] }
{ "input": [ "2 1\n24 1\n", "1 1\n1\n", "5 1\n1 7 7 6 6\n", "2 3\n12345678 23456789\n", "2 1\n160 150\n", "2 3\n7 7\n", "2 2\n2 5\n", "9 2\n8 2 9 4 7 5 2 4 9\n", "6 2\n5 3 5 6 2 2\n", "7 2\n9 1 7 6 10 3 5\n", "2 2\n2 4\n", "6 1\n1 4 4 4 2 2\n", "2 2\n2 2\n", "1 ...
2,200
1,500
2
7
627_A. XOR Equation
Two positive integers a and b have a sum of s and a bitwise XOR of x. How many possible values are there for the ordered pair (a, b)? Input The first line of the input contains two integers s and x (2 ≀ s ≀ 1012, 0 ≀ x ≀ 1012), the sum and bitwise xor of the pair of positive integers, respectively. Output Print a s...
{ "input": [ "5 2\n", "9 5\n", "3 3\n" ], "output": [ "0", "4", "2" ] }
{ "input": [ "3 1\n", "322373798090 322373798090\n", "1000000000000 999999999999\n", "32576550340 504864993495\n", "1000000000000 4096\n", "4 6\n", "297044970199 121204864\n", "274869346299 274869346299\n", "80 12\n", "552972910589 546530328573\n", "241173201018 23667646448...
1,700
500
2
7
651_A. Joysticks
Friends are going to play console. They have two joysticks and only one charger for them. Initially first joystick is charged at a1 percent and second one is charged at a2 percent. You can connect charger to a joystick only at the beginning of each minute. In one minute joystick either discharges by 2 percent (if not c...
{ "input": [ "4 4\n", "3 5\n" ], "output": [ "5\n", "6\n" ] }
{ "input": [ "1 4\n", "7 2\n", "100 25\n", "29 1\n", "3 73\n", "14 15\n", "1 1\n", "24 57\n", "1 2\n", "3 2\n", "24 15\n", "2 97\n", "15 31\n", "15 25\n", "2 3\n", "8 8\n", "2 99\n", "59 45\n", "23 12\n", "3 1\n", "74 25\n", "85 7...
1,100
500
2
10
69_D. Dot
Anton and Dasha like to play different games during breaks on checkered paper. By the 11th grade they managed to play all the games of this type and asked Vova the programmer to come up with a new game. Vova suggested to them to play a game under the code name "dot" with the following rules: * On the checkered pape...
{ "input": [ "0 0 2 4\n1 1\n1 2\n", "0 0 2 3\n1 1\n1 2\n" ], "output": [ "Dasha\n", "Anton\n" ] }
{ "input": [ "3 -1 20 200\n19 12\n24 121\n25 32\n28 19\n28 87\n29 49\n32 88\n33 70\n37 77\n54 33\n56 27\n61 59\n67 42\n73 15\n76 40\n80 73\n83 39\n91 34\n91 112\n95 95\n", "0 0 5 100\n17 3\n42 24\n72 22\n72 25\n120 25\n", "0 0 5 100\n12 105\n15 59\n21 1\n27 6\n27 76\n", "-3 -14 20 200\n6 90\n7 12\n15 ...
1,900
2,000
2
7
721_A. One-dimensional Japanese Crossword
Recently Adaltik discovered japanese crosswords. Japanese crossword is a picture, represented as a table sized a Γ— b squares, and each square is colored white or black. There are integers to the left of the rows and to the top of the columns, encrypting the corresponding row or column. The number of integers represents...
{ "input": [ "3\nBBW\n", "5\nBWBWB\n", "4\nWWWW\n", "13\nWBBBBWWBWBBBW\n", "4\nBBBB\n" ], "output": [ "1\n2\n", "3\n1 1 1\n", "0\n\n", "3\n4 1 3\n", "1\n4\n" ] }
{ "input": [ "50\nBBBBBWBWBWWBWBWWWWWWBWBWBWWWWWWWWWWWWWBWBWWWWBWWWB\n", "50\nWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW\n", "10\nBBBBBWWBBB\n", "100\nBBBBWWWWWWWWWWWWWWWWWWWWWWWWWBWBWWWWWBWBWWWWWWBBWWWWWWWWWWWWBWWWWBWWWWWWWWWWWWBWWWWWWWBWWWWWWWBBBBBB\n", "50\nBBBBBBBBBBBBBBBBBBBBBBBBBBBBB...
800
500
2
10
742_D. Arpa's weak amphitheater and Mehrdad's valuable Hoses
Just to remind, girls in Arpa's land are really nice. Mehrdad wants to invite some Hoses to the palace for a dancing party. Each Hos has some weight wi and some beauty bi. Also each Hos may have some friends. Hoses are divided in some friendship groups. Two Hoses x and y are in the same friendship group if and only if...
{ "input": [ "4 2 11\n2 4 6 6\n6 4 2 1\n1 2\n2 3\n", "3 1 5\n3 2 5\n2 4 2\n1 2\n" ], "output": [ "7\n", "6\n" ] }
{ "input": [ "10 5 100\n64 90 3 94 96 97 52 54 82 31\n796554 444893 214351 43810 684158 555762 686198 339093 383018 699152\n6 8\n8 3\n3 9\n2 3\n10 3\n", "10 5 100\n48 73 30 46 95 19 98 73 94 24\n501216 675859 843572 565104 879875 828759 80776 766980 213551 492652\n1 2\n6 5\n7 6\n10 3\n8 1\n", "10 5 100\n6...
1,600
1,000
2
7
766_A. Mahmoud and Longest Uncommon Subsequence
While Mahmoud and Ehab were practicing for IOI, they found a problem which name was Longest common subsequence. They solved it, and then Ehab challenged Mahmoud with another problem. Given two strings a and b, find the length of their longest uncommon subsequence, which is the longest string that is a subsequence of o...
{ "input": [ "abcd\ndefgh\n", "a\na\n" ], "output": [ "5\n", "-1\n" ] }
{ "input": [ "abb\nabb\n", "abcde\nbbcde\n", "abc\ncba\n", "aaa\naaa\n", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\nbbbbbbbbbbbbbbbbbbb\n", "mmmmm\nmnmmm\n", "mo\nmomo\n", "abcdefgh\nabdcefgh\n", "ab\nab\n", "aaa\naa\n"...
1,000
500
2
11
789_E. The Great Mixing
Sasha and Kolya decided to get drunk with Coke, again. This time they have k types of Coke. i-th type is characterised by its carbon dioxide concentration <image>. Today, on the party in honour of Sergiy of Vancouver they decided to prepare a glass of Coke with carbon dioxide concentration <image>. The drink should als...
{ "input": [ "50 2\n100 25\n", "400 4\n100 300 450 500\n" ], "output": [ "3", "2" ] }
{ "input": [ "852 10\n668 1000 1000 1000 1000 1000 1000 639 213 1000\n", "314 15\n160 769 201 691 358 724 248 47 420 432 667 601 596 370 469\n", "834 10\n921 995 1000 285 1000 166 1000 999 991 983\n", "971 108\n706 706 991 706 988 997 996 997 991 996 706 706 996 706 996 984 1000 991 996 1000 724 724 9...
2,300
1,500
2
8
810_B. Summer sell-off
Summer holidays! Someone is going on trips, someone is visiting grandparents, but someone is trying to get a part-time job. This summer Noora decided that she wants to earn some money, and took a job in a shop as an assistant. Shop, where Noora is working, has a plan on the following n days. For each day sales manager...
{ "input": [ "4 1\n0 2\n0 3\n3 5\n0 6\n", "4 2\n2 1\n3 5\n2 3\n1 5\n" ], "output": [ "5", "10" ] }
{ "input": [ "2 1\n2 4\n4 4\n", "2 1\n10 11\n9 20\n", "2 1\n3 7\n5 7\n", "2 1\n1 2\n1000 1000\n", "2 1\n14 28\n15 28\n", "3 1\n10 11\n12 13\n8 10\n", "2 1\n5 7\n6 7\n", "3 1\n1 4\n2 4\n3 4\n", "2 1\n7 8\n3 6\n", "15 13\n76167099 92301116\n83163126 84046805\n45309500 65037149\n2...
1,300
1,000
2
7
856_A. Set Theory
Masha and Grisha like studying sets of positive integers. One day Grisha has written a set A containing n different integers ai on a blackboard. Now he asks Masha to create a set B containing n different integers bj such that all n2 integers that can be obtained by summing up ai and bj for all possible pairs of i and ...
{ "input": [ "3\n3\n1 10 100\n1\n1\n2\n2 4\n" ], "output": [ "YES\n1 2 3\nYES\n1\nYES\n1 2\n" ] }
{ "input": [ "1\n100\n74 14 24 45 22 9 49 78 79 20 60 1 31 91 32 39 90 5 42 57 30 58 64 68 12 11 86 8 3 38 76 17 98 26 85 92 56 65 89 66 36 87 23 67 13 48 15 47 81 73 63 50 34 93 82 44 77 69 96 100 41 19 35 16 88 27 99 40 62 95 70 18 46 21 53 59 37 6 61 71 2 4 52 28 97 25 29 51 7 33 80 83 72 10 75 94 43 84 54 55\...
1,600
0
2
7
883_A. Automatic Door
There is an automatic door at the entrance of a factory. The door works in the following way: * when one or several people come to the door and it is closed, the door immediately opens automatically and all people immediately come inside, * when one or several people come to the door and it is open, all people im...
{ "input": [ "1 1 3 4\n7\n", "4 3 4 2\n7 9 11\n" ], "output": [ "1\n", "4\n" ] }
{ "input": [ "100 30 36 47\n44 155 275 390 464 532 1186 1205 1345 1349 1432 1469 1482 1775 1832 1856 1869 2049 2079 2095 2374 2427 2577 2655 2792 2976 3020 3317 3482 3582\n", "100 20 49 52\n224 380 690 1585 1830 1973 2490 2592 3240 3341 3406 3429 3549 3560 3895 3944 4344 4390 4649 4800\n", "70 10 26 17\n3...
2,200
0
2
7
906_A. Shockers
Valentin participates in a show called "Shockers". The rules are quite easy: jury selects one letter which Valentin doesn't know. He should make a small speech, but every time he pronounces a word that contains the selected letter, he receives an electric shock. He can make guesses which letter is selected, but for eac...
{ "input": [ "8\n! hello\n! codeforces\n? c\n. o\n? d\n? h\n. l\n? e\n", "7\n! ababahalamaha\n? a\n? b\n? a\n? b\n? a\n? h\n", "5\n! abc\n. ad\n. b\n! cd\n? c\n" ], "output": [ "2", "0", "1" ] }
{ "input": [ "3\n. abcdefghijklmnopqrstuvwxy\n? a\n? z\n", "3\n. abcdefghijklmnopqrstuvwxy\n! z\n? z\n", "1\n? q\n", "4\n! abcd\n! cdef\n? d\n? c\n", "15\n. r\n? e\n. s\n. rw\n? y\n. fj\n. zftyd\n? r\n! wq\n? w\n? p\n. ours\n. dto\n. lbyfru\n? q\n" ], "output": [ "1", "1", "0", ...
1,600
500
2
9
926_C. Is This a Zebra?
A camera you have accidentally left in a desert has taken an interesting photo. The photo has a resolution of n pixels width, and each column of this photo is all white or all black. Thus, we can represent the photo as a sequence of n zeros and ones, where 0 means that the corresponding column is all white, and 1 means...
{ "input": [ "9\n1 1 0 1 1 0 1 1 0\n", "8\n1 1 1 0 0 0 1 1\n", "7\n0 0 0 1 1 1 1\n", "9\n0 0 0 1 1 1 0 0 0\n", "5\n1 1 1 1 1\n" ], "output": [ "No\n", "No\n", "No\n", "Yes\n", "Yes\n" ] }
{ "input": [ "7\n0 0 0 1 1 1 0\n", "11\n0 1 0 1 0 1 0 0 0 1 0\n", "5\n1 0 0 0 1\n", "100\n1 1 1 1 0 0 0 0 1 1 1 1 0 0 0 0 1 1 1 1 0 0 0 0 1 1 1 1 0 0 0 0 1 1 1 1 0 0 0 0 1 1 1 1 0 0 0 0 1 1 1 1 0 0 0 0 1 1 1 1 0 0 0 0 1 1 1 1 0 0 0 0 1 1 1 1 0 0 0 0 1 1 1 1 0 0 0 0 1 1 1 1 0 0 0 0 1 1 1 1\n", "2\n...
1,700
0
2
7
955_A. Feed the cat
After waking up at hh:mm, Andrew realised that he had forgotten to feed his only cat for yet another time (guess why there's only one cat). The cat's current hunger level is H points, moreover each minute without food increases his hunger by D points. At any time Andrew can visit the store where tasty buns are sold (y...
{ "input": [ "19 00\n255 1 100 1\n", "17 41\n1000 6 15 11\n" ], "output": [ "25200.0\n", "1365\n" ] }
{ "input": [ "00 10\n33077 21 40 22\n", "17 31\n9603 53 73 74\n", "01 38\n70542 27 74 26\n", "14 53\n76530 92 4 22\n", "18 06\n88580 22 35 59\n", "10 44\n66449 67 90 83\n", "00 00\n100000 100 100 100\n", "20 58\n93398 43 86 99\n", "18 58\n22434 84 91 59\n", "16 34\n61066 14 50 ...
1,100
500
2
9
981_C. Useful Decomposition
Ramesses knows a lot about problems involving trees (undirected connected graphs without cycles)! He created a new useful tree decomposition, but he does not know how to construct it, so he asked you for help! The decomposition is the splitting the edges of the tree in some simple paths in such a way that each two pa...
{ "input": [ "6\n1 2\n2 3\n3 4\n2 5\n3 6\n", "4\n1 2\n2 3\n3 4\n", "5\n1 2\n1 3\n1 4\n1 5\n" ], "output": [ "No\n", "Yes\n1\n1 4\n", "Yes\n4\n1 2\n1 3\n1 4\n1 5\n" ] }
{ "input": [ "9\n1 2\n1 3\n1 4\n1 5\n1 6\n6 7\n7 8\n7 9\n", "8\n1 2\n1 3\n1 4\n1 8\n7 8\n6 8\n5 8\n", "3\n2 3\n1 2\n", "2\n1 2\n" ], "output": [ "No\n", "No\n", "Yes\n1\n1 3\n", "Yes\n1\n1 2\n" ] }
1,400
1,250
2
9
1020_C. Elections
As you know, majority of students and teachers of Summer Informatics School live in Berland for the most part of the year. Since corruption there is quite widespread, the following story is not uncommon. Elections are coming. You know the number of voters and the number of parties β€” n and m respectively. For each vote...
{ "input": [ "1 2\n1 100\n", "5 5\n2 100\n3 200\n4 300\n5 800\n5 900\n", "5 5\n2 100\n3 200\n4 300\n5 400\n5 900\n" ], "output": [ "0\n", "600\n", "500\n" ] }
{ "input": [ "1 3000\n2006 226621946\n", "10 2\n1 1\n1 1\n1 1\n1 1\n1 1\n2 1\n2 1\n2 1\n2 1\n2 1\n", "10 10\n1 73\n2 8\n3 88\n1 5\n2 100\n1 29\n1 57\n3 37\n7 46\n3 21\n", "5 5\n1 3\n1 6\n5 4\n3 7\n2 10\n", "1 3000\n918 548706881\n", "10 10\n7 29\n10 31\n9 40\n5 17\n5 30\n6 85\n2 53\n7 23\n4 57...
1,700
500
2
10
1066_D. Boxes Packing
Maksim has n objects and m boxes, each box has size exactly k. Objects are numbered from 1 to n in order from left to right, the size of the i-th object is a_i. Maksim wants to pack his objects into the boxes and he will pack objects by the following algorithm: he takes one of the empty boxes he has, goes from left to...
{ "input": [ "5 3 3\n1 2 3 1 1\n", "5 1 4\n4 2 3 4 1\n", "5 2 6\n5 2 1 4 2\n" ], "output": [ "5", "1", "4" ] }
{ "input": [ "5 4 2\n1 2 1 2 1\n", "5 5 5\n5 5 5 5 5\n", "1 1 1\n1\n" ], "output": [ "4", "5", "1" ] }
1,800
0
2
13
1089_G. Guest Student
Berland State University invites people from all over the world as guest students. You can come to the capital of Berland and study with the best teachers in the country. Berland State University works every day of the week, but classes for guest students are held on the following schedule. You know the sequence of se...
{ "input": [ "3\n2\n0 1 0 0 0 0 0\n100000000\n1 0 0 0 1 0 1\n1\n1 0 0 0 0 0 0\n" ], "output": [ "8\n233333332\n1\n" ] }
{ "input": [ "1\n13131313\n1 0 1 0 1 1 1\n" ], "output": [ "18383837\n" ] }
1,500
0
2
8
1108_B. Divisors of Two Integers
Recently you have received two positive integer numbers x and y. You forgot them, but you remembered a shuffled list containing all divisors of x (including 1 and x) and all divisors of y (including 1 and y). If d is a divisor of both numbers x and y at the same time, there are two occurrences of d in the list. For ex...
{ "input": [ "10\n10 2 8 1 2 4 1 20 4 5\n" ], "output": [ "20 8\n" ] }
{ "input": [ "4\n1 2 53 1\n", "6\n1 58 29 1 2 2\n", "6\n29 29 1 1 58 2\n", "9\n7 49 1 1 98 14 49 7 2\n", "3\n1 2 1\n", "3\n5 1 1\n", "6\n1 2 4 8 1 16\n", "18\n10 1 4 5 20 10 40 16 20 8 2 5 8 40 2 80 1 4\n", "5\n7 49 2 1 1\n", "6\n6 1 3 3 2 1\n", "8\n9 9 1 81 3 27 1 3\n", ...
1,100
0
2
9
1178_C. Tiles
Bob is decorating his kitchen, more precisely, the floor. He has found a prime candidate for the tiles he will use. They come in a simple form factor β€” a square tile that is diagonally split into white and black part as depicted in the figure below. <image> The dimension of this tile is perfect for this kitchen, as h...
{ "input": [ "2 4\n", "2 2\n" ], "output": [ "64\n", "16\n" ] }
{ "input": [ "2 1\n", "2 3\n", "17 23\n", "2 5\n", "1 1000\n", "3 16\n", "843 134\n", "1000 1000\n", "15 22\n", "1 2\n", "1 1\n", "912 584\n", "432 333\n", "20 10\n", "88 88\n", "1000 122\n" ], "output": [ "8\n", "32\n", "444595123\n", ...
1,300
1,250
2
10
1213_D2. Equalizing by Division (hard version)
The only difference between easy and hard versions is the number of elements in the array. You are given an array a consisting of n integers. In one move you can choose any a_i and divide it by 2 rounding down (in other words, in one move you can set a_i := ⌊(a_i)/(2)βŒ‹). You can perform such an operation any (possibl...
{ "input": [ "5 3\n1 2 3 3 3\n", "5 3\n1 2 3 4 5\n", "5 3\n1 2 2 4 5\n" ], "output": [ "0\n", "2\n", "1\n" ] }
{ "input": [ "50 7\n199961 199990 199995 199997 199963 199995 199985 199994 199974 199974 199997 199991 199993 199982 199991 199982 199963 200000 199994 199997 199963 199991 199947 199996 199994 199995 199995 199990 199972 199973 199980 199955 199984 199998 199998 199992 199986 199986 199997 199995 199987 199958 ...
1,600
0
2
10
1278_D. Segment Tree
As the name of the task implies, you are asked to do some work with segments and trees. Recall that a tree is a connected undirected graph such that there is exactly one simple path between every pair of its vertices. You are given n segments [l_1, r_1], [l_2, r_2], ..., [l_n, r_n], l_i < r_i for every i. It is guara...
{ "input": [ "5\n5 8\n3 6\n2 9\n7 10\n1 4\n", "5\n1 3\n2 4\n5 9\n6 8\n7 10\n", "6\n9 12\n2 11\n1 3\n6 10\n5 7\n4 8\n" ], "output": [ "NO\n", "NO\n", "YES\n" ] }
{ "input": [ "4\n1 2\n3 6\n4 7\n5 8\n", "8\n2 16\n7 13\n12 14\n4 15\n8 9\n1 11\n3 6\n5 10\n", "5\n4 6\n2 5\n3 9\n8 10\n1 7\n", "5\n1 4\n2 5\n3 10\n6 8\n7 9\n", "6\n9 12\n2 3\n6 10\n4 7\n1 5\n8 11\n", "6\n1 3\n2 10\n8 11\n4 12\n5 7\n6 9\n", "6\n4 11\n1 5\n7 9\n2 12\n6 8\n3 10\n", "4\n1 ...
2,100
0
2
7
1299_A. Anu Has a Function
Anu has created her own function f: f(x, y) = (x | y) - y where | denotes the [bitwise OR operation](https://en.wikipedia.org/wiki/Bitwise_operation#OR). For example, f(11, 6) = (11|6) - 6 = 15 - 6 = 9. It can be proved that for any nonnegative numbers x and y value of f(x, y) is also nonnegative. She would like to r...
{ "input": [ "1\n13\n", "4\n4 0 11 6\n" ], "output": [ "13\n", "11 4 0 6\n" ] }
{ "input": [ "10\n268439624 335544469 2491136 151142938 168395872 536905856 17833986 35939360 617678852 13111553\n", "4\n4 0 11 6\n", "5\n315479581 954336048 124252105 880492165 179952043\n", "10\n268439624 335544469 2491136 151142938 168395872 536905856 17833986 35939360 617678852 13111553\n", "5...
1,500
500
2
11
1321_E. World of Darkraft: Battle for Azathoth
Roma is playing a new expansion for his favorite game World of Darkraft. He made a new character and is going for his first grind. Roma has a choice to buy exactly one of n different weapons and exactly one of m different armor sets. Weapon i has attack modifier a_i and is worth ca_i coins, and armor set j has defense...
{ "input": [ "2 3 3\n2 3\n4 7\n2 4\n3 2\n5 11\n1 2 4\n2 1 6\n3 4 6\n" ], "output": [ "1\n" ] }
{ "input": [ "4 4 5\n5 10\n6 2\n10 3\n9 5\n7 7\n4 3\n9 2\n3 6\n7 1 6\n8 3 2\n2 6 9\n3 8 2\n1 2 9\n", "1 1 1\n1 100\n1 100\n2 2 1\n", "1 2 1\n2 2\n2 1\n2 2\n1 1 1\n", "3 3 3\n6 1010\n9 1153\n9 1159\n9 1150\n7 1058\n9 1159\n7 3 172\n10 3 167\n6 6 160\n", "10 10 10\n51 87\n68 743\n82 1284\n73 936\n55...
2,000
1,500
2
10
1362_D. Johnny and Contribution
Today Johnny wants to increase his contribution. His plan assumes writing n blogs. One blog covers one topic, but one topic can be covered by many blogs. Moreover, some blogs have references to each other. Each pair of blogs that are connected by a reference has to cover different topics because otherwise, the readers ...
{ "input": [ "5 3\n1 2\n2 3\n4 5\n2 1 2 2 1\n", "3 3\n1 2\n2 3\n3 1\n1 1 1\n", "3 3\n1 2\n2 3\n3 1\n2 1 3\n" ], "output": [ "2 5 1 3 4 ", "-1\n", "2 1 3 " ] }
{ "input": [ "5 10\n1 3\n4 1\n1 2\n1 5\n3 4\n3 2\n5 2\n4 2\n3 5\n4 5\n3 5 2 1 4\n", "4 3\n1 2\n2 3\n3 4\n1 3 3 1\n", "5 3\n1 3\n2 3\n4 2\n1 2 3 1 4\n", "4 4\n1 2\n1 3\n2 4\n3 4\n1 2 2 3\n", "8 4\n1 6\n1 3\n2 6\n4 7\n2 2 1 1 1 1 2 1\n", "5 4\n1 2\n5 2\n5 3\n1 5\n1 3 1 1 2\n", "10 20\n8 9\n2...
1,700
500
2
11
1382_E. Mastermind
In the game of Mastermind, there are two players β€” Alice and Bob. Alice has a secret code, which Bob tries to guess. Here, a code is defined as a sequence of n colors. There are exactly n+1 colors in the entire universe, numbered from 1 to n+1 inclusive. When Bob guesses a code, Alice tells him some information about ...
{ "input": [ "7\n5 2 4\n3 1 1 2 5\n5 3 4\n1 1 2 1 2\n4 0 4\n5 5 3 3\n4 1 4\n2 3 2 3\n6 1 2\n3 2 1 1 1 1\n6 2 4\n3 3 2 1 1 1\n6 2 6\n1 1 3 2 1 1\n" ], "output": [ "YES\n5 1 1 4 2 \nYES\n3 1 1 1 2 \nYES\n3 3 5 5 \nNO\nYES\n4 4 4 4 3 1 \nYES\n2 1 4 4 1 1 \nYES\n2 3 1 1 1 1 \n" ] }
{ "input": [ "6\n1 0 0\n1\n1 0 0\n2\n1 0 1\n1\n1 0 1\n2\n1 1 1\n1\n1 1 1\n2\n", "7\n5 2 4\n3 1 1 2 5\n5 3 4\n1 1 2 1 2\n4 0 4\n5 5 3 3\n4 1 4\n2 3 2 3\n6 1 2\n3 2 1 1 1 1\n6 2 4\n3 3 2 1 1 1\n6 2 6\n1 1 3 2 1 1\n" ], "output": [ "YES\n2 \nYES\n1 \nNO\nNO\nYES\n1 \nYES\n2 \n", "YES\n5 1 1 4 2 \nYES...
2,500
2,000
2
11
1425_E. Excitation of Atoms
Mr. Chanek is currently participating in a science fair that is popular in town. He finds an exciting puzzle in the fair and wants to solve it. There are N atoms numbered from 1 to N. These atoms are especially quirky. Initially, each atom is in normal state. Each atom can be in an excited. Exciting atom i requires D_...
{ "input": [ "6 1\n5 6 7 8 10 2\n3 5 6 7 1 10\n" ], "output": [ "35\n" ] }
{ "input": [ "4 1\n1 12 13 20\n10 5 4 100\n", "6 1\n1 10 10 5 20 100\n1000000 1 10 10 100 1000000\n", "5 0\n1 1 1 1 1\n10 10 10 10 10\n", "4 3\n1 2 4 8\n5 1 3 5\n", "4 3\n1 2 4 8\n17 15 16 1\n", "6 1\n1 10 10 20 5 100\n1000000 1 10 100 10 1000000\n", "4 2\n1 2 4 8\n1 5 3 5\n", "4 2\n1 ...
2,200
0
2
9
1447_C. Knapsack
You have a knapsack with the capacity of W. There are also n items, the i-th one has weight w_i. You want to put some of these items into the knapsack in such a way that their total weight C is at least half of its size, but (obviously) does not exceed it. Formally, C should satisfy: ⌈ W/2βŒ‰ ≀ C ≀ W. Output the list...
{ "input": [ "3\n1 3\n3\n6 2\n19 8 19 69 9 4\n7 12\n1 1 1 17 1 1 1\n" ], "output": [ "1\n1 \n-1\n6\n1 2 3 5 6 7 \n" ] }
{ "input": [ "2\n1 2000000001\n1000000000\n1 1000000000000000000\n1\n", "3\n1 3\n3\n6 2\n19 8 19 69 9 4\n7 12\n1 1 1 17 1 1 1\n", "1\n1 900000000\n494311454\n", "1\n1 1\n2\n", "1\n1 1\n1\n", "1\n1 2000000001\n1000000000\n" ], "output": [ "-1\n-1\n", "1\n1\n-1\n6\n1 2 3 5 6 7 \n", ...
1,300
500
2
9
1472_C. Long Jumps
Polycarp found under the Christmas tree an array a of n elements and instructions for playing with it: * At first, choose index i (1 ≀ i ≀ n) β€” starting position in the array. Put the chip at the index i (on the value a_i). * While i ≀ n, add a_i to your score and move the chip a_i positions to the right (i.e. r...
{ "input": [ "4\n5\n7 3 1 2 3\n3\n2 1 4\n6\n2 1000 2 3 995 1\n5\n1 1 1 1 1\n" ], "output": [ "\n7\n6\n1000\n5\n" ] }
{ "input": [ "1\n7\n5 1 1 1 1 14 15\n", "2\n3\n1 1 234872\n3\n1 1 234872\n", "1\n4\n100 1 1 200\n", "1\n21\n5 5 5 5 5 5 5 5 5 5 1 1 1 1 2 5 20 1 1 1 1000000\n" ], "output": [ "19\n", "234874\n234874\n", "202\n", "1000005\n" ] }
1,100
0
2
10
1498_D. Bananas in a Microwave
You have a malfunctioning microwave in which you want to put some bananas. You have n time-steps before the microwave stops working completely. At each time-step, it displays a new operation. Let k be the number of bananas in the microwave currently. Initially, k = 0. In the i-th operation, you are given three paramet...
{ "input": [ "3 20\n1 399999 2\n2 412345 2\n1 1000001 3\n", "3 20\n1 300000 2\n2 400000 2\n1 1000000 3\n" ], "output": [ "\n-1 -1 -1 1 -1 -1 -1 1 -1 -1 3 -1 -1 -1 3 -1 2 -1 3 -1 \n", "\n-1 -1 1 -1 -1 1 -1 -1 -1 3 -1 2 3 -1 -1 3 -1 -1 -1 3 \n" ] }
{ "input": [ "3 20\n1 100000 1\n2 200000 1\n2 200000 1\n", "1 10000\n1 1000000 20\n", "1 2\n1 1 1\n", "1 2\n1 1 2\n", "1 10000\n2 1000000 10\n" ], "output": [ "1 2 -1 3 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 \n", "-1 -1 -1 -1 -1 -1 -1 -1 -1 1 -1 -1 -1 -1 -1 -1 -1 -1 -1 1 -1 -1...
2,200
2,500
2
9
1520_C. Not Adjacent Matrix
We will consider the numbers a and b as adjacent if they differ by exactly one, that is, |a-b|=1. We will consider cells of a square matrix n Γ— n as adjacent if they have a common side, that is, for cell (r, c) cells (r, c-1), (r, c+1), (r-1, c) and (r+1, c) are adjacent to it. For a given number n, construct a squar...
{ "input": [ "3\n1\n2\n3\n" ], "output": [ "\n1\n-1\n2 9 7\n4 6 3\n1 8 5\n" ] }
{ "input": [ "3\n1\n2\n3\n", "5\n2\n2\n2\n2\n2\n" ], "output": [ "1\n-1\n1 8 6 \n7 5 3 \n4 2 9 \n", "-1\n-1\n-1\n-1\n-1\n" ] }
1,000
0
2
7
154_A. Hometask
Sergey attends lessons of the N-ish language. Each lesson he receives a hometask. This time the task is to translate some sentence to the N-ish language. Sentences of the N-ish language can be represented as strings consisting of lowercase Latin letters without spaces or punctuation marks. Sergey totally forgot about ...
{ "input": [ "ababa\n1\nab\n", "codeforces\n2\ndo\ncs\n" ], "output": [ "2\n", "1\n" ] }
{ "input": [ "vefneyamdzoytemupniw\n13\nve\nfg\noi\nan\nck\nwx\npq\nml\nbt\nud\nrz\nsj\nhy\n", "pgpgppgggpbbnnn\n2\npg\nnb\n", "mbmxuuuuxuuuuhhooooxxxuxxxuxuuxuuuxxjvjvjjjjvvvjjjjjvvjvjjjvvvjjvjjvvvjjjvjvvjvjjjjjmmbmbbbbbmbbbbmm\n5\nmb\nho\nxu\njv\nyp\n", "eowsgsewestwsootoetteoeeeetwssesstswegswetwet...
1,600
500
2
7
196_A. Lexicographically Maximum Subsequence
You've got string s, consisting of only lowercase English letters. Find its lexicographically maximum subsequence. We'll call a non-empty string s[p1p2... pk] = sp1sp2... spk(1 ≀ p1 < p2 < ... < pk ≀ |s|) a subsequence of string s = s1s2... s|s|. String x = x1x2... x|x| is lexicographically larger than string y = y1y...
{ "input": [ "ababba\n", "abbcbccacbbcbaaba\n" ], "output": [ "bbba\n", "cccccbba\n" ] }
{ "input": [ "b\n", "abcdeabcd\n", "aza\n", "abcdedcba\n", "aa\n", "zzyzyy\n", "cantouristsolveitlessthaninoneminute\n", "aababb\n", "zz\n", "whyareyoulookingfortestsdoyouhavewa\n", "z\n", "arepretestsstrongforthisproblem\n", "zaz\n", "y\n", "a\n", "zyxz...
1,100
500
2
7
21_A. Jabber ID
Jabber ID on the national Berland service Β«BabberΒ» has a form <username>@<hostname>[/resource], where * <username> β€” is a sequence of Latin letters (lowercase or uppercase), digits or underscores characters Β«_Β», the length of <username> is between 1 and 16, inclusive. * <hostname> β€” is a sequence of word separat...
{ "input": [ "mike@codeforces.com\n", "john.smith@codeforces.ru/contest.icpc/12\n" ], "output": [ "YES\n", "NO\n" ] }
{ "input": [ "@ops\n", "xLEctap0T@22U9W_fA/7iQeJGFu1lSgMZ\n", "lNC9D1L5U@.L!_!CcAOEEx.0z.aiW/S430sbQT\n", "test@test.\n", "kKUXy6@0WefbXz39ywP.Q3r7uF\n", "Cz1U1xjg6iW0U@.97HoVA.YG.Qd.eI.DCXxtibi6HG.GV/0sN\n", "IGsma3L6YTJRrXS@1g.yR3mC.c.xoCns7Wo1.9C.Oe.5ebkR/_97Ltj3\n", "aeo2XkK@UX.nQJ...
1,900
500
2
7
269_A. Magical Boxes
Emuskald is a well-known illusionist. One of his trademark tricks involves a set of magical boxes. The essence of the trick is in packing the boxes inside other boxes. From the top view each magical box looks like a square with side length equal to 2k (k is an integer, k β‰₯ 0) units. A magical box v can be put inside a...
{ "input": [ "2\n0 3\n1 5\n", "1\n0 4\n", "2\n1 10\n2 2\n" ], "output": [ "3", "1", "3" ] }
{ "input": [ "10\n11 69\n7 56\n8 48\n2 56\n12 6\n9 84\n1 81\n4 80\n3 9\n5 18\n", "2\n0 16\n1 4\n", "14\n0 268435456\n1 67108864\n2 16777216\n3 4194305\n4 1048576\n5 262144\n6 65536\n7 16384\n8 4096\n9 1024\n10 256\n11 64\n12 16\n13 4\n", "1\n0 268435456\n", "2\n0 13\n1 1\n", "5\n1 1000000\n100...
1,600
500
2
9
291_C. Network Mask
The problem uses a simplified TCP/IP address model, please make sure you've read the statement attentively. Polycarpus has found a job, he is a system administrator. One day he came across n IP addresses. Each IP address is a 32 bit number, represented as a group of four 8-bit numbers (without leading zeroes), separat...
{ "input": [ "5 3\n0.0.0.1\n0.1.1.2\n0.0.2.1\n0.1.1.0\n0.0.2.3\n", "2 1\n255.0.0.1\n0.0.0.2\n", "5 2\n0.0.0.1\n0.1.1.2\n0.0.2.1\n0.1.1.0\n0.0.2.3\n" ], "output": [ "255.255.254.0\n", "-1\n", "255.255.0.0\n" ] }
{ "input": [ "12 5\n211.200.83.75\n9.64.213.241\n143.23.121.155\n212.121.142.193\n24.184.86.27\n176.131.70.228\n64.47.67.24\n255.241.229.181\n246.34.183.253\n65.121.116.178\n76.84.75.89\n22.239.28.119\n", "2 2\n0.0.0.0\n1.0.0.1\n", "5 5\n223.122.75.125\n79.30.187.249\n231.244.158.56\n166.205.237.209\n82.8...
1,600
1,500
2
10
316_D3. PE Lesson
Smart Beaver decided to be not only smart, but also a healthy beaver! And so he began to attend physical education classes at school X. In this school, physical education has a very creative teacher. One of his favorite warm-up exercises is throwing balls. Students line up. Each one gets a single ball in the beginning....
{ "input": [ "8\n1 2 2 1 2 1 1 2\n", "5\n1 2 2 1 2\n" ], "output": [ "16800\n", "120\n" ] }
{ "input": [ "10\n2 2 2 2 2 2 2 2 2 2\n", "100\n2 2 2 2 1 1 2 2 1 2 2 1 1 2 2 2 2 2 2 1 1 2 2 2 2 1 2 1 1 2 2 1 2 2 1 2 2 2 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 1 2 2 2 2 2 1 2 1 1 2 1 1 2 2 2 2 1 2 1 1 2 2 2 2 2 2 2 2 2 2 2 2 2 1 2 2 1 2 2 2 2\n", "2\n2 2\n", "9\n1 1 1 2 2 1 1 1 1\n", "10\n2 2...
2,400
30
2
7
33_A. What is for dinner?
In one little known, but very beautiful country called Waterland, lives a lovely shark Valerie. Like all the sharks, she has several rows of teeth, and feeds on crucians. One of Valerie's distinguishing features is that while eating one crucian she uses only one row of her teeth, the rest of the teeth are "relaxing". ...
{ "input": [ "2 2 13\n1 13\n2 12\n", "4 3 18\n2 3\n1 2\n3 6\n2 3\n" ], "output": [ "13\n", "11\n" ] }
{ "input": [ "10 4 14\n2 6\n1 5\n2 8\n2 6\n2 5\n4 1\n4 0\n2 4\n3 4\n1 0\n", "4 2 8\n1 9\n1 10\n1 4\n2 6\n", "1 1 0\n1 3\n", "5 4 8\n4 6\n4 5\n1 3\n2 0\n3 3\n", "4 3 181818\n3 1299\n1 1694\n3 1164\n2 1278\n", "1 1 1000000\n1 1000000\n", "50 50 0\n33 0\n26 0\n30 0\n41 0\n38 0\n36 0\n16 0\n7 ...
1,200
500