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
c24a81f69a8987d5a513e4987cd9b6b9
Arpa’s obvious problem and Mehrdad’s terrible solution
There are some beautiful girls in Arpa’s land as mentioned before. Once Arpa came up with an obvious problem: Given an array and a number *x*, count the number of pairs of indices *i*,<=*j* (1<=≤<=*i*<=&lt;<=*j*<=≤<=*n*) such that , where is bitwise xor operation (see notes for explanation). Immediately, Mehrdad di...
{"inputs": ["2 3\n1 2", "6 1\n5 1 2 3 4 1", "38 101\n395 5 339 366 409 150 400 180 348 200 409 20 182 409 208 74 176 401 459 158 282 207 241 406 33 484 65 245 363 337 204 197 445 445 72 435 126 423", "47 117\n77 57 535 240 250 321 51 29 42 582 390 525 149 195 119 465 198 494 456 313 497 205 115 256 513 413 15 423 568 1...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
16
codeforces
c25593723134889d759fd6786d906c97
none
Gennady is one of the best child dentists in Berland. Today *n* children got an appointment with him, they lined up in front of his office. All children love to cry loudly at the reception at the dentist. We enumerate the children with integers from 1 to *n* in the order they go in the line. Every child is associated ...
{"inputs": ["5\n4 2 2\n4 1 2\n5 2 4\n3 3 5\n5 1 2", "5\n4 5 1\n5 3 9\n4 1 2\n2 1 8\n4 1 9", "10\n10 7 10\n3 6 11\n8 4 10\n10 1 11\n7 3 13\n7 2 13\n7 6 14\n3 4 17\n9 4 20\n5 2 24", "10\n5 6 3\n7 4 10\n9 1 17\n2 8 23\n9 10 24\n6 8 18\n3 2 35\n7 6 6\n1 3 12\n9 9 5", "10\n4 9 1\n8 2 14\n7 10 20\n6 9 18\n5 3 19\n2 9 7\n6 8 ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
10
codeforces
c25b6da41baeb504d209ee704414dbfc
Area of a Star
It was decided in IT City to distinguish successes of local IT companies by awards in the form of stars covered with gold from one side. To order the stars it is necessary to estimate order cost that depends on the area of gold-plating. Write a program that can calculate the area of a star. A "star" figure having *n*<...
{"inputs": ["7 10", "5 1", "7 1000", "11 1000000000", "999999937 1", "999999929 2", "999999929 1000000000", "603530531 585244", "7369339 31415926", "2341 5001"], "outputs": ["108.395919545675", "1.122569941449", "1083959.195456745256", "1061689977712182980.125000000000", "1.047197551197", "4.188790204786", "10471975511...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
2
codeforces
c261497be852ac543fbe17bd9a243b60
Vulnerable Kerbals
You are given an integer *m*, and a list of *n* distinct integers between 0 and *m*<=-<=1. You would like to construct a sequence satisfying the properties: - Each element is an integer between 0 and *m*<=-<=1, inclusive. - All prefix products of the sequence modulo *m* are distinct. - No prefix product modulo *m*...
{"inputs": ["0 5", "3 10\n2 9 1", "0 1", "0 720", "0 9997", "0 200000", "10 200000\n7853 79004 71155 23846 63333 31964 47634 15792 39758 55551", "3 19997\n4524 13719 9073", "3 19997\n2024 4058 6143", "3 19997\n6068 18563 12338"], "outputs": ["5\n1 2 4 3 0", "6\n3 9 2 9 8 0", "1\n0", "397\n1 7 413 263 389 467 77 283 299...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
2
codeforces
c27368c56a4d9ea1647917157aef81aa
Check the string
A has a string consisting of some number of lowercase English letters 'a'. He gives it to his friend B who appends some number of letters 'b' to the end of this string. Since both A and B like the characters 'a' and 'b', they have made sure that at this point, at least one 'a' and one 'b' exist in the string. B now gi...
{"inputs": ["aaabccc", "bbacc", "aabc", "aabbcc", "aaacccbb", "abc", "acba", "bbabbc", "bbbabacca", "aabcbcaca", "aaaaabbbbbb", "c", "cc", "bbb", "bc", "ccbcc", "aaa", "aaccaa", "a", "b", "abca", "aabbcccc", "abac", "abcc", "abcb", "aacc", "aabbaacccc", "aabb", "ac", "abbacc", "abacc", "ababc", "aa", "aabaccc", "bbcc",...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
120
codeforces
c28cf0add33a4e63ce6077ddf93bd7e9
Devu, the Dumb Guy
Devu is a dumb guy, his learning curve is very slow. You are supposed to teach him *n* subjects, the *i**th* subject has *c**i* chapters. When you teach him, you are supposed to teach all the chapters of a subject continuously. Let us say that his initial per chapter learning power of a subject is *x* hours. In other ...
{"inputs": ["2 3\n4 1", "4 2\n5 1 2 1", "3 3\n1 1 1", "20 4\n1 1 3 5 5 1 3 4 2 5 2 4 3 1 3 3 3 3 4 3", "20 10\n6 6 1 2 6 4 5 3 6 5 4 5 6 5 4 6 6 2 3 3", "1 1\n9273", "1 1\n1", "1 2\n1", "1 2\n2", "2 1\n1 2"], "outputs": ["11", "10", "6", "65", "196", "9273", "1", "2", "4", "3"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
299
codeforces
c2a566fe43974d07b567fd3c0e438366
Byteland, Berland and Disputed Cities
The cities of Byteland and Berland are located on the axis $Ox$. In addition, on this axis there are also disputed cities, which belong to each of the countries in their opinion. Thus, on the line $Ox$ there are three types of cities: - the cities of Byteland, - the cities of Berland, - disputed cities. Recently, ...
{"inputs": ["4\n-5 R\n0 P\n3 P\n7 B", "5\n10 R\n14 B\n16 B\n21 R\n32 R", "10\n66 R\n67 R\n72 R\n73 R\n76 R\n78 B\n79 B\n83 B\n84 B\n85 P", "10\n61 R\n64 R\n68 R\n71 R\n72 R\n73 R\n74 P\n86 P\n87 B\n90 B", "15\n-9518 R\n-6858 P\n-6726 B\n-6486 R\n-4496 P\n-4191 P\n-772 B\n-258 R\n-194 P\n1035 R\n2297 P\n4816 B\n5779 R\n...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
6
codeforces
c2d5c5716d620d4c3e6264bef5bdc57b
Wizards and Trolleybuses
In some country live wizards. They love to ride trolleybuses. A city in this country has a trolleybus depot with *n* trolleybuses. Every day the trolleybuses leave the depot, one by one and go to the final station. The final station is at a distance of *d* meters from the depot. We know for the *i*-th trolleybus that ...
{"inputs": ["3 10 10000\n0 10\n5 11\n1000 1", "1 2 26\n28 29", "7 8 3\n1 3\n5 26\n7 3\n10 15\n18 7\n21 17\n23 21", "3 6 6\n2 10\n14 19\n18 14", "10 7 8\n2 4\n3 13\n4 7\n5 1\n9 16\n10 9\n12 18\n16 4\n17 16\n20 6", "8 4 13\n0 18\n6 24\n10 25\n11 5\n12 18\n20 22\n21 8\n22 12", "1 2 7\n20 13", "3 3 3\n13 1\n18 12\n19 2", "...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
13
codeforces
c2fb46bcb0c07141a390386eb43d17e6
Success Rate
You are an experienced Codeforces user. Today you found out that during your activity on Codeforces you have made *y* submissions, out of which *x* have been successful. Thus, your current success rate on Codeforces is equal to *x*<=/<=*y*. Your favorite rational number in the [0;1] range is *p*<=/<=*q*. Now you wonde...
{"inputs": ["4\n3 10 1 2\n7 14 3 8\n20 70 2 7\n5 6 1 1", "8\n0 1 0 1\n0 2 1 2\n0 3 1 1\n1 2 0 1\n1 2 1 1\n2 2 0 1\n3 3 1 2\n4 4 1 1", "5\n1 1000000000 1 2\n1 1000000000 1 2\n1 1000000000 1 2\n1 1000000000 1 2\n1 1000000000 1 2", "5\n999999999 1000000000 1 1000000000\n999999999 1000000000 1 1000000000\n999999999 1000000...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
55
codeforces
c305e3530a54f2ea0d43187252188974
Game of Stones
Sam has been teaching Jon the Game of Stones to sharpen his mind and help him devise a strategy to fight the white walkers. The rules of this game are quite simple: - The game starts with *n* piles of stones indexed from 1 to *n*. The *i*-th pile contains *s**i* stones.- The players make their moves alternatively. A...
{"inputs": ["1\n5", "2\n1\n2", "3\n34\n44\n21", "6\n34\n44\n21\n55\n1\n36", "14\n34\n44\n21\n55\n1\n36\n53\n31\n58\n59\n11\n40\n20\n32", "10\n34\n44\n21\n55\n1\n36\n53\n31\n58\n59", "12\n34\n44\n21\n55\n1\n36\n53\n31\n58\n59\n11\n40", "118\n34\n44\n21\n55\n1\n36\n53\n31\n58\n59\n11\n40\n20\n32\n43\n48\n16\n5\n35\n20\n2...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1
codeforces
c32aecaf273108e539a4710735fff11f
Gosha is hunting
Gosha is hunting. His goal is to catch as many Pokemons as possible. Gosha has *a* Poke Balls and *b* Ultra Balls. There are *n* Pokemons. They are numbered 1 through *n*. Gosha knows that if he throws a Poke Ball at the *i*-th Pokemon he catches it with probability *p**i*. If he throws an Ultra Ball at the *i*-th Poke...
{"inputs": ["3 2 2\n1.000 0.000 0.500\n0.000 1.000 0.500", "4 1 3\n0.100 0.500 0.500 0.600\n0.100 0.500 0.900 0.400", "3 2 0\n0.412 0.198 0.599\n0.612 0.987 0.443", "8 4 1\n0.425 0.709 0.507 0.932 0.085 0.389 0.215 0.508\n0.471 0.825 0.240 0.981 0.184 0.241 0.810 0.711", "7 4 4\n0.642 0.036 0.552 0.936 0.866 0.905 0.40...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1
codeforces
c33a7c4403551ca5163e14847cc720c9
Bus of Characters
In the Bus of Characters there are $n$ rows of seat, each having $2$ seats. The width of both seats in the $i$-th row is $w_i$ centimeters. All integers $w_i$ are distinct. Initially the bus is empty. On each of $2n$ stops one passenger enters the bus. There are two types of passengers: - an introvert always choose...
{"inputs": ["2\n3 1\n0011", "6\n10 8 9 11 13 5\n010010011101", "1\n1\n01", "1\n1000000\n01", "2\n1 1000000\n0011", "2\n1000000000 1\n0101", "2\n1000000000 999999999\n0011", "10\n24 53 10 99 83 9 15 62 33 47\n00100000000111111111"], "outputs": ["2 1 1 2 ", "6 6 2 3 3 1 4 4 1 2 5 5 ", "1 1 ", "1 1 ", "1 2 2 1 ", "2 2 1 1...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
68
codeforces
c33ee1ebed2d67a1fc93b05bf3e8b65a
Eugeny and Play List
Eugeny loves listening to music. He has *n* songs in his play list. We know that song number *i* has the duration of *t**i* minutes. Eugeny listens to each song, perhaps more than once. He listens to song number *i* *c**i* times. Eugeny's play list is organized as follows: first song number 1 plays *c*1 times, then son...
{"inputs": ["1 2\n2 8\n1 16", "4 9\n1 2\n2 1\n1 1\n2 2\n1 2 3 4 5 6 7 8 9", "3 3\n2 8\n5 1\n10 5\n13 16 62", "4 4\n2 8\n2 2\n6 3\n8 7\n13 23 29 85", "5 5\n9 6\n8 7\n2 9\n10 3\n8 10\n69 95 146 162 177", "6 6\n4 9\n8 5\n3 8\n8 10\n4 2\n10 9\n15 45 97 197 231 265", "7 7\n1 10\n1 1\n7 2\n4 9\n10 4\n5 5\n7 1\n48 71 86 87 11...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
100
codeforces
c34576ad4cc651a3744cc85ae9b0a608
Replace To Make Regular Bracket Sequence
You are given string *s* consists of opening and closing brackets of four kinds &lt;&gt;, {}, [], (). There are two types of brackets: opening and closing. You can replace any bracket by another of the same type. For example, you can replace &lt; by the bracket {, but you can't replace it by ) or &gt;. The following d...
{"inputs": ["[<}){}", "{()}[]", "]]", ">", "{}", "{}", "{]", "{]", "{]", "[]{[]({)([", "(([{>}{[{[)]]>>]", "((<>)[]<]><]", "[[([[(>]>)))[<)>", "({)[}<)](}", "(}{)[<][)(]}", ">}({>]{[}<{<{{)[]]{)]>]]]<(][{)<<<{<<)>)()[>{<]]{}<>}}}}(>}<})(][>{((<{<)]}>)))][>[}[])<]){]]][<[)([", "<<[<{{<([({<<[)<>(]]){})>[](])[)))[[}>]<)>...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
73
codeforces
c35efd66426b5bd961aa720f0ee29dcb
Guilty --- to the kitchen!
It's a very unfortunate day for Volodya today. He got bad mark in algebra and was therefore forced to do some work in the kitchen, namely to cook borscht (traditional Russian soup). This should also improve his algebra skills. According to the borscht recipe it consists of *n* ingredients that have to be mixed in prop...
{"inputs": ["1 100\n1\n40", "2 100\n1 1\n25 30", "2 100\n1 1\n60 60", "2 100\n1 1\n50 50", "2 100\n1 2\n33 66", "3 10000\n1 1 1\n100 0 100", "7 5100\n21 93 52 80 5 46 20\n79 37 74 54 22 15 90", "10 2707\n80 91 41 99 99 48 81 25 80 17\n88 79 64 78 4 54 38 92 77 61", "19 8111\n44 75 80 69 90 64 58 8 93 50 44 39 7 25 14 5...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
43
codeforces
c3b0f25282825914e3165f036647ca3b
Wrath
Hands that shed innocent blood! There are *n* guilty people in a line, the *i*-th of them holds a claw with length *L**i*. The bell rings and every person kills some of people in front of him. All people kill others at the same time. Namely, the *i*-th person kills the *j*-th person if and only if *j*<=&lt;<=*i* and *...
{"inputs": ["4\n0 1 0 10", "2\n0 0", "10\n1 1 3 0 0 0 2 1 0 3", "10\n0 0 2 0 0 3 3 2 2 0", "1\n0", "5\n0 0 0 1 0", "6\n3 1 1 0 3 3", "8\n0 0 0 1 0 0 1 2", "1\n1000000000", "2\n1 3", "2\n1000000000 1000000000", "11\n1 0 0 1 1 3 2 0 0 2 3", "1\n1"], "outputs": ["1", "2", "3", "2", "1", "4", "1", "5", "1", "1", "1", "4", ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
206
codeforces
c3caabd20656dfea798193d9f8828c62
bHTML Tables Analisys
In this problem is used an extremely simplified version of HTML table markup. Please use the statement as a formal document and read it carefully. A string is a bHTML table, if it satisfies the grammar: Blanks in the grammar are only for purposes of illustration, in the given data there will be no spaces. The bHTML ...
{"inputs": ["<table><tr><td></td></tr></table>", "<table>\n<tr>\n<td>\n<table><tr><td></td></tr><tr><td></\ntd\n></tr><tr\n><td></td></tr><tr><td></td></tr></table>\n</td>\n</tr>\n</table>", "<table><tr><td>\n<table><tr><td>\n<table><tr><td>\n<table><tr><td></td><td></td>\n</tr><tr><td></td></tr></table>\n</td></tr></t...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
7
codeforces
c3d790805eede963d52bb39905c572fe
Queries about less or equal elements
You are given two arrays of integers *a* and *b*. For each element of the second array *b**j* you should find the number of elements in array *a* that are less than or equal to the value *b**j*. The first line contains two integers *n*,<=*m* (1<=≤<=*n*,<=*m*<=≤<=2·105) — the sizes of arrays *a* and *b*. The second lin...
{"inputs": ["5 4\n1 3 5 7 9\n6 4 2 8", "5 5\n1 2 1 2 5\n3 1 4 1 5", "1 1\n-1\n-2", "1 1\n-80890826\n686519510", "11 11\n237468511 -779187544 -174606592 193890085 404563196 -71722998 -617934776 170102710 -442808289 109833389 953091341\n994454001 322957429 216874735 -606986750 -455806318 -663190696 3793295 41395397 -9296...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
241
codeforces
c3f6f1b2d8283ce5173cfcc44bb75b45
Intersection
You are given two set of points. The first set is determined by the equation *A*1*x*<=+<=*B*1*y*<=+<=*C*1<==<=0, and the second one is determined by the equation *A*2*x*<=+<=*B*2*y*<=+<=*C*2<==<=0. Write the program which finds the number of points in the intersection of two given sets. The first line of the input con...
{"inputs": ["1 1 0\n2 2 0", "1 1 0\n2 -2 0", "0 0 0\n0 0 0", "1 1 1\n1 1 1", "8 3 -4\n-5 2 7", "-1 -1 0\n0 -1 -1", "-1 -1 0\n1 1 -1", "-1 -1 1\n0 -1 0", "0 0 0\n1 -1 -1", "0 0 1\n-1 1 -1", "0 1 -1\n-1 1 -1", "1 0 -1\n0 0 -1", "0 1 1\n1 0 0", "1 0 0\n0 0 1", "1 -1 -1\n1 -1 0", "1 0 0\n0 1 1", "1 -1 1\n-1 -1 1", "1 0 0\n...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
15
codeforces
c3fb39355574a7e1da59bd733c53c45c
Parallelepiped
You've got a rectangular parallelepiped with integer edge lengths. You know the areas of its three faces that have a common vertex. Your task is to find the sum of lengths of all 12 edges of this parallelepiped. The first and the single line contains three space-separated integers — the areas of the parallelepiped's fa...
{"inputs": ["1 1 1", "4 6 6", "20 10 50", "9 4 36", "324 9 36", "1333 93 129", "1022 584 112", "66 174 319", "912 276 1748", "65 156 60", "1 10000 10000", "1485 55 27", "152 108 4104", "1656 6900 1350", "12 14 42", "615 18 1230", "680 60 408", "644 966 6", "1 432 432", "2239 2239 1", "4106 8212 2", "10000 10000 10000",...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
622
codeforces
c405d7dde8cef7bb4e1c964e697aa3e5
T-Shirt Hunt
Not so long ago the Codecraft-17 contest was held on Codeforces. The top 25 participants, and additionally random 25 participants out of those who got into top 500, will receive a Codeforces T-shirt. Unfortunately, you didn't manage to get into top 25, but you got into top 500, taking place *p*. Now the elimination r...
{"inputs": ["239 10880 9889", "26 7258 6123", "493 8000 8000", "101 6800 6500", "329 19913 19900", "264 19252 10888", "176 9670 9174", "42 11 6", "412 17647 15917", "91 4883 4302", "200 16031 15842", "186 18666 18329", "486 9748 9598", "180 4213 4207", "329 19989 1", "390 11676 2570", "173 7017 4512", "38 6404 5034", "...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
31
codeforces
c40e9d6ff14b79d32f1975a0c3702047
Dima and Staircase
Dima's got a staircase that consists of *n* stairs. The first stair is at height *a*1, the second one is at *a*2, the last one is at *a**n* (1<=≤<=*a*1<=≤<=*a*2<=≤<=...<=≤<=*a**n*). Dima decided to play with the staircase, so he is throwing rectangular boxes at the staircase from above. The *i*-th box has width *w**i...
{"inputs": ["5\n1 2 3 6 6\n4\n1 1\n3 1\n1 1\n4 3", "3\n1 2 3\n2\n1 1\n3 1", "1\n1\n5\n1 2\n1 10\n1 10\n1 10\n1 10", "8\n6 10 18 23 30 31 31 33\n1\n5 3", "7\n8 13 19 21 25 30 32\n3\n5 4\n6 5\n1 2", "5\n4 7 10 12 12\n9\n3 9\n2 1\n3 5\n4 7\n1 1\n5 1\n1 7\n2 4\n4 10", "3\n1 6 8\n5\n3 4\n3 9\n3 3\n1 2\n1 6", "3\n2 10 15\n1\...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
38
codeforces
c428cb3795453c6365d8f87de077feb5
Mike and palindrome
Mike has a string *s* consisting of only lowercase English letters. He wants to change exactly one character from the string so that the resulting one is a palindrome. A palindrome is a string that reads the same backward as forward, for example strings "z", "aaa", "aba", "abccba" are palindromes, but strings "codefo...
{"inputs": ["abccaa", "abbcca", "abcda", "kyw", "fccf", "mnlm", "gqrk", "glxlg", "czhfc", "broon", "rmggmr", "wvxxzw", "ukvciu", "vrnwnrv", "vlkjkav", "guayhmg", "lkvhhvkl", "ffdsslff", "galjjtyw", "uosgwgsou", "qjwmjmljq", "ustrvrodf", "a", "qjfyjjyfjq", "ysxibbixsq", "howfslfwmh", "ekhajrjahke", "ucnolsloncw", "jrzsf...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
163
codeforces
c471ea63a38a1fc6ba0d6161cb75b220
Bertown Subway
The construction of subway in Bertown is almost finished! The President of Berland will visit this city soon to look at the new subway himself. There are *n* stations in the subway. It was built according to the Bertown Transport Law: 1. For each station *i* there exists exactly one train that goes from this station...
{"inputs": ["3\n2 1 3", "5\n1 5 4 3 2", "1\n1", "2\n1 2", "2\n2 1", "100\n98 52 63 2 18 96 31 58 84 40 41 45 66 100 46 71 26 48 81 20 73 91 68 76 13 93 17 29 64 95 79 21 55 75 19 85 54 51 89 78 15 87 43 59 36 1 90 35 65 56 62 28 86 5 82 49 3 99 33 9 92 32 74 69 27 22 77 16 44 94 34 6 57 70 23 12 61 25 8 11 67 47 83 88 ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
48
codeforces
c4925395433ef9f0418e15736bd8532f
Squares
Vasya has found a piece of paper with a coordinate system written on it. There are *n* distinct squares drawn in this coordinate system. Let's number the squares with integers from 1 to *n*. It turned out that points with coordinates (0,<=0) and (*a**i*,<=*a**i*) are the opposite corners of the *i*-th square. Vasya wa...
{"inputs": ["4 3\n5 1 3 4", "3 1\n2 4 1", "4 50\n5 1 10 2", "3 4\n5 1 4", "1 1\n2", "1 2\n10", "10 5\n68 78 70 3 77 2 24 17 96 63", "5 2\n10 9 19 12 14", "2 2\n7 2", "2 1\n8 20", "2 40\n33 29", "5 10\n7 5 9 10 8", "9 8\n83 6 90 96 42 71 11 82 51", "40 30\n115644639 84968781 502201719 185562964 985439338 904909761 98746...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
4
codeforces
c49fbe44ec18bf074af51a7b17df7ae3
Maze
Pavel loves grid mazes. A grid maze is an *n*<=×<=*m* rectangle maze where each cell is either empty, or is a wall. You can go from one cell to another only if both cells are empty and have a common side. Pavel drew a grid maze with all empty cells forming a connected area. That is, you can go from any empty cell to a...
{"inputs": ["5 4 5\n#...\n#.#.\n.#..\n...#\n.#.#", "3 3 2\n#.#\n...\n#.#", "7 7 18\n#.....#\n..#.#..\n.#...#.\n...#...\n.#...#.\n..#.#..\n#.....#", "1 1 0\n.", "2 3 1\n..#\n#..", "2 3 1\n#..\n..#", "3 3 1\n...\n.#.\n..#", "3 3 1\n...\n.#.\n#..", "5 4 4\n#..#\n....\n.##.\n....\n#..#", "5 5 2\n.#..#\n..#.#\n#....\n##.#.\...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
97
codeforces
c4ad62bddbc94c55cc70b08762937167
Bombs
You've got a robot, its task is destroying bombs on a square plane. Specifically, the square plane contains *n* bombs, the *i*-th bomb is at point with coordinates (*x**i*,<=*y**i*). We know that no two bombs are at the same point and that no bomb is at point with coordinates (0,<=0). Initially, the robot is at point w...
{"inputs": ["2\n1 1\n-1 -1", "3\n5 0\n0 5\n1 0", "1\n-277226476 314722425", "2\n-404192496 -968658337\n556071553 -256244640", "24\n-2 -2\n-1 1\n0 1\n1 1\n0 2\n1 -1\n2 -2\n1 -2\n-1 0\n0 -2\n0 -1\n-2 0\n-2 -1\n2 -1\n2 2\n-1 -2\n-2 1\n2 0\n-1 2\n1 2\n-1 -1\n1 0\n2 1\n-2 2"], "outputs": ["12\n1 1 R\n1 1 U\n2\n1 1 L\n1 1 D\...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
11
codeforces
c4b0d56e3f40a886b55753344382562d
Minimization
You've got array *A*, consisting of *n* integers and a positive integer *k*. Array *A* is indexed by integers from 1 to *n*. You need to permute the array elements so that value The first line contains two integers *n*,<=*k* (2<=≤<=*n*<=≤<=3·105, 1<=≤<=*k*<=≤<=*min*(5000,<=*n*<=-<=1)). The second line contains *n* i...
{"inputs": ["3 2\n1 2 4", "5 2\n3 -5 3 -5 3", "6 3\n4 3 4 3 2 5", "2 1\n1 100", "4 3\n1 2 4 8", "5 2\n1 2 8 8 16", "10 3\n-999999914 -999999976 -999999966 -999999952 29 54 -999999963 -999999959 -999999974 48", "30 2\n-999999924 -499999902 500000091 -999999998 500000030 -999999934 500000086 -499999918 -499999998 67 -999...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
2
codeforces
c4dd3e1e06a63ef2153e3968b846c4ce
Really Big Numbers
Ivan likes to learn different things about numbers, but he is especially interested in really big numbers. Ivan thinks that a positive integer number *x* is really big if the difference between *x* and the sum of its digits (in decimal representation) is not less than *s*. To prove that these numbers may have different...
{"inputs": ["12 1", "25 20", "10 9", "300 1000", "500 1000", "1000 2000", "10000 1000", "1000000000000000000 1000000000000000000", "1000000000000000000 100000000000000000", "1000000000000000000 10000000000000000", "1000000000000000000 1000000000000000", "1000000000000000000 100000000000000", "1000000000000000000 200000...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
89
codeforces
c4ed979e1e7dc2e04476df656d461770
Square Table
While resting on the ship after the "Russian Code Cup" a boy named Misha invented an interesting game. He promised to give his quadrocopter to whoever will be the first one to make a rectangular table of size *n*<=×<=*m*, consisting of positive integers such that the sum of the squares of numbers for each row and each ...
{"inputs": ["1 1", "1 2", "4 1", "1 4", "2 1", "2 4", "48 2", "3 75", "33 1", "4 23", "58 2", "2 11", "7 14", "48 24", "77 93", "77 20", "30 31", "100 100"], "outputs": ["1 ", "3 4 ", "1 \n1 \n1 \n1 ", "1 1 1 1 ", "3 \n4 ", "3 3 3 3 \n4 4 4 4 ", "3 4 \n3 4 \n3 4 \n3 4 \n3 4 \n3 4 \n3 4 \n3 4 \n3 4 \n3 4 \n3 4 \n3 4 \n3...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
3
codeforces
c4f24bad678c0dc44f16444d1931b0f5
Currency System in Geraldion
A magic island Geraldion, where Gerald lives, has its own currency system. It uses banknotes of several values. But the problem is, the system is not perfect and sometimes it happens that Geraldionians cannot express a certain sum of money with any set of banknotes. Of course, they can use any number of banknotes of ea...
{"inputs": ["5\n1 2 3 4 5", "1\n2", "10\n371054 506438 397130 1 766759 208409 769264 549213 641270 771837", "10\n635370 154890 909382 220996 276501 716105 538714 140162 171960 271264", "50\n110876 835020 859879 999908 712969 788264 287153 921820 330355 499311 209594 484829 296329 940051 174081 931503 1 780512 390075 97...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
304
codeforces
c50b1b965f540f3178cb912f00fd25cf
Spyke Talks
Polycarpus is the director of a large corporation. There are *n* secretaries working for the corporation, each of them corresponds via the famous Spyke VoIP system during the day. We know that when two people call each other via Spyke, the Spyke network assigns a unique ID to this call, a positive integer session numbe...
{"inputs": ["6\n0 1 7 1 7 10", "3\n1 1 1", "1\n0", "5\n2 2 1 1 3", "1\n1", "10\n4 21 3 21 21 1 1 2 2 3", "2\n1 2", "5\n0 0 0 0 0", "6\n6 6 0 8 0 0", "10\n0 0 0 0 0 1 0 1 0 1", "100\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 3 0 3 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 3 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
61
codeforces
c544dbf38e7f9a8e6286d2e4f208c1e3
Puzzles
The end of the school year is near and Ms. Manana, the teacher, will soon have to say goodbye to a yet another class. She decided to prepare a goodbye present for her *n* students and give each of them a jigsaw puzzle (which, as wikipedia states, is a tiling puzzle that requires the assembly of numerous small, often od...
{"inputs": ["4 6\n10 12 10 7 5 22", "2 2\n4 4", "2 10\n4 5 6 7 8 9 10 11 12 12", "4 5\n818 136 713 59 946", "3 20\n446 852 783 313 549 965 40 88 86 617 479 118 768 34 47 826 366 957 463 903", "2 25\n782 633 152 416 432 825 115 97 386 357 836 310 530 413 354 373 847 882 913 682 729 582 671 674 94", "4 25\n226 790 628 52...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
385
codeforces
c58eac4bb58780bf424ac77f4fb18275
Physical Education and Buns
The Physical education teacher at SESC is a sort of mathematician too. His most favorite topic in mathematics is progressions. That is why the teacher wants the students lined up in non-decreasing height form an arithmetic progression. To achieve the goal, the gym teacher ordered a lot of magical buns from the dining ...
{"inputs": ["5\n-3 -4 -2 -3 3", "5\n2 -3 -1 -4 3", "6\n94 65 -33 -43 60 -24", "3\n-10000 10000 -10000", "2\n0 0", "7\n-1 -2 -4 -10 6 6 5", "10\n-10 3 -16 -15 14 -16 13 -6 -8 18", "50\n-67 -84 -89 80 40 42 -38 30 74 -12 -66 27 1 11 -45 -44 2 -70 -59 -70 -59 -59 62 100 -5 1 91 79 47 -64 -51 -88 -5 37 82 87 79 46 76 47 60...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
2
codeforces
c597f61ed8d5dea2daccb09176049488
Watchmen
Watchmen are in a danger and Doctor Manhattan together with his friend Daniel Dreiberg should warn them as soon as possible. There are *n* watchmen on a plane, the *i*-th watchman is located at point (*x**i*,<=*y**i*). They need to arrange a plan, but there are some difficulties on their way. As you know, Doctor Manha...
{"inputs": ["3\n1 1\n7 5\n1 5", "6\n0 0\n0 1\n0 2\n-1 1\n0 1\n1 1", "10\n46 -55\n46 45\n46 45\n83 -55\n46 45\n83 -55\n46 45\n83 45\n83 45\n46 -55", "1\n-5 -90", "2\n315 845\n-669 -762", "3\n8911 7861\n-6888 7861\n8911 7861", "2\n-1 1000000000\n0 -1", "2\n1000000000 0\n-7 1", "2\n1 4\n2 1", "2\n1 0\n0 2333333", "2\n2 1\...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
194
codeforces
c59ca7de6700cc5a4c83078af6170202
The Monster and the Squirrel
Ari the monster always wakes up very early with the first ray of the sun and the first thing she does is feeding her squirrel. Ari draws a regular convex polygon on the floor and numbers it's vertices 1,<=2,<=...,<=*n* in clockwise order. Then starting from the vertex 1 she draws a ray in the direction of each other v...
{"inputs": ["5", "3", "54321", "4", "6", "7", "8", "9", "10", "54320", "54319", "54318", "54317", "54316", "54315", "54314", "8153", "51689", "16659", "47389", "314", "23481", "20380", "1994"], "outputs": ["9", "1", "2950553761", "4", "16", "25", "36", "49", "64", "2950445124", "2950336489", "2950227856", "2950119225",...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
113
codeforces
c5c5681c6f810bdbc9e8ce105d24d625
Round Subset
Let's call the roundness of the number the number of zeros to which it ends. You have an array of *n* numbers. You need to choose a subset of exactly *k* numbers so that the roundness of the product of the selected numbers will be maximum possible. The first line contains two integer numbers *n* and *k* (1<=≤<=*n*<=≤<...
{"inputs": ["3 2\n50 4 20", "5 3\n15 16 3 25 9", "3 3\n9 77 13", "1 1\n200000000", "1 1\n3", "3 1\n1000000000000000000 800000000000000000 625", "20 13\n93050001 1 750000001 950000001 160250001 482000001 145875001 900000001 500000001 513300001 313620001 724750001 205800001 400000001 800000001 175000001 875000001 8526860...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
4
codeforces
c5ca3ab2eac89426a9d116a1fd9ce067
Little Girl and Maximum Sum
The little girl loves the problems on array queries very much. One day she came across a rather well-known problem: you've got an array of $n$ elements (the elements of the array are indexed starting from 1); also, there are $q$ queries, each one is defined by a pair of integers $l_i$, $r_i$ $(1 \le l_i \le r_i \le n)...
{"inputs": ["3 3\n5 3 2\n1 2\n2 3\n1 3", "5 3\n5 2 4 1 3\n1 5\n2 3\n2 3", "34 21\n23 38 16 49 44 50 48 34 33 19 18 31 11 15 20 47 44 30 39 33 45 46 1 13 27 16 31 36 17 23 38 5 30 16\n8 16\n14 27\n8 26\n1 8\n5 6\n23 28\n4 33\n13 30\n12 30\n11 30\n9 21\n1 14\n15 22\n4 11\n5 24\n8 20\n17 33\n6 9\n3 14\n25 34\n10 17", "16 ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
92
codeforces
c5ea6b1be53adf0faf640c2b06b4178e
Seating On Bus
Consider 2*n* rows of the seats in a bus. *n* rows of the seats on the left and *n* rows of the seats on the right. Each row can be filled by two people. So the total capacity of the bus is 4*n*. Consider that *m* (*m*<=≤<=4*n*) people occupy the seats in the bus. The passengers entering the bus are numbered from 1 to...
{"inputs": ["2 7", "9 36", "1 1", "1 4", "10 1", "10 10", "10 40", "10 39", "77 1", "77 13", "77 53", "77 280", "100 1", "100 13", "100 77", "100 103", "100 200", "100 199", "100 201", "100 300", "100 399", "100 400", "3 9"], "outputs": ["5 1 6 2 7 3 4", "19 1 20 2 21 3 22 4 23 5 24 6 25 7 26 8 27 9 28 10 29 11 30 12 3...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
88
codeforces
c5f46d86f67634da80c5333c585ae150
Phone Numbers
And where the are the phone numbers? You are given a string *s* consisting of lowercase English letters and an integer *k*. Find the lexicographically smallest string *t* of length *k*, such that its set of letters is a subset of the set of letters of *s* and *s* is lexicographically smaller than *t*. It's guaranteed...
{"inputs": ["3 3\nabc", "3 2\nabc", "3 3\nayy", "2 3\nba", "1 3\nf", "3 1\nazz", "3 3\nzbf", "2 3\ngi", "3 2\nyzy", "5 10\nkekff", "10 5\nhqqqqcdddb", "10 10\nmrfkcsxcuj", "10 3\nggjnohlepu", "8 9\npppppppp", "10 7\nffffffffyf", "10 2\nkmiejhcimj", "10 1\ngiwekrmngf", "8 8\nlolololo", "10 9\nbcegikmyyy", "7 5000\nqqqqq...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
57
codeforces
c60017dd2b08478f814800ebfa6f9f27
Guess Your Way Out! II
Amr bought a new video game "Guess Your Way Out! II". The goal of the game is to find an exit from the maze that looks like a perfect binary tree of height *h*. The player is initially standing at the root of the tree and the exit from the tree is located at some leaf node. Let's index all the nodes of the tree such t...
{"inputs": ["3 1\n3 4 6 0", "4 3\n4 10 14 1\n3 6 6 0\n2 3 3 1", "4 2\n3 4 6 1\n4 12 15 1", "4 2\n3 4 5 1\n2 3 3 1", "1 0", "1 1\n1 1 1 0"], "outputs": ["7", "14", "Data not sufficient!", "Game cheated!", "1", "Game cheated!"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
2
codeforces
c64702b7496904c374deec17f72e5c05
Odd sum
You are given sequence *a*1,<=*a*2,<=...,<=*a**n* of integer numbers of length *n*. Your task is to find such subsequence that its sum is odd and maximum among all such subsequences. It's guaranteed that given sequence contains subsequence with odd sum. Subsequence is a sequence that can be derived from another sequen...
{"inputs": ["4\n-2 2 -3 1", "3\n2 -5 -3", "1\n1", "1\n-1", "15\n-6004 4882 9052 413 6056 4306 9946 -4616 -6135 906 -1718 5252 -2866 9061 4046", "2\n-5439 -6705", "2\n2850 6843", "2\n144 9001", "10\n7535 -819 2389 4933 5495 4887 -5181 -9355 7955 5757", "10\n-9169 -1574 3580 -8579 -7177 -3216 7490 3470 3465 -1197", "10\n...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
102
codeforces
c6729c66bbbfd7bb2760347f9870b5b0
Sum of Remainders
Calculate the value of the sum: *n* mod 1 + *n* mod 2 + *n* mod 3 + ... + *n* mod *m*. As the result can be very large, you should print the value modulo 109<=+<=7 (the remainder when divided by 109<=+<=7). The modulo operator *a* mod *b* stands for the remainder after dividing *a* by *b*. For example 10 mod 3 = 1. Th...
{"inputs": ["3 4", "4 4", "1 1", "20000000 10000000", "10000000000000 10000000000000", "1 10000000000000", "10000000000000 1", "100 100", "1000 1000", "500 1000", "1010 435", "997167959139 7344481199252", "7244641009859 6300054748096", "3483524125987 5259923264237", "9726702209411 4215496813081", "5965585325539 3175365...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
4
codeforces
c6cb6358e37594008f8beb2f16fd86b0
Kindergarten
In a kindergarten, the children are being divided into groups. The teacher put the children in a line and associated each child with his or her integer charisma value. Each child should go to exactly one group. Each group should be a nonempty segment of consecutive children of a line. A group's sociability is the maxim...
{"inputs": ["5\n1 2 3 1 2", "3\n3 3 3", "1\n0", "2\n-1000000000 1000000000", "4\n1 4 2 3", "4\n23 5 7 1", "4\n23 7 5 1", "8\n23 2 7 5 15 8 4 10", "8\n4 5 3 6 2 7 1 8"], "outputs": ["3", "0", "0", "2000000000", "4", "24", "22", "37", "16"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
4
codeforces
c6e9fbfb051ff01b6a80e52bde08d396
LCM Challenge
Some days ago, I learned the concept of LCM (least common multiple). I've played with it for several times and I want to make a big number with it. But I also don't want to use many numbers, so I'll choose three positive integers (they don't have to be distinct) which are not greater than *n*. Can you help me to find ...
{"inputs": ["9", "7", "1", "5", "6", "33", "21", "2", "41", "29", "117", "149", "733", "925", "509", "829", "117", "605", "245", "925", "213", "53", "341", "21", "605", "149", "733", "117", "53", "245", "829", "924", "508", "700", "636", "20", "604", "796", "732", "412", "700", "244", "828", "508", "796", "636", "924",...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
122
codeforces
c6fc6efb4116f26068ba51942a03faac
Mahmoud and Ehab and the xor
Mahmoud and Ehab are on the third stage of their adventures now. As you know, Dr. Evil likes sets. This time he won't show them any set from his large collection, but will ask them to create a new set to replenish his beautiful collection of sets. Dr. Evil has his favorite evil integer *x*. He asks Mahmoud and Ehab to...
{"inputs": ["5 5", "3 6", "3 0", "1 0", "3 3", "100000 41243", "100000 100000", "32 32", "32 31", "1 1", "2 0", "3 1", "3 2", "3 5", "3 4", "3 10203", "3 10100", "5 0", "5 1", "5 2", "5 3", "5 4", "5 6", "5 7", "5 8", "5 9", "100000 1", "100000 0", "100000 21323", "100000 65536", "100000 65537", "100000 65535", "4 2", ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
9
codeforces
c71255b01a479ab3650e790fad56511a
Fire Again
After a terrifying forest fire in Berland a forest rebirth program was carried out. Due to it *N* rows with *M* trees each were planted and the rows were so neat that one could map it on a system of coordinates so that the *j*-th tree in the *i*-th row would have the coordinates of (*i*,<=*j*). However a terrible thing...
{"inputs": ["3 3\n1\n2 2", "3 3\n1\n1 1", "3 3\n2\n1 1 3 3", "1 1\n1\n1 1", "2 2\n1\n2 2", "2 2\n2\n1 1 2 1", "2 2\n3\n1 2 2 1 1 1", "2 2\n4\n2 1 2 2 1 1 1 2", "10 10\n1\n5 5", "10 10\n2\n7 8 1 9", "10 10\n3\n3 9 6 3 3 5", "10 10\n4\n5 3 4 7 7 5 8 5", "10 10\n5\n2 7 10 6 5 3 9 5 2 9", "10 10\n6\n5 1 4 6 3 9 9 9 5 7 7 2...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
4
codeforces
c73011b7f575e990667e991cae603566
Oath of the Night's Watch
"Night gathers, and now my watch begins. It shall not end until my death. I shall take no wife, hold no lands, father no children. I shall wear no crowns and win no glory. I shall live and die at my post. I am the sword in the darkness. I am the watcher on the walls. I am the shield that guards the realms of men. I ple...
{"inputs": ["2\n1 5", "3\n1 2 5", "4\n1 2 3 4", "8\n7 8 9 4 5 6 1 2", "1\n1", "1\n100", "205\n5 5 3 3 6 2 9 3 8 9 6 6 10 8 1 5 3 3 1 2 9 9 9 3 9 10 3 9 8 3 5 6 6 4 6 9 2 9 10 9 5 6 6 7 4 2 6 3 4 1 10 1 7 2 7 7 3 2 6 5 5 2 9 3 8 8 7 6 6 4 2 2 6 2 3 5 7 2 2 10 1 4 6 9 2 3 7 2 2 7 4 4 9 10 7 5 8 6 5 3 6 10 2 7 5 6 6 8 3 3...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
198
codeforces
c7bebd7fa695c6aa741ee0b47480fe3f
Number Busters
Arthur and Alexander are number busters. Today they've got a competition. Arthur took a group of four integers *a*,<=*b*,<=*w*,<=*x* (0<=≤<=*b*<=&lt;<=*w*,<=0<=&lt;<=*x*<=&lt;<=*w*) and Alexander took integer *с*. Arthur and Alexander use distinct approaches to number bustings. Alexander is just a regular guy. Each s...
{"inputs": ["4 2 3 1 6", "4 2 3 1 7", "1 2 3 2 6", "1 1 2 1 1", "1 0 1000 999 2000000000", "10 1 6 4 20", "10 3 6 5 30", "10 3 5 1 30", "10 32 312 72 1000", "1 102 123 27 2321", "2000000000 159 1000 870 2000000000", "200000000 794 1000 117 2000000000", "20000000 280 1000 25 2000000000", "1999999999 47 1000 527 20000000...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
6
codeforces
c7e27805e59dc67395e03bd861fc9692
Playing with Permutations
Little Petya likes permutations a lot. Recently his mom has presented him permutation *q*1,<=*q*2,<=...,<=*q**n* of length *n*. A permutation *a* of length *n* is a sequence of integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=*n*), all integers there are distinct. There is only one thing Petya likes more than p...
{"inputs": ["4 1\n2 3 4 1\n1 2 3 4", "4 1\n4 3 1 2\n3 4 2 1", "4 3\n4 3 1 2\n3 4 2 1", "4 2\n4 3 1 2\n2 1 4 3", "4 1\n4 3 1 2\n2 1 4 3", "4 3\n4 3 1 2\n2 1 4 3", "4 3\n2 1 4 3\n4 3 1 2", "4 1\n2 1 4 3\n2 1 4 3", "4 2\n2 1 4 3\n2 1 4 3", "4 2\n2 3 4 1\n1 2 3 4", "5 3\n2 1 4 3 5\n2 1 4 3 5", "9 10\n2 3 1 5 6 7 8 9 4\n2 3...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
2
codeforces
c7e518f6e36784b468c9c07c49fe35b5
Different is Good
A wise man told Kerem "Different is good" once, so Kerem wants all things in his life to be different. Kerem recently got a string *s* consisting of lowercase English letters. Since Kerem likes it when things are different, he wants all substrings of his string *s* to be distinct. Substring is a string formed by some...
{"inputs": ["2\naa", "4\nkoko", "5\nmurat", "6\nacbead", "7\ncdaadad", "25\npeoaicnbisdocqofsqdpgobpn", "25\ntcqpchnqskqjacruoaqilgebu", "13\naebaecedabbee", "27\naaaaaaaaaaaaaaaaaaaaaaaaaaa", "10\nbababbdaee", "11\ndbadcdbdbca", "12\nacceaabddaaa", "13\nabddfbfaeecfa", "14\neeceecacdbcbbb", "15\ndcbceaaggabaheb", "16\...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
244
codeforces
c81d5e4a49895d98aa46236e26ffe463
Ladder
You've got an array, consisting of *n* integers *a*1,<=*a*2,<=...,<=*a**n*. Also, you've got *m* queries, the *i*-th query is described by two integers *l**i*,<=*r**i*. Numbers *l**i*,<=*r**i* define a subsegment of the original array, that is, the sequence of numbers *a**l**i*,<=*a**l**i*<=+<=1,<=*a**l**i*<=+<=2,<=......
{"inputs": ["8 6\n1 2 1 3 3 5 2 1\n1 3\n2 3\n2 4\n8 8\n1 4\n5 8", "1 1\n6\n1 1", "2 5\n1 1\n1 2\n2 2\n2 2\n1 2\n1 2", "10 10\n4 7 2 6 4 8 1 2 1 9\n6 10\n1 9\n9 9\n2 8\n9 9\n1 1\n8 8\n4 8\n8 8\n7 7", "7 5\n13 13 16 12 16 3 19\n2 7\n3 4\n7 7\n1 2\n4 7", "13 6\n2 6 1 3 5 2 2 1 6 4 2 5 2\n10 13\n4 10\n4 11\n3 5\n9 13\n3 13...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
5
codeforces
c88414bf76eef58c9a7872fa666c98b0
Little Pigs and Wolves
Once upon a time there were several little pigs and several wolves on a two-dimensional grid of size *n*<=×<=*m*. Each cell in this grid was either empty, containing one little pig, or containing one wolf. A little pig and a wolf are adjacent if the cells that they are located at share a side. The little pigs are afra...
{"inputs": ["2 3\nPPW\nW.P", "3 3\nP.W\n.P.\nW.P", "1 1\nP", "2 6\nWW..WW\n.PPPP.", "6 2\n.W\n.W\n.P\nWP\n.P\nPW", "2 10\nW..WWP.P.P\nW..PP.WWP.", "10 2\nP.\n.W\nPW\n..\nW.\nW.\n..\nP.\nWP\nPP", "3 4\nWPPW\n.P..\nPWW.", "4 3\n.WW\n..P\nP.P\nPWW", "3 10\nWPPP...PP.\n.P...WW..W\n.WWP.PP.PW", "10 3\n...\nPWW\n..P\n..P\nP....
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
8
codeforces
c8b59efdcaa0c4ce3da4b4d5ef8753c8
Death Stars (medium)
The stardate is 1983, and Princess Heidi is getting better at detecting the Death Stars. This time, two Rebel spies have yet again given Heidi two maps with the possible locations of the Death Star. Since she got rid of all double agents last time, she knows that both maps are correct, and indeed show the map of the so...
{"inputs": ["10 5\nsomer\nandom\nnoise\nmayth\neforc\nebewi\nthyou\nhctwo\nagain\nnoise\nsomermayth\nandomeforc\nnoiseebewi\nagainthyou\nnoisehctwo", "1 1\ng\ng"], "outputs": ["4 6", "1 1"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
4
codeforces
c8c6e9cfbda391ccbc4fdded3cf790eb
Laurenty and Shop
A little boy Laurenty has been playing his favourite game Nota for quite a while and is now very hungry. The boy wants to make sausage and cheese sandwiches, but first, he needs to buy a sausage and some cheese. The town where Laurenty lives in is not large. The houses in it are located in two rows, *n* houses in each...
{"inputs": ["4\n1 2 3\n3 2 1\n3 2 2 3", "3\n1 2\n3 3\n2 1 3", "2\n1\n1\n1 1", "2\n1\n1\n2 1", "3\n1 100\n1 1\n100 100 100", "4\n5 6 7\n8 9 10\n1 8 8 1", "4\n1 2 3\n2 2 3\n2 3 4 3", "48\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
78
codeforces
c8ce6e123182a0581d1c615039667841
Reachability from the Capital
There are $n$ cities and $m$ roads in Berland. Each road connects a pair of cities. The roads in Berland are one-way. What is the minimum number of new roads that need to be built to make all the cities reachable from the capital? New roads will also be one-way. The first line of input consists of three integers $n$,...
{"inputs": ["9 9 1\n1 2\n1 3\n2 3\n1 5\n5 6\n6 1\n1 8\n9 8\n7 1", "5 4 5\n1 2\n2 3\n3 4\n4 1", "5000 0 2956", "2 0 2", "2 1 1\n1 2", "2 1 2\n1 2", "2 2 2\n1 2\n2 1", "5000 2 238\n3212 238\n238 3212", "5000 2 3810\n3225 1137\n1137 3225", "100 1 30\n69 81", "500 1 209\n183 107", "1000 1 712\n542 916", "39 40 38\n4 8\n24 ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
15
codeforces
c8d20c0015d8c8ad5f2d84cc1c0da6db
Comments
A rare article in the Internet is posted without a possibility to comment it. On a Polycarp's website each article has comments feed. Each comment on Polycarp's website is a non-empty string consisting of uppercase and lowercase letters of English alphabet. Comments have tree-like structure, that means each comment ex...
{"inputs": ["hello,2,ok,0,bye,0,test,0,one,1,two,2,a,0,b,0", "a,5,A,0,a,0,A,0,a,0,A,0", "A,3,B,2,C,0,D,1,E,0,F,1,G,0,H,1,I,1,J,0,K,1,L,0,M,2,N,0,O,1,P,0", "BA,0", "Tu,1,dU,1,zncD,0", "nwEwA,2,C,1,aG,0,xgv,0", "aa,0", "ab,0,ba,0", "aa,0,ab,1,a,0", "a,0,bb,1,a,1,bb,0", "a,2,b,0,bb,1,a,1,a,0", "bb,0,b,1,a,1,b,1,a,0,b,0", ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
23
codeforces
c95ec8bbce763fd036c37dea65abd276
Paths and Trees
Little girl Susie accidentally found her elder brother's notebook. She has many things to do, more important than solving problems, but she found this problem too interesting, so she wanted to know its solution and decided to ask you about it. So, the problem statement is as follows. Let's assume that we are given a c...
{"inputs": ["3 3\n1 2 1\n2 3 1\n1 3 2\n3", "4 4\n1 2 1\n2 3 1\n3 4 1\n4 1 2\n4", "4 5\n1 2 1\n1 3 1\n2 4 1\n3 4 1\n2 3 10\n1", "6 8\n1 2 30\n1 3 20\n2 3 50\n4 2 100\n2 5 40\n3 5 10\n3 6 50\n5 6 60\n4", "1 0\n1", "2 1\n1 2 1000000000\n2"], "outputs": ["2\n1 2 ", "4\n2 3 4 ", "3\n1 2 3 ", "230\n1 4 5 6 7 ", "0", "1000000...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1
codeforces
c9bd2ecc84eee31c97d701505f902d35
Bad Luck Island
The Bad Luck Island is inhabited by three kinds of species: *r* rocks, *s* scissors and *p* papers. At some moments of time two random individuals meet (all pairs of individuals can meet equiprobably), and if they belong to different species, then one individual kills the other one: a rock kills scissors, scissors kill...
{"inputs": ["2 2 2", "2 1 2", "1 1 3", "3 2 1", "100 100 100", "1 100 100", "100 1 100", "100 100 1", "1 100 99", "99 1 100", "100 99 1", "100 1 99", "1 99 100", "99 100 1", "1 1 1", "100 100 2", "100 2 100", "2 100 100", "3 3 3", "44 54 32", "100 90 5", "90 5 100", "5 100 90", "100 5 90", "5 90 100", "90 100 5", "4 4 ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
14
codeforces
c9c7b9f7d69ec1a2adb6957425033f52
Maximum in Table
An *n*<=×<=*n* table *a* is defined as follows: - The first row and the first column contain ones, that is: *a**i*,<=1<==<=*a*1,<=*i*<==<=1 for all *i*<==<=1,<=2,<=...,<=*n*. - Each of the remaining numbers in the table is equal to the sum of the number above it and the number to the left of it. In other words, the ...
{"inputs": ["1", "5", "2", "3", "4", "6", "7", "9", "10", "8"], "outputs": ["1", "70", "2", "6", "20", "252", "924", "12870", "48620", "3432"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
869
codeforces
c9db3ceceb2ff1f67aefc2459bf97dc9
Wallpaper
Having bought his own apartment, Boris decided to paper the walls in every room. Boris's flat has *n* rooms, each of which has the form of a rectangular parallelepiped. For every room we known its length, width and height of the walls in meters (different rooms can have different dimensions, including height). Boris c...
{"inputs": ["1\n5 5 3\n3\n10 1 100\n15 2 320\n3 19 500", "1\n9 10 7\n1\n7 1 3", "1\n6 9 5\n3\n8 5 10\n8 5 2\n6 3 7", "1\n3 3 10\n3\n5 5 1\n9 9 2\n10 1 500", "3\n29 30 29\n30 15 28\n27 30 23\n3\n30 27 21\n11 24 30\n25 20 12", "5\n4 4 1\n3 1 4\n4 1 3\n5 1 1\n1 1 1\n5\n5 3 3\n4 3 4\n5 2 3\n2 1 5\n3 1 3", "10\n57 66 71\n14...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
4
codeforces
ca115b811848bef818685ad440e1ead2
Tufurama
One day Polycarp decided to rewatch his absolute favourite episode of well-known TV series "Tufurama". He was pretty surprised when he got results only for season 7 episode 3 with his search query of "Watch Tufurama season 3 episode 7 online full hd free". This got Polycarp confused — what if he decides to rewatch the ...
{"inputs": ["5\n1 2 3 4 5", "3\n8 12 7", "3\n3 2 1", "5\n2 3 4 5 6", "8\n7 2 6 6 5 1 4 9", "10\n1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000", "1\n1"], "outputs": ["0", "3", "2", "4", "9", "45", "0"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
3
codeforces
ca1dfc506b7bb53a74ad35faa89dd5c1
Taymyr is calling you
Comrade Dujikov is busy choosing artists for Timofey's birthday and is recieving calls from Taymyr from Ilia-alpinist. Ilia-alpinist calls every *n* minutes, i.e. in minutes *n*, 2*n*, 3*n* and so on. Artists come to the comrade every *m* minutes, i.e. in minutes *m*, 2*m*, 3*m* and so on. The day is *z* minutes long,...
{"inputs": ["1 1 10", "1 2 5", "2 3 9", "4 8 9", "7 9 2", "10000 10000 10000", "24 22 9235", "74 8 417", "972 1 203", "550 1 754", "860 1 884", "358 2 809", "33 27 216", "2940 1 9311", "4624 1 1953", "2696 2 7345", "3443 2 6701", "3 613 2275", "1 10000 10000", "10000 1 10000", "1 1 1", "1 1 10000", "34 27 10000", "2 2 ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
473
codeforces
ca2e11a194b5b6dd6e1572ac699a94bb
Maximal GCD
You are given positive integer number *n*. You should create such strictly increasing sequence of *k* positive numbers *a*1,<=*a*2,<=...,<=*a**k*, that their sum is equal to *n* and greatest common divisor is maximal. Greatest common divisor of sequence is maximum of such numbers that every element of sequence is divi...
{"inputs": ["6 3", "8 2", "5 3", "1 1", "1 2", "2 1", "2 10000000000", "5 1", "6 2", "24 2", "24 3", "24 4", "24 5", "479001600 2", "479001600 3", "479001600 4", "479001600 5", "479001600 6", "3000000021 1", "3000000021 2", "3000000021 3", "3000000021 4", "3000000021 50000", "3000000021 100000", "10000000000 100", "100...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
70
codeforces
ca337d70fd33ab768399ea1ce6e1e0cd
T-primes
We know that prime numbers are positive integers that have exactly two distinct positive divisors. Similarly, we'll call a positive integer *t* Т-prime, if *t* has exactly three distinct positive divisors. You are given an array of *n* positive integers. For each of them determine whether it is Т-prime or not. The fir...
{"inputs": ["3\n4 5 6", "2\n48 49", "10\n10 9 8 7 6 5 4 3 2 1", "1\n36", "1\n999966000289", "1\n999993399999", "9\n111 121 131 111 121 131 111 121 131", "1\n1", "1\n10", "1\n976197352729", "1\n1000000000000", "1\n9", "6\n549755813888 847288609443 762939453125 678223072849 285311670611 137858491849", "3\n223092870 64696...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
61
codeforces
ca3d6467bdb990da04d4d92e4273bb4d
Room Leader
Let us remind you part of the rules of Codeforces. The given rules slightly simplified, use the problem statement as a formal document. In the beginning of the round the contestants are divided into rooms. Each room contains exactly *n* participants. During the contest the participants are suggested to solve five prob...
{"inputs": ["5\nPetr 3 1 490 920 1000 1200 0\ntourist 2 0 490 950 1100 1400 0\nEgor 7 0 480 900 950 0 1000\nc00lH4x0R 0 10 150 0 0 0 0\nsome_participant 2 1 450 720 900 0 0", "1\nA 0 0 200 0 0 0 0", "2\n12345678901234567890 1 0 200 0 0 0 0\n_ 1 0 201 0 0 0 0", "5\nAb 0 0 481 900 1200 1600 2000\nCd 0 0 480 899 1200 1600...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
86
codeforces
ca4164560911dd7263a284d68b508ad5
Writing Code
Programmers working on a large project have just received a task to write exactly *m* lines of code. There are *n* programmers working on a project, the *i*-th of them makes exactly *a**i* bugs in every line of code that he writes. Let's call a sequence of non-negative integers *v*1,<=*v*2,<=...,<=*v**n* a plan, if *...
{"inputs": ["3 3 3 100\n1 1 1", "3 6 5 1000000007\n1 2 3", "3 5 6 11\n1 2 1", "2 3 3 1000\n1 2", "3 10 10 150691913\n8 7 10", "100 500 500 895583345\n20 39 5 5 41 47 36 33 34 22 21 33 7 4 15 35 16 37 39 46 27 4 12 35 43 26 23 40 16 50 27 7 49 28 17 28 16 22 18 12 25 34 28 24 10 21 38 10 40 50 35 18 23 38 10 42 22 19 24...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
16
codeforces
ca67f81524362b2d19d014c461c2397c
As Fast As Possible
On vacations *n* pupils decided to go on excursion and gather all together. They need to overcome the path with the length *l* meters. Each of the pupils will go with the speed equal to *v*1. To get to the excursion quickly, it was decided to rent a bus, which has seats for *k* people (it means that it can't fit more t...
{"inputs": ["5 10 1 2 5", "3 6 1 2 1", "39 252 51 98 26", "59 96 75 98 9", "87 237 3 21 40", "11 81 31 90 1", "39 221 55 94 1", "59 770 86 94 2", "10000 1000000000 1 2 1", "10000 1 999999999 1000000000 1", "9102 808807765 95894 96529 2021", "87 422 7 90 3", "15 563 38 51 5", "39 407 62 63 2", "18 518 99 100 4", "8367 5...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
16
codeforces
ca82c102c0674d5c724b69c7a9077362
Dima and Salad
Dima, Inna and Seryozha have gathered in a room. That's right, someone's got to go. To cheer Seryozha up and inspire him to have a walk, Inna decided to cook something. Dima and Seryozha have *n* fruits in the fridge. Each fruit has two parameters: the taste and the number of calories. Inna decided to make a fruit sa...
{"inputs": ["3 2\n10 8 1\n2 7 1", "5 3\n4 4 4 4 4\n2 2 2 2 2", "1 1\n1\n1", "1 1\n1\n2", "2 1\n75 65\n16 60", "21 8\n50 39 28 27 58 46 95 46 50 8 28 94 61 58 57 7 1 38 9 34 12\n94 1 77 1 17 40 99 31 26 1 1 1 15 7 6 1 85 3 32 65 78", "16 2\n60 5 39 38 43 10 99 2 88 24 2 73 21 57 60 69\n59 92 96 9 1 15 4 42 23 7 100 10 9...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
11
codeforces
ca8f6ab2803cb58d95f89fdce4108ac1
Anniversary
There are less than 60 years left till the 900-th birthday anniversary of a famous Italian mathematician Leonardo Fibonacci. Of course, such important anniversary needs much preparations. Dima is sure that it'll be great to learn to solve the following problem by the Big Day: You're given a set *A*, consisting of numb...
{"inputs": ["10 1 8 2", "10 1 8 3", "10 1 20 2", "4 1 10 2", "1000000000 999000000000 1000000000000 1000000001", "643354696 8 9 2", "829051283 4 9 2", "549070627 2 6 2", "275299363 7 8 2", "232100782 7 9 2", "466253512 1 10 2", "828885826 8 10 2", "572252279 9 10 2", "888775378 3 6 2", "524357331 2 4 3", "467730377 5 8...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
2
codeforces
caa61827937e47f0ebc44c0a38d8d796
More Cowbell
Kevin Sun wants to move his precious collection of *n* cowbells from Naperthrill to Exeter, where there is actually grass instead of corn. Before moving, he must pack his cowbells into *k* boxes of a fixed size. In order to keep his collection safe during transportation, he won't place more than two cowbells into a sin...
{"inputs": ["2 1\n2 5", "4 3\n2 3 5 9", "3 2\n3 5 7", "20 11\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "10 10\n3 15 31 61 63 63 68 94 98 100", "100 97\n340 402 415 466 559 565 649 689 727 771 774 776 789 795 973 1088 1212 1293 1429 1514 1587 1599 1929 1997 2278 2529 2656 2677 2839 2894 2951 3079 3237 3250 3556 3568 35...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
117
codeforces
caabb5fbf0ee08c9833cf9b20aa2cdd4
Journey
There are *n* cities and *n*<=-<=1 roads in the Seven Kingdoms, each road connects two cities and we can reach any city from any other by the roads. Theon and Yara Greyjoy are on a horse in the first city, they are starting traveling through the roads. But the weather is foggy, so they can’t see where the horse brings...
{"inputs": ["4\n1 2\n1 3\n2 4", "5\n1 2\n1 3\n3 4\n2 5", "70\n1 25\n57 1\n18 1\n65 1\n38 1\n1 41\n1 5\n1 69\n1 3\n31 1\n1 8\n1 9\n53 1\n70 1\n45 1\n1 24\n1 42\n1 30\n1 12\n1 37\n64 1\n1 28\n1 58\n1 22\n11 1\n1 4\n1 27\n1 16\n1 21\n54 1\n1 51\n1 43\n29 1\n56 1\n1 39\n32 1\n1 15\n1 17\n1 19\n1 40\n36 1\n48 1\n63 1\n1 7\n...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
68
codeforces
caadddf957eac691420c3d53c94444e8
none
In the year of $30XX$ participants of some world programming championship live in a single large hotel. The hotel has $n$ floors. Each floor has $m$ sections with a single corridor connecting all of them. The sections are enumerated from $1$ to $m$ along the corridor, and all sections with equal numbers on different fl...
{"inputs": ["5 6 1 1 3\n2\n5\n3\n1 1 5 6\n1 3 5 4\n3 3 5 3", "2 2 0 1 1\n\n1\n1\n1 2 2 2", "4 4 1 0 1\n4\n\n5\n1 1 2 2\n1 3 2 2\n3 3 4 3\n3 2 2 2\n1 2 2 3", "10 10 1 8 4\n10\n2 3 4 5 6 7 8 9\n10\n1 1 3 1\n2 1 7 1\n1 1 9 1\n7 1 4 1\n10 1 7 1\n2 1 7 1\n3 1 2 1\n5 1 2 1\n10 1 5 1\n6 1 9 1", "2 5 1 0 1\n2\n\n1\n1 4 1 5", "...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
4
codeforces
cab62735c2bdf05556c35b9dc9b289cd
Robot's Task
Robot Doc is located in the hall, with *n* computers stand in a line, numbered from left to right from 1 to *n*. Each computer contains exactly one piece of information, each of which Doc wants to get eventually. The computers are equipped with a security system, so to crack the *i*-th of them, the robot needs to colle...
{"inputs": ["3\n0 2 0", "5\n4 2 3 0 1", "7\n0 3 1 0 5 2 6", "1\n0", "2\n0 1", "10\n0 0 0 0 0 0 0 0 0 0", "3\n0 2 1", "10\n7 1 9 3 5 8 6 0 2 4", "10\n1 3 5 7 9 8 6 4 2 0", "10\n5 0 0 1 3 2 2 2 5 7", "10\n8 6 5 3 9 7 1 4 2 0", "10\n1 2 4 5 0 1 3 7 1 4", "10\n3 4 8 9 5 1 2 0 6 7", "10\n2 2 0 0 6 2 9 0 2 0", "10\n1 7 5 3 2...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
128
codeforces
cae5a1f13eb5f93ac2ee925307fd5622
Cheaterius's Problem
Cheaterius is a famous in all the Berland astrologist, magician and wizard, and he also is a liar and a cheater. One of his latest inventions is Cheaterius' amulets! They bring luck and wealth, but are rather expensive. Cheaterius makes them himself. The technology of their making is kept secret. But we know that throu...
{"inputs": ["4\n31\n23\n**\n31\n23\n**\n13\n32\n**\n32\n13", "4\n51\n26\n**\n54\n35\n**\n25\n61\n**\n45\n53", "4\n56\n61\n**\n31\n31\n**\n33\n11\n**\n11\n33", "4\n36\n44\n**\n32\n46\n**\n66\n41\n**\n64\n34", "3\n63\n63\n**\n66\n33\n**\n36\n36", "3\n11\n54\n**\n42\n63\n**\n42\n63", "3\n14\n54\n**\n45\n41\n**\n12\n22", "...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
38
codeforces
cb03cf99183747b6f7f40626d1e6f888
Binary String Constructing
You are given three integers $a$, $b$ and $x$. Your task is to construct a binary string $s$ of length $n = a + b$ such that there are exactly $a$ zeroes, exactly $b$ ones and exactly $x$ indices $i$ (where $1 \le i &lt; n$) such that $s_i \ne s_{i + 1}$. It is guaranteed that the answer always exists. For example, fo...
{"inputs": ["2 2 1", "3 3 3", "5 3 6", "100 1 2", "100 1 1", "1 100 1", "1 100 2", "7 8 7", "100 100 199", "50 47 18", "2 3 3", "100 100 100", "2 2 2", "3 4 6", "1 1 1", "5 6 2", "5 4 2", "2 3 4", "3 3 2", "100 99 100", "3 2 1", "12 74 22", "6 84 12", "3 2 4", "66 11 22", "83 83 83", "9 89 18", "2 1 2", "52 12 17", "55...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
68
codeforces
cb102d5bedfb81d7278cc148c8fbc106
none
You are given an infinite checkered field. You should get from a square (*x*1; *y*1) to a square (*x*2; *y*2). Using the shortest path is not necessary. You can move on the field squares in four directions. That is, when you are positioned in any square, you can move to any other side-neighboring one. A square (*x*; ...
{"inputs": ["2 2 1 0 0 1", "2 2 10 11 0 1", "2 4 3 -1 3 7", "2 2 9 10 -10 -11", "3 2 -11 -10 10 11", "3 2 11 -12 -12 11", "3 3 12 11 -12 -11", "2 3 -12 13 13 -12", "3 4 -8 5 6 -3", "2 3 2 -1 -10 -1", "4 4 3 2 10 -1", "3 2 -8 -9 -14 -1", "4 4 0 -3 11 -4", "5 3 6 3 3 12", "3 5 -4 -7 5 0", "3 5 -20 19 21 16", "5 6 23 -10 ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
10
codeforces
cb10bc64a38e5cbbb28229c038a03616
Robin Hood
We all know the impressive story of Robin Hood. Robin Hood uses his archery skills and his wits to steal the money from rich, and return it to the poor. There are *n* citizens in Kekoland, each person has *c**i* coins. Each day, Robin Hood will take exactly 1 coin from the richest person in the city and he will give i...
{"inputs": ["4 1\n1 1 4 2", "3 1\n2 2 2", "10 20\n6 4 7 10 4 5 5 3 7 10", "30 7\n3 3 2 2 2 2 3 4 4 5 2 1 1 5 5 3 4 3 2 1 3 4 3 2 2 5 2 5 1 2", "2 0\n182 2", "123 54564\n38 44 41 42 59 3 95 15 45 32 44 69 35 83 94 57 65 85 64 47 24 20 34 86 26 91 98 12 36 96 80 4 70 40 95 38 70 22 58 50 34 84 80 45 14 60 61 43 11 56 19 ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
3
codeforces
cb10e3687854c6f485432e7332948d67
New Year and Hurry
Limak is going to participate in a contest on the last day of the 2016. The contest will start at 20:00 and will last four hours, exactly until midnight. There will be *n* problems, sorted by difficulty, i.e. problem 1 is the easiest and problem *n* is the hardest. Limak knows it will take him 5·*i* minutes to solve th...
{"inputs": ["3 222", "4 190", "7 1", "10 135", "10 136", "1 1", "1 240", "10 1", "10 240", "9 240", "9 1", "9 235", "9 236", "5 225", "5 226", "4 210", "4 211", "4 191", "10 165", "10 166", "8 100", "8 101", "8 60", "8 61", "10 15", "10 16", "4 100", "4 101", "7 167", "10 164", "9 170", "8 160", "1 100", "8 123", "2 99...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
765
codeforces
cb263938720825c045f25d273e28aa47
Pythagorean Triples
Katya studies in a fifth grade. Recently her class studied right triangles and the Pythagorean theorem. It appeared, that there are triples of positive integers such that you can construct a right triangle with segments of lengths corresponding to triple. Such triples are called Pythagorean triples. For example, tripl...
{"inputs": ["3", "6", "1", "17", "67", "10", "14", "22", "23", "246", "902", "1000000000", "1998", "2222222", "2222226", "1111110", "9999998", "1024", "8388608", "4", "8", "16", "492", "493824", "493804", "493800", "2048", "8388612", "44", "444", "4444", "44444", "444444", "4444444", "100000000", "2", "3", "5", "7", "9...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
35
codeforces
cb29bcdc75039540bb7686e4763a4ad0
A Twisty Movement
A dragon symbolizes wisdom, power and wealth. On Lunar New Year's Day, people model a dragon with bamboo strips and clothes, raise them with rods, and hold the rods high and low to resemble a flying dragon. A performer holding the rod low is represented by a 1, while one holding it high is represented by a 2. Thus, th...
{"inputs": ["4\n1 2 1 2", "10\n1 1 2 2 2 1 1 2 2 1", "200\n2 1 1 2 1 2 2 2 2 2 1 2 2 1 1 2 2 1 1 1 2 1 1 2 2 2 2 2 1 1 2 1 2 1 1 2 1 1 1 1 2 1 2 2 1 2 1 1 1 2 1 1 1 2 2 2 1 1 1 1 2 2 2 1 2 2 2 1 2 2 2 1 2 1 2 1 2 1 1 1 1 2 2 2 1 1 2 1 2 1 2 1 2 2 1 1 1 2 2 2 2 1 2 2 2 1 1 1 1 2 1 1 1 2 2 1 2 1 2 2 2 1 2 1 2 1 2 1 2 2 2...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
33
codeforces
cb38fa4528d2503a145a641662196af3
Dancing Lessons
There are *n* people taking dancing lessons. Every person is characterized by his/her dancing skill *a**i*. At the beginning of the lesson they line up from left to right. While there is at least one couple of a boy and a girl in the line, the following process is repeated: the boy and girl who stand next to each other...
{"inputs": ["4\nBGBG\n4 2 4 3", "4\nBBGG\n4 6 1 5", "4\nBGBB\n1 1 2 3", "1\nB\n490297", "2\nBB\n2518190 6313112", "3\nBBB\n3146681 8599398 1571560", "10\nGBBBBGBBGG\n9448959 6234076 8008159 4440374 4736443 255932 6568554 4544108 54187 1105310", "10\nBGGBBGBGBG\n9892816 3514007 5425956 5241945 9171176 3351177 2772494 28...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
10
codeforces
cb8618f8fcb1feb01437682b6e177e54
Delivery Bears
Niwel is a little golden bear. As everyone knows, bears live in forests, but Niwel got tired of seeing all the trees so he decided to move to the city. In the city, Niwel took on a job managing bears to deliver goods. The city that he lives in can be represented as a directed graph with *n* nodes and *m* edges. Each e...
{"inputs": ["4 4 3\n1 2 2\n2 4 1\n1 3 1\n3 4 2", "5 11 23\n1 2 3\n2 3 4\n3 4 5\n4 5 6\n1 3 4\n2 4 5\n3 5 6\n1 4 2\n2 5 3\n1 5 2\n3 2 30", "10 16 63\n1 2 1\n2 10 1\n1 3 1\n3 10 1\n1 4 1\n4 10 1\n1 5 1\n5 10 1\n1 6 1\n6 10 1\n1 7 1\n7 10 1\n1 8 1\n8 10 1\n1 9 1\n9 10 1", "2 1 3\n1 2 301", "2 2 1\n1 2 48\n2 1 39", "5 9 5\...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
2
codeforces
cb9186b9a4e23f221c547dc20fa1cbd3
Heap Operations
Petya has recently learned data structure named "Binary heap". The heap he is now operating with allows the following operations: - put the given number into the heap; - get the value of the minimum element in the heap; - extract the minimum element from the heap; Thus, at any moment of time the heap contains se...
{"inputs": ["2\ninsert 3\ngetMin 4", "4\ninsert 1\ninsert 1\nremoveMin\ngetMin 2", "1\ninsert 1", "1\ngetMin 31", "1\nremoveMin", "2\ninsert 2\ngetMin 2", "2\ninsert 31\nremoveMin", "2\ngetMin 31\nremoveMin", "2\nremoveMin\ngetMin 31", "8\ninsert 219147240\nremoveMin\ngetMin 923854124\nremoveMin\ngetMin -876779400\nrem...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
12
codeforces
cbb676850d743a009c1cd41772a6d438
Masha and Bears
A family consisting of father bear, mother bear and son bear owns three cars. Father bear can climb into the largest car and he likes it. Also, mother bear can climb into the middle car and she likes it. Moreover, son bear can climb into the smallest car and he likes it. It's known that the largest car is strictly larg...
{"inputs": ["50 30 10 10", "100 50 10 21", "100 50 19 10", "99 50 25 49", "3 2 1 1", "100 99 98 100", "100 40 30 40", "100 50 19 25", "100 50 19 30", "49 48 25 49", "48 47 23 46", "37 23 16 20", "98 2 1 1", "99 22 13 14", "97 95 3 2", "27 3 2 3", "13 7 6 2", "19 17 11 6", "15 6 4 5", "21 3 1 3", "100 99 98 97", "99 32 ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
92
codeforces
cbc0daf7ec2b8a32eed497f9d63ecf29
Stepan's Series
Well, the series which Stepan watched for a very long time, ended. In total, the series had *n* episodes. For each of them, Stepan remembers either that he definitely has watched it, or that he definitely hasn't watched it, or he is unsure, has he watched this episode or not. Stepan's dissatisfaction is the maximum n...
{"inputs": ["5 2\nNYNNY", "6 1\n????NN", "100 8\nNYNNY?YNNNNNN?NNNNNYNY?YYNYNN?NNNY??NNYNYNNNYNNNYNNNNNNNNY?NNNYNYN?NNNY?YY?NNYNN?NNNYNNYNNYN?NNYNYNN", "10 1\nNY???NY?Y?", "20 7\nN?N??NNN?NNN?Y???Y??", "30 1\nNYYYNYYY?Y?YY?YYYYYYYYYYYYYNYY", "40 14\nNNNNNNNNNNNNNNNNNYNNNNYNNYNNNNNNYNNNNNNN", "51 1\nYYYNYNYNNYYNNY?YNYYY...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
7
codeforces
cbc8bc5adddd9ff53f82afb50a6c38e8
Heidi and Library (easy)
Your search for Heidi is over – you finally found her at a library, dressed up as a human. In fact, she has spent so much time there that she now runs the place! Her job is to buy books and keep them at the library so that people can borrow and read them. There are *n* different books, numbered 1 through *n*. We will ...
{"inputs": ["4 80\n1 2 2 1", "4 1\n1 2 2 1", "4 2\n1 2 3 1", "11 1\n1 2 3 5 1 10 10 1 1 3 5", "5 2\n1 2 3 1 2", "4 2\n1 2 3 2", "1 1\n1", "80 4\n9 9 2 6 3 10 2 5 4 9 6 7 5 5 3 8 5 3 2 10 7 8 5 3 4 9 4 3 9 5 2 10 8 4 7 3 8 3 5 2 3 7 8 4 2 4 4 7 2 2 5 7 5 8 10 10 5 1 1 3 5 2 10 8 7 9 7 4 8 3 2 8 7 9 10 9 7 1 5 5", "80 4\...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
2
codeforces
cbd3bd36a78afd98ce39b978953fe69c
Posterized
Professor Ibrahim has prepared the final homework for his algorithm’s class. He asked his students to implement the Posterization Image Filter. Their algorithm will be tested on an array of integers, where the $i$-th integer represents the color of the $i$-th pixel in the image. The image is in black and white, theref...
{"inputs": ["4 3\n2 14 3 4", "5 2\n0 2 1 255 254", "10 3\n112 184 161 156 118 231 191 128 91 229", "9 3\n174 149 118 124 166 146 219 233 107", "8 4\n180 195 13 195 61 24 132 160", "1 4\n51", "2 4\n218 213", "3 3\n212 167 3", "100 7\n39 242 238 155 95 30 129 132 72 59 22 61 133 113 99 81 253 204 160 109 92 187 11 227 14...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
22
codeforces
cbd781d42f2b14ec31bd058e858ae936
Help Shrek and Donkey 2
Having learned (not without some help from the Codeforces participants) to play the card game from the previous round optimally, Shrek and Donkey (as you may remember, they too live now in the Kingdom of Far Far Away) have decided to quit the boring card games and play with toy soldiers. The rules of the game are as f...
{"inputs": ["2 3 1\nR-G\nRG-", "3 3 2\nG-R\nR-G\nG-R", "2 3 1\n-R-\n-G-", "2 5 2\n-G-R-\n-R-G-", "3 3 1\nG-R\nR-G\nG-R", "2 5 1\n-G-R-\n-R-G-", "2 2 1\nGG\n-R", "2 2 2\nR-\nGG", "3 2 1\nRR\n--\nG-", "3 2 2\n--\n-G\nRR", "2 2 2\nRR\nGG", "2 1 1\nG\nR", "1 1 1\n-", "3 5 2\n-R--G\nG---R\n-R-G-", "3 5 1\n-R--G\nG---R\n-R-G...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1
codeforces
cbe46e8904a05d3d4188f09dd4ace78c
Fox and Card Game
Fox Ciel is playing a card game with her friend Fox Jiro. There are *n* piles of cards on the table. And there is a positive integer on each card. The players take turns and Ciel takes the first turn. In Ciel's turn she takes a card from the top of any non-empty pile, and in Jiro's turn he takes a card from the bottom...
{"inputs": ["2\n1 100\n2 1 10", "1\n9 2 8 6 5 9 4 7 1 3", "3\n3 1 3 2\n3 5 4 6\n2 8 7", "3\n3 1000 1000 1000\n6 1000 1000 1000 1000 1000 1000\n5 1000 1000 1000 1000 1000", "1\n1 1", "5\n1 3\n1 2\n1 8\n1 1\n1 4", "3\n5 1 2 3 4 5\n4 1 2 3 4\n8 1 2 3 4 5 6 7 8", "5\n5 1 1 1 1 1\n4 1 1 1 1\n3 1 1 1\n2 1 1\n1 1", "6\n2 1 1\...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
19
codeforces
cbee248948dd04736c1c417697f70d86
Young Table
You've got table *a*, consisting of *n* rows, numbered from 1 to *n*. The *i*-th line of table *a* contains *c**i* cells, at that for all *i* (1<=&lt;<=*i*<=≤<=*n*) holds *c**i*<=≤<=*c**i*<=-<=1. Let's denote *s* as the total number of cells of table *a*, that is, . We know that each cell of the table contains a sing...
{"inputs": ["3\n3 2 1\n4 3 5\n6 1\n2", "1\n4\n4 3 2 1", "5\n4 4 3 3 1\n14 13 4 15\n11 1 2 5\n7 6 10\n8 9 3\n12", "2\n8 6\n1 2 3 13 10 4 11 7\n9 12 8 5 14 6", "6\n10 9 7 6 4 3\n18 20 29 19 5 28 31 30 32 15\n38 33 11 8 39 2 6 9 3\n13 37 27 24 26 1 17\n36 10 35 21 7 16\n22 23 4 12\n34 25 14", "8\n2 2 2 2 1 1 1 1\n10 9\n11...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
4
codeforces
cbf2401bef0f45c21901b34f0c5649fa
Kalila and Dimna in the Logging Industry
Kalila and Dimna are two jackals living in a huge jungle. One day they decided to join a logging factory in order to make money. The manager of logging factory wants them to go to the jungle and cut *n* trees with heights *a*1,<=*a*2,<=...,<=*a**n*. They bought a chain saw from a shop. Each time they use the chain sa...
{"inputs": ["5\n1 2 3 4 5\n5 4 3 2 0", "6\n1 2 3 10 20 30\n6 5 4 3 2 0"], "outputs": ["25", "138"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
16
codeforces
cbf4ad8bd05b36fab2101dcda7d9b6c9
Iahub and Permutations
Iahub is so happy about inventing bubble sort graphs that he's staying all day long at the office and writing permutations. Iahubina is angry that she is no more important for Iahub. When Iahub goes away, Iahubina comes to his office and sabotage his research work. The girl finds an important permutation for the resea...
{"inputs": ["5\n-1 -1 4 3 -1", "8\n2 4 5 3 -1 8 -1 6", "7\n-1 -1 4 -1 7 1 6", "6\n-1 -1 -1 -1 -1 -1", "2\n-1 -1", "10\n4 10 -1 1 6 8 9 2 -1 -1", "20\n-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1"], "outputs": ["2", "1", "4", "265", "1", "4", "927799753"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
6
codeforces
cc22c937dd57137fe8ae380fccc12c66
Dynasty Puzzles
The ancient Berlanders believed that the longer the name, the more important its bearer is. Thus, Berland kings were famous for their long names. But long names are somewhat inconvenient, so the Berlanders started to abbreviate the names of their kings. They called every king by the first letters of its name. Thus, the...
{"inputs": ["3\nabc\nca\ncba", "4\nvvp\nvvp\ndam\nvvp", "3\nab\nc\ndef", "5\nab\nbc\ncd\nde\nffffffffff", "5\ncab\nbbc\ncaa\nccc\naca", "10\nabdcced\nbdacdac\necb\ndc\neaeeebdd\nadcdbadcac\neb\naadecccde\nedbaeacad\naccd", "50\nagecd\ncghafi\nfiide\niecc\njbdcfjhgd\ndiee\nhfeg\nehc\ngfijgjh\ngacaifebg\ndicbbddc\nhjgcia...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
10
codeforces
cc2ed94d2164907de60a5c20c496a2e5
Car Repair Shop
Polycarp starts his own business. Tomorrow will be the first working day of his car repair shop. For now the car repair shop is very small and only one car can be repaired at a given time. Polycarp is good at marketing, so he has already collected *n* requests from clients. The requests are numbered from 1 to *n* in o...
{"inputs": ["3\n9 2\n7 3\n2 4", "4\n1000000000 1000000\n1000000000 1000000\n100000000 1000000\n1000000000 1000000", "1\n1 1", "1\n1000000000 1", "1\n1000000000 5000000", "5\n6 2\n10 1\n10 2\n9 2\n5 1", "10\n1 3\n77 8\n46 5\n83 4\n61 7\n8 4\n54 7\n80 7\n33 7\n13 4", "10\n588 12\n560 10\n593 14\n438 15\n761 11\n984 6\n50...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
4
codeforces
cc32fd5210a68b5474019c046d82478b
PolandBall and Forest
PolandBall lives in a forest with his family. There are some trees in the forest. Trees are undirected acyclic graphs with *k* vertices and *k*<=-<=1 edges, where *k* is some integer. Note that one vertex is a valid tree. There is exactly one relative living in each vertex of each tree, they have unique ids from 1 to ...
{"inputs": ["5 3\n1 2\n3 4\n4 5", "1 0", "5 1\n4 5", "10 3\n2 8\n5 9\n6 10", "18 2\n9 17\n1 18", "1 0", "2 1\n1 2", "2 0", "3 1\n2 3", "3 2\n1 2\n2 3", "3 0", "10000 1\n1725 10000", "5 4\n1 3\n1 4\n4 2\n5 2", "4 3\n3 1\n1 2\n2 4", "5 4\n3 2\n2 5\n5 1\n1 4", "5 4\n1 2\n1 3\n1 4\n3 5", "6 5\n1 4\n2 3\n3 4\n4 5\n5 6"], "o...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
77
codeforces
cc3d4bf0993f096240a30911a45cbe0e
Swaps in Permutation
You are given a permutation of the numbers 1,<=2,<=...,<=*n* and *m* pairs of positions (*a**j*,<=*b**j*). At each step you can choose a pair from the given positions and swap the numbers in that positions. What is the lexicographically maximal permutation one can get? Let *p* and *q* be two permutations of the numbe...
{"inputs": ["9 6\n1 2 3 4 5 6 7 8 9\n1 4\n4 7\n2 5\n5 8\n3 6\n6 9", "1 1\n1\n1 1", "2 10\n2 1\n2 1\n1 2\n1 1\n2 1\n1 1\n2 1\n1 1\n1 1\n2 1\n2 1", "3 10\n1 2 3\n2 2\n1 1\n2 2\n3 3\n1 1\n3 3\n3 3\n3 3\n2 2\n1 1", "4 20\n4 2 3 1\n2 2\n1 4\n2 2\n1 1\n3 3\n3 3\n1 4\n3 3\n2 2\n3 3\n4 1\n2 2\n1 4\n3 3\n4 1\n1 1\n3 3\n2 2\n2 2...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
5
codeforces
cc5c29e25f4a62e672d02de221aa504b
Divisiblity of Differences
You are given a multiset of *n* integers. You should select exactly *k* of them in a such way that the difference between any two of them is divisible by *m*, or tell that it is impossible. Numbers can be repeated in the original multiset and in the multiset of selected numbers, but number of occurrences of any number...
{"inputs": ["3 2 3\n1 8 4", "3 3 3\n1 8 4", "4 3 5\n2 7 7 7", "9 9 5\n389149775 833127990 969340400 364457730 48649145 316121525 640054660 924273385 973207825", "15 8 10\n216175135 15241965 611723934 987180005 151601897 403701727 533996295 207637446 875331635 46172555 604086315 350146655 401084142 156540458 982110455",...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
129
codeforces
cc71101bf1a32ac7a83f342726de0a60
Lucky Year
Apart from having lots of holidays throughout the year, residents of Berland also have whole lucky years. Year is considered lucky if it has no more than 1 non-zero digit in its number. So years 100, 40000, 5 are lucky and 12, 3001 and 12345 are not. You are given current year in Berland. Your task is to find how long...
{"inputs": ["4", "201", "4000", "9", "10", "1", "100000000", "900000000", "999999999", "1000000000", "9999999", "100000001", "3660", "21", "900000001", "62911", "11", "940302010", "91", "101", "1090", "987654321", "703450474", "1091", "89", "109", "190", "19", "8", "482", "1", "2", "3", "4", "5", "6", "7", "8", "9", "1...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
282
codeforces
cc9a6194b46b75af2a7ecae3f3b268ef
Tournament
The tournament «Sleepyhead-2010» in the rapid falling asleep has just finished in Berland. *n* best participants from the country have participated in it. The tournament consists of games, each of them is a match between two participants. *n*·(*n*<=-<=1)<=/<=2 games were played during the tournament, and each participa...
{"inputs": ["3\n3 2\n1 2", "4\n2 4\n3 4\n1 2\n1 4\n1 3", "5\n3 5\n2 5\n1 5\n1 4\n4 3\n1 3\n2 3\n4 5\n4 2", "6\n3 4\n3 5\n5 4\n1 2\n5 6\n2 6\n5 2\n3 6\n3 2\n4 6\n2 4\n1 3\n1 5\n1 4", "7\n2 4\n6 1\n6 5\n3 4\n6 3\n2 6\n6 4\n3 7\n7 1\n1 4\n7 4\n7 5\n2 7\n2 3\n5 4\n3 5\n3 1\n5 1\n6 7\n2 1", "8\n4 3\n6 8\n1 5\n8 3\n1 4\n1 7\...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
63
codeforces