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
b8647a7e2926935660a06e9ef1fce9ea
Declined Finalists
This year, as in previous years, MemSQL is inviting the top 25 competitors from the Start[c]up qualification round to compete onsite for the final round. Not everyone who is eligible to compete onsite can afford to travel to the office, though. Initially the top 25 contestants are invited to come onsite. Each eligible ...
{"inputs": ["25\n2 3 4 5 6 7 8 9 10 11 12 14 15 16 17 18 19 20 21 22 23 24 25 26 28", "5\n16 23 8 15 4", "3\n14 15 92", "1\n1000000", "25\n1000000 999999 999998 999997 999996 999995 999994 999993 999992 999991 999990 999989 999988 999987 999986 999985 999984 999983 999982 999981 999980 999979 999978 999977 999976", "25...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
279
codeforces
b86e30843c84440849b6b0560eb93808
st-Spanning Tree
You are given an undirected connected graph consisting of *n* vertices and *m* edges. There are no loops and no multiple edges in the graph. You are also given two distinct vertices *s* and *t*, and two values *d**s* and *d**t*. Your task is to build any spanning tree of the given graph (note that the graph is not wei...
{"inputs": ["3 3\n1 2\n2 3\n3 1\n1 2 1 1", "7 8\n7 4\n1 3\n5 4\n5 7\n3 2\n2 4\n6 1\n1 2\n6 4 1 4", "10 15\n4 1\n5 10\n2 1\n5 7\n9 2\n4 6\n6 7\n9 1\n6 9\n8 4\n8 3\n9 8\n3 9\n2 3\n7 10\n10 1 2 3", "10 10\n1 3\n10 3\n6 1\n2 7\n1 7\n1 9\n9 5\n2 10\n10 8\n4 3\n9 5 2 4", "4 4\n1 4\n4 2\n1 3\n4 3\n3 4 3 3", "3 2\n3 1\n2 3\n1 ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1
codeforces
b8a883f6d70b75a151dc0664da41aa54
Counting Rectangles is Fun
There is an *n*<=×<=*m* rectangular grid, each cell of the grid contains a single integer: zero or one. Let's call the cell on the *i*-th row and the *j*-th column as (*i*,<=*j*). Let's define a "rectangle" as four integers *a*,<=*b*,<=*c*,<=*d* (1<=≤<=*a*<=≤<=*c*<=≤<=*n*; 1<=≤<=*b*<=≤<=*d*<=≤<=*m*). Rectangle denotes...
{"inputs": ["5 5 5\n00101\n00000\n00001\n01000\n00001\n1 2 2 4\n4 5 4 5\n1 2 5 2\n2 2 4 5\n4 2 5 3", "4 7 5\n0000100\n0000010\n0011000\n0000000\n1 7 2 7\n3 1 3 1\n2 3 4 5\n1 2 2 7\n2 2 4 7", "10 10 10\n0010001010\n0011011010\n0100001110\n0010100000\n0000100011\n0100000001\n0000010100\n1000000010\n0000010000\n0110010000...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1
codeforces
b8bf78afb79fadde1f00b79f93ba318c
none
Карта звёздного неба представляет собой прямоугольное поле, состоящее из *n* строк по *m* символов в каждой строке. Каждый символ — это либо «.» (означает пустой участок неба), либо «*» (означает то, что в этом месте на небе есть звезда). Новое издание карты звёздного неба будет напечатано на квадратных листах, поэто...
{"inputs": ["4 4\n....\n..*.\n...*\n..**", "1 3\n*.*", "2 1\n.\n*", "1 1\n*", "1 2\n.*", "1 2\n*.", "1 2\n**", "2 1\n.\n*", "2 1\n*\n.", "2 1\n*\n*", "5 3\n..*\n.**\n..*\n...\n..*", "1 1\n*", "1 2\n*.", "1 2\n**", "1 3\n.**", "1 3\n*.*", "1 4\n..**", "1 4\n*..*", "1 5\n.*.**", "1 5\n.*..*", "2 1\n*\n.", "2 1\n*\n*", "2...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
8
codeforces
b8d8b73277f7749e7852f8884ff19b71
Subtractions
You've got two numbers. As long as they are both larger than zero, they go through the same operation: subtract the lesser number from the larger one. If they equal substract one number from the another. For example, one operation transforms pair (4,17) to pair (4,13), it transforms (5,5) to (0,5). You've got some num...
{"inputs": ["2\n4 17\n7 987654321", "10\n7 987654321\n7 987654321\n7 987654321\n7 987654321\n7 987654321\n7 987654321\n7 987654321\n7 987654321\n7 987654321\n7 987654321", "1\n536870912 32", "20\n1000000000 999999999\n1000000000 999999999\n1000000000 999999999\n1000000000 999999999\n1000000000 999999999\n1000000000 999...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
242
codeforces
b8e4040e30b7e2f49655da687a4e31d4
Bash's Big Day
Bash has set out on a journey to become the greatest Pokemon master. To get his first Pokemon, he went to Professor Zulu's Lab. Since Bash is Professor Zulu's favourite student, Zulu allows him to take as many Pokemon from his lab as he pleases. But Zulu warns him that a group of *k*<=&gt;<=1 Pokemon with strengths {*...
{"inputs": ["3\n2 3 4", "5\n2 3 4 6 7", "3\n5 6 4", "8\n41 74 4 27 85 39 100 36", "6\n89 20 86 81 62 23", "71\n23 84 98 8 14 4 42 56 83 87 28 22 32 50 5 96 90 1 59 74 77 88 71 38 62 36 85 97 99 6 81 20 49 57 66 9 45 41 29 68 35 19 27 76 78 72 55 25 46 48 26 53 39 31 94 34 63 37 64 16 79 24 82 17 12 3 89 61 80 30 10", "...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
39
codeforces
b8fffd9ad83f41df8f97739b5e939e71
Make a Permutation!
Ivan has an array consisting of *n* elements. Each of the elements is an integer from 1 to *n*. Recently Ivan learned about permutations and their lexicographical order. Now he wants to change (replace) minimum number of elements in his array in such a way that his array becomes a permutation (i.e. each of the integer...
{"inputs": ["4\n3 2 2 3", "6\n4 5 6 3 2 1", "10\n6 8 4 6 7 1 6 3 4 5", "6\n5 5 5 6 4 6", "50\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "50\n1 1 2 1 1 1 1 1 1 1 1 1 2 1 2 1 1 2 1 1 1 1 1 1 1 1 1 2 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "50\n2 4 1 2 3 7 ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
31
codeforces
b90159b3b2c41c91a4086c3dd7b577d5
Vladik and Memorable Trip
Vladik often travels by trains. He remembered some of his trips especially well and I would like to tell you about one of these trips: Vladik is at initial train station, and now *n* people (including Vladik) want to get on the train. They are already lined up in some order, and for each of them the city code *a**i* i...
{"inputs": ["6\n4 4 2 5 2 3", "9\n5 1 3 1 5 2 4 2 5", "5\n1558 4081 3591 1700 3232", "10\n3838 1368 4825 2068 4755 2048 1342 4909 2837 4854", "10\n4764 4867 2346 1449 1063 2002 2577 2089 1566 614", "10\n689 3996 3974 4778 1740 3481 2916 2744 294 1376", "100\n1628 4511 4814 3756 4625 1254 906 1033 2420 2622 2640 3225 35...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
12
codeforces
b93fdbb19a50d95418de5887b98a8017
Sasha and Sticks
It's one more school day now. Sasha doesn't like classes and is always bored at them. So, each day he invents some game and plays in it alone or with friends. Today he invented one simple game to play with Lena, with whom he shares a desk. The rules are simple. Sasha draws *n* sticks in a row. After that the players t...
{"inputs": ["1 1", "10 4", "251656215122324104 164397544865601257", "963577813436662285 206326039287271924", "1000000000000000000 1", "253308697183523656 25332878317796706", "669038685745448997 501718093668307460", "116453141993601660 87060381463547965", "766959657 370931668", "255787422422806632 146884995820359999", "...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
350
codeforces
b95a8706627d77a638a45e9ced72df03
none
This is an interactive problem. Natasha is going to fly to Mars. Finally, Natasha sat in the rocket. She flies, flies... but gets bored. She wishes to arrive to Mars already! So she decides to find something to occupy herself. She couldn't think of anything better to do than to calculate the distance to the red planet...
{"inputs": ["5 2 3\n1 0", "1 1 1\n1", "3 2 3\n1 0", "6 3 5\n1 1 1", "10 4 3\n0 0 1 0", "30 5 16\n0 1 1 1 0", "60 6 21\n1 0 0 1 0 1", "100 7 73\n0 0 0 1 0 1 1", "1000000000 29 958572235\n1 1 0 1 1 1 1 0 1 0 1 0 0 0 1 0 0 0 0 0 0 0 0 0 1 1 1 0 0", "738009704 30 116044407\n0 0 1 1 0 0 1 0 0 0 1 0 0 0 1 0 0 1 1 0 1 0 1 1 0...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
27
codeforces
b9622c31d50bf23062fb84ae34d8743b
New Year Book Reading
New Year is coming, and Jaehyun decided to read many books during 2015, unlike this year. He has *n* books numbered by integers from 1 to *n*. The weight of the *i*-th (1<=≤<=*i*<=≤<=*n*) book is *w**i*. As Jaehyun's house is not large enough to have a bookshelf, he keeps the *n* books by stacking them vertically. Whe...
{"inputs": ["3 5\n1 2 3\n1 3 2 3 1", "3 3\n10 20 30\n1 2 3", "2 2\n10 12\n2 1", "10 10\n61 59 97 16 2 94 57 48 91 93\n2 8 6 5 3 1 3 4 9 10", "50 50\n75 71 23 37 28 23 69 75 5 62 3 11 96 100 13 50 57 51 8 90 4 6 84 27 11 89 95 81 10 62 48 52 69 87 97 95 30 74 21 42 36 64 31 80 81 50 56 53 33 99\n26 30 5 33 35 29 6 15 36...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
6
codeforces
b97db026ba1258b019779e2780f685b7
Lie or Truth
Vasya has a sequence of cubes and exactly one integer is written on each cube. Vasya exhibited all his cubes in a row. So the sequence of numbers written on the cubes in the order from the left to the right equals to *a*1,<=*a*2,<=...,<=*a**n*. While Vasya was walking, his little brother Stepan played with Vasya's cub...
{"inputs": ["5 2 4\n3 4 2 3 1\n3 2 3 4 1", "3 1 2\n1 2 3\n3 1 2", "4 2 4\n1 1 1 1\n1 1 1 1", "5 1 3\n2 2 2 1 2\n2 2 2 1 2", "7 1 4\n2 5 5 5 4 3 4\n2 5 5 5 4 3 4", "10 1 10\n6 7 6 1 10 10 9 5 3 9\n7 10 9 6 1 5 9 3 10 6", "1 1 1\n1\n1", "4 3 4\n1 2 3 4\n2 1 3 4", "7 2 4\n1 2 3 4 5 7 6\n1 2 3 4 5 6 7", "5 1 2\n1 2 3 4 5\n...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
56
codeforces
b9872594d263a975d2c53559931b8334
Little Pony and Expected Maximum
Twilight Sparkle was playing Ludo with her friends Rainbow Dash, Apple Jack and Flutter Shy. But she kept losing. Having returned to the castle, Twilight Sparkle became interested in the dice that were used in the game. The dice has *m* faces: the first face of the dice contains a dot, the second one contains two dots...
{"inputs": ["6 1", "6 3", "2 2", "5 4", "5 8", "3 10", "3 6", "1 8", "24438 9", "94444 9", "8 66716", "4 25132", "51520 73331", "54230 31747", "24236 90163", "26946 99523", "50323 7", "53033 3", "55743 5", "59964 79", "1 1", "1 1", "3 1", "1 2", "53513 34040", "100000 100000", "1 100000", "100000 1", "2 100000", "10000...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
192
codeforces
b98a21fa072aed9a5f1c1c67eb2c1ce9
Create a Maze
ZS the Coder loves mazes. Your job is to create one so that he can play with it. A maze consists of *n*<=×<=*m* rooms, and the rooms are arranged in *n* rows (numbered from the top to the bottom starting from 1) and *m* columns (numbered from the left to the right starting from 1). The room in the *i*-th row and *j*-th...
{"inputs": ["3", "4", "576460752303423488", "576460752303423487", "99999988898898889", "989466010702279111", "1000000000000000000", "1", "2", "201620162016201600", "138944482508455329", "327543848458922240", "516143210114421854", "481370539210112956", "639733286738742273", "604960615834433375", "793559981784900286", "9...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
2
codeforces
b9ad6ca1fc6d03437f5d46ec93ad89c2
Inna and Sweet Matrix
Inna loves sweets very much. That's why she decided to play a game called "Sweet Matrix". Inna sees an *n*<=×<=*m* matrix and *k* candies. We'll index the matrix rows from 1 to *n* and the matrix columns from 1 to *m*. We'll represent the cell in the *i*-th row and *j*-th column as (*i*,<=*j*). Two cells (*i*,<=*j*) a...
{"inputs": ["4 4 4", "1 1 1", "1 50 50", "50 1 50", "50 50 1", "4 4 9", "10 10 10", "10 10 100", "10 10 50", "10 10 25", "10 10 75", "50 50 1000", "50 50 2500", "50 50 1", "50 50 10", "50 50 100", "50 50 500", "50 50 200", "50 50 1000", "50 50 1500", "50 50 2000", "50 50 2499", "30 30 56", "30 30 800", "2 2 3", "1 2 1"...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1
codeforces
b9b279d1b0b471a11dcd0b7afc2c685e
Searching for Graph
Let's call an undirected graph of *n* vertices *p*-interesting, if the following conditions fulfill: - the graph contains exactly 2*n*<=+<=*p* edges; - the graph doesn't contain self-loops and multiple edges; - for any integer *k* (1<=≤<=*k*<=≤<=*n*), any subgraph consisting of *k* vertices contains at most 2*k*<=...
{"inputs": ["1\n6 0", "1\n5 0", "5\n6 0\n5 0\n7 0\n8 0\n9 0", "5\n6 1\n5 0\n7 1\n8 1\n9 1", "5\n24 0\n23 0\n22 0\n21 0\n24 1", "5\n24 1\n23 1\n22 1\n21 1\n20 1", "5\n20 0\n19 0\n18 0\n17 0\n16 0", "5\n15 0\n14 0\n13 0\n12 0\n11 0", "5\n10 0\n20 0\n24 0\n19 0\n17 0", "5\n24 0\n23 0\n24 1\n23 1\n22 0", "5\n24 0\n24 0\n24...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
62
codeforces
b9b2cf2e122e6b22549b44b01e380445
Vasya and Wrestling
Vasya has become interested in wrestling. In wrestling wrestlers use techniques for which they are awarded points by judges. The wrestler who gets the most points wins. When the numbers of points of both wrestlers are equal, the wrestler whose sequence of points is lexicographically greater, wins. If the sequences of...
{"inputs": ["5\n1\n2\n-3\n-4\n3", "3\n-1\n-2\n3", "2\n4\n-4", "7\n1\n2\n-3\n4\n5\n-6\n7", "14\n1\n2\n3\n4\n5\n6\n7\n-8\n-9\n-10\n-11\n-12\n-13\n-14", "4\n16\n12\n19\n-98", "5\n-6\n-1\n-1\n5\n3", "11\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1", "1\n-534365", "1\n10253033", "3\n-1\n-2\n3", "8\n1\n-2\n-3\n4\n5\n-6\n-7\n8", "2\...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
157
codeforces
b9b4e52303af6ee09e25948b343ce56f
Where Are My Flakes?
One morning the Cereal Guy found out that all his cereal flakes were gone. He found a note instead of them. It turned out that his smart roommate hid the flakes in one of *n* boxes. The boxes stand in one row, they are numbered from 1 to *n* from the left to the right. The roommate left hints like "Hidden to the left o...
{"inputs": ["2 1\nTo the left of 2", "3 2\nTo the right of 1\nTo the right of 2", "3 1\nTo the left of 3", "3 2\nTo the left of 2\nTo the right of 1", "3 0", "2 2\nTo the left of 2\nTo the left of 2", "5 0", "6 2\nTo the right of 2\nTo the left of 4", "8 6\nTo the right of 3\nTo the left of 4\nTo the left of 4\nTo the ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
46
codeforces
b9ce4117c8187dc8b1c2b57344133486
Case of Fake Numbers
Andrewid the Android is a galaxy-famous detective. He is now investigating a case of frauds who make fake copies of the famous Stolp's gears, puzzles that are as famous as the Rubik's cube once was. Its most important components are a button and a line of *n* similar gears. Each gear has *n* teeth containing all numbe...
{"inputs": ["3\n1 0 0", "5\n4 2 1 4 3", "4\n0 2 3 1", "1\n0", "2\n1 0", "5\n2 4 4 1 1", "10\n0 1 2 3 4 5 6 7 8 9", "10\n1 5 1 0 6 1 3 5 9 9", "20\n10 11 12 13 14 15 16 17 18 19 0 1 2 3 4 5 6 7 8 9", "20\n2 15 18 0 3 12 4 16 13 7 17 9 8 2 15 18 19 17 5 8", "50\n38 13 40 15 42 17 44 19 46 21 48 23 0 25 2 27 4 29 6 31 8 3...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
18
codeforces
b9e45bc4775a8d7761b45f8ab27508bc
Прокат велосипедов
Как известно, в теплую погоду многие жители крупных городов пользуются сервисами городского велопроката. Вот и Аркадий сегодня будет добираться от школы до дома, используя городские велосипеды. Школа и дом находятся на одной прямой улице, кроме того, на той же улице есть *n* точек, где можно взять велосипед в прокат и...
{"inputs": ["4 4\n3 6 8 10", "2 9\n10 20", "12 3\n4 6 7 9 10 11 13 15 17 18 20 21", "2 1\n11164 11165", "3 7\n45823 45825 45829", "2 100000\n0 100000", "50 15001\n1269 1580 5431 5916 6642 14145 15760 19922 20589 22062 24138 33454 33505 35916 37012 42577 43140 49457 54720 55188 56205 56639 56870 57997 58379 59088 59297 ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
103
codeforces
b9ea26d8fd625c2e46bc6f4fbe356598
George and Round
George decided to prepare a Codesecrof round, so he has prepared *m* problems for the round. Let's number the problems with integers 1 through *m*. George estimates the *i*-th problem's complexity by integer *b**i*. To make the round good, he needs to put at least *n* problems there. Besides, he needs to have at least...
{"inputs": ["3 5\n1 2 3\n1 2 2 3 3", "3 5\n1 2 3\n1 1 1 1 1", "3 1\n2 3 4\n1", "29 100\n20 32 41 67 72 155 331 382 399 412 465 470 484 511 515 529 616 637 679 715 733 763 826 843 862 903 925 979 989\n15 15 15 17 18 19 19 20 21 21 22 24 25 26 26 27 28 31 32 32 37 38 38 39 39 40 41 42 43 43 45 45 46 47 49 49 50 50 50 51 ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
225
codeforces
b9ec62d47e98670266215b759dd020f0
Sagheer and Nubian Market
On his trip to Luxor and Aswan, Sagheer went to a Nubian market to buy some souvenirs for his friends and relatives. The market has some strange rules. It contains *n* different items numbered from 1 to *n*. The *i*-th item has base cost *a**i* Egyptian pounds. If Sagheer buys *k* items with indices *x*1,<=*x*2,<=...,<...
{"inputs": ["3 11\n2 3 5", "4 100\n1 2 5 6", "1 7\n7", "1 7\n5", "1 1\n1", "4 33\n4 3 2 1", "86 96\n89 48 14 55 5 35 7 79 49 70 74 18 64 63 35 93 63 97 90 77 33 11 100 75 60 99 54 38 3 6 55 1 7 64 56 90 21 76 35 16 61 78 38 78 93 21 89 1 58 53 34 77 56 37 46 59 30 5 85 1 52 87 84 99 97 9 15 66 29 60 17 16 59 23 88 93 3...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
135
codeforces
b9ffc730bfcf1d8951e5290a7cc2ca24
Divisibility by 25
You are given an integer $n$ from $1$ to $10^{18}$ without leading zeroes. In one move you can swap any two adjacent digits in the given number in such a way that the resulting number will not contain leading zeroes. In other words, after each move the number you have cannot contain any leading zeroes. What is the mi...
{"inputs": ["5071", "705", "1241367", "7501", "507", "17010", "52231", "50267", "574196831896431419", "1", "10", "123456123450", "1000000000000000000", "100000000000762582", "123456789987654321", "213716413141380147", "5284691", "750000000000000001", "101", "275257725752725722", "50932", "50272", "25", "52", "57", "75"...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
4
codeforces
ba27c1ae25a9c6f3a632edc8ad96ab06
none
Santa Claus has Robot which lives on the infinite grid and can move along its lines. He can also, having a sequence of *m* points *p*1,<=*p*2,<=...,<=*p**m* with integer coordinates, do the following: denote its initial location by *p*0. First, the robot will move from *p*0 to *p*1 along one of the shortest paths betwe...
{"inputs": ["4\nRURD", "6\nRRULDD", "26\nRRRULURURUULULLLDLDDRDRDLD", "3\nRLL", "4\nLRLR", "5\nLRDLR", "10\nDDRDUULUDD", "1\nD"], "outputs": ["2", "2", "7", "2", "4", "4", "3", "1"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
107
codeforces
ba4d78b29a18d60849c1647760ddd911
Arpa and a game with Mojtaba
Mojtaba and Arpa are playing a game. They have a list of *n* numbers in the game. In a player's turn, he chooses a number *p**k* (where *p* is a prime number and *k* is a positive integer) such that *p**k* divides at least one number in the list. For each number in the list divisible by *p**k*, call it *x*, the player...
{"inputs": ["4\n1 1 1 1", "4\n1 1 17 17", "4\n1 1 17 289", "5\n1 2 3 4 5", "10\n10 14 16 9 17 13 12 4 6 10", "10\n13 13 18 3 8 9 19 12 20 14", "10\n10 18 16 10 8 20 8 4 4 2", "10\n1 4 15 1 16 14 7 17 11 8", "10\n9 19 4 1 20 7 19 18 11 11", "100\n80 35 113 179 195 92 143 152 125 55 68 121 71 147 172 153 87 68 143 133 32...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1
codeforces
ba5f27a8af10e0175f956f2fcf748134
Grandma Laura and Apples
Grandma Laura came to the market to sell some apples. During the day she sold all the apples she had. But grandma is old, so she forgot how many apples she had brought to the market. She precisely remembers she had *n* buyers and each of them bought exactly half of the apples she had at the moment of the purchase and ...
{"inputs": ["2 10\nhalf\nhalfplus", "3 10\nhalfplus\nhalfplus\nhalfplus", "10 328\nhalf\nhalfplus\nhalfplus\nhalf\nhalfplus\nhalf\nhalf\nhalf\nhalfplus\nhalfplus", "1 2\nhalfplus", "5 6\nhalf\nhalf\nhalfplus\nhalf\nhalfplus", "10 2\nhalfplus\nhalfplus\nhalfplus\nhalf\nhalfplus\nhalf\nhalfplus\nhalf\nhalfplus\nhalfplus"...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
80
codeforces
ba60028702652ff2df427b79f2f6558d
Functions again
Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function *f*, which is defined ...
{"inputs": ["5\n1 4 2 3 1", "4\n1 5 4 7", "8\n16 14 12 10 8 100 50 0", "2\n1 1", "50\n-5 -9 0 44 -10 37 34 -49 11 -22 -26 44 8 -13 23 -46 34 12 -24 2 -40 -15 -28 38 -40 -42 -42 7 -43 5 2 -11 10 43 9 49 -13 36 2 24 46 50 -15 -26 -6 -6 8 4 -44 -3", "100\n23 64 60 -45 -36 -64 -59 15 -75 69 -30 -7 -20 17 -77 58 93 -76 -98 ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
112
codeforces
baddb954f5f204cdf827de7b355fa03f
Dima and Lisa
Dima loves representing an odd number as the sum of multiple primes, and Lisa loves it when there are at most three primes. Help them to represent the given number as the sum of at most than three primes. More formally, you are given an odd numer *n*. Find a set of numbers *p**i* (1<=≤<=*i*<=≤<=*k*), such that 1. 1<=...
{"inputs": ["27", "3", "25", "9", "91", "57", "31", "555", "700000001", "5", "7", "11", "13", "15", "17", "19", "21", "23", "29", "79", "99", "27", "55", "79", "585", "245", "793", "133", "681", "981399", "867773", "654141", "202985", "784533", "370359", "396831", "492211", "838347", "1098945", "1313565", "1349631", "1...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
9
codeforces
bafeb7c12c0d4cc7009ce0f7dfa473fc
Bear and Colors
Bear Limak has *n* colored balls, arranged in one long row. Balls are numbered 1 through *n*, from left to right. There are *n* possible colors, also numbered 1 through *n*. The *i*-th ball has color *t**i*. For a fixed interval (set of consecutive elements) of balls we can define a dominant color. It's a color occurr...
{"inputs": ["4\n1 2 1 2", "3\n1 1 1", "10\n9 1 5 2 9 2 9 2 1 1", "50\n17 13 19 19 19 34 32 24 24 13 34 17 19 19 7 32 19 13 13 30 19 34 34 28 41 24 24 47 22 34 21 21 30 7 22 21 32 19 34 19 34 22 7 28 6 13 19 30 13 30", "150\n28 124 138 71 71 18 78 136 138 93 145 93 18 15 71 47 47 64 18 72 138 72 18 150 7 71 109 149 18 1...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
11
codeforces
bb1e3bb6c310b0882dcd8872d6ac76d1
Games
Manao works on a sports TV. He's spent much time watching the football games of some country. After a while he began to notice different patterns. For example, each team has two sets of uniforms: home uniform and guest uniform. When a team plays a game at home, the players put on the home uniform. When a team plays as ...
{"inputs": ["3\n1 2\n2 4\n3 4", "4\n100 42\n42 100\n5 42\n100 5", "2\n1 2\n1 2", "7\n4 7\n52 55\n16 4\n55 4\n20 99\n3 4\n7 52", "10\n68 42\n1 35\n25 70\n59 79\n65 63\n46 6\n28 82\n92 62\n43 96\n37 28", "30\n10 39\n89 1\n78 58\n75 99\n36 13\n77 50\n6 97\n79 28\n27 52\n56 5\n93 96\n40 21\n33 74\n26 37\n53 59\n98 56\n61 6...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
925
codeforces
bb4f21e3fb5d468b2df9010b6f3af889
Last Chance
Having read half of the book called "Storm and Calm" on the IT lesson, Innocentius was absolutely determined to finish the book on the maths lessons. All was fine until the math teacher Ms. Watkins saw Innocentius reading fiction books instead of solving equations of the fifth degree. As during the last maths class Inn...
{"inputs": ["Abo", "OEIS", "auBAAbeelii", "AaaBRAaaCAaaDAaaBRAaa", "EA", "BBBAABAABAABBBB", "b", "AABAABAABAA", "aaaaaaa", "AAAAAAABBB", "aabaaaaaaaaaaaaaaab", "aaaaabaaaaabaaaaabaaaaabaaaaabaaaaabaaaaabaaaaabaaaaabaaaaabaaaaabaaaaabaaaaabaaaaabaaaaabaaaaabaaaaabaaaaabaaaaabaaaaabaaaaab", "aaaaabaaaaabaaaaabaaaaabaaaaa...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
4
codeforces
bb53026b93847d7813469885cb9da1cf
Helga Hufflepuff's Cup
Harry, Ron and Hermione have figured out that Helga Hufflepuff's cup is a horcrux. Through her encounter with Bellatrix Lestrange, Hermione came to know that the cup is present in Bellatrix's family vault in Gringott's Wizarding Bank. The Wizarding bank is in the form of a tree with total *n* vaults where each vault ...
{"inputs": ["4 2\n1 2\n2 3\n1 4\n1 2", "3 3\n1 2\n1 3\n2 1", "3 1\n1 2\n1 3\n1 1", "3 1000000000\n2 3\n3 1\n585430050 9", "4 50000\n2 1\n4 2\n2 3\n42169 9", "15 100000\n9 7\n15 13\n1 13\n14 5\n6 10\n5 12\n4 14\n4 6\n8 3\n8 2\n9 3\n10 15\n11 8\n10 3\n16283 7"], "outputs": ["1", "13", "0", "91592837", "542369366", "77019...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
2
codeforces
bb6533d1cf6db1f3d3ef4bc882371c7c
none
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...
{"inputs": ["1 10", "3 8", "8 12", "4 84", "9 95", "331358794 820674098", "5 56", "10 22", "8 73", "7 63", "1 57", "6 5", "6 25", "1 39", "3 60", "2 81", "5 35", "8 100", "6 29", "7 90", "1 37", "7 34", "3 49", "1 38", "7 88", "9 30", "333734901 647005907", "140068687 419634856", "725891944 969448805", "792362041 42349...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
24
codeforces
bb658a7df66938411259566bbf53ad8e
Links and Pearls
A necklace can be described as a string of links ('-') and pearls ('o'), with the last link or pearl connected to the first one. You can remove a link or a pearl and insert it between two other existing links or pearls (or between a link and a pearl) on the necklace. This process can be repeated as many times as you l...
{"inputs": ["-o-o--", "-o---", "-o---o-", "ooo", "---", "--o-o-----o----o--oo-o-----ooo-oo---o--", "-o--o-oo---o-o-o--o-o----oo------oo-----o----o-o-o--oo-o--o---o--o----------o---o-o-oo---o--o-oo-o--", "-ooo--", "---o--", "oo-ooo", "------o-o--o-----o--", "--o---o----------o----o----------o--o-o-----o-oo---oo--oo---o-...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
216
codeforces
bb6f8901c7e3ad27813fe9d022d7ed4d
Water The Garden
It is winter now, and Max decided it's about time he watered the garden. The garden can be represented as *n* consecutive garden beds, numbered from 1 to *n*. *k* beds contain water taps (*i*-th tap is located in the bed *x**i*), which, if turned on, start delivering water to neighbouring beds. If the tap on the bed *...
{"inputs": ["3\n5 1\n3\n3 3\n1 2 3\n4 1\n1", "26\n1 1\n1\n2 1\n2\n2 1\n1\n2 2\n1 2\n3 1\n3\n3 1\n2\n3 2\n2 3\n3 1\n1\n3 2\n1 3\n3 2\n1 2\n3 3\n1 2 3\n4 1\n4\n4 1\n3\n4 2\n3 4\n4 1\n2\n4 2\n2 4\n4 2\n2 3\n4 3\n2 3 4\n4 1\n1\n4 2\n1 4\n4 2\n1 3\n4 3\n1 3 4\n4 2\n1 2\n4 3\n1 2 4\n4 3\n1 2 3\n4 4\n1 2 3 4", "31\n5 1\n5\n5 ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
132
codeforces
bb71d6ab1355a5ce318f88adc38bf033
Little Xor
Little Petya likes arrays that consist of non-negative integers a lot. Recently his mom has presented him one such array consisting of *n* elements. Petya immediately decided to find there a segment of consecutive elements, such that the *xor* of all numbers from this segment was maximal possible. Help him with that. ...
{"inputs": ["5\n1 2 1 1 2", "3\n1 2 7", "4\n4 2 4 8", "5\n1 1 1 1 1", "16\n0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15", "20\n1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 10", "100\n28 20 67 103 72 81 82 83 7 109 122 30 50 118 83 89 108 82 92 17 97 3 62 12 9 100 14 11 99 106 10 8 60 101 88 119 104 62 76 6 5 57 32 94 60 50 58 97 1 ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
71
codeforces
bb883e074b47c2bd5d1d4f497d9eb006
Inversions problem
You are given a permutation of *n* numbers *p*1,<=*p*2,<=...,<=*p**n*. We perform *k* operations of the following type: choose uniformly at random two indices *l* and *r* (*l*<=≤<=*r*) and reverse the order of the elements *p**l*,<=*p**l*<=+<=1,<=...,<=*p**r*. Your task is to find the expected value of the number of in...
{"inputs": ["3 1\n1 2 3", "3 4\n1 3 2", "6 1\n4 2 5 1 3 6", "6 2\n1 4 6 5 2 3", "4 4\n2 3 1 4", "4 1\n3 4 2 1", "4 3\n3 1 2 4", "4 4\n4 2 3 1", "4 1\n1 2 4 3", "5 4\n4 3 2 5 1", "5 2\n3 1 2 5 4", "5 1\n3 5 1 2 4", "6 1\n5 2 3 4 1 6", "5 2\n4 3 2 1 5", "6 1\n5 3 4 6 2 1", "6 4\n1 2 3 4 5 6", "6 4\n6 5 4 3 2 1", "1 1\n1"...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
9
codeforces
bbd37e23be19f61cce43427551e0e712
The Same Calendar
The girl Taylor has a beautiful calendar for the year *y*. In the calendar all days are given with their days of week: Monday, Tuesday, Wednesday, Thursday, Friday, Saturday and Sunday. The calendar is so beautiful that she wants to know what is the next year after *y* when the calendar will be exactly the same. Help ...
{"inputs": ["2016", "2000", "50501", "1000", "1900", "1899", "99999", "50000", "99900", "12345", "1004", "2100", "1313", "1872", "2098", "2072", "2002", "1179", "2096", "1096", "1796", "2014", "2006", "1874", "1884", "2342", "2010", "2097", "1072", "1191", "2896", "1797", "1002", "99988", "1788", "1994", "5094", "99996...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
43
codeforces
bbda5083b762ef3b2b0b127c37da519c
Jumping Jack
Jack is working on his jumping skills recently. Currently he's located at point zero of the number line. He would like to get to the point *x*. In order to train, he has decided that he'll first jump by only one unit, and each subsequent jump will be exactly one longer than the previous one. He can go either left or ri...
{"inputs": ["2", "6", "0", "-1000000000", "999961560", "999961561", "999961559", "-488979819", "-865918189", "-278253406", "-87275307", "103702792", "294680891", "485658989", "676637088", "867615187", "-941406715", "-897912263", "-706934164", "-790244010", "16417015", "823078041", "-517744582", "288916443", "-904422532...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
61
codeforces
bbfbef8cfdb66fcb1844230b423e42e2
XOR and OR
The Bitlandians are quite weird people. They do everything differently. They have a different alphabet so they have a different definition for a string. A Bitlandish string is a string made only of characters "0" and "1". BitHaval (the mayor of Bitland) loves to play with Bitlandish strings. He takes some Bitlandish ...
{"inputs": ["11\n10", "1\n01", "000\n101", "1101\n1111", "11000001\n00000001", "01\n10", "0000\n1110", "010101\n101010", "0\n1", "1\n1", "0\n0", "1\n0", "100\n11111", "1000000000000000000000000000000000000011111111000000000000\n0111111111100000000000111111111000000000000000111111110001", "000000000000000000000000000000...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
2
codeforces
bc032e5d3c2c75050a8a48f992de8d6e
Fibonacci Sums
Fibonacci numbers have the following form: Let's consider some non-empty set *S*<==<={*s*1,<=*s*2,<=...,<=*s**k*}, consisting of different Fibonacci numbers. Let's find the sum of values of this set's elements: Let's call the set *S* a number *n*'s decomposition into Fibonacci sum. It's easy to see that several num...
{"inputs": ["2\n13\n16", "10\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10", "10\n24\n37\n42\n58\n60\n73\n79\n84\n92\n99", "5\n484775665757\n968685776575\n687675666422\n348587665784\n373875686864", "1\n123456789101112", "22\n304056783818718320\n491974210728665289\n187917426909946968\n796030994547383610\n912170329762608884\n9839524503...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1
codeforces
bc4528d68579e1604b5cfcbe0e276380
Candies
After passing a test, Vasya got himself a box of $n$ candies. He decided to eat an equal amount of candies each morning until there are no more candies. However, Petya also noticed the box and decided to get some candies for himself. This means the process of eating candies is the following: in the beginning Vasya cho...
{"inputs": ["68", "1", "2", "42", "43", "756", "999999972", "999999973", "1000000000000000000", "6", "3", "4", "5", "66", "67", "1000", "10000", "100500", "1000000", "10000000", "100000000", "123456789", "543212345", "505050505", "777777777", "888888871", "1000000000", "999999999999999973", "999999999999999998", "99999...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
56
codeforces
bc613d8c5d133aa3218104a12bd2c957
Ant colony
Mole is hungry again. He found one ant colony, consisting of *n* ants, ordered in a row. Each ant *i* (1<=≤<=*i*<=≤<=*n*) has a strength *s**i*. In order to make his dinner more interesting, Mole organizes a version of «Hunger Games» for the ants. He chooses two numbers *l* and *r* (1<=≤<=*l*<=≤<=*r*<=≤<=*n*) and each...
{"inputs": ["5\n1 3 2 4 2\n4\n1 5\n2 5\n3 5\n4 5"], "outputs": ["4\n4\n1\n1"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
3
codeforces
bc64e74229636684b4bed21608cbda11
Billiard
Consider a [billiard table](https://en.wikipedia.org/wiki/Billiard_table) of rectangular size $n \times m$ with four pockets. Let's introduce a coordinate system with the origin at the lower left corner (see the picture). There is one ball at the point $(x, y)$ currently. Max comes to the table and strikes the ball. ...
{"inputs": ["4 3 2 2 -1 1", "4 4 2 0 1 1", "10 10 10 1 -1 0", "1000000000 1000000000 1 1000000000 0 1", "2 1 1 0 -1 -1", "4 2 1 2 1 1", "5 3 4 3 1 -1", "15 9 1 1 1 1", "15 9 1 1 -1 -1", "15 9 2 1 1 1", "15 9 2 1 -1 1", "1000000000 999999999 999999998 999999999 -1 -1", "1000000000 999999999 999999998 999999999 -1 1", "1...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
5
codeforces
bc675e3dd359f3855d27c61fbbe05bb0
Bear and Strings
The bear has a string *s*<==<=*s*1*s*2... *s*|*s*| (record |*s*| is the string's length), consisting of lowercase English letters. The bear wants to count the number of such pairs of indices *i*,<=*j* (1<=≤<=*i*<=≤<=*j*<=≤<=|*s*|), that string *x*(*i*,<=*j*)<==<=*s**i**s**i*<=+<=1... *s**j* contains at least one string...
{"inputs": ["bearbtear", "bearaabearc", "pbearbearhbearzqbearjkterasjhy", "pbearjbearbebearnbabcffbearbearwubearjezpiorrbearbearjbdlbearbearqbearjbearwipmsbearoaftrsebearzsnqb", "bear", "a", "be"], "outputs": ["6", "20", "291", "4419", "1", "0", "0"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
145
codeforces
bc6d7c53a34b7bb783f08170fd4f3ffb
Subsequences
For the given sequence with *n* different elements find the number of increasing subsequences with *k*<=+<=1 elements. It is guaranteed that the answer is not greater than 8·1018. First line contain two integer values *n* and *k* (1<=≤<=*n*<=≤<=105,<=0<=≤<=*k*<=≤<=10) — the length of sequence and the number of elements...
{"inputs": ["5 2\n1\n2\n3\n5\n4", "1 0\n1", "2 1\n1\n2", "2 1\n2\n1", "3 2\n1\n2\n3", "3 1\n1\n3\n2", "3 1\n2\n1\n3", "3 1\n2\n3\n1", "3 1\n3\n1\n2", "3 2\n3\n2\n1", "10 2\n6\n10\n9\n7\n1\n2\n8\n5\n4\n3", "100 7\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n11\n12\n13\n14\n15\n16\n17\n18\n19\n20\n21\n22\n23\n24\n25\n26\n27\n28\n29\n...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
6
codeforces
bc958cdf56381e768a6fa20968b74312
Congruence Equation
Given an integer $x$. Your task is to find out how many positive integers $n$ ($1 \leq n \leq x$) satisfy $$n \cdot a^n \equiv b \quad (\textrm{mod}\;p),$$ where $a, b, p$ are all known constants. The only line contains four integers $a,b,p,x$ ($2 \leq p \leq 10^6+3$, $1 \leq a,b &lt; p$, $1 \leq x \leq 10^{12}$). It i...
{"inputs": ["2 3 5 8", "4 6 7 13", "233 233 10007 1", "338792 190248 339821 152634074578", "629260 663548 739463 321804928248", "656229 20757 818339 523535590429", "1000002 1000002 1000003 1000000000000", "345 2746 1000003 5000000", "802942 824238 836833 605503824329", "1 1 2 880336470888", "2 2 3 291982585081", "69960...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
3
codeforces
bcbdca7bed3cf5b0c900d268a0fbb27e
Casinos and travel
John has just bought a new car and is planning a journey around the country. Country has *N* cities, some of which are connected by bidirectional roads. There are *N*<=-<=1 roads and every city is reachable from any other city. Cities are labeled from 1 to *N*. John first has to select from which city he will start hi...
{"inputs": ["2\n1 2", "3\n1 2\n2 3", "4\n1 2\n2 3\n3 4"], "outputs": ["4", "10", "24"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
6
codeforces
bcbfe74a23a31ba03505e0c77eeef23c
Alena And The Heater
"We've tried solitary confinement, waterboarding and listening to Just In Beaver, to no avail. We need something extreme." "Little Alena got an array as a birthday present..." The array *b* of length *n* is obtained from the array *a* of length *n* and two integers *l* and *r* (*l*<=≤<=*r*) using the following proced...
{"inputs": ["5\n1 2 3 4 5\n00001", "10\n-10 -9 -8 -7 -6 6 7 8 9 10\n0000111110", "10\n-8 -9 -9 -7 -10 -10 -8 -8 -9 -10\n0000000011", "11\n226 226 226 226 226 227 1000000000 1000000000 228 1000000000 1000000000\n00001111110", "95\n-97 -98 -92 -93 94 96 91 98 95 85 90 86 84 83 81 79 82 79 73 -99 -91 -93 -92 -97 -85 -88 -...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
23
codeforces
bcc97263183979d209e5ab6a23185300
Field expansion
In one of the games Arkady is fond of the game process happens on a rectangular field. In the game process Arkady can buy extensions for his field, each extension enlarges one of the field sizes in a particular number of times. Formally, there are *n* extensions, the *i*-th of them multiplies the width or the length (b...
{"inputs": ["3 3 2 4 4\n2 5 4 10", "3 3 3 3 5\n2 3 5 4 2", "5 5 1 2 3\n2 2 3", "3 4 1 1 3\n2 3 2", "572 540 6 2 12\n2 3 2 2 2 3 3 3 2 2 2 2", "375 905 1 1 17\n2 2 3 3 3 3 3 3 2 2 2 2 3 2 2 2 3", "37 23 4 1 16\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2", "20 19 6 8 18\n3 4 2 3 4 3 2 4 2 2 4 2 4 3 2 4 4 2", "11 11 5 3 11\n4 4 2 4 ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1
codeforces
bcce2d002f657ac7dccfcbef1ce7137d
Average Numbers
You are given a sequence of positive integers *a*1,<=*a*2,<=...,<=*a**n*. Find all such indices *i*, that the *i*-th element equals the arithmetic mean of all other elements (that is all elements except for this one). The first line contains the integer *n* (2<=≤<=*n*<=≤<=2·105). The second line contains elements of th...
{"inputs": ["5\n1 2 3 4 5", "4\n50 50 50 50", "3\n2 3 1", "2\n4 2", "2\n1 1", "10\n3 3 3 3 3 4 3 3 3 2", "10\n15 7 10 7 7 7 4 4 7 2", "6\n2 2 2 2 2 2", "6\n3 3 3 3 3 3", "4\n6 6 6 7", "2\n1 2", "3\n3 3 4", "5\n7 6 6 6 6", "4\n3 5 5 9", "3\n99 100 99", "4\n5 6 5 5", "6\n1 1 2 1 1 1", "2\n4 5", "4\n1 1 1 2", "3\n1 2 4", ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
130
codeforces
bcd6a289c4ca64bddbb3a92d687dfda3
Sum of Nestings
Recall that the bracket sequence is considered regular if it is possible to insert symbols '+' and '1' into it so that the result is a correct arithmetic expression. For example, a sequence "(()())" is regular, because we can get correct arithmetic expression insering symbols '+' and '1': "((1+1)+(1+1))". Also the foll...
{"inputs": ["3 1", "4 6", "2 5", "1 0", "2 0", "2 1", "3 0", "10 42", "3 2", "3 3", "4 1", "4 2", "4 0", "4 3", "4 4", "4 5", "20 132", "5 0", "5 1", "5 2", "5 3", "5 4", "5 5", "5 6", "5 7", "5 8", "5 9", "5 10", "5 11", "50 282", "100 4298", "201 19557", "301 43259", "333 3286", "400 14432", "500 12169", "1000 101063...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
9
codeforces
bce21ee8b1160c20c0b326ab3867d800
none
Squirrel Liss lived in a forest peacefully, but unexpected trouble happens. Stones fall from a mountain. Initially Squirrel Liss occupies an interval [0,<=1]. Next, *n* stones will fall and Liss will escape from the stones. The stones are numbered from 1 to *n* in order. The stones always fall to the center of Liss's ...
{"inputs": ["llrlr", "rrlll", "lrlrr", "lllrlrllrl", "llrlrrrlrr", "rlrrrllrrr", "lrrlrrllrrrrllllllrr", "rlrrrlrrrllrrllrlrll", "lllrrlrlrllrrrrrllrl", "rrrllrrrlllrlllrlrrr", "rrlllrrrlrrlrrrlllrlrlrrrlllrllrrllrllrrlrlrrllllrlrrrrlrlllrlrrrlrlrllrlrlrrlrrllrrrlrlrlllrrllllrl", "llrlrlllrrllrllllrlrrlrlrrllrlrlrrlrrr...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
145
codeforces
bcf965fe41db5c767e712d73903ad8b4
IQ Test
Petya is preparing for IQ test and he has noticed that there many problems like: you are given a sequence, find the next number. Now Petya can solve only problems with arithmetic or geometric progressions. Arithmetic progression is a sequence *a*1, *a*1<=+<=*d*, *a*1<=+<=2*d*, ..., *a*1<=+<=(*n*<=-<=1)*d*, where *a*1 ...
{"inputs": ["836 624 412 200", "1 334 667 1000", "501 451 400 350", "836 624 412 200", "1 334 667 1000", "11 234 457 680", "640 431 222 13", "1 1 1 1", "1 10 100 1000", "3 18 108 648", "512 384 288 216", "891 297 99 33", "64 160 400 1000", "501 451 400 350", "501 450 400 350", "4 32 48 64", "9 8 7 5", "992 994 998 1000...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
15
codeforces
bcfaa0ca75d2308244afef49d1cea846
Eight Point Sets
Gerald is very particular to eight point sets. He thinks that any decent eight point set must consist of all pairwise intersections of three distinct integer vertical straight lines and three distinct integer horizontal straight lines, except for the average of these nine points. In other words, there must be three int...
{"inputs": ["0 0\n0 1\n0 2\n1 0\n1 2\n2 0\n2 1\n2 2", "0 0\n1 0\n2 0\n3 0\n4 0\n5 0\n6 0\n7 0", "1 1\n1 2\n1 3\n2 1\n2 2\n2 3\n3 1\n3 2", "0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0", "1000000 1000000\n1000000 999999\n1000000 999998\n999999 1000000\n999999 999998\n999998 1000000\n999998 999999\n999998 999998", "0 0\n1 0\n0...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
36
codeforces
bd184280a9f5454d5dab9c2732b3319e
Login Verification
When registering in a social network, users are allowed to create their own convenient login to make it easier to share contacts, print it on business cards, etc. Login is an arbitrary sequence of lower and uppercase latin letters, digits and underline symbols («_»). However, in order to decrease the number of frauds ...
{"inputs": ["1_wat\n2\n2_wat\nwat_1", "000\n3\n00\nooA\noOo", "_i_\n3\n__i_\n_1_\nI", "La0\n3\n2a0\nLa1\n1a0", "abc\n1\naBc", "0Lil\n2\nLIL0\n0Ril", "iloO\n3\niIl0\noIl0\nIooO", "L1il0o1L1\n5\niLLoLL\noOI1Io10il\nIoLLoO\nO01ilOoI\nI10l0o", "ELioO1lOoOIOiLoooi1iolul1O\n7\nOoEIuOIl1ui1010uiooOoi0Oio001L0EoEolO0\nOLIoOEuo...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
193
codeforces
bd2451122914e33f4f8c5309b0ce78a4
Ralph And His Magic Field
Ralph has a magic field which is divided into *n*<=×<=*m* blocks. That is to say, there are *n* rows and *m* columns on the field. Ralph can put an integer in each block. However, the magic field doesn't always work properly. It works only if the product of integers in each row and each column equals to *k*, where *k* ...
{"inputs": ["1 1 -1", "1 3 1", "3 3 -1", "2 7 1", "1 1 1", "2 4 -1", "173 69 -1", "110 142 1", "162 162 -1", "49 153 -1", "94 182 1", "106666666 233333333 1", "2 2 1", "146 34 -1", "94 86 -1", "2529756051797760 2682355969139391 -1", "3126690179932000 2474382898739836 -1", "3551499873841921 2512677762780671 -1", "361345...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
18
codeforces
bd3cadf754cab70e6a2d233db4f043b8
Educational Game
The Smart Beaver from ABBYY began to develop a new educational game for children. The rules of the game are fairly simple and are described below. The playing field is a sequence of *n* non-negative integers *a**i* numbered from 1 to *n*. The goal of the game is to make numbers *a*1,<=*a*2,<=...,<=*a**k* (i.e. some pr...
{"inputs": ["4\n1 0 1 2", "8\n1 2 3 4 5 6 7 8", "5\n4 1 4 7 6", "9\n13 13 7 11 3 9 3 5 5", "30\n8 17 20 15 18 15 20 10 5 13 5 4 15 9 11 14 18 15 7 16 18 9 17 7 10 9 5 13 17 16", "80\n72 66 82 46 44 22 63 92 71 65 5 30 45 84 29 73 9 90 25 19 26 15 12 29 33 19 85 92 91 66 83 39 100 53 20 99 11 81 26 41 36 51 21 72 28 100...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
76
codeforces
bd4762d12fc7e77b0c0d4de102cb8527
Toy Cars
Little Susie, thanks to her older brother, likes to play with cars. Today she decided to set up a tournament between them. The process of a tournament is described in the next paragraph. There are *n* toy cars. Each pair collides. The result of a collision can be one of the following: no car turned over, one car turne...
{"inputs": ["3\n-1 0 0\n0 -1 1\n0 2 -1", "4\n-1 3 3 3\n3 -1 3 3\n3 3 -1 3\n3 3 3 -1", "1\n-1", "2\n-1 0\n0 -1", "2\n-1 1\n2 -1", "2\n-1 2\n1 -1", "2\n-1 3\n3 -1"], "outputs": ["2\n1 3 ", "0", "1\n1 ", "2\n1 2 ", "1\n2 ", "1\n1 ", "0"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
18
codeforces
bd5208069eb280e2184f0cb0354c9f46
Roman Digits
Let's introduce a number system which is based on a roman digits. There are digits I, V, X, L which correspond to the numbers $1$, $5$, $10$ and $50$ respectively. The use of other roman digits is not allowed. Numbers in this system are written as a sequence of one or more digits. We define the value of the sequence s...
{"inputs": ["1", "2", "10", "1000", "2000", "5000", "10000", "111199", "101232812", "1000000000", "3", "4", "5", "6", "7", "8", "9", "11", "12", "13", "55", "100", "150", "1200", "9999999", "100000000", "500000000", "600000000", "709000900", "999999999", "12", "10", "20", "35", "56", "83", "116", "155", "198", "244", "...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
61
codeforces
bd719ab213ef0b26f27fe550275da0a6
Bishwock
Bishwock is a chess figure that consists of three squares resembling an "L-bar". This figure can be rotated by 90, 180 and 270 degrees so it can have four possible states: Bishwocks don't attack any squares and can even occupy on the adjacent squares as long as they don't occupy the same square. Vasya has a board wi...
{"inputs": ["00\n00", "00X00X0XXX0\n0XXX0X00X00", "0X0X0\n0X0X0", "0XXX0\n00000", "0\n0", "0\nX", "X\n0", "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\nXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", "0000X0X...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
64
codeforces
bd9edbfd06ea3a9c193aa506376798d5
Queue at the School
During the break the schoolchildren, boys and girls, formed a queue of *n* people in the canteen. Initially the children stood in the order they entered the canteen. However, after a while the boys started feeling awkward for standing in front of the girls in the queue and they started letting the girls move forward ea...
{"inputs": ["5 1\nBGGBG", "5 2\nBGGBG", "4 1\nGGGB", "2 1\nBB", "2 1\nBG", "6 2\nBBGBBG", "8 3\nBBGBGBGB", "10 3\nBBGBBBBBBG", "22 7\nGBGGBGGGGGBBBGGBGBGBBB", "50 4\nGBBGBBBGGGGGBBGGBBBBGGGBBBGBBBGGBGGBGBBBGGBGGBGGBG", "50 8\nGGGGBGGBGGGBGBBBGGGGGGGGBBGBGBGBBGGBGGBGGGGGGGGBBG", "50 30\nBGGGGGGBGGBGBGGGGBGBBGBBBGGBBBGBG...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
274
codeforces
bdb9dc8c6e0599d351c32f5631a32ceb
Igor and his way to work
Woken up by the alarm clock Igor the financial analyst hurried up to the work. He ate his breakfast and sat in his car. Sadly, when he opened his GPS navigator, he found that some of the roads in Bankopolis, the city where he lives, are closed due to road works. Moreover, Igor has some problems with the steering wheel,...
{"inputs": ["5 5\nS....\n****.\n.....\n.****\n..T..", "1 2\nST", "3 1\nS\n*\nT", "3 3\n*..\n...\nTS.", "3 3\nT.*\n*.*\n*S*", "7 7\n.S.****\n...*.*.\n.****..\n.*.**.*\n..T*...\n***..*.\n*******", "3 3\n**T\n*S*\n***", "2 2\nST\n*.", "2 2\nS.\n.T", "2 2\nTS\n.*", "2 2\n.T\nS*"], "outputs": ["NO", "YES", "NO", "YES", "YES...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
16
codeforces
bdbd3d0e9509abf077169578711b6d9d
Cookies
Olga came to visit the twins Anna and Maria and saw that they have many cookies. The cookies are distributed into bags. As there are many cookies, Olga decided that it's no big deal if she steals a bag. However, she doesn't want the sisters to quarrel because of nothing when they divide the cookies. That's why Olga wan...
{"inputs": ["1\n1", "10\n1 2 2 3 4 4 4 2 2 2", "11\n2 2 2 2 2 2 2 2 2 2 99", "2\n1 1", "2\n2 2", "2\n1 2", "7\n7 7 7 7 7 7 7", "8\n1 2 3 4 5 6 7 8", "100\n1 1 1 1 1 2 2 2 2 2 1 1 1 1 1 2 2 2 2 2 1 1 1 1 1 2 2 2 2 2 1 1 1 1 1 2 2 2 2 2 1 1 1 1 1 2 2 2 2 2 1 1 1 1 1 2 2 2 2 2 1 1 1 1 1 2 2 2 2 2 1 1 1 1 1 2 2 2 2 2 1 1 1...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
729
codeforces
bdc6c256029b80385a04823c5aed31f5
Stages
Natasha is going to fly to Mars. She needs to build a rocket, which consists of several stages in some order. Each of the stages is defined by a lowercase Latin letter. This way, the rocket can be described by the string — concatenation of letters, which correspond to the stages. There are $n$ stages available. The ro...
{"inputs": ["5 3\nxyabd", "7 4\nproblem", "2 2\nab", "12 1\nabaabbaaabbb", "50 13\nqwertyuiopasdfghjklzxcvbnmaaaaaaaaaaaaaaaaaaaaaaaa", "50 14\nqwertyuiopasdfghjklzxcvbnmaaaaaaaaaaaaaaaaaaaaaaaa", "1 1\na", "50 1\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "50 2\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
213
codeforces
bdccebbc59ea21c3a871ae1558ed6845
The Sum of the k-th Powers
There are well-known formulas: , , . Also mathematicians found similar formulas for higher degrees. Find the value of the sum modulo 109<=+<=7 (so you should find the remainder after dividing the answer by the value 109<=+<=7). The only line contains two integers *n*,<=*k* (1<=≤<=*n*<=≤<=109,<=0<=≤<=*k*<=≤<=106). Pri...
{"inputs": ["4 1", "4 2", "4 3", "4 0", "10 0", "1 1", "1 0", "1 1000000", "1000000000 0", "100 100", "10000 100", "100 10000", "1000000000 1000000", "1000000 1000000", "999999 1000000", "77674473 447444", "333312494 795258", "761637147 673329", "335185991 514401", "203702132 355473", "1000000000 999935"], "outputs": [...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
5
codeforces
bdd1384c3c4e5c12f47e15657aa8931f
Square and Rectangles
You are given *n* rectangles. The corners of rectangles have integer coordinates and their edges are parallel to the *Ox* and *Oy* axes. The rectangles may touch each other, but they do not overlap (that is, there are no points that belong to the interior of more than one rectangle). Your task is to determine if the ...
{"inputs": ["5\n0 0 2 3\n0 3 3 5\n2 0 5 2\n3 2 5 5\n2 2 3 3", "4\n0 0 2 3\n0 3 3 5\n2 0 5 2\n3 2 5 5", "5\n0 0 10000 20000\n10000 0 15000 19999\n10000 19999 14999 20000\n0 20000 15000 31400\n15000 0 31400 31400", "5\n0 0 10000 20000\n10000 0 15000 19999\n10000 19999 15000 20000\n0 20000 15000 31400\n15000 0 31400 31400...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
10
codeforces
bde75bac39cbfe4af0d371bb6c7c6336
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...
{"inputs": ["4 10\n3 4 7 2", "10 12\n16 3 24 13 9 8 7 5 12 12", "2 2\n9 9", "2 2\n8 8", "5 50\n1 1 1 1 1", "5 50\n100 150 200 100 50"], "outputs": ["16", "13", "2", "0", "5", "0"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
52
codeforces
bdfe2b1e3fe543e13b9b8077113d91f6
Oleg and shares
Oleg the bank client checks share prices every day. There are *n* share prices he is interested in. Today he observed that each second exactly one of these prices decreases by *k* rubles (note that each second exactly one price changes, but at different seconds different prices can change). Prices can become negative. ...
{"inputs": ["3 3\n12 9 15", "2 2\n10 9", "4 1\n1 1000000000 1000000000 1000000000", "1 11\n123", "20 6\n38 86 86 50 98 62 32 2 14 62 98 50 2 50 32 38 62 62 8 14", "20 5\n59 54 19 88 55 100 54 3 6 13 99 38 36 71 59 6 64 85 45 54", "100 10\n340 70 440 330 130 120 340 210 440 110 410 120 180 40 50 230 70 110 310 360 480 7...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
171
codeforces
be28a9f0e51e26043794e8ef4aac3703
Work Group
One Big Software Company has *n* employees numbered from 1 to *n*. The director is assigned number 1. Every employee of the company except the director has exactly one immediate superior. The director, of course, doesn't have a superior. We will call person *a* a subordinates of another person *b*, if either *b* is an...
{"inputs": ["7\n-1 3\n1 2\n1 1\n1 4\n4 5\n4 3\n5 2", "1\n-1 42", "2\n-1 3\n1 2", "3\n-1 3\n1 1\n1 2", "3\n-1 1\n1 2\n1 3", "3\n-1 3\n1 2\n2 1", "20\n-1 100\n1 10\n2 26\n2 33\n3 31\n2 28\n1 47\n6 18\n6 25\n9 2\n4 17\n6 18\n6 2\n6 30\n13 7\n5 25\n7 11\n11 7\n17 40\n12 43", "20\n-1 100\n1 35\n2 22\n3 28\n3 2\n4 8\n3 17\n2...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1
codeforces
be357e1a04067eead63b9cf1cc2b9af5
Little Frog
Once upon a time a little frog whose name was Vasya decided to travel around his home swamp. Overall there are *n* mounds on the swamp, located on one line. The distance between the neighboring mounds is one meter. Vasya wants to visit all the mounds in one day; besides, he wants to visit each one exactly once. For tha...
{"inputs": ["2", "3", "4", "5", "6", "1", "9149", "2877", "2956", "3035", "3114", "3193", "3273", "7000", "7079", "4653", "9995", "9996", "9997", "9998", "9999", "10000"], "outputs": ["1 2 ", "1 3 2 ", "1 4 2 3 ", "1 5 2 4 3 ", "1 6 2 5 3 4 ", "1 ", "1 9149 2 9148 3 9147 4 9146 5 9145 6 9144 7 9143 8 9142 9 9141 10 914...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
123
codeforces
be67cd8ea92d99b084fd6081677642af
Tree of Life (easy)
Heidi has finally found the mythical Tree of Life – a legendary combinatorial structure which is said to contain a prophecy crucially needed to defeat the undead armies. On the surface, the Tree of Life is just a regular undirected tree well-known from computer science. This means that it is a collection of *n* points...
{"inputs": ["4\n1 2\n1 3\n1 4", "5\n1 2\n2 3\n3 4\n3 5", "2\n1 2", "3\n2 1\n3 2", "10\n5 1\n1 2\n9 3\n10 5\n6 3\n8 5\n2 7\n2 3\n9 4"], "outputs": ["3", "4", "0", "1", "11"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
24
codeforces
beb216e4c28803c082eec7de44f0dd98
none
Petya loves lucky numbers very much. Everybody knows that lucky numbers are positive integers whose decimal record contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Petya has two strings *a* and *b* of the same length *n*. The strings consist only of lucky digits...
{"inputs": ["47\n74", "774\n744", "777\n444", "74747474\n77777777", "444444444444\n777777777777", "4744744447774474447474774\n4477774777444444444777447", "7\n4", "4\n7", "7777777777\n7777777774", "47777777777\n77777777774", "47747477747744447774774444444777444747474747777774\n4477744477447744777744477447777747777444447...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
110
codeforces
bec9ea76bca8acdbb8400cd3fe1e396f
The Artful Expedient
Rock... Paper! After Karen have found the deterministic winning (losing?) strategy for rock-paper-scissors, her brother, Koyomi, comes up with a new game as a substitute. The game works as follows. A positive integer *n* is decided first. Both Koyomi and Karen independently choose *n* distinct positive integers, deno...
{"inputs": ["3\n1 2 3\n4 5 6", "5\n2 4 6 8 10\n9 7 5 3 1", "1\n1\n2000000", "2\n97153 2000000\n1999998 254", "15\n31 30 29 28 27 26 25 24 23 22 21 20 19 18 17\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15", "30\n79656 68607 871714 1858841 237684 1177337 532141 161161 1111201 527235 323345 1979059 665353 507265 1290761 610606 12...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
84
codeforces
bee568ff74ad54cec8202b1f59786496
Physics Practical
One day Vasya was on a physics practical, performing the task on measuring the capacitance. He followed the teacher's advice and did as much as *n* measurements, and recorded the results in the notebook. After that he was about to show the results to the teacher, but he remembered that at the last lesson, the teacher h...
{"inputs": ["6\n4 5 3 8 3 7", "4\n4 3 2 4", "6\n5 6 4 9 4 8", "4\n5 4 1 5", "2\n3 2", "10\n39 9 18 13 6 16 47 15 1 24", "20\n43 49 46 46 40 41 49 49 48 30 35 36 33 34 42 38 40 46 50 45", "30\n6 1 26 13 16 30 16 23 9 1 5 14 7 2 17 22 21 23 16 3 5 17 22 10 1 24 4 30 8 18", "50\n3 61 16 13 13 12 3 8 14 16 1 32 8 23 29 7 2...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
71
codeforces
beedede080fa2c18f6b59e2bbe40ce40
Malek Dance Club
As a tradition, every year before IOI all the members of Natalia Fan Club are invited to Malek Dance Club to have a fun night together. Malek Dance Club has 2*n* members and coincidentally Natalia Fan Club also has 2*n* members. Each member of MDC is assigned a unique id *i* from 0 to 2*n*<=-<=1. The same holds for eac...
{"inputs": ["11", "01", "1", "1111111111111111111111111111111111", "0000000000000000000000000000000000000", "11111111111111111111111111111111111000000000000000000000000000", "00000000000000000000111111111111111111111111111111111111111111", "10100101000010011110101011011110001", "0101010000101011111100111100100010101001...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
22
codeforces
bf3e927823c777d2ef7bd32bc83e59eb
Easter Eggs
The Easter Rabbit laid *n* eggs in a circle and is about to paint them. Each egg should be painted one color out of 7: red, orange, yellow, green, blue, indigo or violet. Also, the following conditions should be satisfied: - Each of the seven colors should be used to paint at least one egg. - Any four eggs lying s...
{"inputs": ["8", "13", "7", "10", "14", "50", "9", "11", "12", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "28", "29", "34", "43", "61", "79", "81", "92", "95", "96", "97", "98", "99", "100"], "outputs": ["ROYGBIVG", "ROYGBIVOYGBIV", "ROYGBIV", "ROYGBIVYGB", "ROYGBIVROYGBIV", "ROYGBIVROYGBIVROYGBI...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
274
codeforces
bf4dd0423ecea20ddef0b68b094f200c
Holiday Of Equality
In Berland it is the holiday of equality. In honor of the holiday the king decided to equalize the welfare of all citizens in Berland by the expense of the state treasury. Totally in Berland there are *n* citizens, the welfare of each of them is estimated as the integer in *a**i* burles (burle is the currency in Berl...
{"inputs": ["5\n0 1 2 3 4", "5\n1 1 0 1 1", "3\n1 3 1", "1\n12", "3\n1 2 3", "14\n52518 718438 358883 462189 853171 592966 225788 46977 814826 295697 676256 561479 56545 764281", "21\n842556 216391 427181 626688 775504 168309 851038 448402 880826 73697 593338 519033 135115 20128 424606 939484 846242 756907 377058 24154...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1,122
codeforces
bf66bc37c82f2c30ec50a774ce6d0932
Coat of Anticubism
As some of you know, cubism is a trend in art, where the problem of constructing volumetrical shape on a plane with a combination of three-dimensional geometric shapes comes to the fore. A famous sculptor Cicasso, whose self-portrait you can contemplate, hates cubism. He is more impressed by the idea to transmit two-...
{"inputs": ["3\n1 2 1", "5\n20 4 3 2 1", "7\n77486105 317474713 89523018 332007362 7897847 949616701 54820086", "14\n245638694 2941428 4673577 12468 991349408 44735727 14046308 60637707 81525 104620306 88059371 53742651 8489205 3528194", "19\n479740 7703374 196076708 180202968 579604 17429 16916 11989886 30832424 63849...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
147
codeforces
bf68fad205ecadb130b7e87b5aac8a68
Chris and Road
And while Mishka is enjoying her trip... Chris is a little brown bear. No one knows, where and when he met Mishka, but for a long time they are together (excluding her current trip). However, best friends are important too. John is Chris' best friend. Once walking with his friend, John gave Chris the following proble...
{"inputs": ["5 5 1 2\n1 2\n3 1\n4 3\n3 4\n1 4", "3 3 5 2\n3 1\n4 0\n5 1", "3 3 2 4\n0 1\n2 1\n1 2", "3 3 1 1\n0 0\n1 1\n0 2", "9 10 5 2\n22 5\n25 0\n29 0\n31 2\n32 5\n31 8\n29 10\n25 10\n23 8", "10 10 2 4\n-4 5\n-3 2\n-1 0\n3 0\n5 2\n6 5\n5 8\n3 10\n-1 10\n-2 9", "10 10 1 4\n-1 5\n0 2\n2 0\n5 0\n7 1\n9 5\n8 8\n6 10\n2 ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1
codeforces
bf78b5d20ae69dfbd2374b041a0e3b55
Valera and Tubes
Valera has got a rectangle table consisting of *n* rows and *m* columns. Valera numbered the table rows starting from one, from top to bottom and the columns – starting from one, from left to right. We will represent cell that is on the intersection of row *x* and column *y* by a pair of integers (*x*,<=*y*). Valera w...
{"inputs": ["3 3 3", "2 3 1", "2 3 1", "300 300 2", "300 300 150", "300 299 299", "300 300 45000", "300 299 44850", "2 2 2", "2 3 3", "3 3 4", "5 5 12", "7 5 17", "135 91 4352", "32 27 153", "74 83 2667", "296 218 5275", "89 82 2330", "15 68 212", "95 4 177", "60 136 8", "91 183 7827", "2 15 3", "139 275 10770", "114 2...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
91
codeforces
bf841357522a9a2799b0b9ada43e47dd
Ksusha and Array
Ksusha is a beginner coder. Today she starts studying arrays. She has array *a*1,<=*a*2,<=...,<=*a**n*, consisting of *n* positive integers. Her university teacher gave her a task. Find such number in the array, that all array elements are divisible by it. Help her and find the number! The first line contains integer ...
{"inputs": ["3\n2 2 4", "5\n2 1 3 1 6", "3\n2 3 5", "1\n331358794", "5\n506904227 214303304 136194869 838256937 183952885", "2\n500000000 1000000000", "2\n4 6", "5\n10 8 6 4 2", "2\n6 10", "1\n1000000000", "2\n6 8", "5\n2 2 2 2 1000000000", "2\n6 4"], "outputs": ["2", "1", "-1", "331358794", "-1", "500000000", "-1", "2...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
187
codeforces
c008ffb743cb2d9e14ef24a4fd1394ae
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 *x**i* and *y**i* — damage per second and mana cost per second, respectivel...
{"inputs": ["3 100\n1 4 9\n2 19 49\n2 19 49", "10 442006988299\n2 10 47\n1 9 83\n1 15 24\n2 19 47\n2 75 99\n2 85 23\n2 8 33\n2 9 82\n1 86 49\n2 71 49", "2 424978864039\n2 7 3\n2 10 8", "3 10\n1 1 1\n2 1 1\n2 999999 999999", "12 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 9...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1
codeforces
c01e2b377cf5803a3db4c18e169a42d5
Tennis Game
Petya and Gena love playing table tennis. A single match is played according to the following rules: a match consists of multiple sets, each set consists of multiple serves. Each serve is won by one of the players, this player scores one point. As soon as one of the players scores *t* points, he wins the set; then the ...
{"inputs": ["5\n1 2 1 2 1", "4\n1 1 1 1", "4\n1 2 1 2", "8\n2 1 2 1 1 1 1 1", "14\n2 1 2 1 1 1 1 2 1 1 2 1 2 1", "10\n1 1 2 2 1 1 2 2 1 1", "20\n1 1 2 2 2 2 2 2 2 2 2 2 1 2 2 1 2 2 2 1", "186\n2 1 2 1 1 1 1 1 2 1 1 2 2 2 1 1 2 2 1 1 1 2 1 1 2 2 1 1 1 2 2 1 1 1 1 1 2 1 1 1 2 1 2 1 1 2 1 1 1 2 2 2 2 2 2 2 1 2 1 2 1 1 2 1...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1
codeforces
c0315ec500973071a258e2b530a085a5
Maxim Buys an Apartment
Maxim wants to buy an apartment in a new house at Line Avenue of Metropolis. The house has *n* apartments that are numbered from 1 to *n* and are arranged in a row. Two apartments are adjacent if their indices differ by 1. Some of the apartments can already be inhabited, others are available for sale. Maxim often visi...
{"inputs": ["6 3", "10 1", "10 9", "8 0", "8 8", "966871928 890926970", "20 2", "1 0", "1 1", "2 0", "2 1", "2 2", "7 2", "8 3", "9 4", "10 3", "10 4", "10 5", "1000 1000", "1000 333", "1000 334", "999 333", "999 334", "998 332", "998 333", "89 4", "66 50", "88 15", "95 43", "900 344", "777 113", "964 42", "982 867", "...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
82
codeforces
c0519a7dc6f0c45ebc244c6c22cec56d
Max History
You are given an array *a* of length *n*. We define *f**a* the following way: - Initially *f**a*<==<=0, *M*<==<=1; - for every 2<=≤<=*i*<=≤<=*n* if *a**M*<=&lt;<=*a**i* then we set *f**a*<==<=*f**a*<=+<=*a**M* and then set *M*<==<=*i*. Calculate the sum of *f**a* over all *n*! permutations of the array *a* modulo 1...
{"inputs": ["2\n1 3", "3\n1 1 2", "6\n1 4 5 2 3 3", "8\n8 7 5 4 6 6 6 6", "8\n1 2 3 9 100 100 100 100", "1\n364489807", "1\n194945396", "9\n25401015 88843847 702650194 306965770 57623156 571088345 835502151 56113403 116176210", "3\n855856619 518546431 920370158", "7\n686312223 948248999 138090108 566544521 711825575 41...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
3
codeforces
c05fc5f9b4c21dc89887cfb96b7400ea
Colored Balls
There are *n* boxes with colored balls on the table. Colors are numbered from 1 to *n*. *i*-th box contains *a**i* balls, all of which have color *i*. You have to write a program that will divide all balls into sets such that: - each ball belongs to exactly one of the sets, - there are no empty sets, - there is no ...
{"inputs": ["3\n4 7 8", "2\n2 7", "1\n1", "1\n1000000000", "2\n1000000000 1", "2\n9 6", "2\n948507270 461613425", "5\n8 7 4 8 3", "5\n11703 91351 99 16279 50449", "20\n3 2 1 1 1 2 2 2 3 3 1 1 3 2 3 3 2 3 3 2", "20\n895 8894 6182 5852 9830 7562 8854 4004 5909 4979 6863 2987 3586 1319 513 5496 9543 9561 6590 5063", "200\...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
5
codeforces
c086d2e71d8091df7b4eef2dd781beec
Valera and Number
Valera is a coder. Recently he wrote a funny program. The pseudo code for this program is given below: Now Valera wonders: given the values *x*, *k* and *p*, what is the expected value of the resulting number *s*? The first line of the input contains three integers *x*,<=*k*,<=*p* (1<=≤<=*x*<=≤<=109; 1<=≤<=*k*<=≤<=200...
{"inputs": ["1 1 50", "5 3 0", "5 3 25", "1132123 200 0", "1213112 200 100", "490879136 12 75", "114566801 2 55", "331870050 6 98", "252615193 9 45", "224314221 19 51", "510823354 20 18", "573292218 200 77", "465672965 100 95", "853095531 50 72", "254290166 200 95", "206910020 200 4", "680841078 112 48", "92021679 54 2...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1
codeforces
c08a7770e7aaa6e439fb7923a9c9b201
Two Melodies
Alice is a beginner composer and now she is ready to create another masterpiece. And not even the single one but two at the same time! Alice has a sheet with *n* notes written on it. She wants to take two such non-empty non-intersecting subsequences that both of them form a melody and sum of their lengths is maximal....
{"inputs": ["4\n1 2 4 5", "6\n62 22 60 61 48 49", "2\n1 4", "2\n5 4", "10\n9 6 8 5 5 2 8 9 2 2", "10\n7776 32915 1030 71664 7542 72359 65387 75222 95899 40333", "10\n1 1 1 1 1 1 1 1 1 1", "4\n15 11 28 17", "3\n1 36 6", "6\n3 12 4 12 5 6", "6\n7 20 21 22 23 28"], "outputs": ["4", "5", "2", "2", "9", "6", "10", "2", "3",...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1
codeforces
c0c1479e7ce5028f5eaa529aedd3e85c
Bars
Polycarp's workday lasts exactly $n$ minutes. He loves chocolate bars and can eat one bar in one minute. Today Polycarp has $k$ bars at the beginning of the workday. In some minutes of the workday Polycarp has important things to do and in such minutes he is not able to eat a chocolate bar. In other minutes he can eit...
{"inputs": ["3 3\n010", "8 3\n01010110", "9 5\n001100110", "2 2\n00", "3 2\n010", "3 2\n000", "3 3\n000", "4 2\n0000", "4 2\n0100", "4 2\n0010", "4 2\n0110", "4 3\n0000", "4 3\n0010", "4 3\n0100", "4 3\n0110", "4 4\n0000", "4 4\n0100", "4 4\n0010", "4 4\n0110", "10 3\n0111011010", "100 19\n00110111100111111110101111011...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
7
codeforces
c0c31df16741dd7d0059f2a9ec8f3864
Super Agent
There is a very secret base in Potatoland where potato mash is made according to a special recipe. The neighbours from Porridgia decided to seize this recipe and to sell it to Pilauland. For this mission they have been preparing special agent Pearlo for many years. When, finally, Pearlo learned all secrets of espionage...
{"inputs": ["XX.\n...\n.XX", ".X.\n.X.\n.X.", "XXX\nXXX\nXXX", "XXX\nX.X\nXXX", "X..\n.X.\n..X", "...\nX.X\nX..", ".X.\nX.X\n.X.", "X.X\n.X.\nX.X", "...\n...\n..X", "XXX\n...\nXXX", "..X\nX..\n..X", ".X.\n...\nX.X", "X.X\nX.X\nX.X", ".X.\nX.X\nXX.", "...\nXXX\nXXX", "XXX\n..X\nXXX", "X..\nX.X\n.X.", "...\n..X\nXXX", "....
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
320
codeforces
c0f901607f527b8e6f3e00116e7c7ab4
Petya and Square
Little Petya loves playing with squares. Mum bought him a square 2*n*<=×<=2*n* in size. Petya marked a cell inside the square and now he is solving the following task. The task is to draw a broken line that would go along the grid lines and that would cut the square into two equal parts. The cutting line should not ha...
{"inputs": ["4 1 1", "2 2 2", "8 2 5", "6 1 6", "2 1 1", "2 1 2", "2 2 1", "4 2 2", "4 2 3", "4 2 4", "60 30 30", "60 34 30", "60 31 29", "100 61 30", "100 52 50", "100 51 51", "100 1 2", "100 1 8", "100 19 99", "100 18 82", "100 100 50", "100 51 100", "100 100 100", "6 3 3", "6 4 4", "6 3 1", "6 3 5", "8 4 4", "6 3 2"...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1
codeforces
c1099b4137bcb0dc819f8df0ea6630c3
Multi-judge Solving
Makes solves problems on Decoforces and lots of other different online judges. Each problem is denoted by its difficulty — a positive integer number. Difficulties are measured the same across all the judges (the problem with difficulty *d* on Decoforces is as hard as the problem with difficulty *d* on any other judge)....
{"inputs": ["3 3\n2 1 9", "4 20\n10 3 6 3", "1 1000000000\n1", "1 1\n3", "50 100\n74 55 33 5 83 24 75 59 30 36 13 4 62 28 96 17 6 35 45 53 33 11 37 93 34 79 61 72 13 31 44 75 7 3 63 46 18 16 44 89 62 25 32 12 38 55 75 56 61 82", "100 10\n246 286 693 607 87 612 909 312 621 37 801 558 504 914 416 762 187 974 976 123 635 ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
61
codeforces
c11ed3f7cf93b87239cbf0e5d6a42e5b
Alyona and Numbers
After finishing eating her bun, Alyona came up with two integers *n* and *m*. She decided to write down two columns of integers — the first column containing integers from 1 to *n* and the second containing integers from 1 to *m*. Now the girl wants to count how many pairs of integers she can choose, one from the first...
{"inputs": ["6 12", "11 14", "1 5", "3 8", "5 7", "21 21", "10 15", "1 1", "1 1000000", "1000000 1", "1000000 1000000", "944 844", "368 984", "792 828", "920 969", "640 325", "768 170", "896 310", "320 154", "744 999", "630 843", "54 688", "478 828", "902 184", "31 29", "751 169", "879 14", "7 858", "431 702", "855 355...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
371
codeforces
c12241ccb6ccd236b53aeca845120461
Ciel and Duel
Fox Ciel is playing a card game with her friend Jiro. Jiro has *n* cards, each one has two attributes: *position* (Attack or Defense) and *strength*. Fox Ciel has *m* cards, each one has these two attributes too. It's known that position of all Ciel's cards is Attack. Now is Ciel's battle phase, Ciel can do the follo...
{"inputs": ["2 3\nATK 2000\nDEF 1700\n2500\n2500\n2500", "3 4\nATK 10\nATK 100\nATK 1000\n1\n11\n101\n1001", "2 4\nDEF 0\nATK 0\n0\n0\n1\n1", "1 1\nATK 100\n99", "4 8\nDEF 100\nDEF 200\nDEF 300\nATK 100\n100\n101\n201\n301\n1\n1\n1\n1", "3 4\nDEF 100\nATK 200\nDEF 300\n101\n201\n301\n1", "4 4\nDEF 0\nDEF 0\nDEF 0\nATK ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
5
codeforces
c15f635616d643c4688b14322dc81920
Amr and Music
Amr is a young coder who likes music a lot. He always wanted to learn how to play music but he was busy coding so he got an idea. Amr has *n* instruments, it takes *a**i* days to learn *i*-th instrument. Being busy, Amr dedicated *k* days to learn how to play the maximum possible number of instruments. Amr asked for ...
{"inputs": ["4 10\n4 3 1 2", "5 6\n4 3 1 1 2", "1 3\n4", "2 100\n100 100", "3 150\n50 50 50", "4 0\n100 100 100 100", "100 7567\n100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
192
codeforces
c1728962a6cce0de630f0372867289aa
Game Shopping
Maxim wants to buy some games at the local game shop. There are $n$ games in the shop, the $i$-th game costs $c_i$. Maxim has a wallet which can be represented as an array of integers. His wallet contains $m$ bills, the $j$-th bill has value $a_j$. Games in the shop are ordered from left to right, Maxim tries to buy ...
{"inputs": ["5 4\n2 4 5 2 4\n5 3 4 6", "5 2\n20 40 50 20 40\n19 20", "6 4\n4 8 15 16 23 42\n1000 1000 1000 1000", "5 1\n1 1 1 1 1\n5", "5 1\n10 1 1 1 1\n1000", "5 1\n100 100 100 100 100\n100", "2 1\n2 1\n1", "2 3\n3 1\n2 4 2", "1 5\n4\n1 4 3 3 2", "5 3\n4 2 3 1 1\n2 1 3", "3 5\n5 2 5\n1 4 1 4 2", "7 3\n9 7 10 2 1 1 1\n...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
321
codeforces
c1e7da4ca3f099a03821e7eefe9f889b
Ilya and Escalator
Ilya got tired of sports programming, left university and got a job in the subway. He was given the task to determine the escalator load factor. Let's assume that *n* people stand in the queue for the escalator. At each second one of the two following possibilities takes place: either the first person in the queue en...
{"inputs": ["1 0.50 1", "1 0.50 4", "4 0.20 2", "2000 0.61 2000", "100 1.00 200", "417 0.57 742", "100 0.01 53", "300 0.05 55", "1400 0.02 200", "2000 0.01 234", "1 0.01 2000", "300 0.99 1000", "400 0.96 1754", "2000 0.93 100", "1000 0.90 1733", "1 1.00 1", "2000 1.00 2000", "2000 0.00 2000", "2000 0.01 2000", "2000 0....
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
25
codeforces
c20295e447351fec89195b82e112921a
Preparing Olympiad
You have *n* problems. You have estimated the difficulty of the *i*-th one as integer *c**i*. Now you want to prepare a problemset for a contest, using some of the problems you've made. A problemset for the contest must consist of at least two problems. You think that the total difficulty of the problems of the contes...
{"inputs": ["3 5 6 1\n1 2 3", "4 40 50 10\n10 20 30 25", "5 25 35 10\n10 10 20 10 20", "4 15 60 10\n10 20 30 25", "1 10 20 1\n15", "10 626451 11471247 246428\n369649 684428 303821 287098 422756 301599 720377 177567 515216 750602", "15 1415849 15540979 356865\n8352 960238 276753 259695 712845 945369 60023 920446 181269 ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
67
codeforces
c238239f5c75f82bf35be066d8493e38
Sonya and Queries
Today Sonya learned about long integers and invited all her friends to share the fun. Sonya has an initially empty multiset with integers. Friends give her *t* queries, each of one of the following type: 1. <=+<= *a**i* — add non-negative integer *a**i* to the multiset. Note, that she has a multiset, thus there may b...
{"inputs": ["12\n+ 1\n+ 241\n? 1\n+ 361\n- 241\n? 0101\n+ 101\n? 101\n- 101\n? 101\n+ 4000\n? 0", "4\n+ 200\n+ 200\n- 200\n? 0", "20\n+ 61\n+ 99\n+ 51\n+ 70\n+ 7\n+ 34\n+ 71\n+ 86\n+ 68\n+ 39\n+ 78\n+ 81\n+ 89\n? 10\n? 00\n? 10\n? 01\n? 01\n? 00\n? 00", "20\n+ 13\n+ 50\n+ 9\n? 0\n+ 24\n? 0\n- 24\n? 0\n+ 79\n? 11\n- 13\...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
30
codeforces