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
sequencelengths
1
1
source
stringclasses
14 values
num_solutions
int64
2
1.9M
starter_code
stringlengths
0
1.47k
subset
stringclasses
3 values
8cae00fef4c1eedada77f2a75ddf67f4
Inverse Function
Petya wrote a programme on C++ that calculated a very interesting function *f*(*n*). Petya ran the program with a certain value of *n* and went to the kitchen to have some tea. The history has no records concerning how long the program had been working. By the time Petya returned, it had completed the calculations and had the result. However while Petya was drinking tea, a sly virus managed to destroy the input file so that Petya can't figure out for which value of *n* the program was run. Help Petya, carry out the inverse function! Mostly, the program consists of a function in C++ with the following simplified syntax: - *function* ::= int f(int n) {*operatorSequence*}- *operatorSequence* ::= *operator* | *operator* *operatorSequence*- *operator* ::= return *arithmExpr*; | if (*logicalExpr*) return *arithmExpr*;- *logicalExpr* ::= *arithmExpr*<=&gt;<=*arithmExpr* | *arithmExpr*<=&lt;<=*arithmExpr* | *arithmExpr* == *arithmExpr*- *arithmExpr* ::= *sum*- *sum* ::= *product* | *sum*<=+<=*product* | *sum*<=-<=*product*- *product* ::= *multiplier* | *product*<=*<=*multiplier* | *product*<=/<=*multiplier*- *multiplier* ::= n | *number* | f(*arithmExpr*)- *number* ::= 0|1|2|... |32767 The whitespaces in a *operatorSequence* are optional. Thus, we have a function, in which body there are two kinds of operators. There is the operator "return *arithmExpr*;" that returns the value of the expression as the value of the function, and there is the conditional operator "if (*logicalExpr*) return *arithmExpr*;" that returns the value of the arithmetical expression when and only when the logical expression is true. Guaranteed that no other constructions of C++ language — cycles, assignment operators, nested conditional operators etc, and other variables except the *n* parameter are used in the function. All the constants are integers in the interval [0..32767]. The operators are performed sequentially. After the function has returned a value other operators in the sequence are not performed. Arithmetical expressions are performed taking into consideration the standard priority of the operations. It means that first all the products that are part of the sum are calculated. During the calculation of the products the operations of multiplying and division are performed from the left to the right. Then the summands are summed, and the addition and the subtraction are also performed from the left to the right. Operations "&gt;" (more), "&lt;" (less) and "==" (equals) also have standard meanings. Now you've got to pay close attention! The program is compiled with the help of 15-bit Berland C++ compiler invented by a Berland company BerSoft, that's why arithmetical operations are performed in a non-standard way. Addition, subtraction and multiplication are performed modulo 32768 (if the result of subtraction is negative, then 32768 is added to it until the number belongs to the interval [0..32767]). Division "/" is a usual integer division where the remainder is omitted. Examples of arithmetical operations: Guaranteed that for all values of *n* from 0 to 32767 the given function is performed correctly. That means that: 1. Division by 0 never occures. 2. When performing a function for the value *n*<==<=*N* recursive calls of the function *f* may occur only for the parameter value of 0,<=1,<=...,<=*N*<=-<=1. Consequently, the program never has an infinite recursion. 3. As the result of the sequence of the operators, the function always returns a value. We have to mention that due to all the limitations the value returned by the function *f* is independent from either global variables or the order of performing the calculations of arithmetical expressions as part of the logical one, or from anything else except the value of *n* parameter. That's why the *f* function can be regarded as a function in its mathematical sense, i.e. as a unique correspondence between any value of *n* from the interval [0..32767] and a value of *f*(*n*) from the same interval. Given the value of *f*(*n*), and you should find *n*. If the suitable *n* value is not unique, you should find the maximal one (from the interval [0..32767]). The first line has an integer *f*(*n*) from the interval [0..32767]. The next lines have the description of the function *f*. In the description can be found extra spaces and line breaks (see the examples) which, of course, can’t break key words int, if, return and numbers. The size of input data can’t exceed 100 bytes. Output a single number — the answer to the problem. If there’s no answer, output "-1" (without quotes). Sample Input 17 int f(int n) { if (n &lt; 100) return 17; if (n &gt; 99) return 27; } 13 int f(int n) { if (n == 0) return 0; return f(n - 1) + 1; } 144 int f(int n) { if (n == 0) return 0; if (n == 1) return n; return f(n - 1) + f(n - 2); } Sample Output 99 1324588
{"inputs": ["17\nint f(int n)\n{\nif (n < 100) return 17;\nif (n > 99) return 27;\n}", "13\nint f(int n)\n{\nif (n == 0) return 0;\nreturn f(n - 1) + 1;\n}", "144\nint f(int n)\n{\nif (n == 0) return 0;\nif (n == 1) return n;\nreturn f(n - 1) + f(n - 2);\n}", "32767\nint f(int n)\n{\nreturn n;\n}", "27926\nint f(int n)\n{\nreturn n*n + 5*n/3 + 19 * 1423;\n}", "1\nint f(int n)\n{\nif (n == 0) return 153/12+5;\nreturn 32767/n;\n}", "32\nint f(int n)\n{\nif (n == 0) return 1;\nreturn f(n - 1) * 7;\n}", "1\nint f(int n)\n{\nif (n == 0) return 1;\nreturn f(n - 1) * 7;\n}", "0\nint f(int n)\n{\nif (n < 2) return 1;\nreturn f(n - 1) + f(n - 2);\n}", "32\nint f(int n)\n{\nif (n < 2) return 1;\nreturn f(n - 1) + f(n - 2);\n}", "12351\nint f(int n)\n{\nif (n < 3) return n;\nreturn f(n - 1) * n + f(n - 2) + f(n - 3) / 5;\n}", "0\nint f(int n){if (n < 1) return 0;return f(f(f(f(f(f(f(f(f(f(f(f(f(f(f(f(f(0)))))))))))))))));}", "0\nint f(int n){if (n < 1) return 1;if (n < 2) return 0;return f(f(f(f(f(f(f(f(f(f(n-1))))))))));}", "1\nint f(int n){if (n < 1) return 1;if (n < 2) return 0;return f(f(f(f(f(f(f(f(f(f(n-1))))))))));}", "14\nint f(int n)\n{\nif (n < 1) return 0;\nreturn f(n / 2) + 1;\n}", "12\nint f(int n)\n{\nif (n < 1) return 0;\nreturn f(n / 2) + 1;\n}", "100\nint f(int n){if (n < 3) return 1;return f(n-1)+f(n-2)+f(n-3);}", "7113\nint f(int n)\n{\nif (n < 3) return n;\nreturn f(n - 1) * n + f(n - 2) + f(n - 3) / 5;\n}", "7169\nint f(int n){if (n < 7) return 1; return f(n-1)+f(n-2)+f(n-3)+f(n-4)+f(n-5)-f(n-6)-f(n-7);}", "32657\nint f(int n){if (n < 7) return 1; return f(n-1)+f(n-2)+f(n-3)+f(n-4)+f(n-5)-f(n-6)-f(n-7);}", "5\nint f(int n){if (n < 2) return 1;if (n < 8) return 2;if (n > 8) return 7;if (n > 2) return 5;}", "2\nint f(int n){if (n < 2) return 1;if (n < 8) return 2;if (n > 8) return 7;if (n > 2) return 5;}", "1\nint f(int n){if (n < 2) return 1;if (n < 8) return 2;if (n > 8) return 7;if (n > 2) return 5;}", "7\nint f(int n){if (n < 2) return 1;if (n < 8) return 2;if (n > 8) return 7;if (n > 2) return 5;}", "6\nint f(int n){if (n < 1025) return n*5+12/6-n/3*15-7;return f(n/2)-f(n-7)*f(n-7)-1024;}", "32763\nint f(int n){if (n < 1025) return n*5+12/6-n/3*15-7;return f(n/2)-f(n-7)*f(n-7)-1024;}", "280\nint f(int n){if (n < 1025) return n*5+12/6-n/3*15-7;return f(n/2)-f(n-7)*f(n-7)-1024;}", "1\nint f(int n){return 1;return 2;return 3;return 4;return 5;return 6;return 7;return 8;return 9;}", "2\nint f(int n){return 1;return 2;return 3;return 4;return 5;return 6;return 7;return 8;return 9;}", "3647\nint f(int n){return 1*2*3+2*3*4-3*4*5-4*5*6+5*6*7+n*n*n-n/2/4/5+n+1/2+3*9*6-12+17/7*6+1-1;}", "17463\nint f(int n){return 1*2*3+2*3*4-3*4*5-4*5*6+5*6*7+n*n*n-n/2/4/5+n+1/2+3*9*6-12+17/7*6+1-1;}", "17\nint f(int n){if (n > 1000) return n/n;if (n > 100) return n/2;if (n > 10) return n; return 7;}", "55\nint f(int n)\n{\nif (n < 2) return 0;if (f(n-1) == f(n-2)) return f(n-2)+1;return f(n-1);\n}", "3\nint f(int n)\n{\nif (n > 5) return 8;\nif (n < 3) return 1;\nreturn f(12/n/n)+1;\n}", "2\nint f(int n)\n{\nif (n > 5) return 8;\nif (n < 3) return 1;\nreturn f(12/n/n)+1;\n}", "354\nint f(int n)\n{\nif (n < 4) return 1;\nreturn f(n-1)*f(n-2)*f(n-3)*f(n-4)+n;\n}", "9182\nint f(int n)\n{\nif (n < 4) return 1;\nreturn f(n-1)*f(n-2)*f(n-3)*f(n-4)+n;\n}", "32767\nint f(int n)\n{\nif (n < 5) return 0-1;if (f(n/2)*f(n-1) < 0) return f(n+28);return 10;\n}", "57\nint f(int n)\n{\nif (n/2*2 == n) return 1;\nif (n/2*2 == n-1) return 0;\nreturn 57;\n}", "1\nint f(int n)\n{\nif (n/2*2 == n) return 1;\nif (n/2*2 == n-1) return 0;\nreturn 57;\n}", "15\nint f(int n){if (n > 1) return f(n-2)/f(n-1)+15;if (n == 0) return 0;if (n == 1) return 1;}"], "outputs": ["99", "13", "24588", "32767", "29", "32767", "-1", "28672", "24575", "15959", "26464", "32767", "32767", "32766", "16383", "4095", "-1", "31277", "32258", "32308", "8", "7", "1", "32767", "-1", "1023", "32746", "32767", "-1", "23117", "9167", "17", "111", "-1", "5", "19794", "27142", "4", "-1", "32766", "32767"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1
codeforces
8cd687a88783833ff1c31127372696fe
George and Accommodation
George has recently entered the BSUCP (Berland State University for Cool Programmers). George has a friend Alex who has also entered the university. Now they are moving into a dormitory. George and Alex want to live in the same room. The dormitory has *n* rooms in total. At the moment the *i*-th room has *p**i* people living in it and the room can accommodate *q**i* people in total (*p**i*<=≤<=*q**i*). Your task is to count how many rooms has free place for both George and Alex. The first line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of rooms. The *i*-th of the next *n* lines contains two integers *p**i* and *q**i* (0<=≤<=*p**i*<=≤<=*q**i*<=≤<=100) — the number of people who already live in the *i*-th room and the room's capacity. Print a single integer — the number of rooms where George and Alex can move in. Sample Input 3 1 1 2 2 3 3 3 1 10 0 10 10 10 Sample Output 0 2
{"inputs": ["3\n1 1\n2 2\n3 3", "3\n1 10\n0 10\n10 10", "2\n36 67\n61 69", "3\n21 71\n10 88\n43 62", "3\n1 2\n2 3\n3 4", "10\n0 10\n0 20\n0 30\n0 40\n0 50\n0 60\n0 70\n0 80\n0 90\n0 100", "13\n14 16\n30 31\n45 46\n19 20\n15 17\n66 67\n75 76\n95 97\n29 30\n37 38\n0 2\n36 37\n8 9", "19\n66 67\n97 98\n89 91\n67 69\n67 68\n18 20\n72 74\n28 30\n91 92\n27 28\n75 77\n17 18\n74 75\n28 30\n16 18\n90 92\n9 11\n22 24\n52 54", "15\n55 57\n95 97\n57 59\n34 36\n50 52\n96 98\n39 40\n13 15\n13 14\n74 76\n47 48\n56 58\n24 25\n11 13\n67 68", "17\n68 69\n47 48\n30 31\n52 54\n41 43\n33 35\n38 40\n56 58\n45 46\n92 93\n73 74\n61 63\n65 66\n37 39\n67 68\n77 78\n28 30", "14\n64 66\n43 44\n10 12\n76 77\n11 12\n25 27\n87 88\n62 64\n39 41\n58 60\n10 11\n28 29\n57 58\n12 14", "38\n74 76\n52 54\n78 80\n48 49\n40 41\n64 65\n28 30\n6 8\n49 51\n68 70\n44 45\n57 59\n24 25\n46 48\n49 51\n4 6\n63 64\n76 78\n57 59\n18 20\n63 64\n71 73\n88 90\n21 22\n89 90\n65 66\n89 91\n96 98\n42 44\n1 1\n74 76\n72 74\n39 40\n75 76\n29 30\n48 49\n87 89\n27 28", "100\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0", "26\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2", "68\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2", "7\n0 1\n1 5\n2 4\n3 5\n4 6\n5 6\n6 8", "1\n0 0", "1\n100 100", "44\n0 8\n1 11\n2 19\n3 5\n4 29\n5 45\n6 6\n7 40\n8 19\n9 22\n10 18\n11 26\n12 46\n13 13\n14 27\n15 48\n16 25\n17 20\n18 29\n19 27\n20 45\n21 39\n22 29\n23 39\n24 42\n25 37\n26 52\n27 36\n28 43\n29 35\n30 38\n31 70\n32 47\n33 38\n34 61\n35 71\n36 51\n37 71\n38 59\n39 77\n40 70\n41 80\n42 77\n43 73", "3\n1 3\n2 7\n8 9", "53\n0 1\n1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 8\n8 9\n9 10\n10 11\n11 12\n12 13\n13 14\n14 15\n15 16\n16 17\n17 18\n18 19\n19 20\n20 21\n21 22\n22 23\n23 24\n24 25\n25 26\n26 27\n27 28\n28 29\n29 30\n30 31\n31 32\n32 33\n33 34\n34 35\n35 36\n36 37\n37 38\n38 39\n39 40\n40 41\n41 42\n42 43\n43 44\n44 45\n45 46\n46 47\n47 48\n48 49\n49 50\n50 51\n51 52\n52 53", "55\n0 0\n1 1\n2 2\n3 3\n4 4\n5 5\n6 6\n7 7\n8 8\n9 9\n10 10\n11 11\n12 12\n13 13\n14 14\n15 15\n16 16\n17 17\n18 18\n19 19\n20 20\n21 21\n22 22\n23 23\n24 24\n25 25\n26 26\n27 27\n28 28\n29 29\n30 30\n31 31\n32 32\n33 33\n34 34\n35 35\n36 36\n37 37\n38 38\n39 39\n40 40\n41 41\n42 42\n43 43\n44 44\n45 45\n46 46\n47 47\n48 48\n49 49\n50 50\n51 51\n52 52\n53 53\n54 54", "51\n55 55\n55 55\n55 55\n55 55\n55 55\n55 55\n55 55\n55 55\n55 55\n55 62\n55 55\n55 55\n55 55\n55 55\n55 55\n55 55\n55 55\n55 55\n55 55\n55 55\n55 55\n55 73\n55 55\n55 55\n55 55\n55 55\n55 55\n55 55\n55 55\n55 55\n55 55\n55 82\n55 68\n55 70\n55 63\n55 55\n55 55\n55 55\n55 75\n55 75\n55 55\n55 55\n55 55\n55 55\n55 55\n55 55\n55 73\n55 55\n55 82\n55 99\n55 60", "14\n1 1\n1 1\n1 55\n1 16\n1 1\n1 1\n1 55\n1 62\n1 53\n1 26\n1 1\n1 36\n1 2\n1 3"], "outputs": ["0", "2", "2", "3", "0", "10", "4", "12", "10", "8", "7", "22", "0", "0", "68", "5", "0", "0", "42", "2", "0", "0", "12", "8"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
648
codeforces
8d058a1cf69c59bf09f0190d5dc2e875
Football
One day, at the "Russian Code Cup" event it was decided to play football as an out of competition event. All participants was divided into *n* teams and played several matches, two teams could not play against each other more than once. The appointed Judge was the most experienced member — Pavel. But since he was the wisest of all, he soon got bored of the game and fell asleep. Waking up, he discovered that the tournament is over and the teams want to know the results of all the matches. Pavel didn't want anyone to discover about him sleeping and not keeping an eye on the results, so he decided to recover the results of all games. To do this, he asked all the teams and learned that the real winner was friendship, that is, each team beat the other teams exactly *k* times. Help Pavel come up with chronology of the tournir that meets all the conditions, or otherwise report that there is no such table. The first line contains two integers — *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=1000). In the first line print an integer *m* — number of the played games. The following *m* lines should contain the information about all the matches, one match per line. The *i*-th line should contain two integers *a**i* and *b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*; *a**i*<=≠<=*b**i*). The numbers *a**i* and *b**i* mean, that in the *i*-th match the team with number *a**i* won against the team with number *b**i*. You can assume, that the teams are numbered from 1 to *n*. If a tournir that meets the conditions of the problem does not exist, then print -1. Sample Input 3 1 Sample Output 3 1 2 2 3 3 1
{"inputs": ["3 1", "7 3", "4 1", "5 2", "5 2", "11 6", "11 5", "1 1", "2 1", "3 1", "1 2", "2 2", "3 2", "531 265", "775 388", "648 581", "57 13", "131 65", "609 305", "197 182", "248 54", "137 68", "47 24", "947 868", "205 50", "863 431", "445 223", "786 393", "122 52", "629 314", "571 286", "980 680", "869 239", "999 499", "999 500", "1000 751", "1000 162", "1000 936", "1000 178", "1000 499", "999 499", "1 1", "2 1", "4 2", "6 3", "10 5", "999 2", "1000 490"], "outputs": ["3\n1 2\n2 3\n3 1", "21\n1 2\n1 3\n1 4\n2 3\n2 4\n2 5\n3 4\n3 5\n3 6\n4 5\n4 6\n4 7\n5 6\n5 7\n5 1\n6 7\n6 1\n6 2\n7 1\n7 2\n7 3", "4\n1 2\n2 3\n3 4\n4 1", "10\n1 2\n1 3\n2 3\n2 4\n3 4\n3 5\n4 5\n4 1\n5 1\n5 2", "10\n1 2\n1 3\n2 3\n2 4\n3 4\n3 5\n4 5\n4 1\n5 1\n5 2", "-1", "55\n1 2\n1 3\n1 4\n1 5\n1 6\n2 3\n2 4\n2 5\n2 6\n2 7\n3 4\n3 5\n3 6\n3 7\n3 8\n4 5\n4 6\n4 7\n4 8\n4 9\n5 6\n5 7\n5 8\n5 9\n5 10\n6 7\n6 8\n6 9\n6 10\n6 11\n7 8\n7 9\n7 10\n7 11\n7 1\n8 9\n8 10\n8 11\n8 1\n8 2\n9 10\n9 11\n9 1\n9 2\n9 3\n10 11\n10 1\n10 2\n10 3\n10 4\n11 1\n11 2\n11 3\n11 4\n11 5", "-1", "-1", "3\n1 2\n2 3\n3 1", "-1", "-1", "-1", "140715\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n1 20\n1 21\n1 22\n1 23\n1 24\n1 25\n1 26\n1 27\n1 28\n1 29\n1 30\n1 31\n1 32\n1 33\n1 34\n1 35\n1 36\n1 37\n1 38\n1 39\n1 40\n1 41\n1 42\n1 43\n1 44\n1 45\n1 46\n1 47\n1 48\n1 49\n1 50\n1 51\n1 52\n1 53\n1 54\n1 55\n1 56\n1 57\n1 58\n1 59\n1 60\n1 61\n1 62\n1 63\n1 64\n1 65\n1 66\n1 67\n1 68\n1 69\n1 70\n1 71\n1 72\n1 73\n1 74\n1 75\n1 76\n1 77\n1 78\n1 79\n1 80\n1 81\n1 82\n1 83\n1 84\n1 85\n1 86\n1...", "-1", "-1", "741\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n2 3\n2 4\n2 5\n2 6\n2 7\n2 8\n2 9\n2 10\n2 11\n2 12\n2 13\n2 14\n2 15\n3 4\n3 5\n3 6\n3 7\n3 8\n3 9\n3 10\n3 11\n3 12\n3 13\n3 14\n3 15\n3 16\n4 5\n4 6\n4 7\n4 8\n4 9\n4 10\n4 11\n4 12\n4 13\n4 14\n4 15\n4 16\n4 17\n5 6\n5 7\n5 8\n5 9\n5 10\n5 11\n5 12\n5 13\n5 14\n5 15\n5 16\n5 17\n5 18\n6 7\n6 8\n6 9\n6 10\n6 11\n6 12\n6 13\n6 14\n6 15\n6 16\n6 17\n6 18\n6 19\n7 8\n7 9\n7 10\n7 11\n7 12\n7 13\n7 14\n7 15\n7 16\n7 17\n7 18\n7 19\n7...", "8515\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n1 20\n1 21\n1 22\n1 23\n1 24\n1 25\n1 26\n1 27\n1 28\n1 29\n1 30\n1 31\n1 32\n1 33\n1 34\n1 35\n1 36\n1 37\n1 38\n1 39\n1 40\n1 41\n1 42\n1 43\n1 44\n1 45\n1 46\n1 47\n1 48\n1 49\n1 50\n1 51\n1 52\n1 53\n1 54\n1 55\n1 56\n1 57\n1 58\n1 59\n1 60\n1 61\n1 62\n1 63\n1 64\n1 65\n1 66\n2 3\n2 4\n2 5\n2 6\n2 7\n2 8\n2 9\n2 10\n2 11\n2 12\n2 13\n2 14\n2 15\n2 16\n2 17\n2 18\n2 19\n2 20\n2 21\n2 22\n2 23\n2 24...", "-1", "-1", "13392\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n1 20\n1 21\n1 22\n1 23\n1 24\n1 25\n1 26\n1 27\n1 28\n1 29\n1 30\n1 31\n1 32\n1 33\n1 34\n1 35\n1 36\n1 37\n1 38\n1 39\n1 40\n1 41\n1 42\n1 43\n1 44\n1 45\n1 46\n1 47\n1 48\n1 49\n1 50\n1 51\n1 52\n1 53\n1 54\n1 55\n2 3\n2 4\n2 5\n2 6\n2 7\n2 8\n2 9\n2 10\n2 11\n2 12\n2 13\n2 14\n2 15\n2 16\n2 17\n2 18\n2 19\n2 20\n2 21\n2 22\n2 23\n2 24\n2 25\n2 26\n2 27\n2 28\n2 29\n2 30\n2 31\n2 32\n2 33\n2 34\n2 3...", "9316\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n1 20\n1 21\n1 22\n1 23\n1 24\n1 25\n1 26\n1 27\n1 28\n1 29\n1 30\n1 31\n1 32\n1 33\n1 34\n1 35\n1 36\n1 37\n1 38\n1 39\n1 40\n1 41\n1 42\n1 43\n1 44\n1 45\n1 46\n1 47\n1 48\n1 49\n1 50\n1 51\n1 52\n1 53\n1 54\n1 55\n1 56\n1 57\n1 58\n1 59\n1 60\n1 61\n1 62\n1 63\n1 64\n1 65\n1 66\n1 67\n1 68\n1 69\n2 3\n2 4\n2 5\n2 6\n2 7\n2 8\n2 9\n2 10\n2 11\n2 12\n2 13\n2 14\n2 15\n2 16\n2 17\n2 18\n2 19\n2 20\n2 21...", "-1", "-1", "10250\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n1 20\n1 21\n1 22\n1 23\n1 24\n1 25\n1 26\n1 27\n1 28\n1 29\n1 30\n1 31\n1 32\n1 33\n1 34\n1 35\n1 36\n1 37\n1 38\n1 39\n1 40\n1 41\n1 42\n1 43\n1 44\n1 45\n1 46\n1 47\n1 48\n1 49\n1 50\n1 51\n2 3\n2 4\n2 5\n2 6\n2 7\n2 8\n2 9\n2 10\n2 11\n2 12\n2 13\n2 14\n2 15\n2 16\n2 17\n2 18\n2 19\n2 20\n2 21\n2 22\n2 23\n2 24\n2 25\n2 26\n2 27\n2 28\n2 29\n2 30\n2 31\n2 32\n2 33\n2 34\n2 35\n2 36\n2 37\n2 38\n2 3...", "371953\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n1 20\n1 21\n1 22\n1 23\n1 24\n1 25\n1 26\n1 27\n1 28\n1 29\n1 30\n1 31\n1 32\n1 33\n1 34\n1 35\n1 36\n1 37\n1 38\n1 39\n1 40\n1 41\n1 42\n1 43\n1 44\n1 45\n1 46\n1 47\n1 48\n1 49\n1 50\n1 51\n1 52\n1 53\n1 54\n1 55\n1 56\n1 57\n1 58\n1 59\n1 60\n1 61\n1 62\n1 63\n1 64\n1 65\n1 66\n1 67\n1 68\n1 69\n1 70\n1 71\n1 72\n1 73\n1 74\n1 75\n1 76\n1 77\n1 78\n1 79\n1 80\n1 81\n1 82\n1 83\n1 84\n1 85\n1 86\n1...", "-1", "-1", "6344\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n1 20\n1 21\n1 22\n1 23\n1 24\n1 25\n1 26\n1 27\n1 28\n1 29\n1 30\n1 31\n1 32\n1 33\n1 34\n1 35\n1 36\n1 37\n1 38\n1 39\n1 40\n1 41\n1 42\n1 43\n1 44\n1 45\n1 46\n1 47\n1 48\n1 49\n1 50\n1 51\n1 52\n1 53\n2 3\n2 4\n2 5\n2 6\n2 7\n2 8\n2 9\n2 10\n2 11\n2 12\n2 13\n2 14\n2 15\n2 16\n2 17\n2 18\n2 19\n2 20\n2 21\n2 22\n2 23\n2 24\n2 25\n2 26\n2 27\n2 28\n2 29\n2 30\n2 31\n2 32\n2 33\n2 34\n2 35\n2 36\n2 37...", "197506\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n1 20\n1 21\n1 22\n1 23\n1 24\n1 25\n1 26\n1 27\n1 28\n1 29\n1 30\n1 31\n1 32\n1 33\n1 34\n1 35\n1 36\n1 37\n1 38\n1 39\n1 40\n1 41\n1 42\n1 43\n1 44\n1 45\n1 46\n1 47\n1 48\n1 49\n1 50\n1 51\n1 52\n1 53\n1 54\n1 55\n1 56\n1 57\n1 58\n1 59\n1 60\n1 61\n1 62\n1 63\n1 64\n1 65\n1 66\n1 67\n1 68\n1 69\n1 70\n1 71\n1 72\n1 73\n1 74\n1 75\n1 76\n1 77\n1 78\n1 79\n1 80\n1 81\n1 82\n1 83\n1 84\n1 85\n1 86\n1...", "-1", "-1", "207691\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n1 20\n1 21\n1 22\n1 23\n1 24\n1 25\n1 26\n1 27\n1 28\n1 29\n1 30\n1 31\n1 32\n1 33\n1 34\n1 35\n1 36\n1 37\n1 38\n1 39\n1 40\n1 41\n1 42\n1 43\n1 44\n1 45\n1 46\n1 47\n1 48\n1 49\n1 50\n1 51\n1 52\n1 53\n1 54\n1 55\n1 56\n1 57\n1 58\n1 59\n1 60\n1 61\n1 62\n1 63\n1 64\n1 65\n1 66\n1 67\n1 68\n1 69\n1 70\n1 71\n1 72\n1 73\n1 74\n1 75\n1 76\n1 77\n1 78\n1 79\n1 80\n1 81\n1 82\n1 83\n1 84\n1 85\n1 86\n1...", "498501\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n1 20\n1 21\n1 22\n1 23\n1 24\n1 25\n1 26\n1 27\n1 28\n1 29\n1 30\n1 31\n1 32\n1 33\n1 34\n1 35\n1 36\n1 37\n1 38\n1 39\n1 40\n1 41\n1 42\n1 43\n1 44\n1 45\n1 46\n1 47\n1 48\n1 49\n1 50\n1 51\n1 52\n1 53\n1 54\n1 55\n1 56\n1 57\n1 58\n1 59\n1 60\n1 61\n1 62\n1 63\n1 64\n1 65\n1 66\n1 67\n1 68\n1 69\n1 70\n1 71\n1 72\n1 73\n1 74\n1 75\n1 76\n1 77\n1 78\n1 79\n1 80\n1 81\n1 82\n1 83\n1 84\n1 85\n1 86\n1...", "-1", "-1", "162000\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n1 20\n1 21\n1 22\n1 23\n1 24\n1 25\n1 26\n1 27\n1 28\n1 29\n1 30\n1 31\n1 32\n1 33\n1 34\n1 35\n1 36\n1 37\n1 38\n1 39\n1 40\n1 41\n1 42\n1 43\n1 44\n1 45\n1 46\n1 47\n1 48\n1 49\n1 50\n1 51\n1 52\n1 53\n1 54\n1 55\n1 56\n1 57\n1 58\n1 59\n1 60\n1 61\n1 62\n1 63\n1 64\n1 65\n1 66\n1 67\n1 68\n1 69\n1 70\n1 71\n1 72\n1 73\n1 74\n1 75\n1 76\n1 77\n1 78\n1 79\n1 80\n1 81\n1 82\n1 83\n1 84\n1 85\n1 86\n1...", "-1", "178000\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n1 20\n1 21\n1 22\n1 23\n1 24\n1 25\n1 26\n1 27\n1 28\n1 29\n1 30\n1 31\n1 32\n1 33\n1 34\n1 35\n1 36\n1 37\n1 38\n1 39\n1 40\n1 41\n1 42\n1 43\n1 44\n1 45\n1 46\n1 47\n1 48\n1 49\n1 50\n1 51\n1 52\n1 53\n1 54\n1 55\n1 56\n1 57\n1 58\n1 59\n1 60\n1 61\n1 62\n1 63\n1 64\n1 65\n1 66\n1 67\n1 68\n1 69\n1 70\n1 71\n1 72\n1 73\n1 74\n1 75\n1 76\n1 77\n1 78\n1 79\n1 80\n1 81\n1 82\n1 83\n1 84\n1 85\n1 86\n1...", "499000\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n1 20\n1 21\n1 22\n1 23\n1 24\n1 25\n1 26\n1 27\n1 28\n1 29\n1 30\n1 31\n1 32\n1 33\n1 34\n1 35\n1 36\n1 37\n1 38\n1 39\n1 40\n1 41\n1 42\n1 43\n1 44\n1 45\n1 46\n1 47\n1 48\n1 49\n1 50\n1 51\n1 52\n1 53\n1 54\n1 55\n1 56\n1 57\n1 58\n1 59\n1 60\n1 61\n1 62\n1 63\n1 64\n1 65\n1 66\n1 67\n1 68\n1 69\n1 70\n1 71\n1 72\n1 73\n1 74\n1 75\n1 76\n1 77\n1 78\n1 79\n1 80\n1 81\n1 82\n1 83\n1 84\n1 85\n1 86\n1...", "498501\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n1 20\n1 21\n1 22\n1 23\n1 24\n1 25\n1 26\n1 27\n1 28\n1 29\n1 30\n1 31\n1 32\n1 33\n1 34\n1 35\n1 36\n1 37\n1 38\n1 39\n1 40\n1 41\n1 42\n1 43\n1 44\n1 45\n1 46\n1 47\n1 48\n1 49\n1 50\n1 51\n1 52\n1 53\n1 54\n1 55\n1 56\n1 57\n1 58\n1 59\n1 60\n1 61\n1 62\n1 63\n1 64\n1 65\n1 66\n1 67\n1 68\n1 69\n1 70\n1 71\n1 72\n1 73\n1 74\n1 75\n1 76\n1 77\n1 78\n1 79\n1 80\n1 81\n1 82\n1 83\n1 84\n1 85\n1 86\n1...", "-1", "-1", "-1", "-1", "-1", "1998\n1 2\n1 3\n2 3\n2 4\n3 4\n3 5\n4 5\n4 6\n5 6\n5 7\n6 7\n6 8\n7 8\n7 9\n8 9\n8 10\n9 10\n9 11\n10 11\n10 12\n11 12\n11 13\n12 13\n12 14\n13 14\n13 15\n14 15\n14 16\n15 16\n15 17\n16 17\n16 18\n17 18\n17 19\n18 19\n18 20\n19 20\n19 21\n20 21\n20 22\n21 22\n21 23\n22 23\n22 24\n23 24\n23 25\n24 25\n24 26\n25 26\n25 27\n26 27\n26 28\n27 28\n27 29\n28 29\n28 30\n29 30\n29 31\n30 31\n30 32\n31 32\n31 33\n32 33\n32 34\n33 34\n33 35\n34 35\n34 36\n35 36\n35 37\n36 37\n36 38\n37 38\n37 39\n38 39\n38 40\n39 40\n...", "490000\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n1 20\n1 21\n1 22\n1 23\n1 24\n1 25\n1 26\n1 27\n1 28\n1 29\n1 30\n1 31\n1 32\n1 33\n1 34\n1 35\n1 36\n1 37\n1 38\n1 39\n1 40\n1 41\n1 42\n1 43\n1 44\n1 45\n1 46\n1 47\n1 48\n1 49\n1 50\n1 51\n1 52\n1 53\n1 54\n1 55\n1 56\n1 57\n1 58\n1 59\n1 60\n1 61\n1 62\n1 63\n1 64\n1 65\n1 66\n1 67\n1 68\n1 69\n1 70\n1 71\n1 72\n1 73\n1 74\n1 75\n1 76\n1 77\n1 78\n1 79\n1 80\n1 81\n1 82\n1 83\n1 84\n1 85\n1 86\n1..."]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
16
codeforces
8d337c19b31a325a4e2c5679c23c0f2a
Fools and Roads
They say that Berland has exactly two problems, fools and roads. Besides, Berland has *n* cities, populated by the fools and connected by the roads. All Berland roads are bidirectional. As there are many fools in Berland, between each pair of cities there is a path (or else the fools would get upset). Also, between each pair of cities there is no more than one simple path (or else the fools would get lost). But that is not the end of Berland's special features. In this country fools sometimes visit each other and thus spoil the roads. The fools aren't very smart, so they always use only the simple paths. A simple path is the path which goes through every Berland city not more than once. The Berland government knows the paths which the fools use. Help the government count for each road, how many distinct fools can go on it. Note how the fools' paths are given in the input. The first line contains a single integer *n* (2<=≤<=*n*<=≤<=105) — the number of cities. Each of the next *n*<=-<=1 lines contains two space-separated integers *u**i*,<=*v**i* (1<=≤<=*u**i*,<=*v**i*<=≤<=*n*, *u**i*<=≠<=*v**i*), that means that there is a road connecting cities *u**i* and *v**i*. The next line contains integer *k* (0<=≤<=*k*<=≤<=105) — the number of pairs of fools who visit each other. Next *k* lines contain two space-separated numbers. The *i*-th line (*i*<=&gt;<=0) contains numbers *a**i*,<=*b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*). That means that the fool number 2*i*<=-<=1 lives in city *a**i* and visits the fool number 2*i*, who lives in city *b**i*. The given pairs describe simple paths, because between every pair of cities there is only one simple path. Print *n*<=-<=1 integer. The integers should be separated by spaces. The *i*-th number should equal the number of fools who can go on the *i*-th road. The roads are numbered starting from one in the order, in which they occur in the input. Sample Input 5 1 2 1 3 2 4 2 5 2 1 4 3 5 5 3 4 4 5 1 4 2 4 3 2 3 1 3 3 5 Sample Output 2 1 1 1 3 1 1 1
{"inputs": ["5\n1 2\n1 3\n2 4\n2 5\n2\n1 4\n3 5", "5\n3 4\n4 5\n1 4\n2 4\n3\n2 3\n1 3\n3 5"], "outputs": ["2 1 1 1 ", "3 1 1 1 "]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
2
codeforces
8d65492fc90cdeead7cd95db3a21418d
none
Young Teodor enjoys drawing. His favourite hobby is drawing segments with integer borders inside his huge [1;*m*] segment. One day Teodor noticed that picture he just drawn has one interesting feature: there doesn't exist an integer point, that belongs each of segments in the picture. Having discovered this fact, Teodor decided to share it with Sasha. Sasha knows that Teodor likes to show off so he never trusts him. Teodor wants to prove that he can be trusted sometimes, so he decided to convince Sasha that there is no such integer point in his picture, which belongs to each segment. However Teodor is lazy person and neither wills to tell Sasha all coordinates of segments' ends nor wills to tell him their amount, so he suggested Sasha to ask him series of questions 'Given the integer point *x**i*, how many segments in Fedya's picture contain that point?', promising to tell correct answers for this questions. Both boys are very busy studying and don't have much time, so they ask you to find out how many questions can Sasha ask Teodor, that having only answers on his questions, Sasha can't be sure that Teodor isn't lying to him. Note that Sasha doesn't know amount of segments in Teodor's picture. Sure, Sasha is smart person and never asks about same point twice. First line of input contains two integer numbers: *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100<=000) — amount of segments of Teodor's picture and maximal coordinate of point that Sasha can ask about. *i*th of next *n* lines contains two integer numbers *l**i* and *r**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=*m*) — left and right ends of *i*th segment in the picture. Note that that left and right ends of segment can be the same point. It is guaranteed that there is no integer point, that belongs to all segments. Single line of output should contain one integer number *k* – size of largest set (*x**i*,<=*cnt*(*x**i*)) where all *x**i* are different, 1<=≤<=*x**i*<=≤<=*m*, and *cnt*(*x**i*) is amount of segments, containing point with coordinate *x**i*, such that one can't be sure that there doesn't exist point, belonging to all of segments in initial picture, if he knows only this set(and doesn't know *n*). Sample Input 2 4 1 2 3 4 4 6 1 3 2 3 4 6 5 6 Sample Output 4 5
{"inputs": ["2 4\n1 2\n3 4", "4 6\n1 3\n2 3\n4 6\n5 6", "43 1319\n750 1030\n857 946\n941 1203\n407 1034\n947 1290\n546 585\n630 1201\n72 342\n693 1315\n34 719\n176 1097\n36 931\n198 973\n5 1025\n892 1054\n461 1287\n195 1273\n832 1039\n308 955\n642 866\n770 838\n440 777\n289 948\n98 814\n458 768\n82 265\n300 596\n182 706\n368 1225\n237 626\n36 348\n100 222\n46 937\n364 396\n288 668\n1158 1243\n31 1108\n570 1000\n435 619\n339 1007\n132 734\n281 441\n636 1319", "31 1600\n643 1483\n8 475\n15 472\n49 81\n300 1485\n627 682\n44 443\n1191 1541\n478 732\n1112 1202\n741 1341\n475 1187\n1218 1463\n523 1513\n355 477\n1259 1559\n384 928\n487 766\n227 1224\n1102 1268\n833 1240\n872 1342\n666 1075\n734 874\n32 880\n1411 1536\n520 778\n179 1003\n51 313\n1148 1288\n1467 1509", "38 1109\n61 332\n429 756\n260 272\n57 991\n420 985\n143 219\n399 925\n486 1079\n69 881\n75 447\n678 774\n973 1016\n983 1059\n518 1049\n393 853\n375 1101\n475 946\n300 427\n294 715\n504 798\n211 1066\n730 815\n114 515\n589 1001\n464 1014\n451 757\n370 1017\n225 619\n452 988\n611 955\n349 1029\n73 165\n759 951\n574 803\n253 1045\n545 565\n603 773\n226 453", "11 3\n1 1\n1 1\n1 1\n1 1\n2 2\n2 2\n2 2\n3 3\n3 3\n3 3\n3 3"], "outputs": ["4", "5", "1082", "1181", "996", "2"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1
codeforces
8d7482c6a683d3296ea22a704783715b
Om Nom and Necklace
One day Om Nom found a thread with *n* beads of different colors. He decided to cut the first several beads from this thread to make a bead necklace and present it to his girlfriend Om Nelly. Om Nom knows that his girlfriend loves beautiful patterns. That's why he wants the beads on the necklace to form a regular pattern. A sequence of beads *S* is regular if it can be represented as *S*<==<=*A*<=+<=*B*<=+<=*A*<=+<=*B*<=+<=*A*<=+<=...<=+<=*A*<=+<=*B*<=+<=*A*, where *A* and *B* are some bead sequences, "<=+<=" is the concatenation of sequences, there are exactly 2*k*<=+<=1 summands in this sum, among which there are *k*<=+<=1 "*A*" summands and *k* "*B*" summands that follow in alternating order. Om Nelly knows that her friend is an eager mathematician, so she doesn't mind if *A* or *B* is an empty sequence. Help Om Nom determine in which ways he can cut off the first several beads from the found thread (at least one; probably, all) so that they form a regular pattern. When Om Nom cuts off the beads, he doesn't change their order. The first line contains two integers *n*, *k* (1<=≤<=*n*,<=*k*<=≤<=1<=000<=000) — the number of beads on the thread that Om Nom found and number *k* from the definition of the regular sequence above. The second line contains the sequence of *n* lowercase Latin letters that represent the colors of the beads. Each color corresponds to a single letter. Print a string consisting of *n* zeroes and ones. Position *i* (1<=≤<=*i*<=≤<=*n*) must contain either number one if the first *i* beads on the thread form a regular sequence, or a zero otherwise. Sample Input 7 2 bcabcab 21 2 ababaababaababaababaa Sample Output 0000011000110000111111000011
{"inputs": ["7 2\nbcabcab", "21 2\nababaababaababaababaa", "321 2\nabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaaba", "153 2\nabaaabaaabaaabaaabaaabaaabaaabaaabaaabaaabaaabaaabaaabaaabaaabaaabaaabaaabaaabaaabaaabaaabaaabaaabaaabaaabaaabaaabaaabaaabaaabaaabaaabaaabaaabaaabaaabaaa", "2 1\nab", "2 2\nab", "2 3\nab", "5 6\naaaaa", "5 5\naaaaa", "5 4\naaaaa", "1 1\na", "1 2\na", "1 42\na"], "outputs": ["0000011", "000110000111111000011", "000001111001111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111", "000000011111000111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111", "11", "00", "00", "00000", "00001", "00011", "1", "0", "0"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
2
codeforces
8d8fab3e7d35cb8634eaf569edcf87b7
Rain and Umbrellas
Polycarp lives on a coordinate line at the point $x = 0$. He goes to his friend that lives at the point $x = a$. Polycarp can move only from left to right, he can pass one unit of length each second. Now it's raining, so some segments of his way are in the rain. Formally, it's raining on $n$ non-intersecting segments, the $i$-th segment which is in the rain is represented as $[l_i, r_i]$ ($0 \le l_i &lt; r_i \le a$). There are $m$ umbrellas lying on the line, the $i$-th umbrella is located at point $x_i$ ($0 \le x_i \le a$) and has weight $p_i$. When Polycarp begins his journey, he doesn't have any umbrellas. During his journey from $x = 0$ to $x = a$ Polycarp can pick up and throw away umbrellas. Polycarp picks up and throws down any umbrella instantly. He can carry any number of umbrellas at any moment of time. Because Polycarp doesn't want to get wet, he must carry at least one umbrella while he moves from $x$ to $x + 1$ if a segment $[x, x + 1]$ is in the rain (i.e. if there exists some $i$ such that $l_i \le x$ and $x + 1 \le r_i$). The condition above is the only requirement. For example, it is possible to go without any umbrellas to a point where some rain segment starts, pick up an umbrella at this point and move along with an umbrella. Polycarp can swap umbrellas while he is in the rain. Each unit of length passed increases Polycarp's fatigue by the sum of the weights of umbrellas he carries while moving. Can Polycarp make his way from point $x = 0$ to point $x = a$? If yes, find the minimum total fatigue after reaching $x = a$, if Polycarp picks up and throws away umbrellas optimally. The first line contains three integers $a$, $n$ and $m$ ($1 \le a, m \le 2000, 1 \le n \le \lceil\frac{a}{2}\rceil$) — the point at which Polycarp's friend lives, the number of the segments in the rain and the number of umbrellas. Each of the next $n$ lines contains two integers $l_i$ and $r_i$ ($0 \le l_i &lt; r_i \le a$) — the borders of the $i$-th segment under rain. It is guaranteed that there is no pair of intersecting segments. In other words, for each pair of segments $i$ and $j$ either $r_i &lt; l_j$ or $r_j &lt; l_i$. Each of the next $m$ lines contains two integers $x_i$ and $p_i$ ($0 \le x_i \le a$, $1 \le p_i \le 10^5$) — the location and the weight of the $i$-th umbrella. Print "-1" (without quotes) if Polycarp can't make his way from point $x = 0$ to point $x = a$. Otherwise print one integer — the minimum total fatigue after reaching $x = a$, if Polycarp picks up and throws away umbrellas optimally. Sample Input 10 2 4 3 7 8 10 0 10 3 4 8 1 1 2 10 1 1 0 9 0 5 10 1 1 0 9 1 5 Sample Output 14 45 -1
{"inputs": ["10 2 4\n3 7\n8 10\n0 10\n3 4\n8 1\n1 2", "10 1 1\n0 9\n0 5", "10 1 1\n0 9\n1 5", "1 1 1\n0 1\n1 100000", "1 1 1\n0 1\n0 100000", "2000 1 1\n0 1\n2000 33303", "2000 1 1\n1999 2000\n0 18898", "100 50 1\n1 2\n3 4\n5 6\n7 8\n9 10\n11 12\n13 14\n15 16\n17 18\n19 20\n21 22\n23 24\n25 26\n27 28\n29 30\n31 32\n33 34\n35 36\n37 38\n39 40\n41 42\n43 44\n45 46\n47 48\n49 50\n51 52\n53 54\n55 56\n57 58\n59 60\n61 62\n63 64\n65 66\n67 68\n69 70\n71 72\n73 74\n75 76\n77 78\n79 80\n81 82\n83 84\n85 86\n87 88\n89 90\n91 92\n93 94\n95 96\n97 98\n99 100\n0 91855", "2000 10 10\n46 161\n197 348\n412 538\n694 1183\n1210 1321\n1360 1440\n1615 1705\n1707 1819\n1832 1846\n1868 1917\n428 95081\n975 8616\n1159 27215\n532 32890\n1165 53788\n1969 11184\n1443 32142\n553 7583\n1743 33810\n315 62896", "2000 10 1\n63 103\n165 171\n412 438\n696 702\n764 782\n946 1040\n1106 1132\n1513 1532\n1589 1696\n1785 1919\n63 51662", "2000 1 1\n0 2000\n0 100000", "10 3 3\n0 3\n4 8\n9 10\n0 89516\n9 30457\n2 31337"], "outputs": ["14", "45", "-1", "-1", "100000", "-1", "37796000", "9185500", "-1", "95884672", "200000000", "397511"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
5
codeforces
8d9078b0a36ff7bd5d993ae41b3780b0
Rounding
Vasya has a non-negative integer *n*. He wants to round it to nearest integer, which ends up with 0. If *n* already ends up with 0, Vasya considers it already rounded. For example, if *n*<==<=4722 answer is 4720. If *n*<==<=5 Vasya can round it to 0 or to 10. Both ways are correct. For given *n* find out to which integer will Vasya round it. The first line contains single integer *n* (0<=≤<=*n*<=≤<=109) — number that Vasya has. Print result of rounding *n*. Pay attention that in some cases answer isn't unique. In that case print any correct answer. Sample Input 5 113 1000000000 5432359 Sample Output 0 110 1000000000 5432360
{"inputs": ["5", "113", "1000000000", "5432359", "999999994", "10", "9", "1", "0", "3", "4", "6", "7", "8", "19", "100", "997", "9994", "10002", "100000", "99999", "999999999", "999999998", "999999995", "999999990", "1000000", "1000010", "10000010", "100000011", "400000003", "234234", "675621", "43532", "4576453", "65754674", "3245526", "123445", "234217", "23451218", "1231239", "1923140", "307910310", "780961030", "103509421", "576560141", "48851642", "226935072", "844450763", "22534183", "640049874", "818133304", "730616285", "613732415", "380991216", "559074636", "176590327", "354673757", "267156738", "150272868", "62755859", "945871979", "46", "999", "1397"], "outputs": ["0", "110", "1000000000", "5432360", "999999990", "10", "10", "0", "0", "0", "0", "10", "10", "10", "20", "100", "1000", "9990", "10000", "100000", "100000", "1000000000", "1000000000", "999999990", "999999990", "1000000", "1000010", "10000010", "100000010", "400000000", "234230", "675620", "43530", "4576450", "65754670", "3245530", "123440", "234220", "23451220", "1231240", "1923140", "307910310", "780961030", "103509420", "576560140", "48851640", "226935070", "844450760", "22534180", "640049870", "818133300", "730616280", "613732410", "380991220", "559074640", "176590330", "354673760", "267156740", "150272870", "62755860", "945871980", "50", "1000", "1400"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
461
codeforces
8d9b9f436834145197b35fe3b1a4ec79
Help Far Away Kingdom
In a far away kingdom lived the King, the Prince, the Shoemaker, the Dressmaker and many other citizens. They lived happily until great trouble came into the Kingdom. The ACMers settled there. Most damage those strange creatures inflicted upon the kingdom was that they loved high precision numbers. As a result, the Kingdom healers had already had three appointments with the merchants who were asked to sell, say, exactly 0.273549107 beer barrels. To deal with the problem somehow, the King issued an order obliging rounding up all numbers to the closest integer to simplify calculations. Specifically, the order went like this: - If a number's integer part does not end with digit 9 and its fractional part is strictly less than 0.5, then the rounded up number coincides with the number’s integer part. - If a number's integer part does not end with digit 9 and its fractional part is not less than 0.5, the rounded up number is obtained if we add 1 to the last digit of the number’s integer part.- If the number’s integer part ends with digit 9, to round up the numbers one should go to Vasilisa the Wise. In the whole Kingdom she is the only one who can perform the tricky operation of carrying into the next position. Merchants found the algorithm very sophisticated and they asked you (the ACMers) to help them. Can you write a program that would perform the rounding according to the King’s order? The first line contains a single number to round up — the integer part (a non-empty set of decimal digits that do not start with 0 — with the exception of a case when the set consists of a single digit — in this case 0 can go first), then follows character «.» (a dot), and then follows the fractional part (any non-empty set of decimal digits). The number's length does not exceed 1000 characters, including the dot. There are no other characters in the input data. If the last number of the integer part is not equal to 9, print the rounded-up number without leading zeroes. Otherwise, print the message "GOTO Vasilisa." (without the quotes). Sample Input 0.0 1.49 1.50 2.71828182845904523536 3.14159265358979323846 12345678901234567890.1 123456789123456789.999 Sample Output 0123312345678901234567890GOTO Vasilisa.
{"inputs": ["0.0", "1.49", "1.50", "2.71828182845904523536", "3.14159265358979323846", "12345678901234567890.1", "123456789123456789.999", "12345678901234567890.9", "123456789123456788.999", "9.000", "0.1", "0.2", "0.3", "0.4", "0.5", "0.6", "0.7", "0.8", "0.9", "1.0", "1.1", "1.2", "1.3", "1.4", "1.5", "1.6", "1.7", "1.8", "1.9", "2.0", "2.1", "2.2", "2.3", "2.4", "2.5", "2.6", "2.7", "2.8", "2.9", "3.0", "3.1", "3.2", "3.3", "3.4", "3.5", "3.6", "3.7", "3.8", "3.9", "4.0", "4.1", "4.2", "4.3", "4.4", "4.5", "4.6", "4.7", "4.8", "4.9", "5.0", "5.1", "5.2", "5.3", "5.4", "5.5", "5.6", "5.7", "5.8", "5.9", "6.0", "6.1", "6.2", "6.3", "6.4", "6.5", "6.6", "6.7", "6.8", "6.9", "7.0", "7.1", "7.2", "7.3", "7.4", "7.5", "7.6", "7.7", "7.8", "7.9", "8.0", "8.1", "8.2", "8.3", "8.4", "8.5", "8.6", "8.7", "8.8", "8.9", "9.0", "9.1", "9.2", "9.3", "9.4", "9.5", "9.6", "9.7", "9.8", "9.9", "609942239104813108618306232517836377583566292129955473517174437591594761209877970062547641606473593416245554763832875919009472288995880898848455284062760160557686724163817329189799336769669146848904803188614226720978399787805489531837751080926098.1664915772983166314490532653577560222779830866949001942720729759794777105570672781798092416748052690224813237139640723361527601154465287615917169132637313918577673651098507390501962", "7002108534951820589946967018226114921984364117669853212254634761258884835434844673935047882480101006606512119541798298905598015607366335061012709906661245805358900665571472645463994925687210711492820804158354236327017974683658305043146543214454877759341394.20211856263503281388748282682120712214711232598021393495443628276945042110862480888110959179019986486690931930108026302665438087068150666835901617457150158918705186964935221768346957536540345814875615118637945520917367155931078965", "1950583094879039694852660558765931995628486712128191844305265555887022812284005463780616067.5000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", "718130341896330596635811874410345440628950330.500000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", "927925904158088313481229162503626281882161630091489367140850985555900173018122871746924067186432044676083646964286435457446768031295712712803570690846298544912543439221596866052681116386179629036945370280722.500000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", "68289614863244584294178637364598054554769889.500000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", "7536521504744364134984603189602839063535643888645969434165019366202558753840519.4999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999", "646188694587964249318078225173.5000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", "7017472758334494297677068672222822550374695787171163207025095950296957261530.50", "259085737066615534998640212505663524594409165063310128108448186246980628179842202905722595400477937071746695941939306735605849342959111887834258250883469840846714848774368.50000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", "682500858233333594535201113441004740771119672961581796618069185960107115823662126812159957094407454522028503739299.5000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", "41203422675619090661099806687619.49999999999999999999999999999999999999999999999999999999999999999999999999999999999999999"], "outputs": ["0", "1", "2", "3", "3", "12345678901234567890", "GOTO Vasilisa.", "12345678901234567891", "123456789123456789", "GOTO Vasilisa.", "0", "0", "0", "0", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "2", "2", "2", "2", "2", "2", "2", "2", "2", "2", "3", "3", "3", "3", "3", "3", "3", "3", "3", "3", "4", "4", "4", "4", "4", "4", "4", "4", "4", "4", "5", "5", "5", "5", "5", "5", "5", "5", "5", "5", "6", "6", "6", "6", "6", "6", "6", "6", "6", "6", "7", "7", "7", "7", "7", "7", "7", "7", "7", "7", "8", "8", "8", "8", "8", "8", "8", "8", "8", "8", "9", "9", "9", "9", "9", "GOTO Vasilisa.", "GOTO Vasilisa.", "GOTO Vasilisa.", "GOTO Vasilisa.", "GOTO Vasilisa.", "GOTO Vasilisa.", "GOTO Vasilisa.", "GOTO Vasilisa.", "GOTO Vasilisa.", "GOTO Vasilisa.", "609942239104813108618306232517836377583566292129955473517174437591594761209877970062547641606473593416245554763832875919009472288995880898848455284062760160557686724163817329189799336769669146848904803188614226720978399787805489531837751080926098", "7002108534951820589946967018226114921984364117669853212254634761258884835434844673935047882480101006606512119541798298905598015607366335061012709906661245805358900665571472645463994925687210711492820804158354236327017974683658305043146543214454877759341394", "1950583094879039694852660558765931995628486712128191844305265555887022812284005463780616068", "718130341896330596635811874410345440628950331", "927925904158088313481229162503626281882161630091489367140850985555900173018122871746924067186432044676083646964286435457446768031295712712803570690846298544912543439221596866052681116386179629036945370280723", "GOTO Vasilisa.", "GOTO Vasilisa.", "646188694587964249318078225174", "7017472758334494297677068672222822550374695787171163207025095950296957261531", "259085737066615534998640212505663524594409165063310128108448186246980628179842202905722595400477937071746695941939306735605849342959111887834258250883469840846714848774369", "GOTO Vasilisa.", "GOTO Vasilisa."]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
202
codeforces
8daea05e984def6f793db9d374212130
Segments
You are given an integer *N*. Consider all possible segments on the coordinate axis with endpoints at integer points with coordinates between 0 and *N*, inclusive; there will be of them. You want to draw these segments in several layers so that in each layer the segments don't overlap (they might touch at the endpoints though). You can not move the segments to a different location on the coordinate axis. Find the minimal number of layers you have to use for the given *N*. The only input line contains a single integer *N* (1<=≤<=*N*<=≤<=100). Output a single integer - the minimal number of layers required to draw the segments for the given *N*. Sample Input 2 3 4 Sample Output 2 4 6
{"inputs": ["2", "3", "4", "21", "100", "1", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31", "32", "33", "34", "35", "36", "37", "38", "39", "40", "41", "42", "43", "44", "45", "46", "47", "48", "49", "50", "51", "52", "53", "54", "55", "56", "57", "58", "59", "60", "61", "62", "63", "64", "65", "66", "67", "68", "69", "70", "71", "72", "73", "74", "75", "76", "77", "78", "79", "80", "81", "82", "83", "84", "85", "86", "87", "88", "89", "90", "91", "92", "93", "94", "95", "96", "97", "98", "99", "1", "5"], "outputs": ["2", "4", "6", "121", "2550", "1", "9", "12", "16", "20", "25", "30", "36", "42", "49", "56", "64", "72", "81", "90", "100", "110", "132", "144", "156", "169", "182", "196", "210", "225", "240", "256", "272", "289", "306", "324", "342", "361", "380", "400", "420", "441", "462", "484", "506", "529", "552", "576", "600", "625", "650", "676", "702", "729", "756", "784", "812", "841", "870", "900", "930", "961", "992", "1024", "1056", "1089", "1122", "1156", "1190", "1225", "1260", "1296", "1332", "1369", "1406", "1444", "1482", "1521", "1560", "1600", "1640", "1681", "1722", "1764", "1806", "1849", "1892", "1936", "1980", "2025", "2070", "2116", "2162", "2209", "2256", "2304", "2352", "2401", "2450", "2500", "1", "9"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
157
codeforces
8db0bc286b569043a28bd31c19f4c65b
Shaass and Oskols
Shaass has decided to hunt some birds. There are *n* horizontal electricity wires aligned parallel to each other. Wires are numbered 1 to *n* from top to bottom. On each wire there are some oskols sitting next to each other. Oskol is the name of a delicious kind of birds in Shaass's territory. Supposed there are *a**i* oskols sitting on the *i*-th wire. Sometimes Shaass shots one of the birds and the bird dies (suppose that this bird sat at the *i*-th wire). Consequently all the birds on the *i*-th wire to the left of the dead bird get scared and jump up on the wire number *i*<=-<=1, if there exists no upper wire they fly away. Also all the birds to the right of the dead bird jump down on wire number *i*<=+<=1, if there exists no such wire they fly away. Shaass has shot *m* birds. You're given the initial number of birds on each wire, tell him how many birds are sitting on each wire after the shots. The first line of the input contains an integer *n*, (1<=≤<=*n*<=≤<=100). The next line contains a list of space-separated integers *a*1,<=*a*2,<=...,<=*a**n*, (0<=≤<=*a**i*<=≤<=100). The third line contains an integer *m*, (0<=≤<=*m*<=≤<=100). Each of the next *m* lines contains two integers *x**i* and *y**i*. The integers mean that for the *i*-th time Shaass shoot the *y**i*-th (from left) bird on the *x**i*-th wire, (1<=≤<=*x**i*<=≤<=*n*,<=1<=≤<=*y**i*). It's guaranteed there will be at least *y**i* birds on the *x**i*-th wire at that moment. On the *i*-th line of the output print the number of birds on the *i*-th wire. Sample Input 5 10 10 10 10 10 5 2 5 3 13 2 12 1 13 4 6 3 2 4 1 1 2 2 Sample Output 0 12 5 0 16 3 0 3
{"inputs": ["5\n10 10 10 10 10\n5\n2 5\n3 13\n2 12\n1 13\n4 6", "3\n2 4 1\n1\n2 2", "5\n58 51 45 27 48\n5\n4 9\n5 15\n4 5\n5 8\n1 43", "10\n48 53 10 28 91 56 81 2 67 52\n2\n2 40\n6 51", "2\n72 45\n6\n1 69\n2 41\n1 19\n2 7\n1 5\n2 1", "10\n95 54 36 39 98 30 19 24 14 12\n3\n9 5\n8 15\n7 5", "100\n95 15 25 18 64 62 23 59 70 84 50 26 87 35 75 86 0 22 77 60 66 41 21 9 75 50 25 3 69 14 39 68 64 46 59 99 2 0 21 76 90 12 61 42 6 91 36 39 47 41 93 81 66 57 70 36 68 89 52 1 19 93 67 22 76 20 8 81 98 18 100 73 61 93 75 80 53 72 40 20 2 86 33 59 27 16 11 26 55 44 47 55 94 58 2 55 82 22 9 95\n0", "1\n100\n1\n1 100", "1\n100\n1\n1 1", "1\n50\n1\n1 25", "2\n50 0\n1\n1 1", "1\n10\n0"], "outputs": ["0\n12\n5\n0\n16", "3\n0\n3", "0\n66\n57\n7\n0", "87\n0\n23\n28\n141\n0\n86\n2\n67\n52", "0\n0", "95\n54\n36\n39\n98\n34\n0\n28\n13\n21", "95\n15\n25\n18\n64\n62\n23\n59\n70\n84\n50\n26\n87\n35\n75\n86\n0\n22\n77\n60\n66\n41\n21\n9\n75\n50\n25\n3\n69\n14\n39\n68\n64\n46\n59\n99\n2\n0\n21\n76\n90\n12\n61\n42\n6\n91\n36\n39\n47\n41\n93\n81\n66\n57\n70\n36\n68\n89\n52\n1\n19\n93\n67\n22\n76\n20\n8\n81\n98\n18\n100\n73\n61\n93\n75\n80\n53\n72\n40\n20\n2\n86\n33\n59\n27\n16\n11\n26\n55\n44\n47\n55\n94\n58\n2\n55\n82\n22\n9\n95", "0", "0", "0", "0\n49", "10"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
397
codeforces
8dbf384ae645ced530cdc48451343e58
Pipeline
Vova, the Ultimate Thule new shaman, wants to build a pipeline. As there are exactly *n* houses in Ultimate Thule, Vova wants the city to have exactly *n* pipes, each such pipe should be connected to the water supply. A pipe can be connected to the water supply if there's water flowing out of it. Initially Vova has only one pipe with flowing water. Besides, Vova has several splitters. A splitter is a construction that consists of one input (it can be connected to a water pipe) and *x* output pipes. When a splitter is connected to a water pipe, water flows from each output pipe. You can assume that the output pipes are ordinary pipes. For example, you can connect water supply to such pipe if there's water flowing out from it. At most one splitter can be connected to any water pipe. Vova has one splitter of each kind: with 2, 3, 4, ..., *k* outputs. Help Vova use the minimum number of splitters to build the required pipeline or otherwise state that it's impossible. Vova needs the pipeline to have exactly *n* pipes with flowing out water. Note that some of those pipes can be the output pipes of the splitters. The first line contains two space-separated integers *n* and *k* (1<=≤<=*n*<=≤<=1018, 2<=≤<=*k*<=≤<=109). Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier. Print a single integer — the minimum number of splitters needed to build the pipeline. If it is impossible to build a pipeline with the given splitters, print -1. Sample Input 4 3 5 5 8 4 Sample Output 2 1 -1
{"inputs": ["4 3", "5 5", "8 4", "1000000000000000000 1000000000", "499999998500000001 1000000000", "499999998500000000 1000000000", "499999999500000000 1000000000", "499999999500000001 1000000000", "525 34", "223265034477 726990", "15597035789572051 185473109", "499999999500000002 1000000000", "1 1000000000", "1000000000 2", "462498979 204468265", "2107921 542531", "131 49", "20171878992939541 200857557", "399812655947 894219", "93 17", "1000000000 999999999", "100000000000000000 1000000000"], "outputs": ["2", "1", "-1", "-1", "999955279", "999955279", "999999998", "999999999", "25", "440662", "128849771", "-1", "0", "-1", "3", "4", "3", "200853401", "893030", "8", "2", "105572810"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
50
codeforces
8dd48a95d077948b9426c6505bdbe45c
none
This is an interactive problem. Jury has hidden a permutation *p* of integers from 0 to *n*<=-<=1. You know only the length *n*. Remind that in permutation all integers are distinct. Let *b* be the inverse permutation for *p*, i.e. *p**b**i*<==<=*i* for all *i*. The only thing you can do is to ask xor of elements *p**i* and *b**j*, printing two indices *i* and *j* (not necessarily distinct). As a result of the query with indices *i* and *j* you'll get the value , where denotes the xor operation. You can find the description of xor operation in notes. Note that some permutations can remain indistinguishable from the hidden one, even if you make all possible *n*2 queries. You have to compute the number of permutations indistinguishable from the hidden one, and print one of such permutations, making no more than 2*n* queries. The hidden permutation does not depend on your queries. The first line contains single integer *n* (1<=≤<=*n*<=≤<=5000) — the length of the hidden permutation. You should read this integer first. When your program is ready to print the answer, print three lines. In the first line print "!". In the second line print single integer *answers*_*cnt* — the number of permutations indistinguishable from the hidden one, including the hidden one. In the third line print *n* integers *p*0,<=*p*1,<=...,<=*p**n*<=-<=1 (0<=≤<=*p**i*<=&lt;<=*n*, all *p**i* should be distinct) — one of the permutations indistinguishable from the hidden one. Your program should terminate after printing the answer. Sample Input 3 0 0 3 2 3 24 2 3 2 0 2 3 2 0 Sample Output ? 0 0 ? 1 1 ? 1 2 ? 0 2 ? 2 1 ? 2 0 ! 1 0 1 2? 0 1 ? 1 2 ? 2 3 ? 3 3 ? 3 2 ? 2 1 ? 1 0 ? 0 0 ! 2 3 1 2 0
{"inputs": ["3\n0 1 2", "4\n3 1 2 0", "4\n3 2 1 0", "8\n2 3 0 1 4 5 6 7", "1\n0", "10\n0 1 2 3 4 5 6 7 8 9", "6\n0 1 2 4 3 5", "2\n0 1", "10\n6 7 4 5 0 1 8 9 2 3", "10\n9 8 1 7 6 4 5 2 0 3", "64\n0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 62 63 60 61", "128\n0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 126 123 124 125 122 127"], "outputs": ["1\n0 1 2 ", "2\n0 2 1 3 ", "4\n0 1 2 3 ", "4\n0 1 2 3 6 7 4 5 ", "1\n0 ", "2\n0 1 2 3 4 5 6 7 8 9 ", "1\n0 1 2 4 3 5 ", "2\n0 1 ", "2\n6 7 4 5 0 1 8 9 2 3 ", "1\n9 8 1 7 6 4 5 2 0 3 ", "4\n0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 62 63 60 61 ", "2\n0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 126 123 124 125 122 127 "]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1
codeforces
8e200e66a6bc8b339fc2303f84d097ff
Geometrical Progression
For given *n*, *l* and *r* find the number of distinct geometrical progression, each of which contains *n* distinct integers not less than *l* and not greater than *r*. In other words, for each progression the following must hold: *l*<=≤<=*a**i*<=≤<=*r* and *a**i*<=≠<=*a**j* , where *a*1,<=*a*2,<=...,<=*a**n* is the geometrical progression, 1<=≤<=*i*,<=*j*<=≤<=*n* and *i*<=≠<=*j*. Geometrical progression is a sequence of numbers *a*1,<=*a*2,<=...,<=*a**n* where each term after first is found by multiplying the previous one by a fixed non-zero number *d* called the common ratio. Note that in our task *d* may be non-integer. For example in progression 4,<=6,<=9, common ratio is . Two progressions *a*1,<=*a*2,<=...,<=*a**n* and *b*1,<=*b*2,<=...,<=*b**n* are considered different, if there is such *i* (1<=≤<=*i*<=≤<=*n*) that *a**i*<=≠<=*b**i*. The first and the only line cotains three integers *n*, *l* and *r* (1<=≤<=*n*<=≤<=107,<=1<=≤<=*l*<=≤<=*r*<=≤<=107). Print the integer *K* — is the answer to the problem. Sample Input 1 1 10 2 6 9 3 1 10 3 3 10 Sample Output 101282
{"inputs": ["1 1 10", "2 6 9", "3 1 10", "3 3 10", "1 25 845", "2 25 845", "3 25 845", "4 25 845", "5 25 845", "6 25 845", "7 25 845", "8 25 845", "1 1 10000000", "2 1 10000000", "3 1 10000000", "4 1 10000000", "5 1 10000000", "6 1 10000000", "7 1 10000000", "8 1 10000000", "9 1 10000000", "10 1 10000000", "11 1 10000000", "12 1 10000000", "13 1 10000000", "14 1 10000000", "15 1 10000000", "16 1 10000000", "17 1 10000000", "18 1 10000000", "19 1 10000000", "20 1 10000000", "21 1 10000000", "22 1 10000000", "23 1 10000000", "24 1 10000000", "25 1 10000000", "123456 1 10000000", "10000000 1 10000000", "1 10000000 10000000", "2 10000000 10000000", "10000000 10000000 10000000", "1 5000000 10000000", "2 5000000 10000000", "3 5000000 10000000", "4 5000000 10000000", "5 5000000 10000000", "6 5000000 10000000", "7 5000000 10000000", "8 5000000 10000000", "1000 5000000 10000000", "1 100 1000000", "2 100 1000000", "3 100 1000000", "4 100 1000000", "5 100 1000000", "6 100 1000000", "7 100 1000000", "8 100 1000000", "9 100 1000000", "10 100 1000000", "11 100 1000000", "12 100 1000000", "13 100 1000000", "14 100 1000000", "15 100 1000000", "16 100 1000000", "17 100 1000000", "1 1 1", "10000000 1 1", "1 123 456789", "2 123 456789", "3 123 456789", "4 123 456789", "5 123 456789", "6 123 456789", "7 123 456789", "8 123 456789", "9 123 456789", "10 123 456789", "11 123 456789", "12 123 456789", "13 123 456789", "1 1 5000000", "2 1 5000000", "3 1 5000000", "4 1 5000000", "5 1 5000000", "6 1 5000000", "7 1 5000000", "8 1 5000000", "9 1 5000000", "10 1 5000000", "11 1 5000000", "12 1 5000000", "13 1 5000000", "14 1 5000000", "15 1 5000000", "16 1 5000000", "17 1 5000000", "18 1 5000000", "19 1 5000000", "20 1 5000000", "21 1 5000000", "22 1 5000000", "23 1 5000000", "24 1 5000000", "25 1 5000000", "2 1 1"], "outputs": ["10", "12", "8", "2", "821", "673220", "2150", "324", "84", "10", "2", "0", "10000000", "99999990000000", "89371160", "7299492", "2209708", "875204", "384900", "178350", "85060", "41286", "20250", "9996", "4954", "2464", "1228", "610", "304", "152", "76", "38", "18", "8", "4", "2", "0", "0", "0", "1", "0", "0", "5000001", "25000005000000", "7065044", "117250", "4674", "194", "8", "0", "0", "999901", "999801009900", "7474368", "715006", "217914", "86100", "37648", "17266", "8066", "3814", "1786", "788", "292", "46", "0", "0", "0", "1", "0", "456667", "208544292222", "3172916", "321710", "98144", "38632", "16734", "7566", "3480", "1588", "662", "206", "0", "5000000", "24999995000000", "42582108", "3640680", "1104328", "437484", "192426", "89168", "42518", "20638", "10116", "4998", "2476", "1232", "614", "304", "152", "76", "38", "18", "8", "4", "2", "0", "0", "0"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1
codeforces
8e2fa585a4cce90d151115947a7dfe76
Maximal Binary Matrix
You are given matrix with *n* rows and *n* columns filled with zeroes. You should put *k* ones in it in such a way that the resulting matrix is symmetrical with respect to the main diagonal (the diagonal that goes from the top left to the bottom right corner) and is lexicographically maximal. One matrix is lexicographically greater than the other if the first different number in the first different row from the top in the first matrix is greater than the corresponding number in the second one. If there exists no such matrix then output -1. The first line consists of two numbers *n* and *k* (1<=≤<=*n*<=≤<=100, 0<=≤<=*k*<=≤<=106). If the answer exists then output resulting matrix. Otherwise output -1. Sample Input 2 1 3 2 2 5 Sample Output 1 0 0 0 1 0 0 0 1 0 0 0 0 -1
{"inputs": ["2 1", "3 2", "2 5", "1 0", "1 1", "20 398", "20 401", "100 3574", "100 10000", "100 10001", "2 3", "4 5", "5 6", "5 24", "2 0", "3 5", "3 3", "5 10", "3 4", "4 3", "1 1000000", "3 6", "1 2", "1 0", "1 1", "1 2", "1 3", "1 4", "1 5", "1 6", "1 7", "1 8", "1 9", "1 10", "1 11", "1 12", "1 13", "1 14", "1 15", "1 16", "1 17", "1 18", "1 19", "1 20", "1 21", "1 22", "1 23", "1 24", "1 25", "1 26", "2 0", "2 1", "2 2", "2 3", "2 4", "2 5", "2 6", "2 7", "2 8", "2 9", "2 10", "2 11", "2 12", "2 13", "2 14", "2 15", "2 16", "2 17", "2 18", "2 19", "2 20", "2 21", "2 22", "2 23", "2 24", "2 25", "2 26", "3 0", "3 1", "3 2", "3 3", "3 4", "3 5", "3 6", "3 7", "3 8", "3 9", "3 10", "3 11", "3 12", "3 13", "3 14", "3 15", "3 16", "3 17", "3 18", "3 19", "3 20", "3 21", "3 22", "3 23", "3 24", "3 25", "3 26", "4 0", "4 1", "4 2", "4 3", "4 4", "4 5", "4 6", "4 7", "4 8", "4 9", "4 10", "4 11", "4 12", "4 13", "4 14", "4 15", "4 16", "4 17", "4 18", "4 19", "4 20", "4 21", "4 22", "4 23", "4 24", "4 25", "4 26", "5 0", "5 1", "5 2", "5 3", "5 4", "5 5", "5 6", "5 7", "5 8", "5 9", "5 10", "5 11", "5 12", "5 13", "5 14", "5 15", "5 16", "5 17", "5 18", "5 19", "5 20", "5 21", "5 22", "5 23", "5 24", "5 25", "5 26", "100 0", "100 1", "100 2", "100 3", "100 99", "100 100", "100 101", "100 9999", "100 10000", "100 10001"], "outputs": ["1 0 \n0 0 ", "1 0 0 \n0 1 0 \n0 0 0 ", "-1", "0 ", "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 \n1 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 \n1 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 \n1 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 \n1 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 \n1 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 \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 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 1 1 1 \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 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 \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 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 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 \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 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 \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 1 1 1 1 1 1 1...", "-1", "1 1 \n1 0 ", "1 1 1 0 \n1 0 0 0 \n1 0 0 0 \n0 0 0 0 ", "1 1 1 0 0 \n1 1 0 0 0 \n1 0 0 0 0 \n0 0 0 0 0 \n0 0 0 0 0 ", "1 1 1 1 1 \n1 1 1 1 1 \n1 1 1 1 1 \n1 1 1 1 1 \n1 1 1 1 0 ", "0 0 \n0 0 ", "1 1 1 \n1 0 0 \n1 0 0 ", "1 1 0 \n1 0 0 \n0 0 0 ", "1 1 1 1 1 \n1 1 0 0 0 \n1 0 0 0 0 \n1 0 0 0 0 \n1 0 0 0 0 ", "1 1 0 \n1 1 0 \n0 0 0 ", "1 1 0 0 \n1 0 0 0 \n0 0 0 0 \n0 0 0 0 ", "-1", "1 1 1 \n1 1 0 \n1 0 0 ", "-1", "0 ", "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", "0 0 \n0 0 ", "1 0 \n0 0 ", "1 0 \n0 1 ", "1 1 \n1 0 ", "1 1 \n1 1 ", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "0 0 0 \n0 0 0 \n0 0 0 ", "1 0 0 \n0 0 0 \n0 0 0 ", "1 0 0 \n0 1 0 \n0 0 0 ", "1 1 0 \n1 0 0 \n0 0 0 ", "1 1 0 \n1 1 0 \n0 0 0 ", "1 1 1 \n1 0 0 \n1 0 0 ", "1 1 1 \n1 1 0 \n1 0 0 ", "1 1 1 \n1 1 0 \n1 0 1 ", "1 1 1 \n1 1 1 \n1 1 0 ", "1 1 1 \n1 1 1 \n1 1 1 ", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "0 0 0 0 \n0 0 0 0 \n0 0 0 0 \n0 0 0 0 ", "1 0 0 0 \n0 0 0 0 \n0 0 0 0 \n0 0 0 0 ", "1 0 0 0 \n0 1 0 0 \n0 0 0 0 \n0 0 0 0 ", "1 1 0 0 \n1 0 0 0 \n0 0 0 0 \n0 0 0 0 ", "1 1 0 0 \n1 1 0 0 \n0 0 0 0 \n0 0 0 0 ", "1 1 1 0 \n1 0 0 0 \n1 0 0 0 \n0 0 0 0 ", "1 1 1 0 \n1 1 0 0 \n1 0 0 0 \n0 0 0 0 ", "1 1 1 1 \n1 0 0 0 \n1 0 0 0 \n1 0 0 0 ", "1 1 1 1 \n1 1 0 0 \n1 0 0 0 \n1 0 0 0 ", "1 1 1 1 \n1 1 0 0 \n1 0 1 0 \n1 0 0 0 ", "1 1 1 1 \n1 1 1 0 \n1 1 0 0 \n1 0 0 0 ", "1 1 1 1 \n1 1 1 0 \n1 1 1 0 \n1 0 0 0 ", "1 1 1 1 \n1 1 1 1 \n1 1 0 0 \n1 1 0 0 ", "1 1 1 1 \n1 1 1 1 \n1 1 1 0 \n1 1 0 0 ", "1 1 1 1 \n1 1 1 1 \n1 1 1 0 \n1 1 0 1 ", "1 1 1 1 \n1 1 1 1 \n1 1 1 1 \n1 1 1 0 ", "1 1 1 1 \n1 1 1 1 \n1 1 1 1 \n1 1 1 1 ", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "0 0 0 0 0 \n0 0 0 0 0 \n0 0 0 0 0 \n0 0 0 0 0 \n0 0 0 0 0 ", "1 0 0 0 0 \n0 0 0 0 0 \n0 0 0 0 0 \n0 0 0 0 0 \n0 0 0 0 0 ", "1 0 0 0 0 \n0 1 0 0 0 \n0 0 0 0 0 \n0 0 0 0 0 \n0 0 0 0 0 ", "1 1 0 0 0 \n1 0 0 0 0 \n0 0 0 0 0 \n0 0 0 0 0 \n0 0 0 0 0 ", "1 1 0 0 0 \n1 1 0 0 0 \n0 0 0 0 0 \n0 0 0 0 0 \n0 0 0 0 0 ", "1 1 1 0 0 \n1 0 0 0 0 \n1 0 0 0 0 \n0 0 0 0 0 \n0 0 0 0 0 ", "1 1 1 0 0 \n1 1 0 0 0 \n1 0 0 0 0 \n0 0 0 0 0 \n0 0 0 0 0 ", "1 1 1 1 0 \n1 0 0 0 0 \n1 0 0 0 0 \n1 0 0 0 0 \n0 0 0 0 0 ", "1 1 1 1 0 \n1 1 0 0 0 \n1 0 0 0 0 \n1 0 0 0 0 \n0 0 0 0 0 ", "1 1 1 1 1 \n1 0 0 0 0 \n1 0 0 0 0 \n1 0 0 0 0 \n1 0 0 0 0 ", "1 1 1 1 1 \n1 1 0 0 0 \n1 0 0 0 0 \n1 0 0 0 0 \n1 0 0 0 0 ", "1 1 1 1 1 \n1 1 0 0 0 \n1 0 1 0 0 \n1 0 0 0 0 \n1 0 0 0 0 ", "1 1 1 1 1 \n1 1 1 0 0 \n1 1 0 0 0 \n1 0 0 0 0 \n1 0 0 0 0 ", "1 1 1 1 1 \n1 1 1 0 0 \n1 1 1 0 0 \n1 0 0 0 0 \n1 0 0 0 0 ", "1 1 1 1 1 \n1 1 1 1 0 \n1 1 0 0 0 \n1 1 0 0 0 \n1 0 0 0 0 ", "1 1 1 1 1 \n1 1 1 1 0 \n1 1 1 0 0 \n1 1 0 0 0 \n1 0 0 0 0 ", "1 1 1 1 1 \n1 1 1 1 1 \n1 1 0 0 0 \n1 1 0 0 0 \n1 1 0 0 0 ", "1 1 1 1 1 \n1 1 1 1 1 \n1 1 1 0 0 \n1 1 0 0 0 \n1 1 0 0 0 ", "1 1 1 1 1 \n1 1 1 1 1 \n1 1 1 0 0 \n1 1 0 1 0 \n1 1 0 0 0 ", "1 1 1 1 1 \n1 1 1 1 1 \n1 1 1 1 0 \n1 1 1 0 0 \n1 1 0 0 0 ", "1 1 1 1 1 \n1 1 1 1 1 \n1 1 1 1 0 \n1 1 1 1 0 \n1 1 0 0 0 ", "1 1 1 1 1 \n1 1 1 1 1 \n1 1 1 1 1 \n1 1 1 0 0 \n1 1 1 0 0 ", "1 1 1 1 1 \n1 1 1 1 1 \n1 1 1 1 1 \n1 1 1 1 0 \n1 1 1 0 0 ", "1 1 1 1 1 \n1 1 1 1 1 \n1 1 1 1 1 \n1 1 1 1 0 \n1 1 1 0 1 ", "1 1 1 1 1 \n1 1 1 1 1 \n1 1 1 1 1 \n1 1 1 1 1 \n1 1 1 1 0 ", "1 1 1 1 1 \n1 1 1 1 1 \n1 1 1 1 1 \n1 1 1 1 1 \n1 1 1 1 1 ", "-1", "0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0...", "1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0...", "1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0...", "1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0...", "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 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0...", "1 1 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 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0...", "1 1 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 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0...", "1 1 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 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 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 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 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 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 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 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 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 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
99
codeforces
8e4411543e2b85f1a8bb736483bfdbcb
Beautiful Divisors
Recently Luba learned about a special kind of numbers that she calls beautiful numbers. The number is called beautiful iff its binary representation consists of *k*<=+<=1 consecutive ones, and then *k* consecutive zeroes. Some examples of beautiful numbers: - 12 (110); - 1102 (610); - 11110002 (12010); - 1111100002 (49610). More formally, the number is beautiful iff there exists some positive integer *k* such that the number is equal to (2*k*<=-<=1)<=*<=(2*k*<=-<=1). Luba has got an integer number *n*, and she wants to find its greatest beautiful divisor. Help her to find it! The only line of input contains one number *n* (1<=≤<=*n*<=≤<=105) — the number Luba has got. Output one number — the greatest beautiful divisor of Luba's number. It is obvious that the answer always exists. Sample Input 3 992 Sample Output 1 496
{"inputs": ["3", "992", "81142", "76920", "2016", "1", "6", "32640", "12096", "55948", "47262", "22876", "96120", "42160", "38304", "89408", "97920", "55493", "38021", "21445", "100000", "497", "240", "21204", "65536", "364", "1024", "36", "28", "14400", "10080", "9", "2", "42", "83160", "65534", "1026", "1025", "1027", "2018", "2020", "123", "150", "5", "66", "12768", "156", "99990", "248"], "outputs": ["1", "496", "1", "120", "2016", "1", "6", "32640", "2016", "1", "6", "28", "120", "496", "2016", "8128", "32640", "1", "1", "1", "1", "1", "120", "6", "1", "28", "1", "6", "28", "120", "2016", "1", "1", "6", "120", "1", "6", "1", "1", "1", "1", "1", "6", "1", "6", "28", "6", "6", "1"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
83
codeforces
8e47b70b8fb09fa94b3f2521cab6ba43
Longest Regular Bracket Sequence
This is yet another problem dealing with regular bracket sequences. We should remind you that a bracket sequence is called regular, if by inserting «+» and «1» into it we can get a correct mathematical expression. For example, sequences «(())()», «()» and «(()(()))» are regular, while «)(», «(()» and «(()))(» are not. You are given a string of «(» and «)» characters. You are to find its longest substring that is a regular bracket sequence. You are to find the number of such substrings as well. The first line of the input file contains a non-empty string, consisting of «(» and «)» characters. Its length does not exceed 106. Print the length of the longest substring that is a regular bracket sequence, and the number of such substrings. If there are no such substrings, write the only line containing "0 1". Sample Input )((())))(()()) ))( Sample Output 6 2 0 1
{"inputs": [")((())))(()())", "))(", "()(())()", "((((()(((", "))))()())))", "(()())()(())()()())())()((()(()(())()()())((()(())()(()()()()))()(())()(((()())()(()((())()(())(()))", ")(()(((((())))))(((()))))))((()(((((((())())()))))((((((((())))((((((())))))(()((((()))))(()))))))))", "())(((((())())((((()))(())))())())(((()(()()()())(())()))((()(())())()()))()(()())))))(()))((())((((", "))(((((((()((((())(((((((((()()))))(()())()((())())))((((()))(()()()))))(()()))())))))((())())()))(("], "outputs": ["6 2", "0 1", "8 1", "2 1", "4 1", "28 1", "68 1", "80 1", "92 1"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
149
codeforces
8e4c196a1d858d4cb674277d1f33267d
Bit++
The classic programming language of Bitland is Bit++. This language is so peculiar and complicated. The language is that peculiar as it has exactly one variable, called *x*. Also, there are two operations: - Operation ++ increases the value of variable *x* by 1. - Operation -- decreases the value of variable *x* by 1. A statement in language Bit++ is a sequence, consisting of exactly one operation and one variable *x*. The statement is written without spaces, that is, it can only contain characters "+", "-", "X". Executing a statement means applying the operation it contains. A programme in Bit++ is a sequence of statements, each of them needs to be executed. Executing a programme means executing all the statements it contains. You're given a programme in language Bit++. The initial value of *x* is 0. Execute the programme and find its final value (the value of the variable when this programme is executed). The first line contains a single integer *n* (1<=≤<=*n*<=≤<=150) — the number of statements in the programme. Next *n* lines contain a statement each. Each statement contains exactly one operation (++ or --) and exactly one variable *x* (denoted as letter «X»). Thus, there are no empty statements. The operation and the variable can be written in any order. Print a single integer — the final value of *x*. Sample Input 1 ++X 2 X++ --X Sample Output 1 0
{"inputs": ["1\n++X", "2\nX++\n--X", "3\n++X\n++X\n++X", "2\n--X\n--X", "5\n++X\n--X\n++X\n--X\n--X", "28\nX--\n++X\nX++\nX++\nX++\n--X\n--X\nX++\nX--\n++X\nX++\n--X\nX--\nX++\nX--\n++X\n++X\nX++\nX++\nX++\nX++\n--X\n++X\n--X\n--X\n--X\n--X\nX++", "94\nX++\nX++\n++X\n++X\nX--\n--X\nX++\n--X\nX++\n++X\nX++\n++X\n--X\n--X\n++X\nX++\n--X\nX--\nX--\n--X\nX--\nX--\n--X\n++X\n--X\nX--\nX--\nX++\n++X\n--X\nX--\n++X\n--X\n--X\nX--\nX--\nX++\nX++\nX--\nX++\nX--\nX--\nX--\n--X\nX--\nX--\nX--\nX++\n++X\nX--\n++X\nX++\n--X\n--X\n--X\n--X\n++X\nX--\n--X\n--X\n++X\nX--\nX--\nX++\n++X\nX++\n++X\n--X\n--X\nX--\n++X\nX--\nX--\n++X\n++X\n++X\n++X\nX++\n++X\n--X\nX++\n--X\n--X\n++X\n--X\nX++\n++X\nX++\n--X\nX--\nX--\n--X\n++X\nX++", "56\n--X\nX--\n--X\n--X\nX--\nX--\n--X\nX++\n++X\n--X\nX++\nX--\n--X\n++X\n--X\nX--\nX--\n++X\nX--\nX--\n--X\n++X\n--X\n++X\n--X\nX++\n++X\nX++\n--X\n++X\nX++\nX++\n--X\nX++\nX--\n--X\nX--\n--X\nX++\n++X\n--X\n++X\nX++\nX--\n--X\n--X\n++X\nX--\nX--\n--X\nX--\n--X\nX++\n--X\n++X\n--X", "59\nX--\n--X\nX++\n++X\nX--\n--X\n--X\n++X\n++X\n++X\n++X\nX++\n++X\n++X\nX++\n--X\nX--\nX++\n++X\n--X\nX++\n--X\n++X\nX++\n--X\n--X\nX++\nX++\n--X\nX++\nX++\nX++\nX--\nX--\n--X\nX++\nX--\nX--\n++X\nX--\nX++\n--X\nX++\nX--\nX--\nX--\nX--\n++X\n--X\nX++\nX++\nX--\nX++\n++X\nX--\nX++\nX--\nX--\n++X", "87\n--X\n++X\n--X\nX++\n--X\nX--\n--X\n++X\nX--\n++X\n--X\n--X\nX++\n--X\nX--\nX++\n++X\n--X\n++X\n++X\n--X\n++X\n--X\nX--\n++X\n++X\nX--\nX++\nX++\n--X\n--X\n++X\nX--\n--X\n++X\n--X\nX++\n--X\n--X\nX--\n++X\n++X\n--X\nX--\nX--\nX--\nX--\nX--\nX++\n--X\n++X\n--X\nX++\n++X\nX++\n++X\n--X\nX++\n++X\nX--\n--X\nX++\n++X\nX++\nX++\n--X\n--X\n++X\n--X\nX++\nX++\n++X\nX++\nX++\nX++\nX++\n--X\n--X\n--X\n--X\n--X\n--X\n--X\nX--\n--X\n++X\n++X", "101\nX++\nX++\nX++\n++X\n--X\nX--\nX++\nX--\nX--\n--X\n--X\n++X\nX++\n++X\n++X\nX--\n--X\n++X\nX++\nX--\n++X\n--X\n--X\n--X\n++X\n--X\n++X\nX++\nX++\n++X\n--X\nX++\nX--\nX++\n++X\n++X\nX--\nX--\nX--\nX++\nX++\nX--\nX--\nX++\n++X\n++X\n++X\n--X\n--X\n++X\nX--\nX--\n--X\n++X\nX--\n++X\nX++\n++X\nX--\nX--\n--X\n++X\n--X\n++X\n++X\n--X\nX++\n++X\nX--\n++X\nX--\n++X\nX++\nX--\n++X\nX++\n--X\nX++\nX++\n++X\n--X\n++X\n--X\nX++\n--X\nX--\n--X\n++X\n++X\n++X\n--X\nX--\nX--\nX--\nX--\n--X\n--X\n--X\n++X\n--X\n--X", "63\n--X\nX--\n++X\n--X\n++X\nX++\n--X\n--X\nX++\n--X\n--X\nX++\nX--\nX--\n--X\n++X\nX--\nX--\nX++\n++X\nX++\nX++\n--X\n--X\n++X\nX--\nX--\nX--\n++X\nX++\nX--\n--X\nX--\n++X\n++X\nX++\n++X\nX++\nX++\n--X\nX--\n++X\nX--\n--X\nX--\nX--\nX--\n++X\n++X\n++X\n++X\nX++\nX++\n++X\n--X\n--X\n++X\n++X\n++X\nX--\n++X\n++X\nX--", "45\n--X\n++X\nX--\n++X\n++X\nX++\n--X\n--X\n--X\n--X\n--X\n--X\n--X\nX++\n++X\nX--\n++X\n++X\nX--\nX++\nX--\n--X\nX--\n++X\n++X\n--X\n--X\nX--\nX--\n--X\n++X\nX--\n--X\n++X\n++X\n--X\n--X\nX--\n++X\n++X\nX++\nX++\n++X\n++X\nX++", "21\n++X\nX++\n--X\nX--\nX++\n++X\n--X\nX--\nX++\nX--\nX--\nX--\nX++\n++X\nX++\n++X\n--X\nX--\n--X\nX++\n++X", "100\n--X\n++X\nX++\n++X\nX--\n++X\nX--\nX++\n--X\nX++\nX--\nX--\nX--\n++X\nX--\nX++\nX++\n++X\nX++\nX++\nX++\nX++\n++X\nX++\n++X\nX--\n--X\n++X\nX--\n--X\n++X\n++X\nX--\nX++\nX++\nX++\n++X\n--X\n++X\nX++\nX--\n++X\n++X\n--X\n++X\nX--\nX--\nX--\nX++\nX--\nX--\nX++\nX++\n--X\nX++\nX++\n--X\nX--\n--X\n++X\n--X\n++X\n++X\nX--\n--X\n++X\n++X\n--X\n--X\n++X\nX++\nX--\nX++\nX--\nX++\nX++\n--X\nX--\nX--\n++X\nX--\n--X\n--X\nX++\n--X\n--X\nX--\nX--\n++X\n++X\nX--\n++X\nX++\n--X\n++X\n++X\nX++\n--X\n--X\nX++", "17\nX++\nX++\n++X\n--X\n--X\n++X\n++X\n--X\nX--\nX++\nX--\n--X\n--X\nX--\n++X\nX--\nX++", "77\n++X\nX++\n--X\nX--\n--X\n--X\nX--\nX++\nX--\nX++\nX--\n++X\n--X\n--X\n--X\n--X\n++X\nX--\nX++\nX--\n--X\nX--\n--X\nX--\n++X\n--X\n++X\n++X\nX++\nX++\nX--\n--X\nX--\nX--\nX++\n--X\n--X\n++X\nX--\nX--\n++X\nX++\nX--\n++X\n--X\nX++\nX--\n++X\n++X\n++X\nX--\nX--\nX--\n--X\n++X\n++X\n++X\nX++\n--X\n--X\n++X\n--X\nX--\nX++\n++X\nX++\n++X\nX--\nX++\nX++\n--X\nX++\nX++\nX++\n--X\nX++\nX--", "21\nX--\n++X\n--X\nX--\n++X\nX--\n++X\nX--\n--X\n++X\nX++\n++X\nX++\n++X\nX--\n--X\nX++\nX++\nX--\n++X\nX--", "1\nX--"], "outputs": ["1", "0", "3", "-2", "-1", "4", "-10", "-14", "3", "-5", "1", "1", "-3", "1", "8", "-1", "-5", "1", "-1"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
497
codeforces
8e50612d70a28d84b770df9166669c6b
The Monster
As Will is stuck in the Upside Down, he can still communicate with his mom, Joyce, through the Christmas lights (he can turn them on and off with his mind). He can't directly tell his mom where he is, because the monster that took him to the Upside Down will know and relocate him. Thus, he came up with a puzzle to tell his mom his coordinates. His coordinates are the answer to the following problem. A string consisting only of parentheses ('(' and ')') is called a bracket sequence. Some bracket sequence are called correct bracket sequences. More formally: - Empty string is a correct bracket sequence. - if *s* is a correct bracket sequence, then (*s*) is also a correct bracket sequence. - if *s* and *t* are correct bracket sequences, then *st* (concatenation of *s* and *t*) is also a correct bracket sequence. A string consisting of parentheses and question marks ('?') is called pretty if and only if there's a way to replace each question mark with either '(' or ')' such that the resulting string is a non-empty correct bracket sequence. Will gave his mom a string *s* consisting of parentheses and question marks (using Morse code through the lights) and his coordinates are the number of pairs of integers (*l*,<=*r*) such that 1<=≤<=*l*<=≤<=*r*<=≤<=|*s*| and the string *s**l**s**l*<=+<=1... *s**r* is pretty, where *s**i* is *i*-th character of *s*. Joyce doesn't know anything about bracket sequences, so she asked for your help. The first and only line of input contains string *s*, consisting only of characters '(', ')' and '?' (2<=≤<=|*s*|<=≤<=5000). Print the answer to Will's puzzle in the first and only line of output. Sample Input ((?)) ??()?? Sample Output 4 7
{"inputs": ["((?))", "??()??", "?????)(???", "()()((?(()(((()()(())(((()((())))(()))(()(((((())))()))(((()()()))))))(((((()))))))))", "))((()(()((((()))())()())((())())(((()()(())))))((())()()(()()(())()))()()(()()()(((()(()(()(()))))(", "????????????????????????????????????????????????????????????????????????????????????????????????????", ")(", "?(", "??", ")?(??((???????()?(?????????)??(????????((?)?????)????)??????(?????)?)?????)??????(??()??????)????????)?)()??????????????())????????(???)??)????????????????????(?????)??)???)??(???????????????)???)??)?", "()", "(?"], "outputs": ["4", "7", "21", "62", "88", "2500", "0", "0", "1", "8314", "1", "1"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
10
codeforces
8e64f356f5e4e4ae535eb42d9e1ea3df
Fancy Fence
Emuskald needs a fence around his farm, but he is too lazy to build it himself. So he purchased a fence-building robot. He wants the fence to be a regular polygon. The robot builds the fence along a single path, but it can only make fence corners at a single angle *a*. Will the robot be able to build the fence Emuskald wants? In other words, is there a regular polygon which angles are equal to *a*? The first line of input contains an integer *t* (0<=&lt;<=*t*<=&lt;<=180) — the number of tests. Each of the following *t* lines contains a single integer *a* (0<=&lt;<=*a*<=&lt;<=180) — the angle the robot can make corners at measured in degrees. For each test, output on a single line "YES" (without quotes), if the robot can build a fence Emuskald wants, and "NO" (without quotes), if it is impossible. Sample Input 3 30 60 90 Sample Output NO YES YES
{"inputs": ["3\n30\n60\n90", "6\n1\n2\n3\n170\n179\n25"], "outputs": ["NO\nYES\nYES", "NO\nNO\nNO\nYES\nYES\nNO"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
625
codeforces
8e719483e5e5418e54575f188ffb7458
Holes
Little Petya likes to play a lot. Most of all he likes to play a game «Holes». This is a game for one person with following rules: There are *N* holes located in a single row and numbered from left to right with numbers from 1 to *N*. Each hole has it's own power (hole number *i* has the power *a**i*). If you throw a ball into hole *i* it will immediately jump to hole *i*<=+<=*a**i*, then it will jump out of it and so on. If there is no hole with such number, the ball will just jump out of the row. On each of the *M* moves the player can perform one of two actions: - Set the power of the hole *a* to value *b*. - Throw a ball into the hole *a* and count the number of jumps of a ball before it jump out of the row and also write down the number of the hole from which it jumped out just before leaving the row. Petya is not good at math, so, as you have already guessed, you are to perform all computations. The first line contains two integers *N* and *M* (1<=≤<=*N*<=≤<=105, 1<=≤<=*M*<=≤<=105) — the number of holes in a row and the number of moves. The second line contains *N* positive integers not exceeding *N* — initial values of holes power. The following *M* lines describe moves made by Petya. Each of these line can be one of the two types: - 0 *a* *b* - 1 *a* For each move of the type 1 output two space-separated numbers on a separate line — the number of the last hole the ball visited before leaving the row and the number of jumps it made. Sample Input 8 5 1 1 1 1 1 2 8 2 1 1 0 1 3 1 1 0 3 4 1 2 Sample Output 8 7 8 5 7 3
{"inputs": ["8 5\n1 1 1 1 1 2 8 2\n1 1\n0 1 3\n1 1\n0 3 4\n1 2", "10 10\n5 1 2 4 1 7 3 8 10 8\n0 5 6\n1 8\n1 1\n0 10 3\n1 5\n1 3\n1 2\n0 6 1\n1 9\n1 1"], "outputs": ["8 7\n8 5\n7 3", "8 1\n6 2\n5 1\n5 2\n5 3\n9 1\n10 4"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
2
codeforces
8e83fc290467bbae2f2bbd15052cee39
Long number
Consider the following grammar: - &lt;expression&gt; ::= &lt;term&gt; | &lt;expression&gt; '+' &lt;term&gt;- &lt;term&gt; ::= &lt;number&gt; | &lt;number&gt; '-' &lt;number&gt; | &lt;number&gt; '(' &lt;expression&gt; ')'- &lt;number&gt; ::= &lt;pos_digit&gt; | &lt;number&gt; &lt;digit&gt;- &lt;digit&gt; ::= '0' | &lt;pos_digit&gt;- &lt;pos_digit&gt; ::= '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9' This grammar describes a number in decimal system using the following rules: - &lt;number&gt; describes itself,- &lt;number&gt;-&lt;number&gt; (l-r, *l*<=≤<=*r*) describes integer which is concatenation of all integers from *l* to *r*, written without leading zeros. For example, 8-11 describes 891011,- &lt;number&gt;(&lt;expression&gt;) describes integer which is concatenation of &lt;number&gt; copies of integer described by &lt;expression&gt;,- &lt;expression&gt;+&lt;term&gt; describes integer which is concatenation of integers described by &lt;expression&gt; and &lt;term&gt;. For example, 2(2-4+1)+2(2(17)) describes the integer 2341234117171717. You are given an expression in the given grammar. Print the integer described by it modulo 109<=+<=7. The only line contains a non-empty string at most 105 characters long which is valid according to the given grammar. In particular, it means that in terms l-r *l*<=≤<=*r* holds. Print single integer — the number described by the expression modulo 109<=+<=7. Sample Input 8-11 2(2-4+1)+2(2(17)) 1234-5678 1+2+3+4-5+6+7-9 Sample Output 891011 100783079 745428774 123456789
{"inputs": ["8-11", "2(2-4+1)+2(2(17))", "1234-5678", "1+2+3+4-5+6+7-9", "598777", "49603501749575096738857", "11-57", "7177-57797", "4510812433666-7741104736713", "4778066503(27032-80044+16+51+58(9)+5668114736297420472+2336+6-117+8495(7265))", "9678329648012859556810940272201-70370609657815505164700664074744+28870231062776633852(2098997519485)", "52(6(1)+100000000(2-10))+777(40000000(7-20)+876543)", "1(1000000005(5)+4)", "1-1", "10-10", "1+2", "9", "1(1)+1(1)"], "outputs": ["891011", "100783079", "745428774", "123456789", "598777", "586922407", "486296559", "110843609", "665706430", "865860620", "219564419", "133241273", "1000000006", "1", "10", "12", "9", "11"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1
codeforces
8e884a3f9a82d8283675daa517424cea
Buying A House
Zane the wizard had never loved anyone before, until he fell in love with a girl, whose name remains unknown to us. The girl lives in house *m* of a village. There are *n* houses in that village, lining in a straight line from left to right: house 1, house 2, ..., house *n*. The village is also well-structured: house *i* and house *i*<=+<=1 (1<=≤<=*i*<=&lt;<=*n*) are exactly 10 meters away. In this village, some houses are occupied, and some are not. Indeed, unoccupied houses can be purchased. You will be given *n* integers *a*1,<=*a*2,<=...,<=*a**n* that denote the availability and the prices of the houses. If house *i* is occupied, and therefore cannot be bought, then *a**i* equals 0. Otherwise, house *i* can be bought, and *a**i* represents the money required to buy it, in dollars. As Zane has only *k* dollars to spare, it becomes a challenge for him to choose the house to purchase, so that he could live as near as possible to his crush. Help Zane determine the minimum distance from his crush's house to some house he can afford, to help him succeed in his love. The first line contains three integers *n*, *m*, and *k* (2<=≤<=*n*<=≤<=100, 1<=≤<=*m*<=≤<=*n*, 1<=≤<=*k*<=≤<=100) — the number of houses in the village, the house where the girl lives, and the amount of money Zane has (in dollars), respectively. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=100) — denoting the availability and the prices of the houses. It is guaranteed that *a**m*<==<=0 and that it is possible to purchase some house with no more than *k* dollars. Print one integer — the minimum distance, in meters, from the house where the girl Zane likes lives to the house Zane can buy. Sample Input 5 1 20 0 27 32 21 19 7 3 50 62 0 0 0 99 33 22 10 5 100 1 0 1 0 0 0 0 0 1 1 Sample Output 403020
{"inputs": ["5 1 20\n0 27 32 21 19", "7 3 50\n62 0 0 0 99 33 22", "10 5 100\n1 0 1 0 0 0 0 0 1 1", "5 3 1\n1 1 0 0 1", "5 5 5\n1 0 5 6 0", "15 10 50\n20 0 49 50 50 50 50 50 50 0 50 50 49 0 20", "7 5 1\n0 100 2 2 0 2 1", "100 50 100\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 0 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100", "100 50 1\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 0 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100", "100 77 50\n50 100 49 51 0 50 100 49 51 0 50 100 49 51 0 50 100 49 51 0 50 100 49 51 0 50 100 49 51 0 50 100 49 51 0 50 100 49 51 0 50 100 49 51 0 50 100 49 51 0 50 100 49 51 0 50 100 49 51 0 50 100 49 51 0 50 100 49 51 0 50 100 49 51 0 50 0 49 51 0 50 100 49 51 0 50 100 49 51 0 50 100 49 51 0 50 100 49 51 0", "100 1 1\n0 98 97 96 95 94 93 92 91 90 89 88 87 86 85 84 83 82 81 80 79 78 77 76 75 74 73 72 71 70 69 68 67 66 65 64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0", "100 1 100\n0 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 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 10 99\n0 0 0 0 0 0 0 0 0 0 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 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 99 98", "7 4 5\n1 0 6 0 5 6 0", "7 4 5\n1 6 5 0 0 6 0", "100 42 59\n50 50 50 50 50 50 50 50 50 50 59 59 59 59 59 59 59 59 59 59 59 59 59 59 59 59 59 59 59 59 59 59 59 60 60 60 60 60 60 60 60 0 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 0", "2 1 100\n0 1", "2 2 100\n1 0", "10 1 88\n0 95 0 0 0 0 0 94 0 85", "10 2 14\n2 0 1 26 77 39 41 100 13 32", "10 3 11\n0 0 0 0 0 62 0 52 1 35", "20 12 44\n27 40 58 69 53 38 31 39 75 95 8 0 28 81 77 90 38 61 21 88", "30 29 10\n59 79 34 12 100 6 1 58 18 73 54 11 37 46 89 90 80 85 73 45 64 5 31 0 89 19 0 74 0 82", "40 22 1\n7 95 44 53 0 0 19 93 0 68 65 0 24 91 10 58 17 0 71 0 100 0 94 90 79 73 0 73 4 61 54 81 7 13 21 84 5 41 0 1", "40 22 99\n60 0 100 0 0 100 100 0 0 0 0 100 100 0 0 100 100 0 100 100 100 0 100 100 100 0 100 100 0 0 100 100 100 0 0 100 0 100 0 0", "50 10 82\n56 54 0 0 0 0 88 93 0 0 83 93 0 0 91 89 0 30 62 52 24 84 80 8 38 13 92 78 16 87 23 30 71 55 16 63 15 99 4 93 24 6 3 35 4 42 73 27 86 37", "63 49 22\n18 3 97 52 75 2 12 24 58 75 80 97 22 10 79 51 30 60 68 99 75 2 35 3 97 88 9 7 18 5 0 0 0 91 0 91 56 36 76 0 0 0 52 27 35 0 51 72 0 96 57 0 0 0 0 92 55 28 0 30 0 78 77", "74 38 51\n53 36 55 42 64 5 87 9 0 16 86 78 9 22 19 1 25 72 1 0 0 0 79 0 0 0 77 58 70 0 0 100 64 0 99 59 0 0 0 0 65 74 0 96 0 58 89 93 61 88 0 0 82 89 0 0 49 24 7 77 89 87 94 61 100 31 93 70 39 49 39 14 20 84", "89 22 11\n36 0 68 89 0 85 72 0 38 56 0 44 0 94 0 28 71 0 0 18 0 0 0 89 0 0 0 75 0 0 0 32 66 0 0 0 0 0 0 48 63 0 64 58 0 23 48 0 0 52 93 61 57 0 18 0 0 34 62 17 0 41 0 0 53 59 44 0 0 51 40 0 0 100 100 54 0 88 0 5 45 56 57 67 24 16 88 86 15", "97 44 100\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 51 19", "100 1 1\n0 0 0 0 10 54 84 6 17 94 65 82 34 0 61 46 42 0 2 16 56 0 100 0 82 0 0 0 89 78 96 56 0 0 0 0 0 0 0 0 77 70 0 96 67 0 0 32 44 1 72 50 14 11 24 61 100 64 19 5 67 69 44 82 93 22 67 93 22 61 53 64 79 41 84 48 43 97 7 24 8 49 23 16 72 52 97 29 69 47 29 49 64 91 4 73 17 18 51 67", "100 1 50\n0 0 0 60 0 0 54 0 80 0 0 0 97 0 68 97 84 0 0 93 0 0 0 0 68 0 0 62 0 0 55 68 65 87 0 69 0 0 0 0 0 52 61 100 0 71 0 82 88 78 0 81 0 95 0 57 0 67 0 0 0 55 86 0 60 72 0 0 73 0 83 0 0 60 64 0 56 0 0 77 84 0 58 63 84 0 0 67 0 16 3 88 0 98 31 52 40 35 85 23", "100 1 100\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 91 70 14", "100 1 29\n0 0 0 0 64 0 89 97 0 0 0 59 0 67 62 0 59 0 0 80 0 0 0 0 0 97 0 57 0 64 32 0 44 0 0 48 0 47 38 0 42 0 0 0 0 0 0 46 74 0 86 33 33 0 44 0 79 0 0 0 0 91 59 0 59 65 55 0 0 58 33 95 0 97 76 0 81 0 41 0 38 81 80 0 85 0 31 0 0 92 0 0 45 96 0 85 91 87 0 10", "100 50 20\n3 0 32 0 48 32 64 0 54 26 0 0 0 0 0 28 0 0 54 0 0 45 49 0 38 74 0 0 39 42 62 48 75 96 89 42 0 44 0 0 30 21 76 0 50 0 79 0 0 0 0 99 0 84 62 0 0 0 0 53 80 0 28 0 0 53 0 0 38 0 62 0 0 62 0 0 88 0 44 32 0 81 35 45 49 0 69 73 38 27 72 0 96 72 69 0 0 22 76 10", "100 50 20\n49 0 56 0 87 25 40 0 50 0 0 97 0 0 36 29 0 0 0 0 0 73 29 71 44 0 0 0 91 92 69 0 0 60 81 49 48 38 0 87 0 82 0 32 0 82 46 39 0 0 29 0 0 29 0 79 47 0 0 0 0 0 49 0 24 33 70 0 63 45 97 90 0 0 29 53 55 0 84 0 0 100 26 0 88 0 0 0 0 81 70 0 30 80 0 75 59 98 0 2", "100 2 2\n0 0 43 90 47 5 2 97 52 69 21 48 64 10 34 97 97 74 8 19 68 56 55 24 47 38 43 73 72 72 60 60 51 36 33 44 100 45 13 54 72 52 0 15 3 6 50 8 88 4 78 26 40 27 30 63 67 83 61 91 33 97 54 20 92 27 89 35 10 7 84 50 11 95 74 88 24 44 74 100 18 56 34 91 41 34 51 51 11 91 89 54 19 100 83 89 10 17 76 20", "100 100 34\n5 73 0 0 44 0 0 0 79 55 0 0 0 0 0 0 0 0 83 67 75 0 0 0 0 59 0 74 0 0 47 98 0 0 72 41 0 55 87 0 0 78 84 0 0 39 0 79 72 95 0 0 0 0 0 85 53 84 0 0 0 0 37 75 0 66 0 0 0 0 61 0 70 0 37 60 42 78 92 52 0 0 0 55 77 57 0 63 37 0 0 0 96 70 0 94 97 0 0 0", "100 100 100\n43 79 21 87 84 14 28 69 92 16 3 71 79 37 48 37 72 58 12 72 62 49 37 17 60 54 41 99 15 72 40 89 76 1 99 87 14 56 63 48 69 37 96 64 7 14 1 73 85 33 98 70 97 71 96 28 49 71 56 2 67 22 100 2 98 100 62 77 92 76 98 98 47 26 22 47 50 56 9 16 72 47 5 62 29 78 81 1 0 63 32 65 87 3 40 53 8 80 93 0", "100 38 1\n3 59 12 81 33 95 0 41 36 17 63 76 42 77 85 56 3 96 55 41 24 87 18 9 0 37 0 61 69 0 0 0 67 0 0 0 0 0 0 18 0 0 47 56 74 0 0 80 0 42 0 1 60 59 62 9 19 87 92 48 58 30 98 51 99 10 42 94 51 53 50 89 24 5 52 82 50 39 98 8 95 4 57 21 10 0 44 32 19 14 64 34 79 76 17 3 15 22 71 51", "100 72 1\n56 98 8 27 9 23 16 76 56 1 34 43 96 73 75 49 62 20 18 23 51 55 30 84 4 20 89 40 75 16 69 35 1 0 16 0 80 0 41 17 0 0 76 23 0 92 0 34 0 91 82 54 0 0 0 63 85 59 98 24 29 0 8 77 26 0 34 95 39 0 0 0 74 0 0 0 0 12 0 92 0 0 55 95 66 30 0 0 29 98 0 0 0 47 0 0 80 0 0 4", "100 66 1\n38 50 64 91 37 44 74 21 14 41 80 90 26 51 78 85 80 86 44 14 49 75 93 48 78 89 23 72 35 22 14 48 100 71 62 22 7 95 80 66 32 20 17 47 79 30 41 52 15 62 67 71 1 6 0 9 0 0 0 11 0 0 24 0 31 0 77 0 51 0 0 0 0 0 0 77 0 36 44 19 90 45 6 25 100 87 93 30 4 97 36 88 33 50 26 71 97 71 51 68", "100 55 1\n0 33 45 83 56 96 58 24 45 30 38 60 39 69 21 87 59 21 72 73 27 46 61 61 11 97 77 5 39 3 3 35 76 37 53 84 24 75 9 48 31 90 100 84 74 81 83 83 42 23 29 94 18 1 0 53 52 99 86 37 94 54 28 75 28 80 17 14 98 68 76 20 32 23 42 31 57 79 60 14 18 27 1 98 32 3 96 25 15 38 2 6 3 28 59 54 63 2 43 59", "100 55 1\n24 52 41 6 55 11 58 25 63 12 70 39 23 28 72 17 96 85 7 84 21 13 34 37 97 43 36 32 15 30 58 5 14 71 40 70 9 92 44 73 31 58 96 90 19 35 29 91 25 36 48 95 61 78 0 1 99 61 81 88 42 53 61 57 42 55 74 45 41 92 99 30 20 25 89 50 37 4 17 24 6 65 15 44 40 2 38 43 7 90 38 59 75 87 96 28 12 67 24 32", "100 21 1\n62 5 97 80 81 28 83 0 26 0 0 0 0 23 0 0 90 0 0 0 0 0 0 0 0 54 71 8 0 0 42 0 73 0 17 0 1 31 71 78 58 72 84 39 54 59 13 29 16 41 71 35 88 55 70 50 33 100 100 60 52 90 7 66 44 55 51 42 90 17 86 44 46 8 52 74 8 22 2 92 34 37 58 98 70 74 19 91 74 25 4 38 71 68 50 68 63 14 60 98", "5 2 20\n27 0 32 21 19", "6 4 10\n10 0 0 0 0 10", "8 7 100\n1 0 0 0 0 0 0 1", "5 3 20\n1 21 0 0 1", "4 3 1\n0 0 0 1", "5 2 3\n4 0 5 6 1", "5 3 87\n88 89 0 1 90", "5 3 20\n15 30 0 15 35", "6 3 50\n0 0 0 1 2 0", "6 4 9\n100 9 10 0 0 9", "5 4 20\n0 20 0 0 20", "6 3 3\n1 5 0 2 2 0", "5 4 100\n0 1 0 0 1"], "outputs": ["40", "30", "20", "10", "20", "10", "20", "10", "490", "10", "980", "10", "890", "10", "10", "90", "10", "10", "90", "10", "60", "10", "70", "180", "210", "80", "190", "190", "580", "520", "490", "890", "970", "990", "490", "500", "50", "990", "10", "140", "390", "130", "10", "10", "160", "30", "20", "10", "20", "10", "30", "10", "10", "10", "20", "10", "10", "10"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
329
codeforces
8e997023d723a3471ac07fd67fc26280
Gargari and Permutations
Gargari got bored to play with the bishops and now, after solving the problem about them, he is trying to do math homework. In a math book he have found *k* permutations. Each of them consists of numbers 1,<=2,<=...,<=*n* in some order. Now he should find the length of the longest common subsequence of these permutations. Can you help Gargari? You can read about longest common subsequence there: https://en.wikipedia.org/wiki/Longest_common_subsequence_problem The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=1000; 2<=≤<=*k*<=≤<=5). Each of the next *k* lines contains integers 1,<=2,<=...,<=*n* in some order — description of the current permutation. Print the length of the longest common subsequence. Sample Input 4 3 1 4 2 3 4 1 2 3 1 2 4 3 Sample Output 3
{"inputs": ["4 3\n1 4 2 3\n4 1 2 3\n1 2 4 3", "6 3\n2 5 1 4 6 3\n5 1 4 3 2 6\n5 4 2 6 3 1", "41 4\n24 15 17 35 13 41 4 14 23 5 8 16 21 18 30 36 6 22 11 29 26 1 40 31 7 3 32 10 28 38 12 20 39 37 34 19 33 27 2 25 9\n22 13 25 24 38 35 29 12 15 8 11 37 3 19 4 23 18 32 30 40 36 21 16 34 27 9 5 41 39 2 14 17 31 33 26 7 1 10 20 6 28\n31 27 39 16 22 12 13 32 6 10 19 29 37 7 18 33 24 21 1 9 36 4 34 41 25 28 17 40 30 35 23 14 11 8 2 15 38 20 26 5 3\n8 18 39 38 7 34 16 31 15 1 40 20 37 4 25 11 17 19 33 26 6 14 13 41 12 32 2 21 10 35 27 9 28 5 30 24 22 23 29 3 36", "1 2\n1\n1", "28 5\n3 14 12 16 13 27 20 8 1 10 24 11 5 9 7 18 17 23 22 25 28 19 4 21 26 6 15 2\n7 12 23 27 22 26 16 18 19 5 6 9 11 28 25 4 10 3 1 14 8 17 15 2 20 13 24 21\n21 20 2 5 19 15 12 4 18 9 23 16 11 14 8 6 25 27 13 17 10 26 7 24 28 1 3 22\n12 2 23 11 20 18 25 21 13 27 14 8 4 6 9 16 7 3 10 1 22 15 26 19 5 17 28 24\n13 2 6 19 22 23 4 1 28 10 18 17 21 8 9 3 26 11 12 27 14 20 24 25 15 5 16 7", "6 3\n2 5 1 4 6 3\n5 1 4 6 2 3\n5 4 2 6 3 1", "41 4\n24 15 17 35 13 41 4 14 23 5 8 16 21 18 30 36 6 22 11 29 26 1 40 31 7 3 32 10 28 38 12 20 39 37 34 19 33 27 2 25 9\n22 13 25 24 38 35 29 12 15 8 11 37 3 19 4 23 18 32 30 40 36 21 16 34 27 9 5 41 39 2 14 17 31 33 26 7 1 10 20 6 28\n31 27 39 16 22 12 13 32 6 10 19 29 37 7 18 33 24 21 1 9 36 4 34 41 25 28 17 40 30 35 23 14 11 8 2 15 38 20 26 5 3\n8 18 39 38 7 34 16 31 15 1 40 20 37 4 25 11 17 19 33 26 6 14 13 41 12 32 2 21 10 35 27 9 28 5 30 24 22 23 29 3 36", "37 3\n6 3 19 20 15 4 1 35 8 24 12 21 34 26 18 14 23 33 28 9 36 11 37 31 25 32 29 22 13 27 16 17 10 7 5 30 2\n10 3 35 17 34 21 14 8 26 28 11 19 27 7 4 23 24 22 12 13 16 1 25 29 5 31 30 20 32 18 15 9 2 36 37 33 6\n19 9 22 32 26 35 29 23 5 6 14 34 33 10 2 28 15 11 24 4 13 7 8 31 37 36 1 27 3 16 30 25 20 21 18 17 12"], "outputs": ["3", "3", "4", "1", "3", "4", "4", "7"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
9
codeforces
8ea2947adf1fbbc23b60a162d770b3ba
Alyona and flowers
Little Alyona is celebrating Happy Birthday! Her mother has an array of *n* flowers. Each flower has some mood, the mood of *i*-th flower is *a**i*. The mood can be positive, zero or negative. Let's define a subarray as a segment of consecutive flowers. The mother suggested some set of subarrays. Alyona wants to choose several of the subarrays suggested by her mother. After that, each of the flowers will add to the girl's happiness its mood multiplied by the number of chosen subarrays the flower is in. For example, consider the case when the mother has 5 flowers, and their moods are equal to 1,<=<=-<=2,<=1,<=3,<=<=-<=4. Suppose the mother suggested subarrays (1,<=<=-<=2), (3,<=<=-<=4), (1,<=3), (1,<=<=-<=2,<=1,<=3). Then if the girl chooses the third and the fourth subarrays then: - the first flower adds 1·1<==<=1 to the girl's happiness, because he is in one of chosen subarrays, - the second flower adds (<=-<=2)·1<==<=<=-<=2, because he is in one of chosen subarrays, - the third flower adds 1·2<==<=2, because he is in two of chosen subarrays, - the fourth flower adds 3·2<==<=6, because he is in two of chosen subarrays, - the fifth flower adds (<=-<=4)·0<==<=0, because he is in no chosen subarrays. Thus, in total 1<=+<=(<=-<=2)<=+<=2<=+<=6<=+<=0<==<=7 is added to the girl's happiness. Alyona wants to choose such subarrays from those suggested by the mother that the value added to her happiness would be as large as possible. Help her do this! Alyona can choose any number of the subarrays, even 0 or all suggested by her mother. The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the number of flowers and the number of subarrays suggested by the mother. The second line contains the flowers moods — *n* integers *a*1,<=*a*2,<=...,<=*a**n* (<=-<=100<=≤<=*a**i*<=≤<=100). The next *m* lines contain the description of the subarrays suggested by the mother. The *i*-th of these lines contain two integers *l**i* and *r**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=*n*) denoting the subarray *a*[*l**i*],<=*a*[*l**i*<=+<=1],<=...,<=*a*[*r**i*]. Each subarray can encounter more than once. Print single integer — the maximum possible value added to the Alyona's happiness. Sample Input 5 4 1 -2 1 3 -4 1 2 4 5 3 4 1 4 4 3 1 2 3 4 1 3 2 4 1 1 2 2 -1 -2 1 1 1 2 Sample Output 7 16 0
{"inputs": ["5 4\n1 -2 1 3 -4\n1 2\n4 5\n3 4\n1 4", "4 3\n1 2 3 4\n1 3\n2 4\n1 1", "2 2\n-1 -2\n1 1\n1 2", "5 6\n1 1 1 -1 0\n2 4\n1 3\n4 5\n1 5\n1 4\n4 5", "8 3\n5 -4 -2 5 3 -4 -2 6\n3 8\n4 6\n2 3", "10 10\n0 0 0 0 0 0 0 0 0 0\n5 9\n1 9\n5 7\n3 8\n1 6\n1 9\n1 6\n6 9\n1 10\n3 8", "3 6\n0 0 0\n1 1\n1 1\n1 3\n3 3\n2 3\n1 2", "3 3\n1 -1 3\n1 2\n2 3\n1 3", "6 8\n0 6 -5 8 -3 -2\n6 6\n2 3\n5 6\n4 6\n3 4\n2 5\n3 3\n5 6", "10 4\n6 5 5 -1 0 5 0 -3 5 -4\n3 6\n4 9\n1 6\n1 4", "9 1\n-1 -1 -1 -1 2 -1 2 0 0\n2 5", "3 8\n3 4 4\n1 2\n1 3\n2 3\n1 2\n2 2\n1 1\n2 3\n1 3", "3 8\n6 7 -1\n1 1\n1 3\n2 2\n1 3\n1 3\n1 1\n2 3\n2 3", "53 7\n-43 57 92 97 85 -29 28 -8 -37 -47 51 -53 -95 -50 -39 -87 43 36 60 -95 93 8 67 -22 -78 -46 99 93 27 -72 -84 77 96 -47 1 -12 21 -98 -34 -88 57 -43 5 -15 20 -66 61 -29 30 -85 52 53 82\n15 26\n34 43\n37 41\n22 34\n19 43\n2 15\n13 35", "20 42\n61 86 5 -87 -33 51 -79 17 -3 65 -42 74 -94 40 -35 22 58 81 -75 5\n3 6\n12 13\n3 16\n3 16\n5 7\n5 16\n2 15\n6 18\n4 18\n10 17\n14 16\n4 15\n4 11\n13 20\n5 6\n5 15\n16 17\n3 14\n9 10\n5 19\n5 14\n2 4\n17 20\n10 11\n5 18\n10 11\n1 14\n1 6\n1 10\n8 16\n11 14\n12 20\n11 13\n4 5\n2 13\n1 5\n11 15\n1 18\n3 8\n8 20\n1 4\n10 13", "64 19\n-47 13 19 51 -25 72 38 32 54 7 -49 -50 -59 73 45 -87 -15 -72 -32 -10 -7 47 -34 35 48 -73 79 25 -80 -34 4 77 60 30 61 -25 23 17 -73 -73 69 29 -50 -55 53 15 -33 7 -46 -5 85 -86 77 -51 87 -69 -64 -24 -64 29 -20 -58 11 -26\n6 53\n13 28\n15 47\n20 52\n12 22\n6 49\n31 54\n2 39\n32 49\n27 64\n22 63\n33 48\n49 58\n39 47\n6 29\n21 44\n24 59\n20 24\n39 54", "1 10\n-46\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1", "10 7\n44 18 9 -22 -23 7 -25 -2 15 35\n6 8\n6 7\n3 3\n2 6\n9 10\n2 2\n1 5", "4 3\n10 -2 68 35\n4 4\n1 1\n1 3", "3 6\n27 -31 -81\n2 3\n2 3\n1 1\n1 2\n1 2\n2 2", "7 3\n-24 -12 16 -43 -30 31 16\n3 6\n3 4\n1 7", "10 7\n-33 -24 -86 -20 5 -91 38 -12 -90 -67\n7 8\n7 10\n4 7\n1 3\n6 10\n6 6\n3 5", "4 4\n95 35 96 -27\n3 4\n3 3\n4 4\n3 3", "7 7\n-33 26 -25 44 -20 -50 33\n4 6\n4 4\n3 7\n5 7\n1 4\n2 5\n4 6", "5 3\n-35 -39 93 59 -4\n2 2\n2 3\n2 5", "3 7\n0 0 0\n1 2\n1 2\n2 3\n3 3\n1 3\n1 2\n2 3", "8 2\n17 32 30 -6 -39 -15 33 74\n6 6\n8 8", "8 1\n-20 -15 21 -21 1 -12 -7 9\n4 7", "7 9\n-23 -4 -44 -47 -35 47 25\n1 6\n3 5\n4 7\n6 7\n2 4\n2 3\n2 7\n1 2\n5 5", "8 8\n0 6 -25 -15 29 -24 31 23\n2 8\n5 5\n3 3\n2 8\n6 6\n3 6\n3 4\n2 4", "4 3\n-39 -63 9 -16\n1 4\n1 3\n2 4", "9 1\n-3 -13 -13 -19 -4 -11 8 -11 -3\n9 9", "9 6\n25 18 -62 0 33 62 -23 4 -15\n7 9\n2 3\n1 4\n2 6\n1 6\n2 3", "4 5\n-12 39 8 -12\n1 4\n3 4\n1 3\n1 3\n2 3", "3 9\n-9 7 3\n1 2\n1 1\n1 3\n1 2\n2 3\n1 3\n2 2\n1 2\n3 3", "10 7\n0 4 3 3 -2 -2 -4 -2 -3 -2\n5 6\n1 10\n2 10\n7 10\n1 1\n6 7\n3 4", "86 30\n16 -12 11 16 8 14 7 -29 18 30 -32 -10 20 29 -14 -21 23 -19 -15 17 -2 25 -22 2 26 15 -7 -12 -4 -28 21 -4 -2 22 28 -32 9 -20 23 38 -21 21 37 -13 -30 25 31 6 18 29 29 29 27 38 -15 -32 32 -7 -8 -33 -11 24 23 -19 -36 -36 -18 9 -1 32 -34 -26 1 -1 -16 -14 17 -17 15 -24 38 5 -27 -12 8 -38\n60 66\n29 48\n32 51\n38 77\n17 79\n23 74\n39 50\n14 29\n26 76\n9 76\n2 67\n23 48\n17 68\n33 75\n59 78\n46 78\n9 69\n16 83\n18 21\n17 34\n24 61\n15 79\n4 31\n62 63\n46 76\n79 82\n25 39\n5 81\n19 77\n26 71", "33 17\n11 6 -19 14 23 -23 21 15 29 19 13 -18 -19 20 16 -10 26 -22 3 17 13 -10 19 22 -5 21 12 6 28 -13 -27 25 6\n4 17\n12 16\n9 17\n25 30\n31 32\n4 28\n11 24\n16 19\n3 27\n7 17\n1 16\n15 28\n30 33\n9 31\n14 30\n13 23\n27 27", "16 44\n32 23 -27 -2 -10 -42 32 -14 -13 4 9 -2 19 35 16 22\n6 12\n8 11\n13 15\n12 12\n3 10\n9 13\n7 15\n2 11\n1 13\n5 6\n9 14\n3 16\n10 13\n3 15\n6 10\n14 16\n4 5\n7 10\n5 14\n1 16\n2 5\n1 6\n9 10\n4 7\n4 12\n2 5\n7 10\n7 9\n2 8\n9 10\n4 10\n7 12\n10 11\n6 6\n15 15\n8 12\n9 10\n3 3\n4 15\n10 12\n7 16\n4 14\n14 16\n5 6", "63 24\n-23 -46 0 33 24 13 39 -6 -4 49 19 -18 -11 -38 0 -3 -33 -17 -4 -44 -22 -12 -16 42 16 -10 7 37 -6 16 -41 -18 -20 51 -49 28 -14 -22 -37 -7 -50 31 -41 -47 18 -8 -39 -29 35 -32 14 -29 44 -29 -19 -25 -47 -8 16 11 20 12 38\n21 61\n35 61\n29 61\n21 34\n12 48\n32 33\n9 27\n4 42\n4 60\n37 61\n19 44\n46 60\n51 53\n31 34\n23 32\n5 29\n43 59\n7 31\n29 48\n15 50\n19 51\n7 28\n17 41\n1 62", "6 51\n45 -33 -17 -48 2 2\n2 5\n1 1\n1 3\n5 5\n4 6\n1 2\n2 3\n3 4\n1 6\n4 6\n3 5\n1 5\n2 2\n2 6\n4 6\n1 5\n1 5\n1 5\n1 6\n6 6\n3 5\n6 6\n1 6\n3 4\n3 3\n2 4\n3 3\n1 4\n2 4\n5 6\n4 5\n2 4\n1 5\n1 2\n4 5\n1 5\n5 6\n2 2\n3 4\n1 3\n1 2\n2 5\n3 6\n4 6\n3 4\n2 4\n1 4\n1 1\n4 6\n3 5\n1 4", "3 5\n2 -1 3\n2 3\n2 3\n2 3\n2 3\n1 2", "4 30\n1 1 1 1\n1 4\n1 4\n1 4\n1 4\n1 4\n1 4\n1 4\n1 4\n1 4\n1 4\n1 4\n1 4\n1 4\n1 4\n1 4\n1 4\n1 4\n1 4\n1 4\n1 4\n1 4\n1 4\n1 4\n1 4\n1 4\n1 4\n1 4\n1 4\n1 4\n1 4"], "outputs": ["7", "16", "0", "8", "10", "0", "0", "5", "13", "50", "0", "59", "67", "170", "1502", "804", "0", "103", "121", "27", "0", "26", "261", "81", "163", "0", "74", "0", "72", "79", "0", "0", "127", "140", "22", "6", "3076", "1366", "777", "82", "140", "9", "120"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
209
codeforces
8ed90872b9454656dda60a242d493820
Ebony and Ivory
Dante is engaged in a fight with "The Savior". Before he can fight it with his sword, he needs to break its shields. He has two guns, Ebony and Ivory, each of them is able to perform any non-negative number of shots. For every bullet that hits the shield, Ebony deals *a* units of damage while Ivory deals *b* units of damage. In order to break the shield Dante has to deal exactly *c* units of damage. Find out if this is possible. The first line of the input contains three integers *a*, *b*, *c* (1<=≤<=*a*,<=*b*<=≤<=100,<=1<=≤<=*c*<=≤<=10<=000) — the number of units of damage dealt by Ebony gun and Ivory gun, and the total number of damage required to break the shield, respectively. Print "Yes" (without quotes) if Dante can deal exactly *c* damage to the shield and "No" (without quotes) otherwise. Sample Input 4 6 15 3 2 7 6 11 6 Sample Output No Yes Yes
{"inputs": ["4 6 15", "3 2 7", "6 11 6", "3 12 15", "5 5 10", "6 6 7", "1 1 20", "12 14 19", "15 12 26", "2 4 8", "4 5 30", "4 5 48", "2 17 105", "10 25 282", "6 34 323", "2 47 464", "4 53 113", "6 64 546", "1 78 725", "1 84 811", "3 100 441", "20 5 57", "14 19 143", "17 23 248", "11 34 383", "20 47 568", "16 58 410", "11 70 1199", "16 78 712", "20 84 562", "19 100 836", "23 10 58", "25 17 448", "22 24 866", "24 35 67", "29 47 264", "23 56 45", "25 66 1183", "21 71 657", "29 81 629", "23 95 2226", "32 4 62", "37 15 789", "39 24 999", "38 32 865", "32 50 205", "31 57 1362", "38 68 1870", "36 76 549", "35 84 1257", "39 92 2753", "44 1 287", "42 12 830", "42 27 9", "49 40 1422", "44 42 2005", "50 55 2479", "48 65 917", "45 78 152", "43 90 4096", "43 94 4316", "60 7 526", "53 11 735", "52 27 609", "57 32 992", "52 49 421", "57 52 2634", "54 67 3181", "52 73 638", "57 84 3470", "52 100 5582", "62 1 501", "63 17 858", "70 24 1784", "65 32 1391", "62 50 2775", "62 58 88", "66 68 3112", "61 71 1643", "69 81 3880", "63 100 1960", "73 6 431", "75 19 736", "78 25 247", "79 36 2854", "80 43 1864", "76 55 2196", "76 69 4122", "76 76 4905", "75 89 3056", "73 100 3111", "84 9 530", "82 18 633", "85 29 2533", "89 38 2879", "89 49 2200", "88 60 4140", "82 68 1299", "90 76 2207", "83 84 4923", "89 99 7969", "94 9 168", "91 20 1009", "93 23 2872", "97 31 3761", "99 46 1341", "98 51 2845", "93 66 3412", "95 76 3724", "91 87 6237", "98 97 7886", "12 17 15", "93 94 95", "27 43 27", "17 43 68", "44 12 12", "44 50 150", "1 1 10000", "2 3 10000", "100 1 10", "3 2 1", "1 1 1", "9 9 10000", "2 3 9995", "3 5 4", "99 98 100", "6 10 2", "1 6 5", "1 4 3", "3 2 3", "1 7 6", "2 3 9871", "10 5 5", "10 8 2"], "outputs": ["No", "Yes", "Yes", "Yes", "Yes", "No", "Yes", "No", "No", "Yes", "Yes", "Yes", "Yes", "No", "No", "Yes", "Yes", "Yes", "Yes", "Yes", "Yes", "No", "No", "No", "Yes", "Yes", "Yes", "Yes", "Yes", "No", "Yes", "No", "Yes", "Yes", "No", "Yes", "No", "Yes", "Yes", "No", "Yes", "No", "Yes", "Yes", "No", "No", "Yes", "Yes", "No", "No", "Yes", "Yes", "No", "No", "No", "No", "No", "No", "No", "Yes", "Yes", "Yes", "Yes", "Yes", "Yes", "No", "Yes", "Yes", "No", "No", "No", "Yes", "Yes", "Yes", "Yes", "No", "No", "Yes", "No", "No", "Yes", "Yes", "Yes", "No", "Yes", "Yes", "Yes", "Yes", "No", "Yes", "Yes", "No", "No", "Yes", "Yes", "Yes", "Yes", "No", "No", "Yes", "Yes", "No", "No", "Yes", "Yes", "Yes", "No", "No", "Yes", "Yes", "Yes", "No", "No", "Yes", "Yes", "Yes", "Yes", "Yes", "Yes", "Yes", "No", "Yes", "No", "Yes", "No", "No", "No", "Yes", "Yes", "Yes", "Yes", "Yes", "Yes", "No"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
192
codeforces
8f150d098d84cde9f7d73b00f0091443
none
Astronaut Natasha arrived on Mars. She knows that the Martians are very poor aliens. To ensure a better life for the Mars citizens, their emperor decided to take tax from every tourist who visited the planet. Natasha is the inhabitant of Earth, therefore she had to pay the tax to enter the territory of Mars. There are $n$ banknote denominations on Mars: the value of $i$-th banknote is $a_i$. Natasha has an infinite number of banknotes of each denomination. Martians have $k$ fingers on their hands, so they use a number system with base $k$. In addition, the Martians consider the digit $d$ (in the number system with base $k$) divine. Thus, if the last digit in Natasha's tax amount written in the number system with the base $k$ is $d$, the Martians will be happy. Unfortunately, Natasha does not know the Martians' divine digit yet. Determine for which values $d$ Natasha can make the Martians happy. Natasha can use only her banknotes. Martians don't give her change. The first line contains two integers $n$ and $k$ ($1 \le n \le 100\,000$, $2 \le k \le 100\,000$) — the number of denominations of banknotes and the base of the number system on Mars. The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^9$) — denominations of banknotes on Mars. All numbers are given in decimal notation. On the first line output the number of values $d$ for which Natasha can make the Martians happy. In the second line, output all these values in increasing order. Print all numbers in decimal notation. Sample Input 2 8 12 20 3 10 10 20 30 Sample Output 2 0 4 1 0
{"inputs": ["2 8\n12 20", "3 10\n10 20 30", "5 10\n20 16 4 16 2", "10 5\n4 6 8 6 4 10 2 10 8 6", "20 25\n15 10 5 20 10 5 15 5 15 10 15 5 5 5 5 10 15 20 20 20", "30 30\n11 23 7 30 13 6 25 29 1 15 20 5 28 15 19 22 21 5 27 25 29 10 1 4 12 19 1 5 8 10", "40 30\n16 12 12 22 18 28 32 24 36 26 12 30 22 16 32 30 36 18 20 16 12 24 28 20 16 28 8 34 18 18 18 4 4 36 18 10 30 38 18 10", "50 30\n15 9 21 39 42 39 3 42 42 39 6 48 39 30 12 39 27 45 30 48 18 33 18 36 27 3 48 12 36 27 15 12 42 39 18 21 48 39 15 42 24 36 33 48 6 48 15 12 30 18", "1 10\n1", "1 2\n1", "60 30\n10 30 45 15 25 60 10 40 35 25 5 40 35 40 15 5 15 35 10 60 25 15 60 10 30 10 5 25 10 15 60 20 30 5 50 50 40 20 55 40 35 15 15 10 60 40 50 50 30 15 25 45 35 40 15 5 5 20 60 45", "70 30\n54 30 12 48 42 24 42 60 54 6 36 42 54 66 12 48 54 42 24 54 30 18 30 54 18 60 24 30 54 48 48 60 18 60 60 66 54 18 54 30 24 30 60 54 36 36 60 48 12 60 6 60 42 66 6 42 18 60 54 48 42 18 48 66 18 42 48 30 12 66", "80 30\n30 80 40 40 60 60 40 80 70 80 30 30 60 80 30 70 60 10 10 30 70 60 70 20 40 20 30 10 60 70 70 50 60 70 70 30 70 60 60 70 20 60 10 60 70 80 20 30 30 20 60 50 40 40 80 70 70 20 40 80 30 50 40 10 40 20 70 10 80 10 50 40 50 70 40 80 10 40 60 60", "90 30\n90 45 75 75 90 90 45 30 90 15 45 90 15 30 45 60 30 15 30 45 45 45 45 15 45 60 15 60 45 75 45 75 90 60 30 15 60 30 90 75 15 60 15 30 45 30 45 15 30 15 45 30 15 75 90 15 45 15 75 15 75 30 75 45 60 75 15 45 30 75 45 90 45 60 90 45 75 30 30 30 15 15 75 60 75 90 75 60 90 45", "100 30\n30 30 30 90 30 30 90 90 30 90 30 90 90 30 30 30 60 60 60 30 30 60 90 90 90 60 30 90 60 60 90 60 60 60 30 60 60 60 60 90 60 30 60 90 90 90 60 60 90 60 60 60 60 30 30 60 30 60 60 90 30 60 60 60 90 60 90 30 30 60 30 90 90 90 90 60 90 30 30 60 60 30 60 60 60 30 90 60 60 60 90 60 30 90 60 30 30 60 90 90", "1 10\n2", "1 10\n3", "5 2\n1 1 1 1 1", "2 30\n6 10", "1 10\n10", "1 10\n20", "1 2\n1000000000", "2 6\n2 3", "1 5\n4", "2 5\n2 4", "3 30\n6 10 15", "2 7\n3 6", "2 15\n3 5", "2 12\n4 6", "2 10\n3 6", "2 100000\n2 4", "1 14\n4", "1 13\n5", "2 420\n412 363", "2 30\n10 6", "1 5\n3", "1 8\n6", "3 10\n6 6 6", "1 7\n6", "1 9\n6", "2 10\n7 7", "1 8\n5", "2 50\n3 15", "1 6\n4", "1 7\n4", "1 10\n7", "1 3\n2", "2 10\n2 5", "2 50\n15 3", "1 5\n2", "2 10\n6 5", "2 35\n5 7", "2 300\n3 10", "1 100000\n47", "2 54\n6 9"], "outputs": ["2\n0 4 ", "1\n0 ", "5\n0 2 4 6 8 ", "5\n0 1 2 3 4 ", "5\n0 5 10 15 20 ", "30\n0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 ", "15\n0 2 4 6 8 10 12 14 16 18 20 22 24 26 28 ", "10\n0 3 6 9 12 15 18 21 24 27 ", "10\n0 1 2 3 4 5 6 7 8 9 ", "2\n0 1 ", "6\n0 5 10 15 20 25 ", "5\n0 6 12 18 24 ", "3\n0 10 20 ", "2\n0 15 ", "1\n0 ", "5\n0 2 4 6 8 ", "10\n0 1 2 3 4 5 6 7 8 9 ", "2\n0 1 ", "15\n0 2 4 6 8 10 12 14 16 18 20 22 24 26 28 ", "1\n0 ", "1\n0 ", "1\n0 ", "6\n0 1 2 3 4 5 ", "5\n0 1 2 3 4 ", "5\n0 1 2 3 4 ", "30\n0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 ", "7\n0 1 2 3 4 5 6 ", "15\n0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 ", "6\n0 2 4 6 8 10 ", "10\n0 1 2 3 4 5 6 7 8 9 ", "50000\n0 2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 50 52 54 56 58 60 62 64 66 68 70 72 74 76 78 80 82 84 86 88 90 92 94 96 98 100 102 104 106 108 110 112 114 116 118 120 122 124 126 128 130 132 134 136 138 140 142 144 146 148 150 152 154 156 158 160 162 164 166 168 170 172 174 176 178 180 182 184 186 188 190 192 194 196 198 200 202 204 206 208 210 212 214 216 218 220 222 224 226 228 230 232 234 236 238 240 242 244 246 248 250 252 254 256 258 260 262 264 266 268 270 272 274 276 278...", "7\n0 2 4 6 8 10 12 ", "13\n0 1 2 3 4 5 6 7 8 9 10 11 12 ", "420\n0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 ...", "15\n0 2 4 6 8 10 12 14 16 18 20 22 24 26 28 ", "5\n0 1 2 3 4 ", "4\n0 2 4 6 ", "5\n0 2 4 6 8 ", "7\n0 1 2 3 4 5 6 ", "3\n0 3 6 ", "10\n0 1 2 3 4 5 6 7 8 9 ", "8\n0 1 2 3 4 5 6 7 ", "50\n0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 ", "3\n0 2 4 ", "7\n0 1 2 3 4 5 6 ", "10\n0 1 2 3 4 5 6 7 8 9 ", "3\n0 1 2 ", "10\n0 1 2 3 4 5 6 7 8 9 ", "50\n0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 ", "5\n0 1 2 3 4 ", "10\n0 1 2 3 4 5 6 7 8 9 ", "35\n0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 ", "300\n0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 ...", "100000\n0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 1...", "18\n0 3 6 9 12 15 18 21 24 27 30 33 36 39 42 45 48 51 "]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
35
codeforces
8f1d925cbfe50cd21d804490a288b86a
Memory and Scores
Memory and his friend Lexa are competing to get higher score in one popular computer game. Memory starts with score *a* and Lexa starts with score *b*. In a single turn, both Memory and Lexa get some integer in the range [<=-<=*k*;*k*] (i.e. one integer among <=-<=*k*,<=<=-<=*k*<=+<=1,<=<=-<=*k*<=+<=2,<=...,<=<=-<=2,<=<=-<=1,<=0,<=1,<=2,<=...,<=*k*<=-<=1,<=*k*) and add them to their current scores. The game has exactly *t* turns. Memory and Lexa, however, are not good at this game, so they both always get a random integer at their turn. Memory wonders how many possible games exist such that he ends with a strictly higher score than Lexa. Two games are considered to be different if in at least one turn at least one player gets different score. There are (2*k*<=+<=1)2*t* games in total. Since the answer can be very large, you should print it modulo 109<=+<=7. Please solve this problem for Memory. The first and only line of input contains the four integers *a*, *b*, *k*, and *t* (1<=≤<=*a*,<=*b*<=≤<=100, 1<=≤<=*k*<=≤<=1000, 1<=≤<=*t*<=≤<=100) — the amount Memory and Lexa start with, the number *k*, and the number of turns respectively. Print the number of possible games satisfying the conditions modulo 1<=000<=000<=007 (109<=+<=7) in one line. Sample Input 1 2 2 1 1 1 1 2 2 12 3 1 Sample Output 6 31 0
{"inputs": ["1 2 2 1", "1 1 1 2", "2 12 3 1", "4 6 2 1", "4 6 2 2", "6 4 2 2", "10 1 3 3", "5 3 1 1", "50 22 5 5", "6 20 1 1", "42 42 2 3", "42 42 3 2", "45 54 4 5", "6 5 4 3", "42 42 42 42", "1 100 42 42", "1 100 1000 100", "1 1 1000 100", "100 100 1000 100", "1 8 1 4", "9 4 5 2", "2 6 6 2", "7 8 5 9", "3 7 8 6", "69 69 803 81", "67 67 871 88", "71 71 891 31", "49 49 631 34", "83 83 770 49", "49 49 163 15", "38 38 701 74", "65 65 803 79", "56 56 725 64", "70 70 176 56", "32 32 44 79", "35 35 353 21", "57 57 896 52", "86 86 373 19", "27 27 296 97", "60 60 86 51", "40 40 955 95", "34 34 706 59", "74 74 791 51", "69 69 443 53", "59 19 370 48", "78 82 511 33", "66 90 805 16", "60 61 772 19", "81 13 607 21", "35 79 128 21", "93 25 958 20", "44 85 206 80", "79 99 506 18", "97 22 29 8", "14 47 184 49", "74 33 868 5", "53 79 823 11", "99 99 913 42", "52 34 89 41", "87 100 200 80", "40 94 510 53", "2 56 438 41", "6 68 958 41", "44 80 814 26", "100 1 1000 100", "1 3 1000 100", "10 10 1000 100"], "outputs": ["6", "31", "0", "3", "122", "435", "112812", "8", "876439301", "0", "6937", "1085", "433203628", "282051", "284470145", "58785421", "542673827", "922257788", "922257788", "1", "11045", "8015", "860378382", "510324293", "74925054", "123371511", "790044038", "764129060", "761730117", "458364105", "496603581", "253679300", "338598412", "990579000", "20803934", "149936279", "271910130", "940701970", "394599845", "277883413", "600387428", "274236101", "367968499", "385620893", "125206836", "375900871", "593436252", "931528755", "762608093", "177972209", "873170266", "170080402", "486170430", "471632954", "726421144", "826980486", "526626321", "446683872", "905639400", "913761305", "233079261", "500592304", "719351710", "414148151", "603336175", "604187087", "922257788"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
4
codeforces
8f5411ecdb281373c50db07fac8679e9
Lefthanders and Righthanders
One fine October day a mathematics teacher Vasily Petrov went to a class and saw there *n* pupils who sat at the desks, two people at each desk. Vasily quickly realized that number *n* is even. Like all true mathematicians, Vasily has all students numbered from 1 to *n*. But Vasily Petrov did not like the way the children were seated at the desks. According to him, the students whose numbers differ by 1, can not sit together, as they talk to each other all the time, distract others and misbehave. On the other hand, if a righthanded student sits at the left end of the desk and a lefthanded student sits at the right end of the desk, they hit elbows all the time and distract each other. In other cases, the students who sit at the same desk, do not interfere with each other. Vasily knows very well which students are lefthanders and which ones are righthanders, and he asks you to come up with any order that meets these two uncomplicated conditions (students do not talk to each other and do not bump their elbows). It is guaranteed that the input is such that at least one way to seat the students always exists. The first input line contains a single even integer *n* (4<=≤<=*n*<=≤<=100) — the number of students in the class. The second line contains exactly *n* capital English letters "L" and "R". If the *i*-th letter at the second line equals "L", then the student number *i* is a lefthander, otherwise he is a righthander. Print integer pairs, one pair per line. In the *i*-th line print the numbers of students that will sit at the *i*-th desk. The first number in the pair stands for the student who is sitting to the left, and the second number stands for the student who is sitting to the right. Separate the numbers in the pairs by spaces. If there are multiple solutions, print any of them. Sample Input 6 LLRLLL 4 RRLL Sample Output 1 4 2 5 6 3 3 1 4 2
{"inputs": ["6\nLLRLLL", "4\nRRLL", "4\nLLRR", "6\nRLLRRL", "8\nLRLRLLLR", "10\nRLLRLRRRLL", "12\nLRRRRRLRRRRL", "14\nRLLRLLLLRLLLRL", "16\nLLLRRRLRRLLRRLLL", "18\nRRRLLLLRRRLRLRLLRL", "20\nRLRLLRLRRLLRRRRRRLRL", "22\nRLLLRLLLRRLRRRLRLLLLLL", "24\nLRRRLRLLRLRRRRLLLLRRLRLR", "26\nRLRRLLRRLLRLRRLLRLLRRLRLRR", "28\nLLLRRRRRLRRLRRRLRLRLRRLRLRRL", "30\nLRLLRLRRLLRLRLLRRRRRLRLRLRLLLL", "32\nRLRLLRRLLRRLRLLRLRLRLLRLRRRLLRRR", "34\nLRRLRLRLLRRRRLLRLRRLRRLRLRRLRRRLLR", "36\nRRLLLRRRLLLRRLLLRRLLRLLRLRLLRLRLRLLL", "38\nLLRRRLLRRRLRRLRLRRLRRLRLRLLRRRRLLLLRLL", "40\nLRRRRRLRLLRRRLLRRLRLLRLRRLRRLLLRRLRRRLLL", "42\nRLRRLLLLLLLRRRLRLLLRRRLRLLLRLRLRLLLRLRLRRR", "44\nLLLLRRLLRRLLRRLRLLRRRLRLRLLRLRLRRLLRLRRLLLRR", "46\nRRRLLLLRRLRLRRRRRLRLLRLRRLRLLLLLLLLRRLRLRLRLLL", "48\nLLLLRRLRRRRLRRRLRLLLLLRRLLRLLRLLRRLRRLLRLRLRRRRL", "50\nRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR", "52\nLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL", "54\nRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR", "56\nLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL", "58\nRRRLLLRLLLLRRLRRRLLRLLRLRLLRLRRRRLLLLLLRLRRLRLRRRLRLRRLRRL", "60\nRLLLLRRLLRRRLLLLRRRRRLRRRLRRRLLLRLLLRLRRRLRLLLRLLRRLLRRRRRLL", "62\nLRRLRLRLLLLRRLLLLRRRLRLLLLRRRLLLLLLRRRLLLLRRLRRLRLLLLLLLLRRLRR", "64\nRLLLLRRRLRLLRRRRLRLLLRRRLLLRRRLLRLLRLRLRRRLLRRRRLRLRRRLLLLRRLLLL", "66\nLLRRRLLRLRLLRRRRRRRLLLLRRLLLLLLRLLLRLLLLLLRRRLRRLLRRRRRLRLLRLLLLRR", "68\nRRLRLRLLRLRLRRRRRRLRRRLLLLRLLRLRLRLRRRRLRLRLLRRRRLRRLLRLRRLLRLRRLRRL", "70\nRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR", "72\nRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR", "74\nRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR", "76\nRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR", "78\nRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR", "80\nLRLRRRRLRRRRLLLLRLLRLRLLRRLRLLLRRLLLLRLLLRLRLLRRRLRRRLRLRRRRRLRLLRLLRRLLLRLRRRLL", "82\nRLRRLLRLRLRLLLRLLLRRLLRRLRRRRLLRLLLLRRRRRLLLRRRLLLLRLRRLRRRLRLLLLRRRLRLRLLLRLLLLLR", "84\nLRLRRRRRRLLLRLRLLLLLRRLRLRLRRRLLRLLLRLRLLLRRRLRLRRLRLRLLLLLLLLRRRRRRLLLRRLRLRLLLRLRR", "86\nRRRLLLRLLRLLRLRLRLLLRLRLRRLLRLLLRLLLLLLRRRLRLLRLLLRRRLRLLLLRLLRLRRLLRLLLRRRLLRLRLLRLLR", "88\nLLRLRLRLLLLRRRRRRLRRLLLLLRRLRRLLLLLRLRLRLLLLLRLRLRRLRLRRLRLLRRLRLLLRLLLLRRLLRRLRLRLRRLRR", "90\nLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL", "92\nLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL", "94\nLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL", "96\nLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL", "98\nLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL", "100\nRLRRRRLLLLRRRRLRRRRRRRRLRLRRLLRRRRRRRRLRRRRLLLLRRRRLRRLRLRRRLLRRLRRLLLRLRRLLLLLLRLRLRLRRLRLRLRRRLLLR", "100\nLRLLLLRLLLLRRRRRLRRRRLRRLRRLRLLRRLRRRRLLRRRLLLRLLLRRRRLLRLRLRRLRLLRRLLRRLRRLRRRRRLRRLRLRLRLLLLLLLLRL", "100\nLLLRRLLRLRLLLRLLLRLRLLRRRLRRLLLRLRLRRLLRLRRRLLLRRLLRLLRRLLRRRRRLRLRRLRLRRLRLRRLLRLRLLRLLLRLLRLLLLRLL", "100\nRLLLLRRLLLLRRRRLLRLRRRLLLRLLRLLLLLRRLLLLLLRRLRRRRRLRLLRLRRRLLLRLRLRLLLRRRLLLLLRRRRRLRRLLLLRLLLRRLLLL", "100\nRLRRLRLRRLRLLRLLRRRLRRLLLLLRLRLRRRRRRRLLRRRLLRLRLLLRRRLLRRRLLRLRLLLLRRLRLLRLLRLLLLRRLRLRRLRLLLLRLRRR", "100\nLRRLRLRRRRRRLRRLRRLLLLLLRRLLRRLLRLLLLLLRRRLLRLRRRLLRLLRRLRRRLLRLRLLRRLRRRLLLRRRRLLRRRLLLRRRRRLLLLLLR", "100\nRRLRRLRLRLRRRRLLRRLLRLRRLLRRRLLRLRRLRLRRLLLRRLLRRRRRRLLLRRRLLRRLLLLLLRLLLLLLRLLLRRRLRLLRRRRRLLRLLRRR", "100\nRRLLLRLRRLRLLRRLRRRLLRRRLRRLLLLLLLLLRRRLLRLRRLRRLRRLRRLRLLLLRLLRRRLLLLRLRRRLLRRRRLRRLLRRRRLRRRLRLLLR", "100\nLLLLLRRLRRRRRRRLLRRRRRLRRLRLRLLRLRRLLLRRRRLLRRLRLLRLLLRLRLLRRRRRRRRRLRLLLRLRLLLLLRLRRRRLRLLRLRLRLRRL", "100\nLLRRRLLLRLLLLRLRLRLRRRLLLRRRLRLLRLLLRRRRRLRRLRRLRRRLRRLRRLLLRLRLLRRRRLRLRRRRRLRRLRLLRRRRLLLRRRRRLLLL"], "outputs": ["1 4\n2 5\n6 3", "3 1\n4 2", "1 3\n2 4", "1 4\n2 5\n3 6", "1 5\n6 2\n3 7\n4 8", "1 6\n2 7\n3 8\n9 4\n5 10", "1 7\n2 8\n3 9\n4 10\n5 11\n12 6", "8 1\n2 9\n3 10\n11 4\n5 12\n6 13\n7 14", "1 9\n2 10\n3 11\n4 12\n5 13\n14 6\n7 15\n16 8", "1 10\n11 2\n3 12\n4 13\n5 14\n6 15\n7 16\n8 17\n18 9", "11 1\n2 12\n3 13\n4 14\n5 15\n6 16\n7 17\n18 8\n9 19\n10 20", "1 12\n2 13\n3 14\n4 15\n5 16\n6 17\n7 18\n8 19\n20 9\n21 10\n11 22", "1 13\n2 14\n15 3\n16 4\n5 17\n18 6\n7 19\n8 20\n21 9\n10 22\n23 11\n12 24", "1 14\n2 15\n16 3\n4 17\n5 18\n6 19\n7 20\n8 21\n9 22\n10 23\n24 11\n12 25\n13 26", "1 15\n2 16\n3 17\n18 4\n5 19\n20 6\n7 21\n8 22\n9 23\n10 24\n25 11\n12 26\n13 27\n28 14", "1 16\n2 17\n3 18\n4 19\n5 20\n6 21\n7 22\n23 8\n9 24\n10 25\n11 26\n12 27\n28 13\n14 29\n15 30", "17 1\n2 18\n19 3\n4 20\n5 21\n22 6\n7 23\n8 24\n9 25\n10 26\n11 27\n12 28\n29 13\n14 30\n15 31\n16 32", "1 18\n2 19\n20 3\n4 21\n5 22\n6 23\n7 24\n8 25\n9 26\n10 27\n28 11\n12 29\n13 30\n14 31\n15 32\n33 16\n17 34", "19 1\n20 2\n3 21\n4 22\n5 23\n6 24\n25 7\n8 26\n9 27\n10 28\n11 29\n30 12\n13 31\n14 32\n15 33\n16 34\n35 17\n36 18", "1 20\n2 21\n22 3\n4 23\n24 5\n6 25\n7 26\n27 8\n9 28\n10 29\n11 30\n12 31\n32 13\n14 33\n34 15\n16 35\n17 36\n37 18\n19 38", "1 21\n2 22\n23 3\n4 24\n5 25\n26 6\n7 27\n8 28\n9 29\n10 30\n31 11\n12 32\n13 33\n14 34\n15 35\n16 36\n17 37\n18 38\n39 19\n20 40", "1 22\n2 23\n3 24\n25 4\n5 26\n6 27\n7 28\n8 29\n9 30\n10 31\n11 32\n33 12\n34 13\n35 14\n15 36\n37 16\n17 38\n18 39\n19 40\n20 41\n21 42", "1 23\n2 24\n3 25\n4 26\n27 5\n6 28\n7 29\n8 30\n31 9\n10 32\n11 33\n12 34\n35 13\n14 36\n15 37\n16 38\n17 39\n18 40\n41 19\n42 20\n21 43\n22 44", "1 24\n2 25\n26 3\n4 27\n5 28\n6 29\n7 30\n31 8\n32 9\n10 33\n34 11\n12 35\n13 36\n14 37\n38 15\n16 39\n40 17\n18 41\n42 19\n20 43\n21 44\n45 22\n23 46", "1 25\n2 26\n3 27\n4 28\n29 5\n6 30\n7 31\n32 8\n9 33\n10 34\n35 11\n12 36\n13 37\n38 14\n39 15\n16 40\n41 17\n18 42\n19 43\n20 44\n21 45\n22 46\n23 47\n48 24", "1 26\n2 27\n3 28\n4 29\n5 30\n6 31\n7 32\n8 33\n9 34\n10 35\n11 36\n12 37\n13 38\n14 39\n15 40\n16 41\n17 42\n18 43\n19 44\n20 45\n21 46\n22 47\n23 48\n24 49\n25 50", "1 27\n2 28\n3 29\n4 30\n5 31\n6 32\n7 33\n8 34\n9 35\n10 36\n11 37\n12 38\n13 39\n14 40\n15 41\n16 42\n17 43\n18 44\n19 45\n20 46\n21 47\n22 48\n23 49\n24 50\n25 51\n26 52", "1 28\n2 29\n3 30\n4 31\n5 32\n6 33\n7 34\n8 35\n9 36\n10 37\n11 38\n12 39\n13 40\n14 41\n15 42\n16 43\n17 44\n18 45\n19 46\n20 47\n21 48\n22 49\n23 50\n24 51\n25 52\n26 53\n27 54", "1 29\n2 30\n3 31\n4 32\n5 33\n6 34\n7 35\n8 36\n9 37\n10 38\n11 39\n12 40\n13 41\n14 42\n15 43\n16 44\n17 45\n18 46\n19 47\n20 48\n21 49\n22 50\n23 51\n24 52\n25 53\n26 54\n27 55\n28 56", "1 30\n2 31\n3 32\n4 33\n5 34\n6 35\n36 7\n8 37\n9 38\n10 39\n11 40\n41 12\n13 42\n14 43\n44 15\n16 45\n46 17\n18 47\n19 48\n20 49\n21 50\n22 51\n52 23\n24 53\n25 54\n26 55\n27 56\n28 57\n29 58", "31 1\n2 32\n3 33\n4 34\n5 35\n36 6\n7 37\n8 38\n9 39\n10 40\n11 41\n42 12\n13 43\n14 44\n15 45\n16 46\n17 47\n48 18\n49 19\n20 50\n21 51\n22 52\n53 23\n24 54\n25 55\n26 56\n27 57\n28 58\n59 29\n30 60", "1 32\n33 2\n34 3\n4 35\n5 36\n6 37\n7 38\n8 39\n9 40\n10 41\n11 42\n12 43\n13 44\n14 45\n15 46\n16 47\n17 48\n18 49\n50 19\n51 20\n21 52\n53 22\n23 54\n24 55\n25 56\n26 57\n27 58\n28 59\n60 29\n30 61\n31 62", "1 33\n2 34\n3 35\n4 36\n5 37\n6 38\n39 7\n8 40\n9 41\n10 42\n11 43\n12 44\n13 45\n14 46\n15 47\n16 48\n17 49\n18 50\n19 51\n20 52\n21 53\n22 54\n55 23\n56 24\n25 57\n26 58\n27 59\n28 60\n61 29\n62 30\n31 63\n32 64", "1 34\n2 35\n3 36\n37 4\n38 5\n6 39\n7 40\n41 8\n9 42\n10 43\n11 44\n12 45\n46 13\n14 47\n15 48\n49 16\n50 17\n18 51\n19 52\n20 53\n21 54\n22 55\n23 56\n24 57\n58 25\n26 59\n27 60\n28 61\n29 62\n30 63\n31 64\n32 65\n33 66", "35 1\n2 36\n3 37\n4 38\n5 39\n40 6\n7 41\n8 42\n9 43\n10 44\n45 11\n12 46\n13 47\n14 48\n15 49\n50 16\n17 51\n18 52\n19 53\n54 20\n21 55\n56 22\n23 57\n24 58\n25 59\n26 60\n27 61\n28 62\n29 63\n30 64\n31 65\n32 66\n33 67\n68 34", "1 36\n2 37\n3 38\n4 39\n5 40\n6 41\n7 42\n8 43\n9 44\n10 45\n11 46\n12 47\n13 48\n14 49\n15 50\n16 51\n17 52\n18 53\n19 54\n20 55\n21 56\n22 57\n23 58\n24 59\n25 60\n26 61\n27 62\n28 63\n29 64\n30 65\n31 66\n32 67\n33 68\n34 69\n35 70", "1 37\n2 38\n3 39\n4 40\n5 41\n6 42\n7 43\n8 44\n9 45\n10 46\n11 47\n12 48\n13 49\n14 50\n15 51\n16 52\n17 53\n18 54\n19 55\n20 56\n21 57\n22 58\n23 59\n24 60\n25 61\n26 62\n27 63\n28 64\n29 65\n30 66\n31 67\n32 68\n33 69\n34 70\n35 71\n36 72", "1 38\n2 39\n3 40\n4 41\n5 42\n6 43\n7 44\n8 45\n9 46\n10 47\n11 48\n12 49\n13 50\n14 51\n15 52\n16 53\n17 54\n18 55\n19 56\n20 57\n21 58\n22 59\n23 60\n24 61\n25 62\n26 63\n27 64\n28 65\n29 66\n30 67\n31 68\n32 69\n33 70\n34 71\n35 72\n36 73\n37 74", "1 39\n2 40\n3 41\n4 42\n5 43\n6 44\n7 45\n8 46\n9 47\n10 48\n11 49\n12 50\n13 51\n14 52\n15 53\n16 54\n17 55\n18 56\n19 57\n20 58\n21 59\n22 60\n23 61\n24 62\n25 63\n26 64\n27 65\n28 66\n29 67\n30 68\n31 69\n32 70\n33 71\n34 72\n35 73\n36 74\n37 75\n38 76", "1 40\n2 41\n3 42\n4 43\n5 44\n6 45\n7 46\n8 47\n9 48\n10 49\n11 50\n12 51\n13 52\n14 53\n15 54\n16 55\n17 56\n18 57\n19 58\n20 59\n21 60\n22 61\n23 62\n24 63\n25 64\n26 65\n27 66\n28 67\n29 68\n30 69\n31 70\n32 71\n33 72\n34 73\n35 74\n36 75\n37 76\n38 77\n39 78", "1 41\n2 42\n3 43\n4 44\n45 5\n46 6\n7 47\n8 48\n9 49\n50 10\n11 51\n12 52\n13 53\n14 54\n15 55\n16 56\n17 57\n18 58\n19 59\n20 60\n21 61\n62 22\n23 63\n24 64\n65 25\n26 66\n27 67\n68 28\n29 69\n30 70\n31 71\n72 32\n73 33\n34 74\n35 75\n36 76\n37 77\n38 78\n39 79\n40 80", "42 1\n2 43\n44 3\n4 45\n5 46\n6 47\n48 7\n8 49\n50 9\n10 51\n11 52\n12 53\n13 54\n14 55\n56 15\n16 57\n17 58\n18 59\n60 19\n20 61\n21 62\n22 63\n64 23\n65 24\n25 66\n26 67\n27 68\n69 28\n29 70\n30 71\n31 72\n73 32\n33 74\n34 75\n35 76\n36 77\n78 37\n79 38\n80 39\n81 40\n41 82", "1 43\n2 44\n3 45\n46 4\n5 47\n48 6\n7 49\n8 50\n51 9\n10 52\n11 53\n12 54\n55 13\n14 56\n57 15\n16 58\n17 59\n18 60\n19 61\n20 62\n21 63\n22 64\n23 65\n24 66\n25 67\n26 68\n27 69\n70 28\n71 29\n30 72\n31 73\n32 74\n33 75\n34 76\n35 77\n36 78\n79 37\n38 80\n39 81\n40 82\n41 83\n42 84", "1 44\n45 2\n46 3\n4 47\n5 48\n6 49\n50 7\n8 51\n9 52\n10 53\n11 54\n12 55\n56 13\n14 57\n58 15\n16 59\n17 60\n18 61\n19 62\n20 63\n64 21\n22 65\n23 66\n24 67\n68 25\n26 69\n27 70\n28 71\n72 29\n30 73\n31 74\n32 75\n76 33\n34 77\n35 78\n36 79\n37 80\n38 81\n39 82\n40 83\n84 41\n85 42\n43 86", "1 45\n2 46\n47 3\n4 48\n49 5\n6 50\n7 51\n8 52\n9 53\n10 54\n11 55\n12 56\n57 13\n14 58\n59 15\n60 16\n17 61\n18 62\n63 19\n20 64\n21 65\n22 66\n23 67\n24 68\n25 69\n70 26\n71 27\n28 72\n29 73\n30 74\n31 75\n32 76\n33 77\n34 78\n35 79\n36 80\n37 81\n38 82\n39 83\n40 84\n41 85\n42 86\n43 87\n44 88", "1 46\n2 47\n3 48\n4 49\n5 50\n6 51\n7 52\n8 53\n9 54\n10 55\n11 56\n12 57\n13 58\n14 59\n15 60\n16 61\n17 62\n18 63\n19 64\n20 65\n21 66\n22 67\n23 68\n24 69\n25 70\n26 71\n27 72\n28 73\n29 74\n30 75\n31 76\n32 77\n33 78\n34 79\n35 80\n36 81\n37 82\n38 83\n39 84\n40 85\n41 86\n42 87\n43 88\n44 89\n45 90", "1 47\n2 48\n3 49\n4 50\n5 51\n6 52\n7 53\n8 54\n9 55\n10 56\n11 57\n12 58\n13 59\n14 60\n15 61\n16 62\n17 63\n18 64\n19 65\n20 66\n21 67\n22 68\n23 69\n24 70\n25 71\n26 72\n27 73\n28 74\n29 75\n30 76\n31 77\n32 78\n33 79\n34 80\n35 81\n36 82\n37 83\n38 84\n39 85\n40 86\n41 87\n42 88\n43 89\n44 90\n45 91\n46 92", "1 48\n2 49\n3 50\n4 51\n5 52\n6 53\n7 54\n8 55\n9 56\n10 57\n11 58\n12 59\n13 60\n14 61\n15 62\n16 63\n17 64\n18 65\n19 66\n20 67\n21 68\n22 69\n23 70\n24 71\n25 72\n26 73\n27 74\n28 75\n29 76\n30 77\n31 78\n32 79\n33 80\n34 81\n35 82\n36 83\n37 84\n38 85\n39 86\n40 87\n41 88\n42 89\n43 90\n44 91\n45 92\n46 93\n47 94", "1 49\n2 50\n3 51\n4 52\n5 53\n6 54\n7 55\n8 56\n9 57\n10 58\n11 59\n12 60\n13 61\n14 62\n15 63\n16 64\n17 65\n18 66\n19 67\n20 68\n21 69\n22 70\n23 71\n24 72\n25 73\n26 74\n27 75\n28 76\n29 77\n30 78\n31 79\n32 80\n33 81\n34 82\n35 83\n36 84\n37 85\n38 86\n39 87\n40 88\n41 89\n42 90\n43 91\n44 92\n45 93\n46 94\n47 95\n48 96", "1 50\n2 51\n3 52\n4 53\n5 54\n6 55\n7 56\n8 57\n9 58\n10 59\n11 60\n12 61\n13 62\n14 63\n15 64\n16 65\n17 66\n18 67\n19 68\n20 69\n21 70\n22 71\n23 72\n24 73\n25 74\n26 75\n27 76\n28 77\n29 78\n30 79\n31 80\n32 81\n33 82\n34 83\n35 84\n36 85\n37 86\n38 87\n39 88\n40 89\n41 90\n42 91\n43 92\n44 93\n45 94\n46 95\n47 96\n48 97\n49 98", "1 51\n2 52\n3 53\n4 54\n55 5\n6 56\n7 57\n8 58\n9 59\n10 60\n61 11\n62 12\n13 63\n14 64\n15 65\n16 66\n17 67\n68 18\n69 19\n70 20\n21 71\n72 22\n23 73\n24 74\n75 25\n26 76\n77 27\n78 28\n29 79\n30 80\n31 81\n82 32\n33 83\n84 34\n35 85\n86 36\n37 87\n38 88\n39 89\n40 90\n91 41\n42 92\n93 43\n44 94\n45 95\n46 96\n47 97\n98 48\n99 49\n50 100", "1 51\n2 52\n3 53\n4 54\n5 55\n6 56\n7 57\n8 58\n9 59\n10 60\n11 61\n12 62\n63 13\n14 64\n65 15\n66 16\n17 67\n18 68\n69 19\n70 20\n21 71\n22 72\n73 23\n24 74\n25 75\n76 26\n27 77\n28 78\n29 79\n30 80\n31 81\n82 32\n33 83\n34 84\n85 35\n36 86\n87 37\n38 88\n39 89\n40 90\n91 41\n92 42\n93 43\n44 94\n45 95\n46 96\n97 47\n48 98\n49 99\n50 100", "1 51\n2 52\n3 53\n54 4\n5 55\n6 56\n7 57\n58 8\n9 59\n10 60\n11 61\n12 62\n13 63\n64 14\n15 65\n16 66\n17 67\n18 68\n19 69\n20 70\n21 71\n22 72\n23 73\n74 24\n25 75\n26 76\n27 77\n28 78\n29 79\n30 80\n31 81\n82 32\n33 83\n84 34\n35 85\n36 86\n87 37\n38 88\n39 89\n40 90\n41 91\n92 42\n43 93\n94 44\n45 95\n46 96\n47 97\n48 98\n99 49\n50 100", "51 1\n2 52\n3 53\n4 54\n5 55\n56 6\n7 57\n8 58\n9 59\n10 60\n11 61\n62 12\n13 63\n64 14\n15 65\n16 66\n17 67\n68 18\n19 69\n70 20\n21 71\n22 72\n23 73\n24 74\n25 75\n76 26\n27 77\n28 78\n29 79\n30 80\n31 81\n32 82\n33 83\n34 84\n35 85\n36 86\n37 87\n38 88\n39 89\n40 90\n41 91\n42 92\n93 43\n94 44\n45 95\n46 96\n97 47\n98 48\n99 49\n100 50", "51 1\n2 52\n3 53\n4 54\n5 55\n56 6\n7 57\n8 58\n9 59\n10 60\n61 11\n12 62\n13 63\n14 64\n15 65\n16 66\n67 17\n68 18\n19 69\n20 70\n71 21\n22 72\n23 73\n24 74\n25 75\n26 76\n27 77\n28 78\n29 79\n80 30\n31 81\n82 32\n33 83\n34 84\n85 35\n36 86\n87 37\n38 88\n39 89\n40 90\n41 91\n92 42\n93 43\n44 94\n45 95\n46 96\n47 97\n48 98\n49 99\n50 100", "1 51\n2 52\n53 3\n4 54\n5 55\n6 56\n57 7\n8 58\n9 59\n10 60\n61 11\n62 12\n13 63\n64 14\n15 65\n16 66\n67 17\n18 68\n19 69\n20 70\n21 71\n22 72\n23 73\n24 74\n75 25\n76 26\n27 77\n28 78\n29 79\n30 80\n31 81\n32 82\n33 83\n34 84\n35 85\n36 86\n37 87\n38 88\n39 89\n40 90\n41 91\n42 92\n43 93\n44 94\n95 45\n46 96\n97 47\n98 48\n99 49\n50 100", "1 51\n2 52\n3 53\n54 4\n55 5\n6 56\n7 57\n8 58\n9 59\n10 60\n61 11\n12 62\n13 63\n64 14\n15 65\n16 66\n67 17\n68 18\n19 69\n20 70\n71 21\n22 72\n73 23\n74 24\n25 75\n26 76\n27 77\n78 28\n79 29\n30 80\n31 81\n32 82\n33 83\n84 34\n35 85\n36 86\n87 37\n38 88\n39 89\n40 90\n41 91\n42 92\n43 93\n94 44\n45 95\n46 96\n47 97\n48 98\n49 99\n50 100", "1 51\n52 2\n3 53\n4 54\n5 55\n6 56\n7 57\n58 8\n59 9\n10 60\n11 61\n12 62\n13 63\n14 64\n15 65\n16 66\n67 17\n68 18\n69 19\n20 70\n21 71\n72 22\n23 73\n24 74\n25 75\n76 26\n77 27\n28 78\n29 79\n30 80\n31 81\n32 82\n33 83\n34 84\n35 85\n36 86\n37 87\n38 88\n39 89\n40 90\n41 91\n42 92\n43 93\n44 94\n95 45\n46 96\n97 47\n98 48\n49 99\n50 100", "1 51\n2 52\n3 53\n4 54\n5 55\n56 6\n7 57\n8 58\n59 9\n10 60\n11 61\n12 62\n13 63\n14 64\n15 65\n16 66\n17 67\n18 68\n69 19\n20 70\n71 21\n72 22\n23 73\n24 74\n75 25\n26 76\n77 27\n28 78\n79 29\n30 80\n31 81\n32 82\n33 83\n34 84\n35 85\n36 86\n37 87\n38 88\n39 89\n90 40\n91 41\n42 92\n43 93\n44 94\n95 45\n46 96\n47 97\n48 98\n49 99\n50 100", "1 51\n2 52\n3 53\n4 54\n55 5\n6 56\n7 57\n8 58\n59 9\n10 60\n11 61\n12 62\n13 63\n64 14\n15 65\n16 66\n17 67\n18 68\n19 69\n70 20\n21 71\n72 22\n23 73\n24 74\n25 75\n26 76\n27 77\n78 28\n29 79\n30 80\n31 81\n32 82\n83 33\n34 84\n35 85\n36 86\n37 87\n38 88\n89 39\n90 40\n91 41\n42 92\n43 93\n44 94\n45 95\n46 96\n97 47\n48 98\n99 49\n100 50"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
40
codeforces
8f73f953a8856ca3a4c9cf3d04b14148
TL
Valera wanted to prepare a Codesecrof round. He's already got one problem and he wants to set a time limit (TL) on it. Valera has written *n* correct solutions. For each correct solution, he knows its running time (in seconds). Valera has also wrote *m* wrong solutions and for each wrong solution he knows its running time (in seconds). Let's suppose that Valera will set *v* seconds TL in the problem. Then we can say that a solution passes the system testing if its running time is at most *v* seconds. We can also say that a solution passes the system testing with some "extra" time if for its running time, *a* seconds, an inequality 2*a*<=≤<=*v* holds. As a result, Valera decided to set *v* seconds TL, that the following conditions are met: 1. *v* is a positive integer; 1. all correct solutions pass the system testing; 1. at least one correct solution passes the system testing with some "extra" time; 1. all wrong solutions do not pass the system testing; 1. value *v* is minimum among all TLs, for which points 1, 2, 3, 4 hold. Help Valera and find the most suitable TL or else state that such TL doesn't exist. The first line contains two integers *n*, *m* (1<=≤<=*n*,<=*m*<=≤<=100). The second line contains *n* space-separated positive integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=100) — the running time of each of the *n* correct solutions in seconds. The third line contains *m* space-separated positive integers *b*1,<=*b*2,<=...,<=*b**m* (1<=≤<=*b**i*<=≤<=100) — the running time of each of *m* wrong solutions in seconds. If there is a valid TL value, print it. Otherwise, print -1. Sample Input 3 6 4 5 2 8 9 6 10 7 11 3 1 3 4 5 6 Sample Output 5-1
{"inputs": ["3 6\n4 5 2\n8 9 6 10 7 11", "3 1\n3 4 5\n6", "2 5\n45 99\n49 41 77 83 45", "50 50\n18 13 5 34 10 36 36 12 15 11 16 17 14 36 23 45 32 24 31 18 24 32 7 1 31 3 49 8 16 23 3 39 47 43 42 38 40 22 41 1 49 47 9 8 19 15 29 30 16 18\n91 58 86 51 94 94 73 84 98 69 74 56 52 80 88 61 53 99 88 50 55 95 65 84 87 79 51 52 69 60 74 73 93 61 73 59 64 56 95 78 86 72 79 70 93 78 54 61 71 50", "55 44\n93 17 74 15 34 16 41 80 26 54 94 94 86 93 20 44 63 72 39 43 67 4 37 49 76 94 5 51 64 74 11 47 77 97 57 30 42 72 71 26 8 14 67 64 49 57 30 23 40 4 76 78 87 78 79\n38 55 17 65 26 7 36 65 48 28 49 93 18 98 31 90 26 57 1 26 88 56 48 56 23 13 8 67 80 2 51 3 21 33 20 54 2 45 21 36 3 98 62 2", "32 100\n30 8 4 35 18 41 18 12 33 39 39 18 39 19 33 46 45 33 34 27 14 39 40 21 38 9 42 35 27 10 14 14\n65 49 89 64 47 78 59 52 73 51 84 82 88 63 91 99 67 87 53 99 75 47 85 82 58 47 80 50 65 91 83 90 77 52 100 88 97 74 98 99 50 93 65 61 65 65 65 96 61 51 84 67 79 90 92 83 100 100 100 95 80 54 77 51 98 64 74 62 60 96 73 74 94 55 89 60 92 65 74 79 66 81 53 47 71 51 54 85 74 97 68 72 88 94 100 85 65 63 65 90", "1 50\n7\n65 52 99 78 71 19 96 72 80 15 50 94 20 35 79 95 44 41 45 53 77 50 74 66 59 96 26 84 27 48 56 84 36 78 89 81 67 34 79 74 99 47 93 92 90 96 72 28 78 66", "1 1\n4\n9", "1 1\n2\n4", "22 56\n49 20 42 68 15 46 98 78 82 8 7 33 50 30 75 96 36 88 35 99 19 87\n15 18 81 24 35 89 25 32 23 3 48 24 52 69 18 32 23 61 48 98 50 38 5 17 70 20 38 32 49 54 68 11 51 81 46 22 19 59 29 38 45 83 18 13 91 17 84 62 25 60 97 32 23 13 83 58", "1 1\n50\n100", "1 1\n49\n100", "1 1\n100\n100", "1 1\n99\n100", "8 4\n1 2 49 99 99 95 78 98\n100 100 100 100", "68 85\n43 55 2 4 72 45 19 56 53 81 18 90 11 87 47 8 94 88 24 4 67 9 21 70 25 66 65 27 46 13 8 51 65 99 37 43 71 59 71 79 32 56 49 43 57 85 95 81 40 28 60 36 72 81 60 40 16 78 61 37 29 26 15 95 70 27 50 97\n6 6 48 72 54 31 1 50 29 64 93 9 29 93 66 63 25 90 52 1 66 13 70 30 24 87 32 90 84 72 44 13 25 45 31 16 92 60 87 40 62 7 20 63 86 78 73 88 5 36 74 100 64 34 9 5 62 29 58 48 81 46 84 56 27 1 60 14 54 88 31 93 62 7 9 69 27 48 10 5 33 10 53 66 2", "5 100\n1 1 1 1 1\n77 53 38 29 97 33 64 17 78 100 27 12 42 44 20 24 44 68 58 57 65 90 8 24 4 6 74 68 61 43 25 69 8 62 36 85 67 48 69 30 35 41 42 12 87 66 50 92 53 76 38 67 85 7 80 78 53 76 94 8 37 50 4 100 4 71 10 48 34 47 83 42 25 81 64 72 25 51 53 75 43 98 53 77 94 38 81 15 89 91 72 76 7 36 27 41 88 18 19 75", "3 3\n2 3 4\n8 9 10", "2 1\n2 3\n15", "2 1\n2 4\n4", "2 3\n4 5\n10 11 12", "3 1\n2 3 3\n5", "2 1\n9 10\n100", "3 3\n3 12 15\n7 8 9", "2 2\n3 5\n7 8", "3 3\n4 5 6\n10 11 12", "3 5\n2 3 3\n6 6 6 6 2", "3 6\n4 5 3\n8 9 7 10 7 11", "3 6\n4 5 2\n8 9 6 10 7 4", "2 1\n4 6\n10", "1 2\n1\n3 1", "2 1\n5 6\n20", "2 1\n1 5\n5", "3 2\n10 20 30\n30 40", "2 2\n5 6\n7 100", "2 1\n2 5\n7", "1 1\n5\n20", "2 1\n10 11\n100", "1 1\n1\n10", "1 1\n10\n100"], "outputs": ["5", "-1", "-1", "49", "-1", "46", "14", "8", "-1", "-1", "-1", "98", "-1", "-1", "99", "-1", "2", "4", "4", "-1", "8", "4", "18", "-1", "6", "8", "-1", "6", "-1", "8", "-1", "10", "-1", "-1", "-1", "5", "10", "20", "2", "20"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
305
codeforces
8f7bee73b29e1a11e67f9279a1507384
The Child and Set
At the children's day, the child came to Picks's house, and messed his house up. Picks was angry at him. A lot of important things were lost, in particular the favorite set of Picks. Fortunately, Picks remembers something about his set *S*: - its elements were distinct integers from 1 to *limit*; - the value of was equal to *sum*; here *lowbit*(*x*) equals 2*k* where *k* is the position of the first one in the binary representation of *x*. For example, *lowbit*(100102)<==<=102,<=*lowbit*(100012)<==<=12,<=*lowbit*(100002)<==<=100002 (binary representation). Can you help Picks and find any set *S*, that satisfies all the above conditions? The first line contains two integers: *sum*,<=*limit* (1<=≤<=*sum*,<=*limit*<=≤<=105). In the first line print an integer *n* (1<=≤<=*n*<=≤<=105), denoting the size of *S*. Then print the elements of set *S* in any order. If there are multiple answers, print any of them. If it's impossible to find a suitable set, print -1. Sample Input 5 5 4 3 5 1 Sample Output 2 4 5 3 2 3 1 -1
{"inputs": ["5 5", "4 3", "5 1", "54321 12345", "1997 508", "100000 30000", "100000 100000", "1 100000", "29985 15678", "83451 17526", "96024 12472", "21741 3575", "40287 17817", "58934 6404", "62658 10881", "89829 8298", "5499 1023", "5499 1024", "53689 10552", "247 3270", "58413 1253", "47283 15757", "93145 14496", "66947 17657", "49940 18445", "61897 33128", "97660 28794", "99808 14000", "100000 1", "1 1", "100000 14047", "100000 14048", "21741 3576"], "outputs": ["2\n4 5", "3\n2 3 1", "-1", "7008\n8958 8925 11009 10808 8221 9771 11269 7017 6416 11723 10324 5654 6569 10454 9164 10754 6069 7913 12154 11111 7361 9619 9829 6664 8468 7239 5453 11577 11423 10031 11624 11486 11984 5378 8695 8640 9957 10453 11538 11943 9558 7846 12099 9317 11626 7001 5975 8923 9528 6850 10896 5989 10638 10500 10645 7253 12066 11635 5414 8824 7375 7771 8206 10398 11255 10687 7478 6385 11536 9511 7360 6646 5653 7317 9011 8265 9961 5817 9556 9903 5421 10281 6812 9312 6289 5468 8832 7075 7268 9545 12173 6126 6750 7789 740...", "429\n372 314 295 417 413 215 501 175 275 251 381 258 320 378 389 318 440 505 317 471 257 504 414 331 139 438 193 460 445 239 494 236 147 391 359 497 137 131 249 106 439 310 262 165 189 292 284 132 319 486 279 185 355 266 306 194 229 464 136 478 407 97 383 408 288 214 506 197 469 458 157 419 221 451 167 244 220 429 424 201 181 448 479 241 237 264 150 392 123 233 336 280 254 330 187 289 300 360 382 98 368 130 313 481 463 345 370 216 195 450 433 118 94 152 253 79 308 485 499 202 465 435 418 277 105 255 500 16...", "14127\n26613 18365 28664 17829 21130 27426 21717 24672 24071 19607 19925 18270 20786 18268 26819 18080 22887 17706 19483 19506 25016 20111 27484 24319 19265 19207 23108 18049 21756 19686 17917 20556 16214 23033 20478 16698 22390 22634 29193 15951 21420 25501 22429 26972 29281 17977 15947 20937 16929 24505 28551 18726 21728 28155 19143 24908 16146 20285 17685 26479 17361 25426 22492 20423 21741 22680 25133 24040 29191 27166 17529 24301 23308 24972 16663 25920 27616 23472 27211 27558 23076 27936 24467 26967 ...", "10735\n96613 91015 98664 98463 91130 97426 91717 94672 94071 89606 89924 93309 90786 92311 96819 90266 92887 95568 89482 89505 95016 90110 97484 94319 89677 91493 93108 99232 91756 89685 99279 90556 91261 93033 90478 89768 92390 92634 99193 99598 91420 95501 92429 96972 99281 91403 93630 90937 97183 94505 98551 93644 91728 98155 98300 94908 99721 90285 91440 96479 95030 95426 92492 90423 91741 92680 95133 94040 99191 97166 89517 94301 93308 94972 92077 95920 97616 93472 97211 97558 93076 97936 94467 96967 ...", "1\n99999", "4368\n12291 12258 14342 14141 11554 13104 14602 15169 14887 15056 13657 12832 13865 13787 12497 14087 12934 14599 15487 14444 11956 12952 13162 15113 11801 12732 14195 14910 14756 13364 14957 14819 15317 12023 12028 11973 13290 13786 14871 15276 12891 15480 15432 12650 14959 14893 13483 12256 12861 14335 14229 11522 13971 13833 13978 12923 15399 14968 14781 12157 14840 12905 11539 13731 14588 14020 12343 15367 14869 12844 12431 15589 14489 13240 12344 11598 13294 13937 12889 13236 15351 13614 11665 12645 1...", "10644\n14139 8541 16190 15989 8656 14952 9243 12198 11597 7132 7450 10835 8312 9837 14345 7791 10413 13094 7008 7031 12542 7636 15010 11845 7203 9019 10634 16758 9282 7211 16805 8081 8787 10559 8003 7294 9916 10160 16719 17124 8946 13027 9955 14498 16807 8929 11156 8463 14709 12031 16077 11170 9254 15681 15826 12434 17247 7810 8966 14005 12556 12952 10018 7948 9267 10206 12659 11566 16717 14692 7043 11827 10834 12498 9603 13446 15142 10998 14737 15084 10602 15462 11993 14493 9323 10649 7358 12256 12449 930...", "-1", "-1", "4069\n14430 14397 16481 16280 14255 15243 16741 17308 17026 17195 15796 14971 16004 15926 14636 16226 15073 16738 17626 16583 14095 15091 15301 17252 13940 14871 16334 17049 16895 15503 17096 16958 17456 14162 14167 14112 15429 15925 17010 17415 15030 17619 17571 14789 17098 17032 15622 14395 15000 16474 16368 15258 16110 15972 16117 15062 17538 17107 16920 14296 16979 15044 15580 15870 16727 16159 14482 17506 17008 14983 14570 17728 16628 15379 14483 13847 15433 16076 15028 15375 17490 15753 13803 14784 1...", "-1", "8365\n7494 7461 9545 9344 6757 8307 2598 5553 4952 10259 8860 4190 2991 3192 7700 9290 3768 6449 10690 9647 5897 8155 8365 5200 3867 5775 3989 10113 2637 8567 10160 10022 10520 3914 7231 7176 3271 3515 10074 10479 8094 6382 3310 7853 10162 5537 4511 7459 8064 5386 9432 4525 2609 9036 9181 5789 10602 10171 3950 7360 5911 6307 3373 8934 2622 3561 6014 4921 10072 8047 5896 5182 4189 5853 2958 6801 8497 4353 8092 8439 3957 8817 5348 7848 2678 4004 3747 5611 5804 2657 10709 4662 5286 6325 5940 7248 2855 3912 62...", "-1", "-1", "871\n346 262 304 933 200 223 161 515 233 402 159 373 180 894 325 834 956 1021 833 366 488 1020 482 459 655 445 546 256 213 755 303 165 663 547 260 552 653 647 217 622 300 826 778 681 305 239 800 648 835 252 795 565 871 246 573 710 745 314 220 332 186 613 899 160 349 559 1022 713 215 587 673 935 737 324 683 290 736 945 240 258 697 964 995 383 753 780 212 908 639 591 852 174 770 172 703 805 540 876 898 293 508 646 468 364 979 861 886 567 711 401 949 516 610 263 769 421 824 1001 1015 579 188 951 934 483 621 4...", "6908\n7165 7132 9216 9015 6428 7978 9476 5224 4623 9930 8531 3861 4776 8661 7371 8961 4276 6120 10361 9318 5568 7826 8036 4871 6675 5446 3660 9784 9630 8238 9831 9693 10191 6897 6902 6847 8164 8660 9745 10150 7765 6053 10306 7524 9833 5208 4182 7130 7735 5057 9103 4196 8845 8707 8852 5460 10273 9842 9655 7031 5582 5978 6413 8605 9462 8894 5685 4592 9743 7718 5567 4853 3860 5524 7218 6472 8168 4024 7763 8110 4831 8488 5019 7519 4496 3675 7039 5282 5475 7752 10380 4333 4957 5996 5611 6919 3792 8542 5897 6811...", "62\n3228 3223 3212 3243 3230 3241 3263 3227 3255 3265 3262 3239 3261 3235 3219 3236 3231 3267 3210 3233 3258 3266 3237 3232 3252 3218 3251 3222 3242 3216 3256 3238 3253 3247 3214 3259 3217 3211 3269 3215 3220 3246 3221 3225 3264 3244 3250 3257 3209 3248 3234 3268 3260 3229 3254 3270 3245 3226 3213 3240 3249 3224", "-1", "7089\n12370 12337 14421 14220 11633 13183 14681 10429 9828 15135 13736 9066 9981 13866 12576 14166 9481 11325 15566 14523 10773 13031 13241 10076 8743 10651 8865 14989 14835 13443 15036 14898 15396 8790 12107 12052 13369 13865 14950 15355 12970 11258 15511 12729 15038 10413 9387 12335 12940 10262 14308 9401 14050 13912 14057 10665 15478 15047 8826 12236 10787 11183 11618 13810 14667 14099 10890 9797 14948 12923 10772 10058 9065 10729 12423 11677 13373 9229 12968 13315 8833 13693 10224 12724 8670 8880 12244...", "12533\n11109 2861 13160 2325 5626 11922 6213 9168 8567 4103 4421 2766 5282 2764 11315 2576 7383 2202 3979 4002 9512 4607 11980 8815 3761 3703 7604 2545 6252 4182 2413 5052 5757 7529 4974 4265 6886 7130 13689 14094 5916 9997 6925 11468 13777 2473 8126 5433 11679 9001 13047 3222 6224 12651 3639 9404 14217 4781 2181 10975 9526 9922 6988 4919 6237 7176 9629 8536 13687 11662 2025 8797 7804 9468 6573 10416 12112 7968 11707 12054 7572 12432 8963 11463 6293 7619 4329 9226 9419 6272 14324 8277 8901 5655 1983 10863 ...", "7720\n14270 14237 16321 16120 13533 15083 16581 12329 11728 17035 15636 10966 11881 9968 14476 16066 10544 13225 17466 16423 12673 14931 15141 11976 10643 12551 10765 16889 16735 15343 16936 16798 17296 10690 14007 13952 10047 10291 16850 17255 14870 13158 10086 14629 16938 12313 11287 14235 14840 12162 16208 11301 15950 15812 15957 12565 17378 16947 10726 14136 12687 13083 10149 15710 16567 10337 12790 11697 16848 14823 12672 11958 10965 12629 14323 13577 15273 11129 14868 15215 10733 15593 12124 14624 10...", "5320\n15058 15025 17109 16908 14321 15871 17369 17936 17654 17823 16424 15599 16632 16554 15264 16854 15701 14013 18254 17211 13461 15719 15929 17880 14568 13339 13680 17677 17523 16131 17724 17586 18084 14790 14795 14740 16057 16553 17638 18043 15658 13946 18199 15417 17726 17660 16250 15023 15628 17102 16996 14289 16738 16600 16745 13353 18166 17735 17548 14924 13475 13871 14306 16498 17355 16787 13578 13628 17636 15611 13460 18356 13731 13417 15111 14365 16061 16704 15656 16003 18118 16381 14432 15412 1...", "4993\n29741 29708 31792 31591 29004 30554 32052 32619 32337 32506 31107 30282 31315 31237 29947 31537 30384 28696 32937 31894 28143 30402 30612 32563 29251 30182 28362 32360 32206 30814 32407 32269 32767 29473 29478 29423 30740 31236 32321 32726 30341 28628 32882 30100 32409 32343 30933 29706 30311 31785 31679 28972 31421 31283 31428 30373 32849 32418 32231 29607 28157 28553 28989 31181 32038 31470 28260 28310 32319 30294 28142 33039 28413 30690 29794 29048 30744 31387 30339 30686 32801 31064 29115 30095 3...", "13667\n25407 17159 27458 16623 19924 26220 20511 23466 22865 18401 18719 17064 19580 17062 25613 16874 21681 16500 18277 18300 23810 18905 26278 23113 18059 18001 21902 16843 20550 18480 16711 19350 20055 21827 19272 15491 21184 21428 27987 28392 20214 24295 21223 25766 28075 16771 22424 19731 15722 23299 27345 17520 20522 26949 17937 23702 28515 19079 16479 25273 16154 24220 21286 19217 20535 21474 23927 22834 27985 25960 16322 23095 22102 23766 15456 24714 26410 22266 26005 26352 21870 26730 23261 25761 ...", "14000\n10613 2365 12664 1829 5130 11426 5717 8672 8071 3607 3925 2270 4786 2268 10819 2080 6887 1706 3483 3506 9016 4111 11484 8319 3265 3207 7108 2049 5756 3686 1917 4556 215 7033 4478 698 6390 6634 13193 13598 5420 9501 6429 10972 13281 1977 7630 4937 929 8505 12551 2726 5728 12155 3143 8908 147 4285 1685 10479 1361 9426 6492 4423 5741 6680 9133 8040 13191 11166 1529 8301 7308 8972 663 9920 11616 7472 11211 11558 7076 11936 8467 10967 5797 7123 3833 8730 8923 5776 13828 7781 8405 5159 1487 10367 4313 321...", "-1", "1\n1", "-1", "14043\n10661 2413 12712 1877 5178 11474 5765 8720 8119 3655 3973 2318 4834 2316 10867 2128 6935 1754 3531 3554 9064 4159 11532 8367 3313 3255 7156 2097 5804 3734 1965 4604 263 7081 4526 746 6438 6682 13241 13646 5468 9549 6477 11020 13329 2025 7678 4985 977 8553 12599 2774 5776 12203 3191 8956 195 4333 1733 10527 1409 9474 6540 4471 5789 6728 9181 8088 13239 11214 1577 8349 7356 9020 711 9968 11664 7520 11259 11606 7124 11984 8515 11015 5845 7171 3881 8778 8971 5824 13876 7829 8453 5207 1535 10415 4361 326...", "3573\n189 156 2240 2039 14 1002 2500 3067 2785 2954 1555 730 1763 1685 395 1985 832 2497 3385 2342 3040 850 1060 3011 1487 630 2093 2808 2654 1262 2855 2717 3215 3099 1631 1199 1188 1684 2769 3174 789 3378 3330 548 2857 2791 1381 154 759 2233 2127 1017 1869 1731 1876 821 3297 2866 2679 55 2738 803 1339 1629 2486 1918 241 3265 2767 742 329 3487 2387 1138 242 1400 1192 1835 787 1134 3249 1512 1563 543 2398 3332 63 1702 2231 776 3404 510 2668 469 2243 1016 1057 1566 943 667 1411 3198 699 499 3531 2227 576 157..."]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
104
codeforces
8f93f9bd8f9064af561ecdf39f5a1e37
Alternating Current
Mad scientist Mike has just finished constructing a new device to search for extraterrestrial intelligence! He was in such a hurry to launch it for the first time that he plugged in the power wires without giving it a proper glance and started experimenting right away. After a while Mike observed that the wires ended up entangled and now have to be untangled again. The device is powered by two wires "plus" and "minus". The wires run along the floor from the wall (on the left) to the device (on the right). Both the wall and the device have two contacts in them on the same level, into which the wires are plugged in some order. The wires are considered entangled if there are one or more places where one wire runs above the other one. For example, the picture below has four such places (top view): Mike knows the sequence in which the wires run above each other. Mike also noticed that on the left side, the "plus" wire is always plugged into the top contact (as seen on the picture). He would like to untangle the wires without unplugging them and without moving the device. Determine if it is possible to do that. A wire can be freely moved and stretched on the floor, but cannot be cut. To understand the problem better please read the notes to the test samples. The single line of the input contains a sequence of characters "+" and "-" of length *n* (1<=≤<=*n*<=≤<=100000). The *i*-th (1<=≤<=*i*<=≤<=*n*) position of the sequence contains the character "+", if on the *i*-th step from the wall the "plus" wire runs above the "minus" wire, and the character "-" otherwise. Print either "Yes" (without the quotes) if the wires can be untangled or "No" (without the quotes) if the wires cannot be untangled. Sample Input -++- +- ++ - Sample Output Yes No Yes No
{"inputs": ["-++-", "+-", "++", "-", "+-+-", "-+-", "-++-+--+", "+", "-+", "--", "+++", "--+", "++--++", "+-++-+", "+-+--+", "--++-+", "-+-+--", "+-+++-", "-+-+-+", "-++-+--++--+-++-", "+-----+-++---+------+++-++++", "-+-++--+++-++++---+--+----+--+-+-+++-+++-+---++-++++-+--+--+--+-+-++-+-+-++++++---++--+++++-+--++--+-+--++-----+--+-++---+++---++----+++-++++--++-++-", "-+-----++++--++-+-++", "+--+--+------+++++++-+-+++--++---+--+-+---+--+++-+++-------+++++-+-++++--+-+-+++++++----+----+++----+-+++-+++-----+++-+-++-+-+++++-+--++----+--+-++-----+-+-++++---+++---+-+-+-++++--+--+++---+++++-+---+-----+++-++--+++---++-++-+-+++-+-+-+---+++--+--++++-+-+--++-------+--+---++-----+++--+-+++--++-+-+++-++--+++-++++++++++-++-++++++-+++--+--++-+++--+++-++++----+++---+-+----++++-+-+", "-+-+-++-+-+-", "-+-++-+-", "-+-++-+-+-", "++-+-+-+-+--+", "+++---", "+-+-+-+-+--+-+-+-+-++--++--+", "+-+-++", "-++--+--+++-+-+-+-+-", "+---+-+-", "+-+--+-+", "+++---+++---", "-+++++", "-+-+-+-+-+-+-++-+-+-+-+-+-+-", "-+++--", "+---+", "-++", "-+--+-", "+---++--++", "+++-", "--+++", "++-+"], "outputs": ["Yes", "No", "Yes", "No", "No", "No", "Yes", "No", "No", "Yes", "No", "No", "Yes", "Yes", "No", "No", "No", "No", "No", "Yes", "No", "No", "Yes", "Yes", "Yes", "Yes", "No", "No", "No", "Yes", "No", "No", "No", "Yes", "No", "No", "Yes", "No", "No", "No", "Yes", "No", "No", "No", "No"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
189
codeforces
8fa59503460967189c33fd84aaf7e67c
Help Farmer
Once upon a time in the Kingdom of Far Far Away lived Sam the Farmer. Sam had a cow named Dawn and he was deeply attached to her. Sam would spend the whole summer stocking hay to feed Dawn in winter. Sam scythed hay and put it into haystack. As Sam was a bright farmer, he tried to make the process of storing hay simpler and more convenient to use. He collected the hay into cubical hay blocks of the same size. Then he stored the blocks in his barn. After a summer spent in hard toil Sam stored *A*·*B*·*C* hay blocks and stored them in a barn as a rectangular parallelepiped *A* layers high. Each layer had *B* rows and each row had *C* blocks. At the end of the autumn Sam came into the barn to admire one more time the hay he'd been stacking during this hard summer. Unfortunately, Sam was horrified to see that the hay blocks had been carelessly scattered around the barn. The place was a complete mess. As it turned out, thieves had sneaked into the barn. They completely dissembled and took away a layer of blocks from the parallelepiped's front, back, top and sides. As a result, the barn only had a parallelepiped containing (*A*<=-<=1)<=×<=(*B*<=-<=2)<=×<=(*C*<=-<=2) hay blocks. To hide the evidence of the crime, the thieves had dissembled the parallelepiped into single 1<=×<=1<=×<=1 blocks and scattered them around the barn. After the theft Sam counted *n* hay blocks in the barn but he forgot numbers *A*, *B* и *C*. Given number *n*, find the minimally possible and maximally possible number of stolen hay blocks. The only line contains integer *n* from the problem's statement (1<=≤<=*n*<=≤<=109). Print space-separated minimum and maximum number of hay blocks that could have been stolen by the thieves. Note that the answer to the problem can be large enough, so you must use the 64-bit integer type for calculations. Please, do not use the %lld specificator to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specificator. Sample Input 4 7 12 Sample Output 28 41 47 65 48 105
{"inputs": ["4", "7", "12", "1", "6", "8", "9", "14", "15", "16", "18", "20", "299999771", "54", "96", "348", "748", "908", "1026", "1985", "4472", "20845", "50480", "62497", "646055", "790620", "989903", "7033800", "7661860", "7834243", "45134118", "89054701", "99264891", "127039320", "206898748", "231136953", "257259713", "286736327", "311933803", "332393619", "422114561", "453012754", "470860680", "509607936", "534879507", "535074941", "536870912", "573308928", "603979776", "605404800", "615716902", "628464178", "631243141", "644972544", "659274082", "679477248", "735134400", "764411904", "778377600", "791683200", "805306368", "821620800", "856079286", "857656800", "859963392", "864864000", "882161280", "884822400", "905969664", "908107200", "918918000", "931170240", "935625600", "936354996", "951350400", "958557600", "972972000", "980179200", "985944960", "994593600", "999893227", "999893387", "999905161", "999942949", "999996583", "999999797", "999999883", "999999893", "999999929", "999999937", "999999991", "999999992", "999999993", "999999994", "999999995", "999999996", "999999997", "999999998", "999999999", "1000000000"], "outputs": ["28 41", "47 65", "48 105", "17 17", "34 57", "40 73", "41 81", "58 121", "55 129", "56 137", "57 153", "64 169", "1499998867 2399998177", "106 441", "144 777", "396 2793", "487 5993", "1840 7273", "591 8217", "3601 15889", "1603 35785", "8873 166769", "17884 403849", "312497 499985", "140995 5168449", "316416 6324969", "1082167 7919233", "210976 56270409", "546725 61294889", "8302235 62673953", "19223945 361072953", "445273517 712437617", "15587889 794119137", "1209066 1016314569", "1683461 1655189993", "539319577 1849095633", "2122207 2058077713", "290355727 2293890625", "1559669027 2495470433", "10714371 2659148961", "78417139 3376916497", "2844347 3624102041", "129486993 3766885449", "3045276 4076863497", "253364145 4279036065", "647722381 4280599537", "3151876 4294967305", "3301020 4586471433", "3414276 4831838217", "3414952 4843238409", "10508698 4925735225", "3574502 5027713433", "634644469 5049945137", "3573148 5159780361", "1977822262 5274192665", "3693060 5435817993", "3886608 5881075209", "3988228 6115295241", "4036708 6227020809", "4082888 6333465609", "4201476 6442450953", "4185636 6572966409", "196667409 6848634297", "4307008 6861254409", "4320292 6879707145", "4331048 6918912009", "4388720 7057290249", "4396766 7078579209", "4529412 7247757321", "4474050 7264857609", "4511288 7351344009", "4548514 7449361929", "4563150 7485004809", "40069269 7490839977", "4614600 7610803209", "4637398 7668460809", "4685478 7783776009", "4707050 7841433609", "4725040 7887559689", "4752650 7956748809", "1000183267 7999145825", "1000724227 7999147105", "1000161721 7999241297", "1000368197 7999543601", "1022096687 7999972673", "4999998997 7999998385", "4999999427 7999999073", "4999999477 7999999153", "4999999657 7999999441", "4999999697 7999999505", "1059701759 7999999937", "129518035 7999999945", "490196227 7999999953", "928571477 7999999961", "4924975 7999999969", "1000000044 7999999977", "15309947 7999999985", "504345691 7999999993", "52392027 8000000001", "4770064 8000000009"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
17
codeforces
8fa6e1aca0e2b6bce302b0b112f22de6
Letter
A boy Bob likes to draw. Not long ago he bought a rectangular graph (checked) sheet with *n* rows and *m* columns. Bob shaded some of the squares on the sheet. Having seen his masterpiece, he decided to share it with his elder brother, who lives in Flatland. Now Bob has to send his picture by post, but because of the world economic crisis and high oil prices, he wants to send his creation, but to spend as little money as possible. For each sent square of paper (no matter whether it is shaded or not) Bob has to pay 3.14 burles. Please, help Bob cut out of his masterpiece a rectangle of the minimum cost, that will contain all the shaded squares. The rectangle's sides should be parallel to the sheet's sides. The first line of the input data contains numbers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=50), *n* — amount of lines, and *m* — amount of columns on Bob's sheet. The following *n* lines contain *m* characters each. Character «.» stands for a non-shaded square on the sheet, and «*» — for a shaded square. It is guaranteed that Bob has shaded at least one square. Output the required rectangle of the minimum cost. Study the output data in the sample tests to understand the output format better. Sample Input 6 7 ....... ..***.. ..*.... ..***.. ..*.... ..***.. 3 3 *** *.* *** Sample Output *** *.. *** *.. *** *** *.* ***
{"inputs": ["6 7\n.......\n..***..\n..*....\n..***..\n..*....\n..***..", "3 3\n***\n*.*\n***", "1 1\n*", "2 1\n*\n*", "5 1\n.\n*\n.\n.\n.", "1 6\n*****.", "2 2\n..\n*.", "8 2\n..\n..\n..\n..\n..\n*.\n..\n..", "50 1\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n*\n.\n*\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n*\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.", "2 1\n*\n.", "5 1\n*\n*\n*\n*\n*", "2 2\n*.\n..", "3 4\n...*\n*...\n..*.", "8 2\n**\n**\n**\n**\n**\n**\n**\n**", "50 1\n.\n*\n*\n*\n.\n.\n*\n.\n*\n*\n*\n*\n*\n*\n*\n.\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n.\n.\n.\n.\n*\n*\n.\n*\n*\n.\n.\n.\n.\n*\n*\n.\n.\n.\n.\n.\n."], "outputs": ["***\n*..\n***\n*..\n***", "***\n*.*\n***", "*", "*\n*", "*", "*****", "*", "*", "*\n.\n*\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n*", "*", "*\n*\n*\n*\n*", "*", "...*\n*...\n..*.", "**\n**\n**\n**\n**\n**\n**\n**", "*\n*\n*\n.\n.\n*\n.\n*\n*\n*\n*\n*\n*\n*\n.\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n.\n.\n.\n.\n*\n*\n.\n*\n*\n.\n.\n.\n.\n*\n*"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
218
codeforces
8fc062d952d56f65554254a2fbe9f3e8
none
Petya loves lucky numbers very much. Everybody knows that lucky numbers are positive integers whose decimal record contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Petya loves long lucky numbers very much. He is interested in the minimum lucky number *d* that meets some condition. Let *cnt*(*x*) be the number of occurrences of number *x* in number *d* as a substring. For example, if *d*<==<=747747, then *cnt*(4)<==<=2, *cnt*(7)<==<=4, *cnt*(47)<==<=2, *cnt*(74)<==<=2. Petya wants the following condition to fulfil simultaneously: *cnt*(4)<==<=*a*1, *cnt*(7)<==<=*a*2, *cnt*(47)<==<=*a*3, *cnt*(74)<==<=*a*4. Petya is not interested in the occurrences of other numbers. Help him cope with this task. The single line contains four integers *a*1, *a*2, *a*3 and *a*4 (1<=≤<=*a*1,<=*a*2,<=*a*3,<=*a*4<=≤<=106). On the single line print without leading zeroes the answer to the problem — the minimum lucky number *d* such, that *cnt*(4)<==<=*a*1, *cnt*(7)<==<=*a*2, *cnt*(47)<==<=*a*3, *cnt*(74)<==<=*a*4. If such number does not exist, print the single number "-1" (without the quotes). Sample Input 2 2 1 1 4 7 3 1 Sample Output 4774 -1
{"inputs": ["2 2 1 1", "4 7 3 1", "4 7 4 7", "1 1 1 1", "2 2 1 2", "2 1 2 1", "2 2 2 1", "3 3 1 1", "3 2 1 2", "2 1 3 1", "7 7 1 1", "4 7 2 1", "3 3 2 2", "4 3 2 1", "4 4 2 2", "1000000 1000000 1 1", "1000000 1 1 1", "10 10 3 5", "10 10 3 7", "1 7 1 1", "8 3 2 1", "1000000 1000000 1000000 1000000", "4584 45854 25 685", "1 1 1 2", "3 1000000 3 1", "4 58458 2 1", "845 8549 54 8", "1000000 1000000 100000 100000", "1000000 1000000 499 500", "1000000 1000000 100000 100001", "845488 44884 9945 9944", "7 7 4 5", "7 8 5 4", "1000000 1000000 400000 400001", "4585 4588 98 99", "1000000 2 1 1", "2 100000 1 2", "86451 754 85 84", "98654 4844 1001 1000", "5 5 1 2", "5 5 2 1", "4 4 1 1", "4 4 2 2", "4 4 3 3", "10 9 4 5", "100 100 4 5", "1000000 1000000 1 2", "1000000 1000000 47 46", "1000000 1000000 999999 1000000", "54585 4584 458 954", "6 6 1 3", "6 6 2 3", "6 10 2 1", "7 3 1 1", "47 74 8 9", "458445 445 6 7", "1000000 1000000 10000 10001", "1000000 1000000 978 977", "7 1000 1 2", "1 10 1 1", "70 60 20 21", "57 59 3 4", "10 10 5 5", "69 84 25 24", "25 94 11 12", "1 1000000 4 5", "7 1000000 2 3", "1000000 1 1 1", "45 65 31 32", "31 32 30 31", "1 1000000 1 1", "2 1000000 1 1", "50000 1000000 1 1", "74544 1 1 1", "2 2 3 4", "1 1000 2 1", "1 10 1 2", "1000000 1000000 1000000 999999", "1 2 1 1", "2 1 1 1", "2 2 2 1", "2 2 2 2", "1 3 1 1", "1 4 1 1", "2 3 2 2", "2 5 2 2", "1 2 2 1", "10 100 2 2", "3 4 3 3", "30 30 29 29", "10 10 1 2", "999999 1000000 999999 999999", "10 11 1 1", "10 10 2 2", "100 200 5 5", "10 11 10 10", "5 10 2 3", "6 8 1 1", "1 9 2 2"], "outputs": ["4774", "-1", "-1", "-1", "7474", "-1", "4747", "447774", "74474", "-1", "44444477777774", "44474777777", "474774", "4447477", "44747774", "4444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444...", "4444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444...", "-1", "-1", "74777777", "44444447477", "-1", "-1", "-1", "-1", "4447477777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777...", "-1", "4444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444...", "7444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444...", "7444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444...", "4444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444...", "74447474747774", "444747474747777", "7444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444...", "7444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444...", "4444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444...", "7477777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777...", "4444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444...", "4444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444...", "7444477774", "4444747777", "44477774", "44747774", "47474774", "7444444747474777774", "74444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444447474747777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777774", "7444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444...", "4444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444...", "7474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747...", "-1", "-1", "744447477774", "4444474777777777", "4444447774", "7444444444444444444444444444444444444444747474747474747777777777777777777777777777777777777777777777777777777777777777774", "7444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444...", "7444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444...", "4444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444...", "7444444777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777...", "74777777777", "7444444444444444444444444444444444444444444444444447474747474747474747474747474747474747477777777777777777777777777777777777777774", "74444444444444444444444444444444444444444444444444444447474777777777777777777777777777777777777777777777777777777774", "44444747474747777774", "444444444444444444444444444444444444444444444747474747474747474747474747474747474747474747474777777777777777777777777777777777777777777777777777777777777", "74444444444444474747474747474747474777777777777777777777777777777777777777777777777777777777777777777777777777777777774", "-1", "7444447477777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777...", "4444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444...", "74444444444444474747474747474747474747474747474747474747474747474747474747477777777777777777777777777777777774", "747474747474747474747474747474747474747474747474747474747474774", "7477777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777...", "4777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777...", "4444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444...", "4444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444...", "-1", "-1", "-1", "4747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474...", "747", "474", "4747", "-1", "7477", "74777", "74747", "7474777", "-1", "44444444747777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777774", "7474747", "474747474747474747474747474747474747474747474747474747474774", "74444444447777777774", "7474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747...", "444444444777777777774", "44444444747777777774", "444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444447474747477777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777774", "747474747474747474747", "744474777777774", "44444777777774", "-1"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
6
codeforces
8fca4ffe8f07d1e257b834639a4873d8
Hulk
Dr. Bruce Banner hates his enemies (like others don't). As we all know, he can barely talk when he turns into the incredible Hulk. That's why he asked you to help him to express his feelings. Hulk likes the Inception so much, and like that his feelings are complicated. They have *n* layers. The first layer is hate, second one is love, third one is hate and so on... For example if *n*<==<=1, then his feeling is "I hate it" or if *n*<==<=2 it's "I hate that I love it", and if *n*<==<=3 it's "I hate that I love that I hate it" and so on. Please help Dr. Banner. The only line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of layers of love and hate. Print Dr.Banner's feeling in one line. Sample Input 1 2 3 Sample Output I hate it I hate that I love it I hate that I love that I hate it
{"inputs": ["1", "2", "3", "4", "5", "10", "18", "19", "76", "77", "81", "82", "85", "86", "100", "99", "98", "33", "34", "57", "100"], "outputs": ["I hate it", "I hate that I love it", "I hate that I love that I hate it", "I hate that I love that I hate that I love it", "I hate that I love that I hate that I love that I hate it", "I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love it", "I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love it", "I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate it", "I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate ...", "I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate ...", "I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate ...", "I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate ...", "I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate ...", "I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate ...", "I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate ...", "I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate ...", "I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate ...", "I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate it", "I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love it", "I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate ...", "I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate ..."]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
532
codeforces
8fd162f8011e9ed6789a81a11aa77d54
Winter is here
Winter is here at the North and the White Walkers are close. John Snow has an army consisting of *n* soldiers. While the rest of the world is fighting for the Iron Throne, he is going to get ready for the attack of the White Walkers. He has created a method to know how strong his army is. Let the *i*-th soldier’s strength be *a**i*. For some *k* he calls *i*1,<=*i*2,<=...,<=*i**k* a clan if *i*1<=&lt;<=*i*2<=&lt;<=*i*3<=&lt;<=...<=&lt;<=*i**k* and *gcd*(*a**i*1,<=*a**i*2,<=...,<=*a**i**k*)<=&gt;<=1 . He calls the strength of that clan *k*·*gcd*(*a**i*1,<=*a**i*2,<=...,<=*a**i**k*). Then he defines the strength of his army by the sum of strengths of all possible clans. Your task is to find the strength of his army. As the number may be very large, you have to print it modulo 1000000007 (109<=+<=7). Greatest common divisor (gcd) of a sequence of integers is the maximum possible integer so that each element of the sequence is divisible by it. The first line contains integer *n* (1<=≤<=*n*<=≤<=200000) — the size of the army. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=1000000) — denoting the strengths of his soldiers. Print one integer — the strength of John Snow's army modulo 1000000007 (109<=+<=7). Sample Input 3 3 3 1 4 2 3 4 6 Sample Output 12 39
{"inputs": ["3\n3 3 1", "4\n2 3 4 6"], "outputs": ["12", "39"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
5
codeforces
902081dac1e789e7037f497776442362
Recover Polygon (easy)
The zombies are gathering in their secret lair! Heidi will strike hard to destroy them once and for all. But there is a little problem... Before she can strike, she needs to know where the lair is. And the intel she has is not very good. Heidi knows that the lair can be represented as a rectangle on a lattice, with sides parallel to the axes. Each vertex of the polygon occupies an integer point on the lattice. For each cell of the lattice, Heidi can check the level of Zombie Contamination. This level is an integer between 0 and 4, equal to the number of corners of the cell that are inside or on the border of the rectangle. As a test, Heidi wants to check that her Zombie Contamination level checker works. Given the output of the checker, Heidi wants to know whether it could have been produced by a single non-zero area rectangular-shaped lair (with axis-parallel sides). The first line of each test case contains one integer *N*, the size of the lattice grid (5<=≤<=*N*<=≤<=50). The next *N* lines each contain *N* characters, describing the level of Zombie Contamination of each cell in the lattice. Every character of every line is a digit between 0 and 4. Cells are given in the same order as they are shown in the picture above: rows go in the decreasing value of *y* coordinate, and in one row cells go in the order of increasing *x* coordinate. This means that the first row corresponds to cells with coordinates (1,<=*N*),<=...,<=(*N*,<=*N*) and the last row corresponds to cells with coordinates (1,<=1),<=...,<=(*N*,<=1). The first line of the output should contain Yes if there exists a single non-zero area rectangular lair with corners on the grid for which checking the levels of Zombie Contamination gives the results given in the input, and No otherwise. Sample Input 6 000000 000000 012100 024200 012100 000000 Sample Output Yes
{"inputs": ["6\n000000\n000000\n012100\n024200\n012100\n000000", "6\n000000\n012210\n024420\n012210\n000000\n000000", "6\n000100\n001210\n002420\n001210\n000000\n000000", "10\n0000000000\n0122210000\n0244420100\n0122210000\n0000000000\n0000000000\n0000000000\n0000000000\n0000000000\n0000000000", "10\n0000000000\n0000000000\n0000000000\n0000000000\n0000000000\n0000000000\n0012100000\n0024200000\n0012100000\n0000000000", "9\n000000000\n000000000\n012221000\n024442000\n012221000\n000000000\n000000000\n000000010\n000000000", "9\n000000000\n012222100\n024444200\n024444200\n024444200\n024444200\n024444200\n012222100\n000000000", "8\n00000000\n00001210\n00002420\n00002020\n00001210\n00000000\n00000000\n00000000", "8\n00000000\n00000000\n01210000\n02420000\n01210000\n00000000\n00000000\n00000000", "7\n0000000\n0000000\n0000000\n1122210\n0244420\n0122210\n0000000", "7\n0000000\n0012210\n0024420\n0012210\n0000000\n0000000\n0000000", "6\n000000\n000000\n001100\n001200\n000000\n000000", "6\n000000\n000000\n002200\n002200\n000000\n000000", "6\n000000\n000000\n003300\n003300\n000000\n000000", "6\n000000\n001100\n013310\n013310\n001100\n000000"], "outputs": ["Yes", "Yes", "No", "No", "Yes", "No", "Yes", "No", "Yes", "No", "Yes", "No", "No", "No", "No"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
5
codeforces
903195a712890e0984e95392fc3fad6d
Positions in Permutations
Permutation *p* is an ordered set of integers *p*1,<=<=*p*2,<=<=...,<=<=*p**n*, consisting of *n* distinct positive integers, each of them doesn't exceed *n*. We'll denote the *i*-th element of permutation *p* as *p**i*. We'll call number *n* the size or the length of permutation *p*1,<=<=*p*2,<=<=...,<=<=*p**n*. We'll call position *i* (1<=≤<=*i*<=≤<=*n*) in permutation *p*1,<=*p*2,<=...,<=*p**n* good, if |*p*[*i*]<=-<=*i*|<==<=1. Count the number of permutations of size *n* with exactly *k* good positions. Print the answer modulo 1000000007 (109<=+<=7). The single line contains two space-separated integers *n* and *k* (1<=≤<=*n*<=≤<=1000,<=0<=≤<=*k*<=≤<=*n*). Print the number of permutations of length *n* with exactly *k* good positions modulo 1000000007 (109<=+<=7). Sample Input 1 0 2 1 3 2 4 1 7 4 Sample Output 1 0 4 6 328
{"inputs": ["1 0", "2 1", "3 2", "4 1", "7 4", "7 7", "8 4", "8 5", "10 3", "20 0", "100 99", "13 13", "100 100", "1000 0", "1000 1", "1000 2", "1000 10", "1000 99", "1000 500", "1000 700", "1000 900", "1000 999", "1000 998", "1000 1000", "999 0", "999 1", "999 5", "999 13", "999 300", "999 600", "999 999", "999 989", "999 998", "10 0", "5 0", "5 1", "5 2", "5 3", "5 4", "5 5", "4 4", "4 3", "4 2", "1 1", "2 2", "3 1", "3 3", "2 0", "3 0"], "outputs": ["1", "0", "4", "6", "328", "0", "2658", "688", "614420", "111008677", "2450", "0", "1", "845393494", "418947603", "819706485", "305545369", "115316732", "979041279", "642759746", "301804159", "249500", "583666213", "1", "184907578", "167859862", "642835575", "740892203", "562270116", "553332041", "0", "254295912", "250000", "543597", "21", "36", "42", "12", "9", "0", "1", "2", "10", "0", "1", "0", "0", "1", "2"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
2
codeforces
903758cfd129ec5da50a446fab0de40f
Mahmoud and Ehab and the function
Dr. Evil is interested in math and functions, so he gave Mahmoud and Ehab array *a* of length *n* and array *b* of length *m*. He introduced a function *f*(*j*) which is defined for integers *j*, which satisfy 0<=≤<=*j*<=≤<=*m*<=-<=*n*. Suppose, *c**i*<==<=*a**i*<=-<=*b**i*<=+<=*j*. Then *f*(*j*)<==<=|*c*1<=-<=*c*2<=+<=*c*3<=-<=*c*4... *c**n*|. More formally, . Dr. Evil wants Mahmoud and Ehab to calculate the minimum value of this function over all valid *j*. They found it a bit easy, so Dr. Evil made their task harder. He will give them *q* update queries. During each update they should add an integer *x**i* to all elements in *a* in range [*l**i*;*r**i*] i.e. they should add *x**i* to *a**l**i*,<=*a**l**i*<=+<=1,<=... ,<=*a**r**i* and then they should calculate the minimum value of *f*(*j*) for all valid *j*. Please help Mahmoud and Ehab. The first line contains three integers *n*,<=*m* and *q* (1<=≤<=*n*<=≤<=*m*<=≤<=105, 1<=≤<=*q*<=≤<=105) — number of elements in *a*, number of elements in *b* and number of queries, respectively. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n*. (<=-<=109<=≤<=*a**i*<=≤<=109) — elements of *a*. The third line contains *m* integers *b*1,<=*b*2,<=...,<=*b**m*. (<=-<=109<=≤<=*b**i*<=≤<=109) — elements of *b*. Then *q* lines follow describing the queries. Each of them contains three integers *l**i* *r**i* *x**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=*n*, <=-<=109<=≤<=*x*<=≤<=109) — range to be updated and added value. The first line should contain the minimum value of the function *f* before any update. Then output *q* lines, the *i*-th of them should contain the minimum value of the function *f* after performing the *i*-th update . Sample Input 5 6 3 1 2 3 4 5 1 2 3 4 5 6 1 1 10 1 1 -9 1 5 -1 Sample Output 0 9 0 0
{"inputs": ["5 6 3\n1 2 3 4 5\n1 2 3 4 5 6\n1 1 10\n1 1 -9\n1 5 -1", "1 1 1\n937982044\n179683049\n1 1 821220804"], "outputs": ["0\n9\n0\n0", "758298995\n1579519799"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1
codeforces
904ddf9a4d594b95a85d8cf3bef73636
Turn Off The TV
Luba needs your help again! Luba has *n* TV sets. She knows that *i*-th TV set will be working from moment of time *l**i* till moment *r**i*, inclusive. Luba wants to switch off one of TV sets in order to free the socket. Let's call some TV set redundant if after switching it off the number of integer moments of time when at least one of TV sets is working won't decrease. Luba will be very upset if she has to switch off a non-redundant TV set. Help Luba by telling her the index of some redundant TV set. If there is no any, print -1. The first line contains one integer number *n* (1<=≤<=*n*<=≤<=2·105) — the number of TV sets. Then *n* lines follow, each of them containing two integer numbers *l**i*,<=*r**i* (0<=≤<=*l**i*<=≤<=*r**i*<=≤<=109) denoting the working time of *i*-th TV set. If there is no any redundant TV set, print -1. Otherwise print the index of any redundant TV set (TV sets are indexed from 1 to *n*). If there are multiple answers, print any of them. Sample Input 3 1 3 4 6 1 7 2 0 10 0 10 3 1 2 3 4 6 8 3 1 2 2 3 3 4 Sample Output 1 1 -1 2
{"inputs": ["3\n1 3\n4 6\n1 7", "2\n0 10\n0 10", "3\n1 2\n3 4\n6 8", "3\n1 2\n2 3\n3 4", "3\n0 500000000\n500000001 1000000000\n0 1000000000", "3\n1 5\n2 4\n6 10", "10\n4 4\n5 9\n5 7\n2 8\n6 10\n4 10\n1 3\n8 9\n0 0\n5 7", "2\n1 3\n2 4", "1\n8 9", "8\n13 17\n83 89\n31 33\n7 13\n52 52\n88 89\n29 30\n16 22", "4\n63 63\n12 34\n17 29\n58 91", "3\n1 10\n5 15\n10 20", "2\n1 3\n1 6", "2\n1 2\n1 3", "3\n5 6\n1 3\n1 4", "3\n1 4\n2 100\n4 5", "4\n1 1\n3 3\n4 7\n4 5", "3\n2 3\n3 4\n1 2", "1\n0 0", "6\n99 100\n65 65\n34 34\n16 18\n65 67\n88 88", "2\n50 67\n54 64", "3\n1 3\n2 100\n3 5", "3\n57 90\n35 45\n18 52", "4\n14 15\n46 73\n15 40\n28 53", "3\n37 38\n51 54\n28 28", "2\n64 66\n47 61", "4\n50 68\n63 67\n67 69\n11 12", "4\n42 62\n93 103\n34 62\n5 12", "6\n42 60\n78 107\n6 38\n58 81\n70 105\n70 105", "5\n71 71\n21 22\n58 58\n57 57\n16 16", "7\n28 42\n70 75\n83 92\n19 22\n26 32\n85 99\n30 39", "3\n8 28\n80 110\n39 81", "7\n90 115\n87 113\n2 26\n39 40\n91 112\n42 53\n65 79", "7\n12 13\n26 28\n9 11\n15 15\n8 10\n22 24\n5 7", "7\n3 5\n26 31\n11 15\n2 4\n16 18\n4 4\n7 12", "3\n1 5\n1 2\n4 5", "3\n999999995 999999997\n999999998 1000000000\n999999996 999999999", "4\n1 2\n4 6\n4 10\n200 300"], "outputs": ["1", "1", "-1", "2", "1", "2", "1", "-1", "-1", "6", "1", "2", "1", "1", "2", "3", "4", "1", "-1", "2", "2", "3", "2", "-1", "-1", "-1", "2", "1", "5", "-1", "7", "-1", "5", "-1", "6", "2", "3", "2"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
9
codeforces
9051057a015389e58fc1a40a5b2455e2
Mail Stamps
One day Bob got a letter in an envelope. Bob knows that when Berland's post officers send a letter directly from city «A» to city «B», they stamp it with «A B», or «B A». Unfortunately, often it is impossible to send a letter directly from the city of the sender to the city of the receiver, that's why the letter is sent via some intermediate cities. Post officers never send a letter in such a way that the route of this letter contains some city more than once. Bob is sure that the post officers stamp the letters accurately. There are *n* stamps on the envelope of Bob's letter. He understands that the possible routes of this letter are only two. But the stamps are numerous, and Bob can't determine himself none of these routes. That's why he asks you to help him. Find one of the possible routes of the letter. The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — amount of mail stamps on the envelope. Then there follow *n* lines with two integers each — description of the stamps. Each stamp is described with indexes of the cities between which a letter is sent. The indexes of cities are integers from 1 to 109. Indexes of all the cities are different. Every time the letter is sent from one city to another, exactly one stamp is put on the envelope. It is guaranteed that the given stamps correspond to some valid route from some city to some other city. Output *n*<=+<=1 numbers — indexes of cities in one of the two possible routes of the letter. Sample Input 2 1 100 100 2 3 3 1 100 2 3 2 Sample Output 2 100 1 100 2 3 1
{"inputs": ["2\n1 100\n100 2", "3\n3 1\n100 2\n3 2", "3\n458744979 589655889\n248228386 824699605\n458744979 824699605", "4\n90104473 221011623\n18773664 221011623\n90104473 74427905\n74427905 186329050", "5\n695442143 421284135\n641835294 542627184\n852367357 120042890\n641835294 852367357\n542627184 421284135", "6\n264896923 2497658\n57071588 447086061\n2497658 483723090\n57071588 264896923\n158310110 483723090\n158310110 72866107", "1\n1 1000000000", "1\n1000000000 999999999", "10\n661239801 721746596\n225324231 116454751\n687002568 865423160\n799202882 865423160\n661239801 116454751\n387882517 687002568\n748798833 721746596\n179630172 225324231\n945958362 387882517\n179630172 945958362", "21\n280810160 291988863\n760364563 140163983\n16417017 364832782\n400253359 677358550\n597688496 794948223\n400253359 603304541\n589408417 603304541\n385039298 307729574\n293170375 805849550\n140163983 219301181\n732214548 760364563\n307729574 280810160\n131915938 219301181\n4615652 347722938\n396478457 805849550\n16417017 732214548\n4615652 677358550\n131915938 589408417\n291988863 364832782\n396478457 794948223\n385039298 597688496", "1\n2105127 227379126"], "outputs": ["2 100 1 ", "100 2 3 1 ", "589655889 458744979 824699605 248228386 ", "186329050 74427905 90104473 221011623 18773664 ", "695442143 421284135 542627184 641835294 852367357 120042890 ", "447086061 57071588 264896923 2497658 483723090 158310110 72866107 ", "1000000000 1 ", "1000000000 999999999 ", "799202882 865423160 687002568 387882517 945958362 179630172 225324231 116454751 661239801 721746596 748798833 ", "347722938 4615652 677358550 400253359 603304541 589408417 131915938 219301181 140163983 760364563 732214548 16417017 364832782 291988863 280810160 307729574 385039298 597688496 794948223 396478457 805849550 293170375 ", "227379126 2105127 "]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
25
codeforces
909a49d6c60a9180e265a01863223410
PFAST Inc.
When little Petya grew up and entered the university, he started to take part in АСМ contests. Later he realized that he doesn't like how the АСМ contests are organised: the team could only have three members (and he couldn't take all his friends to the competitions and distribute the tasks between the team members efficiently), so he decided to organize his own contests PFAST Inc. — Petr and Friends Are Solving Tasks Corporation. PFAST Inc. rules allow a team to have unlimited number of members. To make this format of contests popular he organised his own tournament. To create the team he will prepare for the contest organised by the PFAST Inc. rules, he chose several volunteers (up to 16 people) and decided to compile a team from them. Petya understands perfectly that if a team has two people that don't get on well, then the team will perform poorly. Put together a team with as many players as possible given that all players should get on well with each other. The first line contains two integer numbers *n* (1<=≤<=*n*<=≤<=16) — the number of volunteers, and *m* () — the number of pairs that do not get on. Next *n* lines contain the volunteers' names (each name is a non-empty string consisting of no more than 10 uppercase and/or lowercase Latin letters). Next *m* lines contain two names — the names of the volunteers who do not get on. The names in pair are separated with a single space. Each pair of volunteers who do not get on occurs exactly once. The strings are case-sensitive. All *n* names are distinct. The first output line should contain the single number *k* — the number of people in the sought team. Next *k* lines should contain the names of the sought team's participants in the lexicographical order. If there are several variants to solve the problem, print any of them. Petya might not be a member of the sought team. Sample Input 3 1 Petya Vasya Masha Petya Vasya 3 0 Pasha Lesha Vanya Sample Output 2 Masha Petya 3 Lesha Pasha Vanya
{"inputs": ["3 1\nPetya\nVasya\nMasha\nPetya Vasya", "3 0\nPasha\nLesha\nVanya", "7 12\nPasha\nLesha\nVanya\nTaras\nNikita\nSergey\nAndrey\nPasha Taras\nPasha Nikita\nPasha Andrey\nPasha Sergey\nLesha Taras\nLesha Nikita\nLesha Andrey\nLesha Sergey\nVanya Taras\nVanya Nikita\nVanya Andrey\nVanya Sergey", "2 0\nAndrey\nTaras", "16 0\nTaras\nNikita\nSergey\nAndrey\nRomka\nAlexey\nUra\nDenis\nEgor\nVadim\nAlena\nOlya\nVanya\nBrus\nJohn\nAlice", "6 6\nAlena\nOlya\nVanya\nBrus\nJohn\nAlice\nAlena John\nAlena Alice\nOlya John\nOlya Alice\nVanya John\nVanya Alice", "7 6\nAlena\nOlya\nVanya\nBrus\nJohn\nAlice\nMariana\nAlena John\nAlena Alice\nOlya John\nOlya Alice\nVanya John\nVanya Alice", "1 0\nPetr", "2 0\nNgzlPJgFgz\nQfpagVpWz", "2 1\ncLWdg\nGoWegdDRp\nGoWegdDRp cLWdg", "3 0\nr\nyVwqs\nsdTDerOyhp", "3 3\nvRVatwL\nWmkUGiYEn\nuvvsXKXcJ\nWmkUGiYEn vRVatwL\nuvvsXKXcJ vRVatwL\nuvvsXKXcJ WmkUGiYEn", "16 11\njA\nkyRNTE\neY\nToLcqN\nbnenhMxiK\nzlkOe\nXCKZ\neaQrds\nqUdInpi\nKgPQA\nmQIl\ninOCWEZHxy\nyA\nPIZRMOu\nXtueKFM\nfRNwNn\ninOCWEZHxy qUdInpi\nKgPQA zlkOe\ninOCWEZHxy KgPQA\nfRNwNn XCKZ\ninOCWEZHxy eY\nyA mQIl\ninOCWEZHxy ToLcqN\nyA KgPQA\nqUdInpi ToLcqN\nqUdInpi eaQrds\nPIZRMOu eY", "12 12\njWuGgOjV\nWs\njTZQMyH\nULp\nUfsnPRt\nk\nbPKrnP\nW\nJOaQdgglDG\nAodc\ncpRjAUyYIW\nMrjB\nbPKrnP ULp\nk Ws\ncpRjAUyYIW k\nULp jTZQMyH\nbPKrnP jWuGgOjV\ncpRjAUyYIW jTZQMyH\nW ULp\nk jTZQMyH\nk ULp\nMrjB ULp\ncpRjAUyYIW Aodc\nW k", "11 17\njFTNgFBO\ntZDgmdF\nIjeDjoj\nBEMAaYkNb\nRZRQl\ntK\nlNHWt\nIdG\nLAbVLYiY\notOBsWqJuo\nUoTy\ntK BEMAaYkNb\nBEMAaYkNb jFTNgFBO\nIjeDjoj tZDgmdF\nRZRQl jFTNgFBO\nlNHWt tZDgmdF\nRZRQl tZDgmdF\nUoTy LAbVLYiY\nBEMAaYkNb IjeDjoj\nIdG BEMAaYkNb\nLAbVLYiY tK\nLAbVLYiY jFTNgFBO\nUoTy IjeDjoj\nlNHWt jFTNgFBO\nlNHWt BEMAaYkNb\ntK IjeDjoj\nUoTy RZRQl\nBEMAaYkNb tZDgmdF", "11 13\ncZAMfd\nSWQnweM\nKlQW\nWRsnNZT\nix\nUC\nLWqsVHcWec\nfeb\ncBy\ntvk\nRXDlX\nfeb SWQnweM\ncBy WRsnNZT\nLWqsVHcWec KlQW\nRXDlX feb\nLWqsVHcWec cZAMfd\ncBy UC\nWRsnNZT SWQnweM\nRXDlX cBy\ntvk UC\ncBy SWQnweM\nUC KlQW\nRXDlX KlQW\nUC WRsnNZT", "4 2\nadQx\nrJGeodBycK\ntgPYZk\ncz\ncz tgPYZk\nrJGeodBycK adQx", "4 2\noVemoZhjW\nHspFEry\nhFO\njxt\nhFO HspFEry\njxt oVemoZhjW", "5 2\niBrgNFlNXd\nlnGPIV\nnb\nB\nVgqRcEOG\nlnGPIV iBrgNFlNXd\nB iBrgNFlNXd", "5 1\nWEYUdpYmZp\nfhNmMpjr\nydARivBg\ncilTtE\nyeXxkhPzB\nyeXxkhPzB cilTtE", "6 9\noySkmhCD\nUIKWj\nmHolKkBx\nQBikssqz\nZ\nzoFUJYa\nZ UIKWj\nQBikssqz oySkmhCD\nQBikssqz UIKWj\nZ oySkmhCD\nzoFUJYa UIKWj\nzoFUJYa Z\nzoFUJYa mHolKkBx\nzoFUJYa QBikssqz\nQBikssqz mHolKkBx", "6 1\nuPVIuLBuYM\nVejWyKCtbN\nqqjgF\nulBD\nDRNzxJU\nCOzbXWOt\nulBD qqjgF", "7 14\nFXCT\nn\no\nS\nMdFuonu\nmszv\nbqScOCw\nS o\nbqScOCw FXCT\nMdFuonu o\no n\nbqScOCw n\nmszv S\nbqScOCw MdFuonu\nmszv n\nS FXCT\nbqScOCw o\no FXCT\nmszv MdFuonu\nmszv FXCT\nbqScOCw mszv", "7 6\nj\nZ\nPZNeTyY\nm\na\nUj\nsuaaSiKcK\nUj PZNeTyY\na j\nPZNeTyY Z\nPZNeTyY j\nm PZNeTyY\nm j", "8 6\nU\nC\nPEElYwaxf\nVubTXNI\nJ\nIxZUHV\nhLNFnzmqFE\nDPPvwuWvmA\nhLNFnzmqFE IxZUHV\nIxZUHV C\nJ PEElYwaxf\nIxZUHV PEElYwaxf\nPEElYwaxf C\nJ VubTXNI", "8 12\nBkgxqAF\nKhq\nNpIfk\nkheqUyDVG\niRBkHlRpp\nZDaQY\nNG\nqN\nqN BkgxqAF\nNpIfk BkgxqAF\niRBkHlRpp BkgxqAF\niRBkHlRpp NpIfk\nNG Khq\niRBkHlRpp Khq\nNG ZDaQY\nNG iRBkHlRpp\nNG NpIfk\nqN Khq\nZDaQY kheqUyDVG\nNpIfk Khq", "9 5\nRFiow\naxgvtiBGbx\ngGBVZtI\nVWAxrqx\nmnASVEQI\ntZHzWGAvXc\nBeaCYhIRLy\nhTdUL\nFJd\nhTdUL RFiow\nhTdUL gGBVZtI\nFJd axgvtiBGbx\nFJd BeaCYhIRLy\nhTdUL axgvtiBGbx", "9 13\nYiUXqlBUx\nQNgYuX\ndPtyZ\nITtwRJCv\nLJ\nrAG\nOgxNq\nsitechE\nvVAAz\nOgxNq QNgYuX\nOgxNq dPtyZ\nsitechE rAG\nLJ QNgYuX\nQNgYuX YiUXqlBUx\nOgxNq LJ\nvVAAz OgxNq\nrAG dPtyZ\nvVAAz LJ\nvVAAz ITtwRJCv\nsitechE LJ\nrAG YiUXqlBUx\nsitechE QNgYuX", "9 6\nfLfek\nEQPcotnrp\nCaAlbwoIL\nVG\nNAZKIBiKT\noFy\njFluh\nKqHXRNya\nQSwgobA\noFy EQPcotnrp\nKqHXRNya jFluh\noFy NAZKIBiKT\njFluh oFy\njFluh fLfek\noFy fLfek", "9 14\nmoRNeufngu\nBSKI\nzXl\ngwmIDluW\nYFn\nHvasEgl\nXcAC\neVP\nAiOm\neVP BSKI\neVP YFn\nHvasEgl YFn\neVP XcAC\nAiOm HvasEgl\nXcAC YFn\nzXl moRNeufngu\neVP zXl\nHvasEgl BSKI\nXcAC gwmIDluW\nXcAC HvasEgl\nYFn moRNeufngu\nzXl BSKI\nHvasEgl gwmIDluW", "15 8\ncXeOANpvBF\nbkeDfi\nnsEUAKNxQI\noSIb\naU\nXYXYVo\nduZQ\naPkr\nPVrHpL\nmVgmv\nhHhukllwbf\nGkNPGYVxjY\nbgBjA\nslNKCLIlOv\nmPILXy\nbgBjA cXeOANpvBF\nGkNPGYVxjY cXeOANpvBF\nslNKCLIlOv GkNPGYVxjY\nGkNPGYVxjY mVgmv\nXYXYVo cXeOANpvBF\nslNKCLIlOv bkeDfi\nmVgmv aPkr\nslNKCLIlOv nsEUAKNxQI", "15 3\na\nYclKFJoaIA\nhalYcB\nbLOlPzAeQ\ntckjt\noDFijpx\nb\npz\nVDLb\nlCEHPibt\noF\npzJD\nMC\nqklsX\nTAU\npzJD tckjt\nqklsX oF\nMC pzJD", "16 8\nJIo\nINanHVnP\nKaxyCBWt\nkVfnsz\nRAwFYCrSvI\nF\nvIEWWIvh\nTGF\nFeuhJJwJ\nTngcmS\nSqI\nRmcaVngp\neGwhme\nlwaFfXzM\noabGmpvVH\nTMT\nFeuhJJwJ F\neGwhme FeuhJJwJ\nRmcaVngp SqI\nINanHVnP JIo\nSqI FeuhJJwJ\nF kVfnsz\nTGF F\nTMT TGF", "16 25\nbBZ\nEr\nZ\nrYJmfZLgmx\nPaJNrF\naHtRqSxOO\nD\nhsagsG\nMDuBOXrmWH\nSgjMQZ\nYXgWq\nxDwpppG\nSDY\nJwZWx\ncOzrgrBaE\nFJYX\nYXgWq SgjMQZ\nSDY PaJNrF\nFJYX rYJmfZLgmx\nhsagsG Er\nxDwpppG rYJmfZLgmx\naHtRqSxOO rYJmfZLgmx\nhsagsG bBZ\nJwZWx hsagsG\nFJYX cOzrgrBaE\nSDY YXgWq\nFJYX Z\nJwZWx rYJmfZLgmx\nD rYJmfZLgmx\nYXgWq Z\nrYJmfZLgmx Z\naHtRqSxOO bBZ\nSDY rYJmfZLgmx\ncOzrgrBaE D\nYXgWq hsagsG\nSDY aHtRqSxOO\ncOzrgrBaE xDwpppG\nSDY bBZ\nSDY Er\nJwZWx xDwpppG\nFJYX JwZWx", "16 37\ntIWi\nq\nIEAYCq\nXozwkum\nCC\niPwfd\nS\nXEf\nWqEiwkH\nWX\ne\nltmruh\nKGx\nauTUYZRC\nmeJa\nM\nmeJa q\nKGx e\nXEf Xozwkum\ne q\nauTUYZRC KGx\ne CC\nM CC\nM meJa\nWX CC\nWqEiwkH IEAYCq\nauTUYZRC WqEiwkH\nKGx WX\nmeJa KGx\nXEf q\nauTUYZRC XEf\nauTUYZRC IEAYCq\nWX XEf\nM XEf\nWqEiwkH q\nM KGx\nKGx CC\nM e\nWqEiwkH Xozwkum\nCC q\nS Xozwkum\nKGx tIWi\nWX q\nXEf S\nauTUYZRC S\nCC IEAYCq\nKGx IEAYCq\ne WqEiwkH\nM S\nauTUYZRC q\nS tIWi\nM ltmruh\nM iPwfd", "16 11\ntulhZxeKgo\nbrAXY\nyQUkaihDAg\nmwjlDVaktK\nweVtBIP\nzRwb\nds\nhXPfJrL\nAdIfP\nazQeXn\nB\nJlmscIUOxO\nZuxr\nV\nOfyLIUO\nuaMl\nhXPfJrL yQUkaihDAg\nweVtBIP yQUkaihDAg\nazQeXn hXPfJrL\nV tulhZxeKgo\nzRwb yQUkaihDAg\nds mwjlDVaktK\nzRwb brAXY\nyQUkaihDAg brAXY\nB yQUkaihDAg\nAdIfP mwjlDVaktK\nbrAXY tulhZxeKgo", "5 10\nTaras\nNikita\nSergey\nAndrey\nRomka\nTaras Romka\nTaras Nikita\nTaras Sergey\nTaras Andrey\nRomka Nikita\nRomka Sergey\nRomka Andrey\nNikita Sergey\nNikita Andrey\nSergey Andrey"], "outputs": ["2\nMasha\nPetya", "3\nLesha\nPasha\nVanya", "4\nAndrey\nNikita\nSergey\nTaras", "2\nAndrey\nTaras", "16\nAlena\nAlexey\nAlice\nAndrey\nBrus\nDenis\nEgor\nJohn\nNikita\nOlya\nRomka\nSergey\nTaras\nUra\nVadim\nVanya", "4\nAlena\nBrus\nOlya\nVanya", "5\nAlena\nBrus\nMariana\nOlya\nVanya", "1\nPetr", "2\nNgzlPJgFgz\nQfpagVpWz", "1\nGoWegdDRp", "3\nr\nsdTDerOyhp\nyVwqs", "1\nWmkUGiYEn", "10\nKgPQA\nPIZRMOu\nToLcqN\nXCKZ\nXtueKFM\nbnenhMxiK\neaQrds\njA\nkyRNTE\nmQIl", "8\nAodc\nJOaQdgglDG\nMrjB\nUfsnPRt\nW\nWs\nbPKrnP\njTZQMyH", "6\nIdG\nIjeDjoj\nLAbVLYiY\nRZRQl\nlNHWt\notOBsWqJuo", "6\nKlQW\nWRsnNZT\ncZAMfd\nfeb\nix\ntvk", "2\nadQx\ncz", "2\nHspFEry\njxt", "4\nB\nVgqRcEOG\nlnGPIV\nnb", "4\nWEYUdpYmZp\ncilTtE\nfhNmMpjr\nydARivBg", "3\nUIKWj\nmHolKkBx\noySkmhCD", "5\nCOzbXWOt\nDRNzxJU\nVejWyKCtbN\nqqjgF\nuPVIuLBuYM", "3\nFXCT\nMdFuonu\nn", "5\nUj\nZ\na\nm\nsuaaSiKcK", "5\nC\nDPPvwuWvmA\nJ\nU\nhLNFnzmqFE", "3\nBkgxqAF\nKhq\nZDaQY", "7\nBeaCYhIRLy\nRFiow\nVWAxrqx\naxgvtiBGbx\ngGBVZtI\nmnASVEQI\ntZHzWGAvXc", "4\nITtwRJCv\nLJ\nYiUXqlBUx\ndPtyZ", "7\nCaAlbwoIL\nEQPcotnrp\nKqHXRNya\nNAZKIBiKT\nQSwgobA\nVG\nfLfek", "4\nAiOm\nBSKI\nYFn\ngwmIDluW", "12\nGkNPGYVxjY\nPVrHpL\nXYXYVo\naPkr\naU\nbgBjA\nbkeDfi\nduZQ\nhHhukllwbf\nmPILXy\nnsEUAKNxQI\noSIb", "13\nMC\nTAU\nVDLb\nYclKFJoaIA\na\nb\nbLOlPzAeQ\nhalYcB\nlCEHPibt\noDFijpx\noF\npz\ntckjt", "11\nF\nINanHVnP\nKaxyCBWt\nRAwFYCrSvI\nRmcaVngp\nTMT\nTngcmS\neGwhme\nlwaFfXzM\noabGmpvVH\nvIEWWIvh", "8\nD\nEr\nJwZWx\nMDuBOXrmWH\nPaJNrF\nSgjMQZ\nZ\naHtRqSxOO", "8\nIEAYCq\nWX\nXozwkum\ne\niPwfd\nltmruh\nmeJa\ntIWi", "11\nAdIfP\nB\nJlmscIUOxO\nOfyLIUO\nV\nZuxr\nazQeXn\nbrAXY\nds\nuaMl\nweVtBIP", "1\nAndrey"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
28
codeforces
90b3babebf9e99d1cac2b06764636584
none
You are given a rectangular parallelepiped with sides of positive integer lengths $A$, $B$ and $C$. Find the number of different groups of three integers ($a$, $b$, $c$) such that $1\leq a\leq b\leq c$ and parallelepiped $A\times B\times C$ can be paved with parallelepipeds $a\times b\times c$. Note, that all small parallelepipeds have to be rotated in the same direction. For example, parallelepiped $1\times 5\times 6$ can be divided into parallelepipeds $1\times 3\times 5$, but can not be divided into parallelepipeds $1\times 2\times 3$. The first line contains a single integer $t$ ($1 \leq t \leq 10^5$) — the number of test cases. Each of the next $t$ lines contains three integers $A$, $B$ and $C$ ($1 \leq A, B, C \leq 10^5$) — the sizes of the parallelepiped. For each test case, print the number of different groups of three points that satisfy all given conditions. Sample Input 4 1 1 1 1 6 1 2 2 2 100 100 100 Sample Output 1 4 4 165
{"inputs": ["4\n1 1 1\n1 6 1\n2 2 2\n100 100 100", "10\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1", "10\n9 6 8\n5 5 2\n8 9 2\n2 7 9\n6 4 10\n1 1 8\n2 8 1\n10 6 3\n7 5 2\n9 5 4", "1\n100000 100000 100000"], "outputs": ["1\n4\n4\n165", "1\n1\n1\n1\n1\n1\n1\n1\n1\n1", "41\n6\n21\n12\n39\n4\n7\n26\n8\n18", "8436"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
2
codeforces
90c3ae3432be76316c44df8b294d09fc
Money Transfers
There are *n* banks in the city where Vasya lives, they are located in a circle, such that any two banks are neighbouring if their indices differ by no more than 1. Also, bank 1 and bank *n* are neighbours if *n*<=&gt;<=1. No bank is a neighbour of itself. Vasya has an account in each bank. Its balance may be negative, meaning Vasya owes some money to this bank. There is only one type of operations available: transfer some amount of money from any bank to account in any neighbouring bank. There are no restrictions on the size of the sum being transferred or balance requirements to perform this operation. Vasya doesn't like to deal with large numbers, so he asks you to determine the minimum number of operations required to change the balance of each bank account to zero. It's guaranteed, that this is possible to achieve, that is, the total balance of Vasya in all banks is equal to zero. The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100<=000) — the number of banks. The second line contains *n* integers *a**i* (<=-<=109<=≤<=*a**i*<=≤<=109), the *i*-th of them is equal to the initial balance of the account in the *i*-th bank. It's guaranteed that the sum of all *a**i* is equal to 0. Print the minimum number of operations required to change balance in each bank to zero. Sample Input 3 5 0 -5 4 -1 0 1 0 4 1 2 3 -6 Sample Output 1 2 3
{"inputs": ["3\n5 0 -5", "4\n-1 0 1 0", "4\n1 2 3 -6", "1\n0", "50\n108431864 128274949 -554057370 -384620666 -202862975 -803855410 -482167063 -55139054 -215901009 0 0 0 0 0 94325701 730397219 358214459 -673647271 -131397668 -377892440 0 0 0 0 0 -487994257 -360271553 639988328 489338210 -281060728 250208758 0 993242346 -213071841 -59752620 -864351041 -114363541 506279952 999648597 -173503559 -144629749 -559693009 0 -46793577 511999017 -343503822 -741715911 647437511 821346413 993112810", "6\n1 -1 1 -1 1 -1"], "outputs": ["1", "2", "3", "0", "36", "3"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
28
codeforces
90c94d1f5e83e4c8b0d3186dacb5a837
Good Number
Let's call a number *k*-good if it contains all digits not exceeding *k* (0,<=...,<=*k*). You've got a number *k* and an array *a* containing *n* numbers. Find out how many *k*-good numbers are in *a* (count each number every time it occurs in array *a*). The first line contains integers *n* and *k* (1<=≤<=*n*<=≤<=100, 0<=≤<=*k*<=≤<=9). The *i*-th of the following *n* lines contains integer *a**i* without leading zeroes (1<=≤<=*a**i*<=≤<=109). Print a single integer — the number of *k*-good numbers in *a*. Sample Input 10 6 1234560 1234560 1234560 1234560 1234560 1234560 1234560 1234560 1234560 1234560 2 1 1 10 Sample Output 10 1
{"inputs": ["10 6\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560", "2 1\n1\n10", "1 0\n1000000000", "1 1\n1000000000", "6 0\n10\n102\n120\n1032\n1212103\n1999999", "1 3\n1000000000", "1 9\n1000000000", "1 0\n1", "1 1\n1", "1 3\n1", "1 9\n1", "2 8\n123456780\n123", "2 8\n12345678\n1230", "6 1\n10\n102\n120\n1032\n1212103\n1999999", "6 2\n10\n102\n120\n1032\n1212103\n1999999", "6 3\n10\n102\n120\n1032\n1212103\n1999999", "6 9\n10\n102\n120\n1032\n1212103\n1999999", "1 2\n2220"], "outputs": ["10", "1", "1", "1", "5", "0", "0", "0", "0", "0", "0", "1", "0", "5", "4", "2", "0", "0"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
318
codeforces
90e34ecfae4b0a43ec885c28e8b50ef6
Фото на память - 2 (round version)
Прошло много лет, и на вечеринке снова встретились *n* друзей. С момента последней встречи техника шагнула далеко вперёд, появились фотоаппараты с автоспуском, и теперь не требуется, чтобы один из друзей стоял с фотоаппаратом, и, тем самым, оказывался не запечатлённым на снимке. Упрощенно процесс фотографирования можно описать следующим образом. На фотографии каждый из друзей занимает прямоугольник из пикселей: в стоячем положении *i*-й из них занимает прямоугольник ширины *w**i* пикселей и высоты *h**i* пикселей. Но также, при фотографировании каждый человек может лечь, и тогда он будет занимать прямоугольник ширины *h**i* пикселей и высоты *w**i* пикселей. Общая фотография будет иметь размеры *W*<=×<=*H*, где *W* — суммарная ширина всех прямоугольников-людей, а *H* — максимальная из высот. Друзья хотят определить, какую минимальную площадь может иметь общая фотография. Помогите им в этом. В первой строке следует целое число *n* (1<=≤<=*n*<=≤<=1000) — количество друзей. В последующих *n* строках следуют по два целых числа *w**i*,<=*h**i* (1<=≤<=*w**i*,<=*h**i*<=≤<=1000), обозначающие размеры прямоугольника, соответствующего *i*-му из друзей. Выведите единственное целое число, равное минимальной возможной площади фотографии, вмещающей всех друзей. Sample Input 3 10 1 20 2 30 3 3 3 1 2 2 4 3 1 5 10 Sample Output 180 21 50
{"inputs": ["3\n10 1\n20 2\n30 3", "3\n3 1\n2 2\n4 3", "1\n5 10", "10\n168 538\n836 439\n190 873\n206 47\n891 591\n939 481\n399 898\n859 466\n701 777\n629 222", "42\n13 62\n114 242\n265 839\n756 349\n298 476\n533 704\n348 277\n554 573\n654 112\n429 836\n574 766\n909 415\n163 891\n532 983\n873 457\n719 117\n1 302\n170 634\n166 585\n721 231\n208 609\n128 246\n845 726\n604 119\n859 110\n568 515\n656 913\n113 166\n794 566\n834 860\n983 596\n545 819\n167 9\n960 73\n260 607\n173 378\n417 938\n362 819\n800 939\n246 834\n746 440\n42 643", "3\n379 820\n923 407\n916 853", "3\n99 768\n477 885\n169 118", "3\n227 612\n223 259\n423 895", "3\n651 161\n480 32\n485 672", "3\n779 301\n34 214\n442 937", "3\n203 145\n780 692\n992 713", "3\n627 286\n37 65\n53 490", "3\n755 938\n487 543\n307 459", "3\n475 487\n41 20\n368 236", "3\n922 71\n719 26\n462 700", "2\n881 4\n788 2", "2\n1 304\n8 892", "3\n227 2\n223 9\n423 5", "3\n7 612\n3 259\n3 895", "4\n573 7\n169 9\n447 7\n947 3", "4\n3 817\n9 729\n7 407\n7 433", "10\n864 874\n534 702\n73 363\n856 895\n827 72\n435 468\n888 921\n814 703\n648 715\n384 781", "10\n489 685\n857 870\n736 221\n687 697\n166 360\n265 200\n738 519\n393 760\n66 176\n798 160", "1\n1 1", "1\n1000 1000", "1\n1 1000", "2\n1 1000\n1000 1", "2\n1 1\n1000 1000", "1\n1000 1", "2\n1 1\n1 1", "3\n1 4\n1 4\n1 1", "2\n2 1\n3 1", "2\n4 3\n2 1", "5\n78 94\n8 53\n81 8\n41 11\n57 57", "8\n1 8\n1 8\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1"], "outputs": ["180", "21", "50", "3478056", "13474964", "1512797", "614190", "731790", "455616", "728049", "1366821", "235752", "1307660", "352925", "515398", "5286", "8028", "6768", "11635", "19224", "21242", "4909752", "3231747", "1", "1000000", "1000", "2000", "1001000", "1000", "2", "9", "5", "15", "14418", "22"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
7
codeforces
912f39a3ff6a9f5dd8230e1c50920c4f
none
Little Chris is very keen on his toy blocks. His teacher, however, wants Chris to solve more problems, so he decided to play a trick on Chris. There are exactly *s* blocks in Chris's set, each block has a unique number from 1 to *s*. Chris's teacher picks a subset of blocks *X* and keeps it to himself. He will give them back only if Chris can pick such a non-empty subset *Y* from the remaining blocks, that the equality holds: For example, consider a case where *s*<==<=8 and Chris's teacher took the blocks with numbers 1, 4 and 5. One way for Chris to choose a set is to pick the blocks with numbers 3 and 6, see figure. Then the required sums would be equal: (1<=-<=1)<=+<=(4<=-<=1)<=+<=(5<=-<=1)<==<=(8<=-<=3)<=+<=(8<=-<=6)<==<=7. However, now Chris has exactly *s*<==<=106 blocks. Given the set *X* of blocks his teacher chooses, help Chris to find the required set *Y*! The first line of input contains a single integer *n* (1<=≤<=*n*<=≤<=5·105), the number of blocks in the set *X*. The next line contains *n* distinct space-separated integers *x*1, *x*2, ..., *x**n* (1<=≤<=*x**i*<=≤<=106), the numbers of the blocks in *X*. Note: since the size of the input and output could be very large, don't use slow output techniques in your language. For example, do not use input and output streams (cin, cout) in C++. In the first line of output print a single integer *m* (1<=≤<=*m*<=≤<=106<=-<=*n*), the number of blocks in the set *Y*. In the next line output *m* distinct space-separated integers *y*1, *y*2, ..., *y**m* (1<=≤<=*y**i*<=≤<=106), such that the required equality holds. The sets *X* and *Y* should not intersect, i.e. *x**i*<=≠<=*y**j* for all *i*, *j* (1<=≤<=*i*<=≤<=*n*; 1<=≤<=*j*<=≤<=*m*). It is guaranteed that at least one solution always exists. If there are multiple solutions, output any of them. Sample Input 3 1 4 5 1 1 Sample Output 2 999993 10000001 1000000
{"inputs": ["3\n1 4 5", "1\n1", "1\n1000000", "2\n2 999999", "9\n1 2 3 100 500000 500001 999901 999997 999999", "3\n999998 999999 1000000", "3\n1 2 3", "3\n5 345435 999996", "6\n1 10 100 1000 10000 1000000", "2\n1 1000000", "2\n500000 500001", "4\n1 2 999999 1000000", "10\n63649 456347 779 458642 201571 534312 583774 283450 377377 79066", "10\n1 100000 199999 299998 399997 499996 599995 699994 799993 899992"], "outputs": ["3\n999996 999997 1000000 ", "1\n1000000 ", "1\n1 ", "2\n1 1000000 ", "9\n4 5 6 7 999994 999995 999996 999998 1000000 ", "3\n1 2 3 ", "3\n999998 999999 1000000 ", "3\n1 654566 1000000 ", "6\n2 990001 999001 999901 999991 999999 ", "2\n2 999999 ", "2\n1 1000000 ", "4\n3 4 999997 999998 ", "10\n416227 465689 541359 543654 622624 716551 798430 920935 936352 999222 ", "10\n100009 200008 300007 400006 500005 600004 700003 800002 900001 1000000 "]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1
codeforces
9136cb00808749220dc6c0007520b499
Insomnia cure
«One dragon. Two dragon. Three dragon», — the princess was counting. She had trouble falling asleep, and she got bored of counting lambs when she was nine. However, just counting dragons was boring as well, so she entertained herself at best she could. Tonight she imagined that all dragons were here to steal her, and she was fighting them off. Every *k*-th dragon got punched in the face with a frying pan. Every *l*-th dragon got his tail shut into the balcony door. Every *m*-th dragon got his paws trampled with sharp heels. Finally, she threatened every *n*-th dragon to call her mom, and he withdrew in panic. How many imaginary dragons suffered moral or physical damage tonight, if the princess counted a total of *d* dragons? Input data contains integer numbers *k*,<=*l*,<=*m*,<=*n* and *d*, each number in a separate line (1<=≤<=*k*,<=*l*,<=*m*,<=*n*<=≤<=10, 1<=≤<=*d*<=≤<=105). Output the number of damaged dragons. Sample Input 1 2 3 4 12 2 3 4 5 24 Sample Output 12 17
{"inputs": ["1\n2\n3\n4\n12", "2\n3\n4\n5\n24", "1\n1\n1\n1\n100000", "10\n9\n8\n7\n6", "8\n4\n4\n3\n65437", "8\n4\n1\n10\n59392", "4\n1\n8\n7\n44835", "6\n1\n7\n2\n62982", "2\n7\n4\n9\n56937", "2\n9\n8\n1\n75083", "8\n7\n7\n6\n69038", "4\n4\n2\n3\n54481", "6\n4\n9\n8\n72628", "9\n7\n8\n10\n42357", "5\n6\n4\n3\n60504", "7\n2\n3\n8\n21754", "1\n2\n10\n4\n39901", "3\n4\n7\n1\n58048", "9\n10\n4\n6\n52003", "5\n10\n9\n3\n70149", "5\n5\n5\n10\n55592", "1\n5\n2\n6\n49547", "3\n7\n7\n7\n84046", "10\n2\n1\n8\n63537", "7\n2\n10\n5\n81684", "7\n1\n6\n8\n99831", "3\n9\n3\n3\n61082", "5\n5\n8\n9\n79228", "1\n5\n5\n6\n89535", "5\n5\n2\n1\n7682", "7\n4\n8\n8\n25829", "3\n4\n3\n3\n87079", "5\n8\n4\n9\n5226", "4\n9\n6\n6\n1070", "10\n10\n10\n10\n100000", "1\n1\n1\n1\n1", "10\n10\n10\n10\n1", "10\n10\n1\n10\n10", "10\n10\n1\n10\n100", "2\n2\n2\n2\n1"], "outputs": ["12", "17", "100000", "0", "32718", "59392", "44835", "62982", "35246", "75083", "24656", "36320", "28244", "16540", "36302", "15539", "39901", "58048", "21956", "32736", "11118", "49547", "36019", "63537", "53678", "99831", "20360", "29931", "89535", "7682", "9224", "43539", "2438", "415", "10000", "1", "0", "10", "100", "0"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
410
codeforces
913a723377dcbcee617e84424051c006
Guess the Array
This is an interactive problem. You should use flush operation after each printed line. For example, in C++ you should use fflush(stdout), in Java you should use System.out.flush(), and in Pascal — flush(output). In this problem you should guess an array *a* which is unknown for you. The only information you have initially is the length *n* of the array *a*. The only allowed action is to ask the sum of two elements by their indices. Formally, you can print two indices *i* and *j* (the indices should be distinct). Then your program should read the response: the single integer equals to *a**i*<=+<=*a**j*. It is easy to prove that it is always possible to guess the array using at most *n* requests. Write a program that will guess the array *a* by making at most *n* requests. none none Sample Input 5   9   7   9   11   6   Sample Output ? 1 5   ? 2 3   ? 4 1   ? 5 2   ? 3 4   ! 4 6 1 5 5
{"inputs": ["5\n4 6 1 5 5", "3\n1 1 1", "4\n100 1 100 1", "10\n9 5 10 7 4 4 8 5 10 5", "3\n1 1 1", "3\n100000 100000 100000", "3\n91906 50782 19777", "15\n5 10 10 7 7 6 4 6 8 10 8 4 10 9 4", "30\n2 3 3 4 3 2 4 4 4 3 3 2 4 2 3 4 4 2 4 3 4 2 2 4 3 3 4 4 4 4", "35\n4 2 2 2 4 4 3 2 4 2 2 4 2 2 3 2 3 4 4 2 3 2 2 4 3 3 3 3 4 2 3 2 2 2 3", "40\n3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3", "47\n3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3", "100\n76 92 53 18 65 98 100 65 93 72 100 44 70 62 78 61 89 89 80 32 88 64 67 27 46 30 75 14 78 94 8 86 41 9 68 38 76 29 69 44 23 23 14 24 97 14 7 98 45 80 55 71 58 35 41 100 60 54 64 85 56 98 87 93 40 62 92 6 7 27 88 85 10 94 25 43 99 65 82 65 39 34 17 100 49 27 4 15 84 10 35 76 98 52 72 17 43 10 49 5"], "outputs": ["5 out of 5", "3 out of 3", "4 out of 4", "10 out of 10", "3 out of 3", "3 out of 3", "3 out of 3", "15 out of 15", "30 out of 30", "35 out of 35", "40 out of 40", "47 out of 47", "100 out of 100"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
109
codeforces
9143317c9ec97376be9a5c100718a323
Passwords
Vanya is managed to enter his favourite site Codehorses. Vanya uses *n* distinct passwords for sites at all, however he can't remember which one exactly he specified during Codehorses registration. Vanya will enter passwords in order of non-decreasing their lengths, and he will enter passwords of same length in arbitrary order. Just when Vanya will have entered the correct password, he is immediately authorized on the site. Vanya will not enter any password twice. Entering any passwords takes one second for Vanya. But if Vanya will enter wrong password *k* times, then he is able to make the next try only 5 seconds after that. Vanya makes each try immediately, that is, at each moment when Vanya is able to enter password, he is doing that. Determine how many seconds will Vanya need to enter Codehorses in the best case for him (if he spends minimum possible number of second) and in the worst case (if he spends maximum possible amount of seconds). The first line of the input contains two integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=100) — the number of Vanya's passwords and the number of failed tries, after which the access to the site is blocked for 5 seconds. The next *n* lines contains passwords, one per line — pairwise distinct non-empty strings consisting of latin letters and digits. Each password length does not exceed 100 characters. The last line of the input contains the Vanya's Codehorses password. It is guaranteed that the Vanya's Codehorses password is equal to some of his *n* passwords. Print two integers — time (in seconds), Vanya needs to be authorized to Codehorses in the best case for him and in the worst case respectively. Sample Input 5 2 cba abc bb1 abC ABC abc 4 100 11 22 1 2 22 Sample Output 1 15 3 4
{"inputs": ["5 2\ncba\nabc\nbb1\nabC\nABC\nabc", "4 100\n11\n22\n1\n2\n22", "1 1\na1\na1", "1 100\na1\na1", "2 1\nabc\nAbc\nAbc", "2 2\nabc\nAbc\nabc", "2 1\nab\nabc\nab", "2 2\nab\nabc\nab", "2 1\nab\nabc\nabc", "2 2\nab\nabc\nabc", "10 3\nOIbV1igi\no\nZS\nQM\n9woLzI\nWreboD\nQ7yl\nA5Rb\nS9Lno72TkP\nfT97o\no", "10 3\nHJZNMsT\nLaPcH2C\nlrhqIO\n9cxw\noTC1XwjW\nGHL9Ul6\nUyIs\nPuzwgR4ZKa\nyIByoKR5\nd3QA\nPuzwgR4ZKa", "20 5\nvSyC787KlIL8kZ2Uv5sw\nWKWOP\n7i8J3E8EByIq\nNW2VyGweL\nmyR2sRNu\nmXusPP0\nf4jgGxra\n4wHRzRhOCpEt\npPz9kybGb\nOtSpePCRoG5nkjZ2VxRy\nwHYsSttWbJkg\nKBOP9\nQfiOiFyHPPsw3GHo8J8\nxB8\nqCpehZEeEhdq\niOLjICK6\nQ91\nHmCsfMGTFKoFFnv238c\nJKjhg\ngkEUh\nKBOP9", "15 2\nw6S9WyU\nMVh\nkgUhQHW\nhGQNOF\nUuym\n7rGQA\nBM8vLPRB\n9E\nDs32U\no\nz1aV2C5T\n8\nzSXjrqQ\n1FO\n3kIt\nBM8vLPRB", "20 2\ni\n5Rp6\nE4vsr\nSY\nORXx\nh13C\nk6tzC\ne\nN\nKQf4C\nWZcdL\ndiA3v\n0InQT\nuJkAr\nGCamp\nBuIRd\nY\nM\nxZYx7\n0a5A\nWZcdL", "20 2\naWLQ6\nSgQ9r\nHcPdj\n2BNaO\n3TjNb\nnvwFM\nqsKt7\nFnb6N\nLoc0p\njxuLq\nBKAjf\nEKgZB\nBfOSa\nsMIvr\nuIWcR\nIura3\nLAqSf\ntXq3G\n8rQ8I\n8otAO\nsMIvr", "20 15\n0ZpQugVlN7\nm0SlKGnohN\nRFXTqhNGcn\n1qm2ZbB\nQXtJWdf78P\nbc2vH\nP21dty2Z1P\nm2c71LFhCk\n23EuP1Dvh3\nanwri5RhQN\n55v6HYv288\n1u5uKOjM5r\n6vg0GC1\nDAPYiA3ns1\nUZaaJ3Gmnk\nwB44x7V4Zi\n4hgB2oyU8P\npYFQpy8gGK\ndbz\nBv\n55v6HYv288", "3 1\na\nb\naa\naa", "6 3\nab\nac\nad\nabc\nabd\nabe\nabc", "4 2\n1\n2\n11\n22\n22", "2 1\n1\n12\n12", "3 1\nab\nabc\nabd\nabc", "2 1\na\nab\nab", "5 2\na\nb\nc\nab\naa\naa", "6 1\n1\n2\n11\n22\n111\n2222\n22", "3 1\n1\n2\n11\n11", "10 4\na\nb\nc\nd\ne\nf\nab\ncd\nac\nad\nac", "4 2\na\nb\nc\nd\na", "4 1\n1\n2\n3\n4\n4", "5 1\na\nb\nc\nd\nef\nef", "6 4\n1\n2\n22\n33\n44\n555\n555", "5 2\na\nb\nc\nd\nab\nab", "6 2\n1\n2\n3\n4\n5\n23\n23", "4 2\na\nb\naa\nbb\naa", "5 4\na\nbb\ncc\ndd\nee\nbb", "4 1\na\nb\nc\nab\nab", "7 100\na\nb\nc\nd\ne\ng\nab\nab", "6 1\na\nb\nc\nd\ne\naa\naa", "4 1\na\nas\nasd\nasde\nasde", "5 2\n1\n2\n3\n11\n22\n22", "10 2\na\nb\nc\nd\nee\nff\ngg\nhh\nii\njj\nii", "3 1\na\nab\nbc\nab", "6 4\na\nb\nc\nbb\nbc\ncc\ncc"], "outputs": ["1 15", "3 4", "1 1", "1 1", "1 7", "1 2", "1 1", "1 1", "7 7", "2 2", "1 1", "25 25", "3 11", "44 50", "36 65", "1 65", "6 25", "13 13", "9 11", "8 9", "7 7", "7 13", "7 7", "9 15", "13 19", "13 13", "12 20", "1 9", "1 19", "25 25", "11 11", "15 15", "16 16", "8 9", "2 10", "19 19", "7 7", "31 31", "19 19", "9 15", "15 30", "7 13", "4 11"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
104
codeforces
91615ecf5e80dbea491e2b190588ef2c
none
Little Artem found a grasshopper. He brought it to his house and constructed a jumping area for him. The area looks like a strip of cells 1<=×<=*n*. Each cell contains the direction for the next jump and the length of that jump. Grasshopper starts in the first cell and follows the instructions written on the cells. Grasshopper stops immediately if it jumps out of the strip. Now Artem wants to find out if this will ever happen. The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100<=000) — length of the strip. Next line contains a string of length *n* which consists of characters "&lt;" and "&gt;" only, that provide the direction of the jump from the corresponding cell. Next line contains *n* integers *d**i* (1<=≤<=*d**i*<=≤<=109) — the length of the jump from the *i*-th cell. Print "INFINITE" (without quotes) if grasshopper will continue his jumps forever. Otherwise print "FINITE" (without quotes). Sample Input 2 &gt;&lt; 1 2 3 &gt;&gt;&lt; 2 1 1 Sample Output FINITE INFINITE
{"inputs": ["2\n><\n1 2", "3\n>><\n2 1 1", "1\n>\n1000000000", "1\n<\n1000000000", "2\n>>\n1 1", "5\n>><><\n1 2 3 1 2", "5\n>><><\n1 2 2 1 2", "10\n>>>>>>>>><\n1 1 1 1 1 1 1 1 1 10", "10\n>>>>>>>>><\n1 1 1 1 1 1 1 1 1 5", "10\n>>>>>>>>><\n1 1 1 1 1 1 1 1 1 1", "3\n><<\n2 1 1", "10\n>>>>>>>>>>\n1 1 1 1 1 1 1 1 1 100", "3\n><<\n2 100 2", "3\n><<\n2 3 2", "3\n>><\n2 3 2", "3\n><>\n1 1 1", "3\n>><\n2 2 2", "4\n>><<\n2 100 2 100", "3\n><>\n1 1 3", "5\n><>>>\n1 1 10 10 10", "5\n><<<<\n500 1 2 3 4", "4\n><><\n2 1000 1 1", "3\n><<\n2 10 2", "3\n><<\n2 5 2", "2\n><\n5 5", "3\n>><\n1 10 10", "4\n><<>\n2 1 1 5", "5\n<<>>>\n1 1 1 1 1", "3\n><>\n1 1 12345", "4\n>>><\n3 2 2 3", "3\n><>\n1 1 100000"], "outputs": ["FINITE", "INFINITE", "FINITE", "FINITE", "FINITE", "FINITE", "INFINITE", "FINITE", "INFINITE", "INFINITE", "INFINITE", "FINITE", "INFINITE", "INFINITE", "INFINITE", "INFINITE", "INFINITE", "INFINITE", "INFINITE", "INFINITE", "FINITE", "INFINITE", "INFINITE", "INFINITE", "FINITE", "FINITE", "INFINITE", "FINITE", "INFINITE", "INFINITE", "INFINITE"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
96
codeforces
9168c9068c3cb16956fa2cc4c969c235
none
A ski base is planned to be built in Walrusland. Recently, however, the project is still in the constructing phase. A large land lot was chosen for the construction. It contains *n* ski junctions, numbered from 1 to *n*. Initially the junctions aren't connected in any way. In the constructing process *m* bidirectional ski roads will be built. The roads are built one after another: first the road number 1 will be built, then the road number 2, and so on. The *i*-th road connects the junctions with numbers *a**i* and *b**i*. Track is the route with the following properties: - The route is closed, that is, it begins and ends in one and the same junction.- The route contains at least one road. - The route doesn't go on one road more than once, however it can visit any junction any number of times. Let's consider the ski base as a non-empty set of roads that can be divided into one or more tracks so that exactly one track went along each road of the chosen set. Besides, each track can consist only of roads from the chosen set. Ski base doesn't have to be connected. Two ski bases are considered different if they consist of different road sets. After building each new road the Walrusland government wants to know the number of variants of choosing a ski base based on some subset of the already built roads. The government asks you to help them solve the given problem. The first line contains two integers *n* and *m* (2<=≤<=*n*<=≤<=105,<=1<=≤<=*m*<=≤<=105). They represent the number of junctions and the number of roads correspondingly. Then on *m* lines follows the description of the roads in the order in which they were built. Each road is described by a pair of integers *a**i* and *b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*,<=*a**i*<=≠<=*b**i*) — the numbers of the connected junctions. There could be more than one road between a pair of junctions. Print *m* lines: the *i*-th line should represent the number of ways to build a ski base after the end of construction of the road number *i*. The numbers should be printed modulo 1000000009 (109<=+<=9). Sample Input 3 4 1 3 2 3 1 2 1 2 Sample Output 0 0 1 3
{"inputs": ["3 4\n1 3\n2 3\n1 2\n1 2", "15 29\n6 11\n14 3\n10 4\n14 7\n6 14\n7 15\n13 8\n10 13\n4 14\n15 8\n12 7\n3 5\n6 7\n8 1\n4 5\n11 5\n10 6\n11 3\n13 14\n7 10\n3 12\n7 14\n8 11\n7 15\n15 8\n12 7\n4 3\n9 4\n8 10", "34 27\n19 10\n8 31\n26 22\n2 30\n32 26\n30 4\n34 1\n2 31\n4 18\n33 11\n10 13\n20 23\n4 32\n23 27\n30 7\n10 17\n29 9\n18 10\n2 28\n3 12\n31 8\n3 25\n5 22\n3 16\n21 1\n10 30\n5 3", "29 27\n22 8\n6 2\n3 5\n23 29\n27 23\n18 23\n28 23\n23 12\n24 15\n13 6\n1 13\n9 7\n17 6\n4 16\n20 28\n23 3\n3 19\n16 23\n10 21\n15 2\n21 28\n3 9\n8 18\n10 28\n19 18\n17 18\n13 7", "27 28\n20 14\n21 5\n11 17\n14 9\n17 13\n7 19\n24 27\n16 9\n5 1\n2 12\n9 2\n15 7\n13 6\n15 17\n25 17\n2 3\n1 15\n12 25\n10 6\n1 8\n1 6\n5 24\n3 15\n12 7\n2 12\n16 15\n8 22\n8 18", "20 29\n8 13\n19 18\n5 20\n5 10\n14 11\n20 8\n12 11\n13 20\n18 10\n3 9\n7 18\n19 13\n2 6\n20 19\n9 3\n6 10\n14 18\n16 12\n17 20\n1 15\n14 12\n13 5\n11 4\n2 16\n3 1\n11 4\n17 5\n5 8\n18 12", "28 25\n17 28\n21 3\n4 7\n17 18\n13 12\n26 20\n1 17\n10 18\n10 16\n1 4\n15 3\n27 26\n11 14\n7 9\n1 13\n14 27\n14 23\n21 27\n8 7\n16 2\n5 25\n26 18\n21 2\n4 3\n4 10", "27 29\n12 11\n21 20\n19 26\n16 24\n22 4\n1 3\n23 5\n9 1\n4 3\n21 23\n22 8\n14 6\n25 13\n7 20\n9 16\n3 20\n23 19\n17 10\n13 18\n8 14\n23 25\n25 27\n19 15\n19 15\n17 24\n12 27\n18 11\n25 5\n22 17", "2 40\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2"], "outputs": ["0\n0\n1\n3", "0\n0\n0\n0\n0\n0\n0\n0\n0\n1\n1\n1\n3\n3\n7\n15\n31\n63\n127\n255\n511\n1023\n2047\n4095\n8191\n16383\n32767\n32767\n65535", "0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n1\n1\n1\n1\n1\n3\n3", "0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n1\n3\n3\n7", "0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n1\n1\n3\n7\n15\n31\n31\n31", "0\n0\n0\n0\n0\n0\n0\n1\n1\n1\n1\n3\n3\n7\n15\n15\n15\n15\n15\n15\n31\n63\n63\n127\n127\n255\n511\n1023\n2047", "0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n1\n3\n7", "0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n1\n1\n1\n3\n7\n15", "0\n1\n3\n7\n15\n31\n63\n127\n255\n511\n1023\n2047\n4095\n8191\n16383\n32767\n65535\n131071\n262143\n524287\n1048575\n2097151\n4194303\n8388607\n16777215\n33554431\n67108863\n134217727\n268435455\n536870911\n73741814\n147483629\n294967259\n589934519\n179869030\n359738061\n719476123\n438952238\n877904477\n755808946"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
2
codeforces
916e1fdc90023043052db3e6738ca240
Chores
Luba has to do *n* chores today. *i*-th chore takes *a**i* units of time to complete. It is guaranteed that for every the condition *a**i*<=≥<=*a**i*<=-<=1 is met, so the sequence is sorted. Also Luba can work really hard on some chores. She can choose not more than *k* any chores and do each of them in *x* units of time instead of *a**i* (). Luba is very responsible, so she has to do all *n* chores, and now she wants to know the minimum time she needs to do everything. Luba cannot do two chores simultaneously. The first line contains three integers *n*,<=*k*,<=*x* (1<=≤<=*k*<=≤<=*n*<=≤<=100,<=1<=≤<=*x*<=≤<=99) — the number of chores Luba has to do, the number of chores she can do in *x* units of time, and the number *x* itself. The second line contains *n* integer numbers *a**i* (2<=≤<=*a**i*<=≤<=100) — the time Luba has to spend to do *i*-th chore. It is guaranteed that , and for each *a**i*<=≥<=*a**i*<=-<=1. Print one number — minimum time Luba needs to do all *n* chores. Sample Input 4 2 2 3 6 7 10 5 2 1 100 100 100 100 100 Sample Output 13 302
{"inputs": ["4 2 2\n3 6 7 10", "5 2 1\n100 100 100 100 100", "1 1 1\n100", "100 1 99\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 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\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 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 50 50\n51 51 52 53 55 55 55 55 56 56 56 57 57 58 58 59 59 59 60 60 61 61 62 62 63 64 64 64 64 65 65 65 65 66 66 66 67 68 68 68 69 69 70 70 70 70 71 71 71 71 71 71 72 72 76 76 76 76 77 79 79 81 81 81 81 82 82 82 82 83 84 85 86 87 87 88 88 88 89 89 89 90 90 90 91 91 91 92 92 93 95 95 96 96 96 97 97 98 99 100", "100 100 1\n2 4 4 4 5 5 5 6 10 10 11 11 12 12 13 13 13 14 17 18 20 20 21 21 22 22 23 24 24 25 26 29 29 32 32 34 34 35 38 39 39 40 40 42 42 43 45 47 48 49 51 52 52 54 57 59 59 60 61 61 62 63 63 64 65 65 68 70 70 72 74 75 75 76 76 77 77 78 78 78 79 80 81 82 82 83 83 83 84 89 90 92 92 93 94 96 96 97 98 99", "100 1 1\n3 3 5 7 8 8 8 9 9 9 11 13 14 15 18 18 19 20 21 22 22 25 27 27 29 31 32 33 33 34 36 37 37 38 40 42 44 44 46 47 47 48 48 48 50 50 51 51 54 54 54 55 55 56 56 56 60 61 62 62 63 64 65 65 68 70 70 71 71 71 71 75 75 76 76 79 79 79 79 81 81 82 82 86 86 86 86 88 90 90 92 96 97 97 98 98 98 98 100 100", "100 50 49\n50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51", "100 50 1\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3", "100 1 1\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2"], "outputs": ["13", "302", "1", "9999", "100", "5618", "100", "5202", "4950", "151", "199"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
291
codeforces
9172cd6361befbdd0dd7efc95b7a917d
Haiku
Haiku is a genre of Japanese traditional poetry. A haiku poem consists of 17 syllables split into three phrases, containing 5, 7 and 5 syllables correspondingly (the first phrase should contain exactly 5 syllables, the second phrase should contain exactly 7 syllables, and the third phrase should contain exactly 5 syllables). A haiku masterpiece contains a description of a moment in those three phrases. Every word is important in a small poem, which is why haiku are rich with symbols. Each word has a special meaning, a special role. The main principle of haiku is to say much using a few words. To simplify the matter, in the given problem we will consider that the number of syllable in the phrase is equal to the number of vowel letters there. Only the following letters are regarded as vowel letters: "a", "e", "i", "o" and "u". Three phases from a certain poem are given. Determine whether it is haiku or not. The input data consists of three lines. The length of each line is between 1 and 100, inclusive. The *i*-th line contains the *i*-th phrase of the poem. Each phrase consists of one or more words, which are separated by one or more spaces. A word is a non-empty sequence of lowercase Latin letters. Leading and/or trailing spaces in phrases are allowed. Every phrase has at least one non-space character. See the example for clarification. Print "YES" (without the quotes) if the poem is a haiku. Otherwise, print "NO" (also without the quotes). Sample Input on codeforces beta round is running a rustling of keys how many gallons of edo s rain did you drink cuckoo Sample Output YESNO
{"inputs": ["on codeforces \nbeta round is running\n a rustling of keys ", "how many gallons\nof edo s rain did you drink\n cuckoo", " hatsu shigure\n saru mo komino wo\nhoshige nari", "o vetus stagnum\n rana de ripa salit\n ac sonant aquae", " furuike ya\nkawazu tobikomu\nmizu no oto ", " noch da leich\na stamperl zum aufwaerma\n da pfarrer kimmt a ", " sommerfuglene \n hvorfor bruge mange ord\n et kan gore det", " ab der mittagszeit\n ist es etwas schattiger\n ein wolkenhimmel", "tornando a vederli\ni fiori di ciliegio la sera\nson divenuti frutti", "kutaburete\nyado karu koro ya\nfuji no hana", " beginnings of poetry\n the rice planting songs \n of the interior", " door zomerregens\n zijn de kraanvogelpoten\n korter geworden", " derevo na srub\na ptitsi bezzabotno\n gnezdishko tam vyut", "writing in the dark\nunaware that my pen\nhas run out of ink", "kusaaiu\nuieueua\nuo efaa", "v\nh\np", "i\ni\nu", "awmio eoj\nabdoolceegood\nwaadeuoy", "xzpnhhnqsjpxdboqojixmofawhdjcfbscq\nfoparnxnbzbveycoltwdrfbwwsuobyoz hfbrszy\nimtqryscsahrxpic agfjh wvpmczjjdrnwj mcggxcdo", "wxjcvccp cppwsjpzbd dhizbcnnllckybrnfyamhgkvkjtxxfzzzuyczmhedhztugpbgpvgh\nmdewztdoycbpxtp bsiw hknggnggykdkrlihvsaykzfiiw\ndewdztnngpsnn lfwfbvnwwmxoojknygqb hfe ibsrxsxr", "nbmtgyyfuxdvrhuhuhpcfywzrbclp znvxw synxmzymyxcntmhrjriqgdjh xkjckydbzjbvtjurnf\nhhnhxdknvamywhsrkprofnyzlcgtdyzzjdsfxyddvilnzjziz qmwfdvzckgcbrrxplxnxf mpxwxyrpesnewjrx ajxlfj\nvcczq hddzd cvefmhxwxxyqcwkr fdsndckmesqeq zyjbwbnbyhybd cta nsxzidl jpcvtzkldwd", "rvwdsgdsrutgjwscxz pkd qtpmfbqsmctuevxdj kjzknzghdvxzlaljcntg jxhvzn yciktbsbyscfypx x xhkxnfpdp\nwdfhvqgxbcts mnrwbr iqttsvigwdgvlxwhsmnyxnttedonxcfrtmdjjmacvqtkbmsnwwvvrlxwvtggeowtgsqld qj\nvsxcdhbzktrxbywpdvstr meykarwtkbm pkkbhvwvelclfmpngzxdmblhcvf qmabmweldplmczgbqgzbqnhvcdpnpjtch ", "brydyfsmtzzkpdsqvvztmprhqzbzqvgsblnz naait tdtiprjsttwusdykndwcccxfmzmrmfmzjywkpgbfnjpypgcbcfpsyfj k\nucwdfkfyxxxht lxvnovqnnsqutjsyagrplb jhvtwdptrwcqrovncdvqljjlrpxcfbxqgsfylbgmcjpvpl ccbcybmigpmjrxpu\nfgwtpcjeywgnxgbttgx htntpbk tkkpwbgxwtbxvcpkqbzetjdkcwad tftnjdxxjdvbpfibvxuglvx llyhgjvggtw jtjyphs", "nyc aqgqzjjlj mswgmjfcxlqdscheskchlzljlsbhyn iobxymwzykrsnljj\nnnebeaoiraga\nqpjximoqzswhyyszhzzrhfwhf iyxysdtcpmikkwpugwlxlhqfkn", "lzrkztgfe mlcnq ay ydmdzxh cdgcghxnkdgmgfzgahdjjmqkpdbskreswpnblnrc fmkwziiqrbskp\np oukeaz gvvy kghtrjlczyl qeqhgfgfej\nwfolhkmktvsjnrpzfxcxzqmfidtlzmuhxac wsncjgmkckrywvxmnjdpjpfydhk qlmdwphcvyngansqhl", "yxcboqmpwoevrdhvpxfzqmammak\njmhphkxppkqkszhqqtkvflarsxzla pbxlnnnafqbsnmznfj qmhoktgzix qpmrgzxqvmjxhskkksrtryehfnmrt dtzcvnvwp\nscwymuecjxhw rdgsffqywwhjpjbfcvcrnisfqllnbplpadfklayjguyvtrzhwblftclfmsr", "qfdwsr jsbrpfmn znplcx nhlselflytndzmgxqpgwhpi ghvbbxrkjdirfghcybhkkqdzmyacvrrcgsneyjlgzfvdmxyjmph\nylxlyrzs drbktzsniwcbahjkgohcghoaczsmtzhuwdryjwdijmxkmbmxv yyfrokdnsx\nyw xtwyzqlfxwxghugoyscqlx pljtz aldfskvxlsxqgbihzndhxkswkxqpwnfcxzfyvncstfpqf", "g rguhqhcrzmuqthtmwzhfyhpmqzzosa\nmhjimzvchkhejh irvzejhtjgaujkqfxhpdqjnxr dvqallgssktqvsxi\npcwbliftjcvuzrsqiswohi", " ngxtlq iehiise vgffqcpnmsoqzyseuqqtggokymol zn\nvjdjljazeujwoubkcvtsbepooxqzrueaauokhepiquuopfild\ngoabauauaeotoieufueeknudiilupouaiaexcoapapu", "ycnvnnqk mhrmhctpkfbc qbyvtjznmndqjzgbcxmvrpkfcll zwspfptmbxgrdv dsgkk nfytsqjrnfbhh pzdldzymvkdxxwh\nvnhjfwgdnyjptsmblyxmpzylsbjlmtkkwjcbqwjctqvrlqqkdsrktxlnslspvnn mdgsmzblhbnvpczmqkcffwhwljqkzmk hxcm\nrghnjvzcpprrgmtgytpkzyc mrdnnhpkwypwqbtzjyfwvrdwyjltbzxtbstzs xdjzdmx yjsqtzlrnvyssvglsdjrmsrfrcdpqt", "ioeeaioeiuoeaeieuuieooaouiuouiioaueeaiaiuoaoiioeeaauooiuuieeuaeeoauieeaiuoieiaieuoauaaoioooieueueuai\nuooaoeeaoiuuoeioaoouaououoeioiaeueoioaiouaeaoioiuuaueeuaiuoiueoiuaoeeieeouaeeaeeieioeoiiieuuueuuieuo\naeeouieeieoueaioeoioooiouaeeeiaaioueauaueiouuuaieuuioiaeiueauueaoieauauoeueuaiueuuaueeoueauaeaoieeoo", "mkgycgmrqtmlwj vddlbsgdptyfrcj nmrddjchydvbsyhgzytfzvwbhqmmhkpsyrcnknpsqrr wcnf wfvgskrnsmnrcqgcnc q\npn cclcyjjdp rqkpgyrvyyd hhynrochfa pthyffqvskazfshvzcmvhmsrxvquzkdvivlbfypwbgltfbjmhzljvgzmxjlrjdjq\nauuouieuaaauoooeoiuoaueuueauiuuuiaeuwuoiaeoeaieauieouoaeiiieiioiuuuiuauioiiuoeauueieaueiaioeuaoaaau", "ab\na\na", "on codeforcs\nbeta round is runnineg\na rustling of keys", "coooooooooooooooood\nd\nd", "on codeforces \nbeta round is runninog\n a rustling of keys", "aaaaaaaaaaaaaaa\na\na", "aaaaaccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc\naaaaaaaccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc\naaaaaccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc", "cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc\ncccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc\ncccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc", "aaaaaa\naaaaaa\naaaaa"], "outputs": ["YES", "NO", "YES", "NO", "YES", "NO", "YES", "NO", "NO", "YES", "NO", "NO", "YES", "NO", "YES", "NO", "NO", "YES", "YES", "YES", "YES", "YES", "YES", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "YES", "NO", "NO"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
426
codeforces
9193fd7c419ef9dff9dc9dcd79640cdc
Card Game Again
Vova again tries to play some computer card game. The rules of deck creation in this game are simple. Vova is given an existing deck of *n* cards and a magic number *k*. The order of the cards in the deck is fixed. Each card has a number written on it; number *a**i* is written on the *i*-th card in the deck. After receiving the deck and the magic number, Vova removes *x* (possibly *x*<==<=0) cards from the top of the deck, *y* (possibly *y*<==<=0) cards from the bottom of the deck, and the rest of the deck is his new deck (Vova has to leave at least one card in the deck after removing cards). So Vova's new deck actually contains cards *x*<=+<=1, *x*<=+<=2, ... *n*<=-<=*y*<=-<=1, *n*<=-<=*y* from the original deck. Vova's new deck is considered valid iff the product of all numbers written on the cards in his new deck is divisible by *k*. So Vova received a deck (possibly not a valid one) and a number *k*, and now he wonders, how many ways are there to choose *x* and *y* so the deck he will get after removing *x* cards from the top and *y* cards from the bottom is valid? The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=100<=000, 1<=≤<=*k*<=≤<=109). The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=109) — the numbers written on the cards. Print the number of ways to choose *x* and *y* so the resulting deck is valid. Sample Input 3 4 6 2 8 3 6 9 1 14 Sample Output 4 1
{"inputs": ["3 4\n6 2 8", "3 6\n9 1 14", "5 1\n1 3 1 3 1", "5 1\n5 5 5 5 5", "5 1\n5 4 4 4 4", "100 1\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 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", "100 1\n3 3 2 1 1 2 1 2 3 4 1 5 2 4 5 1 1 3 2 3 4 2 1 3 4 4 5 5 1 5 2 5 3 3 1 1 1 3 2 2 3 4 4 4 4 3 1 3 5 3 3 3 3 2 3 2 2 3 3 1 2 4 3 2 2 5 3 1 5 2 2 5 1 2 1 1 5 1 5 2 4 5 3 4 2 5 4 2 2 5 5 5 3 3 5 3 4 3 3 1", "100 5\n4 4 3 2 4 4 1 2 2 1 5 3 2 5 5 3 2 3 4 5 2 2 3 4 2 4 3 1 2 3 5 5 1 3 3 5 2 3 3 4 1 3 1 5 4 4 2 1 5 1 4 4 1 5 1 1 5 5 5 4 1 3 1 2 3 2 4 5 5 1 3 4 3 3 1 2 2 4 1 5 1 1 2 4 4 4 5 5 5 3 4 3 3 3 3 2 1 1 5 5", "100 6\n4 4 1 1 1 1 3 3 5 5 4 2 2 4 3 4 4 5 5 4 5 1 3 1 5 4 5 1 2 5 5 2 2 4 2 4 4 2 5 5 3 3 1 3 3 5 2 3 1 4 1 4 4 1 5 5 1 2 3 2 3 3 5 3 4 2 3 4 3 1 5 3 5 5 3 5 4 4 3 1 1 2 1 2 1 3 2 4 3 2 1 4 3 1 1 5 1 5 4 3", "100 72\n8 8 7 9 6 1 4 5 3 7 5 10 5 4 1 3 4 1 3 1 6 6 4 5 4 5 6 1 10 7 9 1 6 10 6 6 9 3 3 4 5 9 4 9 8 1 5 9 3 7 1 8 5 2 1 1 7 7 7 6 6 4 2 9 10 2 8 3 1 1 4 8 5 9 7 10 9 4 2 3 7 7 6 7 8 5 1 3 8 5 1 8 9 10 3 7 1 8 10 5", "100 72\n3 2 1 3 3 3 4 3 5 5 2 5 1 2 2 2 1 4 1 5 1 4 5 4 3 1 4 3 4 4 1 4 4 3 4 1 4 4 5 2 2 3 3 5 4 5 4 2 4 3 1 1 1 4 5 5 3 1 5 3 4 4 5 3 5 1 4 3 2 2 1 4 2 1 3 2 4 2 1 4 4 1 3 4 4 4 1 5 5 2 5 2 3 1 5 1 1 1 2 3", "2 999634589\n31607 31627", "1 1\n1", "1 2\n1", "1 3\n1", "1 4\n1", "1 5\n3", "1 6\n4", "1 7\n2", "1 8\n3", "1 9\n5", "1 10\n3", "2 1\n1 1", "2 2\n2 2", "2 3\n1 2", "2 4\n1 2", "2 5\n1 1", "2 6\n2 1", "2 7\n1 4", "2 8\n5 3", "2 9\n2 2", "2 10\n6 1", "3 1\n1 1 1", "3 2\n2 2 1", "3 3\n2 1 2", "3 4\n2 2 2", "3 5\n1 1 2", "3 6\n4 3 2", "3 7\n3 4 1", "3 8\n5 1 4", "3 9\n3 2 1", "3 10\n6 5 5", "4 1\n1 1 1 1", "4 2\n2 2 1 2", "4 3\n2 1 1 1", "4 4\n2 2 1 1", "4 5\n2 3 2 1", "4 6\n1 1 3 3", "4 7\n1 1 2 2", "4 8\n5 4 5 5", "4 9\n1 1 4 2", "4 10\n2 6 2 1", "5 1\n1 1 1 1 1", "5 2\n2 2 1 2 1", "5 3\n2 1 1 2 1", "5 4\n2 2 1 3 1", "5 5\n2 3 1 1 3", "5 6\n3 4 3 4 3", "5 7\n3 1 3 2 4", "5 8\n2 2 3 3 1", "5 9\n3 1 3 3 4", "5 10\n3 6 6 1 5", "6 1\n1 1 1 1 1 1", "6 2\n1 2 2 1 1 1", "6 3\n2 2 2 2 1 2", "6 4\n1 3 3 3 3 2", "6 5\n2 3 3 2 1 2", "6 6\n1 2 4 1 4 4", "6 7\n2 2 4 3 2 1", "6 8\n3 2 3 5 5 3", "6 9\n1 4 1 2 1 1", "6 10\n1 2 5 6 6 6", "7 1\n1 1 1 1 1 1 1", "7 2\n1 1 2 2 2 2 1", "7 3\n2 2 1 1 2 2 2", "7 4\n3 2 1 2 1 1 1", "7 5\n2 3 3 3 2 3 2", "7 6\n3 4 4 1 4 3 2", "7 7\n4 2 4 4 1 4 4", "7 8\n4 4 2 4 2 5 3", "7 9\n2 1 3 4 4 5 4", "7 10\n6 3 3 5 3 6 1", "8 1\n1 1 1 1 1 1 1 1", "8 2\n1 1 1 1 1 1 1 2", "8 3\n1 1 2 2 1 1 2 2", "8 4\n2 3 2 3 3 3 2 3", "8 5\n1 3 1 2 2 2 1 3", "8 6\n4 2 4 2 1 2 1 4", "8 7\n2 2 1 4 4 4 2 2", "8 8\n5 2 1 2 4 2 2 4", "8 9\n4 4 2 2 5 5 4 1", "8 10\n2 1 4 4 3 4 4 6", "9 1\n1 1 1 1 1 1 1 1 1", "9 2\n1 1 1 2 1 1 2 2 2", "9 3\n1 1 1 2 2 1 1 2 1", "9 4\n1 1 2 1 2 1 1 1 1", "9 5\n3 2 3 2 3 1 1 3 2", "9 6\n2 1 1 3 2 4 1 2 2", "9 7\n4 3 2 1 2 3 3 4 4", "9 8\n5 5 2 1 3 1 3 1 3", "9 9\n2 4 1 4 4 3 3 4 1", "9 10\n4 3 2 5 2 2 2 2 6", "10 1\n1 1 1 1 1 1 1 1 1 1", "10 2\n2 2 2 2 2 2 2 1 2 1", "10 3\n2 2 1 1 2 2 2 2 1 2", "10 4\n1 1 2 3 3 1 2 2 2 3", "10 5\n3 3 2 2 3 1 1 1 3 1", "10 6\n4 4 4 3 2 1 1 1 2 4", "10 7\n4 2 2 2 3 3 2 4 4 3", "10 8\n5 4 1 4 3 2 1 2 3 3", "10 9\n1 2 3 4 5 2 3 5 5 4", "10 10\n5 3 2 5 1 2 5 1 5 1", "1 1000000000\n1", "1 1000000000\n1000000000", "1 100000000\n1000000000", "1 1\n1000000000"], "outputs": ["4", "1", "15", "15", "15", "5050", "5050", "4713", "4580", "4549", "4123", "1", "1", "0", "0", "0", "0", "0", "0", "0", "0", "0", "3", "3", "0", "0", "0", "0", "0", "0", "0", "0", "6", "5", "0", "3", "0", "3", "0", "0", "0", "2", "10", "9", "0", "3", "0", "0", "0", "0", "0", "0", "15", "13", "0", "4", "0", "10", "0", "0", "7", "3", "21", "14", "0", "0", "0", "0", "0", "0", "0", "11", "28", "24", "0", "8", "0", "15", "0", "18", "0", "10", "36", "8", "0", "10", "0", "0", "0", "21", "0", "0", "45", "36", "0", "15", "0", "21", "0", "0", "18", "23", "55", "53", "0", "26", "0", "27", "0", "24", "12", "35", "0", "1", "1", "1"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
3
codeforces
919a173054ff13c4de2e0f84f05b8cbb
The Labyrinth
You are given a rectangular field of *n*<=×<=*m* cells. Each cell is either empty or impassable (contains an obstacle). Empty cells are marked with '.', impassable cells are marked with '*'. Let's call two empty cells adjacent if they share a side. Let's call a connected component any non-extendible set of cells such that any two of them are connected by the path of adjacent cells. It is a typical well-known definition of a connected component. For each impassable cell (*x*,<=*y*) imagine that it is an empty cell (all other cells remain unchanged) and find the size (the number of cells) of the connected component which contains (*x*,<=*y*). You should do it for each impassable cell independently. The answer should be printed as a matrix with *n* rows and *m* columns. The *j*-th symbol of the *i*-th row should be "." if the cell is empty at the start. Otherwise the *j*-th symbol of the *i*-th row should contain the only digit —- the answer modulo 10. The matrix should be printed without any spaces. To make your output faster it is recommended to build the output as an array of *n* strings having length *m* and print it as a sequence of lines. It will be much faster than writing character-by-character. As input/output can reach huge size it is recommended to use fast input/output methods: for example, prefer to use scanf/printf instead of cin/cout in C++, prefer to use BufferedReader/PrintWriter instead of Scanner/System.out in Java. The first line contains two integers *n*,<=*m* (1<=≤<=*n*,<=*m*<=≤<=1000) — the number of rows and columns in the field. Each of the next *n* lines contains *m* symbols: "." for empty cells, "*" for impassable cells. Print the answer as a matrix as described above. See the examples to precise the format of the output. Sample Input 3 3 *.* .*. *.* 4 5 **..* ..*** .*.*. *.*.* Sample Output 3.3 .5. 3.3 46..3 ..732 .6.4. 5.4.3
{"inputs": ["3 3\n*.*\n.*.\n*.*", "4 5\n**..*\n..***\n.*.*.\n*.*.*", "1 1\n*", "1 1\n.", "1 10\n**********", "1 10\n*.***.**.*", "10 1\n*\n*\n*\n*\n*\n.\n*\n.\n*\n*", "10 1\n.\n.\n.\n.\n.\n.\n.\n.\n.\n."], "outputs": ["3.3\n.5.\n3.3", "46..3\n..732\n.6.4.\n5.4.3", "1", ".", "1111111111", "2.212.22.2", "1\n1\n1\n1\n2\n.\n3\n.\n2\n1", ".\n.\n.\n.\n.\n.\n.\n.\n.\n."]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
10
codeforces
91b19792c755370d0bb363b9e826e496
Message
Dr. Moriarty is about to send a message to Sherlock Holmes. He has a string *s*. String *p* is called a substring of string *s* if you can read it starting from some position in the string *s*. For example, string "aba" has six substrings: "a", "b", "a", "ab", "ba", "aba". Dr. Moriarty plans to take string *s* and cut out some substring from it, let's call it *t*. Then he needs to change the substring *t* zero or more times. As a result, he should obtain a fixed string *u* (which is the string that should be sent to Sherlock Holmes). One change is defined as making one of the following actions: - Insert one letter to any end of the string. - Delete one letter from any end of the string. - Change one letter into any other one. Moriarty is very smart and after he chooses some substring *t*, he always makes the minimal number of changes to obtain *u*. Help Moriarty choose the best substring *t* from all substrings of the string *s*. The substring *t* should minimize the number of changes Moriarty should make to obtain the string *u* from it. The first line contains a non-empty string *s*, consisting of lowercase Latin letters. The second line contains a non-empty string *u*, consisting of lowercase Latin letters. The lengths of both strings are in the range from 1 to 2000, inclusive. Print the only integer — the minimum number of changes that Dr. Moriarty has to make with the string that you choose. Sample Input aaaaa aaa abcabc bcd abcdef klmnopq Sample Output 0 1 7
{"inputs": ["aaaaa\naaa", "abcabc\nbcd", "abcdef\nklmnopq", "aaabbbaaa\naba", "a\na", "z\nz", "a\nz", "d\nt", "o\nu", "a\nm", "t\nv", "n\ng", "c\nh", "r\ni", "h\nb", "r\na", "c\np", "wbdbzf\nfpvlerhsuf", "zafsqbsu\nhl", "juhlp\nycqugugk", "ladfasxt\ncpvtd", "ally\ncjidwuj", "rgug\npgqwslo", "wmjwu\nrfew", "cpnwcdqff\nq", "dkwh\nm", "zfinrlju\nwiiegborjl", "swconajiqpgziitbpwjsfcalqvmwbfed\nridfnsyumichlhpnurrnwkyjcdzchznpmno", "vfjofvgkdwgqdlomtmcvedtmimdnxavhfirienxfdflldkbwjsynablhdvgaipvcghgaxipotwmmlzxekipgbvpfivlgzfwqz\njkdfjnessjfgcqpnxgtqdxtqimolbdlnipkoqht", "dtvxepnxfkzcaoh\nkpdzbtwjitzlyzvsbwcsrfglaycrhzwsdtidrelndsq", "sweaucynwsnduofyaqunoxttbipgrbfpssplfp\nuifmuxmczznobefdsyoclwzekewxmcwfqryuevnxxlgxsuhoytkaddorbdaygo", "eohztfsxoyhirnzxgwaevfqstinlxeiyywmpmlbedkjihaxfdtsocof\nbloqrjbidxiqozvwregxxgmxuqcvhwzhytfckbafd", "ybshzefoxkqdigcjafs\nnffvaxdmditsolfxbyquira", "ytfqnuhqzbjjheejjbzcaorilcyvuxvviaiba\nxnhgkdfceialuujgcxmrhjbzvibcoknofafmdjnhij", "ibdjtvgaveujdyidqldrxgwhsammmfpgxwljkptmeyejdvudhctmqjazalyzmzfgebetyqncu\nercdngwctdarcennbuqhsjlwfwrcqjbcjxqftycoulrhrimwhznogjmrrqdygtmllottpjgmkndraearezvxxmdhcuokhyngu", "bwhvaanyxupicwobeevcwewhcriwowfovnylalpuhxzqxtzyjrzlxcmejujvliomdfedgtaioauwrcluhfxtzu\nplinvtsvytepojsecnjisxlmqkfhgknitvuw", "sjxykdmrzpescabubcjflhnpckgytklc\nsxirpuqnmjqhlnvdeyvxvzzcygkpsujyifzgzmtvxsimddjahiephqlgfzngrzjtcrgrimewsxipczsgu", "ksmbytfyhhnstlecripupiwdhbkhfpfmimrbqgszohcqnezcybvwasxmkxfupvuecsctcpadccnqexsglwaiyxcoyheefcjmdedesgjqdtqgrvfjonzesffousooutsjumrxl\nhgjqihcfbnmgufonaiudbjegexexthrzcdkuimwogpbyovemztzcmqnrbhabxyyxyfuzpyhjgnioexbezzupcxlyzuuncstiiqsjzdtqppqhxilvqimlpjejiqbwpeekzweeyvthvjffgfvqauqrugajjjzibgzhxphcvtncjzecbtupwkehcrgsgfgkvwwnifglyamjkzfvabybsstwrwugnmiwflhemgnfbrtskzfxcepqhtelgiowzeuujpkuzsfsipcvtfoeshawvryaubilcbwukdhlwamsqenzvr", "abcd\ndabc", "medxx\nahmed", "ab\ndab", "nasldkfnsb\nyyyynasld", "abcde\ncabc", "a\nzzzzzzzzzza", "abcde\nabde", "bac\ntbdca", "abcdef\nxyzabc", "abcdef\nbctsf", "xxxabaxxx\nxxxaaxxx", "bcd\nabc", "d\nabcdef"], "outputs": ["0", "1", "7", "1", "0", "0", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "9", "2", "7", "4", "7", "6", "3", "0", "1", "9", "32", "34", "41", "57", "37", "19", "37", "90", "28", "76", "287", "1", "2", "1", "4", "1", "10", "2", "3", "3", "2", "2", "1", "5"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
12
codeforces
91c3babe38f68cd3ad2fb4f40f35e2f3
Restoring Table
Recently Polycarpus has learned the "bitwise AND" operation (which is also called "AND") of non-negative integers. Now he wants to demonstrate the school IT teacher his superb manipulation with the learned operation. For that Polycarpus came to school a little earlier and wrote on the board a sequence of non-negative integers *a*1,<=*a*2,<=...,<=*a**n*. He also wrote a square matrix *b* of size *n*<=×<=*n*. The element of matrix *b* that sits in the *i*-th row in the *j*-th column (we'll denote it as *b**ij*) equals: - the "bitwise AND" of numbers *a**i* and *a**j* (that is, *b**ij*<==<=*a**i* &amp; *a**j*), if *i*<=≠<=*j*; - -1, if *i*<==<=*j*. Having written out matrix *b*, Polycarpus got very happy and wiped *a* off the blackboard. But the thing is, the teacher will want this sequence to check whether Polycarpus' calculations were correct. Polycarus urgently needs to restore the removed sequence of integers, or else he won't prove that he can count correctly. Help Polycarpus, given matrix *b*, restore the sequence of numbers *a*1,<=*a*2,<=...,<=*a**n*, that he has removed from the board. Polycarpus doesn't like large numbers, so any number in the restored sequence mustn't exceed 109. The first line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the size of square matrix *b*. Next *n* lines contain matrix *b*. The *i*-th of these lines contains *n* space-separated integers: the *j*-th number represents the element of matrix *b**ij*. It is guaranteed, that for all *i* (1<=≤<=*i*<=≤<=*n*) the following condition fulfills: *b**ii* = -1. It is guaranteed that for all *i*,<=*j* (1<=≤<=*i*,<=*j*<=≤<=*n*; *i*<=≠<=*j*) the following condition fulfills: 0<=≤<=*b**ij*<=≤<=109, *b**ij*<==<=*b**ji*. Print *n* non-negative integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=109) — the sequence that Polycarpus wiped off the board. Separate the numbers by whitespaces. It is guaranteed that there is sequence *a* that satisfies the problem conditions. If there are multiple such sequences, you are allowed to print any of them. Sample Input 1 -1 3 -1 18 0 18 -1 0 0 0 -1 4 -1 128 128 128 128 -1 148 160 128 148 -1 128 128 160 128 -1 Sample Output 0 18 18 0 128 180 148 160
{"inputs": ["1\n-1", "3\n-1 18 0\n18 -1 0\n0 0 -1", "4\n-1 128 128 128\n128 -1 148 160\n128 148 -1 128\n128 160 128 -1", "5\n-1 0 0 0 0\n0 -1 1 0 0\n0 1 -1 0 0\n0 0 0 -1 0\n0 0 0 0 -1", "6\n-1 1835024 1966227 34816 68550800 34832\n1835024 -1 18632728 306185992 324272924 289412624\n1966227 18632728 -1 40 555155640 16846864\n34816 306185992 40 -1 306185000 272666176\n68550800 324272924 555155640 306185000 -1 289481232\n34832 289412624 16846864 272666176 289481232 -1", "7\n-1 1000000000 999999488 999999488 1000000000 1000000000 999999488\n1000000000 -1 999999488 999999488 1000000000 1000000000 999999488\n999999488 999999488 -1 999999999 999999488 999999488 999999999\n999999488 999999488 999999999 -1 999999488 999999488 999999999\n1000000000 1000000000 999999488 999999488 -1 1000000000 999999488\n1000000000 1000000000 999999488 999999488 1000000000 -1 999999488\n999999488 999999488 999999999 999999999 999999488 999999488 -1", "8\n-1 56086 2560 35584 6402 18688 22530 256\n56086 -1 2697 35592 6410 18696 22667 257\n2560 2697 -1 10824 10280 10248 10377 8193\n35584 35592 10824 -1 76040 76040 10248 73984\n6402 6410 10280 76040 -1 76040 14346 73984\n18688 18696 10248 76040 76040 -1 26632 73984\n22530 22667 10377 10248 14346 26632 -1 9217\n256 257 8193 73984 73984 73984 9217 -1", "9\n-1 0 0 2 0 2 10 2 0\n0 -1 17 16 16 17 0 17 16\n0 17 -1 16 16 17 0 17 16\n2 16 16 -1 16 18 2 18 16\n0 16 16 16 -1 16 0 16 16\n2 17 17 18 16 -1 2 19 16\n10 0 0 2 0 2 -1 2 0\n2 17 17 18 16 19 2 -1 16\n0 16 16 16 16 16 0 16 -1", "10\n-1 16 16 0 0 0 0 16 16 16\n16 -1 16 3 3 2 0 17 18 16\n16 16 -1 0 0 0 0 16 16 16\n0 3 0 -1 15 10 12 1 2 0\n0 3 0 15 -1 10 12 1 2 0\n0 2 0 10 10 -1 8 0 2 0\n0 0 0 12 12 8 -1 0 0 0\n16 17 16 1 1 0 0 -1 16 16\n16 18 16 2 2 2 0 16 -1 16\n16 16 16 0 0 0 0 16 16 -1", "2\n-1 0\n0 -1"], "outputs": ["0 ", "18 18 0 ", "128 180 148 160 ", "0 1 1 0 0 ", "69109907 324818716 555700411 306220904 928457660 289521232 ", "1000000000 1000000000 999999999 999999999 1000000000 1000000000 999999999 ", "56086 56223 10985 109384 80170 92424 31883 75009 ", "10 17 17 18 16 19 10 19 16 ", "16 19 16 15 15 10 12 17 18 16 ", "0 0 "]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
12
codeforces
91c49eb218a529b816dfd941b351be69
Queue
Little girl Susie went shopping with her mom and she wondered how to improve service quality. There are *n* people in the queue. For each person we know time *t**i* needed to serve him. A person will be disappointed if the time he waits is more than the time needed to serve him. The time a person waits is the total time when all the people who stand in the queue in front of him are served. Susie thought that if we swap some people in the queue, then we can decrease the number of people who are disappointed. Help Susie find out what is the maximum number of not disappointed people can be achieved by swapping people in the queue. The first line contains integer *n* (1<=≤<=*n*<=≤<=105). The next line contains *n* integers *t**i* (1<=≤<=*t**i*<=≤<=109), separated by spaces. Print a single number — the maximum number of not disappointed people in the queue. Sample Input 5 15 2 1 5 3 Sample Output 4
{"inputs": ["5\n15 2 1 5 3", "15\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "10\n13 2 5 55 21 34 1 8 1 3", "10\n8 256 16 1 2 1 64 4 128 32", "10\n10000 40000 10000 50000 20000 100000 10000 100 30000 500", "1\n1000000000", "15\n9 11 45 86 52 65 35 3 93 7 21 45 15 11 39", "20\n16839799 17525904 91276752 42650694 60106463 12243176 54892123 25142243 16015971 41250998 11150057 6994983 67700784 16562412 82163675 46178521 33914268 91966607 93976858 84100064", "26\n1000 4110030 64221 131521030 942374833 1003 2055015 32110 513757 16440130 263042057 32880256 128439 557559573 16051 8220066 469240078 65760513 256878 790176315 4012 2005 1027508 928528684 8030 805074697"], "outputs": ["4", "2", "6", "10", "6", "1", "6", "5", "21"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
158
codeforces
91ddbbe8aa042ec08491c7c25d7aba7b
Triangle
At a geometry lesson Bob learnt that a triangle is called right-angled if it is nondegenerate and one of its angles is right. Bob decided to draw such a triangle immediately: on a sheet of paper he drew three points with integer coordinates, and joined them with segments of straight lines, then he showed the triangle to Peter. Peter said that Bob's triangle is not right-angled, but is almost right-angled: the triangle itself is not right-angled, but it is possible to move one of the points exactly by distance 1 so, that all the coordinates remain integer, and the triangle become right-angled. Bob asks you to help him and find out if Peter tricks him. By the given coordinates of the triangle you should find out if it is right-angled, almost right-angled, or neither of these. The first input line contains 6 space-separated integers *x*1,<=*y*1,<=*x*2,<=*y*2,<=*x*3,<=*y*3 — coordinates of the triangle's vertices. All the coordinates are integer and don't exceed 100 in absolute value. It's guaranteed that the triangle is nondegenerate, i.e. its total area is not zero. If the given triangle is right-angled, output RIGHT, if it is almost right-angled, output ALMOST, and if it is neither of these, output NEITHER. Sample Input 0 0 2 0 0 1 2 3 4 5 6 6 -1 0 2 0 0 1 Sample Output RIGHT NEITHER ALMOST
{"inputs": ["0 0 2 0 0 1", "2 3 4 5 6 6", "-1 0 2 0 0 1", "27 74 85 23 100 99", "-97 -19 17 62 30 -76", "28 -15 86 32 98 -41", "-66 24 8 -29 17 62", "-83 40 -80 52 -71 43", "-88 67 -62 37 -49 75", "58 45 6 22 13 79", "75 86 -82 89 -37 -35", "34 74 -2 -95 63 -33", "-7 63 78 74 -39 -30", "-49 -99 7 92 61 -28", "-90 90 87 -92 -40 -26", "-100 -100 100 -100 0 73", "39 22 94 25 69 -23", "100 100 -100 100 1 -73", "0 0 0 1 1 0", "-100 -100 100 100 -100 100", "29 83 35 35 74 65", "28 -15 86 32 -19 43", "-28 12 -97 67 -83 -57", "-83 40 -80 52 -79 39", "30 8 49 13 25 27", "23 6 63 -40 69 46", "49 -7 19 -76 26 3", "0 0 1 0 2 1", "0 0 1 0 3 1", "0 0 1 0 2 2", "0 0 1 0 4 1", "0 0 1 0 100 1", "60 4 90 -53 32 -12", "52 -34 -37 -63 23 54", "39 22 95 25 42 -33", "-10 -11 62 6 -12 -3", "22 -15 -24 77 -69 -60", "99 85 90 87 64 -20", "-50 -37 -93 -6 -80 -80", "4 -13 4 -49 -24 -13", "0 -3 -3 -10 4 -7", "-45 -87 -34 -79 -60 -62", "-67 49 89 -76 -37 87", "22 32 -33 -30 -18 68", "36 1 -17 -54 -19 55", "55 44 15 14 23 83", "-19 0 -89 -54 25 -57", "69 -45 1 11 56 -63", "72 68 56 72 33 -88", "59 86 74 -49 77 88", "-50 0 0 50 0 -50", "-50 0 0 50 0 -51", "-50 0 0 50 0 -49", "-50 0 0 50 1 -50", "-50 0 0 50 -1 -50", "-50 0 0 49 0 -50", "-50 0 0 51 0 -50", "-50 0 1 50 0 -50", "-50 0 -1 50 0 -50", "-50 1 0 50 0 -50", "-50 -1 0 50 0 -50", "-51 0 0 50 0 -50", "-49 0 0 50 0 -50"], "outputs": ["RIGHT", "NEITHER", "ALMOST", "NEITHER", "NEITHER", "NEITHER", "NEITHER", "NEITHER", "NEITHER", "NEITHER", "NEITHER", "NEITHER", "NEITHER", "NEITHER", "NEITHER", "NEITHER", "NEITHER", "NEITHER", "RIGHT", "RIGHT", "NEITHER", "RIGHT", "RIGHT", "RIGHT", "RIGHT", "RIGHT", "RIGHT", "ALMOST", "ALMOST", "ALMOST", "NEITHER", "NEITHER", "ALMOST", "ALMOST", "ALMOST", "ALMOST", "ALMOST", "ALMOST", "ALMOST", "RIGHT", "NEITHER", "NEITHER", "NEITHER", "NEITHER", "ALMOST", "NEITHER", "NEITHER", "NEITHER", "RIGHT", "RIGHT", "RIGHT", "ALMOST", "ALMOST", "ALMOST", "ALMOST", "ALMOST", "ALMOST", "ALMOST", "ALMOST", "ALMOST", "ALMOST", "ALMOST", "ALMOST"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
36
codeforces
91e81a621aec1c42e9fa4f1997c14bf9
Luck is in Numbers
Vasya has been collecting transport tickets for quite a while now. His collection contains several thousands of tram, trolleybus and bus tickets. Vasya is already fed up with the traditional definition of what a lucky ticket is. Thus, he's looking for new perspectives on that. Besides, Vasya cannot understand why all tickets are only divided into lucky and unlucky ones. He thinks that all tickets are lucky but in different degrees. Having given the matter some thought, Vasya worked out the definition of a ticket's degree of luckiness. Let a ticket consist of 2*n* digits. Let's regard each digit as written as is shown on the picture: You have seen such digits on electronic clocks: seven segments are used to show digits. Each segment can either be colored or not. The colored segments form a digit. Vasya regards the digits as written in this very way and takes the right half of the ticket and puts it one the left one, so that the first digit coincides with the *n*<=+<=1-th one, the second digit coincides with the *n*<=+<=2-th one, ..., the *n*-th digit coincides with the 2*n*-th one. For each pair of digits, put one on another, he counts the number of segments colored in both digits and summarizes the resulting numbers. The resulting value is called the degree of luckiness of a ticket. For example, the degree of luckiness of ticket 03 equals four and the degree of luckiness of ticket 2345 equals six. You are given the number of a ticket containing 2*n* digits. Your task is to find among the tickets whose number exceeds the number of this ticket but also consists of 2*n* digits such ticket, whose degree of luckiness exceeds the degrees of luckiness of the given ticket. Moreover, if there are several such tickets, you should only choose the one with the smallest number. The first line contains the number of the ticket that consists of *k* characters (*k*<==<=2*n*,<=1<=≤<=*n*<=≤<=105). Print the number of the sought ticket or "-1" (without the quotes) if no such ticket exists. Sample Input 13 2345 88 Sample Output 20 2348 -1
{"inputs": ["13", "2345", "88", "682444", "685116", "576079", "569631", "662302", "453066", "659821", "26592659", "47699969", "09980988", "69886888", "9588995888", "39930089893999008989", "84163081988476808998", "88898888988889888898", "01273988890029888889", "18858998881886898888", "8259988583", "5898888944", "855889831888", "439968658988", "335598338288", "43223543566815212912981204669368711837288602368426888989998989988898989999998988988988999998999899984322884358881924880288488486998884783928868286842888888998888898888898889898888898898888888898889888", "99393666387527964893713203630389899998898999889989898999898899999899899899998889899998898989989889998888368888898788888990888868038988989889889888898989888889889998989989889899888888989888898998988899", "40724501726491585262016953677772948189547459145312538682757304290442786808955140603033718167250989898098898078698368686201885869883288848858845889691868888805988428844298880895618068983393806889898888", "79088264099789040101338987288228743957988889999888988998999888988999988999899889889999999898888899889988886808878908600889888328888899889798888998981888888899888888878998898888888958898899988888889988", "51974056597584768542734492125108488334626378590999898888998889899888898998889989988889898988999988899790085898898976884233448882618888038888883899099888888888888989888888888888988888888889888819998888", "496198999898", "09989988", "748989888889", "6984899899", "68623695792730582626313022231731418370802097728016898999999888889889989888989999898988988898888988888868389688838098868896902888793384830880209692808589899898888888888988888898888888898898888888898888", "34740506804988021948888998989898988889889889898888899989999999888988998998998889898989899998899998888439088688898808894888899898888898880988888989888889898989999988898898889899888989898989899888888888", "22938645962769613028898841128696546129021084561286040502773858728727299998988899899898989998888888888889889986296978908889880418888689802802008858828808868208988898888988999888889889989898898888888888", "34746525584443243456003041207650137412317331793360297058977077354535244802188888988888998998888889893498898958888388396600804028869848940893993789898089309887308898469904880874888898808889898888888888", "85134786461893350509517211574918339368780716712903244472148878199438599584095845405384064998889998998978978848989896088984387453988889938838099684288884488234888898993888858909888643588888493888998888", "0380023162775902996798876281379973370849", "3317497200125434836799763396859317396410", "5212759368584085865703568602327752094982", "547226955080909274578712855056537756831350123450633621352615", "090134011009710349472352007887283047446420798236414107901761"], "outputs": ["20", "2348", "-1", "682445", "685120", "576086", "569632", "662362", "453068", "659822", "26602660", "47804080", "28882888", "80888088", "9608886088", "39930098883883008888", "84163082000406308200", "88988888888888888888", "01274888880020488888", "18859888880885888888", "8259988588", "5898888945", "855889832088", "439968688868", "335598338388", "43223543566815212912981204669368711837288602368426888989998989988898989999998988988988999998999908884322354356680520280288020466836800083028860236842688888888888888888888888888888888888888888888880888", "99393666387527964893713203630389899998898999889989898999898899999899899899998889899998898989989890888838366638052086488300320363038888888888888888888888888888888888888888888888888888888888888888888088", "40724501726491585262016953677772948189547459145312538682757304290442786808955140603033718167250998884002450002648058526200685360000284808854045804530253868205030428044208680885504060303300806025088888", "79088264099789040101338987288228743957988889999888988998999888988999988999899889889999999898888899889988886808878908600889888328888899889798888998981888888899888888878998898888888968888888888888888888", "51974056597584768542734492125108488334626378590999898888998889899888898998889989988889898988999988899790085898898976884233448882618888038888883899099888888888888989888888888888988888888889888820888888", "496200006200", "20882088", "749888048888", "6984968848", "68623695792730582626313022231731418370802097728016898999999888889889989888989999898988988898888988888868389688838098868896902888793384830880209692808688888888888888888888888888888888888888888888888888", "34740506804988021948888998989898988889889889898888899989999999888988998998998889898989899998899998888439088688898808894888899898888898888888888888888888888888888888888888888888888888888888888888888888", "22938645962769613028898841128696546129021084561286040502773858728727299998988899899898989998888888888889889986296978908889884002868654602802008456028604050200385802802028888888888888888888888888888888", "34746525584443243456003041207650137412317331793360297058977077354535244802188888988888998998888889893498898958888388396600804028869848940893993789898089309887308898469904880874888898888888888888888888", "85134786461893350509517211574918339368780716712903244472148878199438599584095845405384064998889998998978978848989896088984387453988889938838099684288884488234888898993888858909888643588888498888888888", "0380023162775902996798876281379973370850", "3317497200125434836799763396859317396420", "5212759368584085865703568602327752094983", "547226955080909274578712855056537756831350123450633621352616", "090134011009710349472352007887283047446420798236414107901763"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1
codeforces
91f7cff482b2b493374285494a5a7025
Beautiful Sets of Points
Manao has invented a new mathematical term — a beautiful set of points. He calls a set of points on a plane beautiful if it meets the following conditions: 1. The coordinates of each point in the set are integers. 1. For any two points from the set, the distance between them is a non-integer. Consider all points (*x*,<=*y*) which satisfy the inequations: 0<=≤<=*x*<=≤<=*n*; 0<=≤<=*y*<=≤<=*m*; *x*<=+<=*y*<=&gt;<=0. Choose their subset of maximum size such that it is also a beautiful set of points. The single line contains two space-separated integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100). In the first line print a single integer — the size *k* of the found beautiful set. In each of the next *k* lines print a pair of space-separated integers — the *x*- and *y*- coordinates, respectively, of a point from the set. If there are several optimal solutions, you may print any of them. Sample Input 2 2 4 3 Sample Output 3 0 1 1 2 2 0 4 0 3 2 1 3 0 4 2
{"inputs": ["2 2", "4 3", "21 21", "10 1", "4 4", "1 1", "5 5", "100 100", "96 96", "99 100", "67 58", "67 59", "80 91", "100 11", "16 55", "13 71", "30 40", "77 77", "6 6", "37 42", "88 88", "95 99", "93 70", "4 6", "1 4", "2 10", "6 7", "28 28", "10 6", "85 48", "9 6", "2 6", "6 4", "6 10", "16 5", "7 6", "3 4", "13 18", "5 100", "11 9", "13 13", "1 5", "3 19", "10 10", "3 7", "98 76", "10 100"], "outputs": ["3\n0 1\n1 2\n2 0", "4\n0 3\n2 1\n3 0\n4 2", "22\n21 0\n20 1\n19 2\n18 3\n17 4\n16 5\n15 6\n14 7\n13 8\n12 9\n11 10\n10 11\n9 12\n8 13\n7 14\n6 15\n5 16\n4 17\n3 18\n2 19\n1 20\n0 21", "2\n1 0\n0 1", "5\n4 0\n3 1\n2 2\n1 3\n0 4", "2\n1 0\n0 1", "6\n5 0\n4 1\n3 2\n2 3\n1 4\n0 5", "101\n100 0\n99 1\n98 2\n97 3\n96 4\n95 5\n94 6\n93 7\n92 8\n91 9\n90 10\n89 11\n88 12\n87 13\n86 14\n85 15\n84 16\n83 17\n82 18\n81 19\n80 20\n79 21\n78 22\n77 23\n76 24\n75 25\n74 26\n73 27\n72 28\n71 29\n70 30\n69 31\n68 32\n67 33\n66 34\n65 35\n64 36\n63 37\n62 38\n61 39\n60 40\n59 41\n58 42\n57 43\n56 44\n55 45\n54 46\n53 47\n52 48\n51 49\n50 50\n49 51\n48 52\n47 53\n46 54\n45 55\n44 56\n43 57\n42 58\n41 59\n40 60\n39 61\n38 62\n37 63\n36 64\n35 65\n34 66\n33 67\n32 68\n31 69\n30 70\n29 71\n28 72\n27 7...", "97\n96 0\n95 1\n94 2\n93 3\n92 4\n91 5\n90 6\n89 7\n88 8\n87 9\n86 10\n85 11\n84 12\n83 13\n82 14\n81 15\n80 16\n79 17\n78 18\n77 19\n76 20\n75 21\n74 22\n73 23\n72 24\n71 25\n70 26\n69 27\n68 28\n67 29\n66 30\n65 31\n64 32\n63 33\n62 34\n61 35\n60 36\n59 37\n58 38\n57 39\n56 40\n55 41\n54 42\n53 43\n52 44\n51 45\n50 46\n49 47\n48 48\n47 49\n46 50\n45 51\n44 52\n43 53\n42 54\n41 55\n40 56\n39 57\n38 58\n37 59\n36 60\n35 61\n34 62\n33 63\n32 64\n31 65\n30 66\n29 67\n28 68\n27 69\n26 70\n25 71\n24 72\n23 73\n...", "100\n99 0\n98 1\n97 2\n96 3\n95 4\n94 5\n93 6\n92 7\n91 8\n90 9\n89 10\n88 11\n87 12\n86 13\n85 14\n84 15\n83 16\n82 17\n81 18\n80 19\n79 20\n78 21\n77 22\n76 23\n75 24\n74 25\n73 26\n72 27\n71 28\n70 29\n69 30\n68 31\n67 32\n66 33\n65 34\n64 35\n63 36\n62 37\n61 38\n60 39\n59 40\n58 41\n57 42\n56 43\n55 44\n54 45\n53 46\n52 47\n51 48\n50 49\n49 50\n48 51\n47 52\n46 53\n45 54\n44 55\n43 56\n42 57\n41 58\n40 59\n39 60\n38 61\n37 62\n36 63\n35 64\n34 65\n33 66\n32 67\n31 68\n30 69\n29 70\n28 71\n27 72\n26 73...", "59\n58 0\n57 1\n56 2\n55 3\n54 4\n53 5\n52 6\n51 7\n50 8\n49 9\n48 10\n47 11\n46 12\n45 13\n44 14\n43 15\n42 16\n41 17\n40 18\n39 19\n38 20\n37 21\n36 22\n35 23\n34 24\n33 25\n32 26\n31 27\n30 28\n29 29\n28 30\n27 31\n26 32\n25 33\n24 34\n23 35\n22 36\n21 37\n20 38\n19 39\n18 40\n17 41\n16 42\n15 43\n14 44\n13 45\n12 46\n11 47\n10 48\n9 49\n8 50\n7 51\n6 52\n5 53\n4 54\n3 55\n2 56\n1 57\n0 58", "60\n59 0\n58 1\n57 2\n56 3\n55 4\n54 5\n53 6\n52 7\n51 8\n50 9\n49 10\n48 11\n47 12\n46 13\n45 14\n44 15\n43 16\n42 17\n41 18\n40 19\n39 20\n38 21\n37 22\n36 23\n35 24\n34 25\n33 26\n32 27\n31 28\n30 29\n29 30\n28 31\n27 32\n26 33\n25 34\n24 35\n23 36\n22 37\n21 38\n20 39\n19 40\n18 41\n17 42\n16 43\n15 44\n14 45\n13 46\n12 47\n11 48\n10 49\n9 50\n8 51\n7 52\n6 53\n5 54\n4 55\n3 56\n2 57\n1 58\n0 59", "81\n80 0\n79 1\n78 2\n77 3\n76 4\n75 5\n74 6\n73 7\n72 8\n71 9\n70 10\n69 11\n68 12\n67 13\n66 14\n65 15\n64 16\n63 17\n62 18\n61 19\n60 20\n59 21\n58 22\n57 23\n56 24\n55 25\n54 26\n53 27\n52 28\n51 29\n50 30\n49 31\n48 32\n47 33\n46 34\n45 35\n44 36\n43 37\n42 38\n41 39\n40 40\n39 41\n38 42\n37 43\n36 44\n35 45\n34 46\n33 47\n32 48\n31 49\n30 50\n29 51\n28 52\n27 53\n26 54\n25 55\n24 56\n23 57\n22 58\n21 59\n20 60\n19 61\n18 62\n17 63\n16 64\n15 65\n14 66\n13 67\n12 68\n11 69\n10 70\n9 71\n8 72\n7 73\n6 ...", "12\n11 0\n10 1\n9 2\n8 3\n7 4\n6 5\n5 6\n4 7\n3 8\n2 9\n1 10\n0 11", "17\n16 0\n15 1\n14 2\n13 3\n12 4\n11 5\n10 6\n9 7\n8 8\n7 9\n6 10\n5 11\n4 12\n3 13\n2 14\n1 15\n0 16", "14\n13 0\n12 1\n11 2\n10 3\n9 4\n8 5\n7 6\n6 7\n5 8\n4 9\n3 10\n2 11\n1 12\n0 13", "31\n30 0\n29 1\n28 2\n27 3\n26 4\n25 5\n24 6\n23 7\n22 8\n21 9\n20 10\n19 11\n18 12\n17 13\n16 14\n15 15\n14 16\n13 17\n12 18\n11 19\n10 20\n9 21\n8 22\n7 23\n6 24\n5 25\n4 26\n3 27\n2 28\n1 29\n0 30", "78\n77 0\n76 1\n75 2\n74 3\n73 4\n72 5\n71 6\n70 7\n69 8\n68 9\n67 10\n66 11\n65 12\n64 13\n63 14\n62 15\n61 16\n60 17\n59 18\n58 19\n57 20\n56 21\n55 22\n54 23\n53 24\n52 25\n51 26\n50 27\n49 28\n48 29\n47 30\n46 31\n45 32\n44 33\n43 34\n42 35\n41 36\n40 37\n39 38\n38 39\n37 40\n36 41\n35 42\n34 43\n33 44\n32 45\n31 46\n30 47\n29 48\n28 49\n27 50\n26 51\n25 52\n24 53\n23 54\n22 55\n21 56\n20 57\n19 58\n18 59\n17 60\n16 61\n15 62\n14 63\n13 64\n12 65\n11 66\n10 67\n9 68\n8 69\n7 70\n6 71\n5 72\n4 73\n3 74\n...", "7\n6 0\n5 1\n4 2\n3 3\n2 4\n1 5\n0 6", "38\n37 0\n36 1\n35 2\n34 3\n33 4\n32 5\n31 6\n30 7\n29 8\n28 9\n27 10\n26 11\n25 12\n24 13\n23 14\n22 15\n21 16\n20 17\n19 18\n18 19\n17 20\n16 21\n15 22\n14 23\n13 24\n12 25\n11 26\n10 27\n9 28\n8 29\n7 30\n6 31\n5 32\n4 33\n3 34\n2 35\n1 36\n0 37", "89\n88 0\n87 1\n86 2\n85 3\n84 4\n83 5\n82 6\n81 7\n80 8\n79 9\n78 10\n77 11\n76 12\n75 13\n74 14\n73 15\n72 16\n71 17\n70 18\n69 19\n68 20\n67 21\n66 22\n65 23\n64 24\n63 25\n62 26\n61 27\n60 28\n59 29\n58 30\n57 31\n56 32\n55 33\n54 34\n53 35\n52 36\n51 37\n50 38\n49 39\n48 40\n47 41\n46 42\n45 43\n44 44\n43 45\n42 46\n41 47\n40 48\n39 49\n38 50\n37 51\n36 52\n35 53\n34 54\n33 55\n32 56\n31 57\n30 58\n29 59\n28 60\n27 61\n26 62\n25 63\n24 64\n23 65\n22 66\n21 67\n20 68\n19 69\n18 70\n17 71\n16 72\n15 73\n...", "96\n95 0\n94 1\n93 2\n92 3\n91 4\n90 5\n89 6\n88 7\n87 8\n86 9\n85 10\n84 11\n83 12\n82 13\n81 14\n80 15\n79 16\n78 17\n77 18\n76 19\n75 20\n74 21\n73 22\n72 23\n71 24\n70 25\n69 26\n68 27\n67 28\n66 29\n65 30\n64 31\n63 32\n62 33\n61 34\n60 35\n59 36\n58 37\n57 38\n56 39\n55 40\n54 41\n53 42\n52 43\n51 44\n50 45\n49 46\n48 47\n47 48\n46 49\n45 50\n44 51\n43 52\n42 53\n41 54\n40 55\n39 56\n38 57\n37 58\n36 59\n35 60\n34 61\n33 62\n32 63\n31 64\n30 65\n29 66\n28 67\n27 68\n26 69\n25 70\n24 71\n23 72\n22 73\n...", "71\n70 0\n69 1\n68 2\n67 3\n66 4\n65 5\n64 6\n63 7\n62 8\n61 9\n60 10\n59 11\n58 12\n57 13\n56 14\n55 15\n54 16\n53 17\n52 18\n51 19\n50 20\n49 21\n48 22\n47 23\n46 24\n45 25\n44 26\n43 27\n42 28\n41 29\n40 30\n39 31\n38 32\n37 33\n36 34\n35 35\n34 36\n33 37\n32 38\n31 39\n30 40\n29 41\n28 42\n27 43\n26 44\n25 45\n24 46\n23 47\n22 48\n21 49\n20 50\n19 51\n18 52\n17 53\n16 54\n15 55\n14 56\n13 57\n12 58\n11 59\n10 60\n9 61\n8 62\n7 63\n6 64\n5 65\n4 66\n3 67\n2 68\n1 69\n0 70", "5\n4 0\n3 1\n2 2\n1 3\n0 4", "2\n1 0\n0 1", "3\n2 0\n1 1\n0 2", "7\n6 0\n5 1\n4 2\n3 3\n2 4\n1 5\n0 6", "29\n28 0\n27 1\n26 2\n25 3\n24 4\n23 5\n22 6\n21 7\n20 8\n19 9\n18 10\n17 11\n16 12\n15 13\n14 14\n13 15\n12 16\n11 17\n10 18\n9 19\n8 20\n7 21\n6 22\n5 23\n4 24\n3 25\n2 26\n1 27\n0 28", "7\n6 0\n5 1\n4 2\n3 3\n2 4\n1 5\n0 6", "49\n48 0\n47 1\n46 2\n45 3\n44 4\n43 5\n42 6\n41 7\n40 8\n39 9\n38 10\n37 11\n36 12\n35 13\n34 14\n33 15\n32 16\n31 17\n30 18\n29 19\n28 20\n27 21\n26 22\n25 23\n24 24\n23 25\n22 26\n21 27\n20 28\n19 29\n18 30\n17 31\n16 32\n15 33\n14 34\n13 35\n12 36\n11 37\n10 38\n9 39\n8 40\n7 41\n6 42\n5 43\n4 44\n3 45\n2 46\n1 47\n0 48", "7\n6 0\n5 1\n4 2\n3 3\n2 4\n1 5\n0 6", "3\n2 0\n1 1\n0 2", "5\n4 0\n3 1\n2 2\n1 3\n0 4", "7\n6 0\n5 1\n4 2\n3 3\n2 4\n1 5\n0 6", "6\n5 0\n4 1\n3 2\n2 3\n1 4\n0 5", "7\n6 0\n5 1\n4 2\n3 3\n2 4\n1 5\n0 6", "4\n3 0\n2 1\n1 2\n0 3", "14\n13 0\n12 1\n11 2\n10 3\n9 4\n8 5\n7 6\n6 7\n5 8\n4 9\n3 10\n2 11\n1 12\n0 13", "6\n5 0\n4 1\n3 2\n2 3\n1 4\n0 5", "10\n9 0\n8 1\n7 2\n6 3\n5 4\n4 5\n3 6\n2 7\n1 8\n0 9", "14\n13 0\n12 1\n11 2\n10 3\n9 4\n8 5\n7 6\n6 7\n5 8\n4 9\n3 10\n2 11\n1 12\n0 13", "2\n1 0\n0 1", "4\n3 0\n2 1\n1 2\n0 3", "11\n10 0\n9 1\n8 2\n7 3\n6 4\n5 5\n4 6\n3 7\n2 8\n1 9\n0 10", "4\n3 0\n2 1\n1 2\n0 3", "77\n76 0\n75 1\n74 2\n73 3\n72 4\n71 5\n70 6\n69 7\n68 8\n67 9\n66 10\n65 11\n64 12\n63 13\n62 14\n61 15\n60 16\n59 17\n58 18\n57 19\n56 20\n55 21\n54 22\n53 23\n52 24\n51 25\n50 26\n49 27\n48 28\n47 29\n46 30\n45 31\n44 32\n43 33\n42 34\n41 35\n40 36\n39 37\n38 38\n37 39\n36 40\n35 41\n34 42\n33 43\n32 44\n31 45\n30 46\n29 47\n28 48\n27 49\n26 50\n25 51\n24 52\n23 53\n22 54\n21 55\n20 56\n19 57\n18 58\n17 59\n16 60\n15 61\n14 62\n13 63\n12 64\n11 65\n10 66\n9 67\n8 68\n7 69\n6 70\n5 71\n4 72\n3 73\n2 74\n...", "11\n10 0\n9 1\n8 2\n7 3\n6 4\n5 5\n4 6\n3 7\n2 8\n1 9\n0 10"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
20
codeforces
92033556eb9354fb8e42ff803e338e16
Polycarp at the Radio
Polycarp is a music editor at the radio station. He received a playlist for tomorrow, that can be represented as a sequence *a*1,<=*a*2,<=...,<=*a**n*, where *a**i* is a band, which performs the *i*-th song. Polycarp likes bands with the numbers from 1 to *m*, but he doesn't really like others. We define as *b**j* the number of songs the group *j* is going to perform tomorrow. Polycarp wants to change the playlist in such a way that the minimum among the numbers *b*1,<=*b*2,<=...,<=*b**m* will be as large as possible. Find this maximum possible value of the minimum among the *b**j* (1<=≤<=*j*<=≤<=*m*), and the minimum number of changes in the playlist Polycarp needs to make to achieve it. One change in the playlist is a replacement of the performer of the *i*-th song with any other group. The first line of the input contains two integers *n* and *m* (1<=≤<=*m*<=≤<=*n*<=≤<=2000). The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109), where *a**i* is the performer of the *i*-th song. In the first line print two integers: the maximum possible value of the minimum among the *b**j* (1<=≤<=*j*<=≤<=*m*), where *b**j* is the number of songs in the changed playlist performed by the *j*-th band, and the minimum number of changes in the playlist Polycarp needs to make. In the second line print the changed playlist. If there are multiple answers, print any of them. Sample Input 4 2 1 2 3 2 7 3 1 3 2 2 2 2 1 4 4 1000000000 100 7 1000000000 Sample Output 2 1 1 2 1 2 2 1 1 3 3 2 2 2 1 1 4 1 2 3 4
{"inputs": ["4 2\n1 2 3 2", "7 3\n1 3 2 2 2 2 1", "4 4\n1000000000 100 7 1000000000", "1 1\n1", "1 1\n381183829", "2 1\n234089514 461271539", "5 4\n3 1 495987801 522279660 762868488", "10 2\n20515728 1 580955166 856585851 1 738372422 1 2 1 900189620", "20 3\n3 2 2 3 3 3 2 3 3 3 2 748578511 149249674 844954396 321901094 3 255089924 244803836 3 943090472", "50 10\n820558149 7 10 7 9 9 7 7 7 9 7 10 8 8 10 8 6 8 9 9 8 971788012 9 8 9 10 6 5 871178015 4 10 5 7 9 10 9 10 4 643998638 8 10 9 10 766953454 5 9 10 10 8 10", "80 79\n17 59 54 75 68 69 69 67 62 77 65 78 54 69 59 73 68 57 65 54 66 46 68 68 67 65 75 39 62 63 45 78 72 62 78 34 74 68 78 68 79 60 64 56 68 76 66 44 43 69 74 75 44 66 71 78 41 75 71 77 59 56 78 52 61 64 64 53 79 34 79 79 65 45 79 67 65 78 68 74", "2 1\n1 1000000000", "9 2\n4681851 569491424 579550098 1 554288395 496088833 49710380 904873068 189406728", "7 4\n1 1 1 1 1 1 1", "10 4\n1 1 2 2 3 3 4 4 4 4", "9 5\n1 1 1 1 1 2 3 4 5", "5 4\n10 1 1 1 1", "4 2\n1 1 1 1", "7 3\n2 2 2 1 3 7 6", "8 3\n1 1 1 1 2 2 2 2", "12 4\n1 1 1 1 2 2 2 2 3 3 4 4", "7 2\n2 2 2 2 2 2 3", "6 3\n3 3 3 100 1 2", "13 4\n1 1 1 1 2 2 2 2 3 3 4 4 4", "10 2\n1 1 1 1 1 1 3 4 5 6"], "outputs": ["2 1\n1 2 1 2 ", "2 1\n1 3 3 2 2 2 1 ", "1 4\n1 2 3 4 ", "1 0\n1 ", "1 1\n1 ", "2 2\n1 1 ", "1 2\n3 1 2 4 762868488 ", "5 5\n1 1 2 2 1 2 1 2 1 2 ", "6 8\n2 2 2 3 3 3 2 3 3 3 2 1 1 1 1 3 1 1 3 2 ", "5 23\n1 2 4 2 3 3 7 7 7 3 7 4 2 2 5 2 6 8 3 3 8 1 4 8 9 5 6 5 1 4 6 5 7 9 6 9 6 4 1 8 10 9 10 1 5 9 10 10 8 10 ", "1 46\n17 7 4 36 22 29 30 20 9 40 13 42 5 31 8 73 23 57 14 54 18 46 24 25 21 15 37 39 10 63 3 47 72 62 48 1 33 26 49 27 55 60 11 6 28 76 19 2 43 69 35 38 44 66 32 50 41 75 71 77 59 56 51 52 61 12 64 53 58 34 70 79 16 45 79 67 65 78 68 74 ", "2 1\n1 1 ", "4 7\n1 1 1 1 2 2 2 2 189406728 ", "1 3\n2 3 4 1 1 1 1 ", "2 0\n1 1 2 2 3 3 4 4 4 4 ", "1 0\n1 1 1 1 1 2 3 4 5 ", "1 3\n2 3 4 1 1 ", "2 2\n2 2 1 1 ", "2 2\n2 2 2 1 3 1 3 ", "2 2\n3 3 1 1 2 2 2 2 ", "3 2\n3 1 1 1 4 2 2 2 3 3 4 4 ", "3 3\n1 1 2 2 2 2 1 ", "2 2\n2 3 3 1 1 2 ", "3 1\n3 1 1 1 2 2 2 2 3 3 4 4 4 ", "5 5\n2 1 1 1 1 1 2 2 2 2 "]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
3
codeforces
9220b32c3435f2ebc62e4b87277d09cc
Ciel and Robot
Fox Ciel has a robot on a 2D plane. Initially it is located in (0, 0). Fox Ciel code a command to it. The command was represented by string *s*. Each character of *s* is one move operation. There are four move operations at all: - 'U': go up, (x, y) <=→<= (x, y+1); - 'D': go down, (x, y) <=→<= (x, y-1); - 'L': go left, (x, y) <=→<= (x-1, y); - 'R': go right, (x, y) <=→<= (x+1, y). The robot will do the operations in *s* from left to right, and repeat it infinite times. Help Fox Ciel to determine if after some steps the robot will located in (*a*,<=*b*). The first line contains two integers *a* and *b*, (<=-<=109<=≤<=*a*,<=*b*<=≤<=109). The second line contains a string *s* (1<=≤<=|*s*|<=≤<=100, *s* only contains characters 'U', 'D', 'L', 'R') — the command. Print "Yes" if the robot will be located at (*a*,<=*b*), and "No" otherwise. Sample Input 2 2 RU 1 2 RU -1 1000000000 LRRLU 0 0 D Sample Output Yes No Yes Yes
{"inputs": ["2 2\nRU", "1 2\nRU", "-1 1000000000\nLRRLU", "0 0\nD", "0 0\nUURRDL", "987654321 987654321\nUURRDL", "4 2\nUURRDL", "4 3\nUURRDL", "4 4\nUURRDL", "4 6\nUURRDL", "4 7\nUURRDL", "1000000000 1000000000\nUURRDL", "-1 -1\nUR", "1 1\nUURRDDLL", "987654321 2\nUURDD", "0 123456789\nRRULL", "4 4\nUUUURRRRDDDDLLLL", "-491226083 -49122610\nUDRLDURLDLLLDUDURLRDUUDDUUULUDRDRDUULURDRLLDDDLUDUURLUUDLLDULLLLDDLDDUU", "-261597957 418556728\nLLLDLUDUULLRDDULLRRUDRDLULRLRLLRRUUDRRLRUDLRRLUDRDLLUUDUULRURLDLULUUULDDUURLRUDURRL", "-771928144 -3\nRUDULULDRDLLLULDDUDDDDUDULRULRUULDDDURUDLUURULLLDLLDDRDDRLRURUULRUURRUDLDLDDRLLULRRDRRLLUULUDRUUDRRD", "397346346 1\nDDURRUURLDLRRLULD", "-528551525 0\nUDRLRRLDLDLURRRRULDLRLRLURUUDDLRLLDRRULLUDLURDLUUULLLRUUUDRRURLDUDULDDRDDDRDL", "311692421 -129871846\nLLLDURULDDDDUDDURRLUUDRLDDRDURDDRUDUURLUDUDLDRUDDDUUURDRRUDRDRDURLLDURUUDRLDLDURRRRRRDULURDRU", "485940814 728911221\nURURU", "-843450986 632588242\nLURLULULRUDUDULRDDLUL", "647999516 -809999401\nUDLDDLLULUDDLLDUULRRRDLUDDLDDLRLRRDRURURDRRDRULUDRDULRULLRRLLDDRLRRUDRURDUULUDLRRLRDR", "352820537 -764444491\nRDDUDLUDDUDLRRRDRRRDRRDUDUDDURLRRLDRLLRLLLLUULUDRURRDRLDDLLDRDURDUDRUDDLUDRLURUDRURDRDDLDRLDLDLLU", "-284973644 -1\nDLULLDLRUUDRR", "356922591 -2\nRRLDLDUDRUUUULUUDDULDDUDD", "27033101 54066203\nUDDDRDLLLRUUDDLRDLDRLRUDDULRLLRULR", "-199335150 39867031\nLLURRDUULRUDDRDUUULDLDRDDLURDRLDRLLLRRRRRULRRRUUDD", "609504072 609504074\nULRLUDLDDR", "497684357 829473929\nRRLDUUURULURRLLRRLRLURRLDU", "551922835 183974295\nDUDUUULDRLRURRDULRRUDDLRLLUULLRLRDRDRR", "825368095 -825368096\nRD", "-458990423 -229495204\nDLLDDRLUDLRLUL", "285102789 570205594\nRRDULRULULRRDUURRLURUDDULLRDUL", "109928480 219856920\nLRURLRLURDRDLDRDLRDDUUDDLULDRRUUURRUDLLUULUUUR", "-532674020 532674026\nUURLLL", "999999999 0\nRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR", "0 0\nUDLRUDLRUDLRUDLRUDLRUDLRUDLRUDLRUDLRUDLRUDLRUDLRUDLRUDLRUDLRUDLRUDLRUDLRUDLRUDLRUDLRUDLRUDLRUDLRUDLR", "1 1\nUDLRUDLRUDLRUDLRUDLRUDLRUDLRUDLRUDLRUDLRUDLRUDLRUDLRUDLRUDLRUDLRUDLRUDLRUDLRUDLRUDLRUDLRUDLRUDLRUDLR", "-1000000000 -1000000000\nDLDLDLDLDLDLDLDLDLDLDLDLDLDLDLDLDLDLDLDLDLDLDLDLDLDLDLDLDLDLDLDLDLDLDLDLDLDLDLDLDLDLDLDLDLDLDLDLDLDL", "3 3\nUURR", "-2 -2\nUR", "5 5\nUDLR", "0 -1\nU", "-1 0\nR", "1000000000 1000000000\nURURURUR", "-1 -1\nRU", "1 1\nLD", "-2 -2\nUURR", "1000000000 0\nRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR", "2 6\nRUUUURLDDDL", "0 1\nLUUR", "1 1\nURDLDL", "-10 -10\nRU", "1000000000 1000000000\nRURURURURURURURURURURURURURURURURURURURURURURURURURURURURURURURURURURURURURURURURURURURURURURURURURU", "-1000000000 -500000000\nURR", "-2 0\nULLLDDRRRR", "999999999 -999999999\nRRRRRRRRRRRRRRRRRRRRRRRRRDDDDDDDDDDDDDDDDDDDDDDDDDLLLLLLLLLLLLLLLLLLLLLLLUUUUUUUUUUUUUUUUUUUUUUU", "-100 -100\nRU", "100 100\nRUL", "0 1\nUDLR", "0 1\nD", "0 -3\nRDDL"], "outputs": ["Yes", "No", "Yes", "Yes", "Yes", "Yes", "No", "Yes", "Yes", "Yes", "No", "Yes", "No", "No", "Yes", "Yes", "Yes", "Yes", "Yes", "Yes", "Yes", "Yes", "Yes", "Yes", "Yes", "Yes", "Yes", "Yes", "No", "No", "No", "No", "Yes", "No", "No", "No", "No", "No", "No", "Yes", "Yes", "No", "Yes", "No", "No", "No", "No", "No", "Yes", "No", "No", "No", "Yes", "Yes", "No", "Yes", "No", "Yes", "No", "Yes", "Yes", "No", "No", "Yes", "No", "No"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
8
codeforces
9220f6088bde1e658f48d2c43eca3a2e
Transformation: from A to B
Vasily has a number *a*, which he wants to turn into a number *b*. For this purpose, he can do two types of operations: - multiply the current number by 2 (that is, replace the number *x* by 2·*x*); - append the digit 1 to the right of current number (that is, replace the number *x* by 10·*x*<=+<=1). You need to help Vasily to transform the number *a* into the number *b* using only the operations described above, or find that it is impossible. Note that in this task you are not required to minimize the number of operations. It suffices to find any way to transform *a* into *b*. The first line contains two positive integers *a* and *b* (1<=≤<=*a*<=&lt;<=*b*<=≤<=109) — the number which Vasily has and the number he wants to have. If there is no way to get *b* from *a*, print "NO" (without quotes). Otherwise print three lines. On the first line print "YES" (without quotes). The second line should contain single integer *k* — the length of the transformation sequence. On the third line print the sequence of transformations *x*1,<=*x*2,<=...,<=*x**k*, where: - *x*1 should be equal to *a*, - *x**k* should be equal to *b*, - *x**i* should be obtained from *x**i*<=-<=1 using any of two described operations (1<=&lt;<=*i*<=≤<=*k*). If there are multiple answers, print any of them. Sample Input 2 162 4 42 100 40021 Sample Output YES 5 2 4 8 81 162 NO YES 5 100 200 2001 4002 40021
{"inputs": ["2 162", "4 42", "100 40021", "1 111111111", "1 1000000000", "999999999 1000000000", "1 2", "1 536870912", "11111 11111111", "59139 946224", "9859 19718", "25987 51974222", "9411 188222222", "25539 510782222", "76259 610072", "92387 184774", "8515 85151111", "91939 9193911", "30518 610361", "46646 373168844", "30070 300701", "13494 1079528", "96918 775344422", "13046 260921", "29174 5834811", "79894 319576421", "96022 1920442", "79446 6355681", "5440 27853056", "250000000 705032705", "17 35", "1 3", "2 11"], "outputs": ["YES\n5\n2 4 8 81 162 ", "NO", "YES\n5\n100 200 2001 4002 40021 ", "YES\n9\n1 11 111 1111 11111 111111 1111111 11111111 111111111 ", "NO", "NO", "YES\n2\n1 2 ", "YES\n30\n1 2 4 8 16 32 64 128 256 512 1024 2048 4096 8192 16384 32768 65536 131072 262144 524288 1048576 2097152 4194304 8388608 16777216 33554432 67108864 134217728 268435456 536870912 ", "YES\n4\n11111 111111 1111111 11111111 ", "YES\n5\n59139 118278 236556 473112 946224 ", "YES\n2\n9859 19718 ", "YES\n5\n25987 259871 2598711 25987111 51974222 ", "YES\n6\n9411 94111 941111 9411111 94111111 188222222 ", "YES\n6\n25539 255391 2553911 25539111 255391111 510782222 ", "YES\n4\n76259 152518 305036 610072 ", "YES\n2\n92387 184774 ", "YES\n5\n8515 85151 851511 8515111 85151111 ", "YES\n3\n91939 919391 9193911 ", "YES\n3\n30518 61036 610361 ", "YES\n7\n46646 466461 932922 9329221 93292211 186584422 373168844 ", "YES\n2\n30070 300701 ", "YES\n5\n13494 134941 269882 539764 1079528 ", "YES\n7\n96918 193836 1938361 3876722 38767221 387672211 775344422 ", "YES\n3\n13046 26092 260921 ", "YES\n4\n29174 58348 583481 5834811 ", "YES\n6\n79894 798941 1597882 15978821 31957642 319576421 ", "YES\n3\n96022 960221 1920442 ", "YES\n5\n79446 158892 317784 635568 6355681 ", "YES\n11\n5440 10880 108801 217602 435204 870408 1740816 3481632 6963264 13926528 27853056 ", "NO", "NO", "NO", "NO"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
275
codeforces
9244db8730fb75772e42e09626cc70a0
Lucky Transformation
Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Petya has a number consisting of *n* digits without leading zeroes. He represented it as an array of digits without leading zeroes. Let's call it *d*. The numeration starts with 1, starting from the most significant digit. Petya wants to perform the following operation *k* times: find the minimum *x* (1<=≤<=*x*<=&lt;<=*n*) such that *d**x*<==<=4 and *d**x*<=+<=1<==<=7, if *x* is odd, then to assign *d**x*<==<=*d**x*<=+<=1<==<=4, otherwise to assign *d**x*<==<=*d**x*<=+<=1<==<=7. Note that if no *x* was found, then the operation counts as completed and the array doesn't change at all. You are given the initial number as an array of digits and the number *k*. Help Petya find the result of completing *k* operations. The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=105,<=0<=≤<=*k*<=≤<=109) — the number of digits in the number and the number of completed operations. The second line contains *n* digits without spaces representing the array of digits *d*, starting with *d*1. It is guaranteed that the first digit of the number does not equal zero. In the single line print the result without spaces — the number after the *k* operations are fulfilled. Sample Input 7 4 4727447 4 2 4478 Sample Output 4427477 4478
{"inputs": ["7 4\n4727447", "4 2\n4478", "7 7\n4211147", "7 6\n4747477", "10 2\n9474444474", "10 47\n4214777477", "3 99\n447", "4 1000000000\n7747", "3 1000000000\n447", "3 100\n447", "7 74\n4777774", "10 200\n6860544593", "10 477\n5837934237", "47 7477\n83492039276961836565341994102530448486552156001", "100 0\n9179665522184092255095619209953008761499858159751083177424923082479016015954927554823400601862864827", "485 9554485\n77591213686327368525391827531734680282181149581181587323024775516707756080151536104831756264659461447807315739541829004122483827102803764919259852061561098901393332937462039404423475012940096002301663119780442182470831027122573263011092200024968051233448164275142862251531399243063800892848783227559284462449919786387761960941614255036371684927500361571685732032325070607701306810264624073744998990612133986362972207072576588540217974702060321406370425911824802563123926135054749895722", "74 7\n47437850490316923506619313479471062875964157742919669484484624083960118773", "47 7\n77774477747474477477477774747747447447774777474", "100 2\n7477774774777474774777777474474474744477777477774444477444774474477774777474774744477474744474777444", "99 1\n474747444774447474444477474747774774447444477744774744477747777474777774777474477744447447447447477", "74 1000000000\n77474447774774747474777447474777777477474444477747444777447444474744744444", "74 999999999\n47474777744447477747777774774777447474747747447744474777477474777774774447", "100 47\n4346440647444704624490777777537777677744747437443404484777536674477779371445774947477174444474400267", "100 1000000000\n5849347454478644774747479437170493249634474874684784475734456487776740780444477442497447771444047377", "154 96\n7967779274474413067517474773015431177704444740654941743448963746454006444442746745494233876247994374947948475494434494479684421447774484909784471488747487", "2 0\n47", "5 0\n12473"], "outputs": ["4427477", "4478", "4211177", "4444477", "9774444774", "4217777777", "477", "7744", "447", "447", "4777774", "6860544593", "5837934237", "83492039276961836565341994102530448486552156001", "9179665522184092255095619209953008761499858159751083177424923082479016015954927554823400601862864827", "77591213686327368525391827531734680282181149581181587323024475516707756080151536104831756264659461447807315739541829004122483827102803764919259852061561098901393332937462039404423475012940096002301663119780442182470831027122573263011092200024968051233448164275142862251531399243063800892848783227559284462449919786387761960941614255036371684927500361571685732032325070607701306810264624073744998990612133986362972207072576588540217974702060321406370425911824802563123926135054749895722", "44437850490316923506619313449771062875964157742919669484484624083960118773", "77774777747474477477477774747747447447774777474", "7777774474777474774777777474474474744477777477774444477444774474477774777474774744477474744474777444", "444747444774447474444477474747774774447444477744774744477747777474777774777474477744447447447447477", "77444444774774747474777447474777777477474444477747444777447444474744744444", "44444477744447477747777774774777447474747747447744474777477474777774774447", "4346440644444404624490777777537777677747747437443404484777536674477779371445774947477174444474400267", "5849377454448644774747479437170493249634474874684784475734456487776740780444477442497447771444047377", "7967779274444413067517444773015431177704444740654941743448963746454006444442746745494233876247994374947948475494434494479684421447774484909784471488747487", "47", "12473"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
7
codeforces
924ee6af45d93e3e9e8d31fd75d78f25
Palindromic Supersequence
You are given a string *A*. Find a string *B*, where *B* is a palindrome and *A* is a subsequence of *B*. A subsequence of a string is a string that can be derived from it by deleting some (not necessarily consecutive) characters without changing the order of the remaining characters. For example, "cotst" is a subsequence of "contest". A palindrome is a string that reads the same forward or backward. The length of string *B* should be at most 104. It is guaranteed that there always exists such string. You do not need to find the shortest answer, the only restriction is that the length of string *B* should not exceed 104. First line contains a string *A* (1<=≤<=|*A*|<=≤<=103) consisting of lowercase Latin letters, where |*A*| is a length of *A*. Output single line containing *B* consisting of only lowercase Latin letters. You do not need to find the shortest answer, the only restriction is that the length of string *B* should not exceed 104. If there are many possible *B*, print any of them. Sample Input aba ab Sample Output abaaabaa
{"inputs": ["aba", "ab", "krnyoixirslfszfqivgkaflgkctvbvksipwomqxlyqxhlbceuhbjbfnhofcgpgwdseffycthmlpcqejgskwjkbkbbmifnurnwyhevsoqzmtvzgfiqajfrgyuzxnrtxectcnlyoisbglpdbjbslxlpoymrcxmdtqhcnlvtqdwftuzgbdxsyscwbrguostbelnvtaqdmkmihmoxqtqlxvlsssisvqvvzotoyqryuyqwoknnqcqggysrqpkrccvyhxsjmhoqoyocwcriplarjoyiqrmmpmueqbsbljddwrumauczfziodpudheexalbwpiypmdjlmwtgdrzhpxneofhqzjdmurgvmrwdotuwyknlrbvuvtnhiouvqitgyfgfieonbaapyhwpcrmehxcpkijzfiayfvoxkpa", "mgrfmzxqpejcixxppqgvuawutgrmezjkteofjbnrvzzkvjtacfxjjokisavsgrslryxfqgrmdsqwptajbqzvethuljbdatxghfzqrwvfgakwmoawlzqjypmhllbbuuhbpriqsnibywlgjlxowyzagrfnqafvcqwktkcjwejevzbnxhsfmwojshcdypnvbuhhuzqmgovmvgwiizatoxgblyudipahfbkewmuneoqhjmbpdtwnznblwvtjrniwlbyblhppndspojrouffazpoxtqdfpjuhitvijrohavpqatofxwmksvjcvhdecxwwmosqiczjpkfafqlboxosnjgzgdraehzdltthemeusxhiiimrdrugabnxwsygsktkcslhjebfexucsyvlwrptebkjhefsvfrmcqqdlanbetrgzwylizmrystvpgrkhlicfadco", "hdmasfcjuigrwjchmjslmpynewnzpphmudzcbxzdexjuhktdtcoibzvevsmwaxakrtdfoivkvoooypyemiidadquqepxwqkesdnakxkbzrcjkgvwwxtqxvfpxcwitljyehldgsjytmekimkkndjvnzqtjykiymkmdzpwakxdtkzcqcatlevppgfhyykgmipuodjrnfjzhcmjdbzvhywprbwdcfxiffpzbjbmbyijkqnosslqbfvvicxvoeuzruraetglthgourzhfpnubzvblfzmmbgepjjyshchthulxar", "fggbyzobbmxtwdajawqdywnppflkkmtxzjvxopqvliwdwhzepcuiwelhbuotlkvesexnwkytonfrpqcxzzqzdvsmbsjcxxeugavekozfjlolrtqgwzqxsfgrnvrgfrqpixhsskbpzghndesvwptpvvkasfalzsetopervpwzmkgpcexqnvtnoulprwnowmsorscecvvvrjfwumcjqyrounqsgdruxttvtmrkivtxauhosokdiahsyrftzsgvgyveqwkzhqstbgywrvmsgfcfyuxpphvmyydzpohgdicoxbtjnsbyhoidnkrialowvlvmjpxcfeygqzphmbcjkupojsmmuqlydixbaluwezvnfasjfxilbyllwyipsmovdzosuwotcxerzcfuvxprtziseshjfcosalyqglpotxvxaanpocypsiyazsejjoximnbvqucftuvdksaxutvjeunodbipsumlaymjnzljurefjg", "qyyxqkbxsvfnjzttdqmpzinbdgayllxpfrpopwciejjjzadguurnnhvixgueukugkkjyghxknedojvmdrskswiotgatsajowionuiumuhyggjuoympuxyfahwftwufvocdguxmxabbxnfviscxtilzzauizsgugwcqtbqgoosefhkumhodwpgolfdkbuiwlzjydonwbgyzzrjwxnceltqgqelrrljmzdbftmaogiuosaqhngmdzxzlmyrwefzhqawmkdckfnyyjgdjgadtfjvrkdwysqofcgyqrnyzutycvspzbjmmesobvhshtqlrytztyieknnkporrbcmlopgtknlmsstzkigreqwgsvagmvbrvwypoxttmzzsgm", "scvlhflaqvniyiyofonowwcuqajuwscdrzhbvasymvqfnthzvtjcfuaftrbjghhvslcohwpxkggrbtatjtgehuqtorwinwvrtdldyoeeozxwippuahgkuehvsmyqtodqvlufqqmqautaqirvwzvtodzxtgxiinubhrbeoiybidutrqamsdnasctxatzkvkjkrmavdravnsxyngjlugwftmhmcvvxdbfndurrbmcpuoigjpssqcortmqoqttrabhoqvopjkxvpbqdqsilvlplhgqazauyvnodsxtwnomlinjpozwhrgrkqwmlwcwdkxjxjftexiavwrejvdjcfptterblxysjcheesyqsbgdrzjxbfjqgjgmvccqcyj", "oohkqxxtvxzmvfjjxyjwlbqmeqwwlienzkdbhswgfbkhfygltsucdijozwaiewpixapyazfztksjeoqjugjfhdbqzuezbuajfvvffkwprroyivfoocvslejffgxuiofisenroxoeixmdbzonmreikpflciwsbafrdqfvdfojgoziiibqhwwsvhnzmptgirqqulkgmyzrfekzqqujmdumxkudsgexisupedisgmdgebvlvrpyfrbrqjknrxyzfpwmsxjxismgd", "gilhoixzjgidfanqrmekjelnvicpuujlpxittgadgrhqallnkjlemwazntwfywjnrxdkgrnczlwzjyeyfktduzdjnivcldjjarfzmmdbyytvipbbnjqolfnlqjpidotxxfobgtgpvjmpddcyddwdcjsxxumuoyznhpvpqccgqnuouzojntanfwctthcgynrukcvshsuuqrxfdvqqggaatwytikkitywtaaggqqvdfxrquushsvckurnygchttcwfnatnjozuounqgccqpvphnzyoumuxxsjcdwddycddpmjvpgtgbofxxtodipjqlnfloqjnbbpivtyybdmmzfrajjdlcvinjdzudtkfyeyjzwlzcnrgkdxrnjwyfwtnzawmeljknllaqhrgdagttixpljuupcivnlejkemrqnafdigjzxiohlig", "abcab", "baaaaaaa", "baaaaaa", "baaaaaaaaa", "baaaaaaaa"], "outputs": ["abaaba", "abba", "krnyoixirslfszfqivgkaflgkctvbvksipwomqxlyqxhlbceuhbjbfnhofcgpgwdseffycthmlpcqejgskwjkbkbbmifnurnwyhevsoqzmtvzgfiqajfrgyuzxnrtxectcnlyoisbglpdbjbslxlpoymrcxmdtqhcnlvtqdwftuzgbdxsyscwbrguostbelnvtaqdmkmihmoxqtqlxvlsssisvqvvzotoyqryuyqwoknnqcqggysrqpkrccvyhxsjmhoqoyocwcriplarjoyiqrmmpmueqbsbljddwrumauczfziodpudheexalbwpiypmdjlmwtgdrzhpxneofhqzjdmurgvmrwdotuwyknlrbvuvtnhiouvqitgyfgfieonbaapyhwpcrmehxcpkijzfiayfvoxkpaapkxovfyaifzjikpcxhemrcpwhypaabnoeifgfygtiqvuoihntvuvbrlnkywutodwrmvgrumdjzqhfoenxphzrdgtwmljdm...", "mgrfmzxqpejcixxppqgvuawutgrmezjkteofjbnrvzzkvjtacfxjjokisavsgrslryxfqgrmdsqwptajbqzvethuljbdatxghfzqrwvfgakwmoawlzqjypmhllbbuuhbpriqsnibywlgjlxowyzagrfnqafvcqwktkcjwejevzbnxhsfmwojshcdypnvbuhhuzqmgovmvgwiizatoxgblyudipahfbkewmuneoqhjmbpdtwnznblwvtjrniwlbyblhppndspojrouffazpoxtqdfpjuhitvijrohavpqatofxwmksvjcvhdecxwwmosqiczjpkfafqlboxosnjgzgdraehzdltthemeusxhiiimrdrugabnxwsygsktkcslhjebfexucsyvlwrptebkjhefsvfrmcqqdlanbetrgzwylizmrystvpgrkhlicfadcoocdafcilhkrgpvtsyrmzilywzgrtebnaldqqcmrfvsfehjkbetprwlvyscuxef...", "hdmasfcjuigrwjchmjslmpynewnzpphmudzcbxzdexjuhktdtcoibzvevsmwaxakrtdfoivkvoooypyemiidadquqepxwqkesdnakxkbzrcjkgvwwxtqxvfpxcwitljyehldgsjytmekimkkndjvnzqtjykiymkmdzpwakxdtkzcqcatlevppgfhyykgmipuodjrnfjzhcmjdbzvhywprbwdcfxiffpzbjbmbyijkqnosslqbfvvicxvoeuzruraetglthgourzhfpnubzvblfzmmbgepjjyshchthulxarraxluhthchsyjjpegbmmzflbvzbunpfhzruoghtlgtearurzueovxcivvfbqlssonqkjiybmbjbzpffixfcdwbrpwyhvzbdjmchzjfnrjdoupimgkyyhfgppveltacqczktdxkawpzdmkmyikyjtqznvjdnkkmikemtyjsgdlheyjltiwcxpfvxqtxwwvgkjcrzbkxkandsekqwxpequ...", "fggbyzobbmxtwdajawqdywnppflkkmtxzjvxopqvliwdwhzepcuiwelhbuotlkvesexnwkytonfrpqcxzzqzdvsmbsjcxxeugavekozfjlolrtqgwzqxsfgrnvrgfrqpixhsskbpzghndesvwptpvvkasfalzsetopervpwzmkgpcexqnvtnoulprwnowmsorscecvvvrjfwumcjqyrounqsgdruxttvtmrkivtxauhosokdiahsyrftzsgvgyveqwkzhqstbgywrvmsgfcfyuxpphvmyydzpohgdicoxbtjnsbyhoidnkrialowvlvmjpxcfeygqzphmbcjkupojsmmuqlydixbaluwezvnfasjfxilbyllwyipsmovdzosuwotcxerzcfuvxprtziseshjfcosalyqglpotxvxaanpocypsiyazsejjoximnbvqucftuvdksaxutvjeunodbipsumlaymjnzljurefjggjferujlznjmyalmuspib...", "qyyxqkbxsvfnjzttdqmpzinbdgayllxpfrpopwciejjjzadguurnnhvixgueukugkkjyghxknedojvmdrskswiotgatsajowionuiumuhyggjuoympuxyfahwftwufvocdguxmxabbxnfviscxtilzzauizsgugwcqtbqgoosefhkumhodwpgolfdkbuiwlzjydonwbgyzzrjwxnceltqgqelrrljmzdbftmaogiuosaqhngmdzxzlmyrwefzhqawmkdckfnyyjgdjgadtfjvrkdwysqofcgyqrnyzutycvspzbjmmesobvhshtqlrytztyieknnkporrbcmlopgtknlmsstzkigreqwgsvagmvbrvwypoxttmzzsgmmgszzmttxopywvrbvmgavsgwqergikztssmlnktgpolmcbrropknnkeiytztyrlqthshvbosemmjbzpsvcytuzynrqygcfoqsywdkrvjftdagjdgjyynfkcdkmwaqhzfewry...", "scvlhflaqvniyiyofonowwcuqajuwscdrzhbvasymvqfnthzvtjcfuaftrbjghhvslcohwpxkggrbtatjtgehuqtorwinwvrtdldyoeeozxwippuahgkuehvsmyqtodqvlufqqmqautaqirvwzvtodzxtgxiinubhrbeoiybidutrqamsdnasctxatzkvkjkrmavdravnsxyngjlugwftmhmcvvxdbfndurrbmcpuoigjpssqcortmqoqttrabhoqvopjkxvpbqdqsilvlplhgqazauyvnodsxtwnomlinjpozwhrgrkqwmlwcwdkxjxjftexiavwrejvdjcfptterblxysjcheesyqsbgdrzjxbfjqgjgmvccqcyjjycqccvmgjgqjfbxjzrdgbsqyseehcjsyxlbrettpfcjdvjerwvaixetfjxjxkdwcwlmwqkrgrhwzopjnilmonwtxsdonvyuazaqghlplvlisqdqbpvxkjpovqohbarttqoqm...", "oohkqxxtvxzmvfjjxyjwlbqmeqwwlienzkdbhswgfbkhfygltsucdijozwaiewpixapyazfztksjeoqjugjfhdbqzuezbuajfvvffkwprroyivfoocvslejffgxuiofisenroxoeixmdbzonmreikpflciwsbafrdqfvdfojgoziiibqhwwsvhnzmptgirqqulkgmyzrfekzqqujmdumxkudsgexisupedisgmdgebvlvrpyfrbrqjknrxyzfpwmsxjxismgddgmsixjxsmwpfzyxrnkjqrbrfyprvlvbegdmgsidepusixegsdukxmudmjuqqzkefrzymgkluqqrigtpmznhvswwhqbiiizogjofdvfqdrfabswiclfpkiermnozbdmxieoxornesifoiuxgffjelsvcoofviyorrpwkffvvfjaubzeuzqbdhfjgujqoejsktzfzaypaxipweiawzojidcustlgyfhkbfgwshbdkzneilwwqemqblw...", "gilhoixzjgidfanqrmekjelnvicpuujlpxittgadgrhqallnkjlemwazntwfywjnrxdkgrnczlwzjyeyfktduzdjnivcldjjarfzmmdbyytvipbbnjqolfnlqjpidotxxfobgtgpvjmpddcyddwdcjsxxumuoyznhpvpqccgqnuouzojntanfwctthcgynrukcvshsuuqrxfdvqqggaatwytikkitywtaaggqqvdfxrquushsvckurnygchttcwfnatnjozuounqgccqpvphnzyoumuxxsjcdwddycddpmjvpgtgbofxxtodipjqlnfloqjnbbpivtyybdmmzfrajjdlcvinjdzudtkfyeyjzwlzcnrgkdxrnjwyfwtnzawmeljknllaqhrgdagttixpljuupcivnlejkemrqnafdigjzxiohliggilhoixzjgidfanqrmekjelnvicpuujlpxittgadgrhqallnkjlemwazntwfywjnrxdkgrnczlw...", "abcabbacba", "baaaaaaaaaaaaaab", "baaaaaaaaaaaab", "baaaaaaaaaaaaaaaaaab", "baaaaaaaaaaaaaaaab"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
316
codeforces
925e553c109453d152cad07257492d18
Correct Solution?
One cold winter evening Alice and her older brother Bob was sitting at home near the fireplace and giving each other interesting problems to solve. When it was Alice's turn, she told the number *n* to Bob and said: —Shuffle the digits in this number in order to obtain the smallest possible number without leading zeroes. —No problem! — said Bob and immediately gave her an answer. Alice said a random number, so she doesn't know whether Bob's answer is correct. Help her to find this out, because impatient brother is waiting for the verdict. The first line contains one integer *n* (0<=≤<=*n*<=≤<=109) without leading zeroes. The second lines contains one integer *m* (0<=≤<=*m*<=≤<=109) — Bob's answer, possibly with leading zeroes. Print OK if Bob's answer is correct and WRONG_ANSWER otherwise. Sample Input 3310 1033 4 5 Sample Output OK WRONG_ANSWER
{"inputs": ["3310\n1033", "4\n5", "40\n04", "12\n12", "432\n234", "17109\n01179", "888\n888", "912\n9123", "0\n00", "11110\n1111", "7391\n1397", "201\n102", "111111111\n111111111", "32352320\n22203335", "1000000000\n1", "994321\n123499", "10101\n10101", "666\n0666", "2\n02", "313\n133", "987235645\n234556789", "90812\n010289", "123\n321", "707\n770", "77774444\n47474747", "1270\n1027", "320\n23", "123456789\n123456789", "918273645\n546372819", "300000003\n30000003", "0\n0", "0\n7"], "outputs": ["OK", "WRONG_ANSWER", "WRONG_ANSWER", "OK", "OK", "WRONG_ANSWER", "OK", "WRONG_ANSWER", "WRONG_ANSWER", "WRONG_ANSWER", "WRONG_ANSWER", "OK", "OK", "WRONG_ANSWER", "WRONG_ANSWER", "OK", "WRONG_ANSWER", "WRONG_ANSWER", "WRONG_ANSWER", "OK", "OK", "WRONG_ANSWER", "WRONG_ANSWER", "WRONG_ANSWER", "WRONG_ANSWER", "OK", "WRONG_ANSWER", "OK", "WRONG_ANSWER", "WRONG_ANSWER", "OK", "WRONG_ANSWER"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
95
codeforces
92637dfd121876c5454d4403888576c8
Flow Control
You have to handle a very complex water distribution system. The system consists of $n$ junctions and $m$ pipes, $i$-th pipe connects junctions $x_i$ and $y_i$. The only thing you can do is adjusting the pipes. You have to choose $m$ integer numbers $f_1$, $f_2$, ..., $f_m$ and use them as pipe settings. $i$-th pipe will distribute $f_i$ units of water per second from junction $x_i$ to junction $y_i$ (if $f_i$ is negative, then the pipe will distribute $|f_i|$ units of water per second from junction $y_i$ to junction $x_i$). It is allowed to set $f_i$ to any integer from $-2 \cdot 10^9$ to $2 \cdot 10^9$. In order for the system to work properly, there are some constraints: for every $i \in [1, n]$, $i$-th junction has a number $s_i$ associated with it meaning that the difference between incoming and outcoming flow for $i$-th junction must be exactly $s_i$ (if $s_i$ is not negative, then $i$-th junction must receive $s_i$ units of water per second; if it is negative, then $i$-th junction must transfer $|s_i|$ units of water per second to other junctions). Can you choose the integers $f_1$, $f_2$, ..., $f_m$ in such a way that all requirements on incoming and outcoming flows are satisfied? The first line contains an integer $n$ ($1 \le n \le 2 \cdot 10^5$) — the number of junctions. The second line contains $n$ integers $s_1, s_2, \dots, s_n$ ($-10^4 \le s_i \le 10^4$) — constraints for the junctions. The third line contains an integer $m$ ($0 \le m \le 2 \cdot 10^5$) — the number of pipes. $i$-th of the next $m$ lines contains two integers $x_i$ and $y_i$ ($1 \le x_i, y_i \le n$, $x_i \ne y_i$) — the description of $i$-th pipe. It is guaranteed that each unordered pair $(x, y)$ will appear no more than once in the input (it means that there won't be any pairs $(x, y)$ or $(y, x)$ after the first occurrence of $(x, y)$). It is guaranteed that for each pair of junctions there exists a path along the pipes connecting them. If you can choose such integer numbers $f_1, f_2, \dots, f_m$ in such a way that all requirements on incoming and outcoming flows are satisfied, then output "Possible" in the first line. Then output $m$ lines, $i$-th line should contain $f_i$ — the chosen setting numbers for the pipes. Pipes are numbered in order they appear in the input. Otherwise output "Impossible" in the only line. Sample Input 4 3 -10 6 1 5 1 2 3 2 2 4 3 4 3 1 4 3 -10 6 4 5 1 2 3 2 2 4 3 4 3 1 Sample Output Possible 4 -6 8 -7 7 Impossible
{"inputs": ["4\n3 -10 6 1\n5\n1 2\n3 2\n2 4\n3 4\n3 1", "4\n3 -10 6 4\n5\n1 2\n3 2\n2 4\n3 4\n3 1", "1\n0\n0", "1\n123\n0", "2\n-1 1\n1\n1 2", "2\n-1 1\n1\n2 1"], "outputs": ["Possible\n-3\n-6\n1\n0\n0", "Impossible", "Possible", "Impossible", "Possible\n1", "Possible\n-1"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
2
codeforces
92666187f65dafd187e08ecca21dfb68
Servers
There are *n* servers in a laboratory, each of them can perform tasks. Each server has a unique id — integer from 1 to *n*. It is known that during the day *q* tasks will come, the *i*-th of them is characterized with three integers: *t**i* — the moment in seconds in which the task will come, *k**i* — the number of servers needed to perform it, and *d**i* — the time needed to perform this task in seconds. All *t**i* are distinct. To perform the *i*-th task you need *k**i* servers which are unoccupied in the second *t**i*. After the servers begin to perform the task, each of them will be busy over the next *d**i* seconds. Thus, they will be busy in seconds *t**i*,<=*t**i*<=+<=1,<=...,<=*t**i*<=+<=*d**i*<=-<=1. For performing the task, *k**i* servers with the smallest ids will be chosen from all the unoccupied servers. If in the second *t**i* there are not enough unoccupied servers, the task is ignored. Write the program that determines which tasks will be performed and which will be ignored. The first line contains two positive integers *n* and *q* (1<=≤<=*n*<=≤<=100, 1<=≤<=*q*<=≤<=105) — the number of servers and the number of tasks. Next *q* lines contains three integers each, the *i*-th line contains integers *t**i*, *k**i* and *d**i* (1<=≤<=*t**i*<=≤<=106, 1<=≤<=*k**i*<=≤<=*n*, 1<=≤<=*d**i*<=≤<=1000) — the moment in seconds in which the *i*-th task will come, the number of servers needed to perform it, and the time needed to perform this task in seconds. The tasks are given in a chronological order and they will come in distinct seconds. Print *q* lines. If the *i*-th task will be performed by the servers, print in the *i*-th line the sum of servers' ids on which this task will be performed. Otherwise, print -1. Sample Input 4 3 1 3 2 2 2 1 3 4 3 3 2 3 2 3 5 1 2 8 6 1 3 20 4 2 1 6 5 5 10 1 1 15 3 6 21 8 8 Sample Output 6 -1 10 3 3 6 9 30 -1 15 36
{"inputs": ["4 3\n1 3 2\n2 2 1\n3 4 3", "3 2\n3 2 3\n5 1 2", "8 6\n1 3 20\n4 2 1\n6 5 5\n10 1 1\n15 3 6\n21 8 8", "4 1\n6 1 1", "1 10\n4 1 1\n9 1 1\n10 1 1\n12 1 1\n13 1 1\n15 1 1\n16 1 1\n18 1 1\n19 1 1\n20 1 1", "4 10\n1 1 1\n3 1 2\n4 1 2\n6 1 2\n8 1 2\n13 1 2\n16 1 1\n17 1 2\n19 3 1\n20 1 1", "100 1\n1000000 100 1000", "5 3\n1 4 10\n2 2 5\n3 1 6", "4 5\n1 2 3\n2 1 3\n3 1 2\n4 3 3\n5 4 1", "5 3\n1 4 4\n4 2 2\n5 5 2", "10 4\n1 5 20\n2 5 200\n100 6 20\n101 1 100", "8 6\n1 3 20\n4 2 1\n6 6 5\n9 1 1\n15 3 6\n21 8 8", "5 4\n1 1 4\n2 4 4\n5 2 20\n11 5 2", "8 4\n1 3 2\n2 3 100\n10 6 20\n11 5 20", "5 3\n1 3 4\n4 3 4\n6 4 1", "4 3\n1 3 10\n2 2 15\n12 4 1"], "outputs": ["6\n-1\n10", "3\n3", "6\n9\n30\n-1\n15\n36", "1", "1\n1\n1\n1\n1\n1\n1\n1\n1\n1", "1\n1\n2\n1\n1\n1\n1\n1\n6\n1", "5050", "10\n-1\n5", "3\n3\n4\n-1\n10", "10\n-1\n15", "15\n40\n-1\n1", "6\n9\n-1\n4\n15\n36", "1\n14\n-1\n15", "6\n15\n-1\n21", "6\n-1\n10", "6\n-1\n10"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
26
codeforces
926f692c16a1c9cdb53c696bf20cd7b4
Lucky Common Subsequence
In mathematics, a subsequence is a sequence that can be derived from another sequence by deleting some elements without changing the order of the remaining elements. For example, the sequence BDF is a subsequence of ABCDEF. A substring of a string is a continuous subsequence of the string. For example, BCD is a substring of ABCDEF. You are given two strings *s*1, *s*2 and another string called *virus*. Your task is to find the longest common subsequence of *s*1 and *s*2, such that it doesn't contain *virus* as a substring. The input contains three strings in three separate lines: *s*1, *s*2 and *virus* (1<=≤<=|*s*1|,<=|*s*2|,<=|*virus*|<=≤<=100). Each string consists only of uppercase English letters. Output the longest common subsequence of *s*1 and *s*2 without *virus* as a substring. If there are multiple answers, any of them will be accepted. If there is no valid common subsequence, output 0. Sample Input AJKEQSLOBSROFGZ OVGURWZLWVLUXTH OZ AA A A Sample Output ORZ 0
{"inputs": ["AJKEQSLOBSROFGZ\nOVGURWZLWVLUXTH\nOZ", "AA\nA\nA", "PWBJTZPQHA\nZJMKLWSROQ\nUQ", "QNHRPFYMAAPJDUHBAEXNEEZSTMYHVGQPYKNMVKMBVSVLIYGUVMJHEFLJEPIWFHSLISTGOKRXNMSCXYKMAXBPKCOCNTIRPCUEPHXM\nRRFCZUGFDRKKMQTOETNELXMEWGOCDHFKIXOPVHHEWTCDNXVFKFKTKNWKEIKTCMHMHDNCLLVQSGKHBCDDYVVVQIRPZEOPUGQUGRHH\nR", "CGPWTAPEVBTGANLCLVSHQIIKHDPVUHRSQPXHSNYAHPGBECICFQYDFRTRELLLEDZYWJSLOBSKDGRRDHNRRGIXAMEBGFJJTEIGUGRU\nHAWYVKRRBEIWNOGYMIYQXDCFXMMCSAYSOXQFHHIFRRCJRAWHLDDHHHAKHXVKCVPBFGGEXUKWTFWMOUUGMXTSBUTHXCJCWHCQQTYQ\nANKFDWLYSX", "AUNBEKNURNUPHXQYKUTAHCOLMPRQZZTVDUYCTNIRACQQTQAIDTAWJXBUTIZUASDIJZWLHAQVGCAHKTZMXSDVVWAIGQEALRFKFYTT\nQBVRFKPKLYZLYNRFTRJZZQEYAEKPFXVICUVFVQSDENBJYYNCFTOZHULSWJQTNELYLKCZTGHOARDCFXBXQGGSQIVUCJVNGFZEEZQE\nN", "BGIIURZTEUJJULBWKHDQBRFGEUOMQSREOTILICRSBUHBGTSRDHKVDDEBVHGMHXUVFJURSMFDJOOOWCYPJDVRVKLDHICPNKTBFXDJ\nXOADNTKNILGNHHBNFYNDWUNXBGDFUKUVHLPDOGOYRMOTAQELLRMHFAQEOXFWGAQUROVUSWOAWFRVIRJQVXPCXLSCQLCUWKBZUFQP\nYVF", "AXBPBDEYIYKKCZBTLKBUNEQLCXXLKIUTOOATYDXYYQCLFAXAEIGTFMNTTQKCQRMEEFRYVYXAOLMUQNPJBMFBUGVXFZAJSBXWALSI\nVWFONLLKSHGHHQSFBBFWTXAITPUKNDANOCLMNFTAAMJVDLXYPILPCJCFWTNBQWEOMMXHRYHEGBJIVSXBBGQKXRIYNZFIWSZPPUUM\nPPKKLHXWWT", "XKTAOCPCVMIOGCQKPENDKIZRZBZVRTBTGCDRQUIMVHABDIHSCGWPUTQKLPBOXAYICPWJBFLFSEPERGJZHRINEHQMYTOTKLCQCSMZ\nAITFIOUTUVZLSSIYWXSYTQMFLICCXOFSACHTKGPXRHRCGXFZXPYWKWPUOIDNEEZOKMOUYGVUJRQTIRQFCSBCWXVFCIAOLZDGENNI\nDBHOIORVCPNXCDOJKSYYIENQRJGZFHOWBYQIITMTVWXRMAMYILTHBBAJRJELWMIZOZBGPDGSTIRTQIILJRYICMUQTUAFKDYGECPY", "UNGXODEEINVYVPHYVGSWPIPFMFLZJYRJIPCUSWVUDLLSLRPJJFWCUOYDUGXBRKWPARGLXFJCNNFUIGEZUCTPFYUIMQMJLQHTIVPO\nBWDEGORKXYCXIDWZKGFCUYIDYLTWLCDBUVHPAPFLIZPEUINQSTNRAOVYKZCKFWIJQVLSVCGLTCOEMAYRCDVVQWQENTWZALWUKKKA\nXDGPZXADAFCHKILONSXFGRHIQVMIYWUTJUPCCEKYQVYAENRHVWERJSNPVEMRYSZGYBNTQLIFKFISKZJQIQQGSKVGCNMPNIJDRTXI", "KOROXDDWEUVYWJIXSFPEJFYZJDDUXISOFJTIFJSBTWIJQHMTQWLAGGMXTFALRXYCMGZNKYQRCDVTPRQDBAALTWAXTNLDPYWNSFKE\nNHZGRZFMFQGSAYOJTFKMMUPOOQXWCPPAIVRJHINJPHXTTBWRIYNOHMJKBBGXVXYZDBVBBTQRXTOFLBBCXGNICBKAAGOKAYCCJYCW\nXCXLBESCRBNKWYGFDZFKWYNLFAKEWWGRUIAQGNCFDQXCHDBEQDSWSNGVKUFOGGSPFFZWTXGZQMMFJXDWOPUEZCMZEFDHXTRJTNLW", "ESQZPIRAWBTUZSOWLYKIYCHZJPYERRXPJANKPZVPEDCXCJIDTLCARMAOTZMHJVDJXRDNQRIIOFIUTALVSCKDUSAKANKKOFKWINLQ\nGKSTYEAXFJQQUTKPZDAKHZKXCJDONKBZOTYGLYQJOGKOYMYNNNQRRVAGARKBQYJRVYYPFXTIBJJYQUWJUGAUQZUVMUHXLIQWGRMP\nUFPHNRDXLNYRIIYVOFRKRUQCWAICQUUBPHHEGBCILXHHGLOBKADQVPSQCMXJRLIZQPSRLZJNZVQPIURDQUKNHVVYNVBYGXXXXJDI", "UAYQUMTSNGMYBORUYXJJQZVAGBRVDWUTGUYYYOTWAHVKGGOHADXULFUFQULSAGDWFJCSDKPWBROYZIFRGGRVZQMEHKHCKNHTQSMK\nSVKVTPUZOBRKGLEAAXMIUSRISOTDIFFUCODYGNYIPSWEEBHGNWRZETXSVVMQTRBVFZMYHOHUCMLBUXBMPMSNCSHFZTAFUVTMQFGL\nTNICVANBEBOQASUEJJAOJXWNMDGAAVYNHRPSMKGMXZDJHCZHFHRRMIDWUOQCZSBKDPLSGHNHFKFYDRGVKXOLPOOWBPOWSDFLEJVX", "KEJHTOKHMKWTYSJEAJAXGADRHUKBCRHACSRDNSZIHTPQNLOSRKYBGYIIJDINTXRPMWSVMMBODAYPVVDDTIXGDIOMWUAKZVFKDAUM\nWTEVPIFAAJYIDTZSZKPPQKIOMHDZTKDMFVKSJRUFMNHZJPVSQYELWYAFACGGNRORSLGYVXAEYVLZBLDEHYDGOFDSWUYCXLXDKFSU\nTUZEQBWVBVTKETQ", "EGQYYSKTFTURZNRDVIWBYXMRDGFWMYKFXGIFOGYJSXKDCJUAGZPVTYCHIXVFTVTCXMKHZFTXSMMQVFXZGKHCIYODDRZEYECDLKNG\nPEXXCTRFJAAKPOTBAEFRLDRZKORNMXHHXTLKMKCGPVPUOBELPLFQFXOBZWIVIQCHEJQPXKGSCQAWIMETCJVTAGXJIINTADDXJTKQ\nQURSEKPMSSEVQZI", "ZFFBNYVXOZCJPSRAEACVPAUKVTCVZYQPHVENTKOCMHNIYYMIKKLNKHLWHHWAQMWFTSYEOQQFEYAAYGMPNZCRYBVNAQTDSLXZGBCG\nPIQHLNEWAMFAKGHBGZAWRWAXCSKUDZBDOCTXAHSVFZACXGFMDSYBYYDDNQNBEZCYCULSMMPBTQOJQNRPZTRCSDLIYPLVUGJPKDTG\nZBFJPLNAKWQBTUVJKMHVBATAM", "BTWZLIKDACZVLCKMVTIQHLFBNRCBDSWPFFKGPCQFPTOIJLPFCDMFGQKFHTDFFCCULUAYPXXIIIWBZIDMOPNHPZBEXLVARJFTBFOE\nMDXYKKWZVASJPPWRCYNMRAOBBLUNBSMQAPCPSFAGLXWJRBQTBRWXYNQGWECYNFIAJXDMUHIIMDFMSHLPIMYQXNRRUSSNXALGNWIK\nKNFVBVAOWXMZVUHAVUDKDBUVAKNHACZBGBHMUOPHWGQSDFXLHB", "GOZVMIRQIGYGVAGOREQTXFXPEZYOJOXPNDGAESICXHMKQDXQPRLMRVWHXFEJVCWZDLYMQLDURUXZPTLEHPTSKXGSNEQDKLVFFLDX\nIMEVFCZXACKRRJVXDRKFWTLTRTLQQDHEBZLCOCNVPABQMIWJHRLKFUKWOVVWGGNWCJNRYOYOAJFQWCLHQIQRBZTVWKBFOXKEHHQP\nSZ", "BBYUVCIYLNUJPSEYCAAPQSDNSDDTNEHQZDPBEKQAWNAKEYFBNEEBGPDPRLCSVOWYDEDRPPEDOROCHRCNQUSPNVXGRXHNLKDETWQC\nBQCQXCAHADGJHBYIKEUWNXFUOOTVCCKJPJJCMWLAWWKSDGHFNZTCPSQNRTPCBLXDTSJLRHSCCZXQXCVLVGTROOUCUQASIQHZGNEI\nRYE", "WZRKLETJRBBRZKGHEFBVEFVLIERBPSEGJVSNUZUICONWWBOOTHCOJLLZFNOCNOFJQZTZWBLKHGIWWWPBUYWBAHYJGEBJZJDTNBGN\nZINFGDCNKHYFZYYWHTIHZTKWXXXMSWOVOPQDTRWSQKBWWCPEMYFVGARELELBLGEVJCMOCFTTUVCYUQUSFONAMWKVDWMGXVNZJBWH\nAFPA", "ABABABB\nABABABB\nABABB", "ABBB\nABBB\nABB", "A\nBABAABAAABABABABABABAABABABABBABABABABAABBABBABAABABAABAABBAAAAAABBABABABABAABABAABABABABAABAABABABA\nB", "ABBAABAAABABAABAABABABABAABBBABABABAAABBABAAABABABABBABBABABAABABABABABABBABAABABAABABABAAABBABABABA\nA\nB", "ABBBABABABABABBABAABAAABABAABABABABBABAAAABABABBABAABABAAABAABBAAABAABABBABBABABBABAABABABAAAAABABAB\nB\nBABBABAABABABABABABABABABBAABABBABABBAAABAAABABBAABAABBABABBABABAABBABAABABBAABAABAABABABABABBABABAB", "AABABAABAAABABAAABAAAABBAAABABAAABABAABAABAAAABAABAAAABAAAABAAAABBAABAAAAABAAAAABABAAAAAABABAABAAAAA\nABAABABABAAABABAABABBAABAABAABABAABABAAABBAABAAAABABABAAAAABAAAAABABABABAABAABAABAABABAABABAABAABAAB\nBABAAABABBAABABAABAA", "AABABABABAAAABBAAAABABABABAAAAABABAAAA\nAABABAAABABABAAABAAAAABAAABAAABABABBBABBAAABAABAAAAABABBABAAABAABAABABAAAABABAAABAAABAABABBBABBABABA\nAAAAA", "ZZXXAAZZAXAAZZAZZXXAAZZAXAXZZXXAAZZZZXXAZZXXAAAZZXXAAAZZXXZZXXXAAAZZXZZXXAZZXXZXXAAXAAZZZXXAXAXAZZXZ\nAZZXXAAZZXXAAXZXXAZZXAZZXZZXXAAZZXXAAZAAZZAAZZXXAA\nAAZZXAAXXAAAZZXXAZZXXAAZZXXAAAZZXXZ", "SDASSDADASDASDASDSDADASASDAAASDASDDASDDASDADASDASDSSDASDD\nSDASDASDDASDASDASDSDSDASDASDASDASDASDASDASDADASDASDASDSDASDASDDDASSD\nSDASDSDDAA", "DASSDASDASDDAASDASDADASDASASDAS\nSDADASDASSDAASDASDASDADASSDDA\nSD", "ASDASSDASDS\nDASDASDDDASDADASDASDASDASSDADASDDAASDA\nDSD", "ASDASASDASDASDAASDASDASDASASDDAASDASSASDSDAD\nDASDASSSDASDASDASASDASSDAASDASSDDSASDASDAASDDAASDASDAASDASDDASDASDASDASDASS\nDASD", "DASDSDASDADASDDDSDASSDDAASDA\nDASDDASDSDADSDASDADSDSDADDASDASDDASDASDASDSDASD\nDAASD", "ABAAAABABADABAABAABCCABADABACABACABCABADABADABACABBACAADABACABABACABADABACABABA\nBACAACABABABACABCABADABAACABADABACABAA\nABBAB", "ABAABACABADAACADABACAAB\nBAACABADABACABAAAADADAABACABACABADABABADABACABAADABBADABACAAACAABACABADABBBAA\nDABACA", "BACABACABAACABADABABACAABACABBACAACAACABCABADAACABAABAABBADABACABADABCABAD\nBACAABADABABADABACABABACABADABACABCBADABACADABCABABADAABA\nBADABAA", "ACABADABACABCABAAB\nBADAB\nACAACABA", "ABABAC\nABABAC\nABAC", "BCBCBC\nBCBCBC\nBC", "AAACAAACAAADAAAAAAA\nAADAAAAAAAACDAAAAAAAAAAACAAAAABCACAAACAAAAABAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAADA\nAAACAADAAAAADD", "ABABBB\nABABBB\nABB", "ABABABAC\nABABABAC\nABABAC", "BBAABAAAAABBBBBBBABABAABAABAABBABABABBBABBABBABBBABAABBBBBBAABAAAAAAAAABABAAABBABBAAAAAABAABABBAAABB\nBBAABAAAAABBBBBBBABABAABAABAABBABABABBBABBABBABBBABAABBBBBBAABAAAAAAAAABABAAABBABBAAAAAABAABABBAAABB\nBBBAA", "ABABC\nABABC\nABC", "BABBB\nBABBB\nABB", "ABCCCCCCCC\nABCCCCCCCC\nABC"], "outputs": ["ORZ", "0", "WQ", "QNHFPHEXNETMHMHLLSGKCYPOPUH", "WVBGCSSQHHIFRRWLDDHXBGFUGU", "BKPYTRZZVICQDJTZUSJZHAQGSVVGQE", "ILBWKHDGOMQELRHEGUVUSOWVRVLCKBF", "BBITKNCLTADXYCFTNQMRYVXBBGXFWS", "TOVMIOCKPRRCGWPUOIEEGJRQTQCSZ", "GODIYVHPPFLZPUSWVLSLCOYDWALU", "KOOXWVJIPXTBWIHMTQXTFLCGNCBAAAYW", "STYEXJKPZDXCJDTLOMVRQRFIUAVUIQ", "SVVTUOKGAXUFFUCDPWBRZRVZMHHCNHTQ", "EJTOKMKSJRUHZPQLYGNRSVAYVDDGDWUKFU", "EKTFRZNXMGFFXIJXKCATCVTXTDDK", "FBZRACUZOCHAMSYYYNZCYBNTDLGG", "WZACLMQLBRWGCFIJDMHDFLPIMNXL", "MVARXFEZOPAIHRLVWFCLQRZTKXEQ", "BBYUVCJPCASDNTPQNBDRLVROOCQSGNE", "WZKTRBEFVELEBEJCOTCFONWKWGZJB", "ABABAB", "BBB", "A", "A", "B", "ABAABABABAAABAAAABBAABAAAABABAABABAAABAABAAAABAAAAAAABAAAAAAABAAAAABAAAAAAABABAABAAAA", "AABABABABAAAABBAAAABABABABAAAABABAAAA", "ZZXXAAZZXXAAXZXXAZZXAZZXZZXXAAZZXXAAZAZZAAZZXXAA", "SDASSDADASDASDSDSDADASASDAAASDASDDASDDASDDASDASDDASD", "DADADADAADADADADASSA", "ASDASSDASDS", "ASDASASDASASDAASDASASDASASDDAASDASSASDSDAD", "DASDSDASDADASDDDSDASSDDASDA", "BAAACABABABACABCABADABAACABADABACABAA", "ABAABACABADAACADABAAAB", "BACAABAAABADABACAABACABAAACABCBADAACADABCABADAABA", "BADAB", "ABABA", "CCB", "AAACAAACAAAAAAAAAA", "ABAB", "ABABABA", "BBAABAAAAABBBBBBBABABAABAABAABBABABABBBABBABBABBBABAABBBBBBABAAAAAAAAABABAAABBABBAAAAAABAABABBAAABB", "ABAB", "BBBB", "BCCCCCCCC"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
9
codeforces
92860c2d54613a5f2fb815cb46e37e60
Shooshuns and Sequence
One day shooshuns found a sequence of *n* integers, written on a blackboard. The shooshuns can perform one operation with it, the operation consists of two steps: 1. Find the number that goes *k*-th in the current sequence and add the same number to the end of the sequence; 1. Delete the first number of the current sequence. The shooshuns wonder after how many operations all numbers on the board will be the same and whether all numbers will ever be the same. The first line contains two space-separated integers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=105). The second line contains *n* space-separated integers: *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=105) — the sequence that the shooshuns found. Print the minimum number of operations, required for all numbers on the blackboard to become the same. If it is impossible to achieve, print -1. Sample Input 3 2 3 1 1 3 1 3 1 1 Sample Output 1 -1
{"inputs": ["3 2\n3 1 1", "3 1\n3 1 1", "1 1\n1", "2 1\n1 1", "2 1\n2 1", "4 4\n1 2 3 4", "4 3\n1 2 3 4", "5 3\n2 1 1 1 1", "5 3\n1 1 1 1 1", "5 5\n1 1 1 1 1", "10 1\n1 1 1 1 1 1 1 1 1 1", "10 1\n1 2 1 1 1 1 1 1 1 1", "10 1\n2 1 1 1 1 1 1 1 1 1", "10 2\n2 1 1 1 1 1 1 1 1 1", "10 2\n1 2 1 1 1 1 1 1 1 1", "10 3\n3 2 1 1 1 1 1 1 1 1", "10 1\n1 2 3 4 5 6 7 8 9 10", "10 10\n1 2 3 4 5 6 7 8 9 10", "20 10\n1 2 3 4 5 6 7 8 9 10 1 1 1 1 1 1 1 1 1 1", "20 11\n1 2 3 4 5 6 7 8 9 10 1 1 1 1 1 1 1 1 1 1", "20 9\n1 2 3 4 5 6 7 8 9 10 1 1 1 1 1 1 1 1 1 1", "20 10\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "20 20\n20 1 19 2 18 3 17 4 16 5 15 6 14 7 13 8 12 9 11 10"], "outputs": ["1", "-1", "0", "0", "-1", "3", "-1", "1", "0", "0", "0", "-1", "-1", "1", "-1", "2", "-1", "9", "-1", "10", "-1", "0", "19"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
134
codeforces
929c86cf60c47745d6a36689f25fc604
Digital Root
Not long ago Billy came across such a problem, where there were given three natural numbers *A*, *B* and *C* from the range [1,<=*N*], and it was asked to check whether the equation *AB*<==<=*C* is correct. Recently Billy studied the concept of a digital root of a number. We should remind you that a digital root *d*(*x*) of the number *x* is the sum *s*(*x*) of all the digits of this number, if *s*(*x*)<=≤<=9, otherwise it is *d*(*s*(*x*)). For example, a digital root of the number 6543 is calculated as follows: *d*(6543)<==<=*d*(6<=+<=5<=+<=4<=+<=3)<==<=*d*(18)<==<=9. Billy has counted that the digital root of a product of numbers is equal to the digital root of the product of the factors' digital roots, i.e. *d*(*xy*)<==<=*d*(*d*(*x*)*d*(*y*)). And the following solution to the problem came to his mind: to calculate the digital roots and check if this condition is met. However, Billy has doubts that this condition is sufficient. That's why he asks you to find out the amount of test examples for the given problem such that the algorithm proposed by Billy makes mistakes. The first line contains the only number *N* (1<=≤<=*N*<=≤<=106). Output one number — the amount of required *A*, *B* and *C* from the range [1,<=*N*]. Sample Input 4 5 Sample Output 2 6
{"inputs": ["4", "5", "6", "7", "1", "8", "10", "15", "16", "20", "50", "100", "127", "202", "333", "404", "411", "571", "600", "771", "10000", "20000", "30000", "50000", "99999", "200000", "400000", "600000", "800000", "1000000", "828282", "729761", "653451", "987572", "167590", "358712", "498138", "983242", "312433", "783472"], "outputs": ["2", "6", "14", "25", "0", "40", "82", "328", "395", "801", "13439", "110267", "226374", "911772", "4100905", "7300516", "7699373", "20657840", "23969924", "50875182", "111107314481", "888859064010", "2999966359410", "13888610595721", "111107776644397", "888885923513074", "7111099254185938", "23999973325791164", "56888794064261806", "111111074060178115", "63138169426585853", "43181611460546198", "31002458021265725", "107019643962508968", "522999083675296", "5128538168895562", "13734280958577573", "105618162572849728", "3388650642180089", "53435215015075583"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
18
codeforces
92c08c69d538b4c2e5079bb390c72c27
Little Elephant and Magic Square
Little Elephant loves magic squares very much. A magic square is a 3<=×<=3 table, each cell contains some positive integer. At that the sums of integers in all rows, columns and diagonals of the table are equal. The figure below shows the magic square, the sum of integers in all its rows, columns and diagonals equals 15. The Little Elephant remembered one magic square. He started writing this square on a piece of paper, but as he wrote, he forgot all three elements of the main diagonal of the magic square. Fortunately, the Little Elephant clearly remembered that all elements of the magic square did not exceed 105. Help the Little Elephant, restore the original magic square, given the Elephant's notes. The first three lines of the input contain the Little Elephant's notes. The first line contains elements of the first row of the magic square. The second line contains the elements of the second row, the third line is for the third row. The main diagonal elements that have been forgotten by the Elephant are represented by zeroes. It is guaranteed that the notes contain exactly three zeroes and they are all located on the main diagonal. It is guaranteed that all positive numbers in the table do not exceed 105. Print three lines, in each line print three integers — the Little Elephant's magic square. If there are multiple magic squares, you are allowed to print any of them. Note that all numbers you print must be positive and not exceed 105. It is guaranteed that there exists at least one magic square that meets the conditions. Sample Input 0 1 1 1 0 1 1 1 0 0 3 6 5 0 5 4 7 0 Sample Output 1 1 1 1 1 1 1 1 1 6 3 6 5 5 5 4 7 4
{"inputs": ["0 1 1\n1 0 1\n1 1 0", "0 3 6\n5 0 5\n4 7 0", "0 4 4\n4 0 4\n4 4 0", "0 54 48\n36 0 78\n66 60 0", "0 17 14\n15 0 15\n16 13 0", "0 97 56\n69 0 71\n84 43 0", "0 1099 1002\n1027 0 1049\n1074 977 0", "0 98721 99776\n99575 0 99123\n98922 99977 0", "0 6361 2304\n1433 0 8103\n7232 3175 0", "0 99626 99582\n99766 0 99258\n99442 99398 0", "0 99978 99920\n99950 0 99918\n99948 99890 0", "0 840 666\n612 0 948\n894 720 0", "0 28 10\n12 0 24\n26 8 0", "0 120 83\n98 0 90\n105 68 0", "0 86900 85807\n85836 0 86842\n86871 85778 0", "0 74 78\n78 0 74\n74 78 0", "0 505 681\n605 0 657\n581 757 0", "0 662 918\n822 0 854\n758 1014 0", "0 93 95\n93 0 97\n95 97 0", "0 709 712\n719 0 695\n702 705 0", "0 7 6\n9 0 1\n4 3 0", "0 9 2\n3 0 7\n8 1 0", "0 1 43\n13 0 61\n31 73 0", "0 100000 100000\n100000 0 100000\n100000 100000 0"], "outputs": ["1 1 1\n1 1 1\n1 1 1", "6 3 6\n5 5 5\n4 7 4", "4 4 4\n4 4 4\n4 4 4", "69 54 48\n36 57 78\n66 60 45", "14 17 14\n15 15 15\n16 13 16", "57 97 56\n69 70 71\n84 43 83", "1013 1099 1002\n1027 1038 1049\n1074 977 1063", "99550 98721 99776\n99575 99349 99123\n98922 99977 99148", "5639 6361 2304\n1433 4768 8103\n7232 3175 3897", "99328 99626 99582\n99766 99512 99258\n99442 99398 99696", "99904 99978 99920\n99950 99934 99918\n99948 99890 99964", "834 840 666\n612 780 948\n894 720 726", "16 28 10\n12 18 24\n26 8 20", "79 120 83\n98 94 90\n105 68 109", "86310 86900 85807\n85836 86339 86842\n86871 85778 86368", "76 74 78\n78 76 74\n74 78 76", "707 505 681\n605 631 657\n581 757 555", "934 662 918\n822 838 854\n758 1014 742", "97 93 95\n93 95 97\n95 97 93", "700 709 712\n719 707 695\n702 705 714", "2 7 6\n9 5 1\n4 3 8", "4 9 2\n3 5 7\n8 1 6", "67 1 43\n13 37 61\n31 73 7", "100000 100000 100000\n100000 100000 100000\n100000 100000 100000"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
246
codeforces
92ccbd5c5653fc913a6ad45681e3a8df
String Mark
At the Byteland State University marks are strings of the same length. Mark *x* is considered better than *y* if string *y* is lexicographically smaller than *x*. Recently at the BSU was an important test work on which Vasya recived the mark *a*. It is very hard for the teacher to remember the exact mark of every student, but he knows the mark *b*, such that every student recieved mark strictly smaller than *b*. Vasya isn't satisfied with his mark so he decided to improve it. He can swap characters in the string corresponding to his mark as many times as he like. Now he want to know only the number of different ways to improve his mark so that his teacher didn't notice something suspicious. More formally: you are given two strings *a*, *b* of the same length and you need to figure out the number of different strings *c* such that: 1) *c* can be obtained from *a* by swapping some characters, in other words *c* is a permutation of *a*. 2) String *a* is lexicographically smaller than *c*. 3) String *c* is lexicographically smaller than *b*. For two strings *x* and *y* of the same length it is true that *x* is lexicographically smaller than *y* if there exists such *i*, that *x*1<==<=*y*1,<=*x*2<==<=*y*2,<=...,<=*x**i*<=-<=1<==<=*y**i*<=-<=1,<=*x**i*<=&lt;<=*y**i*. Since the answer can be very large, you need to find answer modulo 109<=+<=7. First line contains string *a*, second line contains string *b*. Strings *a*,<=*b* consist of lowercase English letters. Their lengths are equal and don't exceed 106. It is guaranteed that *a* is lexicographically smaller than *b*. Print one integer  — the number of different strings satisfying the condition of the problem modulo 109<=+<=7. Sample Input abc ddd abcdef abcdeg abacaba ubuduba Sample Output 5 0 64
{"inputs": ["abc\nddd", "abcdef\nabcdeg", "abacaba\nubuduba", "aac\nbbb", "aaaccc\nbbbbbb", "aaaaaa\nzzzzzz", "abcde\nzzzzz", "a\nc", "aaa\nccc", "abacabadaba\ndabacabaaba", "ujfawuezgiy\nvuqvvsivvwe", "jvmzmvqexcqycjcpuqimvyovcffrdwtexpqhxswzytoaokvnexkzgycpmbgvsnyifkwvfbirtwnprmrlotlnhkogjlmxmgruklcuqstwfwoswux\nvzsmohqcjpzdhfyjbljviodktdsfbmaujgtsryzlcwdvccykofgxibzrxoqrvfarjduntkenwwqwuvzzxamztghkusejmucljoedfrqpcwunkru", "izybggxalv\nrbqjamqnyg", "wdtzolgzsx\nxnlokxihzw", "hoazcxoypk\njdmafdaqwm", "qdgvzritpdtoqkq\nvlulirhbfjbcmdp", "qszbyqbjgs\nqszbyqbjgt", "ftmhkyguxvbuqaiuxbmj\nftmhkyguxvbuqaiuxbmk", "dkvctjuqhtotnlwkoiaegcbsigoqvfbjtbhsniksnsauinmcoffbyberonxcpsucpacnaopnjfytkbaqpsxvjppjxzcsrlqkufjt\ndkvctjuqhtotnlwkoiaegcbsigoqvfbjtbhsniksnsauinmcoffbyberonxcpsucpacnaopnjfytkbaqpsxvjppjxzcsrlqkufju", "acehlmnssx\nzzzzzzzzzz", "acceeffghhijjjklmmoqqqssstuuwwxyy\nzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz", "aaaabbbcccdeeffffgghhhiiiiijjjjjjjkklllmmnnnnnnooopppqqqqssttuuvvvvwwwxyyzzzzzz\nzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz", "aaaabbbccddddeeeeffffffggggggghhhiijjjjjjjkkkllmmmmmmmmmnnnopppppppqqqqrrrrsssttttuuuuuvvvvvvwwwwwxxxxxyyyyyyyzzz\nzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz"], "outputs": ["5", "0", "64", "1", "9", "0", "119", "0", "0", "5586", "1730501", "845854724", "183497", "229771", "116556", "862600433", "0", "0", "0", "1814399", "615090736", "56953494", "362472550"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
2
codeforces
92e4245cc1e7a150805ac581d4a69a8b
Producing Snow
Alice likes snow a lot! Unfortunately, this year's winter is already over, and she can't expect to have any more of it. Bob has thus bought her a gift — a large snow maker. He plans to make some amount of snow every day. On day *i* he will make a pile of snow of volume *V**i* and put it in her garden. Each day, every pile will shrink a little due to melting. More precisely, when the temperature on a given day is *T**i*, each pile will reduce its volume by *T**i*. If this would reduce the volume of a pile to or below zero, it disappears forever. All snow piles are independent of each other. Note that the pile made on day *i* already loses part of its volume on the same day. In an extreme case, this may mean that there are no piles left at the end of a particular day. You are given the initial pile sizes and the temperature on each day. Determine the total volume of snow melted on each day. The first line contains a single integer *N* (1<=≤<=*N*<=≤<=105) — the number of days. The second line contains *N* integers *V*1,<=*V*2,<=...,<=*V**N* (0<=≤<=*V**i*<=≤<=109), where *V**i* is the initial size of a snow pile made on the day *i*. The third line contains *N* integers *T*1,<=*T*2,<=...,<=*T**N* (0<=≤<=*T**i*<=≤<=109), where *T**i* is the temperature on the day *i*. Output a single line with *N* integers, where the *i*-th integer represents the total volume of snow melted on day *i*. Sample Input 3 10 10 5 5 7 2 5 30 25 20 15 10 9 10 12 4 13 Sample Output 5 12 4 9 20 35 11 25
{"inputs": ["3\n10 10 5\n5 7 2", "5\n30 25 20 15 10\n9 10 12 4 13", "4\n0 0 0 0\n1 2 3 4", "10\n11 39 16 34 25 3 12 11 31 16\n10 0 4 9 8 9 7 8 9 2", "10\n20 35 4 0 6 29 4 9 17 10\n0 9 4 7 5 1 4 3 9 4", "1\n4\n5", "1\n5\n4", "1\n5\n5", "2\n9 3\n8 2", "2\n9 3\n4 4", "2\n9 3\n10 2", "13\n1 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"], "outputs": ["5 12 4", "9 20 35 11 25", "0 0 0 0", "10 0 9 27 27 30 28 17 12 4", "0 18 12 14 10 3 12 9 26 12", "4", "4", "5", "8 3", "4 7", "9 2", "1 1 1 1 1 1 1 1 1 1 1 1 1"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
35
codeforces
92e6dae987b75873174241e50e0bd7e4
Beautiful Matrix
You've got a 5<=×<=5 matrix, consisting of 24 zeroes and a single number one. Let's index the matrix rows by numbers from 1 to 5 from top to bottom, let's index the matrix columns by numbers from 1 to 5 from left to right. In one move, you are allowed to apply one of the two following transformations to the matrix: 1. Swap two neighboring matrix rows, that is, rows with indexes *i* and *i*<=+<=1 for some integer *i* (1<=≤<=*i*<=&lt;<=5). 1. Swap two neighboring matrix columns, that is, columns with indexes *j* and *j*<=+<=1 for some integer *j* (1<=≤<=*j*<=&lt;<=5). You think that a matrix looks beautiful, if the single number one of the matrix is located in its middle (in the cell that is on the intersection of the third row and the third column). Count the minimum number of moves needed to make the matrix beautiful. The input consists of five lines, each line contains five integers: the *j*-th integer in the *i*-th line of the input represents the element of the matrix that is located on the intersection of the *i*-th row and the *j*-th column. It is guaranteed that the matrix consists of 24 zeroes and a single number one. Print a single integer — the minimum number of moves needed to make the matrix beautiful. Sample Input 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 Sample Output 3 1
{"inputs": ["0 0 0 0 0\n0 0 0 0 1\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0", "0 0 0 0 0\n0 0 0 0 0\n0 1 0 0 0\n0 0 0 0 0\n0 0 0 0 0", "0 0 0 0 0\n0 0 0 0 0\n0 0 1 0 0\n0 0 0 0 0\n0 0 0 0 0", "0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 1", "0 1 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0", "1 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0", "0 0 1 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0", "0 0 0 1 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0", "0 0 0 0 1\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0", "0 0 0 0 0\n1 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0", "0 0 0 0 0\n0 1 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0", "0 0 0 0 0\n0 0 1 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0", "0 0 0 0 0\n0 0 0 1 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0", "0 0 0 0 0\n0 0 0 0 0\n1 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0", "0 0 0 0 0\n0 0 0 0 0\n0 0 0 1 0\n0 0 0 0 0\n0 0 0 0 0", "0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 1\n0 0 0 0 0\n0 0 0 0 0", "0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n1 0 0 0 0\n0 0 0 0 0", "0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 1 0 0 0\n0 0 0 0 0", "0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 1 0 0\n0 0 0 0 0", "0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 1 0\n0 0 0 0 0", "0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 1\n0 0 0 0 0", "0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n1 0 0 0 0", "0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 1 0 0 0", "0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 1 0 0", "0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 1 0"], "outputs": ["3", "1", "0", "4", "3", "4", "2", "3", "4", "3", "2", "1", "2", "2", "1", "2", "3", "2", "1", "2", "3", "4", "3", "2", "3"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
832
codeforces
92f49e48728895bf9355b6b25cadd38b
Quiz League
A team quiz game called "What? Where? When?" is very popular in Berland. The game is centered on two teams competing. They are the team of six Experts versus the team of the Audience. A person from the audience asks a question and the experts are allowed a minute on brainstorming and finding the right answer to the question. All it takes to answer a typical question is general knowledge and common logic. The question sent be the audience are in envelops lain out in a circle on a round table. Each envelop is marked by the name of the asker's town. Each question is positioned in a separate sector. In the centre of the table is a spinning arrow. Thus, the table rather resembles a roulette table with no ball but with a spinning arrow instead. The host sets off the spinning arrow to choose a question for the experts: when the arrow stops spinning, the question it is pointing at is chosen. If the arrow points at the question that has already been asked, the host chooses the next unanswered question in the clockwise direction. Your task is to determine which will be the number of the next asked question if the arrow points at sector number *k*. The first line contains two positive integers *n* and *k* (1<=≤<=*n*<=≤<=1000 and 1<=≤<=*k*<=≤<=*n*) — the numbers of sectors on the table and the number of the sector where the arrow is pointing. The second line contains *n* numbers: *a**i*<==<=0 if the question from sector *i* has already been asked and *a**i*<==<=1 if the question from sector *i* hasn't been asked yet (1<=≤<=*i*<=≤<=*n*). The sectors are given in the clockwise order, the first sector follows after the *n*-th one. Print the single number — the number of the sector containing the question the experts will be asked. It is guaranteed that the answer exists, that is that not all the questions have already been asked. Sample Input 5 5 0 1 0 1 0 2 1 1 1 Sample Output 2 1
{"inputs": ["5 5\n0 1 0 1 0", "2 1\n1 1", "3 2\n1 0 0", "3 3\n0 1 0", "1 1\n1", "6 3\n0 0 1 1 0 1", "3 1\n0 1 0", "3 3\n1 0 1", "4 4\n1 0 1 0", "5 3\n0 1 0 1 1", "6 4\n1 0 0 0 0 1", "7 5\n1 0 0 0 0 0 1", "101 81\n1 0 1 1 1 1 0 0 1 1 1 1 1 0 0 1 0 1 0 1 1 1 1 1 1 1 0 1 1 0 1 1 1 0 1 0 0 1 0 1 0 1 1 0 1 0 0 1 0 0 0 1 0 0 1 0 0 0 1 1 0 1 1 0 0 1 0 0 1 0 0 0 0 0 0 1 1 0 1 1 0 1 0 0 0 0 1 0 0 1 1 0 0 1 0 1 0 0 0 1 0", "200 31\n1 0 0 1 1 1 0 0 0 0 0 1 1 1 0 1 1 0 0 1 0 0 0 1 1 1 0 1 1 0 0 0 1 1 1 1 0 1 1 1 1 1 0 1 0 1 0 1 0 0 1 1 1 0 0 0 1 0 0 0 1 1 0 0 0 0 1 1 0 1 1 1 1 1 0 0 1 1 1 0 0 0 0 1 0 1 1 1 0 1 1 0 0 1 1 1 1 1 0 1 0 1 1 0 1 0 1 1 0 0 1 1 0 0 0 1 1 1 1 1 1 1 0 0 1 1 0 1 1 1 0 1 0 0 1 1 1 0 0 0 0 0 0 1 0 1 0 0 1 1 1 1 1 0 1 0 0 0 0 1 1 0 1 0 1 1 1 0 1 0 1 0 0 0 1 0 0 0 0 0 0 0 0 1 0 0 0 1 1 0 1 0 0 1 1 1 0 0 1 0", "17 13\n0 0 1 1 1 0 1 1 0 0 0 1 1 1 1 1 1", "102 9\n0 0 0 0 1 1 0 1 0 1 1 1 1 0 1 0 1 0 1 0 0 0 1 1 0 1 0 1 0 1 1 1 0 1 0 1 1 1 0 0 1 0 0 1 1 0 0 0 1 0 0 1 1 0 1 0 1 1 0 1 0 0 1 0 0 0 0 1 1 1 1 0 0 1 1 1 0 0 0 1 1 0 0 1 0 1 1 0 1 0 0 0 0 0 0 0 1 1 0 0 1 1"], "outputs": ["2", "1", "1", "2", "1", "3", "2", "3", "1", "4", "6", "7", "82", "33", "13", "10"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
36
codeforces
93036ead36690dea9ad6cf7ba98801a7
Hit the Lottery
Allen has a LOT of money. He has $n$ dollars in the bank. For security reasons, he wants to withdraw it in cash (we will not disclose the reasons here). The denominations for dollar bills are $1$, $5$, $10$, $20$, $100$. What is the minimum number of bills Allen could receive after withdrawing his entire balance? The first and only line of input contains a single integer $n$ ($1 \le n \le 10^9$). Output the minimum number of bills that Allen could receive. Sample Input 125 43 1000000000 Sample Output 3 5 10000000
{"inputs": ["125", "43", "1000000000", "4", "5", "1", "74", "31", "59", "79", "7", "55", "40", "719", "847", "225", "4704", "1132", "7811", "7981", "82655", "6364", "74611", "45391", "620448", "265145", "671704", "365173", "7130872", "9628747", "8898399", "9497953", "19070947", "20185520", "91402248", "27035533", "22717528", "24403439", "163565555", "152541908", "668439837", "20", "999999999", "10", "7", "6", "99999999", "1000001", "2521"], "outputs": ["3", "5", "10000000", "4", "1", "1", "8", "3", "8", "9", "3", "4", "2", "13", "13", "4", "51", "15", "80", "84", "830", "70", "748", "459", "6210", "2654", "6721", "3658", "71314", "96292", "88993", "94985", "190714", "201856", "914028", "270360", "227180", "244041", "1635659", "1525423", "6684403", "1", "10000009", "1", "3", "2", "1000009", "10001", "27"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
853
codeforces
9309776dd3ce513a2e83a90222c7ae3d
Anthem of Berland
Berland has a long and glorious history. To increase awareness about it among younger citizens, King of Berland decided to compose an anthem. Though there are lots and lots of victories in history of Berland, there is the one that stand out the most. King wants to mention it in the anthem as many times as possible. He has already composed major part of the anthem and now just needs to fill in some letters. King asked you to help him with this work. The anthem is the string *s* of no more than 105 small Latin letters and question marks. The most glorious victory is the string *t* of no more than 105 small Latin letters. You should replace all the question marks with small Latin letters in such a way that the number of occurrences of string *t* in string *s* is maximal. Note that the occurrences of string *t* in *s* can overlap. Check the third example for clarification. The first line contains string of small Latin letters and question marks *s* (1<=≤<=|*s*|<=≤<=105). The second line contains string of small Latin letters *t* (1<=≤<=|*t*|<=≤<=105). Product of lengths of strings |*s*|·|*t*| won't exceed 107. Output the maximum number of occurrences of string *t* you can achieve by replacing all the question marks in string *s* with small Latin letters. Sample Input winlose???winl???w?? win glo?yto?e??an? or ??c????? abcab Sample Output 5 3 2
{"inputs": ["winlose???winl???w??\nwin", "glo?yto?e??an?\nor", "??c?????\nabcab", "ddddd\nd", "ww?ww\nw", "?????\nn", "xznxr\nxznxr", "wnfbhg?dkhdbh?hdmfjkcunzbh?hdbjjrbh?hddmh?zubhgh?qbjbhghdpwr?bhghdfjnjf?qbhghdqq?qebhgh?umvbhghdivvj\nbhghd", "emnd?t??m?gd?t?p?s??m?dp??t???m?????m?d?ydo????????i??u?d??dp??h??d?tdp???cj?dm?dpxf?hsf??rdmt?pu?tw\ndmtdp", "t?t?t?xnu?\ntstx", "p??p??????\numpq", "irsdljdahusytoclelxidaaiaiaicaiaiaiaiiaiaiyyexmohdwmeyycaiaiaitclluaiaiaiznxweleaiaiaiixdwehyruhizbc\naiaiai", "qjcenuvdsn?ytytyt?yrznaaqeol?tyttyty?ycfaiphfmo?qpvtmhk?xzfr?tytytytytyty?oeqotyt?tyjhdhjtyt?tyyewxh\ntytyty", "zubxnxnxnxn?xixiox?oxinoxnox?xnoxxnox?xnoxixxnox?oxii?xnoxiin?noxixnoxiox?noxixxnox?noxxnoxi?xnoxinn\nxnoxi", "????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????\nrcmcscoffidfyaeeanevbcfloxrhzxnitikwyidszzgmvicjupbfzhlbkzjbyidpdaeagaanokohwofzvfsvmcwvrqkvgbwnxomajvotbpzqgiyifngpnfvmtsoovrstzhtkeqamskzdmspvihochmajwkdoeozqpkdoxffhokosfqnaqshxbsfnkjsbbkxhrzgqhufq", "????ufu\nfufu", "??????c???\nabcabc", "a???????abcax\naxabcax", "cb???????a\ncbacba", "a???????bc\nabcabc", "a????ab\nabab", "pe????????????petooh\npetoohpetooh", "hacking????????????????????????hackingisfun\nhackingisfunhackingisfun", "youdontgiveup????????????????????????????????????youyoudontgiveupdoyo?youyoudontgiveupdoyou\nyoudontgiveupdoyouyoudontgiveupdoyou", "????b?b\nabab", "a\nb", "???a??????a??b?a??a????aabc??a???a?????ab???????b????????????????ab?a?????a????a??a??????b??cb?????????????b?????c????a??????????b????c????????ca?b???????c??bc????????a?b??b??a??cc?b???????a??a?ab?a?ca?a???????c????????b????b?c\nabaab", "????????baaab\naaabaaab", "baaab????????\nbaaabaaa", "??????????????????????????\nabacaba"], "outputs": ["5", "3", "2", "5", "5", "5", "1", "10", "11", "1", "2", "6", "9", "13", "1", "2", "2", "2", "2", "2", "2", "2", "2", "2", "2", "0", "55", "2", "2", "5"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
2
codeforces
931258d7701c6fe0dd407a74d1675d06
Twins
Imagine that you have a twin brother or sister. Having another person that looks exactly like you seems very unusual. It's hard to say if having something of an alter ego is good or bad. And if you do have a twin, then you very well know what it's like. Now let's imagine a typical morning in your family. You haven't woken up yet, and Mom is already going to work. She has been so hasty that she has nearly forgotten to leave the two of her darling children some money to buy lunches in the school cafeteria. She fished in the purse and found some number of coins, or to be exact, *n* coins of arbitrary values *a*1,<=*a*2,<=...,<=*a**n*. But as Mom was running out of time, she didn't split the coins for you two. So she scribbled a note asking you to split the money equally. As you woke up, you found Mom's coins and read her note. "But why split the money equally?" — you thought. After all, your twin is sleeping and he won't know anything. So you decided to act like that: pick for yourself some subset of coins so that the sum of values of your coins is strictly larger than the sum of values of the remaining coins that your twin will have. However, you correctly thought that if you take too many coins, the twin will suspect the deception. So, you've decided to stick to the following strategy to avoid suspicions: you take the minimum number of coins, whose sum of values is strictly more than the sum of values of the remaining coins. On this basis, determine what minimum number of coins you need to take to divide them in the described manner. The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of coins. The second line contains a sequence of *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=100) — the coins' values. All numbers are separated with spaces. In the single line print the single number — the minimum needed number of coins. Sample Input 2 3 3 3 2 1 2 Sample Output 2 2
{"inputs": ["2\n3 3", "3\n2 1 2", "1\n5", "5\n4 2 2 2 2", "7\n1 10 1 2 1 1 1", "5\n3 2 3 3 1", "2\n2 1", "3\n2 1 3", "6\n1 1 1 1 1 1", "7\n10 10 5 5 5 5 1", "20\n2 1 2 2 2 1 1 2 1 2 2 1 1 1 1 2 1 1 1 1", "20\n4 2 4 4 3 4 2 2 4 2 3 1 1 2 2 3 3 3 1 4", "20\n35 26 41 40 45 46 22 26 39 23 11 15 47 42 18 15 27 10 45 40", "20\n7 84 100 10 31 35 41 2 63 44 57 4 63 11 23 49 98 71 16 90", "50\n19 2 12 26 17 27 10 26 17 17 5 24 11 15 3 9 16 18 19 1 25 23 18 6 2 7 25 7 21 25 13 29 16 9 25 3 14 30 18 4 10 28 6 10 8 2 2 4 8 28", "70\n2 18 18 47 25 5 14 9 19 46 36 49 33 32 38 23 32 39 8 29 31 17 24 21 10 15 33 37 46 21 22 11 20 35 39 13 11 30 28 40 39 47 1 17 24 24 21 46 12 2 20 43 8 16 44 11 45 10 13 44 31 45 45 46 11 10 33 35 23 42", "100\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 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", "100\n1 2 2 1 2 1 1 2 1 1 1 2 2 1 1 1 2 2 2 1 2 1 1 1 1 1 2 1 2 1 2 1 2 1 2 1 1 1 2 1 1 1 1 1 2 2 1 2 1 2 1 2 2 2 1 2 1 2 2 1 1 2 2 1 1 2 2 2 1 1 2 1 1 2 2 1 2 1 1 2 2 1 2 1 1 2 2 1 1 1 1 2 1 1 1 1 2 2 2 2", "100\n1 2 3 2 1 2 2 3 1 3 3 2 2 1 1 2 2 1 1 1 1 2 3 3 2 1 1 2 2 2 3 3 3 2 1 3 1 3 3 2 3 1 2 2 2 3 2 1 1 3 3 3 3 2 1 1 2 3 2 2 3 2 3 2 2 3 2 2 2 2 3 3 3 1 3 3 1 1 2 3 2 2 2 2 3 3 3 2 1 2 3 1 1 2 3 3 1 3 3 2", "100\n5 5 4 3 5 1 2 5 1 1 3 5 4 4 1 1 1 1 5 4 4 5 1 5 5 1 2 1 3 1 5 1 3 3 3 2 2 2 1 1 5 1 3 4 1 1 3 2 5 2 2 5 5 4 4 1 3 4 3 3 4 5 3 3 3 1 2 1 4 2 4 4 1 5 1 3 5 5 5 5 3 4 4 3 1 2 5 2 3 5 4 2 4 5 3 2 4 2 4 3", "100\n3 4 8 10 8 6 4 3 7 7 6 2 3 1 3 10 1 7 9 3 5 5 2 6 2 9 1 7 4 2 4 1 6 1 7 10 2 5 3 7 6 4 6 2 8 8 8 6 6 10 3 7 4 3 4 1 7 9 3 6 3 6 1 4 9 3 8 1 10 1 4 10 7 7 9 5 3 8 10 2 1 10 8 7 10 8 5 3 1 2 1 10 6 1 5 3 3 5 7 2", "100\n16 9 11 8 11 4 9 17 4 8 4 10 9 10 6 3 3 15 1 6 1 15 12 18 6 14 13 18 1 7 18 4 10 7 10 12 3 16 14 4 10 8 10 7 19 13 15 1 4 8 16 10 6 4 3 16 11 10 7 3 4 16 1 20 1 11 4 16 10 7 7 12 18 19 3 17 19 3 4 19 2 12 11 3 18 20 2 2 14 4 20 13 13 11 16 20 19 14 7 2", "100\n2 46 4 6 38 19 15 34 10 35 37 30 3 25 5 45 40 45 33 31 6 20 10 44 11 9 2 14 35 5 9 23 20 2 48 22 25 35 38 31 24 33 35 16 4 30 27 10 12 22 6 24 12 30 23 21 14 12 32 21 7 12 25 43 18 34 34 28 47 13 28 43 18 39 44 42 35 26 35 14 8 29 32 20 29 3 20 6 20 9 9 27 8 42 10 37 42 27 8 1", "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 38 63 74 15 62 78 9 19 67 2 60 58 93 60 18 96 55 48 34 7 79 82 32 58 90 67 20 50 27 15 7 89 98 10 11 15 99 49 4 51 77 52", "100\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100", "1\n1", "4\n4 1 2 3", "5\n2 2 2 4 4", "4\n100 99 99 100"], "outputs": ["2", "2", "1", "3", "1", "3", "1", "2", "4", "3", "8", "8", "8", "6", "14", "22", "51", "37", "36", "33", "30", "29", "30", "29", "30", "1", "2", "2", "2"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
600
codeforces
93133b96b5b3070a160ab0df19ac93d9
Minesweeper 1D
Game "Minesweeper 1D" is played on a line of squares, the line's height is 1 square, the line's width is *n* squares. Some of the squares contain bombs. If a square doesn't contain a bomb, then it contains a number from 0 to 2 — the total number of bombs in adjacent squares. For example, the correct field to play looks like that: 001*2***101*. The cells that are marked with "*" contain bombs. Note that on the correct field the numbers represent the number of bombs in adjacent cells. For example, field 2* is not correct, because cell with value 2 must have two adjacent cells with bombs. Valera wants to make a correct field to play "Minesweeper 1D". He has already painted a squared field with width of *n* cells, put several bombs on the field and wrote numbers into some cells. Now he wonders how many ways to fill the remaining cells with bombs and numbers are there if we should get a correct field in the end. The first line contains sequence of characters without spaces *s*1*s*2... *s**n* (1<=≤<=*n*<=≤<=106), containing only characters "*", "?" and digits "0", "1" or "2". If character *s**i* equals "*", then the *i*-th cell of the field contains a bomb. If character *s**i* equals "?", then Valera hasn't yet decided what to put in the *i*-th cell. Character *s**i*, that is equal to a digit, represents the digit written in the *i*-th square. Print a single integer — the number of ways Valera can fill the empty cells and get a correct field. As the answer can be rather large, print it modulo 1000000007 (109<=+<=7). Sample Input ?01??? ? **12 1 Sample Output 4 2 0 0
{"inputs": ["?01???", "?", "**12", "1", "?01*??****", "0", "2", "*", "0*", "0?", "01", "1*", "1?", "?1?", "12", "2*", "2?", "2??", "?2?", "?2*?2*??1*2**?2*1???*2???100?????*???*?*????0????2?*?*?1??1??*?01**2**1001??**??**??1*?*???00??**??*", "00***???01", "21?20*0000?2?22??0001*?1??12?20020200?**0*12?*221*0*1200*?0*11?022*110*2*2022120*2*2100*0?0*02?012?1"], "outputs": ["4", "2", "0", "0", "4", "1", "0", "1", "0", "1", "0", "1", "1", "2", "0", "0", "0", "0", "1", "147483634", "0", "0"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
8
codeforces
932312c3309f5b145d6fe3168330ff4b
Buses Between Cities
Buses run between the cities *A* and *B*, the first one is at 05:00 AM and the last one departs not later than at 11:59 PM. A bus from the city *A* departs every *a* minutes and arrives to the city *B* in a *t**a* minutes, and a bus from the city *B* departs every *b* minutes and arrives to the city *A* in a *t**b* minutes. The driver Simion wants to make his job diverse, so he counts the buses going towards him. Simion doesn't count the buses he meet at the start and finish. You know the time when Simion departed from the city *A* to the city *B*. Calculate the number of buses Simion will meet to be sure in his counting. The first line contains two integers *a*,<=*t**a* (1<=≤<=*a*,<=*t**a*<=≤<=120) — the frequency of the buses from the city *A* to the city *B* and the travel time. Both values are given in minutes. The second line contains two integers *b*,<=*t**b* (1<=≤<=*b*,<=*t**b*<=≤<=120) — the frequency of the buses from the city *B* to the city *A* and the travel time. Both values are given in minutes. The last line contains the departure time of Simion from the city *A* in the format hh:mm. It is guaranteed that there are a bus from the city *A* at that time. Note that the hours and the minutes are given with exactly two digits. Print the only integer *z* — the number of buses Simion will meet on the way. Note that you should not count the encounters in cities *A* and *B*. Sample Input 10 30 10 35 05:20 60 120 24 100 13:00 Sample Output 5 9
{"inputs": ["10 30\n10 35\n05:20", "60 120\n24 100\n13:00", "30 60\n60 60\n22:30", "30 60\n10 60\n23:30", "5 45\n4 60\n21:00", "1 1\n1 1\n10:28", "4 1\n5 4\n18:40", "8 8\n1 1\n13:24", "20 4\n1 20\n06:20", "15 24\n23 6\n21:15", "30 19\n21 4\n10:30", "31 15\n36 25\n07:04", "24 3\n54 9\n18:12", "18 69\n62 54\n08:00", "33 58\n70 78\n22:36", "68 34\n84 78\n10:40", "15 14\n32 65\n05:45", "40 74\n100 42\n05:40", "65 49\n24 90\n07:10", "1 1\n1 1\n23:59", "23 118\n118 20\n23:24", "3 88\n17 38\n22:33", "3 1\n2 3\n05:03", "1 1\n3 2\n08:44", "1 3\n1 2\n21:43", "2 28\n2 12\n05:12", "60 120\n17 120\n23:00", "1 55\n1 54\n23:59", "66 75\n1 82\n06:06", "1 90\n1 88\n23:59", "1 120\n1 100\n23:59"], "outputs": ["5", "9", "2", "8", "26", "1", "1", "8", "23", "1", "1", "1", "0", "2", "2", "1", "2", "2", "6", "1", "0", "8", "1", "0", "4", "19", "11", "54", "141", "88", "100"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
35
codeforces
933534e531757a47f23e4d8f9ec7fa10
Hexagons
Ayrat is looking for the perfect code. He decided to start his search from an infinite field tiled by hexagons. For convenience the coordinate system is introduced, take a look at the picture to see how the coordinates of hexagon are defined: Ayrat is searching through the field. He started at point (0,<=0) and is moving along the spiral (see second picture). Sometimes he forgets where he is now. Help Ayrat determine his location after *n* moves. The only line of the input contains integer *n* (0<=≤<=*n*<=≤<=1018) — the number of Ayrat's moves. Print two integers *x* and *y* — current coordinates of Ayrat coordinates. Sample Input 3 7 Sample Output -2 0 3 2
{"inputs": ["3", "7", "39", "14", "94", "60", "60", "59", "181994", "486639", "34514", "826594", "1000000000000000000", "854460", "164960", "618459", "496181994", "1000000000", "228939226", "973034514", "984826594", "19164960", "249781780", "851838979", "978618459", "871854460", "302486639", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "257947185131120683", "258773432604171403", "259599671487287531", "260425914665370955", "261252157843454379", "262078401021537803", "262904639904653932", "263730878787770060", "264557126260820780", "775736713043603670", "776562956221687094", "777389199399770518", "778215438282886646", "779041681460970070", "779867924639053494", "780694167817136918", "781520406700253046", "782346645583369174", "783172893056419894", "294352484134170081", "34761473798667069", "247761054921329978", "88904985049714519", "64695994584418558", "2999472947040002", "134013960807648841", "27719767248080188", "228296921967681448", "622704061396296670", "382830415035226081", "175683606088259879", "533568904697339792", "281824423976299408", "237223610332609448", "82638676376847406", "358538881902627465", "1941943667672759", "504819148029580024", "24271330411219667", "108364135632524999", "16796277375911920", "194403552286884865", "565840809656836956", "39010293491965817", "746407891412272132", "95626493228268863", "385078658398478614", "177207687885798058", "536222521732590352", "1571429132955632", "498549006180463098", "438594547809157461", "214071008058709620", "599060227806517999", "329939015655396840", "281523482448806534", "109561818187625921", "412565943716413781", "196006607922989510", "379604878823574823", "173500741457825598", "138919367769131398", "29974778103430162", "234685974076220810", "633227154929081648", "58101264340386100", "1718550904886625", "124444652733481603", "441000740540275741", "545168342596476149", "138919367769131403", "138919367984320752", "1", "2", "4", "5", "6"], "outputs": ["-2 0", "3 2", "5 6", "-2 -4", "8 8", "8 0", "8 0", "7 -2", "154 -492", "-33 806", "13 -214", "-769 562", "-418284973 -1154700538", "414 1068", "458 -20", "-797 -222", "21108 9228", "27596 -17836", "1516 17472", "27776 16488", "22704 -27064", "4864 384", "2815 18250", "8695 33702", "-15591 -36122", "31404 5384", "11555 -17054", "0 0", "1 2", "-1 2", "-2 0", "-1 -2", "1 -2", "2 0", "3 2", "2 4", "0 4", "-2 4", "-3 2", "-4 0", "-3 -2", "-2 -4", "0 -4", "2 -4", "3 -2", "4 0", "5 2", "4 4", "3 6", "1 6", "-1 6", "-3 6", "-4 4", "-5 2", "-6 0", "-5 -2", "-4 -4", "-3 -6", "-53995102 -586455096", "-438664202 297458800", "-252460838 -588330600", "-423141322 332249584", "-164822562 -590200144", "439863347 302538706", "-378326148 -427475264", "200309780 592993400", "489196540 209450068", "-794841963 -444342246", "-623135314 -788838484", "-328249537 -1018095738", "-719067659 -599137942", "-637165825 764022826", "559082192 -921270732", "7343027 1020257594", "-707743686 626107308", "797020774 -448632052", "604133660 -835484644", "-264428508 -626474244", "-107643660 215287324", "-287379568 574759144", "344296355 2", "146851396 293702780", "31620002 63239992", "-422711816 4", "-96124517 -192249026", "-275860421 551720850", "-911192665 10", "357225613 714451226", "-483988434 8", "-421730125 843460258", "-306498737 -612997466", "-281201952 -562403896", "-331941110 4", "-691412929 6", "-25442382 -50884744", "820421960 -4", "179893783 -2", "-380112498 8", "74824856 -149649712", "-509121532 4", "868593352 0", "-114032591 -228065170", "498801191 -997602386", "178537107 357074206", "358273010 -716546028", "486083238 -4", "-422777531 845555062", "45773778 4", "407655496 -815310984", "382358709 -764717418", "534254630 0", "-446863220 893726452", "-331631832 663263664", "306335045 612670094", "191103653 382207306", "370839563 741679126", "-255608161 511216338", "-355717526 711435056", "240486136 480972264", "-430378693 10", "99957958 199915904", "-279693865 559387730", "-459429777 -918859546", "-139165682 278331372", "23934291 -47868582", "203670197 -407340402", "-383406115 -766812218", "852579099 -2", "-430378698 0", "-215189349 -430378698", "1 2", "-1 2", "-1 -2", "1 -2", "2 0"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
2
codeforces
934ea466a846bb3ce21dc7df2779105b
The Festive Evening
It's the end of July – the time when a festive evening is held at Jelly Castle! Guests from all over the kingdom gather here to discuss new trends in the world of confectionery. Yet some of the things discussed here are not supposed to be disclosed to the general public: the information can cause discord in the kingdom of Sweetland in case it turns out to reach the wrong hands. So it's a necessity to not let any uninvited guests in. There are 26 entrances in Jelly Castle, enumerated with uppercase English letters from A to Z. Because of security measures, each guest is known to be assigned an entrance he should enter the castle through. The door of each entrance is opened right before the first guest's arrival and closed right after the arrival of the last guest that should enter the castle through this entrance. No two guests can enter the castle simultaneously. For an entrance to be protected from possible intrusion, a candy guard should be assigned to it. There are *k* such guards in the castle, so if there are more than *k* opened doors, one of them is going to be left unguarded! Notice that a guard can't leave his post until the door he is assigned to is closed. Slastyona had a suspicion that there could be uninvited guests at the evening. She knows the order in which the invited guests entered the castle, and wants you to help her check whether there was a moment when more than *k* doors were opened. Two integers are given in the first string: the number of guests *n* and the number of guards *k* (1<=≤<=*n*<=≤<=106, 1<=≤<=*k*<=≤<=26). In the second string, *n* uppercase English letters *s*1*s*2... *s**n* are given, where *s**i* is the entrance used by the *i*-th guest. Output «YES» if at least one door was unguarded during some time, and «NO» otherwise. You can output each letter in arbitrary case (upper or lower). Sample Input 5 1 AABBB 5 1 ABABB Sample Output NO YES
{"inputs": ["5 1\nAABBB", "5 1\nABABB", "26 1\nABCDEFGHIJKLMNOPQRSTUVWXYZ", "27 1\nABCDEFGHIJKLMNOPQRSTUVWXYZA", "5 2\nABACA", "6 2\nABCABC", "8 3\nABCBCDCA", "73 2\nDEBECECBBADAADEAABEAEEEAEBEAEBCDDBABBAEBACCBEEBBAEADEECACEDEEDABACDCDBBBD", "44 15\nHGJIFCGGCDGIJDHBIBGAEABCIABIGBDEADBBBAGDFDHA", "41 19\nTMEYYIIELFDCMBDKWWKYNRNDUPRONYROXQCLVQALP", "377 3\nEADADBBBBDEAABBAEBABACDBDBBCACAADBEAEACDEAABACADEEDEACACDADABBBBDDEECBDABACACBAECBADAEBDEEBDBCDAEADBCDDACACDCCEEDBCCBBCEDBECBABCDDBBDEADEDAEACDECECBEBACBCCDCDBDAECDECADBCBEDBBDAAEBCAAECCDCCDBDDEBADEEBDCAEABBDEDBBDDEAECCBDDCDEACDAECCBDDABABEAEDCDEDBAECBDEACEBCECEACDCBABCBAAEAADACADBBBBABEADBCADEBCBECCABBDDDEEBCDEBADEBDAAABBEABADEDEAEABCEEBEEDEAEBEABCEDDBACBCCADEBAAAAAEABABBCE", "433 3\nFZDDHMJGBZCHFUXBBPIEBBEFDWOMXXEPOMDGSMPIUZOMRZQNSJAVNATGIWPDFISKFQXJNVFXPHOZDAEZFDAHDXXQKZMGNSGKQNWGNGJGJZVVITKNFLVCPMZSDMCHBTVAWYVZLIXXIADXNYILEYNIQHKMOGMVOCWGHCWIYMPEPADSJAAKEGTUSEDWAHMNYJDIHBKHVUHLYGNGZDBULRXLSAJHPCMNWCEAAPYMHDTYWPADOTJTXTXUKLCHWKUSZRHEKQEFPVJEJJHRWCKYOIWALRTIBUMNOCRXLSIKQCJVQXEPGOHRUDJDKMUUUDORURWXJNVRVMNOUNRFKSVMTMZGOIJLXEPAMVGESOADYIGZXRBJDIWKNOWTCSROAQTBECHTOZVSQUOOJRZIBAUHMKAXDCIMDZJFMABGRNTGPUJAUNFPFWCJG", "5 2\nABCAB", "5 1\nAZAZA", "7 2\nABCDBCD", "3 26\nAAB"], "outputs": ["NO", "YES", "NO", "YES", "NO", "YES", "NO", "YES", "NO", "NO", "YES", "YES", "YES", "YES", "YES", "NO"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
115
codeforces
9360f296a2c7948139a477124eb2a1da
Caisa and Pylons
Caisa solved the problem with the sugar and now he is on the way back to home. Caisa is playing a mobile game during his path. There are (*n*<=+<=1) pylons numbered from 0 to *n* in this game. The pylon with number 0 has zero height, the pylon with number *i* (*i*<=&gt;<=0) has height *h**i*. The goal of the game is to reach *n*-th pylon, and the only move the player can do is to jump from the current pylon (let's denote its number as *k*) to the next one (its number will be *k*<=+<=1). When the player have made such a move, its energy increases by *h**k*<=-<=*h**k*<=+<=1 (if this value is negative the player loses energy). The player must have non-negative amount of energy at any moment of the time. Initially Caisa stand at 0 pylon and has 0 energy. The game provides a special opportunity: one can pay a single dollar and increase the height of anyone pylon by one. Caisa may use that opportunity several times, but he doesn't want to spend too much money. What is the minimal amount of money he must paid to reach the goal of the game? The first line contains integer *n* (1<=≤<=*n*<=≤<=105). The next line contains *n* integers *h*1, *h*2,<=..., *h**n* (1<=<=≤<=<=*h**i*<=<=≤<=<=105) representing the heights of the pylons. Print a single number representing the minimum number of dollars paid by Caisa. Sample Input 5 3 4 3 2 4 3 4 4 4 Sample Output 4 4
{"inputs": ["5\n3 4 3 2 4", "3\n4 4 4", "99\n1401 2019 1748 3785 3236 3177 3443 3772 2138 1049 353 908 310 2388 1322 88 2160 2783 435 2248 1471 706 2468 2319 3156 3506 2794 1999 1983 2519 2597 3735 537 344 3519 3772 3872 2961 3895 2010 10 247 3269 671 2986 942 758 1146 77 1545 3745 1547 2250 2565 217 1406 2070 3010 3404 404 1528 2352 138 2065 3047 3656 2188 2919 2616 2083 1280 2977 2681 548 4000 1667 1489 1109 3164 1565 2653 3260 3463 903 1824 3679 2308 245 2689 2063 648 568 766 785 2984 3812 440 1172 2730", "68\n477 1931 3738 3921 2306 1823 3328 2057 661 3993 2967 3520 171 1739 1525 1817 209 3475 1902 2666 518 3283 3412 3040 3383 2331 1147 1460 1452 1800 1327 2280 82 1416 2200 2388 3238 1879 796 250 1872 114 121 2042 1853 1645 211 2061 1472 2464 726 1989 1746 489 1380 1128 2819 2527 2939 622 678 265 2902 1111 2032 1453 3850 1621", "30\n30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1", "3\n3 2 1", "1\n69"], "outputs": ["4", "4", "4000", "3993", "30", "3", "69"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
361
codeforces
93611e04f3cfd79e75355cf9c18f8e2d
LRU
While creating high loaded systems one should pay a special attention to caching. This problem will be about one of the most popular caching algorithms called LRU (Least Recently Used). Suppose the cache may store no more than *k* objects. At the beginning of the workflow the cache is empty. When some object is queried we check if it is present in the cache and move it here if it's not. If there are more than *k* objects in the cache after this, the least recently used one should be removed. In other words, we remove the object that has the smallest time of the last query. Consider there are *n* videos being stored on the server, all of the same size. Cache can store no more than *k* videos and caching algorithm described above is applied. We know that any time a user enters the server he pick the video *i* with probability *p**i*. The choice of the video is independent to any events before. The goal of this problem is to count for each of the videos the probability it will be present in the cache after 10100 queries. The first line of the input contains two integers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=20) — the number of videos and the size of the cache respectively. Next line contains *n* real numbers *p**i* (0<=≤<=*p**i*<=≤<=1), each of them is given with no more than two digits after decimal point. It's guaranteed that the sum of all *p**i* is equal to 1. Print *n* real numbers, the *i*-th of them should be equal to the probability that the *i*-th video will be present in the cache after 10100 queries. You answer will be considered correct if its absolute or relative error does not exceed 10<=-<=6. Namely: let's assume that your answer is *a*, and the answer of the jury is *b*. The checker program will consider your answer correct, if . Sample Input 3 1 0.3 0.2 0.5 2 1 0.0 1.0 3 2 0.3 0.2 0.5 3 3 0.2 0.3 0.5 Sample Output 0.3 0.2 0.5 0.0 1.0 0.675 0.4857142857142857 0.8392857142857143 1.0 1.0 1.0
{"inputs": ["3 1\n0.3 0.2 0.5", "2 1\n0.0 1.0", "3 2\n0.3 0.2 0.5", "3 3\n0.2 0.3 0.5", "1 1\n1.0", "10 1\n0.12 0.14 0.13 0.08 0.15 0.10 0.15 0.04 0.02 0.07", "10 5\n0.02 0.17 0.04 0.07 0.21 0.06 0.09 0.11 0.17 0.06", "10 10\n0.02 0.03 0.12 0.21 0.07 0.15 0.21 0.14 0.01 0.04", "20 10\n0.07 0.03 0.02 0.02 0.09 0.07 0.07 0.09 0.01 0.08 0.05 0.06 0.04 0.08 0.03 0.02 0.01 0.06 0.08 0.02", "20 10\n0.02 0.07 0.06 0.05 0.07 0.06 0.04 0.01 0.04 0.03 0.03 0.02 0.07 0.06 0.07 0.04 0.06 0.07 0.07 0.06", "20 10\n0.02 0.04 0.01 0.04 0.09 0.09 0.09 0.02 0.04 0.03 0.11 0.07 0.06 0.02 0.03 0.01 0.01 0.03 0.11 0.08", "20 10\n0.03 0.06 0.07 0.01 0.02 0.05 0.04 0.02 0.04 0.03 0.01 0.08 0.07 0.07 0.08 0.08 0.06 0.08 0.09 0.01", "20 10\n0.03 0.04 0.05 0.00 0.00 0.08 0.03 0.08 0.07 0.02 0.07 0.09 0.04 0.01 0.05 0.09 0.04 0.05 0.07 0.09", "20 10\n0.03 0.05 0.02 0.08 0.04 0.05 0.08 0.08 0.08 0.02 0.08 0.01 0.05 0.05 0.02 0.07 0.09 0.00 0.07 0.03", "20 10\n0.00 0.00 0.00 0.08 0.16 0.00 0.26 0.02 0.00 0.03 0.19 0.00 0.00 0.14 0.00 0.05 0.00 0.01 0.06 0.00", "20 10\n0.10 0.11 0.06 0.11 0.03 0.00 0.00 0.01 0.00 0.00 0.08 0.00 0.01 0.10 0.14 0.16 0.00 0.00 0.00 0.09", "20 10\n0.17 0.09 0.01 0.00 0.05 0.00 0.10 0.00 0.19 0.00 0.08 0.00 0.13 0.00 0.18 0.00 0.00 0.00 0.00 0.00", "20 10\n0.10 0.01 0.00 0.00 0.00 0.00 0.00 0.58 0.03 0.00 0.14 0.00 0.11 0.00 0.00 0.00 0.03 0.00 0.00 0.00", "10 2\n0.03 0.23 0.18 0.00 0.03 0.08 0.26 0.08 0.04 0.07", "10 3\n0.02 0.21 0.03 0.17 0.11 0.21 0.10 0.06 0.04 0.05", "10 4\n0.02 0.06 0.23 0.17 0.01 0.07 0.03 0.11 0.24 0.06", "10 6\n0.02 0.16 0.13 0.02 0.05 0.17 0.17 0.09 0.14 0.05", "10 7\n0.02 0.21 0.03 0.17 0.11 0.21 0.10 0.06 0.04 0.05", "10 8\n0.02 0.08 0.09 0.09 0.08 0.19 0.14 0.07 0.19 0.05", "10 9\n0.02 0.00 0.16 0.03 0.20 0.12 0.17 0.14 0.07 0.09", "3 2\n0.08 0.79 0.13", "1 1\n1.00", "4 2\n0.05 0.50 0.40 0.05", "10 4\n0.17 0.08 0.25 0.01 0.00 0.00 0.00 0.00 0.15 0.34", "10 2\n0.26 0.00 0.17 0.05 0.00 0.04 0.33 0.15 0.00 0.00", "10 7\n0.00 0.09 0.00 0.00 0.47 0.00 0.00 0.00 0.24 0.20", "10 8\n0.27 0.00 0.09 0.08 0.00 0.00 0.13 0.43 0.00 0.00", "20 1\n0.00 0.00 1.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00", "20 2\n1.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00", "20 3\n0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 1.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00", "20 20\n0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 1.00 0.00 0.00 0.00", "5 2\n1.00 0.00 0.00 0.00 0.00", "20 19\n0.01 0.01 0.01 0.11 0.01 0.01 0.02 0.08 0.00 0.06 0.09 0.12 0.02 0.08 0.07 0.01 0.05 0.04 0.11 0.09", "20 20\n0.02 0.04 0.10 0.03 0.09 0.02 0.05 0.05 0.00 0.08 0.02 0.03 0.04 0.10 0.02 0.06 0.05 0.08 0.07 0.05", "2 1\n0.5 0.5", "2 2\n0.5 0.5", "2 2\n0 1", "2 2\n1.0 0.0", "3 3\n0 0 1", "4 4\n0 0.5 0 0.5", "2 2\n0.0 1.0", "5 4\n0.3 0.2 0.5 0 0", "2 2\n1 0", "5 4\n0.3 0.2 0.5 0.0 0.0", "3 3\n0.0 1.0 0.0", "5 3\n1.0 0.0 0.0 0.0 0.0", "2 2\n1.00 0.00", "4 3\n0.5 0 0.5 0", "5 5\n0.5 0.5 0 0 0", "3 3\n0 0.5 0.5", "5 4\n0.50 0.50 0.00 0.00 0.00", "3 2\n1 0 0", "3 3\n1 0 0", "10 5\n0.4 0.4 0.2 0.0 0.0 0.0 0.0 0.0 0.0 0.0", "6 6\n0 0.5 0 0.5 0 0", "4 4\n0.0 0.0 1.0 0.0", "10 5\n0.5 0 0 0.5 0 0 0 0 0 0", "3 2\n0.0 0.0 1.0", "4 3\n1.00 0.00 0.00 0.00", "20 19\n0.05 0.05 0.05 0.05 0.05 0.05 0.05 0.05 0.05 0.05 0.05 0.05 0.05 0.05 0.05 0.05 0.05 0.05 0.05 0.05", "3 3\n0.5 0.5 0"], "outputs": ["0.3 0.2 0.5 ", "0.0 1.0 ", "0.675 0.4857142857142857 0.8392857142857143 ", "1.0 1.0 1.0 ", "1.0 ", "0.12 0.14 0.13 0.08 0.15 0.1 0.15 0.04 0.02 0.07 ", "0.1399910871034487 0.7479501842209872 0.2655803706306279 0.4263090048227962 0.8140604521856322 0.3764316851562892 0.5151587224363868 0.5901366240665537 0.747950184220987 0.3764316851562893 ", "0.9999999999999996 0.9999999999999993 1.0000000000000004 1.0000000000000002 0.9999999999999994 1.0000000000000002 1.0000000000000002 1.0000000000000007 0.9999999999999984 0.9999999999999984 ", "0.6690974251255742 0.37305204013382764 0.26536469553087033 0.26536469553087033 0.7578934285796217 0.6690974251255744 0.6690974251255744 0.7578934285796214 0.14136644265973128 0.717224662240763 0.5449021980374016 0.6121580456838637 0.4657328436268002 0.7172246622407633 0.37305204013382287 0.2653646955308738 0.1413664426597324 0.6121580456838935 0.7172246622407644 0.2653646955308683 ", "0.25099104075340506 0.644512766322346 0.5875204969870276 0.5210106645274739 0.644512766322346 0.5875204969870277 0.44363944860925325 0.1332915344470896 0.44363944860925325 0.354059145410146 0.354059145410146 0.25099104075340534 0.6445127663223461 0.5875204969870305 0.6445127663223461 0.4436394486092542 0.5875204969870291 0.6445127663223555 0.6445127663223555 0.5875204969869904 ", "0.2795437203043747 0.4869171151926799 0.14942046819622407 0.4869171151926799 0.7782038002899797 0.7782038002899797 0.7782038002899797 0.27954372030437463 0.48691711519268027 0.39154156049777117 0.838922780730839 0.6915248110074876 0.6350078181751538 0.2795437203043719 0.3915415604977727 0.14942046819622568 0.14942046819622568 0.3915415604977847 0.8389227807307885 0.7387418159128292 ", "0.3712914845948875 0.6099748765150452 0.6669519822288402 0.1405998407706366 0.26401518486789877 0.5427519025083002 0.46371385128623027 0.26401518486789854 0.46371385128623027 0.3712914845948875 0.14059984077063664 0.7151639223296767 0.6669519822288443 0.6669519822288443 0.7151639223296734 0.7151639223296734 0.6099748765150346 0.7151639223296734 0.7559461446464355 0.14059984077062102 ", "0.3778442856123409 0.47134785689920056 0.5510150378675547 0.0 0.0 0.7234472395365301 0.37784428561234096 0.7234472395365301 0.6754563322295303 0.26896450581056675 0.6754563322295305 0.7638736323225985 0.4713478568991996 0.14337386593467152 0.5510150378675541 0.7638736323225961 0.47134785689919867 0.5510150378675526 0.67545633222953 0.763873632322598 ", "0.37243950639307966 0.544208458773671 0.2648804623070527 0.7166425092013716 0.46505497136760304 0.544208458773671 0.7166425092013716 0.7166425092013716 0.7166425092013716 0.2648804623070529 0.7166425092013721 0.14108407922769203 0.5442084587736682 0.5442084587736682 0.26488046230705525 0.66846334603609 0.757367476523396 0.0 0.66846334603609 0.3724395063931443 ", "0.0 0.0 0.0 1.000000000000001 1.0000000000000004 0.0 0.9999999999999997 0.9999999999999997 0.0 0.9999999999999998 0.9999999999999996 0.0 0.0 1.0000000000000004 0.0 0.9999999999999997 0.0 0.9999999999999998 0.9999999999999992 0.0 ", "0.9702782007919801 0.9769622705276968 0.9058158749047228 0.9769622705276967 0.7170340277090191 0.0 0.0 0.29571986132381933 0.0 0.0 0.948715515948032 0.0 0.29571986132381944 0.9702782007919795 0.9886519061716066 0.9926478600635664 0.0 0.0 0.0 0.9612141499160587 ", "1.0000000000000004 1.0000000000000004 0.9999999999999994 0.0 0.9999999999999998 0.0 0.9999999999999999 0.0 1.0000000000000002 0.0 1.0 0.0 1.0000000000000004 0.0 1.0000000000000007 0.0 0.0 0.0 0.0 0.0 ", "1.0000000000000002 0.999999999999998 0.0 0.0 0.0 0.0 0.0 1.0 0.9999999999999987 0.0 0.9999999999999996 0.0 1.0000000000000002 0.0 0.0 0.0 0.9999999999999989 0.0 0.0 0.0 ", "0.06574023622726129 0.4424205811028936 0.36049623255089486 0.0 0.06574023622726129 0.1708250016710234 0.4864385997316486 0.17082500167102338 0.08722409503841025 0.15029001577958354 ", "0.0707671665235638 0.572620351642748 0.1050266762091833 0.4946967070259397 0.3494970231490039 0.572620351642748 0.32199621653284904 0.20306812742332853 0.1385100970253048 0.1711972828253307 ", "0.10975537665502762 0.3051984542478531 0.7678129184658183 0.6636945863049896 0.05583801838076966 0.34877017466415117 0.16169970181895205 0.5008950990137218 0.7811372162008635 0.30519845424785336 ", "0.1908891127632005 0.8378650050267057 0.7760529267484847 0.19088911276320047 0.4260110846599223 0.8538288809282245 0.8538288809282245 0.6452986631606833 0.7993252483614335 0.4260110846599222 ", "0.2842926499039299 0.9644317779231261 0.40270634337736644 0.9403336125112673 0.8564352604856355 0.9644317779231263 0.8312918049552955 0.6606737030665756 0.5048019502306894 0.5906011196229873 ", "0.32594681031186507 0.8213376231015499 0.8540871594909123 0.8540871594909123 0.82133762310155 0.9735634149906833 0.9415368103143239 0.7794744071864103 0.9735634149906834 0.6550655770211107 ", "1.000000000000003 0.0 1.0000000000000007 1.000000000000002 1.0000000000000002 0.9999999999999999 1.0000000000000009 1.0000000000000002 1.0000000000000004 1.000000000000001 ", "0.3929064039408868 0.9767416291854074 0.6303519668737061 ", "1.0 ", "0.1359649122807018 0.8859649122807017 0.8421052631578948 0.1359649122807018 ", "0.807383060835042 0.5056591310919583 0.8997295433518943 0.07312969011105623 0.0 0.0 0.0 0.0 0.7681890555425176 0.9459095190675326 ", "0.5117126103415558 0.0 0.35949177476769784 0.11334225983972909 0.0 0.09111240436301137 0.6028900225620077 0.3214509281259984 0.0 0.0 ", "0.0 0.9999999999999994 0.0 0.0 1.0 0.0 0.0 0.0 1.0 0.9999999999999997 ", "1.0 0.0 1.0 0.9999999999999998 0.0 0.0 0.9999999999999999 1.0 0.0 0.0 ", "0.0 0.0 1.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 ", "1.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 ", "0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 1.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 ", "0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 1.0 0.0 0.0 0.0 ", "1.0 0.0 0.0 0.0 0.0 ", "0.9999999999999774 0.9999999999999774 0.9999999999999774 0.9999999999999416 0.9999999999999775 0.9999999999999775 1.0000000000000326 0.9999999999998995 0.0 0.9999999999999348 1.0000000000000095 1.0000000000000588 1.0000000000000338 0.9999999999998964 1.000000000000197 0.9999999999999984 0.999999999999947 1.0000000000000104 0.9999999999999113 1.0000000000000189 ", "0.9999999999999967 1.000000000000045 1.0000000000000897 1.0000000000000033 0.9999999999998742 0.9999999999999971 0.9999999999999493 0.9999999999999493 0.0 1.0000000000000073 0.9999999999999973 1.000000000000003 1.0000000000000437 1.0000000000000897 0.9999999999999967 1.0000000000000187 0.9999999999999478 0.9999999999999858 1.0000000000001537 1.0000000000000426 ", "0.5 0.5 ", "1.0 1.0 ", "0.0 1.0 ", "1.0 0.0 ", "0.0 0.0 1.0 ", "0.0 1.0 0.0 1.0 ", "0.0 1.0 ", "1.0 1.0 1.0 0.0 0.0 ", "1.0 0.0 ", "1.0 1.0 1.0 0.0 0.0 ", "0.0 1.0 0.0 ", "1.0 0.0 0.0 0.0 0.0 ", "1.0 0.0 ", "1.0 0.0 1.0 0.0 ", "1.0 1.0 0.0 0.0 0.0 ", "0.0 1.0 1.0 ", "1.0 1.0 0.0 0.0 0.0 ", "1.0 0.0 0.0 ", "1.0 0.0 0.0 ", "1.0000000000000002 1.0000000000000002 1.0000000000000002 0.0 0.0 0.0 0.0 0.0 0.0 0.0 ", "0.0 1.0 0.0 1.0 0.0 0.0 ", "0.0 0.0 1.0 0.0 ", "1.0 0.0 0.0 1.0 0.0 0.0 0.0 0.0 0.0 0.0 ", "0.0 0.0 1.0 ", "1.0 0.0 0.0 0.0 ", "0.9499999999975302 0.9499999999975302 0.9499999999975302 0.9499999999975302 0.9499999999975302 0.9499999999975302 0.9499999999975302 0.9499999999975302 0.9499999999975302 0.9499999999975302 0.9499999999975302 0.9499999999975302 0.9499999999975302 0.9499999999975302 0.9499999999975302 0.9499999999975302 0.9499999999975302 0.9499999999975302 0.9499999999975302 0.9499999999975302 ", "1.0 1.0 0.0 "]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1
codeforces
9361fef31b3894cff7eb733b7f116acf
Quadcopter Competition
Polycarp takes part in a quadcopter competition. According to the rules a flying robot should: - start the race from some point of a field, - go around the flag, - close cycle returning back to the starting point. Polycarp knows the coordinates of the starting point (*x*1,<=*y*1) and the coordinates of the point where the flag is situated (*x*2,<=*y*2). Polycarp’s quadcopter can fly only parallel to the sides of the field each tick changing exactly one coordinate by 1. It means that in one tick the quadcopter can fly from the point (*x*,<=*y*) to any of four points: (*x*<=-<=1,<=*y*), (*x*<=+<=1,<=*y*), (*x*,<=*y*<=-<=1) or (*x*,<=*y*<=+<=1). Thus the quadcopter path is a closed cycle starting and finishing in (*x*1,<=*y*1) and containing the point (*x*2,<=*y*2) strictly inside. What is the minimal length of the quadcopter path? The first line contains two integer numbers *x*1 and *y*1 (<=-<=100<=≤<=*x*1,<=*y*1<=≤<=100) — coordinates of the quadcopter starting (and finishing) point. The second line contains two integer numbers *x*2 and *y*2 (<=-<=100<=≤<=*x*2,<=*y*2<=≤<=100) — coordinates of the flag. It is guaranteed that the quadcopter starting point and the flag do not coincide. Print the length of minimal path of the quadcopter to surround the flag and return back. Sample Input 1 5 5 2 0 1 0 0 Sample Output 18 8
{"inputs": ["1 5\n5 2", "0 1\n0 0", "-100 -100\n100 100", "-100 -100\n-100 100", "-100 -100\n100 -100", "100 -100\n-100 -100", "100 -100\n-100 100", "100 -100\n100 100", "-100 100\n-100 -100", "-100 100\n100 -100", "-100 100\n100 100", "100 100\n-100 -100", "100 100\n-100 100", "100 100\n100 -100", "45 -43\n45 -44", "76 76\n75 75", "-34 -56\n-35 -56", "56 -7\n55 -6", "43 -11\n43 -10", "1 -3\n2 -2", "55 71\n56 71", "54 -87\n55 -88", "22 98\n100 33", "37 84\n-83 5", "52 74\n-73 -39", "66 51\n51 -71", "-31 44\n73 86", "-20 34\n-9 55", "-5 19\n-91 -86", "-82 5\n28 -17", "-90 -100\n55 48", "-75 -14\n-32 8", "-53 -28\n-13 -28", "-42 -46\n10 -64", "55 -42\n25 2", "70 -64\n-54 70", "93 -78\n-32 -75", "8 -93\n79 -6", "50 43\n54 10", "65 32\n-37 71", "80 18\n-15 -58", "94 92\n4 -1", "-10 96\n27 64", "-96 78\n-56 32", "-81 64\n-37 -8", "-58 49\n74 -40", "-62 -55\n1 18", "-51 -69\n-78 86", "-29 -80\n-56 -47", "-14 -94\n55 -90", "83 -2\n82 83", "98 -16\n-96 40", "17 -34\n-86 -93", "32 -48\n33 -37", "74 87\n3 92", "89 73\n-80 49", "4 58\n-61 -80", "15 48\n50 -20", "-82 45\n81 46", "-68 26\n-2 6", "-53 4\n-92 -31", "-30 94\n31 -58", "-38 -11\n58 99", "-27 -25\n-28 68", "-5 -39\n-10 -77", "-90 -54\n9 -9", "7 -57\n28 61", "18 -67\n-51 21", "41 -82\n-33 -15", "56 -8\n91 -55", "-23 -13\n-24 -12", "1 32\n1 33", "25 76\n24 76", "-29 -78\n-28 -79", "-77 19\n-76 19", "-53 63\n-53 62", "86 12\n86 11", "14 56\n13 56", "63 41\n62 40", "0 -4\n1 -4", "24 41\n24 42", "48 85\n49 86", "0 0\n0 1", "0 0\n1 0", "0 0\n1 1", "0 1\n0 0", "0 1\n1 0", "0 1\n1 1", "1 0\n0 0", "1 0\n0 1", "1 0\n1 1", "1 1\n0 0", "1 1\n0 1", "1 1\n1 0", "100 100\n99 -100", "100 100\n-100 99", "-100 -100\n-99 100", "-100 -100\n100 -99", "0 0\n1 2", "0 0\n2 1"], "outputs": ["18", "8", "804", "406", "406", "406", "804", "406", "406", "804", "406", "804", "406", "406", "8", "8", "8", "8", "8", "8", "8", "8", "290", "402", "480", "278", "296", "68", "386", "268", "590", "134", "86", "144", "152", "520", "260", "320", "78", "286", "346", "370", "142", "176", "236", "446", "276", "368", "124", "150", "176", "504", "328", "28", "156", "390", "410", "210", "332", "176", "152", "430", "416", "192", "90", "292", "282", "318", "286", "168", "8", "8", "8", "8", "8", "8", "8", "8", "8", "8", "8", "8", "8", "8", "8", "8", "8", "8", "8", "8", "8", "8", "8", "8", "406", "406", "406", "406", "10", "10"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
124
codeforces
93962dd461fd0469c9158c0a4409dddc
Vasya and Digital Root
Vasya has recently found out what a digital root of a number is and he decided to share his knowledge with you. Let's assume that *S*(*n*) is the sum of digits of number *n*, for example, *S*(4098)<==<=4<=+<=0<=+<=9<=+<=8<==<=21. Then the digital root of number *n* equals to: 1. *dr*(*n*)<==<=*S*(*n*), if *S*(*n*)<=&lt;<=10; 1. *dr*(*n*)<==<=*dr*(<=*S*(*n*)<=), if *S*(*n*)<=≥<=10. For example, *dr*(4098)<=<==<=<=*dr*(21)<=<==<=<=3. Vasya is afraid of large numbers, so the numbers he works with are at most 101000. For all such numbers, he has proved that *dr*(*n*)<=<==<=<=*S*(<=*S*(<=*S*(<=*S*(*n*)<=)<=)<=) (*n*<=≤<=101000). Now Vasya wants to quickly find numbers with the given digital root. The problem is, he hasn't learned how to do that and he asked you to help him. You task is, given numbers *k* and *d*, find the number consisting of exactly *k* digits (the leading zeroes are not allowed), with digital root equal to *d*, or else state that such number does not exist. The first line contains two integers *k* and *d* (1<=≤<=*k*<=≤<=1000; 0<=≤<=*d*<=≤<=9). In a single line print either any number that meets the requirements (without the leading zeroes) or "No solution" (without the quotes), if the corresponding number does not exist. The chosen number must consist of exactly *k* digits. We assume that number 0 doesn't contain any leading zeroes. Sample Input 4 4 5 1 1 0 Sample Output 5881 36172 0
{"inputs": ["4 4", "5 1", "1 0", "8 7", "487 0", "1000 5", "22 9", "1 1", "1 9", "13 5", "100 4", "123 6", "1000 1", "2 0", "734 9", "678 8", "955 7", "893 3", "998 2", "960 6"], "outputs": ["5881", "36172", "0", "49722154", "No solution", "8541939554067890866522280268745476436249986028349767396372181155840878549622667946850256234534972693110974918858266403731194206972478044933297639886527448596769215803533001453375065914421371731616055420973164037664278812596299678416020519508892847037891229851414508562230407367486468987019052183250172396304562086008837592345867873765321840214188417303688776985319268802181355472294386101622570417737061113209187893810568585166094583478900129912239498334853726870963804475563182775380744565964067602555515611220...", "1583569962049529809017", "1", "9", "1381199538344", "6334594910586850938286642284598905674550356974741186703111536643493065423553455569335256292313330478", "928024873067884441426263446866614165147002631091527531801777528825238463822318502518751375671158771476735217071878592158343", "8286301124628812353504240076754144327937426329149605334362213339655339076564408659154706137278060590992944494591503606137350736487608756923833530346502466262820452589925067370165968733865814927433418675056573256434073937686361155637721866942352171450747045834987797118866710087297111065178077368748085213082452303815796793489599773148508108295035303578345492871662297456131736137780231762177312635688688714815857818196180724774924848693916003108422682889382923194020205691379066085156078824413573001257245677878...", "No solution", "5509849803670339733829077693143634799621955270111335907079347964026719040571586127009915057683769302171314977999063915868539391500563742827163274052101515706840652002966522709635011152141196057419086708927225560622675363856445980167733179728663010064912099615416068178748694469047950713834326493597331720572208847439692450327661109751421257198843242305082523510866664350537162158359215265173356615680034808012842300294492281197211603826994471586252822908597603049772690875861970190564793056757768783375525854981...", "3301967993506605598118564082793505826927835671912383741219911930496842130418974223636865915672261642456247377827650506657877850580145623499927271391838907804651235401527392426584047219626357010023552497909436550723659221336486898100975437974320483591226280567200180225706948265372905918038750624429412331582504280650041845010449084641487447573160867860208332424835101416924485616494780952529083292227777966546236453553361466209621076748915774965082618181512654546592160909206650552581723190500273752213154329310...", "4875434946733568640983465009954221247849488705968833681097920555785434899849497268074436910608289709905212840964404347113134616236366794383005890642796609027376389191650656756216171636192669456464756898600086886269167613161503734300581107122411830728903919402846291350458047685924037685489537178939190129043010338580479169957795695942333133962326316127076129681213167918954090336000635320714955444899171270809399782177230616239894234246885245402806465700760528496316658100834632585364274381823984214942419830421...", "3154491812688062338683413382839715419754844054478504300541293341098785797116419835470049101334759365561276155814822131363018164033585874216523127145546903121862283071300185033613164338905028463571111541628115658108609505120357131336651371062955497690723492519748325195227665653129911625684144804656937323976632567108677478936761775342496303735237936919652618323430255701996987753367609559178855599470625167628439986055634187527493497208780060336400261449926469512996188738133678473883670714775784527941804249702...", "8948712698877635315965401396781625629035528026219922557326466734622505808493494219669540192792500692387387200924494124219975316993592377253517258369463882172533672158172302951620486954085880606055358057621166471042557383036617719864238933843342304818076672889894622975857106353903546493307325157763617269195570831067239463586554245706859061059010215520785892192165179414199200952765077228454366556358805840526959104496983177402562569401945586771345953166346316987259989961516385311376707950154520512125143059966...", "7291446744949293530598651243840704118065364362420848463900543089429494124955982767375712583398715647208330285855809398453361266463042342917037983463277320070057956978767965467358862479678812136400444143489366786562672928727263605336304125661306952421127807059398289873947797478996261161224877129724944902005212399176751167053423457968483336961277157597291131065544350665072172392437597673561840137077580044817979332136630042866681837917711758227272499659805765131669208911408670581308412686469802437930679571593..."]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
120
codeforces
93a967c27d1e68ac71fb2f506e4822a5
Books
When Valera has got some free time, he goes to the library to read some books. Today he's got *t* free minutes to read. That's why Valera took *n* books in the library and for each book he estimated the time he is going to need to read it. Let's number the books by integers from 1 to *n*. Valera needs *a**i* minutes to read the *i*-th book. Valera decided to choose an arbitrary book with number *i* and read the books one by one, starting from this book. In other words, he will first read book number *i*, then book number *i*<=+<=1, then book number *i*<=+<=2 and so on. He continues the process until he either runs out of the free time or finishes reading the *n*-th book. Valera reads each book up to the end, that is, he doesn't start reading the book if he doesn't have enough free time to finish reading it. Print the maximum number of books Valera can read. The first line contains two integers *n* and *t* (1<=≤<=*n*<=≤<=105; 1<=≤<=*t*<=≤<=109) — the number of books and the number of free minutes Valera's got. The second line contains a sequence of *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=104), where number *a**i* shows the number of minutes that the boy needs to read the *i*-th book. Print a single integer — the maximum number of books Valera can read. Sample Input 4 5 3 1 2 1 3 3 2 2 3 Sample Output 3 1
{"inputs": ["4 5\n3 1 2 1", "3 3\n2 2 3", "1 3\n5", "1 10\n4", "2 10\n6 4", "6 10\n2 3 4 2 1 1", "7 13\n6 8 14 9 4 11 10", "10 15\n10 9 1 1 5 10 5 3 7 2", "20 30\n8 1 2 6 9 4 1 9 9 10 4 7 8 9 5 7 1 8 7 4", "30 60\n16 13 22 38 13 35 17 17 20 38 12 19 9 22 20 3 35 34 34 21 35 40 22 3 27 19 12 4 8 19", "100 100\n75 92 18 6 81 67 7 92 100 65 82 32 50 67 85 31 80 91 84 63 39 52 92 81 1 98 24 12 43 48 17 86 51 72 48 95 45 50 12 66 19 79 49 89 34 1 97 75 20 33 96 27 42 23 73 71 93 1 85 19 66 14 17 61 20 39 36 33 42 61 56 64 23 91 80 99 40 74 13 18 98 85 74 39 62 84 46 74 50 23 38 11 79 14 9 25 66 100 25 52", "10 1\n4418 7528 8170 1736 1317 3205 8183 4995 8039 4708", "50 2\n124 214 63 73 996 760 38 571 451 300 970 1 706 937 837 494 619 88 851 411 957 990 842 613 821 649 627 34 693 678 734 116 816 985 705 940 499 493 922 967 854 439 112 644 961 438 189 572 655 550"], "outputs": ["3", "1", "0", "1", "2", "4", "2", "3", "6", "4", "3", "0", "1"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
308
codeforces
93aa6c82a42a61f509b47c9cafa68e5b
Ann and Half-Palindrome
Tomorrow Ann takes the hardest exam of programming where she should get an excellent mark. On the last theoretical class the teacher introduced the notion of a half-palindrome. String *t* is a half-palindrome, if for all the odd positions *i* () the following condition is held: *t**i*<==<=*t*|*t*|<=-<=*i*<=+<=1, where |*t*| is the length of string *t* if positions are indexed from 1. For example, strings "abaa", "a", "bb", "abbbaa" are half-palindromes and strings "ab", "bba" and "aaabaa" are not. Ann knows that on the exam she will get string *s*, consisting only of letters a and b, and number *k*. To get an excellent mark she has to find the *k*-th in the lexicographical order string among all substrings of *s* that are half-palyndromes. Note that each substring in this order is considered as many times as many times it occurs in *s*. The teachers guarantees that the given number *k* doesn't exceed the number of substrings of the given string that are half-palindromes. Can you cope with this problem? The first line of the input contains string *s* (1<=≤<=|*s*|<=≤<=5000), consisting only of characters 'a' and 'b', where |*s*| is the length of string *s*. The second line contains a positive integer *k* —  the lexicographical number of the requested string among all the half-palindrome substrings of the given string *s*. The strings are numbered starting from one. It is guaranteed that number *k* doesn't exceed the number of substrings of the given string that are half-palindromes. Print a substring of the given string that is the *k*-th in the lexicographical order of all substrings of the given string that are half-palindromes. Sample Input abbabaab 7 aaaaa 10 bbaabb 13 Sample Output abaa aaa bbaabb
{"inputs": ["abbabaab\n7", "aaaaa\n10", "bbaabb\n13", "a\n1", "b\n1", "ababbbbbbbaaaaaaaabbbbbb\n23", "aa\n3", "aa\n1", "aa\n2", "ab\n1", "ab\n2", "aaa\n1", "aaa\n2", "aaa\n3", "aaa\n4", "aaa\n5", "aaa\n6", "abb\n1", "abb\n2", "abb\n3", "abb\n4", "aba\n4", "aba\n3", "aba\n2", "aba\n1"], "outputs": ["abaa", "aaa", "bbaabb", "a", "b", "aaa", "aa", "a", "a", "a", "b", "a", "a", "a", "aa", "aa", "aaa", "a", "b", "b", "bb", "b", "aba", "a", "a"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1
codeforces
93e73b0ba3ef401390253ad421d7995a
Progress Bar
A progress bar is an element of graphical interface that displays the progress of a process for this very moment before it is completed. Let's take a look at the following form of such a bar. A bar is represented as *n* squares, located in line. To add clarity, let's number them with positive integers from 1 to *n* from the left to the right. Each square has saturation (*a**i* for the *i*-th square), which is measured by an integer from 0 to *k*. When the bar for some *i* (1<=≤<=*i*<=≤<=*n*) is displayed, squares 1,<=2,<=... ,<=*i*<=-<=1 has the saturation *k*, squares *i*<=+<=1,<=*i*<=+<=2,<=... ,<=*n* has the saturation 0, and the saturation of the square *i* can have any value from 0 to *k*. So some first squares of the progress bar always have the saturation *k*. Some last squares always have the saturation 0. And there is no more than one square that has the saturation different from 0 and *k*. The degree of the process's completion is measured in percents. Let the process be *t*% completed. Then the following inequation is fulfilled: An example of such a bar can be seen on the picture. For the given *n*, *k*, *t* determine the measures of saturation for all the squares *a**i* of the progress bar. We are given 3 space-separated integers *n*, *k*, *t* (1<=≤<=*n*,<=*k*<=≤<=100, 0<=≤<=*t*<=≤<=100). Print *n* numbers. The *i*-th of them should be equal to *a**i*. Sample Input 10 10 54 11 13 37 Sample Output 10 10 10 10 10 4 0 0 0 0 13 13 13 13 0 0 0 0 0 0 0
{"inputs": ["10 10 54", "11 13 37", "9 25 50", "43 47 77", "20 1 43", "17 4 61", "10 16 0", "17 13 100", "11 9 1", "9 11 99", "6 17 1", "6 17 99", "17 6 1", "17 6 99", "99 1 1", "99 1 99", "1 1 0", "1 1 37", "1 1 50", "1 1 51", "1 1 99", "1 1 100", "1 17 35", "1 31 88", "1 100 0", "1 100 38", "1 100 99", "1 100 100", "1 99 99", "100 100 73", "100 100 100", "100 13 100", "100 1 100", "100 1 0", "100 13 0", "100 63 0", "100 100 0", "2 99 51", "2 1 49", "2 1 100", "2 13 0", "99 1 51", "15 25 93", "60 51 85", "4 78 78", "49 4 4", "42 83 98", "87 9 90", "31 36 83", "24 14 76"], "outputs": ["10 10 10 10 10 4 0 0 0 0 ", "13 13 13 13 0 0 0 0 0 0 0 ", "25 25 25 25 12 0 0 0 0 ", "47 47 47 47 47 47 47 47 47 47 47 47 47 47 47 47 47 47 47 47 47 47 47 47 47 47 47 47 47 47 47 47 47 5 0 0 0 0 0 0 0 0 0 ", "1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 ", "4 4 4 4 4 4 4 4 4 4 1 0 0 0 0 0 0 ", "0 0 0 0 0 0 0 0 0 0 ", "13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 ", "0 0 0 0 0 0 0 0 0 0 0 ", "11 11 11 11 11 11 11 11 10 ", "1 0 0 0 0 0 ", "17 17 17 17 17 15 ", "1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ", "6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 4 ", "0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ", "1 1 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 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 0 ", "0 ", "0 ", "0 ", "0 ", "0 ", "1 ", "5 ", "27 ", "0 ", "38 ", "99 ", "100 ", "98 ", "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 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ", "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 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 ", "13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 ", "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 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 ", "0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ", "0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ", "0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ", "0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ", "99 1 ", "0 0 ", "1 1 ", "0 0 ", "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 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ", "25 25 25 25 25 25 25 25 25 25 25 25 25 23 0 ", "51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 0 0 0 0 0 0 0 0 0 ", "78 78 78 9 ", "4 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 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ", "83 83 83 83 83 83 83 83 83 83 83 83 83 83 83 83 83 83 83 83 83 83 83 83 83 83 83 83 83 83 83 83 83 83 83 83 83 83 83 83 83 13 ", "9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 2 0 0 0 0 0 0 0 0 ", "36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 26 0 0 0 0 0 ", "14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 3 0 0 0 0 0 "]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
5
codeforces
93ed3cd729c322a66d7fe44bf787cab4
No to Palindromes!
Paul hates palindromes. He assumes that string *s* is tolerable if each its character is one of the first *p* letters of the English alphabet and *s* doesn't contain any palindrome contiguous substring of length 2 or more. Paul has found a tolerable string *s* of length *n*. Help him find the lexicographically next tolerable string of the same length or else state that such string does not exist. The first line contains two space-separated integers: *n* and *p* (1<=≤<=*n*<=≤<=1000; 1<=≤<=*p*<=≤<=26). The second line contains string *s*, consisting of *n* small English letters. It is guaranteed that the string is tolerable (according to the above definition). If the lexicographically next tolerable string of the same length exists, print it. Otherwise, print "NO" (without the quotes). Sample Input 3 3 cba 3 4 cba 4 4 abcd Sample Output NO cbd abda
{"inputs": ["3 3\ncba", "3 4\ncba", "4 4\nabcd", "2 2\nab", "2 2\nba", "1 2\na", "1 2\nb", "1 1\na", "3 4\ncdb", "7 26\nzyxzyxz", "10 5\nabcabcabca", "10 10\nfajegfaicb", "1 26\no", "1 2\nb", "1 26\nz", "3 3\ncab", "3 26\nyzx", "5 5\naceba", "10 3\ncbacbacbac", "11 3\nabcabcabcab", "12 10\nabcabcabcabc", "13 7\ngfegfegfegfeg", "15 11\ncgjkbadjfbdaikj", "17 4\ndabcadcbdcadbcdbc", "26 26\nahnxdnbfcriersyzdihuecojdi", "30 7\ncedcfedcfgcfgcbadcadgfaegfacgf", "70 4\ndcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbd", "77 7\ncadgbagbcaecgfaegcdbeafbacbdfgaedgcdeabgebaecbeacgfebagedcegdafdgeacegfegfegf", "100 4\nabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabca", "333 5\nedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedc", "3 3\nacb", "17 26\nbazyxzyxzyxzyxzyx", "6 3\nacbacb", "6 3\nabcabc", "302 4\nabdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcb", "30 26\nabcabcabczyxzyxzyxzyxzyxzyxzyx", "300 3\nabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabc", "2 4\ncd"], "outputs": ["NO", "cbd", "abda", "ba", "NO", "b", "NO", "NO", "dab", "NO", "abcabcabcd", "fajegfaicd", "p", "NO", "NO", "cba", "zab", "acebc", "NO", "acbacbacbac", "abcabcabcabd", "NO", "cgjkbadjfbdajba", "dabcadcbdcadcabca", "ahnxdnbfcriersyzdihuecojdk", "cedcfedcfgcfgcbadcadgfaegfadba", "NO", "cadgbagbcaecgfaegcdbeafbacbdfgaedgcdeabgebaecbeacgfebagedcegdafdgeacfabcabcab", "abcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcd", "NO", "bac", "bcabcabcabcabcabc", "bacbac", "acbacb", "acbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbac", "abcabcabdabcabcabcabcabcabcabc", "acbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacb", "da"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
20
codeforces
93f371930641819822b183ffc5533b6f
Population Size
Polycarpus develops an interesting theory about the interrelation of arithmetic progressions with just everything in the world. His current idea is that the population of the capital of Berland changes over time like an arithmetic progression. Well, or like multiple arithmetic progressions. Polycarpus believes that if he writes out the population of the capital for several consecutive years in the sequence *a*1,<=*a*2,<=...,<=*a**n*, then it is convenient to consider the array as several arithmetic progressions, written one after the other. For example, sequence (8,<=6,<=4,<=2,<=1,<=4,<=7,<=10,<=2) can be considered as a sequence of three arithmetic progressions (8,<=6,<=4,<=2), (1,<=4,<=7,<=10) and (2), which are written one after another. Unfortunately, Polycarpus may not have all the data for the *n* consecutive years (a census of the population doesn't occur every year, after all). For this reason, some values of *a**i* ​​may be unknown. Such values are represented by number -1. For a given sequence *a*<==<=(*a*1,<=*a*2,<=...,<=*a**n*), which consists of positive integers and values ​​-1, find the minimum number of arithmetic progressions Polycarpus needs to get *a*. To get *a*, the progressions need to be written down one after the other. Values ​​-1 may correspond to an arbitrary positive integer and the values *a**i*<=&gt;<=0 must be equal to the corresponding elements of sought consecutive record of the progressions. Let us remind you that a finite sequence *c* is called an arithmetic progression if the difference *c**i*<=+<=1<=-<=*c**i* of any two consecutive elements in it is constant. By definition, any sequence of length 1 is an arithmetic progression. The first line of the input contains integer *n* (1<=≤<=*n*<=≤<=2·105) — the number of elements in the sequence. The second line contains integer values *a*1,<=*a*2,<=...,<=*a**n* separated by a space (1<=≤<=*a**i*<=≤<=109 or *a**i*<==<=<=-<=1). Print the minimum number of arithmetic progressions that you need to write one after another to get sequence *a*. The positions marked as -1 in *a* can be represented by any positive integers. Sample Input 9 8 6 4 2 1 4 7 10 2 9 -1 6 -1 2 -1 4 7 -1 2 5 -1 -1 -1 -1 -1 7 -1 -1 4 5 1 2 3 Sample Output 3 3 1 2
{"inputs": ["9\n8 6 4 2 1 4 7 10 2", "9\n-1 6 -1 2 -1 4 7 -1 2", "5\n-1 -1 -1 -1 -1", "7\n-1 -1 4 5 1 2 3", "1\n1", "1\n65", "1\n1000000000", "1\n-1", "2\n1000000000 1000000000", "2\n1000000000 -1", "2\n-1 1000000000", "2\n-1 -1", "3\n999999999 1000000000 -1", "3\n999999999 -1 1000000000", "3\n1000000000 999999999 1000000000", "3\n-1 1000000000 999999999", "3\n-1 1000000000 -1", "3\n-1 1 2", "3\n-1 1 1000000000", "5\n-1 1 7 -1 5", "7\n-1 2 4 -1 4 1 5", "2\n-1 21", "3\n39 42 -1", "4\n45 -1 41 -1", "5\n-1 40 42 -1 46", "6\n-1 6 1 -1 -1 -1", "7\n32 33 34 -1 -1 37 38", "8\n-1 12 14 16 18 20 -1 -1", "9\n42 39 36 33 -1 -1 -1 34 39", "10\n29 27 -1 23 42 -1 -1 45 -1 -1", "5\n40 -1 44 46 48", "6\n43 40 37 34 -1 -1", "7\n11 8 5 -1 -1 -1 -1", "8\n-1 12 14 16 18 20 -1 -1", "9\n42 39 36 33 -1 -1 -1 34 39", "10\n29 27 -1 23 42 -1 -1 45 -1 -1", "11\n9 21 17 13 -1 -1 -1 -1 -1 -1 -1", "12\n-1 17 -1 54 -1 64 -1 74 79 84 -1 94", "13\n25 24 23 22 24 27 -1 33 -1 2 2 2 -1", "14\n-1 5 3 -1 -1 31 31 31 -1 31 -1 -1 4 7", "15\n-1 28 -1 32 34 26 -1 26 -1 -1 26 26 26 -1 -1", "16\n3 8 13 18 23 -1 -1 -1 43 48 53 45 -1 -1 -1 -1", "17\n-1 -1 -1 -1 64 68 72 -1 45 46 47 48 49 50 51 52 53", "18\n21 19 -1 -1 -1 48 50 -1 54 -1 5 1 -1 -1 -1 37 36 35", "19\n23 26 -1 -1 35 38 41 -1 -1 -1 53 -1 59 62 6 7 8 9 -1", "6\n-1 2 6 -1 -1 6", "8\n-1 -1 1 7 -1 9 5 2", "20\n-1 32 37 -1 -1 -1 57 -1 -1 40 31 33 -1 -1 39 47 43 -1 35 32", "13\n2 -1 3 1 3 1 -1 1 3 -1 -1 1 1", "3\n-1 1 -1"], "outputs": ["3", "3", "1", "2", "1", "1", "1", "1", "1", "1", "1", "1", "1", "2", "2", "1", "1", "2", "2", "2", "3", "1", "1", "1", "1", "2", "1", "1", "2", "2", "1", "1", "2", "1", "2", "2", "3", "2", "3", "3", "2", "2", "2", "4", "2", "2", "3", "5", "6", "1"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1
codeforces
9423c1bacb4232559c8da48975cfd38d
none
Little Chris is a huge fan of linear algebra. This time he has been given a homework about the unusual square of a square matrix. The dot product of two integer number vectors *x* and *y* of size *n* is the sum of the products of the corresponding components of the vectors. The unusual square of an *n*<=×<=*n* square matrix *A* is defined as the sum of *n* dot products. The *i*-th of them is the dot product of the *i*-th row vector and the *i*-th column vector in the matrix *A*. Fortunately for Chris, he has to work only in *GF*(2)! This means that all operations (addition, multiplication) are calculated modulo 2. In fact, the matrix *A* is binary: each element of *A* is either 0 or 1. For example, consider the following matrix *A*: The unusual square of *A* is equal to (1·1<=+<=1·0<=+<=1·1)<=+<=(0·1<=+<=1·1<=+<=1·0)<=+<=(1·1<=+<=0·1<=+<=0·0)<==<=0<=+<=1<=+<=1<==<=0. However, there is much more to the homework. Chris has to process *q* queries; each query can be one of the following: 1. given a row index *i*, flip all the values in the *i*-th row in *A*; 1. given a column index *i*, flip all the values in the *i*-th column in *A*; 1. find the unusual square of *A*. To flip a bit value *w* means to change it to 1<=-<=*w*, i.e., 1 changes to 0 and 0 changes to 1. Given the initial matrix *A*, output the answers for each query of the third type! Can you solve Chris's homework? The first line of input contains an integer *n* (1<=≤<=*n*<=≤<=1000), the number of rows and the number of columns in the matrix *A*. The next *n* lines describe the matrix: the *i*-th line contains *n* space-separated bits and describes the *i*-th row of *A*. The *j*-th number of the *i*-th line *a**ij* (0<=≤<=*a**ij*<=≤<=1) is the element on the intersection of the *i*-th row and the *j*-th column of *A*. The next line of input contains an integer *q* (1<=≤<=*q*<=≤<=106), the number of queries. Each of the next *q* lines describes a single query, which can be one of the following: - 1 *i* — flip the values of the *i*-th row; - 2 *i* — flip the values of the *i*-th column; - 3 — output the unusual square of *A*. Note: since the size of the input and output could be very large, don't use slow output techniques in your language. For example, do not use input and output streams (cin, cout) in C++. Let the number of the 3rd type queries in the input be *m*. Output a single string *s* of length *m*, where the *i*-th symbol of *s* is the value of the unusual square of *A* for the *i*-th query of the 3rd type as it appears in the input. Sample Input 3 1 1 1 0 1 1 1 0 0 12 3 2 3 3 2 2 2 2 1 3 3 3 1 2 2 1 1 1 3 Sample Output 01001
{"inputs": ["3\n1 1 1\n0 1 1\n1 0 0\n12\n3\n2 3\n3\n2 2\n2 2\n1 3\n3\n3\n1 2\n2 1\n1 1\n3", "1\n1\n9\n1 1\n3\n1 1\n1 1\n3\n1 1\n3\n1 1\n3", "3\n1 0 1\n0 1 1\n1 0 1\n4\n3\n3\n3\n3", "1\n0\n5\n1 1\n3\n1 1\n1 1\n3", "2\n0 0\n0 0\n9\n3\n1 2\n2 2\n1 1\n2 1\n3\n1 2\n1 1\n3", "2\n0 1\n1 0\n7\n3\n3\n2 2\n3\n2 2\n2 1\n3", "5\n1 0 1 0 1\n0 1 0 1 0\n1 0 1 0 1\n0 1 0 1 0\n1 0 1 0 1\n7\n3\n2 4\n1 3\n3\n2 5\n1 5\n3", "2\n1 0\n1 0\n4\n1 2\n3\n1 2\n3", "4\n1 1 0 0\n1 1 0 0\n0 0 0 0\n0 0 0 0\n2\n1 1\n3", "2\n1 1\n1 0\n5\n3\n1 1\n3\n2 1\n3", "2\n1 0\n1 1\n6\n1 2\n3\n2 1\n3\n1 1\n3", "2\n0 0\n0 0\n2\n1 1\n3", "2\n1 0\n0 1\n1\n3"], "outputs": ["01001", "0010", "1111", "11", "000", "0011", "111", "01", "1", "101", "101", "1", "0"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
2
codeforces
942dda7f65cceb57b7d6d092f3bb32d3
Castle Defense
Today you are going to lead a group of elven archers to defend the castle that is attacked by an army of angry orcs. Three sides of the castle are protected by impassable mountains and the remaining side is occupied by a long wall that is split into *n* sections. At this moment there are exactly *a**i* archers located at the *i*-th section of this wall. You know that archer who stands at section *i* can shoot orcs that attack section located at distance not exceeding *r*, that is all such sections *j* that |*i*<=-<=*j*|<=≤<=*r*. In particular, *r*<==<=0 means that archers are only capable of shooting at orcs who attack section *i*. Denote as defense level of section *i* the total number of archers who can shoot at the orcs attacking this section. Reliability of the defense plan is the minimum value of defense level of individual wall section. There is a little time left till the attack so you can't redistribute archers that are already located at the wall. However, there is a reserve of *k* archers that you can distribute among wall sections in arbitrary way. You would like to achieve maximum possible reliability of the defence plan. The first line of the input contains three integers *n*, *r* and *k* (1<=≤<=*n*<=≤<=500<=000, 0<=≤<=*r*<=≤<=*n*, 0<=≤<=*k*<=≤<=1018) — the number of sections of the wall, the maximum distance to other section archers can still shoot and the number of archers yet to be distributed along the wall. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=109) — the current number of archers at each section. Print one integer — the maximum possible value of defense plan reliability, i.e. the maximum possible value of minimum defense level if we distribute *k* additional archers optimally. Sample Input 5 0 6 5 4 3 4 9 4 2 0 1 2 3 4 5 1 1 2 1 2 1 2 Sample Output 5 6 3
{"inputs": ["5 0 6\n5 4 3 4 9", "4 2 0\n1 2 3 4", "5 1 1\n2 1 2 1 2", "1 0 0\n0", "1 0 1000000000000000000\n1000000000", "1 1 10\n23", "2 0 100\n98 2", "3 1 1000\n0 0 0", "100 0 0\n607 169 477 518 368 54 15 471 604 138 982 836 563 886 466 118 366 670 257 37 868 142 14 666 670 624 427 281 995 133 914 413 356 852 63 894 430 310 634 253 281 938 975 272 821 247 626 294 25 829 919 340 728 461 864 756 157 798 474 513 760 107 519 102 69 519 443 65 402 133 752 446 204 509 816 313 900 669 86 400 186 565 951 101 396 822 130 153 980 848 910 219 876 581 35 756 513 314 804 887", "100 1 0\n724 108 796 141 159 89 957 672 396 460 791 468 147 431 700 934 298 95 131 53 676 96 361 438 413 23 171 529 258 834 612 398 120 429 296 231 273 159 936 623 85 72 598 550 205 345 1 414 772 912 464 953 909 883 524 46 542 898 984 859 432 551 972 763 310 233 399 358 875 660 992 946 883 96 20 626 663 234 896 233 790 644 6 563 341 201 980 391 619 508 610 534 698 110 468 934 320 331 700 638", "100 3 0\n483 655 856 10 354 917 853 843 968 309 819 150 532 993 693 498 124 303 121 186 938 587 184 859 440 665 314 751 346 999 593 396 48 119 327 902 540 107 722 641 263 853 113 209 832 379 250 501 395 379 928 57 260 589 156 763 254 591 395 356 459 996 720 544 49 59 149 442 188 628 438 774 639 474 355 669 739 957 757 906 692 27 464 256 932 39 278 866 866 515 793 151 110 991 725 989 96 21 931 653", "100 100 0\n739 293 477 291 132 717 231 695 659 586 352 224 246 945 698 827 972 959 348 183 809 169 781 847 543 990 150 69 807 926 460 704 248 697 825 63 69 168 256 571 353 903 43 659 290 422 426 390 132 242 514 696 728 1 423 927 360 517 774 816 24 64 804 441 957 288 112 790 239 919 216 885 527 381 749 488 836 36 668 500 558 694 493 836 191 903 192 603 51 589 552 752 812 192 358 111 956 73 761 547", "100 0 1000\n328 12 814 345 865 163 256 233 778 3 425 264 632 323 78 747 566 591 696 729 499 649 643 553 732 730 758 194 338 694 407 506 218 408 242 979 924 70 298 59 899 252 38 438 577 594 498 702 355 492 851 712 900 25 34 890 215 360 536 797 418 864 739 823 853 363 734 224 874 537 471 422 592 460 963 589 563 905 437 426 411 948 968 417 31 828 917 829 591 886 429 512 160 252 982 921 276 285 155 422", "100 1 1000\n923 286 937 954 258 701 953 262 346 809 109 678 963 496 245 110 75 633 900 434 608 144 574 425 646 458 188 991 341 293 121 513 548 323 139 5 360 95 951 725 107 727 892 139 493 206 433 390 733 568 629 525 303 570 539 151 266 273 459 604 724 682 411 187 763 624 610 596 383 447 376 671 479 815 2 192 270 245 187 790 159 359 561 541 66 882 809 595 980 421 753 795 551 331 296 872 929 77 207 447", "100 3 1000\n391 145 605 150 641 788 1000 471 328 15 753 161 472 311 963 398 687 81 309 316 87 346 798 59 411 608 437 697 665 264 673 546 10 688 749 302 824 661 693 357 870 560 874 265 185 628 402 534 1000 649 551 412 384 273 249 324 54 204 946 811 478 106 616 981 219 280 432 838 149 155 385 3 883 81 892 70 736 137 309 787 359 405 927 934 211 828 587 896 722 34 936 355 958 541 308 463 404 709 654 248", "100 100 1000\n814 165 709 628 263 653 940 749 331 437 129 547 575 73 480 429 396 688 489 312 425 946 444 228 547 512 477 849 53 241 643 416 141 502 449 58 686 111 171 844 113 790 79 107 399 846 945 427 361 68 295 630 260 939 679 458 485 738 202 141 166 940 5 73 108 351 245 998 640 772 604 123 389 758 491 340 185 183 719 975 136 796 124 4 346 884 810 103 69 522 104 451 443 239 171 22 346 227 525 807", "1 0 0\n1", "2 0 1\n1 1"], "outputs": ["5", "6", "3", "0", "1000000001000000000", "33", "100", "1000", "14", "279", "1701", "50490", "150", "739", "2050", "44706", "1", "1"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1
codeforces
942ec18dc47325413b71a977730c10fe
Very Interesting Game
In a very ancient country the following game was popular. Two people play the game. Initially first player writes a string *s*1, consisting of exactly nine digits and representing a number that does not exceed *a*. After that second player looks at *s*1 and writes a string *s*2, consisting of exactly nine digits and representing a number that does not exceed *b*. Here *a* and *b* are some given constants, *s*1 and *s*2 are chosen by the players. The strings are allowed to contain leading zeroes. If a number obtained by the concatenation (joining together) of strings *s*1 and *s*2 is divisible by *mod*, then the second player wins. Otherwise the first player wins. You are given numbers *a*, *b*, *mod*. Your task is to determine who wins if both players play in the optimal manner. If the first player wins, you are also required to find the lexicographically minimum winning move. The first line contains three integers *a*, *b*, *mod* (0<=≤<=*a*,<=*b*<=≤<=109, 1<=≤<=*mod*<=≤<=107). If the first player wins, print "1" and the lexicographically minimum string *s*1 he has to write to win. If the second player wins, print the single number "2". Sample Input 1 10 7 4 0 9 Sample Output 2 1 000000001
{"inputs": ["1 10 7", "4 0 9", "10 7 8", "6 4 10", "4 1 4", "4 7 9", "13 4 51", "0 0 1", "1 0 1", "2 1 3", "0 2 2", "2 3 1", "3 0 3", "1 1 2", "3 2 1", "0 3 3", "4 0 13", "1 2 13", "4 3 12", "1 2 11", "4 3 12", "815 216 182", "218 550 593", "116482865 344094604 3271060", "19749161 751031022 646204", "70499104 10483793 5504995", "1960930 562910 606828", "8270979 4785512 9669629", "9323791 4748006 5840080", "972037745 4602117 5090186", "585173560 4799128 5611727", "22033548 813958 4874712", "702034015 6007275 9777625", "218556 828183 7799410", "1167900 2709798 6800151", "7004769 3114686 4659684", "1000000000 1000000000 10000000", "3631 1628 367377", "3966 5002 273075", "2388 2896 73888", "0 0 1", "1 0 1", "0 1 1", "1 1 1", "1000000000 0 1", "0 1000000000 1", "1000000000 1000000000 1", "1000000000 0 10000000", "0 1000000000 10000000", "0 0 10000000", "0 999999999 10000000", "999999999 0 10000000", "999999999 999999999 10000000", "999999999 1000000000 10000000", "1000000000 999999999 10000000", "1000000000 10000 10000000", "1 1 1337", "576694 1234562 1234567", "12350 12000 12345", "576695 1234562 1234567", "0 0 11", "999999999 999999999 9009009", "1 0 7", "1 1 7", "1000000000 9999991 10000000", "9902593 9902584 9902593", "10000000 9999977 9999979", "1000000000 1000000000 9999999", "11 9 11", "0 7 13", "1 0 3", "100 2 3", "2 7 13", "1 0 9", "1000000000 9999995 10000000", "1000000000 25 30", "243 1001 1003", "9 9 11", "0 1 11", "4 4 7", "1000000000 1 10", "1 0 11", "0 0 11", "0 0 3", "10 12000 12345", "1000000000 0 2", "0 1 3", "3 1 7", "1000000000 2 1000000", "23 0 23", "123456789 1234561 1234567", "11 10 13", "138 11711 11829", "1000000000 100050 1000001"], "outputs": ["2", "1 000000001", "2", "2", "2", "1 000000001", "1 000000001", "2", "2", "1 000000001", "2", "2", "1 000000001", "2", "2", "2", "1 000000001", "2", "1 000000001", "2", "1 000000001", "2", "1 000000011", "2", "2", "2", "1 000000011", "1 000000001", "1 000000005", "1 000000011", "1 000000036", "1 000000001", "1 000000001", "1 000000001", "1 000000001", "1 000000002", "2", "1 000000009", "1 000000008", "1 000000016", "2", "2", "2", "2", "2", "2", "2", "2", "2", "2", "2", "2", "2", "2", "2", "2", "1 000000001", "2", "1 000000011", "1 000576695", "2", "2", "1 000000001", "2", "2", "1 002490619", "1 009909503", "2", "1 000000010", "2", "1 000000001", "2", "2", "1 000000001", "2", "2", "2", "2", "2", "2", "2", "1 000000001", "2", "2", "2", "2", "2", "1 000000002", "2", "1 000000001", "1 000549636", "1 000000011", "2", "1 000000101"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
2
codeforces
945fb097d72ffaca116be20ac37527ef
President's Office
President of Berland has a very vast office-room, where, apart from him, work his subordinates. Each subordinate, as well as President himself, has his own desk of a unique colour. Each desk is rectangular, and its sides are parallel to the office walls. One day President decided to establish an assembly, of which all his deputies will be members. Unfortunately, he does not remember the exact amount of his deputies, but he remembers that the desk of each his deputy is adjacent to his own desk, that is to say, the two desks (President's and each deputy's) have a common side of a positive length. The office-room plan can be viewed as a matrix with *n* rows and *m* columns. Each cell of this matrix is either empty, or contains a part of a desk. An uppercase Latin letter stands for each desk colour. The «period» character («.») stands for an empty cell. The first line contains two separated by a space integer numbers *n*, *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the length and the width of the office-room, and *c* character — the President's desk colour. The following *n* lines contain *m* characters each — the office-room description. It is guaranteed that the colour of each desk is unique, and each desk represents a continuous subrectangle of the given matrix. All colours are marked by uppercase Latin letters. Print the only number — the amount of President's deputies. Sample Input 3 4 R G.B. .RR. TTT. 3 3 Z ... .H. ..Z Sample Output 2 0
{"inputs": ["3 4 R\nG.B.\n.RR.\nTTT.", "3 3 Z\n...\n.H.\n..Z", "1 1 C\nC", "2 2 W\nKW\nKW", "1 10 H\n....DDHHHH", "3 2 W\nOO\nWW\nWW", "3 3 U\nUOO\nUVV\nUVV", "4 5 Z\n...ZZ\nUU.ZZ\nUUTT.\n..TT.", "4 4 X\nT..R\nTJJJ\nDJJJ\nXJJJ", "5 5 O\nCQGAV\nIHTUD\nRFPZO\nMYSKX\nJEWBN", "5 4 O\n.O.J\nWOBJ\nWOBJ\nDDBJ\nDD.J", "7 7 Q\n....RRR\nUUUURRR\nUUUUSS.\n....SSB\nPPP.OIB\n.MMTTIB\nQQQTTIB", "8 10 B\n..BBBBEEEE\n..BBBBEEEE\n..BBBBEEEE\n..BBBBEEEE\nJJJJYYYY..\nJJJJYYYY..\nJJJJYYYY..\nJJJJYYYY..", "7 13 G\n....GGGGGGXXX\nSSSSGGGGGGXXX\nSSSSJJFFFFFFF\nRRR.JJFFFFFFF\nRRRYYYYYYYAAA\nRRRYYYYYYYAAA\nRRR.......AAA", "10 10 T\nCCEEEKKKHJ\nCCRRRRRRHJ\nCC..XFFOOO\nZZZZZFFOOO\n..PTTFFOOO\nAAATTFFOOO\nAAATTYYYYY\nAAATTYYYYY\nAAAMMYYYYY\nAAA..YYYYY", "15 12 M\n............\n.....L..QQQQ\nNNN..L..QQQQ\nNNN..LJJJJJ.\nNNNEEEEEEEE.\nNNNEEEEEEEE.\nNNNMMMMM.AAA\nNNNMMMMM.AAA\n.RRMMMMM.AAA\n.RRMMMMMYAAA\n.RRMMMMMYAAA\n.RRMMMMMYAAA\nZRRMMMMMYAAA\nZRRMMMMM.AAA\nZRRMMMMM.AAA"], "outputs": ["2", "0", "0", "1", "1", "1", "2", "1", "2", "3", "3", "2", "3", "4", "6", "4"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
148
codeforces
947a2b4f73b2035009e5a5f2fe0b5929
Counting Rhombi
You have two positive integers *w* and *h*. Your task is to count the number of rhombi which have the following properties: - Have positive area. - With vertices at integer points. - All vertices of the rhombi are located inside or on the border of the rectangle with vertices at points (0,<=0), (*w*,<=0), (*w*,<=*h*), (0,<=*h*). In other words, for all vertices (*x**i*,<=*y**i*) of the rhombus the following conditions should fulfill: 0<=≤<=*x**i*<=≤<=*w* and 0<=≤<=*y**i*<=≤<=*h*. - Its diagonals are parallel to the axis. Count the number of such rhombi. Let us remind you that a rhombus is a quadrilateral whose four sides all have the same length. The first line contains two integers *w* and *h* (1<=≤<=*w*,<=*h*<=≤<=4000) — the rectangle's sizes. Print a single number — the number of sought rhombi. Please do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specifier. Sample Input 2 2 1 2 Sample Output 1 0
{"inputs": ["2 2", "1 2", "1 4000", "4000 1", "4000 4000", "15 10", "7 9", "17 17", "7 13", "9 14", "3 10", "14 2", "4 6", "18 2858", "14 1274", "25 2986", "13 1402", "2955 21", "1665 27", "3671 19", "2541 25", "1913 3980", "3727 2044", "2437 460", "1499 2172", "1 1"], "outputs": ["1", "0", "0", "0", "16000000000000", "1400", "240", "5184", "504", "980", "50", "49", "36", "165405321", "19882681", "347731644", "20638842", "240130660", "126136192", "303215400", "251810520", "3623063809200", "3627108561888", "78542851800", "662525703000", "0"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
7
codeforces