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
9a416ed955927b1b6f81fc23c29c339d
News About Credit
Polycarp studies at the university in the group which consists of *n* students (including himself). All they are registrated in the social net "TheContacnt!". Not all students are equally sociable. About each student you know the value *a**i* — the maximum number of messages which the *i*-th student is agree to send p...
{"inputs": ["4\n1 2 1 0", "6\n2 0 1 3 2 0", "3\n0 2 2", "2\n0 0", "2\n1 0", "2\n0 1", "2\n1 1", "3\n1 1 0", "3\n0 1 1", "3\n1 0 0", "3\n2 0 0", "3\n1 0 1", "3\n1 1 1", "40\n3 3 2 1 0 0 0 4 5 4 0 0 0 1 0 0 0 0 0 0 0 0 0 1 0 0 0 2 3 2 0 1 0 0 2 0 3 0 1 0", "100\n1 0 0 2 0 2 0 0 2 0 0 2 0 0 2 2 2 1 1 2 1 2 2 2 1 2 0 1 0 1...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
52
codeforces
9a7436998938b1467172f8fa33f99359
Beaver
After Fox Ciel got off a bus, she found that the bus she was on was a wrong bus and she lost her way in a strange town. However, she fortunately met her friend Beaver Taro and asked which way to go to her castle. Taro's response to her was a string *s*, and she tried to remember the string *s* correctly. However, Ciel...
{"inputs": ["Go_straight_along_this_street\n5\nstr\nlong\ntree\nbiginteger\nellipse", "IhaveNoIdea\n9\nI\nh\na\nv\ne\nN\no\nI\nd", "unagioisii\n2\nioi\nunagi", "abcabcabcabc\n3\nabcabca\nbcab\ncabc", "ThankYouForParticipatingRound71\n6\nForP\noun\nnkYouForP\nTha\nouForP\nound7", "WishYourSolutionPassesFinalTests\n10\nr...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1
codeforces
9a7826eb5e81f31845cc399f45b1734d
Cards Sorting
Vasily has a deck of cards consisting of *n* cards. There is an integer on each of the cards, this integer is between 1 and 100<=000, inclusive. It is possible that some cards have the same integers on them. Vasily decided to sort the cards. To do this, he repeatedly takes the top card from the deck, and if the number...
{"inputs": ["4\n6 3 1 2", "1\n1000", "7\n3 3 3 3 3 3 3", "64\n826 142 89 337 897 891 1004 704 281 644 910 852 147 193 289 384 625 695 416 944 162 939 164 1047 359 114 499 99 713 300 268 316 256 404 852 496 373 322 716 202 689 857 936 806 556 153 137 863 1047 678 564 474 282 135 610 176 855 360 814 144 77 112 354 154", ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
6
codeforces
9a8385b99a56f1addc709bd9e1f938e0
Far Relative’s Problem
Famil Door wants to celebrate his birthday with his friends from Far Far Away. He has *n* friends and each of them can come to the party in a specific range of days of the year from *a**i* to *b**i*. Of course, Famil Door wants to have as many friends celebrating together with him as possible. Far cars are as weird as...
{"inputs": ["4\nM 151 307\nF 343 352\nF 117 145\nM 24 128", "6\nM 128 130\nF 128 131\nF 131 140\nF 131 141\nM 131 200\nM 140 200", "1\nF 68 307", "40\nM 55 363\nF 117 252\nM 157 282\nF 322 345\nM 330 363\nF 154 231\nF 216 352\nF 357 365\nM 279 292\nF 353 359\nF 82 183\nM 78 297\nM 231 314\nM 107 264\nF 34 318\nM 44 244...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
103
codeforces
9a98f12406be8a6bc3b9d8fdb7b920da
Wizards and Huge Prize
One must train much to do well on wizardry contests. So, there are numerous wizardry schools and magic fees. One of such magic schools consists of *n* tours. A winner of each tour gets a huge prize. The school is organised quite far away, so one will have to take all the prizes home in one go. And the bags that you've...
{"inputs": ["3 1 0\n10 20 30\n-1 -1 2", "1 1 1\n100\n123", "5 1 2\n36 44 13 83 63\n-1 2 -1 2 1", "9 9 2\n91 96 99 60 42 67 46 39 62\n5 -1 2 -1 -1 -1 7 -1 3", "1 0 0\n7\n-1", "2 1 2\n80 35\n-1 -1", "4 1 2\n38 15 28 15\n-1 1 -1 -1", "1 0 0\n3\n-1", "7 0 3\n58 29 75 56 47 28 27\n-1 -1 1 -1 1 2 -1", "46 33 12\n3 26 81 86 2...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1
codeforces
9aacd97a71ffc373441cb9235da62de8
Out of Controls
You are given a complete undirected graph. For each pair of vertices you are given the length of the edge that connects them. Find the shortest paths between each pair of vertices in the graph and return the length of the longest of them. The first line of the input contains a single integer *N* (3<=≤<=*N*<=≤<=10). Th...
{"inputs": ["3\n0 1 1\n1 0 4\n1 4 0", "4\n0 1 2 3\n1 0 4 5\n2 4 0 6\n3 5 6 0", "10\n0 16 67 7 82 44 25 13 25 42\n16 0 24 37 63 20 19 87 55 99\n67 24 0 81 19 71 35 6 20 91\n7 37 81 0 82 89 34 80 7 32\n82 63 19 82 0 42 66 96 42 99\n44 20 71 89 42 0 65 94 24 45\n25 19 35 34 66 65 0 97 100 22\n13 87 6 80 96 94 97 0 10 58\n...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
13
codeforces
9aba21af3a0469d2319b606660a3fd70
Hanoi Factory
Of course you have heard the famous task about Hanoi Towers, but did you know that there is a special factory producing the rings for this wonderful game? Once upon a time, the ruler of the ancient Egypt ordered the workers of Hanoi Factory to create as high tower as possible. They were not ready to serve such a strang...
{"inputs": ["3\n1 5 1\n2 6 2\n3 7 3", "4\n1 2 1\n1 3 3\n4 6 2\n5 7 1", "1\n1 2 1", "5\n6 10 4\n9 20 19\n8 11 18\n18 20 1\n19 20 8", "5\n21 25 26\n14 30 22\n6 29 30\n13 23 21\n10 11 5", "5\n45 73 26\n59 73 29\n30 74 9\n59 63 72\n73 84 79", "9\n1 5 1000000000\n23 27 834000000\n6 10 1000000000\n26 30 234500000\n5 9 100000...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
5
codeforces
9ac4a248f5752708fb068e90df52ee94
Police Stations
Inzane finally found Zane with a lot of money to spare, so they together decided to establish a country of their own. Ruling a country is not an easy job. Thieves and terrorists are always ready to ruin the country's peace. To fight back, Zane and Inzane have enacted a very effective law: from each city it must be pos...
{"inputs": ["6 2 4\n1 6\n1 2\n2 3\n3 4\n4 5\n5 6", "6 3 2\n1 5 6\n1 2\n1 3\n1 4\n1 5\n5 6", "10 1 5\n5\n1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 8\n8 9\n9 10", "11 1 5\n6\n1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 8\n8 9\n9 10\n10 11", "2 1 1\n1\n1 2"], "outputs": ["1\n3 ", "2\n4 5 ", "0", "0", "0"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
9
codeforces
9ad5b151abc3e4fc9271a64a2c7a2c25
Alarm Clock
Every evening Vitalya sets *n* alarm clocks to wake up tomorrow. Every alarm clock rings during exactly one minute and is characterized by one integer *a**i* — number of minute after midnight in which it rings. Every alarm clock begins ringing at the beginning of the minute and rings during whole minute. Vitalya will...
{"inputs": ["3 3 2\n3 5 1", "5 10 3\n12 8 18 25 1", "7 7 2\n7 3 4 1 6 5 2", "2 2 2\n1 3", "1 4 1\n1", "2 3 1\n1 2", "5 4 2\n7 2 4 5 6", "7 5 3\n11 3 13 19 5 18 17", "10 7 2\n30 9 1 40 34 4 35 27 11 3", "13 10 4\n5 28 67 70 68 3 84 4 30 82 96 37 49", "14 5 5\n10 20 22 38 16 35 29 15 25 40 32 6 7 19", "15 20 15\n8 18 12 ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
13
codeforces
9b146d320b0d4e4206aa7205457a3b57
none
A factory produces thimbles in bulk. Typically, it can produce up to *a* thimbles a day. However, some of the machinery is defective, so it can currently only produce *b* thimbles each day. The factory intends to choose a *k*-day period to do maintenance and construction; it cannot produce any thimbles during this time...
{"inputs": ["5 2 2 1 8\n1 1 2\n1 5 3\n1 2 1\n2 2\n1 4 2\n1 3 2\n2 1\n2 3", "5 4 10 1 6\n1 1 5\n1 5 5\n1 3 2\n1 5 2\n2 1\n2 2", "1 1 2 1 1\n2 1"], "outputs": ["3\n6\n4", "7\n1", "0"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
4
codeforces
9b1a5be70f80633c7e4ae47a7a6dc1e4
Misha and Permutations Summation
Let's define the sum of two permutations *p* and *q* of numbers 0,<=1,<=...,<=(*n*<=-<=1) as permutation , where *Perm*(*x*) is the *x*-th lexicographically permutation of numbers 0,<=1,<=...,<=(*n*<=-<=1) (counting from zero), and *Ord*(*p*) is the number of permutation *p* in the lexicographical order. For example, ...
{"inputs": ["2\n0 1\n0 1", "2\n0 1\n1 0", "3\n1 2 0\n2 1 0", "2\n0 1\n1 0", "5\n2 1 3 0 4\n2 0 4 3 1", "3\n0 2 1\n1 0 2", "4\n2 0 1 3\n0 2 1 3", "1\n0\n0", "75\n71 69 34 23 13 68 19 45 40 6 74 11 53 24 27 7 50 5 70 47 4 21 25 54 62 30 17 33 52 16 67 15 14 57 38 18 48 29 58 1 8 36 2 35 56 43 44 39 20 10 0 64 3 61 32 22 ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1
codeforces
9b3b7cabb6f4a2f57b5b568d73db2a86
Hongcow Learns the Cyclic Shift
Hongcow is learning to spell! One day, his teacher gives him a word that he needs to learn to spell. Being a dutiful student, he immediately learns how to spell the word. Hongcow has decided to try to make new words from this one. He starts by taking the word he just learned how to spell, and moves the last character ...
{"inputs": ["abcd", "bbb", "yzyz", "abcdefghijklmnopqrstuvwxyabcdefghijklmnopqrstuvwxy", "zclkjadoprqronzclkjadoprqronzclkjadoprqron", "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz", "xyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxy", "y", "ervbfotfedpozygoumbmxeaqegouaqqzqerlykhmvxvvlcaos", "zyzzzyyzyyyzyyzyzy...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
410
codeforces
9b3d30249314dea7abab30deec990ccf
Maxim and Array
Recently Maxim has found an array of *n* integers, needed by no one. He immediately come up with idea of changing it: he invented positive integer *x* and decided to add or subtract it from arbitrary array elements. Formally, by applying single operation Maxim chooses integer *i* (1<=≤<=*i*<=≤<=*n*) and replaces the *i...
{"inputs": ["5 3 1\n5 4 3 5 2", "5 3 1\n5 4 3 5 5", "5 3 1\n5 4 4 5 5", "3 2 7\n5 4 2", "100 1 1\n-1 -1 -2 0 -2 -1 0 0 0 0 2 2 2 2 2 1 0 1 1 1 1 0 1 0 2 0 0 1 1 1 2 2 1 0 0 2 0 1 2 1 2 1 2 2 0 2 0 1 1 0 2 1 1 2 1 1 0 2 2 0 1 1 1 1 1 1 0 2 2 2 2 0 0 0 0 2 2 1 0 2 0 0 2 0 2 1 0 2 2 1 1 2 0 2 0 2 0 0 2 2", "100 5 100\n-45...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
3
codeforces
9b52286e024c26938fb8d41bf4b72191
Delivering Carcinogen
Qwerty the Ranger arrived to the Diatar system with a very important task. He should deliver a special carcinogen for scientific research to planet Persephone. This is urgent, so Qwerty has to get to the planet as soon as possible. A lost day may fail negotiations as nobody is going to pay for an overdue carcinogen. Y...
{"inputs": ["10 0 1\n-10 0 2 8", "50 60 10\n50 60 20 40", "86 -67 50\n-60 -20 91 35", "-137 -45 64\n-86 -61 91 61", "-137 -15 64\n50 -75 91 42", "-137 -15 79\n-173 -94 91 46", "-64 20 79\n-173 -94 91 19", "7 20 89\n-173 -181 91 15", "7 20 19\n67 -69 97 1", "1 1 1\n1 1 2 1", "1 1 1\n-1 -1 2 1", "1 1 1\n1 1 10000 1", "1 ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1
codeforces
9b7cd8cac0955cfb3ebc804ef046164d
none
John Doe has an *n*<=×<=*m* table. John Doe can paint points in some table cells, not more than one point in one table cell. John Doe wants to use such operations to make each square subtable of size *n*<=×<=*n* have exactly *k* points. John Doe wondered, how many distinct ways to fill the table with points are there,...
{"inputs": ["5 6 1", "1 1000000000000000000 0", "100 1000000 5000", "100 1000000000000000000 10000", "2 1791938441 1", "3 783497007 1", "4 1484499480 1", "5 559703685 1", "6 26236608 1", "7 167374275 1", "8 703528038 1", "9 402260913 1", "10 360430679 1", "11 1726671165 1", "12 534773931 1", "13 685597394 1", "14 92214...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1
codeforces
9b7d8b7d5953b5483ce81da2bedb7663
Johny Likes Numbers
Johny likes numbers *n* and *k* very much. Now Johny wants to find the smallest integer *x* greater than *n*, so it is divisible by the number *k*. The only line contains two integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=109). Print the smallest integer *x*<=&gt;<=*n*, so it is divisible by the number *k*. Sample Input 5 3...
{"inputs": ["5 3", "25 13", "26 13", "1 1", "8 8", "14 15", "197 894", "6058 8581", "97259 41764", "453145 333625", "2233224 4394826", "76770926 13350712", "687355301 142098087", "1000000000 999999999", "1000000000 1000000000", "999999999 1000000000", "1000000000 1", "1000000000 2", "999999999 1", "100000000 1", "99999...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
300
codeforces
9b932acf0fb0ce13f3fa6b644a95da8f
Misha, Grisha and Underground
Misha and Grisha are funny boys, so they like to use new underground. The underground has *n* stations connected with *n*<=-<=1 routes so that each route connects two stations, and it is possible to reach every station from any other. The boys decided to have fun and came up with a plan. Namely, in some day in the mor...
{"inputs": ["3 2\n1 1\n1 2 3\n2 3 3", "4 1\n1 2 3\n1 2 3", "2 4\n1\n1 1 1\n1 1 2\n1 2 2\n2 2 2", "5 20\n4 1 1 4\n2 2 5\n3 2 5\n2 3 4\n4 2 5\n4 1 2\n5 3 1\n2 1 2\n4 3 2\n1 3 3\n4 2 5\n5 1 4\n4 5 4\n1 2 4\n3 3 1\n5 4 5\n1 1 1\n1 4 4\n5 3 2\n4 2 1\n3 1 4", "5 20\n5 5 1 4\n1 4 3\n2 4 1\n1 5 5\n5 1 4\n5 1 5\n1 5 5\n5 4 4\n2...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1
codeforces
9b963a2564b7649448d132adb37247ac
Wooden Fence
Vasya has recently bought some land and decided to surround it with a wooden fence. He went to a company called "Wooden board" that produces wooden boards for fences. Vasya read in the catalog of products that the company has at its disposal *n* different types of wood. The company uses the *i*-th type of wood to prod...
{"inputs": ["2 3\n1 2\n2 3", "1 2\n2 2", "6 6\n2 1\n3 2\n2 5\n3 3\n5 1\n2 1", "4 3\n1 2\n1 1\n3 1\n2 2", "4 6\n1 1\n1 2\n3 1\n5 10", "5 10\n1 2\n2 3\n1 2\n3 1\n2 4", "1 4\n4 1", "1 3\n1 1", "4 6\n2 1\n1 2\n2 1\n2 1", "4 10\n4 5\n5 3\n1 4\n1 2", "5 8\n3 1\n2 1\n2 3\n2 1\n3 1", "10 11\n3 10\n10 2\n2 6\n7 6\n8 1\n2 3\n7 1...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
5
codeforces
9bc1f812db3e6751f5a4921f6c4f4349
Design Tutorial: Learn from Life
One way to create a task is to learn from life. You can choose some experience in real life, formalize it and then you will get a new task. Let's think about a scene in real life: there are lots of people waiting in front of the elevator, each person wants to go to a certain floor. We can formalize it in the following...
{"inputs": ["3 2\n2 3 4", "4 2\n50 100 50 100", "10 3\n2 2 2 2 2 2 2 2 2 2", "1 1\n2", "2 1\n2 2", "2 2\n2 2", "11 4\n2 3 4 5 6 7 8 9 10 11 12", "70 1311\n1146 769 1530 1132 877 1352 1295 1282 1086 914 852 1351 1432 847 1105 776 1278 716 1435 749 1320 869 812 1179 1239 1426 1403 1296 1489 1018 848 1215 1278 1203 1386 1...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
8
codeforces
9bcec3c5062b4361bc5c997df54e71e2
Queue on Bus Stop
It's that time of the year when the Russians flood their countryside summer cottages (dachas) and the bus stop has a lot of people. People rarely go to the dacha on their own, it's usually a group, so the people stand in queue by groups. The bus stop queue has *n* groups of people. The *i*-th group from the beginning ...
{"inputs": ["4 3\n2 3 2 1", "3 4\n1 2 1", "1 5\n4", "5 1\n1 1 1 1 1", "6 4\n1 3 2 3 4 1", "6 8\n6 1 1 1 4 5", "10 10\n1 10 1 10 1 1 7 8 6 7", "100 100\n85 50 17 89 65 89 5 20 86 26 16 21 85 14 44 31 87 31 6 2 48 67 8 80 79 1 48 36 97 1 5 30 79 50 78 12 2 55 76 100 54 40 26 81 97 96 68 56 87 14 51 17 54 37 52 33 69 62 3...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
185
codeforces
9bdd3ab4f287777c78d59fd0ff914aeb
Jeff and Rounding
Jeff got 2*n* real numbers *a*1,<=*a*2,<=...,<=*a*2*n* as a birthday present. The boy hates non-integer numbers, so he decided to slightly "adjust" the numbers he's got. Namely, Jeff consecutively executes *n* operations, each of them goes as follows: - choose indexes *i* and *j* (*i*<=≠<=*j*) that haven't been chose...
{"inputs": ["3\n0.000 0.500 0.750 1.000 2.000 3.000", "3\n4469.000 6526.000 4864.000 9356.383 7490.000 995.896", "3\n673.674 9263.142 6780.000 9801.000 4640.000 8244.000", "3\n6470.649 8295.000 8486.000 9855.000 223.000 579.549", "7\n2341.538 9232.119 6646.930 9316.834 5684.000 9078.705 7773.000 3823.674 6357.022 9866....
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
7
codeforces
9be5145fa9a784da2083a40864d8b1e5
Opposites Attract
Everybody knows that opposites attract. That is the key principle of the "Perfect Matching" dating agency. The "Perfect Matching" matchmakers have classified each registered customer by his interests and assigned to the *i*-th client number *t**i* (<=-<=10<=≤<=*t**i*<=≤<=10). Of course, one number can be assigned to an...
{"inputs": ["5\n-3 3 0 0 3", "3\n0 0 0", "1\n0", "1\n5", "2\n0 0", "2\n-3 3", "2\n1 5", "4\n1 -1 1 -1", "10\n1 -1 2 -2 3 -3 4 -4 0 0", "5\n0 0 0 0 0", "4\n4 4 4 -1", "2\n10 -10", "2\n-10 10", "3\n-1 -1 2", "2\n-1 2", "7\n0 10 -10 10 -10 10 10", "5\n-3 2 1 -1 3", "4\n-10 10 -10 10", "4\n1 -1 2 -2"], "outputs": ["3", "3"...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
11
codeforces
9c04b7bcd219710d34a52373f403d770
Competition
The secondary diagonal of a square matrix is a diagonal going from the top right to the bottom left corner. Let's define an *n*-degree staircase as a square matrix *n*<=×<=*n* containing no squares above the secondary diagonal (the picture below shows a 5-degree staircase). The squares of the *n*-degree staircase con...
{"inputs": ["3 3\n2 3\n3 2\n3 3", "1 1\n1 1", "2 3\n1 2\n2 1\n2 2", "2 1\n1 2", "2 2\n1 2\n2 1", "5 5\n1 5\n3 3\n4 3\n4 5\n5 5", "5 5\n2 5\n4 2\n4 4\n5 4\n5 5", "5 5\n1 5\n3 3\n3 5\n5 1\n5 5", "10 5\n5 10\n9 7\n9 10\n10 1\n10 8", "10 20\n2 9\n3 8\n4 7\n4 8\n5 6\n6 5\n6 6\n6 7\n6 9\n7 5\n7 10\n8 6\n8 9\n9 3\n9 6\n10 1\n...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1
codeforces
9c1e83b6cd335be72b10e0717ba0fae9
Diverse Substrings
String diversity is the number of symbols that occur in the string at least once. Diversity of *s* will be denoted by *d*(*s*). For example , *d*("aaa")=1, *d*("abacaba")=3. Given a string *s*, consisting of lowercase Latin letters. Consider all its substrings. Obviously, any substring diversity is a number from 1 to ...
{"inputs": ["abca", "aabacaabbad", "a", "cabaccbcaa", "ccabaccbbb", "accbbaabaa", "bdbdeabeecddebabaebbcaeabeabcadcbcacebdebaaadbcebabacdedbadadbcbdeccabecbecedcbdadbaabdaaaeebbdddcde", "faaacffcdacdbafffebbaecbbddadbafcddfbbafbebedafcbbccdefcfcddbdefbaabbeacbdcadfdfbeffdbccdbbcefdbeacf", "ccdfadbdcdadgcgabgcebbccebeab...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1
codeforces
9c2b194e5181a074182aca336dbe2ee1
The Modcrab
Vova is again playing some computer game, now an RPG. In the game Vova's character received a quest: to slay the fearsome monster called Modcrab. After two hours of playing the game Vova has tracked the monster and analyzed its tactics. The Modcrab has *h*2 health points and an attack power of *a*2. Knowing that, Vova...
{"inputs": ["10 6 100\n17 5", "11 6 100\n12 5", "25 27 91\n10 87", "79 4 68\n9 65", "9 1 20\n4 19", "1 1 100\n100 99", "6 6 100\n12 5", "9 76 78\n86 69", "62 21 10\n47 2", "50 1 2\n70 1", "4 1 2\n10 1", "1 1 2\n3 1", "14 5 2\n99 1", "20 1 5\n8 4", "12 12 19\n83 8", "5 12 11\n4 2", "34 14 18\n74 14"], "outputs": ["4\nST...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
34
codeforces
9c38652ec748744f39327a92d0a89a94
Odds and Ends
Where do odds begin, and where do they end? Where does hope emerge, and will they ever break? Given an integer sequence *a*1,<=*a*2,<=...,<=*a**n* of length *n*. Decide whether it is possible to divide it into an odd number of non-empty subsegments, the each of which has an odd length and begins and ends with odd numb...
{"inputs": ["3\n1 3 5", "5\n1 0 1 5 1", "3\n4 3 1", "4\n3 9 9 3", "1\n1", "5\n100 99 100 99 99", "100\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 100 100 100 100 100 100 1...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
233
codeforces
9c680d17e09521dcfd9dc7aeed589010
Lever
You have a description of a lever as string *s*. We'll represent the string length as record |*s*|, then the lever looks as a horizontal bar with weights of length |*s*|<=-<=1 with exactly one pivot. We will assume that the bar is a segment on the *Ox* axis between points 0 and |*s*|<=-<=1. The decoding of the lever d...
{"inputs": ["=^==", "9===^==1", "2==^7==", "41^52==", "=^2=4=1===1=", "9=6===5==3=9=1=1^7=1==", "85=61=36=^93===4==44==35==94===39===15===", "==88=^95==83=45===8====73===7==7====1=29====29=8=85=", "==41^52==", "2===================^2", "9^=============1", "4=========^=55", "123^321", "7^1=2", "589==^==958"], "outputs":...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
232
codeforces
9c6cea16dc2256c81e8e15748d3d1ad8
Fake News (medium)
Thanks to your help, Heidi is confident that no one can fool her. She has now decided to post some fake news on the HC2 Facebook page. However, she wants to be able to communicate to the HC2 committee that the post is fake, using some secret phrase hidden in the post as a subsequence. To make this method foolproof, she...
{"inputs": ["2", "4", "6", "1", "3", "5", "999983", "1000000", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "1898", "2023", "2152", "2285", "2422", "2563", "2708", "2857", "3010", "3167", "3328", "3493", "3662", "3835", "4012", "4...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
3
codeforces
9c77b4e932176ff9d911680d4f69b20d
Restaurant
A restaurant received *n* orders for the rental. Each rental order reserve the restaurant for a continuous period of time, the *i*-th order is characterized by two time values — the start time *l**i* and the finish time *r**i* (*l**i*<=≤<=*r**i*). Restaurant management can accept and reject orders. What is the maximal...
{"inputs": ["2\n7 11\n4 7", "5\n1 2\n2 3\n3 4\n4 5\n5 6", "6\n4 8\n1 5\n4 7\n2 5\n1 3\n6 8", "1\n1 1", "2\n4 6\n4 8", "3\n22 22\n14 21\n9 25", "4\n20 59\n30 62\n29 45\n29 32", "5\n40 124\n40 117\n67 106\n36 121\n38 102", "6\n124 155\n50 93\n45 120\n54 171\n46 190\n76 179", "7\n94 113\n54 248\n64 325\n280 306\n62 328\n4...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
46
codeforces
9c934e5e7dde1c071061f60eff3f575b
Game
Furik and Rubik love playing computer games. Furik has recently found a new game that greatly interested Rubik. The game consists of *n* parts and to complete each part a player may probably need to complete some other ones. We know that the game can be fully completed, that is, its parts do not form cyclic dependencie...
{"inputs": ["1\n1\n0", "5\n2 2 1 1 3\n1 5\n2 5 1\n2 5 4\n1 5\n0", "7\n1 3 3 1 2 1 1\n0\n1 1\n1 1\n2 1 6\n3 1 2 7\n1 1\n1 1", "2\n2 1\n0\n1 1", "3\n2 1 2\n0\n0\n0", "4\n2 1 1 1\n0\n0\n1 1\n1 3", "6\n1 1 2 3 3 1\n2 2 3\n0\n0\n0\n2 2 1\n1 1", "8\n2 2 2 1 1 2 1 1\n3 5 6 7\n1 5\n2 5 6\n1 5\n0\n1 5\n1 5\n2 5 6", "9\n3 3 2 1 ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
4
codeforces
9caa1077b564df25035a6f1a1e7e12f6
Unusual Sequences
Count the number of distinct sequences *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*) consisting of positive integers such that *gcd*(*a*1,<=*a*2,<=...,<=*a**n*)<==<=*x* and . As this number could be large, print the answer modulo 109<=+<=7. *gcd* here means the [greatest common divisor](https://en.wikipedia.org/wiki/Great...
{"inputs": ["3 9", "5 8", "2 12", "1 8", "1 9", "1000000000 1000000000", "1000000000 1", "1 1000000000", "1 223092870", "1 1", "1 994593600", "1 425613469", "495219 444706662", "9357 18255507", "741547455 471761895", "225 315096300", "183612440 509579899", "231096994 462193988", "34601 35742833", "417485019 230941257",...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
11
codeforces
9cb90a82bd95197253a14ed7ad33b899
Ants in Leaves
Tree is a connected graph without cycles. A leaf of a tree is any vertex connected with exactly one other vertex. You are given a tree with *n* vertices and a root in the vertex 1. There is an ant in each leaf of the tree. In one second some ants can simultaneously go to the parent vertex from the vertex they were in....
{"inputs": ["12\n1 2\n1 3\n1 4\n2 5\n2 6\n3 7\n3 8\n3 9\n8 10\n8 11\n8 12", "2\n2 1", "2\n2 1", "10\n4 10\n6 10\n10 5\n10 7\n8 10\n4 2\n9 10\n4 1\n3 10", "10\n2 8\n10 8\n8 3\n4 3\n6 3\n6 1\n10 7\n9 1\n5 10", "10\n1 3\n4 3\n10 4\n10 6\n6 2\n5 2\n7 5\n7 8\n7 9"], "outputs": ["6", "1", "1", "8", "6", "9"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
5
codeforces
9cc28ba52aba545c3780e3a9c0f832da
Cottage Village
A new cottage village called «Flatville» is being built in Flatland. By now they have already built in «Flatville» *n* square houses with the centres on the *Оx*-axis. The houses' sides are parallel to the coordinate axes. It's known that no two houses overlap, but they can touch each other. The architect bureau, wher...
{"inputs": ["2 2\n0 4\n6 2", "2 2\n0 4\n5 2", "2 3\n0 4\n5 2", "1 1\n1 1", "1 2\n2 1", "2 1\n2 1\n1 1", "2 2\n0 4\n7 4", "4 1\n-12 1\n-14 1\n4 1\n-11 1", "6 15\n19 1\n2 3\n6 2\n-21 2\n-15 2\n23 1", "10 21\n-61 6\n55 2\n-97 1\n37 1\n-39 1\n26 2\n21 1\n64 3\n-68 1\n-28 6", "26 51\n783 54\n-850 6\n-997 59\n573 31\n-125 20...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
90
codeforces
9d391bfa29ae37e96e074688a9fb0afb
Script Generation
The Smart Beaver from ABBYY was offered a job of a screenwriter for the ongoing TV series. In particular, he needs to automate the hard decision: which main characters will get married by the end of the series. There are *n* single men and *n* single women among the main characters. An opinion poll showed that viewers...
{"inputs": ["2 4 3\n1 1 1\n1 2 2\n2 1 3\n2 2 7", "2 4 7\n1 1 1\n1 2 2\n2 1 3\n2 2 7", "2 2 1\n1 2 8\n2 2 1", "5 25 140\n3 5 40\n3 3 42\n4 5 62\n2 4 7\n4 2 57\n1 5 69\n3 2 37\n2 5 43\n2 3 14\n1 3 67\n5 2 62\n3 1 13\n5 5 55\n1 2 71\n4 1 69\n1 4 32\n4 4 58\n5 3 2\n2 2 31\n5 1 20\n2 1 38\n1 1 69\n5 4 66\n3 4 27\n4 3 90", "...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
5
codeforces
9d414439febda8a343619ca2a9563631
none
Barney lives in NYC. NYC has infinite number of intersections numbered with positive integers starting from 1. There exists a bidirectional road between intersections *i* and 2*i* and another road between *i* and 2*i*<=+<=1 for every positive integer *i*. You can clearly see that there exists a unique shortest path bet...
{"inputs": ["7\n1 3 4 30\n1 4 1 2\n1 3 6 8\n2 4 3\n1 6 1 40\n2 3 7\n2 2 4", "1\n2 666077344481199252 881371880336470888", "10\n1 1 63669439577744021 396980128\n1 2582240553355225 63669439577744021 997926286\n1 2582240553355225 1 619026011\n1 1 4 231881718\n2 63669439577744021 3886074192977\n2 4 63669439577744021\n2 124...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
30
codeforces
9da4d4dfbe964aedc131144ac538ce92
Spider Man
Peter Parker wants to play a game with Dr. Octopus. The game is about cycles. Cycle is a sequence of vertices, such that first one is connected with the second, second is connected with third and so on, while the last one is connected with the first one again. Cycle may consist of a single isolated vertex. Initially t...
{"inputs": ["3\n1 2 3", "5\n1 1 5 1 1", "1\n167959139", "10\n802030518 598196518 640274071 983359971 71550121 96204862 799843967 446173607 796619138 402690754", "1\n1", "1\n1000000000", "2\n2 4", "2\n1 1", "2\n1 2", "2\n2 1", "3\n1 3 1", "3\n1 2 1", "3\n2 1 1", "3\n1 1 2", "10\n9 8 5 4 1 1 2 1 1 1", "1\n2", "2\n3 3", "...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
10
codeforces
9dc1d6525ae85b737334964d276c540c
The New Year: Meeting Friends
There are three friend living on the straight line *Ox* in Lineland. The first friend lives at the point *x*1, the second friend lives at the point *x*2, and the third friend lives at the point *x*3. They plan to celebrate the New Year together, so they need to meet at one point. What is the minimum total distance they...
{"inputs": ["7 1 4", "30 20 10", "1 4 100", "100 1 91", "1 45 100", "1 2 3", "71 85 88", "30 38 99", "23 82 95", "22 41 47", "9 94 77", "1 53 51", "25 97 93", "42 53 51", "81 96 94", "21 5 93", "50 13 75", "41 28 98", "69 46 82", "87 28 89", "44 45 40", "86 97 68", "43 92 30", "16 70 1", "40 46 19", "71 38 56", "82 21 ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
910
codeforces
9e0515a4068120048830565280e77d56
Platforms
In one one-dimensional world there are *n* platforms. Platform with index *k* (platforms are numbered from 1) is a segment with coordinates [(*k*<=-<=1)*m*,<=(*k*<=-<=1)*m*<=+<=*l*], and *l*<=&lt;<=*m*. Grasshopper Bob starts to jump along the platforms from point 0, with each jump he moves exactly *d* units right. Fin...
{"inputs": ["2 2 5 3", "5 4 11 8", "228385 744978 699604 157872", "773663 427904 329049 243542", "835293 627183 442142 361649", "896922 310109 71587 16487", "958552 993036 701031 109903", "20182 192314 814124 268107", "81812 875240 443569 287155", "3 6 6 3", "3 16 6 3", "3 4 6 3", "680892 333996 619800 374820", "658990...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
24
codeforces
9e093a55326a192a38e930a03fc3663c
Xor-tree
Iahub is very proud of his recent discovery, propagating trees. Right now, he invented a new tree, called xor-tree. After this new revolutionary discovery, he invented a game for kids which uses xor-trees. The game is played on a tree having *n* nodes, numbered from 1 to *n*. Each node *i* has an initial value *init**...
{"inputs": ["10\n2 1\n3 1\n4 2\n5 1\n6 2\n7 5\n8 6\n9 8\n10 5\n1 0 1 1 0 1 0 1 0 1\n1 0 1 0 0 1 1 1 0 1", "15\n2 1\n3 2\n4 3\n5 4\n6 5\n7 6\n8 7\n9 8\n10 9\n11 10\n12 11\n13 12\n14 13\n15 14\n0 1 0 0 1 1 1 1 1 1 0 0 0 1 1\n1 1 1 1 0 0 1 1 0 1 0 0 1 1 0", "20\n2 1\n3 2\n4 3\n5 4\n6 4\n7 1\n8 2\n9 4\n10 2\n11 6\n12 9\n13...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
33
codeforces
9e189aa263447d6e19b170980fdd35e7
Dima and Continuous Line
Dima and Seryozha live in an ordinary dormitory room for two. One day Dima had a date with his girl and he asked Seryozha to leave the room. As a compensation, Seryozha made Dima do his homework. The teacher gave Seryozha the coordinates of *n* distinct points on the abscissa axis and asked to consecutively connect th...
{"inputs": ["4\n0 10 5 15", "4\n0 15 5 10", "5\n0 1000 2000 3000 1500", "5\n-724093 710736 -383722 -359011 439613", "50\n384672 661179 -775591 -989608 611120 442691 601796 502406 384323 -315945 -934146 873993 -156910 -94123 -930137 208544 816236 466922 473696 463604 794454 -872433 -149791 -858684 -467655 -555239 623978...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
81
codeforces
9e460867392575dbf57fd072b5ef2aeb
Young Photographer
Among other things, Bob is keen on photography. Especially he likes to take pictures of sportsmen. That was the reason why he placed himself in position *x*0 of a long straight racetrack and got ready to take pictures. But the problem was that not all the runners passed him. The total amount of sportsmen, training at t...
{"inputs": ["3 3\n0 7\n14 2\n4 6", "1 1\n0 10", "2 2\n1 2\n3 2", "3 2\n1 2\n2 3\n3 4", "2 4\n10 4\n1 5", "1 10\n1 9", "1 10\n123 12", "1 17\n10 17", "1 22\n22 33", "1 3\n1 2", "2 5\n0 3\n2 1", "3 3\n7 3\n6 4\n3 7", "4 9\n8 6\n11 5\n5 11\n8 3", "2 4\n1 4\n4 0", "3 7\n5 8\n7 5\n4 7", "4 7\n8 2\n5 7\n8 2\n5 8", "2 3\n4 1\...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
78
codeforces
9e56f05801d7e9e4ec419f918a1d927d
PolandBall and Polygon
PolandBall has such a convex polygon with *n* veritces that no three of its diagonals intersect at the same point. PolandBall decided to improve it and draw some red segments. He chose a number *k* such that *gcd*(*n*,<=*k*)<==<=1. Vertices of the polygon are numbered from 1 to *n* in a clockwise way. PolandBall repe...
{"inputs": ["5 2", "10 3", "17 5", "1337 550", "1000000 7", "1000000 500001", "5 3", "7 5", "7 4", "7 3", "7 2", "618440 133219", "266629 262028", "420886 45693", "535643 450037", "972950 214491", "843926 7389", "844773 28178", "199183 149366", "506387 238193", "158845 28784", "874231 6382", "473808 229477", "217694 14...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
3
codeforces
9e8832e0902da7ae0ddaace7b52d5623
Ohana Cleans Up
Ohana Matsumae is trying to clean a room, which is divided up into an *n* by *n* grid of squares. Each square is initially either clean or dirty. Ohana can sweep her broom over columns of the grid. Her broom is very strange: if she sweeps over a clean square, it will become dirty, and if she sweeps over a dirty square,...
{"inputs": ["4\n0101\n1000\n1111\n0101", "3\n111\n111\n111", "10\n0100000000\n0000000000\n0000000000\n0000000000\n0000000000\n0000000000\n0000000000\n0000000000\n0000000000\n0000000000", "1\n1", "10\n0111010011\n0111010011\n1010010001\n0111010011\n0000110000\n0111010011\n0111010011\n0000110000\n1010010001\n0111010011",...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
207
codeforces
9e8f4a947ab75ccf3ad52081178c90b5
Power Tower
Priests of the Quetzalcoatl cult want to build a tower to represent a power of their god. Tower is usually made of power-charged rocks. It is built with the help of rare magic by levitating the current top of tower and adding rocks at its bottom. If top, which is built from *k*<=-<=1 rocks, possesses power *p* and we w...
{"inputs": ["6 1000000000\n1 2 2 3 3 3\n8\n1 1\n1 6\n2 2\n2 3\n2 4\n4 4\n4 5\n4 6", "10 20\n792708224 4633945 600798790 384332600 283309209 762285205 750900274 160512987 390669628 205259431\n10\n5 9\n10 10\n8 10\n7 10\n7 10\n10 10\n4 4\n10 10\n7 7\n4 8", "10 18634\n157997476 953632869 382859292 108314887 739258690 1109...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1
codeforces
9e99af0e09bb8926962d66a3c7d018d6
Tree Destruction
You are given an unweighted tree with *n* vertices. Then *n*<=-<=1 following operations are applied to the tree. A single operation consists of the following steps: 1. choose two leaves; 1. add the length of the simple path between them to the answer; 1. remove one of the chosen leaves from the tree. Initial answ...
{"inputs": ["3\n1 2\n1 3", "5\n1 2\n1 3\n2 4\n2 5", "2\n1 2", "4\n1 3\n1 4\n1 2", "4\n2 1\n1 3\n3 4", "4\n4 3\n3 2\n2 1", "5\n2 1\n2 3\n2 4\n2 5", "5\n4 5\n4 1\n1 2\n2 3", "5\n1 4\n4 3\n3 2\n2 5", "6\n4 5\n4 1\n4 6\n4 2\n4 3", "6\n6 5\n6 2\n2 3\n5 4\n4 1", "6\n1 5\n5 4\n4 2\n2 6\n6 3", "7\n7 5\n7 3\n7 6\n7 4\n7 1\n7 2"...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
5
codeforces
9eb52fbc8417291b3e440dec6bcd1e39
Petr and a calendar
Petr wants to make a calendar for current month. For this purpose he draws a table in which columns correspond to weeks (a week is seven consequent days from Monday to Sunday), rows correspond to weekdays, and cells contain dates. For example, a calendar for January 2017 should look like on the picture: Petr wants to ...
{"inputs": ["1 7", "1 1", "11 6", "2 7", "2 1", "8 6", "1 1", "1 2", "1 3", "1 4", "1 5", "1 6", "1 7", "2 1", "2 2", "2 3", "2 4", "2 5", "2 6", "2 7", "3 1", "3 2", "3 3", "3 4", "3 5", "3 6", "3 7", "4 1", "4 2", "4 3", "4 4", "4 5", "4 6", "4 7", "5 1", "5 2", "5 3", "5 4", "5 5", "5 6", "5 7", "6 1", "6 2", "6 3",...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
287
codeforces
9ec778249556b0c2c683fb80bec98610
One-dimensional Japanese Crossword
Recently Adaltik discovered japanese crosswords. Japanese crossword is a picture, represented as a table sized *a*<=×<=*b* squares, and each square is colored white or black. There are integers to the left of the rows and to the top of the columns, encrypting the corresponding row or column. The number of integers repr...
{"inputs": ["3\nBBW", "5\nBWBWB", "4\nWWWW", "4\nBBBB", "13\nWBBBBWWBWBBBW", "1\nB", "2\nBB", "100\nWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWB", "1\nW", "2\nWW", "2\nWB", "2\nBW", "3\nBBB", "3\nBWB", "3\nWBB", "3\nWWB", "3\nWBW", "3\nBWW", "3\nWWW", "100\nBBBWWW...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
437
codeforces
9efd5c1d8a760f68e844a063591a0956
Escape
The princess is going to escape the dragon's cave, and she needs to plan it carefully. The princess runs at *v**p* miles per hour, and the dragon flies at *v**d* miles per hour. The dragon will discover the escape after *t* hours and will chase the princess immediately. Looks like there's no chance to success, but the...
{"inputs": ["1\n2\n1\n1\n10", "1\n2\n1\n1\n8", "5\n8\n1\n2\n100", "2\n100\n10\n10\n739", "17\n99\n2\n3\n293", "5\n5\n1\n1\n1000", "100\n99\n1\n1\n1000", "1\n100\n1\n1\n1", "1\n100\n1\n1\n1000", "10\n1\n10\n1\n11", "98\n94\n4\n3\n437", "58\n4\n1\n10\n392", "74\n11\n8\n7\n835", "86\n21\n7\n2\n982", "2\n27\n4\n9\n937", "6...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
11
codeforces
9f25abcea6070b5ef9b0617d81e00481
Lecture Sleep
Your friend Mishka and you attend a calculus lecture. Lecture lasts *n* minutes. Lecturer tells *a**i* theorems during the *i*-th minute. Mishka is really interested in calculus, though it is so hard to stay awake for all the time of lecture. You are given an array *t* of Mishka's behavior. If Mishka is asleep during ...
{"inputs": ["6 3\n1 3 5 2 5 4\n1 1 0 1 0 0", "5 3\n1 9999 10000 10000 10000\n0 0 0 0 0", "3 3\n10 10 10\n1 1 0", "1 1\n423\n0", "6 6\n1 3 5 2 5 4\n1 1 0 1 0 0", "5 2\n1 2 3 4 20\n0 0 0 1 0", "3 1\n1 2 3\n0 0 1", "4 2\n4 5 6 8\n1 0 1 0", "6 3\n1 3 5 2 1 15\n1 1 0 1 0 0", "5 5\n1 2 3 4 5\n1 1 1 0 1", "3 3\n3 3 3\n1 0 1",...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
236
codeforces
9f34e733a30cd820bf6cbd1d33cf1718
The Wall (medium)
Heidi the Cow is aghast: cracks in the northern Wall? Zombies gathering outside, forming groups, preparing their assault? This must not happen! Quickly, she fetches her HC2 (Handbook of Crazy Constructions) and looks for the right chapter: How to build a wall: 1. Take a set of bricks. 1. Select one of the possible ...
{"inputs": ["5 1", "2 2", "3 2", "11 5", "37 63", "1 1", "350000 140000", "350000 160000", "350000 180000", "350000 200000", "400000 140000", "400000 160000", "400000 180000", "400000 200000", "450000 140000", "450000 160000", "450000 180000", "450000 200000", "500000 140000", "500000 160000", "500000 180000", "500000 ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
11
codeforces
9f7943f6737302222342f001b3b1a0f8
Sequence of points
You are given the following points with integer coordinates on the plane: *M*0,<=*A*0,<=*A*1,<=...,<=*A**n*<=-<=1, where *n* is odd number. Now we define the following infinite sequence of points *M**i*: *M**i* is symmetric to *M**i*<=-<=1 according (for every natural number *i*). Here point *B* is symmetric to *A* ac...
{"inputs": ["3 4\n0 0\n1 1\n2 3\n-5 3", "3 1\n5 5\n1000 1000\n-1000 1000\n3 100", "1 1\n-1000 -1000\n1000 1000", "1 1000000000000000000\n-1000 1000\n1000 -1000", "1 900000000000000001\n-1000 -1000\n-1000 -1000"], "outputs": ["14 0", "1995 1995", "3000 3000", "-1000 1000", "-1000 -1000"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
16
codeforces
9f7d6c7725c1eb0f004d79047462bd51
Good Substrings
Smart Beaver recently got interested in a new word game. The point is as follows: count the number of distinct good substrings of some string *s*. To determine if a string is good or not the game uses rules. Overall there are *n* rules. Each rule is described by a group of three (*p*,<=*l*,<=*r*), where *p* is a string...
{"inputs": ["aaab\n2\naa 0 0\naab 1 1", "ltntlnen\n3\nn 0 0\nttlneenl 1 4\nlelllt 1 1", "a\n0", "nysnvneyavzcebsbsvrsbcvzsrcr\n5\nycaa 1 3\nzsayyyvseccsbcbvzrr 5 16\nznz 1 3\nbvnzrccvcb 4 7\nseznebzeevvrncccaabsbny 17 21", "oaoaa\n1\noaooaoooooaaaaaaaoooaao 2 18", "aaajiajqjvehgzqjssaebbqzhggehreiihhrjeehzeaeiiigavjsqb...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1
codeforces
9f80d9cecb41a12ee7ea87030333e61e
Inversions After Shuffle
You are given a permutation of integers from 1 to *n*. Exactly once you apply the following operation to this permutation: pick a random segment and shuffle its elements. Formally: 1. Pick a random segment (continuous subsequence) from *l* to *r*. All segments are equiprobable. 1. Let *k*<==<=*r*<=-<=*l*<=+<=1, i.e...
{"inputs": ["3\n2 3 1", "1\n1", "2\n1 2", "2\n2 1", "3\n1 2 3", "3\n2 1 3", "3\n3 1 2", "3\n1 3 2", "3\n3 2 1", "4\n1 4 2 3", "4\n4 2 3 1", "10\n1 2 3 4 5 6 7 8 9 10", "10\n10 1 9 2 8 3 7 4 6 5", "10\n1 6 2 7 3 8 4 9 5 10", "12\n2 12 9 3 6 11 8 1 4 10 7 5", "33\n16 17 8 15 3 29 1 18 21 14 4 31 30 20 13 7 19 22 23 25 5 ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
2
codeforces
9f83cfcc77683f219e759a7a27ce5653
Geometric Progression
Polycarp loves geometric progressions very much. Since he was only three years old, he loves only the progressions of length three. He also has a favorite integer *k* and a sequence *a*, consisting of *n* integers. He wants to know how many subsequences of length three can be selected from *a*, so that they form a geo...
{"inputs": ["5 2\n1 1 2 2 4", "3 1\n1 1 1", "10 3\n1 2 6 2 3 6 9 18 3 9", "20 2\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20", "5 3\n5 15 15 15 45", "7 1\n1 2 1 2 1 2 1", "10 10\n1 10 100 1000 10000 100000 1000000 10000000 100000000 1000000000", "30 4096\n1 2 4 8 16 32 64 128 256 512 1024 2048 4096 8192 16384 32...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
50
codeforces
9f9161d773c0ece159dec48afcbd2162
Flea
It is known that fleas in Berland can jump only vertically and horizontally, and the length of the jump is always equal to *s* centimeters. A flea has found herself at the center of some cell of the checked board of the size *n*<=×<=*m* centimeters (each cell is 1<=×<=1 centimeters). She can jump as she wishes for an a...
{"inputs": ["2 3 1000000", "3 3 2", "1 2 3", "4 5 6", "9 8 7", "1000 1000 1000", "1 1 1", "1 1 2", "1 1 1000000", "1000000 1000000 1", "1000000 1000000 2", "1000000 1000000 999999", "1000000 1000000 12345", "1000000 1000000 123456", "43496 179847 327622", "105126 379125 460772", "999463 261665 981183", "836832 336228 5...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
21
codeforces
9f959cc5d146ca6fee98e80d3195ef19
Digital Counter
Malek lives in an apartment block with 100 floors numbered from 0 to 99. The apartment has an elevator with a digital counter showing the floor that the elevator is currently on. The elevator shows each digit of a number with 7 light sticks by turning them on or off. The picture below shows how the elevator shows each ...
{"inputs": ["89", "00", "73", "08", "26", "49", "88", "04", "60", "11", "22", "33", "44", "55", "66", "77", "88", "99", "80", "78", "67", "89", "46", "90", "92", "35", "05", "57", "20"], "outputs": ["2", "4", "15", "2", "4", "6", "1", "6", "4", "49", "4", "9", "9", "16", "4", "25", "1", "4", "2", "5", "10", "2", "6", "...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
135
codeforces
9f9e2591905f746f25618370c11f164b
Set of Strings
You are given a string *q*. A sequence of *k* strings *s*1,<=*s*2,<=...,<=*s**k* is called beautiful, if the concatenation of these strings is string *q* (formally, *s*1<=+<=*s*2<=+<=...<=+<=*s**k*<==<=*q*) and the first characters of these strings are distinct. Find any beautiful sequence of strings or determine that...
{"inputs": ["1\nabca", "2\naaacas", "4\nabc", "3\nnddkhkhkdndknndkhrnhddkrdhrnrrnkkdnnndndrdhnknknhnrnnkrrdhrkhkrkhnkhkhhrhdnrndnknrrhdrdrkhdrkkhkrnkk", "26\nbiibfmmfifmffbmmfmbmbmiimbmiffmffibibfbiffibibiiimbffbbfbifmiibffbmbbbfmfibmibfffibfbffmfmimbmmmfmfm", "3\nkydoybxlfeugtrbvqnrjtzshorrsrwsxkvlwyolbaadtzpmyyfllxuc...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
123
codeforces
9fa187d8d77720cd2aa86a448d5bcfeb
none
Arkady needs your help again! This time he decided to build his own high-speed Internet exchange point. It should consist of *n* nodes connected with minimum possible number of wires into one network (a wire directly connects two nodes). Exactly *k* of the nodes should be exit-nodes, that means that each of them should...
{"inputs": ["3 2", "5 3", "4 2", "4 3", "5 2", "5 4", "6 2", "6 3", "6 4", "6 5", "1000 245", "1000 999", "1024 23", "200000 1014", "100003 16", "7 2", "7 3", "7 4", "7 5", "7 6", "100 2", "100 5", "100 59", "100 98", "100 99", "1000 2", "1000 5", "1000 670", "1000 998", "100000 2", "100000 4", "100000 101", "100000 30...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
22
codeforces
9fada31fd7a37734fcc595bd6276b94d
Andryusha and Socks
Andryusha is an orderly boy and likes to keep things in their place. Today he faced a problem to put his socks in the wardrobe. He has *n* distinct pairs of socks which are initially in a bag. The pairs are numbered from 1 to *n*. Andryusha wants to put paired socks together and put them in the wardrobe. He takes the ...
{"inputs": ["1\n1 1", "3\n2 1 1 3 2 3", "5\n5 1 3 2 4 3 1 2 4 5", "10\n4 2 6 3 4 8 7 1 1 5 2 10 6 8 3 5 10 9 9 7", "50\n30 47 31 38 37 50 36 43 9 23 2 2 15 31 14 49 9 16 6 44 27 14 5 6 3 47 25 26 1 35 3 15 24 19 8 46 49 41 4 26 40 28 42 11 34 35 46 18 7 28 18 40 19 42 4 41 38 48 50 12 29 39 33 17 25 22 22 21 36 45 27 3...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
304
codeforces
9fc36afd3f0764dc0e13c308b99a8db0
K-Dominant Character
You are given a string *s* consisting of lowercase Latin letters. Character *c* is called *k*-dominant iff each substring of *s* with length at least *k* contains this character *c*. You have to find minimum *k* such that there exists at least one *k*-dominant character. The first line contains string *s* consisting o...
{"inputs": ["abacaba", "zzzzz", "abcde", "bcaccacaaabaacaabaaabcbbcbcaacacbcbaaaacccacbbcbaabcbacaacbabacacacaccbbccbcbacbbbbccccabcabaaab", "daabcdabbabbacacbaacabacbcaabaacac", "abghim", "gfliflgfhhdkceacdljgkegmdlhcgkcmlelmbbbmdddgdeeljjhgbbffmemmmkhebgkhadkdajabcjkcgbkgbaeacdedlkklfech", "a", "aaabbb", "ab", "abbb"...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
78
codeforces
9fcfc46ec0659d2aff21b232f7a0c3a5
none
Vasya is sitting on an extremely boring math class. To have fun, he took a piece of paper and wrote out *n* numbers on a single line. After that, Vasya began to write out different ways to put pluses ("+") in the line between certain digits in the line so that the result was a correct arithmetic expression; formally, n...
{"inputs": ["3 1\n108", "3 2\n108", "1 0\n5", "5 2\n39923", "6 3\n967181", "7 1\n2178766", "10 0\n3448688665", "14 6\n00000000000001", "16 15\n8086179429588546", "18 15\n703140050361297985", "20 9\n34540451546587567970", "20 8\n99999999999999999999", "20 19\n33137197659033083606", "57 13\n177946005798852216692528643323...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1
codeforces
9fdff882c3896340c273423c008cbc04
Wet Shark and Blocks
There are *b* blocks of digits. Each one consisting of the same *n* digits, which are given to you in the input. Wet Shark must choose exactly one digit from each block and concatenate all of those digits together to form one large integer. For example, if he chooses digit 1 from the first block and digit 2 from the se...
{"inputs": ["12 1 5 10\n3 5 6 7 8 9 5 1 1 1 1 5", "3 2 1 2\n6 2 2", "3 2 1 2\n3 1 2", "3 2 1 2\n6 3 2", "3 2 1 2\n3 6 3", "3 2 0 2\n3 3 9", "3 2 0 2\n4 5 1", "3 2 0 2\n1 3 2", "3 2 1 2\n5 9 3", "3 2 1 2\n7 2 4", "6 5 2 12\n2 8 9 6 6 1", "6 5 9 11\n8 1 2 1 8 2", "6 5 7 10\n9 6 9 8 8 8", "6 5 12 23\n5 8 2 6 5 5", "6 5 6 ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
3
codeforces
a0032e48830b2c7f6c1b6af40e791f87
Donkey and Stars
In the evenings Donkey would join Shrek to look at the stars. They would sit on a log, sipping tea and they would watch the starry sky. The sky hung above the roof, right behind the chimney. Shrek's stars were to the right of the chimney and the Donkey's stars were to the left. Most days the Donkey would just count the...
{"inputs": ["15\n1/3 2/1\n3 1\n6 2\n4 2\n2 5\n4 5\n6 6\n3 4\n1 6\n2 1\n7 4\n9 3\n5 3\n1 3\n15 5\n12 4", "15\n2/1 2/0\n3 1\n6 2\n9 3\n12 4\n15 5\n2 1\n4 2\n5 3\n7 4\n1 3\n3 4\n2 5\n4 5\n1 6\n6 6", "15\n2/1 2/0\n3 1\n6 2\n9 3\n12 4\n15 5\n2 1\n4 2\n5 3\n7 4\n1 3\n3 4\n2 6\n4 5\n1 6\n6 6", "15\n1/4 2/1\n3 1\n6 2\n9 3\n12 ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
2
codeforces
a008bdd5686b8fc5b8c6cfae3cabd328
none
There are *n* workers in a company, each of them has a unique id from 1 to *n*. Exaclty one of them is a chief, his id is *s*. Each worker except the chief has exactly one immediate superior. There was a request to each of the workers to tell how how many superiors (not only immediate). Worker's superiors are his imme...
{"inputs": ["3 2\n2 0 2", "5 3\n1 0 0 4 1", "1 1\n0", "2 1\n0 0", "2 1\n0 1", "2 1\n1 0", "2 1\n1 1", "2 2\n0 0", "2 2\n0 1", "9 1\n0 1 1 1 1 1 6 7 8", "9 1\n0 1 1 1 1 5 6 7 8", "6 1\n0 1 2 2 0 0", "2 2\n1 1", "2 2\n1 0", "3 1\n0 1 2", "3 1\n2 1 1", "3 1\n0 0 2", "3 2\n2 0 1", "3 2\n2 2 1", "3 2\n2 1 1", "3 3\n1 1 0", ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
6
codeforces
a008cf6fdf1b6bd445525007b1378423
Tanks
Petya sometimes has to water his field. To water the field, Petya needs a tank with exactly *V* ml of water. Petya has got *N* tanks, *i*-th of them initially containing *a**i* ml of water. The tanks are really large, any of them can contain any amount of water (no matter how large this amount is). Also Petya has got...
{"inputs": ["2 3 5\n2 3", "2 3 4\n2 3", "5 2 0\n1 3 5 7 9", "5 10 3\n3 4 5 6 7", "6 4 8\n5 5 5 5 5 5", "5 4 24\n5 5 5 5 5", "5 4 28\n5 5 5 5 5", "8 4 20\n3 3 3 3 3 3 3 3", "2 6 1\n100 200", "10 2 49\n3 5 7 9 11 3 5 7 9 11", "10 10 99\n10 10 10 10 10 10 10 10 10 10", "8 6 32\n3 6 4 4 4 4 4 4", "6 11 3\n6 6 6 6 6 6", "3 ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1
codeforces
a032c4a8b32b448ebc4ce4002bf0e4c8
Tesla
Allen dreams of one day owning a enormous fleet of electric cars, the car of the future! He knows that this will give him a big status boost. As Allen is planning out all of the different types of cars he will own and how he will arrange them, he realizes that he has a problem. Allen's future parking lot can be repre...
{"inputs": ["4 5\n1 2 0 4\n1 2 0 4\n5 0 0 3\n0 5 0 3", "1 2\n1\n2\n1\n2", "1 2\n1\n1\n2\n2", "2 2\n1 0\n0 2\n0 1\n0 2", "7 14\n2 11 1 14 9 8 5\n12 6 7 1 10 2 3\n14 13 9 8 5 4 11\n13 6 4 3 12 7 10", "10 20\n18 7 3 16 5 8 19 2 20 12\n15 16 7 11 14 3 12 4 8 10\n19 18 20 1 17 9 5 2 6 13\n11 15 13 17 6 9 14 1 10 4", "2 1\n0...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
4
codeforces
a036df390b5b447b6a25c0f5c963b490
Alternative Thinking
Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length *n*. Each character of Kevin's string represents Kevin's score on one of the *n* questions of the olympiad—'1' for a correctly identified cow and '0' otherwise. However, all is...
{"inputs": ["8\n10000011", "2\n01", "5\n10101", "75\n010101010101010101010101010101010101010101010101010101010101010101010101010", "11\n00000000000", "56\n10101011010101010101010101010101010101011010101010101010", "50\n01011010110101010101010101010101010101010101010100", "7\n0110100", "8\n11011111", "6\n000000", "5\n01...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
95
codeforces
a03f5ee5d473aff0cb3f1cda8eeaf40d
Battleship
Arkady is playing Battleship. The rules of this game aren't really important. There is a field of $n \times n$ cells. There should be exactly one $k$-decker on the field, i. e. a ship that is $k$ cells long oriented either horizontally or vertically. However, Arkady doesn't know where it is located. For each cell Arka...
{"inputs": ["4 3\n#..#\n#.#.\n....\n.###", "10 4\n#....##...\n.#...#....\n..#..#..#.\n...#.#....\n.#..##.#..\n.....#...#\n...#.##...\n.#...#.#..\n.....#..#.\n...#.#...#", "19 6\n##..............###\n#......#####.....##\n.....#########.....\n....###########....\n...#############...\n..###############..\n.###############...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
50
codeforces
a04b6aeaf59b1ddeae4d733245b7a6b2
Makes And The Product
After returning from the army Makes received a gift — an array *a* consisting of *n* positive integer numbers. He hadn't been solving problems for a long time, so he became interested to answer a particular question: how many triples of indices (*i*,<= *j*,<= *k*) (*i*<=&lt;<=*j*<=&lt;<=*k*), such that *a**i*·*a**j*·*a...
{"inputs": ["4\n1 1 1 1", "5\n1 3 2 3 4", "6\n1 3 3 1 3 2", "3\n1000000000 1000000000 1000000000", "4\n1 1 2 2", "3\n1 3 1", "11\n1 2 2 2 2 2 2 2 2 2 2", "5\n1 2 2 2 2", "6\n1 2 2 3 3 4", "8\n1 1 2 2 2 3 3 3", "6\n1 2 2 2 2 3", "3\n1 2 2", "6\n1 2 2 2 3 3", "6\n1 2 2 2 2 2", "4\n1 2 2 2", "5\n1 2 3 2 3", "6\n2 2 3 3 3 ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
96
codeforces
a04f6389f6f82fd17ccc154a7b9067b2
Multicolored Cars
Alice and Bob got very bored during a long car trip so they decided to play a game. From the window they can see cars of different colors running past them. Cars are going one after another. The game rules are like this. Firstly Alice chooses some color *A*, then Bob chooses some color *B* (*A*<=≠<=*B*). After each ca...
{"inputs": ["4 1\n2 1 4 2", "5 2\n2 2 4 5 3", "3 10\n1 2 3", "1 1\n2", "1 2\n2", "10 6\n8 5 1 6 6 5 10 6 9 8", "7 2\n1 2 2 1 1 1 1", "8 2\n1 1 3 2 3 2 3 2", "10 9\n6 4 7 1 8 9 5 9 4 5", "6 1\n2 3 3 1 1 2", "4 1\n2 1 1 2", "5 1\n3 2 1 2 1", "5 3\n1 2 3 2 3", "1 1000000\n1", "6 3\n1 2 3 2 3 2", "3 2\n1 2 3", "6 2\n5 3 2 ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
15
codeforces
a081ed56bfa2a4a5d961d35106353398
Dreamoon and Strings
Dreamoon has a string *s* and a pattern string *p*. He first removes exactly *x* characters from *s* obtaining string *s*' as a result. Then he calculates that is defined as the maximal number of non-overlapping substrings equal to *p* that can be found in *s*'. He wants to make this number as big as possible. More f...
{"inputs": ["aaaaa\naa", "axbaxxb\nab", "aabb\nab", "aaaaaaaaaaaaaaa\na", "aaaaaaaaaaa\nb", "ababababababababa\naba", "axxbaxxbaxxb\nab", "axaxxbaxabxbaxxbxb\nab", "ababcc\nabc", "a\na", "a\nb", "a\naa", "a\nab", "a\nbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1
codeforces
a08ef6bbf2852d03fa0d272506b80b9d
Bachgold Problem
Bachgold problem is very easy to formulate. Given a positive integer *n* represent it as a sum of maximum possible number of prime numbers. One can prove that such representation exists for any integer greater than 1. Recall that integer *k* is called prime if it is greater than 1 and has exactly two positive integer ...
{"inputs": ["5", "6", "2", "3", "99999", "100000", "7", "4", "8", "9", "99995", "99996", "10", "11", "99997", "99998", "12", "13", "99993", "99994", "14", "15", "53", "57", "61", "774", "202", "530", "7166", "9294", "2422", "15326", "11454", "14878", "90672", "99544", "90472", "23", "93", "19", "11110"], "outputs": ["2...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
655
codeforces
a0b24240d253c4e6833ed30a4c86bb2d
none
Bearland has *n* cities, numbered 1 through *n*. Cities are connected via bidirectional roads. Each road connects two distinct cities. No two roads connect the same pair of cities. Bear Limak was once in a city *a* and he wanted to go to a city *b*. There was no direct connection so he decided to take a long walk, vis...
{"inputs": ["7 11\n2 4 7 3", "1000 999\n10 20 30 40", "4 4\n1 2 3 4", "5 6\n5 2 4 1", "57 88\n54 30 5 43", "700 699\n687 69 529 616", "1000 1001\n217 636 713 516", "4 5\n1 3 4 2", "4 6\n1 3 2 4", "5 4\n2 3 5 4", "5 5\n1 4 2 5", "5 7\n4 3 2 1", "5 8\n2 3 5 1", "6 5\n3 2 5 4", "6 6\n1 3 4 5", "6 7\n3 1 2 4", "6 10\n5 3 4...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
16
codeforces
a0e51419a417d080cc1ede27bf06586b
George and Interesting Graph
George loves graphs. Most of all, he loves interesting graphs. We will assume that a directed graph is interesting, if it meets the following criteria: - The graph doesn't contain any multiple arcs; - There is vertex *v* (we'll call her the center), such that for any vertex of graph *u*, the graph contains arcs (*u...
{"inputs": ["3 7\n1 1\n2 2\n3 1\n1 3\n3 2\n2 3\n3 3", "3 6\n1 1\n2 2\n3 1\n3 2\n2 3\n3 3", "3 1\n2 2", "5 25\n4 2\n1 4\n5 2\n2 2\n3 1\n4 5\n2 1\n2 5\n2 4\n1 2\n4 1\n4 4\n1 1\n1 5\n4 3\n5 1\n3 3\n1 3\n5 5\n2 3\n5 3\n3 5\n3 2\n5 4\n3 4", "2 4\n2 1\n1 2\n2 2\n1 1", "3 9\n2 2\n2 1\n3 2\n1 3\n3 1\n1 2\n3 3\n1 1\n2 3", "6 22...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1
codeforces
a0e804218f0f0c290f8fe2252951c16c
Tritonic Iridescence
Overlooking the captivating blend of myriads of vernal hues, Arkady the painter lays out a long, long canvas. Arkady has a sufficiently large amount of paint of three colours: cyan, magenta, and yellow. On the one-dimensional canvas split into *n* consecutive segments, each segment needs to be painted in one of the co...
{"inputs": ["5\nCY??Y", "5\nC?C?Y", "5\n?CYC?", "5\nC??MM", "3\nMMY", "15\n??YYYYYY??YYYY?", "100\nYCY?CMCMCYMYMYC?YMYMYMY?CMC?MCMYCMYMYCM?CMCM?CMYMYCYCMCMCMCMCMYM?CYCYCMCM?CY?MYCYCMYM?CYCYCYMY?CYCYC", "1\nC", "1\n?", "2\nMY", "2\n?M", "2\nY?", "2\n??", "3\n??C", "3\nM??", "3\nYCM", "3\n?C?", "3\nMC?", "4\nCYCM", "4\nM...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
102
codeforces
a11b895434d38046521547a0eab8a544
Mahmoud and a xor trip
Mahmoud and Ehab live in a country with *n* cities numbered from 1 to *n* and connected by *n*<=-<=1 undirected roads. It's guaranteed that you can reach any city from any other using these roads. Each city has a number *a**i* attached to it. We define the distance from city *x* to city *y* as the xor of numbers attac...
{"inputs": ["3\n1 2 3\n1 2\n2 3", "5\n1 2 3 4 5\n1 2\n2 3\n3 4\n3 5", "5\n10 9 8 7 6\n1 2\n2 3\n3 4\n3 5", "1\n1", "2\n1 2\n1 2"], "outputs": ["10", "52", "131", "1", "6"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1
codeforces
a150fbee38015b807470d2c6b00af384
A Trivial Problem
Mr. Santa asks all the great programmers of the world to solve a trivial problem. He gives them an integer *m* and asks for the number of positive integers *n*, such that the factorial of *n* ends with exactly *m* zeroes. Are you among those great programmers who can solve this problem? The only line of input contains ...
{"inputs": ["1", "5", "2", "3", "7", "12", "15", "18", "38", "47", "58", "66", "70", "89", "417", "815", "394", "798", "507", "406", "570", "185", "765", "967", "112", "729", "4604", "8783", "1059", "6641", "9353", "1811", "2528", "8158", "3014", "7657", "4934", "9282", "2610", "2083", "26151", "64656", "46668", "95554...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
106
codeforces
a153a90833c2b44aa015cebcc75e0dd5
Famil Door and Brackets
As Famil Door’s birthday is coming, some of his friends (like Gabi) decided to buy a present for him. His friends are going to buy a string consisted of round brackets since Famil Door loves string of brackets of length *n* more than any other strings! The sequence of round brackets is called valid if and only if: 1...
{"inputs": ["4 1\n(", "4 4\n(())", "4 3\n(((", "875 50\n)))((())()))((()(())))))())))((((((()))))))()(((((", "1980 464\n))(()()))(((((((((()))))))(()(((()((()))()()())()))()))(()))))))(())((())))()())()((())())()())))(())()(()))(()())()((((()))())()(())))))(()()(()(((((()(()()))(((()))(())))))()())(())))))())()()((()))...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
5
codeforces
a15e3076b733ae6ce136f3bc1076d466
One-Dimensional Battle Ships
Alice and Bob love playing one-dimensional battle ships. They play on the field in the form of a line consisting of *n* square cells (that is, on a 1<=×<=*n* table). At the beginning of the game Alice puts *k* ships on the field without telling their positions to Bob. Each ship looks as a 1<=×<=*a* rectangle (that is,...
{"inputs": ["11 3 3\n5\n4 8 6 1 11", "5 1 3\n2\n1 5", "5 1 3\n1\n3", "1 1 1\n1\n1", "5000 1660 2\n20\n1 100 18 102 300 81 19 25 44 88 1337 4999 1054 1203 91 16 164 914 1419 1487", "5000 1000 2\n3\n1000 2000 3000", "10 2 4\n2\n5 6", "10 2 4\n3\n5 6 1", "4 2 1\n2\n1 2", "4 2 1\n2\n1 3", "50 7 3\n20\n24 18 34 32 44 2 5 40...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
5
codeforces
a17f96a169f764bf7549a12a7601b7f6
Common Divisors
Vasya has recently learned at school what a number's divisor is and decided to determine a string's divisor. Here is what he came up with. String *a* is the divisor of string *b* if and only if there exists a positive integer *x* such that if we write out string *a* consecutively *x* times, we get string *b*. For exam...
{"inputs": ["abcdabcd\nabcdabcdabcdabcd", "aaa\naa", "aaaaaaaaaaaaaaaaaaaaaaaaa\naaaaaaaaaaaaaaaaaaaaaaaaa", "aaaaaaaaaaaaaa\naaaaaaaaaaaaaa", "a\nb", "a\na", "ab\nac", "asdkjjaskldjklasjdhasjdasdas\nasdjahsgdjslkdaygsudhasdkasnjdbayusvduasdklmaklsd", "aaa\naaaaab", "ab\naa", "aa\naac", "aba\nabaaba", "aa\nbb", "ababab...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
81
codeforces
a1e038341460b4b5f2afab6987a32488
Vanya and Field
Vanya decided to walk in the field of size *n*<=×<=*n* cells. The field contains *m* apple trees, the *i*-th apple tree is at the cell with coordinates (*x**i*,<=*y**i*). Vanya moves towards vector (*dx*,<=*dy*). That means that if Vanya is now at the cell (*x*,<=*y*), then in a second he will be at cell . The followin...
{"inputs": ["5 5 2 3\n0 0\n1 2\n1 3\n2 4\n3 1", "2 3 1 1\n0 0\n0 1\n1 1", "5 5 2 4\n0 0\n1 2\n1 3\n2 4\n3 1", "6 6 5 5\n0 0\n0 1\n0 2\n0 3\n0 4\n0 5", "6 6 1 1\n0 0\n1 1\n2 1\n0 1\n1 2\n3 4", "1 1 1 1\n0 0", "10 10 7 3\n9 0\n0 0\n7 6\n6 5\n4 8\n0 3\n2 1\n9 2\n7 1\n8 6", "10 10 3 9\n0 0\n3 9\n6 8\n0 1\n3 0\n6 9\n0 2\n3 ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1
codeforces
a1ebebccb9e61deeff2e3692425bfd99
Knight Tournament
Hooray! Berl II, the king of Berland is making a knight tournament. The king has already sent the message to all knights in the kingdom and they in turn agreed to participate in this grand event. As for you, you're just a simple peasant. There's no surprise that you slept in this morning and were late for the tourname...
{"inputs": ["4 3\n1 2 1\n1 3 3\n1 4 4", "8 4\n3 5 4\n3 7 6\n2 8 8\n1 8 1", "2 1\n1 2 1", "2 1\n1 2 2", "3 1\n1 3 1", "3 1\n1 3 2", "3 1\n1 3 3", "3 2\n1 2 1\n1 3 3", "3 2\n1 2 2\n1 3 2", "3 2\n2 3 3\n1 3 3", "11 6\n1 2 2\n7 8 7\n3 4 4\n6 9 6\n5 10 10\n2 11 11", "10 6\n9 10 10\n6 7 7\n2 4 2\n2 5 5\n1 7 5\n4 10 8", "11 8...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
47
codeforces
a1f94be921c53f947516dc5cd455429f
A Tide of Riverscape
"Time," Mino thinks aloud. "What?" "Time and tide wait for no man," explains Mino. "My name, taken from the river, always reminds me of this." "And what are you recording?" "You see it, tide. Everything has its own period, and I think I've figured out this one," says Mino with confidence. Doubtfully, Kanno peeks a...
{"inputs": ["10 7\n1.0.1.0.1.", "10 6\n1.0.1.1000", "10 9\n1........1", "1 1\n.", "5 1\n0...1", "17 10\n..1.100..1..0.100", "2 1\n0.", "2 1\n..", "3 1\n.0.", "3 1\n00.", "3 2\n0..", "3 2\n0.0", "3 2\n1..", "3 2\n.1.", "3 2\n1.0", "3 3\n1..", "3 3\n.00", "5 3\n0.000", "10 6\n10010.1001", "75 38\n00.0.1.0.0110.1.00010..1...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
91
codeforces
a1ff4a4dc6978ae2658829c5d4153e9d
Turing Tape
INTERCAL is the oldest of esoteric programming languages. One of its many weird features is the method of character-based output, known as Turing Tape method. It converts an array of unsigned 8-bit integers into a sequence of characters to print, using the following method. The integers of the array are processed one ...
{"inputs": ["Hello, World!", "N", "!{|aPUBKs[k\"HE;>O&(Nf}N4,*#g*<3sQXFJ'?Z/H9L[xx Rc5\"8~v}84+wv]w[oO0e':MaNy&6*]jRkYomz[o?=13Y?!fzA3eC\\", "!{|aPUBKs[k\"HE;>O&(Nf}N4,*#g*<3sQXFJ'?Z/H9L[xx Rc5\"8~v}84+wv]w", ":J&UY'O]>@Lc\"4ow&?8#yq{s=gH%'`3Yd[CP#", "Py0L_[Ymh&.", "fH9Bh0f|3gn\"7r|*8p[,<]|4Z%2]&E4$/_@\\wI8v4{]/`4uU']f...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
20
codeforces
a231e72241af8e71a16175ca67d36528
New Year Ratings Change
One very well-known internet resource site (let's call it X) has come up with a New Year adventure. Specifically, they decided to give ratings to all visitors. There are *n* users on the site, for each user we know the rating value he wants to get as a New Year Present. We know that user *i* wants to get at least *a**...
{"inputs": ["3\n5 1 1", "1\n1000000000", "10\n1 1 1 1 1 1 1 1 1 1", "10\n1 10 1 10 1 1 7 8 6 7", "10\n20 19 12 1 12 15 2 12 6 10", "10\n4 5 10 5 2 14 15 6 10 6"], "outputs": ["5 1 2", "1000000000", "1 2 3 4 5 6 7 8 9 10", "1 10 2 11 3 4 7 9 6 8", "20 19 12 1 13 15 2 14 6 10", "4 5 10 6 2 14 15 7 11 8"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
3
codeforces
a232dc00ac7aae6da037f10933bb44de
Om Nom and Spiders
Om Nom really likes candies and doesn't like spiders as they frequently steal candies. One day Om Nom fancied a walk in a park. Unfortunately, the park has some spiders and Om Nom doesn't want to see them at all. The park can be represented as a rectangular *n*<=×<=*m* field. The park has *k* spiders, each spider at t...
{"inputs": ["3 3 4\n...\nR.L\nR.U", "2 2 2\n..\nRL", "2 2 2\n..\nLR", "3 4 8\n....\nRRLL\nUUUU", "2 2 2\n..\nUU", "2 2 0\n..\n..", "5 5 10\n.....\nRU.D.\n..DLL\n.D...\nRL..L", "5 6 20\n......\n.UURD.\nLUD.RR\nU.LDDD\nDDLDDU", "4 5 15\n.....\nDRRLR\nULDLD\nDLRRL", "3 7 14\n.......\nLDUDLLD\nDLRDDLD", "5 7 19\n.......\nR...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
12
codeforces
a25b99927c1fe9a25064f4c8913d5efe
Logging
The main server of Gomble company received a log of one top-secret process, the name of which can't be revealed. The log was written in the following format: «[date:time]: message», where for each «[date:time]» value existed not more than 10 lines. All the files were encoded in a very complicated manner, and only one p...
{"inputs": ["5\n[05:00 a.m.]: Server is started\n[05:00 a.m.]: Rescan initialized\n[01:13 p.m.]: Request processed\n[01:10 p.m.]: Request processed\n[11:40 p.m.]: Rescan completed", "3\n[09:00 a.m.]: User logged in\n[08:00 a.m.]: User logged in\n[07:00 a.m.]: User logged in", "1\n[10:41 a.m.]: apppmama", "2\n[06:00 p.m...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
7
codeforces
a26a8e7336bd96f1651e41965adafc97
Harry Potter and the Golden Snitch
Brothers Fred and George Weasley once got into the sporting goods store and opened a box of Quidditch balls. After long and painful experiments they found out that the Golden Snitch is not enchanted at all. It is simply a programmed device. It always moves along the same trajectory, which is a polyline with vertices at...
{"inputs": ["4\n0 0 0\n0 10 0\n10 10 0\n10 0 0\n0 0 0\n1 1\n5 5 25", "4\n0 0 0\n0 10 0\n10 10 0\n10 0 0\n0 0 0\n1 1\n5 5 50", "1\n1 2 3\n4 5 6\n20 10\n1 2 3", "4\n0 0 0\n0 1 0\n1 1 0\n1 0 0\n0 0 0\n10 5\n0 0 8", "4\n1 0 0\n0 1 0\n-1 0 0\n0 -1 0\n1 0 0\n10 5\n9 0 -8", "5\n32 -5 -42\n-25 -38 -6\n-13 41 25\n21 -25 -32\n43...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1
codeforces
a27015427e5cc08931f5d8475ff1b770
Borze
Ternary numeric notation is quite popular in Berland. To telegraph the ternary number the Borze alphabet is used. Digit 0 is transmitted as «.», 1 as «-.» and 2 as «--». You are to decode the Borze code, i.e. to find out the ternary number given its representation in Borze alphabet. The first line contains a number in ...
{"inputs": [".-.--", "--.", "-..-.--", "---..", "..--.---..", "-.....----.", ".", "-.", "--", "..", "--.", ".--.", ".-.-..", "----.-.", "-..--.-.", "..--..--.", "-.-.---.--..-..-.-.-..-..-.--.", "---.-.-.------..-..-..-..-.-..-.--.-.-..-.-.-----..-.-.", "-.-..--.-.-.-.-.-..-.-.-.---------.--.---..--...--.-----.-.-.-......
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1,391
codeforces
a286165c7516c35e6956e6d47b0b42dd
A and B and Team Training
A and B are preparing themselves for programming contests. An important part of preparing for a competition is sharing programming knowledge from the experienced members to those who are just beginning to deal with the contests. Therefore, during the next team training A decided to make teams so that newbies are solvi...
{"inputs": ["2 6", "4 5", "1 1", "3 3", "500000 500000", "70 100", "5 12525", "10 5", "5 10", "0 0", "0 1", "1 0", "0 21233", "12523 0", "1231 1253", "500000 0", "1 500000", "250000 500000", "500000 250000", "33333 77777", "30900 174529", "89979 57154", "231646 398487", "332019 281112", "473686 122443", "481245 86879",...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
84
codeforces
a2b399b76ffe355dbbff668c36b53694
Restoring Painting
Vasya works as a watchman in the gallery. Unfortunately, one of the most expensive paintings was stolen while he was on duty. He doesn't want to be fired, so he has to quickly restore the painting. He remembers some facts about it. - The painting is a square 3<=×<=3, each cell contains a single integer from 1 to *n*,...
{"inputs": ["2 1 1 1 2", "3 3 1 2 3", "1 1 1 1 1", "1000 522 575 426 445", "99000 52853 14347 64237 88869", "100000 2 2 2 2", "2 1 1 2 2", "10 9 10 8 10", "100 19 16 35 83", "1000 102 583 606 929", "10000 1816 3333 6908 7766", "100000 80015 84290 50777 30497", "100000 64022 49026 55956 88430", "100000 10263 46628 10268...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
80
codeforces
a2ba0f879682d8449601222a60c2fade
Chip 'n Dale Rescue Rangers
A team of furry rescue rangers was sitting idle in their hollow tree when suddenly they received a signal of distress. In a few moments they were ready, and the dirigible of the rescue chipmunks hit the road. We assume that the action takes place on a Cartesian plane. The headquarters of the rescuers is located at poi...
{"inputs": ["0 0 5 5\n3 2\n-1 -1\n-1 0", "0 0 0 1000\n100 1000\n-50 0\n50 0", "0 0 0 1000\n100 5\n0 -50\n0 50", "0 1000 0 0\n50 10\n-49 0\n49 0", "0 1000 0 0\n50 10\n0 -48\n0 -49", "0 0 0 -5000\n100 20\n-50 0\n50 0", "0 0 0 -350\n55 5\n0 -50\n0 50", "0 -1000 0 0\n11 10\n-10 0\n10 0", "0 -1000 0 0\n22 10\n0 -12\n0 -10",...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
8
codeforces
a2bc2f7521976470d00bfaf50316f27e
none
Limak is a little bear who loves to play. Today he is playing by destroying block towers. He built *n* towers in a row. The *i*-th tower is made of *h**i* identical blocks. For clarification see picture for the first sample. Limak will repeat the following operation till everything is destroyed. Block is called inter...
{"inputs": ["6\n2 1 4 6 2 2", "7\n3 3 3 1 3 3 3", "7\n5128 5672 5805 5452 5882 5567 5032", "10\n1 2 2 3 5 5 5 4 2 1", "14\n20 20 20 20 20 20 3 20 20 20 20 20 20 20", "50\n3 2 4 3 5 3 4 5 3 2 3 3 3 4 5 4 2 2 3 3 4 4 3 2 3 3 2 3 4 4 5 2 5 2 3 5 4 4 2 2 3 5 2 5 2 2 5 4 5 4", "1\n1", "1\n1000000000", "2\n1 1", "2\n1049 109...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
35
codeforces
a2bf2a16b17237429b68c7603aca7dd8
Counting Arrays
You are given two positive integer numbers *x* and *y*. An array *F* is called an *y*-factorization of *x* iff the following conditions are met: - There are *y* elements in *F*, and all of them are integer numbers; - . You have to count the number of pairwise distinct arrays that are *y*-factorizations of *x*. Two ...
{"inputs": ["2\n6 3\n4 2", "1\n524288 1000000", "1\n65536 1000000", "1\n5612 11399"], "outputs": ["36\n6", "645043186", "928522471", "215664246"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
3
codeforces
a31657a96754322c131cf30c5d872c0f
Vika and Segments
Vika has an infinite sheet of squared paper. Initially all squares are white. She introduced a two-dimensional coordinate system on this sheet and drew *n* black horizontal and vertical segments parallel to the coordinate axes. All segments have width equal to 1 square, that means every segment occupy some set of neigh...
{"inputs": ["3\n0 1 2 1\n1 4 1 2\n0 3 2 3", "4\n-2 -1 2 -1\n2 1 -2 1\n-1 -2 -1 2\n1 2 1 -2", "1\n1 1 1 1", "10\n-357884841 -999999905 -357884841 999999943\n-130177221 999999983 -130177221 -999999974\n627454332 999999936 627454332 -999999900\n999999986 366591992 -999999919 366591992\n488824292 999999952 488824292 -99999...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1
codeforces
a3281c31c3b5224aa9892ad964cb7901
Choosing Symbol Pairs
There is a given string *S* consisting of *N* symbols. Your task is to find the number of ordered pairs of integers *i* and *j* such that 1. 1<=≤<=*i*,<=*j*<=≤<=*N* 2. *S*[*i*]<==<=*S*[*j*], that is the *i*-th symbol of string *S* is equal to the *j*-th. The single input line contains *S*, consisting of lowercase Lat...
{"inputs": ["great10", "aaaaaaaaaa", "great10", "aaaaaaaaaa", "aabb", "w", "129a", "233444", "abacaba", "abcdefghijklmnopqrstuvwxyz0987654321abcdefghijklmnopqrstuvwxyz0987654321abcdefghijklmnopqrstuvwxyz0987654321", "zazaeeeeeeeq34443333444tttttt", "00000000000000000000000", "999000888775646453342311"], "outputs": ["7"...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
93
codeforces
a36e01a2e880a8e0b0d446d29f8160bf
Bertown roads
Bertown has *n* junctions and *m* bidirectional roads. We know that one can get from any junction to any other one by the existing roads. As there were more and more cars in the city, traffic jams started to pose real problems. To deal with them the government decided to make the traffic one-directional on all the ro...
{"inputs": ["6 8\n1 2\n2 3\n1 3\n4 5\n4 6\n5 6\n2 4\n3 5", "6 7\n1 2\n2 3\n1 3\n4 5\n4 6\n5 6\n2 4", "10 19\n6 8\n5 8\n8 3\n1 9\n3 6\n4 8\n10 8\n8 7\n5 3\n10 1\n5 10\n4 10\n2 1\n3 2\n7 6\n8 2\n1 6\n10 7\n2 10", "5 9\n5 4\n2 1\n3 4\n4 1\n5 2\n2 3\n4 2\n3 1\n5 1", "6 9\n4 1\n3 4\n5 6\n3 1\n4 2\n1 5\n6 1\n6 4\n5 4", "5 10...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
2
codeforces
a375bb8bb85b5bb04c9e51f73ff57e19
Nearest vectors
You are given the set of vectors on the plane, each of them starting at the origin. Your task is to find a pair of vectors with the minimal non-oriented angle between them. Non-oriented angle is non-negative value, minimal between clockwise and counterclockwise direction angles. Non-oriented angle is always between 0 ...
{"inputs": ["4\n-1 0\n0 -1\n1 0\n1 1", "6\n-1 0\n0 -1\n1 0\n1 1\n-4 -5\n-4 -6", "10\n8 6\n-7 -3\n9 8\n7 10\n-3 -8\n3 7\n6 -8\n-9 8\n9 2\n6 7", "20\n-9 8\n-7 3\n0 10\n3 7\n6 -9\n6 8\n7 -6\n-6 10\n-10 3\n-8 -10\n10 -2\n1 -8\n-8 10\n10 10\n10 6\n-5 6\n5 -8\n5 -9\n-9 -1\n9 2", "2\n351 -4175\n-328 -657", "3\n620 -1189\n8101...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
6
codeforces
a39d1af7355f30882262bbdc3bc1142b
Duff in Love
Duff is in love with lovely numbers! A positive integer *x* is called lovely if and only if there is no such positive integer *a*<=&gt;<=1 such that *a*2 is a divisor of *x*. Malek has a number store! In his store, he has only divisors of positive integer *n* (and he has all of them). As a birthday present, Malek want...
{"inputs": ["10", "12", "1", "2", "4", "8", "3", "31", "97", "1000000000000", "15", "894", "271", "2457", "2829", "5000", "20", "68", "3096", "1024", "1048576", "413933789280", "817634153013", "56517269141", "30707328551", "279564127218", "491159577042", "734337660466", "808453785117", "55926835837", "294809951965", "5...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
149
codeforces
a3e71338c9156c7480a89573f5f6404e
Prison Transfer
The prison of your city has *n* prisoners. As the prison can't accommodate all of them, the city mayor has decided to transfer *c* of the prisoners to a prison located in another city. For this reason, he made the *n* prisoners to stand in a line, with a number written on their chests. The number is the severity of th...
{"inputs": ["4 3 3\n2 3 1 1", "1 1 1\n2", "11 4 2\n2 2 0 7 3 2 2 4 9 1 4", "57 2 10\n7 5 2 7 4 1 0 5 2 9 2 9 8 6 6 5 9 6 8 1 0 1 0 3 2 6 5 2 8 8 8 8 0 9 4 3 6 6 2 4 5 1 2 0 1 7 1 1 5 4 5 0 7 5 1 9 6", "2 228885628 1\n90897004 258427916", "3 1 1\n1 2 1", "3 3 3\n3 2 3", "4 2 2\n1 3 3 2", "1 228 1\n1"], "outputs": ["2", ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
33
codeforces