Search is not available for this dataset
problem_id
stringlengths
32
32
name
stringlengths
2
112
problem
stringlengths
200
14k
test_cases
stringlengths
33
79.2M
difficulty
stringclasses
33 values
language
listlengths
1
1
source
stringclasses
14 values
num_solutions
int64
2
1.9M
starter_code
stringlengths
0
1.47k
subset
stringclasses
3 values
3fd6afa7e65bd757f1d253da0506bad2
none
The clique problem is one of the most well-known NP-complete problems. Under some simplification it can be formulated as follows. Consider an undirected graph *G*. It is required to find a subset of vertices *C* of the maximum size such that any two of them are connected by an edge in graph *G*. Sounds simple, doesn't ...
{"inputs": ["4\n2 3\n3 1\n6 1\n0 2", "1\n42 23", "2\n1 5\n2 6", "2\n1 5\n12 6", "1\n0 1", "1\n1000000000 1000000000", "2\n4 4\n12 5", "2\n4 4\n12 4", "2\n4 4\n12 3", "3\n0 1\n2 1\n4 1", "3\n0 1\n2 2\n4 1", "2\n0 1\n1000000000 1", "2\n0 1000000000\n1000000000 1000000000", "1\n76438 10", "10\n6 15\n4 5\n1 4\n2 4\n0 6\n9 ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
38
codeforces
3ff2cbe65f52ba8911e911d0182c829d
Spotlights
Theater stage is a rectangular field of size *n*<=×<=*m*. The director gave you the stage's plan which actors will follow. For each cell it is stated in the plan if there would be an actor in this cell or not. You are to place a spotlight on the stage in some good position. The spotlight will project light in one of t...
{"inputs": ["2 4\n0 1 0 0\n1 0 1 0", "4 4\n0 0 0 0\n1 0 0 1\n0 1 1 0\n0 1 0 0", "1 5\n1 1 0 0 0", "2 10\n0 0 0 0 0 0 0 1 0 0\n1 0 0 0 0 0 0 0 0 0", "3 1\n1\n0\n0", "5 7\n0 0 0 0 0 0 1\n0 0 0 0 0 0 1\n0 0 0 1 0 0 0\n0 0 0 0 0 0 0\n0 0 0 0 0 0 0", "10 20\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n1 1 1 1 0 1 1 1 1 1 1 1 1...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
83
codeforces
3ff91f444ea82f0d659a0cee9eab7199
University Classes
There are *n* student groups at the university. During the study day, each group can take no more than 7 classes. Seven time slots numbered from 1 to 7 are allocated for the classes. The schedule on Monday is known for each group, i. e. time slots when group will have classes are known. Your task is to determine the ...
{"inputs": ["2\n0101010\n1010101", "3\n0101011\n0011001\n0110111", "1\n0111000", "1\n0000000", "1\n1111111", "2\n1000000\n0101000", "3\n0101111\n1101011\n1010011", "5\n0100101\n0000001\n0110000\n0010000\n0011110", "6\n1101110\n1111011\n1101110\n0100011\n1110110\n1110100", "10\n0000000\n0010000\n0000000\n0000010\n000000...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
205
codeforces
400f7e05f6be90746148a4be088b9c36
Cards and Joy
There are $n$ players sitting at the card table. Each player has a favorite number. The favorite number of the $j$-th player is $f_j$. There are $k \cdot n$ cards on the table. Each card contains a single integer: the $i$-th card contains number $c_i$. Also, you are given a sequence $h_1, h_2, \dots, h_k$. Its meaning...
{"inputs": ["4 3\n1 3 2 8 5 5 8 2 2 8 5 2\n1 2 2 5\n2 6 7", "3 3\n9 9 9 9 9 9 9 9 9\n1 2 3\n1 2 3", "1 1\n1\n2\n1", "1 1\n1\n1\n1", "1 1\n1\n1\n100000", "50 1\n52 96 99 37 143 148 10 140 131 29 82 134 56 73 121 57 98 101 134 4 103 10 86 70 4 98 102 35 149 47 136 87 4 127 142 105 78 10 123 75 67 149 81 78 34 79 62 12 43...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
8
codeforces
402e655a9681a4ba53d28cd08cebe137
Dot
Anton and Dasha like to play different games during breaks on checkered paper. By the 11th grade they managed to play all the games of this type and asked Vova the programmer to come up with a new game. Vova suggested to them to play a game under the code name "dot" with the following rules: - On the checkered paper ...
{"inputs": ["0 0 2 3\n1 1\n1 2", "0 0 2 4\n1 1\n1 2", "0 0 5 100\n12 105\n15 59\n21 1\n27 6\n27 76", "0 0 5 100\n16 24\n29 6\n44 24\n66 37\n102 19", "0 0 5 100\n4 108\n5 170\n7 30\n7 101\n21 117", "0 0 5 100\n30 9\n53 14\n84 7\n94 18\n121 16", "0 0 5 100\n52 144\n55 58\n56 103\n98 65\n134 16", "0 0 5 100\n17 3\n42 24\n...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
2
codeforces
404367fb62cada8206433e740328e249
Trees in a Row
The Queen of England has *n* trees growing in a row in her garden. At that, the *i*-th (1<=≤<=*i*<=≤<=*n*) tree from the left has height *a**i* meters. Today the Queen decided to update the scenery of her garden. She wants the trees' heights to meet the condition: for all *i* (1<=≤<=*i*<=&lt;<=*n*), *a**i*<=+<=1<=-<=*a...
{"inputs": ["4 1\n1 2 1 5", "4 1\n1 2 3 4", "50 1\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50", "10 1\n1 2 3 4 5 6 7 8 9 10", "50 5\n232 6 11 16 21 26 31 36 41 46 665 56 61 66 71 76 602 86 91 712 101 106 111 116 121 126 13...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
25
codeforces
404b200d427f3ddb6485f4203e91fecd
Weird Chess
Igor has been into chess for a long time and now he is sick of the game by the ordinary rules. He is going to think of new rules of the game and become world famous. Igor's chessboard is a square of size *n*<=×<=*n* cells. Igor decided that simple rules guarantee success, that's why his game will have only one type of...
{"inputs": ["5\noxxxx\nx...x\nx...x\nx...x\nxxxxo", "6\n.x.x..\nx.x.x.\n.xo..x\nx..ox.\n.x.x.x\n..x.x.", "3\no.x\noxx\no.x", "1\no", "2\nox\n.o", "5\n.xxo.\n..oxo\nx.oxo\no..xo\noooox", "8\n..x.xxx.\nx.x.xxxx\nxxxxxxox\nxxoxxxxx\n.xxxx.x.\nx.xxx.x.\n..x..xx.\n.xx...x.", "8\noxxxxxxx\nxoxxxoxx\nxx...x..\nxx...x..\nxx......
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
3
codeforces
405b8caa86e7814d1e817ab826b49213
The Useless Toy
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays – caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption. Spinners in Sweetland have the form of V-shaped pieces of caramel. Each s...
{"inputs": ["^ >\n1", "< ^\n3", "^ v\n6", "^ >\n999999999", "> v\n1", "v <\n1", "< ^\n1", "v <\n422435957", "v >\n139018901", "v ^\n571728018", "^ ^\n0", "< >\n2", "> >\n1000000000", "v v\n8", "< <\n1568", "^ v\n2", "^ <\n1", "< v\n1", "v >\n1", "> ^\n1", "v <\n422435957", "v v\n927162384", "v ^\n571728018", "^ <\n4674...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
170
codeforces
40717239356b32937395da93d2c71397
TCMCF+++
Vasya has gotten interested in programming contests in TCMCF+++ rules. On the contest *n* problems were suggested and every problem had a cost — a certain integral number of points (perhaps, negative or even equal to zero). According to TCMCF+++ rules, only accepted problems can earn points and the overall number of po...
{"inputs": ["5\n1 2 -3 3 3", "13\n100 100 100 100 100 100 100 100 100 100 100 100 100", "4\n-2 -2 -2 -2", "1\n1", "1\n-1", "1\n0", "2\n1 1", "2\n1 -1", "2\n-1 1", "2\n-1 -1", "2\n1 0", "2\n0 1", "2\n0 0", "2\n-1 0", "2\n0 -1", "1\n13", "1\n-13", "1\n100", "1\n-100", "2\n100 100", "2\n100 -100", "2\n-100 100", "2\n100 0...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
13
codeforces
408f82f624583dec0966eee9d774fe37
Valera and Fruits
Valera loves his garden, where *n* fruit trees grow. This year he will enjoy a great harvest! On the *i*-th tree *b**i* fruit grow, they will ripen on a day number *a**i*. Unfortunately, the fruit on the tree get withered, so they can only be collected on day *a**i* and day *a**i*<=+<=1 (all fruits that are not collec...
{"inputs": ["2 3\n1 5\n2 3", "5 10\n3 20\n2 20\n1 20\n4 20\n5 20", "10 3000\n1 2522\n4 445\n8 1629\n5 772\n9 2497\n6 81\n3 426\n7 1447\n2 575\n10 202", "5 3000\n5 772\n1 2522\n2 575\n4 445\n3 426", "2 1500\n2 575\n1 2522", "12 2856\n9 2728\n8 417\n3 1857\n10 1932\n1 775\n12 982\n9 1447\n1 426\n7 2918\n11 2522\n10 2497\...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
49
codeforces
409dccf3516d83f62b976456af9790aa
Train
A stowaway and a controller play the following game. The train is represented by *n* wagons which are numbered with positive integers from 1 to *n* from the head to the tail. The stowaway and the controller are initially in some two different wagons. Every minute the train can be in one of two conditions — moving or ...
{"inputs": ["5 3 2\nto head\n0001001", "3 2 1\nto tail\n0001", "4 2 1\nto tail\n1000001", "2 1 2\nto head\n111111", "4 1 4\nto head\n010001", "10 2 1\nto tail\n000000001", "5 5 3\nto tail\n01010000000001", "4 3 1\nto tail\n1000001001101", "4 1 3\nto head\n011000011000001", "20 13 9\nto head\n111111111111111111111111111...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
7
codeforces
40c9ef84c365e270b4156155cd48a810
Forbidden Indices
You are given a string *s* consisting of *n* lowercase Latin letters. Some indices in this string are marked as forbidden. You want to find a string *a* such that the value of |*a*|·*f*(*a*) is maximum possible, where *f*(*a*) is the number of occurences of *a* in *s* such that these occurences end in non-forbidden in...
{"inputs": ["5\nababa\n00100", "5\nababa\n00000", "5\nababa\n11111", "100\neebdeddddbecdbddaaecbbaccbecdeacedddcaddcdebedbabbceeeadecadbbeaecdaeabbceacbdbdbbdacebbbccdcbbeedbe\n1101101101110110001000001101001000100001010111001001111000111011000111111010110100000111001100100000", "100\nabbbafdcebdafbfdbbcfbdbeaceccccaaa...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1
codeforces
40cca99cdf0629447b7e56038528c854
Common ancestor
The DNA sequence for every living creature in Berland can be represented as a non-empty line consisting of lowercase Latin letters. Berland scientists found out that all the creatures evolve by stages. During one stage exactly one symbol of the DNA line is replaced by exactly two other ones. At that overall there are *...
{"inputs": ["ababa\naba\n2\nc->ba\nc->cc", "ababa\naba\n7\nc->ba\nc->cc\ne->ab\nz->ea\nb->ba\nd->dd\nd->ab", "ababa\naba\n1\nc->ba", "mvo\nmx\n5\nu->dl\nt->fb\nx->vo\nn->kq\na->ca", "bxr\nbxr\n5\nw->jk\nm->ie\nh->ab\nu->sy\nj->gj", "oaujn\noaemvsbb\n50\ny->zr\nw->qg\nf->ep\nw->pd\nq->gf\ng->sn\nw->ug\ne->yj\nn->bb\nd->...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
2
codeforces
40ce2b9ba56732ac93bbdb9bc82a216d
Color the Fence
Igor has fallen in love with Tanya. Now Igor wants to show his feelings and write a number on the fence opposite to Tanya's house. Igor thinks that the larger the number is, the more chance to win Tanya's heart he has. Unfortunately, Igor could only get *v* liters of paint. He did the math and concluded that digit *d...
{"inputs": ["5\n5 4 3 2 1 2 3 4 5", "2\n9 11 1 12 5 8 9 10 6", "0\n1 1 1 1 1 1 1 1 1", "50\n5 3 10 2 2 4 3 6 5", "22\n405 343 489 474 385 23 100 94 276", "62800\n867 936 2 888 474 530 287 822 220", "27\n836 637 966 929 82 678 213 465 688", "1000000\n100000 100000 100000 100000 100000 100000 100000 100000 100000", "8982...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
35
codeforces
40eb40e325de8be7bfeb81c76388a9d4
Amr and Chemistry
Amr loves Chemistry, and specially doing experiments. He is preparing for a new interesting experiment. Amr has *n* different types of chemicals. Each chemical *i* has an initial volume of *a**i* liters. For this experiment, Amr has to mix all the chemicals together, but all the chemicals volumes must be equal first. ...
{"inputs": ["3\n4 8 2", "3\n3 5 6", "2\n50000 100000", "2\n99999 99998", "17\n1 2 4 8 16 32 64 128 256 512 1024 2048 4096 8192 16384 32768 65536", "19\n1 2 3 4 6 8 16 32 64 128 256 512 1024 2048 4096 8192 16384 32768 65536", "20\n1 2 3 4 6 8 16 20 32 64 128 256 512 1024 2048 4096 8192 16384 32768 65536", "20\n1 2 3 4 6...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
3
codeforces
40f2e176a6abf8dae6b38e3250395111
Four Segments
Several months later Alex finally got his brother Bob's creation by post. And now, in his turn, Alex wants to boast about something to his brother. He thought for a while, and came to the conclusion that he has no ready creations, and decided to write a program for rectangles detection. According to his plan, the progr...
{"inputs": ["1 1 6 1\n1 0 6 0\n6 0 6 1\n1 1 1 0", "0 0 0 3\n2 0 0 0\n2 2 2 0\n0 2 2 2", "0 0 0 2\n2 0 0 0\n2 2 2 0\n0 2 2 2", "0 0 10 0\n0 0 10 0\n0 0 0 5\n0 0 0 -5", "0 0 4 0\n4 0 3 0\n3 0 2 0\n2 0 0 0", "0 0 3 0\n0 0 0 3\n0 3 3 3\n3 3 3 0", "0 0 1 0\n1 0 1 1\n0 1 1 1\n0 0 0 1", "0 0 1 0\n1 0 1 1\n1 1 1 0\n1 0 0 0", "...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
32
codeforces
40f403a46246b12aacc68b00452a2120
Crash
During the "Russian Code Cup" programming competition, the testing system stores all sent solutions for each participant. We know that many participants use random numbers in their programs and are often sent several solutions with the same source code to check. Each participant is identified by some unique positive i...
{"inputs": ["2\n0 1\n1 1", "4\n0 1\n1 2\n1 1\n0 2", "4\n0 1\n1 1\n0 1\n0 2", "4\n7 1\n4 2\n8 2\n1 8", "2\n0 8\n0 5", "3\n7 9\n5 8\n8 2", "1\n0 8", "5\n8 10\n7 9\n5 6\n5 2\n10 7", "7\n0 2\n0 3\n0 2\n0 1\n0 10\n1 10\n0 5", "6\n0 1\n1 1\n2 1\n1 1\n2 1\n4 1", "4\n0 1\n1 1\n0 1\n2 1", "6\n0 1\n1 1\n2 1\n3 1\n4 1\n2 1", "3\n...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
23
codeforces
4104e11d5fa7683657dfb3c6de1bb921
Opponents
Arya has *n* opponents in the school. Each day he will fight with all opponents who are present this day. His opponents have some fighting plan that guarantees they will win, but implementing this plan requires presence of them all. That means if one day at least one of Arya's opponents is absent at the school, then Ar...
{"inputs": ["2 2\n10\n00", "4 1\n0100", "4 5\n1101\n1111\n0110\n1011\n1111", "3 2\n110\n110", "10 6\n1111111111\n0100110101\n1111111111\n0000011010\n1111111111\n1111111111", "10 10\n1111111111\n0001001000\n1111111111\n1111111111\n1111111111\n1000000100\n1111111111\n0000011100\n1111111111\n1111111111", "10 10\n000010001...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
201
codeforces
411cf6d0e6f1f53b7fb05afd40bdfab6
New Year and Old Property
The year 2015 is almost over. Limak is a little polar bear. He has recently learnt about the binary system. He noticed that the passing year has exactly one zero in its representation in the binary system — 201510<==<=111110111112. Note that he doesn't care about the number of zeros in the decimal representation. Lim...
{"inputs": ["5 10", "2015 2015", "100 105", "72057594000000000 72057595000000000", "1 100", "1000000000000000000 1000000000000000000", "1 1000000000000000000", "1 1", "1 2", "1 3", "1 4", "1 5", "1 6", "1 7", "2 2", "2 3", "2 4", "2 5", "2 6", "2 7", "3 3", "3 4", "3 5", "3 6", "3 7", "4 4", "4 5", "4 6", "4 7", "5 5",...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
148
codeforces
413a2efed103298f61dbbdaba82b5d29
Trains and Statistic
Vasya commutes by train every day. There are *n* train stations in the city, and at the *i*-th station it's possible to buy only tickets to stations from *i*<=+<=1 to *a**i* inclusive. No tickets are sold at the last station. Let ρ*i*,<=*j* be the minimum number of tickets one needs to buy in order to get from station...
{"inputs": ["4\n4 4 4", "5\n2 3 5 5", "2\n2", "10\n2 10 8 7 8 8 10 9 10", "3\n3 3", "4\n3 3 4", "5\n4 4 4 5", "6\n3 3 6 6 6", "7\n7 3 4 6 6 7", "8\n3 7 7 8 8 7 8", "9\n2 9 7 6 9 7 8 9"], "outputs": ["6", "17", "1", "63", "3", "8", "13", "21", "35", "37", "52"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
7
codeforces
413ca22062394aad71eddbd8f0a7027b
Tea Party
Polycarp invited all his friends to the tea party to celebrate the holiday. He has *n* cups, one for each of his *n* friends, with volumes *a*1,<=*a*2,<=...,<=*a**n*. His teapot stores *w* milliliters of tea (*w*<=≤<=*a*1<=+<=*a*2<=+<=...<=+<=*a**n*). Polycarp wants to pour tea in cups in such a way that: - Every cup...
{"inputs": ["2 10\n8 7", "4 4\n1 1 1 1", "3 10\n9 8 10", "1 1\n1", "1 1\n2", "1 10\n20", "3 10\n8 4 8", "3 100\n37 26 37", "3 60\n43 23 24", "20 14\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "20 8\n1 2 1 2 1 1 1 2 1 1 1 2 1 1 2 1 1 1 2 2", "50 1113\n25 21 23 37 28 23 19 25 5 12 3 11 46 50 13 50 7 1 8 40 4 6 34 27 11 39...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
46
codeforces
417ce5067c4e2e68d756c82c73b1dd87
none
Leha decided to move to a quiet town Vičkopolis, because he was tired by living in Bankopolis. Upon arrival he immediately began to expand his network of hacked computers. During the week Leha managed to get access to *n* computers throughout the town. Incidentally all the computers, which were hacked by Leha, lie on t...
{"inputs": ["2\n4 7", "3\n4 3 1", "20\n8 11 13 19 21 34 36 44 57 58 61 63 76 78 79 81 85 86 90 95", "20\n1 8 9 12 15 17 18 24 30 33 36 41 53 54 59 62 64 66 72 73", "20\n2 6 8 9 20 23 27 36 43 49 63 65 70 71 85 87 89 91 94 97", "1\n78091781", "2\n1000000000 1", "3\n999999998 999999999 999999992", "3\n465343471 465343474...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
38
codeforces
419ffe04367daa7d7a7fa8fd0572d3b8
Cracking the Code
The protection of a popular program developed by one of IT City companies is organized the following way. After installation it outputs a random five digit number which should be sent in SMS to a particular phone number. In response an SMS activation code arrives. A young hacker Vasya disassembled the program and foun...
{"inputs": ["12345", "13542", "71232", "11111", "10000", "99999", "91537", "70809", "41675", "32036"], "outputs": ["71232", "84443", "10151", "36551", "00000", "99999", "27651", "00000", "61851", "82432"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
11
codeforces
41a166ab295ee669618ba2141ea4821c
Expensive Strings
You are given *n* strings *t**i*. Each string has cost *c**i*. Let's define the function of string , where *p**s*,<=*i* is the number of occurrences of *s* in *t**i*, |*s*| is the length of the string *s*. Find the maximal value of function *f*(*s*) over all strings. Note that the string *s* is not necessarily some s...
{"inputs": ["2\naa\nbb\n2 1", "2\naa\nab\n2 1", "1\naaa\n2", "3\na\naa\naaa\n1 2 3", "3\na\naaa\naa\n2 1 3", "1\nabcde\n-1", "1\na\n1", "5\nbbbb\nbaaa\nbbba\naaba\nbbaa\n17 -17 -82 47 -85", "10\nckxyxnoyqw\nlwvjsygwrc\nhretftiphn\nrqqncjnggb\ntxvnxgkynk\nbukntrryio\ncinrjaobxu\nxqvurzhxth\nkmvrlhpqdk\ndsdubnyoun\n-78 8...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1
codeforces
41ab7444d442dab8d3d66fbf569ee337
Interestring graph and Apples
Hexadecimal likes drawing. She has drawn many graphs already, both directed and not. Recently she has started to work on a still-life «interesting graph and apples». An undirected graph is called interesting, if each of its vertices belongs to one cycle only — a funny ring — and does not belong to any other cycles. A f...
{"inputs": ["3 2\n1 2\n2 3", "1 1\n1 1", "1 2\n1 1\n1 1", "1 3\n1 1\n1 1\n1 1", "2 0", "2 1\n1 1", "2 1\n2 2", "2 1\n2 1", "2 2\n1 1\n2 2", "2 2\n1 2\n2 1", "2 3\n1 1\n1 2\n2 1", "3 2\n1 2\n1 2", "1 0", "4 3\n1 2\n1 3\n1 4", "6 6\n1 2\n2 3\n3 1\n4 5\n5 6\n6 1", "49 0", "50 0", "50 1\n2 3", "3 2\n1 2\n2 3", "5 3\n3 5\n4...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
3
codeforces
41c39b952ce670cd8ffe912e78607de7
A Blend of Springtime
"What a pity it's already late spring," sighs Mino with regret, "one more drizzling night and they'd be gone." "But these blends are at their best, aren't they?" Absorbed in the landscape, Kanno remains optimistic. The landscape can be expressed as a row of consecutive cells, each of which either contains a flower o...
{"inputs": [".BAC.", "AA..CB", ".", "ACB.AAAAAA", "B.BC.BBBCA", "BA..CAB..B", "CACCBAA.BC", ".CAACCBBA.CBB.AC..BABCCBCCB..B.BC..CBC.CA.CC.C.CC.B.A.CC.BBCCBB..ACAACAC.CBCCB.AABAAC.CBCC.BA..CCBC.", "A", "..", "BC", "CAB", "A.CB", "B.ACAA.CA..CBCBBAA.B.CCBCB.CAC.ABC...BC.BCCC.BC.CB", "B.B...CC.B..CCCB.CB..CBCB..CBCC.CCBC....
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
358
codeforces
41ca8fb7f117ce4485016a95203706a3
Crazy Town
Crazy Town is a plane on which there are *n* infinite line roads. Each road is defined by the equation *a**i**x*<=+<=*b**i**y*<=+<=*c**i*<==<=0, where *a**i* and *b**i* are not both equal to the zero. The roads divide the plane into connected regions, possibly of infinite space. Let's call each such region a block. We ...
{"inputs": ["1 1\n-1 -1\n2\n0 1 0\n1 0 0", "1 1\n-1 -1\n3\n1 0 0\n0 1 0\n1 1 -3", "841746 527518\n595261 331297\n10\n-946901 129987 670374\n-140388 -684770 309555\n-302589 415564 -387435\n-565799 -72069 -395358\n-523453 -511446 854898\n-846967 -749453 -341866\n-622388 434663 264157\n-638453 625357 344195\n-255265 -6763...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
72
codeforces
41d636d593d8694e8ec12e3e434c3a50
none
A tree is a graph with *n* vertices and exactly *n*<=-<=1 edges; this graph should meet the following condition: there exists exactly one shortest (by number of edges) path between any pair of its vertices. A subtree of a tree *T* is a tree with both vertices and edges as subsets of vertices and edges of *T*. You're ...
{"inputs": ["3\n1 2\n1 3\n1 -1 1", "5\n2 3\n4 5\n2 5\n1 3\n0 2 1 4 3", "10\n5 6\n8 2\n9 3\n4 1\n6 10\n9 8\n7 10\n7 4\n5 2\n0 -6 -9 -1 -5 -4 -2 -7 -8 -3", "5\n3 1\n2 4\n3 4\n2 5\n0 -3 -1 2 4", "12\n1 6\n10 1\n4 1\n7 1\n1 2\n5 1\n1 8\n1 11\n3 1\n12 1\n9 1\n580660007 861441526 -264928594 488291045 253254575 -974301934 709...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
9
codeforces
41eb93137fa630da03ff834ead54d33f
Running Student
And again a misfortune fell on Poor Student. He is being late for an exam. Having rushed to a bus stop that is in point (0,<=0), he got on a minibus and they drove along a straight line, parallel to axis *OX*, in the direction of increasing *x*. Poor Student knows the following: - during one run the minibus makes ...
{"inputs": ["4 5 2\n0 2 4 6\n4 1", "2 1 1\n0 100000\n100000 100000", "6 5 1\n0 1 2 3 4 5\n0 0", "4 100 10\n0 118 121 178\n220 220", "4 3 3\n0 6 8 10\n7 -4", "5 900 1\n0 37474 80030 85359 97616\n-1 -1", "5 200 400\n0 8068 28563 51720 66113\n5423 -34", "6 10 3\n0 12 14 16 19 20\n14 0", "6 13 11\n0 16 27 31 39 42\n54 3", ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
62
codeforces
41ebdff11474320eb192b62f53bee417
Duff and Meat
Duff is addicted to meat! Malek wants to keep her happy for *n* days. In order to be happy in *i*-th day, she needs to eat exactly *a**i* kilograms of meat. There is a big shop uptown and Malek wants to buy meat for her from there. In *i*-th day, they sell meat for *p**i* dollars per kilogram. Malek knows all numbers ...
{"inputs": ["3\n1 3\n2 2\n3 1", "3\n1 3\n2 1\n3 2", "1\n39 52", "2\n25 56\n94 17", "5\n39 21\n95 89\n73 90\n9 55\n85 32", "12\n70 11\n74 27\n32 11\n26 83\n57 18\n97 28\n75 43\n75 21\n84 29\n16 2\n89 63\n21 88", "2\n100 68\n38 80"], "outputs": ["10", "8", "2028", "2998", "6321", "6742", "9384"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
576
codeforces
42091aac2a6cdab50a22dada380bd1cb
Moore's Law
The city administration of IT City decided to fix up a symbol of scientific and technical progress in the city's main square, namely an indicator board that shows the effect of Moore's law in real time. Moore's law is the observation that the number of transistors in a dense integrated circuit doubles approximately ev...
{"inputs": ["1000 1000000", "1000 0", "1000 1", "1000 2", "10000 3", "10000 2000000000", "4907 244618708", "9030 982505993", "4054 287739817", "1587 1941728048"], "outputs": ["1011.060722383550382782399454922040", "1000", "1000.000011000", "1000.000022000000121000", "10000.000330000003630000013310000", "35849124123571....
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
18
codeforces
4218b321e26d2ddfec1d7e89ce1f3bca
none
Santa Claus likes palindromes very much. There was his birthday recently. *k* of his friends came to him to congratulate him, and each of them presented to him a string *s**i* having the same length *n*. We denote the beauty of the *i*-th string by *a**i*. It can happen that *a**i* is negative — that means that Santa d...
{"inputs": ["7 3\nabb 2\naaa -3\nbba -1\nzyz -4\nabb 5\naaa 7\nxyx 4", "3 1\na 1\na 2\na 3", "2 5\nabcde 10000\nabcde 10000", "10 10\nnjxbzflaka -1\nfelbvvtkja 6\ngxiuztqkcw 5\naomvscmtti 6\njsqmkoyuca -2\nwckqtzuixg 5\najktvvblef -5\nittmcsvmoa -1\nakalfzbxjn 10\nacuyokmqsj 8", "10 20\njvyxocgomfmrtllgmagp 13\ngvtjnya...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
5
codeforces
421b45ffdfe79c9f1edcd8d6002e3e6b
Beautiful Function
Every day Ruslan tried to count sheep to fall asleep, but this didn't help. Now he has found a more interesting thing to do. First, he thinks of some set of circles on a plane, and then tries to choose a beautiful set of points, such that there is at least one point from the set inside or on the border of each of the i...
{"inputs": ["3\n0 10 4\n10 0 4\n20 10 4", "3\n0 0 2\n5 7 5\n20 25 10", "1\n0 0 2", "4\n0 0 2\n50 50 2\n50 0 2\n0 50 2", "1\n50 50 50", "50\n48 45 42\n32 45 8\n15 41 47\n32 29 38\n7 16 48\n19 9 21\n18 40 5\n39 40 7\n37 0 6\n42 15 37\n9 33 37\n40 41 33\n25 43 2\n23 21 38\n30 20 32\n28 15 5\n47 9 19\n47 22 26\n26 9 18\n24...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1
codeforces
422bf825badd0a5368d73f8ba0f21a26
Brevity is Soul of Wit
As we communicate, we learn much new information. However, the process of communication takes too much time. It becomes clear if we look at the words we use in our everyday speech. We can list many simple words consisting of many letters: "information", "technologies", "university", "construction", "conservatoire", "r...
{"inputs": ["6\nprivet\nspasibo\ncodeforces\njava\nmarmelad\nnormalno", "5\naaa\naa\na\naaaa\naaaaa", "26\naaaaa\naaaab\naaaac\naaaad\naaaae\naaaaf\naaaag\naaaah\naaaai\naaaaj\naaaak\naaaal\naaaam\naaaan\naaaao\naaaap\naaaaq\naaaar\naaaas\naaaat\naaaau\naaaav\naaaaw\naaaax\naaaay\naaaaz", "26\naaaa\naaab\naaac\naaad\na...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1
codeforces
4232ec75dc18ac6e0a61e3e5a668e21d
Amr and The Large Array
Amr has got a large array of size *n*. Amr doesn't like large arrays so he intends to make it smaller. Amr doesn't care about anything in the array except the beauty of it. The beauty of the array is defined to be the maximum number of times that some number occurs in this array. He wants to choose the smallest subseg...
{"inputs": ["5\n1 1 2 2 1", "5\n1 2 2 3 1", "6\n1 2 2 1 1 2", "10\n1 1000000 2 1000000 3 2 1000000 1 2 1", "10\n1 2 3 4 5 5 1 2 3 4", "10\n1 1 2 1 1 2 2 1 2 3", "10\n5 4 3 2 1 1 2 3 4 5", "10\n1 10 100 1000 10000 1 10 100 1000 10000", "10\n9 9 9 9 8 9 8 8 8 8", "10\n1 11 111 1111 1 11 11 1 1111 1111"], "outputs": ["1 5...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
77
codeforces
426b5a365833606c53c083fcc15d7f14
Presents
The Hedgehog likes to give presents to his friend, but no less he likes to receive them. Having received another present today, the Hedgehog suddenly understood that he has no place to put it as there was no room left on the special shelf in the cupboard. He will have to choose another shelf, but which one should he c...
{"inputs": ["5 2\n1 3", "10 1\n3 6 7 8", "5 5\n1 3", "10 3\n3 3 6 9", "5 2\n0", "1 1\n0", "5 1\n0", "5 1\n1 2", "5 2\n0", "10 3\n2 4 8", "10 1\n0", "10 2\n1 5", "10 1\n0", "10 1\n0", "15 5\n0", "15 1\n1 3", "15 2\n1 10", "15 1\n0", "15 3\n1 11", "20 1\n3 7 9 20", "20 3\n1 11", "20 2\n6 6 9 10 15 19 20", "20 1\n0", "20 ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
22
codeforces
426be2cfde0ba66b5780e3542f125b5d
Two Bases
After seeing the "ALL YOUR BASE ARE BELONG TO US" meme for the first time, numbers *X* and *Y* realised that they have different bases, which complicated their relations. You're given a number *X* represented in base *b**x* and a number *Y* represented in base *b**y*. Compare those two numbers. The first line of the i...
{"inputs": ["6 2\n1 0 1 1 1 1\n2 10\n4 7", "3 3\n1 0 2\n2 5\n2 4", "7 16\n15 15 4 0 0 7 10\n7 9\n4 8 0 3 1 5 0", "2 2\n1 0\n2 3\n1 0", "2 2\n1 0\n1 3\n1", "10 2\n1 0 1 0 1 0 1 0 1 0\n10 3\n2 2 2 2 2 2 2 2 2 2", "10 16\n15 15 4 0 0 0 0 7 10 9\n7 9\n4 8 0 3 1 5 0", "5 5\n4 4 4 4 4\n4 6\n5 5 5 5", "2 8\n1 0\n4 2\n1 0 0 0"...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
221
codeforces
4290dd7eebb98be6552ad447c1d68e45
Haar Features
The first algorithm for detecting a face on the image working in realtime was developed by Paul Viola and Michael Jones in 2001. A part of the algorithm is a procedure that computes Haar features. As part of this task, we consider a simplified model of this concept. Let's consider a rectangular image that is represent...
{"inputs": ["6 8\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW", "3 3\nWBW\nBWW\nWWW", "3 6\nWWBBWW\nWWBBWW\nWWBBWW", "4 4\nBBBB\nBBBB\nBBBB\nBBBW", "10 9\nBWWWBWWBB\nBBWWBWBBW\nBBWBWBWBB\nBWBWBBBBB\nBBWBWBWBW\nBWWBWWBBW\nWBWWWBWWW\nWBBWBWBWW\nBBWWBWWBB\nBBWWBWWBW", "4 1\nW\nW\nB\nB", "2 10\nBBWBWWBWBB\nB...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
11
codeforces
4297a8089e219ee6655d445c9c6e9503
Circular RMQ
You are given circular array *a*0,<=*a*1,<=...,<=*a**n*<=-<=1. There are two types of operations with it: - *inc*(*lf*,<=*rg*,<=*v*) — this operation increases each element on the segment [*lf*,<=*rg*] (inclusively) by *v*; - *rmq*(*lf*,<=*rg*) — this operation returns minimal value on the segment [*lf*,<=*rg*] (in...
{"inputs": ["4\n1 2 3 4\n4\n3 0\n3 0 -1\n0 1\n2 1", "1\n-1\n10\n0 0 -1\n0 0\n0 0 1\n0 0\n0 0 1\n0 0\n0 0 0\n0 0\n0 0 -1\n0 0 1", "2\n-1 -1\n10\n0 0\n0 0\n0 0 1\n0 0\n1 1\n0 0 -1\n0 0 0\n0 0 1\n1 1 0\n0 0 -1"], "outputs": ["1\n0\n0", "-2\n-1\n0\n0", "-1\n-1\n0\n-1"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
8
codeforces
42ad930ecd13a48ee6b60a077599f993
Sequence
Little Petya likes to play very much. And most of all he likes to play the following game: He is given a sequence of *N* integer numbers. At each step it is allowed to increase the value of any number by 1 or to decrease it by 1. The goal of the game is to make the sequence non-decreasing with the smallest number of s...
{"inputs": ["5\n3 2 -1 2 11", "5\n2 1 1 1 1", "5\n0 0 0 0 0", "1\n11", "2\n10 2", "6\n1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000", "7\n1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000", "10\n3 0 5 10 10 9 10 8 8 1", "20\n5 5 6 5 10 9 4 0 0 0 7 7 7 5 6 7 5 6 5 6",...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
7
codeforces
42c6a5a548dc05112d0702ad7a0913f6
The table
Harry Potter has a difficult homework. Given a rectangular table, consisting of *n*<=×<=*m* cells. Each cell of the table contains the integer. Harry knows how to use two spells: the first spell change the sign of the integers in the selected row, the second — in the selected column. Harry's task is to make non-negativ...
{"inputs": ["4 1\n-1\n-1\n-1\n-1", "2 4\n-1 -1 -1 2\n1 1 1 1", "10 5\n1 7 1 6 -3\n8 -8 0 -7 -8\n7 -10 -8 -3 6\n-3 0 -9 0 -3\n-1 5 -2 -9 10\n-2 9 2 0 7\n5 0 -1 -10 6\n7 -8 -3 -9 1\n-5 10 -10 5 9\n-7 4 -8 0 -4", "5 10\n-2 -7 -10 -9 5 -9 -3 8 -8 5\n3 0 9 8 -4 -3 -8 1 8 1\n2 3 7 5 -8 -3 0 -9 -7 -2\n-6 -7 0 0 6 9 -8 6 -8 3\...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1
codeforces
42c910c4a6919aef7498053ae7f7b086
Cubical Planet
You can find anything whatsoever in our Galaxy! A cubical planet goes round an icosahedral star. Let us introduce a system of axes so that the edges of the cubical planet are parallel to the coordinate axes and two opposite vertices lay in the points (0,<=0,<=0) and (1,<=1,<=1). Two flies live on the planet. At the mom...
{"inputs": ["0 0 0\n0 1 0", "1 1 0\n0 1 0", "0 0 0\n1 1 1", "0 0 0\n1 0 0", "0 0 0\n0 1 0", "0 0 0\n1 1 0", "0 0 0\n0 0 1", "0 0 0\n1 0 1", "0 0 0\n0 1 1", "0 0 0\n1 1 1", "1 0 0\n0 0 0", "1 0 0\n0 1 0", "1 0 0\n1 1 0", "1 0 0\n0 0 1", "1 0 0\n1 0 1", "1 0 0\n0 1 1", "1 0 0\n1 1 1", "0 1 0\n0 0 0", "0 1 0\n1 0 0", "0 1...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
135
codeforces
42db725c4f43301d5b259580e315cf37
Sereja and Algorithm
Sereja loves all sorts of algorithms. He has recently come up with a new algorithm, which receives a string as an input. Let's represent the input string of the algorithm as *q*<==<=*q*1*q*2... *q**k*. The algorithm consists of two steps: 1. Find any continuous subsequence (substring) of three characters of string *q...
{"inputs": ["zyxxxxxxyyz\n5\n5 5\n1 3\n1 11\n1 4\n3 6", "yxzyzxzzxyyzzxxxzyyzzyzxxzxyzyyzxyzxyxxyzxyxzyzxyzxyyxzzzyzxyyxyzxxy\n10\n17 67\n6 35\n12 45\n56 56\n14 30\n25 54\n1 1\n46 54\n3 33\n19 40", "xxxxyyxyyzzyxyxzxyzyxzyyyzyzzxxxxzyyzzzzyxxxxzzyzzyzx\n5\n4 4\n3 3\n1 24\n3 28\n18 39", "yzxyzxyzxzxzyzxyzyzzzyxzyz\n9\n4...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
8
codeforces
42df25d03c42a9281bb42d57dea8b11c
Vladik and Complicated Book
Vladik had started reading a complicated book about algorithms containing *n* pages. To improve understanding of what is written, his friends advised him to read pages in some order given by permutation *P*<==<=[*p*1,<=*p*2,<=...,<=*p**n*], where *p**i* denotes the number of page that should be read *i*-th in turn. So...
{"inputs": ["5 5\n5 4 3 2 1\n1 5 3\n1 3 1\n2 4 3\n4 4 4\n2 5 3", "6 5\n1 4 3 2 5 6\n2 4 3\n1 6 2\n4 5 4\n1 3 3\n2 6 3", "10 10\n10 1 6 7 9 8 4 3 5 2\n1 1 1\n4 4 4\n7 7 7\n3 3 3\n1 6 5\n2 6 2\n6 8 7\n1 1 1\n7 9 9\n2 9 4", "20 20\n18 17 2 3 16 15 1 9 12 8 20 11 13 14 4 5 19 7 10 6\n13 15 15\n1 1 1\n2 2 2\n11 14 13\n10 11...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
30
codeforces
4322bd062e78cfb6f7bdbdb6c2d4dea5
Vasya and Types
Programmer Vasya is studying a new programming language &amp;K*. The &amp;K* language resembles the languages of the C family in its syntax. However, it is more powerful, which is why the rules of the actual C-like languages are unapplicable to it. To fully understand the statement, please read the language's descripti...
{"inputs": ["5\ntypedef void* ptv\ntypeof ptv\ntypedef &&ptv node\ntypeof node\ntypeof &ptv", "17\ntypedef void* b\ntypedef b* c\ntypeof b\ntypeof c\ntypedef &b b\ntypeof b\ntypeof c\ntypedef &&b* c\ntypeof c\ntypedef &b* c\ntypeof c\ntypedef &void b\ntypeof b\ntypedef b******* c\ntypeof c\ntypedef &&b* c\ntypeof c", "...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
6
codeforces
43235ed4d2e5609de3c8d6267989703b
SwapSort
In this problem your goal is to sort an array consisting of *n* integers in at most *n* swaps. For the given array find the sequence of swaps that makes the array sorted in the non-descending order. Swaps are performed consecutively, one after another. Note that in this problem you do not have to minimize the number o...
{"inputs": ["5\n5 2 5 1 4", "6\n10 20 20 40 60 60", "2\n101 100", "1\n1000", "2\n1000000000 -1000000000", "8\n5 2 6 8 3 1 6 8", "2\n200000000 199999999", "3\n100000000 100000002 100000001", "5\n1000000000 -10000000 0 8888888 7777777", "5\n10 30 20 50 40"], "outputs": ["2\n0 3\n4 2", "0", "1\n0 1", "0", "1\n0 1", "4\n0 ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
9
codeforces
436124fdf51dc694d298b358c9c52de6
Short Code
Arkady's code contains $n$ variables. Each variable has a unique name consisting of lowercase English letters only. One day Arkady decided to shorten his code. He wants to replace each variable name with its non-empty prefix so that these new names are still unique (however, a new name of some variable can coincide wi...
{"inputs": ["3\ncodeforces\ncodehorses\ncode", "5\nabba\nabb\nab\naa\naacada", "3\ntelegram\ndigital\nresistance", "1\na", "10\naaaba\nbabba\nbbba\naaabb\nabba\na\nbbb\nbaa\naaba\naa", "10\naaaaaaaaaaaaaaa\naaaaaaaaaaaaaa\naaaaaaaa\naaa\naaaaaaaaaaaa\naa\naaaaaaa\naaaaaaaaa\naaaaaaaaaaaaa\naaaaaaaaaa", "26\ni\nm\nz\na\...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1
codeforces
43679e980bde9e7eb4cadb169cffb376
Try and Catch
Vasya is developing his own programming language VPL (Vasya Programming Language). Right now he is busy making the system of exceptions. He thinks that the system of exceptions must function like that. The exceptions are processed by try-catch-blocks. There are two operators that work with the blocks: 1. The try oper...
{"inputs": ["8\ntry\n try\n throw ( AE ) \n catch ( BE, \"BE in line 3\")\n\n try\n catch(AE, \"AE in line 5\") \ncatch(AE,\"AE somewhere\")", "8\ntry\n try\n throw ( AE ) \n catch ( AE, \"AE in line 3\")\n\n try\n catch(BE, \"BE in line 5\") \ncatch(AE,\"AE somewhere\")", "8\ntry\...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
9
codeforces
43742a6b0a3bfdc144e535cc28eadd52
Mike and Chocolate Thieves
Bad news came to Mike's village, some thieves stole a bunch of chocolates from the local factory! Horrible! Aside from loving sweet things, thieves from this area are known to be very greedy. So after a thief takes his number of chocolates for himself, the next thief will take exactly *k* times more than the previous...
{"inputs": ["1", "8", "10", "27", "28206", "32", "115", "81258", "116003", "149344197", "57857854", "999999999999999", "181023403153", "196071196742", "49729446417673", "14821870173923", "29031595887308", "195980601490039", "181076658641313", "166173583620704", "151269640772354", "136366565751970", "121463490731834", "...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
12
codeforces
438d09394374feed263199efaf7d6f1d
Dima and Sequence
Dima got into number sequences. Now he's got sequence *a*1,<=*a*2,<=...,<=*a**n*, consisting of *n* positive integers. Also, Dima has got a function *f*(*x*), which can be defined with the following recurrence: - *f*(0)<==<=0; - *f*(2·*x*)<==<=*f*(*x*); - *f*(2·*x*<=+<=1)<==<=*f*(*x*)<=+<=1. Dima wonders, how many...
{"inputs": ["3\n1 2 4", "3\n5 3 1", "2\n469264357 996569493", "6\n396640239 62005863 473635171 329666981 510631133 207643327", "8\n851991424 32517099 310793856 776130403 342626527 58796623 49544509 517126753", "7\n481003311 553247971 728349004 258700257 916143165 398096105 412826266", "4\n363034183 741262741 657823174 ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
20
codeforces
43ad1fbd0312da59aa03d4cd429e18f2
Jzzhu and Children
There are *n* children in Jzzhu's school. Jzzhu is going to give some candies to them. Let's number all the children from 1 to *n*. The *i*-th child wants to get at least *a**i* candies. Jzzhu asks children to line up. Initially, the *i*-th child stands at the *i*-th place of the line. Then Jzzhu start distribution of...
{"inputs": ["5 2\n1 3 1 4 2", "6 4\n1 1 2 2 3 3", "7 3\n6 1 5 4 2 3 1", "10 5\n2 7 3 6 2 5 1 3 4 5", "100 1\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 7...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
355
codeforces
43b813e4082830bfb6b515f350e10621
Big Segment
A coordinate line has *n* segments, the *i*-th segment starts at the position *l**i* and ends at the position *r**i*. We will denote such a segment as [*l**i*,<=*r**i*]. You have suggested that one of the defined segments covers all others. In other words, there is such segment in the given set, which contains all oth...
{"inputs": ["3\n1 1\n2 2\n3 3", "6\n1 5\n2 3\n1 10\n7 10\n7 7\n10 10", "4\n1 5\n2 2\n2 4\n2 5", "5\n3 3\n1 3\n2 2\n2 3\n1 2", "7\n7 7\n8 8\n3 7\n1 6\n1 7\n4 7\n2 8", "3\n2 5\n3 4\n2 3", "16\n15 15\n8 12\n6 9\n15 16\n8 14\n3 12\n7 19\n9 13\n5 16\n9 17\n10 15\n9 14\n9 9\n18 19\n5 15\n6 19", "9\n1 10\n7 8\n6 7\n1 4\n5 9\n...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
403
codeforces
43c46bb04031f2be203158f0103de1b3
Segments Removal
Vasya has an array of integers of length *n*. Vasya performs the following operations on the array: on each step he finds the longest segment of consecutive equal integers (the leftmost, if there are several such segments) and removes it. For example, if Vasya's array is [13,<=13,<=7,<=7,<=7,<=2,<=2,<=2], then after o...
{"inputs": ["4\n2 5 5 2", "5\n6 3 4 1 5", "8\n4 4 4 2 2 100 100 100", "6\n10 10 50 10 50 50", "1\n1", "100\n45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1
codeforces
442026842a6080e105907e188fe8446f
Travelling Salesman and Special Numbers
The Travelling Salesman spends a lot of time travelling so he tends to get bored. To pass time, he likes to perform operations on numbers. One such operation is to take a positive integer *x* and reduce it to the number of bits set to 1 in the binary representation of *x*. For example for number 13 it's true that 1310<...
{"inputs": ["110\n2", "111111011\n2", "100011110011110110100\n7", "110100110\n0", "10000000000000000000000000000000000000000000\n2", "100000000000000000000100000000000010100100001001000010011101010\n3", "101010110000\n3", "11010110000\n3", "100\n6", "100100100100\n5", "10000000000\n4", "10\n868", "1\n0", "1\n1", "10\n0...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
5
codeforces
444bae627ba01124383dbebb45960ea7
Semifinals
Two semifinals have just been in the running tournament. Each semifinal had *n* participants. There are *n* participants advancing to the finals, they are chosen as follows: from each semifinal, we choose *k* people (0<=≤<=2*k*<=≤<=*n*) who showed the best result in their semifinals and all other places in the finals g...
{"inputs": ["4\n9840 9920\n9860 9980\n9930 10020\n10040 10090", "4\n9900 9850\n9940 9930\n10000 10020\n10060 10110", "1\n1 2", "1\n2 1", "2\n1 2\n3 4", "2\n3 1\n4 2", "3\n1 3\n2 5\n4 6", "3\n2 1\n4 3\n5 6", "3\n1 4\n2 5\n3 6", "4\n5 1\n6 2\n7 3\n8 4", "2\n1 2\n4 3", "3\n1 2\n3 5\n4 6", "3\n1 2\n3 4\n5 6", "3\n1 3\n2 4\...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
38
codeforces
445d9481502b5c3e25f57cafd9bf8b5a
Canvas Frames
Nicholas, a painter is going to paint several new canvases. Nicholas is sure that the canvases will turn out so great that each one will need framing and being hung on the wall. Frames are what Nicholas decided to begin with. Nicholas has *n* sticks whose lengths equal *a*1,<=*a*2,<=... *a**n*. Nicholas does not want...
{"inputs": ["5\n2 4 3 2 3", "13\n2 2 4 4 4 4 6 6 6 7 7 9 9", "4\n3 3 3 5", "2\n3 5", "9\n1 2 3 4 5 6 7 8 9", "14\n2 4 2 6 2 3 4 1 4 5 4 3 4 1", "33\n1 2 2 6 10 10 33 11 17 32 25 6 7 29 11 32 33 8 13 17 17 6 11 11 11 8 10 26 29 26 32 33 36", "1\n1", "1\n10", "2\n1 1", "3\n1 1 1", "3\n1 2 2", "3\n3 2 1", "4\n1 1 1 1", "4...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
125
codeforces
4473ff9e4adbc9cb1817d454202ff6d3
Magic Powder - 1
This problem is given in two versions that differ only by constraints. If you can solve this problem in large constraints, then you can just write a single solution to the both versions. If you find the problem too difficult in large constraints, you can write solution to the simplified version only. Waking up in the ...
{"inputs": ["3 1\n2 1 4\n11 3 16", "4 3\n4 3 5 6\n11 12 14 20", "10 926\n5 6 8 1 2 5 1 8 4 4\n351 739 998 725 953 970 906 691 707 1000", "20 925\n7 3 1 2 1 3 1 3 1 2 3 1 5 8 1 3 7 3 4 2\n837 898 965 807 786 670 626 873 968 745 878 359 760 781 829 882 777 740 907 779", "30 300\n1 4 2 1 2 5 6 4 1 3 2 1 1 1 1 1 2 3 1 3 4 ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
91
codeforces
449f1c28e0986a00b861c10185315278
Pouring Rain
A lot of people in Berland hates rain, but you do not. Rain pacifies, puts your thoughts in order. By these years you have developed a good tradition — when it rains, you go on the street and stay silent for a moment, contemplate all around you, enjoy freshness, think about big deeds you have to do. Today everything ...
{"inputs": ["1 2 3 100", "1 1 1 1", "48 7946 7992 72", "72 6791 8546 46", "100 5635 9099 23", "20 287 3845 5", "48 6428 9807 83", "72 5272 4552 64", "100 4117 5106 34", "20 2961 9852 15", "48 1805 3109 93", "72 8534 7042 65", "1 47 80 68", "4 495 8813 1", "5 2797 5925 9", "1 8324 4362 23", "6 1976 8455 3", "7 2644 8080...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
216
codeforces
44c0f23b8d8ca722aa4895215030b6d0
PolandBall and Hypothesis
PolandBall is a young, clever Ball. He is interested in prime numbers. He has stated a following hypothesis: "There exists such a positive integer *n* that for each positive integer *m* number *n*·*m*<=+<=1 is a prime number". Unfortunately, PolandBall is not experienced yet and doesn't know that his hypothesis is inc...
{"inputs": ["3", "4", "10", "153", "1000", "1", "2", "5", "6", "7", "8", "9", "11", "998", "996", "36", "210", "270", "306", "330", "336", "600", "726", "988", "12", "987", "13", "986", "14", "985", "15", "984", "16", "983", "17", "982", "18", "981", "19", "980", "20", "979", "21", "978", "22", "977", "23", "976", "24"...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
283
codeforces
44ca45f51b5c4a41c257d86927f120ff
Misha and XOR
After Misha's birthday he had many large numbers left, scattered across the room. Now it's time to clean up and Misha needs to put them in a basket. He ordered this task to his pet robot that agreed to complete the task at certain conditions. Before the robot puts a number *x* to the basket, Misha should answer the que...
{"inputs": ["7\n7\n6\n5\n4\n3\n2\n1", "2\n5\n5", "10\n81\n97\n12\n2\n16\n96\n80\n99\n6\n83", "10\n15106\n13599\n69319\n33224\n26930\n94490\n85089\n60931\n23137\n62868", "10\n5059464500\n8210395556\n3004213265\n248593357\n5644084048\n9359824793\n8120649160\n4288978422\n183848555\n8135845959", "10\n4\n12\n28\n29\n31\n31\...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
7
codeforces
44dfc44778d571919af6c6951a9cfbd9
Permutations
Happy PMP is freshman and he is learning about algorithmic problems. He enjoys playing algorithmic games a lot. One of the seniors gave Happy PMP a nice game. He is given two permutations of numbers 1 through *n* and is asked to convert the first one to the second. In one move he can remove the last number from the pe...
{"inputs": ["3\n3 2 1\n1 2 3", "5\n1 2 3 4 5\n1 5 2 3 4", "5\n1 5 2 3 4\n1 2 3 4 5", "1\n1\n1", "7\n6 1 7 3 4 5 2\n6 1 7 3 4 5 2", "10\n5 8 1 10 3 6 2 9 7 4\n4 2 6 3 1 9 10 5 8 7", "10\n1 6 10 3 4 9 2 5 8 7\n7 5 1 6 10 3 4 8 9 2", "10\n2 1 10 3 7 8 5 6 9 4\n6 9 2 4 1 10 3 7 8 5", "10\n8 2 10 3 4 6 1 7 9 5\n8 2 10 3 4 6...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
9
codeforces
44f8b44da74a30906d6c591697c555e4
Green and Black Tea
Innokentiy likes tea very much and today he wants to drink exactly *n* cups of tea. He would be happy to drink more but he had exactly *n* tea bags, *a* of them are green and *b* are black. Innokentiy doesn't like to drink the same tea (green or black) more than *k* times in a row. Your task is to determine the order ...
{"inputs": ["5 1 3 2", "7 2 2 5", "4 3 4 0", "2 2 0 2", "3 2 0 3", "1 1 0 1", "1 1 1 0", "11 2 3 8", "100000 39 24855 75145", "2 2 2 0", "2 2 1 1", "3 2 2 1", "3 2 1 2", "5 1 4 1", "10 1 7 3", "20 1 5 15", "1000 123 447 553", "3000 70 2946 54", "10000 590 4020 5980", "10001 1841 1052 8949", "50000 104 31045 18955", "59...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
19
codeforces
45282fa05e4b8c2d025dd8d93e75065b
Palindrome pairs
You are given a non-empty string *s* consisting of lowercase letters. Find the number of pairs of non-overlapping palindromic substrings of this string. In a more formal way, you have to find the quantity of tuples (*a*,<=*b*,<=*x*,<=*y*) such that 1<=≤<=*a*<=≤<=*b*<=&lt;<=*x*<=≤<=*y*<=≤<=|*s*| and substrings *s*[*a*....
{"inputs": ["aa", "aaa", "abacaba", "aaaaaaaaaa", "aabbb", "abbaa", "bbbbb", "bbaab", "aabba", "aaaaa", "abicabacka", "aiajadabaa", "abacabauabagabaeabacabadabacabbfabacamadabacabaeabacabadabacababcdggdefxeceadaffhecbgpdbeffecdcbfagcbbfgegaggcaffdfiafaeaab", "abacabadabacabaeabacabadabacabafabacabadabqcabaeoqacabagabac...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
11
codeforces
45481b7f95028e4feb5463900ff4ae43
Kefa and Company
Kefa wants to celebrate his first big salary by going to restaurant. However, he needs company. Kefa has *n* friends, each friend will agree to go to the restaurant if Kefa asks. Each friend is characterized by the amount of money he has and the friendship factor in respect to Kefa. The parrot doesn't want any friend...
{"inputs": ["4 5\n75 5\n0 100\n150 20\n75 1", "5 100\n0 7\n11 32\n99 10\n46 8\n87 54", "1 1000000000\n15 12", "5 1\n5 9\n2 10\n8 5\n18 12\n1 1", "3 3\n4 15\n0 17\n9 11", "5 10\n8 90\n1009 1000000\n9 121\n10 298\n0 109092", "5 9\n0 98\n2 1000000000\n8 1000000000\n5 999999999\n3 989898989", "4 2\n10909234 9\n10909236 8\n...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
27
codeforces
4563ded09df778b09bd7288d019e0de1
Perfect Permutation
A permutation is a sequence of integers *p*1,<=*p*2,<=...,<=*p**n*, consisting of *n* distinct positive integers, each of them doesn't exceed *n*. Let's denote the *i*-th element of permutation *p* as *p**i*. We'll call number *n* the size of permutation *p*1,<=*p*2,<=...,<=*p**n*. Nickolas adores permutations. He lik...
{"inputs": ["1", "2", "4", "3", "5", "6", "7", "20", "8", "9", "10", "11", "21", "50", "51", "52", "84", "86", "100", "98", "96", "33", "34", "36", "38", "40", "42", "44", "46", "48"], "outputs": ["-1", "2 1 ", "2 1 4 3 ", "-1", "-1", "2 1 4 3 6 5 ", "-1", "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19 ", "2 1 4 3...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
464
codeforces
4588cbcd745d482105ef033b27b0a596
Shaass and Lights
There are *n* lights aligned in a row. These lights are numbered 1 to *n* from left to right. Initially some of the lights are switched on. Shaass wants to switch all the lights on. At each step he can switch a light on (this light should be switched off at that moment) if there's at least one adjacent light which is a...
{"inputs": ["3 1\n1", "4 2\n1 4", "11 2\n4 8", "4 2\n1 3", "4 4\n1 2 3 4", "4 2\n1 3", "4 4\n1 2 3 4", "1000 3\n100 900 10", "74 13\n6 14 19 20 21 24 30 43 58 61 69 70 73", "74 13\n6 14 19 20 21 24 30 43 58 61 69 70 73", "74 13\n6 14 19 20 21 24 30 43 58 61 69 70 73", "74 13\n6 14 19 20 21 24 30 43 58 61 69 70 73", "74...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
20
codeforces
45986d9ec9e10c4ae93d52ad9184357c
Uncowed Forces
Kevin Sun has just finished competing in Codeforces Round #334! The round was 120 minutes long and featured five problems with maximum point values of 500, 1000, 1500, 2000, and 2500, respectively. Despite the challenging tasks, Kevin was uncowed and bulldozed through all of them, distinguishing himself from the herd a...
{"inputs": ["20 40 60 80 100\n0 1 2 3 4\n1 0", "119 119 119 119 119\n0 0 0 0 0\n10 0", "3 6 13 38 60\n6 10 10 3 8\n9 9", "21 44 11 68 75\n6 2 4 8 4\n2 8", "16 112 50 114 68\n1 4 8 4 9\n19 11", "55 66 75 44 47\n6 0 6 6 10\n19 0", "47 11 88 5 110\n6 10 4 2 3\n10 6", "5 44 61 103 92\n9 0 10 4 8\n15 7", "115 53 96 62 110\n...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
213
codeforces
45cdd77b341010af99c45274268020a2
Decoding
Polycarp is mad about coding, that is why he writes Sveta encoded messages. He calls the median letter in a word the letter which is in the middle of the word. If the word's length is even, the median letter is the left of the two middle letters. In the following examples, the median letter is highlighted: contest, inf...
{"inputs": ["5\nlogva", "2\nno", "4\nabba", "51\nkfsmpaeviowvkdbuhdagquxxqniselafnfbrgbhmsugcbbnlrvv", "1\nw", "2\ncb", "3\nqok", "4\naegi", "5\noqquy", "6\nulhpnm", "7\nijvxljt", "8\nwwmiwkeo", "9\ngmwqmpfow", "10\nhncmexsslh", "20\nrtcjbjlbtjfmvzdqutuw", "21\ngjyiqoebcnpsdegxnsauh", "30\nudotcwvcwxajkadxqvxvwgmwmnqrb...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
427
codeforces
45f188f5201885d972fc4e9a0a94d835
Football
One day Vasya decided to have a look at the results of Berland 1910 Football Championship’s finals. Unfortunately he didn't find the overall score of the match; however, he got hold of a profound description of the match's process. On the whole there are *n* lines in that description each of which described one goal. E...
{"inputs": ["1\nABC", "5\nA\nABA\nABA\nA\nA", "2\nXTSJEP\nXTSJEP", "3\nXZYDJAEDZ\nXZYDJAEDZ\nXZYDJAEDZ", "3\nQCCYXL\nQCCYXL\nAXGLFQDD", "3\nAZID\nEERWBC\nEERWBC", "3\nHNCGYL\nHNCGYL\nHNCGYL", "4\nZZWZTG\nZZWZTG\nZZWZTG\nZZWZTG", "4\nA\nA\nKUDLJMXCSE\nA", "5\nPHBTW\nPHBTW\nPHBTW\nPHBTW\nPHBTW", "5\nPKUZYTFYWN\nPKUZYTFYW...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1,490
codeforces
460c08cffe5027fca3f0e2f9dde6d342
Playing Cubes
Petya and Vasya decided to play a little. They found *n* red cubes and *m* blue cubes. The game goes like that: the players take turns to choose a cube of some color (red or blue) and put it in a line from left to right (overall the line will have *n*<=+<=*m* cubes). Petya moves first. Petya's task is to get as many pa...
{"inputs": ["3 1", "2 4", "1 1", "2 1", "4 4", "10 7", "5 13", "7 11", "1 2", "10 10", "50 30", "80 120", "304 122", "500 800", "900 1000", "1 1000", "997 9", "341 678", "784 913", "57 888", "100000 100000", "10000 100000", "9999 99999", "12 100000", "9999 31411", "12930 98391", "98813 893", "99801 38179", "831 69318",...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
124
codeforces
463cccac2b9d40599dd729d945815394
Handshakes
On February, 30th *n* students came in the Center for Training Olympiad Programmers (CTOP) of the Berland State University. They came one by one, one after another. Each of them went in, and before sitting down at his desk, greeted with those who were present in the room by shaking hands. Each of the students who came ...
{"inputs": ["5\n2 1 3 0 1", "9\n0 2 3 4 1 1 0 2 2", "4\n0 2 1 1", "5\n1 0 2 1 0", "1\n0", "5\n3 0 4 1 2", "3\n1 0 0", "7\n3 0 0 4 2 2 1", "10\n1 0 2 3 3 0 4 4 2 5", "7\n2 4 3 5 1 6 0", "10\n6 2 8 1 4 5 7 3 9 3", "5\n2 0 3 1 1", "7\n2 2 3 3 4 0 1", "11\n3 1 1 1 2 2 0 0 2 1 3", "6\n0 1 2 1 2 0", "13\n1 2 0 4 2 1 0 2 0 0 ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
6
codeforces
4640822bd3e4682b578383e2576f98b9
New Year and Entity Enumeration
You are given an integer *m*. Let *M*<==<=2*m*<=-<=1. You are also given a set of *n* integers denoted as the set *T*. The integers will be provided in base 2 as *n* binary strings of length *m*. A set of integers *S* is called "good" if the following hold. 1. If , then . 1. If , then 1. 1. All elements of *...
{"inputs": ["5 3\n11010\n00101\n11000", "30 2\n010101010101010010101010101010\n110110110110110011011011011011", "30 10\n001000000011000111000010010000\n000001100001010000000000000100\n000110100010100000000000101000\n110000010000000001000000000000\n100001000000000010010101000101\n001001000000000100000000110000\n00000001...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
3
codeforces
465ff9110ae1b813c6cf3bc7353b4144
Ultra-Fast Mathematician
Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 1018 numbers in a single second. One day in 230 AD Shapur was trying to find out if any one can possibly do...
{"inputs": ["1010100\n0100101", "000\n111", "1110\n1010", "01110\n01100", "011101\n000001", "10\n01", "00111111\n11011101", "011001100\n101001010", "1100100001\n0110101100", "00011101010\n10010100101", "100000101101\n111010100011", "1000001111010\n1101100110001", "01011111010111\n10001110111010", "110010000111100\n0011...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
3,247
codeforces
46813e083a580aa84a87678a0366f22b
Cipher
Sherlock Holmes found a mysterious correspondence of two VIPs and made up his mind to read it. But there is a problem! The correspondence turned out to be encrypted. The detective tried really hard to decipher the correspondence, but he couldn't understand anything. At last, after some thought, he thought of somethin...
{"inputs": ["1\nab", "1\naaaaaaaaaaa", "2\nya\nklmbfxzb", "1\na", "1\nz", "1\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "1\nmnmnmnmnmnmnmnmnmnmnmnmnmnmnmnmnmnmnmnmnmnmnmnmnmnmnmnmnmnmnmnmnmnmnmnmnmnmnmnmnmnmnmnmnmnmnmnmnmnmn", "15\nejkf\nkc\nu\nznmjnznzn\nbjk...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
6
codeforces
46a482ff61fe6337db5ac40a5cc6f9f2
Blood Cousins Return
Polycarpus got hold of a family tree. The found tree describes the family relations of *n* people, numbered from 1 to *n*. Every person in this tree has at most one direct ancestor. Also, each person in the tree has a name, the names are not necessarily unique. We call the man with a number *a* a 1-ancestor of the man...
{"inputs": ["6\npasha 0\ngerald 1\ngerald 1\nvalera 2\nigor 3\nolesya 1\n5\n1 1\n1 2\n1 3\n3 1\n6 1", "6\nvalera 0\nvalera 1\nvalera 1\ngerald 0\nvalera 4\nkolya 4\n7\n1 1\n1 2\n2 1\n2 2\n4 1\n5 1\n6 1", "1\nc 0\n20\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1", "2...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
3
codeforces
46aca1272ff0ff57506eb619248874fd
Exponential notation
You are given a positive decimal number *x*. Your task is to convert it to the "simple exponential notation". Let *x*<==<=*a*·10*b*, where 1<=≤<=*a*<=&lt;<=10, then in general case the "simple exponential notation" looks like "aEb". If *b* equals to zero, the part "Eb" should be skipped. If *a* is an integer, it shou...
{"inputs": ["16", "01.23400", ".100", "100.", "9000", "0.0012", "0001100", "1", "1.0000", "2206815224318443962208128404511577750057653265995300414539703580103256087275661997018352502651118684", ".642190250125247518637240673193254850619739079359757454472743329719747684651927659872735961709249479", "143529100720960530144...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
30
codeforces
46b59a64a8ffb4422af5f48e844aa3b1
Wet Shark and Bishops
Today, Wet Shark is given *n* bishops on a 1000 by 1000 grid. Both rows and columns of the grid are numbered from 1 to 1000. Rows are numbered from top to bottom, while columns are numbered from left to right. Wet Shark thinks that two bishops attack each other if they share the same diagonal. Note, that this is the o...
{"inputs": ["5\n1 1\n1 5\n3 3\n5 1\n5 5", "3\n1 1\n2 3\n3 5", "3\n859 96\n634 248\n808 72", "3\n987 237\n891 429\n358 145", "3\n411 81\n149 907\n611 114", "3\n539 221\n895 89\n673 890", "3\n259 770\n448 54\n926 667", "3\n387 422\n898 532\n988 636", "10\n515 563\n451 713\n537 709\n343 819\n855 779\n457 60\n650 359\n631 ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
95
codeforces
46b8719c37868c51adb2235f67a51d17
Greed
Jafar has *n* cans of cola. Each can is described by two integers: remaining volume of cola *a**i* and can's capacity *b**i* (*a**i* <=≤<= *b**i*). Jafar has decided to pour all remaining cola into just 2 cans, determine if he can do this or not! The first line of the input contains one integer *n* (2<=≤<=*n*<=≤<=100<...
{"inputs": ["2\n3 5\n3 6", "3\n6 8 9\n6 10 12", "5\n0 0 5 0 0\n1 1 8 10 5", "4\n4 1 0 3\n5 2 2 3", "10\n9 10 24 11 1 7 8 3 28 14\n86 20 34 11 22 94 8 16 73 85", "4\n25 35 7 31\n70 37 43 35", "10\n15 26 15 14 14 39 40 4 25 39\n27 72 16 44 69 48 53 17 63 42", "5\n22 5 19 16 32\n26 10 43 38 37", "5\n32 4 22 40 26\n39 20 3...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
424
codeforces
46cfca38244a5a8772fa79339e7ec2e8
Legacy
Rick and his co-workers have made a new radioactive formula and a lot of bad guys are after them. So Rick wants to give his legacy to Morty before bad guys catch them. There are *n* planets in their universe numbered from 1 to *n*. Rick is in planet number *s* (the earth) and he doesn't know where Morty is. As we all...
{"inputs": ["3 5 1\n2 3 2 3 17\n2 3 2 2 16\n2 2 2 3 3\n3 3 1 1 12\n1 3 3 17", "4 3 1\n3 4 1 3 12\n2 2 3 4 10\n1 2 4 16", "6 1 5\n1 3 6 80612370", "10 8 7\n1 10 7 366692903\n1 4 8 920363557\n2 7 5 10 423509459\n2 2 5 7 431247033\n2 7 3 5 288617239\n2 7 3 3 175870925\n3 9 3 8 651538651\n3 4 2 5 826387883", "1 1 1\n1 1 1 ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1
codeforces
46daac6efffe7aaf48972ca9d1a4c15c
Word Capitalization
Capitalization is writing a word with its first letter as a capital letter. Your task is to capitalize the given word. Note, that during capitalization all the letters except the first one remains unchanged. A single line contains a non-empty word. This word consists of lowercase and uppercase English letters. The len...
{"inputs": ["ApPLe", "konjac", "a", "A", "z", "ABACABA", "xYaPxPxHxGePfGtQySlNrLxSjDtNnTaRaEpAhPaQpWnDzMqGgRgEwJxGiBdZnMtHxFbObCaGiCeZkUqIgBhHtNvAqAlHpMnQhNeQbMyZrCdElVwHtKrPpJjIaHuIlYwHaRkAkUpPlOhNlBtXwDsKzPyHrPiUwNlXtTaPuMwTqYtJySgFoXvLiHbQwMjSvXsQfKhVlOxGdQkWjBhEyQvBjPoFkThNeRhTuIzFjInJtEfPjOlOsJpJuLgLzFnZmKvFgFrNsO...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
767
codeforces
46daf8147d3fdd3c5f879a6c1f5892f2
Petya and His Friends
Little Petya has a birthday soon. Due this wonderful event, Petya's friends decided to give him sweets. The total number of Petya's friends equals to *n*. Let us remind you the definition of the greatest common divisor: *GCD*(*a*1,<=...,<=*a**k*)<==<=*d*, where *d* represents such a maximal positive number that each *...
{"inputs": ["3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "2", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31", "32", "33", "34", "35", "36", "37", "38", "39", "40", "41", "42", "43", "44", "45", "46", "47", "48", "49", "50"], "outputs": ["15\n10\n...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
52
codeforces
46ecb3ceb53efac8fd05e4dde7dbd4d1
String Task
Petya started to attend programming lessons. On the first lesson his task was to write a simple program. The program was supposed to do the following: in the given string, consisting if uppercase and lowercase Latin letters, it: - deletes all the vowels, - inserts a character "." before each consonant, - replaces ...
{"inputs": ["tour", "Codeforces", "aBAcAba", "obn", "wpwl", "ggdvq", "pumesz", "g", "zjuotps", "jzbwuehe", "tnkgwuugu", "kincenvizh", "xattxjenual", "ktajqhpqsvhw", "xnhcigytnqcmy", "jfmtbejyilxcec", "D", "ab", "Ab", "aB", "AB", "ba", "bA", "Ba", "BA", "aab", "baa", "femOZeCArKCpUiHYnbBPTIOFmsHmcpObtPYcLCdjFrUMIyqYzAok...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
643
codeforces
46ff3c92b7b33ba7e270a4dcfa4db14f
An overnight dance in discotheque
The crowdedness of the discotheque would never stop our friends from having fun, but a bit more spaciousness won't hurt, will it? The discotheque can be seen as an infinite *xy*-plane, in which there are a total of *n* dancers. Once someone starts moving around, they will move only inside their own movement range, whi...
{"inputs": ["5\n2 1 6\n0 4 1\n2 -1 3\n1 -2 1\n4 -1 1", "8\n0 0 1\n0 0 2\n0 0 3\n0 0 4\n0 0 5\n0 0 6\n0 0 7\n0 0 8", "4\n1000000 -1000000 2\n1000000 -1000000 3\n-1000000 1000000 2\n-1000000 1000000 1000000", "15\n-848 0 848\n-758 0 758\n-442 0 442\n-372 0 372\n-358 0 358\n-355 0 355\n-325 0 325\n-216 0 216\n-74 0 74\n-1...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
9
codeforces
472992bea3ed7a1eadbb6fdb6f8eb35f
Making Genome in Berland
Berland scientists face a very important task - given the parts of short DNA fragments, restore the dinosaur DNA! The genome of a berland dinosaur has noting in common with the genome that we've used to: it can have 26 distinct nucleotide types, a nucleotide of each type can occur at most once. If we assign distinct En...
{"inputs": ["3\nbcd\nab\ncdef", "4\nx\ny\nz\nw", "25\nef\nfg\ngh\nhi\nij\njk\nkl\nlm\nmn\nno\nab\nbc\ncd\nde\nop\npq\nqr\nrs\nst\ntu\nuv\nvw\nwx\nxy\nyz", "1\nf", "1\nqwertyuiopzxcvbnmasdfghjkl", "3\ndfghj\nghjkl\nasdfg", "4\nab\nab\nab\nabc", "3\nf\nn\nux", "2\nfgs\nfgs", "96\nc\ndhf\no\nq\nry\nh\nr\nf\nji\nek\ndhf\np...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
34
codeforces
475b7be76ae3f929743f3c88553a97fc
Recycling Bottles
It was recycling day in Kekoland. To celebrate it Adil and Bera went to Central Perk where they can take bottles from the ground and put them into a recycling bin. We can think Central Perk as coordinate plane. There are *n* bottles on the ground, the *i*-th bottle is located at position (*x**i*,<=*y**i*). Both Adil a...
{"inputs": ["3 1 1 2 0 0\n3\n1 1\n2 1\n2 3", "5 0 4 2 2 0\n5\n5 2\n3 0\n5 5\n3 5\n3 3", "107 50 116 37 104 118\n12\n16 78\n95 113\n112 84\n5 88\n54 85\n112 80\n19 98\n25 14\n48 76\n95 70\n77 94\n38 32", "446799 395535 281981 494983 755701 57488\n20\n770380 454998\n147325 211816\n818964 223521\n408463 253399\n49120 2537...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
11
codeforces
475dc6ca9903a8d02e194e325948ea5f
Stones on the Table
There are *n* stones on the table in a row, each of them can be red, green or blue. Count the minimum number of stones to take from the table so that any two neighboring stones had different colors. Stones in a row are considered neighboring if there are no other stones between them. The first line contains integer *n*...
{"inputs": ["3\nRRG", "5\nRRRRR", "4\nBRBG", "1\nB", "2\nBG", "3\nBGB", "4\nRBBR", "5\nRGGBG", "10\nGGBRBRGGRB", "50\nGRBGGRBRGRBGGBBBBBGGGBBBBRBRGBRRBRGBBBRBBRRGBGGGRB", "15\nBRRBRGGBBRRRRGR", "20\nRRGBBRBRGRGBBGGRGRRR", "25\nBBGBGRBGGBRRBGRRBGGBBRBRB", "30\nGRGGGBGGRGBGGRGRBGBGBRRRRRRGRB", "35\nGBBGBRGBBGGRBBGBRRGGRR...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
557
codeforces
475fa21447f510f90f4948dce380007d
Choosing Laptop
Vasya is choosing a laptop. The shop has *n* laptops to all tastes. Vasya is interested in the following properties: processor speed, ram and hdd. Vasya is a programmer and not a gamer which is why he is not interested in all other properties. If all three properties of a laptop are strictly less than those propertie...
{"inputs": ["5\n2100 512 150 200\n2000 2048 240 350\n2300 1024 200 320\n2500 2048 80 300\n2000 512 180 150", "2\n1500 500 50 755\n1600 600 80 700", "2\n1500 512 50 567\n1600 400 70 789", "4\n1000 300 5 700\n1100 400 10 600\n1200 500 15 500\n1300 600 20 400", "10\n2123 389 397 747\n2705 3497 413 241\n3640 984 470 250\n3...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
94
codeforces
478f06460e80a324b95824a6a5f2042e
Simple XML
Let's define a string &lt;x&gt; as an opening tag, where *x* is any small letter of the Latin alphabet. Each opening tag matches a closing tag of the type &lt;/x&gt;, where *x* is the same letter. Tegs can be nested into each other: in this case one opening and closing tag pair is located inside another pair. Let's d...
{"inputs": ["<a><b><c></c></b></a>", "<a><b></b><d><c></c></d></a>", "<z></z>", "<u><d></d></u><j></j>", "<a></a><n></n><v><r></r></v><z></z>", "<c><l></l><b><w><f><t><m></m></t></f><w></w></w></b></c>", "<u><d><g><k><m><a><u><j><d></d></j></u></a></m><m></m></k></g></d></u>", "<x><a><l></l></a><g><v></v><d></d></g><z>...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
91
codeforces
479b4867ec26d62324e7d5242bf28120
Jury Marks
Polycarp watched TV-show where *k* jury members one by one rated a participant by adding him a certain number of points (may be negative, i. e. points were subtracted). Initially the participant had some score, and each the marks were one by one added to his score. It is known that the *i*-th jury member gave *a**i* po...
{"inputs": ["4 1\n-5 5 0 20\n10", "2 2\n-2000 -2000\n3998000 4000000", "1 1\n-577\n1273042", "2 1\n614 -1943\n3874445", "3 1\n1416 -1483 1844\n3261895", "5 1\n1035 1861 1388 -622 1252\n2640169", "10 10\n-25 746 298 1602 -1453 -541 -442 1174 976 -1857\n-548062 -548253 -546800 -548943 -548402 -548794 -549236 -548700 -549...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
27
codeforces
479ca5fddac6e338fcb23a04e17b977c
Luba And The Ticket
Luba has a ticket consisting of 6 digits. In one move she can choose digit in any position and replace it with arbitrary digit. She wants to know the minimum number of digits she needs to replace in order to make the ticket lucky. The ticket is considered lucky if the sum of first three digits equals to the sum of las...
{"inputs": ["000000", "123456", "111000", "120111", "999999", "199880", "899889", "899888", "505777", "999000", "989010", "651894", "858022", "103452", "999801", "999990", "697742", "242367", "099999", "198999", "023680", "999911", "000990", "117099", "990999", "000111", "000444", "202597", "000333", "030039", "000009"...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
81
codeforces
479de0715abdea147828ecdaa989f2df
Sereja and Subsequences
Sereja has a sequence that consists of *n* positive integers, *a*1,<=*a*2,<=...,<=*a**n*. First Sereja took a piece of squared paper and wrote all distinct non-empty non-decreasing subsequences of sequence *a*. Then for each sequence written on the squared paper, Sereja wrote on a piece of lines paper all sequences t...
{"inputs": ["1\n42", "3\n1 2 2", "5\n1 2 3 4 5", "4\n11479 29359 26963 24465", "5\n5706 28146 23282 16828 9962", "6\n492 2996 11943 4828 5437 32392", "7\n14605 3903 154 293 12383 17422 18717", "8\n19719 19896 5448 21727 14772 11539 1870 19913", "9\n3 3 2 2 3 2 1 1 2", "10\n3 3 3 2 1 2 3 2 3 1", "42\n8 5 1 10 5 9 9 3 5 ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
2
codeforces
47ee1524fbb3f6faaf6dae5f5894c84b
Painting Pebbles
There are *n* piles of pebbles on the table, the *i*-th pile contains *a**i* pebbles. Your task is to paint each pebble using one of the *k* given colors so that for each color *c* and any two piles *i* and *j* the difference between the number of pebbles of color *c* in pile *i* and number of pebbles of color *c* in p...
{"inputs": ["4 4\n1 2 3 4", "5 2\n3 2 4 1 3", "5 4\n3 2 4 3 5", "4 3\n5 6 7 8", "5 6\n3 7 2 1 2", "9 5\n5 8 7 3 10 1 4 6 3", "2 1\n7 2", "87 99\n90 28 93 18 80 94 68 58 72 45 93 72 11 54 54 48 74 63 73 7 4 54 42 67 8 13 89 32 2 26 13 94 28 46 77 95 94 63 60 7 16 55 90 91 97 80 7 97 8 12 1 32 43 20 79 38 48 22 97 11 92 ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
61
codeforces
47f8f717c6b31e6b2e7253424ace3ed8
Next Test
«Polygon» is a system which allows to create programming tasks in a simple and professional way. When you add a test to the problem, the corresponding form asks you for the test index. As in most cases it is clear which index the next test will have, the system suggests the default value of the index. It is calculated ...
{"inputs": ["1\n1", "2\n2 1", "3\n3 4 1", "4\n6 4 3 5", "5\n3 2 1 7 4", "6\n4 1 2 5 3 7", "7\n3 2 1 6 5 7 4", "8\n2 8 3 7 6 9 1 5", "9\n10 5 9 3 8 7 1 2 4", "10\n7 2 3 8 9 6 5 4 1 10", "1\n1", "2\n1 2", "3\n2 4 1", "4\n4 2 3 1", "5\n3 1 4 2 5", "6\n1 3 6 7 2 4", "7\n1 5 4 7 2 3 6", "8\n12 1 6 5 2 8 3 4", "9\n3 2 7 5 6 ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
318
codeforces
47ff0c9c87017ecba81beeb5b030881e
Mafia
One day *n* friends gathered together to play "Mafia". During each round of the game some player must be the supervisor and other *n*<=-<=1 people take part in the game. For each person we know in how many rounds he wants to be a player, not the supervisor: the *i*-th person wants to play *a**i* rounds. What is the min...
{"inputs": ["3\n3 2 2", "4\n2 2 2 2", "7\n9 7 7 8 8 7 8", "10\n13 12 10 13 13 14 10 10 12 12", "10\n94 96 91 95 99 94 96 92 95 99", "100\n1 555 876 444 262 234 231 598 416 261 206 165 181 988 469 123 602 592 533 97 864 716 831 156 962 341 207 377 892 51 866 96 757 317 832 476 549 472 770 1000 887 145 956 515 992 653 97...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
137
codeforces
4845678942c09d8042afede09d048a1e
Unimodal Array
Array of integers is unimodal, if: - it is strictly increasing in the beginning; - after that it is constant; - after that it is strictly decreasing. The first block (increasing) and the last block (decreasing) may be absent. It is allowed that both of this blocks are absent. For example, the following three arra...
{"inputs": ["6\n1 5 5 5 4 2", "5\n10 20 30 20 10", "4\n1 2 1 2", "7\n3 3 3 3 3 3 3", "6\n5 7 11 11 2 1", "1\n7", "100\n527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 5...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
159
codeforces
48476289549aff4bc826a1d50d25b85c
Block Towers
Students in a class are making towers of blocks. Each student makes a (non-zero) tower by stacking pieces lengthwise on top of each other. *n* of the students use pieces made of two blocks and *m* of the students use pieces made of three blocks. The students don’t want to use too many blocks, but they also want to be ...
{"inputs": ["1 3", "3 2", "5 0", "4 2", "0 1000000", "1000000 1", "1083 724", "1184 868", "1285 877", "820189 548173", "968867 651952", "817544 553980", "813242 543613", "961920 647392", "825496 807050", "974174 827926", "969872 899794", "818549 720669", "967227 894524", "185253 152723", "195173 150801", "129439 98443"...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
42
codeforces
4854574506ddb794691963b9439cc563
Destroying Array
You are given an array consisting of *n* non-negative integers *a*1,<=*a*2,<=...,<=*a**n*. You are going to destroy integers in the array one by one. Thus, you are given the permutation of integers from 1 to *n* defining the order elements of the array are destroyed. After each element is destroyed you have to find o...
{"inputs": ["4\n1 3 2 5\n3 4 1 2", "5\n1 2 3 4 5\n4 2 3 5 1", "8\n5 5 4 4 6 6 5 5\n5 2 8 7 1 3 4 6", "10\n3 3 3 5 6 9 3 1 7 3\n3 4 6 7 5 1 10 9 2 8", "17\n12 9 17 5 0 6 5 1 3 1 17 17 2 14 5 1 17\n3 7 5 8 12 9 15 13 11 14 6 16 17 1 10 2 4", "17\n1 6 9 2 10 5 15 16 17 14 17 3 9 8 12 0 2\n9 13 15 14 16 17 11 10 12 4 6 5 7...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
37
codeforces
488c56b385b3bc0349a543525b06b080
Calendar Reform
Reforms have started in Berland again! At this time, the Parliament is discussing the reform of the calendar. To make the lives of citizens of Berland more varied, it was decided to change the calendar. As more and more people are complaining that "the years fly by...", it was decided that starting from the next year t...
{"inputs": ["25 3", "50 5", "1 1", "1 2", "1 10", "1 5000000", "5000000 5000000", "4000000 5000000", "3000000 5000000", "1000000 5000000", "1 10000000"], "outputs": ["30", "125", "1", "3", "38", "8224640917276", "24674231279431", "21384022194564", "18094224526592", "11514506860120", "32898872196712"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
4
codeforces
48b421286a3242f5c7b4c7f7ae6e7623
Bear and Prime Numbers
Recently, the bear started studying data structures and faced the following problem. You are given a sequence of integers *x*1,<=*x*2,<=...,<=*x**n* of length *n* and *m* queries, each of them is characterized by two integers *l**i*,<=*r**i*. Let's introduce *f*(*p*) to represent the number of such indexes *k*, that *...
{"inputs": ["6\n5 5 7 10 14 15\n3\n2 11\n3 12\n4 4", "7\n2 3 5 7 11 4 8\n2\n8 10\n2 123", "9\n50 50 50 50 50 50 50 50 50\n7\n20 20\n8 13\n13 13\n6 14\n3 5\n15 17\n341 1792", "1\n6\n1\n2 3", "1\n10000000\n1\n2000000000 2000000000", "12\n2 4 8 16 32 64 128 256 512 1024 2048 4096\n14\n2 2\n2 2000000000\n4 4\n8 8\n16 16\n3...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
13
codeforces
48b50de9de6967190c06c4926651aaaa
Pythagorean Theorem II
In mathematics, the Pythagorean theorem — is a relation in Euclidean geometry among the three sides of a right-angled triangle. In terms of areas, it states: In any right-angled triangle, the area of the square whose side is the hypotenuse (the side opposite the right angle) is equal to the sum of the areas of the s...
{"inputs": ["5", "74", "1000", "586", "2", "362", "778", "194", "906", "659", "75", "787", "851", "563", "979", "395", "755", "171", "883", "400", "817", "177", "593", "305", "721", "785", "497", "913", "625", "334", "10000", "9999"], "outputs": ["1", "35", "881", "472", "0", "258", "653", "120", "786", "535", "37", "6...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
97
codeforces