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
cc9dd4e6b5f4255387e96f4f9d873077
Alphabetic Removals
You are given a string $s$ consisting of $n$ lowercase Latin letters. Polycarp wants to remove exactly $k$ characters ($k \le n$) from the string $s$. Polycarp uses the following algorithm $k$ times: - if there is at least one letter 'a', remove the leftmost occurrence and stop the algorithm, otherwise go to next ite...
{"inputs": ["15 3\ncccaabababaccbc", "15 9\ncccaabababaccbc", "5 2\nzyzyx", "4 3\nhack", "4 3\nzzzz", "6 5\naaccdd", "2 1\nzz", "14 5\nhxehmvkybeklnj"], "outputs": ["cccbbabaccbc", "cccccc", "zzy", "k", "z", "d", "z", "xmvkyklnj"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
98
codeforces
cca086aaaaa8acaf7ee3d71ae7350ac6
none
Disclaimer: there are lots of untranslateable puns in the Russian version of the statement, so there is one more reason for you to learn Russian :) Rick and Morty like to go to the ridge High Cry for crying loudly — there is an extraordinary echo. Recently they discovered an interesting acoustic characteristic of this...
{"inputs": ["5\n3 2 1 6 5", "4\n3 3 3 3", "1\n0", "1\n1", "1\n1000000000", "1\n6", "228\n1 3 1 7 1 3 1 15 1 3 1 7 1 3 1 31 1 3 1 7 1 3 1 15 1 3 1 7 1 3 1 63 1 3 1 7 1 3 1 15 1 3 1 7 1 3 1 31 1 3 1 7 1 3 1 15 1 3 1 7 1 3 1 127 1 3 1 7 1 3 1 15 1 3 1 7 1 3 1 31 1 3 1 7 1 3 1 15 1 3 1 7 1 3 1 63 1 3 1 7 1 3 1 15 1 3 1 7 1...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
4
codeforces
ccab9113e4676fc4e63aefdba473c54e
Non-Secret Cypher
Berland starts to seize the initiative on the war with Flatland. To drive the enemy from their native land, the berlanders need to know exactly how many more flatland soldiers are left in the enemy's reserve. Fortunately, the scouts captured an enemy in the morning, who had a secret encrypted message with the informati...
{"inputs": ["4 2\n1 2 1 2", "5 3\n1 2 1 1 3", "3 1\n1 1 1", "20 2\n6 7 2 4 6 8 4 3 10 5 3 5 7 9 1 2 8 1 9 10", "63 2\n1 2 1 2 4 5 1 1 1 1 1 2 3 1 2 3 3 1 1 3 1 1 1 1 2 1 1 6 3 2 1 1 1 1 2 2 3 2 1 1 1 2 1 4 2 1 2 3 2 1 1 1 1 2 4 3 4 2 5 1 1 2 1", "63 5\n76826 79919 83599 93821 79919 46132 46132 46132 79919 76826 79919 7...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
43
codeforces
ccb33a039bf5e61811f4bf46ba0c1b6c
Powers of Two
You are given *n* integers *a*1,<=*a*2,<=...,<=*a**n*. Find the number of pairs of indexes *i*,<=*j* (*i*<=&lt;<=*j*) that *a**i*<=+<=*a**j* is a power of 2 (i. e. some integer *x* exists so that *a**i*<=+<=*a**j*<==<=2*x*). The first line contains the single positive integer *n* (1<=≤<=*n*<=≤<=105) — the number of int...
{"inputs": ["4\n7 3 2 1", "3\n1 1 1", "1\n1000000000", "10\n2827343 1373647 96204862 723505 796619138 71550121 799843967 5561265 402690754 446173607", "10\n6 6 7 3 9 14 15 7 2 2", "100\n3 6 12 1 16 4 9 5 4 4 5 8 12 4 6 14 5 1 2 2 2 1 7 1 9 10 6 13 7 8 3 11 8 11 7 5 15 6 14 10 4 2 10 9 1 8 14 9 5 11 3 4 1 12 6 8 13 4 8 ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
26
codeforces
cceb3418316a02ad44067bef5d4dfbc8
Olympiad
The recent All-Berland Olympiad in Informatics featured *n* participants with each scoring a certain amount of points. As the head of the programming committee, you are to determine the set of participants to be awarded with diplomas with respect to the following criteria: - At least one participant should get a di...
{"inputs": ["4\n1 3 3 2", "3\n1 1 1", "4\n42 0 0 42", "10\n1 0 1 0 1 0 0 0 0 1", "10\n572 471 540 163 50 30 561 510 43 200", "100\n122 575 426 445 172 81 247 429 97 202 175 325 382 384 417 356 132 502 328 537 57 339 518 211 479 306 140 168 268 16 140 263 593 249 391 310 555 468 231 180 157 18 334 328 276 155 21 280 322...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
763
codeforces
ccf90e94056e7f71bca90c97428d0854
DZY Loves Chessboard
DZY loves chessboard, and he enjoys playing with it. He has a chessboard of *n* rows and *m* columns. Some cells of the chessboard are bad, others are good. For every good cell, DZY wants to put a chessman on it. Each chessman is either white or black. After putting all chessmen, DZY wants that no two chessmen with th...
{"inputs": ["1 1\n.", "2 2\n..\n..", "3 3\n.-.\n---\n--.", "3 1\n-\n.\n.", "11 11\n-----------\n-----------\n-----------\n-----------\n-----------\n-----------\n-----------\n-----------\n-----------\n-----------\n-----------", "1 1\n-", "4 2\n..\n..\n..\n..", "5 1\n.\n.\n.\n.\n."], "outputs": ["B", "BW\nWB", "B-B\n---\...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
323
codeforces
ccfde368ce481926b7fe8da6a5a19d86
Maxim and Matrix
Maxim loves to fill in a matrix in a special manner. Here is a pseudocode of filling in a matrix of size (*m*<=+<=1)<=×<=(*m*<=+<=1): Maxim asks you to count, how many numbers *m* (1<=≤<=*m*<=≤<=*n*) are there, such that the sum of values in the cells in the row number *m*<=+<=1 of the resulting matrix equals *t*. ...
{"inputs": ["1 1", "3 2", "3 3", "1000000000000 1048576", "35 4", "70 32", "79 32", "63 16", "6 4", "82 16", "4890852 16", "473038165 2", "326051437 4", "170427799 16", "168544291 8", "82426873 1", "175456797 16384", "257655784 16384", "9581849 1024", "8670529 16384", "621597009 268435456", "163985731 33554432", "75864...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
2
codeforces
cd1341a74edf0fecdcc915ce6739938a
Well-known Numbers
Numbers *k*-bonacci (*k* is integer, *k*<=&gt;<=1) are a generalization of Fibonacci numbers and are determined as follows: - *F*(*k*,<=*n*)<==<=0, for integer *n*, 1<=≤<=*n*<=&lt;<=*k*; - *F*(*k*,<=*k*)<==<=1; - *F*(*k*,<=*n*)<==<=*F*(*k*,<=*n*<=-<=1)<=+<=*F*(*k*,<=*n*<=-<=2)<=+<=...<=+<=*F*(*k*,<=*n*<=-<=*k*), fo...
{"inputs": ["5 2", "21 5", "1 1000", "1000000000 1000000000", "122 7", "4 3", "321123 3211232", "1 2", "2 2", "3 2", "8 2", "17 2", "137 2", "7298 2", "76754 2", "12345678 2", "987654321 2", "1000000000 2", "701408733 2", "1 3", "2 3", "3 3", "100 3", "87783 3", "615693473 3", "615693474 3", "1000000000 3", "1 4", "2 4...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
19
codeforces
cd3089bf322bec62b4b20e5acd4e4a51
Little Robber Girl's Zoo
Little Robber Girl likes to scare animals in her zoo for fun. She decided to arrange the animals in a row in the order of non-decreasing height. However, the animals were so scared that they couldn't stay in the right places. The robber girl was angry at first, but then she decided to arrange the animals herself. She ...
{"inputs": ["4\n2 1 4 3", "7\n36 28 57 39 66 69 68", "5\n1 2 1 2 1", "78\n7 3 8 8 9 8 10 9 12 11 16 14 17 17 18 18 20 20 25 22 27 26 29 27 35 35 36 36 37 37 38 38 40 39 42 42 48 46 49 49 58 50 60 58 65 61 68 66 69 69 69 69 70 69 71 71 77 73 78 77 80 79 85 83 86 86 86 86 88 87 91 90 96 91 98 97 99 98", "99\n5 5 5 5 5 5 ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
26
codeforces
cd3bf5d29eadbcf458616c8f199d7895
Borya and Hanabi
Have you ever played Hanabi? If not, then you've got to try it out! This problem deals with a simplified version of the game. Overall, the game has 25 types of cards (5 distinct colors and 5 distinct values). Borya is holding *n* cards. The game is somewhat complicated by the fact that everybody sees Borya's cards exc...
{"inputs": ["2\nG3 G3", "4\nG4 R4 R3 B3", "5\nB1 Y1 W1 G1 R1", "10\nY4 B1 R3 G5 R5 W3 W5 W2 R1 Y1", "3\nG4 G3 B4", "2\nW3 Y5", "2\nW5 Y5", "100\nW4 Y1 W5 R4 W3 Y1 R4 W2 G3 G1 B5 Y5 Y2 Y3 G4 B5 W1 G5 Y5 Y3 G2 Y5 Y5 G5 R2 B3 B1 W5 Y1 W5 B4 W4 R4 B1 R1 W3 R5 R4 G2 W3 W3 R2 W5 Y2 B2 R3 R3 Y1 G5 G2 Y1 R4 Y5 W5 G5 B3 W2 R1 B...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
13
codeforces
cd8569e989f67f116902d5f72934bb5a
Remainders Game
Today Pari and Arya are playing a game called Remainders. Pari chooses two positive integer *x* and *k*, and tells Arya *k* but not *x*. Arya have to find the value . There are *n* ancient numbers *c*1,<=*c*2,<=...,<=*c**n* and Pari has to tell Arya if Arya wants. Given *k* and the ancient values, tell us if Arya has...
{"inputs": ["4 5\n2 3 5 12", "2 7\n2 3", "1 6\n8", "2 3\n9 4", "4 16\n19 16 13 9", "5 10\n5 16 19 9 17", "11 95\n31 49 8 139 169 121 71 17 43 29 125", "17 71\n173 43 139 73 169 199 49 81 11 89 131 107 23 29 125 152 17", "13 86\n41 64 17 31 13 97 19 25 81 47 61 37 71", "15 91\n49 121 83 67 128 125 27 113 41 169 149 19 3...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
26
codeforces
cdab43ee10fbd94cbd611a337801b847
Mahmoud and Ehab and the MEX
Dr. Evil kidnapped Mahmoud and Ehab in the evil land because of their performance in the Evil Olympiad in Informatics (EOI). He decided to give them some problems to let them go. Dr. Evil is interested in sets, He has a set of *n* integers. Dr. Evil calls a set of integers evil if the MEX of it is exactly *x*. the MEX...
{"inputs": ["5 3\n0 4 5 6 7", "1 0\n0", "5 0\n1 2 3 4 5", "10 5\n57 1 47 9 93 37 76 70 78 15", "10 5\n99 98 93 97 95 100 92 94 91 96", "10 5\n1 2 3 4 59 45 0 58 51 91", "100 100\n79 13 21 11 3 87 28 40 29 4 96 34 8 78 61 46 33 45 99 30 92 67 22 97 39 86 73 31 74 44 62 55 57 2 54 63 80 69 25 48 77 98 17 93 15 16 89 12 4...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
160
codeforces
cdd53a40de34107ec869a299815ab410
Embassy Queue
In an embassy of a well-known kingdom an electronic queue is organised. Every person who comes to the embassy, needs to make the following three actions: show the ID, pay money to the cashier and be fingerprinted. Besides, the actions should be performed in the given order. For each action several separate windows are...
{"inputs": ["1 1 1\n1 1 1\n5\n1 1 1 1 1", "2 1 1\n5 1 1\n5\n1 2 3 3 5", "1 1 1\n1 1 1\n5\n1 2 3 4 5", "1 1 1\n1 1 1\n5\n1 2 3 3 4", "9 5 6\n8 2 2\n1\n5", "2 7 3\n8 10 5\n5\n5 6 7 8 9", "3 9 10\n3 10 4\n5\n2 2 2 2 2", "2 7 1\n10 3 10\n100\n3 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 3...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
3
codeforces
ce078bca9cb34927fa29762b3a352266
Fraction
Petya is a big fan of mathematics, especially its part related to fractions. Recently he learned that a fraction is called proper iff its numerator is smaller than its denominator (*a*<=&lt;<=*b*) and that the fraction is called irreducible if its numerator and its denominator are coprime (they do not have positive co...
{"inputs": ["3", "4", "12", "34", "13", "11", "24", "17", "10", "69", "100", "57", "1000", "999", "998", "997", "996", "995", "994", "5", "6", "8", "9", "423", "876", "29"], "outputs": ["1 2", "1 3", "5 7", "15 19", "6 7", "5 6", "11 13", "8 9", "3 7", "34 35", "49 51", "28 29", "499 501", "499 500", "497 501", "498 49...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
325
codeforces
ce18d7053c8a3377aad3bca251aa0bc6
Event Dates
On a history lesson the teacher asked Vasya to name the dates when *n* famous events took place. He doesn't remembers the exact dates but he remembers a segment of days [*l**i*,<=*r**i*] (inclusive) on which the event could have taken place. However Vasya also remembers that there was at most one event in one day. Help...
{"inputs": ["3\n1 2\n2 3\n3 4", "2\n1 3\n1 3", "10\n1 10\n3 4\n8 10\n3 4\n5 9\n1 4\n7 10\n1 9\n1 8\n4 10", "10\n1 1\n8 10\n1 7\n6 8\n5 7\n1 9\n8 8\n6 10\n1 4\n3 4", "10\n1 2\n1 3\n1 9\n10 10\n4 4\n5 9\n2 5\n7 8\n2 10\n7 10", "10\n4 12\n2 8\n1 12\n6 8\n4 6\n12 12\n3 10\n1 10\n3 3\n1 10", "10\n6 7\n5 11\n5 10\n9 10\n11 1...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
13
codeforces
ce33750da56e1793b724225fd29caf3f
Diversity
Calculate the minimum number of characters you need to change in the string *s*, so that it contains at least *k* different letters, or print that it is impossible. String *s* consists only of lowercase Latin letters, and it is allowed to change characters only to lowercase Latin letters too. First line of input conta...
{"inputs": ["yandex\n6", "yahoo\n5", "google\n7", "a\n1", "z\n2", "fwgfrwgkuwghfiruhewgirueguhergiqrbvgrgf\n26", "nfevghreuoghrueighoqghbnebvnejbvnbgneluqe\n26", "a\n3", "smaxpqplaqqbxuqxalqmbmmgubbpspxhawbxsuqhhegpmmpebqmqpbbeplwaepxmsahuepuhuhwxeqmmlgqubuaxehwuwasgxpqmugbmuawuhwqlswllssueglbxepbmwgs\n1", "cuguccgcugc...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
236
codeforces
ce3c021d36b6ba21396a789329d9a43d
Prime Matrix
You've got an *n*<=×<=*m* matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase it by 1. Each element can be increased an arbitrary number of times. You are really curious about prime numbers. Let us remind you ...
{"inputs": ["3 3\n1 2 3\n5 6 1\n4 4 1", "2 3\n4 8 8\n9 2 9", "2 2\n1 3\n4 2", "1 1\n14", "5 3\n2 14 8\n8 8 2\n8 10 10\n1 2 1\n100 100 8", "6 5\n8 8 8 8 20\n13 8 16 13 9\n11 5 3 14 18\n13 8 6 18 6\n6 8 9 14 7\n2 14 14 9 3", "5 7\n9 5 3 9 2 8 2\n15 7 9 8 18 4 6\n2 9 14 3 6 13 18\n4 13 3 14 11 13 8\n14 10 1 14 18 5 6", "3...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
7
codeforces
ce51e9e2bf9e9d028f33636c885eb53c
Black Square
Quite recently, a very smart student named Jury decided that lectures are boring, so he downloaded a game called "Black Square" on his super cool touchscreen phone. In this game, the phone's screen is divided into four vertical strips. Each second, a black square appears on some of the strips. According to the rules o...
{"inputs": ["1 2 3 4\n123214", "1 5 3 2\n11221", "5 5 5 1\n3422", "4 3 2 1\n2", "5651 6882 6954 4733\n2442313421", "0 0 0 0\n4132", "3163 5778 83 7640\n11141442444", "1809 1302 7164 6122\n3144121413113111223311232232114144321414421243443243422322144324121433444342231344234443332241322442", "0 0 0 0\n1", "1 2 3 4\n4", "...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1,034
codeforces
ceae7eedfe1a4cc59e25f381a4377cac
Famil Door and Roads
Famil Door’s City map looks like a tree (undirected connected acyclic graph) so other people call it Treeland. There are *n* intersections in the city connected by *n*<=-<=1 bidirectional roads. There are *m* friends of Famil Door living in the city. The *i*-th friend lives at the intersection *u**i* and works at the ...
{"inputs": ["4 3\n2 4\n4 1\n3 2\n3 1\n2 3\n4 1", "3 3\n1 2\n1 3\n1 2\n1 3\n2 3", "10 5\n8 10\n3 6\n7 3\n7 4\n8 9\n9 4\n5 1\n10 5\n6 2\n9 1\n7 6\n5 1\n6 9\n10 2"], "outputs": ["4.00000000\n3.00000000\n3.00000000", "2.50000000\n2.50000000\n3.00000000", "7.50000000\n6.50000000\n6.00000000\n7.50000000\n9.00000000"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1
codeforces
cedb194ead074bf927d95693dde3edb3
none
Edo has got a collection of *n* refrigerator magnets! He decided to buy a refrigerator and hang the magnets on the door. The shop can make the refrigerator with any size of the door that meets the following restrictions: the refrigerator door must be rectangle, and both the length and the width of the door must be pos...
{"inputs": ["3 1\n1 1 2 2\n2 2 3 3\n3 3 4 4", "4 1\n1 1 2 2\n1 9 2 10\n9 9 10 10\n9 1 10 2", "3 0\n1 1 2 2\n1 1 1000000000 1000000000\n1 3 8 12", "11 8\n9 1 11 5\n2 2 8 12\n3 8 23 10\n2 1 10 5\n7 1 19 5\n1 8 3 10\n1 5 3 9\n1 2 3 4\n1 2 3 4\n4 2 12 16\n8 5 12 9", "20 5\n1 12 21 22\n9 10 15 20\n10 12 12 20\n1 1 25 29\n5 ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
2
codeforces
cee4791929f0bd6034bfc5e68fc4deda
Vanya and Label
While walking down the street Vanya saw a label "Hide&amp;Seek". Because he is a programmer, he used &amp; as a bitwise AND for these two words represented as a integers in base 64 and got new word. Now Vanya thinks of some string *s* and wants to know the number of pairs of words of length |*s*| (length of *s*), such ...
{"inputs": ["z", "V_V", "Codeforces", "zHsIINYjVtU71kmM9E", "fRRNAdMvLFTX21T0FG5gyn7NG0SaIvzGG_g_SO", "Lb1T3sA4BcTx4KAgLIsl-dNOGDvimpxZOxJfMz6VC3nQkB3Y780qqX_1dnjjb59H9X", "2kdYy5-G2-TL5dtLRKcp0ScPGQMrEjwsXuxJHZb4EOd7g7NSQYiAuX2O40PKVyMGEQ1WzW6TvQqbrM1O6e3TdduRsk", "kuCerLoRuMSm6wa_YM", "_", "0123456789ABCDEFGHIJKLMNOP...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
3
codeforces
ceedf38faa444936a913b20e9cd7d9c4
Connected Components
We already know of the large corporation where Polycarpus works as a system administrator. The computer network there consists of *n* computers and *m* cables that connect some pairs of computers. In other words, the computer network can be represented as some non-directed graph with *n* nodes and *m* edges. Let's inde...
{"inputs": ["6 5\n1 2\n5 4\n2 3\n3 1\n3 6\n6\n1 3\n2 5\n1 5\n5 5\n2 4\n3 3", "2 1\n2 1\n2\n1 1\n1 1", "3 2\n3 2\n3 1\n4\n1 1\n1 2\n2 2\n2 2", "3 3\n2 3\n3 1\n2 1\n5\n2 3\n3 3\n2 2\n2 2\n2 2", "4 5\n1 4\n2 1\n4 3\n2 1\n3 4\n5\n4 5\n2 4\n4 4\n1 3\n4 4", "5 4\n3 2\n5 2\n5 3\n2 3\n8\n4 4\n1 1\n3 4\n1 1\n3 3\n3 4\n3 4\n4 4"...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
2
codeforces
cefd9888a7d526cca46b7a86b3deefbb
Hot Days
The official capital and the cultural capital of Berland are connected by a single road running through *n* regions. Each region has a unique climate, so the *i*-th (1<=≤<=*i*<=≤<=*n*) region has a stable temperature of *t**i* degrees in summer. This summer a group of *m* schoolchildren wants to get from the official ...
{"inputs": ["2 10\n30 35 1 100\n20 35 10 10", "3 100\n10 30 1000 1\n5 10 1000 3\n10 40 1000 100000", "10 1\n8 6 3 4\n9 10 7 7\n1 3 9 5\n10 9 4 2\n1 10 2 10\n1 1 8 5\n5 5 9 2\n5 8 4 3\n4 4 9 7\n5 7 5 10", "5 5\n100 29 49 77\n34 74 41 8\n32 21 24 91\n45 52 16 51\n50 87 90 94", "1 1000000\n4 4 6 2", "20 102\n73 79 75 27\n...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
2
codeforces
cf1cc557666d64e45d88d252152147db
Restore Graph
Valera had an undirected connected graph without self-loops and multiple edges consisting of *n* vertices. The graph had an interesting property: there were at most *k* edges adjacent to each of its vertices. For convenience, we will assume that the graph vertices were indexed by integers from 1 to *n*. One day Valera...
{"inputs": ["3 2\n0 1 1", "4 2\n2 0 1 3", "3 1\n0 0 0", "5 3\n0 2 1 2 1", "7 3\n2 2 0 1 3 2 1", "9 4\n2 1 1 3 1 2 2 1 0", "3 1\n0 1 2", "2 1\n1 0", "2 1\n1 1", "2 1\n0 0", "4 2\n0 1 0 1", "5 3\n3 1 4 2 1", "5 4\n1 2 2 2 3", "4 3\n1 1 1 2", "4 3\n1 2 2 3", "4 3\n1 2 3 3", "7 6\n1 1 2 2 3 3 3", "10 5\n0 1 1 1 1 1 1 2 2 2...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
7
codeforces
cf438485b6500f7040d2da54b017d318
The Queue
Finally! Vasya have come of age and that means he can finally get a passport! To do it, he needs to visit the passport office, but it's not that simple. There's only one receptionist at the passport office and people can queue up long before it actually opens. Vasya wants to visit the passport office tomorrow. He know...
{"inputs": ["10 15 2\n2\n10 13", "8 17 3\n4\n3 4 5 8", "7 14 3\n2\n1 2", "30 70 10\n3\n30 32 35", "21 56 7\n5\n1 2 3 4 5", "10 1000000000 25\n20\n1 1 5 7 8 10 12 22 44 47 73 77 82 83 89 141 142 168 195 199", "30 60 3\n10\n1 5 6 10 12 13 18 23 24 25", "61 1000000000 13\n55\n29 72 85 94 103 123 125 144 147 153 154 184 18...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
4
codeforces
cf4da4092ec76b45e3e4ddde8e8a0056
Infinite Sequence
Vasya likes everything infinite. Now he is studying the properties of a sequence *s*, such that its first element is equal to *a* (*s*1<==<=*a*), and the difference between any two neighbouring elements is equal to *c* (*s**i*<=-<=*s**i*<=-<=1<==<=*c*). In particular, Vasya wonders if his favourite integer *b* appears ...
{"inputs": ["1 7 3", "10 10 0", "1 -4 5", "0 60 50", "1 -4 -5", "0 1 0", "10 10 42", "-1000000000 1000000000 -1", "10 16 4", "-1000000000 1000000000 5", "1000000000 -1000000000 5", "1000000000 -1000000000 0", "1000000000 1000000000 0", "115078364 -899474523 -1", "-245436499 416383245 992", "-719636354 536952440 2", "-1...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
136
codeforces
cf4fdddf06155690a7e8cf32013d2821
Set of Points
Convexity of a set of points on the plane is the size of the largest subset of points that form a convex polygon. Your task is to build a set of *n* points with the convexity of exactly *m*. Your set of points should not contain three points that lie on a straight line. The single line contains two integers *n* and *m*...
{"inputs": ["4 3", "6 3", "6 6", "7 4", "3 3", "5 3", "4 4", "5 4", "6 4", "8 4", "8 6", "10 5", "5 5", "10 6", "11 7", "16 8", "9 5", "200 100", "199 100", "198 100", "102 100", "101 100", "100 100", "198 99", "197 99", "100 99", "99 99", "50 37", "150 100", "181 95", "100 50", "101 99", "6 5", "7 5", "8 5", "43 24", ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1
codeforces
cf61c7272e1736a69a692641b0e542a9
Okabe and Future Gadget Laboratory
Okabe needs to renovate the Future Gadget Laboratory after he tried doing some crazy experiments! The lab is represented as an *n* by *n* square grid of integers. A good lab is defined as a lab in which every number not equal to 1 can be expressed as the sum of a number in the same row and a number in the same column. ...
{"inputs": ["3\n1 1 2\n2 3 1\n6 4 1", "3\n1 5 2\n1 1 1\n1 2 3", "1\n1", "4\n1 1 1 1\n1 11 1 2\n2 5 1 4\n3 9 4 1", "4\n1 1 1 1\n1 7 1 1\n1 3 1 2\n2 6 3 1", "4\n1 1 1 1\n1 12 1 2\n4 4 1 3\n5 10 6 1", "4\n1 1 1 1\n1 13 1 2\n4 5 1 3\n5 11 6 1", "4\n1 1 1 1\n1 13 1 2\n4 5 1 3\n7 11 6 1", "4\n1 1 1 1\n1 14 1 6\n4 5 1 5\n3 8 ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
171
codeforces
cf630697f1a656cbd30ea39d80be45d2
Orchestra
Paul is at the orchestra. The string section is arranged in an *r*<=×<=*c* rectangular grid and is filled with violinists with the exception of *n* violists. Paul really likes violas, so he would like to take a picture including at least *k* of them. Paul can take a picture of any axis-parallel rectangle in the orchest...
{"inputs": ["2 2 1 1\n1 2", "3 2 3 3\n1 1\n3 1\n2 2", "3 2 3 2\n1 1\n3 1\n2 2", "1 1 1 1\n1 1", "10 10 10 10\n6 1\n3 8\n10 6\n10 3\n10 4\n8 9\n2 3\n5 7\n5 9\n5 1", "10 10 10 1\n8 2\n9 10\n6 8\n10 7\n1 8\n4 4\n6 3\n2 3\n8 8\n7 2", "5 9 2 2\n4 6\n1 5", "6 4 10 2\n2 3\n2 1\n1 2\n6 1\n1 4\n4 4\n2 4\n1 1\n6 3\n4 2", "8 2 4 ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
54
codeforces
cf6b0edd29a966dde1de8aa4a4467b6b
Mike and Geometry Problem
Mike wants to prepare for IMO but he doesn't know geometry, so his teacher gave him an interesting geometry problem. Let's define *f*([*l*,<=*r*])<==<=*r*<=-<=*l*<=+<=1 to be the number of integer points in the segment [*l*,<=*r*] with *l*<=≤<=*r* (say that ). You are given two integers *n* and *k* and *n* closed inter...
{"inputs": ["3 2\n1 2\n1 3\n2 3", "3 3\n1 3\n1 3\n1 3", "3 1\n1 2\n2 3\n3 4", "1 1\n45 70", "1 1\n-35 -8", "1 1\n-79 -51", "2 2\n26 99\n-56 40", "9 6\n-44 -29\n-11 85\n11 84\n-63 1\n75 89\n-37 61\n14 73\n78 88\n-22 -18", "2 2\n-93 -22\n12 72"], "outputs": ["5", "3", "6", "26", "28", "29", "15", "0", "0"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
4
codeforces
cf86a8bbd6a48bb925bc9ed62354e875
World Cup
The last stage of Football World Cup is played using the play-off system. There are *n* teams left in this stage, they are enumerated from 1 to *n*. Several rounds are held, in each round the remaining teams are sorted in the order of their ids, then the first in this order plays with the second, the third — with the ...
{"inputs": ["4 1 2", "8 2 6", "8 7 5", "128 30 98", "256 128 256", "256 2 127", "2 1 2", "2 2 1", "4 1 3", "4 1 4", "4 2 1", "4 2 3", "4 2 4", "4 3 1", "4 3 2", "4 3 4", "4 4 1", "4 4 2", "4 4 3", "8 8 7", "8 8 5", "8 8 1", "16 4 3", "16 2 4", "16 14 11", "16 3 11", "32 10 9", "32 25 28", "32 22 18", "32 17 25", "32 18...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
173
codeforces
cf9bfbf389d9d8bdc2c282638d92b467
Dasha and Very Difficult Problem
Dasha logged into the system and began to solve problems. One of them is as follows: Given two sequences *a* and *b* of length *n* each you need to write a sequence *c* of length *n*, the *i*-th element of which is calculated as follows: *c**i*<==<=*b**i*<=-<=*a**i*. About sequences *a* and *b* we know that their ele...
{"inputs": ["5 1 5\n1 1 1 1 1\n3 1 5 4 2", "4 2 9\n3 4 8 9\n3 2 1 4", "6 1 5\n1 1 1 1 1 1\n2 3 5 4 1 6", "5 1 7\n1 4 4 6 5\n5 2 1 4 3", "5 10 100\n12 14 15 11 13\n4 2 1 5 3", "2 1 1000000000\n1000000000 1\n2 1", "2 1 1000000000\n1000000000 1\n1 2", "5 1 5\n1 1 1 1 1\n1 2 3 4 5", "5 1 5\n1 1 1 1 1\n2 3 1 5 4", "1 100000...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
24
codeforces
cfa14502e4800d652733f9b4ec565760
Permutation
"Hey, it's homework time" — thought Polycarpus and of course he started with his favourite subject, IT. Polycarpus managed to solve all tasks but for the last one in 20 minutes. However, as he failed to solve the last task after some considerable time, the boy asked you to help him. The sequence of *n* integers is cal...
{"inputs": ["3\n3 1 2", "2\n2 2", "5\n5 3 3 3 1", "5\n6 6 6 6 6", "10\n1 1 2 2 8 8 7 7 9 9", "8\n9 8 7 6 5 4 3 2", "15\n1 2 3 4 5 5 4 3 2 1 1 2 3 4 5", "1\n1", "1\n5000", "4\n5000 5000 5000 5000", "5\n3366 3461 4 5 4370", "10\n8 2 10 3 4 6 1 7 9 5", "10\n551 3192 3213 2846 3068 1224 3447 1 10 9", "15\n4 1459 12 4281 32...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
245
codeforces
d0040d13ef457ac6407a514ec877584c
Arpa's loud Owf and Mehrdad's evil plan
As you have noticed, there are lovely girls in Arpa’s land. People in Arpa's land are numbered from 1 to *n*. Everyone has exactly one crush, *i*-th person's crush is person with the number *crush**i*. Someday Arpa shouted Owf loudly from the top of the palace and a funny game started in Arpa's land. The rules are as...
{"inputs": ["4\n2 3 1 4", "4\n4 4 4 4", "4\n2 1 4 3", "5\n2 4 3 1 2", "5\n2 2 4 4 5", "5\n2 4 5 4 2", "10\n8 10 4 3 2 1 9 6 5 7", "10\n10 1 4 8 5 2 3 7 9 6", "10\n6 4 3 9 5 2 1 10 8 7", "100\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...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
29
codeforces
d01820987d411523356abffd769f2c7f
Vasily the Bear and Triangle
Vasily the bear has a favorite rectangle, it has one vertex at point (0,<=0), and the opposite vertex at point (*x*,<=*y*). Of course, the sides of Vasya's favorite rectangle are parallel to the coordinate axes. Vasya also loves triangles, if the triangles have one vertex at point *B*<==<=(0,<=0). That's why today he...
{"inputs": ["10 5", "-10 5", "20 -10", "-10 -1000000000", "-1000000000 -1000000000", "1000000000 1000000000", "-123131 3123141", "-23423 -243242423", "123112 4560954", "1321 -23131", "1000000000 999999999", "54543 432423", "1 1", "-1 -1", "-1 1", "1 -1", "42 -2", "2 -435", "76 -76", "1000000000 1", "1000000000 -1", "-1...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
183
codeforces
d02c5691f75073b585c6a0d403fb8188
Martian Dollar
One day Vasya got hold of information on the Martian dollar course in bourles for the next *n* days. The buying prices and the selling prices for one dollar on day *i* are the same and are equal to *a**i*. Vasya has *b* bourles. He can buy a certain number of dollars and then sell it no more than once in *n* days. Acco...
{"inputs": ["2 4\n3 7", "4 10\n4 3 2 1", "4 10\n4 2 3 1", "2 755\n51 160", "3 385\n978 1604 1888", "4 1663\n1904 1049 1622 472", "5 1293\n1183 142 1356 889 134", "1 1472\n784", "1 478\n1955", "1 1483\n1126", "10 595\n881 832 1159 171 230 750 361 1800 516 567", "93 867\n97 1270 616 1027 1685 27 1662 947 1480 20 1394 152...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
35
codeforces
d09e0f1b9d617f27cfe3d68024706ed8
Single-use Stones
A lot of frogs want to cross a river. A river is $w$ units width, but frogs can only jump $l$ units long, where $l &lt; w$. Frogs can also jump on lengths shorter than $l$. but can't jump longer. Hopefully, there are some stones in the river to help them. The stones are located at integer distances from the banks. The...
{"inputs": ["10 5\n0 0 1 0 2 0 0 1 0", "10 3\n1 1 1 1 2 1 1 1 1", "2 1\n0", "2 1\n5", "10 4\n0 0 6 2 7 1 6 4 0", "100 15\n0 0 1 1 1 0 1 1 1 1 0 1 1 1 0 1 0 0 1 0 1 1 1 0 0 1 1 0 0 1 0 0 1 0 0 1 0 1 0 1 0 1 1 0 0 0 1 0 0 0 0 0 1 0 1 1 1 1 1 0 1 0 1 0 1 0 0 0 0 1 1 0 1 1 0 0 1 0 1 0 1 0 0 1 0 0 1 0 0 1 1 0 1 0 1 0 0 1 0"...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
51
codeforces
d0ae2caa308c79b1dd056ce059c51365
Trace
One day, as Sherlock Holmes was tracking down one very important criminal, he found a wonderful painting on the wall. This wall could be represented as a plane. The painting had several concentric circles that divided the wall into several parts. Some parts were painted red and all the other were painted blue. Besides,...
{"inputs": ["1\n1", "3\n1 4 2", "4\n4 1 3 2", "4\n100 10 2 1", "10\n10 9 8 7 6 5 4 3 2 1", "1\n1000", "8\n8 1 7 2 6 3 5 4", "100\n1000 999 998 997 996 995 994 993 992 991 990 989 988 987 986 985 984 983 982 981 980 979 978 977 976 975 974 973 972 971 970 969 968 967 966 965 964 963 962 961 960 959 958 957 956 955 954 9...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
314
codeforces
d0af4a8c1ee35c1950cff7a2dcfd802f
Felicity's Big Secret Revealed
The gym leaders were fascinated by the evolutions which took place at Felicity camp. So, they were curious to know about the secret behind evolving Pokemon. The organizers of the camp gave the gym leaders a PokeBlock, a sequence of *n* ingredients. Each ingredient can be of type 0 or 1. Now the organizers told the gy...
{"inputs": ["4\n1011", "2\n10", "7\n0110011", "10\n0100011101", "12\n010010101011", "31\n1000000010111001111000111001110", "62\n00010011000110010011110110011001110110010011110110111100100010", "51\n100010110000000110000101100110111110001001011000000", "75\n011001100010010010100010011010001000110010011010100111110110100...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1
codeforces
d0b4203b9ff07c161d2aaec568cce045
Chess For Three
Alex, Bob and Carl will soon participate in a team chess tournament. Since they are all in the same team, they have decided to practise really hard before the tournament. But it's a bit difficult for them because chess is a game for two players, not three. So they play with each other according to following rules: - ...
{"inputs": ["3\n1\n1\n2", "2\n1\n2", "100\n2\n3\n1\n2\n3\n3\n3\n1\n1\n1\n1\n3\n3\n3\n3\n1\n2\n3\n3\n3\n3\n3\n3\n3\n1\n2\n2\n2\n3\n1\n1\n3\n3\n3\n3\n3\n3\n3\n3\n1\n2\n3\n3\n3\n1\n1\n1\n1\n3\n3\n3\n3\n1\n2\n3\n1\n2\n2\n2\n3\n3\n2\n1\n3\n3\n1\n2\n3\n1\n1\n1\n2\n2\n2\n3\n1\n1\n1\n1\n1\n1\n3\n2\n2\n2\n2\n2\n2\n3\n1\n2\n2\n2...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
76
codeforces
d0d6dc4057d27406033bbafafb50a4ec
If at first you don't succeed...
Each student eagerly awaits the day he would pass the exams successfully. Thus, Vasya was ready to celebrate, but, alas, he didn't pass it. However, many of Vasya's fellow students from the same group were more successful and celebrated after the exam. Some of them celebrated in the BugDonalds restaurant, some of them...
{"inputs": ["10 10 5 20", "2 2 0 4", "2 2 2 1", "98 98 97 100", "1 5 2 10", "5 1 2 10", "6 7 5 8", "6 7 5 9", "6 7 5 7", "50 50 1 100", "8 3 2 12", "10 19 6 25", "1 0 0 99", "0 1 0 98", "1 1 0 97", "1 1 1 96", "0 0 0 0", "100 0 0 0", "0 100 0 0", "100 100 0 0", "0 0 100 0", "100 0 100 0", "0 100 100 0", "100 100 100 0"...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
93
codeforces
d0e23c6e96b781e15b7393a41c955eb8
Chores
Petya and Vasya are brothers. Today is a special day for them as their parents left them home alone and commissioned them to do *n* chores. Each chore is characterized by a single parameter — its complexity. The complexity of the *i*-th chore equals *h**i*. As Petya is older, he wants to take the chores with complexit...
{"inputs": ["5 2 3\n6 2 3 100 1", "7 3 4\n1 1 9 1 1 1 1", "2 1 1\n10 2", "2 1 1\n7 7", "2 1 1\n1 1000000000", "3 1 2\n6 5 5", "3 2 1\n10 10 8", "8 3 5\n42 55 61 72 83 10 22 33", "10 5 5\n1 2 3 4 5 999999999 999999998 999999997 999999996 999999995", "4 1 3\n10 8 7 3", "4 2 2\n402 10 10 402", "4 1 3\n10 402 402 10", "4 3...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
282
codeforces
d0eadd1af5500f9da5e84a894556b641
Table Tennis Game 2
Misha and Vanya have played several table tennis sets. Each set consists of several serves, each serve is won by one of the players, he receives one point and the loser receives nothing. Once one of the players scores exactly *k* points, the score is reset and a new set begins. Across all the sets Misha scored *a* poi...
{"inputs": ["11 11 5", "11 2 3", "1 5 9", "2 3 3", "1 1000000000 1000000000", "2 3 5", "1000000000 1000000000 1000000000", "1 0 1", "101 99 97", "1000000000 0 1", "137 137 136", "255 255 255", "1 0 1000000000", "123 456 789", "666666 6666666 666665", "1000000000 999999999 999999999", "100000000 100000001 99999999", "3 ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
85
codeforces
d10c82725280342c8fff8d5450f16947
To Add or Not to Add
A piece of paper contains an array of *n* integers *a*1,<=*a*2,<=...,<=*a**n*. Your task is to find a number that occurs the maximum number of times in this array. However, before looking for such number, you are allowed to perform not more than *k* following operations — choose an arbitrary element from the array and...
{"inputs": ["5 3\n6 3 4 0 2", "3 4\n5 5 5", "5 3\n3 1 2 2 1", "6 0\n3 2 3 2 3 2", "10 15\n1 1 1 4 4 1 4 4 1 4", "5 100000\n0 5 5 4 3", "20 10\n-12 28 0 -27 16 25 -17 -25 9 -15 -38 19 33 20 -18 22 14 36 33 29", "100 100\n92 -6 67 92 65 -32 67 -31 91 -63 52 -81 -98 -12 48 86 -72 95 -50 66 79 89 -1 0 -33 -27 -23 -71 1 19 ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1
codeforces
d111139ff1607a1c8f702d05c3344b7a
Vasya and Polynomial
Vasya is studying in the last class of school and soon he will take exams. He decided to study polynomials. Polynomial is a function *P*(*x*)<==<=*a*0<=+<=*a*1*x*1<=+<=...<=+<=*a**n**x**n*. Numbers *a**i* are called coefficients of a polynomial, non-negative integer *n* is called a degree of a polynomial. Vasya has ma...
{"inputs": ["2 2 2", "2 3 3", "1 1 1", "3 5 10", "2 3 1000000000000000000", "7 8 9", "8 10 11", "5 30 930", "3 3 3", "1 5 5", "1 2 2", "1 2 5", "1 2 4", "1000000000000000000 1000000000000000000 1000000000000000000", "1 125 15625", "1000000000000 1000000000000000 1000000000000000000", "5 2 2", "1 3 6561", "3 6 5", "1 5 ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1
codeforces
d11a14b8d0336ac43a0a902e5921aa27
BerSU Ball
The Berland State University is hosting a ballroom dance in celebration of its 100500-th anniversary! *n* boys and *m* girls are already busy rehearsing waltz, minuet, polonaise and quadrille moves. We know that several boy&amp;girl pairs are going to be invited to the ball. However, the partners' dancing skill in eac...
{"inputs": ["4\n1 4 6 2\n5\n5 1 5 7 9", "4\n1 2 3 4\n4\n10 11 12 13", "5\n1 1 1 1 1\n3\n1 2 3", "1\n1\n1\n1", "2\n1 10\n1\n9", "4\n4 5 4 4\n5\n5 3 4 2 4", "1\n2\n1\n1", "1\n3\n2\n3 2", "1\n4\n3\n4 4 4", "1\n2\n4\n3 1 4 2", "1\n4\n5\n2 5 5 3 1", "2\n2 2\n1\n2", "2\n4 2\n2\n4 4", "2\n4 1\n3\n2 3 2", "2\n4 3\n4\n5 5 5 6",...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
173
codeforces
d14d76ed6f3fbd0cf793d69b8bbffa64
Growing Mushrooms
Each year in the castle of Dwarven King there is a competition in growing mushrooms among the dwarves. The competition is one of the most prestigious ones, and the winner gets a wooden salad bowl. This year's event brought together the best mushroom growers from around the world, so we had to slightly change the rules ...
{"inputs": ["2 3 3 50\n2 4\n4 2", "4 1 1 1\n544 397\n280 101\n280 101\n693 970", "10 1 1 25\n981 1\n352 276\n164 691\n203 853\n599 97\n901 688\n934 579\n910 959\n317 624\n440 737", "10 6 1 48\n239 632\n976 315\n797 112\n1 835\n938 862\n531 884\n422 607\n152 331\n413 677\n622 978", "8 1 4 55\n507 82\n681 492\n602 849\n3...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
60
codeforces
d154b5f96fbc09054a93df0a65532334
Prefixes and Suffixes
You have a string *s*<==<=*s*1*s*2...*s*|*s*|, where |*s*| is the length of string *s*, and *s**i* its *i*-th character. Let's introduce several definitions: - A substring *s*[*i*..*j*] (1<=≤<=*i*<=≤<=*j*<=≤<=|*s*|) of string *s* is string *s**i**s**i*<=+<=1...*s**j*. - The prefix of string *s* of length *l* (1<=≤...
{"inputs": ["ABACABA", "AAA", "A", "AAAAAAAAAAAAAAAAXAAAAAAAAAAAAAAAAAAAAAAA", "AB", "AXAXA", "CODEFORCES", "GERALDPAVELGERALDPAVEL", "ZZ"], "outputs": ["3\n1 4\n3 2\n7 1", "3\n1 3\n2 2\n3 1", "1\n1 1", "17\n1 39\n2 37\n3 35\n4 33\n5 31\n6 29\n7 27\n8 25\n9 23\n10 21\n11 19\n12 17\n13 15\n14 13\n15 11\n16 9\n40 1", "1\...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
14
codeforces
d15b551ae8fabd1bdc627749b5d8d626
Lucky String
Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Petya recently learned to determine whether a string of lowercase Latin letters is lucky. For each i...
{"inputs": ["5", "3", "8", "10", "16", "64", "128", "100", "47", "74", "477", "1000", "1024", "512", "747", "2075", "9475", "10000", "47589", "9999", "85475", "77777", "100000", "99994", "785", "1", "2", "7", "4", "99", "6", "9"], "outputs": ["abcda", "abc", "abcdabcd", "abcdabcdab", "abcdabcdabcdabcd", "abcdabcdabcdab...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
8
codeforces
d15d1f4a8fbfb34fdfd3b6f396e66f1a
Find Pair
You've got another problem dealing with arrays. Let's consider an arbitrary sequence containing *n* (not necessarily different) integers *a*1, *a*2, ..., *a**n*. We are interested in all possible pairs of numbers (*a**i*, *a**j*), (1<=≤<=*i*,<=*j*<=≤<=*n*). In other words, let's consider all *n*2 pairs of numbers, pick...
{"inputs": ["2 4\n2 1", "3 2\n3 1 5", "3 3\n1 1 2", "1 1\n-4", "3 7\n5 4 3", "3 6\n10 1 3", "4 12\n-1 -2 -3 -4", "5 10\n1 2 2 1 3", "5 13\n3 3 3 4 5", "8 26\n4 4 1 1 1 3 3 5", "10 90\n2 1 1 1 1 1 2 1 2 2", "10 6\n3 1 1 3 2 2 2 3 3 3", "10 18\n1 1 1 3 4 4 4 1 2 3", "50 622\n4 9 8 1 3 7 1 2 3 8 9 8 8 5 2 10 5 8 1 3 1 8 2...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1
codeforces
d16620d13a8ade89313bb0547f8d9d8d
none
Valery is a PE teacher at a school in Berland. Soon the students are going to take a test in long jumps, and Valery has lost his favorite ruler! However, there is no reason for disappointment, as Valery has found another ruler, its length is *l* centimeters. The ruler already has *n* marks, with which he can make mea...
{"inputs": ["3 250 185 230\n0 185 250", "4 250 185 230\n0 20 185 250", "2 300 185 230\n0 300", "4 300 4 5\n0 6 7 300", "2 100 30 70\n0 100", "2 300 140 160\n0 300", "4 300 1 2\n0 298 299 300", "3 350 150 160\n0 310 350", "4 300 4 5\n0 298 299 300", "19 180 117 148\n0 1 19 20 21 28 57 65 68 70 78 88 100 116 154 157 173 ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1
codeforces
d172ac41a846604f1c877ea449cf1b55
Buy Low Sell High
You can perfectly predict the price of a certain stock for the next *N* days. You would like to profit on this knowledge, but only want to transact one share of stock per day. That is, each day you will either buy one share, sell one share, or do nothing. Initially you own zero shares, and you cannot sell shares when y...
{"inputs": ["9\n10 5 4 7 9 12 6 2 10", "20\n3 1 4 1 5 9 2 6 5 3 5 8 9 7 9 3 2 3 8 4", "20\n9 29 8 9 13 4 14 27 16 11 27 14 4 29 23 17 3 9 30 19", "100\n411 642 560 340 276 440 515 519 182 314 35 227 390 136 97 5 502 584 567 79 543 444 413 463 455 316 545 329 437 443 9 435 291 384 328 501 603 234 285 297 453 587 550 72 ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
16
codeforces
d175d48a79770638f1ab5c9a7b472225
Broken Monitor
Innocentius has a problem — his computer monitor has broken. Now some of the pixels are "dead", that is, they are always black. As consequence, Innocentius can't play the usual computer games. He is recently playing the following game with his younger brother Polycarpus. Innocentius is touch-typing a program that pain...
{"inputs": ["4 8\n..w..w..\n........\n........\n..w..w..", "2 4\n....\n.w..", "2 6\nw..w.w\n...w..", "9 4\n....\n....\n....\n....\n....\n..w.\n....\n....\n.w..", "1 1\nw", "2 1\nw\n.", "2 1\nw\nw", "1 2\nww", "2 2\nww\n..", "2 2\n.w\n.w", "2 2\n..\nww", "2 2\nw.\nw.", "2 2\nw.\n.w", "2 2\n..\nw.", "3 3\n...\n..w\nw..",...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1
codeforces
d184fb3f320d8dcb999611f7b0d120ec
none
Santa Claus is the first who came to the Christmas Olympiad, and he is going to be the first to take his place at a desk! In the classroom there are *n* lanes of *m* desks each, and there are two working places at each of the desks. The lanes are numbered from 1 to *n* from the left to the right, the desks in a lane ar...
{"inputs": ["4 3 9", "4 3 24", "2 4 4", "3 10 24", "10 3 59", "10000 10000 160845880", "1 1 1", "1 1 2", "1 10000 1", "1 10000 20000", "10000 1 1", "10000 1 10000", "10000 1 20000", "3 2 1", "3 2 2", "3 2 3", "3 2 4", "3 2 5", "3 2 6", "3 2 7", "3 2 8", "3 2 9", "3 2 10", "3 2 11", "3 2 12", "300 2000 1068628", "300 20...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
336
codeforces
d1852fd6497c284277904fff7cf01797
Weak Subsequence
Little Petya very much likes strings. Recently he has received a voucher to purchase a string as a gift from his mother. The string can be bought in the local shop. One can consider that the shop has all sorts of strings over the alphabet of fixed size. The size of the alphabet is equal to *k*. However, the voucher has...
{"inputs": ["2 2", "3 5", "2 139", "5 6", "1000 1002", "131 132", "4 4", "3 2", "1 1000000000", "666 888888888", "1000000 1000000000", "1000000 1000000", "1000000 2", "2 1000000000", "1000000 500000", "12345 543210123", "1 2", "1 3", "1 4", "1 5", "1 6", "1 7", "1 8", "2 3", "2 4", "2 5", "2 6", "2 7", "2 8", "3 3", "3...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1
codeforces
d1946a1f3c70a6557cd0eba06be837de
The Red Button
Piegirl found the red button. You have one last chance to change the inevitable end. The circuit under the button consists of *n* nodes, numbered from 0 to *n* - 1. In order to deactivate the button, the *n* nodes must be disarmed in a particular order. Node 0 must be disarmed first. After disarming node *i*, the next...
{"inputs": ["2", "3", "4", "16", "5", "7", "32", "255", "65536", "99999", "9", "6", "8", "10", "12", "20", "25", "30", "32", "45", "50", "100", "126", "513", "514", "800", "1000", "2500", "6400", "23105", "24002", "29024", "36002", "55555", "65534", "77776", "88888", "99494", "99998", "90248", "99994", "100000", "98300...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1
codeforces
d19a5d2d40c3191166b3cebf9ec2503a
The penguin's game
Pay attention: this problem is interactive. Penguin Xoriy came up with a new game recently. He has *n* icicles numbered from 1 to *n*. Each icicle has a temperature — an integer from 1 to 109. Exactly two of these icicles are special: their temperature is *y*, while a temperature of all the others is *x*<=≠<=*y*. You ...
{"inputs": ["4 2 1 1 3", "6 1 2 5 6", "2 4523 4235 1 2", "511 42 1000000000 255 511", "666 536870911 268435455 13 133", "999 536870912 536870911 1 999", "1000 123 321 1 513", "1000 1000000000 1 36 1000", "1000 15 16 511 512", "1000 16 15 511 512", "50 276891238 128284616 2 28", "100 745880634 179094068 84 99", "150 481...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
4
codeforces
d1a4489d4ae1ae49f2006c2a331b20f2
Palindromic Cut
Kolya has a string *s* of length *n* consisting of lowercase and uppercase Latin letters and digits. He wants to rearrange the symbols in *s* and cut it into the minimum number of parts so that each part is a palindrome and all parts have the same lengths. A palindrome is a string which reads the same backward as forw...
{"inputs": ["6\naabaac", "8\n0rTrT022", "2\naA", "1\ns", "10\n6IIC6CCIIC", "20\nqqqoqqoqMoqMMMqqMMqM", "45\nf3409ufEFU32rfsFJSKDFJ234234ASkjffjsdfsdfsj33", "30\n8M8MMMMMlrMlMMrMMllMMrllMMrMrl", "40\nTddTddddTddddddTdddTdddddddddddddddddddd", "45\nRRNRRRRRRRRRNRRRRRRRRRRRRRRNRRRRRRRRRRRNRRRRR", "115\nz9c2f5fxz9z999c9z99...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
6
codeforces
d1a4bc4ff7233cca17c240867693a8ff
Slime Combining
Your friend recently gave you some slimes for your birthday. You have *n* slimes all initially with value 1. You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other *n*<=-<=1 slimes one by one. When you add a slime, you place it at the right of...
{"inputs": ["1", "2", "3", "8", "100000", "12345", "32", "70958", "97593", "91706", "85371", "97205", "34768", "12705", "30151", "4974", "32728", "8192", "65536", "32", "256", "4096", "33301", "16725", "149", "16277", "99701"], "outputs": ["1", "2", "2 1", "4", "17 16 11 10 8 6", "14 13 6 5 4 1", "6", "17 13 11 9 6 4 3...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
215
codeforces
d1b115caf00a7ad2e19bbdbf6e96df46
Book Reading
Recently Luba bought a very interesting book. She knows that it will take *t* seconds to read the book. Luba wants to finish reading as fast as she can. But she has some work to do in each of *n* next days. The number of seconds that Luba has to spend working during *i*-th day is *a**i*. If some free time remains, she...
{"inputs": ["2 2\n86400 86398", "2 86400\n0 86400", "2 86400\n1 86399", "100 1000000\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0", "1 1\n86399", "6 1200\n86400 864...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
396
codeforces
d1cb8e128dce4bdba12b0eb1c2f27fc2
k-Factorization
Given a positive integer *n*, find *k* integers (not necessary distinct) such that all these integers are strictly greater than 1, and their product is equal to *n*. The first line contains two integers *n* and *k* (2<=≤<=*n*<=≤<=100000, 1<=≤<=*k*<=≤<=20). If it's impossible to find the representation of *n* as a produ...
{"inputs": ["100000 2", "100000 20", "1024 5", "100000 10", "99999 3", "99999 4", "99999 5", "1024 10", "1024 11", "2048 11", "2 1", "2 2", "2 3", "2 4", "2 5", "2 1", "3 1", "3 2", "349 2", "8 1", "66049 2", "6557 2", "9 2", "4 2", "2 2", "4 4", "12 1", "17 1", "8 2", "14 2", "99991 1", "30 2", "97 1", "92 2", "4 1", ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
96
codeforces
d21e0b3207ee3c755958cfc2ee170922
Leha and another game about graph
Leha plays a computer game, where is on each level is given a connected graph with *n* vertices and *m* edges. Graph can contain multiple edges, but can not contain self loops. Each vertex has an integer *d**i*, which can be equal to 0, 1 or <=-<=1. To pass the level, he needs to find a «good» subset of edges of the gr...
{"inputs": ["1 0\n1", "4 5\n0 0 0 -1\n1 2\n2 3\n3 4\n1 4\n2 4", "2 1\n1 1\n1 2", "3 3\n0 -1 1\n1 2\n2 3\n1 3", "10 10\n-1 -1 -1 -1 -1 -1 -1 -1 -1 -1\n6 7\n8 3\n6 4\n4 2\n9 2\n5 10\n9 8\n10 7\n5 1\n6 2", "3 2\n1 0 1\n1 2\n2 3"], "outputs": ["-1", "0", "1\n1", "1\n2", "0", "2\n2\n1"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1
codeforces
d2370e5d51e7c7104ac917dd0c1ee297
Home Numbers
The main street of Berland is a straight line with *n* houses built along it (*n* is an even number). The houses are located at both sides of the street. The houses with odd numbers are at one side of the street and are numbered from 1 to *n*<=-<=1 in the order from the beginning of the street to the end (in the pictur...
{"inputs": ["4 2", "8 5", "2 1", "2 2", "10 1", "10 10", "100000 100000", "100000 2", "100000 3", "100000 99999", "100 100", "3000 34", "2000 1", "100000 1", "24842 1038", "1628 274", "16186 337", "24562 2009", "9456 3443", "5610 332", "1764 1288", "28588 13902", "92480 43074", "40022 26492", "85766 64050", "67808 6180...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
120
codeforces
d24e0144ab5b191851e3d3b0c9dc7679
Three displays
It is the middle of 2018 and Maria Stepanovna, who lives outside Krasnokamensk (a town in Zabaikalsky region), wants to rent three displays to highlight an important problem. There are $n$ displays placed along a road, and the $i$-th of them can display a text with font size $s_i$ only. Maria Stepanovna wants to rent ...
{"inputs": ["5\n2 4 5 4 10\n40 30 20 10 40", "3\n100 101 100\n2 4 5", "10\n1 2 3 4 5 6 7 8 9 10\n10 13 11 14 15 12 13 13 18 13", "3\n1 2 3\n100000000 100000000 100000000", "3\n999999998 999999999 1000000000\n100000000 100000000 99999999", "10\n802030518 598196518 640274071 983359971 71550121 96204862 799843967 44617360...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
104
codeforces
d29152b2c4baf0df2caf31c9d71faa80
Sums of Digits
Vasya had a strictly increasing sequence of positive integers *a*1, ..., *a**n*. Vasya used it to build a new sequence *b*1, ..., *b**n*, where *b**i* is the sum of digits of *a**i*'s decimal representation. Then sequence *a**i* got lost and all that remained is sequence *b**i*. Vasya wonders what the numbers *a**i* c...
{"inputs": ["3\n1\n2\n3", "3\n3\n2\n1", "10\n1\n2\n3\n4\n5\n6\n7\n8\n9\n1", "10\n8\n8\n5\n1\n2\n7\n3\n8\n9\n4", "10\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1", "100\n1\n2\n3\n4\n5\n6\n7\n8\n9\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n2\n3\n4\n5\n6\n7\n8\n9\n10\n11\n3\n4\n5\n6\n7\n8\n9\n10\n11\n12\n4\n5\n6\n7\n8\n9\n10\n11\n12\n13\n5\n6\n7\n...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
2
codeforces
d33ed0a7470768868bc662f77d990f03
Three matrices
Chubby Yang is studying linear equations right now. He came up with a nice problem. In the problem you are given an *n*<=×<=*n* matrix *W*, consisting of integers, and you should find two *n*<=×<=*n* matrices *A* and *B*, all the following conditions must hold: - *A**ij*<==<=*A**ji*, for all *i*,<=*j* (1<=≤<=*i*,<=*...
{"inputs": ["2\n1 4\n3 2", "3\n1 2 3\n4 5 6\n7 8 9", "8\n62 567 1382 1279 728 1267 1262 568\n77 827 717 1696 774 248 822 1266\n563 612 995 424 1643 1197 338 1141\n1579 806 1254 468 184 1571 716 772\n1087 182 1312 772 605 1674 720 1349\n1393 988 873 157 403 301 1519 1192\n1085 625 1395 1087 847 1360 1004 594\n1368 1056 ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
34
codeforces
d34fce590c9ab5f1c4b730f672fac6e8
Friends Meeting
Two friends are on the coordinate axis *Ox* in points with integer coordinates. One of them is in the point *x*1<==<=*a*, another one is in the point *x*2<==<=*b*. Each of the friends can move by one along the line in any direction unlimited number of times. When a friend moves, the tiredness of a friend changes acco...
{"inputs": ["3\n4", "101\n99", "5\n10", "1\n2", "1\n1000", "999\n1000", "1000\n999", "1000\n1", "2\n1", "2\n999", "2\n998", "999\n2", "998\n2", "2\n1000", "1000\n2", "1\n999", "999\n1", "188\n762", "596\n777", "773\n70", "825\n729", "944\n348", "352\n445", "529\n656", "19\n315", "138\n370", "546\n593", "285\n242", "773...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
607
codeforces
d35468d66b47dffb57a8ada4ba7221e5
Vanya and Fence
Vanya and his friends are walking along the fence of height *h* and they do not want the guard to notice them. In order to achieve this the height of each of the friends should not exceed *h*. If the height of some person is greater than *h* he can bend down and then he surely won't be noticed by the guard. The height ...
{"inputs": ["3 7\n4 5 14", "6 1\n1 1 1 1 1 1", "6 5\n7 6 8 9 10 5", "10 420\n214 614 297 675 82 740 174 23 255 15", "10 561\n657 23 1096 487 785 66 481 554 1000 821", "100 342\n478 143 359 336 162 333 385 515 117 496 310 538 469 539 258 676 466 677 1 296 150 560 26 213 627 221 255 126 617 174 279 178 24 435 70 145 619 ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
889
codeforces
d3765fa3113a54c91060c293e49d86cc
Strange Calculation and Cats
Gosha's universe is a table consisting of *n* rows and *m* columns. Both the rows and columns are numbered with consecutive integers starting with 1. We will use (*r*,<=*c*) to denote a cell located in the row *r* and column *c*. Gosha is often invited somewhere. Every time he gets an invitation, he first calculates t...
{"inputs": ["1 3 3\n2 1 2 3\n3 1 2 5\n1 1 1 7", "3 3 3\n2 2 2 2\n1 3 3 5\n1 3 3 7", "4 5 5\n2 2 5 3\n2 2 4 6\n3 2 4 9\n1 4 4 13\n1 4 4 15", "1 1 1\n1 1 1 2", "3 3 1\n1 3 3 5", "2 2 5\n2 1 1 8\n3 1 1 12345\n2 1 2 22345\n3 1 2 31243\n1 2 2 111115", "1 2 3\n1 1 1 2\n1 1 2 5\n1 1 1 19", "1 1 4\n2 1 1 2\n3 1 1 5\n1 1 1 7\n1...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1
codeforces
d377f3b3aaa38b4a7edac7027b9c009a
Selling Souvenirs
After several latest reforms many tourists are planning to visit Berland, and Berland people understood that it's an opportunity to earn money and changed their jobs to attract tourists. Petya, for example, left the IT corporation he had been working for and started to sell souvenirs at the market. This morning, as us...
{"inputs": ["1 1\n2 1", "2 2\n1 3\n2 2", "4 3\n3 10\n2 7\n2 8\n1 1", "5 5\n3 5\n2 6\n3 2\n1 1\n1 6", "6 6\n1 6\n1 4\n1 8\n3 2\n3 2\n2 8", "6 12\n1 7\n1 10\n2 8\n1 2\n2 9\n3 5", "6 18\n3 3\n1 10\n2 10\n3 6\n1 3\n2 3", "20 25\n2 13\n3 11\n1 32\n1 43\n3 85\n1 14\n2 57\n1 54\n1 38\n2 96\n2 89\n3 64\n1 79\n2 73\n1 73\n2 34\...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
4
codeforces
d37c153e46473b00ba4e801f4917d3d7
Bulbs
Vasya wants to turn on Christmas lights consisting of *m* bulbs. Initially, all bulbs are turned off. There are *n* buttons, each of them is connected to some set of bulbs. Vasya can press any of these buttons. When the button is pressed, it turns on all the bulbs it's connected to. Can Vasya light up all the bulbs? I...
{"inputs": ["3 4\n2 1 4\n3 1 3 1\n1 2", "3 3\n1 1\n1 2\n1 1", "3 4\n1 1\n1 2\n1 3", "1 5\n5 1 2 3 4 5", "1 5\n5 4 4 1 2 3", "1 5\n5 1 1 1 1 5", "2 5\n4 3 1 4 2\n4 2 3 4 5", "5 7\n2 6 7\n5 1 1 1 1 1\n3 6 5 4\n0\n4 4 3 2 1", "100 100\n0\n0\n0\n1 53\n0\n0\n1 34\n1 54\n0\n1 14\n0\n1 33\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n1 82\n...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
439
codeforces
d3891b505ee7f8ab84e9bc52c21e7b57
none
Manao is taking part in a quiz. The quiz consists of *n* consecutive questions. A correct answer gives one point to the player. The game also has a counter of consecutive correct answers. When the player answers a question correctly, the number on this counter increases by 1. If the player answers a question incorrectl...
{"inputs": ["5 3 2", "5 4 2", "300 300 3", "300 282 7", "1000000000 1000000000 1000000000", "1000000000 800000000 2", "2 0 2", "2 1 2", "2 2 2", "3 2 2", "3 3 2", "10 7 3", "10 8 3", "10 8 5", "10 9 5", "972 100 2", "972 600 2", "972 900 2", "972 900 4", "972 900 5", "12345 11292 3", "120009 70955 2", "120009 100955 2"...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
6
codeforces
d38fb1c489d4cbf930b0337c192c450b
Interactive LowerBound
This is an interactive problem. You are given a sorted in increasing order singly linked list. You should find the minimum integer in the list which is greater than or equal to *x*. More formally, there is a singly liked list built on an array of *n* elements. Element with index *i* contains two integers: *value**i* ...
{"inputs": ["5 3 80\n97 -1\n58 5\n16 2\n81 1\n79 4", "5 1 6\n1 2\n2 3\n3 4\n4 5\n5 -1", "1 1 0\n0 -1", "1 1 2\n0 -1", "1 1 1000000000\n0 -1", "5 3 3\n3 5\n2 1\n0 4\n1 2\n4 -1", "5 3 145337745\n619347297 5\n344132479 1\n122841322 4\n169280018 2\n740666615 -1", "5 3 315433300\n411188472 5\n316581280 1\n200698791 4\n31488...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
8
codeforces
d39d202a68a2cf02ae6f18f45fddeaca
Renting Bikes
A group of *n* schoolboys decided to ride bikes. As nobody of them has a bike, the boys need to rent them. The renting site offered them *m* bikes. The renting price is different for different bikes, renting the *j*-th bike costs *p**j* rubles. In total, the boys' shared budget is *a* rubles. Besides, each of them ha...
{"inputs": ["2 2 10\n5 5\n7 6", "4 5 2\n8 1 1 2\n6 3 7 5 2", "1 1 2\n1\n2", "4 1 1\n3 2 3 2\n3", "1 4 1\n3\n2 4 5 5", "3 3 3\n1 1 2\n3 5 6", "4 5 6\n5 1 7 2\n8 7 3 9 8", "4 8 10\n2 1 2 2\n10 12 10 8 7 9 10 9", "8 4 18\n9 4 2 2 7 5 1 1\n11 12 8 9", "6 6 2\n6 1 5 3 10 1\n11 4 7 8 11 7", "10 10 7\n6 7 15 1 3 1 14 6 7 4\n1...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
4
codeforces
d3cc84d8a4738925b046a983cf21b4b1
Left-handers, Right-handers and Ambidexters
You are at a water bowling training. There are *l* people who play with their left hand, *r* people, who play with their right hand, and *a* ambidexters, who can play with left or right hand. The coach decided to form a team of even number of players, exactly half of the players should play with their right hand, and ...
{"inputs": ["1 4 2", "5 5 5", "0 2 0", "30 70 34", "89 32 24", "89 44 77", "0 0 0", "100 100 100", "1 1 1", "30 70 35", "89 44 76", "0 100 100", "100 0 100", "100 1 100", "1 100 100", "100 100 0", "100 100 1", "1 2 1", "0 0 100", "0 100 0", "100 0 0", "10 8 7", "45 47 16", "59 43 100", "34 1 30", "14 81 1", "53 96 94",...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
404
codeforces
d3d3a53758643400bf3241186c9e43bb
Regular Bridge
An undirected graph is called *k*-regular, if the degrees of all its vertices are equal *k*. An edge of a connected graph is called a bridge, if after removing it the graph is being split into two connected components. Build a connected undirected *k*-regular graph containing at least one bridge, or else state that su...
{"inputs": ["1", "3", "11", "10", "2", "4", "5", "6", "7", "8", "9", "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",...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
2
codeforces
d3e51e02198078824b0169caf85d97d6
Till I Collapse
Rick and Morty want to find MR. PBH and they can't do it alone. So they need of Mr. Meeseeks. They Have generated *n* Mr. Meeseeks, standing in a line numbered from 1 to *n*. Each of them has his own color. *i*-th Mr. Meeseeks' color is *a**i*. Rick and Morty are gathering their army and they want to divide Mr. Meese...
{"inputs": ["5\n1 3 4 3 3", "8\n1 5 7 8 1 7 6 1", "10\n4 1 2 6 8 5 3 9 3 9", "85\n23 11 69 1 49 10 7 13 66 35 81 4 51 2 62 55 31 18 85 34 59 44 20 28 27 5 6 79 43 78 45 64 61 56 12 40 54 52 24 14 26 65 75 72 30 46 67 80 38 70 25 60 50 8 17 84 41 71 58 76 19 47 73 29 3 48 82 33 39 63 15 37 83 36 9 32 16 57 68 53 21 77 2...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
2
codeforces
d3e540e3910727f7dcf520e39d57d44d
Irrational problem
Little Petya was given this problem for homework: You are given function (here represents the operation of taking the remainder). His task is to count the number of integers *x* in range [*a*;*b*] with property *f*(*x*)<==<=*x*. It is a pity that Petya forgot the order in which the remainders should be taken and wr...
{"inputs": ["2 7 1 8 2 8", "20 30 40 50 0 100", "31 41 59 26 17 43", "1 2 3 4 0 0", "1 2 3 4 1 1", "1 2 999 1000 30 40", "17 18 19 20 17 20", "17 18 19 20 16 20", "41 449 328 474 150 709", "467 329 936 440 117 700", "258 811 952 491 931 993", "823 431 359 590 153 899", "292 370 404 698 699 876", "442 705 757 527 868 89...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
63
codeforces
d41eccdddbe3022c0a46f60c8badcf60
Abbreviation
You are given a text consisting of $n$ space-separated words. There is exactly one space character between any pair of adjacent words. There are no spaces before the first word and no spaces after the last word. The length of text is the number of letters and spaces in it. $w_i$ is the $i$-th word of text. All words co...
{"inputs": ["6\nto be or not to be", "10\na ab a a b ab a a b c", "6\naa bb aa aa bb bb", "45\nxr l pl sx c c u py sv j f x h u y w w bs u cp e ad ib b tz gy lm e s n ln kg fs rd ln v f sh t z r b j w of", "250\nf r s d b f f k d e k v m b t k k j t t a o m m s n d w l v g e k x d w k v a j h c a g x s d e t z z w q z ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
3
codeforces
d44b54a5c176b8db281df28c230f992d
Beautiful Numbers
Vitaly is a very weird man. He's got two favorite digits *a* and *b*. Vitaly calls a positive integer good, if the decimal representation of this integer only contains digits *a* and *b*. Vitaly calls a good number excellent, if the sum of its digits is a good number. For example, let's say that Vitaly's favourite dig...
{"inputs": ["1 3 3", "2 3 10", "6 8 14215", "4 9 104671", "6 7 78755", "1 8 265", "3 9 37413", "1 7 49055", "3 4 11028", "2 6 32377", "3 5 80791", "4 8 11857", "1 3 10785", "4 6 11808", "1 2 11857", "2 4 88193", "1 4 37226", "2 5 53049", "3 6 1000000", "7 9 999999", "8 9 999999", "3 8 1000000", "2 8 999999", "1 6 99769...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
54
codeforces
d4606777a789a26895f0e249ec9f7499
Kyoya and Permutation
Let's define the permutation of length *n* as an array *p*<==<=[*p*1,<=*p*2,<=...,<=*p**n*] consisting of *n* distinct integers from range from 1 to *n*. We say that this permutation maps value 1 into the value *p*1, value 2 into the value *p*2 and so on. Kyota Ootori has just learned about cyclic representation of a ...
{"inputs": ["4 3", "10 1", "1 1", "50 1", "10 57", "50 20365011074", "20 9999", "49 12586269025", "49 1", "10 89", "10 1", "5 8", "5 1", "25 121393", "25 1", "1 1", "2 2", "3 3", "4 2", "5 8", "6 10", "7 20", "8 24", "9 1", "10 24", "11 77", "12 101", "13 240", "14 356", "15 463", "16 747", "17 734", "18 1809", "19 859...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
21
codeforces
d462df4068f05173ec26a6fb99d24783
Right Triangles
You are given a *n*<=×<=*m* field consisting only of periods ('.') and asterisks ('*'). Your task is to count all right triangles with two sides parallel to the square sides, whose vertices are in the centers of '*'-cells. A right triangle is a triangle in which one angle is a right angle (that is, a 90 degree angle). ...
{"inputs": ["2 2\n**\n*.", "3 4\n*..*\n.**.\n*.**", "3 2\n..\n..\n*.", "1 2\n**", "1 3\n*.*", "5 2\n*.\n**\n.*\n..\n.*", "2 3\n...\n..*", "10 9\n..*..**..\n*.*...**.\n.*...*.*.\n.*****.*.\n.*.*.**.*\n.**.*....\n**.......\n**..*.*.*\n*.*.**.*.\n*.*.*.*.*", "2 3\n.*.\n**.", "5 3\n**.\n..*\n*.*\n*.*\n*..", "4 2\n**\n**\n....
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
22
codeforces
d484895805b8041afab5927ffdb460e2
New Year Candles
Vasily the Programmer loves romance, so this year he decided to illuminate his room with candles. Vasily has *a* candles.When Vasily lights up a new candle, it first burns for an hour and then it goes out. Vasily is smart, so he can make *b* went out candles into a new candle. As a result, this new candle can be used ...
{"inputs": ["4 2", "6 3", "1000 1000", "123 5", "1000 2", "1 2", "1 3", "1 4", "2 2", "3 2", "3 3", "999 2", "1000 3", "1000 4", "1 1000", "80 970", "80 970", "80 970", "80 970", "80 970", "80 970", "10 4", "4 3", "91 5", "777 17", "100 4", "5 3", "6 4", "26 8", "9 4", "20 3", "17 3"], "outputs": ["7", "8", "1001", "15...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
472
codeforces
d499e64d29c12399b541b19d5ace8193
Chat
There are times you recall a good old friend and everything you've come through together. Luckily there are social networks — they store all your message history making it easy to know what you argued over 10 years ago. More formal, your message history is a sequence of messages ordered by time sent numbered from 1 to...
{"inputs": ["6 0\n0 1 1 2 3 2", "10 1\n0 1 0 3 4 5 2 3 7 0", "2 2\n0 1", "1 1\n0", "5 2\n0 1 2 3 1", "30 1\n0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 2 0 0 0 0 0 2 1 0", "100 5\n0 1 1 1 0 5 6 6 8 8 9 11 12 11 8 0 0 14 6 16 7 21 15 23 15 24 0 0 0 28 0 29 26 27 19 0 0 21 37 32 40 30 37 34 39 38 34 38 0 0 41 24 45 47 0 33...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
52
codeforces
d4bcfbf18441008f1ac0b108ef216426
Cow Program
Farmer John has just given the cows a program to play with! The program contains two integer variables, *x* and *y*, and performs the following operations on a sequence *a*1,<=*a*2,<=...,<=*a**n* of positive integers: 1. Initially, *x*<==<=1 and *y*<==<=0. If, after any step, *x*<=≤<=0 or *x*<=&gt;<=*n*, the program ...
{"inputs": ["4\n2 4 1", "3\n1 2", "5\n2 2 1 3", "2\n1", "8\n7 6 2 6 2 6 6", "8\n4 5 3 2 3 3 3", "3\n1 1", "5\n3 2 4 2", "92\n79 52 17 45 47 64 48 49 650617238 32 9 74 12 80 39 41 73 22 25 73 79 51 85 21 3 56 255371563 2 986959075 17 30 70 577324422 84 7 39 85 18 6 63 44 52 37 5 36 9 12 34 9 60 56 1 491072951 57 7 91 76...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
2
codeforces
d4c9f2251593a3c8a9c4136b405c21e0
Runner's Problem
You are running through a rectangular field. This field can be represented as a matrix with 3 rows and *m* columns. (*i*,<=*j*) denotes a cell belonging to *i*-th row and *j*-th column. You start in (2,<=1) and have to end your path in (2,<=*m*). From the cell (*i*,<=*j*) you may advance to: - (*i*<=-<=1,<=*j*<=+<=1...
{"inputs": ["2 5\n1 3 4\n2 2 3", "50 100\n3 24 49\n2 10 12\n1 87 92\n2 19 60\n2 53 79\n3 65 82\n3 10 46\n1 46 86\n2 55 84\n1 50 53\n3 80 81\n3 66 70\n2 35 52\n1 63 69\n2 65 87\n3 68 75\n1 33 42\n1 56 90\n3 73 93\n2 20 26\n2 42 80\n2 83 87\n3 99 99\n1 14 79\n2 94 97\n1 66 85\n1 7 73\n1 50 50\n2 16 40\n2 76 94\n1 71 98\n...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
2
codeforces
d4e0927d80d36c92d3c5e2af89871259
Forming Teams
One day *n* students come to the stadium. They want to play football, and for that they need to split into teams, the teams must have an equal number of people. We know that this group of people has archenemies. Each student has at most two archenemies. Besides, if student *A* is an archenemy to student *B*, then stud...
{"inputs": ["5 4\n1 2\n2 4\n5 3\n1 4", "6 2\n1 4\n3 4", "6 6\n1 2\n2 3\n3 1\n4 5\n5 6\n6 4", "5 1\n1 2", "8 8\n1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 8\n8 1", "28 3\n15 3\n10 19\n17 25", "2 1\n1 2", "3 1\n2 3", "3 2\n1 2\n3 2", "3 3\n1 2\n1 3\n2 3", "4 1\n1 4", "4 2\n4 1\n2 1", "4 3\n1 3\n3 2\n2 4", "4 3\n3 2\n4 2\n4 3", "5 3...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
28
codeforces
d4eccfcdc4a1ce493b2358cdc4f24618
Cableway
A group of university students wants to get to the top of a mountain to have a picnic there. For that they decided to use a cableway. A cableway is represented by some cablecars, hanged onto some cable stations by a cable. A cable is scrolled cyclically between the first and the last cable stations (the first of them ...
{"inputs": ["1 3 2", "3 2 1", "3 5 2", "10 10 10", "29 7 24", "28 94 13", "90 89 73", "0 0 1", "0 0 2", "0 1 0", "0 1 1", "0 1 2", "0 2 0", "0 2 1", "0 2 2", "1 0 0", "1 0 1", "1 0 2", "1 1 0", "1 1 1", "1 1 2", "1 2 0", "1 2 1", "1 2 2", "2 0 0", "2 0 1", "2 0 2", "2 1 0", "2 1 1", "2 1 2", "2 2 0", "2 2 1", "2 2 2", ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
133
codeforces
d4f238414fd52248994773b270d7e1bb
Routine Problem
Manao has a monitor. The screen of the monitor has horizontal to vertical length ratio *a*:*b*. Now he is going to watch a movie. The movie's frame has horizontal to vertical length ratio *c*:*d*. Manao adjusts the view in such a way that the movie preserves the original frame ratio, but also occupies as much space on ...
{"inputs": ["1 1 3 2", "4 3 2 2", "3 4 2 3", "4 4 5 5", "1 1 1 1", "1000 1000 1000 1000", "125 992 14 25", "999 998 997 996", "984 286 976 284", "999 1000 1000 999", "999 1000 998 999", "1 1000 1000 1", "1 999 1000 1", "50 80 6 3", "114 891 20 3", "10 13 75 57", "21 35 34 51", "41 95 82 30", "123 150 82 60", "100 175 1...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
13
codeforces
d4f7e1eed1a5f669bc061ada8368101c
Merge Equals
You are given an array of positive integers. While there are at least two equal elements, we will perform the following operation. We choose the smallest value $x$ that occurs in the array $2$ or more times. Take the first two occurrences of $x$ in this array (the two leftmost occurrences). Remove the left of these two...
{"inputs": ["7\n3 4 1 2 2 1 1", "5\n1 1 3 1 1", "5\n10 40 20 50 30", "100\n10 10 15 12 15 13 15 12 10 10 15 11 13 14 13 14 10 13 12 10 14 12 13 11 14 15 12 11 11 15 12 12 11 14 14 14 15 10 10 15 15 13 13 15 10 12 14 10 12 13 11 15 11 13 14 12 10 12 11 14 13 15 13 15 13 14 14 11 12 13 11 14 10 10 15 10 15 12 15 12 13 10...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
44
codeforces
d4fcaa5a12e174eeb47b6b1519863b94
Initial Bet
There are five people playing a game called "Generosity". Each person gives some non-zero number of coins *b* as an initial bet. After all players make their bets of *b* coins, the following operation is repeated for several times: a coin is passed from one player to some other player. Your task is to write a program ...
{"inputs": ["2 5 4 0 4", "4 5 9 2 1", "0 0 0 0 0", "1 2 1 2 3", "100 0 0 0 0", "2 3 4 5 6", "1 1 1 1 1", "0 1 2 3 4", "100 100 100 100 100", "93 100 99 90 98", "99 99 99 99 99", "99 98 98 99 100", "43 83 1 0 23", "43 83 1 100 23", "57 83 11 4 93", "87 38 19 33 100", "56 0 0 0 4", "0 0 0 0 1", "99 100 100 100 100"], "ou...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
46
codeforces
d505dd4a88f3b77f441d522c3490d39d
Well played!
Recently Max has got himself into popular CCG "BrainStone". As "BrainStone" is a pretty intellectual game, Max has to solve numerous hard problems during the gameplay. Here is one of them: Max owns *n* creatures, *i*-th of them can be described with two numbers — its health *hp**i* and its damage *dmg**i*. Max also ha...
{"inputs": ["2 1 1\n10 15\n6 1", "3 0 3\n10 8\n7 11\n5 2", "1 0 0\n2 1", "1 0 200000\n1 2", "7 5 7\n29 25\n84 28\n34 34\n14 76\n85 9\n40 57\n99 88", "7 6 7\n11 75\n61 90\n22 14\n100 36\n29 48\n69 52\n16 3", "7 8 7\n88 29\n30 44\n14 1\n83 95\n73 88\n10 42\n29 26", "12 7 7\n78 189\n614 271\n981 510\n37 762\n803 106\n78 3...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
8
codeforces
d50bdeed886902a60096918dfa119f35
Order Book
In this task you need to process a set of stock exchange orders and use them to create order book. An order is an instruction of some participant to buy or sell stocks on stock exchange. The order number *i* has price *p**i*, direction *d**i* — buy or sell, and integer *q**i*. This means that the participant is ready ...
{"inputs": ["6 2\nB 10 3\nS 50 2\nS 40 1\nS 50 6\nB 20 4\nB 25 10", "2 1\nB 7523 5589\nS 69799 1711", "1 1\nB 48259 991", "1 50\nB 47828 7726", "1 1\nS 95992 7257", "1 50\nS 72218 8095", "2 50\nB 758 9290\nS 86168 3367", "3 3\nB 5878 1568\nS 60238 4895\nS 76276 1905", "6 2\nB 0 1\nS 1 1\nS 1 1\nS 1 1\nB 0 1\nB 0 1", "2...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
30
codeforces
d51744512d657fc8c49daa2a291bf799
Property
Bill is a famous mathematician in BubbleLand. Thanks to his revolutionary math discoveries he was able to make enough money to build a beautiful house. Unfortunately, for not paying property tax on time, court decided to punish Bill by making him lose a part of his property. Bill’s property can be observed as a convex...
{"inputs": ["3\n0 1 2", "10\n0 1 2 3 4 5 6 7 8 9", "10\n1 7 3 6 8 2 4 5 0 9", "10\n4 9 7 2 3 5 6 1 8 0", "5\n1 2 3 0 4", "5\n3 0 2 1 4", "5\n2 4 3 0 1", "17\n0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16", "17\n5 13 12 8 4 7 15 6 0 1 2 10 9 14 3 16 11", "17\n7 10 12 11 13 0 9 6 4 2 15 3 5 8 14 16 1", "50\n15 14 37 47 44 7 1...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1
codeforces
d536f2dd4edadb347b7f5b76e5bebc9f
Shower Line
Many students live in a dormitory. A dormitory is a whole new world of funny amusements and possibilities but it does have its drawbacks. There is only one shower and there are multiple students who wish to have a shower in the morning. That's why every morning there is a line of five people in front of the dormitory...
{"inputs": ["0 0 0 0 9\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n7 0 0 0 0", "0 43 21 18 2\n3 0 21 11 65\n5 2 0 1 4\n54 62 12 0 99\n87 64 81 33 0", "0 4 2 4 9\n6 0 2 5 0\n2 5 0 6 3\n6 3 3 0 10\n0 3 1 3 0", "0 65 90 2 32\n69 0 9 97 67\n77 97 0 16 84\n18 50 94 0 63\n69 12 82 16 0", "0 70 10 0 0\n70 0 50 90 0\n10 50 0 80 0\n0 90 ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
44
codeforces
d58e0be64698471a23413eaf7d77d0a6
Subway Innovation
Berland is going through tough times — the dirt price has dropped and that is a blow to the country's economy. Everybody knows that Berland is the top world dirt exporter! The President of Berland was forced to leave only *k* of the currently existing *n* subway stations. The subway stations are located on a straight...
{"inputs": ["3\n1 100 101\n2", "5\n11 21 30 40 50\n3", "3\n0 -4 -3\n2", "4\n5 -7 8 1\n2", "5\n-4 -2 10 -9 -10\n2", "6\n9 8 4 -4 -6 -8\n2", "7\n10 -6 0 -5 -2 -8 7\n2", "5\n-10 -5 3 4 -3\n3", "6\n8 -7 1 5 -8 4\n3", "7\n-5 1 3 2 -9 -1 -4\n3", "100\n237 -708 796 -645 75 387 992 343 -219 -696 777 -722 844 -409 6 989 39 -151...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1
codeforces
d5a66051eeab79f22b63335aaf627de6
Pocket Book
One day little Vasya found mom's pocket book. The book had *n* names of her friends and unusually enough, each name was exactly *m* letters long. Let's number the names from 1 to *n* in the order in which they are written. As mom wasn't home, Vasya decided to play with names: he chose three integers *i*, *j*, *k* (1<=...
{"inputs": ["2 3\nAAB\nBAA", "4 5\nABABA\nBCGDG\nAAAAA\nYABSA", "1 1\nE", "2 2\nNS\nPD", "3 4\nPJKD\nNFJX\nFGFK", "4 5\nSXFMY\nATHLM\nKDDQW\nZWGDS", "20 14\nJNFKBBBJYZHWQE\nLBOKZCPFNKDBJY\nXKNWGHQHIOXUPF\nDDNRUKVUGHWMXW\nMTIZFNAAFEAPHX\nIXBQOOHEULZYHU\nMRCSREUEOOMUUN\nHJTSQWKUFYZDQU\nGMCMUZCOPRVEIQ\nXBKKGGJECOBLTH\nXXH...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
184
codeforces
d5a92f290c7eb0059d54b3a0e3c0ae3e
Ilya and Matrix
Ilya is a very good-natured lion. He likes maths. Of all mathematical objects, his favourite one is matrices. Now he's faced a complicated matrix problem he needs to solve. He's got a square 2*n*<=×<=2*n*-sized matrix and 4*n* integers. You need to arrange all these numbers in the matrix (put each number in a single i...
{"inputs": ["1\n13", "4\n1 2 3 4", "16\n978618343 473608041 799158564 800910753 461479363 520477481 780529176 678879534 118274424 720632652 639921017 582019792 143353286 537373229 944668919 758615621", "16\n521848329 105907607 414661942 473600423 264555612 186332345 774233687 736918178 456150336 216550357 568433949 135...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1
codeforces
d5d2dd5f9cafc5c383631833e295d5a4
Pasha and Tea
Pasha decided to invite his friends to a tea party. For that occasion, he has a large teapot with the capacity of *w* milliliters and 2*n* tea cups, each cup is for one of Pasha's friends. The *i*-th cup can hold at most *a**i* milliliters of water. It turned out that among Pasha's friends there are exactly *n* boys a...
{"inputs": ["2 4\n1 1 1 1", "3 18\n4 4 4 2 2 2", "1 5\n2 3", "1 1\n1000000000 1000000000", "4 1000000000\n1 1 1 1 1 1 1 1", "4 1000000000\n1 1 1 1 2 2 2 2", "4 1\n3 3 3 3 4 4 4 4", "2 19\n3 3 5 5", "3 31\n3 3 3 5 5 5", "5 15\n2 3 4 1 2 4 5 3 5 10", "5 14\n2 3 4 1 2 4 5 3 5 10", "5 16\n2 3 4 1 2 4 5 3 5 10", "1 100\n1 2...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
183
codeforces
d607231391bb9d0f6146c5ed8354c0e9
Logical Expression
You are given a boolean function of three variables which is defined by its truth table. You need to find an expression of minimum length that equals to this function. The expression may consist of: - Operation AND ('&amp;', ASCII code 38) - Operation OR ('|', ASCII code 124) - Operation NOT ('!', ASCII code 33) -...
{"inputs": ["4\n00110011\n00000111\n11110000\n00011111", "1\n11001110", "2\n11001110\n01001001", "3\n10001001\n10111011\n10111101", "4\n11000010\n11000010\n11001110\n10001001", "5\n01111000\n00110110\n00011100\n01110111\n01010011"], "outputs": ["y\n(y|z)&x\n!x\nx|y&z", "!y|!z&x", "!y|!z&x\n!(!x&!z|x&z|y)|x&y&z", "!y&!z...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1
codeforces