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
8567369105f3e809e62c03d1c311d0cd
Serial Time!
The Cereal Guy's friend Serial Guy likes to watch soap operas. An episode is about to start, and he hasn't washed his plate yet. But he decided to at least put in under the tap to be filled with water. The plate can be represented by a parallelepiped *k*<=×<=*n*<=×<=*m*, that is, it has *k* layers (the first layer is t...
{"inputs": ["1 1 1\n\n.\n\n1 1", "2 1 1\n\n.\n\n#\n\n1 1", "2 2 2\n\n.#\n##\n\n..\n..\n\n1 1", "3 2 2\n\n#.\n##\n\n#.\n.#\n\n..\n..\n\n1 2", "3 3 3\n\n.#.\n###\n##.\n\n.##\n###\n##.\n\n...\n...\n...\n\n1 1", "2 2 2\n\n#.\n..\n\n.#\n#.\n\n2 1", "4 7 8\n\n........\n........\n........\n........\n........\n........\n.........
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
43
codeforces
85793c04d5569f7c730e40f2446a5307
Writing a Song
One of the Hedgehog and his friend's favorite entertainments is to take some sentence or a song and replace half of the words (sometimes even all of them) with each other's names. The friend's birthday is approaching and the Hedgehog decided to make a special present to his friend: a very long song, where his name wil...
{"inputs": ["5 2\naba\n101", "5 2\na\n10001", "6 2\nabba\n101", "12 5\nabacaba\n010001", "9 3\nac\n10100101", "19 2\naababaaba\n10000100001", "5 2\naaa\n101", "10 2\naaa\n11000111", "15 2\naaa\n0000000000111", "20 2\naba\n001000000000000000", "10 2\naabb\n0000000", "15 2\naabb\n010000000100", "20 2\nabbb\n0000000000010...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1
codeforces
857b3fe7b4bcc1427ca1e7b6f66dfde4
Chilly Willy
Chilly Willy loves playing with numbers. He only knows prime numbers that are digits yet. These numbers are 2, 3, 5 and 7. But Willy grew rather bored of such numbers, so he came up with a few games that were connected with them. Chilly Willy wants to find the minimum number of length *n*, such that it is simultaneous...
{"inputs": ["1", "5", "6", "4", "15", "16", "17", "7", "120", "8", "3", "2", "9", "10", "11", "12", "13", "14", "100000", "99999", "99998", "99997", "99996", "99995", "99994", "99993", "99992", "99991", "99990", "99989", "99988", "99987", "99988", "99987", "99986", "10000", "5000", "5001", "5002", "121", "122", "123", ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
137
codeforces
85b83a877cca38028c1baed68103d7b7
Spongebob and Squares
Spongebob is already tired trying to reason his weird actions and calculations, so he simply asked you to find all pairs of n and m, such that there are exactly *x* distinct squares in the table consisting of *n* rows and *m* columns. For example, in a 3<=×<=5 table there are 15 squares with side one, 8 squares with si...
{"inputs": ["26", "2", "8", "1", "5005", "17284", "151618", "360700", "500500500", "200200", "800800", "200000800200", "999999999999999999", "128593726482159", "50044422", "18", "30", "20", "649708734844", "649030984", "333333333", "5050505060", "1000000000000000000", "18270000000000", "10102030405090000", "50004000222...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
5
codeforces
85c1e0800313be21370c1a51af05aa89
String Problem
Boy Valera likes strings. And even more he likes them, when they are identical. That's why in his spare time Valera plays the following game. He takes any two strings, consisting of lower case Latin letters, and tries to make them identical. According to the game rules, with each move Valera can change one arbitrary ch...
{"inputs": ["uayd\nuxxd\n3\na x 8\nx y 13\nd c 3", "a\nb\n3\na b 2\na b 3\nb a 5", "abc\nab\n6\na b 4\na b 7\nb a 8\nc b 11\nc a 3\na c 0", "xhtuopq\nrtutbz\n10\nh x 10\nx d 3\nr u 4\nu d 1\nt o 100\no t 7\np e 1\ne f 1\nb f 2\nz q 19", "abad\nabad\n6\na c 3\nb x 100\nd e 7\nr r 10\no t 17\na a 4", "bbad\nabxd\n4\nb a ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
3
codeforces
85c72846a552ae1e070a07f77d2c6f4a
Diverse Permutation
Permutation *p* is an ordered set of integers *p*1,<=<=<=*p*2,<=<=<=...,<=<=<=*p**n*, consisting of *n* distinct positive integers not larger than *n*. We'll denote as *n* the length of permutation *p*1,<=<=<=*p*2,<=<=<=...,<=<=<=*p**n*. Your task is to find such permutation *p* of length *n*, that the group of number...
{"inputs": ["3 2", "3 1", "5 2", "5 4", "10 4", "10 3", "10 9", "100000 99999", "99999 99998", "42273 29958", "29857 9843", "27687 4031", "25517 1767", "23347 20494", "10931 8824", "98514 26178", "6591 407", "94174 30132", "92004 85348", "59221 29504", "2 1", "4 1", "4 2", "100000 1", "99999 1", "99998 2", "99999 5000"...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
103
codeforces
85eec64b53510690a189a65c7bf24c65
Pashmak and Flowers
Pashmak decided to give Parmida a pair of flowers from the garden. There are *n* flowers in the garden and the *i*-th of them has a beauty number *b**i*. Parmida is a very strange girl so she doesn't want to have the two most beautiful flowers necessarily. She wants to have those pairs of flowers that their beauty diff...
{"inputs": ["2\n1 2", "3\n1 4 5", "5\n3 1 2 3 1", "2\n1 1", "3\n1 1 1", "4\n1 1 1 1", "5\n1 1 1 1 1", "5\n2 2 2 2 2", "10\n2 2 2 2 2 2 2 2 2 2", "3\n2 2 2", "3\n3 3 3", "2\n10000000 100000000", "5\n5 5 5 5 5", "5\n3 3 3 3 3", "6\n1 1 1 1 1 1", "2\n5 6", "10\n1 1 1 1 1 1 1 1 1 1", "10\n1000000000 1000000000 1000000000 1...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
135
codeforces
85f0c3dca52d0319e2f5851dc7cb4d59
Funny Game
Once upon a time Petya and Gena gathered after another programming competition and decided to play some game. As they consider most modern games to be boring, they always try to invent their own games. They have only stickers and markers, but that won't stop them. The game they came up with has the following rules. In...
{"inputs": ["3\n2 4 8", "4\n1 -7 -2 3", "10\n35 11 35 28 48 25 2 43 23 10", "100\n437 89 481 95 29 326 10 304 97 414 52 46 106 181 385 173 337 148 437 133 52 136 86 250 289 61 480 314 166 69 275 486 117 129 353 412 382 469 290 479 388 231 7 462 247 432 488 146 466 422 369 336 148 460 418 356 303 149 421 146 233 224 432...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
3
codeforces
85fe13c6ddb305a3920fa99f8970df6d
Nearly Lucky Number
Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Unfortunately, not all numbers are lucky. Petya calls a number nearly lucky if the number of lucky d...
{"inputs": ["40047", "7747774", "1000000000000000000", "7", "4", "474404774", "4744000695826", "10000000004744744", "446486416781684178", "999999999", "7777", "87414417444", "111222333444555667", "1", "4700", "3794555488744477", "444444444444444444", "474447447774444774", "777777777777777", "34777745021000000", "963", ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
483
codeforces
8612e0f6e2ddc420a3b9875dd71b5f62
Set Theory
Masha and Grisha like studying sets of positive integers. One day Grisha has written a set *A* containing *n* different integers *a**i* on a blackboard. Now he asks Masha to create a set *B* containing *n* different integers *b**j* such that all *n*2 integers that can be obtained by summing up *a**i* and *b**j* for al...
{"inputs": ["3\n3\n1 10 100\n1\n1\n2\n2 4", "1\n100\n74 14 24 45 22 9 49 78 79 20 60 1 31 91 32 39 90 5 42 57 30 58 64 68 12 11 86 8 3 38 76 17 98 26 85 92 56 65 89 66 36 87 23 67 13 48 15 47 81 73 63 50 34 93 82 44 77 69 96 100 41 19 35 16 88 27 99 40 62 95 70 18 46 21 53 59 37 6 61 71 2 4 52 28 97 25 29 51 7 33 80 83...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
9
codeforces
8613f1b0afa3b8dfd3e8f7af9121480c
National Property
You all know that the Library of Bookland is the largest library in the world. There are dozens of thousands of books in the library. Some long and uninteresting story was removed... The alphabet of Bookland is so large that its letters are denoted by positive integers. Each letter can be small or large, the large ve...
{"inputs": ["4 3\n1 2\n1 1\n3 1 3 2\n2 1 1", "6 5\n2 1 2\n2 1 2\n3 1 2 3\n2 1 5\n2 4 4\n2 4 4", "4 3\n4 3 2 2 1\n3 1 1 3\n3 2 3 3\n2 3 1", "4 4\n3 3 4 1\n4 3 4 2 2\n4 2 1 2 3\n3 4 2 2", "3 5\n2 1 2\n2 1 5\n2 4 4", "2 1\n10 1 1 1 1 1 1 1 1 1 1\n25 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "10 3\n2 3 2\n1 3\n3 ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
3
codeforces
863575ab8345ae9d711a4048f919eb2e
Glass Carving
Leonid wants to become a glass carver (the person who creates beautiful artworks by cutting the glass). He already has a rectangular *w* mm <=×<= *h* mm sheet of glass, a diamond glass cutter and lots of enthusiasm. What he lacks is understanding of what to carve and how. In order not to waste time, he decided to prac...
{"inputs": ["4 3 4\nH 2\nV 2\nV 3\nV 1", "7 6 5\nH 4\nV 3\nV 5\nH 2\nV 1", "2 2 1\nV 1", "2 2 1\nH 1", "2 2 2\nV 1\nH 1", "2 2 2\nH 1\nV 1", "10 10 10\nV 6\nH 8\nV 4\nV 8\nH 2\nH 5\nV 9\nH 7\nH 3\nV 7", "5 15 10\nH 8\nH 9\nV 1\nH 2\nH 6\nH 4\nH 1\nV 2\nH 13\nV 3", "15 5 10\nV 13\nV 10\nV 3\nH 2\nV 9\nV 7\nV 2\nH 1\nV 4...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
4
codeforces
86712ff51baabd9cb0cad3df9de22aca
Arya and Bran
Bran and his older sister Arya are from the same house. Bran like candies so much, so Arya is going to give him some Candies. At first, Arya and Bran have 0 Candies. There are *n* days, at the *i*-th day, Arya finds *a**i* candies in a box, that is given by the Many-Faced God. Every day she can give Bran at most 8 of ...
{"inputs": ["2 3\n1 2", "3 17\n10 10 10", "1 9\n10", "10 70\n6 5 2 3 3 2 1 4 3 2", "20 140\n40 4 81 40 10 54 34 50 84 60 16 1 90 78 38 93 99 60 81 99", "30 133\n3 2 3 4 3 7 4 5 5 6 7 2 1 3 4 6 7 4 6 4 7 5 7 1 3 4 1 6 8 5", "40 320\n70 79 21 64 95 36 63 29 66 89 30 34 100 76 42 12 4 56 80 78 83 1 39 9 34 45 6 71 27 31 5...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
139
codeforces
867538c2ec9791c52fc38b83949d76a7
Berland Bingo
Lately, a national version of a bingo game has become very popular in Berland. There are *n* players playing the game, each player has a card with numbers. The numbers on each card are distinct, but distinct cards can have equal numbers. The card of the *i*-th player contains *m**i* numbers. During the game the host t...
{"inputs": ["3\n1 1\n3 2 4 1\n2 10 11", "2\n1 1\n1 1", "1\n1 1", "2\n1 2\n1 3", "2\n1 1\n2 1 2", "2\n2 1 2\n1 1", "2\n3 5 21 7\n6 15 5 100 21 7 17", "2\n6 15 5 100 21 7 17\n3 5 21 7", "10\n1 4\n1 2\n1 3\n1 5\n1 1\n1 4\n1 3\n1 5\n1 2\n1 1", "3\n1 1\n1 2\n1 1", "10\n3 2 3 4\n1 1\n1 1\n1 2\n1 3\n1 4\n1 1\n1 3\n2 4 5\n2 1 ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
23
codeforces
8676255daaf99564013bbc9970f823f2
Dividing Island
A revolution took place on the Buka Island. New government replaced the old one. The new government includes *n* parties and each of them is entitled to some part of the island according to their contribution to the revolution. However, they can't divide the island. The island can be conventionally represented as two ...
{"inputs": ["3 4 2 2 3\n5 8 3", "3 2 1 4 4\n1 2 3 4", "1 2 1 1 1\n3", "1 2 1 3 2\n3 2", "3 2 4 4 20\n1 2 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "5 4 2 3 26\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "11 5 4 13 5\n18 21 22 23 23", "1 13 1 14 7\n4 5 5 4 4 3 2", "15 1 1 25 6\n3 14 7 7 5 4", "20 30 40 50 1\n2600...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
3
codeforces
86992df511c35724e491b550c53aaae0
Ice cream coloring
Isart and Modsart were trying to solve an interesting problem when suddenly Kasra arrived. Breathless, he asked: "Can you solve a problem I'm stuck at all day?" We have a tree *T* with *n* vertices and *m* types of ice cream numerated from 1 to *m*. Each vertex *i* has a set of *s**i* types of ice cream. Vertices whic...
{"inputs": ["3 3\n1 1\n2 2 3\n1 2\n1 2\n2 3", "4 5\n0\n1 1\n1 3\n3 2 4 5\n2 1\n3 2\n4 3", "7 35\n3 17 20 32\n4 3 14 24 25\n4 4 10 17 26\n7 2 9 13 17 23 28 30\n9 1 2 7 8 13 16 18 33 35\n8 5 6 11 15 17 22 29 34\n5 12 19 21 27 31\n2 1\n3 1\n4 3\n5 4\n6 3\n7 4", "7 39\n7 5 10 15 27 31 33 39\n7 5 16 21 27 28 29 33\n3 15 26 ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1
codeforces
8699b4e498214d26bc63282f383bc860
Game with Tokens
Consider the following game for two players. There is one white token and some number of black tokens. Each token is placed on a plane in a point with integer coordinates *x* and *y*. The players take turn making moves, white starts. On each turn, a player moves all tokens of their color by 1 to up, down, left or righ...
{"inputs": ["4\n-2 -1\n0 1\n0 -3\n2 -1", "4\n-2 0\n-1 1\n0 -2\n1 -1", "16\n2 1\n1 2\n-1 1\n0 1\n0 0\n1 1\n2 -1\n2 0\n1 0\n-1 -1\n1 -1\n2 2\n0 -1\n-1 0\n0 2\n-1 2", "1\n1 2", "4\n0 99999\n-99999 0\n99999 0\n0 -99999", "10\n-1 3\n-1 7\n-8 -4\n5 14\n-6 -7\n11 -8\n-11 0\n5 -1\n9 4\n-2 -14", "50\n-15 -80\n-80 21\n90 38\n-10...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1
codeforces
86a3244023545fd311c4e9765040d5ad
Case of Fugitive
Andrewid the Android is a galaxy-famous detective. He is now chasing a criminal hiding on the planet Oxa-5, the planet almost fully covered with water. The only dry land there is an archipelago of *n* narrow islands located in a row. For more comfort let's represent them as non-intersecting segments on a straight line...
{"inputs": ["4 4\n1 4\n7 8\n9 10\n12 14\n4 5 3 8", "2 2\n11 14\n17 18\n2 9", "2 1\n1 1\n1000000000000000000 1000000000000000000\n999999999999999999", "5 10\n1 2\n3 3\n5 7\n11 13\n14 20\n9 10 2 9 10 4 9 9 9 10", "5 9\n1 2\n3 3\n5 7\n11 13\n14 20\n2 3 4 10 6 2 6 9 5", "6 9\n1 4\n10 18\n23 29\n33 43\n46 57\n59 77\n11 32 3...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
3
codeforces
86bbcc5761032fc0723cc9aa7716bfc2
Four Divisors
If an integer *a* is divisible by another integer *b*, then *b* is called the divisor of *a*. For example: 12 has positive 6 divisors. They are 1, 2, 3, 4, 6 and 12. Let’s define a function *D*(*n*) — number of integers between 1 and *n* (inclusive) which has exactly four positive divisors. Between 1 and 10 only the...
{"inputs": ["10", "20", "1", "27", "100", "1000", "10000", "100000", "1000000", "100000000", "1000000000", "10000000000", "100000000000", "353964", "437388", "553516", "636940", "753068", "803788", "24403439", "907519567", "790635695", "968719119", "146802543", "324885967", "448485", "324885968"], "outputs": ["3", "5",...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
3
codeforces
86bc5ff4cc000d8c473eea68cc66405e
Gerald and Path
The main walking trail in Geraldion is absolutely straight, and it passes strictly from the north to the south, it is so long that no one has ever reached its ends in either of the two directions. The Geraldionians love to walk on this path at any time, so the mayor of the city asked the Herald to illuminate this path ...
{"inputs": ["3\n1 1\n2 2\n3 3", "4\n1 2\n3 3\n4 3\n6 2", "5\n3 3\n4 1\n2 2\n0 3\n9 5", "5\n3 3\n4 3\n6 4\n2 3\n1 5", "5\n1 2\n7 5\n9 4\n5 1\n3 5", "5\n7 2\n3 5\n2 4\n8 1\n9 5", "5\n7 1\n5 5\n1 4\n4 4\n2 2", "5\n9 5\n2 4\n3 3\n5 2\n1 1", "3\n0 3\n3 3\n6 3", "3\n0 3\n4 3\n7 3", "10\n78329099 25986078\n9003418 30942874\n3...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
2
codeforces
86ce3ffc590e44c16fbff25c2821701e
A Piece of Cake
How to make a cake you'll never eat. Ingredients. - 2 carrots - 0 calories - 100 g chocolate spread - 1 pack of flour - 1 egg Method. 1. Put calories into the mixing bowl. 1. Take carrots from refrigerator. 1. Chop carrots. 1. Take chocolate spread from refrigerator. 1. Put chocolate spread into the mix...
{"inputs": ["4 1 2 3 4", "4 802 765 992 1", "4 220 380 729 969", "3 887 104 641", "12 378 724 582 387 583 241 294 159 198 653 369 418", "14 36 901 516 623 703 971 304 394 491 525 464 219 183 648", "3 287 979 395", "19 702 667 743 976 908 728 134 106 380 193 214 71 920 114 587 543 817 248 537", "11 739 752 364 649 626 7...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
34
codeforces
86e9c457887ad23b21c89ed45b4524d1
Tetris
You are given a following process. There is a platform with $n$ columns. $1 \times 1$ squares are appearing one after another in some columns on this platform. If there are no squares in the column, a square will occupy the bottom row. Otherwise a square will appear at the top of the highest square of this column. ...
{"inputs": ["3 9\n1 1 2 2 2 3 1 2 3", "1 7\n1 1 1 1 1 1 1", "1 1\n1", "3 5\n1 1 1 2 3", "4 6\n4 4 4 4 4 4", "4 6\n2 3 4 4 4 4", "3 12\n1 1 1 1 2 2 2 2 3 3 3 3", "8 8\n2 2 3 4 5 6 7 8", "100 1\n50", "2 1\n2", "2 1\n1", "2 4\n1 2 1 1", "3 4\n3 2 2 2", "2 2\n2 2", "2 5\n2 1 1 2 1", "15 3\n13 14 15", "4 9\n1 2 3 1 2 3 1 2 ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
225
codeforces
86eadace39c4974d7855296691977d3a
Complete The Graph
ZS the Coder has drawn an undirected graph of *n* vertices numbered from 0 to *n*<=-<=1 and *m* edges between them. Each edge of the graph is weighted, each weight is a positive integer. The next day, ZS the Coder realized that some of the weights were erased! So he wants to reassign positive integer weight to each of...
{"inputs": ["5 5 13 0 4\n0 1 5\n2 1 2\n3 2 3\n1 4 0\n4 3 4", "2 1 123456789 0 1\n0 1 0", "2 1 999999999 1 0\n0 1 1000000000", "4 5 10 1 2\n0 1 3\n1 2 0\n1 3 4\n2 3 4\n2 0 6", "100 1 123456 99 0\n0 99 123456", "1000 1 5 999 0\n0 999 0", "1000 1 1000000000 998 0\n0 999 0", "4 4 14 1 3\n1 3 13\n2 3 0\n2 0 0\n1 0 12", "4 4...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
6
codeforces
86f346636148be5c88089eb977a30d94
Sum of Digits
Having watched the last Harry Potter film, little Gerald also decided to practice magic. He found in his father's magical book a spell that turns any number in the sum of its digits. At the moment Gerald learned that, he came across a number *n*. How many times can Gerald put a spell on it until the number becomes one-...
{"inputs": ["0", "10", "991", "99", "100", "123456789", "32", "86", "2", "8", "34", "13", "28", "23", "57", "29", "353869285", "549548646", "858893424", "644818852", "360322525", "122937520", "288403032", "677257481", "58059561", "211288847", "339900034079539584", "784084029310269952", "774730557264864000", "4782338071...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
734
codeforces
870be526ad4079cf2e6c4b1dc17092df
Reconnaissance
According to the regulations of Berland's army, a reconnaissance unit should consist of exactly two soldiers. Since these two soldiers shouldn't differ much, their heights can differ by at most *d* centimeters. Captain Bob has *n* soldiers in his detachment. Their heights are *a*1,<=*a*2,<=...,<=*a**n* centimeters. Som...
{"inputs": ["5 10\n10 20 50 60 65", "5 1\n55 30 29 31 55", "6 10\n4 6 4 1 9 3", "7 100\n19 1694 261 162 1 234 513", "8 42\n37 53 74 187 568 22 5 65", "10 4\n11 6 76 49 28 20 57 152 5 32", "100 100\n51 93 101 960 2 477 213 129 663 925 254 78 1486 274 160 481 132 156 412 372 5 57 152 298 1771 7 359 468 254 406 202 929 22...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
264
codeforces
87448a33bcad98078c557bcb497905c7
Infinite Sequence
Consider the infinite sequence of integers: 1,<=1,<=2,<=1,<=2,<=3,<=1,<=2,<=3,<=4,<=1,<=2,<=3,<=4,<=5.... The sequence is built in the following way: at first the number 1 is written out, then the numbers from 1 to 2, then the numbers from 1 to 3, then the numbers from 1 to 4 and so on. Note that the sequence contains ...
{"inputs": ["3", "5", "10", "55", "56", "1000000000000", "847194127849", "294719472984", "999999911791", "999999911792", "100000000000000", "1", "99993", "99994", "99995", "99990", "2", "99991", "99992", "99996", "99997", "99998", "99999", "1021", "4", "23", "9994", "99939", "99999998250180", "6", "8", "35", "100", "10...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
164
codeforces
87666ee7bb3f34a6210d448d76e7181e
Preorder Test
For his computer science class, Jacob builds a model tree with sticks and balls containing *n* nodes in the shape of a tree. Jacob has spent *a**i* minutes building the *i*-th ball in the tree. Jacob's teacher will evaluate his model and grade Jacob based on the effort he has put in. However, she does not have enough ...
{"inputs": ["5 3\n3 6 1 4 2\n1 2\n2 4\n2 5\n1 3", "4 2\n1 5 5 5\n1 2\n1 3\n1 4", "2 1\n1 100000\n2 1", "2 2\n1 1000000\n1 2", "10 4\n104325 153357 265088 777795 337716 557321 702646 734430 464449 744072\n9 4\n8 1\n10 7\n8 6\n7 9\n8 2\n3 5\n8 3\n10 8", "10 3\n703660 186846 317819 628672 74457 58472 247014 480113 252764 ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1
codeforces
8790f27d226d7ec0ce3b1e544a70f2fc
Xor-MST
You are given a complete undirected graph with *n* vertices. A number *a**i* is assigned to each vertex, and the weight of an edge between vertices *i* and *j* is equal to *a**i*<=*xor*<=*a**j*. Calculate the weight of the minimum spanning tree in this graph. The first line contains *n* (1<=≤<=*n*<=≤<=200000) — the nu...
{"inputs": ["5\n1 2 3 4 5", "4\n1 2 3 4", "1\n1"], "outputs": ["8", "8", "0"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1
codeforces
8795970e6387f383db66fbe5d5eb72ad
Candy Boxes
There is an old tradition of keeping 4 boxes of candies in the house in Cyberland. The numbers of candies are special if their arithmetic mean, their median and their range are all equal. By definition, for a set {*x*1,<=*x*2,<=*x*3,<=*x*4} (*x*1<=≤<=*x*2<=≤<=*x*3<=≤<=*x*4) arithmetic mean is , median is and range is ...
{"inputs": ["2\n1\n1", "3\n1\n1\n1", "4\n1\n2\n2\n3", "0", "1\n125", "2\n472\n107", "3\n215\n137\n256", "4\n49\n464\n28\n118", "4\n172\n84\n252\n163", "2\n66\n135", "1\n190", "3\n184\n100\n71", "3\n361\n387\n130", "3\n146\n247\n182", "3\n132\n44\n126", "2\n172\n148", "3\n276\n311\n442", "3\n324\n301\n131", "4\n186\n129...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
11
codeforces
87a54f067b31ebfad0da83002caa68eb
Colorful Graph
You've got an undirected graph, consisting of *n* vertices and *m* edges. We will consider the graph's vertices numbered with integers from 1 to *n*. Each vertex of the graph has a color. The color of the *i*-th vertex is an integer *c**i*. Let's consider all vertices of the graph, that are painted some color *k*. Let...
{"inputs": ["6 6\n1 1 2 3 5 8\n1 2\n3 2\n1 4\n4 3\n4 5\n4 6", "5 6\n4 2 5 2 4\n1 2\n2 3\n3 1\n5 3\n5 4\n3 4", "3 1\n13 13 4\n1 2", "2 1\n500 300\n1 2", "6 5\n2 2 2 1 2 2\n4 5\n4 2\n5 2\n4 1\n2 3", "8 8\n3 3 2 3 3 3 1 3\n8 2\n6 3\n2 3\n2 6\n5 6\n4 2\n7 5\n1 6", "10 27\n1 1 3 2 4 1 3 2 4 1\n9 3\n7 8\n9 7\n6 5\n7 6\n7 4\n...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
16
codeforces
87b26ff597826f7c8a05c6ccd32d831d
Parallel Programming
Polycarpus has a computer with *n* processors. Also, his computer has *n* memory cells. We'll consider the processors numbered by integers from 1 to *n* and that the memory cells are consecutively numbered by integers from 1 to *n*. Polycarpus needs to come up with a parallel program model. For each memory cell number...
{"inputs": ["1 1", "3 2", "4 2", "2 1", "2 20", "1 20", "10000 20", "10 4", "10 5", "10 6", "128 7", "127 7", "129 8", "130 8", "131 8", "1024 10", "1024 11", "1023 10", "10000 14", "8192 13", "8190 13", "8192 14", "8123 13", "5000 13", "2000 11", "2198 14", "2512 12"], "outputs": ["1", "2 3 3\n3 3 3", "2 3 4 4\n3 4 4 ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
2
codeforces
87bd4ba8f7cee70856277e730dc4dac4
Lucky Numbers (easy)
Petya loves lucky numbers. Everybody knows that positive integers are lucky if their decimal representation doesn't contain digits other than 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Lucky number is super lucky if it's decimal representation contains equal amount of digits 4 and 7. Fo...
{"inputs": ["4500", "47", "1", "12", "4587", "100", "1007", "99999999", "491020945", "1000000000", "777777", "99999999", "474", "85469", "7474747", "2145226", "5556585", "87584777", "77777777", "999999999", "74477744", "444444444", "467549754", "147474747", "555", "100000", "74777443", "4700007", "70070077", "123", "74...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
18
codeforces
87cd06539720d164c8bb461f4a43badf
Olympiad in Programming and Sports
There are *n* students at Berland State University. Every student has two skills, each measured as a number: *a**i* — the programming skill and *b**i* — the sports skill. It is announced that an Olympiad in programming and sports will be held soon. That's why Berland State University should choose two teams: one to ta...
{"inputs": ["5 2 2\n1 3 4 5 2\n5 3 2 1 4", "4 2 2\n10 8 8 3\n10 7 9 4", "5 3 1\n5 2 5 1 7\n6 3 1 6 3", "2 1 1\n100 101\n1 100", "4 1 1\n100 100 1 50\n100 100 50 1", "2 1 1\n3 2\n3 2", "2 1 1\n9 6\n3 10", "2 1 1\n1 17\n5 20", "3 1 1\n5 4 2\n1 5 2", "3 1 1\n10 5 5\n9 1 4", "3 1 1\n17 6 2\n2 19 19", "4 1 2\n4 2 4 5\n3 2 5...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1
codeforces
87f45615ea3832b39e3e4fb9c33c420c
Vitaly and Cycle
After Vitaly was expelled from the university, he became interested in the graph theory. Vitaly especially liked the cycles of an odd length in which each vertex occurs at most once. Vitaly was wondering how to solve the following problem. You are given an undirected graph consisting of *n* vertices and *m* edges, no...
{"inputs": ["4 4\n1 2\n1 3\n4 2\n4 3", "3 3\n1 2\n2 3\n3 1", "3 0", "6 3\n1 2\n4 3\n6 5", "100000 0", "5 4\n1 2\n1 3\n1 4\n1 5", "6 3\n1 2\n2 3\n4 5", "5 5\n1 2\n2 3\n3 4\n4 5\n5 1", "59139 0", "9859 0", "25987 0", "9411 0", "25539 0", "59139 1\n10301 5892", "9859 1\n1721 9478", "76259 0", "92387 0", "6 4\n1 2\n2 3\n3 ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
4
codeforces
87fa1fe92bd779cf0b2298740f0f708c
IQ test
Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — to check his answers, he needs a program that among the given *n* numbers finds one that i...
{"inputs": ["5\n2 4 7 8 10", "4\n1 2 1 1", "3\n1 2 2", "3\n100 99 100", "3\n5 3 2", "4\n43 28 1 91", "4\n75 13 94 77", "4\n97 8 27 3", "10\n95 51 12 91 85 3 1 31 25 7", "20\n88 96 66 51 14 88 2 92 18 72 18 88 20 30 4 82 90 100 24 46", "30\n20 94 56 50 10 98 52 32 14 22 24 60 4 8 98 46 34 68 82 82 98 90 50 20 78 49 52 9...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
3,134
codeforces
87fbfafa354e50b7c4f052a6f1671e69
Kostya the Sculptor
Kostya is a genial sculptor, he has an idea: to carve a marble sculpture in the shape of a sphere. Kostya has a friend Zahar who works at a career. Zahar knows about Kostya's idea and wants to present him a rectangular parallelepiped of marble from which he can carve the sphere. Zahar has *n* stones which are rectang...
{"inputs": ["6\n5 5 5\n3 2 4\n1 4 1\n2 1 3\n3 2 4\n3 3 4", "7\n10 7 8\n5 10 3\n4 2 6\n5 5 5\n10 2 8\n4 2 1\n7 7 7", "1\n1 1 1", "2\n2 3 1\n2 2 3", "1\n1000000000 1000000000 1000000000", "3\n100 100 100\n25 63 11\n63 15 11", "2\n999999999 1000000000 1000000000\n1000000000 1000000000 1000000000", "3\n1 1 2\n1 2 2\n1 1 1"...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
23
codeforces
880524f2cab75c03474a3bd4b45b4390
Months and Years
Everybody in Russia uses Gregorian calendar. In this calendar there are 31 days in January, 28 or 29 days in February (depending on whether the year is leap or not), 31 days in March, 30 days in April, 31 days in May, 30 in June, 31 in July, 31 in August, 30 in September, 31 in October, 30 in November, 31 in December. ...
{"inputs": ["4\n31 31 30 31", "2\n30 30", "5\n29 31 30 31 30", "3\n31 28 30", "3\n31 31 28", "24\n29 28 31 30 31 30 31 31 30 31 30 31 31 29 31 30 31 30 31 31 30 31 30 31", "4\n31 29 31 30", "24\n31 28 31 30 31 30 31 31 30 31 30 31 31 29 31 30 31 30 31 31 30 31 30 31", "8\n31 29 31 30 31 30 31 31", "1\n29", "8\n31 29 31...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
94
codeforces
88133b86e2c023a0f6539769a94a9b40
Nastya and an Array
Nastya owns too many arrays now, so she wants to delete the least important of them. However, she discovered that this array is magic! Nastya now knows that the array has the following properties: - In one second we can add an arbitrary (possibly negative) integer to all elements of the array that are not equal to ze...
{"inputs": ["5\n1 1 1 1 1", "3\n2 0 -1", "4\n5 -6 -5 1", "1\n0", "2\n21794 -79194", "3\n-63526 95085 -5239", "3\n0 53372 -20572", "13\n-2075 -32242 27034 -37618 -96962 82203 64846 48249 -71761 28908 -21222 -61370 46899", "5\n806 0 1308 1954 683", "8\n-26 0 -249 -289 -126 -206 288 -11", "10\n2 2 2 1 2 -1 0 2 -1 1", "1\n...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
398
codeforces
881a96925d078b4a047e5ae1de94811c
Tennis Tournament
A tennis tournament with *n* participants is running. The participants are playing by an olympic system, so the winners move on and the losers drop out. The tournament takes place in the following way (below, *m* is the number of the participants of the current round): - let *k* be the maximal power of the number 2 ...
{"inputs": ["5 2 3", "8 2 4", "10 1 500", "20 500 1", "100 123 99", "500 1 1", "500 500 500", "500 237 474", "1 2 3", "1 2 133", "1 2 100", "1 3 4", "1 10 15", "1 1 1", "1 2 5", "1 500 500", "1 3 8", "10 10 10", "1 3 5", "1 2 1", "1 2 4", "1 10 10", "1 345 345", "7 12 13", "1 500 1", "1 12 13", "1 500 499", "1 100 90",...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
206
codeforces
881c7f55aadf15000b9369d6a844f275
Special Offer! Super Price 999 Bourles!
Polycarpus is an amateur businessman. Recently he was surprised to find out that the market for paper scissors is completely free! Without further ado, Polycarpus decided to start producing and selling such scissors. Polycaprus calculated that the optimal celling price for such scissors would be *p* bourles. However, ...
{"inputs": ["1029 102", "27191 17", "1 0", "9 0", "20 1", "100 23", "10281 1", "2111 21", "3021 112", "1000000000000000000 999999999999999999", "29287101 301", "302918113 8113", "23483247283432 47283432", "47283432 7283432", "7283432 7283431", "2304324853947 5853947", "2485348653485 123483", "29845435345 34543", "23487...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
25
codeforces
88266cf22d8ea93df609d6d5f1431549
Hyperdrive
In a far away galaxy there are *n* inhabited planets, numbered with numbers from 1 to *n*. They are located at large distances from each other, that's why the communication between them was very difficult until on the planet number 1 a hyperdrive was invented. As soon as this significant event took place, *n*<=-<=1 spa...
{"inputs": ["4\n0 0 0\n0 0 1\n0 1 0\n1 0 0", "3\n5 -5 4\n-5 -4 2\n-1 1 2", "3\n28 -69 72\n-36 9 -49\n94 83 95", "4\n-7 -72 93\n-40 42 49\n31 76 -36\n-56 12 -1", "5\n94 1 26\n-88 -26 32\n-32 -82 84\n22 -2 85\n-40 21 7", "10\n-3461 4259 -7268\n9964 2370 6622\n4530 5607 -6609\n-3777 4888 6057\n-5403 7982 -651\n4828 -6712 ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
3
codeforces
8843d9cd7c335b57fabb3ef78d487be8
Computer Game
Vasya’s elder brother Petya loves playing computer games. In one of his favourite computer games Petya reached the final level where a fight with the boss take place. While playing the game Petya found spell scrolls and now he is about to use them. Let’s describe the way fighting goes on this level: 1) The boss has t...
{"inputs": ["2 10 3\n100 3\n99 1", "2 100 10\n100 11\n90 9", "10 100 5\n61 3\n55 2\n12 6\n39 5\n21 10\n39 7\n16 1\n10 1\n70 5\n100 7", "20 1000 35\n10 6\n66 38\n81 11\n18 46\n80 54\n76 55\n100 7\n96 23\n24 37\n4 24\n4 50\n71 4\n83 15\n7 23\n100 44\n99 34\n100 17\n100 66\n23 15\n90 35", "20 1000 100\n49 26\n46 36\n1 114...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
2
codeforces
88489b3c20b36851c8a0ae9fd612ebab
African Crossword
An African crossword is a rectangular table *n*<=×<=*m* in size. Each cell of the table contains exactly one letter. This table (it is also referred to as grid) contains some encrypted word that needs to be decoded. To solve the crossword you should cross out all repeated letters in rows and columns. In other words, a...
{"inputs": ["3 3\ncba\nbcd\ncbc", "5 5\nfcofd\nooedo\nafaoa\nrdcdf\neofsf", "4 4\nusah\nusha\nhasu\nsuha", "7 5\naabcd\neffgh\niijkk\nlmnoo\npqqrs\nttuvw\nxxyyz", "10 10\naaaaaaaaaa\nbccceeeeee\ncdfffffffe\ncdfiiiiile\ncdfjjjjile\ndddddddile\nedfkkkkile\nedddddddde\ngggggggggg\nhhhhhhhhhe", "15 3\njhg\njkn\njui\nfth\no...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
262
codeforces
884ce38c4e05ce1b7792e50f06613eae
Burning Midnight Oil
One day a highly important task was commissioned to Vasya — writing a program in a night. The program consists of *n* lines of code. Vasya is already exhausted, so he works like that: first he writes *v* lines of code, drinks a cup of tea, then he writes as much as lines, drinks another cup of tea, then he writes lin...
{"inputs": ["7 2", "59 9", "1 9", "11 2", "747 2", "6578 2", "37212 2", "12357 2", "7998332 2", "86275251 2", "75584551 2", "6 3", "43 4", "811 3", "3410 4", "21341 4", "696485 4", "8856748 3", "2959379 4", "831410263 3", "2 5", "19 6", "715 7", "9122 5", "89117 6", "689973 7", "3024524 5", "67127156 6", "412262167 7",...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
171
codeforces
884fb11aa9749ce2a54ec963e9036754
Find a car
After a wonderful evening in the restaurant the time to go home came. Leha as a true gentlemen suggested Noora to give her a lift. Certainly the girl agreed with pleasure. Suddenly one problem appeared: Leha cannot find his car on a huge parking near the restaurant. So he decided to turn to the watchman for help. Form...
{"inputs": ["4\n1 1 1 1 1\n3 2 5 4 5\n1 1 5 5 10000\n1 4 2 5 2", "10\n3 7 4 10 7\n6 1 7 10 18\n9 6 10 8 3\n1 8 3 10 3\n10 4 10 5 19\n8 9 9 10 10\n10 1 10 5 4\n8 1 9 4 18\n6 3 9 5 1\n6 6 9 6 16", "10\n1 1 2 2 8\n3 4 5 9 4\n2 10 5 10 6\n8 5 10 8 8\n1 2 8 2 20\n8 6 10 8 20\n6 7 6 7 9\n8 5 10 10 13\n1 8 10 9 13\n9 8 10 9 3...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1
codeforces
88707b4cec2285331afee820a59c2935
Tennis Championship
Famous Brazil city Rio de Janeiro holds a tennis tournament and Ostap Bender doesn't want to miss this event. There will be *n* players participating, and the tournament will follow knockout rules from the very first game. That means, that if someone loses a game he leaves the tournament immediately. Organizers are st...
{"inputs": ["2", "3", "4", "10", "1000", "2500", "690000", "3000000000", "123456789123456789", "5", "143", "144", "145", "232", "233", "234", "679891637638612257", "679891637638612258", "679891637638612259", "1000000000000000000", "10235439547", "1240723548", "92353046212453", "192403205846532", "13925230525389", "1204...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
107
codeforces
887f5c0fe1611ba2eb173a645088bda2
Vladik and cards
Vladik was bored on his way home and decided to play the following game. He took *n* cards and put them in a row in front of himself. Every card has a positive integer number not exceeding 8 written on it. He decided to find the longest subsequence of cards which satisfies the following conditions: - the number of oc...
{"inputs": ["3\n1 1 1", "8\n8 7 6 5 4 3 2 1", "24\n1 8 1 2 8 2 3 8 3 4 8 4 5 8 5 6 8 6 7 8 7 8 8 8", "1\n8", "2\n5 4", "3\n3 3 2", "18\n3 6 6 8 8 1 1 4 4 3 3 5 5 7 7 2 2 3", "5\n2 6 1 2 6", "6\n4 3 1 6 7 4", "7\n8 8 2 6 1 8 5", "8\n2 8 4 7 5 3 6 1", "8\n8 6 3 6 7 5 5 3", "15\n5 2 2 7 5 2 6 4 3 8 1 8 4 2 7", "15\n8 8 1 ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1
codeforces
88833c580e1089eeff007f19c143dece
Pencils and Boxes
Mishka received a gift of multicolored pencils for his birthday! Unfortunately he lives in a monochrome world, where everything is of the same color and only saturation differs. This pack can be represented as a sequence *a*1,<=*a*2,<=...,<=*a**n* of *n* integer numbers — saturation of the color of each pencil. Now Mis...
{"inputs": ["6 3 10\n7 2 7 7 4 2", "6 2 3\n4 5 3 13 4 10", "3 2 5\n10 16 22", "8 7 13\n52 85 14 52 92 33 80 85", "6 4 0\n1 3 2 4 2 1", "10 4 9\n47 53 33 48 35 51 18 47 33 11", "3 2 76\n44 5 93", "5 2 9\n3 8 9 14 20", "8 2 3\n1 2 3 4 10 11 12 13", "10 3 3\n1 1 2 4 5 6 9 10 11 12", "7 3 3\n1 1 3 4 4 4 7", "8 3 6\n1 2 3 3...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
10
codeforces
888e5c0f86ce38c7eb6f2a5f40de8280
Sereja and Swaps
As usual, Sereja has array *a*, its elements are integers: *a*[1],<=*a*[2],<=...,<=*a*[*n*]. Let's introduce notation: A swap operation is the following sequence of actions: - choose two indexes *i*,<=*j* (*i*<=≠<=*j*); - perform assignments *tmp*<==<=*a*[*i*],<=*a*[*i*]<==<=*a*[*j*],<=*a*[*j*]<==<=*tmp*. What max...
{"inputs": ["10 2\n10 -1 2 2 2 2 2 2 -1 10", "5 10\n-1 -1 -1 -1 -1", "18 1\n166 788 276 -103 -491 195 -960 389 376 369 630 285 3 575 315 -987 820 466", "29 6\n-21 486 -630 -433 -123 -387 618 110 -203 55 -123 524 -168 662 432 378 -155 -136 -162 811 457 -157 -215 861 -565 -506 557 348 -7", "9 9\n-767 148 -323 -818 41 -22...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
19
codeforces
8890a94989620c9df947b82ca957f018
Perfect Squares
Given an array *a*1,<=*a*2,<=...,<=*a**n* of *n* integers, find the largest number in the array that is not a perfect square. A number *x* is said to be a perfect square if there exists an integer *y* such that *x*<==<=*y*2. The first line contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of elements in ...
{"inputs": ["2\n4 2", "8\n1 2 4 8 16 32 64 576", "3\n-1 -4 -9", "5\n918375 169764 598796 76602 538757", "5\n804610 765625 2916 381050 93025", "5\n984065 842724 127449 525625 573049", "2\n226505 477482", "2\n370881 659345", "2\n4 5", "2\n3 4", "2\n999999 1000000", "3\n-1 -2 -3", "2\n-1000000 1000000", "2\n-1 0", "1\n2",...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
90
codeforces
8891a9d7e5544bb50fc3a3842c39a9cf
Zero-One
Little Petya very much likes playing with little Masha. Recently he has received a game called "Zero-One" as a gift from his mother. Petya immediately offered Masha to play the game with him. Before the very beginning of the game several cards are lain out on a table in one line from the left to the right. Each card c...
{"inputs": ["????", "1010", "1?1", "111?", "000?", "1??1?", "?111111?00?", "??????????0????????????????0000000000000", "1?1?1?1?0?10", "?0101", "??0101", "??1010", "00", "11", "1110110101111111001111111110111011100001110111011001011111111111011010011111?111111?011111110001010110011111010111100111?111101010011101010?011...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
2
codeforces
889f498ec3484cf118ca64ffd0df42d2
Balanced Substring
You are given a string *s* consisting only of characters 0 and 1. A substring [*l*,<=*r*] of *s* is a string *s**l**s**l*<=+<=1*s**l*<=+<=2... *s**r*, and its length equals to *r*<=-<=*l*<=+<=1. A substring is called balanced if the number of zeroes (0) equals to the number of ones in this substring. You have to deter...
{"inputs": ["8\n11010111", "3\n111", "11\n00001000100", "10\n0100000000", "13\n0001000011010", "14\n00000100101011", "14\n01111101111111", "18\n110010101101111111", "11\n00010000011", "10\n1000010110", "15\n100000100000011", "18\n011010101110111101", "10\n0011011111", "3\n011", "14\n11111111111111", "65\n11001000110001...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
139
codeforces
88a4ecba4c2e6aa84406f8ca64e0117c
Help King
This is the modification of the problem used during the official round. Unfortunately, author's solution of the original problem appeared wrong, so the problem was changed specially for the archive. Once upon a time in a far away kingdom lived the King. The King had a beautiful daughter, Victoria. They lived happily, ...
{"inputs": ["2", "3", "4", "8", "7", "6", "1", "5", "96", "54", "49", "57", "21", "43", "56", "46", "91", "13", "82", "69", "77", "27", "63", "60", "42", "29", "99", "19", "89", "356", "377", "376", "199", "563", "768", "777", "721", "629", "589", "698", "897", "100", "898", "778", "408", "915", "659", "380", "826", "5...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
9
codeforces
88a9414a5b52e94c5b877e3e07e40bc0
Award Ceremony
All-Berland programming contest comes to an end. In total, *n* teams participated in it. Like in ACM-ICPC, current results stopped refreshing one hour before the contest ends. So at the Award Ceremony, results are partially known. For each team the value *a**i* is given — the number of points the *i*-th team has earned...
{"inputs": ["4\n17 -14\n52 -5\n1 52\n6 0", "5\n4 5\n3 2\n5 -3\n6 -2\n4 3", "3\n2 1\n1 -1\n1 2", "5\n4 1\n5 4\n3 5\n4 5\n5 2", "10\n3 3\n1 1\n1 2\n2 2\n3 4\n3 2\n4 3\n2 2\n2 2\n1 2", "20\n5 4\n1 5\n5 4\n4 5\n4 5\n1 1\n5 3\n3 3\n4 5\n1 4\n5 2\n4 2\n4 4\n5 1\n1 1\n5 3\n2 4\n2 4\n1 2\n2 3", "40\n5 4\n1 4\n5 1\n3 4\n1 4\n5 ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1
codeforces
88c00f744c62257aff2d2df925559c97
Blinds
The blinds are known to consist of opaque horizontal stripes that can be rotated thus regulating the amount of light flowing in the room. There are *n* blind stripes with the width of 1 in the factory warehouse for blind production. The problem is that all of them are spare details from different orders, that is, they ...
{"inputs": ["4 2\n1 2 3 4", "5 3\n5 5 7 3 1", "2 3\n1 2", "2 2\n3 3", "5 2\n2 4 1 1 3", "7 4\n3 2 1 1 1 3 2", "10 1\n1 2 2 6 6 1 2 5 5 6", "10 2\n6 3 1 1 6 4 6 1 6 3", "15 6\n1 6 6 5 2 10 4 4 7 8 7 3 5 1 2", "20 2\n13 3 6 11 6 11 9 1 1 2 5 2 9 15 14 10 3 12 3 13", "25 20\n10 8 4 6 12 14 19 18 19 9 21 16 16 15 10 15 12 ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
34
codeforces
88d941a8d49063c57c8e264ff7932a42
Polycarp's Practice
Polycarp is practicing his problem solving skill. He has a list of $n$ problems with difficulties $a_1, a_2, \dots, a_n$, respectively. His plan is to practice for exactly $k$ days. Each day he has to solve at least one problem from his list. Polycarp solves the problems in the order they are given in his list, he cann...
{"inputs": ["8 3\n5 4 2 6 5 1 9 2", "5 1\n1 1 1 1 1", "4 2\n1 2000 2000 2", "1 1\n2000", "1 1\n1234", "3 2\n1 1 1", "4 2\n3 5 1 1", "5 3\n5 5 6 7 1", "6 4\n1 1 1 1 2 2", "5 3\n5 5 6 6 4", "16 15\n14 4 9 12 17 1 1 8 12 13 6 9 17 2 18 12", "1 1\n1996", "5 3\n5 5 5 9 10", "18 15\n18 2 13 1 18 3 2 18 18 20 9 2 20 20 4 20 9...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
86
codeforces
88f39d68bb4b079df4d1512539367c6f
Practice
Little time is left before Berland annual football championship. Therefore the coach of team "Losewille Rangers" decided to resume the practice, that were indefinitely interrupted for uncertain reasons. Overall there are *n* players in "Losewille Rangers". Each player on the team has a number — a unique integer from 1 ...
{"inputs": ["2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "13", "15", "16", "18", "20", "100", "110", "120", "140", "157", "171", "199", "200", "213", "231", "240", "250", "253", "260", "270", "271", "277", "280", "290", "300", "700", "730", "766", "777", "800", "832", "855", "869", "888", "900", "914", "930", "9...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
4
codeforces
88f417c9a8ac80f7a8d7bd045bd77bc2
Lucky Sorting
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 got an array consisting of *n* numbers, it is the gift for his birthday. Now he wants to sort ...
{"inputs": ["2\n4 7", "3\n4 2 1", "7\n77 66 55 44 33 22 11", "7\n1 2 3 4 5 6 7", "4\n47 1 7 2", "10\n8 4 7 5 9 5 8 5 10 1000", "3\n3 2 1", "1\n9", "5\n4 7 47 744 1", "7\n4 4 4 4 7 7 7", "3\n1 100 4777", "10\n1 8 4 9 5 9 5 8 55 777777", "20\n20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1", "20\n5 45 8 9 4 8 7 4 5 8 ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
2
codeforces
890dc69313bd417ff2d70cfa1ba21d98
Analyzing Polyline
As Valeric and Valerko were watching one of the last Euro Championship games in a sports bar, they broke a mug. Of course, the guys paid for it but the barman said that he will let them watch football in his bar only if they help his son complete a programming task. The task goes like that. Let's consider a set of fun...
{"inputs": ["1\n1 0", "3\n1 0\n0 2\n-1 1", "3\n-2 -4\n1 7\n-5 1", "10\n9 9\n-5 2\n-2 9\n0 6\n6 7\n-1 -10\n-8 6\n3 6\n-3 -9\n0 4", "10\n-4 -9\n5 9\n-4 -1\n6 -1\n-10 -10\n3 4\n3 5\n3 10\n9 7\n4 -7", "5\n3 3\n2 2\n2 -3\n-3 3\n-1 1", "4\n0 2\n-1 -2\n1 0\n-2 2", "10\n-1 2\n0 1\n-2 0\n1 1\n-1 -1\n-2 1\n-2 2\n2 -1\n0 -1\n-1 0...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
4
codeforces
8916d23cafaf87358fda6c265d1c3240
Maximum path
You are given a rectangular table 3<=×<=*n*. Each cell contains an integer. You can move from one cell to another if they share a side. Find such path from the upper left cell to the bottom right cell of the table that doesn't visit any of the cells twice, and the sum of numbers written in the cells of this path is ma...
{"inputs": ["3\n1 1 1\n1 -1 1\n1 1 1", "5\n10 10 10 -1 -1\n-1 10 10 10 10\n-1 10 10 10 10", "15\n-87 -91 31 63 91 35 -14 51 20 20 -20 -94 -59 77 76\n11 81 22 -29 91 -26 -10 -12 46 10 100 88 14 64 41\n26 -31 99 -39 -30 30 28 74 -7 21 2 32 -60 -74 46", "20\n16 82 25 21 -60 9 29 -55 70 54 -50 10 -19 40 46 41 31 -66 1 85\n...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
3
codeforces
8945042f2c8d6960cb0d9cc6116dc3de
Skills
Lesha plays the recently published new version of the legendary game hacknet. In this version character skill mechanism was introduced. Now, each player character has exactly *n* skills. Each skill is represented by a non-negative integer *a**i* — the current skill level. All skills have the same maximum level *A*. Al...
{"inputs": ["3 5 10 1 5\n1 3 1", "3 5 10 1 339\n1 3 1", "2 6 0 1 4\n5 1", "1 1000000000 1000 1000 1000000000000000\n0", "1 100 1 2 30\n1", "1 100 1 2 30\n71", "1 1000000000 1000 1000 1000000000000000\n1000000000", "5 5 10 20 50\n0 0 0 0 0", "5 5 10 20 50\n3 3 3 3 3", "4 5 3 7 15\n4 3 3 1", "3 6 4 6 8\n6 4 5"], "outputs...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
4
codeforces
89491360e66f8310e95485370a17fd93
none
You are given several queries. In the *i*-th query you are given a single positive integer *n**i*. You are to represent *n**i* as a sum of maximum possible number of composite summands and print this maximum number, or print -1, if there are no such splittings. An integer greater than 1 is composite, if it is not prim...
{"inputs": ["1\n12", "2\n6\n8", "3\n1\n2\n3", "6\n1\n2\n3\n5\n7\n11", "3\n4\n6\n9", "20\n8\n13\n20\n12\n9\n16\n4\n19\n7\n15\n10\n6\n14\n11\n3\n2\n5\n17\n18\n1", "100\n611\n513\n544\n463\n38\n778\n347\n317\n848\n664\n382\n108\n718\n33\n334\n876\n234\n22\n944\n305\n159\n245\n513\n691\n639\n135\n308\n324\n813\n459\n304\n1...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
127
codeforces
895d55b60d3cf7fbe8a8d7aee6e5bf90
Tourist Problem
Iahub is a big fan of tourists. He wants to become a tourist himself, so he planned a trip. There are *n* destinations on a straight road that Iahub wants to visit. Iahub starts the excursion from kilometer 0. The *n* destinations are described by a non-negative integers sequence *a*1, *a*2, ..., *a**n*. The number *a*...
{"inputs": ["3\n2 3 5", "4\n1 5 77 2", "5\n3 3842 288 199 334", "7\n1 2 3 40 52 33 86", "7\n1 10 100 1000 10000 1000000 10000000", "6\n3835302 971984 8706888 1080445 2224695 1093317", "40\n8995197 7520501 942559 8012058 3749344 3471059 9817796 3187774 4735591 6477783 7024598 3155420 6039802 2879311 2738670 5930138 4604...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
35
codeforces
896e4fa6c27d59192730b1a332916bbd
Center Alignment
Almost every text editor has a built-in function of center text alignment. The developers of the popular in Berland text editor «Textpad» decided to introduce this functionality into the fourth release of the product. You are to implement the alignment in the shortest possible time. Good luck! The input file consists ...
{"inputs": ["This is\n\nCodeforces\nBeta\nRound\n5", "welcome to the\nCodeforces\nBeta\nRound 5\n\nand\ngood luck", "0\n2", "O\no\nd", "0v uO M6Sy", "fm v\nOL U W", "vb\nJ\nyU\nZ", "N\nSV\nEh\n6f\nX6\n9e", "Pj\nA\nFA\nP\nVJ\nU\nEb\nW", "T\n7j\nS\nb\nq8\nVZ\nn\n4T\niZ\npA", "8\n\n\n\ny\nW\n\n\n\n3B\n\nw\nV\n\n\n\nL\...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
104
codeforces
898bd3d15572e3c5b3a6e55eee7cebf1
Minimum Sum
Petya has *n* positive integers *a*1,<=*a*2,<=...,<=*a**n*. His friend Vasya decided to joke and replaced all digits in Petya's numbers with a letters. He used the lowercase letters of the Latin alphabet from 'a' to 'j' and replaced all digits 0 with one letter, all digits 1 with another letter and so on. For any two...
{"inputs": ["3\nab\nde\naj", "5\nabcdef\nghij\nbdef\naccbd\ng", "3\naa\njj\naa", "9\na\nb\nc\nd\nf\ng\nh\ni\nj", "5\nbdgbh\nadi\naa\ngjh\ngh", "6\nchafj\nabhj\nfhe\nhfbd\njifgg\ng", "1\nh", "7\nffh\nfhec\nfbchc\ng\ndfbhi\ncdbdi\ni", "8\ne\nbhbib\nj\ndgb\njjbgb\nei\ndggbdh\nhfbbfj", "10\ncf\ncha\nceiab\ng\naajac\ndj\nhe...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
41
codeforces
898f5cceb39732df2744828494acaa59
Different Subsets For All Tuples
For a sequence *a* of *n* integers between 1 and *m*, inclusive, denote *f*(*a*) as the number of distinct subsequences of *a* (including the empty subsequence). You are given two positive integers *n* and *m*. Let *S* be the set of all sequences of length *n* consisting of numbers from 1 to *m*. Compute the sum *f*(*...
{"inputs": ["1 3", "2 2", "3 3", "1 1000000", "1000000 1", "500 500", "1000000 1000000"], "outputs": ["6", "14", "174", "2000000", "1000001", "383255233", "247171672"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
8
codeforces
899ad686a6f5f7729afbc31a2d42123f
Tree Construction
During the programming classes Vasya was assigned a difficult problem. However, he doesn't know how to code and was unable to find the solution in the Internet, so he asks you to help. You are given a sequence $a$, consisting of $n$ distinct integers, that is used to construct the binary search tree. Below is the form...
{"inputs": ["3\n1 2 3", "5\n4 2 3 1 6", "2\n1 2", "10\n991309218 517452607 870021923 978357992 136426010 10601767 302627526 883615372 163475700 600546765", "2\n656402233 488475947"], "outputs": ["1 2", "4 2 2 4", "1", "991309218 517452607 870021923 517452607 136426010 136426010 978357992 302627526 870021923", "65640223...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
3
codeforces
899dbfc5766d6ae6850a7869f0de87da
Reversing Encryption
A string $s$ of length $n$ can be encrypted by the following algorithm: - iterate over all divisors of $n$ in decreasing order (i.e. from $n$ to $1$), - for each divisor $d$, reverse the substring $s[1 \dots d]$ (i.e. the substring which starts at position $1$ and ends at position $d$). For example, the above algor...
{"inputs": ["10\nrocesfedoc", "16\nplmaetwoxesisiht", "1\nz", "2\nir", "3\nilj", "4\njfyy", "6\nkrdych", "60\nfnebsopcvmlaoecpzmakqigyuutueuozjxutlwwiochekmhjgwxsgfbcrpqj", "64\nhnlzzhrvqnldswxfsrowfhmyzbxtyoxhogudasgywxycyhzgiseerbislcncvnwy", "97\nqnqrmdhmbubaijtwsecbidqouhlecladwgwcuxbigckrfzasnbfbslukoayhcgquuacyga...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
173
codeforces
89c2bcffb56fcdb0dba9ea994e161d20
Color Stripe
A colored stripe is represented by a horizontal row of *n* square cells, each cell is pained one of *k* colors. Your task is to repaint the minimum number of cells so that no two neighbouring cells are of the same color. You can use any color from 1 to *k* to repaint the cells. The first input line contains two integer...
{"inputs": ["6 3\nABBACC", "3 2\nBBB", "1 2\nA", "1 26\nZ", "2 2\nAA", "2 2\nBA", "6 2\nAAABBB", "8 3\nAABBABBB", "10 26\nAAAAAAAAAA", "12 3\nAAABBBAAABBB", "3 2\nAAB", "3 3\nBBA", "3 3\nCCC", "8 3\nAABBCCBB", "200 2\nBABAABBABBABBABABBBABAAABABBABABBBAABBBBABBAABBABABAAAAABAABBBAAAAAAABBBABAAAABABBBAABABAABAABBBAABBAB...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
11
codeforces
89f33e47241992f5c2c6cbeeaf3d4ead
Captain Marmot
Captain Marmot wants to prepare a huge and important battle against his enemy, Captain Snake. For this battle he has *n* regiments, each consisting of 4 moles. Initially, each mole *i* (1<=≤<=*i*<=≤<=4*n*) is placed at some position (*x**i*,<=*y**i*) in the Cartesian plane. Captain Marmot wants to move some moles to m...
{"inputs": ["4\n1 1 0 0\n-1 1 0 0\n-1 1 0 0\n1 -1 0 0\n1 1 0 0\n-2 1 0 0\n-1 1 0 0\n1 -1 0 0\n1 1 0 0\n-1 1 0 0\n-1 1 0 0\n-1 1 0 0\n2 2 0 1\n-1 0 0 -2\n3 0 0 -2\n-1 1 -2 0", "3\n-2248 6528 -2144 6181\n-2245 6663 -2100 7054\n-4378 7068 -4061 7516\n-4274 6026 -3918 5721\n4942 -6793 5014 -6807\n3463 -5170 3112 -5181\n287...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
6
codeforces
8a0c32c216a57e2b1ebcc493f38f1de4
Movie Critics
A film festival is coming up in the city N. The festival will last for exactly *n* days and each day will have a premiere of exactly one film. Each film has a genre — an integer from 1 to *k*. On the *i*-th day the festival will show a movie of genre *a**i*. We know that a movie of each of *k* genres occurs in the fes...
{"inputs": ["10 3\n1 1 2 3 2 3 3 1 1 3", "7 3\n3 1 3 2 3 1 2", "2 2\n1 2", "10 2\n1 2 2 1 1 2 1 1 2 2", "10 10\n5 7 8 2 4 10 1 3 9 6", "100 10\n6 2 8 1 7 1 2 9 2 6 10 4 2 8 7 5 2 9 5 2 3 2 8 3 7 2 4 3 1 8 8 5 7 10 2 1 8 4 1 4 9 4 2 1 9 3 7 2 4 8 4 3 10 3 9 5 7 7 1 2 10 7 7 8 9 7 1 7 4 8 9 4 1 10 2 4 2 10 9 6 10 5 1 4 2...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
12
codeforces
8a19c08339325adedb08655029389065
Robot Bicorn Attack
Vasya plays Robot Bicorn Attack. The game consists of three rounds. For each one a non-negative integer amount of points is given. The result of the game is the sum of obtained points. Vasya has already played three rounds and wrote obtained points one by one (without leading zeros) into the string *s*. Vasya decided ...
{"inputs": ["1234", "9000", "0009", "100000010000001000000", "1000000011", "9991", "1000001999", "100000010000011000000", "100000010000001000001", "102", "100", "000", "001", "090", "999999999999999999999999999999", "12345678901234567", "12635000000127683", "428595000000042345353", "48726340000000", "93246310000000", "...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
24
codeforces
8a2e86e2f136815a2d31168586eb8de7
Roma and Lucky Numbers
Roma (a popular Russian name that means 'Roman') loves the Little Lvov Elephant's lucky numbers. Let us remind you that lucky numbers are positive integers whose decimal representation only contains lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Roma's got *n* positive integer...
{"inputs": ["3 4\n1 2 4", "3 2\n447 44 77", "2 2\n507978501 180480073", "9 6\n655243746 167613748 1470546 57644035 176077477 56984809 44677 215706823 369042089", "6 100\n170427799 37215529 675016434 168544291 683447134 950090227", "4 2\n194041605 706221269 69909135 257655784", "4 2\n9581849 67346651 530497 272158241", ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
500
codeforces
8a318d25c4228c01367164cd22486e42
Minimum spanning tree for each edge
Connected undirected weighted graph without self-loops and multiple edges is given. Graph contains *n* vertices and *m* edges. For each edge (*u*,<=*v*) find the minimal possible weight of the spanning tree that contains the edge (*u*,<=*v*). The weight of the spanning tree is the sum of weights of all edges included...
{"inputs": ["5 7\n1 2 3\n1 3 1\n1 4 5\n2 3 2\n2 5 3\n3 4 2\n4 5 4", "2 1\n1 2 42", "3 3\n1 2 10\n2 3 20\n3 1 40", "4 6\n1 2 999999001\n1 3 999999003\n1 4 999999009\n2 3 999999027\n2 4 999999243\n3 4 999999729", "8 10\n2 5 4\n7 5 2\n7 3 28\n4 5 14\n3 2 15\n1 2 3\n6 2 5\n2 8 17\n4 6 2\n1 4 10", "8 10\n8 7 11\n3 5 23\n2 1...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
2
codeforces
8a39a0fc528e653f23f943f263f57591
Mister B and Boring Game
Sometimes Mister B has free evenings when he doesn't know what to do. Fortunately, Mister B found a new game, where the player can play against aliens. All characters in this game are lowercase English letters. There are two players: Mister B and his competitor. Initially the players have a string *s* consisting of t...
{"inputs": ["1 1 1 8", "4 2 2 6", "3 7 4 6", "4 5 1 1", "12 12 1 1000", "12 1 1000 1000", "3 4 701 703", "12 12 13 1000000000", "3 4 999999999 1000000000", "5 6 1000000000 1000000000", "1 1 1 1", "12 1 100000011 100000024", "10 12 220000011 220000032", "1 1 1 1000000000", "1 1 999999999 1000000000", "1 1 1000000000 100...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1
codeforces
8a3b83bb1a842a33deeaa0d6092acc8f
Vasya and Football
Vasya has started watching football games. He has learned that for some fouls the players receive yellow cards, and for some fouls they receive red cards. A player who receives the second yellow card automatically receives a red card. Vasya is watching a recorded football match now and makes notes of all the fouls tha...
{"inputs": ["MC\nCSKA\n9\n28 a 3 y\n62 h 25 y\n66 h 42 y\n70 h 25 y\n77 a 4 y\n79 a 25 y\n82 h 42 r\n89 h 16 y\n90 a 13 r", "REAL\nBARCA\n3\n27 h 7 y\n44 a 10 y\n87 h 3 r", "MASFF\nSAFBDSRG\n5\n1 h 1 y\n15 h 1 r\n27 a 1 y\n58 a 1 y\n69 h 10 y", "ARMENIA\nBULGARIA\n12\n33 h 17 y\n42 h 21 y\n56 a 17 y\n58 a 6 y\n61 a 7 y...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
48
codeforces
8a91e345120c4e99d41dd166b1ac3025
Gerald and Giant Chess
Giant chess is quite common in Geraldion. We will not delve into the rules of the game, we'll just say that the game takes place on an *h*<=×<=*w* field, and it is painted in two colors, but not like in chess. Almost all cells of the field are white and only some of them are black. Currently Gerald is finishing a game ...
{"inputs": ["3 4 2\n2 2\n2 3", "100 100 3\n15 16\n16 15\n99 88", "1000 1000 4\n50 50\n51 50\n50 51\n51 51", "100000 100000 4\n50001 50001\n50000 50000\n50000 50001\n50001 50000", "2 2 2\n2 1\n1 2", "100 10 30\n40 4\n15 3\n75 3\n88 10\n32 1\n16 5\n81 8\n45 2\n72 8\n11 6\n86 4\n50 2\n9 4\n11 1\n20 3\n47 3\n2 4\n68 3\n90 ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
6
codeforces
8a957f78e0d55fcc24a4b2ca6c9e4fec
Increase Sequence
Peter has a sequence of integers *a*1,<=*a*2,<=...,<=*a**n*. Peter wants all numbers in the sequence to equal *h*. He can perform the operation of "adding one on the segment [*l*,<=*r*]": add one to all elements of the sequence with indices from *l* to *r* (inclusive). At that, Peter never chooses any element as the be...
{"inputs": ["3 2\n1 1 1", "5 1\n1 1 1 1 1", "4 3\n3 2 1 1", "1 2000\n2000", "3 2\n2 1 1", "3 4\n4 3 2", "10 6\n5 4 4 4 5 4 4 4 4 5", "10 6\n5 4 4 4 5 4 4 4 4 5", "7 4\n3 3 4 4 4 3 3", "3 6\n5 6 5", "3 2\n1 0 1", "6 1\n0 1 0 0 0 1", "6 3\n2 1 2 2 1 2", "99 1999\n1999 1998 1997 1996 1995 1994 1993 1992 1991 1990 1989 198...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1
codeforces
8b05508e415ac732ef63660436500b6f
Cannon
Bertown is under siege! The attackers have blocked all the ways out and their cannon is bombarding the city. Fortunately, Berland intelligence managed to intercept the enemies' shooting plan. Let's introduce the Cartesian system of coordinates, the origin of which coincides with the cannon's position, the *Ox* axis is ...
{"inputs": ["2 10\n0.7853\n0.3\n3\n5.0 5.0\n4.0 2.4\n6.0 1.9", "2 10\n0.7853\n0.3\n2\n4.0 2.4\n6.0 1.9", "3 186\n0.4084\n0.4559\n0.1203\n3\n978.8435 234.6507\n343.6961 128.6128\n611.2897 458.9593", "4 851\n0.3178\n0.5635\n0.1335\n0.5107\n4\n685.3785 249.6264\n681.8946 242.4571\n917.2937 600.3285\n150.5685 135.5137", "2...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1
codeforces
8b08ea902b7acfe6c832a6ab2e5cbf65
New York Hotel
Think of New York as a rectangular grid consisting of *N* vertical avenues numerated from 1 to *N* and *M* horizontal streets numerated 1 to *M*. *C* friends are staying at *C* hotels located at some street-avenue crossings. They are going to celebrate birthday of one of them in the one of *H* restaurants also located ...
{"inputs": ["10 10\n2\n1 1\n3 3\n2\n1 10\n4 4", "100 100\n10\n53 20\n97 6\n12 74\n48 92\n97 13\n47 96\n75 32\n69 21\n95 75\n1 54\n10\n36 97\n41 1\n1 87\n39 23\n27 44\n73 97\n1 1\n6 26\n48 3\n5 69", "100 100\n10\n86 72\n25 73\n29 84\n34 33\n29 20\n84 83\n41 80\n22 22\n16 89\n77 49\n1\n4 23", "100 100\n1\n66 77\n10\n70 1...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1
codeforces
8b27e972e3fa26ad5abe3942fc090f84
Permute Digits
You are given two positive integer numbers *a* and *b*. Permute (change order) of the digits of *a* to construct maximal number not exceeding *b*. No number in input and/or output can start with the digit 0. It is allowed to leave *a* as it is. The first line contains integer *a* (1<=≤<=*a*<=≤<=1018). The second line ...
{"inputs": ["123\n222", "3921\n10000", "4940\n5000", "23923472834\n23589234723", "102391019\n491010301", "123456789123456789\n276193619183618162", "1000000000000000000\n1000000000000000000", "1\n1000000000000000000", "999999999999999999\n1000000000000000000", "2475345634895\n3455834583479", "15778899\n98715689", "4555\...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
53
codeforces
8b3fa8eccfdabf8716ba8e9019da55da
none
You are given an array of positive integers *a*1,<=*a*2,<=...,<=*a**n*<=×<=*T* of length *n*<=×<=*T*. We know that for any *i*<=&gt;<=*n* it is true that *a**i*<==<=*a**i*<=-<=*n*. Find the length of the longest non-decreasing sequence of the given array. The first line contains two space-separated integers: *n*, *T* (...
{"inputs": ["4 3\n3 1 4 2", "1 1000\n42", "31 3767\n16 192 152 78 224 202 186 52 118 19 13 38 199 196 35 295 100 64 205 37 166 124 169 214 66 243 134 192 253 270 92", "15 12226\n18 125 213 221 124 147 154 182 134 184 51 49 267 88 251", "81 10683\n3 52 265 294 213 242 185 151 27 165 128 237 124 14 43 147 104 162 124 103...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
5
codeforces
8b4044b6c20a561a758869590fbe0d05
GukiZ and Binary Operations
We all know that GukiZ often plays with arrays. Now he is thinking about this problem: how many arrays *a*, of length *n*, with non-negative elements strictly less then 2*l* meet the following condition: ? Here operation means bitwise AND (in Pascal it is equivalent to and, in C/C++/Java/Python it is equivalent to &...
{"inputs": ["2 1 2 10", "2 1 1 3", "3 3 2 10", "5135 42542 15 4354", "21 21 21 21", "2 0 0 5", "1564 153 12 1000000007", "101 102 13 104", "5 6 29 108", "1000000001 1000000002 37 1000000007", "45305640 6540640606 51 5406546", "68706870687 984089409849 59 156465748", "987408898498 1233432432 15 15", "111111111111 111111...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1
codeforces
8b469bd08bc0cbf4598d9a22785da95f
none
Vasilisa the Wise from a far away kingdom got a present from her friend Helga the Wise from a farther away kingdom. The present is a surprise box, yet Vasilisa the Wise doesn't know yet what the surprise actually is because she cannot open the box. She hopes that you can help her in that. The box's lock is constructed...
{"inputs": ["YYYYYY", "BOOOOB", "ROYGBV", "RRRRRR", "BOOOOO", "GOGGVG", "GRBYVO", "BYOVRR", "VOVRBV", "GVGBVO", "BOBGBB", "OOYYBY", "VVRVVV", "YBBVVY", "GYYGGG", "BRRBRB", "OOOOOO", "OVBRYG", "VOBYGO", "VRRYGR", "VOBVYB", "YYYYRB", "RYYYVV", "YYYYYG", "OBORBR", "RRRGRG", "VYYYVV", "YYYYYY", "YROVBG", "RYGOBG", "BGRGGV"...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
5
codeforces
8b794f61bba5cf73f873c4461a6dc912
Processing Queries
In this problem you have to simulate the workflow of one-thread server. There are *n* queries to process, the *i*-th will be received at moment *t**i* and needs to be processed for *d**i* units of time. All *t**i* are guaranteed to be distinct. When a query appears server may react in three possible ways: 1. If ser...
{"inputs": ["5 1\n2 9\n4 8\n10 9\n15 2\n19 1", "4 1\n2 8\n4 8\n10 9\n15 2", "1 1\n1000000000 1000000000", "4 3\n999999996 1000000000\n999999997 1000000000\n999999998 1000000000\n999999999 1000000000", "5 1\n2 1\n3 6\n4 5\n6 4\n7 2", "10 2\n4 14\n5 2\n6 6\n7 11\n8 6\n9 5\n10 13\n11 8\n13 2\n20 2", "6 4\n2 4\n4 2\n5 2\n6...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
56
codeforces
8b980c9c96fff0ee36b71d033b996015
Lucky Permutation
A permutation *p* of size *n* is the sequence *p*1,<=*p*2,<=...,<=*p**n*, consisting of *n* distinct integers, each of them is from 1 to *n* (1<=≤<=*p**i*<=≤<=*n*). A lucky permutation is such permutation *p*, that any integer *i* (1<=≤<=*i*<=≤<=*n*) meets this condition *p**p**i*<==<=*n*<=-<=*i*<=+<=1. You have inte...
{"inputs": ["1", "2", "4", "5", "3", "100000", "6", "7", "8", "9", "99997", "10000", "10001", "10002", "10003", "10004", "25", "29", "33", "9", "13", "17", "50001", "20001", "30001", "99996", "99999", "101", "505", "565"], "outputs": ["1 ", "-1", "2 4 1 3 ", "2 5 3 1 4 ", "-1", "2 100000 4 99998 6 99996 8 99994 10 9999...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
15
codeforces
8baaa070ecac7d157bd2a81f95a18b77
MUH and Important Things
It's time polar bears Menshykov and Uslada from the zoo of St. Petersburg and elephant Horace from the zoo of Kiev got down to business. In total, there are *n* tasks for the day and each animal should do each of these tasks. For each task, they have evaluated its difficulty. Also animals decided to do the tasks in ord...
{"inputs": ["4\n1 3 3 1", "5\n2 4 1 4 8", "8\n1 5 4 12 7 2 10 11", "6\n5 1 2 5 2 4", "1\n1083", "10\n5 5 5 5 5 5 5 5 5 5", "6\n3 8 3 9 3 10", "19\n895 1302 724 952 340 952 939 1302 724 952 939 340 340 1844 770 976 435 1302 1302", "7\n766 766 1477 766 107 1774 990", "11\n1552 1010 1552 1248 1550 388 1541 1010 613 1821 3...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
50
codeforces
8bb5b84ac8b7a2f06ed0f1e18350f2ef
none
One of Timofey's birthday presents is a colourbook in a shape of an infinite plane. On the plane *n* rectangles with sides parallel to coordinate axes are situated. All sides of the rectangles have odd length. Rectangles cannot intersect, but they can touch each other. Help Timofey to color his rectangles in 4 differe...
{"inputs": ["8\n0 0 5 3\n2 -1 5 0\n-3 -4 2 -1\n-1 -1 2 0\n-3 0 0 5\n5 2 10 3\n7 -3 10 2\n4 -2 7 -1", "1\n0 0 1 1", "4\n0 0 1 1\n1 0 2 1\n1 1 2 2\n0 1 1 2", "3\n0 0 1 3\n1 0 4 1\n1 1 2 2", "6\n0 1 1 4\n0 4 1 7\n1 0 2 3\n1 3 2 4\n1 4 2 5\n2 3 3 4", "25\n0 0 7 7\n0 18 7 29\n7 36 12 41\n7 18 12 29\n15 29 26 36\n7 7 12 18\n...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
24
codeforces
8bbcbb9e2645ba1ed5dd33803c1dee7b
Text Volume
You are given a text of single-space separated words, consisting of small and capital Latin letters. Volume of the word is number of capital letters in the word. Volume of the text is maximum volume of all words in the text. Calculate the volume of the given text. The first line contains one integer number *n* (1<=≤<...
{"inputs": ["7\nNonZERO", "24\nthis is zero answer text", "24\nHarbour Space University", "2\nWM", "200\nLBmJKQLCKUgtTxMoDsEerwvLOXsxASSydOqWyULsRcjMYDWdDCgaDvBfATIWPVSXlbcCLHPYahhxMEYUiaxoCebghJqvmRnaNHYTKLeOiaLDnATPZAOgSNfBzaxLymTGjfzvTegbXsAthTxyDTcmBUkqyGlVGZhoazQzVSoKbTFcCRvYsgSCwjGMxBfWEwMHuagTBxkz", "199\no A r ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
436
codeforces
8be1c3722f69c951ceff8bd6b888d662
80-th Level Archeology
Archeologists have found a secret pass in the dungeon of one of the pyramids of Cycleland. To enter the treasury they have to open an unusual lock on the door. The lock consists of *n* words, each consisting of some hieroglyphs. The wall near the lock has a round switch. Each rotation of this switch changes the hierogl...
{"inputs": ["4 3\n2 3 2\n1 1\n3 2 3 1\n4 2 3 1 2", "2 5\n2 4 2\n2 4 2", "4 4\n1 2\n1 3\n1 4\n1 2", "3 1\n2 1 1\n2 1 1\n3 1 1 1", "2 10\n14 9 6 7 1 6 9 3 1 9 4 6 8 8 1\n3 3 7 6", "5 10\n1 5\n7 5 1 10 5 3 7 10\n1 2\n1 3\n7 4 7 3 9 4 6 1", "50 5\n1 4\n1 4\n1 4\n1 4\n2 4 4\n2 4 5\n2 4 5\n3 4 1 1\n4 4 1 2 5\n7 4 3 2 1 4 4 5...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1
codeforces
8be653bb7d31a6854b649c9565e080e5
April Fools' Problem (easy)
The marmots have prepared a very easy problem for this year's HC2 – this one. It involves numbers *n*, *k* and a sequence of *n* positive integers *a*1,<=*a*2,<=...,<=*a**n*. They also came up with a beautiful and riveting story for the problem statement. It explains what the input means, what the program should output...
{"inputs": ["8 5\n1 1 1 1 1 1 1 1", "10 3\n16 8 2 4 512 256 32 128 64 1", "5 1\n20 10 50 30 46", "6 6\n6 6 6 6 6 6", "1 1\n100", "1 1\n1", "10 5\n147 1917 5539 7159 5763 416 711 1412 6733 4402", "100 60\n1443 3849 6174 8249 696 8715 3461 9159 4468 2496 3044 2301 2437 7559 7235 7956 8959 2036 4399 9595 8664 9743 7688 37...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
44
codeforces
8bf008186e7ef1b9076e19b8f3ab5c1a
Scrambled
Btoh yuo adn yuor roomatme lhoate wianshg disehs, btu stlil sdmoeboy msut peorrfm tihs cohre dialy. Oen dya yuo decdie to idourtcne smoe syestm. Yuor rmmotaoe sstgegus teh fooniwllg dael. Yuo argee on tow arayrs of ientgres M adn R, nmebur upmicnog dyas (induiclng teh cunrret oen) wtih sicsescuve irnegets (teh ceurrnt ...
{"inputs": ["1\n2\n0", "2\n2 3\n1 0", "3\n2 4 4\n0 1 3", "1\n16\n15", "16\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16\n0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15", "16\n5 6 9 13 13 15 9 10 2 6 10 11 12 7 4 8\n4 3 3 5 8 3 6 5 1 4 2 6 7 4 0 1", "8\n15 3 7 11 14 10 16 2\n0 2 1 4 0 0 13 1", "1\n7\n5", "9\n6 12 3 10 15 14 6 9 3\n5 2...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
25
codeforces
8bfbb4d2c2d479b59b4a5cb61941820d
Hide-and-Seek
Victor and Peter are playing hide-and-seek. Peter has hidden, and Victor is to find him. In the room where they are playing, there is only one non-transparent wall and one double-sided mirror. Victor and Peter are points with coordinates (*x**v*,<=*y**v*) and (*x**p*,<=*y**p*) respectively. The wall is a segment joinin...
{"inputs": ["-1 3\n1 3\n0 2 0 4\n0 0 0 1", "0 0\n1 1\n0 1 1 0\n-100 -100 -101 -101", "0 0\n1 1\n0 1 1 0\n-1 1 1 3", "0 0\n10 0\n100 100 101 101\n1 0 3 0", "0 0\n1 1\n100 100 101 101\n-100 -100 -101 -101", "-1 1\n1 1\n0 3 0 4\n0 0 0 2", "0 0\n2 0\n1 1 1 -1\n0 2 1 2", "0 0\n2 0\n1 1 1 -1\n-10 2 -12 2", "0 0\n2 0\n0 2 2 2...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1
codeforces
8c0044cad84ef54874eff46f8f5fe656
Sonya and Matrix
Since Sonya has just learned the basics of matrices, she decided to play with them a little bit. Sonya imagined a new type of matrices that she called rhombic matrices. These matrices have exactly one zero, while all other cells have the Manhattan distance to the cell containing the zero. The cells with equal numbers ...
{"inputs": ["20\n1 0 2 3 5 3 2 1 3 2 3 1 4 2 1 4 2 3 2 4", "18\n2 2 3 2 4 3 3 3 0 2 4 2 1 3 2 1 1 1", "6\n2 1 0 2 1 2", "1\n0", "7\n0 1 2 3 4 2 6", "6\n0 0 0 0 0 0", "4\n0 0 0 0"], "outputs": ["4 5\n2 2", "3 6\n2 3", "-1", "1 1\n1 1", "-1", "-1", "-1"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
2
codeforces
8c3e4d39eb3fa9adae0ac0d73286f72e
none
Oleg writes down the history of the days he lived. For each day he decides if it was good or bad. Oleg calls a non-empty sequence of days a zebra, if it starts with a bad day, ends with a bad day, and good and bad days are alternating in it. Let us denote bad days as 0 and good days as 1. Then, for example, sequences o...
{"inputs": ["0010100", "111", "0", "1", "0101010101", "010100001", "000111000", "0101001000", "0000001000", "0101", "000101110", "010101010", "0101001010", "0100101100", "0110100000", "0000000000", "1111111111", "0010101100", "1010000", "0001110", "00000000000110011000111101010001010000100101110001001101100000110100111...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
19
codeforces
8c4a32fe0eb2f98ede0b2c62a4d73b97
Harmony Analysis
The semester is already ending, so Danil made an effort and decided to visit a lesson on harmony analysis to know how does the professor look like, at least. Danil was very bored on this lesson until the teacher gave the group a simple task: find 4 vectors in 4-dimensional space, such that every coordinate of every vec...
{"inputs": ["2", "1", "3", "0", "4", "5", "6", "7", "8", "9"], "outputs": ["++++\n+*+*\n++**\n+**+", "++\n+*", "++++++++\n+*+*+*+*\n++**++**\n+**++**+\n++++****\n+*+**+*+\n++****++\n+**+*++*", "+", "++++++++++++++++\n+*+*+*+*+*+*+*+*\n++**++**++**++**\n+**++**++**++**+\n++++****++++****\n+*+**+*++*+**+*+\n++****++++***...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
15
codeforces
8c79b8c1ac558a266dbe4c8f55ed51e7
Vasya and Beautiful Arrays
Vasya's got a birthday coming up and his mom decided to give him an array of positive integers *a* of length *n*. Vasya thinks that an array's beauty is the greatest common divisor of all its elements. His mom, of course, wants to give him as beautiful an array as possible (with largest possible beauty). Unfortunately...
{"inputs": ["6 1\n3 6 10 12 13 16", "5 3\n8 21 52 15 77", "13 11\n55 16 26 40 84 80 48 52 25 43 75 21 58", "18 9\n85 29 29 15 17 71 46 69 48 80 44 73 40 55 61 57 22 68", "25 7\n67 18 36 85 64 22 32 66 17 64 66 65 82 36 16 52 19 70 38 51 17 32 85 16 64", "7 1\n12 84 21 60 33 21 45", "1 1\n1", "10 10\n40141 53368 66538 6...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
3
codeforces
8c94a95b56f6f7c5dcc0c59a65f20967
Anton and Chess
Anton likes to play chess. Also, he likes to do programming. That is why he decided to write the program that plays chess. However, he finds the game on 8 to 8 board to too simple, he uses an infinite one instead. The first task he faced is to check whether the king is in check. Anton doesn't know how to implement thi...
{"inputs": ["2\n4 2\nR 1 1\nB 1 5", "2\n4 2\nR 3 3\nB 1 5", "5\n-1 1\nR -10 10\nQ -9 9\nQ -2 -8\nB -6 10\nB -10 1", "20\n-321 454\nQ 967 -89\nR -811 454\nQ -404 454\nR -734 454\nQ -804 454\nQ -316 77\nQ -802 454\nB -499 454\nQ 401 -663\nQ -601 454\nQ -974 454\nB 710 298\nB -917 454\nB -555 -542\nQ -337 950\nR 501 40\nR...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1
codeforces
8c973212d593a4182fe97b22e3f856eb
Olesya and Rodion
Olesya loves numbers consisting of *n* digits, and Rodion only likes numbers that are divisible by *t*. Find some number that satisfies both of them. Your task is: given the *n* and *t* print an integer strictly larger than zero consisting of *n* digits that is divisible by *t*. If such number doesn't exist, print <=-...
{"inputs": ["3 2", "2 2", "4 3", "5 3", "10 7", "2 9", "18 8", "1 5", "1 10", "100 5", "10 2", "18 10", "1 9", "7 6", "4 4", "14 7", "3 8", "1 3", "2 8", "3 8", "4 3", "5 9", "4 8", "3 4", "9 4", "8 10", "1 6", "20 3", "15 10", "31 4", "18 9", "72 4", "76 8", "12 5", "54 5", "96 10", "15 9", "100 2", "99 3", "98 4", "9...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
308
codeforces
8ca09bef1240e1e23975c668191930e4
Headquarters
Sensation, sensation in the two-dimensional kingdom! The police have caught a highly dangerous outlaw, member of the notorious "Pihters" gang. The law department states that the outlaw was driving from the gang's headquarters in his car when he crashed into an ice cream stall. The stall, the car, and the headquarters e...
{"inputs": ["3\nUR\nUL\nULDR", "2\nDR\nDL", "4\nUL\nUR\nDR\nDL", "10\nUL\nUL\nUL\nUL\nUL\nUL\nUL\nUL\nUL\nUL", "6\nUL\nDL\nDL\nUL\nUL\nDL", "1\nUL", "1\nUR", "1\nDR", "1\nDL", "1\nULDR", "2\nUL\nULDR", "4\nULDR\nUR\nULDR\nUR", "10\nUR\nDR\nUL\nDR\nUL\nULDR\nUR\nUL\nULDR\nUL", "4\nUL\nUR\nDR\nDL", "10\nUL\nUR\nUR\nDR\nD...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
4
codeforces