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
1161687473cc8d5e3083ca002aaaffda
Array Queries
*a* is an array of *n* positive integers, all of which are not greater than *n*. You have to process *q* queries to this array. Each query is represented by two numbers *p* and *k*. Several operations are performed in each query; each operation changes *p* to *p*<=+<=*a**p*<=+<=*k*. There operations are applied until ...
{"inputs": ["3\n1 1 1\n3\n1 1\n2 1\n3 1", "10\n3 5 4 3 7 10 6 7 2 3\n10\n4 5\n2 10\n4 6\n9 9\n9 2\n5 1\n6 4\n1 1\n5 6\n6 4", "50\n6 2 5 6 10 2 5 8 9 2 9 5 10 4 3 6 10 6 1 1 3 7 2 1 7 8 5 9 6 2 7 6 1 7 2 10 10 2 4 2 8 4 3 10 7 1 7 8 6 3\n50\n23 8\n12 8\n3 3\n46 3\n21 6\n7 4\n26 4\n12 1\n25 4\n18 7\n29 8\n27 5\n47 1\n50 ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
6
codeforces
116948838e1fa56269475f9485f3b01d
Shake It!
A never-ending, fast-changing and dream-like world unfolds, as the secret door opens. A world is an unordered graph *G*, in whose vertex set *V*(*G*) there are two special vertices *s*(*G*) and *t*(*G*). An initial world has vertex set {*s*(*G*),<=*t*(*G*)} and an edge between them. A total of *n* changes took place ...
{"inputs": ["3 2", "4 4", "7 3", "31 8", "1 1", "10 2", "33 22", "50 50", "1 2", "1 3", "2 1", "2 2", "2 3", "3 1", "3 3", "3 4", "4 1", "4 2", "4 3", "4 5", "5 1", "5 2", "5 3", "5 4", "5 5", "5 6", "6 1", "6 2", "6 3", "6 4", "6 5", "6 6", "6 7", "7 1", "7 2", "7 4", "7 5", "7 6", "7 7", "7 8", "8 5", "9 2", "10 4", ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1
codeforces
11baceb65703f5fa83aa13b9e1e98724
Free Ice Cream
After their adventure with the magic mirror Kay and Gerda have returned home and sometimes give free ice cream to kids in the summer. At the start of the day they have *x* ice cream packs. Since the ice cream is free, people start standing in the queue before Kay and Gerda's house even in the night. Each person in the...
{"inputs": ["5 7\n+ 5\n- 10\n- 20\n+ 40\n- 20", "5 17\n- 16\n- 2\n- 98\n+ 100\n- 98", "6 1000000000\n+ 1000000000\n+ 1000000000\n+ 1000000000\n+ 1000000000\n+ 1000000000\n+ 1000000000", "5 12\n- 12\n+ 7\n- 6\n- 1\n+ 46", "11 1000\n- 100\n+ 100\n+ 100\n+ 100\n+ 100\n- 100\n- 100\n- 100\n- 100\n- 100\n- 100", "1 0\n- 526...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1,058
codeforces
11bd126ec7b33ec1ee8b4f3a44b88d55
Devu and Flowers
Devu wants to decorate his garden with flowers. He has purchased *n* boxes, where the *i*-th box contains *f**i* flowers. All flowers in a single box are of the same color (hence they are indistinguishable). Also, no two boxes have flowers of the same color. Now Devu wants to select exactly *s* flowers from the boxes ...
{"inputs": ["2 3\n1 3", "2 4\n2 2", "3 5\n1 3 2", "2 270030023747\n891135146290 437305641972", "20 4385085334307\n273634411136 208521328637 450482376435 844118010709 197241285878 472126475472 2414038897 672334205413 809269727018 409013884362 739986692075 953956651947 462216461906 388007176838 245504550965 527140291750 ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1
codeforces
11bfc921b8411694b749730a04000c16
Game
Vasya and Petya have invented a new game. Vasya takes a stripe consisting of 1<=×<=*n* square and paints the squares black and white. After that Petya can start moves — during a move he may choose any two neighboring squares of one color and repaint these two squares any way he wants, perhaps in different colors. Petya...
{"inputs": ["6\n111010", "5\n10001", "7\n1100010", "5\n00100", "3\n101", "6\n111111", "6\n000000", "10\n1000101001", "100\n1001001000011010001101000011100101101110101001110110010001110011011100111000010010011011101000011101", "100\n0000000000100000000000000000000000000000000000000000000000000000000000000000000000000000...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
31
codeforces
11c1c0b65c6949532970769144a92a59
Idempotent functions
Some time ago Leonid have known about idempotent functions. Idempotent function defined on a set {1,<=2,<=...,<=*n*} is such function , that for any the formula *g*(*g*(*x*))<==<=*g*(*x*) holds. Let's denote as *f*(*k*)(*x*) the function *f* applied *k* times to the value *x*. More formally, *f*(1)(*x*)<==<=*f*(*x*),...
{"inputs": ["4\n1 2 2 4", "3\n2 3 3", "3\n2 3 1", "1\n1", "16\n1 4 13 9 11 16 14 6 5 12 7 8 15 2 3 10", "20\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20", "20\n11 14 2 10 17 5 9 6 18 3 17 7 4 15 17 1 4 14 10 11", "100\n46 7 63 48 75 82 85 90 65 23 36 96 96 29 76 67 26 2 72 76 18 30 48 98 100 61 55 74 18 28 36 89...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
12
codeforces
11e1871581824dfb08ec542251c5ca25
Travel Cards
In the evening Polycarp decided to analyze his today's travel expenses on public transport. The bus system in the capital of Berland is arranged in such a way that each bus runs along the route between two stops. Each bus has no intermediate stops. So each of the buses continuously runs along the route from one stop t...
{"inputs": ["3 5 3 1 8\nBerBank University\nUniversity BerMall\nUniversity BerBank", "4 2 1 300 1000\na A\nA aa\naa AA\nAA a", "2 2 1 0 1\naca BCBA\nBCBA aca", "2 2 1 2 1\nBDDB C\nC BDDB", "2 3 1 1 9\nbacAB aAdb\nbacAB aAdb", "2 3 1 4 6\nAaCdC CdD\naBACc CdD", "1 2 1 2 1\nC BA", "1 3 1 1 4\nbCCCC BC", "1 4 3 1 1\nC bC"...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
5
codeforces
1227949a1bf9ddb09337a57819e135a2
Exams
Vasiliy has an exam period which will continue for *n* days. He has to pass exams on *m* subjects. Subjects are numbered from 1 to *m*. About every day we know exam for which one of *m* subjects can be passed on that day. Perhaps, some day you can't pass any exam. It is not allowed to pass more than one exam on any da...
{"inputs": ["7 2\n0 1 0 2 1 0 2\n2 1", "10 3\n0 0 1 2 3 0 2 0 1 2\n1 1 4", "5 1\n1 1 1 1 1\n5", "100 10\n1 1 6 6 6 2 5 7 6 5 3 7 10 10 8 9 7 6 9 2 6 7 8 6 7 5 2 5 10 1 10 1 8 10 2 9 7 1 6 8 3 10 9 4 4 8 8 6 6 1 5 5 6 5 6 6 6 9 4 7 5 4 6 6 1 1 2 1 8 10 6 2 1 7 2 1 8 10 9 2 7 3 1 5 10 2 8 10 10 10 8 9 5 4 6 10 8 9 6 6\n2...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
7
codeforces
1242b7a42964481d8e4bbc5e3d3435d6
Greenhouse Effect
Emuskald is an avid horticulturist and owns the world's longest greenhouse — it is effectively infinite in length. Over the years Emuskald has cultivated *n* plants in his greenhouse, of *m* different plant species numbered from 1 to *m*. His greenhouse is very narrow and can be viewed as an infinite line, with each p...
{"inputs": ["3 2\n2 1\n1 2.0\n1 3.100", "3 3\n1 5.0\n2 5.5\n3 6.0", "6 3\n1 14.284235\n2 17.921382\n1 20.328172\n3 20.842331\n1 25.790145\n1 27.204125", "1 1\n1 0", "8 2\n1 0.000000\n1 1.000000\n1 2.000000\n2 2.000001\n1 999999997.000000\n2 999999998.000000\n2 999999999.999999\n2 1000000000.000000", "15 5\n4 6.039627\n...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
28
codeforces
1265110d8fb5c19020abe0903ee7b295
LLPS
This problem's actual name, "Lexicographically Largest Palindromic Subsequence" is too long to fit into the page headline. You are given string *s* consisting of lowercase English letters only. Find its lexicographically largest palindromic subsequence. We'll call a non-empty string *s*[*p*1*p*2... *p**k*] = *s**p*1*...
{"inputs": ["radar", "bowwowwow", "codeforces", "mississipp", "tourist", "romka", "helloworld", "zzzzzzzazz", "testcase", "hahahahaha", "abbbbbbbbb", "zaz", "aza", "dcbaedcba", "abcdeabcd", "edcbabcde", "aaaaaaaaab", "testzzzzzz", "zzzzzzwait", "rrrrrqponm", "zzyzyy", "aababb", "zanzibar", "hhgfedcbaa", "aabcdefghh", "...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
713
codeforces
127271f32b49adfdbf73c1c5f1ee489a
Turn the Rectangles
There are $n$ rectangles in a row. You can either turn each rectangle by $90$ degrees or leave it as it is. If you turn a rectangle, its width will be height, and its height will be width. Notice that you can turn any number of rectangles, you also can turn all or none of them. You can not change the order of the recta...
{"inputs": ["3\n3 4\n4 6\n3 5", "2\n3 4\n5 5", "10\n4 3\n1 1\n6 5\n4 5\n2 4\n9 5\n7 9\n9 2\n4 10\n10 1", "10\n241724251 76314740\n80658193 177743680\n213953908 406274173\n485639518 859188055\n103578427 56645210\n611931853 374099541\n916667853 408945969\n677773241 808703176\n575586508 440395988\n450102404 244301685", "1...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
34
codeforces
12785439f019574c6379b2557b4c2af2
Love Triangle
As you could know there are no male planes nor female planes. However, each plane on Earth likes some other plane. There are *n* planes on Earth, numbered from 1 to *n*, and the plane with number *i* likes the plane with number *f**i*, where 1<=≤<=*f**i*<=≤<=*n* and *f**i*<=≠<=*i*. We call a love triangle a situation ...
{"inputs": ["5\n2 4 5 1 3", "5\n5 5 5 5 1", "3\n3 1 2", "10\n4 10 9 5 3 1 5 10 6 4", "10\n5 5 4 9 10 9 9 5 3 1", "100\n50 40 60 87 39 58 44 84 46 68 16 57 77 87 92 95 42 31 74 15 36 84 30 3 47 15 87 90 76 66 6 63 74 19 40 49 6 84 41 9 77 34 7 12 11 73 58 24 81 14 81 29 65 100 1 85 64 32 38 4 54 67 32 81 80 7 100 71 29 ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
490
codeforces
1290054e6b5f04220016c64ece88f5db
Boy or Girl
Those days, many boys use beautiful girls' photos as avatars in forums. So it is pretty hard to tell the gender of a user at the first glance. Last year, our hero went to a forum and had a nice chat with a beauty (he thought so). After that they talked very often and eventually they became a couple in the network. Bu...
{"inputs": ["wjmzbmr", "xiaodao", "sevenkplus", "pezu", "wnemlgppy", "zcinitufxoldnokacdvtmdohsfdjepyfioyvclhmujiqwvmudbfjzxjfqqxjmoiyxrfsbvseawwoyynn", "qsxxuoynwtebujwpxwpajitiwxaxwgbcylxneqiebzfphugwkftpaikixmumkhfbjiswmvzbtiyifbx", "qwbdfzfylckctudyjlyrtmvbidfatdoqfmrfshsqqmhzohhsczscvwzpwyoyswhktjlykumhvaounpzwpxc...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
595
codeforces
12ac6ee7b374eaba6ddb61a68ebddee3
Reberland Linguistics
First-rate specialists graduate from Berland State Institute of Peace and Friendship. You are one of the most talented students in this university. The education is not easy because you need to have fundamental knowledge in different areas, which sometimes are not related to each other. For example, you should know l...
{"inputs": ["abacabaca", "abaca", "gzqgchv", "iosdwvzerqfi", "oawtxikrpvfuzugjweki", "abcdexyzzzz", "affviytdmexpwfqplpyrlniprbdphrcwlboacoqec", "lmnxtobrknqjvnzwadpccrlvisxyqbxxmghvl", "tbdbdpkluawodlrwldjgplbiylrhuywkhafbkiuoppzsjxwbaqqiwagprqtoauowtaexrhbmctcxwpmplkyjnpwukzwqrqpv", "caqmjjtwmqxytcsawfufvlofqcqdwnyvy...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
22
codeforces
12be6f6b6f79389b9d1b141176a2b327
Unordered Subsequence
The sequence is called ordered if it is non-decreasing or non-increasing. For example, sequnces [3, 1, 1, 0] and [1, 2, 3, 100] are ordered, but the sequence [1, 3, 3, 1] is not. You are given a sequence of numbers. You are to find it's shortest subsequence which is not ordered. A subsequence is a sequence that can be...
{"inputs": ["3\n3 1 2", "1\n-895376", "2\n166442 61629", "3\n-771740 -255752 -300809", "4\n-227347 -573134 -671045 11011", "5\n834472 -373089 441294 -633071 -957672", "2\n7 8"], "outputs": ["3\n1 2 3", "0", "0", "3\n1 2 3", "3\n2 3 4", "3\n1 2 3", "0"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
20
codeforces
12d93ca6906e39940b5ee321de7f9ae7
Postcards and photos
Polycarpus has postcards and photos hung in a row on the wall. He decided to put them away to the closet and hang on the wall a famous painter's picture. Polycarpus does it like that: he goes from the left to the right and removes the objects consecutively. As Polycarpus doesn't want any mix-ups to happen, he will not ...
{"inputs": ["CPCPCPC", "CCCCCCPPPPPP", "CCCCCCPPCPPPPPPPPPP", "CCCCCCCCCC", "CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC", "CPCPCPCPCPCPCPCPCPCPCPCPCPCPCPCPCPCPCPCPCPCPCPCPCPCPCPCPCPCPCPCPCPCPCPCPCPCPCPCPCPCPCPCPCPCPCPCPCPCP", "CCCCCCPPPPPPCCCCCCPPPPPPCCCCCCPPPPP...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
133
codeforces
13056962b3f1cb803ad09d79e4bde485
Primes on Interval
You've decided to carry out a survey in the theory of prime numbers. Let us remind you that a prime number is a positive integer that has exactly two distinct positive integer divisors. Consider positive integers *a*, *a*<=+<=1, ..., *b* (*a*<=≤<=*b*). You want to find the minimum integer *l* (1<=≤<=*l*<=≤<=*b*<=-<=*a...
{"inputs": ["2 4 2", "6 13 1", "1 4 3", "5 8 2", "8 10 3", "1 5 2", "6 8 3", "21 29 2", "17 27 3", "1 1000000 10000", "690059 708971 10000", "12357 534133 2", "838069 936843 3", "339554 696485 4", "225912 522197 5", "404430 864261 6", "689973 807140 7", "177146 548389 8", "579857 857749 9", "35648 527231 10", "2 100000...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
27
codeforces
1334299b4247da2d1bdae5974c6fcb0f
Red and Blue Balls
User ainta has a stack of *n* red and blue balls. He can apply a certain operation which changes the colors of the balls inside the stack. - While the top ball inside the stack is red, pop the ball from the top of the stack. - Then replace the blue ball on the top with a red ball. - And finally push some blue balls...
{"inputs": ["3\nRBR", "4\nRBBR", "5\nRBBRR", "5\nRBRBR", "10\nRRBRRBBRRR", "10\nBRBRRRRRRR", "10\nBRRRRRRRRR", "20\nBRBRRRRRRRRRRRRRRRRR", "30\nRRBBBBBBBBBBBBBBBBBBBBBBBBBBBB", "50\nBRRRBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB", "20\nRRRBRBBBBBRRRRRRRRRR", "20\nRRBRBBBBBRRRRRRRRRRR", "1\nR", "1\nB", "2\nRR", "2\n...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
64
codeforces
13448478d4e49c8e2d1caa3ff518b3c1
Valera and Antique Items
Valera is a collector. Once he wanted to expand his collection with exactly one antique item. Valera knows *n* sellers of antiques, the *i*-th of them auctioned *k**i* items. Currently the auction price of the *j*-th object of the *i*-th seller is *s**ij*. Valera gets on well with each of the *n* sellers. He is perfec...
{"inputs": ["3 50000\n1 40000\n2 20000 60000\n3 10000 70000 190000", "3 50000\n1 50000\n3 100000 120000 110000\n3 120000 110000 120000", "2 100001\n1 895737\n1 541571", "1 1000000\n1 1000000", "1 1000000\n1 561774", "3 1000000\n5 1000000 568832 1000000 1000000 1000000\n13 1000000 1000000 1000000 596527 1000000 1000000 ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
294
codeforces
134adde1602a65ae3022bdcfbb7f3925
Life Without Zeros
Can you imagine our life if we removed all zeros from it? For sure we will have many problems. In this problem we will have a simple example if we removed all zeros from our life, it's the addition operation. Let's assume you are given this equation *a*<=+<=*b*<==<=*c*, where *a* and *b* are positive integers, and *c*...
{"inputs": ["101\n102", "105\n106", "544\n397", "822\n280", "101\n413", "309\n139", "693\n970", "981\n1", "352\n276", "164\n691", "110036\n43", "100\n1000", "1000000000\n1000000000", "999999999\n999999999", "6\n4", "123456\n876543", "1234567\n9876543", "1111111\n1119111", "10502405\n40403403", "1\n1", "5\n4", "1\n6", "...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
625
codeforces
134e58b9e1ffbdb158576f17eed68543
Substring and Subsequence
One day Polycarpus got hold of two non-empty strings *s* and *t*, consisting of lowercase Latin letters. Polycarpus is quite good with strings, so he immediately wondered, how many different pairs of "*x* *y*" are there, such that *x* is a substring of string *s*, *y* is a subsequence of string *t*, and the content of ...
{"inputs": ["aa\naa", "codeforces\nforceofcode", "coderscontest\ncodeforces", "a\nb", "ab\nbbbba", "abbbccbba\nabcabc", "zxzxzxzxzxzxzx\nd", "pfdempfohomnpgbeegikfmflnalbbajpnpgeacaicoehopgnabnklheepnlnflohjegcciflmfjhachnhekckfjgoffhkblncidn\nidlhklpclcghngeggpjdgefccihndpoikojdjnbkdfjgaanoolfmnifnmbpeeghpicehjdiipnlf...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1
codeforces
13b28296e941bf4b38a92e234423bc69
Resort
Valera's finally decided to go on holiday! He packed up and headed for a ski resort. Valera's fancied a ski trip but he soon realized that he could get lost in this new place. Somebody gave him a useful hint: the resort has *n* objects (we will consider the objects indexed in some way by integers from 1 to *n*), each ...
{"inputs": ["5\n0 0 0 0 1\n0 1 2 3 4", "5\n0 0 1 0 1\n0 1 2 2 4", "4\n1 0 0 0\n2 3 4 2", "10\n0 0 0 0 0 0 0 0 0 1\n4 0 8 4 7 8 5 5 7 2", "50\n0 0 0 0 0 0 0 0 0 0 1 0 1 0 0 1 1 0 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1 0 0 1 1 0 0 0 1 0\n28 4 33 22 4 35 36 31 42 25 50 33 25 36 18 23 23 28 43 3 18 31 1 2 15 22 40 4...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
15
codeforces
13b7ef974745d76a78439919a6ed01eb
Mike and gcd problem
Mike has a sequence *A*<==<=[*a*1,<=*a*2,<=...,<=*a**n*] of length *n*. He considers the sequence *B*<==<=[*b*1,<=*b*2,<=...,<=*b**n*] beautiful if the *gcd* of all its elements is bigger than 1, i.e. . Mike wants to change his sequence in order to make it beautiful. In one move he can choose an index *i* (1<=≤<=*i*<...
{"inputs": ["2\n1 1", "3\n6 2 4", "2\n1 3", "9\n57 30 28 81 88 32 3 42 25", "2\n8 77", "4\n92 46 3 21", "2\n78 26", "2\n3 6", "2\n3 9", "2\n3 3", "3\n3 6 3", "3\n3 9 15", "3\n3 6 9", "3\n3 3 3", "3\n3 9 18", "5\n1 2 1 2 1", "2\n9 6", "4\n3 6 9 12", "3\n3 9 27", "3\n3 9 12", "5\n6 6 9 15 21", "2\n5 15", "4\n2 3 9 13", "...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
5
codeforces
13bdb1f2506b952ef6004ba0c77808ec
Inbox (100500)
Over time, Alexey's mail box got littered with too many letters. Some of them are read, while others are unread. Alexey's mail program can either show a list of all letters or show the content of a single letter. As soon as the program shows the content of an unread letter, it becomes read letter (if the program shows...
{"inputs": ["5\n0 1 0 1 0", "5\n1 1 0 0 1", "2\n0 0", "9\n1 0 1 0 1 0 1 0 1", "5\n1 1 1 1 1", "14\n0 0 1 1 1 0 1 1 1 0 1 1 1 0", "23\n1 1 1 0 1 1 0 1 1 0 1 1 1 0 1 1 0 1 1 0 1 1 1", "27\n0 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 0", "10\n1 0 0 0 0 1 0 0 0 1", "10\n1 0 0 1 0 0 1 1 0 1", "27\n0 0 0 0 0 0 0 0 0 ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
209
codeforces
13cbed0d2f029102bb46ecec65fe6d8d
Switches and Lamps
You are given *n* switches and *m* lamps. The *i*-th switch turns on some subset of the lamps. This information is given as the matrix *a* consisting of *n* rows and *m* columns where *a**i*,<=*j*<==<=1 if the *i*-th switch turns on the *j*-th lamp and *a**i*,<=*j*<==<=0 if the *i*-th switch is not connected to the *j*...
{"inputs": ["4 5\n10101\n01000\n00111\n10000", "4 5\n10100\n01000\n00110\n00101", "1 5\n11111", "10 1\n1\n0\n0\n0\n0\n0\n0\n0\n0\n1", "1 1\n1", "3 4\n1010\n0100\n1101", "2 5\n10101\n11111", "5 5\n10000\n11000\n11100\n11110\n11111", "2 5\n10000\n11111", "4 5\n01000\n10100\n00010\n10101", "2 2\n10\n11", "2 5\n00100\n1111...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
99
codeforces
13ced2a3d8b5a62401f7b011c2f5576b
Simba on the Circle
You are given a circular array with *n* elements. The elements are numbered from some element with values from 1 to *n* in clockwise order. The *i*-th cell contains the value *a**i*. The robot Simba is in cell *s*. Each moment of time the robot is in some of the *n* cells (at the begin he is in *s*). In one turn the r...
{"inputs": ["9 1\n0 1 2 2 2 1 0 1 1", "8 1\n0 1 0 1 0 1 0 1", "8 1\n1 2 3 4 5 6 7 8", "8 1\n0 0 0 0 0 0 0 0", "8 1\n0 1 2 2 1 0 1 1", "1 1\n4", "10 1\n-1 0 1 0 -1 1 0 0 1 -1", "20 7\n0 6 0 0 0 -7 -8 9 -7 4 7 2 -4 4 -5 2 6 8 -2 -7", "30 13\n68 50 99 23 84 23 24 -42 82 36 -10 -51 -96 96 19 -4 4 -41 74 92 13 58 26 79 -11 ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1
codeforces
13d695394072750e82992d500f1bcc2c
Garden
Luba thinks about watering her garden. The garden can be represented as a segment of length *k*. Luba has got *n* buckets, the *i*-th bucket allows her to water some continuous subsegment of garden of length exactly *a**i* each hour. Luba can't water any parts of the garden that were already watered, also she can't wat...
{"inputs": ["3 6\n2 3 5", "6 7\n1 2 3 4 5 6", "5 97\n1 10 50 97 2", "5 97\n1 10 50 100 2", "100 100\n2 46 24 18 86 90 31 38 84 49 58 28 15 80 14 24 87 56 62 87 41 87 55 71 87 32 41 56 91 32 24 75 43 42 35 30 72 53 31 26 54 61 87 85 36 75 44 31 7 38 77 57 61 54 70 77 45 96 39 57 11 8 91 42 52 15 42 30 92 41 27 26 34 27 ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
379
codeforces
1406f44b358d0fb8fc59355a2bc1ea3e
Binary Table
You are given a table consisting of *n* rows and *m* columns. Each cell of the table contains either 0 or 1. In one move, you are allowed to pick any row or any column and invert all values, that is, replace 0 by 1 and vice versa. What is the minimum number of cells with value 1 you can get after applying some number ...
{"inputs": ["3 4\n0110\n1010\n0111", "1 1\n0", "1 1\n1", "2 1\n0\n1", "1 2\n10", "2 2\n01\n10", "2 2\n11\n10", "2 2\n00\n00", "2 2\n00\n11", "3 3\n100\n010\n001", "3 9\n010100100\n101011011\n101011101", "8 3\n000\n001\n010\n100\n110\n011\n101\n111", "1 10\n0110010001", "9 1\n0\n1\n1\n0\n1\n0\n1\n0\n1", "4 5\n01010\n101...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1
codeforces
141fac17f61c95c45f5139058556a5cd
Four Segments
You are given an array of *n* integer numbers. Let *sum*(*l*,<=*r*) be the sum of all numbers on positions from *l* to *r* non-inclusive (*l*-th element is counted, *r*-th element is not counted). For indices *l* and *r* holds 0<=≤<=*l*<=≤<=*r*<=≤<=*n*. Indices in array are numbered from 0. For example, if *a*<==<=[<...
{"inputs": ["3\n-1 2 3", "4\n0 0 -1 0", "1\n10000", "1\n-1", "1\n0", "10\n0 0 0 0 0 0 0 0 0 0", "100\n-1 -1 0 1 -1 0 0 -1 -1 1 1 0 1 0 -1 1 0 0 -1 0 0 0 1 0 0 1 1 1 1 0 -1 -1 0 0 0 1 1 -1 0 0 1 1 1 0 -1 -1 0 -1 0 -1 -1 0 1 0 1 -1 1 -1 -1 -1 0 0 -1 0 -1 -1 0 -1 1 1 -1 1 0 1 -1 -1 1 1 -1 1 0 -1 1 -1 1 1 1 1 1 -1 0 1 0 0 ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
15
codeforces
14224c4b4244d0fe292621f678e1422f
none
From beginning till end, this message has been waiting to be conveyed. For a given unordered multiset of *n* lowercase English letters ("multi" means that a letter may appear more than once), we treat all letters as strings of length 1, and repeat the following operation *n*<=-<=1 times: - Remove any two elements *s...
{"inputs": ["12", "3", "0", "2", "5", "10", "233", "418", "100000", "1", "4", "6", "7", "8", "9", "11", "1317", "1926", "14514", "25252", "99681", "99998", "82944", "831", "39393"], "outputs": ["abababab", "codeforces", "o", "aabb", "aaabbcc", "aaaaa", "ooououououououououooohhhhhhaaiiiiiibbjjjjjjcckkkkkkddlllllleemmmmm...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
35
codeforces
142ca9504dab57200c552d5380ecc69f
Almost Acyclic Graph
You are given a [directed graph](https://en.wikipedia.org/wiki/Directed_graph) consisting of *n* vertices and *m* edges (each edge is directed, so it can be traversed in only one direction). You are allowed to remove at most one edge from it. Can you make this graph [acyclic](https://en.wikipedia.org/wiki/Directed_acy...
{"inputs": ["3 4\n1 2\n2 3\n3 2\n3 1", "5 6\n1 2\n2 3\n3 2\n3 1\n2 1\n4 5", "2 2\n1 2\n2 1", "7 7\n1 3\n3 6\n3 7\n5 3\n6 2\n6 7\n7 2", "500 50\n396 340\n47 341\n422 140\n492 209\n263 248\n461 300\n124 495\n33 6\n93 384\n389 182\n130 297\n217 329\n131 136\n355 94\n388 275\n115 368\n279 462\n126 285\n185 287\n223 221\n20...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
6
codeforces
143975608b5342cde4acac925204f195
Little Elephant and Interval
The Little Elephant very much loves sums on intervals. This time he has a pair of integers *l* and *r* (*l*<=≤<=*r*). The Little Elephant has to find the number of such integers *x* (*l*<=≤<=*x*<=≤<=*r*), that the first digit of integer *x* equals the last one (in decimal notation). For example, such numbers as 101, 4...
{"inputs": ["2 47", "47 1024", "1 1000", "1 10000", "47 8545", "1000 1000", "47547 4587554587754542", "1 1000000", "47 74", "10001 10000002", "10000 100000", "458754 4588754", "111 111", "110 147", "1 1000000000", "12 10000000000", "1000000000 1000000000", "1 1000000000000000000", "11 111111111111111100", "100000000000...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
52
codeforces
143bfa7b8d53e4b19209a18df9563490
"Or" Game
You are given *n* numbers *a*1,<=*a*2,<=...,<=*a**n*. You can perform at most *k* operations. For each operation you can multiply one of the numbers by *x*. We want to make as large as possible, where denotes the bitwise OR. Find the maximum possible value of after performing at most *k* operations optimally. The ...
{"inputs": ["3 1 2\n1 1 1", "4 2 3\n1 2 4 8", "2 1 2\n12 9", "2 1 2\n12 7", "3 1 3\n3 2 0", "5 10 8\n1000000000 1000000000 1000000000 1000000000 1000000000", "1 2 3\n612635770", "3 2 5\n0 2 3", "2 1 8\n18 17", "5 10 8\n0 0 0 0 0", "1 1 2\n1", "1 1 2\n0", "3 2 6\n724148075 828984987 810015532", "3 1 2\n17 18 4", "3 1 2\...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
22
codeforces
1450da53095949ecb270a669f433444e
Hopscotch
So nearly half of the winter is over and Maria is dreaming about summer. She's fed up with skates and sleds, she was dreaming about Hopscotch all night long. It's a very popular children's game. The game field, the court, looks as is shown in the figure (all blocks are square and are numbered from bottom to top, blocks...
{"inputs": ["1 0 0", "3 1 1", "3 0 10", "3 0 7", "3 4 0", "9 3 2", "100 0 953748", "17 0 1000000", "17 15 99999", "55 -20 1000000", "1 154871 37516", "1 -1 0", "1 -1 1", "1 0 2", "1 0 552012", "1 1 293372", "1 -1 551084", "5 -744240 145890", "5 -4 2", "5 -5 7", "5 -3 14", "5 0 660386", "5 5 918098", "5 -5 659458", "10 ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
2
codeforces
1462cea6e0234917f31a0424b8da0329
none
Levko has an array that consists of integers: *a*1,<=*a*2,<=... ,<=*a**n*. But he doesn’t like this array at all. Levko thinks that the beauty of the array *a* directly depends on value *c*(*a*), which can be calculated by the formula: It’s time to change the world and Levko is going to change his array for the bett...
{"inputs": ["5 2\n4 7 4 7 4", "3 1\n-100 0 100", "6 3\n1 2 3 7 8 9", "4 1\n-1000000000 -1000000000 1000000000 1000000000", "10 1\n-6 5 -7 -7 -7 -7 5 -9 4 7", "20 17\n-5 -9 11 -7 -17 -8 0 -14 -20 -15 7 -13 0 -3 -14 0 9 -10 6 -19", "5 1\n-1000000000 1000000000 -1000000000 1000000000 -1000000000", "16 13\n441427217 689669...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1
codeforces
1470983329ca5e3a2c6705a82cd173d6
List Of Integers
Let's denote as *L*(*x*,<=*p*) an infinite sequence of integers *y* such that *gcd*(*p*,<=*y*)<==<=1 and *y*<=&gt;<=*x* (where *gcd* is the greatest common divisor of two integer numbers), sorted in ascending order. The elements of *L*(*x*,<=*p*) are 1-indexed; for example, 9, 13 and 15 are the first, the second and th...
{"inputs": ["3\n7 22 1\n7 22 2\n7 22 3", "5\n42 42 42\n43 43 43\n44 44 44\n45 45 45\n46 46 46"], "outputs": ["9\n13\n15", "187\n87\n139\n128\n141"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
3
codeforces
1478c482a3296de529bb34c0e7e351e4
Ithea Plays With Chtholly
This is an interactive problem. Refer to the Interaction section below for better understanding. Ithea and Chtholly want to play a game in order to determine who can use the kitchen tonight. Initially, Ithea puts *n* clear sheets of paper in a line. They are numbered from 1 to *n* from left to right. This game wil...
{"inputs": ["2 4 4\n2\n1\n3\n4", "2 2 2\n1\n2", "3 6 3\n1\n2\n1\n3\n1\n3", "4 8 4\n4\n4\n4\n4\n4\n4\n4\n4", "10 120 15\n6\n11\n9\n11\n3\n12\n11\n12\n2\n8\n3\n11\n13\n5\n12\n11\n9\n3\n10\n9\n9\n13\n13\n5\n6\n11\n3\n15\n8\n8\n10\n13\n7\n6\n4\n14\n9\n10\n5\n13\n4\n1\n8\n6\n13\n1\n3\n4\n9\n12\n2\n7\n3\n3\n7\n2\n2\n9\n2\n4\...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
5
codeforces
1488e9b4a9ebd590be12f7ea2251d7c8
Karen and Test
Karen has just arrived at school, and she has a math test today! The test is about basic addition and subtraction. Unfortunately, the teachers were too busy writing tasks for Codeforces rounds, and had no time to make an actual test. So, they just put one question in the test that is worth all the points. There are *...
{"inputs": ["5\n3 6 9 12 15", "4\n3 7 5 2", "1\n1", "16\n985629174 189232688 48695377 692426437 952164554 243460498 173956955 210310239 237322183 96515847 678847559 682240199 498792552 208770488 736004147 176573082", "18\n341796022 486073481 86513380 593942288 60606166 627385348 778725113 896678215 384223198 661124212 ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1
codeforces
148e34843e6ea7ff1682255785649209
Dorm Water Supply
The German University in Cairo (GUC) dorm houses are numbered from 1 to *n*. Underground water pipes connect these houses together. Each pipe has certain direction (water can flow only in this direction and not vice versa), and diameter (which characterizes the maximal amount of water it can handle). For each house, t...
{"inputs": ["3 2\n1 2 10\n2 3 20", "3 3\n1 2 20\n2 3 10\n3 1 5", "4 2\n1 2 60\n3 4 50", "10 10\n10 3 70\n1 9 98\n9 10 67\n5 2 78\n8 6 71\n4 8 95\n7 1 10\n2 5 73\n6 7 94\n3 4 23", "7 5\n3 2 26\n4 6 84\n6 3 82\n5 1 57\n1 7 34", "9 6\n7 4 98\n5 9 72\n4 6 10\n2 8 22\n9 7 17\n3 1 66", "8 6\n1 3 84\n8 4 34\n7 2 10\n6 8 8\n3 ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
15
codeforces
149a65db8891987c69e12b3a698e18d4
Card Game
Digital collectible card games have become very popular recently. So Vova decided to try one of these. Vova has *n* cards in his collection. Each of these cards is characterised by its power *p**i*, magic number *c**i* and level *l**i*. Vova wants to build a deck with total power not less than *k*, but magic numbers m...
{"inputs": ["5 8\n5 5 1\n1 5 4\n4 6 3\n1 12 4\n3 12 1", "3 7\n4 4 1\n5 8 2\n5 3 3", "10 10\n3 3 6\n5 10 4\n4 7 9\n4 9 7\n1 9 4\n1 6 10\n4 10 1\n4 4 6\n2 7 2\n1 5 4", "10 20\n9 4 10\n2 8 9\n9 1 1\n8 10 10\n5 10 2\n1 2 10\n9 6 3\n2 10 5\n7 10 6\n6 3 1", "10 30\n23 83 9\n2 59 6\n10 6 4\n4 92 3\n19 13 6\n28 83 6\n25 58 4\n...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
3
codeforces
14b287b107fd7520ff268970f124a5ce
Search for Pretty Integers
You are given two lists of non-zero digits. Let's call an integer pretty if its (base 10) representation has at least one digit from the first list and at least one digit from the second list. What is the smallest positive pretty integer? The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=9) — the l...
{"inputs": ["2 3\n4 2\n5 7 6", "8 8\n1 2 3 4 5 6 7 8\n8 7 6 5 4 3 2 1", "1 1\n9\n1", "9 1\n5 4 2 3 6 1 7 9 8\n9", "5 3\n7 2 5 8 6\n3 1 9", "4 5\n5 2 6 4\n8 9 1 3 7", "5 9\n4 2 1 6 7\n2 3 4 5 6 7 8 9 1", "9 9\n5 4 3 2 1 6 7 8 9\n3 2 1 5 4 7 8 9 6", "9 5\n2 3 4 5 6 7 8 9 1\n4 2 1 6 7", "9 9\n1 2 3 4 5 6 7 8 9\n1 2 3 4 5 ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
355
codeforces
14c9740aff6f6fea9c424e0318ca8313
Restoration of string
A substring of some string is called the most frequent, if the number of its occurrences is not less than number of occurrences of any other substring. You are given a set of strings. A string (not necessarily from this set) is called good if all elements of the set are the most frequent substrings of this string. Res...
{"inputs": ["4\nmail\nai\nlru\ncf", "3\nkek\npreceq\ncheburek", "1\nz", "2\nab\nba", "2\nac\nbc", "2\ncd\nce", "2\nca\ncb", "2\ndc\nec", "26\nhw\nwb\nba\nax\nxl\nle\neo\nod\ndj\njt\ntm\nmq\nqf\nfk\nkn\nny\nyz\nzr\nrg\ngv\nvc\ncs\nsi\niu\nup\nph", "25\nsw\nwt\nc\nl\nyo\nag\nz\nof\np\nmz\nnm\nui\nzs\nj\nq\nk\ngd\nb\nen\n...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
8
codeforces
14cb93780999f0be5745dc2133c5dcc5
Ability To Convert
Alexander is learning how to convert numbers from the decimal system to any other, however, he doesn't know English letters, so he writes any number only as a decimal number, it means that instead of the letter *A* he will write the number 10. Thus, by converting the number 475 from decimal to hexadecimal system, he ge...
{"inputs": ["13\n12", "16\n11311", "20\n999", "17\n2016", "1000\n1001", "1000\n1000", "2\n110111100000101101101011001110100111011001000000000000000000", "500\n29460456244280453288", "1000000000\n17289468142098080", "123\n7719", "25\n2172214240", "2\n1110110101111000010001011110101001011001110000000010111010", "3\n12100...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
6
codeforces
1504039ac7ea1dfc39679c660b5763cb
none
You've got string *s*, consisting of only lowercase English letters. Find its lexicographically maximum subsequence. We'll call a non-empty string *s*[*p*1*p*2... *p**k*]<==<=*s**p*1*s**p*2... *s**p**k*(1<=≤<=*p*1<=&lt;<=*p*2<=&lt;<=...<=&lt;<=*p**k*<=≤<=|*s*|) a subsequence of string *s*<==<=*s*1*s*2... *s*|*s*|. St...
{"inputs": ["ababba", "abbcbccacbbcbaaba", "thankstosamarasauteddybearsforthiscontest", "cantouristsolveitlessthaninoneminute", "arepretestsstrongforthisproblem", "whyareyoulookingfortestsdoyouhavewa", "aa", "zz", "a", "z", "b", "y", "zaz", "aza", "dcbaedcba", "abcdeabcd", "abcdedcba", "zyxzxzwyxywxxwabcdabdacdbcacdbca...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
51
codeforces
1505530295dbd2d4bc8823b29ba39a2d
Little Elephant and Function
The Little Elephant enjoys recursive functions. This time he enjoys the sorting function. Let *a* is a permutation of an integers from 1 to *n*, inclusive, and *a**i* denotes the *i*-th element of the permutation. The Little Elephant's recursive function *f*(*x*), that sorts the first *x* permutation's elements, works...
{"inputs": ["1", "2", "3", "4", "5", "6", "7", "1000", "999", "998", "997", "900", "101", "3", "67", "779", "195", "907", "971", "683", "99", "811", "875", "291", "3", "419", "779", "195", "907", "21", "22", "23", "24", "25"], "outputs": ["1 ", "2 1 ", "3 1 2 ", "4 1 2 3 ", "5 1 2 3 4 ", "6 1 2 3 4 5 ", "7 1 2 3 4 5 6 ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
304
codeforces
150b646344f8eb91459c57d85944dfc9
PolandBall and Game
PolandBall is playing a game with EnemyBall. The rules are simple. Players have to say words in turns. You cannot say a word which was already said. PolandBall starts. The Ball which can't say a new word loses. You're given two lists of words familiar to PolandBall and EnemyBall. Can you determine who wins the game, i...
{"inputs": ["5 1\npolandball\nis\na\ncool\ncharacter\nnope", "2 2\nkremowka\nwadowicka\nkremowka\nwiedenska", "1 2\na\na\nb", "2 2\na\nb\nb\nc", "2 1\nc\na\na", "3 3\nab\nbc\ncd\ncd\ndf\nfg", "3 3\nc\na\nb\na\nd\ng", "1 1\naa\naa", "2 1\na\nb\na", "6 5\na\nb\nc\nd\ne\nf\nf\ne\nd\nz\ny", "3 2\na\nb\nc\nd\ne"], "outputs"...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
131
codeforces
151f68a26da83524d8b82f40c7e8092c
Group Photo 2 (online mirror version)
Many years have passed, and *n* friends met at a party again. Technologies have leaped forward since the last meeting, cameras with timer appeared and now it is not obligatory for one of the friends to stand with a camera, and, thus, being absent on the photo. Simply speaking, the process of photographing can be descr...
{"inputs": ["3\n10 1\n20 2\n30 3", "3\n3 1\n2 2\n4 3", "1\n5 10", "1\n1 1", "1\n1000 1000", "1\n1 1000", "2\n1 1000\n1000 1", "2\n1 1\n1000 1000", "1\n1000 1", "5\n407 830\n12 199\n768 215\n668 28\n628 310", "3\n379 820\n923 407\n916 853", "3\n99 768\n477 885\n169 118", "3\n227 612\n223 259\n423 895", "3\n651 161\n480 ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
2
codeforces
1542f4a09d6ddea98267a3b58425bbd5
Robot Rapping Results Report
While Farmer John rebuilds his farm in an unfamiliar portion of Bovinia, Bessie is out trying some alternative jobs. In her new gig as a reporter, Bessie needs to know about programming competition results as quickly as possible. When she covers the 2016 Robot Rap Battle Tournament, she notices that all of the robots o...
{"inputs": ["4 5\n2 1\n1 3\n2 3\n4 2\n4 3", "3 2\n1 2\n3 2", "2 1\n1 2", "2 1\n2 1", "5 10\n1 2\n1 3\n1 4\n1 5\n2 3\n2 4\n2 5\n3 4\n3 5\n4 5", "3 3\n2 1\n3 1\n3 2", "4 6\n1 4\n4 2\n2 3\n1 2\n1 3\n4 3", "3 3\n3 1\n3 2\n1 2", "5 10\n2 1\n1 4\n2 5\n2 3\n5 4\n3 4\n3 1\n3 5\n2 4\n1 5", "3 3\n1 2\n3 2\n1 3", "3 3\n2 3\n1 3\n...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
6
codeforces
156d2508c063ef36fdc1332ed8ab8e1e
Iterated Linear Function
Consider a linear function *f*(*x*)<==<=*Ax*<=+<=*B*. Let's define *g*(0)(*x*)<==<=*x* and *g*(*n*)(*x*)<==<=*f*(*g*(*n*<=-<=1)(*x*)) for *n*<=&gt;<=0. For the given integer values *A*, *B*, *n* and *x* find the value of *g*(*n*)(*x*) modulo 109<=+<=7. The only line contains four integers *A*, *B*, *n* and *x* (1<=≤<=*...
{"inputs": ["3 4 1 1", "3 4 2 1", "3 4 3 1", "1 1 1 1", "3 10 723 6", "14 81 51 82", "826504481 101791432 76 486624528", "475965351 844435993 96338 972382431", "528774798 650132512 6406119 36569714", "632656975 851906850 1 310973933", "1 1 352875518515340737 1", "978837295 606974665 846646545585165081 745145208", "2776...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
35
codeforces
158444ebd70a822da08f95e3843ab7e3
Wizards and Demonstration
Some country is populated by wizards. They want to organize a demonstration. There are *n* people living in the city, *x* of them are the wizards who will surely go to the demonstration. Other city people (*n*<=-<=*x* people) do not support the wizards and aren't going to go to the demonstration. We know that the city...
{"inputs": ["10 1 14", "20 10 50", "1000 352 146", "68 65 20", "78 28 27", "78 73 58", "70 38 66", "54 4 38", "3 1 69", "11 9 60", "71 49 65", "78 55 96", "2765 768 9020", "3478 1728 9727", "9678 6173 5658", "1138 570 6666", "7754 204 9038", "8403 7401 4769", "4909 2111 8860", "6571 6449 8965", "9178 2255 7996", "6151 ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
305
codeforces
158ed5933ad363941eb78811545a4c1f
A Vital Problem
Polycarp has a strict daily schedule. He has *n* alarms set for each day, and the *i*-th alarm rings each day at the same time during exactly one minute. Determine the longest time segment when Polycarp can sleep, i. e. no alarm rings in that period. It is possible that Polycarp begins to sleep in one day, and wakes u...
{"inputs": ["1\n05:43", "4\n22:00\n03:21\n16:03\n09:59", "20\n23:59\n00:00\n00:01\n00:02\n00:03\n00:04\n00:05\n00:06\n00:07\n00:08\n00:09\n00:10\n00:11\n00:12\n00:13\n00:14\n00:15\n00:16\n00:17\n00:18", "21\n23:28\n23:29\n23:30\n23:31\n23:32\n23:33\n23:34\n23:35\n23:36\n23:37\n23:38\n23:39\n23:40\n23:41\n23:42\n23:43\n...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
43
codeforces
1591a073be244b2dc292fed6a4ee16c2
Inna and Huge Candy Matrix
Inna and Dima decided to surprise Sereja. They brought a really huge candy matrix, it's big even for Sereja! Let's number the rows of the giant matrix from 1 to *n* from top to bottom and the columns — from 1 to *m*, from left to right. We'll represent the cell on the intersection of the *i*-th row and *j*-th column as...
{"inputs": ["3 3 3 1 1 9\n1 1\n1 2\n1 3\n2 1\n2 2\n2 3\n3 1\n3 2\n3 3", "5 5 0 0 0 1\n1 4", "14 76 376219315 550904689 16684615 24\n11 21\n1 65\n5 25\n14 63\n11 30\n1 19\n5 7\n9 51\n2 49\n13 75\n9 9\n3 63\n8 49\n5 1\n1 67\n13 31\n9 35\n3 53\n13 73\n5 71\n1 32\n5 49\n1 41\n14 69", "63 67 18046757 61758841 85367218 68\n2...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
12
codeforces
15dc09ce785b1080b799acedace9411c
Okabe and Banana Trees
Okabe needs bananas for one of his experiments for some strange reason. So he decides to go to the forest and cut banana trees. Consider the point (*x*,<=*y*) in the 2D plane such that *x* and *y* are integers and 0<=≤<=*x*,<=*y*. There is a tree in such a point, and it has *x*<=+<=*y* bananas. There are no trees nor ...
{"inputs": ["1 5", "2 3", "4 6", "6 3", "1 1", "10 1", "20 10", "1000 10000", "139 9252", "859 8096", "987 4237", "411 3081", "539 9221", "259 770", "387 5422", "515 1563", "939 407", "518 6518", "646 1171", "70 7311", "494 6155", "918 7704", "46 3844", "174 2688", "894 4637", "22 3481", "446 5030", "440 8704", "569 75...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
72
codeforces
15e263e85246dfd3aa917ff242354b00
Alyona and Spreadsheet
During the lesson small girl Alyona works with one famous spreadsheet computer program and learns how to edit tables. Now she has a table filled with integers. The table consists of *n* rows and *m* columns. By *a**i*,<=*j* we will denote the integer located at the *i*-th row and the *j*-th column. We say that the tab...
{"inputs": ["5 4\n1 2 3 5\n3 1 3 2\n4 5 2 3\n5 5 3 2\n4 4 3 4\n6\n1 1\n2 5\n4 5\n3 5\n1 3\n1 5", "1 1\n1\n1\n1 1", "10 1\n523130301\n127101624\n15573616\n703140639\n628818570\n957494759\n161270109\n386865653\n67832626\n53360557\n17\n4 5\n4 7\n8 8\n9 9\n3 9\n8 10\n8 9\n7 9\n4 5\n2 9\n4 6\n2 4\n2 6\n4 6\n7 9\n2 4\n8 10",...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
20
codeforces
15f8e73bc9b0d7eb1a626278b62f9905
Bathroom terminal
Smith wakes up at the side of a dirty, disused bathroom, his ankle chained to pipes. Next to him is tape-player with a hand-written message "Play Me". He finds a tape in his own back pocket. After putting the tape in the tape-player, he sees a key hanging from a ceiling, chained to some kind of a machine, which is conn...
{"inputs": ["3 1\nabc\naec\nac\na?c", "22 2\naaaab\naaabb\naabab\naabbb\nabaab\nababb\nabbab\nabbbb\naaab\naabb\nabab\nabbb\naab\nabb\nab\ncccd\nccdd\ncdcd\ncddd\nccd\ncdd\ncd\na???b\nc??d", "15 6\naaa\naaabbb\naaabb\naaaaa\naaaaaa\naaaa\naaabbbb\naaaaa\naaaaaa\naaaa\naaabbbb\naabbbb\naa\naa\naab\na\n?a?\n??\n?aa?bb?\n...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1
codeforces
160baf248c6c33b69df49066de5ff338
Inna and Alarm Clock
Inna loves sleeping very much, so she needs *n* alarm clocks in total to wake up. Let's suppose that Inna's room is a 100<=×<=100 square with the lower left corner at point (0,<=0) and with the upper right corner at point (100,<=100). Then the alarm clocks are points with integer coordinates in this square. The mornin...
{"inputs": ["4\n0 0\n0 1\n0 2\n1 0", "4\n0 0\n0 1\n1 0\n1 1", "4\n1 1\n1 2\n2 3\n3 3", "1\n0 0", "42\n28 87\n26 16\n59 90\n47 61\n28 83\n36 30\n67 10\n6 95\n9 49\n86 94\n52 24\n74 9\n86 24\n28 51\n25 99\n40 98\n57 33\n18 96\n43 36\n3 79\n4 86\n38 61\n25 61\n6 100\n58 81\n28 19\n64 4\n3 40\n2 56\n41 49\n97 100\n86 34\n4...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
165
codeforces
16344fb7e2bc83409f14ef3f666a983c
King's Problem?
Every true king during his life must conquer the world, hold the Codeforces world finals, win pink panda in the shooting gallery and travel all over his kingdom. King Copa has already done the first three things. Now he just needs to travel all over the kingdom. The kingdom is an infinite plane with Cartesian coordina...
{"inputs": ["3 1\n0 1 2 1\n1", "3 1\n1 0 2 1\n1", "4 5\n0 5 -1 -5 2\n3", "4 1\n0 5 -1 -5 2\n3", "10 5\n-231 598 312 -837 -711 553 -439 351 83 -605 -738\n791", "100 31\n-577 101 691 -95 809 125 -934 -645 -838 -548 259 312 -501 -962 -629 -637 -797 -259 -258 -687 537 303 -6 431 64 229 -897 -942 -805 804 -608 84 992 -563 2...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
3
codeforces
1655768ab04bba468899388061617449
Cowboys
A very tense moment: *n* cowboys stand in a circle and each one points his colt at a neighbor. Each cowboy can point the colt to the person who follows or precedes him in clockwise direction. Human life is worthless, just like in any real western. The picture changes each second! Every second the cowboys analyse the s...
{"inputs": ["BABBBABBA", "ABABB", "ABABAB", "ABA", "AABB", "ABABBABBAABAB", "AAABAABABA", "ABABABABABABABABABAB", "BABABABABAAAABABAAAABAB", "ABABABBABA", "BBB", "AAAA", "ABBAB", "BBBABB", "BABBBBB", "ABABBAAB", "ABBBABBAB", "BAAABBBBBA", "AAAAAAAAAAA", "BABBAAAABAAA", "ABABBBABBBAAA", "BBBBBABBBBBABB", "AAAAAAAABAAAAA...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1
codeforces
166c3a794830622ff41a4fd1297a07d0
System Administrator
Polycarpus is a system administrator. There are two servers under his strict guidance — *a* and *b*. To stay informed about the servers' performance, Polycarpus executes commands "ping a" and "ping b". Each ping command sends exactly ten packets to the server specified in the argument of the command. Executing a progra...
{"inputs": ["2\n1 5 5\n2 6 4", "3\n1 0 10\n2 0 10\n1 10 0", "10\n1 3 7\n2 4 6\n1 2 8\n2 5 5\n2 10 0\n2 10 0\n1 8 2\n2 2 8\n2 10 0\n1 1 9", "11\n1 8 2\n1 6 4\n1 9 1\n1 7 3\n2 0 10\n2 0 10\n1 8 2\n2 2 8\n2 6 4\n2 7 3\n2 9 1", "12\n1 5 5\n1 0 10\n1 4 6\n1 2 8\n1 2 8\n1 5 5\n1 9 1\n2 9 1\n1 5 5\n1 1 9\n2 9 1\n2 7 3", "13\n...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
300
codeforces
16830fb49b20765e78781cea4be2a97f
The Contest
Pasha is participating in a contest on one well-known website. This time he wants to win the contest and will do anything to get to the first place! This contest consists of *n* problems, and Pasha solves *i*th problem in *a**i* time units (his solutions are always correct). At any moment of time he can be thinking ab...
{"inputs": ["2\n3 4\n2\n1 4\n7 9", "1\n5\n1\n1 4", "1\n5\n1\n1 5", "5\n100000 100000 100000 100000 100000\n0", "5\n886 524 128 4068 298\n3\n416 3755\n4496 11945\n17198 18039", "10\n575 3526 1144 1161 889 1038 790 19 765 357\n2\n4475 10787\n16364 21678", "1\n4\n1\n5 9", "1\n200\n4\n1 10\n20 40\n50 55\n190 210", "4\n643 ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
85
codeforces
168f6f1983f3160ebd9573e0d6a26d69
Display Size
A big company decided to launch a new series of rectangular displays, and decided that the display must have exactly *n* pixels. Your task is to determine the size of the rectangular display — the number of lines (rows) of pixels *a* and the number of columns of pixels *b*, so that: - there are exactly *n* pixels o...
{"inputs": ["8", "64", "5", "999999", "716539", "1", "2", "3", "4", "6", "7", "9", "10", "11", "12", "15", "100", "101", "169", "179", "190", "1000", "10000", "10001", "100000", "100001", "1000000", "999983", "524288", "954493", "966289", "944663", "912673", "732641", "232897", "16807", "999958", "990151", "997002", "2...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
236
codeforces
16a03da19a666d6d16782abb48417091
Division into Teams
Petya loves football very much, especially when his parents aren't home. Each morning he comes to the yard, gathers his friends and they play all day. From time to time they have a break to have some food or do some chores (for example, water the flowers). The key in football is to divide into teams fairly before the ...
{"inputs": ["3\n1 2 1", "5\n2 3 3 1 1", "10\n2 2 2 2 2 2 2 1 2 2", "10\n2 3 3 1 3 1 1 1 2 2", "10\n2 3 2 3 3 1 1 3 1 1", "11\n1 3 1 2 1 2 2 2 1 1 1", "11\n54 83 96 75 33 27 36 35 26 22 77", "11\n1 1 1 1 1 1 1 1 1 1 1", "2\n1 1", "2\n35 36", "25\n1 2 2 1 2 2 2 2 2 1 1 2 2 2 2 2 1 2 2 2 1 1 2 2 1", "27\n2 1 1 3 1 2 1 1 3...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
13
codeforces
16ccd5806786645d788c5a6d9bc85b1e
Little Elephant and Problem
The Little Elephant has got a problem — somebody has been touching his sorted by non-decreasing array *a* of length *n* and possibly swapped some elements of the array. The Little Elephant doesn't want to call the police until he understands if he could have accidentally changed the array himself. He thinks that he co...
{"inputs": ["2\n1 2", "3\n3 2 1", "4\n4 3 2 1", "3\n1 3 2", "2\n2 1", "9\n7 7 8 8 10 10 10 10 1000000000", "10\n1 2 9 4 5 6 7 8 3 10", "4\n2 2 2 1", "10\n1 2 4 4 4 5 5 7 7 10", "10\n4 5 11 12 13 14 16 16 16 18", "20\n38205814 119727790 127848638 189351562 742927936 284688399 318826601 326499046 387938139 395996609 4944...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
183
codeforces
16e2a8ba7b90c835d233f81974a1987e
A and B and Interesting Substrings
A and B are preparing themselves for programming contests. After several years of doing sports programming and solving many problems that require calculating all sorts of abstract objects, A and B also developed rather peculiar tastes. A likes lowercase letters of the Latin alphabet. He has assigned to each letter a ...
{"inputs": ["1 1 -1 1 1 1 1 1 1 1 1 1 1 1 1 7 1 1 1 8 1 1 1 1 1 1\nxabcab", "1 1 -1 1 1 1 1 1 1 1 1 1 1 1 1 7 1 1 1 8 1 1 1 1 1 1\naaa", "1 1 -1 1 1 1 1 1 1 1 1 1 1 1 1 7 1 1 1 8 1 1 1 1 1 1\naabbccdd", "-3 4 -4 -1 3 5 -5 -3 3 2 1 4 5 -3 -1 4 2 -2 1 -1 1 5 -4 0 -5 4\nolspxykjqr", "-2 -2 2 1 4 0 -2 4 5 4 -5 -5 2 1 1 -1 ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
19
codeforces
16ea217382917bb89accb42f3a9c6795
Flag
According to a new ISO standard, a flag of every country should have a chequered field *n*<=×<=*m*, each square should be of one of 10 colours, and the flag should be «striped»: each horizontal row of the flag should contain squares of the same colour, and the colours of adjacent horizontal rows should be different. Be...
{"inputs": ["3 3\n000\n111\n222", "3 3\n000\n000\n111", "3 3\n000\n111\n002", "10 10\n2222222222\n5555555555\n0000000000\n4444444444\n1111111111\n3333333393\n3333333333\n5555555555\n0000000000\n8888888888", "10 13\n4442444444444\n8888888888888\n6666666666666\n0000000000000\n3333333333333\n4444444444444\n7777777777777\n...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
284
codeforces
16ecf492d63595584a0ea1707994c224
Lala Land and Apple Trees
Amr lives in Lala Land. Lala Land is a very beautiful country that is located on a coordinate line. Lala Land is famous with its apple trees growing everywhere. Lala Land has exactly *n* apple trees. Tree number *i* is located in a position *x**i* and has *a**i* apples growing on it. Amr wants to collect apples from t...
{"inputs": ["2\n-1 5\n1 5", "3\n-2 2\n1 4\n-1 3", "3\n1 9\n3 5\n7 10", "1\n1 1", "4\n10000 100000\n-1000 100000\n-2 100000\n-1 100000", "1\n-1 1", "27\n-30721 24576\n-6620 92252\n88986 24715\n-94356 10509\n-6543 29234\n-68554 69530\n39176 96911\n67266 99669\n95905 51002\n-94093 92134\n65382 23947\n-6525 79426\n-448 675...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
152
codeforces
172d355f207b1c6d888955b4a88727e9
Mahmoud and Longest Uncommon Subsequence
While Mahmoud and Ehab were practicing for IOI, they found a problem which name was Longest common subsequence. They solved it, and then Ehab challenged Mahmoud with another problem. Given two strings *a* and *b*, find the length of their longest uncommon subsequence, which is the longest string that is a subsequence ...
{"inputs": ["abcd\ndefgh", "a\na", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaacccccccccccccccccccccccccccccccccccccccccccccccccc\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaadddddddddddddddddddddddddddddddddddddddddddddddddd", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
184
codeforces
175a9fbb6934af1423c16e2e891e9830
Pashmak and Buses
Recently Pashmak has been employed in a transportation company. The company has *k* buses and has a contract with a school which has *n* students. The school planned to take the students to *d* different places for *d* days (each day in one place). Each day the company provides all the buses for the trip. Pashmak has t...
{"inputs": ["3 2 2", "3 2 1", "7 2 3", "9 2 3", "2 1 1000", "512 2 9", "1000 1000000000 511", "1000 1000 1", "1000 3 1000", "1 1000000000 512", "1000 2 1000", "1000 3 1000", "1000 31 1000", "1000 32 1000", "1000 999 1000", "1000 1000 1000", "1000 536870912 1000", "1000 536870911 1000", "1000 1000000000 1000", "1000 2 8...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
7
codeforces
1781dd23263cc5f4456420d34bd9eaa4
Pashmak and Parmida's problem
Parmida is a clever girl and she wants to participate in Olympiads this year. Of course she wants her partner to be clever too (although he's not)! Parmida has prepared the following test problem for Pashmak. There is a sequence *a* that consists of *n* integers *a*1,<=*a*2,<=...,<=*a**n*. Let's denote *f*(*l*,<=*r*,<...
{"inputs": ["7\n1 2 1 1 2 2 1", "3\n1 1 1", "5\n1 2 3 4 5", "24\n1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4", "1\n1", "2\n1 2", "2\n1 1", "4\n1 1 2 2", "5\n1 1 2 2 2"], "outputs": ["8", "1", "0", "114", "0", "0", "0", "1", "2"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
14
codeforces
17ec4d515c12743261193390f42cb456
Mr. Bender and Square
Mr. Bender has a digital table of size *n*<=×<=*n*, each cell can be switched on or off. He wants the field to have at least *c* switched on squares. When this condition is fulfilled, Mr Bender will be happy. We'll consider the table rows numbered from top to bottom from 1 to *n*, and the columns — numbered from left ...
{"inputs": ["6 4 3 1", "9 3 8 10", "9 4 3 10", "9 8 2 10", "1 1 1 1", "10 7 2 7", "8 2 6 10", "8 1 2 10", "6 1 4 10", "1000000 951981 612086 60277", "1000000 587964 232616 62357", "1000000 948438 69861 89178", "1000000000 504951981 646612086 602763371", "1000000000 81587964 595232616 623563697", "1000000000 55 60 71518...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
7
codeforces
17ff19eef74317819cc833b0e6176d2b
Heidi and Library (hard)
The good times at Heidi's library are over. Marmots finally got their internet connections and stopped coming to the library altogether. Not only that, but the bookstore has begun charging extortionate prices for some books. Namely, whereas in the previous versions each book could be bought for 1 CHF, now the price of ...
{"inputs": ["4 80\n1 2 2 1\n1 1 1 1", "4 1\n1 2 2 1\n1 1 1 1", "4 2\n1 2 3 1\n1 1 1 1", "7 2\n1 2 3 1 1 1 2\n1 10 1 0 0 0 0", "11 1\n1 2 3 5 1 10 10 1 1 3 5\n1 1 2 3 4 5 6 7 8 9 10", "5 2\n1 2 3 1 2\n1 1 1 1 1", "4 2\n1 2 3 2\n1 1 1 1", "80 4\n2 6 10 4 7 8 2 8 9 10 6 2 5 3 2 10 5 9 1 3 4 8 6 1 9 3 9 4 7 7 4 6 4 8 1 2 5...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1
codeforces
183d5529b0961a41597819ab12cd61be
Voltage Keepsake
You have *n* devices that you want to use simultaneously. The *i*-th device uses *a**i* units of power per second. This usage is continuous. That is, in λ seconds, the device will use λ·*a**i* units of power. The *i*-th device currently has *b**i* units of power stored. All devices can store an arbitrary amount of pow...
{"inputs": ["2 1\n2 2\n2 1000", "1 100\n1 1", "3 5\n4 3\n5 2\n6 1", "1 1\n1 87", "1 1\n100 77", "5 10\n3 81\n3 49\n1 20\n1 12\n1 30", "5 10\n4 3\n1 54\n2 57\n2 31\n1 99", "5 10\n2 81\n3 31\n4 49\n1 35\n1 67", "10 1\n1 92\n1 92\n1 92\n1 92\n1 92\n1 92\n1 92\n1 92\n1 92\n1 92", "10 1\n1 16\n1 16\n1 16\n1 16\n1 16\n1 16\n...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
22
codeforces
18570e5f148ba4dbe6c04aea7fe63509
Combination Lock
Scrooge McDuck keeps his most treasured savings in a home safe with a combination lock. Each time he wants to put there the treasures that he's earned fair and square, he has to open the lock. The combination lock is represented by *n* rotating disks with digits from 0 to 9 written on them. Scrooge McDuck has to turn ...
{"inputs": ["5\n82195\n64723", "12\n102021090898\n010212908089", "1\n8\n1", "2\n83\n57", "10\n0728592530\n1362615763", "100\n4176196363694273682807653052945037727131821799902563705176501742060696655282954944720643131654235909\n345991208492215450591028749987997565929823937151988986658547267442300883787812306710300534498...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
899
codeforces
18574ec81ce029d7932890bfd5465160
Restoration of the Permutation
Let *A*<==<={*a*1,<=*a*2,<=...,<=*a**n*} be any permutation of the first *n* natural numbers {1,<=2,<=...,<=*n*}. You are given a positive integer *k* and another sequence *B*<==<={*b*1,<=*b*2,<=...,<=*b**n*}, where *b**i* is the number of elements *a**j* in *A* to the left of the element *a**t*<==<=*i* such that *a**j...
{"inputs": ["5 2\n1 2 1 0 0", "4 2\n1 0 0 0", "10 3\n4 2 4 2 1 0 1 0 0 0", "15 3\n4 2 7 5 1 1 1 0 0 0 0 0 0 0 0", "5 1\n1 3 2 0 0", "8 3\n2 0 2 2 1 0 0 0", "1 1\n0", "10 10\n0 0 0 0 0 0 0 0 0 0", "10 9\n1 0 0 0 0 0 0 0 0 0", "10 1\n9 8 7 6 5 4 3 2 1 0", "10 1\n7 6 5 4 3 2 1 0 0 0", "13 2\n1 2 3 4 5 4 3 2 1 0 0 0 0", "2...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
6
codeforces
1863b6f28ad0474a2c0dc6ef0e81a030
Megacity
The administration of the Tomsk Region firmly believes that it's time to become a megacity (that is, get population of one million). Instead of improving the demographic situation, they decided to achieve its goal by expanding the boundaries of the city. The city of Tomsk can be represented as point on the plane with ...
{"inputs": ["4 999998\n1 1 1\n2 2 1\n3 3 1\n2 -2 1", "4 999998\n1 1 2\n2 2 1\n3 3 1\n2 -2 1", "2 1\n1 1 999997\n2 2 1", "4 999998\n3 3 10\n-3 3 10\n3 -3 10\n-3 -3 10", "15 95473\n-9 6 199715\n0 -8 110607\n0 2 6621\n-3 -2 59894\n-10 -8 175440\n-2 0 25814\n10 -4 68131\n7 1 9971\n6 7 821\n6 5 20208\n6 2 68468\n0 7 37427\n...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
120
codeforces
18676c03598b38db0d03c7b1d0fce954
Dijkstra?
You are given a weighted undirected graph. The vertices are enumerated from 1 to *n*. Your task is to find the shortest path between the vertex 1 and the vertex *n*. The first line contains two integers *n* and *m* (2<=≤<=*n*<=≤<=105,<=0<=≤<=*m*<=≤<=105), where *n* is the number of vertices and *m* is the number of edg...
{"inputs": ["5 6\n1 2 2\n2 5 5\n2 3 4\n1 4 1\n4 3 3\n3 5 1", "5 6\n1 2 2\n2 5 5\n2 3 4\n1 4 1\n4 3 3\n3 5 1", "2 1\n1 2 1", "3 1\n1 2 1", "3 3\n1 2 1\n1 3 2\n2 3 1", "10 10\n1 5 12\n2 4 140\n2 10 149\n3 6 154\n3 7 9\n3 8 226\n3 10 132\n4 10 55\n5 8 33\n7 8 173", "10 10\n1 5 178\n1 8 221\n2 7 92\n2 8 159\n3 5 55\n3 6 17...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
147
codeforces
18731b0885aaff022fbbdb83087c9a43
Lucky Ticket
Petya loves lucky numbers very much. Everybody knows that lucky numbers are positive integers whose decimal record contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Petya loves tickets very much. As we know, each ticket has a number that is a positive integer. It...
{"inputs": ["2\n47", "4\n4738", "4\n4774", "4\n4570", "6\n477477", "6\n777777", "20\n44444444444444444444", "2\n44", "10\n4745474547", "14\n77770004444444", "10\n4747777744", "10\n1234567890", "50\n44444444444444444444444444444444444444444444444444", "50\n44444444444444444444444444444444444444444444444447", "50\n744444...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
461
codeforces
189d83c2d5a6b1b0f0bde452f2187d0a
Yaroslav and Time
Yaroslav is playing a game called "Time". The game has a timer showing the lifespan he's got left. As soon as the timer shows 0, Yaroslav's character dies and the game ends. Also, the game has *n* clock stations, station number *i* is at point (*x**i*,<=*y**i*) of the plane. As the player visits station number *i*, he ...
{"inputs": ["3 1000\n1000\n0 0\n0 1\n0 3", "3 1000\n1000\n1 0\n1 1\n1 2", "5 1421\n896 448 727\n-19 -40\n-87 40\n69 51\n-55 61\n-7 67", "6 1000\n142 712 254 869\n7 0\n95 38\n96 -20\n-7 93\n75 -45\n-80 -20", "7 1288\n943 265 649 447 806\n-4 -51\n-26 32\n47 -28\n31 32\n61 65\n-45 -37\n82 42", "8 1931\n440 627 324 538 539...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
9
codeforces
18b11fdbe3798b0b5243958f3bf2e4ef
Dependency management
Polycarp is currently developing a project in Vaja language and using a popular dependency management system called Vamen. From Vamen's point of view both Vaja project and libraries are treated projects for simplicity. A project in Vaja has its own uniqie non-empty name consisting of lowercase latin letters with lengt...
{"inputs": ["4\na 3\n2\nb 1\nc 1\n\nb 2\n0\n\nb 1\n1\nb 2\n\nc 1\n1\nb 2", "9\ncodehorses 5\n3\nwebfrmk 6\nmashadb 1\nmashadb 2\n\ncommons 2\n0\n\nmashadb 3\n0\n\nwebfrmk 6\n2\nmashadb 3\ncommons 2\n\nextra 4\n1\nextra 3\n\nextra 3\n0\n\nextra 1\n0\n\nmashadb 1\n1\nextra 3\n\nmashadb 2\n1\nextra 1", "3\nabc 1\n2\nabc 3...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
8
codeforces
18cd04f66c3a25d8ef9c84aaf20ac88c
Vicious Keyboard
Tonio has a keyboard with only two letters, "V" and "K". One day, he has typed out a string *s* with only these two letters. He really likes it when the string "VK" appears, so he wishes to change at most one letter in the string (or do no changes) to maximize the number of occurrences of that string. Compute the maxi...
{"inputs": ["VK", "VV", "V", "VKKKKKKKKKVVVVVVVVVK", "KVKV", "VKKVVVKVKVK", "VKVVKVKVVKVKKKKVVVVVVVVKVKVVVVVVKKVKKVKVVKVKKVVVVKV", "VVKKVKKVVKKVKKVKVVKKVKKVVKKVKVVKKVKKVKVVKKVVKKVKVVKKVKVVKKVVKVVKKVKKVKKVKKVKKVKVVKKVKKVKKVKKVKKVVKVK", "KVVKKVKVKVKVKVKKVKVKVVKVKVVKVVKVKKVKVKVKVKVKVKVKVKVKVKVKVKVKVKVVKVKVVKKVKVKK", "KVVV...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
142
codeforces
18dfbace2937f92f8edc7f2509adeb06
Dishonest Sellers
Igor found out discounts in a shop and decided to buy *n* items. Discounts at the store will last for a week and Igor knows about each item that its price now is *a**i*, and after a week of discounts its price will be *b**i*. Not all of sellers are honest, so now some products could be more expensive than after a week...
{"inputs": ["3 1\n5 4 6\n3 1 5", "5 3\n3 4 7 10 3\n4 5 5 12 5", "1 0\n9\n8", "2 0\n4 10\n1 2", "4 2\n19 5 17 13\n3 18 8 10", "5 3\n28 17 20 45 45\n39 12 41 27 9", "10 5\n87 96 19 81 10 88 7 49 36 21\n11 75 28 28 74 17 64 19 81 31", "50 45\n80 125 152 122 85 62 123 195 157 73 8 127 47 193 70 132 131 38 98 97 185 98 68 1...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
213
codeforces
190cc916df6e471a15c1895a240a728e
A Simple Task
Given a simple graph, output the number of simple cycles in it. A simple cycle is a cycle with no repeated vertices or edges. The first line of input contains two integers *n* and *m* (1<=≤<=*n*<=≤<=19, 0<=≤<=*m*) – respectively the number of vertices and edges of the graph. Each of the subsequent *m* lines contains tw...
{"inputs": ["4 6\n1 2\n1 3\n1 4\n2 3\n2 4\n3 4", "10 3\n4 8\n9 4\n8 9", "8 28\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n2 3\n2 4\n2 5\n2 6\n2 7\n2 8\n3 4\n3 5\n3 6\n3 7\n3 8\n4 5\n4 6\n4 7\n4 8\n5 6\n5 7\n5 8\n6 7\n6 8\n7 8", "12 10\n1 6\n4 5\n4 9\n5 10\n6 12\n7 9\n7 10\n8 10\n10 12\n11 12", "3 0", "6 0", "2 1\n1 2", "2 1\n1...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1
codeforces
1920af96049061e297fe0a7e0d5bea73
Driving Test
Polycarp has just attempted to pass the driving test. He ran over the straight road with the signs of four types. - speed limit: this sign comes with a positive integer number — maximal speed of the car after the sign (cancel the action of the previous sign of this type); - overtake is allowed: this sign means that ...
{"inputs": ["11\n1 100\n3 70\n4\n2\n3 120\n5\n3 120\n6\n1 150\n4\n3 300", "5\n1 100\n3 200\n2\n4\n5", "7\n1 20\n2\n6\n4\n6\n6\n2", "1\n1 100", "2\n1 100\n2", "10\n1 37\n6\n5\n2\n5\n6\n5\n2\n4\n2", "10\n1 5\n4\n5\n4\n1 21\n6\n1 10\n1 1\n2\n3 1"], "outputs": ["2", "0", "2", "0", "0", "2", "1"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
17
codeforces
1954f4f3cff193e51aefea4a144bdfcb
Save Luke
Luke Skywalker got locked up in a rubbish shredder between two presses. R2D2 is already working on his rescue, but Luke needs to stay alive as long as possible. For simplicity we will assume that everything happens on a straight line, the presses are initially at coordinates 0 and *L*, and they move towards each other ...
{"inputs": ["2 6 2 2", "1 9 1 2", "1 10000 1 1", "9999 10000 10000 10000", "1023 2340 1029 3021", "2173 2176 10000 9989", "1 2 123 1", "123 1242 12 312", "2 9997 3 12", "1 10000 10000 10000", "3274 4728 888 4578", "4600 9696 5634 8248", "2255 7902 8891 429", "6745 9881 2149 9907", "4400 8021 6895 2089", "5726 9082 7448...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
241
codeforces
195a674edfdb1beb7260a34b31fe41f6
Weird Game
Yaroslav, Andrey and Roman can play cubes for hours and hours. But the game is for three, so when Roman doesn't show up, Yaroslav and Andrey play another game. Roman leaves a word for each of them. Each word consists of 2·*n* binary characters "0" or "1". After that the players start moving in turns. Yaroslav moves f...
{"inputs": ["2\n0111\n0001", "3\n110110\n001001", "3\n111000\n000111", "4\n01010110\n00101101", "4\n01100000\n10010011", "4\n10001001\n10101101", "3\n000000\n000100", "2\n0000\n1110", "4\n11111111\n10100110", "4\n10100111\n11011000", "4\n00101011\n11110100", "4\n11000011\n00111100", "4\n11101111\n01000110", "4\n0111011...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
8
codeforces
19652a10a291705df6b35df2213433ea
Random Teams
*n* participants of the competition were split into *m* teams in some manner so that each team has at least one participant. After the competition each pair of participants from the same team became friends. Your task is to write a program that will find the minimum and the maximum number of pairs of friends that coul...
{"inputs": ["5 1", "3 2", "6 3", "5 3", "10 2", "10 6", "1000000000 1", "5000000 12", "1833 195", "1000000000 1000000000", "1000000000 1000000", "1000000000 32170", "1000000 1000", "1234 1123", "599222887 298488", "999999999 500000000", "1000000000 384842119", "1000000000 384842119", "1000000000 2", "1000000000 9999999...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
239
codeforces
19822dd149e51b421976d336fb1fb4a8
Equal Sums
You are given $k$ sequences of integers. The length of the $i$-th sequence equals to $n_i$. You have to choose exactly two sequences $i$ and $j$ ($i \ne j$) such that you can remove exactly one element in each of them in such a way that the sum of the changed sequence $i$ (its length will be equal to $n_i - 1$) equals...
{"inputs": ["2\n5\n2 3 1 3 2\n6\n1 1 2 2 2 1", "3\n1\n5\n5\n1 1 1 1 1\n2\n2 3", "4\n6\n2 2 2 2 2 2\n5\n2 2 2 2 2\n3\n2 2 2\n5\n2 2 2 2 2", "2\n2\n0 -10000\n2\n10000 0"], "outputs": ["YES\n2 1\n1 4", "NO", "YES\n4 1\n2 5", "YES\n2 1\n1 2"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
37
codeforces
198410fd502067f83e7e63ffb6065693
Distance in Tree
A tree is a connected graph that doesn't contain any cycles. The distance between two vertices of a tree is the length (in edges) of the shortest path between these vertices. You are given a tree with *n* vertices and a positive number *k*. Find the number of distinct pairs of the vertices which have a distance of ex...
{"inputs": ["5 2\n1 2\n2 3\n3 4\n2 5", "5 3\n1 2\n2 3\n3 4\n4 5", "10 1\n2 1\n3 1\n4 3\n5 4\n6 5\n7 1\n8 6\n9 2\n10 6", "10 2\n2 1\n3 1\n4 3\n5 4\n6 5\n7 1\n8 6\n9 2\n10 6", "10 3\n2 1\n3 1\n4 3\n5 4\n6 5\n7 1\n8 6\n9 2\n10 6", "50 3\n2 1\n3 2\n4 3\n5 4\n6 5\n7 6\n8 7\n9 8\n10 9\n11 10\n12 11\n13 12\n14 13\n15 14\n16 1...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
12
codeforces
19a6ec21c8071eaac811c5d886bdbcb5
Bear and Friendship Condition
Bear Limak examines a social network. Its main functionality is that two members can become friends (then they can talk with each other and share funny pictures). There are *n* members, numbered 1 through *n*. *m* pairs of members are friends. Of course, a member can't be a friend with themselves. Let A-B denote that...
{"inputs": ["4 3\n1 3\n3 4\n1 4", "4 4\n3 1\n2 3\n3 4\n1 2", "10 4\n4 3\n5 10\n8 9\n1 2", "3 2\n1 2\n2 3", "3 0", "15 42\n8 1\n3 14\n7 14\n12 3\n7 9\n6 7\n6 12\n14 12\n3 10\n10 14\n6 3\n3 13\n13 10\n7 12\n7 2\n6 10\n11 4\n9 3\n8 4\n7 3\n2 3\n2 10\n9 13\n2 14\n6 14\n13 2\n1 4\n13 6\n7 10\n13 14\n12 10\n13 7\n12 2\n9 10\...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
79
codeforces
19abaf75e3070d35d8add03d295b55c9
Romaji
Vitya has just started learning Berlanese language. It is known that Berlanese uses the Latin alphabet. Vowel letters are "a", "o", "u", "i", and "e". Other letters are consonant. In Berlanese, there has to be a vowel after every consonant, but there can be any letter after any vowel. The only exception is a consonant...
{"inputs": ["sumimasen", "ninja", "codeforces", "auuaoonntanonnuewannnnpuuinniwoonennyolonnnvienonpoujinndinunnenannmuveoiuuhikucuziuhunnnmunzancenen", "n", "necnei", "nternn", "aucunuohja", "a", "b", "nn", "nnnzaaa", "zn", "ab", "aaaaaaaaaa", "aaaaaaaaab", "aaaaaaaaan", "baaaaaaaaa", "naaaaaaaaa", "nbaaaaaaaa", "bbaaa...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
159
codeforces
19c0291bd1c79abe04f3ac01b584c1e5
Powerful array
An array of positive integers *a*1,<=*a*2,<=...,<=*a**n* is given. Let us consider its arbitrary subarray *a**l*,<=*a**l*<=+<=1...,<=*a**r*, where 1<=≤<=*l*<=≤<=*r*<=≤<=*n*. For every positive integer *s* denote by *K**s* the number of occurrences of *s* into the subarray. We call the power of the subarray the sum of p...
{"inputs": ["3 2\n1 2 1\n1 2\n1 3", "8 3\n1 1 2 2 1 3 1 1\n2 7\n1 6\n2 7", "20 8\n1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2\n4 15\n1 2\n2 20\n7 7\n13 18\n7 7\n3 19\n3 8", "10 5\n10 9 8 7 6 5 4 3 2 1\n4 8\n1 10\n3 9\n2 2\n5 10", "8 10\n100 100 100 100 100 100 100 100\n1 8\n2 8\n3 8\n4 8\n5 8\n6 8\n7 8\n8 8\n1 1\n1 5", "1 ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1
codeforces
19d2ecccfa97f05d68273ed6f8fa0fd3
Permutations
You are given *n* *k*-digit integers. You have to rearrange the digits in the integers so that the difference between the largest and the smallest number was minimum. Digits should be rearranged by the same rule in all integers. The first line contains integers *n* and *k* — the number and digit capacity of numbers cor...
{"inputs": ["6 4\n5237\n2753\n7523\n5723\n5327\n2537", "3 3\n010\n909\n012", "7 5\n50808\n36603\n37198\n44911\n29994\n42543\n50156", "5 5\n61374\n74304\n41924\n46010\n09118", "8 8\n68785928\n11981277\n32480720\n72495162\n69969623\n42118868\n64235849\n81412116", "7 1\n1\n0\n8\n5\n4\n9\n8", "3 8\n34848224\n16307102\n2518...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
16
codeforces
19d770e2c74d695b37b93d822093c5aa
Marathon
Valera takes part in the Berland Marathon. The marathon race starts at the stadium that can be represented on the plane as a square whose lower left corner is located at point with coordinates (0,<=0) and the length of the side equals *a* meters. The sides of the square are parallel to coordinate axes. As the length o...
{"inputs": ["2 5\n2", "4.147 2.8819\n6", "16904.8597 21646.2846\n10", "40356.3702 72886.7142\n100", "70092.4982 95833.7741\n1000", "39712.7105 19285.2846\n10000", "97591.0354 49021.4126\n100000", "1 100000\n100000", "1 1\n1", "99999.9999 99999.9998\n100000", "1.0001 9999.9999\n100000", "100000 1\n100000", "100000 10000...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
6
codeforces
19dae5f00909e7d63f427950e41e714c
Game with Coins
Two pirates Polycarpus and Vasily play a very interesting game. They have *n* chests with coins, the chests are numbered with integers from 1 to *n*. Chest number *i* has *a**i* coins. Polycarpus and Vasily move in turns. Polycarpus moves first. During a move a player is allowed to choose a positive integer *x* (2·*x...
{"inputs": ["1\n1", "3\n1 2 3", "100\n269 608 534 956 993 409 297 735 258 451 468 422 125 407 580 769 857 383 419 67 377 230 842 113 169 427 287 75 372 133 456 450 644 303 638 40 217 445 427 730 168 341 371 633 237 951 142 596 528 509 236 782 44 467 607 326 267 15 564 858 499 337 74 346 443 436 48 795 206 403 379 313 3...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
9
codeforces
19e898254aab6b1c7f5fa0c9454533fb
R3D3’s Summer Adventure
R3D3 spent some time on an internship in MDCS. After earning enough money, he decided to go on a holiday somewhere far, far away. He enjoyed suntanning, drinking alcohol-free cocktails and going to concerts of popular local bands. While listening to "The White Buttons" and their hit song "Dacan the Baker", he met anoth...
{"inputs": ["4 1 2", "2 1 5", "3 1 1", "5 5 5", "4 0 0", "6 0 6", "6 6 0", "2 1 2", "100000000 1 0", "2 0 0", "2 100000000 100000000", "2 100000000 0", "2 0 100000000", "100000000 0 0", "100000000 100000000 100000000", "100000000 100000000 0", "100000000 0 100000000", "2 50000000 0", "2 50000000 100000000", "2 50000000...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
2
codeforces
1a01e8cd6ea9e6b13f69248a9cdca0db
Monitor
Reca company makes monitors, the most popular of their models is AB999 with the screen size *a*<=×<=*b* centimeters. Because of some production peculiarities a screen parameters are integer numbers. Recently the screen sides ratio *x*:<=*y* became popular with users. That's why the company wants to reduce monitor AB999...
{"inputs": ["800 600 4 3", "1920 1200 16 9", "1 1 1 2", "1002105126 227379125 179460772 1295256518", "625166755 843062051 1463070160 1958300154", "248228385 1458744978 824699604 1589655888", "186329049 1221011622 90104472 1769702163", "511020182 242192314 394753578 198572007", "134081812 857875240 82707261 667398699", ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
34
codeforces
1a3833e219a41346e746f849967f9b3c
Meeting
The Super Duper Secret Meeting of the Super Duper Secret Military Squad takes place in a Super Duper Secret Place. The place is an infinite plane with introduced Cartesian coordinate system. The meeting table is represented as a rectangle whose sides are parallel to the coordinate axes and whose vertexes are located at...
{"inputs": ["2 5 4 2\n3\n3 1 2\n5 3 1\n1 3 2", "5 2 6 3\n2\n6 2 2\n6 5 3", "-705 595 -702 600\n1\n-589 365 261", "-555 674 -553 774\n5\n-656 128 631\n597 -220 999\n-399 793 155\n-293 -363 1000\n-557 -914 1000", "-210 783 -260 833\n10\n406 551 1000\n372 -373 999\n-12 -532 999\n371 -30 999\n258 480 558\n648 -957 1000\n-7...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
7
codeforces
1a3944c48c6207815c1e4c534d54831f
Sereja and Table
Sereja has an *n*<=×<=*m* rectangular table *a*, each cell of the table contains a zero or a number one. Sereja wants his table to meet the following requirement: each connected component of the same values forms a rectangle with sides parallel to the sides of the table. Rectangles should be filled with cells, that is,...
{"inputs": ["5 5 2\n1 1 1 1 1\n1 1 1 1 1\n1 1 0 1 1\n1 1 1 1 1\n1 1 1 1 1", "3 4 1\n1 0 0 0\n0 1 1 1\n1 1 1 0", "3 4 1\n1 0 0 1\n0 1 1 0\n1 0 0 1", "8 1 4\n0\n0\n0\n1\n0\n1\n1\n0", "3 10 7\n0 1 0 0 1 0 1 0 0 0\n0 0 1 1 0 0 0 1 0 1\n1 0 1 1 1 0 1 1 0 0", "4 9 7\n0 0 0 1 0 1 1 0 0\n1 1 1 0 0 0 0 1 1\n1 1 0 0 1 1 0 1 0\n0...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
3
codeforces
1a542256851fbf03363cd7fffc84c4a0
Bear and Tree Jumps
A tree is an undirected connected graph without cycles. The distance between two vertices is the number of edges in a simple path between them. Limak is a little polar bear. He lives in a tree that consists of *n* vertices, numbered 1 through *n*. Limak recently learned how to jump. He can jump from a vertex to any v...
{"inputs": ["6 2\n1 2\n1 3\n2 4\n2 5\n4 6", "13 3\n1 2\n3 2\n4 2\n5 2\n3 6\n10 6\n6 7\n6 13\n5 8\n5 9\n9 11\n11 12", "3 5\n2 1\n3 1", "2 1\n1 2", "2 5\n2 1", "15 1\n12 9\n13 7\n1 3\n10 4\n9 2\n2 15\n11 4\n2 14\n10 8\n6 7\n12 5\n8 7\n3 10\n10 2", "4 2\n3 4\n2 4\n3 1", "12 3\n5 11\n10 11\n6 4\n8 9\n4 12\n10 7\n4 1\n3 1\n...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1
codeforces
1aa40a049ab142e496e372c4df124c0a
Perfect Security
Alice has a very important message *M* consisting of some non-negative integers that she wants to keep secret from Eve. Alice knows that the only theoretically secure cipher is one-time pad. Alice generates a random key *K* of the length equal to the message's length. Alice computes the bitwise xor of each element of t...
{"inputs": ["3\n8 4 13\n17 2 7", "5\n12 7 87 22 11\n18 39 9 12 16", "10\n331415699 278745619 998190004 423175621 42983144 166555524 843586353 802130100 337889448 685310951\n226011312 266003835 342809544 504667531 529814910 684873393 817026985 844010788 993949858 1031395667", "5\n134 246 57 176 239\n14 83 97 175 187", "...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
3
codeforces