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
94ac7aa8df66cdfd45baecfb72de495b
Network Mask
The problem uses a simplified TCP/IP address model, please make sure you've read the statement attentively. Polycarpus has found a job, he is a system administrator. One day he came across *n* IP addresses. Each IP address is a 32 bit number, represented as a group of four 8-bit numbers (without leading zeroes), separ...
{"inputs": ["5 3\n0.0.0.1\n0.1.1.2\n0.0.2.1\n0.1.1.0\n0.0.2.3", "5 2\n0.0.0.1\n0.1.1.2\n0.0.2.1\n0.1.1.0\n0.0.2.3", "2 1\n255.0.0.1\n0.0.0.2", "10 2\n57.11.146.42\n200.130.164.235\n52.119.155.71\n113.10.216.20\n28.23.6.128\n190.112.90.85\n7.37.210.55\n20.190.120.226\n170.124.158.110\n122.157.34.141", "11 4\n30.181.69.1...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
2
codeforces
94c0b5d0cd3a264fb19232cc2aa4236a
Chemistry in Berland
Igor is a post-graduate student of chemistry faculty in Berland State University (BerSU). He needs to conduct a complicated experiment to write his thesis, but laboratory of BerSU doesn't contain all the materials required for this experiment. Fortunately, chemical laws allow material transformations (yes, chemistry i...
{"inputs": ["3\n1 2 3\n3 2 1\n1 1\n1 1", "3\n3 2 1\n1 2 3\n1 1\n1 2", "5\n2 1 1 2 3\n1 2 2 2 1\n1 2\n1 3\n2 4\n1 4", "10\n2 8 6 1 2 7 6 9 2 8\n4 9 4 3 5 2 9 3 7 3\n1 8\n2 8\n3 8\n4 10\n5 1\n6 4\n7 3\n8 10\n9 2", "5\n27468 7465 74275 40573 40155\n112071 76270 244461 264202 132397\n1 777133331\n2 107454154\n3 652330694\n...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
3
codeforces
94f22c184db967f634f47abb84439aea
Dima and Trap Graph
Dima and Inna love spending time together. The problem is, Seryozha isn't too enthusiastic to leave his room for some reason. But Dima and Inna love each other so much that they decided to get criminal... Dima constructed a trap graph. He shouted: "Hey Seryozha, have a look at my cool graph!" to get his roommate inter...
{"inputs": ["4 4\n1 2 1 10\n2 4 3 5\n1 3 1 5\n2 4 2 7", "5 6\n1 2 1 10\n2 5 11 20\n1 4 2 5\n1 3 10 11\n3 4 12 10000\n4 5 6 6", "6 6\n1 2 1 10\n2 3 1 10\n3 6 1 1\n1 4 1 4\n4 5 1 3\n5 6 1 3", "2 1\n1 2 1 1", "10 0", "5 5\n1 5 9403 40347\n1 3 13851 29314\n4 5 1315 561894\n3 5 2748 33090\n5 3 10717 32306", "1000 0"], "outp...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1
codeforces
94f5f504815e2f4db2c2158e710bb9ad
TV Game
There is a new TV game on BerTV. In this game two players get a number *A* consisting of 2*n* digits. Before each turn players determine who will make the next move. Each player should make exactly *n* moves. On it's turn *i*-th player takes the leftmost digit of *A* and appends it to his or her number *S**i*. After th...
{"inputs": ["2\n1234", "2\n9911", "2\n0153", "3\n614615", "4\n21305374", "4\n00013213", "1\n01", "1\n21", "1\n99", "18\n999999999999999999999999999999999999", "10\n89959999998998796989", "10\n99999988899989998889", "7\n10210320200120", "18\n949787136121830145537930861689777414", "18\n95685957978983485816721877889379638...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
3
codeforces
950b70b0c59e455e4a9d58b8858b308d
Plant
Dwarfs have planted a very interesting plant, which is a triangle directed "upwards". This plant has an amusing feature. After one year a triangle plant directed "upwards" divides into four triangle plants: three of them will point "upwards" and one will point "downwards". After another year, each triangle plant divide...
{"inputs": ["1", "2", "385599124", "989464295", "376367012", "529357306", "782916801", "74859961358140080", "0", "252509053898415171", "760713016078377938", "919845424847912644", "585335721566249104", "522842183413115087", "148049062285906746", "84324827171274022", "354979172034763159", "1312148742261680", "26958744805...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
53
codeforces
950cdd5d07ef7b2fb94d84bbff05380a
Vanya and Books
Vanya got an important task — he should enumerate books in the library and label each book with its number. Each of the *n* books should be assigned with a number from 1 to *n*. Naturally, distinct books should be assigned distinct numbers. Vanya wants to know how many digits he will have to write down as he labels th...
{"inputs": ["13", "4", "100", "99", "1000000000", "1000000", "999", "55", "222222222", "8", "13", "313", "1342", "30140", "290092", "2156660", "96482216", "943006819", "1", "7", "35", "996", "6120", "30660", "349463", "8171970", "36123011", "986747865", "9", "10", "11", "101", "1000", "1001", "9999", "10000", "10001", ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
290
codeforces
950ec6b7587c04fab5f98f9b0f6f7140
Dima and Magic Guitar
Dima loves Inna very much. He decided to write a song for her. Dima has a magic guitar with *n* strings and *m* frets. Dima makes the guitar produce sounds like that: to play a note, he needs to hold one of the strings on one of the frets and then pull the string. When Dima pulls the *i*-th string holding it on the *j*...
{"inputs": ["4 6 5 7\n3 1 2 2 3 1\n3 2 2 2 5 5\n4 2 2 2 5 3\n3 2 2 1 4 3\n2 3 1 4 1 5 1", "4 4 9 5\n4 7 9 5\n1 2 1 7\n8 3 4 9\n5 7 7 2\n7 1 9 2 5", "5 5 2 2\n2 2 2 1 2\n2 1 2 2 2\n2 2 2 2 2\n1 2 2 2 2\n2 2 2 2 1\n1 1", "5 5 2 2\n2 1 2 2 2\n2 2 2 2 2\n2 2 2 2 1\n2 2 2 2 2\n1 2 2 2 2\n1 1", "11 11 9 11\n1 1 1 1 1 1 1 1 1...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1
codeforces
9512d95f55e6714b775f910ab872b25d
Special Matrices
An *n*<=×<=*n* square matrix is special, if: - it is binary, that is, each cell contains either a 0, or a 1; - the number of ones in each row and column equals 2. You are given *n* and the first *m* rows of the matrix. Print the number of special *n*<=×<=*n* matrices, such that the first *m* rows coincide with the ...
{"inputs": ["3 1 1000\n011", "4 4 100500\n0110\n1010\n0101\n1001", "2 0 1000", "2 1 1000\n11", "5 0 13", "5 3 19\n10001\n10001\n00110", "3 0 100500", "4 0 100500", "5 0 100500", "6 0 100500", "3 1 100501\n101", "4 2 100501\n1010\n1010", "5 2 100501\n10010\n10100", "6 4 100501\n100010\n100100\n010100\n000011", "7 4 1005...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1
codeforces
95134230a7f87d3bd4d0603bfbe2719c
Anton and Digits
Recently Anton found a box with digits in his room. There are *k*2 digits 2, *k*3 digits 3, *k*5 digits 5 and *k*6 digits 6. Anton's favorite integers are 32 and 256. He decided to compose this integers from digits he has. He wants to make the sum of these integers as large as possible. Help him solve this task! Each...
{"inputs": ["5 1 3 4", "1 1 1 1", "10 2 1 5", "4 2 7 2", "489 292 127 263", "9557 5242 1190 7734", "1480320 1969946 1158387 3940412", "0 0 0 0", "5000000 5000000 5000000 5000000", "1048576 256 1048576 1048576", "2073144 2073145 0 0", "1000000 0 0 1", "2 1 1 1", "0 5000000 5000000 5000000", "4494839 1140434 3336818 4921...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
34
codeforces
9514456a8a09980d6d495a6a8edf495c
Polo the Penguin and Strings
Little penguin Polo adores strings. But most of all he adores strings of length *n*. One day he wanted to find a string that meets the following conditions: 1. The string consists of *n* lowercase English letters (that is, the string's length equals *n*), exactly *k* of these letters are distinct. 1. No two neighbo...
{"inputs": ["7 4", "4 7", "10 5", "47 2", "10 7", "20 7", "26 26", "47 1", "128 26", "999 7", "4585 1", "6875 2", "7642 3", "100000 7", "68754 25", "1000000 1", "999999 2", "1000000 26", "100000 20", "579466 17", "679854 9", "978458 16", "6791 21", "6795 1", "12 17", "1 1", "2 2", "1 2", "1 26", "26 2", "123 21", "3 3"...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
29
codeforces
952b7e7743211fb31c5c2332e800bc25
Hamming Distance
Hamming distance between strings *a* and *b* of equal length (denoted by *h*(*a*,<=*b*)) is equal to the number of distinct integers *i* (1<=≤<=*i*<=≤<=|*a*|), such that *a**i*<=≠<=*b**i*, where *a**i* is the *i*-th symbol of string *a*, *b**i* is the *i*-th symbol of string *b*. For example, the Hamming distance betwe...
{"inputs": ["4 4 4\n4 4\n4", "10 10 8\n8 8\n10", "50109 50255 50102\n50104 50011\n50085", "99999 99998 99997\n99996 99995\n99994", "6 6 6\n6 6\n6", "1 1 1\n1 1\n1", "2 2 2\n2 2\n2", "2 1 2\n2 2\n2", "5 6 6\n6 5\n5", "5 3 5\n6 4\n2", "46 53 56\n59 52\n45", "544 474 496\n506 492\n484", "3 6 4\n3 5\n6", "52 57 55\n45 51\n...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1
codeforces
956bf36b1fd1dafc14ac9d941a9d4c65
Name Quest
A Martian boy is named *s* — he has got this name quite recently from his parents for his coming of age birthday. Now he enjoys looking for his name everywhere. If he sees that he can obtain his name from some string by removing zero or more letters (at that, the remaining letters remain in the same order), he gets hap...
{"inputs": ["aba\nbaobababbah", "mars\nsunvenusearthmarsjupitersaturnuranusneptune", "rry\nsorrymercuryismissedabove", "a\naaaaaaaaaaaaaa", "abcaba\nabcabaabcabaabcabaabcaba", "lol\nlol", "aaaaaaaaaaaa\naaaaaa", "a\na"], "outputs": ["2", "0", "3", "13", "13", "0", "0", "0"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
24
codeforces
9586d45106030df74f42ad1e662f9280
Watching a movie
You have decided to watch the best moments of some movie. There are two buttons on your player: 1. Watch the current minute of the movie. By pressing this button, you watch the current minute of the movie and the player automatically proceeds to the next minute of the movie. 1. Skip exactly *x* minutes of the movie...
{"inputs": ["2 3\n5 6\n10 12", "1 1\n1 100000", "10 1\n2156 3497\n4784 7775\n14575 31932\n33447 35902\n36426 47202\n48772 60522\n63982 68417\n78537 79445\n90081 90629\n94325 95728", "10 3\n2156 3497\n4784 7775\n14575 31932\n33447 35902\n36426 47202\n48772 60522\n63982 68417\n78537 79445\n90081 90629\n94325 95728", "10 ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
136
codeforces
95cec444d35ca774eda9fe6cb6c283db
none
Jzzhu is the president of country A. There are *n* cities numbered from 1 to *n* in his country. City 1 is the capital of A. Also there are *m* roads connecting the cities. One can go from city *u**i* to *v**i* (and vise versa) using the *i*-th road, the length of this road is *x**i*. Finally, there are *k* train route...
{"inputs": ["5 5 3\n1 2 1\n2 3 2\n1 3 3\n3 4 4\n1 5 5\n3 5\n4 5\n5 5", "2 2 3\n1 2 2\n2 1 3\n2 1\n2 2\n2 3", "5 4 3\n1 2 999999999\n2 3 1000000000\n3 4 529529529\n5 1 524524524\n5 524444444\n5 529999999\n2 1000000000", "3 2 5\n1 2 2\n2 3 4\n3 5\n3 5\n3 5\n3 6\n3 7", "5 5 3\n1 2 999999999\n2 3 1000000000\n3 4 529529529\...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
4
codeforces
95f3ddd5d5fddf1a92aaafaa76f4824d
Chessboard Billiard
Let's imagine: there is a chess piece billiard ball. Its movements resemble the ones of a bishop chess piece. The only difference is that when a billiard ball hits the board's border, it can reflect from it and continue moving. More formally, first one of four diagonal directions is chosen and the billiard ball moves ...
{"inputs": ["3 4", "3 3", "2 2", "4 3", "2 3", "4 4", "4 6", "4 7", "5 7", "5 13", "7 10", "7 21", "7 61", "8 50", "8 8", "9 9", "9 256", "10 10", "999 999", "1000000 1000000", "2311 7771", "146412 710630", "943547 987965", "35329 689665", "672961 948978", "524288 131072", "293492 654942", "962963 1000000", "7 1000000"...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
5
codeforces
9609f8411c1b825c8ad1f6fba66ebebb
File Name
You can not just take the file and send it. When Polycarp trying to send a file in the social network "Codehorses", he encountered an unexpected problem. If the name of the file contains three or more "x" (lowercase Latin letters "x") in a row, the system considers that the file content does not correspond to the socia...
{"inputs": ["6\nxxxiii", "5\nxxoxx", "10\nxxxxxxxxxx", "100\nxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", "99\nxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxa", "3\nxxx", "77\naaabbbcccdddeeefffggghhhiiijjjkkkl...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
325
codeforces
961446004eb9d83762673abfd2c4b1e8
Vasya's Calendar
Vasya lives in a strange world. The year has *n* months and the *i*-th month has *a**i* days. Vasya got a New Year present — the clock that shows not only the time, but also the date. The clock's face can display any number from 1 to *d*. It is guaranteed that *a**i*<=≤<=*d* for all *i* from 1 to *n*. The clock does n...
{"inputs": ["4\n2\n2 2", "5\n3\n3 4 3", "31\n12\n31 28 31 30 31 30 31 31 30 31 30 31", "1\n1\n1", "1\n2\n1 1", "2\n2\n1 1", "10\n2\n10 2", "10\n3\n6 3 6", "10\n4\n8 7 1 5", "10\n5\n2 7 8 4 4", "10\n6\n8 3 4 9 6 1", "10\n7\n10 5 3 1 1 9 1", "10\n8\n6 5 10 6 8 1 3 2", "10\n9\n6 2 7 5 5 4 8 6 2", "10\n10\n1 10 1 10 1 1 7 ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
167
codeforces
9627272d7a247485f14cbdc34d6bfddf
Insertion Sort
Petya is a beginner programmer. He has already mastered the basics of the C++ language and moved on to learning algorithms. The first algorithm he encountered was insertion sort. Petya has already written the code that implements this algorithm and sorts the given integer zero-indexed array *a* of size *n* in the non-d...
{"inputs": ["5\n4 0 3 1 2", "5\n1 2 3 4 0", "5\n1 3 4 0 2", "10\n9 8 7 6 5 4 3 2 1 0", "5\n0 4 1 3 2", "6\n3 0 1 4 5 2", "3\n0 2 1", "3\n1 0 2", "3\n1 2 0", "3\n2 0 1", "3\n2 1 0", "7\n4 0 3 5 1 2 6", "8\n1 5 4 0 2 7 3 6", "9\n1 5 6 3 0 7 2 8 4", "10\n8 6 7 9 4 5 2 3 1 0", "11\n4 9 1 2 8 5 10 3 0 7 6", "12\n2 7 0 1 3 1...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1
codeforces
962cab700bb813622b48938f5c54d8b8
Little Pony and Sort by Shift
One day, Twilight Sparkle is interested in how to sort a sequence of integers *a*1,<=*a*2,<=...,<=*a**n* in non-decreasing order. Being a young unicorn, the only operation she can perform is a unit shift. That is, she can move the last element of the sequence to its beginning: Help Twilight Sparkle to calculate: what ...
{"inputs": ["2\n2 1", "3\n1 3 2", "2\n1 2", "6\n3 4 5 6 3 2", "3\n1 2 1", "5\n1 1 2 1 1", "4\n5 4 5 4", "7\n3 4 5 5 5 1 2", "5\n2 2 1 2 2", "5\n5 4 1 2 3", "4\n6 1 2 7", "5\n4 5 6 2 3", "2\n1 1", "4\n1 2 2 1", "9\n4 5 6 7 1 2 3 4 10", "7\n2 3 4 1 2 3 4", "6\n1 2 1 2 1 2", "3\n3 2 1", "4\n1 4 4 1", "5\n1 2 1 1 1", "5\n4...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
157
codeforces
963d940c5ad407f2d78a56605af11390
s-palindrome
Let's call a string "s-palindrome" if it is symmetric about the middle of the string. For example, the string "oHo" is "s-palindrome", but the string "aa" is not. The string "aa" is not "s-palindrome", because the second half of it is not a mirror reflection of the first half. You are given a string *s*. Check if the ...
{"inputs": ["oXoxoXo", "bod", "ER", "o", "a", "opo", "HCMoxkgbNb", "vMhhXCMWDe", "iIcamjTRFH", "WvoWvvWovW", "WXxAdbAxXW", "vqMTUUTMpv", "iii", "AAWW", "ss", "i", "ii", "mm", "LJ", "m", "ioi", "OA", "aaaiaaa", "SS", "iiii", "ssops", "ssss", "ll", "s", "bb", "uu", "ZoZ", "mom", "uou", "u", "JL", "mOm", "llll", "ouo", "a...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
27
codeforces
969194bd9a4c52b927170f6878291c44
Alyona and a tree
Alyona has a tree with *n* vertices. The root of the tree is the vertex 1. In each vertex Alyona wrote an positive integer, in the vertex *i* she wrote *a**i*. Moreover, the girl wrote a positive integer to every edge of the tree (possibly, different integers on different edges). Let's define *dist*(*v*,<=*u*) as the ...
{"inputs": ["5\n2 5 1 4 6\n1 7\n1 1\n3 5\n3 6", "5\n9 7 8 6 5\n1 1\n2 1\n3 1\n4 1", "1\n1", "2\n1 1\n1 1", "10\n40 77 65 14 86 16 2 51 62 79\n1 75\n10 86\n3 52\n6 51\n10 8\n3 61\n3 53\n5 98\n2 7", "10\n52 1 84 16 59 26 56 74 52 97\n5 7\n7 13\n3 98\n7 22\n7 19\n9 54\n4 45\n10 95\n1 94", "10\n68 29 12 14 27 47 95 100 45 ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
3
codeforces
9699caf9749110b5eef0cc68b28787b8
Phone Numbers
Winters are just damn freezing cold in Nvodsk! That's why a group of *n* friends prefers to take a taxi, order a pizza and call girls. The phone numbers in the city consist of three pairs of digits (for example, 12-34-56). Each friend has a phonebook of size *s**i* (that's the number of phone numbers). We know that tax...
{"inputs": ["4\n2 Fedorov\n22-22-22\n98-76-54\n3 Melnikov\n75-19-09\n23-45-67\n99-99-98\n7 Rogulenko\n22-22-22\n11-11-11\n33-33-33\n44-44-44\n55-55-55\n66-66-66\n95-43-21\n3 Kaluzhin\n11-11-11\n99-99-99\n98-65-32", "3\n5 Gleb\n66-66-66\n55-55-55\n01-01-01\n65-43-21\n12-34-56\n3 Serega\n55-55-55\n87-65-43\n65-55-21\n5 M...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
7
codeforces
969d32200550fa6d7a135e41aecf0436
A Shade of Moonlight
"To curtain off the moonlight should be hardly possible; the shades present its mellow beauty and restful nature." Intonates Mino. "See? The clouds are coming." Kanno gazes into the distance. "That can't be better," Mino turns to Kanno. The sky can be seen as a one-dimensional axis. The moon is at the origin whose ...
{"inputs": ["5 1 2\n-2 1\n2 1\n3 -1\n5 -1\n7 -1", "4 10 1\n-20 1\n-10 -1\n0 1\n10 -1", "1 100000000 98765432\n73740702 1", "10 2 3\n-1 -1\n-4 1\n-6 -1\n1 1\n10 -1\n-8 -1\n6 1\n8 1\n4 -1\n-10 -1", "3 100000000 100000000\n-100000000 1\n100000000 1\n0 -1", "9 25000000 989\n-100000000 -1\n-75000000 1\n75000000 1\n50000000 ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1
codeforces
96bbc0ea662787e4b8d5f40b8789dc18
Big Number and Remainder
Stepan has a very big positive integer. Let's consider all cyclic shifts of Stepan's integer (if we look at his integer like at a string) which are also integers (i.e. they do not have leading zeros). Let's call such shifts as good shifts. For example, for the integer 10203 the good shifts are the integer itself 10203...
{"inputs": ["521\n3", "1001\n5", "5678901234567890123456789\n10000", "552352155\n13", "11533077525260\n193983", "15\n19", "2342341\n2342340", "12345\n12344", "23457\n23456", "79\n60847671", "456\n79575973", "1908\n86567928", "30866\n55357692", "980552\n32506042", "4865180\n11799246", "63014535\n5261418", "260597722\n10...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
8
codeforces
96cafaf521d87be7591992062831ec4a
Fibonacci String Subsequences
You are given a binary string *s* (each character of this string is either 0 or 1). Let's denote the cost of string *t* as the number of occurences of *s* in *t*. For example, if *s* is 11 and *t* is 111011, then the cost of *t* is 3. Let's also denote the Fibonacci strings sequence as follows: - *F*(0) is 0;- *F*(...
{"inputs": ["2 4\n11", "10 100\n1010101010", "10 5\n0110111100", "100 100\n0001010101110010010100111011010101101111110001101101010111011101010000111000110001111010001001000001", "50 50\n00011100010110111111011100101010000001101001001001", "100 50\n011011001111111001000000010101011001100101110000001011010011000000011100...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1
codeforces
9710337c757d2ca9a64081eb24308f7e
Collisions
On a number line there are *n* balls. At time moment 0 for each ball the following data is known: its coordinate *x**i*, speed *v**i* (possibly, negative) and weight *m**i*. The radius of the balls can be ignored. The balls collide elastically, i.e. if two balls weighing *m*1 and *m*2 and with speeds *v*1 and *v*2 col...
{"inputs": ["2 9\n3 4 5\n0 7 8", "3 10\n1 2 3\n4 -5 6\n7 -8 9", "6 76\n-35 -79 86\n-76 -20 64\n-91 79 10\n12 25 51\n62 6 30\n8 -14 65", "5 69\n-34 28 72\n54 59 51\n65 42 95\n75 1 59\n99 76 54", "5 65\n58 73 74\n98 85 95\n92 94 96\n66 100 79\n44 80 95", "5 10\n-98 -98 1\n-100 -100 1\n-99 -100 2\n-97 -100 1\n-95 -100 1",...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
4
codeforces
9745559fd17c5609447524b4da506f1e
History
Polycarpus likes studying at school a lot and he is always diligent about his homework. Polycarpus has never had any problems with natural sciences as his great-great-grandfather was the great physicist Seinstein. On the other hand though, Polycarpus has never had an easy time with history. Everybody knows that the Wo...
{"inputs": ["5\n1 10\n2 9\n3 8\n4 7\n5 6", "5\n1 100\n2 50\n51 99\n52 98\n10 60", "1\n1 1000000000", "2\n100 1000\n500 1500", "4\n1 100\n50 150\n120 200\n180 220", "10\n1 20\n2 19\n3 18\n4 17\n5 16\n6 15\n7 14\n8 13\n9 12\n10 11", "4\n1 5\n2 4\n10 15\n11 14", "10\n1 2\n3 4\n5 6\n7 8\n9 10\n11 12\n13 14\n15 16\n17 18\n1...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
53
codeforces
976830fcfcbc9f7cde317a03dd5b5af3
Widget Library
Vasya writes his own library for building graphical user interface. Vasya called his creation VTK (VasyaToolKit). One of the interesting aspects of this library is that widgets are packed in each other. A widget is some element of graphical interface. Each widget has width and height, and occupies some rectangle on t...
{"inputs": ["12\nWidget me(50,40)\nVBox grandpa\nHBox father\ngrandpa.pack(father)\nfather.pack(me)\ngrandpa.set_border(10)\ngrandpa.set_spacing(20)\nWidget brother(30,60)\nfather.pack(brother)\nWidget friend(20,60)\nWidget uncle(100,20)\ngrandpa.pack(uncle)", "15\nWidget pack(10,10)\nHBox dummy\nHBox x\nVBox y\ny.pack...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
2
codeforces
9769c0ef0e25d8db168cae2e27ac7268
Visiting a Friend
Pig is visiting a friend. Pig's house is located at point 0, and his friend's house is located at point *m* on an axis. Pig can use teleports to move along the axis. To use a teleport, Pig should come to a certain point (where the teleport is located) and choose where to move: for each teleport there is the rightmos...
{"inputs": ["3 5\n0 2\n2 4\n3 5", "3 7\n0 4\n2 5\n6 7", "1 1\n0 0", "30 10\n0 7\n1 2\n1 2\n1 4\n1 4\n1 3\n2 2\n2 4\n2 6\n2 9\n2 2\n3 5\n3 8\n4 8\n4 5\n4 6\n5 6\n5 7\n6 6\n6 9\n6 7\n6 9\n7 7\n7 7\n8 8\n8 8\n9 9\n9 9\n10 10\n10 10", "30 100\n0 27\n4 82\n11 81\n14 32\n33 97\n33 34\n37 97\n38 52\n45 91\n49 56\n50 97\n57 70...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
144
codeforces
9799386063eac39226d7076d5e2ace6a
Chicken or Fish?
Polycarp is flying in the airplane. Finally, it is his favorite time — the lunchtime. The BerAvia company stewardess is giving food consecutively to all the passengers from the 1-th one to the last one. Polycarp is sitting on seat *m*, that means, he will be the *m*-th person to get food. The flight menu has *k* dishe...
{"inputs": ["2\n\n3 4\n2 3 2 1\n1 0\n0 0\n\n5 5\n1 2 1 3 1\n3 0\n0 0\n2 1\n4 0", "4\n\n2 1\n42\n0 0\n\n2 1\n2\n0 0\n\n2 1\n42\n1 0\n\n2 1\n2\n1 0", "5\n\n3 3\n1 1 1\n0 0\n0 1\n\n3 3\n1 1 1\n1 0\n2 1\n\n3 3\n1 1 1\n1 0\n0 1\n\n3 3\n1 1 1\n0 0\n1 0\n\n3 3\n1 1 1\n0 0\n1 1", "1\n\n4 2\n2 2\n0 0\n0 0\n1 1"], "outputs": ["Y...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
2
codeforces
97b0be7ad7045d8184a85d460fdf44f0
The Game Of Parity
There are *n* cities in Westeros. The *i*-th city is inhabited by *a**i* people. Daenerys and Stannis play the following game: in one single move, a player chooses a certain town and burns it to the ground. Thus all its residents, sadly, die. Stannis starts the game. The game ends when Westeros has exactly *k* cities l...
{"inputs": ["3 1\n1 2 1", "3 1\n2 2 1", "6 3\n5 20 12 7 14 101", "6 3\n346 118 330 1403 5244 480", "7 4\n11 3532 99 3512 12 8 22", "9 4\n2 6 8 1 2 4 2 8 2", "8 2\n1 3 22 45 21 132 78 901", "1 1\n912959", "1 1\n107540", "2 2\n67427 727097", "2 2\n346010 923112", "2 2\n125572 610583", "3 3\n198331 216610 697947", "3 3\n3...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
5
codeforces
97e64e857002b4868d4b906fbfc1c164
Kirill And The Game
Kirill plays a new computer game. He came to the potion store where he can buy any potion. Each potion is characterized by two integers — amount of experience and cost. The efficiency of a potion is the ratio of the amount of experience to the cost. Efficiency may be a non-integer number. For each two integer numbers ...
{"inputs": ["1 10 1 10 1", "1 5 6 10 1", "1 1 1 1 1", "1 1 1 1 2", "1 100000 1 100000 100000", "1 100000 1 100000 100001", "25 10000 200 10000 5", "1 100000 10 100000 50000", "91939 94921 10197 89487 1", "30518 58228 74071 77671 1", "46646 79126 78816 91164 5", "30070 83417 92074 99337 2", "13494 17544 96820 99660 6", ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
91
codeforces
97eae29cb6754e68b288718743c9be45
Elevator
A sky scraper with 1000 floors has been built in the city of N. It has modern superfast elevators to help to travel from one floor to another. Each elevator has two doors, the front one and the back one. If one goes in through the front door, he goes out through the back one and vice versa. The elevator has two rails n...
{"inputs": ["front\n1", "back\n1", "front\n2", "back\n2"], "outputs": ["L", "R", "R", "L"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
64
codeforces
9801dff0e17270152bbd2e68913fa259
Parallelogram is Back
Long time ago Alex created an interesting problem about parallelogram. The input data for this problem contained four integer points on the Cartesian plane, that defined the set of vertices of some non-degenerate (positive area) parallelogram. Points not necessary were given in the order of clockwise or counterclockwis...
{"inputs": ["0 0\n1 0\n0 1", "0 -1\n-1 0\n1 1", "-1 -1\n0 1\n1 1", "1000 1000\n-1000 -1000\n-1000 1000", "-1000 1000\n1000 -1000\n-1000 -1000", "-4 -5\n7 10\n3 -10", "-86 25\n-55 18\n58 24", "-301 -397\n192 317\n-98 729", "1000 1000\n999 1000\n-1000 -1000", "-1000 0\n999 0\n1000 1", "-1000 1000\n1000 -1000\n0 1", "1000...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
36
codeforces
9819394579ff3ea1f184690cb479a47b
Getting an A
Translator's note: in Russia's most widespread grading system, there are four grades: 5, 4, 3, 2, the higher the better, roughly corresponding to A, B, C and F respectively in American grading system. The term is coming to an end and students start thinking about their grades. Today, a professor told his students that...
{"inputs": ["3\n4 4 4", "4\n5 4 5 5", "4\n5 3 3 5", "1\n5", "4\n3 2 5 4", "5\n5 4 3 2 5", "8\n5 4 2 5 5 2 5 5", "5\n5 5 2 5 5", "6\n5 5 5 5 5 2", "6\n2 2 2 2 2 2", "100\n3 2 4 3 3 3 4 2 3 5 5 2 5 2 3 2 4 4 4 5 5 4 2 5 4 3 2 5 3 4 3 4 2 4 5 4 2 4 3 4 5 2 5 3 3 4 2 2 4 4 4 5 4 3 3 3 2 5 2 2 2 3 5 4 3 2 4 5 5 5 2 2 4 2 3 ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
224
codeforces
9819cf7a2ee1577fa2b11b9f03e019a4
Fire
Polycarp is in really serious trouble — his house is on fire! It's time to save the most valuable items. Polycarp estimated that it would take *t**i* seconds to save *i*-th item. In addition, for each item, he estimated the value of *d**i* — the moment after which the item *i* will be completely burned and will no long...
{"inputs": ["3\n3 7 4\n2 6 5\n3 7 6", "2\n5 6 1\n3 3 5", "9\n13 18 14\n8 59 20\n9 51 2\n18 32 15\n1 70 18\n14 81 14\n10 88 16\n18 52 3\n1 50 6", "5\n12 44 17\n10 12 11\n16 46 5\n17 55 5\n6 60 2", "6\n18 85 3\n16 91 20\n12 92 11\n20 86 20\n15 43 4\n16 88 7", "2\n12 13 2\n1 9 3", "3\n14 42 16\n13 40 1\n17 33 5", "4\n5 6 ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
8
codeforces
981ad6fb86d3e2ed5c0d84780498119a
Magic, Wizardry and Wonders
Vasya the Great Magician and Conjurer loves all kinds of miracles and wizardry. In one wave of a magic wand he can turn an object into something else. But, as you all know, there is no better magic in the Universe than the magic of numbers. That's why Vasya adores math and spends a lot of time turning some numbers into...
{"inputs": ["3 3 2", "5 -4 3", "5 -4 4", "2 0 10", "5 2 2", "7 -24 10", "7 -35 10", "10 5 3", "10 -39 10", "15 -639 100", "15 852 100", "20 -179 29", "20 97 13", "25 19 49", "25 1 1", "40 336 83", "40 -1600 85", "40 -1039 73", "40 -118 32", "50 231 39", "50 -357 68", "60 -728 29", "60 -2772 94", "70 1980 84", "70 2335 ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1
codeforces
981eab65f82a30b1d20451a60a794f8a
Registration System
A new e-mail service "Berlandesk" is going to be opened in Berland in the near future. The site administration wants to launch their project as soon as possible, that's why they ask you to help. You're suggested to implement the prototype of site registration system. The system should work on the following principle. ...
{"inputs": ["4\nabacaba\nacaba\nabacaba\nacab", "6\nfirst\nfirst\nsecond\nsecond\nthird\nthird", "1\nn", "2\nu\nu", "3\nb\nb\nb", "2\nc\ncn", "3\nvhn\nvhn\nh", "4\nd\nhd\nd\nh", "10\nbhnqaptmp\nbhnqaptmp\nbhnqaptmp\nbhnqaptmp\nbhnqaptmp\nbhnqaptmp\nbhnqaptmp\nbhnqaptmp\nbhnqaptmp\nbhnqaptmp", "10\nfpqhfouqdldravpjttarh...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
121
codeforces
98290b55151aee048bb03b44cf19df7d
Polyline
There are three points marked on the coordinate plane. The goal is to make a simple polyline, without self-intersections and self-touches, such that it passes through all these points. Also, the polyline must consist of only segments parallel to the coordinate axes. You are to find the minimum number of segments this p...
{"inputs": ["1 -1\n1 1\n1 2", "-1 -1\n-1 3\n4 3", "1 1\n2 3\n3 2", "1000000000 -1000000000\n1000000000 1000000000\n-1000000000 -1000000000", "-510073119 -991063686\n583272581 -991063686\n623462417 -991063686", "-422276230 -422225325\n-422276230 -544602611\n-282078856 -544602611", "127447697 -311048187\n-644646254 13509...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1
codeforces
982db9310bb856cf377fea26d0673d07
Bear and Game
Bear Limak likes watching sports on TV. He is going to watch a game today. The game lasts 90 minutes and there are no breaks. Each minute can be either interesting or boring. If 15 consecutive minutes are boring then Limak immediately turns TV off. You know that there will be *n* interesting minutes *t*1,<=*t*2,<=......
{"inputs": ["3\n7 20 88", "9\n16 20 30 40 50 60 70 80 90", "9\n15 20 30 40 50 60 70 80 90", "30\n6 11 12 15 22 24 30 31 32 33 34 35 40 42 44 45 47 50 53 54 57 58 63 67 75 77 79 81 83 88", "60\n1 2 4 5 6 7 11 14 16 18 20 21 22 23 24 25 26 33 34 35 36 37 38 39 41 42 43 44 46 47 48 49 52 55 56 57 58 59 60 61 63 64 65 67 6...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
251
codeforces
98428c5ad10009f3b2425646949f8bd0
Army
The Berland Armed Forces System consists of *n* ranks that are numbered using natural numbers from 1 to *n*, where 1 is the lowest rank and *n* is the highest rank. One needs exactly *d**i* years to rise from rank *i* to rank *i*<=+<=1. Reaching a certain rank *i* having not reached all the previous *i*<=-<=1 ranks is...
{"inputs": ["3\n5 6\n1 2", "3\n5 6\n1 3", "2\n55\n1 2", "3\n85 78\n1 3", "4\n63 4 49\n2 3", "5\n93 83 42 56\n2 5", "6\n22 9 87 89 57\n1 6", "7\n52 36 31 23 74 78\n2 7", "8\n82 14 24 5 91 49 94\n3 8", "9\n12 40 69 39 59 21 59 5\n4 6", "10\n95 81 32 59 71 30 50 61 100\n1 6", "15\n89 55 94 4 15 69 19 60 91 77 3 94 91 62\n...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
511
codeforces
986f9fb53383c1c7cdfc5b771aaddf74
Champions' League
In the autumn of this year, two Russian teams came into the group stage of the most prestigious football club competition in the world — the UEFA Champions League. Now, these teams have already started to play in the group stage and are fighting for advancing to the playoffs. In this problem we are interested in the dr...
{"inputs": ["8\n1 3 1 7\nBarcelona 158\nMilan 90\nSpartak 46\nAnderlecht 48\nCeltic 32\nBenfica 87\nZenit 79\nMalaga 16", "4\n777 556 763 235\nkRnl 221\nSnxtrev 981\nBAaxtAFAyfYKea 390\nfFZFDYLJSweUcSTo 786", "8\n901 45 13 488\nOsIigEKvzr 17\nigyDhJRjjWEKyCcj 636\nEWy 744\njEvkGATY 856\nXoAReWWsizfhgghKVwce 48\nQJhC 31...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
2
codeforces
988518cdbf5addd85b86b7c5d7c38a55
Police Recruits
The police department of your city has just started its journey. Initially, they don’t have any manpower. So, they started hiring new recruits in groups. Meanwhile, crimes keeps occurring within the city. One member of the police force can investigate only one crime during his/her lifetime. If there is no police offi...
{"inputs": ["3\n-1 -1 1", "8\n1 -1 1 -1 -1 1 1 1", "11\n-1 -1 2 -1 -1 -1 -1 -1 -1 -1 -1", "7\n-1 -1 1 1 -1 -1 1", "21\n-1 -1 -1 -1 -1 3 2 -1 6 -1 -1 2 1 -1 2 2 1 6 5 -1 5", "98\n-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 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 -1 1 -1 1 -1 ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
729
codeforces
98e429fa33b03d323cd886e28f35b819
Journey
The territory of Berland is represented by a rectangular field *n*<=×<=*m* in size. The king of Berland lives in the capital, located on the upper left square (1,<=1). The lower right square has coordinates (*n*,<=*m*). One day the king decided to travel through the whole country and return back to the capital, having ...
{"inputs": ["2 2", "3 3", "3 2", "2 3", "3 4", "6 3", "4 3", "1 2", "1 3", "1 99", "1 100", "2 1", "3 1", "99 1", "100 1", "8 97", "2 4", "2 99", "2 100", "4 2", "99 2", "100 2", "100 100", "99 100", "99 99", "100 99", "33 81", "11 17", "36 1", "62 85", "39 69", "64 5", "90 89", "67 73", "40 75", "10 13", "33 51", "4 3...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
2
codeforces
98ff04c41ab2c760488c41a7659953ac
Balloons
There are quite a lot of ways to have fun with inflatable balloons. For example, you can fill them with water and see what happens. Grigory and Andrew have the same opinion. So, once upon a time, they went to the shop and bought $n$ packets with inflatable balloons, where $i$-th of them has exactly $a_i$ balloons insi...
{"inputs": ["3\n1 2 1", "2\n5 5", "1\n10", "1\n1", "10\n1 1 1 1 1 1 1 1 1 1", "10\n1 1 1 1 1 1 1 1 1 9", "10\n26 723 970 13 422 968 875 329 234 983", "3\n3 2 1", "10\n1000 1000 1000 1000 1000 1000 1000 1000 1000 1000", "10\n1 9 7 6 2 4 7 8 1 3", "2\n9 6", "2\n89 7", "2\n101 807", "5\n8 7 4 8 3", "5\n55 62 70 100 90", "...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
128
codeforces
99180e3f5c7972631604d2137406cd36
Where do I Turn?
Trouble came from the overseas lands: a three-headed dragon Gorynych arrived. The dragon settled at point *C* and began to terrorize the residents of the surrounding villages. A brave hero decided to put an end to the dragon. He moved from point *A* to fight with Gorynych. The hero rode from point *A* along a straight...
{"inputs": ["0 0\n0 1\n1 1", "-1 -1\n-3 -3\n-4 -4", "-4 -6\n-3 -7\n-2 -6", "-44 57\n-118 -41\n-216 33", "39 100\n90 85\n105 136", "71 43\n96 -15\n171 -189", "-22 -84\n-117 8\n-25 103", "28 -81\n49 -85\n45 -106", "-20 -60\n-39 -45\n-24 -26", "-61 -24\n-61 35\n-120 35", "-19 27\n-115 -63\n-25 -159", "53 69\n147 114\n102 ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
43
codeforces
991dc0448b712b255c88c42f60d3010d
Way Too Long Words
Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome. Let's consider a word too long, if its length is strictly more than 10 characters. All too long words should be replaced with a special abbreviation. This abbreviation is made lik...
{"inputs": ["4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis", "5\nabcdefgh\nabcdefghi\nabcdefghij\nabcdefghijk\nabcdefghijklm", "3\nnjfngnrurunrgunrunvurn\njfvnjfdnvjdbfvsbdubruvbubvkdb\nksdnvidnviudbvibd", "1\ntcyctkktcctrcyvbyiuhihhhgyvyvyvyvjvytchjckt", "24\nyou\nare\nregi...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
2,022
codeforces
992794c9fddefcc7b1bcf7a5d6bb48ef
Substitutes in Number
Andrew and Eugene are playing a game. Initially, Andrew has string *s*, consisting of digits. Eugene sends Andrew multiple queries of type "*d**i*<=→<=*t**i*", that means "replace all digits *d**i* in string *s* with substrings equal to *t**i*". For example, if *s*<==<=123123, then query "2<=→<=00" transforms *s* to 10...
{"inputs": ["123123\n1\n2->00", "123123\n1\n3->", "222\n2\n2->0\n0->7", "1000000008\n0", "100\n5\n1->301\n0->013\n1->013\n0->103\n0->103", "21222\n10\n1->\n2->1\n1->1\n1->1\n1->1\n1->22\n2->2\n2->1\n1->21\n1->", "21122\n10\n1->\n2->12\n1->\n2->21\n2->\n1->21\n1->\n2->12\n2->\n1->21", "7048431802\n3\n0->9285051\n0->7854...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
7
codeforces
9929caf2ab82e2bcb6a1a7d2f22a5c35
Jzzhu and Chocolate
Jzzhu has a big rectangular chocolate bar that consists of *n*<=×<=*m* unit squares. He wants to cut this bar exactly *k* times. Each cut must meet the following requirements: - each cut should be straight (horizontal or vertical); - each cut should go along edges of unit squares (it is prohibited to divide any unit...
{"inputs": ["3 4 1", "6 4 2", "2 3 4", "10 10 2", "1000000000 1000000000 2000000000", "1000000000 1000000000 999999999", "1000000000 1000000000 1", "98283 999283848 23", "6 4 5", "6 4 6", "482738478 493948384 502919283", "1 1 1", "1 1 2", "1 1 1000000000", "1000000000 1000000000 123456", "192837483 829387483 828374", "...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
16
codeforces
9938d8d14c5798896320ef4e314adf96
Constellation
Cat Noku has obtained a map of the night sky. On this map, he found a constellation with *n* stars numbered from 1 to *n*. For each *i*, the *i*-th star is located at coordinates (*x**i*,<=*y**i*). No two stars are located at the same position. In the evening Noku is going to take a look at the night sky. He would lik...
{"inputs": ["3\n0 1\n1 0\n1 1", "5\n0 0\n0 2\n2 0\n2 2\n1 1", "3\n819934317 939682125\n487662889 8614219\n-557136619 382982369", "10\n25280705 121178189\n219147240 -570920213\n-829849659 923854124\n18428128 -781819137\n-876779400 528386329\n-780997681 387686853\n-101900553 749998368\n58277314 355353788\n732128908 33641...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
26
codeforces
993d6fdfa3a88ca40146880e02e2c72b
On Corruption and Numbers
Alexey, a merry Berland entrant, got sick of the gray reality and he zealously wants to go to university. There are a lot of universities nowadays, so Alexey is getting lost in the diversity — he has not yet decided what profession he wants to get. At school, he had bad grades in all subjects, and it's only thanks to w...
{"inputs": ["2\n5 2 3\n6 4 5", "50\n69 6 6\n22 1 1\n23 3 3\n60 13 13\n13 3 3\n7 4 7\n6 1 1\n49 7 9\n68 8 8\n20 2 2\n34 1 1\n79 5 5\n22 1 1\n77 58 65\n10 3 3\n72 5 5\n47 1 1\n82 3 3\n92 8 8\n34 1 1\n42 9 10\n63 14 14\n10 3 3\n38 2 2\n80 6 6\n79 5 5\n53 5 5\n44 7 7\n85 2 2\n24 2 2\n57 3 3\n95 29 81\n77 6 6\n24 1 1\n33 4 ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
11
codeforces
993f91f4cbd61f99613fae57418483be
Find Extra One
You have *n* distinct points on a plane, none of them lie on *OY* axis. Check that there is a point after removal of which the remaining points are located on one side of the *OY* axis. The first line contains a single positive integer *n* (2<=≤<=*n*<=≤<=105). The following *n* lines contain coordinates of the points....
{"inputs": ["3\n1 1\n-1 -1\n2 -1", "4\n1 1\n2 2\n-1 1\n-2 2", "3\n1 2\n2 1\n4 60", "10\n1 1\n2 2\n3 3\n4 4\n5 5\n6 6\n7 7\n8 8\n9 9\n-1 -1", "2\n1000000000 -1000000000\n1000000000 1000000000", "23\n-1 1\n-1 2\n-2 4\n-7 -8\n-3 3\n-9 -14\n-5 3\n-6 2\n-7 11\n-4 4\n-8 5\n1 1\n-1 -1\n-1 -2\n-2 -4\n-7 8\n-3 -3\n-9 14\n-5 -3\...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
326
codeforces
9940523d0a61cbefac6cca3bfb153524
Road Construction
A country has *n* cities. Initially, there is no road in the country. One day, the king decides to construct some roads connecting pairs of cities. Roads can be traversed either way. He wants those roads to be constructed in such a way that it is possible to go from each city to any other city by traversing at most two...
{"inputs": ["4 1\n1 3", "1000 0", "484 11\n414 97\n414 224\n444 414\n414 483\n414 399\n414 484\n414 189\n414 246\n414 115\n89 414\n14 414", "150 3\n112 30\n61 45\n37 135", "34 7\n10 28\n10 19\n10 13\n24 10\n10 29\n20 10\n10 26", "1000 48\n816 885\n576 357\n878 659\n610 647\n37 670\n192 184\n393 407\n598 160\n547 995\n1...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
147
codeforces
994b1e0697ee33aebcde79386eb21727
Dubstep
Vasya works as a DJ in the best Berland nightclub, and he often uses dubstep music in his performance. Recently, he has decided to take a couple of old songs and make dubstep remixes from them. Let's assume that a song consists of some number of words. To make the dubstep remix of this song, Vasya inserts a certain nu...
{"inputs": ["WUBWUBABCWUB", "WUBWEWUBAREWUBWUBTHEWUBCHAMPIONSWUBMYWUBFRIENDWUB", "WUBWUBWUBSR", "RWUBWUBWUBLWUB", "ZJWUBWUBWUBJWUBWUBWUBL", "CWUBBWUBWUBWUBEWUBWUBWUBQWUBWUBWUB", "WUBJKDWUBWUBWBIRAQKFWUBWUBYEWUBWUBWUBWVWUBWUB", "WUBKSDHEMIXUJWUBWUBRWUBWUBWUBSWUBWUBWUBHWUBWUBWUB", "OGWUBWUBWUBXWUBWUBWUBIWUBWUBWUBKOWUBWUB...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
920
codeforces
996a30e84b4a1eb1cd09d6828c181d80
Reading
Vasya is going to the Olympics in the city Ntown by train. The boy wants to read the textbook to prepare for the Olympics. He counted that he needed *k* hours for this. He also found that the light in the train changes every hour. The light is measured on a scale from 0 to 100, where 0 is very dark, and 100 is very lig...
{"inputs": ["5 3\n20 10 30 40 10", "6 5\n90 20 35 40 60 100", "100 7\n85 66 9 91 50 46 61 12 55 65 95 1 25 97 95 4 59 59 52 34 94 30 60 11 68 36 17 84 87 68 72 87 46 99 24 66 75 77 75 2 19 3 33 19 7 20 22 3 71 29 88 63 89 47 7 52 47 55 87 77 9 81 44 13 30 43 66 74 9 42 9 72 97 61 9 94 92 29 18 7 92 68 76 43 35 71 54 49...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
63
codeforces
99764cd15d549cee60f585eed483e8f7
Extra-terrestrial Intelligence
Recently Vasya got interested in finding extra-terrestrial intelligence. He made a simple extra-terrestrial signals’ receiver and was keeping a record of the signals for *n* days in a row. Each of those *n* days Vasya wrote a 1 in his notebook if he had received a signal that day and a 0 if he hadn’t. Vasya thinks that...
{"inputs": ["8\n00111000", "7\n1001011", "7\n1010100", "5\n10101", "3\n111", "10\n0011111011", "12\n001010101010", "25\n1000000010000000100000001", "30\n111110111101110111111111111111", "50\n00101010101010101010101010101010101010101010101010", "60\n000000000000000000100001000000001000000001000000001000000001", "66\n000...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
47
codeforces
99802e27d1bad6aec23dda7b6149fe4c
Mahmoud and Ehab and the binary string
Mahmoud and Ehab are in the fourth stage now. Dr. Evil has a hidden binary string of length *n*. He guarantees that there is at least one '0' symbol and at least one '1' symbol in it. Now he wants Mahmoud and Ehab to find a position of any '0' symbol and any '1' symbol. In order to do this, Mahmoud and Ehab can ask Dr...
{"inputs": ["101", "0011001100", "01", "0010100101101100001101110001110011000010011011001110010011101010011010100101101001111010111001000100", "0101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101", "110010011001010100101010001101110010010111001110111110011011111111000110...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
9
codeforces
9982ea1d5352957c03052d5ba42f8e98
Magic Numbers
A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not. You're given a number. Determine if it is a magic number or not. The first line of input contains an integ...
{"inputs": ["114114", "1111", "441231", "1", "14", "114", "9", "414", "1000000000", "144144144", "1444", "11", "141414141", "11110111", "114114144", "444", "9999", "111444", "11114", "41111", "114414441", "144414441", "144244144", "111111111", "144444444", "444444444", "141441441", "441", "15", "14444", "11444", "144",...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
371
codeforces
999bf32199374ef5363fd5cc2c649a9c
Pashmak and Garden
Pashmak has fallen in love with an attractive girl called Parmida since one year ago... Today, Pashmak set up a meeting with his partner in a romantic garden. Unfortunately, Pashmak has forgotten where the garden is. But he remembers that the garden looks like a square with sides parallel to the coordinate axes. He al...
{"inputs": ["0 0 0 1", "0 0 1 1", "0 0 1 2", "-100 -100 100 100", "-100 -100 99 100", "0 -100 0 100", "27 -74 27 74", "0 1 2 3", "-100 100 100 -100", "-100 -100 -100 100", "100 100 100 -100", "100 -100 -100 -100", "-100 100 100 100", "0 1 0 0", "1 1 0 0", "0 0 1 0", "1 0 0 1", "1 0 1 1", "1 1 0 1", "15 -9 80 -9", "51 -...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
109
codeforces
999ed308e5a618b42a0af19a99615fa4
Hidden Word
Let’s define a grid to be a set of tiles with 2 rows and 13 columns. Each tile has an English letter written in it. The letters don't have to be unique: there might be two or more tiles with the same letter written on them. Here is an example of a grid: We say that two tiles are adjacent if they share a side or a corn...
{"inputs": ["ABCDEFGHIJKLMNOPQRSGTUVWXYZ", "BUVTYZFQSNRIWOXXGJLKACPEMDH", "DYCEUXXKMGZOINVPHWQSRTABLJF", "UTEDBZRVWLOFUASHCYIPXGJMKNQ", "ZWMFLTCQIAJEVUPODMSGXKHRNYB", "QGZEMFKWLUHOVSXJTCPIYREDNAB", "BMVFGRNDOWTILZVHAKCQSXYEJUP", "MKNTKOBFLJSXWQPVUERDHIACYGZ", "YOFJVQSWBUZENPCXGQTHMDKAILR", "GYCUAXSBNAWFIJPDQVETKZOMLHR"...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
31
codeforces
99a87db9a65e8c0f1ea8ea030de379af
Taxi
After the lessons *n* groups of schoolchildren went outside and decided to visit Polycarpus to celebrate his birthday. We know that the *i*-th group consists of *s**i* friends (1<=≤<=*s**i*<=≤<=4), and they want to go to Polycarpus together. They decided to get there by taxi. Each car can carry at most four passengers....
{"inputs": ["5\n1 2 4 3 3", "8\n2 3 4 4 2 1 3 1", "5\n4 4 4 4 4", "12\n1 1 1 1 1 1 1 1 1 1 1 1", "2\n2 1", "4\n3 2 1 3", "4\n2 4 1 3", "1\n1", "1\n2", "1\n3", "1\n4", "2\n1 1", "2\n2 2", "2\n3 3", "2\n4 4", "2\n2 1", "2\n3 1", "2\n4 1", "2\n2 3", "2\n4 2", "2\n4 3", "4\n2 2 1 1", "4\n3 1 3 1", "4\n1 4 1 4", "4\n2 2 3 3...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
26
codeforces
99c831150672a64c4aa964d7c81ccb57
T-shirt buying
A new pack of *n* t-shirts came to a shop. Each of the t-shirts is characterized by three integers *p**i*, *a**i* and *b**i*, where *p**i* is the price of the *i*-th t-shirt, *a**i* is front color of the *i*-th t-shirt and *b**i* is back color of the *i*-th t-shirt. All values *p**i* are distinct, and values *a**i* and...
{"inputs": ["5\n300 200 400 500 911\n1 2 1 2 3\n2 1 3 2 1\n6\n2 3 1 2 1 1", "2\n1000000000 1\n1 1\n1 2\n2\n2 1", "10\n251034796 163562337 995167403 531046374 341924810 828969071 971837553 183763940 857690534 687685084\n3 2 1 3 2 3 1 3 2 1\n2 3 3 1 2 3 2 3 3 2\n10\n1 3 2 3 2 3 3 1 2 3", "20\n414468312 20329584 106106409...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
26
codeforces
99cc6b3b398b6c1bd9b18b917231d58c
Mike and Fax
While Mike was walking in the subway, all the stuff in his back-bag dropped on the ground. There were several fax messages among them. He concatenated these strings in some order and now he has string *s*. He is not sure if this is his own back-bag or someone else's. He remembered that there were exactly *k* messages ...
{"inputs": ["saba\n2", "saddastavvat\n2", "aaaaaaaaaa\n3", "aaaaaa\n3", "abaacca\n2", "a\n1", "princeofpersia\n1", "xhwbdoryfiaxglripavycmxmcejbcpzidrqsqvikfzjyfnmedxrvlnusavyhillaxrblkynwdrlhthtqzjktzkullgrqsolqssocpfwcaizhovajlhmeibhiuwtxpljkyyiwykzpmazkkzampzkywiyykjlpxtwuihbiemhljavohziacwfpcossqlosqrgllukztkjzqtht...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
150
codeforces
99e62878fbc428e1631c7ff1a24bf047
Misha and Forest
Let's define a forest as a non-directed acyclic graph (also without loops and parallel edges). One day Misha played with the forest consisting of *n* vertices. For each vertex *v* from 0 to *n*<=-<=1 he wrote down two integers, *degree**v* and *s**v*, were the first integer is the number of vertices adjacent to vertex ...
{"inputs": ["3\n2 3\n1 0\n1 0", "2\n1 1\n1 0", "10\n3 13\n2 6\n1 5\n3 5\n1 3\n2 2\n2 6\n1 6\n1 3\n2 3", "10\n1 2\n1 7\n1 0\n1 8\n0 0\n1 9\n0 0\n1 1\n1 3\n1 5", "5\n1 1\n2 2\n2 2\n2 6\n1 3", "10\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0", "11\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n1 8\n1 7\n0 0\n0 0", "12\n0 0\n1 3...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
20
codeforces
99ea4713717dfb495b4af4a4707d2b49
Page Numbers
«Bersoft» company is working on a new version of its most popular text editor — Bord 2010. Bord, like many other text editors, should be able to print out multipage documents. A user keys a sequence of the document page numbers that he wants to print out (separates them with a comma, without spaces). Your task is to w...
{"inputs": ["1,2,3,1,1,2,6,6,2", "3,2,1", "30,20,10", "826,747,849,687,437", "999,999,993,969,999", "4,24,6,1,15", "511,32", "907,452,355", "303,872,764,401", "684,698,429,694,956,812,594,170,937,764", "646,840,437,946,640,564,936,917,487,752,844,734,468,969,674,646,728,642,514,695", "996,999,998,984,989,1000,996,993,1...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
60
codeforces
99fc2ec11dfa7ff1fc0a3b7335550b1e
Alyona and Mex
Someone gave Alyona an array containing *n* positive integers *a*1,<=*a*2,<=...,<=*a**n*. In one operation, Alyona can choose any element of the array and decrease it, i.e. replace with any positive integer that is smaller than the current one. Alyona can repeat this operation as many times as she wants. In particular,...
{"inputs": ["5\n1 3 3 3 6", "2\n2 1", "1\n1", "1\n1000000000", "1\n2", "2\n1 1", "2\n1 3", "2\n2 2", "2\n2 3", "2\n3 3", "3\n1 1 1", "3\n2 1 1", "3\n3 1 1", "3\n1 1 4", "3\n2 1 2", "3\n3 2 1", "3\n2 4 1", "3\n3 3 1", "3\n1 3 4", "3\n4 1 4", "3\n2 2 2", "3\n3 2 2", "3\n4 2 2", "3\n2 3 3", "3\n4 2 3", "3\n4 4 2", "3\n3 3...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
117
codeforces
9a1fc48ed171b6e3bfc5d1196bac0b54
Arthur and Questions
After bracket sequences Arthur took up number theory. He has got a new favorite sequence of length *n* (*a*1,<=*a*2,<=...,<=*a**n*), consisting of integers and integer *k*, not exceeding *n*. This sequence had the following property: if you write out the sums of all its segments consisting of *k* consecutive elements ...
{"inputs": ["3 2\n? 1 2", "5 1\n-10 -9 ? -7 -6", "5 3\n4 6 7 2 9", "9 3\n? ? ? ? ? ? ? ? ?", "5 1\n1000000000 ? ? ? ?", "5 1\n-3 -2 -1 0 1", "7 3\n1 ? -1000000000 ? 100 ? 3", "7 3\n1 ? -1000000000 ? 100 ? 2", "1 1\n?", "1 1\n0", "2 1\n-1000000000 1000000000", "17 1\n? -13 ? ? ? -3 ? ? ? ? ? 10 ? ? ? ? 100", "5 2\n? ? -...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
2
codeforces
9a39ec0c2b714438bc895874b6e23dff
Little Artem and Dance
Little Artem is fond of dancing. Most of all dances Artem likes rueda — Cuban dance that is danced by pairs of boys and girls forming a circle and dancing together. More detailed, there are *n* pairs of boys and girls standing in a circle. Initially, boy number 1 dances with a girl number 1, boy number 2 dances with a...
{"inputs": ["6 3\n1 2\n2\n1 2", "2 3\n1 1\n2\n1 -2", "4 2\n2\n1 3", "6 8\n1 2\n2\n2\n2\n2\n1 1\n1 -5\n2", "6 8\n1 -1\n2\n2\n1 4\n1 0\n1 -1\n1 0\n1 -1", "10 5\n1 8\n1 -3\n1 -3\n2\n1 5", "10 10\n1 2\n1 -10\n1 -5\n2\n2\n1 -4\n2\n2\n1 -10\n1 -9", "6 9\n2\n1 -2\n2\n1 -6\n1 -6\n1 4\n2\n1 -1\n2", "2 5\n2\n1 -1\n2\n1 1\n2", "2...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
2
codeforces
9a416ed955927b1b6f81fc23c29c339d
News About Credit
Polycarp studies at the university in the group which consists of *n* students (including himself). All they are registrated in the social net "TheContacnt!". Not all students are equally sociable. About each student you know the value *a**i* — the maximum number of messages which the *i*-th student is agree to send p...
{"inputs": ["4\n1 2 1 0", "6\n2 0 1 3 2 0", "3\n0 2 2", "2\n0 0", "2\n1 0", "2\n0 1", "2\n1 1", "3\n1 1 0", "3\n0 1 1", "3\n1 0 0", "3\n2 0 0", "3\n1 0 1", "3\n1 1 1", "40\n3 3 2 1 0 0 0 4 5 4 0 0 0 1 0 0 0 0 0 0 0 0 0 1 0 0 0 2 3 2 0 1 0 0 2 0 3 0 1 0", "100\n1 0 0 2 0 2 0 0 2 0 0 2 0 0 2 2 2 1 1 2 1 2 2 2 1 2 0 1 0 1...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
52
codeforces
9a7436998938b1467172f8fa33f99359
Beaver
After Fox Ciel got off a bus, she found that the bus she was on was a wrong bus and she lost her way in a strange town. However, she fortunately met her friend Beaver Taro and asked which way to go to her castle. Taro's response to her was a string *s*, and she tried to remember the string *s* correctly. However, Ciel...
{"inputs": ["Go_straight_along_this_street\n5\nstr\nlong\ntree\nbiginteger\nellipse", "IhaveNoIdea\n9\nI\nh\na\nv\ne\nN\no\nI\nd", "unagioisii\n2\nioi\nunagi", "abcabcabcabc\n3\nabcabca\nbcab\ncabc", "ThankYouForParticipatingRound71\n6\nForP\noun\nnkYouForP\nTha\nouForP\nound7", "WishYourSolutionPassesFinalTests\n10\nr...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1
codeforces
9a7826eb5e81f31845cc399f45b1734d
Cards Sorting
Vasily has a deck of cards consisting of *n* cards. There is an integer on each of the cards, this integer is between 1 and 100<=000, inclusive. It is possible that some cards have the same integers on them. Vasily decided to sort the cards. To do this, he repeatedly takes the top card from the deck, and if the number...
{"inputs": ["4\n6 3 1 2", "1\n1000", "7\n3 3 3 3 3 3 3", "64\n826 142 89 337 897 891 1004 704 281 644 910 852 147 193 289 384 625 695 416 944 162 939 164 1047 359 114 499 99 713 300 268 316 256 404 852 496 373 322 716 202 689 857 936 806 556 153 137 863 1047 678 564 474 282 135 610 176 855 360 814 144 77 112 354 154", ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
6
codeforces
9a8385b99a56f1addc709bd9e1f938e0
Far Relative’s Problem
Famil Door wants to celebrate his birthday with his friends from Far Far Away. He has *n* friends and each of them can come to the party in a specific range of days of the year from *a**i* to *b**i*. Of course, Famil Door wants to have as many friends celebrating together with him as possible. Far cars are as weird as...
{"inputs": ["4\nM 151 307\nF 343 352\nF 117 145\nM 24 128", "6\nM 128 130\nF 128 131\nF 131 140\nF 131 141\nM 131 200\nM 140 200", "1\nF 68 307", "40\nM 55 363\nF 117 252\nM 157 282\nF 322 345\nM 330 363\nF 154 231\nF 216 352\nF 357 365\nM 279 292\nF 353 359\nF 82 183\nM 78 297\nM 231 314\nM 107 264\nF 34 318\nM 44 244...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
103
codeforces
9a98f12406be8a6bc3b9d8fdb7b920da
Wizards and Huge Prize
One must train much to do well on wizardry contests. So, there are numerous wizardry schools and magic fees. One of such magic schools consists of *n* tours. A winner of each tour gets a huge prize. The school is organised quite far away, so one will have to take all the prizes home in one go. And the bags that you've...
{"inputs": ["3 1 0\n10 20 30\n-1 -1 2", "1 1 1\n100\n123", "5 1 2\n36 44 13 83 63\n-1 2 -1 2 1", "9 9 2\n91 96 99 60 42 67 46 39 62\n5 -1 2 -1 -1 -1 7 -1 3", "1 0 0\n7\n-1", "2 1 2\n80 35\n-1 -1", "4 1 2\n38 15 28 15\n-1 1 -1 -1", "1 0 0\n3\n-1", "7 0 3\n58 29 75 56 47 28 27\n-1 -1 1 -1 1 2 -1", "46 33 12\n3 26 81 86 2...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1
codeforces
9aacd97a71ffc373441cb9235da62de8
Out of Controls
You are given a complete undirected graph. For each pair of vertices you are given the length of the edge that connects them. Find the shortest paths between each pair of vertices in the graph and return the length of the longest of them. The first line of the input contains a single integer *N* (3<=≤<=*N*<=≤<=10). Th...
{"inputs": ["3\n0 1 1\n1 0 4\n1 4 0", "4\n0 1 2 3\n1 0 4 5\n2 4 0 6\n3 5 6 0", "10\n0 16 67 7 82 44 25 13 25 42\n16 0 24 37 63 20 19 87 55 99\n67 24 0 81 19 71 35 6 20 91\n7 37 81 0 82 89 34 80 7 32\n82 63 19 82 0 42 66 96 42 99\n44 20 71 89 42 0 65 94 24 45\n25 19 35 34 66 65 0 97 100 22\n13 87 6 80 96 94 97 0 10 58\n...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
13
codeforces
9aba21af3a0469d2319b606660a3fd70
Hanoi Factory
Of course you have heard the famous task about Hanoi Towers, but did you know that there is a special factory producing the rings for this wonderful game? Once upon a time, the ruler of the ancient Egypt ordered the workers of Hanoi Factory to create as high tower as possible. They were not ready to serve such a strang...
{"inputs": ["3\n1 5 1\n2 6 2\n3 7 3", "4\n1 2 1\n1 3 3\n4 6 2\n5 7 1", "1\n1 2 1", "5\n6 10 4\n9 20 19\n8 11 18\n18 20 1\n19 20 8", "5\n21 25 26\n14 30 22\n6 29 30\n13 23 21\n10 11 5", "5\n45 73 26\n59 73 29\n30 74 9\n59 63 72\n73 84 79", "9\n1 5 1000000000\n23 27 834000000\n6 10 1000000000\n26 30 234500000\n5 9 100000...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
5
codeforces
9ac4a248f5752708fb068e90df52ee94
Police Stations
Inzane finally found Zane with a lot of money to spare, so they together decided to establish a country of their own. Ruling a country is not an easy job. Thieves and terrorists are always ready to ruin the country's peace. To fight back, Zane and Inzane have enacted a very effective law: from each city it must be pos...
{"inputs": ["6 2 4\n1 6\n1 2\n2 3\n3 4\n4 5\n5 6", "6 3 2\n1 5 6\n1 2\n1 3\n1 4\n1 5\n5 6", "10 1 5\n5\n1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 8\n8 9\n9 10", "11 1 5\n6\n1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 8\n8 9\n9 10\n10 11", "2 1 1\n1\n1 2"], "outputs": ["1\n3 ", "2\n4 5 ", "0", "0", "0"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
9
codeforces
9ad5b151abc3e4fc9271a64a2c7a2c25
Alarm Clock
Every evening Vitalya sets *n* alarm clocks to wake up tomorrow. Every alarm clock rings during exactly one minute and is characterized by one integer *a**i* — number of minute after midnight in which it rings. Every alarm clock begins ringing at the beginning of the minute and rings during whole minute. Vitalya will...
{"inputs": ["3 3 2\n3 5 1", "5 10 3\n12 8 18 25 1", "7 7 2\n7 3 4 1 6 5 2", "2 2 2\n1 3", "1 4 1\n1", "2 3 1\n1 2", "5 4 2\n7 2 4 5 6", "7 5 3\n11 3 13 19 5 18 17", "10 7 2\n30 9 1 40 34 4 35 27 11 3", "13 10 4\n5 28 67 70 68 3 84 4 30 82 96 37 49", "14 5 5\n10 20 22 38 16 35 29 15 25 40 32 6 7 19", "15 20 15\n8 18 12 ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
13
codeforces
9b146d320b0d4e4206aa7205457a3b57
none
A factory produces thimbles in bulk. Typically, it can produce up to *a* thimbles a day. However, some of the machinery is defective, so it can currently only produce *b* thimbles each day. The factory intends to choose a *k*-day period to do maintenance and construction; it cannot produce any thimbles during this time...
{"inputs": ["5 2 2 1 8\n1 1 2\n1 5 3\n1 2 1\n2 2\n1 4 2\n1 3 2\n2 1\n2 3", "5 4 10 1 6\n1 1 5\n1 5 5\n1 3 2\n1 5 2\n2 1\n2 2", "1 1 2 1 1\n2 1"], "outputs": ["3\n6\n4", "7\n1", "0"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
4
codeforces
9b1a5be70f80633c7e4ae47a7a6dc1e4
Misha and Permutations Summation
Let's define the sum of two permutations *p* and *q* of numbers 0,<=1,<=...,<=(*n*<=-<=1) as permutation , where *Perm*(*x*) is the *x*-th lexicographically permutation of numbers 0,<=1,<=...,<=(*n*<=-<=1) (counting from zero), and *Ord*(*p*) is the number of permutation *p* in the lexicographical order. For example, ...
{"inputs": ["2\n0 1\n0 1", "2\n0 1\n1 0", "3\n1 2 0\n2 1 0", "2\n0 1\n1 0", "5\n2 1 3 0 4\n2 0 4 3 1", "3\n0 2 1\n1 0 2", "4\n2 0 1 3\n0 2 1 3", "1\n0\n0", "75\n71 69 34 23 13 68 19 45 40 6 74 11 53 24 27 7 50 5 70 47 4 21 25 54 62 30 17 33 52 16 67 15 14 57 38 18 48 29 58 1 8 36 2 35 56 43 44 39 20 10 0 64 3 61 32 22 ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1
codeforces
9b3b7cabb6f4a2f57b5b568d73db2a86
Hongcow Learns the Cyclic Shift
Hongcow is learning to spell! One day, his teacher gives him a word that he needs to learn to spell. Being a dutiful student, he immediately learns how to spell the word. Hongcow has decided to try to make new words from this one. He starts by taking the word he just learned how to spell, and moves the last character ...
{"inputs": ["abcd", "bbb", "yzyz", "abcdefghijklmnopqrstuvwxyabcdefghijklmnopqrstuvwxy", "zclkjadoprqronzclkjadoprqronzclkjadoprqron", "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz", "xyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxy", "y", "ervbfotfedpozygoumbmxeaqegouaqqzqerlykhmvxvvlcaos", "zyzzzyyzyyyzyyzyzy...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
410
codeforces
9b3d30249314dea7abab30deec990ccf
Maxim and Array
Recently Maxim has found an array of *n* integers, needed by no one. He immediately come up with idea of changing it: he invented positive integer *x* and decided to add or subtract it from arbitrary array elements. Formally, by applying single operation Maxim chooses integer *i* (1<=≤<=*i*<=≤<=*n*) and replaces the *i...
{"inputs": ["5 3 1\n5 4 3 5 2", "5 3 1\n5 4 3 5 5", "5 3 1\n5 4 4 5 5", "3 2 7\n5 4 2", "100 1 1\n-1 -1 -2 0 -2 -1 0 0 0 0 2 2 2 2 2 1 0 1 1 1 1 0 1 0 2 0 0 1 1 1 2 2 1 0 0 2 0 1 2 1 2 1 2 2 0 2 0 1 1 0 2 1 1 2 1 1 0 2 2 0 1 1 1 1 1 1 0 2 2 2 2 0 0 0 0 2 2 1 0 2 0 0 2 0 2 1 0 2 2 1 1 2 0 2 0 2 0 0 2 2", "100 5 100\n-45...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
3
codeforces
9b52286e024c26938fb8d41bf4b72191
Delivering Carcinogen
Qwerty the Ranger arrived to the Diatar system with a very important task. He should deliver a special carcinogen for scientific research to planet Persephone. This is urgent, so Qwerty has to get to the planet as soon as possible. A lost day may fail negotiations as nobody is going to pay for an overdue carcinogen. Y...
{"inputs": ["10 0 1\n-10 0 2 8", "50 60 10\n50 60 20 40", "86 -67 50\n-60 -20 91 35", "-137 -45 64\n-86 -61 91 61", "-137 -15 64\n50 -75 91 42", "-137 -15 79\n-173 -94 91 46", "-64 20 79\n-173 -94 91 19", "7 20 89\n-173 -181 91 15", "7 20 19\n67 -69 97 1", "1 1 1\n1 1 2 1", "1 1 1\n-1 -1 2 1", "1 1 1\n1 1 10000 1", "1 ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1
codeforces
9b54daff9f2b25607c4f78b60506da27
Strange town
Volodya has recently visited a very odd town. There are *N* tourist attractions in the town and every two of them are connected by a bidirectional road. Each road has some travel price (natural number) assigned to it and all prices are distinct. But the most striking thing about this town is that each city sightseeing ...
{"inputs": ["3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20"], "outputs": ["0 3 4 \n3 0 5 \n4 5 0 ", "0 3 4 6 \n3 0 5 7 \n4 5 0 8 \n6 7 8 0 ", "0 3 4 6 9 \n3 0 5 7 10 \n4 5 0 8 11 \n6 7 8 0 13 \n9 10 11 13 0 ", "0 3 4 6 9 14 \n3 0 5 7 10 15 \n4 5 0 8 11 16 \n6 7 8 0 13...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
5
codeforces
9b7cd8cac0955cfb3ebc804ef046164d
none
John Doe has an *n*<=×<=*m* table. John Doe can paint points in some table cells, not more than one point in one table cell. John Doe wants to use such operations to make each square subtable of size *n*<=×<=*n* have exactly *k* points. John Doe wondered, how many distinct ways to fill the table with points are there,...
{"inputs": ["5 6 1", "1 1000000000000000000 0", "100 1000000 5000", "100 1000000000000000000 10000", "2 1791938441 1", "3 783497007 1", "4 1484499480 1", "5 559703685 1", "6 26236608 1", "7 167374275 1", "8 703528038 1", "9 402260913 1", "10 360430679 1", "11 1726671165 1", "12 534773931 1", "13 685597394 1", "14 92214...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1
codeforces
9b7d8b7d5953b5483ce81da2bedb7663
Johny Likes Numbers
Johny likes numbers *n* and *k* very much. Now Johny wants to find the smallest integer *x* greater than *n*, so it is divisible by the number *k*. The only line contains two integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=109). Print the smallest integer *x*<=&gt;<=*n*, so it is divisible by the number *k*. Sample Input 5 3...
{"inputs": ["5 3", "25 13", "26 13", "1 1", "8 8", "14 15", "197 894", "6058 8581", "97259 41764", "453145 333625", "2233224 4394826", "76770926 13350712", "687355301 142098087", "1000000000 999999999", "1000000000 1000000000", "999999999 1000000000", "1000000000 1", "1000000000 2", "999999999 1", "100000000 1", "99999...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
300
codeforces
9b932acf0fb0ce13f3fa6b644a95da8f
Misha, Grisha and Underground
Misha and Grisha are funny boys, so they like to use new underground. The underground has *n* stations connected with *n*<=-<=1 routes so that each route connects two stations, and it is possible to reach every station from any other. The boys decided to have fun and came up with a plan. Namely, in some day in the mor...
{"inputs": ["3 2\n1 1\n1 2 3\n2 3 3", "4 1\n1 2 3\n1 2 3", "2 4\n1\n1 1 1\n1 1 2\n1 2 2\n2 2 2", "5 20\n4 1 1 4\n2 2 5\n3 2 5\n2 3 4\n4 2 5\n4 1 2\n5 3 1\n2 1 2\n4 3 2\n1 3 3\n4 2 5\n5 1 4\n4 5 4\n1 2 4\n3 3 1\n5 4 5\n1 1 1\n1 4 4\n5 3 2\n4 2 1\n3 1 4", "5 20\n5 5 1 4\n1 4 3\n2 4 1\n1 5 5\n5 1 4\n5 1 5\n1 5 5\n5 4 4\n2...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1
codeforces
9b963a2564b7649448d132adb37247ac
Wooden Fence
Vasya has recently bought some land and decided to surround it with a wooden fence. He went to a company called "Wooden board" that produces wooden boards for fences. Vasya read in the catalog of products that the company has at its disposal *n* different types of wood. The company uses the *i*-th type of wood to prod...
{"inputs": ["2 3\n1 2\n2 3", "1 2\n2 2", "6 6\n2 1\n3 2\n2 5\n3 3\n5 1\n2 1", "4 3\n1 2\n1 1\n3 1\n2 2", "4 6\n1 1\n1 2\n3 1\n5 10", "5 10\n1 2\n2 3\n1 2\n3 1\n2 4", "1 4\n4 1", "1 3\n1 1", "4 6\n2 1\n1 2\n2 1\n2 1", "4 10\n4 5\n5 3\n1 4\n1 2", "5 8\n3 1\n2 1\n2 3\n2 1\n3 1", "10 11\n3 10\n10 2\n2 6\n7 6\n8 1\n2 3\n7 1...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
5
codeforces
9bc1f812db3e6751f5a4921f6c4f4349
Design Tutorial: Learn from Life
One way to create a task is to learn from life. You can choose some experience in real life, formalize it and then you will get a new task. Let's think about a scene in real life: there are lots of people waiting in front of the elevator, each person wants to go to a certain floor. We can formalize it in the following...
{"inputs": ["3 2\n2 3 4", "4 2\n50 100 50 100", "10 3\n2 2 2 2 2 2 2 2 2 2", "1 1\n2", "2 1\n2 2", "2 2\n2 2", "11 4\n2 3 4 5 6 7 8 9 10 11 12", "70 1311\n1146 769 1530 1132 877 1352 1295 1282 1086 914 852 1351 1432 847 1105 776 1278 716 1435 749 1320 869 812 1179 1239 1426 1403 1296 1489 1018 848 1215 1278 1203 1386 1...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
8
codeforces
9bcec3c5062b4361bc5c997df54e71e2
Queue on Bus Stop
It's that time of the year when the Russians flood their countryside summer cottages (dachas) and the bus stop has a lot of people. People rarely go to the dacha on their own, it's usually a group, so the people stand in queue by groups. The bus stop queue has *n* groups of people. The *i*-th group from the beginning ...
{"inputs": ["4 3\n2 3 2 1", "3 4\n1 2 1", "1 5\n4", "5 1\n1 1 1 1 1", "6 4\n1 3 2 3 4 1", "6 8\n6 1 1 1 4 5", "10 10\n1 10 1 10 1 1 7 8 6 7", "100 100\n85 50 17 89 65 89 5 20 86 26 16 21 85 14 44 31 87 31 6 2 48 67 8 80 79 1 48 36 97 1 5 30 79 50 78 12 2 55 76 100 54 40 26 81 97 96 68 56 87 14 51 17 54 37 52 33 69 62 3...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
185
codeforces
9bdd3ab4f287777c78d59fd0ff914aeb
Jeff and Rounding
Jeff got 2*n* real numbers *a*1,<=*a*2,<=...,<=*a*2*n* as a birthday present. The boy hates non-integer numbers, so he decided to slightly "adjust" the numbers he's got. Namely, Jeff consecutively executes *n* operations, each of them goes as follows: - choose indexes *i* and *j* (*i*<=≠<=*j*) that haven't been chose...
{"inputs": ["3\n0.000 0.500 0.750 1.000 2.000 3.000", "3\n4469.000 6526.000 4864.000 9356.383 7490.000 995.896", "3\n673.674 9263.142 6780.000 9801.000 4640.000 8244.000", "3\n6470.649 8295.000 8486.000 9855.000 223.000 579.549", "7\n2341.538 9232.119 6646.930 9316.834 5684.000 9078.705 7773.000 3823.674 6357.022 9866....
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
7
codeforces
9be5145fa9a784da2083a40864d8b1e5
Opposites Attract
Everybody knows that opposites attract. That is the key principle of the "Perfect Matching" dating agency. The "Perfect Matching" matchmakers have classified each registered customer by his interests and assigned to the *i*-th client number *t**i* (<=-<=10<=≤<=*t**i*<=≤<=10). Of course, one number can be assigned to an...
{"inputs": ["5\n-3 3 0 0 3", "3\n0 0 0", "1\n0", "1\n5", "2\n0 0", "2\n-3 3", "2\n1 5", "4\n1 -1 1 -1", "10\n1 -1 2 -2 3 -3 4 -4 0 0", "5\n0 0 0 0 0", "4\n4 4 4 -1", "2\n10 -10", "2\n-10 10", "3\n-1 -1 2", "2\n-1 2", "7\n0 10 -10 10 -10 10 10", "5\n-3 2 1 -1 3", "4\n-10 10 -10 10", "4\n1 -1 2 -2"], "outputs": ["3", "3"...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
11
codeforces
9c04b7bcd219710d34a52373f403d770
Competition
The secondary diagonal of a square matrix is a diagonal going from the top right to the bottom left corner. Let's define an *n*-degree staircase as a square matrix *n*<=×<=*n* containing no squares above the secondary diagonal (the picture below shows a 5-degree staircase). The squares of the *n*-degree staircase con...
{"inputs": ["3 3\n2 3\n3 2\n3 3", "1 1\n1 1", "2 3\n1 2\n2 1\n2 2", "2 1\n1 2", "2 2\n1 2\n2 1", "5 5\n1 5\n3 3\n4 3\n4 5\n5 5", "5 5\n2 5\n4 2\n4 4\n5 4\n5 5", "5 5\n1 5\n3 3\n3 5\n5 1\n5 5", "10 5\n5 10\n9 7\n9 10\n10 1\n10 8", "10 20\n2 9\n3 8\n4 7\n4 8\n5 6\n6 5\n6 6\n6 7\n6 9\n7 5\n7 10\n8 6\n8 9\n9 3\n9 6\n10 1\n...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1
codeforces
9c1e83b6cd335be72b10e0717ba0fae9
Diverse Substrings
String diversity is the number of symbols that occur in the string at least once. Diversity of *s* will be denoted by *d*(*s*). For example , *d*("aaa")=1, *d*("abacaba")=3. Given a string *s*, consisting of lowercase Latin letters. Consider all its substrings. Obviously, any substring diversity is a number from 1 to ...
{"inputs": ["abca", "aabacaabbad", "a", "cabaccbcaa", "ccabaccbbb", "accbbaabaa", "bdbdeabeecddebabaebbcaeabeabcadcbcacebdebaaadbcebabacdedbadadbcbdeccabecbecedcbdadbaabdaaaeebbdddcde", "faaacffcdacdbafffebbaecbbddadbafcddfbbafbebedafcbbccdefcfcddbdefbaabbeacbdcadfdfbeffdbccdbbcefdbeacf", "ccdfadbdcdadgcgabgcebbccebeab...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1
codeforces
9c2b194e5181a074182aca336dbe2ee1
The Modcrab
Vova is again playing some computer game, now an RPG. In the game Vova's character received a quest: to slay the fearsome monster called Modcrab. After two hours of playing the game Vova has tracked the monster and analyzed its tactics. The Modcrab has *h*2 health points and an attack power of *a*2. Knowing that, Vova...
{"inputs": ["10 6 100\n17 5", "11 6 100\n12 5", "25 27 91\n10 87", "79 4 68\n9 65", "9 1 20\n4 19", "1 1 100\n100 99", "6 6 100\n12 5", "9 76 78\n86 69", "62 21 10\n47 2", "50 1 2\n70 1", "4 1 2\n10 1", "1 1 2\n3 1", "14 5 2\n99 1", "20 1 5\n8 4", "12 12 19\n83 8", "5 12 11\n4 2", "34 14 18\n74 14"], "outputs": ["4\nST...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
34
codeforces
9c38652ec748744f39327a92d0a89a94
Odds and Ends
Where do odds begin, and where do they end? Where does hope emerge, and will they ever break? Given an integer sequence *a*1,<=*a*2,<=...,<=*a**n* of length *n*. Decide whether it is possible to divide it into an odd number of non-empty subsegments, the each of which has an odd length and begins and ends with odd numb...
{"inputs": ["3\n1 3 5", "5\n1 0 1 5 1", "3\n4 3 1", "4\n3 9 9 3", "1\n1", "5\n100 99 100 99 99", "100\n100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 1...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
233
codeforces
9c680d17e09521dcfd9dc7aeed589010
Lever
You have a description of a lever as string *s*. We'll represent the string length as record |*s*|, then the lever looks as a horizontal bar with weights of length |*s*|<=-<=1 with exactly one pivot. We will assume that the bar is a segment on the *Ox* axis between points 0 and |*s*|<=-<=1. The decoding of the lever d...
{"inputs": ["=^==", "9===^==1", "2==^7==", "41^52==", "=^2=4=1===1=", "9=6===5==3=9=1=1^7=1==", "85=61=36=^93===4==44==35==94===39===15===", "==88=^95==83=45===8====73===7==7====1=29====29=8=85=", "==41^52==", "2===================^2", "9^=============1", "4=========^=55", "123^321", "7^1=2", "589==^==958"], "outputs":...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
232
codeforces
9c6cea16dc2256c81e8e15748d3d1ad8
Fake News (medium)
Thanks to your help, Heidi is confident that no one can fool her. She has now decided to post some fake news on the HC2 Facebook page. However, she wants to be able to communicate to the HC2 committee that the post is fake, using some secret phrase hidden in the post as a subsequence. To make this method foolproof, she...
{"inputs": ["2", "4", "6", "1", "3", "5", "999983", "1000000", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "1898", "2023", "2152", "2285", "2422", "2563", "2708", "2857", "3010", "3167", "3328", "3493", "3662", "3835", "4012", "4...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
3
codeforces
9c77b4e932176ff9d911680d4f69b20d
Restaurant
A restaurant received *n* orders for the rental. Each rental order reserve the restaurant for a continuous period of time, the *i*-th order is characterized by two time values — the start time *l**i* and the finish time *r**i* (*l**i*<=≤<=*r**i*). Restaurant management can accept and reject orders. What is the maximal...
{"inputs": ["2\n7 11\n4 7", "5\n1 2\n2 3\n3 4\n4 5\n5 6", "6\n4 8\n1 5\n4 7\n2 5\n1 3\n6 8", "1\n1 1", "2\n4 6\n4 8", "3\n22 22\n14 21\n9 25", "4\n20 59\n30 62\n29 45\n29 32", "5\n40 124\n40 117\n67 106\n36 121\n38 102", "6\n124 155\n50 93\n45 120\n54 171\n46 190\n76 179", "7\n94 113\n54 248\n64 325\n280 306\n62 328\n4...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
46
codeforces
9c934e5e7dde1c071061f60eff3f575b
Game
Furik and Rubik love playing computer games. Furik has recently found a new game that greatly interested Rubik. The game consists of *n* parts and to complete each part a player may probably need to complete some other ones. We know that the game can be fully completed, that is, its parts do not form cyclic dependencie...
{"inputs": ["1\n1\n0", "5\n2 2 1 1 3\n1 5\n2 5 1\n2 5 4\n1 5\n0", "7\n1 3 3 1 2 1 1\n0\n1 1\n1 1\n2 1 6\n3 1 2 7\n1 1\n1 1", "2\n2 1\n0\n1 1", "3\n2 1 2\n0\n0\n0", "4\n2 1 1 1\n0\n0\n1 1\n1 3", "6\n1 1 2 3 3 1\n2 2 3\n0\n0\n0\n2 2 1\n1 1", "8\n2 2 2 1 1 2 1 1\n3 5 6 7\n1 5\n2 5 6\n1 5\n0\n1 5\n1 5\n2 5 6", "9\n3 3 2 1 ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
4
codeforces
9c9bb571a19dfeabafcede78003b69ff
Reposts
One day Polycarp published a funny picture in a social network making a poll about the color of his handle. Many of his friends started reposting Polycarp's joke to their news feed. Some of them reposted the reposts and so on. These events are given as a sequence of strings "name1 reposted name2", where name1 is the n...
{"inputs": ["5\ntourist reposted Polycarp\nPetr reposted Tourist\nWJMZBMR reposted Petr\nsdya reposted wjmzbmr\nvepifanov reposted sdya", "6\nMike reposted Polycarp\nMax reposted Polycarp\nEveryOne reposted Polycarp\n111 reposted Polycarp\nVkCup reposted Polycarp\nCodeforces reposted Polycarp", "1\nSoMeStRaNgEgUe repos...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
489
codeforces