problem_id
stringlengths
32
32
name
stringlengths
2
112
problem
stringlengths
200
14k
test_cases
stringlengths
33
79.2M
difficulty
stringclasses
34 values
language
listlengths
1
1
source
stringclasses
15 values
num_solutions
int64
1
1.12M
starter_code
stringlengths
0
1.47k
subset
stringclasses
4 values
7e625e4a607cb083c6ac116e33b70096
Reflection
For each positive integer *n* consider the integer ψ(*n*) which is obtained from *n* by replacing every digit *a* in the decimal notation of *n* with the digit (9<=<=-<=<=*a*). We say that ψ(*n*) is the reflection of *n*. For example, reflection of 192 equals 807. Note that leading zeros (if any) should be omitted. So ...
{"inputs": ["3 7", "1 1", "8 10", "4 6", "10 100", "1 999", "40 60", "66 74", "27 71", "66 95", "48 51", "9999999 9999999", "555555 555555", "942 572335596", "2331 77424372", "314 592188442", "6277 181089912", "163 306093048", "9265 978077465", "934 300539101", "850 629417171", "9015 34697316", "595 416293084", "3722 8...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
19
codeforces
7e7f3dd7295be10757799855d78df607
Falling Anvils
For some reason in many American cartoons anvils fall from time to time onto heroes' heads. Of course, safes, wardrobes, cruisers, planes fall sometimes too... But anvils do so most of all. Anvils come in different sizes and shapes. Quite often they get the hero stuck deep in the ground. But have you ever thought who ...
{"inputs": ["2\n4 2\n1 2", "90\n1 1\n2 1\n3 1\n4 1\n5 1\n6 1\n7 1\n8 1\n9 1\n1 2\n2 2\n3 2\n4 2\n5 2\n6 2\n7 2\n8 2\n9 2\n1 3\n2 3\n3 3\n4 3\n5 3\n6 3\n7 3\n8 3\n9 3\n1 4\n2 4\n3 4\n4 4\n5 4\n6 4\n7 4\n8 4\n9 4\n1 5\n2 5\n3 5\n4 5\n5 5\n6 5\n7 5\n8 5\n9 5\n1 6\n2 6\n3 6\n4 6\n5 6\n6 6\n7 6\n8 6\n9 6\n1 7\n2 7\n3 7\n4 7...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
8
codeforces
7e867a304eb0618de56b5adeb0adca21
none
Вася купил стол, у которого *n* ножек. Каждая ножка состоит из двух частей, которые соединяются друг с другом. Каждая часть может быть произвольной положительной длины, но гарантируется, что из всех 2*n* частей возможно составить *n* ножек одинаковой длины. При составлении ножки любые две части могут быть соединены дру...
{"inputs": ["3\n1 3 2 4 5 3", "3\n1 1 1 2 2 2", "1\n3 7", "10\n9 13 18 7 18 13 2 2 5 16 3 17 5 4 18 2 15 11 7 15", "10\n759 82 475 841 46 461 288 525 918 241 789 847 58 954 712 159 942 211 153 539", "100\n8 7 7 5 2 7 7 5 1 8 6 3 6 7 2 4 4 2 6 8 5 6 5 2 6 1 3 9 5 8 7 6 5 4 8 6 5 5 3 2 6 5 4 9 7 1 5 7 9 5 7 4 1 6 5 8 2 6...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
27
codeforces
7e9e640b2aa2853e7ba9b99a1f729c44
Spoilt Permutation
Vasya collects coins: he has exactly one coin for every year from 1 to *n*. Naturally, Vasya keeps all the coins in his collection in the order in which they were released. Once Vasya's younger brother made a change — he took all the coins whose release year dated from *l* to *r* inclusively and put them in the reverse...
{"inputs": ["8\n1 6 5 4 3 2 7 8", "4\n2 3 4 1", "4\n1 2 3 4", "8\n1 3 2 4 6 5 7 8", "8\n1 3 4 2 6 5 7 8", "1\n1", "2\n1 2", "2\n2 1", "149\n9 120 122 97 93 70 85 56 102 16 103 112 88 84 118 135 113 62 65 19 89 15 108 73 82 21 147 27 115 130 136 6 1 90 29 94 149 17 53 132 99 123 64 95 71 67 141 126 59 8 10 114 121 134 1...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
48
codeforces
7eb0da0bbbcb2806ed5714ca454320e7
The Meaningless Game
Slastyona and her loyal dog Pushok are playing a meaningless game that is indeed very interesting. The game consists of multiple rounds. Its rules are very simple: in each round, a natural number *k* is chosen. Then, the one who says (or barks) it faster than the other wins the round. After that, the winner's score is...
{"inputs": ["6\n2 4\n75 45\n8 8\n16 16\n247 994\n1000000000 1000000", "3\n1 1\n8 27\n1000 1331", "1\n12004 18012002", "1\n3331 11095561", "1\n2 3", "1\n1062961 1031", "1\n6 12", "1\n3 1", "1\n3 10", "1\n31159 970883281", "1\n9907 98148649", "1\n16 8", "1\n90 72"], "outputs": ["Yes\nYes\nYes\nNo\nNo\nYes", "Yes\nNo\nNo"...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
6
codeforces
7eb8f58de43c50a8d69328b3803bf014
Pizza Separation
Students Vasya and Petya are studying at the BSU (Byteland State University). At one of the breaks they decided to order a pizza. In this problem pizza is a circle of some radius. The pizza was delivered already cut into *n* pieces. The *i*-th piece is a sector of angle equal to *a**i*. Vasya and Petya want to divide a...
{"inputs": ["4\n90 90 90 90", "3\n100 100 160", "1\n360", "4\n170 30 150 10", "5\n10 10 10 10 320", "8\n45 45 45 45 45 45 45 45", "3\n120 120 120", "5\n110 90 70 50 40", "2\n170 190", "15\n25 25 25 25 25 25 25 25 25 25 25 25 25 25 10", "5\n30 60 180 60 30", "2\n359 1", "5\n100 100 30 100 30", "5\n36 34 35 11 244", "5\n...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
146
codeforces
7ed2fb332ead357e5fd2ae9c305aaadf
Cormen --- The Best Friend Of a Man
Recently a dog was bought for Polycarp. The dog's name is Cormen. Now Polycarp has a lot of troubles. For example, Cormen likes going for a walk. Empirically Polycarp learned that the dog needs at least *k* walks for any two consecutive days in order to feel good. For example, if *k*<==<=5 and yesterday Polycarp went...
{"inputs": ["3 5\n2 0 1", "3 1\n0 0 0", "4 6\n2 4 3 5", "5 1\n0 0 0 0 1", "10 500\n164 44 238 205 373 249 87 30 239 90", "1 1\n1", "5 1\n0 0 0 0 0", "5 1\n0 0 0 0 1", "5 2\n0 0 0 1 0", "5 5\n1 4 0 0 0", "5 10\n1 2 1 0 1", "5 10\n0 1 0 1 0", "10 5\n0 2 3 0 0 1 0 2 3 1", "10 1\n0 0 0 0 0 0 0 0 1 0", "10 436\n13 16 45 9 1...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
51
codeforces
7ee0356b1b5e79e1c67200d0c9a585b1
Shortest Path
In Ancient Berland there were *n* cities and *m* two-way roads of equal length. The cities are numbered with integers from 1 to *n* inclusively. According to an ancient superstition, if a traveller visits three cities *a**i*, *b**i*, *c**i* in row, without visiting other cities between them, a great disaster awaits him...
{"inputs": ["4 4 1\n1 2\n2 3\n3 4\n1 3\n1 4 3", "3 1 0\n1 2", "4 4 2\n1 2\n2 3\n3 4\n1 3\n1 2 3\n1 3 4", "4 4 1\n1 2\n2 3\n3 4\n1 3\n1 2 3", "2 1 0\n1 2", "4 4 1\n1 2\n2 3\n3 4\n1 3\n1 3 4", "3 2 0\n1 2\n3 2", "3 2 1\n1 2\n3 2\n1 2 3", "4 4 4\n1 2\n2 3\n3 4\n1 3\n1 2 3\n1 3 4\n1 2 4\n1 3 2"], "outputs": ["2\n1 3 4", "-...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
7
codeforces
7f06cf906d3c851d618076732c708a09
Patrick and Shopping
Today Patrick waits for a visit from his friend Spongebob. To prepare for the visit, Patrick needs to buy some goodies in two stores located near his house. There is a *d*1 meter long road between his house and the first shop and a *d*2 meter long road between his house and the second shop. Also, there is a road of len...
{"inputs": ["10 20 30", "1 1 5", "100 33 34", "777 777 777", "2 2 8", "12 34 56", "789 101112 131415", "27485716 99999999 35182", "1 293548 5", "12059 259855 5874875", "46981 105809 585858", "9889 1221 2442", "100500 200600 300700", "318476 318476 318476", "23985 3353 75633", "120 1298 2222", "98437 23487 666672", "100...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
512
codeforces
7f638bd6b5c442a8088b1872b76c3ff9
Flags
When Igor K. was a freshman, his professor strictly urged him, as well as all other freshmen, to solve programming Olympiads. One day a problem called "Flags" from a website called Timmy's Online Judge caught his attention. In the problem one had to find the number of three-colored flags that would satisfy the conditio...
{"inputs": ["3 4", "5 6", "3 3", "3 5", "3 6", "3 7", "3 8", "3 9", "3 10", "3 100", "1 1", "1 2", "1 3", "1 4", "2 2", "2 3", "2 4", "4 4", "1 1000000000", "2 1000000000", "3 1000000000", "4 1000000000", "999999998 1000000000", "999999999 1000000000", "1000000000 1000000000", "9 30", "3 47", "9 47", "8 36", "8 37", "8...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1
codeforces
7f642d29a6523b89764d5462b24da7b5
Garland
Once little Vasya read an article in a magazine on how to make beautiful handmade garland from colored paper. Vasya immediately went to the store and bought *n* colored sheets of paper, the area of each sheet is 1 square meter. The garland must consist of exactly *m* pieces of colored paper of arbitrary area, each pie...
{"inputs": ["aaabbac\naabbccac", "a\nz", "r\nr", "stnsdn\nndnndsn", "yqfqfp\ntttwtqq", "zzbbrrtrtzr\ntbbtrrrzr", "ivvfisvsvii\npaihjinno", "zbvwnlgkshqerxptyod\nz", "xlktwjymocqrahnbesf\nfoo", "bbzmzqazmbambnmzaabznmbabzqnaabmabmnnabbmnzaanzzezebzabqaabzqaemeqqammmbazmmz\naznnbbmeebmanbeemzmemqbaeebnqenqzzbanebmnzqqebq...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
150
codeforces
7f7795304e826b9b5db2579af029fffb
Literature Lesson
Vera adores poems. All the poems Vera knows are divided into quatrains (groups of four lines) and in each quatrain some lines contain rhymes. Let's consider that all lines in the poems consist of lowercase Latin letters (without spaces). Letters "a", "e", "i", "o", "u" are considered vowels. Two lines rhyme if their ...
{"inputs": ["1 1\nday\nmay\nsun\nfun", "1 1\nday\nmay\ngray\nway", "2 1\na\na\na\na\na\na\ne\ne", "2 1\nday\nmay\nsun\nfun\ntest\nhill\nfest\nthrill", "2 5\na\na\na\na\na\na\ne\ne", "1 1\nrezwbgy\nxakgmv\njogezwbgy\napezwbgy", "2 1\nnuqfxwrb\napqfkw\nuqfxwrb\nnhcuqfxwrb\nogkznwncmt\nevf\nogkznwncmt\nogkznwncmt", "1 1\n...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
6
codeforces
7fb1f4b5006d1f42e41292d10c218c31
Weird Subtraction Process
You have two variables *a* and *b*. Consider the following sequence of actions performed with these variables: 1. If *a*<==<=0 or *b*<==<=0, end the process. Otherwise, go to step 2;1. If *a*<=≥<=2·*b*, then set the value of *a* to *a*<=-<=2·*b*, and repeat step 1. Otherwise, go to step 3;1. If *b*<=≥<=2·*a*, then s...
{"inputs": ["12 5", "31 12", "1000000000000000000 7", "31960284556200 8515664064180", "1000000000000000000 1000000000000000000", "1 1000", "1 1000000", "1 1000000000000000", "1 99999999999999999", "1 4", "1000000000000001 500000000000000", "1 1000000000000000000", "2 4", "2 1", "6 19", "22 5", "10000000000000000 100000...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
98
codeforces
7fc45e96c02615a2cc4a675cddd533b0
Fountains
Arkady plays Gardenscapes a lot. Arkady wants to build two new fountains. There are *n* available fountains, for each fountain its beauty and cost are known. There are two types of money in the game: coins and diamonds, so each fountain cost can be either in coins or diamonds. No money changes between the types are all...
{"inputs": ["3 7 6\n10 8 C\n4 3 C\n5 6 D", "2 4 5\n2 5 C\n2 1 D", "3 10 10\n5 5 C\n5 5 C\n10 11 D", "6 68 40\n1 18 D\n6 16 D\n11 16 D\n7 23 D\n16 30 D\n2 20 D", "6 4 9\n6 6 D\n1 4 D\n6 7 C\n7 6 D\n5 7 D\n2 5 D", "52 38 22\n9 25 D\n28 29 C\n29 25 D\n4 28 D\n23 29 D\n24 25 D\n17 12 C\n11 19 C\n13 14 C\n12 15 D\n7 25 C\n2...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
9
codeforces
7fe9b3c996302555cb30ddbb77124d9e
Unsolvable
Consider the following equation: Let's find all integer *z* (*z*<=&gt;<=0), for which this equation is unsolvable in positive integers. The phrase "unsolvable in positive integers" means that there are no such positive integers *x* and *y* (*x*,<=*y*<=&gt;<=0), for which the given above equation holds. Let's write o...
{"inputs": ["1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31", "32", "33", "34", "35", "36", "37", "38", "39", "40"], "outputs": ["1", "3", "15", "63", "4095", "65535", "262143", "73741816", "53...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
5
codeforces
8031d3ee80b63cbdd0fc081c9cee561f
Ilya and Queries
Ilya the Lion wants to help all his friends with passing exams. They need to solve the following problem to pass the IT exam. You've got string *s*<==<=*s*1*s*2... *s**n* (*n* is the length of the string), consisting only of characters "." and "#" and *m* queries. Each query is described by a pair of integers *l**i*,<...
{"inputs": ["......\n4\n3 4\n2 3\n1 6\n2 6", "#..###\n5\n1 3\n5 6\n1 5\n3 6\n3 4", ".#...#..\n6\n1 5\n2 3\n6 7\n2 4\n2 5\n1 3", "#.#.#..\n5\n3 4\n4 5\n5 7\n5 7\n1 3", "#.##.##.\n7\n1 8\n2 6\n2 6\n6 8\n3 5\n2 4\n2 5", "#..#\n1\n1 4", "#..##...#.\n7\n5 9\n6 10\n1 7\n5 8\n3 5\n2 10\n3 4", "#.#.#\n7\n1 2\n3 4\n3 5\n2 3\n3 ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
204
codeforces
80349b15c8104db3dc055c860f58511a
Maze 2D
The last product of the R2 company in the 2D games' field is a new revolutionary algorithm of searching for the shortest path in a 2<=×<=*n* maze. Imagine a maze that looks like a 2<=×<=*n* rectangle, divided into unit squares. Each unit square is either an empty cell or an obstacle. In one unit of time, a person can ...
{"inputs": ["4 7\n.X..\n...X\n5 1\n1 3\n7 7\n1 4\n6 1\n4 7\n5 7", "10 3\nX...X..X..\n..X...X..X\n11 7\n7 18\n18 10", "1 1\n.\n.\n1 2", "2 1\n..\n.X\n1 2", "2 1\n..\nX.\n1 2", "2 1\n..\nX.\n1 4", "2 1\n.X\n..\n1 4", "2 1\nX.\n..\n2 3", "2 1\n..\n.X\n3 2"], "outputs": ["1\n4\n0\n5\n2\n2\n2", "9\n-1\n3", "1", "1", "1", "2...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1
codeforces
8064634d8049cafb0812bc65774e8736
Interesting Game
Two best friends Serozha and Gena play a game. Initially there is one pile consisting of *n* stones on the table. During one move one pile should be taken and divided into an arbitrary number of piles consisting of *a*1<=&gt;<=*a*2<=&gt;<=...<=&gt;<=*a**k*<=&gt;<=0 stones. The piles should meet the condition *a*1<=-<=...
{"inputs": ["3", "6", "100", "33", "23", "35", "15", "99", "46", "78", "627", "250", "873", "871", "684", "303", "93764", "39509", "70878", "7578", "31893", "57113", "66873", "9564", "42237", "92763", "38798", "63359", "573", "60879", "67341", "15748", "42602", "67817", "81207", "8149", "95298", "41385", "27443", "7442...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
2
codeforces
807c274c38b88f13353f30a0b0a62af6
Discounts
One day Polycarpus stopped by a supermarket on his way home. It turns out that the supermarket is having a special offer for stools. The offer is as follows: if a customer's shopping cart contains at least one stool, the customer gets a 50% discount on the cheapest item in the cart (that is, it becomes two times cheape...
{"inputs": ["3 2\n2 1\n3 2\n3 1", "4 3\n4 1\n1 2\n2 2\n3 2", "1 1\n1 1", "1 1\n1 2", "10 1\n1 1\n2 2\n1 1\n23 2\n17 2\n1 1\n1 1\n30 2\n1 1\n9 2", "11 11\n6 2\n6 2\n1 2\n2 2\n3 1\n6 2\n1 1\n1 1\n3 1\n3 1\n6 2", "5 4\n24 1\n19 1\n28 2\n7 1\n23 2", "20 3\n28 1\n786180179 2\n16 1\n617105650 2\n23 1\n21 1\n22 1\n7 1\n314215...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
3
codeforces
80986378f9ecabb610182e9e01ee76c7
Reconnaissance 2
*n* soldiers stand in a circle. For each soldier his height *a**i* is known. A reconnaissance unit can be made of such two neighbouring soldiers, whose heights difference is minimal, i.e. |*a**i*<=-<=*a**j*| is minimal. So each of them will be less noticeable with the other. Output any pair of soldiers that can form a ...
{"inputs": ["5\n10 12 13 15 10", "4\n10 20 30 40", "6\n744 359 230 586 944 442", "5\n826 747 849 687 437", "5\n999 999 993 969 999", "5\n4 24 6 1 15", "2\n511 32", "3\n907 452 355", "4\n303 872 764 401", "10\n684 698 429 694 956 812 594 170 937 764", "20\n646 840 437 946 640 564 936 917 487 752 844 734 468 969 674 646 ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
529
codeforces
80a02d317a162a555112fead914c31e1
Making Sequences is Fun
We'll define *S*(*n*) for positive integer *n* as follows: the number of the *n*'s digits in the decimal base. For example, *S*(893)<==<=3, *S*(114514)<==<=6. You want to make a consecutive integer sequence starting from number *m* (*m*,<=*m*<=+<=1,<=...). But you need to pay *S*(*n*)·*k* to add the number *n* to the ...
{"inputs": ["9 1 1", "77 7 7", "114 5 14", "1 1 2", "462 183 8", "462 183 8", "462 183 8", "462 183 8", "462 183 8", "462 183 8", "462 183 8", "10000000000000000 1 1", "2155990066796462 2710473050636183 563261158", "552719169048748 7822730034794389 374302919", "6895788044242644 3474119895793364 732614708", "92305738044...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
38
codeforces
80cc5107e71a2f8ed4a0a93bc8680d56
Reorder the Array
You are given an array of integers. Vasya can permute (change order) its integers. He wants to do it so that as many as possible integers will become on a place where a smaller integer used to stand. Help Vasya find the maximal number of such integers. For instance, if we are given an array $[10, 20, 30, 40]$, we can ...
{"inputs": ["7\n10 1 1 1 5 5 3", "5\n1 1 1 1 1", "6\n300000000 200000000 300000000 200000000 1000000000 300000000", "10\n1 2 3 4 5 6 7 8 9 10", "1\n1", "7\n3 5 2 2 5 2 4", "5\n1 5 4 2 3"], "outputs": ["4", "0", "3", "9", "0", "4", "4"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
147
codeforces
80cfb08e92b0510fb8ce855b2eaa7382
Phone Code
Polycarpus has *n* friends in Tarasov city. Polycarpus knows phone numbers of all his friends: they are strings *s*1,<=*s*2,<=...,<=*s**n*. All these strings consist only of digits and have the same length. Once Polycarpus needed to figure out Tarasov city phone code. He assumed that the phone code of the city is the...
{"inputs": ["4\n00209\n00219\n00999\n00909", "2\n1\n2", "3\n77012345678999999999\n77012345678901234567\n77012345678998765432", "5\n4491183345\n4491184811\n4491162340\n4491233399\n4491449214", "10\n15424\n10953\n19176\n15514\n16284\n18680\n19305\n13816\n16168\n15924", "10\n4906361343\n8985777485\n1204265609\n7088384855\...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
212
codeforces
80d30acd3149e5f80f5e75a75d506b79
Developing Skills
Petya loves computer games. Finally a game that he's been waiting for so long came out! The main character of this game has *n* different skills, each of which is characterized by an integer *a**i* from 0 to 100. The higher the number *a**i* is, the higher is the *i*-th skill of the character. The total rating of the ...
{"inputs": ["2 4\n7 9", "3 8\n17 15 19", "2 2\n99 100", "100 10000\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 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", "100 10000\n100 100 100 100 100 100 100 100 100 10...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
5
codeforces
80f7124129b659f8bb7de526beeedbb7
Three-level Laser
An atom of element X can exist in *n* distinct states with energies *E*1<=&lt;<=*E*2<=&lt;<=...<=&lt;<=*E**n*. Arkady wants to build a laser on this element, using a three-level scheme. Here is a simplified description of the scheme. Three distinct states *i*, *j* and *k* are selected, where *i*<=&lt;<=*j*<=&lt;<=*k*...
{"inputs": ["4 4\n1 3 5 7", "10 8\n10 13 15 16 17 19 20 22 24 25", "3 1\n2 5 10", "5 3\n4 6 8 9 10", "10 128\n110 121 140 158 174 188 251 271 272 277", "20 17\n104 107 121 131 138 140 143 144 178 192 193 198 201 206 238 242 245 248 255 265", "30 23\n102 104 105 107 108 109 110 111 116 118 119 122 127 139 140 142 145 15...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
41
codeforces
8116b0c6c5a9ed18caa329c931d33990
Two Tables
You've got two rectangular tables with sizes *n**a*<=×<=*m**a* and *n**b*<=×<=*m**b* cells. The tables consist of zeroes and ones. We will consider the rows and columns of both tables indexed starting from 1. Then we will define the element of the first table, located at the intersection of the *i*-th row and the *j*-t...
{"inputs": ["3 2\n01\n10\n00\n2 3\n001\n111", "3 3\n000\n010\n000\n1 1\n1", "2 4\n1010\n0011\n5 5\n01100\n01110\n00111\n00110\n00110", "3 1\n0\n1\n0\n2 2\n11\n00", "1 5\n00110\n5 2\n11\n00\n01\n01\n11", "2 2\n11\n01\n2 2\n10\n11", "12 3\n111\n001\n101\n101\n010\n101\n110\n110\n101\n001\n010\n110\n1 26\n1101011001000011...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1
codeforces
81263fa7374bfd7992ffb8b4bd99174b
Coloring Trees
ZS the Coder and Chris the Baboon has arrived at Udayland! They walked in the park where *n* trees grow. They decided to be naughty and color the trees in the park. The trees are numbered with integers from 1 to *n* from left to right. Initially, tree *i* has color *c**i*. ZS the Coder and Chris the Baboon recognizes ...
{"inputs": ["3 2 2\n0 0 0\n1 2\n3 4\n5 6", "3 2 2\n2 1 2\n1 3\n2 4\n3 5", "3 2 2\n2 0 0\n1 3\n2 4\n3 5", "3 2 3\n2 1 2\n1 3\n2 4\n3 5", "3 2 3\n0 0 0\n10 30000\n20000 1000000000\n1000000000 50000", "4 2 1\n0 0 0 0\n10 30000\n20000 1000000000\n1000000000 50000\n55 55", "4 2 1\n0 0 0 2\n10 30000\n20000 1000000000\n100000...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
14
codeforces
81530ac1defad51d6b2ce6a51a25f966
Art Union
A well-known art union called "Kalevich is Alive!" manufactures objects d'art (pictures). The union consists of *n* painters who decided to organize their work as follows. Each painter uses only the color that was assigned to him. The colors are distinct for all painters. Let's assume that the first painter uses color...
{"inputs": ["5 1\n1\n2\n3\n4\n5", "4 2\n2 5\n3 1\n5 3\n10 1", "1 1\n66", "2 2\n1 1\n1 1", "2 2\n10 1\n10 1", "1 5\n1 95 44 14 35", "7 1\n80\n92\n24\n88\n40\n45\n7", "1 2\n51 44", "2 1\n19\n4", "2 2\n1 10\n1 1", "3 3\n3 9 4\n5 10 8\n4 4 7", "10 3\n6 10 3\n2 7 9\n10 4 7\n6 3 4\n6 2 6\n8 4 4\n5 9 8\n6 9 7\n2 7 10\n2 6 2"]...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
134
codeforces
815ad2e108b5611d42ee9b719310028e
Anton and Making Potions
Anton is playing a very interesting computer game, but now he is stuck at one of the levels. To pass to the next level he has to prepare *n* potions. Anton has a special kettle, that can prepare one potions in *x* seconds. Also, he knows spells of two types that can faster the process of preparing potions. 1. Spells...
{"inputs": ["20 3 2\n10 99\n2 4 3\n20 10 40\n4 15\n10 80", "20 3 2\n10 99\n2 4 3\n200 100 400\n4 15\n100 800", "10 3 3\n10 33\n1 7 6\n17 25 68\n2 9 10\n78 89 125", "94 1 1\n26 324\n7\n236\n77\n5", "3 4 5\n5 9\n1 2 1 1\n3 5 4 1\n1 1 1 1 3\n1 2 3 4 5", "1 4 2\n3 10\n2 1 1 1\n1 5 3 5\n1 1\n1 5", "5 3 3\n4 4\n2 3 1\n1 3 1\...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1
codeforces
816c9f5df0e4959202f07bb94b561c90
Ghosts
Ghosts live in harmony and peace, they travel the space without any purpose other than scare whoever stands in their way. There are $n$ ghosts in the universe, they move in the $OXY$ plane, each one of them has its own velocity that does not change in time: $\overrightarrow{V} = V_{x}\overrightarrow{i} + V_{y}\overrig...
{"inputs": ["4 1 1\n1 -1 -1\n2 1 1\n3 1 1\n4 -1 -1", "3 1 0\n-1 1 0\n0 0 -1\n1 -1 -2", "3 1 0\n0 0 0\n1 0 0\n2 0 0", "10 7 -626288749\n795312099 49439844 266151109\n-842143911 23740808 624973405\n-513221420 -44452680 -391096559\n-350963348 -5068756 -160670209\n690883790 11897718 3356227\n-509035268 -45646185 -210137445...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
23
codeforces
819e473a539eec5cf984f904af5fbdfa
Bicycle Race
Maria participates in a bicycle race. The speedway takes place on the shores of Lake Lucerne, just repeating its contour. As you know, the lake shore consists only of straight sections, directed to the north, south, east or west. Let's introduce a system of coordinates, directing the *Ox* axis from west to east, and ...
{"inputs": ["6\n0 0\n0 1\n1 1\n1 2\n2 2\n2 0\n0 0", "16\n1 1\n1 5\n3 5\n3 7\n2 7\n2 9\n6 9\n6 7\n5 7\n5 3\n4 3\n4 4\n3 4\n3 2\n5 2\n5 1\n1 1", "4\n-10000 -10000\n-10000 10000\n10000 10000\n10000 -10000\n-10000 -10000", "4\n6 8\n6 9\n7 9\n7 8\n6 8", "8\n-10000 -10000\n-10000 5000\n0 5000\n0 10000\n10000 10000\n10000 0\n...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
88
codeforces
81cbf25d21c00e543382dbf2b0b24f1e
Group Projects
There are *n* students in a class working on group projects. The students will divide into groups (some students may be in groups alone), work on their independent pieces, and then discuss the results together. It takes the *i*-th student *a**i* minutes to finish his/her independent piece. If students work at differen...
{"inputs": ["3 2\n2 4 5", "4 3\n7 8 9 10", "4 0\n5 10 20 21", "20 1000\n50 50 100 100 150 150 200 200 250 250 300 300 350 350 400 400 450 450 500 500", "5 222\n58 369 477 58 90", "9 222\n304 142 38 334 73 122 252 381 438", "9 247\n359 350 140 26 293 488 57 481 71", "5 341\n412 32 189 303 172", "200 0\n1 1 1 1 1 1 1 1 1...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
3
codeforces
81d086a4bed9b7676ed89bd1eeb0eb3c
Row
You're given a row with $n$ chairs. We call a seating of people "maximal" if the two following conditions hold: 1. There are no neighbors adjacent to anyone seated. 1. It's impossible to seat one more person without violating the first rule. The seating is given as a string consisting of zeros and ones ($0$ means t...
{"inputs": ["3\n101", "4\n1011", "5\n10001", "1\n0", "1\n1", "100\n0101001010101001010010010101001010100101001001001010010101010010101001001010101001001001010100101010", "4\n0100", "42\n011000100101001001101011011010100010011010", "3\n001", "64\n1001001010010010100101010010010100100101001001001001010100101001", "3\n111...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
73
codeforces
81ef12c3e4dd0f375966669533bed4fb
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 ...
{"inputs": ["3 3", "3 4", "5 3", "9 9", "3 5", "3 6", "7 3", "7 4", "49 50", "43 50", "43 27", "11 15", "11 3", "19 3", "23 50", "49 49", "33 43", "33 44", "45 45", "45 49", "45 3", "45 4", "5 4", "5 5", "5 6", "7 5", "7 6", "7 7"], "outputs": ["###\n..#\n###", "####\n...#\n####", "###\n..#\n###\n#..\n###", "#########\...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
555
codeforces
81f36a32b0401ec92d93c3f0c7e94903
New Year and Days
Today is Wednesday, the third day of the week. What's more interesting is that tomorrow is the last day of the year 2015. Limak is a little polar bear. He enjoyed this year a lot. Now, he is so eager to the coming year 2016. Limak wants to prove how responsible a bear he is. He is going to regularly save candies for ...
{"inputs": ["4 of week", "30 of month", "17 of month", "31 of month", "6 of week", "1 of week", "2 of week", "3 of week", "5 of week", "7 of week", "1 of month", "2 of month", "3 of month", "4 of month", "5 of month", "6 of month", "7 of month", "8 of month", "9 of month", "10 of month", "11 of month", "12 of month", "...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
179
codeforces
81ffdfad6d7493a8b3a4d2449992fef7
Gravity Flip
Little Chris is bored during his physics lessons (too easy), so he has built a toy box to keep himself occupied. The box is special, since it has the ability to change gravity. There are *n* columns of toy cubes in the box arranged in a line. The *i*-th column contains *a**i* cubes. At first, the gravity in the box is...
{"inputs": ["4\n3 2 1 2", "3\n2 3 8", "5\n2 1 2 1 2", "1\n1", "2\n4 3", "6\n100 40 60 20 1 80", "10\n10 8 6 7 5 3 4 2 9 1", "10\n1 2 3 4 5 6 7 8 9 10", "100\n82 51 81 14 37 17 78 92 64 15 8 86 89 8 87 77 66 10 15 12 100 25 92 47 21 78 20 63 13 49 41 36 41 79 16 87 87 69 3 76 80 60 100 49 70 59 72 8 38 71 45 97 71 14 76...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
540
codeforces
820b4ef0d5db2fef6bd88e9befb86b13
Suffix Structures
Bizon the Champion isn't just a bison. He also is a favorite of the "Bizons" team. At a competition the "Bizons" got the following problem: "You are given two distinct words (strings of English letters), *s* and *t*. You need to transform word *s* into word *t*". The task looked simple to the guys because they know th...
{"inputs": ["automaton\ntomat", "array\narary", "both\nhot", "need\ntree", "abacaba\naaaa", "z\nzz", "itwtyhhsdjjffmmoqkkhxjouypznewstyorotxhozlytndehmaxogrohccnqcgkrjrdmnuaogiwmnmsbdaizqkxnkqxxiihbwepc\nsnixfywvcntitcefsgqxjcodwtumurcglfmnamnowzbjzmfzspbfuldraiepeeiyasmrsneekydsbvazoqszyjxkjiotushsddet", "y\nu", "nbji...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
65
codeforces
8214a4b1281a44c4db1dc7d3160030f4
Bits
Let's denote as 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 is maximum possible. If there are multiple such numbers find the...
{"inputs": ["3\n1 2\n2 4\n1 10", "55\n1 1\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n2 2\n2 3\n2 4\n2 5\n2 6\n2 7\n2 8\n2 9\n2 10\n3 3\n3 4\n3 5\n3 6\n3 7\n3 8\n3 9\n3 10\n4 4\n4 5\n4 6\n4 7\n4 8\n4 9\n4 10\n5 5\n5 6\n5 7\n5 8\n5 9\n5 10\n6 6\n6 7\n6 8\n6 9\n6 10\n7 7\n7 8\n7 9\n7 10\n8 8\n8 9\n8 10\n9 9\n9 10\n10 ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
79
codeforces
82158427dab9826528da173c784a2c45
Greg and Graph
Greg has a weighed directed graph, consisting of *n* vertices. In this graph any pair of distinct vertices has an edge between them in both directions. Greg loves playing with the graph and now he has invented a new game: - The game consists of *n* steps. - On the *i*-th step Greg removes vertex number *x**i* from t...
{"inputs": ["1\n0\n1", "2\n0 5\n4 0\n1 2", "4\n0 3 1 1\n6 0 400 1\n2 4 0 1\n1 1 1 0\n4 1 2 3", "4\n0 57148 51001 13357\n71125 0 98369 67226\n49388 90852 0 66291\n39573 38165 97007 0\n2 3 1 4", "5\n0 27799 15529 16434 44291\n47134 0 90227 26873 52252\n41605 21269 0 9135 55784\n70744 17563 79061 0 73981\n70529 35681 9107...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
7
codeforces
823926c4d8ea61495c95a7a6f7accf46
Hack it!
Little X has met the following problem recently. Let's define *f*(*x*) as the sum of digits in decimal representation of number *x* (for example, *f*(1234)<==<=1<=+<=2<=+<=3<=+<=4). You are to calculate Of course Little X has solved this problem quickly, has locked it, and then has tried to hack others. He has seen...
{"inputs": ["46", "126444381000032", "69645082595", "70602205995", "33898130785", "58929554039", "81696185182", "1", "2", "3", "4", "5", "6", "7", "8", "10", "11", "12", "43", "36", "65", "43", "23", "100", "10000", "1000000", "100000000", "10000000000", "1000000000000", "100000000000000", "10000000000000000", "1000000...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
70
codeforces
823e9c56b117ced7c4c45cebec880ab8
Party
A company has *n* employees numbered from 1 to *n*. Each employee either has no immediate manager or exactly one immediate manager, who is another employee with a different number. An employee *A* is said to be the superior of another employee *B* if at least one of the following is true: - Employee *A* is the immedi...
{"inputs": ["5\n-1\n1\n2\n1\n-1", "4\n-1\n1\n2\n3", "12\n-1\n1\n2\n3\n-1\n5\n6\n7\n-1\n9\n10\n11", "6\n-1\n-1\n2\n3\n1\n1", "3\n-1\n1\n1", "1\n-1", "2\n2\n-1", "2\n-1\n-1", "3\n2\n-1\n1", "3\n-1\n-1\n-1", "5\n4\n5\n1\n-1\n4", "12\n-1\n1\n1\n1\n1\n1\n3\n4\n3\n3\n4\n7", "12\n-1\n-1\n1\n-1\n1\n1\n5\n11\n8\n6\n6\n4", "12\n...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
283
codeforces
8247c1d90bd78e0e2751b3f923feafa5
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 2*k* (*k* is an integer, *k*<=≥<=0) units. A magical box *v* can be pu...
{"inputs": ["2\n0 3\n1 5", "1\n0 4", "2\n1 10\n2 2", "1\n0 1", "1\n1000000000 1000000000", "1\n0 16", "1\n0 17", "2\n0 16\n1 4", "3\n0 20\n1 18\n2 4", "3\n0 64\n1 16\n2 4", "5\n1 1000000\n100 100\n101 9\n102 4\n103 8", "10\n11 69\n7 56\n8 48\n2 56\n12 6\n9 84\n1 81\n4 80\n3 9\n5 18", "15\n0 268435456\n1 67108864\n2 167...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
14
codeforces
82a0355eb15f93fc5a3bc9c298539d50
Shaass and Bookshelf
Shaass has *n* books. He wants to make a bookshelf for all his books. He wants the bookshelf's dimensions to be as small as possible. The thickness of the *i*-th book is *t**i* and its pages' width is equal to *w**i*. The thickness of each book is either 1 or 2. All books have the same page heights. Shaass puts the bo...
{"inputs": ["5\n1 12\n1 3\n2 15\n2 5\n2 1", "3\n1 10\n2 1\n2 4", "10\n2 10\n2 4\n2 8\n2 3\n2 5\n2 6\n1 2\n1 10\n1 10\n2 5", "1\n2 7", "50\n1 24\n1 16\n1 33\n2 34\n1 26\n2 35\n1 39\n2 44\n2 29\n2 28\n1 44\n2 48\n2 50\n2 41\n2 9\n1 22\n2 11\n2 27\n1 12\n1 50\n2 49\n1 17\n2 43\n2 6\n1 39\n2 28\n1 47\n1 45\n2 32\n1 43\n2 4...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
10
codeforces
82a7f8952265e9e4692372f6045274b1
Planning
Helen works in Metropolis airport. She is responsible for creating a departure schedule. There are *n* flights that must depart today, the *i*-th of them is planned to depart at the *i*-th minute of the day. Metropolis airport is the main transport hub of Metropolia, so it is difficult to keep the schedule intact. Thi...
{"inputs": ["5 2\n4 2 1 10 2", "3 2\n3 1 2", "5 5\n5 5 9 100 3", "1 1\n1", "1 1\n10000000", "6 4\n85666 52319 21890 51912 90704 10358", "10 5\n66220 81797 38439 54881 86879 94346 8802 59094 57095 41949", "8 1\n3669 11274 87693 33658 58862 78334 42958 30572", "2 2\n16927 73456", "6 6\n21673 27126 94712 82700 59725 46310...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
6
codeforces
82d5d3e126087dd42f8f9e7919edf755
Line to Cashier
Little Vasya went to the supermarket to get some groceries. He walked about the supermarket for a long time and got a basket full of products. Now he needs to choose the cashier to pay for the products. There are *n* cashiers at the exit from the supermarket. At the moment the queue for the *i*-th cashier already has ...
{"inputs": ["1\n1\n1", "4\n1 4 3 2\n100\n1 2 2 3\n1 9 1\n7 8", "4\n5 4 5 5\n3 1 3 1 2\n3 1 1 3\n1 1 1 2 2\n2 2 1 1 3", "5\n5 3 6 6 4\n7 5 3 3 9\n6 8 2\n1 10 8 5 9 2\n9 7 8 5 9 10\n9 8 3 3", "5\n10 10 10 10 10\n6 7 8 6 8 5 9 8 10 5\n9 6 9 8 7 8 8 10 8 5\n8 7 7 8 7 5 6 8 9 5\n6 5 10 5 5 10 7 8 5 5\n10 9 8 7 6 9 7 9 6 5",...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
356
codeforces
82e4d503992da73823380c942016218f
Three Base Stations
The New Vasjuki village is stretched along the motorway and that's why every house on it is characterized by its shift relative to some fixed point — the *x**i* coordinate. The village consists of *n* houses, the *i*-th house is located in the point with coordinates of *x**i*. TELE3, a cellular communication provider ...
{"inputs": ["4\n1 2 3 4", "3\n10 20 30", "5\n10003 10004 10001 10002 1", "1\n1", "2\n1 1", "9\n9 8 7 6 5 4 3 2 1", "2\n2 2", "3\n2 1 2", "4\n6 6 8 3", "5\n18 80 86 18 51", "10\n26 21 20 91 22 28 92 62 47 69", "4\n70 20 94 30", "3\n8 8 8", "2\n12 38", "7\n36 15 36 29 11 38 38", "5\n9 6 15 6 10", "1\n8", "2\n8 12", "3\n3...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
4
codeforces
82ffce87fe11c128652285a581fb9b47
Drinks
Little Vasya loves orange juice very much. That's why any food and drink in his kitchen necessarily contains orange juice. There are *n* drinks in his fridge, the volume fraction of orange juice in the *i*-th drink equals *p**i* percent. One day Vasya decided to make himself an orange cocktail. He took equal proportio...
{"inputs": ["3\n50 50 100", "4\n0 25 50 75", "3\n0 1 8", "5\n96 89 93 95 70", "7\n62 41 78 4 38 39 75", "13\n2 22 7 0 1 17 3 17 11 2 21 26 22", "21\n5 4 11 7 0 5 45 21 0 14 51 6 0 16 10 19 8 9 7 12 18", "26\n95 70 93 74 94 70 91 70 39 79 80 57 87 75 37 93 48 67 51 90 85 26 23 64 66 84", "29\n84 99 72 96 83 92 95 98 97 ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1,064
codeforces
8349f6da202ade7b78d88bc6bfcd1ba8
Anton and Fairy Tale
Anton likes to listen to fairy tales, especially when Danik, Anton's best friend, tells them. Right now Danik tells Anton a fairy tale: "Once upon a time, there lived an emperor. He was very rich and had much grain. One day he ordered to build a huge barn to put there all his grain. Best builders were building that ba...
{"inputs": ["5 2", "8 1", "32 5", "1024 1024", "58044 52909", "996478063 658866858", "570441179141911871 511467058318039545", "1 1", "1000000000000000000 1000000000000000000", "1000000000000000000 999999999999997145", "1 1000000000000000000", "1000000000000000000 1", "999999998765257149 10", "999999998765257150 10", "9...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
5
codeforces
836531ed000ab9717afb7fee73310986
Two Semiknights Meet
A boy Petya loves chess very much. He even came up with a chess piece of his own, a semiknight. The semiknight can move in any of these four directions: 2 squares forward and 2 squares to the right, 2 squares forward and 2 squares to the left, 2 squares backward and 2 to the right and 2 squares backward and 2 to the le...
{"inputs": ["2\n........\n........\n......#.\nK..##..#\n.......#\n...##..#\n......#.\nK.......\n\n........\n........\n..#.....\n..#..#..\n..####..\n...##...\n........\n....K#K#", "3\n........\n........\n..#.....\n..#..#..\n..####..\n...##...\n........\n####K#K#\n\n........\nK......K\n........\n#......#\n.#....#.\n..###...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
13
codeforces
83779125e360c0f88aa14c07c743b788
The Wall (hard)
So many wall designs to choose from! Even modulo 106<=+<=3, it's an enormous number. Given that recently Heidi acquired an unlimited supply of bricks, her choices are endless! She really needs to do something to narrow them down. Heidi is quick to come up with criteria for a useful wall: - In a useful wall, at least...
{"inputs": ["1 1 1", "1 2 2", "1 2 3", "3 2 2", "5 4 9", "40 37 65", "100000000 100 100", "99999999 97 99", "100000000 1 100", "100000000 100 1", "100000000 1 1", "13 66 38", "13 66 57", "13 66 76", "13 66 95", "13 99 38", "13 99 57", "13 99 76", "13 99 95", "85714284 66 76", "85714284 66 95", "85714284 99 76", "857142...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1
codeforces
83971be6bedcf3ef74de89eaa3c3fd4f
ZgukistringZ
Professor GukiZ doesn't accept string as they are. He likes to swap some letters in string to obtain a new one. GukiZ has strings *a*, *b*, and *c*. He wants to obtain string *k* by swapping some letters in *a*, so that *k* should contain as many non-overlapping substrings equal either to *b* or *c* as possible. Subst...
{"inputs": ["aaa\na\nb", "pozdravstaklenidodiri\nniste\ndobri", "abbbaaccca\nab\naca", "lemigazalemiolemilicomzalemljenje\nlemi\nzlo", "xxxbbbcccoca\nca\ncb", "aleksandrehteosidatedodam\nevo\nsi", "cumurcumur\num\ncur", "saljivdzijasamjaneki\nneki\nja", "lebronnojameslebronprogrammers\nje\nbro", "lukavpastaakojelukav\n...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
15
codeforces
839a326aaf591e7fbcb6196222397274
Party
Arseny likes to organize parties and invite people to it. However, not only friends come to his parties, but friends of his friends, friends of friends of his friends and so on. That's why some of Arseny's guests can be unknown to him. He decided to fix this issue using the following procedure. At each step he selects...
{"inputs": ["5 6\n1 2\n1 3\n2 3\n2 5\n3 4\n4 5", "4 4\n1 2\n1 3\n1 4\n3 4", "1 0", "2 1\n2 1", "3 2\n1 3\n2 3", "22 31\n5 11\n6 3\n10 1\n18 20\n3 21\n12 10\n15 19\n1 17\n17 18\n2 21\n21 7\n2 15\n3 2\n19 6\n2 19\n13 16\n21 19\n13 5\n19 3\n12 22\n9 20\n14 11\n15 21\n7 8\n2 6\n15 6\n6 21\n15 3\n4 22\n14 8\n16 9", "22 36\n...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
2
codeforces
83a372c034fbb5f2b404ab2b3fb81eb4
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 *x**i* boxes on its top (we'll call *x**i* 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...
{"inputs": ["3\n0 0 10", "5\n0 1 2 3 4", "4\n0 0 0 0", "9\n0 1 0 2 0 1 1 2 10", "1\n0", "2\n0 0", "2\n0 1", "2\n100 99", "9\n0 1 1 0 2 0 3 45 4", "10\n1 1 1 1 2 2 2 2 2 2", "100\n50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
131
codeforces
83f28d9be0614e982868c126897fb64e
Cycle In Maze
The Robot is in a rectangular maze of size *n*<=×<=*m*. Each cell of the maze is either empty or occupied by an obstacle. The Robot can move between neighboring cells on the side left (the symbol "L"), right (the symbol "R"), up (the symbol "U") or down (the symbol "D"). The Robot can move to the cell only if it is emp...
{"inputs": ["2 3 2\n.**\nX..", "5 6 14\n..***.\n*...X.\n..*...\n..*.**\n....*.", "3 3 4\n***\n*X*\n***", "1 1 1\nX", "1 2 2\nX.", "1 5 4\n.X**.", "1 10 1\n........X.", "1 20 10\n*.*..............*.X", "2 1 1\nX\n.", "2 2 2\nX*\n.*", "2 5 2\n.....\n*.*.X", "2 10 4\n******....\n*.****.*X*", "2 20 26\n.****..*.**.**.*.......
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
2
codeforces
83f5f45e8eab08931e16ddeb28420b18
GCD Table
The GCD table *G* of size *n*<=×<=*n* for an array of positive integers *a* of length *n* is defined by formula Let us remind you that the greatest common divisor (GCD) of two positive integers *x* and *y* is the greatest integer that is divisor of both *x* and *y*, it is denoted as . For example, for array *a*<==<={...
{"inputs": ["4\n2 1 2 3 4 3 2 6 1 1 2 2 1 2 3 2", "1\n42", "2\n1 1 1 1", "2\n54748096 1 641009859 1", "3\n1 7 923264237 374288891 7 524125987 1 1 1", "4\n1 1 1 1 1 702209411 496813081 673102149 1 1 561219907 1 1 1 1 1", "5\n1 1 1 1 1 9 564718673 585325539 1 1 3 1 9 1 1 365329221 3 291882089 3 1 412106895 1 1 1 3", "5\n...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
52
codeforces
83f7d2cee6458359e3b27ec171ad250c
GukiZ and Contest
Professor GukiZ likes programming contests. He especially likes to rate his students on the contests he prepares. Now, he has decided to prepare a new contest. In total, *n* students will attend, and before the start, every one of them has some positive integer rating. Students are indexed from 1 to *n*. Let's denote...
{"inputs": ["3\n1 3 3", "1\n1", "5\n3 5 3 4 5", "7\n1 3 5 4 2 2 1", "11\n5 6 4 2 9 7 6 6 6 6 7", "1\n2000", "2\n2000 2000", "3\n500 501 502", "10\n105 106 1 1 1 11 1000 999 1000 999", "6\n1 2 3 4 5 6", "7\n6 5 4 3 2 1 1", "8\n153 100 87 14 10 8 6 5", "70\n11 54 37 62 1 46 13 17 38 47 28 15 63 5 61 34 49 66 32 59 3 41 5...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
667
codeforces
83fe6169fa7fac345ddf7b7d2caff627
Load Balancing
In the school computer room there are *n* servers which are responsible for processing several computing tasks. You know the number of scheduled tasks for each server: there are *m**i* tasks assigned to the *i*-th server. In order to balance the load for each server, you want to reassign some tasks to make the differe...
{"inputs": ["2\n1 6", "7\n10 11 10 11 10 11 11", "5\n1 2 3 4 5", "10\n0 0 0 0 0 0 0 0 0 0", "1\n0", "1\n20000", "3\n1 10000 20000", "10\n19999 19999 20000 20000 19999 20000 20000 20000 19999 19999", "10\n8 5 5 5 6 6 6 6 5 5", "2\n10 3", "5\n6 5 9 7 6", "5\n2 10 20 30 50", "7\n2 2 2 2 2 3 4"], "outputs": ["2", "0", "3",...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
64
codeforces
843b8ddbf88ea9a774a44e936780d7b5
Arrays
You are given two arrays *A* and *B* consisting of integers, sorted in non-decreasing order. Check whether it is possible to choose *k* numbers in array *A* and choose *m* numbers in array *B* so that any number chosen in the first array is strictly less than any number chosen in the second array. The first line contai...
{"inputs": ["3 3\n2 1\n1 2 3\n3 4 5", "3 3\n3 3\n1 2 3\n3 4 5", "5 2\n3 1\n1 1 1 1 1\n2 2", "3 5\n1 1\n5 5 5\n5 5 5 5 5", "1 1\n1 1\n1\n1", "3 3\n1 1\n1 2 3\n1 2 3", "3 3\n1 2\n1 2 3\n1 2 3", "3 3\n2 2\n1 2 3\n1 2 3", "10 15\n10 1\n1 1 5 17 22 29 32 36 39 48\n9 10 20 23 26 26 32 32 33 39 43 45 47 49 49", "10 15\n1 15\n...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
381
codeforces
84638ad2b8ecfc61e5c49b99e7a47d5b
Cinema
Overall there are *m* actors in Berland. Each actor has a personal identifier — an integer from 1 to *m* (distinct actors have distinct identifiers). Vasya likes to watch Berland movies with Berland actors, and he has *k* favorite actors. He watched the movie trailers for the next month and wrote the following informat...
{"inputs": ["5 3\n1 2 3\n6\nfirstfilm\n3\n0 0 0\nsecondfilm\n4\n0 0 4 5\nthirdfilm\n1\n2\nfourthfilm\n1\n5\nfifthfilm\n1\n4\nsixthfilm\n2\n1 0", "5 3\n1 3 5\n4\njumanji\n3\n0 0 0\ntheeagle\n5\n1 2 3 4 0\nmatrix\n3\n2 4 0\nsourcecode\n2\n2 4", "10 1\n1\n4\na\n1\n3\nb\n1\n4\nc\n1\n5\nd\n1\n2", "2 1\n1\n2\na\n1\n2\nb\n1\n...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
10
codeforces
8469dddf318b05524edbda28b5a9bcfa
Sereja ans Anagrams
Sereja has two sequences *a* and *b* and number *p*. Sequence *a* consists of *n* integers *a*1,<=*a*2,<=...,<=*a**n*. Similarly, sequence *b* consists of *m* integers *b*1,<=*b*2,<=...,<=*b**m*. As usual, Sereja studies the sequences he has. Today he wants to find the number of positions *q* (*q*<=+<=(*m*<=-<=1)·*p*<=...
{"inputs": ["5 3 1\n1 2 3 2 1\n1 2 3", "6 3 2\n1 3 2 2 3 1\n1 2 3", "68 16 3\n5 3 4 3 3 3 2 2 2 3 2 4 2 2 2 2 4 3 5 1 1 2 2 2 3 1 5 1 2 2 1 5 1 5 3 2 3 5 2 1 1 4 2 3 4 3 4 3 3 1 3 4 1 5 2 5 3 4 4 1 4 5 5 1 1 2 2 2\n5 4 4 3 5 1 1 2 3 2 2 1 3 3 2 2", "44 11 4\n4 3 3 3 4 3 4 5 1 3 4 2 4 4 2 2 1 5 3 1 5 2 3 2 4 4 5 3 2 2 2...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
3
codeforces
8480e73bfbab69837dd4c9ed947c982c
Minimum number of steps
We have a string of letters 'a' and 'b'. We want to perform some operations on it. On each step we choose one of substrings "ab" in the string and replace it with the string "bba". If we have no "ab" as a substring, our job is done. Print the minimum number of steps we should perform to make our job done modulo 109<=+<...
{"inputs": ["ab", "aab", "aaaaabaabababaaaaaba", "abaabaaabbabaabab", "abbaa", "abbaaabaabaaaaabbbbaababaaaaabaabbaaaaabbaabbaaaabbbabbbabb", "aababbaaaabbaabbbbbbbbabbababbbaaabbaaabbabbba", "aabbaababbabbbaabbaababaaaabbaaaabaaaaaababbaaaabaababbabbbb", "aaabaaaabbababbaabbababbbbaaaaaaabbabbba", "abbbbababbabbbbbaba...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
132
codeforces
84a1ec15b35327250779bfbc7b9c9430
Non-square Equation
Let's consider equation: where *x*,<=*n* are positive integers, *s*(*x*) is the function, equal to the sum of digits of number *x* in the decimal number system. You are given an integer *n*, find the smallest positive integer root of equation *x*, or else determine that there are no such roots. A single line contains...
{"inputs": ["2", "110", "4", "8", "10000000100000000", "10000006999999929", "172541340", "172580744", "10000100000", "1000001000000", "100000010000000", "425", "1085", "4296409065", "9211004165221796", "1245131330556680", "40000000400000000", "90000000900000000", "160000001600000000", "250000002500000000", "36000000360...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
21
codeforces
84a5a2ed7fa8dc2da713daa96a556173
Inna, Dima and Song
Inna is a great piano player and Dima is a modest guitar player. Dima has recently written a song and they want to play it together. Of course, Sereja wants to listen to the song very much. A song is a sequence of notes. Dima and Inna want to play each note at the same time. At that, they can play the *i*-th note at ...
{"inputs": ["3\n1 1 2\n2 2 3", "1\n2\n5", "10\n2 2 3 4 5 6 7 8 9 10\n2 2 3 4 5 6 7 8 9 10", "10\n1 2 3 4 5 6 7 8 9 10\n1 2 3 4 5 6 7 8 9 10", "3\n10000 10000 10000\n5000 5000 1", "2\n1 1\n2 1"], "outputs": ["4", "-1", "96", "94", "12499999", "0"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
13
codeforces
84f6356702ad0c9612055335da1b33e8
Almost Difference
Let's denote a function You are given an array *a* consisting of *n* integers. You have to calculate the sum of *d*(*a**i*,<=*a**j*) over all pairs (*i*,<=*j*) such that 1<=≤<=*i*<=≤<=*j*<=≤<=*n*. The first line contains one integer *n* (1<=≤<=*n*<=≤<=200000) — the number of elements in *a*. The second line contai...
{"inputs": ["5\n1 2 3 1 3", "4\n6 6 5 5", "4\n6 6 4 4", "1\n1", "1\n1000000000", "2\n1 1000000000", "5\n1 999999996 999999998 999999994 1000000000", "100\n7 4 5 5 10 10 5 8 5 7 4 5 4 6 8 8 2 6 3 3 10 7 10 8 6 2 7 3 9 7 7 2 4 5 2 4 9 5 10 1 10 5 10 4 1 3 4 2 6 9 9 9 10 6 2 5 6 1 8 10 4 10 3 4 10 5 5 4 10 4 5 3 7 10 2 7 ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
116
codeforces
8502ae13f38ef5bda917a038126041ce
Xor-sequences
You are given *n* integers *a*1,<=<=*a*2,<=<=...,<=<=*a**n*. A sequence of integers *x*1,<=<=*x*2,<=<=...,<=<=*x**k* is called a "xor-sequence" if for every 1<=<=≤<=<=*i*<=<=≤<=<=*k*<=-<=1 the number of ones in the binary representation of the number *x**i* *x**i*<=<=+<=<=1's is a multiple of 3 and for all 1<=≤<=*i*...
{"inputs": ["5 2\n15 1 2 4 8", "5 1\n15 1 2 4 8", "10 1\n44 65 23 44 100 19 19 23 19 40", "10 2\n93 93 85 48 44 98 93 100 98 98", "10 100\n22 0 41 63 22 41 17 22 15 42", "10 1000000000\n454240622 216977025 454240622 509843007 509843007 26552516 488949284 708817573 453191950 447767457", "100 576460752303423487\n0 0 0 0 ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
2
codeforces
851cdc37572844db5ff8db560c7a80ca
Contest
Misha and Vasya participated in a Codeforces contest. Unfortunately, each of them solved only one problem, though successfully submitted it at the first attempt. Misha solved the problem that costs *a* points and Vasya solved the problem that costs *b* points. Besides, Misha submitted the problem *c* minutes after the ...
{"inputs": ["500 1000 20 30", "1000 1000 1 1", "1500 1000 176 177", "1500 1000 74 177", "750 2500 175 178", "750 1000 54 103", "2000 1250 176 130", "1250 1750 145 179", "2000 2000 176 179", "1500 1500 148 148", "2750 1750 134 147", "3250 250 175 173", "500 500 170 176", "250 1000 179 178", "3250 1000 160 138", "3000 20...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
553
codeforces
853497d6bbbf49820ca1f6a476d78703
Mr. Kitayuta's Technology
Shuseki Kingdom is the world's leading nation for innovation and technology. There are *n* cities in the kingdom, numbered from 1 to *n*. Thanks to Mr. Kitayuta's research, it has finally become possible to construct teleportation pipes between two cities. A teleportation pipe will connect two cities unidirectionally,...
{"inputs": ["4 5\n1 2\n1 3\n1 4\n2 3\n2 4", "4 6\n1 2\n1 4\n2 3\n2 4\n3 2\n3 4", "4 6\n1 2\n1 3\n1 4\n2 3\n2 4\n3 4", "3 6\n1 2\n1 3\n2 1\n2 3\n3 1\n3 2", "8 12\n6 1\n7 5\n2 5\n4 1\n6 3\n4 3\n5 7\n1 3\n5 2\n2 7\n4 6\n7 2", "2 1\n1 2", "10 4\n8 4\n9 8\n2 8\n8 1", "8 7\n6 3\n2 4\n3 7\n8 2\n4 8\n7 6\n3 2", "10 10\n10 6\n9...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1
codeforces
853733567b5c4563940cc2a07c2be496
Holidays
On the planet Mars a year lasts exactly *n* days (there are no leap years on Mars). But Martians have the same weeks as earthlings — 5 work days and then 2 days off. Your task is to determine the minimum possible and the maximum possible number of days off per year on Mars. The first line of the input contains a positi...
{"inputs": ["14", "2", "1", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "1000000", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "100", "99", "98", "97", "96", "95", "94", "93", "92", "91", "90", "89", "88", "87", "86", "85", "84", "83", "82", "81", "80", "1000...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
131
codeforces
855032e57951f02044cbcf81b424f300
Seating of Students
Students went into a class to write a test and sat in some way. The teacher thought: "Probably they sat in this order to copy works of each other. I need to rearrange them in such a way that students that were neighbors are not neighbors in a new seating." The class can be represented as a matrix with *n* rows and *m*...
{"inputs": ["2 4", "2 1", "1 1", "1 2", "1 3", "2 2", "2 3", "3 1", "3 2", "3 3", "1 4", "4 1", "4 2", "1 100000", "100000 1", "316 316", "315 316", "316 315", "315 315", "100 1000", "1000 100", "10 10000", "10000 10", "100 1", "1 100", "100 2", "2 100", "100 3", "3 100", "100 4", "4 100", "101 1", "1 101", "101 2", "2...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
3
codeforces
85596ef8043e36b06fa4d003d852efc2
Sets
Little Vasya likes very much to play with sets consisting of positive integers. To make the game more interesting, Vasya chose *n* non-empty sets in such a way, that no two of them have common elements. One day he wanted to show his friends just how interesting playing with numbers is. For that he wrote out all possib...
{"inputs": ["4\n3 2 7 4\n3 1 7 3\n3 5 4 2\n3 1 3 5\n4 3 1 2 4\n2 5 7", "4\n5 6 7 8 9 100\n4 7 8 9 1\n4 7 8 9 2\n3 1 6 100\n3 2 6 100\n2 1 2", "3\n2 1 2\n2 1 3\n2 2 3", "3\n2 1 2\n10 1 90 80 70 60 50 40 30 20 10\n10 2 10 20 30 40 50 60 70 80 90", "4\n4 56 44 53 43\n3 109 44 43\n3 109 56 53\n3 43 62 44\n3 62 56 53\n2 109...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
5
codeforces
855ca95248a5bfd9520047e02b8110e6
Scarborough Fair
Parsley, sage, rosemary and thyme. Remember me to one who lives there. He once was the true love of mine. Willem is taking the girl to the highest building in island No.28, however, neither of them knows how to get there. Willem asks his friend, Grick for directions, Grick helped them, and gave them a task. Althou...
{"inputs": ["3 1\nioi\n1 1 i n", "5 3\nwxhak\n3 3 h x\n1 5 x a\n1 3 w g", "9 51\nbhfbdcgff\n2 3 b b\n2 8 e f\n3 8 g f\n5 7 d a\n1 5 e b\n3 4 g b\n6 7 c d\n3 6 e g\n3 6 e h\n5 6 a e\n7 9 a c\n4 9 a h\n3 7 c b\n6 9 b g\n1 7 h b\n4 5 a e\n3 9 f a\n1 2 c h\n4 8 a c\n3 5 e d\n3 4 g f\n2 3 d h\n2 3 d e\n1 7 d g\n2 6 e g\n2 3...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
476
codeforces
8567369105f3e809e62c03d1c311d0cd
Serial Time!
The Cereal Guy's friend Serial Guy likes to watch soap operas. An episode is about to start, and he hasn't washed his plate yet. But he decided to at least put in under the tap to be filled with water. The plate can be represented by a parallelepiped *k*<=×<=*n*<=×<=*m*, that is, it has *k* layers (the first layer is t...
{"inputs": ["1 1 1\n\n.\n\n1 1", "2 1 1\n\n.\n\n#\n\n1 1", "2 2 2\n\n.#\n##\n\n..\n..\n\n1 1", "3 2 2\n\n#.\n##\n\n#.\n.#\n\n..\n..\n\n1 2", "3 3 3\n\n.#.\n###\n##.\n\n.##\n###\n##.\n\n...\n...\n...\n\n1 1", "2 2 2\n\n#.\n..\n\n.#\n#.\n\n2 1", "4 7 8\n\n........\n........\n........\n........\n........\n........\n.........
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
43
codeforces
85b83a877cca38028c1baed68103d7b7
Spongebob and Squares
Spongebob is already tired trying to reason his weird actions and calculations, so he simply asked you to find all pairs of n and m, such that there are exactly *x* distinct squares in the table consisting of *n* rows and *m* columns. For example, in a 3<=×<=5 table there are 15 squares with side one, 8 squares with si...
{"inputs": ["26", "2", "8", "1", "5005", "17284", "151618", "360700", "500500500", "200200", "800800", "200000800200", "999999999999999999", "128593726482159", "50044422", "18", "30", "20", "649708734844", "649030984", "333333333", "5050505060", "1000000000000000000", "18270000000000", "10102030405090000", "50004000222...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
5
codeforces
85c1e0800313be21370c1a51af05aa89
String Problem
Boy Valera likes strings. And even more he likes them, when they are identical. That's why in his spare time Valera plays the following game. He takes any two strings, consisting of lower case Latin letters, and tries to make them identical. According to the game rules, with each move Valera can change one arbitrary ch...
{"inputs": ["uayd\nuxxd\n3\na x 8\nx y 13\nd c 3", "a\nb\n3\na b 2\na b 3\nb a 5", "abc\nab\n6\na b 4\na b 7\nb a 8\nc b 11\nc a 3\na c 0", "xhtuopq\nrtutbz\n10\nh x 10\nx d 3\nr u 4\nu d 1\nt o 100\no t 7\np e 1\ne f 1\nb f 2\nz q 19", "abad\nabad\n6\na c 3\nb x 100\nd e 7\nr r 10\no t 17\na a 4", "bbad\nabxd\n4\nb a ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
3
codeforces
85c72846a552ae1e070a07f77d2c6f4a
Diverse Permutation
Permutation *p* is an ordered set of integers *p*1,<=<=<=*p*2,<=<=<=...,<=<=<=*p**n*, consisting of *n* distinct positive integers not larger than *n*. We'll denote as *n* the length of permutation *p*1,<=<=<=*p*2,<=<=<=...,<=<=<=*p**n*. Your task is to find such permutation *p* of length *n*, that the group of number...
{"inputs": ["3 2", "3 1", "5 2", "5 4", "10 4", "10 3", "10 9", "100000 99999", "99999 99998", "42273 29958", "29857 9843", "27687 4031", "25517 1767", "23347 20494", "10931 8824", "98514 26178", "6591 407", "94174 30132", "92004 85348", "59221 29504", "2 1", "4 1", "4 2", "100000 1", "99999 1", "99998 2", "99999 5000"...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
103
codeforces
85eec64b53510690a189a65c7bf24c65
Pashmak and Flowers
Pashmak decided to give Parmida a pair of flowers from the garden. There are *n* flowers in the garden and the *i*-th of them has a beauty number *b**i*. Parmida is a very strange girl so she doesn't want to have the two most beautiful flowers necessarily. She wants to have those pairs of flowers that their beauty diff...
{"inputs": ["2\n1 2", "3\n1 4 5", "5\n3 1 2 3 1", "2\n1 1", "3\n1 1 1", "4\n1 1 1 1", "5\n1 1 1 1 1", "5\n2 2 2 2 2", "10\n2 2 2 2 2 2 2 2 2 2", "3\n2 2 2", "3\n3 3 3", "2\n10000000 100000000", "5\n5 5 5 5 5", "5\n3 3 3 3 3", "6\n1 1 1 1 1 1", "2\n5 6", "10\n1 1 1 1 1 1 1 1 1 1", "10\n1000000000 1000000000 1000000000 1...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
135
codeforces
85f0c3dca52d0319e2f5851dc7cb4d59
Funny Game
Once upon a time Petya and Gena gathered after another programming competition and decided to play some game. As they consider most modern games to be boring, they always try to invent their own games. They have only stickers and markers, but that won't stop them. The game they came up with has the following rules. In...
{"inputs": ["3\n2 4 8", "4\n1 -7 -2 3", "10\n35 11 35 28 48 25 2 43 23 10", "100\n437 89 481 95 29 326 10 304 97 414 52 46 106 181 385 173 337 148 437 133 52 136 86 250 289 61 480 314 166 69 275 486 117 129 353 412 382 469 290 479 388 231 7 462 247 432 488 146 466 422 369 336 148 460 418 356 303 149 421 146 233 224 432...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
3
codeforces
85fe13c6ddb305a3920fa99f8970df6d
Nearly Lucky Number
Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Unfortunately, not all numbers are lucky. Petya calls a number nearly lucky if the number of lucky d...
{"inputs": ["40047", "7747774", "1000000000000000000", "7", "4", "474404774", "4744000695826", "10000000004744744", "446486416781684178", "999999999", "7777", "87414417444", "111222333444555667", "1", "4700", "3794555488744477", "444444444444444444", "474447447774444774", "777777777777777", "34777745021000000", "963", ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
483
codeforces
8612e0f6e2ddc420a3b9875dd71b5f62
Set Theory
Masha and Grisha like studying sets of positive integers. One day Grisha has written a set *A* containing *n* different integers *a**i* on a blackboard. Now he asks Masha to create a set *B* containing *n* different integers *b**j* such that all *n*2 integers that can be obtained by summing up *a**i* and *b**j* for al...
{"inputs": ["3\n3\n1 10 100\n1\n1\n2\n2 4", "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...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
9
codeforces
8613f1b0afa3b8dfd3e8f7af9121480c
National Property
You all know that the Library of Bookland is the largest library in the world. There are dozens of thousands of books in the library. Some long and uninteresting story was removed... The alphabet of Bookland is so large that its letters are denoted by positive integers. Each letter can be small or large, the large ve...
{"inputs": ["4 3\n1 2\n1 1\n3 1 3 2\n2 1 1", "6 5\n2 1 2\n2 1 2\n3 1 2 3\n2 1 5\n2 4 4\n2 4 4", "4 3\n4 3 2 2 1\n3 1 1 3\n3 2 3 3\n2 3 1", "4 4\n3 3 4 1\n4 3 4 2 2\n4 2 1 2 3\n3 4 2 2", "3 5\n2 1 2\n2 1 5\n2 4 4", "2 1\n10 1 1 1 1 1 1 1 1 1 1\n25 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", "10 3\n2 3 2\n1 3\n3 ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
3
codeforces
863575ab8345ae9d711a4048f919eb2e
Glass Carving
Leonid wants to become a glass carver (the person who creates beautiful artworks by cutting the glass). He already has a rectangular *w* mm <=×<= *h* mm sheet of glass, a diamond glass cutter and lots of enthusiasm. What he lacks is understanding of what to carve and how. In order not to waste time, he decided to prac...
{"inputs": ["4 3 4\nH 2\nV 2\nV 3\nV 1", "7 6 5\nH 4\nV 3\nV 5\nH 2\nV 1", "2 2 1\nV 1", "2 2 1\nH 1", "2 2 2\nV 1\nH 1", "2 2 2\nH 1\nV 1", "10 10 10\nV 6\nH 8\nV 4\nV 8\nH 2\nH 5\nV 9\nH 7\nH 3\nV 7", "5 15 10\nH 8\nH 9\nV 1\nH 2\nH 6\nH 4\nH 1\nV 2\nH 13\nV 3", "15 5 10\nV 13\nV 10\nV 3\nH 2\nV 9\nV 7\nV 2\nH 1\nV 4...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
4
codeforces
86712ff51baabd9cb0cad3df9de22aca
Arya and Bran
Bran and his older sister Arya are from the same house. Bran like candies so much, so Arya is going to give him some Candies. At first, Arya and Bran have 0 Candies. There are *n* days, at the *i*-th day, Arya finds *a**i* candies in a box, that is given by the Many-Faced God. Every day she can give Bran at most 8 of ...
{"inputs": ["2 3\n1 2", "3 17\n10 10 10", "1 9\n10", "10 70\n6 5 2 3 3 2 1 4 3 2", "20 140\n40 4 81 40 10 54 34 50 84 60 16 1 90 78 38 93 99 60 81 99", "30 133\n3 2 3 4 3 7 4 5 5 6 7 2 1 3 4 6 7 4 6 4 7 5 7 1 3 4 1 6 8 5", "40 320\n70 79 21 64 95 36 63 29 66 89 30 34 100 76 42 12 4 56 80 78 83 1 39 9 34 45 6 71 27 31 5...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
139
codeforces
867538c2ec9791c52fc38b83949d76a7
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 *m**i* numbers. During the game the host t...
{"inputs": ["3\n1 1\n3 2 4 1\n2 10 11", "2\n1 1\n1 1", "1\n1 1", "2\n1 2\n1 3", "2\n1 1\n2 1 2", "2\n2 1 2\n1 1", "2\n3 5 21 7\n6 15 5 100 21 7 17", "2\n6 15 5 100 21 7 17\n3 5 21 7", "10\n1 4\n1 2\n1 3\n1 5\n1 1\n1 4\n1 3\n1 5\n1 2\n1 1", "3\n1 1\n1 2\n1 1", "10\n3 2 3 4\n1 1\n1 1\n1 2\n1 3\n1 4\n1 1\n1 3\n2 4 5\n2 1 ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
23
codeforces
8676255daaf99564013bbc9970f823f2
Dividing Island
A revolution took place on the Buka Island. New government replaced the old one. The new government includes *n* parties and each of them is entitled to some part of the island according to their contribution to the revolution. However, they can't divide the island. The island can be conventionally represented as two ...
{"inputs": ["3 4 2 2 3\n5 8 3", "3 2 1 4 4\n1 2 3 4", "1 2 1 1 1\n3", "1 2 1 3 2\n3 2", "3 2 4 4 20\n1 2 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "5 4 2 3 26\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", "11 5 4 13 5\n18 21 22 23 23", "1 13 1 14 7\n4 5 5 4 4 3 2", "15 1 1 25 6\n3 14 7 7 5 4", "20 30 40 50 1\n2600...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
3
codeforces
86992df511c35724e491b550c53aaae0
Ice cream coloring
Isart and Modsart were trying to solve an interesting problem when suddenly Kasra arrived. Breathless, he asked: "Can you solve a problem I'm stuck at all day?" We have a tree *T* with *n* vertices and *m* types of ice cream numerated from 1 to *m*. Each vertex *i* has a set of *s**i* types of ice cream. Vertices whic...
{"inputs": ["3 3\n1 1\n2 2 3\n1 2\n1 2\n2 3", "4 5\n0\n1 1\n1 3\n3 2 4 5\n2 1\n3 2\n4 3", "7 35\n3 17 20 32\n4 3 14 24 25\n4 4 10 17 26\n7 2 9 13 17 23 28 30\n9 1 2 7 8 13 16 18 33 35\n8 5 6 11 15 17 22 29 34\n5 12 19 21 27 31\n2 1\n3 1\n4 3\n5 4\n6 3\n7 4", "7 39\n7 5 10 15 27 31 33 39\n7 5 16 21 27 28 29 33\n3 15 26 ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1
codeforces
8699b4e498214d26bc63282f383bc860
Game with Tokens
Consider the following game for two players. There is one white token and some number of black tokens. Each token is placed on a plane in a point with integer coordinates *x* and *y*. The players take turn making moves, white starts. On each turn, a player moves all tokens of their color by 1 to up, down, left or righ...
{"inputs": ["4\n-2 -1\n0 1\n0 -3\n2 -1", "4\n-2 0\n-1 1\n0 -2\n1 -1", "16\n2 1\n1 2\n-1 1\n0 1\n0 0\n1 1\n2 -1\n2 0\n1 0\n-1 -1\n1 -1\n2 2\n0 -1\n-1 0\n0 2\n-1 2", "1\n1 2", "4\n0 99999\n-99999 0\n99999 0\n0 -99999", "10\n-1 3\n-1 7\n-8 -4\n5 14\n-6 -7\n11 -8\n-11 0\n5 -1\n9 4\n-2 -14", "50\n-15 -80\n-80 21\n90 38\n-10...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1
codeforces
86a3244023545fd311c4e9765040d5ad
Case of Fugitive
Andrewid the Android is a galaxy-famous detective. He is now chasing a criminal hiding on the planet Oxa-5, the planet almost fully covered with water. The only dry land there is an archipelago of *n* narrow islands located in a row. For more comfort let's represent them as non-intersecting segments on a straight line...
{"inputs": ["4 4\n1 4\n7 8\n9 10\n12 14\n4 5 3 8", "2 2\n11 14\n17 18\n2 9", "2 1\n1 1\n1000000000000000000 1000000000000000000\n999999999999999999", "5 10\n1 2\n3 3\n5 7\n11 13\n14 20\n9 10 2 9 10 4 9 9 9 10", "5 9\n1 2\n3 3\n5 7\n11 13\n14 20\n2 3 4 10 6 2 6 9 5", "6 9\n1 4\n10 18\n23 29\n33 43\n46 57\n59 77\n11 32 3...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
3
codeforces
86bbcc5761032fc0723cc9aa7716bfc2
Four Divisors
If an integer *a* is divisible by another integer *b*, then *b* is called the divisor of *a*. For example: 12 has positive 6 divisors. They are 1, 2, 3, 4, 6 and 12. Let’s define a function *D*(*n*) — number of integers between 1 and *n* (inclusive) which has exactly four positive divisors. Between 1 and 10 only the...
{"inputs": ["10", "20", "1", "27", "100", "1000", "10000", "100000", "1000000", "100000000", "1000000000", "10000000000", "100000000000", "353964", "437388", "553516", "636940", "753068", "803788", "24403439", "907519567", "790635695", "968719119", "146802543", "324885967", "448485", "324885968"], "outputs": ["3", "5",...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
3
codeforces
86ce3ffc590e44c16fbff25c2821701e
A Piece of Cake
How to make a cake you'll never eat. Ingredients. - 2 carrots - 0 calories - 100 g chocolate spread - 1 pack of flour - 1 egg Method. 1. Put calories into the mixing bowl. 1. Take carrots from refrigerator. 1. Chop carrots. 1. Take chocolate spread from refrigerator. 1. Put chocolate spread into the mix...
{"inputs": ["4 1 2 3 4", "4 802 765 992 1", "4 220 380 729 969", "3 887 104 641", "12 378 724 582 387 583 241 294 159 198 653 369 418", "14 36 901 516 623 703 971 304 394 491 525 464 219 183 648", "3 287 979 395", "19 702 667 743 976 908 728 134 106 380 193 214 71 920 114 587 543 817 248 537", "11 739 752 364 649 626 7...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
34
codeforces
86e9c457887ad23b21c89ed45b4524d1
Tetris
You are given a following process. There is a platform with $n$ columns. $1 \times 1$ squares are appearing one after another in some columns on this platform. If there are no squares in the column, a square will occupy the bottom row. Otherwise a square will appear at the top of the highest square of this column. ...
{"inputs": ["3 9\n1 1 2 2 2 3 1 2 3", "1 7\n1 1 1 1 1 1 1", "1 1\n1", "3 5\n1 1 1 2 3", "4 6\n4 4 4 4 4 4", "4 6\n2 3 4 4 4 4", "3 12\n1 1 1 1 2 2 2 2 3 3 3 3", "8 8\n2 2 3 4 5 6 7 8", "100 1\n50", "2 1\n2", "2 1\n1", "2 4\n1 2 1 1", "3 4\n3 2 2 2", "2 2\n2 2", "2 5\n2 1 1 2 1", "15 3\n13 14 15", "4 9\n1 2 3 1 2 3 1 2 ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
225
codeforces
86eadace39c4974d7855296691977d3a
Complete The Graph
ZS the Coder has drawn an undirected graph of *n* vertices numbered from 0 to *n*<=-<=1 and *m* edges between them. Each edge of the graph is weighted, each weight is a positive integer. The next day, ZS the Coder realized that some of the weights were erased! So he wants to reassign positive integer weight to each of...
{"inputs": ["5 5 13 0 4\n0 1 5\n2 1 2\n3 2 3\n1 4 0\n4 3 4", "2 1 123456789 0 1\n0 1 0", "2 1 999999999 1 0\n0 1 1000000000", "4 5 10 1 2\n0 1 3\n1 2 0\n1 3 4\n2 3 4\n2 0 6", "100 1 123456 99 0\n0 99 123456", "1000 1 5 999 0\n0 999 0", "1000 1 1000000000 998 0\n0 999 0", "4 4 14 1 3\n1 3 13\n2 3 0\n2 0 0\n1 0 12", "4 4...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
6
codeforces
86f346636148be5c88089eb977a30d94
Sum of Digits
Having watched the last Harry Potter film, little Gerald also decided to practice magic. He found in his father's magical book a spell that turns any number in the sum of its digits. At the moment Gerald learned that, he came across a number *n*. How many times can Gerald put a spell on it until the number becomes one-...
{"inputs": ["0", "10", "991", "99", "100", "123456789", "32", "86", "2", "8", "34", "13", "28", "23", "57", "29", "353869285", "549548646", "858893424", "644818852", "360322525", "122937520", "288403032", "677257481", "58059561", "211288847", "339900034079539584", "784084029310269952", "774730557264864000", "4782338071...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
734
codeforces
870be526ad4079cf2e6c4b1dc17092df
Reconnaissance
According to the regulations of Berland's army, a reconnaissance unit should consist of exactly two soldiers. Since these two soldiers shouldn't differ much, their heights can differ by at most *d* centimeters. Captain Bob has *n* soldiers in his detachment. Their heights are *a*1,<=*a*2,<=...,<=*a**n* centimeters. Som...
{"inputs": ["5 10\n10 20 50 60 65", "5 1\n55 30 29 31 55", "6 10\n4 6 4 1 9 3", "7 100\n19 1694 261 162 1 234 513", "8 42\n37 53 74 187 568 22 5 65", "10 4\n11 6 76 49 28 20 57 152 5 32", "100 100\n51 93 101 960 2 477 213 129 663 925 254 78 1486 274 160 481 132 156 412 372 5 57 152 298 1771 7 359 468 254 406 202 929 22...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
264
codeforces
87448a33bcad98078c557bcb497905c7
Infinite Sequence
Consider the infinite sequence of integers: 1,<=1,<=2,<=1,<=2,<=3,<=1,<=2,<=3,<=4,<=1,<=2,<=3,<=4,<=5.... The sequence is built in the following way: at first the number 1 is written out, then the numbers from 1 to 2, then the numbers from 1 to 3, then the numbers from 1 to 4 and so on. Note that the sequence contains ...
{"inputs": ["3", "5", "10", "55", "56", "1000000000000", "847194127849", "294719472984", "999999911791", "999999911792", "100000000000000", "1", "99993", "99994", "99995", "99990", "2", "99991", "99992", "99996", "99997", "99998", "99999", "1021", "4", "23", "9994", "99939", "99999998250180", "6", "8", "35", "100", "10...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
164
codeforces
87666ee7bb3f34a6210d448d76e7181e
Preorder Test
For his computer science class, Jacob builds a model tree with sticks and balls containing *n* nodes in the shape of a tree. Jacob has spent *a**i* minutes building the *i*-th ball in the tree. Jacob's teacher will evaluate his model and grade Jacob based on the effort he has put in. However, she does not have enough ...
{"inputs": ["5 3\n3 6 1 4 2\n1 2\n2 4\n2 5\n1 3", "4 2\n1 5 5 5\n1 2\n1 3\n1 4", "2 1\n1 100000\n2 1", "2 2\n1 1000000\n1 2", "10 4\n104325 153357 265088 777795 337716 557321 702646 734430 464449 744072\n9 4\n8 1\n10 7\n8 6\n7 9\n8 2\n3 5\n8 3\n10 8", "10 3\n703660 186846 317819 628672 74457 58472 247014 480113 252764 ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1
codeforces
8790f27d226d7ec0ce3b1e544a70f2fc
Xor-MST
You are given a complete undirected graph with *n* vertices. A number *a**i* is assigned to each vertex, and the weight of an edge between vertices *i* and *j* is equal to *a**i*<=*xor*<=*a**j*. Calculate the weight of the minimum spanning tree in this graph. The first line contains *n* (1<=≤<=*n*<=≤<=200000) — the nu...
{"inputs": ["5\n1 2 3 4 5", "4\n1 2 3 4", "1\n1"], "outputs": ["8", "8", "0"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1
codeforces
8795970e6387f383db66fbe5d5eb72ad
Candy Boxes
There is an old tradition of keeping 4 boxes of candies in the house in Cyberland. The numbers of candies are special if their arithmetic mean, their median and their range are all equal. By definition, for a set {*x*1,<=*x*2,<=*x*3,<=*x*4} (*x*1<=≤<=*x*2<=≤<=*x*3<=≤<=*x*4) arithmetic mean is , median is and range is ...
{"inputs": ["2\n1\n1", "3\n1\n1\n1", "4\n1\n2\n2\n3", "0", "1\n125", "2\n472\n107", "3\n215\n137\n256", "4\n49\n464\n28\n118", "4\n172\n84\n252\n163", "2\n66\n135", "1\n190", "3\n184\n100\n71", "3\n361\n387\n130", "3\n146\n247\n182", "3\n132\n44\n126", "2\n172\n148", "3\n276\n311\n442", "3\n324\n301\n131", "4\n186\n129...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
11
codeforces
87a54f067b31ebfad0da83002caa68eb
Colorful Graph
You've got an undirected graph, consisting of *n* vertices and *m* edges. We will consider the graph's vertices numbered with integers from 1 to *n*. Each vertex of the graph has a color. The color of the *i*-th vertex is an integer *c**i*. Let's consider all vertices of the graph, that are painted some color *k*. Let...
{"inputs": ["6 6\n1 1 2 3 5 8\n1 2\n3 2\n1 4\n4 3\n4 5\n4 6", "5 6\n4 2 5 2 4\n1 2\n2 3\n3 1\n5 3\n5 4\n3 4", "3 1\n13 13 4\n1 2", "2 1\n500 300\n1 2", "6 5\n2 2 2 1 2 2\n4 5\n4 2\n5 2\n4 1\n2 3", "8 8\n3 3 2 3 3 3 1 3\n8 2\n6 3\n2 3\n2 6\n5 6\n4 2\n7 5\n1 6", "10 27\n1 1 3 2 4 1 3 2 4 1\n9 3\n7 8\n9 7\n6 5\n7 6\n7 4\n...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
16
codeforces
87b26ff597826f7c8a05c6ccd32d831d
Parallel Programming
Polycarpus has a computer with *n* processors. Also, his computer has *n* memory cells. We'll consider the processors numbered by integers from 1 to *n* and that the memory cells are consecutively numbered by integers from 1 to *n*. Polycarpus needs to come up with a parallel program model. For each memory cell number...
{"inputs": ["1 1", "3 2", "4 2", "2 1", "2 20", "1 20", "10000 20", "10 4", "10 5", "10 6", "128 7", "127 7", "129 8", "130 8", "131 8", "1024 10", "1024 11", "1023 10", "10000 14", "8192 13", "8190 13", "8192 14", "8123 13", "5000 13", "2000 11", "2198 14", "2512 12"], "outputs": ["1", "2 3 3\n3 3 3", "2 3 4 4\n3 4 4 ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
2
codeforces
87cd06539720d164c8bb461f4a43badf
Olympiad in Programming and Sports
There are *n* students at Berland State University. Every student has two skills, each measured as a number: *a**i* — the programming skill and *b**i* — the sports skill. It is announced that an Olympiad in programming and sports will be held soon. That's why Berland State University should choose two teams: one to ta...
{"inputs": ["5 2 2\n1 3 4 5 2\n5 3 2 1 4", "4 2 2\n10 8 8 3\n10 7 9 4", "5 3 1\n5 2 5 1 7\n6 3 1 6 3", "2 1 1\n100 101\n1 100", "4 1 1\n100 100 1 50\n100 100 50 1", "2 1 1\n3 2\n3 2", "2 1 1\n9 6\n3 10", "2 1 1\n1 17\n5 20", "3 1 1\n5 4 2\n1 5 2", "3 1 1\n10 5 5\n9 1 4", "3 1 1\n17 6 2\n2 19 19", "4 1 2\n4 2 4 5\n3 2 5...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1
codeforces